@systemfsoftware/effect-atom 0.5.3 → 1.0.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.
@@ -1,1257 +0,0 @@
1
- import { L as Result } from "./Result-CAjFdzam.js";
2
- import * as Arr from "effect/Array";
3
- import * as Cause from "effect/Cause";
4
- import * as Context from "effect/Context";
5
- import * as Duration from "effect/Duration";
6
- import * as Effect from "effect/Effect";
7
- import { LazyArg } from "effect/Function";
8
- import * as Layer from "effect/Layer";
9
- import * as Option from "effect/Option";
10
- import { Scheduler } from "effect/Scheduler";
11
- import * as Schema from "effect/Schema";
12
- import * as Scope$1 from "effect/Scope";
13
- import * as Stream from "effect/Stream";
14
- import * as SubscriptionRef from "effect/SubscriptionRef";
15
- import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore";
16
- import * as Reactivity from "effect/unstable/reactivity/Reactivity";
17
- import { Pipeable } from "effect/Pipeable";
18
- import { Inspectable } from "effect/Inspectable";
19
- import { ReadonlyRecord } from "effect/Record";
20
- import { NoInfer } from "effect/Types";
21
- //#region src/internal/core.d.ts
22
- /**
23
- * Type-level identifier used to recognize `Atom` values.
24
- *
25
- * @category type IDs
26
- * @since 4.0.0
27
- */
28
- type TypeId$1 = '~effect/reactivity/Atom';
29
- /**
30
- * Runtime identifier attached to `Atom` values and used by `isAtom`.
31
- *
32
- * @category type IDs
33
- * @since 4.0.0
34
- */
35
- declare const TypeId$1: TypeId$1;
36
- /**
37
- * Type-level identifier used to recognize writable atoms.
38
- *
39
- * @category type IDs
40
- * @since 4.0.0
41
- */
42
- type WritableTypeId = '~effect/reactivity/Atom/Writable';
43
- /**
44
- * Runtime identifier attached to writable atoms and used by `isWritable`.
45
- *
46
- * @category type IDs
47
- * @since 4.0.0
48
- */
49
- declare const WritableTypeId: WritableTypeId;
50
- /**
51
- * Returns `true` when a value is an `Atom`.
52
- *
53
- * @category guards
54
- * @since 4.0.0
55
- */
56
- declare const isAtom: (u: unknown) => u is Atom<any>;
57
- /**
58
- * Returns a copy of an atom with an idle time-to-live: finite durations dispose it after inactivity, while an infinite duration keeps it alive.
59
- *
60
- * @category combinators
61
- * @since 4.0.0
62
- */
63
- declare const setIdleTTL: {
64
- (duration: Duration.Input): <A extends Atom<any>>(self: A) => A;
65
- <A extends Atom<any>>(self: A, duration: Duration.Input): A;
66
- };
67
- /**
68
- * Returns `true` when an atom is writable.
69
- *
70
- * @category guards
71
- * @since 4.0.0
72
- */
73
- declare const isWritable: <R, W>(atom: Atom<R>) => atom is Writable<R, W>;
74
- /**
75
- * Creates a read-only atom from a read function and an optional custom refresh registration callback.
76
- *
77
- * @category constructors
78
- * @since 4.0.0
79
- */
80
- declare const readable: <A>(read: (get: AtomContext) => A, refresh?: (f: <A_1>(atom: Atom<A_1>) => void) => void) => Atom<A>;
81
- /**
82
- * Creates a writable atom from read and write functions, with an optional custom refresh registration callback.
83
- *
84
- * @category constructors
85
- * @since 4.0.0
86
- */
87
- declare const writable: <R, W>(read: (get: AtomContext) => R, write: (ctx: WriteContext<R>, value: W) => void, refresh?: (f: <A>(atom: Atom<A>) => void) => void) => Writable<R, W>;
88
- /**
89
- * Creates a derived atom by reading another atom with a custom `AtomContext`
90
- * function.
91
- *
92
- * **Details**
93
- *
94
- * If the source is writable, the derived atom keeps the source write input and
95
- * forwards writes to the source. `initialValueTarget` controls which atom receives
96
- * preloaded initial values for the derived atom.
97
- *
98
- * @category combinators
99
- * @since 4.0.0
100
- */
101
- declare const transform: {
102
- <R extends Atom<any>, B>(f: (get: AtomContext, atom: R) => B, options?: {
103
- readonly initialValueTarget?: Atom<B> | undefined;
104
- }): (self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Atom<B>;
105
- <R extends Atom<any>, B>(self: R, f: (get: AtomContext, atom: R) => B, options?: {
106
- readonly initialValueTarget?: Atom<B> | undefined;
107
- }): [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Atom<B>;
108
- };
109
- declare namespace Registry_d_exports {
110
- export { AtomRegistry, Node, Registry, TypeId, getResult$1 as getResult, isAtomRegistry, layer, layerOptions, make$1 as make, mount$1 as mount, toStream$1 as toStream, toStreamResult$1 as toStreamResult };
111
- }
112
- /**
113
- * The literal type used to identify `AtomRegistry` services and values.
114
- *
115
- * @category type IDs
116
- * @since 4.0.0
117
- */
118
- type TypeId = '~effect-atom/atom/Registry';
119
- /**
120
- * The runtime type id used to identify `AtomRegistry` services and values.
121
- *
122
- * @category type IDs
123
- * @since 4.0.0
124
- */
125
- declare const TypeId: TypeId;
126
- /**
127
- * Returns `true` when the value has the `AtomRegistry` type id.
128
- *
129
- * @category guards
130
- * @since 4.0.0
131
- */
132
- declare const isAtomRegistry: (u: unknown) => u is Registry;
133
- /**
134
- * The runtime registry that stores atom nodes and coordinates reads, writes,
135
- * refreshes, subscriptions, and disposal.
136
- *
137
- * **Details**
138
- *
139
- * It also manages scheduler configuration, serializable preloaded values, and node
140
- * addition/removal callbacks.
141
- *
142
- * @category models
143
- * @since 4.0.0
144
- */
145
- interface Registry {
146
- readonly [TypeId]: TypeId;
147
- readonly scheduler: Scheduler;
148
- readonly schedulerAsync: Scheduler;
149
- readonly getNodes: () => ReadonlyMap<Atom<any> | string, Node<any>>;
150
- readonly get: <A>(atom: Atom<A>) => A;
151
- readonly mount: <A>(atom: Atom<A>) => () => void;
152
- readonly refresh: <A>(atom: Atom<A>) => void;
153
- readonly set: <R, W>(atom: Writable<R, W>, value: W) => void;
154
- readonly setSerializable: (key: string, encoded: unknown) => void;
155
- readonly setInitialValue: <A>(atom: Atom<A>, value: A) => void;
156
- readonly modify: <R, W, A>(atom: Writable<R, W>, f: (_: R) => [returnValue: A, nextValue: W]) => A;
157
- readonly update: <R, W>(atom: Writable<R, W>, f: (_: R) => W) => void;
158
- readonly subscribe: <A>(atom: Atom<A>, f: (_: A) => void, options?: {
159
- readonly immediate?: boolean;
160
- }) => () => void;
161
- readonly reset: () => void;
162
- readonly dispose: () => void;
163
- onNodeAdded?: ((node: Node<any>) => void) | undefined;
164
- onNodeRemoved?: ((node: Node<any>) => void) | undefined;
165
- }
166
- /**
167
- * A registry node for a single atom.
168
- *
169
- * **Details**
170
- *
171
- * Nodes expose the current value, parent and child dependency links, listener set,
172
- * and current lifecycle state.
173
- *
174
- * @category models
175
- * @since 4.0.0
176
- */
177
- interface Node<A> {
178
- readonly atom: Atom<A>;
179
- readonly value: () => A;
180
- parents: Set<Node<any>>;
181
- children: Set<Node<any>>;
182
- listeners: Set<() => void>;
183
- currentState(): 'uninitialized' | 'stale' | 'valid' | 'removed';
184
- }
185
- /**
186
- * Creates an `AtomRegistry`.
187
- *
188
- * **Details**
189
- *
190
- * Options can preload initial atom values, provide a custom task scheduler,
191
- * configure timeout bucket resolution, and set a default idle time-to-live for
192
- * unused atoms.
193
- *
194
- * @category constructors
195
- * @since 4.0.0
196
- */
197
- declare const make$1: (options?: {
198
- readonly initialValues?: Iterable<readonly [Atom<any>, any]> | undefined;
199
- readonly scheduleTask?: ((f: () => void) => () => void) | undefined;
200
- readonly timeoutResolution?: number | undefined;
201
- readonly defaultIdleTTL?: number | undefined;
202
- }) => Registry;
203
- declare const AtomRegistry_base: Context.ServiceClass<AtomRegistry, "~effect-atom/atom/Registry", Registry>;
204
- /**
205
- * Service tag for the active atom runtime cache.
206
- *
207
- * **When to use**
208
- *
209
- * Use to access or provide the registry that stores atom values,
210
- * dependencies, subscriptions, and disposal state for a reactive lifetime.
211
- *
212
- * @category services
213
- * @since 4.0.0
214
- */
215
- declare class AtomRegistry extends AtomRegistry_base {}
216
- /**
217
- * Creates a layer that provides an `AtomRegistry` configured with the supplied
218
- * options.
219
- *
220
- * **Details**
221
- *
222
- * The registry is disposed when the layer scope is finalized.
223
- *
224
- * @category layers
225
- * @since 4.0.0
226
- */
227
- declare const layerOptions: (options?: {
228
- readonly initialValues?: Iterable<readonly [Atom<any>, any]> | undefined;
229
- readonly scheduleTask?: ((f: () => void) => () => void) | undefined;
230
- readonly timeoutResolution?: number | undefined;
231
- readonly defaultIdleTTL?: number | undefined;
232
- }) => Layer.Layer<AtomRegistry>;
233
- /**
234
- * The default layer that provides a fresh `AtomRegistry`.
235
- *
236
- * @category layers
237
- * @since 4.0.0
238
- */
239
- declare const layer: Layer.Layer<AtomRegistry>;
240
- /**
241
- * Converts an atom in this registry into a stream.
242
- *
243
- * **Details**
244
- *
245
- * The stream emits the current value immediately, emits subsequent changes, and
246
- * unsubscribes from the registry when the stream scope closes.
247
- *
248
- * @category converting
249
- * @since 4.0.0
250
- */
251
- declare const toStream$1: {
252
- <A>(atom: Atom<A>): (self: Registry) => Stream.Stream<A>;
253
- <A>(self: Registry, atom: Atom<A>): Stream.Stream<A>;
254
- };
255
- /**
256
- * Converts an `AsyncResult` atom in this registry into a stream of successful
257
- * values.
258
- *
259
- * **Details**
260
- *
261
- * Initial results are skipped, failures fail the stream with their cause, and
262
- * duplicate stream values are dropped with `Stream.changes`.
263
- *
264
- * @category converting
265
- * @since 4.0.0
266
- */
267
- declare const toStreamResult$1: {
268
- <A, E>(atom: Atom<Result<A, E>>): (self: Registry) => Stream.Stream<A, E>;
269
- <A, E>(self: Registry, atom: Atom<Result<A, E>>): Stream.Stream<A, E>;
270
- };
271
- /**
272
- * Reads an `AsyncResult` atom from this registry as an effect.
273
- *
274
- * **Details**
275
- *
276
- * The effect waits for the result to leave `Initial`, and also waits through
277
- * waiting results when `suspendOnWaiting` is enabled.
278
- *
279
- * @category converting
280
- * @since 4.0.0
281
- */
282
- declare const getResult$1: {
283
- <A, E>(atom: Atom<Result<A, E>>, options?: {
284
- readonly suspendOnWaiting?: boolean | undefined;
285
- }): (self: Registry) => Effect.Effect<A, E>;
286
- <A, E>(self: Registry, atom: Atom<Result<A, E>>, options?: {
287
- readonly suspendOnWaiting?: boolean | undefined;
288
- }): Effect.Effect<A, E>;
289
- };
290
- /**
291
- * Mounts an atom in this registry for the lifetime of the current scope.
292
- *
293
- * **Details**
294
- *
295
- * The atom is subscribed with a no-op listener and the subscription is released
296
- * when the scope finalizer runs.
297
- *
298
- * @category converting
299
- * @since 4.0.0
300
- */
301
- declare const mount$1: {
302
- <A>(atom: Atom<A>): (self: Registry) => Effect.Effect<void, never, Scope$1.Scope>;
303
- <A>(self: Registry, atom: Atom<A>): Effect.Effect<void, never, Scope$1.Scope>;
304
- };
305
- //#endregion
306
- //#region src/browser.d.ts
307
- /**
308
- * Creates a browser-only signal atom that increments when the document becomes visible.
309
- *
310
- * **Details**
311
- *
312
- * It listens for `visibilitychange` events on `window` and removes the listener
313
- * when the atom is disposed.
314
- *
315
- * @category constants
316
- * @since 4.0.0
317
- */
318
- declare const windowFocusSignal: Atom<number>;
319
- /**
320
- * Creates a combinator that refreshes an atom whenever the supplied signal atom
321
- * changes.
322
- *
323
- * **Details**
324
- *
325
- * The derived atom also subscribes to the source atom so normal source updates are
326
- * forwarded to its own value.
327
- *
328
- * @category constructors
329
- * @since 4.0.0
330
- */
331
- declare const makeRefreshOnSignal: <_>(signal: Atom<_>) => <A extends Atom<any>>(self: A) => WithoutSerializable<A>;
332
- /**
333
- * Refreshes an atom whenever `windowFocusSignal` changes.
334
- *
335
- * **Details**
336
- *
337
- * This helper is browser-only because `windowFocusSignal` depends on `window` and
338
- * `document.visibilityState`.
339
- *
340
- * @category combinators
341
- * @since 4.0.0
342
- */
343
- declare const refreshOnWindowFocus: <A extends Atom<any>>(self: A) => WithoutSerializable<A>;
344
- /**
345
- * Creates an atom that reads and writes a URL search parameter.
346
- *
347
- * **Gotchas**
348
- *
349
- * If you pass a schema, it has to be synchronous and have no context.
350
- *
351
- * @category constructors
352
- * @since 4.0.0
353
- */
354
- declare function searchParam<S extends Schema.ConstraintCodec<any, string> = never>(name: string, options?: {
355
- readonly schema?: S | undefined;
356
- }): Writable<[S] extends [never] ? string : Option.Option<S['Type']>>;
357
- //#endregion
358
- //#region src/server.d.ts
359
- /**
360
- * The type id used to mark atoms with a server-side read override.
361
- *
362
- * @category type IDs
363
- * @since 4.0.0
364
- */
365
- declare const ServerValueTypeId: '~effect-atom/atom/Atom/ServerValue';
366
- /**
367
- * Server-side read override attached to an atom by `withServerValue`.
368
- *
369
- * @category models
370
- * @since 4.0.0
371
- */
372
- type ServerValue<A> = {
373
- readonly [ServerValueTypeId]: (get: <A>(atom: Atom<A>) => A) => A;
374
- };
375
- /**
376
- * Sets the value of an Atom when read on the server.
377
- *
378
- * @category transforming
379
- * @since 4.0.0
380
- */
381
- declare const withServerValue: {
382
- <A extends Atom<any>>(read: (get: <A>(atom: Atom<A>) => A) => Type<A>): (self: A) => A;
383
- <A extends Atom<any>>(self: A, read: (get: <A>(atom: Atom<A>) => A) => Type<A>): A;
384
- };
385
- /**
386
- * Sets an `AsyncResult` atom's server-side value to
387
- * `AsyncResult.initial(true)`.
388
- *
389
- * @category transforming
390
- * @since 4.0.0
391
- */
392
- declare const withServerValueInitial: <A extends Atom<Result<any, any>>>(self: A) => A;
393
- /**
394
- * Reads an atom from a registry, using its server-side read override when one is
395
- * present.
396
- *
397
- * **Details**
398
- *
399
- * Nested reads performed by the override are resolved against the same registry.
400
- *
401
- * @category getters
402
- * @since 4.0.0
403
- */
404
- declare const getServerValue: {
405
- (registry: Registry): <A>(self: Atom<A>) => A;
406
- <A>(self: Atom<A>, registry: Registry): A;
407
- };
408
- declare namespace Atom_d_exports {
409
- export { Atom, AtomContext, AtomResultFn, AtomRuntime, Failure, FnContext, Interrupt, PullResult, PullSuccess, RegistryRuntimeFactory, Reset, RuntimeFactory, Serializable, SerializableTypeId, ServerValue, ServerValueTypeId, SharedRuntimeFactory, Success, Type, TypeId$1 as TypeId, WithoutSerializable, Writable, WritableTypeId, WriteContext, autoDispose, batch, context, debounce, family, fn, fnSync, get, getResult, getServerValue, initialValue, isAtom, isSerializable, isWritable, keepAlive, kvs, make, makeRefreshOnSignal, map, mapResult, modify, mount, optimistic, optimisticFn, pull, readable, refresh, refreshOnWindowFocus, runtime, searchParam, serializable, set, setIdleTTL, setLazy, subscriptionRef, swr, toStream, toStreamResult, transform, update, windowFocusSignal, withEquality, withFallback, withLabel, withReactivity, withRefresh, withServerValue, withServerValueInitial, writable };
410
- }
411
- /**
412
- * Reactive value read by an `AtomRegistry`, with metadata controlling caching, laziness, refresh behavior, and initial value targeting.
413
- *
414
- * @category models
415
- * @since 4.0.0
416
- */
417
- interface Atom<A> extends Pipeable, Inspectable {
418
- readonly [TypeId$1]: TypeId$1;
419
- readonly keepAlive: boolean;
420
- readonly lazy: boolean;
421
- readonly read: (get: AtomContext) => A;
422
- equals(value: A, next: A): boolean;
423
- readonly refresh?: (f: <A>(atom: Atom<A>) => void) => void;
424
- readonly label?: readonly [name: string, stack: string];
425
- readonly idleTTL?: number;
426
- readonly initialValueTarget?: Atom<A>;
427
- }
428
- /**
429
- * Extracts the value type produced by an `Atom`.
430
- *
431
- * @category utility types
432
- * @since 4.0.0
433
- */
434
- type Type<T extends Atom<any>> = T extends Atom<infer A> ? A : never;
435
- /**
436
- * Extracts the success value type from an atom whose value is an `AsyncResult`.
437
- *
438
- * @category utility types
439
- * @since 4.0.0
440
- */
441
- type Success<T extends Atom<any>> = T extends Atom<Result<infer A, infer _>> ? A : never;
442
- /**
443
- * Extracts the item type from an atom whose value is a `PullResult`.
444
- *
445
- * @category utility types
446
- * @since 4.0.0
447
- */
448
- type PullSuccess<T extends Atom<any>> = T extends Atom<PullResult<infer A, infer _>> ? A : never;
449
- /**
450
- * Extracts the failure error type from an atom whose value is an `AsyncResult`.
451
- *
452
- * @category utility types
453
- * @since 4.0.0
454
- */
455
- type Failure<T extends Atom<any>> = T extends Atom<Result<infer _, infer E>> ? E : never;
456
- /**
457
- * Returns an atom type without serializable metadata, preserving `Writable` read and write types when the input atom is writable.
458
- *
459
- * @category utility types
460
- * @since 4.0.0
461
- */
462
- type WithoutSerializable<T extends Atom<any>> = T extends Writable<infer R, infer W> ? Writable<R, W> : Atom<Type<T>>;
463
- /**
464
- * Atom that can also be written to, using a `WriteContext` and an input value to update reactive state.
465
- *
466
- * @category models
467
- * @since 4.0.0
468
- */
469
- interface Writable<R, W = R> extends Atom<R> {
470
- readonly [WritableTypeId]: WritableTypeId;
471
- readonly write: (ctx: WriteContext<R>, value: W) => void;
472
- }
473
- /**
474
- * Context passed to atom read functions for reading dependencies, awaiting `AsyncResult` or `Option` values, managing subscriptions and finalizers, refreshing atoms, and updating writable atoms.
475
- *
476
- * @category context
477
- * @since 4.0.0
478
- */
479
- interface AtomContext {
480
- <A>(atom: Atom<A>): A;
481
- get<A>(this: AtomContext, atom: Atom<A>): A;
482
- result<A, E>(this: AtomContext, atom: Atom<Result<A, E>>, options?: {
483
- readonly suspendOnWaiting?: boolean | undefined;
484
- }): Effect.Effect<A, E>;
485
- resultOnce<A, E>(this: AtomContext, atom: Atom<Result<A, E>>, options?: {
486
- readonly suspendOnWaiting?: boolean | undefined;
487
- }): Effect.Effect<A, E>;
488
- once<A>(this: AtomContext, atom: Atom<A>): A;
489
- addFinalizer(this: AtomContext, f: () => void): void;
490
- mount<A>(this: AtomContext, atom: Atom<A>): void;
491
- refresh<A>(this: AtomContext, atom: Atom<A>): void;
492
- refreshSelf(this: AtomContext): void;
493
- self<A>(this: AtomContext): Option.Option<A>;
494
- setSelf<A>(this: AtomContext, a: A): void;
495
- set<R, W>(this: AtomContext, atom: Writable<R, W>, value: W): void;
496
- setResult<A, E, W>(this: AtomContext, atom: Writable<Result<A, E>, W>, value: W): Effect.Effect<A, E>;
497
- some<A>(this: AtomContext, atom: Atom<Option.Option<A>>): Effect.Effect<A>;
498
- someOnce<A>(this: AtomContext, atom: Atom<Option.Option<A>>): Effect.Effect<A>;
499
- stream<A>(this: AtomContext, atom: Atom<A>, options?: {
500
- readonly withoutInitialValue?: boolean;
501
- readonly bufferSize?: number;
502
- }): Stream.Stream<A>;
503
- streamResult<A, E>(this: AtomContext, atom: Atom<Result<A, E>>, options?: {
504
- readonly withoutInitialValue?: boolean;
505
- readonly bufferSize?: number;
506
- }): Stream.Stream<A, E>;
507
- subscribe<A>(this: AtomContext, atom: Atom<A>, f: (_: A) => void, options?: {
508
- readonly immediate?: boolean;
509
- }): void;
510
- isFn?: boolean | undefined;
511
- readonly registry: Registry;
512
- }
513
- /**
514
- * Context passed to writable atom write functions for reading atoms, refreshing or setting the current atom, and writing to other writable atoms.
515
- *
516
- * @category context
517
- * @since 4.0.0
518
- */
519
- interface WriteContext<A> {
520
- get<T>(this: WriteContext<A>, atom: Atom<T>): T;
521
- refreshSelf(this: WriteContext<A>): void;
522
- setSelf(this: WriteContext<A>, a: A): void;
523
- set<R, W>(this: WriteContext<A>, atom: Writable<R, W>, value: W): void;
524
- }
525
- /**
526
- * Creates an atom from a synchronous value or read function, or from an `Effect` or `Stream` whose state is exposed as an `AsyncResult`; plain values create writable state atoms.
527
- *
528
- * @category constructors
529
- * @since 4.0.0
530
- */
531
- declare function make<A, E>(create: (get: AtomContext) => Effect.Effect<A, E, Scope$1.Scope | AtomRegistry>, options?: {
532
- readonly initialValue?: A | undefined;
533
- readonly uninterruptible?: boolean | undefined;
534
- }): Atom<Result<A, E>>;
535
- declare function make<A, E>(effect: Effect.Effect<A, E, Scope$1.Scope | AtomRegistry>, options?: {
536
- readonly initialValue?: A;
537
- readonly uninterruptible?: boolean | undefined;
538
- }): Atom<Result<A, E>>;
539
- declare function make<A, E>(create: (get: AtomContext) => Stream.Stream<A, E, AtomRegistry>, options?: {
540
- readonly initialValue?: A;
541
- }): Atom<Result<A, E | Cause.NoSuchElementError>>;
542
- declare function make<A, E>(stream: Stream.Stream<A, E, AtomRegistry>, options?: {
543
- readonly initialValue?: A;
544
- }): Atom<Result<A, E | Cause.NoSuchElementError>>;
545
- declare function make<A>(create: (get: AtomContext) => A): Atom<A>;
546
- declare function make<A>(initialValue: A): Writable<A>;
547
- /**
548
- * Atom that builds a `Context` from a `Layer` and exposes constructors for atoms, functions, pulls, and subscription refs that run with that context.
549
- *
550
- * @category models
551
- * @since 4.0.0
552
- */
553
- interface AtomRuntime<R, ER = never> extends Atom<Result<Context.Context<R>, ER>> {
554
- readonly factory: RuntimeFactory;
555
- readonly layer: Atom<Layer.Layer<R, ER>>;
556
- readonly atom: {
557
- <A, E>(create: (get: AtomContext) => Effect.Effect<A, E, Scope$1.Scope | R | AtomRegistry | Reactivity.Reactivity>, options?: {
558
- readonly initialValue?: A;
559
- readonly uninterruptible?: boolean | undefined;
560
- }): Atom<Result<A, E | ER>>;
561
- <A, E>(effect: Effect.Effect<A, E, Scope$1.Scope | R | AtomRegistry | Reactivity.Reactivity>, options?: {
562
- readonly initialValue?: A;
563
- readonly uninterruptible?: boolean | undefined;
564
- }): Atom<Result<A, E | ER>>;
565
- <A, E>(create: (get: AtomContext) => Stream.Stream<A, E, AtomRegistry | Reactivity.Reactivity | R>, options?: {
566
- readonly initialValue?: A;
567
- }): Atom<Result<A, E | ER | Cause.NoSuchElementError>>;
568
- <A, E>(stream: Stream.Stream<A, E, AtomRegistry | Reactivity.Reactivity | R>, options?: {
569
- readonly initialValue?: A;
570
- }): Atom<Result<A, E | ER | Cause.NoSuchElementError>>;
571
- };
572
- readonly fn: {
573
- <Arg>(): {
574
- <E, A>(fn: (arg: Arg, get: FnContext) => Effect.Effect<A, E, Scope$1.Scope | AtomRegistry | Reactivity.Reactivity | R>, options?: {
575
- readonly initialValue?: A | undefined;
576
- readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
577
- readonly concurrent?: boolean | undefined;
578
- }): AtomResultFn<Arg, A, E | ER>;
579
- <E, A>(fn: (arg: Arg, get: FnContext) => Stream.Stream<A, E, AtomRegistry | Reactivity.Reactivity | R>, options?: {
580
- readonly initialValue?: A | undefined;
581
- readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
582
- readonly concurrent?: boolean | undefined;
583
- }): AtomResultFn<Arg, A, E | ER | Cause.NoSuchElementError>;
584
- };
585
- <E, A, Arg = void>(fn: (arg: Arg, get: FnContext) => Effect.Effect<A, E, Scope$1.Scope | AtomRegistry | Reactivity.Reactivity | R>, options?: {
586
- readonly initialValue?: A | undefined;
587
- readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
588
- readonly concurrent?: boolean | undefined;
589
- }): AtomResultFn<Arg, A, E | ER>;
590
- <E, A, Arg = void>(fn: (arg: Arg, get: FnContext) => Stream.Stream<A, E, AtomRegistry | Reactivity.Reactivity | R>, options?: {
591
- readonly initialValue?: A | undefined;
592
- readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
593
- readonly concurrent?: boolean | undefined;
594
- }): AtomResultFn<Arg, A, E | ER | Cause.NoSuchElementError>;
595
- };
596
- readonly pull: <A, E>(create: ((get: AtomContext) => Stream.Stream<A, E, R | AtomRegistry | Reactivity.Reactivity>) | Stream.Stream<A, E, R | AtomRegistry | Reactivity.Reactivity>, options?: {
597
- readonly disableAccumulation?: boolean;
598
- readonly initialValue?: readonly A[];
599
- }) => Writable<PullResult<A, E | ER>, void>;
600
- readonly subscriptionRef: <A, E>(create: Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, Scope$1.Scope | R | AtomRegistry | Reactivity.Reactivity> | ((get: AtomContext) => Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, Scope$1.Scope | R | AtomRegistry | Reactivity.Reactivity>)) => Writable<Result<A, E>, A>;
601
- }
602
- /**
603
- * Factory for `AtomRuntime` values that share a set of global layers.
604
- *
605
- * @category models
606
- * @since 4.0.0
607
- */
608
- interface RuntimeFactory {
609
- <R, E>(create: Layer.Layer<R, E, AtomRegistry | Reactivity.Reactivity> | ((get: AtomContext) => Layer.Layer<R, E, AtomRegistry | Reactivity.Reactivity>)): AtomRuntime<R, E>;
610
- readonly addGlobalLayer: <A, E>(layer: Layer.Layer<A, E, AtomRegistry | Reactivity.Reactivity>) => void;
611
- /**
612
- * Uses the `Reactivity` service from the runtime to refresh the atom whenever
613
- * the keys change.
614
- */
615
- readonly withReactivity: (keys: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]>) => <A extends Atom<any>>(atom: A) => A;
616
- }
617
- /**
618
- * A `RuntimeFactory` backed by an atom whose memo map is scoped to each registry.
619
- *
620
- * @category models
621
- * @since 4.0.0
622
- */
623
- interface RegistryRuntimeFactory extends RuntimeFactory {
624
- readonly memoMap: Atom<Layer.MemoMap>;
625
- }
626
- /**
627
- * A `RuntimeFactory` backed by a concrete memo map shared across registries.
628
- *
629
- * @category models
630
- * @since 4.0.0
631
- */
632
- interface SharedRuntimeFactory extends RuntimeFactory {
633
- readonly memoMap: Layer.MemoMap;
634
- }
635
- /**
636
- * Creates a `RuntimeFactory` backed by a registry-scoped memo map by default,
637
- * or by the supplied atom or concrete `Layer.MemoMap`.
638
- *
639
- * @category constructors
640
- * @since 4.0.0
641
- */
642
- declare function context(): RegistryRuntimeFactory;
643
- declare function context(options: {
644
- readonly memoMap: Atom<Layer.MemoMap>;
645
- }): RegistryRuntimeFactory;
646
- declare function context(options: {
647
- readonly memoMap: Layer.MemoMap;
648
- }): SharedRuntimeFactory;
649
- /**
650
- * Default registry-scoped `RuntimeFactory`.
651
- *
652
- * @category context
653
- * @since 4.0.0
654
- */
655
- declare const runtime: RegistryRuntimeFactory;
656
- /**
657
- * Returns `Rx.runtime.withReactivity` for refreshing an atom whenever the
658
- * keys change in the `Reactivity` service.
659
- *
660
- * **When to use**
661
- *
662
- * Use to refresh an atom whenever one or more invalidation keys change in the
663
- * default reactivity runtime.
664
- *
665
- * @category reactivity
666
- * @since 4.0.0
667
- */
668
- declare const withReactivity: (keys: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]>) => <A extends Atom<any>>(atom: A) => A;
669
- /**
670
- * Creates a writable atom backed by a `SubscriptionRef`, or by an effect that produces one, updating from ref changes and writing atom updates back to the ref.
671
- *
672
- * @category constructors
673
- * @since 4.0.0
674
- */
675
- declare const subscriptionRef: {
676
- <A>(ref: SubscriptionRef.SubscriptionRef<A> | ((get: AtomContext) => SubscriptionRef.SubscriptionRef<A>)): Writable<A>;
677
- <A, E>(effect: Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, Scope$1.Scope | AtomRegistry> | ((get: AtomContext) => Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, Scope$1.Scope | AtomRegistry>)): Writable<Result<A, E>, A>;
678
- };
679
- /**
680
- * Context passed to `fn` and `fnSync` computations for reading atoms, awaiting results, registering finalizers, refreshing atoms, subscribing to changes, and writing updates.
681
- *
682
- * @category models
683
- * @since 4.0.0
684
- */
685
- interface FnContext {
686
- <A>(atom: Atom<A>): A;
687
- result<A, E>(this: FnContext, atom: Atom<Result<A, E>>, options?: {
688
- readonly suspendOnWaiting?: boolean | undefined;
689
- }): Effect.Effect<A, E>;
690
- addFinalizer(this: FnContext, f: () => void): void;
691
- mount<A>(this: FnContext, atom: Atom<A>): void;
692
- refresh<A>(this: FnContext, atom: Atom<A>): void;
693
- self<A>(this: FnContext): Option.Option<A>;
694
- setSelf<A>(this: FnContext, a: A): void;
695
- set<R, W>(this: FnContext, atom: Writable<R, W>, value: W): void;
696
- setResult<A, E, W>(this: FnContext, atom: Writable<Result<A, E>, W>, value: W): Effect.Effect<A, E>;
697
- some<A>(this: FnContext, atom: Atom<Option.Option<A>>): Effect.Effect<A>;
698
- stream<A>(this: FnContext, atom: Atom<A>, options?: {
699
- readonly withoutInitialValue?: boolean;
700
- readonly bufferSize?: number;
701
- }): Stream.Stream<A>;
702
- streamResult<A, E>(this: FnContext, atom: Atom<Result<A, E>>, options?: {
703
- readonly withoutInitialValue?: boolean;
704
- readonly bufferSize?: number;
705
- }): Stream.Stream<A, E>;
706
- subscribe<A>(this: FnContext, atom: Atom<A>, f: (_: A) => void, options?: {
707
- readonly immediate?: boolean;
708
- }): void;
709
- readonly registry: Registry;
710
- }
711
- /**
712
- * Creates a writable atom for a synchronous function; writing an argument re-runs the function, returning `Option.none` before the first call unless an initial value is supplied.
713
- *
714
- * @category constructors
715
- * @since 4.0.0
716
- */
717
- declare function fnSync<Arg>(): {
718
- <A>(f: (arg: Arg, get: FnContext) => A): Writable<Option.Option<A>, Arg>;
719
- <A>(f: (arg: Arg, get: FnContext) => A, options: {
720
- readonly initialValue: A;
721
- }): Writable<A, Arg>;
722
- };
723
- declare function fnSync<A, Arg = void>(f: (arg: Arg, get: FnContext) => A): Writable<Option.Option<A>, Arg>;
724
- declare function fnSync<A, Arg = void>(f: (arg: Arg, get: FnContext) => A, options: {
725
- readonly initialValue: A;
726
- }): Writable<A, Arg>;
727
- /**
728
- * Writable async function atom whose value is an `AsyncResult` and whose writes accept function arguments plus `Reset` and `Interrupt` controls.
729
- *
730
- * @category models
731
- * @since 4.0.0
732
- */
733
- interface AtomResultFn<Arg, A, E = never> extends Writable<Result<A, E>, Arg | Reset | Interrupt> {}
734
- /**
735
- * Defines the control symbol that can be written to an `AtomResultFn` to reset it to its initial state.
736
- *
737
- * **When to use**
738
- *
739
- * Use when you need an `AtomResultFn` write value that clears the current async
740
- * result and returns it to the initial state.
741
- *
742
- * @category symbols
743
- * @since 4.0.0
744
- */
745
- declare const Reset: unique symbol;
746
- /**
747
- * Type of the `Reset` control symbol accepted by `AtomResultFn` writes.
748
- *
749
- * @category symbols
750
- * @since 4.0.0
751
- */
752
- type Reset = typeof Reset;
753
- /**
754
- * Defines the control symbol that can be written to an `AtomResultFn` to interrupt the current asynchronous computation.
755
- *
756
- * **When to use**
757
- *
758
- * Use when you need an `AtomResultFn` write value that interrupts the currently
759
- * running async computation.
760
- *
761
- * @category symbols
762
- * @since 4.0.0
763
- */
764
- declare const Interrupt: unique symbol;
765
- /**
766
- * Type of the `Interrupt` control symbol accepted by `AtomResultFn` writes.
767
- *
768
- * @category symbols
769
- * @since 4.0.0
770
- */
771
- type Interrupt = typeof Interrupt;
772
- /**
773
- * Creates a writable atom for an `Effect` or `Stream` function; writing an argument starts the computation and exposes its state as an `AsyncResult`.
774
- *
775
- * @category constructors
776
- * @since 4.0.0
777
- */
778
- declare function fn<Arg>(): <E, A>(fn: (arg: Arg, get: FnContext) => Effect.Effect<A, E, Scope$1.Scope | AtomRegistry>, options?: {
779
- readonly initialValue?: A | undefined;
780
- readonly concurrent?: boolean | undefined;
781
- }) => AtomResultFn<Arg, A, E>;
782
- declare function fn<E, A, Arg = void>(fn: (arg: Arg, get: FnContext) => Effect.Effect<A, E, Scope$1.Scope | AtomRegistry>, options?: {
783
- readonly initialValue?: A | undefined;
784
- readonly concurrent?: boolean | undefined;
785
- }): AtomResultFn<Arg, A, E>;
786
- declare function fn<Arg>(): <E, A>(fn: (arg: Arg, get: FnContext) => Stream.Stream<A, E, AtomRegistry>, options?: {
787
- readonly initialValue?: A | undefined;
788
- readonly concurrent?: boolean | undefined;
789
- }) => AtomResultFn<Arg, A, E | Cause.NoSuchElementError>;
790
- declare function fn<E, A, Arg = void>(fn: (arg: Arg, get: FnContext) => Stream.Stream<A, E, AtomRegistry>, options?: {
791
- readonly initialValue?: A | undefined;
792
- readonly concurrent?: boolean | undefined;
793
- }): AtomResultFn<Arg, A, E | Cause.NoSuchElementError>;
794
- /**
795
- * `AsyncResult` produced by `pull`, containing a non-empty batch of pulled items and a `done` flag, or `NoSuchElementError` when the stream completes without items.
796
- *
797
- * @category models
798
- * @since 4.0.0
799
- */
800
- type PullResult<A, E = never> = Result<{
801
- readonly done: boolean;
802
- readonly items: Arr.NonEmptyArray<A>;
803
- }, E | Cause.NoSuchElementError>;
804
- /**
805
- * Creates a writable atom that pulls an initial chunk from a stream and then pulls the next chunk whenever it is written to, accumulating items unless `disableAccumulation` is enabled.
806
- *
807
- * @category constructors
808
- * @since 4.0.0
809
- */
810
- declare const pull: <A, E>(create: ((get: AtomContext) => Stream.Stream<A, E, AtomRegistry>) | Stream.Stream<A, E, AtomRegistry>, options?: {
811
- readonly disableAccumulation?: boolean | undefined;
812
- }) => Writable<PullResult<A, E>, void>;
813
- /**
814
- * Creates a memoized atom factory that returns the same object for the same argument, using weak references for cached values when the platform supports them.
815
- *
816
- * @category constructors
817
- * @since 4.0.0
818
- */
819
- declare const family: <Arg, T extends object>(f: (arg: Arg) => T) => (arg: Arg) => T;
820
- /**
821
- * Uses a fallback `AsyncResult` atom while the primary atom is `Initial`, marking the fallback result as waiting until the primary atom produces a non-initial result.
822
- *
823
- * @category combinators
824
- * @since 4.0.0
825
- */
826
- declare const withFallback: {
827
- <E2, A2>(fallback: Atom<Result<A2, E2>>): <R extends Atom<Result<any, any>>>(self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<Result<Result.Success<Type<R>> | A2, Result.Failure<Type<R>> | E2>, RW> : Atom<Result<Result.Success<Type<R>> | A2, Result.Failure<Type<R>> | E2>>;
828
- <R extends Atom<Result<any, any>>, A2, E2>(self: R, fallback: Atom<Result<A2, E2>>): [R] extends [Writable<infer _, infer RW>] ? Writable<Result<Result.Success<Type<R>> | A2, Result.Failure<Type<R>> | E2>, RW> : Atom<Result<Result.Success<Type<R>> | A2, Result.Failure<Type<R>> | E2>>;
829
- };
830
- /**
831
- * Returns a copy of an atom that remains cached and mounted even when no subscribers are using it.
832
- *
833
- * @category combinators
834
- * @since 4.0.0
835
- */
836
- declare const keepAlive: <A extends Atom<any>>(self: A) => A;
837
- /**
838
- * Allows a reactive value to be disposed of when it is not in use.
839
- *
840
- * **Details**
841
- *
842
- * Atoms have this behavior by default, so use this to undo `keepAlive` on a copied atom.
843
- *
844
- * @category combinators
845
- * @since 4.0.0
846
- */
847
- declare const autoDispose: <A extends Atom<any>>(self: A) => A;
848
- /**
849
- * Sets whether an atom should be lazy.
850
- *
851
- * **Details**
852
- *
853
- * Lazy atoms defer recomputation while they have no active listeners or active
854
- * non-lazy dependents, rebuilding the next time their value is observed.
855
- *
856
- * @category combinators
857
- * @since 4.0.0
858
- */
859
- declare const setLazy: {
860
- (lazy: boolean): <A extends Atom<any>>(self: A) => A;
861
- <A extends Atom<any>>(self: A, lazy: boolean): A;
862
- };
863
- /**
864
- * Returns a copy of an atom that uses a custom equality function to detect
865
- * value changes.
866
- *
867
- * **Details**
868
- *
869
- * When an atom's value is rebuilt or written, the registry compares the new
870
- * value against the current one to decide whether dependents and listeners
871
- * should be notified. By default the comparison uses `Object.is`, so a
872
- * structurally equal but referentially distinct value still triggers
873
- * notifications. Providing an equality function lets the atom skip updates
874
- * when the new value is equal to the current one.
875
- *
876
- * **Example** (Comparing values structurally)
877
- *
878
- * ```ts import.meta.vitest
879
- * import { Atom } from "effect/unstable/reactivity"
880
- *
881
- * const point = Atom.make({ x: 0, y: 0 }).pipe(
882
- * Atom.withEquality<{ x: number; y: number }>((a, b) => a.x === b.x && a.y === b.y)
883
- * )
884
- * point.equals({ x: 1, y: 2 }, { x: 1, y: 2 }) // => true
885
- * ```
886
- *
887
- * @category combinators
888
- * @since 4.0.0
889
- */
890
- declare const withEquality: {
891
- <A>(equals: (value: A, next: A) => boolean): <T extends Atom<A>>(self: T) => T;
892
- <T extends Atom<any>>(self: T, equals: (value: Type<T>, next: Type<T>) => boolean): T;
893
- };
894
- /**
895
- * Attaches a diagnostic label to an atom.
896
- *
897
- * **Details**
898
- *
899
- * The label is used for inspection and debugging metadata and does not change the
900
- * atom's read or write behavior.
901
- *
902
- * @category combinators
903
- * @since 4.0.0
904
- */
905
- declare const withLabel: {
906
- (name: string): <A extends Atom<any>>(self: A) => A;
907
- <A extends Atom<any>>(self: A, name: string): A;
908
- };
909
- /**
910
- * Pairs an atom with an initial value for registry initialization.
911
- *
912
- * **When to use**
913
- *
914
- * Use to preload an atom value when constructing or seeding a registry.
915
- *
916
- * **Details**
917
- *
918
- * The returned tuple can be supplied to `AtomRegistry` initial values so the atom
919
- * starts with the provided value before it is first rebuilt.
920
- *
921
- * @category combinators
922
- * @since 4.0.0
923
- */
924
- declare const initialValue: {
925
- <A>(initialValue: A): (self: Atom<A>) => readonly [Atom<A>, A];
926
- <A>(self: Atom<A>, initialValue: A): readonly [Atom<A>, A];
927
- };
928
- /**
929
- * Maps the value of an atom by reading the source atom, applying the function,
930
- *
931
- * **Details**
932
- *
933
- * When the source atom is writable, the returned atom remains writable and keeps
934
- * the source atom's write input type.
935
- *
936
- * @category combinators
937
- * @since 4.0.0
938
- */
939
- declare const map: {
940
- <R extends Atom<any>, B>(f: (_: Type<R>) => B): (self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Atom<B>;
941
- <R extends Atom<any>, B>(self: R, f: (_: Type<R>) => B): [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Atom<B>;
942
- };
943
- /**
944
- * Maps the successful value inside an `AsyncResult` atom.
945
- *
946
- * **Details**
947
- *
948
- * Initial and failure states are preserved, and writable source atoms keep their
949
- * original write input type.
950
- *
951
- * @category combinators
952
- * @since 4.0.0
953
- */
954
- declare const mapResult: {
955
- <R extends Atom<Result<any, any>>, B>(f: (_: Result.Success<Type<R>>) => B): (self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<Result<B, Result.Failure<Type<R>>>, RW> : Atom<Result<B, Result.Failure<Type<R>>>>;
956
- <R extends Atom<Result<any, any>>, B>(self: R, f: (_: Result.Success<Type<R>>) => B): [R] extends [Writable<infer _, infer RW>] ? Writable<Result<B, Result.Failure<Type<R>>>, RW> : Atom<Result<B, Result.Failure<Type<R>>>>;
957
- };
958
- /**
959
- * Creates an atom that publishes source changes only after the source has stopped
960
- * changing for the specified duration.
961
- *
962
- * **Details**
963
- *
964
- * The current source value is used immediately, and any pending debounce timer is
965
- * cleared when the derived atom is disposed.
966
- *
967
- * @category combinators
968
- * @since 4.0.0
969
- */
970
- declare const debounce: {
971
- (duration: Duration.Input): <A extends Atom<any>>(self: A) => WithoutSerializable<A>;
972
- <A extends Atom<any>>(self: A, duration: Duration.Input): WithoutSerializable<A>;
973
- };
974
- /**
975
- * Creates a derived atom that reads the source and schedules a refresh after the
976
- * specified duration.
977
- *
978
- * **Details**
979
- *
980
- * The scheduled refresh is canceled when the derived atom's lifetime is disposed.
981
- *
982
- * @category combinators
983
- * @since 4.0.0
984
- */
985
- declare const withRefresh: {
986
- (duration: Duration.Input): <A extends Atom<any>>(self: A) => WithoutSerializable<A>;
987
- <A extends Atom<any>>(self: A, duration: Duration.Input): WithoutSerializable<A>;
988
- };
989
- /**
990
- * Adds stale-while-revalidate refresh behavior to an async result atom.
991
- *
992
- * **Details**
993
- *
994
- * Automatic revalidation during reads is skipped while the current value is
995
- * fresh within `staleTime`. Manual `refresh` calls remain forceful and always
996
- * forward to the wrapped atom. Use `revalidateOnMount` to control whether stale data should trigger a
997
- * background refresh on first mount. Use `revalidateOnFocus` to control
998
- * focus behavior. `true` respects `staleTime` and `"always"` forces refetch.
999
- *
1000
- * @category combinators
1001
- * @since 4.0.0
1002
- */
1003
- declare const swr: {
1004
- (options: {
1005
- readonly staleTime: Duration.Input;
1006
- readonly revalidateOnMount?: boolean | undefined;
1007
- readonly revalidateOnFocus?: boolean | 'always' | undefined;
1008
- readonly focusSignal?: Atom<any> | undefined;
1009
- }): <R extends Atom<Result<any, any>>>(self: R) => WithoutSerializable<R>;
1010
- <R extends Atom<Result<any, any>>>(self: R, options: {
1011
- readonly staleTime: Duration.Input;
1012
- readonly revalidateOnMount?: boolean | undefined;
1013
- readonly revalidateOnFocus?: boolean | 'always' | undefined;
1014
- readonly focusSignal?: Atom<any> | undefined;
1015
- }): WithoutSerializable<R>;
1016
- };
1017
- /**
1018
- * Wraps an atom in a writable optimistic atom.
1019
- *
1020
- * **Details**
1021
- *
1022
- * Writes accept transition atoms containing `AsyncResult` values. Waiting
1023
- * successes are shown optimistically while transitions run; when successful
1024
- * transitions finish, the source atom is refreshed, and failures roll the value
1025
- * back to the latest source value.
1026
- *
1027
- * @category constructors
1028
- * @since 4.0.0
1029
- */
1030
- declare const optimistic: <A>(self: Atom<A>) => Writable<A, Atom<Result<A, unknown>>>;
1031
- /**
1032
- * Creates an `AtomResultFn` that applies an optimistic update before running the
1033
- * underlying mutation.
1034
- *
1035
- * **Details**
1036
- *
1037
- * The reducer computes the provisional value from the current value and mutation
1038
- * input. The wrapped function result then completes the transition or updates the
1039
- * optimistic value through the provided setter callback.
1040
- *
1041
- * @category combinators
1042
- * @since 4.0.0
1043
- */
1044
- declare const optimisticFn: {
1045
- <A, W, XA, XE, OW = void>(options: {
1046
- readonly reducer: (current: NoInfer<A>, update: OW) => NoInfer<W>;
1047
- readonly fn: AtomResultFn<OW, XA, XE> | ((set: (result: NoInfer<W>) => void) => AtomResultFn<OW, XA, XE>);
1048
- }): (self: Writable<A, Atom<Result<W, unknown>>>) => AtomResultFn<OW, XA, XE>;
1049
- <A, W, XA, XE, OW = void>(self: Writable<A, Atom<Result<W, unknown>>>, options: {
1050
- readonly reducer: (current: NoInfer<A>, update: OW) => NoInfer<W>;
1051
- readonly fn: AtomResultFn<OW, XA, XE> | ((set: (result: NoInfer<W>) => void) => AtomResultFn<OW, XA, XE>);
1052
- }): AtomResultFn<OW, XA, XE>;
1053
- };
1054
- /**
1055
- * Runs synchronous atom updates as a batch.
1056
- *
1057
- * **Details**
1058
- *
1059
- * Stale nodes are rebuilt and listeners are notified after the callback completes,
1060
- * so dependent updates observe the final batched state.
1061
- *
1062
- * @category batching
1063
- * @since 4.0.0
1064
- */
1065
- declare const batch: (f: () => void) => void;
1066
- /**
1067
- * Creates a writable atom backed by a `KeyValueStore` entry.
1068
- *
1069
- * **Details**
1070
- *
1071
- * Values are encoded and decoded with the supplied schema. In sync mode the atom
1072
- * exposes the decoded value and writes the default value when the key is missing;
1073
- * in async mode it exposes an `AsyncResult` of the decoded value.
1074
- *
1075
- * **Gotchas**
1076
- *
1077
- * Error surfacing differs by mode. Async mode reports a failed store read as an
1078
- * `AsyncResult.failure`; sync mode has no error channel on its bare value, so a
1079
- * failed read renders the default value instead. Writes are optimistic in both
1080
- * modes: the value is shown immediately and the store write is fired in the
1081
- * background, so a write the store later refuses is not reflected in the atom.
1082
- * Use async mode when store failures must be observable.
1083
- *
1084
- * @category constructors
1085
- * @since 4.0.0
1086
- */
1087
- declare function kvs<S extends Schema.ConstraintCodec<any, any>, const Mode extends 'sync' | 'async' = never>(options: {
1088
- readonly runtime: AtomRuntime<KeyValueStore.KeyValueStore, any>;
1089
- readonly key: string;
1090
- readonly schema: S;
1091
- readonly defaultValue: LazyArg<S['Type']>;
1092
- readonly mode?: Mode | undefined;
1093
- }): Writable<'async' extends Mode ? Result<S['Type']> : S['Type'], S['Type']>;
1094
- /**
1095
- * Converts an atom into a stream using the `AtomRegistry` service.
1096
- *
1097
- * **Details**
1098
- *
1099
- * The stream emits the atom's current value immediately and then emits subsequent
1100
- * changes until the stream scope is closed.
1101
- *
1102
- * @category converting
1103
- * @since 4.0.0
1104
- */
1105
- declare const toStream: <A>(self: Atom<A>) => Stream.Stream<A, never, AtomRegistry>;
1106
- /**
1107
- * Converts an `AsyncResult` atom into a stream using the `AtomRegistry` service.
1108
- *
1109
- * **Details**
1110
- *
1111
- * Initial results are skipped, successes are emitted as stream values, and
1112
- * failures fail the stream with the result cause.
1113
- *
1114
- * @category converting
1115
- * @since 4.0.0
1116
- */
1117
- declare const toStreamResult: <A, E>(self: Atom<Result<A, E>>) => Stream.Stream<A, E, AtomRegistry>;
1118
- /**
1119
- * Reads an atom's current value from the `AtomRegistry` service.
1120
- *
1121
- * @category converting
1122
- * @since 4.0.0
1123
- */
1124
- declare const get: <A>(self: Atom<A>) => Effect.Effect<A, never, AtomRegistry>;
1125
- /**
1126
- * Reads a writable atom, computes a return value and next write value, writes the
1127
- * next value, and returns the computed result.
1128
- *
1129
- * @category converting
1130
- * @since 4.0.0
1131
- */
1132
- declare const modify: {
1133
- <R, W, A>(f: (_: R) => [returnValue: A, nextValue: W]): (self: Writable<R, W>) => Effect.Effect<A, never, AtomRegistry>;
1134
- <R, W, A>(self: Writable<R, W>, f: (_: R) => [returnValue: A, nextValue: W]): Effect.Effect<A, never, AtomRegistry>;
1135
- };
1136
- /**
1137
- * Writes a value to a writable atom through the `AtomRegistry` service.
1138
- *
1139
- * @category converting
1140
- * @since 4.0.0
1141
- */
1142
- declare const set: {
1143
- <W>(value: W): <R>(self: Writable<R, W>) => Effect.Effect<void, never, AtomRegistry>;
1144
- <R, W>(self: Writable<R, W>, value: W): Effect.Effect<void, never, AtomRegistry>;
1145
- };
1146
- /**
1147
- * Updates a writable atom by reading its current value from the registry and
1148
- * writing the value returned by the update function.
1149
- *
1150
- * @category converting
1151
- * @since 4.0.0
1152
- */
1153
- declare const update: {
1154
- <R, W>(f: (_: R) => W): (self: Writable<R, W>) => Effect.Effect<void, never, AtomRegistry>;
1155
- <R, W>(self: Writable<R, W>, f: (_: R) => W): Effect.Effect<void, never, AtomRegistry>;
1156
- };
1157
- /**
1158
- * Reads an `AsyncResult` atom as an effect through the `AtomRegistry` service.
1159
- *
1160
- * **Details**
1161
- *
1162
- * The effect waits while the result is `Initial`, and also while it is waiting
1163
- * when `suspendOnWaiting` is enabled. Successes succeed with the value and
1164
- * failures fail with the result cause.
1165
- *
1166
- * @category converting
1167
- * @since 4.0.0
1168
- */
1169
- declare const getResult: <A, E>(self: Atom<Result<A, E>>, options?: {
1170
- readonly suspendOnWaiting?: boolean | undefined;
1171
- }) => Effect.Effect<A, E, AtomRegistry>;
1172
- /**
1173
- * Runs a refresh request for an atom through the `AtomRegistry` service.
1174
- *
1175
- * **When to use**
1176
- *
1177
- * Use to invalidate and recompute an atom from an Effect that has access to the
1178
- * active registry.
1179
- *
1180
- * @category converting
1181
- * @since 4.0.0
1182
- */
1183
- declare const refresh: <A>(self: Atom<A>) => Effect.Effect<void, never, AtomRegistry>;
1184
- /**
1185
- * Mounts an atom in the `AtomRegistry` for the lifetime of the current scope.
1186
- *
1187
- * **Details**
1188
- *
1189
- * Mounting keeps the atom subscribed with a no-op listener until the scope
1190
- * finalizer releases it.
1191
- *
1192
- * @category converting
1193
- * @since 4.0.0
1194
- */
1195
- declare const mount: <A>(self: Atom<A>) => Effect.Effect<void, never, AtomRegistry | Scope$1.Scope>;
1196
- /**
1197
- * The type id used to mark atoms that carry serialization metadata.
1198
- *
1199
- * @category type IDs
1200
- * @since 4.0.0
1201
- */
1202
- declare const SerializableTypeId: SerializableTypeId;
1203
- /**
1204
- * The literal type of the serializable atom marker.
1205
- *
1206
- * @category type IDs
1207
- * @since 4.0.0
1208
- */
1209
- type SerializableTypeId = '~effect-atom/atom/Atom/Serializable';
1210
- /**
1211
- * Serialization metadata attached to an atom.
1212
- *
1213
- * **Details**
1214
- *
1215
- * The key identifies the atom in dehydrated state, and the encode/decode
1216
- * functions convert between the atom value and the schema encoded value.
1217
- *
1218
- * @category models
1219
- * @since 4.0.0
1220
- */
1221
- interface Serializable<S extends Schema.Constraint> {
1222
- readonly [SerializableTypeId]: {
1223
- readonly key: string;
1224
- readonly encode: (value: S['Type']) => S['Encoded'];
1225
- readonly decode: (value: S['Encoded']) => S['Type'];
1226
- };
1227
- }
1228
- /**
1229
- * Returns `true` when an atom carries `Serializable` metadata.
1230
- *
1231
- * @category guards
1232
- * @since 4.0.0
1233
- */
1234
- declare const isSerializable: (self: Atom<any>) => self is Atom<any> & Serializable<any>;
1235
- /**
1236
- * Attaches serialization metadata to an atom using a schema and stable key.
1237
- *
1238
- * **Details**
1239
- *
1240
- * The schema is converted to a JSON codec for synchronous encode/decode, and the
1241
- * key is also used as the atom label when the atom does not already have one.
1242
- *
1243
- * @category combinators
1244
- * @since 4.0.0
1245
- */
1246
- declare const serializable: {
1247
- <R extends Atom<any>, S extends Schema.ConstraintCodec<Type<R>, any>>(options: {
1248
- readonly key: string;
1249
- readonly schema: S;
1250
- }): (self: R) => R & Serializable<S>;
1251
- <R extends Atom<any>, S extends Schema.ConstraintCodec<Type<R>, any>>(self: R, options: {
1252
- readonly key: string;
1253
- readonly schema: S;
1254
- }): R & Serializable<S>;
1255
- };
1256
- //#endregion
1257
- export { withEquality as $, getResult as A, readable as At, optimistic as B, batch as C, mount$1 as Ct, fn as D, WritableTypeId as Dt, family as E, TypeId$1 as Et, make as F, serializable as G, pull as H, map as I, subscriptionRef as J, set as K, mapResult as L, isSerializable as M, transform as Mt, keepAlive as N, writable as Nt, fnSync as O, isAtom as Ot, kvs as P, update as Q, modify as R, autoDispose as S, make$1 as St, debounce as T, toStreamResult$1 as Tt, refresh as U, optimisticFn as V, runtime as W, toStream as X, swr as Y, toStreamResult as Z, Success as _, TypeId as _t, Atom_d_exports as a, ServerValueTypeId as at, Writable as b, layer as bt, Interrupt as c, withServerValueInitial as ct, RegistryRuntimeFactory as d, searchParam as dt, withFallback as et, Reset as f, windowFocusSignal as ft, SharedRuntimeFactory as g, Registry_d_exports as gt, SerializableTypeId as h, Registry as ht, AtomRuntime as i, ServerValue as it, initialValue as j, setIdleTTL as jt, get as k, isWritable as kt, PullResult as l, makeRefreshOnSignal as lt, Serializable as m, Node as mt, AtomContext as n, withReactivity as nt, Failure as o, getServerValue as ot, RuntimeFactory as p, AtomRegistry as pt, setLazy as q, AtomResultFn as r, withRefresh as rt, FnContext as s, withServerValue as st, Atom as t, withLabel as tt, PullSuccess as u, refreshOnWindowFocus as ut, Type as v, getResult$1 as vt, context as w, toStream$1 as wt, WriteContext as x, layerOptions as xt, WithoutSerializable as y, isAtomRegistry as yt, mount as z };