@arrai-innovations/reactive-helpers 18.0.0 → 18.0.2
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/package.json +20 -6
- package/types/config/listCrud.d.ts +153 -0
- package/types/config/listCrud.d.ts.map +1 -0
- package/types/config/objectCrud.d.ts +171 -0
- package/types/config/objectCrud.d.ts.map +1 -0
- package/types/index.d.ts +37 -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 +129 -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 +81 -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 +289 -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 +249 -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 +36 -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/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/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/loadingError.js +1 -1
- package/.circleci/config.yml +0 -88
- package/.commitlintrc.json +0 -25
- 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
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to create multiple object calculateds instances.
|
|
3
|
+
*
|
|
4
|
+
* @param {{
|
|
5
|
+
* [key: string]: ObjectCalculatedOptions
|
|
6
|
+
* }} objectCalculatedArgs - Options for each object calculated to create.
|
|
7
|
+
* @returns {{
|
|
8
|
+
* [key: string]: ObjectCalculated
|
|
9
|
+
* }} - The created object calculated instances by key.
|
|
10
|
+
*/
|
|
11
|
+
export function useObjectCalculateds(objectCalculatedArgs: {
|
|
12
|
+
[key: string]: ObjectCalculatedOptions;
|
|
13
|
+
}): {
|
|
14
|
+
[key: string]: ObjectCalculated;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Vue Composition API composable function for object calculated.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```vue
|
|
21
|
+
* <script setup>
|
|
22
|
+
* import { useObjectCalculated, useObjectSubscription } from "@arrai-innovations/reactive-helpers";
|
|
23
|
+
* import { ref, reactive } from "vue";
|
|
24
|
+
*
|
|
25
|
+
* const objectSubscriptionProps = reactive({
|
|
26
|
+
* // whatever object subscription props you need to work with your crud implementation
|
|
27
|
+
* crudArgs: {},
|
|
28
|
+
* retrieveArgs: {},
|
|
29
|
+
* pk: '1',
|
|
30
|
+
* pkKey: 'id',
|
|
31
|
+
* intendToRetrieve: true,
|
|
32
|
+
* };
|
|
33
|
+
* const objectSubscription = useObjectSubscription(objectSubscriptionProps);
|
|
34
|
+
* const objectCalculatedProps = reactive({
|
|
35
|
+
* parentState: objectSubscription.state,
|
|
36
|
+
* calculatedObjectRules: {
|
|
37
|
+
* someRule: (object, relatedObject, calculatedObjects) => {
|
|
38
|
+
* // some complex calculation, relatedObjects would be assuming there was a listRelated between the two
|
|
39
|
+
* // calculatedObjects would be the other calculated objects in the list
|
|
40
|
+
* // including yourself, so try not to create circular dependencies
|
|
41
|
+
* // this is used as a computed body.
|
|
42
|
+
* return object.someProperty + object.someOtherProperty;
|
|
43
|
+
* },
|
|
44
|
+
* ...
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
* </script>
|
|
48
|
+
* <template>
|
|
49
|
+
* <div>
|
|
50
|
+
* <!-- the reactive result of the calculation, based on the fn passed in, turned into a computed -->
|
|
51
|
+
* <p>{{ objectCalculated.state.calculatedObject.someRule }}</p>
|
|
52
|
+
* </div>
|
|
53
|
+
* </template>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param {ObjectCalculatedOptions} options - The object calculated options.
|
|
57
|
+
* @returns {ObjectCalculated} - The object calculated instance.
|
|
58
|
+
*/
|
|
59
|
+
export function useObjectCalculated({ parentState, calculatedObjectRules }: ObjectCalculatedOptions): ObjectCalculated;
|
|
60
|
+
/**
|
|
61
|
+
* Vue Composition API composable function for object calculated.
|
|
62
|
+
*
|
|
63
|
+
* @module use/objectCalculated.js
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* The object calculated state keys.
|
|
67
|
+
*
|
|
68
|
+
* @typedef {{
|
|
69
|
+
* [ruleKey: string]: (object: any, relatedObject: any) => any
|
|
70
|
+
* }} ObjectCalculatedRules
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {object} ObjectCalculatedRawState - The raw state for object calculated.
|
|
74
|
+
* @property {ObjectCalculatedRules} calculatedObjectRules - The calculated object rules.
|
|
75
|
+
* @property {{
|
|
76
|
+
* [ruleKey: string]: import('vue').ComputedRef<any>
|
|
77
|
+
* }} calculatedObject - The calculated object.
|
|
78
|
+
* @property {boolean} calculatedObjectWatchRunning - Whether the calculated object watch is running.
|
|
79
|
+
* @property {boolean} parentStateObjectWatchRunning - Whether the parent state object watch is running.
|
|
80
|
+
* @property {boolean} calculatedRunning - Whether the calculated is running.
|
|
81
|
+
* @property {import('vue').Ref<boolean>} running - Whether the object calculated is running.
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
*
|
|
86
|
+
* @typedef {(
|
|
87
|
+
* import('./objectInstance.js').ObjectInstanceRawState &
|
|
88
|
+
* Partial<import('./objectSubscription.js').ObjectSubscriptionRawState> &
|
|
89
|
+
* Partial<import('./objectRelated.js').ObjectRelatedRawState>
|
|
90
|
+
* )} ObjectCalculatedParentRawState
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* @typedef {import('vue').UnwrapNestedRefs<(
|
|
96
|
+
* ObjectCalculatedParentRawState
|
|
97
|
+
* )>} ObjectCalculatedParentState - The object calculated options.
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* The state for object calculated.
|
|
101
|
+
*
|
|
102
|
+
* @typedef {import('vue').UnwrapNestedRefs<
|
|
103
|
+
* ObjectCalculatedParentRawState &
|
|
104
|
+
* ObjectCalculatedRawState
|
|
105
|
+
* >} ObjectCalculatedState
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* The properties for object calculated.
|
|
109
|
+
*
|
|
110
|
+
* @typedef {object} ObjectCalculatedProperties
|
|
111
|
+
* @property {ObjectCalculatedParentState} parentState - The parent state.
|
|
112
|
+
* @property {ObjectCalculatedState} state - The object calculated state.
|
|
113
|
+
* @property {import('./watchesRunning.js').WatchesRunning} watchesRunning - The watches running rules.
|
|
114
|
+
* @property {import('vue').EffectScope} effectScope - The effect scope.
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* The object calculated instance.
|
|
118
|
+
*
|
|
119
|
+
* @typedef {ObjectCalculatedProperties} ObjectCalculated
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
*
|
|
124
|
+
* @typedef {object} ObjectCalculatedRawProps
|
|
125
|
+
* @property {import('vue').Ref<ObjectCalculatedRules>} calculatedObjectRules - The calculated object rules.
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @typedef {({
|
|
130
|
+
* parentState: ObjectCalculatedParentState,
|
|
131
|
+
* } & ObjectCalculatedRawProps)} ObjectCalculatedOptions
|
|
132
|
+
*/
|
|
133
|
+
export const objectCalculatedStateKeys: string[];
|
|
134
|
+
export const objectCalculatedFunctions: any[];
|
|
135
|
+
/**
|
|
136
|
+
* The object calculated state keys.
|
|
137
|
+
*/
|
|
138
|
+
export type ObjectCalculatedRules = {
|
|
139
|
+
[ruleKey: string]: (object: any, relatedObject: any) => any;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* - The raw state for object calculated.
|
|
143
|
+
*/
|
|
144
|
+
export type ObjectCalculatedRawState = {
|
|
145
|
+
/**
|
|
146
|
+
* - The calculated object rules.
|
|
147
|
+
*/
|
|
148
|
+
calculatedObjectRules: ObjectCalculatedRules;
|
|
149
|
+
/**
|
|
150
|
+
* - The calculated object.
|
|
151
|
+
*/
|
|
152
|
+
calculatedObject: {
|
|
153
|
+
[ruleKey: string]: import("vue").ComputedRef<any>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* - Whether the calculated object watch is running.
|
|
157
|
+
*/
|
|
158
|
+
calculatedObjectWatchRunning: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* - Whether the parent state object watch is running.
|
|
161
|
+
*/
|
|
162
|
+
parentStateObjectWatchRunning: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* - Whether the calculated is running.
|
|
165
|
+
*/
|
|
166
|
+
calculatedRunning: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* - Whether the object calculated is running.
|
|
169
|
+
*/
|
|
170
|
+
running: import("vue").Ref<boolean>;
|
|
171
|
+
};
|
|
172
|
+
export type ObjectCalculatedParentRawState = (import("./objectInstance.js").ObjectInstanceRawState & Partial<import("./objectSubscription.js").ObjectSubscriptionRawState> & Partial<import("./objectRelated.js").ObjectRelatedRawState>);
|
|
173
|
+
/**
|
|
174
|
+
* - The object calculated options.
|
|
175
|
+
*/
|
|
176
|
+
export type ObjectCalculatedParentState = import("vue").UnwrapNestedRefs<(ObjectCalculatedParentRawState)>;
|
|
177
|
+
/**
|
|
178
|
+
* The state for object calculated.
|
|
179
|
+
*/
|
|
180
|
+
export type ObjectCalculatedState = import("vue").UnwrapNestedRefs<ObjectCalculatedParentRawState & ObjectCalculatedRawState>;
|
|
181
|
+
/**
|
|
182
|
+
* The properties for object calculated.
|
|
183
|
+
*/
|
|
184
|
+
export type ObjectCalculatedProperties = {
|
|
185
|
+
/**
|
|
186
|
+
* - The parent state.
|
|
187
|
+
*/
|
|
188
|
+
parentState: ObjectCalculatedParentState;
|
|
189
|
+
/**
|
|
190
|
+
* - The object calculated state.
|
|
191
|
+
*/
|
|
192
|
+
state: ObjectCalculatedState;
|
|
193
|
+
/**
|
|
194
|
+
* - The watches running rules.
|
|
195
|
+
*/
|
|
196
|
+
watchesRunning: import("./watchesRunning.js").WatchesRunning;
|
|
197
|
+
/**
|
|
198
|
+
* - The effect scope.
|
|
199
|
+
*/
|
|
200
|
+
effectScope: import("vue").EffectScope;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* The object calculated instance.
|
|
204
|
+
*/
|
|
205
|
+
export type ObjectCalculated = ObjectCalculatedProperties;
|
|
206
|
+
export type ObjectCalculatedRawProps = {
|
|
207
|
+
/**
|
|
208
|
+
* - The calculated object rules.
|
|
209
|
+
*/
|
|
210
|
+
calculatedObjectRules: import("vue").Ref<ObjectCalculatedRules>;
|
|
211
|
+
};
|
|
212
|
+
export type ObjectCalculatedOptions = ({
|
|
213
|
+
parentState: ObjectCalculatedParentState;
|
|
214
|
+
} & ObjectCalculatedRawProps);
|
|
215
|
+
//# sourceMappingURL=objectCalculated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectCalculated.d.ts","sourceRoot":"","sources":["../../use/objectCalculated.js"],"names":[],"mappings":"AA2GA;;;;;;;;;GASG;AACH,2DAPW;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAA;CACzC,GACS;IACZ,CAAM,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACjC,CAYH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,4EAHW,uBAAuB,GACrB,gBAAgB,CA4G5B;AA3QD;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;GAUG;AAEH;;;;;;;;GAQG;AAEH;;;;;;GAMG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AAIH;;;;GAIG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AAEH,iDAOE;AAEF,8CAA4C;;;;oCArF/B;IACZ,CAAO,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,KAAK,GAAG,CAAA;CAC9D;;;;;;;;2BAKU,qBAAqB;;;;sBACrB;QACb,CAAO,OAAO,EAAE,MAAM,GAAG,OAAO,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;KACpD;;;;kCACU,OAAO;;;;mCACP,OAAO;;;;uBACP,OAAO;;;;aACP,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;;6CAM3B,CACZ,OAAa,qBAAqB,EAAE,sBAAsB,GACpD,OAAO,CAAC,OAAO,yBAAyB,EAAE,0BAA0B,CAAC,GACrE,OAAO,CAAC,OAAO,oBAAoB,EAAE,qBAAqB,CAAC,CAC9D;;;;0CAMS,OAAO,KAAK,EAAE,gBAAgB,CAAC,CACrC,8BAA8B,CACjC,CAAC;;;;oCAMQ,OAAO,KAAK,EAAE,gBAAgB,CACtC,8BAA8B,GAC9B,wBAAwB,CACzB;;;;;;;;iBAOU,2BAA2B;;;;WAC3B,qBAAqB;;;;oBACrB,OAAO,qBAAqB,EAAE,cAAc;;;;iBAC5C,OAAO,KAAK,EAAE,WAAW;;;;;+BAQ1B,0BAA0B;;;;;2BAOzB,OAAO,KAAK,EAAE,GAAG,CAAC,qBAAqB,CAAC;;sCAKzC,CAAC;IACP,WAAW,EAAE,2BAA2B,CAAC;CAC5C,GAAG,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes multiple useObjectInstance instances, returning an object of them based on the keys of the instanceArgs.
|
|
3
|
+
*
|
|
4
|
+
* @param {{[key: string]: ObjectInstanceOptions}} instanceArgs - An object of objects to be passed to useObjectInstance.
|
|
5
|
+
* @returns {{[key: string]: ObjectInstance}} - An object of useObjectInstance instances.
|
|
6
|
+
*/
|
|
7
|
+
export function useObjectInstances(instanceArgs: {
|
|
8
|
+
[key: string]: ObjectInstanceOptions;
|
|
9
|
+
}): {
|
|
10
|
+
[key: string]: ObjectInstance;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Initializes an object instance to manage CRUD operations. This setup includes reactive state management
|
|
14
|
+
* and functions to perform create, retrieve, update, delete, and patch operations based on provided CRUD
|
|
15
|
+
* configurations and arguments.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```vue
|
|
19
|
+
* <script setup>
|
|
20
|
+
* import { useObjectInstance } from "@arrai-innovations/reactive-helpers";
|
|
21
|
+
* import { reactive, toRef } from "vue";
|
|
22
|
+
*
|
|
23
|
+
* const props = defineProps({
|
|
24
|
+
* app: {
|
|
25
|
+
* type: String,
|
|
26
|
+
* required: true,
|
|
27
|
+
* },
|
|
28
|
+
* model: {
|
|
29
|
+
* type: String,
|
|
30
|
+
* required: true,
|
|
31
|
+
* },
|
|
32
|
+
* pk: {
|
|
33
|
+
* type: String,
|
|
34
|
+
* default: '',
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const pkRef = toRef(props, 'pk');
|
|
39
|
+
* const objectInstanceProps = reactive({
|
|
40
|
+
* pk: pkRef,
|
|
41
|
+
* pkKey: 'id',
|
|
42
|
+
* crudArgs: {
|
|
43
|
+
* app: toRef(props, "app"),
|
|
44
|
+
* model: toRef(props, "model"),
|
|
45
|
+
* },
|
|
46
|
+
* retrieveArgs: {},
|
|
47
|
+
* });
|
|
48
|
+
* const objectInstance = useObjectInstance(objectInstanceProps);
|
|
49
|
+
* watch(pkRef, (newValue, oldValue) => {
|
|
50
|
+
* if (newValue !== oldValue && newValue) {
|
|
51
|
+
* objectInstance.retrieve();
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* </script>
|
|
55
|
+
* <template>
|
|
56
|
+
* <!-- Display the retrieved object reactively, as a valid pk is provided in props. -->
|
|
57
|
+
* <div>{{ objectInstance.state.object }}</div>
|
|
58
|
+
* </template>
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param {ObjectInstanceOptions} options - The options to be passed to useObjectInstance.
|
|
62
|
+
* @returns {ObjectInstance} - An object used to manage create, retrieve, update, delete, and patch operations.
|
|
63
|
+
*/
|
|
64
|
+
export function useObjectInstance({ props, functions }: ObjectInstanceOptions): ObjectInstance;
|
|
65
|
+
/**
|
|
66
|
+
* A composition function to manage create, retrieve, update, delete, and patch operations.
|
|
67
|
+
*
|
|
68
|
+
* @module use/objectInstance.js
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* The object being managed by the instance. Empty object is the default.
|
|
72
|
+
*
|
|
73
|
+
* @typedef {{pkKey: string, [key: string]: any}|{}} CrudObject
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Arguments to be passed to the object instance.
|
|
77
|
+
*
|
|
78
|
+
* @typedef {object} ObjectInstanceOptions
|
|
79
|
+
* @property {import('vue').UnwrapNestedRefs<ObjectInstanceRawProps>} props - The reactive configuration object.
|
|
80
|
+
* @property {import('../config/objectCrud.js').ObjectCrudFunctions} functions - An object of custom crud functions to use instead of the defaults.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Reactive arguments to be passed to the object instance.
|
|
84
|
+
*
|
|
85
|
+
* @typedef {object} ObjectInstanceRawProps
|
|
86
|
+
* @property {string} [pk] - The pk of the object, optional to support creating new objects.
|
|
87
|
+
* @property {string} pkKey - The pk key of the object.
|
|
88
|
+
* @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
89
|
+
* @property {import('../config/objectCrud.js').ObjectCrudArgs} crudArgs - The arguments to be passed to the crud functions.
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* The raw state of the object instance.
|
|
93
|
+
*
|
|
94
|
+
* @typedef {object} ObjectInstanceRawState
|
|
95
|
+
* @property {import('../config/objectCrud.js').ObjectCrudArgs} crud - The crud functions.
|
|
96
|
+
* @property {string} pk - The pk of the object.
|
|
97
|
+
* @property {string} pkKey - The pk key of the object.
|
|
98
|
+
* @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
99
|
+
* @property {CrudObject} object - The object.
|
|
100
|
+
* @property {Readonly<import('vue').Ref<boolean>>} loading - Whether the object is loading.
|
|
101
|
+
* @property {Readonly<import('vue').Ref<boolean>>} errored - Whether the object errored.
|
|
102
|
+
* @property {Readonly<import('vue').Ref<Error|null>>} error - The error.
|
|
103
|
+
* @property {Readonly<import('vue').Ref<boolean>>} deleted - Whether the object is deleted.
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
|
|
107
|
+
* Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
|
|
108
|
+
*
|
|
109
|
+
* @typedef {import('vue').UnwrapNestedRefs<ObjectInstanceRawState>} ObjectInstanceState
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* The functions available on the object instance.
|
|
113
|
+
*
|
|
114
|
+
* @typedef {object} ObjectInstanceFunctions
|
|
115
|
+
* @property {(args: { object: object }) => Promise<boolean>} create - Called to turn the current object into a new object on the server.
|
|
116
|
+
* @property {() => Promise<boolean>} retrieve - Called to retrieve the current object by pk from the server.
|
|
117
|
+
* @property {(args: { object: CrudObject }) => Promise<boolean>} update - Called to update the current object on the server.
|
|
118
|
+
* @property {() => Promise<boolean>} delete - Called to delete the current object on the server.
|
|
119
|
+
* @property {(args: { partialObject: CrudObject }) => Promise<boolean>} patch - Called to patch the current object on the server.
|
|
120
|
+
* @property {import('./loadingError.js').ClearErrorFn} clearError - Called to clear the error state.
|
|
121
|
+
* @property {() => void} clear - Called to clear the object state.
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* The properties of the object instance.
|
|
125
|
+
*
|
|
126
|
+
* @typedef {object} ObjectInstanceProperties
|
|
127
|
+
* @property {ObjectInstanceState} state - The state of the object instance.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* The instance of the object instance.
|
|
131
|
+
*
|
|
132
|
+
* @typedef {ObjectInstanceFunctions & ObjectInstanceProperties} ObjectInstance
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* Represents an error related to CRUD operations on an object instance. This error might be thrown
|
|
136
|
+
* when there are issues such as invalid input, network failures, or permissions issues during CRUD operations.
|
|
137
|
+
*/
|
|
138
|
+
export class ObjectError extends Error {
|
|
139
|
+
/**
|
|
140
|
+
* Creates an instance of ObjectError.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} message - The error message.
|
|
143
|
+
* @param {string} code - The error code.
|
|
144
|
+
*/
|
|
145
|
+
constructor(message: string, code: string);
|
|
146
|
+
code: string;
|
|
147
|
+
}
|
|
148
|
+
export const objectInstanceStateKeys: string[];
|
|
149
|
+
export const objectInstanceFunctions: string[];
|
|
150
|
+
/**
|
|
151
|
+
* The object being managed by the instance. Empty object is the default.
|
|
152
|
+
*/
|
|
153
|
+
export type CrudObject = {
|
|
154
|
+
pkKey: string;
|
|
155
|
+
[key: string]: any;
|
|
156
|
+
} | {};
|
|
157
|
+
/**
|
|
158
|
+
* Arguments to be passed to the object instance.
|
|
159
|
+
*/
|
|
160
|
+
export type ObjectInstanceOptions = {
|
|
161
|
+
/**
|
|
162
|
+
* - The reactive configuration object.
|
|
163
|
+
*/
|
|
164
|
+
props: import("vue").UnwrapNestedRefs<ObjectInstanceRawProps>;
|
|
165
|
+
/**
|
|
166
|
+
* - An object of custom crud functions to use instead of the defaults.
|
|
167
|
+
*/
|
|
168
|
+
functions: import("../config/objectCrud.js").ObjectCrudFunctions;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Reactive arguments to be passed to the object instance.
|
|
172
|
+
*/
|
|
173
|
+
export type ObjectInstanceRawProps = {
|
|
174
|
+
/**
|
|
175
|
+
* - The pk of the object, optional to support creating new objects.
|
|
176
|
+
*/
|
|
177
|
+
pk?: string;
|
|
178
|
+
/**
|
|
179
|
+
* - The pk key of the object.
|
|
180
|
+
*/
|
|
181
|
+
pkKey: string;
|
|
182
|
+
/**
|
|
183
|
+
* - The arguments to be passed to the retrieve function.
|
|
184
|
+
*/
|
|
185
|
+
retrieveArgs: object;
|
|
186
|
+
/**
|
|
187
|
+
* - The arguments to be passed to the crud functions.
|
|
188
|
+
*/
|
|
189
|
+
crudArgs: import("../config/objectCrud.js").ObjectCrudArgs;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* The raw state of the object instance.
|
|
193
|
+
*/
|
|
194
|
+
export type ObjectInstanceRawState = {
|
|
195
|
+
/**
|
|
196
|
+
* - The crud functions.
|
|
197
|
+
*/
|
|
198
|
+
crud: import("../config/objectCrud.js").ObjectCrudArgs;
|
|
199
|
+
/**
|
|
200
|
+
* - The pk of the object.
|
|
201
|
+
*/
|
|
202
|
+
pk: string;
|
|
203
|
+
/**
|
|
204
|
+
* - The pk key of the object.
|
|
205
|
+
*/
|
|
206
|
+
pkKey: string;
|
|
207
|
+
/**
|
|
208
|
+
* - The arguments to be passed to the retrieve function.
|
|
209
|
+
*/
|
|
210
|
+
retrieveArgs: object;
|
|
211
|
+
/**
|
|
212
|
+
* - The object.
|
|
213
|
+
*/
|
|
214
|
+
object: CrudObject;
|
|
215
|
+
/**
|
|
216
|
+
* - Whether the object is loading.
|
|
217
|
+
*/
|
|
218
|
+
loading: Readonly<import("vue").Ref<boolean>>;
|
|
219
|
+
/**
|
|
220
|
+
* - Whether the object errored.
|
|
221
|
+
*/
|
|
222
|
+
errored: Readonly<import("vue").Ref<boolean>>;
|
|
223
|
+
/**
|
|
224
|
+
* - The error.
|
|
225
|
+
*/
|
|
226
|
+
error: Readonly<import("vue").Ref<Error | null>>;
|
|
227
|
+
/**
|
|
228
|
+
* - Whether the object is deleted.
|
|
229
|
+
*/
|
|
230
|
+
deleted: Readonly<import("vue").Ref<boolean>>;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
|
|
234
|
+
* Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
|
|
235
|
+
*/
|
|
236
|
+
export type ObjectInstanceState = import("vue").UnwrapNestedRefs<ObjectInstanceRawState>;
|
|
237
|
+
/**
|
|
238
|
+
* The functions available on the object instance.
|
|
239
|
+
*/
|
|
240
|
+
export type ObjectInstanceFunctions = {
|
|
241
|
+
/**
|
|
242
|
+
* - Called to turn the current object into a new object on the server.
|
|
243
|
+
*/
|
|
244
|
+
create: (args: {
|
|
245
|
+
object: object;
|
|
246
|
+
}) => Promise<boolean>;
|
|
247
|
+
/**
|
|
248
|
+
* - Called to retrieve the current object by pk from the server.
|
|
249
|
+
*/
|
|
250
|
+
retrieve: () => Promise<boolean>;
|
|
251
|
+
/**
|
|
252
|
+
* - Called to update the current object on the server.
|
|
253
|
+
*/
|
|
254
|
+
update: (args: {
|
|
255
|
+
object: CrudObject;
|
|
256
|
+
}) => Promise<boolean>;
|
|
257
|
+
/**
|
|
258
|
+
* - Called to delete the current object on the server.
|
|
259
|
+
*/
|
|
260
|
+
delete: () => Promise<boolean>;
|
|
261
|
+
/**
|
|
262
|
+
* - Called to patch the current object on the server.
|
|
263
|
+
*/
|
|
264
|
+
patch: (args: {
|
|
265
|
+
partialObject: CrudObject;
|
|
266
|
+
}) => Promise<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* - Called to clear the error state.
|
|
269
|
+
*/
|
|
270
|
+
clearError: import("./loadingError.js").ClearErrorFn;
|
|
271
|
+
/**
|
|
272
|
+
* - Called to clear the object state.
|
|
273
|
+
*/
|
|
274
|
+
clear: () => void;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* The properties of the object instance.
|
|
278
|
+
*/
|
|
279
|
+
export type ObjectInstanceProperties = {
|
|
280
|
+
/**
|
|
281
|
+
* - The state of the object instance.
|
|
282
|
+
*/
|
|
283
|
+
state: ObjectInstanceState;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* The instance of the object instance.
|
|
287
|
+
*/
|
|
288
|
+
export type ObjectInstance = ObjectInstanceFunctions & ObjectInstanceProperties;
|
|
289
|
+
//# sourceMappingURL=objectInstance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectInstance.d.ts","sourceRoot":"","sources":["../../use/objectInstance.js"],"names":[],"mappings":"AAmHA;;;;;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,CAkM1B;AAjXD;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;GAQG;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;;;;yBAnGrG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,GAAC,EAAE;;;;;;;;WAOrC,OAAO,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;;;;eACtD,OAAO,yBAAyB,EAAE,mBAAmB;;;;;;;;;SAOrD,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;cACN,OAAO,yBAAyB,EAAE,cAAc;;;;;;;;;UAOhD,OAAO,yBAAyB,EAAE,cAAc;;;;QAChD,MAAM;;;;WACN,MAAM;;;;kBACN,MAAM;;;;YACN,UAAU;;;;aACV,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;aACpC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;WACpC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,KAAK,GAAC,IAAI,CAAC,CAAC;;;;aACvC,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;kCAOrC,OAAO,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;;;;;;;;YAOrD,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;cAC9C,MAAM,OAAO,CAAC,OAAO,CAAC;;;;YACtB,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;YAClD,MAAM,OAAO,CAAC,OAAO,CAAC;;;;WACtB,CAAC,IAAI,EAAE;QAAE,aAAa,EAAE,UAAU,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;;;;gBACzD,OAAO,mBAAmB,EAAE,YAAY;;;;WACxC,MAAM,IAAI;;;;;;;;;WAOV,mBAAmB;;;;;6BAMpB,uBAAuB,GAAG,wBAAwB"}
|