@arrai-innovations/reactive-helpers 18.0.0 → 18.0.2

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 (216) hide show
  1. package/package.json +20 -6
  2. package/types/config/listCrud.d.ts +153 -0
  3. package/types/config/listCrud.d.ts.map +1 -0
  4. package/types/config/objectCrud.d.ts +171 -0
  5. package/types/config/objectCrud.d.ts.map +1 -0
  6. package/types/index.d.ts +37 -0
  7. package/types/index.d.ts.map +1 -0
  8. package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
  9. package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
  10. package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
  11. package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
  12. package/types/tests/unit/crudPromise.d.ts +25 -0
  13. package/types/tests/unit/crudPromise.d.ts.map +1 -0
  14. package/types/tests/unit/expectHelpers.d.ts +2 -0
  15. package/types/tests/unit/expectHelpers.d.ts.map +1 -0
  16. package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
  17. package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
  18. package/types/tests/unit/poll.d.ts +2 -0
  19. package/types/tests/unit/poll.d.ts.map +1 -0
  20. package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
  21. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
  22. package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
  23. package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
  24. package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
  25. package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
  26. package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
  27. package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
  28. package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
  29. package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
  30. package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
  31. package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
  32. package/types/tests/unit/use/listSort.spec.d.ts +2 -0
  33. package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
  34. package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
  35. package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
  36. package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
  37. package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
  38. package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
  39. package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
  40. package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
  41. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
  42. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
  43. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
  44. package/types/tests/unit/use/search.spec.d.ts +2 -0
  45. package/types/tests/unit/use/search.spec.d.ts.map +1 -0
  46. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
  47. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
  48. package/types/tests/unit/utils/classes.spec.d.ts +2 -0
  49. package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
  50. package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
  51. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
  52. package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
  53. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
  54. package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
  55. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
  56. package/types/tests/unit/utils/set.spec.d.ts +2 -0
  57. package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
  58. package/types/tests/unit/utils/watches.spec.d.ts +2 -0
  59. package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
  60. package/types/use/cancellableIntent.d.ts +129 -0
  61. package/types/use/cancellableIntent.d.ts.map +1 -0
  62. package/types/use/combineClasses.d.ts +43 -0
  63. package/types/use/combineClasses.d.ts.map +1 -0
  64. package/types/use/list.d.ts +176 -0
  65. package/types/use/list.d.ts.map +1 -0
  66. package/types/use/listCalculated.d.ts +192 -0
  67. package/types/use/listCalculated.d.ts.map +1 -0
  68. package/types/use/listFilter.d.ts +203 -0
  69. package/types/use/listFilter.d.ts.map +1 -0
  70. package/types/use/listInstance.d.ts +357 -0
  71. package/types/use/listInstance.d.ts.map +1 -0
  72. package/types/use/listKeys.d.ts +15 -0
  73. package/types/use/listKeys.d.ts.map +1 -0
  74. package/types/use/listRelated.d.ts +239 -0
  75. package/types/use/listRelated.d.ts.map +1 -0
  76. package/types/use/listSearch.d.ts +298 -0
  77. package/types/use/listSearch.d.ts.map +1 -0
  78. package/types/use/listSort.d.ts +235 -0
  79. package/types/use/listSort.d.ts.map +1 -0
  80. package/types/use/listSubscription.d.ts +218 -0
  81. package/types/use/listSubscription.d.ts.map +1 -0
  82. package/types/use/loadingError.d.ts +81 -0
  83. package/types/use/loadingError.d.ts.map +1 -0
  84. package/types/use/object.d.ts +67 -0
  85. package/types/use/object.d.ts.map +1 -0
  86. package/types/use/objectCalculated.d.ts +215 -0
  87. package/types/use/objectCalculated.d.ts.map +1 -0
  88. package/types/use/objectInstance.d.ts +289 -0
  89. package/types/use/objectInstance.d.ts.map +1 -0
  90. package/types/use/objectRelated.d.ts +264 -0
  91. package/types/use/objectRelated.d.ts.map +1 -0
  92. package/types/use/objectSubscription.d.ts +249 -0
  93. package/types/use/objectSubscription.d.ts.map +1 -0
  94. package/types/use/paginatedListInstance.d.ts +51 -0
  95. package/types/use/paginatedListInstance.d.ts.map +1 -0
  96. package/types/use/proxyLoadingError.d.ts +36 -0
  97. package/types/use/proxyLoadingError.d.ts.map +1 -0
  98. package/types/use/search.d.ts +144 -0
  99. package/types/use/search.d.ts.map +1 -0
  100. package/types/use/watchesRunning.d.ts +63 -0
  101. package/types/use/watchesRunning.d.ts.map +1 -0
  102. package/types/utils/assignReactiveObject.d.ts +115 -0
  103. package/types/utils/assignReactiveObject.d.ts.map +1 -0
  104. package/types/utils/classes.d.ts +22 -0
  105. package/types/utils/classes.d.ts.map +1 -0
  106. package/types/utils/compact.d.ts +4 -0
  107. package/types/utils/compact.d.ts.map +1 -0
  108. package/types/utils/deleteKey.d.ts +16 -0
  109. package/types/utils/deleteKey.d.ts.map +1 -0
  110. package/types/utils/flattenPaths.d.ts +23 -0
  111. package/types/utils/flattenPaths.d.ts.map +1 -0
  112. package/types/utils/getFakePk.d.ts +13 -0
  113. package/types/utils/getFakePk.d.ts.map +1 -0
  114. package/types/utils/keepAliveTry.d.ts +15 -0
  115. package/types/utils/keepAliveTry.d.ts.map +1 -0
  116. package/types/utils/keyDiff.d.ts +63 -0
  117. package/types/utils/keyDiff.d.ts.map +1 -0
  118. package/types/utils/loadingCombine.d.ts +9 -0
  119. package/types/utils/loadingCombine.d.ts.map +1 -0
  120. package/types/utils/proxyRunning.d.ts +9 -0
  121. package/types/utils/proxyRunning.d.ts.map +1 -0
  122. package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
  123. package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
  124. package/types/utils/set.d.ts +7 -0
  125. package/types/utils/set.d.ts.map +1 -0
  126. package/types/utils/transformWalk.d.ts +2 -0
  127. package/types/utils/transformWalk.d.ts.map +1 -0
  128. package/types/utils/watches.d.ts +155 -0
  129. package/types/utils/watches.d.ts.map +1 -0
  130. package/use/loadingError.js +1 -1
  131. package/.circleci/config.yml +0 -88
  132. package/.commitlintrc.json +0 -25
  133. package/.editorconfig +0 -5
  134. package/.husky/commit-msg +0 -3
  135. package/.husky/pre-commit +0 -3
  136. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  137. package/.idea/encodings.xml +0 -6
  138. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  139. package/.idea/modules.xml +0 -8
  140. package/.idea/prettier.xml +0 -8
  141. package/.idea/reactive-helpers.iml +0 -15
  142. package/.prettierignore +0 -5
  143. package/.prettierrc.cjs +0 -5
  144. package/.vscode/extensions.json +0 -3
  145. package/docs/README.md +0 -45
  146. package/docs/config/listCrud.md +0 -422
  147. package/docs/config/objectCrud.md +0 -427
  148. package/docs/use/cancellableIntent.md +0 -165
  149. package/docs/use/combineClasses.md +0 -62
  150. package/docs/use/list.md +0 -361
  151. package/docs/use/listCalculated.md +0 -794
  152. package/docs/use/listFilter.md +0 -897
  153. package/docs/use/listInstance.md +0 -559
  154. package/docs/use/listKeys.md +0 -91
  155. package/docs/use/listRelated.md +0 -706
  156. package/docs/use/listSearch.md +0 -903
  157. package/docs/use/listSort.md +0 -1171
  158. package/docs/use/listSubscription.md +0 -393
  159. package/docs/use/loadingError.md +0 -115
  160. package/docs/use/object.md +0 -668
  161. package/docs/use/objectCalculated.md +0 -741
  162. package/docs/use/objectInstance.md +0 -685
  163. package/docs/use/objectRelated.md +0 -723
  164. package/docs/use/objectSubscription.md +0 -538
  165. package/docs/use/paginatedListInstance.md +0 -155
  166. package/docs/use/proxyLoadingError.md +0 -51
  167. package/docs/use/search.md +0 -321
  168. package/docs/use/watchesRunning.md +0 -84
  169. package/docs/utils/assignReactiveObject.md +0 -413
  170. package/docs/utils/classes.md +0 -139
  171. package/docs/utils/compact.md +0 -67
  172. package/docs/utils/deleteKey.md +0 -61
  173. package/docs/utils/flattenPaths.md +0 -53
  174. package/docs/utils/getFakePk.md +0 -39
  175. package/docs/utils/keepAliveTry.md +0 -59
  176. package/docs/utils/keyDiff.md +0 -117
  177. package/docs/utils/loadingCombine.md +0 -30
  178. package/docs/utils/proxyRunning.md +0 -39
  179. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  180. package/docs/utils/set.md +0 -223
  181. package/docs/utils/transformWalk.md +0 -68
  182. package/docs/utils/watches.md +0 -489
  183. package/eslint.config.js +0 -125
  184. package/lint-staged.config.js +0 -10
  185. package/makeTypeDoc.sh +0 -25
  186. package/make_type_doc.js +0 -59
  187. package/tests/unit/config/listCrud.spec.js +0 -114
  188. package/tests/unit/config/objectCrud.spec.js +0 -160
  189. package/tests/unit/crudPromise.js +0 -40
  190. package/tests/unit/expectHelpers.js +0 -6
  191. package/tests/unit/mockOnUnmounted.js +0 -9
  192. package/tests/unit/poll.js +0 -50
  193. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  194. package/tests/unit/use/listCalculated.spec.js +0 -135
  195. package/tests/unit/use/listFilter.spec.js +0 -484
  196. package/tests/unit/use/listInstance.spec.js +0 -1166
  197. package/tests/unit/use/listRelated.spec.js +0 -260
  198. package/tests/unit/use/listSearch.spec.js +0 -586
  199. package/tests/unit/use/listSort.spec.js +0 -418
  200. package/tests/unit/use/listSubscription.spec.js +0 -845
  201. package/tests/unit/use/loadingError.spec.js +0 -43
  202. package/tests/unit/use/objectInstance.spec.js +0 -1525
  203. package/tests/unit/use/objectSubscription.spec.js +0 -849
  204. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  205. package/tests/unit/use/search.spec.js +0 -248
  206. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  207. package/tests/unit/utils/classes.spec.js +0 -427
  208. package/tests/unit/utils/deleteKey.spec.js +0 -265
  209. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  210. package/tests/unit/utils/keyDiff.spec.js +0 -110
  211. package/tests/unit/utils/set.spec.js +0 -81
  212. package/tests/unit/utils/watches.spec.js +0 -276
  213. package/tsconfig.json +0 -19
  214. package/typedoc-local-plugins/customize-output.js +0 -13
  215. package/typedoc.json +0 -11
  216. package/vitest.config.js +0 -11
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Helper function to create multiple object calculateds instances.
3
+ *
4
+ * @param {{
5
+ * [key: string]: ObjectCalculatedOptions
6
+ * }} objectCalculatedArgs - Options for each object calculated to create.
7
+ * @returns {{
8
+ * [key: string]: ObjectCalculated
9
+ * }} - The created object calculated instances by key.
10
+ */
11
+ export function useObjectCalculateds(objectCalculatedArgs: {
12
+ [key: string]: ObjectCalculatedOptions;
13
+ }): {
14
+ [key: string]: ObjectCalculated;
15
+ };
16
+ /**
17
+ * Vue Composition API composable function for object calculated.
18
+ *
19
+ * @example
20
+ * ```vue
21
+ * <script setup>
22
+ * import { useObjectCalculated, useObjectSubscription } from "@arrai-innovations/reactive-helpers";
23
+ * import { ref, reactive } from "vue";
24
+ *
25
+ * const objectSubscriptionProps = reactive({
26
+ * // whatever object subscription props you need to work with your crud implementation
27
+ * crudArgs: {},
28
+ * retrieveArgs: {},
29
+ * pk: '1',
30
+ * pkKey: 'id',
31
+ * intendToRetrieve: true,
32
+ * };
33
+ * const objectSubscription = useObjectSubscription(objectSubscriptionProps);
34
+ * const objectCalculatedProps = reactive({
35
+ * parentState: objectSubscription.state,
36
+ * calculatedObjectRules: {
37
+ * someRule: (object, relatedObject, calculatedObjects) => {
38
+ * // some complex calculation, relatedObjects would be assuming there was a listRelated between the two
39
+ * // calculatedObjects would be the other calculated objects in the list
40
+ * // including yourself, so try not to create circular dependencies
41
+ * // this is used as a computed body.
42
+ * return object.someProperty + object.someOtherProperty;
43
+ * },
44
+ * ...
45
+ * },
46
+ * });
47
+ * </script>
48
+ * <template>
49
+ * <div>
50
+ * <!-- the reactive result of the calculation, based on the fn passed in, turned into a computed -->
51
+ * <p>{{ objectCalculated.state.calculatedObject.someRule }}</p>
52
+ * </div>
53
+ * </template>
54
+ * ```
55
+ *
56
+ * @param {ObjectCalculatedOptions} options - The object calculated options.
57
+ * @returns {ObjectCalculated} - The object calculated instance.
58
+ */
59
+ export function useObjectCalculated({ parentState, calculatedObjectRules }: ObjectCalculatedOptions): ObjectCalculated;
60
+ /**
61
+ * Vue Composition API composable function for object calculated.
62
+ *
63
+ * @module use/objectCalculated.js
64
+ */
65
+ /**
66
+ * The object calculated state keys.
67
+ *
68
+ * @typedef {{
69
+ * [ruleKey: string]: (object: any, relatedObject: any) => any
70
+ * }} ObjectCalculatedRules
71
+ */
72
+ /**
73
+ * @typedef {object} ObjectCalculatedRawState - The raw state for object calculated.
74
+ * @property {ObjectCalculatedRules} calculatedObjectRules - The calculated object rules.
75
+ * @property {{
76
+ * [ruleKey: string]: import('vue').ComputedRef<any>
77
+ * }} calculatedObject - The calculated object.
78
+ * @property {boolean} calculatedObjectWatchRunning - Whether the calculated object watch is running.
79
+ * @property {boolean} parentStateObjectWatchRunning - Whether the parent state object watch is running.
80
+ * @property {boolean} calculatedRunning - Whether the calculated is running.
81
+ * @property {import('vue').Ref<boolean>} running - Whether the object calculated is running.
82
+ */
83
+ /**
84
+ *
85
+ *
86
+ * @typedef {(
87
+ * import('./objectInstance.js').ObjectInstanceRawState &
88
+ * Partial<import('./objectSubscription.js').ObjectSubscriptionRawState> &
89
+ * Partial<import('./objectRelated.js').ObjectRelatedRawState>
90
+ * )} ObjectCalculatedParentRawState
91
+ */
92
+ /**
93
+ *
94
+ *
95
+ * @typedef {import('vue').UnwrapNestedRefs<(
96
+ * ObjectCalculatedParentRawState
97
+ * )>} ObjectCalculatedParentState - The object calculated options.
98
+ */
99
+ /**
100
+ * The state for object calculated.
101
+ *
102
+ * @typedef {import('vue').UnwrapNestedRefs<
103
+ * ObjectCalculatedParentRawState &
104
+ * ObjectCalculatedRawState
105
+ * >} ObjectCalculatedState
106
+ */
107
+ /**
108
+ * The properties for object calculated.
109
+ *
110
+ * @typedef {object} ObjectCalculatedProperties
111
+ * @property {ObjectCalculatedParentState} parentState - The parent state.
112
+ * @property {ObjectCalculatedState} state - The object calculated state.
113
+ * @property {import('./watchesRunning.js').WatchesRunning} watchesRunning - The watches running rules.
114
+ * @property {import('vue').EffectScope} effectScope - The effect scope.
115
+ */
116
+ /**
117
+ * The object calculated instance.
118
+ *
119
+ * @typedef {ObjectCalculatedProperties} ObjectCalculated
120
+ */
121
+ /**
122
+ *
123
+ *
124
+ * @typedef {object} ObjectCalculatedRawProps
125
+ * @property {import('vue').Ref<ObjectCalculatedRules>} calculatedObjectRules - The calculated object rules.
126
+ */
127
+ /**
128
+ *
129
+ * @typedef {({
130
+ * parentState: ObjectCalculatedParentState,
131
+ * } & ObjectCalculatedRawProps)} ObjectCalculatedOptions
132
+ */
133
+ export const objectCalculatedStateKeys: string[];
134
+ export const objectCalculatedFunctions: any[];
135
+ /**
136
+ * The object calculated state keys.
137
+ */
138
+ export type ObjectCalculatedRules = {
139
+ [ruleKey: string]: (object: any, relatedObject: any) => any;
140
+ };
141
+ /**
142
+ * - The raw state for object calculated.
143
+ */
144
+ export type ObjectCalculatedRawState = {
145
+ /**
146
+ * - The calculated object rules.
147
+ */
148
+ calculatedObjectRules: ObjectCalculatedRules;
149
+ /**
150
+ * - The calculated object.
151
+ */
152
+ calculatedObject: {
153
+ [ruleKey: string]: import("vue").ComputedRef<any>;
154
+ };
155
+ /**
156
+ * - Whether the calculated object watch is running.
157
+ */
158
+ calculatedObjectWatchRunning: boolean;
159
+ /**
160
+ * - Whether the parent state object watch is running.
161
+ */
162
+ parentStateObjectWatchRunning: boolean;
163
+ /**
164
+ * - Whether the calculated is running.
165
+ */
166
+ calculatedRunning: boolean;
167
+ /**
168
+ * - Whether the object calculated is running.
169
+ */
170
+ running: import("vue").Ref<boolean>;
171
+ };
172
+ export type ObjectCalculatedParentRawState = (import("./objectInstance.js").ObjectInstanceRawState & Partial<import("./objectSubscription.js").ObjectSubscriptionRawState> & Partial<import("./objectRelated.js").ObjectRelatedRawState>);
173
+ /**
174
+ * - The object calculated options.
175
+ */
176
+ export type ObjectCalculatedParentState = import("vue").UnwrapNestedRefs<(ObjectCalculatedParentRawState)>;
177
+ /**
178
+ * The state for object calculated.
179
+ */
180
+ export type ObjectCalculatedState = import("vue").UnwrapNestedRefs<ObjectCalculatedParentRawState & ObjectCalculatedRawState>;
181
+ /**
182
+ * The properties for object calculated.
183
+ */
184
+ export type ObjectCalculatedProperties = {
185
+ /**
186
+ * - The parent state.
187
+ */
188
+ parentState: ObjectCalculatedParentState;
189
+ /**
190
+ * - The object calculated state.
191
+ */
192
+ state: ObjectCalculatedState;
193
+ /**
194
+ * - The watches running rules.
195
+ */
196
+ watchesRunning: import("./watchesRunning.js").WatchesRunning;
197
+ /**
198
+ * - The effect scope.
199
+ */
200
+ effectScope: import("vue").EffectScope;
201
+ };
202
+ /**
203
+ * The object calculated instance.
204
+ */
205
+ export type ObjectCalculated = ObjectCalculatedProperties;
206
+ export type ObjectCalculatedRawProps = {
207
+ /**
208
+ * - The calculated object rules.
209
+ */
210
+ calculatedObjectRules: import("vue").Ref<ObjectCalculatedRules>;
211
+ };
212
+ export type ObjectCalculatedOptions = ({
213
+ parentState: ObjectCalculatedParentState;
214
+ } & ObjectCalculatedRawProps);
215
+ //# sourceMappingURL=objectCalculated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectCalculated.d.ts","sourceRoot":"","sources":["../../use/objectCalculated.js"],"names":[],"mappings":"AA2GA;;;;;;;;;GASG;AACH,2DAPW;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CACzC,GACS;IACZ,CAAM,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACjC,CAYH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,4EAHW,uBAAuB,GACrB,gBAAgB,CA4G5B;AA3QD;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;;;GAQG;AAEH;;;;;;GAMG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AAIH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AAEH,iDAOE;AAEF,8CAA4C;;;;oCArF/B;IACZ,CAAO,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,KAAK,GAAG,CAAA;CAC9D;;;;;;;;2BAKU,qBAAqB;;;;sBACrB;QACb,CAAO,OAAO,EAAE,MAAM,GAAG,OAAO,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;KACpD;;;;kCACU,OAAO;;;;mCACP,OAAO;;;;uBACP,OAAO;;;;aACP,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;;6CAM3B,CACZ,OAAa,qBAAqB,EAAE,sBAAsB,GACpD,OAAO,CAAC,OAAO,yBAAyB,EAAE,0BAA0B,CAAC,GACrE,OAAO,CAAC,OAAO,oBAAoB,EAAE,qBAAqB,CAAC,CAC9D;;;;0CAMS,OAAO,KAAK,EAAE,gBAAgB,CAAC,CACrC,8BAA8B,CACjC,CAAC;;;;oCAMQ,OAAO,KAAK,EAAE,gBAAgB,CACtC,8BAA8B,GAC9B,wBAAwB,CACzB;;;;;;;;iBAOU,2BAA2B;;;;WAC3B,qBAAqB;;;;oBACrB,OAAO,qBAAqB,EAAE,cAAc;;;;iBAC5C,OAAO,KAAK,EAAE,WAAW;;;;;+BAQ1B,0BAA0B;;;;;2BAOzB,OAAO,KAAK,EAAE,GAAG,CAAC,qBAAqB,CAAC;;sCAKzC,CAAC;IACP,WAAW,EAAE,2BAA2B,CAAC;CAC5C,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Initializes multiple useObjectInstance instances, returning an object of them based on the keys of the instanceArgs.
3
+ *
4
+ * @param {{[key: string]: ObjectInstanceOptions}} instanceArgs - An object of objects to be passed to useObjectInstance.
5
+ * @returns {{[key: string]: ObjectInstance}} - An object of useObjectInstance instances.
6
+ */
7
+ export function useObjectInstances(instanceArgs: {
8
+ [key: string]: ObjectInstanceOptions;
9
+ }): {
10
+ [key: string]: ObjectInstance;
11
+ };
12
+ /**
13
+ * Initializes an object instance to manage CRUD operations. This setup includes reactive state management
14
+ * and functions to perform create, retrieve, update, delete, and patch operations based on provided CRUD
15
+ * configurations and arguments.
16
+ *
17
+ * @example
18
+ * ```vue
19
+ * <script setup>
20
+ * import { useObjectInstance } from "@arrai-innovations/reactive-helpers";
21
+ * import { reactive, toRef } from "vue";
22
+ *
23
+ * const props = defineProps({
24
+ * app: {
25
+ * type: String,
26
+ * required: true,
27
+ * },
28
+ * model: {
29
+ * type: String,
30
+ * required: true,
31
+ * },
32
+ * pk: {
33
+ * type: String,
34
+ * default: '',
35
+ * },
36
+ * });
37
+ *
38
+ * const pkRef = toRef(props, 'pk');
39
+ * const objectInstanceProps = reactive({
40
+ * pk: pkRef,
41
+ * pkKey: 'id',
42
+ * crudArgs: {
43
+ * app: toRef(props, "app"),
44
+ * model: toRef(props, "model"),
45
+ * },
46
+ * retrieveArgs: {},
47
+ * });
48
+ * const objectInstance = useObjectInstance(objectInstanceProps);
49
+ * watch(pkRef, (newValue, oldValue) => {
50
+ * if (newValue !== oldValue && newValue) {
51
+ * objectInstance.retrieve();
52
+ * }
53
+ * });
54
+ * </script>
55
+ * <template>
56
+ * <!-- Display the retrieved object reactively, as a valid pk is provided in props. -->
57
+ * <div>{{ objectInstance.state.object }}</div>
58
+ * </template>
59
+ * ```
60
+ *
61
+ * @param {ObjectInstanceOptions} options - The options to be passed to useObjectInstance.
62
+ * @returns {ObjectInstance} - An object used to manage create, retrieve, update, delete, and patch operations.
63
+ */
64
+ export function useObjectInstance({ props, functions }: ObjectInstanceOptions): ObjectInstance;
65
+ /**
66
+ * A composition function to manage create, retrieve, update, delete, and patch operations.
67
+ *
68
+ * @module use/objectInstance.js
69
+ */
70
+ /**
71
+ * The object being managed by the instance. Empty object is the default.
72
+ *
73
+ * @typedef {{pkKey: string, [key: string]: any}|{}} CrudObject
74
+ */
75
+ /**
76
+ * Arguments to be passed to the object instance.
77
+ *
78
+ * @typedef {object} ObjectInstanceOptions
79
+ * @property {import('vue').UnwrapNestedRefs<ObjectInstanceRawProps>} props - The reactive configuration object.
80
+ * @property {import('../config/objectCrud.js').ObjectCrudFunctions} functions - An object of custom crud functions to use instead of the defaults.
81
+ */
82
+ /**
83
+ * Reactive arguments to be passed to the object instance.
84
+ *
85
+ * @typedef {object} ObjectInstanceRawProps
86
+ * @property {string} [pk] - The pk of the object, optional to support creating new objects.
87
+ * @property {string} pkKey - The pk key of the object.
88
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
89
+ * @property {import('../config/objectCrud.js').ObjectCrudArgs} crudArgs - The arguments to be passed to the crud functions.
90
+ */
91
+ /**
92
+ * The raw state of the object instance.
93
+ *
94
+ * @typedef {object} ObjectInstanceRawState
95
+ * @property {import('../config/objectCrud.js').ObjectCrudArgs} crud - The crud functions.
96
+ * @property {string} pk - The pk of the object.
97
+ * @property {string} pkKey - The pk key of the object.
98
+ * @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
99
+ * @property {CrudObject} object - The object.
100
+ * @property {Readonly<import('vue').Ref<boolean>>} loading - Whether the object is loading.
101
+ * @property {Readonly<import('vue').Ref<boolean>>} errored - Whether the object errored.
102
+ * @property {Readonly<import('vue').Ref<Error|null>>} error - The error.
103
+ * @property {Readonly<import('vue').Ref<boolean>>} deleted - Whether the object is deleted.
104
+ */
105
+ /**
106
+ * Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
107
+ * Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
108
+ *
109
+ * @typedef {import('vue').UnwrapNestedRefs<ObjectInstanceRawState>} ObjectInstanceState
110
+ */
111
+ /**
112
+ * The functions available on the object instance.
113
+ *
114
+ * @typedef {object} ObjectInstanceFunctions
115
+ * @property {(args: { object: object }) => Promise<boolean>} create - Called to turn the current object into a new object on the server.
116
+ * @property {() => Promise<boolean>} retrieve - Called to retrieve the current object by pk from the server.
117
+ * @property {(args: { object: CrudObject }) => Promise<boolean>} update - Called to update the current object on the server.
118
+ * @property {() => Promise<boolean>} delete - Called to delete the current object on the server.
119
+ * @property {(args: { partialObject: CrudObject }) => Promise<boolean>} patch - Called to patch the current object on the server.
120
+ * @property {import('./loadingError.js').ClearErrorFn} clearError - Called to clear the error state.
121
+ * @property {() => void} clear - Called to clear the object state.
122
+ */
123
+ /**
124
+ * The properties of the object instance.
125
+ *
126
+ * @typedef {object} ObjectInstanceProperties
127
+ * @property {ObjectInstanceState} state - The state of the object instance.
128
+ */
129
+ /**
130
+ * The instance of the object instance.
131
+ *
132
+ * @typedef {ObjectInstanceFunctions & ObjectInstanceProperties} ObjectInstance
133
+ */
134
+ /**
135
+ * Represents an error related to CRUD operations on an object instance. This error might be thrown
136
+ * when there are issues such as invalid input, network failures, or permissions issues during CRUD operations.
137
+ */
138
+ export class ObjectError extends Error {
139
+ /**
140
+ * Creates an instance of ObjectError.
141
+ *
142
+ * @param {string} message - The error message.
143
+ * @param {string} code - The error code.
144
+ */
145
+ constructor(message: string, code: string);
146
+ code: string;
147
+ }
148
+ export const objectInstanceStateKeys: string[];
149
+ export const objectInstanceFunctions: string[];
150
+ /**
151
+ * The object being managed by the instance. Empty object is the default.
152
+ */
153
+ export type CrudObject = {
154
+ pkKey: string;
155
+ [key: string]: any;
156
+ } | {};
157
+ /**
158
+ * Arguments to be passed to the object instance.
159
+ */
160
+ export type ObjectInstanceOptions = {
161
+ /**
162
+ * - The reactive configuration object.
163
+ */
164
+ props: import("vue").UnwrapNestedRefs<ObjectInstanceRawProps>;
165
+ /**
166
+ * - An object of custom crud functions to use instead of the defaults.
167
+ */
168
+ functions: import("../config/objectCrud.js").ObjectCrudFunctions;
169
+ };
170
+ /**
171
+ * Reactive arguments to be passed to the object instance.
172
+ */
173
+ export type ObjectInstanceRawProps = {
174
+ /**
175
+ * - The pk of the object, optional to support creating new objects.
176
+ */
177
+ pk?: string;
178
+ /**
179
+ * - The pk key of the object.
180
+ */
181
+ pkKey: string;
182
+ /**
183
+ * - The arguments to be passed to the retrieve function.
184
+ */
185
+ retrieveArgs: object;
186
+ /**
187
+ * - The arguments to be passed to the crud functions.
188
+ */
189
+ crudArgs: import("../config/objectCrud.js").ObjectCrudArgs;
190
+ };
191
+ /**
192
+ * The raw state of the object instance.
193
+ */
194
+ export type ObjectInstanceRawState = {
195
+ /**
196
+ * - The crud functions.
197
+ */
198
+ crud: import("../config/objectCrud.js").ObjectCrudArgs;
199
+ /**
200
+ * - The pk of the object.
201
+ */
202
+ pk: string;
203
+ /**
204
+ * - The pk key of the object.
205
+ */
206
+ pkKey: string;
207
+ /**
208
+ * - The arguments to be passed to the retrieve function.
209
+ */
210
+ retrieveArgs: object;
211
+ /**
212
+ * - The object.
213
+ */
214
+ object: CrudObject;
215
+ /**
216
+ * - Whether the object is loading.
217
+ */
218
+ loading: Readonly<import("vue").Ref<boolean>>;
219
+ /**
220
+ * - Whether the object errored.
221
+ */
222
+ errored: Readonly<import("vue").Ref<boolean>>;
223
+ /**
224
+ * - The error.
225
+ */
226
+ error: Readonly<import("vue").Ref<Error | null>>;
227
+ /**
228
+ * - Whether the object is deleted.
229
+ */
230
+ deleted: Readonly<import("vue").Ref<boolean>>;
231
+ };
232
+ /**
233
+ * Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
234
+ * Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
235
+ */
236
+ export type ObjectInstanceState = import("vue").UnwrapNestedRefs<ObjectInstanceRawState>;
237
+ /**
238
+ * The functions available on the object instance.
239
+ */
240
+ export type ObjectInstanceFunctions = {
241
+ /**
242
+ * - Called to turn the current object into a new object on the server.
243
+ */
244
+ create: (args: {
245
+ object: object;
246
+ }) => Promise<boolean>;
247
+ /**
248
+ * - Called to retrieve the current object by pk from the server.
249
+ */
250
+ retrieve: () => Promise<boolean>;
251
+ /**
252
+ * - Called to update the current object on the server.
253
+ */
254
+ update: (args: {
255
+ object: CrudObject;
256
+ }) => Promise<boolean>;
257
+ /**
258
+ * - Called to delete the current object on the server.
259
+ */
260
+ delete: () => Promise<boolean>;
261
+ /**
262
+ * - Called to patch the current object on the server.
263
+ */
264
+ patch: (args: {
265
+ partialObject: CrudObject;
266
+ }) => Promise<boolean>;
267
+ /**
268
+ * - Called to clear the error state.
269
+ */
270
+ clearError: import("./loadingError.js").ClearErrorFn;
271
+ /**
272
+ * - Called to clear the object state.
273
+ */
274
+ clear: () => void;
275
+ };
276
+ /**
277
+ * The properties of the object instance.
278
+ */
279
+ export type ObjectInstanceProperties = {
280
+ /**
281
+ * - The state of the object instance.
282
+ */
283
+ state: ObjectInstanceState;
284
+ };
285
+ /**
286
+ * The instance of the object instance.
287
+ */
288
+ export type ObjectInstance = ObjectInstanceFunctions & ObjectInstanceProperties;
289
+ //# sourceMappingURL=objectInstance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectInstance.d.ts","sourceRoot":"","sources":["../../use/objectInstance.js"],"names":[],"mappings":"AAmHA;;;;;GAKG;AACH,iDAHW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;CAAC,GACpC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAC,CAS3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wDAHW,qBAAqB,GACnB,cAAc,CAkM1B;AAjXD;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;AAED,+CAUE;AAEF,+CAAkH;;;;yBAnGrG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,GAAC,EAAE;;;;;;;;WAOrC,OAAO,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;;;;eACtD,OAAO,yBAAyB,EAAE,mBAAmB;;;;;;;;;SAOrD,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,OAAO,yBAAyB,EAAE,cAAc;;;;;;;;;UAOhD,OAAO,yBAAyB,EAAE,cAAc;;;;QAChD,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;YACN,UAAU;;;;aACV,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;aACpC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;WACpC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,KAAK,GAAC,IAAI,CAAC,CAAC;;;;aACvC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;kCAOrC,OAAO,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;;;;;;;;YAOrD,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;cAC9C,MAAM,OAAO,CAAC,OAAO,CAAC;;;;YACtB,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;YAClD,MAAM,OAAO,CAAC,OAAO,CAAC;;;;WACtB,CAAC,IAAI,EAAE;QAAE,aAAa,EAAE,UAAU,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;gBACzD,OAAO,mBAAmB,EAAE,YAAY;;;;WACxC,MAAM,IAAI;;;;;;;;;WAOV,mBAAmB;;;;;6BAMpB,uBAAuB,GAAG,wBAAwB"}