@arrai-innovations/reactive-helpers 18.0.1 → 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 (215) hide show
  1. package/package.json +17 -2
  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/.circleci/config.yml +0 -88
  131. package/.commitlintrc.json +0 -3
  132. package/.editorconfig +0 -5
  133. package/.husky/commit-msg +0 -3
  134. package/.husky/pre-commit +0 -3
  135. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  136. package/.idea/encodings.xml +0 -6
  137. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  138. package/.idea/modules.xml +0 -8
  139. package/.idea/prettier.xml +0 -8
  140. package/.idea/reactive-helpers.iml +0 -15
  141. package/.prettierignore +0 -5
  142. package/.prettierrc.cjs +0 -5
  143. package/.vscode/extensions.json +0 -3
  144. package/docs/README.md +0 -45
  145. package/docs/config/listCrud.md +0 -422
  146. package/docs/config/objectCrud.md +0 -427
  147. package/docs/use/cancellableIntent.md +0 -165
  148. package/docs/use/combineClasses.md +0 -62
  149. package/docs/use/list.md +0 -361
  150. package/docs/use/listCalculated.md +0 -794
  151. package/docs/use/listFilter.md +0 -897
  152. package/docs/use/listInstance.md +0 -559
  153. package/docs/use/listKeys.md +0 -91
  154. package/docs/use/listRelated.md +0 -706
  155. package/docs/use/listSearch.md +0 -903
  156. package/docs/use/listSort.md +0 -1171
  157. package/docs/use/listSubscription.md +0 -393
  158. package/docs/use/loadingError.md +0 -115
  159. package/docs/use/object.md +0 -668
  160. package/docs/use/objectCalculated.md +0 -741
  161. package/docs/use/objectInstance.md +0 -685
  162. package/docs/use/objectRelated.md +0 -723
  163. package/docs/use/objectSubscription.md +0 -538
  164. package/docs/use/paginatedListInstance.md +0 -155
  165. package/docs/use/proxyLoadingError.md +0 -51
  166. package/docs/use/search.md +0 -321
  167. package/docs/use/watchesRunning.md +0 -84
  168. package/docs/utils/assignReactiveObject.md +0 -413
  169. package/docs/utils/classes.md +0 -139
  170. package/docs/utils/compact.md +0 -67
  171. package/docs/utils/deleteKey.md +0 -61
  172. package/docs/utils/flattenPaths.md +0 -53
  173. package/docs/utils/getFakePk.md +0 -39
  174. package/docs/utils/keepAliveTry.md +0 -59
  175. package/docs/utils/keyDiff.md +0 -117
  176. package/docs/utils/loadingCombine.md +0 -30
  177. package/docs/utils/proxyRunning.md +0 -39
  178. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  179. package/docs/utils/set.md +0 -223
  180. package/docs/utils/transformWalk.md +0 -68
  181. package/docs/utils/watches.md +0 -489
  182. package/eslint.config.js +0 -125
  183. package/lint-staged.config.js +0 -10
  184. package/makeTypeDoc.sh +0 -25
  185. package/make_type_doc.js +0 -59
  186. package/tests/unit/config/listCrud.spec.js +0 -114
  187. package/tests/unit/config/objectCrud.spec.js +0 -160
  188. package/tests/unit/crudPromise.js +0 -40
  189. package/tests/unit/expectHelpers.js +0 -6
  190. package/tests/unit/mockOnUnmounted.js +0 -9
  191. package/tests/unit/poll.js +0 -50
  192. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  193. package/tests/unit/use/listCalculated.spec.js +0 -135
  194. package/tests/unit/use/listFilter.spec.js +0 -484
  195. package/tests/unit/use/listInstance.spec.js +0 -1166
  196. package/tests/unit/use/listRelated.spec.js +0 -260
  197. package/tests/unit/use/listSearch.spec.js +0 -586
  198. package/tests/unit/use/listSort.spec.js +0 -418
  199. package/tests/unit/use/listSubscription.spec.js +0 -845
  200. package/tests/unit/use/loadingError.spec.js +0 -43
  201. package/tests/unit/use/objectInstance.spec.js +0 -1525
  202. package/tests/unit/use/objectSubscription.spec.js +0 -849
  203. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  204. package/tests/unit/use/search.spec.js +0 -248
  205. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  206. package/tests/unit/utils/classes.spec.js +0 -427
  207. package/tests/unit/utils/deleteKey.spec.js +0 -265
  208. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  209. package/tests/unit/utils/keyDiff.spec.js +0 -110
  210. package/tests/unit/utils/set.spec.js +0 -81
  211. package/tests/unit/utils/watches.spec.js +0 -276
  212. package/tsconfig.json +0 -19
  213. package/typedoc-local-plugins/customize-output.js +0 -13
  214. package/typedoc.json +0 -11
  215. package/vitest.config.js +0 -11
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @module use/cancellableIntent.js - A composable function for handling cancellable intents.
3
+ */
4
+ /**
5
+ * A Promise that can be cancelled.
6
+ *
7
+ * @typedef {Promise<any> & { cancel: () => Promise<void>|void }} CancellablePromise
8
+ */
9
+ /**
10
+ * @typedef {import("vue").UnwrapNestedRefs<object>} CancellableIntentState - The state of the cancellable intent.
11
+ * @property {number} activeCount - The number of active intents.
12
+ * @property {boolean} active - Whether there are active intents.
13
+ * @property {number} resolvingCount - The number of resolving intents.
14
+ * @property {boolean} resolving - Whether there are resolving intents.
15
+ * @property {boolean} errored - Whether there was an error.
16
+ * @property {Error} error - The error that occurred.
17
+ * @property {boolean} clearActiveOnResolved - Whether to clear the active state when the promise resolves.
18
+ */
19
+ /**
20
+ * @typedef {object} CancellableIntentOptions - The options for the cancellable intent.
21
+ * @property {() => CancellablePromise} awaitableWithCancel - The function that returns a promise that can be cancelled.
22
+ * @property {import("vue").UnwrapNestedRefs<object>} [watchArguments={}] - The reactive object to watch for changes.
23
+ * @property {import("vue").UnwrapNestedRefs<object>} [guardArguments={}] - The reactive object to watch for truthiness before running the intent.
24
+ * @property {boolean} [clearActiveOnResolved=true] - Whether to clear the active state when the promise resolves.
25
+ */
26
+ /**
27
+ * @typedef {object} CancellableIntent - The instance of the cancellable intent.
28
+ * @property {CancellableIntentState} state - The state of the cancellable intent.
29
+ * @property {import('vue').UnwrapNestedRefs<object>} watchArguments - The watch arguments.
30
+ * @property {import('vue').UnwrapNestedRefs<object>} guardArguments - The guard arguments.
31
+ * @property {Function} stop - Stop the cancellable intent.
32
+ * @property {Function} cancel - Cancel the cancellable intent.
33
+ */
34
+ /**
35
+ * Calls your awaitable function with the arguments you pass in when the watch arguments change and are all truthy.
36
+ * Watch arguments should be a reactive object.
37
+ * If the promise is not resolved before the watch arguments change again, the previous promise is cancelled.
38
+ *
39
+ * @example
40
+ * ```vue
41
+ * <script setup>
42
+ * import { useCancellableIntent } from "@vueda/use/cancellableIntent.js";
43
+ * import { ref, computed, onMounted, onUnmounted } from "vue";
44
+ *
45
+ * const myValue = ref(0);
46
+ * const myOtherValue = ref(0);
47
+ *
48
+ * const myIntent = useCancellableIntent({
49
+ * awaitableWithCancel: async () => {
50
+ * await new Promise((resolve) => setTimeout(resolve, 1000));
51
+ * console.log("resolved");
52
+ * return true;
53
+ * },
54
+ * watchArguments: { myValue, myOtherValue },
55
+ * guardArguments: { myValue: computed(() => myValue.value > 0) },
56
+ * clearActiveOnResolved: true,
57
+ * });
58
+ *
59
+ * onMounted(() => {
60
+ * setTimeout(() => {
61
+ * myValue.value = 1;
62
+ * myOtherValue.value = 1;
63
+ * }, 500);
64
+ * });
65
+ *
66
+ * onUnmounted(() => myIntent.stop());
67
+ * </script>
68
+ * ```
69
+ * @param {CancellableIntentOptions} options - The options for the cancellable intent.
70
+ * @returns {CancellableIntent} - The instance of the cancellable intent.
71
+ */
72
+ export function useCancellableIntent({ awaitableWithCancel, watchArguments, guardArguments, clearActiveOnResolved, }: CancellableIntentOptions): CancellableIntent;
73
+ /**
74
+ * A Promise that can be cancelled.
75
+ */
76
+ export type CancellablePromise = Promise<any> & {
77
+ cancel: () => Promise<void> | void;
78
+ };
79
+ /**
80
+ * - The state of the cancellable intent.
81
+ */
82
+ export type CancellableIntentState = import("vue").UnwrapNestedRefs<object>;
83
+ /**
84
+ * - The options for the cancellable intent.
85
+ */
86
+ export type CancellableIntentOptions = {
87
+ /**
88
+ * - The function that returns a promise that can be cancelled.
89
+ */
90
+ awaitableWithCancel: () => CancellablePromise;
91
+ /**
92
+ * - The reactive object to watch for changes.
93
+ */
94
+ watchArguments?: import("vue").UnwrapNestedRefs<object>;
95
+ /**
96
+ * - The reactive object to watch for truthiness before running the intent.
97
+ */
98
+ guardArguments?: import("vue").UnwrapNestedRefs<object>;
99
+ /**
100
+ * - Whether to clear the active state when the promise resolves.
101
+ */
102
+ clearActiveOnResolved?: boolean;
103
+ };
104
+ /**
105
+ * - The instance of the cancellable intent.
106
+ */
107
+ export type CancellableIntent = {
108
+ /**
109
+ * - The state of the cancellable intent.
110
+ */
111
+ state: CancellableIntentState;
112
+ /**
113
+ * - The watch arguments.
114
+ */
115
+ watchArguments: import("vue").UnwrapNestedRefs<object>;
116
+ /**
117
+ * - The guard arguments.
118
+ */
119
+ guardArguments: import("vue").UnwrapNestedRefs<object>;
120
+ /**
121
+ * - Stop the cancellable intent.
122
+ */
123
+ stop: Function;
124
+ /**
125
+ * - Cancel the cancellable intent.
126
+ */
127
+ cancel: Function;
128
+ };
129
+ //# sourceMappingURL=cancellableIntent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancellableIntent.d.ts","sourceRoot":"","sources":["../../use/cancellableIntent.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH;;;;;;GAMG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,sHAHW,wBAAwB,GACtB,iBAAiB,CAwL7B;;;;iCA3PY,OAAO,CAAC,GAAG,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;qCAInD,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;;;;;;;;yBAYrC,MAAM,kBAAkB;;;;qBACxB,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;;;;qBACtC,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;;;;4BACtC,OAAO;;;;;;;;;WAKP,sBAAsB;;;;oBACtB,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;;;;oBACtC,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @typedef {(
3
+ * string |
4
+ * string[] |
5
+ * { [key: string]: boolean | import("vue").Ref<boolean> } |
6
+ * import("vue").Ref<string | string[]>
7
+ * )} CSSClasses
8
+ */
9
+ /**
10
+ * Normalize various ways of specifying CSS classes into an object for use in Vue.js with reactivity. If refs are
11
+ * present, the resulting object will be a ref containing an array of objects to preserve order of operations in
12
+ * reactive contexts.
13
+ *
14
+ * @example
15
+ * ```vue
16
+ * <script setup>
17
+ * import { useCombineClasses } from "@vueda/use/combineClasses.js";
18
+ * import { ref } from "vue";
19
+ * const myClasses = useCombineClasses(
20
+ * "class1",
21
+ * ["class2", "class3"],
22
+ * { class4: true, class5: false },
23
+ * ref("class6"),
24
+ * ref(["class7", "class8"]),
25
+ * ref({ class9: true, class10: false }),
26
+ * );
27
+ * // myClasses.value = [
28
+ * // { class1: true, class2: true, class3: true, class4: true, class5: false },
29
+ * // { class6: true, class7: true, class8: true, class9: true, class10: false }
30
+ * // ]
31
+ * </script>
32
+ * ```
33
+ *
34
+ * @param {...(CSSClasses)} classes - A mixed array containing multiple ways of specifying CSS classes.
35
+ * @returns {import("vue").Ref<import('../utils/classes.js').CombinedClasses>} - A ref
36
+ * containing an object or array of objects containing CSS classes. Arrays are used if refs are present, to
37
+ * preserve order of operations in reactive contexts.
38
+ */
39
+ export function useCombineClasses(...classes: (CSSClasses)[]): import("vue").Ref<import("../utils/classes.js").CombinedClasses>;
40
+ export type CSSClasses = (string | string[] | {
41
+ [key: string]: boolean | import("vue").Ref<boolean>;
42
+ } | import("vue").Ref<string | string[]>);
43
+ //# sourceMappingURL=combineClasses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combineClasses.d.ts","sourceRoot":"","sources":["../../use/combineClasses.js"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,8CALc,CAAC,UAAU,CAAC,EAAA,GACb,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,qBAAqB,EAAE,eAAe,CAAC,CAyB5E;yBA3DY,CACZ,MAAY,GACZ,MAAY,EAAE,GACd;IAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CAAE,GAC7D,OAAa,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CACvC"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Provides a comprehensive Vue 3 composable function for managing a list of objects. This module orchestrates several
3
+ * list-related functionalities including instance creation, subscriptions, relationships, calculations, filtering, searching,
4
+ * and sorting. It's designed to handle complex state management seamlessly in larger applications, ensuring optimal
5
+ * performance and reactivity.
6
+ *
7
+ * @module use/list.js
8
+ */
9
+ /**
10
+ * Custom error class for use list errors.
11
+ */
12
+ export class ListError extends Error {
13
+ /**
14
+ * Creates a new ListError.
15
+ *
16
+ * @param {string} message - The error message.
17
+ * @param {string} code - The error code.
18
+ */
19
+ constructor(message: string, code: string);
20
+ code: string;
21
+ }
22
+ export function useLists(listOptions: {
23
+ [key: string]: ListOptions;
24
+ }): {
25
+ [key: string]: ListManager;
26
+ };
27
+ export function useList({ props, functions, paged, keepOldPages, clearListOnListIntentTriggered, searchThrottle, sortThrottleWait, searchShowAllWhenEmpty, }: ListOptions): ListManager;
28
+ /**
29
+ * Defines properties for configuring the list management system.
30
+ */
31
+ export type ListRawProps = {
32
+ /**
33
+ * - The arguments to pass to the registered list crud functions, related to the list itself.
34
+ */
35
+ listArgs: object;
36
+ /**
37
+ * - The primary key for the list items.
38
+ */
39
+ pkKey: string;
40
+ /**
41
+ * - The arguments to pass to the registered list crud functions, related to the items.
42
+ */
43
+ retrieveArgs: object;
44
+ /**
45
+ * - General arguments to pass to the registered list crud functions, often related to endpoints.
46
+ */
47
+ crudArgs: object;
48
+ /**
49
+ * - Indicates whether the list should be fetched immediately.
50
+ */
51
+ intendToList: boolean;
52
+ /**
53
+ * - Indicates whether changes to the list should be subscribed to.
54
+ */
55
+ intendToSubscribe: boolean;
56
+ /**
57
+ * - Defines rules for associating related objects with list items.
58
+ */
59
+ relatedObjectsRules: import("./listRelated.js").ListRelatedRules;
60
+ /**
61
+ * - Defines rules for dynamically calculating properties of list items.
62
+ */
63
+ calculatedObjectsRules: import("./listCalculated.js").ListCalculatedRules;
64
+ /**
65
+ * - Function or rule to determine if an item should be included based on inclusion criteria.
66
+ */
67
+ allowedFilter: import("./listFilter.js").ListFilterAllowedFilter;
68
+ /**
69
+ * - Function or rule to determine if an item should be excluded based on exclusion criteria.
70
+ */
71
+ excludedFilter: import("./listFilter.js").ListFilterExcludedFilter;
72
+ /**
73
+ * - Defines the properties and conditions used to filter the list via text search.
74
+ */
75
+ textSearchRules: import("./listSearch.js").TextSearchRules;
76
+ /**
77
+ * - Current text query used for filtering the list.
78
+ */
79
+ textSearchValue: string;
80
+ /**
81
+ * - FlexSearch document configuration options for advanced searching capabilities.
82
+ */
83
+ customDocumentOptions: object;
84
+ /**
85
+ * - Additional search options for FlexSearch.
86
+ */
87
+ customSearchOptions: object;
88
+ /**
89
+ * - Sorting rules that define the order of list items.
90
+ */
91
+ orderByRules: import("./listSort.js").OrderByRule[];
92
+ };
93
+ export type ListOptions = {
94
+ /**
95
+ * - The properties for configuring the list.
96
+ */
97
+ props: ListRawProps;
98
+ /**
99
+ * - Additional functions to be included in the list manager.
100
+ */
101
+ functions: import("../config/listCrud.js").ListCrudFunctions;
102
+ /**
103
+ * - Indicates whether the list should be paginated.
104
+ */
105
+ paged: boolean;
106
+ /**
107
+ * - Indicates whether old pages should be kept when paginating.
108
+ */
109
+ keepOldPages: boolean;
110
+ /**
111
+ * - Indicates whether the list should be cleared when the list intent is triggered.
112
+ */
113
+ clearListOnListIntentTriggered: boolean;
114
+ /**
115
+ * - The throttle time for text search.
116
+ */
117
+ searchThrottle: number;
118
+ /**
119
+ * - The throttle time for sorting.
120
+ */
121
+ sortThrottleWait: number;
122
+ /**
123
+ * - Indicates whether all items should be shown when the search query is empty.
124
+ */
125
+ searchShowAllWhenEmpty: boolean;
126
+ };
127
+ /**
128
+ * Represents the combined state definitions for all list-related components.
129
+ * This interface aggregates the raw state from multiple list management functionalities.
130
+ */
131
+ export type ListRawState = (import("./listInstance.js").ListInstanceRawState | import("./listSubscription.js").ListSubscriptionRawState | import("./listRelated.js").ListRelatedRawState | import("./listCalculated.js").ListCalculatedRawState | import("./listFilter.js").ListFilterRawState | import("./listSearch.js").ListSearchRawState | import("./listSort.js").ListSortRawState);
132
+ /**
133
+ * Represents the reactive state derived from aggregating states of various list-related components.
134
+ * This state is typically used within Vue components for reactivity and access to updated list properties.
135
+ */
136
+ export type ListState = import("vue").UnwrapNestedRefs<ListRawState>;
137
+ /**
138
+ * Holds references to instances of all list-related composables, facilitating direct access and management.
139
+ */
140
+ export type ListManaged = {
141
+ listInstance: import("./listInstance.js").ListInstance;
142
+ listSubscription: import("./listSubscription.js").ListSubscription;
143
+ listRelated: import("./listRelated.js").ListRelated;
144
+ listCalculated: import("./listCalculated.js").ListCalculated;
145
+ listFilter: import("./listFilter.js").ListFilter;
146
+ listSearch: import("./listSearch.js").ListSearch;
147
+ listSort: import("./listSort.js").ListSort;
148
+ };
149
+ /**
150
+ * Aggregates all functions provided by various list-related composables, allowing for a unified approach to calling these methods.
151
+ */
152
+ export type ListFunctions = (import("./listInstance.js").ListInstanceFunctions & import("./listSubscription.js").ListSubscriptionFunctions);
153
+ /**
154
+ * Encapsulates properties relevant to the overall management of list-related hooks, including state, direct access to hooks,
155
+ * and scoped effects.
156
+ */
157
+ export type ListManagerProperties = {
158
+ /**
159
+ * - A readonly reference to the managed list hooks.
160
+ */
161
+ managed: ListManaged;
162
+ /**
163
+ * - Represents the final reactive state in the list processing chain.
164
+ */
165
+ state: ListState;
166
+ /**
167
+ * - Encapsulates all reactive effects related to the list hooks.
168
+ */
169
+ effectScope: import("vue").EffectScope;
170
+ };
171
+ /**
172
+ * Combines functionality and properties to represent a fully managed list instance,
173
+ * orchestrating various functionalities such as sorting, searching, filtering, and state management.
174
+ */
175
+ export type ListManager = ListFunctions & ListManagerProperties;
176
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../use/list.js"],"names":[],"mappings":"AAmBA;;;;;;;GAOG;AAEH;;GAEG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;AAiHM,sCAPI;IACV,CAA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U,EAAE,OAAO,iBAAiB,EAAE,UAAU,CAAC;IACjD,UAAU,EAAE,OAAO,iBAAiB,EAAE,UAAU,CAAC;IACjD,QAAQ,EAAE,OAAO,eAAe,EAAE,QAAQ,CAAA;CAC7C;;;;4BAMS,CACZ,OAAa,mBAAmB,EAAE,qBAAqB,GAC/C,OAAO,uBAAuB,EAAE,yBAAyB,CAC9D;;;;;;;;;aAcU,WAAW;;;;WACX,SAAS;;;;iBACT,OAAO,KAAK,EAAE,WAAW;;;;;;0BAO1B,aAAa,GAAG,qBAAqB"}
@@ -0,0 +1,192 @@
1
+ /**
2
+ * The options to create a list calculated composition function.
3
+ *
4
+ * @typedef {object} ListCalculatedOptions - Options to configure the behavior of the list calculated properties.
5
+ * @property {ListCalculatedParentState} parentState - The parent state that interacts with the calculated objects.
6
+ * @property {ListCalculatedRules} calculatedObjectsRules - A reactive reference to rules used for dynamic calculations
7
+ * within list objects. Proper setup of this reference ensures that updates are managed reactively, including deep
8
+ * property changes.
9
+ */
10
+ /**
11
+ * The properties for the list computed composition function.
12
+ *
13
+ * @typedef {object} ListCalculatedProperties
14
+ * @property {ListCalculatedState} state - The state for the list calculated property.
15
+ * @property {ListCalculatedParentState} parentState - The parent state object.
16
+ * @property {import('./watchesRunning.js').WatchesRunning} watchesRunning - The watches running.
17
+ * @property {import('vue').EffectScope} effectScope - The effect scope for the list calculated property.
18
+ */
19
+ /**
20
+ * The instance of `useListCalculated`.
21
+ *
22
+ * @typedef {ListCalculatedProperties} ListCalculated
23
+ */
24
+ /**
25
+ * A composable function to create multiple list calculated objects.
26
+ *
27
+ * @param {{
28
+ * [key: string]: ListCalculatedOptions
29
+ * }} listCalculatedArgs - The arguments for the list calculated objects.
30
+ * @returns {{[key: string]: ListCalculated}} - The list calculated objects.
31
+ */
32
+ export function useListCalculateds(listCalculatedArgs: {
33
+ [key: string]: ListCalculatedOptions;
34
+ }): {
35
+ [key: string]: ListCalculated;
36
+ };
37
+ /**
38
+ * Initializes and manages a calculated properties object for lists. This function sets up reactive states and computations
39
+ * that dynamically update as specified in `calculatedObjectsRules`. It is used to add derived properties to list items,
40
+ * which depend on complex calculations or interactions between multiple objects in the list. These derived properties
41
+ * are reactive and will update in real-time as the underlying data changes, which is essential for maintaining data
42
+ * consistency in dynamic UIs.
43
+ *
44
+ * @example
45
+ * ```vue
46
+ * <script setup>
47
+ * import { useListSubscription, useListCalculated } from "@arrai-innovations/reactive-helpers";
48
+ * import { reactive, toRef } from "vue";
49
+ *
50
+ * const listSubscriptionProps = reactive({
51
+ * // whatever props you need to get the list to work with your crud implementation
52
+ * crudArgs: {},
53
+ * listArgs: {},
54
+ * pkKey: "pk",
55
+ * retrieveArgs: {},
56
+ * intendToList: true,
57
+ * });
58
+ * const listSubscription = useListSubscription(listSubscriptionProps);
59
+ * const listCalculatedProps = reactive({
60
+ * parentState: listSubscription.state,
61
+ * computedObjectsRules: {
62
+ * someRule: (object, relatedObjects, calculatedObjects) => {
63
+ * // some complex calculation, relatedObjects would be assuming there was a listRelated between the two
64
+ * // calculatedObjects would be the other calculated objects in the list
65
+ * // including yourself, so try not to create circular dependencies
66
+ * // this is used as a computed body.
67
+ * return object.someProperty + object.someOtherProperty;
68
+ * }
69
+ * },
70
+ * });
71
+ * const listCalculated = useListCalculated(listCalculatedProps);
72
+ * </script>
73
+ * <template>
74
+ * <ul>
75
+ * <!-- reactive list of objects, re-retrieving the list as someListFilter changes. -->
76
+ * <li v-for="obj in listInstance.state.objectsInOrder">
77
+ * {{ obj }}
78
+ * <div>
79
+ * <!-- the computed object or objects based on the rule -->
80
+ * {{ listCalculated.state.computedObjects[obj.pk].someRule }}
81
+ * </div>
82
+ * </li>
83
+ * </ul>
84
+ * </template>
85
+ * ```
86
+ *
87
+ * @param {ListCalculatedOptions} options - Configuration options including the parent state and rules for dynamically
88
+ * generating calculated properties. This setup allows the system to handle calculations as part of the list management
89
+ * process, ensuring that all related data is consistently updated.
90
+ * @returns {ListCalculated} - A reactive instance that manages and provides access to calculated properties within the
91
+ * list, facilitating real-time updates and complex dependency management across multiple components.
92
+ */
93
+ export function useListCalculated({ parentState, calculatedObjectsRules }: ListCalculatedOptions): ListCalculated;
94
+ /**
95
+ * - Options to configure the behavior of the list calculated properties.
96
+ */
97
+ export type ListCalculatedOptions = {
98
+ /**
99
+ * - The parent state that interacts with the calculated objects.
100
+ */
101
+ parentState: ListCalculatedParentState;
102
+ /**
103
+ * - A reactive reference to rules used for dynamic calculations
104
+ * within list objects. Proper setup of this reference ensures that updates are managed reactively, including deep
105
+ * property changes.
106
+ */
107
+ calculatedObjectsRules: ListCalculatedRules;
108
+ };
109
+ /**
110
+ * The properties for the list computed composition function.
111
+ */
112
+ export type ListCalculatedProperties = {
113
+ /**
114
+ * - The state for the list calculated property.
115
+ */
116
+ state: ListCalculatedState;
117
+ /**
118
+ * - The parent state object.
119
+ */
120
+ parentState: ListCalculatedParentState;
121
+ /**
122
+ * - The watches running.
123
+ */
124
+ watchesRunning: import("./watchesRunning.js").WatchesRunning;
125
+ /**
126
+ * - The effect scope for the list calculated property.
127
+ */
128
+ effectScope: import("vue").EffectScope;
129
+ };
130
+ /**
131
+ * The instance of `useListCalculated`.
132
+ */
133
+ export type ListCalculated = ListCalculatedProperties;
134
+ /**
135
+ * Defines rules for dynamically calculating new properties for objects in a list. Each rule is a function that takes an
136
+ * object from the list, optionally its related objects, and previously calculated properties to compute a new
137
+ * property. These functions are reactive and re-evaluate when underlying dependencies change.
138
+ */
139
+ export type ListCalculatedRules = import("vue").Ref<{
140
+ [rule: string]: (object: import("./listInstance.js").ListObject, relatedObject: {
141
+ [rule: string]: any;
142
+ }, calculatedObjects: {
143
+ [rule: string]: import("vue").ComputedRef<any>;
144
+ }) => any;
145
+ }>;
146
+ /**
147
+ * - The raw state for a list calculated property.
148
+ */
149
+ export type ListCalculatedRawState = {
150
+ /**
151
+ * - The calculated objects.
152
+ */
153
+ calculatedObjects: {
154
+ [pk: string]: {
155
+ [rule: string]: import("vue").ComputedRef<any>;
156
+ };
157
+ };
158
+ /**
159
+ * - The rules for the calculated objects.
160
+ */
161
+ calculatedObjectsRules: ListCalculatedRules;
162
+ /**
163
+ * - Whether the parent state objects watch is running.
164
+ */
165
+ calculatedObjectsParentStateObjectsWatchRunning: boolean;
166
+ /**
167
+ * - Whether the calculated objects watch is running.
168
+ */
169
+ calculatedObjectsWatchRunning: boolean;
170
+ /**
171
+ * - Whether the calculated properties are running.
172
+ */
173
+ calculatedRunning: boolean;
174
+ /**
175
+ * - Whether the list is running.
176
+ */
177
+ running: import("vue").Ref<boolean>;
178
+ };
179
+ /**
180
+ * The raw parent state for a list calculated.
181
+ */
182
+ export type ListCalculatedParentRawState = (import("./listInstance.js").ListInstanceRawState & Partial<import("./listSubscription.js").ListSubscriptionRawState> & Partial<import("./listRelated.js").ListRelatedRawState>);
183
+ /**
184
+ * The state for a list calculated property.
185
+ */
186
+ export type ListCalculatedState = import("vue").UnwrapNestedRefs<ListCalculatedParentRawState & ListCalculatedRawState>;
187
+ /**
188
+ * Represents a combined reactive state that includes properties from list related,
189
+ * subscription, and instance modules.
190
+ */
191
+ export type ListCalculatedParentState = import("vue").UnwrapNestedRefs<(import("./listInstance.js").ListInstanceRawState & Partial<import("./listSubscription.js").ListSubscriptionRawState> & Partial<import("./listRelated.js").ListRelatedRawState>)>;
192
+ //# sourceMappingURL=listCalculated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listCalculated.d.ts","sourceRoot":"","sources":["../../use/listCalculated.js"],"names":[],"mappings":"AAoGA;;;;;;;;GAQG;AAEH;;;;;;;;GAQG;AAIH;;;;GAIG;AAEH;;;;;;;GAOG;AACH,uDALW;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;CACvC,GACS;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAC,CAS3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,2EANW,qB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