@arrai-innovations/reactive-helpers 13.0.2 → 13.0.4

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.
@@ -3,16 +3,81 @@ import cloneDeep from "lodash-es/cloneDeep.js";
3
3
  import isFunction from "lodash-es/isFunction.js";
4
4
  import { isReactive, toRef } from "vue";
5
5
 
6
+ /**
7
+ * Configuration for the default list crud functions.
8
+ *
9
+ * @module config/listCrud.js
10
+ */
11
+
6
12
  const defaultCrud = {
7
13
  args: {},
8
14
  list: undefined,
15
+ bulkDelete: undefined,
9
16
  subscribe: undefined,
10
17
  };
11
18
 
19
+ /**
20
+ * @typedef {object} PaginateInfo
21
+ * @property {number} totalRecords - The total records.
22
+ * @property {number} totalPages - The total pages.
23
+ * @property {number} perPage - The per page.
24
+ */
25
+
26
+ /**
27
+ * @typedef {(
28
+ * newObjects:import('../use/listInstance.js').ListObject,
29
+ * paginationInfo: PaginateInfo|undefined
30
+ * )=>void} PageCallback
31
+ */
32
+
33
+ /**
34
+ * @typedef {object} ListFnArgs
35
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
36
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
37
+ * @property {object} listArgs - The arguments to be passed for list crud functions.
38
+ * @property {PageCallback} pageCallback - The method to call with new page(s) of data received.
39
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to a boolean indicating whether the request has
40
+ * been cancelled.
41
+ */
42
+
43
+ /**
44
+ * @typedef {object} DeleteFnArgs
45
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
46
+ * @property {string[]} ids - The ids of the objects to be deleted.
47
+ */
48
+
49
+ /**
50
+ * @typedef {(
51
+ * newOrUpdatedOrDeleteObject:import('../use/listInstance.js').ListObject|string,
52
+ * action: 'create'|'update'|'delete'
53
+ * )=>void} SubscriptionEventCallback
54
+ */
55
+
56
+ /**
57
+ * @typedef {object} SubscribeFnArgs
58
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
59
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
60
+ * @property {object} listArgs - The arguments to be passed for list crud functions.
61
+ * @property {SubscriptionEventCallback} subscriptionEventCallback - The method to call when new data is received.
62
+ */
63
+
64
+ /**
65
+ * @typedef {(ListFnArgs)=>void} ListFn
66
+ */
67
+
68
+ /**
69
+ * @typedef {(DeleteFnArgs)=>void} BulkDeleteFn
70
+ */
71
+
72
+ /**
73
+ * @typedef {(SubscribeFnArgs)=>void} SubscribeFn
74
+ */
75
+
12
76
  /**
13
77
  * @typedef {object} ListCrudFunctions
14
- * @property {Function} [list] - The list function to get a list of items.
15
- * @property {Function} [subscribe] - The subscribe function to get a subscription to a list of items.
78
+ * @property {ListFn} [list] - The list function to get a list of items.
79
+ * @property {BulkDeleteFn} [bulkDelete] - The delete function to bulk delete a list of items.
80
+ * @property {SubscribeFn} [subscribe] - The subscribe function to get a subscription to a list of items.
16
81
  */
17
82
 
18
83
  /**
@@ -27,9 +92,10 @@ const defaultCrud = {
27
92
  * @throws {Error} - If unknown keys are passed.
28
93
  * @returns {void}
29
94
  */
30
- export const setListCrud = ({ list, subscribe, args = {}, ...rest }) => {
95
+ export const setListCrud = ({ list, bulkDelete, subscribe, args = {}, ...rest }) => {
31
96
  defaultCrud.list = list;
32
97
  defaultCrud.subscribe = subscribe;
98
+ defaultCrud.bulkDelete = bulkDelete;
33
99
  Object.assign(defaultCrud.args, cloneDeep(args));
34
100
  if (Object.keys(rest).length) {
35
101
  throw new Error(`Unknown key(s) passed to setListCrud: ${Object.keys(rest).join(", ")}`);
@@ -3,6 +3,12 @@ import cloneDeep from "lodash-es/cloneDeep.js";
3
3
  import isFunction from "lodash-es/isFunction.js";
4
4
  import { isReactive, toRef } from "vue";
5
5
 
6
+ /**
7
+ * Configuration for the default object crud functions.
8
+ *
9
+ * @module config/objectCrud.js
10
+ */
11
+
6
12
  const defaultCrud = {
7
13
  args: {},
8
14
  retrieve: undefined,
@@ -20,16 +26,66 @@ const defaultCrud = {
20
26
  * @property {object} [args={}] - The arguments to be passed to the crud functions.
21
27
  */
22
28
 
29
+ /**
30
+ * @typedef {object} CreateDetailArgs
31
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
32
+ * @property {object} object - The data to be acted upon.
33
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
34
+ */
35
+
36
+ /**
37
+ * @typedef {object} RetrieveDetailArgs
38
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
39
+ * @property {string} id - The id of the object to be acted upon.
40
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
41
+ */
42
+
43
+ /**
44
+ * @typedef {object} UpdateDetailArgs
45
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
46
+ * @property {import('../use/objectInstance.js').CrudObject} object - The data to be acted upon.
47
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
48
+ */
49
+
50
+ /**
51
+ * @typedef {object} DeleteDetailArgs
52
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
53
+ * @property {string} id - The id of the object to be acted upon.
54
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
55
+ */
56
+
57
+ /**
58
+ * @typedef {object} PartialDetailArgs
59
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
60
+ * @property {string} id - The id of the object to be acted upon.
61
+ * @property {object} partialObject - The data to be acted upon.
62
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
63
+ */
64
+
65
+ /**
66
+ * @typedef {object} SubscribeArgs
67
+ * @property {object} crudArgs - The arguments to be passed to the crud functions.
68
+ * @property {string} id - The id of the object to be acted upon.
69
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
70
+ * @property {(
71
+ * data:import('../use/objectInstance.js').CrudObject, action:string
72
+ * ) => void} callback - The callback to be called when the object is updated.
73
+ */
74
+
75
+ /**
76
+ * @typedef {Promise<object|string>} ResponseData
77
+ */
78
+
23
79
  /**
24
80
  * Defines the CRUD-related functions and additional utilities provided by the object instance.
25
81
  *
26
82
  * @typedef {object} ObjectCrudFunctions
27
- * @property {Function} [create] - A function to be used instead of the default crud create function.
28
- * @property {Function} [retrieve] - A function to be used instead of the default crud retrieve function.
29
- * @property {Function} [update] - A function to be used instead of the default crud update function.
30
- * @property {Function} [delete] - A function to be used instead of the default crud delete function.
31
- * @property {Function} [patch] - A function to be used instead of the default crud patch function.
32
- * @property {Function} [subscribe] - A function to be used instead of the default crud subscribe function.
83
+ * @property {(CreateDetailArgs)=>ResponseData} [create] - A function to be used instead of the default crud create function.
84
+ * @property {(RetrieveDetailArgs)=>ResponseData} [retrieve] - A function to be used instead of the default crud retrieve function.
85
+ * @property {(UpdateDetailArgs)=>ResponseData} [update] - A function to be used instead of the default crud update function.
86
+ * @property {(DeleteDetailArgs)=>ResponseData} [delete] - A function to be used instead of the default crud delete function.
87
+ * @property {(PartialDetailArgs)=>ResponseData} [patch] - A function to be used instead of the default crud patch function.
88
+ * @property {(SubscribeArgs)=>void} [subscribe] - A function to be used instead of the default crud subscribe function.
33
89
  */
34
90
 
35
91
  /**
@@ -8,6 +8,24 @@
8
8
 
9
9
  ## Interfaces
10
10
 
11
+ ### DeleteFnArgs
12
+
13
+ #### Properties
14
+
15
+ ##### crudArgs
16
+
17
+ > **crudArgs**: `any`
18
+
19
+ The arguments to be passed to the crud functions.
20
+
21
+ ##### ids
22
+
23
+ > **ids**: `string`[]
24
+
25
+ The ids of the objects to be deleted.
26
+
27
+ ***
28
+
11
29
  ### ListCrudArgs
12
30
 
13
31
  #### Properties
@@ -24,18 +42,199 @@ The default arguments for the crud functions.
24
42
 
25
43
  #### Properties
26
44
 
45
+ ##### bulkDelete
46
+
47
+ > **bulkDelete**: [`BulkDeleteFn`](listCrud.md#bulkdeletefn)
48
+
49
+ The delete function to bulk delete a list of items.
50
+
27
51
  ##### list
28
52
 
29
- > **list**: `Function`
53
+ > **list**: [`ListFn`](listCrud.md#listfn)
30
54
 
31
55
  The list function to get a list of items.
32
56
 
33
57
  ##### subscribe
34
58
 
35
- > **subscribe**: `Function`
59
+ > **subscribe**: [`SubscribeFn`](listCrud.md#subscribefn)
36
60
 
37
61
  The subscribe function to get a subscription to a list of items.
38
62
 
63
+ ***
64
+
65
+ ### ListFnArgs
66
+
67
+ #### Properties
68
+
69
+ ##### crudArgs
70
+
71
+ > **crudArgs**: `any`
72
+
73
+ The arguments to be passed to the crud functions.
74
+
75
+ ##### isCancelled
76
+
77
+ > **isCancelled**: `Readonly`\<`Ref`\<`boolean`\>\>
78
+
79
+ A ref to a boolean indicating whether the request has
80
+ been cancelled.
81
+
82
+ ##### listArgs
83
+
84
+ > **listArgs**: `any`
85
+
86
+ The arguments to be passed for list crud functions.
87
+
88
+ ##### pageCallback
89
+
90
+ > **pageCallback**: [`PageCallback`](listCrud.md#pagecallback-1)
91
+
92
+ The method to call with new page(s) of data received.
93
+
94
+ ##### retrieveArgs
95
+
96
+ > **retrieveArgs**: `any`
97
+
98
+ The arguments to be passed to the retrieve function.
99
+
100
+ ***
101
+
102
+ ### PaginateInfo
103
+
104
+ #### Properties
105
+
106
+ ##### perPage
107
+
108
+ > **perPage**: `number`
109
+
110
+ The per page.
111
+
112
+ ##### totalPages
113
+
114
+ > **totalPages**: `number`
115
+
116
+ The total pages.
117
+
118
+ ##### totalRecords
119
+
120
+ > **totalRecords**: `number`
121
+
122
+ The total records.
123
+
124
+ ***
125
+
126
+ ### SubscribeFnArgs
127
+
128
+ #### Properties
129
+
130
+ ##### crudArgs
131
+
132
+ > **crudArgs**: `any`
133
+
134
+ The arguments to be passed to the crud functions.
135
+
136
+ ##### listArgs
137
+
138
+ > **listArgs**: `any`
139
+
140
+ The arguments to be passed for list crud functions.
141
+
142
+ ##### retrieveArgs
143
+
144
+ > **retrieveArgs**: `any`
145
+
146
+ The arguments to be passed to the retrieve function.
147
+
148
+ ##### subscriptionEventCallback
149
+
150
+ > **subscriptionEventCallback**: [`SubscriptionEventCallback`](listCrud.md#subscriptioneventcallback-1)
151
+
152
+ The method to call when new data is received.
153
+
154
+ ## Type Aliases
155
+
156
+ ### BulkDeleteFn()
157
+
158
+ > **BulkDeleteFn**\<\>: (`DeleteFnArgs`) => `void`
159
+
160
+ #### Type Parameters
161
+
162
+ #### Parameters
163
+
164
+ • **DeleteFnArgs**: `any`
165
+
166
+ #### Returns
167
+
168
+ `void`
169
+
170
+ ***
171
+
172
+ ### ListFn()
173
+
174
+ > **ListFn**\<\>: (`ListFnArgs`) => `void`
175
+
176
+ #### Type Parameters
177
+
178
+ #### Parameters
179
+
180
+ • **ListFnArgs**: `any`
181
+
182
+ #### Returns
183
+
184
+ `void`
185
+
186
+ ***
187
+
188
+ ### PageCallback()
189
+
190
+ > **PageCallback**\<\>: (`newObjects`, `paginationInfo`) => `void`
191
+
192
+ #### Type Parameters
193
+
194
+ #### Parameters
195
+
196
+ • **newObjects**: [`use/listInstance`](../use/listInstance.md)
197
+
198
+ • **paginationInfo**: [`PaginateInfo`](listCrud.md#paginateinfo) \| `undefined`
199
+
200
+ #### Returns
201
+
202
+ `void`
203
+
204
+ ***
205
+
206
+ ### SubscribeFn()
207
+
208
+ > **SubscribeFn**\<\>: (`SubscribeFnArgs`) => `void`
209
+
210
+ #### Type Parameters
211
+
212
+ #### Parameters
213
+
214
+ • **SubscribeFnArgs**: `any`
215
+
216
+ #### Returns
217
+
218
+ `void`
219
+
220
+ ***
221
+
222
+ ### SubscriptionEventCallback()
223
+
224
+ > **SubscriptionEventCallback**\<\>: (`newOrUpdatedOrDeleteObject`, `action`) => `void`
225
+
226
+ #### Type Parameters
227
+
228
+ #### Parameters
229
+
230
+ • **newOrUpdatedOrDeleteObject**: [`use/listInstance`](../use/listInstance.md) \| `string`
231
+
232
+ • **action**: `"create"` \| `"update"` \| `"delete"`
233
+
234
+ #### Returns
235
+
236
+ `void`
237
+
39
238
  ## Functions
40
239
 
41
240
  ### getListCrud()
@@ -54,11 +253,15 @@ The reactive crud object, which will be mutated.
54
253
 
55
254
  The default arguments for the crud functions.
56
255
 
57
- • **reactiveCrud.list**: `Function`
256
+ • **reactiveCrud.bulkDelete**: [`BulkDeleteFn`](listCrud.md#bulkdeletefn)
257
+
258
+ The delete function to bulk delete a list of items.
259
+
260
+ • **reactiveCrud.list**: [`ListFn`](listCrud.md#listfn)
58
261
 
59
262
  The list function to get a list of items.
60
263
 
61
- • **reactiveCrud.subscribe**: `Function`
264
+ • **reactiveCrud.subscribe**: [`SubscribeFn`](listCrud.md#subscribefn)
62
265
 
63
266
  The subscribe function to get a subscription to a list of items.
64
267
 
@@ -8,6 +8,54 @@
8
8
 
9
9
  ## Interfaces
10
10
 
11
+ ### CreateDetailArgs
12
+
13
+ #### Properties
14
+
15
+ ##### crudArgs
16
+
17
+ > **crudArgs**: `any`
18
+
19
+ The arguments to be passed to the crud functions.
20
+
21
+ ##### object
22
+
23
+ > **object**: `any`
24
+
25
+ The data to be acted upon.
26
+
27
+ ##### retrieveArgs
28
+
29
+ > **retrieveArgs**: `any`
30
+
31
+ The arguments to be passed to the retrieve function.
32
+
33
+ ***
34
+
35
+ ### DeleteDetailArgs
36
+
37
+ #### Properties
38
+
39
+ ##### crudArgs
40
+
41
+ > **crudArgs**: `any`
42
+
43
+ The arguments to be passed to the crud functions.
44
+
45
+ ##### id
46
+
47
+ > **id**: `string`
48
+
49
+ The id of the object to be acted upon.
50
+
51
+ ##### retrieveArgs
52
+
53
+ > **retrieveArgs**: `any`
54
+
55
+ The arguments to be passed to the retrieve function.
56
+
57
+ ***
58
+
11
59
  ### ObjectCrudArgsProperties
12
60
 
13
61
  #### Properties
@@ -24,42 +72,208 @@ The arguments to be passed to the crud functions.
24
72
 
25
73
  #### Properties
26
74
 
27
- ##### create
75
+ ##### create()
28
76
 
29
- > **create**: `Function`
77
+ > **create**: (`CreateDetailArgs`) => [`ResponseData`](objectCrud.md#responsedata)
30
78
 
31
79
  A function to be used instead of the default crud create function.
32
80
 
33
- ##### delete
81
+ ###### Parameters
82
+
83
+ • **CreateDetailArgs**: `any`
84
+
85
+ ###### Returns
86
+
87
+ [`ResponseData`](objectCrud.md#responsedata)
88
+
89
+ ##### delete()
34
90
 
35
- > **delete**: `Function`
91
+ > **delete**: (`DeleteDetailArgs`) => [`ResponseData`](objectCrud.md#responsedata)
36
92
 
37
93
  A function to be used instead of the default crud delete function.
38
94
 
39
- ##### patch
95
+ ###### Parameters
40
96
 
41
- > **patch**: `Function`
97
+ **DeleteDetailArgs**: `any`
98
+
99
+ ###### Returns
100
+
101
+ [`ResponseData`](objectCrud.md#responsedata)
102
+
103
+ ##### patch()
104
+
105
+ > **patch**: (`PartialDetailArgs`) => [`ResponseData`](objectCrud.md#responsedata)
42
106
 
43
107
  A function to be used instead of the default crud patch function.
44
108
 
45
- ##### retrieve
109
+ ###### Parameters
110
+
111
+ • **PartialDetailArgs**: `any`
46
112
 
47
- > **retrieve**: `Function`
113
+ ###### Returns
114
+
115
+ [`ResponseData`](objectCrud.md#responsedata)
116
+
117
+ ##### retrieve()
118
+
119
+ > **retrieve**: (`RetrieveDetailArgs`) => [`ResponseData`](objectCrud.md#responsedata)
48
120
 
49
121
  A function to be used instead of the default crud retrieve function.
50
122
 
51
- ##### subscribe
123
+ ###### Parameters
124
+
125
+ • **RetrieveDetailArgs**: `any`
52
126
 
53
- > **subscribe**: `Function`
127
+ ###### Returns
128
+
129
+ [`ResponseData`](objectCrud.md#responsedata)
130
+
131
+ ##### subscribe()
132
+
133
+ > **subscribe**: (`SubscribeArgs`) => `void`
54
134
 
55
135
  A function to be used instead of the default crud subscribe function.
56
136
 
57
- ##### update
137
+ ###### Parameters
138
+
139
+ • **SubscribeArgs**: `any`
140
+
141
+ ###### Returns
142
+
143
+ `void`
144
+
145
+ ##### update()
58
146
 
59
- > **update**: `Function`
147
+ > **update**: (`UpdateDetailArgs`) => [`ResponseData`](objectCrud.md#responsedata)
60
148
 
61
149
  A function to be used instead of the default crud update function.
62
150
 
151
+ ###### Parameters
152
+
153
+ • **UpdateDetailArgs**: `any`
154
+
155
+ ###### Returns
156
+
157
+ [`ResponseData`](objectCrud.md#responsedata)
158
+
159
+ ***
160
+
161
+ ### PartialDetailArgs
162
+
163
+ #### Properties
164
+
165
+ ##### crudArgs
166
+
167
+ > **crudArgs**: `any`
168
+
169
+ The arguments to be passed to the crud functions.
170
+
171
+ ##### id
172
+
173
+ > **id**: `string`
174
+
175
+ The id of the object to be acted upon.
176
+
177
+ ##### partialObject
178
+
179
+ > **partialObject**: `any`
180
+
181
+ The data to be acted upon.
182
+
183
+ ##### retrieveArgs
184
+
185
+ > **retrieveArgs**: `any`
186
+
187
+ The arguments to be passed to the retrieve function.
188
+
189
+ ***
190
+
191
+ ### RetrieveDetailArgs
192
+
193
+ #### Properties
194
+
195
+ ##### crudArgs
196
+
197
+ > **crudArgs**: `any`
198
+
199
+ The arguments to be passed to the crud functions.
200
+
201
+ ##### id
202
+
203
+ > **id**: `string`
204
+
205
+ The id of the object to be acted upon.
206
+
207
+ ##### retrieveArgs
208
+
209
+ > **retrieveArgs**: `any`
210
+
211
+ The arguments to be passed to the retrieve function.
212
+
213
+ ***
214
+
215
+ ### SubscribeArgs
216
+
217
+ #### Properties
218
+
219
+ ##### callback()
220
+
221
+ > **callback**: (`data`, `action`) => `void`
222
+
223
+ The callback to be called when the object is updated.
224
+
225
+ ###### Parameters
226
+
227
+ • **data**: [`CrudObject`](../use/objectInstance.md#crudobject)
228
+
229
+ • **action**: `string`
230
+
231
+ ###### Returns
232
+
233
+ `void`
234
+
235
+ ##### crudArgs
236
+
237
+ > **crudArgs**: `any`
238
+
239
+ The arguments to be passed to the crud functions.
240
+
241
+ ##### id
242
+
243
+ > **id**: `string`
244
+
245
+ The id of the object to be acted upon.
246
+
247
+ ##### retrieveArgs
248
+
249
+ > **retrieveArgs**: `any`
250
+
251
+ The arguments to be passed to the retrieve function.
252
+
253
+ ***
254
+
255
+ ### UpdateDetailArgs
256
+
257
+ #### Properties
258
+
259
+ ##### crudArgs
260
+
261
+ > **crudArgs**: `any`
262
+
263
+ The arguments to be passed to the crud functions.
264
+
265
+ ##### object
266
+
267
+ > **object**: [`CrudObject`](../use/objectInstance.md#crudobject)
268
+
269
+ The data to be acted upon.
270
+
271
+ ##### retrieveArgs
272
+
273
+ > **retrieveArgs**: `any`
274
+
275
+ The arguments to be passed to the retrieve function.
276
+
63
277
  ## Type Aliases
64
278
 
65
279
  ### ObjectCrudArgs
@@ -68,6 +282,14 @@ A function to be used instead of the default crud update function.
68
282
 
69
283
  #### Type Parameters
70
284
 
285
+ ***
286
+
287
+ ### ResponseData
288
+
289
+ > **ResponseData**\<\>: `Promise`\<`object` \| `string`\>
290
+
291
+ #### Type Parameters
292
+
71
293
  ## Functions
72
294
 
73
295
  ### getObjectCrud()