stroid 0.1.3 → 0.1.4

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 (133) hide show
  1. package/CHANGELOG.md +312 -265
  2. package/README.md +1017 -115
  3. package/dist/async.d.ts +1 -1
  4. package/dist/async.js +1 -33
  5. package/dist/chunk-645IESIU.js +2 -0
  6. package/dist/chunk-6ELWGQ4Q.js +2 -0
  7. package/dist/chunk-BW32TJGE.js +13 -0
  8. package/dist/chunk-FOQKGHPS.js +26 -0
  9. package/dist/chunk-KQCSFGHJ.js +2 -0
  10. package/dist/chunk-M2NJVI36.js +2 -0
  11. package/dist/chunk-PVATWAY4.js +2 -0
  12. package/dist/chunk-X3JR32JD.js +2 -0
  13. package/dist/chunk-YU5GMPCC.js +2 -0
  14. package/dist/computed-types.d.ts +42 -0
  15. package/dist/computed-types.js +2 -0
  16. package/dist/computed.d.ts +9 -2
  17. package/dist/computed.js +1 -12
  18. package/dist/core.js +1 -22
  19. package/dist/devtools.d.ts +1 -1
  20. package/dist/devtools.js +1 -1
  21. package/dist/feature.js +1 -1
  22. package/dist/helpers.js +1 -22
  23. package/dist/index-internal.d.ts +1 -1
  24. package/dist/index.d.cts +3 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +1 -35
  27. package/dist/install.js +1 -1
  28. package/dist/options.d.ts +1 -1
  29. package/dist/persist.js +1 -1
  30. package/dist/psr.d.ts +48 -0
  31. package/dist/psr.js +2 -0
  32. package/dist/react/index.d.ts +3 -1
  33. package/dist/react/index.js +5 -36
  34. package/dist/registry.d.ts +1 -0
  35. package/dist/runtime-admin.js +1 -1
  36. package/dist/runtime-patch.d.ts +29 -0
  37. package/dist/runtime-tools.d.ts +6 -1
  38. package/dist/runtime-tools.js +1 -3
  39. package/dist/selectors.js +1 -1
  40. package/dist/server.d.ts +4 -1
  41. package/dist/server.js +1 -12
  42. package/dist/store-registry.d.ts +8 -0
  43. package/dist/sync.js +1 -1
  44. package/dist/testing.js +1 -22
  45. package/dist/types/adapters/options.d.ts +335 -0
  46. package/dist/types/async/cache.d.ts +40 -0
  47. package/dist/types/async/clone.d.ts +10 -0
  48. package/dist/types/async/errors.d.ts +3 -0
  49. package/dist/types/async/fetch.d.ts +37 -0
  50. package/dist/types/async/inflight.d.ts +30 -0
  51. package/dist/types/async/rate.d.ts +5 -0
  52. package/dist/types/async/registry.d.ts +117 -0
  53. package/dist/types/async/request.d.ts +11 -0
  54. package/dist/types/async/retry.d.ts +10 -0
  55. package/dist/types/async.d.ts +10 -0
  56. package/dist/types/computed/computed-graph.d.ts +33 -0
  57. package/dist/types/computed/index.d.ts +21 -0
  58. package/dist/types/computed/types.d.ts +40 -0
  59. package/dist/types/config.d.ts +10 -0
  60. package/dist/types/core/index.d.ts +11 -0
  61. package/dist/types/core/lifecycle-hooks.d.ts +16 -0
  62. package/dist/types/core/runtime-patch.d.ts +67 -0
  63. package/dist/types/core/store-admin-impl.d.ts +9 -0
  64. package/dist/types/core/store-admin.d.ts +9 -0
  65. package/dist/types/core/store-core.d.ts +13 -0
  66. package/dist/types/core/store-create.d.ts +16 -0
  67. package/dist/types/core/store-hydrate-impl.d.ts +35 -0
  68. package/dist/types/core/store-hydrate.d.ts +9 -0
  69. package/dist/types/core/store-lifecycle/hooks.d.ts +20 -0
  70. package/dist/types/core/store-lifecycle/identity.d.ts +23 -0
  71. package/dist/types/core/store-lifecycle/registry.d.ts +54 -0
  72. package/dist/types/core/store-lifecycle/types.d.ts +67 -0
  73. package/dist/types/core/store-lifecycle/validation.d.ts +53 -0
  74. package/dist/types/core/store-name.d.ts +28 -0
  75. package/dist/types/core/store-notify.d.ts +13 -0
  76. package/dist/types/core/store-read.d.ts +18 -0
  77. package/dist/types/core/store-registry.d.ts +115 -0
  78. package/dist/types/core/store-replace-impl.d.ts +11 -0
  79. package/dist/types/core/store-replace.d.ts +9 -0
  80. package/dist/types/core/store-set-impl.d.ts +13 -0
  81. package/dist/types/core/store-set.d.ts +9 -0
  82. package/dist/types/core/store-shared/core.d.ts +13 -0
  83. package/dist/types/core/store-shared/notify.d.ts +12 -0
  84. package/dist/types/core/store-transaction.d.ts +28 -0
  85. package/dist/types/core/store-write-shared.d.ts +25 -0
  86. package/dist/types/core/store-write.d.ts +13 -0
  87. package/dist/types/features/feature-registry.d.ts +91 -0
  88. package/dist/types/features/lifecycle.d.ts +40 -0
  89. package/dist/types/index.d.ts +17 -0
  90. package/dist/types/integrations/query.d.ts +8 -0
  91. package/dist/types/internals/computed-order.d.ts +3 -0
  92. package/dist/types/internals/config.d.ts +116 -0
  93. package/dist/types/internals/diagnostics.d.ts +21 -0
  94. package/dist/types/internals/reporting.d.ts +9 -0
  95. package/dist/types/internals/store-admin.d.ts +7 -0
  96. package/dist/types/internals/store-ops.d.ts +13 -0
  97. package/dist/types/internals/test-reset.d.ts +2 -0
  98. package/dist/types/internals/write-context.d.ts +20 -0
  99. package/dist/types/notification/delivery.d.ts +3 -0
  100. package/dist/types/notification/index.d.ts +10 -0
  101. package/dist/types/notification/metrics.d.ts +12 -0
  102. package/dist/types/notification/priority.d.ts +9 -0
  103. package/dist/types/notification/scheduler.d.ts +11 -0
  104. package/dist/types/notification/snapshot.d.ts +8 -0
  105. package/dist/types/runtime-admin/index.d.ts +2 -0
  106. package/dist/types/runtime-tools/index.d.ts +63 -0
  107. package/dist/types/store.d.ts +16 -0
  108. package/dist/types/types/utility.d.ts +17 -0
  109. package/dist/types/utils/clone.d.ts +4 -0
  110. package/dist/types/utils/devfreeze.d.ts +2 -0
  111. package/dist/types/utils/hash.d.ts +8 -0
  112. package/dist/types/utils/path.d.ts +5 -0
  113. package/dist/types/utils/validation.d.ts +14 -0
  114. package/dist/types/utils.d.ts +13 -0
  115. package/dist/types.d.ts +2 -2
  116. package/package.json +31 -20
  117. package/dist/async.js.map +0 -1
  118. package/dist/computed.js.map +0 -1
  119. package/dist/core.js.map +0 -1
  120. package/dist/devtools.js.map +0 -1
  121. package/dist/feature.js.map +0 -1
  122. package/dist/helpers.js.map +0 -1
  123. package/dist/index.js.map +0 -1
  124. package/dist/install.js.map +0 -1
  125. package/dist/persist.js.map +0 -1
  126. package/dist/react/index.js.map +0 -1
  127. package/dist/runtime-admin.js.map +0 -1
  128. package/dist/runtime-tools.js.map +0 -1
  129. package/dist/selectors.js.map +0 -1
  130. package/dist/server.js.map +0 -1
  131. package/dist/sync.js.map +0 -1
  132. package/dist/testing.js.map +0 -1
  133. package/dist/tsdoc-metadata.json +0 -11
@@ -0,0 +1,53 @@
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";
11
+ import type { StoreValue } from "./types.js";
12
+ type PathSafetyVerdict = {
13
+ ok: true;
14
+ } | {
15
+ ok: false;
16
+ reason: string;
17
+ };
18
+ type PathValidationCacheNode = {
19
+ children: Map<string, PathValidationCacheNode>;
20
+ verdicts?: Map<SupportedType, PathSafetyVerdict>;
21
+ };
22
+ export declare const pathValidationCache: Map<string, PathValidationCacheNode>;
23
+ export declare const resetPathValidationCache: (registry: object) => void;
24
+ export declare const validatePathSafety: (storeName: string, base: StoreValue, path: PathInput, nextValue: unknown) => {
25
+ ok: boolean;
26
+ reason?: string;
27
+ };
28
+ export declare const sanitizeValue: (name: string, value: unknown, onError?: (message: string) => void, options?: {
29
+ reuseInput?: boolean;
30
+ }) => {
31
+ ok: true;
32
+ value: StoreValue;
33
+ } | {
34
+ ok: false;
35
+ };
36
+ export declare const runValidation: (name: string, value: StoreValue, validate: ValidateOption | undefined, onError?: (message: string) => void) => {
37
+ ok: true;
38
+ value: StoreValue;
39
+ } | {
40
+ ok: false;
41
+ };
42
+ export declare const normalizeCommittedState: (name: string, value: unknown, validate: ValidateOption | undefined, onError?: (message: string) => void, options?: {
43
+ reuseInput?: boolean;
44
+ }) => {
45
+ ok: true;
46
+ value: StoreValue;
47
+ } | {
48
+ ok: false;
49
+ };
50
+ export declare const invalidatePathCache: (name: string) => void;
51
+ export declare const clearPathValidationCache: () => void;
52
+ export declare const materializeInitial: (name: string, registry?: import("../store-registry.js").StoreRegistry) => boolean;
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
+ };
@@ -0,0 +1,13 @@
1
+ import type { StoreValue, Subscriber } from "./store-lifecycle/types.js";
2
+ export declare const notify: (name: string) => void;
3
+ export declare const setStoreBatch: (fn: () => unknown) => void;
4
+ export declare const subscribeStore: (name: string, fn: Subscriber) => (() => void);
5
+ /** @deprecated Use subscribeStore instead. */
6
+ export declare const subscribeInternal: (name: string, fn: Subscriber) => (() => void);
7
+ /** @deprecated Use subscribeStore instead. */
8
+ export declare const subscribe: (name: string, fn: Subscriber) => (() => void);
9
+ export declare const getStoreSnapshot: (name: string) => StoreValue | null;
10
+ export declare const getStoreSnapshotNoTrack: (name: string) => StoreValue | null;
11
+ /** @deprecated Use getStoreSnapshot instead. */
12
+ export declare const getSnapshot: (name: string) => StoreValue | null;
13
+ export declare const resetNotifyStateForTests: () => void;
@@ -0,0 +1,18 @@
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";
5
+ type StoreSnapshot<T> = T extends object ? Readonly<T> : T;
6
+ export declare function getStore<Name extends string, State, P extends Path<State>>(name: StoreDefinition<Name, State>, path: P): StoreSnapshot<PathValue<State, P>> | null;
7
+ export declare function getStore<Name extends string, State>(name: StoreDefinition<Name, State>, path?: undefined): StoreSnapshot<State> | null;
8
+ export declare function getStore<Name extends string, State, P extends Path<State>>(name: StoreKey<Name, State>, path: P): StoreSnapshot<PathValue<State, P>> | null;
9
+ export declare function getStore<Name extends string, State>(name: StoreKey<Name, State>, path?: undefined): StoreSnapshot<State> | null;
10
+ export declare function getStore<Name extends StoreName, P extends Path<StateFor<Name>>>(name: Name, path: P): StoreSnapshot<PathValue<StateFor<Name>, P>> | null;
11
+ export declare function getStore<Name extends StoreName>(name: Name, path?: undefined): StoreSnapshot<StateFor<Name>> | null;
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;
16
+ export { hasStoreEntryInternal as _hasStoreEntryInternal, getStoreValueRef as _getStoreValueRef, getFeatureApi as _getFeatureApi };
17
+ export declare const getInitialState: () => Record<string, StoreValue>;
18
+ export declare const getMetrics: (name: string) => FeatureMetrics | null;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @module store-registry
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Module-level behavior and exports for store-registry.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import { type FeatureName, type StoreFeatureMeta, type StoreFeatureRuntime } from "../features/feature-registry.js";
10
+ import type { RuntimePatch } from "./runtime-patch.js";
11
+ import type { AsyncRegistry } from "../async/registry.js";
12
+ import type { ComputedClassification } from "../computed/types.js";
13
+ export type RegistryStoreValue = unknown;
14
+ export type RegistrySubscriber = (value: RegistryStoreValue | null) => void;
15
+ export type RegistrySnapshotEntry = {
16
+ version: number;
17
+ snapshot: RegistryStoreValue | null;
18
+ source?: RegistryStoreValue | null;
19
+ mode?: "deep" | "shallow" | "ref";
20
+ };
21
+ export type StoreLifecycleEvent = {
22
+ type: "created";
23
+ name: string;
24
+ isGlobal: boolean;
25
+ isTemp: boolean;
26
+ } | {
27
+ type: "deleted";
28
+ name: string;
29
+ };
30
+ export type StoreLifecycleListener = (event: StoreLifecycleEvent) => void;
31
+ export type TransactionState = {
32
+ depth: number;
33
+ pending: Array<() => void>;
34
+ stagedValues: Map<string, RegistryStoreValue>;
35
+ snapshotCache: Map<string, TransactionSnapshotEntry>;
36
+ runtimePatches: RuntimePatch[];
37
+ failed: boolean;
38
+ error?: Error;
39
+ };
40
+ type TransactionSnapshotMode = "deep" | "shallow" | "ref";
41
+ type TransactionSnapshotEntry = {
42
+ source: RegistryStoreValue | null | undefined;
43
+ snapshot: RegistryStoreValue | null;
44
+ mode: TransactionSnapshotMode;
45
+ };
46
+ export type ComputedEntry = {
47
+ deps: string[];
48
+ compute: (...args: unknown[]) => unknown;
49
+ stale: boolean;
50
+ classification: ComputedClassification;
51
+ hasLastOutput: boolean;
52
+ lastOutput: unknown;
53
+ };
54
+ export type NotifyState = {
55
+ pendingNotifications: Set<string>;
56
+ pendingBuffer: string[];
57
+ orderedNames: string[];
58
+ subscriberBuffer: RegistrySubscriber[];
59
+ notifyScheduled: boolean;
60
+ batchDepth: number;
61
+ flushId: number;
62
+ isFlushing: boolean;
63
+ };
64
+ export type RegistryScope = "default" | "request";
65
+ export type StoreRegistry = {
66
+ scope: RegistryScope;
67
+ stores: Record<string, RegistryStoreValue>;
68
+ subscribers: Record<string, Set<RegistrySubscriber>>;
69
+ initialStates: Record<string, RegistryStoreValue>;
70
+ initialFactories: Record<string, (() => RegistryStoreValue) | undefined>;
71
+ metaEntries: Record<string, StoreFeatureMeta>;
72
+ snapshotCache: Record<string, RegistrySnapshotEntry>;
73
+ featureRuntimes: Map<FeatureName, StoreFeatureRuntime>;
74
+ deletingStores: Set<string>;
75
+ computedEntries: Record<string, ComputedEntry>;
76
+ computedDependents: Record<string, Set<string>>;
77
+ computedCleanups: Map<string, () => void>;
78
+ lastRuntimePatches: RuntimePatch[];
79
+ transaction: TransactionState;
80
+ async: AsyncRegistry;
81
+ notify: NotifyState;
82
+ lifecycleListener: StoreLifecycleListener | null;
83
+ };
84
+ export declare const initializeRegistryFeatureRuntimes: (registry: StoreRegistry) => void;
85
+ export declare const normalizeStoreRegistryScope: (scope: string) => string;
86
+ export declare const defaultRegistryScope: string;
87
+ export declare const getDefaultStoreRegistry: () => StoreRegistry;
88
+ export declare const setRegistryScope: (scope: string) => void;
89
+ export declare const clearRegistryScopeOverrideForTests: () => void;
90
+ export declare const createTransactionState: () => TransactionState;
91
+ export declare const createStoreRegistry: (scope?: RegistryScope) => StoreRegistry;
92
+ export declare const getStoreRegistry: (scope: string) => StoreRegistry;
93
+ export declare const hasStoreEntry: (registry: StoreRegistry, name: string) => boolean;
94
+ export declare const isStoreDeleting: (registry: StoreRegistry, name: string) => boolean;
95
+ export declare const clearStoreRegistries: (registry: StoreRegistry) => void;
96
+ export declare const setLifecycleListener: (registry: StoreRegistry, listener: StoreLifecycleListener | null) => void;
97
+ export declare const emitLifecycleEvent: (registry: StoreRegistry, event: StoreLifecycleEvent) => void;
98
+ export declare const resetAllStoreRegistriesForTests: () => void;
99
+ export type CarrierContext = Record<string, unknown>;
100
+ export interface CarrierRunner {
101
+ run<T>(carrier: CarrierContext, fn: () => T): T;
102
+ get(): CarrierContext | null;
103
+ }
104
+ export declare const injectCarrierRunner: (runner: CarrierRunner) => void;
105
+ export declare const getRequestCarrier: () => CarrierContext | null;
106
+ export interface RegistryRunner {
107
+ run<T>(registry: StoreRegistry, fn: () => T): T;
108
+ get(): StoreRegistry | null;
109
+ enterWith?: (registry: StoreRegistry) => void;
110
+ }
111
+ export declare const injectRegistryRunner: (runner: RegistryRunner) => void;
112
+ export declare const runWithRegistry: <T>(registry: StoreRegistry, fn: () => T) => T;
113
+ export declare const getActiveStoreRegistry: (fallback?: StoreRegistry) => StoreRegistry;
114
+ export declare const enterRegistry: (registry: StoreRegistry) => void;
115
+ 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 {};
@@ -0,0 +1,28 @@
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
+ */
9
+ import type { StoreValue } from "./store-lifecycle/types.js";
10
+ import type { RuntimePatch } from "./runtime-patch.js";
11
+ import { type StoreRegistry, type TransactionState } from "./store-registry.js";
12
+ export type TransactionRunner = {
13
+ run: <T>(state: TransactionState, fn: () => T) => T;
14
+ get: () => TransactionState | null;
15
+ enterWith?: (state: TransactionState) => void;
16
+ };
17
+ export declare const injectTransactionRunner: (runner: TransactionRunner | null) => void;
18
+ export declare const beginTransaction: (registry?: StoreRegistry) => StoreRegistry;
19
+ export declare const isTransactionActive: () => boolean;
20
+ export declare const markTransactionFailed: (err?: unknown, registry?: StoreRegistry) => void;
21
+ export declare const registerTransactionCommit: (fn: () => void) => void;
22
+ export declare const stageTransactionValue: (name: string, value: StoreValue) => void;
23
+ export declare const stageTransactionPatches: (patches: readonly RuntimePatch[]) => void;
24
+ export declare const getStagedTransactionValue: (name: string) => {
25
+ has: boolean;
26
+ value: StoreValue | undefined;
27
+ };
28
+ export declare const endTransaction: (err?: unknown, registry?: StoreRegistry) => Error | null;
@@ -0,0 +1,25 @@
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
+ import { type RuntimePatch } from "./runtime-patch.js";
5
+ export type CommitAction = "set" | "reset" | "hydrate" | "replace";
6
+ export type CommitHookLabel = "onSet" | "onReset";
7
+ export type CommitMetricsUpdate = {
8
+ resetElapsedMs?: number;
9
+ };
10
+ export type CommitArgs = {
11
+ name: string;
12
+ prev: StoreValue;
13
+ next: StoreValue;
14
+ action: CommitAction;
15
+ hookLabel: CommitHookLabel;
16
+ logMessage: string;
17
+ context?: WriteContext | null;
18
+ runtimePatches?: readonly RuntimePatch[];
19
+ metricsUpdate?: CommitMetricsUpdate;
20
+ };
21
+ export declare const clearSlowMutatorWarnings: () => void;
22
+ export declare const forgetSlowMutatorWarning: (storeName: string) => void;
23
+ export declare const maybeWarnSlowMutator: (storeName: string, elapsedMs: number) => void;
24
+ export declare const resolveWriteContext: (context?: WriteContext | null) => WriteContext | null;
25
+ 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;
@@ -0,0 +1,40 @@
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
+ */
9
+ import type { StoreValue } from "../adapters/options.js";
10
+ export declare const MIDDLEWARE_ABORT: unique symbol;
11
+ export type LifecycleIssueReporter = (message: string, visibility?: "dev" | "always") => void;
12
+ export declare const runMiddleware: ({ name, payload, middlewares, reportIssue, warn, }: {
13
+ name: string;
14
+ payload: {
15
+ action: string;
16
+ prev: StoreValue;
17
+ next: StoreValue;
18
+ path: unknown;
19
+ correlationId?: string;
20
+ traceContext?: import("../types/utility.js").TraceContext;
21
+ };
22
+ middlewares: Array<(ctx: {
23
+ action: string;
24
+ name: string;
25
+ prev: StoreValue;
26
+ next: StoreValue;
27
+ path: unknown;
28
+ correlationId?: string;
29
+ traceContext?: import("../types/utility.js").TraceContext;
30
+ }) => StoreValue | void>;
31
+ reportIssue: LifecycleIssueReporter;
32
+ warn: (message: string) => void;
33
+ }) => StoreValue | typeof MIDDLEWARE_ABORT;
34
+ export declare const runStoreHook: ({ name, label, fn, args, reportIssue, }: {
35
+ name: string;
36
+ label: "onCreate" | "onSet" | "onReset" | "onDelete";
37
+ fn: ((...args: any[]) => void) | undefined;
38
+ args: any[];
39
+ reportIssue: LifecycleIssueReporter;
40
+ }) => void;
@@ -0,0 +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
+ */
9
+ export { createStore, createStoreStrict, setStore, setStoreBatch, getStore, deleteStore, resetStore, hasStore, hydrateStores, } from "./store.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";
14
+ export { namespace, store } 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";
16
+ export { configureStroid } from "./config.js";
17
+ export * as queryIntegrations from "./integrations/query.js";
@@ -0,0 +1,8 @@
1
+ import type { FetchInput, FetchOptions } from "../async/cache.js";
2
+ import type { StoreDefinition, StoreKey, StoreName } from "../core/store-lifecycle/types.js";
3
+ type StoreTarget = StoreDefinition<string, unknown> | StoreKey<string, unknown> | StoreName;
4
+ export declare const reactQueryKey: (storeName: StoreTarget, cacheKey?: string | number) => (string | number)[];
5
+ export declare const createReactQueryFetcher: (storeName: StoreTarget, input: FetchInput, options?: FetchOptions) => () => Promise<unknown>;
6
+ export declare const swrKey: (storeName: StoreTarget, cacheKey?: string | number) => (string | number)[];
7
+ export declare const createSwrFetcher: (storeName: StoreTarget, input: FetchInput, options?: FetchOptions) => () => Promise<unknown>;
8
+ export {};
@@ -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[];
@@ -0,0 +1,116 @@
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
+ */
9
+ import type { SnapshotMode, MiddlewareCtx, StoreValue } from "../adapters/options.js";
10
+ export type LogSink = {
11
+ log?: (msg: string, meta?: Record<string, unknown>) => void;
12
+ warn?: (msg: string, meta?: Record<string, unknown>) => void;
13
+ critical?: (msg: string, meta?: Record<string, unknown>) => void;
14
+ };
15
+ export type AsyncCloneMode = "none" | "shallow" | "deep";
16
+ export type FlushConfig = {
17
+ chunkSize?: number;
18
+ chunkDelayMs?: number;
19
+ priorityStores?: string[];
20
+ };
21
+ export type RevalidateOnFocusConfig = {
22
+ debounceMs?: number;
23
+ maxConcurrent?: number;
24
+ staggerMs?: number;
25
+ };
26
+ export type StroidConfig = {
27
+ logSink?: LogSink;
28
+ flush?: FlushConfig;
29
+ revalidateOnFocus?: RevalidateOnFocusConfig;
30
+ namespace?: string;
31
+ strictMissingFeatures?: boolean;
32
+ strictFeatures?: boolean;
33
+ assertRuntime?: boolean;
34
+ strictMutatorReturns?: boolean;
35
+ asyncAutoCreate?: boolean;
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;
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;
62
+ middleware?: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
63
+ /**
64
+ * Allow hydrateStores to accept trusted snapshots without explicit opt-in.
65
+ * Default: false (hydration requires an explicit trust opt-in).
66
+ */
67
+ allowTrustedHydration?: boolean;
68
+ /**
69
+ * @deprecated Use allowTrustedHydration instead.
70
+ */
71
+ allowUntrustedHydration?: boolean;
72
+ /**
73
+ * Alias for allowTrustedHydration.
74
+ */
75
+ allowHydration?: boolean;
76
+ /**
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().
79
+ */
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;
86
+ };
87
+ type ResolvedConfig = {
88
+ logSink: LogSink;
89
+ flush: Required<FlushConfig>;
90
+ revalidateOnFocus: Required<RevalidateOnFocusConfig>;
91
+ namespace: string;
92
+ strictMissingFeatures: boolean;
93
+ assertRuntime: boolean;
94
+ strictMutatorReturns: boolean;
95
+ asyncAutoCreate: boolean;
96
+ asyncCloneResult: AsyncCloneMode;
97
+ autoCorrelationIds: boolean;
98
+ acknowledgeLooseTypes: boolean;
99
+ pathCacheSize: number;
100
+ defaultSnapshotMode: SnapshotMode;
101
+ strictAsyncUsageErrors: boolean;
102
+ middleware: Array<(ctx: MiddlewareCtx) => StoreValue | void>;
103
+ allowUntrustedHydration: boolean;
104
+ mutatorProduce?: <T>(base: T, recipe: (draft: T) => void) => T;
105
+ selectorCloneFrozen: boolean;
106
+ };
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;
111
+ export declare const configureStroid: (next?: StroidConfig) => void;
112
+ export declare const resetConfig: () => void;
113
+ export declare const _resetConfigForTests: () => void;
114
+ export declare const getNamespace: () => string;
115
+ export declare const setNamespace: (ns: string) => void;
116
+ export {};