@arrai-innovations/reactive-helpers 18.0.1 → 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 +16 -1
- package/types/config/listCrud.d.ts +153 -0
- package/types/config/listCrud.d.ts.map +1 -0
- package/types/config/objectCrud.d.ts +237 -0
- package/types/config/objectCrud.d.ts.map +1 -0
- package/types/index.d.ts +40 -0
- package/types/index.d.ts.map +1 -0
- package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
- package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
- package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
- package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
- package/types/tests/unit/crudPromise.d.ts +25 -0
- package/types/tests/unit/crudPromise.d.ts.map +1 -0
- package/types/tests/unit/expectHelpers.d.ts +2 -0
- package/types/tests/unit/expectHelpers.d.ts.map +1 -0
- package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
- package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
- package/types/tests/unit/poll.d.ts +2 -0
- package/types/tests/unit/poll.d.ts.map +1 -0
- package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
- package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
- package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
- package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
- package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
- package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
- package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSort.spec.d.ts +2 -0
- package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
- package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
- package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
- package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
- package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
- package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
- package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
- package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
- package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
- package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
- package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
- package/types/tests/unit/use/search.spec.d.ts +2 -0
- package/types/tests/unit/use/search.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
- package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/classes.spec.d.ts +2 -0
- package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
- package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
- package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
- package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/set.spec.d.ts +2 -0
- package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
- package/types/tests/unit/utils/watches.spec.d.ts +2 -0
- package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
- package/types/use/cancellableIntent.d.ts +118 -0
- package/types/use/cancellableIntent.d.ts.map +1 -0
- package/types/use/combineClasses.d.ts +43 -0
- package/types/use/combineClasses.d.ts.map +1 -0
- package/types/use/list.d.ts +176 -0
- package/types/use/list.d.ts.map +1 -0
- package/types/use/listCalculated.d.ts +192 -0
- package/types/use/listCalculated.d.ts.map +1 -0
- package/types/use/listFilter.d.ts +203 -0
- package/types/use/listFilter.d.ts.map +1 -0
- package/types/use/listInstance.d.ts +357 -0
- package/types/use/listInstance.d.ts.map +1 -0
- package/types/use/listKeys.d.ts +15 -0
- package/types/use/listKeys.d.ts.map +1 -0
- package/types/use/listRelated.d.ts +239 -0
- package/types/use/listRelated.d.ts.map +1 -0
- package/types/use/listSearch.d.ts +298 -0
- package/types/use/listSearch.d.ts.map +1 -0
- package/types/use/listSort.d.ts +235 -0
- package/types/use/listSort.d.ts.map +1 -0
- package/types/use/listSubscription.d.ts +218 -0
- package/types/use/listSubscription.d.ts.map +1 -0
- package/types/use/loadingError.d.ts +105 -0
- package/types/use/loadingError.d.ts.map +1 -0
- package/types/use/object.d.ts +67 -0
- package/types/use/object.d.ts.map +1 -0
- package/types/use/objectCalculated.d.ts +215 -0
- package/types/use/objectCalculated.d.ts.map +1 -0
- package/types/use/objectInstance.d.ts +341 -0
- package/types/use/objectInstance.d.ts.map +1 -0
- package/types/use/objectRelated.d.ts +264 -0
- package/types/use/objectRelated.d.ts.map +1 -0
- package/types/use/objectSubscription.d.ts +253 -0
- package/types/use/objectSubscription.d.ts.map +1 -0
- package/types/use/paginatedListInstance.d.ts +51 -0
- package/types/use/paginatedListInstance.d.ts.map +1 -0
- package/types/use/proxyLoadingError.d.ts +21 -0
- package/types/use/proxyLoadingError.d.ts.map +1 -0
- package/types/use/search.d.ts +144 -0
- package/types/use/search.d.ts.map +1 -0
- package/types/use/watchesRunning.d.ts +63 -0
- package/types/use/watchesRunning.d.ts.map +1 -0
- package/types/utils/assignReactiveObject.d.ts +115 -0
- package/types/utils/assignReactiveObject.d.ts.map +1 -0
- 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/classes.d.ts +22 -0
- package/types/utils/classes.d.ts.map +1 -0
- package/types/utils/compact.d.ts +4 -0
- package/types/utils/compact.d.ts.map +1 -0
- package/types/utils/deepUnref.d.ts +26 -0
- package/types/utils/deepUnref.d.ts.map +1 -0
- package/types/utils/deleteKey.d.ts +16 -0
- package/types/utils/deleteKey.d.ts.map +1 -0
- package/types/utils/flattenPaths.d.ts +23 -0
- package/types/utils/flattenPaths.d.ts.map +1 -0
- package/types/utils/getFakePk.d.ts +13 -0
- package/types/utils/getFakePk.d.ts.map +1 -0
- package/types/utils/keepAliveTry.d.ts +15 -0
- package/types/utils/keepAliveTry.d.ts.map +1 -0
- package/types/utils/keyDiff.d.ts +63 -0
- package/types/utils/keyDiff.d.ts.map +1 -0
- package/types/utils/loadingCombine.d.ts +9 -0
- package/types/utils/loadingCombine.d.ts.map +1 -0
- package/types/utils/proxyRunning.d.ts +9 -0
- package/types/utils/proxyRunning.d.ts.map +1 -0
- package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
- package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
- package/types/utils/set.d.ts +7 -0
- package/types/utils/set.d.ts.map +1 -0
- package/types/utils/transformWalk.d.ts +2 -0
- package/types/utils/transformWalk.d.ts.map +1 -0
- package/types/utils/watches.d.ts +155 -0
- package/types/utils/watches.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/.circleci/config.yml +0 -88
- package/.commitlintrc.json +0 -3
- package/.editorconfig +0 -5
- package/.husky/commit-msg +0 -3
- package/.husky/pre-commit +0 -3
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/encodings.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -8
- package/.idea/reactive-helpers.iml +0 -15
- package/.prettierignore +0 -5
- package/.prettierrc.cjs +0 -5
- package/.vscode/extensions.json +0 -3
- package/docs/README.md +0 -45
- package/docs/config/listCrud.md +0 -422
- package/docs/config/objectCrud.md +0 -427
- package/docs/use/cancellableIntent.md +0 -165
- package/docs/use/combineClasses.md +0 -62
- package/docs/use/list.md +0 -361
- package/docs/use/listCalculated.md +0 -794
- package/docs/use/listFilter.md +0 -897
- package/docs/use/listInstance.md +0 -559
- package/docs/use/listKeys.md +0 -91
- package/docs/use/listRelated.md +0 -706
- package/docs/use/listSearch.md +0 -903
- package/docs/use/listSort.md +0 -1171
- package/docs/use/listSubscription.md +0 -393
- package/docs/use/loadingError.md +0 -115
- package/docs/use/object.md +0 -668
- package/docs/use/objectCalculated.md +0 -741
- package/docs/use/objectInstance.md +0 -685
- package/docs/use/objectRelated.md +0 -723
- package/docs/use/objectSubscription.md +0 -538
- package/docs/use/paginatedListInstance.md +0 -155
- package/docs/use/proxyLoadingError.md +0 -51
- package/docs/use/search.md +0 -321
- package/docs/use/watchesRunning.md +0 -84
- package/docs/utils/assignReactiveObject.md +0 -413
- package/docs/utils/classes.md +0 -139
- package/docs/utils/compact.md +0 -67
- package/docs/utils/deleteKey.md +0 -61
- package/docs/utils/flattenPaths.md +0 -53
- package/docs/utils/getFakePk.md +0 -39
- package/docs/utils/keepAliveTry.md +0 -59
- package/docs/utils/keyDiff.md +0 -117
- package/docs/utils/loadingCombine.md +0 -30
- package/docs/utils/proxyRunning.md +0 -39
- package/docs/utils/relatedCalculatedHelpers.md +0 -93
- package/docs/utils/set.md +0 -223
- package/docs/utils/transformWalk.md +0 -68
- package/docs/utils/watches.md +0 -489
- package/eslint.config.js +0 -125
- package/lint-staged.config.js +0 -10
- package/makeTypeDoc.sh +0 -25
- package/make_type_doc.js +0 -59
- package/tests/unit/config/listCrud.spec.js +0 -114
- package/tests/unit/config/objectCrud.spec.js +0 -160
- package/tests/unit/crudPromise.js +0 -40
- package/tests/unit/expectHelpers.js +0 -6
- package/tests/unit/mockOnUnmounted.js +0 -9
- package/tests/unit/poll.js +0 -50
- package/tests/unit/use/cancellableIntent.spec.js +0 -152
- package/tests/unit/use/listCalculated.spec.js +0 -135
- package/tests/unit/use/listFilter.spec.js +0 -484
- package/tests/unit/use/listInstance.spec.js +0 -1166
- package/tests/unit/use/listRelated.spec.js +0 -260
- package/tests/unit/use/listSearch.spec.js +0 -586
- package/tests/unit/use/listSort.spec.js +0 -418
- package/tests/unit/use/listSubscription.spec.js +0 -845
- package/tests/unit/use/loadingError.spec.js +0 -43
- package/tests/unit/use/objectInstance.spec.js +0 -1525
- package/tests/unit/use/objectSubscription.spec.js +0 -849
- package/tests/unit/use/proxyLoadingError.spec.js +0 -64
- package/tests/unit/use/search.spec.js +0 -248
- package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
- package/tests/unit/utils/classes.spec.js +0 -427
- package/tests/unit/utils/deleteKey.spec.js +0 -265
- package/tests/unit/utils/flattenPaths.spec.js +0 -126
- package/tests/unit/utils/keyDiff.spec.js +0 -110
- package/tests/unit/utils/set.spec.js +0 -81
- package/tests/unit/utils/watches.spec.js +0 -276
- package/tsconfig.json +0 -19
- package/typedoc-local-plugins/customize-output.js +0 -13
- package/typedoc.json +0 -11
- package/vitest.config.js +0 -11
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,9 +1,24 @@
|
|
|
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",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"types": "./types/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"README.md",
|
|
17
|
+
"use/",
|
|
18
|
+
"utils/",
|
|
19
|
+
"config/",
|
|
20
|
+
"types/"
|
|
21
|
+
],
|
|
7
22
|
"directories": {
|
|
8
23
|
"use": "use",
|
|
9
24
|
"utils": "utils",
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export function setListCrud({ list, bulkDelete, subscribe, executeAction, args, ...rest }: ListCrudFunctions & Partial<ListCrudArgs>): void;
|
|
2
|
+
export function getListCrud(reactiveCrud: import("vue").UnwrapNestedRefs<ListCrudFunctions & ListCrudArgs>, { props, functions }?: {
|
|
3
|
+
props?: import("vue").UnwrapNestedRefs<{
|
|
4
|
+
crudArgs: object | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
functions?: ListCrudFunctions & ListCrudArgs;
|
|
7
|
+
}): void;
|
|
8
|
+
export type PaginateInfo = {
|
|
9
|
+
/**
|
|
10
|
+
* - The total records.
|
|
11
|
+
*/
|
|
12
|
+
totalRecords: number;
|
|
13
|
+
/**
|
|
14
|
+
* - The total pages.
|
|
15
|
+
*/
|
|
16
|
+
totalPages: number;
|
|
17
|
+
/**
|
|
18
|
+
* - The per page.
|
|
19
|
+
*/
|
|
20
|
+
perPage: number;
|
|
21
|
+
};
|
|
22
|
+
export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo: PaginateInfo | undefined) => void;
|
|
23
|
+
export type ListFnArgs = {
|
|
24
|
+
/**
|
|
25
|
+
* - The arguments to be passed to the crud functions.
|
|
26
|
+
*/
|
|
27
|
+
crudArgs: object;
|
|
28
|
+
/**
|
|
29
|
+
* - The key name of the primary key.
|
|
30
|
+
*/
|
|
31
|
+
pkKey: string;
|
|
32
|
+
/**
|
|
33
|
+
* - The arguments to be passed to the retrieve function.
|
|
34
|
+
*/
|
|
35
|
+
retrieveArgs: object;
|
|
36
|
+
/**
|
|
37
|
+
* - The arguments to be passed for list crud functions.
|
|
38
|
+
*/
|
|
39
|
+
listArgs: object;
|
|
40
|
+
/**
|
|
41
|
+
* - The method to call with new page(s) of data received.
|
|
42
|
+
*/
|
|
43
|
+
pageCallback: PageCallback;
|
|
44
|
+
/**
|
|
45
|
+
* - A ref to a boolean indicating whether the request has
|
|
46
|
+
* been cancelled.
|
|
47
|
+
*/
|
|
48
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
49
|
+
};
|
|
50
|
+
export type DeleteFnArgs = {
|
|
51
|
+
/**
|
|
52
|
+
* - The arguments to be passed to the crud functions.
|
|
53
|
+
*/
|
|
54
|
+
crudArgs: object;
|
|
55
|
+
/**
|
|
56
|
+
* - The ids of the objects to be deleted.
|
|
57
|
+
*/
|
|
58
|
+
pks: string[];
|
|
59
|
+
/**
|
|
60
|
+
* - The key name of the primary key.
|
|
61
|
+
*/
|
|
62
|
+
pkKey: string;
|
|
63
|
+
};
|
|
64
|
+
export type SubscriptionEventCallback = (newOrUpdatedOrDeleteObject: import("../use/listInstance.js").ListObject | string, action: "create" | "update" | "delete") => void;
|
|
65
|
+
export type SubscribeFnArgs = {
|
|
66
|
+
/**
|
|
67
|
+
* - The arguments to be passed to the crud functions.
|
|
68
|
+
*/
|
|
69
|
+
crudArgs: object;
|
|
70
|
+
/**
|
|
71
|
+
* - The key name of the primary key.
|
|
72
|
+
*/
|
|
73
|
+
pkKey: string;
|
|
74
|
+
/**
|
|
75
|
+
* - The arguments to be passed to the retrieve function.
|
|
76
|
+
*/
|
|
77
|
+
retrieveArgs: object;
|
|
78
|
+
/**
|
|
79
|
+
* - The arguments to be passed for list crud functions.
|
|
80
|
+
*/
|
|
81
|
+
listArgs: object;
|
|
82
|
+
/**
|
|
83
|
+
* - The method to call when new data is received.
|
|
84
|
+
*/
|
|
85
|
+
subscriptionEventCallback: SubscriptionEventCallback;
|
|
86
|
+
};
|
|
87
|
+
export type ExecuteActionFnArgs = {
|
|
88
|
+
/**
|
|
89
|
+
* - The arguments to be passed to the crud functions.
|
|
90
|
+
*/
|
|
91
|
+
crudArgs: object;
|
|
92
|
+
/**
|
|
93
|
+
* - The ids of the objects to be acted upon.
|
|
94
|
+
*/
|
|
95
|
+
pks: string[];
|
|
96
|
+
/**
|
|
97
|
+
* - The key name of the primary key.
|
|
98
|
+
*/
|
|
99
|
+
pkKey: string;
|
|
100
|
+
/**
|
|
101
|
+
* - The action to execute.
|
|
102
|
+
*/
|
|
103
|
+
action: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* - The list function to get a list of items, returning a boolean indicating success.
|
|
107
|
+
*/
|
|
108
|
+
export type ListFn = (ListFnArgs: any) => Promise<boolean> & {
|
|
109
|
+
cancel: () => Promise<void> | void;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* - The delete function to bulk delete a list of items.
|
|
113
|
+
*/
|
|
114
|
+
export type BulkDeleteFn = (DeleteFnArgs: any) => Promise<boolean> & {
|
|
115
|
+
cancel: () => Promise<void> | void;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* - The subscribe function to set up a subscription to a list of items.
|
|
119
|
+
*/
|
|
120
|
+
export type SubscribeFn = (SubscribeFnArgs: any) => Promise<boolean> & {
|
|
121
|
+
cancel: () => Promise<void> | void;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* - The function to execute a certain action on a list of items, returning the response data or false.
|
|
125
|
+
*/
|
|
126
|
+
export type ExecuteActionFn = (ExecuteActionFnArgs: any) => Promise<import("./objectCrud.js").CrudResponse | false> & {
|
|
127
|
+
cancel: () => Promise<void> | void;
|
|
128
|
+
};
|
|
129
|
+
export type ListCrudFunctions = {
|
|
130
|
+
/**
|
|
131
|
+
* - The list function to get a list of items.
|
|
132
|
+
*/
|
|
133
|
+
list?: ListFn;
|
|
134
|
+
/**
|
|
135
|
+
* - The delete function to bulk delete a list of items.
|
|
136
|
+
*/
|
|
137
|
+
bulkDelete?: BulkDeleteFn;
|
|
138
|
+
/**
|
|
139
|
+
* - The function to execute a certain action on a list of items.
|
|
140
|
+
*/
|
|
141
|
+
executeAction?: ExecuteActionFn;
|
|
142
|
+
/**
|
|
143
|
+
* - The subscribe function to get a subscription to a list of items.
|
|
144
|
+
*/
|
|
145
|
+
subscribe?: SubscribeFn;
|
|
146
|
+
};
|
|
147
|
+
export type ListCrudArgs = {
|
|
148
|
+
/**
|
|
149
|
+
* - The default arguments for the crud functions.
|
|
150
|
+
*/
|
|
151
|
+
args?: object;
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=listCrud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"AA+GO,2FAJI,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,GAEvC,IAAI,CAWhB;AAYM,0CAPI,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,YAAY,CAAC,yBAExE;IAEa,KAAK,GAFV,OAAO,KAAK,EAAE,gBAAgB,CAAC;QACnC,QAAQ,EAAE,MAAM,GAAC,SAAS,CAAC;KAC9B,CAAC;IACiD,SAAS,GAApD,iBAAiB,GAAG,YAAY;CAC1C,QAmBA;;;;;kBAjIa,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM;;2BAIP,CACN,UAAU,EAAC,OAAO,wBAAwB,EAAE,UAAU,EACtD,cAAc,EAAE,YAAY,GAAC,SAAS,KACvC,IAAI;;;;;cAKI,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,MAAM;;;;kBACN,YAAY;;;;;iBACZ,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;cAMpC,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;wCAIP,CACN,0BAA0B,EAAC,OAAO,wBAAwB,EAAE,UAAU,GAAC,MAAM,EAC7E,MAAM,EAAE,QAAQ,GAAC,QAAQ,GAAC,QAAQ,KACnC,IAAI;;;;;cAKI,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,MAAM;;;;+BACN,yBAAyB;;;;;;cAKzB,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;;;YACN,MAAM;;;;;qBAIP,CAAC,UAAU,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;2BAIrE,CAAC,YAAY,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;0BAIvE,CAAC,eAAe,KAAA,KAAG,OAAO,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;8BAI1E,CAAC,mBAAmB,KAAA,KAAG,OAAO,CAAC,OAAO,iBAAiB,EAAE,YAAY,GAAC,KAAK,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAA;CAAE;;;;;WAKlH,MAAM;;;;iBACN,YAAY;;;;oBACZ,eAAe;;;;gBACf,WAAW;;;;;;WAKX,MAAM"}
|