@solidjs/signals 0.13.13 → 2.0.0-beta.11

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 (110) hide show
  1. package/README.md +8 -7
  2. package/dist/dev.js +1230 -598
  3. package/dist/node.cjs +2064 -1555
  4. package/dist/prod.js +1783 -1251
  5. package/dist/types/boundaries.d.ts +126 -5
  6. package/dist/types/core/action.d.ts +34 -0
  7. package/dist/types/core/constants.d.ts +26 -0
  8. package/dist/types/core/context.d.ts +10 -2
  9. package/dist/types/core/core.d.ts +129 -9
  10. package/dist/types/core/dev.d.ts +1 -1
  11. package/dist/types/core/effect.d.ts +4 -2
  12. package/dist/types/core/error.d.ts +24 -0
  13. package/dist/types/core/external.d.ts +19 -0
  14. package/dist/types/core/graph.d.ts +2 -0
  15. package/dist/types/core/index.d.ts +1 -1
  16. package/dist/types/core/owner.d.ts +93 -3
  17. package/dist/types/core/scheduler.d.ts +43 -2
  18. package/dist/types/core/types.d.ts +5 -6
  19. package/dist/types/index.d.ts +3 -3
  20. package/dist/types/map.d.ts +32 -3
  21. package/dist/types/signals.d.ts +362 -42
  22. package/dist/types/src/boundaries.d.ts +173 -0
  23. package/dist/types/src/core/action.d.ts +35 -0
  24. package/dist/types/src/core/async.d.ts +6 -0
  25. package/dist/types/src/core/constants.d.ts +51 -0
  26. package/dist/types/src/core/context.d.ts +36 -0
  27. package/dist/types/src/core/core.d.ts +174 -0
  28. package/dist/types/src/core/dev.d.ts +49 -0
  29. package/dist/types/src/core/effect.d.ts +32 -0
  30. package/dist/types/src/core/error.d.ts +38 -0
  31. package/dist/types/src/core/external.d.ts +45 -0
  32. package/dist/types/src/core/graph.d.ts +5 -0
  33. package/dist/types/src/core/heap.d.ts +14 -0
  34. package/dist/types/src/core/index.d.ts +12 -0
  35. package/dist/types/src/core/lanes.d.ts +54 -0
  36. package/dist/types/src/core/owner.d.ts +116 -0
  37. package/dist/types/src/core/scheduler.d.ts +122 -0
  38. package/dist/types/src/core/types.d.ts +85 -0
  39. package/dist/types/src/index.d.ts +9 -0
  40. package/dist/types/src/map.d.ts +53 -0
  41. package/dist/types/src/signals.d.ts +512 -0
  42. package/dist/types/src/store/index.d.ts +9 -0
  43. package/dist/types/src/store/optimistic.d.ts +45 -0
  44. package/dist/types/src/store/projection.d.ts +66 -0
  45. package/dist/types/src/store/reconcile.d.ts +23 -0
  46. package/dist/types/src/store/store.d.ts +125 -0
  47. package/dist/types/src/store/storePath.d.ts +58 -0
  48. package/dist/types/src/store/utils.d.ts +114 -0
  49. package/dist/types/store/optimistic.d.ts +38 -12
  50. package/dist/types/store/projection.d.ts +55 -15
  51. package/dist/types/store/reconcile.d.ts +22 -0
  52. package/dist/types/store/store.d.ts +72 -15
  53. package/dist/types/store/storePath.d.ts +28 -0
  54. package/dist/types/store/utils.d.ts +78 -7
  55. package/dist/types-cjs/boundaries.d.cts +173 -0
  56. package/dist/types-cjs/core/action.d.cts +35 -0
  57. package/dist/types-cjs/core/async.d.cts +6 -0
  58. package/dist/types-cjs/core/constants.d.cts +51 -0
  59. package/dist/types-cjs/core/context.d.cts +36 -0
  60. package/dist/types-cjs/core/core.d.cts +174 -0
  61. package/dist/types-cjs/core/dev.d.cts +49 -0
  62. package/dist/types-cjs/core/effect.d.cts +32 -0
  63. package/dist/types-cjs/core/error.d.cts +38 -0
  64. package/dist/types-cjs/core/external.d.cts +45 -0
  65. package/dist/types-cjs/core/graph.d.cts +5 -0
  66. package/dist/types-cjs/core/heap.d.cts +14 -0
  67. package/dist/types-cjs/core/index.d.cts +12 -0
  68. package/dist/types-cjs/core/lanes.d.cts +54 -0
  69. package/dist/types-cjs/core/owner.d.cts +116 -0
  70. package/dist/types-cjs/core/scheduler.d.cts +122 -0
  71. package/dist/types-cjs/core/types.d.cts +85 -0
  72. package/dist/types-cjs/index.d.cts +9 -0
  73. package/dist/types-cjs/map.d.cts +53 -0
  74. package/dist/types-cjs/package.json +3 -0
  75. package/dist/types-cjs/signals.d.cts +512 -0
  76. package/dist/types-cjs/src/boundaries.d.cts +173 -0
  77. package/dist/types-cjs/src/core/action.d.cts +35 -0
  78. package/dist/types-cjs/src/core/async.d.cts +6 -0
  79. package/dist/types-cjs/src/core/constants.d.cts +51 -0
  80. package/dist/types-cjs/src/core/context.d.cts +36 -0
  81. package/dist/types-cjs/src/core/core.d.cts +174 -0
  82. package/dist/types-cjs/src/core/dev.d.cts +49 -0
  83. package/dist/types-cjs/src/core/effect.d.cts +32 -0
  84. package/dist/types-cjs/src/core/error.d.cts +38 -0
  85. package/dist/types-cjs/src/core/external.d.cts +45 -0
  86. package/dist/types-cjs/src/core/graph.d.cts +5 -0
  87. package/dist/types-cjs/src/core/heap.d.cts +14 -0
  88. package/dist/types-cjs/src/core/index.d.cts +12 -0
  89. package/dist/types-cjs/src/core/lanes.d.cts +54 -0
  90. package/dist/types-cjs/src/core/owner.d.cts +116 -0
  91. package/dist/types-cjs/src/core/scheduler.d.cts +122 -0
  92. package/dist/types-cjs/src/core/types.d.cts +85 -0
  93. package/dist/types-cjs/src/index.d.cts +9 -0
  94. package/dist/types-cjs/src/map.d.cts +53 -0
  95. package/dist/types-cjs/src/signals.d.cts +512 -0
  96. package/dist/types-cjs/src/store/index.d.cts +9 -0
  97. package/dist/types-cjs/src/store/optimistic.d.cts +45 -0
  98. package/dist/types-cjs/src/store/projection.d.cts +66 -0
  99. package/dist/types-cjs/src/store/reconcile.d.cts +23 -0
  100. package/dist/types-cjs/src/store/store.d.cts +125 -0
  101. package/dist/types-cjs/src/store/storePath.d.cts +58 -0
  102. package/dist/types-cjs/src/store/utils.d.cts +114 -0
  103. package/dist/types-cjs/store/index.d.cts +9 -0
  104. package/dist/types-cjs/store/optimistic.d.cts +45 -0
  105. package/dist/types-cjs/store/projection.d.cts +66 -0
  106. package/dist/types-cjs/store/reconcile.d.cts +23 -0
  107. package/dist/types-cjs/store/store.d.cts +125 -0
  108. package/dist/types-cjs/store/storePath.d.cts +58 -0
  109. package/dist/types-cjs/store/utils.d.cts +114 -0
  110. package/package.json +35 -27
@@ -0,0 +1,125 @@
1
+ import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
2
+ /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
3
+ export type Store<T> = Readonly<T>;
4
+ /**
5
+ * A store setter. The callback receives a writable **draft** of the store.
6
+ *
7
+ * - **Mutate in place (canonical):** `s.foo = 1`, `s.list.push(x)`,
8
+ * `s.list.splice(i, 1)`. This is the default form for most updates.
9
+ * - **Return a new value:** for shapes where mutation is awkward, most
10
+ * commonly removing items (`s => s.list.filter(...)`). Arrays are replaced
11
+ * by index (length adjusted); objects are shallow-diffed at the top level
12
+ * (keys present in the returned value are written, missing keys deleted).
13
+ *
14
+ * The setter does **not** perform keyed reconciliation. If you need surviving
15
+ * items to keep their store identity across full-array replacement, use the
16
+ * projection form — `createStore(fn, seed, { key })` or `createProjection` —
17
+ * whose derive function reconciles its return by `options.key`.
18
+ */
19
+ export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
20
+ /** Base options for store primitives. */
21
+ export interface StoreOptions {
22
+ /** Debug name (dev mode only) */
23
+ name?: string;
24
+ }
25
+ /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
26
+ export interface ProjectionOptions extends StoreOptions {
27
+ /** Key property name or function for reconciliation identity */
28
+ key?: string | ((item: NonNullable<any>) => any);
29
+ }
30
+ export type NoFn<T> = T extends Function ? never : T;
31
+ type DataNode = Signal<any>;
32
+ type DataNodes = Record<PropertyKey, DataNode>;
33
+ /**
34
+ * Brand symbols used internally by the store proxy / projection plumbing.
35
+ * Cross-package wiring; not part of the user-facing API.
36
+ *
37
+ * @internal
38
+ */
39
+ export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
40
+ export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p";
41
+ export type StoreNode = {
42
+ [$PROXY]: any;
43
+ [STORE_VALUE]: Record<PropertyKey, any>;
44
+ [STORE_OVERRIDE]?: Record<PropertyKey, any>;
45
+ [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
46
+ [STORE_NODE]?: DataNodes;
47
+ [STORE_HAS]?: DataNodes;
48
+ [STORE_CUSTOM_PROTO]?: boolean;
49
+ [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
50
+ [STORE_LOOKUP]?: WeakMap<any, any>;
51
+ [STORE_FIREWALL]?: Computed<any>;
52
+ [STORE_OPTIMISTIC]?: boolean;
53
+ [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
54
+ };
55
+ export declare namespace SolidStore {
56
+ interface Unwrappable {
57
+ }
58
+ }
59
+ export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
60
+ export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
61
+ export declare const storeLookup: WeakMap<WeakKey, any>;
62
+ export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
63
+ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
64
+ export declare function setWriteOverride(value: boolean): void;
65
+ export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
66
+ export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
67
+ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
68
+ export declare const storeTraps: ProxyHandler<StoreNode>;
69
+ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
70
+ /**
71
+ * Creates a deeply-reactive store backed by a Proxy. Reads track each property
72
+ * accessed; only the parts that change trigger updates.
73
+ *
74
+ * Store properties hold **plain values**, not accessors. The proxy already
75
+ * tracks reads per-property — wrapping a value in `() => state.foo` produces
76
+ * a getter that *won't* track when called, which looks like a reactivity bug
77
+ * but is just a category error. If you have a signal-shaped piece of state,
78
+ * make it a property of the store (`{ foo: 1 }`) rather than nesting an
79
+ * accessor inside (`{ foo: () => signal() }`).
80
+ *
81
+ * The setter takes a **draft-mutating** function — mutate the draft in place
82
+ * (canonical). The callback may also return a new value: arrays are replaced
83
+ * by index (length adjusted), objects are shallow-diffed at the top level
84
+ * (keys present in the returned value are written, missing keys deleted). Use
85
+ * the return form for shapes where mutation is awkward — most commonly
86
+ * removing items via `filter`. The setter does **not** do keyed reconciliation;
87
+ * for that, use the derived/projection form (or `createProjection`).
88
+ *
89
+ * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
90
+ * proxy.
91
+ * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
92
+ * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
93
+ * an `AsyncIterable`; the projection's result reconciles against the
94
+ * existing store by `options.key` (default `"id"`) for stable identity.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const [state, setState] = createStore({
99
+ * user: { name: "Ada", age: 36 },
100
+ * todos: [] as { id: string; text: string; done: boolean }[]
101
+ * });
102
+ *
103
+ * // Canonical: mutate the draft in place.
104
+ * setState(s => { s.user.age = 37; });
105
+ * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
106
+ *
107
+ * // Return form: reach for it when mutation is awkward.
108
+ * setState(s => s.todos.filter(t => !t.done)); // remove items
109
+ * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
110
+ * ```
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * // Derived store — auto-fetches & reconciles by `id`.
115
+ * const [users] = createStore(
116
+ * async () => fetch("/users").then(r => r.json()),
117
+ * [] as User[]
118
+ * );
119
+ * ```
120
+ *
121
+ * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
122
+ */
123
+ export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
124
+ 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>];
125
+ export {};
@@ -0,0 +1,58 @@
1
+ import { type NotWrappable } from "./store.js";
2
+ type W<T> = Exclude<T, NotWrappable>;
3
+ type KeyOf<T> = number extends keyof T ? 0 extends 1 & T ? keyof T : [T] extends [never] ? never : [T] extends [readonly unknown[]] ? number : keyof T : keyof T;
4
+ export type CustomPartial<T> = T extends readonly unknown[] ? "0" extends keyof T ? {
5
+ [K in Extract<keyof T, `${number}`>]?: T[K];
6
+ } : {
7
+ [x: number]: T[number];
8
+ } : Partial<T>;
9
+ export type StorePathRange = {
10
+ from?: number;
11
+ to?: number;
12
+ by?: number;
13
+ };
14
+ export type ArrayFilterFn<T> = (item: T, index: number) => boolean;
15
+ export type PathSetter<T> = T | CustomPartial<T> | ((prev: T) => T | CustomPartial<T>) | typeof DELETE;
16
+ export type Part<T, K extends KeyOf<T> = KeyOf<T>> = K | ([K] extends [never] ? never : readonly K[]) | ([T] extends [readonly unknown[]] ? ArrayFilterFn<T[number]> | StorePathRange : never);
17
+ declare const DELETE: unique symbol;
18
+ export interface storePath {
19
+ DELETE: typeof DELETE;
20
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, K7 extends KeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, setter: PathSetter<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7]>): (state: T) => void;
21
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, setter: PathSetter<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>): (state: T) => void;
22
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, setter: PathSetter<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>): (state: T) => void;
23
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, setter: PathSetter<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>): (state: T) => void;
24
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, setter: PathSetter<W<W<W<T>[K1]>[K2]>[K3]>): (state: T) => void;
25
+ <T, K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, setter: PathSetter<W<W<T>[K1]>[K2]>): (state: T) => void;
26
+ <T, K1 extends KeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: PathSetter<W<T>[K1]>): (state: T) => void;
27
+ <T>(setter: PathSetter<T>): (state: T) => void;
28
+ }
29
+ /**
30
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
31
+ * to produce a draft-mutating function suitable for passing to `setStore`.
32
+ *
33
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
34
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
35
+ * compatibility helper for users porting from Solid 1.x's
36
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
37
+ * two styles freely.
38
+ *
39
+ * Path parts can be:
40
+ * - a single key — `"user"`, `0`
41
+ * - an array of keys — `[0, 1, 2]`
42
+ * - a range over an array — `{ from?, to?, by? }`
43
+ * - a filter `(item, index) => boolean` for arrays
44
+ *
45
+ * The final argument is the new value or an updater `(prev) => next`. Use
46
+ * `storePath.DELETE` to remove a property.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
51
+ *
52
+ * setState(storePath("user", "name", "Grace"));
53
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
54
+ * setState(storePath("user", "nickname", storePath.DELETE));
55
+ * ```
56
+ */
57
+ export declare const storePath: storePath;
58
+ export {};
@@ -0,0 +1,114 @@
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
+ type DistributeOverride<T, F> = T extends undefined ? F : T;
42
+ type Override<T, U> = T extends any ? U extends any ? {
43
+ [K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
44
+ } & {
45
+ [K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K];
46
+ } : T & U : T & U;
47
+ type OverrideSpread<T, U> = T extends any ? {
48
+ [K in keyof ({
49
+ [K in keyof T]: any;
50
+ } & {
51
+ [K in keyof U]?: any;
52
+ } & {
53
+ [K in U extends any ? keyof U : keyof U]?: any;
54
+ })]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never;
55
+ } : T & U;
56
+ type Simplify<T> = T extends any ? {
57
+ [K in keyof T]: T[K];
58
+ } : T;
59
+ type _Merge<T extends unknown[], Curr = {}> = T extends [
60
+ infer Next | (() => infer Next),
61
+ ...infer Rest
62
+ ] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
63
+ export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
64
+ /**
65
+ * Merges multiple props-like objects into a single proxy that *preserves
66
+ * reactivity*. Reads are forwarded to the right-most source that defines the
67
+ * property, so later sources override earlier ones (like `Object.assign`).
68
+ *
69
+ * Function arguments are treated as memo-backed sources — useful for passing
70
+ * derived defaults whose computation should track reactively.
71
+ *
72
+ * Use this in component bodies to merge defaults / overrides without losing
73
+ * Solid's per-property tracking.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * function Button(_props: { label: string; type?: string; disabled?: boolean }) {
78
+ * const props = merge({ type: "button", disabled: false }, _props);
79
+ *
80
+ * return <button type={props.type} disabled={props.disabled}>{props.label}</button>;
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
85
+ export type Omit<T, K extends readonly (keyof T)[]> = {
86
+ [P in keyof T as Exclude<P, K[number]>]: T[P];
87
+ };
88
+ /**
89
+ * Returns a reactive proxy of `props` with the listed keys hidden. Tracking
90
+ * on the remaining keys is preserved.
91
+ *
92
+ * Use it to forward "rest" props to a child element while pulling out the
93
+ * keys your component handles itself — the equivalent of `splitProps(p, ["a","b"])[1]`.
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * function Input(props: { label: string; value: string; onInput: (v: string) => void } & JSX.HTMLAttributes<HTMLInputElement>) {
98
+ * const rest = omit(props, "label", "value", "onInput");
99
+ *
100
+ * return (
101
+ * <label>
102
+ * {props.label}
103
+ * <input
104
+ * {...rest}
105
+ * value={props.value}
106
+ * onInput={e => props.onInput(e.currentTarget.value)}
107
+ * />
108
+ * </label>
109
+ * );
110
+ * }
111
+ * ```
112
+ */
113
+ export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
114
+ export {};
@@ -1,19 +1,45 @@
1
- import { $REFRESH } from "../core/index.js";
1
+ import { type Refreshable } from "../core/index.js";
2
2
  import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from "./store.js";
3
3
  /**
4
- * Creates an optimistic store that can be used to optimistically update a value
5
- * and then revert it back to the previous value at end of transition.
4
+ * The store equivalent of `createOptimistic`. Writes inside an `action`
5
+ * transition are tentative they show up immediately but auto-revert (or
6
+ * reconcile to the action's resolved value) once the transition finishes.
6
7
  *
7
- * When called with a plain value, creates an optimistic store.
8
- * When called with a function, creates a derived optimistic store with `ProjectionOptions` (name, key, all).
8
+ * Use this for optimistic UI on collection-shaped data. For single-value
9
+ * optimistic state, prefer `createOptimistic`.
9
10
  *
10
- * @param fn a function that receives the current store and can be used to mutate it directly inside a transition
11
- * @param initial The initial value of the store.
12
- * @param options Optional projection options for reconciliation.
11
+ * - Plain form: `createOptimisticStore(initialValue)`.
12
+ * - Derived form: `createOptimisticStore(fn, seed, options?)` a projection
13
+ * store whose authoritative value is recomputed by `fn` and whose
14
+ * optimistic overlay reverts after each transition.
13
15
  *
14
- * @returns A tuple containing a store accessor and a setter function to apply changes.
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.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const [todos, setTodos] = createOptimisticStore<Todo[]>([]);
23
+ *
24
+ * // Mutation: optimistic add, then in-place reconcile to the saved row.
25
+ * const addTodo = action(function* (text: string) {
26
+ * const tempId = crypto.randomUUID();
27
+ * setTodos(t => { t.push({ id: tempId, text, pending: true }); });
28
+ * const saved = yield api.createTodo(text);
29
+ * setTodos(t => {
30
+ * const i = t.findIndex(x => x.id === tempId);
31
+ * if (i >= 0) t[i] = saved;
32
+ * });
33
+ * });
34
+ *
35
+ * // Return form: filter is the natural shape for removal.
36
+ * const removeTodo = action(function* (id: string) {
37
+ * setTodos(t => t.filter(x => x.id !== id));
38
+ * yield api.removeTodo(id);
39
+ * });
40
+ * ```
41
+ *
42
+ * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
15
43
  */
16
44
  export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
17
- export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store?: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T> & {
18
- [$REFRESH]: any;
19
- }, set: StoreSetter<T>];
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,26 +1,66 @@
1
- import { $REFRESH, type Computed } from "../core/index.js";
1
+ import { type Computed, type Refreshable } from "../core/index.js";
2
2
  import { type ProjectionOptions, type Store } from "./store.js";
3
- export declare function createProjectionInternal<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, initialValue?: T, options?: ProjectionOptions): {
4
- store: Store<T> & {
5
- [$REFRESH]: any;
6
- };
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
+ store: Refreshable<Store<T>>;
7
5
  node: Computed<void | T>;
8
6
  };
9
7
  /**
10
- * Creates a mutable derived store (projection). The derive function receives a mutable
11
- * draft and can mutate it directly or return a new value for reconciliation.
8
+ * Creates a derived (projected) store. Like `createMemo` but for stores: the
9
+ * derive function receives a mutable draft and either mutates it in place
10
+ * (canonical) or returns a new value. Either way the result is reconciled
11
+ * against the previous draft by `options.key` (default `"id"`), so surviving
12
+ * items keep their proxy identity — only added/removed items are
13
+ * created/disposed.
12
14
  *
13
- * ```typescript
14
- * const store = createProjection<T>(fn, initialValue?, options?: ProjectionOptions);
15
+ * Returns the projected store directly (no setter — reads only).
16
+ *
17
+ * Use this when you want the structural-sharing / per-property tracking
18
+ * behaviour of a store on top of a derived computation. For simple read-only
19
+ * derivations, `createMemo` is lighter.
20
+ *
21
+ * @param fn receives the current draft; mutate it in place or return new
22
+ * data. Return is convenient for filter/derive shapes where mutation is
23
+ * awkward.
24
+ * @param seed the backing store value to wrap and reconcile into
25
+ * @param options `ProjectionOptions` — `name`, `key`. `key` defaults to
26
+ * `"id"`; specify it only when your data uses a different identity field
27
+ * (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`).
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Mutation form — update individual fields on the draft.
32
+ * const summary = createProjection<{ total: number; active: number }>(
33
+ * draft => {
34
+ * draft.total = users().length;
35
+ * draft.active = users().filter(u => u.active).length;
36
+ * },
37
+ * { total: 0, active: 0 }
38
+ * );
39
+ *
40
+ * // Return form — produce a derived collection. Reconciled by `id` so each
41
+ * // surviving user keeps the same store identity across recomputes.
42
+ * const activeUsers = createProjection<User[]>(
43
+ * () => allUsers().filter(u => u.active),
44
+ * []
45
+ * );
15
46
  * ```
16
- * @param fn a function that receives the current draft and mutates it or returns new data
17
- * @param initialValue the initial store value (defaults to `{}`)
18
- * @param options `ProjectionOptions` -- name, key, all
19
47
  *
20
48
  * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
21
49
  */
22
- export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, initialValue?: T, options?: ProjectionOptions): Store<T> & {
23
- [$REFRESH]: any;
24
- };
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>>;
51
+ /**
52
+ * Shared projection computed body used by both `createProjection` and the derived
53
+ * form of `createOptimisticStore`. Encapsulates the write-trap draft, `storeSetter`
54
+ * wrapping, the `handleAsync` subscription with a setter callback, and the commit
55
+ * path (which must always go through `storeSetter` so the `writeOnly` guard is
56
+ * engaged during `reconcile`'s property reads).
57
+ *
58
+ * `wrapCommit` is invoked for every commit (sync return and each async yield) and
59
+ * lets callers layer extra context around the write — e.g. the optimistic store
60
+ * re-enters `setProjectionWriteActive` so reconciles target `STORE_OVERRIDE`
61
+ * instead of `STORE_OPTIMISTIC_OVERRIDE` even when an async yield fires outside
62
+ * the outer `setProjectionWriteActive` scope.
63
+ */
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>;
25
65
  export declare function createWriteTraps(isActive?: () => boolean): ProxyHandler<any>;
26
66
  export declare const writeTraps: ProxyHandler<any>;
@@ -1 +1,23 @@
1
+ /**
2
+ * 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.
6
+ *
7
+ * Items with the same key are updated in place (only changed properties
8
+ * trigger updates). Items added or removed update the corresponding signals.
9
+ *
10
+ * @param value the next state to merge in
11
+ * @param key property name (string) or extractor function for stable identity
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const [todos, setTodos] = createStore<Todo[]>([]);
16
+ *
17
+ * async function refresh() {
18
+ * const fresh = await api.getTodos();
19
+ * setTodos(reconcile(fresh, "id")); // diff-merge by `id`
20
+ * }
21
+ * ```
22
+ */
1
23
  export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
@@ -1,5 +1,21 @@
1
- import { $REFRESH, STORE_SNAPSHOT_PROPS, type Computed, type Signal } from "../core/index.js";
1
+ import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
2
+ /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
2
3
  export type Store<T> = Readonly<T>;
4
+ /**
5
+ * A store setter. The callback receives a writable **draft** of the store.
6
+ *
7
+ * - **Mutate in place (canonical):** `s.foo = 1`, `s.list.push(x)`,
8
+ * `s.list.splice(i, 1)`. This is the default form for most updates.
9
+ * - **Return a new value:** for shapes where mutation is awkward, most
10
+ * commonly removing items (`s => s.list.filter(...)`). Arrays are replaced
11
+ * by index (length adjusted); objects are shallow-diffed at the top level
12
+ * (keys present in the returned value are written, missing keys deleted).
13
+ *
14
+ * The setter does **not** perform keyed reconciliation. If you need surviving
15
+ * items to keep their store identity across full-array replacement, use the
16
+ * projection form — `createStore(fn, seed, { key })` or `createProjection` —
17
+ * whose derive function reconciles its return by `options.key`.
18
+ */
3
19
  export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
4
20
  /** Base options for store primitives. */
5
21
  export interface StoreOptions {
@@ -14,8 +30,14 @@ export interface ProjectionOptions extends StoreOptions {
14
30
  export type NoFn<T> = T extends Function ? never : T;
15
31
  type DataNode = Signal<any>;
16
32
  type DataNodes = Record<PropertyKey, DataNode>;
33
+ /**
34
+ * Brand symbols used internally by the store proxy / projection plumbing.
35
+ * Cross-package wiring; not part of the user-facing API.
36
+ *
37
+ * @internal
38
+ */
17
39
  export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
18
- 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";
40
+ export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p";
19
41
  export type StoreNode = {
20
42
  [$PROXY]: any;
21
43
  [STORE_VALUE]: Record<PropertyKey, any>;
@@ -23,6 +45,7 @@ export type StoreNode = {
23
45
  [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
24
46
  [STORE_NODE]?: DataNodes;
25
47
  [STORE_HAS]?: DataNodes;
48
+ [STORE_CUSTOM_PROTO]?: boolean;
26
49
  [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
27
50
  [STORE_LOOKUP]?: WeakMap<any, any>;
28
51
  [STORE_FIREWALL]?: Computed<any>;
@@ -45,24 +68,58 @@ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>,
45
68
  export declare const storeTraps: ProxyHandler<StoreNode>;
46
69
  export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
47
70
  /**
48
- * Creates a deeply reactive store with proxy-based tracking.
71
+ * Creates a deeply-reactive store backed by a Proxy. Reads track each property
72
+ * accessed; only the parts that change trigger updates.
49
73
  *
50
- * When called with a plain value, wraps it in a reactive proxy.
51
- * When called with a function, creates a derived projection store with `ProjectionOptions` (name, key, all).
74
+ * Store properties hold **plain values**, not accessors. The proxy already
75
+ * tracks reads per-property wrapping a value in `() => state.foo` produces
76
+ * a getter that *won't* track when called, which looks like a reactivity bug
77
+ * but is just a category error. If you have a signal-shaped piece of state,
78
+ * make it a property of the store (`{ foo: 1 }`) rather than nesting an
79
+ * accessor inside (`{ foo: () => signal() }`).
80
+ *
81
+ * The setter takes a **draft-mutating** function — mutate the draft in place
82
+ * (canonical). The callback may also return a new value: arrays are replaced
83
+ * by index (length adjusted), objects are shallow-diffed at the top level
84
+ * (keys present in the returned value are written, missing keys deleted). Use
85
+ * the return form for shapes where mutation is awkward — most commonly
86
+ * removing items via `filter`. The setter does **not** do keyed reconciliation;
87
+ * for that, use the derived/projection form (or `createProjection`).
88
+ *
89
+ * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
90
+ * proxy.
91
+ * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
92
+ * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
93
+ * an `AsyncIterable`; the projection's result reconciles against the
94
+ * existing store by `options.key` (default `"id"`) for stable identity.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const [state, setState] = createStore({
99
+ * user: { name: "Ada", age: 36 },
100
+ * todos: [] as { id: string; text: string; done: boolean }[]
101
+ * });
102
+ *
103
+ * // Canonical: mutate the draft in place.
104
+ * setState(s => { s.user.age = 37; });
105
+ * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
106
+ *
107
+ * // Return form: reach for it when mutation is awkward.
108
+ * setState(s => s.todos.filter(t => !t.done)); // remove items
109
+ * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
110
+ * ```
52
111
  *
53
- * ```typescript
54
- * // Plain store
55
- * const [store, setStore] = createStore<T>(initialValue);
56
- * // Derived store (projection)
57
- * const [store, setStore] = createStore<T>(fn, initialValue?, options?: ProjectionOptions);
112
+ * @example
113
+ * ```ts
114
+ * // Derived store auto-fetches & reconciles by `id`.
115
+ * const [users] = createStore(
116
+ * async () => fetch("/users").then(r => r.json()),
117
+ * [] as User[]
118
+ * );
58
119
  * ```
59
- * @param store initial value to wrap in a reactive proxy, or a derive function
60
- * @param options `ProjectionOptions` -- name, key, all (only for derived stores)
61
120
  *
62
121
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
63
122
  */
64
123
  export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
65
- export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store?: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T> & {
66
- [$REFRESH]: any;
67
- }, set: StoreSetter<T>];
124
+ 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>];
68
125
  export {};
@@ -26,5 +26,33 @@ export interface storePath {
26
26
  <T, K1 extends KeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: PathSetter<W<T>[K1]>): (state: T) => void;
27
27
  <T>(setter: PathSetter<T>): (state: T) => void;
28
28
  }
29
+ /**
30
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
31
+ * to produce a draft-mutating function suitable for passing to `setStore`.
32
+ *
33
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
34
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
35
+ * compatibility helper for users porting from Solid 1.x's
36
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
37
+ * two styles freely.
38
+ *
39
+ * Path parts can be:
40
+ * - a single key — `"user"`, `0`
41
+ * - an array of keys — `[0, 1, 2]`
42
+ * - a range over an array — `{ from?, to?, by? }`
43
+ * - a filter `(item, index) => boolean` for arrays
44
+ *
45
+ * The final argument is the new value or an updater `(prev) => next`. Use
46
+ * `storePath.DELETE` to remove a property.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
51
+ *
52
+ * setState(storePath("user", "name", "Grace"));
53
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
54
+ * setState(storePath("user", "nickname", storePath.DELETE));
55
+ * ```
56
+ */
29
57
  export declare const storePath: storePath;
30
58
  export {};