svelte-effect-runtime 3.4.4 → 3.4.6
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/.dist/chunks/{client-5cizmHtc.js → client-CsVu54pU.js} +119 -56
- package/.dist/chunks/client-CsVu54pU.js.map +1 -0
- package/.dist/chunks/{descriptors-OS4VfJuW.js → descriptors-cOe9uRJz.js} +2 -2
- package/.dist/chunks/descriptors-cOe9uRJz.js.map +1 -0
- package/.dist/chunks/{dispatcher-C38yhZRs.js → dispatcher-LtvFKYUp.js} +3 -3
- package/.dist/chunks/dispatcher-LtvFKYUp.js.map +1 -0
- package/.dist/chunks/{dispatcher-DuBLHNa6.js → dispatcher-pHH4JcFR.js} +12 -11
- package/.dist/chunks/dispatcher-pHH4JcFR.js.map +1 -0
- package/.dist/chunks/{errors-0PaWf7Bq.js → errors-Dcf0MVbq.js} +3 -3
- package/.dist/chunks/errors-Dcf0MVbq.js.map +1 -0
- package/.dist/chunks/{runtime-C51Dv3K6.js → runtime-ekkMQ-wL.js} +4 -4
- package/.dist/chunks/runtime-ekkMQ-wL.js.map +1 -0
- package/.dist/chunks/{transform-Cdsx7ygD.js → transform-02e-RvXH.js} +246 -172
- package/.dist/chunks/transform-02e-RvXH.js.map +1 -0
- package/.dist/chunks/{vite-DR3-WaqQ.js → vite-Dkwdtbgj.js} +118 -34
- package/.dist/chunks/vite-Dkwdtbgj.js.map +1 -0
- package/.dist/detect.js.map +1 -1
- package/.dist/dispatcher.d.ts +1 -1
- package/.dist/dispatcher.js +1 -1
- package/.dist/errors.d.ts +1 -1
- package/.dist/internal/generators.js +2 -2
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/markup/promise.js +1 -1
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.js +3 -3
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/index.d.ts +8 -0
- package/.dist/markup/transform/scan.d.ts +20 -0
- package/.dist/markup/transform/types.d.ts +136 -2
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.js +1 -1
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +1 -1
- package/.dist/mod.js +3 -3
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/client/command.d.ts +1 -1
- package/.dist/remote/client/effect.d.ts +15 -1
- package/.dist/remote/client/index.d.ts +1 -1
- package/.dist/remote/client/types.d.ts +3 -1
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.d.ts +8 -5
- package/.dist/remote/server.js +38 -15
- package/.dist/remote/server.js.map +1 -1
- package/.dist/remote/shared.d.ts +126 -0
- package/.dist/remote/shared.js +117 -5
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/transform.js +2 -2
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/types.d.ts +95 -0
- package/.dist/server/control-flow.d.ts +70 -4
- package/.dist/server/effects.d.ts +15 -1
- package/.dist/server/factories.d.ts +128 -9
- package/.dist/server/index.d.ts +2 -2
- package/.dist/server/runtime.d.ts +1 -1
- package/.dist/server/types.d.ts +128 -7
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +40 -23
- package/.dist/server.js.map +1 -1
- package/.dist/vite.js +1 -1
- package/LICENSE +29 -0
- package/package.json +21 -21
- package/.dist/chunks/client-5cizmHtc.js.map +0 -1
- package/.dist/chunks/descriptors-OS4VfJuW.js.map +0 -1
- package/.dist/chunks/dispatcher-C38yhZRs.js.map +0 -1
- package/.dist/chunks/dispatcher-DuBLHNa6.js.map +0 -1
- package/.dist/chunks/errors-0PaWf7Bq.js.map +0 -1
- package/.dist/chunks/runtime-C51Dv3K6.js.map +0 -1
- package/.dist/chunks/transform-Cdsx7ygD.js.map +0 -1
- package/.dist/chunks/vite-DR3-WaqQ.js.map +0 -1
|
@@ -30,16 +30,69 @@ type OptionalFormKeys<Value> = {
|
|
|
30
30
|
*/
|
|
31
31
|
export declare const Query: QueryFactory;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Creates a write-oriented remote command from a no-argument Effect handler.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* export const RebuildCache = Command(() => Effect.succeed("done"));
|
|
38
|
+
* ```
|
|
34
39
|
*
|
|
35
40
|
* @since 2.0.0
|
|
36
|
-
* @param validate_or_handler -
|
|
37
|
-
*
|
|
38
|
-
* @returns A
|
|
41
|
+
* @param validate_or_handler - Effect value or no-argument handler to run on
|
|
42
|
+
* the server when the command is invoked.
|
|
43
|
+
* @returns A command function that yields an Effect when called.
|
|
39
44
|
*/
|
|
40
45
|
export declare function Command<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>): EffectRemoteCommand<void, A, E>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a write-oriented remote command with unchecked input.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* export const SaveDraft = Command("unchecked", (input: { id: string }) =>
|
|
52
|
+
* Effect.succeed(input.id)
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @since 2.0.0
|
|
57
|
+
* @param validate_or_handler - `"unchecked"` sentinel that skips runtime input
|
|
58
|
+
* validation.
|
|
59
|
+
* @param maybe_handler - Handler that receives the caller-provided input.
|
|
60
|
+
* @returns A command function that yields an Effect when called with input.
|
|
61
|
+
*/
|
|
41
62
|
export declare function Command<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>): EffectRemoteCommand<Input, A, E>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a write-oriented remote command validated with an Effect Schema.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* export const SaveUser = Command(Schema.Struct({ id: Schema.String }), ({ id }) =>
|
|
69
|
+
* Effect.succeed({ id, saved: true })
|
|
70
|
+
* );
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @since 2.0.0
|
|
74
|
+
* @param validate_or_handler - Effect Schema used to decode and validate
|
|
75
|
+
* caller input before the handler runs.
|
|
76
|
+
* @param maybe_handler - Handler that receives the decoded schema output.
|
|
77
|
+
* @returns A command function whose caller input is the schema encoded type.
|
|
78
|
+
*/
|
|
42
79
|
export declare function Command<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>): EffectRemoteCommand<SchemaEncodedInput<S>, A, E>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a write-oriented remote command validated with a Standard Schema.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* export const Toggle = Command(standard_schema, (input) =>
|
|
86
|
+
* Effect.succeed(input.enabled)
|
|
87
|
+
* );
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @since 3.0.0
|
|
91
|
+
* @param validate_or_handler - Standard Schema used to validate caller input
|
|
92
|
+
* before the handler runs.
|
|
93
|
+
* @param maybe_handler - Handler that receives the decoded schema output.
|
|
94
|
+
* @returns A command function whose caller input is the schema input type.
|
|
95
|
+
*/
|
|
43
96
|
export declare function Command<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteCommand<StandardSchemaInput<S>, A, E>;
|
|
44
97
|
/**
|
|
45
98
|
* Factory for a remote form handler.
|
|
@@ -67,16 +120,82 @@ export declare function Form<Input extends RemoteFormInput, A, E = never, R = ne
|
|
|
67
120
|
export declare function Form<S extends Schema.Top, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<SchemaInput<S>, A, E, R>): EffectRemoteForm<FormSchemaEncodedInput<S>, A, E>;
|
|
68
121
|
export declare function Form<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteFormHandler<StandardSchemaOutput<S>, A, E, R>): EffectRemoteForm<FormStandardSchemaInput<S>, A, E>;
|
|
69
122
|
/**
|
|
70
|
-
*
|
|
123
|
+
* Creates a prerenderable remote function from a no-argument Effect handler.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* export const GetBuildInfo = Prerender(() => Effect.succeed("ready"));
|
|
128
|
+
* ```
|
|
71
129
|
*
|
|
72
130
|
* @since 2.0.0
|
|
73
|
-
* @param validate_or_handler -
|
|
74
|
-
*
|
|
75
|
-
* @param maybe_options -
|
|
76
|
-
*
|
|
131
|
+
* @param validate_or_handler - Effect value or no-argument handler to run at
|
|
132
|
+
* prerender time.
|
|
133
|
+
* @param maybe_options - Optional prerender inputs and dynamic fallback
|
|
134
|
+
* configuration.
|
|
135
|
+
* @returns A prerender function that yields an Effect when called.
|
|
77
136
|
*/
|
|
78
137
|
export declare function Prerender<A, E = never, R = never>(validate_or_handler: EffectLike<A, E, R> | RemoteHandler<void, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<void, A, E>;
|
|
138
|
+
/**
|
|
139
|
+
* Creates a prerenderable remote function with unchecked input.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* export const GetPost = Prerender(
|
|
144
|
+
* "unchecked",
|
|
145
|
+
* (slug: string) => Effect.succeed({ slug }),
|
|
146
|
+
* { inputs: () => ["intro"] },
|
|
147
|
+
* );
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @since 2.0.0
|
|
151
|
+
* @param validate_or_handler - `"unchecked"` sentinel that skips runtime input
|
|
152
|
+
* validation.
|
|
153
|
+
* @param maybe_handler - Handler that receives the caller-provided input.
|
|
154
|
+
* @param maybe_options - Optional prerender inputs and dynamic fallback
|
|
155
|
+
* configuration.
|
|
156
|
+
* @returns A prerender function that yields an Effect when called with input.
|
|
157
|
+
*/
|
|
79
158
|
export declare function Prerender<Input, A, E = never, R = never>(validate_or_handler: "unchecked", maybe_handler: RemoteHandler<Input, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<Input, A, E>;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a prerenderable remote function validated with an Effect Schema.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* export const GetPost = Prerender(
|
|
165
|
+
* Schema.String,
|
|
166
|
+
* (slug) => Effect.succeed({ slug }),
|
|
167
|
+
* { inputs: () => ["intro"] },
|
|
168
|
+
* );
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @since 2.0.0
|
|
172
|
+
* @param validate_or_handler - Effect Schema used to decode and validate
|
|
173
|
+
* caller input before the handler runs.
|
|
174
|
+
* @param maybe_handler - Handler that receives the decoded schema output.
|
|
175
|
+
* @param maybe_options - Optional prerender inputs and dynamic fallback
|
|
176
|
+
* configuration.
|
|
177
|
+
* @returns A prerender function whose caller input is the schema encoded type.
|
|
178
|
+
*/
|
|
80
179
|
export declare function Prerender<S extends Schema.Schema<unknown>, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<SchemaInput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<SchemaEncodedInput<S>, A, E>;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a prerenderable remote function validated with a Standard Schema.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* export const GetPost = Prerender(
|
|
186
|
+
* standard_schema,
|
|
187
|
+
* (post) => Effect.succeed(post.slug),
|
|
188
|
+
* { dynamic: true },
|
|
189
|
+
* );
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @since 3.0.0
|
|
193
|
+
* @param validate_or_handler - Standard Schema used to validate caller input
|
|
194
|
+
* before the handler runs.
|
|
195
|
+
* @param maybe_handler - Handler that receives the decoded schema output.
|
|
196
|
+
* @param maybe_options - Optional prerender inputs and dynamic fallback
|
|
197
|
+
* configuration.
|
|
198
|
+
* @returns A prerender function whose caller input is the schema input type.
|
|
199
|
+
*/
|
|
81
200
|
export declare function Prerender<S extends StandardSchema, A, E = never, R = never>(validate_or_handler: S, maybe_handler: RemoteHandler<StandardSchemaOutput<S>, A, E, R>, maybe_options?: PrerenderOptions): EffectRemoteFunction<StandardSchemaInput<S>, A, E>;
|
|
82
201
|
export {};
|
package/.dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Command, Form, Prerender, Query } from "./factories.js";
|
|
2
2
|
export { Error, Redirect } from "./control-flow.js";
|
|
3
|
-
export { get_server_runtime_or_throw, RequestEvent, ServerRuntime
|
|
3
|
+
export { get_server_runtime_or_throw, RequestEvent, ServerRuntime } from "./runtime.js";
|
|
4
4
|
export { RuntimeAlreadyInitializedError } from "../errors.js";
|
|
5
|
-
export type { ErrorEffectFactory, ErrorStatus, ErrorStatusName, RedirectEffectFactory, RedirectStatus, RedirectStatusName, } from "./control-flow.js";
|
|
5
|
+
export type { ErrorBody, ErrorEffectFactory, ErrorProperties, ErrorStatus, ErrorStatusName, RedirectEffectFactory, RedirectOptions, RedirectStatus, RedirectStatusName, } from "./control-flow.js";
|
|
6
6
|
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, StandardSchemaInput, StandardSchemaOutput, } from "./types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequestEvent as SvelteKitRequestEvent } from "@sveltejs/kit";
|
|
2
|
-
import { Context, Layer, ManagedRuntime } from "effect";
|
|
3
2
|
import { Dispatcher as InternalDispatcher } from "../dispatcher.js";
|
|
3
|
+
import { Context, Layer, ManagedRuntime } from "effect";
|
|
4
4
|
/**
|
|
5
5
|
* Subset of SvelteKit's `RequestEvent` that remote handlers typically access.
|
|
6
6
|
*
|
package/.dist/server/types.d.ts
CHANGED
|
@@ -5,18 +5,35 @@ import type { Effect, Layer, ManagedRuntime, Schema, Stream } from "effect";
|
|
|
5
5
|
/**
|
|
6
6
|
* Effect-like values accepted by remote helper wrappers.
|
|
7
7
|
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const value: EffectLike<number> = Effect.succeed(1);
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
8
13
|
* @since 2.0.0
|
|
9
14
|
*/
|
|
10
15
|
export type EffectLike<A = unknown, E = unknown, R = unknown> = Effect.Effect<A, E, R> | Effect.gen.Return<A, E, R>;
|
|
11
16
|
/**
|
|
12
17
|
* Handler shape accepted by query, command, and prerender helpers.
|
|
13
18
|
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const handler: RemoteHandler<{ id: string }, string> = ({ id }) =>
|
|
22
|
+
* Effect.succeed(id);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
14
25
|
* @since 2.0.0
|
|
15
26
|
*/
|
|
16
27
|
export type RemoteHandler<Input = unknown, A = unknown, E = unknown, R = unknown> = (input: Input) => EffectLike<A, E, R>;
|
|
17
28
|
/**
|
|
18
29
|
* Handler or source shape accepted by live query helpers.
|
|
19
30
|
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const handler: RemoteLiveHandler<void, number> = () =>
|
|
34
|
+
* Stream.make(1, 2, 3);
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
20
37
|
* @since 2.0.0
|
|
21
38
|
*/
|
|
22
39
|
export type RemoteLiveHandler<Input = unknown, A = unknown, E = unknown, R = unknown> = EffectLike<EffectRemoteLiveSource<A>, E, R> | EffectRemoteLiveSource<A> | ((input: Input) => EffectLike<EffectRemoteLiveSource<A>, E, R> | EffectRemoteLiveSource<A>);
|
|
@@ -25,12 +42,25 @@ export type RemoteLiveHandler<Input = unknown, A = unknown, E = unknown, R = unk
|
|
|
25
42
|
* validated inputs collected by SvelteKit and returns an Effect-producing
|
|
26
43
|
* resolver for each requested input.
|
|
27
44
|
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const handler: EffectRemoteBatchHandler<string, boolean> = (ids) =>
|
|
48
|
+
* Effect.succeed((id) => ids.includes(id));
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
28
51
|
* @since 2.0.0
|
|
29
52
|
*/
|
|
30
53
|
export type EffectRemoteBatchHandler<Input = unknown, A = unknown, E = unknown, R = unknown> = (inputs: readonly Input[]) => EffectLike<(input: Input, index: number) => A, E, R>;
|
|
31
54
|
/**
|
|
32
55
|
* Handler shape accepted by the form helper.
|
|
33
56
|
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const handler: RemoteFormHandler<{ email: string }, { ok: true }> = (
|
|
60
|
+
* { data },
|
|
61
|
+
* ) => Effect.succeed({ ok: data.email.length > 0 });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
34
64
|
* @since 2.0.0
|
|
35
65
|
*/
|
|
36
66
|
export type RemoteFormHandler<Input = unknown, A = unknown, E = unknown, R = unknown> = (input: {
|
|
@@ -41,6 +71,13 @@ export type RemoteFormHandler<Input = unknown, A = unknown, E = unknown, R = unk
|
|
|
41
71
|
/**
|
|
42
72
|
* Proxy callable used to create typed form validation failures.
|
|
43
73
|
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const fail: Effect.Effect<never, unknown> = invalid.email(
|
|
77
|
+
* "Use an email address.",
|
|
78
|
+
* );
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
44
81
|
* @since 2.0.0
|
|
45
82
|
*/
|
|
46
83
|
export type FormInvalid<Input = unknown> = FormInvalidFunctionChildren & FormInvalidChildren<Input> & {
|
|
@@ -61,10 +98,18 @@ type FormInvalidChildren<Input> = IsUnknown<Input> extends true ? {
|
|
|
61
98
|
} : NonNullable<Input> extends object ? {
|
|
62
99
|
readonly [Key in keyof NonNullable<Input>]-?: FormInvalid<NonNullable<Input>[Key]>;
|
|
63
100
|
} : Record<never, never>;
|
|
64
|
-
type IsUnknown<Value> = unknown extends Value ? [Value] extends [unknown] ? true : false : false;
|
|
101
|
+
type IsUnknown<Value> = unknown extends Value ? ([Value] extends [unknown] ? true : false) : false;
|
|
65
102
|
/**
|
|
66
103
|
* Options accepted by the prerender helper.
|
|
67
104
|
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const options: PrerenderOptions = {
|
|
108
|
+
* inputs: () => ["first-post", "second-post"],
|
|
109
|
+
* dynamic: true,
|
|
110
|
+
* };
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
68
113
|
* @since 2.0.0
|
|
69
114
|
*/
|
|
70
115
|
export type PrerenderOptions = {
|
|
@@ -74,6 +119,15 @@ export type PrerenderOptions = {
|
|
|
74
119
|
/**
|
|
75
120
|
* Minimal Standard Schema shape accepted by SvelteKit remote helpers.
|
|
76
121
|
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const schema: StandardSchema = {
|
|
125
|
+
* "~standard": {
|
|
126
|
+
* validate: (input) => ({ value: input }),
|
|
127
|
+
* },
|
|
128
|
+
* };
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
77
131
|
* @since 2.0.0
|
|
78
132
|
*/
|
|
79
133
|
export type StandardSchema = {
|
|
@@ -88,18 +142,33 @@ export type StandardSchema = {
|
|
|
88
142
|
/**
|
|
89
143
|
* Extracts the input type from an Effect Schema.
|
|
90
144
|
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* type Input = SchemaInput<typeof Schema.String>;
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
91
150
|
* @since 2.0.0
|
|
92
151
|
*/
|
|
93
152
|
export type SchemaInput<S> = S extends Schema.Top ? Schema.Schema.Type<S> : unknown;
|
|
94
153
|
/**
|
|
95
154
|
* Extracts the encoded caller input type from an Effect Schema.
|
|
96
155
|
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* type Input = SchemaEncodedInput<typeof Schema.String>;
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
97
161
|
* @since 2.4.2
|
|
98
162
|
*/
|
|
99
163
|
export type SchemaEncodedInput<S> = S extends Schema.Top ? S["Encoded"] : unknown;
|
|
100
164
|
/**
|
|
101
165
|
* Extracts the encoded input type from a Standard Schema.
|
|
102
166
|
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* type Input = StandardSchemaInput<typeof schema>;
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
103
172
|
* @since 3.0.0
|
|
104
173
|
*/
|
|
105
174
|
export type StandardSchemaInput<S> = S extends {
|
|
@@ -112,6 +181,11 @@ export type StandardSchemaInput<S> = S extends {
|
|
|
112
181
|
/**
|
|
113
182
|
* Extracts the decoded handler input type from a Standard Schema.
|
|
114
183
|
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* type Output = StandardSchemaOutput<typeof schema>;
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
115
189
|
* @since 3.0.0
|
|
116
190
|
*/
|
|
117
191
|
export type StandardSchemaOutput<S> = S extends {
|
|
@@ -124,14 +198,32 @@ export type StandardSchemaOutput<S> = S extends {
|
|
|
124
198
|
/**
|
|
125
199
|
* Root and server export shape for building the server-side runtime.
|
|
126
200
|
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const runtime = ServerRuntime.make();
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
127
206
|
* @since 2.0.0
|
|
128
207
|
*/
|
|
129
208
|
export interface ServerRuntimeFactory {
|
|
209
|
+
/**
|
|
210
|
+
* Builds and caches the server-side Effect runtime.
|
|
211
|
+
*
|
|
212
|
+
* @param layer - Optional Effect layer to provide to remote handlers.
|
|
213
|
+
* @returns The managed runtime used by server-side SER helpers.
|
|
214
|
+
*/
|
|
130
215
|
make<R = never>(layer?: Layer.Layer<R>): ManagedRuntime.ManagedRuntime<R, never>;
|
|
131
216
|
}
|
|
132
217
|
/**
|
|
133
218
|
* Root and server export shape for query helpers.
|
|
134
219
|
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* export const GetUser = Query(Schema.Struct({ id: Schema.String }), ({ id }) =>
|
|
223
|
+
* Effect.succeed({ id })
|
|
224
|
+
* );
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
135
227
|
* @since 2.0.0
|
|
136
228
|
*/
|
|
137
229
|
export interface QueryFactory {
|
|
@@ -145,6 +237,13 @@ export interface QueryFactory {
|
|
|
145
237
|
/**
|
|
146
238
|
* Root and server export shape for batched query helpers.
|
|
147
239
|
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* export const HasUser = Query.batch(Schema.String, (ids) =>
|
|
243
|
+
* Effect.succeed((id) => ids.includes(id))
|
|
244
|
+
* );
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
148
247
|
* @since 2.0.0
|
|
149
248
|
*/
|
|
150
249
|
export interface QueryBatchFactory {
|
|
@@ -155,6 +254,11 @@ export interface QueryBatchFactory {
|
|
|
155
254
|
/**
|
|
156
255
|
* Root and server export shape for live query helpers.
|
|
157
256
|
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* export const Clock = Query.live(() => Stream.repeatValue(new Date()));
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
158
262
|
* @since 2.0.0
|
|
159
263
|
*/
|
|
160
264
|
export interface QueryLiveFactory {
|
|
@@ -166,6 +270,14 @@ export interface QueryLiveFactory {
|
|
|
166
270
|
/**
|
|
167
271
|
* Root and server export shape for command helpers.
|
|
168
272
|
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* export const SaveUser = Command(
|
|
276
|
+
* Schema.Struct({ id: Schema.String }),
|
|
277
|
+
* ({ id }) => Effect.succeed({ id, saved: true }),
|
|
278
|
+
* );
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
169
281
|
* @since 2.0.0
|
|
170
282
|
*/
|
|
171
283
|
export interface CommandFactory {
|
|
@@ -177,6 +289,14 @@ export interface CommandFactory {
|
|
|
177
289
|
/**
|
|
178
290
|
* Root and server export shape for form helpers.
|
|
179
291
|
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* export const SignIn = Form(
|
|
295
|
+
* Schema.Struct({ email: Schema.String }),
|
|
296
|
+
* ({ data }) => Effect.succeed({ ok: data.email.length > 0 }),
|
|
297
|
+
* );
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
180
300
|
* @since 2.0.0
|
|
181
301
|
*/
|
|
182
302
|
export interface FormFactory {
|
|
@@ -188,6 +308,11 @@ export interface FormFactory {
|
|
|
188
308
|
/**
|
|
189
309
|
* Root and server export shape for prerender helpers.
|
|
190
310
|
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* export const GetBuildInfo = Prerender(() => Effect.succeed("ready"));
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
191
316
|
* @since 2.0.0
|
|
192
317
|
*/
|
|
193
318
|
export interface PrerenderFactory {
|
|
@@ -254,9 +379,7 @@ export type EffectRemoteQuery<A, E = never> = Effect.Effect<A, RemoteFailure<E>,
|
|
|
254
379
|
*
|
|
255
380
|
* @since 2.0.0
|
|
256
381
|
*/
|
|
257
|
-
export type EffectRemoteQueryFunction<Input, A, E = never> = [Input] extends [
|
|
258
|
-
void
|
|
259
|
-
] ? () => EffectRemoteQuery<A, E> : undefined extends Input ? (input?: Input) => EffectRemoteQuery<A, E> : (input: Input) => EffectRemoteQuery<A, E>;
|
|
382
|
+
export type EffectRemoteQueryFunction<Input, A, E = never> = [Input] extends [void] ? () => EffectRemoteQuery<A, E> : undefined extends Input ? (input?: Input) => EffectRemoteQuery<A, E> : (input: Input) => EffectRemoteQuery<A, E>;
|
|
260
383
|
/**
|
|
261
384
|
* Live query resource with SvelteKit live stream state and reconnect controls
|
|
262
385
|
* preserved.
|
|
@@ -305,9 +428,7 @@ export type EffectRemoteLiveQuery<A, E = never> = Effect.Effect<EffectRemoteLive
|
|
|
305
428
|
*
|
|
306
429
|
* @since 2.2.0
|
|
307
430
|
*/
|
|
308
|
-
export type EffectRemoteLiveQueryFunction<Input, A, E = never> = [Input] extends [
|
|
309
|
-
void
|
|
310
|
-
] ? () => EffectRemoteLiveQuery<A, E> : undefined extends Input ? (input?: Input) => EffectRemoteLiveQuery<A, E> : (input: Input) => EffectRemoteLiveQuery<A, E>;
|
|
431
|
+
export type EffectRemoteLiveQueryFunction<Input, A, E = never> = [Input] extends [void] ? () => EffectRemoteLiveQuery<A, E> : undefined extends Input ? (input?: Input) => EffectRemoteLiveQuery<A, E> : (input: Input) => EffectRemoteLiveQuery<A, E>;
|
|
311
432
|
/**
|
|
312
433
|
* Effect-returning command type with SvelteKit's pending counter preserved.
|
|
313
434
|
*
|
package/.dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Command, Error, Form, get_server_runtime_or_throw, Prerender, Query, Redirect, RequestEvent, ServerRuntime, } from "./server/index.js";
|
|
2
|
-
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, ErrorEffectFactory, ErrorStatus, ErrorStatusName, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RedirectEffectFactory, RedirectStatus, RedirectStatusName, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, StandardSchemaInput, StandardSchemaOutput, } from "./server/index.js";
|
|
2
|
+
export type { CommandFactory, EffectLike, EffectRemoteBatchHandler, EffectRemoteCommand, EffectRemoteForm, EffectRemoteFunction, EffectRemoteLiveQuery, EffectRemoteLiveQueryFunction, EffectRemoteLiveQueryResource, EffectRemoteLiveSource, EffectRemoteQuery, EffectRemoteQueryFunction, ErrorBody, ErrorEffectFactory, ErrorProperties, ErrorStatus, ErrorStatusName, FormFactory, FormInvalid, PrerenderFactory, PrerenderOptions, QueryBatchFactory, QueryFactory, QueryLiveFactory, RedirectEffectFactory, RedirectOptions, RedirectStatus, RedirectStatusName, RemoteFormHandler, RemoteHandler, RemoteLiveHandler, SchemaEncodedInput, SchemaInput, ServerRuntimeFactory, StandardSchema, StandardSchemaInput, StandardSchemaOutput, } from "./server/index.js";
|
package/.dist/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as UncheckedLiveQueryHandlerMissingError, S as UncheckedFormHandlerMissingError, T as UncheckedQueryHandlerMissingError, c as InvalidLiveQueryReturnError, i as BatchQueryHandlerMissingError, w as UncheckedPrerenderHandlerMissingError, x as UncheckedCommandHandlerMissingError } from "./chunks/errors-
|
|
1
|
+
import { C as UncheckedLiveQueryHandlerMissingError, S as UncheckedFormHandlerMissingError, T as UncheckedQueryHandlerMissingError, c as InvalidLiveQueryReturnError, i as BatchQueryHandlerMissingError, w as UncheckedPrerenderHandlerMissingError, x as UncheckedCommandHandlerMissingError } from "./chunks/errors-Dcf0MVbq.js";
|
|
2
2
|
import { create_form_error } from "./remote/shared.js";
|
|
3
|
-
import { t as copy_property_descriptors } from "./chunks/descriptors-
|
|
3
|
+
import { t as copy_property_descriptors } from "./chunks/descriptors-cOe9uRJz.js";
|
|
4
4
|
import { normalize_remote_helper_error, run_remote_effect } from "./remote/server.js";
|
|
5
|
-
import { i as get_server_runtime_or_throw, n as ServerRuntime, t as RequestEvent } from "./chunks/runtime-
|
|
5
|
+
import { i as get_server_runtime_or_throw, n as ServerRuntime, t as RequestEvent } from "./chunks/runtime-ekkMQ-wL.js";
|
|
6
6
|
import { Effect, Schema, Stream } from "effect";
|
|
7
7
|
import { error, invalid, redirect } from "@sveltejs/kit";
|
|
8
8
|
import { command, form, getRequestEvent, prerender, query } from "$app/server";
|
|
@@ -77,7 +77,7 @@ function is_generator_result(value) {
|
|
|
77
77
|
* @param value - Effect or generator return value.
|
|
78
78
|
* @returns Normalized Effect.
|
|
79
79
|
*/
|
|
80
|
-
function
|
|
80
|
+
function ToEffect(value) {
|
|
81
81
|
if (is_generator_result(value)) return Effect.gen(() => value);
|
|
82
82
|
return value;
|
|
83
83
|
}
|
|
@@ -105,13 +105,13 @@ function is_live_source(value) {
|
|
|
105
105
|
*/
|
|
106
106
|
function run_live_handler_source(value, event) {
|
|
107
107
|
const runtime = get_server_runtime_or_throw();
|
|
108
|
-
return run_remote_effect(Effect.provideService(
|
|
108
|
+
return run_remote_effect(Effect.provideService(ToLiveSourceEffect(value), RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function ToLiveSourceEffect(value) {
|
|
111
111
|
if (Stream.isStream(value)) return Stream.toAsyncIterableEffect(value);
|
|
112
112
|
if (is_native_live_source(value)) return Effect.succeed(value);
|
|
113
113
|
if (!Effect.isEffect(value)) return Effect.fail(new InvalidLiveQueryReturnError());
|
|
114
|
-
return Effect.flatMap(value,
|
|
114
|
+
return Effect.flatMap(value, ToLiveSourceEffect);
|
|
115
115
|
}
|
|
116
116
|
function is_native_live_source(value) {
|
|
117
117
|
return is_live_source(value) && !Stream.isStream(value);
|
|
@@ -126,11 +126,8 @@ function is_native_live_source(value) {
|
|
|
126
126
|
*/
|
|
127
127
|
function run_handler_effect(value, event) {
|
|
128
128
|
const runtime = get_server_runtime_or_throw();
|
|
129
|
-
return run_remote_effect(Effect.provideService(
|
|
129
|
+
return run_remote_effect(Effect.provideService(ToEffect(value), RequestEvent, event), runtime, invalid, svelte_remote_error);
|
|
130
130
|
}
|
|
131
|
-
const svelte_invalid = (_status, body) => {
|
|
132
|
-
invalid(...typeof body === "object" && body !== null && Array.isArray(body.issues) ? body.issues : [String(body)]);
|
|
133
|
-
};
|
|
134
131
|
const svelte_remote_error = (status, body) => {
|
|
135
132
|
error(status, body);
|
|
136
133
|
};
|
|
@@ -263,6 +260,8 @@ async function run_inside_remote_effect_handler(run) {
|
|
|
263
260
|
}
|
|
264
261
|
//#endregion
|
|
265
262
|
//#region src/server/factories.ts
|
|
263
|
+
const request_event_context_error_start = "Can only read the current request event inside functions invoked during `handle`";
|
|
264
|
+
const request_store_context_error = "Could not get the request store.";
|
|
266
265
|
function to_effect_query(native) {
|
|
267
266
|
const wrapped = ((input) => {
|
|
268
267
|
if (is_current_remote_request()) return native(input);
|
|
@@ -279,12 +278,25 @@ function to_effect_query(native) {
|
|
|
279
278
|
}
|
|
280
279
|
function is_current_remote_request() {
|
|
281
280
|
if (is_running_remote_effect_handler()) return false;
|
|
281
|
+
const detection = detect_current_remote_request();
|
|
282
|
+
if (detection._tag === "NoCurrentRemoteRequest") return false;
|
|
283
|
+
return detection.event.isRemoteRequest === true;
|
|
284
|
+
}
|
|
285
|
+
function detect_current_remote_request() {
|
|
282
286
|
try {
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
287
|
+
return {
|
|
288
|
+
_tag: "CurrentRemoteRequest",
|
|
289
|
+
event: getRequestEvent()
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
if (is_request_event_context_error(error)) return { _tag: "NoCurrentRemoteRequest" };
|
|
293
|
+
throw error;
|
|
286
294
|
}
|
|
287
295
|
}
|
|
296
|
+
function is_request_event_context_error(error) {
|
|
297
|
+
if (!(error instanceof Error)) return false;
|
|
298
|
+
return error.message.startsWith(request_event_context_error_start) || error.message === request_store_context_error;
|
|
299
|
+
}
|
|
288
300
|
function to_effect_live_query(native) {
|
|
289
301
|
const wrapped = ((input) => {
|
|
290
302
|
return Effect.try({
|
|
@@ -533,15 +545,19 @@ const redirect_status_codes = {
|
|
|
533
545
|
* SvelteKit's `error` helper.
|
|
534
546
|
* @param body - Optional SvelteKit error body or message forwarded unchanged
|
|
535
547
|
* to SvelteKit.
|
|
548
|
+
* @param properties - Optional SvelteKit 3 app error properties forwarded when
|
|
549
|
+
* using a string error message.
|
|
536
550
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
537
551
|
* control flow.
|
|
538
552
|
*/
|
|
539
|
-
const Error = (status, body) => {
|
|
553
|
+
const Error$1 = ((status, body, properties) => {
|
|
540
554
|
const resolved_status = resolve_error_status(status);
|
|
555
|
+
const error$1 = error;
|
|
541
556
|
return Effect.sync(() => {
|
|
542
|
-
error(resolved_status, body);
|
|
557
|
+
if (properties === void 0) return error$1(resolved_status, body);
|
|
558
|
+
return error$1(resolved_status, body, properties);
|
|
543
559
|
});
|
|
544
|
-
};
|
|
560
|
+
});
|
|
545
561
|
/**
|
|
546
562
|
* Creates an Effect that raises SvelteKit's redirect control flow.
|
|
547
563
|
*
|
|
@@ -554,15 +570,16 @@ const Error = (status, body) => {
|
|
|
554
570
|
* @param status - Numeric redirect status or PascalCase status name to pass to
|
|
555
571
|
* SvelteKit's `redirect` helper.
|
|
556
572
|
* @param location - Target URL forwarded unchanged to SvelteKit.
|
|
573
|
+
* @param options - Optional SvelteKit redirect options. In SvelteKit 3, pass
|
|
574
|
+
* `{ external: true }` or an allowlist to redirect to external URLs.
|
|
557
575
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
558
576
|
* control flow.
|
|
559
577
|
*/
|
|
560
|
-
const Redirect = (status, location) => {
|
|
578
|
+
const Redirect = ((status, location, options) => {
|
|
561
579
|
const resolved_status = resolve_redirect_status(status);
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
};
|
|
580
|
+
const redirect$1 = redirect;
|
|
581
|
+
return Effect.sync(() => redirect$1(resolved_status, location, options));
|
|
582
|
+
});
|
|
566
583
|
function resolve_error_status(status) {
|
|
567
584
|
if (typeof status === "number") return status;
|
|
568
585
|
return error_status_codes[status];
|
|
@@ -572,6 +589,6 @@ function resolve_redirect_status(status) {
|
|
|
572
589
|
return redirect_status_codes[status];
|
|
573
590
|
}
|
|
574
591
|
//#endregion
|
|
575
|
-
export { Command, Error, Form, Prerender, Query, Redirect, RequestEvent, ServerRuntime, get_server_runtime_or_throw };
|
|
592
|
+
export { Command, Error$1 as Error, Form, Prerender, Query, Redirect, RequestEvent, ServerRuntime, get_server_runtime_or_throw };
|
|
576
593
|
|
|
577
594
|
//# sourceMappingURL=server.js.map
|