@arrai-innovations/reactive-helpers 18.0.2 → 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 +110 -77
- package/index.js +6 -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 +102 -40
- package/types/config/objectCrud.d.ts.map +1 -1
- package/types/index.d.ts +6 -1
- package/types/use/cancellableIntent.d.ts +2 -13
- package/types/use/cancellableIntent.d.ts.map +1 -1
- package/types/use/listInstance.d.ts +10 -10
- package/types/use/listInstance.d.ts.map +1 -1
- package/types/use/loadingError.d.ts +30 -6
- package/types/use/loadingError.d.ts.map +1 -1
- package/types/use/objectInstance.d.ts +83 -31
- package/types/use/objectInstance.d.ts.map +1 -1
- package/types/use/objectSubscription.d.ts +33 -29
- package/types/use/objectSubscription.d.ts.map +1 -1
- package/types/use/proxyLoadingError.d.ts +8 -23
- package/types/use/proxyLoadingError.d.ts.map +1 -1
- package/types/utils/cancellableFetch.d.ts +12 -0
- package/types/utils/cancellableFetch.d.ts.map +1 -0
- package/types/utils/cancellablePromise.d.ts +40 -0
- package/types/utils/cancellablePromise.d.ts.map +1 -0
- package/types/utils/deepUnref.d.ts +26 -0
- package/types/utils/deepUnref.d.ts.map +1 -0
- package/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/cancellableIntent.js +8 -13
- package/use/listInstance.js +67 -68
- package/use/listSearch.js +1 -1
- package/use/loadingError.js +30 -6
- package/use/objectInstance.js +228 -128
- package/use/objectSubscription.js +81 -82
- package/use/proxyLoadingError.js +14 -27
- package/use/search.js +1 -1
- package/utils/cancellableFetch.js +22 -0
- package/utils/cancellablePromise.js +70 -0
- package/utils/classes.js +5 -5
- package/utils/deepUnref.js +28 -0
- package/utils/refIfReactive.js +18 -0
- package/utils/unwrapNested.js +25 -0
|
@@ -70,14 +70,20 @@ export function useObjectInstance({ props, functions }: ObjectInstanceOptions):
|
|
|
70
70
|
/**
|
|
71
71
|
* The object being managed by the instance. Empty object is the default.
|
|
72
72
|
*
|
|
73
|
-
* @typedef {{pkKey: string, [key: string]: any}
|
|
73
|
+
* @typedef {{pkKey: string, [key: string]: any}} ExistingCrudObject
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {{[key: string]: any}} NewCrudObject
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {ExistingCrudObject|NewCrudObject} CrudObject
|
|
74
80
|
*/
|
|
75
81
|
/**
|
|
76
82
|
* Arguments to be passed to the object instance.
|
|
77
83
|
*
|
|
78
84
|
* @typedef {object} ObjectInstanceOptions
|
|
79
85
|
* @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.
|
|
86
|
+
* @property {import('../config/objectCrud.js').ObjectCrudFunctions} [functions] - An object of custom crud functions to use instead of the defaults.
|
|
81
87
|
*/
|
|
82
88
|
/**
|
|
83
89
|
* Reactive arguments to be passed to the object instance.
|
|
@@ -88,35 +94,45 @@ export function useObjectInstance({ props, functions }: ObjectInstanceOptions):
|
|
|
88
94
|
* @property {object} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
89
95
|
* @property {import('../config/objectCrud.js').ObjectCrudArgs} crudArgs - The arguments to be passed to the crud functions.
|
|
90
96
|
*/
|
|
97
|
+
/**
|
|
98
|
+
* @typedef {object} ObjectInstanceRawStateCrud
|
|
99
|
+
* @property {import('vue').Reactive<import('../config/objectCrud.js').ObjectCrudArgsArgs|{}>} args - The arguments to be passed to the crud functions.
|
|
100
|
+
* @property {import('../config/objectCrud.js').CrudCreateFn} create - The create function.
|
|
101
|
+
* @property {import('../config/objectCrud.js').CrudRetrieveFn} retrieve - The retrieve function.
|
|
102
|
+
* @property {import('../config/objectCrud.js').CrudUpdateFn} update - The update function.
|
|
103
|
+
* @property {import('../config/objectCrud.js').CrudPatchFn} patch - The patch function.
|
|
104
|
+
* @property {import('../config/objectCrud.js').CrudDeleteFn} delete - The delete function.
|
|
105
|
+
* @property {import('../config/objectCrud.js').CrudObjectSubscribeFn} subscribe - The subscribe function.
|
|
106
|
+
*/
|
|
91
107
|
/**
|
|
92
108
|
* The raw state of the object instance.
|
|
93
109
|
*
|
|
94
110
|
* @typedef {object} ObjectInstanceRawState
|
|
95
|
-
* @property {import('
|
|
96
|
-
* @property {string} pk - The pk of the object.
|
|
97
|
-
* @property {string} pkKey - The pk key of the object.
|
|
98
|
-
* @property {
|
|
99
|
-
* @property {CrudObject} object - The object.
|
|
111
|
+
* @property {import('vue').Reactive<ObjectInstanceRawStateCrud>} crud - The crud functions.
|
|
112
|
+
* @property {import('vue').Ref<string|undefined>} pk - The pk of the object.
|
|
113
|
+
* @property {import('vue').Ref<string|undefined>} pkKey - The pk key of the object.
|
|
114
|
+
* @property {import('vue').Ref<{[key:string]: any}>} retrieveArgs - The arguments to be passed to the retrieve function.
|
|
115
|
+
* @property {import('vue').Reactive<CrudObject>} object - The object.
|
|
100
116
|
* @property {Readonly<import('vue').Ref<boolean>>} loading - Whether the object is loading.
|
|
101
117
|
* @property {Readonly<import('vue').Ref<boolean>>} errored - Whether the object errored.
|
|
102
118
|
* @property {Readonly<import('vue').Ref<Error|null>>} error - The error.
|
|
103
|
-
* @property {
|
|
119
|
+
* @property {boolean} deleted - Whether the object is deleted.
|
|
104
120
|
*/
|
|
105
121
|
/**
|
|
106
122
|
* Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
|
|
107
123
|
* Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
|
|
108
124
|
*
|
|
109
|
-
* @typedef {import('vue').
|
|
125
|
+
* @typedef {import('vue').Reactive<ObjectInstanceRawState>} ObjectInstanceState
|
|
110
126
|
*/
|
|
111
127
|
/**
|
|
112
128
|
* The functions available on the object instance.
|
|
113
129
|
*
|
|
114
130
|
* @typedef {object} ObjectInstanceFunctions
|
|
115
|
-
* @property {(args: { object: object }) =>
|
|
116
|
-
* @property {() =>
|
|
117
|
-
* @property {(args: { object:
|
|
118
|
-
* @property {() =>
|
|
119
|
-
* @property {(args: { partialObject:
|
|
131
|
+
* @property {(args: { object: object }) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} create - Called to turn the current object into a new object on the server.
|
|
132
|
+
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} retrieve - Called to retrieve the current object by pk from the server.
|
|
133
|
+
* @property {(args: { object: ExistingCrudObject }) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} update - Called to update the current object on the server.
|
|
134
|
+
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} delete - Called to delete the current object on the server.
|
|
135
|
+
* @property {(args: { partialObject: ExistingCrudObject }) => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean>} patch - Called to patch the current object on the server.
|
|
120
136
|
* @property {import('./loadingError.js').ClearErrorFn} clearError - Called to clear the error state.
|
|
121
137
|
* @property {() => void} clear - Called to clear the object state.
|
|
122
138
|
*/
|
|
@@ -150,10 +166,14 @@ export const objectInstanceFunctions: string[];
|
|
|
150
166
|
/**
|
|
151
167
|
* The object being managed by the instance. Empty object is the default.
|
|
152
168
|
*/
|
|
153
|
-
export type
|
|
169
|
+
export type ExistingCrudObject = {
|
|
154
170
|
pkKey: string;
|
|
155
171
|
[key: string]: any;
|
|
156
|
-
}
|
|
172
|
+
};
|
|
173
|
+
export type NewCrudObject = {
|
|
174
|
+
[key: string]: any;
|
|
175
|
+
};
|
|
176
|
+
export type CrudObject = ExistingCrudObject | NewCrudObject;
|
|
157
177
|
/**
|
|
158
178
|
* Arguments to be passed to the object instance.
|
|
159
179
|
*/
|
|
@@ -165,7 +185,7 @@ export type ObjectInstanceOptions = {
|
|
|
165
185
|
/**
|
|
166
186
|
* - An object of custom crud functions to use instead of the defaults.
|
|
167
187
|
*/
|
|
168
|
-
functions
|
|
188
|
+
functions?: import("../config/objectCrud.js").ObjectCrudFunctions;
|
|
169
189
|
};
|
|
170
190
|
/**
|
|
171
191
|
* Reactive arguments to be passed to the object instance.
|
|
@@ -188,6 +208,36 @@ export type ObjectInstanceRawProps = {
|
|
|
188
208
|
*/
|
|
189
209
|
crudArgs: import("../config/objectCrud.js").ObjectCrudArgs;
|
|
190
210
|
};
|
|
211
|
+
export type ObjectInstanceRawStateCrud = {
|
|
212
|
+
/**
|
|
213
|
+
* - The arguments to be passed to the crud functions.
|
|
214
|
+
*/
|
|
215
|
+
args: import("vue").Reactive<import("../config/objectCrud.js").ObjectCrudArgsArgs | {}>;
|
|
216
|
+
/**
|
|
217
|
+
* - The create function.
|
|
218
|
+
*/
|
|
219
|
+
create: import("../config/objectCrud.js").CrudCreateFn;
|
|
220
|
+
/**
|
|
221
|
+
* - The retrieve function.
|
|
222
|
+
*/
|
|
223
|
+
retrieve: import("../config/objectCrud.js").CrudRetrieveFn;
|
|
224
|
+
/**
|
|
225
|
+
* - The update function.
|
|
226
|
+
*/
|
|
227
|
+
update: import("../config/objectCrud.js").CrudUpdateFn;
|
|
228
|
+
/**
|
|
229
|
+
* - The patch function.
|
|
230
|
+
*/
|
|
231
|
+
patch: import("../config/objectCrud.js").CrudPatchFn;
|
|
232
|
+
/**
|
|
233
|
+
* - The delete function.
|
|
234
|
+
*/
|
|
235
|
+
delete: import("../config/objectCrud.js").CrudDeleteFn;
|
|
236
|
+
/**
|
|
237
|
+
* - The subscribe function.
|
|
238
|
+
*/
|
|
239
|
+
subscribe: import("../config/objectCrud.js").CrudObjectSubscribeFn;
|
|
240
|
+
};
|
|
191
241
|
/**
|
|
192
242
|
* The raw state of the object instance.
|
|
193
243
|
*/
|
|
@@ -195,23 +245,25 @@ export type ObjectInstanceRawState = {
|
|
|
195
245
|
/**
|
|
196
246
|
* - The crud functions.
|
|
197
247
|
*/
|
|
198
|
-
crud: import("
|
|
248
|
+
crud: import("vue").Reactive<ObjectInstanceRawStateCrud>;
|
|
199
249
|
/**
|
|
200
250
|
* - The pk of the object.
|
|
201
251
|
*/
|
|
202
|
-
pk: string
|
|
252
|
+
pk: import("vue").Ref<string | undefined>;
|
|
203
253
|
/**
|
|
204
254
|
* - The pk key of the object.
|
|
205
255
|
*/
|
|
206
|
-
pkKey: string
|
|
256
|
+
pkKey: import("vue").Ref<string | undefined>;
|
|
207
257
|
/**
|
|
208
258
|
* - The arguments to be passed to the retrieve function.
|
|
209
259
|
*/
|
|
210
|
-
retrieveArgs:
|
|
260
|
+
retrieveArgs: import("vue").Ref<{
|
|
261
|
+
[key: string]: any;
|
|
262
|
+
}>;
|
|
211
263
|
/**
|
|
212
264
|
* - The object.
|
|
213
265
|
*/
|
|
214
|
-
object: CrudObject
|
|
266
|
+
object: import("vue").Reactive<CrudObject>;
|
|
215
267
|
/**
|
|
216
268
|
* - Whether the object is loading.
|
|
217
269
|
*/
|
|
@@ -227,13 +279,13 @@ export type ObjectInstanceRawState = {
|
|
|
227
279
|
/**
|
|
228
280
|
* - Whether the object is deleted.
|
|
229
281
|
*/
|
|
230
|
-
deleted:
|
|
282
|
+
deleted: boolean;
|
|
231
283
|
};
|
|
232
284
|
/**
|
|
233
285
|
* Manages a reactive state of an object including its CRUD status, loading states, and any operational errors.
|
|
234
286
|
* Reactivity ensures that any changes in state immediately reflect in the UI components that depend on this state.
|
|
235
287
|
*/
|
|
236
|
-
export type ObjectInstanceState = import("vue").
|
|
288
|
+
export type ObjectInstanceState = import("vue").Reactive<ObjectInstanceRawState>;
|
|
237
289
|
/**
|
|
238
290
|
* The functions available on the object instance.
|
|
239
291
|
*/
|
|
@@ -243,27 +295,27 @@ export type ObjectInstanceFunctions = {
|
|
|
243
295
|
*/
|
|
244
296
|
create: (args: {
|
|
245
297
|
object: object;
|
|
246
|
-
}) =>
|
|
298
|
+
}) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
247
299
|
/**
|
|
248
300
|
* - Called to retrieve the current object by pk from the server.
|
|
249
301
|
*/
|
|
250
|
-
retrieve: () =>
|
|
302
|
+
retrieve: () => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
251
303
|
/**
|
|
252
304
|
* - Called to update the current object on the server.
|
|
253
305
|
*/
|
|
254
306
|
update: (args: {
|
|
255
|
-
object:
|
|
256
|
-
}) =>
|
|
307
|
+
object: ExistingCrudObject;
|
|
308
|
+
}) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
257
309
|
/**
|
|
258
310
|
* - Called to delete the current object on the server.
|
|
259
311
|
*/
|
|
260
|
-
delete: () =>
|
|
312
|
+
delete: () => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
261
313
|
/**
|
|
262
314
|
* - Called to patch the current object on the server.
|
|
263
315
|
*/
|
|
264
316
|
patch: (args: {
|
|
265
|
-
partialObject:
|
|
266
|
-
}) =>
|
|
317
|
+
partialObject: ExistingCrudObject;
|
|
318
|
+
}) => import("../utils/cancellablePromise.js").MaybeCancellablePromise<boolean>;
|
|
267
319
|
/**
|
|
268
320
|
* - Called to clear the error state.
|
|
269
321
|
*/
|
|
@@ -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,C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+2,17 @@
|
|
|
2
2
|
* The raw state of the object subscription.
|
|
3
3
|
*
|
|
4
4
|
* @typedef {object} ObjectSubscriptionRawState
|
|
5
|
-
* @property {
|
|
6
|
-
* @property {
|
|
7
|
-
* @property {
|
|
8
|
-
* @property {boolean} intendToRetrieve - Whether the object intends to retrieve.
|
|
9
|
-
* @property {boolean} intendToSubscribe - Whether the object intends to subscribe.
|
|
10
|
-
* @property {boolean} subscribed - Whether the object is subscribed.
|
|
5
|
+
* @property {import('./loadingError.js').LoadingReadonlyRef} subscriptionLoading - Whether the subscription is loading.
|
|
6
|
+
* @property {import('./loadingError.js').ErroredReadonlyRef} subscriptionErrored - Whether the subscription has errored.
|
|
7
|
+
* @property {import('./loadingError.js').ErrorReadonlyRef} subscriptionError - The error that occurred.
|
|
8
|
+
* @property {import('vue').Ref<boolean>} intendToRetrieve - Whether the object intends to retrieve.
|
|
9
|
+
* @property {import('vue').Ref<boolean>} intendToSubscribe - Whether the object intends to subscribe.
|
|
10
|
+
* @property {import('vue').Ref<boolean|undefined>} subscribed - Whether the object is subscribed.
|
|
11
11
|
*/
|
|
12
12
|
/**
|
|
13
13
|
* The state of the object subscription, including both subscription and object instance states.
|
|
14
14
|
*
|
|
15
|
-
* @typedef {import('vue').
|
|
15
|
+
* @typedef {import('vue').Reactive<
|
|
16
16
|
* ObjectSubscriptionRawState &
|
|
17
17
|
* import('./objectInstance.js').ObjectInstanceRawState
|
|
18
18
|
* >} ObjectSubscriptionState
|
|
@@ -21,12 +21,15 @@
|
|
|
21
21
|
* Functions available for object subscription management.
|
|
22
22
|
*
|
|
23
23
|
* @typedef {object} ObjectSubscriptionFunctions
|
|
24
|
-
* @property {(
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* @property {(
|
|
25
|
+
* (options?: { retrieve?: boolean }) => boolean
|
|
26
|
+
* )} subscribe - Subscribes to updates from an object, managing subscription state and handling errors internally.
|
|
27
|
+
* Ensures that only one active subscription can exist at a time to prevent duplicate calls. Returns a promise that
|
|
28
|
+
* resolves to true if the subscription was successful, and false if it failed.
|
|
27
29
|
* @property {() => boolean} unsubscribe - Unsubscribes from the object, resetting related state flags. Returns
|
|
28
30
|
* true if the object was unsubscribed, and false if it was not subscribed.
|
|
29
|
-
* @property {(data: import('./objectInstance.js').
|
|
31
|
+
* @property {(data: import('./objectInstance.js').ExistingCrudObject) => void} updateFromSubscription - Update the
|
|
32
|
+
* object from a subscription.
|
|
30
33
|
* @property {() => void} deleteFromSubscription - Delete the object from a subscription.
|
|
31
34
|
* @property {() => void} clearError - Clears any errors related to the subscription, and resets the loading state.
|
|
32
35
|
*/
|
|
@@ -49,8 +52,8 @@
|
|
|
49
52
|
* Raw props for the object subscription.
|
|
50
53
|
*
|
|
51
54
|
* @typedef {object} ObjectSubscriptionRawProps
|
|
52
|
-
* @property {boolean}
|
|
53
|
-
* @property {boolean}
|
|
55
|
+
* @property {boolean|undefined} intendToRetrieve - Whether the object intends to retrieve.
|
|
56
|
+
* @property {boolean|undefined} intendToSubscribe - Whether the object intends to subscribe.
|
|
54
57
|
*/
|
|
55
58
|
/**
|
|
56
59
|
* Options for initializing an object subscription, including reactive props and non-reactive functions.
|
|
@@ -144,53 +147,54 @@ export type ObjectSubscriptionRawState = {
|
|
|
144
147
|
/**
|
|
145
148
|
* - Whether the subscription is loading.
|
|
146
149
|
*/
|
|
147
|
-
subscriptionLoading:
|
|
150
|
+
subscriptionLoading: import("./loadingError.js").LoadingReadonlyRef;
|
|
148
151
|
/**
|
|
149
152
|
* - Whether the subscription has errored.
|
|
150
153
|
*/
|
|
151
|
-
subscriptionErrored:
|
|
154
|
+
subscriptionErrored: import("./loadingError.js").ErroredReadonlyRef;
|
|
152
155
|
/**
|
|
153
156
|
* - The error that occurred.
|
|
154
157
|
*/
|
|
155
|
-
subscriptionError:
|
|
158
|
+
subscriptionError: import("./loadingError.js").ErrorReadonlyRef;
|
|
156
159
|
/**
|
|
157
160
|
* - Whether the object intends to retrieve.
|
|
158
161
|
*/
|
|
159
|
-
intendToRetrieve: boolean
|
|
162
|
+
intendToRetrieve: import("vue").Ref<boolean>;
|
|
160
163
|
/**
|
|
161
164
|
* - Whether the object intends to subscribe.
|
|
162
165
|
*/
|
|
163
|
-
intendToSubscribe: boolean
|
|
166
|
+
intendToSubscribe: import("vue").Ref<boolean>;
|
|
164
167
|
/**
|
|
165
168
|
* - Whether the object is subscribed.
|
|
166
169
|
*/
|
|
167
|
-
subscribed: boolean
|
|
170
|
+
subscribed: import("vue").Ref<boolean | undefined>;
|
|
168
171
|
};
|
|
169
172
|
/**
|
|
170
173
|
* The state of the object subscription, including both subscription and object instance states.
|
|
171
174
|
*/
|
|
172
|
-
export type ObjectSubscriptionState = import("vue").
|
|
175
|
+
export type ObjectSubscriptionState = import("vue").Reactive<ObjectSubscriptionRawState & import("./objectInstance.js").ObjectInstanceRawState>;
|
|
173
176
|
/**
|
|
174
177
|
* Functions available for object subscription management.
|
|
175
178
|
*/
|
|
176
179
|
export type ObjectSubscriptionFunctions = {
|
|
177
180
|
/**
|
|
178
|
-
* - Subscribes to updates from an object, managing subscription state and
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
+
* - Subscribes to updates from an object, managing subscription state and handling errors internally.
|
|
182
|
+
* Ensures that only one active subscription can exist at a time to prevent duplicate calls. Returns a promise that
|
|
183
|
+
* resolves to true if the subscription was successful, and false if it failed.
|
|
181
184
|
*/
|
|
182
|
-
subscribe: (
|
|
185
|
+
subscribe: ((options?: {
|
|
183
186
|
retrieve?: boolean;
|
|
184
|
-
}) => boolean;
|
|
187
|
+
}) => boolean);
|
|
185
188
|
/**
|
|
186
189
|
* - Unsubscribes from the object, resetting related state flags. Returns
|
|
187
190
|
* true if the object was unsubscribed, and false if it was not subscribed.
|
|
188
191
|
*/
|
|
189
192
|
unsubscribe: () => boolean;
|
|
190
193
|
/**
|
|
191
|
-
* - Update the
|
|
194
|
+
* - Update the
|
|
195
|
+
* object from a subscription.
|
|
192
196
|
*/
|
|
193
|
-
updateFromSubscription: (data: import("./objectInstance.js").
|
|
197
|
+
updateFromSubscription: (data: import("./objectInstance.js").ExistingCrudObject) => void;
|
|
194
198
|
/**
|
|
195
199
|
* - Delete the object from a subscription.
|
|
196
200
|
*/
|
|
@@ -236,11 +240,11 @@ export type ObjectSubscriptionRawProps = {
|
|
|
236
240
|
/**
|
|
237
241
|
* - Whether the object intends to retrieve.
|
|
238
242
|
*/
|
|
239
|
-
intendToRetrieve
|
|
243
|
+
intendToRetrieve: boolean | undefined;
|
|
240
244
|
/**
|
|
241
245
|
* - Whether the object intends to subscribe.
|
|
242
246
|
*/
|
|
243
|
-
intendToSubscribe
|
|
247
|
+
intendToSubscribe: boolean | undefined;
|
|
244
248
|
};
|
|
245
249
|
/**
|
|
246
250
|
* Options for initializing an object subscription, including reactive props and non-reactive functions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectSubscription.d.ts","sourceRoot":"","sources":["../../use/objectSubscription.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"objectSubscription.d.ts","sourceRoot":"","sources":["../../use/objectSubscription.js"],"names":[],"mappings":"AAgDA;;;;;;;;;;GAUG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;GASG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,yDAHW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAA;CAAC,GACxC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAA;CAAC,CAS/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,4EAHW,yBAAyB,GACvB,kBAAkB,CA0M9B;AApXD;;;;GAIG;AAEH;;GAEG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;AAED,mDAOE;AAEF,mD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vue').UnwrapNestedRefs<
|
|
11
|
-
* import('vue').Ref<
|
|
12
|
-
*
|
|
13
|
-
* )}
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* The instance of useProxyLoadingError.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {import('./loadingError.js').LoadingErrorStatus} ProxyLoadingError
|
|
5
|
+
* import('vue').UnwrapNestedRefs<import('./loadingError.js').LoadingErrorStatus> |
|
|
6
|
+
* import('vue').Ref<import('./loadingError.js').LoadingErrorStatus> |
|
|
7
|
+
* import('./loadingError.js').LoadingErrorStatus
|
|
8
|
+
* )} WatchableLoadingError
|
|
19
9
|
*/
|
|
20
10
|
/**
|
|
21
11
|
* A composable function for managing aggregated loading and error states across multiple sources.
|
|
22
12
|
*
|
|
23
|
-
* @param {
|
|
24
|
-
* @returns {
|
|
13
|
+
* @param {WatchableLoadingError[]} loadingErrors - A collection of loading error statuses to monitor and aggregate.
|
|
14
|
+
* @returns {import('./loadingError.js').LoadingErrorStatus} An object containing aggregated reactive fields and actions for loading and error states.
|
|
25
15
|
*/
|
|
26
|
-
export function useProxyLoadingError(loadingErrors:
|
|
27
|
-
export type WatchableLoadingErrorsRaw = (import("./loadingError.js").LoadingErrorStatus[]);
|
|
16
|
+
export function useProxyLoadingError(loadingErrors: WatchableLoadingError[]): import("./loadingError.js").LoadingErrorStatus;
|
|
28
17
|
/**
|
|
29
18
|
* A watchable collection of loading errors.
|
|
30
19
|
*/
|
|
31
|
-
export type
|
|
32
|
-
/**
|
|
33
|
-
* The instance of useProxyLoadingError.
|
|
34
|
-
*/
|
|
35
|
-
export type ProxyLoadingError = import("./loadingError.js").LoadingErrorStatus;
|
|
20
|
+
export type WatchableLoadingError = (import("vue").UnwrapNestedRefs<import("./loadingError.js").LoadingErrorStatus> | import("vue").Ref<import("./loadingError.js").LoadingErrorStatus> | import("./loadingError.js").LoadingErrorStatus);
|
|
36
21
|
//# sourceMappingURL=proxyLoadingError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyLoadingError.d.ts","sourceRoot":"","sources":["../../use/proxyLoadingError.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxyLoadingError.d.ts","sourceRoot":"","sources":["../../use/proxyLoadingError.js"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,oDAHW,qBAAqB,EAAE,GACrB,OAAO,mBAAmB,EAAE,kBAAkB,CA2B1D;;;;oCAtCY,CACZ,OAAa,KAAK,EAAE,gBAAgB,CAAC,OAAO,mBAAmB,EAAE,kBAAkB,CAAC,GACpF,OAAa,KAAK,EAAE,GAAG,CAAC,OAAO,mBAAmB,EAAE,kBAAkB,CAAC,GACvE,OAAa,mBAAmB,EAAE,kBAAkB,CACjD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper around fetch that adds cancellation via AbortController and returns a CancellablePromise.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {RequestInfo} input - The URL or Request object to fetch.
|
|
6
|
+
* @param {RequestInit} init - The options for the fetch request.
|
|
7
|
+
* @param {(response: Response) => Promise<T>} transform - A function to transform the response.
|
|
8
|
+
* @returns {CancellablePromise<T>} A cancellable promise that resolves to the transformed response.
|
|
9
|
+
*/
|
|
10
|
+
export function cancellableFetch<T>(input: RequestInfo, init: RequestInit, transform: (response: Response) => Promise<T>): CancellablePromise<T>;
|
|
11
|
+
import { CancellablePromise } from "./cancellablePromise.js";
|
|
12
|
+
//# sourceMappingURL=cancellableFetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellableFetch.d.ts","sourceRoot":"","sources":["../../utils/cancellableFetch.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,iCANa,CAAC,SACH,WAAW,QACX,WAAW,aACX,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAChC,kBAAkB,CAAC,CAAC,CAAC,CAYjC;mCArBkC,yBAAyB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a promise and optionally adds a cancel method if provided.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {Promise<T>} inner - The inner promise to wrap.
|
|
6
|
+
* @param {(() => Promise<void> | void)=} cancel - Optional cancel function.
|
|
7
|
+
* @returns {MaybeCancellablePromise<T>} The wrapped promise with an optional cancel method.
|
|
8
|
+
*/
|
|
9
|
+
export function wrapMaybeCancellable<T>(inner: Promise<T>, cancel?: (() => Promise<void> | void) | undefined): MaybeCancellablePromise<T>;
|
|
10
|
+
export function CancellablePromise<T>(promise: Promise<T>, cancel: () => (Promise<void> | void)): CancellablePromise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* A Promise that can be cancelled.
|
|
13
|
+
*/
|
|
14
|
+
export type CancellablePromise<T> = Promise<T> & {
|
|
15
|
+
cancel: (reason?: any) => Promise<void> | void;
|
|
16
|
+
};
|
|
17
|
+
export namespace CancellablePromise {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a rejected 'cancellable' promise.
|
|
20
|
+
*
|
|
21
|
+
* @param {any} reason - The reason for the rejection.
|
|
22
|
+
* @returns {MaybeCancellablePromise<never>} A rejected 'cancellable' promise.
|
|
23
|
+
*/
|
|
24
|
+
function reject(reason: any): MaybeCancellablePromise<never>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a resolved 'cancellable' promise.
|
|
27
|
+
*
|
|
28
|
+
* @template T
|
|
29
|
+
* @param {T} value - The value to resolve the promise with.
|
|
30
|
+
* @returns {MaybeCancellablePromise<T>} A resolved 'cancellable' promise.
|
|
31
|
+
*/
|
|
32
|
+
function resolve<T_1>(value: T_1): MaybeCancellablePromise<T_1>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A possibly cancellable promise.
|
|
36
|
+
*/
|
|
37
|
+
export type MaybeCancellablePromise<T> = Promise<T> & {
|
|
38
|
+
cancel?: (reason?: any) => Promise<void> | void;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=cancellablePromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancellablePromise.d.ts","sourceRoot":"","sources":["../../utils/cancellablePromise.js"],"names":[],"mappings":"AAiDA;;;;;;;GAOG;AACH,qCALa,CAAC,SACH,OAAO,CAAC,CAAC,CAAC,WACV,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAC,GAC3B,uBAAuB,CAAC,CAAC,CAAC,CActC;AA/CM,mCALM,CAAC,WACH,OAAO,CAAC,CAAC,CAAC,UACV,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,CAAC,GACxB,kBAAkB,CAAC,CAAC,CAAC,CAMjC;;;;+BAvBY,CAAC,IACD,OAAO,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CAAE;;IAwB5E;;;;;OAKG;IACH,wBAHW,GAAG,GACD,uBAAuB,CAAC,KAAK,CAAC,CAI1C;IAED;;;;;;OAMG;IACH,6BAHW,GAAC,GACC,uBAAuB,CAAC,GAAC,CAAC,CAItC;;;;;oCArCY,CAAC,IACD,OAAO,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CAAE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively unwraps refs from a nested object, array, or primitive.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @typedef {T extends import('vue').Ref<infer U>
|
|
6
|
+
* ? DeepUnwrap<U>
|
|
7
|
+
* : T extends Array<infer V>
|
|
8
|
+
* ? Array<DeepUnwrap<V>>
|
|
9
|
+
* : T extends object
|
|
10
|
+
* ? { [K in keyof T]: DeepUnwrap<T[K]> }
|
|
11
|
+
* : T
|
|
12
|
+
* } DeepUnwrap
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Safe, recursively-typed deep unref.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {T} val - The value to deeply unwrap.
|
|
19
|
+
* @returns {DeepUnwrap<T>} - The deeply unwrapped value.
|
|
20
|
+
*/
|
|
21
|
+
export const deepUnref: any;
|
|
22
|
+
/**
|
|
23
|
+
* Recursively unwraps refs from a nested object, array, or primitive.
|
|
24
|
+
*/
|
|
25
|
+
export type DeepUnwrap<T_1> = T_1 extends import("vue").Ref<infer U> ? DeepUnwrap<U> : T_1 extends Array<infer V> ? Array<DeepUnwrap<V>> : T_1 extends object ? { [K in keyof T_1]: DeepUnwrap<T_1[K]>; } : T_1;
|
|
26
|
+
//# sourceMappingURL=deepUnref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepUnref.d.ts","sourceRoot":"","sources":["../../utils/deepUnref.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAIH;;;;;;GAMG;AACH,4BAAoC;;;;8BAnBvB,GAAC,SAAS,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAC1C,UAAU,CAAC,CAAC,CAAC,GACb,GAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GACpB,GAAC,SAAS,MAAM,GACd,GAAG,CAAC,IAAI,MAAM,GAAC,GAAG,UAAU,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAE,GACpC,GAAC"}
|
|
@@ -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/cancellableIntent.js
CHANGED
|
@@ -2,19 +2,13 @@ import identity from "lodash-es/identity.js";
|
|
|
2
2
|
import isEmpty from "lodash-es/isEmpty.js";
|
|
3
3
|
import isEqual from "lodash-es/isEqual.js";
|
|
4
4
|
import { computed, effectScope, nextTick, onScopeDispose, reactive, readonly, watch } from "vue";
|
|
5
|
-
import { deepUnref } from "
|
|
5
|
+
import { deepUnref } from "../utils/deepUnref.js";
|
|
6
6
|
import { tryOnActivated, tryOnDeactivated } from "../utils/keepAliveTry.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @module use/cancellableIntent.js - A composable function for handling cancellable intents.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* A Promise that can be cancelled.
|
|
14
|
-
*
|
|
15
|
-
* @typedef {Promise<any> & { cancel: () => Promise<void>|void }} CancellablePromise
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* @typedef {import("vue").UnwrapNestedRefs<object>} CancellableIntentState - The state of the cancellable intent.
|
|
20
14
|
* @property {number} activeCount - The number of active intents.
|
|
@@ -28,7 +22,7 @@ import { tryOnActivated, tryOnDeactivated } from "../utils/keepAliveTry.js";
|
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
24
|
* @typedef {object} CancellableIntentOptions - The options for the cancellable intent.
|
|
31
|
-
* @property {() =>
|
|
25
|
+
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<void>} awaitableWithCancel - The function that returns a promise that can be cancelled.
|
|
32
26
|
* @property {import("vue").UnwrapNestedRefs<object>} [watchArguments={}] - The reactive object to watch for changes.
|
|
33
27
|
* @property {import("vue").UnwrapNestedRefs<object>} [guardArguments={}] - The reactive object to watch for truthiness before running the intent.
|
|
34
28
|
* @property {boolean} [clearActiveOnResolved=true] - Whether to clear the active state when the promise resolves.
|
|
@@ -112,9 +106,9 @@ export function useCancellableIntent({
|
|
|
112
106
|
es.stop();
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
async function cancel() {
|
|
109
|
+
async function cancel(reason) {
|
|
116
110
|
if (cancelFunction) {
|
|
117
|
-
return cancelFunction()
|
|
111
|
+
return cancelFunction(reason)
|
|
118
112
|
.catch(console.error)
|
|
119
113
|
.finally(() => {
|
|
120
114
|
if (!state.clearActiveOnResolved) {
|
|
@@ -145,7 +139,7 @@ export function useCancellableIntent({
|
|
|
145
139
|
// we don't want to await this, because we want to be able to cancel it
|
|
146
140
|
awaitablePromise
|
|
147
141
|
.catch(async (err) => {
|
|
148
|
-
await cancel();
|
|
142
|
+
await cancel("Error in awaitableWithCancel");
|
|
149
143
|
console.error(err);
|
|
150
144
|
state.errored = true;
|
|
151
145
|
state.error = err;
|
|
@@ -174,7 +168,7 @@ export function useCancellableIntent({
|
|
|
174
168
|
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
175
169
|
return;
|
|
176
170
|
}
|
|
177
|
-
await cancel(); // this can take time so guards and watches can change!
|
|
171
|
+
await cancel("Intent watch cancelled"); // this can take time so guards and watches can change!
|
|
178
172
|
newWatchValues = deepUnref(Object.values(watchArguments));
|
|
179
173
|
if (isEqual(newWatchValues, previousWatchValues)) {
|
|
180
174
|
return;
|
|
@@ -212,7 +206,8 @@ export function useCancellableIntent({
|
|
|
212
206
|
|
|
213
207
|
const cleanup = () => {
|
|
214
208
|
// cancel the intent when the component is deactivated
|
|
215
|
-
|
|
209
|
+
// noinspection JSIgnoredPromiseFromCall
|
|
210
|
+
cancel("Component deactivated");
|
|
216
211
|
if (state.clearActiveOnResolved) {
|
|
217
212
|
// otherwise it clears when resolved
|
|
218
213
|
cancelFunction = null;
|