@thomasfosterau/effect-sveltekit 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +178 -83
- package/dist/Hooks.d.ts +3 -3
- package/dist/Hooks.js +1 -1
- package/dist/Hooks.js.map +1 -1
- package/dist/Navigation.d.ts +70 -17
- package/dist/Navigation.js +93 -19
- package/dist/Navigation.js.map +1 -1
- package/dist/Remote.d.ts +54 -35
- package/dist/Remote.js +22 -11
- package/dist/Remote.js.map +1 -1
- package/dist/State.d.ts +79 -6
- package/dist/State.js +117 -27
- package/dist/State.js.map +1 -1
- package/dist/adapter/assets.d.ts +24 -7
- package/dist/adapter/assets.js +58 -37
- package/dist/adapter/assets.js.map +1 -1
- package/dist/adapter/handler.d.ts +27 -12
- package/dist/adapter/handler.js +53 -26
- package/dist/adapter/handler.js.map +1 -1
- package/dist/adapter/index.d.ts +3 -3
- package/dist/adapter/index.js +1 -1
- package/dist/adapter/index.js.map +1 -1
- package/dist/adapter/serve.d.ts +6 -5
- package/dist/adapter/serve.js +3 -1
- package/dist/adapter/serve.js.map +1 -1
- package/dist/api-client.d.ts +3 -4
- package/dist/api-client.js +2 -1
- package/dist/api-client.js.map +1 -1
- package/dist/app-runtime.d.ts +12 -9
- package/dist/app-runtime.js +23 -14
- package/dist/app-runtime.js.map +1 -1
- package/dist/client/Hooks.d.ts +4 -4
- package/dist/client/Hooks.js +2 -1
- package/dist/client/Hooks.js.map +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/config.d.ts +7 -5
- package/dist/config.js +5 -34
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +14 -16
- package/dist/errors.js +20 -12
- package/dist/errors.js.map +1 -1
- package/dist/forms.d.ts +70 -8
- package/dist/forms.js +69 -5
- package/dist/forms.js.map +1 -1
- package/dist/internal/app-state.d.ts +42 -5
- package/dist/internal/app-state.js +64 -15
- package/dist/internal/app-state.js.map +1 -1
- package/dist/internal/auto.d.ts +23 -14
- package/dist/internal/auto.js +50 -40
- package/dist/internal/auto.js.map +1 -1
- package/dist/internal/enhance.d.ts +114 -14
- package/dist/internal/enhance.js +33 -7
- package/dist/internal/enhance.js.map +1 -1
- package/dist/internal/error.d.ts +13 -0
- package/dist/internal/error.js +4 -3
- package/dist/internal/error.js.map +1 -1
- package/dist/internal/navigation-events.js +3 -1
- package/dist/internal/navigation-events.js.map +1 -1
- package/dist/internal/remote-run.d.ts +6 -6
- package/dist/internal/remote-run.js +13 -16
- package/dist/internal/remote-run.js.map +1 -1
- package/dist/internal/remote-validators.js +4 -3
- package/dist/internal/remote-validators.js.map +1 -1
- package/dist/internal/route-params.d.ts +1 -2
- package/dist/internal/sse.js +2 -1
- package/dist/internal/sse.js.map +1 -1
- package/dist/internal/watch.svelte.js +33 -0
- package/dist/internal/watch.svelte.js.map +1 -0
- package/dist/kit.d.ts +12 -11
- package/dist/kit.js +6 -2
- package/dist/kit.js.map +1 -1
- package/dist/realtime.d.ts +49 -30
- package/dist/realtime.js +90 -46
- package/dist/realtime.js.map +1 -1
- package/dist/remote-functions.d.ts +34 -18
- package/dist/remote-functions.js +78 -46
- package/dist/remote-functions.js.map +1 -1
- package/dist/remote-reactive.d.ts +8 -4
- package/dist/remote-reactive.js.map +1 -1
- package/dist/request-parse.d.ts +13 -13
- package/dist/request-parse.js +29 -15
- package/dist/request-parse.js.map +1 -1
- package/dist/request-runtime.d.ts +16 -11
- package/dist/request-runtime.js +28 -29
- package/dist/request-runtime.js.map +1 -1
- package/dist/request-services.d.ts +10 -8
- package/dist/request-services.js +3 -1
- package/dist/request-services.js.map +1 -1
- package/dist/response-headers.d.ts +2 -3
- package/dist/response-headers.js +2 -1
- package/dist/response-headers.js.map +1 -1
- package/dist/runtime.d.ts +8 -5
- package/dist/runtime.js +4 -1
- package/dist/runtime.js.map +1 -1
- package/dist/server/Endpoint.d.ts +17 -11
- package/dist/server/Endpoint.js +18 -4
- package/dist/server/Endpoint.js.map +1 -1
- package/dist/server/Hooks.d.ts +6 -6
- package/dist/server/Hooks.js +1 -1
- package/dist/server/Hooks.js.map +1 -1
- package/dist/server.d.ts +8 -7
- package/dist/server.js +8 -8
- package/dist/server.js.map +1 -1
- package/dist/streamed-load.d.ts +2 -3
- package/dist/streamed-load.js +1 -1
- package/dist/streamed-load.js.map +1 -1
- package/dist/testing.d.ts +15 -14
- package/dist/testing.js +27 -7
- package/dist/testing.js.map +1 -1
- package/dist/transport.d.ts +6 -7
- package/dist/transport.js +3 -6
- package/dist/transport.js.map +1 -1
- package/dist/universal.d.ts +3 -3
- package/dist/universal.js +1 -1
- package/dist/universal.js.map +1 -1
- package/dist/vite.d.ts +4 -4
- package/dist/vite.js +102 -103
- package/dist/vite.js.map +1 -1
- package/package.json +14 -11
- package/LICENSE +0 -21
package/dist/forms.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { makeSubmitFunction } from "./internal/enhance.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
4
5
|
import { applyAction, deserialize } from "$app/forms";
|
|
5
6
|
//#region src/forms.ts
|
|
6
7
|
/**
|
|
@@ -34,6 +35,7 @@ import { applyAction, deserialize } from "$app/forms";
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
var forms_exports = /* @__PURE__ */ __exportAll({
|
|
38
|
+
ApplyActionError: () => ApplyActionError,
|
|
37
39
|
applyAction: () => applyAction$1,
|
|
38
40
|
deserialize: () => deserialize$1,
|
|
39
41
|
enhance: () => enhance
|
|
@@ -43,15 +45,77 @@ var forms_exports = /* @__PURE__ */ __exportAll({
|
|
|
43
45
|
*
|
|
44
46
|
* `onSubmit` runs before the request (call `input.cancel()` to abort);
|
|
45
47
|
* `onResult` runs on the response with SvelteKit's `update()`. Omit `onResult`
|
|
46
|
-
* to keep SvelteKit's default behaviour.
|
|
47
|
-
* require application services
|
|
48
|
+
* to keep SvelteKit's default behaviour. When the handlers (or `onError`)
|
|
49
|
+
* require application services, pass `{ runtime }` (a `Context` or
|
|
50
|
+
* `ManagedRuntime` providing them): it is then required, and a call without it
|
|
51
|
+
* does not type-check. Each handler may require different services; the runtime
|
|
52
|
+
* must provide all of them. A missing runtime is reported on the call, and one
|
|
53
|
+
* that lacks a service on the runtime, never on a handler; the message may at
|
|
54
|
+
* first name only the services of the handlers TypeScript types first (such as
|
|
55
|
+
* an `onError` passed by name), and the rest once the runtime provides those.
|
|
56
|
+
* Handlers that require no services run on the default runtime, and the options
|
|
57
|
+
* may be omitted; an effect typed as requiring `any` or `unknown` is treated as
|
|
58
|
+
* requiring no services, so no runtime is demanded. A function that wraps
|
|
59
|
+
* `enhance` for handlers requiring any `R` forwards its options as
|
|
60
|
+
* `...options: EnhanceOptionsArgs<R>` (or takes a required
|
|
61
|
+
* `{ runtime: EnhanceRuntime<R> }`): an `EnhanceOptions<R>`, whose runtime is
|
|
62
|
+
* optional, does not type-check there.
|
|
63
|
+
*
|
|
64
|
+
* Either handler may fail. Add an `onError` handler to handle the error
|
|
65
|
+
* (typed as the union of the handlers' error types when written after them;
|
|
66
|
+
* `unknown` when written before a handler with unannotated parameters): a
|
|
67
|
+
* failed `onSubmit` also cancels the submission, and a failed `onResult` does
|
|
68
|
+
* not fall back to SvelteKit's default behaviour. Without `onError`, or for a
|
|
69
|
+
* defect or interruption, the promise SvelteKit awaits rejects (with the error
|
|
70
|
+
* itself for a failure), which SvelteKit leaves unhandled.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const submit = Forms.enhance({
|
|
75
|
+
* onResult: ({ result }) => Forms.applyAction(result),
|
|
76
|
+
* // error: ApplyActionError
|
|
77
|
+
* onError: (error) => Effect.logWarning("applyAction failed", error.cause),
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
48
80
|
*/
|
|
49
81
|
const enhance = makeSubmitFunction;
|
|
50
82
|
/**
|
|
83
|
+
* {@link applyAction} rejected or threw. `cause` is SvelteKit's original
|
|
84
|
+
* reason, unchanged.
|
|
85
|
+
*
|
|
86
|
+
* SvelteKit 3 throws when `applyAction` is called during server rendering, and
|
|
87
|
+
* follows a `redirect` result with a client-side navigation that rejects if it
|
|
88
|
+
* fails: for example, a `location` that cannot be parsed even relative to the
|
|
89
|
+
* page's base URL, or a `beforeNavigate` / `onNavigate` callback that throws. Recover with
|
|
90
|
+
* `Effect.catchTag("ApplyActionError", ...)`.
|
|
91
|
+
*/
|
|
92
|
+
var ApplyActionError = class extends Schema.TaggedError()("ApplyActionError", {
|
|
93
|
+
/** The rejection reason, or the value thrown, as SvelteKit produced it. */
|
|
94
|
+
cause: Schema.Defect() }) {};
|
|
95
|
+
/**
|
|
51
96
|
* Apply an `ActionResult` to the page (updating `page.form` / `page.status`,
|
|
52
97
|
* resetting the form, etc.) as an Effect. Wraps `$app/forms`' `applyAction`.
|
|
98
|
+
*
|
|
99
|
+
* Fails with an {@link ApplyActionError} if SvelteKit rejects or throws: for
|
|
100
|
+
* example, when the navigation that follows a `redirect` result fails, or when
|
|
101
|
+
* called during server rendering.
|
|
102
|
+
*
|
|
103
|
+
* {@link enhance}'s `onResult` can return it directly; its `onError` handler
|
|
104
|
+
* then receives the `ApplyActionError`. Without `onError`, the error rejects
|
|
105
|
+
* the promise SvelteKit awaits.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const submit = Forms.enhance({
|
|
110
|
+
* onResult: ({ result }) => Forms.applyAction(result),
|
|
111
|
+
* onError: (error) => Effect.logWarning("applyAction failed", error.cause),
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
53
114
|
*/
|
|
54
|
-
const applyAction$1 = (result) => Effect.
|
|
115
|
+
const applyAction$1 = (result) => Effect.tryPromise({
|
|
116
|
+
try: () => applyAction(result),
|
|
117
|
+
catch: (cause) => new ApplyActionError({ cause })
|
|
118
|
+
});
|
|
55
119
|
/**
|
|
56
120
|
* Deserialize a raw form-action response body into an `ActionResult`, as an
|
|
57
121
|
* Effect. Wraps `$app/forms`' `deserialize`; a malformed body fails the effect.
|
|
@@ -61,6 +125,6 @@ const deserialize$1 = (result) => Effect.try({
|
|
|
61
125
|
catch: (error) => error
|
|
62
126
|
});
|
|
63
127
|
//#endregion
|
|
64
|
-
export { applyAction$1 as applyAction, deserialize$1 as deserialize, enhance, forms_exports };
|
|
128
|
+
export { ApplyActionError, applyAction$1 as applyAction, deserialize$1 as deserialize, enhance, forms_exports };
|
|
65
129
|
|
|
66
130
|
//# sourceMappingURL=forms.js.map
|
package/dist/forms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forms.js","names":["applyAction","kitApplyAction","deserialize","kitDeserialize"],"sources":["../src/forms.ts"],"sourcesContent":["/**\n * Effect bridge for SvelteKit's native form actions\n * ([`$app/forms`](https://svelte.dev/docs/kit/$app-forms)) — the `Forms`\n * namespace of `@thomasfosterau/effect-sveltekit/client`.\n *\n * This complements `Remote.submitForm` (which covers *remote* forms): here the\n * progressive-enhancement `use:enhance` flow for page `actions` is expressed\n * with Effects, and `applyAction` / `deserialize` are wrapped so a hand-rolled\n * `fetch` submission can be finished off inside an Effect pipeline.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { enhance } from '$app/forms';\n * import { Forms } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * const submit = Forms.enhance({\n * onSubmit: () => Effect.sync(() => { saving = true; }),\n * onResult: ({ result, update }) =>\n * Effect.gen(function* () {\n * yield* Effect.promise(() => update());\n * saving = false;\n * }),\n * });\n * </script>\n *\n * <form method=\"POST\" use:enhance={submit}>...</form>\n * ```\n */\n\nimport { applyAction as kitApplyAction, deserialize as kitDeserialize } from \"$app/forms\";\nimport type { ActionResult } from \"$app/forms\";\nimport
|
|
1
|
+
{"version":3,"file":"forms.js","names":["applyAction","kitApplyAction","deserialize","kitDeserialize"],"sources":["../src/forms.ts"],"sourcesContent":["/**\n * Effect bridge for SvelteKit's native form actions\n * ([`$app/forms`](https://svelte.dev/docs/kit/$app-forms)) — the `Forms`\n * namespace of `@thomasfosterau/effect-sveltekit/client`.\n *\n * This complements `Remote.submitForm` (which covers *remote* forms): here the\n * progressive-enhancement `use:enhance` flow for page `actions` is expressed\n * with Effects, and `applyAction` / `deserialize` are wrapped so a hand-rolled\n * `fetch` submission can be finished off inside an Effect pipeline.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { enhance } from '$app/forms';\n * import { Forms } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * const submit = Forms.enhance({\n * onSubmit: () => Effect.sync(() => { saving = true; }),\n * onResult: ({ result, update }) =>\n * Effect.gen(function* () {\n * yield* Effect.promise(() => update());\n * saving = false;\n * }),\n * });\n * </script>\n *\n * <form method=\"POST\" use:enhance={submit}>...</form>\n * ```\n */\n\nimport { applyAction as kitApplyAction, deserialize as kitDeserialize } from \"$app/forms\";\nimport type { ActionResult } from \"$app/forms\";\nimport * as Schema from \"effect/Schema\";\nimport * as Effect from \"effect/Effect\";\nimport { makeSubmitFunction } from \"./internal/enhance.js\";\n\nexport type {\n EnhanceHandlers,\n EnhanceOptions,\n EnhanceOptionsArgs,\n EnhanceRuntime,\n SubmitInput,\n ResultOptions,\n} from \"./internal/enhance.js\";\n\n/**\n * Build a `SubmitFunction` for `use:enhance` from Effect-based handlers.\n *\n * `onSubmit` runs before the request (call `input.cancel()` to abort);\n * `onResult` runs on the response with SvelteKit's `update()`. Omit `onResult`\n * to keep SvelteKit's default behaviour. When the handlers (or `onError`)\n * require application services, pass `{ runtime }` (a `Context` or\n * `ManagedRuntime` providing them): it is then required, and a call without it\n * does not type-check. Each handler may require different services; the runtime\n * must provide all of them. A missing runtime is reported on the call, and one\n * that lacks a service on the runtime, never on a handler; the message may at\n * first name only the services of the handlers TypeScript types first (such as\n * an `onError` passed by name), and the rest once the runtime provides those.\n * Handlers that require no services run on the default runtime, and the options\n * may be omitted; an effect typed as requiring `any` or `unknown` is treated as\n * requiring no services, so no runtime is demanded. A function that wraps\n * `enhance` for handlers requiring any `R` forwards its options as\n * `...options: EnhanceOptionsArgs<R>` (or takes a required\n * `{ runtime: EnhanceRuntime<R> }`): an `EnhanceOptions<R>`, whose runtime is\n * optional, does not type-check there.\n *\n * Either handler may fail. Add an `onError` handler to handle the error\n * (typed as the union of the handlers' error types when written after them;\n * `unknown` when written before a handler with unannotated parameters): a\n * failed `onSubmit` also cancels the submission, and a failed `onResult` does\n * not fall back to SvelteKit's default behaviour. Without `onError`, or for a\n * defect or interruption, the promise SvelteKit awaits rejects (with the error\n * itself for a failure), which SvelteKit leaves unhandled.\n *\n * @example\n * ```ts\n * const submit = Forms.enhance({\n * onResult: ({ result }) => Forms.applyAction(result),\n * // error: ApplyActionError\n * onError: (error) => Effect.logWarning(\"applyAction failed\", error.cause),\n * });\n * ```\n */\nexport const enhance = makeSubmitFunction;\n\n/**\n * {@link applyAction} rejected or threw. `cause` is SvelteKit's original\n * reason, unchanged.\n *\n * SvelteKit 3 throws when `applyAction` is called during server rendering, and\n * follows a `redirect` result with a client-side navigation that rejects if it\n * fails: for example, a `location` that cannot be parsed even relative to the\n * page's base URL, or a `beforeNavigate` / `onNavigate` callback that throws. Recover with\n * `Effect.catchTag(\"ApplyActionError\", ...)`.\n */\nexport class ApplyActionError extends Schema.TaggedError<ApplyActionError>()(\"ApplyActionError\", {\n /** The rejection reason, or the value thrown, as SvelteKit produced it. */\n cause: Schema.Defect(),\n}) {}\n\n/**\n * Apply an `ActionResult` to the page (updating `page.form` / `page.status`,\n * resetting the form, etc.) as an Effect. Wraps `$app/forms`' `applyAction`.\n *\n * Fails with an {@link ApplyActionError} if SvelteKit rejects or throws: for\n * example, when the navigation that follows a `redirect` result fails, or when\n * called during server rendering.\n *\n * {@link enhance}'s `onResult` can return it directly; its `onError` handler\n * then receives the `ApplyActionError`. Without `onError`, the error rejects\n * the promise SvelteKit awaits.\n *\n * @example\n * ```ts\n * const submit = Forms.enhance({\n * onResult: ({ result }) => Forms.applyAction(result),\n * onError: (error) => Effect.logWarning(\"applyAction failed\", error.cause),\n * });\n * ```\n */\nexport const applyAction = <\n Success extends Record<string, unknown> | undefined = Record<string, unknown>,\n Failure extends Record<string, unknown> | undefined = Record<string, unknown>,\n>(\n result: ActionResult<Success, Failure>,\n): Effect.Effect<void, ApplyActionError> =>\n Effect.tryPromise({\n try: () => kitApplyAction(result),\n catch: (cause) => new ApplyActionError({ cause }),\n });\n\n/**\n * Deserialize a raw form-action response body into an `ActionResult`, as an\n * Effect. Wraps `$app/forms`' `deserialize`; a malformed body fails the effect.\n */\nexport const deserialize = <\n Success extends Record<string, unknown> | undefined = Record<string, unknown>,\n Failure extends Record<string, unknown> | undefined = Record<string, unknown>,\n>(\n result: string,\n): Effect.Effect<ActionResult<Success, Failure>, unknown> =>\n Effect.try({\n try: () => kitDeserialize<Success, Failure>(result),\n catch: (error) => error,\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,MAAa,UAAU;;;;;;;;;;;AAYvB,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;;AAE/F,OAAO,OAAO,OAAO,EACvB,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBJ,MAAaA,iBAIX,WAEA,OAAO,WAAW;CAChB,WAAWC,YAAe,MAAM;CAChC,QAAQ,UAAU,IAAI,iBAAiB,EAAE,MAAM,CAAC;AAClD,CAAC;;;;;AAMH,MAAaC,iBAIX,WAEA,OAAO,IAAI;CACT,WAAWC,YAAiC,MAAM;CAClD,QAAQ,UAAU;AACpB,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { NavigationTarget, NavigationType } from "$app/navigation";
|
|
5
|
+
import "effect/Option";
|
|
2
6
|
//#region src/internal/app-state.d.ts
|
|
3
7
|
/**
|
|
4
8
|
* The fields of SvelteKit's `page` we snapshot. Mirrors the shape of
|
|
5
9
|
* `@sveltejs/kit`'s `Page`, but as a plain readonly record rather than the live
|
|
6
10
|
* mutating proxy.
|
|
7
11
|
*/
|
|
8
|
-
interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {
|
|
12
|
+
export interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {
|
|
9
13
|
readonly url: P["url"];
|
|
10
14
|
readonly params: P["params"];
|
|
11
15
|
readonly route: P["route"];
|
|
@@ -14,6 +18,7 @@ interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {
|
|
|
14
18
|
readonly data: P["data"];
|
|
15
19
|
readonly state: P["state"];
|
|
16
20
|
readonly form: P["form"];
|
|
21
|
+
readonly shallow: P["shallow"];
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
24
|
* The subset of `Page` fields the snapshot reads. Deliberately loose (the value
|
|
@@ -21,7 +26,7 @@ interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {
|
|
|
21
26
|
* / `error` / `state` are app-specific — satisfies the constraint, while
|
|
22
27
|
* `PageSnapshot<P>` recovers the precise field types from `P`.
|
|
23
28
|
*/
|
|
24
|
-
interface ReadonlyPage {
|
|
29
|
+
export interface ReadonlyPage {
|
|
25
30
|
readonly url: Readonly<Omit<URL, "searchParams">>;
|
|
26
31
|
readonly params: Record<string, string | undefined>;
|
|
27
32
|
readonly route: {
|
|
@@ -29,10 +34,42 @@ interface ReadonlyPage {
|
|
|
29
34
|
};
|
|
30
35
|
readonly status: number;
|
|
31
36
|
readonly error: unknown;
|
|
32
|
-
readonly data:
|
|
37
|
+
readonly data: App.PageData;
|
|
33
38
|
readonly state: unknown;
|
|
34
39
|
readonly form: unknown;
|
|
40
|
+
readonly shallow: unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A snapshot of an in-flight SvelteKit navigation, as `$app/state`'s
|
|
44
|
+
* `navigating` exposes it. `delta` is the history step count for a `popstate`
|
|
45
|
+
* navigation and `null` otherwise; `complete` resolves when the navigation
|
|
46
|
+
* finishes and rejects if it fails or is aborted.
|
|
47
|
+
*/
|
|
48
|
+
export interface NavigatingSnapshot {
|
|
49
|
+
readonly type: Exclude<NavigationType, "enter">;
|
|
50
|
+
readonly from: NavigationTarget | null;
|
|
51
|
+
readonly to: NavigationTarget | null;
|
|
52
|
+
readonly willUnload: boolean;
|
|
53
|
+
readonly delta: number | null;
|
|
54
|
+
readonly complete: Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
declare const UpdateCheckError_base: Schema.Class<UpdateCheckError, Schema.TaggedStruct<"UpdateCheckError", {
|
|
57
|
+
/** What `updated.check()` rejected with, or threw. */
|
|
58
|
+
readonly cause: Schema.Defect;
|
|
59
|
+
}>, import("effect/Cause").YieldableError>;
|
|
60
|
+
/**
|
|
61
|
+
* `updated.check()` rejected. SvelteKit resolves `false` when the version
|
|
62
|
+
* request fails, so this signals misuse (e.g. calling it during server
|
|
63
|
+
* rendering, where there is no `window`) rather than a network error.
|
|
64
|
+
*/
|
|
65
|
+
export declare class UpdateCheckError extends UpdateCheckError_base {}
|
|
66
|
+
/** The service behind `State.CurrentPage`: a snapshot and a stream of page changes. */
|
|
67
|
+
export interface CurrentPageService<P extends ReadonlyPage = ReadonlyPage> {
|
|
68
|
+
/** Snapshots the current page when run. */
|
|
69
|
+
readonly get: Effect.Effect<PageSnapshot<P>>;
|
|
70
|
+
/** The current page, then a fresh snapshot whenever any of its fields changes. */
|
|
71
|
+
readonly changes: Stream.Stream<PageSnapshot<P>>;
|
|
35
72
|
}
|
|
36
73
|
//#endregion
|
|
37
|
-
export {
|
|
74
|
+
export {};
|
|
38
75
|
//# sourceMappingURL=app-state.d.ts.map
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Queue from "effect/Queue";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
2
6
|
//#region src/internal/app-state.ts
|
|
3
7
|
/**
|
|
4
|
-
* Pure, `$app/*`-free core for the `$app/state` bridge in `../State.ts`.
|
|
5
|
-
*
|
|
6
|
-
* The public `page` can't be unit-tested directly because importing it
|
|
7
|
-
* pulls in `$app/navigation` and `$app/state` (SvelteKit virtual modules that
|
|
8
|
-
* only exist inside a build). The snapshotting and the "emit now, then after
|
|
9
|
-
* each navigation" plumbing live here instead, parameterised over the
|
|
10
|
-
* navigation registrar and a `readPage` thunk, so they can be driven with
|
|
11
|
-
* stand-ins in tests while the public wrapper stays a thin pass-through.
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
8
|
* Builds a shallow snapshot of the `page` fields that matter. We copy the
|
|
17
9
|
* fields rather than forwarding the live `$app/state` proxy so downstream Effect
|
|
18
10
|
* consumers see a stable value (the proxy mutates in place on every
|
|
@@ -29,7 +21,8 @@ function snapshotPage(page) {
|
|
|
29
21
|
error: page.error,
|
|
30
22
|
data: page.data,
|
|
31
23
|
state: page.state,
|
|
32
|
-
form: page.form
|
|
24
|
+
form: page.form,
|
|
25
|
+
shallow: page.shallow
|
|
33
26
|
};
|
|
34
27
|
}
|
|
35
28
|
/**
|
|
@@ -46,7 +39,63 @@ function pageSnapshotStream(registerAfterNavigate, readPage) {
|
|
|
46
39
|
});
|
|
47
40
|
return Stream.fromQueue(queue);
|
|
48
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A `Stream` of `read()`: the current value, then a new one each time `watch`
|
|
44
|
+
* reports a change. Cold and lazy — each run opens its own watcher and disposes
|
|
45
|
+
* it when the stream ends or is interrupted. Never fails; a throwing `watch`
|
|
46
|
+
* surfaces as a defect (the stream dies with what it threw, with no watcher
|
|
47
|
+
* left to dispose).
|
|
48
|
+
*/
|
|
49
|
+
function watchedStream(watch, read) {
|
|
50
|
+
return Stream.callback((queue) => Effect.acquireRelease(Effect.sync(() => watch(read, (value) => {
|
|
51
|
+
Queue.offerUnsafe(queue, value);
|
|
52
|
+
})), (dispose) => Effect.sync(dispose)));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Copies `navigating` into a plain {@link NavigatingSnapshot}, or `None` when
|
|
56
|
+
* no navigation is in flight (`type` is `null`). Reads every field, so a
|
|
57
|
+
* watcher tracks the whole object.
|
|
58
|
+
*/
|
|
59
|
+
function snapshotNavigating(navigating) {
|
|
60
|
+
const { type, from, to, willUnload, delta, complete } = navigating;
|
|
61
|
+
if (type === null || willUnload === null || complete === null) return Option.none();
|
|
62
|
+
return Option.some({
|
|
63
|
+
type,
|
|
64
|
+
from,
|
|
65
|
+
to,
|
|
66
|
+
willUnload,
|
|
67
|
+
delta: delta ?? null,
|
|
68
|
+
complete
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `updated.check()` rejected. SvelteKit resolves `false` when the version
|
|
73
|
+
* request fails, so this signals misuse (e.g. calling it during server
|
|
74
|
+
* rendering, where there is no `window`) rather than a network error.
|
|
75
|
+
*/
|
|
76
|
+
var UpdateCheckError = class extends Schema.TaggedError()("UpdateCheckError", {
|
|
77
|
+
/** What `updated.check()` rejected with, or threw. */
|
|
78
|
+
cause: Schema.Defect() }) {};
|
|
79
|
+
/**
|
|
80
|
+
* Runs `check` (SvelteKit's `updated.check`) as an Effect that succeeds with
|
|
81
|
+
* whether a new version is available and fails with {@link UpdateCheckError}
|
|
82
|
+
* if the promise rejects (or `check` throws).
|
|
83
|
+
*/
|
|
84
|
+
function checkForUpdateWith(check) {
|
|
85
|
+
return Effect.tryPromise({
|
|
86
|
+
try: () => check(),
|
|
87
|
+
catch: (cause) => new UpdateCheckError({ cause })
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** Builds a {@link CurrentPageService} reading `readPage()` and watching it with `watch`. */
|
|
91
|
+
function makeCurrentPage(readPage, watch) {
|
|
92
|
+
const read = () => snapshotPage(readPage());
|
|
93
|
+
return {
|
|
94
|
+
get: Effect.sync(read),
|
|
95
|
+
changes: watchedStream(watch, read)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
49
98
|
//#endregion
|
|
50
|
-
export { pageSnapshotStream, snapshotPage };
|
|
99
|
+
export { UpdateCheckError, checkForUpdateWith, makeCurrentPage, pageSnapshotStream, snapshotNavigating, snapshotPage, watchedStream };
|
|
51
100
|
|
|
52
101
|
//# sourceMappingURL=app-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-state.js","names":[],"sources":["../../src/internal/app-state.ts"],"sourcesContent":["/**\n * Pure, `$app/*`-free core for the `$app/state` bridge in `../State.ts`.\n *\n * The public `page` can't be unit-tested directly because importing it\n * pulls in `$app/navigation` and `$app/state` (SvelteKit virtual modules that\n * only exist inside a build). The snapshotting and the \"emit now, then after\n * each navigation\" plumbing live here instead, parameterised over the\n * navigation registrar and a `readPage` thunk, so they can be driven with\n * stand-ins in tests while the public wrapper stays a thin pass-through.\n *\n * @internal\n */\n\nimport { Effect, Queue, Stream } from \"effect\";\n\n/**\n * The fields of SvelteKit's `page` we snapshot. Mirrors the shape of\n * `@sveltejs/kit`'s `Page`, but as a plain readonly record rather than the live\n * mutating proxy.\n */\nexport interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {\n readonly url: P[\"url\"];\n readonly params: P[\"params\"];\n readonly route: P[\"route\"];\n readonly status: P[\"status\"];\n readonly error: P[\"error\"];\n readonly data: P[\"data\"];\n readonly state: P[\"state\"];\n readonly form: P[\"form\"];\n}\n\n/**\n * The subset of `Page` fields the snapshot reads. Deliberately loose (the value\n * types are `unknown` / broad) so SvelteKit's `Page` — whose `params` / `data`\n * / `error` / `state` are app-specific — satisfies the constraint, while\n * `PageSnapshot<P>` recovers the precise field types from `P`.\n */\nexport interface ReadonlyPage {\n // SvelteKit 3 types `page.url` as an immutable `ReadonlyURL` (from\n // `$app/state`); everything but `searchParams` is enough here.\n readonly url: Readonly<Omit<URL, \"searchParams\">>;\n readonly params: Record<string, string | undefined>;\n readonly route: { readonly id: string | null };\n readonly status: number;\n readonly error: unknown;\n readonly data: Record<string, unknown>;\n readonly state: unknown;\n readonly form: unknown;\n}\n\n/**\n * Builds a shallow snapshot of the `page` fields that matter. We copy the\n * fields rather than forwarding the live `$app/state` proxy so downstream Effect\n * consumers see a stable value (the proxy mutates in place on every\n * navigation, which would make a captured reference unreliable). Nested values\n * (`url`, `data`, ...) are *not* deep-cloned: they're replaced wholesale on each\n * navigation, so a shallow copy is enough to distinguish snapshots.\n */\nexport function snapshotPage<P extends ReadonlyPage>(page: P): PageSnapshot<P> {\n return {\n url: page.url,\n params: page.params,\n route: page.route,\n status: page.status,\n error: page.error,\n data: page.data,\n state: page.state,\n form: page.form,\n };\n}\n\n/**\n * Emits a snapshot of `readPage()` immediately, then again every time\n * `registerAfterNavigate`'s callback fires (i.e. after each navigation). Backed\n * by an unbounded queue, exposed as a `Stream` — the same push bridge as the\n * navigation-event helpers.\n */\nexport function pageSnapshotStream<P extends ReadonlyPage>(\n registerAfterNavigate: (callback: () => void) => void,\n readPage: () => P,\n): Stream.Stream<PageSnapshot<P>> {\n const queue = Effect.runSync(Queue.unbounded<PageSnapshot<P>>());\n // Initial value: the current page, so consumers start from a known state.\n Queue.offerUnsafe(queue, snapshotPage(readPage()));\n // afterNavigate fires once on mount too, but emitting up front means a\n // late-subscribing consumer still sees the current page without waiting for a\n // navigation.\n registerAfterNavigate(() => {\n Queue.offerUnsafe(queue, snapshotPage(readPage()));\n });\n return Stream.fromQueue(queue);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,aAAqC,MAA0B;CAC7E,OAAO;EACL,KAAK,KAAK;EACV,QAAQ,KAAK;EACb,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,OAAO,KAAK;EACZ,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,MAAM,KAAK;CACb;AACF;;;;;;;AAQA,SAAgB,mBACd,uBACA,UACgC;CAChC,MAAM,QAAQ,OAAO,QAAQ,MAAM,UAA2B,CAAC;CAE/D,MAAM,YAAY,OAAO,aAAa,SAAS,CAAC,CAAC;CAIjD,4BAA4B;EAC1B,MAAM,YAAY,OAAO,aAAa,SAAS,CAAC,CAAC;CACnD,CAAC;CACD,OAAO,OAAO,UAAU,KAAK;AAC/B"}
|
|
1
|
+
{"version":3,"file":"app-state.js","names":[],"sources":["../../src/internal/app-state.ts"],"sourcesContent":["/**\n * Pure, `$app/*`-free core for the `$app/state` bridge in `../State.ts`.\n *\n * The public helpers can't be unit-tested in plain Node because importing them\n * pulls in `$app/navigation` and `$app/state` (SvelteKit virtual modules that\n * only exist inside a build). The snapshotting, the \"emit now, then after each\n * navigation\" plumbing and the watch-to-`Stream` bridge live here instead,\n * parameterised over the navigation registrar, a {@link Watch} function and\n * read thunks, so they can be driven with stand-ins in tests while the public\n * wrappers stay thin pass-throughs. The only runes code is `watch.svelte.ts`.\n *\n * @internal\n */\n\nimport type { NavigationTarget, NavigationType } from \"$app/navigation\";\nimport * as Schema from \"effect/Schema\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Queue from \"effect/Queue\";\nimport * as Stream from \"effect/Stream\";\n\n/**\n * The fields of SvelteKit's `page` we snapshot. Mirrors the shape of\n * `@sveltejs/kit`'s `Page`, but as a plain readonly record rather than the live\n * mutating proxy.\n */\nexport interface PageSnapshot<P extends ReadonlyPage = ReadonlyPage> {\n readonly url: P[\"url\"];\n readonly params: P[\"params\"];\n readonly route: P[\"route\"];\n readonly status: P[\"status\"];\n readonly error: P[\"error\"];\n readonly data: P[\"data\"];\n readonly state: P[\"state\"];\n readonly form: P[\"form\"];\n readonly shallow: P[\"shallow\"];\n}\n\n/**\n * The subset of `Page` fields the snapshot reads. Deliberately loose (the value\n * types are `unknown` / broad) so SvelteKit's `Page` — whose `params` / `data`\n * / `error` / `state` are app-specific — satisfies the constraint, while\n * `PageSnapshot<P>` recovers the precise field types from `P`.\n */\nexport interface ReadonlyPage {\n // SvelteKit 3 types `page.url` as an immutable `ReadonlyURL` (from\n // `$app/state`); everything but `searchParams` is enough here.\n readonly url: Readonly<Omit<URL, \"searchParams\">>;\n readonly params: Record<string, string | undefined>;\n readonly route: { readonly id: string | null };\n readonly status: number;\n readonly error: unknown;\n readonly data: App.PageData;\n readonly state: unknown;\n readonly form: unknown;\n // SvelteKit 3: the target of the current shallow navigation, or `null`.\n readonly shallow: unknown;\n}\n\n/**\n * Builds a shallow snapshot of the `page` fields that matter. We copy the\n * fields rather than forwarding the live `$app/state` proxy so downstream Effect\n * consumers see a stable value (the proxy mutates in place on every\n * navigation, which would make a captured reference unreliable). Nested values\n * (`url`, `data`, ...) are *not* deep-cloned: they're replaced wholesale on each\n * navigation, so a shallow copy is enough to distinguish snapshots.\n */\nexport function snapshotPage<P extends ReadonlyPage>(page: P): PageSnapshot<P> {\n return {\n url: page.url,\n params: page.params,\n route: page.route,\n status: page.status,\n error: page.error,\n data: page.data,\n state: page.state,\n form: page.form,\n shallow: page.shallow,\n };\n}\n\n/**\n * Emits a snapshot of `readPage()` immediately, then again every time\n * `registerAfterNavigate`'s callback fires (i.e. after each navigation). Backed\n * by an unbounded queue, exposed as a `Stream` — the same push bridge as the\n * navigation-event helpers.\n */\nexport function pageSnapshotStream<P extends ReadonlyPage>(\n registerAfterNavigate: (callback: () => void) => void,\n readPage: () => P,\n): Stream.Stream<PageSnapshot<P>> {\n const queue = Effect.runSync(Queue.unbounded<PageSnapshot<P>>());\n // Initial value: the current page, so consumers start from a known state.\n Queue.offerUnsafe(queue, snapshotPage(readPage()));\n // afterNavigate fires once on mount too, but emitting up front means a\n // late-subscribing consumer still sees the current page without waiting for a\n // navigation.\n registerAfterNavigate(() => {\n Queue.offerUnsafe(queue, snapshotPage(readPage()));\n });\n return Stream.fromQueue(queue);\n}\n\n// ─── Watching rune state ─────────────────────────────────────────────────────\n\n/**\n * Observes a reactive read: calls `onValue` with `read()` once, then again\n * whenever something `read` touched changes, until the returned disposer runs.\n * The real implementation is `watch` in `./watch.svelte.ts`.\n */\nexport type Watch = <A>(read: () => A, onValue: (value: A) => void) => () => void;\n\n/**\n * A `Stream` of `read()`: the current value, then a new one each time `watch`\n * reports a change. Cold and lazy — each run opens its own watcher and disposes\n * it when the stream ends or is interrupted. Never fails; a throwing `watch`\n * surfaces as a defect (the stream dies with what it threw, with no watcher\n * left to dispose).\n */\nexport function watchedStream<A>(watch: Watch, read: () => A): Stream.Stream<A> {\n return Stream.callback<A>((queue) =>\n Effect.acquireRelease(\n Effect.sync(() =>\n watch(read, (value) => {\n Queue.offerUnsafe(queue, value);\n }),\n ),\n (dispose) => Effect.sync(dispose),\n ),\n );\n}\n\n// ─── navigating ──────────────────────────────────────────────────────────────\n\n/**\n * A snapshot of an in-flight SvelteKit navigation, as `$app/state`'s\n * `navigating` exposes it. `delta` is the history step count for a `popstate`\n * navigation and `null` otherwise; `complete` resolves when the navigation\n * finishes and rejects if it fails or is aborted.\n */\nexport interface NavigatingSnapshot {\n readonly type: Exclude<NavigationType, \"enter\">;\n readonly from: NavigationTarget | null;\n readonly to: NavigationTarget | null;\n readonly willUnload: boolean;\n readonly delta: number | null;\n readonly complete: Promise<void>;\n}\n\n/**\n * The shape of `$app/state`'s `navigating`: every field is `null` while no\n * navigation is in flight.\n */\nexport interface ReadonlyNavigating {\n readonly type: NavigatingSnapshot[\"type\"] | null;\n readonly from: NavigationTarget | null;\n readonly to: NavigationTarget | null;\n readonly willUnload: boolean | null;\n readonly delta?: number | null | undefined;\n readonly complete: Promise<void> | null;\n}\n\n/**\n * Copies `navigating` into a plain {@link NavigatingSnapshot}, or `None` when\n * no navigation is in flight (`type` is `null`). Reads every field, so a\n * watcher tracks the whole object.\n */\nexport function snapshotNavigating(\n navigating: ReadonlyNavigating,\n): Option.Option<NavigatingSnapshot> {\n const { type, from, to, willUnload, delta, complete } = navigating;\n if (type === null || willUnload === null || complete === null) return Option.none();\n return Option.some({ type, from, to, willUnload, delta: delta ?? null, complete });\n}\n\n// ─── updated ─────────────────────────────────────────────────────────────────\n\n/**\n * `updated.check()` rejected. SvelteKit resolves `false` when the version\n * request fails, so this signals misuse (e.g. calling it during server\n * rendering, where there is no `window`) rather than a network error.\n */\nexport class UpdateCheckError extends Schema.TaggedError<UpdateCheckError>()(\"UpdateCheckError\", {\n /** What `updated.check()` rejected with, or threw. */\n cause: Schema.Defect(),\n}) {}\n\n/**\n * Runs `check` (SvelteKit's `updated.check`) as an Effect that succeeds with\n * whether a new version is available and fails with {@link UpdateCheckError}\n * if the promise rejects (or `check` throws).\n */\nexport function checkForUpdateWith(\n check: () => Promise<boolean>,\n): Effect.Effect<boolean, UpdateCheckError> {\n return Effect.tryPromise({\n try: () => check(),\n catch: (cause) => new UpdateCheckError({ cause }),\n });\n}\n\n// ─── CurrentPage ─────────────────────────────────────────────────────────────\n\n/** The service behind `State.CurrentPage`: a snapshot and a stream of page changes. */\nexport interface CurrentPageService<P extends ReadonlyPage = ReadonlyPage> {\n /** Snapshots the current page when run. */\n readonly get: Effect.Effect<PageSnapshot<P>>;\n /** The current page, then a fresh snapshot whenever any of its fields changes. */\n readonly changes: Stream.Stream<PageSnapshot<P>>;\n}\n\n/** Builds a {@link CurrentPageService} reading `readPage()` and watching it with `watch`. */\nexport function makeCurrentPage<P extends ReadonlyPage>(\n readPage: () => P,\n watch: Watch,\n): CurrentPageService<P> {\n const read = (): PageSnapshot<P> => snapshotPage(readPage());\n return { get: Effect.sync(read), changes: watchedStream(watch, read) };\n}\n"],"mappings":";;;;;;;;;;;;;;AAmEA,SAAgB,aAAqC,MAA0B;CAC7E,OAAO;EACL,KAAK,KAAK;EACV,QAAQ,KAAK;EACb,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,OAAO,KAAK;EACZ,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,MAAM,KAAK;EACX,SAAS,KAAK;CAChB;AACF;;;;;;;AAQA,SAAgB,mBACd,uBACA,UACgC;CAChC,MAAM,QAAQ,OAAO,QAAQ,MAAM,UAA2B,CAAC;CAE/D,MAAM,YAAY,OAAO,aAAa,SAAS,CAAC,CAAC;CAIjD,4BAA4B;EAC1B,MAAM,YAAY,OAAO,aAAa,SAAS,CAAC,CAAC;CACnD,CAAC;CACD,OAAO,OAAO,UAAU,KAAK;AAC/B;;;;;;;;AAkBA,SAAgB,cAAiB,OAAc,MAAiC;CAC9E,OAAO,OAAO,UAAa,UACzB,OAAO,eACL,OAAO,WACL,MAAM,OAAO,UAAU;EACrB,MAAM,YAAY,OAAO,KAAK;CAChC,CAAC,CACH,IACC,YAAY,OAAO,KAAK,OAAO,CAClC,CACF;AACF;;;;;;AAqCA,SAAgB,mBACd,YACmC;CACnC,MAAM,EAAE,MAAM,MAAM,IAAI,YAAY,OAAO,aAAa;CACxD,IAAI,SAAS,QAAQ,eAAe,QAAQ,aAAa,MAAM,OAAO,OAAO,KAAK;CAClF,OAAO,OAAO,KAAK;EAAE;EAAM;EAAM;EAAI;EAAY,OAAO,SAAS;EAAM;CAAS,CAAC;AACnF;;;;;;AASA,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;;AAE/F,OAAO,OAAO,OAAO,EACvB,CAAC,CAAC,CAAC,CAAC;;;;;;AAOJ,SAAgB,mBACd,OAC0C;CAC1C,OAAO,OAAO,WAAW;EACvB,WAAW,MAAM;EACjB,QAAQ,UAAU,IAAI,iBAAiB,EAAE,MAAM,CAAC;CAClD,CAAC;AACH;;AAaA,SAAgB,gBACd,UACA,OACuB;CACvB,MAAM,aAA8B,aAAa,SAAS,CAAC;CAC3D,OAAO;EAAE,KAAK,OAAO,KAAK,IAAI;EAAG,SAAS,cAAc,OAAO,IAAI;CAAE;AACvE"}
|
package/dist/internal/auto.d.ts
CHANGED
|
@@ -1,70 +1,79 @@
|
|
|
1
1
|
import { ServerRuntime, UniversalRuntime } from "../app-runtime.js";
|
|
2
|
-
import
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
3
|
import { Action, Actions, Load, RequestEvent, ServerLoad } from "@sveltejs/kit";
|
|
4
4
|
import { Handle, HandleClientError, HandleFetch, HandleServerError, Reroute } from "@sveltejs/kit/hooks";
|
|
5
5
|
//#region src/internal/auto.d.ts
|
|
6
6
|
type AnyEffect = Effect.Effect<unknown, unknown, never>;
|
|
7
|
+
/**
|
|
8
|
+
* The function form of a user export: called with the hook / load argument, it
|
|
9
|
+
* returns an Effect to run or a plain SvelteKit value to pass through. Its
|
|
10
|
+
* result is only known at runtime (`Effect.isEffect` tells the two apart).
|
|
11
|
+
*/
|
|
12
|
+
type UserFn<Arg> = (arg: Arg) => unknown;
|
|
13
|
+
/** The argument-less function form of a user `init` export (see {@link UserFn}). */
|
|
14
|
+
type UserThunk = () => unknown;
|
|
7
15
|
type AnyRuntime = ServerRuntime<any, any> | UniversalRuntime<any, any>;
|
|
8
16
|
/**
|
|
9
17
|
* Module shape accepted for the plugin's `serverRuntime` / `clientRuntime`
|
|
10
18
|
* options: the runtime can be the default export or a named `runtime` export.
|
|
11
19
|
*/
|
|
12
|
-
interface RuntimeModule {
|
|
20
|
+
export interface RuntimeModule {
|
|
13
21
|
readonly runtime?: AnyRuntime;
|
|
14
22
|
readonly default?: AnyRuntime;
|
|
15
23
|
}
|
|
16
|
-
type LoadLikeInput = undefined | AnyEffect |
|
|
24
|
+
type LoadLikeInput = undefined | AnyEffect | UserFn<any>;
|
|
17
25
|
/**
|
|
18
26
|
* Wraps a value intended to be a SvelteKit universal `load` export.
|
|
19
27
|
* Used by the Vite plugin for `+page.ts` / `+layout.ts`.
|
|
20
28
|
*/
|
|
21
|
-
declare function wrapLoad<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Load;
|
|
29
|
+
export declare function wrapLoad<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Load;
|
|
22
30
|
/**
|
|
23
31
|
* Wraps a value intended to be a SvelteKit server `load` export.
|
|
24
32
|
* Used by the Vite plugin for `+page.server.ts` / `+layout.server.ts`.
|
|
25
33
|
*/
|
|
26
|
-
declare function wrapServerLoad<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : ServerLoad;
|
|
34
|
+
export declare function wrapServerLoad<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : ServerLoad;
|
|
27
35
|
/**
|
|
28
36
|
* Wraps a single SvelteKit action handler.
|
|
29
37
|
*/
|
|
30
|
-
declare function wrapAction<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Action;
|
|
38
|
+
export declare function wrapAction<T extends LoadLikeInput>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Action;
|
|
31
39
|
/**
|
|
32
40
|
* Wraps a SvelteKit `actions` object, individually wrapping each entry.
|
|
33
41
|
*/
|
|
34
|
-
declare function wrapActions<T extends Record<string, LoadLikeInput> | undefined>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Actions;
|
|
42
|
+
export declare function wrapActions<T extends Record<string, LoadLikeInput> | undefined>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Actions;
|
|
35
43
|
/**
|
|
36
44
|
* Wraps a SvelteKit `handle` hook export.
|
|
37
45
|
*/
|
|
38
|
-
declare function wrapHandle<T extends undefined | AnyEffect |
|
|
46
|
+
export declare function wrapHandle<T extends undefined | AnyEffect | UserFn<Parameters<Handle>[0]>>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Handle;
|
|
39
47
|
/**
|
|
40
48
|
* Wraps a SvelteKit `handleFetch` hook export.
|
|
41
49
|
*/
|
|
42
|
-
declare function wrapHandleFetch<T extends undefined | AnyEffect |
|
|
50
|
+
export declare function wrapHandleFetch<T extends undefined | AnyEffect | UserFn<Parameters<HandleFetch>[0]>>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : HandleFetch;
|
|
43
51
|
type AnyHandleError = HandleServerError | HandleClientError;
|
|
52
|
+
type HandleErrorInput = Parameters<AnyHandleError>[0];
|
|
44
53
|
/**
|
|
45
54
|
* Wraps a SvelteKit `handleError` hook export.
|
|
46
55
|
*/
|
|
47
|
-
declare function wrapHandleError<T extends undefined | AnyEffect |
|
|
56
|
+
export declare function wrapHandleError<T extends undefined | AnyEffect | UserFn<HandleErrorInput>>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : AnyHandleError;
|
|
48
57
|
/**
|
|
49
58
|
* Wraps a SvelteKit HTTP endpoint export (`GET`, `POST`, etc.).
|
|
50
59
|
* Errors thrown by the underlying Effect propagate to SvelteKit's normal
|
|
51
60
|
* error-handling pipeline (i.e. they are not silently swallowed). Use the
|
|
52
61
|
* explicit `endpoint()` helper if you need the `exposeErrors` toggle.
|
|
53
62
|
*/
|
|
54
|
-
declare function wrapEndpoint<T extends undefined | AnyEffect |
|
|
63
|
+
export declare function wrapEndpoint<T extends undefined | AnyEffect | UserFn<RequestEvent>>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : (event: RequestEvent) => Response | Promise<Response>;
|
|
55
64
|
type RerouteEvent = Parameters<Reroute>[0];
|
|
56
65
|
/**
|
|
57
66
|
* Wraps a SvelteKit universal `reroute` hook export. The effect runs on the
|
|
58
67
|
* universal runtime with an `HttpClient` backed by the event's `fetch`, on both
|
|
59
68
|
* the server and the client.
|
|
60
69
|
*/
|
|
61
|
-
declare function wrapReroute<T extends undefined | AnyEffect |
|
|
70
|
+
export declare function wrapReroute<T extends undefined | AnyEffect | UserFn<RerouteEvent>>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : Reroute;
|
|
62
71
|
/**
|
|
63
72
|
* Wraps a SvelteKit `init` hook export (server or client).
|
|
64
73
|
* `init` runs once at startup; there is no request event available, but the
|
|
65
74
|
* application runtime's services (if configured) are.
|
|
66
75
|
*/
|
|
67
|
-
declare function wrapInit<T extends undefined | AnyEffect |
|
|
76
|
+
export declare function wrapInit<T extends undefined | AnyEffect | UserThunk>(value: T, runtimeMod?: RuntimeModule): T extends undefined ? undefined : () => Promise<void>;
|
|
68
77
|
//#endregion
|
|
69
|
-
export {
|
|
78
|
+
export {};
|
|
70
79
|
//# sourceMappingURL=auto.d.ts.map
|
package/dist/internal/auto.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { causeToThrowable } from "./error.js";
|
|
2
2
|
import { makeServerRuntime, makeUniversalRuntime } from "../app-runtime.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Exit from "effect/Exit";
|
|
5
|
+
import * as Predicate from "effect/Predicate";
|
|
6
|
+
import * as Rec from "effect/Record";
|
|
7
|
+
import * as Result from "effect/Result";
|
|
4
8
|
//#region src/internal/auto.ts
|
|
5
9
|
let defaultServerRuntime;
|
|
6
10
|
let defaultUniversalRuntime;
|
|
@@ -30,27 +34,33 @@ async function runBare(effect, runtime) {
|
|
|
30
34
|
onSuccess: (value) => value
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Detect an Effect returned by (or exported as) a user hook. Its requirements
|
|
39
|
+
* are typed `never`: the user's export may only need what the runtime provides,
|
|
40
|
+
* and anything else surfaces as a missing-service defect when it runs.
|
|
41
|
+
*/
|
|
42
|
+
const isUserEffect = (value) => Effect.isEffect(value);
|
|
43
|
+
/** A user export's Effect form as is, or the result of calling its function form with `arg`. */
|
|
44
|
+
const resolveExport = (value, arg) => Effect.isEffect(value) ? value : value(arg);
|
|
36
45
|
/**
|
|
37
46
|
* Wraps a value intended to be a SvelteKit universal `load` export.
|
|
38
47
|
* Used by the Vite plugin for `+page.ts` / `+layout.ts`.
|
|
39
48
|
*/
|
|
40
49
|
function wrapLoad(value, runtimeMod) {
|
|
41
|
-
if (value === void 0) return
|
|
42
|
-
|
|
43
|
-
const result =
|
|
44
|
-
if (!
|
|
50
|
+
if (value === void 0) return;
|
|
51
|
+
const load = async (event) => {
|
|
52
|
+
const result = resolveExport(value, event);
|
|
53
|
+
if (!Effect.isEffect(result)) return result;
|
|
45
54
|
return universalRuntimeOf(runtimeMod).load(() => result)(event);
|
|
46
|
-
}
|
|
55
|
+
};
|
|
56
|
+
return load;
|
|
47
57
|
}
|
|
48
58
|
/** Shared implementation for server-side, event-based wrappers. */
|
|
49
59
|
function wrapServerEvent(value, runtimeMod) {
|
|
50
60
|
if (value === void 0) return void 0;
|
|
51
61
|
return async (event) => {
|
|
52
|
-
const result =
|
|
53
|
-
if (!
|
|
62
|
+
const result = resolveExport(value, event);
|
|
63
|
+
if (!Effect.isEffect(result)) return result;
|
|
54
64
|
return serverRuntimeOf(runtimeMod).runPromise(event, result);
|
|
55
65
|
};
|
|
56
66
|
}
|
|
@@ -71,23 +81,20 @@ function wrapAction(value, runtimeMod) {
|
|
|
71
81
|
* Wraps a SvelteKit `actions` object, individually wrapping each entry.
|
|
72
82
|
*/
|
|
73
83
|
function wrapActions(value, runtimeMod) {
|
|
74
|
-
if (value === void 0) return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (wrappedAction !== void 0) wrapped[key] = wrappedAction;
|
|
80
|
-
}
|
|
81
|
-
return wrapped;
|
|
84
|
+
if (value === void 0 || !Predicate.isObjectOrArray(value)) return value;
|
|
85
|
+
return Rec.filterMap(value, (fn) => {
|
|
86
|
+
const wrappedAction = wrapServerEvent(fn, runtimeMod);
|
|
87
|
+
return wrappedAction === void 0 ? Result.fail(void 0) : Result.succeed(wrappedAction);
|
|
88
|
+
});
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
* Wraps a SvelteKit `handle` hook export.
|
|
85
92
|
*/
|
|
86
93
|
function wrapHandle(value, runtimeMod) {
|
|
87
|
-
if (value === void 0) return
|
|
94
|
+
if (value === void 0) return;
|
|
88
95
|
const handle = (input) => {
|
|
89
|
-
const result =
|
|
90
|
-
if (!
|
|
96
|
+
const result = resolveExport(value, input);
|
|
97
|
+
if (!Effect.isEffect(result)) return result;
|
|
91
98
|
return serverRuntimeOf(runtimeMod).handle(() => result)(input);
|
|
92
99
|
};
|
|
93
100
|
return handle;
|
|
@@ -96,10 +103,10 @@ function wrapHandle(value, runtimeMod) {
|
|
|
96
103
|
* Wraps a SvelteKit `handleFetch` hook export.
|
|
97
104
|
*/
|
|
98
105
|
function wrapHandleFetch(value, runtimeMod) {
|
|
99
|
-
if (value === void 0) return
|
|
106
|
+
if (value === void 0) return;
|
|
100
107
|
const handleFetch = async (args) => {
|
|
101
|
-
const result =
|
|
102
|
-
if (!
|
|
108
|
+
const result = resolveExport(value, args);
|
|
109
|
+
if (!Effect.isEffect(result)) return result;
|
|
103
110
|
return serverRuntimeOf(runtimeMod).runPromise(args.event, result);
|
|
104
111
|
};
|
|
105
112
|
return handleFetch;
|
|
@@ -108,14 +115,15 @@ function wrapHandleFetch(value, runtimeMod) {
|
|
|
108
115
|
* Wraps a SvelteKit `handleError` hook export.
|
|
109
116
|
*/
|
|
110
117
|
function wrapHandleError(value, runtimeMod) {
|
|
111
|
-
if (value === void 0) return
|
|
112
|
-
|
|
113
|
-
const result =
|
|
114
|
-
if (!
|
|
118
|
+
if (value === void 0) return;
|
|
119
|
+
const handleError = async (args) => {
|
|
120
|
+
const result = resolveExport(value, args);
|
|
121
|
+
if (!isUserEffect(result)) return result;
|
|
115
122
|
const event = args.event;
|
|
116
123
|
if (event !== void 0 && "request" in event) return serverRuntimeOf(runtimeMod).runPromise(event, result);
|
|
117
124
|
return runBare(result, runtimeOfModule(runtimeMod));
|
|
118
|
-
}
|
|
125
|
+
};
|
|
126
|
+
return handleError;
|
|
119
127
|
}
|
|
120
128
|
/**
|
|
121
129
|
* Wraps a SvelteKit HTTP endpoint export (`GET`, `POST`, etc.).
|
|
@@ -132,12 +140,13 @@ function wrapEndpoint(value, runtimeMod) {
|
|
|
132
140
|
* the server and the client.
|
|
133
141
|
*/
|
|
134
142
|
function wrapReroute(value, runtimeMod) {
|
|
135
|
-
if (value === void 0) return
|
|
136
|
-
|
|
137
|
-
const result =
|
|
138
|
-
if (!
|
|
143
|
+
if (value === void 0) return;
|
|
144
|
+
const reroute = (event) => {
|
|
145
|
+
const result = resolveExport(value, event);
|
|
146
|
+
if (!Effect.isEffect(result)) return result;
|
|
139
147
|
return universalRuntimeOf(runtimeMod).runPromise(event.fetch, result);
|
|
140
|
-
}
|
|
148
|
+
};
|
|
149
|
+
return reroute;
|
|
141
150
|
}
|
|
142
151
|
/**
|
|
143
152
|
* Wraps a SvelteKit `init` hook export (server or client).
|
|
@@ -145,15 +154,16 @@ function wrapReroute(value, runtimeMod) {
|
|
|
145
154
|
* application runtime's services (if configured) are.
|
|
146
155
|
*/
|
|
147
156
|
function wrapInit(value, runtimeMod) {
|
|
148
|
-
if (value === void 0) return
|
|
149
|
-
|
|
150
|
-
const result =
|
|
151
|
-
if (!
|
|
157
|
+
if (value === void 0) return;
|
|
158
|
+
const init = async () => {
|
|
159
|
+
const result = Effect.isEffect(value) ? value : value();
|
|
160
|
+
if (!isUserEffect(result)) {
|
|
152
161
|
await result;
|
|
153
162
|
return;
|
|
154
163
|
}
|
|
155
164
|
await runBare(result, runtimeOfModule(runtimeMod));
|
|
156
|
-
}
|
|
165
|
+
};
|
|
166
|
+
return init;
|
|
157
167
|
}
|
|
158
168
|
//#endregion
|
|
159
169
|
export { wrapAction, wrapActions, wrapEndpoint, wrapHandle, wrapHandleError, wrapHandleFetch, wrapInit, wrapLoad, wrapReroute, wrapServerLoad };
|