@arrai-innovations/reactive-helpers 18.0.2 → 18.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/listCrud.js +1 -1
- package/config/objectCrud.js +129 -47
- package/index.js +3 -0
- package/package.json +2 -2
- package/types/config/listCrud.d.ts +1 -1
- package/types/config/objectCrud.d.ts +99 -33
- package/types/config/objectCrud.d.ts.map +1 -1
- package/types/index.d.ts +3 -0
- package/types/use/cancellableIntent.d.ts +2 -13
- package/types/use/cancellableIntent.d.ts.map +1 -1
- package/types/use/listInstance.d.ts +2 -2
- package/types/use/listInstance.d.ts.map +1 -1
- package/types/use/loadingError.d.ts +30 -6
- package/types/use/loadingError.d.ts.map +1 -1
- package/types/use/objectInstance.d.ts +83 -31
- package/types/use/objectInstance.d.ts.map +1 -1
- package/types/use/objectSubscription.d.ts +33 -29
- package/types/use/objectSubscription.d.ts.map +1 -1
- package/types/use/proxyLoadingError.d.ts +8 -23
- package/types/use/proxyLoadingError.d.ts.map +1 -1
- package/types/utils/cancellableFetch.d.ts +12 -0
- package/types/utils/cancellableFetch.d.ts.map +1 -0
- package/types/utils/cancellablePromise.d.ts +40 -0
- package/types/utils/cancellablePromise.d.ts.map +1 -0
- package/types/utils/deepUnref.d.ts +26 -0
- package/types/utils/deepUnref.d.ts.map +1 -0
- package/use/cancellableIntent.js +8 -13
- package/use/listInstance.js +39 -40
- package/use/listSearch.js +1 -1
- package/use/loadingError.js +30 -6
- package/use/objectInstance.js +225 -125
- package/use/objectSubscription.js +81 -82
- package/use/proxyLoadingError.js +14 -27
- package/use/search.js +1 -1
- package/utils/cancellableFetch.js +22 -0
- package/utils/cancellablePromise.js +70 -0
- package/utils/classes.js +5 -5
- package/utils/deepUnref.js +28 -0
package/config/listCrud.js
CHANGED
|
@@ -86,7 +86,7 @@ const defaultCrud = {
|
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* @typedef {(ExecuteActionFnArgs)=>Promise<import('./objectCrud.js').
|
|
89
|
+
* @typedef {(ExecuteActionFnArgs)=>Promise<import('./objectCrud.js').CrudResponse|false> & { cancel: () => Promise<void>|void }} ExecuteActionFn - The function to execute a certain action on a list of items, returning the response data or false.
|
|
90
90
|
*/
|
|
91
91
|
|
|
92
92
|
/**
|
package/config/objectCrud.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { addOrUpdateReactiveObject } from "../utils/assignReactiveObject.js";
|
|
2
2
|
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
3
3
|
import isFunction from "lodash-es/isFunction.js";
|
|
4
|
-
import { isReactive, toRef } from "vue";
|
|
4
|
+
import { isReactive, readonly, toRef } from "vue";
|
|
5
|
+
import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Configuration for the default object crud functions.
|
|
@@ -9,89 +10,160 @@ import { isReactive, toRef } from "vue";
|
|
|
9
10
|
* @module config/objectCrud.js
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @template T
|
|
15
|
+
* @param {string} name - The name of the method.
|
|
16
|
+
* @returns {(...args:any[]) => import('../utils/cancellablePromise.js')
|
|
17
|
+
* .MaybeCancellablePromise<T>} - A function that returns a rejected promise with an error message.
|
|
18
|
+
*/
|
|
19
|
+
const missingMethod = (name) => () => {
|
|
20
|
+
return CancellablePromise.reject(new Error(`Crud method "${name}" is not implemented.`));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @template T
|
|
25
|
+
* @param {string} name - The name of the method.
|
|
26
|
+
* @returns {(...args:any[]) => import('../utils/cancellablePromise.js')
|
|
27
|
+
* .CancellablePromise<T>} - A function that returns a rejected promise with an error message.
|
|
28
|
+
*/
|
|
29
|
+
const requiredCancelMissingMethod = (name) => () => {
|
|
30
|
+
return CancellablePromise(
|
|
31
|
+
new Promise(() => {
|
|
32
|
+
return Promise.reject(new Error(`Crud method "${name}" is not implemented.`));
|
|
33
|
+
}),
|
|
34
|
+
() => {
|
|
35
|
+
// do nothing
|
|
36
|
+
}
|
|
37
|
+
);
|
|
20
38
|
};
|
|
21
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {{[key:string]: any}} ObjectCrudArgsArgs
|
|
42
|
+
*/
|
|
43
|
+
|
|
22
44
|
/**
|
|
23
45
|
* Defines the CRUD-related functions and additional utilities provided by the object instance.
|
|
24
46
|
*
|
|
25
47
|
* @typedef {object} ObjectCrudArgsProperties
|
|
26
|
-
* @property {
|
|
48
|
+
* @property {ObjectCrudArgsArgs} args - The arguments to be passed to the crud functions.
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {object} ObjectCrudArgsOption
|
|
53
|
+
* @property {ObjectCrudArgsArgs} [crudArgs={}] - The arguments to be passed to the crud functions.
|
|
27
54
|
*/
|
|
28
55
|
|
|
29
56
|
/**
|
|
30
57
|
* @typedef {object} CreateDetailArgs
|
|
31
|
-
* @property {
|
|
32
|
-
* @property {
|
|
33
|
-
* @property {
|
|
58
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
59
|
+
* @property {{[key:string]: any}} object - The data to be acted upon.
|
|
60
|
+
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
34
61
|
* @property {string} pkKey - The key name of the primary key.
|
|
62
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
35
63
|
*/
|
|
36
64
|
|
|
37
65
|
/**
|
|
38
66
|
* @typedef {object} RetrieveDetailArgs
|
|
39
|
-
* @property {
|
|
67
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
40
68
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
41
69
|
* @property {string} pkKey - The key name of the primary key.
|
|
42
|
-
* @property {
|
|
70
|
+
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
71
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
43
72
|
*/
|
|
44
73
|
|
|
45
74
|
/**
|
|
46
75
|
* @typedef {object} UpdateDetailArgs
|
|
47
|
-
* @property {
|
|
48
|
-
* @property {import('../use/objectInstance.js').
|
|
49
|
-
* @property {
|
|
76
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
77
|
+
* @property {import('../use/objectInstance.js').ExistingCrudObject} object - The data to be acted upon.
|
|
78
|
+
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
50
79
|
* @property {string} pkKey - The key name of the primary key.
|
|
80
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
51
81
|
*/
|
|
52
82
|
|
|
53
83
|
/**
|
|
54
84
|
* @typedef {object} DeleteDetailArgs
|
|
55
|
-
* @property {
|
|
85
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
56
86
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
57
87
|
* @property {string} pkKey - The key name of the primary key.
|
|
58
|
-
* @property {
|
|
88
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
59
89
|
*/
|
|
60
90
|
|
|
61
91
|
/**
|
|
62
92
|
* @typedef {object} PartialDetailArgs
|
|
63
|
-
* @property {
|
|
93
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
64
94
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
65
95
|
* @property {string} pkKey - The key name of the primary key.
|
|
66
|
-
* @property {
|
|
67
|
-
* @property {
|
|
96
|
+
* @property {{[key:string]: any}} partialObject - The data to be acted upon.
|
|
97
|
+
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
98
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @callback CrudSubscribeCallback
|
|
103
|
+
* @param {import('../use/objectInstance.js').ExistingCrudObject} data - The data to be passed to the callback.
|
|
104
|
+
* @param {string} action - The action that was performed.
|
|
68
105
|
*/
|
|
69
106
|
|
|
70
107
|
/**
|
|
71
108
|
* @typedef {object} SubscribeArgs
|
|
72
|
-
* @property {
|
|
109
|
+
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
73
110
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
74
111
|
* @property {string} pkKey - The key name of the primary key.
|
|
75
|
-
* @property {
|
|
76
|
-
* @property {
|
|
77
|
-
*
|
|
78
|
-
|
|
112
|
+
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
113
|
+
* @property {CrudSubscribeCallback} callback - The callback to be called when the object is updated.
|
|
114
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to indicate if the request was cancelled.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @typedef {import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string>} CrudResponse
|
|
79
119
|
*/
|
|
80
120
|
|
|
81
121
|
/**
|
|
82
|
-
* @
|
|
122
|
+
* @callback CrudCreateFn
|
|
123
|
+
* @param {CreateDetailArgs} args - The arguments to be passed to the create function.
|
|
124
|
+
* @returns {CrudResponse} - The response data from the create function.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @callback CrudRetrieveFn
|
|
129
|
+
* @param {RetrieveDetailArgs} args - The arguments to be passed to the retrieve function.
|
|
130
|
+
* @returns {CrudResponse} - The response data from the retrieve function.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @callback CrudUpdateFn
|
|
135
|
+
* @param {UpdateDetailArgs} args - The arguments to be passed to the update function.
|
|
136
|
+
* @returns {CrudResponse} - The response data from the update function.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @callback CrudPatchFn
|
|
141
|
+
* @param {PartialDetailArgs} args - The arguments to be passed to the patch function.
|
|
142
|
+
* @returns {CrudResponse} - The response data from the patch function.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @callback CrudDeleteFn
|
|
147
|
+
* @param {DeleteDetailArgs} args - The arguments to be passed to the delete function.
|
|
148
|
+
* @returns {CrudResponse} - The response data from the delete function.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @callback CrudSubscribeFn
|
|
153
|
+
* @param {SubscribeArgs} args - The arguments to be passed to the subscribe function.
|
|
154
|
+
* @returns {import('../utils/cancellablePromise.js').CancellablePromise<void>} - The cancellable promise.
|
|
83
155
|
*/
|
|
84
156
|
|
|
85
157
|
/**
|
|
86
158
|
* Defines the CRUD-related functions and additional utilities provided by the object instance.
|
|
87
159
|
*
|
|
88
160
|
* @typedef {object} ObjectCrudFunctions
|
|
89
|
-
* @property {
|
|
90
|
-
* @property {
|
|
91
|
-
* @property {
|
|
92
|
-
* @property {
|
|
93
|
-
* @property {
|
|
94
|
-
* @property {
|
|
161
|
+
* @property {CrudCreateFn} [create] - A function to be used instead of the default crud create function.
|
|
162
|
+
* @property {CrudRetrieveFn} [retrieve] - A function to be used instead of the default crud retrieve function.
|
|
163
|
+
* @property {CrudUpdateFn} [update] - A function to be used instead of the default crud update function.
|
|
164
|
+
* @property {CrudDeleteFn} [delete] - A function to be used instead of the default crud delete function.
|
|
165
|
+
* @property {CrudPatchFn} [patch] - A function to be used instead of the default crud patch function.
|
|
166
|
+
* @property {CrudSubscribeFn} [subscribe] - A function to be used instead of the default crud subscribe function.
|
|
95
167
|
*/
|
|
96
168
|
|
|
97
169
|
/**
|
|
@@ -101,6 +173,18 @@ const defaultCrud = {
|
|
|
101
173
|
*
|
|
102
174
|
*/
|
|
103
175
|
|
|
176
|
+
const _defaultCrud = {
|
|
177
|
+
args: {},
|
|
178
|
+
retrieve: /** @type {CrudRetrieveFn} */ missingMethod("retrieve"),
|
|
179
|
+
create: /** @type {CrudCreateFn} */ missingMethod("create"),
|
|
180
|
+
update: /** @type {CrudUpdateFn} */ missingMethod("update"),
|
|
181
|
+
patch: /** @type {CrudPatchFn} */ missingMethod("patch"),
|
|
182
|
+
delete: /** @type {CrudDeleteFn} */ missingMethod("delete"),
|
|
183
|
+
subscribe: /** @type {CrudSubscribeFn} */ requiredCancelMissingMethod("subscribe"),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const defaultCrud = readonly(_defaultCrud);
|
|
187
|
+
|
|
104
188
|
/**
|
|
105
189
|
* Set the object crud functions.
|
|
106
190
|
*
|
|
@@ -108,14 +192,14 @@ const defaultCrud = {
|
|
|
108
192
|
* @throws {Error} - if unknown keys are passed.
|
|
109
193
|
*/
|
|
110
194
|
export const setObjectCrud = ({ retrieve, create, update, patch, delete: deleteFn, subscribe, args = {}, ...rest }) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
195
|
+
_defaultCrud.retrieve = retrieve ?? missingMethod("retrieve");
|
|
196
|
+
_defaultCrud.create = create ?? missingMethod("create");
|
|
197
|
+
_defaultCrud.update = update ?? missingMethod("update");
|
|
198
|
+
_defaultCrud.patch = patch ?? missingMethod("patch");
|
|
199
|
+
_defaultCrud.delete = deleteFn ?? missingMethod("delete");
|
|
200
|
+
_defaultCrud.subscribe = subscribe ?? requiredCancelMissingMethod("subscribe");
|
|
117
201
|
// defensive cloning
|
|
118
|
-
Object.assign(
|
|
202
|
+
Object.assign(_defaultCrud.args, cloneDeep(args));
|
|
119
203
|
if (Object.keys(rest).length) {
|
|
120
204
|
throw new Error(`Unknown key(s) passed to setObjectCrud: ${Object.keys(rest).join(", ")}`);
|
|
121
205
|
}
|
|
@@ -124,17 +208,15 @@ export const setObjectCrud = ({ retrieve, create, update, patch, delete: deleteF
|
|
|
124
208
|
/**
|
|
125
209
|
* Get the previously set object crud functions.
|
|
126
210
|
*
|
|
127
|
-
* @param {import("vue").UnwrapNestedRefs<
|
|
211
|
+
* @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>} reactiveCrud - The reactive object you want to add the resulting crud to.
|
|
128
212
|
* @param {object} options - The options for the reactive crud object.
|
|
129
|
-
* @param {import("vue").UnwrapNestedRefs<
|
|
130
|
-
* crudArgs: ObjectCrudArgsProperties|undefined,
|
|
131
|
-
* }>} [options.props] - The props with any passed crudArgs.
|
|
213
|
+
* @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsOption>} [options.props] - The props with any passed crudArgs.
|
|
132
214
|
* @param {ObjectCrudFunctions} [options.functions] - Any functions to override the default crud functions.
|
|
133
215
|
* @throws {Error} - If an invalid function is passed, or if the function is not a function.
|
|
134
216
|
*/
|
|
135
217
|
export const getObjectCrud = (reactiveCrud, { props, functions } = {}) => {
|
|
136
218
|
// don't mutate the default crud
|
|
137
|
-
Object.assign(reactiveCrud, cloneDeep(
|
|
219
|
+
Object.assign(reactiveCrud, cloneDeep(_defaultCrud));
|
|
138
220
|
if (props?.crudArgs) {
|
|
139
221
|
addOrUpdateReactiveObject(reactiveCrud.args, props.crudArgs);
|
|
140
222
|
}
|
package/index.js
CHANGED
|
@@ -23,8 +23,11 @@ export * from "./use/proxyLoadingError.js";
|
|
|
23
23
|
export * from "./use/search.js";
|
|
24
24
|
export * from "./use/watchesRunning.js";
|
|
25
25
|
export * from "./utils/assignReactiveObject.js";
|
|
26
|
+
export * from "./utils/cancellableFetch.js";
|
|
27
|
+
export * from "./utils/cancellablePromise.js";
|
|
26
28
|
export * from "./utils/classes.js";
|
|
27
29
|
export * from "./utils/compact.js";
|
|
30
|
+
export * from "./utils/deepUnref.js";
|
|
28
31
|
export * from "./utils/deleteKey.js";
|
|
29
32
|
export * from "./utils/flattenPaths.js";
|
|
30
33
|
export * from "./utils/getFakePk.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrai-innovations/reactive-helpers",
|
|
3
|
-
"version": "18.0
|
|
3
|
+
"version": "18.1.0",
|
|
4
4
|
"description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"prettier": "npx --no-install prettier --write .",
|
|
31
31
|
"coverage": "npm test -- run --coverage=true",
|
|
32
32
|
"prepare": "npx --no-install husky",
|
|
33
|
-
"docs": "
|
|
33
|
+
"docs": "node make_type_doc.js"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
@@ -123,7 +123,7 @@ export type SubscribeFn = (SubscribeFnArgs: any) => Promise<boolean> & {
|
|
|
123
123
|
/**
|
|
124
124
|
* - The function to execute a certain action on a list of items, returning the response data or false.
|
|
125
125
|
*/
|
|
126
|
-
export type ExecuteActionFn = (ExecuteActionFnArgs: any) => Promise<import("./objectCrud.js").
|
|
126
|
+
export type ExecuteActionFn = (ExecuteActionFnArgs: any) => Promise<import("./objectCrud.js").CrudResponse | false> & {
|
|
127
127
|
cancel: () => Promise<void> | void;
|
|
128
128
|
};
|
|
129
129
|
export type ListCrudFunctions = {
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
export const defaultCrud: {
|
|
2
|
+
readonly args: {};
|
|
3
|
+
readonly retrieve: (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
4
|
+
readonly create: (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
5
|
+
readonly update: (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
6
|
+
readonly patch: (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
7
|
+
readonly delete: (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
8
|
+
readonly subscribe: (...args: any[]) => CancellablePromise<any>;
|
|
9
|
+
};
|
|
1
10
|
export function setObjectCrud({ retrieve, create, update, patch, delete: deleteFn, subscribe, args, ...rest }: ObjectCrudArgs): void;
|
|
2
|
-
export function getObjectCrud(reactiveCrud: import("vue").UnwrapNestedRefs<
|
|
3
|
-
props?: import("vue").UnwrapNestedRefs<
|
|
4
|
-
crudArgs: ObjectCrudArgsProperties | undefined;
|
|
5
|
-
}>;
|
|
11
|
+
export function getObjectCrud(reactiveCrud: import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>, { props, functions }?: {
|
|
12
|
+
props?: import("vue").UnwrapNestedRefs<ObjectCrudArgsOption>;
|
|
6
13
|
functions?: ObjectCrudFunctions;
|
|
7
14
|
}): void;
|
|
15
|
+
export type ObjectCrudArgsArgs = {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
8
18
|
/**
|
|
9
19
|
* Defines the CRUD-related functions and additional utilities provided by the object instance.
|
|
10
20
|
*/
|
|
@@ -12,31 +22,49 @@ export type ObjectCrudArgsProperties = {
|
|
|
12
22
|
/**
|
|
13
23
|
* - The arguments to be passed to the crud functions.
|
|
14
24
|
*/
|
|
15
|
-
args
|
|
25
|
+
args: ObjectCrudArgsArgs;
|
|
26
|
+
};
|
|
27
|
+
export type ObjectCrudArgsOption = {
|
|
28
|
+
/**
|
|
29
|
+
* - The arguments to be passed to the crud functions.
|
|
30
|
+
*/
|
|
31
|
+
crudArgs?: ObjectCrudArgsArgs;
|
|
16
32
|
};
|
|
17
33
|
export type CreateDetailArgs = {
|
|
18
34
|
/**
|
|
19
35
|
* - The arguments to be passed to the crud functions.
|
|
20
36
|
*/
|
|
21
|
-
crudArgs:
|
|
37
|
+
crudArgs: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
};
|
|
22
40
|
/**
|
|
23
41
|
* - The data to be acted upon.
|
|
24
42
|
*/
|
|
25
|
-
object:
|
|
43
|
+
object: {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
};
|
|
26
46
|
/**
|
|
27
47
|
* - The arguments to be passed to the retrieve function.
|
|
28
48
|
*/
|
|
29
|
-
retrieveArgs:
|
|
49
|
+
retrieveArgs: {
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
};
|
|
30
52
|
/**
|
|
31
53
|
* - The key name of the primary key.
|
|
32
54
|
*/
|
|
33
55
|
pkKey: string;
|
|
56
|
+
/**
|
|
57
|
+
* - A ref to indicate if the request was cancelled.
|
|
58
|
+
*/
|
|
59
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
34
60
|
};
|
|
35
61
|
export type RetrieveDetailArgs = {
|
|
36
62
|
/**
|
|
37
63
|
* - The arguments to be passed to the crud functions.
|
|
38
64
|
*/
|
|
39
|
-
crudArgs:
|
|
65
|
+
crudArgs: {
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
};
|
|
40
68
|
/**
|
|
41
69
|
* - The pk of the object to be acted upon.
|
|
42
70
|
*/
|
|
@@ -48,31 +76,47 @@ export type RetrieveDetailArgs = {
|
|
|
48
76
|
/**
|
|
49
77
|
* - The arguments to be passed to the retrieve function.
|
|
50
78
|
*/
|
|
51
|
-
retrieveArgs:
|
|
79
|
+
retrieveArgs: {
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* - A ref to indicate if the request was cancelled.
|
|
84
|
+
*/
|
|
85
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
52
86
|
};
|
|
53
87
|
export type UpdateDetailArgs = {
|
|
54
88
|
/**
|
|
55
89
|
* - The arguments to be passed to the crud functions.
|
|
56
90
|
*/
|
|
57
|
-
crudArgs:
|
|
91
|
+
crudArgs: {
|
|
92
|
+
[key: string]: any;
|
|
93
|
+
};
|
|
58
94
|
/**
|
|
59
95
|
* - The data to be acted upon.
|
|
60
96
|
*/
|
|
61
|
-
object: import("../use/objectInstance.js").
|
|
97
|
+
object: import("../use/objectInstance.js").ExistingCrudObject;
|
|
62
98
|
/**
|
|
63
99
|
* - The arguments to be passed to the retrieve function.
|
|
64
100
|
*/
|
|
65
|
-
retrieveArgs:
|
|
101
|
+
retrieveArgs: {
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
};
|
|
66
104
|
/**
|
|
67
105
|
* - The key name of the primary key.
|
|
68
106
|
*/
|
|
69
107
|
pkKey: string;
|
|
108
|
+
/**
|
|
109
|
+
* - A ref to indicate if the request was cancelled.
|
|
110
|
+
*/
|
|
111
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
70
112
|
};
|
|
71
113
|
export type DeleteDetailArgs = {
|
|
72
114
|
/**
|
|
73
115
|
* - The arguments to be passed to the crud functions.
|
|
74
116
|
*/
|
|
75
|
-
crudArgs:
|
|
117
|
+
crudArgs: {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
};
|
|
76
120
|
/**
|
|
77
121
|
* - The pk of the object to be acted upon.
|
|
78
122
|
*/
|
|
@@ -82,15 +126,17 @@ export type DeleteDetailArgs = {
|
|
|
82
126
|
*/
|
|
83
127
|
pkKey: string;
|
|
84
128
|
/**
|
|
85
|
-
* -
|
|
129
|
+
* - A ref to indicate if the request was cancelled.
|
|
86
130
|
*/
|
|
87
|
-
|
|
131
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
88
132
|
};
|
|
89
133
|
export type PartialDetailArgs = {
|
|
90
134
|
/**
|
|
91
135
|
* - The arguments to be passed to the crud functions.
|
|
92
136
|
*/
|
|
93
|
-
crudArgs:
|
|
137
|
+
crudArgs: {
|
|
138
|
+
[key: string]: any;
|
|
139
|
+
};
|
|
94
140
|
/**
|
|
95
141
|
* - The pk of the object to be acted upon.
|
|
96
142
|
*/
|
|
@@ -102,17 +148,28 @@ export type PartialDetailArgs = {
|
|
|
102
148
|
/**
|
|
103
149
|
* - The data to be acted upon.
|
|
104
150
|
*/
|
|
105
|
-
partialObject:
|
|
151
|
+
partialObject: {
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
};
|
|
106
154
|
/**
|
|
107
155
|
* - The arguments to be passed to the retrieve function.
|
|
108
156
|
*/
|
|
109
|
-
retrieveArgs:
|
|
157
|
+
retrieveArgs: {
|
|
158
|
+
[key: string]: any;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* - A ref to indicate if the request was cancelled.
|
|
162
|
+
*/
|
|
163
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
110
164
|
};
|
|
165
|
+
export type CrudSubscribeCallback = (data: import("../use/objectInstance.js").ExistingCrudObject, action: string) => any;
|
|
111
166
|
export type SubscribeArgs = {
|
|
112
167
|
/**
|
|
113
168
|
* - The arguments to be passed to the crud functions.
|
|
114
169
|
*/
|
|
115
|
-
crudArgs:
|
|
170
|
+
crudArgs: {
|
|
171
|
+
[key: string]: any;
|
|
172
|
+
};
|
|
116
173
|
/**
|
|
117
174
|
* - The pk of the object to be acted upon.
|
|
118
175
|
*/
|
|
@@ -124,15 +181,25 @@ export type SubscribeArgs = {
|
|
|
124
181
|
/**
|
|
125
182
|
* - The arguments to be passed to the retrieve function.
|
|
126
183
|
*/
|
|
127
|
-
retrieveArgs:
|
|
184
|
+
retrieveArgs: {
|
|
185
|
+
[key: string]: any;
|
|
186
|
+
};
|
|
128
187
|
/**
|
|
129
188
|
* - The callback to be called when the object is updated.
|
|
130
189
|
*/
|
|
131
|
-
callback:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
190
|
+
callback: CrudSubscribeCallback;
|
|
191
|
+
/**
|
|
192
|
+
* - A ref to indicate if the request was cancelled.
|
|
193
|
+
*/
|
|
194
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
135
195
|
};
|
|
196
|
+
export type CrudResponse = import("../utils/cancellablePromise.js").MaybeCancellablePromise<object | string>;
|
|
197
|
+
export type CrudCreateFn = (args: CreateDetailArgs) => CrudResponse;
|
|
198
|
+
export type CrudRetrieveFn = (args: RetrieveDetailArgs) => CrudResponse;
|
|
199
|
+
export type CrudUpdateFn = (args: UpdateDetailArgs) => CrudResponse;
|
|
200
|
+
export type CrudPatchFn = (args: PartialDetailArgs) => CrudResponse;
|
|
201
|
+
export type CrudDeleteFn = (args: DeleteDetailArgs) => CrudResponse;
|
|
202
|
+
export type CrudSubscribeFn = (args: SubscribeArgs) => import("../utils/cancellablePromise.js").CancellablePromise<void>;
|
|
136
203
|
/**
|
|
137
204
|
* Defines the CRUD-related functions and additional utilities provided by the object instance.
|
|
138
205
|
*/
|
|
@@ -140,32 +207,31 @@ export type ObjectCrudFunctions = {
|
|
|
140
207
|
/**
|
|
141
208
|
* - A function to be used instead of the default crud create function.
|
|
142
209
|
*/
|
|
143
|
-
create?:
|
|
210
|
+
create?: CrudCreateFn;
|
|
144
211
|
/**
|
|
145
212
|
* - A function to be used instead of the default crud retrieve function.
|
|
146
213
|
*/
|
|
147
|
-
retrieve?:
|
|
214
|
+
retrieve?: CrudRetrieveFn;
|
|
148
215
|
/**
|
|
149
216
|
* - A function to be used instead of the default crud update function.
|
|
150
217
|
*/
|
|
151
|
-
update?:
|
|
218
|
+
update?: CrudUpdateFn;
|
|
152
219
|
/**
|
|
153
220
|
* - A function to be used instead of the default crud delete function.
|
|
154
221
|
*/
|
|
155
|
-
delete?:
|
|
222
|
+
delete?: CrudDeleteFn;
|
|
156
223
|
/**
|
|
157
224
|
* - A function to be used instead of the default crud patch function.
|
|
158
225
|
*/
|
|
159
|
-
patch?:
|
|
226
|
+
patch?: CrudPatchFn;
|
|
160
227
|
/**
|
|
161
228
|
* - A function to be used instead of the default crud subscribe function.
|
|
162
229
|
*/
|
|
163
|
-
subscribe?:
|
|
164
|
-
cancel: () => Promise<void> | void;
|
|
165
|
-
};
|
|
230
|
+
subscribe?: CrudSubscribeFn;
|
|
166
231
|
};
|
|
167
232
|
/**
|
|
168
233
|
* The CRUD arguments.
|
|
169
234
|
*/
|
|
170
235
|
export type ObjectCrudArgs = ObjectCrudArgsProperties & ObjectCrudFunctions;
|
|
236
|
+
import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
171
237
|
//# sourceMappingURL=objectCrud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectCrud.d.ts","sourceRoot":"","sources":["../../config/objectCrud.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"objectCrud.d.ts","sourceRoot":"","sources":["../../config/objectCrud.js"],"names":[],"mappings":"AAyLA;;iCA1KsB,GAAG,EAAE;+BAAL,GAAG,EAAE;+BAAL,GAAG,EAAE;8BAAL,GAAG,EAAE;+BAAL,GAAG,EAAE;kCAUL,GAAG,EAAE;EAgKuB;AAQ3C,+GAHI,cAAc,QAexB;AAWM,4CANI,OAAO,KAAK,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,yBAEhE;IAAuE,KAAK,GAApE,OAAO,KAAK,EAAE,gBAAgB,CAAC,oBAAoB,CAAC;IACtB,SAAS,GAAvC,mBAAmB;CAC3B,QAoBF;iCAlMY;IAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;CAAC;;;;;;;;UAOlB,kBAAkB;;;;;;eAKlB,kBAAkB;;;;;;cAKlB;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;YACnB;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;kBACnB;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;WACnB,MAAM;;;;iBACN,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAKpC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;QACnB,MAAM;;;;WACN,MAAM;;;;kBACN;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;iBACnB,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAKpC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;YACnB,OAAO,0BAA0B,EAAE,kBAAkB;;;;kBACrD;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;WACnB,MAAM;;;;iBACN,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAKpC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;QACnB,MAAM;;;;WACN,MAAM;;;;iBACN,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAKpC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;QACnB,MAAM;;;;WACN,MAAM;;;;mBACN;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;kBACnB;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;iBACnB,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;2CAKvC,OAAO,0BAA0B,EAAE,kBAAkB,UACrD,MAAM;;;;;cAKH;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;QACnB,MAAM;;;;WACN,MAAM;;;;kBACN;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC;;;;cACnB,qBAAqB;;;;iBACrB,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;2BAIrC,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,MAAM,GAAC,MAAM,CAAC;kCAKjF,gBAAgB,KACd,YAAY;oCAKd,kBAAkB,KAChB,YAAY;kCAKd,gBAAgB,KACd,YAAY;iCAKd,iBAAiB,KACf,YAAY;kCAKd,gBAAgB,KACd,YAAY;qCAKd,aAAa,KACX,OAAO,gCAAgC,EAAE,kBAAkB,CAAC,IAAI,CAAC;;;;;;;;aAOhE,YAAY;;;;eACZ,cAAc;;;;aACd,YAAY;;;;aACZ,YAAY;;;;YACZ,WAAW;;;;gBACX,eAAe;;;;;6BAMhB,wBAAwB,GAAG,mBAAmB;mCAvKxB,gCAAgC"}
|
package/types/index.d.ts
CHANGED
|
@@ -22,8 +22,11 @@ export * from "./use/proxyLoadingError.js";
|
|
|
22
22
|
export * from "./use/search.js";
|
|
23
23
|
export * from "./use/watchesRunning.js";
|
|
24
24
|
export * from "./utils/assignReactiveObject.js";
|
|
25
|
+
export * from "./utils/cancellableFetch.js";
|
|
26
|
+
export * from "./utils/cancellablePromise.js";
|
|
25
27
|
export * from "./utils/classes.js";
|
|
26
28
|
export * from "./utils/compact.js";
|
|
29
|
+
export * from "./utils/deepUnref.js";
|
|
27
30
|
export * from "./utils/deleteKey.js";
|
|
28
31
|
export * from "./utils/flattenPaths.js";
|
|
29
32
|
export * from "./utils/getFakePk.js";
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module use/cancellableIntent.js - A composable function for handling cancellable intents.
|
|
3
3
|
*/
|
|
4
|
-
/**
|
|
5
|
-
* A Promise that can be cancelled.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {Promise<any> & { cancel: () => Promise<void>|void }} CancellablePromise
|
|
8
|
-
*/
|
|
9
4
|
/**
|
|
10
5
|
* @typedef {import("vue").UnwrapNestedRefs<object>} CancellableIntentState - The state of the cancellable intent.
|
|
11
6
|
* @property {number} activeCount - The number of active intents.
|
|
@@ -18,7 +13,7 @@
|
|
|
18
13
|
*/
|
|
19
14
|
/**
|
|
20
15
|
* @typedef {object} CancellableIntentOptions - The options for the cancellable intent.
|
|
21
|
-
* @property {() =>
|
|
16
|
+
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} awaitableWithCancel - The function that returns a promise that can be cancelled.
|
|
22
17
|
* @property {import("vue").UnwrapNestedRefs<object>} [watchArguments={}] - The reactive object to watch for changes.
|
|
23
18
|
* @property {import("vue").UnwrapNestedRefs<object>} [guardArguments={}] - The reactive object to watch for truthiness before running the intent.
|
|
24
19
|
* @property {boolean} [clearActiveOnResolved=true] - Whether to clear the active state when the promise resolves.
|
|
@@ -70,12 +65,6 @@
|
|
|
70
65
|
* @returns {CancellableIntent} - The instance of the cancellable intent.
|
|
71
66
|
*/
|
|
72
67
|
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
68
|
/**
|
|
80
69
|
* - The state of the cancellable intent.
|
|
81
70
|
*/
|
|
@@ -87,7 +76,7 @@ export type CancellableIntentOptions = {
|
|
|
87
76
|
/**
|
|
88
77
|
* - The function that returns a promise that can be cancelled.
|
|
89
78
|
*/
|
|
90
|
-
awaitableWithCancel: () =>
|
|
79
|
+
awaitableWithCancel: () => import("../utils/cancellablePromise.js").MaybeCancellablePromise<void>;
|
|
91
80
|
/**
|
|
92
81
|
* - The reactive object to watch for changes.
|
|
93
82
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancellableIntent.d.ts","sourceRoot":"","sources":["../../use/cancellableIntent.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH
|
|
1
|
+
{"version":3,"file":"cancellableIntent.d.ts","sourceRoot":"","sources":["../../use/cancellableIntent.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH;;;;;;;;;GASG;AAEH;;;;;;GAMG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,sHAHW,wBAAwB,GACtB,iBAAiB,CAyL7B;;;;qCAxPY,OAAO,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC;;;;;;;;yBAYrC,MAAM,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,IAAI,CAAC;;;;qBAC5E,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"}
|