@arrai-innovations/reactive-helpers 21.1.2 → 22.1.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/LICENSE +28 -0
- package/README.md +109 -21
- package/config/commonCrud.js +7 -10
- package/config/listCrud.js +33 -33
- package/config/objectCrud.js +64 -59
- package/package.json +103 -89
- package/types/config/listCrud.d.ts +83 -28
- package/types/config/objectCrud.d.ts +139 -49
- package/types/tests/benchmarks/fixtures.d.ts +60 -0
- package/types/tests/benchmarks/listLayers.bench.d.ts +1 -0
- package/types/tests/benchmarks/listPush.bench.d.ts +1 -0
- package/types/tests/benchmarks/listStream.bench.d.ts +1 -0
- package/types/tests/unit/use/lifecycleCleanup.spec.d.ts +1 -0
- package/types/tests/unit/use/listPerformance.spec.d.ts +1 -0
- package/types/tests/unit/utils/cancellablePromise.spec.d.ts +1 -0
- package/types/use/cancellableIntent.d.ts +36 -33
- package/types/use/combineClasses.d.ts +5 -2
- package/types/use/error.d.ts +39 -19
- package/types/use/list.d.ts +27 -26
- package/types/use/listCalculated.d.ts +38 -55
- package/types/use/listFilter.d.ts +25 -33
- package/types/use/listInstance.d.ts +94 -81
- package/types/use/listRelated.d.ts +37 -57
- package/types/use/listSearch.d.ts +54 -52
- package/types/use/listSort.d.ts +31 -40
- package/types/use/listSubscription.d.ts +33 -36
- package/types/use/loading.d.ts +20 -10
- package/types/use/loadingError.d.ts +12 -3
- package/types/use/object.d.ts +8 -5
- package/types/use/objectCalculated.d.ts +46 -39
- package/types/use/objectInstance.d.ts +70 -74
- package/types/use/objectRelated.d.ts +51 -41
- package/types/use/objectSubscription.d.ts +38 -48
- package/types/use/proxyError.d.ts +15 -6
- package/types/use/proxyLoading.d.ts +11 -5
- package/types/use/proxyLoadingError.d.ts +19 -7
- package/types/use/search.d.ts +33 -29
- package/types/utils/assignReactiveObject.d.ts +3 -0
- package/types/utils/cancellableFetch.d.ts +2 -3
- package/types/utils/cancellablePromise.d.ts +42 -8
- package/types/utils/classes.d.ts +7 -1
- package/types/utils/deepUnref.d.ts +1 -1
- package/types/utils/getFakePk.d.ts +2 -2
- package/types/utils/isReactiveTyped.d.ts +2 -0
- package/types/utils/keyDiff.d.ts +4 -6
- package/types/utils/relatedCalculatedHelpers.d.ts +2 -0
- package/types/utils/watches.d.ts +1 -1
- package/use/cancellableIntent.js +36 -9
- package/use/combineClasses.js +2 -2
- package/use/error.js +10 -14
- package/use/list.js +6 -18
- package/use/listCalculated.js +28 -38
- package/use/listFilter.js +12 -24
- package/use/listInstance.js +101 -60
- package/use/listRelated.js +18 -37
- package/use/listSearch.js +9 -18
- package/use/listSort.js +95 -64
- package/use/listSubscription.js +19 -25
- package/use/loading.js +5 -7
- package/use/loadingError.js +3 -3
- package/use/object.js +14 -27
- package/use/objectCalculated.js +21 -25
- package/use/objectInstance.js +55 -50
- package/use/objectRelated.js +19 -25
- package/use/objectSubscription.js +18 -30
- package/use/proxyError.js +10 -10
- package/use/proxyLoading.js +5 -5
- package/use/proxyLoadingError.js +13 -8
- package/use/search.js +5 -11
- package/utils/assignReactiveObject.js +3 -3
- package/utils/cancellableFetch.js +3 -3
- package/utils/cancellablePromise.js +25 -8
- package/utils/classes.js +2 -2
- package/utils/deepUnref.js +1 -5
- package/utils/getFakePk.js +2 -2
- package/utils/isReactiveTyped.js +2 -0
- package/utils/keyDiff.js +1 -3
- package/utils/relatedCalculatedHelpers.js +2 -0
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The reactive arguments for the list instance.
|
|
3
|
-
*
|
|
4
|
-
* @typedef {object} ListInstanceProps
|
|
2
|
+
* @typedef {object} ListInstanceProps - The reactive arguments for the list instance.
|
|
5
3
|
* @property {string} pkKey - The primary key field for the list objects.
|
|
6
4
|
* @property {object} params - The arguments passed to the server.
|
|
7
5
|
* @property {object} target - Implementation specific arguments.
|
|
8
6
|
*/
|
|
9
7
|
/**
|
|
10
|
-
* The configuration options used to create a list instance.
|
|
11
|
-
*
|
|
12
|
-
* @typedef {object} ListInstanceOptions
|
|
8
|
+
* @typedef {object} ListInstanceOptions - The configuration options used to create a list instance.
|
|
13
9
|
* @property {import('vue').UnwrapNestedRefs<ListInstanceProps>} props - The props for the list instance.
|
|
14
10
|
* @property {object} [handlers] - Default implementation are used as set by `setListCrud`.
|
|
15
11
|
* @property {import('../config/listCrud.js').CrudListFn} [handlers.list] - Provide the implementation for the list
|
|
@@ -22,22 +18,16 @@
|
|
|
22
18
|
* subscribe function.
|
|
23
19
|
*/
|
|
24
20
|
/**
|
|
25
|
-
* The objects by pk.
|
|
26
|
-
*
|
|
27
|
-
* @typedef {{[pk: import('../config/commonCrud.js').Pk]: import('../use/objectInstance.js').ExistingCrudObject}} ObjectsByPk
|
|
21
|
+
* @typedef {{[pk: import('../config/commonCrud.js').Pk]: import('../use/objectInstance.js').ExistingCrudObject}} ObjectsByPk - The objects by pk.
|
|
28
22
|
*/
|
|
29
23
|
/**
|
|
30
|
-
* The objects in order, based on .order & .objects.
|
|
31
|
-
*
|
|
32
|
-
* @typedef {import('vue').ComputedRef<import('../use/objectInstance.js').ExistingCrudObject[]>} ObjectsInOrder
|
|
24
|
+
* @typedef {import('vue').ComputedRef<import('../use/objectInstance.js').ExistingCrudObject[]>} ObjectsInOrder - The objects in order, based on .order & .objects.
|
|
33
25
|
*/
|
|
34
26
|
/**
|
|
35
|
-
* The order of the objects in the list.
|
|
36
|
-
*
|
|
37
|
-
* @typedef {import('vue').ComputedRef<import('../config/commonCrud.js').Pk[]>} ListOrder
|
|
27
|
+
* @typedef {import('vue').ComputedRef<import('../config/commonCrud.js').Pk[]>} ListOrder - The order of the objects in the list.
|
|
38
28
|
*/
|
|
39
29
|
/**
|
|
40
|
-
* @typedef {object} ListInstanceRawStateCrud
|
|
30
|
+
* @typedef {object} ListInstanceRawStateCrud - The raw CRUD handlers and target args stored in a list instance's reactive state.
|
|
41
31
|
* @property {import('vue').Reactive<import('../config/objectCrud.js').TargetArgs|{}>} args - The arguments to be passed to the crud handlers.
|
|
42
32
|
* @property {import('../config/listCrud.js').CrudListFn} list - The list function.
|
|
43
33
|
* @property {import('../config/listCrud.js').CrudListSubscribeFn} subscribe - The subscribe function.
|
|
@@ -45,64 +35,57 @@
|
|
|
45
35
|
* @property {import('../config/listCrud.js').CrudExecuteActionFn} executeAction - The execute action function.
|
|
46
36
|
*/
|
|
47
37
|
/**
|
|
48
|
-
* @typedef {Map<import('../config/commonCrud.js').Pk, import('vue').Reactive<import('../use/objectInstance.js').ExistingCrudObject>>} ObjectsMap
|
|
38
|
+
* @typedef {Map<import('../config/commonCrud.js').Pk, import('vue').Reactive<import('../use/objectInstance.js').ExistingCrudObject>>} ObjectsMap - A Map of primary keys to the list's reactive existing objects.
|
|
49
39
|
*/
|
|
50
40
|
/**
|
|
51
|
-
* @typedef {object} PaginateInfo
|
|
41
|
+
* @typedef {object} PaginateInfo - Pagination details for a list, including total records, total pages, per-page count, and current page.
|
|
52
42
|
* @property {number} [totalRecords] - The total records.
|
|
53
43
|
* @property {number} [totalPages] - The total pages.
|
|
54
44
|
* @property {number} [perPage] - The per page.
|
|
55
45
|
* @property {number} [page] - The page you are giving us results for.
|
|
56
46
|
*/
|
|
57
47
|
/**
|
|
58
|
-
* @typedef {{ [key: string]: number | string }} ColumnTotals
|
|
48
|
+
* @typedef {{ [key: string]: number | string }} ColumnTotals - A map of column names to their aggregate total values for a list.
|
|
59
49
|
*/
|
|
60
50
|
/**
|
|
61
|
-
* The raw state object for the list instance, defining the reactive properties and their types.
|
|
62
|
-
*
|
|
63
|
-
* @typedef {object} ListInstanceRawMyState
|
|
51
|
+
* @typedef {object} ListInstanceRawMyState - The raw state object for the list instance, defining the reactive properties and their types.
|
|
64
52
|
* @property {import('vue').Reactive<ListInstanceRawStateCrud>} crud - CRUD handlers and their configurations for the list.
|
|
65
53
|
* @property {string} pkKey - The primary key field for the list objects.
|
|
66
54
|
* @property {object} params - Arguments passed to the server for listing operations.
|
|
67
55
|
* @property {ObjectsMap} objectsMap - The map of objects stored by their pks.
|
|
68
56
|
* @property {ObjectsByPk} objects - The list objects stored by their pks.
|
|
57
|
+
* @property {number} objectsVersion - Increments when the set of object keys changes.
|
|
69
58
|
* @property {ListOrder} order - The order of objects in the list.
|
|
70
59
|
* @property {ObjectsInOrder} objectsInOrder - The objects in the order specified by the list.
|
|
71
60
|
* @property {import('vue').ShallowReactive<PaginateInfo>} paginateInfo - Pagination information for the list.
|
|
72
61
|
* @property {import('vue').ShallowReactive<ColumnTotals>} columnTotals - Column totals for the list.
|
|
73
62
|
*/
|
|
74
63
|
/**
|
|
75
|
-
* @typedef {ListInstanceRawMyState & Pick<import('./loadingError.js').LoadingErrorStatus, "loading" | "error" | "errored">} ListInstanceRawState
|
|
64
|
+
* @typedef {ListInstanceRawMyState & Pick<import('./loadingError.js').LoadingErrorStatus, "loading" | "error" | "errored">} ListInstanceRawState - The raw, pre-unwrapped state of a list instance, combining its own state with loading and error status.
|
|
76
65
|
*/
|
|
77
66
|
/**
|
|
78
|
-
* Defines the reactive state used by the list instance.
|
|
79
|
-
*
|
|
80
|
-
* @typedef {import('vue').UnwrapNestedRefs<ListInstanceRawState>} ListInstanceState
|
|
67
|
+
* @typedef {import('vue').UnwrapNestedRefs<ListInstanceRawState>} ListInstanceState - Defines the reactive state used by the list instance.
|
|
81
68
|
*/
|
|
82
69
|
/**
|
|
83
|
-
* @typedef {(newObjects: import('../use/objectInstance.js').ExistingCrudObject[]) => void} PushObjectsFn
|
|
70
|
+
* @typedef {(newObjects: import('../use/objectInstance.js').ExistingCrudObject[]) => void} PushObjectsFn - Signature for the function that pushes a page of newly received objects into the list.
|
|
84
71
|
*/
|
|
85
72
|
/**
|
|
86
|
-
* Options to control which reactive state is reset when clearing the list.
|
|
87
|
-
*
|
|
88
|
-
* @typedef {object} ClearListOptions
|
|
73
|
+
* @typedef {object} ClearListOptions - Options to control which reactive state is reset when clearing the list.
|
|
89
74
|
* @property {boolean} [keepPagination] - When true, keep the current pagination information.
|
|
90
75
|
* @property {boolean} [keepColumnTotals] - When true, keep the current column totals.
|
|
91
76
|
* @property {boolean} [keepError] - When true, keep the current error state.
|
|
92
77
|
*/
|
|
93
78
|
/**
|
|
94
|
-
* @typedef {(options?: ClearListOptions) => void} ClearListFn
|
|
79
|
+
* @typedef {(options?: ClearListOptions) => void} ClearListFn - Signature for the handler that clears the objects held by the list.
|
|
95
80
|
*/
|
|
96
81
|
/**
|
|
97
|
-
* @typedef {(info: PaginateInfo) => void} SetPaginateInfoFn
|
|
82
|
+
* @typedef {(info: PaginateInfo) => void} SetPaginateInfoFn - Signature for the handler that updates the list's pagination information.
|
|
98
83
|
*/
|
|
99
84
|
/**
|
|
100
|
-
* @typedef {(total: ColumnTotals) => void} SetColumnTotalsFn
|
|
85
|
+
* @typedef {(total: ColumnTotals) => void} SetColumnTotalsFn - Signature for the handler that updates the list's column totals.
|
|
101
86
|
*/
|
|
102
87
|
/**
|
|
103
|
-
* Defines the methods provided by the list instance for managing objects in the list.
|
|
104
|
-
*
|
|
105
|
-
* @typedef {object} ListInstanceMyFunctions
|
|
88
|
+
* @typedef {object} ListInstanceMyFunctions - Defines the methods provided by the list instance for managing objects in the list.
|
|
106
89
|
* @property {PushObjectsFn} pushObjects - Customizable callback for handling new objects per page.
|
|
107
90
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} addListObject - Adds an object to the list.
|
|
108
91
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} updateListObject - Updates an object in the list.
|
|
@@ -117,17 +100,13 @@
|
|
|
117
100
|
* @property {(total: ColumnTotals) => void} setColumnTotals - The method to update column totals.
|
|
118
101
|
*/
|
|
119
102
|
/**
|
|
120
|
-
* @typedef {ListInstanceMyFunctions & Pick<import('./loadingError.js').LoadingErrorStatus, "clearError">} ListInstanceFunctions
|
|
103
|
+
* @typedef {ListInstanceMyFunctions & Pick<import('./loadingError.js').LoadingErrorStatus, "clearError">} ListInstanceFunctions - The methods contributed by the list instance, including its CRUD operations plus clearError.
|
|
121
104
|
*/
|
|
122
105
|
/**
|
|
123
|
-
* Helper type to facilitate the combination of state and functions into a single type.
|
|
124
|
-
*
|
|
125
|
-
* @typedef {{state: ListInstanceState}} ListInstanceStateMixIn
|
|
106
|
+
* @typedef {{state: ListInstanceState}} ListInstanceStateMixIn - Helper type to facilitate the combination of state and functions into a single type.
|
|
126
107
|
*/
|
|
127
108
|
/**
|
|
128
|
-
* The list instance, combining state management and functional operations for managing a list of objects.
|
|
129
|
-
*
|
|
130
|
-
* @typedef {ListInstanceStateMixIn & ListInstanceFunctions} ListInstance
|
|
109
|
+
* @typedef {ListInstanceStateMixIn & ListInstanceFunctions} ListInstance - The list instance, combining state management and functional operations for managing a list of objects.
|
|
131
110
|
*/
|
|
132
111
|
/**
|
|
133
112
|
* Creates and manages multiple list instances.
|
|
@@ -188,7 +167,7 @@ export function useListInstances(listInstanceArgs: {
|
|
|
188
167
|
* ```
|
|
189
168
|
*
|
|
190
169
|
* @param {ListInstanceOptions} options - Specifies the configuration options for creating a list instance, including
|
|
191
|
-
* properties for CRUD operations and UI
|
|
170
|
+
* properties for CRUD operations and UI behaviours like page persistence.
|
|
192
171
|
* @returns {ListInstance} The list instance.
|
|
193
172
|
* @throws {ListInstanceError} If the props are missing.
|
|
194
173
|
*/
|
|
@@ -217,15 +196,15 @@ export class ListInstanceError extends Error {
|
|
|
217
196
|
*/
|
|
218
197
|
export type ListInstanceProps = {
|
|
219
198
|
/**
|
|
220
|
-
*
|
|
199
|
+
* The primary key field for the list objects.
|
|
221
200
|
*/
|
|
222
201
|
pkKey: string;
|
|
223
202
|
/**
|
|
224
|
-
*
|
|
203
|
+
* The arguments passed to the server.
|
|
225
204
|
*/
|
|
226
205
|
params: object;
|
|
227
206
|
/**
|
|
228
|
-
*
|
|
207
|
+
* Implementation specific arguments.
|
|
229
208
|
*/
|
|
230
209
|
target: object;
|
|
231
210
|
};
|
|
@@ -234,11 +213,11 @@ export type ListInstanceProps = {
|
|
|
234
213
|
*/
|
|
235
214
|
export type ListInstanceOptions = {
|
|
236
215
|
/**
|
|
237
|
-
*
|
|
216
|
+
* The props for the list instance.
|
|
238
217
|
*/
|
|
239
218
|
props: import("vue").UnwrapNestedRefs<ListInstanceProps>;
|
|
240
219
|
/**
|
|
241
|
-
*
|
|
220
|
+
* Default implementation are used as set by `setListCrud`.
|
|
242
221
|
*/
|
|
243
222
|
handlers?: {
|
|
244
223
|
list?: import("../config/listCrud.js").CrudListFn;
|
|
@@ -261,47 +240,59 @@ export type ObjectsInOrder = import("vue").ComputedRef<import("../use/objectInst
|
|
|
261
240
|
* The order of the objects in the list.
|
|
262
241
|
*/
|
|
263
242
|
export type ListOrder = import("vue").ComputedRef<import("../config/commonCrud.js").Pk[]>;
|
|
243
|
+
/**
|
|
244
|
+
* The raw CRUD handlers and target args stored in a list instance's reactive state.
|
|
245
|
+
*/
|
|
264
246
|
export type ListInstanceRawStateCrud = {
|
|
265
247
|
/**
|
|
266
|
-
*
|
|
248
|
+
* The arguments to be passed to the crud handlers.
|
|
267
249
|
*/
|
|
268
250
|
args: import("vue").Reactive<import("../config/objectCrud.js").TargetArgs | {}>;
|
|
269
251
|
/**
|
|
270
|
-
*
|
|
252
|
+
* The list function.
|
|
271
253
|
*/
|
|
272
254
|
list: import("../config/listCrud.js").CrudListFn;
|
|
273
255
|
/**
|
|
274
|
-
*
|
|
256
|
+
* The subscribe function.
|
|
275
257
|
*/
|
|
276
258
|
subscribe: import("../config/listCrud.js").CrudListSubscribeFn;
|
|
277
259
|
/**
|
|
278
|
-
*
|
|
260
|
+
* The bulk delete function.
|
|
279
261
|
*/
|
|
280
262
|
bulkDelete: import("../config/listCrud.js").CrudBulkDeleteFn;
|
|
281
263
|
/**
|
|
282
|
-
*
|
|
264
|
+
* The execute action function.
|
|
283
265
|
*/
|
|
284
266
|
executeAction: import("../config/listCrud.js").CrudExecuteActionFn;
|
|
285
267
|
};
|
|
268
|
+
/**
|
|
269
|
+
* A Map of primary keys to the list's reactive existing objects.
|
|
270
|
+
*/
|
|
286
271
|
export type ObjectsMap = Map<import("../config/commonCrud.js").Pk, import("vue").Reactive<import("../use/objectInstance.js").ExistingCrudObject>>;
|
|
272
|
+
/**
|
|
273
|
+
* Pagination details for a list, including total records, total pages, per-page count, and current page.
|
|
274
|
+
*/
|
|
287
275
|
export type PaginateInfo = {
|
|
288
276
|
/**
|
|
289
|
-
*
|
|
277
|
+
* The total records.
|
|
290
278
|
*/
|
|
291
279
|
totalRecords?: number;
|
|
292
280
|
/**
|
|
293
|
-
*
|
|
281
|
+
* The total pages.
|
|
294
282
|
*/
|
|
295
283
|
totalPages?: number;
|
|
296
284
|
/**
|
|
297
|
-
*
|
|
285
|
+
* The per page.
|
|
298
286
|
*/
|
|
299
287
|
perPage?: number;
|
|
300
288
|
/**
|
|
301
|
-
*
|
|
289
|
+
* The page you are giving us results for.
|
|
302
290
|
*/
|
|
303
291
|
page?: number;
|
|
304
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* A map of column names to their aggregate total values for a list.
|
|
295
|
+
*/
|
|
305
296
|
export type ColumnTotals = {
|
|
306
297
|
[key: string]: number | string;
|
|
307
298
|
};
|
|
@@ -310,123 +301,145 @@ export type ColumnTotals = {
|
|
|
310
301
|
*/
|
|
311
302
|
export type ListInstanceRawMyState = {
|
|
312
303
|
/**
|
|
313
|
-
*
|
|
304
|
+
* CRUD handlers and their configurations for the list.
|
|
314
305
|
*/
|
|
315
306
|
crud: import("vue").Reactive<ListInstanceRawStateCrud>;
|
|
316
307
|
/**
|
|
317
|
-
*
|
|
308
|
+
* The primary key field for the list objects.
|
|
318
309
|
*/
|
|
319
310
|
pkKey: string;
|
|
320
311
|
/**
|
|
321
|
-
*
|
|
312
|
+
* Arguments passed to the server for listing operations.
|
|
322
313
|
*/
|
|
323
314
|
params: object;
|
|
324
315
|
/**
|
|
325
|
-
*
|
|
316
|
+
* The map of objects stored by their pks.
|
|
326
317
|
*/
|
|
327
318
|
objectsMap: ObjectsMap;
|
|
328
319
|
/**
|
|
329
|
-
*
|
|
320
|
+
* The list objects stored by their pks.
|
|
330
321
|
*/
|
|
331
322
|
objects: ObjectsByPk;
|
|
332
323
|
/**
|
|
333
|
-
*
|
|
324
|
+
* Increments when the set of object keys changes.
|
|
325
|
+
*/
|
|
326
|
+
objectsVersion: number;
|
|
327
|
+
/**
|
|
328
|
+
* The order of objects in the list.
|
|
334
329
|
*/
|
|
335
330
|
order: ListOrder;
|
|
336
331
|
/**
|
|
337
|
-
*
|
|
332
|
+
* The objects in the order specified by the list.
|
|
338
333
|
*/
|
|
339
334
|
objectsInOrder: ObjectsInOrder;
|
|
340
335
|
/**
|
|
341
|
-
*
|
|
336
|
+
* Pagination information for the list.
|
|
342
337
|
*/
|
|
343
338
|
paginateInfo: import("vue").ShallowReactive<PaginateInfo>;
|
|
344
339
|
/**
|
|
345
|
-
*
|
|
340
|
+
* Column totals for the list.
|
|
346
341
|
*/
|
|
347
342
|
columnTotals: import("vue").ShallowReactive<ColumnTotals>;
|
|
348
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* The raw, pre-unwrapped state of a list instance, combining its own state with loading and error status.
|
|
346
|
+
*/
|
|
349
347
|
export type ListInstanceRawState = ListInstanceRawMyState & Pick<import("./loadingError.js").LoadingErrorStatus, "loading" | "error" | "errored">;
|
|
350
348
|
/**
|
|
351
349
|
* Defines the reactive state used by the list instance.
|
|
352
350
|
*/
|
|
353
351
|
export type ListInstanceState = import("vue").UnwrapNestedRefs<ListInstanceRawState>;
|
|
352
|
+
/**
|
|
353
|
+
* Signature for the function that pushes a page of newly received objects into the list.
|
|
354
|
+
*/
|
|
354
355
|
export type PushObjectsFn = (newObjects: import("../use/objectInstance.js").ExistingCrudObject[]) => void;
|
|
355
356
|
/**
|
|
356
357
|
* Options to control which reactive state is reset when clearing the list.
|
|
357
358
|
*/
|
|
358
359
|
export type ClearListOptions = {
|
|
359
360
|
/**
|
|
360
|
-
*
|
|
361
|
+
* When true, keep the current pagination information.
|
|
361
362
|
*/
|
|
362
363
|
keepPagination?: boolean;
|
|
363
364
|
/**
|
|
364
|
-
*
|
|
365
|
+
* When true, keep the current column totals.
|
|
365
366
|
*/
|
|
366
367
|
keepColumnTotals?: boolean;
|
|
367
368
|
/**
|
|
368
|
-
*
|
|
369
|
+
* When true, keep the current error state.
|
|
369
370
|
*/
|
|
370
371
|
keepError?: boolean;
|
|
371
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* Signature for the handler that clears the objects held by the list.
|
|
375
|
+
*/
|
|
372
376
|
export type ClearListFn = (options?: ClearListOptions) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Signature for the handler that updates the list's pagination information.
|
|
379
|
+
*/
|
|
373
380
|
export type SetPaginateInfoFn = (info: PaginateInfo) => void;
|
|
381
|
+
/**
|
|
382
|
+
* Signature for the handler that updates the list's column totals.
|
|
383
|
+
*/
|
|
374
384
|
export type SetColumnTotalsFn = (total: ColumnTotals) => void;
|
|
375
385
|
/**
|
|
376
386
|
* Defines the methods provided by the list instance for managing objects in the list.
|
|
377
387
|
*/
|
|
378
388
|
export type ListInstanceMyFunctions = {
|
|
379
389
|
/**
|
|
380
|
-
*
|
|
390
|
+
* Customizable callback for handling new objects per page.
|
|
381
391
|
*/
|
|
382
392
|
pushObjects: PushObjectsFn;
|
|
383
393
|
/**
|
|
384
|
-
*
|
|
394
|
+
* Adds an object to the list.
|
|
385
395
|
*/
|
|
386
396
|
addListObject: (object: import("../use/objectInstance.js").ExistingCrudObject) => void;
|
|
387
397
|
/**
|
|
388
|
-
*
|
|
398
|
+
* Updates an object in the list.
|
|
389
399
|
*/
|
|
390
400
|
updateListObject: (object: import("../use/objectInstance.js").ExistingCrudObject) => void;
|
|
391
401
|
/**
|
|
392
|
-
*
|
|
402
|
+
* Deletes an object from the list by pk.
|
|
393
403
|
*/
|
|
394
404
|
deleteListObject: (objectId: import("../config/commonCrud.js").PkInput) => void;
|
|
395
405
|
/**
|
|
396
|
-
*
|
|
406
|
+
* Clears the list objects and optionally keeps pagination, totals,
|
|
397
407
|
* or error state.
|
|
398
408
|
*/
|
|
399
409
|
clearList: (options?: ClearListOptions) => void;
|
|
400
410
|
/**
|
|
401
|
-
*
|
|
411
|
+
* Generates a unique fake pk for use within the list.
|
|
402
412
|
*/
|
|
403
413
|
getFakePk: () => import("../config/commonCrud.js").Pk;
|
|
404
414
|
/**
|
|
405
|
-
*
|
|
415
|
+
* Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
|
|
406
416
|
*/
|
|
407
417
|
list: (args?: import("../config/listCrud.js").AdditionalListArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
408
418
|
/**
|
|
409
|
-
*
|
|
419
|
+
* Deletes objects from the list by pk, returning a promise to a boolean indicating success.
|
|
410
420
|
*/
|
|
411
421
|
bulkDelete: (args?: {
|
|
412
422
|
pks?: import("../config/commonCrud.js").Pk[];
|
|
413
423
|
} & import("../config/listCrud.js").AdditionalListArgs) => Promise<boolean>;
|
|
414
424
|
/**
|
|
415
|
-
*
|
|
425
|
+
* Initiates an action on all objects in the list, returning the response, or null if the action failed.
|
|
416
426
|
*/
|
|
417
427
|
executeAction: (args: {
|
|
418
428
|
action: string;
|
|
419
429
|
pks?: import("../config/commonCrud.js").Pk[];
|
|
420
430
|
} & import("../config/listCrud.js").AdditionalListArgs) => Promise<object | string | boolean | null>;
|
|
421
431
|
/**
|
|
422
|
-
*
|
|
432
|
+
* The method to update pagination information.
|
|
423
433
|
*/
|
|
424
434
|
setPaginateInfo: (info: PaginateInfo) => void;
|
|
425
435
|
/**
|
|
426
|
-
*
|
|
436
|
+
* The method to update column totals.
|
|
427
437
|
*/
|
|
428
438
|
setColumnTotals: (total: ColumnTotals) => void;
|
|
429
439
|
};
|
|
440
|
+
/**
|
|
441
|
+
* The methods contributed by the list instance, including its CRUD operations plus clearError.
|
|
442
|
+
*/
|
|
430
443
|
export type ListInstanceFunctions = ListInstanceMyFunctions & Pick<import("./loadingError.js").LoadingErrorStatus, "clearError">;
|
|
431
444
|
/**
|
|
432
445
|
* Helper type to facilitate the combination of state and functions into a single type.
|
|
@@ -5,87 +5,68 @@
|
|
|
5
5
|
* @module use/listRelated.js
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* The rule for defining relationships for objects in a list.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @property {string} pkKey - Specifies the foreign key used to link objects across lists. Planned to be renamed to
|
|
12
|
-
* 'fkKey' to better reflect its usage.
|
|
8
|
+
* @typedef {object} ListRelatedRule - The rule for defining relationships for objects in a list.
|
|
9
|
+
* @property {string} [pkKey] - Specifies the foreign key used to link objects across lists. Defaults to the rule's
|
|
10
|
+
* own key when omitted. Planned to be renamed to 'fkKey' to better reflect its usage.
|
|
13
11
|
* @property {string[]} [order] - Specifies the order in which related objects should be sorted, if applicable.
|
|
14
12
|
* @property {import('./listInstance.js').ObjectsByPk} objects - The objects that can be related based on the foreign key.
|
|
15
13
|
*/
|
|
16
14
|
/**
|
|
17
|
-
* The rules for defining relationships among objects in a list.
|
|
18
|
-
*
|
|
19
15
|
* @typedef {{
|
|
20
16
|
* [rule: string]: ListRelatedRule,
|
|
21
|
-
* }} ListRelatedRules
|
|
17
|
+
* }} ListRelatedRules - The rules for defining relationships among objects in a list.
|
|
22
18
|
*/
|
|
23
19
|
/**
|
|
24
|
-
* Represents the internal state used by the list related composition function. It manages and computes the relationships
|
|
25
|
-
* between objects based on specified rules, providing real-time updates to related objects as the parent state changes.
|
|
26
|
-
*
|
|
27
|
-
* @typedef {object} ListRelatedRawState
|
|
20
|
+
* @typedef {object} ListRelatedRawState - Represents the internal state used by the list related composition function. It manages and computes the relationships between objects based on specified rules, providing real-time updates to related objects as the parent state changes.
|
|
28
21
|
* @property {{
|
|
29
22
|
* [pk: import('../config/commonCrud.js').Pk]: {
|
|
30
|
-
* [rule: string]:
|
|
23
|
+
* [rule: string]: any,
|
|
31
24
|
* },
|
|
32
|
-
* }} relatedObjects -
|
|
25
|
+
* }} relatedObjects - The related objects, by object pk and then rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the related object (or array of related objects) and never carry a `.value`.
|
|
33
26
|
* @property {ListRelatedRules} relatedObjectsRules - Defines the rules for establishing relationships, such as foreign key links and sorting orders.
|
|
34
27
|
* @property {{
|
|
35
28
|
* [pk: import('../config/commonCrud.js').Pk]: {
|
|
36
29
|
* [rule: string]: import('vue').ComputedRef<[object, string]>,
|
|
37
30
|
* },
|
|
38
|
-
* }} objAndKeyForPkAndRule - Maps each object pk and rule to a tuple consisting of the related object and its respective key, facilitating direct data manipulation.
|
|
31
|
+
* }} objAndKeyForPkAndRule - Maps each object pk and rule to a tuple consisting of the related object and its respective key, facilitating direct data manipulation. Reads through the reactive state unwrap the computed to the tuple itself, so `.value` is not used.
|
|
39
32
|
* @property {{
|
|
40
33
|
* [pk: import('../config/commonCrud.js').Pk]: {
|
|
41
|
-
* [rule: string]:
|
|
34
|
+
* [rule: string]: any,
|
|
42
35
|
* },
|
|
43
|
-
* }} fkForPkAndRule -
|
|
36
|
+
* }} fkForPkAndRule - The foreign key for each object pk and rule, crucial for navigating complex data relationships. Each entry is backed by a computed that the reactive proxy unwraps on read.
|
|
44
37
|
* @property {boolean} relatedObjectsParentStateObjectsWatchRunning - Flags whether the watch on parent state objects is currently active, ensuring updates trigger as needed.
|
|
45
38
|
* @property {boolean} relatedObjectsWatchRunning - Indicates if watches on the related objects themselves are active, managing updates efficiently.
|
|
46
39
|
* @property {boolean} relatedRunning - Signals whether any computations related to object relationships are currently in progress.
|
|
47
40
|
* @property {import('vue').Ref<boolean>} running - General flag that indicates if the list-related logic is processing, used to manage UI feedback or prevent concurrent operations.
|
|
48
41
|
*/
|
|
49
42
|
/**
|
|
50
|
-
* The raw state properties for a parent of a list related property.
|
|
51
|
-
*
|
|
52
43
|
* @typedef {(
|
|
53
44
|
* import('./listInstance.js').ListInstanceRawState &
|
|
54
45
|
* Partial<import('./listSubscription.js').ListSubscriptionRawState>
|
|
55
|
-
* )} ListRelatedParentRawState
|
|
46
|
+
* )} ListRelatedParentRawState - The raw state properties for a parent of a list related property.
|
|
56
47
|
*/
|
|
57
48
|
/**
|
|
58
|
-
* The type for a parentState object.
|
|
59
|
-
*
|
|
60
|
-
* @typedef {import('vue').UnwrapNestedRefs<ListRelatedParentRawState>} ListRelatedParentState
|
|
49
|
+
* @typedef {import('vue').UnwrapNestedRefs<ListRelatedParentRawState>} ListRelatedParentState - The type for a parentState object.
|
|
61
50
|
*/
|
|
62
51
|
/**
|
|
63
|
-
* The state for a list related property.
|
|
64
|
-
*
|
|
65
52
|
* @typedef {import('vue').UnwrapNestedRefs<
|
|
66
53
|
* ListRelatedParentRawState &
|
|
67
54
|
* ListRelatedRawState
|
|
68
|
-
* >} ListRelatedState
|
|
55
|
+
* >} ListRelatedState - The state for a list related property.
|
|
69
56
|
*/
|
|
70
57
|
/**
|
|
71
|
-
* The options for the list related composition function.
|
|
72
|
-
*
|
|
73
|
-
* @typedef {object} ListRelatedOptions
|
|
58
|
+
* @typedef {object} ListRelatedOptions - The options for the list related composition function.
|
|
74
59
|
* @property {ListRelatedParentState} parentState - The parent state object.
|
|
75
60
|
* @property {import('vue').Ref<ListRelatedRules>} relatedObjectsRules - The rules for the related objects.
|
|
76
61
|
*/
|
|
77
62
|
/**
|
|
78
|
-
* The properties for the list related composition function.
|
|
79
|
-
*
|
|
80
|
-
* @typedef {object} ListRelatedProperties
|
|
63
|
+
* @typedef {object} ListRelatedProperties - The properties for the list related composition function.
|
|
81
64
|
* @property {ListRelatedState} state - The state for the list related property.
|
|
82
65
|
* @property {ListRelatedParentState} parentState - The parent state object.
|
|
83
66
|
* @property {() => void} stop - Stops all effects of the list related property.
|
|
84
67
|
*/
|
|
85
68
|
/**
|
|
86
|
-
* An instance of `useListRelated`.
|
|
87
|
-
*
|
|
88
|
-
* @typedef {ListRelatedProperties} ListRelated
|
|
69
|
+
* @typedef {ListRelatedProperties} ListRelated - An instance of `useListRelated`.
|
|
89
70
|
*/
|
|
90
71
|
/**
|
|
91
72
|
* Creates and manages multiple instances of list-related properties, linking each to corresponding parent instances
|
|
@@ -182,16 +163,16 @@ export function useListRelated({ parentState, relatedObjectsRules }: ListRelated
|
|
|
182
163
|
*/
|
|
183
164
|
export type ListRelatedRule = {
|
|
184
165
|
/**
|
|
185
|
-
*
|
|
186
|
-
* 'fkKey' to better reflect its usage.
|
|
166
|
+
* Specifies the foreign key used to link objects across lists. Defaults to the rule's
|
|
167
|
+
* own key when omitted. Planned to be renamed to 'fkKey' to better reflect its usage.
|
|
187
168
|
*/
|
|
188
|
-
pkKey
|
|
169
|
+
pkKey?: string;
|
|
189
170
|
/**
|
|
190
|
-
*
|
|
171
|
+
* Specifies the order in which related objects should be sorted, if applicable.
|
|
191
172
|
*/
|
|
192
173
|
order?: string[];
|
|
193
174
|
/**
|
|
194
|
-
*
|
|
175
|
+
* The objects that can be related based on the foreign key.
|
|
195
176
|
*/
|
|
196
177
|
objects: import("./listInstance.js").ObjectsByPk;
|
|
197
178
|
};
|
|
@@ -202,24 +183,23 @@ export type ListRelatedRules = {
|
|
|
202
183
|
[rule: string]: ListRelatedRule;
|
|
203
184
|
};
|
|
204
185
|
/**
|
|
205
|
-
* Represents the internal state used by the list related composition function. It manages and computes the relationships
|
|
206
|
-
* between objects based on specified rules, providing real-time updates to related objects as the parent state changes.
|
|
186
|
+
* Represents the internal state used by the list related composition function. It manages and computes the relationships between objects based on specified rules, providing real-time updates to related objects as the parent state changes.
|
|
207
187
|
*/
|
|
208
188
|
export type ListRelatedRawState = {
|
|
209
189
|
/**
|
|
210
|
-
*
|
|
190
|
+
* The related objects, by object pk and then rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the related object (or array of related objects) and never carry a `.value`.
|
|
211
191
|
*/
|
|
212
192
|
relatedObjects: {
|
|
213
193
|
[pk: import("../config/commonCrud.js").Pk]: {
|
|
214
|
-
[rule: string]:
|
|
194
|
+
[rule: string]: any;
|
|
215
195
|
};
|
|
216
196
|
};
|
|
217
197
|
/**
|
|
218
|
-
*
|
|
198
|
+
* Defines the rules for establishing relationships, such as foreign key links and sorting orders.
|
|
219
199
|
*/
|
|
220
200
|
relatedObjectsRules: ListRelatedRules;
|
|
221
201
|
/**
|
|
222
|
-
*
|
|
202
|
+
* Maps each object pk and rule to a tuple consisting of the related object and its respective key, facilitating direct data manipulation. Reads through the reactive state unwrap the computed to the tuple itself, so `.value` is not used.
|
|
223
203
|
*/
|
|
224
204
|
objAndKeyForPkAndRule: {
|
|
225
205
|
[pk: import("../config/commonCrud.js").Pk]: {
|
|
@@ -227,27 +207,27 @@ export type ListRelatedRawState = {
|
|
|
227
207
|
};
|
|
228
208
|
};
|
|
229
209
|
/**
|
|
230
|
-
*
|
|
210
|
+
* The foreign key for each object pk and rule, crucial for navigating complex data relationships. Each entry is backed by a computed that the reactive proxy unwraps on read.
|
|
231
211
|
*/
|
|
232
212
|
fkForPkAndRule: {
|
|
233
213
|
[pk: import("../config/commonCrud.js").Pk]: {
|
|
234
|
-
[rule: string]:
|
|
214
|
+
[rule: string]: any;
|
|
235
215
|
};
|
|
236
216
|
};
|
|
237
217
|
/**
|
|
238
|
-
*
|
|
218
|
+
* Flags whether the watch on parent state objects is currently active, ensuring updates trigger as needed.
|
|
239
219
|
*/
|
|
240
220
|
relatedObjectsParentStateObjectsWatchRunning: boolean;
|
|
241
221
|
/**
|
|
242
|
-
*
|
|
222
|
+
* Indicates if watches on the related objects themselves are active, managing updates efficiently.
|
|
243
223
|
*/
|
|
244
224
|
relatedObjectsWatchRunning: boolean;
|
|
245
225
|
/**
|
|
246
|
-
*
|
|
226
|
+
* Signals whether any computations related to object relationships are currently in progress.
|
|
247
227
|
*/
|
|
248
228
|
relatedRunning: boolean;
|
|
249
229
|
/**
|
|
250
|
-
*
|
|
230
|
+
* General flag that indicates if the list-related logic is processing, used to manage UI feedback or prevent concurrent operations.
|
|
251
231
|
*/
|
|
252
232
|
running: import("vue").Ref<boolean>;
|
|
253
233
|
};
|
|
@@ -268,11 +248,11 @@ export type ListRelatedState = import("vue").UnwrapNestedRefs<ListRelatedParentR
|
|
|
268
248
|
*/
|
|
269
249
|
export type ListRelatedOptions = {
|
|
270
250
|
/**
|
|
271
|
-
*
|
|
251
|
+
* The parent state object.
|
|
272
252
|
*/
|
|
273
253
|
parentState: ListRelatedParentState;
|
|
274
254
|
/**
|
|
275
|
-
*
|
|
255
|
+
* The rules for the related objects.
|
|
276
256
|
*/
|
|
277
257
|
relatedObjectsRules: import("vue").Ref<ListRelatedRules>;
|
|
278
258
|
};
|
|
@@ -281,15 +261,15 @@ export type ListRelatedOptions = {
|
|
|
281
261
|
*/
|
|
282
262
|
export type ListRelatedProperties = {
|
|
283
263
|
/**
|
|
284
|
-
*
|
|
264
|
+
* The state for the list related property.
|
|
285
265
|
*/
|
|
286
266
|
state: ListRelatedState;
|
|
287
267
|
/**
|
|
288
|
-
*
|
|
268
|
+
* The parent state object.
|
|
289
269
|
*/
|
|
290
270
|
parentState: ListRelatedParentState;
|
|
291
271
|
/**
|
|
292
|
-
*
|
|
272
|
+
* Stops all effects of the list related property.
|
|
293
273
|
*/
|
|
294
274
|
stop: () => void;
|
|
295
275
|
};
|