capnweb 0.0.0-b2fcb34 → 0.0.0-db952ec

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.
@@ -1,19 +1,32 @@
1
1
  import * as cfw from 'cloudflare:workers';
2
2
 
3
3
  // src/symbols.ts
4
- var WORKERS_MODULE_SYMBOL = Symbol("workers-module");
4
+ var WORKERS_MODULE_SYMBOL = /* @__PURE__ */ Symbol("workers-module");
5
5
  globalThis[WORKERS_MODULE_SYMBOL] = cfw;
6
6
 
7
7
  // src/core.ts
8
8
  if (!Symbol.dispose) {
9
- Symbol.dispose = Symbol.for("dispose");
9
+ Symbol.dispose = /* @__PURE__ */ Symbol.for("dispose");
10
10
  }
11
11
  if (!Symbol.asyncDispose) {
12
- Symbol.asyncDispose = Symbol.for("asyncDispose");
12
+ Symbol.asyncDispose = /* @__PURE__ */ Symbol.for("asyncDispose");
13
+ }
14
+ if (!Promise.withResolvers) {
15
+ Promise.withResolvers = function() {
16
+ let resolve;
17
+ let reject;
18
+ const promise = new Promise((res, rej) => {
19
+ resolve = res;
20
+ reject = rej;
21
+ });
22
+ return { promise, resolve, reject };
23
+ };
13
24
  }
14
25
  var workersModule = globalThis[WORKERS_MODULE_SYMBOL];
15
26
  var RpcTarget = workersModule ? workersModule.RpcTarget : class {
16
27
  };
28
+ var AsyncFunction = (async function() {
29
+ }).constructor;
17
30
  function typeForRpc(value) {
18
31
  switch (typeof value) {
19
32
  case "boolean":
@@ -38,6 +51,7 @@ function typeForRpc(value) {
38
51
  case Object.prototype:
39
52
  return "object";
40
53
  case Function.prototype:
54
+ case AsyncFunction.prototype:
41
55
  return "function";
42
56
  case Array.prototype:
43
57
  return "array";
@@ -121,7 +135,7 @@ function withCallInterceptor(interceptor, callback) {
121
135
  doCall = oldValue;
122
136
  }
123
137
  }
124
- var RAW_STUB = Symbol("realStub");
138
+ var RAW_STUB = /* @__PURE__ */ Symbol("realStub");
125
139
  var PROXY_HANDLERS = {
126
140
  apply(target, thisArg, argumentsList) {
127
141
  let stub = target.raw;
@@ -236,6 +250,9 @@ var RpcStub = class _RpcStub extends RpcTarget {
236
250
  let { hook, pathIfPromise } = this[RAW_STUB];
237
251
  return mapImpl.sendMap(hook, pathIfPromise || [], func);
238
252
  }
253
+ toString() {
254
+ return "[object RpcStub]";
255
+ }
239
256
  };
240
257
  var RpcPromise = class extends RpcStub {
241
258
  // TODO: Support passing target value or promise to constructor.
@@ -251,6 +268,9 @@ var RpcPromise = class extends RpcStub {
251
268
  finally(onfinally) {
252
269
  return pullPromise(this).finally(...arguments);
253
270
  }
271
+ toString() {
272
+ return "[object RpcPromise]";
273
+ }
254
274
  };
255
275
  function unwrapStubTakingOwnership(stub) {
256
276
  let { hook, pathIfPromise } = stub[RAW_STUB];
@@ -383,6 +403,12 @@ var RpcPayload = class _RpcPayload {
383
403
  // Get the StubHook representing the given RpcTarget found inside this payload.
384
404
  getHookForRpcTarget(target, parent, dupStubs = true) {
385
405
  if (this.source === "params") {
406
+ if (dupStubs) {
407
+ let dupable = target;
408
+ if (typeof dupable.dup === "function") {
409
+ target = dupable.dup();
410
+ }
411
+ }
386
412
  return TargetStubHook.create(target, parent);
387
413
  } else if (this.source === "return") {
388
414
  let hook = this.rpcTargets?.get(target);
@@ -748,7 +774,9 @@ function followPath(value, parent, path, owner) {
748
774
  case "rpc-target":
749
775
  case "rpc-thenable": {
750
776
  if (Object.hasOwn(value, part)) {
751
- value = void 0;
777
+ throw new TypeError(
778
+ `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.`
779
+ );
752
780
  } else {
753
781
  value = value[part];
754
782
  }
@@ -1132,7 +1160,17 @@ var Devaluator = class _Devaluator {
1132
1160
  throw new TypeError(msg);
1133
1161
  }
1134
1162
  case "primitive":
1135
- return value;
1163
+ if (typeof value === "number" && !isFinite(value)) {
1164
+ if (value === Infinity) {
1165
+ return ["inf"];
1166
+ } else if (value === -Infinity) {
1167
+ return ["-inf"];
1168
+ } else {
1169
+ return ["nan"];
1170
+ }
1171
+ } else {
1172
+ return value;
1173
+ }
1136
1174
  case "object": {
1137
1175
  let object = value;
1138
1176
  let result = {};
@@ -1316,6 +1354,12 @@ var Evaluator = class _Evaluator {
1316
1354
  return void 0;
1317
1355
  }
1318
1356
  break;
1357
+ case "inf":
1358
+ return Infinity;
1359
+ case "-inf":
1360
+ return -Infinity;
1361
+ case "nan":
1362
+ return NaN;
1319
1363
  case "import":
1320
1364
  case "pipeline": {
1321
1365
  if (value.length < 2 || value.length > 4) {