svelte-effect-runtime 3.4.11 → 4.0.0

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 (83) hide show
  1. package/.dist/chunks/{client-CsVu54pU.js → client-DcZUV4rR.js} +76 -50
  2. package/.dist/chunks/client-DcZUV4rR.js.map +1 -0
  3. package/.dist/chunks/{vite-WGlbSnso.js → compiler-BBPNyXmQ.js} +84 -110
  4. package/.dist/chunks/compiler-BBPNyXmQ.js.map +1 -0
  5. package/.dist/chunks/{dispatcher-pHH4JcFR.js → dispatcher-DOx8iC6r.js} +2 -2
  6. package/.dist/chunks/{dispatcher-pHH4JcFR.js.map → dispatcher-DOx8iC6r.js.map} +1 -1
  7. package/.dist/chunks/{dispatcher-LtvFKYUp.js → dispatcher-H-Ia0Os4.js} +3 -3
  8. package/.dist/chunks/{dispatcher-LtvFKYUp.js.map → dispatcher-H-Ia0Os4.js.map} +1 -1
  9. package/.dist/chunks/{errors-Dcf0MVbq.js → errors-IJjsUwrE.js} +21 -65
  10. package/.dist/chunks/errors-IJjsUwrE.js.map +1 -0
  11. package/.dist/chunks/live-BXAKre_4.js +104 -0
  12. package/.dist/chunks/live-BXAKre_4.js.map +1 -0
  13. package/.dist/chunks/{remote-client-Bj1pZXgq.js → remote-client-CVI4t66c.js} +2 -2
  14. package/.dist/chunks/remote-client-CVI4t66c.js.map +1 -0
  15. package/.dist/chunks/{runtime-ekkMQ-wL.js → runtime-GBQz32DZ.js} +3 -3
  16. package/.dist/chunks/{runtime-ekkMQ-wL.js.map → runtime-GBQz32DZ.js.map} +1 -1
  17. package/.dist/chunks/schema-D9pct6Y5.js +89 -0
  18. package/.dist/chunks/schema-D9pct6Y5.js.map +1 -0
  19. package/.dist/chunks/server-D1LcDnZE.js +213 -0
  20. package/.dist/chunks/server-D1LcDnZE.js.map +1 -0
  21. package/.dist/chunks/source-scan-C4PsggID.js +341 -0
  22. package/.dist/chunks/source-scan-C4PsggID.js.map +1 -0
  23. package/.dist/chunks/{transform-CtQDGS9c.js → transform-jNUr65K9.js} +237 -239
  24. package/.dist/chunks/transform-jNUr65K9.js.map +1 -0
  25. package/.dist/compiler/source-scan.d.ts +198 -0
  26. package/.dist/{vite.d.ts → compiler.d.ts} +1 -1
  27. package/.dist/{vite.js → compiler.js} +1 -1
  28. package/.dist/dispatcher.js +1 -1
  29. package/.dist/errors.d.ts +15 -45
  30. package/.dist/generators.d.ts +3 -1
  31. package/.dist/internal/generators.js +20 -3
  32. package/.dist/internal/generators.js.map +1 -0
  33. package/.dist/internal/remote-client.js +1 -1
  34. package/.dist/internal/remote-server.js +1 -1
  35. package/.dist/internal/schema.d.ts +67 -0
  36. package/.dist/live.d.ts +123 -0
  37. package/.dist/markup/event-attributes.d.ts +16 -7
  38. package/.dist/markup/promise.js +1 -1
  39. package/.dist/markup/run.js +1 -1
  40. package/.dist/markup/transform/constants.d.ts +1 -0
  41. package/.dist/markup/transform/types.d.ts +1 -0
  42. package/.dist/markup/transform.js +1 -1
  43. package/.dist/markup/value.js +1 -1
  44. package/.dist/mod.d.ts +6 -3
  45. package/.dist/mod.js +5 -4
  46. package/.dist/mod.js.map +1 -1
  47. package/.dist/remote/cause-codec.d.ts +53 -0
  48. package/.dist/remote/client/form-transport.d.ts +4 -1
  49. package/.dist/remote/client/form.d.ts +10 -1
  50. package/.dist/remote/client/index.d.ts +1 -1
  51. package/.dist/remote/client/query.d.ts +6 -16
  52. package/.dist/remote/client/types.d.ts +32 -13
  53. package/.dist/remote/client.d.ts +1 -1
  54. package/.dist/remote/client.js +1 -1
  55. package/.dist/remote/server.d.ts +2 -12
  56. package/.dist/remote/server.js +1 -178
  57. package/.dist/runtime/transform.js +81 -68
  58. package/.dist/runtime/transform.js.map +1 -1
  59. package/.dist/script-transform/imports.d.ts +2 -0
  60. package/.dist/script-transform/types.d.ts +8 -0
  61. package/.dist/server/effects.d.ts +7 -7
  62. package/.dist/server/handler.d.ts +37 -0
  63. package/.dist/server/index.d.ts +4 -1
  64. package/.dist/server/schema.d.ts +2 -26
  65. package/.dist/server/types.d.ts +44 -50
  66. package/.dist/server/wrappers.d.ts +2 -2
  67. package/.dist/server.d.ts +2 -2
  68. package/.dist/server.js +88 -97
  69. package/.dist/server.js.map +1 -1
  70. package/.dist/yieldable.d.ts +41 -0
  71. package/README.md +1 -1
  72. package/package.json +4 -4
  73. package/.dist/chunks/client-CsVu54pU.js.map +0 -1
  74. package/.dist/chunks/descriptors-cOe9uRJz.js +0 -36
  75. package/.dist/chunks/descriptors-cOe9uRJz.js.map +0 -1
  76. package/.dist/chunks/errors-Dcf0MVbq.js.map +0 -1
  77. package/.dist/chunks/event-attributes-gHzP2ycp.js +0 -39
  78. package/.dist/chunks/event-attributes-gHzP2ycp.js.map +0 -1
  79. package/.dist/chunks/remote-client-Bj1pZXgq.js.map +0 -1
  80. package/.dist/chunks/transform-CtQDGS9c.js.map +0 -1
  81. package/.dist/chunks/vite-WGlbSnso.js.map +0 -1
  82. package/.dist/remote/server.js.map +0 -1
  83. /package/.dist/{vite → compiler}/remote-client.d.ts +0 -0
@@ -1,7 +1,8 @@
1
- import { O as UnsupportedRemoteFormResponseError, f as RemoteErrorDecodeError, l as InvalidQueryFactoryError, o as InvalidCommandFactoryError, p as RemoteFormEndpointMissingError, s as InvalidLiveQueryFactoryError, u as InvalidRemoteFormResponseError } from "./errors-Dcf0MVbq.js";
2
- import { n as get_dispatcher } from "./dispatcher-pHH4JcFR.js";
1
+ import { O as UnsupportedRemoteFormResponseError, c as InvalidLiveQueryFactoryError, d as InvalidRemoteFormResponseError, m as RemoteFormEndpointMissingError, p as RemoteErrorDecodeError, s as InvalidCommandFactoryError, u as InvalidQueryFactoryError } from "./errors-IJjsUwrE.js";
2
+ import { n as get_dispatcher } from "./dispatcher-DOx8iC6r.js";
3
+ import { n as make_remote_live_stream } from "./live-BXAKre_4.js";
3
4
  import { create_remote_http_error, create_remote_transport_error, create_remote_validation_error, is_serialized_remote_failure_envelope } from "../remote/shared.js";
4
- import { t as copy_property_descriptors } from "./descriptors-cOe9uRJz.js";
5
+ import { n as normalize_validator, r as copy_property_descriptors, t as is_standard_schema } from "./schema-D9pct6Y5.js";
5
6
  import { Effect, Option, Schema } from "effect";
6
7
  import { isRedirect } from "@sveltejs/kit";
7
8
  import { parse } from "devalue";
@@ -242,7 +243,7 @@ function to_form_data(input) {
242
243
  function append_form_value(form_data, path, value) {
243
244
  if (value === void 0) return;
244
245
  if (Array.isArray(value)) {
245
- for (const item of value) append_form_value(form_data, `${path}[]`, item);
246
+ for (const [index, item] of value.entries()) append_form_value(form_data, `${path}[${index}]`, item);
246
247
  return;
247
248
  }
248
249
  if (value instanceof Blob) {
@@ -295,13 +296,17 @@ const DecodeRemoteFormPayload = Schema.decodeUnknownOption(RemoteFormDecodedPayl
295
296
  * @param input - Form input value.
296
297
  * @param decode_payload - Function to decode successful payloads.
297
298
  * @param remote_base - Base URL for the remote endpoint.
299
+ * @param preflight_schema - Optional schema used to mirror SvelteKit's
300
+ * client-side preflight before posting direct programmatic input.
298
301
  * @returns Decoded form output.
299
302
  */
300
- async function submit_remote_form(form_obj, input, decode_payload, remote_base) {
303
+ async function submit_remote_form(form_obj, input, decode_payload, remote_base, preflight_schema) {
301
304
  const action_id = get_remote_action_id(form_obj);
302
305
  if (!action_id || remote_base.length === 0) throw create_remote_transport_error(new RemoteFormEndpointMissingError());
306
+ await validate_preflight_input(preflight_schema, input);
303
307
  const response = await fetch(to_remote_form_url(remote_base, action_id), {
304
308
  method: "POST",
309
+ headers: get_remote_request_headers(),
305
310
  body: to_form_data(input)
306
311
  });
307
312
  if (!response.ok) throw await decode_response_failure(response);
@@ -329,6 +334,40 @@ function to_remote_form_url(remote_base, action_id) {
329
334
  if (tail.length === 0) return `${normalized_base}/${head}`;
330
335
  return `${normalized_base}/${head}/${encodeURIComponent(tail)}`;
331
336
  }
337
+ function get_remote_request_headers() {
338
+ if (typeof location === "undefined") return {};
339
+ return {
340
+ "x-sveltekit-pathname": location.pathname,
341
+ "x-sveltekit-search": location.search
342
+ };
343
+ }
344
+ async function validate_preflight_input(schema, input) {
345
+ if (!schema) return;
346
+ const validated = await schema["~standard"].validate(input);
347
+ if (!is_record(validated) || !Array.isArray(validated.issues)) return;
348
+ const issues = validated.issues.map(normalize_standard_issue);
349
+ throw create_remote_validation_error(issues, { issues }, 400);
350
+ }
351
+ function normalize_standard_issue(issue) {
352
+ if (!is_record(issue)) return {
353
+ message: String(issue),
354
+ path: []
355
+ };
356
+ return {
357
+ message: typeof issue.message === "string" ? issue.message : "Invalid input",
358
+ path: Array.isArray(issue.path) ? issue.path.flatMap(normalize_path_segment) : []
359
+ };
360
+ }
361
+ function normalize_path_segment(segment) {
362
+ if (typeof segment === "string" || typeof segment === "number") return [segment];
363
+ if (!is_record(segment)) return [];
364
+ const key = segment.key;
365
+ if (typeof key === "string" || typeof key === "number") return [key];
366
+ return [];
367
+ }
368
+ function is_record(value) {
369
+ return typeof value === "object" && value !== null;
370
+ }
332
371
  function decode_form_response(envelope, decode_payload) {
333
372
  const response = decode_remote_form_response_envelope(envelope);
334
373
  if (!response) throw create_remote_transport_error(new InvalidRemoteFormResponseError(envelope), envelope);
@@ -432,15 +471,20 @@ function read_submit_result(event) {
432
471
  * @param native_factory - SvelteKit's native form object.
433
472
  * @param decode_payload - Function to decode the response payload.
434
473
  * @param remote_base - Base URL for SvelteKit's remote endpoint.
474
+ * @param adapter_state - Shared mutable state used to mirror root form
475
+ * preflight schemas across keyed form instances.
476
+ * @param keyed - Whether this adapter wraps a keyed form instance returned by
477
+ * SvelteKit's native `for(...)` helper.
435
478
  * @returns A callable form function whose properties mirror the native form.
436
479
  * @internal
437
480
  */
438
- function create_remote_form_adapter(native_factory, decode_payload, remote_base = "") {
481
+ function create_remote_form_adapter(native_factory, decode_payload, remote_base = "", adapter_state = {}, keyed = false) {
439
482
  const form_obj = native_factory;
483
+ let local_preflight_schema;
440
484
  const submit_effect = (input) => MakeEffectFromPromise(async () => {
441
485
  const can_use_remote_endpoint = remote_base.length > 0 && get_remote_action_id(form_obj) !== void 0;
442
486
  if (has_method(form_obj, "submit") && !can_use_remote_endpoint) return await decode_response_or_value(await form_obj.submit(input), decode_payload);
443
- return await submit_remote_form(form_obj, input, decode_payload, remote_base);
487
+ return await submit_remote_form(form_obj, input, decode_payload, remote_base, local_preflight_schema ?? adapter_state.shared_preflight_schema);
444
488
  });
445
489
  const callable = ((input) => submit_effect(input));
446
490
  copy_property_descriptors(form_obj, callable, /* @__PURE__ */ new Set([
@@ -459,7 +503,7 @@ function create_remote_form_adapter(native_factory, decode_payload, remote_base
459
503
  configurable: true,
460
504
  enumerable: false,
461
505
  value: (options) => MakeEffectFromPromise(async () => {
462
- await form_obj.validate(options);
506
+ await form_obj.validate(normalize_validate_options(form_obj.validate, options));
463
507
  })
464
508
  });
465
509
  if (has_method(form_obj, "enhance")) Object.defineProperty(callable, "enhance", {
@@ -470,18 +514,32 @@ function create_remote_form_adapter(native_factory, decode_payload, remote_base
470
514
  if (has_method(form_obj, "for")) Object.defineProperty(callable, "for", {
471
515
  configurable: true,
472
516
  enumerable: false,
473
- value: (key) => create_remote_form_adapter(form_obj.for(key), decode_payload, remote_base)
517
+ value: (key) => create_remote_form_adapter(form_obj.for(key), decode_payload, remote_base, adapter_state, true)
474
518
  });
475
519
  if (has_method(form_obj, "preflight")) Object.defineProperty(callable, "preflight", {
476
520
  configurable: true,
477
521
  enumerable: false,
478
522
  value: (schema) => {
479
- form_obj.preflight(schema);
523
+ const normalized_schema = normalize_validator(schema);
524
+ if (is_standard_schema(normalized_schema)) {
525
+ local_preflight_schema = normalized_schema;
526
+ if (!keyed) adapter_state.shared_preflight_schema = normalized_schema;
527
+ }
528
+ form_obj.preflight(normalized_schema);
480
529
  return callable;
481
530
  }
482
531
  });
483
532
  return callable;
484
533
  }
534
+ function normalize_validate_options(validate, options) {
535
+ if (!options || !("all" in options) || "includeUntouched" in options) return options;
536
+ const source = Function.prototype.toString.call(validate);
537
+ if (!(source.includes("includeUntouched") && !/\ball\s*=/.test(source))) return options;
538
+ return {
539
+ ...options,
540
+ includeUntouched: options.all
541
+ };
542
+ }
485
543
  //#endregion
486
544
  //#region src/remote/client/query-result.ts
487
545
  /**
@@ -522,14 +580,13 @@ function create_remote_query_adapter(native_factory, decode_payload, _base = "")
522
580
  }
523
581
  /**
524
582
  * Creates a remote live query adapter. The returned function takes input and
525
- * returns an `Effect` that resolves to a live query resource with stream state
526
- * and reconnect controls.
583
+ * returns an Effect Stream whose transport state is exposed through `Live`.
527
584
  *
528
585
  * @example
529
586
  * ```ts
530
587
  * const getTime = create_remote_live_query_adapter(nativeLive, (value) => value);
531
- * const time = yield* getTime();
532
- * const current = time.current;
588
+ * const time = getTime();
589
+ * const first = yield* Stream.runHead(time);
533
590
  * ```
534
591
  *
535
592
  * @since 2.0.0
@@ -537,18 +594,15 @@ function create_remote_query_adapter(native_factory, decode_payload, _base = "")
537
594
  * @param _decode_payload - Deprecated payload decoder retained for parity with
538
595
  * other remote adapters.
539
596
  * @param _base - Deprecated transport base retained for compatibility.
540
- * @returns A function returning an Effect-backed live query resource.
597
+ * @returns A function returning a remote live stream.
541
598
  * @internal
542
599
  */
543
600
  function create_remote_live_query_adapter(native_factory, _decode_payload, _base = "") {
544
601
  const query = typeof native_factory === "function" ? native_factory : void 0;
545
602
  if (!query) throw new InvalidLiveQueryFactoryError();
546
- const wrapped = ((input) => Effect.try({
547
- try: () => {
548
- return make_live_query_resource(query(input));
549
- },
550
- catch: normalize_native_error
551
- }));
603
+ const wrapped = ((input) => {
604
+ return make_remote_live_stream(query(input), normalize_native_error);
605
+ });
552
606
  copy_property_descriptors(native_factory, wrapped);
553
607
  return wrapped;
554
608
  }
@@ -593,35 +647,7 @@ function attach_query_resource(resource, effect) {
593
647
  value: (update) => with_override.call(resource, update)
594
648
  });
595
649
  }
596
- function attach_live_query_resource(resource, effect) {
597
- const methods = is_resource(resource) ? resource : void 0;
598
- const async_iterator = methods?.[Symbol.asyncIterator];
599
- const reconnect = methods?.reconnect;
600
- const keys = ["connected", "done"];
601
- attach_resource_getters(resource, effect);
602
- if (!methods) return;
603
- for (const key of keys) {
604
- if (!(key in methods)) continue;
605
- Object.defineProperty(effect, key, {
606
- configurable: true,
607
- get: () => methods[key]
608
- });
609
- }
610
- if (typeof reconnect === "function") Object.defineProperty(effect, "reconnect", {
611
- configurable: true,
612
- value: () => MakeEffectFromPromise(() => Promise.resolve(reconnect.call(resource)))
613
- });
614
- if (typeof async_iterator === "function") Object.defineProperty(effect, Symbol.asyncIterator, {
615
- configurable: true,
616
- value: () => async_iterator.call(resource)
617
- });
618
- }
619
- function make_live_query_resource(resource) {
620
- const live_resource = {};
621
- attach_live_query_resource(resource, live_resource);
622
- return live_resource;
623
- }
624
650
  //#endregion
625
651
  export { create_remote_command_adapter as i, create_remote_query_adapter as n, create_remote_form_adapter as r, create_remote_live_query_adapter as t };
626
652
 
627
- //# sourceMappingURL=client-CsVu54pU.js.map
653
+ //# sourceMappingURL=client-DcZUV4rR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-DcZUV4rR.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/client/utils.ts","../../../modules/svelte-effect-runtime/src/remote/client/failures.ts","../../../modules/svelte-effect-runtime/src/remote/client/responses.ts","../../../modules/svelte-effect-runtime/src/remote/client/effect.ts","../../../modules/svelte-effect-runtime/src/remote/client/command.ts","../../../modules/svelte-effect-runtime/src/remote/client/form-data.ts","../../../modules/svelte-effect-runtime/src/remote/client/form-transport.ts","../../../modules/svelte-effect-runtime/src/remote/client/form-enhance.ts","../../../modules/svelte-effect-runtime/src/remote/client/form.ts","../../../modules/svelte-effect-runtime/src/remote/client/query-result.ts","../../../modules/svelte-effect-runtime/src/remote/client/query.ts"],"sourcesContent":["export { copy_property_descriptors } from \"$/internal/descriptors.ts\";\nimport type { NativeMethod } from \"./types.ts\";\n\n/**\n * Checks whether a value has a callable method property.\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @param key - Method key to look up.\n * @returns Whether the value has a function at `key`.\n */\nexport function has_method<K extends PropertyKey>(\n\tvalue: unknown,\n\tkey: K,\n): value is Record<K, NativeMethod> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\ttypeof (value as Record<PropertyKey, unknown>)[key] === \"function\"\n\t);\n}\n","import {\n\tcreate_remote_http_error,\n\tcreate_remote_transport_error,\n\tis_serialized_remote_failure_envelope,\n} from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { RemoteErrorDecodeError } from \"$/errors.ts\";\nimport { Option, Schema } from \"effect\";\nimport { parse } from \"devalue\";\n\ntype JsonStringDecode =\n\t| {\n\t\t\treadonly _tag: \"JsonStringDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"JsonStringIgnored\";\n\t };\n\ntype EmbeddedRemoteFailureDecode =\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureIgnored\";\n\t };\n\ntype SerializedRemoteFailureDecode<ErrorType> =\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureDecoded\";\n\t\t\treadonly value: RemoteFailure<ErrorType>;\n\t }\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureInvalid\";\n\t };\n\nconst RemoteErrorMessageEnvelopeSchema = Schema.Struct({\n\tmessage: Schema.String,\n});\n\nconst DecodedRemoteFailureSchema = Schema.Struct({\n\t_tag: Schema.String,\n});\n\nconst DecodeJsonString = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);\nconst is_decoded_remote_failure_value = Schema.is(DecodedRemoteFailureSchema);\nconst is_remote_error_message_envelope = Schema.is(RemoteErrorMessageEnvelopeSchema);\n\n/**\n * Decodes a raw wire value into a remote failure when it uses the runtime\n * failure envelope.\n *\n * @example\n * ```ts\n * const failure = decode_remote_error(body);\n * ```\n *\n * @since 2.0.0\n * @param raw - Raw value received from the network or SvelteKit error body.\n * @param decode - Optional devalue decoder for custom error payloads.\n * @returns The decoded failure/value, or a transport error when decoding fails.\n */\nexport function decode_remote_error<ErrorType = never>(\n\traw: unknown,\n\tdecode?: (encoded: string) => unknown,\n): RemoteFailure<ErrorType> | unknown {\n\tconst embedded = decode_embedded_remote_failure(raw);\n\n\tif (embedded._tag === \"EmbeddedRemoteFailureDecoded\") {\n\t\treturn decode_remote_error<ErrorType>(embedded.value, decode);\n\t}\n\n\tif (is_serialized_remote_failure_envelope(raw)) {\n\t\tconst decoded = decode_serialized_remote_failure<ErrorType>(raw.encoded, decode);\n\n\t\tif (decoded._tag === \"SerializedRemoteFailureInvalid\") {\n\t\t\treturn create_remote_transport_error(new RemoteErrorDecodeError(raw), raw);\n\t\t}\n\n\t\treturn decoded.value;\n\t}\n\n\treturn raw;\n}\n\nfunction decode_embedded_remote_failure(raw: unknown): EmbeddedRemoteFailureDecode {\n\tif (typeof raw === \"string\") {\n\t\treturn decode_embedded_json_remote_failure(raw);\n\t}\n\n\tif (!is_remote_error_message_envelope(raw)) {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn decode_embedded_json_remote_failure(raw.message);\n}\n\nfunction decode_embedded_json_remote_failure(value: string): EmbeddedRemoteFailureDecode {\n\tconst decoded = decode_json_string(value);\n\n\tif (decoded._tag === \"JsonStringIgnored\") {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"EmbeddedRemoteFailureDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_json_string(value: string): JsonStringDecode {\n\tconst decoded = DecodeJsonString(value);\n\n\tif (!Option.isSome(decoded)) {\n\t\treturn { _tag: \"JsonStringIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"JsonStringDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_serialized_remote_failure<ErrorType>(\n\tencoded: string,\n\tdecode: ((encoded: string) => unknown) | undefined,\n): SerializedRemoteFailureDecode<ErrorType> {\n\ttry {\n\t\tconst decoded = decode ? decode(encoded) : parse(encoded);\n\n\t\treturn {\n\t\t\t_tag: \"SerializedRemoteFailureDecoded\",\n\t\t\tvalue: decoded as RemoteFailure<ErrorType>,\n\t\t};\n\t} catch {\n\t\treturn { _tag: \"SerializedRemoteFailureInvalid\" };\n\t}\n}\n\n/**\n * Checks whether a decoded value is a tagged remote failure.\n *\n * @example\n * ```ts\n * if (is_decoded_remote_failure(value)) throw value;\n * ```\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @returns Whether the value carries a `_tag` discriminator.\n */\nexport function is_decoded_remote_failure(value: unknown): value is RemoteFailure<never> {\n\treturn is_decoded_remote_failure_value(value);\n}\n\n/**\n * Normalizes native thrown values into the runtime's remote failure model.\n *\n * @example\n * ```ts\n * const failure = normalize_native_error(error);\n * ```\n *\n * @since 2.0.0\n * @param error - Unknown value thrown by a native remote helper.\n * @returns A typed remote failure.\n */\nexport function normalize_native_error<ErrorType = never>(\n\terror: unknown,\n): RemoteFailure<ErrorType> {\n\tconst body = get_error_body(error);\n\tconst decoded = decode_remote_error<ErrorType>(body);\n\tconst status = get_error_status(error);\n\n\tif (is_decoded_remote_failure(decoded)) {\n\t\treturn decoded;\n\t}\n\n\tif (status !== undefined) {\n\t\treturn create_remote_http_error(status, body, error);\n\t}\n\n\treturn create_remote_transport_error(error);\n}\n\nfunction get_error_status(error: unknown): number | undefined {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tconst status = (error as { status?: unknown }).status;\n\n\treturn typeof status === \"number\" ? status : undefined;\n}\n\nfunction get_error_body(error: unknown): unknown {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tif (\"body\" in error) {\n\t\treturn (error as { body?: unknown }).body;\n\t}\n\n\tif (\"data\" in error) {\n\t\treturn (error as { data?: unknown }).data;\n\t}\n\n\treturn undefined;\n}\n","import { create_remote_http_error } from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\n\nimport { decode_remote_error, is_decoded_remote_failure } from \"./failures.ts\";\n\n/**\n * Decodes a failed fetch response into the runtime failure model.\n *\n * @example\n * ```ts\n * const failure = await decode_response_failure(response);\n * ```\n *\n * @since 2.0.0\n * @param response - Failed fetch response returned by the remote endpoint.\n * @returns Remote failure represented by the response.\n */\nexport async function decode_response_failure<ErrorType = never>(\n\tresponse: Response,\n): Promise<RemoteFailure<ErrorType>> {\n\tconst body = await response.json().catch(() => undefined);\n\tconst decoded = decode_remote_error<ErrorType>(body);\n\n\tif (is_decoded_remote_failure(decoded)) {\n\t\treturn decoded;\n\t}\n\n\treturn create_remote_http_error(response.status, body);\n}\n\n/**\n * Decodes either a raw value or `Response` returned by a native remote helper.\n *\n * @example\n * ```ts\n * const output = await decode_response_or_value(result, decode_payload);\n * ```\n *\n * @since 2.0.0\n * @param value - Native result value or fetch response.\n * @param decode_payload - Function used to decode successful payloads.\n * @returns Decoded successful output.\n */\nexport async function decode_response_or_value<Output, ErrorType = never>(\n\tvalue: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n\tif (value instanceof Response) {\n\t\tif (!value.ok) {\n\t\t\tthrow await decode_response_failure<ErrorType>(value);\n\t\t}\n\n\t\tconst data = await decode_success_response_body(value);\n\n\t\treturn decode_payload(data) as Output;\n\t}\n\n\treturn decode_payload(value) as Output;\n}\n\nasync function decode_success_response_body(response: Response): Promise<unknown> {\n\tif (response.status === 204 || response.status === 205) {\n\t\treturn undefined;\n\t}\n\n\tconst text = await response.text();\n\n\tif (text.length === 0) {\n\t\treturn undefined;\n\t}\n\n\treturn JSON.parse(text);\n}\n","import type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { isRedirect } from \"@sveltejs/kit\";\nimport { Effect } from \"effect\";\n\nimport { is_decoded_remote_failure, normalize_native_error } from \"./failures.ts\";\n\n/**\n * Wraps a promise-producing remote operation in an Effect with failure mapping.\n *\n * @example\n * ```ts\n * const program = make_effect_from_promise(() => native_remote(input));\n * ```\n *\n * @since 2.0.0\n * @param run - Promise-producing operation that invokes a native remote helper.\n * @returns Effect that maps thrown values into remote failures.\n */\nexport function MakeEffectFromPromise<Output, ErrorType = never>(\n\trun: () => Promise<Output>,\n): Effect.Effect<Output, RemoteFailure<ErrorType>> {\n\treturn Effect.tryPromise({\n\t\ttry: run,\n\t\tcatch: (error: unknown) => {\n\t\t\tif (isRedirect(error)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (is_decoded_remote_failure(error)) {\n\t\t\t\treturn error;\n\t\t\t}\n\n\t\t\treturn normalize_native_error<ErrorType>(error);\n\t\t},\n\t}) as Effect.Effect<Output, RemoteFailure<ErrorType>>;\n}\n\n/**\n * Compatibility alias for {@link MakeEffectFromPromise}.\n *\n * @example\n * ```ts\n * const program = make_effect_from_promise(() => native_remote(input));\n * ```\n *\n * @since 2.0.0\n * @param run - Promise-producing operation that invokes a native remote helper.\n * @returns Effect that maps thrown values into remote failures.\n * @internal\n */\nexport const make_effect_from_promise = MakeEffectFromPromise;\n","import { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { InvalidCommandFactoryError } from \"$/errors.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport type { NativeMethod, Pending } from \"./types.ts\";\nimport { MakeEffectFromPromise } from \"./effect.ts\";\nimport type { Effect } from \"effect\";\n\ntype EffectRemoteCommandAdapter<Input, Output, ErrorType = never> = ((\n\tinput: undefined extends Input ? Input | void : Input,\n) => Effect.Effect<Output, RemoteFailure<ErrorType>>) & {\n\treadonly pending: number;\n};\n\n/**\n * Creates a remote command adapter. The adapter preserves the native\n * pending getter and turns each invocation into an Effect.\n *\n * @since 2.0.0\n * @param native_factory - SvelteKit's native command function or a legacy\n * response factory used by tests.\n * @param decode_payload - Function to decode the response payload.\n * @param _base - Deprecated transport base retained for compatibility.\n * @param pending - Optional pending counter for legacy response factories.\n * @returns A function returning an Effect of the response.\n * @internal\n */\nexport function create_remote_command_adapter<Input, Output, ErrorType = never>(\n\tnative_factory: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n\t_base = \"\",\n\tpending?: Pending,\n): EffectRemoteCommandAdapter<Input, Output, ErrorType> {\n\tconst invoke = has_method(native_factory, \"invoke\") ? native_factory.invoke : undefined;\n\n\tif (typeof native_factory !== \"function\" && !invoke) {\n\t\tthrow new InvalidCommandFactoryError();\n\t}\n\n\tconst count = pending ?? { value: 0 };\n\n\tconst adapter = (input: undefined extends Input ? Input | void : Input) =>\n\t\tMakeEffectFromPromise<Output, ErrorType>(async () => {\n\t\t\tcount.value += 1;\n\n\t\t\ttry {\n\t\t\t\tconst result = invoke\n\t\t\t\t\t? await invoke(input)\n\t\t\t\t\t: await (native_factory as NativeMethod)(input);\n\n\t\t\t\treturn await decode_response_or_value<Output, ErrorType>(result, decode_payload);\n\t\t\t} finally {\n\t\t\t\tcount.value -= 1;\n\t\t\t}\n\t\t});\n\n\tcopy_property_descriptors(native_factory, adapter);\n\n\tif (!Object.prototype.hasOwnProperty.call(adapter, \"pending\")) {\n\t\tObject.defineProperty(adapter, \"pending\", {\n\t\t\tget: () => count.value,\n\t\t});\n\t}\n\n\treturn adapter as EffectRemoteCommandAdapter<Input, Output, ErrorType>;\n}\n","/**\n * Encodes remote form input into SvelteKit-compatible form data.\n *\n * @since 2.0.0\n * @param input - Input value supplied to the remote form.\n * @returns FormData payload for the remote endpoint.\n */\nexport function to_form_data(input: unknown): FormData {\n\tconst form_data = new FormData();\n\n\tappend_form_value(form_data, \"\", input);\n\n\treturn form_data;\n}\n\nfunction append_form_value(form_data: FormData, path: string, value: unknown): void {\n\tif (value === undefined) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const [index, item] of value.entries()) {\n\t\t\tappend_form_value(form_data, `${path}[${index}]`, item);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (value instanceof Blob) {\n\t\tform_data.append(path, value);\n\n\t\treturn;\n\t}\n\n\tif (typeof value === \"object\" && value !== null) {\n\t\tfor (const [key, child] of Object.entries(value)) {\n\t\t\tconst child_path = path.length === 0 ? key : `${path}.${key}`;\n\n\t\t\tappend_form_value(form_data, child_path, child);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (typeof value === \"number\") {\n\t\tform_data.append(`n:${path}`, String(value));\n\n\t\treturn;\n\t}\n\n\tif (typeof value === \"boolean\") {\n\t\tif (value) {\n\t\t\tform_data.append(`b:${path}`, \"on\");\n\t\t}\n\n\t\treturn;\n\t}\n\n\tform_data.append(path, value === null ? \"\" : String(value));\n}\n","import {\n\tcreate_remote_http_error,\n\tcreate_remote_transport_error,\n\tcreate_remote_validation_error,\n} from \"$/remote/shared.ts\";\nimport {\n\tInvalidRemoteFormResponseError,\n\tRemoteFormEndpointMissingError,\n\tUnsupportedRemoteFormResponseError,\n} from \"$/errors.ts\";\nimport type { StandardSchema } from \"$/internal/schema.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { Option, Schema } from \"effect\";\nimport { parse } from \"devalue\";\n\nimport { decode_remote_error, is_decoded_remote_failure } from \"./failures.ts\";\nimport { decode_response_failure } from \"./responses.ts\";\nimport { to_form_data } from \"./form-data.ts\";\nimport type { NativeFormRecord } from \"./types.ts\";\n\ntype RemoteFormResponseEnvelope =\n\t| {\n\t\t\treadonly _tag: \"RemoteFormErrorEnvelope\";\n\t\t\treadonly error?: unknown;\n\t\t\treadonly status?: number | undefined;\n\t }\n\t| {\n\t\t\treadonly _tag: \"RemoteFormResultEnvelope\";\n\t\t\treadonly data?: string | undefined;\n\t\t\treadonly result?: string | undefined;\n\t };\n\ntype RemoteFormDecodedPayload<Output> = {\n\treadonly issues?: readonly FormIssue[];\n\treadonly result?: Output;\n};\n\nconst FormIssuePathSegmentSchema = Schema.Union([Schema.String, Schema.Number]);\n\nconst FormIssueSchema = Schema.Struct({\n\tmessage: Schema.String,\n\tpath: Schema.Array(FormIssuePathSegmentSchema),\n});\n\nconst RemoteFormErrorEnvelopeSchema = Schema.Struct({\n\ttype: Schema.Literal(\"error\"),\n\terror: Schema.optional(Schema.Unknown),\n\tstatus: Schema.optional(Schema.Number),\n});\n\nconst RemoteFormResultEnvelopeSchema = Schema.Struct({\n\ttype: Schema.Literal(\"result\"),\n\tdata: Schema.optional(Schema.String),\n\tresult: Schema.optional(Schema.String),\n});\n\nconst RemoteFormResponseEnvelopeSchema = Schema.Union([\n\tRemoteFormErrorEnvelopeSchema,\n\tRemoteFormResultEnvelopeSchema,\n]);\n\nconst RemoteFormDecodedPayloadSchema = Schema.Struct({\n\tissues: Schema.optional(Schema.Array(FormIssueSchema)),\n\tresult: Schema.optional(Schema.Unknown),\n});\n\nconst DecodeRemoteFormResponseEnvelope = Schema.decodeUnknownOption(\n\tRemoteFormResponseEnvelopeSchema,\n);\nconst DecodeRemoteFormPayload = Schema.decodeUnknownOption(RemoteFormDecodedPayloadSchema);\n\n/**\n * Submits a native remote form through the SvelteKit remote endpoint.\n *\n * @since 2.0.0\n * @param form_obj - Native form object being adapted.\n * @param input - Form input value.\n * @param decode_payload - Function to decode successful payloads.\n * @param remote_base - Base URL for the remote endpoint.\n * @param preflight_schema - Optional schema used to mirror SvelteKit's\n * client-side preflight before posting direct programmatic input.\n * @returns Decoded form output.\n */\nexport async function submit_remote_form<Output>(\n\tform_obj: NativeFormRecord,\n\tinput: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n\tremote_base: string,\n\tpreflight_schema?: StandardSchema,\n): Promise<Output> {\n\tconst action_id = get_remote_action_id(form_obj);\n\n\tif (!action_id || remote_base.length === 0) {\n\t\tthrow create_remote_transport_error(new RemoteFormEndpointMissingError());\n\t}\n\n\tawait validate_preflight_input(preflight_schema, input);\n\n\tconst response = await fetch(to_remote_form_url(remote_base, action_id), {\n\t\tmethod: \"POST\",\n\t\theaders: get_remote_request_headers(),\n\t\tbody: to_form_data(input),\n\t});\n\n\tif (!response.ok) {\n\t\tthrow await decode_response_failure(response);\n\t}\n\n\tconst envelope = await response.json();\n\n\treturn decode_form_response<Output>(envelope, decode_payload);\n}\n\n/**\n * Extracts SvelteKit's remote action id from a native form action URL.\n *\n * @since 2.0.0\n * @param form_obj - Native form object being adapted.\n * @returns Remote action id when present.\n */\nexport function get_remote_action_id(form_obj: NativeFormRecord): string | undefined {\n\tconst action = form_obj.action;\n\n\tif (typeof action !== \"string\") {\n\t\treturn undefined;\n\t}\n\n\tconst fallback = \"http://localhost/\";\n\tconst href = typeof location === \"undefined\" ? fallback : location.href;\n\tconst url = new URL(action, href);\n\n\treturn url.searchParams.get(\"/remote\") ?? url.searchParams.get(\"remote\") ?? undefined;\n}\n\nfunction to_remote_form_url(remote_base: string, action_id: string): string {\n\tconst parts = action_id.split(\"/\");\n\tconst head = parts.slice(0, 2).join(\"/\");\n\tconst tail = parts.slice(2).join(\"/\");\n\tconst normalized_base = remote_base.replace(/\\/$/, \"\");\n\n\tif (tail.length === 0) {\n\t\treturn `${normalized_base}/${head}`;\n\t}\n\n\treturn `${normalized_base}/${head}/${encodeURIComponent(tail)}`;\n}\n\nfunction get_remote_request_headers(): HeadersInit {\n\tif (typeof location === \"undefined\") {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t\"x-sveltekit-pathname\": location.pathname,\n\t\t\"x-sveltekit-search\": location.search,\n\t};\n}\n\nasync function validate_preflight_input(\n\tschema: StandardSchema | undefined,\n\tinput: unknown,\n): Promise<void> {\n\tif (!schema) {\n\t\treturn;\n\t}\n\n\tconst validated = await schema[\"~standard\"].validate(input);\n\n\tif (!is_record(validated) || !Array.isArray(validated.issues)) {\n\t\treturn;\n\t}\n\n\tconst issues = validated.issues.map(normalize_standard_issue);\n\n\tthrow create_remote_validation_error(issues, { issues }, 400);\n}\n\nfunction normalize_standard_issue(issue: unknown): FormIssue {\n\tif (!is_record(issue)) {\n\t\treturn { message: String(issue), path: [] };\n\t}\n\n\tconst message = typeof issue.message === \"string\" ? issue.message : \"Invalid input\";\n\tconst path = Array.isArray(issue.path) ? issue.path.flatMap(normalize_path_segment) : [];\n\n\treturn { message, path };\n}\n\nfunction normalize_path_segment(segment: unknown): Array<string | number> {\n\tif (typeof segment === \"string\" || typeof segment === \"number\") {\n\t\treturn [segment];\n\t}\n\n\tif (!is_record(segment)) {\n\t\treturn [];\n\t}\n\n\tconst key = segment.key;\n\n\tif (typeof key === \"string\" || typeof key === \"number\") {\n\t\treturn [key];\n\t}\n\n\treturn [];\n}\n\nfunction is_record(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction decode_form_response<Output>(\n\tenvelope: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n): Output {\n\tconst response = decode_remote_form_response_envelope(envelope);\n\n\tif (!response) {\n\t\tthrow create_remote_transport_error(new InvalidRemoteFormResponseError(envelope), envelope);\n\t}\n\n\tif (response._tag === \"RemoteFormErrorEnvelope\") {\n\t\tconst decoded = decode_remote_error(response.error);\n\n\t\tif (is_decoded_remote_failure(decoded)) {\n\t\t\tthrow decoded;\n\t\t}\n\n\t\tthrow create_remote_http_error(response.status ?? 500, response.error);\n\t}\n\n\tconst result_text = response.result ?? response.data;\n\n\tif (result_text === undefined) {\n\t\tthrow create_remote_transport_error(\n\t\t\tnew UnsupportedRemoteFormResponseError(envelope),\n\t\t\tenvelope,\n\t\t);\n\t}\n\n\tconst parsed = parse(result_text);\n\tconst decoded = decode_remote_form_payload<Output>(decode_payload(parsed));\n\n\tif (!decoded) {\n\t\tthrow create_remote_transport_error(\n\t\t\tnew UnsupportedRemoteFormResponseError(envelope),\n\t\t\tenvelope,\n\t\t);\n\t}\n\n\tif (decoded.issues && decoded.issues.length > 0) {\n\t\tthrow create_remote_validation_error(decoded.issues, decoded, 400);\n\t}\n\n\treturn decoded.result as Output;\n}\n\nfunction decode_remote_form_response_envelope(\n\tenvelope: unknown,\n): RemoteFormResponseEnvelope | undefined {\n\tconst decoded = DecodeRemoteFormResponseEnvelope(envelope);\n\n\tif (!Option.isSome(decoded)) {\n\t\treturn undefined;\n\t}\n\n\tif (decoded.value.type === \"error\") {\n\t\treturn {\n\t\t\t_tag: \"RemoteFormErrorEnvelope\",\n\t\t\terror: decoded.value.error,\n\t\t\tstatus: decoded.value.status,\n\t\t};\n\t}\n\n\treturn {\n\t\t_tag: \"RemoteFormResultEnvelope\",\n\t\tdata: decoded.value.data,\n\t\tresult: decoded.value.result,\n\t};\n}\n\nfunction decode_remote_form_payload<Output>(\n\tpayload: unknown,\n): RemoteFormDecodedPayload<Output> | undefined {\n\tconst decoded = DecodeRemoteFormPayload(payload);\n\n\tif (!Option.isSome(decoded)) {\n\t\treturn undefined;\n\t}\n\n\treturn decoded.value as RemoteFormDecodedPayload<Output>;\n}\n","import { get_dispatcher } from \"$/dispatcher.ts\";\nimport { Effect } from \"effect\";\n\nimport { MakeEffectFromPromise } from \"./effect.ts\";\nimport { has_method } from \"./utils.ts\";\nimport type { EffectRemoteFormSubmit, NativeMethod } from \"./types.ts\";\n\n/**\n * Wraps a remote form enhance callback so Effect return values are run.\n *\n * @since 2.0.0\n * @param callback - Native enhance callback to wrap.\n * @returns Wrapped callback or undefined.\n */\nexport function wrap_enhance_callback<Output, ErrorType = never>(\n\tcallback: NativeMethod | undefined,\n): NativeMethod | undefined {\n\tif (!callback) {\n\t\treturn undefined;\n\t}\n\n\treturn (event: unknown) => {\n\t\tconst wrapped_event = wrap_submit_callback<Output, ErrorType>(event);\n\t\tconst result = callback(wrapped_event);\n\n\t\tif (Effect.isEffect(result)) {\n\t\t\treturn get_dispatcher().run(result);\n\t\t}\n\n\t\treturn result;\n\t};\n}\n\nfunction wrap_submit_callback<Output, ErrorType>(event: unknown): unknown {\n\tif (typeof event !== \"object\" || event === null || !has_method(event, \"submit\")) {\n\t\treturn event;\n\t}\n\n\tconst original_submit = event.submit;\n\tconst { submit: _submit, ...descriptors } = Object.getOwnPropertyDescriptors(event);\n\n\tvoid _submit;\n\n\treturn Object.defineProperties(\n\t\t{},\n\t\t{\n\t\t\t...descriptors,\n\t\t\tsubmit: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: false,\n\t\t\t\tvalue: () => make_submit_effect<Output, ErrorType>(original_submit, event),\n\t\t\t},\n\t\t},\n\t);\n}\n\nfunction make_submit_effect<Output, ErrorType>(\n\toriginal_submit: NativeMethod,\n\tevent: unknown,\n): EffectRemoteFormSubmit<Output, ErrorType> {\n\tlet updates_args: unknown[] | undefined;\n\n\tconst SubmitEffect = MakeEffectFromPromise<Output | undefined, ErrorType>(\n\t\tasync (): Promise<Output | undefined> => {\n\t\t\tconst result = original_submit();\n\t\t\tconst value =\n\t\t\t\tupdates_args && has_method(result, \"updates\")\n\t\t\t\t\t? await Promise.resolve(result.updates(...updates_args))\n\t\t\t\t\t: await Promise.resolve(result);\n\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\treturn read_submit_result<Output>(event);\n\t\t\t}\n\n\t\t\treturn value as Output;\n\t\t},\n\t) as EffectRemoteFormSubmit<Output, ErrorType>;\n\n\tObject.defineProperty(SubmitEffect, \"updates\", {\n\t\tconfigurable: true,\n\t\tenumerable: false,\n\t\tvalue: (...args: unknown[]) => {\n\t\t\tupdates_args ??= args;\n\n\t\t\treturn SubmitEffect;\n\t\t},\n\t});\n\n\treturn SubmitEffect;\n}\n\nfunction read_submit_result<Output>(event: unknown): Output | undefined {\n\tif (typeof event !== \"object\" || event === null || !(\"result\" in event)) {\n\t\treturn undefined;\n\t}\n\n\treturn Reflect.get(event, \"result\") as Output | undefined;\n}\n","import type { RemoteFormInput } from \"@sveltejs/kit\";\n\nimport {\n\tis_standard_schema,\n\tnormalize_validator,\n\ttype StandardSchema,\n} from \"$/internal/schema.ts\";\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { MakeEffectFromPromise } from \"./effect.ts\";\nimport { get_remote_action_id, submit_remote_form } from \"./form-transport.ts\";\nimport { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport { wrap_enhance_callback } from \"./form-enhance.ts\";\nimport type { EffectRemoteForm, NativeFormRecord, NativeMethod } from \"./types.ts\";\n\ntype RemoteInput<Input> = undefined extends Input ? Input | void : Input;\n\ninterface RemoteFormAdapterState {\n\tshared_preflight_schema?: StandardSchema;\n}\n\n/**\n * Creates a remote form adapter. The callable preserves SvelteKit's native\n * form descriptors while wrapping `validate`, `enhance`, and programmatic\n * submission in Effect-returning APIs.\n *\n * @example\n * ```ts\n * const createPost = create_remote_form_adapter(nativeForm, (value) => value);\n * yield* createPost.validate({ includeUntouched: true });\n * ```\n *\n * @since 2.0.0\n * @param native_factory - SvelteKit's native form object.\n * @param decode_payload - Function to decode the response payload.\n * @param remote_base - Base URL for SvelteKit's remote endpoint.\n * @param adapter_state - Shared mutable state used to mirror root form\n * preflight schemas across keyed form instances.\n * @param keyed - Whether this adapter wraps a keyed form instance returned by\n * SvelteKit's native `for(...)` helper.\n * @returns A callable form function whose properties mirror the native form.\n * @internal\n */\nexport function create_remote_form_adapter<\n\tInput extends RemoteFormInput | void,\n\tOutput,\n\tErrorType = never,\n>(\n\tnative_factory: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n\tremote_base = \"\",\n\tadapter_state: RemoteFormAdapterState = {},\n\tkeyed = false,\n): EffectRemoteForm<Input, Output, ErrorType> {\n\tconst form_obj = native_factory as NativeFormRecord;\n\tlet local_preflight_schema: StandardSchema | undefined;\n\n\tconst submit_effect = (input?: RemoteInput<Input>) =>\n\t\tMakeEffectFromPromise<Output, ErrorType>(async () => {\n\t\t\tconst can_use_remote_endpoint =\n\t\t\t\tremote_base.length > 0 && get_remote_action_id(form_obj) !== undefined;\n\n\t\t\tif (has_method(form_obj, \"submit\") && !can_use_remote_endpoint) {\n\t\t\t\tconst result = await form_obj.submit(input);\n\n\t\t\t\treturn await decode_response_or_value<Output>(result, decode_payload);\n\t\t\t}\n\n\t\t\treturn await submit_remote_form<Output>(\n\t\t\t\tform_obj,\n\t\t\t\tinput,\n\t\t\t\tdecode_payload,\n\t\t\t\tremote_base,\n\t\t\t\tlocal_preflight_schema ?? adapter_state.shared_preflight_schema,\n\t\t\t);\n\t\t});\n\n\tconst callable = ((input?: RemoteInput<Input>) => submit_effect(input)) as EffectRemoteForm<\n\t\tInput,\n\t\tOutput,\n\t\tErrorType\n\t>;\n\n\tcopy_property_descriptors(\n\t\tform_obj,\n\t\tcallable,\n\t\tnew Set([\"submit\", \"validate\", \"enhance\", \"for\", \"preflight\"]),\n\t);\n\n\tObject.defineProperty(callable, \"submit\", {\n\t\tconfigurable: true,\n\t\tenumerable: false,\n\t\tvalue: submit_effect,\n\t});\n\n\tif (has_method(form_obj, \"validate\")) {\n\t\tObject.defineProperty(callable, \"validate\", {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: false,\n\t\t\tvalue: (options?: Record<string, unknown>) =>\n\t\t\t\tMakeEffectFromPromise<void, ErrorType>(async () => {\n\t\t\t\t\tawait form_obj.validate(normalize_validate_options(form_obj.validate, options));\n\t\t\t\t}),\n\t\t});\n\t}\n\n\tif (has_method(form_obj, \"enhance\")) {\n\t\tObject.defineProperty(callable, \"enhance\", {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: false,\n\t\t\tvalue: (callback?: NativeMethod) =>\n\t\t\t\tform_obj.enhance(wrap_enhance_callback<Output, ErrorType>(callback)),\n\t\t});\n\t}\n\n\tif (has_method(form_obj, \"for\")) {\n\t\tObject.defineProperty(callable, \"for\", {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: false,\n\t\t\tvalue: (key: string | number | boolean) =>\n\t\t\t\tcreate_remote_form_adapter<Input, Output, ErrorType>(\n\t\t\t\t\tform_obj.for(key),\n\t\t\t\t\tdecode_payload,\n\t\t\t\t\tremote_base,\n\t\t\t\t\tadapter_state,\n\t\t\t\t\ttrue,\n\t\t\t\t),\n\t\t});\n\t}\n\n\tif (has_method(form_obj, \"preflight\")) {\n\t\tObject.defineProperty(callable, \"preflight\", {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: false,\n\t\t\tvalue: (schema: unknown) => {\n\t\t\t\tconst normalized_schema = normalize_validator(schema);\n\n\t\t\t\tif (is_standard_schema(normalized_schema)) {\n\t\t\t\t\tlocal_preflight_schema = normalized_schema;\n\n\t\t\t\t\tif (!keyed) {\n\t\t\t\t\t\tadapter_state.shared_preflight_schema = normalized_schema;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tform_obj.preflight(normalized_schema);\n\n\t\t\t\treturn callable;\n\t\t\t},\n\t\t});\n\t}\n\n\treturn callable;\n}\n\nfunction normalize_validate_options(\n\tvalidate: NativeMethod,\n\toptions: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n\tif (!options || !(\"all\" in options) || \"includeUntouched\" in options) {\n\t\treturn options;\n\t}\n\n\tconst source = Function.prototype.toString.call(validate);\n\tconst uses_stable_option =\n\t\tsource.includes(\"includeUntouched\") && !/\\ball\\s*=/.test(source);\n\n\tif (!uses_stable_option) {\n\t\treturn options;\n\t}\n\n\treturn {\n\t\t...options,\n\t\tincludeUntouched: options.all,\n\t};\n}\n","import { decode_response_or_value } from \"./responses.ts\";\nimport { has_method } from \"./utils.ts\";\n\n/**\n * Resolves native query results, including SvelteKit run handles.\n *\n * @example\n * ```ts\n * const output = await resolve_query_result(result, decode_payload);\n * ```\n *\n * @since 2.0.0\n * @param value - Native query result or query run handle.\n * @param decode_payload - Function used to decode successful payloads.\n * @returns Decoded query output.\n */\nexport async function resolve_query_result<Output>(\n\tvalue: unknown,\n\tdecode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n\tif (has_method(value, \"then\")) {\n\t\tconst result = await Promise.resolve(value);\n\n\t\treturn decode_response_or_value(result, decode_payload);\n\t}\n\n\tif (has_method(value, \"run\")) {\n\t\tconst result = await value.run();\n\n\t\treturn decode_response_or_value(result, decode_payload);\n\t}\n\n\tconst result = await Promise.resolve(value);\n\n\treturn decode_response_or_value(result, decode_payload);\n}\n","import { InvalidLiveQueryFactoryError, InvalidQueryFactoryError } from \"$/errors.ts\";\nimport { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport { normalize_native_error } from \"./failures.ts\";\nimport { resolve_query_result } from \"./query-result.ts\";\nimport { MakeEffectFromPromise } from \"./effect.ts\";\nimport type { EffectRemoteQueryUpdateBrand, NativeMethod } from \"./types.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { make_remote_live_stream, type RemoteLiveStream } from \"$/live.ts\";\nimport { Effect } from \"effect\";\n\ntype RemoteInput<Input> = undefined extends Input ? Input | void : Input;\n\ntype DecodePayload<Output> = (value: unknown) => Output;\n\ntype NativeQueryFactory<Input> =\n\t| ((input: RemoteInput<Input>) => unknown)\n\t| {\n\t\t\treadonly load: (input: RemoteInput<Input>) => unknown;\n\t };\n\ntype RemoteResourceEffect<Output, ErrorType = never> = Effect.Effect<\n\tOutput,\n\tRemoteFailure<ErrorType>\n> & {\n\treadonly current: Output | undefined;\n\treadonly error: unknown;\n\treadonly loading: boolean;\n\treadonly ready: boolean;\n};\n\ntype RemoteResourceLike<Output, ErrorType = never> = RemoteResourceEffect<Output, ErrorType>;\n\ntype RemoteQueryEffect<Output, ErrorType = never> = RemoteResourceEffect<Output, ErrorType> & {\n\treadonly refresh: () => Effect.Effect<void, unknown, never>;\n\treadonly set: (value: Output) => void;\n\treadonly withOverride: (update: (current: Output) => Output) => unknown;\n};\n\ntype NativeRemoteResource<Output> = {\n\treadonly current?: Output;\n\treadonly error?: unknown;\n\treadonly loading?: boolean;\n\treadonly ready?: boolean;\n\treadonly refresh?: () => Promise<void>;\n\treadonly set?: (value: Output) => void;\n\treadonly withOverride?: (update: (current: Output) => Output) => unknown;\n};\n\n/**\n * Creates a remote query adapter. The returned function takes input and\n * returns an `Effect` that executes SvelteKit's native query function.\n *\n * @example\n * ```ts\n * const getUser = create_remote_query_adapter(nativeQuery, (value) => value);\n * const user = yield* getUser({ id: 1 });\n * ```\n *\n * @since 2.0.0\n * @param native_factory - SvelteKit's native query function or a legacy\n * response factory used by tests.\n * @param decode_payload - Function to decode the response payload.\n * @param _base - Deprecated transport base retained for compatibility.\n * @returns A function returning an Effect of the response.\n * @internal\n */\nexport function create_remote_query_adapter<Input, Output, ErrorType = never>(\n\tnative_factory: NativeQueryFactory<Input>,\n\tdecode_payload: DecodePayload<Output>,\n\t_base?: string,\n): EffectRemoteQueryUpdateBrand &\n\t((input: RemoteInput<Input>) => RemoteQueryEffect<Output, ErrorType>);\nexport function create_remote_query_adapter<Input, Output, ErrorType = never>(\n\tnative_factory: NativeQueryFactory<Input>,\n\tdecode_payload: (value: unknown) => unknown,\n\t_base?: string,\n): EffectRemoteQueryUpdateBrand &\n\t((input: RemoteInput<Input>) => RemoteQueryEffect<Output, ErrorType>);\nexport function create_remote_query_adapter<Input, Output, ErrorType = never>(\n\tnative_factory: unknown,\n\tdecode_payload: DecodePayload<Output>,\n\t_base = \"\",\n): EffectRemoteQueryUpdateBrand &\n\t((input: RemoteInput<Input>) => RemoteQueryEffect<Output, ErrorType>) {\n\tconst load = has_method(native_factory, \"load\") ? native_factory.load : undefined;\n\tconst query =\n\t\ttypeof native_factory === \"function\" ? (native_factory as NativeMethod) : undefined;\n\n\tif (!query && !load) {\n\t\tthrow new InvalidQueryFactoryError();\n\t}\n\n\tconst wrapped = ((input: RemoteInput<Input>) => {\n\t\tif (!query) {\n\t\t\treturn MakeEffectFromPromise<Output, ErrorType>(async () => {\n\t\t\t\tconst result = await load?.(input);\n\n\t\t\t\treturn await resolve_query_result<Output>(result, decode_payload);\n\t\t\t}) as RemoteQueryEffect<Output, ErrorType>;\n\t\t}\n\n\t\tconst resource = query(input);\n\t\tconst QueryEffect = MakeEffectFromPromise<Output, ErrorType>(\n\t\t\tasync () => await resolve_query_result<Output>(resource, decode_payload),\n\t\t) as RemoteQueryEffect<Output, ErrorType>;\n\n\t\tattach_query_resource(resource, QueryEffect);\n\n\t\treturn QueryEffect;\n\t}) as EffectRemoteQueryUpdateBrand &\n\t\t((input: RemoteInput<Input>) => RemoteQueryEffect<Output, ErrorType>);\n\n\tcopy_property_descriptors(native_factory, wrapped);\n\n\treturn wrapped;\n}\n\n/**\n * Creates a remote live query adapter. The returned function takes input and\n * returns an Effect Stream whose transport state is exposed through `Live`.\n *\n * @example\n * ```ts\n * const getTime = create_remote_live_query_adapter(nativeLive, (value) => value);\n * const time = getTime();\n * const first = yield* Stream.runHead(time);\n * ```\n *\n * @since 2.0.0\n * @param native_factory - SvelteKit's native live query function.\n * @param _decode_payload - Deprecated payload decoder retained for parity with\n * other remote adapters.\n * @param _base - Deprecated transport base retained for compatibility.\n * @returns A function returning a remote live stream.\n * @internal\n */\nexport function create_remote_live_query_adapter<Input, Output, ErrorType = never>(\n\tnative_factory: unknown,\n\t_decode_payload: (value: unknown) => unknown,\n\t_base = \"\",\n): EffectRemoteQueryUpdateBrand &\n\t((input: RemoteInput<Input>) => RemoteLiveStream<Output, ErrorType>) {\n\tconst query =\n\t\ttypeof native_factory === \"function\" ? (native_factory as NativeMethod) : undefined;\n\n\tif (!query) {\n\t\tthrow new InvalidLiveQueryFactoryError();\n\t}\n\n\tconst wrapped = ((input: Input) => {\n\t\tconst resource = query(input);\n\n\t\treturn make_remote_live_stream<Output, ErrorType>(resource, normalize_native_error);\n\t}) as EffectRemoteQueryUpdateBrand &\n\t\t((input: RemoteInput<Input>) => RemoteLiveStream<Output, ErrorType>);\n\n\tcopy_property_descriptors(native_factory, wrapped);\n\n\treturn wrapped;\n}\n\nfunction is_resource<Output>(resource: unknown): resource is NativeRemoteResource<Output> {\n\tconst resource_type = typeof resource;\n\n\treturn (resource_type === \"object\" && resource !== null) || resource_type === \"function\";\n}\n\nfunction attach_resource_getters<Output, ErrorType = never>(\n\tresource: unknown,\n\teffect: RemoteResourceLike<Output, ErrorType>,\n): void {\n\tconst methods = is_resource<Output>(resource) ? resource : undefined;\n\tconst keys = [\"current\", \"error\", \"loading\", \"ready\"] as const;\n\n\tif (!methods) {\n\t\treturn;\n\t}\n\n\tfor (const key of keys) {\n\t\tif (!(key in methods)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(effect, key, {\n\t\t\tconfigurable: true,\n\t\t\tget: () => methods[key],\n\t\t});\n\t}\n}\n\nfunction attach_query_resource<Output, ErrorType = never>(\n\tresource: unknown,\n\teffect: RemoteQueryEffect<Output, ErrorType>,\n): void {\n\tconst methods = is_resource<Output>(resource) ? resource : undefined;\n\tconst refresh = methods?.refresh;\n\tconst set = methods?.set;\n\tconst with_override = methods?.withOverride;\n\n\tattach_resource_getters(resource, effect);\n\n\tif (!methods) {\n\t\treturn;\n\t}\n\n\tif (typeof refresh === \"function\") {\n\t\tObject.defineProperty(effect, \"refresh\", {\n\t\t\tconfigurable: true,\n\t\t\tvalue: () => MakeEffectFromPromise(() => Promise.resolve(refresh.call(resource))),\n\t\t});\n\t}\n\n\tif (typeof set === \"function\") {\n\t\tObject.defineProperty(effect, \"set\", {\n\t\t\tconfigurable: true,\n\t\t\tvalue: (value: Output) => set.call(resource, value),\n\t\t});\n\t}\n\n\tif (typeof with_override === \"function\") {\n\t\tObject.defineProperty(effect, \"withOverride\", {\n\t\t\tconfigurable: true,\n\t\t\tvalue: (update: (current: Output) => Output) => with_override.call(resource, update),\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAWA,SAAgB,WACf,OACA,KACmC;CACnC,OACC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAuC,SAAS;AAE1D;;;ACiBA,MAAM,mCAAmC,OAAO,OAAO,EACtD,SAAS,OAAO,OACjB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO,EAChD,MAAM,OAAO,OACd,CAAC;AAED,MAAM,mBAAmB,OAAO,oBAAoB,OAAO,qBAAqB;AAChF,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,gCAAgC;;;;;;;;;;;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,KAAK;GAClC,cAAc;GACd,WAAW,QAAQ;EACpB,CAAC;CACF;AACD;AAEA,SAAS,sBACR,UACA,QACO;CACP,MAAM,UAAU,YAAoB,QAAQ,IAAI,WAAW,KAAA;CAC3D,MAAM,UAAU,SAAS;CACzB,MAAM,MAAM,SAAS;CACrB,MAAM,gBAAgB,SAAS;CAE/B,wBAAwB,UAAU,MAAM;CAExC,IAAI,CAAC,SACJ;CAGD,IAAI,OAAO,YAAY,YACtB,OAAO,eAAe,QAAQ,WAAW;EACxC,cAAc;EACd,aAAa,4BAA4B,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,CAAC,CAAC;CACjF,CAAC;CAGF,IAAI,OAAO,QAAQ,YAClB,OAAO,eAAe,QAAQ,OAAO;EACpC,cAAc;EACd,QAAQ,UAAkB,IAAI,KAAK,UAAU,KAAK;CACnD,CAAC;CAGF,IAAI,OAAO,kBAAkB,YAC5B,OAAO,eAAe,QAAQ,gBAAgB;EAC7C,cAAc;EACd,QAAQ,WAAwC,cAAc,KAAK,UAAU,MAAM;CACpF,CAAC;AAEH"}
@@ -1,4 +1,4 @@
1
- import { t as is_event_attribute_name } from "./event-attributes-gHzP2ycp.js";
1
+ import { t as scan_svelte_effect_source } from "./source-scan-C4PsggID.js";
2
2
  //#region src/diagnostics.ts
3
3
  /**
4
4
  * Finds best-effort SER usage diagnostics in Svelte component markup.
@@ -17,21 +17,20 @@ import { t as is_event_attribute_name } from "./event-attributes-gHzP2ycp.js";
17
17
  * @returns Warning diagnostics with a message and source location.
18
18
  */
19
19
  function find_svelte_effect_diagnostics(code, filename) {
20
- const effect_names = find_effect_local_names(code);
21
- return find_markup_expressions(code).flatMap((expression) => make_expression_diagnostics(code, filename, effect_names, expression));
20
+ const scan = scan_svelte_effect_source(code, filename);
21
+ const effect_names = find_effect_local_names(scan.scripts);
22
+ const line_starts = make_line_starts(code);
23
+ return scan.markup_expressions.flatMap((expression) => make_expression_diagnostics(filename, effect_names, expression, line_starts));
22
24
  }
23
- function find_effect_local_names(code) {
25
+ function find_effect_local_names(scripts) {
24
26
  const names = /* @__PURE__ */ new Set(["Effect"]);
25
- for (const script_match of code.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)) {
26
- const script = script_match[1];
27
- for (const import_match of script.matchAll(/import\s+(type\s+)?\{([^}]+)\}\s+from\s+["']effect["']/g)) {
28
- const is_type_only_import = import_match[1] !== void 0;
29
- const specifiers = import_match[2].split(",");
30
- if (is_type_only_import) continue;
31
- for (const specifier of specifiers) {
32
- const local_name = parse_effect_import_local_name(specifier);
33
- if (local_name) names.add(local_name);
34
- }
27
+ for (const script of scripts) for (const import_match of script.text.matchAll(/import\s+(type\s+)?\{([^}]+)\}\s+from\s+["']effect["']/g)) {
28
+ const is_type_only_import = import_match[1] !== void 0;
29
+ const specifiers = import_match[2].split(",");
30
+ if (is_type_only_import) continue;
31
+ for (const specifier of specifiers) {
32
+ const local_name = parse_effect_import_local_name(specifier);
33
+ if (local_name) names.add(local_name);
35
34
  }
36
35
  }
37
36
  return names;
@@ -41,39 +40,15 @@ function parse_effect_import_local_name(specifier) {
41
40
  if (!match) return;
42
41
  return match[1] ?? "Effect";
43
42
  }
44
- function find_markup_expressions(code) {
45
- const expressions = [];
46
- let cursor = 0;
47
- while (cursor < code.length) {
48
- const open = code.indexOf("{", cursor);
49
- if (open === -1) break;
50
- if (is_inside_svelte_excluded_block(code, open)) {
51
- cursor = open + 1;
52
- continue;
53
- }
54
- const close = find_closing_brace(code, open + 1);
55
- if (close === -1) {
56
- cursor = open + 1;
57
- continue;
58
- }
59
- expressions.push({
60
- start: open,
61
- end: close,
62
- expression_text: code.slice(open + 1, close).trim(),
63
- attribute_name: find_attribute_name_before_expression(code, open)
64
- });
65
- cursor = close + 1;
66
- }
67
- return expressions;
68
- }
69
- function make_expression_diagnostics(code, filename, effect_names, expression) {
43
+ function make_expression_diagnostics(filename, effect_names, expression, line_starts) {
70
44
  const attribute_name = expression.attribute_name;
71
45
  const expression_text = expression.expression_text;
72
- const is_event_attribute = attribute_name !== void 0 && is_event_attribute_name(attribute_name);
46
+ /** The source scanner exposes a name only for a direct single-expression value. */
47
+ const is_event_attribute = attribute_name !== void 0 && attribute_name.startsWith("on");
73
48
  const is_attribute = attribute_name !== void 0;
74
- const loc = get_line_column(code, expression.start);
75
49
  if (!contains_effect_reference(expression_text, effect_names)) return [];
76
50
  if (starts_with_yield_star(expression_text)) return [];
51
+ const loc = get_line_column(line_starts, expression.open);
77
52
  if (is_event_attribute && is_callback_expression(expression_text) && contains_yield_star(expression_text)) return [make_diagnostic(loc, make_hidden_event_yield_warning(filename, attribute_name, expression_text))];
78
53
  if (contains_effect_runner(expression_text, effect_names)) return [make_diagnostic(loc, make_explicit_runner_warning(filename, attribute_name, expression_text))];
79
54
  if (is_bare_effect_gen(expression_text, effect_names)) return [make_diagnostic(loc, make_bare_effect_gen_warning(filename, attribute_name, expression_text))];
@@ -173,77 +148,33 @@ function contains_yield_star(expression_text) {
173
148
  function is_callback_expression(expression_text) {
174
149
  return /^(?:async\s+)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>/.test(expression_text) || /^(?:async\s+)?function\b/.test(expression_text);
175
150
  }
176
- function find_attribute_name_before_expression(code, open) {
177
- const tag_start = code.lastIndexOf("<", open);
178
- const last_tag_end = code.lastIndexOf(">", open);
179
- if (tag_start === -1 || tag_start < last_tag_end) return;
180
- return code.slice(tag_start + 1, open).match(/(?:^|\s)([A-Za-z_$:][\w$:-]*)\s*=\s*$/)?.[1];
181
- }
182
- function is_inside_svelte_excluded_block(code, pos) {
183
- const script = find_svelte_tag_range(code, "script", pos);
184
- const style = find_svelte_tag_range(code, "style", pos);
185
- return script !== void 0 && pos < script.end && pos > script.start || style !== void 0 && pos < style.end && pos > style.start;
186
- }
187
- function find_svelte_tag_range(code, tag, after_pos) {
188
- const pattern = new RegExp(`<${tag}\\b[^>]*>([\\s\\S]*?)<\\/${tag}\\s*>`, "gi");
189
- for (const match of code.matchAll(pattern)) {
190
- if (match.index === void 0) continue;
191
- const end = match.index + match[0].length;
192
- if (match.index <= after_pos && after_pos < end) return {
193
- start: match.index,
194
- end
195
- };
196
- }
197
- }
198
- function find_closing_brace(code, start) {
199
- let depth = 0;
200
- for (let i = start; i < code.length; i += 1) {
201
- const ch = code[i];
202
- if (ch === "{" && code[i - 1] !== "$") depth += 1;
203
- else if (ch === "}") {
204
- if (depth === 0) return i;
205
- depth -= 1;
206
- } else if (ch === "'" || ch === "\"" || ch === "`") {
207
- i = skip_string(code, i, ch);
208
- if (i === -1) return -1;
209
- } else if (ch === "/" && code[i + 1] === "/") i = skip_line_comment(code, i);
210
- else if (ch === "/" && code[i + 1] === "*") {
211
- i = skip_block_comment(code, i);
212
- if (i === -1) return -1;
213
- }
214
- }
215
- return -1;
216
- }
217
- function skip_string(code, start, quote) {
218
- for (let i = start + 1; i < code.length; i += 1) {
219
- if (code[i] === "\\") {
220
- i += 1;
221
- continue;
222
- }
223
- if (code[i] === quote) return i;
151
+ function get_line_column(line_starts, position) {
152
+ let low = 0;
153
+ let high = line_starts.length - 1;
154
+ while (low <= high) {
155
+ const mid = Math.floor((low + high) / 2);
156
+ if (line_starts[mid] <= position) low = mid + 1;
157
+ else high = mid - 1;
224
158
  }
225
- return -1;
226
- }
227
- function skip_line_comment(code, start) {
228
- for (let i = start + 2; i < code.length; i += 1) if (code[i] === "\n") return i;
229
- return code.length;
230
- }
231
- function skip_block_comment(code, start) {
232
- for (let i = start + 2; i < code.length; i += 1) if (code[i] === "*" && code[i + 1] === "/") return i + 1;
233
- return -1;
234
- }
235
- function get_line_column(code, position) {
236
- const lines = code.slice(0, position).split("\n");
159
+ const line_index = Math.max(0, high);
237
160
  return {
238
- line: lines.length,
239
- column: lines.at(-1)?.length ?? 0
161
+ line: line_index + 1,
162
+ column: position - line_starts[line_index]
240
163
  };
241
164
  }
165
+ function make_line_starts(code) {
166
+ const line_starts = [0];
167
+ for (let i = 0; i < code.length; i += 1) {
168
+ if (code[i] !== "\n") continue;
169
+ line_starts.push(i + 1);
170
+ }
171
+ return line_starts;
172
+ }
242
173
  function escape_regexp(value) {
243
174
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
244
175
  }
245
176
  //#endregion
246
- //#region src/vite.ts
177
+ //#region src/compiler.ts
247
178
  const default_svelte_component_extensions = [".svelte"];
248
179
  /**
249
180
  * Vite plugin for SvelteKit. The server import plugin rewrites server-side
@@ -252,7 +183,7 @@ const default_svelte_component_extensions = [".svelte"];
252
183
  *
253
184
  * @example
254
185
  * ```ts
255
- * import { effect } from "svelte-effect-runtime/vite";
186
+ * import { effect } from "svelte-effect-runtime/compiler";
256
187
  * import { sveltekit } from "@sveltejs/kit/vite";
257
188
  *
258
189
  * export default defineConfig({ plugins: [effect(), sveltekit()] });
@@ -391,9 +322,10 @@ function make_server_rewrite_plugin() {
391
322
  config() {
392
323
  return { optimizeDeps: { exclude: ["svelte-effect-runtime"] } };
393
324
  },
394
- transform(code, id) {
325
+ async transform(code, id) {
395
326
  if (!is_server_runtime_module(id)) return;
396
- const rewritten = code.replace(/from\s+["']svelte-effect-runtime["']/g, `from "svelte-effect-runtime/server"`).replace(/from\s+["']svelte-effect-runtime\/internal\/generators["']/g, `from "svelte-effect-runtime/server"`);
327
+ if (!code.includes("svelte-effect-runtime")) return;
328
+ const rewritten = await rewrite_server_imports(code, id);
397
329
  if (rewritten === code) return;
398
330
  return {
399
331
  code: rewritten,
@@ -402,6 +334,48 @@ function make_server_rewrite_plugin() {
402
334
  }
403
335
  };
404
336
  }
337
+ async function rewrite_server_imports(code, id) {
338
+ const [{ default: MagicString }, ts] = await Promise.all([import("magic-string"), import("typescript")]);
339
+ const filename = id.split("?", 2)[0] ?? id;
340
+ const source_file = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, get_script_kind(filename, ts));
341
+ const magic = new MagicString(code);
342
+ let changed = false;
343
+ const rewrite_specifier = (specifier) => {
344
+ const replacement = get_server_import_replacement(specifier.text);
345
+ if (!replacement) return;
346
+ magic.overwrite(specifier.getStart(source_file), specifier.end, JSON.stringify(replacement));
347
+ changed = true;
348
+ };
349
+ const visit = (node) => {
350
+ if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) rewrite_specifier(node.moduleSpecifier);
351
+ if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) rewrite_specifier(node.moduleSpecifier);
352
+ if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
353
+ const [specifier] = node.arguments;
354
+ if (specifier && ts.isStringLiteralLike(specifier)) rewrite_specifier(specifier);
355
+ }
356
+ ts.forEachChild(node, visit);
357
+ };
358
+ visit(source_file);
359
+ return changed ? magic.toString() : code;
360
+ }
361
+ function get_server_import_replacement(specifier) {
362
+ if (specifier === "svelte-effect-runtime") return "svelte-effect-runtime/server";
363
+ if (specifier === "svelte-effect-runtime/internal/generators") return "svelte-effect-runtime/server";
364
+ }
365
+ function get_script_kind(filename, ts) {
366
+ const normalized_filename = filename.toLowerCase();
367
+ if (has_file_extension(normalized_filename, [".tsx"])) return ts.ScriptKind.TSX;
368
+ if (has_file_extension(normalized_filename, [".jsx"])) return ts.ScriptKind.JSX;
369
+ if (has_file_extension(normalized_filename, [
370
+ ".js",
371
+ ".mjs",
372
+ ".cjs"
373
+ ])) return ts.ScriptKind.JS;
374
+ return ts.ScriptKind.TS;
375
+ }
376
+ function has_file_extension(filename, extensions) {
377
+ return extensions.some((extension) => filename.endsWith(extension));
378
+ }
405
379
  function make_remote_client_wrapper_plugin(options) {
406
380
  return {
407
381
  name: "svelte-effect-runtime:remote-client",
@@ -478,9 +452,9 @@ function make_reserved_helper_warning(names) {
478
452
  * @internal
479
453
  */
480
454
  async function rewrite_remote_client_exports(code, options) {
481
- return (await import("./remote-client-Bj1pZXgq.js")).rewrite_remote_client_exports(code, options);
455
+ return (await import("./remote-client-CVI4t66c.js")).rewrite_remote_client_exports(code, options);
482
456
  }
483
457
  //#endregion
484
458
  export { rewrite_remote_client_exports as n, effect as t };
485
459
 
486
- //# sourceMappingURL=vite-WGlbSnso.js.map
460
+ //# sourceMappingURL=compiler-BBPNyXmQ.js.map