exoagent 0.0.1 → 0.0.2
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 +109 -30
- package/dist/capnweb/index-workers.cjs +2811 -0
- package/dist/capnweb/index-workers.cjs.map +1 -0
- package/dist/capnweb/index-workers.d.cts +2 -0
- package/dist/capnweb/index-workers.d.ts +2 -0
- package/dist/capnweb/index-workers.js +2774 -0
- package/dist/capnweb/index-workers.js.map +1 -0
- package/dist/capnweb/index.cjs +2788 -0
- package/dist/capnweb/index.cjs.map +1 -0
- package/dist/capnweb/index.d.cts +383 -0
- package/dist/capnweb/index.d.ts +383 -0
- package/dist/{code-mode-runtime.mjs → capnweb/index.js} +342 -90
- package/dist/capnweb/index.js.map +1 -0
- package/dist/capnweb-test-helpers.d.ts +25 -0
- package/dist/code-mode-deno.d.ts +13 -0
- package/dist/code-mode-runtime.d.ts +1 -0
- package/dist/code-mode.d.ts +39 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +97 -3391
- package/dist/rpc-toolset-BnC2BXPq.js +146 -0
- package/dist/rpc-toolset-test-helpers.d.mts +11 -2
- package/dist/rpc-toolset-test-helpers.d.ts +45 -0
- package/dist/rpc-toolset-test-helpers.mjs +12 -1371
- package/dist/rpc-toolset.d.ts +34 -0
- package/dist/sql/builder.d.ts +127 -0
- package/dist/sql/expression.d.ts +69 -0
- package/dist/sql/sql.d.ts +4 -0
- package/dist/sql/test-helpers.d.ts +9 -0
- package/dist/sql.d.ts +2 -0
- package/dist/sql.mjs +553 -0
- package/dist/stream-transport.d.ts +11 -0
- package/dist/tool-wrapper.d.ts +16 -0
- package/package.json +26 -12
- package/dist/index.d.mts +0 -426
|
@@ -1,1378 +1,10 @@
|
|
|
1
1
|
import { a as or, c as F, d as R, f as T, g as x, h as u, l as L, m as h, n as Vr, p as U, r as ce, s as ur, t as C, u as P } from "./chunk-VBDAOXYI-BhoIkhUn.mjs";
|
|
2
2
|
import z$1, { z } from "zod";
|
|
3
3
|
import { inspect } from "node:util";
|
|
4
|
+
import { RpcTarget } from "capnweb";
|
|
4
5
|
import { CompiledQuery, DummyDriver, Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, sql } from "kysely";
|
|
5
6
|
import invariant from "tiny-invariant";
|
|
6
7
|
|
|
7
|
-
//#region packages/capnweb/dist/index.js
|
|
8
|
-
var WORKERS_MODULE_SYMBOL = /* @__PURE__ */ Symbol("workers-module");
|
|
9
|
-
if (!Symbol.dispose) Symbol.dispose = /* @__PURE__ */ Symbol.for("dispose");
|
|
10
|
-
if (!Symbol.asyncDispose) Symbol.asyncDispose = /* @__PURE__ */ Symbol.for("asyncDispose");
|
|
11
|
-
if (!Promise.withResolvers) Promise.withResolvers = function() {
|
|
12
|
-
let resolve;
|
|
13
|
-
let reject;
|
|
14
|
-
return {
|
|
15
|
-
promise: new Promise((res, rej) => {
|
|
16
|
-
resolve = res;
|
|
17
|
-
reject = rej;
|
|
18
|
-
}),
|
|
19
|
-
resolve,
|
|
20
|
-
reject
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
var workersModule = globalThis[WORKERS_MODULE_SYMBOL];
|
|
24
|
-
var RpcTarget = workersModule ? workersModule.RpcTarget : class {};
|
|
25
|
-
var AsyncFunction = (async function() {}).constructor;
|
|
26
|
-
var getGlobalRpcSessionOptions = () => ({});
|
|
27
|
-
var CALLBACK_CLEANUP = /* @__PURE__ */ Symbol("callback-cleanup");
|
|
28
|
-
function typeForRpc(value) {
|
|
29
|
-
switch (typeof value) {
|
|
30
|
-
case "boolean":
|
|
31
|
-
case "number":
|
|
32
|
-
case "string": return "primitive";
|
|
33
|
-
case "undefined": return "undefined";
|
|
34
|
-
case "object":
|
|
35
|
-
case "function": break;
|
|
36
|
-
case "bigint": return "bigint";
|
|
37
|
-
default: return "unsupported";
|
|
38
|
-
}
|
|
39
|
-
if (value === null) return "primitive";
|
|
40
|
-
let prototype = Object.getPrototypeOf(value);
|
|
41
|
-
switch (prototype) {
|
|
42
|
-
case Object.prototype: return "object";
|
|
43
|
-
case Function.prototype:
|
|
44
|
-
case AsyncFunction.prototype: return "function";
|
|
45
|
-
case Array.prototype: return "array";
|
|
46
|
-
case Date.prototype: return "date";
|
|
47
|
-
case Uint8Array.prototype: return "bytes";
|
|
48
|
-
case RpcStub.prototype: return "stub";
|
|
49
|
-
case RpcPromise.prototype: return "rpc-promise";
|
|
50
|
-
default:
|
|
51
|
-
if (workersModule) {
|
|
52
|
-
if (prototype == workersModule.RpcStub.prototype || value instanceof workersModule.ServiceStub) return "rpc-target";
|
|
53
|
-
else if (prototype == workersModule.RpcPromise.prototype || prototype == workersModule.RpcProperty.prototype) return "rpc-thenable";
|
|
54
|
-
}
|
|
55
|
-
if (value instanceof RpcTarget) return "rpc-target";
|
|
56
|
-
if (value instanceof Error) return "error";
|
|
57
|
-
return "unsupported";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function mapNotLoaded() {
|
|
61
|
-
throw new Error("RPC map() implementation was not loaded.");
|
|
62
|
-
}
|
|
63
|
-
var mapImpl = {
|
|
64
|
-
applyMap: mapNotLoaded,
|
|
65
|
-
sendMap: mapNotLoaded,
|
|
66
|
-
recordCallback: mapNotLoaded
|
|
67
|
-
};
|
|
68
|
-
var StubHook = class {};
|
|
69
|
-
var ErrorStubHook = class extends StubHook {
|
|
70
|
-
constructor(error) {
|
|
71
|
-
super();
|
|
72
|
-
this.error = error;
|
|
73
|
-
}
|
|
74
|
-
call(path, args) {
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
map(path, captures, instructions) {
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
get(path) {
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
dup() {
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
pull() {
|
|
87
|
-
return Promise.reject(this.error);
|
|
88
|
-
}
|
|
89
|
-
ignoreUnhandledRejections() {}
|
|
90
|
-
dispose() {}
|
|
91
|
-
onBroken(callback) {
|
|
92
|
-
try {
|
|
93
|
-
callback(this.error);
|
|
94
|
-
} catch (err) {
|
|
95
|
-
Promise.resolve(err);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var DISPOSED_HOOK = new ErrorStubHook(/* @__PURE__ */ new Error("Attempted to use RPC stub after it has been disposed."));
|
|
100
|
-
var doCall = (hook, path, params) => {
|
|
101
|
-
return hook.call(path, params);
|
|
102
|
-
};
|
|
103
|
-
function withCallInterceptor(interceptor, callback) {
|
|
104
|
-
let oldValue = doCall;
|
|
105
|
-
doCall = interceptor;
|
|
106
|
-
try {
|
|
107
|
-
return callback();
|
|
108
|
-
} finally {
|
|
109
|
-
doCall = oldValue;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
var RAW_STUB = /* @__PURE__ */ Symbol("realStub");
|
|
113
|
-
var PROXY_HANDLERS = {
|
|
114
|
-
apply(target, thisArg, argumentsList) {
|
|
115
|
-
let stub = target.raw;
|
|
116
|
-
return new RpcPromise(doCall(stub.hook, stub.pathIfPromise || [], RpcPayload.fromAppParams(argumentsList)), []);
|
|
117
|
-
},
|
|
118
|
-
get(target, prop, receiver) {
|
|
119
|
-
let stub = target.raw;
|
|
120
|
-
if (prop === RAW_STUB) return stub;
|
|
121
|
-
else if (prop in RpcPromise.prototype) return stub[prop];
|
|
122
|
-
else if (typeof prop === "string") return new RpcPromise(stub.hook, stub.pathIfPromise ? [...stub.pathIfPromise, prop] : [prop]);
|
|
123
|
-
else if (prop === Symbol.dispose && (!stub.pathIfPromise || stub.pathIfPromise.length == 0)) return () => {
|
|
124
|
-
stub.hook.dispose();
|
|
125
|
-
stub.hook = DISPOSED_HOOK;
|
|
126
|
-
};
|
|
127
|
-
else return;
|
|
128
|
-
},
|
|
129
|
-
has(target, prop) {
|
|
130
|
-
let stub = target.raw;
|
|
131
|
-
if (prop === RAW_STUB) return true;
|
|
132
|
-
else if (prop in RpcPromise.prototype) return prop in stub;
|
|
133
|
-
else if (typeof prop === "string") return true;
|
|
134
|
-
else if (prop === Symbol.dispose && (!stub.pathIfPromise || stub.pathIfPromise.length == 0)) return true;
|
|
135
|
-
else return false;
|
|
136
|
-
},
|
|
137
|
-
construct(target, args) {
|
|
138
|
-
throw new Error("An RPC stub cannot be used as a constructor.");
|
|
139
|
-
},
|
|
140
|
-
defineProperty(target, property, attributes) {
|
|
141
|
-
throw new Error("Can't define properties on RPC stubs.");
|
|
142
|
-
},
|
|
143
|
-
deleteProperty(target, p$1) {
|
|
144
|
-
throw new Error("Can't delete properties on RPC stubs.");
|
|
145
|
-
},
|
|
146
|
-
getOwnPropertyDescriptor(target, p$1) {},
|
|
147
|
-
getPrototypeOf(target) {
|
|
148
|
-
return Object.getPrototypeOf(target.raw);
|
|
149
|
-
},
|
|
150
|
-
isExtensible(target) {
|
|
151
|
-
return false;
|
|
152
|
-
},
|
|
153
|
-
ownKeys(target) {
|
|
154
|
-
return [];
|
|
155
|
-
},
|
|
156
|
-
preventExtensions(target) {
|
|
157
|
-
return true;
|
|
158
|
-
},
|
|
159
|
-
set(target, p$1, newValue, receiver) {
|
|
160
|
-
throw new Error("Can't assign properties on RPC stubs.");
|
|
161
|
-
},
|
|
162
|
-
setPrototypeOf(target, v$1) {
|
|
163
|
-
throw new Error("Can't override prototype of RPC stubs.");
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
var RpcStub = class _RpcStub extends RpcTarget {
|
|
167
|
-
constructor(hook, pathIfPromise) {
|
|
168
|
-
super();
|
|
169
|
-
if (!(hook instanceof StubHook)) {
|
|
170
|
-
let value = hook;
|
|
171
|
-
if (value instanceof RpcTarget || value instanceof Function) hook = TargetStubHook.create(value, void 0);
|
|
172
|
-
else hook = new PayloadStubHook(RpcPayload.fromAppReturn(value));
|
|
173
|
-
if (pathIfPromise) throw new TypeError("RpcStub constructor expected one argument, received two.");
|
|
174
|
-
}
|
|
175
|
-
this.hook = hook;
|
|
176
|
-
this.pathIfPromise = pathIfPromise;
|
|
177
|
-
let func = () => {};
|
|
178
|
-
func.raw = this;
|
|
179
|
-
return new Proxy(func, PROXY_HANDLERS);
|
|
180
|
-
}
|
|
181
|
-
hook;
|
|
182
|
-
pathIfPromise;
|
|
183
|
-
dup() {
|
|
184
|
-
let target = this[RAW_STUB];
|
|
185
|
-
if (target.pathIfPromise) return new _RpcStub(target.hook.get(target.pathIfPromise));
|
|
186
|
-
else return new _RpcStub(target.hook.dup());
|
|
187
|
-
}
|
|
188
|
-
onRpcBroken(callback) {
|
|
189
|
-
this[RAW_STUB].hook.onBroken(callback);
|
|
190
|
-
}
|
|
191
|
-
map(func) {
|
|
192
|
-
let { hook, pathIfPromise } = this[RAW_STUB];
|
|
193
|
-
return mapImpl.sendMap(hook, pathIfPromise || [], func);
|
|
194
|
-
}
|
|
195
|
-
toString() {
|
|
196
|
-
return "[object RpcStub]";
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
var RpcPromise = class extends RpcStub {
|
|
200
|
-
constructor(hook, pathIfPromise) {
|
|
201
|
-
super(hook, pathIfPromise);
|
|
202
|
-
}
|
|
203
|
-
then(onfulfilled, onrejected) {
|
|
204
|
-
return pullPromise(this).then(...arguments);
|
|
205
|
-
}
|
|
206
|
-
catch(onrejected) {
|
|
207
|
-
return pullPromise(this).catch(...arguments);
|
|
208
|
-
}
|
|
209
|
-
finally(onfinally) {
|
|
210
|
-
return pullPromise(this).finally(...arguments);
|
|
211
|
-
}
|
|
212
|
-
toString() {
|
|
213
|
-
return "[object RpcPromise]";
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
function unwrapStubTakingOwnership(stub) {
|
|
217
|
-
let { hook, pathIfPromise } = stub[RAW_STUB];
|
|
218
|
-
if (pathIfPromise && pathIfPromise.length > 0) return hook.get(pathIfPromise);
|
|
219
|
-
else return hook;
|
|
220
|
-
}
|
|
221
|
-
function unwrapStubAndDup(stub) {
|
|
222
|
-
let { hook, pathIfPromise } = stub[RAW_STUB];
|
|
223
|
-
if (pathIfPromise) return hook.get(pathIfPromise);
|
|
224
|
-
else return hook.dup();
|
|
225
|
-
}
|
|
226
|
-
function unwrapStubNoProperties(stub) {
|
|
227
|
-
let { hook, pathIfPromise } = stub[RAW_STUB];
|
|
228
|
-
if (pathIfPromise && pathIfPromise.length > 0) return;
|
|
229
|
-
return hook;
|
|
230
|
-
}
|
|
231
|
-
function unwrapStubOrParent(stub) {
|
|
232
|
-
return stub[RAW_STUB].hook;
|
|
233
|
-
}
|
|
234
|
-
function unwrapStubAndPath(stub) {
|
|
235
|
-
return stub[RAW_STUB];
|
|
236
|
-
}
|
|
237
|
-
async function pullPromise(promise) {
|
|
238
|
-
let { hook, pathIfPromise } = promise[RAW_STUB];
|
|
239
|
-
if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
|
|
240
|
-
return (await hook.pull()).deliverResolve();
|
|
241
|
-
}
|
|
242
|
-
var RpcPayload = class _RpcPayload {
|
|
243
|
-
constructor(value, source, stubs, promises) {
|
|
244
|
-
this.value = value;
|
|
245
|
-
this.source = source;
|
|
246
|
-
this.stubs = stubs;
|
|
247
|
-
this.promises = promises;
|
|
248
|
-
}
|
|
249
|
-
static fromAppParams(value) {
|
|
250
|
-
return new _RpcPayload(value, "params");
|
|
251
|
-
}
|
|
252
|
-
static fromAppReturn(value) {
|
|
253
|
-
return new _RpcPayload(value, "return");
|
|
254
|
-
}
|
|
255
|
-
static fromArray(array) {
|
|
256
|
-
let stubs = [];
|
|
257
|
-
let promises = [];
|
|
258
|
-
let resultArray = [];
|
|
259
|
-
for (let payload of array) {
|
|
260
|
-
payload.ensureDeepCopied();
|
|
261
|
-
for (let stub of payload.stubs) stubs.push(stub);
|
|
262
|
-
for (let promise of payload.promises) {
|
|
263
|
-
if (promise.parent === payload) promise = {
|
|
264
|
-
parent: resultArray,
|
|
265
|
-
property: resultArray.length,
|
|
266
|
-
promise: promise.promise
|
|
267
|
-
};
|
|
268
|
-
promises.push(promise);
|
|
269
|
-
}
|
|
270
|
-
resultArray.push(payload.value);
|
|
271
|
-
}
|
|
272
|
-
return new _RpcPayload(resultArray, "owned", stubs, promises);
|
|
273
|
-
}
|
|
274
|
-
static forEvaluate(stubs, promises) {
|
|
275
|
-
return new _RpcPayload(null, "owned", stubs, promises);
|
|
276
|
-
}
|
|
277
|
-
static deepCopyFrom(value, oldParent, owner) {
|
|
278
|
-
let result = new _RpcPayload(null, "owned", [], []);
|
|
279
|
-
result.value = result.deepCopy(value, oldParent, "value", result, true, owner);
|
|
280
|
-
return result;
|
|
281
|
-
}
|
|
282
|
-
rpcTargets;
|
|
283
|
-
getHookForRpcTarget(target, parent, dupStubs = true) {
|
|
284
|
-
if (this.source === "params") {
|
|
285
|
-
if (dupStubs) {
|
|
286
|
-
let dupable = target;
|
|
287
|
-
if (typeof dupable.dup === "function") target = dupable.dup();
|
|
288
|
-
}
|
|
289
|
-
return TargetStubHook.create(target, parent);
|
|
290
|
-
} else if (this.source === "return") {
|
|
291
|
-
let hook = this.rpcTargets?.get(target);
|
|
292
|
-
if (hook) if (dupStubs) return hook.dup();
|
|
293
|
-
else {
|
|
294
|
-
this.rpcTargets?.delete(target);
|
|
295
|
-
return hook;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
hook = TargetStubHook.create(target, parent);
|
|
299
|
-
if (dupStubs) {
|
|
300
|
-
if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
|
|
301
|
-
this.rpcTargets.set(target, hook);
|
|
302
|
-
return hook.dup();
|
|
303
|
-
} else return hook;
|
|
304
|
-
}
|
|
305
|
-
} else throw new Error("owned payload shouldn't contain raw RpcTargets");
|
|
306
|
-
}
|
|
307
|
-
deepCopy(value, oldParent, property, parent, dupStubs, owner) {
|
|
308
|
-
switch (typeForRpc(value)) {
|
|
309
|
-
case "unsupported": return value;
|
|
310
|
-
case "primitive":
|
|
311
|
-
case "bigint":
|
|
312
|
-
case "date":
|
|
313
|
-
case "bytes":
|
|
314
|
-
case "error":
|
|
315
|
-
case "undefined": return value;
|
|
316
|
-
case "array": {
|
|
317
|
-
let array = value;
|
|
318
|
-
let len = array.length;
|
|
319
|
-
let result = new Array(len);
|
|
320
|
-
for (let i = 0; i < len; i++) result[i] = this.deepCopy(array[i], array, i, result, dupStubs, owner);
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
case "object": {
|
|
324
|
-
let result = {};
|
|
325
|
-
let object = value;
|
|
326
|
-
for (let i in object) result[i] = this.deepCopy(object[i], object, i, result, dupStubs, owner);
|
|
327
|
-
return result;
|
|
328
|
-
}
|
|
329
|
-
case "stub":
|
|
330
|
-
case "rpc-promise": {
|
|
331
|
-
let stub = value;
|
|
332
|
-
let hook;
|
|
333
|
-
if (dupStubs) hook = unwrapStubAndDup(stub);
|
|
334
|
-
else hook = unwrapStubTakingOwnership(stub);
|
|
335
|
-
if (stub instanceof RpcPromise) {
|
|
336
|
-
let promise = new RpcPromise(hook, []);
|
|
337
|
-
this.promises.push({
|
|
338
|
-
parent,
|
|
339
|
-
property,
|
|
340
|
-
promise
|
|
341
|
-
});
|
|
342
|
-
return promise;
|
|
343
|
-
} else {
|
|
344
|
-
let newStub = new RpcStub(hook);
|
|
345
|
-
this.stubs.push(newStub);
|
|
346
|
-
return newStub;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
case "function": if (this.source === "owned" && typeof value === "function" && !(value instanceof RpcTarget)) return value;
|
|
350
|
-
case "rpc-target": {
|
|
351
|
-
let target = value;
|
|
352
|
-
let stub;
|
|
353
|
-
if (owner) stub = new RpcStub(owner.getHookForRpcTarget(target, oldParent, dupStubs));
|
|
354
|
-
else stub = new RpcStub(TargetStubHook.create(target, oldParent));
|
|
355
|
-
this.stubs.push(stub);
|
|
356
|
-
return stub;
|
|
357
|
-
}
|
|
358
|
-
case "rpc-thenable": {
|
|
359
|
-
let target = value;
|
|
360
|
-
let promise;
|
|
361
|
-
if (owner) promise = new RpcPromise(owner.getHookForRpcTarget(target, oldParent, dupStubs), []);
|
|
362
|
-
else promise = new RpcPromise(TargetStubHook.create(target, oldParent), []);
|
|
363
|
-
this.promises.push({
|
|
364
|
-
parent,
|
|
365
|
-
property,
|
|
366
|
-
promise
|
|
367
|
-
});
|
|
368
|
-
return promise;
|
|
369
|
-
}
|
|
370
|
-
default: throw new Error("unreachable");
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
ensureDeepCopied() {
|
|
374
|
-
if (this.source !== "owned") {
|
|
375
|
-
let dupStubs = this.source === "params";
|
|
376
|
-
this.stubs = [];
|
|
377
|
-
this.promises = [];
|
|
378
|
-
try {
|
|
379
|
-
this.value = this.deepCopy(this.value, void 0, "value", this, dupStubs, this);
|
|
380
|
-
} catch (err) {
|
|
381
|
-
this.stubs = void 0;
|
|
382
|
-
this.promises = void 0;
|
|
383
|
-
throw err;
|
|
384
|
-
}
|
|
385
|
-
this.source = "owned";
|
|
386
|
-
if (this.rpcTargets && this.rpcTargets.size > 0) throw new Error("Not all rpcTargets were accounted for in deep-copy?");
|
|
387
|
-
this.rpcTargets = void 0;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
deliverTo(parent, property, promises) {
|
|
391
|
-
const unwrapRpcTargets = (value) => {
|
|
392
|
-
if (value instanceof RpcStub) {
|
|
393
|
-
const { hook, pathIfPromise } = unwrapStubAndPath(value);
|
|
394
|
-
if (pathIfPromise == null && hook instanceof TargetStubHook) return hook.getTarget();
|
|
395
|
-
}
|
|
396
|
-
return value;
|
|
397
|
-
};
|
|
398
|
-
this.ensureDeepCopied();
|
|
399
|
-
if (this.value instanceof RpcPromise) _RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
|
|
400
|
-
else {
|
|
401
|
-
parent[property] = unwrapRpcTargets(this.value);
|
|
402
|
-
for (let record of this.promises) _RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
static deliverRpcPromiseTo(promise, parent, property, promises) {
|
|
406
|
-
let hook = unwrapStubNoProperties(promise);
|
|
407
|
-
if (!hook) throw new Error("property promises should have been resolved earlier");
|
|
408
|
-
let inner = hook.pull();
|
|
409
|
-
if (inner instanceof _RpcPayload) inner.deliverTo(parent, property, promises);
|
|
410
|
-
else promises.push(inner.then((payload) => {
|
|
411
|
-
let subPromises = [];
|
|
412
|
-
payload.deliverTo(parent, property, subPromises);
|
|
413
|
-
if (subPromises.length > 0) return Promise.all(subPromises);
|
|
414
|
-
}));
|
|
415
|
-
}
|
|
416
|
-
async deliverCall(func, thisArg) {
|
|
417
|
-
try {
|
|
418
|
-
let promises = [];
|
|
419
|
-
this.deliverTo(this, "value", promises);
|
|
420
|
-
if (promises.length > 0) await Promise.all(promises);
|
|
421
|
-
let result = Function.prototype.apply.call(func, thisArg, this.value);
|
|
422
|
-
if (result instanceof RpcPromise) return _RpcPayload.fromAppReturn(result);
|
|
423
|
-
else return _RpcPayload.fromAppReturn(await result);
|
|
424
|
-
} finally {
|
|
425
|
-
this.dispose();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async deliverResolve() {
|
|
429
|
-
try {
|
|
430
|
-
let promises = [];
|
|
431
|
-
this.deliverTo(this, "value", promises);
|
|
432
|
-
if (promises.length > 0) await Promise.all(promises);
|
|
433
|
-
let result = this.value;
|
|
434
|
-
if (result instanceof Object) {
|
|
435
|
-
if (!(Symbol.dispose in result)) Object.defineProperty(result, Symbol.dispose, {
|
|
436
|
-
value: () => this.dispose(),
|
|
437
|
-
writable: true,
|
|
438
|
-
enumerable: false,
|
|
439
|
-
configurable: true
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
return result;
|
|
443
|
-
} catch (err) {
|
|
444
|
-
this.dispose();
|
|
445
|
-
throw err;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
dispose() {
|
|
449
|
-
if (this.source === "owned") {
|
|
450
|
-
this.stubs.forEach((stub) => stub[Symbol.dispose]());
|
|
451
|
-
this.promises.forEach((promise) => promise.promise[Symbol.dispose]());
|
|
452
|
-
} else if (this.source === "return") {
|
|
453
|
-
this.disposeImpl(this.value, void 0);
|
|
454
|
-
if (this.rpcTargets && this.rpcTargets.size > 0) throw new Error("Not all rpcTargets were accounted for in disposeImpl()?");
|
|
455
|
-
}
|
|
456
|
-
this.source = "owned";
|
|
457
|
-
this.stubs = [];
|
|
458
|
-
this.promises = [];
|
|
459
|
-
}
|
|
460
|
-
disposeImpl(value, parent) {
|
|
461
|
-
switch (typeForRpc(value)) {
|
|
462
|
-
case "unsupported":
|
|
463
|
-
case "primitive":
|
|
464
|
-
case "bigint":
|
|
465
|
-
case "bytes":
|
|
466
|
-
case "date":
|
|
467
|
-
case "error":
|
|
468
|
-
case "undefined": return;
|
|
469
|
-
case "array": {
|
|
470
|
-
let array = value;
|
|
471
|
-
let len = array.length;
|
|
472
|
-
for (let i = 0; i < len; i++) this.disposeImpl(array[i], array);
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
case "object": {
|
|
476
|
-
let object = value;
|
|
477
|
-
for (let i in object) this.disposeImpl(object[i], object);
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
case "stub":
|
|
481
|
-
case "rpc-promise": {
|
|
482
|
-
let hook = unwrapStubNoProperties(value);
|
|
483
|
-
if (hook) hook.dispose();
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
case "function":
|
|
487
|
-
case "rpc-target": {
|
|
488
|
-
let target = value;
|
|
489
|
-
let hook = this.rpcTargets?.get(target);
|
|
490
|
-
if (hook) {
|
|
491
|
-
hook.dispose();
|
|
492
|
-
this.rpcTargets.delete(target);
|
|
493
|
-
} else disposeRpcTarget(target);
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
case "rpc-thenable": return;
|
|
497
|
-
default: return;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
ignoreUnhandledRejections() {
|
|
501
|
-
if (this.stubs) {
|
|
502
|
-
this.stubs.forEach((stub) => {
|
|
503
|
-
unwrapStubOrParent(stub).ignoreUnhandledRejections();
|
|
504
|
-
});
|
|
505
|
-
this.promises.forEach((promise) => unwrapStubOrParent(promise.promise).ignoreUnhandledRejections());
|
|
506
|
-
} else this.ignoreUnhandledRejectionsImpl(this.value);
|
|
507
|
-
}
|
|
508
|
-
ignoreUnhandledRejectionsImpl(value) {
|
|
509
|
-
switch (typeForRpc(value)) {
|
|
510
|
-
case "unsupported":
|
|
511
|
-
case "primitive":
|
|
512
|
-
case "bigint":
|
|
513
|
-
case "bytes":
|
|
514
|
-
case "date":
|
|
515
|
-
case "error":
|
|
516
|
-
case "undefined":
|
|
517
|
-
case "function":
|
|
518
|
-
case "rpc-target": return;
|
|
519
|
-
case "array": {
|
|
520
|
-
let array = value;
|
|
521
|
-
let len = array.length;
|
|
522
|
-
for (let i = 0; i < len; i++) this.ignoreUnhandledRejectionsImpl(array[i]);
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
case "object": {
|
|
526
|
-
let object = value;
|
|
527
|
-
for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
case "stub":
|
|
531
|
-
case "rpc-promise":
|
|
532
|
-
unwrapStubOrParent(value).ignoreUnhandledRejections();
|
|
533
|
-
return;
|
|
534
|
-
case "rpc-thenable":
|
|
535
|
-
value.then((_$1) => {}, (_$1) => {});
|
|
536
|
-
return;
|
|
537
|
-
default: return;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
function followPath(value, parent, path, owner) {
|
|
542
|
-
for (let i = 0; i < path.length; i++) {
|
|
543
|
-
parent = value;
|
|
544
|
-
let part = path[i];
|
|
545
|
-
if (part in Object.prototype) {
|
|
546
|
-
value = void 0;
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
switch (typeForRpc(value)) {
|
|
550
|
-
case "object":
|
|
551
|
-
case "function":
|
|
552
|
-
if (Object.hasOwn(value, part)) value = value[part];
|
|
553
|
-
else value = void 0;
|
|
554
|
-
break;
|
|
555
|
-
case "array":
|
|
556
|
-
if (Number.isInteger(part) && part >= 0) value = value[part];
|
|
557
|
-
else value = void 0;
|
|
558
|
-
break;
|
|
559
|
-
case "rpc-target":
|
|
560
|
-
case "rpc-thenable":
|
|
561
|
-
if (Object.hasOwn(value, part)) throw new TypeError(`Attempted to access property '${part}', which is an instance property of the RpcTarget. To avoid leaking private internals, instance properties cannot be accessed over RPC. If you want to make this property available over RPC, define it as a method or getter on the class, instead of an instance property.`);
|
|
562
|
-
else value = value[part];
|
|
563
|
-
owner = null;
|
|
564
|
-
break;
|
|
565
|
-
case "stub":
|
|
566
|
-
case "rpc-promise": {
|
|
567
|
-
let { hook, pathIfPromise } = unwrapStubAndPath(value);
|
|
568
|
-
return {
|
|
569
|
-
hook,
|
|
570
|
-
remainingPath: pathIfPromise ? pathIfPromise.concat(path.slice(i)) : path.slice(i)
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
case "primitive":
|
|
574
|
-
case "bigint":
|
|
575
|
-
case "bytes":
|
|
576
|
-
case "date":
|
|
577
|
-
case "error":
|
|
578
|
-
value = void 0;
|
|
579
|
-
break;
|
|
580
|
-
case "undefined":
|
|
581
|
-
value = value[part];
|
|
582
|
-
break;
|
|
583
|
-
case "unsupported": if (i === 0) throw new TypeError(`RPC stub points at a non-serializable type.`);
|
|
584
|
-
else {
|
|
585
|
-
let prefix = path.slice(0, i).join(".");
|
|
586
|
-
let remainder = path.slice(0, i).join(".");
|
|
587
|
-
throw new TypeError(`'${prefix}' is not a serializable type, so property ${remainder} cannot be accessed.`);
|
|
588
|
-
}
|
|
589
|
-
default: throw new TypeError("unreachable");
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
if (value instanceof RpcPromise) {
|
|
593
|
-
let { hook, pathIfPromise } = unwrapStubAndPath(value);
|
|
594
|
-
return {
|
|
595
|
-
hook,
|
|
596
|
-
remainingPath: pathIfPromise || []
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
value,
|
|
601
|
-
parent,
|
|
602
|
-
owner
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
var ValueStubHook = class extends StubHook {
|
|
606
|
-
call(path, args) {
|
|
607
|
-
try {
|
|
608
|
-
let { value, owner } = this.getValue();
|
|
609
|
-
let followResult = followPath(value, void 0, path, owner);
|
|
610
|
-
if (followResult.hook) return followResult.hook.call(followResult.remainingPath, args);
|
|
611
|
-
if (typeof followResult.value != "function") throw new TypeError(`'${path.join(".")}' is not a function.`);
|
|
612
|
-
return new PromiseStubHook(args.deliverCall(followResult.value, followResult.parent).then((payload) => {
|
|
613
|
-
return new PayloadStubHook(payload);
|
|
614
|
-
}));
|
|
615
|
-
} catch (err) {
|
|
616
|
-
return new ErrorStubHook(err);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
map(path, captures, instructions) {
|
|
620
|
-
try {
|
|
621
|
-
let followResult;
|
|
622
|
-
try {
|
|
623
|
-
let { value, owner } = this.getValue();
|
|
624
|
-
followResult = followPath(value, void 0, path, owner);
|
|
625
|
-
} catch (err) {
|
|
626
|
-
for (let cap of captures) cap.dispose();
|
|
627
|
-
throw err;
|
|
628
|
-
}
|
|
629
|
-
if (followResult.hook) return followResult.hook.map(followResult.remainingPath, captures, instructions);
|
|
630
|
-
return mapImpl.applyMap(followResult.value, followResult.parent, followResult.owner, captures, instructions);
|
|
631
|
-
} catch (err) {
|
|
632
|
-
return new ErrorStubHook(err);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
get(path) {
|
|
636
|
-
try {
|
|
637
|
-
let { value, owner } = this.getValue();
|
|
638
|
-
if (path.length === 0 && owner === null) throw new Error("Can't dup an RpcTarget stub as a promise.");
|
|
639
|
-
let followResult = followPath(value, void 0, path, owner);
|
|
640
|
-
if (followResult.hook) return followResult.hook.get(followResult.remainingPath);
|
|
641
|
-
return new PayloadStubHook(RpcPayload.deepCopyFrom(followResult.value, followResult.parent, followResult.owner));
|
|
642
|
-
} catch (err) {
|
|
643
|
-
return new ErrorStubHook(err);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
var PayloadStubHook = class _PayloadStubHook extends ValueStubHook {
|
|
648
|
-
constructor(payload) {
|
|
649
|
-
super();
|
|
650
|
-
this.payload = payload;
|
|
651
|
-
}
|
|
652
|
-
payload;
|
|
653
|
-
getPayload() {
|
|
654
|
-
if (this.payload) return this.payload;
|
|
655
|
-
else throw new Error("Attempted to use an RPC StubHook after it was disposed.");
|
|
656
|
-
}
|
|
657
|
-
getValue() {
|
|
658
|
-
let payload = this.getPayload();
|
|
659
|
-
return {
|
|
660
|
-
value: payload.value,
|
|
661
|
-
owner: payload
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
dup() {
|
|
665
|
-
let thisPayload = this.getPayload();
|
|
666
|
-
return new _PayloadStubHook(RpcPayload.deepCopyFrom(thisPayload.value, void 0, thisPayload));
|
|
667
|
-
}
|
|
668
|
-
pull() {
|
|
669
|
-
return this.getPayload();
|
|
670
|
-
}
|
|
671
|
-
ignoreUnhandledRejections() {
|
|
672
|
-
if (this.payload) this.payload.ignoreUnhandledRejections();
|
|
673
|
-
}
|
|
674
|
-
dispose() {
|
|
675
|
-
if (this.payload) {
|
|
676
|
-
this.payload.dispose();
|
|
677
|
-
this.payload = void 0;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
onBroken(callback) {
|
|
681
|
-
if (this.payload) {
|
|
682
|
-
if (this.payload.value instanceof RpcStub) this.payload.value.onRpcBroken(callback);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
function disposeRpcTarget(target) {
|
|
687
|
-
if (Symbol.dispose in target) try {
|
|
688
|
-
target[Symbol.dispose]();
|
|
689
|
-
} catch (err) {
|
|
690
|
-
Promise.reject(err);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
var TargetStubHook = class _TargetStubHook extends ValueStubHook {
|
|
694
|
-
static create(value, parent) {
|
|
695
|
-
if (typeof value !== "function") parent = void 0;
|
|
696
|
-
return new _TargetStubHook(value, parent);
|
|
697
|
-
}
|
|
698
|
-
constructor(target, parent, dupFrom) {
|
|
699
|
-
super();
|
|
700
|
-
this.target = target;
|
|
701
|
-
this.parent = parent;
|
|
702
|
-
if (dupFrom) {
|
|
703
|
-
if (dupFrom.refcount) {
|
|
704
|
-
this.refcount = dupFrom.refcount;
|
|
705
|
-
++this.refcount.count;
|
|
706
|
-
}
|
|
707
|
-
} else if (Symbol.dispose in target) this.refcount = { count: 1 };
|
|
708
|
-
}
|
|
709
|
-
target;
|
|
710
|
-
parent;
|
|
711
|
-
refcount;
|
|
712
|
-
getTarget() {
|
|
713
|
-
if (this.target) return this.target;
|
|
714
|
-
else throw new Error("Attempted to use an RPC StubHook after it was disposed.");
|
|
715
|
-
}
|
|
716
|
-
getValue() {
|
|
717
|
-
return {
|
|
718
|
-
value: this.getTarget(),
|
|
719
|
-
owner: null
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
dup() {
|
|
723
|
-
return new _TargetStubHook(this.getTarget(), this.parent, this);
|
|
724
|
-
}
|
|
725
|
-
pull() {
|
|
726
|
-
let target = this.getTarget();
|
|
727
|
-
if ("then" in target) return Promise.resolve(target).then((resolution) => {
|
|
728
|
-
return RpcPayload.fromAppReturn(resolution);
|
|
729
|
-
});
|
|
730
|
-
else return Promise.reject(/* @__PURE__ */ new Error("Tried to resolve a non-promise stub."));
|
|
731
|
-
}
|
|
732
|
-
ignoreUnhandledRejections() {}
|
|
733
|
-
dispose() {
|
|
734
|
-
if (this.target) {
|
|
735
|
-
if (this.refcount) {
|
|
736
|
-
if (--this.refcount.count == 0) disposeRpcTarget(this.target);
|
|
737
|
-
}
|
|
738
|
-
this.target = void 0;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
onBroken(callback) {}
|
|
742
|
-
};
|
|
743
|
-
var PromiseStubHook = class _PromiseStubHook extends StubHook {
|
|
744
|
-
promise;
|
|
745
|
-
resolution;
|
|
746
|
-
constructor(promise) {
|
|
747
|
-
super();
|
|
748
|
-
this.promise = promise.then((res) => {
|
|
749
|
-
this.resolution = res;
|
|
750
|
-
return res;
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
call(path, args) {
|
|
754
|
-
args.ensureDeepCopied();
|
|
755
|
-
return new _PromiseStubHook(this.promise.then((hook) => hook.call(path, args)));
|
|
756
|
-
}
|
|
757
|
-
map(path, captures, instructions) {
|
|
758
|
-
return new _PromiseStubHook(this.promise.then((hook) => hook.map(path, captures, instructions), (err) => {
|
|
759
|
-
for (let cap of captures) cap.dispose();
|
|
760
|
-
throw err;
|
|
761
|
-
}));
|
|
762
|
-
}
|
|
763
|
-
get(path) {
|
|
764
|
-
return new _PromiseStubHook(this.promise.then((hook) => hook.get(path)));
|
|
765
|
-
}
|
|
766
|
-
dup() {
|
|
767
|
-
if (this.resolution) return this.resolution.dup();
|
|
768
|
-
else return new _PromiseStubHook(this.promise.then((hook) => hook.dup()));
|
|
769
|
-
}
|
|
770
|
-
pull() {
|
|
771
|
-
if (this.resolution) return this.resolution.pull();
|
|
772
|
-
else return this.promise.then((hook) => hook.pull());
|
|
773
|
-
}
|
|
774
|
-
ignoreUnhandledRejections() {
|
|
775
|
-
if (this.resolution) this.resolution.ignoreUnhandledRejections();
|
|
776
|
-
else this.promise.then((res) => {
|
|
777
|
-
res.ignoreUnhandledRejections();
|
|
778
|
-
}, (err) => {});
|
|
779
|
-
}
|
|
780
|
-
dispose() {
|
|
781
|
-
if (this.resolution) this.resolution.dispose();
|
|
782
|
-
else this.promise.then((hook) => {
|
|
783
|
-
hook.dispose();
|
|
784
|
-
}, (err) => {});
|
|
785
|
-
}
|
|
786
|
-
onBroken(callback) {
|
|
787
|
-
if (this.resolution) this.resolution.onBroken(callback);
|
|
788
|
-
else this.promise.then((hook) => {
|
|
789
|
-
hook.onBroken(callback);
|
|
790
|
-
}, callback);
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
var currentMapBuilder;
|
|
794
|
-
var MapBuilder = class {
|
|
795
|
-
context;
|
|
796
|
-
captureMap = /* @__PURE__ */ new Map();
|
|
797
|
-
instructions = [];
|
|
798
|
-
constructor(subject, path) {
|
|
799
|
-
if (currentMapBuilder) this.context = {
|
|
800
|
-
parent: currentMapBuilder,
|
|
801
|
-
captures: [],
|
|
802
|
-
subject: currentMapBuilder.capture(subject),
|
|
803
|
-
path
|
|
804
|
-
};
|
|
805
|
-
else this.context = {
|
|
806
|
-
parent: void 0,
|
|
807
|
-
captures: [],
|
|
808
|
-
subject,
|
|
809
|
-
path
|
|
810
|
-
};
|
|
811
|
-
currentMapBuilder = this;
|
|
812
|
-
}
|
|
813
|
-
unregister() {
|
|
814
|
-
currentMapBuilder = this.context.parent;
|
|
815
|
-
}
|
|
816
|
-
makeInput() {
|
|
817
|
-
return new MapVariableHook(this, 0);
|
|
818
|
-
}
|
|
819
|
-
makeOutput(result) {
|
|
820
|
-
let devalued;
|
|
821
|
-
try {
|
|
822
|
-
devalued = Devaluator.devaluate(result.value, void 0, this, result);
|
|
823
|
-
} finally {
|
|
824
|
-
result.dispose();
|
|
825
|
-
}
|
|
826
|
-
this.instructions.push(devalued);
|
|
827
|
-
if (this.context.parent) {
|
|
828
|
-
this.context.parent.instructions.push([
|
|
829
|
-
"remap",
|
|
830
|
-
this.context.subject,
|
|
831
|
-
this.context.path,
|
|
832
|
-
this.context.captures.map((cap) => ["import", cap]),
|
|
833
|
-
this.instructions
|
|
834
|
-
]);
|
|
835
|
-
return new MapVariableHook(this.context.parent, this.context.parent.instructions.length);
|
|
836
|
-
} else return this.context.subject.map(this.context.path, this.context.captures, this.instructions);
|
|
837
|
-
}
|
|
838
|
-
pushCall(hook, path, params) {
|
|
839
|
-
let devalued = Devaluator.devaluate(params.value, void 0, this, params);
|
|
840
|
-
devalued = devalued[0];
|
|
841
|
-
let subject = this.capture(hook.dup());
|
|
842
|
-
this.instructions.push([
|
|
843
|
-
"pipeline",
|
|
844
|
-
subject,
|
|
845
|
-
path,
|
|
846
|
-
devalued
|
|
847
|
-
]);
|
|
848
|
-
return new MapVariableHook(this, this.instructions.length);
|
|
849
|
-
}
|
|
850
|
-
pushGet(hook, path) {
|
|
851
|
-
let subject = this.capture(hook.dup());
|
|
852
|
-
this.instructions.push([
|
|
853
|
-
"pipeline",
|
|
854
|
-
subject,
|
|
855
|
-
path
|
|
856
|
-
]);
|
|
857
|
-
return new MapVariableHook(this, this.instructions.length);
|
|
858
|
-
}
|
|
859
|
-
capture(hook) {
|
|
860
|
-
if (hook instanceof MapVariableHook && hook.mapper === this) return hook.idx;
|
|
861
|
-
let result = this.captureMap.get(hook);
|
|
862
|
-
if (result === void 0) {
|
|
863
|
-
if (this.context.parent) {
|
|
864
|
-
let parentIdx = this.context.parent.capture(hook);
|
|
865
|
-
this.context.captures.push(parentIdx);
|
|
866
|
-
} else this.context.captures.push(hook);
|
|
867
|
-
result = -this.context.captures.length;
|
|
868
|
-
this.captureMap.set(hook, result);
|
|
869
|
-
}
|
|
870
|
-
return result;
|
|
871
|
-
}
|
|
872
|
-
exportStub(hook) {
|
|
873
|
-
throw new Error("Can't construct an RpcTarget or RPC callback inside a mapper function. Try creating a new RpcStub outside the callback first, then using it inside the callback.");
|
|
874
|
-
}
|
|
875
|
-
exportPromise(hook) {
|
|
876
|
-
return this.exportStub(hook);
|
|
877
|
-
}
|
|
878
|
-
getImport(hook) {
|
|
879
|
-
return this.capture(hook);
|
|
880
|
-
}
|
|
881
|
-
unexport(ids) {}
|
|
882
|
-
onSendError(error) {}
|
|
883
|
-
};
|
|
884
|
-
mapImpl.sendMap = (hook, path, func) => {
|
|
885
|
-
let builder = new MapBuilder(hook, path);
|
|
886
|
-
let result;
|
|
887
|
-
try {
|
|
888
|
-
result = RpcPayload.fromAppReturn(withCallInterceptor(builder.pushCall.bind(builder), () => {
|
|
889
|
-
return func(new RpcPromise(builder.makeInput(), []));
|
|
890
|
-
}));
|
|
891
|
-
} finally {
|
|
892
|
-
builder.unregister();
|
|
893
|
-
}
|
|
894
|
-
if (result instanceof Promise) {
|
|
895
|
-
result.catch((err) => {});
|
|
896
|
-
throw new Error("RPC map() callbacks cannot be async.");
|
|
897
|
-
}
|
|
898
|
-
return new RpcPromise(builder.makeOutput(result), []);
|
|
899
|
-
};
|
|
900
|
-
mapImpl.recordCallback = (func) => {
|
|
901
|
-
const builder = new MapBuilder(new PayloadStubHook(RpcPayload.fromAppParams([])), []);
|
|
902
|
-
let result;
|
|
903
|
-
try {
|
|
904
|
-
result = RpcPayload.fromAppReturn(withCallInterceptor(builder.pushCall.bind(builder), () => {
|
|
905
|
-
return func(new RpcPromise(builder.makeInput(), []));
|
|
906
|
-
}));
|
|
907
|
-
} finally {
|
|
908
|
-
builder.unregister();
|
|
909
|
-
}
|
|
910
|
-
const devaluatedResult = Devaluator.devaluate(result.value, void 0, builder, result);
|
|
911
|
-
const instructions = [...builder.instructions, devaluatedResult];
|
|
912
|
-
const context = builder.context;
|
|
913
|
-
if (context.parent) return [
|
|
914
|
-
"callback",
|
|
915
|
-
context.captures.map((cap) => ["import", cap]),
|
|
916
|
-
instructions
|
|
917
|
-
];
|
|
918
|
-
else return [
|
|
919
|
-
"callback",
|
|
920
|
-
context.captures,
|
|
921
|
-
instructions
|
|
922
|
-
];
|
|
923
|
-
};
|
|
924
|
-
function throwMapperBuilderUseError() {
|
|
925
|
-
throw new Error("Attempted to use an abstract placeholder from a mapper function. Please make sure your map function has no side effects.");
|
|
926
|
-
}
|
|
927
|
-
var MapVariableHook = class extends StubHook {
|
|
928
|
-
constructor(mapper, idx) {
|
|
929
|
-
super();
|
|
930
|
-
this.mapper = mapper;
|
|
931
|
-
this.idx = idx;
|
|
932
|
-
}
|
|
933
|
-
dup() {
|
|
934
|
-
return this;
|
|
935
|
-
}
|
|
936
|
-
dispose() {}
|
|
937
|
-
get(path) {
|
|
938
|
-
if (path.length == 0) return this;
|
|
939
|
-
else if (currentMapBuilder) return currentMapBuilder.pushGet(this, path);
|
|
940
|
-
else throwMapperBuilderUseError();
|
|
941
|
-
}
|
|
942
|
-
call(path, args) {
|
|
943
|
-
throwMapperBuilderUseError();
|
|
944
|
-
}
|
|
945
|
-
map(path, captures, instructions) {
|
|
946
|
-
throwMapperBuilderUseError();
|
|
947
|
-
}
|
|
948
|
-
pull() {
|
|
949
|
-
throwMapperBuilderUseError();
|
|
950
|
-
}
|
|
951
|
-
ignoreUnhandledRejections() {}
|
|
952
|
-
onBroken(callback) {
|
|
953
|
-
throwMapperBuilderUseError();
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
var MapApplicator = class {
|
|
957
|
-
constructor(captures, input) {
|
|
958
|
-
this.captures = captures;
|
|
959
|
-
this.variables = [input];
|
|
960
|
-
}
|
|
961
|
-
variables;
|
|
962
|
-
dispose() {
|
|
963
|
-
for (let variable of this.variables) variable.dispose();
|
|
964
|
-
}
|
|
965
|
-
apply(instructions) {
|
|
966
|
-
try {
|
|
967
|
-
if (instructions.length < 1) throw new Error("Invalid empty mapper function.");
|
|
968
|
-
for (let instruction of instructions.slice(0, -1)) {
|
|
969
|
-
let payload = new Evaluator(this).evaluateCopy(instruction);
|
|
970
|
-
if (payload.value instanceof RpcStub) {
|
|
971
|
-
let hook = unwrapStubNoProperties(payload.value);
|
|
972
|
-
if (hook) {
|
|
973
|
-
this.variables.push(hook);
|
|
974
|
-
continue;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
this.variables.push(new PayloadStubHook(payload));
|
|
978
|
-
}
|
|
979
|
-
return new Evaluator(this).evaluateCopy(instructions[instructions.length - 1]);
|
|
980
|
-
} finally {
|
|
981
|
-
for (let variable of this.variables) variable.dispose();
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
importStub(idx) {
|
|
985
|
-
throw new Error("A mapper function cannot refer to exports.");
|
|
986
|
-
}
|
|
987
|
-
importPromise(idx) {
|
|
988
|
-
return this.importStub(idx);
|
|
989
|
-
}
|
|
990
|
-
getExport(idx) {
|
|
991
|
-
if (idx < 0) return this.captures[-idx - 1];
|
|
992
|
-
else return this.variables[idx];
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
function applyMapToElement(input, parent, owner, captures, instructions) {
|
|
996
|
-
let mapper = new MapApplicator(captures, new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner)));
|
|
997
|
-
try {
|
|
998
|
-
return mapper.apply(instructions);
|
|
999
|
-
} finally {
|
|
1000
|
-
mapper.dispose();
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
|
|
1004
|
-
try {
|
|
1005
|
-
let result;
|
|
1006
|
-
if (input instanceof RpcPromise) throw new Error("applyMap() can't be called on RpcPromise");
|
|
1007
|
-
else if (input instanceof Array) {
|
|
1008
|
-
let payloads = [];
|
|
1009
|
-
try {
|
|
1010
|
-
for (let elem of input) payloads.push(applyMapToElement(elem, input, owner, captures, instructions));
|
|
1011
|
-
} catch (err) {
|
|
1012
|
-
for (let payload of payloads) payload.dispose();
|
|
1013
|
-
throw err;
|
|
1014
|
-
}
|
|
1015
|
-
result = RpcPayload.fromArray(payloads);
|
|
1016
|
-
} else if (input === null || input === void 0) result = RpcPayload.fromAppReturn(input);
|
|
1017
|
-
else result = applyMapToElement(input, parent, owner, captures, instructions);
|
|
1018
|
-
return new PayloadStubHook(result);
|
|
1019
|
-
} finally {
|
|
1020
|
-
for (let cap of captures) cap.dispose();
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
var isExplicitCallback = (arg) => {
|
|
1024
|
-
return typeof arg === "function" && "serializationMode" in arg;
|
|
1025
|
-
};
|
|
1026
|
-
var NullExporter = class {
|
|
1027
|
-
exportStub(stub) {
|
|
1028
|
-
throw new Error("Cannot serialize RPC stubs without an RPC session.");
|
|
1029
|
-
}
|
|
1030
|
-
exportPromise(stub) {
|
|
1031
|
-
throw new Error("Cannot serialize RPC stubs without an RPC session.");
|
|
1032
|
-
}
|
|
1033
|
-
getImport(hook) {}
|
|
1034
|
-
unexport(ids) {}
|
|
1035
|
-
onSendError(error) {}
|
|
1036
|
-
};
|
|
1037
|
-
var NULL_EXPORTER = new NullExporter();
|
|
1038
|
-
var ERROR_TYPES = {
|
|
1039
|
-
Error,
|
|
1040
|
-
EvalError,
|
|
1041
|
-
RangeError,
|
|
1042
|
-
ReferenceError,
|
|
1043
|
-
SyntaxError,
|
|
1044
|
-
TypeError,
|
|
1045
|
-
URIError,
|
|
1046
|
-
AggregateError
|
|
1047
|
-
};
|
|
1048
|
-
var Devaluator = class _Devaluator {
|
|
1049
|
-
constructor(exporter, source) {
|
|
1050
|
-
this.exporter = exporter;
|
|
1051
|
-
this.source = source;
|
|
1052
|
-
}
|
|
1053
|
-
static devaluate(value, parent, exporter = NULL_EXPORTER, source) {
|
|
1054
|
-
let devaluator = new _Devaluator(exporter, source);
|
|
1055
|
-
try {
|
|
1056
|
-
return devaluator.devaluateImpl(value, parent, 0);
|
|
1057
|
-
} catch (err) {
|
|
1058
|
-
if (devaluator.exports) try {
|
|
1059
|
-
exporter.unexport(devaluator.exports);
|
|
1060
|
-
} catch (err2) {}
|
|
1061
|
-
throw err;
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
exports;
|
|
1065
|
-
devaluateImpl(value, parent, depth) {
|
|
1066
|
-
if (depth >= 64) throw new Error("Serialization exceeded maximum allowed depth. (Does the message contain cycles?)");
|
|
1067
|
-
let kind = typeForRpc(value);
|
|
1068
|
-
switch (kind) {
|
|
1069
|
-
case "unsupported": {
|
|
1070
|
-
let msg;
|
|
1071
|
-
try {
|
|
1072
|
-
msg = `Cannot serialize value: ${value}`;
|
|
1073
|
-
} catch (err) {
|
|
1074
|
-
msg = "Cannot serialize value: (couldn't stringify value)";
|
|
1075
|
-
}
|
|
1076
|
-
throw new TypeError(msg);
|
|
1077
|
-
}
|
|
1078
|
-
case "primitive": if (typeof value === "number" && !isFinite(value)) if (value === Infinity) return ["inf"];
|
|
1079
|
-
else if (value === -Infinity) return ["-inf"];
|
|
1080
|
-
else return ["nan"];
|
|
1081
|
-
else return value;
|
|
1082
|
-
case "object": {
|
|
1083
|
-
let object = value;
|
|
1084
|
-
let result = {};
|
|
1085
|
-
for (let key in object) result[key] = this.devaluateImpl(object[key], object, depth + 1);
|
|
1086
|
-
return result;
|
|
1087
|
-
}
|
|
1088
|
-
case "array": {
|
|
1089
|
-
let array = value;
|
|
1090
|
-
let len = array.length;
|
|
1091
|
-
let result = new Array(len);
|
|
1092
|
-
for (let i = 0; i < len; i++) result[i] = this.devaluateImpl(array[i], array, depth + 1);
|
|
1093
|
-
return [result];
|
|
1094
|
-
}
|
|
1095
|
-
case "bigint": return ["bigint", value.toString()];
|
|
1096
|
-
case "date": return ["date", value.getTime()];
|
|
1097
|
-
case "bytes": {
|
|
1098
|
-
let bytes = value;
|
|
1099
|
-
if (bytes.toBase64) return ["bytes", bytes.toBase64({ omitPadding: true })];
|
|
1100
|
-
else return ["bytes", btoa(String.fromCharCode.apply(null, bytes).replace(/=*$/, ""))];
|
|
1101
|
-
}
|
|
1102
|
-
case "error": {
|
|
1103
|
-
let e = value;
|
|
1104
|
-
let rewritten = this.exporter.onSendError(e);
|
|
1105
|
-
if (rewritten) e = rewritten;
|
|
1106
|
-
let result = [
|
|
1107
|
-
"error",
|
|
1108
|
-
e.name,
|
|
1109
|
-
e.message
|
|
1110
|
-
];
|
|
1111
|
-
if (rewritten && rewritten.stack) result.push(rewritten.stack);
|
|
1112
|
-
return result;
|
|
1113
|
-
}
|
|
1114
|
-
case "undefined": return ["undefined"];
|
|
1115
|
-
case "stub":
|
|
1116
|
-
case "rpc-promise": {
|
|
1117
|
-
if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
|
|
1118
|
-
let { hook, pathIfPromise } = unwrapStubAndPath(value);
|
|
1119
|
-
let importId = this.exporter.getImport(hook);
|
|
1120
|
-
if (importId !== void 0) if (pathIfPromise) if (pathIfPromise.length > 0) return [
|
|
1121
|
-
"pipeline",
|
|
1122
|
-
importId,
|
|
1123
|
-
pathIfPromise
|
|
1124
|
-
];
|
|
1125
|
-
else return ["pipeline", importId];
|
|
1126
|
-
else return ["import", importId];
|
|
1127
|
-
if (pathIfPromise) hook = hook.get(pathIfPromise);
|
|
1128
|
-
else hook = hook.dup();
|
|
1129
|
-
return this.devaluateHook(pathIfPromise ? "promise" : "export", hook);
|
|
1130
|
-
}
|
|
1131
|
-
case "function":
|
|
1132
|
-
case "rpc-target": {
|
|
1133
|
-
let shouldRecordReplay = false;
|
|
1134
|
-
if (kind === "function") if (isExplicitCallback(value)) shouldRecordReplay = value.serializationMode === "recordReplay";
|
|
1135
|
-
else shouldRecordReplay = getGlobalRpcSessionOptions().recordReplayMode === "all";
|
|
1136
|
-
if (shouldRecordReplay) {
|
|
1137
|
-
const res = mapImpl.recordCallback(value);
|
|
1138
|
-
const captures = res[1];
|
|
1139
|
-
if (captures.length === 0 || captures[0] instanceof StubHook) {
|
|
1140
|
-
const captureHooks = captures;
|
|
1141
|
-
const serializedCaptures = captureHooks.map((stub) => {
|
|
1142
|
-
const importId = this.exporter.getImport(stub);
|
|
1143
|
-
if (importId !== void 0) return ["import", importId];
|
|
1144
|
-
else return ["export", this.exporter.exportStub(stub)];
|
|
1145
|
-
});
|
|
1146
|
-
for (const hook2 of captureHooks) hook2.dispose();
|
|
1147
|
-
return [
|
|
1148
|
-
"callback",
|
|
1149
|
-
serializedCaptures,
|
|
1150
|
-
res[2]
|
|
1151
|
-
];
|
|
1152
|
-
} else return res;
|
|
1153
|
-
}
|
|
1154
|
-
if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
|
|
1155
|
-
let hook = this.source.getHookForRpcTarget(value, parent);
|
|
1156
|
-
return this.devaluateHook("export", hook);
|
|
1157
|
-
}
|
|
1158
|
-
case "rpc-thenable": {
|
|
1159
|
-
if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
|
|
1160
|
-
let hook = this.source.getHookForRpcTarget(value, parent);
|
|
1161
|
-
return this.devaluateHook("promise", hook);
|
|
1162
|
-
}
|
|
1163
|
-
default: throw new Error("unreachable");
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
devaluateHook(type, hook) {
|
|
1167
|
-
if (!this.exports) this.exports = [];
|
|
1168
|
-
let exportId = type === "promise" ? this.exporter.exportPromise(hook) : this.exporter.exportStub(hook);
|
|
1169
|
-
this.exports.push(exportId);
|
|
1170
|
-
return [type, exportId];
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
var NullImporter = class {
|
|
1174
|
-
importStub(idx) {
|
|
1175
|
-
throw new Error("Cannot deserialize RPC stubs without an RPC session.");
|
|
1176
|
-
}
|
|
1177
|
-
importPromise(idx) {
|
|
1178
|
-
throw new Error("Cannot deserialize RPC stubs without an RPC session.");
|
|
1179
|
-
}
|
|
1180
|
-
getExport(idx) {}
|
|
1181
|
-
};
|
|
1182
|
-
var NULL_IMPORTER = new NullImporter();
|
|
1183
|
-
var Evaluator = class _Evaluator {
|
|
1184
|
-
constructor(importer) {
|
|
1185
|
-
this.importer = importer;
|
|
1186
|
-
}
|
|
1187
|
-
stubs = [];
|
|
1188
|
-
promises = [];
|
|
1189
|
-
resolveCaptures(capsData) {
|
|
1190
|
-
return capsData.map((cap) => {
|
|
1191
|
-
if (!(cap instanceof Array) || cap.length !== 2 || cap[0] !== "import" && cap[0] !== "export" || typeof cap[1] !== "number") throw new TypeError(`unknown capture: ${JSON.stringify(cap)}`);
|
|
1192
|
-
if (cap[0] === "export") return this.importer.importStub(cap[1]);
|
|
1193
|
-
else {
|
|
1194
|
-
let exp = this.importer.getExport(cap[1]);
|
|
1195
|
-
if (!exp) throw new Error(`no such entry on exports table: ${cap[1]}`);
|
|
1196
|
-
return exp.dup();
|
|
1197
|
-
}
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
evaluate(value) {
|
|
1201
|
-
let payload = RpcPayload.forEvaluate(this.stubs, this.promises);
|
|
1202
|
-
try {
|
|
1203
|
-
payload.value = this.evaluateImpl(value, payload, "value");
|
|
1204
|
-
return payload;
|
|
1205
|
-
} catch (err) {
|
|
1206
|
-
payload.dispose();
|
|
1207
|
-
throw err;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
evaluateCopy(value) {
|
|
1211
|
-
return this.evaluate(structuredClone(value));
|
|
1212
|
-
}
|
|
1213
|
-
evaluateImpl(value, parent, property) {
|
|
1214
|
-
if (value instanceof Array) {
|
|
1215
|
-
if (value.length == 1 && value[0] instanceof Array) {
|
|
1216
|
-
let result = value[0];
|
|
1217
|
-
for (let i = 0; i < result.length; i++) result[i] = this.evaluateImpl(result[i], result, i);
|
|
1218
|
-
return result;
|
|
1219
|
-
} else switch (value[0]) {
|
|
1220
|
-
case "callback": {
|
|
1221
|
-
if (value.length < 3 || !(value[1] instanceof Array) || !(value[2] instanceof Array)) break;
|
|
1222
|
-
const captures = this.resolveCaptures(value[1]);
|
|
1223
|
-
const instructions = value[2];
|
|
1224
|
-
const replayFn = (arg) => {
|
|
1225
|
-
const capturesForThisCall = captures.map((c) => c.dup());
|
|
1226
|
-
const applicator = new MapApplicator(capturesForThisCall, new PayloadStubHook(RpcPayload.fromAppParams(arg)));
|
|
1227
|
-
const disposeInvocation = () => {
|
|
1228
|
-
applicator.dispose();
|
|
1229
|
-
for (const cap of capturesForThisCall) cap.dispose();
|
|
1230
|
-
const cleanup = replayFn[CALLBACK_CLEANUP];
|
|
1231
|
-
if (typeof cleanup === "function") cleanup();
|
|
1232
|
-
};
|
|
1233
|
-
let resultPayload;
|
|
1234
|
-
try {
|
|
1235
|
-
resultPayload = applicator.apply(instructions);
|
|
1236
|
-
} catch (err) {
|
|
1237
|
-
disposeInvocation();
|
|
1238
|
-
throw err;
|
|
1239
|
-
}
|
|
1240
|
-
return resultPayload.deliverResolve().finally(disposeInvocation);
|
|
1241
|
-
};
|
|
1242
|
-
replayFn[CALLBACK_CLEANUP] = () => {
|
|
1243
|
-
for (const cap of captures) cap.dispose();
|
|
1244
|
-
};
|
|
1245
|
-
return replayFn;
|
|
1246
|
-
}
|
|
1247
|
-
case "bigint":
|
|
1248
|
-
if (typeof value[1] == "string") return BigInt(value[1]);
|
|
1249
|
-
break;
|
|
1250
|
-
case "date":
|
|
1251
|
-
if (typeof value[1] == "number") return new Date(value[1]);
|
|
1252
|
-
break;
|
|
1253
|
-
case "bytes": {
|
|
1254
|
-
let b64 = Uint8Array;
|
|
1255
|
-
if (typeof value[1] == "string") if (b64.fromBase64) return b64.fromBase64(value[1]);
|
|
1256
|
-
else {
|
|
1257
|
-
let bs = atob(value[1]);
|
|
1258
|
-
let len = bs.length;
|
|
1259
|
-
let bytes = new Uint8Array(len);
|
|
1260
|
-
for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
|
|
1261
|
-
return bytes;
|
|
1262
|
-
}
|
|
1263
|
-
break;
|
|
1264
|
-
}
|
|
1265
|
-
case "error":
|
|
1266
|
-
if (value.length >= 3 && typeof value[1] === "string" && typeof value[2] === "string") {
|
|
1267
|
-
let result = new (ERROR_TYPES[value[1]] || Error)(value[2]);
|
|
1268
|
-
if (typeof value[3] === "string") result.stack = value[3];
|
|
1269
|
-
return result;
|
|
1270
|
-
}
|
|
1271
|
-
break;
|
|
1272
|
-
case "undefined":
|
|
1273
|
-
if (value.length === 1) return;
|
|
1274
|
-
break;
|
|
1275
|
-
case "inf": return Infinity;
|
|
1276
|
-
case "-inf": return -Infinity;
|
|
1277
|
-
case "nan": return NaN;
|
|
1278
|
-
case "import":
|
|
1279
|
-
case "pipeline": {
|
|
1280
|
-
if (value.length < 2 || value.length > 4) break;
|
|
1281
|
-
if (typeof value[1] != "number") break;
|
|
1282
|
-
let hook = this.importer.getExport(value[1]);
|
|
1283
|
-
if (!hook) throw new Error(`no such entry on exports table: ${value[1]}`);
|
|
1284
|
-
let isPromise = value[0] == "pipeline";
|
|
1285
|
-
let addStub = (hook2) => {
|
|
1286
|
-
const unwrapped = maybeUnwrapStubHook(hook2);
|
|
1287
|
-
if (unwrapped) {
|
|
1288
|
-
hook2.dispose();
|
|
1289
|
-
return unwrapped;
|
|
1290
|
-
}
|
|
1291
|
-
if (isPromise) {
|
|
1292
|
-
let promise = new RpcPromise(hook2, []);
|
|
1293
|
-
this.promises.push({
|
|
1294
|
-
promise,
|
|
1295
|
-
parent,
|
|
1296
|
-
property
|
|
1297
|
-
});
|
|
1298
|
-
return promise;
|
|
1299
|
-
} else {
|
|
1300
|
-
let stub = new RpcPromise(hook2, []);
|
|
1301
|
-
this.stubs.push(stub);
|
|
1302
|
-
return stub;
|
|
1303
|
-
}
|
|
1304
|
-
};
|
|
1305
|
-
if (value.length == 2) if (isPromise) return addStub(hook.get([]));
|
|
1306
|
-
else return addStub(hook.dup());
|
|
1307
|
-
let path = value[2];
|
|
1308
|
-
if (!(path instanceof Array)) break;
|
|
1309
|
-
if (!path.every((part) => {
|
|
1310
|
-
return typeof part == "string" || typeof part == "number";
|
|
1311
|
-
})) break;
|
|
1312
|
-
if (value.length == 3) return addStub(hook.get(path));
|
|
1313
|
-
let args = value[3];
|
|
1314
|
-
if (!(args instanceof Array)) break;
|
|
1315
|
-
args = new _Evaluator(this.importer).evaluate([args]);
|
|
1316
|
-
return addStub(hook.call(path, args));
|
|
1317
|
-
}
|
|
1318
|
-
case "remap": {
|
|
1319
|
-
if (value.length !== 5 || typeof value[1] !== "number" || !(value[2] instanceof Array) || !(value[3] instanceof Array) || !(value[4] instanceof Array)) break;
|
|
1320
|
-
let hook = this.importer.getExport(value[1]);
|
|
1321
|
-
if (!hook) throw new Error(`no such entry on exports table: ${value[1]}`);
|
|
1322
|
-
let path = value[2];
|
|
1323
|
-
if (!path.every((part) => {
|
|
1324
|
-
return typeof part == "string" || typeof part == "number";
|
|
1325
|
-
})) break;
|
|
1326
|
-
let captures = this.resolveCaptures(value[3]);
|
|
1327
|
-
let instructions = value[4];
|
|
1328
|
-
let promise = new RpcPromise(hook.map(path, captures, instructions), []);
|
|
1329
|
-
this.promises.push({
|
|
1330
|
-
promise,
|
|
1331
|
-
parent,
|
|
1332
|
-
property
|
|
1333
|
-
});
|
|
1334
|
-
return promise;
|
|
1335
|
-
}
|
|
1336
|
-
case "export":
|
|
1337
|
-
case "promise":
|
|
1338
|
-
if (typeof value[1] == "number") if (value[0] == "promise") {
|
|
1339
|
-
let promise = new RpcPromise(this.importer.importPromise(value[1]), []);
|
|
1340
|
-
this.promises.push({
|
|
1341
|
-
parent,
|
|
1342
|
-
property,
|
|
1343
|
-
promise
|
|
1344
|
-
});
|
|
1345
|
-
return promise;
|
|
1346
|
-
} else {
|
|
1347
|
-
let stub = new RpcStub(this.importer.importStub(value[1]));
|
|
1348
|
-
this.stubs.push(stub);
|
|
1349
|
-
return stub;
|
|
1350
|
-
}
|
|
1351
|
-
break;
|
|
1352
|
-
}
|
|
1353
|
-
throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
|
|
1354
|
-
} else if (value instanceof Object) {
|
|
1355
|
-
let result = value;
|
|
1356
|
-
for (let key in result) if (key in Object.prototype || key === "toJSON") {
|
|
1357
|
-
this.evaluateImpl(result[key], result, key);
|
|
1358
|
-
delete result[key];
|
|
1359
|
-
} else result[key] = this.evaluateImpl(result[key], result, key);
|
|
1360
|
-
return result;
|
|
1361
|
-
} else return value;
|
|
1362
|
-
}
|
|
1363
|
-
};
|
|
1364
|
-
var maybeUnwrapStubHook = (hook) => {
|
|
1365
|
-
if (!(hook instanceof PayloadStubHook)) return;
|
|
1366
|
-
const payload = hook.getPayload();
|
|
1367
|
-
if (payload.value instanceof RpcStub) {
|
|
1368
|
-
const { hook: innerHook, pathIfPromise } = unwrapStubAndPath(payload.value);
|
|
1369
|
-
if (pathIfPromise == null && innerHook instanceof TargetStubHook) return innerHook.getTarget();
|
|
1370
|
-
else return innerHook;
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
var RpcTarget4 = RpcTarget;
|
|
1374
|
-
|
|
1375
|
-
//#endregion
|
|
1376
8
|
//#region src/rpc-toolset.ts
|
|
1377
9
|
const validate = (schema, value) => {
|
|
1378
10
|
if ("~standard" in schema) {
|
|
@@ -1460,7 +92,7 @@ const tool = toolDef;
|
|
|
1460
92
|
tool.callback = callbackTool;
|
|
1461
93
|
tool.unwrap = unwrapCallback;
|
|
1462
94
|
tool.unsafeNoValidation = toolUnsafeNoValidation;
|
|
1463
|
-
var RpcToolset = class RpcToolset extends
|
|
95
|
+
var RpcToolset = class RpcToolset extends RpcTarget {
|
|
1464
96
|
constructor() {
|
|
1465
97
|
super();
|
|
1466
98
|
let prototype = Object.getPrototypeOf(this);
|
|
@@ -1923,7 +555,16 @@ var Database = class {
|
|
|
1923
555
|
async execute(query) {
|
|
1924
556
|
if (this.kysely == null) this.kysely = new Kysely({ dialect: this.dialect });
|
|
1925
557
|
if (this.opts?.logQuery) this.opts.logQuery(query.compile(this.kysely));
|
|
1926
|
-
|
|
558
|
+
const result = await query.execute(this.kysely);
|
|
559
|
+
if (this.opts?.returnExecutedQuery) {
|
|
560
|
+
const compiled = query.compile(this.kysely);
|
|
561
|
+
return {
|
|
562
|
+
results: result.rows,
|
|
563
|
+
sql: compiled.sql,
|
|
564
|
+
parameters: compiled.parameters
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
return { results: result.rows };
|
|
1927
568
|
}
|
|
1928
569
|
Table(name) {
|
|
1929
570
|
return table(this, name);
|