@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.
Files changed (119) hide show
  1. package/README.md +37 -21
  2. package/dist/Hooks.d.ts +3 -3
  3. package/dist/Hooks.js +1 -1
  4. package/dist/Hooks.js.map +1 -1
  5. package/dist/Navigation.d.ts +11 -11
  6. package/dist/Navigation.js +15 -2
  7. package/dist/Navigation.js.map +1 -1
  8. package/dist/Remote.d.ts +18 -17
  9. package/dist/Remote.js +2 -4
  10. package/dist/Remote.js.map +1 -1
  11. package/dist/State.d.ts +10 -6
  12. package/dist/State.js +2 -1
  13. package/dist/State.js.map +1 -1
  14. package/dist/adapter/assets.d.ts +24 -7
  15. package/dist/adapter/assets.js +58 -37
  16. package/dist/adapter/assets.js.map +1 -1
  17. package/dist/adapter/handler.d.ts +27 -12
  18. package/dist/adapter/handler.js +53 -26
  19. package/dist/adapter/handler.js.map +1 -1
  20. package/dist/adapter/index.d.ts +3 -3
  21. package/dist/adapter/index.js +1 -1
  22. package/dist/adapter/index.js.map +1 -1
  23. package/dist/adapter/serve.d.ts +6 -5
  24. package/dist/adapter/serve.js +3 -1
  25. package/dist/adapter/serve.js.map +1 -1
  26. package/dist/api-client.d.ts +3 -4
  27. package/dist/api-client.js +2 -1
  28. package/dist/api-client.js.map +1 -1
  29. package/dist/app-runtime.d.ts +12 -9
  30. package/dist/app-runtime.js +23 -14
  31. package/dist/app-runtime.js.map +1 -1
  32. package/dist/client/Hooks.d.ts +4 -4
  33. package/dist/client/Hooks.js +2 -1
  34. package/dist/client/Hooks.js.map +1 -1
  35. package/dist/client.d.ts +2 -2
  36. package/dist/config.d.ts +7 -5
  37. package/dist/config.js +5 -34
  38. package/dist/config.js.map +1 -1
  39. package/dist/errors.d.ts +14 -16
  40. package/dist/errors.js +20 -12
  41. package/dist/errors.js.map +1 -1
  42. package/dist/forms.d.ts +9 -10
  43. package/dist/forms.js +5 -2
  44. package/dist/forms.js.map +1 -1
  45. package/dist/index.d.ts +5 -4
  46. package/dist/index.js +5 -4
  47. package/dist/internal/app-state.d.ts +16 -14
  48. package/dist/internal/app-state.js +9 -3
  49. package/dist/internal/app-state.js.map +1 -1
  50. package/dist/internal/auto.d.ts +23 -14
  51. package/dist/internal/auto.js +50 -40
  52. package/dist/internal/auto.js.map +1 -1
  53. package/dist/internal/enhance.d.ts +20 -18
  54. package/dist/internal/enhance.js +3 -1
  55. package/dist/internal/enhance.js.map +1 -1
  56. package/dist/internal/error.d.ts +13 -0
  57. package/dist/internal/error.js +4 -3
  58. package/dist/internal/error.js.map +1 -1
  59. package/dist/internal/navigation-events.js +3 -1
  60. package/dist/internal/navigation-events.js.map +1 -1
  61. package/dist/internal/remote-run.d.ts +6 -6
  62. package/dist/internal/remote-run.js +13 -16
  63. package/dist/internal/remote-run.js.map +1 -1
  64. package/dist/internal/remote-validators.js +4 -3
  65. package/dist/internal/remote-validators.js.map +1 -1
  66. package/dist/internal/route-params.d.ts +1 -2
  67. package/dist/internal/sse.js +2 -1
  68. package/dist/internal/sse.js.map +1 -1
  69. package/dist/kit.d.ts +12 -11
  70. package/dist/kit.js +6 -2
  71. package/dist/kit.js.map +1 -1
  72. package/dist/realtime.d.ts +29 -31
  73. package/dist/realtime.js +23 -4
  74. package/dist/realtime.js.map +1 -1
  75. package/dist/remote-functions.d.ts +34 -18
  76. package/dist/remote-functions.js +78 -46
  77. package/dist/remote-functions.js.map +1 -1
  78. package/dist/remote-reactive.d.ts +8 -4
  79. package/dist/remote-reactive.js.map +1 -1
  80. package/dist/request-parse.d.ts +13 -13
  81. package/dist/request-parse.js +29 -15
  82. package/dist/request-parse.js.map +1 -1
  83. package/dist/request-runtime.d.ts +16 -11
  84. package/dist/request-runtime.js +28 -29
  85. package/dist/request-runtime.js.map +1 -1
  86. package/dist/request-services.d.ts +10 -8
  87. package/dist/request-services.js +3 -1
  88. package/dist/request-services.js.map +1 -1
  89. package/dist/response-headers.d.ts +2 -3
  90. package/dist/response-headers.js +2 -1
  91. package/dist/response-headers.js.map +1 -1
  92. package/dist/runtime.d.ts +8 -5
  93. package/dist/runtime.js +4 -1
  94. package/dist/runtime.js.map +1 -1
  95. package/dist/server/Endpoint.d.ts +17 -11
  96. package/dist/server/Endpoint.js +18 -4
  97. package/dist/server/Endpoint.js.map +1 -1
  98. package/dist/server/Hooks.d.ts +6 -6
  99. package/dist/server/Hooks.js +1 -1
  100. package/dist/server/Hooks.js.map +1 -1
  101. package/dist/server.d.ts +8 -7
  102. package/dist/server.js +8 -8
  103. package/dist/server.js.map +1 -1
  104. package/dist/streamed-load.d.ts +2 -3
  105. package/dist/streamed-load.js +1 -1
  106. package/dist/streamed-load.js.map +1 -1
  107. package/dist/testing.d.ts +15 -14
  108. package/dist/testing.js +27 -7
  109. package/dist/testing.js.map +1 -1
  110. package/dist/transport.d.ts +6 -7
  111. package/dist/transport.js +3 -6
  112. package/dist/transport.js.map +1 -1
  113. package/dist/universal.d.ts +3 -3
  114. package/dist/universal.js +1 -1
  115. package/dist/universal.js.map +1 -1
  116. package/dist/vite.d.ts +4 -4
  117. package/dist/vite.js +102 -103
  118. package/dist/vite.js.map +1 -1
  119. package/package.json +12 -9
@@ -1,9 +1,10 @@
1
1
  import { SvelteKitHttpApp } from "./handler.js";
2
- import { Effect, Layer } from "effect";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
3
4
  import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
4
5
  //#region src/adapter/serve.d.ts
5
6
  /** Options for {@link serve} and {@link layer}. */
6
- interface ServeOptions {
7
+ export interface ServeOptions {
7
8
  /** Prefix for the configuration environment variables (PORT, HOST, ...). */
8
9
  readonly envPrefix?: string;
9
10
  /**
@@ -23,7 +24,7 @@ interface ServeOptions {
23
24
  *
24
25
  * Launch it with `Layer.launch`, or merge it into a larger application.
25
26
  */
26
- declare const layer: (handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>, options?: ServeOptions) => Layer.Layer<never, unknown>;
27
+ export declare const layer: (handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>, options?: ServeOptions) => Layer.Layer<never, unknown>;
27
28
  /** The services provided to the handler effect by `NodeHttpServer.layerConfig`. */
28
29
  type NodeHttpServerServices = Layer.Success<ReturnType<typeof NodeHttpServer.layerConfig>>;
29
30
  /**
@@ -40,7 +41,7 @@ type NodeHttpServerServices = Layer.Success<ReturnType<typeof NodeHttpServer.lay
40
41
  * serve(handler);
41
42
  * ```
42
43
  */
43
- declare const serve: (handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>, options?: ServeOptions) => void;
44
+ export declare const serve: (handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>, options?: ServeOptions) => void;
44
45
  //#endregion
45
- export { ServeOptions, layer, serve };
46
+ export {};
46
47
  //# sourceMappingURL=serve.d.ts.map
@@ -1,4 +1,6 @@
1
- import { Config, Effect, Layer } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as Config from "effect/Config";
2
4
  import { createServer } from "node:http";
3
5
  import * as HttpMiddleware from "effect/http/HttpMiddleware";
4
6
  import * as HttpServer from "effect/http/HttpServer";
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","names":[],"sources":["../../src/adapter/serve.ts"],"sourcesContent":["/**\n * Production server entry for the Effect SvelteKit adapter.\n *\n * The adapter's generated `build/index.js` calls {@link serve} with the\n * handler from `build/handler.js`. The server runs on\n * `@effect/platform-node`'s `NodeHttpServer`, with configuration read from\n * the environment and graceful shutdown handled by Effect scopes.\n *\n * For full control (custom layers, tracing, additional routes), skip the\n * generated entry and compose {@link layer} — or the handler itself — into\n * your own Effect application.\n */\n\nimport { createServer } from \"node:http\";\nimport * as HttpMiddleware from \"effect/http/HttpMiddleware\";\nimport * as HttpServer from \"effect/http/HttpServer\";\nimport * as NodeHttpServer from \"@effect/platform-node/NodeHttpServer\";\nimport * as NodeRuntime from \"@effect/platform-node/NodeRuntime\";\nimport { Config, Effect, Layer } from \"effect\";\nimport type { SvelteKitHttpApp } from \"./handler.js\";\n\n/** Options for {@link serve} and {@link layer}. */\nexport interface ServeOptions {\n /** Prefix for the configuration environment variables (PORT, HOST, ...). */\n readonly envPrefix?: string;\n /**\n * Additional layer merged into the server context, e.g. tracing or logging\n * layers.\n */\n readonly layer?: Layer.Layer<never, never>;\n /**\n * Disable the default request logger middleware.\n */\n readonly disableLogger?: boolean;\n}\n\n/**\n * Builds the full server layer for a SvelteKit HttpApp: HTTP listener\n * (`PORT` / `HOST` environment variables), request logging, and the\n * platform services the handler needs.\n *\n * Launch it with `Layer.launch`, or merge it into a larger application.\n */\nexport const layer = (\n handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>,\n options: ServeOptions = {},\n): Layer.Layer<never, unknown> => {\n const prefix = options.envPrefix ?? \"\";\n\n const serveLayer = Layer.unwrap(\n Effect.map(handler, (app) =>\n options.disableLogger ? HttpServer.serve(app) : HttpServer.serve(app, HttpMiddleware.logger),\n ),\n );\n\n const listenLayer = NodeHttpServer.layerConfig(createServer, {\n port: Config.Int(`${prefix}PORT`).pipe(Config.withDefault(3000)),\n host: Config.String(`${prefix}HOST`).pipe(Config.withDefault(\"0.0.0.0\")),\n });\n\n const withListener = serveLayer.pipe(HttpServer.withLogAddress, Layer.provide(listenLayer));\n\n return options.layer ? Layer.merge(withListener, options.layer) : withListener;\n};\n\n/** The services provided to the handler effect by `NodeHttpServer.layerConfig`. */\ntype NodeHttpServerServices = Layer.Success<ReturnType<typeof NodeHttpServer.layerConfig>>;\n\n/**\n * Starts the production server and runs it until the process receives\n * SIGINT/SIGTERM, at which point the server (and every Effect resource) is\n * shut down gracefully.\n *\n * @example\n * ```ts\n * // build/index.js (generated by the adapter)\n * import { handler } from \"./handler.js\";\n * import { serve } from \"@thomasfosterau/effect-sveltekit/adapter/serve\";\n *\n * serve(handler);\n * ```\n */\nexport const serve = (\n handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>,\n options: ServeOptions = {},\n): void => {\n NodeRuntime.runMain(Layer.launch(layer(handler, options)));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,SACX,SACA,UAAwB,CAAC,MACO;CAChC,MAAM,SAAS,QAAQ,aAAa;CAEpC,MAAM,aAAa,MAAM,OACvB,OAAO,IAAI,UAAU,QACnB,QAAQ,gBAAgB,WAAW,MAAM,GAAG,IAAI,WAAW,MAAM,KAAK,eAAe,MAAM,CAC7F,CACF;CAEA,MAAM,cAAc,eAAe,YAAY,cAAc;EAC3D,MAAM,OAAO,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC,KAAK,OAAO,YAAY,GAAI,CAAC;EAC/D,MAAM,OAAO,OAAO,GAAG,OAAO,KAAK,CAAC,CAAC,KAAK,OAAO,YAAY,SAAS,CAAC;CACzE,CAAC;CAED,MAAM,eAAe,WAAW,KAAK,WAAW,gBAAgB,MAAM,QAAQ,WAAW,CAAC;CAE1F,OAAO,QAAQ,QAAQ,MAAM,MAAM,cAAc,QAAQ,KAAK,IAAI;AACpE;;;;;;;;;;;;;;;AAmBA,MAAa,SACX,SACA,UAAwB,CAAC,MAChB;CACT,YAAY,QAAQ,MAAM,OAAO,MAAM,SAAS,OAAO,CAAC,CAAC;AAC3D"}
1
+ {"version":3,"file":"serve.js","names":[],"sources":["../../src/adapter/serve.ts"],"sourcesContent":["/**\n * Production server entry for the Effect SvelteKit adapter.\n *\n * The adapter's generated `build/index.js` calls {@link serve} with the\n * handler from `build/handler.js`. The server runs on\n * `@effect/platform-node`'s `NodeHttpServer`, with configuration read from\n * the environment and graceful shutdown handled by Effect scopes.\n *\n * For full control (custom layers, tracing, additional routes), skip the\n * generated entry and compose {@link layer} — or the handler itself — into\n * your own Effect application.\n */\n\nimport { createServer } from \"node:http\";\nimport * as HttpMiddleware from \"effect/http/HttpMiddleware\";\nimport * as HttpServer from \"effect/http/HttpServer\";\nimport * as NodeHttpServer from \"@effect/platform-node/NodeHttpServer\";\nimport * as NodeRuntime from \"@effect/platform-node/NodeRuntime\";\nimport * as Config from \"effect/Config\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport type { SvelteKitHttpApp } from \"./handler.js\";\n\n/** Options for {@link serve} and {@link layer}. */\nexport interface ServeOptions {\n /** Prefix for the configuration environment variables (PORT, HOST, ...). */\n readonly envPrefix?: string;\n /**\n * Additional layer merged into the server context, e.g. tracing or logging\n * layers.\n */\n readonly layer?: Layer.Layer<never, never>;\n /**\n * Disable the default request logger middleware.\n */\n readonly disableLogger?: boolean;\n}\n\n/**\n * Builds the full server layer for a SvelteKit HttpApp: HTTP listener\n * (`PORT` / `HOST` environment variables), request logging, and the\n * platform services the handler needs.\n *\n * Launch it with `Layer.launch`, or merge it into a larger application.\n */\nexport const layer = (\n handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>,\n options: ServeOptions = {},\n): Layer.Layer<never, unknown> => {\n const prefix = options.envPrefix ?? \"\";\n\n const serveLayer = Layer.unwrap(\n Effect.map(handler, (app) =>\n options.disableLogger ? HttpServer.serve(app) : HttpServer.serve(app, HttpMiddleware.logger),\n ),\n );\n\n const listenLayer = NodeHttpServer.layerConfig(createServer, {\n port: Config.Int(`${prefix}PORT`).pipe(Config.withDefault(3000)),\n host: Config.String(`${prefix}HOST`).pipe(Config.withDefault(\"0.0.0.0\")),\n });\n\n const withListener = serveLayer.pipe(HttpServer.withLogAddress, Layer.provide(listenLayer));\n\n return options.layer ? Layer.merge(withListener, options.layer) : withListener;\n};\n\n/** The services provided to the handler effect by `NodeHttpServer.layerConfig`. */\ntype NodeHttpServerServices = Layer.Success<ReturnType<typeof NodeHttpServer.layerConfig>>;\n\n/**\n * Starts the production server and runs it until the process receives\n * SIGINT/SIGTERM, at which point the server (and every Effect resource) is\n * shut down gracefully.\n *\n * @example\n * ```ts\n * // build/index.js (generated by the adapter)\n * import { handler } from \"./handler.js\";\n * import { serve } from \"@thomasfosterau/effect-sveltekit/adapter/serve\";\n *\n * serve(handler);\n * ```\n */\nexport const serve = (\n handler: Effect.Effect<SvelteKitHttpApp, never, NodeHttpServerServices>,\n options: ServeOptions = {},\n): void => {\n NodeRuntime.runMain(Layer.launch(layer(handler, options)));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,SACX,SACA,UAAwB,CAAC,MACO;CAChC,MAAM,SAAS,QAAQ,aAAa;CAEpC,MAAM,aAAa,MAAM,OACvB,OAAO,IAAI,UAAU,QACnB,QAAQ,gBAAgB,WAAW,MAAM,GAAG,IAAI,WAAW,MAAM,KAAK,eAAe,MAAM,CAC7F,CACF;CAEA,MAAM,cAAc,eAAe,YAAY,cAAc;EAC3D,MAAM,OAAO,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC,KAAK,OAAO,YAAY,GAAI,CAAC;EAC/D,MAAM,OAAO,OAAO,GAAG,OAAO,KAAK,CAAC,CAAC,KAAK,OAAO,YAAY,SAAS,CAAC;CACzE,CAAC;CAED,MAAM,eAAe,WAAW,KAAK,WAAW,gBAAgB,MAAM,QAAQ,WAAW,CAAC;CAE1F,OAAO,QAAQ,QAAQ,MAAM,MAAM,cAAc,QAAQ,KAAK,IAAI;AACpE;;;;;;;;;;;;;;;AAmBA,MAAa,SACX,SACA,UAAwB,CAAC,MAChB;CACT,YAAY,QAAQ,MAAM,OAAO,MAAM,SAAS,OAAO,CAAC,CAAC;AAC3D"}
@@ -1,11 +1,11 @@
1
- import { Effect } from "effect";
1
+ import * as Effect from "effect/Effect";
2
2
  import * as HttpClient from "effect/http/HttpClient";
3
3
  import * as HttpApiClient from "effect/http-api/HttpApiClient";
4
4
  import * as HttpApi from "effect/http-api/HttpApi";
5
5
  import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
6
6
  //#region src/api-client.d.ts
7
7
  /** Options for {@link apiClient}. */
8
- interface ApiClientOptions {
8
+ export interface ApiClientOptions {
9
9
  /**
10
10
  * The base URL the API is mounted at. For an `Endpoint.fromApi` mounted at
11
11
  * `src/routes/api/[...path]` with `prefix: "/api"`, pass `"/api"`. Defaults to
@@ -25,7 +25,6 @@ interface ApiClientOptions {
25
25
  * via `FetchHttpClient`. Yields the client from an `Effect`; the only remaining
26
26
  * requirement is any client middleware the API declares.
27
27
  */
28
- declare const apiClient: <ApiId extends string, Groups extends HttpApiGroup.Constraint>(api: HttpApi.HttpApi<ApiId, Groups>, options?: ApiClientOptions) => Effect.Effect<HttpApiClient.Client<Groups>, never, HttpApiGroup.MiddlewareClient<Groups>>;
28
+ export declare const apiClient: <ApiId extends string, Groups extends HttpApiGroup.Constraint>(api: HttpApi.HttpApi<ApiId, Groups>, options?: ApiClientOptions) => Effect.Effect<HttpApiClient.Client<Groups>, never, HttpApiGroup.MiddlewareClient<Groups>>;
29
29
  //#endregion
30
- export { ApiClientOptions, apiClient };
31
30
  //# sourceMappingURL=api-client.d.ts.map
@@ -1,4 +1,5 @@
1
- import { Effect, Layer } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
2
3
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
3
4
  import * as HttpApiClient from "effect/http-api/HttpApiClient";
4
5
  //#region src/api-client.ts
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.js","names":[],"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * A typed client for an Effect [`HttpApi`](https://effect.website) served by\n * {@link Endpoint.fromApi}, closing the serve↔consume loop.\n *\n * {@link apiClient} wraps Effect's own `HttpApiClient.make` and provides the\n * `HttpClient` for you (via `FetchHttpClient`), so a browser or a universal\n * `load` can call the same-origin API with full end-to-end types derived from\n * the shared `HttpApi` definition. In a `load`, pass `event.fetch` so the call\n * participates in SvelteKit's SSR fetch (relative URLs, credentials, dedupe).\n *\n * @example\n * ```ts\n * // src/routes/+page.ts — a universal load\n * import { apiClient } from \"@thomasfosterau/effect-sveltekit\";\n * import { Effect } from \"effect\";\n * import { api } from \"#lib/api.ts\"; // the shared HttpApi definition\n *\n * export const load = (event) =>\n * Effect.gen(function* () {\n * const client = yield* apiClient(api, { baseUrl: \"/api\", fetch: event.fetch });\n * return { user: yield* client.users.get({ path: { id: event.params.id } }) };\n * });\n * ```\n */\n\nimport { Effect, Layer } from \"effect\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport type * as HttpClient from \"effect/http/HttpClient\";\nimport type * as HttpApi from \"effect/http-api/HttpApi\";\nimport * as HttpApiClient from \"effect/http-api/HttpApiClient\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\n\n/** Options for {@link apiClient}. */\nexport interface ApiClientOptions {\n /**\n * The base URL the API is mounted at. For an `Endpoint.fromApi` mounted at\n * `src/routes/api/[...path]` with `prefix: \"/api\"`, pass `\"/api\"`. Defaults to\n * the endpoint paths relative to the current origin.\n */\n readonly baseUrl?: URL | string;\n /**\n * The `fetch` implementation to use. In a `load`, pass `event.fetch` so the\n * request joins SvelteKit's SSR fetch. Defaults to the platform `fetch`.\n */\n readonly fetch?: typeof globalThis.fetch;\n /** Transform the underlying `HttpClient` (e.g. add headers, retries). */\n readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;\n}\n\n/**\n * Build a typed {@link HttpApiClient} for `api`, with the `HttpClient` provided\n * via `FetchHttpClient`. Yields the client from an `Effect`; the only remaining\n * requirement is any client middleware the API declares.\n */\nexport const apiClient = <ApiId extends string, Groups extends HttpApiGroup.Constraint>(\n api: HttpApi.HttpApi<ApiId, Groups>,\n options?: ApiClientOptions,\n): Effect.Effect<HttpApiClient.Client<Groups>, never, HttpApiGroup.MiddlewareClient<Groups>> => {\n const fetchLayer =\n options?.fetch === undefined\n ? FetchHttpClient.layer\n : FetchHttpClient.layer.pipe(\n Layer.provide(Layer.succeed(FetchHttpClient.Fetch, options.fetch)),\n );\n\n return HttpApiClient.make(api, {\n baseUrl: options?.baseUrl,\n transformClient: options?.transformClient,\n }).pipe(Effect.provide(fetchLayer));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,aACX,KACA,YAC8F;CAC9F,MAAM,aACJ,SAAS,UAAU,KAAA,IACf,gBAAgB,QAChB,gBAAgB,MAAM,KACpB,MAAM,QAAQ,MAAM,QAAQ,gBAAgB,OAAO,QAAQ,KAAK,CAAC,CACnE;CAEN,OAAO,cAAc,KAAK,KAAK;EAC7B,SAAS,SAAS;EAClB,iBAAiB,SAAS;CAC5B,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,UAAU,CAAC;AACpC"}
1
+ {"version":3,"file":"api-client.js","names":[],"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * A typed client for an Effect [`HttpApi`](https://effect.website) served by\n * {@link Endpoint.fromApi}, closing the serve↔consume loop.\n *\n * {@link apiClient} wraps Effect's own `HttpApiClient.make` and provides the\n * `HttpClient` for you (via `FetchHttpClient`), so a browser or a universal\n * `load` can call the same-origin API with full end-to-end types derived from\n * the shared `HttpApi` definition. In a `load`, pass `event.fetch` so the call\n * participates in SvelteKit's SSR fetch (relative URLs, credentials, dedupe).\n *\n * @example\n * ```ts\n * // src/routes/+page.ts — a universal load\n * import { apiClient } from \"@thomasfosterau/effect-sveltekit\";\n * import { Effect } from \"effect\";\n * import { api } from \"#lib/api.ts\"; // the shared HttpApi definition\n *\n * export const load = (event) =>\n * Effect.gen(function* () {\n * const client = yield* apiClient(api, { baseUrl: \"/api\", fetch: event.fetch });\n * return { user: yield* client.users.get({ path: { id: event.params.id } }) };\n * });\n * ```\n */\n\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport type * as HttpClient from \"effect/http/HttpClient\";\nimport type * as HttpApi from \"effect/http-api/HttpApi\";\nimport * as HttpApiClient from \"effect/http-api/HttpApiClient\";\nimport type * as HttpApiGroup from \"effect/http-api/HttpApiGroup\";\n\n/** Options for {@link apiClient}. */\nexport interface ApiClientOptions {\n /**\n * The base URL the API is mounted at. For an `Endpoint.fromApi` mounted at\n * `src/routes/api/[...path]` with `prefix: \"/api\"`, pass `\"/api\"`. Defaults to\n * the endpoint paths relative to the current origin.\n */\n readonly baseUrl?: URL | string;\n /**\n * The `fetch` implementation to use. In a `load`, pass `event.fetch` so the\n * request joins SvelteKit's SSR fetch. Defaults to the platform `fetch`.\n */\n readonly fetch?: typeof globalThis.fetch;\n /** Transform the underlying `HttpClient` (e.g. add headers, retries). */\n readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;\n}\n\n/**\n * Build a typed {@link HttpApiClient} for `api`, with the `HttpClient` provided\n * via `FetchHttpClient`. Yields the client from an `Effect`; the only remaining\n * requirement is any client middleware the API declares.\n */\nexport const apiClient = <ApiId extends string, Groups extends HttpApiGroup.Constraint>(\n api: HttpApi.HttpApi<ApiId, Groups>,\n options?: ApiClientOptions,\n): Effect.Effect<HttpApiClient.Client<Groups>, never, HttpApiGroup.MiddlewareClient<Groups>> => {\n const fetchLayer =\n options?.fetch === undefined\n ? FetchHttpClient.layer\n : FetchHttpClient.layer.pipe(\n Layer.provide(Layer.succeed(FetchHttpClient.Fetch, options.fetch)),\n );\n\n return HttpApiClient.make(api, {\n baseUrl: options?.baseUrl,\n transformClient: options?.transformClient,\n }).pipe(Effect.provide(fetchLayer));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,aACX,KACA,YAC8F;CAC9F,MAAM,aACJ,SAAS,UAAU,KAAA,IACf,gBAAgB,QAChB,gBAAgB,MAAM,KACpB,MAAM,QAAQ,MAAM,QAAQ,gBAAgB,OAAO,QAAQ,KAAK,CAAC,CACnE;CAEN,OAAO,cAAc,KAAK,KAAK;EAC7B,SAAS,SAAS;EAClB,iBAAiB,SAAS;CAC5B,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,UAAU,CAAC;AACpC"}
@@ -2,16 +2,20 @@ import { SvelteRouteParams } from "./internal/route-params.js";
2
2
  import { SvelteKitRequestEvent } from "./runtime.js";
3
3
  import { ErrorTranslator } from "./request-runtime.js";
4
4
  import { SvelteKitCookies, SvelteKitLocals, SvelteKitResponseHeaders } from "./request-services.js";
5
- import { Effect, Exit, Fiber, Layer, ManagedRuntime } from "effect";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Exit from "effect/Exit";
7
+ import * as Layer from "effect/Layer";
8
+ import * as ManagedRuntime from "effect/ManagedRuntime";
6
9
  import * as HttpClient from "effect/http/HttpClient";
7
10
  import { Action, Actions, Load, RequestEvent, ServerLoad } from "@sveltejs/kit";
8
11
  import { Handle, HandleFetch, HandleServerError, ServerInit } from "@sveltejs/kit/hooks";
12
+ import * as Fiber from "effect/Fiber";
9
13
  //#region src/app-runtime.d.ts
10
14
  /**
11
15
  * The services provided to every wrapped effect on the server, in addition to
12
16
  * the application's own layer.
13
17
  */
14
- type SvelteKitServices = HttpClient.HttpClient | SvelteKitRequestEvent | SvelteKitCookies | SvelteKitResponseHeaders | SvelteKitLocals;
18
+ export type SvelteKitServices = HttpClient.HttpClient | SvelteKitRequestEvent | SvelteKitCookies | SvelteKitResponseHeaders | SvelteKitLocals;
15
19
  /**
16
20
  * A per-request Effect runtime: the application layer's services plus the
17
21
  * per-request {@link SvelteKitServices} (an `HttpClient` backed by the request's
@@ -24,7 +28,7 @@ type SvelteKitServices = HttpClient.HttpClient | SvelteKitRequestEvent | SvelteK
24
28
  * effects share one `HttpClient` and one request scope. Retrieve it from an
25
29
  * event with `ServerRuntime.requestRuntime` to run your own effects.
26
30
  */
27
- interface RequestRuntime<R = never> {
31
+ export interface RequestRuntime<R = never> {
28
32
  /** Run an effect for this request, returning its `Exit`. */
29
33
  readonly runPromiseExit: <A>(effect: Effect.Effect<A, unknown, R | SvelteKitServices>) => Promise<Exit.Exit<A, unknown>>;
30
34
  /** Run an effect for this request, throwing on failure (passing SvelteKit control flow through). */
@@ -35,7 +39,7 @@ interface RequestRuntime<R = never> {
35
39
  /**
36
40
  * Options for {@link makeServerRuntime}.
37
41
  */
38
- interface ServerRuntimeOptions {
42
+ export interface ServerRuntimeOptions {
39
43
  /**
40
44
  * Translate a failed `Cause` into SvelteKit control flow at the boundary of
41
45
  * every wrapper (`serverLoad`, `action`, `actions`, `endpoint`, `handle`,
@@ -55,7 +59,7 @@ interface ServerRuntimeOptions {
55
59
  * effects additionally have access to the services `R` of the application
56
60
  * layer.
57
61
  */
58
- interface ServerRuntime<R = never, E = never> {
62
+ export interface ServerRuntime<R = never, E = never> {
59
63
  /** The underlying managed runtime for the application layer. */
60
64
  readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;
61
65
  /**
@@ -170,7 +174,7 @@ interface ServerRuntime<R = never, E = never> {
170
174
  * `HttpClient`. Request-specific data should be passed to service methods as
171
175
  * arguments instead.
172
176
  */
173
- declare const makeServerRuntime: <R = never, E = never>(layer?: Layer.Layer<R, E>, options?: ServerRuntimeOptions) => ServerRuntime<R, E>;
177
+ export declare const makeServerRuntime: <R = never, E = never>(layer?: Layer.Layer<R, E>, options?: ServerRuntimeOptions) => ServerRuntime<R, E>;
174
178
  /**
175
179
  * A universal (client + server) Effect runtime bound to an application layer.
176
180
  *
@@ -178,7 +182,7 @@ declare const makeServerRuntime: <R = never, E = never>(layer?: Layer.Layer<R, E
178
182
  * functions also run in the browser, the layer must only use services that
179
183
  * work in both environments.
180
184
  */
181
- interface UniversalRuntime<R = never, E = never> {
185
+ export interface UniversalRuntime<R = never, E = never> {
182
186
  /** The underlying managed runtime for the application layer. */
183
187
  readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;
184
188
  /**
@@ -224,7 +228,6 @@ interface UniversalRuntime<R = never, E = never> {
224
228
  * );
225
229
  * ```
226
230
  */
227
- declare const makeUniversalRuntime: <R = never, E = never>(layer?: Layer.Layer<R, E>) => UniversalRuntime<R, E>;
231
+ export declare const makeUniversalRuntime: <R = never, E = never>(layer?: Layer.Layer<R, E>) => UniversalRuntime<R, E>;
228
232
  //#endregion
229
- export { RequestRuntime, ServerRuntime, ServerRuntimeOptions, SvelteKitServices, UniversalRuntime, makeServerRuntime, makeUniversalRuntime };
230
233
  //# sourceMappingURL=app-runtime.d.ts.map
@@ -1,7 +1,15 @@
1
1
  import { SvelteKitRequestEvent } from "./runtime.js";
2
2
  import { SvelteKit } from "./kit.js";
3
3
  import { SvelteKitCookies, SvelteKitLocals, SvelteKitResponseHeaders, requestServicesFrom } from "./request-services.js";
4
- import { Effect, Exit, Layer, ManagedRuntime, Scope } from "effect";
4
+ import * as Effect from "effect/Effect";
5
+ import "effect/Context";
6
+ import * as Exit from "effect/Exit";
7
+ import * as Layer from "effect/Layer";
8
+ import * as ManagedRuntime from "effect/ManagedRuntime";
9
+ import * as Predicate from "effect/Predicate";
10
+ import * as Rec from "effect/Record";
11
+ import * as Result from "effect/Result";
12
+ import * as Scope from "effect/Scope";
5
13
  import * as FetchHttpClient from "effect/http/FetchHttpClient";
6
14
  //#region src/app-runtime.ts
7
15
  /**
@@ -12,6 +20,8 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient";
12
20
  const RequestRuntimeKey = Symbol.for("@thomasfosterau/effect-sveltekit/requestRuntime");
13
21
  /** Read the per-request runtime entry an event carries, if any. */
14
22
  const requestRuntimeEntry = (event) => event.locals?.[RequestRuntimeKey];
23
+ /** Whether a universal load event is a server-side `RequestEvent` (it carries a `request`). */
24
+ const isRequestEvent = (event) => Predicate.hasProperty(event, "request") && Boolean(event.request);
15
25
  /** Layer with the per-request services for a server-side request. */
16
26
  const requestLayer = (event) => {
17
27
  const services = requestServicesFrom(event);
@@ -97,26 +107,26 @@ const makeServerRuntime = (layer, options) => {
97
107
  const { event } = input;
98
108
  const scope = Scope.makeUnsafe();
99
109
  const requestServices = await runtime.runPromise(Layer.buildWithScope(requestLayer(event), scope));
110
+ const requestRuntime = makeRequestRuntime(requestServices);
100
111
  const entry = {
101
112
  owner,
102
- runtime: makeRequestRuntime(requestServices)
113
+ runtime: requestRuntime
103
114
  };
104
115
  event.locals[RequestRuntimeKey] = entry;
105
- try {
106
- return await entry.runtime.runPromise(fn(input).pipe(Effect.withSpan(`handle ${event.route.id ?? "(unknown)"}`, { kind: "server" })));
107
- } finally {
108
- await runtime.runPromise(Scope.close(scope, Exit.void));
109
- }
116
+ const closeScope = () => runtime.runPromise(Scope.close(scope, Exit.void));
117
+ const running = Result.try(() => requestRuntime.runPromise(fn(input).pipe(Effect.withSpan(`handle ${event.route.id ?? "(unknown)"}`, { kind: "server" }))));
118
+ return Result.match(running, {
119
+ onSuccess: (response) => response.finally(closeScope),
120
+ onFailure: (thrown) => closeScope().then(() => {
121
+ throw thrown;
122
+ })
123
+ });
110
124
  };
111
125
  return {
112
126
  runtime,
113
127
  serverLoad: (fn) => (event) => run(event, fn(event).pipe(Effect.withSpan(`serverLoad ${event.route.id ?? "(unknown)"}`, { kind: "server" }))),
114
128
  action,
115
- actions: (actionsMap) => {
116
- const wrapped = {};
117
- for (const [key, fn] of Object.entries(actionsMap)) wrapped[key] = action(fn);
118
- return wrapped;
119
- },
129
+ actions: (actionsMap) => Rec.map(actionsMap, (fn) => action(fn)),
120
130
  handle,
121
131
  handleFetch: (fn) => (args) => run(args.event, fn(args).pipe(Effect.withSpan(`handleFetch ${args.event.route.id ?? "(unknown)"}`, { kind: "server" }))),
122
132
  handleError: (fn) => (args) => run(args.event, fn(args)),
@@ -166,8 +176,7 @@ const makeUniversalRuntime = (layer) => {
166
176
  return {
167
177
  runtime,
168
178
  load: (fn) => (event) => {
169
- const serverEvent = event.request ? event : void 0;
170
- return run(event.fetch, fn(event), serverEvent);
179
+ return run(event.fetch, fn(event), isRequestEvent(event) ? event : void 0);
171
180
  },
172
181
  runPromise: (fetchFn, effect) => run(fetchFn, effect),
173
182
  dispose: () => runtime.dispose()
@@ -1 +1 @@
1
- {"version":3,"file":"app-runtime.js","names":[],"sources":["../src/app-runtime.ts"],"sourcesContent":["/**\n * App-wide Effect runtimes for SvelteKit.\n *\n * `makeServerRuntime` / `makeUniversalRuntime` let an application define its\n * Effect services (database clients, API wrappers, config, ...) as a single\n * `Layer`, built once per server process and shared by every request, instead\n * of being rebuilt for each `load` / `action` / endpoint invocation.\n *\n * Per-request services — the {@link SvelteKitRequestEvent} and an `HttpClient`\n * backed by the event's `fetch` — are provided on top of the shared runtime\n * for each call, so SvelteKit's fetch behaviours (cookie forwarding, request\n * deduplication, relative URLs) keep working as expected.\n */\n\nimport type { Action, Actions, Load, RequestEvent, ServerLoad } from \"@sveltejs/kit\";\nimport type { Handle, HandleFetch, HandleServerError, ServerInit } from \"@sveltejs/kit/hooks\";\nimport { Context, Effect, type Fiber, Exit, Layer, ManagedRuntime, Scope } from \"effect\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport type * as HttpClient from \"effect/http/HttpClient\";\nimport { SvelteKitRequestEvent } from \"./runtime.js\";\nimport type { SvelteRouteParams } from \"./internal/route-params.js\";\nimport type { ErrorTranslator } from \"./request-runtime.js\";\nimport { SvelteKit } from \"./kit.js\";\nimport {\n SvelteKitCookies,\n SvelteKitLocals,\n SvelteKitResponseHeaders,\n requestServicesFrom,\n} from \"./request-services.js\";\n\n/**\n * The services provided to every wrapped effect on the server, in addition to\n * the application's own layer.\n */\nexport type SvelteKitServices =\n | HttpClient.HttpClient\n | SvelteKitRequestEvent\n | SvelteKitCookies\n | SvelteKitResponseHeaders\n | SvelteKitLocals;\n\n/**\n * A per-request Effect runtime: the application layer's services plus the\n * per-request {@link SvelteKitServices} (an `HttpClient` backed by the request's\n * `fetch`, and the {@link SvelteKitRequestEvent}), with the request services\n * built once for the request and shared.\n *\n * A {@link ServerRuntime}'s `handle` hook creates one per request and stores it\n * on `event.locals` (`App.Locals`). Every other wrapper for the same runtime\n * (`serverLoad`, `action`, `endpoint`, ...) then runs on it, so a request's\n * effects share one `HttpClient` and one request scope. Retrieve it from an\n * event with `ServerRuntime.requestRuntime` to run your own effects.\n */\nexport interface RequestRuntime<R = never> {\n /** Run an effect for this request, returning its `Exit`. */\n readonly runPromiseExit: <A>(\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<Exit.Exit<A, unknown>>;\n /** Run an effect for this request, throwing on failure (passing SvelteKit control flow through). */\n readonly runPromise: <A>(effect: Effect.Effect<A, unknown, R | SvelteKitServices>) => Promise<A>;\n /** Fork an effect for this request, returning the running fiber. */\n readonly runFork: <A>(\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Fiber.Fiber<A, unknown>;\n}\n\n/**\n * Symbol under which a {@link ServerRuntime}'s `handle` stores the per-request\n * {@link RequestRuntime} on `event.locals`. `Symbol.for` so the key is stable\n * across module instances.\n */\nconst RequestRuntimeKey: unique symbol = Symbol.for(\n \"@thomasfosterau/effect-sveltekit/requestRuntime\",\n);\n\n/**\n * The locals entry: the per-request runtime tagged with the `ServerRuntime`\n * that created it, so a different runtime's wrappers ignore it (and fall back\n * to building request services themselves) rather than running on the wrong\n * application layer.\n */\ninterface RequestRuntimeEntry {\n readonly owner: object;\n readonly runtime: RequestRuntime<any>;\n}\n\n/** Read the per-request runtime entry an event carries, if any. */\nconst requestRuntimeEntry = (event: RequestEvent): RequestRuntimeEntry | undefined =>\n (event.locals as Record<PropertyKey, unknown> | undefined)?.[RequestRuntimeKey] as\n | RequestRuntimeEntry\n | undefined;\n\n/** Layer with the per-request services for a server-side request. */\nconst requestLayer = (event: RequestEvent): Layer.Layer<SvelteKitServices> => {\n const services = requestServicesFrom(event);\n return Layer.mergeAll(\n FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, event.fetch))),\n Layer.succeed(SvelteKitRequestEvent, event),\n Layer.succeed(SvelteKitCookies, services.cookies),\n Layer.succeed(SvelteKitResponseHeaders, services.responseHeaders),\n Layer.succeed(SvelteKitLocals, services.locals),\n );\n};\n\n/** Layer providing `HttpClient` backed by an arbitrary fetch implementation. */\nconst fetchLayer = (fetchFn: typeof globalThis.fetch): Layer.Layer<HttpClient.HttpClient> =>\n FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetchFn)));\n\n/** Build a settle that returns a success value or throws via the translator. */\nconst makeSettle =\n (translate: ErrorTranslator) =>\n <A>(exit: Exit.Exit<A, unknown>): A =>\n Exit.match(exit, {\n onFailure: (cause) => translate(cause),\n onSuccess: (value) => value,\n });\n\n/** The default settle: Kit control-flow errors through, anything else a 500. */\nconst settle = makeSettle(SvelteKit.translate);\n\n/**\n * Options for {@link makeServerRuntime}.\n */\nexport interface ServerRuntimeOptions {\n /**\n * Translate a failed `Cause` into SvelteKit control flow at the boundary of\n * every wrapper (`serverLoad`, `action`, `actions`, `endpoint`, `handle`,\n * `handleFetch`, `handleError`, `init`). It may throw `redirect()` /\n * `error()` so a domain error catalogue surfaces as SvelteKit control flow\n * instead of a generic 500. Defaults to the package passthrough: SvelteKit's\n * own `redirect()` / `error()` are rethrown, anything else becomes an\n * `EffectCauseError` (a 500).\n */\n readonly translateError?: ErrorTranslator;\n}\n\n/**\n * A server-side Effect runtime bound to an application layer.\n *\n * Produced by {@link makeServerRuntime}. The wrapper methods mirror the\n * standalone helpers in `@thomasfosterau/effect-sveltekit/server`, but\n * effects additionally have access to the services `R` of the application\n * layer.\n */\nexport interface ServerRuntime<R = never, E = never> {\n /** The underlying managed runtime for the application layer. */\n readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `load`.\n */\n readonly serverLoad: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n ParentData extends Record<string, any> = any,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>,\n ) => ServerLoad<Params, ParentData, OutputData, RouteId>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit form action.\n */\n readonly action: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>,\n ) => Action<Params, OutputData, RouteId>;\n\n /**\n * Wraps an object of Effect-based form actions.\n */\n readonly actions: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n actionsMap: Record<\n string,\n (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>\n >,\n ) => Actions<Params, OutputData, RouteId>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit `handle` hook.\n */\n readonly handle: (\n fn: (args: Parameters<Handle>[0]) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => Handle;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `handleFetch` hook,\n * which intercepts `event.fetch` calls made on the server. The effect runs\n * with the per-request services on top of the application layer and produces\n * the `Response` to use.\n */\n readonly handleFetch: (\n fn: (\n args: Parameters<HandleFetch>[0],\n ) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => HandleFetch;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `handleError` hook.\n *\n * The effect receives the error and the request event, and produces the\n * shape that SvelteKit exposes to the client (your `App.Error`, or nothing).\n * It runs with the per-request services on top of the application layer.\n */\n readonly handleError: (\n fn: (\n args: Parameters<HandleServerError>[0],\n ) => Effect.Effect<Awaited<ReturnType<HandleServerError>>, unknown, R | SvelteKitServices>,\n ) => HandleServerError;\n\n /**\n * Wraps an Effect as a SvelteKit server `init` hook, run once before the\n * server responds to its first request. There is no request event, so the\n * effect only has access to the application layer's services.\n */\n readonly init: (effect: Effect.Effect<void, unknown, R>) => ServerInit;\n\n /**\n * The per-request {@link RequestRuntime} this runtime's `handle` stored on the\n * event, or `undefined` when `handle` was not used for the request. Use it to\n * run your own effects on the same per-request runtime (shared `HttpClient`\n * and request scope) that `serverLoad` / `action` / `endpoint` use.\n *\n * @example\n * ```ts\n * // anywhere with the request event, e.g. another `handle` in the sequence\n * const rt = runtime.requestRuntime(event);\n * await rt?.runPromise(Effect.gen(function* () {\n * const user = yield* Auth.currentUser;\n * event.locals.user = user;\n * }));\n * ```\n */\n readonly requestRuntime: (event: RequestEvent) => RequestRuntime<R> | undefined;\n\n /**\n * Wraps an Effect-based function as a SvelteKit `+server.ts` endpoint\n * handler (`GET`, `POST`, ...).\n */\n readonly endpoint: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => (event: RequestEvent<Params, RouteId>) => Promise<Response>;\n\n /**\n * Runs an effect for a specific request, providing both the application\n * layer and the per-request services. Failures (other than SvelteKit\n * control flow) are thrown as `EffectCauseError`.\n */\n readonly runPromise: <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<A>;\n\n /**\n * Runs an effect for a specific request and returns the Exit, without\n * translating failures into thrown errors.\n */\n readonly runPromiseExit: <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<Exit.Exit<A, unknown>>;\n\n /**\n * Disposes the underlying managed runtime, running the layer's finalizers.\n * Call this on server shutdown or in tests.\n */\n readonly dispose: () => Promise<void>;\n}\n\n/**\n * Creates a {@link ServerRuntime} from an application layer.\n *\n * The layer is built lazily on first use and shared by all requests for the\n * lifetime of the server process. Define it once in a server-only module and\n * import its wrappers from your routes:\n *\n * @example\n * ```ts\n * // src/lib/server/runtime.ts\n * import { makeServerRuntime } from '@thomasfosterau/effect-sveltekit/server';\n * import { Layer } from 'effect';\n * import { Database } from './database';\n *\n * export const runtime = makeServerRuntime(Database.layer);\n * ```\n *\n * ```ts\n * // src/routes/items/+page.server.ts\n * import { runtime } from '#lib/server/runtime.ts';\n * import { Effect } from 'effect';\n * import { Database } from '#lib/server/database.ts';\n *\n * export const load = runtime.serverLoad((event) =>\n * Effect.gen(function* () {\n * const db = yield* Database;\n * return { items: yield* db.listItems() };\n * })\n * );\n * ```\n *\n * Note that the application layer is built outside of any request, so its\n * services cannot depend on the per-request `SvelteKitRequestEvent` or\n * `HttpClient`. Request-specific data should be passed to service methods as\n * arguments instead.\n */\nexport const makeServerRuntime = <R = never, E = never>(\n layer?: Layer.Layer<R, E>,\n options?: ServerRuntimeOptions,\n): ServerRuntime<R, E> => {\n const runtime = ManagedRuntime.make((layer ?? Layer.empty) as Layer.Layer<R, E>);\n\n // The boundary translator for this runtime's wrappers (defaults to the\n // package passthrough: SvelteKit control flow through, anything else a 500).\n const settleRequest = options?.translateError ? makeSettle(options.translateError) : settle;\n\n // Identity token tagging the per-request runtimes this runtime creates, so a\n // different runtime's wrappers don't run on the wrong application layer.\n const owner = {};\n\n /** A {@link ScopedRequestRuntime} that provides the prebuilt request services. */\n const makeRequestRuntime = (\n requestServices: Context.Context<SvelteKitServices>,\n ): RequestRuntime<R> => {\n const provide = <A>(effect: Effect.Effect<A, unknown, R | SvelteKitServices>) =>\n Effect.provideContext(effect, requestServices) as Effect.Effect<A, unknown, R>;\n return {\n runPromiseExit: (effect) =>\n runtime.runPromiseExit(provide(effect)) as Promise<Exit.Exit<any, unknown>>,\n runPromise: (effect) => runtime.runPromiseExit(provide(effect)).then(settleRequest),\n runFork: (effect) => runtime.runFork(provide(effect)) as Fiber.Fiber<any, unknown>,\n };\n };\n\n /** The per-request runtime for this runtime carried by the event, if any. */\n const requestRuntimeOf = (event: RequestEvent): RequestRuntime<R> | undefined => {\n const entry = requestRuntimeEntry(event);\n return entry?.owner === owner ? (entry.runtime as RequestRuntime<R>) : undefined;\n };\n\n const runExit = <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ): Promise<Exit.Exit<A, unknown>> => {\n // Reuse the per-request runtime `handle` installed, if any; otherwise build\n // the per-request services for this single call.\n const requestRuntime = requestRuntimeOf(event);\n if (requestRuntime !== undefined) return requestRuntime.runPromiseExit(effect);\n const provided = Effect.provide(effect, requestLayer(event)) as Effect.Effect<A, unknown, R>;\n return runtime.runPromiseExit(provided) as Promise<Exit.Exit<A, unknown>>;\n };\n\n const run = <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ): Promise<A> => runExit(event, effect).then(settleRequest);\n\n const action: ServerRuntime<R, E>[\"action\"] = (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`action ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n );\n\n /**\n * The `handle` hook: build a per-request runtime, store it on `event.locals`\n * so every other wrapper (and the user's own code) runs on it, run the user's\n * effect, then close the request scope.\n */\n const handle: ServerRuntime<R, E>[\"handle\"] = (fn) => async (input) => {\n const { event } = input;\n const scope = Scope.makeUnsafe();\n const requestServices = (await runtime.runPromise(\n Layer.buildWithScope(requestLayer(event), scope),\n )) as Context.Context<SvelteKitServices>;\n\n const entry: RequestRuntimeEntry = { owner, runtime: makeRequestRuntime(requestServices) };\n (event.locals as Record<PropertyKey, unknown>)[RequestRuntimeKey] = entry;\n\n try {\n return await (entry.runtime as RequestRuntime<R>).runPromise(\n fn(input).pipe(\n Effect.withSpan(`handle ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n );\n } finally {\n await runtime.runPromise(Scope.close(scope, Exit.void));\n }\n };\n\n return {\n runtime,\n serverLoad: (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`serverLoad ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n ),\n action,\n actions: (actionsMap) => {\n const wrapped: Record<string, Action<any, any, any>> = {};\n for (const [key, fn] of Object.entries(actionsMap)) {\n wrapped[key] = action(fn);\n }\n return wrapped as never;\n },\n handle,\n handleFetch: (fn) => (args) =>\n run(\n args.event,\n fn(args).pipe(\n Effect.withSpan(`handleFetch ${args.event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n ),\n handleError: (fn) => (args) => run(args.event, fn(args)),\n init: (effect) => async () => {\n // `init` runs outside of any request, so it executes directly on the\n // application runtime without the per-request layer.\n settleRequest(await runtime.runPromiseExit(effect));\n },\n requestRuntime: requestRuntimeOf,\n endpoint: (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`${event.request.method} ${event.route.id ?? \"(unknown)\"}`, {\n kind: \"server\",\n }),\n ),\n ),\n runPromise: run,\n runPromiseExit: runExit,\n dispose: () => runtime.dispose(),\n };\n};\n\n/**\n * A universal (client + server) Effect runtime bound to an application layer.\n *\n * Produced by {@link makeUniversalRuntime}. Because universal `load`\n * functions also run in the browser, the layer must only use services that\n * work in both environments.\n */\nexport interface UniversalRuntime<R = never, E = never> {\n /** The underlying managed runtime for the application layer. */\n readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit universal `load`.\n *\n * The effect gets `HttpClient` (backed by the load event's `fetch`) on both\n * client and server, plus the services of the application layer.\n */\n readonly load: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n InputData extends Record<string, unknown> | null = any,\n ParentData extends Record<string, unknown> = any,\n OutputData extends Record<string, unknown> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: Parameters<Load<Params, InputData, ParentData, OutputData, RouteId>>[0],\n ) => Effect.Effect<OutputData, unknown, R | HttpClient.HttpClient>,\n ) => Load<Params, InputData, ParentData, OutputData, RouteId>;\n\n /**\n * Runs an effect with `HttpClient` backed by the given fetch implementation\n * plus the application layer.\n */\n readonly runPromise: <A>(\n fetchFn: typeof globalThis.fetch,\n effect: Effect.Effect<A, unknown, R | HttpClient.HttpClient>,\n ) => Promise<A>;\n\n /**\n * Disposes the underlying managed runtime, running the layer's finalizers.\n */\n readonly dispose: () => Promise<void>;\n}\n\n/**\n * Creates a {@link UniversalRuntime} from an application layer.\n *\n * @example\n * ```ts\n * // src/lib/runtime.ts\n * import { makeUniversalRuntime } from '@thomasfosterau/effect-sveltekit';\n * import { ApiClient } from '#lib/api.ts';\n *\n * export const runtime = makeUniversalRuntime(ApiClient.layer);\n * ```\n *\n * ```ts\n * // src/routes/+page.ts\n * import { runtime } from '#lib/runtime.ts';\n * import { Effect } from 'effect';\n * import { ApiClient } from '#lib/api.ts';\n *\n * export const load = runtime.load((event) =>\n * Effect.gen(function* () {\n * const api = yield* ApiClient;\n * return { stories: yield* api.topStories() };\n * })\n * );\n * ```\n */\nexport const makeUniversalRuntime = <R = never, E = never>(\n layer?: Layer.Layer<R, E>,\n): UniversalRuntime<R, E> => {\n const runtime = ManagedRuntime.make((layer ?? Layer.empty) as Layer.Layer<R, E>);\n\n const run = <A>(\n fetchFn: typeof globalThis.fetch,\n effect: Effect.Effect<A, unknown, R | HttpClient.HttpClient>,\n event?: RequestEvent,\n ): Promise<A> => {\n // On the server the full request layer (HttpClient + SvelteKitRequestEvent)\n // is available; on the client only HttpClient backed by the event's fetch.\n const services = event ? requestLayer(event) : fetchLayer(fetchFn);\n const provided = Effect.provide(effect, services) as Effect.Effect<A, unknown, R>;\n return runtime.runPromiseExit(provided).then(settle);\n };\n\n return {\n runtime,\n load: (fn) => (event) => {\n const serverEvent = (event as { request?: unknown }).request\n ? (event as unknown as RequestEvent)\n : undefined;\n return run(event.fetch, fn(event), serverEvent);\n },\n runPromise: (fetchFn, effect) => run(fetchFn, effect),\n dispose: () => runtime.dispose(),\n };\n};\n"],"mappings":"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"}
1
+ {"version":3,"file":"app-runtime.js","names":[],"sources":["../src/app-runtime.ts"],"sourcesContent":["/**\n * App-wide Effect runtimes for SvelteKit.\n *\n * `makeServerRuntime` / `makeUniversalRuntime` let an application define its\n * Effect services (database clients, API wrappers, config, ...) as a single\n * `Layer`, built once per server process and shared by every request, instead\n * of being rebuilt for each `load` / `action` / endpoint invocation.\n *\n * Per-request services — the {@link SvelteKitRequestEvent} and an `HttpClient`\n * backed by the event's `fetch` — are provided on top of the shared runtime\n * for each call, so SvelteKit's fetch behaviours (cookie forwarding, request\n * deduplication, relative URLs) keep working as expected.\n */\n\nimport type { Action, Actions, Load, RequestEvent, ServerLoad } from \"@sveltejs/kit\";\nimport type { Handle, HandleFetch, HandleServerError, ServerInit } from \"@sveltejs/kit/hooks\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport type * as Fiber from \"effect/Fiber\";\nimport * as Exit from \"effect/Exit\";\nimport * as Layer from \"effect/Layer\";\nimport * as ManagedRuntime from \"effect/ManagedRuntime\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Rec from \"effect/Record\";\nimport * as Result from \"effect/Result\";\nimport * as Scope from \"effect/Scope\";\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\";\nimport type * as HttpClient from \"effect/http/HttpClient\";\nimport { SvelteKitRequestEvent } from \"./runtime.js\";\nimport type { SvelteRouteParams } from \"./internal/route-params.js\";\nimport type { ErrorTranslator } from \"./request-runtime.js\";\nimport { SvelteKit } from \"./kit.js\";\nimport {\n SvelteKitCookies,\n SvelteKitLocals,\n SvelteKitResponseHeaders,\n requestServicesFrom,\n} from \"./request-services.js\";\n\n/**\n * The services provided to every wrapped effect on the server, in addition to\n * the application's own layer.\n */\nexport type SvelteKitServices =\n | HttpClient.HttpClient\n | SvelteKitRequestEvent\n | SvelteKitCookies\n | SvelteKitResponseHeaders\n | SvelteKitLocals;\n\n/**\n * A per-request Effect runtime: the application layer's services plus the\n * per-request {@link SvelteKitServices} (an `HttpClient` backed by the request's\n * `fetch`, and the {@link SvelteKitRequestEvent}), with the request services\n * built once for the request and shared.\n *\n * A {@link ServerRuntime}'s `handle` hook creates one per request and stores it\n * on `event.locals` (`App.Locals`). Every other wrapper for the same runtime\n * (`serverLoad`, `action`, `endpoint`, ...) then runs on it, so a request's\n * effects share one `HttpClient` and one request scope. Retrieve it from an\n * event with `ServerRuntime.requestRuntime` to run your own effects.\n */\nexport interface RequestRuntime<R = never> {\n /** Run an effect for this request, returning its `Exit`. */\n readonly runPromiseExit: <A>(\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<Exit.Exit<A, unknown>>;\n /** Run an effect for this request, throwing on failure (passing SvelteKit control flow through). */\n readonly runPromise: <A>(effect: Effect.Effect<A, unknown, R | SvelteKitServices>) => Promise<A>;\n /** Fork an effect for this request, returning the running fiber. */\n readonly runFork: <A>(\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Fiber.Fiber<A, unknown>;\n}\n\n/**\n * Symbol under which a {@link ServerRuntime}'s `handle` stores the per-request\n * {@link RequestRuntime} on `event.locals`. `Symbol.for` so the key is stable\n * across module instances.\n */\nconst RequestRuntimeKey: unique symbol = Symbol.for(\n \"@thomasfosterau/effect-sveltekit/requestRuntime\",\n);\n\n/**\n * The locals entry: the per-request runtime tagged with the `ServerRuntime`\n * that created it, so a different runtime's wrappers ignore it (and fall back\n * to building request services themselves) rather than running on the wrong\n * application layer.\n */\ninterface RequestRuntimeEntry {\n readonly owner: object;\n readonly runtime: RequestRuntime<any>;\n}\n\n/** `event.locals` as this module sees it: possibly carrying a {@link RequestRuntimeEntry}. */\ninterface LocalsWithRequestRuntime {\n [RequestRuntimeKey]?: RequestRuntimeEntry | undefined;\n}\n\n/** Read the per-request runtime entry an event carries, if any. */\nconst requestRuntimeEntry = (event: RequestEvent): RequestRuntimeEntry | undefined =>\n // SAFETY: `RequestRuntimeKey` is this package's namespaced symbol, and the\n // only value ever stored under it on `locals` is a `RequestRuntimeEntry`.\n (event.locals as LocalsWithRequestRuntime | undefined)?.[RequestRuntimeKey];\n\n/** Whether a universal load event is a server-side `RequestEvent` (it carries a `request`). */\nconst isRequestEvent = <Event>(event: Event): event is Event & RequestEvent =>\n Predicate.hasProperty(event, \"request\") && Boolean(event.request);\n\n/** Layer with the per-request services for a server-side request. */\nconst requestLayer = (event: RequestEvent): Layer.Layer<SvelteKitServices> => {\n const services = requestServicesFrom(event);\n return Layer.mergeAll(\n FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, event.fetch))),\n Layer.succeed(SvelteKitRequestEvent, event),\n Layer.succeed(SvelteKitCookies, services.cookies),\n Layer.succeed(SvelteKitResponseHeaders, services.responseHeaders),\n Layer.succeed(SvelteKitLocals, services.locals),\n );\n};\n\n/** Layer providing `HttpClient` backed by an arbitrary fetch implementation. */\nconst fetchLayer = (fetchFn: typeof globalThis.fetch): Layer.Layer<HttpClient.HttpClient> =>\n FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetchFn)));\n\n/** Build a settle that returns a success value or throws via the translator. */\nconst makeSettle =\n (translate: ErrorTranslator) =>\n <A>(exit: Exit.Exit<A, unknown>): A =>\n Exit.match(exit, {\n onFailure: (cause) => translate(cause),\n onSuccess: (value) => value,\n });\n\n/** The default settle: Kit control-flow errors through, anything else a 500. */\nconst settle = makeSettle(SvelteKit.translate);\n\n/**\n * Options for {@link makeServerRuntime}.\n */\nexport interface ServerRuntimeOptions {\n /**\n * Translate a failed `Cause` into SvelteKit control flow at the boundary of\n * every wrapper (`serverLoad`, `action`, `actions`, `endpoint`, `handle`,\n * `handleFetch`, `handleError`, `init`). It may throw `redirect()` /\n * `error()` so a domain error catalogue surfaces as SvelteKit control flow\n * instead of a generic 500. Defaults to the package passthrough: SvelteKit's\n * own `redirect()` / `error()` are rethrown, anything else becomes an\n * `EffectCauseError` (a 500).\n */\n readonly translateError?: ErrorTranslator;\n}\n\n/**\n * A server-side Effect runtime bound to an application layer.\n *\n * Produced by {@link makeServerRuntime}. The wrapper methods mirror the\n * standalone helpers in `@thomasfosterau/effect-sveltekit/server`, but\n * effects additionally have access to the services `R` of the application\n * layer.\n */\nexport interface ServerRuntime<R = never, E = never> {\n /** The underlying managed runtime for the application layer. */\n readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `load`.\n */\n readonly serverLoad: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n ParentData extends Record<string, any> = any,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>,\n ) => ServerLoad<Params, ParentData, OutputData, RouteId>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit form action.\n */\n readonly action: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>,\n ) => Action<Params, OutputData, RouteId>;\n\n /**\n * Wraps an object of Effect-based form actions.\n */\n readonly actions: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n OutputData extends Record<string, any> | void = any,\n RouteId extends string | null = any,\n >(\n actionsMap: Record<\n string,\n (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<OutputData, unknown, R | SvelteKitServices>\n >,\n ) => Actions<Params, OutputData, RouteId>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit `handle` hook.\n */\n readonly handle: (\n fn: (args: Parameters<Handle>[0]) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => Handle;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `handleFetch` hook,\n * which intercepts `event.fetch` calls made on the server. The effect runs\n * with the per-request services on top of the application layer and produces\n * the `Response` to use.\n */\n readonly handleFetch: (\n fn: (\n args: Parameters<HandleFetch>[0],\n ) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => HandleFetch;\n\n /**\n * Wraps an Effect-based function as a SvelteKit server `handleError` hook.\n *\n * The effect receives the error and the request event, and produces the\n * shape that SvelteKit exposes to the client (your `App.Error`, or nothing).\n * It runs with the per-request services on top of the application layer.\n */\n readonly handleError: (\n fn: (\n args: Parameters<HandleServerError>[0],\n ) => Effect.Effect<Awaited<ReturnType<HandleServerError>>, unknown, R | SvelteKitServices>,\n ) => HandleServerError;\n\n /**\n * Wraps an Effect as a SvelteKit server `init` hook, run once before the\n * server responds to its first request. There is no request event, so the\n * effect only has access to the application layer's services.\n */\n readonly init: (effect: Effect.Effect<void, unknown, R>) => ServerInit;\n\n /**\n * The per-request {@link RequestRuntime} this runtime's `handle` stored on the\n * event, or `undefined` when `handle` was not used for the request. Use it to\n * run your own effects on the same per-request runtime (shared `HttpClient`\n * and request scope) that `serverLoad` / `action` / `endpoint` use.\n *\n * @example\n * ```ts\n * // anywhere with the request event, e.g. another `handle` in the sequence\n * const rt = runtime.requestRuntime(event);\n * await rt?.runPromise(Effect.gen(function* () {\n * const user = yield* Auth.currentUser;\n * event.locals.user = user;\n * }));\n * ```\n */\n readonly requestRuntime: (event: RequestEvent) => RequestRuntime<R> | undefined;\n\n /**\n * Wraps an Effect-based function as a SvelteKit `+server.ts` endpoint\n * handler (`GET`, `POST`, ...).\n */\n readonly endpoint: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n RouteId extends string | null = any,\n >(\n fn: (\n event: RequestEvent<Params, RouteId>,\n ) => Effect.Effect<Response, unknown, R | SvelteKitServices>,\n ) => (event: RequestEvent<Params, RouteId>) => Promise<Response>;\n\n /**\n * Runs an effect for a specific request, providing both the application\n * layer and the per-request services. Failures (other than SvelteKit\n * control flow) are thrown as `EffectCauseError`.\n */\n readonly runPromise: <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<A>;\n\n /**\n * Runs an effect for a specific request and returns the Exit, without\n * translating failures into thrown errors.\n */\n readonly runPromiseExit: <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ) => Promise<Exit.Exit<A, unknown>>;\n\n /**\n * Disposes the underlying managed runtime, running the layer's finalizers.\n * Call this on server shutdown or in tests.\n */\n readonly dispose: () => Promise<void>;\n}\n\n/**\n * Creates a {@link ServerRuntime} from an application layer.\n *\n * The layer is built lazily on first use and shared by all requests for the\n * lifetime of the server process. Define it once in a server-only module and\n * import its wrappers from your routes:\n *\n * @example\n * ```ts\n * // src/lib/server/runtime.ts\n * import { makeServerRuntime } from '@thomasfosterau/effect-sveltekit/server';\n * import { Layer } from 'effect';\n * import { Database } from './database';\n *\n * export const runtime = makeServerRuntime(Database.layer);\n * ```\n *\n * ```ts\n * // src/routes/items/+page.server.ts\n * import { runtime } from '#lib/server/runtime.ts';\n * import { Effect } from 'effect';\n * import { Database } from '#lib/server/database.ts';\n *\n * export const load = runtime.serverLoad((event) =>\n * Effect.gen(function* () {\n * const db = yield* Database;\n * return { items: yield* db.listItems() };\n * })\n * );\n * ```\n *\n * Note that the application layer is built outside of any request, so its\n * services cannot depend on the per-request `SvelteKitRequestEvent` or\n * `HttpClient`. Request-specific data should be passed to service methods as\n * arguments instead.\n */\nexport const makeServerRuntime = <R = never, E = never>(\n layer?: Layer.Layer<R, E>,\n options?: ServerRuntimeOptions,\n): ServerRuntime<R, E> => {\n // SAFETY: a runtime made without a layer has the defaults `R = never` and\n // `E = never`, which `Layer.empty` provides.\n const runtime = ManagedRuntime.make((layer ?? Layer.empty) as Layer.Layer<R, E>);\n\n // The boundary translator for this runtime's wrappers (defaults to the\n // package passthrough: SvelteKit control flow through, anything else a 500).\n const settleRequest = options?.translateError ? makeSettle(options.translateError) : settle;\n\n // Identity token tagging the per-request runtimes this runtime creates, so a\n // different runtime's wrappers don't run on the wrong application layer.\n const owner = {};\n\n /** A {@link ScopedRequestRuntime} that provides the prebuilt request services. */\n const makeRequestRuntime = (\n requestServices: Context.Context<SvelteKitServices>,\n ): RequestRuntime<R> => {\n const provide = <A>(effect: Effect.Effect<A, unknown, R | SvelteKitServices>) =>\n // SAFETY: providing the `SvelteKitServices` leaves at most `R`; the\n // `Exclude` only stays unresolved while `R` is generic.\n Effect.provideContext(effect, requestServices) as Effect.Effect<A, unknown, R>;\n return {\n runPromiseExit: (effect) => runtime.runPromiseExit(provide(effect)),\n runPromise: (effect) => runtime.runPromiseExit(provide(effect)).then(settleRequest),\n runFork: (effect) => runtime.runFork(provide(effect)),\n };\n };\n\n /** The per-request runtime for this runtime carried by the event, if any. */\n const requestRuntimeOf = (event: RequestEvent): RequestRuntime<R> | undefined => {\n const entry = requestRuntimeEntry(event);\n // SAFETY: an entry tagged with this runtime's `owner` was created by its\n // `handle`, from `makeRequestRuntime`, so it is a `RequestRuntime<R>`.\n return entry?.owner === owner ? (entry.runtime as RequestRuntime<R>) : undefined;\n };\n\n const runExit = <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ): Promise<Exit.Exit<A, unknown>> => {\n // Reuse the per-request runtime `handle` installed, if any; otherwise build\n // the per-request services for this single call.\n const requestRuntime = requestRuntimeOf(event);\n if (requestRuntime !== undefined) return requestRuntime.runPromiseExit(effect);\n // SAFETY: the request layer provides the `SvelteKitServices`, leaving at\n // most `R`; the `Exclude` only stays unresolved while `R` is generic.\n const provided = Effect.provide(effect, requestLayer(event)) as Effect.Effect<A, unknown, R>;\n return runtime.runPromiseExit(provided);\n };\n\n const run = <A>(\n event: RequestEvent,\n effect: Effect.Effect<A, unknown, R | SvelteKitServices>,\n ): Promise<A> => runExit(event, effect).then(settleRequest);\n\n const action: ServerRuntime<R, E>[\"action\"] = (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`action ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n );\n\n /**\n * The `handle` hook: build a per-request runtime, store it on `event.locals`\n * so every other wrapper (and the user's own code) runs on it, run the user's\n * effect, then close the request scope.\n */\n const handle: ServerRuntime<R, E>[\"handle\"] = (fn) => async (input) => {\n const { event } = input;\n const scope = Scope.makeUnsafe();\n const requestServices: Context.Context<SvelteKitServices> = await runtime.runPromise(\n Layer.buildWithScope(requestLayer(event), scope),\n );\n\n const requestRuntime = makeRequestRuntime(requestServices);\n const entry: RequestRuntimeEntry = { owner, runtime: requestRuntime };\n // SAFETY: `locals` is the request's plain, writable object; the namespaced\n // symbol key cannot clash with the app's own `App.Locals` fields.\n (event.locals as LocalsWithRequestRuntime)[RequestRuntimeKey] = entry;\n\n // Close the request scope once the user's effect settles, also when\n // building it throws, then surface its outcome (or the close's failure).\n const closeScope = () => runtime.runPromise(Scope.close(scope, Exit.void));\n const running = Result.try(() =>\n requestRuntime.runPromise(\n fn(input).pipe(\n Effect.withSpan(`handle ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n ),\n );\n return Result.match(running, {\n onSuccess: (response) => response.finally(closeScope),\n onFailure: (thrown) =>\n closeScope().then(() => {\n throw thrown;\n }),\n });\n };\n\n return {\n runtime,\n serverLoad: (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`serverLoad ${event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n ),\n action,\n actions: (actionsMap) => Rec.map(actionsMap, (fn) => action(fn)),\n handle,\n handleFetch: (fn) => (args) =>\n run(\n args.event,\n fn(args).pipe(\n Effect.withSpan(`handleFetch ${args.event.route.id ?? \"(unknown)\"}`, { kind: \"server\" }),\n ),\n ),\n handleError: (fn) => (args) => run(args.event, fn(args)),\n init: (effect) => async () => {\n // `init` runs outside of any request, so it executes directly on the\n // application runtime without the per-request layer.\n settleRequest(await runtime.runPromiseExit(effect));\n },\n requestRuntime: requestRuntimeOf,\n endpoint: (fn) => (event) =>\n run(\n event,\n fn(event).pipe(\n Effect.withSpan(`${event.request.method} ${event.route.id ?? \"(unknown)\"}`, {\n kind: \"server\",\n }),\n ),\n ),\n runPromise: run,\n runPromiseExit: runExit,\n dispose: () => runtime.dispose(),\n };\n};\n\n/**\n * A universal (client + server) Effect runtime bound to an application layer.\n *\n * Produced by {@link makeUniversalRuntime}. Because universal `load`\n * functions also run in the browser, the layer must only use services that\n * work in both environments.\n */\nexport interface UniversalRuntime<R = never, E = never> {\n /** The underlying managed runtime for the application layer. */\n readonly runtime: ManagedRuntime.ManagedRuntime<R, E>;\n\n /**\n * Wraps an Effect-based function as a SvelteKit universal `load`.\n *\n * The effect gets `HttpClient` (backed by the load event's `fetch`) on both\n * client and server, plus the services of the application layer.\n */\n readonly load: <\n Params extends SvelteRouteParams = SvelteRouteParams,\n InputData extends Record<string, unknown> | null = any,\n ParentData extends Record<string, unknown> = any,\n OutputData extends Record<string, unknown> | void = any,\n RouteId extends string | null = any,\n >(\n fn: (\n event: Parameters<Load<Params, InputData, ParentData, OutputData, RouteId>>[0],\n ) => Effect.Effect<OutputData, unknown, R | HttpClient.HttpClient>,\n ) => Load<Params, InputData, ParentData, OutputData, RouteId>;\n\n /**\n * Runs an effect with `HttpClient` backed by the given fetch implementation\n * plus the application layer.\n */\n readonly runPromise: <A>(\n fetchFn: typeof globalThis.fetch,\n effect: Effect.Effect<A, unknown, R | HttpClient.HttpClient>,\n ) => Promise<A>;\n\n /**\n * Disposes the underlying managed runtime, running the layer's finalizers.\n */\n readonly dispose: () => Promise<void>;\n}\n\n/**\n * Creates a {@link UniversalRuntime} from an application layer.\n *\n * @example\n * ```ts\n * // src/lib/runtime.ts\n * import { makeUniversalRuntime } from '@thomasfosterau/effect-sveltekit';\n * import { ApiClient } from '#lib/api.ts';\n *\n * export const runtime = makeUniversalRuntime(ApiClient.layer);\n * ```\n *\n * ```ts\n * // src/routes/+page.ts\n * import { runtime } from '#lib/runtime.ts';\n * import { Effect } from 'effect';\n * import { ApiClient } from '#lib/api.ts';\n *\n * export const load = runtime.load((event) =>\n * Effect.gen(function* () {\n * const api = yield* ApiClient;\n * return { stories: yield* api.topStories() };\n * })\n * );\n * ```\n */\nexport const makeUniversalRuntime = <R = never, E = never>(\n layer?: Layer.Layer<R, E>,\n): UniversalRuntime<R, E> => {\n // SAFETY: a runtime made without a layer has the defaults `R = never` and\n // `E = never`, which `Layer.empty` provides.\n const runtime = ManagedRuntime.make((layer ?? Layer.empty) as Layer.Layer<R, E>);\n\n const run = <A>(\n fetchFn: typeof globalThis.fetch,\n effect: Effect.Effect<A, unknown, R | HttpClient.HttpClient>,\n event?: RequestEvent,\n ): Promise<A> => {\n // On the server the full request layer (HttpClient + SvelteKitRequestEvent)\n // is available; on the client only HttpClient backed by the event's fetch.\n const services = event ? requestLayer(event) : fetchLayer(fetchFn);\n // SAFETY: both layers provide `HttpClient`, leaving at most `R`; the\n // `Exclude` only stays unresolved while `R` is generic.\n const provided = Effect.provide(effect, services) as Effect.Effect<A, unknown, R>;\n return runtime.runPromiseExit(provided).then(settle);\n };\n\n return {\n runtime,\n load: (fn) => (event) => {\n return run(event.fetch, fn(event), isRequestEvent(event) ? event : undefined);\n },\n runPromise: (fetchFn, effect) => run(fetchFn, effect),\n dispose: () => runtime.dispose(),\n };\n};\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- import { Effect } from "effect";
1
+ import * as Effect from "effect/Effect";
2
2
  import { ClientInit, HandleClientError } from "@sveltejs/kit/hooks";
3
3
  declare namespace Hooks_d_exports {
4
4
  export { handleError, init };
@@ -24,7 +24,7 @@ declare namespace Hooks_d_exports {
24
24
  * );
25
25
  * ```
26
26
  */
27
- declare function handleError(fn: (args: Parameters<HandleClientError>[0]) => Effect.Effect<Awaited<ReturnType<HandleClientError>>, unknown>): HandleClientError;
27
+ export declare function handleError(fn: (args: Parameters<HandleClientError>[0]) => Effect.Effect<Awaited<ReturnType<HandleClientError>>, unknown>): HandleClientError;
28
28
  /**
29
29
  * Wraps an Effect as the SvelteKit client
30
30
  * [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) hook, which
@@ -40,7 +40,7 @@ declare function handleError(fn: (args: Parameters<HandleClientError>[0]) => Eff
40
40
  * export const init = Hooks.init(Effect.logInfo('client app started'));
41
41
  * ```
42
42
  */
43
- declare function init(effect: Effect.Effect<void, unknown>): ClientInit;
43
+ export declare function init(effect: Effect.Effect<void, unknown>): ClientInit;
44
44
  //#endregion
45
- export { Hooks_d_exports, handleError, init };
45
+ export { Hooks_d_exports };
46
46
  //# sourceMappingURL=Hooks.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { causeToThrowable } from "../internal/error.js";
3
- import { Effect, Exit } from "effect";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Exit from "effect/Exit";
4
5
  //#region src/client/Hooks.ts
5
6
  var Hooks_exports = /* @__PURE__ */ __exportAll({
6
7
  handleError: () => handleError,
@@ -1 +1 @@
1
- {"version":3,"file":"Hooks.js","names":[],"sources":["../../src/client/Hooks.ts"],"sourcesContent":["/**\n * Effect wrappers for SvelteKit's client-side hooks (`src/hooks.client.ts`),\n * exposed as the `Hooks` namespace of `@thomasfosterau/effect-sveltekit/client`.\n *\n * These mirror the server hook helpers in `../server/Hooks.ts`, but run on the\n * client: there is no request context, so each effect runs on a bare Effect\n * runtime. For application services, run the effect through your own runtime\n * instead. Kept free of `$app/*` imports so it stays importable (and testable)\n * outside of a SvelteKit app.\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const handleError = Hooks.handleError(({ error, event }) =>\n * Effect.as(Effect.logError(`navigation to ${event.url.pathname} failed`, error), {\n * message: 'Something went wrong',\n * })\n * );\n * ```\n */\n\nimport type { ClientInit, HandleClientError } from \"@sveltejs/kit/hooks\";\nimport { Effect, Exit } from \"effect\";\nimport { causeToThrowable } from \"../internal/error.js\";\n\n/** Run a bare Effect (no request context) and settle it the way a hook expects. */\nconst runBareHook = async <A>(effect: Effect.Effect<A, unknown>): Promise<A> =>\n Exit.match(await Effect.runPromiseExit(effect), {\n onFailure: (cause) => {\n throw causeToThrowable(cause);\n },\n onSuccess: (value) => value,\n });\n\n/**\n * Wraps an Effect-based function as the SvelteKit client\n * [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError)\n * hook, which runs when an unexpected error is thrown while navigating in the\n * browser. The effect receives the error and navigation event and produces the\n * shape exposed to the page (your `App.Error`, or nothing).\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const handleError = Hooks.handleError(({ error, event }) =>\n * Effect.gen(function* () {\n * yield* Effect.logError(`navigation to ${event.url.pathname} failed`, error);\n * return { message: 'Something went wrong' };\n * })\n * );\n * ```\n */\nexport function handleError(\n fn: (\n args: Parameters<HandleClientError>[0],\n ) => Effect.Effect<Awaited<ReturnType<HandleClientError>>, unknown>,\n): HandleClientError {\n return (args) => runBareHook(fn(args));\n}\n\n/**\n * Wraps an Effect as the SvelteKit client\n * [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) hook, which\n * runs once when the app starts in the browser. The effect runs on a bare\n * Effect runtime.\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const init = Hooks.init(Effect.logInfo('client app started'));\n * ```\n */\nexport function init(effect: Effect.Effect<void, unknown>): ClientInit {\n return () => runBareHook(effect);\n}\n"],"mappings":";;;;;;;;;AA6BA,MAAM,cAAc,OAAU,WAC5B,KAAK,MAAM,MAAM,OAAO,eAAe,MAAM,GAAG;CAC9C,YAAY,UAAU;EACpB,MAAM,iBAAiB,KAAK;CAC9B;CACA,YAAY,UAAU;AACxB,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuBH,SAAgB,YACd,IAGmB;CACnB,QAAQ,SAAS,YAAY,GAAG,IAAI,CAAC;AACvC;;;;;;;;;;;;;;;;AAiBA,SAAgB,KAAK,QAAkD;CACrE,aAAa,YAAY,MAAM;AACjC"}
1
+ {"version":3,"file":"Hooks.js","names":[],"sources":["../../src/client/Hooks.ts"],"sourcesContent":["/**\n * Effect wrappers for SvelteKit's client-side hooks (`src/hooks.client.ts`),\n * exposed as the `Hooks` namespace of `@thomasfosterau/effect-sveltekit/client`.\n *\n * These mirror the server hook helpers in `../server/Hooks.ts`, but run on the\n * client: there is no request context, so each effect runs on a bare Effect\n * runtime. For application services, run the effect through your own runtime\n * instead. Kept free of `$app/*` imports so it stays importable (and testable)\n * outside of a SvelteKit app.\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const handleError = Hooks.handleError(({ error, event }) =>\n * Effect.as(Effect.logError(`navigation to ${event.url.pathname} failed`, error), {\n * message: 'Something went wrong',\n * })\n * );\n * ```\n */\n\nimport type { ClientInit, HandleClientError } from \"@sveltejs/kit/hooks\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport { causeToThrowable } from \"../internal/error.js\";\n\n/** Run a bare Effect (no request context) and settle it the way a hook expects. */\nconst runBareHook = async <A>(effect: Effect.Effect<A, unknown>): Promise<A> =>\n Exit.match(await Effect.runPromiseExit(effect), {\n onFailure: (cause) => {\n throw causeToThrowable(cause);\n },\n onSuccess: (value) => value,\n });\n\n/**\n * Wraps an Effect-based function as the SvelteKit client\n * [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError)\n * hook, which runs when an unexpected error is thrown while navigating in the\n * browser. The effect receives the error and navigation event and produces the\n * shape exposed to the page (your `App.Error`, or nothing).\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const handleError = Hooks.handleError(({ error, event }) =>\n * Effect.gen(function* () {\n * yield* Effect.logError(`navigation to ${event.url.pathname} failed`, error);\n * return { message: 'Something went wrong' };\n * })\n * );\n * ```\n */\nexport function handleError(\n fn: (\n args: Parameters<HandleClientError>[0],\n ) => Effect.Effect<Awaited<ReturnType<HandleClientError>>, unknown>,\n): HandleClientError {\n return (args) => runBareHook(fn(args));\n}\n\n/**\n * Wraps an Effect as the SvelteKit client\n * [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) hook, which\n * runs once when the app starts in the browser. The effect runs on a bare\n * Effect runtime.\n *\n * @example\n * ```ts\n * // src/hooks.client.ts\n * import { Hooks } from '@thomasfosterau/effect-sveltekit/client';\n * import { Effect } from 'effect';\n *\n * export const init = Hooks.init(Effect.logInfo('client app started'));\n * ```\n */\nexport function init(effect: Effect.Effect<void, unknown>): ClientInit {\n return () => runBareHook(effect);\n}\n"],"mappings":";;;;;;;;;;AA8BA,MAAM,cAAc,OAAU,WAC5B,KAAK,MAAM,MAAM,OAAO,eAAe,MAAM,GAAG;CAC9C,YAAY,UAAU;EACpB,MAAM,iBAAiB,KAAK;CAC9B;CACA,YAAY,UAAU;AACxB,CAAC;;;;;;;;;;;;;;;;;;;;;;AAuBH,SAAgB,YACd,IAGmB;CACnB,QAAQ,SAAS,YAAY,GAAG,IAAI,CAAC;AACvC;;;;;;;;;;;;;;;;AAiBA,SAAgB,KAAK,QAAkD;CACrE,aAAa,YAAY,MAAM;AACjC"}
package/dist/client.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Navigation_d_exports } from "./Navigation.js";
2
2
  import { State_d_exports } from "./State.js";
3
3
  import { Remote_d_exports } from "./Remote.js";
4
- import { useRemoteQuery } from "./remote-reactive.js";
4
+ import { RemoteQueryResult, useRemoteQuery } from "./remote-reactive.js";
5
5
  import { realtime_d_exports } from "./realtime.js";
6
6
  import { forms_d_exports } from "./forms.js";
7
7
  import { Hooks_d_exports } from "./client/Hooks.js";
8
- export { forms_d_exports as Forms, Hooks_d_exports as Hooks, Navigation_d_exports as Navigation, realtime_d_exports as Realtime, Remote_d_exports as Remote, State_d_exports as State, useRemoteQuery };
8
+ export { forms_d_exports as Forms, Hooks_d_exports as Hooks, Navigation_d_exports as Navigation, realtime_d_exports as Realtime, Remote_d_exports as Remote, type RemoteQueryResult, State_d_exports as State, useRemoteQuery };
package/dist/config.d.ts CHANGED
@@ -1,16 +1,19 @@
1
- import { Config, ConfigProvider, Effect, Layer } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as ConfigProvider from "effect/ConfigProvider";
4
+ import * as Config from "effect/Config";
2
5
  //#region src/config.d.ts
3
6
  /**
4
7
  * Creates a {@link ConfigProvider} backed by a SvelteKit env record (e.g. the
5
8
  * `env` export of `$env/dynamic/private`, or `import.meta.env`-style objects).
6
9
  */
7
- declare const sveltekitConfigProvider: (env: Record<string, string | undefined>) => ConfigProvider.ConfigProvider;
10
+ export declare const sveltekitConfigProvider: (env: Record<string, string | undefined>) => ConfigProvider.ConfigProvider;
8
11
  /**
9
12
  * Creates a `Layer` that installs {@link sveltekitConfigProvider} as the
10
13
  * ambient config provider. Provide it to a server/universal runtime so the
11
14
  * application layer's `Config` reads resolve from SvelteKit's environment.
12
15
  */
13
- declare const sveltekitConfig: (env: Record<string, string | undefined>) => Layer.Layer<never>;
16
+ export declare const sveltekitConfig: (env: Record<string, string | undefined>) => Layer.Layer<never>;
14
17
  /**
15
18
  * Read a typed {@link Config} value directly from a SvelteKit env record, in
16
19
  * one call — the typed bridge for reading configuration without wiring a
@@ -41,7 +44,6 @@ declare const sveltekitConfig: (env: Record<string, string | undefined>) => Laye
41
44
  * // settings: Effect<{ apiUrl: string; analytics: string }, ConfigError>
42
45
  * ```
43
46
  */
44
- declare const readConfig: <A>(env: Record<string, string | undefined>, config: Config.Config<A>) => Effect.Effect<A, Config.ConfigError>;
47
+ export declare const readConfig: <A>(env: Record<string, string | undefined>, config: Config.Config<A>) => Effect.Effect<A, Config.ConfigError>;
45
48
  //#endregion
46
- export { readConfig, sveltekitConfig, sveltekitConfigProvider };
47
49
  //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -1,39 +1,10 @@
1
- import { ConfigProvider, Effect } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Predicate from "effect/Predicate";
3
+ import * as Rec from "effect/Record";
4
+ import * as ConfigProvider from "effect/ConfigProvider";
2
5
  //#region src/config.ts
3
- /**
4
- * SvelteKit `$env` ⇄ Effect `Config`.
5
- *
6
- * Effect services read configuration through {@link Config} / a
7
- * {@link ConfigProvider}, while SvelteKit exposes configuration through its
8
- * `$env/static/*` and `$env/dynamic/*` virtual modules. These helpers bridge
9
- * the two: pass a SvelteKit env record and get back a `ConfigProvider` (or a
10
- * `Layer` that installs it), so any `Config.String("DATABASE_URL")` resolves
11
- * from SvelteKit's environment.
12
- *
13
- * ```ts
14
- * // src/lib/server/runtime.ts
15
- * import { env } from "$env/dynamic/private";
16
- * import { sveltekitConfig } from "@thomasfosterau/effect-sveltekit/server";
17
- * import { makeServerRuntime } from "@thomasfosterau/effect-sveltekit/server";
18
- * import { Layer } from "effect";
19
- * import { Database } from "./database";
20
- *
21
- * export const runtime = makeServerRuntime(
22
- * // Database.layer reads Config.String("DATABASE_URL"), now backed by $env
23
- * Database.layer.pipe(Layer.provide(sveltekitConfig(env))),
24
- * );
25
- * ```
26
- *
27
- * `ConfigProvider.fromEnv` joins/splits path segments on `_`, so nested config
28
- * (`Config.String("HOST").pipe(...nested("DATABASE"))`) resolves a
29
- * `DATABASE_HOST` env var just like it does from `process.env`.
30
- */
31
6
  /** Drop `undefined` values so the record satisfies `ConfigProvider.fromEnv`. */
32
- const definedEntries = (env) => {
33
- const out = {};
34
- for (const [key, value] of Object.entries(env)) if (value !== void 0) out[key] = value;
35
- return out;
36
- };
7
+ const definedEntries = (env) => Rec.filter(env, Predicate.isNotUndefined);
37
8
  /**
38
9
  * Creates a {@link ConfigProvider} backed by a SvelteKit env record (e.g. the
39
10
  * `env` export of `$env/dynamic/private`, or `import.meta.env`-style objects).
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["/**\n * SvelteKit `$env` ⇄ Effect `Config`.\n *\n * Effect services read configuration through {@link Config} / a\n * {@link ConfigProvider}, while SvelteKit exposes configuration through its\n * `$env/static/*` and `$env/dynamic/*` virtual modules. These helpers bridge\n * the two: pass a SvelteKit env record and get back a `ConfigProvider` (or a\n * `Layer` that installs it), so any `Config.String(\"DATABASE_URL\")` resolves\n * from SvelteKit's environment.\n *\n * ```ts\n * // src/lib/server/runtime.ts\n * import { env } from \"$env/dynamic/private\";\n * import { sveltekitConfig } from \"@thomasfosterau/effect-sveltekit/server\";\n * import { makeServerRuntime } from \"@thomasfosterau/effect-sveltekit/server\";\n * import { Layer } from \"effect\";\n * import { Database } from \"./database\";\n *\n * export const runtime = makeServerRuntime(\n * // Database.layer reads Config.String(\"DATABASE_URL\"), now backed by $env\n * Database.layer.pipe(Layer.provide(sveltekitConfig(env))),\n * );\n * ```\n *\n * `ConfigProvider.fromEnv` joins/splits path segments on `_`, so nested config\n * (`Config.String(\"HOST\").pipe(...nested(\"DATABASE\"))`) resolves a\n * `DATABASE_HOST` env var just like it does from `process.env`.\n */\n\nimport { type Config, ConfigProvider, Effect, type Layer } from \"effect\";\n\n/** Drop `undefined` values so the record satisfies `ConfigProvider.fromEnv`. */\nconst definedEntries = (env: Record<string, string | undefined>): Record<string, string> => {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(env)) {\n if (value !== undefined) out[key] = value;\n }\n return out;\n};\n\n/**\n * Creates a {@link ConfigProvider} backed by a SvelteKit env record (e.g. the\n * `env` export of `$env/dynamic/private`, or `import.meta.env`-style objects).\n */\nexport const sveltekitConfigProvider = (\n env: Record<string, string | undefined>,\n): ConfigProvider.ConfigProvider => ConfigProvider.fromEnv({ env: definedEntries(env) });\n\n/**\n * Creates a `Layer` that installs {@link sveltekitConfigProvider} as the\n * ambient config provider. Provide it to a server/universal runtime so the\n * application layer's `Config` reads resolve from SvelteKit's environment.\n */\nexport const sveltekitConfig = (env: Record<string, string | undefined>): Layer.Layer<never> =>\n ConfigProvider.layer(sveltekitConfigProvider(env));\n\n/**\n * Read a typed {@link Config} value directly from a SvelteKit env record, in\n * one call — the typed bridge for reading configuration without wiring a\n * provider into a runtime first.\n *\n * Which `$env` module you pass decides *when* the value is resolved:\n *\n * - `$env/static/public` / `$env/static/private` are **build-time** — inlined\n * and fixed for the deployment (public values are safe in client bundles).\n * - `$env/dynamic/public` / `$env/dynamic/private` are **runtime** — read from\n * the process environment per request, so they can change between deploys of\n * the same build.\n *\n * @example\n * ```ts\n * // Build-time public config (usable on the client)\n * import { env } from \"$env/static/public\";\n * import { readConfig } from \"@thomasfosterau/effect-sveltekit\";\n * import { Config, Effect } from \"effect\";\n *\n * const settings = readConfig(\n * env,\n * Config.all({\n * apiUrl: Config.String(\"PUBLIC_API_URL\"),\n * analytics: Config.String(\"PUBLIC_ANALYTICS_KEY\").pipe(Config.withDefault(\"\")),\n * }),\n * );\n * // settings: Effect<{ apiUrl: string; analytics: string }, ConfigError>\n * ```\n */\nexport const readConfig = <A>(\n env: Record<string, string | undefined>,\n config: Config.Config<A>,\n): Effect.Effect<A, Config.ConfigError> => Effect.provide(config, sveltekitConfig(env));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,kBAAkB,QAAoE;CAC1F,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,GAAG,GAC3C,IAAI,UAAU,KAAA,GAAW,IAAI,OAAO;CAEtC,OAAO;AACT;;;;;AAMA,MAAa,2BACX,QACkC,eAAe,QAAQ,EAAE,KAAK,eAAe,GAAG,EAAE,CAAC;;;;;;AAOvF,MAAa,mBAAmB,QAC9B,eAAe,MAAM,wBAAwB,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCnD,MAAa,cACX,KACA,WACyC,OAAO,QAAQ,QAAQ,gBAAgB,GAAG,CAAC"}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["/**\n * SvelteKit `$env` ⇄ Effect `Config`.\n *\n * Effect services read configuration through {@link Config} / a\n * {@link ConfigProvider}, while SvelteKit exposes configuration through its\n * `$env/static/*` and `$env/dynamic/*` virtual modules. These helpers bridge\n * the two: pass a SvelteKit env record and get back a `ConfigProvider` (or a\n * `Layer` that installs it), so any `Config.String(\"DATABASE_URL\")` resolves\n * from SvelteKit's environment.\n *\n * ```ts\n * // src/lib/server/runtime.ts\n * import { env } from \"$env/dynamic/private\";\n * import { sveltekitConfig } from \"@thomasfosterau/effect-sveltekit/server\";\n * import { makeServerRuntime } from \"@thomasfosterau/effect-sveltekit/server\";\n * import { Layer } from \"effect\";\n * import { Database } from \"./database\";\n *\n * export const runtime = makeServerRuntime(\n * // Database.layer reads Config.String(\"DATABASE_URL\"), now backed by $env\n * Database.layer.pipe(Layer.provide(sveltekitConfig(env))),\n * );\n * ```\n *\n * `ConfigProvider.fromEnv` joins/splits path segments on `_`, so nested config\n * (`Config.String(\"HOST\").pipe(...nested(\"DATABASE\"))`) resolves a\n * `DATABASE_HOST` env var just like it does from `process.env`.\n */\n\nimport type * as Config from \"effect/Config\";\nimport * as ConfigProvider from \"effect/ConfigProvider\";\nimport * as Effect from \"effect/Effect\";\nimport type * as Layer from \"effect/Layer\";\nimport * as Predicate from \"effect/Predicate\";\nimport * as Rec from \"effect/Record\";\n\n/** Drop `undefined` values so the record satisfies `ConfigProvider.fromEnv`. */\nconst definedEntries = (env: Record<string, string | undefined>): Record<string, string> =>\n Rec.filter(env, Predicate.isNotUndefined);\n\n/**\n * Creates a {@link ConfigProvider} backed by a SvelteKit env record (e.g. the\n * `env` export of `$env/dynamic/private`, or `import.meta.env`-style objects).\n */\nexport const sveltekitConfigProvider = (\n env: Record<string, string | undefined>,\n): ConfigProvider.ConfigProvider => ConfigProvider.fromEnv({ env: definedEntries(env) });\n\n/**\n * Creates a `Layer` that installs {@link sveltekitConfigProvider} as the\n * ambient config provider. Provide it to a server/universal runtime so the\n * application layer's `Config` reads resolve from SvelteKit's environment.\n */\nexport const sveltekitConfig = (env: Record<string, string | undefined>): Layer.Layer<never> =>\n ConfigProvider.layer(sveltekitConfigProvider(env));\n\n/**\n * Read a typed {@link Config} value directly from a SvelteKit env record, in\n * one call — the typed bridge for reading configuration without wiring a\n * provider into a runtime first.\n *\n * Which `$env` module you pass decides *when* the value is resolved:\n *\n * - `$env/static/public` / `$env/static/private` are **build-time** — inlined\n * and fixed for the deployment (public values are safe in client bundles).\n * - `$env/dynamic/public` / `$env/dynamic/private` are **runtime** — read from\n * the process environment per request, so they can change between deploys of\n * the same build.\n *\n * @example\n * ```ts\n * // Build-time public config (usable on the client)\n * import { env } from \"$env/static/public\";\n * import { readConfig } from \"@thomasfosterau/effect-sveltekit\";\n * import { Config, Effect } from \"effect\";\n *\n * const settings = readConfig(\n * env,\n * Config.all({\n * apiUrl: Config.String(\"PUBLIC_API_URL\"),\n * analytics: Config.String(\"PUBLIC_ANALYTICS_KEY\").pipe(Config.withDefault(\"\")),\n * }),\n * );\n * // settings: Effect<{ apiUrl: string; analytics: string }, ConfigError>\n * ```\n */\nexport const readConfig = <A>(\n env: Record<string, string | undefined>,\n config: Config.Config<A>,\n): Effect.Effect<A, Config.ConfigError> => Effect.provide(config, sveltekitConfig(env));\n"],"mappings":";;;;;;AAqCA,MAAM,kBAAkB,QACtB,IAAI,OAAO,KAAK,UAAU,cAAc;;;;;AAM1C,MAAa,2BACX,QACkC,eAAe,QAAQ,EAAE,KAAK,eAAe,GAAG,EAAE,CAAC;;;;;;AAOvF,MAAa,mBAAmB,QAC9B,eAAe,MAAM,wBAAwB,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCnD,MAAa,cACX,KACA,WACyC,OAAO,QAAQ,QAAQ,gBAAgB,GAAG,CAAC"}