@dxos/functions-simulator-cloudflare 0.8.4-main.4a85c3132b → 0.8.4-main.4f23b4e393
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/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs.map +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/function-worker.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -10
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/function-worker.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Miniflare, Request } from 'miniflare';\n\nimport { type Context, Resource } from '@dxos/context';\nimport { type EdgeEnvelope, type SerializedError } from '@dxos/protocols';\n\nexport type InvokeResult =\n | {\n _kind: 'success';\n /**\n * The output of the function.\n */\n result: unknown;\n }\n | {\n _kind: 'error';\n error: SerializedError;\n };\n\nexport type FunctionWorkerOptions = {\n mainModule: string;\n modules: {\n [filename: string]: {\n contents: Uint8Array<ArrayBuffer>;\n contentType: string;\n };\n };\n};\n\nexport const makeJsModule = (source: string) => ({\n contentType: 'application/javascript',\n contents: new TextEncoder().encode(source),\n});\n\nexport class FunctionWorker extends Resource {\n #miniflare: Miniflare;\n\n constructor(opts: FunctionWorkerOptions) {\n super();\n if (!opts.modules[opts.mainModule]) {\n throw new Error(`Main module not found: ${opts.mainModule}`);\n }\n\n const modules: MiniflareModule[] = Object.entries(opts.modules).map(([filename, mod]) => {\n switch (mod.contentType) {\n case 'application/javascript':\n return {\n type: 'ESModule' as const,\n path: filename,\n contents: mod.contents,\n };\n case 'application/wasm':\n return {\n type: 'CompiledWasm' as const,\n path: filename,\n contents: mod.contents,\n };\n default:\n throw new Error(`Unsupported content type: ${mod.contentType}`);\n }\n });\n\n modules.sort((a, b) => (a.path === opts.mainModule ? -1 : 1));\n\n this.#miniflare = new Miniflare({\n modules,\n });\n }\n\n protected override async _close(_ctx: Context): Promise<void> {\n await this.#miniflare.dispose();\n }\n\n async invoke(input: unknown): Promise<InvokeResult> {\n const request = new Request('http://functions.dxos.internal/', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Edge-Env': 'test',\n },\n body: JSON.stringify({ data: input }),\n });\n const response = await this.#miniflare.dispatchFetch(request);\n try {\n const envelope = (await response.clone().json()) as EdgeEnvelope<unknown>;\n if (envelope.success) {\n return { _kind: 'success', result: envelope.data };\n }\n return {\n _kind: 'error',\n error: envelope.error ?? {\n message: envelope.message,\n },\n };\n } catch (err) {\n return {\n _kind: 'error',\n error: {\n message: (await response.text()).slice(0, 1024),\n },\n };\n }\n }\n}\n\ntype MiniflareModule = {\n type: 'ESModule' | 'CommonJS' | 'Text' | 'Data' | 'CompiledWasm' | 'PythonModule' | 'PythonRequirement';\n path: string;\n contents?: string | Uint8Array<ArrayBuffer> | undefined;\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,WAAWC,eAAe;AAEnC,SAAuBC,gBAAgB;AA0BhC,IAAMC,eAAe,CAACC,YAAoB;EAC/CC,aAAa;EACbC,UAAU,IAAIC,YAAAA,EAAcC,OAAOJ,MAAAA;AACrC;AAEO,IAAMK,iBAAN,
|
|
6
|
-
"names": ["Miniflare", "Request", "Resource", "makeJsModule", "source", "contentType", "contents", "TextEncoder", "encode", "FunctionWorker", "
|
|
5
|
+
"mappings": ";AAIA,SAASA,WAAWC,eAAe;AAEnC,SAAuBC,gBAAgB;AA0BhC,IAAMC,eAAe,CAACC,YAAoB;EAC/CC,aAAa;EACbC,UAAU,IAAIC,YAAAA,EAAcC,OAAOJ,MAAAA;AACrC;AAEO,IAAMK,iBAAN,cAA6BP,SAAAA;EAClC;EAEA,YAAYQ,MAA6B;AACvC,UAAK;AACL,QAAI,CAACA,KAAKC,QAAQD,KAAKE,UAAU,GAAG;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|
6
|
+
"names": ["Miniflare", "Request", "Resource", "makeJsModule", "source", "contentType", "contents", "TextEncoder", "encode", "FunctionWorker", "opts", "modules", "mainModule", "Error", "Object", "entries", "map", "filename", "mod", "type", "path", "sort", "a", "b", "_close", "_ctx", "dispose", "invoke", "input", "request", "method", "headers", "body", "JSON", "stringify", "data", "response", "dispatchFetch", "envelope", "clone", "json", "success", "_kind", "result", "error", "message", "err", "text", "slice"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/function-worker.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/function-worker.ts":{"bytes":9349,"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":395,"imports":[{"path":"src/function-worker.ts","kind":"import-statement","original":"./function-worker"}],"format":"esm"},"src/testing/index.ts":{"bytes":332,"imports":[],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4942},"dist/lib/browser/index.mjs":{"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"exports":["FunctionWorker","makeJsModule"],"entryPoint":"src/index.ts","inputs":{"src/function-worker.ts":{"bytesInOutput":1993},"src/index.ts":{"bytesInOutput":0}},"bytes":2099},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/browser/testing/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/index.ts":{"bytesInOutput":0}},"bytes":35}}}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/function-worker.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Miniflare, Request } from 'miniflare';\n\nimport { type Context, Resource } from '@dxos/context';\nimport { type EdgeEnvelope, type SerializedError } from '@dxos/protocols';\n\nexport type InvokeResult =\n | {\n _kind: 'success';\n /**\n * The output of the function.\n */\n result: unknown;\n }\n | {\n _kind: 'error';\n error: SerializedError;\n };\n\nexport type FunctionWorkerOptions = {\n mainModule: string;\n modules: {\n [filename: string]: {\n contents: Uint8Array<ArrayBuffer>;\n contentType: string;\n };\n };\n};\n\nexport const makeJsModule = (source: string) => ({\n contentType: 'application/javascript',\n contents: new TextEncoder().encode(source),\n});\n\nexport class FunctionWorker extends Resource {\n #miniflare: Miniflare;\n\n constructor(opts: FunctionWorkerOptions) {\n super();\n if (!opts.modules[opts.mainModule]) {\n throw new Error(`Main module not found: ${opts.mainModule}`);\n }\n\n const modules: MiniflareModule[] = Object.entries(opts.modules).map(([filename, mod]) => {\n switch (mod.contentType) {\n case 'application/javascript':\n return {\n type: 'ESModule' as const,\n path: filename,\n contents: mod.contents,\n };\n case 'application/wasm':\n return {\n type: 'CompiledWasm' as const,\n path: filename,\n contents: mod.contents,\n };\n default:\n throw new Error(`Unsupported content type: ${mod.contentType}`);\n }\n });\n\n modules.sort((a, b) => (a.path === opts.mainModule ? -1 : 1));\n\n this.#miniflare = new Miniflare({\n modules,\n });\n }\n\n protected override async _close(_ctx: Context): Promise<void> {\n await this.#miniflare.dispose();\n }\n\n async invoke(input: unknown): Promise<InvokeResult> {\n const request = new Request('http://functions.dxos.internal/', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Edge-Env': 'test',\n },\n body: JSON.stringify({ data: input }),\n });\n const response = await this.#miniflare.dispatchFetch(request);\n try {\n const envelope = (await response.clone().json()) as EdgeEnvelope<unknown>;\n if (envelope.success) {\n return { _kind: 'success', result: envelope.data };\n }\n return {\n _kind: 'error',\n error: envelope.error ?? {\n message: envelope.message,\n },\n };\n } catch (err) {\n return {\n _kind: 'error',\n error: {\n message: (await response.text()).slice(0, 1024),\n },\n };\n }\n }\n}\n\ntype MiniflareModule = {\n type: 'ESModule' | 'CommonJS' | 'Text' | 'Data' | 'CompiledWasm' | 'PythonModule' | 'PythonRequirement';\n path: string;\n contents?: string | Uint8Array<ArrayBuffer> | undefined;\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,WAAWC,eAAe;AAEnC,SAAuBC,gBAAgB;AA0BhC,IAAMC,eAAe,CAACC,YAAoB;EAC/CC,aAAa;EACbC,UAAU,IAAIC,YAAAA,EAAcC,OAAOJ,MAAAA;AACrC;AAEO,IAAMK,iBAAN,
|
|
6
|
-
"names": ["Miniflare", "Request", "Resource", "makeJsModule", "source", "contentType", "contents", "TextEncoder", "encode", "FunctionWorker", "
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,WAAWC,eAAe;AAEnC,SAAuBC,gBAAgB;AA0BhC,IAAMC,eAAe,CAACC,YAAoB;EAC/CC,aAAa;EACbC,UAAU,IAAIC,YAAAA,EAAcC,OAAOJ,MAAAA;AACrC;AAEO,IAAMK,iBAAN,cAA6BP,SAAAA;EAClC;EAEA,YAAYQ,MAA6B;AACvC,UAAK;AACL,QAAI,CAACA,KAAKC,QAAQD,KAAKE,UAAU,GAAG;AAClC,YAAM,IAAIC,MAAM,0BAA0BH,KAAKE,UAAU,EAAE;IAC7D;AAEA,UAAMD,UAA6BG,OAAOC,QAAQL,KAAKC,OAAO,EAAEK,IAAI,CAAC,CAACC,UAAUC,GAAAA,MAAI;AAClF,cAAQA,IAAIb,aAAW;QACrB,KAAK;AACH,iBAAO;YACLc,MAAM;YACNC,MAAMH;YACNX,UAAUY,IAAIZ;UAChB;QACF,KAAK;AACH,iBAAO;YACLa,MAAM;YACNC,MAAMH;YACNX,UAAUY,IAAIZ;UAChB;QACF;AACE,gBAAM,IAAIO,MAAM,6BAA6BK,IAAIb,WAAW,EAAE;MAClE;IACF,CAAA;AAEAM,YAAQU,KAAK,CAACC,GAAGC,MAAOD,EAAEF,SAASV,KAAKE,aAAa,KAAK,CAAA;AAE1D,SAAK,aAAa,IAAIZ,UAAU;MAC9BW;IACF,CAAA;EACF;EAEA,MAAyBa,OAAOC,MAA8B;AAC5D,UAAM,KAAK,WAAWC,QAAO;EAC/B;EAEA,MAAMC,OAAOC,OAAuC;AAClD,UAAMC,UAAU,IAAI5B,QAAQ,mCAAmC;MAC7D6B,QAAQ;MACRC,SAAS;QACP,gBAAgB;QAChB,cAAc;MAChB;MACAC,MAAMC,KAAKC,UAAU;QAAEC,MAAMP;MAAM,CAAA;IACrC,CAAA;AACA,UAAMQ,WAAW,MAAM,KAAK,WAAWC,cAAcR,OAAAA;AACrD,QAAI;AACF,YAAMS,WAAY,MAAMF,SAASG,MAAK,EAAGC,KAAI;AAC7C,UAAIF,SAASG,SAAS;AACpB,eAAO;UAAEC,OAAO;UAAWC,QAAQL,SAASH;QAAK;MACnD;AACA,aAAO;QACLO,OAAO;QACPE,OAAON,SAASM,SAAS;UACvBC,SAASP,SAASO;QACpB;MACF;IACF,SAASC,KAAK;AACZ,aAAO;QACLJ,OAAO;QACPE,OAAO;UACLC,UAAU,MAAMT,SAASW,KAAI,GAAIC,MAAM,GAAG,IAAA;QAC5C;MACF;IACF;EACF;AACF;",
|
|
6
|
+
"names": ["Miniflare", "Request", "Resource", "makeJsModule", "source", "contentType", "contents", "TextEncoder", "encode", "FunctionWorker", "opts", "modules", "mainModule", "Error", "Object", "entries", "map", "filename", "mod", "type", "path", "sort", "a", "b", "_close", "_ctx", "dispose", "invoke", "input", "request", "method", "headers", "body", "JSON", "stringify", "data", "response", "dispatchFetch", "envelope", "clone", "json", "success", "_kind", "result", "error", "message", "err", "text", "slice"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/function-worker.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/function-worker.ts":{"bytes":9349,"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":395,"imports":[{"path":"src/function-worker.ts","kind":"import-statement","original":"./function-worker"}],"format":"esm"},"src/testing/index.ts":{"bytes":332,"imports":[],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4944},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"exports":["FunctionWorker","makeJsModule"],"entryPoint":"src/index.ts","inputs":{"src/function-worker.ts":{"bytesInOutput":1993},"src/index.ts":{"bytesInOutput":0}},"bytes":2192},"dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/node-esm/testing/index.mjs":{"imports":[],"exports":[],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/index.ts":{"bytesInOutput":0}},"bytes":127}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-worker.d.ts","sourceRoot":"","sources":["../../../src/function-worker.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,MAAM,YAAY,GACpB;IACE,KAAK,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB,GACD;IACE,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEN,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;YAClC,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"function-worker.d.ts","sourceRoot":"","sources":["../../../src/function-worker.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KA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