export-runtime 0.0.7 → 0.0.8
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/bin/generate-types.mjs +1 -5
- package/client.js +0 -14
- package/handler.js +2 -6
- package/package.json +1 -1
- package/rpc.js +0 -28
- package/shared-do.js +0 -4
package/bin/generate-types.mjs
CHANGED
|
@@ -212,11 +212,7 @@ for (const node of program.body) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
lines.push("export declare function createUploadStream(): Promise<{");
|
|
217
|
-
lines.push(" stream: WritableStream<any>;");
|
|
218
|
-
lines.push(" writableId: number;");
|
|
219
|
-
lines.push("}>;");
|
|
215
|
+
|
|
220
216
|
|
|
221
217
|
const typeDefinitions = lines.join("\n");
|
|
222
218
|
|
package/client.js
CHANGED
|
@@ -135,14 +135,6 @@ const sendRequest = async (msg) => {
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
const makeWritable = (writableId) => new WritableStream({
|
|
139
|
-
async write(chunk) {
|
|
140
|
-
await sendRequest({ type: "writable-write", writableId, chunk: chunk instanceof Uint8Array ? Array.from(chunk) : chunk });
|
|
141
|
-
},
|
|
142
|
-
async close() { await sendRequest({ type: "writable-close", writableId }); },
|
|
143
|
-
async abort() { await sendRequest({ type: "writable-abort", writableId }); }
|
|
144
|
-
});
|
|
145
|
-
|
|
146
138
|
ws.onmessage = (event) => {
|
|
147
139
|
const msg = parse(event.data);
|
|
148
140
|
const resolver = pending.get(msg.id);
|
|
@@ -166,7 +158,6 @@ ws.onmessage = (event) => {
|
|
|
166
158
|
},
|
|
167
159
|
cancel: () => sendRequest({ type: "stream-cancel", streamId: msg.streamId })
|
|
168
160
|
}));
|
|
169
|
-
else if (msg.valueType === "writablestream") resolver.resolve(makeWritable(msg.writableId));
|
|
170
161
|
else resolver.resolve(msg.value);
|
|
171
162
|
} else if (msg.type === "iterate-result") {
|
|
172
163
|
resolver.resolve({ value: msg.value, done: msg.done });
|
|
@@ -199,11 +190,6 @@ export const createProxy = (path = []) => new Proxy(function(){}, {
|
|
|
199
190
|
async apply(_, __, args) { return sendRequest({ type: "call", path, args }); },
|
|
200
191
|
construct(_, args) { return sendRequest({ type: "construct", path, args }); }
|
|
201
192
|
});
|
|
202
|
-
|
|
203
|
-
export const createUploadStream = async () => {
|
|
204
|
-
const { writableId } = await sendRequest({ type: "writable-create" });
|
|
205
|
-
return { stream: makeWritable(writableId), writableId };
|
|
206
|
-
};
|
|
207
193
|
`;
|
|
208
194
|
|
|
209
195
|
export const CORE_CODE = CORE_TEMPLATE.replace("__WS_SUFFIX__", "./");
|
package/handler.js
CHANGED
|
@@ -27,14 +27,14 @@ export const createHandler = (exports, generatedTypes, minifiedCore, coreId, min
|
|
|
27
27
|
.join("\n");
|
|
28
28
|
|
|
29
29
|
const buildIndexModule = (cpath) =>
|
|
30
|
-
`import { createProxy
|
|
30
|
+
`import { createProxy } from ".${cpath}";\n${namedExportsCode}`;
|
|
31
31
|
|
|
32
32
|
const buildExportModule = (cpath, name) =>
|
|
33
33
|
`import { createProxy } from ".${cpath}";\nconst _export = createProxy([${JSON.stringify(name)}]);\nexport default _export;\nexport { _export as ${name} };`;
|
|
34
34
|
|
|
35
35
|
// Dispatch a parsed devalue message to an RPC dispatcher
|
|
36
36
|
const dispatchMessage = async (dispatcher, msg) => {
|
|
37
|
-
const { type, path = [], args = [], instanceId, iteratorId, streamId
|
|
37
|
+
const { type, path = [], args = [], instanceId, iteratorId, streamId } = msg;
|
|
38
38
|
switch (type) {
|
|
39
39
|
case "ping": return { type: "pong" };
|
|
40
40
|
case "call":
|
|
@@ -49,10 +49,6 @@ export const createHandler = (exports, generatedTypes, minifiedCore, coreId, min
|
|
|
49
49
|
case "iterate-return": return dispatcher.rpcIterateReturn(iteratorId);
|
|
50
50
|
case "stream-read": return dispatcher.rpcStreamRead(streamId);
|
|
51
51
|
case "stream-cancel": return dispatcher.rpcStreamCancel(streamId);
|
|
52
|
-
case "writable-create": return dispatcher.rpcWritableCreate();
|
|
53
|
-
case "writable-write": return dispatcher.rpcWritableWrite(writableId, chunk);
|
|
54
|
-
case "writable-close": return dispatcher.rpcWritableClose(writableId);
|
|
55
|
-
case "writable-abort": return dispatcher.rpcWritableAbort(writableId);
|
|
56
52
|
}
|
|
57
53
|
};
|
|
58
54
|
|
package/package.json
CHANGED
package/rpc.js
CHANGED
|
@@ -19,14 +19,12 @@ export const isClass = (fn) =>
|
|
|
19
19
|
export const RPC_METHODS = [
|
|
20
20
|
"rpcCall", "rpcConstruct", "rpcInstanceCall", "rpcGet", "rpcSet", "rpcRelease",
|
|
21
21
|
"rpcIterateNext", "rpcIterateReturn", "rpcStreamRead", "rpcStreamCancel",
|
|
22
|
-
"rpcWritableCreate", "rpcWritableWrite", "rpcWritableClose", "rpcWritableAbort",
|
|
23
22
|
];
|
|
24
23
|
|
|
25
24
|
export function createRpcDispatcher(exports) {
|
|
26
25
|
const instances = new Map();
|
|
27
26
|
const iterators = new Map();
|
|
28
27
|
const streams = new Map();
|
|
29
|
-
const writables = new Map();
|
|
30
28
|
let nextId = 1;
|
|
31
29
|
|
|
32
30
|
const requireInstance = (id) => {
|
|
@@ -126,36 +124,10 @@ export function createRpcDispatcher(exports) {
|
|
|
126
124
|
return { type: "result", value: true };
|
|
127
125
|
},
|
|
128
126
|
|
|
129
|
-
async rpcWritableCreate() {
|
|
130
|
-
const id = nextId++;
|
|
131
|
-
writables.set(id, { chunks: [] });
|
|
132
|
-
return { type: "result", writableId: id, valueType: "writablestream" };
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
async rpcWritableWrite(writableId, chunk) {
|
|
136
|
-
const entry = writables.get(writableId);
|
|
137
|
-
if (!entry) throw new Error("WritableStream not found");
|
|
138
|
-
entry.chunks.push(Array.isArray(chunk) ? new Uint8Array(chunk) : chunk);
|
|
139
|
-
return { type: "result", value: true };
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
async rpcWritableClose(writableId) {
|
|
143
|
-
const entry = writables.get(writableId);
|
|
144
|
-
if (!entry) throw new Error("WritableStream not found");
|
|
145
|
-
writables.delete(writableId);
|
|
146
|
-
return { type: "result", value: entry.chunks };
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
async rpcWritableAbort(writableId) {
|
|
150
|
-
writables.delete(writableId);
|
|
151
|
-
return { type: "result", value: true };
|
|
152
|
-
},
|
|
153
|
-
|
|
154
127
|
clearAll() {
|
|
155
128
|
instances.clear();
|
|
156
129
|
iterators.clear();
|
|
157
130
|
streams.clear();
|
|
158
|
-
writables.clear();
|
|
159
131
|
},
|
|
160
132
|
};
|
|
161
133
|
}
|
package/shared-do.js
CHANGED
|
@@ -18,8 +18,4 @@ export class SharedExportDO extends DurableObject {
|
|
|
18
18
|
rpcIterateReturn(i) { return this.#d.rpcIterateReturn(i); }
|
|
19
19
|
rpcStreamRead(s) { return this.#d.rpcStreamRead(s); }
|
|
20
20
|
rpcStreamCancel(s) { return this.#d.rpcStreamCancel(s); }
|
|
21
|
-
rpcWritableCreate() { return this.#d.rpcWritableCreate(); }
|
|
22
|
-
rpcWritableWrite(w, c) { return this.#d.rpcWritableWrite(w, c); }
|
|
23
|
-
rpcWritableClose(w) { return this.#d.rpcWritableClose(w); }
|
|
24
|
-
rpcWritableAbort(w) { return this.#d.rpcWritableAbort(w); }
|
|
25
21
|
}
|