svelte-effect-runtime 2.6.0 → 3.0.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-Cj2X9lY-.js → client-Cruhk6Oo.js} +12 -5
- package/.dist/chunks/client-Cruhk6Oo.js.map +1 -0
- package/.dist/chunks/{dispatcher-BVkm8qbG.js → dispatcher-CgCdn6bj.js} +12 -2
- package/.dist/chunks/{dispatcher-BVkm8qbG.js.map → dispatcher-CgCdn6bj.js.map} +1 -1
- package/.dist/chunks/dispatcher-FCsx1Hlh.js +22 -0
- package/.dist/chunks/dispatcher-FCsx1Hlh.js.map +1 -0
- package/.dist/chunks/runtime-Sl685BVb.js +79 -0
- package/.dist/chunks/runtime-Sl685BVb.js.map +1 -0
- package/.dist/chunks/{transform-PXwkylXd.js → transform-CebZMD6u.js} +14 -9
- package/.dist/chunks/transform-CebZMD6u.js.map +1 -0
- package/.dist/dispatcher.js +1 -1
- package/.dist/error.d.ts +1 -1
- package/.dist/generated/dispatcher.d.ts +13 -0
- package/.dist/generators.d.ts +4 -4
- package/.dist/internal/generators.d.ts +1 -1
- package/.dist/internal/generators.js +1 -1
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/markup/promise.d.ts +1 -1
- package/.dist/markup/promise.js +2 -2
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.d.ts +1 -1
- package/.dist/markup/run.js +2 -2
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/types.d.ts +1 -1
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.d.ts +1 -1
- package/.dist/markup/value.js +2 -2
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +1 -40
- package/.dist/mod.js +2 -27
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.js +5 -1
- package/.dist/remote/server.js.map +1 -1
- package/.dist/runtime/transform.d.ts +3 -1
- package/.dist/{chunks/preprocess-D84Ngmby.js → runtime/transform.js} +62 -8
- package/.dist/runtime/transform.js.map +1 -0
- package/.dist/{preprocess → script-transform}/imports.d.ts +1 -1
- package/.dist/{preprocess → script-transform}/types.d.ts +2 -2
- package/.dist/server/factories.d.ts +5 -1
- package/.dist/server/index.d.ts +1 -1
- package/.dist/server/runtime.d.ts +14 -0
- package/.dist/server/types.d.ts +44 -1
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +2 -56
- package/.dist/server.js.map +1 -1
- package/.dist/vite.js +9 -13
- package/.dist/vite.js.map +1 -1
- package/package.json +4 -4
- package/.dist/chunks/client-Cj2X9lY-.js.map +0 -1
- package/.dist/chunks/preprocess-D84Ngmby.js.map +0 -1
- package/.dist/chunks/transform-CHAnW68p.js +0 -72
- package/.dist/chunks/transform-CHAnW68p.js.map +0 -1
- package/.dist/chunks/transform-PXwkylXd.js.map +0 -1
- package/.dist/preprocess.d.ts +0 -2
- package/.dist/preprocess.js +0 -3
- package/.dist/runtime/preprocess.d.ts +0 -39
- package/.dist/runtime/preprocess.js +0 -31
- package/.dist/runtime/preprocess.js.map +0 -1
- /package/.dist/{preprocess → script-transform}/ast.d.ts +0 -0
- /package/.dist/{preprocess → script-transform}/index.d.ts +0 -0
- /package/.dist/{preprocess → script-transform}/lower.d.ts +0 -0
- /package/.dist/{preprocess → script-transform}/runes.d.ts +0 -0
- /package/.dist/{preprocess → script-transform}/runtime-block.d.ts +0 -0
- /package/.dist/{preprocess → script-transform}/source.d.ts +0 -0
package/.dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type {\n ErrorEffectFactory,\n RedirectEffectFactory,\n} from \"$/server/control-flow.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Result returned by the root Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Root preprocessor group shape. The root export keeps transform code lazy so\n * client imports do not pull parser-only dependencies into the browser.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(\n options: { content: string; filename?: string },\n ): MarkupResult | Promise<MarkupResult>;\n}\n\n/**\n * Public API surface for `svelte-effect-runtime`.\n *\n * Call {@link ClientRuntime.make} in `hooks.client.ts`, call\n * {@link ServerRuntime.make} in `hooks.server.ts`, and let the Vite plugin\n * route server-only helpers to the server entrypoint automatically.\n *\n * @module\n */\n\n/**\n * Client-side runtime singleton. Call `ClientRuntime.make(layer?)` once\n * in `hooks.client.ts` to provide services to every component's effect\n * blocks.\n *\n * If never called, a default empty-layer runtime is created lazily on\n * the first `yield*` expression.\n *\n * @example\n * ```ts\n * import { ClientRuntime } from \"svelte-effect-runtime\";\n * import { Db } from \"./db.ts\";\n *\n * ClientRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ClientRuntime {\n /**\n * Build and cache the client-side dispatcher runtime.\n *\n * @since 2.0.0\n * @param layer - Optional Effect layer to provide to the runtime.\n */\n static make<R = never>(layer?: Layer.Layer<R>): void {\n InternalDispatcher.make(layer);\n }\n}\n\n/**\n * Server-side runtime singleton export. In SvelteKit server files the Vite\n * plugin rewrites root imports to `svelte-effect-runtime/server`, so this\n * name resolves to the real server implementation before it is evaluated.\n *\n * @example\n * ```ts\n * import { ServerRuntime } from \"svelte-effect-runtime\";\n *\n * ServerRuntime.make();\n * ```\n *\n * @since 2.0.0\n */\nexport const ServerRuntime: ServerRuntimeFactory = make_server_only_class(\n \"ServerRuntime\",\n) as never;\n\n/**\n * Remote query factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Query } from \"svelte-effect-runtime\";\n *\n * export const GetPosts = Query(Effect.succeed([]));\n * ```\n *\n * @since 2.0.0\n */\nexport const Query: QueryFactory = Object.assign(\n make_server_only_function(\"Query\"),\n {\n batch: make_server_only_function(\"Query.batch\"),\n live: make_server_only_function(\"Query.live\"),\n },\n) as never;\n\n/**\n * Remote command factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Command } from \"svelte-effect-runtime\";\n *\n * export const SavePost = Command(Schema.String, (id) => Effect.succeed(id));\n * ```\n *\n * @since 2.0.0\n */\nexport const Command: CommandFactory = make_server_only_function(\n \"Command\",\n) as never;\n\n/**\n * SvelteKit HTTP error control-flow export for `.remote.ts` files imported\n * from the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Error } from \"svelte-effect-runtime\";\n *\n * return yield* Error(\"NotFound\", \"Post not found\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Error: ErrorEffectFactory = make_server_only_function(\n \"Error\",\n) as never;\n\n/**\n * Remote form factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Form } from \"svelte-effect-runtime\";\n *\n * export const CreatePost = Form(PostInput, ({ data }) => Effect.succeed(data));\n * ```\n *\n * @since 2.0.0\n */\nexport const Form: FormFactory = make_server_only_function(\n \"Form\",\n) as never;\n\n/**\n * Remote prerender factory export for `.remote.ts` files imported from the\n * root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Prerender } from \"svelte-effect-runtime\";\n *\n * export const GetBuildInfo = Prerender(() => Effect.succeed(\"ready\"));\n * ```\n *\n * @since 2.0.0\n */\nexport const Prerender: PrerenderFactory = make_server_only_function(\n \"Prerender\",\n) as never;\n\n/**\n * SvelteKit redirect control-flow export for `.remote.ts` files imported from\n * the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Redirect } from \"svelte-effect-runtime\";\n *\n * return yield* Redirect(\"SeeOther\", \"/posts\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Redirect: RedirectEffectFactory = make_server_only_function(\n \"Redirect\",\n) as never;\n\n/**\n * Current SvelteKit request event service export for `.remote.ts` files\n * imported from the root entrypoint. The Vite plugin rewrites it to the real\n * server implementation.\n *\n * @example\n * ```ts\n * import { RequestEvent } from \"svelte-effect-runtime\";\n *\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEventShape> =\n make_server_only_function(\"RequestEvent\") as never;\n\n/**\n * Returns the active server runtime when imported from a server file. The Vite\n * plugin rewrites root imports to the real server implementation.\n *\n * @example\n * ```ts\n * import { get_server_runtime_or_throw } from \"svelte-effect-runtime\";\n *\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n */\nexport const get_server_runtime_or_throw: () => ManagedRuntime.ManagedRuntime<\n unknown,\n never\n> = make_server_only_function(\"get_server_runtime_or_throw\") as never;\n\n/** Re-export error types users need for typed catch handlers. */\nexport type {\n FormError,\n FormIssue,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$/remote/shared.ts\";\n\nexport {\n is_form_error,\n is_remote_http_error,\n is_remote_transport_error,\n is_remote_validation_error,\n} from \"$/remote/shared.ts\";\n\n/** Re-export app setup helpers so users can import them from root. */\nexport { effect, type EffectOptions } from \"$/vite.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n ErrorEffectFactory,\n ErrorStatus,\n ErrorStatusName,\n RedirectEffectFactory,\n RedirectStatus,\n RedirectStatusName,\n} from \"$/server/control-flow.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n CommandFactory,\n EffectLike,\n EffectRemoteBatchHandler,\n EffectRemoteCommand,\n EffectRemoteForm,\n EffectRemoteFunction,\n EffectRemoteLiveQuery,\n EffectRemoteLiveQueryFunction,\n EffectRemoteLiveQueryResource,\n EffectRemoteLiveSource,\n EffectRemoteQuery,\n EffectRemoteQueryFunction,\n FormFactory,\n FormInvalid,\n PrerenderFactory,\n PrerenderOptions,\n QueryBatchFactory,\n QueryFactory,\n QueryLiveFactory,\n RemoteFormHandler,\n RemoteHandler,\n RemoteLiveHandler,\n SchemaEncodedInput,\n SchemaInput,\n ServerRuntimeFactory,\n StandardSchema,\n} from \"$/server/types.ts\";\n\n/**\n * Creates the Svelte preprocessor that lowers script and markup `yield*`\n * expressions. The heavy transform module is loaded lazily so browser imports\n * from the package root stay client-safe.\n *\n * @example\n * ```js\n * import { preprocess } from \"svelte-effect-runtime\";\n *\n * export default {\n * preprocess: [preprocess()],\n * };\n * ```\n *\n * @since 2.0.0\n * @returns A Svelte preprocessor group with an async markup hook.\n */\nexport function preprocess(): PreprocessGroup {\n return {\n name: \"svelte-effect-runtime\",\n\n async markup(options: { content: string; filename?: string }) {\n const runtime = await import(\"./runtime/preprocess.ts\");\n const group = runtime.preprocess();\n\n return await group.markup(options);\n },\n };\n}\n\nfunction make_server_only_class(name: string): unknown {\n return class ServerOnlyRuntime {\n static make(): never {\n throw make_server_only_error(name);\n }\n };\n}\n\nfunction make_server_only_function(\n name: string,\n): (...args: unknown[]) => never {\n return (..._args: unknown[]): never => {\n throw make_server_only_error(name);\n };\n}\n\nfunction make_server_only_error(name: string): globalThis.Error {\n return new globalThis.Error(\n `[SERVER_ONLY_IMPORT]: ${name} is only available in SvelteKit server files. ` +\n `Ensure the SER Vite plugin is enabled so root imports are rewritten ` +\n `to \\`svelte-effect-runtime/server\\` before evaluation.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,gBAAb,MAA2B;;;;;;;CAOzB,OAAO,KAAgB,OAA8B;EACnD,WAAmB,KAAK,KAAK;CAC/B;AACF;;;;;;;;;;;;;;;AAgBA,MAAa,gBAAsC,uBACjD,eACF;;;;;;;;;;;;;;AAeA,MAAa,QAAsB,OAAO,OACxC,0BAA0B,OAAO,GACjC;CACE,OAAO,0BAA0B,aAAa;CAC9C,MAAM,0BAA0B,YAAY;AAC9C,CACF;;;;;;;;;;;;;;AAeA,MAAa,UAA0B,0BACrC,SACF;;;;;;;;;;;;;;;AAgBA,MAAa,QAA4B,0BACvC,OACF;;;;;;;;;;;;;;AAeA,MAAa,OAAoB,0BAC/B,MACF;;;;;;;;;;;;;;;AAgBA,MAAa,YAA8B,0BACzC,WACF;;;;;;;;;;;;;;;AAgBA,MAAa,WAAkC,0BAC7C,UACF;;;;;;;;;;;;;;;AAgBA,MAAa,eACX,0BAA0B,cAAc;;;;;;;;;;;;;;AAe1C,MAAa,8BAGT,0BAA0B,6BAA6B;;;;;;;;;;;;;;;;;;AA+E3D,SAAgB,aAA8B;CAC5C,OAAO;EACL,MAAM;EAEN,MAAM,OAAO,SAAiD;GAI5D,OAAO,OAFO,MADQ,OAAO,4BACP,WAEL,EAAE,OAAO,OAAO;EACnC;CACF;AACF;AAEA,SAAS,uBAAuB,MAAuB;CACrD,OAAO,MAAM,kBAAkB;EAC7B,OAAO,OAAc;GACnB,MAAM,uBAAuB,IAAI;EACnC;CACF;AACF;AAEA,SAAS,0BACP,MAC+B;CAC/B,QAAQ,GAAG,UAA4B;EACrC,MAAM,uBAAuB,IAAI;CACnC;AACF;AAEA,SAAS,uBAAuB,MAAgC;CAC9D,OAAO,IAAI,WAAW,MACpB,yBAAyB,KAAK,yKAGhC;AACF"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type {\n ErrorEffectFactory,\n RedirectEffectFactory,\n} from \"$/server/control-flow.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Public API surface for `svelte-effect-runtime`.\n *\n * Call {@link ClientRuntime.make} in `hooks.client.ts`, call\n * {@link ServerRuntime.make} in `hooks.server.ts`, and let the Vite plugin\n * route server-only helpers to the server entrypoint automatically.\n *\n * @module\n */\n\n/**\n * Client-side runtime singleton. Call `ClientRuntime.make(layer?)` once\n * in `hooks.client.ts` to provide services to every component's effect\n * blocks.\n *\n * If never called, a default empty-layer runtime is created lazily on\n * the first `yield*` expression.\n *\n * @example\n * ```ts\n * import { ClientRuntime } from \"svelte-effect-runtime\";\n * import { Db } from \"./db.ts\";\n *\n * ClientRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ClientRuntime {\n /**\n * Build and cache the client-side dispatcher runtime.\n *\n * @since 2.0.0\n * @param layer - Optional Effect layer to provide to the runtime.\n */\n static make<R = never>(layer?: Layer.Layer<R>): void {\n InternalDispatcher.make(layer);\n }\n}\n\n/**\n * Server-side runtime singleton export. In SvelteKit server files the Vite\n * plugin rewrites root imports to `svelte-effect-runtime/server`, so this\n * name resolves to the real server implementation before it is evaluated.\n *\n * @example\n * ```ts\n * import { ServerRuntime } from \"svelte-effect-runtime\";\n *\n * ServerRuntime.make();\n * ```\n *\n * @since 2.0.0\n */\nexport const ServerRuntime: ServerRuntimeFactory = make_server_only_class(\n \"ServerRuntime\",\n) as never;\n\n/**\n * Remote query factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Query } from \"svelte-effect-runtime\";\n *\n * export const GetPosts = Query(Effect.succeed([]));\n * ```\n *\n * @since 2.0.0\n */\nexport const Query: QueryFactory = Object.assign(\n make_server_only_function(\"Query\"),\n {\n batch: make_server_only_function(\"Query.batch\"),\n live: make_server_only_function(\"Query.live\"),\n },\n) as never;\n\n/**\n * Remote command factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Command } from \"svelte-effect-runtime\";\n *\n * export const SavePost = Command(Schema.String, (id) => Effect.succeed(id));\n * ```\n *\n * @since 2.0.0\n */\nexport const Command: CommandFactory = make_server_only_function(\n \"Command\",\n) as never;\n\n/**\n * SvelteKit HTTP error control-flow export for `.remote.ts` files imported\n * from the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Error } from \"svelte-effect-runtime\";\n *\n * return yield* Error(\"NotFound\", \"Post not found\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Error: ErrorEffectFactory = make_server_only_function(\n \"Error\",\n) as never;\n\n/**\n * Remote form factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Form } from \"svelte-effect-runtime\";\n *\n * export const CreatePost = Form(PostInput, ({ data }) => Effect.succeed(data));\n * ```\n *\n * @since 2.0.0\n */\nexport const Form: FormFactory = make_server_only_function(\n \"Form\",\n) as never;\n\n/**\n * Remote prerender factory export for `.remote.ts` files imported from the\n * root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Prerender } from \"svelte-effect-runtime\";\n *\n * export const GetBuildInfo = Prerender(() => Effect.succeed(\"ready\"));\n * ```\n *\n * @since 2.0.0\n */\nexport const Prerender: PrerenderFactory = make_server_only_function(\n \"Prerender\",\n) as never;\n\n/**\n * SvelteKit redirect control-flow export for `.remote.ts` files imported from\n * the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Redirect } from \"svelte-effect-runtime\";\n *\n * return yield* Redirect(\"SeeOther\", \"/posts\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Redirect: RedirectEffectFactory = make_server_only_function(\n \"Redirect\",\n) as never;\n\n/**\n * Current SvelteKit request event service export for `.remote.ts` files\n * imported from the root entrypoint. The Vite plugin rewrites it to the real\n * server implementation.\n *\n * @example\n * ```ts\n * import { RequestEvent } from \"svelte-effect-runtime\";\n *\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEventShape> =\n make_server_only_function(\"RequestEvent\") as never;\n\n/**\n * Returns the active server runtime when imported from a server file. The Vite\n * plugin rewrites root imports to the real server implementation.\n *\n * @example\n * ```ts\n * import { get_server_runtime_or_throw } from \"svelte-effect-runtime\";\n *\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n */\nexport const get_server_runtime_or_throw: () => ManagedRuntime.ManagedRuntime<\n unknown,\n never\n> = make_server_only_function(\"get_server_runtime_or_throw\") as never;\n\n/** Re-export error types users need for typed catch handlers. */\nexport type {\n FormError,\n FormIssue,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$/remote/shared.ts\";\n\nexport {\n is_form_error,\n is_remote_http_error,\n is_remote_transport_error,\n is_remote_validation_error,\n} from \"$/remote/shared.ts\";\n\n/** Re-export app setup helpers so users can import them from root. */\nexport { effect, type EffectOptions } from \"$/vite.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n ErrorEffectFactory,\n ErrorStatus,\n ErrorStatusName,\n RedirectEffectFactory,\n RedirectStatus,\n RedirectStatusName,\n} from \"$/server/control-flow.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n CommandFactory,\n EffectLike,\n EffectRemoteBatchHandler,\n EffectRemoteCommand,\n EffectRemoteForm,\n EffectRemoteFunction,\n EffectRemoteLiveQuery,\n EffectRemoteLiveQueryFunction,\n EffectRemoteLiveQueryResource,\n EffectRemoteLiveSource,\n EffectRemoteQuery,\n EffectRemoteQueryFunction,\n FormFactory,\n FormInvalid,\n PrerenderFactory,\n PrerenderOptions,\n QueryBatchFactory,\n QueryFactory,\n QueryLiveFactory,\n RemoteFormHandler,\n RemoteHandler,\n RemoteLiveHandler,\n SchemaEncodedInput,\n SchemaInput,\n ServerRuntimeFactory,\n StandardSchema,\n StandardSchemaInput,\n StandardSchemaOutput,\n} from \"$/server/types.ts\";\n\nfunction make_server_only_class(name: string): unknown {\n return class ServerOnlyRuntime {\n static make(): never {\n throw make_server_only_error(name);\n }\n };\n}\n\nfunction make_server_only_function(\n name: string,\n): (...args: unknown[]) => never {\n return (..._args: unknown[]): never => {\n throw make_server_only_error(name);\n };\n}\n\nfunction make_server_only_error(name: string): globalThis.Error {\n return new globalThis.Error(\n `[SERVER_ONLY_IMPORT]: ${name} is only available in SvelteKit server files. ` +\n `Ensure the SER Vite plugin is enabled so root imports are rewritten ` +\n `to \\`svelte-effect-runtime/server\\` before evaluation.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,gBAAb,MAA2B;;;;;;;CAOzB,OAAO,KAAgB,OAA8B;EACnD,WAAmB,KAAK,KAAK;CAC/B;AACF;;;;;;;;;;;;;;;AAgBA,MAAa,gBAAsC,uBACjD,eACF;;;;;;;;;;;;;;AAeA,MAAa,QAAsB,OAAO,OACxC,0BAA0B,OAAO,GACjC;CACE,OAAO,0BAA0B,aAAa;CAC9C,MAAM,0BAA0B,YAAY;AAC9C,CACF;;;;;;;;;;;;;;AAeA,MAAa,UAA0B,0BACrC,SACF;;;;;;;;;;;;;;;AAgBA,MAAa,QAA4B,0BACvC,OACF;;;;;;;;;;;;;;AAeA,MAAa,OAAoB,0BAC/B,MACF;;;;;;;;;;;;;;;AAgBA,MAAa,YAA8B,0BACzC,WACF;;;;;;;;;;;;;;;AAgBA,MAAa,WAAkC,0BAC7C,UACF;;;;;;;;;;;;;;;AAgBA,MAAa,eACX,0BAA0B,cAAc;;;;;;;;;;;;;;AAe1C,MAAa,8BAGT,0BAA0B,6BAA6B;AAgE3D,SAAS,uBAAuB,MAAuB;CACrD,OAAO,MAAM,kBAAkB;EAC7B,OAAO,OAAc;GACnB,MAAM,uBAAuB,IAAI;EACnC;CACF;AACF;AAEA,SAAS,0BACP,MAC+B;CAC/B,QAAQ,GAAG,UAA4B;EACrC,MAAM,uBAAuB,IAAI;CACnC;AACF;AAEA,SAAS,uBAAuB,MAAgC;CAC9D,OAAO,IAAI,WAAW,MACpB,yBAAyB,KAAK,yKAGhC;AACF"}
|
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-Cruhk6Oo.js";
|
|
2
2
|
export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
|
package/.dist/remote/server.js
CHANGED
|
@@ -37,7 +37,11 @@ function handle_failure(cause, invalid, error) {
|
|
|
37
37
|
if (is_sveltekit_control_flow(defect)) throw defect;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Phase 2 —
|
|
40
|
+
* Phase 2 — let cancellation escape without becoming a remote failure.
|
|
41
|
+
*/
|
|
42
|
+
if (Cause.hasInterruptsOnly(cause)) throw Cause.squash(cause);
|
|
43
|
+
/**
|
|
44
|
+
* Phase 3 — preserve typed form validation failures.
|
|
41
45
|
*/
|
|
42
46
|
for (const reason of reasons) if (Cause.isFailReason(reason)) {
|
|
43
47
|
const failure = reason.error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { Cause, Effect, Exit } from \"effect\";\nimport { stringify } from \"devalue\";\n\ntype CauseReason = {\n readonly _tag: string;\n readonly defect?: unknown;\n readonly error?: unknown;\n};\n\n/**\n * Runs a user-supplied Effect program through a ManagedRuntime, maps its\n * exit into the shape expected by SvelteKit, and returns the result or\n * throws a SvelteKit-compatible error.\n *\n * @since 2.0.0\n * @param effect - The Effect program to execute.\n * @param runtime - The server-side ManagedRuntime.\n * @param invalid - SvelteKit's `invalid` helper (bound per-request).\n * @param error - SvelteKit's `error` helper.\n * @returns A Promise that resolves with the effect's success value.\n * @internal\n */\nexport async function run_remote_effect<A>(\n effect: Effect.Effect<A, unknown, unknown>,\n runtime: {\n runPromise: (\n e: Effect.Effect<unknown, unknown, unknown>,\n ) => Promise<unknown>;\n },\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): Promise<A> {\n const exit: Exit.Exit<A, unknown> = await runtime.runPromise(\n Effect.exit(effect) as Effect.Effect<unknown, unknown, unknown>,\n ) as Exit.Exit<A, unknown>;\n\n if (Exit.isSuccess(exit)) {\n return exit.value;\n }\n\n handle_failure(exit.cause, invalid, error);\n}\n\n/**\n * Inspects the Effect Cause for failures and either throws a form\n * validation error (via SvelteKit's `invalid`) or encodes the error\n * and throws it via SvelteKit's `error`.\n */\nfunction handle_failure(\n cause: Cause.Cause<unknown>,\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): never {\n const reasons = get_cause_reasons(cause);\n\n /**\n * Phase 1 — let SvelteKit's thrown control-flow sentinels escape.\n */\n for (const reason of reasons) {\n if (!Cause.isDieReason(reason as never)) {\n continue;\n }\n\n const defect = reason.defect;\n\n if (is_sveltekit_control_flow(defect)) {\n throw defect;\n }\n }\n\n /**\n * Phase 2 — preserve typed form validation failures.\n */\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n if (\n typeof failure === \"object\" &&\n failure !== null &&\n (failure as Record<string, unknown>)._tag === \"FormError\"\n ) {\n const issues = (failure as { issues?: readonly FormIssue[] }).issues ??\n [];\n invalid(400, { issues });\n }\n }\n }\n\n /**\n * Phase 3 — encode all other failures for the remote client.\n */\n const encoded = encode_remote_failure(cause);\n const envelope = create_serialized_remote_failure_envelope(encoded);\n\n error(500, envelope);\n}\n\n/**\n * Encodes an Effect Cause into a string that the client-side adapter can\n * decode back into a typed `RemoteFailure`.\n *\n * @since 2.0.0\n * @param cause - The Effect Cause from a failed execution.\n * @returns A devalue-encoded string representing the serialised failure.\n * @internal\n */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n const reasons = get_cause_reasons(cause);\n\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n\n const encoded = stringify_failure(failure);\n\n if (encoded !== undefined) {\n return encoded;\n }\n\n const serializable_failure = to_serializable_failure(failure);\n const serializable_encoded = stringify_failure(serializable_failure);\n\n if (serializable_encoded !== undefined) {\n return serializable_encoded;\n }\n }\n }\n\n return stringify({ message: \"[UNKNOWN_REMOTE_FAILURE]: Unknown error\" });\n}\n\nfunction get_cause_reasons(\n cause: Cause.Cause<unknown>,\n): readonly CauseReason[] {\n const reasons = (cause as unknown as { reasons?: readonly CauseReason[] })\n .reasons;\n\n return reasons ?? [];\n}\n\nfunction is_sveltekit_control_flow(value: unknown): boolean {\n return isRedirect(value) || isHttpError(value) || isValidationError(value);\n}\n\nfunction stringify_failure(value: unknown): string | undefined {\n try {\n return stringify(value);\n } catch {\n return undefined;\n }\n}\n\nfunction to_serializable_failure(\n value: unknown,\n seen = new WeakSet<object>(),\n): unknown {\n if (typeof value === \"function\" || typeof value === \"symbol\") {\n return undefined;\n }\n\n if (!is_object_like(value)) {\n return value;\n }\n\n if (stringify_failure(value) !== undefined) {\n return value;\n }\n\n if (seen.has(value)) {\n return undefined;\n }\n\n seen.add(value);\n\n const serializable = Array.isArray(value)\n ? value.map((item) => to_serializable_failure(item, seen))\n : to_plain_record(value, seen);\n\n seen.delete(value);\n\n return serializable;\n}\n\nfunction to_plain_record(\n value: object,\n seen: WeakSet<object>,\n): Record<string, unknown> {\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const record: Record<string, unknown> = {};\n\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (key === \"stack\" || !(\"value\" in descriptor)) {\n continue;\n }\n\n record[key] = to_serializable_failure(descriptor.value, seen);\n }\n\n if (value instanceof Error && !(\"message\" in record)) {\n record.message = value.message;\n }\n\n return record;\n}\n\nfunction is_object_like(value: unknown): value is object {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Throws a SvelteKit `invalid` response from a {@link FormError}, calling\n * through to the request-scoped `invalid` helper.\n *\n * @example\n * ```ts\n * throw_form_error(\n * [{ message: \"Name is required\", path: [\"name\"] }],\n * invalid,\n * );\n * ```\n *\n * @since 2.0.0\n * @param issues - The list of form validation issues.\n * @param invalid - SvelteKit's `invalid` helper bound to the current request.\n * @internal\n */\nexport function throw_form_error(\n issues: readonly FormIssue[],\n invalid: (status: number, body: unknown) => never,\n): never {\n invalid(400, { issues });\n}\n\n/**\n * Remaps low-level SvelteKit errors (e.g. \"Cannot use ___ outside a route\")\n * into clear, actionable messages.\n *\n * @example\n * ```ts\n * try {\n * return native_query(handler);\n * } catch (err) {\n * throw normalize_remote_helper_error(err, \"Query\");\n * }\n * ```\n *\n * @since 2.0.0\n * @param err - The error thrown by SvelteKit's native functions.\n * @param helper_name - Name of the helper that triggered the error.\n * @returns A more descriptive error.\n * @internal\n */\nexport function normalize_remote_helper_error(\n err: unknown,\n helper_name: string,\n): globalThis.Error {\n const message = err instanceof Error ? err.message : String(err);\n\n if (message.includes(\"Cannot use\") || message.includes(\"outside a route\")) {\n return new globalThis.Error(\n `[REMOTE_HELPER_CONTEXT]: ${helper_name} was called outside a .remote.ts file. ` +\n `Ensure the file is named \\`*.remote.ts\\` and is located in a route directory.`,\n );\n }\n\n return err instanceof Error\n ? err\n : new globalThis.Error(`[REMOTE_HELPER_ERROR]: ${message}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAy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AW,MAAM,0BAA0B,SAAS;AAC9D"}
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { Cause, Effect, Exit } from \"effect\";\nimport { stringify } from \"devalue\";\n\ntype CauseReason = {\n readonly _tag: string;\n readonly defect?: unknown;\n readonly error?: unknown;\n};\n\n/**\n * Runs a user-supplied Effect program through a ManagedRuntime, maps its\n * exit into the shape expected by SvelteKit, and returns the result or\n * throws a SvelteKit-compatible error.\n *\n * @since 2.0.0\n * @param effect - The Effect program to execute.\n * @param runtime - The server-side ManagedRuntime.\n * @param invalid - SvelteKit's `invalid` helper (bound per-request).\n * @param error - SvelteKit's `error` helper.\n * @returns A Promise that resolves with the effect's success value.\n * @internal\n */\nexport async function run_remote_effect<A>(\n effect: Effect.Effect<A, unknown, unknown>,\n runtime: {\n runPromise: (\n e: Effect.Effect<unknown, unknown, unknown>,\n ) => Promise<unknown>;\n },\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): Promise<A> {\n const exit: Exit.Exit<A, unknown> = await runtime.runPromise(\n Effect.exit(effect) as Effect.Effect<unknown, unknown, unknown>,\n ) as Exit.Exit<A, unknown>;\n\n if (Exit.isSuccess(exit)) {\n return exit.value;\n }\n\n handle_failure(exit.cause, invalid, error);\n}\n\n/**\n * Inspects the Effect Cause for failures and either throws a form\n * validation error (via SvelteKit's `invalid`) or encodes the error\n * and throws it via SvelteKit's `error`.\n */\nfunction handle_failure(\n cause: Cause.Cause<unknown>,\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): never {\n const reasons = get_cause_reasons(cause);\n\n /**\n * Phase 1 — let SvelteKit's thrown control-flow sentinels escape.\n */\n for (const reason of reasons) {\n if (!Cause.isDieReason(reason as never)) {\n continue;\n }\n\n const defect = reason.defect;\n\n if (is_sveltekit_control_flow(defect)) {\n throw defect;\n }\n }\n\n /**\n * Phase 2 — let cancellation escape without becoming a remote failure.\n */\n if (Cause.hasInterruptsOnly(cause)) {\n throw Cause.squash(cause);\n }\n\n /**\n * Phase 3 — preserve typed form validation failures.\n */\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n if (\n typeof failure === \"object\" &&\n failure !== null &&\n (failure as Record<string, unknown>)._tag === \"FormError\"\n ) {\n const issues = (failure as { issues?: readonly FormIssue[] }).issues ??\n [];\n invalid(400, { issues });\n }\n }\n }\n\n /**\n * Phase 4 — encode all other failures for the remote client.\n */\n const encoded = encode_remote_failure(cause);\n const envelope = create_serialized_remote_failure_envelope(encoded);\n\n error(500, envelope);\n}\n\n/**\n * Encodes an Effect Cause into a string that the client-side adapter can\n * decode back into a typed `RemoteFailure`.\n *\n * @since 2.0.0\n * @param cause - The Effect Cause from a failed execution.\n * @returns A devalue-encoded string representing the serialised failure.\n * @internal\n */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n const reasons = get_cause_reasons(cause);\n\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n\n const encoded = stringify_failure(failure);\n\n if (encoded !== undefined) {\n return encoded;\n }\n\n const serializable_failure = to_serializable_failure(failure);\n const serializable_encoded = stringify_failure(serializable_failure);\n\n if (serializable_encoded !== undefined) {\n return serializable_encoded;\n }\n }\n }\n\n return stringify({ message: \"[UNKNOWN_REMOTE_FAILURE]: Unknown error\" });\n}\n\nfunction get_cause_reasons(\n cause: Cause.Cause<unknown>,\n): readonly CauseReason[] {\n const reasons = (cause as unknown as { reasons?: readonly CauseReason[] })\n .reasons;\n\n return reasons ?? [];\n}\n\nfunction is_sveltekit_control_flow(value: unknown): boolean {\n return isRedirect(value) || isHttpError(value) || isValidationError(value);\n}\n\nfunction stringify_failure(value: unknown): string | undefined {\n try {\n return stringify(value);\n } catch {\n return undefined;\n }\n}\n\nfunction to_serializable_failure(\n value: unknown,\n seen = new WeakSet<object>(),\n): unknown {\n if (typeof value === \"function\" || typeof value === \"symbol\") {\n return undefined;\n }\n\n if (!is_object_like(value)) {\n return value;\n }\n\n if (stringify_failure(value) !== undefined) {\n return value;\n }\n\n if (seen.has(value)) {\n return undefined;\n }\n\n seen.add(value);\n\n const serializable = Array.isArray(value)\n ? value.map((item) => to_serializable_failure(item, seen))\n : to_plain_record(value, seen);\n\n seen.delete(value);\n\n return serializable;\n}\n\nfunction to_plain_record(\n value: object,\n seen: WeakSet<object>,\n): Record<string, unknown> {\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const record: Record<string, unknown> = {};\n\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (key === \"stack\" || !(\"value\" in descriptor)) {\n continue;\n }\n\n record[key] = to_serializable_failure(descriptor.value, seen);\n }\n\n if (value instanceof Error && !(\"message\" in record)) {\n record.message = value.message;\n }\n\n return record;\n}\n\nfunction is_object_like(value: unknown): value is object {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Throws a SvelteKit `invalid` response from a {@link FormError}, calling\n * through to the request-scoped `invalid` helper.\n *\n * @example\n * ```ts\n * throw_form_error(\n * [{ message: \"Name is required\", path: [\"name\"] }],\n * invalid,\n * );\n * ```\n *\n * @since 2.0.0\n * @param issues - The list of form validation issues.\n * @param invalid - SvelteKit's `invalid` helper bound to the current request.\n * @internal\n */\nexport function throw_form_error(\n issues: readonly FormIssue[],\n invalid: (status: number, body: unknown) => never,\n): never {\n invalid(400, { issues });\n}\n\n/**\n * Remaps low-level SvelteKit errors (e.g. \"Cannot use ___ outside a route\")\n * into clear, actionable messages.\n *\n * @example\n * ```ts\n * try {\n * return native_query(handler);\n * } catch (err) {\n * throw normalize_remote_helper_error(err, \"Query\");\n * }\n * ```\n *\n * @since 2.0.0\n * @param err - The error thrown by SvelteKit's native functions.\n * @param helper_name - Name of the helper that triggered the error.\n * @returns A more descriptive error.\n * @internal\n */\nexport function normalize_remote_helper_error(\n err: unknown,\n helper_name: string,\n): globalThis.Error {\n const message = err instanceof Error ? err.message : String(err);\n\n if (message.includes(\"Cannot use\") || message.includes(\"outside a route\")) {\n return new globalThis.Error(\n `[REMOTE_HELPER_CONTEXT]: ${helper_name} was called outside a .remote.ts file. ` +\n `Ensure the file is named \\`*.remote.ts\\` and is located in a route directory.`,\n );\n }\n\n return err instanceof Error\n ? err\n : new globalThis.Error(`[REMOTE_HELPER_ERROR]: ${message}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,eAAsB,kBACpB,QACA,SAKA,SACA,OACY;CACZ,MAAM,OAA8B,MAAM,QAAQ,WAChD,OAAO,KAAK,MAAM,CACpB;CAEA,IAAI,KAAK,UAAU,IAAI,GACrB,OAAO,KAAK;CAGd,eAAe,KAAK,OAAO,SAAS,KAAK;AAC3C;;;;;;AAOA,SAAS,eACP,OACA,SACA,OACO;CACP,MAAM,UAAU,kBAAkB,KAAK;;;;CAKvC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,CAAC,MAAM,YAAY,MAAe,GACpC;EAGF,MAAM,SAAS,OAAO;EAEtB,IAAI,0BAA0B,MAAM,GAClC,MAAM;CAEV;;;;CAKA,IAAI,MAAM,kBAAkB,KAAK,GAC/B,MAAM,MAAM,OAAO,KAAK;;;;CAM1B,KAAK,MAAM,UAAU,SACnB,IAAI,MAAM,aAAa,MAAe,GAAG;EACvC,MAAM,UAAU,OAAO;EACvB,IACE,OAAO,YAAY,YACnB,YAAY,QACX,QAAoC,SAAS,aAI9C,QAAQ,KAAK,EAAE,QAFC,QAA8C,UAC5D,CAAC,EACmB,CAAC;CAE3B;CASF,MAAM,KAFW,0CADD,sBAAsB,KAC2B,CAE/C,CAAC;AACrB;;;;;;;;;;AAWA,SAAgB,sBAAsB,OAAqC;CACzE,MAAM,UAAU,kBAAkB,KAAK;CAEvC,KAAK,MAAM,UAAU,SACnB,IAAI,M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AM;CAGzB,OAAO;AACT;AAEA,SAAS,eAAe,OAAiC;CACvD,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBACd,QACA,SACO;CACP,QAAQ,KAAK,EAAE,OAAO,CAAC;AACzB;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,8BACd,KACA,aACkB;CAClB,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;CAE/D,IAAI,QAAQ,SAAS,YAAY,KAAK,QAAQ,SAAS,iBAAiB,GACtE,OAAO,IAAI,WAAW,MACpB,4BAA4B,YAAY,qHAE1C;CAGF,OAAO,eAAe,QAClB,MACA,IAAI,WAAW,MAAM,0BAA0B,SAAS;AAC9D"}
|
|
@@ -15,7 +15,7 @@ export interface SvelteTransformResult {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Lowers SER syntax in a complete Svelte component without using Svelte's
|
|
18
|
-
*
|
|
18
|
+
* adapter API.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
@@ -33,3 +33,5 @@ export interface SvelteTransformResult {
|
|
|
33
33
|
* @returns The transformed component source.
|
|
34
34
|
*/
|
|
35
35
|
export declare function transform_svelte_effect(content: string, filename?: string): SvelteTransformResult;
|
|
36
|
+
export { type MarkupTransformResult, transform_markup_effect, } from "../markup/transform.js";
|
|
37
|
+
export { type BlockRef, type ScriptTransformResult, transform_script_effect, } from "../script-transform/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as find_yield_star_node, c as AsyncEffectInSyncRuneError, d as collect_top_level_binding_names, f as has_local_import_binding, i as extract_binding_names, l as AwaitInEffectWorkError, n as collect_yield_star_nodes, o as is_yield_star_expression, p as make_imports, r as contains_top_level_await, s as collect_free_identifiers, u as PreprocessError } from "
|
|
1
|
+
import { a as find_yield_star_node, c as AsyncEffectInSyncRuneError, d as collect_top_level_binding_names, f as has_local_import_binding, i as extract_binding_names, l as AwaitInEffectWorkError, n as collect_yield_star_nodes, o as is_yield_star_expression, p as make_imports, r as contains_top_level_await, s as collect_free_identifiers, t as transform_markup_effect, u as PreprocessError } from "../chunks/transform-CebZMD6u.js";
|
|
2
2
|
import { contains_top_level_yield_star } from "../detect.js";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
4
|
import ts from "typescript";
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/script-transform/source.ts
|
|
6
6
|
/**
|
|
7
7
|
* Creates a source map from transformed script back to the original block.
|
|
8
8
|
*
|
|
@@ -41,7 +41,7 @@ function slice_start(content, node) {
|
|
|
41
41
|
return content.slice(node.getStart(), node.end);
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
|
-
//#region src/
|
|
44
|
+
//#region src/script-transform/runtime-block.ts
|
|
45
45
|
/**
|
|
46
46
|
* Builds the runtime blocks appended to lowered script effect code with
|
|
47
47
|
* explicit runtime import bindings.
|
|
@@ -79,7 +79,7 @@ function merge_effect_blocks(blocks) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
//#endregion
|
|
82
|
-
//#region src/
|
|
82
|
+
//#region src/script-transform/runes.ts
|
|
83
83
|
const ASYNC_EXPRESSION_RUNES = new Set([
|
|
84
84
|
"$derived",
|
|
85
85
|
"$inspect",
|
|
@@ -154,7 +154,7 @@ function is_rune_root(name) {
|
|
|
154
154
|
return name === "$bindable" || name === "$derived" || name === "$effect" || name === "$host" || name === "$inspect" || name === "$props" || name === "$state";
|
|
155
155
|
}
|
|
156
156
|
//#endregion
|
|
157
|
-
//#region src/
|
|
157
|
+
//#region src/script-transform/lower.ts
|
|
158
158
|
/**
|
|
159
159
|
* Delegates a statement to the correct lowerer based on syntax kind.
|
|
160
160
|
*
|
|
@@ -493,7 +493,7 @@ function collect_assignment_target_names(node) {
|
|
|
493
493
|
return [];
|
|
494
494
|
}
|
|
495
495
|
//#endregion
|
|
496
|
-
//#region src/
|
|
496
|
+
//#region src/script-transform/index.ts
|
|
497
497
|
/**
|
|
498
498
|
* Transforms a `<script effect>` body by extracting top-level `yield*`
|
|
499
499
|
* expressions into `$state` temp bindings and wrapping the lowered
|
|
@@ -651,6 +651,60 @@ function make_generated_name(hint, suffix) {
|
|
|
651
651
|
return `__SER___${/^[A-Za-z_$]/.test(normalized_hint) ? normalized_hint : `temp_${normalized_hint}`}${suffix}`;
|
|
652
652
|
}
|
|
653
653
|
//#endregion
|
|
654
|
-
|
|
654
|
+
//#region src/runtime/transform.ts
|
|
655
|
+
/**
|
|
656
|
+
* Lowers SER syntax in a complete Svelte component without using Svelte's
|
|
657
|
+
* adapter API.
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* const result = transform_svelte_effect(
|
|
662
|
+
* "<script effect>const value = yield* load()<\/script>",
|
|
663
|
+
* "App.svelte",
|
|
664
|
+
* );
|
|
665
|
+
* ```
|
|
666
|
+
*
|
|
667
|
+
* @since 2.5.0
|
|
668
|
+
* @param content - Full Svelte component source to lower before Svelte parses
|
|
669
|
+
* it.
|
|
670
|
+
* @param filename - Component filename used in generated cache identifiers and
|
|
671
|
+
* diagnostics.
|
|
672
|
+
* @returns The transformed component source.
|
|
673
|
+
*/
|
|
674
|
+
function transform_svelte_effect(content, filename = "unknown.svelte") {
|
|
675
|
+
const script = find_script(content);
|
|
676
|
+
let combined = content;
|
|
677
|
+
if (script?.has_effect) {
|
|
678
|
+
const result = transform_script_effect(script.text, filename, { emit_types: script.is_typescript });
|
|
679
|
+
combined = content.slice(0, script.effect_attr_start) + content.slice(script.effect_attr_end, script.open_end) + result.code + content.slice(script.close_start);
|
|
680
|
+
}
|
|
681
|
+
return { code: transform_markup_effect(combined, filename).code };
|
|
682
|
+
}
|
|
683
|
+
function find_script(content) {
|
|
684
|
+
for (const match of content.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)) {
|
|
685
|
+
if (match.index === void 0 || /\bmodule\b/.test(match[1] ?? "")) continue;
|
|
686
|
+
const attrs = match[1] ?? "";
|
|
687
|
+
const effect_match = /\s+effect(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?/.exec(attrs);
|
|
688
|
+
const open_end = match.index + match[0].indexOf(">") + 1;
|
|
689
|
+
const attr_start = effect_match?.index ?? attrs.length;
|
|
690
|
+
const attr_end = attr_start + (effect_match?.[0].length ?? 0);
|
|
691
|
+
return {
|
|
692
|
+
text: match[2],
|
|
693
|
+
open_end,
|
|
694
|
+
close_start: match.index + match[0].lastIndexOf("<"),
|
|
695
|
+
has_effect: effect_match !== null,
|
|
696
|
+
effect_attr_start: match.index + 7 + attr_start,
|
|
697
|
+
effect_attr_end: match.index + 7 + attr_end,
|
|
698
|
+
is_typescript: has_typescript_lang(attrs)
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function has_typescript_lang(attrs) {
|
|
703
|
+
const lang_match = /\blang\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);
|
|
704
|
+
const lang = (lang_match?.[1] ?? lang_match?.[2] ?? lang_match?.[3] ?? "").toLowerCase();
|
|
705
|
+
return lang === "ts" || lang === "typescript";
|
|
706
|
+
}
|
|
707
|
+
//#endregion
|
|
708
|
+
export { transform_markup_effect, transform_script_effect, transform_svelte_effect };
|
|
655
709
|
|
|
656
|
-
//# sourceMappingURL=
|
|
710
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/script-transform/source.ts","../../../modules/svelte-effect-runtime/src/script-transform/runtime-block.ts","../../../modules/svelte-effect-runtime/src/script-transform/runes.ts","../../../modules/svelte-effect-runtime/src/script-transform/lower.ts","../../../modules/svelte-effect-runtime/src/script-transform/index.ts","../../../modules/svelte-effect-runtime/src/runtime/transform.ts"],"sourcesContent":["import type MagicString from \"magic-string\";\nimport type ts from \"typescript\";\n\n/**\n * Creates a source map from transformed script back to the original block.\n *\n * @since 2.0.0\n * @param magic - MagicString instance holding the transformed source.\n * @param filename - Source filename used for the source map entry.\n * @returns A plain source map object.\n */\nexport function create_source_map(\n magic: MagicString,\n filename: string,\n): Record<string, unknown> {\n const map = magic.generateMap({\n hires: true,\n includeContent: true,\n source: filename,\n });\n\n return map as unknown as Record<string, unknown>;\n}\n\n/**\n * Slices a substring matching a node's full source range.\n *\n * @since 2.0.0\n * @param content - Original source text.\n * @param node - AST node whose full range should be extracted.\n * @returns Source text including leading trivia.\n */\nexport function slice(content: string, node: ts.Node): string {\n return content.slice(node.getFullStart(), node.end);\n}\n\n/**\n * Slices a substring matching a node's source range without leading trivia.\n *\n * @since 2.0.0\n * @param content - Original source text.\n * @param node - AST node whose non-trivia range should be extracted.\n * @returns Source text excluding leading trivia.\n */\nexport function slice_start(content: string, node: ts.Node): string {\n return content.slice(node.getStart(), node.end);\n}\n","import type { EffectBlock, RuntimeImportBindings } from \"./types.ts\";\n\n/**\n * Builds the runtime blocks appended to lowered script effect code.\n *\n * @since 2.0.0\n * @param blocks - Effect bodies and dependency reads to emit.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block(blocks: EffectBlock[]): string {\n const bindings: RuntimeImportBindings = {\n cancel: \"__SER___cancel\",\n dispatcher: \"get_dispatcher\",\n dispatcher_value: \"__SER___dispatcher\",\n effect: \"Effect\",\n program: \"__SER___program\",\n untrack: \"untrack\",\n };\n\n return make_runtime_block_with_bindings(blocks, bindings);\n}\n\n/**\n * Builds the runtime blocks appended to lowered script effect code with\n * explicit runtime import bindings.\n *\n * @since 2.4.2\n * @param blocks - Effect bodies and dependency reads to emit.\n * @param bindings - Runtime binding names available in the generated code.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block_with_bindings(\n blocks: EffectBlock[],\n bindings: RuntimeImportBindings,\n): string {\n const merged_block = merge_effect_blocks(blocks);\n const dep_reads = merged_block.deps.map((dep) => ` ${dep};`);\n\n const body = merged_block.statements\n .map((statement) => ` ${statement}`)\n .join(\"\\n\");\n\n return [\n \"\",\n \"$effect(() => {\",\n ...dep_reads,\n ` const ${bindings.dispatcher_value} = ${bindings.dispatcher}();`,\n ` const ${bindings.program} = ${bindings.effect}.gen(function* () {`,\n body,\n \" });\",\n ` const ${bindings.cancel} = ${bindings.untrack}(() => ${bindings.dispatcher_value}.fork(${bindings.program}));`,\n ` import.meta.hot?.dispose(${bindings.cancel});`,\n ` return ${bindings.cancel};`,\n \"});\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction merge_effect_blocks(blocks: EffectBlock[]): EffectBlock {\n const statements = blocks.flatMap((block) => block.statements);\n const deps = blocks.flatMap((block) => block.deps);\n\n return {\n statements,\n deps: [...new Set(deps)],\n };\n}\n","import { contains_top_level_yield_star } from \"$/detect.ts\";\nimport { AsyncEffectInSyncRuneError } from \"$/error.ts\";\nimport { slice } from \"./source.ts\";\n\nimport ts from \"typescript\";\n\nconst ASYNC_EXPRESSION_RUNES = new Set([\n \"$derived\",\n \"$inspect\",\n \"$state\",\n \"$state.raw\",\n]);\n\nconst CALLBACK_RUNES = new Set([\n \"$derived.by\",\n \"$effect\",\n \"$effect.pre\",\n \"$effect.root\",\n]);\n\n/**\n * Validates that `yield*` only appears in rune positions the script-effect\n * transform can lower without changing the rune's normal Svelte contract.\n *\n * @since 2.0.0\n * @param node - AST node to scan.\n * @param content - Original script source used for diagnostics.\n * @param filename - Source filename used for diagnostics.\n * @returns Nothing.\n */\nexport function validate_rune_yield_usage(\n node: ts.Node,\n content: string,\n filename: string,\n): void {\n visit_rune_yield_usage(node, content, filename);\n}\n\n/**\n * Identifies `$state(...)` and `$state.raw(...)` initializer calls.\n *\n * @since 2.0.0\n * @param expr - Expression to classify.\n * @param content - Original script source used to preserve argument text.\n * @returns State rune details when the expression is a state initializer.\n */\nexport function get_state_rune_initializer(\n expr: ts.Expression,\n content: string,\n): { rune_name: \"$state\" | \"$state.raw\"; value_text: string } | undefined {\n if (!ts.isCallExpression(expr)) {\n return undefined;\n }\n\n const rune_name = get_rune_name(expr.expression);\n\n if (rune_name !== \"$state\" && rune_name !== \"$state.raw\") {\n return undefined;\n }\n\n const first_arg = expr.arguments[0];\n\n if (!first_arg) {\n return undefined;\n }\n\n return {\n rune_name,\n value_text: slice(content, first_arg).trim(),\n };\n}\n\nfunction visit_rune_yield_usage(\n node: ts.Node,\n content: string,\n filename: string,\n): void {\n if (ts.isCallExpression(node)) {\n validate_call_expression(node, content, filename);\n }\n\n node.forEachChild((child) => {\n visit_rune_yield_usage(child, content, filename);\n });\n}\n\nfunction validate_call_expression(\n call: ts.CallExpression,\n content: string,\n filename: string,\n): void {\n const rune_name = get_rune_name(call.expression);\n\n if (!rune_name) {\n return;\n }\n\n if (\n !ASYNC_EXPRESSION_RUNES.has(rune_name) &&\n contains_top_level_yield_star(call)\n ) {\n throw new AsyncEffectInSyncRuneError(\n rune_name,\n slice(content, call),\n filename,\n );\n }\n\n if (!CALLBACK_RUNES.has(rune_name)) {\n return;\n }\n\n const callback = call.arguments[0];\n\n if (!callback || !callback_has_top_level_yield_star(callback)) {\n return;\n }\n\n throw new AsyncEffectInSyncRuneError(\n rune_name,\n slice(content, call),\n filename,\n );\n}\n\nfunction callback_has_top_level_yield_star(node: ts.Expression): boolean {\n if (\n (ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node)) &&\n node.body !== undefined\n ) {\n return contains_top_level_yield_star(node.body);\n }\n\n return contains_top_level_yield_star(node);\n}\n\nfunction get_rune_name(expr: ts.Expression): string | undefined {\n if (ts.isIdentifier(expr) && is_rune_root(expr.text)) {\n return expr.text;\n }\n\n if (!ts.isPropertyAccessExpression(expr)) {\n return undefined;\n }\n\n const root_name = get_rune_name(expr.expression);\n\n if (!root_name) {\n return undefined;\n }\n\n return `${root_name}.${expr.name.text}`;\n}\n\nfunction is_rune_root(name: string): boolean {\n return (\n name === \"$bindable\" ||\n name === \"$derived\" ||\n name === \"$effect\" ||\n name === \"$host\" ||\n name === \"$inspect\" ||\n name === \"$props\" ||\n name === \"$state\"\n );\n}\n","import { collect_free_identifiers } from \"$/markup/transform/expressions.ts\";\nimport { contains_top_level_yield_star } from \"$/detect.ts\";\nimport {\n collect_yield_star_nodes,\n extract_binding_names,\n find_yield_star_node,\n is_yield_star_expression,\n} from \"./ast.ts\";\nimport { get_state_rune_initializer } from \"./runes.ts\";\nimport { slice, slice_start } from \"./source.ts\";\nimport type {\n EffectBlock,\n LoweredExpression,\n LoweredStatement,\n ScriptLoweringContext,\n TempBinding,\n} from \"./types.ts\";\n\nimport ts from \"typescript\";\n\n/**\n * Delegates a statement to the correct lowerer based on syntax kind.\n *\n * @since 2.0.0\n * @param stmt - Statement to lower.\n * @param content - Original source text.\n * @param context - Lowering services for this transform pass.\n * @returns Lowered statement descriptor.\n */\nexport function lower_statement(\n stmt: ts.Statement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n if (ts.isExpressionStatement(stmt)) {\n return lower_expression_statement(stmt, content, context);\n }\n\n if (ts.isVariableStatement(stmt)) {\n return lower_variable_statement(stmt, content, context);\n }\n\n const text = slice(content, stmt);\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [make_effect_block([text], collect_deps(text))],\n range: { start: stmt.getFullStart(), end: stmt.end },\n };\n}\n\nfunction lower_variable_statement(\n stmt: ts.VariableStatement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n const temps: TempBinding[] = [];\n const type_helpers: string[] = [];\n const rewritten_decls: string[] = [];\n const statements: string[] = [];\n const deps: string[] = [];\n\n const decl_list = stmt.declarationList;\n const kind = (decl_list.flags & ts.NodeFlags.Let) !== 0 ? \"let\" : \"const\";\n let has_bare_yield = false;\n let uses_dispatcher_promise = false;\n\n for (const decl of decl_list.declarations) {\n if (!decl.initializer || !contains_top_level_yield_star(decl.initializer)) {\n if (contains_top_level_yield_star(decl.name)) {\n has_bare_yield = true;\n\n const binding_text = slice(content, decl.name).trim();\n const initializer_text = decl.initializer\n ? slice(content, decl.initializer).trim()\n : \"undefined\";\n const names = extract_binding_names(decl.name);\n const statement = `(${binding_text} = ${initializer_text});`;\n\n temps.push(...names.map((name) => make_unknown_temp(name, context)));\n statements.push(statement);\n deps.push(...collect_deps(statement, names));\n\n continue;\n }\n\n rewritten_decls.push(slice(content, decl).trim());\n continue;\n }\n\n const binding_text = slice(content, decl.name).trim();\n\n if (ts.isIdentifier(decl.name)) {\n const original_name = binding_text;\n\n if (is_yield_star_expression(decl.initializer)) {\n if (kind === \"const\") {\n const awaited = make_awaited_yield_initializer(\n decl.initializer,\n content,\n original_name,\n context,\n );\n\n type_helpers.push(awaited.declaration);\n rewritten_decls.push(`${original_name} = ${awaited.expression}`);\n uses_dispatcher_promise = true;\n continue;\n }\n\n const temp_name = context.next_temp_name(original_name);\n const yield_text = extract_yield_star_full_text(\n decl.initializer,\n content,\n );\n const type_helper = make_yield_type_helper(\n yield_text,\n original_name,\n context,\n );\n\n if (type_helper) {\n type_helpers.push(type_helper.declaration);\n temps.push({ name: temp_name, type: type_helper.type });\n } else {\n temps.push({ name: temp_name });\n }\n\n has_bare_yield = true;\n rewritten_decls.push(`${original_name} = $derived(${temp_name})`);\n\n statements.push(`${temp_name} = ${yield_text};`);\n deps.push(...collect_deps(yield_text));\n } else {\n const state_rune = get_state_rune_initializer(\n decl.initializer,\n content,\n );\n\n if (state_rune) {\n const direct_yield_text = extract_yield_star_full_text(\n decl.initializer,\n content,\n );\n const state_type = direct_yield_text === state_rune.value_text\n ? make_yield_type_helper(\n state_rune.value_text,\n original_name,\n context,\n )\n : undefined;\n\n if (state_type) {\n type_helpers.push(state_type.declaration);\n }\n\n has_bare_yield = true;\n rewritten_decls.push(\n `${original_name} = ${\n make_state_placeholder(\n state_rune.rune_name,\n state_type?.type,\n context,\n )\n }`,\n );\n statements.push(`${original_name} = ${state_rune.value_text};`);\n deps.push(...collect_deps(state_rune.value_text));\n continue;\n }\n\n const lowered = lower_expression_yields(\n decl.initializer,\n content,\n original_name,\n context,\n );\n\n temps.push(...lowered.temps);\n type_helpers.push(...(lowered.type_helpers ?? []));\n for (const block of lowered.effect_blocks) {\n statements.push(...block.statements);\n deps.push(...block.deps);\n }\n\n const rewritten_expr = rewrite_state_rune_as_derived(\n lowered.rewritten_expr,\n );\n const final_expr = should_wrap_complex_initializer_as_derived(\n decl.initializer,\n content,\n )\n ? `$derived(${rewritten_expr})`\n : rewritten_expr;\n\n if (final_expr !== rewritten_expr) {\n has_bare_yield = true;\n }\n\n rewritten_decls.push(`${original_name} = ${final_expr}`);\n }\n } else {\n has_bare_yield = true;\n\n const temp_name = context.next_temp_name(\"destructure\");\n const names = extract_binding_names(decl.name);\n const yield_text = extract_yield_star_full_text(\n decl.initializer,\n content,\n );\n const type_helper = make_yield_type_helper(\n yield_text,\n \"destructure\",\n context,\n );\n\n if (type_helper) {\n type_helpers.push(type_helper.declaration);\n temps.push({ name: temp_name, type: type_helper.type });\n } else {\n temps.push({ name: temp_name });\n }\n\n temps.push(...names.map((name) => make_unknown_temp(name, context)));\n\n statements.push(`${temp_name} = ${yield_text};`);\n statements.push(`(${binding_text} = ${temp_name});`);\n deps.push(...collect_deps(yield_text));\n }\n }\n\n const rewritten_text = rewritten_decls.length === 0\n ? \"\"\n : `${has_bare_yield ? \"let\" : kind} ${rewritten_decls.join(\", \")};`;\n\n return {\n temps,\n type_helpers,\n rewritten_text,\n effect_blocks: statements.length === 0\n ? []\n : [make_effect_block(statements, deps)],\n uses_dispatcher_promise,\n range: { start: stmt.getStart(), end: stmt.end },\n };\n}\n\nfunction lower_expression_statement(\n stmt: ts.ExpressionStatement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n const expr = stmt.expression;\n\n if (!contains_top_level_yield_star(expr)) {\n return {\n temps: [],\n rewritten_text: slice(content, stmt).trim(),\n effect_blocks: [],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n if (is_yield_star_expression(expr)) {\n const text = slice(content, expr).trim();\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [make_effect_block([text + \";\"], collect_deps(text))],\n range: { start: stmt.getFullStart(), end: stmt.end },\n };\n }\n\n if (ts.isBinaryExpression(expr) && is_assignment_operator(expr)) {\n const target = slice(content, expr.left).trim();\n const target_names = collect_assignment_target_names(expr.left);\n\n if (\n expr.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n is_yield_star_expression(expr.right)\n ) {\n const yield_text = extract_yield_star_full_text(expr.right, content);\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [`${target} = ${yield_text};`],\n collect_deps(yield_text, target_names),\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const lowered = lower_expression_yields(\n expr.right,\n content,\n make_temp_hint(target),\n context,\n );\n const temp_names = lowered.temps.map((temp) => temp.name);\n const statement = `${target} ${\n slice(content, expr.operatorToken).trim()\n } ${lowered.rewritten_expr};`;\n\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [\n ...lowered.effect_blocks.flatMap((block) => block.statements),\n statement,\n ],\n [\n ...lowered.effect_blocks.flatMap((block) => block.deps),\n ...collect_deps(lowered.rewritten_expr, [\n ...target_names,\n ...temp_names,\n ]),\n ],\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const lowered = lower_expression_yields(\n expr,\n content,\n \"call\",\n context,\n );\n\n if (is_top_level_rune_call(expr)) {\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: lowered.rewritten_expr + \";\",\n effect_blocks: lowered.effect_blocks,\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const temp_names = lowered.temps.map((temp) => temp.name);\n\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [\n ...lowered.effect_blocks.flatMap((block) => block.statements),\n lowered.rewritten_expr + \";\",\n ],\n [\n ...lowered.effect_blocks.flatMap((block) => block.deps),\n ...collect_deps(lowered.rewritten_expr, temp_names),\n ],\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n}\n\nfunction lower_expression_yields(\n expr: ts.Expression,\n content: string,\n hint: string,\n context: ScriptLoweringContext,\n): LoweredExpression {\n const replacements: Array<{\n start: number;\n end: number;\n text: string;\n }> = [];\n\n const temps: TempBinding[] = [];\n const type_helpers: string[] = [];\n const statements: string[] = [];\n const deps: string[] = [];\n\n collect_yield_star_nodes(expr, (node) => {\n const temp_name = context.next_temp_name(hint);\n const yield_text = slice_start(content, node).trim();\n const type_helper = make_yield_type_helper(yield_text, hint, context);\n\n if (type_helper) {\n type_helpers.push(type_helper.declaration);\n temps.push({ name: temp_name, type: type_helper.type });\n } else {\n temps.push({ name: temp_name });\n }\n\n statements.push(`${temp_name} = ${yield_text};`);\n deps.push(...collect_deps(yield_text));\n replacements.push({\n start: node.getStart(),\n end: node.end,\n text: temp_name,\n });\n });\n\n if (replacements.length === 0) {\n return {\n temps,\n type_helpers,\n rewritten_expr: slice(content, expr).trim(),\n effect_blocks: [],\n };\n }\n\n replacements.sort((a, b) => b.start - a.start);\n\n let text = slice(content, expr);\n\n const offset_in_expr = expr.getFullStart();\n\n for (const replacement of replacements) {\n text = text.slice(0, replacement.start - offset_in_expr) +\n replacement.text +\n text.slice(replacement.end - offset_in_expr);\n }\n\n return {\n temps,\n type_helpers,\n rewritten_expr: text.trim(),\n effect_blocks: [make_effect_block(statements, deps)],\n };\n}\n\nfunction make_awaited_yield_initializer(\n expr: ts.Expression,\n content: string,\n hint: string,\n context: ScriptLoweringContext,\n): { declaration: string; expression: string } {\n const yield_text = extract_yield_star_full_text(expr, content);\n const helper_name = context.next_helper_name(`effect_${hint}`);\n const helper_id = make_script_effect_id(expr, context);\n const deps = collect_deps(yield_text);\n const deps_text = `[${deps.join(\", \")}]`;\n\n return {\n declaration: `function* ${helper_name}() { return (${yield_text}); }`,\n expression: [\n `await ${context.dispatcher_name}().promise({`,\n `id: ${JSON.stringify(helper_id)}, `,\n `deps: ${deps_text}, `,\n `factory: () => ${helper_name}()`,\n `})`,\n ].join(\"\"),\n };\n}\n\nfunction make_yield_type_helper(\n yield_text: string,\n hint: string,\n context: ScriptLoweringContext,\n): { declaration: string; type: string } | undefined {\n if (!context.emit_types) {\n return undefined;\n }\n\n const helper_name = context.next_type_helper_name(hint);\n const effect_text = strip_yield_star(yield_text);\n\n return {\n declaration: `function ${helper_name}() { return (${effect_text}); }`,\n type:\n `${context.effect_name}.Success<ReturnType<typeof ${helper_name}>> | undefined`,\n };\n}\n\nfunction make_unknown_temp(\n name: string,\n context: ScriptLoweringContext,\n): TempBinding {\n return {\n name,\n type: context.emit_types ? \"unknown\" : undefined,\n };\n}\n\nfunction make_state_placeholder(\n rune_name: string,\n type: string | undefined,\n context: ScriptLoweringContext,\n): string {\n if (type) {\n return `${rune_name}<${type}>(undefined)`;\n }\n\n if (context.emit_types) {\n return `${rune_name}<unknown>(undefined)`;\n }\n\n return `${rune_name}(undefined)`;\n}\n\nfunction strip_yield_star(yield_text: string): string {\n return yield_text.replace(/^yield\\*\\s*/, \"\");\n}\n\nfunction make_script_effect_id(\n expr: ts.Expression,\n context: ScriptLoweringContext,\n): string {\n return `${context.filename}:${expr.getStart()}:${expr.end}`;\n}\n\nfunction rewrite_state_rune_as_derived(expression: string): string {\n const state_call = expression.match(/^\\$state(?:\\.raw)?\\(([\\s\\S]*)\\)$/);\n\n if (!state_call) {\n return expression;\n }\n\n return `$derived(${state_call[1]})`;\n}\n\nfunction should_wrap_complex_initializer_as_derived(\n expr: ts.Expression,\n content: string,\n): boolean {\n const text = slice(content, expr).trim();\n\n return !/^\\$derived(?:\\.by)?\\(/.test(text) &&\n !/^\\$inspect(?:\\.trace)?\\(/.test(text);\n}\n\nfunction is_assignment_operator(expr: ts.BinaryExpression): boolean {\n return expr.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n expr.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n}\n\nfunction is_top_level_rune_call(expr: ts.Expression): boolean {\n if (!ts.isCallExpression(expr)) {\n return false;\n }\n\n const callee = expr.expression;\n\n if (ts.isIdentifier(callee)) {\n return callee.text.startsWith(\"$\");\n }\n\n return ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text.startsWith(\"$\");\n}\n\nfunction make_temp_hint(target: string): string {\n const match = target.match(/[A-Za-z_$][\\w$]*$/);\n\n return match?.[0] ?? \"assignment\";\n}\n\nfunction extract_yield_star_full_text(\n expr: ts.Expression,\n content: string,\n): string {\n let found: string | undefined;\n\n find_yield_star_node(expr, (node) => {\n found = slice_start(content, node).trim();\n });\n\n return found ?? \"undefined\";\n}\n\nfunction make_effect_block(\n statements: string[],\n deps: string[],\n): EffectBlock {\n return {\n statements,\n deps: [...new Set(deps)],\n };\n}\n\nfunction collect_deps(\n expr_text: string,\n excluded_names: readonly string[] = [],\n): string[] {\n const excluded = new Set(excluded_names);\n\n return collect_free_identifiers(expr_text).filter(\n (identifier) =>\n !identifier.startsWith(\"__SER___\") && !excluded.has(identifier),\n );\n}\n\nfunction collect_assignment_target_names(node: ts.Node): string[] {\n if (ts.isIdentifier(node)) {\n return [node.text];\n }\n\n if (ts.isParenthesizedExpression(node)) {\n return collect_assignment_target_names(node.expression);\n }\n\n if (\n ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)\n ) {\n return collect_assignment_target_names(node.expression);\n }\n\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties.flatMap((property) => {\n if (ts.isShorthandPropertyAssignment(property)) {\n return [property.name.text];\n }\n\n if (ts.isPropertyAssignment(property)) {\n return collect_assignment_target_names(property.initializer);\n }\n\n if (ts.isSpreadAssignment(property)) {\n return collect_assignment_target_names(property.expression);\n }\n\n return [];\n });\n }\n\n if (ts.isArrayLiteralExpression(node)) {\n return node.elements.flatMap((element) =>\n ts.isSpreadElement(element)\n ? collect_assignment_target_names(element.expression)\n : collect_assignment_target_names(element)\n );\n }\n\n return [];\n}\n","import { contains_top_level_yield_star } from \"$/detect.ts\";\nimport {\n collect_top_level_binding_names,\n has_local_import_binding,\n make_imports,\n} from \"./imports.ts\";\nimport { create_source_map, slice } from \"./source.ts\";\nimport { AwaitInEffectWorkError, PreprocessError } from \"$/error.ts\";\nimport { make_runtime_block_with_bindings } from \"./runtime-block.ts\";\nimport { contains_top_level_await } from \"./ast.ts\";\nimport { lower_statement } from \"./lower.ts\";\nimport { validate_rune_yield_usage } from \"./runes.ts\";\nimport type {\n BlockRef,\n EffectBlock,\n RuntimeImportBindings,\n ScriptLoweringContext,\n ScriptTransformResult,\n} from \"./types.ts\";\n\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\nexport type { BlockRef, ScriptTransformResult } from \"./types.ts\";\n\ninterface ScriptTransformOptions {\n emit_types?: boolean;\n}\n\n/**\n * Transforms a `<script effect>` body by extracting top-level `yield*`\n * expressions into `$state` temp bindings and wrapping the lowered\n * assignments in a dependency-tracked `$effect` block.\n *\n * @example\n * ```ts\n * const result = transform_script_effect(\n * `let user = $state(yield* getUser(id));`,\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param content - The raw `<script effect>` body content.\n * @param filename - The source filename, used in error messages.\n * @param options - Optional transform settings for generated script code.\n * @returns The transformed code and any block references.\n */\nexport function transform_script_effect(\n content: string,\n filename: string,\n options: ScriptTransformOptions = {},\n): ScriptTransformResult {\n let temp_counter = 0;\n\n const source_file = ts.createSourceFile(\n filename,\n content,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n const magic = new MagicString(content);\n const effect_blocks: EffectBlock[] = [];\n const block_refs: BlockRef[] = [];\n const top_level_binding_names = collect_top_level_binding_names(source_file);\n const top_level_binding_names_set = new Set(top_level_binding_names);\n const name_allocator = make_name_allocator(top_level_binding_names);\n const emit_types = options.emit_types ?? true;\n\n let has_effect = false;\n let uses_dispatcher_promise = false;\n let uses_effect_types = false;\n\n /** Phase 1: detect imports already provided by the user. */\n const has_effect_import = has_local_import_binding(\n source_file,\n \"effect\",\n \"Effect\",\n );\n\n const has_dispatcher_import = has_local_import_binding(\n source_file,\n \"svelte-effect-runtime/internal/generators\",\n \"get_dispatcher\",\n );\n\n const has_untrack_import = has_local_import_binding(\n source_file,\n \"svelte\",\n \"untrack\",\n );\n\n const reserve_runtime_import = (name: string) =>\n top_level_binding_names_set.has(name)\n ? name_allocator.reserve(make_generated_name(name, \"\"))\n : name_allocator.reserve(name);\n\n const runtime_bindings: RuntimeImportBindings = {\n cancel: name_allocator.reserve(\"__SER___cancel\"),\n dispatcher: has_dispatcher_import\n ? \"get_dispatcher\"\n : reserve_runtime_import(\"get_dispatcher\"),\n dispatcher_value: name_allocator.reserve(\"__SER___dispatcher\"),\n effect: has_effect_import ? \"Effect\" : reserve_runtime_import(\"Effect\"),\n program: name_allocator.reserve(\"__SER___program\"),\n untrack: has_untrack_import ? \"untrack\" : reserve_runtime_import(\"untrack\"),\n };\n\n const context: ScriptLoweringContext = {\n filename,\n dispatcher_name: runtime_bindings.dispatcher,\n effect_name: runtime_bindings.effect,\n emit_types,\n next_helper_name(hint?: string) {\n return name_allocator.reserve(make_generated_name(hint ?? \"helper\", \"\"));\n },\n next_temp_name(hint?: string) {\n const suffix = temp_counter === 0 ? \"\" : `_${temp_counter}`;\n const name = make_generated_name(hint ?? String(temp_counter), suffix);\n\n temp_counter += 1;\n\n return name_allocator.reserve(name);\n },\n next_type_helper_name(hint?: string) {\n return name_allocator.reserve(\n make_generated_name(`type_${hint ?? \"effect\"}`, \"\"),\n );\n },\n };\n\n /** Phase 2: lower every top-level statement that contains `yield*`. */\n for (const stmt of source_file.statements) {\n validate_rune_yield_usage(stmt, content, filename);\n validate_script_yield_boundaries(stmt, content, filename);\n\n const has_top_level_yield_star = contains_top_level_yield_star(stmt);\n\n if (!has_top_level_yield_star) {\n continue;\n }\n\n if (contains_top_level_await(stmt)) {\n const text = slice(content, stmt);\n throw new AwaitInEffectWorkError(filename, text);\n }\n\n has_effect = true;\n const lowered = lower_statement(stmt, content, context);\n\n magic.overwrite(\n lowered.range.start,\n lowered.range.end,\n lowered.rewritten_text,\n );\n\n if (lowered.temps.length > 0 || lowered.type_helpers?.length) {\n const temp_declarations = lowered.temps.map((temp) =>\n temp.type\n ? `let ${temp.name} = $state<${temp.type}>(undefined);`\n : `let ${temp.name} = $state(undefined);`\n );\n\n const prefix = [\n ...(lowered.type_helpers ?? []),\n ...temp_declarations,\n ].join(\"\\n\");\n\n magic.appendLeft(lowered.range.start, prefix + \"\\n\");\n }\n\n effect_blocks.push(...lowered.effect_blocks);\n uses_dispatcher_promise ||= lowered.uses_dispatcher_promise ?? false;\n uses_effect_types ||= lowered.temps.some((temp) =>\n temp.type?.includes(`${runtime_bindings.effect}.Success`) ?? false\n );\n }\n\n if (!has_effect) {\n block_refs.push({ id: filename, kind: \"script\" });\n\n return { code: content, blocks: block_refs };\n }\n\n /** Phase 3: inject runtime imports after the last user import. */\n const imports = make_imports(\n has_effect_import,\n has_dispatcher_import,\n has_untrack_import,\n runtime_bindings,\n {\n needs_dispatcher: effect_blocks.length > 0 || uses_dispatcher_promise,\n needs_effect: effect_blocks.length > 0 || uses_effect_types,\n needs_untrack: effect_blocks.length > 0,\n },\n );\n\n const last_import = [...source_file.statements]\n .reverse()\n .find(ts.isImportDeclaration);\n\n if (imports) {\n if (last_import) {\n magic.appendRight(last_import.end, \"\\n\" + imports);\n } else {\n magic.prepend(imports + \"\\n\");\n }\n }\n\n /** Phase 4: append the runtime program and lifecycle wiring. */\n if (effect_blocks.length > 0) {\n const runtime_block = make_runtime_block_with_bindings(\n effect_blocks,\n runtime_bindings,\n );\n\n magic.append(\"\\n\" + runtime_block);\n }\n\n block_refs.push({ id: filename, kind: \"script\" });\n\n return {\n code: magic.toString(),\n blocks: block_refs,\n map: create_source_map(magic, filename),\n };\n}\n\nfunction validate_script_yield_boundaries(\n stmt: ts.Statement,\n content: string,\n filename: string,\n): void {\n const bad_member = find_class_member_with_yield_star(stmt);\n\n if (!bad_member) {\n return;\n }\n\n throw new PreprocessError(\n [\n `[ASYNC_EFFECT_IN_CLASS_MEMBER]: ${filename}: yield* cannot be used inside class members.`,\n `Class fields and methods are not component top-level reactive work. Move the Effect work into a script effect statement before assigning it to the class instance.`,\n \"\",\n \"Problematic member:\",\n slice(content, bad_member),\n ].join(\"\\n\"),\n filename,\n );\n}\n\nfunction find_class_member_with_yield_star(\n stmt: ts.Statement,\n): ts.Node | undefined {\n let found: ts.Node | undefined;\n\n function visit(node: ts.Node): void {\n if (found) {\n return;\n }\n\n if (\n ts.isPropertyDeclaration(node) &&\n node.initializer &&\n contains_top_level_yield_star(node.initializer)\n ) {\n found = node;\n return;\n }\n\n node.forEachChild(visit);\n }\n\n visit(stmt);\n\n return found;\n}\n\nfunction make_name_allocator(initial_names: readonly string[]): {\n reserve(name: string): string;\n} {\n const used_names = new Set(initial_names);\n\n return {\n reserve(name: string): string {\n let candidate = name;\n let suffix = 1;\n\n while (used_names.has(candidate)) {\n candidate = `${name}_${suffix}`;\n suffix += 1;\n }\n\n used_names.add(candidate);\n\n return candidate;\n },\n };\n}\n\nfunction make_generated_name(hint: string, suffix: string): string {\n const normalized_hint = hint.replace(/[^A-Za-z0-9_$]/g, \"_\");\n const safe_hint = /^[A-Za-z_$]/.test(normalized_hint)\n ? normalized_hint\n : `temp_${normalized_hint}`;\n\n return `__SER___${safe_hint}${suffix}`;\n}\n","import { transform_markup_effect } from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/script-transform/index.ts\";\n\n/**\n * Result returned by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\"<p>{yield* load()}</p>\", \"App.svelte\");\n * result.code;\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformResult {\n /** Transformed Svelte source. */\n code: string;\n}\n\n/**\n * Lowers SER syntax in a complete Svelte component without using Svelte's\n * adapter API.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\n * \"<script effect>const value = yield* load()</script>\",\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.5.0\n * @param content - Full Svelte component source to lower before Svelte parses\n * it.\n * @param filename - Component filename used in generated cache identifiers and\n * diagnostics.\n * @returns The transformed component source.\n */\nexport function transform_svelte_effect(\n content: string,\n filename = \"unknown.svelte\",\n): SvelteTransformResult {\n const script = find_script(content);\n\n let combined = content;\n\n if (script?.has_effect) {\n const result = transform_script_effect(script.text, filename, {\n emit_types: script.is_typescript,\n });\n\n combined = content.slice(0, script.effect_attr_start) +\n content.slice(script.effect_attr_end, script.open_end) +\n result.code +\n content.slice(script.close_start);\n }\n\n const result = transform_markup_effect(combined, filename);\n\n return { code: result.code };\n}\n\nfunction find_script(content: string):\n | {\n text: string;\n open_end: number;\n close_start: number;\n has_effect: boolean;\n effect_attr_start: number;\n effect_attr_end: number;\n is_typescript: boolean;\n }\n | undefined {\n const pattern = /<script\\b([^>]*)>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n for (const match of content.matchAll(pattern)) {\n if (match.index === undefined || /\\bmodule\\b/.test(match[1] ?? \"\")) {\n continue;\n }\n\n const attrs = match[1] ?? \"\";\n const effect_match = /\\s+effect(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+))?/\n .exec(attrs);\n const open_end = match.index + match[0].indexOf(\">\") + 1;\n const attr_start = effect_match?.index ?? attrs.length;\n const attr_end = attr_start + (effect_match?.[0].length ?? 0);\n\n return {\n text: match[2],\n open_end,\n close_start: match.index + match[0].lastIndexOf(\"<\"),\n has_effect: effect_match !== null,\n effect_attr_start: match.index + \"<script\".length + attr_start,\n effect_attr_end: match.index + \"<script\".length + attr_end,\n is_typescript: has_typescript_lang(attrs),\n };\n }\n\n return undefined;\n}\n\nfunction has_typescript_lang(attrs: string): boolean {\n const lang_match = /\\blang\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))/i.exec(\n attrs,\n );\n const lang = (lang_match?.[1] ?? lang_match?.[2] ?? lang_match?.[3] ?? \"\")\n .toLowerCase();\n\n return lang === \"ts\" || lang === \"typescript\";\n}\n\nexport {\n type MarkupTransformResult,\n transform_markup_effect,\n} from \"$/markup/transform.ts\";\n\nexport {\n type BlockRef,\n type ScriptTransformResult,\n transform_script_effect,\n} from \"$/script-transform/index.ts\";\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,kBACd,OACA,UACyB;CAOzB,OANY,MAAM,YAAY;EAC5B,OAAO;EACP,gBAAgB;EAChB,QAAQ;CACV,CAES;AACX;;;;;;;;;AAUA,SAAgB,MAAM,SAAiB,MAAuB;CAC5D,OAAO,QAAQ,MAAM,KAAK,aAAa,GAAG,KAAK,GAAG;AACpD;;;;;;;;;AAUA,SAAgB,YAAY,SAAiB,MAAuB;CAClE,OAAO,QAAQ,MAAM,KAAK,SAAS,GAAG,KAAK,GAAG;AAChD;;;;;;;;;;;;ACfA,SAAgB,iCACd,QACA,UACQ;CACR,MAAM,eAAe,oBAAoB,MAAM;CAC/C,MAAM,YAAY,aAAa,KAAK,KAAK,QAAQ,KAAK,IAAI,EAAE;CAE5D,MAAM,OAAO,aAAa,WACvB,KAAK,cAAc,OAAO,WAAW,EACrC,KAAK,IAAI;CAEZ,OAAO;EACL;EACA;EACA,GAAG;EACH,WAAW,SAAS,iBAAiB,KAAK,SAAS,WAAW;EAC9D,WAAW,SAAS,QAAQ,KAAK,SAAS,OAAO;EACjD;EACA;EACA,WAAW,SAAS,OAAO,KAAK,SAAS,QAAQ,SAAS,SAAS,iBAAiB,QAAQ,SAAS,QAAQ;EAC7G,8BAA8B,SAAS,OAAO;EAC9C,YAAY,SAAS,OAAO;EAC5B;EACA;CACF,EAAE,KAAK,IAAI;AACb;AAEA,SAAS,oBAAoB,QAAoC;CAC/D,MAAM,aAAa,OAAO,SAAS,UAAU,MAAM,UAAU;CAC7D,MA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W;CACpC;CAIA,OAAO,EAAE,MAFM,wBAAwB,UAAU,QAE7B,EAAE,KAAK;AAC7B;AAEA,SAAS,YAAY,SAUP;CAGZ,KAAK,MAAM,SAAS,QAAQ,SAAS,4CAAO,GAAG;EAC7C,IAAI,MAAM,UAAU,KAAA,KAAa,aAAa,KAAK,MAAM,MAAM,EAAE,GAC/D;EAGF,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,eAAe,mDAClB,KAAK,KAAK;EACb,MAAM,WAAW,MAAM,QAAQ,MAAM,GAAG,QAAQ,GAAG,IAAI;EACvD,MAAM,aAAa,cAAc,SAAS,MAAM;EAChD,MAAM,WAAW,cAAc,eAAe,GAAG,UAAU;EAE3D,OAAO;GACL,MAAM,MAAM;GACZ;GACA,aAAa,MAAM,QAAQ,MAAM,GAAG,YAAY,GAAG;GACnD,YAAY,iBAAiB;GAC7B,mBAAmB,MAAM,QAAQ,IAAmB;GACpD,iBAAiB,MAAM,QAAQ,IAAmB;GAClD,eAAe,oBAAoB,KAAK;EAC1C;CACF;AAGF;AAEA,SAAS,oBAAoB,OAAwB;CACnD,MAAM,aAAa,kDAAkD,KACnE,KACF;CACA,MAAM,QAAQ,aAAa,MAAM,aAAa,MAAM,aAAa,MAAM,IACpE,YAAY;CAEf,OAAO,SAAS,QAAQ,SAAS;AACnC"}
|
|
@@ -6,7 +6,7 @@ interface RuntimeImportOptions {
|
|
|
6
6
|
needs_untrack?: boolean;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Builds the import statements injected by the script
|
|
9
|
+
* Builds the import statements injected by the script transform.
|
|
10
10
|
*
|
|
11
11
|
* @since 2.0.0
|
|
12
12
|
* @param has_effect_import - Whether the user already imports `Effect`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Block reference emitted by the
|
|
2
|
+
* Block reference emitted by the script transform to track what blocks were
|
|
3
3
|
* generated in a given file.
|
|
4
4
|
*
|
|
5
5
|
* @since 2.0.0
|
|
@@ -11,7 +11,7 @@ export interface BlockRef {
|
|
|
11
11
|
kind: "value" | "promise" | "run" | "script";
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Result of the script
|
|
14
|
+
* Result of the script transform pass.
|
|
15
15
|
*
|
|
16
16
|
* @since 2.0.0
|
|
17
17
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RemoteFormInput } from "@sveltejs/kit";
|
|
2
2
|
import { type Schema } from "effect";
|
|
3
|
-
import type { EffectLike, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, PrerenderOptions, QueryFactory, RemoteFormHandler, RemoteHandler, SchemaEncodedInput, SchemaInput } from "./types.js";
|
|
3
|
+
import type { EffectLike, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, PrerenderOptions, QueryFactory, RemoteFormHandler, RemoteHandler, SchemaEncodedInput, SchemaInput, StandardSchema, StandardSchemaInput, StandardSchemaOutput } from "./types.js";
|
|
4
4
|
type FormSchemaEncodedInput<S> = S extends Schema.Top ? FormRemoteInput<S["Encoded"]> : never;
|
|
5
5
|
type FormRemoteInput<Input> = NormalizeFormEncoded<Input> extends RemoteFormInput ? NormalizeFormEncoded<Input> : never;
|
|
6
|
+
type FormStandardSchemaInput<S> = StandardSchemaInput<S> extends RemoteFormInput ? StandardSchemaInput<S> : RemoteFormInput;
|
|
6
7
|
type FormScalar = string | number | boolean | File;
|
|
7
8
|
type NormalizeFormEncoded<Value> = Value extends FormScalar ? Value : Value extends ReadonlyArray<infer Item> ? Array<NormalizeFormEncoded<Item>> : Value extends object ? NormalizeFormObject<Value> : Value;
|
|
8
9
|
type NormalizeFormObject<Value> = {
|
|
@@ -39,6 +40,7 @@ export declare const Query: QueryFactory;
|
|
|
39
40
|
export declare function Command<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>): EffectRemoteCommand<void, A, E>;
|
|
40
41
|
export declare function Command<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>): EffectRemoteCommand<Input, A, E>;
|
|
41
42
|
export declare function Command<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>): EffectRemoteCommand<SchemaEncodedInput<S>, A, E>;
|
|
43
|
+
export declare function Command<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteCommand<StandardSchemaInput<S>, A, E>;
|
|
42
44
|
/**
|
|
43
45
|
* Factory for a remote form handler.
|
|
44
46
|
*
|
|
@@ -63,6 +65,7 @@ export declare function Command<S extends Schema.Schema<unknown>, A, E = never,
|
|
|
63
65
|
export declare function Form<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteFormHandler<void, A, E, R>): EffectRemoteForm<void, A, E>;
|
|
64
66
|
export declare function Form<Input extends RemoteFormInput, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteFormHandler<Input, A, E, R>): EffectRemoteForm<Input, A, E>;
|
|
65
67
|
export declare function Form<S extends Schema.Top, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<SchemaInput<S>, A, E, R>): EffectRemoteForm<FormSchemaEncodedInput<S>, A, E>;
|
|
68
|
+
export declare function Form<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteForm<FormStandardSchemaInput<S>, A, E>;
|
|
66
69
|
/**
|
|
67
70
|
* Factory for a prerenderable remote function.
|
|
68
71
|
*
|
|
@@ -75,4 +78,5 @@ export declare function Form<S extends Schema.Top, A, E = never, R = never>(vali
|
|
|
75
78
|
export declare function Prerender<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<void, A, E>;
|
|
76
79
|
export declare function Prerender<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<Input, A, E>;
|
|
77
80
|
export declare function Prerender<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<SchemaEncodedInput<S>, A, E>;
|
|
81
|
+
export declare function Prerender<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<StandardSchemaInput<S>, A, E>;
|
|
78
82
|
export {};
|
package/.dist/server/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Command, Form, Prerender, Query } from "./factories.js";
|
|
|
2
2
|
export { Error, Redirect } from "./control-flow.js";
|
|
3
3
|
export { get_server_runtime_or_throw, RequestEvent, ServerRuntime, } from "./runtime.js";
|
|
4
4
|
export type { ErrorEffectFactory, ErrorStatus, ErrorStatusName, RedirectEffectFactory, RedirectStatus, RedirectStatusName, } from "./control-flow.js";
|
|
5
|
-
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, } from "./types.js";
|
|
5
|
+
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, StandardSchemaInput, StandardSchemaOutput, } from "./types.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RequestEvent as SvelteKitRequestEvent } from "@sveltejs/kit";
|
|
2
2
|
import { Context, Layer, ManagedRuntime } from "effect";
|
|
3
|
+
import { Dispatcher as InternalDispatcher } from "../dispatcher.js";
|
|
3
4
|
/**
|
|
4
5
|
* Subset of SvelteKit's `RequestEvent` that remote handlers typically access.
|
|
5
6
|
*
|
|
@@ -50,3 +51,16 @@ export declare class ServerRuntime {
|
|
|
50
51
|
* @returns The current ManagedRuntime instance.
|
|
51
52
|
*/
|
|
52
53
|
export declare function get_server_runtime_or_throw(): ManagedRuntime.ManagedRuntime<unknown, never>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns a dispatcher backed by the active server runtime.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const dispatcher = get_server_dispatcher();
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @since 3.0.1
|
|
63
|
+
* @returns The cached server dispatcher, creating one from the current server
|
|
64
|
+
* runtime when needed.
|
|
65
|
+
*/
|
|
66
|
+
export declare function get_server_dispatcher(): InternalDispatcher;
|
package/.dist/server/types.d.ts
CHANGED
|
@@ -43,9 +43,17 @@ export type RemoteFormHandler<Input = unknown, A = unknown, E = unknown, R = unk
|
|
|
43
43
|
*
|
|
44
44
|
* @since 2.0.0
|
|
45
45
|
*/
|
|
46
|
-
export type FormInvalid<Input = unknown> = FormInvalidChildren<Input> & {
|
|
46
|
+
export type FormInvalid<Input = unknown> = FormInvalidFunctionChildren & FormInvalidChildren<Input> & {
|
|
47
47
|
(message: string): Effect.Effect<never, ReturnType<typeof create_form_error>>;
|
|
48
48
|
};
|
|
49
|
+
type FormInvalidFunctionChildren = {
|
|
50
|
+
readonly apply: FormInvalid;
|
|
51
|
+
readonly bind: FormInvalid;
|
|
52
|
+
readonly call: FormInvalid;
|
|
53
|
+
readonly length: FormInvalid;
|
|
54
|
+
readonly name: FormInvalid;
|
|
55
|
+
readonly toString: FormInvalid;
|
|
56
|
+
};
|
|
49
57
|
type FormInvalidChildren<Input> = IsUnknown<Input> extends true ? {
|
|
50
58
|
readonly [key: string]: FormInvalid;
|
|
51
59
|
} : NonNullable<Input> extends readonly (infer Item)[] ? {
|
|
@@ -70,6 +78,10 @@ export type PrerenderOptions = {
|
|
|
70
78
|
*/
|
|
71
79
|
export type StandardSchema = {
|
|
72
80
|
readonly "~standard": {
|
|
81
|
+
readonly types?: {
|
|
82
|
+
readonly input: unknown;
|
|
83
|
+
readonly output: unknown;
|
|
84
|
+
};
|
|
73
85
|
readonly validate: (input: unknown) => unknown;
|
|
74
86
|
};
|
|
75
87
|
};
|
|
@@ -85,6 +97,30 @@ export type SchemaInput<S> = S extends Schema.Top ? Schema.Schema.Type<S> : unkn
|
|
|
85
97
|
* @since 2.4.2
|
|
86
98
|
*/
|
|
87
99
|
export type SchemaEncodedInput<S> = S extends Schema.Top ? S["Encoded"] : unknown;
|
|
100
|
+
/**
|
|
101
|
+
* Extracts the encoded input type from a Standard Schema.
|
|
102
|
+
*
|
|
103
|
+
* @since 3.0.0
|
|
104
|
+
*/
|
|
105
|
+
export type StandardSchemaInput<S> = S extends {
|
|
106
|
+
readonly "~standard": {
|
|
107
|
+
readonly types: {
|
|
108
|
+
readonly input: infer Input;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
} ? Input : unknown;
|
|
112
|
+
/**
|
|
113
|
+
* Extracts the decoded handler input type from a Standard Schema.
|
|
114
|
+
*
|
|
115
|
+
* @since 3.0.0
|
|
116
|
+
*/
|
|
117
|
+
export type StandardSchemaOutput<S> = S extends {
|
|
118
|
+
readonly "~standard": {
|
|
119
|
+
readonly types: {
|
|
120
|
+
readonly output: infer Output;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
} ? Output : StandardSchemaInput<S>;
|
|
88
124
|
/**
|
|
89
125
|
* Root and server export shape for building the server-side runtime.
|
|
90
126
|
*
|
|
@@ -102,6 +138,7 @@ export interface QueryFactory {
|
|
|
102
138
|
<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>): EffectRemoteQueryFunction<void, A, E>;
|
|
103
139
|
<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>): EffectRemoteQueryFunction<Input, A, E>;
|
|
104
140
|
<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>): EffectRemoteQueryFunction<SchemaEncodedInput<S>, A, E>;
|
|
141
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteQueryFunction<StandardSchemaInput<S>, A, E>;
|
|
105
142
|
readonly batch: QueryBatchFactory;
|
|
106
143
|
readonly live: QueryLiveFactory;
|
|
107
144
|
}
|
|
@@ -113,6 +150,7 @@ export interface QueryFactory {
|
|
|
113
150
|
export interface QueryBatchFactory {
|
|
114
151
|
<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: EffectRemoteBatchHandler<Input, A, E, R>): EffectRemoteQueryFunction<Input, A, E>;
|
|
115
152
|
<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: EffectRemoteBatchHandler<SchemaInput<S>, A, E, R>): EffectRemoteQueryFunction<SchemaEncodedInput<S>, A, E>;
|
|
153
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: EffectRemoteBatchHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteQueryFunction<StandardSchemaInput<S>, A, E>;
|
|
116
154
|
}
|
|
117
155
|
/**
|
|
118
156
|
* Root and server export shape for live query helpers.
|
|
@@ -123,6 +161,7 @@ export interface QueryLiveFactory {
|
|
|
123
161
|
<A, E = never, R = never>(validate_or_handler: RemoteLiveHandler<void, A, E, R>): EffectRemoteLiveQueryFunction<void, A, E>;
|
|
124
162
|
<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteLiveHandler<Input, A, E, R>): EffectRemoteLiveQueryFunction<Input, A, E>;
|
|
125
163
|
<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteLiveHandler<SchemaInput<S>, A, E, R>): EffectRemoteLiveQueryFunction<SchemaEncodedInput<S>, A, E>;
|
|
164
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteLiveHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteLiveQueryFunction<StandardSchemaInput<S>, A, E>;
|
|
126
165
|
}
|
|
127
166
|
/**
|
|
128
167
|
* Root and server export shape for command helpers.
|
|
@@ -133,6 +172,7 @@ export interface CommandFactory {
|
|
|
133
172
|
<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>): EffectRemoteCommand<void, A, E>;
|
|
134
173
|
<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>): EffectRemoteCommand<Input, A, E>;
|
|
135
174
|
<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>): EffectRemoteCommand<SchemaEncodedInput<S>, A, E>;
|
|
175
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteCommand<StandardSchemaInput<S>, A, E>;
|
|
136
176
|
}
|
|
137
177
|
/**
|
|
138
178
|
* Root and server export shape for form helpers.
|
|
@@ -143,6 +183,7 @@ export interface FormFactory {
|
|
|
143
183
|
<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteFormHandler<void, A, E, R>): EffectRemoteForm<void, A, E>;
|
|
144
184
|
<Input extends RemoteFormInput, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteFormHandler<Input, A, E, R>): EffectRemoteForm<Input, A, E>;
|
|
145
185
|
<S extends Schema.Top, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<SchemaInput<S>, A, E, R>): EffectRemoteForm<FormSchemaEncodedInput<S>, A, E>;
|
|
186
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteForm<FormStandardSchemaInput<S>, A, E>;
|
|
146
187
|
}
|
|
147
188
|
/**
|
|
148
189
|
* Root and server export shape for prerender helpers.
|
|
@@ -153,6 +194,7 @@ export interface PrerenderFactory {
|
|
|
153
194
|
<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<void, A, E>;
|
|
154
195
|
<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<Input, A, E>;
|
|
155
196
|
<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<SchemaEncodedInput<S>, A, E>;
|
|
197
|
+
<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<StandardSchemaInput<S>, A, E>;
|
|
156
198
|
}
|
|
157
199
|
/**
|
|
158
200
|
* Source values accepted by live query helpers.
|
|
@@ -300,6 +342,7 @@ export type EffectRemoteCommand<Input, A, E = never> = EffectRemoteFunction<Inpu
|
|
|
300
342
|
export type EffectRemoteForm<Input extends RemoteFormInput | void, A, E = never> = ClientEffectRemoteForm<Input, A, E>;
|
|
301
343
|
type FormSchemaEncodedInput<S> = S extends Schema.Top ? FormRemoteInput<S["Encoded"]> : never;
|
|
302
344
|
type FormRemoteInput<Input> = NormalizeFormEncoded<Input> extends RemoteFormInput ? NormalizeFormEncoded<Input> : never;
|
|
345
|
+
type FormStandardSchemaInput<S> = StandardSchemaInput<S> extends RemoteFormInput ? StandardSchemaInput<S> : RemoteFormInput;
|
|
303
346
|
type FormScalar = string | number | boolean | File;
|
|
304
347
|
type NormalizeFormEncoded<Value> = Value extends FormScalar ? Value : Value extends ReadonlyArray<infer Item> ? Array<NormalizeFormEncoded<Item>> : Value extends object ? NormalizeFormObject<Value> : Value;
|
|
305
348
|
type NormalizeFormObject<Value> = {
|
package/.dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Command, Error, Form, get_server_runtime_or_throw, Prerender, Query, Redirect, RequestEvent, ServerRuntime, } from "./server/index.js";
|
|
2
|
-
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, ErrorEffectFactory, ErrorStatus, ErrorStatusName, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RedirectEffectFactory, RedirectStatus, RedirectStatusName, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, } from "./server/index.js";
|
|
2
|
+
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, ErrorEffectFactory, ErrorStatus, ErrorStatusName, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RedirectEffectFactory, RedirectStatus, RedirectStatusName, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, StandardSchemaInput, StandardSchemaOutput, } from "./server/index.js";
|