coaction 1.5.0 → 2.0.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.
package/dist/index.d.mts CHANGED
@@ -1,17 +1,17 @@
1
- import { Transport } from 'data-transport';
2
- import { Draft, Patches } from 'mutative';
1
+ import { Transport } from "data-transport";
2
+ import { Draft, Patches } from "mutative";
3
+ import { computed, effect, effectScope, endBatch, isComputed, isEffect, isEffectScope, isSignal, signal, startBatch, trigger } from "alien-signals";
3
4
 
5
+ //#region packages/core/src/interface.d.ts
4
6
  /**
5
7
  * Generic object shape used by stores and slices.
6
8
  */
7
- type ISlices<T = any> = Record<string, T>;
9
+ type ISlices<T = any> = Record<PropertyKey, T>;
8
10
  /**
9
11
  * Recursive partial object accepted by {@link Store.setState} when merging a
10
12
  * plain object payload into the current state tree.
11
13
  */
12
- type DeepPartial<T> = {
13
- [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
14
- };
14
+ type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] };
15
15
  /**
16
16
  * Subscription callback invoked after the store publishes a state change.
17
17
  */
@@ -20,33 +20,33 @@ type Listener = () => void;
20
20
  * Patch pair exposed to middleware compatibility hooks.
21
21
  */
22
22
  interface PatchTransform {
23
- patches: Patches;
24
- inversePatches: Patches;
23
+ patches: Patches;
24
+ inversePatches: Patches;
25
25
  }
26
26
  /**
27
27
  * Trace envelope emitted before and after a store method executes.
28
28
  */
29
29
  interface StoreTraceEvent {
30
- /**
31
- * The id of the method.
32
- */
33
- id: string;
34
- /**
35
- * The method name.
36
- */
37
- method: string;
38
- /**
39
- * The slice key.
40
- */
41
- sliceKey?: string;
42
- /**
43
- * The parameters of the method.
44
- */
45
- parameters?: any[];
46
- /**
47
- * The result of the method.
48
- */
49
- result?: any;
30
+ /**
31
+ * The id of the method.
32
+ */
33
+ id: string;
34
+ /**
35
+ * The method name.
36
+ */
37
+ method: string;
38
+ /**
39
+ * The slice key.
40
+ */
41
+ sliceKey?: PropertyKey;
42
+ /**
43
+ * The parameters of the method.
44
+ */
45
+ parameters?: any[];
46
+ /**
47
+ * The result of the method.
48
+ */
49
+ result?: any;
50
50
  }
51
51
  /**
52
52
  * Runtime store contract returned by {@link create} before framework-specific
@@ -58,92 +58,95 @@ interface StoreTraceEvent {
58
58
  * are later invoked.
59
59
  */
60
60
  interface Store<T extends ISlices = ISlices> {
61
- /**
62
- * The name of the store.
63
- */
64
- name: string;
65
- /**
66
- * Mutate the current state.
67
- *
68
- * @remarks
69
- * Pass a deep-partial object to merge fields, or pass an updater to edit a
70
- * Mutative draft. Passing `null` is a no-op. Client-side shared stores intentionally reject direct
71
- * `setState()` calls; trigger a store method instead.
72
- */
73
- setState: (
74
- /**
75
- * The next partial state, or an updater that mutates a draft.
76
- */
77
- next: DeepPartial<T> | ((draft: Draft<T>) => any) | null,
78
- /**
79
- * Low-level updater hook used by transports and middleware integrations.
80
- */
81
- updater?: (next: DeepPartial<T> | ((draft: Draft<T>) => any) | null) => [] | [T, Patches, Patches]) => void;
82
- /**
83
- * Read the current state object.
84
- *
85
- * @remarks
86
- * The returned object includes methods and getters. Methods destructured from
87
- * this object continue to execute against the latest store state.
88
- */
89
- getState: () => T;
90
- /**
91
- * Subscribe to state changes.
92
- *
93
- * @returns A function that removes the listener.
94
- */
95
- subscribe: (listener: Listener) => () => void;
96
- /**
97
- * Tear down the store.
98
- *
99
- * @remarks
100
- * `destroy()` is idempotent. It clears subscriptions and disposes any
101
- * attached transport.
102
- */
103
- destroy: () => void;
104
- /**
105
- * Indicates whether the store is local, the main shared store, or a client
106
- * mirror of a shared store.
107
- */
108
- share?: 'main' | 'client' | false;
109
- /**
110
- * Transport used to synchronize a shared store between processes or threads.
111
- */
112
- transport?: Transport;
113
- /**
114
- * Whether `createState` was interpreted as a slices object.
115
- */
116
- isSliceStore: boolean;
117
- /**
118
- * Apply patches to the current state.
119
- *
120
- * @remarks
121
- * This is a low-level hook used by transports and middleware. Application
122
- * code should generally prefer store methods or `setState()`.
123
- */
124
- apply: (state?: T, patches?: Patches) => void;
125
- /**
126
- * Return the current state without methods or getters.
127
- *
128
- * @remarks
129
- * Useful for serialization, inspection, or tests that only care about raw
130
- * data.
131
- */
132
- getPureState: () => T;
133
- /**
134
- * Return the state produced during initialization before later mutations.
135
- */
136
- getInitialState: () => T;
137
- /**
138
- * @deprecated Middleware compatibility hook. Prefer typing middleware stores
139
- * with `MiddlewareStore`.
140
- */
141
- patch?: (option: PatchTransform) => PatchTransform;
142
- /**
143
- * @deprecated Middleware compatibility hook. Prefer typing middleware stores
144
- * with `MiddlewareStore`.
145
- */
146
- trace?: (options: StoreTraceEvent) => void;
61
+ /**
62
+ * The name of the store.
63
+ */
64
+ name: string;
65
+ /**
66
+ * Mutate the current state.
67
+ *
68
+ * @remarks
69
+ * Pass a deep-partial object to merge fields, or pass an updater to edit a
70
+ * Mutative draft. Passing `null` is a no-op. Client-side shared stores intentionally reject direct
71
+ * `setState()` calls; trigger a store method instead.
72
+ */
73
+ setState: (
74
+ /**
75
+ * The next partial state, or an updater that mutates a draft.
76
+ */
77
+
78
+ next: DeepPartial<T> | ((draft: Draft<T>) => any) | null,
79
+ /**
80
+ * Low-level updater hook used by transports and middleware integrations.
81
+ */
82
+
83
+ updater?: (next: DeepPartial<T> | ((draft: Draft<T>) => any) | null) => [] | [T, Patches, Patches]) => void;
84
+ /**
85
+ * Read the current state object.
86
+ *
87
+ * @remarks
88
+ * The returned object includes methods and getters. Methods destructured from
89
+ * this object continue to execute against the latest store state.
90
+ */
91
+ getState: () => T;
92
+ /**
93
+ * Subscribe to state changes.
94
+ *
95
+ * @returns A function that removes the listener.
96
+ */
97
+ subscribe: (listener: Listener) => () => void;
98
+ /**
99
+ * Tear down the store.
100
+ *
101
+ * @remarks
102
+ * `destroy()` is idempotent. It clears subscriptions and disposes any
103
+ * attached transport.
104
+ */
105
+ destroy: () => void;
106
+ /**
107
+ * Indicates whether the store is local, the main shared store, or a client
108
+ * mirror of a shared store.
109
+ */
110
+ share?: 'main' | 'client' | false;
111
+ /**
112
+ * Transport used to synchronize a shared store between processes or threads.
113
+ */
114
+ transport?: Transport;
115
+ /**
116
+ * Whether `createState` was interpreted as a slices object.
117
+ */
118
+ isSliceStore: boolean;
119
+ /**
120
+ * Apply patches to the current state.
121
+ *
122
+ * @remarks
123
+ * This is a low-level hook used by transports and middleware. Application
124
+ * code should generally prefer store methods or `setState()`. Client-side
125
+ * shared-store mirrors reject direct `apply()` calls.
126
+ */
127
+ apply: (state?: T, patches?: Patches) => void;
128
+ /**
129
+ * Return the current state without methods or getters.
130
+ *
131
+ * @remarks
132
+ * Useful for serialization, inspection, or tests that only care about raw
133
+ * data.
134
+ */
135
+ getPureState: () => T;
136
+ /**
137
+ * Return the state produced during initialization before later mutations.
138
+ */
139
+ getInitialState: () => T;
140
+ /**
141
+ * @deprecated Middleware compatibility hook. Prefer typing middleware stores
142
+ * with `MiddlewareStore`.
143
+ */
144
+ patch?: (option: PatchTransform) => PatchTransform;
145
+ /**
146
+ * @deprecated Middleware compatibility hook. Prefer typing middleware stores
147
+ * with `MiddlewareStore`.
148
+ */
149
+ trace?: (options: StoreTraceEvent) => void;
147
150
  }
148
151
  /**
149
152
  * Semantic alias for middleware-facing stores.
@@ -152,8 +155,7 @@ interface Store<T extends ISlices = ISlices> {
152
155
  * Middleware implementations should type their `store` parameter as
153
156
  * `MiddlewareStore` instead of relying on deprecated `patch` or `trace` hooks.
154
157
  */
155
- interface MiddlewareStore<T extends ISlices = ISlices> extends Store<T> {
156
- }
158
+ interface MiddlewareStore<T extends ISlices = ISlices> extends Store<T> {}
157
159
  /**
158
160
  * Helper passed into {@link Slice} and {@link Slices} factories.
159
161
  *
@@ -162,8 +164,8 @@ interface MiddlewareStore<T extends ISlices = ISlices> extends Store<T> {
162
164
  * dependency selector pair to define a computed value.
163
165
  */
164
166
  interface Getter<T extends ISlices> {
165
- <P extends any[], R>(getDeps: (store: T) => readonly [...P] | [...P], selector: (...args: P) => R): R;
166
- (): T;
167
+ <P extends any[], R>(getDeps: (store: T) => readonly [...P] | [...P], selector: (...args: P) => R): R;
168
+ (): T;
167
169
  }
168
170
  /**
169
171
  * Factory for a single store object.
@@ -176,14 +178,17 @@ type Slice<T extends ISlices> = (
176
178
  /**
177
179
  * The setState is used to update the state.
178
180
  */
179
- set: Store<T>['setState'],
181
+
182
+ set: Store<T>['setState'],
180
183
  /**
181
184
  * The getState is used to get the state.
182
185
  */
183
- get: Getter<T>,
186
+
187
+ get: Getter<T>,
184
188
  /**
185
189
  * The store is used to store the state.
186
190
  */
191
+
187
192
  store: Store<T>) => T;
188
193
  /**
189
194
  * Factory for a named slice inside a slices store.
@@ -197,14 +202,17 @@ type Slices<T extends ISlices, K extends keyof T> = (
197
202
  /**
198
203
  * The setState is used to update the state.
199
204
  */
200
- set: Store<T>['setState'],
205
+
206
+ set: Store<T>['setState'],
201
207
  /**
202
208
  * The getState is used to get the state.
203
209
  */
204
- get: Getter<T>,
210
+
211
+ get: Getter<T>,
205
212
  /**
206
213
  * The store is used to store the state.
207
214
  */
215
+
208
216
  store: Store<T>) => T[K];
209
217
  /**
210
218
  * Store enhancer invoked during store creation.
@@ -218,48 +226,46 @@ type Middleware<T extends CreateState> = (store: MiddlewareStore<T>) => Middlewa
218
226
  * Derived state object produced by mapping slice factories to their return
219
227
  * types.
220
228
  */
221
- type SliceState<T extends Record<string, Slice<any>>> = {
222
- [K in keyof T]: ReturnType<T[K]>;
223
- };
229
+ type SliceState<T extends Record<PropertyKey, Slice<any>>> = { [K in keyof T]: ReturnType<T[K]> };
224
230
  /**
225
231
  * Options for creating a local store or the main side of a shared store.
226
232
  */
227
233
  type StoreOptions<T extends CreateState> = {
228
- /**
229
- * The name of the store.
230
- */
231
- name?: string;
232
- /**
233
- * @deprecated Internal worker-mode override retained for compatibility.
234
- * Prefer passing `transport` or letting the runtime infer the environment.
235
- */
236
- workerType?: 'SharedWorkerInternal' | 'WebWorkerInternal';
237
- /**
238
- * Inject a pre-built transport for advanced shared-store setups.
239
- */
240
- transport?: Transport;
241
- /**
242
- * Middleware chain applied before the initial state is finalized.
243
- */
244
- middlewares?: Middleware<T>[];
245
- /**
246
- * Enable patch generation.
247
- *
248
- * @remarks
249
- * Required for async client stores and useful for middleware or mutable
250
- * integrations that depend on patch streams.
251
- */
252
- enablePatches?: boolean;
253
- /**
254
- * Control how `createState` should be interpreted.
255
- *
256
- * @remarks
257
- * - auto: infer from createState shape. Object maps whose values are all
258
- * functions are ambiguous, so prefer setting `sliceMode` explicitly.
259
- * - slices: force slices mode.
260
- * - single: force single-store mode.
261
- */
262
- sliceMode?: 'auto' | 'slices' | 'single';
234
+ /**
235
+ * The name of the store.
236
+ */
237
+ name?: string;
238
+ /**
239
+ * @deprecated Internal worker-mode override retained for compatibility.
240
+ * Prefer passing `transport` or letting the runtime infer the environment.
241
+ */
242
+ workerType?: 'SharedWorkerInternal' | 'WebWorkerInternal';
243
+ /**
244
+ * Inject a pre-built transport for advanced shared-store setups.
245
+ */
246
+ transport?: Transport;
247
+ /**
248
+ * Middleware chain applied before the initial state is finalized.
249
+ */
250
+ middlewares?: Middleware<T>[];
251
+ /**
252
+ * Enable patch generation.
253
+ *
254
+ * @remarks
255
+ * Required for async client stores and useful for middleware or mutable
256
+ * integrations that depend on patch streams.
257
+ */
258
+ enablePatches?: boolean;
259
+ /**
260
+ * Control how `createState` should be interpreted.
261
+ *
262
+ * @remarks
263
+ * - auto: infer from createState shape. Object maps whose values are all
264
+ * functions are ambiguous, so prefer setting `sliceMode` explicitly.
265
+ * - slices: force slices mode.
266
+ * - single: force single-store mode.
267
+ */
268
+ sliceMode?: 'auto' | 'slices' | 'single';
263
269
  };
264
270
  /**
265
271
  * Options for creating a client mirror of a shared store.
@@ -269,61 +275,57 @@ type StoreOptions<T extends CreateState> = {
269
275
  * execution happens on the main/shared store.
270
276
  */
271
277
  type ClientStoreOptions<T extends CreateState> = {
272
- /**
273
- * The name of the shared store to connect to.
274
- */
275
- name?: string;
276
- /**
277
- * Middleware chain applied to the client-side store wrapper.
278
- */
279
- middlewares?: Middleware<T>[];
280
- /**
281
- * Control how `createState` should be interpreted.
282
- *
283
- * @remarks
284
- * - auto: infer from createState shape. Object maps whose values are all
285
- * functions are ambiguous, so prefer setting `sliceMode` explicitly.
286
- * - slices: force slices mode.
287
- * - single: force single-store mode.
288
- */
289
- sliceMode?: 'auto' | 'slices' | 'single';
278
+ /**
279
+ * The name of the shared store to connect to.
280
+ */
281
+ name?: string;
282
+ /**
283
+ * Middleware chain applied to the client-side store wrapper.
284
+ */
285
+ middlewares?: Middleware<T>[];
286
+ /**
287
+ * Control how `createState` should be interpreted.
288
+ *
289
+ * @remarks
290
+ * - auto: infer from createState shape. Object maps whose values are all
291
+ * functions are ambiguous, so prefer setting `sliceMode` explicitly.
292
+ * - slices: force slices mode.
293
+ * - single: force single-store mode.
294
+ */
295
+ sliceMode?: 'auto' | 'slices' | 'single';
290
296
  } & ClientTransportOptions;
291
297
  /**
292
298
  * Transport-related options for client/shared-store mirrors.
293
299
  */
294
300
  interface ClientTransportOptions {
295
- /**
296
- * @deprecated Internal worker-mode override retained for compatibility.
297
- * Prefer passing `clientTransport` or `worker`.
298
- */
299
- workerType?: 'WebWorkerClient' | 'SharedWorkerClient';
300
- /**
301
- * How long the client should wait for sequence catch-up before falling back
302
- * to `fullSync`.
303
- *
304
- * Increase this when worker-side execution can complete before the matching
305
- * incremental `update` message arrives under heavy load.
306
- *
307
- * @default 1500
308
- */
309
- executeSyncTimeoutMs?: number;
310
- /**
311
- * Inject a pre-built client transport.
312
- */
313
- clientTransport?: Transport<any>;
314
- /**
315
- * Build a client transport from a Worker or SharedWorker instance.
316
- */
317
- worker?: SharedWorker | Worker;
301
+ /**
302
+ * @deprecated Internal worker-mode override retained for compatibility.
303
+ * Prefer passing `clientTransport` or `worker`.
304
+ */
305
+ workerType?: 'WebWorkerClient' | 'SharedWorkerClient';
306
+ /**
307
+ * How long the client should wait for sequence catch-up before falling back
308
+ * to `fullSync`.
309
+ *
310
+ * Increase this when worker-side execution can complete before the matching
311
+ * incremental `update` message arrives under heavy load.
312
+ *
313
+ * @default 1500
314
+ */
315
+ executeSyncTimeoutMs?: number;
316
+ /**
317
+ * Inject a pre-built client transport.
318
+ */
319
+ clientTransport?: Transport<any>;
320
+ /**
321
+ * Build a client transport from a Worker or SharedWorker instance.
322
+ */
323
+ worker?: SharedWorker | Worker;
318
324
  }
319
325
  /**
320
326
  * Transform store methods into promise-returning methods for client stores.
321
327
  */
322
- type Asyncify<T extends object, D extends true | false> = {
323
- [K in keyof T]: T[K] extends (...args: any[]) => any ? (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>> : D extends false ? T[K] : {
324
- [P in keyof T[K]]: T[K][P] extends (...args: any[]) => any ? (...args: Parameters<T[K][P]>) => Promise<ReturnType<T[K][P]>> : T[K][P];
325
- };
326
- };
328
+ type Asyncify<T extends object, D extends true | false> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? (...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>> : D extends false ? T[K] : { [P in keyof T[K]]: T[K][P] extends ((...args: any[]) => any) ? (...args: Parameters<T[K][P]>) => Promise<Awaited<ReturnType<T[K][P]>>> : T[K][P] } };
327
329
  /**
328
330
  * Store shape returned by {@link create} when acting as a client of a shared
329
331
  * store.
@@ -343,7 +345,13 @@ type StoreReturn<T extends object> = Store<T> & ((...args: any[]) => T);
343
345
  * This can be either a single store factory/object or a map of slice
344
346
  * factories.
345
347
  */
346
- type CreateState = ISlices | Record<string, Slice<any>>;
348
+ type CreateState = ISlices | Record<PropertyKey, Slice<any>>;
349
+ type SingleStoreOptions<T extends CreateState> = StoreOptions<T> & {
350
+ sliceMode: 'single';
351
+ };
352
+ type SingleClientStoreOptions<T extends CreateState> = ClientStoreOptions<T> & {
353
+ sliceMode: 'single';
354
+ };
347
355
  /**
348
356
  * Overload set for {@link create}.
349
357
  *
@@ -357,12 +365,15 @@ type CreateState = ISlices | Record<string, Slice<any>>;
357
365
  * `sliceMode` to avoid ambiguous inference.
358
366
  */
359
367
  type Creator = {
360
- <T extends Record<string, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
361
- <T extends ISlices>(createState: Slice<T>, options?: StoreOptions<T>): StoreReturn<T>;
362
- <T extends Record<string, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
363
- <T extends ISlices>(createState: Slice<T>, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
368
+ <T extends ISlices>(createState: T, options: SingleStoreOptions<T>): StoreReturn<T>;
369
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: StoreOptions<T>): StoreReturn<SliceState<T>>;
370
+ <T extends ISlices>(createState: Slice<T> | T, options?: StoreOptions<T>): StoreReturn<T>;
371
+ <T extends ISlices>(createState: T, options: SingleClientStoreOptions<T>): StoreWithAsyncFunction<T>;
372
+ <T extends Record<PropertyKey, Slice<any>>>(createState: T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<SliceState<T>, true>;
373
+ <T extends ISlices>(createState: Slice<T> | T, options?: ClientStoreOptions<T>): StoreWithAsyncFunction<T>;
364
374
  };
365
-
375
+ //#endregion
376
+ //#region packages/core/src/create.d.ts
366
377
  /**
367
378
  * Create a local store, the main side of a shared store, or a client mirror of
368
379
  * a shared store.
@@ -379,54 +390,128 @@ type Creator = {
379
390
  * ambiguous `create()` input forms.
380
391
  */
381
392
  declare const create: Creator;
382
-
393
+ //#endregion
394
+ //#region packages/core/src/internal.d.ts
395
+ type MutationOperation = 'setState' | 'apply';
396
+ type SignalSlot = {
397
+ refresh: () => void;
398
+ };
383
399
  interface Internal<T extends CreateState = CreateState> {
384
- /**
385
- * The store module.
386
- */
387
- module: T;
388
- /**
389
- * The root state.
390
- */
391
- rootState: T | Draft<T>;
392
- /**
393
- * The backup state.
394
- */
395
- backupState: T | Draft<T>;
396
- /**
397
- * Finalize the draft.
398
- */
399
- finalizeDraft: () => [T, Patches, Patches];
400
- /**
401
- * The mutable instance.
402
- */
403
- mutableInstance: any;
404
- /**
405
- * The sequence number.
406
- */
407
- sequence: number;
408
- /**
409
- * Whether the batch is running.
410
- */
411
- isBatching: boolean;
412
- /**
413
- * The listeners.
414
- */
415
- listeners: Set<Listener>;
416
- /**
417
- * The act is used to run the function in the action for mutable state.
418
- */
419
- actMutable?: <T extends () => any>(fn: T) => ReturnType<T>;
420
- /**
421
- * Get the mutable raw instance via the initial state.
422
- */
423
- toMutableRaw?: (key: any) => any;
424
- /**
425
- * The update immutable function.
426
- */
427
- updateImmutable?: (state: T) => void;
400
+ /**
401
+ * The store module.
402
+ */
403
+ module: T;
404
+ /**
405
+ * The root state.
406
+ */
407
+ rootState: T | Draft<T>;
408
+ /**
409
+ * The backup state.
410
+ */
411
+ backupState: T | Draft<T>;
412
+ /**
413
+ * Finalize the draft.
414
+ */
415
+ finalizeDraft: () => [T, Patches, Patches];
416
+ /**
417
+ * The mutable instance.
418
+ */
419
+ mutableInstance: any;
420
+ /**
421
+ * The sequence number.
422
+ */
423
+ sequence: number;
424
+ /**
425
+ * Whether the batch is running.
426
+ */
427
+ isBatching: boolean;
428
+ /**
429
+ * The listeners.
430
+ */
431
+ listeners: Set<Listener>;
432
+ /**
433
+ * Publish an externally-owned immutable state change to signal slots and
434
+ * store subscribers.
435
+ */
436
+ notifyStateChange: () => void;
437
+ /**
438
+ * Reactive state slots used by computed getters/selectors.
439
+ */
440
+ signalSlots?: Set<SignalSlot>;
441
+ /**
442
+ * The act is used to run the function in the action for mutable state.
443
+ */
444
+ actMutable?: <T extends () => any>(fn: T) => ReturnType<T>;
445
+ /**
446
+ * Get the mutable raw instance via the initial state.
447
+ */
448
+ toMutableRaw?: (key: any) => any;
449
+ /**
450
+ * The update immutable function.
451
+ */
452
+ updateImmutable?: (state: T) => void;
453
+ /**
454
+ * Adapter-level authority check for low-level mutations.
455
+ */
456
+ assertMutationAllowed?: (operation: MutationOperation) => void;
457
+ /**
458
+ * Authorized client-mirror state application used by transports.
459
+ */
460
+ applyClientState?: (state?: T, patches?: Patches) => void;
428
461
  }
462
+ //#endregion
463
+ //#region packages/core/src/binder.d.ts
464
+ type ExternalStoreAdapterOptions<F = (...args: any[]) => any> = {
465
+ /**
466
+ * Normalize a third-party store instance into a raw state object plus the
467
+ * binding hook used during initialization.
468
+ */
469
+ handleState: <T extends object = object>(state: T) => {
470
+ /**
471
+ * Copy of the incoming state object that Coaction should consume.
472
+ */
473
+ copyState: T;
474
+ /**
475
+ * Optional nested key when the adapter exposes a single child object from
476
+ * the third-party store.
477
+ */
478
+ key?: keyof T;
479
+ /**
480
+ * Convert the external state object into the raw state shape used by
481
+ * Coaction.
482
+ */
483
+ bind: (state: T) => T;
484
+ };
485
+ /**
486
+ * Wire Coaction's store lifecycle to the external store implementation.
487
+ */
488
+ handleStore: (
489
+ /**
490
+ * Coaction store wrapper.
491
+ */
492
+
493
+ store: Store<object>,
494
+ /**
495
+ * Raw state object returned from `bind`.
496
+ */
497
+
498
+ rawState: object,
499
+ /**
500
+ * Original external store state object.
501
+ */
502
+
503
+ state: object,
504
+ /**
505
+ * Low-level Coaction adapter hooks used by official bindings.
506
+ */
507
+
508
+ internal: Internal<object>,
509
+ /**
510
+ * Optional nested key returned by `handleState`.
511
+ */
429
512
 
513
+ key?: PropertyKey) => void;
514
+ };
430
515
  /**
431
516
  * Build an adapter helper for bridging an external store implementation into
432
517
  * Coaction.
@@ -436,53 +521,46 @@ interface Internal<T extends CreateState = CreateState> {
436
521
  * Zustand, MobX, and Valtio. Binder-backed integrations are whole-store
437
522
  * adapters; they are not compatible with Coaction slices mode.
438
523
  */
439
- declare function createBinder<F = (...args: any[]) => any>({ handleState, handleStore }: {
440
- /**
441
- * Normalize a third-party store instance into a raw state object plus the
442
- * binding hook used during initialization.
443
- */
444
- handleState: <T extends object = object>(state: T) => {
445
- /**
446
- * Copy of the incoming state object that Coaction should consume.
447
- */
448
- copyState: T;
449
- /**
450
- * Optional nested key when the adapter exposes a single child object from
451
- * the third-party store.
452
- */
453
- key?: keyof T;
454
- /**
455
- * Convert the external state object into the raw state shape used by
456
- * Coaction.
457
- */
458
- bind: (state: T) => T;
459
- };
460
- /**
461
- * Wire Coaction's store lifecycle to the external store implementation.
462
- */
463
- handleStore: (
464
- /**
465
- * Coaction store wrapper.
466
- */
467
- store: Store<object>,
468
- /**
469
- * Raw state object returned from `bind`.
470
- */
471
- rawState: object,
472
- /**
473
- * Original external store state object.
474
- */
475
- state: object,
476
- /**
477
- * Low-level Coaction adapter hooks used by official bindings.
478
- */
479
- internal: Internal<object>,
480
- /**
481
- * Optional nested key returned by `handleState`.
482
- */
483
- key?: string) => void;
484
- }): F;
485
-
524
+ declare function createBinder<F = (...args: any[]) => any>({
525
+ handleState,
526
+ handleStore
527
+ }: ExternalStoreAdapterOptions<F>): F;
528
+ /**
529
+ * Define a whole-store adapter for integrating an external state runtime with
530
+ * Coaction.
531
+ *
532
+ * @remarks
533
+ * This is the stable 2.x name for adapter authors. `createBinder()` remains as
534
+ * a compatibility alias for existing official and community integrations.
535
+ */
536
+ declare function defineExternalStoreAdapter<F = (...args: any[]) => any>(options: ExternalStoreAdapterOptions<F>): F;
537
+ //#endregion
538
+ //#region packages/core/src/lifecycle.d.ts
539
+ declare const onStoreReady: <T extends CreateState>(store: Store<T>, callback: () => void) => () => void;
540
+ //#endregion
541
+ //#region packages/core/src/reactiveTracker.d.ts
542
+ type ReactiveTracker = {
543
+ getSnapshot: () => number;
544
+ subscribe: (listener: () => void) => () => void;
545
+ track: <T>(fn: () => T) => T;
546
+ dispose: () => void;
547
+ };
548
+ declare const createReactiveTracker: () => ReactiveTracker;
549
+ //#endregion
550
+ //#region packages/core/src/replaceExternalStoreState.d.ts
551
+ type ReplaceExternalStoreStateOptions = {
552
+ syncImmutable?: boolean;
553
+ };
554
+ declare const replaceExternalStoreState: <T extends CreateState>(store: MiddlewareStore<T>, internal: Internal<T>, source: Record<PropertyKey, unknown>, {
555
+ syncImmutable
556
+ }?: ReplaceExternalStoreStateOptions) => void;
557
+ //#endregion
558
+ //#region packages/core/src/utils.d.ts
559
+ declare const replaceOwnEnumerable: (target: Record<PropertyKey, unknown>, source: Record<PropertyKey, unknown>) => void;
560
+ declare const sanitizeReplacementState: <T>(source: T, seen?: WeakMap<object, unknown>) => T;
561
+ declare const sanitizeInitialStateValue: <T>(source: T, seen?: WeakMap<object, unknown>) => T;
562
+ //#endregion
563
+ //#region packages/core/src/wrapStore.d.ts
486
564
  /**
487
565
  * Convert a store object into Coaction's callable store shape.
488
566
  *
@@ -493,5 +571,5 @@ declare function createBinder<F = (...args: any[]) => any>({ handleState, handle
493
571
  * directly.
494
572
  */
495
573
  declare const wrapStore: <T extends object>(store: Store<T>, getState?: (...args: unknown[]) => T) => StoreReturn<T>;
496
-
497
- export { type StoreWithAsyncFunction as AsyncStore, type Asyncify, type ClientStoreOptions, type ISlices, type Middleware, type MiddlewareStore, type PatchTransform, type Slice, type SliceState, type Slices, type Store, type StoreOptions, type StoreTraceEvent, create, createBinder, wrapStore };
574
+ //#endregion
575
+ export { type StoreWithAsyncFunction as AsyncStore, type Asyncify, type ClientStoreOptions, type ExternalStoreAdapterOptions, type ISlices, type Middleware, type MiddlewareStore, type PatchTransform, type ReactiveTracker, type Slice, type SliceState, type Slices, type Store, type StoreOptions, type StoreTraceEvent, computed, create, createBinder, createReactiveTracker, defineExternalStoreAdapter, effect, effectScope, endBatch, isComputed, isEffect, isEffectScope, isSignal, onStoreReady, replaceExternalStoreState, replaceOwnEnumerable, sanitizeInitialStateValue, sanitizeReplacementState, signal, startBatch, trigger, wrapStore };