@hurum/core 0.0.1

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.
@@ -0,0 +1,467 @@
1
+ declare const EVENT_CREATOR_BRAND: unique symbol;
2
+ /** Marker type for event payload definition */
3
+ interface EventDefinition<T> {
4
+ readonly __payload?: T;
5
+ }
6
+ /** An event instance: has a `type` string and payload properties */
7
+ type EventInstance<TType extends string = string, TPayload = unknown> = {
8
+ readonly type: TType;
9
+ } & TPayload;
10
+ /** An event creator function that produces typed event instances */
11
+ interface EventCreator<TType extends string = string, TPayload = unknown> {
12
+ (payload: TPayload): EventInstance<TType, TPayload>;
13
+ readonly type: TType;
14
+ readonly [EVENT_CREATOR_BRAND]: true;
15
+ }
16
+ /**
17
+ * Define an event payload type. Used within `Events()` to declare event shapes.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const MyEvent = Events('My', {
22
+ * happened: Event<{ value: number }>(),
23
+ * })
24
+ * ```
25
+ */
26
+ declare function Event<T = {}>(): EventDefinition<T>;
27
+ type EventCreatorMap<TPrefix extends string, TDefs extends Record<string, EventDefinition<unknown>>> = {
28
+ readonly [K in keyof TDefs & string]: TDefs[K] extends EventDefinition<infer P> ? EventCreator<`${TPrefix}/${K}`, P> : never;
29
+ };
30
+ /**
31
+ * Create a namespaced group of event creators.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const PurchaseEvent = Events('Purchase', {
36
+ * saved: Event<{ purchase: Purchase }>(),
37
+ * saveFailed: Event<{ error: Error }>(),
38
+ * })
39
+ *
40
+ * PurchaseEvent.saved({ purchase }) // { type: 'Purchase/saved', purchase: ... }
41
+ * PurchaseEvent.saved.type // 'Purchase/saved' (string literal type)
42
+ * ```
43
+ */
44
+ declare function Events<TPrefix extends string, TDefs extends Record<string, EventDefinition<unknown>>>(prefix: TPrefix, events: TDefs): EventCreatorMap<TPrefix, TDefs>;
45
+
46
+ declare const COMMAND_BRAND: unique symbol;
47
+ declare const EXECUTOR_BRAND: unique symbol;
48
+ /** A branded command type. Commands are identified by their unique symbol. */
49
+ interface Command<TInput = unknown> {
50
+ readonly [COMMAND_BRAND]: symbol;
51
+ readonly name?: string;
52
+ readonly __inputType?: TInput;
53
+ }
54
+ /** Context provided to executor functions */
55
+ interface ExecutorContext<TDeps = unknown, TState = unknown> {
56
+ readonly deps: TDeps;
57
+ readonly emit: (event: EventInstance) => void;
58
+ readonly getState: () => TState;
59
+ readonly signal: AbortSignal;
60
+ /** Access nested child store instances. Available when the store has Nested fields. */
61
+ readonly scope: Record<string, unknown>;
62
+ }
63
+ /** The executor function type */
64
+ type ExecutorFn<TInput, TDeps, TState> = (command: TInput, context: ExecutorContext<TDeps, TState>) => void | Promise<void>;
65
+ /** An executor registered with a Store.
66
+ * __fn is type-erased (never params) to keep Executor covariant in TInput/TDeps/TState. */
67
+ interface Executor<TInput = unknown, TDeps = unknown, TState = unknown> {
68
+ readonly [EXECUTOR_BRAND]: true;
69
+ readonly __command: Command<TInput>;
70
+ readonly __fn: (command: never, context: never) => void | Promise<void>;
71
+ readonly __inputType?: TInput;
72
+ readonly __depsType?: TDeps;
73
+ readonly __stateType?: TState;
74
+ }
75
+ /**
76
+ * Create a CommandExecutor pair: [Command, Executor].
77
+ *
78
+ * Optionally provide a name as the first argument for devtools visibility.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * // With explicit name
83
+ * const [SaveCmd, SaveExec] = CommandExecutor<
84
+ * { purchase: Purchase },
85
+ * { repo: PurchaseRepo },
86
+ * >('SavePurchase', async (command, { deps, emit }) => {
87
+ * const result = await deps.repo.save(command.purchase)
88
+ * result.match(
89
+ * (saved) => emit(PurchaseEvent.saved({ purchase: saved })),
90
+ * (error) => emit(PurchaseEvent.saveFailed({ error })),
91
+ * )
92
+ * })
93
+ *
94
+ * // Without name (fn.name used as fallback for named functions)
95
+ * const [SaveCmd, SaveExec] = CommandExecutor<{ purchase: Purchase }>(
96
+ * async function SavePurchase(command, { emit }) => { ... }
97
+ * )
98
+ * ```
99
+ */
100
+ declare function CommandExecutor<TInput, TDeps = Record<string, never>, TState = unknown>(nameOrFn: string | ExecutorFn<TInput, TDeps, TState>, maybeFn?: ExecutorFn<TInput, TDeps, TState>): [Command<TInput>, Executor<TInput, TDeps, TState>];
101
+ declare namespace CommandExecutor {
102
+ var passthrough: {
103
+ <TType extends string, TPayload>(eventCreator: EventCreator<TType, TPayload>): [Command<TPayload>, Executor<TPayload, Record<string, never>, unknown>];
104
+ <TType extends string, TPayload, TInput>(eventCreator: EventCreator<TType, TPayload>, transform: (input: TInput) => TPayload): [Command<TInput>, Executor<TInput, Record<string, never>, unknown>];
105
+ <TType extends string, TPayload>(name: string, eventCreator: EventCreator<TType, TPayload>): [Command<TPayload>, Executor<TPayload, Record<string, never>, unknown>];
106
+ <TType extends string, TPayload, TInput>(name: string, eventCreator: EventCreator<TType, TPayload>, transform: (input: TInput) => TPayload): [Command<TInput>, Executor<TInput, Record<string, never>, unknown>];
107
+ };
108
+ }
109
+
110
+ declare const INTENT_BRAND: unique symbol;
111
+ declare const INTENTS_BRAND: unique symbol;
112
+ declare const PREPARED_INTENT_BRAND: unique symbol;
113
+ /** Execution mode for an intent */
114
+ type IntentMode = 'sequential' | 'all' | 'allSettled';
115
+ /** An intent descriptor: references commands and their execution mode */
116
+ interface IntentDescriptor<TInput = unknown> {
117
+ readonly [INTENT_BRAND]: true;
118
+ readonly commands: ReadonlyArray<Command<TInput>>;
119
+ readonly mode: IntentMode;
120
+ readonly name?: string;
121
+ readonly __inputType?: TInput;
122
+ }
123
+ /** A callable intent descriptor. Calling with payload produces a PreparedIntent. */
124
+ interface IntentAction<TInput = unknown> extends IntentDescriptor<TInput> {
125
+ (payload: TInput): PreparedIntent<TInput>;
126
+ }
127
+ /** An intent paired with its payload, ready to dispatch via store.send(). */
128
+ interface PreparedIntent<TInput = unknown> {
129
+ readonly [PREPARED_INTENT_BRAND]: true;
130
+ readonly intent: IntentDescriptor<TInput>;
131
+ readonly payload: TInput;
132
+ }
133
+ /** An intents container: a namespaced group of intent descriptors */
134
+ interface IntentsContainer {
135
+ readonly [INTENTS_BRAND]: true;
136
+ readonly __prefix: string;
137
+ }
138
+ /**
139
+ * Create a callable intent with sequential execution (default).
140
+ * If any executor throws, subsequent commands are skipped.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * const MyIntents = Intents('Purchase', {
145
+ * submitClicked: Intent(ValidateCommand, SaveCommand),
146
+ * pageOpened: Intent(LoadCommand),
147
+ * })
148
+ *
149
+ * // Call to create a PreparedIntent
150
+ * store.send(MyIntents.submitClicked({ formData }))
151
+ *
152
+ * // Or use shorthand
153
+ * store.send.submitClicked({ formData })
154
+ * ```
155
+ */
156
+ declare function Intent<TInput>(...commands: Command<TInput>[]): IntentAction<TInput>;
157
+ declare namespace Intent {
158
+ var all: <TInput>(...commands: Command<TInput>[]) => IntentAction<TInput>;
159
+ var allSettled: <TInput>(...commands: Command<TInput>[]) => IntentAction<TInput>;
160
+ }
161
+ /**
162
+ * Create a namespaced group of intents.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * const PurchaseIntents = Intents('Purchase', {
167
+ * submitClicked: Intent(ValidateCommand, SaveCommand),
168
+ * pageOpened: Intent(LoadCommand),
169
+ * })
170
+ * ```
171
+ */
172
+ declare function Intents<TPrefix extends string, TDefs extends Record<string, IntentDescriptor>>(prefix: TPrefix, intents: TDefs): TDefs & IntentsContainer;
173
+ /** Check if a value is a PreparedIntent (intent + payload pair) */
174
+ declare function isPreparedIntent(value: unknown): value is PreparedIntent;
175
+
176
+ declare const NESTED_BRAND: unique symbol;
177
+ type NestedKind = 'single' | 'array' | 'map';
178
+ interface NestedMarker<TStore = unknown, TKind extends NestedKind = NestedKind> {
179
+ readonly [NESTED_BRAND]: true;
180
+ readonly kind: TKind;
181
+ readonly store: TStore;
182
+ }
183
+ /**
184
+ * Declare a single nested child store.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * Store({ state: { transaction: Nested(TransactionStore) } })
189
+ * ```
190
+ */
191
+ declare function Nested<TStore>(store: TStore): NestedMarker<TStore, 'single'>;
192
+ declare namespace Nested {
193
+ var array: <TStore>(store: TStore) => NestedMarker<TStore, "array">;
194
+ var map: <TStore>(store: TStore) => NestedMarker<TStore, "map">;
195
+ }
196
+
197
+ /**
198
+ * Middleware interface for observing store lifecycle events.
199
+ * Middlewares are pure observers — they must NOT modify state or emit events.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * const myMiddleware: Middleware = {
204
+ * name: 'my-middleware',
205
+ * onEvent: (event, state) => console.log(event.type, state),
206
+ * onError: (error) => reportError(error),
207
+ * }
208
+ * ```
209
+ */
210
+ type Middleware = {
211
+ /** Unique name for this middleware instance */
212
+ name: string;
213
+ /** Called when the middleware is attached to a store instance (during Store.create or singleton init). */
214
+ onAttach?: (store: {
215
+ getState: () => Record<string, unknown>;
216
+ meta?: {
217
+ computedKeys?: readonly string[];
218
+ nestedKeys?: readonly {
219
+ key: string;
220
+ kind: 'single' | 'array' | 'map';
221
+ }[];
222
+ };
223
+ }) => void;
224
+ /** Called when an event is applied to the store */
225
+ onEvent?: (event: EventInstance, state: Record<string, unknown>) => void;
226
+ /** Called after state changes, with previous and next state */
227
+ onStateChange?: (prev: Record<string, unknown>, next: Record<string, unknown>) => void;
228
+ /** Called when an intent starts execution */
229
+ onIntentStart?: (intent: IntentDescriptor, payload: unknown) => void;
230
+ /** Called when an intent finishes execution */
231
+ onIntentEnd?: (intent: IntentDescriptor, payload: unknown) => void;
232
+ /** Called when an executor throws an error */
233
+ onError?: (error: Error, context: {
234
+ intent: IntentDescriptor;
235
+ payload?: unknown;
236
+ command?: Command;
237
+ }) => void;
238
+ };
239
+ /**
240
+ * Factory for creating typed middleware instances.
241
+ * The `.create()` method is called by the store builder to produce
242
+ * a concrete Middleware. This pattern avoids the need for generic
243
+ * type parameters at middleware definition time.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * function myMiddleware(options?: MyOptions): MiddlewareFactory {
248
+ * return {
249
+ * name: 'my-middleware',
250
+ * create() {
251
+ * return {
252
+ * name: 'my-middleware',
253
+ * onEvent: (event, state) => console.log(event.type, state),
254
+ * }
255
+ * },
256
+ * }
257
+ * }
258
+ * ```
259
+ */
260
+ interface MiddlewareFactory {
261
+ create(): Middleware;
262
+ readonly name: string;
263
+ }
264
+
265
+ /** A memoized derived state accessor with structural equality. */
266
+ interface Selector<T> {
267
+ /** Get the current derived value (memoized). */
268
+ get(): T;
269
+ /** Subscribe to changes. Only fires when derived value actually changes. Returns unsubscribe. */
270
+ subscribe(cb: (value: T) => void): () => void;
271
+ /** @internal brand for type discrimination */
272
+ readonly __selectorBrand: true;
273
+ }
274
+ /** Type guard for Selector objects. */
275
+ declare function isSelector(value: unknown): value is Selector<unknown>;
276
+
277
+ declare const STORE_DEF_BRAND: unique symbol;
278
+ /** Resolve nested markers in raw state to their runtime types (includes child computed) */
279
+ type ResolvedState<T> = {
280
+ [K in keyof T]: T[K] extends NestedMarker<infer S, 'single'> ? ResolvedStateOf<S> : T[K] extends NestedMarker<infer S, 'array'> ? ResolvedStateOf<S>[] : T[K] extends NestedMarker<infer S, 'map'> ? Record<string, ResolvedStateOf<S>> : T[K];
281
+ };
282
+ /** Extract resolved state (raw + computed) from a store definition */
283
+ type ResolvedStateOf<S> = S extends StoreDefinition<any, infer R, infer C> ? C extends Record<string, never> ? ResolvedState<R> : ResolvedState<R> & C : never;
284
+ /** Resolve nested markers to raw state only (no child computed). Used for on() handlers. */
285
+ type ReducerState<T> = {
286
+ [K in keyof T]: T[K] extends NestedMarker<infer S, 'single'> ? ReducerStateOf<S> : T[K] extends NestedMarker<infer S, 'array'> ? ReducerStateOf<S>[] : T[K] extends NestedMarker<infer S, 'map'> ? Record<string, ReducerStateOf<S>> : T[K];
287
+ };
288
+ /** Extract raw state (without computed) from a store definition */
289
+ type ReducerStateOf<S> = S extends StoreDefinition<any, infer R, any> ? ReducerState<R> : never;
290
+ /** Extract typed scope from raw state: maps nested keys to their store instance types */
291
+ type ScopeOf<T> = {
292
+ [K in keyof T as T[K] extends NestedMarker ? K : never]: T[K] extends NestedMarker<infer S, 'single'> ? StoreInstanceOf<S> : T[K] extends NestedMarker<infer S, 'array'> ? NestedArrayScope<StoreInstanceOf<S>> : T[K] extends NestedMarker<infer S, 'map'> ? Map<string, StoreInstanceOf<S>> : never;
293
+ };
294
+ /** Scope type for Nested.array — supports ID-based O(1) lookup */
295
+ interface NestedArrayScope<T extends StoreInstance = StoreInstance> {
296
+ /** O(1) lookup by the child's state.id */
297
+ get(id: string): T | undefined;
298
+ /** Returns all child instances as an array */
299
+ values(): T[];
300
+ /** Number of child instances */
301
+ readonly size: number;
302
+ [Symbol.iterator](): Iterator<T>;
303
+ }
304
+ /** Extract store instance type from a store definition */
305
+ type StoreInstanceOf<S> = S extends StoreDefinition<infer D, infer R, infer C, infer I> ? StoreInstance<D, R, C, I> : never;
306
+ /** Extract intent key → input type mapping from an IntentsContainer */
307
+ type IntentMap<T> = {
308
+ [K in keyof T as T[K] extends IntentDescriptor ? K : never]: T[K] extends IntentDescriptor<infer TInput> ? TInput : never;
309
+ };
310
+ /** The send function type: callable (2 overloads) + named intent shorthand properties */
311
+ type SendFn<TIntents extends Record<string, unknown> = Record<string, never>> = {
312
+ /** Send a PreparedIntent (from calling an IntentAction) */
313
+ <TInput>(prepared: PreparedIntent<TInput>): IntentRef;
314
+ /** Send an IntentDescriptor with explicit payload (legacy) */
315
+ <TInput>(intent: IntentDescriptor<TInput>, payload: TInput): IntentRef;
316
+ } & {
317
+ /** Named intent shortcuts: store.send.intentName(payload) */
318
+ readonly [K in keyof TIntents]: (payload: TIntents[K]) => IntentRef;
319
+ };
320
+ /** Extract child store deps type from a nested marker */
321
+ type ChildDepsOf<T> = T extends NestedMarker<infer S, NestedKind> ? S extends StoreDefinition<infer D, any, any> ? D : Record<string, never> : Record<string, never>;
322
+ /** Handler map for namespace-style .on() */
323
+ type EventHandlerMap<TNamespace, TState> = {
324
+ [K in keyof TNamespace]?: TNamespace[K] extends EventCreator<string, infer P> ? (state: TState, payload: P) => TState : never;
325
+ };
326
+ /** Handler map for namespace-style .on() — state input includes computed, return is raw only */
327
+ type ReducerEventHandlerMap<TNamespace, TStateIn, TStateOut> = {
328
+ [K in keyof TNamespace]?: TNamespace[K] extends EventCreator<string, infer P> ? (state: TStateIn, payload: P) => TStateOut : never;
329
+ };
330
+ /** Opaque reference returned by `store.send()` for cancellation via `store.cancel(ref)`. */
331
+ interface IntentRef {
332
+ readonly __intentRefBrand: symbol;
333
+ }
334
+ interface NestedMeta {
335
+ source: {
336
+ instanceId: string;
337
+ index: number;
338
+ parentKey: string;
339
+ };
340
+ }
341
+ type InternalOnHandler = (state: Record<string, unknown>, payload: Record<string, unknown>, meta?: NestedMeta) => Record<string, unknown>;
342
+ type InternalOnHandlerMap = Record<string, InternalOnHandler>;
343
+ type InternalRelayHandler = (event: EventInstance, state: Record<string, unknown>) => EventInstance[];
344
+ type InternalRelayMap = Record<string, InternalRelayHandler>;
345
+ /** Internal configuration accumulated by StoreBuilder. */
346
+ interface StoreConfig<TDeps = unknown, TState = unknown, TComputed = unknown> {
347
+ intents?: IntentsContainer;
348
+ executors?: Executor[];
349
+ state: TState;
350
+ computed?: Record<string, (state: Record<string, unknown>) => unknown>;
351
+ on?: InternalOnHandlerMap;
352
+ relay?: InternalRelayMap;
353
+ middleware?: Middleware[];
354
+ childDepsMap?: Record<string, (parentDeps: Record<string, unknown>) => Record<string, unknown>>;
355
+ /** @internal phantom type for computed inference */
356
+ readonly __computedPhantom?: TComputed;
357
+ /** @internal phantom type for deps inference */
358
+ readonly __depsPhantom?: TDeps;
359
+ }
360
+ /** Options for `StoreDefinition.create()`. Supports initial state override and deps injection. */
361
+ interface StoreCreateOptions<TRawState = unknown, TDeps = unknown> {
362
+ initialState?: Partial<ResolvedState<TRawState>>;
363
+ deps?: Partial<TDeps>;
364
+ }
365
+ /** A store definition (blueprint). Call `.create()` to instantiate. */
366
+ interface StoreDefinition<TDeps = unknown, TRawState = unknown, TComputed = unknown, TIntents extends Record<string, unknown> = Record<string, never>> {
367
+ readonly [STORE_DEF_BRAND]: true;
368
+ readonly __config: StoreConfig<TDeps, TRawState, TComputed>;
369
+ readonly __stateType?: ResolvedState<TRawState> & TComputed;
370
+ readonly __rawStateType?: TRawState;
371
+ readonly __depsType?: TDeps;
372
+ readonly __intentsType?: TIntents;
373
+ create(options?: StoreCreateOptions<TRawState, TDeps>): StoreInstance<TDeps, TRawState, TComputed, TIntents>;
374
+ }
375
+ /** A live store instance. Created by `StoreDefinition.create()`. */
376
+ interface StoreInstance<TDeps = unknown, TRawState = unknown, TComputed = unknown, TIntents extends Record<string, unknown> = Record<string, never>> {
377
+ /** Dispatch intents. Callable with PreparedIntent or (descriptor, payload). Also supports store.send.intentName(payload) shorthand. */
378
+ send: SendFn<TIntents>;
379
+ /** Cancel a specific running intent by its ref. */
380
+ cancel(ref: IntentRef): void;
381
+ /** Cancel all running intents. */
382
+ cancelAll(): void;
383
+ /** Get the current combined state (raw + computed). */
384
+ getState(): ResolvedState<TRawState> & TComputed;
385
+ /** Subscribe to state changes. Returns an unsubscribe function. */
386
+ subscribe(cb: (state: ResolvedState<TRawState> & TComputed) => void): () => void;
387
+ /** Subscribe to raw event emissions. Returns an unsubscribe function. */
388
+ subscribe(type: 'events', cb: (event: EventInstance) => void): () => void;
389
+ /** Dispose the store, cancelling all intents and clearing listeners. */
390
+ dispose(): void;
391
+ /** Create a memoized derived state selector. */
392
+ selector<T>(fn: (state: ResolvedState<TRawState> & TComputed) => T): Selector<T>;
393
+ /** Nested store scope for accessing child store instances. */
394
+ readonly scope: ScopeOf<TRawState>;
395
+ /** @internal phantom type for deps inference */
396
+ readonly __depsPhantom?: TDeps;
397
+ }
398
+ interface StoreInternalFields {
399
+ __eventLog: EventInstance[];
400
+ __stateSnapshots: Array<{
401
+ event: EventInstance;
402
+ state: Record<string, unknown>;
403
+ }>;
404
+ __runningCount: () => number;
405
+ __rawState: () => Record<string, unknown>;
406
+ /** Apply event to this store (for event forwarding from parent to children). */
407
+ __applyEvent: (event: EventInstance, options?: {
408
+ skipEventLog?: boolean;
409
+ }) => void;
410
+ /** Execute a single command (for parent → child delegation). */
411
+ __executeCommand: (command: Command, payload: unknown, signal: AbortSignal) => Promise<void>;
412
+ /** Returns the nestedExecutorIndex for recursive delegation (root → child → grandchild). */
413
+ __getHandleableCommands: () => Map<symbol, StoreInstance & StoreInternalFields>;
414
+ }
415
+ /** @deprecated Use StoreInstance & StoreInternalFields instead */
416
+ type StoreInstanceInternal = StoreInstance & StoreInternalFields;
417
+ /** The return type of Store() — a builder that is also a StoreDefinition. */
418
+ type StoreBuilder<TDeps extends Record<string, unknown>, TRawState extends Record<string, unknown>, TComputed extends Record<string, unknown>, TIntents extends Record<string, unknown> = Record<string, never>> = {
419
+ /** Per-event handler: full payload type inference from EventCreator */
420
+ on<TType extends string, TPayload>(event: EventCreator<TType, TPayload>, handler: (state: ResolvedState<TRawState>, payload: TPayload) => ReducerState<TRawState>): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
421
+ /** Namespace handler: grouped handlers with per-key payload type inference */
422
+ on<TNamespace extends object>(events: TNamespace, handlers: ReducerEventHandlerMap<TNamespace, ResolvedState<TRawState>, ReducerState<TRawState>>): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
423
+ computed<C extends Record<string, (state: ResolvedState<TRawState>) => unknown>>(def: C): StoreBuilder<TDeps, TRawState, {
424
+ [K in keyof C]: ReturnType<C[K]>;
425
+ }, TIntents>;
426
+ intents<TContainer extends IntentsContainer>(container: TContainer): StoreBuilder<TDeps, TRawState, TComputed, TIntents & IntentMap<TContainer>>;
427
+ executors(...execs: Executor[]): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
428
+ deps<D extends Record<string, unknown>>(): StoreBuilder<D, TRawState, TComputed, TIntents>;
429
+ childDeps<K extends keyof TRawState & string>(key: K, mapper: (deps: TDeps) => ChildDepsOf<TRawState[K]>): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
430
+ /** Per-event relay: transform one event type into other events */
431
+ relay<TType extends string, TPayload>(event: EventCreator<TType, TPayload>, handler: (event: EventInstance<TType, TPayload>, state: ResolvedState<TRawState>) => EventInstance[]): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
432
+ middleware(...mws: (Middleware | MiddlewareFactory)[]): StoreBuilder<TDeps, TRawState, TComputed, TIntents>;
433
+ create(options?: StoreCreateOptions<TRawState, TDeps>): StoreInstance<TDeps, TRawState, TComputed, TIntents>;
434
+ } & StoreDefinition<TDeps, TRawState, TComputed, TIntents>;
435
+ /**
436
+ * Create a store builder from an initial state.
437
+ * Returns a chainable builder with `.on()`, `.computed()`, `.intents()`,
438
+ * `.executors()`, `.deps()`, `.childDeps()`, `.relay()`, `.middleware()`, and `.create()`.
439
+ *
440
+ * The builder is also a `StoreDefinition` — you can call `.create()` directly
441
+ * or pass it to testing APIs like `TestStore()`, `TestReducer()`, etc.
442
+ *
443
+ * @example
444
+ * ```ts
445
+ * const CounterStore = Store({ state: { count: 0, multiplier: 2 } })
446
+ * .on(CounterEvent.incremented, (state, { amount }) => ({
447
+ * ...state, count: state.count + amount,
448
+ * }))
449
+ * .computed({
450
+ * doubled: (state) => state.count * 2,
451
+ * product: (state) => state.count * state.multiplier,
452
+ * })
453
+ * .intents(CounterIntents)
454
+ * .executors(IncrementExecutor, DecrementExecutor)
455
+ * .middleware(logger())
456
+ *
457
+ * const store = CounterStore.create()
458
+ * store.send(CounterIntents.increment, {})
459
+ * ```
460
+ */
461
+ declare function Store<TState extends Record<string, unknown>>(config: {
462
+ state: TState;
463
+ }): StoreBuilder<Record<string, never>, TState, Record<string, never>>;
464
+ declare function isStoreDefinition(value: unknown): value is StoreDefinition;
465
+ declare function isStoreInstance(value: unknown): value is StoreInstance;
466
+
467
+ export { type StoreCreateOptions as A, type StoreInstanceInternal as B, type ChildDepsOf as C, type StoreInternalFields as D, type EventInstance as E, isPreparedIntent as F, isSelector as G, isStoreDefinition as H, Intent as I, isStoreInstance as J, type Middleware as M, Nested as N, type PreparedIntent as P, type ResolvedState as R, type StoreDefinition as S, type StoreInstance as a, type Command as b, CommandExecutor as c, Event as d, type EventCreator as e, type EventDefinition as f, type EventHandlerMap as g, Events as h, type Executor as i, type ExecutorContext as j, type IntentAction as k, type IntentDescriptor as l, type IntentMap as m, type IntentMode as n, type IntentRef as o, Intents as p, type MiddlewareFactory as q, type NestedArrayScope as r, type NestedKind as s, type NestedMarker as t, type ResolvedStateOf as u, type ScopeOf as v, type Selector as w, type SendFn as x, Store as y, type StoreBuilder as z };