@arrai-innovations/reactive-helpers 21.1.2 → 22.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +109 -21
- package/config/commonCrud.js +7 -10
- package/config/listCrud.js +33 -33
- package/config/objectCrud.js +64 -59
- package/package.json +103 -89
- package/types/config/listCrud.d.ts +83 -28
- package/types/config/objectCrud.d.ts +139 -49
- package/types/tests/benchmarks/fixtures.d.ts +60 -0
- package/types/tests/benchmarks/listLayers.bench.d.ts +1 -0
- package/types/tests/benchmarks/listPush.bench.d.ts +1 -0
- package/types/tests/benchmarks/listStream.bench.d.ts +1 -0
- package/types/tests/unit/use/lifecycleCleanup.spec.d.ts +1 -0
- package/types/tests/unit/use/listPerformance.spec.d.ts +1 -0
- package/types/tests/unit/utils/cancellablePromise.spec.d.ts +1 -0
- package/types/use/cancellableIntent.d.ts +36 -33
- package/types/use/combineClasses.d.ts +5 -2
- package/types/use/error.d.ts +39 -19
- package/types/use/list.d.ts +27 -26
- package/types/use/listCalculated.d.ts +38 -55
- package/types/use/listFilter.d.ts +25 -33
- package/types/use/listInstance.d.ts +94 -81
- package/types/use/listRelated.d.ts +37 -57
- package/types/use/listSearch.d.ts +54 -52
- package/types/use/listSort.d.ts +31 -40
- package/types/use/listSubscription.d.ts +33 -36
- package/types/use/loading.d.ts +20 -10
- package/types/use/loadingError.d.ts +12 -3
- package/types/use/object.d.ts +8 -5
- package/types/use/objectCalculated.d.ts +46 -39
- package/types/use/objectInstance.d.ts +70 -74
- package/types/use/objectRelated.d.ts +51 -41
- package/types/use/objectSubscription.d.ts +38 -48
- package/types/use/proxyError.d.ts +15 -6
- package/types/use/proxyLoading.d.ts +11 -5
- package/types/use/proxyLoadingError.d.ts +19 -7
- package/types/use/search.d.ts +33 -29
- package/types/utils/assignReactiveObject.d.ts +3 -0
- package/types/utils/cancellableFetch.d.ts +2 -3
- package/types/utils/cancellablePromise.d.ts +42 -8
- package/types/utils/classes.d.ts +7 -1
- package/types/utils/deepUnref.d.ts +1 -1
- package/types/utils/getFakePk.d.ts +2 -2
- package/types/utils/isReactiveTyped.d.ts +2 -0
- package/types/utils/keyDiff.d.ts +4 -6
- package/types/utils/relatedCalculatedHelpers.d.ts +2 -0
- package/types/utils/watches.d.ts +1 -1
- package/use/cancellableIntent.js +36 -9
- package/use/combineClasses.js +2 -2
- package/use/error.js +10 -14
- package/use/list.js +6 -18
- package/use/listCalculated.js +28 -38
- package/use/listFilter.js +12 -24
- package/use/listInstance.js +101 -60
- package/use/listRelated.js +18 -37
- package/use/listSearch.js +9 -18
- package/use/listSort.js +95 -64
- package/use/listSubscription.js +19 -25
- package/use/loading.js +5 -7
- package/use/loadingError.js +3 -3
- package/use/object.js +14 -27
- package/use/objectCalculated.js +21 -25
- package/use/objectInstance.js +55 -50
- package/use/objectRelated.js +19 -25
- package/use/objectSubscription.js +18 -30
- package/use/proxyError.js +10 -10
- package/use/proxyLoading.js +5 -5
- package/use/proxyLoadingError.js +13 -8
- package/use/search.js +5 -11
- package/utils/assignReactiveObject.js +3 -3
- package/utils/cancellableFetch.js +3 -3
- package/utils/cancellablePromise.js +25 -8
- package/utils/classes.js +2 -2
- package/utils/deepUnref.js +1 -5
- package/utils/getFakePk.js +2 -2
- package/utils/isReactiveTyped.js +2 -0
- package/utils/keyDiff.js +1 -3
- package/utils/relatedCalculatedHelpers.js +2 -0
package/types/use/search.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A reactive object for passing document options or search options to useSearch.
|
|
3
|
-
*
|
|
4
|
-
* @typedef {object} SearchProps
|
|
2
|
+
* @typedef {object} SearchProps - A reactive object for passing document options or search options to useSearch.
|
|
5
3
|
* @property {DocumentOptions} customDocumentOptions - FlexSearch.Document options.
|
|
6
4
|
* @property {SearchOptions} customSearchOptions - Search options.
|
|
7
5
|
* @property {string} pkKey - The primary key field.
|
|
@@ -23,15 +21,15 @@ export function useSearch({ props, throttle }: {
|
|
|
23
21
|
*/
|
|
24
22
|
export type SearchProps = {
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
24
|
+
* FlexSearch.Document options.
|
|
27
25
|
*/
|
|
28
26
|
customDocumentOptions: DocumentOptions;
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
28
|
+
* Search options.
|
|
31
29
|
*/
|
|
32
30
|
customSearchOptions: SearchOptions;
|
|
33
31
|
/**
|
|
34
|
-
*
|
|
32
|
+
* The primary key field.
|
|
35
33
|
*/
|
|
36
34
|
pkKey: string;
|
|
37
35
|
};
|
|
@@ -40,7 +38,7 @@ export type SearchProps = {
|
|
|
40
38
|
*/
|
|
41
39
|
export type SearchOptions = {
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
41
|
+
* Limit of results.
|
|
44
42
|
*/
|
|
45
43
|
limit: number;
|
|
46
44
|
};
|
|
@@ -49,95 +47,101 @@ export type SearchOptions = {
|
|
|
49
47
|
*/
|
|
50
48
|
export type DocumentOptions = {
|
|
51
49
|
/**
|
|
52
|
-
*
|
|
50
|
+
* The document field to use as an identifier. Populated from `pkKey`.
|
|
53
51
|
*/
|
|
54
52
|
id: string;
|
|
55
53
|
/**
|
|
56
|
-
*
|
|
54
|
+
* The document field to use as a tag. Default is false, can be set to a string.
|
|
57
55
|
*/
|
|
58
56
|
tag: boolean | string;
|
|
59
57
|
/**
|
|
60
|
-
*
|
|
58
|
+
* Fields to index. Can be a single string, an array of strings, or an array of objects specifying custom index options.
|
|
61
59
|
*/
|
|
62
60
|
index: string | string[] | object[];
|
|
63
61
|
/**
|
|
64
|
-
*
|
|
62
|
+
* Specifies if and what document fields to store. Can be false, a string, or an array of strings. Default is false.
|
|
65
63
|
*/
|
|
66
64
|
store: boolean | string | string[];
|
|
67
65
|
/**
|
|
68
|
-
*
|
|
66
|
+
* Specifies the tokenizer to use.
|
|
69
67
|
*/
|
|
70
68
|
tokenizer?: string;
|
|
71
69
|
/**
|
|
72
|
-
*
|
|
70
|
+
* Minimum length of a token to be indexed.
|
|
73
71
|
*/
|
|
74
72
|
minLength?: number;
|
|
75
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* The raw reactive state of a search instance (query, results, status flags, and search options).
|
|
76
|
+
*/
|
|
76
77
|
export type SearchRawState = {
|
|
77
78
|
/**
|
|
78
|
-
*
|
|
79
|
+
* The search string.
|
|
79
80
|
*/
|
|
80
81
|
search: string;
|
|
81
82
|
/**
|
|
82
|
-
*
|
|
83
|
+
* The results, where the keys are the ids of the objects that match, and the values are true.
|
|
83
84
|
*/
|
|
84
85
|
results: object;
|
|
85
86
|
/**
|
|
86
|
-
*
|
|
87
|
+
* Whether the search has been performed.
|
|
87
88
|
*/
|
|
88
89
|
searched: boolean;
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
+
* Whether the search is currently running.
|
|
91
92
|
*/
|
|
92
93
|
searching: boolean;
|
|
93
94
|
/**
|
|
94
|
-
*
|
|
95
|
+
* FlexSearch.Document options.
|
|
95
96
|
*/
|
|
96
97
|
customDocumentOptions: DocumentOptions;
|
|
97
98
|
/**
|
|
98
|
-
*
|
|
99
|
+
* Search options.
|
|
99
100
|
*/
|
|
100
101
|
customSearchOptions: SearchOptions;
|
|
101
102
|
/**
|
|
102
|
-
*
|
|
103
|
+
* The number of times the search has been called.
|
|
103
104
|
*/
|
|
104
105
|
called: number;
|
|
105
106
|
/**
|
|
106
|
-
*
|
|
107
|
+
* The number of times the search has been called, but has not yet returned.
|
|
107
108
|
*/
|
|
108
109
|
pending: number;
|
|
109
110
|
/**
|
|
110
|
-
*
|
|
111
|
+
* Whether the search is currently running or has pending calls.
|
|
111
112
|
*/
|
|
112
113
|
running: boolean;
|
|
113
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* The reactive search instance returned by useSearch, exposing its state, index mutators, event target, and stop.
|
|
117
|
+
*/
|
|
114
118
|
export type SearchInstance = {
|
|
115
119
|
/**
|
|
116
|
-
*
|
|
120
|
+
* The state.
|
|
117
121
|
*/
|
|
118
122
|
state: import("vue").UnwrapNestedRefs<SearchRawState>;
|
|
119
123
|
/**
|
|
120
|
-
*
|
|
124
|
+
* Add an index.
|
|
121
125
|
*/
|
|
122
126
|
addIndex: Function;
|
|
123
127
|
/**
|
|
124
|
-
*
|
|
128
|
+
* Update an index.
|
|
125
129
|
*/
|
|
126
130
|
updateIndex: Function;
|
|
127
131
|
/**
|
|
128
|
-
*
|
|
132
|
+
* Remove an index.
|
|
129
133
|
*/
|
|
130
134
|
removeIndex: Function;
|
|
131
135
|
/**
|
|
132
|
-
*
|
|
136
|
+
* Clear the index.
|
|
133
137
|
*/
|
|
134
138
|
clearIndex: Function;
|
|
135
139
|
/**
|
|
136
|
-
*
|
|
140
|
+
* An event target.
|
|
137
141
|
*/
|
|
138
142
|
events: EventTarget;
|
|
139
143
|
/**
|
|
140
|
-
*
|
|
144
|
+
* Stop the effect scope.
|
|
141
145
|
*/
|
|
142
146
|
stop: Function;
|
|
143
147
|
};
|
|
@@ -111,4 +111,7 @@ export class AssignReactiveObjectError extends Error {
|
|
|
111
111
|
* and refs must ultimately resolve to objects or arrays
|
|
112
112
|
*/
|
|
113
113
|
export type ValidTargetOrSource = import("vue").Ref<object | any[]> | object | any[];
|
|
114
|
+
/**
|
|
115
|
+
* The validated target and source values returned by the reactive-object assignment validator.
|
|
116
|
+
*/
|
|
114
117
|
export type validateTargetAndSourceResult = object;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @param {RequestInfo} input - The URL or Request object to fetch.
|
|
6
6
|
* @param {RequestInit} init - The options for the fetch request.
|
|
7
7
|
* @param {(response: Response) => Promise<T>} transform - A function to transform the response.
|
|
8
|
-
* @returns {CancellablePromise<T>} A cancellable promise that resolves to the transformed response.
|
|
8
|
+
* @returns {import("./cancellablePromise.js").CancellablePromise<T>} A cancellable promise that resolves to the transformed response.
|
|
9
9
|
*/
|
|
10
|
-
export function cancellableFetch<T>(input: RequestInfo, init: RequestInit, transform: (response: Response) => Promise<T>): CancellablePromise<T>;
|
|
11
|
-
import { CancellablePromise } from "./cancellablePromise.js";
|
|
10
|
+
export function cancellableFetch<T>(input: RequestInfo, init: RequestInit, transform: (response: Response) => Promise<T>): import("./cancellablePromise.js").CancellablePromise<T>;
|
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A Promise that can be cancelled.
|
|
3
3
|
*
|
|
4
4
|
* @template T
|
|
5
|
-
* @
|
|
6
|
-
* @param {(() => Promise<void> | void)=} cancel - Optional cancel function.
|
|
7
|
-
* @returns {MaybeCancellablePromise<T>} The wrapped promise with an optional cancel method.
|
|
5
|
+
* @typedef {Promise<T> & { cancel: (reason?: any) => Promise<void> | void }} CancellablePromise - A promise augmented with a cancel method to abort the pending operation.
|
|
8
6
|
*/
|
|
9
|
-
export function wrapMaybeCancellable<T>(inner: Promise<T>, cancel?: (() => Promise<void> | void) | undefined): MaybeCancellablePromise<T>;
|
|
10
|
-
export function CancellablePromise<T>(promise: Promise<T>, cancel: () => (Promise<void> | void)): CancellablePromise<T>;
|
|
11
7
|
/**
|
|
12
|
-
* A
|
|
8
|
+
* A possibly cancellable promise.
|
|
9
|
+
*
|
|
10
|
+
* @template T
|
|
11
|
+
* @typedef {Promise<T> & { cancel?: (reason?: any) => Promise<void> | void }} MaybeCancellablePromise - A promise that may optionally carry a cancel method to abort the pending operation.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Adds a cancel method to a promise.
|
|
15
|
+
*
|
|
16
|
+
* @template T
|
|
17
|
+
* @param {Promise<T>} promise - The promise to make cancellable.
|
|
18
|
+
* @param {(reason?: any) => (Promise<void>|void)} cancel - The function to cancel the promise.
|
|
19
|
+
* @returns {CancellablePromise<T>} The cancellable promise.
|
|
20
|
+
*/
|
|
21
|
+
export function makeCancellable<T>(promise: Promise<T>, cancel: (reason?: any) => (Promise<void> | void)): CancellablePromise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Adds a cancel method to a promise.
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Use {@link makeCancellable} instead.
|
|
26
|
+
* @template T
|
|
27
|
+
* @param {Promise<T>} promise - The promise to make cancellable.
|
|
28
|
+
* @param {(reason?: any) => (Promise<void>|void)} cancel - The function to cancel the promise.
|
|
29
|
+
* @returns {CancellablePromise<T>} The cancellable promise.
|
|
30
|
+
*/
|
|
31
|
+
export function CancellablePromise<T>(promise: Promise<T>, cancel: (reason?: any) => (Promise<void> | void)): CancellablePromise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* A promise augmented with a cancel method to abort the pending operation.
|
|
13
34
|
*/
|
|
14
35
|
export type CancellablePromise<T> = Promise<T> & {
|
|
15
36
|
cancel: (reason?: any) => Promise<void> | void;
|
|
@@ -18,6 +39,8 @@ export namespace CancellablePromise {
|
|
|
18
39
|
/**
|
|
19
40
|
* Creates a rejected 'cancellable' promise.
|
|
20
41
|
*
|
|
42
|
+
* @deprecated Use `Promise.reject` directly; a plain rejected promise already
|
|
43
|
+
* satisfies {@link MaybeCancellablePromise}.
|
|
21
44
|
* @param {any} reason - The reason for the rejection.
|
|
22
45
|
* @returns {MaybeCancellablePromise<never>} A rejected 'cancellable' promise.
|
|
23
46
|
*/
|
|
@@ -25,6 +48,8 @@ export namespace CancellablePromise {
|
|
|
25
48
|
/**
|
|
26
49
|
* Creates a resolved 'cancellable' promise.
|
|
27
50
|
*
|
|
51
|
+
* @deprecated Use `Promise.resolve` directly; a plain resolved promise already
|
|
52
|
+
* satisfies {@link MaybeCancellablePromise}.
|
|
28
53
|
* @template T
|
|
29
54
|
* @param {T} value - The value to resolve the promise with.
|
|
30
55
|
* @returns {MaybeCancellablePromise<T>} A resolved 'cancellable' promise.
|
|
@@ -32,7 +57,16 @@ export namespace CancellablePromise {
|
|
|
32
57
|
function resolve<T_1>(value: T_1): MaybeCancellablePromise<T_1>;
|
|
33
58
|
}
|
|
34
59
|
/**
|
|
35
|
-
*
|
|
60
|
+
* Wraps a promise and optionally adds a cancel method if provided.
|
|
61
|
+
*
|
|
62
|
+
* @template T
|
|
63
|
+
* @param {Promise<T>} inner - The inner promise to wrap.
|
|
64
|
+
* @param {((reason?: any) => Promise<void> | void)=} cancel - Optional cancel function.
|
|
65
|
+
* @returns {MaybeCancellablePromise<T>} The wrapped promise with an optional cancel method.
|
|
66
|
+
*/
|
|
67
|
+
export function wrapMaybeCancellable<T>(inner: Promise<T>, cancel?: ((reason?: any) => Promise<void> | void) | undefined): MaybeCancellablePromise<T>;
|
|
68
|
+
/**
|
|
69
|
+
* A promise that may optionally carry a cancel method to abort the pending operation.
|
|
36
70
|
*/
|
|
37
71
|
export type MaybeCancellablePromise<T> = Promise<T> & {
|
|
38
72
|
cancel?: (reason?: any) => Promise<void> | void;
|
package/types/utils/classes.d.ts
CHANGED
|
@@ -5,12 +5,18 @@ export function combineClasses(...classes: (CombinedClassesArgument | CombinedCl
|
|
|
5
5
|
export function stringifyClasses(...classes: (CombinedClassesArgument | CombinedClassesArgument[])[]): string;
|
|
6
6
|
export function stringifyClass(cls: CombinedClassesArgument | CombinedClassesArgument[] | null | undefined): string | null | undefined;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* The normalized form of the CSS classes, either as a string of space-separated class names or an
|
|
9
9
|
*/
|
|
10
10
|
export type CombinedClasses = (string | {
|
|
11
11
|
[classnames: string]: boolean | import("vue").Ref<boolean>;
|
|
12
12
|
} | {
|
|
13
13
|
[classnames: string]: boolean | import("vue").Ref<boolean>;
|
|
14
14
|
}[]);
|
|
15
|
+
/**
|
|
16
|
+
* A boolean value or a Vue ref to a boolean.
|
|
17
|
+
*/
|
|
15
18
|
export type BooleanOrRef = boolean | import("vue").Ref<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* A single class-specifying argument accepted by combineClasses (a string, array, set, map, object, or ref).
|
|
21
|
+
*/
|
|
16
22
|
export type CombinedClassesArgument = string | string[] | Set<any> | Map<any, any> | object | import("vue").Ref<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function deepUnref<T>(val: T): DeepUnwrap<T> | T;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* A recursive type that unwraps Vue refs from a nested object, array, or primitive.
|
|
4
4
|
*/
|
|
5
5
|
export type DeepUnwrap<T> = T extends import("vue").Ref<infer U> ? DeepUnwrap<U> : T extends Array<infer V> ? Array<DeepUnwrap<V>> : T extends object ? { [K in keyof T]: DeepUnwrap<T[K]>; } : T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get a
|
|
3
|
-
*
|
|
2
|
+
* Get a random safe integer at or below zero and return it as a string. A candidate is redrawn when its numeric value
|
|
3
|
+
* exists in an array field, Set, or Map, or when its string property key exists in an object.
|
|
4
4
|
*
|
|
5
5
|
* @param {Array|Set|Map|object} arraySetMapOrObject - The array, set, map, or object to check for the fake pk.
|
|
6
6
|
* An array is assumed to be an array of objects.
|
package/types/utils/keyDiff.d.ts
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
* @module utils/keyDiff.js
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* Result object of keyDiff and keyDiffDeep.
|
|
9
|
-
*
|
|
10
|
-
* @typedef {object} KeyDiffResult
|
|
8
|
+
* @typedef {object} KeyDiffResult - Result object of keyDiff and keyDiffDeep.
|
|
11
9
|
* @property {Set<string>} [sameKeys] - If sameKeys option is true, return keys that are the same.
|
|
12
10
|
* @property {Set<string>} [removedKeys] - If removedKeys option is true, return keys that are removed.
|
|
13
11
|
* @property {Set<string>} [addedKeys] - If addedKeys option is true, return keys that are added.
|
|
@@ -48,15 +46,15 @@ export function keyDiffDeep(newObj: object, oldObj: object, options?: object): K
|
|
|
48
46
|
*/
|
|
49
47
|
export type KeyDiffResult = {
|
|
50
48
|
/**
|
|
51
|
-
*
|
|
49
|
+
* If sameKeys option is true, return keys that are the same.
|
|
52
50
|
*/
|
|
53
51
|
sameKeys?: Set<string>;
|
|
54
52
|
/**
|
|
55
|
-
*
|
|
53
|
+
* If removedKeys option is true, return keys that are removed.
|
|
56
54
|
*/
|
|
57
55
|
removedKeys?: Set<string>;
|
|
58
56
|
/**
|
|
59
|
-
*
|
|
57
|
+
* If addedKeys option is true, return keys that are added.
|
|
60
58
|
*/
|
|
61
59
|
addedKeys?: Set<string>;
|
|
62
60
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/** @internal */
|
|
1
2
|
export const relatedItemRegex: RegExp;
|
|
3
|
+
/** @internal */
|
|
2
4
|
export const calculatedItemRegex: RegExp;
|
|
3
5
|
export function getObjectRelatedCalculatedByKey(obj: object, relatedObj: object, calculatedObj: object, key: string): [object, string];
|
|
4
6
|
export function getObjectRelatedByKey(obj: object, relatedObj: object, key: string): [object, string];
|
package/types/utils/watches.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export class AwaitTimeout {
|
|
|
92
92
|
resolve: (value: any) => void;
|
|
93
93
|
reject: (reason?: any) => void;
|
|
94
94
|
timeout: number;
|
|
95
|
-
timeoutId:
|
|
95
|
+
timeoutId: number;
|
|
96
96
|
cancelledError: AwaitTimeoutError;
|
|
97
97
|
/**
|
|
98
98
|
* Starts the timeout process. If the timeout duration is reached without being stopped, the promise resolves.
|
package/use/cancellableIntent.js
CHANGED
|
@@ -56,9 +56,7 @@ export class CancellableIntentError extends Error {
|
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* The common run tracking arguments.
|
|
60
|
-
*
|
|
61
|
-
* @typedef {object} CommonRunTracking
|
|
59
|
+
* @typedef {object} CommonRunTracking - The common run tracking arguments.
|
|
62
60
|
* @property {RunId} runId - The unique identifier for your run.
|
|
63
61
|
* @property {IsCurrentRunFn} isCurrentRun - A function that checks if the current run ID matches your run ID.
|
|
64
62
|
*/
|
|
@@ -80,9 +78,7 @@ export class CancellableIntentError extends Error {
|
|
|
80
78
|
*/
|
|
81
79
|
|
|
82
80
|
/**
|
|
83
|
-
* Cancel function signature for cancellable intent.
|
|
84
|
-
*
|
|
85
|
-
* @typedef {Function} CancelFn
|
|
81
|
+
* @typedef {Function} CancelFn - Cancel function signature for cancellable intent.
|
|
86
82
|
* @param {any} reason - The reason for cancellation.
|
|
87
83
|
* @param {boolean} [forceClearActive=false] - Whether to force clear the active state.
|
|
88
84
|
* @returns {Promise<void>} - A promise that resolves when the cancellation is complete.
|
|
@@ -102,12 +98,19 @@ export class CancellableIntentError extends Error {
|
|
|
102
98
|
/**
|
|
103
99
|
* Calls your awaitable function with the arguments you pass in when the watch arguments change and are all truthy.
|
|
104
100
|
* Watch arguments should be a reactive object.
|
|
105
|
-
*
|
|
101
|
+
*
|
|
102
|
+
* If the watch arguments change again before the promise resolves, the in-flight promise is cancelled only when it
|
|
103
|
+
* carries a `cancel` method (a `MaybeCancellablePromise`); a plain promise is left to run to completion. That
|
|
104
|
+
* distinction is visible through the composables built on this one. `useObjectSubscription` calls
|
|
105
|
+
* `objectInstance.retrieve()` again for the new key, and that call returns the promise already in flight for the
|
|
106
|
+
* previous key, so the stale record is assigned and the new key is never fetched. `useListSubscription` guards its
|
|
107
|
+
* list intent on the list's own loading state, so the superseded run is left to finish and the list is then listed
|
|
108
|
+
* again with the current arguments.
|
|
106
109
|
*
|
|
107
110
|
* @example
|
|
108
111
|
* ```vue
|
|
109
112
|
* <script setup>
|
|
110
|
-
* import { useCancellableIntent } from "@
|
|
113
|
+
* import { useCancellableIntent } from "@arrai-innovations/reactive-helpers";
|
|
111
114
|
* import { ref, computed, onMounted, onUnmounted } from "vue";
|
|
112
115
|
*
|
|
113
116
|
* const myValue = ref(0);
|
|
@@ -184,7 +187,13 @@ export function useCancellableIntent({
|
|
|
184
187
|
guardArguments: readonly(internalState.guardArguments),
|
|
185
188
|
});
|
|
186
189
|
let previousWatchValues = null,
|
|
187
|
-
cancelFunction = null
|
|
190
|
+
cancelFunction = null,
|
|
191
|
+
// The run id whose in-flight promise `cancelFunction` would cancel. Paired with cancelFunction
|
|
192
|
+
// so a deliberate cancel can mark exactly which run it is tearing down.
|
|
193
|
+
cancelFunctionRunId = null;
|
|
194
|
+
// Run ids cancelled on purpose (via instance.cancel). Their promises reject with the cancel
|
|
195
|
+
// reason, which is not an error, so the run's catch handler skips setError for these.
|
|
196
|
+
const cancelledRunIds = new Set();
|
|
188
197
|
|
|
189
198
|
const doIntentWatch = () => {
|
|
190
199
|
loadingError.clearError();
|
|
@@ -225,8 +234,10 @@ export function useCancellableIntent({
|
|
|
225
234
|
|
|
226
235
|
if (awaitablePromise.cancel) {
|
|
227
236
|
cancelFunction = awaitablePromise.cancel.bind(awaitablePromise);
|
|
237
|
+
cancelFunctionRunId = thisRunId;
|
|
228
238
|
} else {
|
|
229
239
|
cancelFunction = null;
|
|
240
|
+
cancelFunctionRunId = null;
|
|
230
241
|
}
|
|
231
242
|
// we don't want to await this, because we want to be able to cancel it
|
|
232
243
|
awaitablePromise
|
|
@@ -237,11 +248,21 @@ export function useCancellableIntent({
|
|
|
237
248
|
}
|
|
238
249
|
})
|
|
239
250
|
.catch(async (err) => {
|
|
251
|
+
// A deliberate cancellation (instance.cancel) rejects this run's promise with the
|
|
252
|
+
// cancel reason; that is the intended outcome, not an error, so don't surface it.
|
|
253
|
+
if (cancelledRunIds.delete(thisRunId)) {
|
|
254
|
+
if (state.clearActiveOnResolved) {
|
|
255
|
+
internalState.activeCount--;
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
240
259
|
const cancelPromise = instance.cancel("Error in awaitableWithCancel", true);
|
|
241
260
|
loadingError.setError(err);
|
|
242
261
|
await cancelPromise;
|
|
243
262
|
})
|
|
244
263
|
.finally(() => {
|
|
264
|
+
// Drop any stale marker for this run (e.g. cancelled after it had already resolved).
|
|
265
|
+
cancelledRunIds.delete(thisRunId);
|
|
245
266
|
internalState.resolvingCount--;
|
|
246
267
|
});
|
|
247
268
|
};
|
|
@@ -316,7 +337,13 @@ export function useCancellableIntent({
|
|
|
316
337
|
cancel: async (/** @type {any} */ reason, forceClearActive = false) => {
|
|
317
338
|
if (cancelFunction) {
|
|
318
339
|
const toCancel = cancelFunction;
|
|
340
|
+
const runId = cancelFunctionRunId;
|
|
319
341
|
cancelFunction = null;
|
|
342
|
+
cancelFunctionRunId = null;
|
|
343
|
+
// Mark this run as deliberately cancelled so its rejection is not treated as an error.
|
|
344
|
+
if (runId !== null) {
|
|
345
|
+
cancelledRunIds.add(runId);
|
|
346
|
+
}
|
|
320
347
|
if (!state.clearActiveOnResolved || forceClearActive) {
|
|
321
348
|
internalState.activeCount--;
|
|
322
349
|
}
|
package/use/combineClasses.js
CHANGED
|
@@ -21,7 +21,7 @@ const isRefOrReactive = (v) => isRef(v) || isReactive(v);
|
|
|
21
21
|
* string[] |
|
|
22
22
|
* { [key: string]: boolean | import("vue").Ref<boolean> } |
|
|
23
23
|
* import("vue").Ref<string | string[]>
|
|
24
|
-
* )} CSSClasses
|
|
24
|
+
* )} CSSClasses - The accepted ways of specifying CSS classes to useCombineClasses (a string, array, class-map, or ref thereof).
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -32,7 +32,7 @@ const isRefOrReactive = (v) => isRef(v) || isReactive(v);
|
|
|
32
32
|
* @example
|
|
33
33
|
* ```vue
|
|
34
34
|
* <script setup>
|
|
35
|
-
* import { useCombineClasses } from "@
|
|
35
|
+
* import { useCombineClasses } from "@arrai-innovations/reactive-helpers";
|
|
36
36
|
* import { ref } from "vue";
|
|
37
37
|
* const myClasses = useCombineClasses(
|
|
38
38
|
* "class1",
|
package/use/error.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
import { readonly, ref } from "vue";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @typedef {() => void} ClearErrorFn
|
|
5
|
-
* @typedef {import("vue").Ref<Error|null>} ErrorRef
|
|
6
|
-
* @typedef {import("vue").Ref<boolean>} ErroredRef
|
|
7
|
-
* @typedef {Readonly<ErrorRef>} ErrorReadonlyRef
|
|
8
|
-
* @typedef {Readonly<ErroredRef>} ErroredReadonlyRef
|
|
4
|
+
* @typedef {() => void} ClearErrorFn - Signature for the function that clears the current error state.
|
|
5
|
+
* @typedef {import("vue").Ref<Error|null>} ErrorRef - A Vue ref holding the current error, or null when there is none.
|
|
6
|
+
* @typedef {import("vue").Ref<boolean>} ErroredRef - A Vue ref to the boolean indicating whether an error has occurred.
|
|
7
|
+
* @typedef {Readonly<ErrorRef>} ErrorReadonlyRef - A readonly Vue ref holding the current error, or null when there is none.
|
|
8
|
+
* @typedef {Readonly<ErroredRef>} ErroredReadonlyRef - A readonly Vue ref to the boolean indicating whether an error has occurred.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @typedef {object} ErrorProperties
|
|
12
|
+
* @typedef {object} ErrorProperties - The reactive error-state members (error and errored) contributed by the useError composable.
|
|
13
13
|
* @property {ErrorReadonlyRef} error - The error that occurred.
|
|
14
14
|
* @property {ErroredReadonlyRef} errored - Whether an error has occurred.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @typedef {object} ErrorFunctions
|
|
18
|
+
* @typedef {object} ErrorFunctions - The error-state actions (setError, clearError) contributed by the useError composable.
|
|
19
19
|
* @property {(error: Error) => void} setError - Set the error state.
|
|
20
20
|
* @property {ClearErrorFn} clearError - Clear the error state.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Proxies can still clear errors but cannot set them directly.
|
|
25
|
-
*
|
|
26
|
-
* @typedef {object} ErrorReadOnlyFunctions
|
|
24
|
+
* @typedef {object} ErrorReadOnlyFunctions - Proxies can still clear errors but cannot set them directly.
|
|
27
25
|
* @property {ClearErrorFn} clearError - Clear the error state.
|
|
28
26
|
*/
|
|
29
27
|
|
|
30
28
|
/**
|
|
31
|
-
* @typedef {ErrorProperties & ErrorReadOnlyFunctions} ReadonlyErrorStatus
|
|
29
|
+
* @typedef {ErrorProperties & ErrorReadOnlyFunctions} ReadonlyErrorStatus - The readonly error-state API (error and errored plus clearError) exposed to consumers and proxies.
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
|
-
* The error state API.
|
|
36
|
-
*
|
|
37
|
-
* @typedef {ErrorProperties & ErrorFunctions} ErrorStatus
|
|
33
|
+
* @typedef {ErrorProperties & ErrorFunctions} ErrorStatus - The error state API.
|
|
38
34
|
*/
|
|
39
35
|
|
|
40
36
|
/**
|
package/use/list.js
CHANGED
|
@@ -34,9 +34,7 @@ export class ListError extends Error {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Defines properties for configuring the list management system.
|
|
38
|
-
*
|
|
39
|
-
* @typedef {object} ListRawProps
|
|
37
|
+
* @typedef {object} ListRawProps - Defines properties for configuring the list management system.
|
|
40
38
|
* @property {object} params - The arguments to pass to the registered list crud handlers, related to the list itself.
|
|
41
39
|
* @property {string} pkKey - The primary key for the list items.
|
|
42
40
|
* @property {object} target - General arguments to pass to the registered list crud handlers, often related to endpoints.
|
|
@@ -54,7 +52,7 @@ export class ListError extends Error {
|
|
|
54
52
|
*/
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
|
-
* @typedef {object} ListOptions
|
|
55
|
+
* @typedef {object} ListOptions - The configuration options used to create a fully managed list via useList.
|
|
58
56
|
* @property {ListRawProps} props - The properties for configuring the list.
|
|
59
57
|
* @property {import('../config/listCrud.js').ListCrudHandlers} [handlers] - Additional handlers to be included in the list manager.
|
|
60
58
|
* @property {number} [searchThrottle] - The throttle time for text search.
|
|
@@ -63,8 +61,6 @@ export class ListError extends Error {
|
|
|
63
61
|
*/
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
|
-
* Holds references to instances of all list-related composables, facilitating direct access and management.
|
|
67
|
-
*
|
|
68
64
|
* @typedef {{
|
|
69
65
|
* listInstance: import('./listInstance.js').ListInstance,
|
|
70
66
|
* listSubscription: import('./listSubscription.js').ListSubscription,
|
|
@@ -73,33 +69,25 @@ export class ListError extends Error {
|
|
|
73
69
|
* listFilter: import('./listFilter.js').ListFilter,
|
|
74
70
|
* listSearch: import('./listSearch.js').ListSearch,
|
|
75
71
|
* listSort: import('./listSort.js').ListSort
|
|
76
|
-
* }} ListManaged
|
|
72
|
+
* }} ListManaged - Holds references to instances of all list-related composables, facilitating direct access and management.
|
|
77
73
|
*/
|
|
78
74
|
|
|
79
75
|
/**
|
|
80
|
-
* Aggregates all functions provided by various list-related composables, allowing for a unified approach to calling these methods.
|
|
81
|
-
*
|
|
82
76
|
* @typedef {(
|
|
83
77
|
* import('./listInstance.js').ListInstanceFunctions
|
|
84
78
|
* & import('./listSubscription.js').ListSubscriptionFunctions
|
|
85
|
-
* )} ListFunctions
|
|
79
|
+
* )} ListFunctions - Aggregates all functions provided by various list-related composables, allowing for a unified approach to calling these methods.
|
|
86
80
|
*/
|
|
87
81
|
|
|
88
82
|
/**
|
|
89
|
-
* Encapsulates properties relevant to the overall management of list-related hooks, including state, direct access to hooks,
|
|
90
|
-
* and scoped effects.
|
|
91
|
-
*
|
|
92
|
-
* @typedef {object} ListManagerProperties
|
|
83
|
+
* @typedef {object} ListManagerProperties - Encapsulates properties relevant to the overall management of list-related hooks, including state, direct access to hooks, and scoped effects.
|
|
93
84
|
* @property {ListManaged} managed - A readonly reference to the managed list hooks.
|
|
94
85
|
* @property {import('./listSort.js').ListSortState} state - Represents the final reactive state in the list processing chain.
|
|
95
86
|
* @property {() => void} stop - A function to stop the effect scope and clean up resources.
|
|
96
87
|
*/
|
|
97
88
|
|
|
98
89
|
/**
|
|
99
|
-
* Combines functionality and properties to represent a fully managed list instance,
|
|
100
|
-
* orchestrating various functionalities such as sorting, searching, filtering, and state management.
|
|
101
|
-
*
|
|
102
|
-
* @typedef {ListFunctions & ListManagerProperties} ListManager
|
|
90
|
+
* @typedef {ListFunctions & ListManagerProperties} ListManager - Combines functionality and properties to represent a fully managed list instance, orchestrating various functionalities such as sorting, searching, filtering, and state management.
|
|
103
91
|
*/
|
|
104
92
|
|
|
105
93
|
/* eslint-disable jsdoc/valid-types */
|