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.
Files changed (150) hide show
  1. package/.dist/chunks/client-DbwVAMWm.js +530 -0
  2. package/.dist/chunks/client-DbwVAMWm.js.map +1 -0
  3. package/.dist/chunks/compiler-Dpyu4Owd.js +412 -0
  4. package/.dist/chunks/compiler-Dpyu4Owd.js.map +1 -0
  5. package/.dist/chunks/descriptors-q909VWyR.js +216 -0
  6. package/.dist/chunks/descriptors-q909VWyR.js.map +1 -0
  7. package/.dist/chunks/diagnostics-DLwwrBWb.js +359 -0
  8. package/.dist/chunks/diagnostics-DLwwrBWb.js.map +1 -0
  9. package/.dist/chunks/dispatcher-CTWINW5I.js +534 -0
  10. package/.dist/chunks/dispatcher-CTWINW5I.js.map +1 -0
  11. package/.dist/chunks/dispatcher-pZPzarul.js +23 -0
  12. package/.dist/chunks/dispatcher-pZPzarul.js.map +1 -0
  13. package/.dist/chunks/{errors-IJjsUwrE.js → errors-qhcbUH6o.js} +56 -44
  14. package/.dist/chunks/errors-qhcbUH6o.js.map +1 -0
  15. package/.dist/chunks/live-BW7xZKjb.js +146 -0
  16. package/.dist/chunks/live-BW7xZKjb.js.map +1 -0
  17. package/.dist/chunks/live-CHK0RrZu.js +10 -0
  18. package/.dist/chunks/live-CHK0RrZu.js.map +1 -0
  19. package/.dist/chunks/{remote-client-CVI4t66c.js → remote-client-mkQAfP1G.js} +29 -23
  20. package/.dist/chunks/remote-client-mkQAfP1G.js.map +1 -0
  21. package/.dist/chunks/{runtime-GBQz32DZ.js → runtime-CPosEhGl.js} +3 -27
  22. package/.dist/chunks/runtime-CPosEhGl.js.map +1 -0
  23. package/.dist/chunks/{server-D1LcDnZE.js → server-yQrNoiCR.js} +15 -84
  24. package/.dist/chunks/server-yQrNoiCR.js.map +1 -0
  25. package/.dist/chunks/source-scan-cSawCvsg.js +1059 -0
  26. package/.dist/chunks/source-scan-cSawCvsg.js.map +1 -0
  27. package/.dist/chunks/{transform-jNUr65K9.js → transform-D7TTlPpK.js} +245 -371
  28. package/.dist/chunks/transform-D7TTlPpK.js.map +1 -0
  29. package/.dist/compiler/markup-identifiers.d.ts +2 -0
  30. package/.dist/compiler/remote-client.d.ts +1 -19
  31. package/.dist/compiler/source-scan.d.ts +11 -108
  32. package/.dist/compiler/sveltekit-remote-bridge.d.ts +3 -0
  33. package/.dist/compiler.d.ts +6 -0
  34. package/.dist/compiler.js +1 -1
  35. package/.dist/detect.d.ts +0 -31
  36. package/.dist/detect.js +0 -39
  37. package/.dist/detect.js.map +1 -1
  38. package/.dist/diagnostics.d.ts +0 -16
  39. package/.dist/dispatcher/deps.d.ts +3 -14
  40. package/.dist/dispatcher/fibers.d.ts +5 -46
  41. package/.dist/dispatcher/index.d.ts +42 -135
  42. package/.dist/dispatcher/scope.d.ts +36 -0
  43. package/.dist/dispatcher/types.d.ts +0 -151
  44. package/.dist/dispatcher.d.ts +2 -1
  45. package/.dist/dispatcher.js +2 -2
  46. package/.dist/errors.d.ts +44 -42
  47. package/.dist/generated/dispatcher.d.ts +6 -51
  48. package/.dist/generators.d.ts +2 -12
  49. package/.dist/internal/descriptors.d.ts +0 -16
  50. package/.dist/internal/generators.js +14 -9
  51. package/.dist/internal/generators.js.map +1 -1
  52. package/.dist/internal/live.d.ts +9 -0
  53. package/.dist/internal/remote-client.js +2 -2
  54. package/.dist/internal/remote-server.js +2 -2
  55. package/.dist/internal/schema.d.ts +0 -54
  56. package/.dist/live.d.ts +9 -26
  57. package/.dist/markup/event-attributes.d.ts +0 -32
  58. package/.dist/markup/promise.d.ts +1 -23
  59. package/.dist/markup/promise.js +2 -18
  60. package/.dist/markup/promise.js.map +1 -1
  61. package/.dist/markup/run.d.ts +1 -10
  62. package/.dist/markup/run.js +2 -11
  63. package/.dist/markup/run.js.map +1 -1
  64. package/.dist/markup/transform/apply.d.ts +5 -4
  65. package/.dist/markup/transform/classify.d.ts +2 -11
  66. package/.dist/markup/transform/constants.d.ts +2 -1
  67. package/.dist/markup/transform/effect-bindings.d.ts +2 -26
  68. package/.dist/markup/transform/effect-callbacks.d.ts +0 -20
  69. package/.dist/markup/transform/emit.d.ts +2 -11
  70. package/.dist/markup/transform/expressions.d.ts +0 -35
  71. package/.dist/markup/transform/scan.d.ts +3 -22
  72. package/.dist/markup/transform/types.d.ts +15 -127
  73. package/.dist/markup/transform.js +1 -1
  74. package/.dist/markup/value.d.ts +1 -18
  75. package/.dist/markup/value.js +2 -19
  76. package/.dist/markup/value.js.map +1 -1
  77. package/.dist/mod.d.ts +3 -8
  78. package/.dist/mod.js +5 -5
  79. package/.dist/mod.js.map +1 -1
  80. package/.dist/remote/cause-codec.d.ts +3 -37
  81. package/.dist/remote/client/command.d.ts +3 -17
  82. package/.dist/remote/client/form-data.d.ts +0 -7
  83. package/.dist/remote/client/form-enhance.d.ts +0 -7
  84. package/.dist/remote/client/form-transport.d.ts +14 -20
  85. package/.dist/remote/client/form.d.ts +4 -24
  86. package/.dist/remote/client/index.d.ts +2 -1
  87. package/.dist/remote/client/prerender.d.ts +6 -0
  88. package/.dist/remote/client/query-result.d.ts +2 -14
  89. package/.dist/remote/client/query.d.ts +8 -48
  90. package/.dist/remote/client/responses.d.ts +3 -27
  91. package/.dist/remote/client/types.d.ts +16 -110
  92. package/.dist/remote/client/utils.d.ts +0 -8
  93. package/.dist/remote/client.d.ts +2 -2
  94. package/.dist/remote/client.js +2 -2
  95. package/.dist/remote/effect.d.ts +6 -0
  96. package/.dist/remote/failures.d.ts +4 -0
  97. package/.dist/remote/query-update.d.ts +2 -0
  98. package/.dist/remote/resource.d.ts +25 -0
  99. package/.dist/remote/server.d.ts +5 -50
  100. package/.dist/remote/server.js +2 -2
  101. package/.dist/remote/shared.d.ts +6 -145
  102. package/.dist/remote/shared.js +6 -127
  103. package/.dist/remote/shared.js.map +1 -1
  104. package/.dist/runtime/transform.js +26 -31
  105. package/.dist/runtime/transform.js.map +1 -1
  106. package/.dist/script-transform/ast.d.ts +0 -46
  107. package/.dist/script-transform/imports.d.ts +3 -39
  108. package/.dist/script-transform/index.d.ts +2 -0
  109. package/.dist/script-transform/lower.d.ts +0 -9
  110. package/.dist/script-transform/runes.d.ts +0 -10
  111. package/.dist/script-transform/runtime-block.d.ts +0 -17
  112. package/.dist/script-transform/source.d.ts +0 -24
  113. package/.dist/script-transform/types.d.ts +9 -126
  114. package/.dist/server/effects.d.ts +4 -53
  115. package/.dist/server/factories.d.ts +7 -7
  116. package/.dist/server/index.d.ts +1 -1
  117. package/.dist/server/invalid.d.ts +0 -7
  118. package/.dist/server/live-snapshot.d.ts +5 -0
  119. package/.dist/server/remote-handler-context.d.ts +5 -0
  120. package/.dist/server/runtime.d.ts +6 -24
  121. package/.dist/server/schema.d.ts +0 -14
  122. package/.dist/server/transport.d.ts +2 -0
  123. package/.dist/server/types.d.ts +49 -26
  124. package/.dist/server/wrappers.d.ts +3 -40
  125. package/.dist/server.d.ts +1 -1
  126. package/.dist/server.js +200 -215
  127. package/.dist/server.js.map +1 -1
  128. package/.dist/yieldable.d.ts +1 -35
  129. package/package.json +2 -2
  130. package/.dist/chunks/client-DcZUV4rR.js +0 -653
  131. package/.dist/chunks/client-DcZUV4rR.js.map +0 -1
  132. package/.dist/chunks/compiler-BBPNyXmQ.js +0 -460
  133. package/.dist/chunks/compiler-BBPNyXmQ.js.map +0 -1
  134. package/.dist/chunks/dispatcher-DOx8iC6r.js +0 -505
  135. package/.dist/chunks/dispatcher-DOx8iC6r.js.map +0 -1
  136. package/.dist/chunks/dispatcher-H-Ia0Os4.js +0 -47
  137. package/.dist/chunks/dispatcher-H-Ia0Os4.js.map +0 -1
  138. package/.dist/chunks/errors-IJjsUwrE.js.map +0 -1
  139. package/.dist/chunks/live-BXAKre_4.js +0 -104
  140. package/.dist/chunks/live-BXAKre_4.js.map +0 -1
  141. package/.dist/chunks/remote-client-CVI4t66c.js.map +0 -1
  142. package/.dist/chunks/runtime-GBQz32DZ.js.map +0 -1
  143. package/.dist/chunks/schema-D9pct6Y5.js +0 -89
  144. package/.dist/chunks/schema-D9pct6Y5.js.map +0 -1
  145. package/.dist/chunks/server-D1LcDnZE.js.map +0 -1
  146. package/.dist/chunks/source-scan-C4PsggID.js +0 -341
  147. package/.dist/chunks/source-scan-C4PsggID.js.map +0 -1
  148. package/.dist/chunks/transform-jNUr65K9.js.map +0 -1
  149. package/.dist/remote/client/effect.d.ts +0 -29
  150. package/.dist/remote/client/failures.d.ts +0 -42
@@ -0,0 +1,534 @@
1
+ import { S as ScopeDisposedError, a as DispatcherDisposedError, b as RuntimeAlreadyInitializedError } from "./errors-qhcbUH6o.js";
2
+ import { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime, Scope } from "effect";
3
+ import { createSubscriber } from "svelte/reactivity";
4
+ import { isRedirect } from "@sveltejs/kit";
5
+ //#region src/dispatcher/fibers.ts
6
+ const InterruptFiber = (fiber) => Effect.gen(function* () {
7
+ yield* Fiber.interrupt(fiber);
8
+ });
9
+ /** Observes fiber completion and surfaces failures without taking ownership of the fiber. */
10
+ const WatchFiberExit = (options) => {
11
+ const { fiber, on_complete, on_success, on_failure, surface_failure = true } = options;
12
+ return Effect.gen(function* () {
13
+ const exit = yield* Fiber.await(fiber);
14
+ yield* Effect.sync(() => {
15
+ if (Exit.isSuccess(exit)) {
16
+ on_success?.(exit.value);
17
+ on_complete?.();
18
+ return;
19
+ }
20
+ if (!Cause.hasInterruptsOnly(exit.cause)) {
21
+ const error = Cause.squash(exit.cause);
22
+ on_failure?.(error);
23
+ if (surface_failure) queueMicrotask(() => {
24
+ throw error;
25
+ });
26
+ }
27
+ on_complete?.();
28
+ });
29
+ });
30
+ };
31
+ //#endregion
32
+ //#region src/dispatcher/scope.ts
33
+ /**
34
+ * A component-owned Effect scope.
35
+ *
36
+ * A `ComponentScope` wraps a `Scope.Closeable` forked from the dispatcher's
37
+ * root scope. Work is forked into the scope with `Effect.forkIn`, so closing
38
+ * the scope interrupts that work and runs its finalizers. The generated
39
+ * component teardown disposes the scope on destroy. Disposal is idempotent.
40
+ *
41
+ * @since 4.1.0
42
+ */
43
+ var ComponentScope = class ComponentScope {
44
+ #scope;
45
+ #disposed = false;
46
+ #on_dispose;
47
+ constructor(scope, on_dispose) {
48
+ this.#scope = scope;
49
+ this.#on_dispose = on_dispose;
50
+ }
51
+ /** Forks a child scope from the given root and returns it wrapped. */
52
+ static fork(root, on_dispose) {
53
+ return new ComponentScope(Scope.forkUnsafe(root), on_dispose);
54
+ }
55
+ /** The underlying closeable scope used to bind Effect work. */
56
+ get underlying() {
57
+ return this.#scope;
58
+ }
59
+ /** Whether this scope has already been disposed. */
60
+ get disposed() {
61
+ return this.#disposed;
62
+ }
63
+ /**
64
+ * Forks an effect into this scope. The fiber becomes a child of the scope,
65
+ * so disposing the scope interrupts it and runs its finalizers. The scope
66
+ * is provided ambiently so `Effect.forkIn` registers the fiber as a child.
67
+ */
68
+ fork_in(effect) {
69
+ /**
70
+ * The effect must see the scope before it is forked: provide the scope
71
+ * inside the forked program so `acquireRelease`-style work resolves it,
72
+ * and fork that program into the scope so the fiber is a child whose
73
+ * finalizers run when the scope closes.
74
+ */
75
+ return Effect.forkIn(Effect.provideService(effect, Scope.Scope, this.#scope), this.#scope);
76
+ }
77
+ /** Effect that closes the scope. Must be run by the owning dispatcher. */
78
+ get close_effect() {
79
+ return Scope.close(this.#scope, Exit.void);
80
+ }
81
+ /**
82
+ * Marks the scope disposed and detaches it from the dispatcher. The caller
83
+ * is responsible for running {@link close_effect} to run finalizers.
84
+ * Idempotent.
85
+ */
86
+ dispose() {
87
+ if (this.#disposed) return;
88
+ this.#disposed = true;
89
+ this.#on_dispose(this);
90
+ }
91
+ };
92
+ //#endregion
93
+ //#region src/dispatcher/deps.ts
94
+ function make_dependency_hasher() {
95
+ const object_dep_ids = /* @__PURE__ */ new WeakMap();
96
+ const symbol_dep_ids = /* @__PURE__ */ new Map();
97
+ let next_object_dep_id = 0;
98
+ let next_symbol_dep_id = 0;
99
+ const hash_symbol_dep = (dep) => {
100
+ let id = symbol_dep_ids.get(dep);
101
+ if (id === void 0) {
102
+ next_symbol_dep_id += 1;
103
+ id = next_symbol_dep_id;
104
+ symbol_dep_ids.set(dep, id);
105
+ }
106
+ return `y:${id}`;
107
+ };
108
+ const hash_object_dep = (dep) => {
109
+ let id = object_dep_ids.get(dep);
110
+ if (id === void 0) {
111
+ next_object_dep_id += 1;
112
+ id = next_object_dep_id;
113
+ object_dep_ids.set(dep, id);
114
+ }
115
+ return `o:${id}`;
116
+ };
117
+ const hash_dep = (dep) => {
118
+ if (dep === null) return "l:null";
119
+ if (dep === void 0) return "u:undefined";
120
+ const type = typeof dep;
121
+ if (type === "string") return ["s", dep];
122
+ if (type === "number") return `n:${Object.is(dep, -0) ? "-0" : String(dep)}`;
123
+ if (type === "bigint") return `b:${dep}`;
124
+ if (type === "boolean") return dep ? "t:true" : "f:false";
125
+ if (type === "symbol") return hash_symbol_dep(dep);
126
+ return hash_object_dep(dep);
127
+ };
128
+ const hash_deps = (deps) => JSON.stringify(deps.map(hash_dep));
129
+ return hash_deps;
130
+ }
131
+ //#endregion
132
+ //#region src/dispatcher/types.ts
133
+ const Code = { Markup: {
134
+ Promise: "MarkupPromise",
135
+ Run: "MarkupRun",
136
+ Value: "MarkupValue"
137
+ } };
138
+ //#endregion
139
+ //#region src/dispatcher/index.ts
140
+ var Dispatcher = class Dispatcher {
141
+ #runtime;
142
+ #fibers = /* @__PURE__ */ new Map();
143
+ #value_cells = /* @__PURE__ */ new Map();
144
+ #notify_value_cells = () => {};
145
+ #subscribe_value_cells = createSubscriber((update) => {
146
+ this.#notify_value_cells = update;
147
+ return () => {
148
+ if (this.#notify_value_cells !== update) return;
149
+ this.#notify_value_cells = () => {};
150
+ };
151
+ });
152
+ #promise_values = /* @__PURE__ */ new Map();
153
+ #value_ids = /* @__PURE__ */ new Map();
154
+ #promise_ids = /* @__PURE__ */ new Map();
155
+ #scope_ids = /* @__PURE__ */ new WeakMap();
156
+ #hash_deps = make_dependency_hasher();
157
+ #disposed = false;
158
+ #next_fiber_id = 0;
159
+ #next_scope_id = 0;
160
+ #root_scope = Scope.makeUnsafe();
161
+ #component_scopes = /* @__PURE__ */ new Set();
162
+ /**
163
+ * The component scope that effect execution currently enters. Set by
164
+ * generated code via {@link with_scope}; `undefined` outside components.
165
+ */
166
+ #current_scope = void 0;
167
+ static make(layer) {
168
+ if (current_dispatcher) throw new RuntimeAlreadyInitializedError("ClientRuntime");
169
+ const runtime = ManagedRuntime.make(layer ?? Layer.empty);
170
+ const dispatcher = new Dispatcher(runtime);
171
+ current_dispatcher = dispatcher;
172
+ return dispatcher;
173
+ }
174
+ constructor(runtime) {
175
+ this.#runtime = runtime ?? ManagedRuntime.make(Layer.empty);
176
+ }
177
+ /**
178
+ * Begin a component-owned Effect scope. Pass the returned scope to
179
+ * {@link run_scoped} so the work is interrupted and finalized when the
180
+ * component is destroyed. Disposal is idempotent.
181
+ */
182
+ begin_scope() {
183
+ const scope = ComponentScope.fork(this.#root_scope, (disposed) => {
184
+ this.#component_scopes.delete(disposed);
185
+ });
186
+ this.#component_scopes.add(scope);
187
+ return scope;
188
+ }
189
+ /**
190
+ * Runs `fn` with `scope` as the current component scope. While active,
191
+ * every effect path ({@link promise}, {@link run}, {@link value}) forks
192
+ * its work into `scope` so disposing the scope interrupts it and runs its
193
+ * finalizers. A disposed scope falls back to unscoped execution.
194
+ */
195
+ with_scope(scope, fn) {
196
+ if (scope.disposed) return fn();
197
+ const previous = this.#current_scope;
198
+ this.#current_scope = scope;
199
+ try {
200
+ return fn();
201
+ } finally {
202
+ this.#current_scope = previous;
203
+ }
204
+ }
205
+ /**
206
+ * Forks an effect into a component scope and starts it. The fiber becomes
207
+ * a child of the scope, so disposing the scope interrupts it and runs its
208
+ * finalizers. Returns an idempotent handle that interrupts the scoped
209
+ * fiber directly.
210
+ *
211
+ * Throws {@link ScopeDisposedError} when the scope was already disposed
212
+ * and {@link DispatcherDisposedError} when the dispatcher was shut down.
213
+ */
214
+ run_scoped(scope, effect) {
215
+ if (this.#disposed) return () => {};
216
+ if (scope.disposed || !this.#component_scopes.has(scope)) throw new ScopeDisposedError();
217
+ /**
218
+ * Track the scoped fiber itself: `forkIn` binds it to the component
219
+ * scope rather than the awaiting parent, so per-run disposal must
220
+ * interrupt the scoped fiber directly.
221
+ */
222
+ let scoped_fiber;
223
+ this.#runtime.runFork(Effect.flatMap(scope.fork_in(effect), (fiber) => {
224
+ scoped_fiber = fiber;
225
+ return Effect.asVoid(Fiber.await(fiber));
226
+ }));
227
+ let disposed = false;
228
+ return () => {
229
+ if (disposed) return;
230
+ disposed = true;
231
+ if (scoped_fiber) this.#runtime.runFork(InterruptFiber(scoped_fiber));
232
+ };
233
+ }
234
+ /**
235
+ * Disposes a component scope owned by this dispatcher, interrupting its
236
+ * bound work and running its finalizers. Idempotent. Rejects scopes owned
237
+ * by another dispatcher with {@link ScopeDisposedError}.
238
+ */
239
+ dispose_scope(scope) {
240
+ if (!this.#component_scopes.has(scope)) {
241
+ if (scope.disposed) return;
242
+ throw new ScopeDisposedError();
243
+ }
244
+ scope.dispose();
245
+ this.#runtime.runFork(scope.close_effect);
246
+ }
247
+ emit(event) {
248
+ switch (event.type) {
249
+ case Code.Markup.Value: return this.#emit_markup_value(event);
250
+ case Code.Markup.Promise: return this.#emit_markup_promise(event);
251
+ case Code.Markup.Run: return this.#emit_markup_run(event);
252
+ }
253
+ }
254
+ fork(effect) {
255
+ if (this.#disposed) return () => {};
256
+ const fiber = this.#runtime.runFork(effect);
257
+ const key = `fork:${this.#next_fiber_id}`;
258
+ this.#next_fiber_id += 1;
259
+ this.#fibers.set(key, fiber);
260
+ this.#runtime.runFork(WatchFiberExit({
261
+ fiber,
262
+ on_complete: () => this.#fibers.delete(key)
263
+ }));
264
+ let disposed = false;
265
+ return () => {
266
+ if (disposed) return;
267
+ disposed = true;
268
+ this.#runtime.runFork(InterruptFiber(fiber));
269
+ };
270
+ }
271
+ value(options) {
272
+ if (this.#disposed) return options.fallback;
273
+ const scope_id = this.#scope_id(this.#current_scope);
274
+ const cache_id = this.#make_scoped_id(scope_id, options.id);
275
+ const cache_key = this.#make_value_cache_key(cache_id, options.deps);
276
+ const old_key = this.#value_ids.get(cache_id);
277
+ this.#subscribe_value_cells();
278
+ const cell = this.#value_cells.get(cache_key);
279
+ if (old_key !== void 0 && old_key !== cache_key) {
280
+ const old_fiber = this.#interrupt_cached_fiber(old_key);
281
+ this.#clear_pending_value_cell(old_key, old_fiber);
282
+ }
283
+ this.#value_ids.set(cache_id, cache_key);
284
+ if (this.#should_start_value_fiber(cache_key, cell)) this.#start_value_fiber(cache_key, options);
285
+ if (cell?.status === "success") return cell.value;
286
+ if (cell?.status === "failure") throw cell.error;
287
+ return options.fallback;
288
+ }
289
+ promise(options) {
290
+ if (this.#disposed) return Promise.reject(new DispatcherDisposedError());
291
+ const scope_id = this.#scope_id(this.#current_scope);
292
+ const cache_id = this.#make_scoped_id(scope_id, options.id);
293
+ const cache_key = this.#make_promise_cache_key(cache_id, options.deps);
294
+ const old_key = this.#promise_ids.get(cache_id);
295
+ if (old_key !== void 0 && old_key !== cache_key) {
296
+ this.#interrupt_cached_fiber(old_key);
297
+ this.#promise_values.delete(old_key);
298
+ }
299
+ this.#promise_ids.set(cache_id, cache_key);
300
+ const existing = this.#promise_values.get(cache_key);
301
+ if (existing) return existing;
302
+ const promise = this.#start_promise_fiber(cache_key, options, cache_id);
303
+ this.#promise_values.set(cache_key, promise);
304
+ return promise;
305
+ }
306
+ run(effect) {
307
+ if (this.#disposed) return Promise.reject(new DispatcherDisposedError());
308
+ const Program = Effect.gen(function* () {
309
+ const result = yield* Effect.exit(effect);
310
+ if (Exit.isSuccess(result)) return result.value;
311
+ if (Cause.hasInterruptsOnly(result.cause)) return;
312
+ const error = Cause.squash(result.cause);
313
+ if (isRedirect(error)) return;
314
+ yield* Effect.sync(() => {
315
+ queueMicrotask(() => {
316
+ throw error;
317
+ });
318
+ });
319
+ return yield* Effect.fail(error);
320
+ });
321
+ const scope = this.#current_scope;
322
+ return this.#runtime.runPromise(scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program);
323
+ }
324
+ #emit_markup_value(event) {
325
+ if (this.#is_server_render()) return event.fallback;
326
+ return this.value({
327
+ id: event.id,
328
+ deps: event.deps,
329
+ fallback: event.fallback,
330
+ factory: event.fn
331
+ });
332
+ }
333
+ #emit_markup_promise(event) {
334
+ if (this.#is_server_render()) {
335
+ if (event.options?.ssr === "pending") return new Promise(() => {});
336
+ if ("ssr_fallback" in event) return Promise.resolve(event.ssr_fallback);
337
+ }
338
+ return this.promise({
339
+ id: event.id,
340
+ deps: event.deps,
341
+ factory: event.fn
342
+ });
343
+ }
344
+ #emit_markup_run(event) {
345
+ const Program = Effect.gen(event.fn);
346
+ return this.run(Program);
347
+ }
348
+ dispose() {
349
+ this.#disposed = true;
350
+ for (const scope of this.#component_scopes) scope.dispose();
351
+ this.#component_scopes.clear();
352
+ this.#runtime.runFork(Scope.close(this.#root_scope, Exit.void));
353
+ for (const fiber of this.#fibers.values()) this.#runtime.runFork(InterruptFiber(fiber));
354
+ this.#fibers.clear();
355
+ this.#clear_value_cells();
356
+ this.#promise_values.clear();
357
+ this.#value_ids.clear();
358
+ this.#promise_ids.clear();
359
+ this.#runtime.dispose().catch((error) => {
360
+ queueMicrotask(() => {
361
+ throw error;
362
+ });
363
+ });
364
+ }
365
+ #make_value_cache_key(id, deps) {
366
+ return `value:${id}::${this.#hash_deps(deps)}`;
367
+ }
368
+ #make_promise_cache_key(id, deps) {
369
+ return `promise:${id}::${this.#hash_deps(deps)}`;
370
+ }
371
+ #is_server_render() {
372
+ return typeof document === "undefined";
373
+ }
374
+ #scope_id(scope) {
375
+ if (!scope || scope.disposed) return "global";
376
+ const existing = this.#scope_ids.get(scope);
377
+ if (existing) return existing;
378
+ const next = String(this.#next_scope_id);
379
+ this.#next_scope_id += 1;
380
+ this.#scope_ids.set(scope, next);
381
+ return next;
382
+ }
383
+ #make_scoped_id(scope_id, id) {
384
+ return `${scope_id}|${id}`;
385
+ }
386
+ #interrupt_cached_fiber(cache_key) {
387
+ const old_fiber = this.#fibers.get(cache_key);
388
+ if (!old_fiber) return;
389
+ this.#runtime.runFork(InterruptFiber(old_fiber));
390
+ this.#fibers.delete(cache_key);
391
+ return old_fiber;
392
+ }
393
+ #should_start_value_fiber(cache_key, cell) {
394
+ return !this.#disposed && !this.#fibers.has(cache_key) && cell === void 0;
395
+ }
396
+ #start_value_fiber(cache_key, options) {
397
+ const Program = Effect.gen(function* () {
398
+ return yield* Effect.gen(options.factory);
399
+ });
400
+ /**
401
+ * Provide the active component scope so scoped acquisition works and
402
+ * finalizers run when the scope closes on unmount. Interruption of an
403
+ * individual run does not close the component scope; its finalizers
404
+ * run at scope disposal, matching the component lifetime.
405
+ */
406
+ const scope = this.#current_scope;
407
+ const ScopedProgram = scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program;
408
+ const fiber = this.#runtime.runFork(ScopedProgram);
409
+ this.#fibers.set(cache_key, fiber);
410
+ queueMicrotask(() => {
411
+ if (!this.#is_current_fiber(cache_key, fiber)) return;
412
+ if (this.#value_cells.has(cache_key)) return;
413
+ this.#set_value_cell(cache_key, {
414
+ status: "pending",
415
+ fiber
416
+ });
417
+ });
418
+ this.#runtime.runFork(WatchFiberExit({
419
+ fiber,
420
+ surface_failure: false,
421
+ on_complete: () => this.#complete_fiber(cache_key, fiber),
422
+ on_success: (value) => this.#publish_value_success(cache_key, fiber, value),
423
+ on_failure: (error) => this.#publish_value_failure(cache_key, fiber, error)
424
+ }));
425
+ }
426
+ #start_promise_fiber(cache_key, options, cache_id) {
427
+ const Program = Effect.gen(function* () {
428
+ return yield* Effect.gen(options.factory);
429
+ });
430
+ /**
431
+ * See #start_value_fiber: the component scope is provided ambiently so
432
+ * scoped acquisition works and finalizers run on unmount.
433
+ */
434
+ const scope = this.#current_scope;
435
+ const ScopedProgram = scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program;
436
+ const fiber = this.#runtime.runFork(ScopedProgram);
437
+ const ReleaseFiber = Effect.sync(() => {
438
+ if (!this.#is_current_fiber(cache_key, fiber)) return;
439
+ this.#fibers.delete(cache_key);
440
+ this.#promise_values.delete(cache_key);
441
+ if (this.#promise_ids.get(cache_id) === cache_key) this.#promise_ids.delete(cache_id);
442
+ });
443
+ const AwaitFiber = Effect.gen(function* () {
444
+ const exit = yield* Fiber.await(fiber);
445
+ yield* ReleaseFiber;
446
+ if (Exit.isSuccess(exit)) return exit.value;
447
+ return yield* Effect.fail(Cause.squash(exit.cause));
448
+ });
449
+ this.#fibers.set(cache_key, fiber);
450
+ return this.#runtime.runPromise(AwaitFiber);
451
+ }
452
+ #clear_pending_value_cell(cache_key, fiber) {
453
+ const cell = this.#value_cells.get(cache_key);
454
+ if (cell?.status !== "pending") return;
455
+ if (fiber !== void 0 && cell.fiber !== fiber) return;
456
+ this.#delete_value_cell(cache_key);
457
+ }
458
+ #complete_fiber(cache_key, fiber) {
459
+ if (!this.#is_current_fiber(cache_key, fiber)) return;
460
+ this.#fibers.delete(cache_key);
461
+ }
462
+ #publish_value_success(cache_key, fiber, value) {
463
+ if (!this.#is_current_fiber(cache_key, fiber)) return;
464
+ this.#set_value_cell(cache_key, {
465
+ status: "success",
466
+ value
467
+ });
468
+ }
469
+ #publish_value_failure(cache_key, fiber, error) {
470
+ if (!this.#is_current_fiber(cache_key, fiber)) return;
471
+ this.#set_value_cell(cache_key, {
472
+ status: "failure",
473
+ error
474
+ });
475
+ }
476
+ #set_value_cell(cache_key, cell) {
477
+ this.#value_cells.set(cache_key, cell);
478
+ this.#notify_value_cells();
479
+ }
480
+ #delete_value_cell(cache_key) {
481
+ if (!this.#value_cells.delete(cache_key)) return;
482
+ this.#notify_value_cells();
483
+ }
484
+ #clear_value_cells() {
485
+ if (this.#value_cells.size === 0) return;
486
+ this.#value_cells.clear();
487
+ this.#notify_value_cells();
488
+ }
489
+ #is_current_fiber(cache_key, fiber) {
490
+ return !this.#disposed && this.#fibers.get(cache_key) === fiber;
491
+ }
492
+ };
493
+ let current_dispatcher = null;
494
+ function get_dispatcher() {
495
+ current_dispatcher ??= new Dispatcher();
496
+ return current_dispatcher;
497
+ }
498
+ function reset_dispatcher() {
499
+ current_dispatcher?.dispose();
500
+ current_dispatcher = null;
501
+ }
502
+ /**
503
+ * Lazily-created component scope used by generated component code.
504
+ *
505
+ * The holder is created synchronously during component init (before any
506
+ * top-level `await`, where `onDestroy` is not yet available), and the scope
507
+ * itself is materialized on first use. Disposal is registered separately
508
+ * through `onDestroy` during component initialisation, so the scope is
509
+ * reliably closed on unmount.
510
+ *
511
+ * @since 4.1.0
512
+ */
513
+ var ComponentScopeRef = class {
514
+ #get_dispatcher;
515
+ #scope;
516
+ constructor(get_dispatcher_fn) {
517
+ this.#get_dispatcher = get_dispatcher_fn;
518
+ }
519
+ /** The component scope, creating it on first access. */
520
+ get scope() {
521
+ this.#scope ??= this.#get_dispatcher().begin_scope();
522
+ return this.#scope;
523
+ }
524
+ /** Disposes the scope if it was created. Idempotent. */
525
+ dispose() {
526
+ const scope = this.#scope;
527
+ this.#scope = void 0;
528
+ if (scope && !scope.disposed) this.#get_dispatcher().dispose_scope(scope);
529
+ }
530
+ };
531
+ //#endregion
532
+ export { Code as a, reset_dispatcher as i, Dispatcher as n, ComponentScope as o, get_dispatcher as r, ComponentScopeRef as t };
533
+
534
+ //# sourceMappingURL=dispatcher-CTWINW5I.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher-CTWINW5I.js","names":["#on_dispose","#scope","#disposed","#notify_value_cells","#runtime","#root_scope","#component_scopes","#current_scope","#disposed","#emit_markup_value","#emit_markup_promise","#emit_markup_run","#next_fiber_id","#fibers","#scope_id","#make_scoped_id","#make_value_cache_key","#value_ids","#subscribe_value_cells","#value_cells","#interrupt_cached_fiber","#clear_pending_value_cell","#should_start_value_fiber","#start_value_fiber","#make_promise_cache_key","#promise_ids","#promise_values","#start_promise_fiber","#is_server_render","#clear_value_cells","#hash_deps","#scope_ids","#next_scope_id","#is_current_fiber","#set_value_cell","#complete_fiber","#publish_value_success","#publish_value_failure","#delete_value_cell","#get_dispatcher","#scope"],"sources":["../../../modules/svelte-effect-runtime/src/dispatcher/fibers.ts","../../../modules/svelte-effect-runtime/src/dispatcher/scope.ts","../../../modules/svelte-effect-runtime/src/dispatcher/deps.ts","../../../modules/svelte-effect-runtime/src/dispatcher/types.ts","../../../modules/svelte-effect-runtime/src/dispatcher/index.ts"],"sourcesContent":["import type { Fiber as FiberType } from \"effect/Fiber\";\nimport { Cause, Effect, Exit, Fiber } from \"effect\";\n\nexport interface FiberWatchCallbacks<A> {\n\ton_complete?: () => void;\n\ton_success?: (value: A) => void;\n\ton_failure?: (error: unknown) => void;\n\tsurface_failure?: boolean;\n}\n\nexport const InterruptFiber = (fiber: FiberType<unknown, unknown>) =>\n\tEffect.gen(function* () {\n\t\tyield* Fiber.interrupt(fiber);\n\t});\n\n/** Observes fiber completion and surfaces failures without taking ownership of the fiber. */\nexport const WatchFiberExit = <A>(\n\toptions: { fiber: FiberType<unknown, unknown> } & FiberWatchCallbacks<A>,\n) => {\n\tconst { fiber, on_complete, on_success, on_failure, surface_failure = true } = options;\n\n\treturn Effect.gen(function* () {\n\t\tconst exit = yield* Fiber.await(fiber);\n\n\t\tyield* Effect.sync(() => {\n\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\ton_success?.(exit.value as A);\n\t\t\t\ton_complete?.();\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!Cause.hasInterruptsOnly(exit.cause)) {\n\t\t\t\tconst error = Cause.squash(exit.cause);\n\n\t\t\t\ton_failure?.(error);\n\n\t\t\t\tif (surface_failure) {\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ton_complete?.();\n\t\t});\n\t});\n};\n","import { Effect, Exit, Scope } from \"effect\";\nimport type { Fiber } from \"effect\";\n\n/**\n * A component-owned Effect scope.\n *\n * A `ComponentScope` wraps a `Scope.Closeable` forked from the dispatcher's\n * root scope. Work is forked into the scope with `Effect.forkIn`, so closing\n * the scope interrupts that work and runs its finalizers. The generated\n * component teardown disposes the scope on destroy. Disposal is idempotent.\n *\n * @since 4.1.0\n */\nexport class ComponentScope {\n\t#scope: Scope.Closeable;\n\t#disposed = false;\n\treadonly #on_dispose: (scope: ComponentScope) => void;\n\n\tprivate constructor(scope: Scope.Closeable, on_dispose: (scope: ComponentScope) => void) {\n\t\tthis.#scope = scope;\n\t\tthis.#on_dispose = on_dispose;\n\t}\n\n\t/** Forks a child scope from the given root and returns it wrapped. */\n\tstatic fork(\n\t\troot: Scope.Closeable,\n\t\ton_dispose: (scope: ComponentScope) => void,\n\t): ComponentScope {\n\t\treturn new ComponentScope(Scope.forkUnsafe(root), on_dispose);\n\t}\n\n\t/** The underlying closeable scope used to bind Effect work. */\n\tget underlying(): Scope.Closeable {\n\t\treturn this.#scope;\n\t}\n\n\t/** Whether this scope has already been disposed. */\n\tget disposed(): boolean {\n\t\treturn this.#disposed;\n\t}\n\n\t/**\n\t * Forks an effect into this scope. The fiber becomes a child of the scope,\n\t * so disposing the scope interrupts it and runs its finalizers. The scope\n\t * is provided ambiently so `Effect.forkIn` registers the fiber as a child.\n\t */\n\tfork_in<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<Fiber.Fiber<A, E>, never, R> {\n\t\t/**\n\t\t * The effect must see the scope before it is forked: provide the scope\n\t\t * inside the forked program so `acquireRelease`-style work resolves it,\n\t\t * and fork that program into the scope so the fiber is a child whose\n\t\t * finalizers run when the scope closes.\n\t\t */\n\t\treturn Effect.forkIn(\n\t\t\tEffect.provideService(effect, Scope.Scope, this.#scope),\n\t\t\tthis.#scope,\n\t\t) as Effect.Effect<Fiber.Fiber<A, E>, never, R>;\n\t}\n\n\t/** Effect that closes the scope. Must be run by the owning dispatcher. */\n\tget close_effect(): Effect.Effect<void> {\n\t\treturn Scope.close(this.#scope, Exit.void);\n\t}\n\n\t/**\n\t * Marks the scope disposed and detaches it from the dispatcher. The caller\n\t * is responsible for running {@link close_effect} to run finalizers.\n\t * Idempotent.\n\t */\n\tdispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#disposed = true;\n\t\tthis.#on_dispose(this);\n\t}\n}\n","/** Assigns stable identities to object dependencies while hashing value dependencies. */\nexport type DependencyHasher = (deps: readonly unknown[]) => string;\n\nexport function make_dependency_hasher(): DependencyHasher {\n\tconst object_dep_ids = new WeakMap<object, number>();\n\tconst symbol_dep_ids = new Map<symbol, number>();\n\n\tlet next_object_dep_id = 0;\n\tlet next_symbol_dep_id = 0;\n\n\tconst hash_symbol_dep = (dep: symbol): string => {\n\t\tlet id = symbol_dep_ids.get(dep);\n\n\t\tif (id === undefined) {\n\t\t\tnext_symbol_dep_id += 1;\n\t\t\tid = next_symbol_dep_id;\n\t\t\tsymbol_dep_ids.set(dep, id);\n\t\t}\n\n\t\treturn `y:${id}`;\n\t};\n\n\tconst hash_object_dep = (dep: object): string => {\n\t\tlet id = object_dep_ids.get(dep);\n\n\t\tif (id === undefined) {\n\t\t\tnext_object_dep_id += 1;\n\t\t\tid = next_object_dep_id;\n\t\t\tobject_dep_ids.set(dep, id);\n\t\t}\n\n\t\treturn `o:${id}`;\n\t};\n\n\tconst hash_dep = (dep: unknown): string | readonly [\"s\", string] => {\n\t\tif (dep === null) {\n\t\t\treturn \"l:null\";\n\t\t}\n\n\t\tif (dep === undefined) {\n\t\t\treturn \"u:undefined\";\n\t\t}\n\n\t\tconst type = typeof dep;\n\n\t\tif (type === \"string\") {\n\t\t\treturn [\"s\", dep as string];\n\t\t}\n\n\t\tif (type === \"number\") {\n\t\t\treturn `n:${Object.is(dep, -0) ? \"-0\" : String(dep)}`;\n\t\t}\n\n\t\tif (type === \"bigint\") {\n\t\t\treturn `b:${dep}`;\n\t\t}\n\n\t\tif (type === \"boolean\") {\n\t\t\treturn dep ? \"t:true\" : \"f:false\";\n\t\t}\n\n\t\tif (type === \"symbol\") {\n\t\t\treturn hash_symbol_dep(dep as symbol);\n\t\t}\n\n\t\treturn hash_object_dep(dep as object);\n\t};\n\n\tconst hash_deps = (deps: readonly unknown[]): string => JSON.stringify(deps.map(hash_dep));\n\n\treturn hash_deps;\n}\n","import type { Effect } from \"effect\";\n\nexport const Code = {\n\tMarkup: {\n\t\tPromise: \"MarkupPromise\",\n\t\tRun: \"MarkupRun\",\n\t\tValue: \"MarkupValue\",\n\t},\n} as const;\n\nexport interface MarkupPromiseOptions {\n\t/** Keep the SSR promise pending so Svelte renders an await block fallback. */\n\tssr?: \"pending\";\n}\n\nexport type Dispose = () => void;\n\nexport interface ValueOptions<A> {\n\t/** Stable cache key for this value block. */\n\tid: string;\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is running or during SSR. */\n\tfallback: A;\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface PromiseOptions<A> {\n\t/** Stable cache key for this promise block. */\n\tid: string;\n\tdeps: readonly unknown[];\n\tfactory: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface MarkupValueEvent<A, F> {\n\ttype: typeof Code.Markup.Value;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\tdeps: readonly unknown[];\n\t/** Value returned synchronously while the effect is pending. */\n\tfallback: F;\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport interface MarkupPromiseEvent<A> {\n\ttype: typeof Code.Markup.Promise;\n\t/** Stable identifier generated from the expression's source position. */\n\tid: string;\n\tdeps: readonly unknown[];\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n\t/** Value resolved during SSR when a fallback is required. */\n\tssr_fallback?: A;\n\t/** Optional SSR behavior for await blocks and similar contexts. */\n\toptions?: MarkupPromiseOptions;\n}\n\nexport interface MarkupRunEvent<A> {\n\ttype: typeof Code.Markup.Run;\n\tfn: () => Effect.gen.Return<A, unknown, unknown>;\n}\n\nexport type DispatcherEvent<A, F = A> =\n\t| MarkupPromiseEvent<A>\n\t| MarkupRunEvent<A>\n\t| MarkupValueEvent<A, F>;\n","import type {\n\tDispatcherEvent,\n\tDispose,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n\tPromiseOptions,\n\tValueOptions,\n} from \"./types.ts\";\nimport {\n\tRuntimeAlreadyInitializedError,\n\tDispatcherDisposedError,\n\tScopeDisposedError,\n} from \"$/errors.ts\";\nimport type { ManagedRuntime as ManagedRuntimeType } from \"effect/ManagedRuntime\";\nimport { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime, Scope } from \"effect\";\nimport { InterruptFiber, WatchFiberExit } from \"./fibers.ts\";\nimport { ComponentScope } from \"./scope.ts\";\nimport type { Fiber as FiberType } from \"effect/Fiber\";\nimport { createSubscriber } from \"svelte/reactivity\";\nimport { make_dependency_hasher } from \"./deps.ts\";\nimport { isRedirect } from \"@sveltejs/kit\";\nimport { Code } from \"./types.ts\";\n\nexport { Code } from \"./types.ts\";\nexport type { Dispose, PromiseOptions, ValueOptions } from \"./types.ts\";\n\ntype ValueCell<A> =\n\t| {\n\t\t\treadonly status: \"pending\";\n\t\t\treadonly fiber: FiberType<unknown, unknown>;\n\t }\n\t| {\n\t\t\treadonly status: \"success\";\n\t\t\treadonly value: A;\n\t }\n\t| {\n\t\t\treadonly status: \"failure\";\n\t\t\treadonly error: unknown;\n\t };\n\nexport class Dispatcher {\n\t#runtime: ManagedRuntimeType<unknown, unknown>;\n\t#fibers = new Map<string, FiberType<unknown, unknown>>();\n\t#value_cells = new Map<string, ValueCell<unknown>>();\n\t#notify_value_cells = (): void => {};\n\t#subscribe_value_cells = createSubscriber((update) => {\n\t\tthis.#notify_value_cells = update;\n\n\t\treturn () => {\n\t\t\tif (this.#notify_value_cells !== update) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#notify_value_cells = (): void => {};\n\t\t};\n\t});\n\t#promise_values = new Map<string, Promise<unknown>>();\n\t#value_ids = new Map<string, string>();\n\t#promise_ids = new Map<string, string>();\n\t#scope_ids = new WeakMap<ComponentScope, string>();\n\t#hash_deps = make_dependency_hasher();\n\t#disposed = false;\n\t#next_fiber_id = 0;\n\t#next_scope_id = 0;\n\t#root_scope = Scope.makeUnsafe();\n\t#component_scopes = new Set<ComponentScope>();\n\t/**\n\t * The component scope that effect execution currently enters. Set by\n\t * generated code via {@link with_scope}; `undefined` outside components.\n\t */\n\t#current_scope: ComponentScope | undefined = undefined;\n\n\tstatic make<R = never>(layer?: Layer.Layer<R>): Dispatcher {\n\t\tif (current_dispatcher) {\n\t\t\tthrow new RuntimeAlreadyInitializedError(\"ClientRuntime\");\n\t\t}\n\n\t\tconst runtime = ManagedRuntime.make(layer ?? (Layer.empty as unknown as Layer.Layer<R>));\n\n\t\tconst dispatcher = new Dispatcher(runtime as ManagedRuntimeType<unknown, unknown>);\n\t\tcurrent_dispatcher = dispatcher;\n\n\t\treturn dispatcher;\n\t}\n\n\tconstructor(runtime?: ManagedRuntimeType<unknown, unknown>) {\n\t\tthis.#runtime =\n\t\t\truntime ??\n\t\t\t(ManagedRuntime.make(Layer.empty) as unknown as ManagedRuntimeType<unknown, unknown>);\n\t}\n\n\t/**\n\t * Begin a component-owned Effect scope. Pass the returned scope to\n\t * {@link run_scoped} so the work is interrupted and finalized when the\n\t * component is destroyed. Disposal is idempotent.\n\t */\n\tbegin_scope(): ComponentScope {\n\t\tconst scope = ComponentScope.fork(this.#root_scope, (disposed) => {\n\t\t\tthis.#component_scopes.delete(disposed);\n\t\t});\n\n\t\tthis.#component_scopes.add(scope);\n\n\t\treturn scope;\n\t}\n\n\t/**\n\t * Runs `fn` with `scope` as the current component scope. While active,\n\t * every effect path ({@link promise}, {@link run}, {@link value}) forks\n\t * its work into `scope` so disposing the scope interrupts it and runs its\n\t * finalizers. A disposed scope falls back to unscoped execution.\n\t */\n\twith_scope<T>(scope: ComponentScope, fn: () => T): T {\n\t\tif (scope.disposed) {\n\t\t\treturn fn();\n\t\t}\n\n\t\tconst previous = this.#current_scope;\n\t\tthis.#current_scope = scope;\n\n\t\ttry {\n\t\t\treturn fn();\n\t\t} finally {\n\t\t\tthis.#current_scope = previous;\n\t\t}\n\t}\n\n\t/**\n\t * Forks an effect into a component scope and starts it. The fiber becomes\n\t * a child of the scope, so disposing the scope interrupts it and runs its\n\t * finalizers. Returns an idempotent handle that interrupts the scoped\n\t * fiber directly.\n\t *\n\t * Throws {@link ScopeDisposedError} when the scope was already disposed\n\t * and {@link DispatcherDisposedError} when the dispatcher was shut down.\n\t */\n\trun_scoped<A, E, R>(scope: ComponentScope, effect: Effect.Effect<A, E, R>): Dispose {\n\t\tif (this.#disposed) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tif (scope.disposed || !this.#component_scopes.has(scope)) {\n\t\t\tthrow new ScopeDisposedError();\n\t\t}\n\n\t\t/**\n\t\t * Track the scoped fiber itself: `forkIn` binds it to the component\n\t\t * scope rather than the awaiting parent, so per-run disposal must\n\t\t * interrupt the scoped fiber directly.\n\t\t */\n\t\tlet scoped_fiber: FiberType<unknown, unknown> | undefined;\n\n\t\tthis.#runtime.runFork(\n\t\t\tEffect.flatMap(scope.fork_in(effect), (fiber) => {\n\t\t\t\tscoped_fiber = fiber;\n\n\t\t\t\treturn Effect.asVoid(Fiber.await(fiber));\n\t\t\t}) as Effect.Effect<unknown, unknown, unknown>,\n\t\t);\n\n\t\tlet disposed = false;\n\n\t\treturn (): void => {\n\t\t\tif (disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdisposed = true;\n\n\t\t\tif (scoped_fiber) {\n\t\t\t\tthis.#runtime.runFork(InterruptFiber(scoped_fiber));\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Disposes a component scope owned by this dispatcher, interrupting its\n\t * bound work and running its finalizers. Idempotent. Rejects scopes owned\n\t * by another dispatcher with {@link ScopeDisposedError}.\n\t */\n\tdispose_scope(scope: ComponentScope): void {\n\t\tif (!this.#component_scopes.has(scope)) {\n\t\t\tif (scope.disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthrow new ScopeDisposedError();\n\t\t}\n\n\t\tscope.dispose();\n\t\tthis.#runtime.runFork(scope.close_effect as Effect.Effect<unknown, unknown, unknown>);\n\t}\n\n\temit<A, F>(event: MarkupValueEvent<A, F>): A | F;\n\temit<A>(event: MarkupPromiseEvent<A>): Promise<A>;\n\temit<A>(event: MarkupRunEvent<A>): Promise<A>;\n\temit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;\n\temit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A> {\n\t\tswitch (event.type) {\n\t\t\tcase Code.Markup.Value:\n\t\t\t\treturn this.#emit_markup_value(event);\n\n\t\t\tcase Code.Markup.Promise:\n\t\t\t\treturn this.#emit_markup_promise(event);\n\n\t\t\tcase Code.Markup.Run:\n\t\t\t\treturn this.#emit_markup_run(event);\n\t\t}\n\t}\n\n\tfork<A, E, R>(effect: Effect.Effect<A, E, R>): Dispose {\n\t\tif (this.#disposed) {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst fiber = this.#runtime.runFork(effect as Effect.Effect<unknown, unknown, unknown>);\n\t\tconst key = `fork:${this.#next_fiber_id}`;\n\n\t\tthis.#next_fiber_id += 1;\n\t\tthis.#fibers.set(key, fiber);\n\t\tthis.#runtime.runFork(\n\t\t\tWatchFiberExit({\n\t\t\t\tfiber,\n\t\t\t\ton_complete: () => this.#fibers.delete(key),\n\t\t\t}),\n\t\t);\n\n\t\tlet disposed = false;\n\n\t\treturn (): void => {\n\t\t\tif (disposed) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdisposed = true;\n\t\t\tthis.#runtime.runFork(InterruptFiber(fiber));\n\t\t};\n\t}\n\n\tvalue<A>(options: ValueOptions<A>): A {\n\t\tif (this.#disposed) {\n\t\t\treturn options.fallback;\n\t\t}\n\n\t\tconst scope_id = this.#scope_id(this.#current_scope);\n\t\tconst cache_id = this.#make_scoped_id(scope_id, options.id);\n\t\tconst cache_key = this.#make_value_cache_key(cache_id, options.deps);\n\t\tconst old_key = this.#value_ids.get(cache_id);\n\n\t\tthis.#subscribe_value_cells();\n\n\t\tconst cell = this.#value_cells.get(cache_key);\n\n\t\tif (old_key !== undefined && old_key !== cache_key) {\n\t\t\tconst old_fiber = this.#interrupt_cached_fiber(old_key);\n\n\t\t\tthis.#clear_pending_value_cell(old_key, old_fiber);\n\t\t}\n\n\t\tthis.#value_ids.set(cache_id, cache_key);\n\n\t\tif (this.#should_start_value_fiber(cache_key, cell)) {\n\t\t\tthis.#start_value_fiber(cache_key, options);\n\t\t}\n\n\t\tif (cell?.status === \"success\") {\n\t\t\treturn cell.value as A;\n\t\t}\n\n\t\tif (cell?.status === \"failure\") {\n\t\t\tthrow cell.error;\n\t\t}\n\n\t\treturn options.fallback;\n\t}\n\n\tpromise<A>(options: PromiseOptions<A>): Promise<A> {\n\t\tif (this.#disposed) {\n\t\t\treturn Promise.reject(new DispatcherDisposedError());\n\t\t}\n\n\t\tconst scope_id = this.#scope_id(this.#current_scope);\n\t\tconst cache_id = this.#make_scoped_id(scope_id, options.id);\n\t\tconst cache_key = this.#make_promise_cache_key(cache_id, options.deps);\n\t\tconst old_key = this.#promise_ids.get(cache_id);\n\n\t\tif (old_key !== undefined && old_key !== cache_key) {\n\t\t\tthis.#interrupt_cached_fiber(old_key);\n\t\t\tthis.#promise_values.delete(old_key);\n\t\t}\n\n\t\tthis.#promise_ids.set(cache_id, cache_key);\n\n\t\tconst existing = this.#promise_values.get(cache_key);\n\n\t\tif (existing) {\n\t\t\treturn existing as Promise<A>;\n\t\t}\n\n\t\tconst promise = this.#start_promise_fiber(cache_key, options, cache_id);\n\n\t\tthis.#promise_values.set(cache_key, promise);\n\n\t\treturn promise;\n\t}\n\n\trun<A, E, R>(effect: Effect.Effect<A, E, R>): Promise<A> {\n\t\tif (this.#disposed) {\n\t\t\treturn Promise.reject(new DispatcherDisposedError());\n\t\t}\n\n\t\tconst Program = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.exit(effect);\n\n\t\t\tif (Exit.isSuccess(result)) {\n\t\t\t\treturn result.value;\n\t\t\t}\n\n\t\t\tif (Cause.hasInterruptsOnly(result.cause)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\tconst error = Cause.squash(result.cause);\n\n\t\t\tif (isRedirect(error)) {\n\t\t\t\treturn undefined as A;\n\t\t\t}\n\n\t\t\tyield* Effect.sync(() => {\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t});\n\n\t\t\treturn yield* Effect.fail(error);\n\t\t});\n\n\t\tconst scope = this.#current_scope;\n\n\t\treturn this.#runtime.runPromise(\n\t\t\t(scope\n\t\t\t\t? Effect.provideService(Program, Scope.Scope, scope.underlying)\n\t\t\t\t: Program) as Effect.Effect<A, unknown, unknown>,\n\t\t);\n\t}\n\n\t#emit_markup_value<A, F>(event: MarkupValueEvent<A, F>): A | F {\n\t\tif (this.#is_server_render()) {\n\t\t\treturn event.fallback;\n\t\t}\n\n\t\treturn this.value<A | F>({\n\t\t\tid: event.id,\n\t\t\tdeps: event.deps,\n\t\t\tfallback: event.fallback,\n\t\t\tfactory: event.fn,\n\t\t});\n\t}\n\n\t#emit_markup_promise<A>(event: MarkupPromiseEvent<A>): Promise<A> {\n\t\tif (this.#is_server_render()) {\n\t\t\tif (event.options?.ssr === \"pending\") {\n\t\t\t\treturn new Promise<A>(() => {});\n\t\t\t}\n\n\t\t\tif (\"ssr_fallback\" in event) {\n\t\t\t\treturn Promise.resolve(event.ssr_fallback as A);\n\t\t\t}\n\t\t}\n\n\t\treturn this.promise({\n\t\t\tid: event.id,\n\t\t\tdeps: event.deps,\n\t\t\tfactory: event.fn,\n\t\t});\n\t}\n\n\t#emit_markup_run<A>(event: MarkupRunEvent<A>): Promise<A> {\n\t\tconst Program = Effect.gen(event.fn);\n\n\t\treturn this.run(Program);\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\n\t\tfor (const scope of this.#component_scopes) {\n\t\t\tscope.dispose();\n\t\t}\n\n\t\tthis.#component_scopes.clear();\n\t\tthis.#runtime.runFork(\n\t\t\tScope.close(this.#root_scope, Exit.void) as Effect.Effect<unknown, unknown, unknown>,\n\t\t);\n\n\t\tfor (const fiber of this.#fibers.values()) {\n\t\t\tthis.#runtime.runFork(InterruptFiber(fiber));\n\t\t}\n\n\t\tthis.#fibers.clear();\n\t\tthis.#clear_value_cells();\n\t\tthis.#promise_values.clear();\n\t\tthis.#value_ids.clear();\n\t\tthis.#promise_ids.clear();\n\n\t\tvoid this.#runtime.dispose().catch((error: unknown) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t});\n\t}\n\n\t#make_value_cache_key(id: string, deps: readonly unknown[]): string {\n\t\treturn `value:${id}::${this.#hash_deps(deps)}`;\n\t}\n\n\t#make_promise_cache_key(id: string, deps: readonly unknown[]): string {\n\t\treturn `promise:${id}::${this.#hash_deps(deps)}`;\n\t}\n\n\t#is_server_render(): boolean {\n\t\treturn typeof document === \"undefined\";\n\t}\n\n\t#scope_id(scope: ComponentScope | undefined): string {\n\t\tif (!scope || scope.disposed) {\n\t\t\treturn \"global\";\n\t\t}\n\n\t\tconst existing = this.#scope_ids.get(scope);\n\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst next = String(this.#next_scope_id);\n\t\tthis.#next_scope_id += 1;\n\t\tthis.#scope_ids.set(scope, next);\n\n\t\treturn next;\n\t}\n\n\t#make_scoped_id(scope_id: string, id: string): string {\n\t\treturn `${scope_id}|${id}`;\n\t}\n\n\t#interrupt_cached_fiber(cache_key: string): FiberType<unknown, unknown> | undefined {\n\t\tconst old_fiber = this.#fibers.get(cache_key);\n\n\t\tif (!old_fiber) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tthis.#runtime.runFork(InterruptFiber(old_fiber));\n\t\tthis.#fibers.delete(cache_key);\n\n\t\treturn old_fiber;\n\t}\n\n\t#should_start_value_fiber(cache_key: string, cell: ValueCell<unknown> | undefined): boolean {\n\t\treturn !this.#disposed && !this.#fibers.has(cache_key) && cell === undefined;\n\t}\n\n\t#start_value_fiber<A>(cache_key: string, options: ValueOptions<A>): void {\n\t\tconst Program = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.gen(options.factory);\n\n\t\t\treturn result;\n\t\t});\n\t\t/**\n\t\t * Provide the active component scope so scoped acquisition works and\n\t\t * finalizers run when the scope closes on unmount. Interruption of an\n\t\t * individual run does not close the component scope; its finalizers\n\t\t * run at scope disposal, matching the component lifetime.\n\t\t */\n\t\tconst scope = this.#current_scope;\n\t\tconst ScopedProgram = scope\n\t\t\t? Effect.provideService(Program, Scope.Scope, scope.underlying)\n\t\t\t: Program;\n\t\tconst fiber = this.#runtime.runFork(ScopedProgram as Effect.Effect<unknown, unknown, unknown>);\n\n\t\tthis.#fibers.set(cache_key, fiber);\n\n\t\tqueueMicrotask(() => {\n\t\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (this.#value_cells.has(cache_key)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#set_value_cell(cache_key, {\n\t\t\t\tstatus: \"pending\",\n\t\t\t\tfiber,\n\t\t\t});\n\t\t});\n\n\t\tthis.#runtime.runFork(\n\t\t\tWatchFiberExit({\n\t\t\t\tfiber,\n\t\t\t\tsurface_failure: false,\n\t\t\t\ton_complete: () => this.#complete_fiber(cache_key, fiber),\n\t\t\t\ton_success: (value) => this.#publish_value_success(cache_key, fiber, value),\n\t\t\t\ton_failure: (error) => this.#publish_value_failure(cache_key, fiber, error),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#start_promise_fiber<A>(\n\t\tcache_key: string,\n\t\toptions: PromiseOptions<A>,\n\t\tcache_id: string,\n\t): Promise<A> {\n\t\tconst Program = Effect.gen(function* () {\n\t\t\tconst result = yield* Effect.gen(options.factory);\n\n\t\t\treturn result;\n\t\t});\n\t\t/**\n\t\t * See #start_value_fiber: the component scope is provided ambiently so\n\t\t * scoped acquisition works and finalizers run on unmount.\n\t\t */\n\t\tconst scope = this.#current_scope;\n\t\tconst ScopedProgram = scope\n\t\t\t? Effect.provideService(Program, Scope.Scope, scope.underlying)\n\t\t\t: Program;\n\t\tconst fiber = this.#runtime.runFork(ScopedProgram as Effect.Effect<unknown, unknown, unknown>);\n\t\tconst ReleaseFiber = Effect.sync(() => {\n\t\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#fibers.delete(cache_key);\n\t\t\tthis.#promise_values.delete(cache_key);\n\n\t\t\tif (this.#promise_ids.get(cache_id) === cache_key) {\n\t\t\t\tthis.#promise_ids.delete(cache_id);\n\t\t\t}\n\t\t});\n\t\tconst AwaitFiber = Effect.gen(function* () {\n\t\t\tconst exit = yield* Fiber.await(fiber);\n\n\t\t\tyield* ReleaseFiber;\n\n\t\t\tif (Exit.isSuccess(exit)) {\n\t\t\t\treturn exit.value as A;\n\t\t\t}\n\n\t\t\treturn yield* Effect.fail(Cause.squash(exit.cause));\n\t\t});\n\n\t\tthis.#fibers.set(cache_key, fiber);\n\n\t\treturn this.#runtime.runPromise(AwaitFiber);\n\t}\n\n\t#clear_pending_value_cell(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown> | undefined,\n\t): void {\n\t\tconst cell = this.#value_cells.get(cache_key);\n\n\t\tif (cell?.status !== \"pending\") {\n\t\t\treturn;\n\t\t}\n\n\t\tif (fiber !== undefined && cell.fiber !== fiber) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#delete_value_cell(cache_key);\n\t}\n\n\t#complete_fiber(cache_key: string, fiber: FiberType<unknown, unknown>): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#fibers.delete(cache_key);\n\t}\n\n\t#publish_value_success<A>(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown>,\n\t\tvalue: A,\n\t): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#set_value_cell(cache_key, {\n\t\t\tstatus: \"success\",\n\t\t\tvalue,\n\t\t});\n\t}\n\n\t#publish_value_failure(\n\t\tcache_key: string,\n\t\tfiber: FiberType<unknown, unknown>,\n\t\terror: unknown,\n\t): void {\n\t\tif (!this.#is_current_fiber(cache_key, fiber)) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#set_value_cell(cache_key, {\n\t\t\tstatus: \"failure\",\n\t\t\terror,\n\t\t});\n\t}\n\n\t#set_value_cell(cache_key: string, cell: ValueCell<unknown>): void {\n\t\tthis.#value_cells.set(cache_key, cell);\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#delete_value_cell(cache_key: string): void {\n\t\tconst deleted = this.#value_cells.delete(cache_key);\n\n\t\tif (!deleted) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#clear_value_cells(): void {\n\t\tif (this.#value_cells.size === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#value_cells.clear();\n\t\tthis.#notify_value_cells();\n\t}\n\n\t#is_current_fiber(cache_key: string, fiber: FiberType<unknown, unknown>): boolean {\n\t\treturn !this.#disposed && this.#fibers.get(cache_key) === fiber;\n\t}\n}\n\nlet current_dispatcher: Dispatcher | null = null;\n\nexport function get_dispatcher(): Dispatcher {\n\tcurrent_dispatcher ??= new Dispatcher();\n\n\treturn current_dispatcher;\n}\n\nexport function reset_dispatcher(): void {\n\tcurrent_dispatcher?.dispose();\n\tcurrent_dispatcher = null;\n}\n\n/**\n * Lazily-created component scope used by generated component code.\n *\n * The holder is created synchronously during component init (before any\n * top-level `await`, where `onDestroy` is not yet available), and the scope\n * itself is materialized on first use. Disposal is registered separately\n * through `onDestroy` during component initialisation, so the scope is\n * reliably closed on unmount.\n *\n * @since 4.1.0\n */\nexport class ComponentScopeRef {\n\treadonly #get_dispatcher: () => Dispatcher;\n\t#scope: ComponentScope | undefined;\n\n\tconstructor(get_dispatcher_fn: () => Dispatcher) {\n\t\tthis.#get_dispatcher = get_dispatcher_fn;\n\t}\n\n\t/** The component scope, creating it on first access. */\n\tget scope(): ComponentScope {\n\t\tthis.#scope ??= this.#get_dispatcher().begin_scope();\n\n\t\treturn this.#scope;\n\t}\n\n\t/** Disposes the scope if it was created. Idempotent. */\n\tdispose(): void {\n\t\tconst scope = this.#scope;\n\t\tthis.#scope = undefined;\n\n\t\tif (scope && !scope.disposed) {\n\t\t\tthis.#get_dispatcher().dispose_scope(scope);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AAUA,MAAa,kBAAkB,UAC9B,OAAO,IAAI,aAAa;CACvB,OAAO,MAAM,UAAU,KAAK;AAC7B,CAAC;;AAGF,MAAa,kBACZ,YACI;CACJ,MAAM,EAAE,OAAO,aAAa,YAAY,YAAY,kBAAkB,SAAS;CAE/E,OAAO,OAAO,IAAI,aAAa;EAC9B,MAAM,OAAO,OAAO,MAAM,MAAM,KAAK;EAErC,OAAO,OAAO,WAAW;GACxB,IAAI,KAAK,UAAU,IAAI,GAAG;IACzB,aAAa,KAAK,KAAU;IAC5B,cAAc;IAEd;GACD;GAEA,IAAI,CAAC,MAAM,kBAAkB,KAAK,KAAK,GAAG;IACzC,MAAM,QAAQ,MAAM,OAAO,KAAK,KAAK;IAErC,aAAa,KAAK;IAElB,IAAI,iBACH,qBAAqB;KACpB,MAAM;IACP,CAAC;GAEH;GAEA,cAAc;EACf,CAAC;CACF,CAAC;AACF;;;;;;;;;;;;;AClCA,IAAa,iBAAb,MAAa,eAAe;CAC3B;CACA,YAAY;CACZ;CAEA,YAAoB,OAAwB,YAA6C;EACxF,KAAKC,SAAS;EACd,KAAKD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F;CAEA,gBAAgB,WAAmB,MAAgC;EAClE,KAAKf,aAAa,IAAI,WAAW,IAAI;EACrC,KAAKhB,oBAAoB;CAC1B;CAEA,mBAAmB,WAAyB;EAG3C,IAAI,CAFY,KAAKgB,aAAa,OAAO,SAE9B,GACV;EAGD,KAAKhB,oBAAoB;CAC1B;CAEA,qBAA2B;EAC1B,IAAI,KAAKgB,aAAa,SAAS,GAC9B;EAGD,KAAKA,aAAa,MAAM;EACxB,KAAKhB,oBAAoB;CAC1B;CAEA,kBAAkB,WAAmB,OAA6C;EACjF,OAAO,CAAC,KAAKK,aAAa,KAAKK,QAAQ,IAAI,SAAS,MAAM;CAC3D;AACD;AAEA,IAAI,qBAAwC;AAE5C,SAAgB,iBAA6B;CAC5C,uBAAuB,IAAI,WAAW;CAEtC,OAAO;AACR;AAEA,SAAgB,mBAAyB;CACxC,oBAAoB,QAAQ;CAC5B,qBAAqB;AACtB;;;;;;;;;;;;AAaA,IAAa,oBAAb,MAA+B;CAC9B;CACA;CAEA,YAAY,mBAAqC;EAChD,KAAK0B,kBAAkB;CACxB;;CAGA,IAAI,QAAwB;EAC3B,KAAKC,WAAW,KAAKD,gBAAgB,CAAC,CAAC,YAAY;EAEnD,OAAO,KAAKC;CACb;;CAGA,UAAgB;EACf,MAAM,QAAQ,KAAKA;EACnB,KAAKA,SAAS,KAAA;EAEd,IAAI,SAAS,CAAC,MAAM,UACnB,KAAKD,gBAAgB,CAAC,CAAC,cAAc,KAAK;CAE5C;AACD"}
@@ -0,0 +1,23 @@
1
+ import { r as get_dispatcher$1 } from "./dispatcher-CTWINW5I.js";
2
+ import { r as get_server_dispatcher } from "./runtime-CPosEhGl.js";
3
+ //#region src/generated/dispatcher.ts
4
+ var Dispatcher = class {
5
+ static emit(event) {
6
+ return get_dispatcher().emit(event);
7
+ }
8
+ /**
9
+ * Runs `fn` with `scope` as the active component scope so emitted work is
10
+ * bound to the calling component's lifetime.
11
+ */
12
+ static with_scope(scope, fn) {
13
+ return get_dispatcher().with_scope(scope, fn);
14
+ }
15
+ };
16
+ function get_dispatcher() {
17
+ if (typeof document === "undefined") return get_server_dispatcher();
18
+ return get_dispatcher$1();
19
+ }
20
+ //#endregion
21
+ export { get_dispatcher as n, Dispatcher as t };
22
+
23
+ //# sourceMappingURL=dispatcher-pZPzarul.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher-pZPzarul.js","names":["get_client_dispatcher"],"sources":["../../../modules/svelte-effect-runtime/src/generated/dispatcher.ts"],"sourcesContent":["import type {\n\tComponentScope,\n\tDispatcher as RuntimeDispatcher,\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\nimport { get_dispatcher as get_client_dispatcher } from \"$/dispatcher.ts\";\nimport { get_server_dispatcher } from \"$/server/runtime.ts\";\n\nexport { Code } from \"$/dispatcher.ts\";\nexport type {\n\tDispatcherEvent,\n\tMarkupPromiseEvent,\n\tMarkupPromiseOptions,\n\tMarkupRunEvent,\n\tMarkupValueEvent,\n} from \"$/dispatcher.ts\";\n\nexport class Dispatcher {\n\tstatic emit<A, F>(event: MarkupValueEvent<A, F>): A | F;\n\tstatic emit<A>(event: MarkupPromiseEvent<A>): Promise<A>;\n\tstatic emit<A>(event: MarkupRunEvent<A>): Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;\n\tstatic emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A> {\n\t\treturn get_dispatcher().emit(event);\n\t}\n\n\t/**\n\t * Runs `fn` with `scope` as the active component scope so emitted work is\n\t * bound to the calling component's lifetime.\n\t */\n\tstatic with_scope<T>(scope: ComponentScope, fn: () => T): T {\n\t\treturn get_dispatcher().with_scope(scope, fn);\n\t}\n}\n\nexport function get_dispatcher(): RuntimeDispatcher {\n\tif (typeof document === \"undefined\") {\n\t\treturn get_server_dispatcher();\n\t}\n\n\treturn get_client_dispatcher();\n}\n"],"mappings":";;;AAoBA,IAAa,aAAb,MAAwB;CAKvB,OAAO,KAAW,OAAkD;EACnE,OAAO,eAAe,CAAC,CAAC,KAAK,KAAK;CACnC;;;;;CAMA,OAAO,WAAc,OAAuB,IAAgB;EAC3D,OAAO,eAAe,CAAC,CAAC,WAAW,OAAO,EAAE;CAC7C;AACD;AAEA,SAAgB,iBAAoC;CACnD,IAAI,OAAO,aAAa,aACvB,OAAO,sBAAsB;CAG9B,OAAOA,iBAAsB;AAC9B"}