@selvajs/selva 4.21.0-beta.17 → 4.21.0-beta.18

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