@solidjs/signals 2.0.0-beta.9 → 2.0.0-rc.1

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 (106) hide show
  1. package/README.md +14 -10
  2. package/dist/dev.js +6740 -2011
  3. package/dist/node.cjs +7927 -3340
  4. package/dist/prod/affects.js +126 -0
  5. package/dist/prod/boundaries.js +572 -0
  6. package/dist/prod/core/action.js +139 -0
  7. package/dist/prod/core/async.js +607 -0
  8. package/dist/prod/core/constants.js +92 -0
  9. package/dist/prod/core/context.js +67 -0
  10. package/dist/prod/core/core.js +828 -0
  11. package/dist/prod/core/dev.js +3 -0
  12. package/dist/prod/core/effect.js +145 -0
  13. package/dist/prod/core/error.js +68 -0
  14. package/dist/prod/core/external.js +98 -0
  15. package/dist/prod/core/graph.js +104 -0
  16. package/dist/prod/core/heap.js +140 -0
  17. package/dist/prod/core/invariants.js +42 -0
  18. package/dist/prod/core/lanes.js +140 -0
  19. package/dist/prod/core/optimistic.js +262 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +757 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +319 -0
  25. package/dist/prod/signals.js +394 -0
  26. package/dist/prod/store/index.js +36 -0
  27. package/dist/prod/store/next/optimistic.js +377 -0
  28. package/dist/prod/store/next/projection.js +172 -0
  29. package/dist/prod/store/next/reconcile.js +327 -0
  30. package/dist/prod/store/next/store.js +1232 -0
  31. package/dist/prod/store/next/target.js +20 -0
  32. package/dist/prod/store/store.js +325 -0
  33. package/dist/prod/store/storePath.js +103 -0
  34. package/dist/prod/store/utils.js +201 -0
  35. package/dist/types/affects.d.ts +47 -0
  36. package/dist/types/boundaries.d.ts +60 -13
  37. package/dist/types/core/action.d.ts +35 -6
  38. package/dist/types/core/async.d.ts +16 -1
  39. package/dist/types/core/constants.d.ts +35 -6
  40. package/dist/types/core/context.d.ts +10 -2
  41. package/dist/types/core/core.d.ts +66 -63
  42. package/dist/types/core/dev.d.ts +17 -2
  43. package/dist/types/core/effect.d.ts +1 -2
  44. package/dist/types/core/error.d.ts +33 -0
  45. package/dist/types/core/external.d.ts +0 -11
  46. package/dist/types/core/graph.d.ts +2 -1
  47. package/dist/types/core/heap.d.ts +8 -0
  48. package/dist/types/core/index.d.ts +3 -2
  49. package/dist/types/core/invariants.d.ts +59 -0
  50. package/dist/types/core/lanes.d.ts +2 -0
  51. package/dist/types/core/optimistic.d.ts +6 -0
  52. package/dist/types/core/owner.d.ts +50 -3
  53. package/dist/types/core/scheduler.d.ts +85 -11
  54. package/dist/types/core/types.d.ts +66 -1
  55. package/dist/types/core/verdict.d.ts +2 -0
  56. package/dist/types/index.d.ts +3 -2
  57. package/dist/types/map.d.ts +21 -5
  58. package/dist/types/signals.d.ts +183 -12
  59. package/dist/types/store/index.d.ts +16 -6
  60. package/dist/types/store/next/optimistic.d.ts +20 -0
  61. package/dist/types/store/next/projection.d.ts +24 -0
  62. package/dist/types/store/next/reconcile.d.ts +3 -0
  63. package/dist/types/store/next/store.d.ts +71 -0
  64. package/dist/types/store/next/target.d.ts +99 -0
  65. package/dist/types/store/optimistic.d.ts +3 -3
  66. package/dist/types/store/projection.d.ts +10 -6
  67. package/dist/types/store/reconcile.d.ts +31 -8
  68. package/dist/types/store/store.d.ts +91 -71
  69. package/dist/types/store/utils.d.ts +0 -40
  70. package/dist/types-cjs/affects.d.cts +47 -0
  71. package/dist/types-cjs/boundaries.d.cts +60 -13
  72. package/dist/types-cjs/core/action.d.cts +35 -6
  73. package/dist/types-cjs/core/async.d.cts +16 -1
  74. package/dist/types-cjs/core/constants.d.cts +35 -6
  75. package/dist/types-cjs/core/context.d.cts +10 -2
  76. package/dist/types-cjs/core/core.d.cts +66 -63
  77. package/dist/types-cjs/core/dev.d.cts +17 -2
  78. package/dist/types-cjs/core/effect.d.cts +1 -2
  79. package/dist/types-cjs/core/error.d.cts +33 -0
  80. package/dist/types-cjs/core/external.d.cts +0 -11
  81. package/dist/types-cjs/core/graph.d.cts +2 -1
  82. package/dist/types-cjs/core/heap.d.cts +8 -0
  83. package/dist/types-cjs/core/index.d.cts +3 -2
  84. package/dist/types-cjs/core/invariants.d.cts +59 -0
  85. package/dist/types-cjs/core/lanes.d.cts +2 -0
  86. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  87. package/dist/types-cjs/core/owner.d.cts +50 -3
  88. package/dist/types-cjs/core/scheduler.d.cts +85 -11
  89. package/dist/types-cjs/core/types.d.cts +66 -1
  90. package/dist/types-cjs/core/verdict.d.cts +2 -0
  91. package/dist/types-cjs/index.d.cts +3 -2
  92. package/dist/types-cjs/map.d.cts +21 -5
  93. package/dist/types-cjs/signals.d.cts +183 -12
  94. package/dist/types-cjs/store/index.d.cts +16 -6
  95. package/dist/types-cjs/store/next/optimistic.d.cts +20 -0
  96. package/dist/types-cjs/store/next/projection.d.cts +24 -0
  97. package/dist/types-cjs/store/next/reconcile.d.cts +3 -0
  98. package/dist/types-cjs/store/next/store.d.cts +71 -0
  99. package/dist/types-cjs/store/next/target.d.cts +99 -0
  100. package/dist/types-cjs/store/optimistic.d.cts +3 -3
  101. package/dist/types-cjs/store/projection.d.cts +10 -6
  102. package/dist/types-cjs/store/reconcile.d.cts +31 -8
  103. package/dist/types-cjs/store/store.d.cts +91 -71
  104. package/dist/types-cjs/store/utils.d.cts +0 -40
  105. package/package.json +12 -9
  106. package/dist/prod.js +0 -3627
@@ -1,9 +1,19 @@
1
- export type { Store, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.cjs";
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, 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";
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 { snapshot, deep, merge, omit } from "./utils.cjs";
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,24 @@
1
+ /**
2
+ * Store rewrite — projections (§7/§7b): a projection is a computed store.
3
+ * The derive runs inside a computed whose recompute merges its output into
4
+ * the projection's backing through the adoption channel (replace-mode root:
5
+ * entity changes merge in place, the root proxy is stable for life). Children
6
+ * wrap into the projection's own FAMILY (writes land here, never in a source
7
+ * family), and every family node carries the projection computed as its
8
+ * firewall — reads link the derive's status and lifecycle natively. The §6c
9
+ * status gate in the traps makes an uninitialized async derive's seed
10
+ * unobservable through every read surface.
11
+ *
12
+ * Mirrors the legacy runProjectionComputed shape (shadow runs for open
13
+ * loading windows, handleAsync landings, commit-through-setter) on next
14
+ * primitives; the generic draft write-traps are reused from the legacy
15
+ * module unchanged.
16
+ */
17
+ import { type Computed, type Refreshable } from "../../core/index.cjs";
18
+ import { type NoFn, type ProjectionOptions, type Store } from "../store.cjs";
19
+ 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>>;
20
+ /** Derived writable store (legacy parity): a projection whose public setter
21
+ * masks the recompute for the tick (core R31 — the manual write wins over a
22
+ * same-flush dependency change). */
23
+ 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];
24
+ 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,3 @@
1
+ type KeyFn = (item: any) => any;
2
+ export declare function reconcileNextState(value: any, state: any, key: string | KeyFn | null | undefined, replace?: boolean): void;
3
+ export {};
@@ -0,0 +1,71 @@
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
+ /**
13
+ * Adoption (2026-08-16c): the incoming object becomes the committed backing
14
+ * IMMEDIATELY — reconcile is eagerly visible to every reader (shipped
15
+ * contract; only its notifications batch), unlike setter writes which stay
16
+ * pending until flush. Ownership resets (incoming is unowned/user data). Any
17
+ * staged draft clone folds into the diff and is discarded — next is the
18
+ * authoritative base (R21/R32).
19
+ */
20
+ export declare function adoptPB(target: StoreNextTarget, incoming: Record<PropertyKey, any>, eager?: boolean): void;
21
+ /** Same logical slot: both values resolve to one (re-pointed) child target —
22
+ * adoption preserved identity, so the slot did not change (R9). */
23
+ export declare function targetsEqual(ov: any, nv: any): boolean;
24
+ /**
25
+ * The fold diff walks SUBSCRIPTION KEYS ONLY (legacy parity: `for key in
26
+ * nodes`): nodes exist exactly where something tracked, so unobserved data
27
+ * costs nothing here regardless of object size. Accessor safety rides the
28
+ * sticky `t.a` flag — a node's key was necessarily read, so the get trap has
29
+ * already seen whether it is an accessor.
30
+ */
31
+ /** One node's fold notification (shared by notifyFold's walk and the fused
32
+ * adoption walk): accessor-aware compare + equality/identity-gated setSignal. */
33
+ export declare function notifyKeyDiff(node: Signal<any>, key: PropertyKey, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>, probe?: boolean): void;
34
+ /** Accessor-flag probe for the fused walk's early-continue (accessor keys
35
+ * can never identity-skip: their VALUE is the descriptor's product). */
36
+ export declare function hasAccessorFlag(node: Signal<any>): boolean;
37
+ /** Fused-walk per-key notification with values already in hand: the caller
38
+ * fetched both sides and handled the identity skip; this applies the
39
+ * accessor branch (cached flag only — reconcile channel) or the plain
40
+ * equality/identity-gated write. */
41
+ export declare function notifyKeyValue(node: Signal<any>, key: PropertyKey, ov: any, nv: any, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
42
+ /** Presence + membership halves of a fold notification (shared tail). */
43
+ export declare function notifyFoldTail(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
44
+ export declare function notifyFold(t: StoreNextTarget, old: Record<PropertyKey, any>, neu: Record<PropertyKey, any>): void;
45
+ /** Authoritative-write wrapper exported for the optimistic module: sets the
46
+ * scheduler's projectionWriteActive through THIS module's binding (proven to
47
+ * share the instance core reads — cross-module live-binding writes from other
48
+ * store modules were observed not to propagate under the test transform). */
49
+ export declare function runAuthoritative<T>(fn: () => T): T;
50
+ /** Active optimistic override on an armed node (armed slot idles at
51
+ * NOT_PENDING; undefined = unarmed plain node). */
52
+ export declare function hasActiveOverride(node: Signal<any>): boolean;
53
+ export type SetStoreNextFunction<T> = (fn: (draft: T) => T | void) => void;
54
+ /** Low-level setter primitive: opens write mode on a next proxy, runs `fn`,
55
+ * emits write-time notifications at outermost exit, applies returned
56
+ * replacements as adoptions. `guard=false` skips the owned-scope dev guard —
57
+ * projection recomputes legitimately write from inside their computed. */
58
+ export declare function storeSetterNext<T>(proxy: T, fn: (draft: T) => T | void, guard?: boolean): void;
59
+ export declare function createStoreNext<T extends Record<PropertyKey, any>>(init: T, shallow?: boolean): [T, SetStoreNextFunction<T>];
60
+ /** Tracking deep snapshot (`deep()` for next targets): subscribes to the
61
+ * key-set and every property node at every reachable level, then returns the
62
+ * plain view. Shared references and cycles handled via the visited set. */
63
+ export declare function deepNext<T>(value: T): T;
64
+ /**
65
+ * Snapshot with per-object registration resolution (RUL-12 DAG ruling): every
66
+ * reachable wrappable resolves through its target's CURRENT backing, so
67
+ * privatized subtrees are seen through any parent path. Identity-preserving:
68
+ * a subtree with no substitutions below returns its own object (zero copy for
69
+ * settled, never-diverged graphs).
70
+ */
71
+ export declare function snapshotNext<T>(value: T): T;
@@ -0,0 +1,99 @@
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
+ /** Projection family, null for plain stores (§7b). */
72
+ fam: StoreNextFamily | null;
73
+ /** Shallow store root (values served raw). */
74
+ s: boolean;
75
+ }
76
+ /**
77
+ * Ownership (first cut, decision 2026-08-16d): one WeakSet of store-owned
78
+ * backings serving both the production identity-skip guard and the __TEST__
79
+ * no-mutation oracle.
80
+ */
81
+ export declare const ownedRaw: WeakSet<object>;
82
+ /** raw → target. The only raw-keyed lookup; boundary mechanism (O8). */
83
+ export declare const storeNextLookup: WeakMap<object, StoreNextTarget>;
84
+ /** __TEST__ oracle: every object ingested from a user (never mutate). */
85
+ export declare const ingestedRaw: WeakSet<object> | null;
86
+ export declare function devAssertNeverUserMutation(target: object): void;
87
+ /** Injection table for optimistic-only store machinery (next/optimistic.ts).
88
+ * Every call site is gated on `fam?.opt`, and optimistic families can only
89
+ * be created by createOptimisticStore — whose install populates this — so
90
+ * the non-null assertions at the sites hold by construction. Keeping the
91
+ * implementations out of next/store.ts lets plain-store bundles tree-shake
92
+ * the optimistic channel entirely. */
93
+ export interface OptStoreHooks {
94
+ notifyOptimisticWrites(t: any, pb: Record<PropertyKey, any>): void;
95
+ optimisticView(t: any, src: Record<PropertyKey, any>): Record<PropertyKey, any>;
96
+ applyTentative(t: any, incoming: any, keyFn: ((item: any) => any) | null): void;
97
+ }
98
+ export declare let optHooks: OptStoreHooks | null;
99
+ export declare function setOptHooks(h: OptStoreHooks): void;
@@ -14,8 +14,8 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
14
14
  * optimistic overlay reverts after each transition.
15
15
  *
16
16
  * `options.key` defaults to `"id"`; specify it only when your data uses a
17
- * different identity field (e.g. `{ key: "uuid" }` or `{ key: t => t.slug }`).
18
- * Restating the default just adds noise.
17
+ * different identity field (e.g. `{ key: "uuid" }` or `{ key: t => t.slug }`),
18
+ * or `null` to merge positionally. Restating the default just adds noise.
19
19
  *
20
20
  * @example
21
21
  * ```ts
@@ -41,5 +41,5 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
41
41
  *
42
42
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
43
43
  */
44
- export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
44
+ export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T>, set: StoreSetter<T>];
45
45
  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: Refreshable<Store<T>>, set: StoreSetter<T>];
@@ -1,5 +1,5 @@
1
1
  import { type Computed, type Refreshable } from "../core/index.cjs";
2
- import { type ProjectionOptions, type Store } from "./store.cjs";
2
+ import { type NoFn, type ProjectionOptions, type Store } from "./store.cjs";
3
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
4
  store: Refreshable<Store<T>>;
5
5
  node: Computed<void | T>;
@@ -12,6 +12,10 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
12
12
  * items keep their proxy identity — only added/removed items are
13
13
  * created/disposed.
14
14
  *
15
+ * If the derive returns a different entity than the one currently held (the
16
+ * `/users/1` → `/users/2` shape), the store swaps to it rather than merging,
17
+ * and nothing below it is treated as surviving.
18
+ *
15
19
  * Returns the projected store directly (no setter — reads only).
16
20
  *
17
21
  * Use this when you want the structural-sharing / per-property tracking
@@ -24,7 +28,8 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
24
28
  * @param seed the backing store value to wrap and reconcile into
25
29
  * @param options `ProjectionOptions` — `name`, `key`. `key` defaults to
26
30
  * `"id"`; specify it only when your data uses a different identity field
27
- * (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`).
31
+ * (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`), or `null` to merge
32
+ * positionally with no keyed pass.
28
33
  *
29
34
  * @example
30
35
  * ```ts
@@ -47,7 +52,7 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
47
52
  *
48
53
  * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
49
54
  */
50
- export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T>, options?: ProjectionOptions): Refreshable<Store<T>>;
55
+ export declare function createProjection<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>>;
51
56
  /**
52
57
  * Shared projection computed body used by both `createProjection` and the derived
53
58
  * form of `createOptimisticStore`. Encapsulates the write-trap draft, `storeSetter`
@@ -61,6 +66,5 @@ export declare function createProjection<T extends object = {}>(fn: (draft: T) =
61
66
  * instead of `STORE_OPTIMISTIC_OVERRIDE` even when an async yield fires outside
62
67
  * the outer `setProjectionWriteActive` scope.
63
68
  */
64
- export declare function runProjectionComputed<T extends object>(wrappedStore: Store<T>, fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, key: string | ((item: NonNullable<any>) => any), wrapCommit?: (write: () => void) => void): Computed<void | T>;
65
- export declare function createWriteTraps(isActive?: () => boolean): ProxyHandler<any>;
66
- export declare const writeTraps: ProxyHandler<any>;
69
+ export declare function runProjectionComputed<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>;
70
+ export declare function createWriteTraps(isActive?: () => boolean, onDraftWrite?: () => void): ProxyHandler<any>;
@@ -1,14 +1,34 @@
1
+ /**
2
+ * Shared body of `reconcile()` and the projection commit. `replace` is the
3
+ * only difference: a projection commit is a value swap, not a merge — its root
4
+ * proxy is a cell handed out by `createProjection` that can never change
5
+ * reference, so a derive returning a different entity is not the slot mistake
6
+ * `reconcile()` throws on. Nothing below the root survives that swap, which is
7
+ * the rule the keyed diff already applies at a nested slot on a key mismatch.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function reconcileState(value: any, state: any, key: any, replace: boolean): void;
1
12
  /**
2
13
  * Returns a draft-mutating function that smart-merges `value` into a store,
3
- * preserving the identity of items whose `key` field matches between old and
4
- * new states. Useful when applying server payloads or full-replacement data
5
- * onto an existing store without losing fine-grained reactivity.
14
+ * preserving fine-grained reactivity: only changed leaves trigger updates.
6
15
  *
7
- * Items with the same key are updated in place (only changed properties
8
- * trigger updates). Items added or removed update the corresponding signals.
16
+ * With a `key` (default `"id"`), array items whose key matches between old
17
+ * and new states keep their identity (updated in place, moves and removals
18
+ * update the corresponding signals) — the shape for keyed server payloads.
19
+ * Items without the key field fall back to positional matching.
20
+ *
21
+ * With `key: null`, matching is purely positional: index N of the new array
22
+ * merges into index N of the old, and object properties merge recursively —
23
+ * the classic pattern for fixed-shape data that churns in place (dashboards,
24
+ * monitors), where no keyed diff pass is needed or wanted.
25
+ *
26
+ * Merging into a slot that holds a *different* entity throws — the caller
27
+ * picked the slot, so a key mismatch there is a bug.
9
28
  *
10
29
  * @param value the next state to merge in
11
- * @param key property name (string) or extractor function for stable identity
30
+ * @param key property name (string) or extractor function for stable
31
+ * identity (default `"id"`); pass `null` for positional merging
12
32
  *
13
33
  * @example
14
34
  * ```ts
@@ -16,8 +36,11 @@
16
36
  *
17
37
  * async function refresh() {
18
38
  * const fresh = await api.getTodos();
19
- * setTodos(reconcile(fresh, "id")); // diff-merge by `id`
39
+ * setTodos(reconcile(fresh)); // diff-merge by `id`
20
40
  * }
41
+ *
42
+ * // fixed-shape polling data — positional merge
43
+ * setStats(reconcile(nextStats, null));
21
44
  * ```
22
45
  */
23
- export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
46
+ export declare function reconcile<T extends U, U>(value: T, key?: string | ((item: NonNullable<any>) => any) | null): (state: U) => void;
@@ -1,4 +1,5 @@
1
- import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.cjs";
1
+ import { type Signal } from "../core/index.cjs";
2
+ import type { Refreshable } from "../core/index.cjs";
2
3
  /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
3
4
  export type Store<T> = Readonly<T>;
4
5
  /**
@@ -17,6 +18,10 @@ export type Store<T> = Readonly<T>;
17
18
  * whose derive function reconciles its return by `options.key`.
18
19
  */
19
20
  export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
21
+ /** Tuple returned by the plain `createStore(initialValue)` form. */
22
+ export type StoreReturn<T> = [get: Store<T>, set: StoreSetter<T>];
23
+ /** Tuple returned by the derived `createStore(fn, seed, options?)` form. */
24
+ export type ProjectionStoreReturn<T> = [get: Refreshable<Store<T>>, set: StoreSetter<T>];
20
25
  /** Base options for store primitives. */
21
26
  export interface StoreOptions {
22
27
  /** Debug name (dev mode only) */
@@ -24,95 +29,110 @@ export interface StoreOptions {
24
29
  }
25
30
  /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
26
31
  export interface ProjectionOptions extends StoreOptions {
27
- /** Key property name or function for reconciliation identity */
28
- key?: string | ((item: NonNullable<any>) => any);
32
+ /** Key property name or function for reconciliation identity; `null` merges positionally */
33
+ key?: string | ((item: NonNullable<any>) => any) | null;
34
+ /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
+ shallow?: boolean;
36
+ /**
37
+ * Treat the seed as commit #0: the store is born committed with the seed's
38
+ * contents, shown until the derive's first real answer lands. While that
39
+ * first answer is in flight, reads serve the seed everywhere — nothing
40
+ * suspends to a `<Loading>` boundary, no transition is held, and
41
+ * `isPending` stays false (the seed answers by declaration; first-load
42
+ * affordances belong to the data, e.g. a `skeleton: true` field in the
43
+ * seed). Once the first answer lands (reconciled into the seed), refetches
44
+ * use normal pending semantics with `isPending` true.
45
+ *
46
+ * The store equivalent of `MemoOptions.loadingValue`; the seed already
47
+ * carries the placeholder shape, so this is just the opt-in.
48
+ */
49
+ seedLoadingValue?: boolean;
29
50
  }
30
51
  export type NoFn<T> = T extends Function ? never : T;
31
52
  type DataNode = Signal<any>;
32
53
  type DataNodes = Record<PropertyKey, DataNode>;
33
- export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
34
- 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";
54
+ /**
55
+ * Brand symbols used internally by the store proxy / projection plumbing.
56
+ * Cross-package wiring; not part of the user-facing API.
57
+ *
58
+ * @internal
59
+ */
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_NODE = "n", STORE_HAS = "h", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
62
+ /** Structural view of a store target as shared machinery sees it (the real
63
+ * shape is `StoreNextTarget` in ./next/target.ts). */
35
64
  export type StoreNode = {
36
65
  [$PROXY]: any;
37
66
  [STORE_VALUE]: Record<PropertyKey, any>;
38
- [STORE_OVERRIDE]?: Record<PropertyKey, any>;
39
- [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
40
67
  [STORE_NODE]?: DataNodes;
41
68
  [STORE_HAS]?: DataNodes;
42
- [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
43
- [STORE_LOOKUP]?: WeakMap<any, any>;
44
- [STORE_FIREWALL]?: Computed<any>;
45
- [STORE_OPTIMISTIC]?: boolean;
46
- [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
69
+ [STORE_PARENT]?: StoreNode;
70
+ [STORE_SHALLOW]?: boolean;
71
+ [STORE_DESC]?: boolean;
47
72
  };
48
73
  export declare namespace SolidStore {
49
74
  interface Unwrappable {
50
75
  }
51
76
  }
52
77
  export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
53
- export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
54
- export declare const storeLookup: WeakMap<WeakKey, any>;
55
- export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
78
+ /**
79
+ * Marks a value as raw: no store will ever wrap it — every store presents it
80
+ * as-is, tracked by reference at whatever slot holds it and updated by
81
+ * replacement. Useful for class instances and external objects (editors,
82
+ * scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
83
+ * for the value's lifetime.
84
+ */
85
+ export declare let rawValuesUsed: boolean;
86
+ export declare function isRawValue(value: any): boolean;
87
+ export declare function markRaw<T>(value: T): T;
88
+ export declare function markRawOne(v: any): void;
89
+ export declare function markRawIngest(container: any): void;
56
90
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
57
91
  export declare function setWriteOverride(value: boolean): void;
58
- export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
59
- export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
60
- export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
61
- export declare const storeTraps: ProxyHandler<StoreNode>;
62
- export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
92
+ export declare function getWriteOverride(): boolean;
93
+ export declare function ownEnumerableKeys(o: object): (string | symbol)[];
63
94
  /**
64
- * Creates a deeply-reactive store backed by a Proxy. Reads track each property
65
- * accessed; only the parts that change trigger updates.
66
- *
67
- * Store properties hold **plain values**, not accessors. The proxy already
68
- * tracks reads per-property — wrapping a value in `() => state.foo` produces
69
- * a getter that *won't* track when called, which looks like a reactivity bug
70
- * but is just a category error. If you have a signal-shaped piece of state,
71
- * make it a property of the store (`{ foo: 1 }`) rather than nesting an
72
- * accessor inside (`{ foo: () => signal() }`).
73
- *
74
- * The setter takes a **draft-mutating** function mutate the draft in place
75
- * (canonical). The callback may also return a new value: arrays are replaced
76
- * by index (length adjusted), objects are shallow-diffed at the top level
77
- * (keys present in the returned value are written, missing keys deleted). Use
78
- * the return form for shapes where mutation is awkward — most commonly
79
- * removing items via `filter`. The setter does **not** do keyed reconciliation;
80
- * for that, use the derived/projection form (or `createProjection`).
81
- *
82
- * - Plain form: `createStore(initialValue)` wraps a value in a reactive
83
- * proxy.
84
- * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
85
- * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
86
- * an `AsyncIterable`; the projection's result reconciles against the
87
- * existing store by `options.key` (default `"id"`) for stable identity.
88
- *
89
- * @example
90
- * ```ts
91
- * const [state, setState] = createStore({
92
- * user: { name: "Ada", age: 36 },
93
- * todos: [] as { id: string; text: string; done: boolean }[]
94
- * });
95
- *
96
- * // Canonical: mutate the draft in place.
97
- * setState(s => { s.user.age = 37; });
98
- * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
99
- *
100
- * // Return form: reach for it when mutation is awkward.
101
- * setState(s => s.todos.filter(t => !t.done)); // remove items
102
- * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
103
- * ```
95
+ * Scope inheritance for late-created nodes: every live mark whose identity
96
+ * scope contains the owning record's raw and, for keyed marks, whose key
97
+ * is this property — gets counted on the new node. Inherited marks live
98
+ * exactly as long as the scope's carrier the release hook below drops
99
+ * them with the entry.
100
+ */
101
+ export declare function inheritAffectsMarks(node: DataNode, raw: object, property: PropertyKey): void;
102
+ /** Next-store node factory for affects carriers/slots: injected by the
103
+ * rewrite module (next targets alias the legacy field names, so everything
104
+ * here EXCEPT node creation works on them structurally). */
105
+ export declare let nextAffectsNodeResolver: ((target: any, key: PropertyKey) => DataNode) | null;
106
+ export declare function setNextAffectsNodeResolver(fn: (target: any, key: PropertyKey) => DataNode): void;
107
+ /** Next-store optimistic view for the declaration walk (optimistic rows
108
+ * pushed before the declaration are in motion too legacy reads its write
109
+ * overlays; next composes armed-node overrides). */
110
+ export declare let nextOptimisticViewResolver: ((target: any, raw: any) => any) | null;
111
+ export declare function setNextOptimisticViewResolver(fn: (target: any, raw: any) => any): void;
112
+ /** @internal birth inheritance for nodes created inside a live mark window —
113
+ * exported for the rewrite's node factories. */
114
+ export declare function affectsScopesLive(): boolean;
115
+ /**
116
+ * Witness live mark coverage of a record into the active isPending() probe.
117
+ * Tracked reads don't need this they go through real signal nodes, which
118
+ * carry marks directly (declaration walk or birth inheritance). This covers
119
+ * UNTRACKED probes reading through records whose nodes never materialized
120
+ * (no observer ever subscribed, so no node exists to carry the mark).
121
+ * Callers guard on `pendingCheckActive`, so plain reads never pay for this.
104
122
  *
105
- * @example
106
- * ```ts
107
- * // Derived store auto-fetches & reconciles by `id`.
108
- * const [users] = createStore(
109
- * async () => fetch("/users").then(r => r.json()),
110
- * [] as User[]
111
- * );
112
- * ```
123
+ * @internal
124
+ */
125
+ export declare function witnessAffectsMark(target: StoreNode, property?: PropertyKey): void;
126
+ /**
127
+ * Resolves the store nodes an `affects()` declaration marks: with a `key`,
128
+ * the named slot's leaf node (upserted so the mark has an addressable
129
+ * carrier); without, the record's $AFFECTS carrier plus every LIVE node in
130
+ * its subtree (the edges existing readers subscribed through), with the
131
+ * subtree's identities snapshotted into the mark's scope so nodes created
132
+ * during the window — and untracked probes over captured proxies — resolve
133
+ * against it (#2882).
113
134
  *
114
- * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
135
+ * @internal
115
136
  */
116
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
117
- 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>];
137
+ export declare function getStoreAffectsNodes(target: StoreNode, key?: PropertyKey): DataNode[];
118
138
  export {};
@@ -1,43 +1,3 @@
1
- /**
2
- * Returns a plain (non-proxy, non-reactive) deep copy of a store value.
3
- * Reading via `snapshot` does **not** subscribe to changes — use this when you
4
- * need to hand a stable plain object to non-reactive code (logging,
5
- * serialization, structured-clone, network payloads, etc.).
6
- *
7
- * Returns the original object identity for any sub-tree that wasn't modified
8
- * relative to the proxy's underlying source.
9
- *
10
- * @example
11
- * ```ts
12
- * const [state] = createStore({ user: { name: "Ada" }, todos: [] });
13
- *
14
- * console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
15
- * ```
16
- */
17
- export declare function snapshot<T>(item: T): T;
18
- export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
19
- /**
20
- * Returns a plain (non-proxy) deep copy **and** subscribes the current
21
- * tracking scope to every nested change in the source store. Any write
22
- * anywhere in the subtree invalidates the consumer.
23
- *
24
- * Use this when you need plain data inside a reactive scope and want to
25
- * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
26
- * memo that should rerun on any nested change). For most read paths, prefer
27
- * direct property access — Solid stores already track per-property reads
28
- * with no `deep()` wrapper needed.
29
- *
30
- * @example
31
- * ```ts
32
- * const [state] = createStore({ a: { b: { c: 1 } } });
33
- *
34
- * createEffect(
35
- * () => deep(state), // reruns on any nested change
36
- * plain => sendToWorker(plain) // worker gets a non-proxy copy
37
- * );
38
- * ```
39
- */
40
- export declare function deep<T extends object>(store: T): T;
41
1
  type DistributeOverride<T, F> = T extends undefined ? F : T;
42
2
  type Override<T, U> = T extends any ? U extends any ? {
43
3
  [K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];