@thomasfosterau/effect-sveltekit 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/Hooks.d.ts +0 -1
- package/dist/Hooks.js +1 -2
- package/dist/Navigation.d.ts +0 -1
- package/dist/Navigation.js +1 -2
- package/dist/Remote.d.ts +0 -1
- package/dist/Remote.js +1 -2
- package/dist/State.d.ts +0 -1
- package/dist/State.js +1 -2
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/adapter/assets.d.ts +0 -2
- package/dist/adapter/assets.js +1 -2
- package/dist/adapter/handler.d.ts +0 -2
- package/dist/adapter/handler.js +1 -2
- package/dist/adapter/index.d.ts +0 -2
- package/dist/adapter/index.js +1 -2
- package/dist/adapter/serve.d.ts +0 -2
- package/dist/adapter/serve.js +1 -2
- package/dist/api-client.d.ts +0 -2
- package/dist/api-client.js +1 -2
- package/dist/app-runtime.d.ts +0 -2
- package/dist/app-runtime.js +1 -2
- package/dist/client/Hooks.d.ts +0 -1
- package/dist/client/Hooks.js +1 -2
- package/dist/config.d.ts +0 -2
- package/dist/config.js +1 -2
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +1 -2
- package/dist/forms.d.ts +0 -1
- package/dist/forms.js +1 -2
- package/dist/internal/app-state.d.ts +0 -2
- package/dist/internal/app-state.js +3 -3
- package/dist/internal/app-state.js.map +1 -1
- package/dist/internal/auto.d.ts +0 -2
- package/dist/internal/auto.js +1 -2
- package/dist/internal/default-runtime.js +1 -2
- package/dist/internal/enhance.d.ts +0 -2
- package/dist/internal/enhance.js +1 -2
- package/dist/internal/error.d.ts +0 -2
- package/dist/internal/error.js +1 -2
- package/dist/internal/navigation-events.js +1 -2
- package/dist/internal/remote-run.d.ts +0 -2
- package/dist/internal/remote-run.js +1 -2
- package/dist/internal/remote-validators.js +1 -2
- package/dist/internal/route-params.d.ts +0 -2
- package/dist/internal/sse.js +1 -2
- package/dist/internal/stream-callback.js +17 -0
- package/dist/internal/stream-callback.js.map +1 -0
- package/dist/internal/watch.svelte.js +1 -2
- package/dist/kit.d.ts +0 -2
- package/dist/kit.js +1 -2
- package/dist/realtime.d.ts +0 -1
- package/dist/realtime.js +4 -4
- package/dist/realtime.js.map +1 -1
- package/dist/remote-functions.d.ts +0 -2
- package/dist/remote-functions.js +1 -2
- package/dist/remote-reactive.d.ts +0 -2
- package/dist/remote-reactive.js +1 -2
- package/dist/request-parse.d.ts +0 -2
- package/dist/request-parse.js +1 -2
- package/dist/request-runtime.d.ts +0 -2
- package/dist/request-runtime.js +1 -2
- package/dist/request-services.d.ts +0 -2
- package/dist/request-services.js +1 -2
- package/dist/response-headers.d.ts +0 -2
- package/dist/response-headers.js +1 -2
- package/dist/runtime.d.ts +0 -2
- package/dist/runtime.js +1 -2
- package/dist/server/Endpoint.d.ts +0 -1
- package/dist/server/Endpoint.js +1 -2
- package/dist/server/Hooks.d.ts +0 -1
- package/dist/server/Hooks.js +1 -2
- package/dist/server.d.ts +0 -2
- package/dist/server.js +1 -2
- package/dist/streamed-load.d.ts +0 -2
- package/dist/streamed-load.js +1 -2
- package/dist/testing.d.ts +0 -2
- package/dist/testing.js +1 -2
- package/dist/transport.d.ts +0 -2
- package/dist/transport.js +1 -2
- package/dist/universal.d.ts +0 -2
- package/dist/universal.js +1 -2
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +1 -2
- package/package.json +9 -9
package/dist/internal/error.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Predicate from "effect/Predicate";
|
|
2
2
|
import { error, isHttpError, isRedirect } from "@sveltejs/kit";
|
|
3
3
|
import * as Cause from "effect/Cause";
|
|
4
|
-
|
|
4
|
+
// src/internal/error.ts
|
|
5
5
|
/**
|
|
6
6
|
* Custom error type that preserves the original Effect Cause.
|
|
7
7
|
*/
|
|
@@ -47,7 +47,6 @@ const throwKitError = (status, body) => {
|
|
|
47
47
|
const { message, ...properties } = body;
|
|
48
48
|
return kitErrorWith(status, Predicate.isString(message) ? message : void 0, properties);
|
|
49
49
|
};
|
|
50
|
-
//#endregion
|
|
51
50
|
export { EffectCauseError, causeToThrowable, throwKitError };
|
|
52
51
|
|
|
53
52
|
//# sourceMappingURL=error.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Stream from "effect/Stream";
|
|
3
3
|
import * as Queue from "effect/Queue";
|
|
4
|
-
|
|
4
|
+
// src/internal/navigation-events.ts
|
|
5
5
|
/**
|
|
6
6
|
* Pure, `$app/navigation`-free core for the navigation-event bridge in
|
|
7
7
|
* `../Navigation.ts`.
|
|
@@ -37,7 +37,6 @@ function registeredStream(register) {
|
|
|
37
37
|
function onNavigateWith(register, fn, runEffect) {
|
|
38
38
|
register((navigation) => runEffect(fn(navigation)));
|
|
39
39
|
}
|
|
40
|
-
//#endregion
|
|
41
40
|
export { onNavigateWith, registeredStream };
|
|
42
41
|
|
|
43
42
|
//# sourceMappingURL=navigation-events.js.map
|
|
@@ -2,7 +2,6 @@ import "../request-runtime.js";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import "effect/Exit";
|
|
4
4
|
import { RemoteFormInvalidField } from "$app/server";
|
|
5
|
-
//#region src/internal/remote-run.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Maps a remote *form* handler's failure into SvelteKit's field issues, given
|
|
8
7
|
* the form's parsed `data` and the `issue` helper. It may call `invalid()` so a
|
|
@@ -25,5 +24,4 @@ export interface RunHelpers {
|
|
|
25
24
|
readonly run: Runner;
|
|
26
25
|
readonly runForm: FormRunner;
|
|
27
26
|
}
|
|
28
|
-
//#endregion
|
|
29
27
|
//# sourceMappingURL=remote-run.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SvelteKit } from "../kit.js";
|
|
2
2
|
import * as Exit from "effect/Exit";
|
|
3
3
|
import * as Cause from "effect/Cause";
|
|
4
|
-
|
|
4
|
+
// src/internal/remote-run.ts
|
|
5
5
|
/** The default translator: Kit control-flow errors through, anything else a 500. */
|
|
6
6
|
const defaultTranslate = SvelteKit.translate;
|
|
7
7
|
/**
|
|
@@ -28,7 +28,6 @@ const makeRunHelpers = (resolve, translate, formError) => {
|
|
|
28
28
|
runForm
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
//#endregion
|
|
32
31
|
export { defaultTranslate, makeRunHelpers };
|
|
33
32
|
|
|
34
33
|
//# sourceMappingURL=remote-run.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Predicate from "effect/Predicate";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
|
|
3
|
+
// src/internal/remote-validators.ts
|
|
4
4
|
/**
|
|
5
5
|
* Detects a Standard Schema validator via its `~standard` marker property.
|
|
6
6
|
*
|
|
@@ -18,7 +18,6 @@ const isBareHandler = (value) => Predicate.isFunction(value) && !isStandardSchem
|
|
|
18
18
|
* or the `"unchecked"` marker passes through untouched.
|
|
19
19
|
*/
|
|
20
20
|
const toStandardValidator = (value) => Schema.isSchema(value) ? Schema.toStandardSchemaV1(value) : value;
|
|
21
|
-
//#endregion
|
|
22
21
|
export { isBareHandler, isStandardSchema, toStandardValidator };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=remote-validators.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RequestEvent } from "@sveltejs/kit";
|
|
2
|
-
//#region src/internal/route-params.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* The route-parameter constraint SvelteKit uses for its own handler types
|
|
5
4
|
* (`RequestEvent`, `ServerLoad`, `Load`, `Action`, `RequestHandler`) — the
|
|
@@ -17,5 +16,4 @@ import { RequestEvent } from "@sveltejs/kit";
|
|
|
17
16
|
* exactly as SvelteKit's own `AppLayoutParams<'/'>` does.
|
|
18
17
|
*/
|
|
19
18
|
export type SvelteRouteParams = RequestEvent["params"];
|
|
20
|
-
//#endregion
|
|
21
19
|
//# sourceMappingURL=route-params.d.ts.map
|
package/dist/internal/sse.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Arr from "effect/Array";
|
|
2
|
-
|
|
2
|
+
// src/internal/sse.ts
|
|
3
3
|
/**
|
|
4
4
|
* Server-Sent Events framing helpers, factored out of the endpoint wrapper so
|
|
5
5
|
* the wire format can be unit-tested in isolation.
|
|
@@ -32,7 +32,6 @@ const encodeSseFrame = (frame) => {
|
|
|
32
32
|
const encodeRetry = (milliseconds) => `retry: ${milliseconds}\n\n`;
|
|
33
33
|
/** A comment line used as a heartbeat/keepalive (ignored by the client). */
|
|
34
34
|
const HEARTBEAT_FRAME = ": heartbeat\n\n";
|
|
35
|
-
//#endregion
|
|
36
35
|
export { HEARTBEAT_FRAME, SSE_HEADERS, encodeRetry, encodeSseFrame };
|
|
37
36
|
|
|
38
37
|
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Queue from "effect/Queue";
|
|
3
|
+
// src/internal/stream-callback.ts
|
|
4
|
+
/**
|
|
5
|
+
* Forwards a failed `Stream.callback` setup to the stream's queue, so the
|
|
6
|
+
* stream ends with the setup's cause: a typed failure fails the stream and a
|
|
7
|
+
* throw caught by `Effect.sync` makes it die. Up to `effect@4.0.1`,
|
|
8
|
+
* `Stream.callback` forked the setup Effect and dropped its cause, so the stream
|
|
9
|
+
* hung instead; later versions forward the cause themselves, and this makes
|
|
10
|
+
* every version in the `^4.0.0` peer range behave like them.
|
|
11
|
+
*
|
|
12
|
+
* Use as `Stream.callback((queue) => setup.pipe(failQueueOnSetupError(queue)))`.
|
|
13
|
+
*/
|
|
14
|
+
const failQueueOnSetupError = (queue) => (setup) => Effect.catchCause(setup, (cause) => Queue.failCause(queue, cause));
|
|
15
|
+
export { failQueueOnSetupError };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=stream-callback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-callback.js","names":[],"sources":["../../src/internal/stream-callback.ts"],"sourcesContent":["/**\n * Internal support for `Stream.callback` sites.\n *\n * @internal\n */\n\nimport type * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\n\n/**\n * Forwards a failed `Stream.callback` setup to the stream's queue, so the\n * stream ends with the setup's cause: a typed failure fails the stream and a\n * throw caught by `Effect.sync` makes it die. Up to `effect@4.0.1`,\n * `Stream.callback` forked the setup Effect and dropped its cause, so the stream\n * hung instead; later versions forward the cause themselves, and this makes\n * every version in the `^4.0.0` peer range behave like them.\n *\n * Use as `Stream.callback((queue) => setup.pipe(failQueueOnSetupError(queue)))`.\n */\nexport const failQueueOnSetupError =\n <A, E>(queue: Queue.Queue<A, E | Cause.Done>) =>\n <R>(setup: Effect.Effect<unknown, E, R>): Effect.Effect<unknown, never, R> =>\n Effect.catchCause(setup, (cause) => Queue.failCause(queue, cause));\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAa,yBACJ,WACH,UACF,OAAO,WAAW,QAAQ,UAAU,MAAM,UAAU,OAAO,KAAK,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { untrack } from "svelte";
|
|
2
|
-
|
|
2
|
+
// src/internal/watch.svelte.ts
|
|
3
3
|
/**
|
|
4
4
|
* The one runes-dependent piece of the `$app/state` bridge: watch a reactive
|
|
5
5
|
* read outside any component.
|
|
@@ -27,7 +27,6 @@ function watch(read, onValue) {
|
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
//#endregion
|
|
31
30
|
export { watch };
|
|
32
31
|
|
|
33
32
|
//# sourceMappingURL=watch.svelte.js.map
|
package/dist/kit.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { KitErrorBody } from "./internal/error.js";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Cause from "effect/Cause";
|
|
4
|
-
//#region src/kit.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* An Effect-native redirect. Yield via {@link SvelteKit.redirect}; translated
|
|
7
6
|
* at the request boundary by {@link SvelteKit.translate}.
|
|
@@ -126,5 +125,4 @@ export declare const SvelteKit: {
|
|
|
126
125
|
*/
|
|
127
126
|
readonly makeTranslator: (extraCases: ReadonlyArray<KitTranslatorCase>) => KitErrorTranslator;
|
|
128
127
|
};
|
|
129
|
-
//#endregion
|
|
130
128
|
//# sourceMappingURL=kit.d.ts.map
|
package/dist/kit.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
|
|
|
3
3
|
import { fail, redirect } from "@sveltejs/kit";
|
|
4
4
|
import * as Arr from "effect/Array";
|
|
5
5
|
import * as Cause from "effect/Cause";
|
|
6
|
-
|
|
6
|
+
// src/kit.ts
|
|
7
7
|
/**
|
|
8
8
|
* Effect-native SvelteKit control-flow errors and a turnkey boundary translator.
|
|
9
9
|
*
|
|
@@ -183,7 +183,6 @@ const SvelteKit = {
|
|
|
183
183
|
return baseTranslate(cause);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
|
-
//#endregion
|
|
187
186
|
export { KitActionFailure, KitError, KitRedirect, SvelteKit };
|
|
188
187
|
|
|
189
188
|
//# sourceMappingURL=kit.js.map
|
package/dist/realtime.d.ts
CHANGED
|
@@ -119,6 +119,5 @@ export interface FromWebSocketOptions {
|
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
121
|
export declare const fromWebSocket: (url: string, options?: FromWebSocketOptions) => Stream.Stream<string | ArrayBuffer | Blob, WebSocketError>;
|
|
122
|
-
//#endregion
|
|
123
122
|
export { realtime_d_exports };
|
|
124
123
|
//# sourceMappingURL=realtime.d.ts.map
|
package/dist/realtime.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { failQueueOnSetupError } from "./internal/stream-callback.js";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Arr from "effect/Array";
|
|
4
5
|
import * as Cause from "effect/Cause";
|
|
5
6
|
import * as Stream from "effect/Stream";
|
|
6
7
|
import * as Schema from "effect/Schema";
|
|
7
8
|
import * as Queue from "effect/Queue";
|
|
8
|
-
|
|
9
|
+
// src/realtime.ts
|
|
9
10
|
/**
|
|
10
11
|
* Client-side realtime bridges: consume a Server-Sent-Events endpoint or a
|
|
11
12
|
* WebSocket as an Effect `Stream`. The counterpart to `Endpoint.fromStream`
|
|
@@ -76,7 +77,7 @@ const fromEventSource = (url, options) => {
|
|
|
76
77
|
url,
|
|
77
78
|
cause
|
|
78
79
|
})
|
|
79
|
-
}), (source) => Effect.sync(() => source.close())), {
|
|
80
|
+
}), (source) => Effect.sync(() => source.close())).pipe(failQueueOnSetupError(queue)), {
|
|
80
81
|
bufferSize: options?.bufferSize ?? 16,
|
|
81
82
|
strategy: options?.strategy ?? "sliding"
|
|
82
83
|
});
|
|
@@ -144,12 +145,11 @@ const fromWebSocket = (url, options) => {
|
|
|
144
145
|
})
|
|
145
146
|
}), (socket) => Effect.sync(() => {
|
|
146
147
|
if (socket.readyState === 0 || socket.readyState === 1) socket.close();
|
|
147
|
-
})), {
|
|
148
|
+
})).pipe(failQueueOnSetupError(queue)), {
|
|
148
149
|
bufferSize: options?.bufferSize ?? 16,
|
|
149
150
|
strategy: options?.strategy ?? "suspend"
|
|
150
151
|
});
|
|
151
152
|
};
|
|
152
|
-
//#endregion
|
|
153
153
|
export { EventSourceError, WebSocketError, fromEventSource, fromWebSocket, realtime_exports };
|
|
154
154
|
|
|
155
155
|
//# sourceMappingURL=realtime.js.map
|
package/dist/realtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.js","names":[],"sources":["../src/realtime.ts"],"sourcesContent":["/**\n * Client-side realtime bridges: consume a Server-Sent-Events endpoint or a\n * WebSocket as an Effect `Stream`. The counterpart to `Endpoint.fromStream`\n * (server) on the `@thomasfosterau/effect-sveltekit/client` `Realtime` namespace.\n *\n * These use the browser globals `EventSource` / `WebSocket`; both can be\n * overridden (e.g. a Node polyfill, or a fake in tests) via the `implementation`\n * option. The source is opened when the stream is run and closed when its scope\n * closes, so a `Stream.take` / component teardown tears down the connection.\n */\n\nimport * as Arr from \"effect/Array\";\nimport * as Cause from \"effect/Cause\";\nimport * as Schema from \"effect/Schema\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Stream from \"effect/Stream\";\n\n// ---------------------------------------------------------------------------\n// EventSource\n// ---------------------------------------------------------------------------\n\n/** A decoded Server-Sent Event. */\nexport interface SseMessage {\n /** The event name (`\"message\"` for unnamed events). */\n readonly event: string;\n /** The event payload (the joined `data:` lines). */\n readonly data: string;\n /** The last event id seen, or `\"\"` if none. */\n readonly lastEventId: string;\n}\n\n/**\n * Raised when an `EventSource` cannot be opened (its constructor throws, e.g.\n * for an invalid URL; `cause` holds the thrown value) or its connection fails\n * fatally (its `readyState` is `CLOSED`; `cause` is absent).\n */\nexport class EventSourceError extends Schema.TaggedError<EventSourceError>()(\"EventSourceError\", {\n /** The URL the `EventSource` was opened with. */\n url: Schema.String,\n /** What the `EventSource` constructor threw, when that is why the stream failed. */\n cause: Schema.optionalKey(Schema.Defect()),\n}) {}\n\n/** The subset of the `EventSource` constructor this module relies on. */\nexport type EventSourceConstructor = new (\n url: string,\n eventSourceInitDict?: { withCredentials?: boolean },\n) => EventSource;\n\n/** Options for {@link fromEventSource}. */\nexport interface FromEventSourceOptions {\n /** Send credentials (cookies) with the request. Defaults to `false`. */\n readonly withCredentials?: boolean;\n /**\n * Named events to listen for in addition to the default unnamed `message`\n * event. An `Endpoint.fromStream({ event: \"tick\" })` server needs\n * `events: [\"tick\"]` here.\n */\n readonly events?: ReadonlyArray<string>;\n /** Buffer size for the backing queue. Defaults to 16. */\n readonly bufferSize?: number;\n /** Backpressure strategy when the buffer is full. Defaults to `\"sliding\"`. */\n readonly strategy?: \"sliding\" | \"dropping\" | \"suspend\";\n /** Override the `EventSource` constructor (Node polyfill, tests). */\n readonly implementation?: EventSourceConstructor;\n}\n\n/**\n * Consume a Server-Sent-Events endpoint as a `Stream` of {@link SseMessage}.\n *\n * The browser's `EventSource` reconnects automatically after transient drops,\n * so the stream stays live across reconnects. It fails with\n * {@link EventSourceError} when the connection closes fatally, or, with the\n * thrown value as its `cause`, when the `EventSource` constructor throws (e.g.\n * a `SyntaxError` for an invalid URL). The source is closed when the stream's\n * scope closes; one that failed to construct has nothing to close.\n *\n * @example\n * ```ts\n * import { Realtime } from \"@thomasfosterau/effect-sveltekit/client\";\n * import { Effect, Stream } from \"effect\";\n *\n * const program = Realtime.fromEventSource(\"/events\", { events: [\"tick\"] }).pipe(\n * Stream.runForEach((msg) => Effect.log(`${msg.event}: ${msg.data}`)),\n * );\n * ```\n */\nexport const fromEventSource = (\n url: string,\n options?: FromEventSourceOptions,\n): Stream.Stream<SseMessage, EventSourceError> => {\n const Impl: EventSourceConstructor = options?.implementation ?? globalThis.EventSource;\n // Effect v4's `Stream.callback` runs the returned Effect as the stream's\n // setup, inside the stream's scope; it is not a cleanup. Open the source\n // with `acquireRelease` so it is closed when that scope closes.\n return Stream.callback<SseMessage, EventSourceError>(\n (queue) =>\n Effect.acquireRelease(\n // Construct and attach the listeners in one synchronous step, so no\n // event can be dispatched in between; a throw from either (in practice\n // the constructor) becomes the typed error. A failed acquire registers\n // no release: a source that failed to construct has nothing to close.\n Effect.try({\n try: () => {\n const source =\n options?.withCredentials === undefined\n ? new Impl(url)\n : new Impl(url, { withCredentials: options.withCredentials });\n\n const onMessage = (e: MessageEvent): void => {\n Queue.offerUnsafe(queue, { event: e.type, data: e.data, lastEventId: e.lastEventId });\n };\n\n source.addEventListener(\"message\", onMessage);\n Arr.forEach(options?.events ?? [], (name) => source.addEventListener(name, onMessage));\n\n source.addEventListener(\"error\", () => {\n // EventSource reconnects on its own unless it has closed for good.\n if (source.readyState === 2 /* CLOSED */) {\n Queue.failCauseUnsafe(queue, Cause.fail(new EventSourceError({ url })));\n }\n });\n\n return source;\n },\n catch: (cause) => new EventSourceError({ url, cause }),\n }),\n (source) => Effect.sync(() => source.close()),\n ),\n { bufferSize: options?.bufferSize ?? 16, strategy: options?.strategy ?? \"sliding\" },\n );\n};\n\n// ---------------------------------------------------------------------------\n// WebSocket\n// ---------------------------------------------------------------------------\n\n/**\n * Raised when a `WebSocket` cannot be opened (its constructor throws, e.g. for\n * an invalid URL or protocol list; `cause` holds the thrown value), errors, or\n * closes uncleanly (`code` and `reason` come from the close event).\n */\nexport class WebSocketError extends Schema.TaggedError<WebSocketError>()(\"WebSocketError\", {\n /** The URL the `WebSocket` was opened with. */\n url: Schema.String,\n /** The close code, when an unclean close is why the stream failed. */\n code: Schema.optionalKey(Schema.Number),\n /** The close reason, when an unclean close is why the stream failed. */\n reason: Schema.optionalKey(Schema.String),\n /** What the `WebSocket` constructor threw, when that is why the stream failed. */\n cause: Schema.optionalKey(Schema.Defect()),\n}) {}\n\n/** The subset of the `WebSocket` constructor this module relies on. */\nexport type WebSocketConstructor = new (\n url: string,\n protocols?: string | ReadonlyArray<string>,\n) => WebSocket;\n\n/** Options for {@link fromWebSocket}. */\nexport interface FromWebSocketOptions {\n /** Sub-protocols passed to the `WebSocket` constructor. */\n readonly protocols?: string | ReadonlyArray<string>;\n /** `arraybuffer` or `blob` for binary frames. Defaults to the platform default. */\n readonly binaryType?: BinaryType;\n /** Buffer size for the backing queue. Defaults to 16. */\n readonly bufferSize?: number;\n /** Backpressure strategy when the buffer is full. Defaults to `\"suspend\"`. */\n readonly strategy?: \"sliding\" | \"dropping\" | \"suspend\";\n /** Override the `WebSocket` constructor (Node polyfill, tests). */\n readonly implementation?: WebSocketConstructor;\n}\n\n/**\n * Consume a `WebSocket` as a `Stream` of its message payloads\n * (`string | ArrayBuffer | Blob`, depending on `binaryType`).\n *\n * The stream ends when the socket closes cleanly. It fails with\n * {@link WebSocketError} on an error or unclean close, or, with the thrown\n * value as its `cause`, when the `WebSocket` constructor throws (e.g. a\n * `SyntaxError` for an invalid URL or protocol list). The socket is closed when\n * the stream's scope closes; one that failed to construct has nothing to close.\n *\n * @example\n * ```ts\n * import { Realtime } from \"@thomasfosterau/effect-sveltekit/client\";\n * import { Effect, Stream } from \"effect\";\n *\n * const program = Realtime.fromWebSocket(\"wss://example.com/ws\").pipe(\n * Stream.runForEach((data) => Effect.log(String(data))),\n * );\n * ```\n */\nexport const fromWebSocket = (\n url: string,\n options?: FromWebSocketOptions,\n): Stream.Stream<string | ArrayBuffer | Blob, WebSocketError> => {\n // SAFETY: the platform `WebSocket` constructor only reads `protocols`; it is\n // typed as a mutable `string[]`, but a `ReadonlyArray` is equally valid input.\n const Impl = options?.implementation ?? (globalThis.WebSocket as WebSocketConstructor);\n return Stream.callback<string | ArrayBuffer | Blob, WebSocketError>(\n (queue) =>\n Effect.acquireRelease(\n // See `fromEventSource`: construct and attach the listeners in one\n // synchronous step, mapping a throw to the typed error; a failed\n // acquire registers no release.\n Effect.try({\n try: () => {\n const socket = new Impl(url, options?.protocols);\n if (options?.binaryType !== undefined) socket.binaryType = options.binaryType;\n\n socket.addEventListener(\"message\", (e: MessageEvent) => {\n Queue.offerUnsafe(queue, e.data);\n });\n\n socket.addEventListener(\"error\", () => {\n Queue.failCauseUnsafe(queue, Cause.fail(new WebSocketError({ url })));\n });\n\n socket.addEventListener(\"close\", (e: CloseEvent) => {\n if (e.wasClean) {\n Queue.endUnsafe(queue);\n } else {\n Queue.failCauseUnsafe(\n queue,\n Cause.fail(new WebSocketError({ url, code: e.code, reason: e.reason })),\n );\n }\n });\n\n return socket;\n },\n catch: (cause) => new WebSocketError({ url, cause }),\n }),\n (socket) =>\n Effect.sync(() => {\n // Only close a socket that is still connecting/open.\n if (socket.readyState === 0 || socket.readyState === 1) socket.close();\n }),\n ),\n { bufferSize: options?.bufferSize ?? 16, strategy: options?.strategy ?? \"suspend\" },\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;;CAE/F,KAAK,OAAO;;CAEZ,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AA8CJ,MAAa,mBACX,KACA,YACgD;CAChD,MAAM,OAA+B,SAAS,kBAAkB,WAAW;CAI3E,OAAO,OAAO,UACX,UACC,OAAO,eAKL,OAAO,IAAI;EACT,WAAW;GACT,MAAM,SACJ,SAAS,oBAAoB,KAAA,IACzB,IAAI,KAAK,GAAG,IACZ,IAAI,KAAK,KAAK,EAAE,iBAAiB,QAAQ,gBAAgB,CAAC;GAEhE,MAAM,aAAa,MAA0B;IAC3C,MAAM,YAAY,OAAO;KAAE,OAAO,EAAE;KAAM,MAAM,EAAE;KAAM,aAAa,EAAE;IAAY,CAAC;GACtF;GAEA,OAAO,iBAAiB,WAAW,SAAS;GAC5C,IAAI,QAAQ,SAAS,UAAU,CAAC,IAAI,SAAS,OAAO,iBAAiB,MAAM,SAAS,CAAC;GAErF,OAAO,iBAAiB,eAAe;IAErC,IAAI,OAAO,eAAe,GACxB,MAAM,gBAAgB,OAAO,MAAM,KAAK,IAAI,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAC;GAE1E,CAAC;GAED,OAAO;EACT;EACA,QAAQ,UAAU,IAAI,iBAAiB;GAAE;GAAK;EAAM,CAAC;CACvD,CAAC,IACA,WAAW,OAAO,WAAW,OAAO,MAAM,CAAC,CAC9C,GACF;EAAE,YAAY,SAAS,cAAc;EAAI,UAAU,SAAS,YAAY;CAAU,CACpF;AACF;;;;;;AAWA,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CAAC,kBAAkB;;CAEzF,KAAK,OAAO;;CAEZ,MAAM,OAAO,YAAY,OAAO,MAAM;;CAEtC,QAAQ,OAAO,YAAY,OAAO,MAAM;;CAExC,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AA0CJ,MAAa,iBACX,KACA,YAC+D;CAG/D,MAAM,OAAO,SAAS,kBAAmB,WAAW;CACpD,OAAO,OAAO,UACX,UACC,OAAO,eAIL,OAAO,IAAI;EACT,WAAW;GACT,MAAM,SAAS,IAAI,KAAK,KAAK,SAAS,SAAS;GAC/C,IAAI,SAAS,eAAe,KAAA,GAAW,OAAO,aAAa,QAAQ;GAEnE,OAAO,iBAAiB,YAAY,MAAoB;IACtD,MAAM,YAAY,OAAO,EAAE,IAAI;GACjC,CAAC;GAED,OAAO,iBAAiB,eAAe;IACrC,MAAM,gBAAgB,OAAO,MAAM,KAAK,IAAI,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;GACtE,CAAC;GAED,OAAO,iBAAiB,UAAU,MAAkB;IAClD,IAAI,EAAE,UACJ,MAAM,UAAU,KAAK;SAErB,MAAM,gBACJ,OACA,MAAM,KAAK,IAAI,eAAe;KAAE;KAAK,MAAM,EAAE;KAAM,QAAQ,EAAE;IAAO,CAAC,CAAC,CACxE;GAEJ,CAAC;GAED,OAAO;EACT;EACA,QAAQ,UAAU,IAAI,eAAe;GAAE;GAAK;EAAM,CAAC;CACrD,CAAC,IACA,WACC,OAAO,WAAW;EAEhB,IAAI,OAAO,eAAe,KAAK,OAAO,eAAe,GAAG,OAAO,MAAM;CACvE,CAAC,CACL,GACF;EAAE,YAAY,SAAS,cAAc;EAAI,UAAU,SAAS,YAAY;CAAU,CACpF;AACF"}
|
|
1
|
+
{"version":3,"file":"realtime.js","names":[],"sources":["../src/realtime.ts"],"sourcesContent":["/**\n * Client-side realtime bridges: consume a Server-Sent-Events endpoint or a\n * WebSocket as an Effect `Stream`. The counterpart to `Endpoint.fromStream`\n * (server) on the `@thomasfosterau/effect-sveltekit/client` `Realtime` namespace.\n *\n * These use the browser globals `EventSource` / `WebSocket`; both can be\n * overridden (e.g. a Node polyfill, or a fake in tests) via the `implementation`\n * option. The source is opened when the stream is run and closed when its scope\n * closes, so a `Stream.take` / component teardown tears down the connection.\n */\n\nimport * as Arr from \"effect/Array\";\nimport * as Cause from \"effect/Cause\";\nimport * as Schema from \"effect/Schema\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Stream from \"effect/Stream\";\nimport { failQueueOnSetupError } from \"./internal/stream-callback.js\";\n\n// ---------------------------------------------------------------------------\n// EventSource\n// ---------------------------------------------------------------------------\n\n/** A decoded Server-Sent Event. */\nexport interface SseMessage {\n /** The event name (`\"message\"` for unnamed events). */\n readonly event: string;\n /** The event payload (the joined `data:` lines). */\n readonly data: string;\n /** The last event id seen, or `\"\"` if none. */\n readonly lastEventId: string;\n}\n\n/**\n * Raised when an `EventSource` cannot be opened (its constructor throws, e.g.\n * for an invalid URL; `cause` holds the thrown value) or its connection fails\n * fatally (its `readyState` is `CLOSED`; `cause` is absent).\n */\nexport class EventSourceError extends Schema.TaggedError<EventSourceError>()(\"EventSourceError\", {\n /** The URL the `EventSource` was opened with. */\n url: Schema.String,\n /** What the `EventSource` constructor threw, when that is why the stream failed. */\n cause: Schema.optionalKey(Schema.Defect()),\n}) {}\n\n/** The subset of the `EventSource` constructor this module relies on. */\nexport type EventSourceConstructor = new (\n url: string,\n eventSourceInitDict?: { withCredentials?: boolean },\n) => EventSource;\n\n/** Options for {@link fromEventSource}. */\nexport interface FromEventSourceOptions {\n /** Send credentials (cookies) with the request. Defaults to `false`. */\n readonly withCredentials?: boolean;\n /**\n * Named events to listen for in addition to the default unnamed `message`\n * event. An `Endpoint.fromStream({ event: \"tick\" })` server needs\n * `events: [\"tick\"]` here.\n */\n readonly events?: ReadonlyArray<string>;\n /** Buffer size for the backing queue. Defaults to 16. */\n readonly bufferSize?: number;\n /** Backpressure strategy when the buffer is full. Defaults to `\"sliding\"`. */\n readonly strategy?: \"sliding\" | \"dropping\" | \"suspend\";\n /** Override the `EventSource` constructor (Node polyfill, tests). */\n readonly implementation?: EventSourceConstructor;\n}\n\n/**\n * Consume a Server-Sent-Events endpoint as a `Stream` of {@link SseMessage}.\n *\n * The browser's `EventSource` reconnects automatically after transient drops,\n * so the stream stays live across reconnects. It fails with\n * {@link EventSourceError} when the connection closes fatally, or, with the\n * thrown value as its `cause`, when the `EventSource` constructor throws (e.g.\n * a `SyntaxError` for an invalid URL). The source is closed when the stream's\n * scope closes; one that failed to construct has nothing to close.\n *\n * @example\n * ```ts\n * import { Realtime } from \"@thomasfosterau/effect-sveltekit/client\";\n * import { Effect, Stream } from \"effect\";\n *\n * const program = Realtime.fromEventSource(\"/events\", { events: [\"tick\"] }).pipe(\n * Stream.runForEach((msg) => Effect.log(`${msg.event}: ${msg.data}`)),\n * );\n * ```\n */\nexport const fromEventSource = (\n url: string,\n options?: FromEventSourceOptions,\n): Stream.Stream<SseMessage, EventSourceError> => {\n const Impl: EventSourceConstructor = options?.implementation ?? globalThis.EventSource;\n // Effect v4's `Stream.callback` runs the returned Effect as the stream's\n // setup, inside the stream's scope; it is not a cleanup. Open the source\n // with `acquireRelease` so it is closed when that scope closes.\n return Stream.callback<SseMessage, EventSourceError>(\n (queue) =>\n Effect.acquireRelease(\n // Construct and attach the listeners in one synchronous step, so no\n // event can be dispatched in between; a throw from either (in practice\n // the constructor) becomes the typed error. A failed acquire registers\n // no release: a source that failed to construct has nothing to close.\n Effect.try({\n try: () => {\n const source =\n options?.withCredentials === undefined\n ? new Impl(url)\n : new Impl(url, { withCredentials: options.withCredentials });\n\n const onMessage = (e: MessageEvent): void => {\n Queue.offerUnsafe(queue, { event: e.type, data: e.data, lastEventId: e.lastEventId });\n };\n\n source.addEventListener(\"message\", onMessage);\n Arr.forEach(options?.events ?? [], (name) => source.addEventListener(name, onMessage));\n\n source.addEventListener(\"error\", () => {\n // EventSource reconnects on its own unless it has closed for good.\n if (source.readyState === 2 /* CLOSED */) {\n Queue.failCauseUnsafe(queue, Cause.fail(new EventSourceError({ url })));\n }\n });\n\n return source;\n },\n catch: (cause) => new EventSourceError({ url, cause }),\n }),\n (source) => Effect.sync(() => source.close()),\n ).pipe(failQueueOnSetupError(queue)),\n { bufferSize: options?.bufferSize ?? 16, strategy: options?.strategy ?? \"sliding\" },\n );\n};\n\n// ---------------------------------------------------------------------------\n// WebSocket\n// ---------------------------------------------------------------------------\n\n/**\n * Raised when a `WebSocket` cannot be opened (its constructor throws, e.g. for\n * an invalid URL or protocol list; `cause` holds the thrown value), errors, or\n * closes uncleanly (`code` and `reason` come from the close event).\n */\nexport class WebSocketError extends Schema.TaggedError<WebSocketError>()(\"WebSocketError\", {\n /** The URL the `WebSocket` was opened with. */\n url: Schema.String,\n /** The close code, when an unclean close is why the stream failed. */\n code: Schema.optionalKey(Schema.Number),\n /** The close reason, when an unclean close is why the stream failed. */\n reason: Schema.optionalKey(Schema.String),\n /** What the `WebSocket` constructor threw, when that is why the stream failed. */\n cause: Schema.optionalKey(Schema.Defect()),\n}) {}\n\n/** The subset of the `WebSocket` constructor this module relies on. */\nexport type WebSocketConstructor = new (\n url: string,\n protocols?: string | ReadonlyArray<string>,\n) => WebSocket;\n\n/** Options for {@link fromWebSocket}. */\nexport interface FromWebSocketOptions {\n /** Sub-protocols passed to the `WebSocket` constructor. */\n readonly protocols?: string | ReadonlyArray<string>;\n /** `arraybuffer` or `blob` for binary frames. Defaults to the platform default. */\n readonly binaryType?: BinaryType;\n /** Buffer size for the backing queue. Defaults to 16. */\n readonly bufferSize?: number;\n /** Backpressure strategy when the buffer is full. Defaults to `\"suspend\"`. */\n readonly strategy?: \"sliding\" | \"dropping\" | \"suspend\";\n /** Override the `WebSocket` constructor (Node polyfill, tests). */\n readonly implementation?: WebSocketConstructor;\n}\n\n/**\n * Consume a `WebSocket` as a `Stream` of its message payloads\n * (`string | ArrayBuffer | Blob`, depending on `binaryType`).\n *\n * The stream ends when the socket closes cleanly. It fails with\n * {@link WebSocketError} on an error or unclean close, or, with the thrown\n * value as its `cause`, when the `WebSocket` constructor throws (e.g. a\n * `SyntaxError` for an invalid URL or protocol list). The socket is closed when\n * the stream's scope closes; one that failed to construct has nothing to close.\n *\n * @example\n * ```ts\n * import { Realtime } from \"@thomasfosterau/effect-sveltekit/client\";\n * import { Effect, Stream } from \"effect\";\n *\n * const program = Realtime.fromWebSocket(\"wss://example.com/ws\").pipe(\n * Stream.runForEach((data) => Effect.log(String(data))),\n * );\n * ```\n */\nexport const fromWebSocket = (\n url: string,\n options?: FromWebSocketOptions,\n): Stream.Stream<string | ArrayBuffer | Blob, WebSocketError> => {\n // SAFETY: the platform `WebSocket` constructor only reads `protocols`; it is\n // typed as a mutable `string[]`, but a `ReadonlyArray` is equally valid input.\n const Impl = options?.implementation ?? (globalThis.WebSocket as WebSocketConstructor);\n return Stream.callback<string | ArrayBuffer | Blob, WebSocketError>(\n (queue) =>\n Effect.acquireRelease(\n // See `fromEventSource`: construct and attach the listeners in one\n // synchronous step, mapping a throw to the typed error; a failed\n // acquire registers no release.\n Effect.try({\n try: () => {\n const socket = new Impl(url, options?.protocols);\n if (options?.binaryType !== undefined) socket.binaryType = options.binaryType;\n\n socket.addEventListener(\"message\", (e: MessageEvent) => {\n Queue.offerUnsafe(queue, e.data);\n });\n\n socket.addEventListener(\"error\", () => {\n Queue.failCauseUnsafe(queue, Cause.fail(new WebSocketError({ url })));\n });\n\n socket.addEventListener(\"close\", (e: CloseEvent) => {\n if (e.wasClean) {\n Queue.endUnsafe(queue);\n } else {\n Queue.failCauseUnsafe(\n queue,\n Cause.fail(new WebSocketError({ url, code: e.code, reason: e.reason })),\n );\n }\n });\n\n return socket;\n },\n catch: (cause) => new WebSocketError({ url, cause }),\n }),\n (socket) =>\n Effect.sync(() => {\n // Only close a socket that is still connecting/open.\n if (socket.readyState === 0 || socket.readyState === 1) socket.close();\n }),\n ).pipe(failQueueOnSetupError(queue)),\n { bufferSize: options?.bufferSize ?? 16, strategy: options?.strategy ?? \"suspend\" },\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB;;CAE/F,KAAK,OAAO;;CAEZ,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AA8CJ,MAAa,mBACX,KACA,YACgD;CAChD,MAAM,OAA+B,SAAS,kBAAkB,WAAW;CAI3E,OAAO,OAAO,UACX,UACC,OAAO,eAKL,OAAO,IAAI;EACT,WAAW;GACT,MAAM,SACJ,SAAS,oBAAoB,KAAA,IACzB,IAAI,KAAK,GAAG,IACZ,IAAI,KAAK,KAAK,EAAE,iBAAiB,QAAQ,gBAAgB,CAAC;GAEhE,MAAM,aAAa,MAA0B;IAC3C,MAAM,YAAY,OAAO;KAAE,OAAO,EAAE;KAAM,MAAM,EAAE;KAAM,aAAa,EAAE;IAAY,CAAC;GACtF;GAEA,OAAO,iBAAiB,WAAW,SAAS;GAC5C,IAAI,QAAQ,SAAS,UAAU,CAAC,IAAI,SAAS,OAAO,iBAAiB,MAAM,SAAS,CAAC;GAErF,OAAO,iBAAiB,eAAe;IAErC,IAAI,OAAO,eAAe,GACxB,MAAM,gBAAgB,OAAO,MAAM,KAAK,IAAI,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAC;GAE1E,CAAC;GAED,OAAO;EACT;EACA,QAAQ,UAAU,IAAI,iBAAiB;GAAE;GAAK;EAAM,CAAC;CACvD,CAAC,IACA,WAAW,OAAO,WAAW,OAAO,MAAM,CAAC,CAC9C,CAAC,CAAC,KAAK,sBAAsB,KAAK,CAAC,GACrC;EAAE,YAAY,SAAS,cAAc;EAAI,UAAU,SAAS,YAAY;CAAU,CACpF;AACF;;;;;;AAWA,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CAAC,kBAAkB;;CAEzF,KAAK,OAAO;;CAEZ,MAAM,OAAO,YAAY,OAAO,MAAM;;CAEtC,QAAQ,OAAO,YAAY,OAAO,MAAM;;CAExC,OAAO,OAAO,YAAY,OAAO,OAAO,CAAC;AAC3C,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;AA0CJ,MAAa,iBACX,KACA,YAC+D;CAG/D,MAAM,OAAO,SAAS,kBAAmB,WAAW;CACpD,OAAO,OAAO,UACX,UACC,OAAO,eAIL,OAAO,IAAI;EACT,WAAW;GACT,MAAM,SAAS,IAAI,KAAK,KAAK,SAAS,SAAS;GAC/C,IAAI,SAAS,eAAe,KAAA,GAAW,OAAO,aAAa,QAAQ;GAEnE,OAAO,iBAAiB,YAAY,MAAoB;IACtD,MAAM,YAAY,OAAO,EAAE,IAAI;GACjC,CAAC;GAED,OAAO,iBAAiB,eAAe;IACrC,MAAM,gBAAgB,OAAO,MAAM,KAAK,IAAI,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;GACtE,CAAC;GAED,OAAO,iBAAiB,UAAU,MAAkB;IAClD,IAAI,EAAE,UACJ,MAAM,UAAU,KAAK;SAErB,MAAM,gBACJ,OACA,MAAM,KAAK,IAAI,eAAe;KAAE;KAAK,MAAM,EAAE;KAAM,QAAQ,EAAE;IAAO,CAAC,CAAC,CACxE;GAEJ,CAAC;GAED,OAAO;EACT;EACA,QAAQ,UAAU,IAAI,eAAe;GAAE;GAAK;EAAM,CAAC;CACrD,CAAC,IACA,WACC,OAAO,WAAW;EAEhB,IAAI,OAAO,eAAe,KAAK,OAAO,eAAe,GAAG,OAAO,MAAM;CACvE,CAAC,CACL,CAAC,CAAC,KAAK,sBAAsB,KAAK,CAAC,GACrC;EAAE,YAAY,SAAS,cAAc;EAAI,UAAU,SAAS,YAAY;CAAU,CACpF;AACF"}
|
|
@@ -6,7 +6,6 @@ import * as HttpClient from "effect/http/HttpClient";
|
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
7
7
|
import { RemoteCommand, RemoteForm, RemoteFormInput, RemoteFormInvalidField, RemoteLiveQueryFunction, RemotePrerenderFunction, RemoteQueryFunction } from "$app/server";
|
|
8
8
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
|
-
//#region src/remote-functions.d.ts
|
|
10
9
|
type SvelteKitEffectEnv = HttpClient.HttpClient | SvelteKitRequestEvent;
|
|
11
10
|
declare const RemoteFunctionUsageError_base: Schema.Class<RemoteFunctionUsageError, Schema.TaggedStruct<"RemoteFunctionUsageError", {
|
|
12
11
|
readonly message: Schema.String;
|
|
@@ -144,6 +143,5 @@ export declare const RemoteFunction: {
|
|
|
144
143
|
requested: typeof requested;
|
|
145
144
|
withRuntime: typeof withRuntime;
|
|
146
145
|
};
|
|
147
|
-
//#endregion
|
|
148
146
|
export {};
|
|
149
147
|
//# sourceMappingURL=remote-functions.d.ts.map
|
package/dist/remote-functions.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as Predicate from "effect/Predicate";
|
|
|
6
6
|
import "effect/http/HttpClient";
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
8
8
|
import * as AppServer from "$app/server";
|
|
9
|
-
|
|
9
|
+
// src/remote-functions.ts
|
|
10
10
|
/** The default helpers: a fresh SvelteKit per-request runtime, passthrough translation. */
|
|
11
11
|
const defaultHelpers = makeRunHelpers(() => {
|
|
12
12
|
const event = AppServer.getRequestEvent();
|
|
@@ -214,7 +214,6 @@ const RemoteFunction = {
|
|
|
214
214
|
requested,
|
|
215
215
|
withRuntime
|
|
216
216
|
};
|
|
217
|
-
//#endregion
|
|
218
217
|
export { RemoteFunction, RemoteFunctionUsageError, command, form, prerender, query, requested, withRuntime };
|
|
219
218
|
|
|
220
219
|
//# sourceMappingURL=remote-functions.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RemoteResource } from "$app/server";
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
-
//#region src/remote-reactive.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* What {@link useRemoteQuery} returns: the remote resource's state as an
|
|
6
5
|
* {@link AsyncResult.AsyncResult}, read reactively through `current`.
|
|
@@ -37,5 +36,4 @@ export interface RemoteQueryResult<T> {
|
|
|
37
36
|
* ```
|
|
38
37
|
*/
|
|
39
38
|
export declare function useRemoteQuery<T>(query: RemoteResource<T>): RemoteQueryResult<T>;
|
|
40
|
-
//#endregion
|
|
41
39
|
//# sourceMappingURL=remote-reactive.d.ts.map
|
package/dist/remote-reactive.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
|
-
|
|
2
|
+
// src/remote-reactive.ts
|
|
3
3
|
/**
|
|
4
4
|
* Bridges a SvelteKit remote resource (`query(...)`, `query.live(...)`,
|
|
5
5
|
* `prerender(...)`) into Effect's native
|
|
@@ -38,7 +38,6 @@ function useRemoteQuery(query) {
|
|
|
38
38
|
return AsyncResult.initial(loading);
|
|
39
39
|
} };
|
|
40
40
|
}
|
|
41
|
-
//#endregion
|
|
42
41
|
export { useRemoteQuery };
|
|
43
42
|
|
|
44
43
|
//# sourceMappingURL=remote-reactive.js.map
|
package/dist/request-parse.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { SvelteKitRequestEvent } from "./runtime.js";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
|
-
//#region src/request-parse.d.ts
|
|
6
5
|
/** A single issue reported by a Standard Schema validator. */
|
|
7
6
|
export interface ParseIssue {
|
|
8
7
|
readonly message: string;
|
|
@@ -83,6 +82,5 @@ export declare const decodeJson: <O>(schema: Schema.Schema<O> | StandardSchemaV1
|
|
|
83
82
|
* ```
|
|
84
83
|
*/
|
|
85
84
|
export declare const decodeFormData: <O>(schema: Schema.Schema<O> | StandardSchemaV1<unknown, O>) => Effect.Effect<O, ParseError, SvelteKitRequestEvent>;
|
|
86
|
-
//#endregion
|
|
87
85
|
export {};
|
|
88
86
|
//# sourceMappingURL=request-parse.d.ts.map
|
package/dist/request-parse.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
|
|
|
4
4
|
import * as Rec from "effect/Record";
|
|
5
5
|
import * as Arr from "effect/Array";
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
7
|
-
|
|
7
|
+
// src/request-parse.ts
|
|
8
8
|
/** The schema of a {@link ParseIssue}, so {@link ParseError} can carry it. */
|
|
9
9
|
const ParseIssue = Schema.Struct({
|
|
10
10
|
message: Schema.String,
|
|
@@ -129,7 +129,6 @@ const decodeFormData = (schema) => Effect.gen(function* () {
|
|
|
129
129
|
const raw = collectFields(formData.keys(), (key) => Arr.map(formData.getAll(key), String));
|
|
130
130
|
return yield* validate(normalise(schema), raw);
|
|
131
131
|
});
|
|
132
|
-
//#endregion
|
|
133
132
|
export { ParseError, decodeFormData, decodeJson, decodeParams, decodeSearchParams };
|
|
134
133
|
|
|
135
134
|
//# sourceMappingURL=request-parse.js.map
|
|
@@ -7,7 +7,6 @@ import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
|
7
7
|
import { Action, Actions, RequestEvent, RequestHandler, ServerLoad } from "@sveltejs/kit";
|
|
8
8
|
import * as Cause from "effect/Cause";
|
|
9
9
|
import * as Fiber from "effect/Fiber";
|
|
10
|
-
//#region src/request-runtime.d.ts
|
|
11
10
|
/**
|
|
12
11
|
* The runners a {@link RequestRuntimeProvider} resolves for a single request:
|
|
13
12
|
* a way to run an `Effect<A, unknown, R>` that requires the provider's services
|
|
@@ -139,5 +138,4 @@ export interface RuntimeAdapter<R> {
|
|
|
139
138
|
* ```
|
|
140
139
|
*/
|
|
141
140
|
export declare const makeRuntimeAdapter: <R>(provider: RequestRuntimeProvider<R, any>, opts?: RuntimeAdapterOptions) => RuntimeAdapter<R>;
|
|
142
|
-
//#endregion
|
|
143
141
|
//# sourceMappingURL=request-runtime.d.ts.map
|
package/dist/request-runtime.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as Result from "effect/Result";
|
|
|
9
9
|
import { isHttpError, isRedirect } from "@sveltejs/kit";
|
|
10
10
|
import * as Cause from "effect/Cause";
|
|
11
11
|
import * as Console from "effect/Console";
|
|
12
|
-
|
|
12
|
+
// src/request-runtime.ts
|
|
13
13
|
/**
|
|
14
14
|
* A general, Effect-idiomatic way to provide the per-request execution context
|
|
15
15
|
* for SvelteKit server wrappers.
|
|
@@ -180,7 +180,6 @@ const makeRuntimeAdapter = (provider, opts) => {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
};
|
|
183
|
-
//#endregion
|
|
184
183
|
export { RequestRuntime, makeRuntimeAdapter };
|
|
185
184
|
|
|
186
185
|
//# sourceMappingURL=request-runtime.js.map
|
|
@@ -3,7 +3,6 @@ import * as Effect from "effect/Effect";
|
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
5
|
import { Cookies, RequestEvent } from "@sveltejs/kit";
|
|
6
|
-
//#region src/request-services.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* The Effect-native interface exposed by {@link SvelteKitCookies}. Each method
|
|
9
8
|
* mirrors the corresponding `Cookies` method from `@sveltejs/kit` but returns
|
|
@@ -116,6 +115,5 @@ export declare class SvelteKitLocals extends SvelteKitLocals_base {
|
|
|
116
115
|
* already have `SvelteKitRequestEvent` in scope.
|
|
117
116
|
*/
|
|
118
117
|
export declare const requestServicesLayer: Layer.Layer<SvelteKitCookies | SvelteKitResponseHeaders | SvelteKitLocals, never, SvelteKitRequestEvent>;
|
|
119
|
-
//#endregion
|
|
120
118
|
export {};
|
|
121
119
|
//# sourceMappingURL=request-services.d.ts.map
|
package/dist/request-services.js
CHANGED
|
@@ -2,7 +2,7 @@ import { SvelteKitRequestEvent } from "./runtime.js";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
|
-
|
|
5
|
+
// src/request-services.ts
|
|
6
6
|
/**
|
|
7
7
|
* An Effect service wrapping the `RequestEvent.cookies` API.
|
|
8
8
|
*
|
|
@@ -116,7 +116,6 @@ const requestServicesFrom = (event) => {
|
|
|
116
116
|
locals: event.locals
|
|
117
117
|
};
|
|
118
118
|
};
|
|
119
|
-
//#endregion
|
|
120
119
|
export { SvelteKitCookies, SvelteKitLocals, SvelteKitResponseHeaders, requestServicesFrom, requestServicesLayer };
|
|
121
120
|
|
|
122
121
|
//# sourceMappingURL=request-services.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Transporter } from "@sveltejs/kit/hooks";
|
|
2
|
-
//#region src/response-headers.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* A `Headers` that serialises to `{}` and knows how to copy itself onto a
|
|
5
4
|
* response. Everything else is the platform `Headers`.
|
|
@@ -19,5 +18,4 @@ export declare class ResponseHeaders extends globalThis.Headers {
|
|
|
19
18
|
* reconstructed on the client as a fresh, empty buffer.
|
|
20
19
|
*/
|
|
21
20
|
export declare const responseHeadersTransporter: Transporter<ResponseHeaders, unknown>;
|
|
22
|
-
//#endregion
|
|
23
21
|
//# sourceMappingURL=response-headers.d.ts.map
|
package/dist/response-headers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { markerTransporter } from "./transport.js";
|
|
2
2
|
import * as Arr from "effect/Array";
|
|
3
|
-
|
|
3
|
+
// src/response-headers.ts
|
|
4
4
|
/**
|
|
5
5
|
* A `Headers` that serialises to `{}` and knows how to copy itself onto a
|
|
6
6
|
* response. Everything else is the platform `Headers`.
|
|
@@ -30,7 +30,6 @@ const responseHeadersTransporter = markerTransporter({
|
|
|
30
30
|
guard: (value) => value instanceof ResponseHeaders,
|
|
31
31
|
make: () => new ResponseHeaders()
|
|
32
32
|
});
|
|
33
|
-
//#endregion
|
|
34
33
|
export { ResponseHeaders, responseHeadersTransporter };
|
|
35
34
|
|
|
36
35
|
//# sourceMappingURL=response-headers.js.map
|
package/dist/runtime.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import * as Layer from "effect/Layer";
|
|
|
4
4
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
5
5
|
import * as HttpClient from "effect/http/HttpClient";
|
|
6
6
|
import { RequestEvent } from "@sveltejs/kit";
|
|
7
|
-
//#region src/runtime.d.ts
|
|
8
7
|
declare const SvelteKitRequestEvent_base: Context.ServiceClass<SvelteKitRequestEvent, "SvelteKitRequestEvent", RequestEvent<Record<string, string>, string | null>>;
|
|
9
8
|
/**
|
|
10
9
|
* Service that provides access to the current SvelteKit RequestEvent.
|
|
@@ -127,6 +126,5 @@ export declare class SvelteKitRuntime {
|
|
|
127
126
|
* ```
|
|
128
127
|
*/
|
|
129
128
|
export declare function runWithSvelteKitRuntime<A, E>(event: RequestEvent, effect: Effect.Effect<A, E, HttpClient.HttpClient | SvelteKitRequestEvent>): Promise<A>;
|
|
130
|
-
//#endregion
|
|
131
129
|
export {};
|
|
132
130
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as Layer from "effect/Layer";
|
|
|
4
4
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
5
5
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
6
6
|
import "effect/http/HttpClient";
|
|
7
|
-
|
|
7
|
+
// src/runtime.ts
|
|
8
8
|
/**
|
|
9
9
|
* Service that provides access to the current SvelteKit RequestEvent.
|
|
10
10
|
* This allows Effect code to access request-specific data like cookies, headers, etc.
|
|
@@ -140,7 +140,6 @@ var SvelteKitRuntime = class {
|
|
|
140
140
|
function runWithSvelteKitRuntime(event, effect) {
|
|
141
141
|
return SvelteKitRuntime.forRequest(event).runPromise(effect);
|
|
142
142
|
}
|
|
143
|
-
//#endregion
|
|
144
143
|
export { SvelteKitRequestEvent, SvelteKitRuntime, runWithSvelteKitRuntime };
|
|
145
144
|
|
|
146
145
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -196,6 +196,5 @@ export interface FromStreamOptions<A, R = never> {
|
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
198
|
export declare const fromStream: <A, E, R = never>(stream: Stream.Stream<A, E, R>, options?: FromStreamOptions<A, R>) => RequestHandler;
|
|
199
|
-
//#endregion
|
|
200
199
|
export { Endpoint_d_exports };
|
|
201
200
|
//# sourceMappingURL=Endpoint.d.ts.map
|
package/dist/server/Endpoint.js
CHANGED
|
@@ -14,7 +14,7 @@ import * as HttpEffect from "effect/http/HttpEffect";
|
|
|
14
14
|
import * as HttpPlatform from "effect/http/HttpPlatform";
|
|
15
15
|
import * as HttpRouter from "effect/http/HttpRouter";
|
|
16
16
|
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
|
|
17
|
-
|
|
17
|
+
// src/server/Endpoint.ts
|
|
18
18
|
var Endpoint_exports = /* @__PURE__ */ __exportAll({
|
|
19
19
|
fromApi: () => fromApi,
|
|
20
20
|
fromHttpEffect: () => fromHttpEffect,
|
|
@@ -172,7 +172,6 @@ const fromStream = (stream, options) => {
|
|
|
172
172
|
return new Response(body, { headers: { ...SSE_HEADERS } });
|
|
173
173
|
};
|
|
174
174
|
};
|
|
175
|
-
//#endregion
|
|
176
175
|
export { Endpoint_exports, fromApi, fromHttpEffect, fromRouter, fromStream };
|
|
177
176
|
|
|
178
177
|
//# sourceMappingURL=Endpoint.js.map
|
package/dist/server/Hooks.d.ts
CHANGED
package/dist/server/Hooks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { defaultServerRuntime } from "../internal/default-runtime.js";
|
|
3
3
|
import "effect/Effect";
|
|
4
|
-
|
|
4
|
+
// src/server/Hooks.ts
|
|
5
5
|
var Hooks_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
handle: () => handle,
|
|
7
7
|
handleError: () => handleError,
|
|
@@ -102,7 +102,6 @@ function handleError(fn) {
|
|
|
102
102
|
function init(effect) {
|
|
103
103
|
return defaultServerRuntime().init(effect);
|
|
104
104
|
}
|
|
105
|
-
//#endregion
|
|
106
105
|
export { Hooks_exports, handle, handleError, handleFetch, init };
|
|
107
106
|
|
|
108
107
|
//# sourceMappingURL=Hooks.js.map
|
package/dist/server.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { KitActionFailure, KitError, KitErrorTranslator, KitRedirect, KitTransla
|
|
|
15
15
|
import { errors_d_exports } from "./errors.js";
|
|
16
16
|
import * as Effect from "effect/Effect";
|
|
17
17
|
import { Action, Actions, RequestEvent, ServerLoad } from "@sveltejs/kit";
|
|
18
|
-
//#region src/server.d.ts
|
|
19
18
|
/**
|
|
20
19
|
* Wraps an Effect-based function to work as a SvelteKit server load function.
|
|
21
20
|
* The effect has access to platform services (HttpClient, the RequestEvent, etc.)
|
|
@@ -111,6 +110,5 @@ export declare function actions<Params extends SvelteRouteParams = SvelteRoutePa
|
|
|
111
110
|
export declare function endpoint<Params extends SvelteRouteParams = SvelteRouteParams, RouteId extends string | null = any>(fn: (event: RequestEvent<Params, RouteId>) => Effect.Effect<Response, unknown, SvelteKitServices>, options?: {
|
|
112
111
|
exposeErrors?: boolean;
|
|
113
112
|
}): (event: RequestEvent<Params, RouteId>) => Promise<Response>;
|
|
114
|
-
//#endregion
|
|
115
113
|
export { type AdapterEndpointOptions, Endpoint_d_exports as Endpoint, type ErrorTranslator, errors_d_exports as Errors, type FromLayerPerRequestOptions, Hooks_d_exports as Hooks, KitActionFailure, KitError, type KitErrorBody, type KitErrorTranslator, KitRedirect, type KitTranslatorCase, ParseError, type ParseIssue, RemoteFunction, RemoteFunctionUsageError, RequestRuntime, type RequestRuntimeProvider, type RequestRuntimeRunners, ResponseHeaders, type RuntimeAdapter, type RuntimeAdapterOptions, type RequestRuntime$1 as ScopedRequestRuntime, type ServerRuntime, type ServerRuntimeOptions, SvelteKit, SvelteKitCookies, type SvelteKitCookiesInterface, SvelteKitLocals, SvelteKitRequestEvent, SvelteKitResponseHeaders, type SvelteKitResponseHeadersInterface, SvelteKitRuntime, type SvelteKitServices, decodeFormData, decodeJson, decodeParams, decodeSearchParams, defer, makeRuntimeAdapter, makeServerRuntime, requestServicesLayer, runWithSvelteKitRuntime, sveltekitConfig, sveltekitConfigProvider };
|
|
116
114
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.js
CHANGED
|
@@ -17,7 +17,7 @@ import * as Exit from "effect/Exit";
|
|
|
17
17
|
import { isHttpError, isRedirect } from "@sveltejs/kit";
|
|
18
18
|
import * as Cause from "effect/Cause";
|
|
19
19
|
import * as Console from "effect/Console";
|
|
20
|
-
|
|
20
|
+
// src/server.ts
|
|
21
21
|
/**
|
|
22
22
|
* Wraps an Effect-based function to work as a SvelteKit server load function.
|
|
23
23
|
* The effect has access to platform services (HttpClient, the RequestEvent, etc.)
|
|
@@ -132,7 +132,6 @@ function endpoint(fn, options) {
|
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
//#endregion
|
|
136
135
|
export { Endpoint_exports as Endpoint, errors_exports as Errors, Hooks_exports as Hooks, KitActionFailure, KitError, KitRedirect, ParseError, RemoteFunction, RemoteFunctionUsageError, RequestRuntime, ResponseHeaders, SvelteKit, SvelteKitCookies, SvelteKitLocals, SvelteKitRequestEvent, SvelteKitResponseHeaders, SvelteKitRuntime, action, actions, decodeFormData, decodeJson, decodeParams, decodeSearchParams, defer, endpoint, makeRuntimeAdapter, makeServerRuntime, requestServicesLayer, runWithSvelteKitRuntime, serverLoad, sveltekitConfig, sveltekitConfigProvider };
|
|
137
136
|
|
|
138
137
|
//# sourceMappingURL=server.js.map
|
package/dist/streamed-load.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
//#region src/streamed-load.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Capture the current service context and run `effect` in the background,
|
|
5
4
|
* returning the `Promise` immediately so SvelteKit can stream the result.
|
|
@@ -17,5 +16,4 @@ import * as Effect from "effect/Effect";
|
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
18
|
export declare const defer: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<Promise<A>, never, R>;
|
|
20
|
-
//#endregion
|
|
21
19
|
//# sourceMappingURL=streamed-load.d.ts.map
|
package/dist/streamed-load.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
|
|
2
|
+
// src/streamed-load.ts
|
|
3
3
|
/**
|
|
4
4
|
* Helpers for SvelteKit's streamed (deferred-promise) `serverLoad` data.
|
|
5
5
|
*
|
|
@@ -68,7 +68,6 @@ import * as Effect from "effect/Effect";
|
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
const defer = (effect) => Effect.map(Effect.context(), (ctx) => Effect.runPromiseWith(ctx)(effect));
|
|
71
|
-
//#endregion
|
|
72
71
|
export { defer };
|
|
73
72
|
|
|
74
73
|
//# sourceMappingURL=streamed-load.js.map
|