tsdf 11.2.0 → 12.2.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/main.cjs +239 -92
- package/dist/main.d.cts +332 -0
- package/dist/main.d.ts +33 -9
- package/dist/main.js +239 -92
- package/package.json +36 -36
package/dist/main.d.cts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Store } from 't-state';
|
|
2
|
+
|
|
3
|
+
type FetchType = 'lowPriority' | 'highPriority' | 'realtimeUpdate';
|
|
4
|
+
type ScheduleFetchResults = 'skipped' | 'started' | 'scheduled' | 'rt-scheduled';
|
|
5
|
+
|
|
6
|
+
type TSDFStatus = 'loading' | 'error' | 'refetching' | 'success';
|
|
7
|
+
type ValidPayload = number | string | Record<string, unknown>;
|
|
8
|
+
type ValidStoreState = Record<string, unknown> | any[];
|
|
9
|
+
|
|
10
|
+
type DocumentStatus = TSDFStatus | 'idle';
|
|
11
|
+
type TSDFDocumentStoreState<State extends ValidStoreState, NError> = {
|
|
12
|
+
data: State | null;
|
|
13
|
+
error: NError | null;
|
|
14
|
+
status: DocumentStatus;
|
|
15
|
+
refetchOnMount: false | FetchType;
|
|
16
|
+
};
|
|
17
|
+
type TSDFUseDocumentReturn<Selected, NError> = {
|
|
18
|
+
status: DocumentStatus;
|
|
19
|
+
data: Selected;
|
|
20
|
+
error: NError | null;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
};
|
|
23
|
+
declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ debugName, fetchFn, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, disableInitialDataInvalidation, errorNormalizer, onInvalidate, }: {
|
|
24
|
+
debugName?: string;
|
|
25
|
+
fetchFn: () => Promise<State>;
|
|
26
|
+
getInitialData?: () => State | undefined;
|
|
27
|
+
disableInitialDataInvalidation?: boolean;
|
|
28
|
+
errorNormalizer: (exception: unknown) => NError;
|
|
29
|
+
disableRefetchOnMount?: boolean;
|
|
30
|
+
lowPriorityThrottleMs?: number;
|
|
31
|
+
mediumPriorityThrottleMs?: number;
|
|
32
|
+
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
33
|
+
onInvalidate?: (priority: FetchType) => void;
|
|
34
|
+
}): {
|
|
35
|
+
store: Store<TSDFDocumentStoreState<State, NError>>;
|
|
36
|
+
reset: () => void;
|
|
37
|
+
awaitFetch: () => Promise<{
|
|
38
|
+
data: State;
|
|
39
|
+
error: null;
|
|
40
|
+
} | {
|
|
41
|
+
data: null;
|
|
42
|
+
error: NError;
|
|
43
|
+
}>;
|
|
44
|
+
scheduleFetch: (fetchType: FetchType) => ScheduleFetchResults;
|
|
45
|
+
invalidateData: (priority?: FetchType) => void;
|
|
46
|
+
useDocument: <Selected = State | null>({ selector, disabled, returnRefetchingStatus, disableRefetchOnMount, returnIdleStatus, ensureIsLoaded, }?: {
|
|
47
|
+
selector?: ((data: State | null) => Selected) | undefined;
|
|
48
|
+
disabled?: boolean | undefined;
|
|
49
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
50
|
+
returnIdleStatus?: boolean | undefined;
|
|
51
|
+
ensureIsLoaded?: boolean | undefined;
|
|
52
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
53
|
+
}) => Readonly<TSDFUseDocumentReturn<Selected, NError>>;
|
|
54
|
+
updateState: (produceNewData: (draftData: State) => State | void | undefined) => boolean;
|
|
55
|
+
startMutation: () => () => boolean;
|
|
56
|
+
};
|
|
57
|
+
type TSDFDocumentStore<State extends ValidStoreState, NError> = ReturnType<typeof newTSDFDocumentStore<State, NError>>;
|
|
58
|
+
|
|
59
|
+
type CollectionItemStatus = TSDFStatus;
|
|
60
|
+
type TSFDCollectionItem<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, NError> = {
|
|
61
|
+
data: ItemState | null;
|
|
62
|
+
error: NError | null;
|
|
63
|
+
status: CollectionItemStatus;
|
|
64
|
+
payload: ItemPayload;
|
|
65
|
+
refetchOnMount: false | FetchType;
|
|
66
|
+
wasLoaded: boolean;
|
|
67
|
+
};
|
|
68
|
+
type TSFDCollectionState<ItemState extends ValidStoreState, ItemPayload extends ValidPayload, NError> = Record<string, TSFDCollectionItem<ItemState, ItemPayload, NError> | null>;
|
|
69
|
+
type TSFDUseCollectionItemReturn<Selected, ItemPayload, NError> = {
|
|
70
|
+
data: Selected;
|
|
71
|
+
status: CollectionItemStatus | 'idle' | 'deleted';
|
|
72
|
+
payload: ItemPayload | undefined;
|
|
73
|
+
error: NError | null;
|
|
74
|
+
itemStateKey: string;
|
|
75
|
+
isLoading: boolean;
|
|
76
|
+
};
|
|
77
|
+
type CollectionInitialStateItem<ItemPayload extends ValidPayload, ItemState extends ValidStoreState> = {
|
|
78
|
+
payload: ItemPayload;
|
|
79
|
+
data: ItemState;
|
|
80
|
+
};
|
|
81
|
+
declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NError, ItemPayload extends ValidPayload>({ debugName, fetchFn, lowPriorityThrottleMs, errorNormalizer, disableInitialDataInvalidation, mediumPriorityThrottleMs, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, dynamicRealtimeThrottleMs, getCollectionItemKey: filterCollectionItemObjKey, onInvalidate, }: {
|
|
82
|
+
debugName?: string;
|
|
83
|
+
fetchFn: (params: ItemPayload) => Promise<ItemState>;
|
|
84
|
+
getCollectionItemKey?: (params: ItemPayload) => ValidPayload | any[];
|
|
85
|
+
errorNormalizer: (exception: unknown) => NError;
|
|
86
|
+
disableRefetchOnMount?: boolean;
|
|
87
|
+
getInitialData?: () => CollectionInitialStateItem<ItemPayload, ItemState>[] | undefined;
|
|
88
|
+
disableInitialDataInvalidation?: boolean;
|
|
89
|
+
lowPriorityThrottleMs?: number;
|
|
90
|
+
mediumPriorityThrottleMs?: number;
|
|
91
|
+
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
92
|
+
onInvalidate?: (props: {
|
|
93
|
+
itemState: ItemState;
|
|
94
|
+
payload: ItemPayload;
|
|
95
|
+
priority: FetchType;
|
|
96
|
+
}) => void;
|
|
97
|
+
}): {
|
|
98
|
+
store: Store<TSFDCollectionState<ItemState, ItemPayload, NError>>;
|
|
99
|
+
scheduleFetch: {
|
|
100
|
+
(fetchType: FetchType, payload: ItemPayload): ScheduleFetchResults;
|
|
101
|
+
(fetchType: FetchType, payload: ItemPayload[]): ScheduleFetchResults[];
|
|
102
|
+
};
|
|
103
|
+
awaitFetch: (params: ItemPayload) => Promise<{
|
|
104
|
+
data: null;
|
|
105
|
+
error: NError;
|
|
106
|
+
} | {
|
|
107
|
+
data: ItemState;
|
|
108
|
+
error: null;
|
|
109
|
+
}>;
|
|
110
|
+
useMultipleItems: <Selected = ItemState | null>(queries: readonly ItemPayload[], { selector, omitPayload, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, }?: {
|
|
111
|
+
selector?: ((data: ItemState | null) => Selected) | undefined;
|
|
112
|
+
omitPayload?: boolean | undefined;
|
|
113
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
114
|
+
returnIdleStatus?: boolean | undefined;
|
|
115
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
116
|
+
}) => readonly TSFDUseCollectionItemReturn<Selected, ItemPayload, NError>[];
|
|
117
|
+
useItem: <Selected_1 = ItemState | null>(payload: ItemPayload | undefined | false | null, options?: {
|
|
118
|
+
selector?: ((data: ItemState | null) => Selected_1) | undefined;
|
|
119
|
+
omitPayload?: boolean | undefined;
|
|
120
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
121
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
122
|
+
ensureIsLoaded?: boolean | undefined;
|
|
123
|
+
returnIdleStatus?: boolean | undefined;
|
|
124
|
+
}) => TSFDUseCollectionItemReturn<Selected_1, ItemPayload, NError>;
|
|
125
|
+
reset: () => void;
|
|
126
|
+
getItemKey: (params: ItemPayload) => string;
|
|
127
|
+
getItemState: {
|
|
128
|
+
(fetchParam: ItemPayload): TSFDCollectionItem<ItemState, ItemPayload, NError> | null | undefined;
|
|
129
|
+
(fetchParams: ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)): TSFDCollectionItem<ItemState, ItemPayload, NError>[];
|
|
130
|
+
};
|
|
131
|
+
startMutation: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)) => () => void;
|
|
132
|
+
invalidateItem: (itemPayload: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean), priority?: FetchType) => void;
|
|
133
|
+
updateItemState: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean), produceNewData: (draftData: ItemState, collectionItem: TSFDCollectionItem<ItemState, ItemPayload, NError>) => void | ItemState, ifNothingWasUpdated?: () => void) => boolean;
|
|
134
|
+
addItemToState: (fetchParams: ItemPayload, data: ItemState) => void;
|
|
135
|
+
deleteItemState: (fetchParams: ItemPayload | ItemPayload[] | ((params: ItemPayload, data: ItemState | null) => boolean)) => void;
|
|
136
|
+
};
|
|
137
|
+
type TSDFCollectionStore<ItemState extends ValidStoreState, NError, FetchParams extends ValidPayload> = ReturnType<typeof newTSDFCollectionStore<ItemState, NError, FetchParams>>;
|
|
138
|
+
|
|
139
|
+
type QueryStatus = TSDFStatus | 'loadingMore';
|
|
140
|
+
type TSFDListQuery<NError, QueryPayload extends ValidPayload> = {
|
|
141
|
+
error: NError | null;
|
|
142
|
+
status: QueryStatus;
|
|
143
|
+
payload: QueryPayload;
|
|
144
|
+
hasMore: boolean;
|
|
145
|
+
wasLoaded: boolean;
|
|
146
|
+
refetchOnMount: false | FetchType;
|
|
147
|
+
items: string[];
|
|
148
|
+
};
|
|
149
|
+
type TSDFItemQuery<NError, ItemPayload> = {
|
|
150
|
+
error: NError | null;
|
|
151
|
+
status: Exclude<QueryStatus, 'loadingMore'>;
|
|
152
|
+
wasLoaded: boolean;
|
|
153
|
+
refetchOnMount: false | FetchType;
|
|
154
|
+
payload: ItemPayload;
|
|
155
|
+
};
|
|
156
|
+
type TSFDListQueryState<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
157
|
+
items: Record<string, ItemState | null>;
|
|
158
|
+
queries: Record<string, TSFDListQuery<NError, QueryPayload>>;
|
|
159
|
+
itemQueries: Record<string, TSDFItemQuery<NError, ItemPayload> | null>;
|
|
160
|
+
};
|
|
161
|
+
type TSFDUseListQueryReturn<Selected, ItemPayload, NError> = {
|
|
162
|
+
items: Selected[];
|
|
163
|
+
status: QueryStatus | 'idle';
|
|
164
|
+
payload: ItemPayload | undefined;
|
|
165
|
+
error: NError | null;
|
|
166
|
+
queryKey: string;
|
|
167
|
+
hasMore: boolean;
|
|
168
|
+
isLoading: boolean;
|
|
169
|
+
isLoadingMore: boolean;
|
|
170
|
+
};
|
|
171
|
+
type TSFDUseListItemReturn<Selected, NError, ItemPayload> = {
|
|
172
|
+
data: Selected;
|
|
173
|
+
status: QueryStatus | 'idle' | 'deleted';
|
|
174
|
+
payload: ItemPayload | null;
|
|
175
|
+
error: NError | null;
|
|
176
|
+
isLoading: boolean;
|
|
177
|
+
};
|
|
178
|
+
type FetchListFnReturnItem<ItemPayload extends ValidPayload, ItemState extends ValidStoreState> = {
|
|
179
|
+
itemPayload: ItemPayload;
|
|
180
|
+
data: ItemState;
|
|
181
|
+
};
|
|
182
|
+
type FetchListFnReturn<ItemState extends ValidStoreState, ItemPayload extends ValidPayload> = {
|
|
183
|
+
items: FetchListFnReturnItem<ItemPayload, ItemState>[];
|
|
184
|
+
hasMore: boolean;
|
|
185
|
+
};
|
|
186
|
+
type ListQueryStoreInitialData<ItemState extends ValidStoreState, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = {
|
|
187
|
+
items: {
|
|
188
|
+
payload: ItemPayload;
|
|
189
|
+
data: ItemState;
|
|
190
|
+
}[];
|
|
191
|
+
queries: {
|
|
192
|
+
payload: QueryPayload;
|
|
193
|
+
items: string[];
|
|
194
|
+
hasMore: boolean;
|
|
195
|
+
}[];
|
|
196
|
+
};
|
|
197
|
+
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, syncMutationsAndInvalidations, optimisticListUpdates, onInvalidateItem, onInvalidateQuery, }: {
|
|
198
|
+
debugName?: string;
|
|
199
|
+
fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
200
|
+
fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
|
|
201
|
+
errorNormalizer: (exception: unknown) => NError;
|
|
202
|
+
defaultQuerySize?: number;
|
|
203
|
+
getInitialData?: () => ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload> | undefined;
|
|
204
|
+
disableInitialDataInvalidation?: boolean;
|
|
205
|
+
syncMutationsAndInvalidations?: {
|
|
206
|
+
syncQueries: (query1: QueryPayload, query2: QueryPayload) => boolean;
|
|
207
|
+
syncItemAndQuery: (itemPayload: ItemPayload, query: QueryPayload) => boolean;
|
|
208
|
+
};
|
|
209
|
+
disableRefetchOnMount?: boolean;
|
|
210
|
+
lowPriorityThrottleMs?: number;
|
|
211
|
+
mediumPriorityThrottleMs?: number;
|
|
212
|
+
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
213
|
+
optimisticListUpdates?: {
|
|
214
|
+
queries: QueryPayload | ((query: QueryPayload) => boolean) | QueryPayload[];
|
|
215
|
+
filterItem?: (item: ItemState) => boolean | null;
|
|
216
|
+
/** @default 'end' */
|
|
217
|
+
appendNewTo?: 'start' | 'end';
|
|
218
|
+
invalidateQueries?: boolean;
|
|
219
|
+
sort?: {
|
|
220
|
+
sortBy: (item: ItemState, itemPayload: ItemPayload) => string | number | (string | number)[];
|
|
221
|
+
/** @default 'asc' */
|
|
222
|
+
order?: 'asc' | 'desc' | ('asc' | 'desc')[];
|
|
223
|
+
};
|
|
224
|
+
}[];
|
|
225
|
+
onInvalidateQuery?: (query: QueryPayload, priority: FetchType) => void;
|
|
226
|
+
onInvalidateItem?: (props: {
|
|
227
|
+
itemState: ItemState;
|
|
228
|
+
payload: ItemPayload;
|
|
229
|
+
priority: FetchType;
|
|
230
|
+
}) => void;
|
|
231
|
+
}): {
|
|
232
|
+
store: Store<TSFDListQueryState<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
233
|
+
reset: () => void;
|
|
234
|
+
scheduleListQueryFetch: {
|
|
235
|
+
(fetchType: FetchType, payload: QueryPayload, size?: number): ScheduleFetchResults;
|
|
236
|
+
(fetchType: FetchType, payload: QueryPayload[], size?: number): ScheduleFetchResults[];
|
|
237
|
+
};
|
|
238
|
+
getQueryState: (params: QueryPayload) => TSFDListQuery<NError, QueryPayload> | undefined;
|
|
239
|
+
getQueryKey: (params: QueryPayload) => string;
|
|
240
|
+
deleteItemState: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => void;
|
|
241
|
+
getItemState: {
|
|
242
|
+
(itemPayload: ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]): {
|
|
243
|
+
payload: ItemPayload;
|
|
244
|
+
data: ItemState;
|
|
245
|
+
}[];
|
|
246
|
+
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
247
|
+
};
|
|
248
|
+
loadMore: (params: QueryPayload, size?: number) => ScheduleFetchResults;
|
|
249
|
+
invalidateQuery: (queryPayload: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean), priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
250
|
+
invalidateItem: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
251
|
+
scheduleItemFetch: {
|
|
252
|
+
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
253
|
+
(fetchType: FetchType, itemPayload: ItemPayload[]): ScheduleFetchResults[];
|
|
254
|
+
};
|
|
255
|
+
awaitItemFetch: (itemPayload: ItemPayload) => Promise<{
|
|
256
|
+
data: null;
|
|
257
|
+
error: NError;
|
|
258
|
+
} | {
|
|
259
|
+
data: ItemState;
|
|
260
|
+
error: null;
|
|
261
|
+
}>;
|
|
262
|
+
awaitListQueryFetch: (params: QueryPayload, size?: number) => Promise<{
|
|
263
|
+
items: [
|
|
264
|
+
];
|
|
265
|
+
error: NError;
|
|
266
|
+
hasMore: boolean;
|
|
267
|
+
} | {
|
|
268
|
+
items: {
|
|
269
|
+
data: ItemState;
|
|
270
|
+
itemPayload: ItemPayload;
|
|
271
|
+
}[];
|
|
272
|
+
error: null;
|
|
273
|
+
hasMore: boolean;
|
|
274
|
+
}>;
|
|
275
|
+
useMultipleListQueries: <SelectedItem = ItemState>(queries: readonly QueryPayload[], { itemSelector, omitPayload, returnIdleStatus, returnRefetchingStatus, loadSize, disableRefetchOnMount, }?: {
|
|
276
|
+
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem) | undefined;
|
|
277
|
+
omitPayload?: boolean | undefined;
|
|
278
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
279
|
+
returnIdleStatus?: boolean | undefined;
|
|
280
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
281
|
+
loadSize?: number | undefined;
|
|
282
|
+
}) => readonly TSFDUseListQueryReturn<SelectedItem, QueryPayload, NError>[];
|
|
283
|
+
useListQuery: <SelectedItem_1 = ItemState>(payload: QueryPayload | false | null | undefined, options?: {
|
|
284
|
+
itemSelector?: ((data: ItemState, id: ItemPayload, itemKey: string) => SelectedItem_1) | undefined;
|
|
285
|
+
omitPayload?: boolean | undefined;
|
|
286
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
287
|
+
returnIdleStatus?: boolean | undefined;
|
|
288
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
289
|
+
ensureIsLoaded?: boolean | undefined;
|
|
290
|
+
loadSize?: number | undefined;
|
|
291
|
+
}) => TSFDUseListQueryReturn<SelectedItem_1, QueryPayload, NError>;
|
|
292
|
+
getItemKey: (params: ItemPayload) => string;
|
|
293
|
+
useItem: <SelectedItem_2 = ItemState | null>(itemPayload: ItemPayload | false | null | undefined, options?: {
|
|
294
|
+
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_2) | undefined;
|
|
295
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
296
|
+
returnIdleStatus?: boolean | undefined;
|
|
297
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
298
|
+
ensureIsLoaded?: boolean | undefined;
|
|
299
|
+
loadFromStateOnly?: boolean | undefined;
|
|
300
|
+
}) => TSFDUseListItemReturn<SelectedItem_2, NError, ItemPayload>;
|
|
301
|
+
useMultipleItems: <SelectedItem_3 = ItemState | null>(itemsPayload_: ItemPayload[], { selector, returnIdleStatus, returnRefetchingStatus, disableRefetchOnMount, loadFromStateOnly, }?: {
|
|
302
|
+
selector?: ((data: ItemState | null, id: ItemPayload | null) => SelectedItem_3) | undefined;
|
|
303
|
+
disableRefetchOnMount?: boolean | undefined;
|
|
304
|
+
returnIdleStatus?: boolean | undefined;
|
|
305
|
+
returnRefetchingStatus?: boolean | undefined;
|
|
306
|
+
loadFromStateOnly?: boolean | undefined;
|
|
307
|
+
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
|
|
308
|
+
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
309
|
+
addItemToQueries?: {
|
|
310
|
+
queries: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
311
|
+
appendTo: "start" | "end" | ((itemsPayload: ItemPayload[]) => number);
|
|
312
|
+
} | undefined;
|
|
313
|
+
}) => void;
|
|
314
|
+
updateItemState: (itemIds: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], produceNewData: (draftData: ItemState, itemPayload: ItemPayload) => void | ItemState, { ifNothingWasUpdated, }?: {
|
|
315
|
+
ifNothingWasUpdated?: (() => void) | undefined;
|
|
316
|
+
}) => boolean;
|
|
317
|
+
startItemMutation: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => () => void;
|
|
318
|
+
getQueriesState: (params: QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)) => {
|
|
319
|
+
query: TSFDListQuery<NError, QueryPayload>;
|
|
320
|
+
key: string;
|
|
321
|
+
}[];
|
|
322
|
+
getQueriesRelatedToItem: (itemPayload: ItemPayload) => {
|
|
323
|
+
query: TSFDListQuery<NError, QueryPayload>;
|
|
324
|
+
key: string;
|
|
325
|
+
}[];
|
|
326
|
+
useFindItem: <SelectedItem_4 = ItemState | null>(findItem: (item: ItemState, itemPayload: ItemPayload) => boolean, { selector, }?: {
|
|
327
|
+
selector?: ((data: ItemState, id: ItemPayload) => SelectedItem_4) | undefined;
|
|
328
|
+
}) => Readonly<SelectedItem_4 | null>;
|
|
329
|
+
};
|
|
330
|
+
type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ReturnType<typeof newTSDFListQueryStore<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
331
|
+
|
|
332
|
+
export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore };
|
package/dist/main.d.ts
CHANGED
|
@@ -20,16 +20,17 @@ type TSDFUseDocumentReturn<Selected, NError> = {
|
|
|
20
20
|
error: NError | null;
|
|
21
21
|
isLoading: boolean;
|
|
22
22
|
};
|
|
23
|
-
declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ debugName, fetchFn,
|
|
23
|
+
declare function newTSDFDocumentStore<State extends ValidStoreState, NError>({ debugName, fetchFn, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, disableInitialDataInvalidation, errorNormalizer, onInvalidate, }: {
|
|
24
24
|
debugName?: string;
|
|
25
25
|
fetchFn: () => Promise<State>;
|
|
26
|
-
|
|
26
|
+
getInitialData?: () => State | undefined;
|
|
27
27
|
disableInitialDataInvalidation?: boolean;
|
|
28
28
|
errorNormalizer: (exception: unknown) => NError;
|
|
29
29
|
disableRefetchOnMount?: boolean;
|
|
30
30
|
lowPriorityThrottleMs?: number;
|
|
31
31
|
mediumPriorityThrottleMs?: number;
|
|
32
32
|
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
33
|
+
onInvalidate?: (priority: FetchType) => void;
|
|
33
34
|
}): {
|
|
34
35
|
store: Store<TSDFDocumentStoreState<State, NError>>;
|
|
35
36
|
reset: () => void;
|
|
@@ -77,17 +78,22 @@ type CollectionInitialStateItem<ItemPayload extends ValidPayload, ItemState exte
|
|
|
77
78
|
payload: ItemPayload;
|
|
78
79
|
data: ItemState;
|
|
79
80
|
};
|
|
80
|
-
declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NError, ItemPayload extends ValidPayload>({ debugName, fetchFn, lowPriorityThrottleMs, errorNormalizer, disableInitialDataInvalidation, mediumPriorityThrottleMs,
|
|
81
|
+
declare function newTSDFCollectionStore<ItemState extends ValidStoreState, NError, ItemPayload extends ValidPayload>({ debugName, fetchFn, lowPriorityThrottleMs, errorNormalizer, disableInitialDataInvalidation, mediumPriorityThrottleMs, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, dynamicRealtimeThrottleMs, getCollectionItemKey: filterCollectionItemObjKey, onInvalidate, }: {
|
|
81
82
|
debugName?: string;
|
|
82
83
|
fetchFn: (params: ItemPayload) => Promise<ItemState>;
|
|
83
84
|
getCollectionItemKey?: (params: ItemPayload) => ValidPayload | any[];
|
|
84
85
|
errorNormalizer: (exception: unknown) => NError;
|
|
85
86
|
disableRefetchOnMount?: boolean;
|
|
86
|
-
|
|
87
|
+
getInitialData?: () => CollectionInitialStateItem<ItemPayload, ItemState>[] | undefined;
|
|
87
88
|
disableInitialDataInvalidation?: boolean;
|
|
88
89
|
lowPriorityThrottleMs?: number;
|
|
89
90
|
mediumPriorityThrottleMs?: number;
|
|
90
91
|
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
92
|
+
onInvalidate?: (props: {
|
|
93
|
+
itemState: ItemState;
|
|
94
|
+
payload: ItemPayload;
|
|
95
|
+
priority: FetchType;
|
|
96
|
+
}) => void;
|
|
91
97
|
}): {
|
|
92
98
|
store: Store<TSFDCollectionState<ItemState, ItemPayload, NError>>;
|
|
93
99
|
scheduleFetch: {
|
|
@@ -188,13 +194,13 @@ type ListQueryStoreInitialData<ItemState extends ValidStoreState, QueryPayload e
|
|
|
188
194
|
hasMore: boolean;
|
|
189
195
|
}[];
|
|
190
196
|
};
|
|
191
|
-
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize,
|
|
197
|
+
declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload>({ debugName, fetchListFn, fetchItemFn, errorNormalizer, defaultQuerySize, getInitialData, disableRefetchOnMount: globalDisableRefetchOnMount, lowPriorityThrottleMs, disableInitialDataInvalidation, mediumPriorityThrottleMs, dynamicRealtimeThrottleMs, syncMutationsAndInvalidations, optimisticListUpdates, onInvalidateItem, onInvalidateQuery, }: {
|
|
192
198
|
debugName?: string;
|
|
193
199
|
fetchListFn: (payload: QueryPayload, size: number) => Promise<FetchListFnReturn<ItemState, ItemPayload>>;
|
|
194
200
|
fetchItemFn?: (itemId: ItemPayload) => Promise<ItemState>;
|
|
195
201
|
errorNormalizer: (exception: unknown) => NError;
|
|
196
202
|
defaultQuerySize?: number;
|
|
197
|
-
|
|
203
|
+
getInitialData?: () => ListQueryStoreInitialData<ItemState, QueryPayload, ItemPayload> | undefined;
|
|
198
204
|
disableInitialDataInvalidation?: boolean;
|
|
199
205
|
syncMutationsAndInvalidations?: {
|
|
200
206
|
syncQueries: (query1: QueryPayload, query2: QueryPayload) => boolean;
|
|
@@ -204,6 +210,24 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
204
210
|
lowPriorityThrottleMs?: number;
|
|
205
211
|
mediumPriorityThrottleMs?: number;
|
|
206
212
|
dynamicRealtimeThrottleMs?: (lastFetchDuration: number) => number;
|
|
213
|
+
optimisticListUpdates?: {
|
|
214
|
+
queries: QueryPayload | ((query: QueryPayload) => boolean) | QueryPayload[];
|
|
215
|
+
filterItem?: (item: ItemState) => boolean | null;
|
|
216
|
+
/** @default 'end' */
|
|
217
|
+
appendNewTo?: 'start' | 'end';
|
|
218
|
+
invalidateQueries?: boolean;
|
|
219
|
+
sort?: {
|
|
220
|
+
sortBy: (item: ItemState, itemPayload: ItemPayload) => string | number | (string | number)[];
|
|
221
|
+
/** @default 'asc' */
|
|
222
|
+
order?: 'asc' | 'desc' | ('asc' | 'desc')[];
|
|
223
|
+
};
|
|
224
|
+
}[];
|
|
225
|
+
onInvalidateQuery?: (query: QueryPayload, priority: FetchType) => void;
|
|
226
|
+
onInvalidateItem?: (props: {
|
|
227
|
+
itemState: ItemState;
|
|
228
|
+
payload: ItemPayload;
|
|
229
|
+
priority: FetchType;
|
|
230
|
+
}) => void;
|
|
207
231
|
}): {
|
|
208
232
|
store: Store<TSFDListQueryState<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
209
233
|
reset: () => void;
|
|
@@ -222,7 +246,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
222
246
|
(itemPayload: ItemPayload): ItemState | null | undefined;
|
|
223
247
|
};
|
|
224
248
|
loadMore: (params: QueryPayload, size?: number) => ScheduleFetchResults;
|
|
225
|
-
invalidateQuery: (queryPayload: QueryPayload | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)
|
|
249
|
+
invalidateQuery: (queryPayload: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean), priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
226
250
|
invalidateItem: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[], priority?: FetchType, ignoreInvalidationSync?: boolean) => void;
|
|
227
251
|
scheduleItemFetch: {
|
|
228
252
|
(fetchType: FetchType, itemPayload: ItemPayload): ScheduleFetchResults;
|
|
@@ -283,7 +307,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
283
307
|
}) => readonly TSFDUseListItemReturn<SelectedItem_3, NError, ItemPayload>[];
|
|
284
308
|
addItemToState: (itemPayload: ItemPayload, data: ItemState, { addItemToQueries, }?: {
|
|
285
309
|
addItemToQueries?: {
|
|
286
|
-
queries: QueryPayload | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)
|
|
310
|
+
queries: QueryPayload | QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean);
|
|
287
311
|
appendTo: "start" | "end" | ((itemsPayload: ItemPayload[]) => number);
|
|
288
312
|
} | undefined;
|
|
289
313
|
}) => void;
|
|
@@ -291,7 +315,7 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
291
315
|
ifNothingWasUpdated?: (() => void) | undefined;
|
|
292
316
|
}) => boolean;
|
|
293
317
|
startItemMutation: (itemId: ItemPayload | ((ItemPayload: ItemPayload, itemState: ItemState) => boolean) | ItemPayload[]) => () => void;
|
|
294
|
-
getQueriesState: (params: ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)
|
|
318
|
+
getQueriesState: (params: QueryPayload[] | ((params: QueryPayload, data: TSFDListQuery<NError, QueryPayload>, queryKey: string) => boolean)) => {
|
|
295
319
|
query: TSFDListQuery<NError, QueryPayload>;
|
|
296
320
|
key: string;
|
|
297
321
|
}[];
|