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
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.57.7"
9
+ }
10
+ ]
11
+ }
@@ -1,4 +1,8 @@
1
+ import type { TraceContext } from "../types/utility.js";
1
2
  export type StoreValue = unknown;
3
+ export interface FeatureOptionsMap {
4
+ }
5
+ export type FeatureOptions = Partial<FeatureOptionsMap> & Record<string, unknown>;
2
6
  export interface PersistDriver {
3
7
  getItem?: (k: string) => string | null | Promise<string | null>;
4
8
  setItem?: (k: string, v: string) => void | Promise<void>;
@@ -69,6 +73,11 @@ export interface PersistOptions<State = StoreValue> {
69
73
  * `encrypt` hook is provided.
70
74
  */
71
75
  sensitiveData?: boolean;
76
+ /**
77
+ * Maximum allowed persisted payload size (in characters).
78
+ * When exceeded, hydration is skipped and an error is reported.
79
+ */
80
+ maxSize?: number;
72
81
  /**
73
82
  * Integrity check mode for persisted payloads.
74
83
  * - "hash" (default): store and validate a checksum.
@@ -96,6 +105,7 @@ export interface PersistConfig {
96
105
  decryptAsync?: (v: string) => Promise<string>;
97
106
  allowPlaintext?: boolean;
98
107
  sensitiveData?: boolean;
108
+ maxSize?: number;
99
109
  checksum: "hash" | "none" | "sha256";
100
110
  onMigrationFail?: "reset" | "keep" | ((state: unknown) => unknown);
101
111
  onStorageCleared?: (info: {
@@ -110,21 +120,44 @@ export interface MiddlewareCtx {
110
120
  prev: StoreValue;
111
121
  next: StoreValue;
112
122
  path: unknown;
123
+ correlationId?: string;
124
+ traceContext?: TraceContext;
113
125
  }
114
126
  export interface SyncOptions {
115
127
  channel?: string;
116
128
  maxPayloadBytes?: number;
129
+ /**
130
+ * Authentication policy for sync.
131
+ * - "strict": require authToken or verify (blocks sync if missing)
132
+ * - "insecure": allow unauthenticated sync (explicit opt-out)
133
+ */
134
+ policy?: "strict" | "insecure";
117
135
  /**
118
136
  * Optional shared token for lightweight cross-tab authentication.
119
137
  * When set, incoming sync messages without a matching token are rejected.
120
138
  */
121
139
  authToken?: string;
140
+ /**
141
+ * Explicitly allow unauthenticated sync.
142
+ * Deprecated in favor of policy: "insecure".
143
+ */
144
+ insecure?: boolean;
122
145
  conflictResolver?: (args: {
123
146
  local: StoreValue;
124
147
  incoming: StoreValue;
125
148
  localUpdated: number;
126
149
  incomingUpdated: number;
127
150
  }) => StoreValue | void;
151
+ /**
152
+ * Optional guard to prevent rapid feedback loops when sync updates trigger local reactions.
153
+ *
154
+ * - true: enable with a default window (100ms)
155
+ * - { windowMs }: customize the guard window in milliseconds
156
+ * - false: disable (default is enabled when sync is truthy)
157
+ */
158
+ loopGuard?: boolean | {
159
+ windowMs?: number;
160
+ };
128
161
  /**
129
162
  * Optional checksum mode for sync payloads.
130
163
  * - "hash" (default): include a checksum of the payload.
@@ -208,14 +241,27 @@ export interface StoreOptions<State = StoreValue> {
208
241
  historyLimit?: number;
209
242
  allowSSRGlobalStore?: boolean;
210
243
  sync?: boolean | SyncOptions;
244
+ /**
245
+ * Optional feature option bag for third-party plugins.
246
+ * Keys are plugin names, values are plugin-specific options.
247
+ */
248
+ features?: FeatureOptions;
211
249
  /**
212
250
  * Snapshot cloning strategy used by subscriptions and selector snapshots.
213
251
  *
214
252
  * - "deep" (default): deep clone and dev-freeze snapshot values.
215
253
  * - "shallow": shallow clone (top-level) only; nested references are shared.
216
- * - "ref": return the live store reference (no cloning).
254
+ * - "ref": return the live store reference (dev-freeze by default).
217
255
  */
218
256
  snapshot?: SnapshotMode;
257
+ /**
258
+ * Safety policy for snapshot deliveries when using "ref" or "shallow" modes.
259
+ * - "warn": (default) log a warning in dev when mutation is detected.
260
+ * - "throw": throw an error in dev when mutation is detected.
261
+ * - "auto-clone": in dev, if a subscriber mutates a frozen snapshot, deliver a cloned
262
+ * snapshot to that subscriber so the mutation does not affect other subscribers or the store.
263
+ */
264
+ snapshotSafety?: 'warn' | 'throw' | 'auto-clone';
219
265
  }
220
266
  export interface NormalizedOptions {
221
267
  scope: StoreScope;
@@ -236,12 +282,54 @@ export interface NormalizedOptions {
236
282
  historyLimit: number;
237
283
  allowSSRGlobalStore?: boolean;
238
284
  sync?: boolean | SyncOptions;
285
+ features?: FeatureOptions;
239
286
  snapshot: SnapshotMode;
287
+ /** normalized snapshotSafety value */
288
+ snapshotSafety?: 'warn' | 'throw' | 'auto-clone';
240
289
  explicitPersist: boolean;
241
290
  explicitSync: boolean;
242
291
  explicitDevtools: boolean;
243
292
  }
293
+ /**
294
+ * Resets the internal set of legacy options that have been warned
295
+ * about. Used for testing purposes to prevent warnings from leaking
296
+ * between tests.
297
+ */
244
298
  export declare const resetLegacyOptionDeprecationWarningsForTests: () => void;
299
+ /**
300
+ * Normalize persist options for a store.
301
+ *
302
+ * This function takes the raw persist options from a store and returns
303
+ * a normalized PersistConfig object. If the raw persist options are
304
+ * invalid, this function returns null.
305
+ *
306
+ * @template State
307
+ * @param {StoreOptions<State>["persist"]} persist - The raw persist options for the store.
308
+ * @param {string} name - The name of the store.
309
+ * @returns {PersistConfig | null} A normalized PersistConfig object, or null if the raw persist options are invalid.
310
+ */
245
311
  export declare const normalizePersistOptions: <State>(persist: StoreOptions<State>["persist"], name: string) => PersistConfig | null;
312
+ /**
313
+ * Collect deprecation warnings for a store options object.
314
+ *
315
+ * This function walks through the store options object and checks if any
316
+ * deprecated options are present. If a deprecated option is found, a
317
+ * warning message is added to the warnings array.
318
+ *
319
+ * The function returns an array of warning messages. If no deprecated
320
+ * options are found, an empty array is returned.
321
+ *
322
+ * @template State The type of the state stored in the store.
323
+ * @param option The store options object to check for deprecated options.
324
+ * @returns An array of warning messages for deprecated options. If no deprecated
325
+ * options are found, an empty array is returned.
326
+ */
246
327
  export declare const collectLegacyOptionDeprecationWarnings: <State>(option: StoreOptions<State>) => string[];
247
- export declare const normalizeStoreOptions: <State>(option: StoreOptions<State> | undefined, name: string) => NormalizedOptions;
328
+ /**
329
+ * Normalize a store options object, merging default values and performing deprecation checks.
330
+ * @param option The store options object to normalize.
331
+ * @param name The name of the store.
332
+ * @param defaultSnapshotMode The default snapshot mode to use if none is specified.
333
+ * @returns A normalized store options object.
334
+ */
335
+ export declare const normalizeStoreOptions: <State>(option: StoreOptions<State> | undefined, name: string, defaultSnapshotMode?: SnapshotMode) => NormalizedOptions;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @module async-cache
3
+ *
4
+ * LAYER: Module
5
+ * OWNS: Module-level behavior and exports for async-cache.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import { getActiveAsyncRegistry } from "../core/store-core.js";
10
+ export { getActiveAsyncRegistry } from "../core/store-core.js";
11
+ import type { WarnCategory, StoreCleanupKind } from "./registry.js";
12
+ export type { FetchOptions, AsyncStateSnapshot, AsyncStateAdapter, StoreCleanupKind } from "./registry.js";
13
+ export type FetchInput = string | Promise<unknown> | (() => string | Promise<unknown>);
14
+ export declare const MAX_CACHE_SLOTS_PER_STORE = 100;
15
+ export declare const MAX_INFLIGHT_SLOTS_PER_STORE = 100;
16
+ export declare const MAX_WARNED_ENTRIES = 1000;
17
+ export declare const getFetchRegistry: () => ReturnType<typeof getActiveAsyncRegistry>["fetchRegistry"];
18
+ export declare const getInflightRegistry: () => ReturnType<typeof getActiveAsyncRegistry>["inflight"];
19
+ export declare const getRequestVersionRegistry: () => ReturnType<typeof getActiveAsyncRegistry>["requestVersion"];
20
+ export declare const getCacheMeta: () => ReturnType<typeof getActiveAsyncRegistry>["cacheMeta"];
21
+ export declare const getRateWindowStartRegistry: () => ReturnType<typeof getActiveAsyncRegistry>["rateWindowStart"];
22
+ export declare const getRateCountRegistry: () => ReturnType<typeof getActiveAsyncRegistry>["rateCount"];
23
+ export declare const getRatePruneState: () => ReturnType<typeof getActiveAsyncRegistry>["ratePruneState"];
24
+ export declare const getRevalidateHandlers: () => ReturnType<typeof getActiveAsyncRegistry>["revalidateHandlers"];
25
+ export declare const getStoreCleanups: () => ReturnType<typeof getActiveAsyncRegistry>["storeCleanups"];
26
+ export declare const getWarnedOnce: () => ReturnType<typeof getActiveAsyncRegistry>["warnedOnce"];
27
+ export declare const getRevalidateKeys: () => ReturnType<typeof getActiveAsyncRegistry>["revalidateKeys"];
28
+ export declare const getAsyncMetrics: () => ReturnType<typeof getActiveAsyncRegistry>["asyncMetrics"];
29
+ export declare const markWarned: (set: Set<string>, key: string) => void;
30
+ export declare const warnOnce: (category: WarnCategory, key: string, onWarn: () => void) => void;
31
+ export declare const cleanupStoreCleanupsByKind: (kind: StoreCleanupKind) => void;
32
+ export declare const resetAsyncState: () => void;
33
+ export declare const shouldUseCache: (cacheSlot: string, ttl?: number) => boolean;
34
+ export declare const clearAsyncMeta: (name: string) => void;
35
+ export declare const pruneAsyncCache: (name: string) => void;
36
+ export declare const countInflightSlots: (name: string) => number;
37
+ export declare const registerStoreCleanup: (name: string, fn: () => void, kind?: StoreCleanupKind) => void;
38
+ export declare const unregisterStoreCleanup: (name: string, fn: () => void, kind?: StoreCleanupKind) => void;
39
+ export declare const ensureCleanupSubscription: (_name: string) => void;
@@ -1,2 +1,10 @@
1
- import type { FetchOptions } from "../async-cache.js";
1
+ /**
2
+ * @module async/clone
3
+ *
4
+ * LAYER: Async subsystem
5
+ * OWNS: Module-level behavior and exports for async/clone.
6
+ *
7
+ * Consumers: Internal imports and public API.
8
+ */
9
+ import type { FetchOptions } from "./cache.js";
2
10
  export declare const cloneAsyncResult: (value: unknown, mode: FetchOptions["cloneResult"]) => unknown;
@@ -1,5 +1,5 @@
1
- import { type StoreDefinition, type StoreKey, type StoreName } from "./store-lifecycle.js";
2
- import { type FetchInput, type FetchOptions } from "./async-cache.js";
1
+ import type { StoreDefinition, StoreKey, StoreName } from "../core/store-lifecycle/types.js";
2
+ import { type FetchInput, type FetchOptions } from "./cache.js";
3
3
  export declare function fetchStore<Name extends string, State>(name: StoreDefinition<Name, State>, urlOrRequest: FetchInput, options?: FetchOptions): Promise<unknown>;
4
4
  export declare function fetchStore<Name extends string, State>(name: StoreKey<Name, State>, urlOrRequest: FetchInput, options?: FetchOptions): Promise<unknown>;
5
5
  export declare function fetchStore<Name extends StoreName>(name: Name, urlOrRequest: FetchInput, options?: FetchOptions): Promise<unknown>;
@@ -1,4 +1,4 @@
1
- import type { FetchOptions } from "../async-cache.js";
1
+ import type { FetchOptions } from "./cache.js";
2
2
  export type InflightEntry = {
3
3
  promise: Promise<unknown>;
4
4
  raw: Promise<unknown>;
@@ -1,3 +1,12 @@
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";
1
10
  export type AsyncStateSnapshot = {
2
11
  data?: unknown;
3
12
  loading: boolean;
@@ -5,6 +14,8 @@ export type AsyncStateSnapshot = {
5
14
  status: "idle" | "loading" | "success" | "error" | "aborted";
6
15
  cached?: boolean;
7
16
  revalidating?: boolean;
17
+ correlationId?: string;
18
+ traceContext?: TraceContext;
8
19
  };
9
20
  export type AsyncStateAdapter = (ctx: {
10
21
  name: string;
@@ -12,6 +23,9 @@ export type AsyncStateAdapter = (ctx: {
12
23
  next: AsyncStateSnapshot;
13
24
  set: (value: unknown | ((draft: any) => void)) => void;
14
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>>>;
15
29
  export interface FetchOptions {
16
30
  transform?: (result: unknown) => unknown;
17
31
  onSuccess?: (data: unknown) => void;
@@ -33,6 +47,15 @@ export interface FetchOptions {
33
47
  signal?: AbortSignal;
34
48
  cacheKey?: string;
35
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;
36
59
  /**
37
60
  * Auto-create the backing store if missing.
38
61
  * Defaults to the global config setting (true by default).
@@ -74,11 +97,8 @@ export type AsyncRegistry = {
74
97
  lastAt: number;
75
98
  };
76
99
  ratePruneTimer: ReturnType<typeof setTimeout> | null;
77
- noSignalWarned: Set<string>;
78
- shapeWarned: Set<string>;
79
- autoCreateWarned: Set<string>;
80
- cleanupSubs: Record<string, () => void>;
81
- storeCleanupFns: Record<string, Set<() => void>>;
100
+ warnedOnce: Map<WarnCategory, Set<string>>;
101
+ storeCleanups: Record<string, StoreCleanupBucket>;
82
102
  revalidateKeys: Set<string>;
83
103
  revalidateHandlers: Record<string, () => void>;
84
104
  asyncMetrics: {
@@ -1,3 +1,11 @@
1
- import type { FetchOptions } from "../async-cache.js";
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";
2
10
  export declare const buildFetchOptions: (options: FetchOptions) => RequestInit;
3
11
  export declare const parseResponseBody: (response: Response, responseType: FetchOptions["responseType"]) => Promise<unknown>;
@@ -1,2 +1,10 @@
1
- export type { FetchOptions, FetchInput, AsyncStateSnapshot, AsyncStateAdapter } from "./async-cache.js";
2
- export { fetchStore, refetchStore, enableRevalidateOnFocus, getAsyncMetrics, _resetAsyncStateForTests, } from "./async-fetch.js";
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";
@@ -1,14 +1,12 @@
1
1
  /**
2
2
  * @module computed-graph
3
3
  *
4
- * LAYER: Internal graph engine
5
- * OWNS: Dependency tracking, cycle detection, topological ordering,
6
- * computed entry CRUD. Zero React. Zero async.
4
+ * LAYER: Module
5
+ * OWNS: Module-level behavior and exports for computed-graph.
7
6
  *
8
- * Consumers: computed.ts (public API), store-notify.ts (flush ordering),
9
- * store-admin.ts (cleanup on delete), runtime-tools.ts (diagnostics)
7
+ * Consumers: Internal imports and public API.
10
8
  */
11
- import { type ComputedEntry } from "./store-registry.js";
9
+ import { type ComputedEntry } from "../core/store-registry.js";
12
10
  export declare const detectCycle: (name: string, deps: string[]) => string | null;
13
11
  export declare const registerComputed: (name: string, deps: string[], compute: (...args: unknown[]) => unknown) => boolean;
14
12
  export declare const unregisterComputed: (name: string) => void;
@@ -1,4 +1,5 @@
1
- import type { StoreDefinition, StoreKey, StoreName, StateFor, StoreValue } from "./store-lifecycle.js";
1
+ import "../core/store-notify.js";
2
+ import type { StoreDefinition, StoreKey, StoreName, StateFor, StoreValue } from "../core/store-lifecycle/types.js";
2
3
  export type ComputedOptions = {
3
4
  autoDispose?: boolean;
4
5
  onError?: (err: unknown) => void;
@@ -12,4 +13,4 @@ export declare const invalidateComputed: (name: string) => void;
12
13
  export declare const deleteComputed: (name: string) => void;
13
14
  export declare const isComputedStore: (name: string) => boolean;
14
15
  export declare const _resetComputedForTests: () => void;
15
- export {};
16
+ export { getFullComputedGraph, getComputedDepsFor } from "./computed-graph.js";
@@ -1,2 +1,10 @@
1
- export { configureStroid, resetConfig } from "./internals/config.js";
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";
2
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,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,19 @@
1
+ import { MIDDLEWARE_ABORT } from "../../features/lifecycle.js";
2
+ import { type FeatureHookContext } 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 runFeatureDeleteHooks: (name: string, prev: StoreValue, notify: (name: string) => void) => void;
10
+ export declare const runMiddlewareForStore: (name: string, payload: {
11
+ action: string;
12
+ prev: StoreValue;
13
+ next: StoreValue;
14
+ path: unknown;
15
+ correlationId?: string;
16
+ traceContext?: import("../../types/utility.js").TraceContext;
17
+ }) => StoreValue | typeof MIDDLEWARE_ABORT;
18
+ export declare const runStoreHookSafe: (name: string, label: "onCreate" | "onSet" | "onReset" | "onDelete", fn: ((...args: any[]) => void) | undefined, args: any[]) => void;
19
+ export declare const resolveFeatureAvailability: (name: string, options: NormalizedOptions) => NormalizedOptions;
@@ -1,5 +1,5 @@
1
- import { type IssueSeverity, type IssueVisibility } from "../internals/reporting.js";
2
- import type { FeatureName } from "../feature-registry.js";
1
+ import { type IssueSeverity, type IssueVisibility } from "../../internals/reporting.js";
2
+ import type { FeatureName } from "../../features/feature-registry.js";
3
3
  import type { StoreDefinition } from "./types.js";
4
4
  export declare const getSsrWarningIssued: (name?: string) => boolean;
5
5
  export declare const markSsrWarningIssued: (name: string) => void;
@@ -20,4 +20,4 @@ export declare const reportStoreCreationWarning: (message: string, onError?: (me
20
20
  export declare const reportStoreError: (name: string, message: string) => void;
21
21
  export declare const reportStoreCreationError: (message: string, onError?: (message: string) => void) => void;
22
22
  export declare const warnMissingFeature: (storeName: string, featureName: FeatureName, onError?: (message: string) => void) => void;
23
- export declare const getFeatureApi: (name: FeatureName) => import("../feature-registry.js").DevtoolsFeatureApi | undefined;
23
+ export declare const getFeatureApi: (name: FeatureName) => import("../../features/feature-registry.js").DevtoolsFeatureApi | undefined;
@@ -1,11 +1,22 @@
1
- import { getStoreRegistry, type StoreRegistry } from "../store-registry.js";
2
- import { type FeatureName, type StoreFeatureRuntime, type StoreFeatureMeta } from "../feature-registry.js";
3
- import { createStoreAdmin } from "../internals/store-admin.js";
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";
4
12
  import type { StoreValue, Subscriber } from "./types.js";
5
13
  export { defaultRegistryScope } from "../store-registry.js";
14
+ export type { StoreLifecycleEvent } from "../store-registry.js";
6
15
  export declare const setRegistryContext: (scope: string, registry: StoreRegistry) => void;
7
16
  export declare const getRegistry: () => StoreRegistry;
8
- export declare const setPathCacheInvalidator: (fn: (name: string) => void) => void;
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;
9
20
  export declare const stores: Record<string, unknown>;
10
21
  export declare const subscribers: Record<string, Set<Subscriber>>;
11
22
  export declare const initialStates: Record<string, unknown>;
@@ -14,8 +25,10 @@ export declare const meta: Record<string, StoreFeatureMeta>;
14
25
  export declare const snapshotCache: Record<string, {
15
26
  version: number;
16
27
  snapshot: StoreValue | null;
28
+ source?: StoreValue | null;
29
+ mode?: "deep" | "shallow" | "ref";
17
30
  }>;
18
- export declare const featureRuntimes: Map<FeatureName, StoreFeatureRuntime>;
31
+ export declare const featureRuntimes: Map<FeatureName, StoreFeatureRuntime<{}>>;
19
32
  export declare const storeAdmin: {
20
33
  deleteExistingStore: (name: string) => void;
21
34
  clearAllStores: () => string[];
@@ -25,10 +38,11 @@ export declare const storeAdmin: {
25
38
  export declare const getStoreAdmin: () => ReturnType<typeof createStoreAdmin>;
26
39
  export declare const getFeatureRuntime: (name: FeatureName) => StoreFeatureRuntime | undefined;
27
40
  export declare const initializeRegisteredFeatureRuntimes: () => void;
28
- export declare const hasStoreEntryInternal: (name: string) => boolean;
29
- export declare const getStoreValueRef: (name: string) => StoreValue | undefined;
30
- export declare const setStoreValueInternal: (name: string, value: StoreValue) => 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 setStoreValueInternal: (name: string, value: StoreValue, registry?: StoreRegistry) => void;
31
44
  export declare const applyFeatureState: (name: string, value: StoreValue, updatedAtMs?: number) => void;
45
+ export declare const recordStoreRead: (name: string, registry?: StoreRegistry) => void;
32
46
  export declare const clearAllRegistries: () => void;
33
47
  export declare const resetFeaturesForTests: () => void;
34
48
  export declare const getMetaEntry: (name: string) => StoreFeatureMeta | undefined;
@@ -1,3 +1,11 @@
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
+ */
1
9
  type Primitive = string | number | boolean | bigint | symbol | null | undefined;
2
10
  type PrevDepth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
3
11
  type PathInternal<T, Depth extends number> = Depth extends 0 ? never : T extends Primitive ? never : {
@@ -10,6 +18,26 @@ export type PartialDeep<T> = T extends Primitive ? T : unknown extends T ? T : {
10
18
  [K in keyof T]?: PartialDeep<T[K]>;
11
19
  };
12
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
+ };
13
41
  export interface StoreStateMap {
14
42
  }
15
43
  export interface StrictStoreMap {
@@ -33,7 +61,7 @@ export type WriteResult = {
33
61
  ok: true;
34
62
  } | {
35
63
  ok: false;
36
- reason: "not-found" | "validate" | "path" | "middleware" | "ssr" | "invalid-args";
64
+ reason: "not-found" | "validate" | "path" | "middleware" | "ssr" | "invalid-args" | "lazy-uninitialized";
37
65
  };
38
66
  export type Subscriber = (value: StoreValue | null) => void;
39
67
  export {};