@solidjs/signals 2.0.0-rc.7 → 2.0.0-rc.9

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