svelte-effect-runtime 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/chunks/{client-CfkB_G4o.js → client-CtxuIuC8.js} +2 -3
- package/.dist/chunks/client-CtxuIuC8.js.map +1 -0
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/remote/client/types.d.ts +7 -7
- package/.dist/remote/client.js +1 -1
- package/.dist/vite.js +36 -1
- package/.dist/vite.js.map +1 -1
- package/package.json +1 -1
- package/.dist/chunks/client-CfkB_G4o.js.map +0 -1
|
@@ -341,8 +341,7 @@ function make_submit_effect(original_submit) {
|
|
|
341
341
|
let updates_args;
|
|
342
342
|
const effect = make_effect_from_promise(async () => {
|
|
343
343
|
const result = original_submit();
|
|
344
|
-
|
|
345
|
-
return await Promise.resolve(result);
|
|
344
|
+
return (updates_args && has_method(result, "updates") ? await Promise.resolve(result.updates(...updates_args)) : await Promise.resolve(result)) === true;
|
|
346
345
|
});
|
|
347
346
|
Object.defineProperty(effect, "updates", {
|
|
348
347
|
configurable: true,
|
|
@@ -581,4 +580,4 @@ function make_live_query_resource(resource) {
|
|
|
581
580
|
//#endregion
|
|
582
581
|
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 };
|
|
583
582
|
|
|
584
|
-
//# sourceMappingURL=client-
|
|
583
|
+
//# sourceMappingURL=client-CtxuIuC8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-CtxuIuC8.js","names":[],"sources":["../../../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/utils.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":["import {\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n is_serialized_remote_failure_envelope,\n} from \"$/remote/shared.ts\";\nimport type { FormIssue, RemoteFailure } from \"$/remote/shared.ts\";\nimport { parse } from \"devalue\";\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(\n raw: unknown,\n decode?: (encoded: string) => unknown,\n): RemoteFailure<unknown> | unknown {\n const embedded = parse_embedded_remote_failure(raw);\n\n if (embedded !== raw) {\n return decode_remote_error(embedded, decode);\n }\n\n if (is_serialized_remote_failure_envelope(raw)) {\n try {\n const decoded = decode ? decode(raw.encoded) : parse(raw.encoded);\n\n return decoded as RemoteFailure<unknown>;\n } catch {\n return create_remote_transport_error(\n new Error(\n \"[REMOTE_ERROR_DECODE_FAILED]: Failed to decode remote error payload\",\n ),\n raw,\n );\n }\n }\n\n return raw;\n}\n\nfunction parse_embedded_remote_failure(raw: unknown): unknown {\n if (typeof raw === \"string\") {\n return parse_json_or_original(raw);\n }\n\n if (typeof raw !== \"object\" || raw === null || !(\"message\" in raw)) {\n return raw;\n }\n\n const message = (raw as { message?: unknown }).message;\n\n if (typeof message !== \"string\") {\n return raw;\n }\n\n const parsed = parse_json_or_original(message);\n\n return parsed === message ? raw : parsed;\n}\n\nfunction parse_json_or_original(value: string): unknown {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\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(\n value: unknown,\n): value is RemoteFailure<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"_tag\" in value\n );\n}\n\n/**\n * Checks whether a response body represents SvelteKit validation issues.\n *\n * @example\n * ```ts\n * if (is_validation_body(body)) return body.issues;\n * ```\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @returns Whether the value contains a form issue list.\n */\nexport function is_validation_body(\n value: unknown,\n): value is { issues: readonly FormIssue[] } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { issues?: unknown }).issues)\n );\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(error: unknown): RemoteFailure<unknown> {\n const body = get_error_body(error);\n const decoded = decode_remote_error(body);\n const status = get_error_status(error);\n\n if (is_decoded_remote_failure(decoded)) {\n return decoded;\n }\n\n if (status === 400 && is_validation_body(body)) {\n return create_remote_validation_error(body.issues, body, status);\n }\n\n if (status !== undefined) {\n return create_remote_http_error(status, body, error);\n }\n\n return create_remote_transport_error(error);\n}\n\nfunction get_error_status(error: unknown): number | undefined {\n if (typeof error !== \"object\" || error === null) {\n return undefined;\n }\n\n const status = (error as { status?: unknown }).status;\n\n return typeof status === \"number\" ? status : undefined;\n}\n\nfunction get_error_body(error: unknown): unknown {\n if (typeof error !== \"object\" || error === null) {\n return undefined;\n }\n\n if (\"body\" in error) {\n return (error as { body?: unknown }).body;\n }\n\n if (\"data\" in error) {\n return (error as { data?: unknown }).data;\n }\n\n return undefined;\n}\n","import {\n create_remote_http_error,\n create_remote_validation_error,\n} from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\n\nimport {\n decode_remote_error,\n is_decoded_remote_failure,\n is_validation_body,\n} 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(\n response: Response,\n): Promise<RemoteFailure<unknown>> {\n const body = await response.json().catch(() => undefined);\n const decoded = decode_remote_error(body);\n\n if (is_decoded_remote_failure(decoded)) {\n return decoded;\n }\n\n if (response.status === 400 && is_validation_body(body)) {\n return create_remote_validation_error(body.issues, body, response.status);\n }\n\n return 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>(\n value: unknown,\n decode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n if (value instanceof Response) {\n if (!value.ok) {\n throw await decode_response_failure(value);\n }\n\n const data = await value.json();\n\n return decode_payload(data) as Output;\n }\n\n return decode_payload(value) as Output;\n}\n","import type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { Effect } from \"effect\";\n\nimport {\n is_decoded_remote_failure,\n normalize_native_error,\n} 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 make_effect_from_promise<Output>(\n run: () => Promise<Output>,\n): Effect.Effect<Output, RemoteFailure<unknown>> {\n return Effect.tryPromise({\n try: run,\n catch: (error: unknown) => {\n if (is_decoded_remote_failure(error)) {\n return error;\n }\n\n return normalize_native_error(error);\n },\n }) as Effect.Effect<Output, RemoteFailure<unknown>>;\n}\n","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 value: unknown,\n key: K,\n): value is Record<K, NativeMethod> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<PropertyKey, unknown>)[key] === \"function\"\n );\n}\n","import type { RemoteFailure } from \"$/remote/shared.ts\";\nimport type { Effect } from \"effect\";\n\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { make_effect_from_promise } from \"./effect.ts\";\nimport { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport type { NativeMethod, Pending } from \"./types.ts\";\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>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n _base = \"\",\n pending?: Pending,\n): (input: Input) => Effect.Effect<Output, RemoteFailure<unknown>> {\n const invoke = has_method(native_factory, \"invoke\")\n ? native_factory.invoke\n : undefined;\n\n if (typeof native_factory !== \"function\" && !invoke) {\n throw new Error(\n \"[INVALID_COMMAND_FACTORY]: Invalid command factory: expected a function\",\n );\n }\n\n const count = pending ?? { value: 0 };\n\n const adapter = (input: Input) =>\n make_effect_from_promise(async () => {\n count.value += 1;\n\n try {\n const result = invoke\n ? await invoke(input)\n : await (native_factory as NativeMethod)(input);\n\n return await decode_response_or_value<Output>(result, decode_payload);\n } finally {\n count.value -= 1;\n }\n });\n\n copy_property_descriptors(native_factory, adapter);\n\n if (!Object.prototype.hasOwnProperty.call(adapter, \"pending\")) {\n Object.defineProperty(adapter, \"pending\", {\n get: () => count.value,\n });\n }\n\n return adapter;\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 const form_data = new FormData();\n\n append_form_value(form_data, \"\", input);\n\n return form_data;\n}\n\nfunction append_form_value(\n form_data: FormData,\n path: string,\n value: unknown,\n): void {\n if (value === undefined) {\n return;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n append_form_value(form_data, `${path}[]`, item);\n }\n\n return;\n }\n\n if (value instanceof Blob) {\n form_data.append(path, value);\n\n return;\n }\n\n if (typeof value === \"object\" && value !== null) {\n for (const [key, child] of Object.entries(value)) {\n const child_path = path.length === 0 ? key : `${path}.${key}`;\n\n append_form_value(form_data, child_path, child);\n }\n\n return;\n }\n\n if (typeof value === \"number\") {\n form_data.append(`n:${path}`, String(value));\n\n return;\n }\n\n if (typeof value === \"boolean\") {\n if (value) {\n form_data.append(`b:${path}`, \"on\");\n }\n\n return;\n }\n\n form_data.append(path, value === null ? \"\" : String(value));\n}\n","import {\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n} from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\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\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 * @returns Decoded form output.\n */\nexport async function submit_remote_form<Output>(\n form_obj: NativeFormRecord,\n input: unknown,\n decode_payload: (value: unknown) => unknown,\n remote_base: string,\n): Promise<Output> {\n const action_id = get_remote_action_id(form_obj);\n\n if (!action_id || remote_base.length === 0) {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_ENDPOINT_MISSING]: Form has no submit method or remote endpoint\",\n ),\n );\n }\n\n const response = await fetch(to_remote_form_url(remote_base, action_id), {\n method: \"POST\",\n body: to_form_data(input),\n });\n\n if (!response.ok) {\n throw await decode_response_failure(response);\n }\n\n const envelope = await response.json();\n\n return 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(\n form_obj: NativeFormRecord,\n): string | undefined {\n const action = form_obj.action;\n\n if (typeof action !== \"string\") {\n return undefined;\n }\n\n const fallback = \"http://localhost/\";\n const href = typeof location === \"undefined\" ? fallback : location.href;\n const url = new URL(action, href);\n\n return url.searchParams.get(\"/remote\") ??\n url.searchParams.get(\"remote\") ??\n undefined;\n}\n\nfunction to_remote_form_url(remote_base: string, action_id: string): string {\n const parts = action_id.split(\"/\");\n const head = parts.slice(0, 2).join(\"/\");\n const tail = parts.slice(2).join(\"/\");\n const normalized_base = remote_base.replace(/\\/$/, \"\");\n\n if (tail.length === 0) {\n return `${normalized_base}/${head}`;\n }\n\n return `${normalized_base}/${head}/${encodeURIComponent(tail)}`;\n}\n\nfunction decode_form_response<Output>(\n envelope: unknown,\n decode_payload: (value: unknown) => unknown,\n): Output {\n if (\n typeof envelope !== \"object\" ||\n envelope === null ||\n !(\"type\" in envelope)\n ) {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_RESPONSE_INVALID]: Invalid remote form response\",\n ),\n envelope,\n );\n }\n\n const response = envelope as {\n type: string;\n result?: unknown;\n error?: unknown;\n status?: number;\n };\n\n if (response.type === \"error\") {\n const decoded = decode_remote_error(response.error);\n\n if (is_decoded_remote_failure(decoded)) {\n throw decoded;\n }\n\n throw create_remote_http_error(\n response.status ?? 500,\n response.error,\n );\n }\n\n if (response.type !== \"result\" || typeof response.result !== \"string\") {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_RESPONSE_UNSUPPORTED]: Unsupported remote form response\",\n ),\n envelope,\n );\n }\n\n const parsed = parse(response.result);\n const decoded = decode_payload(parsed) as {\n issues?: readonly FormIssue[];\n result?: Output;\n };\n\n if (decoded.issues && decoded.issues.length > 0) {\n throw create_remote_validation_error(decoded.issues, decoded, 400);\n }\n\n return decoded.result as Output;\n}\n","import { get_dispatcher } from \"$/dispatcher.ts\";\nimport { Effect } from \"effect\";\n\nimport { make_effect_from_promise } 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(\n callback: NativeMethod | undefined,\n): NativeMethod | undefined {\n if (!callback) {\n return undefined;\n }\n\n return (event: unknown) => {\n const wrapped_event = wrap_submit_callback(event);\n const result = callback(wrapped_event);\n\n if (Effect.isEffect(result)) {\n return get_dispatcher().run(result);\n }\n\n return result;\n };\n}\n\nfunction wrap_submit_callback(event: unknown): unknown {\n if (\n typeof event !== \"object\" || event === null || !has_method(event, \"submit\")\n ) {\n return event;\n }\n\n const original_submit = event.submit;\n const { submit: _submit, ...descriptors } = Object.getOwnPropertyDescriptors(\n event,\n );\n\n void _submit;\n\n return Object.defineProperties({}, {\n ...descriptors,\n submit: {\n configurable: true,\n enumerable: false,\n value: () => make_submit_effect(original_submit),\n },\n });\n}\n\nfunction make_submit_effect(\n original_submit: NativeMethod,\n): EffectRemoteFormSubmit {\n let updates_args: unknown[] | undefined;\n\n const effect = make_effect_from_promise(async (): Promise<boolean> => {\n const result = original_submit();\n const value = updates_args && has_method(result, \"updates\")\n ? await Promise.resolve(result.updates(...updates_args))\n : await Promise.resolve(result);\n\n return value === true;\n }) as EffectRemoteFormSubmit;\n\n Object.defineProperty(effect, \"updates\", {\n configurable: true,\n enumerable: false,\n value: (...args: unknown[]) => {\n updates_args ??= args;\n\n return effect;\n },\n });\n\n return effect;\n}\n","import type { RemoteFormInput } from \"@sveltejs/kit\";\n\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { make_effect_from_promise } 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 } from \"./types.ts\";\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 * @returns A callable form function whose properties mirror the native form.\n * @internal\n */\nexport function create_remote_form_adapter<\n Input extends RemoteFormInput | void,\n Output,\n>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n remote_base = \"\",\n): EffectRemoteForm<Input, Output> {\n const form_obj = native_factory as NativeFormRecord;\n\n const submit_effect = (input: Input) =>\n make_effect_from_promise(async () => {\n const can_use_remote_endpoint = remote_base.length > 0 &&\n get_remote_action_id(form_obj) !== undefined;\n\n if (has_method(form_obj, \"submit\") && !can_use_remote_endpoint) {\n const result = await form_obj.submit(input);\n\n return await decode_response_or_value<Output>(result, decode_payload);\n }\n\n return await submit_remote_form<Output>(\n form_obj,\n input,\n decode_payload,\n remote_base,\n );\n });\n\n const callable = ((input: Input) => submit_effect(input)) as EffectRemoteForm<\n Input,\n Output\n >;\n\n copy_property_descriptors(\n form_obj,\n callable,\n new Set([\"submit\", \"validate\", \"enhance\", \"for\", \"preflight\"]),\n );\n\n Object.defineProperty(callable, \"submit\", {\n configurable: true,\n enumerable: false,\n value: submit_effect,\n });\n\n if (has_method(form_obj, \"validate\")) {\n Object.defineProperty(callable, \"validate\", {\n configurable: true,\n enumerable: false,\n value: (options?: Record<string, unknown>) =>\n make_effect_from_promise(async () => {\n await form_obj.validate(options);\n }),\n });\n }\n\n if (has_method(form_obj, \"enhance\")) {\n Object.defineProperty(callable, \"enhance\", {\n configurable: true,\n enumerable: false,\n value: (callback?: Parameters<typeof wrap_enhance_callback>[0]) =>\n form_obj.enhance(wrap_enhance_callback(callback)),\n });\n }\n\n if (has_method(form_obj, \"for\")) {\n Object.defineProperty(callable, \"for\", {\n configurable: true,\n enumerable: false,\n value: (key: string | number | boolean) =>\n create_remote_form_adapter<Input, Output>(\n form_obj.for(key),\n decode_payload,\n remote_base,\n ),\n });\n }\n\n if (has_method(form_obj, \"preflight\")) {\n Object.defineProperty(callable, \"preflight\", {\n configurable: true,\n enumerable: false,\n value: (schema: unknown) => {\n form_obj.preflight(schema);\n\n return callable;\n },\n });\n }\n\n return callable;\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 value: unknown,\n decode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n if (has_method(value, \"then\")) {\n const result = await Promise.resolve(value);\n\n return decode_response_or_value(result, decode_payload);\n }\n\n if (has_method(value, \"run\")) {\n const result = await value.run();\n\n return decode_response_or_value(result, decode_payload);\n }\n\n const result = await Promise.resolve(value);\n\n return decode_response_or_value(result, decode_payload);\n}\n","import { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport { normalize_native_error } from \"./failures.ts\";\nimport { resolve_query_result } from \"./query-result.ts\";\nimport { make_effect_from_promise } from \"./effect.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport type { NativeMethod } from \"./types.ts\";\nimport { Effect } from \"effect\";\n\ntype RemoteResourceEffect<Output> =\n & Effect.Effect<Output, RemoteFailure<unknown>>\n & {\n readonly current: Output | undefined;\n readonly error: unknown;\n readonly loading: boolean;\n readonly ready: boolean;\n };\n\ntype RemoteResourceLike<Output> =\n | RemoteResourceEffect<Output>\n | RemoteLiveQueryResource<Output>;\n\ntype RemoteQueryEffect<Output> =\n & RemoteResourceEffect<Output>\n & {\n readonly refresh: () => Effect.Effect<void, unknown, never>;\n readonly set: (value: Output) => void;\n readonly withOverride: (\n update: (current: Output) => Output,\n ) => unknown;\n };\n\ntype RemoteLiveQueryEffect<Output> = Effect.Effect<\n RemoteLiveQueryResource<Output>,\n RemoteFailure<unknown>\n>;\n\ntype RemoteLiveQueryResource<Output> =\n & {\n readonly connected: boolean;\n readonly current: Output | undefined;\n readonly done: boolean;\n readonly error: unknown;\n readonly loading: boolean;\n readonly ready: boolean;\n readonly reconnect: () => Effect.Effect<void, unknown, never>;\n }\n & AsyncIterable<Output>;\n\ntype NativeRemoteResource<Output> = {\n readonly connected?: boolean;\n readonly current?: Output;\n readonly done?: boolean;\n readonly error?: unknown;\n readonly loading?: boolean;\n readonly ready?: boolean;\n readonly reconnect?: () => Promise<void>;\n readonly refresh?: () => Promise<void>;\n readonly set?: (value: Output) => void;\n readonly withOverride?: (update: (current: Output) => Output) => unknown;\n readonly [Symbol.asyncIterator]?: () => AsyncIterator<Output>;\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>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n _base = \"\",\n): (input: Input) => RemoteQueryEffect<Output> {\n const load = has_method(native_factory, \"load\")\n ? native_factory.load\n : undefined;\n const query = typeof native_factory === \"function\"\n ? native_factory as NativeMethod\n : undefined;\n\n if (!query && !load) {\n throw new Error(\n \"[INVALID_QUERY_FACTORY]: Invalid query factory: expected a function\",\n );\n }\n\n const wrapped = ((input: Input) => {\n if (!query) {\n return make_effect_from_promise(async () => {\n const result = await load?.(input);\n\n return await resolve_query_result<Output>(result, decode_payload);\n }) as RemoteQueryEffect<Output>;\n }\n\n const resource = query(input);\n const effect = make_effect_from_promise(async () =>\n await resolve_query_result<Output>(resource, decode_payload)\n ) as RemoteQueryEffect<Output>;\n\n attach_query_resource(resource, effect);\n\n return effect;\n }) as (input: Input) => RemoteQueryEffect<Output>;\n\n copy_property_descriptors(native_factory, wrapped);\n\n return wrapped;\n}\n\n/**\n * Creates a remote live query adapter. The returned function takes input and\n * returns an `Effect` that resolves to a live query resource with stream state\n * and reconnect controls.\n *\n * @example\n * ```ts\n * const getTime = create_remote_live_query_adapter(nativeLive, (value) => value);\n * const time = yield* getTime();\n * const current = time.current;\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 an Effect-backed live query resource.\n * @internal\n */\nexport function create_remote_live_query_adapter<Input, Output>(\n native_factory: unknown,\n _decode_payload: (value: unknown) => unknown,\n _base = \"\",\n): (input: Input) => RemoteLiveQueryEffect<Output> {\n const query = typeof native_factory === \"function\"\n ? native_factory as NativeMethod\n : undefined;\n\n if (!query) {\n throw new Error(\n \"[INVALID_LIVE_QUERY_FACTORY]: Invalid live query factory: expected a function\",\n );\n }\n\n const wrapped = ((input: Input) =>\n Effect.try({\n try: () => {\n const resource = query(input);\n\n return make_live_query_resource<Output>(resource);\n },\n catch: normalize_native_error,\n }) as RemoteLiveQueryEffect<Output>) as (\n input: Input,\n ) => RemoteLiveQueryEffect<Output>;\n\n copy_property_descriptors(native_factory, wrapped);\n\n return wrapped;\n}\n\nfunction is_resource<Output>(\n resource: unknown,\n): resource is NativeRemoteResource<Output> {\n const resource_type = typeof resource;\n\n return (\n (resource_type === \"object\" && resource !== null) ||\n resource_type === \"function\"\n );\n}\n\nfunction attach_resource_getters<Output>(\n resource: unknown,\n effect: RemoteResourceLike<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const keys = [\"current\", \"error\", \"loading\", \"ready\"] as const;\n\n if (!methods) {\n return;\n }\n\n for (const key of keys) {\n if (!(key in methods)) {\n continue;\n }\n\n Object.defineProperty(effect, key, {\n configurable: true,\n get: () => methods[key],\n });\n }\n}\n\nfunction attach_query_resource<Output>(\n resource: unknown,\n effect: RemoteQueryEffect<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const refresh = methods?.refresh;\n const set = methods?.set;\n const with_override = methods?.withOverride;\n\n attach_resource_getters(resource, effect);\n\n if (!methods) {\n return;\n }\n\n if (typeof refresh === \"function\") {\n Object.defineProperty(effect, \"refresh\", {\n configurable: true,\n value: () =>\n make_effect_from_promise(() => Promise.resolve(refresh.call(resource))),\n });\n }\n\n if (typeof set === \"function\") {\n Object.defineProperty(effect, \"set\", {\n configurable: true,\n value: (value: Output) => set.call(resource, value),\n });\n }\n\n if (typeof with_override === \"function\") {\n Object.defineProperty(effect, \"withOverride\", {\n configurable: true,\n value: (update: (current: Output) => Output) =>\n with_override.call(resource, update),\n });\n }\n}\n\nfunction attach_live_query_resource<Output>(\n resource: unknown,\n effect: RemoteLiveQueryResource<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const async_iterator = methods?.[Symbol.asyncIterator];\n const reconnect = methods?.reconnect;\n const keys = [\"connected\", \"done\"] as const;\n\n attach_resource_getters(resource, effect);\n\n if (!methods) {\n return;\n }\n\n for (const key of keys) {\n if (!(key in methods)) {\n continue;\n }\n\n Object.defineProperty(effect, key, {\n configurable: true,\n get: () => methods[key],\n });\n }\n\n if (typeof reconnect === \"function\") {\n Object.defineProperty(effect, \"reconnect\", {\n configurable: true,\n value: () =>\n make_effect_from_promise(() =>\n Promise.resolve(reconnect.call(resource))\n ),\n });\n }\n\n if (typeof async_iterator === \"function\") {\n Object.defineProperty(effect, Symbol.asyncIterator, {\n configurable: true,\n value: () => async_iterator.call(resource),\n });\n }\n}\n\nfunction make_live_query_resource<Output>(\n resource: unknown,\n): RemoteLiveQueryResource<Output> {\n const live_resource = {} as RemoteLiveQueryResource<Output>;\n\n attach_live_query_resource(resource, live_resource);\n\n return live_resource;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBACd,KACA,QACkC;CAClC,MAAM,WAAW,8BAA8B,GAAG;CAElD,IAAI,aAAa,KACf,OAAO,oBAAoB,UAAU,MAAM;CAG7C,IAAI,sCAAsC,GAAG,GAC3C,IAAI;EAGF,OAFgB,SAAS,OAAO,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO;CAGlE,QAAQ;EACN,OAAO,8CACL,IAAI,MACF,qEACF,GACA,GACF;CACF;CAGF,OAAO;AACT;AAEA,SAAS,8BAA8B,KAAuB;CAC5D,IAAI,OAAO,QAAQ,UACjB,OAAO,uBAAuB,GAAG;CAGnC,IAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,aAAa,MAC5D,OAAO;CAGT,MAAM,UAAW,IAA8B;CAE/C,IAAI,OAAO,YAAY,UAC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BACP,UACiC;CACjC,MAAM,gBAAgB,CAAC;CAEvB,2BAA2B,UAAU,aAAa;CAElD,OAAO;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-
|
|
1
|
+
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-CtxuIuC8.js";
|
|
2
2
|
export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RemoteForm, RemoteFormInput } from "@sveltejs/kit";
|
|
1
|
+
import type { RemoteForm, RemoteFormInput, RemoteQueryUpdate } from "@sveltejs/kit";
|
|
2
2
|
import type { RemoteFailure } from "../shared.js";
|
|
3
3
|
import type { Effect } from "effect";
|
|
4
4
|
/**
|
|
@@ -25,8 +25,8 @@ export type NativeMethod = (...args: unknown[]) => unknown;
|
|
|
25
25
|
*/
|
|
26
26
|
export type NativeFormRecord = Record<PropertyKey, unknown>;
|
|
27
27
|
/**
|
|
28
|
-
* Represents the form submit handle passed into an Effect-aware
|
|
29
|
-
* remote form callback.
|
|
28
|
+
* Represents the native form submit handle passed into an Effect-aware
|
|
29
|
+
* enhanced remote form callback.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
@@ -39,8 +39,8 @@ export type NativeFormRecord = Record<PropertyKey, unknown>;
|
|
|
39
39
|
*
|
|
40
40
|
* @since 2.0.0
|
|
41
41
|
*/
|
|
42
|
-
export type EffectRemoteFormSubmit = Effect.Effect<
|
|
43
|
-
updates: (...updates:
|
|
42
|
+
export type EffectRemoteFormSubmit = Effect.Effect<boolean, RemoteFailure<unknown>> & {
|
|
43
|
+
updates: (...updates: RemoteQueryUpdate[]) => Effect.Effect<boolean, RemoteFailure<unknown>>;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Represents the callback payload passed to an Effect-aware remote form
|
|
@@ -58,7 +58,7 @@ export type EffectRemoteFormSubmit = Effect.Effect<unknown, RemoteFailure<unknow
|
|
|
58
58
|
*
|
|
59
59
|
* @since 2.0.0
|
|
60
60
|
*/
|
|
61
|
-
export type EffectRemoteFormEnhanceOptions<Input extends RemoteFormInput | void> = Omit<Parameters<RemoteForm<Input,
|
|
61
|
+
export type EffectRemoteFormEnhanceOptions<Input extends RemoteFormInput | void, Output> = Omit<Parameters<RemoteForm<Input, Output>["enhance"]>[0] extends (options: infer Options) => unknown ? Options : never, "submit"> & {
|
|
62
62
|
submit: () => EffectRemoteFormSubmit;
|
|
63
63
|
};
|
|
64
64
|
/**
|
|
@@ -75,7 +75,7 @@ export type EffectRemoteFormEnhanceOptions<Input extends RemoteFormInput | void>
|
|
|
75
75
|
* @since 2.0.0
|
|
76
76
|
*/
|
|
77
77
|
export type EffectRemoteForm<Input extends RemoteFormInput | void, Output> = ((input: Input) => Effect.Effect<Output, RemoteFailure<unknown>>) & Omit<RemoteForm<Input, Output>, "enhance" | "for" | "preflight" | "submit" | "validate"> & {
|
|
78
|
-
enhance(callback?: (options: EffectRemoteFormEnhanceOptions<Input>) => void | Promise<void> | Effect.Effect<void, unknown, unknown>): ReturnType<RemoteForm<Input, Output>["enhance"]>;
|
|
78
|
+
enhance(callback?: (options: EffectRemoteFormEnhanceOptions<Input, Output>) => void | Promise<void> | Effect.Effect<void, unknown, unknown>): ReturnType<RemoteForm<Input, Output>["enhance"]>;
|
|
79
79
|
for(id: Parameters<RemoteForm<Input, Output>["for"]>[0]): Omit<EffectRemoteForm<Input, Output>, "for">;
|
|
80
80
|
preflight(schema: unknown): EffectRemoteForm<Input, Output>;
|
|
81
81
|
submit(input: Input): Effect.Effect<Output, RemoteFailure<unknown>>;
|
package/.dist/remote/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-
|
|
1
|
+
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-CtxuIuC8.js";
|
|
2
2
|
export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
|
package/.dist/vite.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { preprocess } from "./runtime/preprocess.js";
|
|
1
2
|
//#region src/vite.ts
|
|
2
3
|
/**
|
|
3
4
|
* Vite plugin for SvelteKit. The pre plugin rewrites server-side imports
|
|
@@ -17,7 +18,33 @@
|
|
|
17
18
|
* @returns Vite plugins that integrate the runtime with SvelteKit.
|
|
18
19
|
*/
|
|
19
20
|
function effect(options) {
|
|
20
|
-
return [
|
|
21
|
+
return [
|
|
22
|
+
make_svelte_preprocess_plugin(),
|
|
23
|
+
make_server_rewrite_plugin(),
|
|
24
|
+
make_remote_client_wrapper_plugin(options)
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function make_svelte_preprocess_plugin() {
|
|
28
|
+
const group = preprocess();
|
|
29
|
+
return {
|
|
30
|
+
name: "svelte-effect-runtime:svelte-preprocess",
|
|
31
|
+
enforce: "pre",
|
|
32
|
+
transform: {
|
|
33
|
+
order: "pre",
|
|
34
|
+
handler(code, id) {
|
|
35
|
+
if (!is_svelte_component_module(id)) return;
|
|
36
|
+
const result = group.markup({
|
|
37
|
+
content: code,
|
|
38
|
+
filename: id
|
|
39
|
+
});
|
|
40
|
+
if (result.code === code) return;
|
|
41
|
+
return {
|
|
42
|
+
code: result.code,
|
|
43
|
+
map: null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
21
48
|
}
|
|
22
49
|
function make_server_rewrite_plugin() {
|
|
23
50
|
return {
|
|
@@ -71,6 +98,14 @@ function is_server_runtime_module(id) {
|
|
|
71
98
|
function is_remote_module(id) {
|
|
72
99
|
return /\.(remote|remote\.[cm]?)\.[jt]s(?:\?.*)?$/.test(id) || id.includes(".remote.");
|
|
73
100
|
}
|
|
101
|
+
function is_svelte_component_module(id) {
|
|
102
|
+
const [filename, query = ""] = id.split("?", 2);
|
|
103
|
+
if (!filename.endsWith(".svelte")) return false;
|
|
104
|
+
if (query.length === 0) return true;
|
|
105
|
+
const params = new URLSearchParams(query);
|
|
106
|
+
const allowed_params = ["t", "v"];
|
|
107
|
+
return [...params.keys()].every((key) => allowed_params.includes(key));
|
|
108
|
+
}
|
|
74
109
|
/**
|
|
75
110
|
* Rewrites SvelteKit's generated client remote module from:
|
|
76
111
|
*
|
package/.dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\n/**\n * Options for the {@link effect} Vite plugin.\n *\n * @since 2.0.0\n */\nexport interface EffectOptions {\n /** Whether to emit debug logging in the generated remote client module. */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for SvelteKit. The pre plugin rewrites server-side imports\n * to the server entrypoint; the post plugin wraps SvelteKit's generated\n * client remote exports in Effect-returning adapters.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\n * import { sveltekit } from \"@sveltejs/kit/vite\";\n *\n * export default defineConfig({ plugins: [effect(), sveltekit()] });\n * ```\n *\n * @since 2.0.0\n * @param options - Optional configuration.\n * @returns Vite plugins that integrate the runtime with SvelteKit.\n */\nexport function effect(options?: EffectOptions): Plugin[] {\n return [\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_server_rewrite_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:server-imports\",\n enforce: \"pre\",\n\n config() {\n return { optimizeDeps: { exclude: [\"svelte-effect-runtime\"] } };\n },\n\n transform(code: string, id: string) {\n if (!is_server_runtime_module(id)) {\n return undefined;\n }\n\n const rewritten = code\n .replace(\n /from\\s+[\"']svelte-effect-runtime[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n )\n .replace(\n /from\\s+[\"']svelte-effect-runtime\\/internal\\/generators[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n );\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction make_remote_client_wrapper_plugin(options?: EffectOptions): Plugin {\n return {\n name: \"svelte-effect-runtime:remote-client\",\n enforce: \"post\",\n\n config() {\n return { ssr: { noExternal: [\"svelte-effect-runtime\"] } };\n },\n\n configResolved(config) {\n const no_external = config.ssr.noExternal;\n const runtime_package = \"svelte-effect-runtime\";\n\n if (no_external === true) {\n return;\n }\n\n if (Array.isArray(no_external)) {\n const has_runtime_package = no_external.some(\n (entry) => entry === runtime_package,\n );\n\n if (!has_runtime_package) {\n no_external.push(runtime_package);\n }\n\n return;\n }\n\n config.ssr.noExternal = [\n no_external,\n runtime_package,\n ].filter((value): value is string | RegExp => value !== undefined);\n },\n\n transform(code: string, id: string) {\n if (!is_remote_module(id) || !code.includes(\"__sveltekit/remote\")) {\n return undefined;\n }\n\n const rewritten = rewrite_remote_client_exports(code, options);\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction is_server_runtime_module(id: string): boolean {\n return (\n id.endsWith(\".server.ts\") ||\n id.endsWith(\".remote.ts\") ||\n id.includes(\"hooks.server.\")\n );\n}\n\nfunction is_remote_module(id: string): boolean {\n return /\\.(remote|remote\\.[cm]?)\\.[jt]s(?:\\?.*)?$/.test(id) ||\n id.includes(\".remote.\");\n}\n\n/**\n * Rewrites SvelteKit's generated client remote module from:\n *\n * `export const get_post = __remote.query(\"hash/get_post\")`\n *\n * into an Effect-aware wrapper around the same native function.\n *\n * @since 2.0.0\n * @param code - The generated client remote module code.\n * @param options - Optional plugin options.\n * @returns The rewritten module code.\n * @internal\n */\nexport function rewrite_remote_client_exports(\n code: string,\n options?: EffectOptions,\n): string {\n const import_match = code.match(\n /import\\s+\\*\\s+as\\s+([A-Za-z_$][\\w$]*)\\s+from\\s+[\"']__sveltekit\\/remote[\"'];?/,\n );\n\n if (!import_match) {\n return code;\n }\n\n const namespace = import_match[1];\n const export_pattern = new RegExp(\n `export\\\\s+const\\\\s+([A-Za-z_$][\\\\w$]*)\\\\s*=\\\\s*${namespace}\\\\.(query_batch|query_live|query|command|form|prerender)\\\\(([\"'][^\"']+[\"'])\\\\);?`,\n \"g\",\n );\n\n let replaced_any = false;\n const body = code.replace(\n export_pattern,\n (_match, name, type, id_literal) => {\n replaced_any = true;\n\n return make_remote_export(name, type, id_literal, namespace);\n },\n );\n\n if (!replaced_any) {\n return code;\n }\n\n const imports = [\n `import { app_dir, base } from \"$app/paths/internal/client\";`,\n `import { create_remote_query_adapter, create_remote_live_query_adapter, create_remote_command_adapter, create_remote_form_adapter } from \"svelte-effect-runtime/internal/remote-client\";`,\n ].join(\"\\n\");\n\n const helpers = [\n `const __SER___remote_base = \\`\\${base}/\\${app_dir}/remote\\`;`,\n `function __SER___decode_payload(value) { return value; }`,\n ].join(\"\\n\");\n\n const debug_line = options?.debug\n ? `console.log(\"[ser] remote client wrappers loaded\");`\n : \"\";\n\n const injected = [\n import_match[0],\n imports,\n helpers,\n debug_line,\n ].filter(Boolean).join(\"\\n\");\n\n return body.replace(import_match[0], injected);\n}\n\nfunction make_remote_export(\n name: string,\n type: string,\n id_literal: string,\n namespace: string,\n): string {\n const native_call = `${namespace}.${type}(${id_literal})`;\n\n if (type === \"command\") {\n return `export const ${name} = create_remote_command_adapter(${native_call}, __SER___decode_payload);`;\n }\n\n if (type === \"form\") {\n return `export const ${name} = create_remote_form_adapter(${native_call}, __SER___decode_payload, __SER___remote_base);`;\n }\n\n if (type === \"query_live\") {\n return `export const ${name} = create_remote_live_query_adapter(${native_call}, __SER___decode_payload);`;\n }\n\n return `export const ${name} = create_remote_query_adapter(${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xB,GAAG,SAAS,eAAe;AAE/B;AAEA,SAAS,iBAAiB,IAAqB;CAC7C,OAAO,4CAA4C,KAAK,EAAE,KACxD,GAAG,SAAS,UAAU;AAC1B;;;;;;;;;;;;;;AAeA,SAAgB,8BACd,MACA,SACQ;CACR,MAAM,eAAe,KAAK,MACxB,8EACF;CAEA,IAAI,CAAC,cACH,OAAO;CAGT,MAAM,YAAY,aAAa;CAC/B,MAAM,iBAAiB,IAAI,OACzB,kDAAkD,UAAU,mFAC5D,GACF;CAEA,IAAI,eAAe;CACnB,MAAM,OAAO,KAAK,QAChB,iBACC,QAAQ,MAAM,MAAM,eAAe;EAClC,eAAe;EAEf,OAAO,mBAAmB,MAAM,MAAM,YAAY,SAAS;CAC7D,CACF;CAEA,IAAI,CAAC,cACH,OAAO;CAGT,MAAM,UAAU,CACd,+DACA,0LACF,EAAE,KAAK,IAAI;CAEX,MAAM,UAAU,CACd,gEACA,0DACF,EAAE,KAAK,IAAI;CAEX,MAAM,aAAa,SAAS,QACxB,wDACA;CAEJ,MAAM,WAAW;EACf,aAAa;EACb;EACA;EACA;CACF,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;CAE3B,OAAO,KAAK,QAAQ,aAAa,IAAI,QAAQ;AAC/C;AAEA,SAAS,mBACP,MACA,MACA,YACA,WACQ;CACR,MAAM,cAAc,GAAG,UAAU,GAAG,KAAK,GAAG,WAAW;CAEvD,IAAI,SAAS,WACX,OAAO,gBAAgB,KAAK,mCAAmC,YAAY;CAG7E,IAAI,SAAS,QACX,OAAO,gBAAgB,KAAK,gCAAgC,YAAY;CAG1E,IAAI,SAAS,cACX,OAAO,gBAAgB,KAAK,sCAAsC,YAAY;CAGhF,OAAO,gBAAgB,KAAK,iCAAiC,YAAY;AAC3E"}
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/vite.ts"],"sourcesContent":["import { preprocess } from \"./runtime/preprocess.ts\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Options for the {@link effect} Vite plugin.\n *\n * @since 2.0.0\n */\nexport interface EffectOptions {\n /** Whether to emit debug logging in the generated remote client module. */\n debug?: boolean;\n}\n\n/**\n * Vite plugin for SvelteKit. The pre plugin rewrites server-side imports\n * to the server entrypoint; the post plugin wraps SvelteKit's generated\n * client remote exports in Effect-returning adapters.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\n * import { sveltekit } from \"@sveltejs/kit/vite\";\n *\n * export default defineConfig({ plugins: [effect(), sveltekit()] });\n * ```\n *\n * @since 2.0.0\n * @param options - Optional configuration.\n * @returns Vite plugins that integrate the runtime with SvelteKit.\n */\nexport function effect(options?: EffectOptions): Plugin[] {\n return [\n make_svelte_preprocess_plugin(),\n make_server_rewrite_plugin(),\n make_remote_client_wrapper_plugin(options),\n ];\n}\n\nfunction make_svelte_preprocess_plugin(): Plugin {\n const group = preprocess();\n\n return {\n name: \"svelte-effect-runtime:svelte-preprocess\",\n enforce: \"pre\",\n\n transform: {\n order: \"pre\",\n handler(code: string, id: string) {\n if (!is_svelte_component_module(id)) {\n return undefined;\n }\n\n const result = group.markup({ content: code, filename: id });\n\n if (result.code === code) {\n return undefined;\n }\n\n return { code: result.code, map: null };\n },\n },\n };\n}\n\nfunction make_server_rewrite_plugin(): Plugin {\n return {\n name: \"svelte-effect-runtime:server-imports\",\n enforce: \"pre\",\n\n config() {\n return { optimizeDeps: { exclude: [\"svelte-effect-runtime\"] } };\n },\n\n transform(code: string, id: string) {\n if (!is_server_runtime_module(id)) {\n return undefined;\n }\n\n const rewritten = code\n .replace(\n /from\\s+[\"']svelte-effect-runtime[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n )\n .replace(\n /from\\s+[\"']svelte-effect-runtime\\/internal\\/generators[\"']/g,\n `from \"svelte-effect-runtime/server\"`,\n );\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction make_remote_client_wrapper_plugin(options?: EffectOptions): Plugin {\n return {\n name: \"svelte-effect-runtime:remote-client\",\n enforce: \"post\",\n\n config() {\n return { ssr: { noExternal: [\"svelte-effect-runtime\"] } };\n },\n\n configResolved(config) {\n const no_external = config.ssr.noExternal;\n const runtime_package = \"svelte-effect-runtime\";\n\n if (no_external === true) {\n return;\n }\n\n if (Array.isArray(no_external)) {\n const has_runtime_package = no_external.some(\n (entry) => entry === runtime_package,\n );\n\n if (!has_runtime_package) {\n no_external.push(runtime_package);\n }\n\n return;\n }\n\n config.ssr.noExternal = [\n no_external,\n runtime_package,\n ].filter((value): value is string | RegExp => value !== undefined);\n },\n\n transform(code: string, id: string) {\n if (!is_remote_module(id) || !code.includes(\"__sveltekit/remote\")) {\n return undefined;\n }\n\n const rewritten = rewrite_remote_client_exports(code, options);\n\n if (rewritten === code) {\n return undefined;\n }\n\n return { code: rewritten, map: null };\n },\n };\n}\n\nfunction is_server_runtime_module(id: string): boolean {\n return (\n id.endsWith(\".server.ts\") ||\n id.endsWith(\".remote.ts\") ||\n id.includes(\"hooks.server.\")\n );\n}\n\nfunction is_remote_module(id: string): boolean {\n return /\\.(remote|remote\\.[cm]?)\\.[jt]s(?:\\?.*)?$/.test(id) ||\n id.includes(\".remote.\");\n}\n\nfunction is_svelte_component_module(id: string): boolean {\n const [filename, query = \"\"] = id.split(\"?\", 2);\n\n if (!filename.endsWith(\".svelte\")) {\n return false;\n }\n\n if (query.length === 0) {\n return true;\n }\n\n const params = new URLSearchParams(query);\n const allowed_params = [\"t\", \"v\"];\n\n return [...params.keys()].every((key) => allowed_params.includes(key));\n}\n\n/**\n * Rewrites SvelteKit's generated client remote module from:\n *\n * `export const get_post = __remote.query(\"hash/get_post\")`\n *\n * into an Effect-aware wrapper around the same native function.\n *\n * @since 2.0.0\n * @param code - The generated client remote module code.\n * @param options - Optional plugin options.\n * @returns The rewritten module code.\n * @internal\n */\nexport function rewrite_remote_client_exports(\n code: string,\n options?: EffectOptions,\n): string {\n const import_match = code.match(\n /import\\s+\\*\\s+as\\s+([A-Za-z_$][\\w$]*)\\s+from\\s+[\"']__sveltekit\\/remote[\"'];?/,\n );\n\n if (!import_match) {\n return code;\n }\n\n const namespace = import_match[1];\n const export_pattern = new RegExp(\n `export\\\\s+const\\\\s+([A-Za-z_$][\\\\w$]*)\\\\s*=\\\\s*${namespace}\\\\.(query_batch|query_live|query|command|form|prerender)\\\\(([\"'][^\"']+[\"'])\\\\);?`,\n \"g\",\n );\n\n let replaced_any = false;\n const body = code.replace(\n export_pattern,\n (_match, name, type, id_literal) => {\n replaced_any = true;\n\n return make_remote_export(name, type, id_literal, namespace);\n },\n );\n\n if (!replaced_any) {\n return code;\n }\n\n const imports = [\n `import { app_dir, base } from \"$app/paths/internal/client\";`,\n `import { create_remote_query_adapter, create_remote_live_query_adapter, create_remote_command_adapter, create_remote_form_adapter } from \"svelte-effect-runtime/internal/remote-client\";`,\n ].join(\"\\n\");\n\n const helpers = [\n `const __SER___remote_base = \\`\\${base}/\\${app_dir}/remote\\`;`,\n `function __SER___decode_payload(value) { return value; }`,\n ].join(\"\\n\");\n\n const debug_line = options?.debug\n ? `console.log(\"[ser] remote client wrappers loaded\");`\n : \"\";\n\n const injected = [\n import_match[0],\n imports,\n helpers,\n debug_line,\n ].filter(Boolean).join(\"\\n\");\n\n return body.replace(import_match[0], injected);\n}\n\nfunction make_remote_export(\n name: string,\n type: string,\n id_literal: string,\n namespace: string,\n): string {\n const native_call = `${namespace}.${type}(${id_literal})`;\n\n if (type === \"command\") {\n return `export const ${name} = create_remote_command_adapter(${native_call}, __SER___decode_payload);`;\n }\n\n if (type === \"form\") {\n return `export const ${name} = create_remote_form_adapter(${native_call}, __SER___decode_payload, __SER___remote_base);`;\n }\n\n if (type === \"query_live\") {\n return `export const ${name} = create_remote_live_query_adapter(${native_call}, __SER___decode_payload);`;\n }\n\n return `export const ${name} = create_remote_query_adapter(${native_call}, __SER___decode_payload);`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,OAAO,S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SAAS,QACxB,wDACA;CAEJ,MAAM,WAAW;EACf,aAAa;EACb;EACA;EACA;CACF,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;CAE3B,OAAO,KAAK,QAAQ,aAAa,IAAI,QAAQ;AAC/C;AAEA,SAAS,mBACP,MACA,MACA,YACA,WACQ;CACR,MAAM,cAAc,GAAG,UAAU,GAAG,KAAK,GAAG,WAAW;CAEvD,IAAI,SAAS,WACX,OAAO,gBAAgB,KAAK,mCAAmC,YAAY;CAG7E,IAAI,SAAS,QACX,OAAO,gBAAgB,KAAK,gCAAgC,YAAY;CAG1E,IAAI,SAAS,cACX,OAAO,gBAAgB,KAAK,sCAAsC,YAAY;CAGhF,OAAO,gBAAgB,KAAK,iCAAiC,YAAY;AAC3E"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-CfkB_G4o.js","names":[],"sources":["../../../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/utils.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":["import {\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n is_serialized_remote_failure_envelope,\n} from \"$/remote/shared.ts\";\nimport type { FormIssue, RemoteFailure } from \"$/remote/shared.ts\";\nimport { parse } from \"devalue\";\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(\n raw: unknown,\n decode?: (encoded: string) => unknown,\n): RemoteFailure<unknown> | unknown {\n const embedded = parse_embedded_remote_failure(raw);\n\n if (embedded !== raw) {\n return decode_remote_error(embedded, decode);\n }\n\n if (is_serialized_remote_failure_envelope(raw)) {\n try {\n const decoded = decode ? decode(raw.encoded) : parse(raw.encoded);\n\n return decoded as RemoteFailure<unknown>;\n } catch {\n return create_remote_transport_error(\n new Error(\n \"[REMOTE_ERROR_DECODE_FAILED]: Failed to decode remote error payload\",\n ),\n raw,\n );\n }\n }\n\n return raw;\n}\n\nfunction parse_embedded_remote_failure(raw: unknown): unknown {\n if (typeof raw === \"string\") {\n return parse_json_or_original(raw);\n }\n\n if (typeof raw !== \"object\" || raw === null || !(\"message\" in raw)) {\n return raw;\n }\n\n const message = (raw as { message?: unknown }).message;\n\n if (typeof message !== \"string\") {\n return raw;\n }\n\n const parsed = parse_json_or_original(message);\n\n return parsed === message ? raw : parsed;\n}\n\nfunction parse_json_or_original(value: string): unknown {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\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(\n value: unknown,\n): value is RemoteFailure<unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"_tag\" in value\n );\n}\n\n/**\n * Checks whether a response body represents SvelteKit validation issues.\n *\n * @example\n * ```ts\n * if (is_validation_body(body)) return body.issues;\n * ```\n *\n * @since 2.0.0\n * @param value - Value to inspect.\n * @returns Whether the value contains a form issue list.\n */\nexport function is_validation_body(\n value: unknown,\n): value is { issues: readonly FormIssue[] } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { issues?: unknown }).issues)\n );\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(error: unknown): RemoteFailure<unknown> {\n const body = get_error_body(error);\n const decoded = decode_remote_error(body);\n const status = get_error_status(error);\n\n if (is_decoded_remote_failure(decoded)) {\n return decoded;\n }\n\n if (status === 400 && is_validation_body(body)) {\n return create_remote_validation_error(body.issues, body, status);\n }\n\n if (status !== undefined) {\n return create_remote_http_error(status, body, error);\n }\n\n return create_remote_transport_error(error);\n}\n\nfunction get_error_status(error: unknown): number | undefined {\n if (typeof error !== \"object\" || error === null) {\n return undefined;\n }\n\n const status = (error as { status?: unknown }).status;\n\n return typeof status === \"number\" ? status : undefined;\n}\n\nfunction get_error_body(error: unknown): unknown {\n if (typeof error !== \"object\" || error === null) {\n return undefined;\n }\n\n if (\"body\" in error) {\n return (error as { body?: unknown }).body;\n }\n\n if (\"data\" in error) {\n return (error as { data?: unknown }).data;\n }\n\n return undefined;\n}\n","import {\n create_remote_http_error,\n create_remote_validation_error,\n} from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\n\nimport {\n decode_remote_error,\n is_decoded_remote_failure,\n is_validation_body,\n} 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(\n response: Response,\n): Promise<RemoteFailure<unknown>> {\n const body = await response.json().catch(() => undefined);\n const decoded = decode_remote_error(body);\n\n if (is_decoded_remote_failure(decoded)) {\n return decoded;\n }\n\n if (response.status === 400 && is_validation_body(body)) {\n return create_remote_validation_error(body.issues, body, response.status);\n }\n\n return 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>(\n value: unknown,\n decode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n if (value instanceof Response) {\n if (!value.ok) {\n throw await decode_response_failure(value);\n }\n\n const data = await value.json();\n\n return decode_payload(data) as Output;\n }\n\n return decode_payload(value) as Output;\n}\n","import type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { Effect } from \"effect\";\n\nimport {\n is_decoded_remote_failure,\n normalize_native_error,\n} 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 make_effect_from_promise<Output>(\n run: () => Promise<Output>,\n): Effect.Effect<Output, RemoteFailure<unknown>> {\n return Effect.tryPromise({\n try: run,\n catch: (error: unknown) => {\n if (is_decoded_remote_failure(error)) {\n return error;\n }\n\n return normalize_native_error(error);\n },\n }) as Effect.Effect<Output, RemoteFailure<unknown>>;\n}\n","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 value: unknown,\n key: K,\n): value is Record<K, NativeMethod> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<PropertyKey, unknown>)[key] === \"function\"\n );\n}\n","import type { RemoteFailure } from \"$/remote/shared.ts\";\nimport type { Effect } from \"effect\";\n\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { make_effect_from_promise } from \"./effect.ts\";\nimport { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport type { NativeMethod, Pending } from \"./types.ts\";\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>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n _base = \"\",\n pending?: Pending,\n): (input: Input) => Effect.Effect<Output, RemoteFailure<unknown>> {\n const invoke = has_method(native_factory, \"invoke\")\n ? native_factory.invoke\n : undefined;\n\n if (typeof native_factory !== \"function\" && !invoke) {\n throw new Error(\n \"[INVALID_COMMAND_FACTORY]: Invalid command factory: expected a function\",\n );\n }\n\n const count = pending ?? { value: 0 };\n\n const adapter = (input: Input) =>\n make_effect_from_promise(async () => {\n count.value += 1;\n\n try {\n const result = invoke\n ? await invoke(input)\n : await (native_factory as NativeMethod)(input);\n\n return await decode_response_or_value<Output>(result, decode_payload);\n } finally {\n count.value -= 1;\n }\n });\n\n copy_property_descriptors(native_factory, adapter);\n\n if (!Object.prototype.hasOwnProperty.call(adapter, \"pending\")) {\n Object.defineProperty(adapter, \"pending\", {\n get: () => count.value,\n });\n }\n\n return adapter;\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 const form_data = new FormData();\n\n append_form_value(form_data, \"\", input);\n\n return form_data;\n}\n\nfunction append_form_value(\n form_data: FormData,\n path: string,\n value: unknown,\n): void {\n if (value === undefined) {\n return;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n append_form_value(form_data, `${path}[]`, item);\n }\n\n return;\n }\n\n if (value instanceof Blob) {\n form_data.append(path, value);\n\n return;\n }\n\n if (typeof value === \"object\" && value !== null) {\n for (const [key, child] of Object.entries(value)) {\n const child_path = path.length === 0 ? key : `${path}.${key}`;\n\n append_form_value(form_data, child_path, child);\n }\n\n return;\n }\n\n if (typeof value === \"number\") {\n form_data.append(`n:${path}`, String(value));\n\n return;\n }\n\n if (typeof value === \"boolean\") {\n if (value) {\n form_data.append(`b:${path}`, \"on\");\n }\n\n return;\n }\n\n form_data.append(path, value === null ? \"\" : String(value));\n}\n","import {\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n} from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\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\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 * @returns Decoded form output.\n */\nexport async function submit_remote_form<Output>(\n form_obj: NativeFormRecord,\n input: unknown,\n decode_payload: (value: unknown) => unknown,\n remote_base: string,\n): Promise<Output> {\n const action_id = get_remote_action_id(form_obj);\n\n if (!action_id || remote_base.length === 0) {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_ENDPOINT_MISSING]: Form has no submit method or remote endpoint\",\n ),\n );\n }\n\n const response = await fetch(to_remote_form_url(remote_base, action_id), {\n method: \"POST\",\n body: to_form_data(input),\n });\n\n if (!response.ok) {\n throw await decode_response_failure(response);\n }\n\n const envelope = await response.json();\n\n return 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(\n form_obj: NativeFormRecord,\n): string | undefined {\n const action = form_obj.action;\n\n if (typeof action !== \"string\") {\n return undefined;\n }\n\n const fallback = \"http://localhost/\";\n const href = typeof location === \"undefined\" ? fallback : location.href;\n const url = new URL(action, href);\n\n return url.searchParams.get(\"/remote\") ??\n url.searchParams.get(\"remote\") ??\n undefined;\n}\n\nfunction to_remote_form_url(remote_base: string, action_id: string): string {\n const parts = action_id.split(\"/\");\n const head = parts.slice(0, 2).join(\"/\");\n const tail = parts.slice(2).join(\"/\");\n const normalized_base = remote_base.replace(/\\/$/, \"\");\n\n if (tail.length === 0) {\n return `${normalized_base}/${head}`;\n }\n\n return `${normalized_base}/${head}/${encodeURIComponent(tail)}`;\n}\n\nfunction decode_form_response<Output>(\n envelope: unknown,\n decode_payload: (value: unknown) => unknown,\n): Output {\n if (\n typeof envelope !== \"object\" ||\n envelope === null ||\n !(\"type\" in envelope)\n ) {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_RESPONSE_INVALID]: Invalid remote form response\",\n ),\n envelope,\n );\n }\n\n const response = envelope as {\n type: string;\n result?: unknown;\n error?: unknown;\n status?: number;\n };\n\n if (response.type === \"error\") {\n const decoded = decode_remote_error(response.error);\n\n if (is_decoded_remote_failure(decoded)) {\n throw decoded;\n }\n\n throw create_remote_http_error(\n response.status ?? 500,\n response.error,\n );\n }\n\n if (response.type !== \"result\" || typeof response.result !== \"string\") {\n throw create_remote_transport_error(\n new Error(\n \"[REMOTE_FORM_RESPONSE_UNSUPPORTED]: Unsupported remote form response\",\n ),\n envelope,\n );\n }\n\n const parsed = parse(response.result);\n const decoded = decode_payload(parsed) as {\n issues?: readonly FormIssue[];\n result?: Output;\n };\n\n if (decoded.issues && decoded.issues.length > 0) {\n throw create_remote_validation_error(decoded.issues, decoded, 400);\n }\n\n return decoded.result as Output;\n}\n","import { get_dispatcher } from \"$/dispatcher.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { Effect } from \"effect\";\n\nimport { make_effect_from_promise } from \"./effect.ts\";\nimport { has_method } from \"./utils.ts\";\nimport type { 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(\n callback: NativeMethod | undefined,\n): NativeMethod | undefined {\n if (!callback) {\n return undefined;\n }\n\n return (event: unknown) => {\n const wrapped_event = wrap_submit_callback(event);\n const result = callback(wrapped_event);\n\n if (Effect.isEffect(result)) {\n return get_dispatcher().run(result);\n }\n\n return result;\n };\n}\n\nfunction wrap_submit_callback(event: unknown): unknown {\n if (\n typeof event !== \"object\" || event === null || !has_method(event, \"submit\")\n ) {\n return event;\n }\n\n const original_submit = event.submit;\n const { submit: _submit, ...descriptors } = Object.getOwnPropertyDescriptors(\n event,\n );\n\n void _submit;\n\n return Object.defineProperties({}, {\n ...descriptors,\n submit: {\n configurable: true,\n enumerable: false,\n value: () => make_submit_effect(original_submit),\n },\n });\n}\n\nfunction make_submit_effect(\n original_submit: NativeMethod,\n): Effect.Effect<unknown, RemoteFailure<unknown>> & Record<string, unknown> {\n let updates_args: unknown[] | undefined;\n\n const effect = make_effect_from_promise(async () => {\n const result = original_submit();\n\n if (updates_args && has_method(result, \"updates\")) {\n return await Promise.resolve(result.updates(...updates_args));\n }\n\n return await Promise.resolve(result);\n }) as\n & Effect.Effect<unknown, RemoteFailure<unknown>>\n & Record<string, unknown>;\n\n Object.defineProperty(effect, \"updates\", {\n configurable: true,\n enumerable: false,\n value: (...args: unknown[]) => {\n updates_args ??= args;\n\n return effect;\n },\n });\n\n return effect;\n}\n","import type { RemoteFormInput } from \"@sveltejs/kit\";\n\nimport { decode_response_or_value } from \"./responses.ts\";\nimport { make_effect_from_promise } 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 } from \"./types.ts\";\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 * @returns A callable form function whose properties mirror the native form.\n * @internal\n */\nexport function create_remote_form_adapter<\n Input extends RemoteFormInput | void,\n Output,\n>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n remote_base = \"\",\n): EffectRemoteForm<Input, Output> {\n const form_obj = native_factory as NativeFormRecord;\n\n const submit_effect = (input: Input) =>\n make_effect_from_promise(async () => {\n const can_use_remote_endpoint = remote_base.length > 0 &&\n get_remote_action_id(form_obj) !== undefined;\n\n if (has_method(form_obj, \"submit\") && !can_use_remote_endpoint) {\n const result = await form_obj.submit(input);\n\n return await decode_response_or_value<Output>(result, decode_payload);\n }\n\n return await submit_remote_form<Output>(\n form_obj,\n input,\n decode_payload,\n remote_base,\n );\n });\n\n const callable = ((input: Input) => submit_effect(input)) as EffectRemoteForm<\n Input,\n Output\n >;\n\n copy_property_descriptors(\n form_obj,\n callable,\n new Set([\"submit\", \"validate\", \"enhance\", \"for\", \"preflight\"]),\n );\n\n Object.defineProperty(callable, \"submit\", {\n configurable: true,\n enumerable: false,\n value: submit_effect,\n });\n\n if (has_method(form_obj, \"validate\")) {\n Object.defineProperty(callable, \"validate\", {\n configurable: true,\n enumerable: false,\n value: (options?: Record<string, unknown>) =>\n make_effect_from_promise(async () => {\n await form_obj.validate(options);\n }),\n });\n }\n\n if (has_method(form_obj, \"enhance\")) {\n Object.defineProperty(callable, \"enhance\", {\n configurable: true,\n enumerable: false,\n value: (callback?: Parameters<typeof wrap_enhance_callback>[0]) =>\n form_obj.enhance(wrap_enhance_callback(callback)),\n });\n }\n\n if (has_method(form_obj, \"for\")) {\n Object.defineProperty(callable, \"for\", {\n configurable: true,\n enumerable: false,\n value: (key: string | number | boolean) =>\n create_remote_form_adapter<Input, Output>(\n form_obj.for(key),\n decode_payload,\n remote_base,\n ),\n });\n }\n\n if (has_method(form_obj, \"preflight\")) {\n Object.defineProperty(callable, \"preflight\", {\n configurable: true,\n enumerable: false,\n value: (schema: unknown) => {\n form_obj.preflight(schema);\n\n return callable;\n },\n });\n }\n\n return callable;\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 value: unknown,\n decode_payload: (value: unknown) => unknown,\n): Promise<Output> {\n if (has_method(value, \"then\")) {\n const result = await Promise.resolve(value);\n\n return decode_response_or_value(result, decode_payload);\n }\n\n if (has_method(value, \"run\")) {\n const result = await value.run();\n\n return decode_response_or_value(result, decode_payload);\n }\n\n const result = await Promise.resolve(value);\n\n return decode_response_or_value(result, decode_payload);\n}\n","import { copy_property_descriptors, has_method } from \"./utils.ts\";\nimport { normalize_native_error } from \"./failures.ts\";\nimport { resolve_query_result } from \"./query-result.ts\";\nimport { make_effect_from_promise } from \"./effect.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport type { NativeMethod } from \"./types.ts\";\nimport { Effect } from \"effect\";\n\ntype RemoteResourceEffect<Output> =\n & Effect.Effect<Output, RemoteFailure<unknown>>\n & {\n readonly current: Output | undefined;\n readonly error: unknown;\n readonly loading: boolean;\n readonly ready: boolean;\n };\n\ntype RemoteResourceLike<Output> =\n | RemoteResourceEffect<Output>\n | RemoteLiveQueryResource<Output>;\n\ntype RemoteQueryEffect<Output> =\n & RemoteResourceEffect<Output>\n & {\n readonly refresh: () => Effect.Effect<void, unknown, never>;\n readonly set: (value: Output) => void;\n readonly withOverride: (\n update: (current: Output) => Output,\n ) => unknown;\n };\n\ntype RemoteLiveQueryEffect<Output> = Effect.Effect<\n RemoteLiveQueryResource<Output>,\n RemoteFailure<unknown>\n>;\n\ntype RemoteLiveQueryResource<Output> =\n & {\n readonly connected: boolean;\n readonly current: Output | undefined;\n readonly done: boolean;\n readonly error: unknown;\n readonly loading: boolean;\n readonly ready: boolean;\n readonly reconnect: () => Effect.Effect<void, unknown, never>;\n }\n & AsyncIterable<Output>;\n\ntype NativeRemoteResource<Output> = {\n readonly connected?: boolean;\n readonly current?: Output;\n readonly done?: boolean;\n readonly error?: unknown;\n readonly loading?: boolean;\n readonly ready?: boolean;\n readonly reconnect?: () => Promise<void>;\n readonly refresh?: () => Promise<void>;\n readonly set?: (value: Output) => void;\n readonly withOverride?: (update: (current: Output) => Output) => unknown;\n readonly [Symbol.asyncIterator]?: () => AsyncIterator<Output>;\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>(\n native_factory: unknown,\n decode_payload: (value: unknown) => unknown,\n _base = \"\",\n): (input: Input) => RemoteQueryEffect<Output> {\n const load = has_method(native_factory, \"load\")\n ? native_factory.load\n : undefined;\n const query = typeof native_factory === \"function\"\n ? native_factory as NativeMethod\n : undefined;\n\n if (!query && !load) {\n throw new Error(\n \"[INVALID_QUERY_FACTORY]: Invalid query factory: expected a function\",\n );\n }\n\n const wrapped = ((input: Input) => {\n if (!query) {\n return make_effect_from_promise(async () => {\n const result = await load?.(input);\n\n return await resolve_query_result<Output>(result, decode_payload);\n }) as RemoteQueryEffect<Output>;\n }\n\n const resource = query(input);\n const effect = make_effect_from_promise(async () =>\n await resolve_query_result<Output>(resource, decode_payload)\n ) as RemoteQueryEffect<Output>;\n\n attach_query_resource(resource, effect);\n\n return effect;\n }) as (input: Input) => RemoteQueryEffect<Output>;\n\n copy_property_descriptors(native_factory, wrapped);\n\n return wrapped;\n}\n\n/**\n * Creates a remote live query adapter. The returned function takes input and\n * returns an `Effect` that resolves to a live query resource with stream state\n * and reconnect controls.\n *\n * @example\n * ```ts\n * const getTime = create_remote_live_query_adapter(nativeLive, (value) => value);\n * const time = yield* getTime();\n * const current = time.current;\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 an Effect-backed live query resource.\n * @internal\n */\nexport function create_remote_live_query_adapter<Input, Output>(\n native_factory: unknown,\n _decode_payload: (value: unknown) => unknown,\n _base = \"\",\n): (input: Input) => RemoteLiveQueryEffect<Output> {\n const query = typeof native_factory === \"function\"\n ? native_factory as NativeMethod\n : undefined;\n\n if (!query) {\n throw new Error(\n \"[INVALID_LIVE_QUERY_FACTORY]: Invalid live query factory: expected a function\",\n );\n }\n\n const wrapped = ((input: Input) =>\n Effect.try({\n try: () => {\n const resource = query(input);\n\n return make_live_query_resource<Output>(resource);\n },\n catch: normalize_native_error,\n }) as RemoteLiveQueryEffect<Output>) as (\n input: Input,\n ) => RemoteLiveQueryEffect<Output>;\n\n copy_property_descriptors(native_factory, wrapped);\n\n return wrapped;\n}\n\nfunction is_resource<Output>(\n resource: unknown,\n): resource is NativeRemoteResource<Output> {\n const resource_type = typeof resource;\n\n return (\n (resource_type === \"object\" && resource !== null) ||\n resource_type === \"function\"\n );\n}\n\nfunction attach_resource_getters<Output>(\n resource: unknown,\n effect: RemoteResourceLike<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const keys = [\"current\", \"error\", \"loading\", \"ready\"] as const;\n\n if (!methods) {\n return;\n }\n\n for (const key of keys) {\n if (!(key in methods)) {\n continue;\n }\n\n Object.defineProperty(effect, key, {\n configurable: true,\n get: () => methods[key],\n });\n }\n}\n\nfunction attach_query_resource<Output>(\n resource: unknown,\n effect: RemoteQueryEffect<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const refresh = methods?.refresh;\n const set = methods?.set;\n const with_override = methods?.withOverride;\n\n attach_resource_getters(resource, effect);\n\n if (!methods) {\n return;\n }\n\n if (typeof refresh === \"function\") {\n Object.defineProperty(effect, \"refresh\", {\n configurable: true,\n value: () =>\n make_effect_from_promise(() => Promise.resolve(refresh.call(resource))),\n });\n }\n\n if (typeof set === \"function\") {\n Object.defineProperty(effect, \"set\", {\n configurable: true,\n value: (value: Output) => set.call(resource, value),\n });\n }\n\n if (typeof with_override === \"function\") {\n Object.defineProperty(effect, \"withOverride\", {\n configurable: true,\n value: (update: (current: Output) => Output) =>\n with_override.call(resource, update),\n });\n }\n}\n\nfunction attach_live_query_resource<Output>(\n resource: unknown,\n effect: RemoteLiveQueryResource<Output>,\n): void {\n const methods = is_resource<Output>(resource) ? resource : undefined;\n const async_iterator = methods?.[Symbol.asyncIterator];\n const reconnect = methods?.reconnect;\n const keys = [\"connected\", \"done\"] as const;\n\n attach_resource_getters(resource, effect);\n\n if (!methods) {\n return;\n }\n\n for (const key of keys) {\n if (!(key in methods)) {\n continue;\n }\n\n Object.defineProperty(effect, key, {\n configurable: true,\n get: () => methods[key],\n });\n }\n\n if (typeof reconnect === \"function\") {\n Object.defineProperty(effect, \"reconnect\", {\n configurable: true,\n value: () =>\n make_effect_from_promise(() =>\n Promise.resolve(reconnect.call(resource))\n ),\n });\n }\n\n if (typeof async_iterator === \"function\") {\n Object.defineProperty(effect, Symbol.asyncIterator, {\n configurable: true,\n value: () => async_iterator.call(resource),\n });\n }\n}\n\nfunction make_live_query_resource<Output>(\n resource: unknown,\n): RemoteLiveQueryResource<Output> {\n const live_resource = {} as RemoteLiveQueryResource<Output>;\n\n attach_live_query_resource(resource, live_resource);\n\n return live_resource;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBACd,KACA,QACkC;CAClC,MAAM,WAAW,8BAA8B,GAAG;CAElD,IAAI,aAAa,KACf,OAAO,oBAAoB,UAAU,MAAM;CAG7C,IAAI,sCAAsC,GAAG,GAC3C,IAAI;EAGF,OAFgB,SAAS,OAAO,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO;CAGlE,QAAQ;EACN,OAAO,8CACL,IAAI,MACF,qEACF,GACA,GACF;CACF;CAGF,OAAO;AACT;AAEA,SAAS,8BAA8B,KAAuB;CAC5D,IAAI,OAAO,QAAQ,UACjB,OAAO,uBAAuB,GAAG;CAGnC,IAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,aAAa,MAC5D,OAAO;CAGT,MAAM,UAAW,IAA8B;CAE/C,IAAI,OAAO,YAAY,UACrB,OAAO;CAGT,MAAM,SAAS,uBAAuB,OAAO;CAE7C,OAAO,WAAW,UAAU,MAAM;AACpC;AAEA,SAAS,uBAAuB,OAAwB;CACtD,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;;AAcA,SAAgB,0BACd,OACiC;CACjC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU;AAEd;;;;;;;;;;;;;AAcA,SAAgB,mBACd,OAC2C;CAC3C,OACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,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