svelte-effect-runtime 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/chunks/client-DbwVAMWm.js +530 -0
- package/.dist/chunks/client-DbwVAMWm.js.map +1 -0
- package/.dist/chunks/compiler-Dpyu4Owd.js +412 -0
- package/.dist/chunks/compiler-Dpyu4Owd.js.map +1 -0
- package/.dist/chunks/descriptors-q909VWyR.js +216 -0
- package/.dist/chunks/descriptors-q909VWyR.js.map +1 -0
- package/.dist/chunks/diagnostics-DLwwrBWb.js +359 -0
- package/.dist/chunks/diagnostics-DLwwrBWb.js.map +1 -0
- package/.dist/chunks/dispatcher-CTWINW5I.js +534 -0
- package/.dist/chunks/dispatcher-CTWINW5I.js.map +1 -0
- package/.dist/chunks/dispatcher-pZPzarul.js +23 -0
- package/.dist/chunks/dispatcher-pZPzarul.js.map +1 -0
- package/.dist/chunks/{errors-IJjsUwrE.js → errors-qhcbUH6o.js} +56 -44
- package/.dist/chunks/errors-qhcbUH6o.js.map +1 -0
- package/.dist/chunks/live-BW7xZKjb.js +146 -0
- package/.dist/chunks/live-BW7xZKjb.js.map +1 -0
- package/.dist/chunks/live-CHK0RrZu.js +10 -0
- package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
- package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
- package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
- package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-CPosEhGl.js} +3 -27
- package/.dist/chunks/runtime-CPosEhGl.js.map +1 -0
- package/.dist/chunks/{server-D1LcDnZE.js → server-yQrNoiCR.js} +15 -84
- package/.dist/chunks/server-yQrNoiCR.js.map +1 -0
- package/.dist/chunks/source-scan-cSawCvsg.js +1059 -0
- package/.dist/chunks/source-scan-cSawCvsg.js.map +1 -0
- package/.dist/chunks/{transform-jNUr65K9.js → transform-D7TTlPpK.js} +245 -371
- package/.dist/chunks/transform-D7TTlPpK.js.map +1 -0
- package/.dist/compiler/markup-identifiers.d.ts +2 -0
- package/.dist/compiler/remote-client.d.ts +1 -19
- package/.dist/compiler/source-scan.d.ts +11 -108
- package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
- package/.dist/compiler.d.ts +6 -0
- package/.dist/compiler.js +1 -1
- package/.dist/detect.d.ts +0 -31
- package/.dist/detect.js +0 -39
- package/.dist/detect.js.map +1 -1
- package/.dist/diagnostics.d.ts +0 -16
- package/.dist/dispatcher/deps.d.ts +3 -14
- package/.dist/dispatcher/fibers.d.ts +5 -46
- package/.dist/dispatcher/index.d.ts +42 -135
- package/.dist/dispatcher/scope.d.ts +36 -0
- package/.dist/dispatcher/types.d.ts +0 -151
- package/.dist/dispatcher.d.ts +2 -1
- package/.dist/dispatcher.js +2 -2
- package/.dist/errors.d.ts +44 -42
- package/.dist/generated/dispatcher.d.ts +6 -51
- package/.dist/generators.d.ts +2 -12
- package/.dist/internal/descriptors.d.ts +0 -16
- package/.dist/internal/generators.js +14 -9
- package/.dist/internal/generators.js.map +1 -1
- package/.dist/internal/live.d.ts +9 -0
- package/.dist/internal/remote-client.js +2 -2
- package/.dist/internal/remote-server.js +2 -2
- package/.dist/internal/schema.d.ts +0 -54
- package/.dist/live.d.ts +9 -26
- package/.dist/markup/event-attributes.d.ts +0 -32
- package/.dist/markup/promise.d.ts +1 -23
- package/.dist/markup/promise.js +2 -18
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.d.ts +1 -10
- package/.dist/markup/run.js +2 -11
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/apply.d.ts +5 -4
- package/.dist/markup/transform/classify.d.ts +2 -11
- package/.dist/markup/transform/constants.d.ts +2 -1
- package/.dist/markup/transform/effect-bindings.d.ts +2 -26
- package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
- package/.dist/markup/transform/emit.d.ts +2 -11
- package/.dist/markup/transform/expressions.d.ts +0 -35
- package/.dist/markup/transform/scan.d.ts +3 -22
- package/.dist/markup/transform/types.d.ts +15 -127
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.d.ts +1 -18
- package/.dist/markup/value.js +2 -19
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +3 -8
- package/.dist/mod.js +5 -5
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/cause-codec.d.ts +3 -37
- package/.dist/remote/client/command.d.ts +3 -17
- package/.dist/remote/client/form-data.d.ts +0 -7
- package/.dist/remote/client/form-enhance.d.ts +0 -7
- package/.dist/remote/client/form-transport.d.ts +14 -20
- package/.dist/remote/client/form.d.ts +4 -24
- package/.dist/remote/client/index.d.ts +2 -1
- package/.dist/remote/client/prerender.d.ts +6 -0
- package/.dist/remote/client/query-result.d.ts +2 -14
- package/.dist/remote/client/query.d.ts +8 -48
- package/.dist/remote/client/responses.d.ts +3 -27
- package/.dist/remote/client/types.d.ts +16 -110
- package/.dist/remote/client/utils.d.ts +0 -8
- package/.dist/remote/client.d.ts +2 -2
- package/.dist/remote/client.js +2 -2
- package/.dist/remote/effect.d.ts +6 -0
- package/.dist/remote/failures.d.ts +4 -0
- package/.dist/remote/query-update.d.ts +2 -0
- package/.dist/remote/resource.d.ts +25 -0
- package/.dist/remote/server.d.ts +5 -50
- package/.dist/remote/server.js +2 -2
- package/.dist/remote/shared.d.ts +6 -145
- package/.dist/remote/shared.js +6 -127
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/transform.js +26 -31
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/ast.d.ts +0 -46
- package/.dist/script-transform/imports.d.ts +3 -39
- package/.dist/script-transform/index.d.ts +2 -0
- package/.dist/script-transform/lower.d.ts +0 -9
- package/.dist/script-transform/runes.d.ts +0 -10
- package/.dist/script-transform/runtime-block.d.ts +0 -17
- package/.dist/script-transform/source.d.ts +0 -24
- package/.dist/script-transform/types.d.ts +9 -126
- package/.dist/server/effects.d.ts +4 -53
- package/.dist/server/factories.d.ts +7 -7
- package/.dist/server/index.d.ts +1 -1
- package/.dist/server/invalid.d.ts +0 -7
- package/.dist/server/live-snapshot.d.ts +5 -0
- package/.dist/server/remote-handler-context.d.ts +5 -0
- package/.dist/server/runtime.d.ts +6 -24
- package/.dist/server/schema.d.ts +0 -14
- package/.dist/server/transport.d.ts +2 -0
- package/.dist/server/types.d.ts +49 -26
- package/.dist/server/wrappers.d.ts +3 -40
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +200 -215
- package/.dist/server.js.map +1 -1
- package/.dist/yieldable.d.ts +1 -35
- package/package.json +2 -2
- package/.dist/chunks/client-DcZUV4rR.js +0 -653
- package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
- package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
- package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
- package/.dist/chunks/dispatcher-DOx8iC6r.js +0 -505
- package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
- package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
- package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
- package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
- package/.dist/chunks/live-BXAKre_4.js +0 -104
- package/.dist/chunks/live-BXAKre_4.js.map +0 -1
- package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
- package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
- package/.dist/chunks/schema-D9pct6Y5.js +0 -89
- package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
- package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
- package/.dist/chunks/source-scan-C4PsggID.js +0 -341
- package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
- package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
- package/.dist/remote/client/effect.d.ts +0 -29
- package/.dist/remote/client/failures.d.ts +0 -42
package/.dist/detect.js
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
//#region src/detect.ts
|
|
3
|
-
/**
|
|
4
|
-
* Returns `true` when the node tree contains a `yield*` expression that is
|
|
5
|
-
* not inside any function boundary (arrow function, function declaration,
|
|
6
|
-
* function expression, method).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const sf = ts.createSourceFile("test.ts", "yield* foo()", ...);
|
|
11
|
-
* contains_top_level_yield_star(sf.statements[0]); // true
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @since 2.0.0
|
|
15
|
-
* @param node - The root node to search from.
|
|
16
|
-
* @returns Whether a top-level yield* expression was found.
|
|
17
|
-
*/
|
|
18
3
|
function contains_top_level_yield_star(node) {
|
|
19
4
|
if (is_function_boundary(node)) return false;
|
|
20
5
|
if (is_yield_star_expression(node)) return true;
|
|
21
6
|
return node.getChildren().some((child) => contains_top_level_yield_star(child));
|
|
22
7
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns `true` when the node is a function-like boundary that owns its
|
|
25
|
-
* own yield/yield* semantics. A function boundary includes arrow functions,
|
|
26
|
-
* function declarations, function expressions, methods, get accessors, and
|
|
27
|
-
* set accessors.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* const stmt = parseStatement("function foo() {}");
|
|
32
|
-
* is_function_boundary(stmt); // true
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @since 2.0.0
|
|
36
|
-
* @param node - The node to check.
|
|
37
|
-
* @returns Whether the node is a function boundary.
|
|
38
|
-
*/
|
|
39
8
|
function is_function_boundary(node) {
|
|
40
9
|
return ts.isArrowFunction(node) || ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isMethodDeclaration(node) || ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node);
|
|
41
10
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns `true` when the node is a binary expression shaped like
|
|
44
|
-
* `yield * operand` — a yield* delegate expression in TypeScript's AST.
|
|
45
|
-
*
|
|
46
|
-
* @since 2.0.0
|
|
47
|
-
* @param node - The node to check.
|
|
48
|
-
* @returns Whether the node is a `yield*` expression.
|
|
49
|
-
*/
|
|
50
11
|
function is_yield_star_expression(node) {
|
|
51
12
|
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield";
|
|
52
13
|
}
|
package/.dist/detect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/detect.ts"],"sourcesContent":["import ts from \"typescript\";\n\
|
|
1
|
+
{"version":3,"file":"detect.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/detect.ts"],"sourcesContent":["import ts from \"typescript\";\n\nexport function contains_top_level_yield_star(node: ts.Node): boolean {\n\tif (is_function_boundary(node)) {\n\t\treturn false;\n\t}\n\n\tif (is_yield_star_expression(node)) {\n\t\treturn true;\n\t}\n\n\treturn node.getChildren().some((child) => contains_top_level_yield_star(child));\n}\n\nexport function is_function_boundary(node: ts.Node): boolean {\n\treturn (\n\t\tts.isArrowFunction(node) ||\n\t\tts.isFunctionDeclaration(node) ||\n\t\tts.isFunctionExpression(node) ||\n\t\tts.isMethodDeclaration(node) ||\n\t\tts.isGetAccessorDeclaration(node) ||\n\t\tts.isSetAccessorDeclaration(node)\n\t);\n}\n\nfunction is_yield_star_expression(node: ts.Node): boolean {\n\treturn (\n\t\tts.isBinaryExpression(node) &&\n\t\tnode.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n\t\tts.isIdentifier(node.left) &&\n\t\tnode.left.text === \"yield\"\n\t);\n}\n"],"mappings":";;AAEA,SAAgB,8BAA8B,MAAwB;CACrE,IAAI,qBAAqB,IAAI,GAC5B,OAAO;CAGR,IAAI,yBAAyB,IAAI,GAChC,OAAO;CAGR,OAAO,KAAK,YAAY,CAAC,CAAC,MAAM,UAAU,8BAA8B,KAAK,CAAC;AAC/E;AAEA,SAAgB,qBAAqB,MAAwB;CAC5D,OACC,GAAG,gBAAgB,IAAI,KACvB,GAAG,sBAAsB,IAAI,KAC7B,GAAG,qBAAqB,IAAI,KAC5B,GAAG,oBAAoB,IAAI,KAC3B,GAAG,yBAAyB,IAAI,KAChC,GAAG,yBAAyB,IAAI;AAElC;AAEA,SAAS,yBAAyB,MAAwB;CACzD,OACC,GAAG,mBAAmB,IAAI,KAC1B,KAAK,cAAc,SAAS,GAAG,WAAW,iBAC1C,GAAG,aAAa,KAAK,IAAI,KACzB,KAAK,KAAK,SAAS;AAErB"}
|
package/.dist/diagnostics.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds best-effort SER usage diagnostics in Svelte component markup.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const diagnostics = find_svelte_effect_diagnostics(
|
|
7
|
-
* `<button onclick={Effect.gen}>save</button>`,
|
|
8
|
-
* "Button.svelte",
|
|
9
|
-
* );
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @since 2.0.0
|
|
13
|
-
* @param code - Svelte component source to scan for suspicious Effect usage.
|
|
14
|
-
* @param filename - Filename used in diagnostic messages.
|
|
15
|
-
* @returns Warning diagnostics with a message and source location.
|
|
16
|
-
*/
|
|
17
1
|
export declare function find_svelte_effect_diagnostics(code: string, filename: string): Array<{
|
|
18
2
|
message: string;
|
|
19
3
|
line: number;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const key = hash_deps([user_id, filters]);
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* @since 2.0.0
|
|
10
|
-
* @param deps - Dependency array to encode for cache lookup.
|
|
11
|
-
* @returns A structured string key suitable for Map lookups.
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare function hash_deps(deps: readonly unknown[]): string;
|
|
1
|
+
/** Assigns stable identities to object dependencies while hashing value dependencies. */
|
|
2
|
+
export type DependencyHasher = (deps: readonly unknown[]) => string;
|
|
3
|
+
export declare function make_dependency_hasher(): DependencyHasher;
|
|
@@ -1,54 +1,13 @@
|
|
|
1
1
|
import type { Fiber as FiberType } from "effect/Fiber";
|
|
2
|
-
import
|
|
3
|
-
/**
|
|
4
|
-
* Callbacks fired when a watched dispatcher fiber completes.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const callbacks: FiberWatchCallbacks<number> = {
|
|
9
|
-
* on_success: (value) => cache.set(key, value),
|
|
10
|
-
* };
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @since 2.0.0
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
2
|
+
import { Effect } from "effect";
|
|
16
3
|
export interface FiberWatchCallbacks<A> {
|
|
17
4
|
on_complete?: () => void;
|
|
18
5
|
on_success?: (value: A) => void;
|
|
19
6
|
on_failure?: (error: unknown) => void;
|
|
20
7
|
surface_failure?: boolean;
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* interrupt_fiber(runtime, fiber);
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @since 2.0.0
|
|
31
|
-
* @param runtime - Managed runtime that owns the fiber.
|
|
32
|
-
* @param fiber - Fiber to interrupt.
|
|
33
|
-
* @returns Nothing.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare function interrupt_fiber(runtime: ManagedRuntimeType<unknown, unknown>, fiber: FiberType<unknown, unknown>): void;
|
|
37
|
-
/**
|
|
38
|
-
* Watches a dispatcher fiber, runs completion callbacks, and surfaces
|
|
39
|
-
* non-interrupt failures on the microtask queue.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* watch_fiber_exit({ runtime, fiber, on_complete: cleanup });
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @since 2.0.0
|
|
47
|
-
* @param options - Runtime, fiber, and callbacks used for the watcher.
|
|
48
|
-
* @returns Nothing.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
export declare function watch_fiber_exit<A>(options: {
|
|
52
|
-
runtime: ManagedRuntimeType<unknown, unknown>;
|
|
9
|
+
export declare const InterruptFiber: (fiber: FiberType<unknown, unknown>) => Effect.Effect<void, never, never>;
|
|
10
|
+
/** Observes fiber completion and surfaces failures without taking ownership of the fiber. */
|
|
11
|
+
export declare const WatchFiberExit: <A>(options: {
|
|
53
12
|
fiber: FiberType<unknown, unknown>;
|
|
54
|
-
} & FiberWatchCallbacks<A>)
|
|
13
|
+
} & FiberWatchCallbacks<A>) => Effect.Effect<void, never, never>;
|
|
@@ -1,163 +1,70 @@
|
|
|
1
|
+
import type { DispatcherEvent, Dispose, MarkupPromiseEvent, MarkupRunEvent, MarkupValueEvent, PromiseOptions, ValueOptions } from "./types.js";
|
|
1
2
|
import type { ManagedRuntime as ManagedRuntimeType } from "effect/ManagedRuntime";
|
|
2
3
|
import { Effect, Layer } from "effect";
|
|
3
|
-
import
|
|
4
|
+
import { ComponentScope } from "./scope.js";
|
|
4
5
|
export { Code } from "./types.js";
|
|
5
6
|
export type { Dispose, PromiseOptions, ValueOptions } from "./types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Unified effect block dispatcher. Manages the fiber lifecycle of every
|
|
8
|
-
* effect block and wires results into reactive channels.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const dispatcher = new Dispatcher();
|
|
13
|
-
* const cancel = dispatcher.fork(Effect.log("running"));
|
|
14
|
-
* cancel();
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @since 2.0.0
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
7
|
export declare class Dispatcher {
|
|
21
8
|
#private;
|
|
9
|
+
static make<R = never>(layer?: Layer.Layer<R>): Dispatcher;
|
|
10
|
+
constructor(runtime?: ManagedRuntimeType<unknown, unknown>);
|
|
22
11
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const dispatcher = Dispatcher.make(Db.Live);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @since 2.0.0
|
|
32
|
-
* @param layer - Optional Effect layer to provide to the runtime.
|
|
33
|
-
* @returns The newly created dispatcher.
|
|
12
|
+
* Begin a component-owned Effect scope. Pass the returned scope to
|
|
13
|
+
* {@link run_scoped} so the work is interrupted and finalized when the
|
|
14
|
+
* component is destroyed. Disposal is idempotent.
|
|
34
15
|
*/
|
|
35
|
-
|
|
16
|
+
begin_scope(): ComponentScope;
|
|
36
17
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* const dispatcher = new Dispatcher(runtime);
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @since 2.0.0
|
|
45
|
-
* @param runtime - Managed runtime to use, or an empty-layer runtime when
|
|
46
|
-
* omitted.
|
|
18
|
+
* Runs `fn` with `scope` as the current component scope. While active,
|
|
19
|
+
* every effect path ({@link promise}, {@link run}, {@link value}) forks
|
|
20
|
+
* its work into `scope` so disposing the scope interrupts it and runs its
|
|
21
|
+
* finalizers. A disposed scope falls back to unscoped execution.
|
|
47
22
|
*/
|
|
48
|
-
|
|
23
|
+
with_scope<T>(scope: ComponentScope, fn: () => T): T;
|
|
49
24
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* const value = dispatcher.emit({
|
|
55
|
-
* type: Code.Markup.Value,
|
|
56
|
-
* id: "Component.svelte:1:2",
|
|
57
|
-
* deps: [],
|
|
58
|
-
* fallback: undefined,
|
|
59
|
-
* fn: function* () {
|
|
60
|
-
* return yield* Effect.succeed(1);
|
|
61
|
-
* },
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
25
|
+
* Forks an effect into a component scope and starts it. The fiber becomes
|
|
26
|
+
* a child of the scope, so disposing the scope interrupts it and runs its
|
|
27
|
+
* finalizers. Returns an idempotent handle that interrupts the scoped
|
|
28
|
+
* fiber directly.
|
|
64
29
|
*
|
|
65
|
-
* @
|
|
66
|
-
* @
|
|
67
|
-
* @returns The operation result for the emitted dispatcher event.
|
|
30
|
+
* Throws {@link ScopeDisposedError} when the scope was already disposed
|
|
31
|
+
* and {@link DispatcherDisposedError} when the dispatcher was shut down.
|
|
68
32
|
*/
|
|
33
|
+
run_scoped<A, E, R>(scope: ComponentScope, effect: Effect.Effect<A, E, R>): Dispose;
|
|
34
|
+
/**
|
|
35
|
+
* Disposes a component scope owned by this dispatcher, interrupting its
|
|
36
|
+
* bound work and running its finalizers. Idempotent. Rejects scopes owned
|
|
37
|
+
* by another dispatcher with {@link ScopeDisposedError}.
|
|
38
|
+
*/
|
|
39
|
+
dispose_scope(scope: ComponentScope): void;
|
|
69
40
|
emit<A, F>(event: MarkupValueEvent<A, F>): A | F;
|
|
70
41
|
emit<A>(event: MarkupPromiseEvent<A>): Promise<A>;
|
|
71
42
|
emit<A>(event: MarkupRunEvent<A>): Promise<A>;
|
|
72
43
|
emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;
|
|
73
|
-
/**
|
|
74
|
-
* Forks an effect as a managed fiber and returns a cleanup function.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* const dispose = dispatcher.fork(Effect.log("clicked"));
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @since 2.0.0
|
|
82
|
-
* @param effect - Effect to fork.
|
|
83
|
-
* @returns A function that interrupts the fiber.
|
|
84
|
-
*/
|
|
85
44
|
fork<A, E, R>(effect: Effect.Effect<A, E, R>): Dispose;
|
|
86
|
-
/**
|
|
87
|
-
* Forks an effect and exposes its result as a cached reactive value.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* const user = dispatcher.value({ id, deps, fallback, factory });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @since 2.0.0
|
|
95
|
-
* @param options - Value id, dependency array, fallback, and effect factory.
|
|
96
|
-
* @returns The cached value if resolved, otherwise the fallback.
|
|
97
|
-
*/
|
|
98
45
|
value<A>(options: ValueOptions<A>): A;
|
|
99
|
-
/**
|
|
100
|
-
* Forks an effect and exposes its completion as a cached promise.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* const promise = dispatcher.promise({ id, deps, factory });
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* @since 2.0.0
|
|
108
|
-
* @param options - Promise id, dependency array, and effect factory.
|
|
109
|
-
* @returns A promise that resolves with the effect result.
|
|
110
|
-
*/
|
|
111
46
|
promise<A>(options: PromiseOptions<A>): Promise<A>;
|
|
112
|
-
/**
|
|
113
|
-
* Runs an event-handler effect and surfaces failures to Svelte.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* await dispatcher.run(Effect.log("submit"));
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* @since 2.0.0
|
|
121
|
-
* @param effect - Effect to execute.
|
|
122
|
-
* @returns A promise that resolves or rejects when the effect completes.
|
|
123
|
-
*/
|
|
124
47
|
run<A, E, R>(effect: Effect.Effect<A, E, R>): Promise<A>;
|
|
125
|
-
/**
|
|
126
|
-
* Cancels all running fibers and releases cached values.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* dispatcher.dispose();
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* @since 2.0.0
|
|
134
|
-
* @returns Nothing.
|
|
135
|
-
*/
|
|
136
48
|
dispose(): void;
|
|
137
49
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Resolves the active dispatcher, creating a default one if necessary.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* const dispatcher = get_dispatcher();
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* @since 2.0.0
|
|
147
|
-
* @returns The active dispatcher singleton.
|
|
148
|
-
* @internal
|
|
149
|
-
*/
|
|
150
50
|
export declare function get_dispatcher(): Dispatcher;
|
|
51
|
+
export declare function reset_dispatcher(): void;
|
|
151
52
|
/**
|
|
152
|
-
*
|
|
53
|
+
* Lazily-created component scope used by generated component code.
|
|
153
54
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
55
|
+
* The holder is created synchronously during component init (before any
|
|
56
|
+
* top-level `await`, where `onDestroy` is not yet available), and the scope
|
|
57
|
+
* itself is materialized on first use. Disposal is registered separately
|
|
58
|
+
* through `onDestroy` during component initialisation, so the scope is
|
|
59
|
+
* reliably closed on unmount.
|
|
158
60
|
*
|
|
159
|
-
* @since
|
|
160
|
-
* @returns Nothing.
|
|
161
|
-
* @internal
|
|
61
|
+
* @since 4.1.0
|
|
162
62
|
*/
|
|
163
|
-
export declare
|
|
63
|
+
export declare class ComponentScopeRef {
|
|
64
|
+
#private;
|
|
65
|
+
constructor(get_dispatcher_fn: () => Dispatcher);
|
|
66
|
+
/** The component scope, creating it on first access. */
|
|
67
|
+
get scope(): ComponentScope;
|
|
68
|
+
/** Disposes the scope if it was created. Idempotent. */
|
|
69
|
+
dispose(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Scope } from "effect";
|
|
2
|
+
import type { Fiber } from "effect";
|
|
3
|
+
/**
|
|
4
|
+
* A component-owned Effect scope.
|
|
5
|
+
*
|
|
6
|
+
* A `ComponentScope` wraps a `Scope.Closeable` forked from the dispatcher's
|
|
7
|
+
* root scope. Work is forked into the scope with `Effect.forkIn`, so closing
|
|
8
|
+
* the scope interrupts that work and runs its finalizers. The generated
|
|
9
|
+
* component teardown disposes the scope on destroy. Disposal is idempotent.
|
|
10
|
+
*
|
|
11
|
+
* @since 4.1.0
|
|
12
|
+
*/
|
|
13
|
+
export declare class ComponentScope {
|
|
14
|
+
#private;
|
|
15
|
+
private constructor();
|
|
16
|
+
/** Forks a child scope from the given root and returns it wrapped. */
|
|
17
|
+
static fork(root: Scope.Closeable, on_dispose: (scope: ComponentScope) => void): ComponentScope;
|
|
18
|
+
/** The underlying closeable scope used to bind Effect work. */
|
|
19
|
+
get underlying(): Scope.Closeable;
|
|
20
|
+
/** Whether this scope has already been disposed. */
|
|
21
|
+
get disposed(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Forks an effect into this scope. The fiber becomes a child of the scope,
|
|
24
|
+
* so disposing the scope interrupts it and runs its finalizers. The scope
|
|
25
|
+
* is provided ambiently so `Effect.forkIn` registers the fiber as a child.
|
|
26
|
+
*/
|
|
27
|
+
fork_in<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<Fiber.Fiber<A, E>, never, R>;
|
|
28
|
+
/** Effect that closes the scope. Must be run by the owning dispatcher. */
|
|
29
|
+
get close_effect(): Effect.Effect<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Marks the scope disposed and detaches it from the dispatcher. The caller
|
|
32
|
+
* is responsible for running {@link close_effect} to run finalizers.
|
|
33
|
+
* Idempotent.
|
|
34
|
+
*/
|
|
35
|
+
dispose(): void;
|
|
36
|
+
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import type { Effect } from "effect";
|
|
2
|
-
/**
|
|
3
|
-
* Stable operation codes used by transform-generated dispatcher events.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const type = Code.Markup.Promise;
|
|
8
|
-
* ```
|
|
9
|
-
*
|
|
10
|
-
* @since 3.3.0
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
2
|
export declare const Code: {
|
|
14
3
|
readonly Markup: {
|
|
15
4
|
readonly Promise: "MarkupPromise";
|
|
@@ -17,187 +6,47 @@ export declare const Code: {
|
|
|
17
6
|
readonly Value: "MarkupValue";
|
|
18
7
|
};
|
|
19
8
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Options for markup promise behavior during server rendering.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const options: MarkupPromiseOptions = { ssr: "pending" };
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @since 3.3.0
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
9
|
export interface MarkupPromiseOptions {
|
|
32
10
|
/** Keep the SSR promise pending so Svelte renders an await block fallback. */
|
|
33
11
|
ssr?: "pending";
|
|
34
12
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Minimal cleanup handle returned by dispatcher lifecycle hooks.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* const dispose: Dispose = dispatcher.fork(program);
|
|
41
|
-
* dispose();
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @since 2.0.0
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
13
|
export type Dispose = () => void;
|
|
48
|
-
/**
|
|
49
|
-
* Options for a cached dispatcher value block.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* const options: ValueOptions<number> = {
|
|
54
|
-
* id: "count",
|
|
55
|
-
* deps: [],
|
|
56
|
-
* fallback: 0,
|
|
57
|
-
* factory: () => Effect.succeed(1),
|
|
58
|
-
* };
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @since 2.0.0
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
14
|
export interface ValueOptions<A> {
|
|
65
15
|
/** Stable cache key for this value block. */
|
|
66
16
|
id: string;
|
|
67
|
-
/** Reactive dependency array. */
|
|
68
17
|
deps: readonly unknown[];
|
|
69
18
|
/** Value returned synchronously while the effect is running or during SSR. */
|
|
70
19
|
fallback: A;
|
|
71
|
-
/** Generator function that yields the effect to run. */
|
|
72
20
|
factory: () => Effect.gen.Return<A, unknown, unknown>;
|
|
73
21
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Options for a cached dispatcher promise block.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* const options: PromiseOptions<number> = {
|
|
80
|
-
* id: "count",
|
|
81
|
-
* deps: [],
|
|
82
|
-
* factory: () => Effect.succeed(1),
|
|
83
|
-
* };
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @since 2.0.0
|
|
87
|
-
* @internal
|
|
88
|
-
*/
|
|
89
22
|
export interface PromiseOptions<A> {
|
|
90
23
|
/** Stable cache key for this promise block. */
|
|
91
24
|
id: string;
|
|
92
|
-
/** Reactive dependency array. */
|
|
93
25
|
deps: readonly unknown[];
|
|
94
|
-
/** Generator function that yields the effect to run. */
|
|
95
26
|
factory: () => Effect.gen.Return<A, unknown, unknown>;
|
|
96
27
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Generated event that reads a markup expression through the cached value
|
|
99
|
-
* channel.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* const event: MarkupValueEvent<number, undefined> = {
|
|
104
|
-
* type: Code.Markup.Value,
|
|
105
|
-
* id: "Component.svelte:1:2",
|
|
106
|
-
* deps: [],
|
|
107
|
-
* fallback: undefined,
|
|
108
|
-
* fn: function* () {
|
|
109
|
-
* return yield* Effect.succeed(1);
|
|
110
|
-
* },
|
|
111
|
-
* };
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* @since 3.3.0
|
|
115
|
-
* @internal
|
|
116
|
-
*/
|
|
117
28
|
export interface MarkupValueEvent<A, F> {
|
|
118
|
-
/** Dispatcher code identifying a markup value read. */
|
|
119
29
|
type: typeof Code.Markup.Value;
|
|
120
30
|
/** Stable identifier generated from the expression's source position. */
|
|
121
31
|
id: string;
|
|
122
|
-
/** Reactive dependency array captured from free identifiers. */
|
|
123
32
|
deps: readonly unknown[];
|
|
124
33
|
/** Value returned synchronously while the effect is pending. */
|
|
125
34
|
fallback: F;
|
|
126
|
-
/** Generator function that yields the effect to run. */
|
|
127
35
|
fn: () => Effect.gen.Return<A, unknown, unknown>;
|
|
128
36
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Generated event that reads a markup expression through the cached promise
|
|
131
|
-
* channel.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```ts
|
|
135
|
-
* const event: MarkupPromiseEvent<number> = {
|
|
136
|
-
* type: Code.Markup.Promise,
|
|
137
|
-
* id: "Component.svelte:1:2",
|
|
138
|
-
* deps: [],
|
|
139
|
-
* fn: function* () {
|
|
140
|
-
* return yield* Effect.succeed(1);
|
|
141
|
-
* },
|
|
142
|
-
* };
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @since 3.3.0
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
37
|
export interface MarkupPromiseEvent<A> {
|
|
149
|
-
/** Dispatcher code identifying a markup promise read. */
|
|
150
38
|
type: typeof Code.Markup.Promise;
|
|
151
39
|
/** Stable identifier generated from the expression's source position. */
|
|
152
40
|
id: string;
|
|
153
|
-
/** Reactive dependency array captured from free identifiers. */
|
|
154
41
|
deps: readonly unknown[];
|
|
155
|
-
/** Generator function that yields the effect to run. */
|
|
156
42
|
fn: () => Effect.gen.Return<A, unknown, unknown>;
|
|
157
43
|
/** Value resolved during SSR when a fallback is required. */
|
|
158
44
|
ssr_fallback?: A;
|
|
159
45
|
/** Optional SSR behavior for await blocks and similar contexts. */
|
|
160
46
|
options?: MarkupPromiseOptions;
|
|
161
47
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Generated event that runs an event-handler Effect.
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```ts
|
|
167
|
-
* const event: MarkupRunEvent<void> = {
|
|
168
|
-
* type: Code.Markup.Run,
|
|
169
|
-
* fn: function* () {
|
|
170
|
-
* yield* Effect.void;
|
|
171
|
-
* },
|
|
172
|
-
* };
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @since 3.3.0
|
|
176
|
-
* @internal
|
|
177
|
-
*/
|
|
178
48
|
export interface MarkupRunEvent<A> {
|
|
179
|
-
/** Dispatcher code identifying a markup event-handler run. */
|
|
180
49
|
type: typeof Code.Markup.Run;
|
|
181
|
-
/** Generator function that yields the effect to run. */
|
|
182
50
|
fn: () => Effect.gen.Return<A, unknown, unknown>;
|
|
183
51
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Union of generated dispatcher events.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```ts
|
|
189
|
-
* const event: DispatcherEvent<number, undefined> = {
|
|
190
|
-
* type: Code.Markup.Value,
|
|
191
|
-
* id: "Component.svelte:1:2",
|
|
192
|
-
* deps: [],
|
|
193
|
-
* fallback: undefined,
|
|
194
|
-
* fn: function* () {
|
|
195
|
-
* return yield* Effect.succeed(1);
|
|
196
|
-
* },
|
|
197
|
-
* };
|
|
198
|
-
* ```
|
|
199
|
-
*
|
|
200
|
-
* @since 3.3.0
|
|
201
|
-
* @internal
|
|
202
|
-
*/
|
|
203
52
|
export type DispatcherEvent<A, F = A> = MarkupPromiseEvent<A> | MarkupRunEvent<A> | MarkupValueEvent<A, F>;
|
package/.dist/dispatcher.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { Code, Dispatcher, get_dispatcher, reset_dispatcher } from "./dispatcher/index.js";
|
|
1
|
+
export { Code, ComponentScopeRef, Dispatcher, get_dispatcher, reset_dispatcher, } from "./dispatcher/index.js";
|
|
2
|
+
export { ComponentScope } from "./dispatcher/scope.js";
|
|
2
3
|
export type { DispatcherEvent, Dispose, MarkupPromiseEvent, MarkupPromiseOptions, MarkupRunEvent, MarkupValueEvent, PromiseOptions, ValueOptions, } from "./dispatcher/types.js";
|
package/.dist/dispatcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Code, Dispatcher, get_dispatcher, reset_dispatcher };
|
|
1
|
+
import { a as Code, i as reset_dispatcher, n as Dispatcher, o as ComponentScope, r as get_dispatcher, t as ComponentScopeRef } from "./chunks/dispatcher-CTWINW5I.js";
|
|
2
|
+
export { Code, ComponentScope, ComponentScopeRef, Dispatcher, get_dispatcher, reset_dispatcher };
|