svelte-effect-runtime 1.3.2 → 1.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-DkW4e4dD.js → client-vV6UAwoP.js} +3 -3
- package/dist/chunks/client-vV6UAwoP.js.map +1 -0
- package/dist/chunks/{effect-CL8GJs8A.js → effect-Cx8OzrcW.js} +3 -3
- package/dist/chunks/{effect-CL8GJs8A.js.map → effect-Cx8OzrcW.js.map} +1 -1
- package/dist/chunks/effect-compat-BhW0YPIs.js.map +1 -1
- package/dist/chunks/{markup-BpSHnnYD.js → markup-BMn2sQOB.js} +3 -1
- package/dist/chunks/{markup-BpSHnnYD.js.map → markup-BMn2sQOB.js.map} +1 -1
- package/dist/chunks/{preprocess-CtLrnJcK.js → preprocess-CGKEA3Py.js} +13 -8
- package/dist/chunks/preprocess-CGKEA3Py.js.map +1 -0
- package/dist/chunks/{server-CQcF2W3T.js → server-7YVuxUNk.js} +53 -2
- package/dist/chunks/server-7YVuxUNk.js.map +1 -0
- package/dist/chunks/v3-D0c0MKPf.js +1 -0
- package/dist/chunks/v4-MMhHmzIG.js +1 -0
- package/dist/chunks/{vite-DqjXRZd4.js → vite-C8ujN78r.js} +14 -5
- package/dist/chunks/vite-C8ujN78r.js.map +1 -0
- package/dist/client.js +1 -1
- package/dist/effect.js +1 -1
- package/dist/internal/markup.js +1 -1
- package/dist/internal/remote-client.js +3 -3
- package/dist/internal/remote-client.js.map +1 -1
- package/dist/internal/remote-shared.d.ts +134 -1
- package/dist/internal/remote-shared.js +64 -0
- package/dist/internal/remote-shared.js.map +1 -1
- package/dist/internal/transform.d.ts +7 -0
- package/dist/internal/transform.js +172 -15
- package/dist/internal/transform.js.map +1 -1
- package/dist/language-server.js +1 -1
- package/dist/mod.d.ts +21 -0
- package/dist/mod.js +2 -2
- package/dist/preprocess.d.ts +5 -0
- package/dist/preprocess.js +7 -2
- package/dist/preprocess.js.map +1 -1
- package/dist/root-node.js +4 -4
- package/dist/root-node.js.map +1 -1
- package/dist/server.d.ts +25 -0
- package/dist/server.js +26 -1
- package/dist/server.js.map +1 -1
- package/dist/v3/client.d.ts +24 -0
- package/dist/v3/mod.d.ts +24 -0
- package/dist/v3/server.d.ts +106 -0
- package/dist/v4/effect.js +1 -1
- package/dist/v4/mod.d.ts +24 -0
- package/dist/v4/mod.js +2 -2
- package/dist/v4/preprocess.d.ts +4 -0
- package/dist/v4/preprocess.js +6 -2
- package/dist/v4/preprocess.js.map +1 -1
- package/dist/v4/root-node.js +2 -2
- package/dist/v4/server.d.ts +196 -0
- package/dist/v4/server.js +50 -1
- package/dist/v4/server.js.map +1 -1
- package/dist/v4/vite.js +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/client-DkW4e4dD.js.map +0 -1
- package/dist/chunks/preprocess-CtLrnJcK.js.map +0 -1
- package/dist/chunks/server-CQcF2W3T.js.map +0 -1
- package/dist/chunks/v3-p8V3Drpp.js +0 -1
- package/dist/chunks/v4-DIhYCbb_.js +0 -1
- package/dist/chunks/vite-DqjXRZd4.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-client.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-client.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { tick } from \"svelte\";\nimport { create_remote_effect_from_promise } from \"$/client.ts\";\nimport { create_async_effect } from \"$internal/effect-compat.ts\";\nimport {\n create_remote_domain_error,\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n type FormIssue,\n is_remote_validation_issue,\n is_serialized_remote_failure_envelope,\n REMOTE_ERROR_DECODER,\n type RemoteFailure,\n} from \"$internal/remote-shared.ts\";\n\ntype AnyCallable = (...args: Array<unknown>) => unknown;\n\ntype Decode_remote_payload = <ErrorType = unknown>(\n encoded: string,\n) => ErrorType;\n\ninterface HttpErrorLike {\n readonly body?: unknown;\n readonly status?: number;\n}\n\ninterface RedirectLike {\n readonly location: string;\n readonly status: number;\n}\n\ninterface Remote_request_dependencies {\n readonly app?: {\n readonly decoders?: Record<string, unknown>;\n readonly hooks?: {\n readonly transport?: Record<string, unknown>;\n };\n };\n readonly app_dir: string;\n readonly apply_refreshes?: (value: string) => void;\n readonly base: string;\n readonly get_remote_request_headers: () => HeadersInit;\n readonly remote_request: (\n url: string,\n headers: HeadersInit,\n ) => Promise<string>;\n readonly stringify_remote_arg: (\n value: unknown,\n transport: unknown,\n sort?: boolean,\n ) => string;\n}\n\ntype Query_adapter_mode = \"query\" | \"query_batch\" | \"prerender\";\n\ntype Form_request_dependencies = Remote_request_dependencies & {\n readonly app: {\n readonly decoders?: Record<string, unknown>;\n readonly encoders?: Record<string, unknown>;\n };\n readonly app_dir: string;\n readonly apply_refreshes: (value: string) => void;\n readonly base: string;\n readonly binary_form_content_type: string;\n readonly goto: (url: string, options?: unknown, code?: number) => void;\n readonly invalidate_all: () => Promise<void> | void;\n readonly serialize_binary_form: (\n data: unknown,\n meta: Record<string, unknown>,\n ) => {\n readonly blob: Blob;\n };\n};\n\ninterface Attached_form_tracker {\n current: HTMLFormElement | null;\n}\n\nfunction is_development_environment(): boolean {\n const vite_environment = (\n import.meta as ImportMeta & {\n env?: {\n DEV?: boolean;\n };\n }\n ).env;\n\n if (typeof vite_environment?.DEV === \"boolean\") {\n return vite_environment.DEV;\n }\n\n const node_process = (globalThis as typeof globalThis & {\n process?: {\n env?: {\n DEV?: string;\n NODE_ENV?: string;\n SVELTE_EFFECT_RUNTIME_DEBUG?: string;\n };\n };\n }).process;\n\n return (\n node_process?.env?.SVELTE_EFFECT_RUNTIME_DEBUG === \"1\" ||\n node_process?.env?.DEV === \"1\" ||\n node_process?.env?.NODE_ENV === \"development\"\n );\n}\n\nconst ENABLE_REMOTE_CLIENT_DEBUG_LOGS = is_development_environment();\n\nfunction log_remote_client_step(\n step: string,\n details?: Record<string, unknown>,\n): void {\n if (!ENABLE_REMOTE_CLIENT_DEBUG_LOGS) {\n return;\n }\n\n console.log(\"[svelte-effect-runtime][remote-client]\", step, details ?? {});\n}\n\nfunction define_hidden_property<Value extends object, Property>(\n value: Value,\n key: string | symbol,\n property: Property,\n): Value {\n Object.defineProperty(value, key, {\n value: property,\n enumerable: false,\n });\n\n return value;\n}\n\nfunction define_remote_error_decoder<Value extends object>(\n value: Value,\n decode_payload: Decode_remote_payload,\n): Value {\n return define_hidden_property(value, REMOTE_ERROR_DECODER, decode_payload);\n}\n\nfunction is_http_error_like(value: unknown): value is HttpErrorLike {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction is_redirect_like(value: unknown): value is RedirectLike {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { location?: unknown }).location === \"string\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction get_error_status(value: unknown): number {\n return is_http_error_like(value) ? value.status ?? 500 : 500;\n}\n\nfunction decode_remote_error<ErrorType>(\n error: unknown,\n decode_payload: Decode_remote_payload,\n): RemoteFailure<ErrorType> {\n log_remote_client_step(\"decode_remote_error:start\", {\n error,\n });\n\n if (is_http_error_like(error)) {\n const body = error.body;\n\n if (is_serialized_remote_failure_envelope(body)) {\n try {\n return create_remote_domain_error<ErrorType>(\n decode_payload<ErrorType>(body.encoded),\n get_error_status(error),\n );\n } catch (cause) {\n return create_remote_transport_error(cause, body);\n }\n }\n\n if (get_error_status(error) === 400) {\n return create_remote_validation_error([], {\n body,\n status: 400,\n });\n }\n\n return create_remote_http_error(error, {\n body,\n status: get_error_status(error),\n });\n }\n\n const decoded = create_remote_http_error(error);\n log_remote_client_step(\"decode_remote_error:http_error\", {\n decoded,\n });\n return decoded;\n}\n\nfunction create_effect_call<Success, ErrorType>(\n create_promise: () => PromiseLike<Success>,\n decode_payload: Decode_remote_payload,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return create_remote_effect_from_promise<Success, ErrorType>(\n () => {\n log_remote_client_step(\"create_effect_call:start\");\n return create_promise();\n },\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n );\n}\n\nfunction create_decoded_native_callable(\n native: AnyCallable,\n decode_payload: Decode_remote_payload,\n): AnyCallable {\n const wrapped = ((...args: Array<unknown>) => {\n const result = native(...args);\n\n if (\n result && (typeof result === \"object\" || typeof result === \"function\")\n ) {\n define_remote_error_decoder(result as object, decode_payload);\n }\n\n return result;\n }) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native);\n define_remote_error_decoder(wrapped as object, decode_payload);\n\n return wrapped;\n}\n\nfunction get_transport(\n dependencies?: Remote_request_dependencies,\n): Record<string, unknown> {\n return dependencies?.app?.hooks?.transport ?? {};\n}\n\nfunction stringify_remote_payload(\n arg: unknown,\n dependencies: Remote_request_dependencies,\n sort = true,\n): string {\n if (arg === undefined) {\n return \"\";\n }\n\n return dependencies.stringify_remote_arg(\n arg,\n get_transport(dependencies),\n sort,\n );\n}\n\nasync function execute_query_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const url = `${dependencies.base}/${dependencies.app_dir}/remote/${id}${\n payload ? `?payload=${payload}` : \"\"\n }`;\n const encoded = await dependencies.remote_request(\n url,\n dependencies.get_remote_request_headers(),\n );\n\n return decode_payload<Success>(encoded);\n}\n\nasync function execute_query_batch_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const response = await fetch(\n `${dependencies.base}/${dependencies.app_dir}/remote/${id}`,\n {\n method: \"POST\",\n body: JSON.stringify({\n payloads: [payload],\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n ...dependencies.get_remote_request_headers(),\n },\n },\n );\n\n if (!response.ok) {\n throw new Error(\"Failed to execute batch query\");\n }\n\n const result = await response.json() as {\n readonly type: string;\n readonly result?: string;\n readonly status?: number;\n readonly error?: unknown;\n readonly location?: string;\n };\n\n if (result.type === \"error\") {\n throw {\n body: result.error,\n status: result.status ?? 500,\n };\n }\n\n if (result.type === \"redirect\") {\n throw {\n location: result.location,\n status: 307,\n };\n }\n\n const entries = decode_payload<\n Array<{\n readonly data?: Success;\n readonly error?: unknown;\n readonly status?: number;\n readonly type: string;\n }>\n >(result.result ?? \"\");\n const first = entries[0];\n\n if (!first) {\n throw new Error(\"Batch query returned no entries.\");\n }\n\n if (first.type === \"error\") {\n throw {\n body: first.error,\n status: first.status ?? 500,\n };\n }\n\n return first.data as Success;\n}\n\nasync function execute_prerender_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const url = `${dependencies.base}/${dependencies.app_dir}/remote/${id}${\n payload ? `/${payload}` : \"\"\n }`;\n const encoded = await dependencies.remote_request(\n url,\n dependencies.get_remote_request_headers(),\n );\n\n return decode_payload<Success>(encoded);\n}\n\nfunction create_query_request<Success>(\n mode: Query_adapter_mode,\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n native_with_decoder?: AnyCallable,\n): Promise<Success> {\n if (!dependencies || !native_with_decoder) {\n return Promise.resolve(native_with_decoder?.(arg) as Success);\n }\n\n switch (mode) {\n case \"query\":\n return execute_query_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n case \"query_batch\":\n return execute_query_batch_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n case \"prerender\":\n return execute_prerender_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n }\n}\n\nasync function execute_command_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const response = await fetch(\n `${dependencies.base}/${dependencies.app_dir}/remote/${id}`,\n {\n method: \"POST\",\n body: JSON.stringify({\n payload: stringify_remote_payload(arg, dependencies, false),\n refreshes: [],\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n ...dependencies.get_remote_request_headers(),\n },\n },\n );\n\n if (!response.ok) {\n throw new Error(\"Failed to execute remote command\");\n }\n\n const result = await response.json() as {\n readonly type: string;\n readonly result?: string;\n readonly status?: number;\n readonly error?: unknown;\n readonly refreshes?: string;\n };\n\n if (result.type === \"error\") {\n throw {\n body: result.error,\n status: result.status ?? 500,\n };\n }\n\n if (result.type === \"redirect\") {\n throw new Error(\n \"Redirects are not allowed in commands. Return a result instead and use goto on the client.\",\n );\n }\n\n if (result.refreshes) {\n dependencies.apply_refreshes?.(result.refreshes);\n }\n\n return decode_payload<Success>(result.result ?? \"\");\n}\n\nexport function create_remote_query_adapter(\n native_query_factory: (id: string) => AnyCallable,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n mode: Query_adapter_mode = \"query\",\n) {\n return (id: string) => {\n const native = native_query_factory(id);\n const native_with_decoder = create_decoded_native_callable(\n native,\n decode_payload,\n );\n const wrapped = ((arg?: unknown) =>\n create_effect_call(\n () =>\n create_query_request(\n mode,\n id,\n arg,\n decode_payload,\n dependencies,\n native_with_decoder,\n ),\n decode_payload,\n )) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native_with_decoder);\n\n return wrapped;\n };\n}\n\nexport function create_remote_command_adapter(\n native_command_factory: (id: string) => AnyCallable,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n) {\n return (id: string) => {\n const native = native_command_factory(id);\n const native_with_decoder = create_decoded_native_callable(\n native,\n decode_payload,\n );\n let local_pending = 0;\n const wrapped = ((arg?: unknown) =>\n create_effect_call(\n async () => {\n local_pending += 1;\n\n try {\n if (!dependencies) {\n return await Promise.resolve(native_with_decoder(arg));\n }\n\n return await execute_command_request(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n } finally {\n local_pending -= 1;\n }\n },\n decode_payload,\n )) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native_with_decoder);\n Object.defineProperty(wrapped, \"pending\", {\n get: () =>\n ((native as { pending?: number }).pending ?? 0) + local_pending,\n });\n\n return wrapped;\n };\n}\n\nfunction normalize_form_issues(issues: unknown): ReadonlyArray<FormIssue> {\n if (!Array.isArray(issues)) {\n return [];\n }\n\n return issues.flatMap((issue) =>\n is_remote_validation_issue(issue)\n ? [{\n message: issue.message,\n path: [...issue.path],\n }]\n : []\n );\n}\n\nfunction get_root_form_issues(\n native: {\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n },\n): ReadonlyArray<FormIssue> {\n return normalize_form_issues(native.fields?.allIssues);\n}\n\nfunction get_attachment(\n value: Record<string | symbol, unknown>,\n): (form: HTMLFormElement) => void | (() => void) {\n for (const symbol of Object.getOwnPropertySymbols(value)) {\n const candidate = value[symbol];\n\n if (typeof candidate === \"function\") {\n return candidate as (form: HTMLFormElement) => void | (() => void);\n }\n }\n\n throw new Error(\n \"Failed to find the Svelte attachment for the remote form enhancement.\",\n );\n}\n\nfunction build_form_field_name(path: ReadonlyArray<string | number>): string {\n let name = \"\";\n\n for (const segment of path) {\n if (typeof segment === \"number\") {\n name += `[${segment}]`;\n continue;\n }\n\n name += name === \"\" ? segment : `.${segment}`;\n }\n\n return name;\n}\n\nfunction append_hidden_input(\n form: HTMLFormElement,\n name: string,\n value: string,\n): void {\n const input = document.createElement(\"input\");\n input.type = \"hidden\";\n input.name = name;\n input.value = value;\n form.append(input);\n}\n\nfunction append_file_input(\n form: HTMLFormElement,\n name: string,\n value: File,\n): void {\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.name = name;\n\n if (typeof DataTransfer === \"function\") {\n const transfer = new DataTransfer();\n transfer.items.add(value);\n\n try {\n input.files = transfer.files;\n } catch {\n // ignore and fall back below\n }\n }\n\n if (input.files?.length) {\n form.append(input);\n return;\n }\n\n append_hidden_input(form, name, value.name);\n}\n\nfunction append_form_value(\n form: HTMLFormElement,\n value: unknown,\n path: ReadonlyArray<string | number>,\n): void {\n if (value === undefined) {\n return;\n }\n\n if (value instanceof File) {\n append_file_input(form, build_form_field_name(path), value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((entry, index) => {\n append_form_value(form, entry, [...path, index]);\n });\n return;\n }\n\n if (value && typeof value === \"object\") {\n for (\n const [key, entry] of Object.entries(value as Record<string, unknown>)\n ) {\n append_form_value(form, entry, [...path, key]);\n }\n return;\n }\n\n const base_name = build_form_field_name(path);\n\n if (typeof value === \"number\") {\n append_hidden_input(form, `n:${base_name}`, String(value));\n return;\n }\n\n if (typeof value === \"boolean\") {\n append_hidden_input(form, `b:${base_name}`, value ? \"on\" : \"\");\n return;\n }\n\n append_hidden_input(\n form,\n base_name,\n value === null ? \"\" : String(value),\n );\n}\n\nfunction apply_input_to_fields(fields: unknown, input: unknown): void {\n if (!fields || typeof fields !== \"object\") {\n return;\n }\n\n const maybe_field = fields as {\n readonly set?: (value: unknown) => void;\n };\n\n if (typeof maybe_field.set === \"function\") {\n maybe_field.set(input);\n return;\n }\n\n if (!input || typeof input !== \"object\") {\n return;\n }\n\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n apply_input_to_fields(\n (fields as Record<string, unknown>)[key],\n value,\n );\n }\n}\n\ntype Submitter_like = {\n click(): void;\n} & Record<string, unknown>;\n\nfunction is_submitter_like(value: unknown): value is Submitter_like {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { click?: unknown }).click === \"function\",\n );\n}\n\nfunction get_submitter(\n form: HTMLFormElement,\n): Submitter_like | undefined {\n const submitter = form.querySelector(\"button:not([type]), [type='submit']\");\n return is_submitter_like(submitter) ? submitter : undefined;\n}\n\nfunction request_form_submit(form: HTMLFormElement): void {\n const submitter = get_submitter(form);\n log_remote_client_step(\"request_form_submit\", {\n action: form.action,\n has_submitter: Boolean(submitter),\n submitter,\n });\n\n if (typeof SubmitEvent === \"function\") {\n form.dispatchEvent(\n new SubmitEvent(\"submit\", {\n bubbles: true,\n cancelable: true,\n submitter: submitter as HTMLElement | null | undefined,\n }),\n );\n return;\n }\n\n const event = new Event(\"submit\", {\n bubbles: true,\n cancelable: true,\n }) as Event & {\n readonly submitter?: Submitter_like;\n };\n Object.defineProperty(event, \"submitter\", {\n configurable: true,\n value: submitter,\n });\n form.dispatchEvent(event);\n}\n\nasync function wait_for_pending_settle(\n native: {\n readonly pending?: number;\n },\n): Promise<void> {\n await tick();\n\n while ((native.pending ?? 0) > 0) {\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n\n await tick();\n}\n\nasync function submit_attached_form<Success, ErrorType>(\n form: {\n readonly native: {\n readonly fields?: {\n readonly allIssues?: unknown;\n } & Record<string, unknown>;\n readonly pending?: number;\n readonly result?: Success;\n };\n },\n element: HTMLFormElement,\n input: unknown,\n): Promise<Effect.Effect<Success, RemoteFailure<ErrorType>, never>> {\n log_remote_client_step(\"submit_attached_form:start\", {\n action: element.action,\n input,\n });\n\n if (input !== undefined) {\n apply_input_to_fields(form.native.fields, input);\n }\n\n await tick();\n request_form_submit(element);\n await wait_for_pending_settle(form.native);\n\n const issues = get_root_form_issues(form.native);\n log_remote_client_step(\"submit_attached_form:after_submit\", {\n issues,\n pending: form.native.pending ?? 0,\n result: form.native.result,\n });\n\n if (issues.length > 0) {\n return Effect.fail(\n create_remote_validation_error(issues, {\n body: issues,\n status: 400,\n }),\n );\n }\n\n return Effect.succeed(form.native.result as Success);\n}\n\nfunction create_form_submit_effect<Success, ErrorType>(\n form: {\n readonly native: {\n readonly action: string;\n readonly result?: Success;\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n enhance(\n callback: (args: {\n readonly form: HTMLFormElement;\n readonly data: unknown;\n readonly submit: () => Promise<unknown>;\n }) => Promise<void> | void,\n ): Record<string | symbol, unknown>;\n };\n },\n input: unknown,\n decode_payload: Decode_remote_payload,\n attached_form_tracker: Attached_form_tracker,\n _dependencies: Form_request_dependencies,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return create_async_effect<Success, RemoteFailure<ErrorType>>((resume) => {\n log_remote_client_step(\"create_form_submit_effect:start\", {\n action: form.native.action,\n input,\n attached: Boolean(attached_form_tracker.current),\n });\n\n if (typeof document === \"undefined\") {\n resume(\n Effect.fail(\n create_remote_http_error(\n new Error(\"Programmatic remote form submission requires a DOM.\"),\n ),\n ),\n );\n return;\n }\n\n let settled = false;\n let dispose_attachment: void | (() => void);\n const temp_form = document.createElement(\"form\");\n temp_form.method = \"POST\";\n temp_form.action = form.native.action;\n temp_form.hidden = true;\n document.body.append(temp_form);\n\n const cleanup = () => {\n if (typeof dispose_attachment === \"function\") {\n dispose_attachment();\n }\n\n temp_form.remove();\n };\n\n const finish = (\n effect: Effect.Effect<Success, RemoteFailure<ErrorType>, never>,\n ) => {\n if (settled) {\n return;\n }\n\n settled = true;\n cleanup();\n resume(effect);\n };\n\n try {\n const attached_form = attached_form_tracker.current;\n\n if (attached_form) {\n log_remote_client_step(\n \"create_form_submit_effect:attached_form_branch\",\n {\n action: attached_form.action,\n },\n );\n void submit_attached_form<Success, ErrorType>(\n form,\n attached_form,\n input,\n ).then(finish, (error) => {\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n });\n return;\n }\n\n log_remote_client_step(\n \"create_form_submit_effect:detached_fallback_branch\",\n {\n action: form.native.action,\n },\n );\n const enhanced = form.native.enhance(async ({ submit }) => {\n try {\n log_remote_client_step(\n \"create_form_submit_effect:fallback_submit:start\",\n {\n action: form.native.action,\n },\n );\n await submit();\n const issues = get_root_form_issues(form.native);\n log_remote_client_step(\n \"create_form_submit_effect:fallback_submit:after\",\n {\n issues,\n result: form.native.result,\n },\n );\n\n if (issues.length > 0) {\n finish(\n Effect.fail(\n create_remote_validation_error(issues, {\n body: issues,\n status: 400,\n }),\n ),\n );\n return;\n }\n\n finish(Effect.succeed(form.native.result as Success));\n } catch (error) {\n if (is_redirect_like(error)) {\n finish(Effect.die(error));\n return;\n }\n\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n }\n });\n\n dispose_attachment = get_attachment(enhanced)(temp_form);\n\n if (input && typeof input === \"object\") {\n append_form_value(temp_form, input, []);\n }\n\n const submitter = document.createElement(\"button\");\n submitter.type = \"submit\";\n temp_form.append(submitter);\n if (typeof temp_form.requestSubmit === \"function\") {\n temp_form.requestSubmit(submitter);\n } else {\n submitter.click();\n }\n } catch (error) {\n log_remote_client_step(\"create_form_submit_effect:error\", {\n error,\n });\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n }\n });\n}\n\nfunction wrap_native_form(\n native: Record<string, unknown>,\n decode_payload: Decode_remote_payload,\n dependencies: Form_request_dependencies,\n) {\n const attached_form_tracker: Attached_form_tracker = {\n current: null,\n };\n const wrapped_symbol_properties = new Map<symbol, unknown>();\n const proxy_target: Record<string, unknown> = {};\n Object.defineProperty(proxy_target, \"native\", {\n configurable: true,\n enumerable: false,\n value: native,\n writable: false,\n });\n const wrapped = new Proxy(proxy_target, {\n get(_target, property, receiver) {\n if (property === \"native\") {\n return native;\n }\n\n if (property === \"submit\") {\n return (input: unknown) =>\n create_form_submit_effect(\n receiver as {\n readonly native: {\n readonly action: string;\n readonly result?: unknown;\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n enhance(\n callback: (args: {\n readonly form: HTMLFormElement;\n readonly data: unknown;\n readonly submit: () => Promise<unknown>;\n }) => Promise<void> | void,\n ): Record<string | symbol, unknown>;\n };\n },\n input,\n decode_payload,\n attached_form_tracker,\n dependencies,\n );\n }\n\n if (typeof property === \"symbol\") {\n if (wrapped_symbol_properties.has(property)) {\n return wrapped_symbol_properties.get(property);\n }\n\n const native_value = Reflect.get(native, property, native);\n\n if (typeof native_value === \"function\") {\n const wrapped_attachment = (element: HTMLFormElement) => {\n log_remote_client_step(\"wrap_native_form:attach\", {\n action: element.action,\n native_action: (native as { action?: unknown }).action,\n });\n attached_form_tracker.current = element;\n const cleanup = native_value.call(native, element);\n\n return () => {\n log_remote_client_step(\"wrap_native_form:detach\", {\n action: element.action,\n });\n if (attached_form_tracker.current === element) {\n attached_form_tracker.current = null;\n }\n\n if (typeof cleanup === \"function\") {\n cleanup();\n }\n };\n };\n\n wrapped_symbol_properties.set(property, wrapped_attachment);\n return wrapped_attachment;\n }\n }\n\n if (property === \"for\") {\n const native_for = Reflect.get(native, property, native);\n\n if (typeof native_for === \"function\") {\n return (key: string | number) =>\n wrap_native_form(\n native_for.call(native, key) as Record<string, unknown>,\n decode_payload,\n dependencies,\n );\n }\n }\n\n return Reflect.get(native, property, native);\n },\n has(_target, property) {\n if (\n property === \"native\" ||\n property === \"submit\" ||\n property === \"for\"\n ) {\n return true;\n }\n\n return Reflect.has(native, property);\n },\n ownKeys() {\n return Array.from(\n new Set([\n ...Reflect.ownKeys(native),\n \"native\",\n \"submit\",\n \"for\",\n ...wrapped_symbol_properties.keys(),\n ]),\n );\n },\n getOwnPropertyDescriptor(\n _target,\n property,\n ): PropertyDescriptor | undefined {\n if (property === \"native\") {\n return Reflect.getOwnPropertyDescriptor(proxy_target, property);\n }\n\n if (property === \"submit\" || property === \"for\") {\n return {\n configurable: true,\n enumerable: false,\n writable: false,\n };\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(native, property);\n\n if (!descriptor) {\n return descriptor;\n }\n\n return {\n ...descriptor,\n configurable: true,\n };\n },\n });\n\n return wrapped as Record<string, unknown>;\n}\n\nexport function create_remote_form_adapter(\n native_form_factory: (id: string) => Record<string, unknown>,\n decode_payload: Decode_remote_payload,\n dependencies: Form_request_dependencies,\n) {\n return (id: string) => {\n const native = native_form_factory(id);\n return wrap_native_form(native, decode_payload, dependencies);\n };\n}\n"],"mappings":";;;;;;;AA+EA,SAAS,6BAAsC;CAC7C,MAAM,mBACJ,OAAO,KAKP;AAEF,KAAI,OAAO,kBAAkB,QAAQ,UACnC,QAAO,iBAAiB;CAG1B,MAAM,eAAgB,WAQnB;AAEH,QACE,cAAc,KAAK,gCAA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,aAAa,YACb,aAAa,MAEb,QAAO;AAGT,UAAO,QAAQ,IAAI,QAAQ,SAAS;;EAEtC,UAAU;AACR,UAAO,MAAM,KACX,IAAI,IAAI;IACN,GAAG,QAAQ,QAAQ,OAAO;IAC1B;IACA;IACA;IACA,GAAG,0BAA0B,MAAM;IACpC,CAAC,CACH;;EAEH,yBACE,SACA,UACgC;AAChC,OAAI,aAAa,SACf,QAAO,QAAQ,yBAAyB,cAAc,SAAS;AAGjE,OAAI,aAAa,YAAY,aAAa,MACxC,QAAO;IACL,cAAc;IACd,YAAY;IACZ,UAAU;IACX;GAGH,MAAM,aAAa,QAAQ,yBAAyB,QAAQ,SAAS;AAErE,OAAI,CAAC,WACH,QAAO;AAGT,UAAO;IACL,GAAG;IACH,cAAc;IACf;;EAEJ,CAAC;;AAKJ,SAAgB,2BACd,qBACA,gBACA,cACA;AACA,SAAQ,OAAe;AAErB,SAAO,iBADQ,oBAAoB,GAAG,EACN,gBAAgB,aAAa"}
|
|
1
|
+
{"version":3,"file":"remote-client.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-client.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { tick } from \"svelte\";\nimport { create_remote_effect_from_promise } from \"$/client.ts\";\nimport { create_async_effect } from \"$internal/effect-compat.ts\";\nimport {\n create_remote_http_error,\n create_remote_transport_error,\n create_remote_validation_error,\n type FormIssue,\n is_remote_validation_issue,\n is_serialized_remote_failure_envelope,\n REMOTE_ERROR_DECODER,\n type RemoteFailure,\n} from \"$internal/remote-shared.ts\";\n\ntype AnyCallable = (...args: Array<unknown>) => unknown;\n\ntype Decode_remote_payload = <ErrorType = unknown>(\n encoded: string,\n) => ErrorType;\n\ninterface HttpErrorLike {\n readonly body?: unknown;\n readonly status?: number;\n}\n\ninterface RedirectLike {\n readonly location: string;\n readonly status: number;\n}\n\ninterface Remote_request_dependencies {\n readonly app?: {\n readonly decoders?: Record<string, unknown>;\n readonly hooks?: {\n readonly transport?: Record<string, unknown>;\n };\n };\n readonly app_dir: string;\n readonly apply_refreshes?: (value: string) => void;\n readonly base: string;\n readonly get_remote_request_headers: () => HeadersInit;\n readonly remote_request: (\n url: string,\n headers: HeadersInit,\n ) => Promise<string>;\n readonly stringify_remote_arg: (\n value: unknown,\n transport: unknown,\n sort?: boolean,\n ) => string;\n}\n\ntype Query_adapter_mode = \"query\" | \"query_batch\" | \"prerender\";\n\ntype Form_request_dependencies = Remote_request_dependencies & {\n readonly app: {\n readonly decoders?: Record<string, unknown>;\n readonly encoders?: Record<string, unknown>;\n };\n readonly app_dir: string;\n readonly apply_refreshes: (value: string) => void;\n readonly base: string;\n readonly binary_form_content_type: string;\n readonly goto: (url: string, options?: unknown, code?: number) => void;\n readonly invalidate_all: () => Promise<void> | void;\n readonly serialize_binary_form: (\n data: unknown,\n meta: Record<string, unknown>,\n ) => {\n readonly blob: Blob;\n };\n};\n\ninterface Attached_form_tracker {\n current: HTMLFormElement | null;\n}\n\nfunction is_development_environment(): boolean {\n const vite_environment = (\n import.meta as ImportMeta & {\n env?: {\n DEV?: boolean;\n };\n }\n ).env;\n\n if (typeof vite_environment?.DEV === \"boolean\") {\n return vite_environment.DEV;\n }\n\n const node_process = (globalThis as typeof globalThis & {\n process?: {\n env?: {\n DEV?: string;\n NODE_ENV?: string;\n SVELTE_EFFECT_RUNTIME_DEBUG?: string;\n };\n };\n }).process;\n\n return (\n node_process?.env?.SVELTE_EFFECT_RUNTIME_DEBUG === \"1\" ||\n node_process?.env?.DEV === \"1\" ||\n node_process?.env?.NODE_ENV === \"development\"\n );\n}\n\nconst ENABLE_REMOTE_CLIENT_DEBUG_LOGS = is_development_environment();\n\nfunction log_remote_client_step(\n step: string,\n details?: Record<string, unknown>,\n): void {\n if (!ENABLE_REMOTE_CLIENT_DEBUG_LOGS) {\n return;\n }\n\n console.log(\"[svelte-effect-runtime][remote-client]\", step, details ?? {});\n}\n\nfunction define_hidden_property<Value extends object, Property>(\n value: Value,\n key: string | symbol,\n property: Property,\n): Value {\n Object.defineProperty(value, key, {\n value: property,\n enumerable: false,\n });\n\n return value;\n}\n\nfunction define_remote_error_decoder<Value extends object>(\n value: Value,\n decode_payload: Decode_remote_payload,\n): Value {\n return define_hidden_property(value, REMOTE_ERROR_DECODER, decode_payload);\n}\n\nfunction is_http_error_like(value: unknown): value is HttpErrorLike {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction is_redirect_like(value: unknown): value is RedirectLike {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { location?: unknown }).location === \"string\" &&\n typeof (value as { status?: unknown }).status === \"number\",\n );\n}\n\nfunction get_error_status(value: unknown): number {\n return is_http_error_like(value) ? value.status ?? 500 : 500;\n}\n\nfunction decode_remote_error<ErrorType>(\n error: unknown,\n decode_payload: Decode_remote_payload,\n): RemoteFailure<ErrorType> {\n log_remote_client_step(\"decode_remote_error:start\", {\n error,\n });\n\n if (is_http_error_like(error)) {\n const body = error.body;\n\n if (is_serialized_remote_failure_envelope(body)) {\n try {\n return decode_payload<ErrorType>(\n body.encoded,\n ) as RemoteFailure<ErrorType>;\n } catch (cause) {\n return create_remote_transport_error(cause, body);\n }\n }\n\n if (get_error_status(error) === 400) {\n return create_remote_validation_error([], {\n body,\n status: 400,\n });\n }\n\n return create_remote_http_error(error, {\n body,\n status: get_error_status(error),\n });\n }\n\n const decoded = create_remote_http_error(error);\n log_remote_client_step(\"decode_remote_error:http_error\", {\n decoded,\n });\n return decoded;\n}\n\nfunction create_effect_call<Success, ErrorType>(\n create_promise: () => PromiseLike<Success>,\n decode_payload: Decode_remote_payload,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return create_remote_effect_from_promise<Success, ErrorType>(\n () => {\n log_remote_client_step(\"create_effect_call:start\");\n return create_promise();\n },\n (error) => decode_remote_error<ErrorType>(error, decode_payload),\n );\n}\n\nfunction create_decoded_native_callable(\n native: AnyCallable,\n decode_payload: Decode_remote_payload,\n): AnyCallable {\n const wrapped = ((...args: Array<unknown>) => {\n const result = native(...args);\n\n if (\n result && (typeof result === \"object\" || typeof result === \"function\")\n ) {\n define_remote_error_decoder(result as object, decode_payload);\n }\n\n return result;\n }) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native);\n define_remote_error_decoder(wrapped as object, decode_payload);\n\n return wrapped;\n}\n\nfunction get_transport(\n dependencies?: Remote_request_dependencies,\n): Record<string, unknown> {\n return dependencies?.app?.hooks?.transport ?? {};\n}\n\nfunction stringify_remote_payload(\n arg: unknown,\n dependencies: Remote_request_dependencies,\n sort = true,\n): string {\n if (arg === undefined) {\n return \"\";\n }\n\n return dependencies.stringify_remote_arg(\n arg,\n get_transport(dependencies),\n sort,\n );\n}\n\nasync function execute_query_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const url = `${dependencies.base}/${dependencies.app_dir}/remote/${id}${\n payload ? `?payload=${payload}` : \"\"\n }`;\n const encoded = await dependencies.remote_request(\n url,\n dependencies.get_remote_request_headers(),\n );\n\n return decode_payload<Success>(encoded);\n}\n\nasync function execute_query_batch_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const response = await fetch(\n `${dependencies.base}/${dependencies.app_dir}/remote/${id}`,\n {\n method: \"POST\",\n body: JSON.stringify({\n payloads: [payload],\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n ...dependencies.get_remote_request_headers(),\n },\n },\n );\n\n if (!response.ok) {\n throw new Error(\"Failed to execute batch query\");\n }\n\n const result = await response.json() as {\n readonly type: string;\n readonly result?: string;\n readonly status?: number;\n readonly error?: unknown;\n readonly location?: string;\n };\n\n if (result.type === \"error\") {\n throw {\n body: result.error,\n status: result.status ?? 500,\n };\n }\n\n if (result.type === \"redirect\") {\n throw {\n location: result.location,\n status: 307,\n };\n }\n\n const entries = decode_payload<\n Array<{\n readonly data?: Success;\n readonly error?: unknown;\n readonly status?: number;\n readonly type: string;\n }>\n >(result.result ?? \"\");\n const first = entries[0];\n\n if (!first) {\n throw new Error(\"Batch query returned no entries.\");\n }\n\n if (first.type === \"error\") {\n throw {\n body: first.error,\n status: first.status ?? 500,\n };\n }\n\n return first.data as Success;\n}\n\nasync function execute_prerender_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const payload = stringify_remote_payload(arg, dependencies);\n const url = `${dependencies.base}/${dependencies.app_dir}/remote/${id}${\n payload ? `/${payload}` : \"\"\n }`;\n const encoded = await dependencies.remote_request(\n url,\n dependencies.get_remote_request_headers(),\n );\n\n return decode_payload<Success>(encoded);\n}\n\nfunction create_query_request<Success>(\n mode: Query_adapter_mode,\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n native_with_decoder?: AnyCallable,\n): Promise<Success> {\n if (!dependencies || !native_with_decoder) {\n return Promise.resolve(native_with_decoder?.(arg) as Success);\n }\n\n switch (mode) {\n case \"query\":\n return execute_query_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n case \"query_batch\":\n return execute_query_batch_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n case \"prerender\":\n return execute_prerender_request<Success>(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n }\n}\n\nasync function execute_command_request<Success>(\n id: string,\n arg: unknown,\n decode_payload: Decode_remote_payload,\n dependencies: Remote_request_dependencies,\n): Promise<Success> {\n const response = await fetch(\n `${dependencies.base}/${dependencies.app_dir}/remote/${id}`,\n {\n method: \"POST\",\n body: JSON.stringify({\n payload: stringify_remote_payload(arg, dependencies, false),\n refreshes: [],\n }),\n headers: {\n \"Content-Type\": \"application/json\",\n ...dependencies.get_remote_request_headers(),\n },\n },\n );\n\n if (!response.ok) {\n throw new Error(\"Failed to execute remote command\");\n }\n\n const result = await response.json() as {\n readonly type: string;\n readonly result?: string;\n readonly status?: number;\n readonly error?: unknown;\n readonly refreshes?: string;\n };\n\n if (result.type === \"error\") {\n throw {\n body: result.error,\n status: result.status ?? 500,\n };\n }\n\n if (result.type === \"redirect\") {\n throw new Error(\n \"Redirects are not allowed in commands. Return a result instead and use goto on the client.\",\n );\n }\n\n if (result.refreshes) {\n dependencies.apply_refreshes?.(result.refreshes);\n }\n\n return decode_payload<Success>(result.result ?? \"\");\n}\n\nexport function create_remote_query_adapter(\n native_query_factory: (id: string) => AnyCallable,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n mode: Query_adapter_mode = \"query\",\n) {\n return (id: string) => {\n const native = native_query_factory(id);\n const native_with_decoder = create_decoded_native_callable(\n native,\n decode_payload,\n );\n const wrapped = ((arg?: unknown) =>\n create_effect_call(\n () =>\n create_query_request(\n mode,\n id,\n arg,\n decode_payload,\n dependencies,\n native_with_decoder,\n ),\n decode_payload,\n )) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native_with_decoder);\n\n return wrapped;\n };\n}\n\nexport function create_remote_command_adapter(\n native_command_factory: (id: string) => AnyCallable,\n decode_payload: Decode_remote_payload,\n dependencies?: Remote_request_dependencies,\n) {\n return (id: string) => {\n const native = native_command_factory(id);\n const native_with_decoder = create_decoded_native_callable(\n native,\n decode_payload,\n );\n let local_pending = 0;\n const wrapped = ((arg?: unknown) =>\n create_effect_call(\n async () => {\n local_pending += 1;\n\n try {\n if (!dependencies) {\n return await Promise.resolve(native_with_decoder(arg));\n }\n\n return await execute_command_request(\n id,\n arg,\n decode_payload,\n dependencies,\n );\n } finally {\n local_pending -= 1;\n }\n },\n decode_payload,\n )) as AnyCallable;\n\n define_hidden_property(wrapped, \"native\", native_with_decoder);\n Object.defineProperty(wrapped, \"pending\", {\n get: () =>\n ((native as { pending?: number }).pending ?? 0) + local_pending,\n });\n\n return wrapped;\n };\n}\n\nfunction normalize_form_issues(issues: unknown): ReadonlyArray<FormIssue> {\n if (!Array.isArray(issues)) {\n return [];\n }\n\n return issues.flatMap((issue) =>\n is_remote_validation_issue(issue)\n ? [{\n message: issue.message,\n path: [...issue.path],\n }]\n : []\n );\n}\n\nfunction get_root_form_issues(\n native: {\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n },\n): ReadonlyArray<FormIssue> {\n return normalize_form_issues(native.fields?.allIssues);\n}\n\nfunction get_attachment(\n value: Record<string | symbol, unknown>,\n): (form: HTMLFormElement) => void | (() => void) {\n for (const symbol of Object.getOwnPropertySymbols(value)) {\n const candidate = value[symbol];\n\n if (typeof candidate === \"function\") {\n return candidate as (form: HTMLFormElement) => void | (() => void);\n }\n }\n\n throw new Error(\n \"Failed to find the Svelte attachment for the remote form enhancement.\",\n );\n}\n\nfunction build_form_field_name(path: ReadonlyArray<string | number>): string {\n let name = \"\";\n\n for (const segment of path) {\n if (typeof segment === \"number\") {\n name += `[${segment}]`;\n continue;\n }\n\n name += name === \"\" ? segment : `.${segment}`;\n }\n\n return name;\n}\n\nfunction append_hidden_input(\n form: HTMLFormElement,\n name: string,\n value: string,\n): void {\n const input = document.createElement(\"input\");\n input.type = \"hidden\";\n input.name = name;\n input.value = value;\n form.append(input);\n}\n\nfunction append_file_input(\n form: HTMLFormElement,\n name: string,\n value: File,\n): void {\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.name = name;\n\n if (typeof DataTransfer === \"function\") {\n const transfer = new DataTransfer();\n transfer.items.add(value);\n\n try {\n input.files = transfer.files;\n } catch {\n // ignore and fall back below\n }\n }\n\n if (input.files?.length) {\n form.append(input);\n return;\n }\n\n append_hidden_input(form, name, value.name);\n}\n\nfunction append_form_value(\n form: HTMLFormElement,\n value: unknown,\n path: ReadonlyArray<string | number>,\n): void {\n if (value === undefined) {\n return;\n }\n\n if (value instanceof File) {\n append_file_input(form, build_form_field_name(path), value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((entry, index) => {\n append_form_value(form, entry, [...path, index]);\n });\n return;\n }\n\n if (value && typeof value === \"object\") {\n for (\n const [key, entry] of Object.entries(value as Record<string, unknown>)\n ) {\n append_form_value(form, entry, [...path, key]);\n }\n return;\n }\n\n const base_name = build_form_field_name(path);\n\n if (typeof value === \"number\") {\n append_hidden_input(form, `n:${base_name}`, String(value));\n return;\n }\n\n if (typeof value === \"boolean\") {\n append_hidden_input(form, `b:${base_name}`, value ? \"on\" : \"\");\n return;\n }\n\n append_hidden_input(\n form,\n base_name,\n value === null ? \"\" : String(value),\n );\n}\n\nfunction apply_input_to_fields(fields: unknown, input: unknown): void {\n if (!fields || typeof fields !== \"object\") {\n return;\n }\n\n const maybe_field = fields as {\n readonly set?: (value: unknown) => void;\n };\n\n if (typeof maybe_field.set === \"function\") {\n maybe_field.set(input);\n return;\n }\n\n if (!input || typeof input !== \"object\") {\n return;\n }\n\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n apply_input_to_fields(\n (fields as Record<string, unknown>)[key],\n value,\n );\n }\n}\n\ntype Submitter_like = {\n click(): void;\n} & Record<string, unknown>;\n\nfunction is_submitter_like(value: unknown): value is Submitter_like {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { click?: unknown }).click === \"function\",\n );\n}\n\nfunction get_submitter(\n form: HTMLFormElement,\n): Submitter_like | undefined {\n const submitter = form.querySelector(\"button:not([type]), [type='submit']\");\n return is_submitter_like(submitter) ? submitter : undefined;\n}\n\nfunction request_form_submit(form: HTMLFormElement): void {\n const submitter = get_submitter(form);\n log_remote_client_step(\"request_form_submit\", {\n action: form.action,\n has_submitter: Boolean(submitter),\n submitter,\n });\n\n if (typeof SubmitEvent === \"function\") {\n form.dispatchEvent(\n new SubmitEvent(\"submit\", {\n bubbles: true,\n cancelable: true,\n submitter: submitter as HTMLElement | null | undefined,\n }),\n );\n return;\n }\n\n const event = new Event(\"submit\", {\n bubbles: true,\n cancelable: true,\n }) as Event & {\n readonly submitter?: Submitter_like;\n };\n Object.defineProperty(event, \"submitter\", {\n configurable: true,\n value: submitter,\n });\n form.dispatchEvent(event);\n}\n\nasync function wait_for_pending_settle(\n native: {\n readonly pending?: number;\n },\n): Promise<void> {\n await tick();\n\n while ((native.pending ?? 0) > 0) {\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n\n await tick();\n}\n\nasync function submit_attached_form<Success, ErrorType>(\n form: {\n readonly native: {\n readonly fields?: {\n readonly allIssues?: unknown;\n } & Record<string, unknown>;\n readonly pending?: number;\n readonly result?: Success;\n };\n },\n element: HTMLFormElement,\n input: unknown,\n): Promise<Effect.Effect<Success, RemoteFailure<ErrorType>, never>> {\n log_remote_client_step(\"submit_attached_form:start\", {\n action: element.action,\n input,\n });\n\n if (input !== undefined) {\n apply_input_to_fields(form.native.fields, input);\n }\n\n await tick();\n request_form_submit(element);\n await wait_for_pending_settle(form.native);\n\n const issues = get_root_form_issues(form.native);\n log_remote_client_step(\"submit_attached_form:after_submit\", {\n issues,\n pending: form.native.pending ?? 0,\n result: form.native.result,\n });\n\n if (issues.length > 0) {\n return Effect.fail(\n create_remote_validation_error(issues, {\n body: issues,\n status: 400,\n }),\n );\n }\n\n return Effect.succeed(form.native.result as Success);\n}\n\nfunction create_form_submit_effect<Success, ErrorType>(\n form: {\n readonly native: {\n readonly action: string;\n readonly result?: Success;\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n enhance(\n callback: (args: {\n readonly form: HTMLFormElement;\n readonly data: unknown;\n readonly submit: () => Promise<unknown>;\n }) => Promise<void> | void,\n ): Record<string | symbol, unknown>;\n };\n },\n input: unknown,\n decode_payload: Decode_remote_payload,\n attached_form_tracker: Attached_form_tracker,\n _dependencies: Form_request_dependencies,\n): Effect.Effect<Success, RemoteFailure<ErrorType>, never> {\n return create_async_effect<Success, RemoteFailure<ErrorType>>((resume) => {\n log_remote_client_step(\"create_form_submit_effect:start\", {\n action: form.native.action,\n input,\n attached: Boolean(attached_form_tracker.current),\n });\n\n if (typeof document === \"undefined\") {\n resume(\n Effect.fail(\n create_remote_http_error(\n new Error(\"Programmatic remote form submission requires a DOM.\"),\n ),\n ),\n );\n return;\n }\n\n let settled = false;\n let dispose_attachment: void | (() => void);\n const temp_form = document.createElement(\"form\");\n temp_form.method = \"POST\";\n temp_form.action = form.native.action;\n temp_form.hidden = true;\n document.body.append(temp_form);\n\n const cleanup = () => {\n if (typeof dispose_attachment === \"function\") {\n dispose_attachment();\n }\n\n temp_form.remove();\n };\n\n const finish = (\n effect: Effect.Effect<Success, RemoteFailure<ErrorType>, never>,\n ) => {\n if (settled) {\n return;\n }\n\n settled = true;\n cleanup();\n resume(effect);\n };\n\n try {\n const attached_form = attached_form_tracker.current;\n\n if (attached_form) {\n log_remote_client_step(\n \"create_form_submit_effect:attached_form_branch\",\n {\n action: attached_form.action,\n },\n );\n void submit_attached_form<Success, ErrorType>(\n form,\n attached_form,\n input,\n ).then(finish, (error) => {\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n });\n return;\n }\n\n log_remote_client_step(\n \"create_form_submit_effect:detached_fallback_branch\",\n {\n action: form.native.action,\n },\n );\n const enhanced = form.native.enhance(async ({ submit }) => {\n try {\n log_remote_client_step(\n \"create_form_submit_effect:fallback_submit:start\",\n {\n action: form.native.action,\n },\n );\n await submit();\n const issues = get_root_form_issues(form.native);\n log_remote_client_step(\n \"create_form_submit_effect:fallback_submit:after\",\n {\n issues,\n result: form.native.result,\n },\n );\n\n if (issues.length > 0) {\n finish(\n Effect.fail(\n create_remote_validation_error(issues, {\n body: issues,\n status: 400,\n }),\n ),\n );\n return;\n }\n\n finish(Effect.succeed(form.native.result as Success));\n } catch (error) {\n if (is_redirect_like(error)) {\n finish(Effect.die(error));\n return;\n }\n\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n }\n });\n\n dispose_attachment = get_attachment(enhanced)(temp_form);\n\n if (input && typeof input === \"object\") {\n append_form_value(temp_form, input, []);\n }\n\n const submitter = document.createElement(\"button\");\n submitter.type = \"submit\";\n temp_form.append(submitter);\n if (typeof temp_form.requestSubmit === \"function\") {\n temp_form.requestSubmit(submitter);\n } else {\n submitter.click();\n }\n } catch (error) {\n log_remote_client_step(\"create_form_submit_effect:error\", {\n error,\n });\n finish(\n Effect.fail(decode_remote_error<ErrorType>(error, decode_payload)),\n );\n }\n });\n}\n\nfunction wrap_native_form(\n native: Record<string, unknown>,\n decode_payload: Decode_remote_payload,\n dependencies: Form_request_dependencies,\n) {\n const attached_form_tracker: Attached_form_tracker = {\n current: null,\n };\n const wrapped_symbol_properties = new Map<symbol, unknown>();\n const proxy_target: Record<string, unknown> = {};\n Object.defineProperty(proxy_target, \"native\", {\n configurable: true,\n enumerable: false,\n value: native,\n writable: false,\n });\n const wrapped = new Proxy(proxy_target, {\n get(_target, property, receiver) {\n if (property === \"native\") {\n return native;\n }\n\n if (property === \"submit\") {\n return (input: unknown) =>\n create_form_submit_effect(\n receiver as {\n readonly native: {\n readonly action: string;\n readonly result?: unknown;\n readonly fields?: {\n readonly allIssues?: unknown;\n };\n enhance(\n callback: (args: {\n readonly form: HTMLFormElement;\n readonly data: unknown;\n readonly submit: () => Promise<unknown>;\n }) => Promise<void> | void,\n ): Record<string | symbol, unknown>;\n };\n },\n input,\n decode_payload,\n attached_form_tracker,\n dependencies,\n );\n }\n\n if (typeof property === \"symbol\") {\n if (wrapped_symbol_properties.has(property)) {\n return wrapped_symbol_properties.get(property);\n }\n\n const native_value = Reflect.get(native, property, native);\n\n if (typeof native_value === \"function\") {\n const wrapped_attachment = (element: HTMLFormElement) => {\n log_remote_client_step(\"wrap_native_form:attach\", {\n action: element.action,\n native_action: (native as { action?: unknown }).action,\n });\n attached_form_tracker.current = element;\n const cleanup = native_value.call(native, element);\n\n return () => {\n log_remote_client_step(\"wrap_native_form:detach\", {\n action: element.action,\n });\n if (attached_form_tracker.current === element) {\n attached_form_tracker.current = null;\n }\n\n if (typeof cleanup === \"function\") {\n cleanup();\n }\n };\n };\n\n wrapped_symbol_properties.set(property, wrapped_attachment);\n return wrapped_attachment;\n }\n }\n\n if (property === \"for\") {\n const native_for = Reflect.get(native, property, native);\n\n if (typeof native_for === \"function\") {\n return (key: string | number) =>\n wrap_native_form(\n native_for.call(native, key) as Record<string, unknown>,\n decode_payload,\n dependencies,\n );\n }\n }\n\n return Reflect.get(native, property, native);\n },\n has(_target, property) {\n if (\n property === \"native\" ||\n property === \"submit\" ||\n property === \"for\"\n ) {\n return true;\n }\n\n return Reflect.has(native, property);\n },\n ownKeys() {\n return Array.from(\n new Set([\n ...Reflect.ownKeys(native),\n \"native\",\n \"submit\",\n \"for\",\n ...wrapped_symbol_properties.keys(),\n ]),\n );\n },\n getOwnPropertyDescriptor(\n _target,\n property,\n ): PropertyDescriptor | undefined {\n if (property === \"native\") {\n return Reflect.getOwnPropertyDescriptor(proxy_target, property);\n }\n\n if (property === \"submit\" || property === \"for\") {\n return {\n configurable: true,\n enumerable: false,\n writable: false,\n };\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(native, property);\n\n if (!descriptor) {\n return descriptor;\n }\n\n return {\n ...descriptor,\n configurable: true,\n };\n },\n });\n\n return wrapped as Record<string, unknown>;\n}\n\nexport function create_remote_form_adapter(\n native_form_factory: (id: string) => Record<string, unknown>,\n decode_payload: Decode_remote_payload,\n dependencies: Form_request_dependencies,\n) {\n return (id: string) => {\n const native = native_form_factory(id);\n return wrap_native_form(native, decode_payload, dependencies);\n };\n}\n"],"mappings":";;;;;;;AA8EA,SAAS,6BAAsC;CAC7C,MAAM,mBACJ,OAAO,KAKP;AAEF,KAAI,OAAO,kBAAkB,QAAQ,UACnC,QAAO,iBAAiB;CAG1B,MAAM,eAAgB,WAQnB;AAEH,QACE,cAAc,KAAK,gCAAgC,OACnD,cAAc,KAAK,QAAQ,OAC3B,cAAc,KAAK,aAAa;;AAIpC,MAAM,kCAAkC,4BAA4B;AAEpE,SAAS,uBACP,MACA,SACM;AACN,KAAI,CAAC,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,GAAG,0BAA0B,MAAM;IACpC,CAAC,CACH;;EAEH,yBACE,SACA,UACgC;AAChC,OAAI,aAAa,SACf,QAAO,QAAQ,yBAAyB,cAAc,SAAS;AAGjE,OAAI,aAAa,YAAY,aAAa,MACxC,QAAO;IACL,cAAc;IACd,YAAY;IACZ,UAAU;IACX;GAGH,MAAM,aAAa,QAAQ,yBAAyB,QAAQ,SAAS;AAErE,OAAI,CAAC,WACH,QAAO;AAGT,UAAO;IACL,GAAG;IACH,cAAc;IACf;;EAEJ,CAAC;;AAKJ,SAAgB,2BACd,qBACA,gBACA,cACA;AACA,SAAQ,OAAe;AAErB,SAAO,iBADQ,oBAAoB,GAAG,EACN,gBAAgB,aAAa"}
|
|
@@ -1,53 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marker property name placed on serialized `RemoteFailure` envelopes so the
|
|
3
|
+
* client adapters can recognise server-produced failure payloads.
|
|
4
|
+
*
|
|
5
|
+
* @internal Internal - do not use.
|
|
6
|
+
*/
|
|
1
7
|
export declare const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
|
|
8
|
+
/**
|
|
9
|
+
* Well-known symbol used to attach a payload decoder to a remote function,
|
|
10
|
+
* enabling the client to reconstruct typed domain errors from wire data.
|
|
11
|
+
*
|
|
12
|
+
* @internal Internal - do not use.
|
|
13
|
+
*/
|
|
2
14
|
export declare const REMOTE_ERROR_DECODER: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* A single validation problem surfaced by a remote form or schema check.
|
|
17
|
+
* Mirrors SvelteKit's `invalid()` issue shape.
|
|
18
|
+
*/
|
|
3
19
|
export interface FormIssue {
|
|
20
|
+
/** Human-readable description of the failure at {@link FormIssue.path}. */
|
|
4
21
|
readonly message: string;
|
|
22
|
+
/** Field path (dot or array-index segments) the issue applies to. */
|
|
5
23
|
readonly path: ReadonlyArray<string | number>;
|
|
6
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Typed error produced by `invalid.form(...)` / `invalid.<field>(...)` helpers
|
|
27
|
+
* inside a `Form` handler. Carries the collected `FormIssue`s to surface to
|
|
28
|
+
* the browser.
|
|
29
|
+
*/
|
|
7
30
|
export interface FormError<SchemaType = unknown> {
|
|
31
|
+
/** Discriminator identifying this as a form error. */
|
|
8
32
|
readonly _tag: "FormError";
|
|
33
|
+
/** Issues produced by the handler, one per failed field. */
|
|
9
34
|
readonly issues: ReadonlyArray<FormIssue>;
|
|
35
|
+
/**
|
|
36
|
+
* Phantom reference to the originating schema. Used purely for type
|
|
37
|
+
* inference of field helpers.
|
|
38
|
+
*/
|
|
10
39
|
readonly _schema?: SchemaType | undefined;
|
|
11
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Legacy wrapper around a typed server-side domain error value.
|
|
43
|
+
*
|
|
44
|
+
* @deprecated Tagged remote domain errors are no longer wrapped in
|
|
45
|
+
* `RemoteDomainError`. The user's own tagged error is now placed directly on
|
|
46
|
+
* the Effect error channel so `Effect.catchTag("YourTag", ...)` works without
|
|
47
|
+
* unwrapping. This interface is kept only for backwards compatibility with
|
|
48
|
+
* code that pattern-matched on `_tag === "RemoteDomainError"`.
|
|
49
|
+
*/
|
|
12
50
|
export interface RemoteDomainError<ErrorType = unknown> {
|
|
51
|
+
/** Discriminator identifying this variant of `RemoteFailure`. */
|
|
13
52
|
readonly _tag: "RemoteDomainError";
|
|
53
|
+
/** The original typed error value produced on the server. */
|
|
14
54
|
readonly cause: ErrorType;
|
|
55
|
+
/** HTTP status code associated with the failure. */
|
|
15
56
|
readonly status: number;
|
|
16
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Remote failure emitted when request validation (schema or form) rejects the
|
|
60
|
+
* payload. Defaults to HTTP `400`, but callers may override the status code
|
|
61
|
+
* when constructing the value.
|
|
62
|
+
*/
|
|
17
63
|
export interface RemoteValidationError {
|
|
64
|
+
/** Discriminator identifying this variant of `RemoteFailure`. */
|
|
18
65
|
readonly _tag: "RemoteValidationError";
|
|
66
|
+
/** Raw response body returned alongside the failure, when available. */
|
|
19
67
|
readonly body?: unknown;
|
|
68
|
+
/** Validation issues, keyed by field path. */
|
|
20
69
|
readonly issues: ReadonlyArray<FormIssue>;
|
|
70
|
+
/** HTTP status code for the validation failure, defaulting to `400`. */
|
|
21
71
|
readonly status: number;
|
|
22
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Remote failure for HTTP-level errors returned by the server that do not map
|
|
75
|
+
* onto a typed domain error or validation failure.
|
|
76
|
+
*/
|
|
23
77
|
export interface RemoteHttpError {
|
|
78
|
+
/** Discriminator identifying this variant of `RemoteFailure`. */
|
|
24
79
|
readonly _tag: "RemoteHttpError";
|
|
80
|
+
/** Parsed response body, if any. */
|
|
25
81
|
readonly body?: unknown;
|
|
82
|
+
/** Original thrown value captured while handling the response. */
|
|
26
83
|
readonly cause: unknown;
|
|
84
|
+
/** HTTP status code reported by the response. */
|
|
27
85
|
readonly status: number;
|
|
28
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Remote failure for transport-level breakages (network errors, decoding
|
|
89
|
+
* failures). Does not carry an HTTP status.
|
|
90
|
+
*/
|
|
29
91
|
export interface RemoteTransportError {
|
|
92
|
+
/** Discriminator identifying this variant of `RemoteFailure`. */
|
|
30
93
|
readonly _tag: "RemoteTransportError";
|
|
94
|
+
/** Raw body captured when the transport failure was detected, if any. */
|
|
31
95
|
readonly body?: unknown;
|
|
96
|
+
/** Underlying error value - usually a `TypeError` or `DOMException`. */
|
|
32
97
|
readonly cause: unknown;
|
|
33
98
|
}
|
|
34
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Error channel produced by every remote Effect wrapper. A server-side
|
|
101
|
+
* `Effect.fail(MyTaggedError)` surfaces on the client as the raw `ErrorType`,
|
|
102
|
+
* so `Effect.catchTag("MyTag", ...)` narrows directly to your error. The
|
|
103
|
+
* framework-level failure variants (`RemoteValidationError`,
|
|
104
|
+
* `RemoteHttpError`, `RemoteTransportError`) are still included for transport
|
|
105
|
+
* and HTTP failures that the caller didn't model explicitly.
|
|
106
|
+
*/
|
|
107
|
+
export type RemoteFailure<ErrorType = unknown> = ErrorType | RemoteValidationError | RemoteHttpError | RemoteTransportError;
|
|
108
|
+
/**
|
|
109
|
+
* Wire shape of a serialised remote failure envelope that the server embeds
|
|
110
|
+
* in its response body.
|
|
111
|
+
*
|
|
112
|
+
* @internal Internal - do not use.
|
|
113
|
+
*/
|
|
35
114
|
export interface SerializedRemoteFailureEnvelope {
|
|
115
|
+
/** Marker flag; always `true`. */
|
|
36
116
|
readonly [EFFECT_REMOTE_ERROR_MARKER]: true;
|
|
117
|
+
/** `devalue.stringify`-encoded payload for the failure value. */
|
|
37
118
|
readonly encoded: string;
|
|
38
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Construct a {@link FormError} from one or more {@link FormIssue}s.
|
|
122
|
+
*
|
|
123
|
+
* @internal Internal - do not use.
|
|
124
|
+
*/
|
|
39
125
|
export declare function create_form_error<SchemaType = unknown>(...issues: Array<FormIssue>): FormError<SchemaType>;
|
|
126
|
+
/**
|
|
127
|
+
* Build a {@link RemoteDomainError} around a typed server-side error value.
|
|
128
|
+
*
|
|
129
|
+
* @deprecated Remote tagged failures are no longer wrapped - the user's
|
|
130
|
+
* tagged error is forwarded directly on the Effect error channel. This helper
|
|
131
|
+
* is retained for backwards compatibility with downstream code that still
|
|
132
|
+
* constructs `RemoteDomainError` values explicitly.
|
|
133
|
+
*
|
|
134
|
+
* @internal Internal - do not use.
|
|
135
|
+
*/
|
|
40
136
|
export declare function create_remote_domain_error<ErrorType = unknown>(cause: ErrorType, status: number): RemoteDomainError<ErrorType>;
|
|
137
|
+
/**
|
|
138
|
+
* Build a {@link RemoteValidationError} from a list of issues.
|
|
139
|
+
*
|
|
140
|
+
* @internal Internal - do not use.
|
|
141
|
+
*/
|
|
41
142
|
export declare function create_remote_validation_error(issues: ReadonlyArray<FormIssue>, options?: {
|
|
42
143
|
body?: unknown;
|
|
43
144
|
status?: number;
|
|
44
145
|
}): RemoteValidationError;
|
|
146
|
+
/**
|
|
147
|
+
* Build a {@link RemoteHttpError} from an arbitrary thrown value.
|
|
148
|
+
*
|
|
149
|
+
* @internal Internal - do not use.
|
|
150
|
+
*/
|
|
45
151
|
export declare function create_remote_http_error(cause: unknown, options?: {
|
|
46
152
|
body?: unknown;
|
|
47
153
|
status?: number;
|
|
48
154
|
}): RemoteHttpError;
|
|
155
|
+
/**
|
|
156
|
+
* Build a {@link RemoteTransportError} from an arbitrary thrown value.
|
|
157
|
+
*
|
|
158
|
+
* @internal Internal - do not use.
|
|
159
|
+
*/
|
|
49
160
|
export declare function create_remote_transport_error(cause: unknown, body?: unknown): RemoteTransportError;
|
|
161
|
+
/**
|
|
162
|
+
* Wrap a pre-encoded failure payload in the marker envelope the client
|
|
163
|
+
* adapters look for when decoding responses.
|
|
164
|
+
*
|
|
165
|
+
* @internal Internal - do not use.
|
|
166
|
+
*/
|
|
50
167
|
export declare function create_serialized_remote_failure_envelope(encoded: string): SerializedRemoteFailureEnvelope;
|
|
168
|
+
/**
|
|
169
|
+
* Type guard for {@link FormError} values.
|
|
170
|
+
*
|
|
171
|
+
* @internal Internal - do not use.
|
|
172
|
+
*/
|
|
51
173
|
export declare function is_form_error(value: unknown): value is FormError;
|
|
174
|
+
/**
|
|
175
|
+
* Type guard recognising the marker envelope wrapping an encoded remote
|
|
176
|
+
* failure payload.
|
|
177
|
+
*
|
|
178
|
+
* @internal Internal - do not use.
|
|
179
|
+
*/
|
|
52
180
|
export declare function is_serialized_remote_failure_envelope(value: unknown): value is SerializedRemoteFailureEnvelope;
|
|
181
|
+
/**
|
|
182
|
+
* Type guard for individual {@link FormIssue} values.
|
|
183
|
+
*
|
|
184
|
+
* @internal Internal - do not use.
|
|
185
|
+
*/
|
|
53
186
|
export declare function is_remote_validation_issue(value: unknown): value is FormIssue;
|
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
//#region internal/remote-shared.ts
|
|
2
|
+
/**
|
|
3
|
+
* Marker property name placed on serialized `RemoteFailure` envelopes so the
|
|
4
|
+
* client adapters can recognise server-produced failure payloads.
|
|
5
|
+
*
|
|
6
|
+
* @internal Internal - do not use.
|
|
7
|
+
*/
|
|
2
8
|
const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
|
|
9
|
+
/**
|
|
10
|
+
* Well-known symbol used to attach a payload decoder to a remote function,
|
|
11
|
+
* enabling the client to reconstruct typed domain errors from wire data.
|
|
12
|
+
*
|
|
13
|
+
* @internal Internal - do not use.
|
|
14
|
+
*/
|
|
3
15
|
const REMOTE_ERROR_DECODER = Symbol.for("svelte-effect-runtime/remote-error-decoder");
|
|
16
|
+
/**
|
|
17
|
+
* Construct a {@link FormError} from one or more {@link FormIssue}s.
|
|
18
|
+
*
|
|
19
|
+
* @internal Internal - do not use.
|
|
20
|
+
*/
|
|
4
21
|
function create_form_error(...issues) {
|
|
5
22
|
return {
|
|
6
23
|
_tag: "FormError",
|
|
7
24
|
issues
|
|
8
25
|
};
|
|
9
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Build a {@link RemoteDomainError} around a typed server-side error value.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Remote tagged failures are no longer wrapped - the user's
|
|
31
|
+
* tagged error is forwarded directly on the Effect error channel. This helper
|
|
32
|
+
* is retained for backwards compatibility with downstream code that still
|
|
33
|
+
* constructs `RemoteDomainError` values explicitly.
|
|
34
|
+
*
|
|
35
|
+
* @internal Internal - do not use.
|
|
36
|
+
*/
|
|
10
37
|
function create_remote_domain_error(cause, status) {
|
|
11
38
|
return {
|
|
12
39
|
_tag: "RemoteDomainError",
|
|
@@ -14,6 +41,11 @@ function create_remote_domain_error(cause, status) {
|
|
|
14
41
|
status
|
|
15
42
|
};
|
|
16
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Build a {@link RemoteValidationError} from a list of issues.
|
|
46
|
+
*
|
|
47
|
+
* @internal Internal - do not use.
|
|
48
|
+
*/
|
|
17
49
|
function create_remote_validation_error(issues, options = {}) {
|
|
18
50
|
return {
|
|
19
51
|
_tag: "RemoteValidationError",
|
|
@@ -22,6 +54,11 @@ function create_remote_validation_error(issues, options = {}) {
|
|
|
22
54
|
status: options.status ?? 400
|
|
23
55
|
};
|
|
24
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Build a {@link RemoteHttpError} from an arbitrary thrown value.
|
|
59
|
+
*
|
|
60
|
+
* @internal Internal - do not use.
|
|
61
|
+
*/
|
|
25
62
|
function create_remote_http_error(cause, options = {}) {
|
|
26
63
|
return {
|
|
27
64
|
_tag: "RemoteHttpError",
|
|
@@ -30,6 +67,11 @@ function create_remote_http_error(cause, options = {}) {
|
|
|
30
67
|
status: options.status ?? 500
|
|
31
68
|
};
|
|
32
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a {@link RemoteTransportError} from an arbitrary thrown value.
|
|
72
|
+
*
|
|
73
|
+
* @internal Internal - do not use.
|
|
74
|
+
*/
|
|
33
75
|
function create_remote_transport_error(cause, body) {
|
|
34
76
|
return {
|
|
35
77
|
_tag: "RemoteTransportError",
|
|
@@ -37,18 +79,40 @@ function create_remote_transport_error(cause, body) {
|
|
|
37
79
|
cause
|
|
38
80
|
};
|
|
39
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Wrap a pre-encoded failure payload in the marker envelope the client
|
|
84
|
+
* adapters look for when decoding responses.
|
|
85
|
+
*
|
|
86
|
+
* @internal Internal - do not use.
|
|
87
|
+
*/
|
|
40
88
|
function create_serialized_remote_failure_envelope(encoded) {
|
|
41
89
|
return {
|
|
42
90
|
[EFFECT_REMOTE_ERROR_MARKER]: true,
|
|
43
91
|
encoded
|
|
44
92
|
};
|
|
45
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Type guard for {@link FormError} values.
|
|
96
|
+
*
|
|
97
|
+
* @internal Internal - do not use.
|
|
98
|
+
*/
|
|
46
99
|
function is_form_error(value) {
|
|
47
100
|
return Boolean(value && typeof value === "object" && value._tag === "FormError" && Array.isArray(value.issues));
|
|
48
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Type guard recognising the marker envelope wrapping an encoded remote
|
|
104
|
+
* failure payload.
|
|
105
|
+
*
|
|
106
|
+
* @internal Internal - do not use.
|
|
107
|
+
*/
|
|
49
108
|
function is_serialized_remote_failure_envelope(value) {
|
|
50
109
|
return Boolean(value && typeof value === "object" && "__svelte_effect_remote__" in value && value["__svelte_effect_remote__"] === true && typeof value.encoded === "string");
|
|
51
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Type guard for individual {@link FormIssue} values.
|
|
113
|
+
*
|
|
114
|
+
* @internal Internal - do not use.
|
|
115
|
+
*/
|
|
52
116
|
function is_remote_validation_issue(value) {
|
|
53
117
|
return Boolean(value && typeof value === "object" && typeof value.message === "string" && Array.isArray(value.path));
|
|
54
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-shared.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"remote-shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-shared.ts"],"sourcesContent":["/**\n * Marker property name placed on serialized `RemoteFailure` envelopes so the\n * client adapters can recognise server-produced failure payloads.\n *\n * @internal Internal - do not use.\n */\nexport const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\n/**\n * Well-known symbol used to attach a payload decoder to a remote function,\n * enabling the client to reconstruct typed domain errors from wire data.\n *\n * @internal Internal - do not use.\n */\nexport const REMOTE_ERROR_DECODER = Symbol.for(\n \"svelte-effect-runtime/remote-error-decoder\",\n);\n\n/**\n * A single validation problem surfaced by a remote form or schema check.\n * Mirrors SvelteKit's `invalid()` issue shape.\n */\nexport interface FormIssue {\n /** Human-readable description of the failure at {@link FormIssue.path}. */\n readonly message: string;\n /** Field path (dot or array-index segments) the issue applies to. */\n readonly path: ReadonlyArray<string | number>;\n}\n\n/**\n * Typed error produced by `invalid.form(...)` / `invalid.<field>(...)` helpers\n * inside a `Form` handler. Carries the collected `FormIssue`s to surface to\n * the browser.\n */\nexport interface FormError<SchemaType = unknown> {\n /** Discriminator identifying this as a form error. */\n readonly _tag: \"FormError\";\n /** Issues produced by the handler, one per failed field. */\n readonly issues: ReadonlyArray<FormIssue>;\n /**\n * Phantom reference to the originating schema. Used purely for type\n * inference of field helpers.\n */\n readonly _schema?: SchemaType | undefined;\n}\n\n/**\n * Legacy wrapper around a typed server-side domain error value.\n *\n * @deprecated Tagged remote domain errors are no longer wrapped in\n * `RemoteDomainError`. The user's own tagged error is now placed directly on\n * the Effect error channel so `Effect.catchTag(\"YourTag\", ...)` works without\n * unwrapping. This interface is kept only for backwards compatibility with\n * code that pattern-matched on `_tag === \"RemoteDomainError\"`.\n */\nexport interface RemoteDomainError<ErrorType = unknown> {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteDomainError\";\n /** The original typed error value produced on the server. */\n readonly cause: ErrorType;\n /** HTTP status code associated with the failure. */\n readonly status: number;\n}\n\n/**\n * Remote failure emitted when request validation (schema or form) rejects the\n * payload. Defaults to HTTP `400`, but callers may override the status code\n * when constructing the value.\n */\nexport interface RemoteValidationError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteValidationError\";\n /** Raw response body returned alongside the failure, when available. */\n readonly body?: unknown;\n /** Validation issues, keyed by field path. */\n readonly issues: ReadonlyArray<FormIssue>;\n /** HTTP status code for the validation failure, defaulting to `400`. */\n readonly status: number;\n}\n\n/**\n * Remote failure for HTTP-level errors returned by the server that do not map\n * onto a typed domain error or validation failure.\n */\nexport interface RemoteHttpError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteHttpError\";\n /** Parsed response body, if any. */\n readonly body?: unknown;\n /** Original thrown value captured while handling the response. */\n readonly cause: unknown;\n /** HTTP status code reported by the response. */\n readonly status: number;\n}\n\n/**\n * Remote failure for transport-level breakages (network errors, decoding\n * failures). Does not carry an HTTP status.\n */\nexport interface RemoteTransportError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteTransportError\";\n /** Raw body captured when the transport failure was detected, if any. */\n readonly body?: unknown;\n /** Underlying error value - usually a `TypeError` or `DOMException`. */\n readonly cause: unknown;\n}\n\n/**\n * Error channel produced by every remote Effect wrapper. A server-side\n * `Effect.fail(MyTaggedError)` surfaces on the client as the raw `ErrorType`,\n * so `Effect.catchTag(\"MyTag\", ...)` narrows directly to your error. The\n * framework-level failure variants (`RemoteValidationError`,\n * `RemoteHttpError`, `RemoteTransportError`) are still included for transport\n * and HTTP failures that the caller didn't model explicitly.\n */\nexport type RemoteFailure<ErrorType = unknown> =\n | ErrorType\n | RemoteValidationError\n | RemoteHttpError\n | RemoteTransportError;\n\n/**\n * Wire shape of a serialised remote failure envelope that the server embeds\n * in its response body.\n *\n * @internal Internal - do not use.\n */\nexport interface SerializedRemoteFailureEnvelope {\n /** Marker flag; always `true`. */\n readonly [EFFECT_REMOTE_ERROR_MARKER]: true;\n /** `devalue.stringify`-encoded payload for the failure value. */\n readonly encoded: string;\n}\n\n/**\n * Construct a {@link FormError} from one or more {@link FormIssue}s.\n *\n * @internal Internal - do not use.\n */\nexport function create_form_error<SchemaType = unknown>(\n ...issues: Array<FormIssue>\n): FormError<SchemaType> {\n return {\n _tag: \"FormError\",\n issues,\n };\n}\n\n/**\n * Build a {@link RemoteDomainError} around a typed server-side error value.\n *\n * @deprecated Remote tagged failures are no longer wrapped - the user's\n * tagged error is forwarded directly on the Effect error channel. This helper\n * is retained for backwards compatibility with downstream code that still\n * constructs `RemoteDomainError` values explicitly.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_domain_error<ErrorType = unknown>(\n cause: ErrorType,\n status: number,\n): RemoteDomainError<ErrorType> {\n return {\n _tag: \"RemoteDomainError\",\n cause,\n status,\n };\n}\n\n/**\n * Build a {@link RemoteValidationError} from a list of issues.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_validation_error(\n issues: ReadonlyArray<FormIssue>,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteValidationError {\n return {\n _tag: \"RemoteValidationError\",\n body: options.body,\n issues,\n status: options.status ?? 400,\n };\n}\n\n/**\n * Build a {@link RemoteHttpError} from an arbitrary thrown value.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_http_error(\n cause: unknown,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteHttpError {\n return {\n _tag: \"RemoteHttpError\",\n body: options.body,\n cause,\n status: options.status ?? 500,\n };\n}\n\n/**\n * Build a {@link RemoteTransportError} from an arbitrary thrown value.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_transport_error(\n cause: unknown,\n body?: unknown,\n): RemoteTransportError {\n return {\n _tag: \"RemoteTransportError\",\n body,\n cause,\n };\n}\n\n/**\n * Wrap a pre-encoded failure payload in the marker envelope the client\n * adapters look for when decoding responses.\n *\n * @internal Internal - do not use.\n */\nexport function create_serialized_remote_failure_envelope(\n encoded: string,\n): SerializedRemoteFailureEnvelope {\n return {\n [EFFECT_REMOTE_ERROR_MARKER]: true,\n encoded,\n };\n}\n\n/**\n * Type guard for {@link FormError} values.\n *\n * @internal Internal - do not use.\n */\nexport function is_form_error(value: unknown): value is FormError {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n (value as { _tag?: unknown })._tag === \"FormError\" &&\n Array.isArray((value as { issues?: unknown }).issues),\n );\n}\n\n/**\n * Type guard recognising the marker envelope wrapping an encoded remote\n * failure payload.\n *\n * @internal Internal - do not use.\n */\nexport function is_serialized_remote_failure_envelope(\n value: unknown,\n): value is SerializedRemoteFailureEnvelope {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n EFFECT_REMOTE_ERROR_MARKER in value &&\n (value as Record<string, unknown>)[EFFECT_REMOTE_ERROR_MARKER] === true &&\n typeof (value as { encoded?: unknown }).encoded === \"string\",\n );\n}\n\n/**\n * Type guard for individual {@link FormIssue} values.\n *\n * @internal Internal - do not use.\n */\nexport function is_remote_validation_issue(\n value: unknown,\n): value is FormIssue {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { message?: unknown }).message === \"string\" &&\n Array.isArray((value as { path?: unknown }).path),\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAa,6BAA6B;;;;;;;AAO1C,MAAa,uBAAuB,OAAO,IACzC,6CACD;;;;;;AA4HD,SAAgB,kBACd,GAAG,QACoB;AACvB,QAAO;EACL,MAAM;EACN;EACD;;;;;;;;;;;;AAaH,SAAgB,2BACd,OACA,QAC8B;AAC9B,QAAO;EACL,MAAM;EACN;EACA;EACD;;;;;;;AAQH,SAAgB,+BACd,QACA,UAGI,EAAE,EACiB;AACvB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;;;;;;AAQH,SAAgB,yBACd,OACA,UAGI,EAAE,EACW;AACjB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;;;;;;AAQH,SAAgB,8BACd,OACA,MACsB;AACtB,QAAO;EACL,MAAM;EACN;EACA;EACD;;;;;;;;AASH,SAAgB,0CACd,SACiC;AACjC,QAAO;GACJ,6BAA6B;EAC9B;EACD;;;;;;;AAQH,SAAgB,cAAc,OAAoC;AAChE,QAAO,QACL,SACE,OAAO,UAAU,YAChB,MAA6B,SAAS,eACvC,MAAM,QAAS,MAA+B,OAAO,CACxD;;;;;;;;AASH,SAAgB,sCACd,OAC0C;AAC1C,QAAO,QACL,SACE,OAAO,UAAU,YAAA,8BACa,SAC7B,MAAA,gCAAkE,QACnE,OAAQ,MAAgC,YAAY,SACvD;;;;;;;AAQH,SAAgB,2BACd,OACoB;AACpB,QAAO,QACL,SACE,OAAO,UAAU,YACjB,OAAQ,MAAgC,YAAY,YACpD,MAAM,QAAS,MAA6B,KAAK,CACpD"}
|
|
@@ -6,6 +6,13 @@ interface TransformEffectScriptOptions extends EffectPreprocessOptions {
|
|
|
6
6
|
interface TransformEffectScriptResult {
|
|
7
7
|
code: string;
|
|
8
8
|
map: SourceMap;
|
|
9
|
+
relocations: Array<TransformRelocation>;
|
|
10
|
+
}
|
|
11
|
+
interface TransformRelocation {
|
|
12
|
+
originalStart: number;
|
|
13
|
+
originalEnd: number;
|
|
14
|
+
generatedStart: number;
|
|
15
|
+
generatedEnd: number;
|
|
9
16
|
}
|
|
10
17
|
export declare function transformEffectScript(content: string, options: TransformEffectScriptOptions): TransformEffectScriptResult;
|
|
11
18
|
export {};
|