@mcp-b/do-runtime 0.2.2 → 0.3.0
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/CHANGELOG.md +12 -0
- package/dist/chunks/io-context-Ci3Rf6U5.js +1459 -0
- package/dist/chunks/io-context-Ci3Rf6U5.js.map +1 -0
- package/dist/gate.js +105 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.js +109 -1442
- package/dist/index.js.map +1 -1
- package/dist/src/api/http.d.ts +1 -0
- package/dist/src/fixtures/await-transform.actor.d.ts +1 -0
- package/dist/src/gate.d.ts +4 -0
- package/dist/src/io/io-context.d.ts +6 -0
- package/dist/src/vite.d.ts +7 -0
- package/dist/vite.js +55 -0
- package/dist/vite.js.map +1 -0
- package/package.json +19 -3
package/dist/src/api/http.d.ts
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
*/
|
|
36
36
|
type IoAwaiter = {
|
|
37
37
|
awaitIo<T>(promise: Promise<T>): Promise<T>;
|
|
38
|
+
awaitIo<T, R>(promise: Promise<T>, func: (value: T) => R | PromiseLike<R>): Promise<R>;
|
|
38
39
|
};
|
|
39
40
|
/** Wrap a host-provided request so consuming or streaming its body resumes gated. */
|
|
40
41
|
export declare function gateRequestBody(ctx: IoAwaiter, request: Request): Request;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readAfterForeignAwait(storage: DurableObjectStorage): Promise<unknown>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Re-enter the actor that owns this transformed await; fail open outside actors. */
|
|
2
|
+
export declare function __gate<T>(value: T): T | Promise<Awaited<T>>;
|
|
3
|
+
/** Gate every operation used by `for await`, including early return and throw. */
|
|
4
|
+
export declare function __gateAsyncIterable<T, IterableType extends AsyncIterable<T> | Iterable<T>>(iterable: IterableType): IterableType;
|
|
@@ -466,6 +466,12 @@ export declare class IoContext {
|
|
|
466
466
|
*/
|
|
467
467
|
awaitIo<T>(promise: Promise<T>): Promise<T>;
|
|
468
468
|
awaitIo<T, R>(promise: Promise<T>, func: (value: T) => R | PromiseLike<R>): Promise<R>;
|
|
469
|
+
/**
|
|
470
|
+
* The await transform's hot path. It preserves provenance without capturing
|
|
471
|
+
* an Error stack for every await: the first call and every 64th call refresh
|
|
472
|
+
* the sampled site, while intervening calls keep that stack and say so.
|
|
473
|
+
*/
|
|
474
|
+
awaitIoFromTransform<T>(promise: Promise<T>): Promise<T>;
|
|
469
475
|
/**
|
|
470
476
|
* Waits for the given I/O while holding the input lock, so that all other I/O is blocked
|
|
471
477
|
* from completing in the meantime (unless it is also holding the same input lock).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type FilterPattern, type Plugin } from "vite";
|
|
2
|
+
export interface DoRuntimeAwaitTransformOptions {
|
|
3
|
+
include?: FilterPattern;
|
|
4
|
+
exclude?: FilterPattern;
|
|
5
|
+
}
|
|
6
|
+
/** Rewrite syntactic awaits in selected actor-bundled modules to re-enter their input gate. */
|
|
7
|
+
export declare function doRuntimeAwaitTransform(options?: DoRuntimeAwaitTransformOptions): Plugin;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import MagicString from "magic-string";
|
|
2
|
+
import { Visitor, createFilter } from "vite";
|
|
3
|
+
//#region src/vite.ts
|
|
4
|
+
var MARKER = "/* @do-runtime-gated */";
|
|
5
|
+
var IMPORT = "import { __gate, __gateAsyncIterable } from \"@mcp-b/do-runtime/gate\";";
|
|
6
|
+
function patterns(pattern) {
|
|
7
|
+
if (pattern === void 0 || pattern === null) return [];
|
|
8
|
+
return typeof pattern === "string" || pattern instanceof RegExp ? [pattern] : pattern;
|
|
9
|
+
}
|
|
10
|
+
/** Rewrite syntactic awaits in selected actor-bundled modules to re-enter their input gate. */
|
|
11
|
+
function doRuntimeAwaitTransform(options) {
|
|
12
|
+
const filter = createFilter(options?.include, [
|
|
13
|
+
"**/node_modules/@mcp-b/do-runtime/**",
|
|
14
|
+
"**/@mcp-b/do-runtime/gate",
|
|
15
|
+
...patterns(options?.exclude)
|
|
16
|
+
]);
|
|
17
|
+
return {
|
|
18
|
+
name: "do-runtime-await-transform",
|
|
19
|
+
enforce: "post",
|
|
20
|
+
transform(code, id) {
|
|
21
|
+
if (!code.includes("await") || code.includes(MARKER) || !filter(id)) return null;
|
|
22
|
+
const source = new MagicString(code);
|
|
23
|
+
let transformed = false;
|
|
24
|
+
const program = this.parse(code);
|
|
25
|
+
new Visitor({
|
|
26
|
+
AwaitExpression(node) {
|
|
27
|
+
source.prependLeft(node.argument.start, "__gate((");
|
|
28
|
+
source.appendRight(node.argument.end, "))");
|
|
29
|
+
transformed = true;
|
|
30
|
+
},
|
|
31
|
+
ForOfStatement(node) {
|
|
32
|
+
if (!node.await) return;
|
|
33
|
+
source.prependLeft(node.right.start, "__gateAsyncIterable((");
|
|
34
|
+
source.appendRight(node.right.end, "))");
|
|
35
|
+
transformed = true;
|
|
36
|
+
}
|
|
37
|
+
}).visit(program);
|
|
38
|
+
if (!transformed) return null;
|
|
39
|
+
const insertionPoint = code.startsWith("#!") ? code.indexOf("\n") + 1 : 0;
|
|
40
|
+
source.appendLeft(insertionPoint, `${MARKER}\n${IMPORT}\n`);
|
|
41
|
+
return {
|
|
42
|
+
code: source.toString(),
|
|
43
|
+
map: source.generateMap({
|
|
44
|
+
hires: "boundary",
|
|
45
|
+
includeContent: true,
|
|
46
|
+
source: id
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { doRuntimeAwaitTransform };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import MagicString from \"magic-string\";\nimport {\n createFilter,\n Visitor,\n type FilterPattern,\n type Plugin,\n} from \"vite\";\n\nconst MARKER = \"/* @do-runtime-gated */\";\nconst IMPORT =\n 'import { __gate, __gateAsyncIterable } from \"@mcp-b/do-runtime/gate\";';\n\nexport interface DoRuntimeAwaitTransformOptions {\n include?: FilterPattern;\n exclude?: FilterPattern;\n}\n\nfunction patterns(pattern: FilterPattern | undefined): readonly (string | RegExp)[] {\n if (pattern === undefined || pattern === null) return [];\n return typeof pattern === \"string\" || pattern instanceof RegExp ? [pattern] : pattern;\n}\n\n/** Rewrite syntactic awaits in selected actor-bundled modules to re-enter their input gate. */\nexport function doRuntimeAwaitTransform(options?: DoRuntimeAwaitTransformOptions): Plugin {\n const filter = createFilter(options?.include, [\n \"**/node_modules/@mcp-b/do-runtime/**\",\n \"**/@mcp-b/do-runtime/gate\",\n ...patterns(options?.exclude),\n ]);\n\n return {\n name: \"do-runtime-await-transform\",\n enforce: \"post\",\n transform(code, id) {\n if (!code.includes(\"await\") || code.includes(MARKER) || !filter(id)) return null;\n\n const source = new MagicString(code);\n let transformed = false;\n const program = this.parse(code);\n new Visitor({\n AwaitExpression(node) {\n source.prependLeft(node.argument.start, \"__gate((\");\n source.appendRight(node.argument.end, \"))\");\n transformed = true;\n },\n ForOfStatement(node) {\n if (!node.await) return;\n source.prependLeft(node.right.start, \"__gateAsyncIterable((\");\n source.appendRight(node.right.end, \"))\");\n transformed = true;\n },\n }).visit(program);\n if (!transformed) return null;\n\n const insertionPoint = code.startsWith(\"#!\") ? code.indexOf(\"\\n\") + 1 : 0;\n source.appendLeft(insertionPoint, `${MARKER}\\n${IMPORT}\\n`);\n return {\n code: source.toString(),\n map: source.generateMap({ hires: \"boundary\", includeContent: true, source: id }),\n };\n },\n };\n}\n"],"mappings":";;;AAQA,IAAM,SAAS;AACf,IAAM,SACJ;AAOF,SAAS,SAAS,SAAkE;CAClF,IAAI,YAAY,KAAA,KAAa,YAAY,MAAM,OAAO,CAAC;CACvD,OAAO,OAAO,YAAY,YAAY,mBAAmB,SAAS,CAAC,OAAO,IAAI;AAChF;;AAGA,SAAgB,wBAAwB,SAAkD;CACxF,MAAM,SAAS,aAAa,SAAS,SAAS;EAC5C;EACA;EACA,GAAG,SAAS,SAAS,OAAO;CAC9B,CAAC;CAED,OAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,MAAM,IAAI;GAClB,IAAI,CAAC,KAAK,SAAS,OAAO,KAAK,KAAK,SAAS,MAAM,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO;GAE5E,MAAM,SAAS,IAAI,YAAY,IAAI;GACnC,IAAI,cAAc;GAClB,MAAM,UAAU,KAAK,MAAM,IAAI;GAC/B,IAAI,QAAQ;IACV,gBAAgB,MAAM;KACpB,OAAO,YAAY,KAAK,SAAS,OAAO,UAAU;KAClD,OAAO,YAAY,KAAK,SAAS,KAAK,IAAI;KAC1C,cAAc;IAChB;IACA,eAAe,MAAM;KACnB,IAAI,CAAC,KAAK,OAAO;KACjB,OAAO,YAAY,KAAK,MAAM,OAAO,uBAAuB;KAC5D,OAAO,YAAY,KAAK,MAAM,KAAK,IAAI;KACvC,cAAc;IAChB;GACF,CAAC,CAAC,CAAC,MAAM,OAAO;GAChB,IAAI,CAAC,aAAa,OAAO;GAEzB,MAAM,iBAAiB,KAAK,WAAW,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI;GACxE,OAAO,WAAW,gBAAgB,GAAG,OAAO,IAAI,OAAO,GAAG;GAC1D,OAAO;IACL,MAAM,OAAO,SAAS;IACtB,KAAK,OAAO,YAAY;KAAE,OAAO;KAAY,gBAAgB;KAAM,QAAQ;IAAG,CAAC;GACjF;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/do-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cloudflare's Durable Object runtime (workerd), ported to TypeScript: actors with input/output gates, SQLite storage, facets and alarms, running in the browser and in Node.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actors",
|
|
@@ -57,6 +57,14 @@
|
|
|
57
57
|
"types": "./dist/src/api/cloudflare-workers.d.ts",
|
|
58
58
|
"import": "./dist/cloudflare-workers.js"
|
|
59
59
|
},
|
|
60
|
+
"./gate": {
|
|
61
|
+
"types": "./dist/src/gate.d.ts",
|
|
62
|
+
"import": "./dist/gate.js"
|
|
63
|
+
},
|
|
64
|
+
"./vite": {
|
|
65
|
+
"types": "./dist/src/vite.d.ts",
|
|
66
|
+
"import": "./dist/vite.js"
|
|
67
|
+
},
|
|
60
68
|
"./conformance": {
|
|
61
69
|
"types": "./dist/conformance/host.d.ts",
|
|
62
70
|
"import": "./dist/conformance.js"
|
|
@@ -65,7 +73,16 @@
|
|
|
65
73
|
},
|
|
66
74
|
"dependencies": {
|
|
67
75
|
"@ungap/structured-clone": "1.3.3",
|
|
68
|
-
"capnweb": "0.10.0"
|
|
76
|
+
"capnweb": "0.10.0",
|
|
77
|
+
"magic-string": "0.30.21"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"vite": "^8.1.5"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"vite": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
69
86
|
},
|
|
70
87
|
"devDependencies": {
|
|
71
88
|
"@arethetypeswrong/cli": "0.18.5",
|
|
@@ -79,7 +96,6 @@
|
|
|
79
96
|
"playwright": "1.61.1",
|
|
80
97
|
"publint": "0.3.23",
|
|
81
98
|
"typescript": "^5.9.3",
|
|
82
|
-
"vite": "^8.1.5",
|
|
83
99
|
"vitest": "4.1.10",
|
|
84
100
|
"workerd": "1.20260820.1",
|
|
85
101
|
"wrangler": "^4.114.0"
|