@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.
Files changed (121) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +178 -83
  3. package/dist/Hooks.d.ts +3 -3
  4. package/dist/Hooks.js +1 -1
  5. package/dist/Hooks.js.map +1 -1
  6. package/dist/Navigation.d.ts +70 -17
  7. package/dist/Navigation.js +93 -19
  8. package/dist/Navigation.js.map +1 -1
  9. package/dist/Remote.d.ts +54 -35
  10. package/dist/Remote.js +22 -11
  11. package/dist/Remote.js.map +1 -1
  12. package/dist/State.d.ts +79 -6
  13. package/dist/State.js +117 -27
  14. package/dist/State.js.map +1 -1
  15. package/dist/adapter/assets.d.ts +24 -7
  16. package/dist/adapter/assets.js +58 -37
  17. package/dist/adapter/assets.js.map +1 -1
  18. package/dist/adapter/handler.d.ts +27 -12
  19. package/dist/adapter/handler.js +53 -26
  20. package/dist/adapter/handler.js.map +1 -1
  21. package/dist/adapter/index.d.ts +3 -3
  22. package/dist/adapter/index.js +1 -1
  23. package/dist/adapter/index.js.map +1 -1
  24. package/dist/adapter/serve.d.ts +6 -5
  25. package/dist/adapter/serve.js +3 -1
  26. package/dist/adapter/serve.js.map +1 -1
  27. package/dist/api-client.d.ts +3 -4
  28. package/dist/api-client.js +2 -1
  29. package/dist/api-client.js.map +1 -1
  30. package/dist/app-runtime.d.ts +12 -9
  31. package/dist/app-runtime.js +23 -14
  32. package/dist/app-runtime.js.map +1 -1
  33. package/dist/client/Hooks.d.ts +4 -4
  34. package/dist/client/Hooks.js +2 -1
  35. package/dist/client/Hooks.js.map +1 -1
  36. package/dist/client.d.ts +2 -2
  37. package/dist/config.d.ts +7 -5
  38. package/dist/config.js +5 -34
  39. package/dist/config.js.map +1 -1
  40. package/dist/errors.d.ts +14 -16
  41. package/dist/errors.js +20 -12
  42. package/dist/errors.js.map +1 -1
  43. package/dist/forms.d.ts +70 -8
  44. package/dist/forms.js +69 -5
  45. package/dist/forms.js.map +1 -1
  46. package/dist/internal/app-state.d.ts +42 -5
  47. package/dist/internal/app-state.js +64 -15
  48. package/dist/internal/app-state.js.map +1 -1
  49. package/dist/internal/auto.d.ts +23 -14
  50. package/dist/internal/auto.js +50 -40
  51. package/dist/internal/auto.js.map +1 -1
  52. package/dist/internal/enhance.d.ts +114 -14
  53. package/dist/internal/enhance.js +33 -7
  54. package/dist/internal/enhance.js.map +1 -1
  55. package/dist/internal/error.d.ts +13 -0
  56. package/dist/internal/error.js +4 -3
  57. package/dist/internal/error.js.map +1 -1
  58. package/dist/internal/navigation-events.js +3 -1
  59. package/dist/internal/navigation-events.js.map +1 -1
  60. package/dist/internal/remote-run.d.ts +6 -6
  61. package/dist/internal/remote-run.js +13 -16
  62. package/dist/internal/remote-run.js.map +1 -1
  63. package/dist/internal/remote-validators.js +4 -3
  64. package/dist/internal/remote-validators.js.map +1 -1
  65. package/dist/internal/route-params.d.ts +1 -2
  66. package/dist/internal/sse.js +2 -1
  67. package/dist/internal/sse.js.map +1 -1
  68. package/dist/internal/watch.svelte.js +33 -0
  69. package/dist/internal/watch.svelte.js.map +1 -0
  70. package/dist/kit.d.ts +12 -11
  71. package/dist/kit.js +6 -2
  72. package/dist/kit.js.map +1 -1
  73. package/dist/realtime.d.ts +49 -30
  74. package/dist/realtime.js +90 -46
  75. package/dist/realtime.js.map +1 -1
  76. package/dist/remote-functions.d.ts +34 -18
  77. package/dist/remote-functions.js +78 -46
  78. package/dist/remote-functions.js.map +1 -1
  79. package/dist/remote-reactive.d.ts +8 -4
  80. package/dist/remote-reactive.js.map +1 -1
  81. package/dist/request-parse.d.ts +13 -13
  82. package/dist/request-parse.js +29 -15
  83. package/dist/request-parse.js.map +1 -1
  84. package/dist/request-runtime.d.ts +16 -11
  85. package/dist/request-runtime.js +28 -29
  86. package/dist/request-runtime.js.map +1 -1
  87. package/dist/request-services.d.ts +10 -8
  88. package/dist/request-services.js +3 -1
  89. package/dist/request-services.js.map +1 -1
  90. package/dist/response-headers.d.ts +2 -3
  91. package/dist/response-headers.js +2 -1
  92. package/dist/response-headers.js.map +1 -1
  93. package/dist/runtime.d.ts +8 -5
  94. package/dist/runtime.js +4 -1
  95. package/dist/runtime.js.map +1 -1
  96. package/dist/server/Endpoint.d.ts +17 -11
  97. package/dist/server/Endpoint.js +18 -4
  98. package/dist/server/Endpoint.js.map +1 -1
  99. package/dist/server/Hooks.d.ts +6 -6
  100. package/dist/server/Hooks.js +1 -1
  101. package/dist/server/Hooks.js.map +1 -1
  102. package/dist/server.d.ts +8 -7
  103. package/dist/server.js +8 -8
  104. package/dist/server.js.map +1 -1
  105. package/dist/streamed-load.d.ts +2 -3
  106. package/dist/streamed-load.js +1 -1
  107. package/dist/streamed-load.js.map +1 -1
  108. package/dist/testing.d.ts +15 -14
  109. package/dist/testing.js +27 -7
  110. package/dist/testing.js.map +1 -1
  111. package/dist/transport.d.ts +6 -7
  112. package/dist/transport.js +3 -6
  113. package/dist/transport.js.map +1 -1
  114. package/dist/universal.d.ts +3 -3
  115. package/dist/universal.js +1 -1
  116. package/dist/universal.js.map +1 -1
  117. package/dist/vite.d.ts +4 -4
  118. package/dist/vite.js +102 -103
  119. package/dist/vite.js.map +1 -1
  120. package/package.json +14 -11
  121. package/LICENSE +0 -21
@@ -1,6 +1,7 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { onNavigateWith, registeredStream } from "./internal/navigation-events.js";
3
- import { Effect } from "effect";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
4
5
  import { afterNavigate, beforeNavigate, goto, invalidate, invalidateAll, onNavigate, preloadCode, preloadData, refreshAll } from "$app/navigation";
5
6
  //#region src/Navigation.ts
6
7
  /**
@@ -11,8 +12,12 @@ import { afterNavigate, beforeNavigate, goto, invalidate, invalidateAll, onNavig
11
12
  * `Effect`, so navigation composes inside Effect pipelines (sequencing,
12
13
  * retries, `Effect.race`, tracing spans, ...). Alongside them sit the
13
14
  * client-side lifecycle callbacks (`beforeNavigate`, `afterNavigate`,
14
- * `onNavigate`) bridged to Effect. These run on the client only — calling them
15
- * during SSR throws, exactly as the underlying `$app/navigation` functions do.
15
+ * `onNavigate`) bridged to Effect. These run on the client only.
16
+ *
17
+ * When SvelteKit rejects (for example, `goto` to a URL outside the app) or
18
+ * throws (for example, any of them run during server rendering), the wrapper
19
+ * fails with a {@link NavigationError} that names the operation and carries
20
+ * SvelteKit's original reason as its `cause`.
16
21
  *
17
22
  * @example
18
23
  * ```svelte
@@ -34,6 +39,7 @@ import { afterNavigate, beforeNavigate, goto, invalidate, invalidateAll, onNavig
34
39
  * ```
35
40
  */
36
41
  var Navigation_exports = /* @__PURE__ */ __exportAll({
42
+ NavigationError: () => NavigationError,
37
43
  afterNavigate: () => afterNavigate$1,
38
44
  beforeNavigate: () => beforeNavigate$1,
39
45
  goto: () => goto$1,
@@ -45,29 +51,97 @@ var Navigation_exports = /* @__PURE__ */ __exportAll({
45
51
  refreshAll: () => refreshAll$1
46
52
  });
47
53
  /**
48
- * Navigate to `url`. Wraps `$app/navigation`'s `goto`. SvelteKit rejects a URL
49
- * outside the app (external, or not matching a route); a rejection surfaces as
50
- * a defect.
54
+ * A `$app/navigation` promise wrapper ({@link goto}, {@link invalidate},
55
+ * {@link invalidateAll}, {@link refreshAll}, {@link preloadData},
56
+ * {@link preloadCode}) rejected or threw. `operation` names the wrapper and
57
+ * `cause` is SvelteKit's original reason, unchanged.
58
+ *
59
+ * SvelteKit 3 rejects `goto` with a URL outside the app (external, or matching
60
+ * no route) and `preloadData` with a URL outside the app; `invalidate` throws on
61
+ * a `resource` that cannot be parsed even relative to the current URL;
62
+ * `preloadCode` rejects when a route's code fails to load; a navigation (including one that follows a `load` redirect during
63
+ * `invalidate` / `refreshAll`) rejects when a `beforeNavigate` / `onNavigate`
64
+ * callback throws; and every one of them throws when called during server
65
+ * rendering. Recover with `Effect.catchTag("NavigationError", ...)`.
66
+ */
67
+ var NavigationError = class extends Schema.TaggedError()("NavigationError", {
68
+ /** The wrapper whose SvelteKit call failed. */
69
+ operation: Schema.Literals([
70
+ "goto",
71
+ "invalidate",
72
+ "invalidateAll",
73
+ "refreshAll",
74
+ "preloadData",
75
+ "preloadCode"
76
+ ]),
77
+ /** The rejection reason, or the value thrown, as SvelteKit produced it. */
78
+ cause: Schema.Defect()
79
+ }) {};
80
+ /**
81
+ * Runs a `$app/navigation` call as an Effect, so a rejection, or a synchronous
82
+ * throw, fails with a {@link NavigationError} instead of becoming a defect.
83
+ */
84
+ const fromNavigation = (operation, thunk) => Effect.tryPromise({
85
+ try: () => thunk(),
86
+ catch: (cause) => new NavigationError({
87
+ operation,
88
+ cause
89
+ })
90
+ });
91
+ /**
92
+ * Navigate to `url`. Wraps `$app/navigation`'s `goto`.
93
+ *
94
+ * Fails with a {@link NavigationError} if SvelteKit rejects: a URL outside the
95
+ * app (external, or not matching a route) rejects, as does a navigation whose
96
+ * `beforeNavigate` / `onNavigate` callback throws, or a call during server
97
+ * rendering. For an external URL, set `window.location` instead.
51
98
  */
52
- const goto$1 = (...args) => Effect.promise(() => goto(...args));
53
- /** Re-run `load` functions that depend on `resource`. Wraps `invalidate`. */
54
- const invalidate$1 = (...args) => Effect.promise(() => invalidate(...args));
99
+ const goto$1 = (...args) => fromNavigation("goto", () => goto(...args));
100
+ /**
101
+ * Re-run `load` functions that depend on `resource`. Wraps `invalidate`.
102
+ *
103
+ * Fails with a {@link NavigationError} if SvelteKit rejects or throws: a
104
+ * `resource` string that cannot be parsed even relative to the current URL
105
+ * throws, as does a call during server rendering, and the navigation that
106
+ * follows a `load` redirect can reject.
107
+ */
108
+ const invalidate$1 = (...args) => fromNavigation("invalidate", () => invalidate(...args));
55
109
  /**
56
110
  * Re-run every `load` function for the active page. Wraps `invalidateAll`.
57
111
  *
112
+ * Fails with a {@link NavigationError} if SvelteKit rejects or throws: for
113
+ * example, when the navigation that follows a `load` redirect fails, or when
114
+ * called during server rendering.
115
+ *
58
116
  * @deprecated SvelteKit 3 deprecates `invalidateAll`; use {@link refreshAll},
59
117
  * which also refreshes active remote functions and keeps `page.state`.
60
118
  */
61
- const invalidateAll$1 = () => Effect.promise(() => invalidateAll());
62
- /** Refresh active remote functions (and, by default, `load`s). Wraps `refreshAll`. */
63
- const refreshAll$1 = (...args) => Effect.promise(() => refreshAll(...args));
64
- /** Preload the data for `href`. Wraps `preloadData`. */
65
- const preloadData$1 = (href) => Effect.promise(() => preloadData(href));
119
+ const invalidateAll$1 = () => fromNavigation("invalidateAll", () => invalidateAll());
120
+ /**
121
+ * Refresh active remote functions (and, by default, `load`s). Wraps `refreshAll`.
122
+ *
123
+ * Fails with a {@link NavigationError} if SvelteKit rejects or throws: for
124
+ * example, when the navigation that follows a `load` redirect fails, or when
125
+ * called during server rendering.
126
+ */
127
+ const refreshAll$1 = (...args) => fromNavigation("refreshAll", () => refreshAll(...args));
128
+ /**
129
+ * Preload the data for `href`. Wraps `preloadData`, succeeding with SvelteKit's
130
+ * result (`loaded`, `redirect`, or `error` when a `load` fails).
131
+ *
132
+ * Fails with a {@link NavigationError} if SvelteKit rejects: an `href` outside
133
+ * the app rejects, as does a call during server rendering.
134
+ */
135
+ const preloadData$1 = (href) => fromNavigation("preloadData", () => preloadData(href));
66
136
  /**
67
137
  * Preload the code for the route `id` (e.g. `/blog/[slug]`, without
68
138
  * `paths.base`). Wraps `preloadCode`.
139
+ *
140
+ * Fails with a {@link NavigationError} if SvelteKit rejects: a route module
141
+ * that fails to load rejects, as does a call during server rendering (and, in
142
+ * development, an `id` not starting with `/`).
69
143
  */
70
- const preloadCode$1 = (...args) => Effect.promise(() => preloadCode(...args));
144
+ const preloadCode$1 = (...args) => fromNavigation("preloadCode", () => preloadCode(...args));
71
145
  /**
72
146
  * Registers a `beforeNavigate` callback and exposes every navigation about to
73
147
  * happen as an Effect `Stream`. Call during component initialization.
@@ -75,9 +149,9 @@ const preloadCode$1 = (...args) => Effect.promise(() => preloadCode(...args));
75
149
  * Unlike the promise-returning navigation functions above, this is a
76
150
  * **callback-registration** function: it must be called *synchronously during
77
151
  * component initialization* (SvelteKit wires it to the component's lifecycle).
78
- * It registers its callback eagerly and feeds an internal `Queue`, returning a
79
- * `Stream` backed by that queue — the same push-based bridge as `SignalEmitter`
80
- * in `@thomasfosterau/effect-svelte`. Call it at the top level of `<script>`,
152
+ * It registers its callback eagerly and feeds an internal unbounded `Queue`,
153
+ * returning a `Stream` backed by that queue: a push-based bridge that buffers
154
+ * every event for its single consumer. Call it at the top level of `<script>`,
81
155
  * exactly where you'd call the bare `beforeNavigate`.
82
156
  *
83
157
  * @example
@@ -162,6 +236,6 @@ function onNavigate$1(fn, runEffect = Effect.runPromise) {
162
236
  onNavigateWith(onNavigate, fn, runEffect);
163
237
  }
164
238
  //#endregion
165
- export { Navigation_exports, afterNavigate$1 as afterNavigate, beforeNavigate$1 as beforeNavigate, goto$1 as goto, invalidate$1 as invalidate, invalidateAll$1 as invalidateAll, onNavigate$1 as onNavigate, preloadCode$1 as preloadCode, preloadData$1 as preloadData, refreshAll$1 as refreshAll };
239
+ export { NavigationError, Navigation_exports, afterNavigate$1 as afterNavigate, beforeNavigate$1 as beforeNavigate, goto$1 as goto, invalidate$1 as invalidate, invalidateAll$1 as invalidateAll, onNavigate$1 as onNavigate, preloadCode$1 as preloadCode, preloadData$1 as preloadData, refreshAll$1 as refreshAll };
166
240
 
167
241
  //# sourceMappingURL=Navigation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Navigation.js","names":["goto","kitGoto","invalidate","kitInvalidate","invalidateAll","kitInvalidateAll","refreshAll","kitRefreshAll","preloadData","kitPreloadData","preloadCode","kitPreloadCode","beforeNavigate","kitBeforeNavigate","afterNavigate","kitAfterNavigate","onNavigate","kitOnNavigate"],"sources":["../src/Navigation.ts"],"sourcesContent":["/**\n * Effect wrappers for SvelteKit's client-side\n * [`$app/navigation`](https://svelte.dev/docs/kit/$app-navigation) API.\n *\n * Each of SvelteKit's promise-returning navigation functions is wrapped as an\n * `Effect`, so navigation composes inside Effect pipelines (sequencing,\n * retries, `Effect.race`, tracing spans, ...). Alongside them sit the\n * client-side lifecycle callbacks (`beforeNavigate`, `afterNavigate`,\n * `onNavigate`) bridged to Effect. These run on the client only — calling them\n * during SSR throws, exactly as the underlying `$app/navigation` functions do.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * const runtime = getRuntime();\n * const save = () =>\n * runtime.runPromise(\n * Effect.gen(function* () {\n * yield* doSave();\n * yield* Navigation.refreshAll();\n * yield* Navigation.goto('/done');\n * }),\n * );\n * </script>\n * ```\n */\n\nimport {\n afterNavigate as kitAfterNavigate,\n beforeNavigate as kitBeforeNavigate,\n goto as kitGoto,\n invalidate as kitInvalidate,\n invalidateAll as kitInvalidateAll,\n onNavigate as kitOnNavigate,\n preloadCode as kitPreloadCode,\n preloadData as kitPreloadData,\n refreshAll as kitRefreshAll,\n} from \"$app/navigation\";\nimport type { AfterNavigate, BeforeNavigate, OnNavigate } from \"$app/navigation\";\nimport { Effect } from \"effect\";\nimport type { Stream } from \"effect\";\nimport { onNavigateWith, registeredStream } from \"./internal/navigation-events.js\";\n\n/**\n * Navigate to `url`. Wraps `$app/navigation`'s `goto`. SvelteKit rejects a URL\n * outside the app (external, or not matching a route); a rejection surfaces as\n * a defect.\n */\nexport const goto = (...args: Parameters<typeof kitGoto>): Effect.Effect<void> =>\n Effect.promise(() => kitGoto(...args));\n\n/** Re-run `load` functions that depend on `resource`. Wraps `invalidate`. */\nexport const invalidate = (...args: Parameters<typeof kitInvalidate>): Effect.Effect<void> =>\n Effect.promise(() => kitInvalidate(...args));\n\n/**\n * Re-run every `load` function for the active page. Wraps `invalidateAll`.\n *\n * @deprecated SvelteKit 3 deprecates `invalidateAll`; use {@link refreshAll},\n * which also refreshes active remote functions and keeps `page.state`.\n */\nexport const invalidateAll = (): Effect.Effect<void> => Effect.promise(() => kitInvalidateAll());\n\n/** Refresh active remote functions (and, by default, `load`s). Wraps `refreshAll`. */\nexport const refreshAll = (...args: Parameters<typeof kitRefreshAll>): Effect.Effect<void> =>\n Effect.promise(() => kitRefreshAll(...args));\n\n/** Preload the data for `href`. Wraps `preloadData`. */\nexport const preloadData = (\n href: string,\n): Effect.Effect<Awaited<ReturnType<typeof kitPreloadData>>> =>\n Effect.promise(() => kitPreloadData(href));\n\n/**\n * Preload the code for the route `id` (e.g. `/blog/[slug]`, without\n * `paths.base`). Wraps `preloadCode`.\n */\nexport const preloadCode = (...args: Parameters<typeof kitPreloadCode>): Effect.Effect<void> =>\n Effect.promise(() => kitPreloadCode(...args));\n\n/**\n * Registers a `beforeNavigate` callback and exposes every navigation about to\n * happen as an Effect `Stream`. Call during component initialization.\n *\n * Unlike the promise-returning navigation functions above, this is a\n * **callback-registration** function: it must be called *synchronously during\n * component initialization* (SvelteKit wires it to the component's lifecycle).\n * It registers its callback eagerly and feeds an internal `Queue`, returning a\n * `Stream` backed by that queue — the same push-based bridge as `SignalEmitter`\n * in `@thomasfosterau/effect-svelte`. Call it at the top level of `<script>`,\n * exactly where you'd call the bare `beforeNavigate`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * // Register at init so the callback is wired to the component lifecycle.\n * const navigations = Navigation.beforeNavigate();\n *\n * getRuntime().runFork(\n * Stream.runForEach(navigations, (nav) =>\n * Effect.logInfo(`leaving: ${nav.from?.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\nexport function beforeNavigate(): Stream.Stream<BeforeNavigate> {\n return registeredStream<BeforeNavigate>(kitBeforeNavigate);\n}\n\n/**\n * Registers an `afterNavigate` callback and exposes every completed navigation\n * (including the initial one) as an Effect `Stream`. Call during component\n * initialization.\n *\n * Like {@link beforeNavigate}, this is a **callback-registration** function:\n * call it at the top level of `<script>`, exactly where you'd call the bare\n * `afterNavigate`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * // Register at init so the callback is wired to the component lifecycle.\n * const navigations = Navigation.afterNavigate();\n *\n * getRuntime().runFork(\n * Stream.runForEach(navigations, (nav) =>\n * Effect.logInfo(`navigated: ${nav.to?.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\nexport function afterNavigate(): Stream.Stream<AfterNavigate> {\n return registeredStream<AfterNavigate>(kitAfterNavigate);\n}\n\n/**\n * Runs an `Effect` for each navigation, registered via `$app/navigation`'s\n * `onNavigate`. Call during component initialization.\n *\n * SvelteKit's `onNavigate` callback may return a cleanup function (or a promise\n * of one) that runs once the navigation completes and the DOM has updated; to\n * support that, `fn`'s Effect may succeed with a `() => void` cleanup, which is\n * forwarded to SvelteKit. The Effect is run with `runEffect` (default\n * {@link Effect.runPromise}); pass a managed runtime's `runPromise` to supply\n * services to `fn`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * Navigation.onNavigate((nav) =>\n * Effect.gen(function* () {\n * yield* Effect.logInfo(`navigating to ${nav.to?.url.pathname}`);\n * // Optionally return a cleanup that runs after the navigation:\n * return () => console.log(\"navigation done\");\n * }),\n * );\n * </script>\n * ```\n */\nexport function onNavigate(\n fn: (navigation: OnNavigate) => Effect.Effect<(() => void) | void>,\n runEffect: <X>(effect: Effect.Effect<X>) => Promise<X> = Effect.runPromise,\n): void {\n onNavigateWith<OnNavigate>(kitOnNavigate, fn, runEffect);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAaA,UAAQ,GAAG,SACtB,OAAO,cAAcC,KAAQ,GAAG,IAAI,CAAC;;AAGvC,MAAaC,gBAAc,GAAG,SAC5B,OAAO,cAAcC,WAAc,GAAG,IAAI,CAAC;;;;;;;AAQ7C,MAAaC,wBAA2C,OAAO,cAAcC,cAAiB,CAAC;;AAG/F,MAAaC,gBAAc,GAAG,SAC5B,OAAO,cAAcC,WAAc,GAAG,IAAI,CAAC;;AAG7C,MAAaC,iBACX,SAEA,OAAO,cAAcC,YAAe,IAAI,CAAC;;;;;AAM3C,MAAaC,iBAAe,GAAG,SAC7B,OAAO,cAAcC,YAAe,GAAG,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC9C,SAAgBC,mBAAgD;CAC9D,OAAO,iBAAiCC,cAAiB;AAC3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgBC,kBAA8C;CAC5D,OAAO,iBAAgCC,aAAgB;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgBC,aACd,IACA,YAAyD,OAAO,YAC1D;CACN,eAA2BC,YAAe,IAAI,SAAS;AACzD"}
1
+ {"version":3,"file":"Navigation.js","names":["goto","kitGoto","invalidate","kitInvalidate","invalidateAll","kitInvalidateAll","refreshAll","kitRefreshAll","preloadData","kitPreloadData","preloadCode","kitPreloadCode","beforeNavigate","kitBeforeNavigate","afterNavigate","kitAfterNavigate","onNavigate","kitOnNavigate"],"sources":["../src/Navigation.ts"],"sourcesContent":["/**\n * Effect wrappers for SvelteKit's client-side\n * [`$app/navigation`](https://svelte.dev/docs/kit/$app-navigation) API.\n *\n * Each of SvelteKit's promise-returning navigation functions is wrapped as an\n * `Effect`, so navigation composes inside Effect pipelines (sequencing,\n * retries, `Effect.race`, tracing spans, ...). Alongside them sit the\n * client-side lifecycle callbacks (`beforeNavigate`, `afterNavigate`,\n * `onNavigate`) bridged to Effect. These run on the client only.\n *\n * When SvelteKit rejects (for example, `goto` to a URL outside the app) or\n * throws (for example, any of them run during server rendering), the wrapper\n * fails with a {@link NavigationError} that names the operation and carries\n * SvelteKit's original reason as its `cause`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * const runtime = getRuntime();\n * const save = () =>\n * runtime.runPromise(\n * Effect.gen(function* () {\n * yield* doSave();\n * yield* Navigation.refreshAll();\n * yield* Navigation.goto('/done');\n * }),\n * );\n * </script>\n * ```\n */\n\nimport {\n afterNavigate as kitAfterNavigate,\n beforeNavigate as kitBeforeNavigate,\n goto as kitGoto,\n invalidate as kitInvalidate,\n invalidateAll as kitInvalidateAll,\n onNavigate as kitOnNavigate,\n preloadCode as kitPreloadCode,\n preloadData as kitPreloadData,\n refreshAll as kitRefreshAll,\n} from \"$app/navigation\";\nimport type { AfterNavigate, BeforeNavigate, OnNavigate } from \"$app/navigation\";\nimport * as Schema from \"effect/Schema\";\nimport * as Effect from \"effect/Effect\";\nimport type * as Stream from \"effect/Stream\";\nimport { onNavigateWith, registeredStream } from \"./internal/navigation-events.js\";\n\n/**\n * A `$app/navigation` promise wrapper ({@link goto}, {@link invalidate},\n * {@link invalidateAll}, {@link refreshAll}, {@link preloadData},\n * {@link preloadCode}) rejected or threw. `operation` names the wrapper and\n * `cause` is SvelteKit's original reason, unchanged.\n *\n * SvelteKit 3 rejects `goto` with a URL outside the app (external, or matching\n * no route) and `preloadData` with a URL outside the app; `invalidate` throws on\n * a `resource` that cannot be parsed even relative to the current URL;\n * `preloadCode` rejects when a route's code fails to load; a navigation (including one that follows a `load` redirect during\n * `invalidate` / `refreshAll`) rejects when a `beforeNavigate` / `onNavigate`\n * callback throws; and every one of them throws when called during server\n * rendering. Recover with `Effect.catchTag(\"NavigationError\", ...)`.\n */\nexport class NavigationError extends Schema.TaggedError<NavigationError>()(\"NavigationError\", {\n /** The wrapper whose SvelteKit call failed. */\n operation: Schema.Literals([\n \"goto\",\n \"invalidate\",\n \"invalidateAll\",\n \"refreshAll\",\n \"preloadData\",\n \"preloadCode\",\n ]),\n /** The rejection reason, or the value thrown, as SvelteKit produced it. */\n cause: Schema.Defect(),\n}) {}\n\n/**\n * Runs a `$app/navigation` call as an Effect, so a rejection, or a synchronous\n * throw, fails with a {@link NavigationError} instead of becoming a defect.\n */\nconst fromNavigation = <A>(\n operation: NavigationError[\"operation\"],\n thunk: () => Promise<A>,\n): Effect.Effect<A, NavigationError> =>\n Effect.tryPromise({\n try: () => thunk(),\n catch: (cause) => new NavigationError({ operation, cause }),\n });\n\n/**\n * Navigate to `url`. Wraps `$app/navigation`'s `goto`.\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects: a URL outside the\n * app (external, or not matching a route) rejects, as does a navigation whose\n * `beforeNavigate` / `onNavigate` callback throws, or a call during server\n * rendering. For an external URL, set `window.location` instead.\n */\nexport const goto = (...args: Parameters<typeof kitGoto>): Effect.Effect<void, NavigationError> =>\n fromNavigation(\"goto\", () => kitGoto(...args));\n\n/**\n * Re-run `load` functions that depend on `resource`. Wraps `invalidate`.\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects or throws: a\n * `resource` string that cannot be parsed even relative to the current URL\n * throws, as does a call during server rendering, and the navigation that\n * follows a `load` redirect can reject.\n */\nexport const invalidate = (\n ...args: Parameters<typeof kitInvalidate>\n): Effect.Effect<void, NavigationError> =>\n fromNavigation(\"invalidate\", () => kitInvalidate(...args));\n\n/**\n * Re-run every `load` function for the active page. Wraps `invalidateAll`.\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects or throws: for\n * example, when the navigation that follows a `load` redirect fails, or when\n * called during server rendering.\n *\n * @deprecated SvelteKit 3 deprecates `invalidateAll`; use {@link refreshAll},\n * which also refreshes active remote functions and keeps `page.state`.\n */\nexport const invalidateAll = (): Effect.Effect<void, NavigationError> =>\n fromNavigation(\"invalidateAll\", () => kitInvalidateAll());\n\n/**\n * Refresh active remote functions (and, by default, `load`s). Wraps `refreshAll`.\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects or throws: for\n * example, when the navigation that follows a `load` redirect fails, or when\n * called during server rendering.\n */\nexport const refreshAll = (\n ...args: Parameters<typeof kitRefreshAll>\n): Effect.Effect<void, NavigationError> =>\n fromNavigation(\"refreshAll\", () => kitRefreshAll(...args));\n\n/**\n * Preload the data for `href`. Wraps `preloadData`, succeeding with SvelteKit's\n * result (`loaded`, `redirect`, or `error` when a `load` fails).\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects: an `href` outside\n * the app rejects, as does a call during server rendering.\n */\nexport const preloadData = (\n href: string,\n): Effect.Effect<Awaited<ReturnType<typeof kitPreloadData>>, NavigationError> =>\n fromNavigation(\"preloadData\", () => kitPreloadData(href));\n\n/**\n * Preload the code for the route `id` (e.g. `/blog/[slug]`, without\n * `paths.base`). Wraps `preloadCode`.\n *\n * Fails with a {@link NavigationError} if SvelteKit rejects: a route module\n * that fails to load rejects, as does a call during server rendering (and, in\n * development, an `id` not starting with `/`).\n */\nexport const preloadCode = (\n ...args: Parameters<typeof kitPreloadCode>\n): Effect.Effect<void, NavigationError> =>\n fromNavigation(\"preloadCode\", () => kitPreloadCode(...args));\n\n/**\n * Registers a `beforeNavigate` callback and exposes every navigation about to\n * happen as an Effect `Stream`. Call during component initialization.\n *\n * Unlike the promise-returning navigation functions above, this is a\n * **callback-registration** function: it must be called *synchronously during\n * component initialization* (SvelteKit wires it to the component's lifecycle).\n * It registers its callback eagerly and feeds an internal unbounded `Queue`,\n * returning a `Stream` backed by that queue: a push-based bridge that buffers\n * every event for its single consumer. Call it at the top level of `<script>`,\n * exactly where you'd call the bare `beforeNavigate`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * // Register at init so the callback is wired to the component lifecycle.\n * const navigations = Navigation.beforeNavigate();\n *\n * getRuntime().runFork(\n * Stream.runForEach(navigations, (nav) =>\n * Effect.logInfo(`leaving: ${nav.from?.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\nexport function beforeNavigate(): Stream.Stream<BeforeNavigate> {\n return registeredStream<BeforeNavigate>(kitBeforeNavigate);\n}\n\n/**\n * Registers an `afterNavigate` callback and exposes every completed navigation\n * (including the initial one) as an Effect `Stream`. Call during component\n * initialization.\n *\n * Like {@link beforeNavigate}, this is a **callback-registration** function:\n * call it at the top level of `<script>`, exactly where you'd call the bare\n * `afterNavigate`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * // Register at init so the callback is wired to the component lifecycle.\n * const navigations = Navigation.afterNavigate();\n *\n * getRuntime().runFork(\n * Stream.runForEach(navigations, (nav) =>\n * Effect.logInfo(`navigated: ${nav.to?.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\nexport function afterNavigate(): Stream.Stream<AfterNavigate> {\n return registeredStream<AfterNavigate>(kitAfterNavigate);\n}\n\n/**\n * Runs an `Effect` for each navigation, registered via `$app/navigation`'s\n * `onNavigate`. Call during component initialization.\n *\n * SvelteKit's `onNavigate` callback may return a cleanup function (or a promise\n * of one) that runs once the navigation completes and the DOM has updated; to\n * support that, `fn`'s Effect may succeed with a `() => void` cleanup, which is\n * forwarded to SvelteKit. The Effect is run with `runEffect` (default\n * {@link Effect.runPromise}); pass a managed runtime's `runPromise` to supply\n * services to `fn`.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { Navigation } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * Navigation.onNavigate((nav) =>\n * Effect.gen(function* () {\n * yield* Effect.logInfo(`navigating to ${nav.to?.url.pathname}`);\n * // Optionally return a cleanup that runs after the navigation:\n * return () => console.log(\"navigation done\");\n * }),\n * );\n * </script>\n * ```\n */\nexport function onNavigate(\n fn: (navigation: OnNavigate) => Effect.Effect<(() => void) | void>,\n runEffect: <X>(effect: Effect.Effect<X>) => Promise<X> = Effect.runPromise,\n): void {\n onNavigateWith<OnNavigate>(kitOnNavigate, fn, runEffect);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CAAC,mBAAmB;;CAE5F,WAAW,OAAO,SAAS;EACzB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;;CAED,OAAO,OAAO,OAAO;AACvB,CAAC,CAAC,CAAC,CAAC;;;;;AAMJ,MAAM,kBACJ,WACA,UAEA,OAAO,WAAW;CAChB,WAAW,MAAM;CACjB,QAAQ,UAAU,IAAI,gBAAgB;EAAE;EAAW;CAAM,CAAC;AAC5D,CAAC;;;;;;;;;AAUH,MAAaA,UAAQ,GAAG,SACtB,eAAe,cAAcC,KAAQ,GAAG,IAAI,CAAC;;;;;;;;;AAU/C,MAAaC,gBACX,GAAG,SAEH,eAAe,oBAAoBC,WAAc,GAAG,IAAI,CAAC;;;;;;;;;;;AAY3D,MAAaC,wBACX,eAAe,uBAAuBC,cAAiB,CAAC;;;;;;;;AAS1D,MAAaC,gBACX,GAAG,SAEH,eAAe,oBAAoBC,WAAc,GAAG,IAAI,CAAC;;;;;;;;AAS3D,MAAaC,iBACX,SAEA,eAAe,qBAAqBC,YAAe,IAAI,CAAC;;;;;;;;;AAU1D,MAAaC,iBACX,GAAG,SAEH,eAAe,qBAAqBC,YAAe,GAAG,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC7D,SAAgBC,mBAAgD;CAC9D,OAAO,iBAAiCC,cAAiB;AAC3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgBC,kBAA8C;CAC5D,OAAO,iBAAgCC,aAAgB;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgBC,aACd,IACA,YAAyD,OAAO,YAC1D;CACN,eAA2BC,YAAe,IAAI,SAAS;AACzD"}
package/dist/Remote.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Effect, Stream } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Stream from "effect/Stream";
2
3
  import { RemoteCommand, RemoteLiveQuery, RemotePrerenderFunction, RemoteQuery, RemoteQueryFunction, RemoteQueryOverride } from "$app/server";
3
4
  declare namespace Remote_d_exports {
4
5
  export { RemoteSubmit, callCommand, callCommandWithUpdates, callPrerender, callQuery, liveQueryStream, submitForm, submitFormWithUpdates };
@@ -6,34 +7,42 @@ declare namespace Remote_d_exports {
6
7
  /**
7
8
  * Calls a SvelteKit remote `query` as an Effect that succeeds with its output.
8
9
  *
9
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
10
- * defect, not on the error channel, despite the declared `unknown` error type.
10
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
11
+ * through unchanged. On the client, a server-side `error()` arrives as
12
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
13
+ * failing.
11
14
  */
12
- declare function callQuery<Output>(query: RemoteQueryFunction<void, Output>): Effect.Effect<Output, unknown, never>;
15
+ export declare function callQuery<Output>(query: RemoteQueryFunction<void, Output>): Effect.Effect<Output, unknown, never>;
13
16
  /**
14
17
  * Calls a SvelteKit remote `query` with `input` as an Effect that succeeds
15
18
  * with its output.
16
19
  *
17
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
18
- * defect, not on the error channel, despite the declared `unknown` error type.
20
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
21
+ * through unchanged. On the client, a server-side `error()` arrives as
22
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
23
+ * failing.
19
24
  */
20
- declare function callQuery<Input, Output>(query: RemoteQueryFunction<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
25
+ export declare function callQuery<Input, Output>(query: RemoteQueryFunction<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
21
26
  /**
22
27
  * Calls a SvelteKit remote `command` as an Effect that succeeds with its
23
28
  * output.
24
29
  *
25
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
26
- * defect, not on the error channel, despite the declared `unknown` error type.
30
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
31
+ * through unchanged. On the client, a server-side `error()` arrives as
32
+ * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
33
+ * rejects one with an `Error`.
27
34
  */
28
- declare function callCommand<Output>(command: RemoteCommand<void, Output>): Effect.Effect<Output, unknown, never>;
35
+ export declare function callCommand<Output>(command: RemoteCommand<void, Output>): Effect.Effect<Output, unknown, never>;
29
36
  /**
30
37
  * Calls a SvelteKit remote `command` with `input` as an Effect that succeeds
31
38
  * with its output.
32
39
  *
33
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
34
- * defect, not on the error channel, despite the declared `unknown` error type.
40
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
41
+ * through unchanged. On the client, a server-side `error()` arrives as
42
+ * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
43
+ * rejects one with an `Error`.
35
44
  */
36
- declare function callCommand<Input, Output>(command: RemoteCommand<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
45
+ export declare function callCommand<Input, Output>(command: RemoteCommand<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
37
46
  /**
38
47
  * Calls a remote command and refreshes the given queries in the same round
39
48
  * trip (SvelteKit's single-flight mutations).
@@ -42,49 +51,59 @@ declare function callCommand<Input, Output>(command: RemoteCommand<Input, Output
42
51
  * changes data those queries depend on must list them here (or call
43
52
  * `query.refresh()` afterwards) for their cached values to update.
44
53
  *
45
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
46
- * defect, not on the error channel, despite the declared `unknown` error type.
54
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
55
+ * through unchanged. On the client, a server-side `error()` arrives as
56
+ * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
57
+ * rejects one with an `Error`.
47
58
  */
48
- declare function callCommandWithUpdates<Input, Output>(command: RemoteCommand<Input, Output>, input: Input, ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Effect.Effect<Output, unknown, never>;
59
+ export declare function callCommandWithUpdates<Input, Output>(command: RemoteCommand<Input, Output>, input: Input, ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Effect.Effect<Output, unknown, never>;
49
60
  /**
50
61
  * Calls a SvelteKit remote `prerender` function as an Effect that succeeds
51
62
  * with its output.
52
63
  *
53
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
54
- * defect, not on the error channel, despite the declared `unknown` error type.
64
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
65
+ * through unchanged. On the client, a server-side `error()` arrives as
66
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
67
+ * failing.
55
68
  */
56
- declare function callPrerender<Output>(prerender: RemotePrerenderFunction<void, Output>): Effect.Effect<Output, unknown, never>;
69
+ export declare function callPrerender<Output>(prerender: RemotePrerenderFunction<void, Output>): Effect.Effect<Output, unknown, never>;
57
70
  /**
58
71
  * Calls a SvelteKit remote `prerender` function with `input` as an Effect
59
72
  * that succeeds with its output.
60
73
  *
61
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
62
- * defect, not on the error channel, despite the declared `unknown` error type.
74
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
75
+ * through unchanged. On the client, a server-side `error()` arrives as
76
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
77
+ * failing.
63
78
  */
64
- declare function callPrerender<Input, Output>(prerender: RemotePrerenderFunction<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
79
+ export declare function callPrerender<Input, Output>(prerender: RemotePrerenderFunction<Input, Output>, input: Input): Effect.Effect<Output, unknown, never>;
65
80
  /**
66
- * The shape of an enhanced remote form `submit` function. The promise result
67
- * is left open (SvelteKit returns `Promise<void>` in older versions and
68
- * `Promise<boolean>` in newer ones).
81
+ * The shape of an enhanced remote form `submit` function, as SvelteKit 3's
82
+ * `RemoteForm.submit`: it resolves with whether the submission was valid, and
83
+ * `updates` refreshes queries in the same round trip.
69
84
  */
70
- type RemoteSubmit = () => PromiseLike<unknown> & {
71
- updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<unknown>;
85
+ export type RemoteSubmit = () => PromiseLike<boolean> & {
86
+ updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<boolean>;
72
87
  };
73
88
  /**
74
89
  * Runs an enhanced remote form's `submit()` as an Effect.
75
90
  *
76
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
77
- * defect, not on the error channel, despite the declared `unknown` error type.
91
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
92
+ * through unchanged. On the client, a server-side `error()` arrives as
93
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
94
+ * failing.
78
95
  */
79
- declare function submitForm(submit: () => PromiseLike<unknown>): Effect.Effect<void, unknown, never>;
96
+ export declare function submitForm(submit: () => PromiseLike<boolean>): Effect.Effect<void, unknown, never>;
80
97
  /**
81
98
  * Runs an enhanced remote form's `submit()` and refreshes the given queries in
82
99
  * the same round trip (SvelteKit's single-flight mutations).
83
100
  *
84
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
85
- * defect, not on the error channel, despite the declared `unknown` error type.
101
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
102
+ * through unchanged. On the client, a server-side `error()` arrives as
103
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
104
+ * failing.
86
105
  */
87
- declare function submitFormWithUpdates(submit: RemoteSubmit, ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Effect.Effect<void, unknown, never>;
106
+ export declare function submitFormWithUpdates(submit: RemoteSubmit, ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Effect.Effect<void, unknown, never>;
88
107
  /**
89
108
  * Consumes a SvelteKit live query (`query.live(...)`) as an Effect `Stream`.
90
109
  *
@@ -101,7 +120,7 @@ declare function submitFormWithUpdates(submit: RemoteSubmit, ...queries: Array<R
101
120
  * const feed = useStream(Remote.liveQueryStream(messages()));
102
121
  * ```
103
122
  */
104
- declare function liveQueryStream<Output>(query: RemoteLiveQuery<Output>): Stream.Stream<Output, unknown>;
123
+ export declare function liveQueryStream<Output>(query: RemoteLiveQuery<Output>): Stream.Stream<Output, unknown>;
105
124
  //#endregion
106
- export { RemoteSubmit, Remote_d_exports, callCommand, callCommandWithUpdates, callPrerender, callQuery, liveQueryStream, submitForm, submitFormWithUpdates };
125
+ export { Remote_d_exports };
107
126
  //# sourceMappingURL=Remote.d.ts.map
package/dist/Remote.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
- import { Effect, Stream } from "effect";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Stream from "effect/Stream";
3
4
  //#region src/Remote.ts
4
5
  var Remote_exports = /* @__PURE__ */ __exportAll({
5
6
  callCommand: () => callCommand,
@@ -10,15 +11,20 @@ var Remote_exports = /* @__PURE__ */ __exportAll({
10
11
  submitForm: () => submitForm,
11
12
  submitFormWithUpdates: () => submitFormWithUpdates
12
13
  });
14
+ /**
15
+ * Wraps a remote call so a rejection, or a synchronous throw from `thunk`,
16
+ * fails the Effect with the original reason instead of becoming a defect.
17
+ */
13
18
  function fromRemotePromise(thunk) {
14
- return Effect.promise(() => Promise.resolve(thunk()));
19
+ return Effect.tryPromise({
20
+ try: () => Promise.resolve(thunk()),
21
+ catch: (error) => error
22
+ });
15
23
  }
16
24
  function callQuery(query, input) {
17
- if (arguments.length === 1) return fromRemotePromise(() => query(void 0));
18
25
  return fromRemotePromise(() => query(input));
19
26
  }
20
27
  function callCommand(command, input) {
21
- if (arguments.length === 1) return fromRemotePromise(() => command(void 0));
22
28
  return fromRemotePromise(() => command(input));
23
29
  }
24
30
  /**
@@ -29,21 +35,24 @@ function callCommand(command, input) {
29
35
  * changes data those queries depend on must list them here (or call
30
36
  * `query.refresh()` afterwards) for their cached values to update.
31
37
  *
32
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
33
- * defect, not on the error channel, despite the declared `unknown` error type.
38
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
39
+ * through unchanged. On the client, a server-side `error()` arrives as
40
+ * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
41
+ * rejects one with an `Error`.
34
42
  */
35
43
  function callCommandWithUpdates(command, input, ...queries) {
36
44
  return fromRemotePromise(() => command(input).updates(...queries));
37
45
  }
38
46
  function callPrerender(prerender, input) {
39
- if (arguments.length === 1) return fromRemotePromise(() => prerender(void 0));
40
47
  return fromRemotePromise(() => prerender(input));
41
48
  }
42
49
  /**
43
50
  * Runs an enhanced remote form's `submit()` as an Effect.
44
51
  *
45
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
46
- * defect, not on the error channel, despite the declared `unknown` error type.
52
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
53
+ * through unchanged. On the client, a server-side `error()` arrives as
54
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
55
+ * failing.
47
56
  */
48
57
  function submitForm(submit) {
49
58
  return Effect.asVoid(fromRemotePromise(() => submit()));
@@ -52,8 +61,10 @@ function submitForm(submit) {
52
61
  * Runs an enhanced remote form's `submit()` and refreshes the given queries in
53
62
  * the same round trip (SvelteKit's single-flight mutations).
54
63
  *
55
- * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a
56
- * defect, not on the error channel, despite the declared `unknown` error type.
64
+ * Fails with the remote call's rejection reason, typed `unknown` and passed
65
+ * through unchanged. On the client, a server-side `error()` arrives as
66
+ * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
67
+ * failing.
57
68
  */
58
69
  function submitFormWithUpdates(submit, ...queries) {
59
70
  return Effect.asVoid(fromRemotePromise(() => submit().updates(...queries)));
@@ -1 +1 @@
1
- {"version":3,"file":"Remote.js","names":[],"sources":["../src/Remote.ts"],"sourcesContent":["import type {\n RemoteCommand,\n RemoteLiveQuery,\n RemotePrerenderFunction,\n RemoteQuery,\n RemoteQueryFunction,\n RemoteQueryOverride,\n} from \"$app/server\";\nimport { Effect, Stream } from \"effect\";\n\nfunction fromRemotePromise<A>(thunk: () => PromiseLike<A>): Effect.Effect<A, unknown, never> {\n return Effect.promise(() => Promise.resolve(thunk()));\n}\n\n/**\n * Calls a SvelteKit remote `query` as an Effect that succeeds with its output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callQuery<Output>(\n query: RemoteQueryFunction<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `query` with `input` as an Effect that succeeds\n * with its output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callQuery<Input, Output>(\n query: RemoteQueryFunction<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callQuery<Input, Output>(\n query: RemoteQueryFunction<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n if (arguments.length === 1) {\n return fromRemotePromise(() =>\n (query as unknown as RemoteQueryFunction<void, Output>)(undefined),\n );\n }\n\n return fromRemotePromise(() => query(input as Input));\n}\n\n/**\n * Calls a SvelteKit remote `command` as an Effect that succeeds with its\n * output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callCommand<Output>(\n command: RemoteCommand<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `command` with `input` as an Effect that succeeds\n * with its output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callCommand<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callCommand<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n if (arguments.length === 1) {\n return fromRemotePromise(() => (command as unknown as RemoteCommand<void, Output>)(undefined));\n }\n\n return fromRemotePromise(() => command(input as Input));\n}\n\n/**\n * Calls a remote command and refreshes the given queries in the same round\n * trip (SvelteKit's single-flight mutations).\n *\n * Newer SvelteKit versions cache remote query instances, so a command that\n * changes data those queries depend on must list them here (or call\n * `query.refresh()` afterwards) for their cached values to update.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callCommandWithUpdates<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input: Input,\n ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>\n): Effect.Effect<Output, unknown, never> {\n return fromRemotePromise(() => command(input).updates(...queries));\n}\n\n/**\n * Calls a SvelteKit remote `prerender` function as an Effect that succeeds\n * with its output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callPrerender<Output>(\n prerender: RemotePrerenderFunction<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `prerender` function with `input` as an Effect\n * that succeeds with its output.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function callPrerender<Input, Output>(\n prerender: RemotePrerenderFunction<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callPrerender<Input, Output>(\n prerender: RemotePrerenderFunction<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n if (arguments.length === 1) {\n return fromRemotePromise(() =>\n (prerender as unknown as RemotePrerenderFunction<void, Output>)(undefined),\n );\n }\n\n return fromRemotePromise(() => prerender(input as Input));\n}\n\n/**\n * The shape of an enhanced remote form `submit` function. The promise result\n * is left open (SvelteKit returns `Promise<void>` in older versions and\n * `Promise<boolean>` in newer ones).\n */\nexport type RemoteSubmit = () => PromiseLike<unknown> & {\n updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<unknown>;\n};\n\n/**\n * Runs an enhanced remote form's `submit()` as an Effect.\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function submitForm(\n submit: () => PromiseLike<unknown>,\n): Effect.Effect<void, unknown, never> {\n return Effect.asVoid(fromRemotePromise(() => submit()));\n}\n\n/**\n * Runs an enhanced remote form's `submit()` and refreshes the given queries in\n * the same round trip (SvelteKit's single-flight mutations).\n *\n * A rejected call (including a thrown `error()` / `redirect()`) surfaces as a\n * defect, not on the error channel, despite the declared `unknown` error type.\n */\nexport function submitFormWithUpdates(\n submit: RemoteSubmit,\n ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>\n): Effect.Effect<void, unknown, never> {\n return Effect.asVoid(fromRemotePromise(() => submit().updates(...queries)));\n}\n\n/**\n * Consumes a SvelteKit live query (`query.live(...)`) as an Effect `Stream`.\n *\n * A `RemoteLiveQuery<T>` is an `AsyncIterable<T>` that yields every update\n * pushed from the server; this turns it into a `Stream` so live data can drive\n * Effect pipelines (and, via `useStream`, Svelte runes).\n *\n * @example\n * ```ts\n * import { Remote } from '@thomasfosterau/effect-sveltekit';\n * import { messages } from './chat.remote';\n * import { useStream } from '@thomasfosterau/effect-svelte';\n *\n * const feed = useStream(Remote.liveQueryStream(messages()));\n * ```\n */\nexport function liveQueryStream<Output>(\n query: RemoteLiveQuery<Output>,\n): Stream.Stream<Output, unknown> {\n return Stream.fromAsyncIterable(query, (error) => error);\n}\n"],"mappings":";;;;;;;;;;;;AAUA,SAAS,kBAAqB,OAA+D;CAC3F,OAAO,OAAO,cAAc,QAAQ,QAAQ,MAAM,CAAC,CAAC;AACtD;AAsBA,SAAgB,UACd,OACA,OACuC;CACvC,IAAI,UAAU,WAAW,GACvB,OAAO,wBACJ,MAAuD,KAAA,CAAS,CACnE;CAGF,OAAO,wBAAwB,MAAM,KAAc,CAAC;AACtD;AAuBA,SAAgB,YACd,SACA,OACuC;CACvC,IAAI,UAAU,WAAW,GACvB,OAAO,wBAAyB,QAAmD,KAAA,CAAS,CAAC;CAG/F,OAAO,wBAAwB,QAAQ,KAAc,CAAC;AACxD;;;;;;;;;;;;AAaA,SAAgB,uBACd,SACA,OACA,GAAG,SACoC;CACvC,OAAO,wBAAwB,QAAQ,KAAK,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC;AACnE;AAuBA,SAAgB,cACd,WACA,OACuC;CACvC,IAAI,UAAU,WAAW,GACvB,OAAO,wBACJ,UAA+D,KAAA,CAAS,CAC3E;CAGF,OAAO,wBAAwB,UAAU,KAAc,CAAC;AAC1D;;;;;;;AAiBA,SAAgB,WACd,QACqC;CACrC,OAAO,OAAO,OAAO,wBAAwB,OAAO,CAAC,CAAC;AACxD;;;;;;;;AASA,SAAgB,sBACd,QACA,GAAG,SACkC;CACrC,OAAO,OAAO,OAAO,wBAAwB,OAAO,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC;AAC5E;;;;;;;;;;;;;;;;;AAkBA,SAAgB,gBACd,OACgC;CAChC,OAAO,OAAO,kBAAkB,QAAQ,UAAU,KAAK;AACzD"}
1
+ {"version":3,"file":"Remote.js","names":[],"sources":["../src/Remote.ts"],"sourcesContent":["import type {\n RemoteCommand,\n RemoteLiveQuery,\n RemotePrerenderFunction,\n RemoteQuery,\n RemoteQueryFunction,\n RemoteQueryOverride,\n} from \"$app/server\";\nimport * as Effect from \"effect/Effect\";\nimport * as Stream from \"effect/Stream\";\n\n/**\n * Wraps a remote call so a rejection, or a synchronous throw from `thunk`,\n * fails the Effect with the original reason instead of becoming a defect.\n */\nfunction fromRemotePromise<A>(thunk: () => PromiseLike<A>): Effect.Effect<A, unknown, never> {\n return Effect.tryPromise({\n try: () => Promise.resolve(thunk()),\n catch: (error) => error,\n });\n}\n\n/**\n * Calls a SvelteKit remote `query` as an Effect that succeeds with its output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function callQuery<Output>(\n query: RemoteQueryFunction<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `query` with `input` as an Effect that succeeds\n * with its output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function callQuery<Input, Output>(\n query: RemoteQueryFunction<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callQuery<Input, Output>(\n query: RemoteQueryFunction<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n // SAFETY: `input` is only absent in the no-input overload, which fixes\n // `Input` to `void`, so `query(undefined)` is the call that overload means.\n return fromRemotePromise(() => query(input as Input));\n}\n\n/**\n * Calls a SvelteKit remote `command` as an Effect that succeeds with its\n * output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit\n * rejects one with an `Error`.\n */\nexport function callCommand<Output>(\n command: RemoteCommand<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `command` with `input` as an Effect that succeeds\n * with its output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit\n * rejects one with an `Error`.\n */\nexport function callCommand<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callCommand<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n // SAFETY: `input` is only absent in the no-input overload, which fixes\n // `Input` to `void`, so `command(undefined)` is the call that overload means.\n return fromRemotePromise(() => command(input as Input));\n}\n\n/**\n * Calls a remote command and refreshes the given queries in the same round\n * trip (SvelteKit's single-flight mutations).\n *\n * Newer SvelteKit versions cache remote query instances, so a command that\n * changes data those queries depend on must list them here (or call\n * `query.refresh()` afterwards) for their cached values to update.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit\n * rejects one with an `Error`.\n */\nexport function callCommandWithUpdates<Input, Output>(\n command: RemoteCommand<Input, Output>,\n input: Input,\n ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>\n): Effect.Effect<Output, unknown, never> {\n return fromRemotePromise(() => command(input).updates(...queries));\n}\n\n/**\n * Calls a SvelteKit remote `prerender` function as an Effect that succeeds\n * with its output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function callPrerender<Output>(\n prerender: RemotePrerenderFunction<void, Output>,\n): Effect.Effect<Output, unknown, never>;\n/**\n * Calls a SvelteKit remote `prerender` function with `input` as an Effect\n * that succeeds with its output.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function callPrerender<Input, Output>(\n prerender: RemotePrerenderFunction<Input, Output>,\n input: Input,\n): Effect.Effect<Output, unknown, never>;\nexport function callPrerender<Input, Output>(\n prerender: RemotePrerenderFunction<Input, Output>,\n input?: Input,\n): Effect.Effect<Output, unknown, never> {\n // SAFETY: `input` is only absent in the no-input overload, which fixes\n // `Input` to `void`, so `prerender(undefined)` is the call that overload means.\n return fromRemotePromise(() => prerender(input as Input));\n}\n\n/**\n * The shape of an enhanced remote form `submit` function, as SvelteKit 3's\n * `RemoteForm.submit`: it resolves with whether the submission was valid, and\n * `updates` refreshes queries in the same round trip.\n */\nexport type RemoteSubmit = () => PromiseLike<boolean> & {\n updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<boolean>;\n};\n\n/**\n * Runs an enhanced remote form's `submit()` as an Effect.\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function submitForm(\n submit: () => PromiseLike<boolean>,\n): Effect.Effect<void, unknown, never> {\n return Effect.asVoid(fromRemotePromise(() => submit()));\n}\n\n/**\n * Runs an enhanced remote form's `submit()` and refreshes the given queries in\n * the same round trip (SvelteKit's single-flight mutations).\n *\n * Fails with the remote call's rejection reason, typed `unknown` and passed\n * through unchanged. On the client, a server-side `error()` arrives as\n * SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of\n * failing.\n */\nexport function submitFormWithUpdates(\n submit: RemoteSubmit,\n ...queries: Array<RemoteQuery<any> | RemoteQueryOverride>\n): Effect.Effect<void, unknown, never> {\n return Effect.asVoid(fromRemotePromise(() => submit().updates(...queries)));\n}\n\n/**\n * Consumes a SvelteKit live query (`query.live(...)`) as an Effect `Stream`.\n *\n * A `RemoteLiveQuery<T>` is an `AsyncIterable<T>` that yields every update\n * pushed from the server; this turns it into a `Stream` so live data can drive\n * Effect pipelines (and, via `useStream`, Svelte runes).\n *\n * @example\n * ```ts\n * import { Remote } from '@thomasfosterau/effect-sveltekit';\n * import { messages } from './chat.remote';\n * import { useStream } from '@thomasfosterau/effect-svelte';\n *\n * const feed = useStream(Remote.liveQueryStream(messages()));\n * ```\n */\nexport function liveQueryStream<Output>(\n query: RemoteLiveQuery<Output>,\n): Stream.Stream<Output, unknown> {\n return Stream.fromAsyncIterable(query, (error) => error);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,SAAS,kBAAqB,OAA+D;CAC3F,OAAO,OAAO,WAAW;EACvB,WAAW,QAAQ,QAAQ,MAAM,CAAC;EAClC,QAAQ,UAAU;CACpB,CAAC;AACH;AA0BA,SAAgB,UACd,OACA,OACuC;CAGvC,OAAO,wBAAwB,MAAM,KAAc,CAAC;AACtD;AA2BA,SAAgB,YACd,SACA,OACuC;CAGvC,OAAO,wBAAwB,QAAQ,KAAc,CAAC;AACxD;;;;;;;;;;;;;;AAeA,SAAgB,uBACd,SACA,OACA,GAAG,SACoC;CACvC,OAAO,wBAAwB,QAAQ,KAAK,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC;AACnE;AA2BA,SAAgB,cACd,WACA,OACuC;CAGvC,OAAO,wBAAwB,UAAU,KAAc,CAAC;AAC1D;;;;;;;;;AAmBA,SAAgB,WACd,QACqC;CACrC,OAAO,OAAO,OAAO,wBAAwB,OAAO,CAAC,CAAC;AACxD;;;;;;;;;;AAWA,SAAgB,sBACd,QACA,GAAG,SACkC;CACrC,OAAO,OAAO,OAAO,wBAAwB,OAAO,CAAC,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC;AAC5E;;;;;;;;;;;;;;;;;AAkBA,SAAgB,gBACd,OACgC;CAChC,OAAO,OAAO,kBAAkB,QAAQ,UAAU,KAAK;AACzD"}
package/dist/State.d.ts CHANGED
@@ -1,15 +1,88 @@
1
- import { PageSnapshot } from "./internal/app-state.js";
2
- import { Stream } from "effect";
1
+ import { CurrentPageService, NavigatingSnapshot, PageSnapshot, UpdateCheckError } from "./internal/app-state.js";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Context from "effect/Context";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Stream from "effect/Stream";
3
6
  import { Page } from "$app/state";
7
+ import * as Option from "effect/Option";
4
8
  declare namespace State_d_exports {
5
- export { PageSnapshot, page$1 as page };
9
+ export { CurrentPage, CurrentPageInterface, NavigatingSnapshot, PageSnapshot, UpdateCheckError, checkForUpdate, navigating$1 as navigating, page$1 as page, updated$1 as updated };
6
10
  }
7
11
  /**
8
12
  * A `Stream` of the current SvelteKit `page`, emitting a shallow snapshot
9
- * immediately and again after every navigation. Call during component
10
- * initialization.
13
+ * immediately and again after every navigation; never fails. Call during
14
+ * component initialization. It follows `afterNavigate`, so page changes
15
+ * without a navigation (shallow routing, form results) don't emit — use
16
+ * {@link CurrentPage}'s `changes` for those.
11
17
  */
12
18
  declare function page$1(): Stream.Stream<PageSnapshot<Page>>;
19
+ /**
20
+ * A `Stream` of SvelteKit's in-flight navigation: `Option.some` with a
21
+ * {@link NavigatingSnapshot} while a navigation is in progress, `Option.none()`
22
+ * when idle. Emits the current state on the next Svelte flush, then on every
23
+ * change; never fails. Client-only, but callable anywhere (not only during
24
+ * component initialization).
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const spinner = Stream.runForEach(State.navigating(), (nav) =>
29
+ * Effect.sync(() => (busy = Option.isSome(nav))),
30
+ * );
31
+ * ```
32
+ */
33
+ declare function navigating$1(): Stream.Stream<Option.Option<NavigatingSnapshot>>;
34
+ /**
35
+ * A `Stream` of SvelteKit's `updated.current`: whether a new version of the app
36
+ * has been deployed since this one loaded. Emits the current value on the next
37
+ * Svelte flush, then on every change (SvelteKit only ever flips it from `false`
38
+ * to `true`); never fails. Client-only, but callable anywhere.
39
+ */
40
+ declare function updated$1(): Stream.Stream<boolean>;
41
+ /**
42
+ * Asks SvelteKit to check for a new app version now (`updated.check()`),
43
+ * succeeding with whether one is available; a positive result also flips
44
+ * {@link updated}. Always succeeds with `false` in development. Fails with
45
+ * {@link UpdateCheckError} if the check rejects. Client-only.
46
+ */
47
+ export declare function checkForUpdate(): Effect.Effect<boolean, UpdateCheckError>;
48
+ /**
49
+ * The service shape of {@link CurrentPage}: `get` snapshots the current page
50
+ * and `changes` streams it. Neither fails on the client; see
51
+ * {@link CurrentPage} for the server.
52
+ */
53
+ export interface CurrentPageInterface extends CurrentPageService<Page> {}
54
+ declare const CurrentPage_base: Context.ServiceClass<CurrentPage, "@thomasfosterau/effect-sveltekit/CurrentPage", CurrentPageInterface>;
55
+ /**
56
+ * The current SvelteKit page as an Effect service, so any client Effect can read
57
+ * it with `yield* State.CurrentPage` instead of taking it as an argument.
58
+ * `get` snapshots the page when run; `changes` emits the current page on the
59
+ * next Svelte flush, then a fresh snapshot whenever any field changes
60
+ * (navigations, but also shallow routing and form results). Neither fails on
61
+ * the client; on the server, Kit's `page` throws outside synchronous component
62
+ * rendering (including after an async boundary in an Effect forked during
63
+ * render), so `get` dies with a defect there.
64
+ *
65
+ * Provide {@link CurrentPage.layer} (backed by `$app/state`) in your client
66
+ * runtime, or `Layer.succeed(State.CurrentPage, …)` in tests.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const trackView = Effect.gen(function* () {
71
+ * const page = yield* (yield* State.CurrentPage).get;
72
+ * yield* analytics.view(page.url.pathname);
73
+ * });
74
+ *
75
+ * runtime.runFork(trackView.pipe(Effect.provide(State.CurrentPage.layer)));
76
+ * ```
77
+ */
78
+ export declare class CurrentPage extends CurrentPage_base {
79
+ /**
80
+ * A layer providing {@link CurrentPage} from `$app/state`'s `page`. Builds
81
+ * instantly and never fails; client-only (during server rendering `changes`
82
+ * never emits, so consuming it there hangs).
83
+ */
84
+ static readonly layer: Layer.Layer<CurrentPage>;
85
+ }
13
86
  //#endregion
14
- export { type PageSnapshot, State_d_exports, page$1 as page };
87
+ export { type NavigatingSnapshot, type PageSnapshot, State_d_exports, UpdateCheckError, navigating$1 as navigating, page$1 as page, updated$1 as updated };
15
88
  //# sourceMappingURL=State.d.ts.map