@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,14 +1,34 @@
1
+ /**
2
+ * Shared body of `reconcile()` and the projection commit. `replace` is the
3
+ * only difference: a projection commit is a value swap, not a merge — its root
4
+ * proxy is a cell handed out by `createProjection` that can never change
5
+ * reference, so a derive returning a different entity is not the slot mistake
6
+ * `reconcile()` throws on. Nothing below the root survives that swap, which is
7
+ * the rule the keyed diff already applies at a nested slot on a key mismatch.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function reconcileState(value: any, state: any, key: any, replace: boolean): void;
1
12
  /**
2
13
  * Returns a draft-mutating function that smart-merges `value` into a store,
3
- * preserving the identity of items whose `key` field matches between old and
4
- * new states. Useful when applying server payloads or full-replacement data
5
- * onto an existing store without losing fine-grained reactivity.
14
+ * preserving fine-grained reactivity: only changed leaves trigger updates.
6
15
  *
7
- * Items with the same key are updated in place (only changed properties
8
- * trigger updates). Items added or removed update the corresponding signals.
16
+ * With a `key` (default `"id"`), array items whose key matches between old
17
+ * and new states keep their identity (updated in place, moves and removals
18
+ * update the corresponding signals) — the shape for keyed server payloads.
19
+ * Items without the key field fall back to positional matching.
20
+ *
21
+ * With `key: null`, matching is purely positional: index N of the new array
22
+ * merges into index N of the old, and object properties merge recursively —
23
+ * the classic pattern for fixed-shape data that churns in place (dashboards,
24
+ * monitors), where no keyed diff pass is needed or wanted.
25
+ *
26
+ * Merging into a slot that holds a *different* entity throws — the caller
27
+ * picked the slot, so a key mismatch there is a bug.
9
28
  *
10
29
  * @param value the next state to merge in
11
- * @param key property name (string) or extractor function for stable identity
30
+ * @param key property name (string) or extractor function for stable
31
+ * identity (default `"id"`); pass `null` for positional merging
12
32
  *
13
33
  * @example
14
34
  * ```ts
@@ -16,8 +36,11 @@
16
36
  *
17
37
  * async function refresh() {
18
38
  * const fresh = await api.getTodos();
19
- * setTodos(reconcile(fresh, "id")); // diff-merge by `id`
39
+ * setTodos(reconcile(fresh)); // diff-merge by `id`
20
40
  * }
41
+ *
42
+ * // fixed-shape polling data — positional merge
43
+ * setStats(reconcile(nextStats, null));
21
44
  * ```
22
45
  */
23
- export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
46
+ export declare function reconcile<T extends U, U>(value: T, key?: string | ((item: NonNullable<any>) => any) | null): (state: U) => void;
@@ -1,4 +1,5 @@
1
- import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
1
+ import { type Signal } from "../core/index.js";
2
+ import type { Refreshable } from "../core/index.js";
2
3
  /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
3
4
  export type Store<T> = Readonly<T>;
4
5
  /**
@@ -17,6 +18,10 @@ export type Store<T> = Readonly<T>;
17
18
  * whose derive function reconciles its return by `options.key`.
18
19
  */
19
20
  export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
21
+ /** Tuple returned by the plain `createStore(initialValue)` form. */
22
+ export type StoreReturn<T> = [get: Store<T>, set: StoreSetter<T>];
23
+ /** Tuple returned by the derived `createStore(fn, seed, options?)` form. */
24
+ export type ProjectionStoreReturn<T> = [get: Refreshable<Store<T>>, set: StoreSetter<T>];
20
25
  /** Base options for store primitives. */
21
26
  export interface StoreOptions {
22
27
  /** Debug name (dev mode only) */
@@ -24,95 +29,110 @@ export interface StoreOptions {
24
29
  }
25
30
  /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
26
31
  export interface ProjectionOptions extends StoreOptions {
27
- /** Key property name or function for reconciliation identity */
28
- key?: string | ((item: NonNullable<any>) => any);
32
+ /** Key property name or function for reconciliation identity; `null` merges positionally */
33
+ key?: string | ((item: NonNullable<any>) => any) | null;
34
+ /** Single-layer store: root keys reactive, values raw records replaced by reference */
35
+ shallow?: boolean;
36
+ /**
37
+ * Treat the seed as commit #0: the store is born committed with the seed's
38
+ * contents, shown until the derive's first real answer lands. While that
39
+ * first answer is in flight, reads serve the seed everywhere — nothing
40
+ * suspends to a `<Loading>` boundary, no transition is held, and
41
+ * `isPending` stays false (the seed answers by declaration; first-load
42
+ * affordances belong to the data, e.g. a `skeleton: true` field in the
43
+ * seed). Once the first answer lands (reconciled into the seed), refetches
44
+ * use normal pending semantics with `isPending` true.
45
+ *
46
+ * The store equivalent of `MemoOptions.loadingValue`; the seed already
47
+ * carries the placeholder shape, so this is just the opt-in.
48
+ */
49
+ seedLoadingValue?: boolean;
29
50
  }
30
51
  export type NoFn<T> = T extends Function ? never : T;
31
52
  type DataNode = Signal<any>;
32
53
  type DataNodes = Record<PropertyKey, DataNode>;
33
- export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
34
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p";
54
+ /**
55
+ * Brand symbols used internally by the store proxy / projection plumbing.
56
+ * Cross-package wiring; not part of the user-facing API.
57
+ *
58
+ * @internal
59
+ */
60
+ export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
61
+ export declare const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
62
+ /** Structural view of a store target as shared machinery sees it (the real
63
+ * shape is `StoreNextTarget` in ./next/target.ts). */
35
64
  export type StoreNode = {
36
65
  [$PROXY]: any;
37
66
  [STORE_VALUE]: Record<PropertyKey, any>;
38
- [STORE_OVERRIDE]?: Record<PropertyKey, any>;
39
- [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
40
67
  [STORE_NODE]?: DataNodes;
41
68
  [STORE_HAS]?: DataNodes;
42
- [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
43
- [STORE_LOOKUP]?: WeakMap<any, any>;
44
- [STORE_FIREWALL]?: Computed<any>;
45
- [STORE_OPTIMISTIC]?: boolean;
46
- [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
69
+ [STORE_PARENT]?: StoreNode;
70
+ [STORE_SHALLOW]?: boolean;
71
+ [STORE_DESC]?: boolean;
47
72
  };
48
73
  export declare namespace SolidStore {
49
74
  interface Unwrappable {
50
75
  }
51
76
  }
52
77
  export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
53
- export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
54
- export declare const storeLookup: WeakMap<WeakKey, any>;
55
- export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
78
+ /**
79
+ * Marks a value as raw: no store will ever wrap it — every store presents it
80
+ * as-is, tracked by reference at whatever slot holds it and updated by
81
+ * replacement. Useful for class instances and external objects (editors,
82
+ * scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
83
+ * for the value's lifetime.
84
+ */
85
+ export declare let rawValuesUsed: boolean;
86
+ export declare function isRawValue(value: any): boolean;
87
+ export declare function markRaw<T>(value: T): T;
88
+ export declare function markRawOne(v: any): void;
89
+ export declare function markRawIngest(container: any): void;
56
90
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
57
91
  export declare function setWriteOverride(value: boolean): void;
58
- export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
59
- export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
60
- export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
61
- export declare const storeTraps: ProxyHandler<StoreNode>;
62
- export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
92
+ export declare function getWriteOverride(): boolean;
93
+ export declare function ownEnumerableKeys(o: object): (string | symbol)[];
63
94
  /**
64
- * Creates a deeply-reactive store backed by a Proxy. Reads track each property
65
- * accessed; only the parts that change trigger updates.
66
- *
67
- * Store properties hold **plain values**, not accessors. The proxy already
68
- * tracks reads per-property — wrapping a value in `() => state.foo` produces
69
- * a getter that *won't* track when called, which looks like a reactivity bug
70
- * but is just a category error. If you have a signal-shaped piece of state,
71
- * make it a property of the store (`{ foo: 1 }`) rather than nesting an
72
- * accessor inside (`{ foo: () => signal() }`).
73
- *
74
- * The setter takes a **draft-mutating** function mutate the draft in place
75
- * (canonical). The callback may also return a new value: arrays are replaced
76
- * by index (length adjusted), objects are shallow-diffed at the top level
77
- * (keys present in the returned value are written, missing keys deleted). Use
78
- * the return form for shapes where mutation is awkward — most commonly
79
- * removing items via `filter`. The setter does **not** do keyed reconciliation;
80
- * for that, use the derived/projection form (or `createProjection`).
81
- *
82
- * - Plain form: `createStore(initialValue)` wraps a value in a reactive
83
- * proxy.
84
- * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
85
- * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
86
- * an `AsyncIterable`; the projection's result reconciles against the
87
- * existing store by `options.key` (default `"id"`) for stable identity.
88
- *
89
- * @example
90
- * ```ts
91
- * const [state, setState] = createStore({
92
- * user: { name: "Ada", age: 36 },
93
- * todos: [] as { id: string; text: string; done: boolean }[]
94
- * });
95
- *
96
- * // Canonical: mutate the draft in place.
97
- * setState(s => { s.user.age = 37; });
98
- * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
99
- *
100
- * // Return form: reach for it when mutation is awkward.
101
- * setState(s => s.todos.filter(t => !t.done)); // remove items
102
- * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
103
- * ```
95
+ * Scope inheritance for late-created nodes: every live mark whose identity
96
+ * scope contains the owning record's raw and, for keyed marks, whose key
97
+ * is this property — gets counted on the new node. Inherited marks live
98
+ * exactly as long as the scope's carrier the release hook below drops
99
+ * them with the entry.
100
+ */
101
+ export declare function inheritAffectsMarks(node: DataNode, raw: object, property: PropertyKey): void;
102
+ /** Next-store node factory for affects carriers/slots: injected by the
103
+ * rewrite module (next targets alias the legacy field names, so everything
104
+ * here EXCEPT node creation works on them structurally). */
105
+ export declare let nextAffectsNodeResolver: ((target: any, key: PropertyKey) => DataNode) | null;
106
+ export declare function setNextAffectsNodeResolver(fn: (target: any, key: PropertyKey) => DataNode): void;
107
+ /** Next-store optimistic view for the declaration walk (optimistic rows
108
+ * pushed before the declaration are in motion too legacy reads its write
109
+ * overlays; next composes armed-node overrides). */
110
+ export declare let nextOptimisticViewResolver: ((target: any, raw: any) => any) | null;
111
+ export declare function setNextOptimisticViewResolver(fn: (target: any, raw: any) => any): void;
112
+ /** @internal birth inheritance for nodes created inside a live mark window —
113
+ * exported for the rewrite's node factories. */
114
+ export declare function affectsScopesLive(): boolean;
115
+ /**
116
+ * Witness live mark coverage of a record into the active isPending() probe.
117
+ * Tracked reads don't need this they go through real signal nodes, which
118
+ * carry marks directly (declaration walk or birth inheritance). This covers
119
+ * UNTRACKED probes reading through records whose nodes never materialized
120
+ * (no observer ever subscribed, so no node exists to carry the mark).
121
+ * Callers guard on `pendingCheckActive`, so plain reads never pay for this.
104
122
  *
105
- * @example
106
- * ```ts
107
- * // Derived store auto-fetches & reconciles by `id`.
108
- * const [users] = createStore(
109
- * async () => fetch("/users").then(r => r.json()),
110
- * [] as User[]
111
- * );
112
- * ```
123
+ * @internal
124
+ */
125
+ export declare function witnessAffectsMark(target: StoreNode, property?: PropertyKey): void;
126
+ /**
127
+ * Resolves the store nodes an `affects()` declaration marks: with a `key`,
128
+ * the named slot's leaf node (upserted so the mark has an addressable
129
+ * carrier); without, the record's $AFFECTS carrier plus every LIVE node in
130
+ * its subtree (the edges existing readers subscribed through), with the
131
+ * subtree's identities snapshotted into the mark's scope so nodes created
132
+ * during the window — and untracked probes over captured proxies — resolve
133
+ * against it (#2882).
113
134
  *
114
- * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
135
+ * @internal
115
136
  */
116
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
117
- export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Refreshable<Store<T>>, set: StoreSetter<T>];
137
+ export declare function getStoreAffectsNodes(target: StoreNode, key?: PropertyKey): DataNode[];
118
138
  export {};
@@ -1,43 +1,3 @@
1
- /**
2
- * Returns a plain (non-proxy, non-reactive) deep copy of a store value.
3
- * Reading via `snapshot` does **not** subscribe to changes — use this when you
4
- * need to hand a stable plain object to non-reactive code (logging,
5
- * serialization, structured-clone, network payloads, etc.).
6
- *
7
- * Returns the original object identity for any sub-tree that wasn't modified
8
- * relative to the proxy's underlying source.
9
- *
10
- * @example
11
- * ```ts
12
- * const [state] = createStore({ user: { name: "Ada" }, todos: [] });
13
- *
14
- * console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
15
- * ```
16
- */
17
- export declare function snapshot<T>(item: T): T;
18
- export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
19
- /**
20
- * Returns a plain (non-proxy) deep copy **and** subscribes the current
21
- * tracking scope to every nested change in the source store. Any write
22
- * anywhere in the subtree invalidates the consumer.
23
- *
24
- * Use this when you need plain data inside a reactive scope and want to
25
- * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
26
- * memo that should rerun on any nested change). For most read paths, prefer
27
- * direct property access — Solid stores already track per-property reads
28
- * with no `deep()` wrapper needed.
29
- *
30
- * @example
31
- * ```ts
32
- * const [state] = createStore({ a: { b: { c: 1 } } });
33
- *
34
- * createEffect(
35
- * () => deep(state), // reruns on any nested change
36
- * plain => sendToWorker(plain) // worker gets a non-proxy copy
37
- * );
38
- * ```
39
- */
40
- export declare function deep<T extends object>(store: T): T;
41
1
  type DistributeOverride<T, F> = T extends undefined ? F : T;
42
2
  type Override<T, U> = T extends any ? U extends any ? {
43
3
  [K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
@@ -0,0 +1,47 @@
1
+ import type { Accessor } from "./signals.cjs";
2
+ import { type Store } from "./store/store.cjs";
3
+ /**
4
+ * Declares that in-flight work will change the targeted data: the named
5
+ * slot(s) — and everything DERIVED from them — read as pending
6
+ * (`isPending` → `true`) from the declaration until the surrounding
7
+ * transaction settles or reverts. A mark lives on its own channel — a
8
+ * refcount on the marked node plus dep-graph reachability in the verdict
9
+ * layer — so the marked values themselves stay readable (a mark is a promise
10
+ * of change, not an absence of value), no reader ever suspends on one, and
11
+ * completion/settlement accounting never sees one. This is the declaration
12
+ * verb of the pending model — additive only. A mark can turn pending ON for
13
+ * data the graph can't see changing yet; nothing can turn pending OFF while
14
+ * a real change is in flight — a quiet `refresh()` re-ask under a mark still
15
+ * reads pending (declaring the reload is what makes it a real question).
16
+ *
17
+ * Targets:
18
+ * - `affects(store)` — a store proxy (any record, root or nested): every
19
+ * record reachable from it at declaration time reads pending, including
20
+ * through captured child proxies (e.g. `<For>` rows). Siblings are
21
+ * untouched; records added after the declaration are not covered.
22
+ * - `affects(record, key)` — exactly the named slot of the record. One key
23
+ * per call (keys do NOT form a path — target the owning record directly).
24
+ * - `affects(accessor)` — a source accessor (signal or memo): the source
25
+ * reads pending.
26
+ *
27
+ * Typically called at the top of an `action` alongside optimistic writes —
28
+ * both are up-front declarations about the same mutation. Outside any
29
+ * transaction the mark is released at the end of the current flush.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const send = action(function* (text: string) {
34
+ * setState(s => { s.messages.push({ text, status: "sending" }); });
35
+ * affects(state.messages.at(-1)!, "status"); // this slot pends until settle
36
+ * yield api.send(text);
37
+ * });
38
+ *
39
+ * const reload = action(function* () {
40
+ * affects(thing); // the whole store pends…
41
+ * refresh(thing); // …over this otherwise-quiet re-ask
42
+ * yield api.done();
43
+ * });
44
+ * ```
45
+ */
46
+ export declare function affects(target: Accessor<unknown> | Store<object>): void;
47
+ export declare function affects<T extends object>(target: Store<T>, key: keyof T): void;
@@ -1,5 +1,6 @@
1
1
  import { Queue, type Computed, type Effect } from "./core/index.cjs";
2
2
  import type { Signal } from "./core/index.cjs";
3
+ import { type Accessor } from "./signals.cjs";
3
4
  export interface BoundaryComputed<T> extends Computed<T> {
4
5
  _propagationMask: number;
5
6
  }
@@ -19,18 +20,18 @@ export declare class RevealController {
19
20
  _evaluating: boolean;
20
21
  constructor(order: OrderAccessor, collapsed: BoolAccessor);
21
22
  _forEachOwnedSlot(fn: (slot: RevealSlot) => boolean | void): boolean;
22
- isReady(): boolean;
23
+ _isReady(): boolean;
23
24
  /**
24
25
  * "Minimally ready" = this group has something visible to show under its own policy.
25
26
  * Used by an enclosing `together` group to decide when it can release.
26
- * - `together`: fully ready (atomic).
27
+ * - `together`: every direct slot is minimally ready.
27
28
  * - `sequential`: the first owned slot is minimally ready (frontier can advance).
28
29
  * - `natural`: any owned slot is minimally ready.
29
30
  */
30
- isMinimallyReady(): boolean;
31
- register(slot: RevealSlot): void;
32
- unregister(slot: RevealSlot): void;
33
- evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
31
+ _isMinimallyReady(): boolean;
32
+ _register(slot: RevealSlot): void;
33
+ _unregister(slot: RevealSlot): void;
34
+ _evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
34
35
  }
35
36
  export declare class CollectionQueue extends Queue {
36
37
  _collectionType: number;
@@ -38,6 +39,7 @@ export declare class CollectionQueue extends Queue {
38
39
  _tree?: BoundaryComputed<any>;
39
40
  _pending: boolean;
40
41
  _disabled: Signal<boolean>;
42
+ _error?: Signal<unknown>;
41
43
  _collapsed: Signal<boolean>;
42
44
  _revealController?: RevealController;
43
45
  _initialized: boolean;
@@ -46,7 +48,7 @@ export declare class CollectionQueue extends Queue {
46
48
  constructor(type: number);
47
49
  run(type: number): void;
48
50
  notify(node: Effect<any>, type: number, flags: number, error?: any): boolean;
49
- checkSources(): void;
51
+ _checkSources(): void;
50
52
  }
51
53
  /**
52
54
  * Lower-level primitive that backs the `<Loading>` flow control. Catches
@@ -59,20 +61,45 @@ export declare class CollectionQueue extends Queue {
59
61
  * @param fallback the fallback shown while async reads in `fn` are unresolved
60
62
  * @param options `on` — accessor whose value scopes the boundary; when set,
61
63
  * transitions caused by writes to other reactive sources are *not* caught
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * // Custom boundary component built on top of the primitive.
68
+ * function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
69
+ * return createLoadingBoundary(
70
+ * () => props.children,
71
+ * () => props.fallback
72
+ * ) as unknown as JSX.Element;
73
+ * }
74
+ * ```
62
75
  */
63
- export declare function createLoadingBoundary(fn: () => any, fallback: () => any, options?: {
76
+ export declare function createLoadingBoundary<T, U>(fn: () => T, fallback: () => U, options?: {
64
77
  on?: () => any;
65
- }): import("./signals.cjs").Accessor<unknown>;
78
+ }): Accessor<T | U>;
66
79
  /**
67
80
  * Lower-level primitive that backs the `<Errored>` flow control. Catches
68
81
  * thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
69
- * `reset()` recomputes the failing sources so the boundary can attempt to
70
- * recover.
82
+ * `error` is an accessor for the latest captured error; `reset()` recomputes
83
+ * the failing sources so the boundary can attempt to recover.
71
84
  *
72
85
  * App code should use `<Errored fallback={...}>` instead — reach for this only
73
86
  * when authoring custom boundary components.
87
+ *
88
+ * @example
89
+ * ```tsx
90
+ * // Custom boundary that wraps the primitive and adds telemetry.
91
+ * function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
92
+ * return createErrorBoundary(
93
+ * () => props.children,
94
+ * (err, reset) => {
95
+ * reportError(err());
96
+ * return props.fallback(err);
97
+ * }
98
+ * ) as unknown as JSX.Element;
99
+ * }
100
+ * ```
74
101
  */
75
- export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): import("./signals.cjs").Accessor<unknown>;
102
+ export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: Accessor<unknown>, reset: () => void) => U): Accessor<T | U>;
76
103
  /**
77
104
  * Coordinate the reveal timing of sibling loading boundaries.
78
105
  *
@@ -101,7 +128,18 @@ export declare function createErrorBoundary<U>(fn: () => any, fallback: (error:
101
128
  * own minimal signal).
102
129
  * - `together` — every direct slot is minimally ready.
103
130
  * - `natural` — any direct slot has visible content (leaves on resolve; nested
104
- * composites when fully ready, since natural treats composites as atomic).
131
+ * composites via their own minimal signal).
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
136
+ * // programmatically. App code uses the JSX `<Reveal>` component instead.
137
+ * // Both options are accessors so they can react to state changes.
138
+ * createRevealOrder(
139
+ * () => renderSiblings(),
140
+ * { order: () => mode(), collapsed: () => true }
141
+ * );
142
+ * ```
105
143
  */
106
144
  export declare function createRevealOrder<T>(fn: () => T, options?: {
107
145
  order?: OrderAccessor;
@@ -120,6 +158,15 @@ export declare function createRevealOrder<T>(fn: () => T, options?: {
120
158
  * @param options
121
159
  * - `skipNonRendered` — drop values that won't render
122
160
  * - `doNotUnwrap` — leave function children as-is (caller will resolve)
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * // Custom renderer walking a children tree manually. Most authors should
165
+ * // use `children()` from solid-js, which memoizes the resolved value.
166
+ * function renderChildren(value: unknown): unknown {
167
+ * return flatten(value, { skipNonRendered: true });
168
+ * }
169
+ * ```
123
170
  */
124
171
  export declare function flatten(children: any, options?: {
125
172
  skipNonRendered?: boolean;
@@ -1,13 +1,41 @@
1
1
  /**
2
+ * The primitive for mutations: imperative async workflows whose *writes span
3
+ * an async gap* — optimistic write, server round-trip, reconciling write —
4
+ * where intermediate state must not leak and failure must revert cleanly
5
+ * (pair with `createOptimistic` / `createOptimisticStore`).
6
+ *
7
+ * Navigation-shaped updates do not need an action. A plain setter call is
8
+ * enough: reads pull the async, and downstream async computeds hold their
9
+ * previous values per-node until the new ones are ready (`isPending` /
10
+ * `latest` expose the in-flight state). Reach for `action` only when writes
11
+ * happen *after* async work, not merely upstream of it.
12
+ *
13
+ * Framework-level actions (router form actions, server actions) are
14
+ * specializations of this primitive: they are actions in exactly this sense —
15
+ * the same transactional semantics — with form binding, serialization, and
16
+ * submission tracking layered on top. The shared name is deliberate.
17
+ *
2
18
  * Wraps a generator function so each invocation runs as a single transaction
3
19
  * (a "transition") that batches every signal/store write between yields. The
4
20
  * surrounding UI sees one atomic update per yielded step; nothing is committed
5
21
  * until the action either completes or the next `yield` resolves.
6
22
  *
7
- * Yield promises (or any awaitable) inside the generator the action waits
8
- * for each before continuing, but the writes you made beforehand are already
9
- * visible (or held by `<Loading>` if optimistic). Yield bare values for
10
- * synchronous batched steps.
23
+ * `yield` is the transaction-safe suspension point: the action waits for a
24
+ * yielded promise and re-enters the transaction before running the code after
25
+ * it. A plain `await` does NOT the runtime has no hook into an async
26
+ * generator's internal await continuations, so writes to fresh signals
27
+ * between an `await` and the next `yield` escape the transaction and commit
28
+ * immediately. `await` is still the ergonomic choice for typed results; just
29
+ * put a bare `yield` before any writes that follow it:
30
+ *
31
+ * ```ts
32
+ * const saved = await api.createTodo(text); // typed result
33
+ * yield; // re-enter the transaction before writing
34
+ * setTodos(t => { ... });
35
+ * ```
36
+ *
37
+ * (For the same reason, don't call `flush()` inside an action body — it
38
+ * drains the transaction mid-step.)
11
39
  *
12
40
  * Each call returns a `Promise` that resolves with the generator's return
13
41
  * value, or rejects if it throws. Pair with `createOptimistic` /
@@ -18,10 +46,11 @@
18
46
  * ```ts
19
47
  * const [todos, setTodos] = createOptimisticStore<Todo[]>([]);
20
48
  *
21
- * const addTodo = action(function* (text: string) {
49
+ * const addTodo = action(async function* (text: string) {
22
50
  * const tempId = crypto.randomUUID();
23
51
  * setTodos(t => { t.push({ id: tempId, text, pending: true }); }); // optimistic
24
- * const saved = yield api.createTodo(text); // network round-trip
52
+ * const saved = await api.createTodo(text); // network round-trip, typed
53
+ * yield; // re-enter the transaction
25
54
  * setTodos(t => {
26
55
  * const i = t.findIndex(x => x.id === tempId);
27
56
  * if (i >= 0) t[i] = saved;
@@ -1,6 +1,21 @@
1
+ import { NotReadyError } from "./error.cjs";
1
2
  import { type OptimisticLane } from "./lanes.cjs";
2
- import type { Computed } from "./types.cjs";
3
+ import type { Computed, Link } from "./types.cjs";
4
+ export declare function addPendingSource(el: Computed<any>, source: Computed<any>): boolean;
5
+ /**
6
+ * A loading-window node hit an unready source (sync throw in recompute, or a
7
+ * NotReadyError-rejected flight): register for the source's settle — the
8
+ * settlePendingSource walk runs off `_pendingSources` + `_blocked` alone —
9
+ * with NO read-visible pending status, no downstream propagation, no
10
+ * transition, no lane registration. Commit #0 keeps serving.
11
+ */
12
+ export declare function parkLoadingWindow(el: Computed<any>, e: NotReadyError): void;
13
+ export declare function setPendingError(el: Computed<any>, source?: Computed<any>, error?: any): void;
14
+ export declare function forEachDependent(el: Computed<any>, fn: (node: Computed<any>, link: Link) => void): void;
15
+ export declare function releaseSettledDependents(el: Computed<any>): void;
16
+ export declare function settleErroredDependents(el: Computed<any>, error: any): void;
3
17
  export declare function settlePendingSource(el: Computed<any>): void;
18
+ export declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
4
19
  export declare function handleAsync<T>(el: Computed<T>, result: T | PromiseLike<T> | AsyncIterable<T>, setter?: (value: T) => void): T;
5
20
  export declare function clearStatus(el: Computed<any>, clearUninitialized?: boolean): void;
6
21
  export declare function notifyStatus(el: Computed<any>, status: number, error: any, blockStatus?: boolean, lane?: OptimisticLane): void;
@@ -9,12 +9,22 @@ export declare const REACTIVE_DISPOSED: number;
9
9
  export declare const REACTIVE_OPTIMISTIC_DIRTY: number;
10
10
  export declare const REACTIVE_SNAPSHOT_STALE: number;
11
11
  export declare const REACTIVE_LAZY: number;
12
+ export declare const REACTIVE_MANUAL_WRITE: number;
13
+ /**
14
+ * The pending recompute is a re-ask of the same question: `refresh()` dirtied
15
+ * the node while no tracked input changed value. Cleared whenever a real
16
+ * value-change notification arrives (`insertSubs`), and consumed by
17
+ * `recompute` into the node's `_reask` classification — a quiet (re-ask)
18
+ * pending window does not read as pending (question-scoped pending model).
19
+ */
20
+ export declare const REACTIVE_REASK: number;
12
21
  export declare const CONFIG_OWNED_WRITE: number;
13
22
  export declare const CONFIG_NO_SNAPSHOT: number;
14
23
  export declare const CONFIG_TRANSPARENT: number;
15
24
  export declare const CONFIG_IN_SNAPSHOT_SCOPE: number;
16
25
  export declare const CONFIG_CHILDREN_FORBIDDEN: number;
17
26
  export declare const CONFIG_AUTO_DISPOSE: number;
27
+ export declare const CONFIG_SYNC: number;
18
28
  export declare const STATUS_NONE = 0;
19
29
  export declare const STATUS_PENDING: number;
20
30
  export declare const STATUS_ERROR: number;
@@ -25,17 +35,36 @@ export declare const EFFECT_USER = 2;
25
35
  export declare const EFFECT_TRACKED = 3;
26
36
  export declare const NOT_PENDING: {};
27
37
  export declare const NO_SNAPSHOT: {};
38
+ /**
39
+ * Stand-in stored in `_overrideValue` for an optimistic write of literal
40
+ * `undefined` (#2898). The slot doubles as the optimistic-node brand
41
+ * (`undefined` = not optimistic, `NOT_PENDING` = at rest), so the raw value
42
+ * would erase the node's optimistic identity: the write turns invisible and
43
+ * follow-up writes route off the optimistic path and commit permanently.
44
+ * Same shape as NO_SNAPSHOT. Sites that surface the override VALUE unwrap
45
+ * via `visibleOverrideValue`; slot identity tests stay raw.
46
+ */
47
+ export declare const OVERRIDE_UNDEFINED: {};
48
+ /** Unwrap an active override's stored value for surfacing to readers (#2898). */
49
+ export declare function unwrapOverride<T = any>(v: unknown): T;
28
50
  export declare const STORE_SNAPSHOT_PROPS = "sp";
29
51
  export declare const SUPPORTS_PROXY: boolean;
30
52
  export declare const defaultContext: {};
53
+ /**
54
+ * Brand symbol used by `Refreshable<T>` values (projection stores, async
55
+ * memos) to expose their underlying computation to `refresh()`. Not part of
56
+ * the user-facing API.
57
+ *
58
+ * @internal
59
+ */
31
60
  export declare const $REFRESH: unique symbol;
32
61
  /**
33
- * Brand applied to derived/projected stores indicating they participate in
34
- * the `refresh()` re-run protocol. Use this alias instead of inlining
35
- * `T & { [$REFRESH]: any }` so that user-defined hooks that wrap
36
- * `createOptimisticStore` / `createProjection` / projection-form
37
- * `createStore` can have their return types inferred without leaking the
38
- * internal `$REFRESH` symbol into public type signatures (TS4058).
62
+ * Brand applied to values that participate in the `refresh()` re-run protocol.
63
+ * Accessors receive this handle internally; projected stores expose it through
64
+ * their public return type so user-defined hooks that wrap `createOptimisticStore`
65
+ * / `createProjection` / projection-form `createStore` can have their return
66
+ * types inferred without leaking the internal `$REFRESH` symbol into public type
67
+ * signatures (TS4058).
39
68
  */
40
69
  export type Refreshable<T> = T & {
41
70
  readonly [$REFRESH]: any;