coaction 1.3.0 → 1.4.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/README.md +6 -1
- package/dist/index.d.mts +71 -36
- package/dist/index.d.ts +71 -36
- package/dist/index.js +316 -252
- package/dist/index.mjs +319 -255
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,12 @@ const useStore = create((set) => ({
|
|
|
27
27
|
|
|
28
28
|
### Store Shape Mode (`sliceMode`)
|
|
29
29
|
|
|
30
|
-
`create()` uses `sliceMode: 'auto'` by default.
|
|
30
|
+
`create()` uses `sliceMode: 'auto'` by default. For backward compatibility,
|
|
31
|
+
`auto` still treats a non-empty object whose enumerable values are all
|
|
32
|
+
functions as slices. That shape is ambiguous with a plain store that only
|
|
33
|
+
contains methods, so you should set `sliceMode` explicitly.
|
|
34
|
+
|
|
35
|
+
You can force behavior explicitly:
|
|
31
36
|
|
|
32
37
|
- `sliceMode: 'single'`: treat object input as a single store.
|
|
33
38
|
- `sliceMode: 'slices'`: require object-of-slice-functions input.
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,32 @@ type DeepPartial<T> = {
|
|
|
6
6
|
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
7
7
|
};
|
|
8
8
|
type Listener = () => void;
|
|
9
|
+
interface PatchTransform {
|
|
10
|
+
patches: Patches;
|
|
11
|
+
inversePatches: Patches;
|
|
12
|
+
}
|
|
13
|
+
interface StoreTraceEvent {
|
|
14
|
+
/**
|
|
15
|
+
* The id of the method.
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* The method name.
|
|
20
|
+
*/
|
|
21
|
+
method: string;
|
|
22
|
+
/**
|
|
23
|
+
* The slice key.
|
|
24
|
+
*/
|
|
25
|
+
sliceKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The parameters of the method.
|
|
28
|
+
*/
|
|
29
|
+
parameters?: any[];
|
|
30
|
+
/**
|
|
31
|
+
* The result of the method.
|
|
32
|
+
*/
|
|
33
|
+
result?: any;
|
|
34
|
+
}
|
|
9
35
|
interface Store<T extends ISlices = ISlices> {
|
|
10
36
|
/**
|
|
11
37
|
* The name of the store.
|
|
@@ -60,40 +86,20 @@ interface Store<T extends ISlices = ISlices> {
|
|
|
60
86
|
*/
|
|
61
87
|
getInitialState: () => T;
|
|
62
88
|
/**
|
|
63
|
-
*
|
|
89
|
+
* @deprecated Middleware compatibility hook. Prefer typing middleware stores
|
|
90
|
+
* with `MiddlewareStore`.
|
|
64
91
|
*/
|
|
65
|
-
patch?: (option:
|
|
66
|
-
patches: Patches;
|
|
67
|
-
inversePatches: Patches;
|
|
68
|
-
}) => {
|
|
69
|
-
patches: Patches;
|
|
70
|
-
inversePatches: Patches;
|
|
71
|
-
};
|
|
92
|
+
patch?: (option: PatchTransform) => PatchTransform;
|
|
72
93
|
/**
|
|
73
|
-
*
|
|
94
|
+
* @deprecated Middleware compatibility hook. Prefer typing middleware stores
|
|
95
|
+
* with `MiddlewareStore`.
|
|
74
96
|
*/
|
|
75
|
-
trace?: (options:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* The method name.
|
|
82
|
-
*/
|
|
83
|
-
method: string;
|
|
84
|
-
/**
|
|
85
|
-
* The slice key.
|
|
86
|
-
*/
|
|
87
|
-
sliceKey?: string;
|
|
88
|
-
/**
|
|
89
|
-
* The parameters of the method.
|
|
90
|
-
*/
|
|
91
|
-
parameters?: any[];
|
|
92
|
-
/**
|
|
93
|
-
* The result of the method.
|
|
94
|
-
*/
|
|
95
|
-
result?: any;
|
|
96
|
-
}) => void;
|
|
97
|
+
trace?: (options: StoreTraceEvent) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Semantic alias for middleware-facing stores.
|
|
101
|
+
*/
|
|
102
|
+
interface MiddlewareStore<T extends ISlices = ISlices> extends Store<T> {
|
|
97
103
|
}
|
|
98
104
|
interface Getter<T extends ISlices> {
|
|
99
105
|
<P extends any[], R>(getDeps: (store: T) => readonly [...P] | [...P], selector: (...args: P) => R): R;
|
|
@@ -125,7 +131,7 @@ get: Getter<T>,
|
|
|
125
131
|
* The store is used to store the state.
|
|
126
132
|
*/
|
|
127
133
|
store: Store<T>) => T[K];
|
|
128
|
-
type Middleware<T extends CreateState> = (store:
|
|
134
|
+
type Middleware<T extends CreateState> = (store: MiddlewareStore<T>) => MiddlewareStore<T>;
|
|
129
135
|
type SliceState<T extends Record<string, Slice<any>>> = {
|
|
130
136
|
[K in keyof T]: ReturnType<T[K]>;
|
|
131
137
|
};
|
|
@@ -134,8 +140,15 @@ type StoreOptions<T extends CreateState> = {
|
|
|
134
140
|
* The name of the store.
|
|
135
141
|
*/
|
|
136
142
|
name?: string;
|
|
137
|
-
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated Internal worker-mode override retained for compatibility.
|
|
145
|
+
* Prefer passing `transport` or letting the runtime infer the environment.
|
|
146
|
+
*/
|
|
138
147
|
workerType?: 'SharedWorkerInternal' | 'WebWorkerInternal';
|
|
148
|
+
/**
|
|
149
|
+
* Inject a pre-built transport for advanced shared-store setups.
|
|
150
|
+
*/
|
|
151
|
+
transport?: Transport;
|
|
139
152
|
middlewares?: Middleware<T>[];
|
|
140
153
|
/**
|
|
141
154
|
* enable patches
|
|
@@ -143,7 +156,8 @@ type StoreOptions<T extends CreateState> = {
|
|
|
143
156
|
enablePatches?: boolean;
|
|
144
157
|
/**
|
|
145
158
|
* control how createState should be interpreted.
|
|
146
|
-
* - auto: infer from createState shape.
|
|
159
|
+
* - auto: infer from createState shape. Object maps whose values are all
|
|
160
|
+
* functions are ambiguous, so prefer setting `sliceMode` explicitly.
|
|
147
161
|
* - slices: force slices mode.
|
|
148
162
|
* - single: force single-store mode.
|
|
149
163
|
*/
|
|
@@ -157,15 +171,36 @@ type ClientStoreOptions<T extends CreateState> = {
|
|
|
157
171
|
middlewares?: Middleware<T>[];
|
|
158
172
|
/**
|
|
159
173
|
* control how createState should be interpreted.
|
|
160
|
-
* - auto: infer from createState shape.
|
|
174
|
+
* - auto: infer from createState shape. Object maps whose values are all
|
|
175
|
+
* functions are ambiguous, so prefer setting `sliceMode` explicitly.
|
|
161
176
|
* - slices: force slices mode.
|
|
162
177
|
* - single: force single-store mode.
|
|
163
178
|
*/
|
|
164
179
|
sliceMode?: 'auto' | 'slices' | 'single';
|
|
165
180
|
} & ClientTransportOptions;
|
|
166
181
|
interface ClientTransportOptions {
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated Internal worker-mode override retained for compatibility.
|
|
184
|
+
* Prefer passing `clientTransport` or `worker`.
|
|
185
|
+
*/
|
|
167
186
|
workerType?: 'WebWorkerClient' | 'SharedWorkerClient';
|
|
187
|
+
/**
|
|
188
|
+
* How long the client should wait for sequence catch-up before falling back
|
|
189
|
+
* to `fullSync`.
|
|
190
|
+
*
|
|
191
|
+
* Increase this when worker-side execution can complete before the matching
|
|
192
|
+
* incremental `update` message arrives under heavy load.
|
|
193
|
+
*
|
|
194
|
+
* @default 1500
|
|
195
|
+
*/
|
|
196
|
+
executeSyncTimeoutMs?: number;
|
|
197
|
+
/**
|
|
198
|
+
* Inject a pre-built client transport.
|
|
199
|
+
*/
|
|
168
200
|
clientTransport?: Transport<any>;
|
|
201
|
+
/**
|
|
202
|
+
* Build a client transport from a Worker or SharedWorker instance.
|
|
203
|
+
*/
|
|
169
204
|
worker?: SharedWorker | Worker;
|
|
170
205
|
}
|
|
171
206
|
type Asyncify<T extends object, D extends true | false> = {
|
|
@@ -287,4 +322,4 @@ declare function createBinder<F = (...args: any[]) => any>({ handleState, handle
|
|
|
287
322
|
*/
|
|
288
323
|
declare const wrapStore: <T extends object>(store: Store<T>, getState?: (...args: unknown[]) => T) => StoreReturn<T>;
|
|
289
324
|
|
|
290
|
-
export { type StoreWithAsyncFunction as AsyncStore, type Asyncify, type ClientStoreOptions, type ISlices, type Middleware, type Slice, type SliceState, type Slices, type Store, type StoreOptions, create, createBinder, wrapStore };
|
|
325
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,32 @@ type DeepPartial<T> = {
|
|
|
6
6
|
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
7
7
|
};
|
|
8
8
|
type Listener = () => void;
|
|
9
|
+
interface PatchTransform {
|
|
10
|
+
patches: Patches;
|
|
11
|
+
inversePatches: Patches;
|
|
12
|
+
}
|
|
13
|
+
interface StoreTraceEvent {
|
|
14
|
+
/**
|
|
15
|
+
* The id of the method.
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* The method name.
|
|
20
|
+
*/
|
|
21
|
+
method: string;
|
|
22
|
+
/**
|
|
23
|
+
* The slice key.
|
|
24
|
+
*/
|
|
25
|
+
sliceKey?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The parameters of the method.
|
|
28
|
+
*/
|
|
29
|
+
parameters?: any[];
|
|
30
|
+
/**
|
|
31
|
+
* The result of the method.
|
|
32
|
+
*/
|
|
33
|
+
result?: any;
|
|
34
|
+
}
|
|
9
35
|
interface Store<T extends ISlices = ISlices> {
|
|
10
36
|
/**
|
|
11
37
|
* The name of the store.
|
|
@@ -60,40 +86,20 @@ interface Store<T extends ISlices = ISlices> {
|
|
|
60
86
|
*/
|
|
61
87
|
getInitialState: () => T;
|
|
62
88
|
/**
|
|
63
|
-
*
|
|
89
|
+
* @deprecated Middleware compatibility hook. Prefer typing middleware stores
|
|
90
|
+
* with `MiddlewareStore`.
|
|
64
91
|
*/
|
|
65
|
-
patch?: (option:
|
|
66
|
-
patches: Patches;
|
|
67
|
-
inversePatches: Patches;
|
|
68
|
-
}) => {
|
|
69
|
-
patches: Patches;
|
|
70
|
-
inversePatches: Patches;
|
|
71
|
-
};
|
|
92
|
+
patch?: (option: PatchTransform) => PatchTransform;
|
|
72
93
|
/**
|
|
73
|
-
*
|
|
94
|
+
* @deprecated Middleware compatibility hook. Prefer typing middleware stores
|
|
95
|
+
* with `MiddlewareStore`.
|
|
74
96
|
*/
|
|
75
|
-
trace?: (options:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* The method name.
|
|
82
|
-
*/
|
|
83
|
-
method: string;
|
|
84
|
-
/**
|
|
85
|
-
* The slice key.
|
|
86
|
-
*/
|
|
87
|
-
sliceKey?: string;
|
|
88
|
-
/**
|
|
89
|
-
* The parameters of the method.
|
|
90
|
-
*/
|
|
91
|
-
parameters?: any[];
|
|
92
|
-
/**
|
|
93
|
-
* The result of the method.
|
|
94
|
-
*/
|
|
95
|
-
result?: any;
|
|
96
|
-
}) => void;
|
|
97
|
+
trace?: (options: StoreTraceEvent) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Semantic alias for middleware-facing stores.
|
|
101
|
+
*/
|
|
102
|
+
interface MiddlewareStore<T extends ISlices = ISlices> extends Store<T> {
|
|
97
103
|
}
|
|
98
104
|
interface Getter<T extends ISlices> {
|
|
99
105
|
<P extends any[], R>(getDeps: (store: T) => readonly [...P] | [...P], selector: (...args: P) => R): R;
|
|
@@ -125,7 +131,7 @@ get: Getter<T>,
|
|
|
125
131
|
* The store is used to store the state.
|
|
126
132
|
*/
|
|
127
133
|
store: Store<T>) => T[K];
|
|
128
|
-
type Middleware<T extends CreateState> = (store:
|
|
134
|
+
type Middleware<T extends CreateState> = (store: MiddlewareStore<T>) => MiddlewareStore<T>;
|
|
129
135
|
type SliceState<T extends Record<string, Slice<any>>> = {
|
|
130
136
|
[K in keyof T]: ReturnType<T[K]>;
|
|
131
137
|
};
|
|
@@ -134,8 +140,15 @@ type StoreOptions<T extends CreateState> = {
|
|
|
134
140
|
* The name of the store.
|
|
135
141
|
*/
|
|
136
142
|
name?: string;
|
|
137
|
-
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated Internal worker-mode override retained for compatibility.
|
|
145
|
+
* Prefer passing `transport` or letting the runtime infer the environment.
|
|
146
|
+
*/
|
|
138
147
|
workerType?: 'SharedWorkerInternal' | 'WebWorkerInternal';
|
|
148
|
+
/**
|
|
149
|
+
* Inject a pre-built transport for advanced shared-store setups.
|
|
150
|
+
*/
|
|
151
|
+
transport?: Transport;
|
|
139
152
|
middlewares?: Middleware<T>[];
|
|
140
153
|
/**
|
|
141
154
|
* enable patches
|
|
@@ -143,7 +156,8 @@ type StoreOptions<T extends CreateState> = {
|
|
|
143
156
|
enablePatches?: boolean;
|
|
144
157
|
/**
|
|
145
158
|
* control how createState should be interpreted.
|
|
146
|
-
* - auto: infer from createState shape.
|
|
159
|
+
* - auto: infer from createState shape. Object maps whose values are all
|
|
160
|
+
* functions are ambiguous, so prefer setting `sliceMode` explicitly.
|
|
147
161
|
* - slices: force slices mode.
|
|
148
162
|
* - single: force single-store mode.
|
|
149
163
|
*/
|
|
@@ -157,15 +171,36 @@ type ClientStoreOptions<T extends CreateState> = {
|
|
|
157
171
|
middlewares?: Middleware<T>[];
|
|
158
172
|
/**
|
|
159
173
|
* control how createState should be interpreted.
|
|
160
|
-
* - auto: infer from createState shape.
|
|
174
|
+
* - auto: infer from createState shape. Object maps whose values are all
|
|
175
|
+
* functions are ambiguous, so prefer setting `sliceMode` explicitly.
|
|
161
176
|
* - slices: force slices mode.
|
|
162
177
|
* - single: force single-store mode.
|
|
163
178
|
*/
|
|
164
179
|
sliceMode?: 'auto' | 'slices' | 'single';
|
|
165
180
|
} & ClientTransportOptions;
|
|
166
181
|
interface ClientTransportOptions {
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated Internal worker-mode override retained for compatibility.
|
|
184
|
+
* Prefer passing `clientTransport` or `worker`.
|
|
185
|
+
*/
|
|
167
186
|
workerType?: 'WebWorkerClient' | 'SharedWorkerClient';
|
|
187
|
+
/**
|
|
188
|
+
* How long the client should wait for sequence catch-up before falling back
|
|
189
|
+
* to `fullSync`.
|
|
190
|
+
*
|
|
191
|
+
* Increase this when worker-side execution can complete before the matching
|
|
192
|
+
* incremental `update` message arrives under heavy load.
|
|
193
|
+
*
|
|
194
|
+
* @default 1500
|
|
195
|
+
*/
|
|
196
|
+
executeSyncTimeoutMs?: number;
|
|
197
|
+
/**
|
|
198
|
+
* Inject a pre-built client transport.
|
|
199
|
+
*/
|
|
168
200
|
clientTransport?: Transport<any>;
|
|
201
|
+
/**
|
|
202
|
+
* Build a client transport from a Worker or SharedWorker instance.
|
|
203
|
+
*/
|
|
169
204
|
worker?: SharedWorker | Worker;
|
|
170
205
|
}
|
|
171
206
|
type Asyncify<T extends object, D extends true | false> = {
|
|
@@ -287,4 +322,4 @@ declare function createBinder<F = (...args: any[]) => any>({ handleState, handle
|
|
|
287
322
|
*/
|
|
288
323
|
declare const wrapStore: <T extends object>(store: Store<T>, getState?: (...args: unknown[]) => T) => StoreReturn<T>;
|
|
289
324
|
|
|
290
|
-
export { type StoreWithAsyncFunction as AsyncStore, type Asyncify, type ClientStoreOptions, type ISlices, type Middleware, type Slice, type SliceState, type Slices, type Store, type StoreOptions, create, createBinder, wrapStore };
|
|
325
|
+
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 };
|