capnweb 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,29 @@
1
+ // src/symbols.ts
2
+ var WORKERS_MODULE_SYMBOL = /* @__PURE__ */ Symbol("workers-module");
3
+
1
4
  // src/core.ts
2
5
  if (!Symbol.dispose) {
3
- Symbol.dispose = Symbol.for("dispose");
6
+ Symbol.dispose = /* @__PURE__ */ Symbol.for("dispose");
4
7
  }
5
8
  if (!Symbol.asyncDispose) {
6
- Symbol.asyncDispose = Symbol.for("asyncDispose");
9
+ Symbol.asyncDispose = /* @__PURE__ */ Symbol.for("asyncDispose");
7
10
  }
8
- var workersModuleName = navigator.userAgent === "Cloudflare-Workers" ? "cloudflare:workers" : null;
9
- var workersModule;
10
- if (workersModuleName) {
11
- workersModule = await import(
12
- /* @vite-ignore */
13
- workersModuleName
14
- );
11
+ if (!Promise.withResolvers) {
12
+ Promise.withResolvers = function() {
13
+ let resolve;
14
+ let reject;
15
+ const promise = new Promise((res, rej) => {
16
+ resolve = res;
17
+ reject = rej;
18
+ });
19
+ return { promise, resolve, reject };
20
+ };
15
21
  }
22
+ var workersModule = globalThis[WORKERS_MODULE_SYMBOL];
16
23
  var RpcTarget = workersModule ? workersModule.RpcTarget : class {
17
24
  };
25
+ var AsyncFunction = (async function() {
26
+ }).constructor;
18
27
  function typeForRpc(value) {
19
28
  switch (typeof value) {
20
29
  case "boolean":
@@ -39,6 +48,7 @@ function typeForRpc(value) {
39
48
  case Object.prototype:
40
49
  return "object";
41
50
  case Function.prototype:
51
+ case AsyncFunction.prototype:
42
52
  return "function";
43
53
  case Array.prototype:
44
54
  return "array";
@@ -122,7 +132,7 @@ function withCallInterceptor(interceptor, callback) {
122
132
  doCall = oldValue;
123
133
  }
124
134
  }
125
- var RAW_STUB = Symbol("realStub");
135
+ var RAW_STUB = /* @__PURE__ */ Symbol("realStub");
126
136
  var PROXY_HANDLERS = {
127
137
  apply(target, thisArg, argumentsList) {
128
138
  let stub = target.raw;
@@ -237,6 +247,9 @@ var RpcStub = class _RpcStub extends RpcTarget {
237
247
  let { hook, pathIfPromise } = this[RAW_STUB];
238
248
  return mapImpl.sendMap(hook, pathIfPromise || [], func);
239
249
  }
250
+ toString() {
251
+ return "[object RpcStub]";
252
+ }
240
253
  };
241
254
  var RpcPromise = class extends RpcStub {
242
255
  // TODO: Support passing target value or promise to constructor.
@@ -252,6 +265,9 @@ var RpcPromise = class extends RpcStub {
252
265
  finally(onfinally) {
253
266
  return pullPromise(this).finally(...arguments);
254
267
  }
268
+ toString() {
269
+ return "[object RpcPromise]";
270
+ }
255
271
  };
256
272
  function unwrapStubTakingOwnership(stub) {
257
273
  let { hook, pathIfPromise } = stub[RAW_STUB];
@@ -311,7 +327,7 @@ var RpcPayload = class _RpcPayload {
311
327
  // Create a payload from a value return from an RPC implementation by the app.
312
328
  //
313
329
  // Unlike fromAppParams(), in this case the payload takes ownership of all stubs in `value`, and
314
- // may hold onto `value` for an arbitarily long time (e.g. to serve pipelined requests). It
330
+ // may hold onto `value` for an arbitrarily long time (e.g. to serve pipelined requests). It
315
331
  // will still avoid modifying `value` and will make a deep copy if it is delivered locally.
316
332
  static fromAppReturn(value) {
317
333
  return new _RpcPayload(value, "return");
@@ -375,7 +391,7 @@ var RpcPayload = class _RpcPayload {
375
391
  );
376
392
  return result;
377
393
  }
378
- // For `soruce === "return"` payloads only, this tracks any StubHooks created around RpcTargets
394
+ // For `source === "return"` payloads only, this tracks any StubHooks created around RpcTargets
379
395
  // found in the payload at the time that it is serialized (or deep-copied) for return, so that we
380
396
  // can make sure they are not disposed before the pipeline ends.
381
397
  //
@@ -749,7 +765,9 @@ function followPath(value, parent, path, owner) {
749
765
  case "rpc-target":
750
766
  case "rpc-thenable": {
751
767
  if (Object.hasOwn(value, part)) {
752
- value = void 0;
768
+ throw new TypeError(
769
+ `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.`
770
+ );
753
771
  } else {
754
772
  value = value[part];
755
773
  }
@@ -1133,7 +1151,17 @@ var Devaluator = class _Devaluator {
1133
1151
  throw new TypeError(msg);
1134
1152
  }
1135
1153
  case "primitive":
1136
- return value;
1154
+ if (typeof value === "number" && !isFinite(value)) {
1155
+ if (value === Infinity) {
1156
+ return ["inf"];
1157
+ } else if (value === -Infinity) {
1158
+ return ["-inf"];
1159
+ } else {
1160
+ return ["nan"];
1161
+ }
1162
+ } else {
1163
+ return value;
1164
+ }
1137
1165
  case "object": {
1138
1166
  let object = value;
1139
1167
  let result = {};
@@ -1317,6 +1345,12 @@ var Evaluator = class _Evaluator {
1317
1345
  return void 0;
1318
1346
  }
1319
1347
  break;
1348
+ case "inf":
1349
+ return Infinity;
1350
+ case "-inf":
1351
+ return -Infinity;
1352
+ case "nan":
1353
+ return NaN;
1320
1354
  case "import":
1321
1355
  case "pipeline": {
1322
1356
  if (value.length < 2 || value.length > 4) {