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,117 @@
1
+ /**
2
+ * @module async-registry
3
+ *
4
+ * LAYER: Module
5
+ * OWNS: Module-level behavior and exports for async-registry.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import type { TraceContext } from "../types/utility.js";
10
+ export type AsyncStateSnapshot = {
11
+ data?: unknown;
12
+ loading: boolean;
13
+ error: string | null;
14
+ status: "idle" | "loading" | "success" | "error" | "aborted";
15
+ cached?: boolean;
16
+ revalidating?: boolean;
17
+ correlationId?: string;
18
+ traceContext?: TraceContext;
19
+ };
20
+ export type AsyncStateAdapter = (ctx: {
21
+ name: string;
22
+ prev: unknown;
23
+ next: AsyncStateSnapshot;
24
+ set: (value: unknown | ((draft: any) => void)) => void;
25
+ }) => void;
26
+ export type WarnCategory = "noSignal" | "shape" | "autoCreate" | "mutableResult";
27
+ export type StoreCleanupKind = "store" | "revalidate";
28
+ export type StoreCleanupBucket = Partial<Record<StoreCleanupKind, Set<() => void>>>;
29
+ export interface FetchOptions {
30
+ transform?: (result: unknown) => unknown;
31
+ onSuccess?: (data: unknown) => void;
32
+ onError?: (message: string) => void;
33
+ /**
34
+ * Optional adapter to write async state into a custom store shape.
35
+ * When provided, default AsyncState writes are skipped.
36
+ */
37
+ stateAdapter?: AsyncStateAdapter;
38
+ method?: string;
39
+ headers?: Record<string, string>;
40
+ body?: unknown;
41
+ ttl?: number;
42
+ staleWhileRevalidate?: boolean;
43
+ dedupe?: boolean;
44
+ retry?: number;
45
+ retryDelay?: number;
46
+ retryBackoff?: number;
47
+ signal?: AbortSignal;
48
+ cacheKey?: string;
49
+ responseType?: "auto" | "json" | "text" | "arrayBuffer" | "blob" | "formData";
50
+ /**
51
+ * Optional correlation ID for tracing async writes.
52
+ * When provided, it is propagated into store metadata and middleware context.
53
+ */
54
+ correlationId?: string;
55
+ /**
56
+ * Optional trace context (e.g. OpenTelemetry).
57
+ */
58
+ traceContext?: TraceContext;
59
+ /**
60
+ * Auto-create the backing store if missing.
61
+ * Defaults to the global config setting (true by default).
62
+ */
63
+ autoCreate?: boolean;
64
+ /**
65
+ * Clone strategy for transformed results.
66
+ * - "none" (default): store by reference.
67
+ * - "shallow": shallow clone objects/arrays.
68
+ * - "deep": deep clone objects/arrays.
69
+ */
70
+ cloneResult?: "none" | "shallow" | "deep";
71
+ }
72
+ type InflightEntry = {
73
+ promise: Promise<unknown>;
74
+ raw: Promise<unknown>;
75
+ transform?: FetchOptions["transform"];
76
+ };
77
+ export type AsyncRegistry = {
78
+ fetchRegistry: Record<string, {
79
+ kind: "url";
80
+ url: string;
81
+ options: FetchOptions;
82
+ } | {
83
+ kind: "factory";
84
+ factory: () => string | Promise<unknown>;
85
+ options: FetchOptions;
86
+ }>;
87
+ inflight: Partial<Record<string, InflightEntry>>;
88
+ requestVersion: Record<string, number>;
89
+ requestSequence: Record<string, number>;
90
+ cacheMeta: Record<string, {
91
+ timestamp: number;
92
+ expiresAt: number | null;
93
+ data: unknown;
94
+ }>;
95
+ rateWindowStart: Record<string, number>;
96
+ rateCount: Record<string, number>;
97
+ ratePruneState: {
98
+ lastAt: number;
99
+ };
100
+ ratePruneTimer: ReturnType<typeof setTimeout> | null;
101
+ warnedOnce: Map<WarnCategory, Set<string>>;
102
+ storeCleanups: Record<string, StoreCleanupBucket>;
103
+ revalidateKeys: Set<string>;
104
+ revalidateHandlers: Record<string, () => void>;
105
+ asyncMetrics: {
106
+ cacheHits: number;
107
+ cacheMisses: number;
108
+ dedupes: number;
109
+ requests: number;
110
+ failures: number;
111
+ avgMs: number;
112
+ lastMs: number;
113
+ };
114
+ };
115
+ export declare const createAsyncRegistry: () => AsyncRegistry;
116
+ export declare const resetAsyncRegistry: (registry: AsyncRegistry) => void;
117
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module async/request
3
+ *
4
+ * LAYER: Async subsystem
5
+ * OWNS: Module-level behavior and exports for async/request.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import type { FetchOptions } from "./cache.js";
10
+ export declare const buildFetchOptions: (options: FetchOptions) => RequestInit;
11
+ export declare const parseResponseBody: (response: Response, responseType: FetchOptions["responseType"]) => Promise<unknown>;
@@ -0,0 +1,10 @@
1
+ export declare const MAX_RETRY_ATTEMPTS = 10;
2
+ export declare const MIN_RETRY_DELAY_MS = 10;
3
+ export declare const MAX_RETRY_DELAY_MS = 30000;
4
+ export declare const MAX_RETRY_BACKOFF = 8;
5
+ export declare const delay: (ms: number, signal?: AbortSignal) => Promise<void>;
6
+ export declare const normalizeRetryOptions: (name: string, retry: number, retryDelay: number, retryBackoff: number) => {
7
+ retry: number;
8
+ retryDelay: number;
9
+ retryBackoff: number;
10
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module async
3
+ *
4
+ * LAYER: Async subsystem
5
+ * OWNS: Module-level behavior and exports for async.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ export type { FetchOptions, FetchInput, AsyncStateSnapshot, AsyncStateAdapter } from "./async/cache.js";
10
+ export { fetchStore, refetchStore, enableRevalidateOnFocus, getAsyncMetrics, _resetAsyncStateForTests, } from "./async/fetch.js";
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @module computed-graph
3
+ *
4
+ * LAYER: Module
5
+ * OWNS: Module-level behavior and exports for computed-graph.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import { type ComputedEntry } from "../core/store-registry.js";
10
+ import type { ComputedClassification, ComputedDescriptor, RuntimeGraph, RuntimeNodeId } from "./types.js";
11
+ export declare const detectCycle: (name: string, deps: string[]) => string | null;
12
+ export declare const registerComputed: (name: string, deps: string[], compute: (...args: unknown[]) => unknown, classification?: ComputedClassification) => boolean;
13
+ export declare const unregisterComputed: (name: string) => void;
14
+ export declare const markStale: (name: string) => void;
15
+ export declare const isComputed: (name: string) => boolean;
16
+ export declare const getComputedEntry: (name: string) => ComputedEntry | undefined;
17
+ export declare const getComputedDescriptor: (nodeId: RuntimeNodeId) => ComputedDescriptor | null;
18
+ export declare const getTopoOrderedComputeds: (changedSources: string[]) => string[];
19
+ export declare const getFullComputedGraph: () => {
20
+ nodes: string[];
21
+ edges: Array<{
22
+ from: string;
23
+ to: string;
24
+ }>;
25
+ dependencies: Record<string, string[]>;
26
+ dependents: Record<string, string[]>;
27
+ };
28
+ export declare const getComputedDepsFor: (name: string) => {
29
+ deps: string[];
30
+ dependents: string[];
31
+ } | null;
32
+ export declare const getRuntimeComputedGraph: () => RuntimeGraph;
33
+ export declare const evaluateComputedFromSnapshot: (nodeId: RuntimeNodeId, snapshot: Record<string, unknown>) => unknown;
@@ -0,0 +1,21 @@
1
+ import "../core/store-notify.js";
2
+ import type { StoreRegistry } from "../core/store-registry.js";
3
+ import type { StoreDefinition, StoreKey, StoreName, StateFor, StoreValue } from "../core/store-lifecycle/types.js";
4
+ import type { ComputedClassification } from "./types.js";
5
+ export type ComputedOptions = {
6
+ autoDispose?: boolean;
7
+ onError?: (err: unknown) => void;
8
+ classification?: ComputedClassification;
9
+ };
10
+ type DepHandle = StoreDefinition<string, StoreValue> | StoreKey<string, StoreValue>;
11
+ type DepValue<T> = T extends StoreDefinition<string, infer S> ? Readonly<S> | null : T extends StoreKey<string, infer S> ? Readonly<S> | null : T extends StoreName ? Readonly<StateFor<T>> | null : StoreValue | null;
12
+ export declare function createComputed<TResult, Deps extends readonly (StoreName | DepHandle)[]>(name: string, deps: Deps, compute: (...args: {
13
+ [K in keyof Deps]: DepValue<Deps[K]>;
14
+ }) => TResult, options?: ComputedOptions): StoreDefinition<string, TResult> | undefined;
15
+ export declare const invalidateComputed: (name: string) => void;
16
+ export declare const deleteComputed: (name: string) => void;
17
+ export declare const isComputedStore: (name: string) => boolean;
18
+ export declare const shouldAutoDisposeComputed: (name: string, registry?: StoreRegistry) => boolean;
19
+ export declare const _resetComputedForTests: () => void;
20
+ export { getFullComputedGraph, getComputedDepsFor, getComputedDescriptor, getRuntimeComputedGraph, evaluateComputedFromSnapshot, } from "./computed-graph.js";
21
+ export type { ComputedClassification, ComputedDescriptor, RuntimeEdgeType, RuntimeGraph, RuntimeGraphEdge, RuntimeGraphGranularity, RuntimeGraphNode, RuntimeNodeId, RuntimeNodeType, } from "./types.js";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @module computed/types
3
+ *
4
+ * LAYER: Module
5
+ * OWNS: Shared public and internal computed graph types.
6
+ *
7
+ * Consumers: Computed registry, runtime tools, and PSR surface.
8
+ */
9
+ export type RuntimeNodeId = string;
10
+ export type RuntimePathSegment = string | number;
11
+ export type RuntimeGraphGranularity = "store";
12
+ export type RuntimeNodeType = "leaf" | "computed" | "async-boundary";
13
+ export type RuntimeEdgeType = "leaf-input" | "computed-input";
14
+ export interface RuntimeGraphNode {
15
+ id: RuntimeNodeId;
16
+ storeId: string;
17
+ path: readonly RuntimePathSegment[];
18
+ type: RuntimeNodeType;
19
+ estimatedCost?: number;
20
+ }
21
+ export interface RuntimeGraphEdge {
22
+ from: RuntimeNodeId;
23
+ to: RuntimeNodeId;
24
+ type: RuntimeEdgeType;
25
+ }
26
+ export interface RuntimeGraph {
27
+ granularity: RuntimeGraphGranularity;
28
+ nodes: readonly RuntimeGraphNode[];
29
+ edges: readonly RuntimeGraphEdge[];
30
+ }
31
+ export type ComputedClassification = "deterministic" | "opaque" | "asyncBoundary";
32
+ export interface ComputedDescriptor {
33
+ id: RuntimeNodeId;
34
+ storeId: string;
35
+ path: readonly RuntimePathSegment[];
36
+ dependencies: readonly RuntimeNodeId[];
37
+ nodeType: Extract<RuntimeNodeType, "computed" | "async-boundary">;
38
+ classification: ComputedClassification;
39
+ asyncBoundary?: boolean;
40
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module config
3
+ *
4
+ * LAYER: Public API
5
+ * OWNS: Module-level behavior and exports for config.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ export { configureStroid, resetConfig, registerMutatorProduce } from "./internals/config.js";
10
+ export type { LogSink, StroidConfig, FlushConfig, RevalidateOnFocusConfig, } from "./internals/config.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module core
3
+ *
4
+ * LAYER: Public API (minimal runtime)
5
+ * OWNS: Core store primitives only.
6
+ *
7
+ * Consumers: Bundle-size-sensitive consumers and explicit core usage.
8
+ */
9
+ export { createStore } from "./store-create.js";
10
+ export { setStore, resetStore, deleteStore } from "./store-write.js";
11
+ export { getStore, hasStore } from "./store-read.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module core/lifecycle-hooks
3
+ *
4
+ * LAYER: Core utilities
5
+ * OWNS: Cross-cutting lifecycle hooks without dependencies on other modules.
6
+ *
7
+ * Consumers: notification/*, async-cache.ts, internals/store-admin.ts
8
+ */
9
+ export type LifecycleHookEvent = {
10
+ type: string;
11
+ [key: string]: unknown;
12
+ };
13
+ export type LifecycleHook = (storeId: string, event: LifecycleHookEvent) => void;
14
+ export declare const registerHook: (name: string, fn: LifecycleHook) => (() => void);
15
+ export declare const hasHook: (name: string) => boolean;
16
+ export declare const fireHook: (name: string, storeId: string, event: LifecycleHookEvent) => void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module runtime-patch
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Canonical serializable patch model and write-lowering helpers.
6
+ *
7
+ * Consumers: store-set-impl, store-replace-impl, store-admin-impl, store-hydrate-impl.
8
+ */
9
+ import { type PathInput } from "../utils.js";
10
+ import type { WriteContext } from "../internals/write-context.js";
11
+ import type { StoreRegistry } from "./store-registry.js";
12
+ export type RuntimePatchOp = "set" | "merge" | "delete" | "insert";
13
+ export type RuntimePatchSource = "setStore" | "replaceStore" | "resetStore" | "hydrateStores";
14
+ export type RuntimePatchPath = readonly (string | number)[];
15
+ export type RuntimePatchPathInput = PathInput | RuntimePatchPath | Array<string | number>;
16
+ export interface RuntimePatchMeta {
17
+ timestamp: number;
18
+ source: RuntimePatchSource;
19
+ causedBy?: readonly string[];
20
+ isUnsafe?: boolean;
21
+ asyncBoundary?: boolean;
22
+ }
23
+ export interface RuntimePatch {
24
+ id: string;
25
+ store: string;
26
+ path: RuntimePatchPath;
27
+ op: RuntimePatchOp;
28
+ value?: unknown;
29
+ meta: RuntimePatchMeta;
30
+ }
31
+ export type SetStorePatchIntent = {
32
+ kind: "root";
33
+ } | {
34
+ kind: "merge";
35
+ value: unknown;
36
+ } | {
37
+ kind: "path";
38
+ path: RuntimePatchPathInput;
39
+ value: unknown;
40
+ };
41
+ export declare const normalizeRuntimePatchPath: (path?: RuntimePatchPathInput | null) => RuntimePatchPath;
42
+ export declare const createRuntimePatch: (options: {
43
+ store: string;
44
+ op: RuntimePatchOp;
45
+ path?: RuntimePatchPathInput | null;
46
+ value?: unknown;
47
+ source: RuntimePatchSource;
48
+ timestamp?: number;
49
+ context?: WriteContext | null;
50
+ isUnsafe?: boolean;
51
+ asyncBoundary?: boolean;
52
+ }) => RuntimePatch;
53
+ export declare const createRootSetRuntimePatch: (options: {
54
+ store: string;
55
+ value: unknown;
56
+ source: RuntimePatchSource;
57
+ context?: WriteContext | null;
58
+ }) => RuntimePatch;
59
+ export declare const createCanonicalSetStorePatches: (options: {
60
+ store: string;
61
+ intent: SetStorePatchIntent;
62
+ committedValue: unknown;
63
+ preserveIntent: boolean;
64
+ context?: WriteContext | null;
65
+ }) => RuntimePatch[];
66
+ export declare const setLastRuntimePatches: (patches: readonly RuntimePatch[], registry?: StoreRegistry) => void;
67
+ export declare const getLastRuntimePatches: (registry?: StoreRegistry) => readonly RuntimePatch[];
@@ -0,0 +1,9 @@
1
+ import type { StoreDefinition, StoreKey, StoreName, WriteResult } from "./store-lifecycle/types.js";
2
+ export declare function deleteStore<Name extends string, State>(name: StoreDefinition<Name, State>): void;
3
+ export declare function deleteStore<Name extends string, State>(name: StoreKey<Name, State>): void;
4
+ export declare function deleteStore<Name extends StoreName>(name: Name): void;
5
+ export declare function resetStore<Name extends string, State>(name: StoreDefinition<Name, State>): WriteResult;
6
+ export declare function resetStore<Name extends string, State>(name: StoreKey<Name, State>): WriteResult;
7
+ export declare function resetStore<Name extends StoreName>(name: Name): WriteResult;
8
+ export declare const clearAllStores: () => void;
9
+ export declare const _hardResetAllStoresForTest: () => void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module store-admin
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Public delete/reset/clear exports.
6
+ *
7
+ * Consumers: store-write barrel.
8
+ */
9
+ export { deleteStore, resetStore, clearAllStores, _hardResetAllStoresForTest, } from "./store-admin-impl.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module store-core
3
+ *
4
+ * LAYER: Store core
5
+ * OWNS: Minimal core adapters and registry accessors.
6
+ *
7
+ * Consumers: Internal async modules.
8
+ */
9
+ import type { StoreRegistry } from "./store-registry.js";
10
+ import type { IStoreCore } from "./store-shared/core.js";
11
+ export declare const getActiveRegistry: () => StoreRegistry;
12
+ export declare const getActiveAsyncRegistry: () => StoreRegistry["async"];
13
+ export declare const createStoreCore: <T = any>(name: string) => IStoreCore<T>;
@@ -0,0 +1,16 @@
1
+ import { type StoreOptions } from "../adapters/options.js";
2
+ import type { NonFunction } from "../types/utility.js";
3
+ import type { StoreDefinition } from "./store-lifecycle/types.js";
4
+ type LazyDisallow<T> = T extends {
5
+ lazy: true;
6
+ } ? never : T;
7
+ export declare const clearSsrGlobalAllowWarned: (name?: string) => void;
8
+ export declare function createStore<Name extends string, State>(name: Name, initialData: () => State, option: StoreOptions<State> & {
9
+ lazy: true;
10
+ }): StoreDefinition<Name, State> | undefined;
11
+ export declare function createStore<Name extends string, State, Opt extends StoreOptions<State>>(name: Name, initialData: NonFunction<State>, option?: LazyDisallow<Opt>): StoreDefinition<Name, State> | undefined;
12
+ export declare function createStoreStrict<Name extends string, State>(name: Name, initialData: () => State, option: StoreOptions<State> & {
13
+ lazy: true;
14
+ }): StoreDefinition<Name, State>;
15
+ export declare function createStoreStrict<Name extends string, State, Opt extends StoreOptions<State>>(name: Name, initialData: NonFunction<State>, option?: LazyDisallow<Opt>): StoreDefinition<Name, State>;
16
+ export {};
@@ -0,0 +1,35 @@
1
+ import { type StoreOptions } from "../adapters/options.js";
2
+ import type { StoreStateMap, StrictStoreMap, HydrateSnapshotFor, HydrationResult } from "./store-lifecycle/types.js";
3
+ type HydrateSnapshot = HydrateSnapshotFor<StoreStateMap & StrictStoreMap>;
4
+ type HydrateOptions<Snapshot extends object> = Partial<{
5
+ [K in keyof Snapshot]: StoreOptions<Snapshot[K]>;
6
+ }> & {
7
+ default?: StoreOptions;
8
+ };
9
+ type HydrationTrustBase<Snapshot extends object> = {
10
+ /**
11
+ * Explicitly trust this snapshot and allow hydration.
12
+ */
13
+ allowTrusted?: boolean;
14
+ /**
15
+ * Alias for allowTrusted.
16
+ */
17
+ allowHydration?: boolean;
18
+ /**
19
+ * @deprecated Use allowTrusted instead.
20
+ */
21
+ allowUntrusted?: boolean;
22
+ validate?: (snapshot: Snapshot) => boolean;
23
+ onValidationError?: (error: unknown, snapshot: Snapshot) => boolean;
24
+ };
25
+ type HydrationTrust<Snapshot extends object> = (HydrationTrustBase<Snapshot> & {
26
+ allowTrusted: true;
27
+ }) | (HydrationTrustBase<Snapshot> & {
28
+ allowHydration: true;
29
+ }) | (HydrationTrustBase<Snapshot> & {
30
+ allowUntrusted: true;
31
+ }) | (HydrationTrustBase<Snapshot> & {
32
+ validate: (snapshot: Snapshot) => boolean;
33
+ });
34
+ export declare const hydrateStores: <Snapshot extends object = HydrateSnapshot>(snapshot: Snapshot, options: HydrateOptions<Snapshot> | undefined, trust: HydrationTrust<Snapshot>) => HydrationResult;
35
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module store-hydrate
3
+ *
4
+ * LAYER: Store runtime
5
+ * OWNS: Public hydrateStores export.
6
+ *
7
+ * Consumers: store-write barrel.
8
+ */
9
+ export { hydrateStores } from "./store-hydrate-impl.js";
@@ -0,0 +1,20 @@
1
+ import { MIDDLEWARE_ABORT } from "../../features/lifecycle.js";
2
+ import { type FeatureHookContext, type FeatureName } from "../../features/feature-registry.js";
3
+ import type { NormalizedOptions } from "../../adapters/options.js";
4
+ import type { StoreValue } from "./types.js";
5
+ export declare const clearFeatureContexts: () => void;
6
+ export declare const createBaseFeatureContext: (name: string) => FeatureHookContext | null;
7
+ export declare const runFeatureCreateHooks: (name: string, notify: (name: string) => void) => void;
8
+ export declare const runFeatureWriteHooks: (name: string, action: string, prev: StoreValue, next: StoreValue, notify: (name: string) => void) => void;
9
+ export declare const runFeatureWriteHooksExcept: (name: string, action: string, prev: StoreValue, next: StoreValue, notify: (name: string) => void, excluded: FeatureName[]) => void;
10
+ export declare const runFeatureDeleteHooks: (name: string, prev: StoreValue, notify: (name: string) => void) => void;
11
+ export declare const runMiddlewareForStore: (name: string, payload: {
12
+ action: string;
13
+ prev: StoreValue;
14
+ next: StoreValue;
15
+ path: unknown;
16
+ correlationId?: string;
17
+ traceContext?: import("../../types/utility.js").TraceContext;
18
+ }) => StoreValue | typeof MIDDLEWARE_ABORT;
19
+ export declare const runStoreHookSafe: (name: string, label: "onCreate" | "onSet" | "onReset" | "onDelete", fn: ((...args: any[]) => void) | undefined, args: any[]) => void;
20
+ export declare const resolveFeatureAvailability: (name: string, options: NormalizedOptions) => NormalizedOptions;
@@ -0,0 +1,23 @@
1
+ import { type IssueSeverity, type IssueVisibility } from "../../internals/reporting.js";
2
+ import type { FeatureName } from "../../features/feature-registry.js";
3
+ import type { StoreDefinition } from "./types.js";
4
+ export declare const getSsrWarningIssued: (name?: string) => boolean;
5
+ export declare const markSsrWarningIssued: (name: string) => void;
6
+ export declare const resetSsrWarningFlag: () => void;
7
+ export declare const qualifyName: (raw: string) => string;
8
+ export declare const nameOf: (name: string | StoreDefinition<string, unknown>) => string;
9
+ export declare const exists: (name: string) => boolean;
10
+ export declare const reportStoreIssue: (name: string, message: string, options?: {
11
+ severity?: IssueSeverity;
12
+ visibility?: IssueVisibility;
13
+ }) => void;
14
+ export declare const reportStoreCreationIssue: (message: string, onError?: (message: string) => void, options?: {
15
+ severity?: IssueSeverity;
16
+ visibility?: IssueVisibility;
17
+ }) => void;
18
+ export declare const reportStoreWarning: (name: string, message: string, visibility?: IssueVisibility) => void;
19
+ export declare const reportStoreCreationWarning: (message: string, onError?: (message: string) => void, visibility?: IssueVisibility) => void;
20
+ export declare const reportStoreError: (name: string, message: string) => void;
21
+ export declare const reportStoreCreationError: (message: string, onError?: (message: string) => void) => void;
22
+ export declare const warnMissingFeature: (storeName: string, featureName: FeatureName, onError?: (message: string) => void) => void;
23
+ export declare const getFeatureApi: (name: FeatureName) => import("../../features/feature-registry.js").DevtoolsFeatureApi | undefined;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @module store-lifecycle/registry
3
+ *
4
+ * LAYER: Store lifecycle
5
+ * OWNS: Module-level behavior and exports for store-lifecycle/registry.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import { getStoreRegistry, type StoreRegistry, type StoreLifecycleEvent, type StoreLifecycleListener } from "../store-registry.js";
10
+ import { type FeatureName, type StoreFeatureRuntime, type StoreFeatureMeta } from "../../features/feature-registry.js";
11
+ import { createStoreAdmin } from "../../internals/store-admin.js";
12
+ import type { StoreValue, Subscriber } from "./types.js";
13
+ export { defaultRegistryScope } from "../store-registry.js";
14
+ export type { StoreLifecycleEvent } from "../store-registry.js";
15
+ export declare const setRegistryContext: (scope: string, registry: StoreRegistry) => void;
16
+ export declare const getRegistry: () => StoreRegistry;
17
+ export declare const onStoreLifecycle: (fn: StoreLifecycleListener | null) => (() => void);
18
+ export declare const emitStoreLifecycle: (registry: StoreRegistry, event: StoreLifecycleEvent) => void;
19
+ export declare function setPathCacheInvalidator(fn: (name: string) => void): void;
20
+ export declare const stores: Record<string, unknown>;
21
+ export declare const subscribers: Record<string, Set<Subscriber>>;
22
+ export declare const initialStates: Record<string, unknown>;
23
+ export declare const initialFactories: Record<string, (() => StoreValue) | undefined>;
24
+ export declare const meta: Record<string, StoreFeatureMeta>;
25
+ export declare const snapshotCache: Record<string, {
26
+ version: number;
27
+ snapshot: StoreValue | null;
28
+ source?: StoreValue | null;
29
+ mode?: "deep" | "shallow" | "ref";
30
+ }>;
31
+ export declare const featureRuntimes: Map<FeatureName, StoreFeatureRuntime<{}>>;
32
+ export declare const storeAdmin: {
33
+ deleteExistingStore: (name: string) => void;
34
+ clearAllStores: () => string[];
35
+ clearStores: (pattern?: string) => string[];
36
+ reportStoreError: (name: string, message: string) => void;
37
+ };
38
+ export declare const getStoreAdmin: () => ReturnType<typeof createStoreAdmin>;
39
+ export declare const getFeatureRuntime: (name: FeatureName) => StoreFeatureRuntime | undefined;
40
+ export declare const initializeRegisteredFeatureRuntimes: () => void;
41
+ export declare const hasStoreEntryInternal: (name: string, registry?: StoreRegistry) => boolean;
42
+ export declare const getStoreValueRef: (name: string, registry?: StoreRegistry) => StoreValue | undefined;
43
+ export declare const getCommittedStoreValueRef: (name: string, registry?: StoreRegistry) => StoreValue | undefined;
44
+ export declare const setStoreValueInternal: (name: string, value: StoreValue, registry?: StoreRegistry) => void;
45
+ export declare const applyFeatureState: (name: string, value: StoreValue, updatedAtMs?: number) => void;
46
+ export declare const recordStoreRead: (name: string, registry?: StoreRegistry) => void;
47
+ export declare const clearAllRegistries: () => void;
48
+ export declare const resetFeaturesForTests: () => void;
49
+ export declare const getMetaEntry: (name: string) => StoreFeatureMeta | undefined;
50
+ export declare const isDeleting: (name: string) => boolean;
51
+ export declare const resolveScope: (scopeOrRegistry?: string | ReturnType<typeof getStoreRegistry>) => {
52
+ scope: string;
53
+ registry: StoreRegistry;
54
+ };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module store-lifecycle/types
3
+ *
4
+ * LAYER: Store lifecycle
5
+ * OWNS: Module-level behavior and exports for store-lifecycle/types.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
10
+ type PrevDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
11
+ type PathInternal<T, Depth extends number> = Depth extends 0 ? never : T extends Primitive ? never : {
12
+ [K in keyof T & (string | number)]: T[K] extends Primitive | Array<unknown> ? `${K}` : `${K}` | `${K}.${PathInternal<T[K], PrevDepth[Depth]>}`;
13
+ }[keyof T & (string | number)];
14
+ export type PathDepth<T, Depth extends number> = PathInternal<T, Depth>;
15
+ export type Path<T, Depth extends number = 10> = PathInternal<T, Depth>;
16
+ export type PathValue<T, P extends Path<T>> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K]> ? PathValue<T[K], Rest> : never : never : P extends keyof T ? T[P] : never;
17
+ export type PartialDeep<T> = T extends Primitive ? T : unknown extends T ? T : {
18
+ [K in keyof T]?: PartialDeep<T[K]>;
19
+ };
20
+ export type StoreValue = unknown;
21
+ export type HydrateSnapshotFor<Map extends object> = Partial<{
22
+ [K in keyof Map & string]: Map[K];
23
+ }>;
24
+ export type HydrationFailureReason = "invalid-name" | "create-failed" | "merge-failed";
25
+ export type HydrationFailure = {
26
+ name: string;
27
+ reason: HydrationFailureReason;
28
+ cause?: unknown;
29
+ received?: unknown;
30
+ };
31
+ export type HydrationBlockReason = "transaction" | "untrusted" | "validation-error" | "validation-failed";
32
+ export type HydrationResult = {
33
+ hydrated: string[];
34
+ created: string[];
35
+ failed: HydrationFailure[];
36
+ blocked?: {
37
+ reason: HydrationBlockReason;
38
+ cause?: unknown;
39
+ };
40
+ };
41
+ export interface StoreStateMap {
42
+ }
43
+ export interface StrictStoreMap {
44
+ }
45
+ type RegisteredStoreMap = StoreStateMap & StrictStoreMap;
46
+ declare const storeNameBrand: unique symbol;
47
+ type BrandedStoreName = string & {
48
+ readonly [storeNameBrand]: true;
49
+ };
50
+ export type StoreName = (keyof RegisteredStoreMap & string) | BrandedStoreName;
51
+ export type StateFor<Name extends string> = Name extends keyof RegisteredStoreMap ? RegisteredStoreMap[Name] : StoreValue;
52
+ export type UnregisteredStoreName<Name extends string> = never;
53
+ export type StoreKey<Name extends string = string, State = StoreValue> = StoreDefinition<Name, State> & {
54
+ __store?: true;
55
+ };
56
+ export interface StoreDefinition<Name extends string = string, State = StoreValue> {
57
+ name: Name;
58
+ state?: State;
59
+ }
60
+ export type WriteResult = {
61
+ ok: true;
62
+ } | {
63
+ ok: false;
64
+ reason: "not-found" | "validate" | "path" | "middleware" | "ssr" | "invalid-args" | "lazy-uninitialized" | "unsupported-op" | "unsupported-path-shape";
65
+ };
66
+ export type Subscriber = (value: StoreValue | null) => void;
67
+ export {};