@arrai-innovations/reactive-helpers 18.0.1 → 18.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.
Files changed (236) hide show
  1. package/config/listCrud.js +1 -1
  2. package/config/objectCrud.js +129 -47
  3. package/index.js +3 -0
  4. package/package.json +16 -1
  5. package/types/config/listCrud.d.ts +153 -0
  6. package/types/config/listCrud.d.ts.map +1 -0
  7. package/types/config/objectCrud.d.ts +237 -0
  8. package/types/config/objectCrud.d.ts.map +1 -0
  9. package/types/index.d.ts +40 -0
  10. package/types/index.d.ts.map +1 -0
  11. package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
  12. package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
  13. package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
  14. package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
  15. package/types/tests/unit/crudPromise.d.ts +25 -0
  16. package/types/tests/unit/crudPromise.d.ts.map +1 -0
  17. package/types/tests/unit/expectHelpers.d.ts +2 -0
  18. package/types/tests/unit/expectHelpers.d.ts.map +1 -0
  19. package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
  20. package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
  21. package/types/tests/unit/poll.d.ts +2 -0
  22. package/types/tests/unit/poll.d.ts.map +1 -0
  23. package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
  24. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
  25. package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
  26. package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
  27. package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
  28. package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
  29. package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
  30. package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
  31. package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
  32. package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
  33. package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
  34. package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
  35. package/types/tests/unit/use/listSort.spec.d.ts +2 -0
  36. package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
  37. package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
  38. package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
  39. package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
  40. package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
  41. package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
  42. package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
  43. package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
  44. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
  45. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
  46. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
  47. package/types/tests/unit/use/search.spec.d.ts +2 -0
  48. package/types/tests/unit/use/search.spec.d.ts.map +1 -0
  49. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
  50. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
  51. package/types/tests/unit/utils/classes.spec.d.ts +2 -0
  52. package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
  53. package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
  54. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
  55. package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
  56. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
  57. package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
  58. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
  59. package/types/tests/unit/utils/set.spec.d.ts +2 -0
  60. package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
  61. package/types/tests/unit/utils/watches.spec.d.ts +2 -0
  62. package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
  63. package/types/use/cancellableIntent.d.ts +118 -0
  64. package/types/use/cancellableIntent.d.ts.map +1 -0
  65. package/types/use/combineClasses.d.ts +43 -0
  66. package/types/use/combineClasses.d.ts.map +1 -0
  67. package/types/use/list.d.ts +176 -0
  68. package/types/use/list.d.ts.map +1 -0
  69. package/types/use/listCalculated.d.ts +192 -0
  70. package/types/use/listCalculated.d.ts.map +1 -0
  71. package/types/use/listFilter.d.ts +203 -0
  72. package/types/use/listFilter.d.ts.map +1 -0
  73. package/types/use/listInstance.d.ts +357 -0
  74. package/types/use/listInstance.d.ts.map +1 -0
  75. package/types/use/listKeys.d.ts +15 -0
  76. package/types/use/listKeys.d.ts.map +1 -0
  77. package/types/use/listRelated.d.ts +239 -0
  78. package/types/use/listRelated.d.ts.map +1 -0
  79. package/types/use/listSearch.d.ts +298 -0
  80. package/types/use/listSearch.d.ts.map +1 -0
  81. package/types/use/listSort.d.ts +235 -0
  82. package/types/use/listSort.d.ts.map +1 -0
  83. package/types/use/listSubscription.d.ts +218 -0
  84. package/types/use/listSubscription.d.ts.map +1 -0
  85. package/types/use/loadingError.d.ts +105 -0
  86. package/types/use/loadingError.d.ts.map +1 -0
  87. package/types/use/object.d.ts +67 -0
  88. package/types/use/object.d.ts.map +1 -0
  89. package/types/use/objectCalculated.d.ts +215 -0
  90. package/types/use/objectCalculated.d.ts.map +1 -0
  91. package/types/use/objectInstance.d.ts +341 -0
  92. package/types/use/objectInstance.d.ts.map +1 -0
  93. package/types/use/objectRelated.d.ts +264 -0
  94. package/types/use/objectRelated.d.ts.map +1 -0
  95. package/types/use/objectSubscription.d.ts +253 -0
  96. package/types/use/objectSubscription.d.ts.map +1 -0
  97. package/types/use/paginatedListInstance.d.ts +51 -0
  98. package/types/use/paginatedListInstance.d.ts.map +1 -0
  99. package/types/use/proxyLoadingError.d.ts +21 -0
  100. package/types/use/proxyLoadingError.d.ts.map +1 -0
  101. package/types/use/search.d.ts +144 -0
  102. package/types/use/search.d.ts.map +1 -0
  103. package/types/use/watchesRunning.d.ts +63 -0
  104. package/types/use/watchesRunning.d.ts.map +1 -0
  105. package/types/utils/assignReactiveObject.d.ts +115 -0
  106. package/types/utils/assignReactiveObject.d.ts.map +1 -0
  107. package/types/utils/cancellableFetch.d.ts +12 -0
  108. package/types/utils/cancellableFetch.d.ts.map +1 -0
  109. package/types/utils/cancellablePromise.d.ts +40 -0
  110. package/types/utils/cancellablePromise.d.ts.map +1 -0
  111. package/types/utils/classes.d.ts +22 -0
  112. package/types/utils/classes.d.ts.map +1 -0
  113. package/types/utils/compact.d.ts +4 -0
  114. package/types/utils/compact.d.ts.map +1 -0
  115. package/types/utils/deepUnref.d.ts +26 -0
  116. package/types/utils/deepUnref.d.ts.map +1 -0
  117. package/types/utils/deleteKey.d.ts +16 -0
  118. package/types/utils/deleteKey.d.ts.map +1 -0
  119. package/types/utils/flattenPaths.d.ts +23 -0
  120. package/types/utils/flattenPaths.d.ts.map +1 -0
  121. package/types/utils/getFakePk.d.ts +13 -0
  122. package/types/utils/getFakePk.d.ts.map +1 -0
  123. package/types/utils/keepAliveTry.d.ts +15 -0
  124. package/types/utils/keepAliveTry.d.ts.map +1 -0
  125. package/types/utils/keyDiff.d.ts +63 -0
  126. package/types/utils/keyDiff.d.ts.map +1 -0
  127. package/types/utils/loadingCombine.d.ts +9 -0
  128. package/types/utils/loadingCombine.d.ts.map +1 -0
  129. package/types/utils/proxyRunning.d.ts +9 -0
  130. package/types/utils/proxyRunning.d.ts.map +1 -0
  131. package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
  132. package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
  133. package/types/utils/set.d.ts +7 -0
  134. package/types/utils/set.d.ts.map +1 -0
  135. package/types/utils/transformWalk.d.ts +2 -0
  136. package/types/utils/transformWalk.d.ts.map +1 -0
  137. package/types/utils/watches.d.ts +155 -0
  138. package/types/utils/watches.d.ts.map +1 -0
  139. package/use/cancellableIntent.js +8 -13
  140. package/use/listInstance.js +39 -40
  141. package/use/listSearch.js +1 -1
  142. package/use/loadingError.js +30 -6
  143. package/use/objectInstance.js +225 -125
  144. package/use/objectSubscription.js +81 -82
  145. package/use/proxyLoadingError.js +14 -27
  146. package/use/search.js +1 -1
  147. package/utils/cancellableFetch.js +22 -0
  148. package/utils/cancellablePromise.js +70 -0
  149. package/utils/classes.js +5 -5
  150. package/utils/deepUnref.js +28 -0
  151. package/.circleci/config.yml +0 -88
  152. package/.commitlintrc.json +0 -3
  153. package/.editorconfig +0 -5
  154. package/.husky/commit-msg +0 -3
  155. package/.husky/pre-commit +0 -3
  156. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  157. package/.idea/encodings.xml +0 -6
  158. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  159. package/.idea/modules.xml +0 -8
  160. package/.idea/prettier.xml +0 -8
  161. package/.idea/reactive-helpers.iml +0 -15
  162. package/.prettierignore +0 -5
  163. package/.prettierrc.cjs +0 -5
  164. package/.vscode/extensions.json +0 -3
  165. package/docs/README.md +0 -45
  166. package/docs/config/listCrud.md +0 -422
  167. package/docs/config/objectCrud.md +0 -427
  168. package/docs/use/cancellableIntent.md +0 -165
  169. package/docs/use/combineClasses.md +0 -62
  170. package/docs/use/list.md +0 -361
  171. package/docs/use/listCalculated.md +0 -794
  172. package/docs/use/listFilter.md +0 -897
  173. package/docs/use/listInstance.md +0 -559
  174. package/docs/use/listKeys.md +0 -91
  175. package/docs/use/listRelated.md +0 -706
  176. package/docs/use/listSearch.md +0 -903
  177. package/docs/use/listSort.md +0 -1171
  178. package/docs/use/listSubscription.md +0 -393
  179. package/docs/use/loadingError.md +0 -115
  180. package/docs/use/object.md +0 -668
  181. package/docs/use/objectCalculated.md +0 -741
  182. package/docs/use/objectInstance.md +0 -685
  183. package/docs/use/objectRelated.md +0 -723
  184. package/docs/use/objectSubscription.md +0 -538
  185. package/docs/use/paginatedListInstance.md +0 -155
  186. package/docs/use/proxyLoadingError.md +0 -51
  187. package/docs/use/search.md +0 -321
  188. package/docs/use/watchesRunning.md +0 -84
  189. package/docs/utils/assignReactiveObject.md +0 -413
  190. package/docs/utils/classes.md +0 -139
  191. package/docs/utils/compact.md +0 -67
  192. package/docs/utils/deleteKey.md +0 -61
  193. package/docs/utils/flattenPaths.md +0 -53
  194. package/docs/utils/getFakePk.md +0 -39
  195. package/docs/utils/keepAliveTry.md +0 -59
  196. package/docs/utils/keyDiff.md +0 -117
  197. package/docs/utils/loadingCombine.md +0 -30
  198. package/docs/utils/proxyRunning.md +0 -39
  199. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  200. package/docs/utils/set.md +0 -223
  201. package/docs/utils/transformWalk.md +0 -68
  202. package/docs/utils/watches.md +0 -489
  203. package/eslint.config.js +0 -125
  204. package/lint-staged.config.js +0 -10
  205. package/makeTypeDoc.sh +0 -25
  206. package/make_type_doc.js +0 -59
  207. package/tests/unit/config/listCrud.spec.js +0 -114
  208. package/tests/unit/config/objectCrud.spec.js +0 -160
  209. package/tests/unit/crudPromise.js +0 -40
  210. package/tests/unit/expectHelpers.js +0 -6
  211. package/tests/unit/mockOnUnmounted.js +0 -9
  212. package/tests/unit/poll.js +0 -50
  213. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  214. package/tests/unit/use/listCalculated.spec.js +0 -135
  215. package/tests/unit/use/listFilter.spec.js +0 -484
  216. package/tests/unit/use/listInstance.spec.js +0 -1166
  217. package/tests/unit/use/listRelated.spec.js +0 -260
  218. package/tests/unit/use/listSearch.spec.js +0 -586
  219. package/tests/unit/use/listSort.spec.js +0 -418
  220. package/tests/unit/use/listSubscription.spec.js +0 -845
  221. package/tests/unit/use/loadingError.spec.js +0 -43
  222. package/tests/unit/use/objectInstance.spec.js +0 -1525
  223. package/tests/unit/use/objectSubscription.spec.js +0 -849
  224. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  225. package/tests/unit/use/search.spec.js +0 -248
  226. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  227. package/tests/unit/utils/classes.spec.js +0 -427
  228. package/tests/unit/utils/deleteKey.spec.js +0 -265
  229. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  230. package/tests/unit/utils/keyDiff.spec.js +0 -110
  231. package/tests/unit/utils/set.spec.js +0 -81
  232. package/tests/unit/utils/watches.spec.js +0 -276
  233. package/tsconfig.json +0 -19
  234. package/typedoc-local-plugins/customize-output.js +0 -13
  235. package/typedoc.json +0 -11
  236. package/vitest.config.js +0 -11
@@ -86,7 +86,7 @@ const defaultCrud = {
86
86
  */
87
87
 
88
88
  /**
89
- * @typedef {(ExecuteActionFnArgs)=>Promise<import('./objectCrud.js').ResponseData|false> & { cancel: () => Promise<void>|void }} ExecuteActionFn - The function to execute a certain action on a list of items, returning the response data or false.
89
+ * @typedef {(ExecuteActionFnArgs)=>Promise<import('./objectCrud.js').CrudResponse|false> & { cancel: () => Promise<void>|void }} ExecuteActionFn - The function to execute a certain action on a list of items, returning the response data or false.
90
90
  */
91
91
 
92
92
  /**
@@ -1,7 +1,8 @@
1
1
  import { addOrUpdateReactiveObject } from "../utils/assignReactiveObject.js";
2
2
  import cloneDeep from "lodash-es/cloneDeep.js";
3
3
  import isFunction from "lodash-es/isFunction.js";
4
- import { isReactive, toRef } from "vue";
4
+ import { isReactive, readonly, toRef } from "vue";
5
+ import { CancellablePromise } from "../utils/cancellablePromise.js";
5
6
 
6
7
  /**
7
8
  * Configuration for the default object crud functions.
@@ -9,89 +10,160 @@ import { isReactive, toRef } from "vue";
9
10
  * @module config/objectCrud.js
10
11
  */
11
12
 
12
- const defaultCrud = {
13
- args: {},
14
- retrieve: undefined,
15
- create: undefined,
16
- update: undefined,
17
- patch: undefined,
18
- delete: undefined,
19
- subscribe: undefined,
13
+ /**
14
+ * @template T
15
+ * @param {string} name - The name of the method.
16
+ * @returns {(...args:any[]) => import('../utils/cancellablePromise.js')
17
+ * .MaybeCancellablePromise<T>} - A function that returns a rejected promise with an error message.
18
+ */
19
+ const missingMethod = (name) => () => {
20
+ return CancellablePromise.reject(new Error(`Crud method "${name}" is not implemented.`));
21
+ };
22
+
23
+ /**
24
+ * @template T
25
+ * @param {string} name - The name of the method.
26
+ * @returns {(...args:any[]) => import('../utils/cancellablePromise.js')
27
+ * .CancellablePromise<T>} - A function that returns a rejected promise with an error message.
28
+ */
29
+ const requiredCancelMissingMethod = (name) => () => {
30
+ return CancellablePromise(
31
+ new Promise(() => {
32
+ return Promise.reject(new Error(`Crud method "${name}" is not implemented.`));
33
+ }),
34
+ () => {
35
+ // do nothing
36
+ }
37
+ );
20
38
  };
21
39
 
40
+ /**
41
+ * @typedef {{[key:string]: any}} ObjectCrudArgsArgs
42
+ */
43
+
22
44
  /**
23
45
  * Defines the CRUD-related functions and additional utilities provided by the object instance.
24
46
  *
25
47
  * @typedef {object} ObjectCrudArgsProperties
26
- * @property {object} [args={}] - The arguments to be passed to the crud functions.
48
+ * @property {ObjectCrudArgsArgs} args - The arguments to be passed to the crud functions.
49
+ */
50
+
51
+ /**
52
+ * @typedef {object} ObjectCrudArgsOption
53
+ * @property {ObjectCrudArgsArgs} [crudArgs={}] - The arguments to be passed to the crud functions.
27
54
  */
28
55
 
29
56
  /**
30
57
  * @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.
58
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
59
+ * @property {{[key:string]: any}} object - The data to be acted upon.
60
+ * @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
34
61
  * @property {string} pkKey - The key name of the primary key.
62
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
35
63
  */
36
64
 
37
65
  /**
38
66
  * @typedef {object} RetrieveDetailArgs
39
- * @property {object} crudArgs - The arguments to be passed to the crud functions.
67
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
40
68
  * @property {string} pk - The pk of the object to be acted upon.
41
69
  * @property {string} pkKey - The key name of the primary key.
42
- * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
70
+ * @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
71
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
43
72
  */
44
73
 
45
74
  /**
46
75
  * @typedef {object} UpdateDetailArgs
47
- * @property {object} crudArgs - The arguments to be passed to the crud functions.
48
- * @property {import('../use/objectInstance.js').CrudObject} object - The data to be acted upon.
49
- * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
76
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
77
+ * @property {import('../use/objectInstance.js').ExistingCrudObject} object - The data to be acted upon.
78
+ * @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
50
79
  * @property {string} pkKey - The key name of the primary key.
80
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
51
81
  */
52
82
 
53
83
  /**
54
84
  * @typedef {object} DeleteDetailArgs
55
- * @property {object} crudArgs - The arguments to be passed to the crud functions.
85
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
56
86
  * @property {string} pk - The pk of the object to be acted upon.
57
87
  * @property {string} pkKey - The key name of the primary key.
58
- * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
88
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
59
89
  */
60
90
 
61
91
  /**
62
92
  * @typedef {object} PartialDetailArgs
63
- * @property {object} crudArgs - The arguments to be passed to the crud functions.
93
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
64
94
  * @property {string} pk - The pk of the object to be acted upon.
65
95
  * @property {string} pkKey - The key name of the primary key.
66
- * @property {object} partialObject - The data to be acted upon.
67
- * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
96
+ * @property {{[key:string]: any}} partialObject - The data to be acted upon.
97
+ * @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
98
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
99
+ */
100
+
101
+ /**
102
+ * @callback CrudSubscribeCallback
103
+ * @param {import('../use/objectInstance.js').ExistingCrudObject} data - The data to be passed to the callback.
104
+ * @param {string} action - The action that was performed.
68
105
  */
69
106
 
70
107
  /**
71
108
  * @typedef {object} SubscribeArgs
72
- * @property {object} crudArgs - The arguments to be passed to the crud functions.
109
+ * @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
73
110
  * @property {string} pk - The pk of the object to be acted upon.
74
111
  * @property {string} pkKey - The key name of the primary key.
75
- * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
76
- * @property {(
77
- * data:import('../use/objectInstance.js').CrudObject, action:string
78
- * ) => void} callback - The callback to be called when the object is updated.
112
+ * @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
113
+ * @property {CrudSubscribeCallback} callback - The callback to be called when the object is updated.
114
+ * @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
115
+ */
116
+
117
+ /**
118
+ * @typedef {import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string>} CrudResponse
79
119
  */
80
120
 
81
121
  /**
82
- * @typedef {Promise<object|string> & { cancel: () => Promise<void>|void }} ResponseData
122
+ * @callback CrudCreateFn
123
+ * @param {CreateDetailArgs} args - The arguments to be passed to the create function.
124
+ * @returns {CrudResponse} - The response data from the create function.
125
+ */
126
+
127
+ /**
128
+ * @callback CrudRetrieveFn
129
+ * @param {RetrieveDetailArgs} args - The arguments to be passed to the retrieve function.
130
+ * @returns {CrudResponse} - The response data from the retrieve function.
131
+ */
132
+
133
+ /**
134
+ * @callback CrudUpdateFn
135
+ * @param {UpdateDetailArgs} args - The arguments to be passed to the update function.
136
+ * @returns {CrudResponse} - The response data from the update function.
137
+ */
138
+
139
+ /**
140
+ * @callback CrudPatchFn
141
+ * @param {PartialDetailArgs} args - The arguments to be passed to the patch function.
142
+ * @returns {CrudResponse} - The response data from the patch function.
143
+ */
144
+
145
+ /**
146
+ * @callback CrudDeleteFn
147
+ * @param {DeleteDetailArgs} args - The arguments to be passed to the delete function.
148
+ * @returns {CrudResponse} - The response data from the delete function.
149
+ */
150
+
151
+ /**
152
+ * @callback CrudSubscribeFn
153
+ * @param {SubscribeArgs} args - The arguments to be passed to the subscribe function.
154
+ * @returns {import('../utils/cancellablePromise.js').CancellablePromise<void>} - The cancellable promise.
83
155
  */
84
156
 
85
157
  /**
86
158
  * Defines the CRUD-related functions and additional utilities provided by the object instance.
87
159
  *
88
160
  * @typedef {object} ObjectCrudFunctions
89
- * @property {(CreateDetailArgs)=>ResponseData} [create] - A function to be used instead of the default crud create function.
90
- * @property {(RetrieveDetailArgs)=>ResponseData} [retrieve] - A function to be used instead of the default crud retrieve function.
91
- * @property {(UpdateDetailArgs)=>ResponseData} [update] - A function to be used instead of the default crud update function.
92
- * @property {(DeleteDetailArgs)=>ResponseData} [delete] - A function to be used instead of the default crud delete function.
93
- * @property {(PartialDetailArgs)=>ResponseData} [patch] - A function to be used instead of the default crud patch function.
94
- * @property {(SubscribeArgs)=>void & { cancel: () => Promise<void>|void }} [subscribe] - A function to be used instead of the default crud subscribe function.
161
+ * @property {CrudCreateFn} [create] - A function to be used instead of the default crud create function.
162
+ * @property {CrudRetrieveFn} [retrieve] - A function to be used instead of the default crud retrieve function.
163
+ * @property {CrudUpdateFn} [update] - A function to be used instead of the default crud update function.
164
+ * @property {CrudDeleteFn} [delete] - A function to be used instead of the default crud delete function.
165
+ * @property {CrudPatchFn} [patch] - A function to be used instead of the default crud patch function.
166
+ * @property {CrudSubscribeFn} [subscribe] - A function to be used instead of the default crud subscribe function.
95
167
  */
96
168
 
97
169
  /**
@@ -101,6 +173,18 @@ const defaultCrud = {
101
173
  *
102
174
  */
103
175
 
176
+ const _defaultCrud = {
177
+ args: {},
178
+ retrieve: /** @type {CrudRetrieveFn} */ missingMethod("retrieve"),
179
+ create: /** @type {CrudCreateFn} */ missingMethod("create"),
180
+ update: /** @type {CrudUpdateFn} */ missingMethod("update"),
181
+ patch: /** @type {CrudPatchFn} */ missingMethod("patch"),
182
+ delete: /** @type {CrudDeleteFn} */ missingMethod("delete"),
183
+ subscribe: /** @type {CrudSubscribeFn} */ requiredCancelMissingMethod("subscribe"),
184
+ };
185
+
186
+ export const defaultCrud = readonly(_defaultCrud);
187
+
104
188
  /**
105
189
  * Set the object crud functions.
106
190
  *
@@ -108,14 +192,14 @@ const defaultCrud = {
108
192
  * @throws {Error} - if unknown keys are passed.
109
193
  */
110
194
  export const setObjectCrud = ({ retrieve, create, update, patch, delete: deleteFn, subscribe, args = {}, ...rest }) => {
111
- defaultCrud.retrieve = retrieve;
112
- defaultCrud.create = create;
113
- defaultCrud.update = update;
114
- defaultCrud.patch = patch;
115
- defaultCrud.delete = deleteFn;
116
- defaultCrud.subscribe = subscribe;
195
+ _defaultCrud.retrieve = retrieve ?? missingMethod("retrieve");
196
+ _defaultCrud.create = create ?? missingMethod("create");
197
+ _defaultCrud.update = update ?? missingMethod("update");
198
+ _defaultCrud.patch = patch ?? missingMethod("patch");
199
+ _defaultCrud.delete = deleteFn ?? missingMethod("delete");
200
+ _defaultCrud.subscribe = subscribe ?? requiredCancelMissingMethod("subscribe");
117
201
  // defensive cloning
118
- Object.assign(defaultCrud.args, cloneDeep(args));
202
+ Object.assign(_defaultCrud.args, cloneDeep(args));
119
203
  if (Object.keys(rest).length) {
120
204
  throw new Error(`Unknown key(s) passed to setObjectCrud: ${Object.keys(rest).join(", ")}`);
121
205
  }
@@ -124,17 +208,15 @@ export const setObjectCrud = ({ retrieve, create, update, patch, delete: deleteF
124
208
  /**
125
209
  * Get the previously set object crud functions.
126
210
  *
127
- * @param {import("vue").UnwrapNestedRefs<object>} reactiveCrud - The reactive object you want to add the resulting crud to.
211
+ * @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>} reactiveCrud - The reactive object you want to add the resulting crud to.
128
212
  * @param {object} options - The options for the reactive crud object.
129
- * @param {import("vue").UnwrapNestedRefs<{
130
- * crudArgs: ObjectCrudArgsProperties|undefined,
131
- * }>} [options.props] - The props with any passed crudArgs.
213
+ * @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsOption>} [options.props] - The props with any passed crudArgs.
132
214
  * @param {ObjectCrudFunctions} [options.functions] - Any functions to override the default crud functions.
133
215
  * @throws {Error} - If an invalid function is passed, or if the function is not a function.
134
216
  */
135
217
  export const getObjectCrud = (reactiveCrud, { props, functions } = {}) => {
136
218
  // don't mutate the default crud
137
- Object.assign(reactiveCrud, cloneDeep(defaultCrud));
219
+ Object.assign(reactiveCrud, cloneDeep(_defaultCrud));
138
220
  if (props?.crudArgs) {
139
221
  addOrUpdateReactiveObject(reactiveCrud.args, props.crudArgs);
140
222
  }
package/index.js CHANGED
@@ -23,8 +23,11 @@ export * from "./use/proxyLoadingError.js";
23
23
  export * from "./use/search.js";
24
24
  export * from "./use/watchesRunning.js";
25
25
  export * from "./utils/assignReactiveObject.js";
26
+ export * from "./utils/cancellableFetch.js";
27
+ export * from "./utils/cancellablePromise.js";
26
28
  export * from "./utils/classes.js";
27
29
  export * from "./utils/compact.js";
30
+ export * from "./utils/deepUnref.js";
28
31
  export * from "./utils/deleteKey.js";
29
32
  export * from "./utils/flattenPaths.js";
30
33
  export * from "./utils/getFakePk.js";
package/package.json CHANGED
@@ -1,9 +1,24 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "18.0.1",
3
+ "version": "18.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",
7
+ "types": "types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./index.js",
11
+ "types": "./types/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "index.js",
16
+ "README.md",
17
+ "use/",
18
+ "utils/",
19
+ "config/",
20
+ "types/"
21
+ ],
7
22
  "directories": {
8
23
  "use": "use",
9
24
  "utils": "utils",
@@ -0,0 +1,153 @@
1
+ export function setListCrud({ list, bulkDelete, subscribe, executeAction, args, ...rest }: ListCrudFunctions & Partial<ListCrudArgs>): void;
2
+ export function getListCrud(reactiveCrud: import("vue").UnwrapNestedRefs<ListCrudFunctions & ListCrudArgs>, { props, functions }?: {
3
+ props?: import("vue").UnwrapNestedRefs<{
4
+ crudArgs: object | undefined;
5
+ }>;
6
+ functions?: ListCrudFunctions & ListCrudArgs;
7
+ }): void;
8
+ export type PaginateInfo = {
9
+ /**
10
+ * - The total records.
11
+ */
12
+ totalRecords: number;
13
+ /**
14
+ * - The total pages.
15
+ */
16
+ totalPages: number;
17
+ /**
18
+ * - The per page.
19
+ */
20
+ perPage: number;
21
+ };
22
+ export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo: PaginateInfo | undefined) => void;
23
+ export type ListFnArgs = {
24
+ /**
25
+ * - The arguments to be passed to the crud functions.
26
+ */
27
+ crudArgs: object;
28
+ /**
29
+ * - The key name of the primary key.
30
+ */
31
+ pkKey: string;
32
+ /**
33
+ * - The arguments to be passed to the retrieve function.
34
+ */
35
+ retrieveArgs: object;
36
+ /**
37
+ * - The arguments to be passed for list crud functions.
38
+ */
39
+ listArgs: object;
40
+ /**
41
+ * - The method to call with new page(s) of data received.
42
+ */
43
+ pageCallback: PageCallback;
44
+ /**
45
+ * - A ref to a boolean indicating whether the request has
46
+ * been cancelled.
47
+ */
48
+ isCancelled: Readonly<import("vue").Ref<boolean>>;
49
+ };
50
+ export type DeleteFnArgs = {
51
+ /**
52
+ * - The arguments to be passed to the crud functions.
53
+ */
54
+ crudArgs: object;
55
+ /**
56
+ * - The ids of the objects to be deleted.
57
+ */
58
+ pks: string[];
59
+ /**
60
+ * - The key name of the primary key.
61
+ */
62
+ pkKey: string;
63
+ };
64
+ export type SubscriptionEventCallback = (newOrUpdatedOrDeleteObject: import("../use/listInstance.js").ListObject | string, action: "create" | "update" | "delete") => void;
65
+ export type SubscribeFnArgs = {
66
+ /**
67
+ * - The arguments to be passed to the crud functions.
68
+ */
69
+ crudArgs: object;
70
+ /**
71
+ * - The key name of the primary key.
72
+ */
73
+ pkKey: string;
74
+ /**
75
+ * - The arguments to be passed to the retrieve function.
76
+ */
77
+ retrieveArgs: object;
78
+ /**
79
+ * - The arguments to be passed for list crud functions.
80
+ */
81
+ listArgs: object;
82
+ /**
83
+ * - The method to call when new data is received.
84
+ */
85
+ subscriptionEventCallback: SubscriptionEventCallback;
86
+ };
87
+ export type ExecuteActionFnArgs = {
88
+ /**
89
+ * - The arguments to be passed to the crud functions.
90
+ */
91
+ crudArgs: object;
92
+ /**
93
+ * - The ids of the objects to be acted upon.
94
+ */
95
+ pks: string[];
96
+ /**
97
+ * - The key name of the primary key.
98
+ */
99
+ pkKey: string;
100
+ /**
101
+ * - The action to execute.
102
+ */
103
+ action: string;
104
+ };
105
+ /**
106
+ * - The list function to get a list of items, returning a boolean indicating success.
107
+ */
108
+ export type ListFn = (ListFnArgs: any) => Promise<boolean> & {
109
+ cancel: () => Promise<void> | void;
110
+ };
111
+ /**
112
+ * - The delete function to bulk delete a list of items.
113
+ */
114
+ export type BulkDeleteFn = (DeleteFnArgs: any) => Promise<boolean> & {
115
+ cancel: () => Promise<void> | void;
116
+ };
117
+ /**
118
+ * - The subscribe function to set up a subscription to a list of items.
119
+ */
120
+ export type SubscribeFn = (SubscribeFnArgs: any) => Promise<boolean> & {
121
+ cancel: () => Promise<void> | void;
122
+ };
123
+ /**
124
+ * - The function to execute a certain action on a list of items, returning the response data or false.
125
+ */
126
+ export type ExecuteActionFn = (ExecuteActionFnArgs: any) => Promise<import("./objectCrud.js").CrudResponse | false> & {
127
+ cancel: () => Promise<void> | void;
128
+ };
129
+ export type ListCrudFunctions = {
130
+ /**
131
+ * - The list function to get a list of items.
132
+ */
133
+ list?: ListFn;
134
+ /**
135
+ * - The delete function to bulk delete a list of items.
136
+ */
137
+ bulkDelete?: BulkDeleteFn;
138
+ /**
139
+ * - The function to execute a certain action on a list of items.
140
+ */
141
+ executeAction?: ExecuteActionFn;
142
+ /**
143
+ * - The subscribe function to get a subscription to a list of items.
144
+ */
145
+ subscribe?: SubscribeFn;
146
+ };
147
+ export type ListCrudArgs = {
148
+ /**
149
+ * - The default arguments for the crud functions.
150
+ */
151
+ args?: object;
152
+ };
153
+ //# sourceMappingURL=listCrud.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"AA+GO,2FAJI,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,GAEvC,IAAI,CAWhB;AAYM,0CAPI,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,YAAY,CAAC,yBAExE;IAEa,KAAK,GAFV,OAAO,KAAK,EAAE,gBAAgB,CAAC;QACnC,QAAQ,EAAE,MAAM,GAAC,SAAS,CAAC;KAC9B,CAAC;IACiD,SAAS,GAApD,iBAAiB,GAAG,YAAY;CAC1C,QAmBA;;;;;kBAjIa,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM;;2BAIP,CACN,UAAU,EAAC,OAAO,wBAAwB,EAAE,UAAU,EACtD,cAAc,EAAE,YAAY,GAAC,SAAS,KACvC,IAAI;;;;;cAKI,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,MAAM;;;;kBACN,YAAY;;;;;iBACZ,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAMpC,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;wCAIP,CACN,0BAA0B,EAAC,OAAO,wBAAwB,EAAE,UAAU,GAAC,MAAM,EAC7E,MAAM,EAAE,QAAQ,GAAC,QAAQ,GAAC,QAAQ,KACnC,IAAI;;;;;cAKI,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,MAAM;;;;+BACN,yBAAyB;;;;;;cAKzB,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;;;YACN,MAAM;;;;;qBAIP,CAAC,UAAU,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;2BAIrE,CAAC,YAAY,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;0BAIvE,CAAC,eAAe,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;8BAI1E,CAAC,mBAAmB,KAAA,KAAG,OAAO,CAAC,OAAO,iBAAiB,EAAE,YAAY,GAAC,KAAK,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;;WAKlH,MAAM;;;;iBACN,YAAY;;;;oBACZ,eAAe;;;;gBACf,WAAW;;;;;;WAKX,MAAM"}