@dxos/functions-simulator-cloudflare 0.8.4-main.3c1ae3b
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/LICENSE +8 -0
- package/README.md +21 -0
- package/dist/lib/browser/index.mjs +81 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/testing/index.mjs +1 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +83 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +2 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/function-worker.d.ts +32 -0
- package/dist/types/src/function-worker.d.ts.map +1 -0
- package/dist/types/src/function-worker.test.d.ts +2 -0
- package/dist/types/src/function-worker.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +44 -0
- package/src/function-worker.test.ts +47 -0
- package/src/function-worker.ts +113 -0
- package/src/index.ts +5 -0
- package/src/testing/index.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @dxos/functions-simulator-cloudflare
|
|
2
|
+
|
|
3
|
+
Simulate functions running in Cloudflare runtime
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm i @dxos/functions-simulator-cloudflare
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## DXOS Resources
|
|
12
|
+
|
|
13
|
+
- [Website](https://dxos.org)
|
|
14
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
15
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
16
|
+
|
|
17
|
+
## Contributions
|
|
18
|
+
|
|
19
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
20
|
+
|
|
21
|
+
License: [MIT](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
|
@@ -0,0 +1,7 @@
|
|
|
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,cAA6BC,SAAAA;EAClC;EAEA,YAAYC,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,IAAId,aAAW;QACrB,KAAK;AACH,iBAAO;YACLe,MAAM;YACNC,MAAMH;YACNZ,UAAUa,IAAIb;UAChB;QACF,KAAK;AACH,iBAAO;YACLc,MAAM;YACNC,MAAMH;YACNZ,UAAUa,IAAIb;UAChB;QACF;AACE,gBAAM,IAAIQ,MAAM,6BAA6BK,IAAId,WAAW,EAAE;MAClE;IACF,CAAA;AAEAO,YAAQU,KAAK,CAACC,GAAGC,MAAOD,EAAEF,SAASV,KAAKE,aAAa,KAAK,CAAA;AAE1D,SAAK,aAAa,IAAIY,UAAU;MAC9Bb;IACF,CAAA;EACF;EAEA,MAAyBc,OAAOC,MAA8B;AAC5D,UAAM,KAAK,WAAWC,QAAO;EAC/B;EAEA,MAAMC,OAAOC,OAAuC;AAClD,UAAMC,UAAU,IAAIC,QAAQ,mCAAmC;MAC7DC,QAAQ;MACRC,SAAS;QACP,gBAAgB;QAChB,cAAc;MAChB;MACAC,MAAMC,KAAKC,UAAU;QAAEC,MAAMR;MAAM,CAAA;IACrC,CAAA;AACA,UAAMS,WAAW,MAAM,KAAK,WAAWC,cAAcT,OAAAA;AACrD,QAAI;AACF,YAAMU,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", "Resource", "opts", "modules", "mainModule", "Error", "Object", "entries", "map", "filename", "mod", "type", "path", "sort", "a", "b", "Miniflare", "_close", "_ctx", "dispose", "invoke", "input", "request", "Request", "method", "headers", "body", "JSON", "stringify", "data", "response", "dispatchFetch", "envelope", "clone", "json", "success", "_kind", "result", "error", "message", "err", "text", "slice"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/function-worker.ts":{"bytes":9454,"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":490,"imports":[{"path":"src/function-worker.ts","kind":"import-statement","original":"./function-worker"}],"format":"esm"},"src/testing/index.ts":{"bytes":435,"imports":[],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4976},"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}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
|
@@ -0,0 +1,7 @@
|
|
|
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,cAA6BC,SAAAA;EAClC;EAEA,YAAYC,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,IAAId,aAAW;QACrB,KAAK;AACH,iBAAO;YACLe,MAAM;YACNC,MAAMH;YACNZ,UAAUa,IAAIb;UAChB;QACF,KAAK;AACH,iBAAO;YACLc,MAAM;YACNC,MAAMH;YACNZ,UAAUa,IAAIb;UAChB;QACF;AACE,gBAAM,IAAIQ,MAAM,6BAA6BK,IAAId,WAAW,EAAE;MAClE;IACF,CAAA;AAEAO,YAAQU,KAAK,CAACC,GAAGC,MAAOD,EAAEF,SAASV,KAAKE,aAAa,KAAK,CAAA;AAE1D,SAAK,aAAa,IAAIY,UAAU;MAC9Bb;IACF,CAAA;EACF;EAEA,MAAyBc,OAAOC,MAA8B;AAC5D,UAAM,KAAK,WAAWC,QAAO;EAC/B;EAEA,MAAMC,OAAOC,OAAuC;AAClD,UAAMC,UAAU,IAAIC,QAAQ,mCAAmC;MAC7DC,QAAQ;MACRC,SAAS;QACP,gBAAgB;QAChB,cAAc;MAChB;MACAC,MAAMC,KAAKC,UAAU;QAAEC,MAAMR;MAAM,CAAA;IACrC,CAAA;AACA,UAAMS,WAAW,MAAM,KAAK,WAAWC,cAAcT,OAAAA;AACrD,QAAI;AACF,YAAMU,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", "Resource", "opts", "modules", "mainModule", "Error", "Object", "entries", "map", "filename", "mod", "type", "path", "sort", "a", "b", "Miniflare", "_close", "_ctx", "dispose", "invoke", "input", "request", "Request", "method", "headers", "body", "JSON", "stringify", "data", "response", "dispatchFetch", "envelope", "clone", "json", "success", "_kind", "result", "error", "message", "err", "text", "slice"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/function-worker.ts":{"bytes":9454,"imports":[{"path":"miniflare","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":490,"imports":[{"path":"src/function-worker.ts","kind":"import-statement","original":"./function-worker"}],"format":"esm"},"src/testing/index.ts":{"bytes":435,"imports":[],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4978},"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}}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Context, Resource } from '@dxos/context';
|
|
2
|
+
import { type SerializedError } from '@dxos/protocols';
|
|
3
|
+
export type InvokeResult = {
|
|
4
|
+
_kind: 'success';
|
|
5
|
+
/**
|
|
6
|
+
* The output of the function.
|
|
7
|
+
*/
|
|
8
|
+
result: unknown;
|
|
9
|
+
} | {
|
|
10
|
+
_kind: 'error';
|
|
11
|
+
error: SerializedError;
|
|
12
|
+
};
|
|
13
|
+
export type FunctionWorkerOptions = {
|
|
14
|
+
mainModule: string;
|
|
15
|
+
modules: {
|
|
16
|
+
[filename: string]: {
|
|
17
|
+
contents: Uint8Array<ArrayBuffer>;
|
|
18
|
+
contentType: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare const makeJsModule: (source: string) => {
|
|
23
|
+
contentType: string;
|
|
24
|
+
contents: Uint8Array<ArrayBuffer>;
|
|
25
|
+
};
|
|
26
|
+
export declare class FunctionWorker extends Resource {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(opts: FunctionWorkerOptions);
|
|
29
|
+
protected _close(_ctx: Context): Promise<void>;
|
|
30
|
+
invoke(input: unknown): Promise<InvokeResult>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=function-worker.d.ts.map
|
|
@@ -0,0 +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,GAAI,QAAQ,MAAM;;;CAGzC,CAAC;AAEH,qBAAa,cAAe,SAAQ,QAAQ;;gBAG9B,IAAI,EAAE,qBAAqB;cAgCd,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;CA8BpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-worker.test.d.ts","sourceRoot":"","sources":["../../../src/function-worker.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC"}
|