@statewalker/cellb 0.8.8 → 0.8.9
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/README.md +1 -1
- package/dist/bindings/cjs-module.d.ts +7 -0
- package/dist/bindings/cjs-module.js +96 -0
- package/dist/bindings/cjs-module.js.map +1 -0
- package/dist/bindings/module-registry.d.ts +33 -0
- package/dist/bindings/module-registry.js +180 -0
- package/dist/bindings/module-registry.js.map +1 -0
- package/dist/bindings/worker-loader.d.ts +23 -5
- package/dist/bindings/worker-loader.js +75 -4
- package/dist/bindings/worker-loader.js.map +1 -1
- package/dist/core/handles.d.ts +21 -1
- package/dist/core/handles.js +49 -3
- package/dist/core/handles.js.map +1 -1
- package/dist/core/namespace.js +4 -1
- package/dist/core/namespace.js.map +1 -1
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +3 -3
- package/dist/core/runtime.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/isolate/browser.d.ts +1 -1
- package/dist/isolate/browser.js +3 -1
- package/dist/isolate/browser.js.map +1 -1
- package/dist/isolate/host.js +20 -2
- package/dist/isolate/host.js.map +1 -1
- package/dist/isolate/isolate-worker.js +13 -1
- package/dist/isolate/isolate-worker.js.map +1 -1
- package/dist/isolate/isolate.js +11 -0
- package/dist/isolate/isolate.js.map +1 -1
- package/dist/isolate/node-entry.js +33 -0
- package/dist/isolate/node-entry.js.map +1 -1
- package/dist/isolate/protocol.d.ts +1 -0
- package/dist/isolate/protocol.js +228 -13
- package/dist/isolate/protocol.js.map +1 -1
- package/dist/isolate/writable-globals.d.ts +9 -0
- package/dist/isolate/writable-globals.js +45 -0
- package/dist/isolate/writable-globals.js.map +1 -0
- package/dist/node-compat/bundle-files.d.ts +26 -0
- package/dist/node-compat/bundle-files.js +210 -0
- package/dist/node-compat/bundle-files.js.map +1 -0
- package/dist/node-compat/fs.d.ts +13 -1
- package/dist/node-compat/fs.js +54 -15
- package/dist/node-compat/fs.js.map +1 -1
- package/dist/project/browser-modules.d.ts +1 -1
- package/dist/project/browser-modules.js +25 -5
- package/dist/project/browser-modules.js.map +1 -1
- package/dist/project/cloudflare-workers.d.ts +9 -0
- package/dist/project/cloudflare-workers.js +14 -0
- package/dist/project/cloudflare-workers.js.map +1 -1
- package/dist/project/module-rules.js +31 -10
- package/dist/project/module-rules.js.map +1 -1
- package/dist/project/node-project.d.ts +2 -0
- package/dist/project/node-project.js +154 -25
- package/dist/project/node-project.js.map +1 -1
- package/dist/project/site-loader.js +2 -1
- package/dist/project/site-loader.js.map +1 -1
- package/dist/project/uint8array-base64.d.ts +7 -0
- package/dist/project/uint8array-base64.js +96 -0
- package/dist/project/uint8array-base64.js.map +1 -0
- package/dist/project/workers-globals-module.d.ts +1 -0
- package/dist/project/workers-globals-module.js +3 -0
- package/dist/project/workers-globals-module.js.map +1 -1
- package/dist/project/wrangler.js +8 -9
- package/dist/project/wrangler.js.map +1 -1
- package/dist/ws/upgrade.js +18 -1
- package/dist/ws/upgrade.js.map +1 -1
- package/package.json +10 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writable-globals.js","sourceRoot":"","sources":["../../src/isolate/writable-globals.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAe,CAAC;IACpC,KACE,IAAI,CAAC,GAAkB,UAAU,EACjC,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,SAAS,EAC3B,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAC5B,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,MAAM,CAAC,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAClD,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,GAAG;gBAAE,SAAS;YAC/B,IAAI,CAAC,KAAK,UAAU,IAAI,CAAC,CAAC,CAAC,YAAY;gBAAE,SAAS;YAClD,IAAI,KAAc,CAAC;YACnB,IAAI,CAAC;gBACH,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YACvC,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS,CAAC,uEAAuE;YACnF,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE;oBACrC,KAAK;oBACL,QAAQ,EAAE,IAAI;oBACd,YAAY,EAAE,IAAI;oBAClB,UAAU,EAAE,CAAC,CAAC,UAAU;iBACzB,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,gCAAgC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * workerd's globals are plain properties that Worker code may assign: Kitesurf's DOM shim sets\n * `globalThis.navigator` and `globalThis.location`. The realm an isolate runs in has getters\n * without setters for some of its own (Node's `navigator`; a Dedicated Worker's `location`,\n * `navigator`, `origin`, … on WorkerGlobalScope.prototype), and assigning one throws in strict\n * mode. The isolate is the loaded Worker's realm, so each such global becomes a writable data\n * property of `globalThis` holding the value it has now.\n */\nexport function makeGlobalsWritable(): string[] {\n const changed: string[] = [];\n const seen = new Set<PropertyKey>();\n for (\n let o: object | null = globalThis;\n o && o !== Object.prototype;\n o = Object.getPrototypeOf(o)\n ) {\n for (const key of Reflect.ownKeys(o)) {\n if (seen.has(key)) continue;\n seen.add(key);\n const d = Object.getOwnPropertyDescriptor(o, key);\n if (!d?.get || d.set) continue;\n if (o === globalThis && !d.configurable) continue;\n let value: unknown;\n try {\n value = Reflect.get(globalThis, key);\n } catch {\n continue; // a getter that throws here (an API this realm refuses) stays as it is\n }\n try {\n Object.defineProperty(globalThis, key, {\n value,\n writable: true,\n configurable: true,\n enumerable: d.enumerable,\n });\n changed.push(String(key));\n } catch {\n // not redefinable in this realm\n }\n }\n }\n return changed;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workerd's `/bundle` for `node:fs` (nodejs_compat): a read-only directory of the Worker's own
|
|
3
|
+
* modules. wrangler uploads each non-JS module a bundle imports (a `.wasm`, a Text or Data file)
|
|
4
|
+
* as a module named `<sha1 of its bytes>-<file name>`, and Worker code can read it there
|
|
5
|
+
* (Kitesurf reads its wasm with `fs.readFileSync("/bundle/…")`).
|
|
6
|
+
*
|
|
7
|
+
* The bundle's rule modules (module-rules.ts) register their bytes here when they are evaluated,
|
|
8
|
+
* under the same names. `bundleFs(base)` wraps a `node:fs` (Node's own, or the browser's, which
|
|
9
|
+
* has no file system) so that paths under `/bundle` read this registry and the rest go to `base`.
|
|
10
|
+
* The registry is the realm's, keyed by content hash, so bundles that share a realm share files.
|
|
11
|
+
*/
|
|
12
|
+
export declare const BUNDLE_DIR = "/bundle";
|
|
13
|
+
type Entry = Uint8Array | (() => Uint8Array);
|
|
14
|
+
/** The realm's `/bundle` files: name → bytes, or a function that makes them. */
|
|
15
|
+
export declare function bundleFiles(): Map<string, Entry>;
|
|
16
|
+
/** Registers `/bundle/<name>` (what a rule module calls). Returns `bytes`. */
|
|
17
|
+
export declare function registerBundleFile<T extends Entry>(name: string, bytes: T): T;
|
|
18
|
+
/**
|
|
19
|
+
* `base` (a `node:fs`) with `/bundle` paths answered from the registry: `existsSync`,
|
|
20
|
+
* `readFileSync`, `statSync`, `lstatSync`, `readdirSync`, `accessSync`, their callback forms and
|
|
21
|
+
* `promises`. Other paths, and every other function, are `base`'s.
|
|
22
|
+
*/
|
|
23
|
+
export declare function bundleFs<T extends Record<string, any>>(base: T): Record<string, unknown>;
|
|
24
|
+
/** `node:fs/promises` with `/bundle` paths answered from the registry. */
|
|
25
|
+
export declare function bundleFsPromises<T extends Record<string, any>>(base: T): Record<string, unknown>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workerd's `/bundle` for `node:fs` (nodejs_compat): a read-only directory of the Worker's own
|
|
3
|
+
* modules. wrangler uploads each non-JS module a bundle imports (a `.wasm`, a Text or Data file)
|
|
4
|
+
* as a module named `<sha1 of its bytes>-<file name>`, and Worker code can read it there
|
|
5
|
+
* (Kitesurf reads its wasm with `fs.readFileSync("/bundle/…")`).
|
|
6
|
+
*
|
|
7
|
+
* The bundle's rule modules (module-rules.ts) register their bytes here when they are evaluated,
|
|
8
|
+
* under the same names. `bundleFs(base)` wraps a `node:fs` (Node's own, or the browser's, which
|
|
9
|
+
* has no file system) so that paths under `/bundle` read this registry and the rest go to `base`.
|
|
10
|
+
* The registry is the realm's, keyed by content hash, so bundles that share a realm share files.
|
|
11
|
+
*/
|
|
12
|
+
export const BUNDLE_DIR = "/bundle";
|
|
13
|
+
const REGISTRY = "__cellsBundleFiles";
|
|
14
|
+
/** The realm's `/bundle` files: name → bytes, or a function that makes them. */
|
|
15
|
+
export function bundleFiles() {
|
|
16
|
+
const g = globalThis;
|
|
17
|
+
g[REGISTRY] ??= new Map();
|
|
18
|
+
return g[REGISTRY];
|
|
19
|
+
}
|
|
20
|
+
/** Registers `/bundle/<name>` (what a rule module calls). Returns `bytes`. */
|
|
21
|
+
export function registerBundleFile(name, bytes) {
|
|
22
|
+
bundleFiles().set(name, bytes);
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
|
25
|
+
/** The file name under `/bundle` of `path` ("" for `/bundle` itself), or `undefined` elsewhere. */
|
|
26
|
+
function bundleName(path) {
|
|
27
|
+
let p;
|
|
28
|
+
if (typeof path === "string")
|
|
29
|
+
p = path;
|
|
30
|
+
else if (path instanceof URL) {
|
|
31
|
+
if (path.protocol !== "file:")
|
|
32
|
+
return undefined;
|
|
33
|
+
p = decodeURIComponent(path.pathname);
|
|
34
|
+
}
|
|
35
|
+
else if (path instanceof Uint8Array)
|
|
36
|
+
p = new TextDecoder().decode(path);
|
|
37
|
+
else
|
|
38
|
+
return undefined;
|
|
39
|
+
p = p.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
40
|
+
if (p === BUNDLE_DIR)
|
|
41
|
+
return "";
|
|
42
|
+
return p.startsWith(`${BUNDLE_DIR}/`) ? p.slice(BUNDLE_DIR.length + 1) : undefined;
|
|
43
|
+
}
|
|
44
|
+
const fsError = (code, syscall, path) => {
|
|
45
|
+
const text = code === "ENOENT"
|
|
46
|
+
? "no such file or directory"
|
|
47
|
+
: code === "EISDIR"
|
|
48
|
+
? "illegal operation on a directory"
|
|
49
|
+
: "not a directory";
|
|
50
|
+
return Object.assign(new Error(`${code}: ${text}, ${syscall} '${String(path)}'`), {
|
|
51
|
+
code,
|
|
52
|
+
syscall,
|
|
53
|
+
path: String(path),
|
|
54
|
+
errno: code === "ENOENT" ? -2 : code === "EISDIR" ? -21 : -20,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
function bytesOf(name, syscall, path) {
|
|
58
|
+
const entry = bundleFiles().get(name);
|
|
59
|
+
if (entry === undefined)
|
|
60
|
+
throw fsError("ENOENT", syscall, path);
|
|
61
|
+
return typeof entry === "function" ? entry() : entry;
|
|
62
|
+
}
|
|
63
|
+
/** Node's Buffer where the realm has one, as `readFileSync` returns; else the bytes. */
|
|
64
|
+
function buffer(bytes) {
|
|
65
|
+
const B = globalThis.Buffer;
|
|
66
|
+
return B ? B.from(bytes) : bytes.slice();
|
|
67
|
+
}
|
|
68
|
+
function decode(bytes, options) {
|
|
69
|
+
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
70
|
+
if (!encoding || encoding === "buffer")
|
|
71
|
+
return buffer(bytes);
|
|
72
|
+
const b = buffer(bytes);
|
|
73
|
+
return globalThis.Buffer && b.toString
|
|
74
|
+
? b.toString(encoding)
|
|
75
|
+
: new TextDecoder(encoding === "utf-8" ? "utf8" : encoding).decode(bytes);
|
|
76
|
+
}
|
|
77
|
+
const MTIME = new Date(0);
|
|
78
|
+
function stats(kind, size) {
|
|
79
|
+
return {
|
|
80
|
+
dev: 0,
|
|
81
|
+
ino: 0,
|
|
82
|
+
mode: kind === "dir" ? 0o40555 : 0o100444,
|
|
83
|
+
nlink: 1,
|
|
84
|
+
uid: 0,
|
|
85
|
+
gid: 0,
|
|
86
|
+
rdev: 0,
|
|
87
|
+
size,
|
|
88
|
+
blksize: 4096,
|
|
89
|
+
blocks: Math.ceil(size / 512),
|
|
90
|
+
atimeMs: 0,
|
|
91
|
+
mtimeMs: 0,
|
|
92
|
+
ctimeMs: 0,
|
|
93
|
+
birthtimeMs: 0,
|
|
94
|
+
atime: MTIME,
|
|
95
|
+
mtime: MTIME,
|
|
96
|
+
ctime: MTIME,
|
|
97
|
+
birthtime: MTIME,
|
|
98
|
+
isFile: () => kind === "file",
|
|
99
|
+
isDirectory: () => kind === "dir",
|
|
100
|
+
isSymbolicLink: () => false,
|
|
101
|
+
isBlockDevice: () => false,
|
|
102
|
+
isCharacterDevice: () => false,
|
|
103
|
+
isFIFO: () => false,
|
|
104
|
+
isSocket: () => false,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const dirent = (name) => ({
|
|
108
|
+
name,
|
|
109
|
+
parentPath: BUNDLE_DIR,
|
|
110
|
+
path: BUNDLE_DIR,
|
|
111
|
+
isFile: () => true,
|
|
112
|
+
isDirectory: () => false,
|
|
113
|
+
isSymbolicLink: () => false,
|
|
114
|
+
isBlockDevice: () => false,
|
|
115
|
+
isCharacterDevice: () => false,
|
|
116
|
+
isFIFO: () => false,
|
|
117
|
+
isSocket: () => false,
|
|
118
|
+
});
|
|
119
|
+
// The synchronous operations on `/bundle`, by name; each throws as Node's does.
|
|
120
|
+
const sync = {
|
|
121
|
+
existsSync: (name) => name === "" || bundleFiles().has(name),
|
|
122
|
+
readFileSync: (name, path, options) => {
|
|
123
|
+
if (name === "")
|
|
124
|
+
throw fsError("EISDIR", "read", path);
|
|
125
|
+
return decode(bytesOf(name, "open", path), options);
|
|
126
|
+
},
|
|
127
|
+
statSync: (name, path, options) => {
|
|
128
|
+
if (name === "")
|
|
129
|
+
return stats("dir", 0);
|
|
130
|
+
// `throwIfNoEntry: false`: a missing file is `undefined`, as libraries probing for one expect.
|
|
131
|
+
if (!bundleFiles().has(name) &&
|
|
132
|
+
options?.throwIfNoEntry === false)
|
|
133
|
+
return undefined;
|
|
134
|
+
return stats("file", bytesOf(name, "stat", path).byteLength);
|
|
135
|
+
},
|
|
136
|
+
readdirSync: (name, path, options) => {
|
|
137
|
+
if (name !== "") {
|
|
138
|
+
bytesOf(name, "scandir", path);
|
|
139
|
+
throw fsError("ENOTDIR", "scandir", path);
|
|
140
|
+
}
|
|
141
|
+
const names = [...bundleFiles().keys()].sort();
|
|
142
|
+
return options?.withFileTypes ? names.map(dirent) : names;
|
|
143
|
+
},
|
|
144
|
+
accessSync: (name, path) => {
|
|
145
|
+
if (name !== "" && !bundleFiles().has(name))
|
|
146
|
+
throw fsError("ENOENT", "access", path);
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* `base` (a `node:fs`) with `/bundle` paths answered from the registry: `existsSync`,
|
|
151
|
+
* `readFileSync`, `statSync`, `lstatSync`, `readdirSync`, `accessSync`, their callback forms and
|
|
152
|
+
* `promises`. Other paths, and every other function, are `base`'s.
|
|
153
|
+
*/
|
|
154
|
+
export function bundleFs(base) {
|
|
155
|
+
const over = (op, own) => function (path, ...rest) {
|
|
156
|
+
const name = bundleName(path);
|
|
157
|
+
if (name === undefined)
|
|
158
|
+
return own?.call(this, path, ...rest);
|
|
159
|
+
return sync[op](name, path, ...rest);
|
|
160
|
+
};
|
|
161
|
+
// Node's callback form: (path, [options], callback).
|
|
162
|
+
const callback = (op, own) => function (path, ...rest) {
|
|
163
|
+
const name = bundleName(path);
|
|
164
|
+
if (name === undefined)
|
|
165
|
+
return own?.call(this, path, ...rest);
|
|
166
|
+
const cb = rest.pop();
|
|
167
|
+
let result;
|
|
168
|
+
try {
|
|
169
|
+
result = sync[op](name, path, ...rest);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
return queueMicrotask(() => cb(e));
|
|
173
|
+
}
|
|
174
|
+
queueMicrotask(() => (op === "accessSync" ? cb(null) : cb(null, result)));
|
|
175
|
+
};
|
|
176
|
+
const p = (base.promises ?? {});
|
|
177
|
+
return {
|
|
178
|
+
existsSync: over("existsSync", base.existsSync),
|
|
179
|
+
readFileSync: over("readFileSync", base.readFileSync),
|
|
180
|
+
statSync: over("statSync", base.statSync),
|
|
181
|
+
lstatSync: over("statSync", base.lstatSync),
|
|
182
|
+
readdirSync: over("readdirSync", base.readdirSync),
|
|
183
|
+
accessSync: over("accessSync", base.accessSync),
|
|
184
|
+
readFile: callback("readFileSync", base.readFile),
|
|
185
|
+
stat: callback("statSync", base.stat),
|
|
186
|
+
lstat: callback("statSync", base.lstat),
|
|
187
|
+
readdir: callback("readdirSync", base.readdir),
|
|
188
|
+
access: callback("accessSync", base.access),
|
|
189
|
+
promises: bundleFsPromises(p),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** `node:fs/promises` with `/bundle` paths answered from the registry. */
|
|
193
|
+
export function bundleFsPromises(base) {
|
|
194
|
+
const promised = (op, own) => async function (path, ...rest) {
|
|
195
|
+
const name = bundleName(path);
|
|
196
|
+
if (name === undefined)
|
|
197
|
+
return own?.call(this, path, ...rest);
|
|
198
|
+
const result = sync[op](name, path, ...rest);
|
|
199
|
+
return op === "accessSync" ? undefined : result;
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
...base,
|
|
203
|
+
readFile: promised("readFileSync", base.readFile),
|
|
204
|
+
stat: promised("statSync", base.stat),
|
|
205
|
+
lstat: promised("statSync", base.lstat),
|
|
206
|
+
readdir: promised("readdirSync", base.readdir),
|
|
207
|
+
access: promised("accessSync", base.access),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=bundle-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-files.js","sourceRoot":"","sources":["../../src/node-compat/bundle-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAGpC,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AAEtC,gFAAgF;AAChF,MAAM,UAAU,WAAW;IACzB,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,CAAC,CAAC,QAAQ,CAAC,KAAK,IAAI,GAAG,EAAiB,CAAC;IACzC,OAAO,CAAC,CAAC,QAAQ,CAAuB,CAAC;AAC3C,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,kBAAkB,CAAkB,IAAY,EAAE,KAAQ;IACxE,WAAW,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,mGAAmG;AACnG,SAAS,UAAU,CAAC,IAAa;IAC/B,IAAI,CAAS,CAAC;IACd,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,CAAC,GAAG,IAAI,CAAC;SAClC,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO;YAAE,OAAO,SAAS,CAAC;QAChD,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;SAAM,IAAI,IAAI,YAAY,UAAU;QAAE,CAAC,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,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,GAAsB,EAAE,EAAE,CACjE,KAAK,WAA0B,IAAa,EAAE,GAAG,IAAe;QAC9D,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAI,IAAI,CAAC,EAAE,CAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,OAAO,EAAE,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IAClD,CAAC,CAAC;IACJ,OAAO;QACL,GAAG,IAAI;QACP,QAAQ,EAAE,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC;QACjD,IAAI,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC;QACvC,OAAO,EAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC;QAC9C,MAAM,EAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC;KAC5C,CAAC;AACJ,CAAC","sourcesContent":["/**\n * workerd's `/bundle` for `node:fs` (nodejs_compat): a read-only directory of the Worker's own\n * modules. wrangler uploads each non-JS module a bundle imports (a `.wasm`, a Text or Data file)\n * as a module named `<sha1 of its bytes>-<file name>`, and Worker code can read it there\n * (Kitesurf reads its wasm with `fs.readFileSync(\"/bundle/…\")`).\n *\n * The bundle's rule modules (module-rules.ts) register their bytes here when they are evaluated,\n * under the same names. `bundleFs(base)` wraps a `node:fs` (Node's own, or the browser's, which\n * has no file system) so that paths under `/bundle` read this registry and the rest go to `base`.\n * The registry is the realm's, keyed by content hash, so bundles that share a realm share files.\n */\n\nexport const BUNDLE_DIR = \"/bundle\";\n\ntype Entry = Uint8Array | (() => Uint8Array);\nconst REGISTRY = \"__cellsBundleFiles\";\n\n/** The realm's `/bundle` files: name → bytes, or a function that makes them. */\nexport function bundleFiles(): Map<string, Entry> {\n const g = globalThis as Record<string, unknown>;\n g[REGISTRY] ??= new Map<string, Entry>();\n return g[REGISTRY] as Map<string, Entry>;\n}\n\n/** Registers `/bundle/<name>` (what a rule module calls). Returns `bytes`. */\nexport function registerBundleFile<T extends Entry>(name: string, bytes: T): T {\n bundleFiles().set(name, bytes);\n return bytes;\n}\n\n/** The file name under `/bundle` of `path` (\"\" for `/bundle` itself), or `undefined` elsewhere. */\nfunction bundleName(path: unknown): string | undefined {\n let p: string;\n if (typeof path === \"string\") p = path;\n else if (path instanceof URL) {\n if (path.protocol !== \"file:\") return undefined;\n p = decodeURIComponent(path.pathname);\n } else if (path instanceof Uint8Array) p = new TextDecoder().decode(path);\n else return undefined;\n p = p.replace(/\\/+/g, \"/\").replace(/\\/$/, \"\");\n if (p === BUNDLE_DIR) return \"\";\n return p.startsWith(`${BUNDLE_DIR}/`) ? p.slice(BUNDLE_DIR.length + 1) : undefined;\n}\n\nconst fsError = (code: string, syscall: string, path: unknown) => {\n const text =\n code === \"ENOENT\"\n ? \"no such file or directory\"\n : code === \"EISDIR\"\n ? \"illegal operation on a directory\"\n : \"not a directory\";\n return Object.assign(new Error(`${code}: ${text}, ${syscall} '${String(path)}'`), {\n code,\n syscall,\n path: String(path),\n errno: code === \"ENOENT\" ? -2 : code === \"EISDIR\" ? -21 : -20,\n });\n};\n\nfunction bytesOf(name: string, syscall: string, path: unknown): Uint8Array {\n const entry = bundleFiles().get(name);\n if (entry === undefined) throw fsError(\"ENOENT\", syscall, path);\n return typeof entry === \"function\" ? entry() : entry;\n}\n\n/** Node's Buffer where the realm has one, as `readFileSync` returns; else the bytes. */\nfunction buffer(bytes: Uint8Array): Uint8Array {\n const B = (globalThis as { Buffer?: { from(b: Uint8Array): Uint8Array } }).Buffer;\n return B ? B.from(bytes) : bytes.slice();\n}\n\nfunction decode(bytes: Uint8Array, options: unknown): Uint8Array | string {\n const encoding =\n typeof options === \"string\" ? options : (options as { encoding?: string })?.encoding;\n if (!encoding || encoding === \"buffer\") return buffer(bytes);\n const b = buffer(bytes) as Uint8Array & { toString?(enc: string): string };\n return (globalThis as { Buffer?: unknown }).Buffer && b.toString\n ? b.toString(encoding)\n : new TextDecoder(encoding === \"utf-8\" ? \"utf8\" : encoding).decode(bytes);\n}\n\nconst MTIME = new Date(0);\nfunction stats(kind: \"file\" | \"dir\", size: number) {\n return {\n dev: 0,\n ino: 0,\n mode: kind === \"dir\" ? 0o40555 : 0o100444,\n nlink: 1,\n uid: 0,\n gid: 0,\n rdev: 0,\n size,\n blksize: 4096,\n blocks: Math.ceil(size / 512),\n atimeMs: 0,\n mtimeMs: 0,\n ctimeMs: 0,\n birthtimeMs: 0,\n atime: MTIME,\n mtime: MTIME,\n ctime: MTIME,\n birthtime: MTIME,\n isFile: () => kind === \"file\",\n isDirectory: () => kind === \"dir\",\n isSymbolicLink: () => false,\n isBlockDevice: () => false,\n isCharacterDevice: () => false,\n isFIFO: () => false,\n isSocket: () => false,\n };\n}\n\nconst dirent = (name: string) => ({\n name,\n parentPath: BUNDLE_DIR,\n path: BUNDLE_DIR,\n isFile: () => true,\n isDirectory: () => false,\n isSymbolicLink: () => false,\n isBlockDevice: () => false,\n isCharacterDevice: () => false,\n isFIFO: () => false,\n isSocket: () => false,\n});\n\n// The synchronous operations on `/bundle`, by name; each throws as Node's does.\nconst sync = {\n existsSync: (name: string) => name === \"\" || bundleFiles().has(name),\n readFileSync: (name: string, path: unknown, options?: unknown) => {\n if (name === \"\") throw fsError(\"EISDIR\", \"read\", path);\n return decode(bytesOf(name, \"open\", path), options);\n },\n statSync: (name: string, path: unknown, options?: unknown) => {\n if (name === \"\") return stats(\"dir\", 0);\n // `throwIfNoEntry: false`: a missing file is `undefined`, as libraries probing for one expect.\n if (\n !bundleFiles().has(name) &&\n (options as { throwIfNoEntry?: boolean })?.throwIfNoEntry === false\n )\n return undefined;\n return stats(\"file\", bytesOf(name, \"stat\", path).byteLength);\n },\n readdirSync: (name: string, path: unknown, options?: unknown) => {\n if (name !== \"\") {\n bytesOf(name, \"scandir\", path);\n throw fsError(\"ENOTDIR\", \"scandir\", path);\n }\n const names = [...bundleFiles().keys()].sort();\n return (options as { withFileTypes?: boolean })?.withFileTypes ? names.map(dirent) : names;\n },\n accessSync: (name: string, path: unknown) => {\n if (name !== \"\" && !bundleFiles().has(name)) throw fsError(\"ENOENT\", \"access\", path);\n },\n};\n\ntype AnyFn = (...args: any[]) => any;\n\n/**\n * `base` (a `node:fs`) with `/bundle` paths answered from the registry: `existsSync`,\n * `readFileSync`, `statSync`, `lstatSync`, `readdirSync`, `accessSync`, their callback forms and\n * `promises`. Other paths, and every other function, are `base`'s.\n */\nexport function bundleFs<T extends Record<string, any>>(base: T): Record<string, unknown> {\n const over = (op: keyof typeof sync, own: AnyFn | undefined) =>\n function (this: unknown, path: unknown, ...rest: unknown[]) {\n const name = bundleName(path);\n if (name === undefined) return own?.call(this, path, ...rest);\n return (sync[op] as AnyFn)(name, path, ...rest);\n };\n // Node's callback form: (path, [options], callback).\n const callback = (op: keyof typeof sync, own: AnyFn | undefined) =>\n function (this: unknown, path: unknown, ...rest: unknown[]) {\n const name = bundleName(path);\n if (name === undefined) return own?.call(this, path, ...rest);\n const cb = rest.pop() as AnyFn;\n let result: unknown;\n try {\n result = (sync[op] as AnyFn)(name, path, ...rest);\n } catch (e) {\n return queueMicrotask(() => cb(e));\n }\n queueMicrotask(() => (op === \"accessSync\" ? cb(null) : cb(null, result)));\n };\n const p = (base.promises ?? {}) as Record<string, AnyFn>;\n return {\n existsSync: over(\"existsSync\", base.existsSync),\n readFileSync: over(\"readFileSync\", base.readFileSync),\n statSync: over(\"statSync\", base.statSync),\n lstatSync: over(\"statSync\", base.lstatSync),\n readdirSync: over(\"readdirSync\", base.readdirSync),\n accessSync: over(\"accessSync\", base.accessSync),\n readFile: callback(\"readFileSync\", base.readFile),\n stat: callback(\"statSync\", base.stat),\n lstat: callback(\"statSync\", base.lstat),\n readdir: callback(\"readdirSync\", base.readdir),\n access: callback(\"accessSync\", base.access),\n promises: bundleFsPromises(p),\n };\n}\n\n/** `node:fs/promises` with `/bundle` paths answered from the registry. */\nexport function bundleFsPromises<T extends Record<string, any>>(base: T): Record<string, unknown> {\n const promised = (op: keyof typeof sync, own: AnyFn | undefined) =>\n async function (this: unknown, path: unknown, ...rest: unknown[]) {\n const name = bundleName(path);\n if (name === undefined) return own?.call(this, path, ...rest);\n const result = (sync[op] as AnyFn)(name, path, ...rest);\n return op === \"accessSync\" ? undefined : result;\n };\n return {\n ...base,\n readFile: promised(\"readFileSync\", base.readFile),\n stat: promised(\"statSync\", base.stat),\n lstat: promised(\"statSync\", base.lstat),\n readdir: promised(\"readdirSync\", base.readdir),\n access: promised(\"accessSync\", base.access),\n };\n}\n"]}
|
package/dist/node-compat/fs.d.ts
CHANGED
|
@@ -4,7 +4,13 @@ export declare const writeFileSync: (path?: unknown) => never;
|
|
|
4
4
|
export declare const statSync: (path?: unknown) => never;
|
|
5
5
|
export declare const lstatSync: (path?: unknown) => never;
|
|
6
6
|
export declare const readdirSync: (path?: unknown) => never;
|
|
7
|
+
export declare const accessSync: (path?: unknown) => never;
|
|
7
8
|
export declare const mkdirSync: (path?: unknown) => never;
|
|
9
|
+
export declare const readFile: (path: unknown, ...rest: unknown[]) => void;
|
|
10
|
+
export declare const stat: (path: unknown, ...rest: unknown[]) => void;
|
|
11
|
+
export declare const lstat: (path: unknown, ...rest: unknown[]) => void;
|
|
12
|
+
export declare const readdir: (path: unknown, ...rest: unknown[]) => void;
|
|
13
|
+
export declare const access: (path: unknown, ...rest: unknown[]) => void;
|
|
8
14
|
export declare const promises: {
|
|
9
15
|
readFile: (path?: unknown) => Promise<never>;
|
|
10
16
|
writeFile: (path?: unknown) => Promise<never>;
|
|
@@ -15,13 +21,19 @@ export declare const promises: {
|
|
|
15
21
|
access: (path?: unknown) => Promise<never>;
|
|
16
22
|
};
|
|
17
23
|
declare const _default: {
|
|
18
|
-
existsSync:
|
|
24
|
+
existsSync: (_path?: unknown) => boolean;
|
|
19
25
|
readFileSync: (path?: unknown) => never;
|
|
20
26
|
writeFileSync: (path?: unknown) => never;
|
|
21
27
|
statSync: (path?: unknown) => never;
|
|
22
28
|
lstatSync: (path?: unknown) => never;
|
|
23
29
|
readdirSync: (path?: unknown) => never;
|
|
30
|
+
accessSync: (path?: unknown) => never;
|
|
24
31
|
mkdirSync: (path?: unknown) => never;
|
|
32
|
+
readFile: (path: unknown, ...rest: unknown[]) => void;
|
|
33
|
+
stat: (path: unknown, ...rest: unknown[]) => void;
|
|
34
|
+
lstat: (path: unknown, ...rest: unknown[]) => void;
|
|
35
|
+
readdir: (path: unknown, ...rest: unknown[]) => void;
|
|
36
|
+
access: (path: unknown, ...rest: unknown[]) => void;
|
|
25
37
|
promises: {
|
|
26
38
|
readFile: (path?: unknown) => Promise<never>;
|
|
27
39
|
writeFile: (path?: unknown) => Promise<never>;
|
package/dist/node-compat/fs.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `node:fs` for browsers (nodejs_compat): there is no file system, so every call fails with
|
|
3
3
|
* `ENOENT` (as for a missing file) and `existsSync` is false. Code that probes for optional
|
|
4
|
-
* files, such as an SDK reading `/proc/self/environ` inside a `try`, keeps working.
|
|
4
|
+
* files, such as an SDK reading `/proc/self/environ` inside a `try`, keeps working. The one
|
|
5
|
+
* directory there is is workerd's `/bundle`, read-only: the bundle's own non-JS modules
|
|
6
|
+
* (bundle-files.ts).
|
|
5
7
|
*/
|
|
8
|
+
import { bundleFs } from "./bundle-files.js";
|
|
6
9
|
const missing = (op) => (path) => {
|
|
7
10
|
throw Object.assign(new Error(`ENOENT: no such file or directory, ${op} '${String(path)}'`), {
|
|
8
11
|
code: "ENOENT",
|
|
@@ -11,22 +14,52 @@ const missing = (op) => (path) => {
|
|
|
11
14
|
});
|
|
12
15
|
};
|
|
13
16
|
const missingAsync = (op) => async (path) => missing(op)(path);
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const missingCallback = (op) => (path, ...rest) => {
|
|
18
|
+
const cb = rest.pop();
|
|
19
|
+
try {
|
|
20
|
+
missing(op)(path);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
queueMicrotask(() => cb(e));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const none = {
|
|
27
|
+
existsSync: (_path) => false,
|
|
28
|
+
readFileSync: missing("open"),
|
|
29
|
+
statSync: missing("stat"),
|
|
30
|
+
lstatSync: missing("lstat"),
|
|
31
|
+
readdirSync: missing("scandir"),
|
|
32
|
+
accessSync: missing("access"),
|
|
33
|
+
readFile: missingCallback("open"),
|
|
34
|
+
stat: missingCallback("stat"),
|
|
35
|
+
lstat: missingCallback("lstat"),
|
|
36
|
+
readdir: missingCallback("scandir"),
|
|
37
|
+
access: missingCallback("access"),
|
|
38
|
+
promises: {
|
|
39
|
+
readFile: missingAsync("open"),
|
|
40
|
+
writeFile: missingAsync("open"),
|
|
41
|
+
stat: missingAsync("stat"),
|
|
42
|
+
lstat: missingAsync("lstat"),
|
|
43
|
+
readdir: missingAsync("scandir"),
|
|
44
|
+
mkdir: missingAsync("mkdir"),
|
|
45
|
+
access: missingAsync("access"),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const fs = bundleFs(none);
|
|
49
|
+
export const existsSync = fs.existsSync;
|
|
50
|
+
export const readFileSync = fs.readFileSync;
|
|
16
51
|
export const writeFileSync = missing("open");
|
|
17
|
-
export const statSync =
|
|
18
|
-
export const lstatSync =
|
|
19
|
-
export const readdirSync =
|
|
52
|
+
export const statSync = fs.statSync;
|
|
53
|
+
export const lstatSync = fs.lstatSync;
|
|
54
|
+
export const readdirSync = fs.readdirSync;
|
|
55
|
+
export const accessSync = fs.accessSync;
|
|
20
56
|
export const mkdirSync = missing("mkdir");
|
|
21
|
-
export const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
mkdir: missingAsync("mkdir"),
|
|
28
|
-
access: missingAsync("access"),
|
|
29
|
-
};
|
|
57
|
+
export const readFile = fs.readFile;
|
|
58
|
+
export const stat = fs.stat;
|
|
59
|
+
export const lstat = fs.lstat;
|
|
60
|
+
export const readdir = fs.readdir;
|
|
61
|
+
export const access = fs.access;
|
|
62
|
+
export const promises = fs.promises;
|
|
30
63
|
export default {
|
|
31
64
|
existsSync,
|
|
32
65
|
readFileSync,
|
|
@@ -34,7 +67,13 @@ export default {
|
|
|
34
67
|
statSync,
|
|
35
68
|
lstatSync,
|
|
36
69
|
readdirSync,
|
|
70
|
+
accessSync,
|
|
37
71
|
mkdirSync,
|
|
72
|
+
readFile,
|
|
73
|
+
stat,
|
|
74
|
+
lstat,
|
|
75
|
+
readdir,
|
|
76
|
+
access,
|
|
38
77
|
promises,
|
|
39
78
|
};
|
|
40
79
|
//# sourceMappingURL=fs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/node-compat/fs.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/node-compat/fs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,OAAO,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC,IAAc,EAAE,EAAE;IACjD,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,EAAE,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC3F,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE;QACX,IAAI;KACL,CAAC,CAAC;AACL,CAAC,CAAC;AACF,MAAM,YAAY,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s` for browsers (nodejs_compat): there is no file system, so every call fails with\n * `ENOENT` (as for a missing file) and `existsSync` is false. Code that probes for optional\n * files, such as an SDK reading `/proc/self/environ` inside a `try`, keeps working. The one\n * directory there is is workerd's `/bundle`, read-only: the bundle's own non-JS modules\n * (bundle-files.ts).\n */\nimport { bundleFs } from \"./bundle-files.js\";\n\nconst missing = (op: string) => (path?: unknown) => {\n throw Object.assign(new Error(`ENOENT: no such file or directory, ${op} '${String(path)}'`), {\n code: \"ENOENT\",\n syscall: op,\n path,\n });\n};\nconst missingAsync =\n (op: string) =>\n async (path?: unknown): Promise<never> =>\n missing(op)(path);\nconst missingCallback =\n (op: string) =>\n (path: unknown, ...rest: unknown[]) => {\n const cb = rest.pop() as (e: unknown) => void;\n try {\n missing(op)(path);\n } catch (e) {\n queueMicrotask(() => cb(e));\n }\n };\n\nconst none = {\n existsSync: (_path?: unknown) => false,\n readFileSync: missing(\"open\"),\n statSync: missing(\"stat\"),\n lstatSync: missing(\"lstat\"),\n readdirSync: missing(\"scandir\"),\n accessSync: missing(\"access\"),\n readFile: missingCallback(\"open\"),\n stat: missingCallback(\"stat\"),\n lstat: missingCallback(\"lstat\"),\n readdir: missingCallback(\"scandir\"),\n access: missingCallback(\"access\"),\n promises: {\n readFile: missingAsync(\"open\"),\n writeFile: missingAsync(\"open\"),\n stat: missingAsync(\"stat\"),\n lstat: missingAsync(\"lstat\"),\n readdir: missingAsync(\"scandir\"),\n mkdir: missingAsync(\"mkdir\"),\n access: missingAsync(\"access\"),\n },\n};\nconst fs = bundleFs(none) as typeof none;\n\nexport const existsSync = fs.existsSync;\nexport const readFileSync = fs.readFileSync;\nexport const writeFileSync = missing(\"open\");\nexport const statSync = fs.statSync;\nexport const lstatSync = fs.lstatSync;\nexport const readdirSync = fs.readdirSync;\nexport const accessSync = fs.accessSync;\nexport const mkdirSync = missing(\"mkdir\");\nexport const readFile = fs.readFile;\nexport const stat = fs.stat;\nexport const lstat = fs.lstat;\nexport const readdir = fs.readdir;\nexport const access = fs.access;\nexport const promises = fs.promises;\n\nexport default {\n existsSync,\n readFileSync,\n writeFileSync,\n statSync,\n lstatSync,\n readdirSync,\n accessSync,\n mkdirSync,\n readFile,\n stat,\n lstat,\n readdir,\n access,\n promises,\n};\n"]}
|
|
@@ -6,7 +6,7 @@ import { type ModuleLoader } from "../bindings/worker-loader.js";
|
|
|
6
6
|
* bundled with the Worker, so it declares no names beyond its exports: esbuild would rename the
|
|
7
7
|
* Worker's own variables of the same name, and those names show in error messages.
|
|
8
8
|
*/
|
|
9
|
-
export declare const PROJECT_WORKERS_MODULE_SHIM = "const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget; export default m; export const env = globalThis.__cellsProjectScope?.env ?? {}, exports = globalThis.__cellsProjectScope?.exports ?? {}, waitUntil = (p) => globalThis.__cellsProjectScope?.waitUntil(p);";
|
|
9
|
+
export declare const PROJECT_WORKERS_MODULE_SHIM = "const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget, abortIsolate = m.abortIsolate; export default m; export const env = globalThis.__cellsProjectScope?.env ?? {}, exports = globalThis.__cellsProjectScope?.exports ?? {}, waitUntil = (p) => globalThis.__cellsProjectScope?.waitUntil(p);";
|
|
10
10
|
/**
|
|
11
11
|
* Worker Loader in a browser realm: each module of a WorkerCode becomes a Blob-URL ES
|
|
12
12
|
* module. `cloudflare:workers` resolves to a shim reading the runtime's own classes from
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMPORT_FROM, prefixModule, resolveModuleName, routeDynamicImports, } from "../bindings/module-registry.js";
|
|
2
|
+
import { compileWasmModules, moduleText, outboundFetch, } from "../bindings/worker-loader.js";
|
|
2
3
|
import { ctxExports } from "../core/handles.js";
|
|
3
4
|
import { rewriteModuleSpecifiers } from "./module-specifiers.js";
|
|
4
5
|
import { workerScope } from "./worker-scope.js";
|
|
5
|
-
const WORKERS_CLASSES = "const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget; export default m;";
|
|
6
|
+
const WORKERS_CLASSES = "const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget, abortIsolate = m.abortIsolate; export default m;";
|
|
6
7
|
/**
|
|
7
8
|
* `cloudflare:workers` for a project's own bundle: the classes, and the project's `env` and
|
|
8
9
|
* `exports` from `globalThis.__cellsProjectScope` (set by `browserProjectRuntime`, and by
|
|
@@ -21,7 +22,8 @@ export const PROJECT_WORKERS_MODULE_SHIM = `${WORKERS_CLASSES} export const env
|
|
|
21
22
|
export function browserModuleLoader(workersModuleShim) {
|
|
22
23
|
const blob = (text) => URL.createObjectURL(new Blob([text], { type: "text/javascript" }));
|
|
23
24
|
const fixedShimUrl = workersModuleShim && blob(workersModuleShim);
|
|
24
|
-
return async (_id,
|
|
25
|
+
return async (_id, loaded, logs) => {
|
|
26
|
+
const code = await compileWasmModules(loaded);
|
|
25
27
|
const env = code.env ?? {};
|
|
26
28
|
const scope = fixedShimUrl ? undefined : workerScope(env);
|
|
27
29
|
let shimUrl = fixedShimUrl;
|
|
@@ -59,6 +61,24 @@ export function browserModuleLoader(workersModuleShim) {
|
|
|
59
61
|
g.__cellsOutbound[key] = outbound;
|
|
60
62
|
consolePrelude += `const fetch = globalThis.__cellsOutbound[${JSON.stringify(key)}];\n`;
|
|
61
63
|
}
|
|
64
|
+
// `import()` the Blob URLs cannot link (a computed specifier, a module's whole name) resolves
|
|
65
|
+
// against this load's modules at run time (module-registry.ts).
|
|
66
|
+
const names = new Set(Object.keys(code.modules));
|
|
67
|
+
const importsKey = `i${Math.random().toString(36).slice(2)}`;
|
|
68
|
+
const g = globalThis;
|
|
69
|
+
g.__cellsImports ??= {};
|
|
70
|
+
const imports = g.__cellsImports;
|
|
71
|
+
imports[importsKey] = (spec, importer) => {
|
|
72
|
+
const name = resolveModuleName(String(spec), importer, names);
|
|
73
|
+
return import(/* @vite-ignore */ name === undefined ? String(spec) : urlOf(name));
|
|
74
|
+
};
|
|
75
|
+
const routed = (name) => {
|
|
76
|
+
const text = source(name);
|
|
77
|
+
const out = routeDynamicImports(text, name);
|
|
78
|
+
return out === undefined
|
|
79
|
+
? text
|
|
80
|
+
: prefixModule(out, `const ${IMPORT_FROM} = globalThis.__cellsImports[${JSON.stringify(importsKey)}]; `);
|
|
81
|
+
};
|
|
62
82
|
const urls = new Map();
|
|
63
83
|
// Modules whose Blob URL is being made: a Blob URL exists only once its text (with its
|
|
64
84
|
// imports' URLs) does, so modules that import each other cannot be loaded this way.
|
|
@@ -67,7 +87,7 @@ export function browserModuleLoader(workersModuleShim) {
|
|
|
67
87
|
const m = code.modules[name];
|
|
68
88
|
if (m === undefined)
|
|
69
89
|
throw new Error(`Worker Loader: module "${name}" not found`);
|
|
70
|
-
return moduleText(m);
|
|
90
|
+
return moduleText(m, name, names);
|
|
71
91
|
};
|
|
72
92
|
const urlOf = (name) => {
|
|
73
93
|
const known = urls.get(name);
|
|
@@ -79,7 +99,7 @@ export function browserModuleLoader(workersModuleShim) {
|
|
|
79
99
|
const base = name.includes("/") ? name.slice(0, name.lastIndexOf("/") + 1) : "";
|
|
80
100
|
// Only the module's own imports: the same words in a string, a template or a comment are
|
|
81
101
|
// not imports (a code generator's template may well contain `from "cloudflare:workers"`).
|
|
82
|
-
const text = rewriteModuleSpecifiers(
|
|
102
|
+
const text = rewriteModuleSpecifiers(routed(name), (spec) => {
|
|
83
103
|
if (spec === "cloudflare:workers")
|
|
84
104
|
return shimUrl;
|
|
85
105
|
if (spec.startsWith("./")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{\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n type WorkerCode,\n} from \"../bindings/worker-loader.js\";\nimport { ctxExports } from \"../core/handles.js\";\nimport { rewriteModuleSpecifiers } from \"./module-specifiers.js\";\nimport { workerScope } from \"./worker-scope.js\";\n\nconst WORKERS_CLASSES =\n \"const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget; export default m;\";\n\n/**\n * `cloudflare:workers` for a project's own bundle: the classes, and the project's `env` and\n * `exports` from `globalThis.__cellsProjectScope` (set by `browserProjectRuntime`, and by\n * `serveIsolate` for the loaded Worker an isolate runs). The shim is\n * bundled with the Worker, so it declares no names beyond its exports: esbuild would rename the\n * Worker's own variables of the same name, and those names show in error messages.\n */\nexport const PROJECT_WORKERS_MODULE_SHIM = `${WORKERS_CLASSES} export const env = globalThis.__cellsProjectScope?.env ?? {}, exports = globalThis.__cellsProjectScope?.exports ?? {}, waitUntil = (p) => globalThis.__cellsProjectScope?.waitUntil(p);`;\n\n/**\n * Worker Loader in a browser realm: each module of a WorkerCode becomes a Blob-URL ES\n * module. `cloudflare:workers` resolves to a shim reading the runtime's own classes from\n * `globalThis.__cellsWorkersModule` and the loaded code's own `env` and `exports` (or to\n * `workersModuleShim`, the same for every load); relative imports resolve to the Blob URLs of\n * sibling modules; with a log sink the module gets a module-scoped `console` (Tail Workers).\n */\nexport function browserModuleLoader(workersModuleShim?: string): ModuleLoader {\n const blob = (text: string) => URL.createObjectURL(new Blob([text], { type: \"text/javascript\" }));\n const fixedShimUrl = workersModuleShim && blob(workersModuleShim);\n return async (_id: string, code: WorkerCode, logs?: LogSink) => {\n const env = code.env ?? {};\n const scope = fixedShimUrl ? undefined : workerScope(env);\n let shimUrl = fixedShimUrl;\n if (scope) {\n const key = `s${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsWorkerScopes ??= {};\n (g.__cellsWorkerScopes as Record<string, unknown>)[key] = scope;\n shimUrl = blob(\n `${WORKERS_CLASSES} const s = globalThis.__cellsWorkerScopes[${JSON.stringify(key)}]; export const env = s.env, exports = s.exports, waitUntil = s.waitUntil;`,\n );\n }\n let consolePrelude = \"\";\n if (logs) {\n const key = `c${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsConsoles ??= {};\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n (g.__cellsConsoles as Record<string, unknown>)[key] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n consolePrelude = `const console = globalThis.__cellsConsoles[${JSON.stringify(key)}];\\n`;\n }\n const outbound = outboundFetch(code);\n if (outbound) {\n const key = `o${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsOutbound ??= {};\n (g.__cellsOutbound as Record<string, unknown>)[key] = outbound;\n consolePrelude += `const fetch = globalThis.__cellsOutbound[${JSON.stringify(key)}];\\n`;\n }\n const urls = new Map<string, string>();\n // Modules whose Blob URL is being made: a Blob URL exists only once its text (with its\n // imports' URLs) does, so modules that import each other cannot be loaded this way.\n const making: string[] = [];\n const source = (name: string) => {\n const m = code.modules[name];\n if (m === undefined) throw new Error(`Worker Loader: module \"${name}\" not found`);\n return moduleText(m);\n };\n const urlOf = (name: string): string => {\n const known = urls.get(name);\n if (known) return known;\n if (making.includes(name))\n throw new Error(\n `Worker Loader: modules import each other (${[...making.slice(making.indexOf(name)), name].join(\" → \")}); a browser realm loads each module from a Blob URL, which cannot form a cycle`,\n );\n making.push(name);\n const base = name.includes(\"/\") ? name.slice(0, name.lastIndexOf(\"/\") + 1) : \"\";\n // Only the module's own imports: the same words in a string, a template or a comment are\n // not imports (a code generator's template may well contain `from \"cloudflare:workers\"`).\n const text = rewriteModuleSpecifiers(source(name), (spec) => {\n if (spec === \"cloudflare:workers\") return shimUrl;\n if (spec.startsWith(\"./\") || spec.startsWith(\"../\"))\n return urlOf(new URL(spec, `file:///${base}`).pathname.slice(1));\n return undefined;\n });\n const url = URL.createObjectURL(\n new Blob([consolePrelude + text], { type: \"text/javascript\" }),\n );\n urls.set(name, url);\n making.pop();\n return url;\n };\n const module = (await import(/* @vite-ignore */ urlOf(code.mainModule))) as Record<\n string,\n unknown\n >;\n scope?.bind({ env, exports: ctxExports(module, env) });\n return module;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-modules.js","sourceRoot":"","sources":["../../src/project/browser-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,kBAAkB,EAGlB,UAAU,EACV,aAAa,GAEd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,eAAe,GACnB,sPAAsP,CAAC;AAEzP;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,eAAe,0LAA0L,CAAC;AAExP;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,iBAA0B;IAC5D,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAClG,MAAM,YAAY,GAAG,iBAAiB,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC;IA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AI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,EAAE,CAAC;YACb,OAAO,GAAG,CAAC;QACb,CAAC,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAGtE,CAAC;QACF,KAAK,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n IMPORT_FROM,\n prefixModule,\n resolveModuleName,\n routeDynamicImports,\n} from \"../bindings/module-registry.js\";\nimport {\n compileWasmModules,\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n type WorkerCode,\n} from \"../bindings/worker-loader.js\";\nimport { ctxExports } from \"../core/handles.js\";\nimport { rewriteModuleSpecifiers } from \"./module-specifiers.js\";\nimport { workerScope } from \"./worker-scope.js\";\n\nconst WORKERS_CLASSES =\n \"const m = globalThis.__cellsWorkersModule; export const DurableObject = m.DurableObject, WorkerEntrypoint = m.WorkerEntrypoint, WorkflowEntrypoint = m.WorkflowEntrypoint, RpcTarget = m.RpcTarget, abortIsolate = m.abortIsolate; export default m;\";\n\n/**\n * `cloudflare:workers` for a project's own bundle: the classes, and the project's `env` and\n * `exports` from `globalThis.__cellsProjectScope` (set by `browserProjectRuntime`, and by\n * `serveIsolate` for the loaded Worker an isolate runs). The shim is\n * bundled with the Worker, so it declares no names beyond its exports: esbuild would rename the\n * Worker's own variables of the same name, and those names show in error messages.\n */\nexport const PROJECT_WORKERS_MODULE_SHIM = `${WORKERS_CLASSES} export const env = globalThis.__cellsProjectScope?.env ?? {}, exports = globalThis.__cellsProjectScope?.exports ?? {}, waitUntil = (p) => globalThis.__cellsProjectScope?.waitUntil(p);`;\n\n/**\n * Worker Loader in a browser realm: each module of a WorkerCode becomes a Blob-URL ES\n * module. `cloudflare:workers` resolves to a shim reading the runtime's own classes from\n * `globalThis.__cellsWorkersModule` and the loaded code's own `env` and `exports` (or to\n * `workersModuleShim`, the same for every load); relative imports resolve to the Blob URLs of\n * sibling modules; with a log sink the module gets a module-scoped `console` (Tail Workers).\n */\nexport function browserModuleLoader(workersModuleShim?: string): ModuleLoader {\n const blob = (text: string) => URL.createObjectURL(new Blob([text], { type: \"text/javascript\" }));\n const fixedShimUrl = workersModuleShim && blob(workersModuleShim);\n return async (_id: string, loaded: WorkerCode, logs?: LogSink) => {\n const code = await compileWasmModules(loaded);\n const env = code.env ?? {};\n const scope = fixedShimUrl ? undefined : workerScope(env);\n let shimUrl = fixedShimUrl;\n if (scope) {\n const key = `s${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsWorkerScopes ??= {};\n (g.__cellsWorkerScopes as Record<string, unknown>)[key] = scope;\n shimUrl = blob(\n `${WORKERS_CLASSES} const s = globalThis.__cellsWorkerScopes[${JSON.stringify(key)}]; export const env = s.env, exports = s.exports, waitUntil = s.waitUntil;`,\n );\n }\n let consolePrelude = \"\";\n if (logs) {\n const key = `c${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsConsoles ??= {};\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n (g.__cellsConsoles as Record<string, unknown>)[key] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n consolePrelude = `const console = globalThis.__cellsConsoles[${JSON.stringify(key)}];\\n`;\n }\n const outbound = outboundFetch(code);\n if (outbound) {\n const key = `o${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsOutbound ??= {};\n (g.__cellsOutbound as Record<string, unknown>)[key] = outbound;\n consolePrelude += `const fetch = globalThis.__cellsOutbound[${JSON.stringify(key)}];\\n`;\n }\n // `import()` the Blob URLs cannot link (a computed specifier, a module's whole name) resolves\n // against this load's modules at run time (module-registry.ts).\n const names = new Set(Object.keys(code.modules));\n const importsKey = `i${Math.random().toString(36).slice(2)}`;\n const g = globalThis as Record<string, unknown>;\n g.__cellsImports ??= {};\n const imports = g.__cellsImports as Record<string, unknown>;\n imports[importsKey] = (spec: unknown, importer: string) => {\n const name = resolveModuleName(String(spec), importer, names);\n return import(/* @vite-ignore */ name === undefined ? String(spec) : urlOf(name));\n };\n const routed = (name: string) => {\n const text = source(name);\n const out = routeDynamicImports(text, name);\n return out === undefined\n ? text\n : prefixModule(\n out,\n `const ${IMPORT_FROM} = globalThis.__cellsImports[${JSON.stringify(importsKey)}]; `,\n );\n };\n const urls = new Map<string, string>();\n // Modules whose Blob URL is being made: a Blob URL exists only once its text (with its\n // imports' URLs) does, so modules that import each other cannot be loaded this way.\n const making: string[] = [];\n const source = (name: string) => {\n const m = code.modules[name];\n if (m === undefined) throw new Error(`Worker Loader: module \"${name}\" not found`);\n return moduleText(m, name, names);\n };\n const urlOf = (name: string): string => {\n const known = urls.get(name);\n if (known) return known;\n if (making.includes(name))\n throw new Error(\n `Worker Loader: modules import each other (${[...making.slice(making.indexOf(name)), name].join(\" → \")}); a browser realm loads each module from a Blob URL, which cannot form a cycle`,\n );\n making.push(name);\n const base = name.includes(\"/\") ? name.slice(0, name.lastIndexOf(\"/\") + 1) : \"\";\n // Only the module's own imports: the same words in a string, a template or a comment are\n // not imports (a code generator's template may well contain `from \"cloudflare:workers\"`).\n const text = rewriteModuleSpecifiers(routed(name), (spec) => {\n if (spec === \"cloudflare:workers\") return shimUrl;\n if (spec.startsWith(\"./\") || spec.startsWith(\"../\"))\n return urlOf(new URL(spec, `file:///${base}`).pathname.slice(1));\n return undefined;\n });\n const url = URL.createObjectURL(\n new Blob([consolePrelude + text], { type: \"text/javascript\" }),\n );\n urls.set(name, url);\n making.pop();\n return url;\n };\n const module = (await import(/* @vite-ignore */ urlOf(code.mainModule))) as Record<\n string,\n unknown\n >;\n scope?.bind({ env, exports: ctxExports(module, env) });\n return module;\n };\n}\n"]}
|
|
@@ -10,3 +10,12 @@ export declare class WorkflowEntrypoint<Env = unknown> {
|
|
|
10
10
|
constructor(ctx: unknown, env: Env);
|
|
11
11
|
}
|
|
12
12
|
export { RpcTarget } from "../core/durable-object.js";
|
|
13
|
+
/** Where an isolate's runtime installs what `abortIsolate` does there (src/isolate/isolate.ts). */
|
|
14
|
+
export declare const ABORT_ISOLATE: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* workerd's `abortIsolate(reason)`: ends the isolate the calling code runs in, and never returns.
|
|
17
|
+
* In a loaded Worker's isolate, the host terminates it: calls in flight reject, and the next
|
|
18
|
+
* `get()` of its id loads the code again. Elsewhere (a project's own realm, a loaded Worker in
|
|
19
|
+
* the project's realm) there is no isolate of its own to end, so the call only throws.
|
|
20
|
+
*/
|
|
21
|
+
export declare function abortIsolate(reason?: unknown): never;
|
|
@@ -13,4 +13,18 @@ export class WorkflowEntrypoint {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export { RpcTarget } from "../core/durable-object.js";
|
|
16
|
+
/** Where an isolate's runtime installs what `abortIsolate` does there (src/isolate/isolate.ts). */
|
|
17
|
+
export const ABORT_ISOLATE = Symbol.for("cellb.abort-isolate");
|
|
18
|
+
/**
|
|
19
|
+
* workerd's `abortIsolate(reason)`: ends the isolate the calling code runs in, and never returns.
|
|
20
|
+
* In a loaded Worker's isolate, the host terminates it: calls in flight reject, and the next
|
|
21
|
+
* `get()` of its id loads the code again. Elsewhere (a project's own realm, a loaded Worker in
|
|
22
|
+
* the project's realm) there is no isolate of its own to end, so the call only throws.
|
|
23
|
+
*/
|
|
24
|
+
export function abortIsolate(reason) {
|
|
25
|
+
const abort = globalThis[ABORT_ISOLATE];
|
|
26
|
+
if (abort)
|
|
27
|
+
return abort(reason);
|
|
28
|
+
throw new Error(`abortIsolate(${String(reason ?? "")}): this code runs in no isolate of its own (cellb runs only loaded Workers in isolates)`);
|
|
29
|
+
}
|
|
16
30
|
//# sourceMappingURL=cloudflare-workers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare-workers.js","sourceRoot":"","sources":["../../src/project/cloudflare-workers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,2FAA2F;AAC3F,MAAM,OAAO,kBAAkB;IACnB,GAAG,CAAU;IACb,GAAG,CAAM;IACnB,YAAY,GAAY,EAAE,GAAQ;QAChC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["/**\n * The `cloudflare:workers` module for Worker code run by cellb (mapped by the\n * bundler / webrun-modules). Exposes the classes Workers code imports.\n */\nexport { DurableObject, WorkerEntrypoint } from \"../core/durable-object.js\";\n\n/** Base class of Workflows (`class X extends WorkflowEntrypoint { run(event, step) }`). */\nexport class WorkflowEntrypoint<Env = unknown> {\n protected ctx: unknown;\n protected env: Env;\n constructor(ctx: unknown, env: Env) {\n this.ctx = ctx;\n this.env = env;\n }\n}\n\nexport { RpcTarget } from \"../core/durable-object.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"cloudflare-workers.js","sourceRoot":"","sources":["../../src/project/cloudflare-workers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,2FAA2F;AAC3F,MAAM,OAAO,kBAAkB;IACnB,GAAG,CAAU;IACb,GAAG,CAAM;IACnB,YAAY,GAAY,EAAE,GAAQ;QAChC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,mGAAmG;AACnG,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAgB;IAC3C,MAAM,KAAK,GAAI,UAAkE,CAAC,aAAa,CAAC,CAAC;IACjG,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,IAAI,KAAK,CACb,gBAAgB,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,yFAAyF,CAC9H,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The `cloudflare:workers` module for Worker code run by cellb (mapped by the\n * bundler / webrun-modules). Exposes the classes Workers code imports.\n */\nexport { DurableObject, WorkerEntrypoint } from \"../core/durable-object.js\";\n\n/** Base class of Workflows (`class X extends WorkflowEntrypoint { run(event, step) }`). */\nexport class WorkflowEntrypoint<Env = unknown> {\n protected ctx: unknown;\n protected env: Env;\n constructor(ctx: unknown, env: Env) {\n this.ctx = ctx;\n this.env = env;\n }\n}\n\nexport { RpcTarget } from \"../core/durable-object.js\";\n\n/** Where an isolate's runtime installs what `abortIsolate` does there (src/isolate/isolate.ts). */\nexport const ABORT_ISOLATE = Symbol.for(\"cellb.abort-isolate\");\n\n/**\n * workerd's `abortIsolate(reason)`: ends the isolate the calling code runs in, and never returns.\n * In a loaded Worker's isolate, the host terminates it: calls in flight reject, and the next\n * `get()` of its id loads the code again. Elsewhere (a project's own realm, a loaded Worker in\n * the project's realm) there is no isolate of its own to end, so the call only throws.\n */\nexport function abortIsolate(reason?: unknown): never {\n const abort = (globalThis as Record<symbol, ((r: unknown) => never) | undefined>)[ABORT_ISOLATE];\n if (abort) return abort(reason);\n throw new Error(\n `abortIsolate(${String(reason ?? \"\")}): this code runs in no isolate of its own (cellb runs only loaded Workers in isolates)`,\n );\n}\n"]}
|