@editframe/api 0.30.2-beta.0 → 0.31.0-beta.1
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.js.map +1 -1
- package/dist/node.js.map +1 -1
- package/dist/resources/image-file.js.map +1 -1
- package/dist/resources/renders.bundle.d.ts +1 -1
- package/dist/uploadChunks.js.map +1 -1
- package/dist/utils/assertTypesMatch.js.map +1 -1
- package/dist/utils/createReadableStreamFromReadable.d.ts +1 -1
- package/dist/utils/createReadableStreamFromReadable.js.map +1 -1
- package/package.json +3 -3
- package/types.json +1 -1
|
@@ -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 {\n CompleteEvent,\n ProgressEvent,\n StreamEventSource,\n} 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
|
|
1
|
+
{"version":3,"file":"ProgressIterator.js","names":["resolve!: (value: T | PromiseLike<T>) => void","reject!: (reason?: any) => void"],"sources":["../src/ProgressIterator.ts"],"sourcesContent":["import type {\n CompleteEvent,\n ProgressEvent,\n StreamEventSource,\n} 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<\n T extends CompleteEvent | any,\n> 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: (\n event: \"progress\",\n callback: (event: ProgressEvent) => void,\n ) => 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<\n ProgressEvent | CompleteEvent\n> {\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<\n CompleteEvent | ProgressEvent\n> {\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":";AAMA,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,MAE8B;CAO5B,YAAY,aAAgC;eALrB,EAAE;eACP;oBACK;uBACG,sBAA4B;AAGpD,OAAK,cAAc;;CAGrB,MAAM,eAAe;AACnB,aAAW,MAAM,KAAK;AAEtB,SAAO,KAAK;;CAQd,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;AACF,UAAO,CAAC,KAAK,cAAc,KAAK,cAAc,EAC5C,KAAI,KAAK,gBAAgB,EACvB,OAAM,KAAK,cAAc;QACpB;IACL,MAAM,OAAO,KAAK,MAAM,KAAK;AAC7B,QAAI,CAAC,KACH,OAAM,IAAI,MAAM,qBAAqB;AAEvC,SAAK;AACL,UAAM;;YAGF;AACR,QAAK,YAAY,OAAO;;;;AAM9B,IAAa,mBAAb,cAAsC,kBAEpC;CACA,YAAY,aAAgC;AAC1C,QAAM,YAAY;AAClB,OAAK,qBAAqB;;CAG5B,AAAQ,sBAAsB;AAC5B,OAAK,YAAY,GAAG,aAAa,UAAU;AACzC,QAAK,KAAK,MAAM;IAChB;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;;;AAKN,IAAa,qBAAb,cAAwC,kBAEtC;CAIA,YAAY,aAAgC;AAC1C,QAAM,YAAY;mBAJA;yBACM;AAIxB,OAAK,qBAAqB;;CAG5B,AAAQ,sBAAsB;AAC5B,OAAK,YAAY,GAAG,SAAS,UAAU;AACrC,QAAK,YAAY,MAAM,KAAK;AAC5B,QAAK,KAAK;IACR,MAAM;IACN,MAAM,EACJ,UAAU,GACX;IACF,CAAC;IACF;AAEF,OAAK,YAAY,GAAG,eAAe,UAAU;AAC3C,QAAK,mBAAmB,OAAO,MAAM,KAAK,MAAM;AAEhD,QAAK,KAAK;IACR,MAAM;IACN,MAAM,EACJ,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"}
|
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 } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport mime from \"mime\";\n\nimport type { Client } from \"./client.js\";\nimport {\n CreateImageFilePayload,\n createImageFile,\n} from \"./resources/image-file.js\";\nimport {\n createUnprocessedFile,\n type UnprocessedFileUploadDetails,\n uploadUnprocessedReadableStream,\n} from \"./resources/unprocessed-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 = mime.getType(path);\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 (\n client: Client,\n path: string,\n) => {\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 }
|
|
1
|
+
{"version":3,"file":"node.js","names":["path","createReadableStreamFromReadable"],"sources":["../src/node.ts"],"sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { basename } from \"node:path\";\nimport { md5FilePath } from \"@editframe/assets\";\nimport mime from \"mime\";\n\nimport type { Client } from \"./client.js\";\nimport {\n CreateImageFilePayload,\n createImageFile,\n} from \"./resources/image-file.js\";\nimport {\n createUnprocessedFile,\n type UnprocessedFileUploadDetails,\n uploadUnprocessedReadableStream,\n} from \"./resources/unprocessed-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 = mime.getType(path);\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 (\n client: Client,\n path: string,\n) => {\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\nexport * from \"./index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAa,0BAA0B,OAAO,QAAgB,WAAiB;CAG7E,MAAM,aAFW,MAAM,KAAKA,OAAK,EAEN;CAE3B,MAAM,MAAM,MAAM,YAAYA,OAAK;CAEnC,MAAM,YAAY,KAAK,QAAQA,OAAK;AAEpC,QAAO,gBAAgB,QAAQ,EAC7B,GAAG,uBAAuB,MAAM;EAC9B;EACA,QAAQ;EACR,OAAO;EACP;EACA,UAAU,SAASA,OAAK;EACxB;EACD,CAAC,EACH,CAAC;;AAGJ,MAAa,gCAAgC,OAC3C,QACA,WACG;CAGH,MAAM,aAFW,MAAM,KAAKA,OAAK,EAEN;AAI3B,QAAO,sBAAsB,QAAQ;EACnC,KAHU,MAAM,YAAYA,OAAK;EAIjC,UAAU,SAASA,OAAK;EACxB;EACD,CAAC;;AAGJ,MAAa,wBAAwB,OACnC,QACA,eACA,WACG;CACH,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,aAAa,iBAAiBA,OAAK;CAEzC,MAAM,EAAE,yEACN,MAAM,OAAO;AAEf,QAAO,gCACL,QACA,eACAC,mCAAiC,WAAW,CAC7C"}
|
|
@@ -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:\n \"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\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\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\nexport interface GetImageFileMetadataResult
|
|
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:\n \"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\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\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\nexport interface GetImageFileMetadataResult extends LookupImageFileByMd5Result {}\n\nexport const createImageFile = async (\n client: Client,\n payload: CreateImageFilePayload,\n) => {\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(\n `Failed to create file ${response.status} ${response.statusText}`,\n );\n};\n\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\nexport const getImageFileMetadata = async (\n client: Client,\n id: string,\n): Promise<GetImageFileMetadataResult | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/image_files/${id}.json`,\n {\n method: \"GET\",\n },\n );\n\n if (response.ok) {\n return (await response.json()) as LookupImageFileByMd5Result;\n }\n\n return null;\n};\n\nexport const lookupImageFileByMd5 = async (\n client: Client,\n md5: string,\n): Promise<LookupImageFileByMd5Result | null> => {\n const response = await client.authenticatedFetch(\n `/api/v1/image_files/md5/${md5}`,\n {\n method: \"GET\",\n },\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(\n `Failed to lookup image by md5 ${md5} ${response.status} ${response.statusText}`,\n );\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,SACE;EACF,MAAM,CAAC,YAAY;EACpB,CAAC;EAEJ;AAoDJ,MAAa,kBAAkB,OAC7B,QACA,YACG;AACH,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,MACR,yBAAyB,SAAS,OAAO,GAAG,SAAS,aACtD;;AAGH,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;;AAGJ,MAAa,uBAAuB,OAClC,QACA,OAC+C;CAC/C,MAAM,WAAW,MAAM,OAAO,mBAC5B,uBAAuB,GAAG,QAC1B,EACE,QAAQ,OACT,CACF;AAED,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,QAAO;;AAGT,MAAa,uBAAuB,OAClC,QACA,QAC+C;CAC/C,MAAM,WAAW,MAAM,OAAO,mBAC5B,2BAA2B,OAC3B,EACE,QAAQ,OACT,CACF;AACD,KAAI,qBAAqB,SAAS;AAElC,KAAI,SAAS,GACX,QAAQ,MAAM,SAAS,MAAM;AAG/B,KAAI,SAAS,WAAW,IACtB,QAAO;AAGT,OAAM,IAAI,MACR,iCAAiC,IAAI,GAAG,SAAS,OAAO,GAAG,SAAS,aACrE"}
|
|
@@ -3,7 +3,7 @@ interface BundlerOptions {
|
|
|
3
3
|
root: string;
|
|
4
4
|
renderData: any;
|
|
5
5
|
}
|
|
6
|
-
declare const bundleRender: (options: BundlerOptions) => Promise<ReadableStream<Uint8Array
|
|
6
|
+
declare const bundleRender: (options: BundlerOptions) => Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { bundleRender };
|
|
9
9
|
//# sourceMappingURL=renders.bundle.d.ts.map
|
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
|
|
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<\n T,\n void,\n unknown\n> {\n whenUploaded: () => Promise<T[]>;\n}\n\nexport const fakeCompleteUpload = (): IteratorWithPromise<UploadChunkEvent> => {\n const makeGenerator = async function* (): AsyncGenerator<\n UploadChunkEvent,\n void,\n unknown\n > {\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 {\n url,\n fileSize,\n fileStream,\n maxSize,\n chunkSizeBytes = CHUNK_SIZE_BYTES,\n }: UploadChunksOptions,\n): IteratorWithPromise<UploadChunkEvent> {\n const makeGenerator = async function* (): AsyncGenerator<\n UploadChunkEvent,\n void,\n unknown\n > {\n if (fileSize > maxSize) {\n throw new Error(\n `File size ${fileSize} bytes exceeds limit ${maxSize} bytes`,\n );\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(\n `File size ${fileSize} bytes exceeds limit ${maxSize} bytes`,\n );\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;AAqCvC,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,EACE,KACA,UACA,YACA,SACA,iBAAiB,oBAEoB;CACvC,MAAM,gBAAgB,mBAIpB;AACA,MAAI,WAAW,QACb,OAAM,IAAI,MACR,aAAa,SAAS,uBAAuB,QAAQ,QACtD;AAGH,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,MACR,aAAa,SAAS,uBAAuB,QAAQ,QACtD;EAEH,MAAMA,SAA6B,EAAE;AACrC,aAAW,MAAM,SAAS,UACxB,QAAO,KAAK,MAAM;AAEpB,SAAO;;AAET,QAAO"}
|
|
@@ -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>
|
|
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\n ? true\n : false;\n// Force error with const assertion\nexport const assertTypesMatch = <T, U>(\n value: Equals<T, U> extends true ? true : never,\n) => value;\n"],"mappings":";AAMA,MAAa,oBACX,UACG"}
|
|
@@ -3,7 +3,7 @@ import { Readable } from "node:stream";
|
|
|
3
3
|
//#region src/utils/createReadableStreamFromReadable.d.ts
|
|
4
4
|
declare const createReadableStreamFromReadable: (source: Readable & {
|
|
5
5
|
readableHighWaterMark?: number;
|
|
6
|
-
}) => ReadableStream<Uint8Array
|
|
6
|
+
}) => ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { createReadableStreamFromReadable };
|
|
9
9
|
//# sourceMappingURL=createReadableStreamFromReadable.d.ts.map
|
|
@@ -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 ||\n 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:
|
|
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 ||\n 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,yBACP,IAAI,OAAO,UAAU,CAAC;AACxB,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;WAEPA,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"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0-beta.1",
|
|
4
4
|
"description": "API functions for EditFrame",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
8
8
|
"build": "tsdown",
|
|
9
9
|
"build:watch": "tsdown --watch",
|
|
10
|
-
"typedoc": "typedoc --json ./types.json --plugin typedoc-plugin-zod --excludeExternals ./src && jq -c . ./types.json > ./types.tmp.json && mv ./types.tmp.json ./types.json"
|
|
10
|
+
"typedoc": "(typedoc --json ./types.json --plugin typedoc-plugin-zod --excludeExternals ./src || true) && ([ -f ./types.json ] && jq -c . ./types.json > ./types.tmp.json && mv ./types.tmp.json ./types.json || true)"
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "UNLICENSED",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"typescript": "^5.5.4"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@editframe/assets": "0.
|
|
22
|
+
"@editframe/assets": "0.31.0-beta.1",
|
|
23
23
|
"@vitejs/plugin-react": "^4.3.4",
|
|
24
24
|
"debug": "^4.3.5",
|
|
25
25
|
"eventsource-parser": "^3.0.0",
|