@arrai-innovations/reactive-helpers 11.4.2 → 13.0.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.
Files changed (115) hide show
  1. package/.husky/pre-commit +0 -1
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.prettierignore +1 -0
  4. package/README.md +11 -10
  5. package/config/listCrud.js +32 -1
  6. package/config/objectCrud.js +47 -1
  7. package/docs/README.md +43 -0
  8. package/docs/config/listCrud.md +97 -0
  9. package/docs/config/objectCrud.md +123 -0
  10. package/docs/use/cancellableIntent.md +163 -0
  11. package/docs/use/combineClasses.md +52 -0
  12. package/docs/use/list.md +285 -0
  13. package/docs/use/listCalculated.md +773 -0
  14. package/docs/use/listFilter.md +877 -0
  15. package/docs/use/listInstance.md +483 -0
  16. package/docs/use/listKeys.md +91 -0
  17. package/docs/use/listRelated.md +685 -0
  18. package/docs/use/listSearch.md +889 -0
  19. package/docs/use/listSort.md +1144 -0
  20. package/docs/use/listSubscription.md +379 -0
  21. package/docs/use/loadingError.md +21 -0
  22. package/docs/use/object.md +437 -0
  23. package/docs/use/objectCalculated.md +606 -0
  24. package/docs/use/objectInstance.md +486 -0
  25. package/docs/use/objectRelated.md +588 -0
  26. package/docs/use/objectSubscription.md +459 -0
  27. package/docs/use/paginatedListInstance.md +147 -0
  28. package/docs/use/search.md +311 -0
  29. package/docs/use/watchesRunning.md +80 -0
  30. package/docs/utils/assignReactiveObject.md +351 -0
  31. package/docs/utils/classes.md +100 -0
  32. package/docs/utils/compact.md +57 -0
  33. package/docs/utils/deleteKey.md +53 -0
  34. package/docs/utils/flattenPaths.md +45 -0
  35. package/docs/utils/getFakeId.md +34 -0
  36. package/docs/utils/keyDiff.md +101 -0
  37. package/docs/utils/loadingCombine.md +28 -0
  38. package/docs/utils/proxyRunning.md +33 -0
  39. package/docs/utils/relatedCalculatedHelpers.md +75 -0
  40. package/docs/utils/set.md +139 -0
  41. package/docs/utils/transformWalk.md +33 -0
  42. package/docs/utils/watches.md +441 -0
  43. package/eslint.config.js +125 -0
  44. package/index.js +34 -3
  45. package/lint-staged.config.js +5 -1
  46. package/makeTypeDoc.sh +25 -0
  47. package/package.json +27 -19
  48. package/tests/unit/config/listCrud.spec.js +5 -0
  49. package/tests/unit/config/objectCrud.spec.js +5 -0
  50. package/tests/unit/crudPromise.js +22 -3
  51. package/tests/unit/mockOnUnmounted.js +1 -1
  52. package/tests/unit/use/cancellableIntent.spec.js +2 -0
  53. package/tests/unit/use/listCalculated.spec.js +4 -3
  54. package/tests/unit/use/listFilter.spec.js +11 -7
  55. package/tests/unit/use/listInstance.spec.js +32 -14
  56. package/tests/unit/use/listRelated.spec.js +3 -2
  57. package/tests/unit/use/listSearch.spec.js +9 -7
  58. package/tests/unit/use/listSort.spec.js +29 -22
  59. package/tests/unit/use/listSubscription.spec.js +11 -5
  60. package/tests/unit/use/objectInstance.spec.js +15 -2
  61. package/tests/unit/use/objectSubscription.spec.js +31 -16
  62. package/tests/unit/use/search.spec.js +2 -2
  63. package/tests/unit/utils/assignReactiveObject.spec.js +21 -13
  64. package/tests/unit/utils/classes.spec.js +7 -6
  65. package/tests/unit/utils/watches.spec.js +4 -4
  66. package/tsconfig.json +19 -0
  67. package/typedoc-local-plugins/customize-output.js +13 -0
  68. package/typedoc.json +12 -0
  69. package/use/cancellableIntent.js +73 -2
  70. package/use/combineClasses.js +41 -31
  71. package/use/list.js +139 -5
  72. package/use/listCalculated.js +175 -10
  73. package/use/listFilter.js +175 -21
  74. package/use/listInstance.js +215 -94
  75. package/use/listRelated.js +260 -72
  76. package/use/listSearch.js +178 -57
  77. package/use/listSort.js +188 -21
  78. package/use/listSubscription.js +211 -63
  79. package/use/loadingError.js +43 -0
  80. package/use/object.js +187 -23
  81. package/use/objectCalculated.js +168 -16
  82. package/use/objectInstance.js +183 -102
  83. package/use/objectRelated.js +276 -84
  84. package/use/objectSubscription.js +169 -17
  85. package/use/paginatedListInstance.js +30 -1
  86. package/use/search.js +39 -23
  87. package/use/watchesRunning.js +41 -6
  88. package/utils/assignReactiveObject.js +139 -88
  89. package/utils/classes.js +57 -48
  90. package/utils/compact.js +28 -2
  91. package/utils/deleteKey.js +14 -1
  92. package/utils/flattenPaths.js +19 -9
  93. package/utils/getFakeId.js +11 -1
  94. package/utils/keyDiff.js +26 -35
  95. package/utils/loadingCombine.js +7 -4
  96. package/utils/proxyRunning.js +16 -8
  97. package/utils/relatedCalculatedHelpers.js +17 -0
  98. package/utils/set.js +66 -0
  99. package/utils/transformWalk.js +7 -6
  100. package/utils/watches.js +205 -71
  101. package/.eslintignore +0 -2
  102. package/.eslintrc.cjs +0 -25
  103. package/.jsdoc2md.json +0 -4
  104. package/config/index.js +0 -2
  105. package/docs.md +0 -1002
  106. package/jsdoc-to-markdown.sh +0 -16
  107. package/tests/unit/.eslintrc.cjs +0 -11
  108. package/tests/unit/config/index.spec.js +0 -18
  109. package/tests/unit/use/index.spec.js +0 -18
  110. package/tests/unit/utils/index.spec.js +0 -18
  111. package/use/index.js +0 -19
  112. package/utils/debugMessage.js +0 -209
  113. package/utils/debugWatch.js +0 -29
  114. package/utils/index.js +0 -16
  115. package/utils/lifecycleDebug.js +0 -126
@@ -0,0 +1,483 @@
1
+ [**@arrai-innovations/reactive-helpers**](../README.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [@arrai-innovations/reactive-helpers](../README.md) / use/listInstance
6
+
7
+ # use/listInstance
8
+
9
+ ## Classes
10
+
11
+ ### ListInstanceError
12
+
13
+ Defines a custom error class specific to list instance operations, encapsulating details about errors that occur
14
+ during list manipulation and processing.
15
+
16
+ #### Extends
17
+
18
+ - `Error`
19
+
20
+ #### Constructors
21
+
22
+ ##### new ListInstanceError()
23
+
24
+ > **new ListInstanceError**(`message`, `code`): [`ListInstanceError`](listInstance.md#listinstanceerror)
25
+
26
+ Creates an instance of ListInstanceError.
27
+
28
+ ###### Parameters
29
+
30
+ • **message**: `string`
31
+
32
+ The error message.
33
+
34
+ • **code**: `string`
35
+
36
+ The error code.
37
+
38
+ ###### Returns
39
+
40
+ [`ListInstanceError`](listInstance.md#listinstanceerror)
41
+
42
+ ###### Overrides
43
+
44
+ `Error.constructor`
45
+
46
+ #### Properties
47
+
48
+ ##### code
49
+
50
+ > **code**: `string`
51
+
52
+ ##### name
53
+
54
+ > **name**: `string`
55
+
56
+ ###### Inherited from
57
+
58
+ `Error.name`
59
+
60
+ ## Interfaces
61
+
62
+ ### ListInstanceFunctions
63
+
64
+ #### Properties
65
+
66
+ ##### addListObject()
67
+
68
+ > **addListObject**: (`object`) => `void`
69
+
70
+ Adds an object to the list.
71
+
72
+ ###### Parameters
73
+
74
+ • **object**: [`ListObject`](listInstance.md#listobject)
75
+
76
+ ###### Returns
77
+
78
+ `void`
79
+
80
+ ##### clearList()
81
+
82
+ > **clearList**: () => `void`
83
+
84
+ Clears all objects and errors from the list.
85
+
86
+ ###### Returns
87
+
88
+ `void`
89
+
90
+ ##### defaultPageCallback()
91
+
92
+ > **defaultPageCallback**: (`newObjects`) => `void`
93
+
94
+ Handles new or updated objects, respecting the keepOldPages setting.
95
+
96
+ ###### Parameters
97
+
98
+ • **newObjects**: [`ListObject`](listInstance.md#listobject)[]
99
+
100
+ ###### Returns
101
+
102
+ `void`
103
+
104
+ ##### deleteListObject()
105
+
106
+ > **deleteListObject**: (`objectId`) => `void`
107
+
108
+ Deletes an object from the list by ID.
109
+
110
+ ###### Parameters
111
+
112
+ • **objectId**: `string`
113
+
114
+ ###### Returns
115
+
116
+ `void`
117
+
118
+ ##### getFakeId()
119
+
120
+ > **getFakeId**: () => `string`
121
+
122
+ Generates a unique fake ID for use within the list.
123
+
124
+ ###### Returns
125
+
126
+ `string`
127
+
128
+ ##### list()
129
+
130
+ > **list**: () => `Promise`\<`void`\>
131
+
132
+ Initiates a fetch to retrieve objects according to the CRUD configuration.
133
+
134
+ ###### Returns
135
+
136
+ `Promise`\<`void`\>
137
+
138
+ ##### pageCallback()
139
+
140
+ > **pageCallback**: (`newObjects`) => `void`
141
+
142
+ Customizable callback for handling new objects per page.
143
+
144
+ ###### Parameters
145
+
146
+ • **newObjects**: [`ListObject`](listInstance.md#listobject)[]
147
+
148
+ ###### Returns
149
+
150
+ `void`
151
+
152
+ ##### updateListObject()
153
+
154
+ > **updateListObject**: (`object`) => `void`
155
+
156
+ Updates an object in the list.
157
+
158
+ ###### Parameters
159
+
160
+ • **object**: [`ListObject`](listInstance.md#listobject)
161
+
162
+ ###### Returns
163
+
164
+ `void`
165
+
166
+ ***
167
+
168
+ ### ListInstanceOptions
169
+
170
+ #### Properties
171
+
172
+ ##### functions
173
+
174
+ > **functions**: `object`
175
+
176
+ Default implementation are used as set by `setListCrud`.
177
+
178
+ ###### list
179
+
180
+ > **list**: `Function`
181
+
182
+ Provide the implementation for the list function.
183
+
184
+ ##### keepOldPages
185
+
186
+ > **keepOldPages**: `boolean`
187
+
188
+ If true, pages will not be cleared when defaultPageCallback is called.
189
+
190
+ ##### props
191
+
192
+ > **props**: `object`
193
+
194
+ The props for the list instance.
195
+
196
+ ###### crudArgs
197
+
198
+ > **crudArgs**: `any`
199
+
200
+ Implementation specific arguments.
201
+
202
+ ###### listArgs
203
+
204
+ > **listArgs**: `any`
205
+
206
+ The arguments passed to the server.
207
+
208
+ ###### retrieveArgs
209
+
210
+ > **retrieveArgs**: `any`
211
+
212
+ The arguments passed to the server.
213
+
214
+ ***
215
+
216
+ ### ListInstanceProps
217
+
218
+ #### Properties
219
+
220
+ ##### crudArgs
221
+
222
+ > **crudArgs**: `any`
223
+
224
+ Implementation specific arguments.
225
+
226
+ ##### listArgs
227
+
228
+ > **listArgs**: `any`
229
+
230
+ The arguments passed to the server.
231
+
232
+ ##### retrieveArgs
233
+
234
+ > **retrieveArgs**: `any`
235
+
236
+ The arguments passed to the server.
237
+
238
+ ***
239
+
240
+ ### ListInstanceRawState
241
+
242
+ #### Properties
243
+
244
+ ##### crud
245
+
246
+ > **crud**: `object`
247
+
248
+ CRUD functions and their configurations for the list.
249
+
250
+ ###### args
251
+
252
+ > **args**: `any`
253
+
254
+ Arguments for the CRUD functions.
255
+
256
+ ###### list
257
+
258
+ > **list**: `Function`
259
+
260
+ Function to list objects.
261
+
262
+ ##### error
263
+
264
+ > **error**: `Readonly`\<`Ref`\<`Error`\>\>
265
+
266
+ The last error encountered.
267
+
268
+ ##### errored
269
+
270
+ > **errored**: `Readonly`\<`Ref`\<`boolean`\>\>
271
+
272
+ Indicates if an error occurred during the last operation.
273
+
274
+ ##### listArgs
275
+
276
+ > **listArgs**: `any`
277
+
278
+ Arguments passed to the server for listing operations.
279
+
280
+ ##### loading
281
+
282
+ > **loading**: `Readonly`\<`Ref`\<`boolean`\>\>
283
+
284
+ Indicates if the list is currently loading.
285
+
286
+ ##### objects
287
+
288
+ > **objects**: [`ObjectsById`](listInstance.md#objectsbyid)
289
+
290
+ The list objects stored by their IDs.
291
+
292
+ ##### objectsInOrder
293
+
294
+ > **objectsInOrder**: `ComputedRef`\<[`ListObject`](listInstance.md#listobject)[]\>
295
+
296
+ The objects in the order specified by the list.
297
+
298
+ ##### order
299
+
300
+ > **order**: `ComputedRef`\<`string`[]\>
301
+
302
+ The order of objects in the list.
303
+
304
+ ##### retrieveArgs
305
+
306
+ > **retrieveArgs**: `any`
307
+
308
+ Arguments passed to the server for retrieval operations.
309
+
310
+ ##### running
311
+
312
+ > **running**: `boolean`
313
+
314
+ Indicates if there are ongoing reactive updates.
315
+
316
+ ## Type Aliases
317
+
318
+ ### ListInstance
319
+
320
+ > **ListInstance**\<\>: [`ListInstanceStateMixIn`](listInstance.md#listinstancestatemixin) & [`ListInstanceFunctions`](listInstance.md#listinstancefunctions)
321
+
322
+ #### Type Parameters
323
+
324
+ ***
325
+
326
+ ### ListInstanceState
327
+
328
+ > **ListInstanceState**\<\>: `UnwrapNestedRefs`
329
+
330
+ #### Type Parameters
331
+
332
+ ***
333
+
334
+ ### ListInstanceStateMixIn
335
+
336
+ > **ListInstanceStateMixIn**\<\>: `object`
337
+
338
+ #### Type Parameters
339
+
340
+ #### Type declaration
341
+
342
+ ##### state
343
+
344
+ > **state**: [`ListInstanceState`](listInstance.md#listinstancestate)
345
+
346
+ ***
347
+
348
+ ### ListObject
349
+
350
+ > **ListObject**\<\>: `object`
351
+
352
+ #### Type Parameters
353
+
354
+ #### Index Signature
355
+
356
+ \[`key`: `string`\]: `any`
357
+
358
+ #### Type declaration
359
+
360
+ ##### id
361
+
362
+ > **id**: `string`
363
+
364
+ ***
365
+
366
+ ### ListOrder
367
+
368
+ > **ListOrder**\<\>: `ComputedRef`
369
+
370
+ #### Type Parameters
371
+
372
+ ***
373
+
374
+ ### ObjectsById
375
+
376
+ > **ObjectsById**\<\>: `object`
377
+
378
+ #### Type Parameters
379
+
380
+ #### Index Signature
381
+
382
+ \[`key`: `string`\]: [`ListObject`](listInstance.md#listobject)
383
+
384
+ ***
385
+
386
+ ### ObjectsInOrder
387
+
388
+ > **ObjectsInOrder**\<\>: `ComputedRef`
389
+
390
+ #### Type Parameters
391
+
392
+ ## Functions
393
+
394
+ ### useListInstance()
395
+
396
+ > **useListInstance**(`options`): [`ListInstance`](listInstance.md#listinstance)
397
+
398
+ Creates and manages a reactive list of objects, providing utilities to add, update, delete, and fetch objects
399
+ according to the specified CRUD operations.
400
+
401
+ #### Parameters
402
+
403
+ • **options**: [`ListInstanceOptions`](listInstance.md#listinstanceoptions)
404
+
405
+ Specifies the configuration options for creating a list instance, including
406
+ properties for CRUD operations and UI behaviors like page persistence.
407
+
408
+ #### Returns
409
+
410
+ [`ListInstance`](listInstance.md#listinstance)
411
+
412
+ The list instance.
413
+
414
+ #### Example
415
+
416
+ ```vue
417
+ <script setup>
418
+ import { useListInstance } from "@arrai-innovations/reactive-helpers";
419
+ import { reactive, toRef } from "vue";
420
+
421
+ const props = defineProps({
422
+ // whatever props are required for your configured list instance
423
+ someListFilter: {
424
+ type: string,
425
+ default: "",
426
+ },
427
+ });
428
+
429
+ const listInstanceProps = reactive({
430
+ crudArgs: {
431
+ // whatever arguments are required for your configured list crud function to get the right endpoint
432
+ },
433
+ listArgs: {
434
+ // whatever arguments are required for your configured list function to get the right list
435
+ someListFilter: toRef(props, "someListFilter"),
436
+ },
437
+ retrieveArgs: {
438
+ // whatever arguments are required for your configured list function to get items back looking as expected
439
+ },
440
+ });
441
+ const listInstance = useListInstance({ props: listInstanceProps });
442
+ watch(toRef(props, "someListFilter"), (newValue, oldValue) => {
443
+ if (newValue !== oldValue && !isEmpty(newValue)) {
444
+ listInstance.list();
445
+ }
446
+ }, {
447
+ immediate: true,
448
+ deep: true,
449
+ });
450
+ </script>
451
+ <template>
452
+ <ul>
453
+ <!-- reactive list of objects, re-retrieving the list as someListFilter changes. -->
454
+ <li v-for="obj in listInstance.state.objectsInOrder">
455
+ {{ obj }}
456
+ </li>
457
+ </ul>
458
+ </template>
459
+ ```
460
+
461
+ #### Throws
462
+
463
+ If the props are missing.
464
+
465
+ ***
466
+
467
+ ### useListInstances()
468
+
469
+ > **useListInstances**(`listInstanceArgs`): `object`
470
+
471
+ Creates and manages multiple list instances.
472
+
473
+ #### Parameters
474
+
475
+ • **listInstanceArgs**
476
+
477
+ The arguments for each list instance.
478
+
479
+ #### Returns
480
+
481
+ `object`
482
+
483
+ An object of list instances.
@@ -0,0 +1,91 @@
1
+ [**@arrai-innovations/reactive-helpers**](../README.md) • **Docs**
2
+
3
+ ***
4
+
5
+ [@arrai-innovations/reactive-helpers](../README.md) / use/listKeys
6
+
7
+ # use/listKeys
8
+
9
+ ## Variables
10
+
11
+ ### listCalculatedFunctions
12
+
13
+ > `const` **listCalculatedFunctions**: `any`[] = `[]`
14
+
15
+ ***
16
+
17
+ ### listCalculatedStateKeys
18
+
19
+ > `const` **listCalculatedStateKeys**: `string`[]
20
+
21
+ ***
22
+
23
+ ### listFilterFunctions
24
+
25
+ > `const` **listFilterFunctions**: `any`[] = `[]`
26
+
27
+ ***
28
+
29
+ ### listFilterStateKeys
30
+
31
+ > `const` **listFilterStateKeys**: `string`[]
32
+
33
+ ***
34
+
35
+ ### listInstanceFunctions
36
+
37
+ > `const` **listInstanceFunctions**: `string`[]
38
+
39
+ ***
40
+
41
+ ### listInstanceStateKeys
42
+
43
+ > `const` **listInstanceStateKeys**: `string`[]
44
+
45
+ ***
46
+
47
+ ### listRelatedFunctions
48
+
49
+ > `const` **listRelatedFunctions**: `any`[] = `[]`
50
+
51
+ ***
52
+
53
+ ### listRelatedStateKeys
54
+
55
+ > `const` **listRelatedStateKeys**: `string`[]
56
+
57
+ ***
58
+
59
+ ### listSearchFunctions
60
+
61
+ > `const` **listSearchFunctions**: `any`[] = `[]`
62
+
63
+ ***
64
+
65
+ ### listSearchStateKeys
66
+
67
+ > `const` **listSearchStateKeys**: `string`[]
68
+
69
+ ***
70
+
71
+ ### listSortFunctions
72
+
73
+ > `const` **listSortFunctions**: `any`[] = `[]`
74
+
75
+ ***
76
+
77
+ ### listSortStateKeys
78
+
79
+ > `const` **listSortStateKeys**: `string`[]
80
+
81
+ ***
82
+
83
+ ### listSubscriptionFunctions
84
+
85
+ > `const` **listSubscriptionFunctions**: `string`[]
86
+
87
+ ***
88
+
89
+ ### listSubscriptionStateKeys
90
+
91
+ > `const` **listSubscriptionStateKeys**: `string`[]