token-usage-dashboard 1.0.13 → 1.0.14
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/build/adapter-node.js +11 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js +1 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js.br +0 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js +1 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js.br +0 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js +1 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js.br +0 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js +3 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js.br +0 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js +3 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js.br +0 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js +2 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js.gz +0 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js +1 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js.br +0 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js +2 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js.br +0 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js +1 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js +1 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js.br +2 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js +2 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/handler.js +1 -22
- package/build/index.js +1 -145
- package/build/server/.vite/manifest.json +271 -0
- package/build/server/_app/immutable/assets/_layout.CZ6VMqH1.css +1 -0
- package/build/server/_app/immutable/assets/_page.CZocdpCk.css +1 -0
- package/build/server/adapter-env.js +2 -0
- package/build/server/adapter-index.js +74 -0
- package/build/server/adapter-node-env.js +63 -0
- package/build/server/adapter-node-handler.js +584 -0
- package/build/server/chunks/config.js +10 -0
- package/build/server/chunks/functions.js +30 -0
- package/build/server/chunks/index-server.js +2 -0
- package/build/server/chunks/instance.js +3546 -0
- package/build/server/chunks/internal.js +3323 -0
- package/build/server/chunks/navigation.js +16 -0
- package/build/server/chunks/{chunks/queries.js-BEdRnpMa.js → queries.js} +9 -9
- package/build/server/chunks/{chunks/range.js-CiCoLGqh.js → range.js} +3 -2
- package/build/server/chunks/{chunks/refresh.js-0W7-GwaH.js → refresh.js} +7 -7
- package/build/server/chunks/{chunks/request.js-BF7n7fZo.js → request.js} +5 -5
- package/build/server/chunks/server-errors.js +489 -0
- package/build/server/chunks/server.js +9 -0
- package/build/server/chunks/server2.js +1504 -0
- package/build/server/chunks/shared.js +84 -0
- package/build/server/chunks/uneval.js +537 -0
- package/build/server/entries/endpoints/api/refresh/_server.ts.js +12 -0
- package/build/server/entries/endpoints/api/settings/_server.ts.js +15 -0
- package/build/server/entries/endpoints/api/usage/_server.ts.js +8 -0
- package/build/server/entries/fallbacks/error.svelte.js +47 -0
- package/build/server/entries/hooks.server.js +10 -0
- package/build/server/{chunks/entries/pages/_layout.svelte.js-C9kkUOBf.js → entries/pages/_layout.svelte.js} +4 -2
- package/build/server/entries/pages/_page.server.ts.js +12 -0
- package/build/server/{chunks/entries/pages/_page.svelte.js-HFiLlojS.js → entries/pages/_page.svelte.js} +64 -27
- package/build/server/env.js +2 -0
- package/build/server/handler.js +2 -0
- package/build/server/index.js +67 -0
- package/build/server/manifest-full.js +58 -0
- package/build/server/manifest.js +58 -0
- package/build/server/nodes/0.js +8 -0
- package/build/server/nodes/1.js +8 -0
- package/build/server/nodes/2.js +10 -0
- package/build/server/remote-entry.js +1564 -0
- package/build/server/server.js +60 -0
- package/package.json +8 -8
- package/build/client/_app/immutable/chunks/CukLSH0w.js +0 -2
- package/build/client/_app/immutable/chunks/CukLSH0w.js.br +0 -0
- package/build/client/_app/immutable/chunks/CukLSH0w.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js +0 -3
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js.br +0 -0
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js.gz +0 -0
- package/build/client/_app/immutable/chunks/xihTtKlq.js +0 -1
- package/build/client/_app/immutable/chunks/xihTtKlq.js.br +0 -1
- package/build/client/_app/immutable/chunks/xihTtKlq.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js +0 -2
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js +0 -1
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js.br +0 -0
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js +0 -1
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js +0 -1
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js +0 -2
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js.gz +0 -0
- package/build/env.js +0 -70
- package/build/server/chunks/chunks/client.js-9ZtqvVP6.js +0 -28
- package/build/server/chunks/chunks/env.js-l0sNRNKZ.js +0 -2
- package/build/server/chunks/chunks/exports.js-Bbyr-JtB.js +0 -349
- package/build/server/chunks/chunks/internal.js-WGl35QnN.js +0 -1202
- package/build/server/chunks/chunks/internal2.js-BlXt2rfE.js +0 -22
- package/build/server/chunks/chunks/server.js-UOanU7fq.js +0 -5527
- package/build/server/chunks/chunks/shared.js-Dg3Ewm8t.js +0 -255
- package/build/server/chunks/chunks/utils.js-DUDFXVFd.js +0 -1049
- package/build/server/chunks/entries/endpoints/api/refresh/_server.ts.js-CcG44vTx.js +0 -21
- package/build/server/chunks/entries/endpoints/api/settings/_server.ts.js-B0LWCQis.js +0 -24
- package/build/server/chunks/entries/endpoints/api/usage/_server.ts.js-CJGTdjik.js +0 -17
- package/build/server/chunks/entries/fallbacks/error.svelte.js-D7UgI0q0.js +0 -68
- package/build/server/chunks/entries/hooks.server.js-_Fcw_IVA.js +0 -16
- package/build/server/chunks/entries/pages/_page.server.ts.js-BBibcAZP.js +0 -17
- package/build/server/chunks/handler-TvIKu86j.js +0 -1475
- package/build/server/chunks/index.js-C3LwYUKO.js +0 -3972
- package/build/server/chunks/manifest.js-CZoz0xLc.js +0 -63
- package/build/server/chunks/nodes/0.js-7EReDAeT.js +0 -9
- package/build/server/chunks/nodes/1.js-BcW8BjKg.js +0 -9
- package/build/server/chunks/nodes/2.js-fS9KDy-5.js +0 -20
- package/build/shims.js +0 -33
|
@@ -0,0 +1,1564 @@
|
|
|
1
|
+
import { t as prerendering } from "./chunks/server.js";
|
|
2
|
+
import { $ as parse, Ft as MUTATIVE_METHODS, Jt as app_dir, K as parse_remote_arg, W as create_remote_key, at as deep_set, ct as parse_form_key, et as stringify, it as create_field_proxy, jt as with_request_store, k as handle_error_and_jsonify, kt as get_request_store, lt as split_path, mt as error, ot as flatten_issues, q as stringify_remote_arg, st as normalize_issue } from "./chunks/internal.js";
|
|
3
|
+
import { n as HandledHttpError, o as ValidationError } from "./chunks/shared.js";
|
|
4
|
+
import { A as remote_cookie_forbidden, B as remote_requested_context, D as remote_command_method, F as remote_query_live_no_value, G as server_api_unavailable, H as remote_requested_invalid_query, I as remote_query_live_not_iterable, L as remote_query_prerender, N as remote_headers_forbidden, O as remote_command_readonly, P as remote_invalid_validator, R as remote_request_property, U as remote_requested_wrong_method, V as remote_requested_invalid_limit, j as remote_cookie_path_relative, k as remote_command_render, z as remote_requested_async_validator } from "./chunks/server-errors.js";
|
|
5
|
+
import { n as noop } from "./chunks/functions.js";
|
|
6
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/shared.js
|
|
7
|
+
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
8
|
+
/** @import { MaybePromise, RequestState, RemoteInternals, RequestStore, RemoteLiveQueryUserFunctionReturnType } from 'types' */
|
|
9
|
+
/**
|
|
10
|
+
* @param {any} validate_or_fn
|
|
11
|
+
* @param {((arg?: any) => any) | undefined} [maybe_fn]
|
|
12
|
+
* @returns {(arg?: any) => MaybePromise<any>}
|
|
13
|
+
*/
|
|
14
|
+
function create_validator(validate_or_fn, maybe_fn) {
|
|
15
|
+
if (!maybe_fn) return (arg) => {
|
|
16
|
+
if (arg !== void 0) error(400, "Bad Request");
|
|
17
|
+
};
|
|
18
|
+
if (validate_or_fn === "unchecked") return (arg) => arg;
|
|
19
|
+
if ("~standard" in validate_or_fn) return async (arg) => {
|
|
20
|
+
const result = await validate_or_fn["~standard"].validate(arg);
|
|
21
|
+
if (result.issues) throw new ValidationError(result.issues);
|
|
22
|
+
return result.value;
|
|
23
|
+
};
|
|
24
|
+
remote_invalid_validator();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* In case of a single remote function call, just returns the result.
|
|
28
|
+
*
|
|
29
|
+
* In case of a full page reload, returns the response for a remote function call,
|
|
30
|
+
* either from the cache or by invoking the function.
|
|
31
|
+
* Also saves an uneval'ed version of the result for later HTML inlining for hydration.
|
|
32
|
+
*
|
|
33
|
+
* @template {MaybePromise<any>} T
|
|
34
|
+
* @param {RemoteInternals} internals
|
|
35
|
+
* @param {string} payload — the stringified raw argument (i.e. the cache key the client will use)
|
|
36
|
+
* @param {RequestState} state
|
|
37
|
+
* @param {() => Promise<T>} get_result
|
|
38
|
+
* @returns {Promise<T>}
|
|
39
|
+
*/
|
|
40
|
+
async function get_response(internals, payload, state, get_result) {
|
|
41
|
+
await 0;
|
|
42
|
+
const cache = get_cache(internals, state);
|
|
43
|
+
if (!state.is_in_remote_query) get_implicit_lookup(internals, state)[payload] = get_result;
|
|
44
|
+
return cache[payload] ??= get_result();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {RequestEvent} event
|
|
48
|
+
* @param {RequestState} state
|
|
49
|
+
* @param {boolean} allow_cookies
|
|
50
|
+
* @returns {RequestStore}
|
|
51
|
+
*/
|
|
52
|
+
function derive_remote_function_event(event, state, allow_cookies) {
|
|
53
|
+
/** @type {RequestEvent} */
|
|
54
|
+
const derived = {
|
|
55
|
+
...event,
|
|
56
|
+
setHeaders: () => {
|
|
57
|
+
remote_headers_forbidden();
|
|
58
|
+
},
|
|
59
|
+
cookies: {
|
|
60
|
+
...event.cookies,
|
|
61
|
+
set: (name, value, opts) => {
|
|
62
|
+
if (!allow_cookies) remote_cookie_forbidden({ operation: "set" });
|
|
63
|
+
if (opts?.path && !opts.path.startsWith("/")) remote_cookie_path_relative({ operation: "set" });
|
|
64
|
+
return event.cookies.set(name, value, opts);
|
|
65
|
+
},
|
|
66
|
+
delete: (name, opts) => {
|
|
67
|
+
if (!allow_cookies) remote_cookie_forbidden({ operation: "delete" });
|
|
68
|
+
if (opts?.path && !opts.path.startsWith("/")) remote_cookie_path_relative({ operation: "deleted" });
|
|
69
|
+
return event.cookies.delete(name, opts);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (state.is_in_remote_query) for (const property of [
|
|
74
|
+
"url",
|
|
75
|
+
"params",
|
|
76
|
+
"route"
|
|
77
|
+
]) Object.defineProperty(derived, property, {
|
|
78
|
+
enumerable: false,
|
|
79
|
+
get() {
|
|
80
|
+
return remote_request_property({ property });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
event: derived,
|
|
85
|
+
state: {
|
|
86
|
+
...state,
|
|
87
|
+
is_in_remote_function: true
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Like `with_event` but removes things from `event` you cannot see/call in remote functions, such as `setHeaders`.
|
|
93
|
+
* @template T
|
|
94
|
+
* @param {RequestEvent} event
|
|
95
|
+
* @param {RequestState} state
|
|
96
|
+
* @param {boolean} allow_cookies
|
|
97
|
+
* @param {() => any} get_input
|
|
98
|
+
* @param {(arg?: any) => T} fn
|
|
99
|
+
*/
|
|
100
|
+
async function run_remote_function(event, state, allow_cookies, get_input, fn) {
|
|
101
|
+
const store = derive_remote_function_event(event, state, allow_cookies);
|
|
102
|
+
const input = await with_request_store(store, get_input);
|
|
103
|
+
return with_request_store(store, () => fn(input));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Like `with_event` but removes things from `event` you cannot see/call in remote functions, such as `setHeaders`.
|
|
107
|
+
* @template T
|
|
108
|
+
* @param {RequestEvent} event
|
|
109
|
+
* @param {RequestState} state
|
|
110
|
+
* @param {boolean} allow_cookies
|
|
111
|
+
* @param {() => any} get_input
|
|
112
|
+
* @param {(arg?: any) => RemoteLiveQueryUserFunctionReturnType<T>} fn
|
|
113
|
+
* @param {string} name
|
|
114
|
+
*/
|
|
115
|
+
async function* run_remote_generator(event, state, allow_cookies, get_input, fn, name) {
|
|
116
|
+
const store = derive_remote_function_event(event, state, allow_cookies);
|
|
117
|
+
const input = await with_request_store(store, get_input);
|
|
118
|
+
const iterator = to_iterator(await with_request_store(store, () => fn(input)), name);
|
|
119
|
+
let done = false;
|
|
120
|
+
try {
|
|
121
|
+
while (true) {
|
|
122
|
+
const result = await with_request_store(store, () => iterator.next());
|
|
123
|
+
if (result.done) {
|
|
124
|
+
done = true;
|
|
125
|
+
return result.value;
|
|
126
|
+
}
|
|
127
|
+
yield result.value;
|
|
128
|
+
}
|
|
129
|
+
} finally {
|
|
130
|
+
if (!done && typeof iterator.return === "function") await with_request_store(store, () => iterator.return?.(void 0));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @template T
|
|
135
|
+
* @param {Awaited<RemoteLiveQueryUserFunctionReturnType<T>>} source
|
|
136
|
+
* @param {string} name
|
|
137
|
+
* @returns {Iterator<T> | AsyncIterator<T>}
|
|
138
|
+
*/
|
|
139
|
+
function to_iterator(source, name) {
|
|
140
|
+
if ("next" in source && typeof source.next === "function") return source;
|
|
141
|
+
if (Symbol.asyncIterator in source && typeof source[Symbol.asyncIterator] === "function") return source[Symbol.asyncIterator]();
|
|
142
|
+
if (Symbol.iterator in source && typeof source[Symbol.iterator] === "function") return source[Symbol.iterator]();
|
|
143
|
+
remote_query_live_not_iterable({ name });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Note that `state` is deliberately not optional: resources that capture the request
|
|
147
|
+
* state at creation must pass it explicitly, because reading it from the request store
|
|
148
|
+
* at call time is only equivalent on runtimes with `AsyncLocalStorage` support.
|
|
149
|
+
* Callers without a captured state (such as the module-level `form` instance getters)
|
|
150
|
+
* should pass `get_request_store().state` themselves.
|
|
151
|
+
* @param {RemoteInternals} internals
|
|
152
|
+
* @param {RequestState} state
|
|
153
|
+
*/
|
|
154
|
+
function get_cache(internals, state) {
|
|
155
|
+
let cache = state.remote.data?.get(internals);
|
|
156
|
+
if (cache === void 0) {
|
|
157
|
+
cache = {};
|
|
158
|
+
(state.remote.data ??= /* @__PURE__ */ new Map()).set(internals, cache);
|
|
159
|
+
}
|
|
160
|
+
return cache;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @param {RemoteInternals} internals
|
|
164
|
+
* @param {RequestState} state
|
|
165
|
+
*/
|
|
166
|
+
function get_implicit_lookup(internals, state) {
|
|
167
|
+
let cache = state.remote.implicit?.get(internals);
|
|
168
|
+
if (cache === void 0) {
|
|
169
|
+
cache = {};
|
|
170
|
+
(state.remote.implicit ??= /* @__PURE__ */ new Map()).set(internals, cache);
|
|
171
|
+
}
|
|
172
|
+
return cache;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/command.js
|
|
176
|
+
/** @import { RemoteCommand } from '$app/server' */
|
|
177
|
+
/** @import { MaybePromise, RemoteCommandInternals } from 'types' */
|
|
178
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
179
|
+
/**
|
|
180
|
+
* Creates a remote command. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
181
|
+
*
|
|
182
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
183
|
+
*
|
|
184
|
+
* @template Output
|
|
185
|
+
* @overload
|
|
186
|
+
* @param {() => MaybePromise<Output>} fn
|
|
187
|
+
* @returns {RemoteCommand<void, Output>}
|
|
188
|
+
* @since 2.27
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* Creates a remote command. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
192
|
+
*
|
|
193
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
194
|
+
*
|
|
195
|
+
* @template Input
|
|
196
|
+
* @template Output
|
|
197
|
+
* @overload
|
|
198
|
+
* @param {'unchecked'} validate
|
|
199
|
+
* @param {(arg: Input) => MaybePromise<Output>} fn
|
|
200
|
+
* @returns {RemoteCommand<Input, Output>}
|
|
201
|
+
* @since 2.27
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* Creates a remote command. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
205
|
+
*
|
|
206
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
207
|
+
*
|
|
208
|
+
* @template {StandardSchemaV1} Schema
|
|
209
|
+
* @template Output
|
|
210
|
+
* @overload
|
|
211
|
+
* @param {Schema} validate
|
|
212
|
+
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => MaybePromise<Output>} fn
|
|
213
|
+
* @returns {RemoteCommand<StandardSchemaV1.InferInput<Schema>, Output>}
|
|
214
|
+
* @since 2.27
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* @template Input
|
|
218
|
+
* @template Output
|
|
219
|
+
* @param {any} validate_or_fn
|
|
220
|
+
* @param {(arg?: Input) => MaybePromise<Output>} [maybe_fn]
|
|
221
|
+
* @returns {RemoteCommand<Input, Output>}
|
|
222
|
+
* @since 2.27
|
|
223
|
+
*/
|
|
224
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
225
|
+
function command(validate_or_fn, maybe_fn) {
|
|
226
|
+
/** @type {(arg?: Input) => MaybePromise<Output>} */
|
|
227
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
228
|
+
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
229
|
+
const validate = create_validator(validate_or_fn, maybe_fn);
|
|
230
|
+
/** @type {RemoteCommandInternals} */
|
|
231
|
+
const __ = {
|
|
232
|
+
type: "command",
|
|
233
|
+
id: "",
|
|
234
|
+
name: ""
|
|
235
|
+
};
|
|
236
|
+
/** @type {RemoteCommand<Input, Output> & { __: RemoteCommandInternals }} */
|
|
237
|
+
const wrapper = (arg) => {
|
|
238
|
+
const { event, state } = get_request_store();
|
|
239
|
+
if (!MUTATIVE_METHODS.includes(event.request.method) || state.is_in_remote_query || state.is_in_remote_prerender) {
|
|
240
|
+
if (state.is_in_remote_query || state.is_in_remote_prerender) remote_command_readonly({ name: __.name });
|
|
241
|
+
remote_command_method({
|
|
242
|
+
name: __.name,
|
|
243
|
+
method: event.request.method
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (state.is_in_render) remote_command_render({ name: __.name });
|
|
247
|
+
const promise = Promise.resolve(run_remote_function(event, state, true, () => validate(arg), fn));
|
|
248
|
+
promise.updates = () => {
|
|
249
|
+
server_api_unavailable({ name: `${__.name}(...).updates(...)` });
|
|
250
|
+
};
|
|
251
|
+
return promise;
|
|
252
|
+
};
|
|
253
|
+
Object.defineProperty(wrapper, "__", { value: __ });
|
|
254
|
+
Object.defineProperty(wrapper, "pending", { get: () => 0 });
|
|
255
|
+
return wrapper;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/form.js
|
|
259
|
+
/** @import { RemoteFormInput, RemoteForm, RemoteFormInvalidField } from '$app/server' */
|
|
260
|
+
/** @import { InternalRemoteFormIssue, MaybePromise, HasNonOptionalBoolean, RemoteFormInternals } from 'types' */
|
|
261
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
262
|
+
/**
|
|
263
|
+
* Creates a form object that can be spread onto a `<form>` element.
|
|
264
|
+
*
|
|
265
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
266
|
+
*
|
|
267
|
+
* @template Output
|
|
268
|
+
* @overload
|
|
269
|
+
* @param {() => MaybePromise<Output>} fn
|
|
270
|
+
* @returns {RemoteForm<void, Output>}
|
|
271
|
+
* @since 2.27
|
|
272
|
+
*/
|
|
273
|
+
/**
|
|
274
|
+
* Creates a form object that can be spread onto a `<form>` element.
|
|
275
|
+
*
|
|
276
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
277
|
+
*
|
|
278
|
+
* @template {RemoteFormInput} Input
|
|
279
|
+
* @template Output
|
|
280
|
+
* @overload
|
|
281
|
+
* @param {'unchecked'} validate
|
|
282
|
+
* @param {(data: Input, issue: RemoteFormInvalidField<Input>) => MaybePromise<Output>} fn
|
|
283
|
+
* @returns {RemoteForm<Input, Output>}
|
|
284
|
+
* @since 2.27
|
|
285
|
+
*/
|
|
286
|
+
/**
|
|
287
|
+
* Creates a form object that can be spread onto a `<form>` element.
|
|
288
|
+
*
|
|
289
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
290
|
+
*
|
|
291
|
+
* @template {StandardSchemaV1<RemoteFormInput, Record<string, any>>} Schema
|
|
292
|
+
* @template Output
|
|
293
|
+
* @overload
|
|
294
|
+
* @param {true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? 'Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked.' : Schema} validate
|
|
295
|
+
* @param {(data: StandardSchemaV1.InferOutput<Schema>, issue: RemoteFormInvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>} fn
|
|
296
|
+
* @returns {RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>}
|
|
297
|
+
* @since 2.27
|
|
298
|
+
*/
|
|
299
|
+
/**
|
|
300
|
+
* @template {RemoteFormInput} Input
|
|
301
|
+
* @template Output
|
|
302
|
+
* @param {any} validate_or_fn
|
|
303
|
+
* @param {(data_or_issue: any, issue?: any) => MaybePromise<Output>} [maybe_fn]
|
|
304
|
+
* @returns {RemoteForm<Input, Output>}
|
|
305
|
+
* @since 2.27
|
|
306
|
+
*/
|
|
307
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
308
|
+
function form(validate_or_fn, maybe_fn) {
|
|
309
|
+
/** @type {any} */
|
|
310
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
311
|
+
/** @type {StandardSchemaV1 | null} */
|
|
312
|
+
const schema = !maybe_fn || validate_or_fn === "unchecked" ? null : validate_or_fn;
|
|
313
|
+
/**
|
|
314
|
+
* @param {string | number | boolean} [key]
|
|
315
|
+
*/
|
|
316
|
+
function create_instance(key) {
|
|
317
|
+
const instance = {};
|
|
318
|
+
instance.method = "POST";
|
|
319
|
+
Object.defineProperty(instance, "enhance", { value: () => {
|
|
320
|
+
return {
|
|
321
|
+
action: instance.action,
|
|
322
|
+
method: instance.method
|
|
323
|
+
};
|
|
324
|
+
} });
|
|
325
|
+
/** @type {RemoteFormInternals} */
|
|
326
|
+
const __ = {
|
|
327
|
+
type: "form",
|
|
328
|
+
name: "",
|
|
329
|
+
id: "",
|
|
330
|
+
fn: async (data, meta, form_data) => {
|
|
331
|
+
const output = {};
|
|
332
|
+
output.submission = true;
|
|
333
|
+
const { event, state } = get_request_store();
|
|
334
|
+
const validated = await schema?.["~standard"].validate(data);
|
|
335
|
+
if (meta.validate_only) return validated?.issues?.map((issue) => normalize_issue(issue, true)) ?? [];
|
|
336
|
+
if (validated?.issues !== void 0) handle_issues(output, validated.issues, form_data, __.id);
|
|
337
|
+
else {
|
|
338
|
+
if (validated !== void 0) data = validated.value;
|
|
339
|
+
const issue = create_issues();
|
|
340
|
+
try {
|
|
341
|
+
output.result = await run_remote_function(event, state, true, () => data, (data) => !maybe_fn ? fn() : fn(data, issue));
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (error instanceof ValidationError) handle_issues(output, error.issues, form_data, __.id);
|
|
344
|
+
else throw error;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!event.isRemoteRequest) {
|
|
348
|
+
const cache = get_cache(__, state);
|
|
349
|
+
cache[""] ??= output;
|
|
350
|
+
get_implicit_lookup(__, state)[__.key ? `${__.id}/${__.key}` : __.id] = () => cache[""];
|
|
351
|
+
}
|
|
352
|
+
return output;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
Object.defineProperty(instance, "__", { value: __ });
|
|
356
|
+
Object.defineProperty(instance, "action", {
|
|
357
|
+
get: () => {
|
|
358
|
+
const { event, state } = get_request_store();
|
|
359
|
+
const search = new URLSearchParams(state.prerendering ? "" : event.url.search);
|
|
360
|
+
search.delete("/remote");
|
|
361
|
+
const query = search.toString();
|
|
362
|
+
const action_id = __.key ? `${__.id}/${encodeURIComponent(__.key)}` : __.id;
|
|
363
|
+
return `?${query ? `${query}&` : ""}/remote=${action_id}`;
|
|
364
|
+
},
|
|
365
|
+
enumerable: true
|
|
366
|
+
});
|
|
367
|
+
Object.defineProperty(instance, "fields", { get() {
|
|
368
|
+
return create_field_proxy({
|
|
369
|
+
form_id: __.id,
|
|
370
|
+
get: () => get_cache(__, get_request_store().state)?.[""]?.input ?? {},
|
|
371
|
+
set: (path, value) => {
|
|
372
|
+
const cache = get_cache(__, get_request_store().state);
|
|
373
|
+
const entry = cache[""];
|
|
374
|
+
if (entry?.submission) return;
|
|
375
|
+
if (path.length === 0) {
|
|
376
|
+
(cache[""] ??= {}).input = value;
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const input = entry?.input ?? {};
|
|
380
|
+
deep_set(input, path.map(String), value);
|
|
381
|
+
(cache[""] ??= {}).input = input;
|
|
382
|
+
},
|
|
383
|
+
get_issues: () => flatten_issues(get_cache(__, get_request_store().state)?.[""]?.issues ?? []),
|
|
384
|
+
get_touched: () => ({}),
|
|
385
|
+
get_dirty: () => ({})
|
|
386
|
+
});
|
|
387
|
+
} });
|
|
388
|
+
Object.defineProperty(instance, "result", { get() {
|
|
389
|
+
try {
|
|
390
|
+
return get_cache(__, get_request_store().state)?.[""]?.result;
|
|
391
|
+
} catch {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
} });
|
|
395
|
+
Object.defineProperty(instance, "pending", { get: () => 0 });
|
|
396
|
+
Object.defineProperty(instance, "submitted", { get: () => false });
|
|
397
|
+
Object.defineProperty(instance, "preflight", { value: () => instance });
|
|
398
|
+
Object.defineProperty(instance, "validate", { value: () => {
|
|
399
|
+
server_api_unavailable({ name: "form.validate()" });
|
|
400
|
+
} });
|
|
401
|
+
Object.defineProperty(instance, "submit", { value: () => {
|
|
402
|
+
server_api_unavailable({ name: "form.submit()" });
|
|
403
|
+
} });
|
|
404
|
+
Object.defineProperty(instance, "element", { get: () => null });
|
|
405
|
+
if (key == void 0) Object.defineProperty(instance, "for", {
|
|
406
|
+
/** @type {RemoteForm<any, any>['for']} */
|
|
407
|
+
value: (key) => {
|
|
408
|
+
const { state } = get_request_store();
|
|
409
|
+
const cache_key = __.id + "|" + JSON.stringify(key);
|
|
410
|
+
/** @type {RemoteForm<Input, Output> & { __: RemoteFormInternals }} */
|
|
411
|
+
let instance = (state.remote.forms ??= /* @__PURE__ */ new Map()).get(cache_key);
|
|
412
|
+
if (!instance) {
|
|
413
|
+
instance = create_instance(key);
|
|
414
|
+
instance.__.id = __.id;
|
|
415
|
+
instance.__.key = JSON.stringify(key);
|
|
416
|
+
instance.__.name = __.name;
|
|
417
|
+
state.remote.forms.set(cache_key, instance);
|
|
418
|
+
}
|
|
419
|
+
return instance;
|
|
420
|
+
} });
|
|
421
|
+
return instance;
|
|
422
|
+
}
|
|
423
|
+
return create_instance();
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @param {{ issues?: InternalRemoteFormIssue[], input?: Record<string, any>, result: any }} output
|
|
427
|
+
* @param {readonly StandardSchemaV1.Issue[]} issues
|
|
428
|
+
* @param {FormData | null} form_data - null if the form is progressively enhanced
|
|
429
|
+
* @param {string} form_id - hash/name of the form
|
|
430
|
+
*/
|
|
431
|
+
function handle_issues(output, issues, form_data, form_id) {
|
|
432
|
+
output.issues = issues.map((issue) => normalize_issue(issue, true));
|
|
433
|
+
if (form_data) {
|
|
434
|
+
output.input = {};
|
|
435
|
+
for (const field_name of form_data.keys()) {
|
|
436
|
+
const field = parse_form_key(form_id, field_name);
|
|
437
|
+
const path = split_path(field.name);
|
|
438
|
+
if (path.some((part) => part.startsWith("_"))) continue;
|
|
439
|
+
const values = form_data.getAll(field_name).filter((value) => typeof value === "string");
|
|
440
|
+
deep_set(output.input, path, field.is_array ? values : values[0]);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Creates an invalid function that can be used to imperatively mark form fields as invalid
|
|
446
|
+
* @returns {RemoteFormInvalidField<any>}
|
|
447
|
+
*/
|
|
448
|
+
function create_issues() {
|
|
449
|
+
return new Proxy(
|
|
450
|
+
/** @param {string} message */
|
|
451
|
+
(message) => {
|
|
452
|
+
return create_issue(message);
|
|
453
|
+
},
|
|
454
|
+
{ get(target, prop) {
|
|
455
|
+
if (typeof prop === "symbol") return target[prop];
|
|
456
|
+
return create_issue_proxy(prop, []);
|
|
457
|
+
} }
|
|
458
|
+
);
|
|
459
|
+
/**
|
|
460
|
+
* @param {string} message
|
|
461
|
+
* @param {(string | number)[]} path
|
|
462
|
+
* @returns {StandardSchemaV1.Issue}
|
|
463
|
+
*/
|
|
464
|
+
function create_issue(message, path = []) {
|
|
465
|
+
return {
|
|
466
|
+
message,
|
|
467
|
+
path
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Creates a proxy that builds up a path and returns a function to create an issue
|
|
472
|
+
* @param {string | number} key
|
|
473
|
+
* @param {(string | number)[]} path
|
|
474
|
+
*/
|
|
475
|
+
function create_issue_proxy(key, path) {
|
|
476
|
+
const new_path = [...path, key];
|
|
477
|
+
/**
|
|
478
|
+
* @param {string} message
|
|
479
|
+
* @returns {StandardSchemaV1.Issue}
|
|
480
|
+
*/
|
|
481
|
+
const issue_func = (message) => create_issue(message, new_path);
|
|
482
|
+
return new Proxy(issue_func, { get(target, prop) {
|
|
483
|
+
if (typeof prop === "symbol") return target[prop];
|
|
484
|
+
if (/^\d+$/.test(prop)) return create_issue_proxy(parseInt(prop, 10), new_path);
|
|
485
|
+
return create_issue_proxy(prop, new_path);
|
|
486
|
+
} });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/prerender.js
|
|
491
|
+
/** @import { RemoteResource, RemotePrerenderFunction } from '$app/server' */
|
|
492
|
+
/** @import { RemoteFunctionResponse, RemotePrerenderInputsGenerator, RemotePrerenderInternals, MaybePromise } from 'types' */
|
|
493
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
494
|
+
/**
|
|
495
|
+
* Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
496
|
+
*
|
|
497
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
498
|
+
*
|
|
499
|
+
* @template Output
|
|
500
|
+
* @overload
|
|
501
|
+
* @param {() => MaybePromise<Output>} fn
|
|
502
|
+
* @param {{ inputs?: RemotePrerenderInputsGenerator<void>, dynamic?: boolean }} [options]
|
|
503
|
+
* @returns {RemotePrerenderFunction<void, Output>}
|
|
504
|
+
* @since 2.27
|
|
505
|
+
*/
|
|
506
|
+
/**
|
|
507
|
+
* Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
508
|
+
*
|
|
509
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
510
|
+
*
|
|
511
|
+
* @template Input
|
|
512
|
+
* @template Output
|
|
513
|
+
* @overload
|
|
514
|
+
* @param {'unchecked'} validate
|
|
515
|
+
* @param {(arg: Input) => MaybePromise<Output>} fn
|
|
516
|
+
* @param {{ inputs?: RemotePrerenderInputsGenerator<Input>, dynamic?: boolean }} [options]
|
|
517
|
+
* @returns {RemotePrerenderFunction<Input, Output>}
|
|
518
|
+
* @since 2.27
|
|
519
|
+
*/
|
|
520
|
+
/**
|
|
521
|
+
* Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
522
|
+
*
|
|
523
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
524
|
+
*
|
|
525
|
+
* @template {StandardSchemaV1} Schema
|
|
526
|
+
* @template Output
|
|
527
|
+
* @overload
|
|
528
|
+
* @param {Schema} schema
|
|
529
|
+
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => MaybePromise<Output>} fn
|
|
530
|
+
* @param {{ inputs?: RemotePrerenderInputsGenerator<StandardSchemaV1.InferInput<Schema>>, dynamic?: boolean }} [options]
|
|
531
|
+
* @returns {RemotePrerenderFunction<StandardSchemaV1.InferInput<Schema>, Output>}
|
|
532
|
+
* @since 2.27
|
|
533
|
+
*/
|
|
534
|
+
/**
|
|
535
|
+
* @template Input
|
|
536
|
+
* @template Output
|
|
537
|
+
* @param {any} validate_or_fn
|
|
538
|
+
* @param {any} [fn_or_options]
|
|
539
|
+
* @param {{ inputs?: RemotePrerenderInputsGenerator<Input>, dynamic?: boolean }} [maybe_options]
|
|
540
|
+
* @returns {RemotePrerenderFunction<Input, Output>}
|
|
541
|
+
* @since 2.27
|
|
542
|
+
*/
|
|
543
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
544
|
+
function prerender(validate_or_fn, fn_or_options, maybe_options) {
|
|
545
|
+
const maybe_fn = typeof fn_or_options === "function" ? fn_or_options : void 0;
|
|
546
|
+
/** @type {typeof maybe_options} */
|
|
547
|
+
const options = maybe_options ?? (maybe_fn ? void 0 : fn_or_options);
|
|
548
|
+
/** @type {(arg?: Input) => MaybePromise<Output>} */
|
|
549
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
550
|
+
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
551
|
+
const validate = create_validator(validate_or_fn, maybe_fn);
|
|
552
|
+
/** @type {RemotePrerenderInternals} */
|
|
553
|
+
const __ = {
|
|
554
|
+
type: "prerender",
|
|
555
|
+
id: "",
|
|
556
|
+
name: "",
|
|
557
|
+
has_arg: !!maybe_fn,
|
|
558
|
+
inputs: options?.inputs,
|
|
559
|
+
dynamic: options?.dynamic
|
|
560
|
+
};
|
|
561
|
+
/** @type {RemotePrerenderFunction<Input, Output> & { __: RemotePrerenderInternals }} */
|
|
562
|
+
const wrapper = (arg) => {
|
|
563
|
+
const { event, state } = get_request_store();
|
|
564
|
+
const payload = stringify_remote_arg(arg);
|
|
565
|
+
/** @type {Promise<Output> & Partial<RemoteResource<Output>>} */
|
|
566
|
+
const promise = get_response(__, payload, state, async () => {
|
|
567
|
+
const id = __.id;
|
|
568
|
+
const url = `/${app_dir}/remote/${id}${payload ? `/${payload}` : ""}`;
|
|
569
|
+
if (!state.prerendering && !event.isRemoteRequest) {
|
|
570
|
+
/** @type {RemoteFunctionResponse | undefined} */
|
|
571
|
+
let prerendered;
|
|
572
|
+
try {
|
|
573
|
+
const response = await fetch(new URL(url, event.request.url).href, { redirect: "manual" });
|
|
574
|
+
if (response.ok) prerendered = await response.json();
|
|
575
|
+
} catch {}
|
|
576
|
+
if (prerendered) {
|
|
577
|
+
if (prerendered.type === "error") throw new HandledHttpError(prerendered.error);
|
|
578
|
+
return parse(prerendered.data)._;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (state.prerendering?.remote_responses.has(url)) return state.prerendering.remote_responses.get(url);
|
|
582
|
+
const promise = run_remote_function(event, {
|
|
583
|
+
...state,
|
|
584
|
+
is_in_remote_prerender: true
|
|
585
|
+
}, false, () => validate(arg), fn);
|
|
586
|
+
if (state.prerendering) state.prerendering.remote_responses.set(url, promise);
|
|
587
|
+
const result = await promise;
|
|
588
|
+
if (state.prerendering) {
|
|
589
|
+
const body = {
|
|
590
|
+
type: "result",
|
|
591
|
+
data: stringify({ _: result })
|
|
592
|
+
};
|
|
593
|
+
state.prerendering.dependencies.set(url, {
|
|
594
|
+
body: JSON.stringify(body),
|
|
595
|
+
response: Response.json(body)
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return result;
|
|
599
|
+
});
|
|
600
|
+
promise.catch(noop);
|
|
601
|
+
return promise;
|
|
602
|
+
};
|
|
603
|
+
Object.defineProperty(wrapper, "__", { value: __ });
|
|
604
|
+
return wrapper;
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region node_modules/@sveltejs/kit/src/utils/shared-iterator.js
|
|
608
|
+
/**
|
|
609
|
+
* A pull-style async iterator that fans out a single stream of values to
|
|
610
|
+
* multiple `for await (...)` consumers. Each subscriber gets its own
|
|
611
|
+
* `AsyncGenerator` whose `.next()` resolves whenever a value is pushed via
|
|
612
|
+
* `push(value)`. Multiple consumers see the same values without each one
|
|
613
|
+
* driving an independent underlying source.
|
|
614
|
+
*
|
|
615
|
+
* Backpressure is **latest-wins**: if values arrive faster than a particular
|
|
616
|
+
* consumer drains its iterator, only the most-recently-pushed value is kept
|
|
617
|
+
* pending for that subscriber. Earlier undrained values are dropped. This is
|
|
618
|
+
* appropriate for live data streams (reactive state replication), not for
|
|
619
|
+
* event logs where every value must be delivered.
|
|
620
|
+
*
|
|
621
|
+
* Lifecycle hooks are exposed via the constructor:
|
|
622
|
+
*
|
|
623
|
+
* - `start()` is called when the subscriber count transitions
|
|
624
|
+
* from 0 to 1 (e.g. to start a pump pulling from a real source).
|
|
625
|
+
* - `stop()` is called when the subscriber count transitions
|
|
626
|
+
* from non-zero back to 0 (e.g. to tear down that pump).
|
|
627
|
+
*
|
|
628
|
+
* Either hook may be omitted.
|
|
629
|
+
*
|
|
630
|
+
* The owner is responsible for calling `push(value)` to broadcast values,
|
|
631
|
+
* `done()` to signal natural completion to all subscribers, and `fail(error)`
|
|
632
|
+
* to broadcast a terminal error. After `done()` or `fail()`, the iterator
|
|
633
|
+
* rejects further `subscribe()` calls with the terminal state appropriately.
|
|
634
|
+
*
|
|
635
|
+
* @template T
|
|
636
|
+
*/
|
|
637
|
+
var SharedIterator = class {
|
|
638
|
+
/**
|
|
639
|
+
* @typedef {object} Subscriber
|
|
640
|
+
* @property {{ value: any } | null} pending
|
|
641
|
+
* @property {{ error: unknown } | null} pending_error
|
|
642
|
+
* @property {boolean} finished
|
|
643
|
+
* @property {((result: IteratorResult<any, void>) => void) | null} waiting_resolve
|
|
644
|
+
* @property {((reason: unknown) => void) | null} waiting_reject
|
|
645
|
+
*/
|
|
646
|
+
/** @type {Set<Subscriber>} */
|
|
647
|
+
#subscribers = /* @__PURE__ */ new Set();
|
|
648
|
+
/** @type {((instance: SharedIterator<T>) => (() => void)) | undefined} */
|
|
649
|
+
#start = void 0;
|
|
650
|
+
/** @type {(() => void) | undefined} */
|
|
651
|
+
#stop = void 0;
|
|
652
|
+
/** Once `done()` or `fail()` has been broadcast, no new values are accepted. */
|
|
653
|
+
#closed = false;
|
|
654
|
+
/** @type {unknown} */
|
|
655
|
+
#terminal_error = void 0;
|
|
656
|
+
/** Whether `done()` or `fail()` has been broadcast. */
|
|
657
|
+
get closed() {
|
|
658
|
+
return this.#closed;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* @param {(instance: SharedIterator<T>) => (() => void)} [start]
|
|
662
|
+
*/
|
|
663
|
+
constructor(start) {
|
|
664
|
+
this.#start = start;
|
|
665
|
+
}
|
|
666
|
+
/** @param {T} value */
|
|
667
|
+
push(value) {
|
|
668
|
+
if (this.#closed) return;
|
|
669
|
+
for (const subscriber of this.#subscribers) if (subscriber.waiting_resolve) {
|
|
670
|
+
const resolve = subscriber.waiting_resolve;
|
|
671
|
+
subscriber.waiting_resolve = null;
|
|
672
|
+
subscriber.waiting_reject = null;
|
|
673
|
+
resolve({
|
|
674
|
+
value,
|
|
675
|
+
done: false
|
|
676
|
+
});
|
|
677
|
+
} else subscriber.pending = { value };
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Signal natural completion to all current subscribers, and to any future
|
|
681
|
+
* subscriber (which will receive an immediately-done iterator).
|
|
682
|
+
*/
|
|
683
|
+
done() {
|
|
684
|
+
if (this.#closed) return;
|
|
685
|
+
this.#closed = true;
|
|
686
|
+
for (const subscriber of this.#subscribers) {
|
|
687
|
+
subscriber.finished = true;
|
|
688
|
+
if (subscriber.waiting_resolve) {
|
|
689
|
+
const resolve = subscriber.waiting_resolve;
|
|
690
|
+
subscriber.waiting_resolve = null;
|
|
691
|
+
subscriber.waiting_reject = null;
|
|
692
|
+
resolve({
|
|
693
|
+
value: void 0,
|
|
694
|
+
done: true
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
this.#subscribers.clear();
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Broadcast a terminal error. All current subscribers will reject their
|
|
702
|
+
* next `.next()` call with `error`. Future subscribers will also reject
|
|
703
|
+
* their first `.next()`.
|
|
704
|
+
*
|
|
705
|
+
* @param {unknown} error
|
|
706
|
+
*/
|
|
707
|
+
fail(error) {
|
|
708
|
+
if (this.#closed) return;
|
|
709
|
+
this.#closed = true;
|
|
710
|
+
this.#terminal_error = error;
|
|
711
|
+
for (const subscriber of this.#subscribers) {
|
|
712
|
+
subscriber.finished = true;
|
|
713
|
+
if (subscriber.waiting_reject) {
|
|
714
|
+
const reject = subscriber.waiting_reject;
|
|
715
|
+
subscriber.waiting_resolve = null;
|
|
716
|
+
subscriber.waiting_reject = null;
|
|
717
|
+
reject(error);
|
|
718
|
+
} else subscriber.pending_error = { error };
|
|
719
|
+
}
|
|
720
|
+
this.#subscribers.clear();
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Subscribe to the shared stream. Returns an `AsyncGenerator<T>` that
|
|
724
|
+
* yields every value pushed after this call (and, if `initial_value` is
|
|
725
|
+
* provided, that value as the first yield).
|
|
726
|
+
*
|
|
727
|
+
* @param {{ initial_value?: { value: T } }} [options]
|
|
728
|
+
* `initial_value` lets the caller seed the iterator with a synchronously-
|
|
729
|
+
* available current value before any new pushes arrive (e.g. the
|
|
730
|
+
* "last-seen value" of a reactive resource). Pass it wrapped in an
|
|
731
|
+
* object so `undefined` can be distinguished from "no initial value".
|
|
732
|
+
* @returns {AsyncGenerator<T, void, void>}
|
|
733
|
+
*/
|
|
734
|
+
subscribe(options) {
|
|
735
|
+
/** @type {Subscriber} */
|
|
736
|
+
const subscriber = {
|
|
737
|
+
pending: options?.initial_value ? { value: options.initial_value.value } : null,
|
|
738
|
+
pending_error: this.#closed && this.#terminal_error !== void 0 ? { error: this.#terminal_error } : null,
|
|
739
|
+
finished: this.#closed && this.#terminal_error === void 0,
|
|
740
|
+
waiting_resolve: null,
|
|
741
|
+
waiting_reject: null
|
|
742
|
+
};
|
|
743
|
+
if (!subscriber.finished && subscriber.pending_error === null) this.#subscribers.add(subscriber);
|
|
744
|
+
if (!this.#closed) this.#stop ??= this.#start?.(this);
|
|
745
|
+
const unsubscribe = () => {
|
|
746
|
+
subscriber.finished = true;
|
|
747
|
+
if (this.#subscribers.delete(subscriber) && this.#subscribers.size === 0) this.#stop?.();
|
|
748
|
+
};
|
|
749
|
+
/** @type {AsyncGenerator<T, void, void>} */
|
|
750
|
+
const iterator = {
|
|
751
|
+
next() {
|
|
752
|
+
if (subscriber.pending_error) {
|
|
753
|
+
const { error } = subscriber.pending_error;
|
|
754
|
+
subscriber.pending_error = null;
|
|
755
|
+
unsubscribe();
|
|
756
|
+
return Promise.reject(error);
|
|
757
|
+
}
|
|
758
|
+
if (subscriber.pending) {
|
|
759
|
+
const { value } = subscriber.pending;
|
|
760
|
+
subscriber.pending = null;
|
|
761
|
+
return Promise.resolve({
|
|
762
|
+
value,
|
|
763
|
+
done: false
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
if (subscriber.finished) return Promise.resolve({
|
|
767
|
+
value: void 0,
|
|
768
|
+
done: true
|
|
769
|
+
});
|
|
770
|
+
return new Promise((resolve, reject) => {
|
|
771
|
+
subscriber.waiting_resolve = resolve;
|
|
772
|
+
subscriber.waiting_reject = reject;
|
|
773
|
+
});
|
|
774
|
+
},
|
|
775
|
+
return(value) {
|
|
776
|
+
unsubscribe();
|
|
777
|
+
if (subscriber.waiting_resolve) {
|
|
778
|
+
const resolve = subscriber.waiting_resolve;
|
|
779
|
+
subscriber.waiting_resolve = null;
|
|
780
|
+
subscriber.waiting_reject = null;
|
|
781
|
+
resolve({
|
|
782
|
+
value: void 0,
|
|
783
|
+
done: true
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return Promise.resolve({
|
|
787
|
+
value,
|
|
788
|
+
done: true
|
|
789
|
+
});
|
|
790
|
+
},
|
|
791
|
+
throw(error) {
|
|
792
|
+
unsubscribe();
|
|
793
|
+
if (subscriber.waiting_reject) {
|
|
794
|
+
const reject = subscriber.waiting_reject;
|
|
795
|
+
subscriber.waiting_resolve = null;
|
|
796
|
+
subscriber.waiting_reject = null;
|
|
797
|
+
reject(error);
|
|
798
|
+
}
|
|
799
|
+
return Promise.reject(error);
|
|
800
|
+
},
|
|
801
|
+
[Symbol.asyncIterator]() {
|
|
802
|
+
return iterator;
|
|
803
|
+
},
|
|
804
|
+
async [Symbol.asyncDispose]() {}
|
|
805
|
+
};
|
|
806
|
+
return iterator;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/query.js
|
|
811
|
+
/** @import { RemoteLiveQuery, RemoteLiveQueryFunction, RemoteQuery, RemoteQueryFunction } from '$app/server' */
|
|
812
|
+
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
813
|
+
/** @import { RemoteInternals, MaybePromise, RequestState, RemoteQueryLiveInternals, RemoteQueryBatchInternals, RemoteQueryInternals, RemoteLiveQueryUserFunctionReturnType } from 'types' */
|
|
814
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
815
|
+
/**
|
|
816
|
+
* Creates a remote query. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
817
|
+
*
|
|
818
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
819
|
+
*
|
|
820
|
+
* @template Output
|
|
821
|
+
* @overload
|
|
822
|
+
* @param {() => MaybePromise<Output>} fn
|
|
823
|
+
* @returns {RemoteQueryFunction<void, Output>}
|
|
824
|
+
* @since 2.27
|
|
825
|
+
*/
|
|
826
|
+
/**
|
|
827
|
+
* Creates a remote query. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
828
|
+
*
|
|
829
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
830
|
+
*
|
|
831
|
+
* @template Input
|
|
832
|
+
* @template Output
|
|
833
|
+
* @overload
|
|
834
|
+
* @param {'unchecked'} validate
|
|
835
|
+
* @param {(arg: Input) => MaybePromise<Output>} fn
|
|
836
|
+
* @returns {RemoteQueryFunction<Input, Output>}
|
|
837
|
+
* @since 2.27
|
|
838
|
+
*/
|
|
839
|
+
/**
|
|
840
|
+
* Creates a remote query. When called from the browser, the function will be invoked on the server via a `fetch` call.
|
|
841
|
+
*
|
|
842
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
843
|
+
*
|
|
844
|
+
* @template {StandardSchemaV1} Schema
|
|
845
|
+
* @template Output
|
|
846
|
+
* @overload
|
|
847
|
+
* @param {Schema} schema
|
|
848
|
+
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => MaybePromise<Output>} fn
|
|
849
|
+
* @returns {RemoteQueryFunction<StandardSchemaV1.InferInput<Schema>, Output, StandardSchemaV1.InferOutput<Schema>>}
|
|
850
|
+
* @since 2.27
|
|
851
|
+
*/
|
|
852
|
+
/**
|
|
853
|
+
* @template Input
|
|
854
|
+
* @template Output
|
|
855
|
+
* @param {any} validate_or_fn
|
|
856
|
+
* @param {(args?: Input) => MaybePromise<Output>} [maybe_fn]
|
|
857
|
+
* @returns {RemoteQueryFunction<Input, Output>}
|
|
858
|
+
* @since 2.27
|
|
859
|
+
*/
|
|
860
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
861
|
+
function query(validate_or_fn, maybe_fn) {
|
|
862
|
+
/** @type {(arg?: Input) => Output} */
|
|
863
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
864
|
+
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
865
|
+
const validate = create_validator(validate_or_fn, maybe_fn);
|
|
866
|
+
/** @type {RemoteQueryInternals} */
|
|
867
|
+
const __ = {
|
|
868
|
+
type: "query",
|
|
869
|
+
id: "",
|
|
870
|
+
name: "",
|
|
871
|
+
validate,
|
|
872
|
+
bind(payload, validated_arg) {
|
|
873
|
+
const { event, state } = get_request_store();
|
|
874
|
+
return create_query_resource(__, payload, event, state, () => run_remote_function(event, {
|
|
875
|
+
...state,
|
|
876
|
+
is_in_remote_query: true
|
|
877
|
+
}, false, () => validated_arg, fn));
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
/** @type {RemoteQueryFunction<Input, Output> & { __: RemoteQueryInternals }} */
|
|
881
|
+
const wrapper = (arg) => {
|
|
882
|
+
if (prerendering) remote_query_prerender({
|
|
883
|
+
type: "query",
|
|
884
|
+
name: __.name
|
|
885
|
+
});
|
|
886
|
+
const { event, state } = get_request_store();
|
|
887
|
+
const payload = stringify_remote_arg(arg);
|
|
888
|
+
return create_query_resource(__, payload, event, state, () => run_remote_function(event, {
|
|
889
|
+
...state,
|
|
890
|
+
is_in_remote_query: true
|
|
891
|
+
}, false, () => validate(arg), fn));
|
|
892
|
+
};
|
|
893
|
+
Object.defineProperty(wrapper, "__", { value: __ });
|
|
894
|
+
return wrapper;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Creates a live remote query. When called from the browser, the function will be invoked on the server via a streaming `fetch` call.
|
|
898
|
+
*
|
|
899
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
|
|
900
|
+
*
|
|
901
|
+
* @template Output
|
|
902
|
+
* @overload
|
|
903
|
+
* @param {(arg: void) => RemoteLiveQueryUserFunctionReturnType<Output>} fn
|
|
904
|
+
* @returns {RemoteLiveQueryFunction<void, Output>}
|
|
905
|
+
*/
|
|
906
|
+
/**
|
|
907
|
+
* @template Input
|
|
908
|
+
* @template Output
|
|
909
|
+
* @overload
|
|
910
|
+
* @param {'unchecked'} validate
|
|
911
|
+
* @param {(arg: Input) => RemoteLiveQueryUserFunctionReturnType<Output>} fn
|
|
912
|
+
* @returns {RemoteLiveQueryFunction<Input, Output>}
|
|
913
|
+
*/
|
|
914
|
+
/**
|
|
915
|
+
* @template {StandardSchemaV1} Schema
|
|
916
|
+
* @template Output
|
|
917
|
+
* @overload
|
|
918
|
+
* @param {Schema} schema
|
|
919
|
+
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => RemoteLiveQueryUserFunctionReturnType<Output>} fn
|
|
920
|
+
* @returns {RemoteLiveQueryFunction<StandardSchemaV1.InferInput<Schema>, Output, StandardSchemaV1.InferOutput<Schema>>}
|
|
921
|
+
*/
|
|
922
|
+
/**
|
|
923
|
+
* @template Input
|
|
924
|
+
* @template Output
|
|
925
|
+
* @param {any} validate_or_fn
|
|
926
|
+
* @param {(args: Input) => RemoteLiveQueryUserFunctionReturnType<Output>} [maybe_fn]
|
|
927
|
+
* @returns {RemoteLiveQueryFunction<Input, Output>}
|
|
928
|
+
*/
|
|
929
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
930
|
+
function live(validate_or_fn, maybe_fn) {
|
|
931
|
+
/** @type {(arg: Input) => RemoteLiveQueryUserFunctionReturnType<Output>} */
|
|
932
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
933
|
+
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
934
|
+
const validate = create_validator(validate_or_fn, maybe_fn);
|
|
935
|
+
/**
|
|
936
|
+
* @param {any} event
|
|
937
|
+
* @param {any} state
|
|
938
|
+
* @param {any} get_input
|
|
939
|
+
*/
|
|
940
|
+
const run = (event, state, get_input) => run_remote_generator(event, {
|
|
941
|
+
...state,
|
|
942
|
+
is_in_remote_query: true
|
|
943
|
+
}, false, get_input, fn, __.name);
|
|
944
|
+
/** @type {RemoteQueryLiveInternals} */
|
|
945
|
+
const __ = {
|
|
946
|
+
type: "query_live",
|
|
947
|
+
id: "",
|
|
948
|
+
name: "",
|
|
949
|
+
run: (event, state, arg) => run(event, state, () => validate(arg)),
|
|
950
|
+
validate,
|
|
951
|
+
bind(payload, validated_arg) {
|
|
952
|
+
const { event, state } = get_request_store();
|
|
953
|
+
return create_live_query_resource(__, payload, event, state, () => run(event, state, () => validated_arg));
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
/** @type {RemoteLiveQueryFunction<Input, Output> & { __: RemoteQueryLiveInternals }} */
|
|
957
|
+
const wrapper = (arg) => {
|
|
958
|
+
if (prerendering) remote_query_prerender({
|
|
959
|
+
type: "query.live",
|
|
960
|
+
name: __.name
|
|
961
|
+
});
|
|
962
|
+
const { event, state } = get_request_store();
|
|
963
|
+
const payload = stringify_remote_arg(arg);
|
|
964
|
+
return create_live_query_resource(__, payload, event, state, () => run(event, state, () => validate(arg)));
|
|
965
|
+
};
|
|
966
|
+
Object.defineProperty(wrapper, "__", { value: __ });
|
|
967
|
+
return wrapper;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Creates a batch query function that collects multiple calls and executes them in a single request
|
|
971
|
+
*
|
|
972
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.batch) for full documentation.
|
|
973
|
+
*
|
|
974
|
+
* @template Input
|
|
975
|
+
* @template Output
|
|
976
|
+
* @overload
|
|
977
|
+
* @param {'unchecked'} validate
|
|
978
|
+
* @param {(args: Input[]) => MaybePromise<(arg: Input, idx: number) => Output>} fn
|
|
979
|
+
* @returns {RemoteQueryFunction<Input, Output>}
|
|
980
|
+
* @since 2.35
|
|
981
|
+
*/
|
|
982
|
+
/**
|
|
983
|
+
* Creates a batch query function that collects multiple calls and executes them in a single request
|
|
984
|
+
*
|
|
985
|
+
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.batch) for full documentation.
|
|
986
|
+
*
|
|
987
|
+
* @template {StandardSchemaV1} Schema
|
|
988
|
+
* @template Output
|
|
989
|
+
* @overload
|
|
990
|
+
* @param {Schema} schema
|
|
991
|
+
* @param {(args: StandardSchemaV1.InferOutput<Schema>[]) => MaybePromise<(arg: StandardSchemaV1.InferOutput<Schema>, idx: number) => Output>} fn
|
|
992
|
+
* @returns {RemoteQueryFunction<StandardSchemaV1.InferInput<Schema>, Output, StandardSchemaV1.InferOutput<Schema>>}
|
|
993
|
+
* @since 2.35
|
|
994
|
+
*/
|
|
995
|
+
/**
|
|
996
|
+
* @template Input
|
|
997
|
+
* @template Output
|
|
998
|
+
* @param {any} validate_or_fn
|
|
999
|
+
* @param {(args?: Input[]) => MaybePromise<(arg: Input, idx: number) => Output>} [maybe_fn]
|
|
1000
|
+
* @returns {RemoteQueryFunction<Input, Output>}
|
|
1001
|
+
* @since 2.35
|
|
1002
|
+
*/
|
|
1003
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1004
|
+
function batch(validate_or_fn, maybe_fn) {
|
|
1005
|
+
/** @type {(args?: Input[]) => MaybePromise<(arg: Input, idx: number) => Output>} */
|
|
1006
|
+
const fn = maybe_fn ?? validate_or_fn;
|
|
1007
|
+
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
1008
|
+
const validate = create_validator(validate_or_fn, maybe_fn);
|
|
1009
|
+
/**
|
|
1010
|
+
* Enqueues a single call into the current batch (creating one if necessary)
|
|
1011
|
+
* and returns a promise that resolves with the result for this entry.
|
|
1012
|
+
*
|
|
1013
|
+
* @param {string} payload — the stringified raw argument (cache key)
|
|
1014
|
+
* @param {() => MaybePromise<any>} get_validated — produces the validated argument for this entry
|
|
1015
|
+
* @returns {Promise<any>}
|
|
1016
|
+
*/
|
|
1017
|
+
const enqueue = (payload, get_validated) => {
|
|
1018
|
+
const { event, state } = get_request_store();
|
|
1019
|
+
return new Promise((resolve, reject) => {
|
|
1020
|
+
const batches = state.remote.batches ??= /* @__PURE__ */ new Map();
|
|
1021
|
+
let batched = batches.get(__.id);
|
|
1022
|
+
if (!batched) {
|
|
1023
|
+
batched = /* @__PURE__ */ new Map();
|
|
1024
|
+
batches.set(__.id, batched);
|
|
1025
|
+
}
|
|
1026
|
+
const entry = batched.get(payload);
|
|
1027
|
+
if (entry) {
|
|
1028
|
+
entry.resolvers.push({
|
|
1029
|
+
resolve,
|
|
1030
|
+
reject
|
|
1031
|
+
});
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
batched.set(payload, {
|
|
1035
|
+
get_validated,
|
|
1036
|
+
resolvers: [{
|
|
1037
|
+
resolve,
|
|
1038
|
+
reject
|
|
1039
|
+
}]
|
|
1040
|
+
});
|
|
1041
|
+
if (batched.size > 1) return;
|
|
1042
|
+
setTimeout(async () => {
|
|
1043
|
+
batches.delete(__.id);
|
|
1044
|
+
const entries = Array.from(batched.values());
|
|
1045
|
+
try {
|
|
1046
|
+
return await run_remote_function(event, {
|
|
1047
|
+
...state,
|
|
1048
|
+
is_in_remote_query: true
|
|
1049
|
+
}, false, async () => Promise.all(entries.map((entry) => entry.get_validated())), async (input) => {
|
|
1050
|
+
const get_result = await fn(input);
|
|
1051
|
+
for (let i = 0; i < entries.length; i++) try {
|
|
1052
|
+
const result = get_result(input[i], i);
|
|
1053
|
+
for (const resolver of entries[i].resolvers) resolver.resolve(result);
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
for (const resolver of entries[i].resolvers) resolver.reject(error);
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
for (const entry of batched.values()) for (const resolver of entry.resolvers) resolver.reject(error);
|
|
1060
|
+
}
|
|
1061
|
+
}, 0);
|
|
1062
|
+
});
|
|
1063
|
+
};
|
|
1064
|
+
/** @type {RemoteQueryBatchInternals} */
|
|
1065
|
+
const __ = {
|
|
1066
|
+
type: "query_batch",
|
|
1067
|
+
id: "",
|
|
1068
|
+
name: "",
|
|
1069
|
+
validate,
|
|
1070
|
+
run: async (args) => {
|
|
1071
|
+
const { event, state } = get_request_store();
|
|
1072
|
+
return run_remote_function(event, {
|
|
1073
|
+
...state,
|
|
1074
|
+
is_in_remote_query: true
|
|
1075
|
+
}, false, async () => Promise.all(args.map(validate)), async (input) => {
|
|
1076
|
+
const get_result = await fn(input);
|
|
1077
|
+
return Promise.all(input.map(async (arg, i) => {
|
|
1078
|
+
try {
|
|
1079
|
+
return {
|
|
1080
|
+
type: "result",
|
|
1081
|
+
data: get_result(arg, i)
|
|
1082
|
+
};
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
return {
|
|
1085
|
+
type: "error",
|
|
1086
|
+
error: await handle_error_and_jsonify(event, state, error)
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
}));
|
|
1090
|
+
});
|
|
1091
|
+
},
|
|
1092
|
+
bind(payload, validated_arg) {
|
|
1093
|
+
const { event, state } = get_request_store();
|
|
1094
|
+
return create_query_resource(__, payload, event, state, () => enqueue(payload, () => validated_arg));
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
/** @type {RemoteQueryFunction<Input, Output> & { __: RemoteQueryBatchInternals }} */
|
|
1098
|
+
const wrapper = (arg) => {
|
|
1099
|
+
if (prerendering) remote_query_prerender({
|
|
1100
|
+
type: "query.batch",
|
|
1101
|
+
name: __.name
|
|
1102
|
+
});
|
|
1103
|
+
const { event, state } = get_request_store();
|
|
1104
|
+
const payload = stringify_remote_arg(arg);
|
|
1105
|
+
return create_query_resource(__, payload, event, state, () => enqueue(payload, () => validate(arg)));
|
|
1106
|
+
};
|
|
1107
|
+
Object.defineProperty(wrapper, "__", { value: __ });
|
|
1108
|
+
return wrapper;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Include this value in the returned payload...
|
|
1112
|
+
* @param {RequestEvent} event
|
|
1113
|
+
* @param {RequestState} state
|
|
1114
|
+
* @param {RemoteInternals} internals
|
|
1115
|
+
* @param {string} payload
|
|
1116
|
+
* @param {() => Promise<any>} fn
|
|
1117
|
+
*/
|
|
1118
|
+
function refresh(event, state, internals, payload, fn) {
|
|
1119
|
+
if (!internals.id) return;
|
|
1120
|
+
if (!event.isRemoteRequest && state.is_in_remote_form_or_command) return;
|
|
1121
|
+
const key = create_remote_key(internals.id, payload);
|
|
1122
|
+
(state.remote.explicit ??= /* @__PURE__ */ new Map()).set(key, {
|
|
1123
|
+
internals,
|
|
1124
|
+
fn
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* @param {RemoteInternals} __
|
|
1129
|
+
* @param {string} payload — the stringified raw argument (i.e. the cache key the client will use)
|
|
1130
|
+
* @param {RequestEvent} event
|
|
1131
|
+
* @param {RequestState} state
|
|
1132
|
+
* @param {() => Promise<any>} fn
|
|
1133
|
+
* @returns {RemoteQuery<any>}
|
|
1134
|
+
*/
|
|
1135
|
+
function create_query_resource(__, payload, event, state, fn) {
|
|
1136
|
+
/** @type {Promise<any> | null} */
|
|
1137
|
+
let promise = null;
|
|
1138
|
+
const get_promise = () => {
|
|
1139
|
+
return promise ??= get_response(__, payload, state, fn);
|
|
1140
|
+
};
|
|
1141
|
+
const populate_hydratable = () => {
|
|
1142
|
+
if (__.id && state.is_in_render) get_promise().catch(noop);
|
|
1143
|
+
};
|
|
1144
|
+
return {
|
|
1145
|
+
/** @type {Promise<any>['catch']} */
|
|
1146
|
+
catch(onrejected) {
|
|
1147
|
+
return get_promise().catch(onrejected);
|
|
1148
|
+
},
|
|
1149
|
+
get current() {
|
|
1150
|
+
populate_hydratable();
|
|
1151
|
+
},
|
|
1152
|
+
get error() {
|
|
1153
|
+
populate_hydratable();
|
|
1154
|
+
},
|
|
1155
|
+
/** @type {Promise<any>['finally']} */
|
|
1156
|
+
finally(onfinally) {
|
|
1157
|
+
return get_promise().finally(onfinally);
|
|
1158
|
+
},
|
|
1159
|
+
get loading() {
|
|
1160
|
+
populate_hydratable();
|
|
1161
|
+
return true;
|
|
1162
|
+
},
|
|
1163
|
+
get ready() {
|
|
1164
|
+
populate_hydratable();
|
|
1165
|
+
return false;
|
|
1166
|
+
},
|
|
1167
|
+
refresh() {
|
|
1168
|
+
promise = null;
|
|
1169
|
+
delete get_cache(__, state)[payload];
|
|
1170
|
+
refresh(event, state, __, payload, get_promise);
|
|
1171
|
+
return Promise.resolve();
|
|
1172
|
+
},
|
|
1173
|
+
/** @param {any} value */
|
|
1174
|
+
set(value) {
|
|
1175
|
+
const p = promise = Promise.resolve(value);
|
|
1176
|
+
get_cache(__, state)[payload] = p;
|
|
1177
|
+
refresh(event, state, __, payload, () => p);
|
|
1178
|
+
},
|
|
1179
|
+
/** @type {Promise<any>['then']} */
|
|
1180
|
+
then(onfulfilled, onrejected) {
|
|
1181
|
+
return get_promise().then(onfulfilled, onrejected);
|
|
1182
|
+
},
|
|
1183
|
+
withOverride() {
|
|
1184
|
+
server_api_unavailable({ name: `${__.name}.withOverride()` });
|
|
1185
|
+
},
|
|
1186
|
+
get [Symbol.toStringTag]() {
|
|
1187
|
+
return "QueryResource";
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* @param {RemoteQueryLiveInternals} __
|
|
1193
|
+
* @param {string} payload — the stringified raw argument (i.e. the cache key the client will use)
|
|
1194
|
+
* @param {RequestEvent} event
|
|
1195
|
+
* @param {RequestState} state
|
|
1196
|
+
* @param {() => AsyncGenerator<any, void, void>} get_generator
|
|
1197
|
+
* @returns {RemoteLiveQuery<any>}
|
|
1198
|
+
*/
|
|
1199
|
+
function create_live_query_resource(__, payload, event, state, get_generator) {
|
|
1200
|
+
/** @type {Promise<any> | null} */
|
|
1201
|
+
let promise = null;
|
|
1202
|
+
const get_first_value = async () => {
|
|
1203
|
+
for await (const value of get_generator()) return value;
|
|
1204
|
+
remote_query_live_no_value({ name: __.name });
|
|
1205
|
+
};
|
|
1206
|
+
const get_promise = () => {
|
|
1207
|
+
return promise ??= get_response(__, payload, state, get_first_value);
|
|
1208
|
+
};
|
|
1209
|
+
const populate_hydratable = () => {
|
|
1210
|
+
if (__.id && state.is_in_render) get_promise().catch(noop);
|
|
1211
|
+
};
|
|
1212
|
+
return {
|
|
1213
|
+
/** @type {Promise<any>['catch']} */
|
|
1214
|
+
catch(onrejected) {
|
|
1215
|
+
return get_promise().catch(onrejected);
|
|
1216
|
+
},
|
|
1217
|
+
get current() {
|
|
1218
|
+
populate_hydratable();
|
|
1219
|
+
},
|
|
1220
|
+
get error() {
|
|
1221
|
+
populate_hydratable();
|
|
1222
|
+
},
|
|
1223
|
+
/** @type {Promise<any>['finally']} */
|
|
1224
|
+
finally(onfinally) {
|
|
1225
|
+
return get_promise().finally(onfinally);
|
|
1226
|
+
},
|
|
1227
|
+
get done() {
|
|
1228
|
+
populate_hydratable();
|
|
1229
|
+
return false;
|
|
1230
|
+
},
|
|
1231
|
+
get loading() {
|
|
1232
|
+
populate_hydratable();
|
|
1233
|
+
return true;
|
|
1234
|
+
},
|
|
1235
|
+
get ready() {
|
|
1236
|
+
populate_hydratable();
|
|
1237
|
+
return false;
|
|
1238
|
+
},
|
|
1239
|
+
get connected() {
|
|
1240
|
+
populate_hydratable();
|
|
1241
|
+
return false;
|
|
1242
|
+
},
|
|
1243
|
+
reconnect() {
|
|
1244
|
+
promise = null;
|
|
1245
|
+
delete get_cache(__, state)[payload];
|
|
1246
|
+
refresh(event, state, __, payload, get_promise);
|
|
1247
|
+
return Promise.resolve();
|
|
1248
|
+
},
|
|
1249
|
+
/** @type {Promise<any>['then']} */
|
|
1250
|
+
then(onfulfilled, onrejected) {
|
|
1251
|
+
return get_promise().then(onfulfilled, onrejected);
|
|
1252
|
+
},
|
|
1253
|
+
[Symbol.asyncIterator]() {
|
|
1254
|
+
const key = create_remote_key(__.id, payload);
|
|
1255
|
+
const cache = state.remote.live_iterators ??= /* @__PURE__ */ new Map();
|
|
1256
|
+
let cached = cache.get(key);
|
|
1257
|
+
if (!cached) {
|
|
1258
|
+
cached = create_shared_live_iterator(event.request.signal, get_generator);
|
|
1259
|
+
cache.set(key, cached);
|
|
1260
|
+
}
|
|
1261
|
+
return cached.subscribe();
|
|
1262
|
+
},
|
|
1263
|
+
get [Symbol.toStringTag]() {
|
|
1264
|
+
return "LiveQueryResource";
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Wraps a lazily-created live-query generator so that multiple `for await`
|
|
1270
|
+
* consumers within the same request share one underlying iteration. The first
|
|
1271
|
+
* subscriber starts the generator; values are broadcast to all subscribers
|
|
1272
|
+
* via a `SharedIterator`. When the last subscriber unsubscribes, the generator
|
|
1273
|
+
* is closed via `generator.return(undefined)`.
|
|
1274
|
+
*
|
|
1275
|
+
* If `signal` aborts (typically because the client has disconnected), the
|
|
1276
|
+
* pump is torn down and any in-flight `next()` calls on consumer iterators
|
|
1277
|
+
* resolve with `{ done: true }`, so suspended `for await` loops unwind
|
|
1278
|
+
* cleanly rather than leaking.
|
|
1279
|
+
*
|
|
1280
|
+
* @param {AbortSignal} signal
|
|
1281
|
+
* @param {() => AsyncGenerator<any, void, void>} get_generator
|
|
1282
|
+
*/
|
|
1283
|
+
function create_shared_live_iterator(signal, get_generator) {
|
|
1284
|
+
return new SharedIterator((instance) => {
|
|
1285
|
+
if (signal.aborted) {
|
|
1286
|
+
instance.done();
|
|
1287
|
+
return noop;
|
|
1288
|
+
}
|
|
1289
|
+
const generator = get_generator();
|
|
1290
|
+
let aborted = false;
|
|
1291
|
+
const close = () => {
|
|
1292
|
+
aborted = true;
|
|
1293
|
+
generator.return().catch(noop);
|
|
1294
|
+
};
|
|
1295
|
+
signal.addEventListener("abort", () => (close(), instance.done()), { once: true });
|
|
1296
|
+
(async () => {
|
|
1297
|
+
try {
|
|
1298
|
+
while (true) {
|
|
1299
|
+
const result = await generator.next();
|
|
1300
|
+
if (result.done) {
|
|
1301
|
+
instance.done();
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
instance.push(result.value);
|
|
1305
|
+
}
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
if (!aborted) instance.fail(error);
|
|
1308
|
+
} finally {
|
|
1309
|
+
close();
|
|
1310
|
+
}
|
|
1311
|
+
})();
|
|
1312
|
+
return close;
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
Object.defineProperty(query, "batch", {
|
|
1316
|
+
value: batch,
|
|
1317
|
+
enumerable: true
|
|
1318
|
+
});
|
|
1319
|
+
Object.defineProperty(query, "live", {
|
|
1320
|
+
value: live,
|
|
1321
|
+
enumerable: true
|
|
1322
|
+
});
|
|
1323
|
+
//#endregion
|
|
1324
|
+
//#region node_modules/@sveltejs/kit/src/runtime/app/server/remote/requested.js
|
|
1325
|
+
/** @import { RemoteLiveQuery, RemoteLiveQueryFunction, RemoteQuery, RemoteQueryFunction, RequestedResult, RemoteQueryRequestedResult, RemoteLiveQueryRequestedResult } from '$app/server' */
|
|
1326
|
+
/** @import { MaybePromise, RemoteAnyQueryInternals } from 'types' */
|
|
1327
|
+
/**
|
|
1328
|
+
* Inside a remote `command` or `form` callback, returns an iterable
|
|
1329
|
+
* of `{ arg, query }` entries for the query instances the client asked to refresh, up to
|
|
1330
|
+
* the supplied `limit`. Each `query` is a `RemoteQuery` bound to the original
|
|
1331
|
+
* client-side cache key, so `refresh()` / `set()` propagate correctly even when
|
|
1332
|
+
* the query's schema transforms the input. `arg` is the *validated* argument,
|
|
1333
|
+
* i.e. the value after the schema has run (so `InferOutput<Schema>` for queries
|
|
1334
|
+
* declared with a Standard Schema).
|
|
1335
|
+
*
|
|
1336
|
+
* Arguments that fail validation or exceed `limit` are recorded as failures in
|
|
1337
|
+
* the response to the client.
|
|
1338
|
+
* See [Client-requested refreshes](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations-Client-requested-refreshes)
|
|
1339
|
+
* for usage in a remote `command` or `form`.
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```ts
|
|
1343
|
+
* import { requested } from '$app/server';
|
|
1344
|
+
*
|
|
1345
|
+
* for (const { arg, query } of requested(getPost, 5)) {
|
|
1346
|
+
* // `arg` is the validated argument; `query` is bound to the client's
|
|
1347
|
+
* // cache key. It's safe to throw away this promise -- SvelteKit will
|
|
1348
|
+
* // await it and forward any errors to the client.
|
|
1349
|
+
* void query.refresh();
|
|
1350
|
+
* }
|
|
1351
|
+
* ```
|
|
1352
|
+
*
|
|
1353
|
+
* As a shorthand for the above, you can also call `refreshAll` on the result:
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```ts
|
|
1357
|
+
* import { requested } from '$app/server';
|
|
1358
|
+
*
|
|
1359
|
+
* await requested(getPost, 5).refreshAll();
|
|
1360
|
+
* ```
|
|
1361
|
+
*
|
|
1362
|
+
* Works with `query.batch` as well — refreshes for individual entries are
|
|
1363
|
+
* collected into a single batched call.
|
|
1364
|
+
*
|
|
1365
|
+
* For live queries, the same applies, but with `reconnect` and `reconnectAll`.
|
|
1366
|
+
*
|
|
1367
|
+
* @template Input
|
|
1368
|
+
* @template Output
|
|
1369
|
+
* @template [Validated=Input]
|
|
1370
|
+
* @overload
|
|
1371
|
+
* @param {RemoteQueryFunction<Input, Output, Validated>} query
|
|
1372
|
+
* @param {number} limit
|
|
1373
|
+
* @returns {RemoteQueryRequestedResult<Validated, Output>}
|
|
1374
|
+
*/
|
|
1375
|
+
/**
|
|
1376
|
+
* Inside a remote `command` or `form` callback, returns an iterable
|
|
1377
|
+
* of `{ arg, query }` entries for the live query instances the client asked to reconnect, up to
|
|
1378
|
+
* the supplied `limit`. Each `query` is a `RemoteLiveQuery` bound to the original
|
|
1379
|
+
* client-side cache key, so `reconnect()` propagates correctly even when
|
|
1380
|
+
* the query's schema transforms the input. `arg` is the *validated* argument.
|
|
1381
|
+
*
|
|
1382
|
+
* Arguments that fail validation or exceed `limit` are recorded as failures in
|
|
1383
|
+
* the response to the client.
|
|
1384
|
+
* See [Client-requested refreshes](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations-Client-requested-refreshes)
|
|
1385
|
+
* for usage in a remote `command` or `form`.
|
|
1386
|
+
*
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```ts
|
|
1389
|
+
* import { requested } from '$app/server';
|
|
1390
|
+
*
|
|
1391
|
+
* for (const { query } of requested(getPost, 5)) {
|
|
1392
|
+
* void query.reconnect();
|
|
1393
|
+
* }
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* As a shorthand, you can also call `reconnectAll` on the result:
|
|
1397
|
+
*
|
|
1398
|
+
* @example
|
|
1399
|
+
* ```ts
|
|
1400
|
+
* import { requested } from '$app/server';
|
|
1401
|
+
*
|
|
1402
|
+
* await requested(getPost, 5).reconnectAll();
|
|
1403
|
+
* ```
|
|
1404
|
+
*
|
|
1405
|
+
* @template Input
|
|
1406
|
+
* @template Output
|
|
1407
|
+
* @template [Validated=Input]
|
|
1408
|
+
* @overload
|
|
1409
|
+
* @param {RemoteLiveQueryFunction<Input, Output, Validated>} query
|
|
1410
|
+
* @param {number} limit
|
|
1411
|
+
* @returns {RemoteLiveQueryRequestedResult<Validated, Output>}
|
|
1412
|
+
*/
|
|
1413
|
+
/**
|
|
1414
|
+
* @template Input
|
|
1415
|
+
* @template Output
|
|
1416
|
+
* @template [Validated=Input]
|
|
1417
|
+
* @param {RemoteQueryFunction<Input, Output, Validated> | RemoteLiveQueryFunction<Input, Output, Validated>} query
|
|
1418
|
+
* @param {number} limit
|
|
1419
|
+
* @returns {RequestedResult<Validated, Output>}
|
|
1420
|
+
*/
|
|
1421
|
+
function requested(query, limit) {
|
|
1422
|
+
const { event, state } = get_request_store();
|
|
1423
|
+
const internals = query.__;
|
|
1424
|
+
if (internals?.type !== "query" && internals?.type !== "query_batch" && internals?.type !== "query_live") remote_requested_invalid_query();
|
|
1425
|
+
const __ = internals;
|
|
1426
|
+
const requested = state.remote.requested;
|
|
1427
|
+
const payloads = requested?.get(__.id) ?? /* @__PURE__ */ new Set();
|
|
1428
|
+
const ignored = state.remote.ignored ??= /* @__PURE__ */ new Set();
|
|
1429
|
+
/** @param {string} payload */
|
|
1430
|
+
const consume = (payload) => {
|
|
1431
|
+
payloads.delete(payload);
|
|
1432
|
+
if (payloads.size === 0) requested?.delete(__.id);
|
|
1433
|
+
};
|
|
1434
|
+
/** @param {string} payload */
|
|
1435
|
+
const create_ignore = (payload) => () => {
|
|
1436
|
+
ignored.add(create_remote_key(__.id, payload));
|
|
1437
|
+
};
|
|
1438
|
+
if (!state.is_in_remote_form_or_command) remote_requested_context();
|
|
1439
|
+
const [selected, skipped] = split_limit([...payloads], limit);
|
|
1440
|
+
/**
|
|
1441
|
+
* Registers the failure exactly like `.set()` registers a value: the error record
|
|
1442
|
+
* is serialized to the client (putting the query there into a failed state), and
|
|
1443
|
+
* subsequent server-side calls of the query with the same argument reject with it.
|
|
1444
|
+
* @param {string} payload
|
|
1445
|
+
* @param {unknown} error
|
|
1446
|
+
*/
|
|
1447
|
+
const record_failure = (payload, error) => {
|
|
1448
|
+
const promise = Promise.reject(error);
|
|
1449
|
+
promise.catch(noop);
|
|
1450
|
+
get_cache(__, state)[payload] = promise;
|
|
1451
|
+
refresh(event, state, __, payload, () => promise);
|
|
1452
|
+
};
|
|
1453
|
+
for (const payload of skipped) consume(payload);
|
|
1454
|
+
const result = {
|
|
1455
|
+
*[Symbol.iterator]() {
|
|
1456
|
+
for (const payload of selected) {
|
|
1457
|
+
consume(payload);
|
|
1458
|
+
try {
|
|
1459
|
+
const parsed = parse_remote_arg(payload);
|
|
1460
|
+
const validated = __.validate(parsed);
|
|
1461
|
+
if (is_thenable(validated)) remote_requested_async_validator({
|
|
1462
|
+
name: __.name,
|
|
1463
|
+
limit: String(limit)
|
|
1464
|
+
});
|
|
1465
|
+
yield {
|
|
1466
|
+
arg: validated,
|
|
1467
|
+
query: __.bind(payload, validated),
|
|
1468
|
+
ignore: create_ignore(payload)
|
|
1469
|
+
};
|
|
1470
|
+
} catch (error) {
|
|
1471
|
+
record_failure(payload, error);
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
},
|
|
1476
|
+
async *[Symbol.asyncIterator]() {
|
|
1477
|
+
yield* race_all(selected, async (payload) => {
|
|
1478
|
+
consume(payload);
|
|
1479
|
+
try {
|
|
1480
|
+
const parsed = parse_remote_arg(payload);
|
|
1481
|
+
const validated = await __.validate(parsed);
|
|
1482
|
+
return {
|
|
1483
|
+
arg: validated,
|
|
1484
|
+
query: __.bind(payload, validated),
|
|
1485
|
+
ignore: create_ignore(payload)
|
|
1486
|
+
};
|
|
1487
|
+
} catch (error) {
|
|
1488
|
+
record_failure(payload, error);
|
|
1489
|
+
throw new Error(`Skipping ${__.name}(${payload})`, { cause: error });
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
async refreshAll() {
|
|
1494
|
+
if (__.type === "query_live") remote_requested_wrong_method({
|
|
1495
|
+
method: "refreshAll",
|
|
1496
|
+
type: "live",
|
|
1497
|
+
replacement: "reconnectAll"
|
|
1498
|
+
});
|
|
1499
|
+
for await (const { query } of result) query.refresh();
|
|
1500
|
+
},
|
|
1501
|
+
async reconnectAll() {
|
|
1502
|
+
if (__.type !== "query_live") remote_requested_wrong_method({
|
|
1503
|
+
method: "reconnectAll",
|
|
1504
|
+
type: "regular",
|
|
1505
|
+
replacement: "refreshAll"
|
|
1506
|
+
});
|
|
1507
|
+
for await (const { query } of result) query.reconnect();
|
|
1508
|
+
},
|
|
1509
|
+
async ignoreAll() {
|
|
1510
|
+
for await (const { ignore } of result) ignore();
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
return result;
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* @template T
|
|
1517
|
+
* @param {Array<T>} array
|
|
1518
|
+
* @param {number} limit
|
|
1519
|
+
* @returns {[Array<T>, Array<T>]}
|
|
1520
|
+
*/
|
|
1521
|
+
function split_limit(array, limit) {
|
|
1522
|
+
if (limit === Infinity) return [array, []];
|
|
1523
|
+
if (!Number.isInteger(limit) || limit < 0) remote_requested_invalid_limit();
|
|
1524
|
+
return [array.slice(0, limit), array.slice(limit)];
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* @param {any} value
|
|
1528
|
+
* @returns {value is PromiseLike<any>}
|
|
1529
|
+
*/
|
|
1530
|
+
function is_thenable(value) {
|
|
1531
|
+
return !!value && (typeof value === "object" || typeof value === "function") && "then" in value;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Runs all callbacks immediately and yields resolved values in completion order.
|
|
1535
|
+
* If the promise rejects, it is skipped.
|
|
1536
|
+
*
|
|
1537
|
+
* @template T
|
|
1538
|
+
* @template R
|
|
1539
|
+
* @param {Array<T>} array
|
|
1540
|
+
* @param {(value: T) => MaybePromise<R>} fn
|
|
1541
|
+
* @returns {AsyncIterable<R>}
|
|
1542
|
+
*/
|
|
1543
|
+
async function* race_all(array, fn) {
|
|
1544
|
+
/** @type {Set<Promise<{ promise: Promise<any>, value: Awaited<R> }>>} */
|
|
1545
|
+
const pending = /* @__PURE__ */ new Set();
|
|
1546
|
+
for (const value of array) {
|
|
1547
|
+
/** @type {Promise<{ promise: Promise<any>, value: Awaited<R> }>} */
|
|
1548
|
+
const promise = Promise.resolve(fn(value)).then((result) => ({
|
|
1549
|
+
promise,
|
|
1550
|
+
value: result
|
|
1551
|
+
}));
|
|
1552
|
+
promise.catch(() => pending.delete(promise));
|
|
1553
|
+
pending.add(promise);
|
|
1554
|
+
}
|
|
1555
|
+
while (pending.size > 0) try {
|
|
1556
|
+
const { promise, value } = await Promise.race(pending);
|
|
1557
|
+
pending.delete(promise);
|
|
1558
|
+
yield value;
|
|
1559
|
+
} catch {}
|
|
1560
|
+
}
|
|
1561
|
+
//#endregion
|
|
1562
|
+
export { command, form, prerender, query, requested };
|
|
1563
|
+
|
|
1564
|
+
//# sourceMappingURL=remote-entry.js.map
|