@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,4 +1,4 @@
1
- import type { Disposable } from "./core/index.js";
1
+ import type { Disposable, Refreshable } from "./core/index.js";
2
2
  /**
3
3
  * Low-level reactive-cleanup primitive. Registers a callback that runs when
4
4
  * the surrounding owner is disposed.
@@ -25,6 +25,18 @@ import type { Disposable } from "./core/index.js";
25
25
  *
26
26
  * Cannot be used inside `createTrackedEffect` or `onSettled` — return a
27
27
  * cleanup function from the callback body instead.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Library shape: thread a resource's disposal into a *captured* owner
32
+ * // from a factory that has no settle-phase setup of its own. `onSettled`
33
+ * // would queue a callback we don't need; `onCleanup` is the leaner
34
+ * // primitive when the only job is "register disposal on this owner".
35
+ * function bindToOwner<T extends { dispose(): void }>(owner: Owner, resource: T): T {
36
+ * runWithOwner(owner, () => onCleanup(() => resource.dispose()));
37
+ * return resource;
38
+ * }
39
+ * ```
28
40
  */
29
41
  export declare function onCleanup(fn: Disposable): Disposable;
30
42
  /**
@@ -35,7 +47,8 @@ export declare function onCleanup(fn: Disposable): Disposable;
35
47
  * creating a subscription.
36
48
  */
37
49
  export type Accessor<T> = () => T;
38
- export declare function accessor<T>(node: any): Accessor<T>;
50
+ export type SourceAccessor<T> = Refreshable<Accessor<T>>;
51
+ export declare function accessor<T>(node: any): SourceAccessor<T>;
39
52
  /**
40
53
  * A signal setter. Accepts either a new value or an updater `(prev) => next`.
41
54
  *
@@ -51,11 +64,22 @@ export type Setter<in out T> = {
51
64
  <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
52
65
  };
53
66
  /** A `[get, set]` pair returned from `createSignal` / `createOptimistic`. */
54
- export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
67
+ export type Signal<T> = [get: SourceAccessor<T>, set: Setter<T>];
55
68
  export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => PromiseLike<Next> | AsyncIterable<Next> | Next;
56
69
  export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
57
70
  export type EffectBundle<Prev, Next extends Prev = Prev> = {
58
71
  effect: EffectFunction<Prev, Next>;
72
+ /**
73
+ * Intercepts compute-phase errors (thrown by the compute function or arriving
74
+ * from upstream sources). Effect-phase throws are NOT routed here — they are
75
+ * your own imperative code and escalate to the nearest error boundary.
76
+ *
77
+ * This is the error arm of the effect phase: it runs on the same queue and
78
+ * in the same imperative, writable scope as `effect` (signal writes are
79
+ * legal), receives the error the user code threw, and observes settled
80
+ * outcomes — an error that recovers before the effect phase runs the
81
+ * `effect` arm instead, and a held transition defers it like `effect`.
82
+ */
59
83
  error: (err: unknown, cleanup: () => void) => void;
60
84
  };
61
85
  /** Options shared by every effect primitive. */
@@ -77,12 +101,49 @@ export interface EffectOptions extends BaseEffectOptions {
77
101
  * `insert()` in `render()`).
78
102
  */
79
103
  schedule?: boolean;
104
+ /**
105
+ * Advanced. When true, asserts the compute function returns synchronous
106
+ * values only (never `PromiseLike` / `AsyncIterable`). Skips the
107
+ * async-shape probe in `recompute` for a small fixed-cost win per run.
108
+ * Intended for compiler emissions (`_$effect`) and library code that
109
+ * provably returns sync values. Returning a Promise or async iterable
110
+ * from a `sync: true` effect is undefined behavior — the value will be
111
+ * stored as-is and never awaited.
112
+ */
113
+ sync?: boolean;
114
+ /**
115
+ * Advanced (integration tier). When true, the effect is invisible to the
116
+ * hydration id scheme: it inherits its parent's id instead of consuming a
117
+ * child slot, and during hydration its compute runs live instead of
118
+ * adopting the serialized server value (its first run is not frozen to
119
+ * the server's decision).
120
+ *
121
+ * For **client-only effects created while hydrating** — effects with no
122
+ * server-rendered counterpart (a router wiring link state, scroll
123
+ * restoration, etc.). An id-consuming node the server never created would
124
+ * shift every later sibling's hydration id, making serialized lookups and
125
+ * template claims after it miss. `transparent` is also the supported
126
+ * alternative to branching on hydration state
127
+ * (`if (hydrating) createEffect(...)`), which freezes whatever the first
128
+ * run decided: create the effect unconditionally and let it observe live
129
+ * state instead.
130
+ *
131
+ * SSR ignores this option (a server-side effect always allocates its id
132
+ * slot), so only mark effects the server does not create. Outside
133
+ * hydration it is a no-op.
134
+ */
135
+ transparent?: boolean;
80
136
  }
81
137
  /** Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`. */
82
138
  export interface SignalOptions<T> {
83
139
  /** Debug name (dev mode only) */
84
140
  name?: string;
85
- /** Custom equality function, or `false` to always notify subscribers */
141
+ /**
142
+ * Custom equality function, or `false` to always notify subscribers.
143
+ * Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
144
+ * `(a, b) => a.id === b.id`) for value-based equality, or `false` to
145
+ * notify on every write regardless of equality.
146
+ */
86
147
  equals?: false | ((prev: T, next: T) => boolean);
87
148
  /** Suppress dev-mode warnings when writing inside an owned scope */
88
149
  ownedWrite?: boolean;
@@ -99,9 +160,21 @@ export interface MemoOptions<T> {
99
160
  id?: string;
100
161
  /** Debug name (dev mode only) */
101
162
  name?: string;
102
- /** When true, the owner is invisible to the ID scheme -- inherits parent ID and doesn't consume a childCount slot */
163
+ /**
164
+ * Advanced (integration tier). When true, the memo is invisible to the
165
+ * hydration id scheme: it inherits its parent's id instead of consuming a
166
+ * child slot, and during hydration it computes live instead of adopting
167
+ * the serialized server value. For client-only memos with no
168
+ * server-rendered counterpart — see {@link EffectOptions.transparent} for
169
+ * the full semantics. No-op outside hydration.
170
+ */
103
171
  transparent?: boolean;
104
- /** Custom equality function, or `false` to always notify subscribers */
172
+ /**
173
+ * Custom equality function, or `false` to always notify subscribers.
174
+ * Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
175
+ * `(a, b) => a.id === b.id`) for value-based equality, or `false` to
176
+ * notify on every recompute regardless of equality.
177
+ */
105
178
  equals?: false | ((prev: T, next: T) => boolean);
106
179
  /** Callback invoked when the computed loses all subscribers */
107
180
  unobserved?: () => void;
@@ -114,6 +187,40 @@ export interface MemoOptions<T> {
114
187
  * never autodispose.
115
188
  */
116
189
  lazy?: boolean;
190
+ /**
191
+ * Advanced. When true, asserts the compute function returns synchronous
192
+ * values only (never `PromiseLike` / `AsyncIterable`). Skips the
193
+ * async-shape probe in `recompute` for a small fixed-cost win per run.
194
+ * Intended for compiler emissions (`_$memo`) and library code that
195
+ * provably returns sync values. Returning a Promise or async iterable
196
+ * from a `sync: true` memo is undefined behavior — the value will be
197
+ * stored as-is and never awaited.
198
+ */
199
+ sync?: boolean;
200
+ /**
201
+ * Commit #0: a committed value the memo is born with, shown until the
202
+ * compute's first real answer lands. While that first answer is in flight
203
+ * the memo reads as a settled value everywhere — nothing suspends to a
204
+ * `<Loading>` boundary, no transition is held (first-flight work is
205
+ * loading-class, like a boundary fallback), and `isPending(memo)` stays
206
+ * **false**: commit #0 answers the question by declaration, so first-load
207
+ * affordances are driven from the value itself (a `null` placeholder, a
208
+ * `skeleton: true` field, etc.). Once the first answer lands, the loading
209
+ * value leaves the lineage forever: refetches use normal pending semantics
210
+ * (stale value shown, `isPending` true, boundaries/transitions coordinate)
211
+ * — the canonical guard is `data.skeleton || isPending(data)`, whose two
212
+ * terms cover the two disjoint states.
213
+ *
214
+ * Typed strictly as `T`: to use `null`/`undefined` as the placeholder,
215
+ * declare it in the memo's type (e.g. `createMemo<User | null>(...)`), so
216
+ * every consumer sees the nullable window honestly. If the placeholder is
217
+ * shaped data standing in for real data, encode its provenance in the data
218
+ * (e.g. a `skeleton: true` field) rather than letting it impersonate truth.
219
+ *
220
+ * The loading value is also the compute's first `prev`, so `prev`-based
221
+ * memos fold from it.
222
+ */
223
+ loadingValue?: T;
117
224
  }
118
225
  export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
119
226
  /**
@@ -162,7 +269,7 @@ export declare function createSignal<T>(fn: ComputeFunction<T>, options?: Signal
162
269
  * const value = createMemo<T>(compute, options?: MemoOptions<T>);
163
270
  * ```
164
271
  * @param compute a function that receives its previous value and returns a new value used to react on a computation
165
- * @param options `MemoOptions` -- id, name, equals, unobserved, lazy
272
+ * @param options `MemoOptions` -- id, name, equals, unobserved, lazy, transparent
166
273
  *
167
274
  * @example
168
275
  * ```ts
@@ -185,7 +292,10 @@ export declare function createSignal<T>(fn: ComputeFunction<T>, options?: Signal
185
292
  *
186
293
  * @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
187
294
  */
188
- export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, options?: MemoOptions<T>): Accessor<T>;
295
+ export declare function createMemo<T>(compute: ComputeFunction<NoInfer<T>, T>, options: MemoOptions<T> & {
296
+ loadingValue: T;
297
+ }): SourceAccessor<T>;
298
+ export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, options?: MemoOptions<T>): SourceAccessor<T>;
189
299
  /**
190
300
  * Creates a reactive effect with **separate compute and effect phases**.
191
301
  *
@@ -202,14 +312,31 @@ export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInf
202
312
  * `createTrackedEffect` (with the tradeoffs noted there).
203
313
  *
204
314
  * Pass an `EffectBundle` (`{ effect, error }`) instead of a plain function to
205
- * intercept errors thrown from the compute or effect phases.
315
+ * intercept **compute-phase** errors — errors thrown by `compute` or arriving
316
+ * from upstream reactive sources (including async rejections), which your own
317
+ * code has no frame to `try/catch`. The `error` handler is the error arm of
318
+ * the effect phase: it runs on the same schedule and in the same imperative,
319
+ * writable scope as `effect` (setting error state via signals is fine), and
320
+ * only for *settled* errors — a transient error that recovers before the
321
+ * effect phase runs `effect` with the recovered value instead, and a held
322
+ * transition defers it exactly as it defers `effect`. Without an `error`
323
+ * handler a compute-phase error is logged and the effect simply skips that
324
+ * run — a non-render effect's reactivity failing does not crash the app.
325
+ * Rethrowing from `error` escalates it to the nearest error boundary
326
+ * (halting the system if none exists).
327
+ *
328
+ * The **effect phase is different**: it is your own imperative code, so handle
329
+ * failures with `try/catch` where they occur. An uncaught effect-phase throw
330
+ * is treated as an unhandled application error — caught by the nearest
331
+ * `createErrorBoundary`/`<Errored>`, and permanently halting the reactive
332
+ * system if there is none. It is *not* routed to the bundle's `error` handler.
206
333
  *
207
334
  * ```typescript
208
335
  * createEffect<T>(compute, effectFn | { effect, error }, options?: EffectOptions);
209
336
  * ```
210
337
  * @param compute a function that receives its previous value and returns a new value used to react on a computation
211
338
  * @param effectFn a function that receives the new value and is used to perform side effects (return a cleanup function), or an `EffectBundle` with `effect` and `error` handlers
212
- * @param options `EffectOptions` -- name, defer, schedule
339
+ * @param options `EffectOptions` -- name, defer, schedule, transparent
213
340
  *
214
341
  * @example
215
342
  * ```ts
@@ -253,12 +380,28 @@ export declare function createEffect<T>(compute: ComputeFunction<undefined | NoI
253
380
  * Creates a reactive computation that runs during the render phase as DOM elements
254
381
  * are created and updated but not necessarily connected.
255
382
  *
383
+ * Same compute / effect split as `createEffect`, but scheduled inside the render
384
+ * queue rather than after it. Reach for this only when authoring renderer
385
+ * plumbing (custom DOM bindings, JSX-generated `insert()` / `spread()` calls).
386
+ * App code should use `createEffect`.
387
+ *
256
388
  * ```typescript
257
389
  * createRenderEffect<T>(compute, effectFn, options?: EffectOptions);
258
390
  * ```
259
391
  * @param compute a function that receives its previous value and returns a new value used to react on a computation
260
392
  * @param effectFn a function that receives the new value and is used to perform side effects
261
- * @param options `EffectOptions` -- name, defer, schedule
393
+ * @param options `EffectOptions` -- name, defer, schedule, transparent
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * // Custom directive: bind an element's textContent to a reactive source.
398
+ * function bindText(el: HTMLElement, source: () => string) {
399
+ * createRenderEffect(
400
+ * () => source(),
401
+ * value => { el.textContent = value; }
402
+ * );
403
+ * }
404
+ * ```
262
405
  *
263
406
  * @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
264
407
  */
@@ -271,6 +414,12 @@ export declare function createRenderEffect<T>(compute: ComputeFunction<undefined
271
414
  * may run multiple times for a single change or show tearing (reading inconsistent
272
415
  * state). Use only when dynamic subscription patterns require same-scope tracking.
273
416
  *
417
+ * The callback runs during the flush itself: writes made inside it are queued
418
+ * into the same flush's continuation and are never visible to the callback's
419
+ * own reads (reads return settled values, as in every effect-phase scope), and
420
+ * `flush()` cannot be called from inside it (dev throws; production is a
421
+ * no-op) — defer with `queueMicrotask(() => flush())` if needed.
422
+ *
274
423
  * ```typescript
275
424
  * createTrackedEffect(compute, options?: { name?: string });
276
425
  * ```
@@ -324,7 +473,9 @@ export declare function createReaction(effectFn: EffectFunction<undefined> | Eff
324
473
  * Awaits a reactive expression and returns its first fully-settled value as a
325
474
  * `Promise`. Pending async reads (`createMemo` returning a promise, etc.) are
326
475
  * waited on; once the expression returns synchronously without `NotReadyError`
327
- * the promise resolves with that value.
476
+ * the promise resolves with that value. If the expression settles with an
477
+ * error instead — including an async source that rejects — the promise
478
+ * rejects with it.
328
479
  *
329
480
  * Must be called *outside* a tracking scope — it doesn't subscribe, it just
330
481
  * resolves the current value once.
@@ -397,9 +548,29 @@ export declare function createOptimistic<T>(fn: ComputeFunction<T>, options?: Si
397
548
  * Reactive reads inside the callback are *not* tracked — to react to
398
549
  * subsequent settles, register a new `onSettled` each time.
399
550
  *
551
+ * The callback runs during the settle flush itself, which gives it the same
552
+ * write semantics as every other effect-phase scope (the effect half of
553
+ * `createEffect`, event handlers):
554
+ *
555
+ * - **Writes** are queued into the same flush's continuation — dependent memos
556
+ * and effects update before the flush returns — but reads inside the
557
+ * callback keep returning the settled (pre-write) values. A callback never
558
+ * observes its own unsettled write. Functional setters still compose:
559
+ * `set(v => v + 1)` twice increments twice.
560
+ * - **`flush()` cannot be called** from inside the callback — the flush is
561
+ * already running (dev throws; production is a no-op). To force a drain
562
+ * after this settle, defer it: `queueMicrotask(() => flush())`.
563
+ *
400
564
  * `onCleanup` is **not** allowed inside the callback — return a cleanup
401
565
  * function instead. The returned cleanup runs on owner disposal.
402
566
  *
567
+ * A cleanup return is only honored when `onSettled` is called from an **owned**
568
+ * scope (e.g. a component body). When it fires out of band from an *unowned*
569
+ * scope — an event handler, a tracked effect, or another `onSettled` — there is
570
+ * no owner lifecycle to bind a cleanup to; returning one is a dev-mode error
571
+ * (and is dropped in production). Use the post-settle/event-handler forms below
572
+ * for one-shot work, and keep setup-with-teardown in an owned scope.
573
+ *
403
574
  * @example
404
575
  * ```tsx
405
576
  * // Component-level setup + teardown — replaces onMount + onCleanup.
@@ -1,9 +1,19 @@
1
- export type { Store, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.js";
1
+ export type { Store, StoreReturn, ProjectionStoreReturn, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.js";
2
2
  export type { Merge, Omit } from "./utils.js";
3
- export { isWrappable, createStore, $TRACK, $PROXY, $TARGET } from "./store.js";
4
- export { createProjection } from "./projection.js";
5
- export { createOptimisticStore } from "./optimistic.js";
6
- export { reconcile } from "./reconcile.js";
3
+ export { isWrappable, $TRACK, $PROXY, $TARGET } from "./store.js";
4
+ import type { NoFn, ProjectionOptions, Store, StoreOptions, StoreSetter } from "./store.js";
5
+ import type { Refreshable } from "../core/index.js";
6
+ export { createProjectionNext as createProjection } from "./next/projection.js";
7
+ export { createOptimisticStoreNext as createOptimisticStore } from "./next/optimistic.js";
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.js";
8
18
  export type { PathSetter, Part, StorePathRange, ArrayFilterFn, CustomPartial } from "./storePath.js";
9
- export { snapshot, deep, merge, omit } from "./utils.js";
19
+ export { merge, omit } from "./utils.js";
@@ -0,0 +1,20 @@
1
+ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from "../store.js";
2
+ import type { StoreNextFamily, StoreNextTarget } from "./target.js";
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.js";
18
+ import { type NoFn, type ProjectionOptions, type Store } from "../store.js";
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.js";
2
+ import { type StoreNextFamily, type StoreNextTarget } from "./target.js";
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.js";
16
+ /** Projection family (§7b): children wrap into the family's own map (writes
17
+ * land in the projection, never the source family), and every node created
18
+ * under the family carries the projection computed as its firewall. */
19
+ export interface StoreNextFamily {
20
+ /** Optimistic family: nodes are born armed (`_overrideValue` slot) so every
21
+ * write rides the core optimistic engine — lanes, per-transaction ownership,
22
+ * reverts all core-native (§3, RUL-3). */
23
+ opt?: boolean;
24
+ /** Root proxy (registered with the scheduler's optimistic-store set for the
25
+ * transitionBlocked store-half, #2951). */
26
+ px?: any;
27
+ /** Targets currently carrying active node overrides (landing-consumption
28
+ * walk, RUL-2: visible landed truth replaces optimism). */
29
+ overlaid?: Set<any>;
30
+ 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.js";
2
- import { type ProjectionOptions, type Store } from "./store.js";
2
+ import { type NoFn, type ProjectionOptions, type Store } from "./store.js";
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>;