@solidjs/signals 2.0.0-rc.1 → 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 (150) hide show
  1. package/dist/dev-shared.js +7138 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5691 -4491
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +793 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +849 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +280 -0
  11. package/dist/observe/core/attribution-hooks.js +83 -0
  12. package/dist/observe/core/attribution-queries.js +43 -0
  13. package/dist/observe/core/attribution.js +2904 -0
  14. package/dist/observe/core/constants.js +283 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1999 -0
  17. package/dist/observe/core/dev.js +343 -0
  18. package/dist/observe/core/effect.js +200 -0
  19. package/dist/observe/core/error-hooks.js +71 -0
  20. package/dist/observe/core/error.js +80 -0
  21. package/dist/observe/core/external.js +98 -0
  22. package/dist/observe/core/graph.js +155 -0
  23. package/dist/observe/core/heap.js +147 -0
  24. package/dist/observe/core/invariants.js +45 -0
  25. package/dist/observe/core/lanes.js +205 -0
  26. package/dist/observe/core/optimistic.js +627 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1547 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/observe/signals.js +731 -0
  33. package/dist/observe/store/index.js +44 -0
  34. package/dist/observe/store/next/optimistic.js +717 -0
  35. package/dist/observe/store/next/projection.js +266 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2480 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +331 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1070 -0
  42. package/dist/prod/affects.js +10 -9
  43. package/dist/prod/attribution.js +45 -0
  44. package/dist/prod/boundaries.js +388 -178
  45. package/dist/prod/core/action.js +65 -37
  46. package/dist/prod/core/async.js +378 -163
  47. package/dist/prod/core/attribution-hooks.js +3 -0
  48. package/dist/prod/core/constants.js +186 -1
  49. package/dist/prod/core/context.js +10 -16
  50. package/dist/prod/core/core.js +1546 -416
  51. package/dist/prod/core/dev.js +18 -1
  52. package/dist/prod/core/effect.js +119 -79
  53. package/dist/prod/core/error-hooks.js +71 -0
  54. package/dist/prod/core/error.js +13 -1
  55. package/dist/prod/core/external.js +4 -4
  56. package/dist/prod/core/graph.js +105 -54
  57. package/dist/prod/core/heap.js +72 -65
  58. package/dist/prod/core/invariants.js +3 -2
  59. package/dist/prod/core/lanes.js +117 -52
  60. package/dist/prod/core/optimistic.js +458 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +998 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +312 -151
  66. package/dist/prod/signals.js +363 -32
  67. package/dist/prod/store/index.js +2 -0
  68. package/dist/prod/store/next/optimistic.js +530 -197
  69. package/dist/prod/store/next/projection.js +142 -57
  70. package/dist/prod/store/next/reconcile.js +149 -103
  71. package/dist/prod/store/next/store.js +1470 -346
  72. package/dist/prod/store/next/target.js +40 -9
  73. package/dist/prod/store/store.js +23 -19
  74. package/dist/prod/store/utils.js +997 -130
  75. package/dist/types/attribution.d.ts +19 -0
  76. package/dist/types/attribution.prod.d.ts +22 -0
  77. package/dist/types/boundaries.d.ts +78 -5
  78. package/dist/types/core/action.d.ts +12 -5
  79. package/dist/types/core/async.d.ts +3 -1
  80. package/dist/types/core/attribution-costs.d.ts +35 -0
  81. package/dist/types/core/attribution-feedback.d.ts +133 -0
  82. package/dist/types/core/attribution-hooks.d.ts +304 -0
  83. package/dist/types/core/attribution-queries.d.ts +24 -0
  84. package/dist/types/core/attribution.d.ts +892 -0
  85. package/dist/types/core/constants.d.ts +179 -0
  86. package/dist/types/core/core.d.ts +299 -25
  87. package/dist/types/core/dev.d.ts +421 -8
  88. package/dist/types/core/effect.d.ts +8 -1
  89. package/dist/types/core/error-hooks.d.ts +71 -0
  90. package/dist/types/core/error.d.ts +9 -0
  91. package/dist/types/core/graph.d.ts +23 -0
  92. package/dist/types/core/heap.d.ts +5 -3
  93. package/dist/types/core/index.d.ts +6 -3
  94. package/dist/types/core/invariants.d.ts +5 -1
  95. package/dist/types/core/lanes.d.ts +51 -19
  96. package/dist/types/core/owner.d.ts +15 -3
  97. package/dist/types/core/scheduler.d.ts +248 -1
  98. package/dist/types/core/types.d.ts +124 -41
  99. package/dist/types/index.d.ts +18 -5
  100. package/dist/types/map.d.ts +2 -0
  101. package/dist/types/signals.d.ts +145 -13
  102. package/dist/types/store/index.d.ts +7 -6
  103. package/dist/types/store/next/optimistic.d.ts +18 -13
  104. package/dist/types/store/next/projection.d.ts +5 -2
  105. package/dist/types/store/next/reconcile.d.ts +7 -0
  106. package/dist/types/store/next/store.d.ts +83 -11
  107. package/dist/types/store/next/target.d.ts +108 -11
  108. package/dist/types/store/store.d.ts +20 -11
  109. package/dist/types/store/utils.d.ts +188 -0
  110. package/package.json +31 -26
  111. package/dist/node.cjs +0 -8137
  112. package/dist/types/store/optimistic.d.ts +0 -45
  113. package/dist/types/store/projection.d.ts +0 -70
  114. package/dist/types/store/reconcile.d.ts +0 -46
  115. package/dist/types-cjs/affects.d.cts +0 -47
  116. package/dist/types-cjs/boundaries.d.cts +0 -175
  117. package/dist/types-cjs/core/action.d.cts +0 -64
  118. package/dist/types-cjs/core/async.d.cts +0 -21
  119. package/dist/types-cjs/core/constants.d.cts +0 -71
  120. package/dist/types-cjs/core/core.d.cts +0 -156
  121. package/dist/types-cjs/core/dev.d.cts +0 -64
  122. package/dist/types-cjs/core/effect.d.cts +0 -30
  123. package/dist/types-cjs/core/error.d.cts +0 -47
  124. package/dist/types-cjs/core/external.d.cts +0 -15
  125. package/dist/types-cjs/core/graph.d.cts +0 -5
  126. package/dist/types-cjs/core/heap.d.cts +0 -22
  127. package/dist/types-cjs/core/index.d.cts +0 -13
  128. package/dist/types-cjs/core/invariants.d.cts +0 -59
  129. package/dist/types-cjs/core/lanes.d.cts +0 -56
  130. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  131. package/dist/types-cjs/core/owner.d.cts +0 -124
  132. package/dist/types-cjs/core/scheduler.d.cts +0 -172
  133. package/dist/types-cjs/core/types.d.cts +0 -148
  134. package/dist/types-cjs/core/verdict.d.cts +0 -2
  135. package/dist/types-cjs/index.d.cts +0 -10
  136. package/dist/types-cjs/map.d.cts +0 -69
  137. package/dist/types-cjs/package.json +0 -3
  138. package/dist/types-cjs/signals.d.cts +0 -624
  139. package/dist/types-cjs/store/index.d.cts +0 -19
  140. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  141. package/dist/types-cjs/store/next/projection.d.cts +0 -24
  142. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  143. package/dist/types-cjs/store/next/store.d.cts +0 -71
  144. package/dist/types-cjs/store/next/target.d.cts +0 -99
  145. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  146. package/dist/types-cjs/store/projection.d.cts +0 -70
  147. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  148. package/dist/types-cjs/store/store.d.cts +0 -138
  149. package/dist/types-cjs/store/storePath.d.cts +0 -58
  150. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Ownership stamp (#3360): every backing the store ALLOCATES (CoW clones,
3
+ * privatized committed backings) carries its owning target under this
4
+ * enumerable symbol. One property write replaces the two weak-collection
5
+ * registrations (ownership set + raw→target map) a fresh object used to pay
6
+ * per draft — V8's identity-hash + ephemeron cost dominated the one-key
7
+ * write floor. Enumerable so a spread copy (the plain-data clone path) stays
8
+ * on the fast path and carries the stamp along.
9
+ *
10
+ * Owned backings are never user-reachable (`snapshot` copies them, the traps
11
+ * hide the key), so every raw key walk in the store must skip `$OWNER`, and
12
+ * ownership is answered by `isOwned` — a user object never carries it.
13
+ * Overlay drafts (`Object.create(v)` over an owned `v`) inherit the stamp.
14
+ */
15
+ const $OWNER = Symbol(0);
16
+
17
+ /** raw → target for UNOWNED backings (user-ingested, adopted); owned
18
+ * backings resolve through their `$OWNER` stamp. Boundary mechanism (O8). */ const storeNextLookup = new WeakMap;
19
+
20
+ /** A backing the store allocated and may mutate in place. */ function isOwned(e) {
21
+ return e[$OWNER] !== undefined;
22
+ }
23
+
24
+ /** raw → target within a family (`null` = plain stores / the global map).
25
+ * The stamp answers for backings owned by a target OF THAT FAMILY; anything
26
+ * else (user objects, adoptees, another family's backings the family
27
+ * re-registered for its own wrapper) resolves through the family's map. */ function lookupTarget(e, o) {
28
+ const t = e[$OWNER];
29
+ return t !== undefined && t.fam === o ? t : (o?.map ?? storeNextLookup).get(e);
30
+ }
31
+
32
+ function devAssertNeverUserMutation(e) {
33
+ return;
34
+ }
35
+
36
+ let optHooks = null;
37
+
38
+ function setOptHooks(e) {
39
+ optHooks = e;
40
+ }
41
+
42
+ /** Sticky descendants flag walk (§6d): reconcile's keyed pruning descends
43
+ * only where subscriptions exist at/below. Nodes AND patches count. */ function markDescendants(e) {
44
+ let o = e;
45
+ while (o && !o.d) {
46
+ o.d = true;
47
+ o = o.u;
48
+ }
49
+ }
50
+
51
+ export { $OWNER, devAssertNeverUserMutation, isOwned, lookupTarget, markDescendants, optHooks, setOptHooks, storeNextLookup };
@@ -0,0 +1,331 @@
1
+ import "../core/core.js";
2
+
3
+ import "../core/dev.js";
4
+
5
+ import { GlobalQueue } from "../core/scheduler.js";
6
+
7
+ import "../core/invariants.js";
8
+
9
+ import "../core/verdict.js";
10
+
11
+ import "../core/effect.js";
12
+
13
+ import { $OWNER, lookupTarget as lookupTarget$1 } from "./next/target.js";
14
+
15
+ /**
16
+ * Brand symbols used internally by the store proxy / projection plumbing.
17
+ * Cross-package wiring; not part of the user-facing API.
18
+ *
19
+ * @internal
20
+ */ const $TRACK = Symbol(0), $TARGET = Symbol(0), $PROXY = Symbol(0),
21
+ // The view record behind a merge()/omit() proxy (a `MergeView` or an
22
+ // `OmitView`, utils.ts); a store answers `undefined` on its symbol fast
23
+ // path. One read classifies any `$PROXY`-marked object — store, view, or
24
+ // foreign — where asking `$TARGET` first and then each view kind was two
25
+ // to four trap hops (see `viewOf`).
26
+ $RECORD = Symbol(0), // Node-map slot carrying a record-level `affects()` mark: any read through
27
+ // the record witnesses it into the active isPending() probe.
28
+ $AFFECTS = Symbol(0);
29
+
30
+ // Structural field names of store targets (StoreNextTarget aliases these, so
31
+ // shared machinery — affects walks, tests — reads targets via the consts).
32
+ const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h";
33
+
34
+ function lookupTarget(e, t) {
35
+ // Family registrations (projections/optimistic) first, then the global
36
+ // next lookup. Proxies resolve through $TARGET directly.
37
+ return (t ? lookupTarget$1(e, t) : undefined) ?? lookupTarget$1(e, null);
38
+ }
39
+
40
+ // Values marked raw never acquire a proxy identity: wrap() serves them as-is
41
+ // everywhere — deep stores hold them as leaf values replaced by reference.
42
+ // Once raw, always raw (identity stays single, just unwrapped). Consulted
43
+ // only on wrap-creation and ingest paths; reads never touch it.
44
+ const rawValues = new WeakSet;
45
+
46
+ /**
47
+ * Marks a value as raw: no store will ever wrap it — every store presents it
48
+ * as-is, tracked by reference at whatever slot holds it and updated by
49
+ * replacement. Useful for class instances and external objects (editors,
50
+ * scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
51
+ * for the value's lifetime.
52
+ */
53
+ // Flipped on the first mark and exported as a LIVE binding: reconcile
54
+ // consults it on every recursable pair, and importing the boolean directly
55
+ // lets those sites skip even the function call when no shallow store or raw
56
+ // mark exists anywhere in the app.
57
+ let rawValuesUsed = false;
58
+
59
+ function isRawValue(e) {
60
+ return rawValuesUsed && rawValues.has(e);
61
+ }
62
+
63
+ function markRawOne(e) {
64
+ if (isWrappable(e)) {
65
+ // A store proxy is already tracked elsewhere: the shallow boundary passes
66
+ // it through by reference (replaced, never edited — same slot semantics
67
+ // as a raw) instead of claiming it raw. The sticky mark is global, so
68
+ // marking a live proxy would make wrap() serve it verbatim through every
69
+ // OTHER store too — downstream deep stores then captured it instead of
70
+ // wrapping it in their own family, and their writes landed in the
71
+ // upstream store's override layer (#2932).
72
+ if (e[$TARGET] !== undefined) return;
73
+ rawValuesUsed = true;
74
+ rawValues.add(e);
75
+ }
76
+ }
77
+
78
+ function markRawIngest(e) {
79
+ if (Array.isArray(e)) {
80
+ for (let t = 0, o = e.length; t < o; t++) markRawOne(e[t]);
81
+ } else {
82
+ for (const t in e) markRawOne(e[t]);
83
+ }
84
+ }
85
+
86
+ const OBJECT_PROTO = Object.prototype;
87
+
88
+ // Per-prototype memo for the custom-proto branch of isWrappable: the verdict
89
+ // is fully determined by the prototype (tag and Node lineage both live on
90
+ // the chain), so each class pays the tag call once — not per read.
91
+ const wrappableProtos = new WeakMap;
92
+
93
+ function isWrappable(e) {
94
+ if (e == null || typeof e !== "object" || Object.isFrozen(e)) return false;
95
+ // Plain data and user class instances wrap; platform objects never do
96
+ // (#2952). Native code brand-checks internal slots and throws through a
97
+ // proxy (`Map.prototype.size`, `Date.prototype.getTime`, ...), so
98
+ // collections and other built-ins can't honestly be stores — they get the
99
+ // markRaw-children contract automatically: served raw, mutations land raw,
100
+ // the property holding them still tracks (reassignment notifies). The tag
101
+ // check separates them structurally: user classes stringify as
102
+ // `[object Object]` while every native/host object carries its own brand
103
+ // (`[object Map]`, `[object Date]`, `[object Headers]`, ...), including
104
+ // subclasses, which inherit the tag. getPrototypeOf keeps the hot path
105
+ // (plain and null-proto objects) intrinsic-only — no property lookup.
106
+ const t = Object.getPrototypeOf(e);
107
+ if (t === OBJECT_PROTO || t === null) return true;
108
+ if (Array.isArray(e)) return true;
109
+ let o = wrappableProtos.get(t);
110
+ if (o === undefined) {
111
+ o = Object.prototype.toString.call(e) === "[object Object]" && (
112
+ // Dynamic Node check (kept dynamic so test/SSR overrides of
113
+ // `globalThis.Node` are observed at call time): shimmed DOMs implement
114
+ // nodes as plain user classes, which pass the tag check.
115
+ typeof Node === "undefined" || !(e instanceof Node));
116
+ wrappableProtos.set(t, o);
117
+ }
118
+ return o;
119
+ }
120
+
121
+ let writeOverride = false;
122
+
123
+ function setWriteOverride(e) {
124
+ writeOverride = e;
125
+ }
126
+
127
+ function getWriteOverride() {
128
+ return writeOverride;
129
+ }
130
+
131
+ // Own enumerable keys including symbols (`Object.keys` drops symbol-keyed props). #2769
132
+ function ownEnumerableKeys(e) {
133
+ return Reflect.ownKeys(e).filter(t => Object.prototype.propertyIsEnumerable.call(e, t));
134
+ }
135
+
136
+ /**
137
+ * Scope inheritance for late-created nodes: every live mark whose identity
138
+ * scope contains the owning record's raw — and, for keyed marks, whose key
139
+ * is this property — gets counted on the new node. Inherited marks live
140
+ * exactly as long as the scope's carrier — the release hook below drops
141
+ * them with the entry.
142
+ */ function inheritAffectsMarks(e, t, o) {
143
+ // A live scope exists, so affects.ts already installed the mark engine.
144
+ for (const [r, s] of affectsScopes) {
145
+ if (r.o?.t && s.scope.has(t) && (s.key === undefined || s.key === o)) {
146
+ GlobalQueue.M(e);
147
+ s.inherited.push(e);
148
+ }
149
+ }
150
+ }
151
+
152
+ const affectsScopes = new Map;
153
+
154
+ /** Next-store node factory for affects carriers/slots: injected by the
155
+ * rewrite module (next targets alias the legacy field names, so everything
156
+ * here EXCEPT node creation works on them structurally). */ let nextAffectsNodeResolver = null;
157
+
158
+ function setNextAffectsNodeResolver(e) {
159
+ nextAffectsNodeResolver = e;
160
+ }
161
+
162
+ /** Next-store optimistic view for the declaration walk (optimistic rows
163
+ * pushed before the declaration are in motion too — legacy reads its write
164
+ * overlays; next composes armed-node overrides). */ let nextOptimisticViewResolver = null;
165
+
166
+ function setNextOptimisticViewResolver(e) {
167
+ nextOptimisticViewResolver = e;
168
+ }
169
+
170
+ /** @internal birth inheritance for nodes created inside a live mark window —
171
+ * exported for the rewrite's node factories. */ function affectsScopesLive() {
172
+ return affectsScopes.size > 0;
173
+ }
174
+
175
+ /**
176
+ * Snapshots the identities reachable from `value` into `scope`, reading
177
+ * through write overlays (an optimistic row pushed before the declaration is
178
+ * in motion too). Untracked by construction: walks raw values, never traps.
179
+ * Every LIVE node under each reachable record — property leaves, `$TRACK`,
180
+ * and has-nodes — collects into `found`: those are the graph edges existing
181
+ * readers subscribed through, so the mark registers on them directly and
182
+ * rides the status rails to everything derived. (Nodes born later inherit
183
+ * from the scope in `getNode`.)
184
+ */ function walkAffectsScope(e, t, o, r,
185
+ // Cycle guard, fresh per declaration: the scope itself can't serve — a
186
+ // re-declaration on the same carrier unions into a scope that already
187
+ // holds the root, and must still descend to pick up records added since.
188
+ s) {
189
+ if (!isWrappable(e)) return;
190
+ const f = e[$TARGET] || lookupTarget(e, r);
191
+ // Next targets: walk the pending backing when present (a draft's writes are
192
+ // in motion too) and cover BOTH identities in the scope.
193
+ let n = f ? f.pb ?? f[STORE_VALUE] : e;
194
+ if (s.has(n)) return;
195
+ s.add(n);
196
+ t.scope.add(n);
197
+ if (f && f.pb) t.scope.add(f[STORE_VALUE]);
198
+ // Next optimistic families: enumerate the VISIBLE view (armed-node
199
+ // overrides compose membership/values the raw doesn't carry).
200
+ if (f && f.fam?.opt && nextOptimisticViewResolver) n = nextOptimisticViewResolver(f, n);
201
+ if (f) {
202
+ collectRecordNodes(f[STORE_NODE], o);
203
+ collectRecordNodes(f[STORE_HAS], o);
204
+ // The key-set and deep-witness nodes are record-level channels: a deep()
205
+ // probe reads ONLY these (one pair per record), so a declared affects
206
+ // scope must mark them like any property node.
207
+ if (f.k) o.push(f.k);
208
+ if (f.dk) o.push(f.dk);
209
+ // Carry the effective family into untouched descendants (projections/
210
+ // optimistic stores register children under their family).
211
+ r = f.fam ?? r;
212
+ }
213
+ // Overlays are gone (next has no layer): raw enumeration; the optimistic
214
+ // view composition above already folded armed-node membership/values in.
215
+ if (Array.isArray(n)) {
216
+ for (let e = 0, f = n.length; e < f; e++) {
217
+ walkAffectsScope(n[e], t, o, r, s);
218
+ }
219
+ const e = Object.getOwnPropertySymbols(n);
220
+ for (let f = 0, c = e.length; f < c; f++) {
221
+ if (e[f] === $OWNER) continue;
222
+ const c = Object.getOwnPropertyDescriptor(n, e[f]);
223
+ if (!c || c.get) continue;
224
+ walkAffectsScope(c.value, t, o, r, s);
225
+ }
226
+ } else {
227
+ const e = Reflect.ownKeys(n);
228
+ for (let f = 0, c = e.length; f < c; f++) {
229
+ if (e[f] === $OWNER) continue;
230
+ const c = Object.getOwnPropertyDescriptor(n, e[f]);
231
+ if (!c || c.get) continue;
232
+ walkAffectsScope(c.value, t, o, r, s);
233
+ }
234
+ }
235
+ }
236
+
237
+ /** All live signal nodes of one record's node map (string + symbol keyed). */ function collectRecordNodes(e, t) {
238
+ if (!e) return;
239
+ for (const o of Object.keys(e)) t.push(e[o]);
240
+ const o = Object.getOwnPropertySymbols(e);
241
+ for (let r = 0, s = o.length; r < s; r++) {
242
+ // Another mark's carrier is its own channel — counting it here would
243
+ // extend that sibling scope's lifetime to this declaration's.
244
+ if (o[r] !== $AFFECTS) t.push(e[o[r]]);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Witness live mark coverage of a record into the active isPending() probe.
250
+ * Tracked reads don't need this — they go through real signal nodes, which
251
+ * carry marks directly (declaration walk or birth inheritance). This covers
252
+ * UNTRACKED probes reading through records whose nodes never materialized
253
+ * (no observer ever subscribed, so no node exists to carry the mark).
254
+ * Callers guard on `pendingCheckActive`, so plain reads never pay for this.
255
+ *
256
+ * @internal
257
+ */ function witnessAffectsMark(e, t) {
258
+ // Callers guard on `pendingCheckActive`, which only flips inside
259
+ // isPending() — the verdict layer is loaded and its hook installed.
260
+ const o = e[STORE_NODE]?.[$AFFECTS];
261
+ if (o?.o?.t) GlobalQueue.ri(o);
262
+ if (affectsScopes.size) {
263
+ // Chained backings (§7b): a wrapper's STORE_VALUE can be another store's
264
+ // proxy — marks cover by identity of the BASE raw, so resolve the chain
265
+ // and check every identity along it.
266
+ let r = e[STORE_VALUE];
267
+ for (const [e, s] of affectsScopes) {
268
+ if (e !== o && e.o?.t && (s.key === undefined || s.key === t)) {
269
+ let t = r;
270
+ for (;;) {
271
+ if (s.scope.has(t)) {
272
+ GlobalQueue.ri(e);
273
+ break;
274
+ }
275
+ const o = t?.[$TARGET];
276
+ if (o === undefined) break;
277
+ const r = o.pb ?? o[STORE_VALUE];
278
+ if (r === t) break;
279
+ t = r;
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Resolves the store nodes an `affects()` declaration marks: with a `key`,
288
+ * the named slot's leaf node (upserted so the mark has an addressable
289
+ * carrier); without, the record's $AFFECTS carrier plus every LIVE node in
290
+ * its subtree (the edges existing readers subscribed through), with the
291
+ * subtree's identities snapshotted into the mark's scope so nodes created
292
+ * during the window — and untracked probes over captured proxies — resolve
293
+ * against it (#2882).
294
+ *
295
+ * @internal
296
+ */ function getStoreAffectsNodes(e, t) {
297
+ GlobalQueue.p ||= e => {
298
+ const t = affectsScopes.get(e);
299
+ if (!t) return;
300
+ affectsScopes.delete(e);
301
+ for (let e = 0; e < t.inherited.length; e++) GlobalQueue.j(t.inherited[e]);
302
+ };
303
+ if (t === undefined) {
304
+ const t = nextAffectsNodeResolver(e, $AFFECTS);
305
+ let o = affectsScopes.get(t);
306
+ if (!o) affectsScopes.set(t, o = {
307
+ scope: new Set,
308
+ inherited: []
309
+ });
310
+ const r = [ t ];
311
+ walkAffectsScope(e[$PROXY], o, r, e.fam, new Set);
312
+ return r;
313
+ }
314
+ const o = e.n?.[t] ?? nextAffectsNodeResolver(e, t);
315
+ // Keyed marks resolve by identity too (#2904): another store family's
316
+ // proxy can share this record's raw (a derived store swaps its backing to
317
+ // the source's raw when its projection lands), and reads through it never
318
+ // touch this target's node map. Scope is exactly the owning record's raw,
319
+ // narrowed to this key for witness and birth inheritance.
320
+ let r = affectsScopes.get(o);
321
+ if (!r) affectsScopes.set(o, r = {
322
+ scope: new Set,
323
+ inherited: [],
324
+ key: t
325
+ });
326
+ r.scope.add(e[STORE_VALUE]);
327
+ if (e.pb) r.scope.add(e.pb);
328
+ return [ o ];
329
+ }
330
+
331
+ export { $AFFECTS, $PROXY, $RECORD, $TARGET, $TRACK, STORE_HAS, STORE_NODE, STORE_VALUE, affectsScopesLive, getStoreAffectsNodes, getWriteOverride, inheritAffectsMarks, isRawValue, isWrappable, markRawIngest, markRawOne, nextAffectsNodeResolver, nextOptimisticViewResolver, ownEnumerableKeys, rawValuesUsed, setNextAffectsNodeResolver, setNextOptimisticViewResolver, setWriteOverride, witnessAffectsMark };
@@ -0,0 +1,103 @@
1
+ import { isWrappable, ownEnumerableKeys } from "./store.js";
2
+
3
+ const DELETE = Symbol(0);
4
+
5
+ function isPrototypePollutionKey(t) {
6
+ return t === "__proto__" || t === "constructor" || t === "prototype";
7
+ }
8
+
9
+ function updatePath(t, e, o = 0) {
10
+ let r, n = t;
11
+ if (o < e.length - 1) {
12
+ r = e[o];
13
+ const i = typeof r;
14
+ const f = Array.isArray(t);
15
+ if (i === "string" && isPrototypePollutionKey(r)) return;
16
+ if (Array.isArray(r)) {
17
+ for (let n = 0; n < r.length; n++) {
18
+ e[o] = r[n];
19
+ updatePath(t, e, o);
20
+ }
21
+ e[o] = r;
22
+ return;
23
+ } else if (f && i === "function") {
24
+ for (let n = 0; n < t.length; n++) {
25
+ if (r(t[n], n)) {
26
+ e[o] = n;
27
+ updatePath(t, e, o);
28
+ }
29
+ }
30
+ e[o] = r;
31
+ return;
32
+ } else if (f && i === "object") {
33
+ const {from: n = 0, to: i = t.length - 1, by: f = 1} = r;
34
+ for (let r = n; r <= i; r += f) {
35
+ e[o] = r;
36
+ updatePath(t, e, o);
37
+ }
38
+ e[o] = r;
39
+ return;
40
+ } else if (o < e.length - 2) {
41
+ updatePath(t[r], e, o + 1);
42
+ return;
43
+ }
44
+ n = t[r];
45
+ }
46
+ let i = e[e.length - 1];
47
+ if (typeof i === "function") {
48
+ i = i(n);
49
+ if (i === n) return;
50
+ }
51
+ if (r === undefined && i == undefined) return;
52
+ if (i === DELETE) {
53
+ delete t[r];
54
+ } else if (r === undefined || isWrappable(n) && isWrappable(i) && !Array.isArray(i)) {
55
+ const e = r !== undefined ? t[r] : t;
56
+ const o = ownEnumerableKeys(i);
57
+ for (let t = 0; t < o.length; t++) {
58
+ const r = o[t];
59
+ if (typeof r === "string" && isPrototypePollutionKey(r)) continue;
60
+ const n = Object.getOwnPropertyDescriptor(i, r);
61
+ if (n.get || n.set) Object.defineProperty(e, r, n); else e[r] = n.value;
62
+ }
63
+ } else {
64
+ t[r] = i;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
70
+ * to produce a draft-mutating function suitable for passing to `setStore`.
71
+ *
72
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
73
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
74
+ * compatibility helper for users porting from Solid 1.x's
75
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
76
+ * two styles freely.
77
+ *
78
+ * Path parts can be:
79
+ * - a single key — `"user"`, `0`
80
+ * - an array of keys — `[0, 1, 2]`
81
+ * - a range over an array — `{ from?, to?, by? }`
82
+ * - a filter `(item, index) => boolean` for arrays
83
+ *
84
+ * The final argument is the new value or an updater `(prev) => next`. Use
85
+ * `storePath.DELETE` to remove a property.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
90
+ *
91
+ * setState(storePath("user", "name", "Grace"));
92
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
93
+ * setState(storePath("user", "nickname", storePath.DELETE));
94
+ * ```
95
+ */ const storePath = /* @__PURE__ */ Object.assign(function storePath(...t) {
96
+ return e => {
97
+ updatePath(e, t);
98
+ };
99
+ }, {
100
+ DELETE: DELETE
101
+ });
102
+
103
+ export { storePath };