@async/framework 0.11.6 → 0.11.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/browser.ts CHANGED
@@ -2379,9 +2379,10 @@ const __componentModule = (() => {
2379
2379
  })();
2380
2380
 
2381
2381
  const __serverModule = (() => {
2382
- const serverEnvelopeKeys = new Set(["value", "signals", "boundary", "html", "redirect", "error"]);
2383
- const appliedServerResult = Symbol.for("@async/framework.appliedServerResult");
2384
- const appliedServerValues = new WeakSet();
2382
+ const serverEnvelopeKind = Symbol.for("@async/framework.serverResult");
2383
+ const serverEnvelopeWireKey = "__async_server_result__";
2384
+ const serverEnvelopeWireVersion = 1;
2385
+ const serverResultInvocation = Symbol("@async/framework.serverResultInvocation");
2385
2386
 
2386
2387
  function createServerProxy({
2387
2388
  endpoint = "/__async/server",
@@ -2401,7 +2402,7 @@ const __serverModule = (() => {
2401
2402
 
2402
2403
  async function run(id, args = [], context = {}) {
2403
2404
  assertServerId(id);
2404
- const runContext = { ...defaults, ...context };
2405
+ const runContext = createServerResultContext({ ...defaults, ...context });
2405
2406
  const body = {
2406
2407
  args,
2407
2408
  input: context.input ?? defaultInput(runContext),
@@ -2424,9 +2425,7 @@ const __serverModule = (() => {
2424
2425
  throw new Error(`Server function "${id}" failed with ${response.status}.`);
2425
2426
  }
2426
2427
 
2427
- const result = await readServerResponse(id, response);
2428
- await applyServerResult(result, runContext);
2429
- return markAppliedServerValue(unwrapServerResult(result));
2428
+ return consumeServerResult(await readServerResponse(id, response), runContext);
2430
2429
  }
2431
2430
 
2432
2431
  return createServerNamespace(run, {
@@ -2461,12 +2460,13 @@ const __serverModule = (() => {
2461
2460
  if (!isServerEnvelope(result)) {
2462
2461
  return result;
2463
2462
  }
2464
- if (result[appliedServerResult] || appliedServerValues.has(result)) {
2463
+ const invocation = getServerResultInvocation(context);
2464
+ if (invocation.applied.has(result)) {
2465
2465
  return result;
2466
2466
  }
2467
+ invocation.applied.add(result);
2467
2468
 
2468
2469
  if (result.error) {
2469
- markAppliedServerResult(result);
2470
2470
  throw toError(result.error);
2471
2471
  }
2472
2472
 
@@ -2488,32 +2488,35 @@ const __serverModule = (() => {
2488
2488
  await context.router?.navigate?.(result.redirect);
2489
2489
  }
2490
2490
 
2491
- markAppliedServerResult(result);
2492
-
2493
2491
  return result;
2494
2492
  }
2495
2493
 
2494
+ async function consumeServerResult(result, context = {}) {
2495
+ await applyServerResult(result, context);
2496
+ return unwrapServerResult(result);
2497
+ }
2498
+
2496
2499
  function unwrapServerResult(result) {
2497
- if (isServerEnvelope(result) && Object.hasOwn(result, "value")) {
2498
- return result.value;
2500
+ if (isServerEnvelope(result)) {
2501
+ return Object.hasOwn(result, "value") ? result.value : undefined;
2499
2502
  }
2500
2503
  return result;
2501
2504
  }
2502
2505
 
2503
- function markAppliedServerValue(value) {
2504
- if (value && typeof value === "object") {
2505
- appliedServerValues.add(value);
2506
- }
2507
- return value;
2506
+ function createServerResultContext(context = {}) {
2507
+ const invocation = context[serverResultInvocation] ?? {
2508
+ applied: new WeakSet()
2509
+ };
2510
+ return {
2511
+ ...context,
2512
+ [serverResultInvocation]: invocation
2513
+ };
2508
2514
  }
2509
2515
 
2510
- function markAppliedServerResult(result) {
2511
- Object.defineProperty(result, appliedServerResult, {
2512
- configurable: true,
2513
- enumerable: false,
2514
- value: true
2515
- });
2516
- return result;
2516
+ function getServerResultInvocation(context = {}) {
2517
+ return context[serverResultInvocation] ?? {
2518
+ applied: new WeakSet()
2519
+ };
2517
2520
  }
2518
2521
 
2519
2522
  function defaultInput(context = {}) {
@@ -2548,9 +2551,7 @@ const __serverModule = (() => {
2548
2551
  throw new Error("Server namespace is not directly callable.");
2549
2552
  }
2550
2553
  const context = contextProvider() ?? {};
2551
- const result = await run(parts.join("."), args, context);
2552
- await applyServerResult(result, context);
2553
- return unwrapServerResult(result);
2554
+ return run(parts.join("."), args, context);
2554
2555
  };
2555
2556
 
2556
2557
  const proxy = new Proxy(callable, {
@@ -2607,7 +2608,7 @@ const __serverModule = (() => {
2607
2608
 
2608
2609
  async function readServerResponse(id, response) {
2609
2610
  if (response.status === 204) {
2610
- return { value: undefined };
2611
+ return undefined;
2611
2612
  }
2612
2613
  const type = response.headers.get("content-type") ?? "";
2613
2614
  if (type.includes("application/json")) {
@@ -2625,7 +2626,7 @@ const __serverModule = (() => {
2625
2626
  if (typeof response.text !== "function") {
2626
2627
  throw new Error(`Server function "${id}" transport returned an invalid response: missing text().`);
2627
2628
  }
2628
- return { value: await response.text() };
2629
+ return response.text();
2629
2630
  }
2630
2631
 
2631
2632
  function snapshotSignalPaths(paths = [], signals) {
@@ -2770,7 +2771,8 @@ const __serverModule = (() => {
2770
2771
  if (!value || typeof value !== "object" || Array.isArray(value)) {
2771
2772
  return false;
2772
2773
  }
2773
- return Object.keys(value).some((key) => serverEnvelopeKeys.has(key));
2774
+ return value[serverEnvelopeKind] === true
2775
+ || value[serverEnvelopeWireKey] === serverEnvelopeWireVersion;
2774
2776
  }
2775
2777
 
2776
2778
  function toError(value) {
@@ -2792,11 +2794,11 @@ const __serverModule = (() => {
2792
2794
  throw new TypeError("Server function id must be a non-empty string.");
2793
2795
  }
2794
2796
  }
2795
- return { createServerProxy, resolveServerCommandArguments, applyServerResult, unwrapServerResult, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2797
+ return { createServerProxy, resolveServerCommandArguments, applyServerResult, consumeServerResult, unwrapServerResult, createServerResultContext, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2796
2798
  })();
2797
2799
 
2798
2800
  const __handlersModule = (() => {
2799
- const { applyServerResult, defaultInput, resolveServerCommandArguments, unwrapServerResult } = __serverModule;
2801
+ const { defaultInput, resolveServerCommandArguments } = __serverModule;
2800
2802
  const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
2801
2803
  const { createLazyRegistry, isLazyDescriptor } = __lazyRegistryModule;
2802
2804
  const builtInTokens = new Set(["prevent", "preventDefault", "stopPropagation", "stopImmediatePropagation"]);
@@ -2894,8 +2896,7 @@ const __handlersModule = (() => {
2894
2896
  signalPaths: resolved.signalPaths,
2895
2897
  signalValues: resolved.signalValues
2896
2898
  });
2897
- await applyServerResult(result, runContext);
2898
- results.push(unwrapServerResult(result));
2899
+ results.push(result);
2899
2900
  continue;
2900
2901
  }
2901
2902
 
package/browser.umd.js CHANGED
@@ -2389,9 +2389,10 @@
2389
2389
  })();
2390
2390
 
2391
2391
  const __serverModule = (() => {
2392
- const serverEnvelopeKeys = new Set(["value", "signals", "boundary", "html", "redirect", "error"]);
2393
- const appliedServerResult = Symbol.for("@async/framework.appliedServerResult");
2394
- const appliedServerValues = new WeakSet();
2392
+ const serverEnvelopeKind = Symbol.for("@async/framework.serverResult");
2393
+ const serverEnvelopeWireKey = "__async_server_result__";
2394
+ const serverEnvelopeWireVersion = 1;
2395
+ const serverResultInvocation = Symbol("@async/framework.serverResultInvocation");
2395
2396
 
2396
2397
  function createServerProxy({
2397
2398
  endpoint = "/__async/server",
@@ -2411,7 +2412,7 @@
2411
2412
 
2412
2413
  async function run(id, args = [], context = {}) {
2413
2414
  assertServerId(id);
2414
- const runContext = { ...defaults, ...context };
2415
+ const runContext = createServerResultContext({ ...defaults, ...context });
2415
2416
  const body = {
2416
2417
  args,
2417
2418
  input: context.input ?? defaultInput(runContext),
@@ -2434,9 +2435,7 @@
2434
2435
  throw new Error(`Server function "${id}" failed with ${response.status}.`);
2435
2436
  }
2436
2437
 
2437
- const result = await readServerResponse(id, response);
2438
- await applyServerResult(result, runContext);
2439
- return markAppliedServerValue(unwrapServerResult(result));
2438
+ return consumeServerResult(await readServerResponse(id, response), runContext);
2440
2439
  }
2441
2440
 
2442
2441
  return createServerNamespace(run, {
@@ -2471,12 +2470,13 @@
2471
2470
  if (!isServerEnvelope(result)) {
2472
2471
  return result;
2473
2472
  }
2474
- if (result[appliedServerResult] || appliedServerValues.has(result)) {
2473
+ const invocation = getServerResultInvocation(context);
2474
+ if (invocation.applied.has(result)) {
2475
2475
  return result;
2476
2476
  }
2477
+ invocation.applied.add(result);
2477
2478
 
2478
2479
  if (result.error) {
2479
- markAppliedServerResult(result);
2480
2480
  throw toError(result.error);
2481
2481
  }
2482
2482
 
@@ -2498,32 +2498,35 @@
2498
2498
  await context.router?.navigate?.(result.redirect);
2499
2499
  }
2500
2500
 
2501
- markAppliedServerResult(result);
2502
-
2503
2501
  return result;
2504
2502
  }
2505
2503
 
2504
+ async function consumeServerResult(result, context = {}) {
2505
+ await applyServerResult(result, context);
2506
+ return unwrapServerResult(result);
2507
+ }
2508
+
2506
2509
  function unwrapServerResult(result) {
2507
- if (isServerEnvelope(result) && Object.hasOwn(result, "value")) {
2508
- return result.value;
2510
+ if (isServerEnvelope(result)) {
2511
+ return Object.hasOwn(result, "value") ? result.value : undefined;
2509
2512
  }
2510
2513
  return result;
2511
2514
  }
2512
2515
 
2513
- function markAppliedServerValue(value) {
2514
- if (value && typeof value === "object") {
2515
- appliedServerValues.add(value);
2516
- }
2517
- return value;
2516
+ function createServerResultContext(context = {}) {
2517
+ const invocation = context[serverResultInvocation] ?? {
2518
+ applied: new WeakSet()
2519
+ };
2520
+ return {
2521
+ ...context,
2522
+ [serverResultInvocation]: invocation
2523
+ };
2518
2524
  }
2519
2525
 
2520
- function markAppliedServerResult(result) {
2521
- Object.defineProperty(result, appliedServerResult, {
2522
- configurable: true,
2523
- enumerable: false,
2524
- value: true
2525
- });
2526
- return result;
2526
+ function getServerResultInvocation(context = {}) {
2527
+ return context[serverResultInvocation] ?? {
2528
+ applied: new WeakSet()
2529
+ };
2527
2530
  }
2528
2531
 
2529
2532
  function defaultInput(context = {}) {
@@ -2558,9 +2561,7 @@
2558
2561
  throw new Error("Server namespace is not directly callable.");
2559
2562
  }
2560
2563
  const context = contextProvider() ?? {};
2561
- const result = await run(parts.join("."), args, context);
2562
- await applyServerResult(result, context);
2563
- return unwrapServerResult(result);
2564
+ return run(parts.join("."), args, context);
2564
2565
  };
2565
2566
 
2566
2567
  const proxy = new Proxy(callable, {
@@ -2617,7 +2618,7 @@
2617
2618
 
2618
2619
  async function readServerResponse(id, response) {
2619
2620
  if (response.status === 204) {
2620
- return { value: undefined };
2621
+ return undefined;
2621
2622
  }
2622
2623
  const type = response.headers.get("content-type") ?? "";
2623
2624
  if (type.includes("application/json")) {
@@ -2635,7 +2636,7 @@
2635
2636
  if (typeof response.text !== "function") {
2636
2637
  throw new Error(`Server function "${id}" transport returned an invalid response: missing text().`);
2637
2638
  }
2638
- return { value: await response.text() };
2639
+ return response.text();
2639
2640
  }
2640
2641
 
2641
2642
  function snapshotSignalPaths(paths = [], signals) {
@@ -2780,7 +2781,8 @@
2780
2781
  if (!value || typeof value !== "object" || Array.isArray(value)) {
2781
2782
  return false;
2782
2783
  }
2783
- return Object.keys(value).some((key) => serverEnvelopeKeys.has(key));
2784
+ return value[serverEnvelopeKind] === true
2785
+ || value[serverEnvelopeWireKey] === serverEnvelopeWireVersion;
2784
2786
  }
2785
2787
 
2786
2788
  function toError(value) {
@@ -2802,11 +2804,11 @@
2802
2804
  throw new TypeError("Server function id must be a non-empty string.");
2803
2805
  }
2804
2806
  }
2805
- return { createServerProxy, resolveServerCommandArguments, applyServerResult, unwrapServerResult, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2807
+ return { createServerProxy, resolveServerCommandArguments, applyServerResult, consumeServerResult, unwrapServerResult, createServerResultContext, defaultInput, createServerNamespace, createSignalReader, assertServerId };
2806
2808
  })();
2807
2809
 
2808
2810
  const __handlersModule = (() => {
2809
- const { applyServerResult, defaultInput, resolveServerCommandArguments, unwrapServerResult } = __serverModule;
2811
+ const { defaultInput, resolveServerCommandArguments } = __serverModule;
2810
2812
  const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
2811
2813
  const { createLazyRegistry, isLazyDescriptor } = __lazyRegistryModule;
2812
2814
  const builtInTokens = new Set(["prevent", "preventDefault", "stopPropagation", "stopImmediatePropagation"]);
@@ -2904,8 +2906,7 @@
2904
2906
  signalPaths: resolved.signalPaths,
2905
2907
  signalValues: resolved.signalValues
2906
2908
  });
2907
- await applyServerResult(result, runContext);
2908
- results.push(unwrapServerResult(result));
2909
+ results.push(result);
2909
2910
  continue;
2910
2911
  }
2911
2912