stroid 0.1.0 → 0.1.2

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 (163) hide show
  1. package/CHANGELOG.md +232 -108
  2. package/README.md +157 -577
  3. package/dist/async.d.ts +5 -3
  4. package/dist/async.js +28 -23
  5. package/dist/async.js.map +1 -0
  6. package/dist/cache.d.ts +12 -0
  7. package/dist/computed.d.ts +19 -8
  8. package/dist/computed.js +12 -10
  9. package/dist/computed.js.map +1 -0
  10. package/dist/core.d.ts +5 -5
  11. package/dist/core.js +16 -23
  12. package/dist/core.js.map +1 -0
  13. package/dist/devtools.d.ts +12 -1
  14. package/dist/devtools.js +2 -1
  15. package/dist/devtools.js.map +1 -0
  16. package/dist/feature.d.ts +92 -0
  17. package/dist/feature.js +2 -0
  18. package/dist/feature.js.map +1 -0
  19. package/dist/helpers.d.ts +13 -5
  20. package/dist/helpers.js +16 -13
  21. package/dist/helpers.js.map +1 -0
  22. package/dist/index-internal.d.ts +44 -0
  23. package/dist/index.d.cts +91 -52
  24. package/dist/index.d.ts +91 -52
  25. package/dist/index.js +27 -21
  26. package/dist/index.js.map +1 -0
  27. package/dist/install.d.ts +6 -0
  28. package/dist/install.js +2 -0
  29. package/dist/install.js.map +1 -0
  30. package/dist/{options-CB35e3Xo.d.cts → options.d.ts} +52 -2
  31. package/dist/persist.d.ts +1 -2
  32. package/dist/persist.js +2 -1
  33. package/dist/persist.js.map +1 -0
  34. package/dist/{react.d.cts → react/index.d.ts} +28 -10
  35. package/dist/react/index.js +38 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/registry.d.ts +117 -0
  38. package/dist/runtime-admin.js +2 -1
  39. package/dist/runtime-admin.js.map +1 -0
  40. package/dist/runtime-tools.d.ts +44 -17
  41. package/dist/runtime-tools.js +3 -2
  42. package/dist/runtime-tools.js.map +1 -0
  43. package/dist/selectors.js +2 -1
  44. package/dist/selectors.js.map +1 -0
  45. package/dist/server.d.ts +27 -11
  46. package/dist/server.js +12 -9
  47. package/dist/server.js.map +1 -0
  48. package/dist/store-registry.d.ts +80 -0
  49. package/dist/sync.d.ts +1 -2
  50. package/dist/sync.js +2 -1
  51. package/dist/sync.js.map +1 -0
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +16 -13
  54. package/dist/testing.js.map +1 -0
  55. package/dist/tsdoc-metadata.json +11 -0
  56. package/dist/types/adapters/options.d.ts +90 -2
  57. package/dist/types/async/cache.d.ts +39 -0
  58. package/dist/types/async/clone.d.ts +9 -1
  59. package/dist/types/{async-fetch.d.ts → async/fetch.d.ts} +2 -2
  60. package/dist/types/async/inflight.d.ts +1 -1
  61. package/dist/types/{async-registry.d.ts → async/registry.d.ts} +25 -5
  62. package/dist/types/async/request.d.ts +9 -1
  63. package/dist/types/async.d.ts +10 -2
  64. package/dist/types/{computed-graph.d.ts → computed/computed-graph.d.ts} +4 -6
  65. package/dist/types/{computed.d.ts → computed/index.d.ts} +3 -2
  66. package/dist/types/config.d.ts +9 -1
  67. package/dist/types/core/index.d.ts +11 -0
  68. package/dist/types/core/lifecycle-hooks.d.ts +16 -0
  69. package/dist/types/core/store-admin-impl.d.ts +9 -0
  70. package/dist/types/core/store-admin.d.ts +9 -0
  71. package/dist/types/core/store-core.d.ts +13 -0
  72. package/dist/types/core/store-create.d.ts +16 -0
  73. package/dist/types/core/store-hydrate-impl.d.ts +35 -0
  74. package/dist/types/core/store-hydrate.d.ts +9 -0
  75. package/dist/types/core/store-lifecycle/hooks.d.ts +19 -0
  76. package/dist/types/{store-lifecycle → core/store-lifecycle}/identity.d.ts +3 -3
  77. package/dist/types/{store-lifecycle → core/store-lifecycle}/registry.d.ts +22 -8
  78. package/dist/types/{store-lifecycle → core/store-lifecycle}/types.d.ts +29 -1
  79. package/dist/types/{store-lifecycle → core/store-lifecycle}/validation.d.ts +11 -3
  80. package/dist/types/core/store-name.d.ts +28 -0
  81. package/dist/types/{store-notify.d.ts → core/store-notify.d.ts} +1 -1
  82. package/dist/types/{store-read.d.ts → core/store-read.d.ts} +8 -2
  83. package/dist/types/{store-registry.d.ts → core/store-registry.d.ts} +44 -10
  84. package/dist/types/core/store-replace-impl.d.ts +11 -0
  85. package/dist/types/core/store-replace.d.ts +9 -0
  86. package/dist/types/core/store-set-impl.d.ts +13 -0
  87. package/dist/types/core/store-set.d.ts +9 -0
  88. package/dist/types/core/store-shared/core.d.ts +13 -0
  89. package/dist/types/core/store-shared/notify.d.ts +12 -0
  90. package/dist/types/{store-transaction.d.ts → core/store-transaction.d.ts} +15 -1
  91. package/dist/types/core/store-write-shared.d.ts +19 -0
  92. package/dist/types/core/store-write.d.ts +13 -0
  93. package/dist/types/features/feature-registry.d.ts +91 -0
  94. package/dist/types/features/lifecycle.d.ts +12 -0
  95. package/dist/types/index.d.ts +13 -2
  96. package/dist/types/integrations/query.d.ts +2 -2
  97. package/dist/types/internals/computed-order.d.ts +3 -0
  98. package/dist/types/internals/config.d.ts +56 -2
  99. package/dist/types/internals/reporting.d.ts +1 -0
  100. package/dist/types/internals/store-admin.d.ts +1 -1
  101. package/dist/types/internals/store-ops.d.ts +13 -3
  102. package/dist/types/internals/test-reset.d.ts +2 -0
  103. package/dist/types/internals/write-context.d.ts +15 -0
  104. package/dist/types/notification/delivery.d.ts +3 -0
  105. package/dist/types/notification/index.d.ts +10 -0
  106. package/dist/types/notification/metrics.d.ts +12 -0
  107. package/dist/types/notification/priority.d.ts +9 -0
  108. package/dist/types/notification/scheduler.d.ts +11 -0
  109. package/dist/types/notification/snapshot.d.ts +8 -0
  110. package/dist/types/runtime-tools/index.d.ts +58 -0
  111. package/dist/types/store.d.ts +16 -7
  112. package/dist/types/types/utility.d.ts +17 -0
  113. package/dist/types/utils/devfreeze.d.ts +2 -0
  114. package/dist/types/utils.d.ts +8 -0
  115. package/dist/{types-grvlY4BX.d.cts → types.d.ts} +30 -2
  116. package/dist/utility.d.ts +15 -0
  117. package/package.json +35 -11
  118. package/dist/async-cache-DFHwcBQL.d.cts +0 -52
  119. package/dist/async-cache-DFHwcBQL.d.ts +0 -52
  120. package/dist/async.cjs +0 -29
  121. package/dist/async.d.cts +0 -40
  122. package/dist/computed-BbAZm1Dq.d.cts +0 -17
  123. package/dist/computed-CccdgY5j.d.ts +0 -17
  124. package/dist/computed.cjs +0 -11
  125. package/dist/computed.d.cts +0 -29
  126. package/dist/core.cjs +0 -30
  127. package/dist/core.d.cts +0 -5
  128. package/dist/devtools.cjs +0 -1
  129. package/dist/devtools.d.cts +0 -19
  130. package/dist/helpers.cjs +0 -20
  131. package/dist/helpers.d.cts +0 -29
  132. package/dist/index.cjs +0 -30
  133. package/dist/options-CB35e3Xo.d.ts +0 -245
  134. package/dist/persist.cjs +0 -1
  135. package/dist/persist.d.cts +0 -2
  136. package/dist/react.cjs +0 -31
  137. package/dist/react.d.ts +0 -52
  138. package/dist/react.js +0 -31
  139. package/dist/runtime-admin.cjs +0 -1
  140. package/dist/runtime-admin.d.cts +0 -4
  141. package/dist/runtime-tools.cjs +0 -3
  142. package/dist/runtime-tools.d.cts +0 -39
  143. package/dist/selectors.cjs +0 -1
  144. package/dist/selectors.d.cts +0 -4
  145. package/dist/server.cjs +0 -10
  146. package/dist/server.d.cts +0 -14
  147. package/dist/sync.cjs +0 -1
  148. package/dist/sync.d.cts +0 -2
  149. package/dist/testing.cjs +0 -20
  150. package/dist/testing.d.cts +0 -16
  151. package/dist/types/async-cache.d.ts +0 -57
  152. package/dist/types/core.d.ts +0 -1
  153. package/dist/types/devfreeze.d.ts +0 -1
  154. package/dist/types/feature-registry.d.ts +0 -69
  155. package/dist/types/internals/hooks-warnings.d.ts +0 -6
  156. package/dist/types/store-lifecycle/bind.d.ts +0 -3
  157. package/dist/types/store-lifecycle/hooks.d.ts +0 -44
  158. package/dist/types/store-lifecycle.d.ts +0 -20
  159. package/dist/types/store-name.d.ts +0 -19
  160. package/dist/types/store-write.d.ts +0 -45
  161. package/dist/types-grvlY4BX.d.ts +0 -37
  162. /package/dist/types/{async-retry.d.ts → async/retry.d.ts} +0 -0
  163. /package/dist/types/{runtime-admin.d.ts → runtime-admin/index.d.ts} +0 -0
@@ -1,5 +1,13 @@
1
- import { type SupportedType, PathInput } from "../utils.js";
2
- import { type ValidateOption } from "../adapters/options.js";
1
+ /**
2
+ * @module store-lifecycle/validation
3
+ *
4
+ * LAYER: Store lifecycle
5
+ * OWNS: Module-level behavior and exports for store-lifecycle/validation.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import { type SupportedType, PathInput } from "../../utils.js";
10
+ import { type ValidateOption } from "../../adapters/options.js";
3
11
  import type { StoreValue } from "./types.js";
4
12
  type PathSafetyVerdict = {
5
13
  ok: true;
@@ -41,5 +49,5 @@ export declare const normalizeCommittedState: (name: string, value: unknown, val
41
49
  };
42
50
  export declare const invalidatePathCache: (name: string) => void;
43
51
  export declare const clearPathValidationCache: () => void;
44
- export declare const materializeInitial: (name: string) => boolean;
52
+ export declare const materializeInitial: (name: string, registry?: import("../store-registry.js").StoreRegistry) => boolean;
45
53
  export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module store-name
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Module-level behavior and exports for store-name.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import type { StoreKey, StoreValue } from "./store-lifecycle/types.js";
10
+ import type { StoreOptions } from "../adapters/options.js";
11
+ import type { NonFunction } from "../types/utility.js";
12
+ /**
13
+ * Helper to get an auto-completable, literal-typed store handle without creating it.
14
+ *
15
+ * Example:
16
+ * const user = store("user");
17
+ * setStore(user, "name", "Alex");
18
+ */
19
+ export declare const store: <Name extends string, State = StoreValue>(name: Name) => StoreKey<Name, State>;
20
+ export declare const namespace: (ns: string) => {
21
+ store: <Name extends string, State = unknown>(name: Name) => StoreKey<Name, State>;
22
+ create: <Name extends string, State>(name: Name, data: NonFunction<State>, options?: StoreOptions<State>) => import("./store-lifecycle/types.js").StoreDefinition<string, State> | undefined;
23
+ createStrict: <Name extends string, State>(name: Name, data: NonFunction<State>, options?: StoreOptions<State>) => import("./store-lifecycle/types.js").StoreDefinition<string, State>;
24
+ set: (name: any, ...rest: any[]) => any;
25
+ get: (name: any, ...rest: any[]) => any;
26
+ delete: (name: string) => void;
27
+ reset: (name: string) => import("./store-lifecycle/types.js").WriteResult;
28
+ };
@@ -1,4 +1,4 @@
1
- import { type StoreValue, type Subscriber } from "./store-lifecycle.js";
1
+ import type { StoreValue, Subscriber } from "./store-lifecycle/types.js";
2
2
  export declare const notify: (name: string) => void;
3
3
  export declare const setStoreBatch: (fn: () => unknown) => void;
4
4
  export declare const subscribeStore: (name: string, fn: Subscriber) => (() => void);
@@ -1,4 +1,7 @@
1
- import { meta, hasStoreEntryInternal, getStoreValueRef, getFeatureApi, type Path, type PathValue, type StoreDefinition, type StoreValue, type StoreKey, type StoreName, type StateFor } from "./store-lifecycle.js";
1
+ import { hasStoreEntryInternal, getStoreValueRef } from "./store-lifecycle/registry.js";
2
+ import { getFeatureApi } from "./store-lifecycle/identity.js";
3
+ import type { Path, PathValue, StoreDefinition, StoreValue, StoreKey, StoreName, StateFor } from "./store-lifecycle/types.js";
4
+ import type { FeatureMetrics } from "../features/feature-registry.js";
2
5
  type StoreSnapshot<T> = T extends object ? Readonly<T> : T;
3
6
  export declare function getStore<Name extends string, State, P extends Path<State>>(name: StoreDefinition<Name, State>, path: P): StoreSnapshot<PathValue<State, P>> | null;
4
7
  export declare function getStore<Name extends string, State>(name: StoreDefinition<Name, State>, path?: undefined): StoreSnapshot<State> | null;
@@ -7,6 +10,9 @@ export declare function getStore<Name extends string, State>(name: StoreKey<Name
7
10
  export declare function getStore<Name extends StoreName, P extends Path<StateFor<Name>>>(name: Name, path: P): StoreSnapshot<PathValue<StateFor<Name>, P>> | null;
8
11
  export declare function getStore<Name extends StoreName>(name: Name, path?: undefined): StoreSnapshot<StateFor<Name>> | null;
9
12
  export declare const hasStore: (name: string) => boolean;
13
+ export declare const isLazyStore: (name: string) => boolean;
14
+ export declare const isStoreMaterialized: (name: string) => boolean;
15
+ export declare const isLazyPending: (name: string) => boolean;
10
16
  export { hasStoreEntryInternal as _hasStoreEntryInternal, getStoreValueRef as _getStoreValueRef, getFeatureApi as _getFeatureApi };
11
17
  export declare const getInitialState: () => Record<string, StoreValue>;
12
- export declare const getMetrics: (name: string) => (typeof meta)[string]["metrics"] | null;
18
+ export declare const getMetrics: (name: string) => FeatureMetrics | null;
@@ -1,36 +1,63 @@
1
1
  /**
2
2
  * @module store-registry
3
3
  *
4
- * LAYER: Dumb Data Container
5
- * OWNS: The shape of a StoreRegistry, the global map of all scoped registries,
6
- * and the SSR carrier-context injection point.
4
+ * LAYER: Store runtime
5
+ * OWNS: Module-level behavior and exports for store-registry.
7
6
  *
8
- * DOES NOT KNOW about: validation, features, hooks, React, or any write logic.
9
- * It is a plain key-value store factory — nothing more.
10
- *
11
- * Consumers: store-lifecycle (binds a registry scope on startup / SSR switch).
7
+ * Consumers: Internal imports and public API.
12
8
  */
13
- import type { FeatureName, StoreFeatureMeta, StoreFeatureRuntime } from "./feature-registry.js";
14
- import type { AsyncRegistry } from "./async-registry.js";
9
+ import { type FeatureName, type StoreFeatureMeta, type StoreFeatureRuntime } from "../features/feature-registry.js";
10
+ import type { AsyncRegistry } from "../async/registry.js";
15
11
  export type RegistryStoreValue = unknown;
16
12
  export type RegistrySubscriber = (value: RegistryStoreValue | null) => void;
17
13
  export type RegistrySnapshotEntry = {
18
14
  version: number;
19
15
  snapshot: RegistryStoreValue | null;
16
+ source?: RegistryStoreValue | null;
17
+ mode?: "deep" | "shallow" | "ref";
18
+ };
19
+ export type StoreLifecycleEvent = {
20
+ type: "created";
21
+ name: string;
22
+ isGlobal: boolean;
23
+ isTemp: boolean;
24
+ } | {
25
+ type: "deleted";
26
+ name: string;
20
27
  };
28
+ export type StoreLifecycleListener = (event: StoreLifecycleEvent) => void;
21
29
  export type TransactionState = {
22
30
  depth: number;
23
31
  pending: Array<() => void>;
24
32
  stagedValues: Map<string, RegistryStoreValue>;
33
+ snapshotCache: Map<string, TransactionSnapshotEntry>;
25
34
  failed: boolean;
26
35
  error?: Error;
27
36
  };
37
+ type TransactionSnapshotMode = "deep" | "shallow" | "ref";
38
+ type TransactionSnapshotEntry = {
39
+ source: RegistryStoreValue | null | undefined;
40
+ snapshot: RegistryStoreValue | null;
41
+ mode: TransactionSnapshotMode;
42
+ };
28
43
  export type ComputedEntry = {
29
44
  deps: string[];
30
45
  compute: (...args: unknown[]) => unknown;
31
46
  stale: boolean;
32
47
  };
48
+ export type NotifyState = {
49
+ pendingNotifications: Set<string>;
50
+ pendingBuffer: string[];
51
+ orderedNames: string[];
52
+ subscriberBuffer: RegistrySubscriber[];
53
+ notifyScheduled: boolean;
54
+ batchDepth: number;
55
+ flushId: number;
56
+ isFlushing: boolean;
57
+ };
58
+ export type RegistryScope = "default" | "request";
33
59
  export type StoreRegistry = {
60
+ scope: RegistryScope;
34
61
  stores: Record<string, RegistryStoreValue>;
35
62
  subscribers: Record<string, Set<RegistrySubscriber>>;
36
63
  initialStates: Record<string, RegistryStoreValue>;
@@ -44,17 +71,23 @@ export type StoreRegistry = {
44
71
  computedCleanups: Map<string, () => void>;
45
72
  transaction: TransactionState;
46
73
  async: AsyncRegistry;
74
+ notify: NotifyState;
75
+ lifecycleListener: StoreLifecycleListener | null;
47
76
  };
77
+ export declare const initializeRegistryFeatureRuntimes: (registry: StoreRegistry) => void;
48
78
  export declare const normalizeStoreRegistryScope: (scope: string) => string;
49
79
  export declare const defaultRegistryScope: string;
50
80
  export declare const getDefaultStoreRegistry: () => StoreRegistry;
51
81
  export declare const setRegistryScope: (scope: string) => void;
52
82
  export declare const clearRegistryScopeOverrideForTests: () => void;
53
- export declare const createStoreRegistry: () => StoreRegistry;
83
+ export declare const createTransactionState: () => TransactionState;
84
+ export declare const createStoreRegistry: (scope?: RegistryScope) => StoreRegistry;
54
85
  export declare const getStoreRegistry: (scope: string) => StoreRegistry;
55
86
  export declare const hasStoreEntry: (registry: StoreRegistry, name: string) => boolean;
56
87
  export declare const isStoreDeleting: (registry: StoreRegistry, name: string) => boolean;
57
88
  export declare const clearStoreRegistries: (registry: StoreRegistry) => void;
89
+ export declare const setLifecycleListener: (registry: StoreRegistry, listener: StoreLifecycleListener | null) => void;
90
+ export declare const emitLifecycleEvent: (registry: StoreRegistry, event: StoreLifecycleEvent) => void;
58
91
  export declare const resetAllStoreRegistriesForTests: () => void;
59
92
  export type CarrierContext = Record<string, unknown>;
60
93
  export interface CarrierRunner {
@@ -72,3 +105,4 @@ export declare const injectRegistryRunner: (runner: RegistryRunner) => void;
72
105
  export declare const runWithRegistry: <T>(registry: StoreRegistry, fn: () => T) => T;
73
106
  export declare const getActiveStoreRegistry: (fallback?: StoreRegistry) => StoreRegistry;
74
107
  export declare const enterRegistry: (registry: StoreRegistry) => void;
108
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { StoreDefinition, StoreKey, StoreName, StateFor, WriteResult } from "./store-lifecycle/types.js";
2
+ import type { StoreRegistry } from "./store-registry.js";
3
+ import type { WriteContext } from "../internals/write-context.js";
4
+ import { type CommitAction } from "./store-write-shared.js";
5
+ export declare function replaceStore<Name extends string, State>(name: StoreDefinition<Name, State>, value: State): WriteResult;
6
+ export declare function replaceStore<Name extends string, State>(name: StoreKey<Name, State>, value: State): WriteResult;
7
+ export declare function replaceStore<Name extends StoreName>(name: Name, value: StateFor<Name>): WriteResult;
8
+ export declare const replaceStoreState: (registry: StoreRegistry, name: string, data: unknown, action?: CommitAction, context?: WriteContext | null) => {
9
+ ok: boolean;
10
+ reason?: string;
11
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module store-replace
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Public replaceStore exports.
6
+ *
7
+ * Consumers: store-write barrel.
8
+ */
9
+ export { replaceStore } from "./store-replace-impl.js";
@@ -0,0 +1,13 @@
1
+ import type { PartialDeep, Path, PathValue, StoreDefinition, StoreValue, StoreKey, StoreName, StateFor, WriteResult } from "./store-lifecycle/types.js";
2
+ import type { WriteContext } from "../internals/write-context.js";
3
+ type KeyOrData = StoreValue | string | string[] | Record<string, unknown> | ((draft: any) => void);
4
+ type IsStoreNameLoose = string extends StoreName ? true : false;
5
+ type StoreUpdate<State> = State | Partial<State> | PartialDeep<State> | ((draft: State) => void);
6
+ type StoreTarget<Name extends string = string, State = StoreValue> = StoreDefinition<Name, State> | StoreKey<Name, State> | StoreName;
7
+ type StorePathForTarget<T> = T extends StoreDefinition<any, infer S> ? Path<S> : T extends StoreKey<any, infer S> ? Path<S> : (IsStoreNameLoose extends true ? string | string[] : (T extends StoreName ? Path<StateFor<T>> : string | string[]));
8
+ type StorePathValueForTarget<T, P> = T extends StoreDefinition<any, infer S> ? (P extends Path<S> ? PathValue<S, P> : never) : T extends StoreKey<any, infer S> ? (P extends Path<S> ? PathValue<S, P> : never) : (IsStoreNameLoose extends true ? unknown : (T extends StoreName ? (P extends Path<StateFor<T>> ? PathValue<StateFor<T>, P> : never) : unknown));
9
+ type StoreUpdateForTarget<T> = T extends StoreDefinition<any, infer S> ? StoreUpdate<S> : T extends StoreKey<any, infer S> ? StoreUpdate<S> : (IsStoreNameLoose extends true ? StoreUpdate<StoreValue> : (T extends StoreName ? StoreUpdate<StateFor<T>> : StoreUpdate<StoreValue>));
10
+ export declare function setStore<T extends StoreTarget, P extends StorePathForTarget<T>>(name: T, path: P, value: StorePathValueForTarget<T, P>): WriteResult;
11
+ export declare function setStore<T extends StoreTarget>(name: T, update: StoreUpdateForTarget<T>): WriteResult;
12
+ export declare const setStoreWithContext: (name: string | StoreDefinition<string, StoreValue>, keyOrData: KeyOrData, value: unknown, context: WriteContext | null) => WriteResult;
13
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module store-set
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Public setStore exports.
6
+ *
7
+ * Consumers: store-write barrel.
8
+ */
9
+ export { setStore, setStoreWithContext } from "./store-set-impl.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module store-shared/core
3
+ *
4
+ * LAYER: Shared types
5
+ * OWNS: Minimal interfaces shared across layers.
6
+ *
7
+ * Consumers: Internal modules (async-cache, adapters).
8
+ */
9
+ export interface IStoreCore<T = any> {
10
+ get(path?: string): T | null;
11
+ set(path: string, value: any): void;
12
+ subscribe(cb: (val: T | null) => void): () => void;
13
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module store-shared/notify
3
+ *
4
+ * LAYER: Shared types
5
+ * OWNS: Notification handler indirection for layer decoupling.
6
+ *
7
+ * Consumers: store-write, store-create, store-notify.
8
+ */
9
+ type NotifyHandler = (name: string) => void;
10
+ export declare const registerNotifyHandler: (handler: NotifyHandler | null) => (() => void);
11
+ export declare const notifyStore: (name: string) => void;
12
+ export {};
@@ -1,5 +1,19 @@
1
+ /**
2
+ * @module store-transaction
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Module-level behavior and exports for store-transaction.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
1
9
  import type { StoreValue } from "./store-lifecycle/types.js";
2
- import { type StoreRegistry } from "./store-registry.js";
10
+ import { type StoreRegistry, type TransactionState } from "./store-registry.js";
11
+ export type TransactionRunner = {
12
+ run: <T>(state: TransactionState, fn: () => T) => T;
13
+ get: () => TransactionState | null;
14
+ enterWith?: (state: TransactionState) => void;
15
+ };
16
+ export declare const injectTransactionRunner: (runner: TransactionRunner | null) => void;
3
17
  export declare const beginTransaction: (registry?: StoreRegistry) => StoreRegistry;
4
18
  export declare const isTransactionActive: () => boolean;
5
19
  export declare const markTransactionFailed: (err?: unknown, registry?: StoreRegistry) => void;
@@ -0,0 +1,19 @@
1
+ import { type WriteContext } from "../internals/write-context.js";
2
+ import type { StoreRegistry } from "./store-registry.js";
3
+ import type { StoreValue } from "./store-lifecycle/types.js";
4
+ export type CommitAction = "set" | "reset" | "hydrate" | "replace";
5
+ export type CommitHookLabel = "onSet" | "onReset";
6
+ export type CommitArgs = {
7
+ name: string;
8
+ prev: StoreValue;
9
+ next: StoreValue;
10
+ action: CommitAction;
11
+ hookLabel: CommitHookLabel;
12
+ logMessage: string;
13
+ context?: WriteContext | null;
14
+ };
15
+ export declare const clearSlowMutatorWarnings: () => void;
16
+ export declare const forgetSlowMutatorWarning: (storeName: string) => void;
17
+ export declare const maybeWarnSlowMutator: (storeName: string, elapsedMs: number) => void;
18
+ export declare const resolveWriteContext: (context?: WriteContext | null) => WriteContext | null;
19
+ export declare const stageOrCommitUpdate: (registry: StoreRegistry, args: CommitArgs) => void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module store-write
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Public write API surface (barrel).
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import "./store-notify.js";
10
+ export { setStore, setStoreWithContext } from "./store-set.js";
11
+ export { replaceStore } from "./store-replace.js";
12
+ export { hydrateStores } from "./store-hydrate.js";
13
+ export { deleteStore, resetStore, clearAllStores, _hardResetAllStoresForTest, } from "./store-admin.js";
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @module feature-registry
3
+ *
4
+ * LAYER: Module
5
+ * OWNS: Module-level behavior and exports for feature-registry.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import type { NormalizedOptions, StoreValue } from "../adapters/options.js";
10
+ import type { TraceContext } from "../types/utility.js";
11
+ export type BuiltInFeatureName = "persist" | "sync" | "devtools";
12
+ export type FeatureName = BuiltInFeatureName | (string & {});
13
+ export interface FeatureMetrics {
14
+ notifyCount: number;
15
+ totalNotifyMs: number;
16
+ lastNotifyMs: number;
17
+ resetCount: number;
18
+ totalResetMs: number;
19
+ lastResetMs: number;
20
+ }
21
+ export interface StoreFeatureMeta {
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ updatedAtMs: number;
25
+ updateCount: number;
26
+ version: number;
27
+ metrics: FeatureMetrics;
28
+ options: NormalizedOptions;
29
+ readCount: number;
30
+ lastReadAt: string | null;
31
+ lastReadAtMs: number | null;
32
+ lastCorrelationId: string | null;
33
+ lastCorrelationAt: string | null;
34
+ lastCorrelationAtMs: number | null;
35
+ lastTraceContext: TraceContext | null;
36
+ }
37
+ export interface FeatureHookContext {
38
+ name: string;
39
+ options: NormalizedOptions;
40
+ getMeta: () => StoreFeatureMeta | undefined;
41
+ getStoreValue: () => StoreValue;
42
+ getAllStores: () => Record<string, StoreValue>;
43
+ getInitialState: () => StoreValue;
44
+ hasStore: () => boolean;
45
+ setStoreValue: (value: StoreValue) => void;
46
+ applyFeatureState: (value: StoreValue, updatedAtMs?: number) => void;
47
+ notify: () => void;
48
+ reportStoreError: (message: string) => void;
49
+ warn: (message: string) => void;
50
+ warnAlways: (message: string) => void;
51
+ log: (message: string) => void;
52
+ hashState: (value: unknown) => number;
53
+ deepClone: <T>(value: T) => T;
54
+ sanitize: (value: unknown) => unknown;
55
+ validate: (next: StoreValue) => {
56
+ ok: boolean;
57
+ value?: StoreValue;
58
+ };
59
+ isDev: () => boolean;
60
+ }
61
+ /** @deprecated Use FeatureHookContext instead. */
62
+ export type BaseFeatureContext = FeatureHookContext;
63
+ export type FeatureCreateContext<Ext extends object = {}> = FeatureHookContext & Ext;
64
+ export type FeatureWriteContext<Ext extends object = {}> = FeatureHookContext & Ext & {
65
+ action: string;
66
+ prev: StoreValue;
67
+ next: StoreValue;
68
+ };
69
+ export type FeatureDeleteContext<Ext extends object = {}> = FeatureHookContext & Ext & {
70
+ prev: StoreValue;
71
+ };
72
+ export interface DevtoolsFeatureApi {
73
+ getHistory?: (name: string, limit?: number) => unknown[];
74
+ clearHistory?: (name?: string) => void;
75
+ getPersistQueueDepth?: (name: string) => number;
76
+ }
77
+ export interface StoreFeatureRuntime<Ext extends object = {}> {
78
+ onStoreCreate?: (ctx: FeatureCreateContext<Ext>) => void;
79
+ onStoreWrite?: (ctx: FeatureWriteContext<Ext>) => void;
80
+ beforeStoreDelete?: (ctx: FeatureDeleteContext<Ext>) => void;
81
+ afterStoreDelete?: (ctx: FeatureDeleteContext<Ext>) => void;
82
+ resetAll?: () => void;
83
+ api?: DevtoolsFeatureApi;
84
+ }
85
+ export type StoreFeatureFactory<Ext extends object = {}> = () => StoreFeatureRuntime<Ext>;
86
+ export declare const registerStoreFeature: <Ext extends object = {}>(name: FeatureName, factory: StoreFeatureFactory<Ext>) => void;
87
+ export declare const hasRegisteredStoreFeature: (name: FeatureName) => boolean;
88
+ export declare const getStoreFeatureFactory: (name: FeatureName) => StoreFeatureFactory<any> | undefined;
89
+ export declare const getRegisteredFeatureNames: () => FeatureName[];
90
+ export declare const setFeatureRegistrationHook: (hook: ((name: FeatureName, factory: StoreFeatureFactory<any>) => void) | null) => void;
91
+ export declare const resetRegisteredStoreFeaturesForTests: () => void;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @module features/lifecycle
3
+ *
4
+ * LAYER: Feature runtime
5
+ * OWNS: Module-level behavior and exports for features/lifecycle.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
1
9
  import type { StoreValue } from "../adapters/options.js";
2
10
  export declare const MIDDLEWARE_ABORT: unique symbol;
3
11
  export type LifecycleIssueReporter = (message: string, visibility?: "dev" | "always") => void;
@@ -8,6 +16,8 @@ export declare const runMiddleware: ({ name, payload, middlewares, reportIssue,
8
16
  prev: StoreValue;
9
17
  next: StoreValue;
10
18
  path: unknown;
19
+ correlationId?: string;
20
+ traceContext?: import("../types/utility.js").TraceContext;
11
21
  };
12
22
  middlewares: Array<(ctx: {
13
23
  action: string;
@@ -15,6 +25,8 @@ export declare const runMiddleware: ({ name, payload, middlewares, reportIssue,
15
25
  prev: StoreValue;
16
26
  next: StoreValue;
17
27
  path: unknown;
28
+ correlationId?: string;
29
+ traceContext?: import("../types/utility.js").TraceContext;
18
30
  }) => StoreValue | void>;
19
31
  reportIssue: LifecycleIssueReporter;
20
32
  warn: (message: string) => void;
@@ -1,6 +1,17 @@
1
+ /**
2
+ * @module index
3
+ *
4
+ * LAYER: Public API
5
+ * OWNS: Module-level behavior and exports for index.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
1
9
  export { createStore, createStoreStrict, setStore, setStoreBatch, getStore, deleteStore, resetStore, hasStore, hydrateStores, } from "./store.js";
2
- export { createComputed, invalidateComputed, deleteComputed, isComputedStore, } from "./computed.js";
10
+ export { getMetrics } from "./core/store-read.js";
11
+ export { getAsyncMetrics } from "./async/fetch.js";
12
+ export { getStoreHealth, findColdStores } from "./runtime-tools/index.js";
13
+ export { createComputed, invalidateComputed, deleteComputed, isComputedStore, } from "./computed/index.js";
3
14
  export { namespace, store } from "./store.js";
4
- export type { Path, PathValue, PartialDeep, StoreDefinition, StoreValue, StoreKey, StoreName, StateFor, StoreStateMap, StrictStoreMap, WriteResult, PersistOptions, StoreOptions, SyncOptions, } from "./store.js";
15
+ export type { Path, PathValue, PartialDeep, HydrateSnapshotFor, HydrationFailure, HydrationResult, StoreDefinition, StoreValue, StoreKey, StoreName, StateFor, StoreStateMap, StrictStoreMap, WriteResult, FeatureOptions, FeatureOptionsMap, PersistOptions, StoreOptions, SyncOptions, } from "./store.js";
5
16
  export { configureStroid } from "./config.js";
6
17
  export * as queryIntegrations from "./integrations/query.js";
@@ -1,5 +1,5 @@
1
- import type { FetchInput, FetchOptions } from "../async-cache.js";
2
- import type { StoreDefinition, StoreKey, StoreName } from "../store-lifecycle.js";
1
+ import type { FetchInput, FetchOptions } from "../async/cache.js";
2
+ import type { StoreDefinition, StoreKey, StoreName } from "../core/store-lifecycle/types.js";
3
3
  type StoreTarget = StoreDefinition<string, unknown> | StoreKey<string, unknown> | StoreName;
4
4
  export declare const reactQueryKey: (storeName: StoreTarget, cacheKey?: string | number) => (string | number)[];
5
5
  export declare const createReactQueryFetcher: (storeName: StoreTarget, input: FetchInput, options?: FetchOptions) => () => Promise<unknown>;
@@ -0,0 +1,3 @@
1
+ export type ComputedOrderResolver = (names: string[]) => string[];
2
+ export declare const setComputedOrderResolver: (next: ComputedOrderResolver | null) => void;
3
+ export declare const getComputedOrder: (names: string[]) => string[];
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @module internals/config
3
+ *
4
+ * LAYER: Internal subsystem
5
+ * OWNS: Module-level behavior and exports for internals/config.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
1
9
  import type { SnapshotMode, MiddlewareCtx, StoreValue } from "../adapters/options.js";
2
10
  export type LogSink = {
3
11
  log?: (msg: string, meta?: Record<string, unknown>) => void;
@@ -26,17 +34,55 @@ export type StroidConfig = {
26
34
  strictMutatorReturns?: boolean;
27
35
  asyncAutoCreate?: boolean;
28
36
  asyncCloneResult?: AsyncCloneMode;
37
+ /**
38
+ * Automatically generate correlation IDs for async fetch writes.
39
+ * Default: false.
40
+ */
41
+ autoCorrelationIds?: boolean;
42
+ /**
43
+ * Acknowledge loose store name typing and suppress dev warnings.
44
+ * Useful when you intentionally skip StoreStateMap augmentation.
45
+ */
46
+ acknowledgeLooseTypes?: boolean;
47
+ /**
48
+ * Max number of cached path validation verdicts per store.
49
+ * Default: 500.
50
+ */
51
+ pathCacheSize?: number;
29
52
  defaultSnapshotMode?: SnapshotMode;
53
+ /**
54
+ * Alias for defaultSnapshotMode.
55
+ */
56
+ snapshotStrategy?: SnapshotMode;
57
+ /**
58
+ * Throw on async usage errors instead of returning null.
59
+ * Default: false (usage errors return null and call onError).
60
+ */
61
+ strictAsyncUsageErrors?: boolean;
30
62
  middleware?: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
31
63
  /**
32
- * Allow hydrateStores to accept untrusted snapshots without explicit opt-in.
64
+ * Allow hydrateStores to accept trusted snapshots without explicit opt-in.
33
65
  * Default: false (hydration requires an explicit trust opt-in).
34
66
  */
67
+ allowTrustedHydration?: boolean;
68
+ /**
69
+ * @deprecated Use allowTrustedHydration instead.
70
+ */
35
71
  allowUntrustedHydration?: boolean;
72
+ /**
73
+ * Alias for allowTrustedHydration.
74
+ */
75
+ allowHydration?: boolean;
36
76
  /**
37
77
  * Optional custom mutator engine (e.g. Immer's produce) to enable structural sharing.
78
+ * You can pass the produce function directly or use "immer" after calling registerMutatorProduce().
38
79
  */
39
- mutatorProduce?: <T>(base: T, recipe: (draft: T) => void) => T;
80
+ mutatorProduce?: (<T>(base: T, recipe: (draft: T) => void) => T) | "immer";
81
+ /**
82
+ * When true, createSelector clones frozen state before proxy tracking.
83
+ * Default: true (safer for mutation-prone selectors in dev).
84
+ */
85
+ selectorCloneFrozen?: boolean;
40
86
  };
41
87
  type ResolvedConfig = {
42
88
  logSink: LogSink;
@@ -48,12 +94,20 @@ type ResolvedConfig = {
48
94
  strictMutatorReturns: boolean;
49
95
  asyncAutoCreate: boolean;
50
96
  asyncCloneResult: AsyncCloneMode;
97
+ autoCorrelationIds: boolean;
98
+ acknowledgeLooseTypes: boolean;
99
+ pathCacheSize: number;
51
100
  defaultSnapshotMode: SnapshotMode;
101
+ strictAsyncUsageErrors: boolean;
52
102
  middleware: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
53
103
  allowUntrustedHydration: boolean;
54
104
  mutatorProduce?: <T>(base: T, recipe: (draft: T) => void) => T;
105
+ selectorCloneFrozen: boolean;
55
106
  };
56
107
  export declare const getConfig: () => ResolvedConfig;
108
+ export declare const registerMutatorProduce: (produce: (<T>(base: T, recipe: (draft: T) => void) => T), options?: {
109
+ force?: boolean;
110
+ }) => void;
57
111
  export declare const configureStroid: (next?: StroidConfig) => void;
58
112
  export declare const resetConfig: () => void;
59
113
  export declare const _resetConfigForTests: () => void;
@@ -5,4 +5,5 @@ export type IssueOptions = {
5
5
  visibility?: IssueVisibility;
6
6
  onError?: (message: string) => void;
7
7
  };
8
+ export declare const safeInvoke: <T extends unknown[]>(fn: ((...args: T) => void) | undefined, label: string, ...args: T) => void;
8
9
  export declare const reportIssue: (message: string, options?: IssueOptions) => void;
@@ -1,4 +1,4 @@
1
- import { type StoreRegistry } from "../store-registry.js";
1
+ import { type StoreRegistry } from "../core/store-registry.js";
2
2
  export declare const createStoreAdmin: (registry: StoreRegistry) => {
3
3
  deleteExistingStore: (name: string) => void;
4
4
  clearAllStores: () => string[];
@@ -1,3 +1,13 @@
1
- export { createStore, replaceStore } from "../store-write.js";
2
- export { getStore, hasStore } from "../store-read.js";
3
- export { subscribeStore } from "../store-notify.js";
1
+ /**
2
+ * @module internals/store-ops
3
+ *
4
+ * LAYER: Internal subsystem
5
+ * OWNS: Module-level behavior and exports for internals/store-ops.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ export { createStore } from "../core/store-create.js";
10
+ export { replaceStore } from "../core/store-replace.js";
11
+ export { setStore, setStoreWithContext } from "../core/store-set.js";
12
+ export { getStore, hasStore } from "../core/store-read.js";
13
+ export { subscribeStore } from "../core/store-notify.js";
@@ -0,0 +1,2 @@
1
+ export declare const registerTestResetHook: (name: string, fn: () => void, order?: number) => void;
2
+ export declare const runTestResets: () => void;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @module internals/write-context
3
+ *
4
+ * LAYER: Internal subsystem
5
+ * OWNS: Correlation/trace context for write chains.
6
+ *
7
+ * Consumers: store-write.ts, notification/delivery.ts, async-fetch.ts.
8
+ */
9
+ import type { TraceContext } from "../types/utility.js";
10
+ export type WriteContext = {
11
+ correlationId?: string;
12
+ traceContext?: TraceContext;
13
+ };
14
+ export declare const getWriteContext: () => WriteContext | null;
15
+ export declare const runWithWriteContext: <T>(context: WriteContext | null | undefined, fn: () => T) => T;
@@ -0,0 +1,3 @@
1
+ import { type StoreRegistry } from "../core/store-registry.js";
2
+ import type { FlushPlan } from "./priority.js";
3
+ export declare const deliverFlush: (registry: StoreRegistry, plan: FlushPlan, flushVersion: number, onComplete: () => void) => void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module notification/index
3
+ *
4
+ * LAYER: Notification pipeline
5
+ * OWNS: Orchestrating flush scheduling without owning sub-responsibilities.
6
+ *
7
+ * Consumers: store-notify.ts
8
+ */
9
+ import type { StoreRegistry } from "../core/store-registry.js";
10
+ export declare const scheduleFlush: (registry: StoreRegistry) => void;