@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/CHANGELOG.md +30 -0
- package/README.md +1 -0
- package/browser.js +36 -35
- package/browser.min.js +1 -1
- package/browser.ts +36 -35
- package/browser.umd.js +36 -35
- package/browser.umd.min.js +1 -1
- package/framework.ts +40 -39
- package/package.json +1 -1
- package/server.js +40 -39
package/server.js
CHANGED
|
@@ -2380,9 +2380,10 @@ const __componentModule = (() => {
|
|
|
2380
2380
|
})();
|
|
2381
2381
|
|
|
2382
2382
|
const __serverModule = (() => {
|
|
2383
|
-
const
|
|
2384
|
-
const
|
|
2385
|
-
const
|
|
2383
|
+
const serverEnvelopeKind = Symbol.for("@async/framework.serverResult");
|
|
2384
|
+
const serverEnvelopeWireKey = "__async_server_result__";
|
|
2385
|
+
const serverEnvelopeWireVersion = 1;
|
|
2386
|
+
const serverResultInvocation = Symbol("@async/framework.serverResultInvocation");
|
|
2386
2387
|
|
|
2387
2388
|
function createServerProxy({
|
|
2388
2389
|
endpoint = "/__async/server",
|
|
@@ -2402,7 +2403,7 @@ const __serverModule = (() => {
|
|
|
2402
2403
|
|
|
2403
2404
|
async function run(id, args = [], context = {}) {
|
|
2404
2405
|
assertServerId(id);
|
|
2405
|
-
const runContext = { ...defaults, ...context };
|
|
2406
|
+
const runContext = createServerResultContext({ ...defaults, ...context });
|
|
2406
2407
|
const body = {
|
|
2407
2408
|
args,
|
|
2408
2409
|
input: context.input ?? defaultInput(runContext),
|
|
@@ -2425,9 +2426,7 @@ const __serverModule = (() => {
|
|
|
2425
2426
|
throw new Error(`Server function "${id}" failed with ${response.status}.`);
|
|
2426
2427
|
}
|
|
2427
2428
|
|
|
2428
|
-
|
|
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,12 +2461,13 @@ const __serverModule = (() => {
|
|
|
2462
2461
|
if (!isServerEnvelope(result)) {
|
|
2463
2462
|
return result;
|
|
2464
2463
|
}
|
|
2465
|
-
|
|
2464
|
+
const invocation = getServerResultInvocation(context);
|
|
2465
|
+
if (invocation.applied.has(result)) {
|
|
2466
2466
|
return result;
|
|
2467
2467
|
}
|
|
2468
|
+
invocation.applied.add(result);
|
|
2468
2469
|
|
|
2469
2470
|
if (result.error) {
|
|
2470
|
-
markAppliedServerResult(result);
|
|
2471
2471
|
throw toError(result.error);
|
|
2472
2472
|
}
|
|
2473
2473
|
|
|
@@ -2489,32 +2489,35 @@ const __serverModule = (() => {
|
|
|
2489
2489
|
await context.router?.navigate?.(result.redirect);
|
|
2490
2490
|
}
|
|
2491
2491
|
|
|
2492
|
-
markAppliedServerResult(result);
|
|
2493
|
-
|
|
2494
2492
|
return result;
|
|
2495
2493
|
}
|
|
2496
2494
|
|
|
2495
|
+
async function consumeServerResult(result, context = {}) {
|
|
2496
|
+
await applyServerResult(result, context);
|
|
2497
|
+
return unwrapServerResult(result);
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2497
2500
|
function unwrapServerResult(result) {
|
|
2498
|
-
if (isServerEnvelope(result)
|
|
2499
|
-
return result.value;
|
|
2501
|
+
if (isServerEnvelope(result)) {
|
|
2502
|
+
return Object.hasOwn(result, "value") ? result.value : undefined;
|
|
2500
2503
|
}
|
|
2501
2504
|
return result;
|
|
2502
2505
|
}
|
|
2503
2506
|
|
|
2504
|
-
function
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
}
|
|
2508
|
-
return
|
|
2507
|
+
function createServerResultContext(context = {}) {
|
|
2508
|
+
const invocation = context[serverResultInvocation] ?? {
|
|
2509
|
+
applied: new WeakSet()
|
|
2510
|
+
};
|
|
2511
|
+
return {
|
|
2512
|
+
...context,
|
|
2513
|
+
[serverResultInvocation]: invocation
|
|
2514
|
+
};
|
|
2509
2515
|
}
|
|
2510
2516
|
|
|
2511
|
-
function
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
value: true
|
|
2516
|
-
});
|
|
2517
|
-
return result;
|
|
2517
|
+
function getServerResultInvocation(context = {}) {
|
|
2518
|
+
return context[serverResultInvocation] ?? {
|
|
2519
|
+
applied: new WeakSet()
|
|
2520
|
+
};
|
|
2518
2521
|
}
|
|
2519
2522
|
|
|
2520
2523
|
function defaultInput(context = {}) {
|
|
@@ -2549,9 +2552,7 @@ const __serverModule = (() => {
|
|
|
2549
2552
|
throw new Error("Server namespace is not directly callable.");
|
|
2550
2553
|
}
|
|
2551
2554
|
const context = contextProvider() ?? {};
|
|
2552
|
-
|
|
2553
|
-
await applyServerResult(result, context);
|
|
2554
|
-
return unwrapServerResult(result);
|
|
2555
|
+
return run(parts.join("."), args, context);
|
|
2555
2556
|
};
|
|
2556
2557
|
|
|
2557
2558
|
const proxy = new Proxy(callable, {
|
|
@@ -2608,7 +2609,7 @@ const __serverModule = (() => {
|
|
|
2608
2609
|
|
|
2609
2610
|
async function readServerResponse(id, response) {
|
|
2610
2611
|
if (response.status === 204) {
|
|
2611
|
-
return
|
|
2612
|
+
return undefined;
|
|
2612
2613
|
}
|
|
2613
2614
|
const type = response.headers.get("content-type") ?? "";
|
|
2614
2615
|
if (type.includes("application/json")) {
|
|
@@ -2626,7 +2627,7 @@ const __serverModule = (() => {
|
|
|
2626
2627
|
if (typeof response.text !== "function") {
|
|
2627
2628
|
throw new Error(`Server function "${id}" transport returned an invalid response: missing text().`);
|
|
2628
2629
|
}
|
|
2629
|
-
return
|
|
2630
|
+
return response.text();
|
|
2630
2631
|
}
|
|
2631
2632
|
|
|
2632
2633
|
function snapshotSignalPaths(paths = [], signals) {
|
|
@@ -2771,7 +2772,8 @@ const __serverModule = (() => {
|
|
|
2771
2772
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
2772
2773
|
return false;
|
|
2773
2774
|
}
|
|
2774
|
-
return
|
|
2775
|
+
return value[serverEnvelopeKind] === true
|
|
2776
|
+
|| value[serverEnvelopeWireKey] === serverEnvelopeWireVersion;
|
|
2775
2777
|
}
|
|
2776
2778
|
|
|
2777
2779
|
function toError(value) {
|
|
@@ -2793,11 +2795,11 @@ const __serverModule = (() => {
|
|
|
2793
2795
|
throw new TypeError("Server function id must be a non-empty string.");
|
|
2794
2796
|
}
|
|
2795
2797
|
}
|
|
2796
|
-
return { createServerProxy, resolveServerCommandArguments, applyServerResult, unwrapServerResult, defaultInput, createServerNamespace, createSignalReader, assertServerId };
|
|
2798
|
+
return { createServerProxy, resolveServerCommandArguments, applyServerResult, consumeServerResult, unwrapServerResult, createServerResultContext, defaultInput, createServerNamespace, createSignalReader, assertServerId };
|
|
2797
2799
|
})();
|
|
2798
2800
|
|
|
2799
2801
|
const __handlersModule = (() => {
|
|
2800
|
-
const {
|
|
2802
|
+
const { defaultInput, resolveServerCommandArguments } = __serverModule;
|
|
2801
2803
|
const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
|
|
2802
2804
|
const { createLazyRegistry, isLazyDescriptor } = __lazyRegistryModule;
|
|
2803
2805
|
const builtInTokens = new Set(["prevent", "preventDefault", "stopPropagation", "stopImmediatePropagation"]);
|
|
@@ -2895,8 +2897,7 @@ const __handlersModule = (() => {
|
|
|
2895
2897
|
signalPaths: resolved.signalPaths,
|
|
2896
2898
|
signalValues: resolved.signalValues
|
|
2897
2899
|
});
|
|
2898
|
-
|
|
2899
|
-
results.push(unwrapServerResult(result));
|
|
2900
|
+
results.push(result);
|
|
2900
2901
|
continue;
|
|
2901
2902
|
}
|
|
2902
2903
|
|
|
@@ -5751,7 +5752,7 @@ const __requestContextModule = (() => {
|
|
|
5751
5752
|
const __serverRegistryModule = (() => {
|
|
5752
5753
|
const { readRequestContext } = __requestContextModule;
|
|
5753
5754
|
const { attachRegistryInspection, createRegistryStore } = __registryStoreModule;
|
|
5754
|
-
const { assertServerId, createServerNamespace, createSignalReader } = __serverModule;
|
|
5755
|
+
const { assertServerId, consumeServerResult, createServerNamespace, createServerResultContext, createSignalReader } = __serverModule;
|
|
5755
5756
|
function createServerRegistry(initialMap = {}, options = {}) {
|
|
5756
5757
|
const registryStore = options.registry ?? createRegistryStore();
|
|
5757
5758
|
const type = options.type ?? "server";
|
|
@@ -5806,7 +5807,7 @@ const __serverRegistryModule = (() => {
|
|
|
5806
5807
|
cache: defaults.cache ?? context.cache
|
|
5807
5808
|
});
|
|
5808
5809
|
|
|
5809
|
-
runContext = {
|
|
5810
|
+
runContext = createServerResultContext({
|
|
5810
5811
|
...mergedContext,
|
|
5811
5812
|
id,
|
|
5812
5813
|
args,
|
|
@@ -5815,9 +5816,9 @@ const __serverRegistryModule = (() => {
|
|
|
5815
5816
|
abort: mergedContext.abort,
|
|
5816
5817
|
cache: mergedContext.cache,
|
|
5817
5818
|
server
|
|
5818
|
-
};
|
|
5819
|
+
});
|
|
5819
5820
|
|
|
5820
|
-
return fn.call(runContext, ...args);
|
|
5821
|
+
return consumeServerResult(await fn.call(runContext, ...args), runContext);
|
|
5821
5822
|
},
|
|
5822
5823
|
|
|
5823
5824
|
_setContext(context = {}) {
|