init
This commit is contained in:
134 files changed
+18678
No files matched your search
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@easy-stream/contracts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": ["dist"],
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.34.41"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { Type, type Static } from '@sinclair/typebox';
|
||||
import { DateTimeSchema, EmailSchema, UuidSchema } from './common.js';
|
||||
|
||||
export const AdminLoginSchema = Type.Object(
|
||||
{
|
||||
email: EmailSchema,
|
||||
password: Type.String({ minLength: 12, maxLength: 1024 }),
|
||||
totp: Type.Optional(Type.String({ pattern: '^[0-9]{6}$' })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const AdminSessionResponseSchema = Type.Object(
|
||||
{
|
||||
admin: Type.Object(
|
||||
{ id: UuidSchema, email: EmailSchema },
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
csrfToken: Type.String(),
|
||||
expiresAt: DateTimeSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const StartScanSchema = Type.Object(
|
||||
{ full: Type.Optional(Type.Boolean({ default: false })) },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PublicationParamsSchema = Type.Object(
|
||||
{ mediaItemId: UuidSchema },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PublicationBodySchema = Type.Object(
|
||||
{ published: Type.Boolean() },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const JobStateSchema = Type.Union([
|
||||
Type.Literal('QUEUED'),
|
||||
Type.Literal('RUNNING'),
|
||||
Type.Literal('SUCCEEDED'),
|
||||
Type.Literal('FAILED'),
|
||||
Type.Literal('CANCELLED'),
|
||||
]);
|
||||
|
||||
export const JobSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
type: Type.String(),
|
||||
state: JobStateSchema,
|
||||
progress: Type.Number({ minimum: 0, maximum: 1 }),
|
||||
error: Type.Union([Type.String(), Type.Null()]),
|
||||
createdAt: DateTimeSchema,
|
||||
updatedAt: DateTimeSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const JobParamsSchema = Type.Object({ jobId: UuidSchema }, { additionalProperties: false });
|
||||
export const CacheParamsSchema = Type.Object(
|
||||
{ generationId: UuidSchema },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CacheStatusSchema = Type.Object(
|
||||
{
|
||||
usedBytes: Type.Integer({ minimum: 0 }),
|
||||
maxBytes: Type.Integer({ minimum: 1 }),
|
||||
highWatermark: Type.Number({ minimum: 0, maximum: 1 }),
|
||||
lowWatermark: Type.Number({ minimum: 0, maximum: 1 }),
|
||||
activePackages: Type.Integer({ minimum: 0 }),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MetadataSearchQuerySchema = Type.Object(
|
||||
{
|
||||
q: Type.String({ minLength: 1, maxLength: 200 }),
|
||||
kind: Type.Union([Type.Literal('MOVIE'), Type.Literal('SERIES')]),
|
||||
year: Type.Optional(Type.Integer({ minimum: 1888, maximum: 2200 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MetadataCandidateSchema = Type.Object(
|
||||
{
|
||||
provider: Type.Literal('TMDB'),
|
||||
externalId: Type.Integer({ minimum: 1 }),
|
||||
kind: Type.Union([Type.Literal('MOVIE'), Type.Literal('SERIES')]),
|
||||
name: Type.Object(
|
||||
{ fa: Type.String(), en: Type.Optional(Type.String()) },
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
synopsis: Type.Object(
|
||||
{ fa: Type.Optional(Type.String()), en: Type.Optional(Type.String()) },
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
posterUrl: Type.Optional(Type.String()),
|
||||
backdropUrl: Type.Optional(Type.String()),
|
||||
year: Type.Optional(Type.Integer()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MetadataSearchResponseSchema = Type.Object(
|
||||
{ items: Type.Array(MetadataCandidateSchema) },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MetadataMatchParamsSchema = Type.Object(
|
||||
{ titleId: UuidSchema },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MetadataMatchBodySchema = Type.Object(
|
||||
{
|
||||
provider: Type.Literal('TMDB'),
|
||||
externalId: Type.Integer({ minimum: 1 }),
|
||||
kind: Type.Union([Type.Literal('MOVIE'), Type.Literal('SERIES')]),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export type AdminLogin = Static<typeof AdminLoginSchema>;
|
||||
export type AdminSessionResponse = Static<typeof AdminSessionResponseSchema>;
|
||||
export type StartScan = Static<typeof StartScanSchema>;
|
||||
export type Job = Static<typeof JobSchema>;
|
||||
export type JobState = Static<typeof JobStateSchema>;
|
||||
export type CacheStatus = Static<typeof CacheStatusSchema>;
|
||||
export type MetadataSearchQuery = Static<typeof MetadataSearchQuerySchema>;
|
||||
export type MetadataCandidate = Static<typeof MetadataCandidateSchema>;
|
||||
export type MetadataMatchBody = Static<typeof MetadataMatchBodySchema>;
|
||||
@@ -0,0 +1,134 @@
|
||||
import { Type, type Static } from '@sinclair/typebox';
|
||||
import { DateTimeSchema, UuidSchema } from './common.js';
|
||||
|
||||
export const TitleKindSchema = Type.Union([Type.Literal('MOVIE'), Type.Literal('SERIES')]);
|
||||
export const MediaKindSchema = Type.Union([Type.Literal('MOVIE'), Type.Literal('EPISODE')]);
|
||||
|
||||
export const LocalizedTextSchema = Type.Object(
|
||||
{
|
||||
fa: Type.String(),
|
||||
en: Type.Optional(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const OptionalLocalizedTextSchema = Type.Object(
|
||||
{
|
||||
fa: Type.Optional(Type.String()),
|
||||
en: Type.Optional(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CatalogCardSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
slug: Type.String(),
|
||||
kind: TitleKindSchema,
|
||||
name: LocalizedTextSchema,
|
||||
posterUrl: Type.Optional(Type.String()),
|
||||
backdropUrl: Type.Optional(Type.String()),
|
||||
year: Type.Optional(Type.Integer()),
|
||||
playable: Type.Boolean(),
|
||||
resumeMediaItemId: Type.Optional(UuidSchema),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const MediaItemSummarySchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
kind: MediaKindSchema,
|
||||
seasonNumber: Type.Optional(Type.Integer({ minimum: 0 })),
|
||||
episodeNumber: Type.Optional(Type.Integer({ minimum: 0 })),
|
||||
name: Type.Optional(OptionalLocalizedTextSchema),
|
||||
durationSeconds: Type.Number({ minimum: 0 }),
|
||||
compatibility: Type.Union([
|
||||
Type.Literal('COPY'),
|
||||
Type.Literal('AUDIO_TRANSCODE'),
|
||||
Type.Literal('VIDEO_TRANSCODE'),
|
||||
Type.Literal('HOLD_HDR'),
|
||||
Type.Literal('INVALID'),
|
||||
]),
|
||||
published: Type.Boolean(),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const SeasonSummarySchema = Type.Object(
|
||||
{
|
||||
number: Type.Integer({ minimum: 0 }),
|
||||
episodeCount: Type.Integer({ minimum: 0 }),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const TitleDetailSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
slug: Type.String(),
|
||||
kind: TitleKindSchema,
|
||||
name: LocalizedTextSchema,
|
||||
posterUrl: Type.Optional(Type.String()),
|
||||
backdropUrl: Type.Optional(Type.String()),
|
||||
year: Type.Optional(Type.Integer()),
|
||||
playable: Type.Boolean(),
|
||||
resumeMediaItemId: Type.Optional(UuidSchema),
|
||||
synopsis: OptionalLocalizedTextSchema,
|
||||
seasons: Type.Optional(Type.Array(SeasonSummarySchema)),
|
||||
mediaItems: Type.Array(MediaItemSummarySchema),
|
||||
updatedAt: DateTimeSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CatalogQuerySchema = Type.Object(
|
||||
{
|
||||
cursor: Type.Optional(Type.String({ maxLength: 512 })),
|
||||
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100, default: 24 })),
|
||||
kind: Type.Optional(TitleKindSchema),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const SearchQuerySchema = Type.Object(
|
||||
{
|
||||
q: Type.String({ minLength: 1, maxLength: 200 }),
|
||||
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 50, default: 20 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CatalogResponseSchema = Type.Object(
|
||||
{
|
||||
items: Type.Array(CatalogCardSchema),
|
||||
nextCursor: Type.Optional(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const SearchResponseSchema = Type.Object(
|
||||
{ items: Type.Array(CatalogCardSchema) },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CatalogSnapshotSchema = Type.Object(
|
||||
{
|
||||
version: Type.Literal(1),
|
||||
generatedAt: DateTimeSchema,
|
||||
titles: Type.Array(TitleDetailSchema),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export type TitleKind = Static<typeof TitleKindSchema>;
|
||||
export type MediaKind = Static<typeof MediaKindSchema>;
|
||||
export type LocalizedText = Static<typeof LocalizedTextSchema>;
|
||||
export type OptionalLocalizedText = Static<typeof OptionalLocalizedTextSchema>;
|
||||
export type CatalogCard = Static<typeof CatalogCardSchema>;
|
||||
export type MediaItemSummary = Static<typeof MediaItemSummarySchema>;
|
||||
export type TitleDetail = Static<typeof TitleDetailSchema>;
|
||||
export type CatalogQuery = Static<typeof CatalogQuerySchema>;
|
||||
export type SearchQuery = Static<typeof SearchQuerySchema>;
|
||||
export type CatalogResponse = Static<typeof CatalogResponseSchema>;
|
||||
export type CatalogSnapshot = Static<typeof CatalogSnapshotSchema>;
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Type, type Static } from '@sinclair/typebox';
|
||||
|
||||
export const UuidSchema = Type.String({
|
||||
pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$',
|
||||
});
|
||||
export const DateTimeSchema = Type.String({
|
||||
pattern: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$',
|
||||
});
|
||||
export const EmailSchema = Type.String({
|
||||
maxLength: 320,
|
||||
pattern: '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$',
|
||||
});
|
||||
|
||||
export const ErrorCodeSchema = Type.Union([
|
||||
Type.Literal('BAD_REQUEST'),
|
||||
Type.Literal('NOT_FOUND'),
|
||||
Type.Literal('UNAUTHORIZED'),
|
||||
Type.Literal('FORBIDDEN'),
|
||||
Type.Literal('CONFLICT'),
|
||||
Type.Literal('VALIDATION_ERROR'),
|
||||
Type.Literal('UNSUPPORTED_CLIENT'),
|
||||
Type.Literal('MEDIA_UNAVAILABLE'),
|
||||
Type.Literal('INTERNAL_ERROR'),
|
||||
]);
|
||||
|
||||
export const ErrorResponseSchema = Type.Object(
|
||||
{
|
||||
error: Type.Object(
|
||||
{
|
||||
code: ErrorCodeSchema,
|
||||
message: Type.String(),
|
||||
requestId: Type.String(),
|
||||
details: Type.Optional(Type.Unknown()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export type ErrorCode = Static<typeof ErrorCodeSchema>;
|
||||
export type ErrorResponse = Static<typeof ErrorResponseSchema>;
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Type, type Static } from '@sinclair/typebox';
|
||||
import { DateTimeSchema, UuidSchema } from './common.js';
|
||||
import { AudioTrackSchema, SubtitleTrackSchema } from './playback.js';
|
||||
|
||||
export const MediaCommandSchema = Type.Union([
|
||||
Type.Object(
|
||||
{
|
||||
type: Type.Literal('media.playback.requested'),
|
||||
sessionId: UuidSchema,
|
||||
mediaItemId: UuidSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{ type: Type.Literal('archive.scan.requested'), jobId: UuidSchema, full: Type.Boolean() },
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{
|
||||
type: Type.Literal('media.publication.changed'),
|
||||
mediaItemId: UuidSchema,
|
||||
published: Type.Boolean(),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{ type: Type.Literal('package.eviction.requested'), generationId: UuidSchema },
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
Type.Object(
|
||||
{
|
||||
type: Type.Literal('cache.generation.accessed'),
|
||||
sessionId: UuidSchema,
|
||||
generationId: UuidSchema,
|
||||
accessedAt: DateTimeSchema,
|
||||
protectedUntil: DateTimeSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
),
|
||||
]);
|
||||
|
||||
/** Shared by the API lease writer and worker eviction reader. */
|
||||
export const CACHE_GENERATION_LEASES_KEY = 'easy-stream:cache-generation-leases:v1';
|
||||
|
||||
export const MediaPreparationResultSchema = Type.Object(
|
||||
{
|
||||
sessionId: UuidSchema,
|
||||
state: Type.Union([
|
||||
Type.Literal('PREPARING'),
|
||||
Type.Literal('READY'),
|
||||
Type.Literal('UNSUPPORTED_CLIENT'),
|
||||
Type.Literal('FAILED'),
|
||||
]),
|
||||
playable: Type.Boolean(),
|
||||
generationId: Type.Optional(UuidSchema),
|
||||
manifestPath: Type.Optional(Type.String({ pattern: '^/media/' })),
|
||||
reasonCode: Type.Optional(Type.String()),
|
||||
pollAfterMs: Type.Optional(Type.Integer({ minimum: 250, maximum: 30000 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PackageRegistryEntrySchema = Type.Object(
|
||||
{
|
||||
mediaItemId: UuidSchema,
|
||||
state: Type.Union([
|
||||
Type.Literal('PREPARING'),
|
||||
Type.Literal('READY'),
|
||||
Type.Literal('UNSUPPORTED_CLIENT'),
|
||||
Type.Literal('FAILED'),
|
||||
]),
|
||||
playable: Type.Boolean(),
|
||||
generationId: Type.Optional(UuidSchema),
|
||||
manifestPath: Type.Optional(Type.String({ pattern: '^/media/' })),
|
||||
reasonCode: Type.Optional(Type.String()),
|
||||
pollAfterMs: Type.Optional(Type.Integer({ minimum: 250, maximum: 30000 })),
|
||||
durationSeconds: Type.Optional(Type.Number({ minimum: 0 })),
|
||||
audioTracks: Type.Optional(Type.Array(AudioTrackSchema)),
|
||||
subtitleTracks: Type.Optional(Type.Array(SubtitleTrackSchema)),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PackageRegistrySchema = Type.Object(
|
||||
{
|
||||
version: Type.Literal(1),
|
||||
updatedAt: Type.String({
|
||||
pattern: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$',
|
||||
}),
|
||||
packages: Type.Array(PackageRegistryEntrySchema),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export type MediaCommand = Static<typeof MediaCommandSchema>;
|
||||
export type MediaPreparationResult = Static<typeof MediaPreparationResultSchema>;
|
||||
export type PackageRegistryEntry = Static<typeof PackageRegistryEntrySchema>;
|
||||
export type PackageRegistry = Static<typeof PackageRegistrySchema>;
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from './admin.js';
|
||||
export * from './catalog.js';
|
||||
export * from './common.js';
|
||||
export * from './events.js';
|
||||
export * from './playback.js';
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Type, type Static } from '@sinclair/typebox';
|
||||
import { DateTimeSchema, UuidSchema } from './common.js';
|
||||
|
||||
export const CompatibilityClassSchema = Type.Union([
|
||||
Type.Literal('COPY'),
|
||||
Type.Literal('AUDIO_TRANSCODE'),
|
||||
Type.Literal('VIDEO_TRANSCODE'),
|
||||
Type.Literal('HOLD_HDR'),
|
||||
Type.Literal('INVALID'),
|
||||
]);
|
||||
|
||||
export const PlaybackStateSchema = Type.Union([
|
||||
Type.Literal('PREPARING'),
|
||||
Type.Literal('READY'),
|
||||
Type.Literal('UNSUPPORTED_CLIENT'),
|
||||
Type.Literal('FAILED'),
|
||||
]);
|
||||
|
||||
export const SubtitleDeliverySchema = Type.Union([
|
||||
Type.Literal('ASS_JASSUB'),
|
||||
Type.Literal('WEBVTT'),
|
||||
Type.Literal('OFF'),
|
||||
]);
|
||||
|
||||
export const ClientCapabilitiesSchema = Type.Object(
|
||||
{
|
||||
mse: Type.Boolean(),
|
||||
nativeHls: Type.Boolean(),
|
||||
hlsJs: Type.Boolean(),
|
||||
assRenderer: Type.Boolean(),
|
||||
supportedCodecs: Type.Array(Type.String({ maxLength: 128 }), { maxItems: 32 }),
|
||||
userAgent: Type.Optional(Type.String({ maxLength: 512 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const AudioTrackSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
language: Type.String({ minLength: 2, maxLength: 35 }),
|
||||
label: Type.String({ maxLength: 100 }),
|
||||
default: Type.Boolean(),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const SubtitleTrackSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
language: Type.String({ minLength: 2, maxLength: 35 }),
|
||||
label: Type.String({ maxLength: 100 }),
|
||||
default: Type.Boolean(),
|
||||
forced: Type.Boolean(),
|
||||
assUrl: Type.Optional(Type.String()),
|
||||
vttUrl: Type.Optional(Type.String()),
|
||||
fontUrls: Type.Array(Type.String()),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const CreatePlaybackSessionSchema = Type.Object(
|
||||
{
|
||||
mediaItemId: UuidSchema,
|
||||
clientCapabilities: ClientCapabilitiesSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PlaybackSessionSchema = Type.Object(
|
||||
{
|
||||
id: UuidSchema,
|
||||
mediaItemId: UuidSchema,
|
||||
state: PlaybackStateSchema,
|
||||
manifestUrl: Type.Optional(Type.String()),
|
||||
generationId: Type.Optional(UuidSchema),
|
||||
durationSeconds: Type.Optional(Type.Number({ minimum: 0 })),
|
||||
audioTracks: Type.Optional(Type.Array(AudioTrackSchema)),
|
||||
subtitleTracks: Type.Optional(Type.Array(SubtitleTrackSchema)),
|
||||
pollAfterMs: Type.Optional(Type.Integer({ minimum: 250, maximum: 30000 })),
|
||||
reasonCode: Type.Optional(Type.String()),
|
||||
expiresAt: DateTimeSchema,
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export const PlaybackSessionParamsSchema = Type.Object(
|
||||
{ id: UuidSchema },
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
export type CompatibilityClass = Static<typeof CompatibilityClassSchema>;
|
||||
export type PlaybackState = Static<typeof PlaybackStateSchema>;
|
||||
export type SubtitleDelivery = Static<typeof SubtitleDeliverySchema>;
|
||||
export type ClientCapabilities = Static<typeof ClientCapabilitiesSchema>;
|
||||
export type AudioTrack = Static<typeof AudioTrackSchema>;
|
||||
export type SubtitleTrack = Static<typeof SubtitleTrackSchema>;
|
||||
export type CreatePlaybackSession = Static<typeof CreatePlaybackSessionSchema>;
|
||||
export type PlaybackSession = Static<typeof PlaybackSessionSchema>;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Value } from '@sinclair/typebox/value';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { CreatePlaybackSessionSchema, MediaCommandSchema } from '../src/index.js';
|
||||
|
||||
describe('public contracts', () => {
|
||||
it('accepts a valid browser capability report', () => {
|
||||
expect(
|
||||
Value.Check(CreatePlaybackSessionSchema, {
|
||||
mediaItemId: '00000000-0000-4000-8000-000000000001',
|
||||
clientCapabilities: {
|
||||
mse: true,
|
||||
nativeHls: false,
|
||||
hlsJs: true,
|
||||
assRenderer: true,
|
||||
supportedCodecs: ['avc1.64001f', 'mp4a.40.2'],
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps worker commands discriminated and closed', () => {
|
||||
expect(
|
||||
Value.Check(MediaCommandSchema, {
|
||||
type: 'archive.scan.requested',
|
||||
jobId: '00000000-0000-4000-8000-000000000002',
|
||||
full: false,
|
||||
unexpected: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(Value.Check(MediaCommandSchema, {
|
||||
type: 'cache.generation.accessed',
|
||||
sessionId: '00000000-0000-4000-8000-000000000001',
|
||||
generationId: '00000000-0000-4000-8000-000000000002',
|
||||
accessedAt: '2026-07-14T10:00:00.000Z',
|
||||
protectedUntil: '2026-07-14T14:00:00.000Z',
|
||||
})).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"tsBuildInfoFile": "dist/.tsbuildinfo"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Reference in new issue
Block a user