webuix 0.0.2 → 0.0.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/build.ts +28 -13
- package/bun.lockb +0 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.esm.js +1 -0
- package/dist/wrapInputStream.cjs.js +1 -0
- package/dist/wrapInputStream.esm.js +1 -0
- package/dist/wrapper/index.d.ts +24 -0
- package/dist/wrapper/wrapInputStream.d.ts +23 -0
- package/package.json +4 -2
- package/dist/index.js +0 -2
- package/dist/wrappers/index.js +0 -135
package/build.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import dts from "bun-plugin-dts";
|
|
1
2
|
import { writeFileSync, readFileSync } from "fs";
|
|
2
3
|
import { execSync } from "child_process";
|
|
4
|
+
import type { BuildConfig } from "bun";
|
|
3
5
|
|
|
4
6
|
// Get Git commit count
|
|
5
|
-
const count = parseInt(
|
|
7
|
+
const count = parseInt(
|
|
8
|
+
execSync("git rev-list --count HEAD").toString().trim(),
|
|
9
|
+
10
|
|
10
|
+
);
|
|
6
11
|
|
|
7
12
|
// Compute MAJOR.MINOR.PATCH
|
|
8
13
|
const MAJOR = Math.floor(count / 10000);
|
|
@@ -16,15 +21,25 @@ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
|
16
21
|
pkg.version = version;
|
|
17
22
|
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const minify = true;
|
|
25
|
+
const formats: Array<BuildConfig["format"]> = ["cjs", "esm"];
|
|
26
|
+
|
|
27
|
+
for (const format of formats) {
|
|
28
|
+
Bun.build({
|
|
29
|
+
entrypoints: ["./src/index.ts"],
|
|
30
|
+
outdir: `./dist/`,
|
|
31
|
+
minify: minify,
|
|
32
|
+
target: "browser",
|
|
33
|
+
format: format,
|
|
34
|
+
plugins: [dts()],
|
|
35
|
+
splitting: true,
|
|
36
|
+
naming: {
|
|
37
|
+
entry: `[name].${format}.js`,
|
|
38
|
+
chunk: "[name]-[hash].js",
|
|
39
|
+
asset: "[name]-[hash][ext]",
|
|
40
|
+
},
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
console.error(err);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
});
|
|
45
|
+
}
|
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{defineProperty:d,getOwnPropertyNames:W,getOwnPropertyDescriptor:X}=Object,h=Object.prototype.hasOwnProperty;var v=new WeakMap,w=(r)=>{var e=v.get(r),t;if(e)return e;if(e=d({},"__esModule",{value:!0}),r&&typeof r==="object"||typeof r==="function")W(r).map((n)=>!h.call(e,n)&&d(e,n,{get:()=>r[n],enumerable:!(t=X(r,n))||t.enumerable}));return v.set(r,e),e};var b=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0,configurable:!0,set:(n)=>e[t]=()=>n})};var S={};b(S,{wrapToReadableStream:()=>c,wrapInputStream:()=>f,WXEvent:()=>m,CustomWXEvent:()=>o});module.exports=w(S);var E={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function c(r,e={}){let t={...E,...e};return new Promise((n,a)=>{let i;try{if(i=r,!i)throw new Error("Failed to open file input stream")}catch(s){a(s);return}let l=()=>{try{i?.close()}catch(s){console.error("Error during abort cleanup:",s)}a(new DOMException("The operation was aborted.","AbortError"))};if(t.signal){if(t.signal.aborted){l();return}t.signal.addEventListener("abort",l)}let y=new ReadableStream({async pull(s){try{let p=g(i,t.chunkSize);if(!p){s.close(),u();return}s.enqueue(p)}catch(p){u(),s.error(p),a(new Error(`Error reading file chunk: ${p}`))}},cancel(s){console.warn("Stream canceled:",s),u()}});function u(){try{if(t.signal)t.signal.removeEventListener("abort",l);i?.close()}catch(s){console.error(`Error during cleanup: ${s}`)}}n(y)})}function g(r,e){try{let t=e?r.readChunk(e):r.read();if(typeof t==="number")return new Uint8Array([t]);else if(typeof t==="string"){let n=JSON.parse(t);return n&&Array.isArray(n)&&n.length>0?new Uint8Array(n):null}return null}catch(t){throw new Error("Error reading chunk data: "+t)}}async function f(r,e={}){let t={...E,...e};try{let n=await c(r,t);return new Response(n,t)}catch(n){throw new Error(`wrapInputStream failed: ${n}`)}}class o extends CustomEvent{_wxOrigin;get wxOrigin(){return this._wxOrigin}set wxOrigin(r){this._wxOrigin=r}constructor(r,e){super(r,{detail:e,bubbles:!0,cancelable:!0,composed:!0})}}class m{static _initialized=!1;static _handlers=new WeakMap;static _eventTypes={WX_ON_BACK:"back",WX_ON_RESUME:"resume",WX_ON_PAUSE:"pause"};static get eventTypes(){return this._eventTypes}static initialize(){if(this._initialized)return;this._initialized=!0,window.addEventListener("message",(r)=>{try{if(typeof r.data!=="string")return;let e=JSON.parse(r.data);if(!e?.type)return;let t=this._eventTypes[e.type]??e.type;this._dispatch(window,t,e)}catch(e){console.error("[WXEvent] Message error:",e)}})}static _dispatch(r,e,t){let n=new o(e,t);n.wxOrigin="system",r.dispatchEvent(n)}static on(r,e,t){if(!this._initialized)this.initialize();let n=(i)=>{if(!(i instanceof o)){console.warn("[WXEvent] Event is not a CustomWXEvent:",i);return}if(i.wxOrigin==="system"){if(typeof t==="function")t(i);else if(t&&typeof t.handleEvent==="function")t.handleEvent(i)}};if(!this._handlers.has(r))this._handlers.set(r,new Map);let a=this._handlers.get(r);if(!a.has(e))a.set(e,new Set);return a.get(e).add({handler:t,wrapper:n}),r.addEventListener(e,n),()=>this.off(r,e,t)}static off(r,e,t){let n=this._handlers.get(r);if(!n?.has(e))return;for(let a of n.get(e))if(a.handler===t){r.removeEventListener(e,a.wrapper),n.get(e).delete(a);break}}}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a private interface which is not accessible in the window object.
|
|
5
|
+
* It is used to define the structure of a file input stream.
|
|
6
|
+
*/
|
|
7
|
+
export interface FileInputInterfaceStream {
|
|
8
|
+
read(): number;
|
|
9
|
+
/**
|
|
10
|
+
* This method needs to be parsed with `JSON.parse(...)`
|
|
11
|
+
* @param chinkSize The size of the chunk to read
|
|
12
|
+
* @returns The chunk data as a string
|
|
13
|
+
*/
|
|
14
|
+
readChunk(chinkSize: number): string;
|
|
15
|
+
close(): void;
|
|
16
|
+
skip(n: number): number;
|
|
17
|
+
}
|
|
18
|
+
export interface ReadableStreamInit extends RequestInit {
|
|
19
|
+
chunkSize?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function wrapToReadableStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<ReadableStream<Uint8Array>>;
|
|
22
|
+
export declare function wrapInputStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<Response>;
|
|
23
|
+
export declare class CustomWXEvent extends CustomEvent<WXEventDetail> {
|
|
24
|
+
private _wxOrigin?;
|
|
25
|
+
get wxOrigin(): string | undefined;
|
|
26
|
+
set wxOrigin(value: string | undefined);
|
|
27
|
+
constructor(type: WXEventType, detail?: WXEventDetail);
|
|
28
|
+
}
|
|
29
|
+
export type WXEventNativeType = "WX_ON_BACK" | "WX_ON_RESUME" | "WX_ON_PAUSE";
|
|
30
|
+
export type WXEventType = "back" | "resume" | "pause";
|
|
31
|
+
export type WXEventDetail = {
|
|
32
|
+
type: WXEventNativeType;
|
|
33
|
+
};
|
|
34
|
+
export interface WXEventListener extends EventListener {
|
|
35
|
+
(evt: CustomWXEvent): void;
|
|
36
|
+
}
|
|
37
|
+
export interface WXEventListenerObject extends EventListenerObject {
|
|
38
|
+
handleEvent(object: CustomWXEvent): void;
|
|
39
|
+
}
|
|
40
|
+
export type WXEventListenerOrWXEventListenerObject = WXEventListener | WXEventListenerObject;
|
|
41
|
+
export declare class WXEvent {
|
|
42
|
+
private static _initialized;
|
|
43
|
+
private static _handlers;
|
|
44
|
+
private static _eventTypes;
|
|
45
|
+
static get eventTypes(): Record<WXEventNativeType, WXEventType>;
|
|
46
|
+
static initialize(): void;
|
|
47
|
+
private static _dispatch;
|
|
48
|
+
static on(element: Window | Element, type: WXEventType, handler: WXEventListenerOrWXEventListenerObject): () => void;
|
|
49
|
+
static off(element: Window | Element, type: WXEventType, handler: WXEventListenerOrWXEventListenerObject): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function d(r,t={}){let e={...u,...t};return new Promise((n,a)=>{let i;try{if(i=r,!i)throw new Error("Failed to open file input stream")}catch(s){a(s);return}let c=()=>{try{i?.close()}catch(s){console.error("Error during abort cleanup:",s)}a(new DOMException("The operation was aborted.","AbortError"))};if(e.signal){if(e.signal.aborted){c();return}e.signal.addEventListener("abort",c)}let m=new ReadableStream({async pull(s){try{let o=v(i,e.chunkSize);if(!o){s.close(),l();return}s.enqueue(o)}catch(o){l(),s.error(o),a(new Error(`Error reading file chunk: ${o}`))}},cancel(s){console.warn("Stream canceled:",s),l()}});function l(){try{if(e.signal)e.signal.removeEventListener("abort",c);i?.close()}catch(s){console.error(`Error during cleanup: ${s}`)}}n(m)})}function v(r,t){try{let e=t?r.readChunk(t):r.read();if(typeof e==="number")return new Uint8Array([e]);else if(typeof e==="string"){let n=JSON.parse(e);return n&&Array.isArray(n)&&n.length>0?new Uint8Array(n):null}return null}catch(e){throw new Error("Error reading chunk data: "+e)}}async function f(r,t={}){let e={...u,...t};try{let n=await d(r,e);return new Response(n,e)}catch(n){throw new Error(`wrapInputStream failed: ${n}`)}}class p extends CustomEvent{_wxOrigin;get wxOrigin(){return this._wxOrigin}set wxOrigin(r){this._wxOrigin=r}constructor(r,t){super(r,{detail:t,bubbles:!0,cancelable:!0,composed:!0})}}class E{static _initialized=!1;static _handlers=new WeakMap;static _eventTypes={WX_ON_BACK:"back",WX_ON_RESUME:"resume",WX_ON_PAUSE:"pause"};static get eventTypes(){return this._eventTypes}static initialize(){if(this._initialized)return;this._initialized=!0,window.addEventListener("message",(r)=>{try{if(typeof r.data!=="string")return;let t=JSON.parse(r.data);if(!t?.type)return;let e=this._eventTypes[t.type]??t.type;this._dispatch(window,e,t)}catch(t){console.error("[WXEvent] Message error:",t)}})}static _dispatch(r,t,e){let n=new p(t,e);n.wxOrigin="system",r.dispatchEvent(n)}static on(r,t,e){if(!this._initialized)this.initialize();let n=(i)=>{if(!(i instanceof p)){console.warn("[WXEvent] Event is not a CustomWXEvent:",i);return}if(i.wxOrigin==="system"){if(typeof e==="function")e(i);else if(e&&typeof e.handleEvent==="function")e.handleEvent(i)}};if(!this._handlers.has(r))this._handlers.set(r,new Map);let a=this._handlers.get(r);if(!a.has(t))a.set(t,new Set);return a.get(t).add({handler:e,wrapper:n}),r.addEventListener(t,n),()=>this.off(r,t,e)}static off(r,t,e){let n=this._handlers.get(r);if(!n?.has(t))return;for(let a of n.get(t))if(a.handler===e){r.removeEventListener(t,a.wrapper),n.get(t).delete(a);break}}}export{d as wrapToReadableStream,f as wrapInputStream,E as WXEvent,p as CustomWXEvent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var{defineProperty:s,getOwnPropertyNames:f,getOwnPropertyDescriptor:S}=Object,b=Object.prototype.hasOwnProperty;var p=new WeakMap,y=(t)=>{var r=p.get(t),e;if(r)return r;if(r=s({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")f(t).map((n)=>!b.call(r,n)&&s(r,n,{get:()=>t[n],enumerable:!(e=S(t,n))||e.enumerable}));return p.set(t,r),r};var h=(t,r)=>{for(var e in r)s(t,e,{get:r[e],enumerable:!0,configurable:!0,set:(n)=>r[e]=()=>n})};var R={};h(R,{wrapInputStream:()=>g});module.exports=y(R);var m={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function d(t,r={}){let e={...m,...r};return new Promise((n,c)=>{let o;try{if(o=t,!o)throw new Error("Failed to open file input stream")}catch(a){c(a);return}let l=()=>{try{o?.close()}catch(a){console.error("Error during abort cleanup:",a)}c(new DOMException("The operation was aborted.","AbortError"))};if(e.signal){if(e.signal.aborted){l();return}e.signal.addEventListener("abort",l)}let I=new ReadableStream({async pull(a){try{let i=w(o,e.chunkSize);if(!i){a.close(),u();return}a.enqueue(i)}catch(i){u(),a.error(i),c(new Error(`Error reading file chunk: ${i}`))}},cancel(a){console.warn("Stream canceled:",a),u()}});function u(){try{if(e.signal)e.signal.removeEventListener("abort",l);o?.close()}catch(a){console.error(`Error during cleanup: ${a}`)}}n(I)})}function w(t,r){try{let e=r?t.readChunk(r):t.read();if(typeof e==="number")return new Uint8Array([e]);else if(typeof e==="string"){let n=JSON.parse(e);return n&&Array.isArray(n)&&n.length>0?new Uint8Array(n):null}return null}catch(e){throw new Error("Error reading chunk data: "+e)}}async function g(t,r={}){let e={...m,...r};try{let n=await d(t,e);return new Response(n,e)}catch(n){throw new Error(`wrapInputStream failed: ${n}`)}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var s={chunkSize:1048576,headers:{"Content-Type":"application/octet-stream"}};async function m(n,a={}){let e={...s,...a};return new Promise((t,c)=>{let o;try{if(o=n,!o)throw new Error("Failed to open file input stream")}catch(r){c(r);return}let l=()=>{try{o?.close()}catch(r){console.error("Error during abort cleanup:",r)}c(new DOMException("The operation was aborted.","AbortError"))};if(e.signal){if(e.signal.aborted){l();return}e.signal.addEventListener("abort",l)}let p=new ReadableStream({async pull(r){try{let i=d(o,e.chunkSize);if(!i){r.close(),u();return}r.enqueue(i)}catch(i){u(),r.error(i),c(new Error(`Error reading file chunk: ${i}`))}},cancel(r){console.warn("Stream canceled:",r),u()}});function u(){try{if(e.signal)e.signal.removeEventListener("abort",l);o?.close()}catch(r){console.error(`Error during cleanup: ${r}`)}}t(p)})}function d(n,a){try{let e=a?n.readChunk(a):n.read();if(typeof e==="number")return new Uint8Array([e]);else if(typeof e==="string"){let t=JSON.parse(e);return t&&Array.isArray(t)&&t.length>0?new Uint8Array(t):null}return null}catch(e){throw new Error("Error reading chunk data: "+e)}}async function S(n,a={}){let e={...s,...a};try{let t=await m(n,e);return new Response(t,e)}catch(t){throw new Error(`wrapInputStream failed: ${t}`)}}export{S as wrapInputStream};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a private interface which is not accessible in the window object.
|
|
5
|
+
* It is used to define the structure of a file input stream.
|
|
6
|
+
*/
|
|
7
|
+
export interface FileInputInterfaceStream {
|
|
8
|
+
read(): number;
|
|
9
|
+
/**
|
|
10
|
+
* This method needs to be parsed with `JSON.parse(...)`
|
|
11
|
+
* @param chinkSize The size of the chunk to read
|
|
12
|
+
* @returns The chunk data as a string
|
|
13
|
+
*/
|
|
14
|
+
readChunk(chinkSize: number): string;
|
|
15
|
+
close(): void;
|
|
16
|
+
skip(n: number): number;
|
|
17
|
+
}
|
|
18
|
+
export interface ReadableStreamInit extends RequestInit {
|
|
19
|
+
chunkSize?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function wrapToReadableStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<ReadableStream<Uint8Array>>;
|
|
22
|
+
export declare function wrapInputStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<Response>;
|
|
23
|
+
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a private interface which is not accessible in the window object.
|
|
5
|
+
* It is used to define the structure of a file input stream.
|
|
6
|
+
*/
|
|
7
|
+
export interface FileInputInterfaceStream {
|
|
8
|
+
read(): number;
|
|
9
|
+
/**
|
|
10
|
+
* This method needs to be parsed with `JSON.parse(...)`
|
|
11
|
+
* @param chinkSize The size of the chunk to read
|
|
12
|
+
* @returns The chunk data as a string
|
|
13
|
+
*/
|
|
14
|
+
readChunk(chinkSize: number): string;
|
|
15
|
+
close(): void;
|
|
16
|
+
skip(n: number): number;
|
|
17
|
+
}
|
|
18
|
+
export interface ReadableStreamInit extends RequestInit {
|
|
19
|
+
chunkSize?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function wrapInputStream(inputStream: FileInputInterfaceStream, init?: ReadableStreamInit): Promise<Response>;
|
|
22
|
+
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webuix",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A library to make your life easier when working with MMRL's WebUI",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "GPL-3.0-only",
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@types/bun": "latest"
|
|
18
|
+
"@types/bun": "latest",
|
|
19
|
+
"bun-plugin-dts": "^0.3.0",
|
|
20
|
+
"tsc": "^2.0.4"
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"typescript": "^5.0.0"
|
package/dist/index.js
DELETED
package/dist/wrappers/index.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// src/wrappers/index.ts
|
|
30
|
-
var exports_wrappers = {};
|
|
31
|
-
__export(exports_wrappers, {
|
|
32
|
-
wrapToReadableStream: () => wrapToReadableStream,
|
|
33
|
-
wrapInputStream: () => wrapInputStream
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(exports_wrappers);
|
|
36
|
-
|
|
37
|
-
// src/wrappers/wrapToReadableStream.ts
|
|
38
|
-
var readableStreamInit = {
|
|
39
|
-
chunkSize: 1024 * 1024,
|
|
40
|
-
headers: {
|
|
41
|
-
"Content-Type": "application/octet-stream"
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
async function wrapToReadableStream(inputStream, init = {}) {
|
|
45
|
-
const mergedInit = {
|
|
46
|
-
...readableStreamInit,
|
|
47
|
-
...init
|
|
48
|
-
};
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
let input;
|
|
51
|
-
try {
|
|
52
|
-
input = inputStream;
|
|
53
|
-
if (!input) {
|
|
54
|
-
throw new Error("Failed to open file input stream");
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
reject(error);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const abortHandler = () => {
|
|
61
|
-
try {
|
|
62
|
-
input?.close();
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error("Error during abort cleanup:", error);
|
|
65
|
-
}
|
|
66
|
-
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
67
|
-
};
|
|
68
|
-
if (mergedInit.signal) {
|
|
69
|
-
if (mergedInit.signal.aborted) {
|
|
70
|
-
abortHandler();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
mergedInit.signal.addEventListener("abort", abortHandler);
|
|
74
|
-
}
|
|
75
|
-
const stream = new ReadableStream({
|
|
76
|
-
async pull(controller) {
|
|
77
|
-
try {
|
|
78
|
-
const chunkData = getChunkData(input, mergedInit.chunkSize);
|
|
79
|
-
if (!chunkData) {
|
|
80
|
-
controller.close();
|
|
81
|
-
cleanup();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
controller.enqueue(chunkData);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
cleanup();
|
|
87
|
-
controller.error(error);
|
|
88
|
-
reject(new Error(`Error reading file chunk: ${error}`));
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
cancel(reason) {
|
|
92
|
-
console.warn("Stream canceled:", reason);
|
|
93
|
-
cleanup();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
function cleanup() {
|
|
97
|
-
try {
|
|
98
|
-
if (mergedInit.signal) {
|
|
99
|
-
mergedInit.signal.removeEventListener("abort", abortHandler);
|
|
100
|
-
}
|
|
101
|
-
input?.close();
|
|
102
|
-
} catch (error) {
|
|
103
|
-
console.error(`Error during cleanup: ${error}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
resolve(stream);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function getChunkData(input, chunkSize) {
|
|
110
|
-
try {
|
|
111
|
-
const chunkData = chunkSize ? input.readChunk(chunkSize) : input.read();
|
|
112
|
-
if (typeof chunkData === "number") {
|
|
113
|
-
return new Uint8Array([chunkData]);
|
|
114
|
-
} else if (typeof chunkData === "string") {
|
|
115
|
-
const chunk = JSON.parse(chunkData);
|
|
116
|
-
return chunk && Array.isArray(chunk) && chunk.length > 0 ? new Uint8Array(chunk) : null;
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
} catch (error) {
|
|
120
|
-
throw new Error("Error reading chunk data: " + error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// src/wrappers/wrapInputStream.ts
|
|
124
|
-
async function wrapInputStream(inputStream, init = {}) {
|
|
125
|
-
const mergedInit = {
|
|
126
|
-
...readableStreamInit,
|
|
127
|
-
...init
|
|
128
|
-
};
|
|
129
|
-
try {
|
|
130
|
-
const stream = await wrapToReadableStream(inputStream, mergedInit);
|
|
131
|
-
return new Response(stream, mergedInit);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
throw new Error(`wrapInputStream failed: ${error}`);
|
|
134
|
-
}
|
|
135
|
-
}
|