@dxos/functions-simulator-cloudflare 0.10.0 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions-simulator-cloudflare",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Simulate functions running in Cloudflare runtime",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -14,14 +14,14 @@
14
14
  "type": "module",
15
15
  "exports": {
16
16
  ".": {
17
+ "source": "./src/index.ts",
17
18
  "types": "./dist/types/src/index.d.ts",
18
- "browser": "./dist/lib/browser/index.mjs",
19
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "import": "./dist/lib/index.mjs"
20
20
  },
21
21
  "./testing": {
22
+ "source": "./src/testing/index.ts",
22
23
  "types": "./dist/types/src/testing/index.d.ts",
23
- "browser": "./dist/lib/browser/testing/index.mjs",
24
- "node": "./dist/lib/node-esm/testing/index.mjs"
24
+ "import": "./dist/lib/testing.mjs"
25
25
  }
26
26
  },
27
27
  "types": "dist/types/src/index.d.ts",
@@ -30,9 +30,9 @@
30
30
  "src"
31
31
  ],
32
32
  "dependencies": {
33
- "miniflare": "^4.20251128.0",
34
- "@dxos/context": "0.10.0",
35
- "@dxos/protocols": "0.10.0"
33
+ "miniflare": "^4.20260714.0",
34
+ "@dxos/context": "0.11.1",
35
+ "@dxos/protocols": "0.11.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
@@ -10,9 +10,6 @@ import { type EdgeEnvelope, type SerializedError } from '@dxos/protocols';
10
10
  export type InvokeResult =
11
11
  | {
12
12
  _kind: 'success';
13
- /**
14
- * The output of the function.
15
- */
16
13
  result: unknown;
17
14
  }
18
15
  | {
@@ -1,81 +0,0 @@
1
- // src/function-worker.ts
2
- import { Miniflare, Request } from "miniflare";
3
- import { Resource } from "@dxos/context";
4
- var makeJsModule = (source) => ({
5
- contentType: "application/javascript",
6
- contents: new TextEncoder().encode(source)
7
- });
8
- var FunctionWorker = class extends Resource {
9
- #miniflare;
10
- constructor(opts) {
11
- super();
12
- if (!opts.modules[opts.mainModule]) {
13
- throw new Error(`Main module not found: ${opts.mainModule}`);
14
- }
15
- const modules = Object.entries(opts.modules).map(([filename, mod]) => {
16
- switch (mod.contentType) {
17
- case "application/javascript":
18
- return {
19
- type: "ESModule",
20
- path: filename,
21
- contents: mod.contents
22
- };
23
- case "application/wasm":
24
- return {
25
- type: "CompiledWasm",
26
- path: filename,
27
- contents: mod.contents
28
- };
29
- default:
30
- throw new Error(`Unsupported content type: ${mod.contentType}`);
31
- }
32
- });
33
- modules.sort((a, b) => a.path === opts.mainModule ? -1 : 1);
34
- this.#miniflare = new Miniflare({
35
- modules
36
- });
37
- }
38
- async _close(_ctx) {
39
- await this.#miniflare.dispose();
40
- }
41
- async invoke(input) {
42
- const request = new Request("http://functions.dxos.internal/", {
43
- method: "POST",
44
- headers: {
45
- "Content-Type": "application/json",
46
- "X-Edge-Env": "test"
47
- },
48
- body: JSON.stringify({
49
- data: input
50
- })
51
- });
52
- const response = await this.#miniflare.dispatchFetch(request);
53
- try {
54
- const envelope = await response.clone().json();
55
- if (envelope.success) {
56
- return {
57
- _kind: "success",
58
- result: envelope.data
59
- };
60
- }
61
- return {
62
- _kind: "error",
63
- error: envelope.error ?? {
64
- message: envelope.message
65
- }
66
- };
67
- } catch (err) {
68
- return {
69
- _kind: "error",
70
- error: {
71
- message: (await response.text()).slice(0, 1024)
72
- }
73
- };
74
- }
75
- }
76
- };
77
- export {
78
- FunctionWorker,
79
- makeJsModule
80
- };
81
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/function-worker.ts"],
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,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
- }
@@ -1 +0,0 @@
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}}}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }
@@ -1,83 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/function-worker.ts
4
- import { Miniflare, Request } from "miniflare";
5
- import { Resource } from "@dxos/context";
6
- var makeJsModule = (source) => ({
7
- contentType: "application/javascript",
8
- contents: new TextEncoder().encode(source)
9
- });
10
- var FunctionWorker = class extends Resource {
11
- #miniflare;
12
- constructor(opts) {
13
- super();
14
- if (!opts.modules[opts.mainModule]) {
15
- throw new Error(`Main module not found: ${opts.mainModule}`);
16
- }
17
- const modules = Object.entries(opts.modules).map(([filename, mod]) => {
18
- switch (mod.contentType) {
19
- case "application/javascript":
20
- return {
21
- type: "ESModule",
22
- path: filename,
23
- contents: mod.contents
24
- };
25
- case "application/wasm":
26
- return {
27
- type: "CompiledWasm",
28
- path: filename,
29
- contents: mod.contents
30
- };
31
- default:
32
- throw new Error(`Unsupported content type: ${mod.contentType}`);
33
- }
34
- });
35
- modules.sort((a, b) => a.path === opts.mainModule ? -1 : 1);
36
- this.#miniflare = new Miniflare({
37
- modules
38
- });
39
- }
40
- async _close(_ctx) {
41
- await this.#miniflare.dispose();
42
- }
43
- async invoke(input) {
44
- const request = new Request("http://functions.dxos.internal/", {
45
- method: "POST",
46
- headers: {
47
- "Content-Type": "application/json",
48
- "X-Edge-Env": "test"
49
- },
50
- body: JSON.stringify({
51
- data: input
52
- })
53
- });
54
- const response = await this.#miniflare.dispatchFetch(request);
55
- try {
56
- const envelope = await response.clone().json();
57
- if (envelope.success) {
58
- return {
59
- _kind: "success",
60
- result: envelope.data
61
- };
62
- }
63
- return {
64
- _kind: "error",
65
- error: envelope.error ?? {
66
- message: envelope.message
67
- }
68
- };
69
- } catch (err) {
70
- return {
71
- _kind: "error",
72
- error: {
73
- message: (await response.text()).slice(0, 1024)
74
- }
75
- };
76
- }
77
- }
78
- };
79
- export {
80
- FunctionWorker,
81
- makeJsModule
82
- };
83
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/function-worker.ts"],
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,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
- }
@@ -1 +0,0 @@
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,2 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }