@editframe/api 0.45.2 → 0.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ProgressIterator.cjs.map +1 -1
- package/dist/ProgressIterator.js.map +1 -1
- package/dist/StreamEventSource.cjs.map +1 -1
- package/dist/StreamEventSource.js.map +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/resources/caption-file.cjs.map +1 -1
- package/dist/resources/caption-file.js.map +1 -1
- package/dist/resources/file.cjs.map +1 -1
- package/dist/resources/file.js.map +1 -1
- package/dist/resources/image-file.cjs.map +1 -1
- package/dist/resources/image-file.js.map +1 -1
- package/dist/resources/isobmff-file.cjs.map +1 -1
- package/dist/resources/isobmff-file.js.map +1 -1
- package/dist/resources/isobmff-track.cjs.map +1 -1
- package/dist/resources/isobmff-track.js.map +1 -1
- package/dist/resources/process-isobmff.cjs.map +1 -1
- package/dist/resources/process-isobmff.js.map +1 -1
- package/dist/resources/renders.cjs.map +1 -1
- package/dist/resources/renders.js.map +1 -1
- package/dist/resources/transcriptions.cjs.map +1 -1
- package/dist/resources/transcriptions.js.map +1 -1
- package/dist/resources/unprocessed-file.cjs.map +1 -1
- package/dist/resources/unprocessed-file.js.map +1 -1
- package/dist/streamChunker.cjs.map +1 -1
- package/dist/streamChunker.js.map +1 -1
- package/dist/uploadChunks.cjs.map +1 -1
- package/dist/uploadChunks.js.map +1 -1
- package/dist/utils/assertTypesMatch.cjs.map +1 -1
- package/dist/utils/assertTypesMatch.js.map +1 -1
- package/dist/utils/createReadableStreamFromReadable.cjs.map +1 -1
- package/dist/utils/createReadableStreamFromReadable.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressIterator.cjs","names":["resolve!: (value: T | PromiseLike<T>) => void","reject!: (reason?: any) => void"],"sources":["../src/ProgressIterator.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"ProgressIterator.cjs","names":["resolve!: (value: T | PromiseLike<T>) => void","reject!: (reason?: any) => void"],"sources":["../src/ProgressIterator.ts"],"sourcesContent":["import type { CompleteEvent, ProgressEvent, StreamEventSource } from \"./StreamEventSource.js\";\n\nconst promiseWithResolvers = <T>() => {\n if (typeof Promise.withResolvers === \"function\") {\n return Promise.withResolvers<T>();\n }\n\n let resolve!: (value: T | PromiseLike<T>) => void;\n let reject!: (reason?: any) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n};\n\nabstract class BaseEventIterator<T extends CompleteEvent | any> implements AsyncIterable<T> {\n protected eventSource: StreamEventSource;\n protected queue: T[] = [];\n protected index = 0;\n protected isComplete = false;\n protected resolversNext = promiseWithResolvers<void>();\n\n constructor(eventSource: StreamEventSource) {\n this.eventSource = eventSource;\n }\n\n async whenComplete() {\n for await (const _ of this) {\n }\n return this.queue;\n }\n\n declare on: (event: \"progress\", callback: (event: ProgressEvent) => void) => this;\n\n protected push(event: T) {\n this.queue.push(event);\n this.resolversNext.resolve();\n this.resolversNext = promiseWithResolvers<void>();\n }\n\n protected get queueLength() {\n return this.queue.length - this.index;\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n try {\n while (!this.isComplete || this.queueLength > 0) {\n if (this.queueLength === 0) {\n await this.resolversNext.promise;\n } else {\n const item = this.queue[this.index];\n if (!item) {\n throw new Error(\"Queue is corrupted\");\n }\n this.index++;\n yield item;\n }\n }\n } finally {\n this.eventSource.close();\n }\n }\n}\n\n// Progress-only iterator\nexport class ProgressIterator extends BaseEventIterator<ProgressEvent | CompleteEvent> {\n constructor(eventSource: StreamEventSource) {\n super(eventSource);\n this.initializeListeners();\n }\n\n private initializeListeners() {\n this.eventSource.on(\"progress\", (event) => {\n this.push(event);\n });\n\n this.eventSource.on(\"complete\", (event) => {\n this.isComplete = true;\n this.push(event);\n });\n\n this.eventSource.on(\"error\", (error) => {\n this.eventSource.close();\n this.resolversNext.reject(error);\n });\n }\n}\n\n// Size and Completion iterator\nexport class CompletionIterator extends BaseEventIterator<CompleteEvent | ProgressEvent> {\n private totalSize = 0;\n private currentProgress = 0;\n\n constructor(eventSource: StreamEventSource) {\n super(eventSource);\n this.initializeListeners();\n }\n\n private initializeListeners() {\n this.eventSource.on(\"size\", (event) => {\n this.totalSize = event.data.size;\n this.push({\n type: \"progress\",\n data: {\n progress: 0,\n },\n });\n });\n\n this.eventSource.on(\"completion\", (event) => {\n this.currentProgress += Number(event.data.count);\n\n this.push({\n type: \"progress\",\n data: {\n progress: this.currentProgress / this.totalSize,\n },\n });\n\n if (this.currentProgress >= this.totalSize) {\n this.isComplete = true;\n }\n });\n\n this.eventSource.on(\"complete\", (event) => {\n this.isComplete = true;\n this.push(event);\n });\n\n this.eventSource.on(\"error\", (error) => {\n this.eventSource.close();\n this.resolversNext.reject(error);\n });\n }\n\n abort() {\n this.eventSource.abort();\n }\n}\n"],"mappings":";;AAEA,MAAM,6BAAgC;AACpC,KAAI,OAAO,QAAQ,kBAAkB,WACnC,QAAO,QAAQ,eAAkB;CAGnC,IAAIA;CACJ,IAAIC;AAKJ,QAAO;EAAE,SAJO,IAAI,SAAY,KAAK,QAAQ;AAC3C,aAAU;AACV,YAAS;IACT;EACgB;EAAS;EAAQ;;AAGrC,IAAe,oBAAf,MAA4F;CAO1F,YAAY,aAAgC;eALrB,EAAE;eACP;oBACK;uBACG,sBAA4B;AAGpD,OAAK,cAAc;;CAGrB,MAAM,eAAe;AACnB,aAAW,MAAM,KAAK;AAEtB,SAAO,KAAK;;CAKd,AAAU,KAAK,OAAU;AACvB,OAAK,MAAM,KAAK,MAAM;AACtB,OAAK,cAAc,SAAS;AAC5B,OAAK,gBAAgB,sBAA4B;;CAGnD,IAAc,cAAc;AAC1B,SAAO,KAAK,MAAM,SAAS,KAAK;;CAGlC,QAAQ,OAAO,iBAAmC;AAChD,MAAI;AAC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U;AACtC,QAAK,YAAY,OAAO;AACxB,QAAK,cAAc,OAAO,MAAM;IAChC;;CAGJ,QAAQ;AACN,OAAK,YAAY,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressIterator.js","names":["resolve!: (value: T | PromiseLike<T>) => void","reject!: (reason?: any) => void"],"sources":["../src/ProgressIterator.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"ProgressIterator.js","names":["resolve!: (value: T | PromiseLike<T>) => void","reject!: (reason?: any) => void"],"sources":["../src/ProgressIterator.ts"],"sourcesContent":["import type { CompleteEvent, ProgressEvent, StreamEventSource } from \"./StreamEventSource.js\";\n\nconst promiseWithResolvers = <T>() => {\n if (typeof Promise.withResolvers === \"function\") {\n return Promise.withResolvers<T>();\n }\n\n let resolve!: (value: T | PromiseLike<T>) => void;\n let reject!: (reason?: any) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n};\n\nabstract class BaseEventIterator<T extends CompleteEvent | any> implements AsyncIterable<T> {\n protected eventSource: StreamEventSource;\n protected queue: T[] = [];\n protected index = 0;\n protected isComplete = false;\n protected resolversNext = promiseWithResolvers<void>();\n\n constructor(eventSource: StreamEventSource) {\n this.eventSource = eventSource;\n }\n\n async whenComplete() {\n for await (const _ of this) {\n }\n return this.queue;\n }\n\n declare on: (event: \"progress\", callback: (event: ProgressEvent) => void) => this;\n\n protected push(event: T) {\n this.queue.push(event);\n this.resolversNext.resolve();\n this.resolversNext = promiseWithResolvers<void>();\n }\n\n protected get queueLength() {\n return this.queue.length - this.index;\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n try {\n while (!this.isComplete || this.queueLength > 0) {\n if (this.queueLength === 0) {\n await this.resolversNext.promise;\n } else {\n const item = this.queue[this.index];\n if (!item) {\n throw new Error(\"Queue is corrupted\");\n }\n this.index++;\n yield item;\n }\n }\n } finally {\n this.eventSource.close();\n }\n }\n}\n\n// Progress-only iterator\nexport class ProgressIterator extends BaseEventIterator<ProgressEvent | CompleteEvent> {\n constructor(eventSource: StreamEventSource) {\n super(eventSource);\n this.initializeListeners();\n }\n\n private initializeListeners() {\n this.eventSource.on(\"progress\", (event) => {\n this.push(event);\n });\n\n this.eventSource.on(\"complete\", (event) => {\n this.isComplete = true;\n this.push(event);\n });\n\n this.eventSource.on(\"error\", (error) => {\n this.eventSource.close();\n this.resolversNext.reject(error);\n });\n }\n}\n\n// Size and Completion iterator\nexport class CompletionIterator extends BaseEventIterator<CompleteEvent | ProgressEvent> {\n private totalSize = 0;\n private currentProgress = 0;\n\n constructor(eventSource: StreamEventSource) {\n super(eventSource);\n this.initializeListeners();\n }\n\n private initializeListeners() {\n this.eventSource.on(\"size\", (event) => {\n this.totalSize = event.data.size;\n this.push({\n type: \"progress\",\n data: {\n progress: 0,\n },\n });\n });\n\n this.eventSource.on(\"completion\", (event) => {\n this.currentProgress += Number(event.data.count);\n\n this.push({\n type: \"progress\",\n data: {\n progress: this.currentProgress / this.totalSize,\n },\n });\n\n if (this.currentProgress >= this.totalSize) {\n this.isComplete = true;\n }\n });\n\n this.eventSource.on(\"complete\", (event) => {\n this.isComplete = true;\n this.push(event);\n });\n\n this.eventSource.on(\"error\", (error) => {\n this.eventSource.close();\n this.resolversNext.reject(error);\n });\n }\n\n abort() {\n this.eventSource.abort();\n }\n}\n"],"mappings":";AAEA,MAAM,6BAAgC;AACpC,KAAI,OAAO,QAAQ,kBAAkB,WACnC,QAAO,QAAQ,eAAkB;CAGnC,IAAIA;CACJ,IAAIC;AAKJ,QAAO;EAAE,SAJO,IAAI,SAAY,KAAK,QAAQ;AAC3C,aAAU;AACV,YAAS;IACT;EACgB;EAAS;EAAQ;;AAGrC,IAAe,oBAAf,MAA4F;CAO1F,YAAY,aAAgC;eALrB,EAAE;eACP;oBACK;uBACG,sBAA4B;AAGpD,OAAK,cAAc;;CAGrB,MAAM,eAAe;AACnB,aAAW,MAAM,KAAK;AAEtB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ACJ,UAAU,KAAK,kBAAkB,KAAK,WACvC;IACF,CAAC;AAEF,OAAI,KAAK,mBAAmB,KAAK,UAC/B,MAAK,aAAa;IAEpB;AAEF,OAAK,YAAY,GAAG,aAAa,UAAU;AACzC,QAAK,aAAa;AAClB,QAAK,KAAK,MAAM;IAChB;AAEF,OAAK,YAAY,GAAG,UAAU,UAAU;AACtC,QAAK,YAAY,OAAO;AACxB,QAAK,cAAc,OAAO,MAAM;IAChC;;CAGJ,QAAQ;AACN,OAAK,YAAY,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamEventSource.cjs","names":[],"sources":["../src/StreamEventSource.ts"],"sourcesContent":["import debug from \"debug\";\nimport { createParser } from \"eventsource-parser\";\n\nconst log = debug(\"ef:StreamEventSource\");\n\nexport type EventCallback<T> = (event: T) => void;\nexport type StreamEventSourceEventMap = {\n progress: ProgressEvent;\n complete: CompleteEvent;\n size: SizeEvent;\n completion: CompletionEvent;\n heartbeat: HeartbeatEvent;\n message: {\n id: string | undefined;\n data: string;\n };\n end: Array<unknown>;\n error: Error;\n};\n\nexport type ProgressEvent = {\n type: \"progress\";\n data: {\n /** Progress events are sent as a percentage of the total render time.\n * This is a number between 0 and 1.\n */\n progress: number;\n };\n};\nexport type CompleteEvent = { type: \"complete\"; data: object };\nexport type SizeEvent = { type: \"size\"; data: { size: number } };\nexport type CompletionEvent = { type: \"completion\"; data: { count: number } };\nexport type HeartbeatEvent = { type: \"heartbeat\"; data: { timestamp: string } };\n\nexport class StreamEventSource {\n private stream: ReadableStream;\n private activeReader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private decoder = new TextDecoder();\n private parser;\n private listeners: {\n [K in keyof StreamEventSourceEventMap]?: EventCallback
|
|
1
|
+
{"version":3,"file":"StreamEventSource.cjs","names":[],"sources":["../src/StreamEventSource.ts"],"sourcesContent":["import debug from \"debug\";\nimport { createParser } from \"eventsource-parser\";\n\nconst log = debug(\"ef:StreamEventSource\");\n\nexport type EventCallback<T> = (event: T) => void;\nexport type StreamEventSourceEventMap = {\n progress: ProgressEvent;\n complete: CompleteEvent;\n size: SizeEvent;\n completion: CompletionEvent;\n heartbeat: HeartbeatEvent;\n message: {\n id: string | undefined;\n data: string;\n };\n end: Array<unknown>;\n error: Error;\n};\n\nexport type ProgressEvent = {\n type: \"progress\";\n data: {\n /** Progress events are sent as a percentage of the total render time.\n * This is a number between 0 and 1.\n */\n progress: number;\n };\n};\nexport type CompleteEvent = { type: \"complete\"; data: object };\nexport type SizeEvent = { type: \"size\"; data: { size: number } };\nexport type CompletionEvent = { type: \"completion\"; data: { count: number } };\nexport type HeartbeatEvent = { type: \"heartbeat\"; data: { timestamp: string } };\n\nexport class StreamEventSource {\n private stream: ReadableStream;\n private activeReader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private decoder = new TextDecoder();\n private parser;\n private listeners: {\n [K in keyof StreamEventSourceEventMap]?: EventCallback<StreamEventSourceEventMap[K]>[];\n } = {};\n private abortController: AbortController;\n constructor(stream: ReadableStream, abortController: AbortController) {\n if (!stream) {\n console.error(\"StreamEventSource: Stream is null or undefined\");\n throw new Error(\"Stream is required\");\n }\n this.stream = stream;\n this.abortController = abortController;\n\n // Create parser instance\n this.parser = createParser({\n onError: (err) => {\n console.error(\"StreamEventSource: Parser error:\", err);\n this.emit(\"error\", err);\n },\n onEvent: (event) => {\n if (event.event) {\n switch (event.event) {\n case \"heartbeat\":\n this.emit(\"heartbeat\", {\n type: \"heartbeat\",\n data: JSON.parse(event.data),\n });\n break;\n case \"size\":\n this.emit(\"size\", {\n type: \"size\",\n data: JSON.parse(event.data),\n });\n break;\n case \"completion\":\n this.emit(\"completion\", {\n type: \"completion\",\n data: JSON.parse(event.data),\n });\n break;\n case \"progress\":\n this.emit(\"progress\", {\n type: \"progress\",\n data: JSON.parse(event.data),\n });\n break;\n case \"complete\":\n this.emit(\"complete\", {\n type: \"complete\",\n data: JSON.parse(event.data),\n });\n break;\n case \"error\":\n log(\"StreamEventSource: Error event\", event.data);\n this.emit(\"error\", new Error(event.data));\n break;\n default:\n this.emit(\"error\", new Error(`Unknown event: ${event.event} data: ${event.data}`));\n }\n } else {\n this.emit(\"message\", {\n id: event.id,\n data: event.data,\n });\n }\n },\n });\n\n this.startReading().catch((error) => {\n console.error(\"StreamEventSource: Error in startReading:\", error);\n this.emit(\"error\", error);\n });\n\n this.abortController.signal.addEventListener(\"abort\", () => {\n this.close();\n });\n }\n\n on<K extends keyof StreamEventSourceEventMap>(\n event: K,\n callback: EventCallback<StreamEventSourceEventMap[K]>,\n ) {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event]?.push(callback);\n return this;\n }\n\n off<K extends keyof StreamEventSourceEventMap>(\n event: K,\n callback: EventCallback<StreamEventSourceEventMap[K]>,\n ) {\n const listeners = this.listeners[event];\n if (listeners) {\n const index = listeners.indexOf(callback);\n if (index !== -1) {\n listeners.splice(index, 1);\n }\n }\n return this;\n }\n\n protected emit<K extends keyof StreamEventSourceEventMap>(\n event: K,\n data: StreamEventSourceEventMap[K],\n ) {\n for (const callback of this.listeners[event] ?? []) {\n callback(data);\n }\n }\n\n whenClosed() {\n return new Promise<void>((resolve) => {\n this.on(\"end\", () => resolve());\n });\n }\n\n private async startReading() {\n try {\n this.activeReader = this.stream.getReader();\n while (true) {\n const { done, value } = await this.activeReader.read();\n if (done) break;\n\n const chunk = this.decoder.decode(value);\n if (!value) {\n throw new Error(\"Chunk is null\");\n }\n this.parser.feed(chunk);\n }\n this.activeReader = null;\n this.emit(\"end\", []);\n } catch (error) {\n console.error(\"StreamEventSource: Error reading stream:\", error);\n if (error instanceof Error) {\n this.emit(\"error\", error);\n } else {\n this.emit(\"error\", new Error(String(error)));\n }\n }\n }\n\n close() {\n if (this.activeReader) {\n this.activeReader = null;\n }\n this.parser.reset();\n }\n\n abort() {\n this.abortController.abort();\n }\n}\n"],"mappings":";;;;;;;AAGA,MAAM,yBAAY,uBAAuB;AA+BzC,IAAa,oB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js","names":[],"sources":["../src/StreamEventSource.ts"],"sourcesContent":["import debug from \"debug\";\nimport { createParser } from \"eventsource-parser\";\n\nconst log = debug(\"ef:StreamEventSource\");\n\nexport type EventCallback<T> = (event: T) => void;\nexport type StreamEventSourceEventMap = {\n progress: ProgressEvent;\n complete: CompleteEvent;\n size: SizeEvent;\n completion: CompletionEvent;\n heartbeat: HeartbeatEvent;\n message: {\n id: string | undefined;\n data: string;\n };\n end: Array<unknown>;\n error: Error;\n};\n\nexport type ProgressEvent = {\n type: \"progress\";\n data: {\n /** Progress events are sent as a percentage of the total render time.\n * This is a number between 0 and 1.\n */\n progress: number;\n };\n};\nexport type CompleteEvent = { type: \"complete\"; data: object };\nexport type SizeEvent = { type: \"size\"; data: { size: number } };\nexport type CompletionEvent = { type: \"completion\"; data: { count: number } };\nexport type HeartbeatEvent = { type: \"heartbeat\"; data: { timestamp: string } };\n\nexport class StreamEventSource {\n private stream: ReadableStream;\n private activeReader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private decoder = new TextDecoder();\n private parser;\n private listeners: {\n [K in keyof StreamEventSourceEventMap]?: EventCallback
|
|
1
|
+
{"version":3,"file":"StreamEventSource.js","names":[],"sources":["../src/StreamEventSource.ts"],"sourcesContent":["import debug from \"debug\";\nimport { createParser } from \"eventsource-parser\";\n\nconst log = debug(\"ef:StreamEventSource\");\n\nexport type EventCallback<T> = (event: T) => void;\nexport type StreamEventSourceEventMap = {\n progress: ProgressEvent;\n complete: CompleteEvent;\n size: SizeEvent;\n completion: CompletionEvent;\n heartbeat: HeartbeatEvent;\n message: {\n id: string | undefined;\n data: string;\n };\n end: Array<unknown>;\n error: Error;\n};\n\nexport type ProgressEvent = {\n type: \"progress\";\n data: {\n /** Progress events are sent as a percentage of the total render time.\n * This is a number between 0 and 1.\n */\n progress: number;\n };\n};\nexport type CompleteEvent = { type: \"complete\"; data: object };\nexport type SizeEvent = { type: \"size\"; data: { size: number } };\nexport type CompletionEvent = { type: \"completion\"; data: { count: number } };\nexport type HeartbeatEvent = { type: \"heartbeat\"; data: { timestamp: string } };\n\nexport class StreamEventSource {\n private stream: ReadableStream;\n private activeReader: ReadableStreamDefaultReader<Uint8Array> | null = null;\n private decoder = new TextDecoder();\n private parser;\n private listeners: {\n [K in keyof StreamEventSourceEventMap]?: EventCallback<StreamEventSourceEventMap[K]>[];\n } = {};\n private abortController: AbortController;\n constructor(stream: ReadableStream, abortController: AbortController) {\n if (!stream) {\n console.error(\"StreamEventSource: Stream is null or undefined\");\n throw new Error(\"Stream is required\");\n }\n this.stream = stream;\n this.abortController = abortController;\n\n // Create parser instance\n this.parser = createParser({\n onError: (err) => {\n console.error(\"StreamEventSource: Parser error:\", err);\n this.emit(\"error\", err);\n },\n onEvent: (event) => {\n if (event.event) {\n switch (event.event) {\n case \"heartbeat\":\n this.emit(\"heartbeat\", {\n type: \"heartbeat\",\n data: JSON.parse(event.data),\n });\n break;\n case \"size\":\n this.emit(\"size\", {\n type: \"size\",\n data: JSON.parse(event.data),\n });\n break;\n case \"completion\":\n this.emit(\"completion\", {\n type: \"completion\",\n data: JSON.parse(event.data),\n });\n break;\n case \"progress\":\n this.emit(\"progress\", {\n type: \"progress\",\n data: JSON.parse(event.data),\n });\n break;\n case \"complete\":\n this.emit(\"complete\", {\n type: \"complete\",\n data: JSON.parse(event.data),\n });\n break;\n case \"error\":\n log(\"StreamEventSource: Error event\", event.data);\n this.emit(\"error\", new Error(event.data));\n break;\n default:\n this.emit(\"error\", new Error(`Unknown event: ${event.event} data: ${event.data}`));\n }\n } else {\n this.emit(\"message\", {\n id: event.id,\n data: event.data,\n });\n }\n },\n });\n\n this.startReading().catch((error) => {\n console.error(\"StreamEventSource: Error in startReading:\", error);\n this.emit(\"error\", error);\n });\n\n this.abortController.signal.addEventListener(\"abort\", () => {\n this.close();\n });\n }\n\n on<K extends keyof StreamEventSourceEventMap>(\n event: K,\n callback: EventCallback<StreamEventSourceEventMap[K]>,\n ) {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event]?.push(callback);\n return this;\n }\n\n off<K extends keyof StreamEventSourceEventMap>(\n event: K,\n callback: EventCallback<StreamEventSourceEventMap[K]>,\n ) {\n const listeners = this.listeners[event];\n if (listeners) {\n const index = listeners.indexOf(callback);\n if (index !== -1) {\n listeners.splice(index, 1);\n }\n }\n return this;\n }\n\n protected emit<K extends keyof StreamEventSourceEventMap>(\n event: K,\n data: StreamEventSourceEventMap[K],\n ) {\n for (const callback of this.listeners[event] ?? []) {\n callback(data);\n }\n }\n\n whenClosed() {\n return new Promise<void>((resolve) => {\n this.on(\"end\", () => resolve());\n });\n }\n\n private async startReading() {\n try {\n this.activeReader = this.stream.getReader();\n while (true) {\n const { done, value } = await this.activeReader.read();\n if (done) break;\n\n const chunk = this.decoder.decode(value);\n if (!value) {\n throw new Error(\"Chunk is null\");\n }\n this.parser.feed(chunk);\n }\n this.activeReader = null;\n this.emit(\"end\", []);\n } catch (error) {\n console.error(\"StreamEventSource: Error reading stream:\", error);\n if (error instanceof Error) {\n this.emit(\"error\", error);\n } else {\n this.emit(\"error\", new Error(String(error)));\n }\n }\n }\n\n close() {\n if (this.activeReader) {\n this.activeReader = null;\n }\n this.parser.reset();\n }\n\n abort() {\n this.abortController.abort();\n }\n}\n"],"mappings":";;;;AAGA,MAAM,MAAM,MAAM,uBAAuB;AA+BzC,IAAa,oBAAb,MAA+B;CAS7B,YAAY,QAAwB,iBAAkC;sBAPC;iBACrD,IAAI,aAAa;mBAI/B,EAAE;AAGJ,MAAI,CAAC,QAAQ;AACX,WAAQ,MAAM,iDAAiD;AAC/D,SAAM,IAAI,MAAM,qBAAqB;;AAEvC,OAAK,SAAS;AACd,OAAK,kBAAkB;AAGvB,OAAK,SAAS,aAAa;GACzB,UAAU,QAAQ;AAChB,YAAQ,MAAM,oCAAoC,IAAI;AACtD,SAAK,KAAK,SAAS,IAAI;;GAEzB,UAAU,UAAU;AAClB,QAAI,MAAM,MACR,SAAQ,MAAM,OAAd;KACE,KAA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;CAGT,AAAU,KACR,OACA,MACA;AACA,OAAK,MAAM,YAAY,KAAK,UAAU,UAAU,EAAE,CAChD,UAAS,KAAK;;CAIlB,aAAa;AACX,SAAO,IAAI,SAAe,YAAY;AACpC,QAAK,GAAG,aAAa,SAAS,CAAC;IAC/B;;CAGJ,MAAc,eAAe;AAC3B,MAAI;AACF,QAAK,eAAe,KAAK,OAAO,WAAW;AAC3C,UAAO,MAAM;IACX,MAAM,EAAE,MAAM,UAAU,MAAM,KAAK,aAAa,MAAM;AACtD,QAAI,KAAM;IAEV,MAAM,QAAQ,KAAK,QAAQ,OAAO,MAAM;AACxC,QAAI,CAAC,MACH,OAAM,IAAI,MAAM,gBAAgB;AAElC,SAAK,OAAO,KAAK,MAAM;;AAEzB,QAAK,eAAe;AACpB,QAAK,KAAK,OAAO,EAAE,CAAC;WACb,OAAO;AACd,WAAQ,MAAM,4CAA4C,MAAM;AAChE,OAAI,iBAAiB,MACnB,MAAK,KAAK,SAAS,MAAM;OAEzB,MAAK,KAAK,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;;;CAKlD,QAAQ;AACN,MAAI,KAAK,aACP,MAAK,eAAe;AAEtB,OAAK,OAAO,OAAO;;CAGrB,QAAQ;AACN,OAAK,gBAAgB,OAAO"}
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs","names":["requestInit: RequestInit","StreamEventSource","#efHost","#token"],"sources":["../src/client.ts"],"sourcesContent":["import debug from \"debug\";\nimport { StreamEventSource } from \"./StreamEventSource.js\";\n\nconst log = debug(\"ef:api:client\");\n\nexport class Client {\n #token?: string;\n #efHost: string;\n\n constructor(token?: string, efHost = \"https://editframe.com\") {\n log(\"Creating client with efHost\", { efHost, tokenIsSet: !!token });\n this.#token = token;\n this.#efHost = efHost;\n\n // Only validate token if provided\n if (token) {\n const { apiKey, apiSecret } =\n token.match(/^(?<apiSecret>ef_[^_]+)_(?<apiKey>.+)$/)?.groups ?? {};\n\n if (!apiKey || !apiSecret) {\n throw new Error(\"Invalid token format. Must look like: ef_{}_{}\");\n }\n }\n }\n\n authenticatedEventSource = async (path: string, init: RequestInit = {}) => {\n const abortController = new AbortController();\n\n const requestInit: RequestInit = {\n ...init,\n };\n\n // if (process.env.NODE_ENV !== \"test\") {\n requestInit.signal ??= abortController.signal;\n // }\n\n const response = await this.authenticatedFetch(path, requestInit);\n if (response.body === null) {\n throw new Error(\"Could not create event source. Response body is null.\");\n }\n\n return new StreamEventSource(response.body, abortController);\n };\n\n authenticatedFetch = async (
|
|
1
|
+
{"version":3,"file":"client.cjs","names":["requestInit: RequestInit","StreamEventSource","#efHost","#token"],"sources":["../src/client.ts"],"sourcesContent":["import debug from \"debug\";\nimport { StreamEventSource } from \"./StreamEventSource.js\";\n\nconst log = debug(\"ef:api:client\");\n\nexport class Client {\n #token?: string;\n #efHost: string;\n\n constructor(token?: string, efHost = \"https://editframe.com\") {\n log(\"Creating client with efHost\", { efHost, tokenIsSet: !!token });\n this.#token = token;\n this.#efHost = efHost;\n\n // Only validate token if provided\n if (token) {\n const { apiKey, apiSecret } =\n token.match(/^(?<apiSecret>ef_[^_]+)_(?<apiKey>.+)$/)?.groups ?? {};\n\n if (!apiKey || !apiSecret) {\n throw new Error(\"Invalid token format. Must look like: ef_{}_{}\");\n }\n }\n }\n\n authenticatedEventSource = async (path: string, init: RequestInit = {}) => {\n const abortController = new AbortController();\n\n const requestInit: RequestInit = {\n ...init,\n };\n\n // if (process.env.NODE_ENV !== \"test\") {\n requestInit.signal ??= abortController.signal;\n // }\n\n const response = await this.authenticatedFetch(path, requestInit);\n if (response.body === null) {\n throw new Error(\"Could not create event source. Response body is null.\");\n }\n\n return new StreamEventSource(response.body, abortController);\n };\n\n authenticatedFetch = async (path: string, init: RequestInit & { duplex?: \"half\" } = {}) => {\n init.headers ||= {};\n const url = new URL(path, this.#efHost);\n\n log(\n \"Authenticated fetch\",\n { url: url.toString(), init },\n this.#token ? \"(Token will be added as Bearer token)\" : \"(Using session cookie)\",\n );\n\n // Only add Authorization header if token is present\n if (this.#token) {\n Object.assign(init.headers, {\n Authorization: `Bearer ${this.#token}`,\n });\n }\n\n // Always include Content-Type\n Object.assign(init.headers, {\n \"Content-Type\": \"application/json\",\n });\n\n // Add credentials: 'include' for cookie support\n init.credentials = \"include\";\n\n try {\n const response = await fetch(url, init);\n\n log(\"Authenticated fetch response\", response.status, response.statusText);\n return response;\n } catch (error) {\n console.error(\"Client authenticatedFetch error\", url, error);\n throw error;\n }\n };\n}\n"],"mappings":";;;;;;AAGA,MAAM,yBAAY,gBAAgB;AAElC,IAAa,SAAb,MAAoB;CAClB;CACA;CAEA,YAAY,OAAgB,SAAS,yBAAyB;kCAgBnC,OAAO,MAAc,OAAoB,EAAE,KAAK;GACzE,MAAM,kBAAkB,IAAI,iBAAiB;GAE7C,MAAMA,cAA2B,EAC/B,GAAG,MACJ;AAGD,eAAY,WAAW,gBAAgB;GAGvC,MAAM,WAAW,MAAM,KAAK,mBAAmB,MAAM,YAAY;AACjE,OAAI,SAAS,SAAS,KACpB,OAAM,IAAI,MAAM,wDAAwD;AAG1E,UAAO,IAAIC,4CAAkB,SAAS,MAAM,gBAAgB;;4BAGzC,OAAO,MAAc,OAA0C,EAAE,KAAK;AACzF,QAAK,YAAY,EAAE;GACnB,MAAM,MAAM,IAAI,IAAI,MAAM,MAAKC,OAAQ;AAEvC,OACE,uBACA;IAAE,KAAK,IAAI,UAAU;IAAE;IAAM,EAC7B,MAAKC,QAAS,0CAA0C,yBACzD;AAGD,OAAI,MAAKA,MACP,QAAO,OAAO,KAAK,SAAS,EAC1B,eAAe,UAAU,MAAKA,SAC/B,CAAC;AAIJ,UAAO,OAAO,KAAK,SAAS,EAC1B,gBAAgB,oBACjB,CAAC;AAGF,QAAK,cAAc;AAEnB,OAAI;IACF,MAAM,WAAW,MAAM,MAAM,KAAK,KAAK;AAEvC,QAAI,gCAAgC,SAAS,QAAQ,SAAS,WAAW;AACzE,WAAO;YACA,OAAO;AACd,YAAQ,MAAM,mCAAmC,KAAK,MAAM;AAC5D,UAAM;;;AAlER,MAAI,+BAA+B;GAAE;GAAQ,YAAY,CAAC,CAAC;GAAO,CAAC;AACnE,QAAKA,QAAS;AACd,QAAKD,SAAU;AAGf,MAAI,OAAO;GACT,MAAM,EAAE,QAAQ,cACd,MAAM,MAAM,yCAAyC,EAAE,UAAU,EAAE;AAErE,OAAI,CAAC,UAAU,CAAC,UACd,OAAM,IAAI,MAAM,iDAAiD"}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["requestInit: RequestInit","#efHost","#token"],"sources":["../src/client.ts"],"sourcesContent":["import debug from \"debug\";\nimport { StreamEventSource } from \"./StreamEventSource.js\";\n\nconst log = debug(\"ef:api:client\");\n\nexport class Client {\n #token?: string;\n #efHost: string;\n\n constructor(token?: string, efHost = \"https://editframe.com\") {\n log(\"Creating client with efHost\", { efHost, tokenIsSet: !!token });\n this.#token = token;\n this.#efHost = efHost;\n\n // Only validate token if provided\n if (token) {\n const { apiKey, apiSecret } =\n token.match(/^(?<apiSecret>ef_[^_]+)_(?<apiKey>.+)$/)?.groups ?? {};\n\n if (!apiKey || !apiSecret) {\n throw new Error(\"Invalid token format. Must look like: ef_{}_{}\");\n }\n }\n }\n\n authenticatedEventSource = async (path: string, init: RequestInit = {}) => {\n const abortController = new AbortController();\n\n const requestInit: RequestInit = {\n ...init,\n };\n\n // if (process.env.NODE_ENV !== \"test\") {\n requestInit.signal ??= abortController.signal;\n // }\n\n const response = await this.authenticatedFetch(path, requestInit);\n if (response.body === null) {\n throw new Error(\"Could not create event source. Response body is null.\");\n }\n\n return new StreamEventSource(response.body, abortController);\n };\n\n authenticatedFetch = async (
|
|
1
|
+
{"version":3,"file":"client.js","names":["requestInit: RequestInit","#efHost","#token"],"sources":["../src/client.ts"],"sourcesContent":["import debug from \"debug\";\nimport { StreamEventSource } from \"./StreamEventSource.js\";\n\nconst log = debug(\"ef:api:client\");\n\nexport class Client {\n #token?: string;\n #efHost: string;\n\n constructor(token?: string, efHost = \"https://editframe.com\") {\n log(\"Creating client with efHost\", { efHost, tokenIsSet: !!token });\n this.#token = token;\n this.#efHost = efHost;\n\n // Only validate token if provided\n if (token) {\n const { apiKey, apiSecret } =\n token.match(/^(?<apiSecret>ef_[^_]+)_(?<apiKey>.+)$/)?.groups ?? {};\n\n if (!apiKey || !apiSecret) {\n throw new Error(\"Invalid token format. Must look like: ef_{}_{}\");\n }\n }\n }\n\n authenticatedEventSource = async (path: string, init: RequestInit = {}) => {\n const abortController = new AbortController();\n\n const requestInit: RequestInit = {\n ...init,\n };\n\n // if (process.env.NODE_ENV !== \"test\") {\n requestInit.signal ??= abortController.signal;\n // }\n\n const response = await this.authenticatedFetch(path, requestInit);\n if (response.body === null) {\n throw new Error(\"Could not create event source. Response body is null.\");\n }\n\n return new StreamEventSource(response.body, abortController);\n };\n\n authenticatedFetch = async (path: string, init: RequestInit & { duplex?: \"half\" } = {}) => {\n init.headers ||= {};\n const url = new URL(path, this.#efHost);\n\n log(\n \"Authenticated fetch\",\n { url: url.toString(), init },\n this.#token ? \"(Token will be added as Bearer token)\" : \"(Using session cookie)\",\n );\n\n // Only add Authorization header if token is present\n if (this.#token) {\n Object.assign(init.headers, {\n Authorization: `Bearer ${this.#token}`,\n });\n }\n\n // Always include Content-Type\n Object.assign(init.headers, {\n \"Content-Type\": \"application/json\",\n });\n\n // Add credentials: 'include' for cookie support\n init.credentials = \"include\";\n\n try {\n const response = await fetch(url, init);\n\n log(\"Authenticated fetch response\", response.status, response.statusText);\n return response;\n } catch (error) {\n console.error(\"Client authenticatedFetch error\", url, error);\n throw error;\n }\n };\n}\n"],"mappings":";;;;AAGA,MAAM,MAAM,MAAM,gBAAgB;AAElC,IAAa,SAAb,MAAoB;CAClB;CACA;CAEA,YAAY,OAAgB,SAAS,yBAAyB;kCAgBnC,OAAO,MAAc,OAAoB,EAAE,KAAK;GACzE,MAAM,kBAAkB,IAAI,iBAAiB;GAE7C,MAAMA,cAA2B,EAC/B,GAAG,MACJ;AAGD,eAAY,WAAW,gBAAgB;GAGvC,MAAM,WAAW,MAAM,KAAK,mBAAmB,MAAM,YAAY;AACjE,OAAI,SAAS,SAAS,KACpB,OAAM,IAAI,MAAM,wDAAwD;AAG1E,UAAO,IAAI,kBAAkB,SAAS,MAAM,gBAAgB;;4BAGzC,OAAO,MAAc,OAA0C,EAAE,KAAK;AACzF,QAAK,YAAY,EAAE;GACnB,MAAM,MAAM,IAAI,IAAI,MAAM,MAAKC,OAAQ;AAEvC,OACE,uBACA;IAAE,KAAK,IAAI,UAAU;IAAE;IAAM,EAC7B,MAAKC,QAAS,0CAA0C,yBACzD;AAGD,OAAI,MAAKA,MACP,QAAO,OAAO,KAAK,SAAS,EAC1B,eAAe,UAAU,MAAKA,SAC/B,CAAC;AAIJ,UAAO,OAAO,KAAK,SAAS,EAC1B,gBAAgB,oBACjB,CAAC;AAGF,QAAK,cAAc;AAEnB,OAAI;IACF,MAAM,WAAW,MAAM,MAAM,KAAK,KAAK;AAEvC,QAAI,gCAAgC,SAAS,QAAQ,SAAS,WAAW;AACzE,WAAO;YACA,OAAO;AACd,YAAQ,MAAM,mCAAmC,KAAK,MAAM;AAC5D,UAAM;;;AAlER,MAAI,+BAA+B;GAAE;GAAQ,YAAY,CAAC,CAAC;GAAO,CAAC;AACnE,QAAKA,QAAS;AACd,QAAKD,SAAU;AAGf,MAAI,OAAO;GACT,MAAM,EAAE,QAAQ,cACd,MAAM,MAAM,yCAAyC,EAAE,UAAU,EAAE;AAErE,OAAI,CAAC,UAAU,CAAC,UACd,OAAM,IAAI,MAAM,iDAAiD"}
|
package/dist/node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.cjs","names":["createImageFile","CreateImageFilePayload","createUnprocessedFile","uploadUnprocessedReadableStream","createReadableStreamFromReadable","createFile","uploadFile"],"sources":["../src/node.ts"],"sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { basename, extname } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport { lookup } from \"mime-types\";\n\nimport type { Client } from \"./client.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"node.cjs","names":["createImageFile","CreateImageFilePayload","createUnprocessedFile","uploadUnprocessedReadableStream","createReadableStreamFromReadable","createFile","uploadFile"],"sources":["../src/node.ts"],"sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { basename, extname } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport { lookup } from \"mime-types\";\n\nimport type { Client } from \"./client.js\";\nimport { CreateImageFilePayload, createImageFile } from \"./resources/image-file.js\";\nimport {\n createUnprocessedFile,\n type UnprocessedFileUploadDetails,\n uploadUnprocessedReadableStream,\n} from \"./resources/unprocessed-file.js\";\nimport { createFile, type FileType, uploadFile } from \"./resources/file.js\";\n\nexport { createReadableStreamFromReadable } from \"./utils/createReadableStreamFromReadable.js\";\n\nexport const createImageFileFromPath = async (client: Client, path: string) => {\n const fileInfo = await stat(path);\n\n const byte_size = fileInfo.size;\n\n const md5 = await md5FilePath(path);\n\n const mime_type = lookup(path) || null;\n\n return createImageFile(client, {\n ...CreateImageFilePayload.parse({\n md5,\n height: 0,\n width: 0,\n mime_type,\n filename: basename(path),\n byte_size,\n }),\n });\n};\n\nexport const createUnprocessedFileFromPath = async (client: Client, path: string) => {\n const fileInfo = await stat(path);\n\n const byte_size = fileInfo.size;\n\n const md5 = await md5FilePath(path);\n\n return createUnprocessedFile(client, {\n md5,\n filename: basename(path),\n byte_size,\n });\n};\n\nexport const uploadUnprocessedFile = async (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n path: string,\n) => {\n const { createReadStream } = await import(\"node:fs\");\n const readStream = createReadStream(path);\n\n const { createReadableStreamFromReadable } =\n await import(\"./utils/createReadableStreamFromReadable.ts\");\n\n return uploadUnprocessedReadableStream(\n client,\n uploadDetails,\n createReadableStreamFromReadable(readStream),\n );\n};\n\nconst VIDEO_EXTENSIONS = new Set([\n \".mp4\",\n \".mov\",\n \".webm\",\n \".mkv\",\n \".avi\",\n \".m4v\",\n \".mp3\",\n \".wav\",\n \".ogg\",\n \".flac\",\n \".aac\",\n \".m4a\",\n]);\nconst IMAGE_EXTENSIONS = new Set([\".jpg\", \".jpeg\", \".png\", \".gif\", \".webp\", \".svg\"]);\nconst CAPTION_EXTENSIONS = new Set([\".vtt\", \".srt\", \".json\"]);\n\nfunction inferFileType(filePath: string): FileType {\n const ext = extname(filePath).toLowerCase();\n if (VIDEO_EXTENSIONS.has(ext)) return \"video\";\n if (IMAGE_EXTENSIONS.has(ext)) return \"image\";\n if (CAPTION_EXTENSIONS.has(ext)) return \"caption\";\n return \"video\";\n}\n\nexport const upload = async (client: Client, filePath: string) => {\n const fileInfo = await stat(filePath);\n const byte_size = fileInfo.size;\n const md5 = await md5FilePath(filePath);\n const filename = basename(filePath);\n const type = inferFileType(filePath);\n const mime_type = lookup(filePath) || undefined;\n\n const file = await createFile(client, {\n filename,\n type,\n byte_size,\n md5,\n mime_type,\n });\n\n const { createReadStream } = await import(\"node:fs\");\n const readStream = createReadStream(filePath);\n const { createReadableStreamFromReadable } =\n await import(\"./utils/createReadableStreamFromReadable.ts\");\n\n const uploadIterator = uploadFile(\n client,\n { id: file.id, byte_size, type },\n createReadableStreamFromReadable(readStream),\n );\n\n return { file, uploadIterator };\n};\n\nexport * from \"./index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,0BAA0B,OAAO,QAAgB,SAAiB;CAG7E,MAAM,aAFW,iCAAW,KAAK,EAEN;CAE3B,MAAM,MAAM,0CAAkB,KAAK;CAEnC,MAAM,mCAAmB,KAAK,IAAI;AAElC,QAAOA,mCAAgB,QAAQ,EAC7B,GAAGC,0CAAuB,MAAM;EAC9B;EACA,QAAQ;EACR,OAAO;EACP;EACA,kCAAmB,KAAK;EACxB;EACD,CAAC,EACH,CAAC;;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gBANQC,wBACrB,QACA;GAAE,IAAI,KAAK;GAAI;GAAW;GAAM,EAChCF,mCAAiC,WAAW,CAC7C;EAE8B"}
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":["path","createReadableStreamFromReadable"],"sources":["../src/node.ts"],"sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { basename, extname } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport { lookup } from \"mime-types\";\n\nimport type { Client } from \"./client.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"node.js","names":["path","createReadableStreamFromReadable"],"sources":["../src/node.ts"],"sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { basename, extname } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport { lookup } from \"mime-types\";\n\nimport type { Client } from \"./client.js\";\nimport { CreateImageFilePayload, createImageFile } from \"./resources/image-file.js\";\nimport {\n createUnprocessedFile,\n type UnprocessedFileUploadDetails,\n uploadUnprocessedReadableStream,\n} from \"./resources/unprocessed-file.js\";\nimport { createFile, type FileType, uploadFile } from \"./resources/file.js\";\n\nexport { createReadableStreamFromReadable } from \"./utils/createReadableStreamFromReadable.js\";\n\nexport const createImageFileFromPath = async (client: Client, path: string) => {\n const fileInfo = await stat(path);\n\n const byte_size = fileInfo.size;\n\n const md5 = await md5FilePath(path);\n\n const mime_type = lookup(path) || null;\n\n return createImageFile(client, {\n ...CreateImageFilePayload.parse({\n md5,\n height: 0,\n width: 0,\n mime_type,\n filename: basename(path),\n byte_size,\n }),\n });\n};\n\nexport const createUnprocessedFileFromPath = async (client: Client, path: string) => {\n const fileInfo = await stat(path);\n\n const byte_size = fileInfo.size;\n\n const md5 = await md5FilePath(path);\n\n return createUnprocessedFile(client, {\n md5,\n filename: basename(path),\n byte_size,\n });\n};\n\nexport const uploadUnprocessedFile = async (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n path: string,\n) => {\n const { createReadStream } = await import(\"node:fs\");\n const readStream = createReadStream(path);\n\n const { createReadableStreamFromReadable } =\n await import(\"./utils/createReadableStreamFromReadable.ts\");\n\n return uploadUnprocessedReadableStream(\n client,\n uploadDetails,\n createReadableStreamFromReadable(readStream),\n );\n};\n\nconst VIDEO_EXTENSIONS = new Set([\n \".mp4\",\n \".mov\",\n \".webm\",\n \".mkv\",\n \".avi\",\n \".m4v\",\n \".mp3\",\n \".wav\",\n \".ogg\",\n \".flac\",\n \".aac\",\n \".m4a\",\n]);\nconst IMAGE_EXTENSIONS = new Set([\".jpg\", \".jpeg\", \".png\", \".gif\", \".webp\", \".svg\"]);\nconst CAPTION_EXTENSIONS = new Set([\".vtt\", \".srt\", \".json\"]);\n\nfunction inferFileType(filePath: string): FileType {\n const ext = extname(filePath).toLowerCase();\n if (VIDEO_EXTENSIONS.has(ext)) return \"video\";\n if (IMAGE_EXTENSIONS.has(ext)) return \"image\";\n if (CAPTION_EXTENSIONS.has(ext)) return \"caption\";\n return \"video\";\n}\n\nexport const upload = async (client: Client, filePath: string) => {\n const fileInfo = await stat(filePath);\n const byte_size = fileInfo.size;\n const md5 = await md5FilePath(filePath);\n const filename = basename(filePath);\n const type = inferFileType(filePath);\n const mime_type = lookup(filePath) || undefined;\n\n const file = await createFile(client, {\n filename,\n type,\n byte_size,\n md5,\n mime_type,\n });\n\n const { createReadStream } = await import(\"node:fs\");\n const readStream = createReadStream(filePath);\n const { createReadableStreamFromReadable } =\n await import(\"./utils/createReadableStreamFromReadable.ts\");\n\n const uploadIterator = uploadFile(\n client,\n { id: file.id, byte_size, type },\n createReadableStreamFromReadable(readStream),\n );\n\n return { file, uploadIterator };\n};\n\nexport * from \"./index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,0BAA0B,OAAO,QAAgB,WAAiB;CAG7E,MAAM,aAFW,MAAM,KAAKA,OAAK,EAEN;CAE3B,MAAM,MAAM,MAAM,YAAYA,OAAK;CAEnC,MAAM,YAAY,OAAOA,O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EACpC;EACA;EACA;EACA;EACA,WAPgB,OAAO,SAAS,IAAI;EAQrC,CAAC;CAEF,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,aAAa,iBAAiB,SAAS;CAC7C,MAAM,EAAE,yEACN,MAAM,OAAO;AAQf,QAAO;EAAE;EAAM,gBANQ,WACrB,QACA;GAAE,IAAI,KAAK;GAAI;GAAW;GAAM,EAChCA,mCAAiC,WAAW,CAC7C;EAE8B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caption-file.cjs","names":["z"],"sources":["../../src/resources/caption-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:caption-file\");\n\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const CreateCaptionFilePayload = z.object({\n /**\n * The md5 hash of the caption file\n */\n md5: z.string(),\n /**\n * The filename of the caption file\n */\n filename: z.string(),\n /**\n * The size of the caption file in bytes\n */\n byte_size: z.number().int().max(MAX_CAPTION_SIZE),\n});\n\nexport type CreateCaptionFilePayload = z.infer<typeof CreateCaptionFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateCaptionFileResult {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupCaptionFileByMd5Result {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\nconst restrictSize = (size: number) => {\n if (size > MAX_CAPTION_SIZE) {\n throw new Error(
|
|
1
|
+
{"version":3,"file":"caption-file.cjs","names":["z"],"sources":["../../src/resources/caption-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:caption-file\");\n\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const CreateCaptionFilePayload = z.object({\n /**\n * The md5 hash of the caption file\n */\n md5: z.string(),\n /**\n * The filename of the caption file\n */\n filename: z.string(),\n /**\n * The size of the caption file in bytes\n */\n byte_size: z.number().int().max(MAX_CAPTION_SIZE),\n});\n\nexport type CreateCaptionFilePayload = z.infer<typeof CreateCaptionFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateCaptionFileResult {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupCaptionFileByMd5Result {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\nconst restrictSize = (size: number) => {\n if (size > MAX_CAPTION_SIZE) {\n throw new Error(`File size ${size} bytes exceeds limit ${MAX_CAPTION_SIZE} bytes\\n`);\n }\n};\n\n/**\n * Create a caption file\n * @param client - The authenticated client to use for the request\n * @param payload - The payload to send to the server\n * @returns The result of the request\n * @example\n * ```ts\n * const result = await createCaptionFile(client, {\n * id: \"123\",\n * filename: \"caption.srt\",\n * });\n * console.log(result);\n * ```\n * @category CaptionFile\n * @resource\n * @beta\n * @deprecated Use the unified file API from ./file.js instead\n */\nexport const createCaptionFile = async (client: Client, payload: CreateCaptionFilePayload) => {\n log(\"Creating caption file\", payload);\n restrictSize(payload.byte_size);\n const response = await client.authenticatedFetch(\"/api/v1/caption_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n log(\"Caption file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateCaptionFileResult;\n }\n\n throw new Error(`Failed to create caption ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadCaptionFile = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading caption file\", fileId);\n restrictSize(fileSize);\n\n const response = await client.authenticatedFetch(`/api/v1/caption_files/${fileId}/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n log(\"Caption file uploaded\", response);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload caption ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupCaptionFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupCaptionFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/caption_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"Caption file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupCaptionFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup caption by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;AAKA,MAAM,yBAAY,sBAAsB;AAExC,MAAM,mBAAmB,OAAO,OAAO;AAEvC,MAAa,2BAA2BA,MAAE,OAAO;CAI/C,KAAKA,MAAE,QAAQ;CAIf,UAAUA,MAAE,QAAQ;CAIpB,WAAWA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,iBAAiB;CAClD,CAAC;AAoCF,MAAM,gBAAgB,SAAiB;AACrC,KAAI,OAAO,iBACT,OAAM,IAAI,MAAM,aAAa,KAAK,uBAAuB,iBAAiB,UAAU;;;;;;;;;;;;;;;;;;;;AAsBxF,MAAa,oBAAoB,OAAO,QAAgB,YAAsC;AAC5F,KAAI,yBAAyB,QAAQ;AACrC,cAAa,QAAQ,UAAU;CAC/B,MAAM,WAAW,MAAM,OAAO,mBAAmB,yBAAyB;EACxE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AACF,KAAI,wBAAwB,SAAS;AAErC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,4BAA4B,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAIvF,MAAa,oBAAoB,OAC/B,QACA,QACA,YACA,aACG;AACH,KAAI,0BAA0B,OAAO;AACrC,cAAa,SAAS;CAEtB,MAAM,WAAW,MAAM,OAAO,mBAAmB,yBAAyB,OAAO,UAAU;EACzF,QAAQ;EACR,MAAM;EACN,QAAQ;EACT,CAAC;AACF,KAAI,yBAAyB,SAAS;AAEtC,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MAAM,4BAA4B,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAIvF,MAAa,yBAAyB,OACpC,QACA,QACiD;CACjD,MAAM,WAAW,MAAM,OAAO,mBAAmB,6BAA6B,OAAO,EACnF,QAAQ,OACT,CAAC;AACF,KAAI,uBAAuB,SAAS;AAEpC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,mCAAmC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caption-file.js","names":[],"sources":["../../src/resources/caption-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:caption-file\");\n\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const CreateCaptionFilePayload = z.object({\n /**\n * The md5 hash of the caption file\n */\n md5: z.string(),\n /**\n * The filename of the caption file\n */\n filename: z.string(),\n /**\n * The size of the caption file in bytes\n */\n byte_size: z.number().int().max(MAX_CAPTION_SIZE),\n});\n\nexport type CreateCaptionFilePayload = z.infer<typeof CreateCaptionFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateCaptionFileResult {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupCaptionFileByMd5Result {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\nconst restrictSize = (size: number) => {\n if (size > MAX_CAPTION_SIZE) {\n throw new Error(
|
|
1
|
+
{"version":3,"file":"caption-file.js","names":[],"sources":["../../src/resources/caption-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:caption-file\");\n\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const CreateCaptionFilePayload = z.object({\n /**\n * The md5 hash of the caption file\n */\n md5: z.string(),\n /**\n * The filename of the caption file\n */\n filename: z.string(),\n /**\n * The size of the caption file in bytes\n */\n byte_size: z.number().int().max(MAX_CAPTION_SIZE),\n});\n\nexport type CreateCaptionFilePayload = z.infer<typeof CreateCaptionFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateCaptionFileResult {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupCaptionFileByMd5Result {\n /**\n * Whether the caption file is complete\n */\n complete: boolean | null;\n /**\n * The id of the caption file\n */\n id: string;\n /**\n * The md5 hash of the caption file\n */\n md5: string;\n}\n\nconst restrictSize = (size: number) => {\n if (size > MAX_CAPTION_SIZE) {\n throw new Error(`File size ${size} bytes exceeds limit ${MAX_CAPTION_SIZE} bytes\\n`);\n }\n};\n\n/**\n * Create a caption file\n * @param client - The authenticated client to use for the request\n * @param payload - The payload to send to the server\n * @returns The result of the request\n * @example\n * ```ts\n * const result = await createCaptionFile(client, {\n * id: \"123\",\n * filename: \"caption.srt\",\n * });\n * console.log(result);\n * ```\n * @category CaptionFile\n * @resource\n * @beta\n * @deprecated Use the unified file API from ./file.js instead\n */\nexport const createCaptionFile = async (client: Client, payload: CreateCaptionFilePayload) => {\n log(\"Creating caption file\", payload);\n restrictSize(payload.byte_size);\n const response = await client.authenticatedFetch(\"/api/v1/caption_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n log(\"Caption file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateCaptionFileResult;\n }\n\n throw new Error(`Failed to create caption ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadCaptionFile = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading caption file\", fileId);\n restrictSize(fileSize);\n\n const response = await client.authenticatedFetch(`/api/v1/caption_files/${fileId}/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n log(\"Caption file uploaded\", response);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload caption ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupCaptionFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupCaptionFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/caption_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"Caption file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupCaptionFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup caption by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;AAKA,MAAM,MAAM,MAAM,sBAAsB;AAExC,MAAM,mBAAmB,OAAO,OAAO;AAEvC,MAAa,2BAA2B,EAAE,OAAO;CAI/C,K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+1 @@
|
|
|
1
|
-
{"version":3,"file":"file.cjs","names":["z","MAX_SIZE_BY_TYPE: Record<FileType, number>","uploadChunks","ProgressIterator"],"sources":["../../src/resources/file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport {\n CreateISOBMFFTrackPayload,\n type CreateISOBMFFTrackResult,\n} from \"./isobmff-track.js\";\n\nconst log = debug(\"ef:api:file\");\n\nconst MAX_VIDEO_SIZE = 1024 * 1024 * 1024; // 1GiB\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const FileType = z.enum([\"video\", \"image\", \"caption\"]);\nexport type FileType = z.infer<typeof FileType>;\n\nexport const FileStatus = z.enum([\n \"created\",\n \"uploading\",\n \"processing\",\n \"ready\",\n \"failed\",\n]);\nexport type FileStatus = z.infer<typeof FileStatus>;\n\nexport const CreateFilePayload = z.object({\n filename: z.string(),\n type: FileType,\n byte_size: z.number().int().positive(),\n md5: z.string().optional(),\n mime_type: z.string().optional(),\n});\n\nexport type CreateFilePayload = z.infer<typeof CreateFilePayload>;\n\nexport interface FileRecord {\n id: string;\n filename: string;\n type: FileType;\n status: FileStatus;\n byte_size: number | null;\n md5: string | null;\n next_byte: number;\n}\n\nexport interface CreateFileResult extends FileRecord {}\n\nexport interface FileDetail extends FileRecord {\n mime_type?: string | null;\n width?: number | null;\n height?: number | null;\n created_at?: string;\n completed_at?: string | null;\n expires_at?: string | null;\n tracks?: Array<{\n track_id: number;\n type: string;\n codec_name: string;\n duration_ms: number;\n byte_size: number;\n }>;\n}\n\nexport interface LookupFileByMd5Result extends FileRecord {}\n\nexport interface TranscribeFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\nexport interface FileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n status: string;\n completed_at: string | null;\n failed_at: string | null;\n}\n\nconst MAX_SIZE_BY_TYPE: Record<FileType, number> = {\n video: MAX_VIDEO_SIZE,\n image: MAX_IMAGE_SIZE,\n caption: MAX_CAPTION_SIZE,\n};\n\nexport const createFile = async (\n client: Client,\n payload: CreateFilePayload,\n) => {\n log(\"Creating a file\", payload);\n CreateFilePayload.parse(payload);\n\n const maxSize = MAX_SIZE_BY_TYPE[payload.type];\n if (payload.byte_size > maxSize) {\n throw new Error(\n `File size ${payload.byte_size} bytes exceeds limit ${maxSize} bytes for type ${payload.type}`,\n );\n }\n\n const response = await client.authenticatedFetch(\"/api/v1/files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateFileResult;\n }\n\n throw new Error(\n `Failed to create file ${response.status} ${response.statusText}`,\n );\n};\n\nexport const uploadFile = (\n client: Client,\n uploadDetails: { id: string; byte_size: number; type: FileType },\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file\", uploadDetails.id);\n\n const maxSize = MAX_SIZE_BY_TYPE[uploadDetails.type];\n\n return uploadChunks(client, {\n url: `/api/v1/files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize,\n });\n};\n\nexport const getFileDetail = async (\n client: Client,\n id: string,\n): Promise<FileDetail> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileDetail;\n }\n\n if (response.status === 404) {\n throw new Error(`File not found: ${id}`);\n }\n\n throw new Error(\n `Failed to get file detail ${response.status} ${response.statusText}`,\n );\n};\n\nexport const lookupFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const deleteFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/delete`,\n {\n method: \"POST\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as { success: boolean };\n }\n\n throw new Error(\n `Failed to delete file ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getFileProcessingProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/files/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const transcribeFile = async (\n client: Client,\n id: string,\n options: { trackId?: number } = {},\n): Promise<TranscribeFileResult> => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/transcribe`,\n {\n method: \"POST\",\n body: JSON.stringify(options),\n },\n );\n\n if (response.ok) {\n return (await response.json()) as TranscribeFileResult;\n }\n\n throw new Error(\n `Failed to transcribe file ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getFileTranscription = async (\n client: Client,\n id: string,\n): Promise<FileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/transcription`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as FileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport type { CreateISOBMFFTrackPayload as CreateFileTrackPayload };\nexport type { CreateISOBMFFTrackResult as CreateFileTrackResult };\n\nexport const createFileTrack = async (\n client: Client,\n fileId: string,\n payload: CreateISOBMFFTrackPayload,\n): Promise<CreateISOBMFFTrackResult> => {\n log(\"Creating file track\", fileId, payload);\n CreateISOBMFFTrackPayload.parse(payload);\n\n const response = await client.authenticatedFetch(\n `/api/v1/files/${fileId}/tracks`,\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n\n log(\"File track created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(\n `Failed to create file track ${response.status} ${response.statusText}`,\n );\n};\n\nexport const uploadFileTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n byteSize: number,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file track\", fileId, trackId);\n\n return uploadChunks(client, {\n url: `/api/v1/files/${fileId}/tracks/${trackId}/upload`,\n fileSize: byteSize,\n fileStream,\n maxSize: MAX_VIDEO_SIZE,\n });\n};\n\nconst FRAGMENT_INDEX_SIZE_LIMIT = 1024 * 1024 * 50; // 50MB\n\nexport const uploadFileIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading file index\", fileId);\n if (fileSize > FRAGMENT_INDEX_SIZE_LIMIT) {\n throw new Error(\n `Fragment index size ${fileSize} exceeds limit of ${FRAGMENT_INDEX_SIZE_LIMIT} bytes`,\n );\n }\n\n const response = await client.authenticatedFetch(\n `/api/v1/files/${fileId}/index/upload`,\n {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n },\n );\n\n log(\"File index uploaded\", response.status, response.statusText);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(\n `Failed to upload file index ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAM,yBAAY,cAAc;AAEhC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,mBAAmB,OAAO,OAAO;AAEvC,MAAa,WAAWA,MAAE,KAAK;CAAC;CAAS;CAAS;CAAU,CAAC;AAG7D,MAAa,aAAaA,MAAE,KAAK;CAC/B;CACA;CACA;CACA;CACA;CACD,CAAC;AAGF,MAAa,oBAAoBA,MAAE,OAAO;CACxC,UAAUA,MAAE,QAAQ;CACpB,MAAM;CACN,WAAWA,MAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CACtC,KAAKA,M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AAO,mBAC5B,iBAAiB,OAAO,UACxB;EACE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CACF;AAED,KAAI,sBAAsB,SAAS,QAAQ,SAAS,WAAW;AAE/D,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAC5D;;AAGH,MAAa,mBACX,QACA,QACA,SACA,UACA,eACG;AACH,KAAI,wBAAwB,QAAQ,QAAQ;AAE5C,QAAOD,kCAAa,QAAQ;EAC1B,KAAK,iBAAiB,OAAO,UAAU,QAAQ;EAC/C,UAAU;EACV;EACA,SAAS;EACV,CAAC;;AAGJ,MAAM,4BAA4B,OAAO,OAAO;AAEhD,MAAa,kBAAkB,OAC7B,QACA,QACA,YACA,aACG;AACH,KAAI,wBAAwB,OAAO;AACnC,KAAI,WAAW,0BACb,OAAM,IAAI,MACR,uBAAuB,SAAS,oBAAoB,0BAA0B,QAC/E;CAGH,MAAM,WAAW,MAAM,OAAO,mBAC5B,iBAAiB,OAAO,gBACxB;EACE,QAAQ;EACR,MAAM;EACN,QAAQ;EACT,CACF;AAED,KAAI,uBAAuB,SAAS,QAAQ,SAAS,WAAW;AAEhE,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MACR,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAC5D"}
|
|
1
|
+
{"version":3,"file":"file.cjs","names":["z","MAX_SIZE_BY_TYPE: Record<FileType, number>","uploadChunks","ProgressIterator"],"sources":["../../src/resources/file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { CreateISOBMFFTrackPayload, type CreateISOBMFFTrackResult } from \"./isobmff-track.js\";\n\nconst log = debug(\"ef:api:file\");\n\nconst MAX_VIDEO_SIZE = 1024 * 1024 * 1024; // 1GiB\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const FileType = z.enum([\"video\", \"image\", \"caption\"]);\nexport type FileType = z.infer<typeof FileType>;\n\nexport const FileStatus = z.enum([\"created\", \"uploading\", \"processing\", \"ready\", \"failed\"]);\nexport type FileStatus = z.infer<typeof FileStatus>;\n\nexport const CreateFilePayload = z.object({\n filename: z.string(),\n type: FileType,\n byte_size: z.number().int().positive(),\n md5: z.string().optional(),\n mime_type: z.string().optional(),\n});\n\nexport type CreateFilePayload = z.infer<typeof CreateFilePayload>;\n\nexport interface FileRecord {\n id: string;\n filename: string;\n type: FileType;\n status: FileStatus;\n byte_size: number | null;\n md5: string | null;\n next_byte: number;\n}\n\nexport interface CreateFileResult extends FileRecord {}\n\nexport interface FileDetail extends FileRecord {\n mime_type?: string | null;\n width?: number | null;\n height?: number | null;\n created_at?: string;\n completed_at?: string | null;\n expires_at?: string | null;\n tracks?: Array<{\n track_id: number;\n type: string;\n codec_name: string;\n duration_ms: number;\n byte_size: number;\n }>;\n}\n\nexport interface LookupFileByMd5Result extends FileRecord {}\n\nexport interface TranscribeFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\nexport interface FileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n status: string;\n completed_at: string | null;\n failed_at: string | null;\n}\n\nconst MAX_SIZE_BY_TYPE: Record<FileType, number> = {\n video: MAX_VIDEO_SIZE,\n image: MAX_IMAGE_SIZE,\n caption: MAX_CAPTION_SIZE,\n};\n\nexport const createFile = async (client: Client, payload: CreateFilePayload) => {\n log(\"Creating a file\", payload);\n CreateFilePayload.parse(payload);\n\n const maxSize = MAX_SIZE_BY_TYPE[payload.type];\n if (payload.byte_size > maxSize) {\n throw new Error(\n `File size ${payload.byte_size} bytes exceeds limit ${maxSize} bytes for type ${payload.type}`,\n );\n }\n\n const response = await client.authenticatedFetch(\"/api/v1/files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateFileResult;\n }\n\n throw new Error(`Failed to create file ${response.status} ${response.statusText}`);\n};\n\nexport const uploadFile = (\n client: Client,\n uploadDetails: { id: string; byte_size: number; type: FileType },\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file\", uploadDetails.id);\n\n const maxSize = MAX_SIZE_BY_TYPE[uploadDetails.type];\n\n return uploadChunks(client, {\n url: `/api/v1/files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize,\n });\n};\n\nexport const getFileDetail = async (client: Client, id: string): Promise<FileDetail> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileDetail;\n }\n\n if (response.status === 404) {\n throw new Error(`File not found: ${id}`);\n }\n\n throw new Error(`Failed to get file detail ${response.status} ${response.statusText}`);\n};\n\nexport const lookupFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(`Failed to lookup file by md5 ${md5} ${response.status} ${response.statusText}`);\n};\n\nexport const deleteFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/delete`, {\n method: \"POST\",\n });\n\n if (response.ok) {\n return (await response.json()) as { success: boolean };\n }\n\n throw new Error(`Failed to delete file ${id} ${response.status} ${response.statusText}`);\n};\n\nexport const getFileProcessingProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(`/api/v1/files/${id}/progress`);\n\n return new ProgressIterator(eventSource);\n};\n\nexport const transcribeFile = async (\n client: Client,\n id: string,\n options: { trackId?: number } = {},\n): Promise<TranscribeFileResult> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/transcribe`, {\n method: \"POST\",\n body: JSON.stringify(options),\n });\n\n if (response.ok) {\n return (await response.json()) as TranscribeFileResult;\n }\n\n throw new Error(`Failed to transcribe file ${id} ${response.status} ${response.statusText}`);\n};\n\nexport const getFileTranscription = async (\n client: Client,\n id: string,\n): Promise<FileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/transcription`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport type { CreateISOBMFFTrackPayload as CreateFileTrackPayload };\nexport type { CreateISOBMFFTrackResult as CreateFileTrackResult };\n\nexport const createFileTrack = async (\n client: Client,\n fileId: string,\n payload: CreateISOBMFFTrackPayload,\n): Promise<CreateISOBMFFTrackResult> => {\n log(\"Creating file track\", fileId, payload);\n CreateISOBMFFTrackPayload.parse(payload);\n\n const response = await client.authenticatedFetch(`/api/v1/files/${fileId}/tracks`, {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File track created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(`Failed to create file track ${response.status} ${response.statusText}`);\n};\n\nexport const uploadFileTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n byteSize: number,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file track\", fileId, trackId);\n\n return uploadChunks(client, {\n url: `/api/v1/files/${fileId}/tracks/${trackId}/upload`,\n fileSize: byteSize,\n fileStream,\n maxSize: MAX_VIDEO_SIZE,\n });\n};\n\nconst FRAGMENT_INDEX_SIZE_LIMIT = 1024 * 1024 * 50; // 50MB\n\nexport const uploadFileIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading file index\", fileId);\n if (fileSize > FRAGMENT_INDEX_SIZE_LIMIT) {\n throw new Error(\n `Fragment index size ${fileSize} exceeds limit of ${FRAGMENT_INDEX_SIZE_LIMIT} bytes`,\n );\n }\n\n const response = await client.authenticatedFetch(`/api/v1/files/${fileId}/index/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n log(\"File index uploaded\", response.status, response.statusText);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload file index ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;;;;AAQA,MAAM,yBAAY,cAAc;AAEhC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,mBAAmB,OAAO,OAAO;AAEvC,MAAa,WAAWA,MAAE,KAAK;CAAC;CAAS;CAAS;CAAU,CAAC;AAG7D,MAAa,aAAaA,MAAE,KAAK;CAAC;CAAW;CAAa;CAAc;CAAS;CAAS,CAAC;AAG3F,MAAa,oBAAoBA,MAAE,OAAO;CACxC,UAAUA,MAAE,QAAQ;CACpB,MAAM;CACN,WAAWA,MAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CACtC,KAAKA,MAAE,QAAQ,CAAC,UAAU;CAC1B,WAAWA,MAAE,QAAQ,CAAC,UAAU;CACjC,CAAC;AAgDF,MAAMC,mBAA6C;CACjD,OAAO;CACP,OAAO;CACP,SAAS;CACV;AAED,MAAa,aAAa,OAAO,QAAgB,YAA+B;AAC9E,KAAI,mBAAmB,QAAQ;AAC/B,mBAAkB,MAAM,QAAQ;CAEhC,MAAM,UAAU,iBAAiB,QAAQ;AACzC,KAAI,QAAQ,YAAY,QACtB,OAAM,IAAI,MACR,aAAa,QAAQ,UAAU,uBAAuB,QAAQ,kBAAkB,QAAQ,OACzF;CAGH,MAAM,WAAW,MAAM,OAAO,mBAAmB,iBAAiB;EAChE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,g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4B,OAAO,OAAO;AAEhD,MAAa,kBAAkB,OAC7B,QACA,QACA,YACA,aACG;AACH,KAAI,wBAAwB,OAAO;AACnC,KAAI,WAAW,0BACb,OAAM,IAAI,MACR,uBAAuB,SAAS,oBAAoB,0BAA0B,QAC/E;CAGH,MAAM,WAAW,MAAM,OAAO,mBAAmB,iBAAiB,OAAO,gBAAgB;EACvF,QAAQ;EACR,MAAM;EACN,QAAQ;EACT,CAAC;AAEF,KAAI,uBAAuB,SAAS,QAAQ,SAAS,WAAW;AAEhE,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MAAM,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","names":["MAX_SIZE_BY_TYPE: Record<FileType, number>"],"sources":["../../src/resources/file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport {\n CreateISOBMFFTrackPayload,\n type CreateISOBMFFTrackResult,\n} from \"./isobmff-track.js\";\n\nconst log = debug(\"ef:api:file\");\n\nconst MAX_VIDEO_SIZE = 1024 * 1024 * 1024; // 1GiB\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const FileType = z.enum([\"video\", \"image\", \"caption\"]);\nexport type FileType = z.infer<typeof FileType>;\n\nexport const FileStatus = z.enum([\n \"created\",\n \"uploading\",\n \"processing\",\n \"ready\",\n \"failed\",\n]);\nexport type FileStatus = z.infer<typeof FileStatus>;\n\nexport const CreateFilePayload = z.object({\n filename: z.string(),\n type: FileType,\n byte_size: z.number().int().positive(),\n md5: z.string().optional(),\n mime_type: z.string().optional(),\n});\n\nexport type CreateFilePayload = z.infer<typeof CreateFilePayload>;\n\nexport interface FileRecord {\n id: string;\n filename: string;\n type: FileType;\n status: FileStatus;\n byte_size: number | null;\n md5: string | null;\n next_byte: number;\n}\n\nexport interface CreateFileResult extends FileRecord {}\n\nexport interface FileDetail extends FileRecord {\n mime_type?: string | null;\n width?: number | null;\n height?: number | null;\n created_at?: string;\n completed_at?: string | null;\n expires_at?: string | null;\n tracks?: Array<{\n track_id: number;\n type: string;\n codec_name: string;\n duration_ms: number;\n byte_size: number;\n }>;\n}\n\nexport interface LookupFileByMd5Result extends FileRecord {}\n\nexport interface TranscribeFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\nexport interface FileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n status: string;\n completed_at: string | null;\n failed_at: string | null;\n}\n\nconst MAX_SIZE_BY_TYPE: Record<FileType, number> = {\n video: MAX_VIDEO_SIZE,\n image: MAX_IMAGE_SIZE,\n caption: MAX_CAPTION_SIZE,\n};\n\nexport const createFile = async (\n client: Client,\n payload: CreateFilePayload,\n) => {\n log(\"Creating a file\", payload);\n CreateFilePayload.parse(payload);\n\n const maxSize = MAX_SIZE_BY_TYPE[payload.type];\n if (payload.byte_size > maxSize) {\n throw new Error(\n `File size ${payload.byte_size} bytes exceeds limit ${maxSize} bytes for type ${payload.type}`,\n );\n }\n\n const response = await client.authenticatedFetch(\"/api/v1/files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateFileResult;\n }\n\n throw new Error(\n `Failed to create file ${response.status} ${response.statusText}`,\n );\n};\n\nexport const uploadFile = (\n client: Client,\n uploadDetails: { id: string; byte_size: number; type: FileType },\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file\", uploadDetails.id);\n\n const maxSize = MAX_SIZE_BY_TYPE[uploadDetails.type];\n\n return uploadChunks(client, {\n url: `/api/v1/files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize,\n });\n};\n\nexport const getFileDetail = async (\n client: Client,\n id: string,\n): Promise<FileDetail> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileDetail;\n }\n\n if (response.status === 404) {\n throw new Error(`File not found: ${id}`);\n }\n\n throw new Error(\n `Failed to get file detail ${response.status} ${response.statusText}`,\n );\n};\n\nexport const lookupFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const deleteFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/delete`,\n {\n method: \"POST\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as { success: boolean };\n }\n\n throw new Error(\n `Failed to delete file ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getFileProcessingProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/files/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const transcribeFile = async (\n client: Client,\n id: string,\n options: { trackId?: number } = {},\n): Promise<TranscribeFileResult> => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/transcribe`,\n {\n method: \"POST\",\n body: JSON.stringify(options),\n },\n );\n\n if (response.ok) {\n return (await response.json()) as TranscribeFileResult;\n }\n\n throw new Error(\n `Failed to transcribe file ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getFileTranscription = async (\n client: Client,\n id: string,\n): Promise<FileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/files/${id}/transcription`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as FileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport type { CreateISOBMFFTrackPayload as CreateFileTrackPayload };\nexport type { CreateISOBMFFTrackResult as CreateFileTrackResult };\n\nexport const createFileTrack = async (\n client: Client,\n fileId: string,\n payload: CreateISOBMFFTrackPayload,\n): Promise<CreateISOBMFFTrackResult> => {\n log(\"Creating file track\", fileId, payload);\n CreateISOBMFFTrackPayload.parse(payload);\n\n const response = await client.authenticatedFetch(\n `/api/v1/files/${fileId}/tracks`,\n {\n method: \"POST\",\n body: JSON.stringify(payload),\n },\n );\n\n log(\"File track created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(\n `Failed to create file track ${response.status} ${response.statusText}`,\n );\n};\n\nexport const uploadFileTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n byteSize: number,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file track\", fileId, trackId);\n\n return uploadChunks(client, {\n url: `/api/v1/files/${fileId}/tracks/${trackId}/upload`,\n fileSize: byteSize,\n fileStream,\n maxSize: MAX_VIDEO_SIZE,\n });\n};\n\nconst FRAGMENT_INDEX_SIZE_LIMIT = 1024 * 1024 * 50; // 50MB\n\nexport const uploadFileIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading file index\", fileId);\n if (fileSize > FRAGMENT_INDEX_SIZE_LIMIT) {\n throw new Error(\n `Fragment index size ${fileSize} exceeds limit of ${FRAGMENT_INDEX_SIZE_LIMIT} bytes`,\n );\n }\n\n const response = await client.authenticatedFetch(\n `/api/v1/files/${fileId}/index/upload`,\n {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n },\n );\n\n log(\"File index uploaded\", response.status, response.statusText);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(\n `Failed to upload file index ${response.status} ${response.statusText}`,\n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AAI,MACR,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAC5D"}
|
|
1
|
+
{"version":3,"file":"file.js","names":["MAX_SIZE_BY_TYPE: Record<FileType, number>"],"sources":["../../src/resources/file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { CreateISOBMFFTrackPayload, type CreateISOBMFFTrackResult } from \"./isobmff-track.js\";\n\nconst log = debug(\"ef:api:file\");\n\nconst MAX_VIDEO_SIZE = 1024 * 1024 * 1024; // 1GiB\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\nconst MAX_CAPTION_SIZE = 1024 * 1024 * 2; // 2MB\n\nexport const FileType = z.enum([\"video\", \"image\", \"caption\"]);\nexport type FileType = z.infer<typeof FileType>;\n\nexport const FileStatus = z.enum([\"created\", \"uploading\", \"processing\", \"ready\", \"failed\"]);\nexport type FileStatus = z.infer<typeof FileStatus>;\n\nexport const CreateFilePayload = z.object({\n filename: z.string(),\n type: FileType,\n byte_size: z.number().int().positive(),\n md5: z.string().optional(),\n mime_type: z.string().optional(),\n});\n\nexport type CreateFilePayload = z.infer<typeof CreateFilePayload>;\n\nexport interface FileRecord {\n id: string;\n filename: string;\n type: FileType;\n status: FileStatus;\n byte_size: number | null;\n md5: string | null;\n next_byte: number;\n}\n\nexport interface CreateFileResult extends FileRecord {}\n\nexport interface FileDetail extends FileRecord {\n mime_type?: string | null;\n width?: number | null;\n height?: number | null;\n created_at?: string;\n completed_at?: string | null;\n expires_at?: string | null;\n tracks?: Array<{\n track_id: number;\n type: string;\n codec_name: string;\n duration_ms: number;\n byte_size: number;\n }>;\n}\n\nexport interface LookupFileByMd5Result extends FileRecord {}\n\nexport interface TranscribeFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\nexport interface FileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n status: string;\n completed_at: string | null;\n failed_at: string | null;\n}\n\nconst MAX_SIZE_BY_TYPE: Record<FileType, number> = {\n video: MAX_VIDEO_SIZE,\n image: MAX_IMAGE_SIZE,\n caption: MAX_CAPTION_SIZE,\n};\n\nexport const createFile = async (client: Client, payload: CreateFilePayload) => {\n log(\"Creating a file\", payload);\n CreateFilePayload.parse(payload);\n\n const maxSize = MAX_SIZE_BY_TYPE[payload.type];\n if (payload.byte_size > maxSize) {\n throw new Error(\n `File size ${payload.byte_size} bytes exceeds limit ${maxSize} bytes for type ${payload.type}`,\n );\n }\n\n const response = await client.authenticatedFetch(\"/api/v1/files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateFileResult;\n }\n\n throw new Error(`Failed to create file ${response.status} ${response.statusText}`);\n};\n\nexport const uploadFile = (\n client: Client,\n uploadDetails: { id: string; byte_size: number; type: FileType },\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file\", uploadDetails.id);\n\n const maxSize = MAX_SIZE_BY_TYPE[uploadDetails.type];\n\n return uploadChunks(client, {\n url: `/api/v1/files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize,\n });\n};\n\nexport const getFileDetail = async (client: Client, id: string): Promise<FileDetail> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileDetail;\n }\n\n if (response.status === 404) {\n throw new Error(`File not found: ${id}`);\n }\n\n throw new Error(`Failed to get file detail ${response.status} ${response.statusText}`);\n};\n\nexport const lookupFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(`Failed to lookup file by md5 ${md5} ${response.status} ${response.statusText}`);\n};\n\nexport const deleteFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/delete`, {\n method: \"POST\",\n });\n\n if (response.ok) {\n return (await response.json()) as { success: boolean };\n }\n\n throw new Error(`Failed to delete file ${id} ${response.status} ${response.statusText}`);\n};\n\nexport const getFileProcessingProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(`/api/v1/files/${id}/progress`);\n\n return new ProgressIterator(eventSource);\n};\n\nexport const transcribeFile = async (\n client: Client,\n id: string,\n options: { trackId?: number } = {},\n): Promise<TranscribeFileResult> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/transcribe`, {\n method: \"POST\",\n body: JSON.stringify(options),\n });\n\n if (response.ok) {\n return (await response.json()) as TranscribeFileResult;\n }\n\n throw new Error(`Failed to transcribe file ${id} ${response.status} ${response.statusText}`);\n};\n\nexport const getFileTranscription = async (\n client: Client,\n id: string,\n): Promise<FileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/files/${id}/transcription`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as FileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport type { CreateISOBMFFTrackPayload as CreateFileTrackPayload };\nexport type { CreateISOBMFFTrackResult as CreateFileTrackResult };\n\nexport const createFileTrack = async (\n client: Client,\n fileId: string,\n payload: CreateISOBMFFTrackPayload,\n): Promise<CreateISOBMFFTrackResult> => {\n log(\"Creating file track\", fileId, payload);\n CreateISOBMFFTrackPayload.parse(payload);\n\n const response = await client.authenticatedFetch(`/api/v1/files/${fileId}/tracks`, {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"File track created\", response.status, response.statusText);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(`Failed to create file track ${response.status} ${response.statusText}`);\n};\n\nexport const uploadFileTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n byteSize: number,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading file track\", fileId, trackId);\n\n return uploadChunks(client, {\n url: `/api/v1/files/${fileId}/tracks/${trackId}/upload`,\n fileSize: byteSize,\n fileStream,\n maxSize: MAX_VIDEO_SIZE,\n });\n};\n\nconst FRAGMENT_INDEX_SIZE_LIMIT = 1024 * 1024 * 50; // 50MB\n\nexport const uploadFileIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading file index\", fileId);\n if (fileSize > FRAGMENT_INDEX_SIZE_LIMIT) {\n throw new Error(\n `Fragment index size ${fileSize} exceeds limit of ${FRAGMENT_INDEX_SIZE_LIMIT} bytes`,\n );\n }\n\n const response = await client.authenticatedFetch(`/api/v1/files/${fileId}/index/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n log(\"File index uploaded\", response.status, response.statusText);\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload file index ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;AAQA,MAAM,MAAM,MAAM,cAAc;AAEhC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,iBAAiB,OAAO,OAAO;AACrC,MAAM,mBAAmB,OAAO,OAAO;AAEvC,MAAa,WAAW,EAAE,KAAK;CAAC;CAAS;CAAS;CAAU,CAAC;AAG7D,MAAa,aAAa,EAAE,KAAK;CAAC;CAAW;CAAa;CAAc;CAAS;CAAS,CAAC;AAG3F,MAAa,oBAAoB,EAAE,OAAO;CACxC,UAAU,EAAE,QAAQ;CACpB,MAAM;CACN,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CACtC,KAAK,EAAE,QAAQ,CAAC,UAAU;CAC1B,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC;AAgDF,MAAMA,mBAA6C;CACjD,OAAO;C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,CAAC;AAEF,KAAI,sBAAsB,SAAS,QAAQ,SAAS,WAAW;AAE/D,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAAa;;AAG1F,MAAa,mBACX,QACA,QACA,SACA,UACA,eACG;AACH,KAAI,wBAAwB,QAAQ,QAAQ;AAE5C,QAAO,aAAa,QAAQ;EAC1B,KAAK,iBAAiB,OAAO,UAAU,QAAQ;EAC/C,UAAU;EACV;EACA,SAAS;EACV,CAAC;;AAGJ,MAAM,4BAA4B,OAAO,OAAO;AAEhD,MAAa,kBAAkB,OAC7B,QACA,QACA,YACA,aACG;AACH,KAAI,wBAAwB,OAAO;AACnC,KAAI,WAAW,0BACb,OAAM,IAAI,MACR,uBAAuB,SAAS,oBAAoB,0BAA0B,QAC/E;CAGH,MAAM,WAAW,MAAM,OAAO,mBAAmB,iBAAiB,OAAO,gBAAgB;EACvF,QAAQ;EACR,MAAM;EACN,QAAQ;EACT,CAAC;AAEF,KAAI,uBAAuB,SAAS,QAAQ,SAAS,WAAW;AAEhE,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MAAM,+BAA+B,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-file.cjs","names":["z","types","uploadChunks"],"sources":["../../src/resources/image-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { types } from \"mime-types\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\n\nconst log = debug(\"ef:api:image-file\");\n\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\n\nexport const ImageFileMimeTypes = z.enum([\n \"image/jpeg\",\n \"image/png\",\n \"image/jpg\",\n \"image/webp\",\n \"image/svg+xml\",\n]);\n\nfunction getFileExtension(path: string) {\n const match = path.match(/\\.([^.]+)$/);\n return match ? match[1] : null;\n}\n\nexport const CreateImageFilePayload = z\n .object({\n /**\n * The md5 hash of the image file.\n */\n md5: z.string().optional(),\n /**\n * The height of the image file in pixels.\n */\n height: z.number().int().optional(),\n /**\n * The width of the image file in pixels.\n */\n width: z.number().int().optional(),\n /**\n * The mime type of the image file. Optional if the filename has a known file extension.\n */\n mime_type: ImageFileMimeTypes.optional(),\n /**\n * The filename of the image file.\n */\n filename: z.string(),\n /**\n * The byte size of the image file.\n */\n byte_size: z.number().int().max(MAX_IMAGE_SIZE),\n })\n .superRefine((data, ctx) => {\n const extension = getFileExtension(data.filename);\n const mimeType = extension ? types[extension] : null;\n const parsedMimeType = ImageFileMimeTypes.safeParse(mimeType).data;\n\n if (parsedMimeType) {\n data.mime_type = parsedMimeType;\n }\n\n if (!parsedMimeType && !data.mime_type) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message
|
|
1
|
+
{"version":3,"file":"image-file.cjs","names":["z","types","uploadChunks"],"sources":["../../src/resources/image-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { types } from \"mime-types\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\n\nconst log = debug(\"ef:api:image-file\");\n\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\n\nexport const ImageFileMimeTypes = z.enum([\n \"image/jpeg\",\n \"image/png\",\n \"image/jpg\",\n \"image/webp\",\n \"image/svg+xml\",\n]);\n\nfunction getFileExtension(path: string) {\n const match = path.match(/\\.([^.]+)$/);\n return match ? match[1] : null;\n}\n\nexport const CreateImageFilePayload = z\n .object({\n /**\n * The md5 hash of the image file.\n */\n md5: z.string().optional(),\n /**\n * The height of the image file in pixels.\n */\n height: z.number().int().optional(),\n /**\n * The width of the image file in pixels.\n */\n width: z.number().int().optional(),\n /**\n * The mime type of the image file. Optional if the filename has a known file extension.\n */\n mime_type: ImageFileMimeTypes.optional(),\n /**\n * The filename of the image file.\n */\n filename: z.string(),\n /**\n * The byte size of the image file.\n */\n byte_size: z.number().int().max(MAX_IMAGE_SIZE),\n })\n .superRefine((data, ctx) => {\n const extension = getFileExtension(data.filename);\n const mimeType = extension ? types[extension] : null;\n const parsedMimeType = ImageFileMimeTypes.safeParse(mimeType).data;\n\n if (parsedMimeType) {\n data.mime_type = parsedMimeType;\n }\n\n if (!parsedMimeType && !data.mime_type) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"mime_type is required when filename extension doesn't match a known image type\",\n path: [\"mime_type\"],\n });\n }\n });\n\nexport type CreateImageFilePayload = z.infer<typeof CreateImageFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateImageFileResult {\n /**\n * Whether the image file has been fully uploaded.\n */\n complete: boolean | null;\n /**\n * The byte size of the image file.\n */\n byte_size: number;\n /**\n * The id of the image file.\n */\n id: string;\n /**\n * The md5 hash of the image file.\n */\n md5: string | null;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupImageFileByMd5Result {\n /**\n * Whether the image file has been fully uploaded.\n */\n complete: boolean | null;\n /**\n * The byte size of the image file.\n */\n byte_size: number;\n /**\n * The id of the image file.\n */\n id: string;\n /**\n * md5 hash of the image file.\n */\n md5: string | null;\n /**\n * The height of the image file in pixels.\n */\n height: number | null;\n /**\n * The width of the image file in pixels.\n */\n width: number | null;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetImageFileMetadataResult extends LookupImageFileByMd5Result {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createImageFile = async (client: Client, payload: CreateImageFilePayload) => {\n log(\"Creating image file\", payload);\n CreateImageFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/image_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Image file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateImageFileResult;\n }\n\n throw new Error(`Failed to create file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadImageFile = (\n client: Client,\n uploadDetails: {\n id: string;\n byte_size: number;\n },\n fileStream: ReadableStream,\n chunkSizeBytes?: number,\n) => {\n log(\"Uploading image file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/image_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_IMAGE_SIZE,\n chunkSizeBytes,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const getImageFileMetadata = async (\n client: Client,\n id: string,\n): Promise<GetImageFileMetadataResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/image_files/${id}.json`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupImageFileByMd5Result;\n }\n\n return null;\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupImageFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupImageFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/image_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"Image file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupImageFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(`Failed to lookup image by md5 ${md5} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;;;;AAOA,MAAM,yBAAY,oBAAoB;AAEtC,MAAM,iBAAiB,OAAO,OAAO;AAErC,MAAa,qBAAqBA,MAAE,KAAK;CACvC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,iBAAiB,MAAc;CACtC,MAAM,QAAQ,KAAK,MAAM,aAAa;AACtC,QAAO,QAAQ,MAAM,KAAK;;AAG5B,MAAa,yBAAyBA,MACnC,OAAO;CAIN,KAAKA,MAAE,QAAQ,CAAC,UAAU;CAI1B,QAAQA,MAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CAInC,OAAOA,MAAE,QAAQ,CAAC,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M,WAAW,MAAM,OAAO,mBAAmB,2BAA2B,OAAO,EACjF,QAAQ,OACT,CAAC;AACF,KAAI,qBAAqB,SAAS;AAElC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MAAM,iCAAiC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-file.js","names":[],"sources":["../../src/resources/image-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { types } from \"mime-types\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\n\nconst log = debug(\"ef:api:image-file\");\n\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\n\nexport const ImageFileMimeTypes = z.enum([\n \"image/jpeg\",\n \"image/png\",\n \"image/jpg\",\n \"image/webp\",\n \"image/svg+xml\",\n]);\n\nfunction getFileExtension(path: string) {\n const match = path.match(/\\.([^.]+)$/);\n return match ? match[1] : null;\n}\n\nexport const CreateImageFilePayload = z\n .object({\n /**\n * The md5 hash of the image file.\n */\n md5: z.string().optional(),\n /**\n * The height of the image file in pixels.\n */\n height: z.number().int().optional(),\n /**\n * The width of the image file in pixels.\n */\n width: z.number().int().optional(),\n /**\n * The mime type of the image file. Optional if the filename has a known file extension.\n */\n mime_type: ImageFileMimeTypes.optional(),\n /**\n * The filename of the image file.\n */\n filename: z.string(),\n /**\n * The byte size of the image file.\n */\n byte_size: z.number().int().max(MAX_IMAGE_SIZE),\n })\n .superRefine((data, ctx) => {\n const extension = getFileExtension(data.filename);\n const mimeType = extension ? types[extension] : null;\n const parsedMimeType = ImageFileMimeTypes.safeParse(mimeType).data;\n\n if (parsedMimeType) {\n data.mime_type = parsedMimeType;\n }\n\n if (!parsedMimeType && !data.mime_type) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message
|
|
1
|
+
{"version":3,"file":"image-file.js","names":[],"sources":["../../src/resources/image-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { types } from \"mime-types\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\n\nconst log = debug(\"ef:api:image-file\");\n\nconst MAX_IMAGE_SIZE = 1024 * 1024 * 16; // 16MB\n\nexport const ImageFileMimeTypes = z.enum([\n \"image/jpeg\",\n \"image/png\",\n \"image/jpg\",\n \"image/webp\",\n \"image/svg+xml\",\n]);\n\nfunction getFileExtension(path: string) {\n const match = path.match(/\\.([^.]+)$/);\n return match ? match[1] : null;\n}\n\nexport const CreateImageFilePayload = z\n .object({\n /**\n * The md5 hash of the image file.\n */\n md5: z.string().optional(),\n /**\n * The height of the image file in pixels.\n */\n height: z.number().int().optional(),\n /**\n * The width of the image file in pixels.\n */\n width: z.number().int().optional(),\n /**\n * The mime type of the image file. Optional if the filename has a known file extension.\n */\n mime_type: ImageFileMimeTypes.optional(),\n /**\n * The filename of the image file.\n */\n filename: z.string(),\n /**\n * The byte size of the image file.\n */\n byte_size: z.number().int().max(MAX_IMAGE_SIZE),\n })\n .superRefine((data, ctx) => {\n const extension = getFileExtension(data.filename);\n const mimeType = extension ? types[extension] : null;\n const parsedMimeType = ImageFileMimeTypes.safeParse(mimeType).data;\n\n if (parsedMimeType) {\n data.mime_type = parsedMimeType;\n }\n\n if (!parsedMimeType && !data.mime_type) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"mime_type is required when filename extension doesn't match a known image type\",\n path: [\"mime_type\"],\n });\n }\n });\n\nexport type CreateImageFilePayload = z.infer<typeof CreateImageFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateImageFileResult {\n /**\n * Whether the image file has been fully uploaded.\n */\n complete: boolean | null;\n /**\n * The byte size of the image file.\n */\n byte_size: number;\n /**\n * The id of the image file.\n */\n id: string;\n /**\n * The md5 hash of the image file.\n */\n md5: string | null;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupImageFileByMd5Result {\n /**\n * Whether the image file has been fully uploaded.\n */\n complete: boolean | null;\n /**\n * The byte size of the image file.\n */\n byte_size: number;\n /**\n * The id of the image file.\n */\n id: string;\n /**\n * md5 hash of the image file.\n */\n md5: string | null;\n /**\n * The height of the image file in pixels.\n */\n height: number | null;\n /**\n * The width of the image file in pixels.\n */\n width: number | null;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetImageFileMetadataResult extends LookupImageFileByMd5Result {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createImageFile = async (client: Client, payload: CreateImageFilePayload) => {\n log(\"Creating image file\", payload);\n CreateImageFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/image_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Image file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateImageFileResult;\n }\n\n throw new Error(`Failed to create file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadImageFile = (\n client: Client,\n uploadDetails: {\n id: string;\n byte_size: number;\n },\n fileStream: ReadableStream,\n chunkSizeBytes?: number,\n) => {\n log(\"Uploading image file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/image_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_IMAGE_SIZE,\n chunkSizeBytes,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const getImageFileMetadata = async (\n client: Client,\n id: string,\n): Promise<GetImageFileMetadataResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/image_files/${id}.json`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupImageFileByMd5Result;\n }\n\n return null;\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupImageFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupImageFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/image_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"Image file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupImageFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(`Failed to lookup image by md5 ${md5} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;AAOA,MAAM,MAAM,MAAM,oBAAoB;AAEtC,MAAM,iBAAiB,OAAO,OAAO;AAErC,MAAa,qBAAqB,EAAE,KAAK;CACvC;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,iBAAiB,MAAc;CACtC,MAAM,QAAQ,KAAK,MAAM,aAAa;AACtC,QAAO,QAAQ,MAAM,KAAK;;AAG5B,MAAa,yBAAyB,EACnC,OAAO;CAIN,KAAK,EAAE,QAAQ,CAAC,UAAU;CAI1B,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CAInC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;CAIlC,WAAW,mBAAmB,UAAU;CAIxC,UAAU,EAAE,QAAQ;CAIpB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe;CAChD,CAAC,CACD,aAAa,MAAM,QAAQ;CAC1B,MAAM,YAAY,iBAAiB,KAAK,SAAS;CACjD,MAAM,WAAW,YAAY,MAAM,aAAa;CAChD,MAAM,iBAAiB,mBAAmB,UAAU,SAAS,CAAC;AAE9D,KAAI,eACF,MAAK,YAAY;AAGnB,KAAI,CAAC,kBAAkB,CAAC,KAAK,UAC3B,KAAI,SAAS;EACX,MAAM,EAAE,aAAa;EACrB,SAAS;EACT,MAAM,CAAC,YAAY;EACpB,CAAC;EAEJ;;AAwDJ,MAAa,kBAAkB,OAAO,QAAgB,YAAoC;AACxF,KAAI,uBAAuB,QAAQ;AACnC,wBAAuB,MAAM,QAAQ;CACrC,MAAM,WAAW,MAAM,OAAO,mBAAmB,uBAAuB;EACtE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,sBAAsB,SAAS;AAEnC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,yBAAyB,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAIpF,MAAa,mBACX,QACA,eAIA,YACA,mBACG;AACH,KAAI,wBAAwB,cAAc,GAAG;AAE7C,QAAO,aAAa,QAAQ;EAC1B,KAAK,uBAAuB,cAAc,GAAG;EAC7C,UAAU,cAAc;EACxB;EACA,SAAS;EACT;EACD,CAAC;;;AAIJ,MAAa,uBAAuB,OAClC,QACA,OAC+C;CAC/C,MAAM,WAAW,MAAM,OAAO,mBAAmB,uBAAuB,GAAG,QAAQ,EACjF,QAAQ,OACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,QAAO;;;AAIT,MAAa,uBAAuB,OAClC,QACA,QAC+C;CAC/C,MAAM,WAAW,MAAM,OAAO,mBAAmB,2BAA2B,OAAO,EACjF,QAAQ,OACT,CAAC;AACF,KAAI,qBAAqB,SAAS;AAElC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MAAM,iCAAiC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isobmff-file.cjs","names":["z"],"sources":["../../src/resources/isobmff-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:isobmff-file\");\nconst FILE_SIZE_LIMIT = 1024 * 1024 * 2; // 32MB\n\nexport const CreateISOBMFFFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n});\n\nexport type CreateISOBMFFFilePayload = z.infer<typeof CreateISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateISOBMFFFileResult {\n /**\n * Whether the fragment index is complete. The fragment index is used internally by editframe to efficiently seek within files.\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n /**\n * The id of the isobmff file\n */\n id: string;\n /**\n * The md5 hash of the isobmff file\n */\n md5: string;\n}\n\nexport interface LookupISOBMFFFileByMd5Result {\n /**\n * Whether the fragment index is complete\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetISOBMFFFileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n isobmff_track: {\n duration_ms: number;\n };\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFFile = async (
|
|
1
|
+
{"version":3,"file":"isobmff-file.cjs","names":["z"],"sources":["../../src/resources/isobmff-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:isobmff-file\");\nconst FILE_SIZE_LIMIT = 1024 * 1024 * 2; // 32MB\n\nexport const CreateISOBMFFFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n});\n\nexport type CreateISOBMFFFilePayload = z.infer<typeof CreateISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateISOBMFFFileResult {\n /**\n * Whether the fragment index is complete. The fragment index is used internally by editframe to efficiently seek within files.\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n /**\n * The id of the isobmff file\n */\n id: string;\n /**\n * The md5 hash of the isobmff file\n */\n md5: string;\n}\n\nexport interface LookupISOBMFFFileByMd5Result {\n /**\n * Whether the fragment index is complete\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetISOBMFFFileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n isobmff_track: {\n duration_ms: number;\n };\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFFile = async (client: Client, payload: CreateISOBMFFFilePayload) => {\n log(\"Creating isobmff file\", payload);\n const response = await client.authenticatedFetch(\"/api/v1/isobmff_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"ISOBMFF file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFFileResult;\n }\n\n throw new Error(`Failed to create isobmff file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadFragmentIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading fragment index\", fileId);\n if (fileSize > FILE_SIZE_LIMIT) {\n throw new Error(`File size exceeds limit of ${FILE_SIZE_LIMIT} bytes`);\n }\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${fileId}/index/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n log(\"Fragment index uploaded\", response);\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to create fragment index ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupISOBMFFFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupISOBMFFFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"ISOBMFF file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupISOBMFFFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup isobmff file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const getISOBMFFFileTranscription = async (\n client: Client,\n id: string,\n): Promise<GetISOBMFFFileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${id}/transcription`);\n\n if (response.ok) {\n return (await response.json()) as GetISOBMFFFileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get isobmff file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const TranscribeISOBMFFFilePayload = z.object({\n trackId: z.string().optional(),\n});\n\nexport type TranscribeISOBMFFFilePayload = z.infer<typeof TranscribeISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface TranscribeISOBMFFFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const transcribeISOBMFFFile = async (\n client: Client,\n id: string,\n payload: TranscribeISOBMFFFilePayload = {},\n) => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${id}/transcribe`, {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n if (response.ok) {\n return (await response.json()) as TranscribeISOBMFFFileResult;\n }\n\n throw new Error(\n `Failed to transcribe isobmff file ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;AAKA,MAAM,yBAAY,sBAAsB;AACxC,MAAM,kBAAkB,OAAO,OAAO;AAEtC,MAAa,2BAA2BA,MAAE,OAAO;CAC/C,KAAKA,MAAE,QAAQ;CACf,UAAUA,MAAE,QAAQ;CACrB,CAAC;;AA+CF,MAAa,oBAAoB,OAAO,QAAgB,YAAsC;AAC5F,KAAI,yBAAyB,QAAQ;CACrC,MAAM,WAAW,MAAM,OAAO,mBAAmB,yBAAyB;EACxE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,wBAAwB,SAAS;AAErC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,iCAAiC,SAAS,OAAO,GAAG,SAAS,aAAa;;;A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AAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,qCAAqC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aACxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isobmff-file.js","names":[],"sources":["../../src/resources/isobmff-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:isobmff-file\");\nconst FILE_SIZE_LIMIT = 1024 * 1024 * 2; // 32MB\n\nexport const CreateISOBMFFFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n});\n\nexport type CreateISOBMFFFilePayload = z.infer<typeof CreateISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateISOBMFFFileResult {\n /**\n * Whether the fragment index is complete. The fragment index is used internally by editframe to efficiently seek within files.\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n /**\n * The id of the isobmff file\n */\n id: string;\n /**\n * The md5 hash of the isobmff file\n */\n md5: string;\n}\n\nexport interface LookupISOBMFFFileByMd5Result {\n /**\n * Whether the fragment index is complete\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetISOBMFFFileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n isobmff_track: {\n duration_ms: number;\n };\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFFile = async (
|
|
1
|
+
{"version":3,"file":"isobmff-file.js","names":[],"sources":["../../src/resources/isobmff-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\n\nconst log = debug(\"ef:api:isobmff-file\");\nconst FILE_SIZE_LIMIT = 1024 * 1024 * 2; // 32MB\n\nexport const CreateISOBMFFFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n});\n\nexport type CreateISOBMFFFilePayload = z.infer<typeof CreateISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateISOBMFFFileResult {\n /**\n * Whether the fragment index is complete. The fragment index is used internally by editframe to efficiently seek within files.\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n /**\n * The id of the isobmff file\n */\n id: string;\n /**\n * The md5 hash of the isobmff file\n */\n md5: string;\n}\n\nexport interface LookupISOBMFFFileByMd5Result {\n /**\n * Whether the fragment index is complete\n */\n fragment_index_complete: boolean;\n /**\n * The filename of the isobmff file\n */\n filename: string;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface GetISOBMFFFileTranscriptionResult {\n id: string;\n work_slice_ms: number;\n isobmff_track: {\n duration_ms: number;\n };\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFFile = async (client: Client, payload: CreateISOBMFFFilePayload) => {\n log(\"Creating isobmff file\", payload);\n const response = await client.authenticatedFetch(\"/api/v1/isobmff_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"ISOBMFF file created\", response);\n\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFFileResult;\n }\n\n throw new Error(`Failed to create isobmff file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadFragmentIndex = async (\n client: Client,\n fileId: string,\n fileStream: ReadableStream,\n fileSize: number,\n) => {\n log(\"Uploading fragment index\", fileId);\n if (fileSize > FILE_SIZE_LIMIT) {\n throw new Error(`File size exceeds limit of ${FILE_SIZE_LIMIT} bytes`);\n }\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${fileId}/index/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n log(\"Fragment index uploaded\", response);\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to create fragment index ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupISOBMFFFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupISOBMFFFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/md5/${md5}`, {\n method: \"GET\",\n });\n log(\"ISOBMFF file lookup\", response);\n\n if (response.ok) {\n return (await response.json()) as LookupISOBMFFFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup isobmff file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const getISOBMFFFileTranscription = async (\n client: Client,\n id: string,\n): Promise<GetISOBMFFFileTranscriptionResult | null> => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${id}/transcription`);\n\n if (response.ok) {\n return (await response.json()) as GetISOBMFFFileTranscriptionResult;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to get isobmff file transcription ${id} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const TranscribeISOBMFFFilePayload = z.object({\n trackId: z.string().optional(),\n});\n\nexport type TranscribeISOBMFFFilePayload = z.infer<typeof TranscribeISOBMFFFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface TranscribeISOBMFFFileResult {\n id: string;\n file_id: string;\n track_id: number;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const transcribeISOBMFFFile = async (\n client: Client,\n id: string,\n payload: TranscribeISOBMFFFilePayload = {},\n) => {\n const response = await client.authenticatedFetch(`/api/v1/isobmff_files/${id}/transcribe`, {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n if (response.ok) {\n return (await response.json()) as TranscribeISOBMFFFileResult;\n }\n\n throw new Error(\n `Failed to transcribe isobmff file ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;AAKA,MAAM,MAAM,MAAM,sBAAsB;AACxC,MAAM,kBAAkB,OAAO,OA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MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,4CAA4C,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAC/E;;AAGH,MAAa,+BAA+B,EAAE,OAAO,EACnD,SAAS,EAAE,QAAQ,CAAC,UAAU,EAC/B,CAAC;;AAYF,MAAa,wBAAwB,OACnC,QACA,IACA,UAAwC,EAAE,KACvC;CACH,MAAM,WAAW,MAAM,OAAO,mBAAmB,yBAAyB,GAAG,cAAc;EACzF,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,qCAAqC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aACxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isobmff-track.cjs","names":["z","assertTypesMatch","uploadChunks"],"sources":["../../src/resources/isobmff-track.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nexport const AudioStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"audio\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n sample_fmt: z.string(),\n sample_rate: z.string(),\n channels: z.number(),\n channel_layout: z.string().optional(),\n bits_per_sample: z.number(),\n initial_padding: z.number().optional(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number(),\n duration: z.coerce.number(),\n bit_rate: z.string(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface AudioStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"audio\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The sample format */\n sample_fmt: string;\n /** The sample rate */\n sample_rate: string;\n /** The number of channels */\n channels: number;\n /** The channel layout */\n channel_layout?: string;\n /** The number of bits per sample */\n bits_per_sample: number;\n /** The initial padding */\n initial_padding?: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts: number;\n /** The duration */\n duration: number;\n /** The bit rate */\n bit_rate: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof AudioStreamSchema>, AudioStreamSchema>(true);\n\nexport const VideoStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"video\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n width: z.number(),\n height: z.number(),\n coded_width: z.number(),\n coded_height: z.number(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number().optional(),\n duration: z.coerce.number().optional(),\n bit_rate: z.string().optional(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface VideoStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"video\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The width */\n width: number;\n /** The height */\n height: number;\n /** The coded width */\n coded_width: number;\n /** The coded height */\n coded_height: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts?: number;\n /** The duration */\n duration?: number;\n /** The bit rate */\n bit_rate?: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof VideoStreamSchema>, VideoStreamSchema>(true);\n\nconst log = debug(\"ef:api:isobmff-track\");\n\nconst MAX_TRACK_SIZE = 1024 * 1024 * 1024; // 1GB\n\nexport const AudioTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"audio\"),\n probe_info: AudioStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface AudioTrackPayload {\n file_id: string;\n track_id: number;\n type: \"audio\";\n probe_info: AudioStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\n// These will actually error if types don't match\nassertTypesMatch<z.infer<typeof AudioTrackPayload>, AudioTrackPayload>(true);\n\nexport const VideoTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"video\"),\n probe_info: VideoStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface VideoTrackPayload {\n file_id: string;\n track_id: number;\n type: \"video\";\n probe_info: VideoStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\nassertTypesMatch<z.infer<typeof VideoTrackPayload>, VideoTrackPayload>(true);\n\nexport const CreateISOBMFFTrackPayload = z.discriminatedUnion(\"type\", [\n AudioTrackPayload,\n VideoTrackPayload,\n]);\n\nexport type CreateISOBMFFTrackPayload = VideoTrackPayload | AudioTrackPayload;\n\nassertTypesMatch
|
|
1
|
+
{"version":3,"file":"isobmff-track.cjs","names":["z","assertTypesMatch","uploadChunks"],"sources":["../../src/resources/isobmff-track.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nexport const AudioStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"audio\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n sample_fmt: z.string(),\n sample_rate: z.string(),\n channels: z.number(),\n channel_layout: z.string().optional(),\n bits_per_sample: z.number(),\n initial_padding: z.number().optional(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number(),\n duration: z.coerce.number(),\n bit_rate: z.string(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface AudioStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"audio\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The sample format */\n sample_fmt: string;\n /** The sample rate */\n sample_rate: string;\n /** The number of channels */\n channels: number;\n /** The channel layout */\n channel_layout?: string;\n /** The number of bits per sample */\n bits_per_sample: number;\n /** The initial padding */\n initial_padding?: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts: number;\n /** The duration */\n duration: number;\n /** The bit rate */\n bit_rate: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof AudioStreamSchema>, AudioStreamSchema>(true);\n\nexport const VideoStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"video\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n width: z.number(),\n height: z.number(),\n coded_width: z.number(),\n coded_height: z.number(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number().optional(),\n duration: z.coerce.number().optional(),\n bit_rate: z.string().optional(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface VideoStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"video\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The width */\n width: number;\n /** The height */\n height: number;\n /** The coded width */\n coded_width: number;\n /** The coded height */\n coded_height: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts?: number;\n /** The duration */\n duration?: number;\n /** The bit rate */\n bit_rate?: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof VideoStreamSchema>, VideoStreamSchema>(true);\n\nconst log = debug(\"ef:api:isobmff-track\");\n\nconst MAX_TRACK_SIZE = 1024 * 1024 * 1024; // 1GB\n\nexport const AudioTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"audio\"),\n probe_info: AudioStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface AudioTrackPayload {\n file_id: string;\n track_id: number;\n type: \"audio\";\n probe_info: AudioStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\n// These will actually error if types don't match\nassertTypesMatch<z.infer<typeof AudioTrackPayload>, AudioTrackPayload>(true);\n\nexport const VideoTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"video\"),\n probe_info: VideoStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface VideoTrackPayload {\n file_id: string;\n track_id: number;\n type: \"video\";\n probe_info: VideoStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\nassertTypesMatch<z.infer<typeof VideoTrackPayload>, VideoTrackPayload>(true);\n\nexport const CreateISOBMFFTrackPayload = z.discriminatedUnion(\"type\", [\n AudioTrackPayload,\n VideoTrackPayload,\n]);\n\nexport type CreateISOBMFFTrackPayload = VideoTrackPayload | AudioTrackPayload;\n\nassertTypesMatch<z.infer<typeof CreateISOBMFFTrackPayload>, CreateISOBMFFTrackPayload>(true);\n\nexport interface CreateISOBMFFTrackResult {\n next_byte: number;\n byte_size: number;\n track_id: number;\n file_id: string;\n complete: boolean;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFTrack = async (client: Client, payload: CreateISOBMFFTrackPayload) => {\n log(\"Creating isobmff track\", payload);\n CreateISOBMFFTrackPayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/isobmff_tracks\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"ISOBMFF track created\", response);\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(`Failed to create isobmff track ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadISOBMFFTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n fileStream: ReadableStream,\n trackSize: number,\n) => {\n log(\"Uploading fragment track\", fileId);\n\n return uploadChunks(client, {\n url: `/api/v1/isobmff_tracks/${fileId}/${trackId}/upload`,\n fileStream,\n fileSize: trackSize,\n maxSize: MAX_TRACK_SIZE,\n });\n};\n"],"mappings":";;;;;;;;;AAMA,MAAa,oBAAoBA,MAAE,OA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GAAG,SAAS,aAAa;;;AAI7F,MAAa,sBACX,QACA,QACA,SACA,YACA,cACG;AACH,KAAI,4BAA4B,OAAO;AAEvC,QAAOC,kCAAa,QAAQ;EAC1B,KAAK,0BAA0B,OAAO,GAAG,QAAQ;EACjD;EACA,UAAU;EACV,SAAS;EACV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isobmff-track.js","names":[],"sources":["../../src/resources/isobmff-track.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nexport const AudioStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"audio\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n sample_fmt: z.string(),\n sample_rate: z.string(),\n channels: z.number(),\n channel_layout: z.string().optional(),\n bits_per_sample: z.number(),\n initial_padding: z.number().optional(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number(),\n duration: z.coerce.number(),\n bit_rate: z.string(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface AudioStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"audio\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The sample format */\n sample_fmt: string;\n /** The sample rate */\n sample_rate: string;\n /** The number of channels */\n channels: number;\n /** The channel layout */\n channel_layout?: string;\n /** The number of bits per sample */\n bits_per_sample: number;\n /** The initial padding */\n initial_padding?: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts: number;\n /** The duration */\n duration: number;\n /** The bit rate */\n bit_rate: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof AudioStreamSchema>, AudioStreamSchema>(true);\n\nexport const VideoStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"video\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n width: z.number(),\n height: z.number(),\n coded_width: z.number(),\n coded_height: z.number(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number().optional(),\n duration: z.coerce.number().optional(),\n bit_rate: z.string().optional(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface VideoStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"video\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The width */\n width: number;\n /** The height */\n height: number;\n /** The coded width */\n coded_width: number;\n /** The coded height */\n coded_height: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts?: number;\n /** The duration */\n duration?: number;\n /** The bit rate */\n bit_rate?: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof VideoStreamSchema>, VideoStreamSchema>(true);\n\nconst log = debug(\"ef:api:isobmff-track\");\n\nconst MAX_TRACK_SIZE = 1024 * 1024 * 1024; // 1GB\n\nexport const AudioTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"audio\"),\n probe_info: AudioStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface AudioTrackPayload {\n file_id: string;\n track_id: number;\n type: \"audio\";\n probe_info: AudioStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\n// These will actually error if types don't match\nassertTypesMatch<z.infer<typeof AudioTrackPayload>, AudioTrackPayload>(true);\n\nexport const VideoTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"video\"),\n probe_info: VideoStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface VideoTrackPayload {\n file_id: string;\n track_id: number;\n type: \"video\";\n probe_info: VideoStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\nassertTypesMatch<z.infer<typeof VideoTrackPayload>, VideoTrackPayload>(true);\n\nexport const CreateISOBMFFTrackPayload = z.discriminatedUnion(\"type\", [\n AudioTrackPayload,\n VideoTrackPayload,\n]);\n\nexport type CreateISOBMFFTrackPayload = VideoTrackPayload | AudioTrackPayload;\n\nassertTypesMatch
|
|
1
|
+
{"version":3,"file":"isobmff-track.js","names":[],"sources":["../../src/resources/isobmff-track.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nexport const AudioStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"audio\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n sample_fmt: z.string(),\n sample_rate: z.string(),\n channels: z.number(),\n channel_layout: z.string().optional(),\n bits_per_sample: z.number(),\n initial_padding: z.number().optional(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number(),\n duration: z.coerce.number(),\n bit_rate: z.string(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface AudioStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"audio\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The sample format */\n sample_fmt: string;\n /** The sample rate */\n sample_rate: string;\n /** The number of channels */\n channels: number;\n /** The channel layout */\n channel_layout?: string;\n /** The number of bits per sample */\n bits_per_sample: number;\n /** The initial padding */\n initial_padding?: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts: number;\n /** The duration */\n duration: number;\n /** The bit rate */\n bit_rate: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof AudioStreamSchema>, AudioStreamSchema>(true);\n\nexport const VideoStreamSchema = z.object({\n index: z.number(),\n codec_name: z.string(),\n codec_long_name: z.string(),\n codec_type: z.literal(\"video\"),\n codec_tag_string: z.string(),\n codec_tag: z.string(),\n width: z.number(),\n height: z.number(),\n coded_width: z.number(),\n coded_height: z.number(),\n r_frame_rate: z.string(),\n avg_frame_rate: z.string(),\n time_base: z.string(),\n start_pts: z.number().optional(),\n start_time: z.coerce.number().optional(),\n duration_ts: z.number().optional(),\n duration: z.coerce.number().optional(),\n bit_rate: z.string().optional(),\n disposition: z.record(z.unknown()),\n});\n\nexport interface VideoStreamSchema {\n /** The index of the stream in the file */\n index: number;\n /** The name of the codec */\n codec_name: string;\n /** The long name of the codec */\n codec_long_name: string;\n /** The type of the codec */\n codec_type: \"video\";\n /** The tag string of the codec */\n codec_tag_string: string;\n /** The tag of the codec */\n codec_tag: string;\n /** The width */\n width: number;\n /** The height */\n height: number;\n /** The coded width */\n coded_width: number;\n /** The coded height */\n coded_height: number;\n /** The frame rate */\n r_frame_rate: string;\n /** The average frame rate */\n avg_frame_rate: string;\n /** The time base */\n time_base: string;\n /** The start presentation timestamp */\n start_pts?: number;\n /** The start time */\n start_time?: number;\n /** The duration timestamp */\n duration_ts?: number;\n /** The duration */\n duration?: number;\n /** The bit rate */\n bit_rate?: string;\n /** The disposition record. Subject to change, not documented. */\n disposition: Record<string, unknown>;\n}\n\nassertTypesMatch<z.infer<typeof VideoStreamSchema>, VideoStreamSchema>(true);\n\nconst log = debug(\"ef:api:isobmff-track\");\n\nconst MAX_TRACK_SIZE = 1024 * 1024 * 1024; // 1GB\n\nexport const AudioTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"audio\"),\n probe_info: AudioStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface AudioTrackPayload {\n file_id: string;\n track_id: number;\n type: \"audio\";\n probe_info: AudioStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\n// These will actually error if types don't match\nassertTypesMatch<z.infer<typeof AudioTrackPayload>, AudioTrackPayload>(true);\n\nexport const VideoTrackPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n type: z.literal(\"video\"),\n probe_info: VideoStreamSchema,\n duration_ms: z.number().int(),\n codec_name: z.string(),\n byte_size: z.number().int().max(MAX_TRACK_SIZE),\n});\n\nexport interface VideoTrackPayload {\n file_id: string;\n track_id: number;\n type: \"video\";\n probe_info: VideoStreamSchema;\n duration_ms: number;\n codec_name: string;\n byte_size: number;\n}\n\nassertTypesMatch<z.infer<typeof VideoTrackPayload>, VideoTrackPayload>(true);\n\nexport const CreateISOBMFFTrackPayload = z.discriminatedUnion(\"type\", [\n AudioTrackPayload,\n VideoTrackPayload,\n]);\n\nexport type CreateISOBMFFTrackPayload = VideoTrackPayload | AudioTrackPayload;\n\nassertTypesMatch<z.infer<typeof CreateISOBMFFTrackPayload>, CreateISOBMFFTrackPayload>(true);\n\nexport interface CreateISOBMFFTrackResult {\n next_byte: number;\n byte_size: number;\n track_id: number;\n file_id: string;\n complete: boolean;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createISOBMFFTrack = async (client: Client, payload: CreateISOBMFFTrackPayload) => {\n log(\"Creating isobmff track\", payload);\n CreateISOBMFFTrackPayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/isobmff_tracks\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"ISOBMFF track created\", response);\n if (response.ok) {\n return (await response.json()) as CreateISOBMFFTrackResult;\n }\n\n throw new Error(`Failed to create isobmff track ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadISOBMFFTrack = (\n client: Client,\n fileId: string,\n trackId: number,\n fileStream: ReadableStream,\n trackSize: number,\n) => {\n log(\"Uploading fragment track\", fileId);\n\n return uploadChunks(client, {\n url: `/api/v1/isobmff_tracks/${fileId}/${trackId}/upload`,\n fileStream,\n fileSize: trackSize,\n maxSize: MAX_TRACK_SIZE,\n });\n};\n"],"mappings":";;;;;;AAMA,MAAa,oBAAoB,EAAE,OAAO;CACxC,OAAO,EAAE,QAAQ;CACjB,YAAY,EAAE,QAAQ;CACtB,iBAAiB,EAAE,QAAQ;CAC3B,YAAY,EAAE,QAAQ,QAAQ;CAC9B,kBAAkB,EAAE,QAAQ;CAC5B,WAAW,EAAE,QAAQ;CACrB,YAAY,EAAE,QAAQ;CACtB,aAAa,EAAE,QAAQ;CACvB,UAAU,EAAE,QAAQ;CACpB,gBAAgB,EAAE,QAAQ,CAAC,UAAU;CACrC,iBAAiB,EAAE,QAAQ;CAC3B,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,cA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,QAAQ;CACtB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe;CAChD,CAAC;AAaF,iBAAuE,KAAK;AAE5E,MAAa,oBAAoB,EAAE,OAAO;CACxC,SAAS,EAAE,QAAQ;CACnB,UAAU,EAAE,QAAQ,CAAC,KAAK;CAC1B,MAAM,EAAE,QAAQ,QAAQ;CACxB,YAAY;CACZ,aAAa,EAAE,QAAQ,CAAC,KAAK;CAC7B,YAAY,EAAE,QAAQ;CACtB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,eAAe;CAChD,CAAC;AAYF,iBAAuE,KAAK;AAE5E,MAAa,4BAA4B,EAAE,mBAAmB,QAAQ,CACpE,mBACA,kBACD,CAAC;AAIF,iBAAuF,KAAK;;AAW5F,MAAa,qBAAqB,OAAO,QAAgB,YAAuC;AAC9F,KAAI,0BAA0B,QAAQ;AACtC,2BAA0B,MAAM,QAAQ;CACxC,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B;EACzE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,yBAAyB,SAAS;AACtC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,kCAAkC,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAI7F,MAAa,sBACX,QACA,QACA,SACA,YACA,cACG;AACH,KAAI,4BAA4B,OAAO;AAEvC,QAAO,aAAa,QAAQ;EAC1B,KAAK,0BAA0B,OAAO,GAAG,QAAQ;EACjD;EACA,UAAU;EACV,SAAS;EACV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-isobmff.cjs","names":["ProgressIterator"],"sources":["../../src/resources/process-isobmff.ts"],"sourcesContent":["import type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\n\nexport interface IsobmffProcessInfoResult {\n id: string;\n created_at: string;\n completed_at: string | null;\n failed_at: string | null;\n isobmff_file_id: string | null;\n unprocessed_file_id: string | null;\n}\n\nexport const getIsobmffProcessProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/process_isobmff/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const getIsobmffProcessInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(
|
|
1
|
+
{"version":3,"file":"process-isobmff.cjs","names":["ProgressIterator"],"sources":["../../src/resources/process-isobmff.ts"],"sourcesContent":["import type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\n\nexport interface IsobmffProcessInfoResult {\n id: string;\n created_at: string;\n completed_at: string | null;\n failed_at: string | null;\n isobmff_file_id: string | null;\n unprocessed_file_id: string | null;\n}\n\nexport const getIsobmffProcessProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/process_isobmff/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const getIsobmffProcessInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/process_isobmff/${id}`);\n\n if (response.ok) {\n return (await response.json()) as IsobmffProcessInfoResult;\n }\n\n throw new Error(`Failed to get isobmff process info ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;AAYA,MAAa,4BAA4B,OAAO,QAAgB,OAAe;AAK7E,QAAO,IAAIA,0CAJS,MAAM,OAAO,yBAC/B,2BAA2B,GAAG,WAC/B,CAEuC;;AAG1C,MAAa,wBAAwB,OAAO,QAAgB,OAAe;CACzE,MAAM,WAAW,MAAM,OAAO,mBAAmB,2BAA2B,KAAK;AAEjF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,sCAAsC,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-isobmff.js","names":[],"sources":["../../src/resources/process-isobmff.ts"],"sourcesContent":["import type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\n\nexport interface IsobmffProcessInfoResult {\n id: string;\n created_at: string;\n completed_at: string | null;\n failed_at: string | null;\n isobmff_file_id: string | null;\n unprocessed_file_id: string | null;\n}\n\nexport const getIsobmffProcessProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/process_isobmff/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const getIsobmffProcessInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(
|
|
1
|
+
{"version":3,"file":"process-isobmff.js","names":[],"sources":["../../src/resources/process-isobmff.ts"],"sourcesContent":["import type { Client } from \"../client.js\";\nimport { ProgressIterator } from \"../ProgressIterator.js\";\n\nexport interface IsobmffProcessInfoResult {\n id: string;\n created_at: string;\n completed_at: string | null;\n failed_at: string | null;\n isobmff_file_id: string | null;\n unprocessed_file_id: string | null;\n}\n\nexport const getIsobmffProcessProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/process_isobmff/${id}/progress`,\n );\n\n return new ProgressIterator(eventSource);\n};\n\nexport const getIsobmffProcessInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/process_isobmff/${id}`);\n\n if (response.ok) {\n return (await response.json()) as IsobmffProcessInfoResult;\n }\n\n throw new Error(`Failed to get isobmff process info ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;AAYA,MAAa,4BAA4B,OAAO,QAAgB,OAAe;AAK7E,QAAO,IAAI,iBAJS,MAAM,OAAO,yBAC/B,2BAA2B,GAAG,WAC/B,CAEuC;;AAG1C,MAAa,wBAAwB,OAAO,QAAgB,OAAe;CACzE,MAAM,WAAW,MAAM,OAAO,mBAAmB,2BAA2B,KAAK;AAEjF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,sCAAsC,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renders.cjs","names":["z","output: RenderOutputConfiguration","assertTypesMatch","CompletionIterator"],"sources":["../../src/resources/renders.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:renders\");\n\nconst H264Configuration = z.object({\n codec: z.literal(\"h264\"),\n});\n\nconst AACConfiguration = z.object({\n codec: z.literal(\"aac\"),\n});\n\nconst MP4Configuration = z.object({\n container: z.literal(\"mp4\"),\n video: H264Configuration,\n audio: AACConfiguration,\n});\n\nconst JpegConfiguration = z.object({\n container: z.literal(\"jpeg\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n});\n\nconst PngConfiguration = z.object({\n container: z.literal(\"png\"),\n compression: z.number().int().min(1).max(100).default(80).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nconst WebpConfiguration = z.object({\n container: z.literal(\"webp\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n compression: z.number().int().min(0).max(6).default(4).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nexport const RenderOutputConfiguration = z.discriminatedUnion(\"container\", [\n MP4Configuration,\n JpegConfiguration,\n PngConfiguration,\n WebpConfiguration,\n]);\n\nexport type RenderOutputConfiguration = z.infer<\n typeof RenderOutputConfiguration\n>;\n\nexport const CreateRenderPayload = z.object({\n md5: z.string().optional(),\n fps: z.number().int().min(1).max(120).default(30).optional(),\n width: z.number().int().min(2).optional(),\n height: z.number().int().min(2).optional(),\n work_slice_ms: z\n .number()\n .int()\n .min(1000)\n .max(10_000)\n .default(4_000)\n .optional(),\n html: z.string().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n duration_ms: z.number().int().optional(),\n strategy: z.enum([\"v1\"]).default(\"v1\").optional(),\n backend: z.enum([\"cpu\", \"gpu\"]).default(\"cpu\").optional(),\n output: RenderOutputConfiguration.default({\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n }).optional(),\n});\n\nexport const CreateRenderPayloadWithOutput = CreateRenderPayload.extend({\n output: RenderOutputConfiguration,\n});\n\nexport class OutputConfiguration {\n static parse(input?: any) {\n const output = RenderOutputConfiguration.parse(\n input ?? {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n },\n );\n return new OutputConfiguration(output);\n }\n\n constructor(public readonly output: RenderOutputConfiguration) {}\n\n get isStill() {\n return (\n this.output.container === \"jpeg\" ||\n this.output.container === \"png\" ||\n this.output.container === \"webp\"\n );\n }\n\n get isVideo() {\n return this.output.container === \"mp4\";\n }\n\n get fileExtension() {\n return this.output.container;\n }\n\n get contentType() {\n if (this.isStill) {\n return `image/${this.fileExtension}`;\n }\n return `video/${this.fileExtension}`;\n }\n\n get container() {\n return this.output.container;\n }\n\n get jpegConfig() {\n return this.output.container === \"jpeg\" ? this.output : null;\n }\n\n get pngConfig() {\n return this.output.container === \"png\" ? this.output : null;\n }\n\n get webpConfig() {\n return this.output.container === \"webp\" ? this.output : null;\n }\n\n get mp4Config() {\n return this.output.container === \"mp4\" ? this.output : null;\n }\n}\n\nexport interface CreateRenderPayload {\n md5?: string;\n fps?: number;\n width?: number;\n height?: number;\n work_slice_ms?: number;\n html?: string;\n duration_ms?: number;\n metadata?: Record<string, string>;\n strategy?: \"v1\";\n backend?: \"cpu\" | \"gpu\";\n output?: z.infer<typeof RenderOutputConfiguration>;\n}\n\nassertTypesMatch<CreateRenderPayload, z.infer<typeof CreateRenderPayload>>(\n true,\n);\n\nexport interface CreateRenderResult {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport interface LookupRenderByMd5Result {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport const createRender = async (\n client: Client,\n payload: CreateRenderPayload,\n) => {\n log(\"Creating render\", payload);\n // FIXME: The order of optional/default matters in zod\n // And if we set the default last, the type is not inferred correctly\n // Manually applying defaults here is a hack\n payload.strategy ??= \"v1\";\n payload.work_slice_ms ??= 4_000;\n payload.output ??= {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n };\n\n const response = await client.authenticatedFetch(\"/api/v1/renders\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Render created\", response);\n if (response.ok) {\n return (await response.json()) as CreateRenderResult;\n }\n\n throw new Error(\n `Failed to create render ${response.status} ${response.statusText} ${await response.text()}`,\n );\n};\n\nexport const uploadRender = async (\n client: Client,\n renderId: string,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading render\", renderId);\n const response = await client.authenticatedFetch(\n `/api/v1/renders/${renderId}/upload`,\n {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n },\n );\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(\n `Failed to upload render ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}`);\n return response.json() as Promise<LookupRenderByMd5Result>;\n};\n\nexport const lookupRenderByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupRenderByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/renders/md5/${md5}`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupRenderByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup render by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/renders/${id}/progress`,\n );\n\n return new CompletionIterator(eventSource);\n};\n\nexport const downloadRender = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}.mp4`);\n\n if (response.ok) {\n return response;\n }\n\n throw new Error(\n `Failed to download render ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,yBAAY,iBAAiB;AAEnC,MAAM,oBAAoBA,MAAE,OAAO,EACjC,OAAOA,MAAE,QAAQ,OAAO,EACzB,CAAC;AAEF,MAAM,mBAAmBA,MAAE,OAAO,EAChC,OAAOA,MAAE,QAAQ,MAAM,EACxB,CAAC;AAEF,MAAM,mBAAmBA,MAAE,OAAO;CAChC,WAAWA,MAAE,QAAQ,MAAM;CAC3B,OAAO;CACP,OAAO;CACR,CAAC;AAEF,MAAM,oBAAoBA,MAAE,OAAO;CACjC,WAAWA,MAAE,QAAQ,OAAO;CAC5B,SAASA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,UAAU;CACjE,CAAC;AAEF,MAAM,mBAAmBA,MAAE,OAAO;CAChC,WAAWA,MAAE,QAAQ,MAAM;CAC3B,aAAaA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,UAAU;CACpE,cAAcA,MAAE,SAAS,CAAC,QAAQ,MAAM,CAAC,UAAU;CACpD,CAAC;AAEF,MAAM,oBAAoBA,MAAE,OAAO;CACjC,WAAWA,MAAE,QAAQ,OAAO;CAC5B,SAASA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,UAAU;CAChE,aAAaA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,UAAU;CACjE,cAAcA,MAAE,SAAS,CAAC,QAAQ,MAAM,CAAC,UAAU;CACpD,CAAC;AAEF,MAAa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EACT,CACF;AAED,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MACR,2BAA2B,SAAS,OAAO,GAAG,SAAS,aACxD;;AAGH,MAAa,gBAAgB,OAAO,QAAgB,OAAe;AAEjE,SADiB,MAAM,OAAO,mBAAmB,mBAAmB,KAAK,EACzD,MAAM;;AAGxB,MAAa,oBAAoB,OAC/B,QACA,QAC4C;CAC5C,MAAM,WAAW,MAAM,OAAO,mBAC5B,uBAAuB,OACvB,EACE,QAAQ,OACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,kCAAkC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACtE;;AAGH,MAAa,oBAAoB,OAAO,QAAgB,OAAe;AAKrE,QAAO,IAAIC,4CAJS,MAAM,OAAO,yBAC/B,mBAAmB,GAAG,WACvB,CAEyC;;AAG5C,MAAa,iBAAiB,OAAO,QAAgB,OAAe;CAClE,MAAM,WAAW,MAAM,OAAO,mBAAmB,mBAAmB,GAAG,MAAM;AAE7E,KAAI,SAAS,GACX,QAAO;AAGT,OAAM,IAAI,MACR,6BAA6B,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAChE"}
|
|
1
|
+
{"version":3,"file":"renders.cjs","names":["z","output: RenderOutputConfiguration","assertTypesMatch","CompletionIterator"],"sources":["../../src/resources/renders.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:renders\");\n\nconst H264Configuration = z.object({\n codec: z.literal(\"h264\"),\n});\n\nconst AACConfiguration = z.object({\n codec: z.literal(\"aac\"),\n});\n\nconst MP4Configuration = z.object({\n container: z.literal(\"mp4\"),\n video: H264Configuration,\n audio: AACConfiguration,\n});\n\nconst JpegConfiguration = z.object({\n container: z.literal(\"jpeg\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n});\n\nconst PngConfiguration = z.object({\n container: z.literal(\"png\"),\n compression: z.number().int().min(1).max(100).default(80).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nconst WebpConfiguration = z.object({\n container: z.literal(\"webp\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n compression: z.number().int().min(0).max(6).default(4).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nexport const RenderOutputConfiguration = z.discriminatedUnion(\"container\", [\n MP4Configuration,\n JpegConfiguration,\n PngConfiguration,\n WebpConfiguration,\n]);\n\nexport type RenderOutputConfiguration = z.infer<typeof RenderOutputConfiguration>;\n\nexport const CreateRenderPayload = z.object({\n md5: z.string().optional(),\n fps: z.number().int().min(1).max(120).default(30).optional(),\n width: z.number().int().min(2).optional(),\n height: z.number().int().min(2).optional(),\n work_slice_ms: z.number().int().min(1000).max(10_000).default(4_000).optional(),\n html: z.string().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n duration_ms: z.number().int().optional(),\n strategy: z.enum([\"v1\"]).default(\"v1\").optional(),\n backend: z.enum([\"cpu\", \"gpu\"]).default(\"cpu\").optional(),\n output: RenderOutputConfiguration.default({\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n }).optional(),\n});\n\nexport const CreateRenderPayloadWithOutput = CreateRenderPayload.extend({\n output: RenderOutputConfiguration,\n});\n\nexport class OutputConfiguration {\n static parse(input?: any) {\n const output = RenderOutputConfiguration.parse(\n input ?? {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n },\n );\n return new OutputConfiguration(output);\n }\n\n constructor(public readonly output: RenderOutputConfiguration) {}\n\n get isStill() {\n return (\n this.output.container === \"jpeg\" ||\n this.output.container === \"png\" ||\n this.output.container === \"webp\"\n );\n }\n\n get isVideo() {\n return this.output.container === \"mp4\";\n }\n\n get fileExtension() {\n return this.output.container;\n }\n\n get contentType() {\n if (this.isStill) {\n return `image/${this.fileExtension}`;\n }\n return `video/${this.fileExtension}`;\n }\n\n get container() {\n return this.output.container;\n }\n\n get jpegConfig() {\n return this.output.container === \"jpeg\" ? this.output : null;\n }\n\n get pngConfig() {\n return this.output.container === \"png\" ? this.output : null;\n }\n\n get webpConfig() {\n return this.output.container === \"webp\" ? this.output : null;\n }\n\n get mp4Config() {\n return this.output.container === \"mp4\" ? this.output : null;\n }\n}\n\nexport interface CreateRenderPayload {\n md5?: string;\n fps?: number;\n width?: number;\n height?: number;\n work_slice_ms?: number;\n html?: string;\n duration_ms?: number;\n metadata?: Record<string, string>;\n strategy?: \"v1\";\n backend?: \"cpu\" | \"gpu\";\n output?: z.infer<typeof RenderOutputConfiguration>;\n}\n\nassertTypesMatch<CreateRenderPayload, z.infer<typeof CreateRenderPayload>>(true);\n\nexport interface CreateRenderResult {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport interface LookupRenderByMd5Result {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport const createRender = async (client: Client, payload: CreateRenderPayload) => {\n log(\"Creating render\", payload);\n // FIXME: The order of optional/default matters in zod\n // And if we set the default last, the type is not inferred correctly\n // Manually applying defaults here is a hack\n payload.strategy ??= \"v1\";\n payload.work_slice_ms ??= 4_000;\n payload.output ??= {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n };\n\n const response = await client.authenticatedFetch(\"/api/v1/renders\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Render created\", response);\n if (response.ok) {\n return (await response.json()) as CreateRenderResult;\n }\n\n throw new Error(\n `Failed to create render ${response.status} ${response.statusText} ${await response.text()}`,\n );\n};\n\nexport const uploadRender = async (\n client: Client,\n renderId: string,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading render\", renderId);\n const response = await client.authenticatedFetch(`/api/v1/renders/${renderId}/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload render ${response.status} ${response.statusText}`);\n};\n\nexport const getRenderInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}`);\n return response.json() as Promise<LookupRenderByMd5Result>;\n};\n\nexport const lookupRenderByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupRenderByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/renders/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupRenderByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup render by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(`/api/v1/renders/${id}/progress`);\n\n return new CompletionIterator(eventSource);\n};\n\nexport const downloadRender = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}.mp4`);\n\n if (response.ok) {\n return response;\n }\n\n throw new Error(`Failed to download render ${id} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;;;AAMA,MAAM,yBAAY,iBAAiB;AAEnC,MAAM,oBAAoBA,MAAE,OAAO,EACjC,OAAOA,MAAE,QAAQ,OAAO,EACzB,CAAC;AAEF,MAAM,mBAAmBA,MAAE,OAAO,EAChC,OAAOA,MAAE,QAAQ,MAAM,EACxB,CAAC;AAEF,MAAM,mBAAmBA,MAAE,OAAO;CAChC,WAAWA,MAAE,QAAQ,MAAM;CAC3B,OAAO;CACP,OAAO;CACR,CAAC;AAEF,MAAM,oBAAoBA,MAAE,OAAO;CACjC,WAAWA,MAAE,QAAQ,O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aACtE;;AAGH,MAAa,oBAAoB,OAAO,QAAgB,OAAe;AAGrE,QAAO,IAAIC,4CAFS,MAAM,OAAO,yBAAyB,mBAAmB,GAAG,WAAW,CAEjD;;AAG5C,MAAa,iBAAiB,OAAO,QAAgB,OAAe;CAClE,MAAM,WAAW,MAAM,OAAO,mBAAmB,mBAAmB,GAAG,MAAM;AAE7E,KAAI,SAAS,GACX,QAAO;AAGT,OAAM,IAAI,MAAM,6BAA6B,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renders.js","names":["output: RenderOutputConfiguration"],"sources":["../../src/resources/renders.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:renders\");\n\nconst H264Configuration = z.object({\n codec: z.literal(\"h264\"),\n});\n\nconst AACConfiguration = z.object({\n codec: z.literal(\"aac\"),\n});\n\nconst MP4Configuration = z.object({\n container: z.literal(\"mp4\"),\n video: H264Configuration,\n audio: AACConfiguration,\n});\n\nconst JpegConfiguration = z.object({\n container: z.literal(\"jpeg\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n});\n\nconst PngConfiguration = z.object({\n container: z.literal(\"png\"),\n compression: z.number().int().min(1).max(100).default(80).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nconst WebpConfiguration = z.object({\n container: z.literal(\"webp\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n compression: z.number().int().min(0).max(6).default(4).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nexport const RenderOutputConfiguration = z.discriminatedUnion(\"container\", [\n MP4Configuration,\n JpegConfiguration,\n PngConfiguration,\n WebpConfiguration,\n]);\n\nexport type RenderOutputConfiguration = z.infer<\n typeof RenderOutputConfiguration\n>;\n\nexport const CreateRenderPayload = z.object({\n md5: z.string().optional(),\n fps: z.number().int().min(1).max(120).default(30).optional(),\n width: z.number().int().min(2).optional(),\n height: z.number().int().min(2).optional(),\n work_slice_ms: z\n .number()\n .int()\n .min(1000)\n .max(10_000)\n .default(4_000)\n .optional(),\n html: z.string().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n duration_ms: z.number().int().optional(),\n strategy: z.enum([\"v1\"]).default(\"v1\").optional(),\n backend: z.enum([\"cpu\", \"gpu\"]).default(\"cpu\").optional(),\n output: RenderOutputConfiguration.default({\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n }).optional(),\n});\n\nexport const CreateRenderPayloadWithOutput = CreateRenderPayload.extend({\n output: RenderOutputConfiguration,\n});\n\nexport class OutputConfiguration {\n static parse(input?: any) {\n const output = RenderOutputConfiguration.parse(\n input ?? {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n },\n );\n return new OutputConfiguration(output);\n }\n\n constructor(public readonly output: RenderOutputConfiguration) {}\n\n get isStill() {\n return (\n this.output.container === \"jpeg\" ||\n this.output.container === \"png\" ||\n this.output.container === \"webp\"\n );\n }\n\n get isVideo() {\n return this.output.container === \"mp4\";\n }\n\n get fileExtension() {\n return this.output.container;\n }\n\n get contentType() {\n if (this.isStill) {\n return `image/${this.fileExtension}`;\n }\n return `video/${this.fileExtension}`;\n }\n\n get container() {\n return this.output.container;\n }\n\n get jpegConfig() {\n return this.output.container === \"jpeg\" ? this.output : null;\n }\n\n get pngConfig() {\n return this.output.container === \"png\" ? this.output : null;\n }\n\n get webpConfig() {\n return this.output.container === \"webp\" ? this.output : null;\n }\n\n get mp4Config() {\n return this.output.container === \"mp4\" ? this.output : null;\n }\n}\n\nexport interface CreateRenderPayload {\n md5?: string;\n fps?: number;\n width?: number;\n height?: number;\n work_slice_ms?: number;\n html?: string;\n duration_ms?: number;\n metadata?: Record<string, string>;\n strategy?: \"v1\";\n backend?: \"cpu\" | \"gpu\";\n output?: z.infer<typeof RenderOutputConfiguration>;\n}\n\nassertTypesMatch<CreateRenderPayload, z.infer<typeof CreateRenderPayload>>(\n true,\n);\n\nexport interface CreateRenderResult {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport interface LookupRenderByMd5Result {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport const createRender = async (\n client: Client,\n payload: CreateRenderPayload,\n) => {\n log(\"Creating render\", payload);\n // FIXME: The order of optional/default matters in zod\n // And if we set the default last, the type is not inferred correctly\n // Manually applying defaults here is a hack\n payload.strategy ??= \"v1\";\n payload.work_slice_ms ??= 4_000;\n payload.output ??= {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n };\n\n const response = await client.authenticatedFetch(\"/api/v1/renders\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Render created\", response);\n if (response.ok) {\n return (await response.json()) as CreateRenderResult;\n }\n\n throw new Error(\n `Failed to create render ${response.status} ${response.statusText} ${await response.text()}`,\n );\n};\n\nexport const uploadRender = async (\n client: Client,\n renderId: string,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading render\", renderId);\n const response = await client.authenticatedFetch(\n `/api/v1/renders/${renderId}/upload`,\n {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n },\n );\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(\n `Failed to upload render ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}`);\n return response.json() as Promise<LookupRenderByMd5Result>;\n};\n\nexport const lookupRenderByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupRenderByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/renders/md5/${md5}`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupRenderByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup render by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/renders/${id}/progress`,\n );\n\n return new CompletionIterator(eventSource);\n};\n\nexport const downloadRender = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}.mp4`);\n\n if (response.ok) {\n return response;\n }\n\n throw new Error(\n `Failed to download render ${id} ${response.status} ${response.statusText}`,\n );\n};\n"],"mappings":";;;;;;AAMA,MAAM,MAAM,MAAM,iBAAiB;AAEnC,MAAM,oBAAoB,EAAE,OAAO,EACjC,OAAO,EAAE,QAAQ,OAAO,EACzB,CAAC;AAEF,MAAM,mBAAmB,EAAE,OAAO,EAChC,OAAO,EAAE,QAAQ,MAAM,EACxB,CAAC;AAEF,MAAM,mBAAmB,EAAE,OAAO;CAChC,WAAW,EAAE,QAAQ,MAAM;CAC3B,OAAO;CACP,OAAO;CACR,CAAC;AAEF,MAAM,oBAAoB,EAAE,OAAO;CACjC,WAAW,EAAE,QAAQ,OAAO;CAC5B,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,UAAU;CACjE,CAAC;AAEF,MAAM,mBAAmB,EAAE,OAAO;CAChC,WAAW,EAAE,QAAQ,MAAM;CAC3B,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,UAAU;CACpE,cAAc,EAAE,SAAS,CAAC,QAAQ,MAAM,CAAC,UAAU;CACpD,CAAC;AAEF,MAAM,oBAAoB,EAAE,OAAO;CACjC,WAAW,EAAE,QAAQ,O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AQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MACR,2BAA2B,SAAS,OAAO,GAAG,SAAS,WAAW,GAAG,MAAM,SAAS,MAAM,GAC3F;;AAGH,MAAa,eAAe,OAC1B,QACA,UACA,eACG;AACH,KAAI,oBAAoB,SAAS;CACjC,MAAM,WAAW,MAAM,OAAO,mBAC5B,mBAAmB,SAAS,UAC5B;EACE,QAAQ;EACR,MAAM;EACN,QAAQ;EACT,CACF;AAED,KAAI,SAAS,GACX,QAAO,SAAS,MAAM;AAGxB,OAAM,IAAI,MACR,2BAA2B,SAAS,OAAO,GAAG,SAAS,aACxD;;AAGH,MAAa,gBAAgB,OAAO,QAAgB,OAAe;AAEjE,SADiB,MAAM,OAAO,mBAAmB,mBAAmB,KAAK,EACzD,MAAM;;AAGxB,MAAa,oBAAoB,OAC/B,QACA,QAC4C;CAC5C,MAAM,WAAW,MAAM,OAAO,mBAC5B,uBAAuB,OACvB,EACE,QAAQ,OACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,kCAAkC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACtE;;AAGH,MAAa,oBAAoB,OAAO,QAAgB,OAAe;AAKrE,QAAO,IAAI,mBAJS,MAAM,OAAO,yBAC/B,mBAAmB,GAAG,WACvB,CAEyC;;AAG5C,MAAa,iBAAiB,OAAO,QAAgB,OAAe;CAClE,MAAM,WAAW,MAAM,OAAO,mBAAmB,mBAAmB,GAAG,MAAM;AAE7E,KAAI,SAAS,GACX,QAAO;AAGT,OAAM,IAAI,MACR,6BAA6B,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAChE"}
|
|
1
|
+
{"version":3,"file":"renders.js","names":["output: RenderOutputConfiguration"],"sources":["../../src/resources/renders.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:renders\");\n\nconst H264Configuration = z.object({\n codec: z.literal(\"h264\"),\n});\n\nconst AACConfiguration = z.object({\n codec: z.literal(\"aac\"),\n});\n\nconst MP4Configuration = z.object({\n container: z.literal(\"mp4\"),\n video: H264Configuration,\n audio: AACConfiguration,\n});\n\nconst JpegConfiguration = z.object({\n container: z.literal(\"jpeg\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n});\n\nconst PngConfiguration = z.object({\n container: z.literal(\"png\"),\n compression: z.number().int().min(1).max(100).default(80).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nconst WebpConfiguration = z.object({\n container: z.literal(\"webp\"),\n quality: z.number().int().min(1).max(100).default(80).optional(),\n compression: z.number().int().min(0).max(6).default(4).optional(),\n transparency: z.boolean().default(false).optional(),\n});\n\nexport const RenderOutputConfiguration = z.discriminatedUnion(\"container\", [\n MP4Configuration,\n JpegConfiguration,\n PngConfiguration,\n WebpConfiguration,\n]);\n\nexport type RenderOutputConfiguration = z.infer<typeof RenderOutputConfiguration>;\n\nexport const CreateRenderPayload = z.object({\n md5: z.string().optional(),\n fps: z.number().int().min(1).max(120).default(30).optional(),\n width: z.number().int().min(2).optional(),\n height: z.number().int().min(2).optional(),\n work_slice_ms: z.number().int().min(1000).max(10_000).default(4_000).optional(),\n html: z.string().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n duration_ms: z.number().int().optional(),\n strategy: z.enum([\"v1\"]).default(\"v1\").optional(),\n backend: z.enum([\"cpu\", \"gpu\"]).default(\"cpu\").optional(),\n output: RenderOutputConfiguration.default({\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n }).optional(),\n});\n\nexport const CreateRenderPayloadWithOutput = CreateRenderPayload.extend({\n output: RenderOutputConfiguration,\n});\n\nexport class OutputConfiguration {\n static parse(input?: any) {\n const output = RenderOutputConfiguration.parse(\n input ?? {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n },\n );\n return new OutputConfiguration(output);\n }\n\n constructor(public readonly output: RenderOutputConfiguration) {}\n\n get isStill() {\n return (\n this.output.container === \"jpeg\" ||\n this.output.container === \"png\" ||\n this.output.container === \"webp\"\n );\n }\n\n get isVideo() {\n return this.output.container === \"mp4\";\n }\n\n get fileExtension() {\n return this.output.container;\n }\n\n get contentType() {\n if (this.isStill) {\n return `image/${this.fileExtension}`;\n }\n return `video/${this.fileExtension}`;\n }\n\n get container() {\n return this.output.container;\n }\n\n get jpegConfig() {\n return this.output.container === \"jpeg\" ? this.output : null;\n }\n\n get pngConfig() {\n return this.output.container === \"png\" ? this.output : null;\n }\n\n get webpConfig() {\n return this.output.container === \"webp\" ? this.output : null;\n }\n\n get mp4Config() {\n return this.output.container === \"mp4\" ? this.output : null;\n }\n}\n\nexport interface CreateRenderPayload {\n md5?: string;\n fps?: number;\n width?: number;\n height?: number;\n work_slice_ms?: number;\n html?: string;\n duration_ms?: number;\n metadata?: Record<string, string>;\n strategy?: \"v1\";\n backend?: \"cpu\" | \"gpu\";\n output?: z.infer<typeof RenderOutputConfiguration>;\n}\n\nassertTypesMatch<CreateRenderPayload, z.infer<typeof CreateRenderPayload>>(true);\n\nexport interface CreateRenderResult {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport interface LookupRenderByMd5Result {\n id: string;\n md5: string | null;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"rendering\" | string;\n metadata: Record<string, string>;\n}\n\nexport const createRender = async (client: Client, payload: CreateRenderPayload) => {\n log(\"Creating render\", payload);\n // FIXME: The order of optional/default matters in zod\n // And if we set the default last, the type is not inferred correctly\n // Manually applying defaults here is a hack\n payload.strategy ??= \"v1\";\n payload.work_slice_ms ??= 4_000;\n payload.output ??= {\n container: \"mp4\",\n video: {\n codec: \"h264\",\n },\n audio: {\n codec: \"aac\",\n },\n };\n\n const response = await client.authenticatedFetch(\"/api/v1/renders\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Render created\", response);\n if (response.ok) {\n return (await response.json()) as CreateRenderResult;\n }\n\n throw new Error(\n `Failed to create render ${response.status} ${response.statusText} ${await response.text()}`,\n );\n};\n\nexport const uploadRender = async (\n client: Client,\n renderId: string,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading render\", renderId);\n const response = await client.authenticatedFetch(`/api/v1/renders/${renderId}/upload`, {\n method: \"POST\",\n body: fileStream,\n duplex: \"half\",\n });\n\n if (response.ok) {\n return response.json();\n }\n\n throw new Error(`Failed to upload render ${response.status} ${response.statusText}`);\n};\n\nexport const getRenderInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}`);\n return response.json() as Promise<LookupRenderByMd5Result>;\n};\n\nexport const lookupRenderByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupRenderByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/renders/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupRenderByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup render by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\nexport const getRenderProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(`/api/v1/renders/${id}/progress`);\n\n return new CompletionIterator(eventSource);\n};\n\nexport const downloadRender = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/renders/${id}.mp4`);\n\n if (response.ok) {\n return response;\n }\n\n throw new Error(`Failed to download render ${id} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;AAMA,MAAM,MAAM,MAAM,iBAAiB;AAEnC,MAAM,oBAAoB,EAAE,OAAO,EACjC,OAAO,EAAE,QAAQ,OAAO,EAC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AAW,MAAM,OAAO,mBAAmB,uBAAuB,OAAO,EAC7E,QAAQ,OACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,kCAAkC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACtE;;AAGH,MAAa,oBAAoB,OAAO,QAAgB,OAAe;AAGrE,QAAO,IAAI,mBAFS,MAAM,OAAO,yBAAyB,mBAAmB,GAAG,WAAW,CAEjD;;AAG5C,MAAa,iBAAiB,OAAO,QAAgB,OAAe;CAClE,MAAM,WAAW,MAAM,OAAO,mBAAmB,mBAAmB,GAAG,MAAM;AAE7E,KAAI,SAAS,GACX,QAAO;AAGT,OAAM,IAAI,MAAM,6BAA6B,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transcriptions.cjs","names":["z","CompletionIterator"],"sources":["../../src/resources/transcriptions.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\n\nconst log = debug(\"ef:api:transcriptions\");\n\nexport const CreateTranscriptionPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n});\n\nexport type CreateTranscriptionPayload = z.infer
|
|
1
|
+
{"version":3,"file":"transcriptions.cjs","names":["z","CompletionIterator"],"sources":["../../src/resources/transcriptions.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\n\nconst log = debug(\"ef:api:transcriptions\");\n\nexport const CreateTranscriptionPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n});\n\nexport type CreateTranscriptionPayload = z.infer<typeof CreateTranscriptionPayload>;\n\nexport interface CreateTranscriptionResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport interface TranscriptionInfoResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport const createTranscription = async (client: Client, payload: CreateTranscriptionPayload) => {\n log(\"Creating transcription\", payload);\n const response = await client.authenticatedFetch(\"/api/v1/transcriptions\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Transcription created\", response);\n if (response.ok) {\n return (await response.json()) as CreateTranscriptionResult;\n }\n\n throw new Error(`Failed to create transcription ${response.status} ${response.statusText}`);\n};\n\nexport const getTranscriptionProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/transcriptions/${id}/progress`,\n );\n\n return new CompletionIterator(eventSource);\n};\n\nexport const getTranscriptionInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/transcriptions/${id}`);\n\n if (response.ok) {\n return (await response.json()) as TranscriptionInfoResult;\n }\n\n throw new Error(`Failed to get transcription info ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;;AAKA,MAAM,yBAAY,wBAAwB;AAE1C,MAAa,6BAA6BA,MAAE,OAAO;CACjD,SAASA,MAAE,QAAQ;CACnB,UAAUA,MAAE,QAAQ,CAAC,KAAK;CAC3B,CAAC;AAcF,MAAa,sBAAsB,OAAO,QAAgB,YAAwC;AAChG,KAAI,0BAA0B,QAAQ;CACtC,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B;EACzE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,yBAAyB,SAAS;AACtC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,kCAAkC,SAAS,OAAO,GAAG,SAAS,aAAa;;AAG7F,MAAa,2BAA2B,OAAO,QAAgB,OAAe;AAK5E,QAAO,IAAIC,4CAJS,MAAM,OAAO,yBAC/B,0BAA0B,GAAG,WAC9B,CAEyC;;AAG5C,MAAa,uBAAuB,OAAO,QAAgB,OAAe;CACxE,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B,KAAK;AAEhF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,oCAAoC,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transcriptions.js","names":[],"sources":["../../src/resources/transcriptions.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\n\nconst log = debug(\"ef:api:transcriptions\");\n\nexport const CreateTranscriptionPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n});\n\nexport type CreateTranscriptionPayload = z.infer
|
|
1
|
+
{"version":3,"file":"transcriptions.js","names":[],"sources":["../../src/resources/transcriptions.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\nimport type { Client } from \"../client.js\";\nimport { CompletionIterator } from \"../ProgressIterator.js\";\n\nconst log = debug(\"ef:api:transcriptions\");\n\nexport const CreateTranscriptionPayload = z.object({\n file_id: z.string(),\n track_id: z.number().int(),\n});\n\nexport type CreateTranscriptionPayload = z.infer<typeof CreateTranscriptionPayload>;\n\nexport interface CreateTranscriptionResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport interface TranscriptionInfoResult {\n id: string;\n status: \"complete\" | \"created\" | \"failed\" | \"pending\" | \"transcribing\";\n}\n\nexport const createTranscription = async (client: Client, payload: CreateTranscriptionPayload) => {\n log(\"Creating transcription\", payload);\n const response = await client.authenticatedFetch(\"/api/v1/transcriptions\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Transcription created\", response);\n if (response.ok) {\n return (await response.json()) as CreateTranscriptionResult;\n }\n\n throw new Error(`Failed to create transcription ${response.status} ${response.statusText}`);\n};\n\nexport const getTranscriptionProgress = async (client: Client, id: string) => {\n const eventSource = await client.authenticatedEventSource(\n `/api/v1/transcriptions/${id}/progress`,\n );\n\n return new CompletionIterator(eventSource);\n};\n\nexport const getTranscriptionInfo = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/transcriptions/${id}`);\n\n if (response.ok) {\n return (await response.json()) as TranscriptionInfoResult;\n }\n\n throw new Error(`Failed to get transcription info ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;AAKA,MAAM,MAAM,MAAM,wBAAwB;AAE1C,MAAa,6BAA6B,EAAE,OAAO;CACjD,SAAS,EAAE,QAAQ;CACnB,UAAU,EAAE,QAAQ,CAAC,KAAK;CAC3B,CAAC;AAcF,MAAa,sBAAsB,OAAO,QAAgB,YAAwC;AAChG,KAAI,0BAA0B,QAAQ;CACtC,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B;EACzE,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,yBAAyB,SAAS;AACtC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,kCAAkC,SAAS,OAAO,GAAG,SAAS,aAAa;;AAG7F,MAAa,2BAA2B,OAAO,QAAgB,OAAe;AAK5E,QAAO,IAAI,mBAJS,MAAM,OAAO,yBAC/B,0BAA0B,GAAG,WAC9B,CAEyC;;AAG5C,MAAa,uBAAuB,OAAO,QAAgB,OAAe;CACxE,MAAM,WAAW,MAAM,OAAO,mBAAmB,0BAA0B,KAAK;AAEhF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,oCAAoC,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessed-file.cjs","names":["z","assertTypesMatch","uploadChunks"],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer
|
|
1
|
+
{"version":3,"file":"unprocessed-file.cjs","names":["z","assertTypesMatch","uploadChunks"],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer<typeof CreateUnprocessedFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFile {\n byte_size: number;\n next_byte: number;\n complete: boolean;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFileUploadDetails {\n id: string;\n byte_size: number;\n}\n\n// Ensure that the UnprocessedFileUploadDetails type matches the shape of the\n// UnprocessedFile type, but without the optional fields.\nassertTypesMatch<Pick<UnprocessedFile, \"id\" | \"byte_size\">, UnprocessedFileUploadDetails>(true);\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UpdateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface ProcessIsobmffFileResult {\n id: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createUnprocessedFile = async (\n client: Client,\n payload: CreateUnprocessedFilePayload,\n) => {\n log(\"Creating an unprocessed file\", payload);\n CreateUnprocessedFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/unprocessed_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Unprocessed file created\", response.status, response.statusText, response.headers);\n\n if (response.ok) {\n return (await response.json()) as CreateUnprocessedFileResult;\n }\n\n throw new Error(`Failed to create unprocessed file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadUnprocessedReadableStream = (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading unprocessed file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_FILE_SIZE,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupUnprocessedFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupUnprocessedFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupUnprocessedFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const processIsobmffFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/${id}/isobmff`, {\n method: \"POST\",\n });\n\n if (response.ok) {\n return (await response.json()) as ProcessIsobmffFileResult;\n }\n\n throw new Error(`Failed to process isobmff file ${id} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;;;;AAOA,MAAM,yBAAY,0BAA0B;AAE5C,MAAM,gBAAgB,OAAO,OAAO;AAEpC,MAAa,+BAA+BA,MAAE,OAAO;CACnD,KAAKA,MAAE,QAAQ;CACf,UAAUA,MAAE,QAAQ;CACpB,WAAWA,MAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc;CAC/C,CAAC;AAEF,MAAa,+BAA+BA,MAAE,OAAO,EAAE,CAAC;AAqBxDC,0CAA0F,KAAK;;AAiB/F,MAAa,wBAAwB,OACnC,QACA,YACG;AACH,KAAI,gCAAgC,QAAQ;AAC5C,8BAA6B,MAAM,QAAQ;CAC3C,MAAM,WAAW,MAAM,OAAO,mBAAmB,6BAA6B;EAC5E,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,4BAA4B,SAAS,QAAQ,SAAS,YAAY,SAAS,QAAQ;AAEvF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,qCAAqC,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAIhG,MAAa,mCACX,QACA,eACA,eACG;AACH,KAAI,8BAA8B,cAAc,GAAG;AAEnD,QAAOC,kCAAa,QAAQ;EAC1B,KAAK,6BAA6B,cAAc,GAAG;EACnD,UAAU,cAAc;EACxB;EACA,SAAS;EACV,CAAC;;;AAIJ,MAAa,6BAA6B,OACxC,QACA,QACqD;CACrD,MAAM,WAAW,MAAM,OAAO,mBAAmB,iCAAiC,OAAO,EACvF,QAAQ,OACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,4CAA4C,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAChF;;;AAIH,MAAa,qBAAqB,OAAO,QAAgB,OAAe;CACtE,MAAM,WAAW,MAAM,OAAO,mBAAmB,6BAA6B,GAAG,WAAW,EAC1F,QAAQ,QACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,kCAAkC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessed-file.js","names":[],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer
|
|
1
|
+
{"version":3,"file":"unprocessed-file.js","names":[],"sources":["../../src/resources/unprocessed-file.ts"],"sourcesContent":["import debug from \"debug\";\nimport { z } from \"zod\";\n\nimport type { Client } from \"../client.js\";\nimport { uploadChunks } from \"../uploadChunks.js\";\nimport { assertTypesMatch } from \"../utils/assertTypesMatch.ts\";\n\nconst log = debug(\"ef:api:unprocessed-file\");\n\nconst MAX_FILE_SIZE = 1024 * 1024 * 1024; // 1GiB\n\nexport const CreateUnprocessedFilePayload = z.object({\n md5: z.string(),\n filename: z.string(),\n byte_size: z.number().int().max(MAX_FILE_SIZE),\n});\n\nexport const UpdateUnprocessedFilePayload = z.object({});\n\nexport type CreateUnprocessedFilePayload = z.infer<typeof CreateUnprocessedFilePayload>;\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFile {\n byte_size: number;\n next_byte: number;\n complete: boolean;\n id: string;\n md5: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UnprocessedFileUploadDetails {\n id: string;\n byte_size: number;\n}\n\n// Ensure that the UnprocessedFileUploadDetails type matches the shape of the\n// UnprocessedFile type, but without the optional fields.\nassertTypesMatch<Pick<UnprocessedFile, \"id\" | \"byte_size\">, UnprocessedFileUploadDetails>(true);\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface CreateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface LookupUnprocessedFileByMd5Result extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface UpdateUnprocessedFileResult extends UnprocessedFile {}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport interface ProcessIsobmffFileResult {\n id: string;\n}\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const createUnprocessedFile = async (\n client: Client,\n payload: CreateUnprocessedFilePayload,\n) => {\n log(\"Creating an unprocessed file\", payload);\n CreateUnprocessedFilePayload.parse(payload);\n const response = await client.authenticatedFetch(\"/api/v1/unprocessed_files\", {\n method: \"POST\",\n body: JSON.stringify(payload),\n });\n\n log(\"Unprocessed file created\", response.status, response.statusText, response.headers);\n\n if (response.ok) {\n return (await response.json()) as CreateUnprocessedFileResult;\n }\n\n throw new Error(`Failed to create unprocessed file ${response.status} ${response.statusText}`);\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const uploadUnprocessedReadableStream = (\n client: Client,\n uploadDetails: UnprocessedFileUploadDetails,\n fileStream: ReadableStream,\n) => {\n log(\"Uploading unprocessed file\", uploadDetails.id);\n\n return uploadChunks(client, {\n url: `/api/v1/unprocessed_files/${uploadDetails.id}/upload`,\n fileSize: uploadDetails.byte_size,\n fileStream,\n maxSize: MAX_FILE_SIZE,\n });\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const lookupUnprocessedFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupUnprocessedFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/md5/${md5}`, {\n method: \"GET\",\n });\n\n if (response.ok) {\n return (await response.json()) as LookupUnprocessedFileByMd5Result;\n }\n\n if (response.status === 404) {\n return null;\n }\n\n throw new Error(\n `Failed to lookup unprocessed file by md5 ${md5} ${response.status} ${response.statusText}`,\n );\n};\n\n/** @deprecated Use the unified file API from ./file.js instead */\nexport const processIsobmffFile = async (client: Client, id: string) => {\n const response = await client.authenticatedFetch(`/api/v1/unprocessed_files/${id}/isobmff`, {\n method: \"POST\",\n });\n\n if (response.ok) {\n return (await response.json()) as ProcessIsobmffFileResult;\n }\n\n throw new Error(`Failed to process isobmff file ${id} ${response.status} ${response.statusText}`);\n};\n"],"mappings":";;;;;;AAOA,MAAM,MAAM,MAAM,0BAA0B;AAE5C,MAAM,gBAAgB,OAAO,OAAO;AAEpC,MAAa,+BAA+B,EAAE,OAAO;CACnD,KAAK,EAAE,QAAQ;CACf,UAAU,EAAE,QAAQ;CACpB,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,cAAc;CAC/C,CAAC;AAEF,MAAa,+BAA+B,EAAE,OAAO,EAAE,CAAC;AAqBxD,iBAA0F,KAAK;;AAiB/F,MAAa,wBAAwB,OACnC,QACA,YACG;AACH,KAAI,gCAAgC,QAAQ;AAC5C,8BAA6B,MAAM,QAAQ;CAC3C,MAAM,WAAW,MAAM,OAAO,mBAAmB,6BAA6B;EAC5E,QAAQ;EACR,MAAM,KAAK,UAAU,QAAQ;EAC9B,CAAC;AAEF,KAAI,4BAA4B,SAAS,QAAQ,SAAS,YAAY,SAAS,QAAQ;AAEvF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,qCAAqC,SAAS,OAAO,GAAG,SAAS,aAAa;;;AAIhG,MAAa,mCACX,QACA,eACA,eACG;AACH,KAAI,8BAA8B,cAAc,GAAG;AAEnD,QAAO,aAAa,QAAQ;EAC1B,KAAK,6BAA6B,cAAc,GAAG;EACnD,UAAU,cAAc;EACxB;EACA,SAAS;EACV,CAAC;;;AAIJ,MAAa,6BAA6B,OACxC,QACA,QACqD;CACrD,MAAM,WAAW,MAAM,OAAO,mBAAmB,iCAAiC,OAAO,EACvF,QAAQ,OACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,4CAA4C,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aAChF;;;AAIH,MAAa,qBAAqB,OAAO,QAAgB,OAAe;CACtE,MAAM,WAAW,MAAM,OAAO,mBAAmB,6BAA6B,GAAG,WAAW,EAC1F,QAAQ,QACT,CAAC;AAEF,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,OAAM,IAAI,MAAM,kCAAkC,GAAG,GAAG,SAAS,OAAO,GAAG,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamChunker.cjs","names":["CHUNK_SIZE_BYTES"],"sources":["../src/streamChunker.ts"],"sourcesContent":["import { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\n\nexport async function* streamChunker(
|
|
1
|
+
{"version":3,"file":"streamChunker.cjs","names":["CHUNK_SIZE_BYTES"],"sources":["../src/streamChunker.ts"],"sourcesContent":["import { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\n\nexport async function* streamChunker(readableStream: ReadableStream, chunkSize = CHUNK_SIZE_BYTES) {\n const reader = readableStream.getReader();\n let buffer = new Uint8Array(0);\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = value;\n const newBuffer = new Uint8Array(buffer.length + chunk.length);\n newBuffer.set(buffer);\n newBuffer.set(chunk, buffer.length);\n buffer = newBuffer;\n\n while (buffer.length >= chunkSize) {\n yield buffer.slice(0, chunkSize);\n buffer = buffer.slice(chunkSize);\n }\n }\n\n if (buffer.length > 0) {\n yield buffer;\n }\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";;;AAEA,gBAAuB,cAAc,gBAAgC,YAAYA,2CAAkB;CACjG,MAAM,SAAS,eAAe,WAAW;CACzC,IAAI,SAAS,IAAI,WAAW,EAAE;AAE9B,KAAI;AACF,SAAO,MAAM;GACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAC3C,OAAI,KAAM;GAEV,MAAM,QAAQ;GACd,MAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,OAAO;AAC9D,aAAU,IAAI,OAAO;AACrB,aAAU,IAAI,OAAO,OAAO,OAAO;AACnC,YAAS;AAET,UAAO,OAAO,UAAU,WAAW;AACjC,UAAM,OAAO,MAAM,GAAG,UAAU;AAChC,aAAS,OAAO,MAAM,UAAU;;;AAIpC,MAAI,OAAO,SAAS,EAClB,OAAM;WAEA;AACR,SAAO,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamChunker.js","names":[],"sources":["../src/streamChunker.ts"],"sourcesContent":["import { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\n\nexport async function* streamChunker(
|
|
1
|
+
{"version":3,"file":"streamChunker.js","names":[],"sources":["../src/streamChunker.ts"],"sourcesContent":["import { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\n\nexport async function* streamChunker(readableStream: ReadableStream, chunkSize = CHUNK_SIZE_BYTES) {\n const reader = readableStream.getReader();\n let buffer = new Uint8Array(0);\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = value;\n const newBuffer = new Uint8Array(buffer.length + chunk.length);\n newBuffer.set(buffer);\n newBuffer.set(chunk, buffer.length);\n buffer = newBuffer;\n\n while (buffer.length >= chunkSize) {\n yield buffer.slice(0, chunkSize);\n buffer = buffer.slice(chunkSize);\n }\n }\n\n if (buffer.length > 0) {\n yield buffer;\n }\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";;;AAEA,gBAAuB,cAAc,gBAAgC,YAAY,kBAAkB;CACjG,MAAM,SAAS,eAAe,WAAW;CACzC,IAAI,SAAS,IAAI,WAAW,EAAE;AAE9B,KAAI;AACF,SAAO,MAAM;GACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAC3C,OAAI,KAAM;GAEV,MAAM,QAAQ;GACd,MAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,OAAO;AAC9D,aAAU,IAAI,OAAO;AACrB,aAAU,IAAI,OAAO,OAAO,OAAO;AACnC,YAAS;AAET,UAAO,OAAO,UAAU,WAAW;AACjC,UAAM,OAAO,MAAM,GAAG,UAAU;AAChC,aAAS,OAAO,MAAM,UAAU;;;AAIpC,MAAI,OAAO,SAAS,EAClB,OAAM;WAEA;AACR,SAAO,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadChunks.cjs","names":["CHUNK_SIZE_BYTES","streamChunker","events: UploadChunkEvent[]"],"sources":["../src/uploadChunks.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\nimport type { Client } from \"./client.js\";\nimport { streamChunker } from \"./streamChunker.js\";\n\nconst log = debug(\"ef:api:uploadChunk\");\n\ninterface UploadChunkOptions {\n url: string;\n chunkBuffer: Uint8Array;\n chunkNumber: number;\n fileSize: number;\n chunkSizeBytes?: number;\n}\n\n/**\n * @internal\n */\nexport interface IteratorWithPromise<T> extends AsyncGenerator
|
|
1
|
+
{"version":3,"file":"uploadChunks.cjs","names":["CHUNK_SIZE_BYTES","streamChunker","events: UploadChunkEvent[]"],"sources":["../src/uploadChunks.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\nimport type { Client } from \"./client.js\";\nimport { streamChunker } from \"./streamChunker.js\";\n\nconst log = debug(\"ef:api:uploadChunk\");\n\ninterface UploadChunkOptions {\n url: string;\n chunkBuffer: Uint8Array;\n chunkNumber: number;\n fileSize: number;\n chunkSizeBytes?: number;\n}\n\n/**\n * @internal\n */\nexport interface IteratorWithPromise<T> extends AsyncGenerator<T, void, unknown> {\n whenUploaded: () => Promise<T[]>;\n}\n\nexport const fakeCompleteUpload = (): IteratorWithPromise<UploadChunkEvent> => {\n const makeGenerator = async function* (): AsyncGenerator<UploadChunkEvent, void, unknown> {\n yield { type: \"progress\", progress: 1 };\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n return [{ type: \"progress\", progress: 1 }];\n };\n return generator;\n};\n\nconst uploadChunk = async (\n client: Client,\n {\n url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes = CHUNK_SIZE_BYTES,\n }: UploadChunkOptions,\n) => {\n const startByte = chunkNumber * chunkSizeBytes;\n const endByte = startByte + chunkBuffer.length - 1;\n\n log(`Uploading chunk ${chunkNumber} for ${url}`);\n const response = await client.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Range\": `bytes=${startByte}-${endByte}/${fileSize}`,\n \"Content-Type\": \"application/octet-stream\",\n },\n body: chunkBuffer as BodyInit,\n });\n\n if (response.ok) {\n if (response.status === 201) {\n log(`File ${url} fully uploaded`);\n return { complete: true, body: await response.json() };\n }\n if (response.status === 202) {\n log(`File ${url} chunk ${chunkNumber} uploaded`);\n return { complete: false, body: await response.json() };\n }\n }\n\n throw new Error(\n `Failed to upload chunk ${chunkNumber} for ${url} ${response.status} ${response.statusText}`,\n );\n};\n\ninterface UploadChunksOptions {\n url: string;\n fileStream: ReadableStream;\n fileSize: number;\n maxSize: number;\n chunkSizeBytes?: number;\n}\n\nexport interface UploadChunkEvent {\n type: \"progress\";\n progress: number;\n}\n\nexport function uploadChunks(\n client: Client,\n { url, fileSize, fileStream, maxSize, chunkSizeBytes = CHUNK_SIZE_BYTES }: UploadChunksOptions,\n): IteratorWithPromise<UploadChunkEvent> {\n const makeGenerator = async function* (): AsyncGenerator<UploadChunkEvent, void, unknown> {\n if (fileSize > maxSize) {\n throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);\n }\n\n log(\"Checking upload status\", url);\n const uploadStatus = await client.authenticatedFetch(url);\n\n yield { type: \"progress\", progress: 0 };\n\n if (uploadStatus.status === 200) {\n log(\"Chunk already uploaded\");\n yield { type: \"progress\", progress: 1 };\n return;\n }\n\n let chunkNumber = 0;\n let complete = false;\n for await (const chunkBuffer of streamChunker(fileStream, chunkSizeBytes)) {\n log(`Uploading chunk ${chunkNumber}`);\n ({ complete } = await uploadChunk(client, {\n url: url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes,\n }));\n chunkNumber++;\n yield {\n type: \"progress\",\n progress: Math.min(1, chunkNumber / (fileSize / chunkSizeBytes)),\n };\n }\n if (!complete) {\n throw new Error(\"Did not complete upload\");\n }\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n if (fileSize > maxSize) {\n throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);\n }\n const events: UploadChunkEvent[] = [];\n for await (const event of generator) {\n events.push(event);\n }\n return events;\n };\n return generator;\n}\n"],"mappings":";;;;;;;AAMA,MAAM,yBAAY,qBAAqB;AA6BvC,MAAM,cAAc,OAClB,QACA,EACE,KACA,aACA,aACA,UACA,iBAAiBA,gDAEhB;CACH,MAAM,YAAY,cAAc;CAChC,MAAM,UAAU,YAAY,YAAY,SAAS;AAEjD,KAAI,mBAAmB,YAAY,OAAO,MAAM;CAChD,MAAM,WAAW,MAAM,OAAO,mBAAmB,KAAK;EACpD,QA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U,eAAe,YAAY;AACnC,MAAI,WAAW,QACb,OAAM,IAAI,MAAM,aAAa,SAAS,uBAAuB,QAAQ,QAAQ;EAE/E,MAAMC,SAA6B,EAAE;AACrC,aAAW,MAAM,SAAS,UACxB,QAAO,KAAK,MAAM;AAEpB,SAAO;;AAET,QAAO"}
|
package/dist/uploadChunks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadChunks.js","names":["events: UploadChunkEvent[]"],"sources":["../src/uploadChunks.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\nimport type { Client } from \"./client.js\";\nimport { streamChunker } from \"./streamChunker.js\";\n\nconst log = debug(\"ef:api:uploadChunk\");\n\ninterface UploadChunkOptions {\n url: string;\n chunkBuffer: Uint8Array;\n chunkNumber: number;\n fileSize: number;\n chunkSizeBytes?: number;\n}\n\n/**\n * @internal\n */\nexport interface IteratorWithPromise<T> extends AsyncGenerator
|
|
1
|
+
{"version":3,"file":"uploadChunks.js","names":["events: UploadChunkEvent[]"],"sources":["../src/uploadChunks.ts"],"sourcesContent":["import debug from \"debug\";\n\nimport { CHUNK_SIZE_BYTES } from \"./CHUNK_SIZE_BYTES.js\";\nimport type { Client } from \"./client.js\";\nimport { streamChunker } from \"./streamChunker.js\";\n\nconst log = debug(\"ef:api:uploadChunk\");\n\ninterface UploadChunkOptions {\n url: string;\n chunkBuffer: Uint8Array;\n chunkNumber: number;\n fileSize: number;\n chunkSizeBytes?: number;\n}\n\n/**\n * @internal\n */\nexport interface IteratorWithPromise<T> extends AsyncGenerator<T, void, unknown> {\n whenUploaded: () => Promise<T[]>;\n}\n\nexport const fakeCompleteUpload = (): IteratorWithPromise<UploadChunkEvent> => {\n const makeGenerator = async function* (): AsyncGenerator<UploadChunkEvent, void, unknown> {\n yield { type: \"progress\", progress: 1 };\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n return [{ type: \"progress\", progress: 1 }];\n };\n return generator;\n};\n\nconst uploadChunk = async (\n client: Client,\n {\n url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes = CHUNK_SIZE_BYTES,\n }: UploadChunkOptions,\n) => {\n const startByte = chunkNumber * chunkSizeBytes;\n const endByte = startByte + chunkBuffer.length - 1;\n\n log(`Uploading chunk ${chunkNumber} for ${url}`);\n const response = await client.authenticatedFetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Range\": `bytes=${startByte}-${endByte}/${fileSize}`,\n \"Content-Type\": \"application/octet-stream\",\n },\n body: chunkBuffer as BodyInit,\n });\n\n if (response.ok) {\n if (response.status === 201) {\n log(`File ${url} fully uploaded`);\n return { complete: true, body: await response.json() };\n }\n if (response.status === 202) {\n log(`File ${url} chunk ${chunkNumber} uploaded`);\n return { complete: false, body: await response.json() };\n }\n }\n\n throw new Error(\n `Failed to upload chunk ${chunkNumber} for ${url} ${response.status} ${response.statusText}`,\n );\n};\n\ninterface UploadChunksOptions {\n url: string;\n fileStream: ReadableStream;\n fileSize: number;\n maxSize: number;\n chunkSizeBytes?: number;\n}\n\nexport interface UploadChunkEvent {\n type: \"progress\";\n progress: number;\n}\n\nexport function uploadChunks(\n client: Client,\n { url, fileSize, fileStream, maxSize, chunkSizeBytes = CHUNK_SIZE_BYTES }: UploadChunksOptions,\n): IteratorWithPromise<UploadChunkEvent> {\n const makeGenerator = async function* (): AsyncGenerator<UploadChunkEvent, void, unknown> {\n if (fileSize > maxSize) {\n throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);\n }\n\n log(\"Checking upload status\", url);\n const uploadStatus = await client.authenticatedFetch(url);\n\n yield { type: \"progress\", progress: 0 };\n\n if (uploadStatus.status === 200) {\n log(\"Chunk already uploaded\");\n yield { type: \"progress\", progress: 1 };\n return;\n }\n\n let chunkNumber = 0;\n let complete = false;\n for await (const chunkBuffer of streamChunker(fileStream, chunkSizeBytes)) {\n log(`Uploading chunk ${chunkNumber}`);\n ({ complete } = await uploadChunk(client, {\n url: url,\n chunkBuffer,\n chunkNumber,\n fileSize,\n chunkSizeBytes,\n }));\n chunkNumber++;\n yield {\n type: \"progress\",\n progress: Math.min(1, chunkNumber / (fileSize / chunkSizeBytes)),\n };\n }\n if (!complete) {\n throw new Error(\"Did not complete upload\");\n }\n };\n\n const generator = makeGenerator() as IteratorWithPromise<UploadChunkEvent>;\n generator.whenUploaded = async () => {\n if (fileSize > maxSize) {\n throw new Error(`File size ${fileSize} bytes exceeds limit ${maxSize} bytes`);\n }\n const events: UploadChunkEvent[] = [];\n for await (const event of generator) {\n events.push(event);\n }\n return events;\n };\n return generator;\n}\n"],"mappings":";;;;;AAMA,MAAM,MAAM,MAAM,qBAAqB;AA6BvC,MAAM,cAAc,OAClB,QACA,EACE,KACA,aACA,aACA,UACA,iBAAiB,uBAEhB;CACH,MAAM,YAAY,cAAc;CAChC,MAAM,UAAU,YAAY,YAAY,SAAS;AAEjD,KAAI,mBAAmB,YAAY,OAAO,MAAM;CAChD,MAAM,WAAW,MAAM,OAAO,mBAAmB,KAAK;EACpD,QAAQ;EACR,SAAS;GACP,iBAAiB,SAAS,UAAU,GAAG,QAAQ,GAAG;GAClD,gBAAgB;GACjB;EACD,MAAM;EACP,CAAC;AAEF,KAAI,SAAS,IAAI;AACf,MAAI,SAAS,WAAW,KAAK;AAC3B,OAAI,QAAQ,IAAI,iBAAiB;AACjC,UAAO;IAAE,UAAU;IAAM,MAAM,MAAM,SAAS,MAAM;IAAE;;AAExD,MAAI,SAAS,WAAW,KAAK;AAC3B,OAAI,QAAQ,IAAI,SAAS,YAAY,WAAW;AAChD,UAAO;IAAE,UAAU;IAAO,MAAM,MAAM,SAAS,MAAM;IAAE;;;AAI3D,OAAM,IAAI,MACR,0BAA0B,YAAY,OAAO,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACjF;;AAgBH,SAAgB,aACd,QACA,EAAE,KAAK,UAAU,YAAY,SAAS,iBAAiB,oBAChB;CACvC,MAAM,gBAAgB,mBAAoE;AACxF,MAAI,WAAW,QACb,OAAM,IAAI,MAAM,aAAa,SAAS,uBAAuB,QAAQ,QAAQ;AAG/E,MAAI,0BAA0B,IAAI;EAClC,MAAM,eAAe,MAAM,OAAO,mBAAmB,IAAI;AAEzD,QAAM;GAAE,MAAM;GAAY,UAAU;GAAG;AAEvC,MAAI,aAAa,WAAW,KAAK;AAC/B,OAAI,yBAAyB;AAC7B,SAAM;IAAE,MAAM;IAAY,UAAU;IAAG;AACvC;;EAGF,IAAI,cAAc;EAClB,IAAI,WAAW;AACf,aAAW,MAAM,eAAe,cAAc,YAAY,eAAe,EAAE;AACzE,OAAI,mBAAmB,cAAc;AACrC,IAAC,CAAE,YAAa,MAAM,YAAY,QAAQ;IACnC;IACL;IACA;IACA;IACA;IACD,CAAC;AACF;AACA,SAAM;IACJ,MAAM;IACN,UAAU,KAAK,IAAI,GAAG,eAAe,WAAW,gBAAgB;IACjE;;AAEH,MAAI,CAAC,SACH,OAAM,IAAI,MAAM,0BAA0B;;CAI9C,MAAM,YAAY,eAAe;AACjC,WAAU,eAAe,YAAY;AACnC,MAAI,WAAW,QACb,OAAM,IAAI,MAAM,aAAa,SAAS,uBAAuB,QAAQ,QAAQ;EAE/E,MAAMA,SAA6B,EAAE;AACrC,aAAW,MAAM,SAAS,UACxB,QAAO,KAAK,MAAM;AAEpB,SAAO;;AAET,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertTypesMatch.cjs","names":[],"sources":["../../src/utils/assertTypesMatch.ts"],"sourcesContent":["// Type helper that will cause a compilation error\ntype Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
1
|
+
{"version":3,"file":"assertTypesMatch.cjs","names":[],"sources":["../../src/utils/assertTypesMatch.ts"],"sourcesContent":["// Type helper that will cause a compilation error\ntype Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n// Force error with const assertion\nexport const assertTypesMatch = <T, U>(value: Equals<T, U> extends true ? true : never) => value;\n"],"mappings":";;AAIA,MAAa,oBAA0B,UAAoD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertTypesMatch.js","names":[],"sources":["../../src/utils/assertTypesMatch.ts"],"sourcesContent":["// Type helper that will cause a compilation error\ntype Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
1
|
+
{"version":3,"file":"assertTypesMatch.js","names":[],"sources":["../../src/utils/assertTypesMatch.ts"],"sourcesContent":["// Type helper that will cause a compilation error\ntype Equals<X, Y> =\n (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\n// Force error with const assertion\nexport const assertTypesMatch = <T, U>(value: Equals<T, U> extends true ? true : never) => value;\n"],"mappings":";AAIA,MAAa,oBAA0B,UAAoD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReadableStreamFromReadable.cjs","names":["Stream","_error: any"],"sources":["../../src/utils/createReadableStreamFromReadable.ts"],"sourcesContent":["import { type Readable, Stream } from \"node:stream\";\n\nexport const createReadableStreamFromReadable = (\n source: Readable & { readableHighWaterMark?: number },\n) => {\n const pump = new StreamPump(source);\n const stream = new ReadableStream(pump, pump);\n return stream;\n};\n\nclass StreamPump {\n public highWaterMark: number;\n public accumalatedSize: number;\n private stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n };\n private controller?: ReadableStreamController<Uint8Array>;\n\n constructor(\n stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n },\n ) {\n this.highWaterMark =\n stream.readableHighWaterMark
|
|
1
|
+
{"version":3,"file":"createReadableStreamFromReadable.cjs","names":["Stream","_error: any"],"sources":["../../src/utils/createReadableStreamFromReadable.ts"],"sourcesContent":["import { type Readable, Stream } from \"node:stream\";\n\nexport const createReadableStreamFromReadable = (\n source: Readable & { readableHighWaterMark?: number },\n) => {\n const pump = new StreamPump(source);\n const stream = new ReadableStream(pump, pump);\n return stream;\n};\n\nclass StreamPump {\n public highWaterMark: number;\n public accumalatedSize: number;\n private stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n };\n private controller?: ReadableStreamController<Uint8Array>;\n\n constructor(\n stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n },\n ) {\n this.highWaterMark =\n stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;\n this.accumalatedSize = 0;\n this.stream = stream;\n this.enqueue = this.enqueue.bind(this);\n this.error = this.error.bind(this);\n this.close = this.close.bind(this);\n }\n\n size(chunk: Uint8Array) {\n return chunk?.byteLength || 0;\n }\n\n start(controller: ReadableStreamController<Uint8Array>) {\n this.controller = controller;\n this.stream.on(\"data\", this.enqueue);\n this.stream.once(\"error\", this.error);\n this.stream.once(\"end\", this.close);\n this.stream.once(\"close\", this.close);\n }\n\n pull() {\n this.resume();\n }\n\n cancel(reason?: Error) {\n if (this.stream.destroy) {\n this.stream.destroy(reason);\n }\n\n this.stream.off(\"data\", this.enqueue);\n this.stream.off(\"error\", this.error);\n this.stream.off(\"end\", this.close);\n this.stream.off(\"close\", this.close);\n }\n\n enqueue(chunk: ArrayBufferView<ArrayBuffer> & Uint8Array<ArrayBufferLike>) {\n if (this.controller) {\n try {\n // const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);\n\n const available = (this.controller.desiredSize || 0) - chunk.length;\n this.controller.enqueue(chunk);\n if (available <= 0) {\n this.pause();\n }\n } catch (_error: any) {\n this.controller.error(\n new Error(\n \"Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object\",\n ),\n );\n this.cancel();\n }\n }\n }\n\n pause() {\n if (this.stream.pause) {\n this.stream.pause();\n }\n }\n\n resume() {\n if (this.stream.readable && this.stream.resume) {\n this.stream.resume();\n }\n }\n\n close() {\n if (this.controller) {\n this.controller.close();\n delete this.controller;\n }\n }\n\n error(error: Error) {\n if (this.controller) {\n this.controller.error(error);\n delete this.controller;\n }\n }\n}\n"],"mappings":";;;;;AAEA,MAAa,oCACX,WACG;CACH,MAAM,OAAO,IAAI,WAAW,OAAO;AAEnC,QADe,IAAI,eAAe,MAAM,KAAK;;AAI/C,IAAM,aAAN,MAAiB;CAYf,YACE,QAOA;AACA,OAAK,gBACH,OAAO,yBAAyB,IAAIA,mBAAO,UAAU,CAAC;AACxD,OAAK,kBAAkB;AACvB,OAAK,SAAS;AACd,OAAK,UAAU,KAAK,QAAQ,KAAK,KAAK;AACtC,OAAK,QAAQ,KAAK,MAAM,KAAK,KAAK;AAClC,OAAK,QAAQ,KAAK,MAAM,KAAK,KAAK;;CAGpC,KAAK,OAAmB;AACtB,SAAO,OAAO,cAAc;;CAG9B,MAAM,YAAkD;AACtD,OAAK,aAAa;AAClB,OAAK,OAAO,GAAG,QAAQ,KAAK,QAAQ;AACpC,OAAK,OAAO,KAAK,SAAS,KAAK,MAAM;AACrC,OAAK,OAAO,KAAK,OAAO,KAAK,MAAM;AACnC,OAAK,OAAO,KAAK,SAAS,KAAK,MAAM;;CAGvC,OAAO;AACL,OAAK,QAAQ;;CAGf,OAAO,QAAgB;AACrB,MAAI,KAAK,OAAO,QACd,MAAK,OAAO,QAAQ,OAAO;AAG7B,OAAK,OAAO,IAAI,QAAQ,KAAK,QAAQ;AACrC,OAAK,OAAO,IAAI,SAAS,KAAK,MAAM;AACpC,OAAK,OAAO,IAAI,OAAO,KAAK,MAAM;AAClC,OAAK,OAAO,IAAI,SAAS,KAAK,MAAM;;CAGtC,QAAQ,OAAmE;AACzE,MAAI,KAAK,WACP,KAAI;GAGF,MAAM,aAAa,KAAK,WAAW,eAAe,KAAK,MAAM;AAC7D,QAAK,WAAW,QAAQ,MAAM;AAC9B,OAAI,aAAa,EACf,MAAK,OAAO;WAEPC,QAAa;AACpB,QAAK,WAAW,sBACd,IAAI,MACF,gIACD,CACF;AACD,QAAK,QAAQ;;;CAKnB,QAAQ;AACN,MAAI,KAAK,OAAO,MACd,MAAK,OAAO,OAAO;;CAIvB,SAAS;AACP,MAAI,KAAK,OAAO,YAAY,KAAK,OAAO,OACtC,MAAK,OAAO,QAAQ;;CAIxB,QAAQ;AACN,MAAI,KAAK,YAAY;AACnB,QAAK,WAAW,OAAO;AACvB,UAAO,KAAK;;;CAIhB,MAAM,OAAc;AAClB,MAAI,KAAK,YAAY;AACnB,QAAK,WAAW,MAAM,MAAM;AAC5B,UAAO,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReadableStreamFromReadable.js","names":["_error: any"],"sources":["../../src/utils/createReadableStreamFromReadable.ts"],"sourcesContent":["import { type Readable, Stream } from \"node:stream\";\n\nexport const createReadableStreamFromReadable = (\n source: Readable & { readableHighWaterMark?: number },\n) => {\n const pump = new StreamPump(source);\n const stream = new ReadableStream(pump, pump);\n return stream;\n};\n\nclass StreamPump {\n public highWaterMark: number;\n public accumalatedSize: number;\n private stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n };\n private controller?: ReadableStreamController<Uint8Array>;\n\n constructor(\n stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n },\n ) {\n this.highWaterMark =\n stream.readableHighWaterMark
|
|
1
|
+
{"version":3,"file":"createReadableStreamFromReadable.js","names":["_error: any"],"sources":["../../src/utils/createReadableStreamFromReadable.ts"],"sourcesContent":["import { type Readable, Stream } from \"node:stream\";\n\nexport const createReadableStreamFromReadable = (\n source: Readable & { readableHighWaterMark?: number },\n) => {\n const pump = new StreamPump(source);\n const stream = new ReadableStream(pump, pump);\n return stream;\n};\n\nclass StreamPump {\n public highWaterMark: number;\n public accumalatedSize: number;\n private stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n };\n private controller?: ReadableStreamController<Uint8Array>;\n\n constructor(\n stream: Stream & {\n readableHighWaterMark?: number;\n readable?: boolean;\n resume?: () => void;\n pause?: () => void;\n destroy?: (error?: Error) => void;\n },\n ) {\n this.highWaterMark =\n stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;\n this.accumalatedSize = 0;\n this.stream = stream;\n this.enqueue = this.enqueue.bind(this);\n this.error = this.error.bind(this);\n this.close = this.close.bind(this);\n }\n\n size(chunk: Uint8Array) {\n return chunk?.byteLength || 0;\n }\n\n start(controller: ReadableStreamController<Uint8Array>) {\n this.controller = controller;\n this.stream.on(\"data\", this.enqueue);\n this.stream.once(\"error\", this.error);\n this.stream.once(\"end\", this.close);\n this.stream.once(\"close\", this.close);\n }\n\n pull() {\n this.resume();\n }\n\n cancel(reason?: Error) {\n if (this.stream.destroy) {\n this.stream.destroy(reason);\n }\n\n this.stream.off(\"data\", this.enqueue);\n this.stream.off(\"error\", this.error);\n this.stream.off(\"end\", this.close);\n this.stream.off(\"close\", this.close);\n }\n\n enqueue(chunk: ArrayBufferView<ArrayBuffer> & Uint8Array<ArrayBufferLike>) {\n if (this.controller) {\n try {\n // const bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);\n\n const available = (this.controller.desiredSize || 0) - chunk.length;\n this.controller.enqueue(chunk);\n if (available <= 0) {\n this.pause();\n }\n } catch (_error: any) {\n this.controller.error(\n new Error(\n \"Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object\",\n ),\n );\n this.cancel();\n }\n }\n }\n\n pause() {\n if (this.stream.pause) {\n this.stream.pause();\n }\n }\n\n resume() {\n if (this.stream.readable && this.stream.resume) {\n this.stream.resume();\n }\n }\n\n close() {\n if (this.controller) {\n this.controller.close();\n delete this.controller;\n }\n }\n\n error(error: Error) {\n if (this.controller) {\n this.controller.error(error);\n delete this.controller;\n }\n }\n}\n"],"mappings":";;;AAEA,MAAa,oCACX,WACG;CACH,MAAM,OAAO,IAAI,WAAW,OAAO;AAEnC,QADe,IAAI,eAAe,MAAM,KAAK;;AAI/C,IAAM,aAAN,MAAiB;CAYf,YACE,QAOA;AACA,OAAK,gBACH,OAAO,yBAAyB,IAAI,OAAO,UAAU,CAAC;AACxD,OAAK,kBAAkB;AACvB,OAAK,SAAS;AACd,OAAK,UAAU,KAAK,QAAQ,KAAK,KAAK;AACtC,OAAK,QAAQ,KAAK,MAAM,KAAK,KAAK;AAClC,OAAK,QAAQ,KAAK,MAAM,KAAK,KAAK;;CAGpC,KAAK,OAAmB;AACtB,SAAO,OAAO,cAAc;;CAG9B,MAAM,YAAkD;AACtD,OAAK,aAAa;AAClB,OAAK,OAAO,GAAG,QAAQ,KAAK,QAAQ;AACpC,OAAK,OAAO,KAAK,SAAS,KAAK,MAAM;AACrC,OAAK,OAAO,KAAK,OAAO,KAAK,MAAM;AACnC,OAAK,OAAO,KAAK,SAAS,KAAK,MAAM;;CAGvC,OAAO;AACL,OAAK,QAAQ;;CAGf,OAAO,QAAgB;AACrB,MAAI,KAAK,OAAO,QACd,MAAK,OAAO,QAAQ,OAAO;AAG7B,OAAK,OAAO,IAAI,QAAQ,KAAK,QAAQ;AACrC,OAAK,OAAO,IAAI,SAAS,KAAK,MAAM;AACpC,OAAK,OAAO,IAAI,OAAO,KAAK,MAAM;AAClC,OAAK,OAAO,IAAI,SAAS,KAAK,MAAM;;CAGtC,QAAQ,OAAmE;AACzE,MAAI,KAAK,WACP,KAAI;GAGF,MAAM,aAAa,KAAK,WAAW,eAAe,KAAK,MAAM;AAC7D,QAAK,WAAW,QAAQ,MAAM;AAC9B,OAAI,aAAa,EACf,MAAK,OA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