@arrai-innovations/reactive-helpers 20.1.2 → 21.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +22 -893
  2. package/config/listCrud.js +30 -27
  3. package/config/objectCrud.js +20 -13
  4. package/index.js +5 -3
  5. package/package.json +5 -3
  6. package/types/config/commonCrud.d.ts +0 -1
  7. package/types/config/listCrud.d.ts +28 -41
  8. package/types/config/objectCrud.d.ts +14 -29
  9. package/types/index.d.ts +5 -4
  10. package/types/tests/unit/config/listCrud.spec.d.ts +0 -1
  11. package/types/tests/unit/config/objectCrud.spec.d.ts +0 -1
  12. package/types/tests/unit/crudPromise.d.ts +42 -15
  13. package/types/tests/unit/mockOnUnmounted.d.ts +0 -1
  14. package/types/tests/unit/poll.d.ts +0 -1
  15. package/types/tests/unit/scopedIt.d.ts +15 -0
  16. package/types/tests/unit/setup.d.ts +2 -0
  17. package/types/tests/unit/use/cancellableIntent.spec.d.ts +0 -1
  18. package/types/tests/unit/use/combineClasses.spec.d.ts +1 -0
  19. package/types/tests/unit/use/list.spec.d.ts +1 -0
  20. package/types/tests/unit/use/listCalculated.spec.d.ts +0 -1
  21. package/types/tests/unit/use/listFilter.spec.d.ts +0 -1
  22. package/types/tests/unit/use/listInstance.spec.d.ts +0 -1
  23. package/types/tests/unit/use/listRelated.spec.d.ts +0 -1
  24. package/types/tests/unit/use/listSearch.spec.d.ts +0 -1
  25. package/types/tests/unit/use/listSort.spec.d.ts +0 -1
  26. package/types/tests/unit/use/listSubscription.spec.d.ts +0 -1
  27. package/types/tests/unit/use/loadingError.spec.d.ts +0 -1
  28. package/types/tests/unit/use/object.spec.d.ts +1 -0
  29. package/types/tests/unit/use/objectCalculated.spec.d.ts +1 -0
  30. package/types/tests/unit/use/objectInstance.spec.d.ts +0 -1
  31. package/types/tests/unit/use/objectRelated.spec.d.ts +1 -0
  32. package/types/tests/unit/use/objectSubscription.spec.d.ts +0 -1
  33. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +0 -1
  34. package/types/tests/unit/use/search.error.spec.d.ts +1 -0
  35. package/types/tests/unit/use/search.spec.d.ts +0 -1
  36. package/types/tests/unit/utils/assignReactiveObject.extra.spec.d.ts +1 -0
  37. package/types/tests/unit/utils/assignReactiveObject.refs.spec.d.ts +1 -0
  38. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +0 -1
  39. package/types/tests/unit/utils/cancellableFetch.spec.d.ts +1 -0
  40. package/types/tests/unit/utils/classes.spec.d.ts +0 -1
  41. package/types/tests/unit/utils/compact.spec.d.ts +1 -0
  42. package/types/tests/unit/utils/deepUnref.spec.d.ts +1 -0
  43. package/types/tests/unit/utils/deleteKey.spec.d.ts +0 -1
  44. package/types/tests/unit/utils/flattenPaths.spec.d.ts +0 -1
  45. package/types/tests/unit/utils/flattenPathsWithValues.spec.d.ts +1 -0
  46. package/types/tests/unit/utils/getFakePk.spec.d.ts +1 -0
  47. package/types/tests/unit/utils/keepAliveTry.spec.d.ts +1 -0
  48. package/types/tests/unit/utils/keyDiff.spec.d.ts +0 -1
  49. package/types/tests/unit/utils/set.spec.d.ts +0 -1
  50. package/types/tests/unit/utils/transformWalk.spec.d.ts +1 -0
  51. package/types/tests/unit/utils/unwrapNested.spec.d.ts +1 -0
  52. package/types/tests/unit/utils/watches.spec.d.ts +0 -1
  53. package/types/use/cancellableIntent.d.ts +121 -48
  54. package/types/use/combineClasses.d.ts +0 -1
  55. package/types/use/error.d.ts +48 -0
  56. package/types/use/list.d.ts +9 -32
  57. package/types/use/listCalculated.d.ts +107 -49
  58. package/types/use/listFilter.d.ts +13 -31
  59. package/types/use/listInstance.d.ts +137 -71
  60. package/types/use/listRelated.d.ts +106 -43
  61. package/types/use/listSearch.d.ts +24 -12
  62. package/types/use/listSort.d.ts +3 -34
  63. package/types/use/listSubscription.d.ts +40 -57
  64. package/types/use/loading.d.ts +37 -0
  65. package/types/use/loadingError.d.ts +5 -100
  66. package/types/use/object.d.ts +3 -12
  67. package/types/use/objectCalculated.d.ts +3 -9
  68. package/types/use/objectInstance.d.ts +59 -47
  69. package/types/use/objectRelated.d.ts +3 -9
  70. package/types/use/objectSubscription.d.ts +33 -51
  71. package/types/use/proxyError.d.ts +27 -0
  72. package/types/use/proxyLoading.d.ts +15 -0
  73. package/types/use/proxyLoadingError.d.ts +8 -16
  74. package/types/use/search.d.ts +2 -3
  75. package/types/utils/assignReactiveObject.d.ts +0 -1
  76. package/types/utils/cancellableFetch.d.ts +0 -1
  77. package/types/utils/cancellablePromise.d.ts +0 -1
  78. package/types/utils/classes.d.ts +2 -8
  79. package/types/utils/compact.d.ts +0 -1
  80. package/types/utils/deepUnref.d.ts +2 -23
  81. package/types/utils/deleteKey.d.ts +6 -6
  82. package/types/utils/flattenPaths.d.ts +0 -1
  83. package/types/utils/flattenPathsWithValues.d.ts +29 -0
  84. package/types/utils/getFakePk.d.ts +0 -1
  85. package/types/utils/keepAliveTry.d.ts +0 -1
  86. package/types/utils/keyDiff.d.ts +9 -10
  87. package/types/utils/loadingCombine.d.ts +0 -1
  88. package/types/utils/proxyRunning.d.ts +2 -3
  89. package/types/utils/refIfReactive.d.ts +0 -1
  90. package/types/utils/relatedCalculatedHelpers.d.ts +0 -1
  91. package/types/utils/set.d.ts +0 -1
  92. package/types/utils/transformWalk.d.ts +0 -1
  93. package/types/utils/unwrapNested.d.ts +0 -1
  94. package/types/utils/watches.d.ts +0 -1
  95. package/use/cancellableIntent.js +185 -100
  96. package/use/error.js +44 -0
  97. package/use/list.js +51 -111
  98. package/use/listCalculated.js +75 -98
  99. package/use/listFilter.js +91 -186
  100. package/use/listInstance.js +357 -282
  101. package/use/listRelated.js +52 -72
  102. package/use/listSearch.js +49 -86
  103. package/use/listSort.js +121 -237
  104. package/use/listSubscription.js +181 -274
  105. package/use/loading.js +35 -0
  106. package/use/loadingError.js +7 -81
  107. package/use/object.js +47 -67
  108. package/use/objectCalculated.js +103 -65
  109. package/use/objectInstance.js +253 -241
  110. package/use/objectRelated.js +48 -30
  111. package/use/objectSubscription.js +110 -175
  112. package/use/proxyError.js +48 -0
  113. package/use/proxyLoading.js +22 -0
  114. package/use/proxyLoadingError.js +9 -35
  115. package/use/search.js +4 -2
  116. package/utils/assignReactiveObject.js +8 -8
  117. package/utils/classes.js +7 -28
  118. package/utils/deepUnref.js +15 -2
  119. package/utils/deleteKey.js +13 -5
  120. package/utils/flattenPathsWithValues.js +65 -0
  121. package/utils/keyDiff.js +5 -5
  122. package/utils/proxyRunning.js +16 -10
  123. package/types/config/commonCrud.d.ts.map +0 -1
  124. package/types/config/listCrud.d.ts.map +0 -1
  125. package/types/config/objectCrud.d.ts.map +0 -1
  126. package/types/index.d.ts.map +0 -1
  127. package/types/tests/unit/config/listCrud.spec.d.ts.map +0 -1
  128. package/types/tests/unit/config/objectCrud.spec.d.ts.map +0 -1
  129. package/types/tests/unit/crudPromise.d.ts.map +0 -1
  130. package/types/tests/unit/expectHelpers.d.ts +0 -2
  131. package/types/tests/unit/expectHelpers.d.ts.map +0 -1
  132. package/types/tests/unit/mockOnUnmounted.d.ts.map +0 -1
  133. package/types/tests/unit/poll.d.ts.map +0 -1
  134. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +0 -1
  135. package/types/tests/unit/use/listCalculated.spec.d.ts.map +0 -1
  136. package/types/tests/unit/use/listFilter.spec.d.ts.map +0 -1
  137. package/types/tests/unit/use/listInstance.spec.d.ts.map +0 -1
  138. package/types/tests/unit/use/listRelated.spec.d.ts.map +0 -1
  139. package/types/tests/unit/use/listSearch.spec.d.ts.map +0 -1
  140. package/types/tests/unit/use/listSort.spec.d.ts.map +0 -1
  141. package/types/tests/unit/use/listSubscription.spec.d.ts.map +0 -1
  142. package/types/tests/unit/use/loadingError.spec.d.ts.map +0 -1
  143. package/types/tests/unit/use/objectInstance.spec.d.ts.map +0 -1
  144. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +0 -1
  145. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +0 -1
  146. package/types/tests/unit/use/search.spec.d.ts.map +0 -1
  147. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +0 -1
  148. package/types/tests/unit/utils/classes.spec.d.ts.map +0 -1
  149. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +0 -1
  150. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +0 -1
  151. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +0 -1
  152. package/types/tests/unit/utils/set.spec.d.ts.map +0 -1
  153. package/types/tests/unit/utils/watches.spec.d.ts.map +0 -1
  154. package/types/use/cancellableIntent.d.ts.map +0 -1
  155. package/types/use/combineClasses.d.ts.map +0 -1
  156. package/types/use/list.d.ts.map +0 -1
  157. package/types/use/listCalculated.d.ts.map +0 -1
  158. package/types/use/listFilter.d.ts.map +0 -1
  159. package/types/use/listInstance.d.ts.map +0 -1
  160. package/types/use/listKeys.d.ts +0 -15
  161. package/types/use/listKeys.d.ts.map +0 -1
  162. package/types/use/listRelated.d.ts.map +0 -1
  163. package/types/use/listSearch.d.ts.map +0 -1
  164. package/types/use/listSort.d.ts.map +0 -1
  165. package/types/use/listSubscription.d.ts.map +0 -1
  166. package/types/use/loadingError.d.ts.map +0 -1
  167. package/types/use/object.d.ts.map +0 -1
  168. package/types/use/objectCalculated.d.ts.map +0 -1
  169. package/types/use/objectInstance.d.ts.map +0 -1
  170. package/types/use/objectRelated.d.ts.map +0 -1
  171. package/types/use/objectSubscription.d.ts.map +0 -1
  172. package/types/use/paginatedListInstance.d.ts +0 -60
  173. package/types/use/paginatedListInstance.d.ts.map +0 -1
  174. package/types/use/proxyLoadingError.d.ts.map +0 -1
  175. package/types/use/search.d.ts.map +0 -1
  176. package/types/use/watchesRunning.d.ts +0 -63
  177. package/types/use/watchesRunning.d.ts.map +0 -1
  178. package/types/utils/assignReactiveObject.d.ts.map +0 -1
  179. package/types/utils/cancellableFetch.d.ts.map +0 -1
  180. package/types/utils/cancellablePromise.d.ts.map +0 -1
  181. package/types/utils/classes.d.ts.map +0 -1
  182. package/types/utils/compact.d.ts.map +0 -1
  183. package/types/utils/deepUnref.d.ts.map +0 -1
  184. package/types/utils/deleteKey.d.ts.map +0 -1
  185. package/types/utils/flattenPaths.d.ts.map +0 -1
  186. package/types/utils/getFakePk.d.ts.map +0 -1
  187. package/types/utils/keepAliveTry.d.ts.map +0 -1
  188. package/types/utils/keyDiff.d.ts.map +0 -1
  189. package/types/utils/loadingCombine.d.ts.map +0 -1
  190. package/types/utils/proxyRunning.d.ts.map +0 -1
  191. package/types/utils/refIfReactive.d.ts.map +0 -1
  192. package/types/utils/relatedCalculatedHelpers.d.ts.map +0 -1
  193. package/types/utils/set.d.ts.map +0 -1
  194. package/types/utils/transformWalk.d.ts.map +0 -1
  195. package/types/utils/unwrapNested.d.ts.map +0 -1
  196. package/types/utils/watches.d.ts.map +0 -1
  197. package/use/listKeys.js +0 -105
  198. package/use/paginatedListInstance.js +0 -126
  199. package/use/watchesRunning.js +0 -69
@@ -1,25 +1,52 @@
1
1
  /**
2
2
  * A class that wraps a promise and its resolve and reject functions
3
+ *
4
+ * @template T
3
5
  */
4
- export class Resolvable {
6
+ export class Resolvable<T> {
5
7
  /**
6
- * @type {Promise}
8
+ * @type {Promise<T>}
7
9
  */
8
- promise: Promise<any>;
9
- /** @type {Function} */
10
- resolve: Function;
11
- /** @type {Function} */
12
- reject: Function;
10
+ promise: Promise<T>;
11
+ /**
12
+ * @type {(value: T) => void}
13
+ */
14
+ resolve: (value: T) => void;
15
+ /**
16
+ * @type {(reason?: any) => void}
17
+ */
18
+ reject: (reason?: any) => void;
13
19
  }
14
20
  /**
15
21
  * A Resolvable with a cancel function.
22
+ *
23
+ * @template T
16
24
  */
17
- export class CancellableResolvable {
18
- promise: Promise<any>;
19
- /** @type {Function} */
20
- resolve: Function;
21
- /** @type {Function} */
22
- reject: Function;
23
- cancel: Resolvable;
25
+ export class CancellableResolvable<T> {
26
+ /**
27
+ * @type {import("../../utils/cancellablePromise.js").CancellablePromise<T>}
28
+ */
29
+ promise: import("../../utils/cancellablePromise.js").CancellablePromise<T>;
30
+ /**
31
+ * @type {(value: T) => void}
32
+ */
33
+ resolve: (value: T) => void;
34
+ /**
35
+ * @type {(reason?: any) => void}
36
+ */
37
+ reject: (reason?: any) => void;
38
+ /**
39
+ * Cancel-related resolvable.
40
+ *
41
+ * @type {{ promise: Promise<void>, resolve: () => void }}
42
+ */
43
+ cancel: {
44
+ promise: Promise<void>;
45
+ resolve: () => void;
46
+ };
47
+ /**
48
+ * @private
49
+ * @type {(value?: any) => void}
50
+ */
51
+ private _cancelResolve;
24
52
  }
25
- //# sourceMappingURL=crudPromise.d.ts.map
@@ -1,2 +1 @@
1
1
  export function getMockOnUnmounted(): {};
2
- //# sourceMappingURL=mockOnUnmounted.d.ts.map
@@ -1,2 +1 @@
1
1
  export function poll(condition: any, interval?: number, timeout?: number): Promise<any>;
2
- //# sourceMappingURL=poll.d.ts.map
@@ -0,0 +1,15 @@
1
+ export function scopedIt(name: string, fn: () => Promise<void> | void, timeout?: number): void;
2
+ export namespace scopedIt {
3
+ /**
4
+ * Mark a scoped test as TODO.
5
+ * @param {string} name - The name of the test.
6
+ */
7
+ export function todo(name: string): void;
8
+ export function each(cases: any): (name: any, optionsOrFn: any, maybeFn: any) => any;
9
+ /**
10
+ * Run a test in a Vue effect scope with multiple cases, using `it.for`.
11
+ * @param {Array} cases - The cases to run the test with.
12
+ */
13
+ function _for(cases: any[]): (name: any, maybeOptionsOrFn: any, maybeFnOrNothing: any) => void;
14
+ export { _for as for };
15
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=cancellableIntent.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listCalculated.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listFilter.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listInstance.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listRelated.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listSearch.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listSort.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=listSubscription.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=loadingError.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=objectInstance.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=objectSubscription.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=proxyLoadingError.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=search.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=assignReactiveObject.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=classes.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=deleteKey.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=flattenPaths.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=keyDiff.spec.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=set.spec.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=watches.spec.d.ts.map
@@ -1,33 +1,62 @@
1
1
  /**
2
- * @module use/cancellableIntent.js - A composable function for handling cancellable intents.
2
+ * @typedef {number} RunId - A unique identifier for a single execution ("run") of an intent.
3
+ * This is incremented each time `watchArguments` change and the intent re-triggers.
4
+ * Enables distinguishing results or effects from overlapping async runs.
3
5
  */
4
6
  /**
5
7
  * @typedef {object} CancellableIntentRawState - The raw state of the cancellable intent.
6
- * @property {number|undefined} activeCount - The number of active intents.
7
- * @property {boolean|undefined} active - Whether there are active intents.
8
- * @property {number|undefined} resolvingCount - The number of resolving intents.
9
- * @property {boolean|undefined} resolving - Whether there are resolving intents.
10
- * @property {boolean} errored - Whether there was an error.
11
- * @property {Error|null} error - The error that occurred.
8
+ * @property {import('vue').ComputedRef<boolean>|undefined} active - Whether there are active intents.
9
+ * @property {import('vue').ComputedRef<boolean>|undefined} resolving - Whether there are resolving intents.
12
10
  * @property {boolean} clearActiveOnResolved - Whether to clear the active state when the promise resolves.
11
+ * @property {RunId|null} lastRunId - The most recent run ID issued for a triggered intent. Useful for associating async results with their originating trigger.
12
+ * @property {import('vue').DeepReadonly<object>} watchArguments - The watch arguments.
13
+ * @property {import('vue').DeepReadonly<object>} guardArguments - The guard arguments.
14
+ */
15
+ /**
16
+ * @typedef {import("vue").Reactive<
17
+ * CancellableIntentRawState &
18
+ * Pick<import('./error.js').ErrorStatus, 'error' | 'errored'>
19
+ * >} CancellableIntentState - The state of the cancellable intent.
20
+ */
21
+ /**
22
+ * @typedef {() => boolean} IsCurrentRunFn - A function that checks if the current run ID matches the last run ID.
23
+ */
24
+ /**
25
+ * The common run tracking arguments.
26
+ *
27
+ * @typedef {object} CommonRunTracking
28
+ * @property {RunId} runId - The unique identifier for your run.
29
+ * @property {IsCurrentRunFn} isCurrentRun - A function that checks if the current run ID matches your run ID.
13
30
  */
14
31
  /**
15
- * @typedef {import("vue").UnwrapNestedRefs<CancellableIntentRawState>} CancellableIntentState - The state of the cancellable intent.
32
+ * @typedef {(runTracking: CommonRunTracking) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} AwaitableWithCancel - A function that returns a promise that can be cancelled.
33
+ */
34
+ /**
35
+ * @typedef {import("vue").UnwrapNestedRefs<object>|{[key: string]: import('vue').Ref<any>}} WatchGuardArguments - The reactive object to watch for changes.
16
36
  */
17
37
  /**
18
38
  * @typedef {object} CancellableIntentOptions - The options for the cancellable intent.
19
- * @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} awaitableWithCancel - The function that returns a promise that can be cancelled.
20
- * @property {import("vue").UnwrapNestedRefs<object>} [watchArguments={}] - The reactive object to watch for changes.
21
- * @property {import("vue").UnwrapNestedRefs<object>} [guardArguments={}] - The reactive object to watch for truthiness before running the intent.
39
+ * @property {AwaitableWithCancel} awaitableWithCancel - The function that returns a promise that can be cancelled. Receives the run ID as an argument.
40
+ * @property {WatchGuardArguments} [watchArguments={}] - The reactive object to watch for changes.
41
+ * @property {WatchGuardArguments} [guardArguments={}] - The reactive object to watch for truthiness before running the intent.
22
42
  * @property {boolean} [clearActiveOnResolved=true] - Whether to clear the active state when the promise resolves.
23
43
  */
24
44
  /**
25
- * @typedef {object} CancellableIntent - The instance of the cancellable intent.
45
+ * Cancel function signature for cancellable intent.
46
+ *
47
+ * @typedef {Function} CancelFn
48
+ * @param {any} reason - The reason for cancellation.
49
+ * @param {boolean} [forceClearActive=false] - Whether to force clear the active state.
50
+ * @returns {Promise<void>} - A promise that resolves when the cancellation is complete.
51
+ */
52
+ /**
53
+ * @typedef {object} MyCancellableIntent - The instance of the cancellable intent.
26
54
  * @property {CancellableIntentState} state - The state of the cancellable intent.
27
- * @property {import('vue').UnwrapNestedRefs<object>} watchArguments - The watch arguments.
28
- * @property {import('vue').UnwrapNestedRefs<object>} guardArguments - The guard arguments.
29
- * @property {Function} stop - Stop the cancellable intent.
30
- * @property {Function} cancel - Cancel the cancellable intent.
55
+ * @property {() => void} stop - Stop the cancellable intent.
56
+ * @property {CancelFn} cancel - Cancel the cancellable intent.
57
+ */
58
+ /**
59
+ * @typedef {MyCancellableIntent & Pick<import('./error.js').ErrorStatus, "clearError">} CancellableIntent - The instance of the cancellable intent.
31
60
  */
32
61
  /**
33
62
  * Calls your awaitable function with the arguments you pass in when the watch arguments change and are all truthy.
@@ -69,86 +98,130 @@
69
98
  */
70
99
  export function useCancellableIntent({ awaitableWithCancel, watchArguments, guardArguments, clearActiveOnResolved, }: CancellableIntentOptions): CancellableIntent;
71
100
  /**
72
- * - The raw state of the cancellable intent.
101
+ * @module use/cancellableIntent.js - A composable function for handling cancellable intents.
73
102
  */
74
- export type CancellableIntentRawState = {
103
+ /**
104
+ * Custom error class for list subscription errors.
105
+ */
106
+ export class CancellableIntentError extends Error {
75
107
  /**
76
- * - The number of active intents.
108
+ * Creates a new CancellableIntentError.
109
+ *
110
+ * @param {string} message - The error message.
111
+ * @param {string} code - The error code.
77
112
  */
78
- activeCount: number | undefined;
113
+ constructor(message: string, code: string);
114
+ code: string;
115
+ }
116
+ /**
117
+ * - A unique identifier for a single execution ("run") of an intent.
118
+ * This is incremented each time `watchArguments` change and the intent re-triggers.
119
+ * Enables distinguishing results or effects from overlapping async runs.
120
+ */
121
+ export type RunId = number;
122
+ /**
123
+ * - The raw state of the cancellable intent.
124
+ */
125
+ export type CancellableIntentRawState = {
79
126
  /**
80
127
  * - Whether there are active intents.
81
128
  */
82
- active: boolean | undefined;
129
+ active: import("vue").ComputedRef<boolean> | undefined;
83
130
  /**
84
- * - The number of resolving intents.
131
+ * - Whether there are resolving intents.
85
132
  */
86
- resolvingCount: number | undefined;
133
+ resolving: import("vue").ComputedRef<boolean> | undefined;
87
134
  /**
88
- * - Whether there are resolving intents.
135
+ * - Whether to clear the active state when the promise resolves.
89
136
  */
90
- resolving: boolean | undefined;
137
+ clearActiveOnResolved: boolean;
91
138
  /**
92
- * - Whether there was an error.
139
+ * - The most recent run ID issued for a triggered intent. Useful for associating async results with their originating trigger.
93
140
  */
94
- errored: boolean;
141
+ lastRunId: RunId | null;
95
142
  /**
96
- * - The error that occurred.
143
+ * - The watch arguments.
97
144
  */
98
- error: Error | null;
145
+ watchArguments: import("vue").DeepReadonly<object>;
99
146
  /**
100
- * - Whether to clear the active state when the promise resolves.
147
+ * - The guard arguments.
101
148
  */
102
- clearActiveOnResolved: boolean;
149
+ guardArguments: import("vue").DeepReadonly<object>;
103
150
  };
104
151
  /**
105
152
  * - The state of the cancellable intent.
106
153
  */
107
- export type CancellableIntentState = import("vue").UnwrapNestedRefs<CancellableIntentRawState>;
154
+ export type CancellableIntentState = import("vue").Reactive<CancellableIntentRawState & Pick<import("./error.js").ErrorStatus, "error" | "errored">>;
155
+ /**
156
+ * - A function that checks if the current run ID matches the last run ID.
157
+ */
158
+ export type IsCurrentRunFn = () => boolean;
159
+ /**
160
+ * The common run tracking arguments.
161
+ */
162
+ export type CommonRunTracking = {
163
+ /**
164
+ * - The unique identifier for your run.
165
+ */
166
+ runId: RunId;
167
+ /**
168
+ * - A function that checks if the current run ID matches your run ID.
169
+ */
170
+ isCurrentRun: IsCurrentRunFn;
171
+ };
172
+ /**
173
+ * - A function that returns a promise that can be cancelled.
174
+ */
175
+ export type AwaitableWithCancel = (runTracking: CommonRunTracking) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<void>;
176
+ /**
177
+ * - The reactive object to watch for changes.
178
+ */
179
+ export type WatchGuardArguments = import("vue").UnwrapNestedRefs<object> | {
180
+ [key: string]: import("vue").Ref<any>;
181
+ };
108
182
  /**
109
183
  * - The options for the cancellable intent.
110
184
  */
111
185
  export type CancellableIntentOptions = {
112
186
  /**
113
- * - The function that returns a promise that can be cancelled.
187
+ * - The function that returns a promise that can be cancelled. Receives the run ID as an argument.
114
188
  */
115
- awaitableWithCancel: () => import("../utils/cancellablePromise.js").MaybeCancellablePromise<void>;
189
+ awaitableWithCancel: AwaitableWithCancel;
116
190
  /**
117
191
  * - The reactive object to watch for changes.
118
192
  */
119
- watchArguments?: import("vue").UnwrapNestedRefs<object>;
193
+ watchArguments?: WatchGuardArguments;
120
194
  /**
121
195
  * - The reactive object to watch for truthiness before running the intent.
122
196
  */
123
- guardArguments?: import("vue").UnwrapNestedRefs<object>;
197
+ guardArguments?: WatchGuardArguments;
124
198
  /**
125
199
  * - Whether to clear the active state when the promise resolves.
126
200
  */
127
201
  clearActiveOnResolved?: boolean;
128
202
  };
203
+ /**
204
+ * Cancel function signature for cancellable intent.
205
+ */
206
+ export type CancelFn = Function;
129
207
  /**
130
208
  * - The instance of the cancellable intent.
131
209
  */
132
- export type CancellableIntent = {
210
+ export type MyCancellableIntent = {
133
211
  /**
134
212
  * - The state of the cancellable intent.
135
213
  */
136
214
  state: CancellableIntentState;
137
- /**
138
- * - The watch arguments.
139
- */
140
- watchArguments: import("vue").UnwrapNestedRefs<object>;
141
- /**
142
- * - The guard arguments.
143
- */
144
- guardArguments: import("vue").UnwrapNestedRefs<object>;
145
215
  /**
146
216
  * - Stop the cancellable intent.
147
217
  */
148
- stop: Function;
218
+ stop: () => void;
149
219
  /**
150
220
  * - Cancel the cancellable intent.
151
221
  */
152
- cancel: Function;
222
+ cancel: CancelFn;
153
223
  };
154
- //# sourceMappingURL=cancellableIntent.d.ts.map
224
+ /**
225
+ * - The instance of the cancellable intent.
226
+ */
227
+ export type CancellableIntent = MyCancellableIntent & Pick<import("./error.js").ErrorStatus, "clearError">;
@@ -40,4 +40,3 @@ export function useCombineClasses(...classes: (CSSClasses)[]): import("vue").Ref
40
40
  export type CSSClasses = (string | string[] | {
41
41
  [key: string]: boolean | import("vue").Ref<boolean>;
42
42
  } | import("vue").Ref<string | string[]>);
43
- //# sourceMappingURL=combineClasses.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @typedef {() => void} ClearErrorFn
3
+ * @typedef {import("vue").Ref<Error|null>} ErrorRef
4
+ * @typedef {import("vue").Ref<boolean>} ErroredRef
5
+ * @typedef {Readonly<ErrorRef>} ErrorReadonlyRef
6
+ * @typedef {Readonly<ErroredRef>} ErroredReadonlyRef
7
+ */
8
+ /**
9
+ * The error state API.
10
+ *
11
+ * @typedef {object} ErrorStatus
12
+ * @property {ErrorReadonlyRef} error - The error that occurred.
13
+ * @property {ErroredReadonlyRef} errored - Whether an error has occurred.
14
+ * @property {(error: Error) => void} setError - Set the error state.
15
+ * @property {ClearErrorFn} clearError - Clear the error state.
16
+ */
17
+ /**
18
+ * A composable function for managing error state.
19
+ *
20
+ * @returns {ErrorStatus} - An object containing reactive fields and actions for error state.
21
+ */
22
+ export function useError(): ErrorStatus;
23
+ export type ClearErrorFn = () => void;
24
+ export type ErrorRef = import("vue").Ref<Error | null>;
25
+ export type ErroredRef = import("vue").Ref<boolean>;
26
+ export type ErrorReadonlyRef = Readonly<ErrorRef>;
27
+ export type ErroredReadonlyRef = Readonly<ErroredRef>;
28
+ /**
29
+ * The error state API.
30
+ */
31
+ export type ErrorStatus = {
32
+ /**
33
+ * - The error that occurred.
34
+ */
35
+ error: ErrorReadonlyRef;
36
+ /**
37
+ * - Whether an error has occurred.
38
+ */
39
+ errored: ErroredReadonlyRef;
40
+ /**
41
+ * - Set the error state.
42
+ */
43
+ setError: (error: Error) => void;
44
+ /**
45
+ * - Clear the error state.
46
+ */
47
+ clearError: ClearErrorFn;
48
+ };
@@ -24,7 +24,7 @@ export function useLists(listOptions: {
24
24
  }): {
25
25
  [key: string]: ListManager;
26
26
  };
27
- export function useList({ props, handlers, paged, keepOldPages, clearListOnListIntentTriggered, searchThrottle, sortThrottleWait, searchShowAllWhenEmpty, }: ListOptions): ListManager;
27
+ export function useList({ props, handlers, searchThrottle, sortThrottleWait, searchShowAllWhenEmpty }: ListOptions): ListManager;
28
28
  /**
29
29
  * Defines properties for configuring the list management system.
30
30
  */
@@ -94,47 +94,25 @@ export type ListOptions = {
94
94
  /**
95
95
  * - Additional handlers to be included in the list manager.
96
96
  */
97
- handlers: import("../config/listCrud.js").ListCrudHandlers;
98
- /**
99
- * - Indicates whether the list should be paginated.
100
- */
101
- paged: boolean;
102
- /**
103
- * - Indicates whether old pages should be kept when paginating.
104
- */
105
- keepOldPages: import("vue").Ref<boolean> | boolean;
106
- /**
107
- * - Indicates whether the list should be cleared when the list intent is triggered.
108
- */
109
- clearListOnListIntentTriggered: boolean;
97
+ handlers?: import("../config/listCrud.js").ListCrudHandlers;
110
98
  /**
111
99
  * - The throttle time for text search.
112
100
  */
113
- searchThrottle: number;
101
+ searchThrottle?: number;
114
102
  /**
115
103
  * - The throttle time for sorting.
116
104
  */
117
- sortThrottleWait: number;
105
+ sortThrottleWait?: number;
118
106
  /**
119
107
  * - Indicates whether all items should be shown when the search query is empty.
120
108
  */
121
- searchShowAllWhenEmpty: boolean;
109
+ searchShowAllWhenEmpty?: boolean;
122
110
  };
123
- /**
124
- * Represents the combined state definitions for all list-related components.
125
- * This interface aggregates the raw state from multiple list management functionalities.
126
- */
127
- export type ListRawState = ((import("./listInstance.js").ListInstanceRawState | import("./paginatedListInstance.js").PagedListInstanceRawState) & import("./listSubscription.js").ListSubscriptionRawState & import("./listRelated.js").ListRelatedRawState & import("./listCalculated.js").ListCalculatedRawState & import("./listFilter.js").ListFilterRawState & import("./listSearch.js").ListSearchRawState & import("./listSort.js").ListSortRawState);
128
- /**
129
- * Represents the reactive state derived from aggregating states of various list-related components.
130
- * This state is typically used within Vue components for reactivity and access to updated list properties.
131
- */
132
- export type ListState = import("vue").UnwrapNestedRefs<ListRawState>;
133
111
  /**
134
112
  * Holds references to instances of all list-related composables, facilitating direct access and management.
135
113
  */
136
114
  export type ListManaged = {
137
- listInstance: import("./listInstance.js").ListInstance | import("./paginatedListInstance.js").PagedListInstance;
115
+ listInstance: import("./listInstance.js").ListInstance;
138
116
  listSubscription: import("./listSubscription.js").ListSubscription;
139
117
  listRelated: import("./listRelated.js").ListRelated;
140
118
  listCalculated: import("./listCalculated.js").ListCalculated;
@@ -158,15 +136,14 @@ export type ListManagerProperties = {
158
136
  /**
159
137
  * - Represents the final reactive state in the list processing chain.
160
138
  */
161
- state: ListState;
139
+ state: import("./listSort.js").ListSortState;
162
140
  /**
163
- * - Encapsulates all reactive effects related to the list hooks.
141
+ * - A function to stop the effect scope and clean up resources.
164
142
  */
165
- effectScope: import("vue").EffectScope;
143
+ stop: () => void;
166
144
  };
167
145
  /**
168
146
  * Combines functionality and properties to represent a fully managed list instance,
169
147
  * orchestrating various functionalities such as sorting, searching, filtering, and state management.
170
148
  */
171
149
  export type ListManager = ListFunctions & ListManagerProperties;
172
- //# sourceMappingURL=list.d.ts.map