@async/framework 0.11.6 → 0.11.7

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/server.js CHANGED
@@ -2380,9 +2380,10 @@ const __componentModule = (() => {
2380
2380
  })();
2381
2381
 
2382
2382
  const __serverModule = (() => {
2383
- const serverEnvelopeKeys = new Set(["value", "signals", "boundary", "html", "redirect", "error"]);
2383
+ const serverEnvelopeKind = Symbol.for("@async/framework.serverResult");
2384
+ const serverEnvelopeWireKey = "__async_server_result__";
2385
+ const serverEnvelopeWireVersion = 1;
2384
2386
  const appliedServerResult = Symbol.for("@async/framework.appliedServerResult");
2385
- const appliedServerValues = new WeakSet();
2386
2387
 
2387
2388
  function createServerProxy({
2388
2389
  endpoint = "/__async/server",
@@ -2425,9 +2426,7 @@ const __serverModule = (() => {
2425
2426
  throw new Error(`Server function "${id}" failed with ${response.status}.`);
2426
2427
  }
2427
2428
 
2428
- const result = await readServerResponse(id, response);
2429
- await applyServerResult(result, runContext);
2430
- return markAppliedServerValue(unwrapServerResult(result));
2429
+ return consumeServerResult(await readServerResponse(id, response), runContext);
2431
2430
  }
2432
2431
 
2433
2432
  return createServerNamespace(run, {
@@ -2462,7 +2461,7 @@ const __serverModule = (() => {
2462
2461
  if (!isServerEnvelope(result)) {
2463
2462
  return result;
2464
2463
  }
2465
- if (result[appliedServerResult] || appliedServerValues.has(result)) {
2464
+ if (result[appliedServerResult]) {
2466
2465
  return result;
2467
2466
  }
2468
2467
 
@@ -2494,18 +2493,16 @@ const __serverModule = (() => {
2494
2493
  return result;
2495
2494
  }
2496
2495
 
2497
- function unwrapServerResult(result) {
2498
- if (isServerEnvelope(result) && Object.hasOwn(result, "value")) {
2499
- return result.value;
2500
- }
2501
- return result;
2496
+ async function consumeServerResult(result, context = {}) {
2497
+ await applyServerResult(result, context);
2498
+ return unwrapServerResult(result);
2502
2499
  }
2503
2500
 
2504
- function markAppliedServerValue(value) {
2505
- if (value && typeof value === "object") {
2506
- appliedServerValues.add(value);
2501
+ function unwrapServerResult(result) {
2502
+ if (isServerEnvelope(result)) {
2503
+ return Object.hasOwn(result, "value") ? result.value : undefined;
2507
2504
  }
2508
- return value;
2505
+ return result;
2509
2506
  }
2510
2507
 
2511
2508
  function markAppliedServerResult(result) {
@@ -2549,9 +2546,7 @@ const __serverModule = (() => {
2549
2546
  throw new Error("Server namespace is not directly callable.");
2550
2547
  }
2551
2548
  const context = contextProvider() ?? {};
2552
- const result = await run(parts.join("."), args, context);
2553
- await applyServerResult(result, context);
2554
- return unwrapServerResult(result);
2549
+ return run(parts.join("."), args, context);
2555
2550
  };
2556
2551
 
2557
2552
  const proxy = new Proxy(callable, {
@@ -2608,7 +2603,7 @@ const __serverModule = (() => {
2608
2603
 
2609
2604
  async function readServerResponse(id, response) {
2610
2605
  if (response.status === 204) {
2611
- return { value: undefined };
2606
+ return undefined;
2612
2607
  }
2613
2608
  const type = response.headers.get("content-type") ?? "";
2614
2609
  if (type.includes("application/json")) {
@@ -2626,7 +2621,7 @@ const __serverModule = (() => {
2626
2621
  if (typeof response.text !== "function") {
2627
2622
  throw new Error(`Server function "${id}" transport returned an invalid response: missing text().`);
2628
2623
  }
2629
- return { value: await response.text() };
2624
+ return response.text();
2630
2625
  }
2631
2626
 
2632
2627
  function snapshotSignalPaths(paths = [], signals) {
@@ -2771,7 +2766,8 @@ const __serverModule = (() => {
2771
2766
  if (!value || typeof value !== "object" || Array.isArray(value)) {
2772
2767
  return false;
2773
2768
  }
2774
- return Object.keys(value).some((key) => serverEnvelopeKeys.has(key));
2769
+ return value[serverEnvelopeKind] === true
2770
+ || value[serverEnvelopeWireKey] === serverEnvelopeWireVersion;
2775
2771
  }
2776
2772
 
2777
2773
  function toError(value) {
@@ -2793,11 +2789,11 @@ const __serverModule = (() => {
2793
2789
  throw new TypeError("Server function id must be a non-empty string.");
2794
2790
  }
2795
2791
  }
2796
- return { createServerProxy, resolveServerCommandArguments, applyServerResult, unwrapServerResult, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2792
+ return { createServerProxy, resolveServerCommandArguments, applyServerResult, consumeServerResult, unwrapServerResult, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2797
2793
  })();
2798
2794
 
2799
2795
  const __handlersModule = (() => {
2800
- const { applyServerResult, defaultInput, resolveServerCommandArguments, unwrapServerResult } = __serverModule;
2796
+ const { defaultInput, resolveServerCommandArguments } = __serverModule;
2801
2797
  const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
2802
2798
  const { createLazyRegistry, isLazyDescriptor } = __lazyRegistryModule;
2803
2799
  const builtInTokens = new Set(["prevent", "preventDefault", "stopPropagation", "stopImmediatePropagation"]);
@@ -2895,8 +2891,7 @@ const __handlersModule = (() => {
2895
2891
  signalPaths: resolved.signalPaths,
2896
2892
  signalValues: resolved.signalValues
2897
2893
  });
2898
- await applyServerResult(result, runContext);
2899
- results.push(unwrapServerResult(result));
2894
+ results.push(result);
2900
2895
  continue;
2901
2896
  }
2902
2897
 
@@ -5751,7 +5746,7 @@ const __requestContextModule = (() => {
5751
5746
  const __serverRegistryModule = (() => {
5752
5747
  const { readRequestContext } = __requestContextModule;
5753
5748
  const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
5754
- const { assertServerId, createServerNamespace, createSignalReader } = __serverModule;
5749
+ const { assertServerId, consumeServerResult, createServerNamespace, createSignalReader } = __serverModule;
5755
5750
  function createServerRegistry(initialMap = {}, options = {}) {
5756
5751
  const registryStore = options.registry ?? createRegistryStore();
5757
5752
  const type = options.type ?? "server";
@@ -5817,7 +5812,7 @@ const __serverRegistryModule = (() => {
5817
5812
  server
5818
5813
  };
5819
5814
 
5820
- return fn.call(runContext, ...args);
5815
+ return consumeServerResult(await fn.call(runContext, ...args), runContext);
5821
5816
  },
5822
5817
 
5823
5818
  _setContext(context = {}) {