@arrai-innovations/reactive-helpers 18.1.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/config/commonCrud.js +75 -0
- package/config/listCrud.js +57 -56
- package/config/objectCrud.js +35 -84
- package/index.js +3 -1
- package/package.json +3 -2
- package/types/config/commonCrud.d.ts +19 -0
- package/types/config/commonCrud.d.ts.map +1 -0
- package/types/config/listCrud.d.ts +44 -39
- package/types/config/listCrud.d.ts.map +1 -1
- package/types/config/objectCrud.d.ts +21 -25
- package/types/config/objectCrud.d.ts.map +1 -1
- package/types/index.d.ts +3 -1
- package/types/use/listInstance.d.ts +8 -8
- package/types/use/listInstance.d.ts.map +1 -1
- package/types/use/objectInstance.d.ts +4 -4
- package/types/use/objectInstance.d.ts.map +1 -1
- package/types/utils/refIfReactive.d.ts +2 -0
- package/types/utils/refIfReactive.d.ts.map +1 -0
- package/types/utils/unwrapNested.d.ts +2 -0
- package/types/utils/unwrapNested.d.ts.map +1 -0
- package/use/listInstance.js +29 -29
- package/use/objectInstance.js +14 -14
- package/utils/refIfReactive.js +18 -0
- package/utils/unwrapNested.js +25 -0
package/README.md
CHANGED
|
@@ -948,11 +948,17 @@ await awaitNot3.promise;
|
|
|
948
948
|
```bash
|
|
949
949
|
$ npm ci
|
|
950
950
|
```
|
|
951
|
-
3. Run tests via
|
|
951
|
+
3. Run tests via vitest:
|
|
952
952
|
```bash
|
|
953
953
|
$ npm test
|
|
954
954
|
```
|
|
955
955
|
4. Run tests with coverage output:
|
|
956
|
+
|
|
956
957
|
```bash
|
|
957
958
|
$ npm run coverage
|
|
958
959
|
```
|
|
960
|
+
|
|
961
|
+
5. Generate types and typedocs:
|
|
962
|
+
```bash
|
|
963
|
+
$ npm run docs
|
|
964
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
2
|
+
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
3
|
+
import { addOrUpdateReactiveObject } from "../utils/assignReactiveObject.js";
|
|
4
|
+
import isFunction from "lodash-es/isFunction.js";
|
|
5
|
+
import { refIfReactive } from "../utils/refIfReactive.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} name - The name of the method.
|
|
9
|
+
* @returns {(...args: any[]) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<any>} - A function that returns a rejected promise with an error message.
|
|
10
|
+
*/
|
|
11
|
+
export const missingMethod = (name) => () =>
|
|
12
|
+
CancellablePromise.reject(new Error(`Crud method "${name}" is not implemented.`));
|
|
13
|
+
|
|
14
|
+
// HACK: eslint, tsc, webstorm all can't agree on how to do this right
|
|
15
|
+
// noinspection JSValidateTypes,JSUnusedLocalSymbols
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} name - The name of the method.
|
|
18
|
+
* @returns {(
|
|
19
|
+
* (..._args: any[]) => import('../utils/cancellablePromise.js').CancellablePromise<void>
|
|
20
|
+
* )} - A function that returns a rejected promise with an error message.
|
|
21
|
+
*/
|
|
22
|
+
export const requiredCancelMissingMethod =
|
|
23
|
+
(name) =>
|
|
24
|
+
/* eslint-disable no-unused-vars */
|
|
25
|
+
// @ts-ignore - refuses to accept returned CancellablePromise<void> = imported CancellablePromise<void>
|
|
26
|
+
(..._args) =>
|
|
27
|
+
CancellablePromise(Promise.reject(new Error(`Crud method "${name}" is not implemented.`)), () => {});
|
|
28
|
+
/* eslint-enable no-unused-vars */
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a default CRUD object with the given keys.
|
|
32
|
+
*
|
|
33
|
+
* @param {string[]} keys - The CRUD function keys.
|
|
34
|
+
* @param {Set<string>} cancellableKeys - Which ones need required cancellation.
|
|
35
|
+
* @returns {object} - The default CRUD object.
|
|
36
|
+
*/
|
|
37
|
+
export const createDefaultCrud = (keys, cancellableKeys = new Set()) => {
|
|
38
|
+
const result = { args: {} };
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
result[key] = cancellableKeys.has(key) ? requiredCancelMissingMethod(key) : missingMethod(key);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Assigns the default CRUD functions to the target object.
|
|
47
|
+
*
|
|
48
|
+
* @param {object} target - The reactive object to assign to.
|
|
49
|
+
* @param {object} defaultCrud - The default CRUD definition (usually created by `createDefaultCrud`).
|
|
50
|
+
* @param {object} [options] - The options object.
|
|
51
|
+
* @param {object} [options.props] - The props object.
|
|
52
|
+
* @param {object} [options.functions] - The functions to assign.
|
|
53
|
+
* @param {Set<string>} [options.validKeys] - The valid keys for the functions.
|
|
54
|
+
*/
|
|
55
|
+
export function assignCrud(
|
|
56
|
+
target,
|
|
57
|
+
defaultCrud,
|
|
58
|
+
{ props, functions, validKeys = new Set(Object.keys(defaultCrud).filter((k) => k !== "args")) } = {}
|
|
59
|
+
) {
|
|
60
|
+
Object.assign(target, cloneDeep(defaultCrud));
|
|
61
|
+
if (props?.crudArgs) {
|
|
62
|
+
addOrUpdateReactiveObject(target.args, props.crudArgs);
|
|
63
|
+
}
|
|
64
|
+
if (functions) {
|
|
65
|
+
for (const [key, fn] of Object.entries(functions)) {
|
|
66
|
+
if (!validKeys.has(key)) {
|
|
67
|
+
throw new Error(`Invalid function key "${key}" passed to assignCrud`);
|
|
68
|
+
}
|
|
69
|
+
if (!isFunction(fn)) {
|
|
70
|
+
throw new Error(`Function "${key}" is not actually a function`);
|
|
71
|
+
}
|
|
72
|
+
target[key] = refIfReactive(functions, key, fn);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/config/listCrud.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assignCrud, createDefaultCrud } from "./commonCrud.js";
|
|
2
2
|
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
3
|
-
import
|
|
4
|
-
import { isReactive, toRef } from "vue";
|
|
3
|
+
import { readonly } from "vue";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Configuration for the default list crud functions.
|
|
@@ -9,14 +8,6 @@ import { isReactive, toRef } from "vue";
|
|
|
9
8
|
* @module config/listCrud.js
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
|
-
const defaultCrud = {
|
|
13
|
-
args: {},
|
|
14
|
-
list: undefined,
|
|
15
|
-
bulkDelete: undefined,
|
|
16
|
-
subscribe: undefined,
|
|
17
|
-
executeAction: undefined,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
11
|
/**
|
|
21
12
|
* @typedef {object} PaginateInfo
|
|
22
13
|
* @property {number} totalRecords - The total records.
|
|
@@ -32,7 +23,7 @@ const defaultCrud = {
|
|
|
32
23
|
*/
|
|
33
24
|
|
|
34
25
|
/**
|
|
35
|
-
* @typedef {object}
|
|
26
|
+
* @typedef {object} ListArgs
|
|
36
27
|
* @property {object} crudArgs - The arguments to be passed to the crud functions.
|
|
37
28
|
* @property {string} pkKey - The key name of the primary key.
|
|
38
29
|
* @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
@@ -43,10 +34,12 @@ const defaultCrud = {
|
|
|
43
34
|
*/
|
|
44
35
|
|
|
45
36
|
/**
|
|
46
|
-
* @typedef {object}
|
|
37
|
+
* @typedef {object} BulkDeleteArgs
|
|
47
38
|
* @property {object} crudArgs - The arguments to be passed to the crud functions.
|
|
48
39
|
* @property {string[]} pks - The ids of the objects to be deleted.
|
|
49
40
|
* @property {string} pkKey - The key name of the primary key.
|
|
41
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to a boolean indicating whether the request has
|
|
42
|
+
* been cancelled.
|
|
50
43
|
*/
|
|
51
44
|
|
|
52
45
|
/**
|
|
@@ -57,51 +50,77 @@ const defaultCrud = {
|
|
|
57
50
|
*/
|
|
58
51
|
|
|
59
52
|
/**
|
|
60
|
-
* @typedef {object}
|
|
53
|
+
* @typedef {object} ListSubscribeArgs
|
|
61
54
|
* @property {object} crudArgs - The arguments to be passed to the crud functions.
|
|
62
55
|
* @property {string} pkKey - The key name of the primary key.
|
|
63
56
|
* @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
64
57
|
* @property {object} listArgs - The arguments to be passed for list crud functions.
|
|
65
58
|
* @property {SubscriptionEventCallback} subscriptionEventCallback - The method to call when new data is received.
|
|
59
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to a boolean indicating whether the request has
|
|
60
|
+
* been cancelled.
|
|
66
61
|
*/
|
|
67
62
|
|
|
68
63
|
/**
|
|
69
|
-
* @typedef {object}
|
|
64
|
+
* @typedef {object} ExecuteActionArgs
|
|
70
65
|
* @property {object} crudArgs - The arguments to be passed to the crud functions.
|
|
71
66
|
* @property {string[]} pks - The ids of the objects to be acted upon.
|
|
72
67
|
* @property {string} pkKey - The key name of the primary key.
|
|
73
68
|
* @property {string} action - The action to execute.
|
|
69
|
+
* @property {Readonly<import('vue').Ref<boolean>>} isCancelled - A ref to a boolean indicating whether the request has
|
|
70
|
+
* been cancelled.
|
|
74
71
|
*/
|
|
75
72
|
|
|
76
73
|
/**
|
|
77
|
-
* @
|
|
74
|
+
* @callback CrudListFn
|
|
75
|
+
* @param {ListArgs} args - The arguments to be passed to the crud functions.
|
|
76
|
+
* @returns {import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} - A promise that resolves to a boolean indicating success.
|
|
78
77
|
*/
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
|
-
* @
|
|
80
|
+
* @callback CrudBulkDeleteFn
|
|
81
|
+
* @param {BulkDeleteArgs} args - The arguments to be passed to the crud functions.
|
|
82
|
+
* @returns {import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} - A promise that resolves to a boolean indicating success.
|
|
82
83
|
*/
|
|
83
84
|
|
|
84
85
|
/**
|
|
85
|
-
* @
|
|
86
|
+
* @callback CrudListSubscribeFn
|
|
87
|
+
* @param {ListSubscribeArgs} args - The arguments to be passed to the crud functions.
|
|
88
|
+
* @returns {import('../utils/cancellablePromise.js').CancellablePromise<void>} - A promise that resolves to a boolean indicating success.
|
|
86
89
|
*/
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
|
-
* @
|
|
92
|
+
* @callback CrudExecuteActionFn
|
|
93
|
+
* @param {ExecuteActionArgs} args - The arguments to be passed to the crud functions.
|
|
94
|
+
* @returns {import('../utils/cancellablePromise.js').MaybeCancellablePromise<object|string|null>} - A promise that resolves the result of the action, returned to the executor.
|
|
90
95
|
*/
|
|
91
96
|
|
|
92
97
|
/**
|
|
93
98
|
* @typedef {object} ListCrudFunctions
|
|
94
|
-
* @property {
|
|
95
|
-
* @property {
|
|
96
|
-
* @property {
|
|
97
|
-
* @property {
|
|
99
|
+
* @property {CrudListFn} [list] - The list function to get a list of items.
|
|
100
|
+
* @property {CrudBulkDeleteFn} [bulkDelete] - The delete function to bulk delete a list of items.
|
|
101
|
+
* @property {CrudExecuteActionFn} [executeAction] - The function to execute a certain action on a list of items.
|
|
102
|
+
* @property {CrudListSubscribeFn} [subscribe] - The subscribe function to get a subscription to a list of items.
|
|
98
103
|
*/
|
|
99
104
|
|
|
100
105
|
/**
|
|
101
106
|
* @typedef {object} ListCrudArgs
|
|
102
|
-
* @property {object}
|
|
107
|
+
* @property {object} args - The default arguments for the crud functions.
|
|
103
108
|
*/
|
|
104
109
|
|
|
110
|
+
/**
|
|
111
|
+
* @typedef {object} ListCrudArgsOption
|
|
112
|
+
* @property {object} [crudArgs={}] - The default arguments for the crud functions.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
const _defaultCrud = createDefaultCrud(["list", "bulkDelete", "executeAction", "subscribe"], new Set(["subscribe"]));
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The default list crud functions.
|
|
119
|
+
*
|
|
120
|
+
* @type {Readonly<ListCrudFunctions>}
|
|
121
|
+
*/
|
|
122
|
+
export const defaultListCrud = readonly(_defaultCrud);
|
|
123
|
+
|
|
105
124
|
/**
|
|
106
125
|
* Set the list and subscribe functions for the default crud.
|
|
107
126
|
*
|
|
@@ -109,43 +128,25 @@ const defaultCrud = {
|
|
|
109
128
|
* @throws {Error} - If unknown keys are passed.
|
|
110
129
|
* @returns {void}
|
|
111
130
|
*/
|
|
112
|
-
export const setListCrud = ({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
throw new Error(`Unknown key(s) passed to setListCrud: ${Object.keys(rest).join(", ")}`);
|
|
131
|
+
export const setListCrud = ({ args = {}, ...rest }) => {
|
|
132
|
+
Object.assign(_defaultCrud.args, cloneDeep(args));
|
|
133
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
134
|
+
if (!(key in _defaultCrud)) {
|
|
135
|
+
throw new Error(`Unknown key "${key}" passed to setListCrud`);
|
|
136
|
+
}
|
|
137
|
+
_defaultCrud[key] = value ?? _defaultCrud[key];
|
|
120
138
|
}
|
|
121
139
|
};
|
|
122
140
|
|
|
123
141
|
/**
|
|
124
142
|
* Get the previously set list and subscribe functions for the default crud.
|
|
125
143
|
*
|
|
126
|
-
* @param {import("vue").UnwrapNestedRefs<ListCrudFunctions & ListCrudArgs>}
|
|
144
|
+
* @param {import("vue").UnwrapNestedRefs<ListCrudFunctions & ListCrudArgs>} target - The reactive crud object, which will be mutated.
|
|
127
145
|
* @param {object} options - The options for the default crud.
|
|
128
|
-
* @param {import("vue").UnwrapNestedRefs<
|
|
129
|
-
*
|
|
130
|
-
* }
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// don't mutate the default crud
|
|
135
|
-
Object.assign(reactiveCrud, cloneDeep(defaultCrud));
|
|
136
|
-
if (props?.crudArgs) {
|
|
137
|
-
addOrUpdateReactiveObject(reactiveCrud.args, props.crudArgs);
|
|
138
|
-
}
|
|
139
|
-
if (functions) {
|
|
140
|
-
for (const [key, value] of Object.entries(functions)) {
|
|
141
|
-
if (isFunction(value) && key in reactiveCrud) {
|
|
142
|
-
reactiveCrud[key] = isReactive(functions)
|
|
143
|
-
? // @ts-ignore - this is a valid key...
|
|
144
|
-
toRef(functions, key)
|
|
145
|
-
: value;
|
|
146
|
-
} else {
|
|
147
|
-
throw Error(`Invalid function "${key}" for getListCrud: invalid key or not a function.`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
146
|
+
* @param {import("vue").UnwrapNestedRefs<ListCrudArgsOption>} [options.props] - The props to set for the crud.
|
|
147
|
+
* @param {ListCrudFunctions} [options.functions] - The functions to set for the crud.
|
|
148
|
+
* @throws {Error} - If an invalid function is passed, or if the function is not a function.
|
|
149
|
+
*/
|
|
150
|
+
export const getListCrud = (target, options) => {
|
|
151
|
+
assignCrud(target, _defaultCrud, options);
|
|
151
152
|
};
|
package/config/objectCrud.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assignCrud, createDefaultCrud } from "./commonCrud.js";
|
|
2
2
|
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
3
|
-
import
|
|
4
|
-
import { isReactive, readonly, toRef } from "vue";
|
|
5
|
-
import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
3
|
+
import { readonly } from "vue";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Configuration for the default object crud functions.
|
|
@@ -10,33 +8,6 @@ import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
|
10
8
|
* @module config/objectCrud.js
|
|
11
9
|
*/
|
|
12
10
|
|
|
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
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
11
|
/**
|
|
41
12
|
* @typedef {{[key:string]: any}} ObjectCrudArgsArgs
|
|
42
13
|
*/
|
|
@@ -54,7 +25,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
54
25
|
*/
|
|
55
26
|
|
|
56
27
|
/**
|
|
57
|
-
* @typedef {object}
|
|
28
|
+
* @typedef {object} CreateArgs
|
|
58
29
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
59
30
|
* @property {{[key:string]: any}} object - The data to be acted upon.
|
|
60
31
|
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
@@ -63,7 +34,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
63
34
|
*/
|
|
64
35
|
|
|
65
36
|
/**
|
|
66
|
-
* @typedef {object}
|
|
37
|
+
* @typedef {object} RetrieveArgs
|
|
67
38
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
68
39
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
69
40
|
* @property {string} pkKey - The key name of the primary key.
|
|
@@ -72,7 +43,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
72
43
|
*/
|
|
73
44
|
|
|
74
45
|
/**
|
|
75
|
-
* @typedef {object}
|
|
46
|
+
* @typedef {object} UpdateArgs
|
|
76
47
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
77
48
|
* @property {import('../use/objectInstance.js').ExistingCrudObject} object - The data to be acted upon.
|
|
78
49
|
* @property {{[key:string]: any}} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
@@ -81,7 +52,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
81
52
|
*/
|
|
82
53
|
|
|
83
54
|
/**
|
|
84
|
-
* @typedef {object}
|
|
55
|
+
* @typedef {object} DeleteArgs
|
|
85
56
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
86
57
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
87
58
|
* @property {string} pkKey - The key name of the primary key.
|
|
@@ -89,7 +60,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
89
60
|
*/
|
|
90
61
|
|
|
91
62
|
/**
|
|
92
|
-
* @typedef {object}
|
|
63
|
+
* @typedef {object} PartialArgs
|
|
93
64
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
94
65
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
95
66
|
* @property {string} pkKey - The key name of the primary key.
|
|
@@ -105,7 +76,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
105
76
|
*/
|
|
106
77
|
|
|
107
78
|
/**
|
|
108
|
-
* @typedef {object}
|
|
79
|
+
* @typedef {object} ObjectSubscribeArgs
|
|
109
80
|
* @property {{[key:string]: any}} crudArgs - The arguments to be passed to the crud functions.
|
|
110
81
|
* @property {string} pk - The pk of the object to be acted upon.
|
|
111
82
|
* @property {string} pkKey - The key name of the primary key.
|
|
@@ -120,37 +91,37 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
120
91
|
|
|
121
92
|
/**
|
|
122
93
|
* @callback CrudCreateFn
|
|
123
|
-
* @param {
|
|
94
|
+
* @param {CreateArgs} args - The arguments to be passed to the create function.
|
|
124
95
|
* @returns {CrudResponse} - The response data from the create function.
|
|
125
96
|
*/
|
|
126
97
|
|
|
127
98
|
/**
|
|
128
99
|
* @callback CrudRetrieveFn
|
|
129
|
-
* @param {
|
|
100
|
+
* @param {RetrieveArgs} args - The arguments to be passed to the retrieve function.
|
|
130
101
|
* @returns {CrudResponse} - The response data from the retrieve function.
|
|
131
102
|
*/
|
|
132
103
|
|
|
133
104
|
/**
|
|
134
105
|
* @callback CrudUpdateFn
|
|
135
|
-
* @param {
|
|
106
|
+
* @param {UpdateArgs} args - The arguments to be passed to the update function.
|
|
136
107
|
* @returns {CrudResponse} - The response data from the update function.
|
|
137
108
|
*/
|
|
138
109
|
|
|
139
110
|
/**
|
|
140
111
|
* @callback CrudPatchFn
|
|
141
|
-
* @param {
|
|
112
|
+
* @param {PartialArgs} args - The arguments to be passed to the patch function.
|
|
142
113
|
* @returns {CrudResponse} - The response data from the patch function.
|
|
143
114
|
*/
|
|
144
115
|
|
|
145
116
|
/**
|
|
146
117
|
* @callback CrudDeleteFn
|
|
147
|
-
* @param {
|
|
118
|
+
* @param {DeleteArgs} args - The arguments to be passed to the delete function.
|
|
148
119
|
* @returns {CrudResponse} - The response data from the delete function.
|
|
149
120
|
*/
|
|
150
121
|
|
|
151
122
|
/**
|
|
152
|
-
* @callback
|
|
153
|
-
* @param {
|
|
123
|
+
* @callback CrudObjectSubscribeFn
|
|
124
|
+
* @param {ObjectSubscribeArgs} args - The arguments to be passed to the subscribe function.
|
|
154
125
|
* @returns {import('../utils/cancellablePromise.js').CancellablePromise<void>} - The cancellable promise.
|
|
155
126
|
*/
|
|
156
127
|
|
|
@@ -163,7 +134,7 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
163
134
|
* @property {CrudUpdateFn} [update] - A function to be used instead of the default crud update function.
|
|
164
135
|
* @property {CrudDeleteFn} [delete] - A function to be used instead of the default crud delete function.
|
|
165
136
|
* @property {CrudPatchFn} [patch] - A function to be used instead of the default crud patch function.
|
|
166
|
-
* @property {
|
|
137
|
+
* @property {CrudObjectSubscribeFn} [subscribe] - A function to be used instead of the default crud subscribe function.
|
|
167
138
|
*/
|
|
168
139
|
|
|
169
140
|
/**
|
|
@@ -173,17 +144,17 @@ const requiredCancelMissingMethod = (name) => () => {
|
|
|
173
144
|
*
|
|
174
145
|
*/
|
|
175
146
|
|
|
176
|
-
const _defaultCrud =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
};
|
|
147
|
+
const _defaultCrud = createDefaultCrud(
|
|
148
|
+
["retrieve", "create", "update", "patch", "delete", "subscribe"],
|
|
149
|
+
new Set(["subscribe"])
|
|
150
|
+
);
|
|
185
151
|
|
|
186
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The default object crud functions.
|
|
154
|
+
*
|
|
155
|
+
* @type {Readonly<ObjectCrudFunctions>}
|
|
156
|
+
*/
|
|
157
|
+
export const defaultObjectCrud = readonly(_defaultCrud);
|
|
187
158
|
|
|
188
159
|
/**
|
|
189
160
|
* Set the object crud functions.
|
|
@@ -191,45 +162,25 @@ export const defaultCrud = readonly(_defaultCrud);
|
|
|
191
162
|
* @param {ObjectCrudArgs} options - The options for the object crud functions.
|
|
192
163
|
* @throws {Error} - if unknown keys are passed.
|
|
193
164
|
*/
|
|
194
|
-
export const setObjectCrud = ({
|
|
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");
|
|
201
|
-
// defensive cloning
|
|
165
|
+
export const setObjectCrud = ({ args = {}, ...rest }) => {
|
|
202
166
|
Object.assign(_defaultCrud.args, cloneDeep(args));
|
|
203
|
-
|
|
204
|
-
|
|
167
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
168
|
+
if (!(key in _defaultCrud)) {
|
|
169
|
+
throw new Error(`Unknown key "${key}" passed to setObjectCrud`);
|
|
170
|
+
}
|
|
171
|
+
_defaultCrud[key] = value ?? _defaultCrud[key];
|
|
205
172
|
}
|
|
206
173
|
};
|
|
207
174
|
|
|
208
175
|
/**
|
|
209
176
|
* Get the previously set object crud functions.
|
|
210
177
|
*
|
|
211
|
-
* @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>}
|
|
178
|
+
* @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>} target - The reactive object you want to add the resulting crud to.
|
|
212
179
|
* @param {object} options - The options for the reactive crud object.
|
|
213
180
|
* @param {import("vue").UnwrapNestedRefs<ObjectCrudArgsOption>} [options.props] - The props with any passed crudArgs.
|
|
214
181
|
* @param {ObjectCrudFunctions} [options.functions] - Any functions to override the default crud functions.
|
|
215
182
|
* @throws {Error} - If an invalid function is passed, or if the function is not a function.
|
|
216
183
|
*/
|
|
217
|
-
export const getObjectCrud = (
|
|
218
|
-
|
|
219
|
-
Object.assign(reactiveCrud, cloneDeep(_defaultCrud));
|
|
220
|
-
if (props?.crudArgs) {
|
|
221
|
-
addOrUpdateReactiveObject(reactiveCrud.args, props.crudArgs);
|
|
222
|
-
}
|
|
223
|
-
if (functions) {
|
|
224
|
-
for (const [key, value] of Object.entries(functions)) {
|
|
225
|
-
if (isFunction(value) && key in reactiveCrud) {
|
|
226
|
-
reactiveCrud[key] = isReactive(functions)
|
|
227
|
-
? // @ts-ignore - key is a keyof ObjectCrudFunctions...
|
|
228
|
-
toRef(functions, key)
|
|
229
|
-
: value;
|
|
230
|
-
} else {
|
|
231
|
-
throw Error(`Invalid function "${key}" for getObjectCrud: invalid key or not a function.`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
184
|
+
export const getObjectCrud = (target, options) => {
|
|
185
|
+
assignCrud(target, _defaultCrud, options);
|
|
235
186
|
};
|
package/index.js
CHANGED
|
@@ -5,9 +5,9 @@ export * from "./use/cancellableIntent.js";
|
|
|
5
5
|
export * from "./use/combineClasses.js";
|
|
6
6
|
export * from "./use/list.js";
|
|
7
7
|
export * from "./use/listCalculated.js";
|
|
8
|
-
export * from "./use/listKeys.js";
|
|
9
8
|
export * from "./use/listFilter.js";
|
|
10
9
|
export * from "./use/listInstance.js";
|
|
10
|
+
export * from "./use/listKeys.js";
|
|
11
11
|
export * from "./use/listRelated.js";
|
|
12
12
|
export * from "./use/listSearch.js";
|
|
13
13
|
export * from "./use/listSort.js";
|
|
@@ -34,7 +34,9 @@ export * from "./utils/getFakePk.js";
|
|
|
34
34
|
export * from "./utils/keepAliveTry.js";
|
|
35
35
|
export * from "./utils/keyDiff.js";
|
|
36
36
|
export * from "./utils/loadingCombine.js";
|
|
37
|
+
export * from "./utils/refIfReactive.js";
|
|
37
38
|
export * from "./utils/relatedCalculatedHelpers.js";
|
|
38
39
|
export * from "./utils/set.js";
|
|
39
40
|
export * from "./utils/transformWalk.js";
|
|
41
|
+
export * from "./utils/unwrapNested.js";
|
|
40
42
|
export * from "./utils/watches.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrai-innovations/reactive-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.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,8 @@
|
|
|
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": "node make_type_doc.js"
|
|
33
|
+
"docs": "node make_type_doc.js",
|
|
34
|
+
"docs:check": "node check_type_doc.js"
|
|
34
35
|
},
|
|
35
36
|
"repository": {
|
|
36
37
|
"type": "git",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assigns the default CRUD functions to the target object.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} target - The reactive object to assign to.
|
|
5
|
+
* @param {object} defaultCrud - The default CRUD definition (usually created by `createDefaultCrud`).
|
|
6
|
+
* @param {object} [options] - The options object.
|
|
7
|
+
* @param {object} [options.props] - The props object.
|
|
8
|
+
* @param {object} [options.functions] - The functions to assign.
|
|
9
|
+
* @param {Set<string>} [options.validKeys] - The valid keys for the functions.
|
|
10
|
+
*/
|
|
11
|
+
export function assignCrud(target: object, defaultCrud: object, { props, functions, validKeys }?: {
|
|
12
|
+
props?: object;
|
|
13
|
+
functions?: object;
|
|
14
|
+
validKeys?: Set<string>;
|
|
15
|
+
}): void;
|
|
16
|
+
export function missingMethod(name: string): (...args: any[]) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<any>;
|
|
17
|
+
export function requiredCancelMissingMethod(name: string): ((..._args: any[]) => import("../utils/cancellablePromise.js").CancellablePromise<void>);
|
|
18
|
+
export function createDefaultCrud(keys: string[], cancellableKeys?: Set<string>): object;
|
|
19
|
+
//# sourceMappingURL=commonCrud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonCrud.d.ts","sourceRoot":"","sources":["../../config/commonCrud.js"],"names":[],"mappings":"AA4CA;;;;;;;;;GASG;AACH,mCAPW,MAAM,eACN,MAAM,oCAEd;IAAyB,KAAK,GAAtB,MAAM;IACW,SAAS,GAA1B,MAAM;IACgB,SAAS,GAA/B,GAAG,CAAC,MAAM,CAAC;CACrB,QAqBA;AAhEM,oCAHI,MAAM,GACJ,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,GAAG,CAAC,CAGjB;AAU9E,kDALI,MAAM,GACJ,CACZ,CAAO,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,OAAO,gCAAgC,EAAE,kBAAkB,CAAC,IAAI,CAAC,CACzF,CAOwG;AAUrG,wCAJI,MAAM,EAAE,oBACR,GAAG,CAAC,MAAM,CAAC,GACT,MAAM,CAQlB"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The default list crud functions.
|
|
3
|
+
*
|
|
4
|
+
* @type {Readonly<ListCrudFunctions>}
|
|
5
|
+
*/
|
|
6
|
+
export const defaultListCrud: Readonly<ListCrudFunctions>;
|
|
7
|
+
export function setListCrud({ args, ...rest }: ListCrudFunctions & Partial<ListCrudArgs>): void;
|
|
8
|
+
export function getListCrud(target: import("vue").UnwrapNestedRefs<ListCrudFunctions & ListCrudArgs>, options: {
|
|
9
|
+
props?: import("vue").UnwrapNestedRefs<ListCrudArgsOption>;
|
|
10
|
+
functions?: ListCrudFunctions;
|
|
7
11
|
}): void;
|
|
8
12
|
export type PaginateInfo = {
|
|
9
13
|
/**
|
|
@@ -20,7 +24,7 @@ export type PaginateInfo = {
|
|
|
20
24
|
perPage: number;
|
|
21
25
|
};
|
|
22
26
|
export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo: PaginateInfo | undefined) => void;
|
|
23
|
-
export type
|
|
27
|
+
export type ListArgs = {
|
|
24
28
|
/**
|
|
25
29
|
* - The arguments to be passed to the crud functions.
|
|
26
30
|
*/
|
|
@@ -47,7 +51,7 @@ export type ListFnArgs = {
|
|
|
47
51
|
*/
|
|
48
52
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
49
53
|
};
|
|
50
|
-
export type
|
|
54
|
+
export type BulkDeleteArgs = {
|
|
51
55
|
/**
|
|
52
56
|
* - The arguments to be passed to the crud functions.
|
|
53
57
|
*/
|
|
@@ -60,9 +64,14 @@ export type DeleteFnArgs = {
|
|
|
60
64
|
* - The key name of the primary key.
|
|
61
65
|
*/
|
|
62
66
|
pkKey: string;
|
|
67
|
+
/**
|
|
68
|
+
* - A ref to a boolean indicating whether the request has
|
|
69
|
+
* been cancelled.
|
|
70
|
+
*/
|
|
71
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
63
72
|
};
|
|
64
73
|
export type SubscriptionEventCallback = (newOrUpdatedOrDeleteObject: import("../use/listInstance.js").ListObject | string, action: "create" | "update" | "delete") => void;
|
|
65
|
-
export type
|
|
74
|
+
export type ListSubscribeArgs = {
|
|
66
75
|
/**
|
|
67
76
|
* - The arguments to be passed to the crud functions.
|
|
68
77
|
*/
|
|
@@ -83,8 +92,13 @@ export type SubscribeFnArgs = {
|
|
|
83
92
|
* - The method to call when new data is received.
|
|
84
93
|
*/
|
|
85
94
|
subscriptionEventCallback: SubscriptionEventCallback;
|
|
95
|
+
/**
|
|
96
|
+
* - A ref to a boolean indicating whether the request has
|
|
97
|
+
* been cancelled.
|
|
98
|
+
*/
|
|
99
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
86
100
|
};
|
|
87
|
-
export type
|
|
101
|
+
export type ExecuteActionArgs = {
|
|
88
102
|
/**
|
|
89
103
|
* - The arguments to be passed to the crud functions.
|
|
90
104
|
*/
|
|
@@ -101,53 +115,44 @@ export type ExecuteActionFnArgs = {
|
|
|
101
115
|
* - The action to execute.
|
|
102
116
|
*/
|
|
103
117
|
action: string;
|
|
118
|
+
/**
|
|
119
|
+
* - A ref to a boolean indicating whether the request has
|
|
120
|
+
* been cancelled.
|
|
121
|
+
*/
|
|
122
|
+
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
104
123
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
export type
|
|
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
|
-
};
|
|
124
|
+
export type CrudListFn = (args: ListArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<void>;
|
|
125
|
+
export type CrudBulkDeleteFn = (args: BulkDeleteArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<void>;
|
|
126
|
+
export type CrudListSubscribeFn = (args: ListSubscribeArgs) => import("../utils/cancellablePromise.js").CancellablePromise<void>;
|
|
127
|
+
export type CrudExecuteActionFn = (args: ExecuteActionArgs) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<object | string | null>;
|
|
129
128
|
export type ListCrudFunctions = {
|
|
130
129
|
/**
|
|
131
130
|
* - The list function to get a list of items.
|
|
132
131
|
*/
|
|
133
|
-
list?:
|
|
132
|
+
list?: CrudListFn;
|
|
134
133
|
/**
|
|
135
134
|
* - The delete function to bulk delete a list of items.
|
|
136
135
|
*/
|
|
137
|
-
bulkDelete?:
|
|
136
|
+
bulkDelete?: CrudBulkDeleteFn;
|
|
138
137
|
/**
|
|
139
138
|
* - The function to execute a certain action on a list of items.
|
|
140
139
|
*/
|
|
141
|
-
executeAction?:
|
|
140
|
+
executeAction?: CrudExecuteActionFn;
|
|
142
141
|
/**
|
|
143
142
|
* - The subscribe function to get a subscription to a list of items.
|
|
144
143
|
*/
|
|
145
|
-
subscribe?:
|
|
144
|
+
subscribe?: CrudListSubscribeFn;
|
|
146
145
|
};
|
|
147
146
|
export type ListCrudArgs = {
|
|
148
147
|
/**
|
|
149
148
|
* - The default arguments for the crud functions.
|
|
150
149
|
*/
|
|
151
|
-
args
|
|
150
|
+
args: object;
|
|
151
|
+
};
|
|
152
|
+
export type ListCrudArgsOption = {
|
|
153
|
+
/**
|
|
154
|
+
* - The default arguments for the crud functions.
|
|
155
|
+
*/
|
|
156
|
+
crudArgs?: object;
|
|
152
157
|
};
|
|
153
158
|
//# sourceMappingURL=listCrud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"AAoHA;;;;GAIG;AACH,8BAFU,QAAQ,CAAC,iBAAiB,CAAC,CAEiB;AAS/C,+CAJI,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,GAEvC,IAAI,CAUhB;AAWM,oCANI,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,YAAY,CAAC,WAExE;IAAqE,KAAK,GAAlE,OAAO,KAAK,EAAE,gBAAgB,CAAC,kBAAkB,CAAC;IACtB,SAAS,GAArC,iBAAiB;CACzB,QAIF;;;;;kBA3Ia,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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subscribe, args, ...rest }: ObjectCrudArgs): void;
|
|
11
|
-
export function getObjectCrud(reactiveCrud: import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>, { props, functions }?: {
|
|
1
|
+
/**
|
|
2
|
+
* The default object crud functions.
|
|
3
|
+
*
|
|
4
|
+
* @type {Readonly<ObjectCrudFunctions>}
|
|
5
|
+
*/
|
|
6
|
+
export const defaultObjectCrud: Readonly<ObjectCrudFunctions>;
|
|
7
|
+
export function setObjectCrud({ args, ...rest }: ObjectCrudArgs): void;
|
|
8
|
+
export function getObjectCrud(target: import("vue").UnwrapNestedRefs<ObjectCrudArgsProperties>, options: {
|
|
12
9
|
props?: import("vue").UnwrapNestedRefs<ObjectCrudArgsOption>;
|
|
13
10
|
functions?: ObjectCrudFunctions;
|
|
14
11
|
}): void;
|
|
@@ -30,7 +27,7 @@ export type ObjectCrudArgsOption = {
|
|
|
30
27
|
*/
|
|
31
28
|
crudArgs?: ObjectCrudArgsArgs;
|
|
32
29
|
};
|
|
33
|
-
export type
|
|
30
|
+
export type CreateArgs = {
|
|
34
31
|
/**
|
|
35
32
|
* - The arguments to be passed to the crud functions.
|
|
36
33
|
*/
|
|
@@ -58,7 +55,7 @@ export type CreateDetailArgs = {
|
|
|
58
55
|
*/
|
|
59
56
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
60
57
|
};
|
|
61
|
-
export type
|
|
58
|
+
export type RetrieveArgs = {
|
|
62
59
|
/**
|
|
63
60
|
* - The arguments to be passed to the crud functions.
|
|
64
61
|
*/
|
|
@@ -84,7 +81,7 @@ export type RetrieveDetailArgs = {
|
|
|
84
81
|
*/
|
|
85
82
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
86
83
|
};
|
|
87
|
-
export type
|
|
84
|
+
export type UpdateArgs = {
|
|
88
85
|
/**
|
|
89
86
|
* - The arguments to be passed to the crud functions.
|
|
90
87
|
*/
|
|
@@ -110,7 +107,7 @@ export type UpdateDetailArgs = {
|
|
|
110
107
|
*/
|
|
111
108
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
112
109
|
};
|
|
113
|
-
export type
|
|
110
|
+
export type DeleteArgs = {
|
|
114
111
|
/**
|
|
115
112
|
* - The arguments to be passed to the crud functions.
|
|
116
113
|
*/
|
|
@@ -130,7 +127,7 @@ export type DeleteDetailArgs = {
|
|
|
130
127
|
*/
|
|
131
128
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
132
129
|
};
|
|
133
|
-
export type
|
|
130
|
+
export type PartialArgs = {
|
|
134
131
|
/**
|
|
135
132
|
* - The arguments to be passed to the crud functions.
|
|
136
133
|
*/
|
|
@@ -163,7 +160,7 @@ export type PartialDetailArgs = {
|
|
|
163
160
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
164
161
|
};
|
|
165
162
|
export type CrudSubscribeCallback = (data: import("../use/objectInstance.js").ExistingCrudObject, action: string) => any;
|
|
166
|
-
export type
|
|
163
|
+
export type ObjectSubscribeArgs = {
|
|
167
164
|
/**
|
|
168
165
|
* - The arguments to be passed to the crud functions.
|
|
169
166
|
*/
|
|
@@ -194,12 +191,12 @@ export type SubscribeArgs = {
|
|
|
194
191
|
isCancelled: Readonly<import("vue").Ref<boolean>>;
|
|
195
192
|
};
|
|
196
193
|
export type CrudResponse = import("../utils/cancellablePromise.js").MaybeCancellablePromise<object | string>;
|
|
197
|
-
export type CrudCreateFn = (args:
|
|
198
|
-
export type CrudRetrieveFn = (args:
|
|
199
|
-
export type CrudUpdateFn = (args:
|
|
200
|
-
export type CrudPatchFn = (args:
|
|
201
|
-
export type CrudDeleteFn = (args:
|
|
202
|
-
export type
|
|
194
|
+
export type CrudCreateFn = (args: CreateArgs) => CrudResponse;
|
|
195
|
+
export type CrudRetrieveFn = (args: RetrieveArgs) => CrudResponse;
|
|
196
|
+
export type CrudUpdateFn = (args: UpdateArgs) => CrudResponse;
|
|
197
|
+
export type CrudPatchFn = (args: PartialArgs) => CrudResponse;
|
|
198
|
+
export type CrudDeleteFn = (args: DeleteArgs) => CrudResponse;
|
|
199
|
+
export type CrudObjectSubscribeFn = (args: ObjectSubscribeArgs) => import("../utils/cancellablePromise.js").CancellablePromise<void>;
|
|
203
200
|
/**
|
|
204
201
|
* Defines the CRUD-related functions and additional utilities provided by the object instance.
|
|
205
202
|
*/
|
|
@@ -227,11 +224,10 @@ export type ObjectCrudFunctions = {
|
|
|
227
224
|
/**
|
|
228
225
|
* - A function to be used instead of the default crud subscribe function.
|
|
229
226
|
*/
|
|
230
|
-
subscribe?:
|
|
227
|
+
subscribe?: CrudObjectSubscribeFn;
|
|
231
228
|
};
|
|
232
229
|
/**
|
|
233
230
|
* The CRUD arguments.
|
|
234
231
|
*/
|
|
235
232
|
export type ObjectCrudArgs = ObjectCrudArgsProperties & ObjectCrudFunctions;
|
|
236
|
-
import { CancellablePromise } from "../utils/cancellablePromise.js";
|
|
237
233
|
//# 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":"AAuJA;;;;GAIG;AACH,gCAFU,QAAQ,CAAC,mBAAmB,CAAC,CAEiB;AAQjD,iDAHI,cAAc,QAWxB;AAWM,sCANI,OAAO,KAAK,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,WAEhE;IAAuE,KAAK,GAApE,OAAO,KAAK,EAAE,gBAAgB,CAAC,oBAAoB,CAAC;IACtB,SAAS,GAAvC,mBAAmB;CAC3B,QAIF;iCA9KY;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,CAA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,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,UAAU,KACR,YAAY;oCAKd,YAAY,KACV,YAAY;kCAKd,UAAU,KACR,YAAY;iCAKd,WAAW,KACT,YAAY;kCAKd,UAAU,KACR,YAAY;2CAKd,mBAAmB,KACjB,OAAO,gCAAgC,EAAE,kBAAkB,CAAC,IAAI,CAAC;;;;;;;;aAOhE,YAAY;;;;eACZ,cAAc;;;;aACd,YAAY;;;;aACZ,YAAY;;;;YACZ,WAAW;;;;gBACX,qBAAqB;;;;;6BAMtB,wBAAwB,GAAG,mBAAmB"}
|
package/types/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export * from "./use/cancellableIntent.js";
|
|
|
4
4
|
export * from "./use/combineClasses.js";
|
|
5
5
|
export * from "./use/list.js";
|
|
6
6
|
export * from "./use/listCalculated.js";
|
|
7
|
-
export * from "./use/listKeys.js";
|
|
8
7
|
export * from "./use/listFilter.js";
|
|
9
8
|
export * from "./use/listInstance.js";
|
|
9
|
+
export * from "./use/listKeys.js";
|
|
10
10
|
export * from "./use/listRelated.js";
|
|
11
11
|
export * from "./use/listSearch.js";
|
|
12
12
|
export * from "./use/listSort.js";
|
|
@@ -33,8 +33,10 @@ export * from "./utils/getFakePk.js";
|
|
|
33
33
|
export * from "./utils/keepAliveTry.js";
|
|
34
34
|
export * from "./utils/keyDiff.js";
|
|
35
35
|
export * from "./utils/loadingCombine.js";
|
|
36
|
+
export * from "./utils/refIfReactive.js";
|
|
36
37
|
export * from "./utils/relatedCalculatedHelpers.js";
|
|
37
38
|
export * from "./utils/set.js";
|
|
38
39
|
export * from "./utils/transformWalk.js";
|
|
40
|
+
export * from "./utils/unwrapNested.js";
|
|
39
41
|
export * from "./utils/watches.js";
|
|
40
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
* @typedef {object} ListInstanceOptions
|
|
14
14
|
* @property {import('vue').UnwrapNestedRefs<ListInstanceProps>} props - The props for the list instance.
|
|
15
15
|
* @property {object} [functions] - Default implementation are used as set by `setListCrud`.
|
|
16
|
-
* @property {import('../config/listCrud.js').
|
|
16
|
+
* @property {import('../config/listCrud.js').CrudListFn} [functions.list] - Provide the implementation for the list
|
|
17
17
|
* function.
|
|
18
|
-
* @property {import('../config/listCrud.js').
|
|
18
|
+
* @property {import('../config/listCrud.js').CrudBulkDeleteFn} [functions.bulkDelete] - Provide the implementation for the bulkDelete
|
|
19
19
|
* function.
|
|
20
|
-
* @property {import('../config/listCrud.js').
|
|
20
|
+
* @property {import('../config/listCrud.js').CrudExecuteActionFn} [functions.executeAction] - Provide the implementation for the executeAction
|
|
21
21
|
* function.
|
|
22
|
-
* @property {import('../config/listCrud.js').
|
|
22
|
+
* @property {import('../config/listCrud.js').CrudListSubscribeFn} [functions.subscribe] - Provide the implementation for the
|
|
23
23
|
* subscribe function.
|
|
24
24
|
* @property {boolean} keepOldPages - If true, pages will not be cleared when defaultPageCallback is called.
|
|
25
25
|
*/
|
|
@@ -211,10 +211,10 @@ export type ListInstanceOptions = {
|
|
|
211
211
|
* - Default implementation are used as set by `setListCrud`.
|
|
212
212
|
*/
|
|
213
213
|
functions?: {
|
|
214
|
-
list?: import("../config/listCrud.js").
|
|
215
|
-
bulkDelete?: import("../config/listCrud.js").
|
|
216
|
-
executeAction?: import("../config/listCrud.js").
|
|
217
|
-
subscribe?: import("../config/listCrud.js").
|
|
214
|
+
list?: import("../config/listCrud.js").CrudListFn;
|
|
215
|
+
bulkDelete?: import("../config/listCrud.js").CrudBulkDeleteFn;
|
|
216
|
+
executeAction?: import("../config/listCrud.js").CrudExecuteActionFn;
|
|
217
|
+
subscribe?: import("../config/listCrud.js").CrudListSubscribeFn;
|
|
218
218
|
};
|
|
219
219
|
/**
|
|
220
220
|
* - If true, pages will not be cleared when defaultPageCallback is called.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listInstance.d.ts","sourceRoot":"","sources":["../../use/listInstance.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listInstance.d.ts","sourceRoot":"","sources":["../../use/listInstance.js"],"names":[],"mappings":"AAwCA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;GAKG;AACH,mDAHW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAA;CAAC,GAClC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAC,CASzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,oEALW,mBAAmB,GAEjB,YAAY,CAqTxB;AAzfD;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;GAGG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;;;;;;;;WAMa,MAAM;;;;kBACN,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;;;;;;;;;WAON,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,CAAC;;;;gBAE5D;QAAkE,IAAI,GAA3D,OAAO,uBAAuB,EAAE,UAAU;QAEoB,UAAU,GAAvE,OAAO,uBAAuB,EAAE,gBAAgB;QAEiB,aAAa,GAA7E,OAAO,uBAAuB,EAAE,mBAAmB;QAEW,SAAS,G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BAM1B,sBAAsB,GAAG,qBAAqB;;;;;yBApH9C;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC"}
|
|
@@ -102,13 +102,13 @@ export function useObjectInstance({ props, functions }: ObjectInstanceOptions):
|
|
|
102
102
|
* @property {import('../config/objectCrud.js').CrudUpdateFn} update - The update function.
|
|
103
103
|
* @property {import('../config/objectCrud.js').CrudPatchFn} patch - The patch function.
|
|
104
104
|
* @property {import('../config/objectCrud.js').CrudDeleteFn} delete - The delete function.
|
|
105
|
-
* @property {import('../config/objectCrud.js').
|
|
105
|
+
* @property {import('../config/objectCrud.js').CrudObjectSubscribeFn} subscribe - The subscribe function.
|
|
106
106
|
*/
|
|
107
107
|
/**
|
|
108
108
|
* The raw state of the object instance.
|
|
109
109
|
*
|
|
110
110
|
* @typedef {object} ObjectInstanceRawState
|
|
111
|
-
* @property {import('vue').
|
|
111
|
+
* @property {import('vue').Reactive<ObjectInstanceRawStateCrud>} crud - The crud functions.
|
|
112
112
|
* @property {import('vue').Ref<string|undefined>} pk - The pk of the object.
|
|
113
113
|
* @property {import('vue').Ref<string|undefined>} pkKey - The pk key of the object.
|
|
114
114
|
* @property {import('vue').Ref<{[key:string]: any}>} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
@@ -236,7 +236,7 @@ export type ObjectInstanceRawStateCrud = {
|
|
|
236
236
|
/**
|
|
237
237
|
* - The subscribe function.
|
|
238
238
|
*/
|
|
239
|
-
subscribe: import("../config/objectCrud.js").
|
|
239
|
+
subscribe: import("../config/objectCrud.js").CrudObjectSubscribeFn;
|
|
240
240
|
};
|
|
241
241
|
/**
|
|
242
242
|
* The raw state of the object instance.
|
|
@@ -245,7 +245,7 @@ export type ObjectInstanceRawState = {
|
|
|
245
245
|
/**
|
|
246
246
|
* - The crud functions.
|
|
247
247
|
*/
|
|
248
|
-
crud: import("vue").
|
|
248
|
+
crud: import("vue").Reactive<ObjectInstanceRawStateCrud>;
|
|
249
249
|
/**
|
|
250
250
|
* - The pk of the object.
|
|
251
251
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectInstance.d.ts","sourceRoot":"","sources":["../../use/objectInstance.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"objectInstance.d.ts","sourceRoot":"","sources":["../../use/objectInstance.js"],"names":[],"mappings":"AAwIA;;;;;GAKG;AACH,iDAHW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,CAAA;CAAC,GACpC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAC,CAS3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wDAHW,qBAAqB,GACnB,cAAc,CAiR1B;AAndD;;;;GAIG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;GAGG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;AAED,+CAUE;AAEF,+CAAkH;;;;iCAtHrG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC;4BAInC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC;yBAIpB,kBAAkB,GAAC,aAAa;;;;;;;;WAO/B,OAAO,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;;;;gBACtD,OAAO,yBAAyB,EAAE,mBAAmB;;;;;;;;;SAOrD,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,OAAO,yBAAyB,EAAE,cAAc;;;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AAE,uBAAuB,CAAC,OAAO,CAAC;;;;YACnH,MAAM,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,OAAO,CAAC;;;;WAC/E,CAAC,IAAI,EAAE;QAAE,aAAa,EAAE,kBAAkB,CAAA;KAAE,KAAK,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,OAAO,CAAC;;;;gBAC1H,OAAO,mBAAmB,EAAE,YAAY;;;;WACxC,MAAM,IAAI;;;;;;;;;WAOV,mBAAmB;;;;;6BAMpB,uBAAuB,GAAG,wBAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refIfReactive.d.ts","sourceRoot":"","sources":["../../utils/refIfReactive.js"],"names":[],"mappings":"AAYO,8BAPM,CAAC,EACS,CAAC,SAAX,MAAO,CAAE,UACX,CAAA,CAAC,GAAG,MAAM,IAAG,SAAS,GAAG,IAAI,YAC7B,CAAC,iBACD,CAAC,CAAC,CAAC,CAAC,GACF,OAAO,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAOtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapNested.d.ts","sourceRoot":"","sources":["../../utils/unwrapNested.js"],"names":[],"mappings":"AASO,6BAJM,CAAC,OACH,CAAC,GACC,OAAO,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAiBtC"}
|
package/use/listInstance.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { getListCrud } from "../config/listCrud.js";
|
|
1
|
+
import { defaultListCrud, getListCrud } from "../config/listCrud.js";
|
|
2
2
|
import { assignReactiveObject } from "../utils/assignReactiveObject.js";
|
|
3
3
|
import { getFakePk } from "../utils/getFakePk.js";
|
|
4
4
|
import { useLoadingError } from "./loadingError.js";
|
|
5
5
|
import inspect from "browser-util-inspect";
|
|
6
|
-
import { computed, effectScope, nextTick, reactive, readonly, ref, toRef, unref, watch } from "vue";
|
|
6
|
+
import { computed, effectScope, nextTick, reactive, readonly, ref, shallowReactive, toRef, unref, watch } from "vue";
|
|
7
7
|
import { CancellablePromise, wrapMaybeCancellable } from "../utils/cancellablePromise.js";
|
|
8
|
+
import { refIfReactive } from "../utils/refIfReactive.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* A composable function for managing a list of objects.
|
|
@@ -53,13 +54,13 @@ export class ListInstanceError extends Error {
|
|
|
53
54
|
* @typedef {object} ListInstanceOptions
|
|
54
55
|
* @property {import('vue').UnwrapNestedRefs<ListInstanceProps>} props - The props for the list instance.
|
|
55
56
|
* @property {object} [functions] - Default implementation are used as set by `setListCrud`.
|
|
56
|
-
* @property {import('../config/listCrud.js').
|
|
57
|
+
* @property {import('../config/listCrud.js').CrudListFn} [functions.list] - Provide the implementation for the list
|
|
57
58
|
* function.
|
|
58
|
-
* @property {import('../config/listCrud.js').
|
|
59
|
+
* @property {import('../config/listCrud.js').CrudBulkDeleteFn} [functions.bulkDelete] - Provide the implementation for the bulkDelete
|
|
59
60
|
* function.
|
|
60
|
-
* @property {import('../config/listCrud.js').
|
|
61
|
+
* @property {import('../config/listCrud.js').CrudExecuteActionFn} [functions.executeAction] - Provide the implementation for the executeAction
|
|
61
62
|
* function.
|
|
62
|
-
* @property {import('../config/listCrud.js').
|
|
63
|
+
* @property {import('../config/listCrud.js').CrudListSubscribeFn} [functions.subscribe] - Provide the implementation for the
|
|
63
64
|
* subscribe function.
|
|
64
65
|
* @property {boolean} keepOldPages - If true, pages will not be cleared when defaultPageCallback is called.
|
|
65
66
|
*/
|
|
@@ -207,16 +208,22 @@ export function useListInstances(listInstanceArgs) {
|
|
|
207
208
|
*/
|
|
208
209
|
export function useListInstance({ props, functions = {}, keepOldPages }) {
|
|
209
210
|
if (!props) {
|
|
210
|
-
throw new ListInstanceError(
|
|
211
|
+
throw new ListInstanceError("useListInstance requires props", "missing-props");
|
|
211
212
|
}
|
|
212
213
|
if (keepOldPages === undefined) {
|
|
213
|
-
throw new ListInstanceError(
|
|
214
|
+
throw new ListInstanceError("useListInstance requires keepOldPages", "missing-keepOldPages");
|
|
214
215
|
}
|
|
216
|
+
if (!props.pkKey) {
|
|
217
|
+
throw new ListInstanceError("useListInstance requires pkKey.", "missing-pkKey");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const es = effectScope();
|
|
215
221
|
|
|
216
222
|
// ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
|
|
217
223
|
const _objectsMap = new Map(); // maps are ordered, if you don't clear lists, you need to insert pages in order.
|
|
218
224
|
|
|
219
225
|
// ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
|
|
226
|
+
// noinspection JSValidateTypes
|
|
220
227
|
/** @type {{[key: string]: ListObject}} */
|
|
221
228
|
// @ts-ignore - we are using a proxy to make this map behave like an object for reactivity
|
|
222
229
|
const _objectsProxy = new Proxy(_objectsMap, {
|
|
@@ -251,7 +258,7 @@ export function useListInstance({ props, functions = {}, keepOldPages }) {
|
|
|
251
258
|
}
|
|
252
259
|
: Reflect.getOwnPropertyDescriptor(target, p); // we can't report target properties as non-existent re: proxy invariants
|
|
253
260
|
},
|
|
254
|
-
// things introspect us thing we are a map, we need to pretend to be
|
|
261
|
+
// things introspect us thing we are a map, we need to pretend to be an object
|
|
255
262
|
getPrototypeOf() {
|
|
256
263
|
return Object.prototype;
|
|
257
264
|
},
|
|
@@ -263,27 +270,24 @@ export function useListInstance({ props, functions = {}, keepOldPages }) {
|
|
|
263
270
|
|
|
264
271
|
// ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
|
|
265
272
|
const state = reactive({
|
|
266
|
-
crud: {
|
|
267
|
-
args: {},
|
|
268
|
-
list:
|
|
269
|
-
bulkDelete:
|
|
270
|
-
executeAction:
|
|
271
|
-
},
|
|
272
|
-
pkKey:
|
|
273
|
-
retrieveArgs:
|
|
274
|
-
listArgs:
|
|
273
|
+
crud: shallowReactive({
|
|
274
|
+
args: reactive({}),
|
|
275
|
+
list: defaultListCrud.list,
|
|
276
|
+
bulkDelete: defaultListCrud.bulkDelete,
|
|
277
|
+
executeAction: defaultListCrud.executeAction,
|
|
278
|
+
}),
|
|
279
|
+
pkKey: refIfReactive(props, "pkKey"),
|
|
280
|
+
retrieveArgs: refIfReactive(props, "retrieveArgs", {}),
|
|
281
|
+
listArgs: refIfReactive(props, "listArgs", {}),
|
|
275
282
|
/** @type {{[key: string]: ListObject}} */
|
|
276
283
|
objects: /** @type {{[key: string]: ListObject}} */ _objectsProxy,
|
|
277
284
|
running: false,
|
|
278
285
|
loading: loadingError.loading,
|
|
279
286
|
errored: loadingError.errored,
|
|
280
287
|
error: loadingError.error,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
/** @type {import('vue').ComputedRef<ListObject[]>|undefined} */
|
|
284
|
-
objectsInOrder: undefined,
|
|
288
|
+
order: es.run(() => computed(() => Object.keys(state.objects))),
|
|
289
|
+
objectsInOrder: es.run(() => computed(() => objectsInOrderRefs.value.map((ref) => unref(ref)))),
|
|
285
290
|
});
|
|
286
|
-
const es = effectScope();
|
|
287
291
|
|
|
288
292
|
getListCrud(state.crud, { props, functions });
|
|
289
293
|
|
|
@@ -345,13 +349,13 @@ export function useListInstance({ props, functions = {}, keepOldPages }) {
|
|
|
345
349
|
pks: Object.keys(state.objects).map(Number),
|
|
346
350
|
pkKey: state.pkKey,
|
|
347
351
|
})
|
|
348
|
-
.then((/** @type {
|
|
352
|
+
.then((/** @type {object|string} */ responseData) => {
|
|
349
353
|
loadingError.clearError();
|
|
350
354
|
return Promise.resolve(responseData);
|
|
351
355
|
})
|
|
352
356
|
.catch((/** @type {Error} */ error) => {
|
|
353
357
|
loadingError.setError(error);
|
|
354
|
-
return Promise.resolve(
|
|
358
|
+
return Promise.resolve(null);
|
|
355
359
|
})
|
|
356
360
|
.finally(() => {
|
|
357
361
|
loadingError.clearLoading();
|
|
@@ -489,10 +493,6 @@ export function useListInstance({ props, functions = {}, keepOldPages }) {
|
|
|
489
493
|
deep: true,
|
|
490
494
|
}
|
|
491
495
|
);
|
|
492
|
-
// @ts-ignore - we want the computed in the explicit effect scope, tsc is mad that we are 'changing' the type
|
|
493
|
-
state.objectsInOrder = computed(() => objectsInOrderRefs.value.map((ref) => unref(ref)));
|
|
494
|
-
// @ts-ignore - we want the computed in the explicit effect scope, tsc is mad that we are 'changing' the type
|
|
495
|
-
state.order = computed(() => Object.keys(state.objects));
|
|
496
496
|
});
|
|
497
497
|
|
|
498
498
|
// This isn't a direct return because we want the live returnedObject.pageCallback in list()
|
package/use/objectInstance.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defaultObjectCrud, getObjectCrud } from "../config/objectCrud.js";
|
|
2
2
|
import { assignReactiveObject } from "../utils/assignReactiveObject.js";
|
|
3
3
|
import { useLoadingError } from "./loadingError.js";
|
|
4
|
-
import { reactive, readonly, ref, shallowReactive
|
|
4
|
+
import { reactive, readonly, ref, shallowReactive } from "vue";
|
|
5
5
|
import { wrapMaybeCancellable } from "../utils/cancellablePromise.js";
|
|
6
|
+
import { refIfReactive } from "../utils/refIfReactive.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A composition function to manage create, retrieve, update, delete, and patch operations.
|
|
@@ -50,14 +51,14 @@ import { wrapMaybeCancellable } from "../utils/cancellablePromise.js";
|
|
|
50
51
|
* @property {import('../config/objectCrud.js').CrudUpdateFn} update - The update function.
|
|
51
52
|
* @property {import('../config/objectCrud.js').CrudPatchFn} patch - The patch function.
|
|
52
53
|
* @property {import('../config/objectCrud.js').CrudDeleteFn} delete - The delete function.
|
|
53
|
-
* @property {import('../config/objectCrud.js').
|
|
54
|
+
* @property {import('../config/objectCrud.js').CrudObjectSubscribeFn} subscribe - The subscribe function.
|
|
54
55
|
*/
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* The raw state of the object instance.
|
|
58
59
|
*
|
|
59
60
|
* @typedef {object} ObjectInstanceRawState
|
|
60
|
-
* @property {import('vue').
|
|
61
|
+
* @property {import('vue').Reactive<ObjectInstanceRawStateCrud>} crud - The crud functions.
|
|
61
62
|
* @property {import('vue').Ref<string|undefined>} pk - The pk of the object.
|
|
62
63
|
* @property {import('vue').Ref<string|undefined>} pkKey - The pk key of the object.
|
|
63
64
|
* @property {import('vue').Ref<{[key:string]: any}>} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
@@ -211,23 +212,22 @@ export function useObjectInstance({ props, functions = {} }) {
|
|
|
211
212
|
const state = reactive(
|
|
212
213
|
/** @type {ObjectInstanceRawState} */
|
|
213
214
|
{
|
|
214
|
-
// function typing support is a lot nicer with shallow reactive
|
|
215
215
|
crud: shallowReactive(
|
|
216
216
|
/** @type {ObjectInstanceRawStateCrud} */
|
|
217
217
|
{
|
|
218
218
|
args: reactive({}),
|
|
219
|
-
create:
|
|
220
|
-
retrieve:
|
|
221
|
-
update:
|
|
222
|
-
delete:
|
|
223
|
-
patch:
|
|
224
|
-
subscribe:
|
|
219
|
+
create: defaultObjectCrud.create,
|
|
220
|
+
retrieve: defaultObjectCrud.retrieve,
|
|
221
|
+
update: defaultObjectCrud.update,
|
|
222
|
+
delete: defaultObjectCrud.delete,
|
|
223
|
+
patch: defaultObjectCrud.patch,
|
|
224
|
+
subscribe: defaultObjectCrud.subscribe,
|
|
225
225
|
}
|
|
226
226
|
),
|
|
227
227
|
object: reactive({}),
|
|
228
|
-
pk:
|
|
229
|
-
pkKey:
|
|
230
|
-
retrieveArgs:
|
|
228
|
+
pk: refIfReactive(props, "pk", null),
|
|
229
|
+
pkKey: refIfReactive(props, "pkKey"),
|
|
230
|
+
retrieveArgs: refIfReactive(props, "retrieveArgs", {}),
|
|
231
231
|
loading: loadingError.loading,
|
|
232
232
|
errored: loadingError.errored,
|
|
233
233
|
error: loadingError.error,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isReactive, toRef, unref } from "vue";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a ref to a property if the source is reactive, otherwise returns the unrefed value.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @template {keyof T} K
|
|
8
|
+
* @param {T & object | undefined | null} source - The source object.
|
|
9
|
+
* @param {K} property - The property to access.
|
|
10
|
+
* @param {T[K]} [defaultValue] - The default value to use if source or property is missing.
|
|
11
|
+
* @returns {import('vue').Ref<T[K]> | T[K] | undefined} The ref to the property if the source is reactive, otherwise the unrefed value.
|
|
12
|
+
*/
|
|
13
|
+
export const refIfReactive = (source, property, defaultValue) => {
|
|
14
|
+
if (source && isReactive(source)) {
|
|
15
|
+
return toRef(source, property);
|
|
16
|
+
}
|
|
17
|
+
return unref(source?.[property]) ?? defaultValue;
|
|
18
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isProxy, isReactive, isRef, toRaw, unref } from "vue";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Unwraps Vue refs and proxies to get the raw value.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T} arg - The argument to unwrap.
|
|
8
|
+
* @returns {import('vue').UnwrapRef<T>} The unwrapped value.
|
|
9
|
+
*/
|
|
10
|
+
export const unwrapNested = (arg) => {
|
|
11
|
+
/** @type {unknown} */
|
|
12
|
+
let key = arg;
|
|
13
|
+
let proxied = isProxy(arg) || isReactive(arg);
|
|
14
|
+
let refed = isRef(arg);
|
|
15
|
+
while (proxied || refed) {
|
|
16
|
+
if (proxied) {
|
|
17
|
+
key = toRaw(key);
|
|
18
|
+
} else if (refed) {
|
|
19
|
+
key = unref(key);
|
|
20
|
+
}
|
|
21
|
+
proxied = isProxy(key);
|
|
22
|
+
refed = isRef(key);
|
|
23
|
+
}
|
|
24
|
+
return /** @type {import('vue').UnwrapRef<T>} */ (key);
|
|
25
|
+
};
|