@solidjs/signals 0.13.12 → 2.0.0-beta.7

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 (39) hide show
  1. package/README.md +8 -7
  2. package/dist/dev.js +188 -102
  3. package/dist/node.cjs +501 -446
  4. package/dist/prod.js +368 -305
  5. package/dist/types/core/graph.d.ts +1 -0
  6. package/dist/types/core/types.d.ts +2 -2
  7. package/dist/types/signals.d.ts +15 -21
  8. package/dist/types/store/optimistic.d.ts +2 -2
  9. package/dist/types/store/projection.d.ts +4 -4
  10. package/dist/types/store/store.d.ts +2 -2
  11. package/dist/types-cjs/boundaries.d.cts +52 -0
  12. package/dist/types-cjs/core/action.d.cts +1 -0
  13. package/dist/types-cjs/core/async.d.cts +6 -0
  14. package/dist/types-cjs/core/constants.d.cts +25 -0
  15. package/dist/types-cjs/core/context.d.cts +28 -0
  16. package/dist/types-cjs/core/core.d.cts +54 -0
  17. package/dist/types-cjs/core/dev.d.cts +49 -0
  18. package/dist/types-cjs/core/effect.d.cts +30 -0
  19. package/dist/types-cjs/core/error.d.cts +14 -0
  20. package/dist/types-cjs/core/external.d.cts +26 -0
  21. package/dist/types-cjs/core/graph.d.cts +4 -0
  22. package/dist/types-cjs/core/heap.d.cts +14 -0
  23. package/dist/types-cjs/core/index.d.cts +12 -0
  24. package/dist/types-cjs/core/lanes.d.cts +54 -0
  25. package/dist/types-cjs/core/owner.d.cts +26 -0
  26. package/dist/types-cjs/core/scheduler.d.cts +81 -0
  27. package/dist/types-cjs/core/types.d.cts +86 -0
  28. package/dist/types-cjs/index.d.cts +9 -0
  29. package/dist/types-cjs/map.d.cts +24 -0
  30. package/dist/types-cjs/package.json +3 -0
  31. package/dist/types-cjs/signals.d.cts +186 -0
  32. package/dist/types-cjs/store/index.d.cts +9 -0
  33. package/dist/types-cjs/store/optimistic.d.cts +19 -0
  34. package/dist/types-cjs/store/projection.d.cts +26 -0
  35. package/dist/types-cjs/store/reconcile.d.cts +1 -0
  36. package/dist/types-cjs/store/store.d.cts +68 -0
  37. package/dist/types-cjs/store/storePath.d.cts +30 -0
  38. package/dist/types-cjs/store/utils.d.cts +43 -0
  39. package/package.json +31 -24
@@ -0,0 +1,81 @@
1
+ import { type Heap } from "./heap.cjs";
2
+ import { activeLanes, assignOrMergeLane, findLane } from "./lanes.cjs";
3
+ import type { Computed, Signal } from "./types.cjs";
4
+ export { activeLanes, assignOrMergeLane, findLane };
5
+ export { getOrCreateLane, hasActiveOverride, mergeLanes, resolveLane } from "./lanes.cjs";
6
+ export declare const dirtyQueue: Heap;
7
+ export declare const zombieQueue: Heap;
8
+ export declare let clock: number;
9
+ export declare let activeTransition: Transition | null;
10
+ export declare let projectionWriteActive: boolean;
11
+ export declare let _hitUnhandledAsync: boolean;
12
+ export declare function resetUnhandledAsync(): void;
13
+ export declare function enforceLoadingBoundary(enabled: boolean): void;
14
+ export declare function shouldReadStashedOptimisticValue(node: Signal<any>): boolean;
15
+ export declare function setProjectionWriteActive(value: boolean): void;
16
+ export declare function setTrackedQueueCallback(value: boolean): void;
17
+ export type QueueCallback = (type: number) => void;
18
+ type QueueStub = {
19
+ _queues: [QueueCallback[], QueueCallback[]];
20
+ _children: QueueStub[];
21
+ };
22
+ type OptimisticNode = Signal<any> | Computed<any>;
23
+ export interface Transition {
24
+ _time: number;
25
+ _asyncReporters: Map<Computed<any>, Set<Computed<any>>>;
26
+ _pendingNodes: Signal<any>[];
27
+ _optimisticNodes: OptimisticNode[];
28
+ _optimisticStores: Set<any>;
29
+ _actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
30
+ _queueStash: QueueStub;
31
+ _done: boolean | Transition;
32
+ }
33
+ export declare function schedule(): void;
34
+ export interface IQueue {
35
+ enqueue(type: number, fn: QueueCallback): void;
36
+ run(type: number): boolean | void;
37
+ addChild(child: IQueue): void;
38
+ removeChild(child: IQueue): void;
39
+ created: number;
40
+ notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
41
+ stashQueues(stub: QueueStub): void;
42
+ restoreQueues(stub: QueueStub): void;
43
+ _parent: IQueue | null;
44
+ }
45
+ export declare class Queue implements IQueue {
46
+ _parent: IQueue | null;
47
+ _queues: [QueueCallback[], QueueCallback[]];
48
+ _children: IQueue[];
49
+ created: number;
50
+ addChild(child: IQueue): void;
51
+ removeChild(child: IQueue): void;
52
+ notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
53
+ run(type: number): void;
54
+ enqueue(type: number, fn: QueueCallback): void;
55
+ stashQueues(stub: QueueStub): void;
56
+ restoreQueues(stub: QueueStub): void;
57
+ }
58
+ export declare class GlobalQueue extends Queue {
59
+ _running: boolean;
60
+ _pendingNodes: Signal<any>[];
61
+ _optimisticNodes: OptimisticNode[];
62
+ _optimisticStores: Set<any>;
63
+ static _update: (el: Computed<unknown>) => void;
64
+ static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
65
+ static _clearOptimisticStore: ((store: any) => void) | null;
66
+ flush(): void;
67
+ notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
68
+ initTransition(transition?: Transition | null): void;
69
+ }
70
+ export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
71
+ export declare function finalizePureQueue(completingTransition?: Transition | null, incomplete?: boolean): void;
72
+ export declare function trackOptimisticStore(store: any): void;
73
+ export declare const globalQueue: GlobalQueue;
74
+ /**
75
+ * By default, changes are batched on the microtask queue which is an async process. You can flush
76
+ * the queue synchronously to get the latest updates by calling `flush()`.
77
+ */
78
+ export declare function flush(): void;
79
+ export declare function currentTransition(transition: Transition): Transition;
80
+ export declare function setActiveTransition(transition: Transition | null): void;
81
+ export declare function runInTransition<T>(transition: Transition, fn: () => T): T;
@@ -0,0 +1,86 @@
1
+ import type { NOT_PENDING } from "./constants.cjs";
2
+ import type { OptimisticLane } from "./lanes.cjs";
3
+ import type { IQueue, Transition } from "./scheduler.cjs";
4
+ export interface Disposable {
5
+ (): void;
6
+ }
7
+ export interface Link {
8
+ _dep: Signal<unknown> | Computed<unknown>;
9
+ _sub: Computed<unknown>;
10
+ _nextDep: Link | null;
11
+ _prevSub: Link | null;
12
+ _nextSub: Link | null;
13
+ }
14
+ export interface NodeOptions<T> {
15
+ id?: string;
16
+ name?: string;
17
+ transparent?: boolean;
18
+ equals?: ((prev: T, next: T) => boolean) | false;
19
+ ownedWrite?: boolean;
20
+ /** Exclude this signal from snapshot capture (internal — not part of public API) */
21
+ _noSnapshot?: boolean;
22
+ unobserved?: () => void;
23
+ lazy?: boolean;
24
+ }
25
+ export interface RawSignal<T> {
26
+ _subs: Link | null;
27
+ _subsTail: Link | null;
28
+ _value: T;
29
+ _snapshotValue?: any;
30
+ _name?: string;
31
+ _equals: false | ((a: T, b: T) => boolean);
32
+ _ownedWrite?: boolean;
33
+ _noSnapshot?: boolean;
34
+ _unobserved?: () => void;
35
+ _time: number;
36
+ _transition: Transition | null;
37
+ _pendingValue: T | typeof NOT_PENDING;
38
+ _overrideValue?: T | typeof NOT_PENDING;
39
+ _optimisticLane?: OptimisticLane;
40
+ _pendingSignal?: Signal<boolean>;
41
+ _latestValueComputed?: Computed<T>;
42
+ _parentSource?: Signal<any> | Computed<any>;
43
+ }
44
+ export interface FirewallSignal<T> extends RawSignal<T> {
45
+ _firewall: Computed<any>;
46
+ _nextChild: FirewallSignal<unknown> | null;
47
+ }
48
+ export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
49
+ export interface Owner {
50
+ id?: string;
51
+ _transparent?: boolean;
52
+ _childrenForbidden?: boolean;
53
+ _snapshotScope?: boolean;
54
+ _disposal: Disposable | Disposable[] | null;
55
+ _parent: Owner | null;
56
+ _context: Record<symbol | string, unknown>;
57
+ _childCount: number;
58
+ _queue: IQueue;
59
+ _firstChild: Owner | null;
60
+ _nextSibling: Owner | null;
61
+ _pendingDisposal: Disposable | Disposable[] | null;
62
+ _pendingFirstChild: Owner | null;
63
+ }
64
+ export interface Computed<T> extends RawSignal<T>, Owner {
65
+ _deps: Link | null;
66
+ _depsTail: Link | null;
67
+ _flags: number;
68
+ _inSnapshotScope?: boolean;
69
+ _blocked?: boolean;
70
+ _pendingSource?: Computed<any>;
71
+ _pendingSources?: Set<Computed<any>>;
72
+ _error?: unknown;
73
+ _statusFlags: number;
74
+ _height: number;
75
+ _nextHeap: Computed<any> | undefined;
76
+ _prevHeap: Computed<any>;
77
+ _fn: (prev?: T) => T;
78
+ _inFlight: PromiseLike<T> | AsyncIterable<T> | null;
79
+ _child: FirewallSignal<any> | null;
80
+ _notifyStatus?: (status?: number, error?: any) => void;
81
+ }
82
+ export interface Root extends Owner {
83
+ _root: true;
84
+ _parentComputed: Computed<any> | null;
85
+ dispose(self?: boolean): void;
86
+ }
@@ -0,0 +1,9 @@
1
+ export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, isRefreshing, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource } from "./core/index.cjs";
2
+ import { type Dev } from "./core/index.cjs";
3
+ export declare const DEV: Dev | undefined;
4
+ export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
5
+ export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.cjs";
6
+ export type { Accessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
7
+ export { mapArray, repeat, type Maybe } from "./map.cjs";
8
+ export * from "./store/index.cjs";
9
+ export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten } from "./boundaries.cjs";
@@ -0,0 +1,24 @@
1
+ import { type Accessor } from "./signals.cjs";
2
+ export type Maybe<T> = T | void | null | undefined | false;
3
+ /**
4
+ * Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
5
+ *
6
+ * similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
7
+ *
8
+ * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
9
+ */
10
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
11
+ keyed?: boolean | ((item: Item) => any);
12
+ fallback?: Accessor<any>;
13
+ name?: string;
14
+ }): Accessor<MappedItem[]>;
15
+ /**
16
+ * Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
17
+ *
18
+ * @description https://docs.solidjs.com/reference/reactive-utilities/repeat
19
+ */
20
+ export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
21
+ from?: Accessor<number | undefined>;
22
+ fallback?: Accessor<any>;
23
+ name?: string;
24
+ }): Accessor<any[]>;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,186 @@
1
+ import type { Disposable } from "./core/index.cjs";
2
+ export declare function onCleanup(fn: Disposable): Disposable;
3
+ export type Accessor<T> = () => T;
4
+ export declare function accessor<T>(node: any): Accessor<T>;
5
+ export type Setter<in out T> = {
6
+ <U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
7
+ <U extends T>(value: (prev: T) => U): U;
8
+ <U extends T>(value: Exclude<U, Function>): U;
9
+ <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
10
+ };
11
+ export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
12
+ export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => PromiseLike<Next> | AsyncIterable<Next> | Next;
13
+ export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
14
+ export type EffectBundle<Prev, Next extends Prev = Prev> = {
15
+ effect: EffectFunction<Prev, Next>;
16
+ error: (err: unknown, cleanup: () => void) => void;
17
+ };
18
+ /** Options for effect primitives (`createEffect`, `createRenderEffect`, `createTrackedEffect`, `createReaction`). */
19
+ export interface EffectOptions {
20
+ /** Debug name (dev mode only) */
21
+ name?: string;
22
+ /** When true, defers the initial effect execution until the next change */
23
+ defer?: boolean;
24
+ }
25
+ /** Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`. */
26
+ export interface SignalOptions<T> {
27
+ /** Debug name (dev mode only) */
28
+ name?: string;
29
+ /** Custom equality function, or `false` to always notify subscribers */
30
+ equals?: false | ((prev: T, next: T) => boolean);
31
+ /** Suppress dev-mode warnings when writing inside an owned scope */
32
+ ownedWrite?: boolean;
33
+ /** Callback invoked when the signal loses all subscribers */
34
+ unobserved?: () => void;
35
+ }
36
+ /**
37
+ * Options for read-only memos created with `createMemo`.
38
+ * Also used in combination with `SignalOptions` for writable memos
39
+ * (`createSignal(fn)` / `createOptimistic(fn)`).
40
+ */
41
+ export interface MemoOptions<T> {
42
+ /** Stable identifier for the owner hierarchy */
43
+ id?: string;
44
+ /** Debug name (dev mode only) */
45
+ name?: string;
46
+ /** When true, the owner is invisible to the ID scheme -- inherits parent ID and doesn't consume a childCount slot */
47
+ transparent?: boolean;
48
+ /** Custom equality function, or `false` to always notify subscribers */
49
+ equals?: false | ((prev: T, next: T) => boolean);
50
+ /** Callback invoked when the computed loses all subscribers */
51
+ unobserved?: () => void;
52
+ /** When true, defers the initial computation until the value is first read */
53
+ lazy?: boolean;
54
+ }
55
+ export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
56
+ /**
57
+ * Creates a simple reactive state with a getter and setter.
58
+ *
59
+ * When called with a plain value, creates a signal with `SignalOptions` (name, equals, ownedWrite, unobserved).
60
+ * When called with a function, creates a writable memo with `SignalOptions & MemoOptions` (adds id, lazy).
61
+ *
62
+ * ```typescript
63
+ * // Plain signal
64
+ * const [state, setState] = createSignal<T>(value, options?: SignalOptions<T>);
65
+ * // Writable memo (function overload)
66
+ * const [state, setState] = createSignal<T>(fn, initialValue?, options?: SignalOptions<T> & MemoOptions<T>);
67
+ * ```
68
+ * @param value initial value of the state; if empty, the state's type will automatically extended with undefined
69
+ * @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
70
+ *
71
+ * @returns `[state: Accessor<T>, setState: Setter<T>]`
72
+ *
73
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
74
+ */
75
+ export declare function createSignal<T>(): Signal<T | undefined>;
76
+ export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
77
+ export declare function createSignal<T>(fn: ComputeFunction<T>, options?: SignalOptions<T> & MemoOptions<T>): Signal<T>;
78
+ /**
79
+ * Creates a readonly derived reactive memoized signal.
80
+ *
81
+ * ```typescript
82
+ * const value = createMemo<T>(compute, options?: MemoOptions<T>);
83
+ * ```
84
+ * @param compute a function that receives its previous value and returns a new value used to react on a computation
85
+ * @param options `MemoOptions` -- id, name, equals, unobserved, lazy
86
+ *
87
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
88
+ */
89
+ export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, options?: MemoOptions<T>): Accessor<T>;
90
+ /**
91
+ * Creates a reactive effect that runs after the render phase.
92
+ *
93
+ * ```typescript
94
+ * createEffect<T>(compute, effectFn | { effect, error }, options?: EffectOptions);
95
+ * ```
96
+ * @param compute a function that receives its previous value and returns a new value used to react on a computation
97
+ * @param effectFn a function that receives the new value and is used to perform side effects (return a cleanup function), or an `EffectBundle` with `effect` and `error` handlers
98
+ * @param options `EffectOptions` -- name, defer
99
+ *
100
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
101
+ */
102
+ export declare function createEffect<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, effectFn: EffectFunction<NoInfer<T>, T> | EffectBundle<NoInfer<T>, T>, options?: EffectOptions): void;
103
+ /**
104
+ * Creates a reactive computation that runs during the render phase as DOM elements
105
+ * are created and updated but not necessarily connected.
106
+ *
107
+ * ```typescript
108
+ * createRenderEffect<T>(compute, effectFn, options?: EffectOptions);
109
+ * ```
110
+ * @param compute a function that receives its previous value and returns a new value used to react on a computation
111
+ * @param effectFn a function that receives the new value and is used to perform side effects
112
+ * @param options `EffectOptions` -- name, defer
113
+ *
114
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
115
+ */
116
+ export declare function createRenderEffect<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, effectFn: EffectFunction<NoInfer<T>, T>, options?: EffectOptions): void;
117
+ /**
118
+ * Creates a tracked reactive effect where dependency tracking and side effects happen
119
+ * in the same scope.
120
+ *
121
+ * WARNING: Because tracking and effects happen in the same scope, this primitive
122
+ * may run multiple times for a single change or show tearing (reading inconsistent
123
+ * state). Use only when dynamic subscription patterns require same-scope tracking.
124
+ *
125
+ * ```typescript
126
+ * createTrackedEffect(compute, options?: EffectOptions);
127
+ * ```
128
+ * @param compute a function that contains reactive reads to track and returns an optional cleanup function to run on disposal or before next execution
129
+ * @param options `EffectOptions` -- name, defer
130
+ *
131
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-tracked-effect
132
+ */
133
+ export declare function createTrackedEffect(compute: () => void | (() => void), options?: EffectOptions): void;
134
+ /**
135
+ * Creates a reactive computation that runs after the render phase with flexible tracking.
136
+ *
137
+ * ```typescript
138
+ * const track = createReaction(effectFn, options?: EffectOptions);
139
+ * track(() => { // reactive reads });
140
+ * ```
141
+ * @param effectFn a function (or `EffectBundle`) that is called when tracked function is invalidated
142
+ * @param options `EffectOptions` -- name, defer
143
+ *
144
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
145
+ */
146
+ export declare function createReaction(effectFn: EffectFunction<undefined> | EffectBundle<undefined>, options?: EffectOptions): (tracking: () => void) => void;
147
+ /**
148
+ * Returns a promise of the resolved value of a reactive expression
149
+ * @param fn a reactive expression to resolve
150
+ */
151
+ export declare function resolve<T>(fn: () => T): Promise<T>;
152
+ /**
153
+ * Creates an optimistic signal that can be used to optimistically update a value
154
+ * and then revert it back to the previous value at end of transition.
155
+ *
156
+ * When called with a plain value, creates an optimistic signal with `SignalOptions` (name, equals, ownedWrite, unobserved).
157
+ * When called with a function, creates a writable optimistic memo with `SignalOptions & MemoOptions` (adds id, lazy).
158
+ *
159
+ * ```typescript
160
+ * // Plain optimistic signal
161
+ * const [state, setState] = createOptimistic<T>(value, options?: SignalOptions<T>);
162
+ * // Writable optimistic memo (function overload)
163
+ * const [state, setState] = createOptimistic<T>(fn, options?: SignalOptions<T> & MemoOptions<T>);
164
+ * ```
165
+ * @param value initial value of the signal; if empty, the signal's type will automatically extended with undefined
166
+ * @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
167
+ *
168
+ * @returns `[state: Accessor<T>, setState: Setter<T>]`
169
+ *
170
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-optimistic-signal
171
+ */
172
+ export declare function createOptimistic<T>(): Signal<T | undefined>;
173
+ export declare function createOptimistic<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
174
+ export declare function createOptimistic<T>(fn: ComputeFunction<T>, options?: SignalOptions<T> & MemoOptions<T>): Signal<T>;
175
+ /**
176
+ * Runs a callback after the current flush cycle completes.
177
+ *
178
+ * When called within a reactive context (owner), uses a tracked effect with untracked
179
+ * reads - this means normal signal reads won't create subscriptions, but uninitialized
180
+ * async values will throw NotReadyError, causing the callback to re-run when they settle.
181
+ *
182
+ * When called without an owner, runs once and immediately calls any returned cleanup.
183
+ *
184
+ * @param callback Function to run, may return a cleanup function
185
+ */
186
+ export declare function onSettled(callback: () => void | (() => void)): void;
@@ -0,0 +1,9 @@
1
+ export type { Store, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.cjs";
2
+ export type { Merge, Omit } from "./utils.cjs";
3
+ export { isWrappable, createStore, $TRACK, $PROXY, $TARGET } from "./store.cjs";
4
+ export { createProjection } from "./projection.cjs";
5
+ export { createOptimisticStore } from "./optimistic.cjs";
6
+ export { reconcile } from "./reconcile.cjs";
7
+ export { storePath } from "./storePath.cjs";
8
+ export type { PathSetter, Part, StorePathRange, ArrayFilterFn, CustomPartial } from "./storePath.cjs";
9
+ export { snapshot, deep, merge, omit } from "./utils.cjs";
@@ -0,0 +1,19 @@
1
+ import { $REFRESH } from "../core/index.cjs";
2
+ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from "./store.cjs";
3
+ /**
4
+ * Creates an optimistic store that can be used to optimistically update a value
5
+ * and then revert it back to the previous value at end of transition.
6
+ *
7
+ * When called with a plain value, creates an optimistic store.
8
+ * When called with a function, creates a derived optimistic store with `ProjectionOptions` (name, key, all).
9
+ *
10
+ * @param fn a function that receives the current store and can be used to mutate it directly inside a transition
11
+ * @param store The plain store value, or the backing seed when using the derived-store form.
12
+ * @param options Optional projection options for reconciliation.
13
+ *
14
+ * @returns A tuple containing a store accessor and a setter function to apply changes.
15
+ */
16
+ export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
17
+ export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T> & {
18
+ [$REFRESH]: any;
19
+ }, set: StoreSetter<T>];
@@ -0,0 +1,26 @@
1
+ import { $REFRESH, type Computed } from "../core/index.cjs";
2
+ import { type ProjectionOptions, type Store } from "./store.cjs";
3
+ export declare function createProjectionInternal<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T>, options?: ProjectionOptions): {
4
+ store: Store<T> & {
5
+ [$REFRESH]: any;
6
+ };
7
+ node: Computed<void | T>;
8
+ };
9
+ /**
10
+ * Creates a mutable derived store (projection). The derive function receives a mutable
11
+ * draft and can mutate it directly or return a new value for reconciliation.
12
+ *
13
+ * ```typescript
14
+ * const store = createProjection<T>(fn, seed, options?: ProjectionOptions);
15
+ * ```
16
+ * @param fn a function that receives the current draft and mutates it or returns new data
17
+ * @param seed the backing store host value to wrap and reconcile into
18
+ * @param options `ProjectionOptions` -- name, key, all
19
+ *
20
+ * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
21
+ */
22
+ export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T>, options?: ProjectionOptions): Store<T> & {
23
+ [$REFRESH]: any;
24
+ };
25
+ export declare function createWriteTraps(isActive?: () => boolean): ProxyHandler<any>;
26
+ export declare const writeTraps: ProxyHandler<any>;
@@ -0,0 +1 @@
1
+ export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
@@ -0,0 +1,68 @@
1
+ import { $REFRESH, STORE_SNAPSHOT_PROPS, type Computed, type Signal } from "../core/index.cjs";
2
+ export type Store<T> = Readonly<T>;
3
+ export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
4
+ /** Base options for store primitives. */
5
+ export interface StoreOptions {
6
+ /** Debug name (dev mode only) */
7
+ name?: string;
8
+ }
9
+ /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
10
+ export interface ProjectionOptions extends StoreOptions {
11
+ /** Key property name or function for reconciliation identity */
12
+ key?: string | ((item: NonNullable<any>) => any);
13
+ }
14
+ export type NoFn<T> = T extends Function ? never : T;
15
+ type DataNode = Signal<any>;
16
+ type DataNodes = Record<PropertyKey, DataNode>;
17
+ export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
18
+ export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p";
19
+ export type StoreNode = {
20
+ [$PROXY]: any;
21
+ [STORE_VALUE]: Record<PropertyKey, any>;
22
+ [STORE_OVERRIDE]?: Record<PropertyKey, any>;
23
+ [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
24
+ [STORE_NODE]?: DataNodes;
25
+ [STORE_HAS]?: DataNodes;
26
+ [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
27
+ [STORE_LOOKUP]?: WeakMap<any, any>;
28
+ [STORE_FIREWALL]?: Computed<any>;
29
+ [STORE_OPTIMISTIC]?: boolean;
30
+ [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
31
+ };
32
+ export declare namespace SolidStore {
33
+ interface Unwrappable {
34
+ }
35
+ }
36
+ export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
37
+ export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
38
+ export declare const storeLookup: WeakMap<WeakKey, any>;
39
+ export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
40
+ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
41
+ export declare function setWriteOverride(value: boolean): void;
42
+ export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
43
+ export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
44
+ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
45
+ export declare const storeTraps: ProxyHandler<StoreNode>;
46
+ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
47
+ /**
48
+ * Creates a deeply reactive store with proxy-based tracking.
49
+ *
50
+ * When called with a plain value, wraps it in a reactive proxy.
51
+ * When called with a function, creates a derived projection store with `ProjectionOptions` (name, key, all).
52
+ *
53
+ * ```typescript
54
+ * // Plain store
55
+ * const [store, setStore] = createStore<T>(initialValue);
56
+ * // Derived store (projection)
57
+ * const [store, setStore] = createStore<T>(fn, seed, options?: ProjectionOptions);
58
+ * ```
59
+ * @param store initial value to wrap in a reactive proxy, or a derive function
60
+ * @param options `ProjectionOptions` -- name, key, all (only for derived stores)
61
+ *
62
+ * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
63
+ */
64
+ export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
65
+ export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T> & {
66
+ [$REFRESH]: any;
67
+ }, set: StoreSetter<T>];
68
+ export {};
@@ -0,0 +1,30 @@
1
+ import { type NotWrappable } from "./store.cjs";
2
+ type W<T> = Exclude<T, NotWrappable>;
3
+ type KeyOf<T> = number extends keyof T ? 0 extends 1 & T ? keyof T : [T] extends [never] ? never : [T] extends [readonly unknown[]] ? number : keyof T : keyof T;
4
+ export type CustomPartial<T> = T extends readonly unknown[] ? "0" extends keyof T ? {
5
+ [K in Extract<keyof T, `${number}`>]?: T[K];
6
+ } : {
7
+ [x: number]: T[number];
8
+ } : Partial<T>;
9
+ export type StorePathRange = {
10
+ from?: number;
11
+ to?: number;
12
+ by?: number;
13
+ };
14
+ export type ArrayFilterFn<T> = (item: T, index: number) => boolean;
15
+ export type PathSetter<T> = T | CustomPartial<T> | ((prev: T) => T | CustomPartial<T>) | typeof DELETE;
16
+ export type Part<T, K extends KeyOf<T> = KeyOf<T>> = K | ([K] extends [never] ? never : readonly K[]) | ([T] extends [readonly unknown[]] ? ArrayFilterFn<T[number]> | StorePathRange : never);
17
+ declare const DELETE: unique symbol;
18
+ export interface storePath {
19
+ DELETE: typeof DELETE;
20
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, K7 extends KeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, setter: PathSetter<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7]>): (state: T) => void;
21
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, setter: PathSetter<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>): (state: T) => void;
22
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, setter: PathSetter<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>): (state: T) => void;
23
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, setter: PathSetter<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>): (state: T) => void;
24
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, setter: PathSetter<W<W<W<T>[K1]>[K2]>[K3]>): (state: T) => void;
25
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, setter: PathSetter<W<W<T>[K1]>[K2]>): (state: T) => void;
26
+ <T, K1 extends KeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: PathSetter<W<T>[K1]>): (state: T) => void;
27
+ <T>(setter: PathSetter<T>): (state: T) => void;
28
+ }
29
+ export declare const storePath: storePath;
30
+ export {};
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Returns a non reactive copy of the store object.
3
+ * It will attempt to preserver the original reference unless the value has been modified.
4
+ * @param item store proxy object
5
+ */
6
+ export declare function snapshot<T>(item: T): T;
7
+ export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
8
+ /**
9
+ * Returns a non-reactive snapshot of the store while subscribing to all nested changes.
10
+ * Subscribes to `$TRACK` at every level so that any deep change triggers recomputation,
11
+ * and returns plain (non-proxy) data. Works correctly with `reconcile()`.
12
+ * @param store store proxy object
13
+ */
14
+ export declare function deep<T extends object>(store: T): T;
15
+ type DistributeOverride<T, F> = T extends undefined ? F : T;
16
+ type Override<T, U> = T extends any ? U extends any ? {
17
+ [K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
18
+ } & {
19
+ [K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K];
20
+ } : T & U : T & U;
21
+ type OverrideSpread<T, U> = T extends any ? {
22
+ [K in keyof ({
23
+ [K in keyof T]: any;
24
+ } & {
25
+ [K in keyof U]?: any;
26
+ } & {
27
+ [K in U extends any ? keyof U : keyof U]?: any;
28
+ })]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never;
29
+ } : T & U;
30
+ type Simplify<T> = T extends any ? {
31
+ [K in keyof T]: T[K];
32
+ } : T;
33
+ type _Merge<T extends unknown[], Curr = {}> = T extends [
34
+ infer Next | (() => infer Next),
35
+ ...infer Rest
36
+ ] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
37
+ export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
38
+ export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
39
+ export type Omit<T, K extends readonly (keyof T)[]> = {
40
+ [P in keyof T as Exclude<P, K[number]>]: T[P];
41
+ };
42
+ export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
43
+ export {};