@solidjs/signals 2.0.0-rc.0 → 2.0.0-rc.10

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 (149) hide show
  1. package/README.md +1 -1
  2. package/dist/dev-shared.js +7138 -0
  3. package/dist/dev.attribution.js +3307 -0
  4. package/dist/dev.js +8076 -6692
  5. package/dist/observe/affects.js +129 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +793 -0
  8. package/dist/observe/core/action.js +177 -0
  9. package/dist/observe/core/async.js +849 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +2904 -0
  15. package/dist/observe/core/constants.js +283 -0
  16. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  17. package/dist/observe/core/core.js +1999 -0
  18. package/dist/observe/core/dev.js +343 -0
  19. package/dist/observe/core/effect.js +200 -0
  20. package/dist/observe/core/error-hooks.js +71 -0
  21. package/dist/observe/core/error.js +80 -0
  22. package/dist/observe/core/external.js +98 -0
  23. package/dist/observe/core/graph.js +155 -0
  24. package/dist/observe/core/heap.js +147 -0
  25. package/dist/observe/core/invariants.js +45 -0
  26. package/dist/observe/core/lanes.js +205 -0
  27. package/dist/observe/core/optimistic.js +627 -0
  28. package/dist/observe/core/owner.js +353 -0
  29. package/dist/observe/core/scheduler.js +1547 -0
  30. package/dist/observe/core/verdict.js +674 -0
  31. package/dist/observe/index.js +59 -0
  32. package/dist/observe/map.js +484 -0
  33. package/dist/observe/signals.js +731 -0
  34. package/dist/observe/store/index.js +44 -0
  35. package/dist/observe/store/next/optimistic.js +717 -0
  36. package/dist/observe/store/next/projection.js +266 -0
  37. package/dist/observe/store/next/reconcile.js +375 -0
  38. package/dist/observe/store/next/store.js +2480 -0
  39. package/dist/observe/store/next/target.js +51 -0
  40. package/dist/observe/store/store.js +331 -0
  41. package/dist/observe/store/storePath.js +103 -0
  42. package/dist/observe/store/utils.js +1070 -0
  43. package/dist/prod/affects.js +10 -9
  44. package/dist/prod/attribution.js +45 -0
  45. package/dist/prod/boundaries.js +388 -178
  46. package/dist/prod/core/action.js +65 -37
  47. package/dist/prod/core/async.js +477 -208
  48. package/dist/prod/core/attribution-hooks.js +3 -0
  49. package/dist/prod/core/constants.js +186 -1
  50. package/dist/prod/core/context.js +10 -16
  51. package/dist/prod/core/core.js +1556 -415
  52. package/dist/prod/core/dev.js +18 -1
  53. package/dist/prod/core/effect.js +119 -79
  54. package/dist/prod/core/error-hooks.js +71 -0
  55. package/dist/prod/core/error.js +13 -1
  56. package/dist/prod/core/external.js +4 -4
  57. package/dist/prod/core/graph.js +105 -54
  58. package/dist/prod/core/heap.js +72 -65
  59. package/dist/prod/core/invariants.js +3 -2
  60. package/dist/prod/core/lanes.js +117 -52
  61. package/dist/prod/core/optimistic.js +474 -103
  62. package/dist/prod/core/owner.js +131 -84
  63. package/dist/prod/core/scheduler.js +1013 -248
  64. package/dist/prod/core/verdict.js +418 -113
  65. package/dist/prod/index.js +25 -13
  66. package/dist/prod/map.js +314 -151
  67. package/dist/prod/signals.js +382 -32
  68. package/dist/prod/store/index.js +38 -0
  69. package/dist/prod/store/next/optimistic.js +710 -0
  70. package/dist/prod/store/next/projection.js +257 -0
  71. package/dist/prod/store/next/reconcile.js +373 -0
  72. package/dist/prod/store/next/store.js +2356 -0
  73. package/dist/prod/store/next/target.js +51 -0
  74. package/dist/prod/store/store.js +129 -881
  75. package/dist/prod/store/utils.js +982 -242
  76. package/dist/types/attribution.d.ts +19 -0
  77. package/dist/types/attribution.prod.d.ts +22 -0
  78. package/dist/types/boundaries.d.ts +78 -5
  79. package/dist/types/core/action.d.ts +12 -5
  80. package/dist/types/core/async.d.ts +3 -1
  81. package/dist/types/core/attribution-costs.d.ts +35 -0
  82. package/dist/types/core/attribution-feedback.d.ts +133 -0
  83. package/dist/types/core/attribution-hooks.d.ts +304 -0
  84. package/dist/types/core/attribution-queries.d.ts +24 -0
  85. package/dist/types/core/attribution.d.ts +892 -0
  86. package/dist/types/core/constants.d.ts +179 -0
  87. package/dist/types/core/core.d.ts +305 -23
  88. package/dist/types/core/dev.d.ts +421 -8
  89. package/dist/types/core/effect.d.ts +8 -1
  90. package/dist/types/core/error-hooks.d.ts +71 -0
  91. package/dist/types/core/error.d.ts +9 -0
  92. package/dist/types/core/graph.d.ts +23 -0
  93. package/dist/types/core/heap.d.ts +5 -3
  94. package/dist/types/core/index.d.ts +6 -3
  95. package/dist/types/core/invariants.d.ts +5 -1
  96. package/dist/types/core/lanes.d.ts +51 -19
  97. package/dist/types/core/owner.d.ts +15 -3
  98. package/dist/types/core/scheduler.d.ts +252 -3
  99. package/dist/types/core/types.d.ts +124 -41
  100. package/dist/types/index.d.ts +18 -5
  101. package/dist/types/map.d.ts +2 -0
  102. package/dist/types/signals.d.ts +164 -13
  103. package/dist/types/store/index.d.ts +16 -5
  104. package/dist/types/store/next/optimistic.d.ts +25 -0
  105. package/dist/types/store/next/projection.d.ts +27 -0
  106. package/dist/types/store/next/reconcile.d.ts +10 -0
  107. package/dist/types/store/next/store.d.ts +143 -0
  108. package/dist/types/store/next/target.d.ts +196 -0
  109. package/dist/types/store/store.d.ts +46 -112
  110. package/dist/types/store/utils.d.ts +188 -40
  111. package/package.json +32 -26
  112. package/dist/node.cjs +0 -7938
  113. package/dist/prod/store/optimistic.js +0 -217
  114. package/dist/prod/store/projection.js +0 -231
  115. package/dist/prod/store/reconcile.js +0 -707
  116. package/dist/types/store/optimistic.d.ts +0 -45
  117. package/dist/types/store/projection.d.ts +0 -70
  118. package/dist/types/store/reconcile.d.ts +0 -46
  119. package/dist/types-cjs/affects.d.cts +0 -47
  120. package/dist/types-cjs/boundaries.d.cts +0 -175
  121. package/dist/types-cjs/core/action.d.cts +0 -64
  122. package/dist/types-cjs/core/async.d.cts +0 -21
  123. package/dist/types-cjs/core/constants.d.cts +0 -71
  124. package/dist/types-cjs/core/core.d.cts +0 -148
  125. package/dist/types-cjs/core/dev.d.cts +0 -64
  126. package/dist/types-cjs/core/effect.d.cts +0 -30
  127. package/dist/types-cjs/core/error.d.cts +0 -47
  128. package/dist/types-cjs/core/external.d.cts +0 -15
  129. package/dist/types-cjs/core/graph.d.cts +0 -5
  130. package/dist/types-cjs/core/heap.d.cts +0 -22
  131. package/dist/types-cjs/core/index.d.cts +0 -13
  132. package/dist/types-cjs/core/invariants.d.cts +0 -59
  133. package/dist/types-cjs/core/lanes.d.cts +0 -56
  134. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  135. package/dist/types-cjs/core/owner.d.cts +0 -124
  136. package/dist/types-cjs/core/scheduler.d.cts +0 -170
  137. package/dist/types-cjs/core/types.d.cts +0 -148
  138. package/dist/types-cjs/core/verdict.d.cts +0 -2
  139. package/dist/types-cjs/index.d.cts +0 -10
  140. package/dist/types-cjs/map.d.cts +0 -69
  141. package/dist/types-cjs/package.json +0 -3
  142. package/dist/types-cjs/signals.d.cts +0 -605
  143. package/dist/types-cjs/store/index.d.cts +0 -9
  144. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  145. package/dist/types-cjs/store/projection.d.cts +0 -70
  146. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  147. package/dist/types-cjs/store/store.d.cts +0 -213
  148. package/dist/types-cjs/store/storePath.d.cts +0 -58
  149. package/dist/types-cjs/store/utils.d.cts +0 -114
@@ -0,0 +1,143 @@
1
+ import { hasActiveOverride, visibleOverride } from "../../core/core.js";
2
+ import type { Computed, Signal } from "../../core/types.js";
3
+ import { type StoreNextFamily, type StoreNextTarget } from "./target.js";
4
+ export declare function wrapNext<T extends Record<PropertyKey, any>>(value: T, parent?: StoreNextTarget | null, parentKey?: PropertyKey | null, fam?: StoreNextFamily | null): T;
5
+ /** Unwrap our own proxies to their current backing; leave everything else. */
6
+ export declare function unwrapValue(v: any): any;
7
+ export declare function getNode(target: StoreNextTarget, key: PropertyKey, current: any, accKnown?: -1 | 0 | 1): Signal<any>;
8
+ /** Record a store proxy's declared name for attribution labels (observe tiers). */
9
+ export declare function nameStore(proxy: any, name: string | undefined): void;
10
+ export declare function getHasNode(target: StoreNextTarget, key: PropertyKey, present: boolean): Signal<boolean>;
11
+ export declare function getKeySetNode(target: StoreNextTarget): Signal<number>;
12
+ /** Deep-witness bump: any value/shape change on a record with a live deep()
13
+ * subscriber notifies it. One null check when unused. */
14
+ export declare function bumpDeep(t: StoreNextTarget): void;
15
+ /** Downgrade a prototype-overlay pending backing to the clone path: builds
16
+ * the real container (committed + overlay writes − deletes) that fold will
17
+ * SWAP in as the committed backing, exactly as if the draft had started on
18
+ * the clone path. Consumers that need a complete container (reconcile's
19
+ * diff walks, drafts escaping into other storage) call this. */
20
+ export declare function materializePB(target: StoreNextTarget): void;
21
+ /** Resolve the held committed view (#3074): answers the masked old backing
22
+ * while the hold is live, and lazily clears a hold whose transition has
23
+ * committed (transitions merge — resolve through currentTransition, same as
24
+ * foldHeld's node stamps). */
25
+ export declare function heldMaskView(t: StoreNextTarget): Record<PropertyKey, any> | null;
26
+ /**
27
+ * Adoption (2026-08-16c): the incoming object becomes the committed backing
28
+ * IMMEDIATELY — reconcile is eagerly visible to every reader (shipped
29
+ * contract; only its notifications batch), unlike setter writes which stay
30
+ * pending until flush. Ownership resets (incoming is unowned/user data). Any
31
+ * staged draft clone folds into the diff and is discarded — next is the
32
+ * authoritative base (R21/R32).
33
+ */
34
+ export declare function adoptPB(target: StoreNextTarget, incoming: Record<PropertyKey, any>, eager?: boolean): void;
35
+ /** Parked truth-staged pending backings (#3164 fold): a tentative draft that
36
+ * opens while a folded landing's backing is live moves the staged container
37
+ * here (see ensurePB); the tentative discard in notifyOptimisticWrites
38
+ * restores it in place of the usual null. */
39
+ export declare const stagedTruthPB: WeakMap<StoreNextTarget, Record<PropertyKey, any>>;
40
+ /** Same logical slot: both values resolve to one (re-pointed) child target —
41
+ * adoption preserved identity, so the slot did not change (R9). */
42
+ export declare function targetsEqual(ov: any, nv: any): boolean;
43
+ export declare function arrayStructureChanged(old: any[], neu: any[]): boolean;
44
+ export declare function membershipChanged(old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): boolean;
45
+ /**
46
+ * The fold diff walks SUBSCRIPTION KEYS ONLY (legacy parity: `for key in
47
+ * nodes`): nodes exist exactly where something tracked, so unobserved data
48
+ * costs nothing here regardless of object size. Accessor safety rides the
49
+ * sticky `t.a` flag — a node's key was necessarily read, so the get trap has
50
+ * already seen whether it is an accessor.
51
+ */
52
+ /** One node's fold notification (shared by notifyFold's walk and the fused
53
+ * adoption walk): accessor-aware compare + equality/identity-gated setSignal. */
54
+ export declare function notifyKeyDiff(node: Signal<any>, key: PropertyKey, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>, probe?: boolean): void;
55
+ /** Accessor-flag probe for the fused walk's early-continue (accessor keys
56
+ * can never identity-skip: their VALUE is the descriptor's product). */
57
+ export declare function hasAccessorFlag(node: Signal<any>): boolean;
58
+ /** Fused-walk per-key notification with values already in hand: the caller
59
+ * fetched both sides and handled the identity skip; this applies the
60
+ * accessor branch (cached flag only — reconcile channel) or the plain
61
+ * equality/identity-gated write. */
62
+ export declare function notifyKeyValue(node: Signal<any>, key: PropertyKey, ov: any, nv: any, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
63
+ /** Presence + membership halves of a fold notification (shared tail). */
64
+ export declare function notifyFoldTail(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
65
+ export declare function notifyFold(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
66
+ /** Authoritative-write wrapper exported for the optimistic module: sets the
67
+ * scheduler's projectionWriteActive through THIS module's binding (proven to
68
+ * share the instance core reads — cross-module live-binding writes from other
69
+ * store modules were observed not to propagate under the test transform). */
70
+ export declare function runAuthoritative<T>(fn: () => T): T;
71
+ export { hasActiveOverride, visibleOverride };
72
+ /** The reading computation is until()'s authoritative-view predicate — same
73
+ * source of truth as core read()'s A17 carve-out (`context`, which persists
74
+ * under untrack). optimisticView()'s composition gate consults exactly this:
75
+ * write-side machinery (patch emission, tentative re-application) must keep
76
+ * composing even when it runs inside an authoritative-write bracket. */
77
+ export declare function authoritativeRead(): boolean;
78
+ /** Serve-side authoritative gate: until()'s predicate PLUS truth authors —
79
+ * the projection derive's draft (wrapDraft trap brackets, runAuthoritative;
80
+ * the same posture pair ensurePB classifies drafts by). A source computing
81
+ * the next truth must never read its callers' tentative overlays: a derive
82
+ * continuation's `store.push` computing its index from an action's
83
+ * optimistic row landed truth in the wrong slot and corrupted committed
84
+ * state (#3108). Trap-level overlay serves gate on this so values, length,
85
+ * membership, and keys leave the authoritative view together. */
86
+ export declare function authoritativeServe(): boolean;
87
+ /** The override a composed READER view (keys, descriptors, snapshot/deep,
88
+ * optimisticView) takes from an armed node whose override is active — the
89
+ * override itself, unless the node's own source superseded it (#3331,
90
+ * CONFIG_OVERRIDE_SUPERSEDED): then the reader-aware selection `serve`
91
+ * makes through nodeValue, so the composed view agrees with what `get`,
92
+ * `in` and `length` serve the same reader (a deriving pass: the staged
93
+ * truth; a lane pass or a context-free read: the override, A18). Composing
94
+ * the raw override left Object.keys / snapshot() / deep() one row behind the
95
+ * traps at a landing whose shape differed from the optimistic frame (F5
96
+ * parity cases). Draft and authoritative callers never reach here — the
97
+ * writer composes on hasActiveOverride, truth authors on the backing. */
98
+ export declare function readerOverride(node: Signal<any>, committed: any): any;
99
+ export type SetStoreNextFunction<T> = (fn: (draft: T) => T | void) => void;
100
+ /** The derived store's setter (CS-R31): within a synchronous frame the manual
101
+ * write wins — the projection's recompute is masked for the tick. Across a
102
+ * hold the write is not a proposal: a leaf the fold staged under another
103
+ * transaction re-runs the fold under it, the write being the draft's prior
104
+ * state (#3612). Decided from the leaf notifications, so the mask lands
105
+ * after them (in the `finally`: a throwing setter's writes before the throw
106
+ * were notified, and are masked as before). */
107
+ export declare function derivedStoreWrite<T>(node: Computed<unknown>, proxy: T, fn: (draft: T) => T | void): void;
108
+ export declare function storeSetterNext<T>(proxy: T, fn: (draft: T) => T | void, guard?: boolean): void;
109
+ export declare function createStoreNext<T extends Record<PropertyKey, any>>(initialValue: T, shallow?: boolean): [T, SetStoreNextFunction<T>];
110
+ /** True when `proxy` is a SHALLOW store (children served verbatim, slots
111
+ * replaced by reference — #2932). The list driver uses this to choose the
112
+ * slot-patch channel (collected row bodies) over per-record registration. */
113
+ export declare function storeIsShallow(proxy: any): boolean;
114
+ /** True when `proxy` belongs to a projection/optimistic FAMILY. The list
115
+ * driver must DECLINE family arrays (external audit finding): family
116
+ * structural changes never emit row/slot ops (the setter channel is
117
+ * fam-gated; optimistic writes ride node overrides), and the proxy identity
118
+ * is stable so the each-watch cannot catch the change either — an engaged
119
+ * list would freeze on optimistic/projection structural updates. Record-
120
+ * level family patches are unaffected (they have their own emission). */
121
+ export declare function storeHasFamily(proxy: any): boolean;
122
+ /** True when `proxy` belongs to an OPTIMISTIC family specifically. The list
123
+ * driver declines these (audit finding, narrowed): optimistic user writes
124
+ * ride node-level overrides — they never enter the reconcile walk, so no
125
+ * row/slot ops are emitted and an engaged list would freeze on optimistic
126
+ * structural changes. PROJECTION (non-optimistic) families are drivable:
127
+ * their recomputes go through the reconcile walk, whose emissions are
128
+ * transition-stamped in the apply queue like any other (equivalence-matrix
129
+ * gated). Re-admitting optimistic families requires a lane-timed structural
130
+ * emission mirroring emitPatchOptimistic, plus revert resync. */
131
+ export declare function storeHasOptimisticFamily(proxy: any): boolean;
132
+ /** Tracking deep snapshot (`deep()` for next targets): subscribes to the
133
+ * key-set and deep-witness node at every reachable level, then returns the
134
+ * plain view. Shared references and cycles handled via the visited set. */
135
+ export declare function deepNext<T>(value: T): T;
136
+ /**
137
+ * Snapshot with per-object registration resolution (RUL-12 DAG ruling): every
138
+ * reachable wrappable resolves through its target's CURRENT backing, so
139
+ * privatized subtrees are seen through any parent path. Identity-preserving:
140
+ * a subtree with no substitutions below returns its own object (zero copy for
141
+ * settled, never-diverged graphs).
142
+ */
143
+ export declare function snapshotNext<T>(value: T): T;
@@ -0,0 +1,196 @@
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.js";
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
+ /** Retaining transactions (#3164 fold ruling): every transaction that made
31
+ * an optimistic setter call on this family and may still be open. While
32
+ * any member is live, truth landings FOLD — they stage into the retaining
33
+ * transaction and reveal atomically at its settle, exactly like a signal
34
+ * landing under an active override. Dead members prune lazily at each
35
+ * landing (retainingTransition). */
36
+ rt?: Set<any>;
37
+ /** Flight-owned transaction (#3146): declared when a truth-flight
38
+ * registers (the ask's transaction — created by the flight's own pending
39
+ * throw when none was ambient, the causing write's when one was), renewed
40
+ * per settle event once the previous reveal committed. Bare optimistic
41
+ * writes and landings route into it BY DECLARATION; the transitionBlocked
42
+ * store-half checks it for ownership instead of reconstructing it from
43
+ * `_optimisticStores` membership. null = no flight declared one (sync
44
+ * derive, or a loading-window flight — the loading rail is
45
+ * transaction-invisible, #2933). */
46
+ ft?: any;
47
+ /** Normalized row-key fn (same resolution as the projection channels:
48
+ * `options.key`, "id" default, null = unkeyed). The staged-landing walk
49
+ * reads it: key-matched rows keep their proxy identity across a fold. */
50
+ key?: ((item: any) => any) | null;
51
+ map: WeakMap<object, StoreNextTarget>;
52
+ /** The projection computed — assigned after creation (accessor pattern). */
53
+ node: Computed<any> | null;
54
+ shallow?: boolean;
55
+ /** Derive run counter (proj R37): the run whose draft is live. A draft
56
+ * compares its own run against this — the next run's start supersedes it. */
57
+ run?: number;
58
+ }
59
+ export interface StoreNextTarget {
60
+ /** Committed backing: source object (shared) or owned clone. */
61
+ v: Record<PropertyKey, any>;
62
+ /** Pending backing for the current flush (null when settled). */
63
+ pb: Record<PropertyKey, any> | null;
64
+ /** cached: committed backing is another store's proxy (§7b chained). */
65
+ ch: boolean;
66
+ /** live value-node count (deleted-key sweep fast-out in the fused walk). */
67
+ nc: number;
68
+ /** Lazy per-property subscription nodes (real core signals). */
69
+ n: Record<PropertyKey, Signal<any>> | null;
70
+ /** Lazy per-key presence nodes (`in` tracks presence, not value — R13). */
71
+ h: Record<PropertyKey, Signal<boolean>> | null;
72
+ /** Lazy key-set node: membership/iteration/$TRACK subscriptions (§6). */
73
+ k: Signal<number> | null;
74
+ /** Keys written through the traps since the last fold commit. Bounds the
75
+ * setter notify/hold-check to O(written) instead of O(subscribed nodes) —
76
+ * a record with thousands of per-key subscriptions (selection maps) would
77
+ * otherwise pay a full node scan on every write. null = no trap writes
78
+ * this batch (bulk paths fall back to the full scan); WK_ALL = bound
79
+ * unusable (array length write). LOAD-BEARING SHAPE RULE: array proxy
80
+ * targets carry their fields as named properties on a real array, and V8
81
+ * normalizes an array to dictionary properties as the named count grows
82
+ * (empirically at counts ≡ 0 mod 3 from 18 up on V8 13.x) — every trap
83
+ * field read then becomes a hash lookup (~15% uibench, tree suites
84
+ * worst). Future write-side state MUST ride an extension object, not new
85
+ * named fields. */
86
+ wk: Set<PropertyKey> | null;
87
+ /** Lazy deep-witness node: `deep()` subscribes ONE node per record instead
88
+ * of one per path; write paths bump it only when it exists. Separate from
89
+ * `k` so $TRACK/mapArray never rerun on leaf value changes (R9). */
90
+ dk: Signal<number> | null;
91
+ /** Parent target (path copying walks this at commit). */
92
+ u: StoreNextTarget | null;
93
+ /** Property key of this target in the parent's backing. */
94
+ pk: PropertyKey | null;
95
+ /** The proxy for this target (stable outward identity). */
96
+ px: any;
97
+ /** Sticky descendants flag (§6d). */
98
+ d: boolean;
99
+ /** Sticky accessors-seen flag: an own accessor property was observed on
100
+ * this target (first-read scan, defineProperty, or clone scan). Gates the
101
+ * fold diff's descriptor-safe path and the get trap's descriptor path. */
102
+ a: boolean;
103
+ /** Accessor scan grade: 0 = not yet scanned (adoption resets — adopted data
104
+ * is not rescanned until the next draft), 1 = scanned, 2 = scanned and
105
+ * PLAIN DATA — `Object.prototype` with every own key an enumerable data
106
+ * property. Grade 2 unlocks the spread clone (cloneRaw), bare-assignment
107
+ * overlay writes and flatten (#3360); a non-plain defineProperty through
108
+ * the draft downgrades it to 1. */
109
+ sc: 0 | 1 | 2;
110
+ /** Own-key count: exact at scan, then bumped by set-trap writes of keys new
111
+ * to the container (never decremented — an estimate for the overlay/clone
112
+ * choice only, #3360). */
113
+ kc: number;
114
+ /** Adoption diff base, non-null when the backing was swapped by adoption
115
+ * this batch: the view the nodes were LAST TOLD — the pre-batch committed
116
+ * backing, or the draft's pending backing when a draft preceded the
117
+ * adoption (its setter-exit notifications already moved the nodes, #3296).
118
+ * The deferred fold diffs incoming against this, never against committed. */
119
+ ab: Record<PropertyKey, any> | null;
120
+ /** Pending backing is a prototype-chain OVERLAY of the committed backing
121
+ * (`Object.create(v)` — own keys are this batch's writes, everything else
122
+ * reads through). O(written) per flush instead of O(container) clones
123
+ * (#3044); commit flattens own keys onto an owned committed backing in
124
+ * place. Plain-data non-array containers qualify, including projection
125
+ * and derived-store families (#3352); optimistic families, chained
126
+ * backings, and accessor containers keep the descriptor clone.
127
+ * `materializePB` downgrades to the clone path when a consumer needs a
128
+ * real container (reconcile, draft escape). */
129
+ ovl: boolean;
130
+ /** Keys deleted in the overlay window (a prototype overlay cannot shadow
131
+ * a delete); null when none. */
132
+ del: Set<PropertyKey> | null;
133
+ /** Projection family, null for plain stores (§7b). */
134
+ fam: StoreNextFamily | null;
135
+ /** Shallow store root (values served raw). */
136
+ s: boolean;
137
+ /** Held committed view (#3074/#3075): the pre-hold committed backing,
138
+ * served to committed-visibility readers while `ht` is live. Adoption is
139
+ * eager by contract, but a projection recompute deriving from uncommitted
140
+ * inputs (a transition-held source, or a latest()-pull ahead of the flush)
141
+ * swaps the backing SPECULATIVELY — the old view must stay servable until
142
+ * the hold resolves. */
143
+ hv: Record<PropertyKey, any> | null;
144
+ /** The holder for `hv`: a live transition (cleared lazily when it is done)
145
+ * or the PLAIN_HOLD sentinel (a latest()-pull staging — cleared by the
146
+ * fold commit). null = no hold. */
147
+ ht: any;
148
+ }
149
+ /**
150
+ * Ownership stamp (#3360): every backing the store ALLOCATES (CoW clones,
151
+ * privatized committed backings) carries its owning target under this
152
+ * enumerable symbol. One property write replaces the two weak-collection
153
+ * registrations (ownership set + raw→target map) a fresh object used to pay
154
+ * per draft — V8's identity-hash + ephemeron cost dominated the one-key
155
+ * write floor. Enumerable so a spread copy (the plain-data clone path) stays
156
+ * on the fast path and carries the stamp along.
157
+ *
158
+ * Owned backings are never user-reachable (`snapshot` copies them, the traps
159
+ * hide the key), so every raw key walk in the store must skip `$OWNER`, and
160
+ * ownership is answered by `isOwned` — a user object never carries it.
161
+ * Overlay drafts (`Object.create(v)` over an owned `v`) inherit the stamp.
162
+ */
163
+ export declare const $OWNER: unique symbol;
164
+ /** raw → target for UNOWNED backings (user-ingested, adopted); owned
165
+ * backings resolve through their `$OWNER` stamp. Boundary mechanism (O8). */
166
+ export declare const storeNextLookup: WeakMap<object, StoreNextTarget>;
167
+ /** A backing the store allocated and may mutate in place. */
168
+ export declare function isOwned(raw: object): boolean;
169
+ /** raw → target within a family (`null` = plain stores / the global map).
170
+ * The stamp answers for backings owned by a target OF THAT FAMILY; anything
171
+ * else (user objects, adoptees, another family's backings the family
172
+ * re-registered for its own wrapper) resolves through the family's map. */
173
+ export declare function lookupTarget(raw: object, fam: StoreNextFamily | null): StoreNextTarget | undefined;
174
+ /** __TEST__ oracle: every object ingested from a user (never mutate). */
175
+ export declare const ingestedRaw: WeakSet<object> | null;
176
+ export declare function devAssertNeverUserMutation(target: object): void;
177
+ /** Injection table for optimistic-only store machinery (next/optimistic.ts).
178
+ * Every call site is gated on `fam?.opt`, and optimistic families can only
179
+ * be created by createOptimisticStore — whose install populates this — so
180
+ * the non-null assertions at the sites hold by construction. Keeping the
181
+ * implementations out of next/store.ts lets plain-store bundles tree-shake
182
+ * the optimistic channel entirely. */
183
+ export interface OptStoreHooks {
184
+ notifyOptimisticWrites(t: any, pb: Record<PropertyKey, any>): void;
185
+ optimisticView(t: any, src: Record<PropertyKey, any>, draft?: boolean): Record<PropertyKey, any>;
186
+ applyTentative(t: any, incoming: any, keyFn: ((item: any) => any) | null): void;
187
+ /** #3164 fold: does this live transaction still retain optimism (armed
188
+ * nodes or tracked stores)? Backs the held-truth masks in next/store.ts so
189
+ * plain-store bundles don't carry the transition-optimism probe. */
190
+ retainsOptimism(t: any): boolean;
191
+ }
192
+ export declare let optHooks: OptStoreHooks | null;
193
+ export declare function setOptHooks(h: OptStoreHooks): void;
194
+ /** Sticky descendants flag walk (§6d): reconcile's keyed pruning descends
195
+ * only where subscriptions exist at/below. Nodes AND patches count. */
196
+ export declare function markDescendants(target: StoreNextTarget): void;
@@ -1,7 +1,7 @@
1
- import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
2
- import { type Transition } from "../core/scheduler.js";
3
- /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
4
- export type Store<T> = Readonly<T>;
1
+ import { type Signal } from "../core/index.js";
2
+ import type { Refreshable } from "../core/index.js";
3
+ /** A reactive view of a store's value. Update it through the paired `StoreSetter`. */
4
+ export type Store<T> = T;
5
5
  /**
6
6
  * A store setter. The callback receives a writable **draft** of the store.
7
7
  *
@@ -14,25 +14,34 @@ export type Store<T> = Readonly<T>;
14
14
  *
15
15
  * The setter does **not** perform keyed reconciliation. If you need surviving
16
16
  * items to keep their store identity across full-array replacement, use the
17
- * projection form — `createStore(fn, seed, { key })` or `createProjection` —
18
- * whose derive function reconciles its return by `options.key`.
17
+ * projection form — `createStore(fn, seed, { key })` or
18
+ * `createProjection(fn, seed, { key })` — whose derive function reconciles
19
+ * its return by `options.key`.
19
20
  */
20
21
  export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
21
- /** Tuple returned by the plain `createStore(initialValue)` form. */
22
+ /** Tuple returned by the plain `createStore(initialValue, options?)` form. */
22
23
  export type StoreReturn<T> = [get: Store<T>, set: StoreSetter<T>];
23
24
  /** Tuple returned by the derived `createStore(fn, seed, options?)` form. */
24
25
  export type ProjectionStoreReturn<T> = [get: Refreshable<Store<T>>, set: StoreSetter<T>];
25
- /** Base options for store primitives. */
26
+ /** Options shared by all store primitives. */
26
27
  export interface StoreOptions {
27
- /** Debug name (dev mode only) */
28
+ /**
29
+ * Debug name (dev and observe builds). Property nodes are labelled
30
+ * `<name>.<key>` in attribution output (`todos.title`); a derived store's
31
+ * projection node carries the name itself.
32
+ */
28
33
  name?: string;
34
+ /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
+ shallow?: boolean;
29
36
  }
30
- /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
37
+ /**
38
+ * Options for derived/projected stores created with
39
+ * `createStore(fn, seed, options?)`, `createProjection(fn, seed, options?)`,
40
+ * or `createOptimisticStore(fn, seed, options?)`.
41
+ */
31
42
  export interface ProjectionOptions extends StoreOptions {
32
43
  /** Key property name or function for reconciliation identity; `null` merges positionally */
33
44
  key?: string | ((item: NonNullable<any>) => any) | null;
34
- /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
- shallow?: boolean;
36
45
  /**
37
46
  * Treat the seed as commit #0: the store is born committed with the seed's
38
47
  * contents, shown until the derive's first real answer lands. While that
@@ -57,22 +66,15 @@ type DataNodes = Record<PropertyKey, DataNode>;
57
66
  *
58
67
  * @internal
59
68
  */
60
- export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
61
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
69
+ export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $RECORD: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
70
+ export declare const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
71
+ /** Structural view of a store target as shared machinery sees it (the real
72
+ * shape is `StoreNextTarget` in ./next/target.ts). */
62
73
  export type StoreNode = {
63
74
  [$PROXY]: any;
64
75
  [STORE_VALUE]: Record<PropertyKey, any>;
65
- [STORE_OVERRIDE]?: Record<PropertyKey, any>;
66
- [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
67
- [STORE_OPTIMISTIC_OWNERS]?: Record<PropertyKey, Transition | null>;
68
76
  [STORE_NODE]?: DataNodes;
69
77
  [STORE_HAS]?: DataNodes;
70
- [STORE_CUSTOM_PROTO]?: boolean;
71
- [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
72
- [STORE_LOOKUP]?: WeakMap<any, any>;
73
- [STORE_FIREWALL]?: Computed<any>;
74
- [STORE_OPTIMISTIC]?: boolean;
75
- [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
76
78
  [STORE_PARENT]?: StoreNode;
77
79
  [STORE_SHALLOW]?: boolean;
78
80
  [STORE_DESC]?: boolean;
@@ -82,10 +84,6 @@ export declare namespace SolidStore {
82
84
  }
83
85
  }
84
86
  export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
85
- export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
86
- export declare const storeLookup: WeakMap<WeakKey, any>;
87
- export declare const symbolKeyedRecords: WeakSet<object>;
88
- export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): StoreNode | undefined;
89
87
  /**
90
88
  * Marks a value as raw: no store will ever wrap it — every store presents it
91
89
  * as-is, tracked by reference at whatever slot holds it and updated by
@@ -96,25 +94,33 @@ export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): St
96
94
  export declare let rawValuesUsed: boolean;
97
95
  export declare function isRawValue(value: any): boolean;
98
96
  export declare function markRaw<T>(value: T): T;
97
+ export declare function markRawOne(v: any): void;
99
98
  export declare function markRawIngest(container: any): void;
100
- export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
101
- export declare function wrapShallow<T extends Record<PropertyKey, any>>(value: T): T;
102
99
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
103
100
  export declare function setWriteOverride(value: boolean): void;
101
+ export declare function getWriteOverride(): boolean;
104
102
  export declare function ownEnumerableKeys(o: object): (string | symbol)[];
105
103
  /**
106
- * Single chokepoint for the store's layered value resolution: returns the
107
- * override layer (optimistic first, then regular) that shadows `property`, or
108
- * `undefined` when the base `STORE_VALUE` is authoritative. Every trap must
109
- * resolve through this — hand-inlining the layer order is how the optimistic
110
- * layer gets missed (#2850).
111
- */
112
- export declare function getOverlayLayer(target: StoreNode, property: PropertyKey): Record<PropertyKey, any> | undefined;
113
- /**
114
- * The value a store leaf's backing signal currently shows to readers: active
115
- * override, else held pending value, else committed value.
104
+ * Scope inheritance for late-created nodes: every live mark whose identity
105
+ * scope contains the owning record's raw — and, for keyed marks, whose key
106
+ * is this property — gets counted on the new node. Inherited marks live
107
+ * exactly as long as the scope's carrier — the release hook below drops
108
+ * them with the entry.
116
109
  */
117
- export declare function visibleNodeValue(node: DataNode): any;
110
+ export declare function inheritAffectsMarks(node: DataNode, raw: object, property: PropertyKey): void;
111
+ /** Next-store node factory for affects carriers/slots: injected by the
112
+ * rewrite module (next targets alias the legacy field names, so everything
113
+ * here EXCEPT node creation works on them structurally). */
114
+ export declare let nextAffectsNodeResolver: ((target: any, key: PropertyKey) => DataNode) | null;
115
+ export declare function setNextAffectsNodeResolver(fn: (target: any, key: PropertyKey) => DataNode): void;
116
+ /** Next-store optimistic view for the declaration walk (optimistic rows
117
+ * pushed before the declaration are in motion too — legacy reads its write
118
+ * overlays; next composes armed-node overrides). */
119
+ export declare let nextOptimisticViewResolver: ((target: any, raw: any) => any) | null;
120
+ export declare function setNextOptimisticViewResolver(fn: (target: any, raw: any) => any): void;
121
+ /** @internal birth inheritance for nodes created inside a live mark window —
122
+ * exported for the rewrite's node factories. */
123
+ export declare function affectsScopesLive(): boolean;
118
124
  /**
119
125
  * Witness live mark coverage of a record into the active isPending() probe.
120
126
  * Tracked reads don't need this — they go through real signal nodes, which
@@ -138,76 +144,4 @@ export declare function witnessAffectsMark(target: StoreNode, property?: Propert
138
144
  * @internal
139
145
  */
140
146
  export declare function getStoreAffectsNodes(target: StoreNode, key?: PropertyKey): DataNode[];
141
- export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
142
- export declare function notifySelf(target: StoreNode): void;
143
- /**
144
- * The write overlay a walk must read through: optimistic writes shadow
145
- * regular pending writes, the same resolution order as every proxy trap and
146
- * `reconcile` (#2850). Merging allocates only in the rare both-present case
147
- * (a derived optimistic store with an in-flight projection commit).
148
- */
149
- export declare function mergedOverlay(target: StoreNode): Record<PropertyKey, any> | undefined;
150
- export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
151
- export declare function getStoreKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): PropertyKey[];
152
- export declare function getStoreSymbols(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): symbol[];
153
- export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
154
- export declare const storeTraps: ProxyHandler<StoreNode>;
155
- export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
156
- /**
157
- * Creates a deeply-reactive store backed by a Proxy. Reads track each property
158
- * accessed; only the parts that change trigger updates.
159
- *
160
- * Store properties hold **plain values**, not accessors. The proxy already
161
- * tracks reads per-property — wrapping a value in `() => state.foo` produces
162
- * a getter that *won't* track when called, which looks like a reactivity bug
163
- * but is just a category error. If you have a signal-shaped piece of state,
164
- * make it a property of the store (`{ foo: 1 }`) rather than nesting an
165
- * accessor inside (`{ foo: () => signal() }`).
166
- *
167
- * The setter takes a **draft-mutating** function — mutate the draft in place
168
- * (canonical). The callback may also return a new value: arrays are replaced
169
- * by index (length adjusted), objects are shallow-diffed at the top level
170
- * (keys present in the returned value are written, missing keys deleted). Use
171
- * the return form for shapes where mutation is awkward — most commonly
172
- * removing items via `filter`. The setter does **not** do keyed reconciliation;
173
- * for that, use the derived/projection form (or `createProjection`).
174
- *
175
- * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
176
- * proxy.
177
- * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
178
- * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
179
- * an `AsyncIterable`; the projection's result reconciles against the
180
- * existing store by `options.key` (default `"id"`) for stable identity.
181
- *
182
- * @example
183
- * ```ts
184
- * const [state, setState] = createStore({
185
- * user: { name: "Ada", age: 36 },
186
- * todos: [] as { id: string; text: string; done: boolean }[]
187
- * });
188
- *
189
- * // Canonical: mutate the draft in place.
190
- * setState(s => { s.user.age = 37; });
191
- * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
192
- *
193
- * // Return form: reach for it when mutation is awkward.
194
- * setState(s => s.todos.filter(t => !t.done)); // remove items
195
- * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
196
- * ```
197
- *
198
- * @example
199
- * ```ts
200
- * // Derived store — auto-fetches & reconciles by `id`.
201
- * const [users] = createStore(
202
- * async () => fetch("/users").then(r => r.json()),
203
- * [] as User[]
204
- * );
205
- * ```
206
- *
207
- * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
208
- */
209
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
210
- shallow?: boolean;
211
- }): StoreReturn<T>;
212
- 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): ProjectionStoreReturn<T>;
213
147
  export {};