@thomasfosterau/effect-sveltekit 0.6.0 → 0.8.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/README.md +37 -21
- 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 +11 -11
- package/dist/Navigation.js +15 -2
- package/dist/Navigation.js.map +1 -1
- package/dist/Remote.d.ts +18 -17
- package/dist/Remote.js +2 -4
- package/dist/Remote.js.map +1 -1
- package/dist/State.d.ts +10 -6
- package/dist/State.js +2 -1
- 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 +9 -10
- package/dist/forms.js +5 -2
- package/dist/forms.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/internal/app-state.d.ts +16 -14
- package/dist/internal/app-state.js +9 -3
- 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 +20 -18
- package/dist/internal/enhance.js +3 -1
- 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/kit.d.ts +12 -11
- package/dist/kit.js +6 -2
- package/dist/kit.js.map +1 -1
- package/dist/realtime.d.ts +29 -31
- package/dist/realtime.js +23 -4
- 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 +12 -9
package/README.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
Effect integration for SvelteKit: load/action/endpoint wrappers, remote
|
|
4
4
|
functions, an `effectKit()` Vite plugin, and an Effect HTTP deployment adapter.
|
|
5
5
|
|
|
6
|
-
It
|
|
6
|
+
It lists
|
|
7
7
|
[`@thomasfosterau/effect-svelte`](https://www.npmjs.com/package/@thomasfosterau/effect-svelte)
|
|
8
|
-
|
|
8
|
+
as a dependency, so a compatible version is always installed alongside it. To
|
|
9
|
+
import its Svelte runes hooks (`useDerived`, `AsyncResult`, …) in your own
|
|
10
|
+
code, add it to your app's dependencies too: pnpm only lets a package import
|
|
11
|
+
what it lists itself.
|
|
9
12
|
|
|
10
13
|
## Install
|
|
11
14
|
|
|
@@ -42,17 +45,17 @@ optional `effectKit()` Vite plugin lets route files export bare Effects instead.
|
|
|
42
45
|
|
|
43
46
|
## API
|
|
44
47
|
|
|
45
|
-
| Entry point | What it provides
|
|
46
|
-
| ---------------------------------- |
|
|
47
|
-
| `@thomasfosterau/effect-sveltekit` | Universal helpers: `load` / `makeUniversalRuntime`, the `Remote` call namespace
|
|
48
|
-
| `…/server` | Server wrappers (`serverLoad`, `action`, `actions`, `endpoint`), `Hooks`, `Endpoint`, `makeServerRuntime`, the per-request runtime seam (`makeRuntimeAdapter` / `RequestRuntime`), `Errors`, `RemoteFunction`, request decoding (`decodeParams`, `decodeJson`, …) |
|
|
49
|
-
| `…/client` | Browser-only `Navigation`, `State` (incl. the `CurrentPage` service), `Remote`, `Realtime`, `Forms` and `Hooks` namespaces, and `useRemoteQuery`
|
|
50
|
-
| `…/vite` | The `effectKit()` Vite plugin (auto-wraps bare-Effect route exports)
|
|
51
|
-
| `…/adapter` | The Effect HTTP deployment adapter (`effectAdapter`)
|
|
52
|
-
| `…/adapter/handler` | The SvelteKit app as an Effect HTTP app (`makeHandler`, `makeHandlerWith`, `AssetSource`, `toWebHandler`)
|
|
53
|
-
| `…/adapter/serve` | The Node server the adapter's `index.js` runs (`serve`, `layer`)
|
|
54
|
-
| `…/testing` | A fake `RequestEvent` and runners for unit-testing server wrappers and remote functions (`TestRequestEvent`, `runServerLoad`, `runAction`, `runEndpoint`, `runRemote`)
|
|
55
|
-
| `…/internal/auto` | Referenced by `effectKit()`'s generated code; not a public API
|
|
48
|
+
| Entry point | What it provides |
|
|
49
|
+
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
50
|
+
| `@thomasfosterau/effect-sveltekit` | Universal helpers: `load` / `makeUniversalRuntime`, the `Remote` call namespace and `Hooks` (`reroute`, `transport`), each also exported member by member, `ResponseHeaders`, `sveltekitConfig` / `readConfig`, `apiClient` |
|
|
51
|
+
| `…/server` | Server wrappers (`serverLoad`, `action`, `actions`, `endpoint`), `Hooks`, `Endpoint`, `makeServerRuntime`, the per-request runtime seam (`makeRuntimeAdapter` / `RequestRuntime`), `Errors`, `RemoteFunction` / `RemoteFunctionUsageError`, `KitError` / `KitErrorBody`, request decoding (`decodeParams`, `decodeJson`, …) |
|
|
52
|
+
| `…/client` | Browser-only `Navigation`, `State` (incl. the `CurrentPage` service), `Remote`, `Realtime`, `Forms` and `Hooks` namespaces, and `useRemoteQuery` / `RemoteQueryResult` |
|
|
53
|
+
| `…/vite` | The `effectKit()` Vite plugin (auto-wraps bare-Effect route exports) |
|
|
54
|
+
| `…/adapter` | The Effect HTTP deployment adapter (`effectAdapter`) |
|
|
55
|
+
| `…/adapter/handler` | The SvelteKit app as an Effect HTTP app (`makeHandler`, `makeHandlerWith`, `AssetSource`, `toWebHandler`, the `SvelteKitServerError` / `AssetFetchError` defects) |
|
|
56
|
+
| `…/adapter/serve` | The Node server the adapter's `index.js` runs (`serve`, `layer`) |
|
|
57
|
+
| `…/testing` | A fake `RequestEvent` and runners for unit-testing server wrappers and remote functions (`TestRequestEvent`, `runServerLoad`, `runAction`, `runEndpoint`, `runRemote`) |
|
|
58
|
+
| `…/internal/auto` | Referenced by `effectKit()`'s generated code; not a public API |
|
|
56
59
|
|
|
57
60
|
### At a glance
|
|
58
61
|
|
|
@@ -431,14 +434,14 @@ const logPath = Effect.gen(function* () {
|
|
|
431
434
|
Move custom types (`Option`, `DateTime`, branded types, `Schema.Class`
|
|
432
435
|
instances, tagged errors, ...) across the server/client boundary — for `load`
|
|
433
436
|
data and remote functions — by building SvelteKit's universal `transport` hook
|
|
434
|
-
from Effect schemas (
|
|
437
|
+
from Effect schemas (also reachable as `Hooks.transport`):
|
|
435
438
|
|
|
436
439
|
```ts
|
|
437
440
|
// src/hooks.ts
|
|
438
|
-
import {
|
|
441
|
+
import { transport as effectTransport } from "@thomasfosterau/effect-sveltekit";
|
|
439
442
|
import { Schema } from "effect";
|
|
440
443
|
|
|
441
|
-
export const transport =
|
|
444
|
+
export const transport = effectTransport({
|
|
442
445
|
Option: Schema.Option(Schema.Number),
|
|
443
446
|
Date: Schema.Date,
|
|
444
447
|
});
|
|
@@ -465,8 +468,11 @@ declare global {
|
|
|
465
468
|
}
|
|
466
469
|
|
|
467
470
|
// src/hooks.ts
|
|
468
|
-
import {
|
|
469
|
-
|
|
471
|
+
import {
|
|
472
|
+
transport as effectTransport,
|
|
473
|
+
responseHeadersTransporter,
|
|
474
|
+
} from "@thomasfosterau/effect-sveltekit";
|
|
475
|
+
export const transport = effectTransport({ ResponseHeaders: responseHeadersTransporter });
|
|
470
476
|
|
|
471
477
|
// src/hooks.server.ts
|
|
472
478
|
import { ResponseHeaders } from "@thomasfosterau/effect-sveltekit";
|
|
@@ -487,6 +493,14 @@ export const load = ({ locals }) => ({ headers: locals.headers });
|
|
|
487
493
|
handler effects; `ResponseHeaders` is the buffer for everything `setHeaders`
|
|
488
494
|
cannot do.)
|
|
489
495
|
|
|
496
|
+
Import the universal hook helpers by name, as above, rather than through the
|
|
497
|
+
`Hooks` namespace. `src/hooks.ts` runs on every page, and the published build
|
|
498
|
+
turns `Hooks` into a single object: `Hooks.transport` keeps `Hooks.reroute`
|
|
499
|
+
and the default universal runtime (with Effect's `HttpClient`, `Stream` and
|
|
500
|
+
`ManagedRuntime`) in the client bundle, while the named imports keep only the
|
|
501
|
+
transport helpers. The same holds for `Remote`, whose members are also root
|
|
502
|
+
exports (`callQuery`, `callCommand`, …).
|
|
503
|
+
|
|
490
504
|
### `$env` as an Effect `Config` source
|
|
491
505
|
|
|
492
506
|
Back Effect's `Config` with SvelteKit's environment, so app-layer services read
|
|
@@ -505,7 +519,9 @@ export const runtime = makeServerRuntime(Database.layer.pipe(Layer.provide(svelt
|
|
|
505
519
|
### SvelteKit hooks as Effects (`Hooks`)
|
|
506
520
|
|
|
507
521
|
Every SvelteKit hook has an explicit Effect wrapper, grouped into a `Hooks`
|
|
508
|
-
namespace per hook file (mirroring the auto-wrap table above)
|
|
522
|
+
namespace per hook file (mirroring the auto-wrap table above). The universal
|
|
523
|
+
members are also exported by name from the root entry; prefer those in
|
|
524
|
+
`src/hooks.ts` (see the `ResponseHeaders` recipe above for why):
|
|
509
525
|
|
|
510
526
|
| Import path | `Hooks` members | Runs on |
|
|
511
527
|
| ----------------------------------------- | ---------------------------------------------- | ------------------------------------------------ |
|
|
@@ -515,10 +531,10 @@ namespace per hook file (mirroring the auto-wrap table above):
|
|
|
515
531
|
|
|
516
532
|
```ts
|
|
517
533
|
// src/hooks.ts
|
|
518
|
-
import {
|
|
534
|
+
import { reroute as effectReroute } from "@thomasfosterau/effect-sveltekit";
|
|
519
535
|
import { Effect } from "effect";
|
|
520
536
|
|
|
521
|
-
export const reroute =
|
|
537
|
+
export const reroute = effectReroute((event) =>
|
|
522
538
|
Effect.succeed(event.url.pathname === "/old" ? "/new" : undefined),
|
|
523
539
|
);
|
|
524
540
|
```
|
package/dist/Hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarkerTransporterOptions, TransportEntry, markerTransporter, transport, transporter } from "./transport.js";
|
|
2
2
|
import { responseHeadersTransporter } from "./response-headers.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as HttpClient from "effect/http/HttpClient";
|
|
5
5
|
import { Reroute } from "@sveltejs/kit/hooks";
|
|
6
6
|
declare namespace Hooks_d_exports {
|
|
@@ -23,10 +23,10 @@ declare namespace Hooks_d_exports {
|
|
|
23
23
|
* );
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
declare function reroute(fn: (event: {
|
|
26
|
+
export declare function reroute(fn: (event: {
|
|
27
27
|
url: URL;
|
|
28
28
|
fetch: typeof globalThis.fetch;
|
|
29
29
|
}) => Effect.Effect<string | void, unknown, HttpClient.HttpClient>): Reroute;
|
|
30
30
|
//#endregion
|
|
31
|
-
export { Hooks_d_exports, type MarkerTransporterOptions, type TransportEntry, markerTransporter,
|
|
31
|
+
export { Hooks_d_exports, type MarkerTransporterOptions, type TransportEntry, markerTransporter, responseHeadersTransporter, transport, transporter };
|
|
32
32
|
//# sourceMappingURL=Hooks.d.ts.map
|
package/dist/Hooks.js
CHANGED
|
@@ -2,7 +2,7 @@ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
|
2
2
|
import { defaultUniversalRuntime } from "./internal/default-runtime.js";
|
|
3
3
|
import { markerTransporter, transport, transporter } from "./transport.js";
|
|
4
4
|
import { responseHeadersTransporter } from "./response-headers.js";
|
|
5
|
-
import "effect";
|
|
5
|
+
import "effect/Effect";
|
|
6
6
|
//#region src/Hooks.ts
|
|
7
7
|
var Hooks_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
markerTransporter: () => markerTransporter,
|
package/dist/Hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","names":[],"sources":["../src/Hooks.ts"],"sourcesContent":["/**\n * Effect helpers for SvelteKit's universal hooks (`src/hooks.ts`), exposed as\n * the `Hooks` namespace of `@thomasfosterau/effect-sveltekit`.\n *\n * The `reroute` hook is expressed as an Effect (running on the universal\n * runtime, with an `HttpClient` backed by the event's `fetch`), and the\n * universal `transport` hook is built from Effect schemas via {@link transport}\n * / {@link transporter}.\n *\n * @example\n * ```ts\n * // src/hooks.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit';\n * import { Effect, Schema } from 'effect';\n *\n * export const reroute = Hooks.reroute((event) =>\n * Effect.succeed(event.url.pathname === '/old' ? '/new' : undefined),\n * );\n *\n * export const transport = Hooks.transport({\n * Option: Schema.Option(Schema.Number),\n * Date: Schema.Date,\n * });\n * ```\n */\n\nimport type { Reroute } from \"@sveltejs/kit/hooks\";\nimport
|
|
1
|
+
{"version":3,"file":"Hooks.js","names":[],"sources":["../src/Hooks.ts"],"sourcesContent":["/**\n * Effect helpers for SvelteKit's universal hooks (`src/hooks.ts`), exposed as\n * the `Hooks` namespace of `@thomasfosterau/effect-sveltekit`.\n *\n * The `reroute` hook is expressed as an Effect (running on the universal\n * runtime, with an `HttpClient` backed by the event's `fetch`), and the\n * universal `transport` hook is built from Effect schemas via {@link transport}\n * / {@link transporter}.\n *\n * @example\n * ```ts\n * // src/hooks.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit';\n * import { Effect, Schema } from 'effect';\n *\n * export const reroute = Hooks.reroute((event) =>\n * Effect.succeed(event.url.pathname === '/old' ? '/new' : undefined),\n * );\n *\n * export const transport = Hooks.transport({\n * Option: Schema.Option(Schema.Number),\n * Date: Schema.Date,\n * });\n * ```\n */\n\nimport type { Reroute } from \"@sveltejs/kit/hooks\";\nimport * as Effect from \"effect/Effect\";\nimport type * as HttpClient from \"effect/http/HttpClient\";\nimport { defaultUniversalRuntime } from \"./internal/default-runtime.js\";\n\n/**\n * Wraps an Effect-based function as the SvelteKit universal\n * [`reroute`](https://svelte.dev/docs/kit/hooks#Universal-hooks-reroute) hook,\n * which rewrites the URL before routing. The effect runs on both the server and\n * the client and gets an `HttpClient` backed by the event's `fetch`.\n *\n * @example\n * ```ts\n * // src/hooks.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit';\n * import { Effect } from 'effect';\n *\n * export const reroute = Hooks.reroute((event) =>\n * Effect.succeed(event.url.pathname === '/old' ? '/new' : undefined),\n * );\n * ```\n */\nexport function reroute(\n fn: (event: {\n url: URL;\n fetch: typeof globalThis.fetch;\n }) => Effect.Effect<string | void, unknown, HttpClient.HttpClient>,\n): Reroute {\n return (event) => defaultUniversalRuntime().runPromise(event.fetch, fn(event));\n}\n\n/**\n * The universal `transport` hook built from Effect schemas: `transport`\n * assembles a whole `transport` object from a record of entries, `transporter`\n * builds a single round-tripping entry from a `Schema.Codec`, and\n * `markerTransporter` builds a deliberately-lossy entry for a non-POJO wrapper\n * whose contents should not round-trip. See {@link transport} for details.\n */\nexport {\n transport,\n transporter,\n markerTransporter,\n type MarkerTransporterOptions,\n type TransportEntry,\n} from \"./transport.js\";\n\n/**\n * The `transport` entry for the {@link ResponseHeaders} response-headers buffer\n * (`Hooks.transport({ ResponseHeaders: Hooks.responseHeadersTransporter })`).\n */\nexport { responseHeadersTransporter } from \"./response-headers.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,QACd,IAIS;CACT,QAAQ,UAAU,wBAAwB,CAAC,CAAC,WAAW,MAAM,OAAO,GAAG,KAAK,CAAC;AAC/E"}
|
package/dist/Navigation.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
2
4
|
import { AfterNavigate, BeforeNavigate, OnNavigate, goto, invalidate, preloadCode, preloadData, refreshAll } from "$app/navigation";
|
|
3
5
|
declare namespace Navigation_d_exports {
|
|
4
6
|
export { NavigationError, 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 };
|
|
5
7
|
}
|
|
6
|
-
declare const NavigationError_base:
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
declare const NavigationError_base: Schema.Class<NavigationError, Schema.TaggedStruct<"NavigationError", {
|
|
9
|
+
/** The wrapper whose SvelteKit call failed. */
|
|
10
|
+
readonly operation: Schema.Literals<readonly ["goto", "invalidate", "invalidateAll", "refreshAll", "preloadData", "preloadCode"]>;
|
|
11
|
+
/** The rejection reason, or the value thrown, as SvelteKit produced it. */
|
|
12
|
+
readonly cause: Schema.Defect;
|
|
13
|
+
}>, import("effect/Cause").YieldableError>;
|
|
9
14
|
/**
|
|
10
15
|
* A `$app/navigation` promise wrapper ({@link goto}, {@link invalidate},
|
|
11
16
|
* {@link invalidateAll}, {@link refreshAll}, {@link preloadData},
|
|
@@ -20,12 +25,7 @@ declare const NavigationError_base: new <A extends Record<string, any> = {}>(arg
|
|
|
20
25
|
* callback throws; and every one of them throws when called during server
|
|
21
26
|
* rendering. Recover with `Effect.catchTag("NavigationError", ...)`.
|
|
22
27
|
*/
|
|
23
|
-
declare class NavigationError extends NavigationError_base
|
|
24
|
-
/** The wrapper whose SvelteKit call failed. */
|
|
25
|
-
readonly operation: "goto" | "invalidate" | "invalidateAll" | "refreshAll" | "preloadData" | "preloadCode";
|
|
26
|
-
/** The rejection reason, or the value thrown, as SvelteKit produced it. */
|
|
27
|
-
readonly cause: unknown;
|
|
28
|
-
}> {}
|
|
28
|
+
export declare class NavigationError extends NavigationError_base {}
|
|
29
29
|
/**
|
|
30
30
|
* Navigate to `url`. Wraps `$app/navigation`'s `goto`.
|
|
31
31
|
*
|
|
@@ -168,5 +168,5 @@ declare function afterNavigate$1(): Stream.Stream<AfterNavigate>;
|
|
|
168
168
|
*/
|
|
169
169
|
declare function onNavigate$1(fn: (navigation: OnNavigate) => Effect.Effect<(() => void) | void>, runEffect?: <X>(effect: Effect.Effect<X>) => Promise<X>): void;
|
|
170
170
|
//#endregion
|
|
171
|
-
export {
|
|
171
|
+
export { Navigation_d_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 };
|
|
172
172
|
//# sourceMappingURL=Navigation.d.ts.map
|
package/dist/Navigation.js
CHANGED
|
@@ -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
|
|
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
|
/**
|
|
@@ -63,7 +64,19 @@ var Navigation_exports = /* @__PURE__ */ __exportAll({
|
|
|
63
64
|
* callback throws; and every one of them throws when called during server
|
|
64
65
|
* rendering. Recover with `Effect.catchTag("NavigationError", ...)`.
|
|
65
66
|
*/
|
|
66
|
-
var NavigationError = class extends
|
|
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
|
+
}) {};
|
|
67
80
|
/**
|
|
68
81
|
* Runs a `$app/navigation` call as an Effect, so a rejection, or a synchronous
|
|
69
82
|
* throw, fails with a {@link NavigationError} instead of becoming a defect.
|
package/dist/Navigation.js.map
CHANGED
|
@@ -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.\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 { Data, Effect } from \"effect\";\nimport type { Stream } from \"effect\";\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 Data.TaggedError(\"NavigationError\")<{\n /** The wrapper whose SvelteKit call failed. */\n readonly operation:\n | \"goto\"\n | \"invalidate\"\n | \"invalidateAll\"\n | \"refreshAll\"\n | \"preloadData\"\n | \"preloadCode\";\n /** The rejection reason, or the value thrown, as SvelteKit produced it. */\n readonly cause: unknown;\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,kBAAb,cAAqC,KAAK,YAAY,iBAAiB,CAAC,CAWrE,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"}
|
|
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
|
|
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 };
|
|
@@ -11,7 +12,7 @@ declare namespace Remote_d_exports {
|
|
|
11
12
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
12
13
|
* failing.
|
|
13
14
|
*/
|
|
14
|
-
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>;
|
|
15
16
|
/**
|
|
16
17
|
* Calls a SvelteKit remote `query` with `input` as an Effect that succeeds
|
|
17
18
|
* with its output.
|
|
@@ -21,7 +22,7 @@ declare function callQuery<Output>(query: RemoteQueryFunction<void, Output>): Ef
|
|
|
21
22
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
22
23
|
* failing.
|
|
23
24
|
*/
|
|
24
|
-
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>;
|
|
25
26
|
/**
|
|
26
27
|
* Calls a SvelteKit remote `command` as an Effect that succeeds with its
|
|
27
28
|
* output.
|
|
@@ -31,7 +32,7 @@ declare function callQuery<Input, Output>(query: RemoteQueryFunction<Input, Outp
|
|
|
31
32
|
* SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
|
|
32
33
|
* rejects one with an `Error`.
|
|
33
34
|
*/
|
|
34
|
-
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>;
|
|
35
36
|
/**
|
|
36
37
|
* Calls a SvelteKit remote `command` with `input` as an Effect that succeeds
|
|
37
38
|
* with its output.
|
|
@@ -41,7 +42,7 @@ declare function callCommand<Output>(command: RemoteCommand<void, Output>): Effe
|
|
|
41
42
|
* SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
|
|
42
43
|
* rejects one with an `Error`.
|
|
43
44
|
*/
|
|
44
|
-
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>;
|
|
45
46
|
/**
|
|
46
47
|
* Calls a remote command and refreshes the given queries in the same round
|
|
47
48
|
* trip (SvelteKit's single-flight mutations).
|
|
@@ -55,7 +56,7 @@ declare function callCommand<Input, Output>(command: RemoteCommand<Input, Output
|
|
|
55
56
|
* SvelteKit's `HttpError`; commands may not `redirect()`, and SvelteKit
|
|
56
57
|
* rejects one with an `Error`.
|
|
57
58
|
*/
|
|
58
|
-
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>;
|
|
59
60
|
/**
|
|
60
61
|
* Calls a SvelteKit remote `prerender` function as an Effect that succeeds
|
|
61
62
|
* with its output.
|
|
@@ -65,7 +66,7 @@ declare function callCommandWithUpdates<Input, Output>(command: RemoteCommand<In
|
|
|
65
66
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
66
67
|
* failing.
|
|
67
68
|
*/
|
|
68
|
-
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>;
|
|
69
70
|
/**
|
|
70
71
|
* Calls a SvelteKit remote `prerender` function with `input` as an Effect
|
|
71
72
|
* that succeeds with its output.
|
|
@@ -75,14 +76,14 @@ declare function callPrerender<Output>(prerender: RemotePrerenderFunction<void,
|
|
|
75
76
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
76
77
|
* failing.
|
|
77
78
|
*/
|
|
78
|
-
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>;
|
|
79
80
|
/**
|
|
80
|
-
* The shape of an enhanced remote form `submit` function
|
|
81
|
-
*
|
|
82
|
-
* `
|
|
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.
|
|
83
84
|
*/
|
|
84
|
-
type RemoteSubmit = () => PromiseLike<
|
|
85
|
-
updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<
|
|
85
|
+
export type RemoteSubmit = () => PromiseLike<boolean> & {
|
|
86
|
+
updates: (...queries: Array<RemoteQuery<any> | RemoteQueryOverride>) => PromiseLike<boolean>;
|
|
86
87
|
};
|
|
87
88
|
/**
|
|
88
89
|
* Runs an enhanced remote form's `submit()` as an Effect.
|
|
@@ -92,7 +93,7 @@ type RemoteSubmit = () => PromiseLike<unknown> & {
|
|
|
92
93
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
93
94
|
* failing.
|
|
94
95
|
*/
|
|
95
|
-
declare function submitForm(submit: () => PromiseLike<
|
|
96
|
+
export declare function submitForm(submit: () => PromiseLike<boolean>): Effect.Effect<void, unknown, never>;
|
|
96
97
|
/**
|
|
97
98
|
* Runs an enhanced remote form's `submit()` and refreshes the given queries in
|
|
98
99
|
* the same round trip (SvelteKit's single-flight mutations).
|
|
@@ -102,7 +103,7 @@ declare function submitForm(submit: () => PromiseLike<unknown>): Effect.Effect<v
|
|
|
102
103
|
* SvelteKit's `HttpError`; a server-side `redirect()` navigates instead of
|
|
103
104
|
* failing.
|
|
104
105
|
*/
|
|
105
|
-
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>;
|
|
106
107
|
/**
|
|
107
108
|
* Consumes a SvelteKit live query (`query.live(...)`) as an Effect `Stream`.
|
|
108
109
|
*
|
|
@@ -119,7 +120,7 @@ declare function submitFormWithUpdates(submit: RemoteSubmit, ...queries: Array<R
|
|
|
119
120
|
* const feed = useStream(Remote.liveQueryStream(messages()));
|
|
120
121
|
* ```
|
|
121
122
|
*/
|
|
122
|
-
declare function liveQueryStream<Output>(query: RemoteLiveQuery<Output>): Stream.Stream<Output, unknown>;
|
|
123
|
+
export declare function liveQueryStream<Output>(query: RemoteLiveQuery<Output>): Stream.Stream<Output, unknown>;
|
|
123
124
|
//#endregion
|
|
124
|
-
export {
|
|
125
|
+
export { Remote_d_exports };
|
|
125
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
|
|
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,
|
|
@@ -21,11 +22,9 @@ function fromRemotePromise(thunk) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
function callQuery(query, input) {
|
|
24
|
-
if (arguments.length === 1) return fromRemotePromise(() => query(void 0));
|
|
25
25
|
return fromRemotePromise(() => query(input));
|
|
26
26
|
}
|
|
27
27
|
function callCommand(command, input) {
|
|
28
|
-
if (arguments.length === 1) return fromRemotePromise(() => command(void 0));
|
|
29
28
|
return fromRemotePromise(() => command(input));
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
@@ -45,7 +44,6 @@ function callCommandWithUpdates(command, input, ...queries) {
|
|
|
45
44
|
return fromRemotePromise(() => command(input).updates(...queries));
|
|
46
45
|
}
|
|
47
46
|
function callPrerender(prerender, input) {
|
|
48
|
-
if (arguments.length === 1) return fromRemotePromise(() => prerender(void 0));
|
|
49
47
|
return fromRemotePromise(() => prerender(input));
|
|
50
48
|
}
|
|
51
49
|
/**
|
package/dist/Remote.js.map
CHANGED
|
@@ -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
|
|
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,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
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
9
|
export { CurrentPage, CurrentPageInterface, NavigatingSnapshot, PageSnapshot, UpdateCheckError, checkForUpdate, navigating$1 as navigating, page$1 as page, updated$1 as updated };
|
|
6
10
|
}
|
|
@@ -40,13 +44,13 @@ declare function updated$1(): Stream.Stream<boolean>;
|
|
|
40
44
|
* {@link updated}. Always succeeds with `false` in development. Fails with
|
|
41
45
|
* {@link UpdateCheckError} if the check rejects. Client-only.
|
|
42
46
|
*/
|
|
43
|
-
declare function checkForUpdate(): Effect.Effect<boolean, UpdateCheckError>;
|
|
47
|
+
export declare function checkForUpdate(): Effect.Effect<boolean, UpdateCheckError>;
|
|
44
48
|
/**
|
|
45
49
|
* The service shape of {@link CurrentPage}: `get` snapshots the current page
|
|
46
50
|
* and `changes` streams it. Neither fails on the client; see
|
|
47
51
|
* {@link CurrentPage} for the server.
|
|
48
52
|
*/
|
|
49
|
-
interface CurrentPageInterface extends
|
|
53
|
+
export interface CurrentPageInterface extends CurrentPageService<Page> {}
|
|
50
54
|
declare const CurrentPage_base: Context.ServiceClass<CurrentPage, "@thomasfosterau/effect-sveltekit/CurrentPage", CurrentPageInterface>;
|
|
51
55
|
/**
|
|
52
56
|
* The current SvelteKit page as an Effect service, so any client Effect can read
|
|
@@ -71,7 +75,7 @@ declare const CurrentPage_base: Context.ServiceClass<CurrentPage, "@thomasfoster
|
|
|
71
75
|
* runtime.runFork(trackView.pipe(Effect.provide(State.CurrentPage.layer)));
|
|
72
76
|
* ```
|
|
73
77
|
*/
|
|
74
|
-
declare class CurrentPage extends CurrentPage_base {
|
|
78
|
+
export declare class CurrentPage extends CurrentPage_base {
|
|
75
79
|
/**
|
|
76
80
|
* A layer providing {@link CurrentPage} from `$app/state`'s `page`. Builds
|
|
77
81
|
* instantly and never fails; client-only (during server rendering `changes`
|
|
@@ -80,5 +84,5 @@ declare class CurrentPage extends CurrentPage_base {
|
|
|
80
84
|
static readonly layer: Layer.Layer<CurrentPage>;
|
|
81
85
|
}
|
|
82
86
|
//#endregion
|
|
83
|
-
export {
|
|
87
|
+
export { type NavigatingSnapshot, type PageSnapshot, State_d_exports, UpdateCheckError, navigating$1 as navigating, page$1 as page, updated$1 as updated };
|
|
84
88
|
//# sourceMappingURL=State.d.ts.map
|
package/dist/State.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { UpdateCheckError, checkForUpdateWith, makeCurrentPage, pageSnapshotStream, snapshotNavigating, watchedStream } from "./internal/app-state.js";
|
|
3
3
|
import { watch } from "./internal/watch.svelte.js";
|
|
4
|
-
import
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
5
6
|
import { afterNavigate } from "$app/navigation";
|
|
6
7
|
import { navigating, page, updated } from "$app/state";
|
|
7
8
|
//#region src/State.ts
|
package/dist/State.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","names":["page","kitPage","navigating","kitNavigating","updated","kitUpdated"],"sources":["../src/State.ts"],"sourcesContent":["/**\n * An Effect-side bridge for SvelteKit's\n * [`$app/state`](https://svelte.dev/docs/kit/$app-state): `page`, `navigating`\n * and `updated`.\n *\n * `$app/state` exposes rune-reactive objects for use inside components. This\n * module turns them into Effect values so navigation and version state can\n * drive Effect pipelines without touching Svelte runes:\n *\n * - {@link page} — a `Stream` of page snapshots, emitted now and after each\n * navigation (via `afterNavigate`, so call it during component\n * initialization).\n * - {@link navigating} — a `Stream` of the in-flight navigation as an\n * `Option` (`None` when idle).\n * - {@link updated} / {@link checkForUpdate} — whether a new app version has\n * been deployed, as a `Stream<boolean>` and as an on-demand check.\n * - {@link CurrentPage} — a `Context` service exposing the current page to any\n * client Effect; provide {@link CurrentPage.layer} in your client runtime.\n *\n * Each page emission is a *shallow snapshot* (`url`, `params`, `route`, `data`,\n * `status`, `error`, `form`, `state`, `shallow`) rather than the live\n * `$app/state` proxy: the proxy mutates in place on every navigation, so a\n * captured reference is unreliable for downstream consumers — the snapshot\n * gives each emission a stable value. `navigating` emissions are snapshots for\n * the same reason.\n *\n * `navigating`, `updated` and `CurrentPage.changes` watch the rune state with a\n * root `$effect`, so they work anywhere on the client (not only during\n * component initialization). Each stream is cold: a run opens its own watcher,\n * emits the current value on the next Svelte flush and again whenever it\n * changes, and disposes the watcher when the stream ends or is interrupted.\n * All of this is client-only: during server rendering the watched streams\n * never emit, so consuming one there (for example with `Stream.runHead`)\n * hangs rather than failing.\n *\n * These are streams and a service rather than atoms; an atom-based variant\n * may follow once the official `@effect/atom-svelte` integration lands (see\n * issue #23).\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { State } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * const pages = State.page();\n * getRuntime().runFork(\n * Stream.runForEach(pages, (page) =>\n * Effect.logInfo(`page: ${page.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\n\nimport { afterNavigate as kitAfterNavigate } from \"$app/navigation\";\nimport { navigating as kitNavigating, page as kitPage, updated as kitUpdated } from \"$app/state\";\nimport type { Page } from \"$app/state\";\nimport
|
|
1
|
+
{"version":3,"file":"State.js","names":["page","kitPage","navigating","kitNavigating","updated","kitUpdated"],"sources":["../src/State.ts"],"sourcesContent":["/**\n * An Effect-side bridge for SvelteKit's\n * [`$app/state`](https://svelte.dev/docs/kit/$app-state): `page`, `navigating`\n * and `updated`.\n *\n * `$app/state` exposes rune-reactive objects for use inside components. This\n * module turns them into Effect values so navigation and version state can\n * drive Effect pipelines without touching Svelte runes:\n *\n * - {@link page} — a `Stream` of page snapshots, emitted now and after each\n * navigation (via `afterNavigate`, so call it during component\n * initialization).\n * - {@link navigating} — a `Stream` of the in-flight navigation as an\n * `Option` (`None` when idle).\n * - {@link updated} / {@link checkForUpdate} — whether a new app version has\n * been deployed, as a `Stream<boolean>` and as an on-demand check.\n * - {@link CurrentPage} — a `Context` service exposing the current page to any\n * client Effect; provide {@link CurrentPage.layer} in your client runtime.\n *\n * Each page emission is a *shallow snapshot* (`url`, `params`, `route`, `data`,\n * `status`, `error`, `form`, `state`, `shallow`) rather than the live\n * `$app/state` proxy: the proxy mutates in place on every navigation, so a\n * captured reference is unreliable for downstream consumers — the snapshot\n * gives each emission a stable value. `navigating` emissions are snapshots for\n * the same reason.\n *\n * `navigating`, `updated` and `CurrentPage.changes` watch the rune state with a\n * root `$effect`, so they work anywhere on the client (not only during\n * component initialization). Each stream is cold: a run opens its own watcher,\n * emits the current value on the next Svelte flush and again whenever it\n * changes, and disposes the watcher when the stream ends or is interrupted.\n * All of this is client-only: during server rendering the watched streams\n * never emit, so consuming one there (for example with `Stream.runHead`)\n * hangs rather than failing.\n *\n * These are streams and a service rather than atoms; an atom-based variant\n * may follow once the official `@effect/atom-svelte` integration lands (see\n * issue #23).\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { State } from '@thomasfosterau/effect-sveltekit/client';\n * import { Stream, Effect } from 'effect';\n * import { getRuntime } from '@thomasfosterau/effect-svelte';\n *\n * const pages = State.page();\n * getRuntime().runFork(\n * Stream.runForEach(pages, (page) =>\n * Effect.logInfo(`page: ${page.url.pathname}`),\n * ),\n * );\n * </script>\n * ```\n */\n\nimport { afterNavigate as kitAfterNavigate } from \"$app/navigation\";\nimport { navigating as kitNavigating, page as kitPage, updated as kitUpdated } from \"$app/state\";\nimport type { Page } from \"$app/state\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Effect from \"effect/Effect\";\nimport type * as Option from \"effect/Option\";\nimport type * as Stream from \"effect/Stream\";\nimport {\n type CurrentPageService,\n type NavigatingSnapshot,\n type PageSnapshot,\n type UpdateCheckError,\n checkForUpdateWith,\n makeCurrentPage,\n pageSnapshotStream,\n snapshotNavigating,\n watchedStream,\n} from \"./internal/app-state.js\";\nimport { watch } from \"./internal/watch.svelte.js\";\n\n/** A shallow snapshot of SvelteKit's `page` — see {@link page}. */\nexport type { PageSnapshot } from \"./internal/app-state.js\";\n\n/**\n * A snapshot of an in-flight SvelteKit navigation (`type`, `from`, `to`,\n * `willUnload`, `delta`, `complete`) — see {@link navigating}.\n */\nexport type { NavigatingSnapshot } from \"./internal/app-state.js\";\n\n/**\n * The error {@link checkForUpdate} fails with when SvelteKit's\n * `updated.check()` rejects (misuse such as calling it during server\n * rendering; a failed version request resolves `false` instead). The original\n * error is on `cause`.\n */\nexport { UpdateCheckError } from \"./internal/app-state.js\";\n\n/**\n * A `Stream` of the current SvelteKit `page`, emitting a shallow snapshot\n * immediately and again after every navigation; never fails. Call during\n * component initialization. It follows `afterNavigate`, so page changes\n * without a navigation (shallow routing, form results) don't emit — use\n * {@link CurrentPage}'s `changes` for those.\n */\nexport function page(): Stream.Stream<PageSnapshot<Page>> {\n return pageSnapshotStream<Page>(\n (callback) => {\n kitAfterNavigate(() => {\n callback();\n });\n },\n () => kitPage,\n );\n}\n\n/**\n * A `Stream` of SvelteKit's in-flight navigation: `Option.some` with a\n * {@link NavigatingSnapshot} while a navigation is in progress, `Option.none()`\n * when idle. Emits the current state on the next Svelte flush, then on every\n * change; never fails. Client-only, but callable anywhere (not only during\n * component initialization).\n *\n * @example\n * ```ts\n * const spinner = Stream.runForEach(State.navigating(), (nav) =>\n * Effect.sync(() => (busy = Option.isSome(nav))),\n * );\n * ```\n */\nexport function navigating(): Stream.Stream<Option.Option<NavigatingSnapshot>> {\n return watchedStream(watch, () => snapshotNavigating(kitNavigating));\n}\n\n/**\n * A `Stream` of SvelteKit's `updated.current`: whether a new version of the app\n * has been deployed since this one loaded. Emits the current value on the next\n * Svelte flush, then on every change (SvelteKit only ever flips it from `false`\n * to `true`); never fails. Client-only, but callable anywhere.\n */\nexport function updated(): Stream.Stream<boolean> {\n return watchedStream(watch, () => kitUpdated.current);\n}\n\n/**\n * Asks SvelteKit to check for a new app version now (`updated.check()`),\n * succeeding with whether one is available; a positive result also flips\n * {@link updated}. Always succeeds with `false` in development. Fails with\n * {@link UpdateCheckError} if the check rejects. Client-only.\n */\nexport function checkForUpdate(): Effect.Effect<boolean, UpdateCheckError> {\n return checkForUpdateWith(() => kitUpdated.check());\n}\n\n/**\n * The service shape of {@link CurrentPage}: `get` snapshots the current page\n * and `changes` streams it. Neither fails on the client; see\n * {@link CurrentPage} for the server.\n */\nexport interface CurrentPageInterface extends CurrentPageService<Page> {}\n\n/**\n * The current SvelteKit page as an Effect service, so any client Effect can read\n * it with `yield* State.CurrentPage` instead of taking it as an argument.\n * `get` snapshots the page when run; `changes` emits the current page on the\n * next Svelte flush, then a fresh snapshot whenever any field changes\n * (navigations, but also shallow routing and form results). Neither fails on\n * the client; on the server, Kit's `page` throws outside synchronous component\n * rendering (including after an async boundary in an Effect forked during\n * render), so `get` dies with a defect there.\n *\n * Provide {@link CurrentPage.layer} (backed by `$app/state`) in your client\n * runtime, or `Layer.succeed(State.CurrentPage, …)` in tests.\n *\n * @example\n * ```ts\n * const trackView = Effect.gen(function* () {\n * const page = yield* (yield* State.CurrentPage).get;\n * yield* analytics.view(page.url.pathname);\n * });\n *\n * runtime.runFork(trackView.pipe(Effect.provide(State.CurrentPage.layer)));\n * ```\n */\nexport class CurrentPage extends Context.Service<CurrentPage, CurrentPageInterface>()(\n \"@thomasfosterau/effect-sveltekit/CurrentPage\",\n) {\n /**\n * A layer providing {@link CurrentPage} from `$app/state`'s `page`. Builds\n * instantly and never fails; client-only (during server rendering `changes`\n * never emits, so consuming it there hangs).\n */\n static readonly layer: Layer.Layer<CurrentPage> = Layer.succeed(\n CurrentPage,\n makeCurrentPage(() => kitPage, watch),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGA,SAAgBA,SAA0C;CACxD,OAAO,oBACJ,aAAa;EACZ,oBAAuB;GACrB,SAAS;EACX,CAAC;CACH,SACMC,IACR;AACF;;;;;;;;;;;;;;;AAgBA,SAAgBC,eAA+D;CAC7E,OAAO,cAAc,aAAa,mBAAmBC,UAAa,CAAC;AACrE;;;;;;;AAQA,SAAgBC,YAAkC;CAChD,OAAO,cAAc,aAAaC,QAAW,OAAO;AACtD;;;;;;;AAQA,SAAgB,iBAA2D;CACzE,OAAO,yBAAyBA,QAAW,MAAM,CAAC;AACpD;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ,QAA2C,CAAC,CACnF,8CACF,CAAC,CAAC;;;;;;CAMA,OAAgB,QAAkC,MAAM,QACtD,aACA,sBAAsBJ,MAAS,KAAK,CACtC;AACF"}
|