svelte-effect-runtime 4.0.0 → 4.0.1
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/chunks/client-BrZka6DW.js +530 -0
- package/.dist/chunks/client-BrZka6DW.js.map +1 -0
- package/.dist/chunks/compiler-COVzgLYo.js +412 -0
- package/.dist/chunks/compiler-COVzgLYo.js.map +1 -0
- package/.dist/chunks/descriptors-B4otDlm1.js +216 -0
- package/.dist/chunks/descriptors-B4otDlm1.js.map +1 -0
- package/.dist/chunks/diagnostics-BDrky-Di.js +359 -0
- package/.dist/chunks/diagnostics-BDrky-Di.js.map +1 -0
- package/.dist/chunks/dispatcher-BA0PLQhA.js +16 -0
- package/.dist/chunks/dispatcher-BA0PLQhA.js.map +1 -0
- package/.dist/chunks/{dispatcher-DOx8iC6r.js → dispatcher-_x0MQZBS.js} +84 -258
- package/.dist/chunks/dispatcher-_x0MQZBS.js.map +1 -0
- package/.dist/chunks/{errors-IJjsUwrE.js → errors-CLsbGjIa.js} +39 -44
- package/.dist/chunks/errors-CLsbGjIa.js.map +1 -0
- package/.dist/chunks/live-BundLSoY.js +146 -0
- package/.dist/chunks/live-BundLSoY.js.map +1 -0
- package/.dist/chunks/live-CHK0RrZu.js +10 -0
- package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
- package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
- package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
- package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-HDTlEnzp.js} +3 -27
- package/.dist/chunks/runtime-HDTlEnzp.js.map +1 -0
- package/.dist/chunks/{server-D1LcDnZE.js → server-BNrA1I-u.js} +15 -84
- package/.dist/chunks/server-BNrA1I-u.js.map +1 -0
- package/.dist/chunks/source-scan-9pZxnfct.js +1059 -0
- package/.dist/chunks/source-scan-9pZxnfct.js.map +1 -0
- package/.dist/chunks/{transform-jNUr65K9.js → transform-BXyYUAez.js} +184 -358
- package/.dist/chunks/transform-BXyYUAez.js.map +1 -0
- package/.dist/compiler/markup-identifiers.d.ts +2 -0
- package/.dist/compiler/remote-client.d.ts +1 -19
- package/.dist/compiler/source-scan.d.ts +11 -108
- package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
- package/.dist/compiler.d.ts +6 -0
- package/.dist/compiler.js +1 -1
- package/.dist/detect.d.ts +0 -31
- package/.dist/detect.js +0 -39
- package/.dist/detect.js.map +1 -1
- package/.dist/diagnostics.d.ts +0 -16
- package/.dist/dispatcher/deps.d.ts +3 -14
- package/.dist/dispatcher/fibers.d.ts +5 -46
- package/.dist/dispatcher/index.d.ts +1 -143
- package/.dist/dispatcher/types.d.ts +0 -151
- package/.dist/dispatcher.js +1 -1
- package/.dist/errors.d.ts +30 -42
- package/.dist/generated/dispatcher.d.ts +0 -50
- package/.dist/generators.d.ts +1 -12
- package/.dist/internal/descriptors.d.ts +0 -16
- package/.dist/internal/generators.js +13 -8
- package/.dist/internal/generators.js.map +1 -1
- package/.dist/internal/live.d.ts +9 -0
- package/.dist/internal/remote-client.js +2 -2
- package/.dist/internal/remote-server.js +2 -2
- package/.dist/internal/schema.d.ts +0 -54
- package/.dist/live.d.ts +9 -26
- package/.dist/markup/event-attributes.d.ts +0 -32
- package/.dist/markup/promise.d.ts +1 -23
- package/.dist/markup/promise.js +2 -18
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.d.ts +1 -10
- package/.dist/markup/run.js +2 -11
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/apply.d.ts +4 -4
- package/.dist/markup/transform/classify.d.ts +2 -11
- package/.dist/markup/transform/constants.d.ts +1 -1
- package/.dist/markup/transform/effect-bindings.d.ts +2 -26
- package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
- package/.dist/markup/transform/emit.d.ts +2 -11
- package/.dist/markup/transform/expressions.d.ts +0 -35
- package/.dist/markup/transform/scan.d.ts +3 -22
- package/.dist/markup/transform/types.d.ts +1 -129
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.d.ts +1 -18
- package/.dist/markup/value.js +2 -19
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +3 -8
- package/.dist/mod.js +5 -5
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/cause-codec.d.ts +3 -37
- package/.dist/remote/client/command.d.ts +3 -17
- package/.dist/remote/client/form-data.d.ts +0 -7
- package/.dist/remote/client/form-enhance.d.ts +0 -7
- package/.dist/remote/client/form-transport.d.ts +14 -20
- package/.dist/remote/client/form.d.ts +4 -24
- package/.dist/remote/client/index.d.ts +2 -1
- package/.dist/remote/client/prerender.d.ts +6 -0
- package/.dist/remote/client/query-result.d.ts +2 -14
- package/.dist/remote/client/query.d.ts +8 -48
- package/.dist/remote/client/responses.d.ts +3 -27
- package/.dist/remote/client/types.d.ts +16 -110
- package/.dist/remote/client/utils.d.ts +0 -8
- package/.dist/remote/client.d.ts +2 -2
- package/.dist/remote/client.js +2 -2
- package/.dist/remote/effect.d.ts +6 -0
- package/.dist/remote/failures.d.ts +4 -0
- package/.dist/remote/query-update.d.ts +2 -0
- package/.dist/remote/resource.d.ts +25 -0
- package/.dist/remote/server.d.ts +5 -50
- package/.dist/remote/server.js +2 -2
- package/.dist/remote/shared.d.ts +6 -145
- package/.dist/remote/shared.js +6 -127
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/transform.js +5 -22
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/ast.d.ts +0 -46
- package/.dist/script-transform/imports.d.ts +0 -38
- package/.dist/script-transform/lower.d.ts +0 -9
- package/.dist/script-transform/runes.d.ts +0 -10
- package/.dist/script-transform/runtime-block.d.ts +0 -17
- package/.dist/script-transform/source.d.ts +0 -24
- package/.dist/script-transform/types.d.ts +1 -126
- package/.dist/server/effects.d.ts +4 -53
- package/.dist/server/factories.d.ts +7 -7
- package/.dist/server/index.d.ts +1 -1
- package/.dist/server/invalid.d.ts +0 -7
- package/.dist/server/live-snapshot.d.ts +5 -0
- package/.dist/server/remote-handler-context.d.ts +5 -0
- package/.dist/server/runtime.d.ts +6 -24
- package/.dist/server/schema.d.ts +0 -14
- package/.dist/server/transport.d.ts +2 -0
- package/.dist/server/types.d.ts +49 -26
- package/.dist/server/wrappers.d.ts +3 -40
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +200 -215
- package/.dist/server.js.map +1 -1
- package/.dist/yieldable.d.ts +1 -35
- package/package.json +2 -2
- package/.dist/chunks/client-DcZUV4rR.js +0 -653
- package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
- package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
- package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
- package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
- package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
- package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
- package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
- package/.dist/chunks/live-BXAKre_4.js +0 -104
- package/.dist/chunks/live-BXAKre_4.js.map +0 -1
- package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
- package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
- package/.dist/chunks/schema-D9pct6Y5.js +0 -89
- package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
- package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
- package/.dist/chunks/source-scan-C4PsggID.js +0 -341
- package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
- package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
- package/.dist/remote/client/effect.d.ts +0 -29
- package/.dist/remote/client/failures.d.ts +0 -42
package/.dist/server.js
CHANGED
|
@@ -1,135 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { i as
|
|
6
|
-
import { i as get_server_runtime_or_throw, n as ServerRuntime, t as RequestEvent } from "./chunks/runtime-
|
|
7
|
-
import {
|
|
1
|
+
import { D as UncheckedPrerenderHandlerMissingError, E as UncheckedLiveQueryHandlerMissingError, O as UncheckedQueryHandlerMissingError, T as UncheckedFormHandlerMissingError, i as BatchQueryHandlerMissingError, l as InvalidLiveQueryReturnError, w as UncheckedCommandHandlerMissingError } from "./chunks/errors-CLsbGjIa.js";
|
|
2
|
+
import { create_form_error, create_remote_transport_error } from "./remote/shared.js";
|
|
3
|
+
import { i as make_remote_live_stream, r as make_failed_remote_live_stream, t as Live } from "./chunks/live-BundLSoY.js";
|
|
4
|
+
import { a as normalize_validator, c as attach_remote_resource_getters, d as MakeEffectFromPromise, f as MakeEffectFromSync, l as is_remote_resource, n as attach_native_remote_query_update, o as attach_failed_remote_query_resource, r as resolve_native_remote_query_updates, s as attach_failed_remote_resource_getters, t as copy_property_descriptors, u as FailWithRemoteError } from "./chunks/descriptors-B4otDlm1.js";
|
|
5
|
+
import { i as throw_remote_cause, n as run_remote_effect, t as normalize_remote_helper_error } from "./chunks/server-BNrA1I-u.js";
|
|
6
|
+
import { i as get_server_runtime_or_throw, n as ServerRuntime, t as RequestEvent } from "./chunks/runtime-HDTlEnzp.js";
|
|
7
|
+
import { Effect, Result, Stream } from "effect";
|
|
8
8
|
import { error, invalid, redirect } from "@sveltejs/kit";
|
|
9
|
+
import { stringify } from "devalue";
|
|
9
10
|
import { command, form, getRequestEvent, prerender, query } from "$app/server";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
import * as SvelteKitInternalServer from "@sveltejs/kit/internal/server";
|
|
12
|
+
//#region src/server/remote-handler-context.ts
|
|
13
|
+
const active_remote_handler_counts = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
/** Tracks ownership per request event so concurrent requests remain isolated. */
|
|
15
|
+
function is_running_remote_effect_handler(event) {
|
|
16
|
+
const request_event = event ?? get_current_request_event();
|
|
17
|
+
if (!request_event) return false;
|
|
18
|
+
return (active_remote_handler_counts.get(request_event) ?? 0) > 0;
|
|
19
|
+
}
|
|
20
|
+
/** Marks one request as handler-owned for the lifetime of the supplied Effect. */
|
|
21
|
+
const RunInsideRemoteEffectHandler = (event, effect) => Effect.acquireUseRelease(AcquireRemoteHandlerOwnership(event), () => effect, () => ReleaseRemoteHandlerOwnership(event));
|
|
22
|
+
const AcquireRemoteHandlerOwnership = (event) => Effect.sync(() => {
|
|
23
|
+
const active_count = active_remote_handler_counts.get(event) ?? 0;
|
|
24
|
+
active_remote_handler_counts.set(event, active_count + 1);
|
|
25
|
+
});
|
|
26
|
+
const ReleaseRemoteHandlerOwnership = (event) => Effect.sync(() => {
|
|
27
|
+
const remaining_count = (active_remote_handler_counts.get(event) ?? 1) - 1;
|
|
28
|
+
if (remaining_count === 0) {
|
|
29
|
+
active_remote_handler_counts.delete(event);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
active_remote_handler_counts.set(event, remaining_count);
|
|
33
|
+
});
|
|
34
|
+
function get_current_request_event() {
|
|
35
|
+
try {
|
|
36
|
+
const event = getRequestEvent();
|
|
37
|
+
return typeof event === "object" && event !== null ? event : void 0;
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
42
|
//#endregion
|
|
32
43
|
//#region src/server/effects.ts
|
|
33
|
-
/**
|
|
34
|
-
* Checks whether a value is an Effect generator return object.
|
|
35
|
-
*
|
|
36
|
-
* @since 2.0.0
|
|
37
|
-
* @param value - Value to inspect.
|
|
38
|
-
* @returns Whether the value should be wrapped with `Effect.gen`.
|
|
39
|
-
*/
|
|
40
44
|
function is_generator_result(value) {
|
|
41
45
|
return typeof value === "object" && value !== null && typeof value.next === "function";
|
|
42
46
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Normalizes an Effect-like handler return value into an Effect.
|
|
45
|
-
*
|
|
46
|
-
* @since 2.0.0
|
|
47
|
-
* @param value - Effect or generator return value.
|
|
48
|
-
* @returns Normalized Effect.
|
|
49
|
-
*/
|
|
50
47
|
function ToEffect(value) {
|
|
51
48
|
if (is_generator_result(value)) return Effect.gen(() => value);
|
|
52
49
|
return value;
|
|
53
50
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Checks whether a value is an Effect Stream live source.
|
|
56
|
-
*
|
|
57
|
-
* @since 2.0.0
|
|
58
|
-
* @param value - Value to inspect.
|
|
59
|
-
* @returns Whether the value is an Effect Stream.
|
|
60
|
-
*/
|
|
61
51
|
function is_live_source(value) {
|
|
62
52
|
return Stream.isStream(value);
|
|
63
53
|
}
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* @returns Promise resolving with a source SvelteKit can stream.
|
|
72
|
-
*/
|
|
73
|
-
function run_live_handler_source(value, event) {
|
|
74
|
-
if (!is_live_source(value)) throw new InvalidLiveQueryReturnError();
|
|
75
|
-
const runtime = get_server_runtime_or_throw();
|
|
76
|
-
return run_remote_effect(Effect.provideService(ToLiveSourceEffect(value), RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
54
|
+
/** Runs a live handler inside the request-local ownership scope. */
|
|
55
|
+
function run_live_handler(handler, event) {
|
|
56
|
+
return run_live_source_effect(RunInsideRemoteEffectHandler(event, Effect.suspend(() => {
|
|
57
|
+
const value = handler();
|
|
58
|
+
if (!is_live_source(value)) return Effect.die(new InvalidLiveQueryReturnError());
|
|
59
|
+
return ToLiveSourceEffect(value, event);
|
|
60
|
+
})), event);
|
|
77
61
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
62
|
+
function run_live_source_effect(effect, event) {
|
|
63
|
+
const runtime = get_server_runtime_or_throw();
|
|
64
|
+
return run_remote_effect(Effect.provideService(effect, RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
80
65
|
}
|
|
81
|
-
|
|
66
|
+
const ToLiveSourceEffect = (value, event) => Stream.toAsyncIterableEffect(preserve_live_source_cause(value)).pipe(Effect.map((source) => wrap_live_source_errors(source, event)));
|
|
67
|
+
const preserve_live_source_cause = (value) => value.pipe(Stream.catchCause((cause) => Stream.fromEffect(Effect.sync(() => throw_remote_cause(cause, invalid, svelte_remote_error)))));
|
|
68
|
+
function wrap_live_source_errors(source, event) {
|
|
82
69
|
return { [Symbol.asyncIterator]() {
|
|
83
70
|
const iterator = source[Symbol.asyncIterator]();
|
|
71
|
+
const throw_iterator = iterator.throw?.bind(iterator);
|
|
84
72
|
return {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return await iterator.next();
|
|
88
|
-
} catch (error) {
|
|
89
|
-
throw_live_source_error(error);
|
|
90
|
-
}
|
|
73
|
+
next() {
|
|
74
|
+
return RunLiveIteratorCall(event, () => iterator.next());
|
|
91
75
|
},
|
|
92
|
-
|
|
93
|
-
if (iterator.return) return
|
|
94
|
-
return {
|
|
76
|
+
return(value) {
|
|
77
|
+
if (iterator.return) return RunLiveIteratorCall(event, () => iterator.return?.(value));
|
|
78
|
+
return Promise.resolve({
|
|
95
79
|
done: true,
|
|
96
80
|
value: void 0
|
|
97
|
-
};
|
|
81
|
+
});
|
|
98
82
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
83
|
+
...throw_iterator === void 0 ? {} : { throw(error) {
|
|
84
|
+
return RunLiveIteratorCall(event, () => throw_iterator(error));
|
|
85
|
+
} }
|
|
103
86
|
};
|
|
104
87
|
} };
|
|
105
88
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
89
|
+
function RunLiveIteratorCall(event, run) {
|
|
90
|
+
const runtime = get_server_runtime_or_throw();
|
|
91
|
+
const IteratorEffect = Effect.tryPromise({
|
|
92
|
+
try: run,
|
|
93
|
+
catch: (error) => error
|
|
94
|
+
});
|
|
95
|
+
return runtime.runPromise(RunInsideRemoteEffectHandler(event, IteratorEffect));
|
|
108
96
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Runs a remote handler Effect with the current request event provided.
|
|
111
|
-
*
|
|
112
|
-
* @since 2.0.0
|
|
113
|
-
* @param value - Handler return value.
|
|
114
|
-
* @param event - SvelteKit request event for this remote call.
|
|
115
|
-
* @returns Promise resolving with the handler output.
|
|
116
|
-
*/
|
|
117
97
|
function run_handler_effect(value, event) {
|
|
118
98
|
const runtime = get_server_runtime_or_throw();
|
|
119
|
-
return run_remote_effect(Effect.provideService(ToEffect(value), RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
99
|
+
return run_remote_effect(Effect.provideService(RunInsideRemoteEffectHandler(event, ToEffect(value)), RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
120
100
|
}
|
|
121
101
|
const svelte_remote_error = (status, body) => {
|
|
122
102
|
error(status, body);
|
|
123
103
|
};
|
|
124
104
|
//#endregion
|
|
125
105
|
//#region src/server/invalid.ts
|
|
126
|
-
/**
|
|
127
|
-
* Creates a path-aware proxy for remote form validation failures.
|
|
128
|
-
*
|
|
129
|
-
* @since 2.0.0
|
|
130
|
-
* @param path - Current nested form path.
|
|
131
|
-
* @returns Callable invalid proxy for this path.
|
|
132
|
-
*/
|
|
133
106
|
function make_invalid_proxy(path = []) {
|
|
134
107
|
const invalid_at_path = (message) => Effect.fail(create_form_error([{
|
|
135
108
|
message,
|
|
@@ -137,37 +110,33 @@ function make_invalid_proxy(path = []) {
|
|
|
137
110
|
}]));
|
|
138
111
|
return new Proxy(invalid_at_path, { get(_target, property) {
|
|
139
112
|
if (typeof property === "symbol") return;
|
|
140
|
-
|
|
113
|
+
const segment = path.length === 0 ? property : normalize_nested_path_segment(property);
|
|
114
|
+
return make_invalid_proxy([...path, segment]);
|
|
141
115
|
} });
|
|
142
116
|
}
|
|
117
|
+
function normalize_nested_path_segment(property) {
|
|
118
|
+
return /^(0|[1-9]\d*)$/.test(property) ? Number(property) : property;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/server/schema.ts
|
|
122
|
+
function is_unchecked(value) {
|
|
123
|
+
return value === "unchecked";
|
|
124
|
+
}
|
|
125
|
+
function is_handler(value) {
|
|
126
|
+
return typeof value === "function";
|
|
127
|
+
}
|
|
143
128
|
//#endregion
|
|
144
129
|
//#region src/server/wrappers.ts
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* ```
|
|
155
|
-
*
|
|
156
|
-
* @since 2.0.0
|
|
157
|
-
* @returns Whether a remote handler wrapper is currently active.
|
|
158
|
-
* @internal
|
|
159
|
-
*/
|
|
160
|
-
function is_running_remote_effect_handler() {
|
|
161
|
-
return running_remote_effect_handlers > 0;
|
|
130
|
+
function make_prerender_inputs_wrapper(generate_inputs) {
|
|
131
|
+
return () => {
|
|
132
|
+
const runtime = get_server_runtime_or_throw();
|
|
133
|
+
const CollectInputs = Effect.gen(function* () {
|
|
134
|
+
const inputs = yield* Effect.suspend(() => ToEffect(generate_inputs()));
|
|
135
|
+
return Array.from(inputs);
|
|
136
|
+
});
|
|
137
|
+
return runtime.runPromise(CollectInputs);
|
|
138
|
+
};
|
|
162
139
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Builds the wrapper passed to native query, command, and prerender helpers.
|
|
165
|
-
*
|
|
166
|
-
* @since 2.0.0
|
|
167
|
-
* @param handler - Effect handler or already-built Effect-like value.
|
|
168
|
-
* @param helper_name - Remote helper name for error normalization.
|
|
169
|
-
* @returns Native SvelteKit handler wrapper.
|
|
170
|
-
*/
|
|
171
140
|
function make_remote_wrapper(handler, helper_name) {
|
|
172
141
|
return async (input) => {
|
|
173
142
|
let event;
|
|
@@ -176,23 +145,11 @@ function make_remote_wrapper(handler, helper_name) {
|
|
|
176
145
|
} catch (error) {
|
|
177
146
|
throw normalize_remote_helper_error(error, helper_name);
|
|
178
147
|
}
|
|
179
|
-
return await
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
} catch (error) {
|
|
183
|
-
throw normalize_remote_helper_error(error, helper_name);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
148
|
+
return await run_handler_effect(Effect.suspend(() => {
|
|
149
|
+
return ToEffect(is_handler(handler) ? handler(input) : handler);
|
|
150
|
+
}), event);
|
|
186
151
|
};
|
|
187
152
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Builds the wrapper passed to native live query helpers.
|
|
190
|
-
*
|
|
191
|
-
* @since 2.0.0
|
|
192
|
-
* @param handler - Effect-aware live source handler.
|
|
193
|
-
* @param helper_name - Remote helper name for error normalization.
|
|
194
|
-
* @returns Native SvelteKit live query wrapper.
|
|
195
|
-
*/
|
|
196
153
|
function make_remote_live_wrapper(handler, helper_name) {
|
|
197
154
|
return async (input) => {
|
|
198
155
|
let event;
|
|
@@ -201,23 +158,9 @@ function make_remote_live_wrapper(handler, helper_name) {
|
|
|
201
158
|
} catch (error) {
|
|
202
159
|
throw normalize_remote_helper_error(error, helper_name);
|
|
203
160
|
}
|
|
204
|
-
return await
|
|
205
|
-
try {
|
|
206
|
-
return run_live_handler_source(typeof handler === "function" ? handler(input) : handler, event);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
throw normalize_remote_helper_error(error, helper_name);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
161
|
+
return await run_live_handler(() => typeof handler === "function" ? handler(input) : handler, event);
|
|
211
162
|
};
|
|
212
163
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Builds the wrapper passed to native form helpers.
|
|
215
|
-
*
|
|
216
|
-
* @since 2.0.0
|
|
217
|
-
* @param handler - Effect-aware form handler.
|
|
218
|
-
* @param helper_name - Remote helper name for error normalization.
|
|
219
|
-
* @returns Native SvelteKit form handler wrapper.
|
|
220
|
-
*/
|
|
221
164
|
function make_remote_form_wrapper(handler, helper_name) {
|
|
222
165
|
return async (data, issue) => {
|
|
223
166
|
let event;
|
|
@@ -226,50 +169,102 @@ function make_remote_form_wrapper(handler, helper_name) {
|
|
|
226
169
|
} catch (error) {
|
|
227
170
|
throw normalize_remote_helper_error(error, helper_name);
|
|
228
171
|
}
|
|
229
|
-
return await
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}), event);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
throw normalize_remote_helper_error(error, helper_name);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
172
|
+
return await run_handler_effect(Effect.suspend(() => {
|
|
173
|
+
return ToEffect(handler({
|
|
174
|
+
data,
|
|
175
|
+
invalid: make_invalid_proxy(),
|
|
176
|
+
issue
|
|
177
|
+
}));
|
|
178
|
+
}), event);
|
|
241
179
|
};
|
|
242
180
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/server/live-snapshot.ts
|
|
183
|
+
/** Converts SvelteKit transport hooks into a devalue live snapshot encoder. */
|
|
184
|
+
function make_remote_live_snapshot_encoder(transport) {
|
|
185
|
+
const encoders = Object.fromEntries(Object.entries(transport).map(([key, transformer]) => [key, transformer.encode]));
|
|
186
|
+
return (value) => stringify(value, encoders);
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/server/transport.ts
|
|
190
|
+
/** Creates the current SvelteKit request's transport-aware live snapshot encoder. */
|
|
191
|
+
function get_remote_live_snapshot_encoder() {
|
|
192
|
+
const try_get_request_store = SvelteKitInternalServer.try_get_request_store;
|
|
193
|
+
const request_store = try_get_request_store?.();
|
|
194
|
+
if (!request_store) return;
|
|
195
|
+
return make_remote_live_snapshot_encoder(request_store.state.transport);
|
|
250
196
|
}
|
|
251
197
|
//#endregion
|
|
252
198
|
//#region src/server/factories.ts
|
|
253
199
|
const request_event_context_error_start = "Can only read the current request event inside functions invoked during `handle`";
|
|
254
200
|
const request_store_context_error = "Could not get the request store.";
|
|
255
|
-
function to_effect_query(native) {
|
|
201
|
+
function to_effect_query(native, mode = "standard") {
|
|
202
|
+
return to_effect_remote_resource(native, attach_query_resource_methods, attach_failed_remote_query_resource, mode);
|
|
203
|
+
}
|
|
204
|
+
function to_effect_prerender(native) {
|
|
205
|
+
return to_effect_remote_resource(native, attach_remote_resource_getters, attach_failed_remote_resource_getters);
|
|
206
|
+
}
|
|
207
|
+
function to_effect_command(native) {
|
|
256
208
|
const wrapped = ((input) => {
|
|
257
209
|
if (is_current_remote_request()) return native(input);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
210
|
+
return MakeServerCommandEffect(native, input);
|
|
211
|
+
});
|
|
212
|
+
copy_property_descriptors(native, wrapped);
|
|
213
|
+
return wrapped;
|
|
214
|
+
}
|
|
215
|
+
const MakeServerCommandEffect = (native, input) => {
|
|
216
|
+
let updates_args;
|
|
217
|
+
const CommandEffect = Effect.gen(function* () {
|
|
218
|
+
const invocation = yield* MakeEffectFromSync(() => {
|
|
219
|
+
const result = native(input);
|
|
220
|
+
if (updates_args && has_command_updates(result)) return result.updates(...resolve_native_remote_query_updates(updates_args));
|
|
221
|
+
return result;
|
|
262
222
|
});
|
|
263
|
-
|
|
264
|
-
|
|
223
|
+
return yield* MakeEffectFromPromise(() => Promise.resolve(invocation));
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(CommandEffect, "updates", {
|
|
226
|
+
configurable: true,
|
|
227
|
+
enumerable: false,
|
|
228
|
+
value: (...args) => {
|
|
229
|
+
updates_args ??= args;
|
|
230
|
+
return CommandEffect;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return CommandEffect;
|
|
234
|
+
};
|
|
235
|
+
function has_command_updates(value) {
|
|
236
|
+
const value_type = typeof value;
|
|
237
|
+
return (value_type === "object" && value !== null || value_type === "function") && typeof value.updates === "function";
|
|
238
|
+
}
|
|
239
|
+
function to_effect_remote_resource(native, attach_resource, attach_failed_resource, mode = "standard") {
|
|
240
|
+
const wrapped = ((input) => {
|
|
241
|
+
if (is_current_remote_request()) return native(input);
|
|
242
|
+
const resource_attempt = Result.try(() => native(input));
|
|
243
|
+
if (Result.isFailure(resource_attempt)) {
|
|
244
|
+
const ResourceEffect = FailWithRemoteError(resource_attempt.failure);
|
|
245
|
+
attach_failed_resource(resource_attempt.failure, ResourceEffect);
|
|
246
|
+
return ResourceEffect;
|
|
247
|
+
}
|
|
248
|
+
const resource = resource_attempt.success;
|
|
249
|
+
const started_result = mode === "batch" ? begin_batch_resource(resource) : void 0;
|
|
250
|
+
const ResourceEffect = MakeEffectFromPromise(() => started_result ?? Promise.resolve(resource));
|
|
251
|
+
attach_native_remote_query_update(ResourceEffect, resource);
|
|
252
|
+
attach_resource(resource, ResourceEffect);
|
|
253
|
+
return ResourceEffect;
|
|
265
254
|
});
|
|
266
255
|
copy_property_descriptors(native, wrapped);
|
|
256
|
+
attach_native_remote_query_update(wrapped, native);
|
|
267
257
|
return wrapped;
|
|
268
258
|
}
|
|
259
|
+
function begin_batch_resource(resource) {
|
|
260
|
+
const result = Promise.resolve(resource);
|
|
261
|
+
result.catch(() => {});
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
269
264
|
function is_current_remote_request() {
|
|
270
|
-
if (is_running_remote_effect_handler()) return false;
|
|
271
265
|
const detection = detect_current_remote_request();
|
|
272
266
|
if (detection._tag === "NoCurrentRemoteRequest") return false;
|
|
267
|
+
if (is_running_remote_effect_handler(detection.event)) return false;
|
|
273
268
|
return detection.event.isRemoteRequest === true;
|
|
274
269
|
}
|
|
275
270
|
function detect_current_remote_request() {
|
|
@@ -289,34 +284,20 @@ function is_request_event_context_error(error) {
|
|
|
289
284
|
}
|
|
290
285
|
function to_effect_live_query(native) {
|
|
291
286
|
const wrapped = ((input) => {
|
|
292
|
-
|
|
287
|
+
const snapshot_encoder = get_remote_live_snapshot_encoder();
|
|
288
|
+
const resource_attempt = Result.try(() => native(input));
|
|
289
|
+
if (Result.isFailure(resource_attempt)) return make_failed_remote_live_stream(resource_attempt.failure, create_remote_transport_error);
|
|
290
|
+
const resource = resource_attempt.success;
|
|
291
|
+
const stream = make_remote_live_stream(resource, create_remote_transport_error, snapshot_encoder);
|
|
292
|
+
attach_native_remote_query_update(stream, resource);
|
|
293
|
+
return stream;
|
|
293
294
|
});
|
|
294
295
|
copy_property_descriptors(native, wrapped);
|
|
296
|
+
attach_native_remote_query_update(wrapped, native);
|
|
295
297
|
return wrapped;
|
|
296
298
|
}
|
|
297
|
-
function is_query_resource(resource) {
|
|
298
|
-
const resource_type = typeof resource;
|
|
299
|
-
return resource_type === "object" && resource !== null || resource_type === "function";
|
|
300
|
-
}
|
|
301
|
-
function attach_remote_resource_getters(resource, effect) {
|
|
302
|
-
const methods = is_query_resource(resource) ? resource : void 0;
|
|
303
|
-
const keys = [
|
|
304
|
-
"current",
|
|
305
|
-
"error",
|
|
306
|
-
"loading",
|
|
307
|
-
"ready"
|
|
308
|
-
];
|
|
309
|
-
if (!methods) return;
|
|
310
|
-
for (const key of keys) {
|
|
311
|
-
if (!(key in methods)) continue;
|
|
312
|
-
Object.defineProperty(effect, key, {
|
|
313
|
-
configurable: true,
|
|
314
|
-
get: () => methods[key]
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
299
|
function attach_query_resource_methods(resource, effect) {
|
|
319
|
-
const methods =
|
|
300
|
+
const methods = is_remote_resource(resource) ? resource : void 0;
|
|
320
301
|
const refresh = methods?.refresh;
|
|
321
302
|
const set = methods?.set;
|
|
322
303
|
const with_override = methods?.withOverride;
|
|
@@ -324,10 +305,7 @@ function attach_query_resource_methods(resource, effect) {
|
|
|
324
305
|
if (!methods) return;
|
|
325
306
|
if (typeof refresh === "function") Object.defineProperty(effect, "refresh", {
|
|
326
307
|
configurable: true,
|
|
327
|
-
value: () =>
|
|
328
|
-
try: () => Promise.resolve(refresh.call(resource)),
|
|
329
|
-
catch: (error) => error
|
|
330
|
-
})
|
|
308
|
+
value: () => MakeEffectFromPromise(() => Promise.resolve(refresh.call(resource)))
|
|
331
309
|
});
|
|
332
310
|
if (typeof set === "function") Object.defineProperty(effect, "set", {
|
|
333
311
|
configurable: true,
|
|
@@ -338,6 +316,13 @@ function attach_query_resource_methods(resource, effect) {
|
|
|
338
316
|
value: (update) => with_override.call(resource, update)
|
|
339
317
|
});
|
|
340
318
|
}
|
|
319
|
+
function normalize_prerender_options(options) {
|
|
320
|
+
if (!options) return;
|
|
321
|
+
return {
|
|
322
|
+
dynamic: options.dynamic,
|
|
323
|
+
inputs: options.inputs ? make_prerender_inputs_wrapper(options.inputs) : void 0
|
|
324
|
+
};
|
|
325
|
+
}
|
|
341
326
|
function QueryRoot(validate_or_handler, maybe_handler) {
|
|
342
327
|
try {
|
|
343
328
|
if (maybe_handler) return to_effect_query(query(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler, "Query")));
|
|
@@ -350,7 +335,7 @@ function QueryRoot(validate_or_handler, maybe_handler) {
|
|
|
350
335
|
function QueryBatch(validate_or_handler, maybe_handler) {
|
|
351
336
|
try {
|
|
352
337
|
if (!maybe_handler) throw new BatchQueryHandlerMissingError();
|
|
353
|
-
return to_effect_query(query.batch(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler, "Query.batch")));
|
|
338
|
+
return to_effect_query(query.batch(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler, "Query.batch")), "batch");
|
|
354
339
|
} catch (error) {
|
|
355
340
|
throw normalize_remote_helper_error(error, "Query.batch");
|
|
356
341
|
}
|
|
@@ -386,9 +371,9 @@ const Query = Object.assign(QueryRoot, {
|
|
|
386
371
|
});
|
|
387
372
|
function Command(validate_or_handler, maybe_handler) {
|
|
388
373
|
try {
|
|
389
|
-
if (maybe_handler) return command(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler, "Command"));
|
|
374
|
+
if (maybe_handler) return to_effect_command(command(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler, "Command")));
|
|
390
375
|
if (is_unchecked(validate_or_handler)) throw new UncheckedCommandHandlerMissingError();
|
|
391
|
-
return command(make_remote_wrapper(validate_or_handler, "Command"));
|
|
376
|
+
return to_effect_command(command(make_remote_wrapper(validate_or_handler, "Command")));
|
|
392
377
|
} catch (error) {
|
|
393
378
|
throw normalize_remote_helper_error(error, "Command");
|
|
394
379
|
}
|
|
@@ -410,11 +395,11 @@ function Form(validate_or_handler, maybe_handler) {
|
|
|
410
395
|
throw normalize_remote_helper_error(error, "Form");
|
|
411
396
|
}
|
|
412
397
|
}
|
|
413
|
-
function Prerender(validate_or_handler, maybe_handler_or_options, maybe_options) {
|
|
398
|
+
function Prerender(validate_or_handler, maybe_handler_or_options, maybe_options, native_factory = prerender) {
|
|
414
399
|
try {
|
|
415
|
-
if (is_handler(maybe_handler_or_options)) return
|
|
400
|
+
if (is_handler(maybe_handler_or_options)) return to_effect_prerender(native_factory(normalize_validator(validate_or_handler), make_remote_wrapper(maybe_handler_or_options, "Prerender"), normalize_prerender_options(maybe_options)));
|
|
416
401
|
if (is_unchecked(validate_or_handler)) throw new UncheckedPrerenderHandlerMissingError();
|
|
417
|
-
return
|
|
402
|
+
return to_effect_prerender(native_factory(make_remote_wrapper(validate_or_handler, "Prerender"), normalize_prerender_options(maybe_handler_or_options)));
|
|
418
403
|
} catch (error) {
|
|
419
404
|
throw normalize_remote_helper_error(error, "Prerender");
|
|
420
405
|
}
|
|
@@ -460,9 +445,9 @@ function Handler(handler) {
|
|
|
460
445
|
const native_handler = async (...arguments_) => {
|
|
461
446
|
const event = getRequestEvent();
|
|
462
447
|
const runtime = get_server_runtime_or_throw();
|
|
463
|
-
const
|
|
464
|
-
const EffectWithRequestEvent = Effect.provideService(
|
|
465
|
-
return await runtime.runPromise(EffectWithRequestEvent);
|
|
448
|
+
const HandlerOwnedEffect = RunInsideRemoteEffectHandler(event, Effect.suspend(() => ToEffect(handler(...arguments_))));
|
|
449
|
+
const EffectWithRequestEvent = Effect.provideService(HandlerOwnedEffect, RequestEvent, event);
|
|
450
|
+
return await runtime.runPromise(EffectWithRequestEvent, { signal: event.request.signal });
|
|
466
451
|
};
|
|
467
452
|
return native_handler;
|
|
468
453
|
}
|