@solidjs/signals 2.0.0-rc.0 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dev.js +4287 -2803
- package/dist/node.cjs +4563 -3756
- package/dist/prod/affects.js +16 -16
- package/dist/prod/boundaries.js +90 -90
- package/dist/prod/core/action.js +3 -3
- package/dist/prod/core/async.js +234 -178
- package/dist/prod/core/constants.js +39 -1
- package/dist/prod/core/core.js +362 -243
- package/dist/prod/core/effect.js +56 -56
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +65 -54
- package/dist/prod/core/heap.js +47 -39
- package/dist/prod/core/invariants.js +3 -2
- package/dist/prod/core/lanes.js +41 -34
- package/dist/prod/core/optimistic.js +78 -58
- package/dist/prod/core/owner.js +101 -100
- package/dist/prod/core/scheduler.js +249 -192
- package/dist/prod/core/verdict.js +185 -78
- package/dist/prod/index.js +7 -7
- package/dist/prod/map.js +108 -106
- package/dist/prod/signals.js +20 -1
- package/dist/prod/store/index.js +36 -0
- package/dist/prod/store/next/optimistic.js +385 -0
- package/dist/prod/store/next/projection.js +172 -0
- package/dist/prod/store/next/reconcile.js +331 -0
- package/dist/prod/store/next/store.js +1499 -0
- package/dist/prod/store/next/target.js +20 -0
- package/dist/prod/store/store.js +126 -882
- package/dist/prod/store/utils.js +59 -186
- package/dist/types/core/attribution-hooks.d.ts +52 -0
- package/dist/types/core/attribution.d.ts +186 -0
- package/dist/types/core/constants.d.ts +26 -0
- package/dist/types/core/core.d.ts +16 -1
- package/dist/types/core/dev.d.ts +20 -3
- package/dist/types/core/graph.d.ts +1 -0
- package/dist/types/core/lanes.d.ts +4 -16
- package/dist/types/core/scheduler.d.ts +12 -2
- package/dist/types/core/types.d.ts +85 -41
- package/dist/types/signals.d.ts +19 -0
- package/dist/types/store/index.d.ts +15 -5
- package/dist/types/store/next/optimistic.d.ts +20 -0
- package/dist/types/store/next/projection.d.ts +8 -0
- package/dist/types/store/next/reconcile.d.ts +3 -0
- package/dist/types/store/next/store.d.ts +77 -0
- package/dist/types/store/next/target.d.ts +117 -0
- package/dist/types/store/store.d.ts +26 -101
- package/dist/types/store/utils.d.ts +0 -40
- package/dist/types-cjs/core/attribution-hooks.d.cts +52 -0
- package/dist/types-cjs/core/attribution.d.cts +186 -0
- package/dist/types-cjs/core/constants.d.cts +26 -0
- package/dist/types-cjs/core/core.d.cts +16 -1
- package/dist/types-cjs/core/dev.d.cts +20 -3
- package/dist/types-cjs/core/graph.d.cts +1 -0
- package/dist/types-cjs/core/lanes.d.cts +4 -16
- package/dist/types-cjs/core/scheduler.d.cts +12 -2
- package/dist/types-cjs/core/types.d.cts +85 -41
- package/dist/types-cjs/signals.d.cts +19 -0
- package/dist/types-cjs/store/index.d.cts +15 -5
- package/dist/types-cjs/store/next/optimistic.d.cts +20 -0
- package/dist/types-cjs/store/next/projection.d.cts +8 -0
- package/dist/types-cjs/store/next/reconcile.d.cts +3 -0
- package/dist/types-cjs/store/next/store.d.cts +77 -0
- package/dist/types-cjs/store/next/target.d.cts +117 -0
- package/dist/types-cjs/store/store.d.cts +26 -101
- package/dist/types-cjs/store/utils.d.cts +0 -40
- package/package.json +2 -1
- package/dist/prod/store/optimistic.js +0 -217
- package/dist/prod/store/projection.js +0 -231
- package/dist/prod/store/reconcile.js +0 -707
|
@@ -9,7 +9,6 @@ export declare let clock: number;
|
|
|
9
9
|
export declare let activeTransition: Transition | null;
|
|
10
10
|
export declare let projectionWriteActive: boolean;
|
|
11
11
|
export declare let _hitUnhandledAsync: boolean;
|
|
12
|
-
export declare function registerTransientStoreNode(node: Signal<any>): void;
|
|
13
12
|
export declare function resetUnhandledAsync(): void;
|
|
14
13
|
/**
|
|
15
14
|
* Toggles the dev-mode "must be inside a `<Loading>` boundary" enforcement
|
|
@@ -22,6 +21,7 @@ export declare function resetUnhandledAsync(): void;
|
|
|
22
21
|
export declare function enforceLoadingBoundary(enabled: boolean): void;
|
|
23
22
|
export declare function setProjectionWriteActive(value: boolean): void;
|
|
24
23
|
export declare function setTrackedQueueCallback(value: boolean): void;
|
|
24
|
+
export declare function setEffectCallback(value: boolean): void;
|
|
25
25
|
export type QueueCallback = (type: number) => void;
|
|
26
26
|
type QueueStub = {
|
|
27
27
|
_queues: [QueueCallback[], QueueCallback[]];
|
|
@@ -97,6 +97,7 @@ export declare class GlobalQueue extends Queue {
|
|
|
97
97
|
static _applyReask: ((el: Computed<any>, hadReask: boolean) => boolean) | null;
|
|
98
98
|
static _repollVerdicts: ((el: Computed<any>, snap?: boolean) => void) | null;
|
|
99
99
|
static _witnessAffects: ((node: OptimisticNode) => void) | null;
|
|
100
|
+
static _wakeSuppressedProbes: ((transition: Transition) => void) | null;
|
|
100
101
|
static _optimisticWrite: (<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)) => T) | null;
|
|
101
102
|
static _resolveOptimistic: ((nodes: OptimisticNode[]) => void) | null;
|
|
102
103
|
static _transitionBlocked: ((transition: Transition) => boolean) | null;
|
|
@@ -105,7 +106,7 @@ export declare class GlobalQueue extends Queue {
|
|
|
105
106
|
static _gatedRead: ((el: Signal<any>, owner: OptimisticNode, c: Computed<any>) => boolean) | null;
|
|
106
107
|
static _laneSuspends: ((owner: OptimisticNode) => boolean) | null;
|
|
107
108
|
static _laneReadsCommitted: ((el: OptimisticNode, owner: OptimisticNode, c: Computed<any>) => boolean) | null;
|
|
108
|
-
static _recomputeLane: ((el: Computed<any>, own: boolean) => OptimisticLane | null) | null;
|
|
109
|
+
static _recomputeLane: ((el: Computed<any>, own: boolean) => OptimisticLane | null | false) | null;
|
|
109
110
|
static _laneAsyncPending: ((el: Computed<any>) => void) | null;
|
|
110
111
|
static _laneAsyncSettled: ((el: Computed<any>) => void) | null;
|
|
111
112
|
static _trackOptimisticStore: ((store: any) => void) | null;
|
|
@@ -114,8 +115,17 @@ export declare class GlobalQueue extends Queue {
|
|
|
114
115
|
initTransition(transition?: Transition | null): void;
|
|
115
116
|
}
|
|
116
117
|
export declare function queuePendingNode(node: Signal<any>): void;
|
|
118
|
+
export declare let reaskArmed: boolean;
|
|
119
|
+
/** §12d: bumped by every recompute and every new subscriber edge. A node's
|
|
120
|
+
* staged-rewrite skip is sound only while NOTHING recomputed or linked since
|
|
121
|
+
* its last notify — a mid-batch pull can clean a marked subscriber, and a
|
|
122
|
+
* skipped re-write would leave it stale. */
|
|
123
|
+
export declare let notifyEpoch: number;
|
|
124
|
+
export declare function bumpNotifyEpoch(): void;
|
|
117
125
|
export declare function armReaskClear(): void;
|
|
118
126
|
export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
|
|
127
|
+
export declare let storeCommitHook: (() => void) | null;
|
|
128
|
+
export declare function setStoreCommitHook(fn: () => void): void;
|
|
119
129
|
export declare function finalizePureQueue(completingTransition?: Transition | null, incomplete?: boolean): void;
|
|
120
130
|
/**
|
|
121
131
|
* Count of live `affects()` registrations across the system (including
|
|
@@ -41,19 +41,19 @@ export interface NodeOptions<T> {
|
|
|
41
41
|
*/
|
|
42
42
|
loadingValue?: T;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_overrideValue
|
|
44
|
+
/**
|
|
45
|
+
* Cold node extension (stage-3 §12): optional machinery that most nodes
|
|
46
|
+
* never touch lives one hop away so the CORE node literal stays under V8's
|
|
47
|
+
* in-object property boundary (~39 fields measured: past it, every literal
|
|
48
|
+
* allocation spills to an out-of-object backing store and creation cost
|
|
49
|
+
* roughly quadruples — the create0to1 cliff). Allocated lazily by `ext()`
|
|
50
|
+
* on first installer write; ONE shape shared by signals and computeds so
|
|
51
|
+
* `_x` access stays monomorphic. Presence bits on `_config`
|
|
52
|
+
* (CONFIG_OPTIMISTIC / HAS_COMPANIONS / HAS_LANE / HAS_SNAPSHOT) remain the
|
|
53
|
+
* hot-path gates — a bit says "consult _x", never the reverse.
|
|
54
|
+
*/
|
|
55
|
+
export interface NodeExtension {
|
|
56
|
+
_overrideValue: unknown | typeof NOT_PENDING;
|
|
57
57
|
/**
|
|
58
58
|
* The transaction that owns the active override (stamped at optimistic
|
|
59
59
|
* write, cleared at settle). Ownership must live on the node: a lane's
|
|
@@ -62,21 +62,66 @@ export interface RawSignal<T> {
|
|
|
62
62
|
* revert another action's live override. Node-level sibling of the store
|
|
63
63
|
* layer's STORE_OPTIMISTIC_OWNERS stamps (#2899). `null` = ambient write.
|
|
64
64
|
*/
|
|
65
|
-
_overrideOwner
|
|
66
|
-
_optimisticLane
|
|
67
|
-
_pendingSignal
|
|
68
|
-
_latestValueComputed
|
|
69
|
-
_parentSource
|
|
65
|
+
_overrideOwner: Transition | null | undefined;
|
|
66
|
+
_optimisticLane: OptimisticLane | undefined;
|
|
67
|
+
_pendingSignal: Signal<boolean> | undefined;
|
|
68
|
+
_latestValueComputed: Computed<any> | undefined;
|
|
69
|
+
_parentSource: Signal<any> | Computed<any> | undefined;
|
|
70
70
|
/**
|
|
71
71
|
* Live `affects()` marks on this node (refcount). Non-zero is declared
|
|
72
|
-
* motion
|
|
73
|
-
* everything derived from it — reads pending regardless of graph state,
|
|
74
|
-
* until every declaring transaction settles/reverts and releases its mark.
|
|
75
|
-
* This count is the mark's ONLY graph state: the dedicated channel stores
|
|
76
|
-
* nothing downstream and never touches status flags, errors, or pending
|
|
77
|
-
* sources.
|
|
72
|
+
* motion — see affects(); the count is the mark's only graph state.
|
|
78
73
|
*/
|
|
79
|
-
_affectsCount
|
|
74
|
+
_affectsCount: number;
|
|
75
|
+
_inFlight: PromiseLike<any> | AsyncIterable<any> | null;
|
|
76
|
+
_error: unknown;
|
|
77
|
+
_blocked: boolean | undefined;
|
|
78
|
+
_pendingSources: Set<Computed<any>> | undefined;
|
|
79
|
+
_notifyStatus: ((status?: number, error?: any) => void) | undefined;
|
|
80
|
+
/** Question-scoped re-ask classification of the current pending window
|
|
81
|
+
* (see the former Computed._x?._reask doc): set by recompute from
|
|
82
|
+
* REACTIVE_REASK, cleared on landing; meaningless while not pending. */
|
|
83
|
+
_reask: boolean;
|
|
84
|
+
_child: FirewallSignal<any> | null;
|
|
85
|
+
_unobserved: (() => void) | undefined;
|
|
86
|
+
_snapshotValue: any;
|
|
87
|
+
/** Zombie staging (staged disposal): a recompute of an owner that HAS
|
|
88
|
+
* children/disposal parks them here until the flush commits (or a
|
|
89
|
+
* transition reverts). Childless nodes — the common case — never write
|
|
90
|
+
* these. */
|
|
91
|
+
_pendingDisposal: Disposable | Disposable[] | null;
|
|
92
|
+
_pendingFirstChild: Owner | null;
|
|
93
|
+
/** #3038: the firewall children that actually carry isPending()/latest()
|
|
94
|
+
* companions. The post-recompute companion snap iterates THIS set —
|
|
95
|
+
* O(companions asked for) — never the full `_child` chain (one entry per
|
|
96
|
+
* materialized leaf). Populated at companion creation; entries live as
|
|
97
|
+
* long as their companions (which are permanent once created). */
|
|
98
|
+
_companionChildren: Set<FirewallSignal<any>> | undefined;
|
|
99
|
+
}
|
|
100
|
+
export interface RawSignal<T> {
|
|
101
|
+
_subs: Link | null;
|
|
102
|
+
_subsTail: Link | null;
|
|
103
|
+
/**
|
|
104
|
+
* DEV-only live subscriber count. Maintained by `link`/`unlinkSubs` for
|
|
105
|
+
* graph-size diagnostics; undefined in production.
|
|
106
|
+
*/
|
|
107
|
+
_subCount?: number;
|
|
108
|
+
_value: T;
|
|
109
|
+
_name?: string;
|
|
110
|
+
_equals: false | ((a: T, b: T) => boolean);
|
|
111
|
+
_config: number;
|
|
112
|
+
_time: number;
|
|
113
|
+
/** IN CORE, not the extension (stage-3 §12c): consulted on EVERY write
|
|
114
|
+
* (setSignal's transition-init check) and on recompute scheduling — the
|
|
115
|
+
* per-write extension chase measurably taxed propagation chains. */
|
|
116
|
+
_transition: Transition | null;
|
|
117
|
+
/** Notify-epoch stamp of the last subscriber walk (§12d). A re-write to an
|
|
118
|
+
* already-staged node whose stamp still equals the global epoch skips the
|
|
119
|
+
* whole walk — marking is idempotent, and the epoch bumps on every
|
|
120
|
+
* recompute and new subscriber edge (either can invalidate the skip). */
|
|
121
|
+
_notifiedAt: number;
|
|
122
|
+
_pendingValue: T | typeof NOT_PENDING;
|
|
123
|
+
/** Cold extension — see NodeExtension. */
|
|
124
|
+
_x: NodeExtension | null;
|
|
80
125
|
}
|
|
81
126
|
export interface FirewallSignal<T> extends RawSignal<T> {
|
|
82
127
|
_firewall: Computed<any>;
|
|
@@ -97,35 +142,33 @@ export interface Owner {
|
|
|
97
142
|
_firstChild: Owner | null;
|
|
98
143
|
_nextSibling: Owner | null;
|
|
99
144
|
_prevSibling: Owner | null;
|
|
100
|
-
|
|
101
|
-
|
|
145
|
+
/** Cold extension — see NodeExtension (owners use the zombie-pair slots). */
|
|
146
|
+
_x: NodeExtension | null;
|
|
102
147
|
}
|
|
103
148
|
export interface Computed<T> extends RawSignal<T>, Owner {
|
|
104
149
|
_deps: Link | null;
|
|
105
150
|
_depsTail: Link | null;
|
|
151
|
+
/**
|
|
152
|
+
* DEV-only live source count. Maintained by `link`/`unlinkSubs` for
|
|
153
|
+
* graph-size diagnostics; undefined in production.
|
|
154
|
+
*/
|
|
155
|
+
_depCount?: number;
|
|
106
156
|
/** Recompute-pass counter; bumped when dep revalidation starts. */
|
|
107
157
|
_depGen: number;
|
|
108
158
|
_flags: number;
|
|
109
|
-
_blocked?: boolean;
|
|
110
|
-
_pendingSources?: Set<Computed<any>>;
|
|
111
|
-
_error?: unknown;
|
|
112
159
|
_statusFlags: number;
|
|
113
160
|
_height: number;
|
|
114
161
|
_nextHeap: Computed<any> | undefined;
|
|
115
162
|
_prevHeap: Computed<any>;
|
|
116
163
|
_fn: (prev?: T) => T;
|
|
117
|
-
_inFlight: PromiseLike<T> | AsyncIterable<T> | null;
|
|
118
|
-
_child: FirewallSignal<any> | null;
|
|
119
|
-
_notifyStatus?: (status?: number, error?: any) => void;
|
|
120
164
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* (`clearStatus`). Meaningless while not STATUS_PENDING.
|
|
165
|
+
* Clock tick at which REACTIVE_MANUAL_WRITE was last applied
|
|
166
|
+
* (`suppressComputedRecompute`). Lets `refresh()` distinguish a same-tick
|
|
167
|
+
* manual write (which wins over the refresh, #2692) from a mask carried
|
|
168
|
+
* across ticks by a transaction (which an explicit refresh lifts, #3026).
|
|
169
|
+
* Only meaningful while REACTIVE_MANUAL_WRITE is set.
|
|
127
170
|
*/
|
|
128
|
-
|
|
171
|
+
_manualWriteTime?: number;
|
|
129
172
|
/**
|
|
130
173
|
* True while a `loadingValue` node's first real answer hasn't landed: the
|
|
131
174
|
* node was born committed (commit #0 = the loading value) and `handleAsync`
|
|
@@ -137,7 +180,8 @@ export interface Computed<T> extends RawSignal<T>, Owner {
|
|
|
137
180
|
* return, sync-resolved promise, first iterator yield, async settle); a
|
|
138
181
|
* real error leaves it set — errors answer reads but don't enter the value
|
|
139
182
|
* lineage, so a retry serves the loading value again. Once cleared, normal
|
|
140
|
-
* pending/refetch semantics apply forever.
|
|
183
|
+
* pending/refetch semantics apply forever. (Stays in CORE: written
|
|
184
|
+
* unconditionally by recompute and every commit.)
|
|
141
185
|
*/
|
|
142
186
|
_loading: boolean;
|
|
143
187
|
}
|
|
@@ -414,6 +414,12 @@ export declare function createRenderEffect<T>(compute: ComputeFunction<undefined
|
|
|
414
414
|
* may run multiple times for a single change or show tearing (reading inconsistent
|
|
415
415
|
* state). Use only when dynamic subscription patterns require same-scope tracking.
|
|
416
416
|
*
|
|
417
|
+
* The callback runs during the flush itself: writes made inside it are queued
|
|
418
|
+
* into the same flush's continuation and are never visible to the callback's
|
|
419
|
+
* own reads (reads return settled values, as in every effect-phase scope), and
|
|
420
|
+
* `flush()` cannot be called from inside it (dev throws; production is a
|
|
421
|
+
* no-op) — defer with `queueMicrotask(() => flush())` if needed.
|
|
422
|
+
*
|
|
417
423
|
* ```typescript
|
|
418
424
|
* createTrackedEffect(compute, options?: { name?: string });
|
|
419
425
|
* ```
|
|
@@ -542,6 +548,19 @@ export declare function createOptimistic<T>(fn: ComputeFunction<T>, options?: Si
|
|
|
542
548
|
* Reactive reads inside the callback are *not* tracked — to react to
|
|
543
549
|
* subsequent settles, register a new `onSettled` each time.
|
|
544
550
|
*
|
|
551
|
+
* The callback runs during the settle flush itself, which gives it the same
|
|
552
|
+
* write semantics as every other effect-phase scope (the effect half of
|
|
553
|
+
* `createEffect`, event handlers):
|
|
554
|
+
*
|
|
555
|
+
* - **Writes** are queued into the same flush's continuation — dependent memos
|
|
556
|
+
* and effects update before the flush returns — but reads inside the
|
|
557
|
+
* callback keep returning the settled (pre-write) values. A callback never
|
|
558
|
+
* observes its own unsettled write. Functional setters still compose:
|
|
559
|
+
* `set(v => v + 1)` twice increments twice.
|
|
560
|
+
* - **`flush()` cannot be called** from inside the callback — the flush is
|
|
561
|
+
* already running (dev throws; production is a no-op). To force a drain
|
|
562
|
+
* after this settle, defer it: `queueMicrotask(() => flush())`.
|
|
563
|
+
*
|
|
545
564
|
* `onCleanup` is **not** allowed inside the callback — return a cleanup
|
|
546
565
|
* function instead. The returned cleanup runs on owner disposal.
|
|
547
566
|
*
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
export type { Store, StoreReturn, ProjectionStoreReturn, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.cjs";
|
|
2
2
|
export type { Merge, Omit } from "./utils.cjs";
|
|
3
|
-
export { isWrappable,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
3
|
+
export { isWrappable, $TRACK, $PROXY, $TARGET } from "./store.cjs";
|
|
4
|
+
import type { NoFn, ProjectionOptions, Store, StoreOptions, StoreSetter } from "./store.cjs";
|
|
5
|
+
import type { Refreshable } from "../core/index.cjs";
|
|
6
|
+
export { createProjectionNext as createProjection } from "./next/projection.cjs";
|
|
7
|
+
export { createOptimisticStoreNext as createOptimisticStore } from "./next/optimistic.cjs";
|
|
8
|
+
/** Public createStore: plain form `(init, options?)` and derived writable
|
|
9
|
+
* form `(fn, seed, options?)`. */
|
|
10
|
+
export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
|
|
11
|
+
shallow?: boolean;
|
|
12
|
+
}): [get: Store<T>, set: StoreSetter<T>];
|
|
13
|
+
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: Refreshable<Store<T>>, set: StoreSetter<T>];
|
|
14
|
+
export declare function reconcile<T extends U, U>(value: T, key?: string | ((item: NonNullable<any>) => any) | null): (state: U) => T;
|
|
15
|
+
export declare function snapshot<T>(value: T): T;
|
|
16
|
+
export declare function deep<T>(value: T): T;
|
|
7
17
|
export { storePath } from "./storePath.cjs";
|
|
8
18
|
export type { PathSetter, Part, StorePathRange, ArrayFilterFn, CustomPartial } from "./storePath.cjs";
|
|
9
|
-
export {
|
|
19
|
+
export { merge, omit } from "./utils.cjs";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from "../store.cjs";
|
|
2
|
+
import type { StoreNextFamily, StoreNextTarget } from "./target.cjs";
|
|
3
|
+
export declare function createOptimisticStoreNext<T extends object = {}>(first: T | ((store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>), second?: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T>, set: StoreSetter<T>];
|
|
4
|
+
/** Diff the draft against the current OPTIMISTIC VIEW (committed + active
|
|
5
|
+
* overrides — the same view the draft was seeded from) and emit engine writes
|
|
6
|
+
* for exactly the changed keys. Visible-view diffing keeps no-op writes from
|
|
7
|
+
* entangling lanes (RUL-10 / opt R38). */
|
|
8
|
+
export declare function notifyOptimisticWrites(t: StoreNextTarget, pb: Record<PropertyKey, any>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Landing consumption (RUL-2): fresh authoritative data supersedes every
|
|
11
|
+
* tentative override in the family. Mirrors legacy clearProjectionOverride —
|
|
12
|
+
* drop the override, clear lane/ownership, notify subscribers whose visible
|
|
13
|
+
* value changes (reversion effects go to regular queues via the projection
|
|
14
|
+
* write posture the caller holds).
|
|
15
|
+
*/
|
|
16
|
+
export declare function consumeOverridesNext(fam: StoreNextFamily): void;
|
|
17
|
+
/** Optimistic-view composition for snapshot/deep (O1: snapshot is the CURRENT
|
|
18
|
+
* view, lane values included; a fresh copy per call during pending windows —
|
|
19
|
+
* RUL-12). Returns `src` untouched when no override is active on `t`. */
|
|
20
|
+
export declare function optimisticView(t: StoreNextTarget, src: Record<PropertyKey, any>): Record<PropertyKey, any>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Computed, type Refreshable } from "../../core/index.cjs";
|
|
2
|
+
import { type NoFn, type ProjectionOptions, type Store } from "../store.cjs";
|
|
3
|
+
export declare function createProjectionNext<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): Refreshable<Store<T>>;
|
|
4
|
+
/** Derived writable store (legacy parity): a projection whose public setter
|
|
5
|
+
* masks the recompute for the tick (core R31 — the manual write wins over a
|
|
6
|
+
* same-flush dependency change). */
|
|
7
|
+
export declare function createStoreDerivedNext<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [Refreshable<Store<T>>, (f: (draft: T) => T | void) => void];
|
|
8
|
+
export declare function runProjectionComputedNext<T extends object>(wrappedStore: Store<T>, fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, key: string | ((item: NonNullable<any>) => any) | null, wrapCommit?: (write: () => void) => void, onDraftWrite?: () => void): Computed<void | T>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Signal } from "../../core/types.cjs";
|
|
2
|
+
import { type StoreNextFamily, type StoreNextTarget } from "./target.cjs";
|
|
3
|
+
export declare function wrapNext<T extends Record<PropertyKey, any>>(value: T, parent?: StoreNextTarget | null, parentKey?: PropertyKey | null, fam?: StoreNextFamily | null): T;
|
|
4
|
+
/** Unwrap our own proxies to their current backing; leave everything else. */
|
|
5
|
+
export declare function unwrapValue(v: any): any;
|
|
6
|
+
export declare function getNode(target: StoreNextTarget, key: PropertyKey, current: any): Signal<any>;
|
|
7
|
+
export declare function getHasNode(target: StoreNextTarget, key: PropertyKey, present: boolean): Signal<boolean>;
|
|
8
|
+
export declare function getKeySetNode(target: StoreNextTarget): Signal<number>;
|
|
9
|
+
/** Deep-witness bump: any value/shape change on a record with a live deep()
|
|
10
|
+
* subscriber notifies it. One null check when unused. */
|
|
11
|
+
export declare function bumpDeep(t: StoreNextTarget): void;
|
|
12
|
+
/** Downgrade a prototype-overlay pending backing to the clone path: builds
|
|
13
|
+
* the real container (committed + overlay writes − deletes) that fold will
|
|
14
|
+
* SWAP in as the committed backing, exactly as if the draft had started on
|
|
15
|
+
* the clone path. Consumers that need a complete container (reconcile's
|
|
16
|
+
* diff walks, drafts escaping into other storage) call this. */
|
|
17
|
+
export declare function materializePB(target: StoreNextTarget): void;
|
|
18
|
+
/**
|
|
19
|
+
* Adoption (2026-08-16c): the incoming object becomes the committed backing
|
|
20
|
+
* IMMEDIATELY — reconcile is eagerly visible to every reader (shipped
|
|
21
|
+
* contract; only its notifications batch), unlike setter writes which stay
|
|
22
|
+
* pending until flush. Ownership resets (incoming is unowned/user data). Any
|
|
23
|
+
* staged draft clone folds into the diff and is discarded — next is the
|
|
24
|
+
* authoritative base (R21/R32).
|
|
25
|
+
*/
|
|
26
|
+
export declare function adoptPB(target: StoreNextTarget, incoming: Record<PropertyKey, any>, eager?: boolean): void;
|
|
27
|
+
/** Same logical slot: both values resolve to one (re-pointed) child target —
|
|
28
|
+
* adoption preserved identity, so the slot did not change (R9). */
|
|
29
|
+
export declare function targetsEqual(ov: any, nv: any): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The fold diff walks SUBSCRIPTION KEYS ONLY (legacy parity: `for key in
|
|
32
|
+
* nodes`): nodes exist exactly where something tracked, so unobserved data
|
|
33
|
+
* costs nothing here regardless of object size. Accessor safety rides the
|
|
34
|
+
* sticky `t.a` flag — a node's key was necessarily read, so the get trap has
|
|
35
|
+
* already seen whether it is an accessor.
|
|
36
|
+
*/
|
|
37
|
+
/** One node's fold notification (shared by notifyFold's walk and the fused
|
|
38
|
+
* adoption walk): accessor-aware compare + equality/identity-gated setSignal. */
|
|
39
|
+
export declare function notifyKeyDiff(node: Signal<any>, key: PropertyKey, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>, probe?: boolean): void;
|
|
40
|
+
/** Accessor-flag probe for the fused walk's early-continue (accessor keys
|
|
41
|
+
* can never identity-skip: their VALUE is the descriptor's product). */
|
|
42
|
+
export declare function hasAccessorFlag(node: Signal<any>): boolean;
|
|
43
|
+
/** Fused-walk per-key notification with values already in hand: the caller
|
|
44
|
+
* fetched both sides and handled the identity skip; this applies the
|
|
45
|
+
* accessor branch (cached flag only — reconcile channel) or the plain
|
|
46
|
+
* equality/identity-gated write. */
|
|
47
|
+
export declare function notifyKeyValue(node: Signal<any>, key: PropertyKey, ov: any, nv: any, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
|
|
48
|
+
/** Presence + membership halves of a fold notification (shared tail). */
|
|
49
|
+
export declare function notifyFoldTail(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
|
|
50
|
+
export declare function notifyFold(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
|
|
51
|
+
/** Authoritative-write wrapper exported for the optimistic module: sets the
|
|
52
|
+
* scheduler's projectionWriteActive through THIS module's binding (proven to
|
|
53
|
+
* share the instance core reads — cross-module live-binding writes from other
|
|
54
|
+
* store modules were observed not to propagate under the test transform). */
|
|
55
|
+
export declare function runAuthoritative<T>(fn: () => T): T;
|
|
56
|
+
/** Active optimistic override on an armed node (armed slot idles at
|
|
57
|
+
* NOT_PENDING; undefined = unarmed plain node). */
|
|
58
|
+
export declare function hasActiveOverride(node: Signal<any>): boolean;
|
|
59
|
+
export type SetStoreNextFunction<T> = (fn: (draft: T) => T | void) => void;
|
|
60
|
+
/** Low-level setter primitive: opens write mode on a next proxy, runs `fn`,
|
|
61
|
+
* emits write-time notifications at outermost exit, applies returned
|
|
62
|
+
* replacements as adoptions. `guard=false` skips the owned-scope dev guard —
|
|
63
|
+
* projection recomputes legitimately write from inside their computed. */
|
|
64
|
+
export declare function storeSetterNext<T>(proxy: T, fn: (draft: T) => T | void, guard?: boolean): void;
|
|
65
|
+
export declare function createStoreNext<T extends Record<PropertyKey, any>>(init: T, shallow?: boolean): [T, SetStoreNextFunction<T>];
|
|
66
|
+
/** Tracking deep snapshot (`deep()` for next targets): subscribes to the
|
|
67
|
+
* key-set and every property node at every reachable level, then returns the
|
|
68
|
+
* plain view. Shared references and cycles handled via the visited set. */
|
|
69
|
+
export declare function deepNext<T>(value: T): T;
|
|
70
|
+
/**
|
|
71
|
+
* Snapshot with per-object registration resolution (RUL-12 DAG ruling): every
|
|
72
|
+
* reachable wrappable resolves through its target's CURRENT backing, so
|
|
73
|
+
* privatized subtrees are seen through any parent path. Identity-preserving:
|
|
74
|
+
* a subtree with no substitutions below returns its own object (zero copy for
|
|
75
|
+
* settled, never-diverged graphs).
|
|
76
|
+
*/
|
|
77
|
+
export declare function snapshotNext<T>(value: T): T;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store rewrite — target & ownership (INTERNALS-STORE-STATE.md §1, §5b).
|
|
3
|
+
*
|
|
4
|
+
* The proxy wraps this internal target, never the raw (proxy-target
|
|
5
|
+
* indirection, decision 2026-08-16d). `b` is the single committed home; `pb`
|
|
6
|
+
* is the per-target pending backing (RUL-1's pending home): the CoW clone
|
|
7
|
+
* created at first draft write, mutated natively by the draft, folded into
|
|
8
|
+
* `b` at flush commit. Adoption (setter replacement / reconcile) parks an
|
|
9
|
+
* UNOWNED incoming object in `pb` — fold swaps it in and ownership resets.
|
|
10
|
+
*
|
|
11
|
+
* Creation budget (§5b): one minimal target + one proxy + one storeLookup
|
|
12
|
+
* entry per read-through object; zero layer slots; nodes, has-nodes, and the
|
|
13
|
+
* key-set node are lazy, materialized only by subscription.
|
|
14
|
+
*/
|
|
15
|
+
import type { Computed, Signal } from "../../core/types.cjs";
|
|
16
|
+
/** Projection family (§7b): children wrap into the family's own map (writes
|
|
17
|
+
* land in the projection, never the source family), and every node created
|
|
18
|
+
* under the family carries the projection computed as its firewall. */
|
|
19
|
+
export interface StoreNextFamily {
|
|
20
|
+
/** Optimistic family: nodes are born armed (`_overrideValue` slot) so every
|
|
21
|
+
* write rides the core optimistic engine — lanes, per-transaction ownership,
|
|
22
|
+
* reverts all core-native (§3, RUL-3). */
|
|
23
|
+
opt?: boolean;
|
|
24
|
+
/** Root proxy (registered with the scheduler's optimistic-store set for the
|
|
25
|
+
* transitionBlocked store-half, #2951). */
|
|
26
|
+
px?: any;
|
|
27
|
+
/** Targets currently carrying active node overrides (landing-consumption
|
|
28
|
+
* walk, RUL-2: visible landed truth replaces optimism). */
|
|
29
|
+
overlaid?: Set<any>;
|
|
30
|
+
map: WeakMap<object, StoreNextTarget>;
|
|
31
|
+
/** The projection computed — assigned after creation (accessor pattern). */
|
|
32
|
+
node: Computed<any> | null;
|
|
33
|
+
shallow?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface StoreNextTarget {
|
|
36
|
+
/** Committed backing: source object (shared) or owned clone. */
|
|
37
|
+
v: Record<PropertyKey, any>;
|
|
38
|
+
/** Pending backing for the current flush (null when settled). */
|
|
39
|
+
pb: Record<PropertyKey, any> | null;
|
|
40
|
+
/** cached: committed backing is another store's proxy (§7b chained). */
|
|
41
|
+
ch: boolean;
|
|
42
|
+
/** live value-node count (deleted-key sweep fast-out in the fused walk). */
|
|
43
|
+
nc: number;
|
|
44
|
+
/** Lazy per-property subscription nodes (real core signals). */
|
|
45
|
+
n: Record<PropertyKey, Signal<any>> | null;
|
|
46
|
+
/** Lazy per-key presence nodes (`in` tracks presence, not value — R13). */
|
|
47
|
+
h: Record<PropertyKey, Signal<boolean>> | null;
|
|
48
|
+
/** Lazy key-set node: membership/iteration/$TRACK subscriptions (§6). */
|
|
49
|
+
k: Signal<number> | null;
|
|
50
|
+
/** Lazy deep-witness node: `deep()` subscribes ONE node per record instead
|
|
51
|
+
* of one per path; write paths bump it only when it exists. Separate from
|
|
52
|
+
* `k` so $TRACK/mapArray never rerun on leaf value changes (R9). */
|
|
53
|
+
dk: Signal<number> | null;
|
|
54
|
+
/** Parent target (path copying walks this at commit). */
|
|
55
|
+
u: StoreNextTarget | null;
|
|
56
|
+
/** Property key of this target in the parent's backing. */
|
|
57
|
+
pk: PropertyKey | null;
|
|
58
|
+
/** The proxy for this target (stable outward identity). */
|
|
59
|
+
px: any;
|
|
60
|
+
/** Sticky descendants flag (§6d). */
|
|
61
|
+
d: boolean;
|
|
62
|
+
/** Sticky accessors-seen flag: an own accessor property was observed on
|
|
63
|
+
* this target (first-read scan, defineProperty, or clone scan). Gates the
|
|
64
|
+
* fold diff's descriptor-safe path and the get trap's descriptor path. */
|
|
65
|
+
a: boolean;
|
|
66
|
+
/** Accessor scan performed (scan-once on first trap read; adopted data is
|
|
67
|
+
* not rescanned — legacy-parity behavior). */
|
|
68
|
+
sc: boolean;
|
|
69
|
+
/** Backing was swapped by adoption this batch (fold diff-notifies it). */
|
|
70
|
+
adopted: boolean;
|
|
71
|
+
/** Pending backing is a prototype-chain OVERLAY of the committed backing
|
|
72
|
+
* (`Object.create(v)` — own keys are this batch's writes, everything else
|
|
73
|
+
* reads through). O(written) per flush instead of O(container) clones
|
|
74
|
+
* (#3044); commit flattens own keys onto an owned committed backing in
|
|
75
|
+
* place. Only plain-data non-array non-family containers qualify;
|
|
76
|
+
* `materializePB` downgrades to the clone path when a consumer needs a
|
|
77
|
+
* real container (reconcile, draft escape). */
|
|
78
|
+
ovl: boolean;
|
|
79
|
+
/** Keys deleted in the overlay window (a prototype overlay cannot shadow
|
|
80
|
+
* a delete); null when none. */
|
|
81
|
+
del: Set<PropertyKey> | null;
|
|
82
|
+
/** Keys written through the traps since the last fold commit. Bounds the
|
|
83
|
+
* setter notify/hold-check to O(written) instead of O(subscribed nodes) —
|
|
84
|
+
* a record with thousands of per-key subscriptions (selection maps) would
|
|
85
|
+
* otherwise pay a full node scan on every write. null = no trap writes
|
|
86
|
+
* this batch (bulk paths fall back to the full scan); WK_ALL sentinel =
|
|
87
|
+
* bound unusable this batch (array length write implies index deletes). */
|
|
88
|
+
wk: Set<PropertyKey> | null;
|
|
89
|
+
/** Projection family, null for plain stores (§7b). */
|
|
90
|
+
fam: StoreNextFamily | null;
|
|
91
|
+
/** Shallow store root (values served raw). */
|
|
92
|
+
s: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Ownership (first cut, decision 2026-08-16d): one WeakSet of store-owned
|
|
96
|
+
* backings serving both the production identity-skip guard and the __TEST__
|
|
97
|
+
* no-mutation oracle.
|
|
98
|
+
*/
|
|
99
|
+
export declare const ownedRaw: WeakSet<object>;
|
|
100
|
+
/** raw → target. The only raw-keyed lookup; boundary mechanism (O8). */
|
|
101
|
+
export declare const storeNextLookup: WeakMap<object, StoreNextTarget>;
|
|
102
|
+
/** __TEST__ oracle: every object ingested from a user (never mutate). */
|
|
103
|
+
export declare const ingestedRaw: WeakSet<object> | null;
|
|
104
|
+
export declare function devAssertNeverUserMutation(target: object): void;
|
|
105
|
+
/** Injection table for optimistic-only store machinery (next/optimistic.ts).
|
|
106
|
+
* Every call site is gated on `fam?.opt`, and optimistic families can only
|
|
107
|
+
* be created by createOptimisticStore — whose install populates this — so
|
|
108
|
+
* the non-null assertions at the sites hold by construction. Keeping the
|
|
109
|
+
* implementations out of next/store.ts lets plain-store bundles tree-shake
|
|
110
|
+
* the optimistic channel entirely. */
|
|
111
|
+
export interface OptStoreHooks {
|
|
112
|
+
notifyOptimisticWrites(t: any, pb: Record<PropertyKey, any>): void;
|
|
113
|
+
optimisticView(t: any, src: Record<PropertyKey, any>): Record<PropertyKey, any>;
|
|
114
|
+
applyTentative(t: any, incoming: any, keyFn: ((item: any) => any) | null): void;
|
|
115
|
+
}
|
|
116
|
+
export declare let optHooks: OptStoreHooks | null;
|
|
117
|
+
export declare function setOptHooks(h: OptStoreHooks): void;
|