storion 0.2.3 → 0.3.0

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 (88) hide show
  1. package/README.md +705 -573
  2. package/dist/async/async.d.ts +87 -0
  3. package/dist/async/async.d.ts.map +1 -0
  4. package/dist/async/index.d.ts +13 -0
  5. package/dist/async/index.d.ts.map +1 -0
  6. package/dist/async/index.js +451 -0
  7. package/dist/async/types.d.ts +275 -0
  8. package/dist/async/types.d.ts.map +1 -0
  9. package/dist/collection.d.ts +42 -0
  10. package/dist/collection.d.ts.map +1 -0
  11. package/dist/core/container.d.ts +33 -2
  12. package/dist/core/container.d.ts.map +1 -1
  13. package/dist/core/createResolver.d.ts +47 -0
  14. package/dist/core/createResolver.d.ts.map +1 -0
  15. package/dist/core/equality.d.ts +23 -3
  16. package/dist/core/equality.d.ts.map +1 -1
  17. package/dist/core/fnWrapper.d.ts +54 -0
  18. package/dist/core/fnWrapper.d.ts.map +1 -0
  19. package/dist/core/pick.d.ts +6 -6
  20. package/dist/core/pick.d.ts.map +1 -1
  21. package/dist/core/store.d.ts +8 -8
  22. package/dist/core/store.d.ts.map +1 -1
  23. package/dist/core/storeContext.d.ts +63 -0
  24. package/dist/core/storeContext.d.ts.map +1 -0
  25. package/dist/devtools/controller.d.ts +4 -0
  26. package/dist/devtools/controller.d.ts.map +1 -0
  27. package/dist/devtools/index.d.ts +16 -0
  28. package/dist/devtools/index.d.ts.map +1 -0
  29. package/dist/devtools/index.js +229 -0
  30. package/dist/devtools/middleware.d.ts +22 -0
  31. package/dist/devtools/middleware.d.ts.map +1 -0
  32. package/dist/devtools/types.d.ts +116 -0
  33. package/dist/devtools/types.d.ts.map +1 -0
  34. package/dist/devtools-panel/DevtoolsPanel.d.ts +17 -0
  35. package/dist/devtools-panel/DevtoolsPanel.d.ts.map +1 -0
  36. package/dist/devtools-panel/components/CompareModal.d.ts +10 -0
  37. package/dist/devtools-panel/components/CompareModal.d.ts.map +1 -0
  38. package/dist/devtools-panel/components/EventEntry.d.ts +14 -0
  39. package/dist/devtools-panel/components/EventEntry.d.ts.map +1 -0
  40. package/dist/devtools-panel/components/EventFilterBar.d.ts +10 -0
  41. package/dist/devtools-panel/components/EventFilterBar.d.ts.map +1 -0
  42. package/dist/devtools-panel/components/EventsTab.d.ts +15 -0
  43. package/dist/devtools-panel/components/EventsTab.d.ts.map +1 -0
  44. package/dist/devtools-panel/components/ResizeHandle.d.ts +8 -0
  45. package/dist/devtools-panel/components/ResizeHandle.d.ts.map +1 -0
  46. package/dist/devtools-panel/components/StoreEntry.d.ts +13 -0
  47. package/dist/devtools-panel/components/StoreEntry.d.ts.map +1 -0
  48. package/dist/devtools-panel/components/StoresTab.d.ts +12 -0
  49. package/dist/devtools-panel/components/StoresTab.d.ts.map +1 -0
  50. package/dist/devtools-panel/components/TabLayout.d.ts +48 -0
  51. package/dist/devtools-panel/components/TabLayout.d.ts.map +1 -0
  52. package/dist/devtools-panel/components/icons.d.ts +27 -0
  53. package/dist/devtools-panel/components/icons.d.ts.map +1 -0
  54. package/dist/devtools-panel/components/index.d.ts +15 -0
  55. package/dist/devtools-panel/components/index.d.ts.map +1 -0
  56. package/dist/devtools-panel/hooks.d.ts +23 -0
  57. package/dist/devtools-panel/hooks.d.ts.map +1 -0
  58. package/dist/devtools-panel/index.d.ts +25 -0
  59. package/dist/devtools-panel/index.d.ts.map +1 -0
  60. package/dist/devtools-panel/index.js +3326 -0
  61. package/dist/devtools-panel/mount.d.ts +41 -0
  62. package/dist/devtools-panel/mount.d.ts.map +1 -0
  63. package/dist/devtools-panel/styles.d.ts +50 -0
  64. package/dist/devtools-panel/styles.d.ts.map +1 -0
  65. package/dist/devtools-panel/types.d.ts +15 -0
  66. package/dist/devtools-panel/types.d.ts.map +1 -0
  67. package/dist/devtools-panel/utils.d.ts +21 -0
  68. package/dist/devtools-panel/utils.d.ts.map +1 -0
  69. package/dist/index.d.ts +6 -1
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/is.d.ts +69 -0
  72. package/dist/is.d.ts.map +1 -0
  73. package/dist/react/create.d.ts +1 -1
  74. package/dist/react/index.d.ts +1 -0
  75. package/dist/react/index.d.ts.map +1 -1
  76. package/dist/react/index.js +209 -33
  77. package/dist/react/useLocalStore.d.ts.map +1 -1
  78. package/dist/react/useStore.d.ts +2 -2
  79. package/dist/react/useStore.d.ts.map +1 -1
  80. package/dist/react/withStore.d.ts +140 -0
  81. package/dist/react/withStore.d.ts.map +1 -0
  82. package/dist/{index-rLf6DusB.js → store-XP2pujaJ.js} +537 -740
  83. package/dist/storion.js +740 -9
  84. package/dist/trigger.d.ts +40 -0
  85. package/dist/trigger.d.ts.map +1 -0
  86. package/dist/types.d.ts +516 -50
  87. package/dist/types.d.ts.map +1 -1
  88. package/package.json +13 -1
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Async data mode:
3
+ * - "fresh": data is undefined during loading/error (only show fresh data)
4
+ * - "stale": data is preserved during loading/error (stale-while-revalidate)
5
+ */
6
+ export type AsyncMode = "fresh" | "stale";
7
+ export type AsyncStatus = "idle" | "pending" | "success" | "error";
8
+ /**
9
+ * Serialized async state for persistence/hydration.
10
+ * Only success states are persisted.
11
+ */
12
+ export type SerializedAsyncState<T = unknown> = {
13
+ status: "success";
14
+ mode: AsyncMode;
15
+ data: T;
16
+ } | null;
17
+ /**
18
+ * Async state with mode support.
19
+ * - Fresh mode: data is undefined during idle/pending/error
20
+ * - Stale mode: data is preserved (T) during pending/error after first load
21
+ */
22
+ export type AsyncState<T = unknown, M extends AsyncMode = AsyncMode> = AsyncIdleState<T, M> | AsyncPendingState<T, M> | AsyncSuccessState<T> | AsyncErrorState<T, M>;
23
+ export interface AsyncIdleStateFresh {
24
+ status: "idle";
25
+ mode: "fresh";
26
+ data: undefined;
27
+ error: undefined;
28
+ timestamp: undefined;
29
+ /** @internal Request ID for concurrency control */
30
+ __requestId?: AsyncRequestId;
31
+ toJSON?(): SerializedAsyncState<undefined>;
32
+ }
33
+ export interface AsyncPendingStateFresh<T = unknown> {
34
+ status: "pending";
35
+ mode: "fresh";
36
+ data: undefined;
37
+ error: undefined;
38
+ timestamp: undefined;
39
+ /** @internal Key for Suspense promise tracking */
40
+ __key?: AsyncKey<T>;
41
+ /** @internal Request ID for concurrency control */
42
+ __requestId?: AsyncRequestId;
43
+ toJSON?(): SerializedAsyncState<T>;
44
+ }
45
+ export interface AsyncErrorStateFresh {
46
+ status: "error";
47
+ mode: "fresh";
48
+ data: undefined;
49
+ error: Error;
50
+ timestamp: undefined;
51
+ /** @internal Request ID for concurrency control */
52
+ __requestId?: AsyncRequestId;
53
+ toJSON?(): SerializedAsyncState<undefined>;
54
+ }
55
+ export interface AsyncIdleStateStale<T = unknown> {
56
+ status: "idle";
57
+ mode: "stale";
58
+ data: T;
59
+ error: undefined;
60
+ timestamp: undefined;
61
+ /** @internal Request ID for concurrency control */
62
+ __requestId?: AsyncRequestId;
63
+ toJSON?(): SerializedAsyncState<T>;
64
+ }
65
+ export interface AsyncPendingStateStale<T = unknown> {
66
+ status: "pending";
67
+ mode: "stale";
68
+ data: T;
69
+ error: undefined;
70
+ timestamp: undefined;
71
+ /** @internal Key for Suspense promise tracking */
72
+ __key?: AsyncKey<T>;
73
+ /** @internal Request ID for concurrency control */
74
+ __requestId?: AsyncRequestId;
75
+ toJSON?(): SerializedAsyncState<T>;
76
+ }
77
+ export interface AsyncErrorStateStale<T = unknown> {
78
+ status: "error";
79
+ mode: "stale";
80
+ data: T;
81
+ error: Error;
82
+ timestamp: undefined;
83
+ /** @internal Request ID for concurrency control */
84
+ __requestId?: AsyncRequestId;
85
+ toJSON?(): SerializedAsyncState<T>;
86
+ }
87
+ export type AsyncIdleState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncIdleStateFresh : M extends "stale" ? AsyncIdleStateStale<T> : AsyncIdleStateFresh | AsyncIdleStateStale<T>;
88
+ export type AsyncPendingState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncPendingStateFresh<T> : M extends "stale" ? AsyncPendingStateStale<T> : AsyncPendingStateFresh<T> | AsyncPendingStateStale<T>;
89
+ export interface AsyncSuccessState<T = unknown> {
90
+ status: "success";
91
+ mode: "fresh" | "stale";
92
+ data: T;
93
+ error: undefined;
94
+ timestamp: number;
95
+ /** @internal Request ID for concurrency control */
96
+ __requestId?: AsyncRequestId;
97
+ toJSON?(): SerializedAsyncState<T>;
98
+ }
99
+ export type AsyncErrorState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncErrorStateFresh : M extends "stale" ? AsyncErrorStateStale<T> : AsyncErrorStateFresh | AsyncErrorStateStale<T>;
100
+ /**
101
+ * Opaque key type for linking state to pending promise.
102
+ * Used internally for React Suspense support.
103
+ */
104
+ export type AsyncKey<T = unknown> = object & {
105
+ __brand?: T;
106
+ };
107
+ /**
108
+ * Request ID for detecting external state modifications.
109
+ * Used to prevent stale async updates from overwriting rolled-back state.
110
+ */
111
+ export type AsyncRequestId = object;
112
+ /**
113
+ * Context passed to async handlers.
114
+ */
115
+ export interface AsyncContext {
116
+ /** AbortSignal for cancellation */
117
+ signal: AbortSignal;
118
+ /**
119
+ * Wrap a promise to never resolve if the async operation is cancelled.
120
+ * Useful for nested async operations that should be cancelled together.
121
+ *
122
+ * @example
123
+ * async(focus, async (ctx) => {
124
+ * const data1 = await ctx.safe(fetch('/api/1'));
125
+ * const data2 = await ctx.safe(fetch('/api/2'));
126
+ * return { data1, data2 };
127
+ * });
128
+ */
129
+ safe<T>(promise: Promise<T>): Promise<T>;
130
+ /**
131
+ * Wrap a callback to not run if the async operation is cancelled.
132
+ * Useful for event handlers and timeouts.
133
+ *
134
+ * @example
135
+ * async(focus, async (ctx) => {
136
+ * setTimeout(ctx.safe(() => {
137
+ * // Only runs if not cancelled
138
+ * doSomething();
139
+ * }), 1000);
140
+ * });
141
+ */
142
+ safe<TArgs extends unknown[], TReturn>(callback: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn | undefined;
143
+ /**
144
+ * Cancel the current async operation.
145
+ * Useful for implementing timeouts.
146
+ *
147
+ * @example
148
+ * async(focus, async (ctx) => {
149
+ * // Timeout after 5 seconds
150
+ * setTimeout(ctx.cancel, 5000);
151
+ *
152
+ * const data = await ctx.safe(fetch('/api/slow'));
153
+ * return data;
154
+ * });
155
+ */
156
+ cancel(): void;
157
+ }
158
+ /**
159
+ * Async handler function signature.
160
+ * Receives AsyncContext as first arg, then user-defined args.
161
+ */
162
+ export type AsyncHandler<T, TArgs extends any[]> = (context: AsyncContext, ...args: TArgs) => T | PromiseLike<T>;
163
+ export interface AsyncRetryOptions {
164
+ /** Number of retry attempts */
165
+ count: number;
166
+ /** Delay between retries (ms) or function returning delay */
167
+ delay?: number | ((attempt: number, error: Error) => number);
168
+ }
169
+ /**
170
+ * Options for async mixin setup.
171
+ */
172
+ export interface AsyncOptions {
173
+ /** Error callback */
174
+ onError?: (error: Error) => void;
175
+ /** Retry configuration */
176
+ retry?: number | AsyncRetryOptions;
177
+ /** Auto-cancel previous request on new dispatch (default: true) */
178
+ autoCancel?: boolean;
179
+ }
180
+ export type CancellablePromise<T> = Promise<T> & {
181
+ cancel(): void;
182
+ };
183
+ /**
184
+ * Last invocation info for async action (for typing asyncAction.last())
185
+ */
186
+ export interface AsyncLastInvocation<T, M extends AsyncMode, TArgs extends any[]> {
187
+ /** Arguments passed to the last dispatch */
188
+ readonly args: TArgs;
189
+ /** Invocation count (1-indexed) */
190
+ readonly nth: number;
191
+ /** Current async state (reactive) */
192
+ readonly state: AsyncState<T, M>;
193
+ }
194
+ /**
195
+ * API returned from async() mixin.
196
+ */
197
+ export interface AsyncActions<T, M extends AsyncMode, TArgs extends any[]> {
198
+ /** Dispatch the async operation */
199
+ dispatch(...args: TArgs): CancellablePromise<T>;
200
+ /** Re-dispatch with last args. Returns undefined if no previous dispatch. */
201
+ refresh(): CancellablePromise<T> | undefined;
202
+ /** Cancel ongoing operation */
203
+ cancel(): void;
204
+ /** Reset to idle state */
205
+ reset(): void;
206
+ /**
207
+ * Get the last invocation info including current async state.
208
+ * Reactive - reads from the async state, triggers re-render when state changes.
209
+ *
210
+ * @returns Last invocation info with state, or undefined if never dispatched
211
+ */
212
+ last(): AsyncLastInvocation<T, M, TArgs> | undefined;
213
+ }
214
+ /**
215
+ * Infer the data type from an AsyncState
216
+ */
217
+ export type InferAsyncData<T> = T extends AsyncState<infer D, any> ? D : never;
218
+ /**
219
+ * Infer the mode from an AsyncState
220
+ */
221
+ export type InferAsyncMode<T> = T extends AsyncState<any, infer M> ? M : never;
222
+ /**
223
+ * Settled result for a single async state
224
+ */
225
+ export type SettledResult<T, M extends AsyncMode = AsyncMode> = {
226
+ status: "success";
227
+ data: T;
228
+ } | (M extends "stale" ? {
229
+ status: "error";
230
+ error: Error;
231
+ data: T;
232
+ } : {
233
+ status: "error";
234
+ error: Error;
235
+ data: undefined;
236
+ }) | (M extends "stale" ? {
237
+ status: "pending";
238
+ data: T;
239
+ } : {
240
+ status: "pending";
241
+ data: undefined;
242
+ }) | (M extends "stale" ? {
243
+ status: "idle";
244
+ data: T;
245
+ } : {
246
+ status: "idle";
247
+ data: undefined;
248
+ });
249
+ /**
250
+ * Map a tuple of AsyncState to their data types
251
+ */
252
+ export type MapAsyncData<T extends readonly AsyncState<any, any>[]> = {
253
+ -readonly [K in keyof T]: InferAsyncData<T[K]>;
254
+ };
255
+ /**
256
+ * Map a tuple of AsyncState to SettledResult
257
+ */
258
+ export type MapSettledResult<T extends readonly AsyncState<any, any>[]> = {
259
+ -readonly [K in keyof T]: SettledResult<InferAsyncData<T[K]>, InferAsyncMode<T[K]>>;
260
+ };
261
+ /**
262
+ * Race result type - tuple of [key, value]
263
+ */
264
+ export type RaceResult<T extends Record<string, AsyncState<any, any>>> = {
265
+ [K in keyof T]: [K, InferAsyncData<T[K]>];
266
+ }[keyof T];
267
+ export declare class AsyncNotReadyError extends Error {
268
+ readonly status: AsyncStatus;
269
+ constructor(message: string, status: AsyncStatus);
270
+ }
271
+ export declare class AsyncAggregateError extends Error {
272
+ readonly errors: Error[];
273
+ constructor(message: string, errors: Error[]);
274
+ }
275
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/async/types.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAI1C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC9C,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,IAAI,CAAC;AAET;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,SAAS,GAAG,SAAS,IAC/D,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GACpB,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvB,iBAAiB,CAAC,CAAC,CAAC,GACpB,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAG1B,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,mDAAmD;IACnD,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,MAAM,CAAC,IAAI,oBAAoB,CAAC,SAAS,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,GAAG,OAAO;IACjD,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB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E,IAAI;IACxE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CACrC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACpB,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI;KACtE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1C,CAAC,MAAM,CAAC,CAAC,CAAC;AAIX,qBAAa,kBAAmB,SAAQ,KAAK;aACE,MAAM,EAAE,WAAW;gBAApD,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,WAAW;CAIjE;AAED,qBAAa,mBAAoB,SAAQ,KAAK;aACC,MAAM,EAAE,KAAK,EAAE;gBAAhD,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,KAAK,EAAE;CAI7D"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Lazy-instantiation Map wrapper.
3
+ *
4
+ * Creates items on first access via `get()`. Useful for managing
5
+ * collections where items should be created on-demand.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // Create a collection of emitters, one per property key
10
+ * const emitters = collection((key: string) => emitter<void>());
11
+ *
12
+ * // First access creates the emitter
13
+ * const countEmitter = emitters.get("count"); // creates new emitter
14
+ * const countEmitter2 = emitters.get("count"); // returns same emitter
15
+ * ```
16
+ *
17
+ * @param createItem - Factory function to create new items
18
+ * @param initialItems - Optional initial entries
19
+ * @returns A Map-like object with lazy instantiation on `get()`
20
+ */
21
+ export declare function collection<TKey, TValue>(createItem: (key: TKey) => TValue, initialItems?: readonly [TKey, TValue][]): {
22
+ with(key: TKey, callback: (item: TValue) => void): /*elided*/ any;
23
+ /** Check if key exists (does NOT create item) */
24
+ has(key: TKey): boolean;
25
+ /** Get item by key, creating it if it doesn't exist */
26
+ get(key: TKey): NonNullable<TValue>;
27
+ /** Explicitly set an item */
28
+ set(key: TKey, value: TValue): /*elided*/ any;
29
+ /** Number of items in the collection */
30
+ readonly size: number;
31
+ /** Remove all items */
32
+ clear(): /*elided*/ any;
33
+ /** Remove a specific item */
34
+ delete(key: TKey): /*elided*/ any;
35
+ /** Iterate over keys */
36
+ keys(): MapIterator<TKey>;
37
+ /** Iterate over values */
38
+ values(): MapIterator<TValue>;
39
+ /** Iterate over [key, value] pairs */
40
+ entries(): MapIterator<[TKey, TValue]>;
41
+ };
42
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,EACjC,YAAY,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;cAK5B,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IAOhD,iDAAiD;aACxC,IAAI;IAIb,uDAAuD;aAC9C,IAAI;IAOb,6BAA6B;aACpB,IAAI,SAAS,MAAM;IAK5B,wCAAwC;;IAKxC,uBAAuB;;IAMvB,6BAA6B;gBACjB,IAAI;IAKhB,wBAAwB;;IAKxB,0BAA0B;;IAK1B,sCAAsC;;EAKzC"}
@@ -1,7 +1,38 @@
1
- import { StoreContainer, ContainerOptions } from '../types';
1
+ import { StoreContainer, ContainerOptions, StoreMiddleware } from '../types';
2
2
 
3
+ interface DefaultMiddlewareConfig {
4
+ /** Middleware to run before container's middleware */
5
+ pre?: StoreMiddleware[];
6
+ /** Middleware to run after container's middleware */
7
+ post?: StoreMiddleware[];
8
+ }
9
+ /**
10
+ * Container function with static defaults method.
11
+ */
12
+ interface ContainerFn {
13
+ (options?: ContainerOptions): StoreContainer;
14
+ /**
15
+ * Add default middleware that will be applied to all new containers.
16
+ */
17
+ defaults: {
18
+ (config?: DefaultMiddlewareConfig): void;
19
+ clear(): void;
20
+ };
21
+ }
3
22
  /**
4
23
  * Create a store container.
24
+ *
25
+ * Container provides resolver methods plus store-specific lifecycle:
26
+ * - get(spec): cached instance
27
+ * - create(spec): fresh instance
28
+ * - set(spec, override): override for DI/testing
29
+ * - has(spec): check cache
30
+ * - tryGet(spec): get if cached
31
+ * - delete(spec): remove from cache
32
+ * - clear(): dispose all
33
+ * - scope(): child container
34
+ * - onCreate/onDispose: lifecycle events
5
35
  */
6
- export declare function container(options?: ContainerOptions): StoreContainer;
36
+ export declare const container: ContainerFn;
37
+ export {};
7
38
  //# sourceMappingURL=container.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAKV,cAAc,EAEd,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAMlB;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,cAAc,CA6NxE"}
1
+ {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAErB,MAAM,UAAU,CAAC;AAUlB,UAAU,uBAAuB;IAC/B,sDAAsD;IACtD,GAAG,CAAC,EAAE,eAAe,EAAE,CAAC;IACxB,qDAAqD;IACrD,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC;CAC1B;AAYD;;GAEG;AACH,UAAU,WAAW;IACnB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC;IAC7C;;OAEG;IACH,QAAQ,EAAE;QACR,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;QACzC,KAAK,IAAI,IAAI,CAAC;KACf,CAAC;CACH;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,EAAE,WA6SvB,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Factory, Middleware, Resolver, ResolverOptions } from '../types';
2
+
3
+ export type { Factory, Middleware, MiddlewareContext, Resolver, ResolverOptions, } from '../types';
4
+ /**
5
+ * Create a new resolver with optional middleware and parent.
6
+ */
7
+ export declare function createResolver(options?: ResolverOptions): Resolver;
8
+ /**
9
+ * Create a middleware that only applies to factories matching a predicate.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const storeOnlyMiddleware = when(
14
+ * (factory) => is(factory, "store.spec"),
15
+ * (ctx) => {
16
+ * console.log("Creating store:", ctx.factory.name);
17
+ * return ctx.next();
18
+ * }
19
+ * );
20
+ * ```
21
+ */
22
+ export declare function when(predicate: (factory: Factory) => boolean, middleware: Middleware): Middleware;
23
+ /**
24
+ * Create a logging middleware for debugging.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const app = createResolver({
29
+ * middleware: [createLoggingMiddleware("App")],
30
+ * });
31
+ * ```
32
+ */
33
+ export declare function createLoggingMiddleware(prefix?: string): Middleware;
34
+ /**
35
+ * Create a middleware that validates factory results.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const validateMiddleware = createValidationMiddleware((result) => {
40
+ * if (result === null || result === undefined) {
41
+ * throw new Error("Factory returned null/undefined");
42
+ * }
43
+ * });
44
+ * ```
45
+ */
46
+ export declare function createValidationMiddleware(validate: (result: unknown, factory: Factory) => void): Middleware;
47
+ //# sourceMappingURL=createResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG/E,YAAY,EACV,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,MAAM,UAAU,CAAC;AAMlB;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAuGtE;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAClB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,EACxC,UAAU,EAAE,UAAU,GACrB,UAAU,CAOZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,SAAa,GAAG,UAAU,CAUvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GACpD,UAAU,CAMZ"}
@@ -1,4 +1,4 @@
1
- import { Equality } from '../types';
1
+ import { Equality, EqualityShorthand } from '../types';
2
2
 
3
3
  /**
4
4
  * Strict equality (Object.is).
@@ -6,8 +6,27 @@ import { Equality } from '../types';
6
6
  export declare function strictEqual<T>(a: T, b: T): boolean;
7
7
  /**
8
8
  * Shallow equality for objects/arrays.
9
+ * Compares by reference for each top-level key/index.
10
+ *
11
+ * @param itemEqual - Optional comparator for each item/value (defaults to Object.is)
9
12
  */
10
- export declare function shallowEqual<T>(a: T, b: T): boolean;
13
+ export declare function shallowEqual<T>(a: T, b: T, itemEqual?: (a: unknown, b: unknown) => boolean): boolean;
14
+ /**
15
+ * 2-level shallow equality.
16
+ * Compares keys/length, then shallow compares each item/value.
17
+ *
18
+ * @example
19
+ * [{ id: 1, data: obj }] vs [{ id: 1, data: obj }] // true (same obj ref)
20
+ */
21
+ export declare function shallow2Equal<T>(a: T, b: T): boolean;
22
+ /**
23
+ * 3-level shallow equality.
24
+ * Compares keys/length, then shallow2 compares each item/value.
25
+ *
26
+ * @example
27
+ * [{ id: 1, nested: { data: obj } }] vs [{ id: 1, nested: { data: obj } }] // true
28
+ */
29
+ export declare function shallow3Equal<T>(a: T, b: T): boolean;
11
30
  /**
12
31
  * Deep equality.
13
32
  */
@@ -15,5 +34,6 @@ export declare const deepEqual: (value: any, other: any) => boolean;
15
34
  /**
16
35
  * Resolve equality strategy to a function.
17
36
  */
18
- export declare function resolveEquality<T>(equality: Equality<T> | undefined): (a: T, b: T) => boolean;
37
+ export declare function resolveEquality<T>(e: Equality<T> | undefined): (a: T, b: T) => boolean;
38
+ export declare function equality(shorthand: EqualityShorthand): (a: unknown, b: unknown) => boolean;
19
39
  //# sourceMappingURL=equality.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/core/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAgBnD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,qCAAU,CAAC;AAEjC;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,GAChC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAKzB"}
1
+ {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/core/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG5D;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAmB,GACzD,OAAO,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,qCAAU,CAAC;AAEjC;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,GACzB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAOzB;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,iBAAiB,+BATlC,OAAO,CAWzB"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Utility for wrapping functions while preserving original references.
3
+ *
4
+ * This allows wrapped and original functions to be treated as the same
5
+ * for deduplication purposes (e.g., in trigger()).
6
+ */
7
+ /** Symbol to mark the original function on wrapped functions */
8
+ export declare const ORIGINAL_FN: unique symbol;
9
+ /**
10
+ * Wrap a function while marking the original for later retrieval.
11
+ *
12
+ * @param originalFn - The original function to wrap
13
+ * @param createWrapper - Factory function that receives the original and returns the wrapper
14
+ * @returns The wrapper function with the original marked
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const original = (x: number) => x * 2;
19
+ * const wrapped = wrapFn(original, (fn) => {
20
+ * return (x: number) => {
21
+ * console.log('calling...');
22
+ * return fn(x);
23
+ * };
24
+ * });
25
+ *
26
+ * unwrapFn(wrapped) === original; // true
27
+ * ```
28
+ */
29
+ export declare function wrapFn<T extends Function>(originalFn: T, createWrapper: (original: T) => T): T;
30
+ /**
31
+ * Unwrap a function to get its original reference.
32
+ * If the function is not wrapped, returns the function itself.
33
+ *
34
+ * @param fn - The function to unwrap
35
+ * @returns The original function or the function itself if not wrapped
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const original = (x: number) => x * 2;
40
+ * const wrapped = wrapFn(original, (...args) => original(...args));
41
+ *
42
+ * unwrapFn(wrapped) === original; // true
43
+ * unwrapFn(original) === original; // true
44
+ * ```
45
+ */
46
+ export declare function unwrapFn<T extends Function>(fn: T): T;
47
+ /**
48
+ * Check if a function is wrapped.
49
+ *
50
+ * @param fn - The function to check
51
+ * @returns true if the function has an original reference marked
52
+ */
53
+ export declare function isWrappedFn(fn: Function): boolean;
54
+ //# sourceMappingURL=fnWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fnWrapper.d.ts","sourceRoot":"","sources":["../../src/core/fnWrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gEAAgE;AAChE,eAAO,MAAM,WAAW,eAAmC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,QAAQ,EACvC,UAAU,EAAE,CAAC,EACb,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAChC,CAAC,CAIH;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAGrD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAEjD"}
@@ -10,20 +10,20 @@ import { PickEquality } from '../types';
10
10
  * @example
11
11
  * ```ts
12
12
  * // Without pick: re-renders when ANY profile property changes
13
- * useStore(({ resolve }) => {
14
- * const [state] = resolve(userStore);
13
+ * useStore(({ get }) => {
14
+ * const [state] = get(userStore);
15
15
  * return { name: state.profile.name }; // tracks "profile"
16
16
  * });
17
17
  *
18
18
  * // With pick: re-renders only when profile.name changes
19
- * useStore(({ resolve }) => {
20
- * const [state] = resolve(userStore);
19
+ * useStore(({ get }) => {
20
+ * const [state] = get(userStore);
21
21
  * return { name: pick(() => state.profile.name) };
22
22
  * });
23
23
  *
24
24
  * // With custom equality
25
- * useStore(({ resolve }) => {
26
- * const [state] = resolve(userStore);
25
+ * useStore(({ get }) => {
26
+ * const [state] = get(userStore);
27
27
  * return {
28
28
  * profile: pick(
29
29
  * () => ({ name: state.profile.name, age: state.profile.age }),
@@ -1 +1 @@
1
- {"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/core/pick.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAwGxE"}
1
+ {"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/core/pick.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAyGxE"}
@@ -1,23 +1,23 @@
1
- import { StateBase, ActionsBase, StoreSpec, StoreOptions, StoreInstance, StoreResolver } from '../types';
1
+ import { StateBase, ActionsBase, StoreSpec, StoreOptions, StoreInstance, Resolver, AutoDisposeOptions } from '../types';
2
2
 
3
3
  /**
4
4
  * Create a store specification.
5
5
  *
6
- * The spec is a pure definition - no instance is created.
7
- * Instances are created lazily via container.get().
6
+ * The spec is both a definition AND a factory function:
7
+ * - As object: holds name, options, and STORION_TYPE
8
+ * - As function: `spec(resolver) => StoreInstance`
9
+ *
10
+ * Instances are created lazily via container.get() or by calling spec directly.
8
11
  */
9
12
  export declare function store<TState extends StateBase, TActions extends ActionsBase>(options: StoreOptions<TState, TActions>): StoreSpec<TState, TActions>;
10
13
  /** Options for creating store instance */
11
14
  export interface CreateStoreInstanceOptions {
12
- /** Called when refCount drops to 0 (after grace period) for autoDispose stores */
13
- onUnused?: () => void;
14
- /** Grace period in ms before calling onUnused (default: 100) */
15
- gracePeriodMs?: number;
15
+ autoDispose?: AutoDisposeOptions;
16
16
  }
17
17
  /**
18
18
  * Create a store instance.
19
19
  *
20
20
  * @internal Used by container, not exported publicly.
21
21
  */
22
- export declare function createStoreInstance<TState extends StateBase, TActions extends ActionsBase>(spec: StoreSpec<TState, TActions>, resolver: StoreResolver, instanceOptions?: CreateStoreInstanceOptions): StoreInstance<TState, TActions>;
22
+ export declare function createStoreInstance<TState extends StateBase, TActions extends ActionsBase>(spec: StoreSpec<TState, TActions>, resolver: Resolver, instanceOptions?: CreateStoreInstanceOptions): StoreInstance<TState, TActions>;
23
23
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,aAAa,EAKd,MAAM,UAAU,CAAC;AAqBlB;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,MAAM,SAAS,SAAS,EAAE,QAAQ,SAAS,WAAW,EAC1E,OAAO,EAAE,YAA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