@arrai-innovations/reactive-helpers 23.0.2 → 24.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/config/commonCrud.js +5 -0
- package/config/listCrud.js +5 -1
- package/config/objectCrud.js +6 -0
- package/package.json +2 -2
- package/types/config/commonCrud.d.ts +5 -0
- package/types/config/listCrud.d.ts +12 -0
- package/types/config/objectCrud.d.ts +24 -0
- package/types/use/listInstance.d.ts +20 -3
- package/types/use/listRelated.d.ts +2 -2
- package/types/use/objectInstance.d.ts +31 -10
- package/types/use/objectRelated.d.ts +2 -2
- package/use/listInstance.js +47 -6
- package/use/listRelated.js +1 -1
- package/use/objectInstance.js +81 -20
- package/use/objectRelated.js +1 -1
- package/utils/relatedCalculatedHelpers.js +1 -1
package/config/commonCrud.js
CHANGED
|
@@ -12,6 +12,11 @@ import { refIfReactive } from "../utils/refIfReactive.js";
|
|
|
12
12
|
* @typedef {string} Pk - Primary key type used for storage and output (always a string).
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {() => void} SetCancelledFn - Callback a CRUD handler calls to mark its current run cancelled. The instance
|
|
17
|
+
* withholds that run's result, stores no error, and resolves the action's cancellation value.
|
|
18
|
+
*/
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* @internal
|
|
17
22
|
* @param {string} name - The name of the method.
|
package/config/listCrud.js
CHANGED
|
@@ -32,6 +32,7 @@ import { readonly } from "vue";
|
|
|
32
32
|
* @property {import("../use/listInstance.js").PushObjectsFn} pushObjects - The method to call with new page(s) of data received.
|
|
33
33
|
* @property {ClearObjectsFn} clearObjects - The method to call to clear the objects.
|
|
34
34
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
35
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
35
36
|
* @property {SetPaginateInfo} setPaginateInfo - The method to update pagination information.
|
|
36
37
|
* @property {SetColumnTotals} setColumnTotals - The method to update column totals.
|
|
37
38
|
*/
|
|
@@ -47,6 +48,7 @@ import { readonly } from "vue";
|
|
|
47
48
|
* @property {string} pkKey - The key name of the primary key.
|
|
48
49
|
* @property {{[key:string]: any}} params - Your listing arguments, passed through to the crud handlers.
|
|
49
50
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
51
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
50
52
|
*/
|
|
51
53
|
|
|
52
54
|
/**
|
|
@@ -81,6 +83,7 @@ import { readonly } from "vue";
|
|
|
81
83
|
* @property {string} action - The action to execute.
|
|
82
84
|
* @property {{[key:string]: any}} params - Your listing arguments, passed through to the crud handlers.
|
|
83
85
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
86
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
84
87
|
*/
|
|
85
88
|
|
|
86
89
|
/**
|
|
@@ -99,7 +102,8 @@ import { readonly } from "vue";
|
|
|
99
102
|
* @callback CrudBulkDeleteFn - Signature for the handler that bulk-deletes objects from the backing store.
|
|
100
103
|
* @param {BulkDeleteArgs} args - The arguments to be passed to the crud handlers.
|
|
101
104
|
* @returns {import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} - A promise whose resolution
|
|
102
|
-
* means the bulk delete succeeded; the resolved value is not inspected, and the instance then
|
|
105
|
+
* means the bulk delete succeeded; the resolved value is not inspected, and the instance then removes the named rows
|
|
106
|
+
* from the list.
|
|
103
107
|
* Carry a `cancel` method to let the caller abandon the run.
|
|
104
108
|
*/
|
|
105
109
|
|
package/config/objectCrud.js
CHANGED
|
@@ -33,6 +33,7 @@ import { readonly } from "vue";
|
|
|
33
33
|
* @property {{[key:string]: any}} params - Your listing or retrieval arguments, passed through to the crud handlers.
|
|
34
34
|
* @property {string} pkKey - The key name of the primary key.
|
|
35
35
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
36
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -46,6 +47,7 @@ import { readonly } from "vue";
|
|
|
46
47
|
* @property {string} pkKey - The key name of the primary key.
|
|
47
48
|
* @property {{[key:string]: any}} params - Your listing or retrieval arguments, passed through to the crud handlers.
|
|
48
49
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
50
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
49
51
|
*/
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -59,6 +61,7 @@ import { readonly } from "vue";
|
|
|
59
61
|
* @property {{[key:string]: any}} params - Your listing or retrieval arguments, passed through to the crud handlers.
|
|
60
62
|
* @property {string} pkKey - The key name of the primary key.
|
|
61
63
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
64
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
62
65
|
*/
|
|
63
66
|
|
|
64
67
|
/**
|
|
@@ -71,6 +74,7 @@ import { readonly } from "vue";
|
|
|
71
74
|
* @property {import('./commonCrud.js').Pk} pk - The pk of the object to be acted upon.
|
|
72
75
|
* @property {string} pkKey - The key name of the primary key.
|
|
73
76
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
77
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
74
78
|
*/
|
|
75
79
|
|
|
76
80
|
/**
|
|
@@ -85,6 +89,7 @@ import { readonly } from "vue";
|
|
|
85
89
|
* @property {{[key:string]: any}} partialObject - The changed fields only.
|
|
86
90
|
* @property {{[key:string]: any}} params - Your listing or retrieval arguments, passed through to the crud handlers.
|
|
87
91
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
92
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
88
93
|
*/
|
|
89
94
|
/**
|
|
90
95
|
* @typedef {PartialArgsRaw & AdditionalCrudArgs} PartialArgs - Arguments for an object patch (partial update) operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -97,6 +102,7 @@ import { readonly } from "vue";
|
|
|
97
102
|
* @property {string} pkKey - The key name of the primary key.
|
|
98
103
|
* @property {string} action - The action to execute.
|
|
99
104
|
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A readonly ref that becomes true once the request is cancelled.
|
|
105
|
+
* @property {import('./commonCrud.js').SetCancelledFn} setCancelled - Marks this run cancelled from inside the handler.
|
|
100
106
|
*/
|
|
101
107
|
|
|
102
108
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrai-innovations/reactive-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.1.0",
|
|
4
4
|
"description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"vue-deepunref": "^1.0.1"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@vueuse/core": "^
|
|
86
|
+
"@vueuse/core": "^14.0.0",
|
|
87
87
|
"lodash-es": "^4.17.23",
|
|
88
88
|
"vue": "^3.5.13"
|
|
89
89
|
},
|
|
@@ -24,3 +24,8 @@ export type PkInput = string | number;
|
|
|
24
24
|
* Primary key type used for storage and output (always a string).
|
|
25
25
|
*/
|
|
26
26
|
export type Pk = string;
|
|
27
|
+
/**
|
|
28
|
+
* Callback a CRUD handler calls to mark its current run cancelled. The instance
|
|
29
|
+
* withholds that run's result, stores no error, and resolves the action's cancellation value.
|
|
30
|
+
*/
|
|
31
|
+
export type SetCancelledFn = () => void;
|
|
@@ -55,6 +55,10 @@ export type ListArgsRaw = {
|
|
|
55
55
|
* A readonly ref that becomes true once the request is cancelled.
|
|
56
56
|
*/
|
|
57
57
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
58
|
+
/**
|
|
59
|
+
* Marks this run cancelled from inside the handler.
|
|
60
|
+
*/
|
|
61
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
58
62
|
/**
|
|
59
63
|
* The method to update pagination information.
|
|
60
64
|
*/
|
|
@@ -94,6 +98,10 @@ export type BulkDeleteArgsRaw = {
|
|
|
94
98
|
* A readonly ref that becomes true once the request is cancelled.
|
|
95
99
|
*/
|
|
96
100
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
101
|
+
/**
|
|
102
|
+
* Marks this run cancelled from inside the handler.
|
|
103
|
+
*/
|
|
104
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
97
105
|
};
|
|
98
106
|
/**
|
|
99
107
|
* Arguments for a bulk-delete operation, combining the raw arguments with any additional list CRUD arguments.
|
|
@@ -162,6 +170,10 @@ export type ExecuteActionArgsRaw = {
|
|
|
162
170
|
* A readonly ref that becomes true once the request is cancelled.
|
|
163
171
|
*/
|
|
164
172
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
173
|
+
/**
|
|
174
|
+
* Marks this run cancelled from inside the handler.
|
|
175
|
+
*/
|
|
176
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
165
177
|
};
|
|
166
178
|
/**
|
|
167
179
|
* Arguments for a list execute-action operation, combining the raw arguments with any additional list CRUD arguments.
|
|
@@ -67,6 +67,10 @@ export type CreateArgsRaw = {
|
|
|
67
67
|
* A readonly ref that becomes true once the request is cancelled.
|
|
68
68
|
*/
|
|
69
69
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
70
|
+
/**
|
|
71
|
+
* Marks this run cancelled from inside the handler.
|
|
72
|
+
*/
|
|
73
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
70
74
|
};
|
|
71
75
|
/**
|
|
72
76
|
* Arguments for an object create operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -98,6 +102,10 @@ export type RetrieveArgsRaw = {
|
|
|
98
102
|
* A readonly ref that becomes true once the request is cancelled.
|
|
99
103
|
*/
|
|
100
104
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
105
|
+
/**
|
|
106
|
+
* Marks this run cancelled from inside the handler.
|
|
107
|
+
*/
|
|
108
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
101
109
|
};
|
|
102
110
|
/**
|
|
103
111
|
* Arguments for an object retrieve operation, combining the raw arguments with run-tracking and any additional CRUD arguments.
|
|
@@ -129,6 +137,10 @@ export type UpdateArgsRaw = {
|
|
|
129
137
|
* A readonly ref that becomes true once the request is cancelled.
|
|
130
138
|
*/
|
|
131
139
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
140
|
+
/**
|
|
141
|
+
* Marks this run cancelled from inside the handler.
|
|
142
|
+
*/
|
|
143
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
132
144
|
};
|
|
133
145
|
/**
|
|
134
146
|
* Arguments for an object update operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -154,6 +166,10 @@ export type DeleteArgsRaw = {
|
|
|
154
166
|
* A readonly ref that becomes true once the request is cancelled.
|
|
155
167
|
*/
|
|
156
168
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
169
|
+
/**
|
|
170
|
+
* Marks this run cancelled from inside the handler.
|
|
171
|
+
*/
|
|
172
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
157
173
|
};
|
|
158
174
|
/**
|
|
159
175
|
* Arguments for an object delete operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -191,6 +207,10 @@ export type PartialArgsRaw = {
|
|
|
191
207
|
* A readonly ref that becomes true once the request is cancelled.
|
|
192
208
|
*/
|
|
193
209
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
210
|
+
/**
|
|
211
|
+
* Marks this run cancelled from inside the handler.
|
|
212
|
+
*/
|
|
213
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
194
214
|
};
|
|
195
215
|
/**
|
|
196
216
|
* Arguments for an object patch (partial update) operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -220,6 +240,10 @@ export type ObjectExecuteActionArgsRaw = {
|
|
|
220
240
|
* A readonly ref that becomes true once the request is cancelled.
|
|
221
241
|
*/
|
|
222
242
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
243
|
+
/**
|
|
244
|
+
* Marks this run cancelled from inside the handler.
|
|
245
|
+
*/
|
|
246
|
+
setCancelled: import("./commonCrud.js").SetCancelledFn;
|
|
223
247
|
};
|
|
224
248
|
/**
|
|
225
249
|
* Arguments for a single-object execute-action operation, combining the raw arguments with any additional CRUD arguments.
|
|
@@ -84,6 +84,12 @@
|
|
|
84
84
|
/**
|
|
85
85
|
* @typedef {(total: ColumnTotals) => void} SetColumnTotalsFn - Signature for the handler that updates the list's column totals.
|
|
86
86
|
*/
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {object} KeepObjectsOption - Per-call control over whether the list applies its own result to `state.objects`.
|
|
89
|
+
* @property {boolean} [keepObjects=false] - When true, `bulkDelete` leaves `state.objects` untouched after a successful
|
|
90
|
+
* handler result. The caller reconciles through `deleteListObject`, `pushObjects`, or `clearList`. The instance
|
|
91
|
+
* consumes the option before calling the crud handler.
|
|
92
|
+
*/
|
|
87
93
|
/**
|
|
88
94
|
* @typedef {object} ListInstanceMyFunctions - Defines the methods provided by the list instance for managing objects in the list.
|
|
89
95
|
* @property {PushObjectsFn} pushObjects - Customizable callback for handling new objects per page.
|
|
@@ -94,7 +100,7 @@
|
|
|
94
100
|
* or error state.
|
|
95
101
|
* @property {() => import('../config/commonCrud.js').Pk} getFakePk - Generates a unique fake pk for use within the list.
|
|
96
102
|
* @property {(args?: import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
|
|
97
|
-
* @property {(args?: {pks?: import('../config/commonCrud.js').Pk[]} & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success. The promise carries a `cancel` method when the handler's promise did.
|
|
103
|
+
* @property {(args?: {pks?: import('../config/commonCrud.js').Pk[]} & KeepObjectsOption & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success. Omitting `pks` names every row the list holds. On success, the list removes named loaded rows unless `keepObjects` is true. Missing loaded rows are ignored. The promise carries a `cancel` method when the handler's promise did.
|
|
98
104
|
* @property {(args: {action: string, pks?: import('../config/commonCrud.js').Pk[]} & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string|boolean|null>} executeAction - Initiates an action on all objects in the list, returning the response, or null if the action failed. The promise carries a `cancel` method when the handler's promise did.
|
|
99
105
|
* @property {(info: PaginateInfo) => void} setPaginateInfo - The method to update pagination information.
|
|
100
106
|
* @property {(total: ColumnTotals) => void} setColumnTotals - The method to update column totals.
|
|
@@ -383,6 +389,17 @@ export type SetPaginateInfoFn = (info: PaginateInfo) => void;
|
|
|
383
389
|
* Signature for the handler that updates the list's column totals.
|
|
384
390
|
*/
|
|
385
391
|
export type SetColumnTotalsFn = (total: ColumnTotals) => void;
|
|
392
|
+
/**
|
|
393
|
+
* Per-call control over whether the list applies its own result to `state.objects`.
|
|
394
|
+
*/
|
|
395
|
+
export type KeepObjectsOption = {
|
|
396
|
+
/**
|
|
397
|
+
* When true, `bulkDelete` leaves `state.objects` untouched after a successful
|
|
398
|
+
* handler result. The caller reconciles through `deleteListObject`, `pushObjects`, or `clearList`. The instance
|
|
399
|
+
* consumes the option before calling the crud handler.
|
|
400
|
+
*/
|
|
401
|
+
keepObjects?: boolean;
|
|
402
|
+
};
|
|
386
403
|
/**
|
|
387
404
|
* Defines the methods provided by the list instance for managing objects in the list.
|
|
388
405
|
*/
|
|
@@ -417,11 +434,11 @@ export type ListInstanceMyFunctions = {
|
|
|
417
434
|
*/
|
|
418
435
|
list: (args?: import("../config/listCrud.js").AdditionalListArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
419
436
|
/**
|
|
420
|
-
* Deletes objects from the list by pk, returning a promise to a boolean indicating success. The promise carries a `cancel` method when the handler's promise did.
|
|
437
|
+
* Deletes objects from the list by pk, returning a promise to a boolean indicating success. Omitting `pks` names every row the list holds. On success, the list removes named loaded rows unless `keepObjects` is true. Missing loaded rows are ignored. The promise carries a `cancel` method when the handler's promise did.
|
|
421
438
|
*/
|
|
422
439
|
bulkDelete: (args?: {
|
|
423
440
|
pks?: import("../config/commonCrud.js").Pk[];
|
|
424
|
-
} & import("../config/listCrud.js").AdditionalListArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
441
|
+
} & KeepObjectsOption & import("../config/listCrud.js").AdditionalListArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
425
442
|
/**
|
|
426
443
|
* Initiates an action on all objects in the list, returning the response, or null if the action failed. The promise carries a `cancel` method when the handler's promise did.
|
|
427
444
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @typedef {object} ListRelatedRule - The rule for defining relationships for objects in a list.
|
|
3
3
|
* @property {string} [fkKey] - Specifies the foreign key on each row used to link objects across lists. Defaults to
|
|
4
4
|
* the rule's own key when omitted.
|
|
5
|
-
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in
|
|
5
|
+
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
6
6
|
* A rule setting both uses `fkKey`.
|
|
7
7
|
* @property {string[]} [order] - Specifies the order in which related objects should be sorted, if applicable.
|
|
8
8
|
* @property {import('./listInstance.js').ObjectsByPk} objects - The objects that can be related based on the foreign key.
|
|
@@ -185,7 +185,7 @@ export type ListRelatedRule = {
|
|
|
185
185
|
*/
|
|
186
186
|
fkKey?: string;
|
|
187
187
|
/**
|
|
188
|
-
* Deprecated alias for `fkKey`, removed in
|
|
188
|
+
* Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
189
189
|
* A rule setting both uses `fkKey`.
|
|
190
190
|
*/
|
|
191
191
|
pkKey?: string;
|
|
@@ -121,13 +121,21 @@ export function useObjectInstance({ props, handlers }: ObjectInstanceOptions): O
|
|
|
121
121
|
/**
|
|
122
122
|
* @typedef {{[key:string]: any}} AdditionalArgs - Arbitrary extra arguments forwarded through to an object instance's CRUD operations.
|
|
123
123
|
*/
|
|
124
|
+
/**
|
|
125
|
+
* @typedef {object} KeepObjectOption - Per-call control over whether the instance applies its own result to `state.object`.
|
|
126
|
+
* @property {boolean} [keepObject=false] - When true, the instance leaves `state.object` and `state.deleted` untouched
|
|
127
|
+
* after a successful handler result. The caller reconciles through `clear` or direct state writes. The instance
|
|
128
|
+
* consumes the option before calling the crud handler.
|
|
129
|
+
*
|
|
130
|
+
* Concurrent `retrieve` calls share the first in-flight promise, including that run's `keepObject` setting.
|
|
131
|
+
*/
|
|
124
132
|
/**
|
|
125
133
|
* @typedef {object} ObjectInstanceMyFunctions - The functions available on the object instance.
|
|
126
|
-
* @property {(args: ObjectInstanceCreateArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} create - Called to turn the current object into a new object on the server.
|
|
127
|
-
* @property {(args?: Partial<import('./cancellableIntent.js').CommonRunTracking> & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} retrieve - Called to retrieve the current object by pk from the server.
|
|
128
|
-
* @property {(args: ObjectInstanceUpdateArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} update - Called to update the current object on the server.
|
|
129
|
-
* @property {(args?: AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} delete - Called to delete the current object on the server.
|
|
130
|
-
* @property {(args: ObjectInstancePatchArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} patch - Called to patch the current object on the server.
|
|
134
|
+
* @property {(args: ObjectInstanceCreateArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} create - Called to turn the current object into a new object on the server.
|
|
135
|
+
* @property {(args?: Partial<import('./cancellableIntent.js').CommonRunTracking> & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} retrieve - Called to retrieve the current object by pk from the server.
|
|
136
|
+
* @property {(args: ObjectInstanceUpdateArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} update - Called to update the current object on the server.
|
|
137
|
+
* @property {(args?: KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} delete - Called to delete the current object on the server.
|
|
138
|
+
* @property {(args: ObjectInstancePatchArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} patch - Called to patch the current object on the server.
|
|
131
139
|
* @property {(args: {action: string} & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string|void|null>} executeAction - Called to execute certain action on the current object. Resolves the handler's own resolved value, or `null` when the action failed.
|
|
132
140
|
* @property {() => void} clear - Called to clear the object state.
|
|
133
141
|
*/
|
|
@@ -313,6 +321,19 @@ export type ObjectInstancePatchArgs = {
|
|
|
313
321
|
export type AdditionalArgs = {
|
|
314
322
|
[key: string]: any;
|
|
315
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* Per-call control over whether the instance applies its own result to `state.object`.
|
|
326
|
+
*/
|
|
327
|
+
export type KeepObjectOption = {
|
|
328
|
+
/**
|
|
329
|
+
* When true, the instance leaves `state.object` and `state.deleted` untouched
|
|
330
|
+
* after a successful handler result. The caller reconciles through `clear` or direct state writes. The instance
|
|
331
|
+
* consumes the option before calling the crud handler.
|
|
332
|
+
*
|
|
333
|
+
* Concurrent `retrieve` calls share the first in-flight promise, including that run's `keepObject` setting.
|
|
334
|
+
*/
|
|
335
|
+
keepObject?: boolean;
|
|
336
|
+
};
|
|
316
337
|
/**
|
|
317
338
|
* The functions available on the object instance.
|
|
318
339
|
*/
|
|
@@ -320,23 +341,23 @@ export type ObjectInstanceMyFunctions = {
|
|
|
320
341
|
/**
|
|
321
342
|
* Called to turn the current object into a new object on the server.
|
|
322
343
|
*/
|
|
323
|
-
create: (args: ObjectInstanceCreateArgs & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
344
|
+
create: (args: ObjectInstanceCreateArgs & KeepObjectOption & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
324
345
|
/**
|
|
325
346
|
* Called to retrieve the current object by pk from the server.
|
|
326
347
|
*/
|
|
327
|
-
retrieve: (args?: Partial<import("./cancellableIntent.js").CommonRunTracking> & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
348
|
+
retrieve: (args?: Partial<import("./cancellableIntent.js").CommonRunTracking> & KeepObjectOption & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
328
349
|
/**
|
|
329
350
|
* Called to update the current object on the server.
|
|
330
351
|
*/
|
|
331
|
-
update: (args: ObjectInstanceUpdateArgs & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
352
|
+
update: (args: ObjectInstanceUpdateArgs & KeepObjectOption & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
332
353
|
/**
|
|
333
354
|
* Called to delete the current object on the server.
|
|
334
355
|
*/
|
|
335
|
-
delete: (args?: AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
356
|
+
delete: (args?: KeepObjectOption & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
336
357
|
/**
|
|
337
358
|
* Called to patch the current object on the server.
|
|
338
359
|
*/
|
|
339
|
-
patch: (args: ObjectInstancePatchArgs & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
360
|
+
patch: (args: ObjectInstancePatchArgs & KeepObjectOption & AdditionalArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean | never>;
|
|
340
361
|
/**
|
|
341
362
|
* Called to execute certain action on the current object. Resolves the handler's own resolved value, or `null` when the action failed.
|
|
342
363
|
*/
|
|
@@ -131,7 +131,7 @@ export class ObjectRelatedError extends Error {
|
|
|
131
131
|
* @typedef {object} ObjectRelatedRule - The rule for defining relationships for the managed object to other collections of objects.
|
|
132
132
|
* @property {string} [fkKey] - The foreign key on the managed object that corresponds to the key in the related
|
|
133
133
|
* object. Defaults to the rule's own key when omitted.
|
|
134
|
-
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in
|
|
134
|
+
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
135
135
|
* A rule setting both uses `fkKey`.
|
|
136
136
|
* @property {import('./listInstance.js').ObjectsByPk} objects - The related objects, indexed by the key in the related object.
|
|
137
137
|
* @property {string[]} [order] - The order of the related objects, if the related objects are an array.
|
|
@@ -225,7 +225,7 @@ export type ObjectRelatedRule = {
|
|
|
225
225
|
*/
|
|
226
226
|
fkKey?: string;
|
|
227
227
|
/**
|
|
228
|
-
* Deprecated alias for `fkKey`, removed in
|
|
228
|
+
* Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
229
229
|
* A rule setting both uses `fkKey`.
|
|
230
230
|
*/
|
|
231
231
|
pkKey?: string;
|
package/use/listInstance.js
CHANGED
|
@@ -136,6 +136,13 @@ export class ListInstanceError extends Error {
|
|
|
136
136
|
* @typedef {(total: ColumnTotals) => void} SetColumnTotalsFn - Signature for the handler that updates the list's column totals.
|
|
137
137
|
*/
|
|
138
138
|
|
|
139
|
+
/**
|
|
140
|
+
* @typedef {object} KeepObjectsOption - Per-call control over whether the list applies its own result to `state.objects`.
|
|
141
|
+
* @property {boolean} [keepObjects=false] - When true, `bulkDelete` leaves `state.objects` untouched after a successful
|
|
142
|
+
* handler result. The caller reconciles through `deleteListObject`, `pushObjects`, or `clearList`. The instance
|
|
143
|
+
* consumes the option before calling the crud handler.
|
|
144
|
+
*/
|
|
145
|
+
|
|
139
146
|
/**
|
|
140
147
|
* @typedef {object} ListInstanceMyFunctions - Defines the methods provided by the list instance for managing objects in the list.
|
|
141
148
|
* @property {PushObjectsFn} pushObjects - Customizable callback for handling new objects per page.
|
|
@@ -146,7 +153,7 @@ export class ListInstanceError extends Error {
|
|
|
146
153
|
* or error state.
|
|
147
154
|
* @property {() => import('../config/commonCrud.js').Pk} getFakePk - Generates a unique fake pk for use within the list.
|
|
148
155
|
* @property {(args?: import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
|
|
149
|
-
* @property {(args?: {pks?: import('../config/commonCrud.js').Pk[]} & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success. The promise carries a `cancel` method when the handler's promise did.
|
|
156
|
+
* @property {(args?: {pks?: import('../config/commonCrud.js').Pk[]} & KeepObjectsOption & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success. Omitting `pks` names every row the list holds. On success, the list removes named loaded rows unless `keepObjects` is true. Missing loaded rows are ignored. The promise carries a `cancel` method when the handler's promise did.
|
|
150
157
|
* @property {(args: {action: string, pks?: import('../config/commonCrud.js').Pk[]} & import('../config/listCrud.js').AdditionalListArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string|boolean|null>} executeAction - Initiates an action on all objects in the list, returning the response, or null if the action failed. The promise carries a `cancel` method when the handler's promise did.
|
|
151
158
|
* @property {(info: PaginateInfo) => void} setPaginateInfo - The method to update pagination information.
|
|
152
159
|
* @property {(total: ColumnTotals) => void} setColumnTotals - The method to update column totals.
|
|
@@ -472,6 +479,9 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
472
479
|
loadingError.clearError();
|
|
473
480
|
loadingError.setLoading();
|
|
474
481
|
const isCancelled = ref(false);
|
|
482
|
+
const setCancelled = () => {
|
|
483
|
+
isCancelled.value = true;
|
|
484
|
+
};
|
|
475
485
|
let listPromise = null;
|
|
476
486
|
try {
|
|
477
487
|
const listCrudArgs = {
|
|
@@ -482,6 +492,7 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
482
492
|
pushObjects: self.pushObjects,
|
|
483
493
|
clearObjects: self.clearList,
|
|
484
494
|
isCancelled: readonly(isCancelled),
|
|
495
|
+
setCancelled,
|
|
485
496
|
setPaginateInfo: self.setPaginateInfo,
|
|
486
497
|
setColumnTotals: self.setColumnTotals,
|
|
487
498
|
};
|
|
@@ -495,7 +506,9 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
495
506
|
promises.list = wrapMaybeCancellable(
|
|
496
507
|
listPromise
|
|
497
508
|
.then(() => {
|
|
498
|
-
|
|
509
|
+
// The handler owns the rows on this path, so there is nothing here to withhold. A cancelled
|
|
510
|
+
// run still reports false, matching the rejection a cancelling handler usually produces.
|
|
511
|
+
return !isCancelled.value;
|
|
499
512
|
})
|
|
500
513
|
.catch((/** @type {Error} */ error) => {
|
|
501
514
|
// A deliberate cancellation rejects with the cancel reason; that is not an error.
|
|
@@ -518,7 +531,7 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
518
531
|
);
|
|
519
532
|
return promises.list;
|
|
520
533
|
},
|
|
521
|
-
bulkDelete: ({ pks, ...additionalArgs } = {}) => {
|
|
534
|
+
bulkDelete: ({ pks, keepObjects = false, ...additionalArgs } = {}) => {
|
|
522
535
|
if (state.loading) {
|
|
523
536
|
// we throw because we want devs to see this error in the console
|
|
524
537
|
// state.error should be for user facing errors, or unknown errors
|
|
@@ -530,6 +543,9 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
530
543
|
loadingError.setLoading();
|
|
531
544
|
loadingError.clearError();
|
|
532
545
|
const isCancelled = ref(false);
|
|
546
|
+
const setCancelled = () => {
|
|
547
|
+
isCancelled.value = true;
|
|
548
|
+
};
|
|
533
549
|
let bulkDeletePromise = null;
|
|
534
550
|
try {
|
|
535
551
|
bulkDeletePromise = state.crud.bulkDelete({
|
|
@@ -539,6 +555,7 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
539
555
|
pkKey: state.pkKey,
|
|
540
556
|
params: state.params,
|
|
541
557
|
isCancelled: readonly(isCancelled),
|
|
558
|
+
setCancelled,
|
|
542
559
|
});
|
|
543
560
|
assertHandlerPromise(bulkDeletePromise, ListInstanceError, "bulkDelete");
|
|
544
561
|
} catch (error) {
|
|
@@ -549,9 +566,26 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
549
566
|
return wrapMaybeCancellable(
|
|
550
567
|
bulkDeletePromise
|
|
551
568
|
.then(() => {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
569
|
+
if (isCancelled.value) {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
if (!keepObjects) {
|
|
573
|
+
batchObjectChanges(() => {
|
|
574
|
+
pks.forEach((pk) => {
|
|
575
|
+
try {
|
|
576
|
+
self.deleteListObject(pk);
|
|
577
|
+
} catch (err) {
|
|
578
|
+
// A bulk delete may name rows outside the loaded page, so a pk the list does
|
|
579
|
+
// not hold is expected. The subscription path warns here; this one stays quiet,
|
|
580
|
+
// or every cross-page delete would log.
|
|
581
|
+
if (err.name === "ListInstanceError" && err.code === "missing-object") {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
throw err;
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
}
|
|
555
589
|
loadingError.clearError();
|
|
556
590
|
return true;
|
|
557
591
|
})
|
|
@@ -586,6 +620,9 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
586
620
|
loadingError.setLoading();
|
|
587
621
|
loadingError.clearError();
|
|
588
622
|
const isCancelled = ref(false);
|
|
623
|
+
const setCancelled = () => {
|
|
624
|
+
isCancelled.value = true;
|
|
625
|
+
};
|
|
589
626
|
let executeActionPromise = null;
|
|
590
627
|
try {
|
|
591
628
|
executeActionPromise = state.crud.executeAction({
|
|
@@ -596,6 +633,7 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
596
633
|
pkKey: state.pkKey,
|
|
597
634
|
params: state.params,
|
|
598
635
|
isCancelled: readonly(isCancelled),
|
|
636
|
+
setCancelled,
|
|
599
637
|
});
|
|
600
638
|
assertHandlerPromise(executeActionPromise, ListInstanceError, "executeAction");
|
|
601
639
|
} catch (error) {
|
|
@@ -606,6 +644,9 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
606
644
|
return wrapMaybeCancellable(
|
|
607
645
|
executeActionPromise
|
|
608
646
|
.then((/** @type {object|string} */ responseData) => {
|
|
647
|
+
if (isCancelled.value) {
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
609
650
|
loadingError.clearError();
|
|
610
651
|
return responseData;
|
|
611
652
|
})
|
package/use/listRelated.js
CHANGED
|
@@ -46,7 +46,7 @@ export class ListRelatedError extends Error {
|
|
|
46
46
|
* @typedef {object} ListRelatedRule - The rule for defining relationships for objects in a list.
|
|
47
47
|
* @property {string} [fkKey] - Specifies the foreign key on each row used to link objects across lists. Defaults to
|
|
48
48
|
* the rule's own key when omitted.
|
|
49
|
-
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in
|
|
49
|
+
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
50
50
|
* A rule setting both uses `fkKey`.
|
|
51
51
|
* @property {string[]} [order] - Specifies the order in which related objects should be sorted, if applicable.
|
|
52
52
|
* @property {import('./listInstance.js').ObjectsByPk} objects - The objects that can be related based on the foreign key.
|
package/use/objectInstance.js
CHANGED
|
@@ -76,13 +76,22 @@ import { pkRefIfReactive, refIfReactive } from "../utils/refIfReactive.js";
|
|
|
76
76
|
* @typedef {{[key:string]: any}} AdditionalArgs - Arbitrary extra arguments forwarded through to an object instance's CRUD operations.
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* @typedef {object} KeepObjectOption - Per-call control over whether the instance applies its own result to `state.object`.
|
|
81
|
+
* @property {boolean} [keepObject=false] - When true, the instance leaves `state.object` and `state.deleted` untouched
|
|
82
|
+
* after a successful handler result. The caller reconciles through `clear` or direct state writes. The instance
|
|
83
|
+
* consumes the option before calling the crud handler.
|
|
84
|
+
*
|
|
85
|
+
* Concurrent `retrieve` calls share the first in-flight promise, including that run's `keepObject` setting.
|
|
86
|
+
*/
|
|
87
|
+
|
|
79
88
|
/**
|
|
80
89
|
* @typedef {object} ObjectInstanceMyFunctions - The functions available on the object instance.
|
|
81
|
-
* @property {(args: ObjectInstanceCreateArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} create - Called to turn the current object into a new object on the server.
|
|
82
|
-
* @property {(args?: Partial<import('./cancellableIntent.js').CommonRunTracking> & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} retrieve - Called to retrieve the current object by pk from the server.
|
|
83
|
-
* @property {(args: ObjectInstanceUpdateArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} update - Called to update the current object on the server.
|
|
84
|
-
* @property {(args?: AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} delete - Called to delete the current object on the server.
|
|
85
|
-
* @property {(args: ObjectInstancePatchArgs & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} patch - Called to patch the current object on the server.
|
|
90
|
+
* @property {(args: ObjectInstanceCreateArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} create - Called to turn the current object into a new object on the server.
|
|
91
|
+
* @property {(args?: Partial<import('./cancellableIntent.js').CommonRunTracking> & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} retrieve - Called to retrieve the current object by pk from the server.
|
|
92
|
+
* @property {(args: ObjectInstanceUpdateArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} update - Called to update the current object on the server.
|
|
93
|
+
* @property {(args?: KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} delete - Called to delete the current object on the server.
|
|
94
|
+
* @property {(args: ObjectInstancePatchArgs & KeepObjectOption & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} patch - Called to patch the current object on the server.
|
|
86
95
|
* @property {(args: {action: string} & AdditionalArgs) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string|void|null>} executeAction - Called to execute certain action on the current object. Resolves the handler's own resolved value, or `null` when the action failed.
|
|
87
96
|
* @property {() => void} clear - Called to clear the object state.
|
|
88
97
|
*/
|
|
@@ -258,7 +267,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
258
267
|
/** @type {ObjectInstance} */
|
|
259
268
|
const instance = {
|
|
260
269
|
state,
|
|
261
|
-
create: ({ object, ...additionalArgs }) => {
|
|
270
|
+
create: ({ object, keepObject = false, ...additionalArgs }) => {
|
|
262
271
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
263
272
|
if (state.loading) {
|
|
264
273
|
// we throw because we want devs to see this error in the console
|
|
@@ -268,6 +277,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
268
277
|
loadingError.setLoading();
|
|
269
278
|
loadingError.clearError();
|
|
270
279
|
const isCancelled = ref(false);
|
|
280
|
+
const setCancelled = () => {
|
|
281
|
+
isCancelled.value = true;
|
|
282
|
+
};
|
|
271
283
|
let createPromise = null;
|
|
272
284
|
try {
|
|
273
285
|
createPromise = state.crud.create({
|
|
@@ -277,6 +289,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
277
289
|
params: state.params,
|
|
278
290
|
pkKey: state.pkKey,
|
|
279
291
|
isCancelled: readonly(isCancelled),
|
|
292
|
+
setCancelled,
|
|
280
293
|
});
|
|
281
294
|
assertHandlerPromise(createPromise, ObjectError, "create");
|
|
282
295
|
} catch (error) {
|
|
@@ -288,8 +301,13 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
288
301
|
return wrapMaybeCancellable(
|
|
289
302
|
createPromise
|
|
290
303
|
.then((/** @type {ExistingCrudObject} */ object) => {
|
|
291
|
-
|
|
292
|
-
|
|
304
|
+
if (isCancelled.value) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (!keepObject) {
|
|
308
|
+
assignReactiveObject(state.object, object);
|
|
309
|
+
state.deleted = false;
|
|
310
|
+
}
|
|
293
311
|
return true;
|
|
294
312
|
})
|
|
295
313
|
.catch((/** @type {Error} */ error) => {
|
|
@@ -311,7 +329,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
311
329
|
: undefined
|
|
312
330
|
);
|
|
313
331
|
},
|
|
314
|
-
retrieve: (args = {}) => {
|
|
332
|
+
retrieve: ({ keepObject = false, ...args } = {}) => {
|
|
315
333
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
316
334
|
if (promises.retrieve) {
|
|
317
335
|
// if a retrieve is already in progress, return the existing promise
|
|
@@ -326,6 +344,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
326
344
|
loadingError.setLoading();
|
|
327
345
|
loadingError.clearError();
|
|
328
346
|
const isCancelled = ref(false);
|
|
347
|
+
const setCancelled = () => {
|
|
348
|
+
isCancelled.value = true;
|
|
349
|
+
};
|
|
329
350
|
let retrievePromise = null;
|
|
330
351
|
try {
|
|
331
352
|
retrievePromise = state.crud.retrieve({
|
|
@@ -335,6 +356,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
335
356
|
params: state.params,
|
|
336
357
|
pkKey: state.pkKey,
|
|
337
358
|
isCancelled: readonly(isCancelled),
|
|
359
|
+
setCancelled,
|
|
338
360
|
});
|
|
339
361
|
assertHandlerPromise(retrievePromise, ObjectError, "retrieve");
|
|
340
362
|
} catch (error) {
|
|
@@ -346,8 +368,13 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
346
368
|
promises.retrieve = wrapMaybeCancellable(
|
|
347
369
|
retrievePromise
|
|
348
370
|
.then((/** @type {ExistingCrudObject} */ object) => {
|
|
349
|
-
|
|
350
|
-
|
|
371
|
+
if (isCancelled.value) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (!keepObject) {
|
|
375
|
+
assignReactiveObject(state.object, object);
|
|
376
|
+
state.deleted = false;
|
|
377
|
+
}
|
|
351
378
|
return true;
|
|
352
379
|
})
|
|
353
380
|
.catch((/** @type {Error} */ error) => {
|
|
@@ -372,7 +399,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
372
399
|
|
|
373
400
|
return promises.retrieve;
|
|
374
401
|
},
|
|
375
|
-
update: ({ object, ...additionalArgs }) => {
|
|
402
|
+
update: ({ object, keepObject = false, ...additionalArgs }) => {
|
|
376
403
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
377
404
|
if (state.loading) {
|
|
378
405
|
// we throw because we want devs to see this error in the console
|
|
@@ -382,6 +409,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
382
409
|
loadingError.setLoading();
|
|
383
410
|
loadingError.clearError();
|
|
384
411
|
const isCancelled = ref(false);
|
|
412
|
+
const setCancelled = () => {
|
|
413
|
+
isCancelled.value = true;
|
|
414
|
+
};
|
|
385
415
|
let updatePromise = null;
|
|
386
416
|
try {
|
|
387
417
|
updatePromise = state.crud.update({
|
|
@@ -391,6 +421,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
391
421
|
params: state.params,
|
|
392
422
|
pkKey: state.pkKey,
|
|
393
423
|
isCancelled: readonly(isCancelled),
|
|
424
|
+
setCancelled,
|
|
394
425
|
});
|
|
395
426
|
assertHandlerPromise(updatePromise, ObjectError, "update");
|
|
396
427
|
} catch (error) {
|
|
@@ -401,8 +432,13 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
401
432
|
return wrapMaybeCancellable(
|
|
402
433
|
updatePromise
|
|
403
434
|
.then((/** @type {ExistingCrudObject} */ object) => {
|
|
404
|
-
|
|
405
|
-
|
|
435
|
+
if (isCancelled.value) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
if (!keepObject) {
|
|
439
|
+
assignReactiveObject(state.object, object);
|
|
440
|
+
state.deleted = false;
|
|
441
|
+
}
|
|
406
442
|
return true;
|
|
407
443
|
})
|
|
408
444
|
.catch((/** @type {Error} */ error) => {
|
|
@@ -424,7 +460,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
424
460
|
: undefined
|
|
425
461
|
);
|
|
426
462
|
},
|
|
427
|
-
delete: (args = {}) => {
|
|
463
|
+
delete: ({ keepObject = false, ...args } = {}) => {
|
|
428
464
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
429
465
|
if (state.loading) {
|
|
430
466
|
// we throw because we want devs to see this error in the console
|
|
@@ -434,6 +470,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
434
470
|
loadingError.setLoading();
|
|
435
471
|
loadingError.clearError();
|
|
436
472
|
const isCancelled = ref(false);
|
|
473
|
+
const setCancelled = () => {
|
|
474
|
+
isCancelled.value = true;
|
|
475
|
+
};
|
|
437
476
|
let deletePromise = null;
|
|
438
477
|
try {
|
|
439
478
|
deletePromise = state.crud.delete({
|
|
@@ -442,6 +481,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
442
481
|
pk: state.pk,
|
|
443
482
|
pkKey: state.pkKey,
|
|
444
483
|
isCancelled: readonly(isCancelled),
|
|
484
|
+
setCancelled,
|
|
445
485
|
});
|
|
446
486
|
assertHandlerPromise(deletePromise, ObjectError, "delete");
|
|
447
487
|
} catch (error) {
|
|
@@ -452,8 +492,13 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
452
492
|
return wrapMaybeCancellable(
|
|
453
493
|
deletePromise
|
|
454
494
|
.then(() => {
|
|
455
|
-
|
|
456
|
-
|
|
495
|
+
if (isCancelled.value) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
if (!keepObject) {
|
|
499
|
+
state.deleted = true;
|
|
500
|
+
assignReactiveObject(state.object, {});
|
|
501
|
+
}
|
|
457
502
|
return true;
|
|
458
503
|
})
|
|
459
504
|
.catch((/** @type {Error} */ error) => {
|
|
@@ -475,7 +520,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
475
520
|
: undefined
|
|
476
521
|
);
|
|
477
522
|
},
|
|
478
|
-
patch: ({ partialObject, ...additionalArgs }) => {
|
|
523
|
+
patch: ({ partialObject, keepObject = false, ...additionalArgs }) => {
|
|
479
524
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
480
525
|
if (state.loading) {
|
|
481
526
|
// we throw because we want devs to see this error in the console
|
|
@@ -485,6 +530,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
485
530
|
loadingError.setLoading();
|
|
486
531
|
loadingError.clearError();
|
|
487
532
|
const isCancelled = ref(false);
|
|
533
|
+
const setCancelled = () => {
|
|
534
|
+
isCancelled.value = true;
|
|
535
|
+
};
|
|
488
536
|
let patchPromise = null;
|
|
489
537
|
try {
|
|
490
538
|
patchPromise = state.crud.patch({
|
|
@@ -495,6 +543,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
495
543
|
pkKey: state.pkKey,
|
|
496
544
|
params: state.params,
|
|
497
545
|
isCancelled: readonly(isCancelled),
|
|
546
|
+
setCancelled,
|
|
498
547
|
});
|
|
499
548
|
assertHandlerPromise(patchPromise, ObjectError, "patch");
|
|
500
549
|
} catch (error) {
|
|
@@ -505,8 +554,13 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
505
554
|
return wrapMaybeCancellable(
|
|
506
555
|
patchPromise
|
|
507
556
|
.then((/** @type {ExistingCrudObject} */ object) => {
|
|
508
|
-
|
|
509
|
-
|
|
557
|
+
if (isCancelled.value) {
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
if (!keepObject) {
|
|
561
|
+
assignReactiveObject(state.object, object);
|
|
562
|
+
state.deleted = false;
|
|
563
|
+
}
|
|
510
564
|
return true;
|
|
511
565
|
})
|
|
512
566
|
.catch((/** @type {Error} */ error) => {
|
|
@@ -535,6 +589,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
535
589
|
loadingError.setLoading();
|
|
536
590
|
loadingError.clearError();
|
|
537
591
|
const isCancelled = ref(false);
|
|
592
|
+
const setCancelled = () => {
|
|
593
|
+
isCancelled.value = true;
|
|
594
|
+
};
|
|
538
595
|
let executeActionPromise = null;
|
|
539
596
|
try {
|
|
540
597
|
executeActionPromise = state.crud.executeAction({
|
|
@@ -544,6 +601,7 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
544
601
|
pk: state.pk,
|
|
545
602
|
pkKey: state.pkKey,
|
|
546
603
|
isCancelled: readonly(isCancelled),
|
|
604
|
+
setCancelled,
|
|
547
605
|
});
|
|
548
606
|
assertHandlerPromise(executeActionPromise, ObjectError, "executeAction");
|
|
549
607
|
} catch (error) {
|
|
@@ -555,6 +613,9 @@ export function useObjectInstance({ props, handlers = {} }) {
|
|
|
555
613
|
return wrapMaybeCancellable(
|
|
556
614
|
executeActionPromise
|
|
557
615
|
.then((/** @type {object|string|void} */ responseData) => {
|
|
616
|
+
if (isCancelled.value) {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
558
619
|
return responseData;
|
|
559
620
|
})
|
|
560
621
|
.catch((/** @type {Error} */ error) => {
|
package/use/objectRelated.js
CHANGED
|
@@ -47,7 +47,7 @@ export class ObjectRelatedError extends Error {
|
|
|
47
47
|
* @typedef {object} ObjectRelatedRule - The rule for defining relationships for the managed object to other collections of objects.
|
|
48
48
|
* @property {string} [fkKey] - The foreign key on the managed object that corresponds to the key in the related
|
|
49
49
|
* object. Defaults to the rule's own key when omitted.
|
|
50
|
-
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in
|
|
50
|
+
* @property {string} [pkKey] - Deprecated alias for `fkKey`, removed in v25. The option never named a primary key.
|
|
51
51
|
* A rule setting both uses `fkKey`.
|
|
52
52
|
* @property {import('./listInstance.js').ObjectsByPk} objects - The related objects, indexed by the key in the related object.
|
|
53
53
|
* @property {string[]} [order] - The order of the related objects, if the related objects are an array.
|
|
@@ -78,7 +78,7 @@ export function warnDeprecatedRulePkKey(composableName, ruleKey, rule, warned) {
|
|
|
78
78
|
warned.add(ruleKey);
|
|
79
79
|
const bothNames = rule.fkKey !== undefined ? ` This rule sets both, and "fkKey" is the one used.` : "";
|
|
80
80
|
console.warn(
|
|
81
|
-
`[${composableName}] Rule "${ruleKey}" uses "pkKey", which is deprecated and will be removed in
|
|
81
|
+
`[${composableName}] Rule "${ruleKey}" uses "pkKey", which is deprecated and will be removed in v25. Rename it to "fkKey", which is what the option has always meant.${bothNames}`
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
|