@data-client/vue 0.2.0 → 0.3.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 +1 -24
- package/dist/index.js +185 -35
- package/dist/index.umd.min.js +1 -1
- package/lib/consumers/index.d.ts +2 -0
- package/lib/consumers/index.d.ts.map +1 -1
- package/lib/consumers/index.js +3 -1
- package/lib/consumers/useCache.d.ts +12 -0
- package/lib/consumers/useCache.d.ts.map +1 -0
- package/lib/consumers/useCache.js +63 -0
- package/lib/consumers/useDLE.d.ts +18 -0
- package/lib/consumers/useDLE.d.ts.map +1 -0
- package/lib/consumers/useDLE.js +88 -0
- package/lib/consumers/useFetch.d.ts +3 -2
- package/lib/consumers/useFetch.d.ts.map +1 -1
- package/lib/consumers/useFetch.js +10 -8
- package/lib/consumers/useLive.d.ts +3 -2
- package/lib/consumers/useLive.d.ts.map +1 -1
- package/lib/consumers/useLive.js +1 -1
- package/lib/consumers/useQuery.d.ts +3 -2
- package/lib/consumers/useQuery.d.ts.map +1 -1
- package/lib/consumers/useQuery.js +7 -3
- package/lib/consumers/useSubscription.d.ts +2 -1
- package/lib/consumers/useSubscription.d.ts.map +1 -1
- package/lib/consumers/useSubscription.js +1 -2
- package/lib/consumers/useSuspense.d.ts +3 -2
- package/lib/consumers/useSuspense.d.ts.map +1 -1
- package/lib/consumers/useSuspense.js +15 -20
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/providers/DataClientPlugin.d.ts +6 -0
- package/lib/providers/DataClientPlugin.d.ts.map +1 -1
- package/lib/providers/DataClientPlugin.js +15 -11
- package/lib/providers/index.d.ts +1 -1
- package/lib/providers/index.d.ts.map +1 -1
- package/lib/providers/index.js +1 -1
- package/lib/test/index.d.ts +3 -4
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +3 -5
- package/lib/test/mountDataClient.d.ts +29 -0
- package/lib/test/mountDataClient.d.ts.map +1 -0
- package/lib/test/mountDataClient.js +114 -0
- package/lib/test/renderDataCompose.d.ts +19 -0
- package/lib/test/renderDataCompose.d.ts.map +1 -0
- package/lib/test/renderDataCompose.js +135 -0
- package/lib/types.d.ts +10 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/package.json +6 -6
- package/src/__tests__/context.test.ts +195 -0
- package/src/__tests__/integration-garbage-collection.web.ts +12 -15
- package/src/__tests__/useCache.web.ts +391 -0
- package/src/__tests__/useDLE.web.ts +660 -0
- package/src/__tests__/useQuery.web.ts +332 -50
- package/src/__tests__/useSubscription.web.ts +233 -119
- package/src/__tests__/useSuspense.web.ts +176 -50
- package/src/consumers/index.ts +2 -0
- package/src/consumers/useCache.ts +122 -0
- package/src/consumers/useDLE.ts +160 -0
- package/src/consumers/useFetch.ts +24 -13
- package/src/consumers/useLive.ts +6 -2
- package/src/consumers/useQuery.ts +14 -5
- package/src/consumers/useSubscription.ts +5 -1
- package/src/consumers/useSuspense.ts +29 -17
- package/src/index.ts +4 -0
- package/src/providers/DataClientPlugin.ts +25 -10
- package/src/providers/__tests__/DataClientPlugin.test.ts +204 -4
- package/src/providers/__tests__/createDataClient.test.ts +234 -0
- package/src/providers/__tests__/getDefaultManagers.test.ts +180 -0
- package/src/providers/index.ts +5 -1
- package/src/test/README.md +77 -16
- package/src/test/__tests__/mountDataClient.test.ts +426 -0
- package/src/test/__tests__/renderDataCompose.test.ts +586 -0
- package/src/test/index.ts +3 -9
- package/src/test/mountDataClient.ts +169 -0
- package/src/test/renderDataCompose.ts +150 -0
- package/src/types.ts +11 -0
- package/ts3.4/consumers/index.d.ts +2 -0
- package/ts3.4/consumers/useCache.d.ts +14 -0
- package/ts3.4/consumers/useDLE.d.ts +20 -0
- package/ts3.4/consumers/useFetch.d.ts +3 -6
- package/ts3.4/consumers/useLive.d.ts +3 -6
- package/ts3.4/consumers/useQuery.d.ts +3 -2
- package/ts3.4/consumers/useSubscription.d.ts +2 -3
- package/ts3.4/consumers/useSuspense.d.ts +3 -6
- package/ts3.4/index.d.ts +1 -0
- package/ts3.4/providers/DataClientPlugin.d.ts +6 -0
- package/ts3.4/providers/index.d.ts +1 -1
- package/ts3.4/test/index.d.ts +3 -4
- package/ts3.4/test/mountDataClient.d.ts +29 -0
- package/ts3.4/test/renderDataCompose.d.ts +19 -0
- package/ts3.4/types.d.ts +10 -0
- package/lib/test/renderDataClient.d.ts +0 -40
- package/lib/test/renderDataClient.d.ts.map +0 -1
- package/lib/test/renderDataClient.js +0 -264
- package/src/__tests__/__snapshots__/useSubscription.web.ts.snap +0 -7
- package/src/test/renderDataClient.ts +0 -316
- package/ts3.4/test/renderDataClient.d.ts +0 -40
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ npm install --save @data-client/vue @data-client/rest @data-client/test
|
|
|
36
36
|
|
|
37
37
|
For more details, see [the Installation docs page](https://dataclient.io/docs/getting-started/installation).
|
|
38
38
|
|
|
39
|
-
## Usage
|
|
39
|
+
## Usage
|
|
40
40
|
|
|
41
41
|
### Simple [TypeScript definition](https://dataclient.io/rest/api/Entity)
|
|
42
42
|
|
|
@@ -78,29 +78,6 @@ const ArticleResource = resource({
|
|
|
78
78
|
});
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
### Provide the Data Client
|
|
82
|
-
|
|
83
|
-
Install the plugin globally in your main app file for automatic setup across your entire application:
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
// main.ts
|
|
87
|
-
import { createApp } from 'vue';
|
|
88
|
-
import { DataClientPlugin } from '@data-client/vue';
|
|
89
|
-
import App from './App.vue';
|
|
90
|
-
|
|
91
|
-
const app = createApp(App);
|
|
92
|
-
|
|
93
|
-
app.use(DataClientPlugin, {
|
|
94
|
-
// optional overrides
|
|
95
|
-
// managers: getDefaultManagers(),
|
|
96
|
-
// initialState,
|
|
97
|
-
// Controller,
|
|
98
|
-
// gcPolicy,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
app.mount('#app');
|
|
102
|
-
```
|
|
103
|
-
|
|
104
81
|
### One line [data binding](https://dataclient.io/docs/getting-started/data-dependency)
|
|
105
82
|
|
|
106
83
|
```vue
|
package/dist/index.js
CHANGED
|
@@ -35,51 +35,46 @@ async function useSuspense(endpoint, ...args) {
|
|
|
35
35
|
const stateRef = injectState();
|
|
36
36
|
const controller = useController();
|
|
37
37
|
|
|
38
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
39
|
+
const resolvedArgs = vue.computed(() => args.map(a => vue.unref(a)));
|
|
40
|
+
|
|
38
41
|
// Compute a key that changes when args change (including reactive props)
|
|
39
|
-
const argsKey = vue.computed(() =>
|
|
42
|
+
const argsKey = vue.computed(() => resolvedArgs.value[0] !== null ? endpoint.key(...resolvedArgs.value) : '');
|
|
40
43
|
|
|
41
44
|
// Compute response meta reactively so we can respond to store updates
|
|
42
45
|
const responseMeta = vue.computed(() => {
|
|
43
|
-
return
|
|
46
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
44
47
|
});
|
|
45
48
|
const maybeFetch = async () => {
|
|
46
49
|
const currentKey = argsKey.value;
|
|
47
50
|
if (!currentKey) return;
|
|
48
51
|
const meta = responseMeta.value;
|
|
49
|
-
if (!meta) return;
|
|
50
52
|
const forceFetch = meta.expiryStatus === core.ExpiryStatus.Invalid;
|
|
51
53
|
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
52
|
-
await controller.fetch(endpoint, ...
|
|
54
|
+
await controller.fetch(endpoint, ...resolvedArgs.value);
|
|
53
55
|
};
|
|
54
56
|
|
|
55
|
-
// Trigger on initial call
|
|
56
|
-
await maybeFetch();
|
|
57
|
-
|
|
58
57
|
// Watch for changes to key, expiry, or store state that require refetch
|
|
59
58
|
vue.watch(() => {
|
|
60
59
|
const m = responseMeta.value;
|
|
61
|
-
return
|
|
60
|
+
return [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value];
|
|
62
61
|
}, () => {
|
|
63
62
|
return maybeFetch();
|
|
64
63
|
});
|
|
65
64
|
|
|
66
65
|
// Maintain GC refcounts on data mount/changes
|
|
67
|
-
vue.watch(() => {
|
|
68
|
-
|
|
69
|
-
return (_responseMeta$value = responseMeta.value) == null ? void 0 : _responseMeta$value.data;
|
|
70
|
-
}, (_newVal, _oldVal, onCleanup) => {
|
|
71
|
-
var _responseMeta$value2;
|
|
72
|
-
const decrement = (_responseMeta$value2 = responseMeta.value) == null ? void 0 : _responseMeta$value2.countRef();
|
|
66
|
+
vue.watch(() => responseMeta.value.data, (_newVal, _oldVal, onCleanup) => {
|
|
67
|
+
const decrement = responseMeta.value.countRef();
|
|
73
68
|
onCleanup(() => decrement == null ? void 0 : decrement());
|
|
74
69
|
}, {
|
|
75
70
|
immediate: true
|
|
76
71
|
});
|
|
77
72
|
|
|
73
|
+
// Trigger on initial call
|
|
74
|
+
await maybeFetch();
|
|
75
|
+
|
|
78
76
|
// Return readonly computed ref - Vue automatically unwraps in templates and reactive contexts
|
|
79
|
-
return vue.readonly(vue.computed(() =>
|
|
80
|
-
var _responseMeta$value3;
|
|
81
|
-
return (_responseMeta$value3 = responseMeta.value) == null ? void 0 : _responseMeta$value3.data;
|
|
82
|
-
}));
|
|
77
|
+
return vue.readonly(vue.computed(() => responseMeta.value.data));
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
/**
|
|
@@ -118,13 +113,17 @@ function useSubscription(endpoint, ...args) {
|
|
|
118
113
|
* Mirrors React's useQuery semantics using Vue reactivity.
|
|
119
114
|
* @see https://dataclient.io/docs/api/useQuery
|
|
120
115
|
*/
|
|
116
|
+
|
|
121
117
|
function useQuery(schema, ...args) {
|
|
122
118
|
const stateRef = injectState();
|
|
123
119
|
const controller = useController();
|
|
124
120
|
|
|
121
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
122
|
+
const resolvedArgs = vue.computed(() => args.map(a => vue.unref(a)));
|
|
123
|
+
|
|
125
124
|
// Compute query meta based on state and args. This mirrors React's memoization
|
|
126
125
|
// that keys off state.entities/indexes and args.
|
|
127
|
-
const queryMeta = vue.computed(() => controller.getQueryMeta(schema, ...
|
|
126
|
+
const queryMeta = vue.computed(() => controller.getQueryMeta(schema, ...resolvedArgs.value, stateRef.value));
|
|
128
127
|
|
|
129
128
|
// Maintain GC refcounts on data mount/changes
|
|
130
129
|
vue.watch(() => queryMeta.value.data, (_newVal, _oldVal, onCleanup) => {
|
|
@@ -251,21 +250,23 @@ function useFetch(endpoint, ...args) {
|
|
|
251
250
|
const stateRef = injectState();
|
|
252
251
|
const controller = useController();
|
|
253
252
|
|
|
253
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
254
|
+
const resolvedArgs = vue.computed(() => args.map(a => vue.unref(a)));
|
|
255
|
+
|
|
254
256
|
// Compute a key that changes when args change (including reactive props)
|
|
255
|
-
const argsKey = vue.computed(() =>
|
|
257
|
+
const argsKey = vue.computed(() => resolvedArgs.value[0] !== null ? endpoint.key(...resolvedArgs.value) : '');
|
|
256
258
|
|
|
257
259
|
// Compute response meta reactively so we can respond to store updates
|
|
258
260
|
const responseMeta = vue.computed(() => {
|
|
259
|
-
return
|
|
261
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
260
262
|
});
|
|
261
263
|
const lastPromise = vue.ref(undefined);
|
|
262
264
|
const maybeFetch = () => {
|
|
263
|
-
if (
|
|
265
|
+
if (!argsKey.value) return;
|
|
264
266
|
const meta = responseMeta.value;
|
|
265
|
-
if (!meta) return;
|
|
266
267
|
const forceFetch = meta.expiryStatus === core.ExpiryStatus.Invalid;
|
|
267
268
|
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
268
|
-
lastPromise.value = controller.fetch(endpoint, ...
|
|
269
|
+
lastPromise.value = controller.fetch(endpoint, ...resolvedArgs.value);
|
|
269
270
|
};
|
|
270
271
|
|
|
271
272
|
// Trigger on initial call
|
|
@@ -274,13 +275,156 @@ function useFetch(endpoint, ...args) {
|
|
|
274
275
|
// Also watch for store changes that might require refetch (e.g., invalidation)
|
|
275
276
|
vue.watch(() => {
|
|
276
277
|
const m = responseMeta.value;
|
|
277
|
-
return
|
|
278
|
+
return [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value];
|
|
278
279
|
}, () => {
|
|
279
280
|
maybeFetch();
|
|
280
281
|
});
|
|
281
282
|
return lastPromise;
|
|
282
283
|
}
|
|
283
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Read an Endpoint's response if it is ready.
|
|
287
|
+
*
|
|
288
|
+
* `useCache` guarantees referential equality globally.
|
|
289
|
+
* @see https://dataclient.io/docs/api/useCache
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
function useCache(endpoint, ...args) {
|
|
293
|
+
const stateRef = injectState();
|
|
294
|
+
const controller = useController();
|
|
295
|
+
|
|
296
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
297
|
+
const resolvedArgs = vue.computed(() => args.map(a => vue.unref(a)));
|
|
298
|
+
|
|
299
|
+
// Compute a key that changes when args change (including reactive props)
|
|
300
|
+
const argsKey = vue.computed(() => resolvedArgs.value[0] !== null ? endpoint.key(...resolvedArgs.value) : '');
|
|
301
|
+
|
|
302
|
+
// Compute response meta reactively so we can respond to store updates
|
|
303
|
+
const responseMeta = vue.computed(() => {
|
|
304
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// If we are hard invalid we must fetch regardless of triggering or staleness
|
|
308
|
+
const forceFetch = vue.computed(() => responseMeta.value.expiryStatus === core.ExpiryStatus.Invalid);
|
|
309
|
+
|
|
310
|
+
/*********** This block is to ensure results are only filled when they would not suspend **************/
|
|
311
|
+
// This computation reflects the behavior of useSuspense/useFetch
|
|
312
|
+
// It only changes the value when expiry or params change.
|
|
313
|
+
// This way, random unrelated re-renders don't cause the concept of expiry
|
|
314
|
+
// to change
|
|
315
|
+
const expired = vue.computed(() => {
|
|
316
|
+
return (Date.now() > responseMeta.value.expiresAt || forceFetch.value) && argsKey.value;
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// fully "valid" data will not suspend/loading even if it is not fresh
|
|
320
|
+
const loading = vue.computed(() => responseMeta.value.expiryStatus !== core.ExpiryStatus.Valid && expired.value);
|
|
321
|
+
/****************************************************************************************************/
|
|
322
|
+
|
|
323
|
+
// Maintain GC refcounts on data mount/changes
|
|
324
|
+
vue.watch(() => responseMeta.value.data, (_newVal, _oldVal, onCleanup) => {
|
|
325
|
+
const decrement = responseMeta.value.countRef();
|
|
326
|
+
onCleanup(() => decrement());
|
|
327
|
+
}, {
|
|
328
|
+
immediate: true
|
|
329
|
+
});
|
|
330
|
+
return vue.computed(() => {
|
|
331
|
+
// if useSuspense() would suspend, don't include entities from cache
|
|
332
|
+
if (loading.value) {
|
|
333
|
+
if (!endpoint.schema) return undefined;
|
|
334
|
+
// TODO: use getResponse() once it just returns data
|
|
335
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, {
|
|
336
|
+
...stateRef.value,
|
|
337
|
+
entities: {}
|
|
338
|
+
}).data;
|
|
339
|
+
}
|
|
340
|
+
return responseMeta.value.data;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Use async data with { data, loading, error } (DLE)
|
|
346
|
+
* @see https://dataclient.io/docs/api/useDLE
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
function useDLE(endpoint, ...args) {
|
|
350
|
+
const stateRef = injectState();
|
|
351
|
+
const controller = useController();
|
|
352
|
+
|
|
353
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
354
|
+
const resolvedArgs = vue.computed(() => args.map(a => vue.unref(a)));
|
|
355
|
+
|
|
356
|
+
// Compute a key that changes when args change (including reactive props)
|
|
357
|
+
const argsKey = vue.computed(() => resolvedArgs.value[0] !== null ? endpoint.key(...resolvedArgs.value) : '');
|
|
358
|
+
|
|
359
|
+
// Compute response meta reactively so we can respond to store updates
|
|
360
|
+
const responseMeta = vue.computed(() => {
|
|
361
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// If we are hard invalid we must fetch regardless of triggering or staleness
|
|
365
|
+
const forceFetch = vue.computed(() => responseMeta.value.expiryStatus === core.ExpiryStatus.Invalid);
|
|
366
|
+
|
|
367
|
+
/*********** This block is to ensure results are only filled when they would not suspend **************/
|
|
368
|
+
// This computation reflects the behavior of useSuspense/useFetch
|
|
369
|
+
// It only changes the value when expiry or params change.
|
|
370
|
+
// This way, random unrelated re-renders don't cause the concept of expiry
|
|
371
|
+
// to change
|
|
372
|
+
const expired = vue.computed(() => {
|
|
373
|
+
return !!((Date.now() > responseMeta.value.expiresAt || forceFetch.value) && argsKey.value);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// fully "valid" data will not suspend/loading even if it is not fresh
|
|
377
|
+
const loading = vue.computed(() => {
|
|
378
|
+
return !!(responseMeta.value.expiryStatus !== core.ExpiryStatus.Valid && expired.value);
|
|
379
|
+
});
|
|
380
|
+
/****************************************************************************************************/
|
|
381
|
+
|
|
382
|
+
// Trigger fetch when necessary
|
|
383
|
+
vue.watch(() => {
|
|
384
|
+
const m = responseMeta.value;
|
|
385
|
+
return [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value];
|
|
386
|
+
}, async () => {
|
|
387
|
+
const currentKey = argsKey.value;
|
|
388
|
+
if (!currentKey) return;
|
|
389
|
+
const meta = responseMeta.value;
|
|
390
|
+
const force = forceFetch.value;
|
|
391
|
+
if (Date.now() <= meta.expiresAt && !force) return;
|
|
392
|
+
await controller.fetch(endpoint, ...resolvedArgs.value).catch(() => {});
|
|
393
|
+
}, {
|
|
394
|
+
immediate: true
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// Maintain GC refcounts on data mount/changes
|
|
398
|
+
vue.watch(() => responseMeta.value.data, (_newVal, _oldVal, onCleanup) => {
|
|
399
|
+
const decrement = responseMeta.value.countRef();
|
|
400
|
+
onCleanup(() => decrement());
|
|
401
|
+
}, {
|
|
402
|
+
immediate: true
|
|
403
|
+
});
|
|
404
|
+
const data = vue.computed(() => {
|
|
405
|
+
// if useSuspense() would suspend, don't include entities from cache
|
|
406
|
+
if (loading.value) {
|
|
407
|
+
if (!endpoint.schema) return undefined;
|
|
408
|
+
// TODO: use getResponse() once it just returns data
|
|
409
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, {
|
|
410
|
+
...stateRef.value,
|
|
411
|
+
entities: {}
|
|
412
|
+
}).data;
|
|
413
|
+
}
|
|
414
|
+
return responseMeta.value.data;
|
|
415
|
+
});
|
|
416
|
+
const error = vue.computed(() => {
|
|
417
|
+
return controller.getError(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// Use markRaw to prevent Vue from auto-unwrapping the computed refs
|
|
421
|
+
return vue.markRaw({
|
|
422
|
+
data,
|
|
423
|
+
loading,
|
|
424
|
+
error
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
284
428
|
/* istanbul ignore next */
|
|
285
429
|
/** Returns the default Managers used by DataProvider. */
|
|
286
430
|
exports.getDefaultManagers = (options = {}) => {
|
|
@@ -450,22 +594,26 @@ const DataClientPlugin = {
|
|
|
450
594
|
...options,
|
|
451
595
|
app
|
|
452
596
|
});
|
|
597
|
+
app.config.globalProperties.$dataClient = provider.controller;
|
|
453
598
|
|
|
454
|
-
|
|
455
|
-
if (
|
|
456
|
-
|
|
457
|
-
beforeMount() {
|
|
458
|
-
provider.start();
|
|
459
|
-
},
|
|
460
|
-
beforeUnmount() {
|
|
461
|
-
provider.stop();
|
|
462
|
-
}
|
|
463
|
-
});
|
|
599
|
+
/* istanbul ignore if */
|
|
600
|
+
if (process.env.NODE_ENV === 'development') {
|
|
601
|
+
console.info('Starting DataClientPlugin');
|
|
464
602
|
}
|
|
603
|
+
provider.start();
|
|
604
|
+
app.onUnmount(() => {
|
|
605
|
+
/* istanbul ignore if */
|
|
606
|
+
if (process.env.NODE_ENV === 'development') {
|
|
607
|
+
console.info('Stopping DataClientPlugin');
|
|
608
|
+
}
|
|
609
|
+
provider.stop();
|
|
610
|
+
});
|
|
465
611
|
return provider;
|
|
466
612
|
}
|
|
467
613
|
};
|
|
468
614
|
|
|
615
|
+
// install global property types
|
|
616
|
+
|
|
469
617
|
Object.defineProperty(exports, "Controller", {
|
|
470
618
|
enumerable: true,
|
|
471
619
|
get: function () { return core.Controller; }
|
|
@@ -504,7 +652,9 @@ Object.defineProperty(exports, "actionTypes", {
|
|
|
504
652
|
});
|
|
505
653
|
exports.DataClientPlugin = DataClientPlugin;
|
|
506
654
|
exports.createDataClient = createDataClient;
|
|
655
|
+
exports.useCache = useCache;
|
|
507
656
|
exports.useController = useController;
|
|
657
|
+
exports.useDLE = useDLE;
|
|
508
658
|
exports.useDebounce = useDebounce;
|
|
509
659
|
exports.useFetch = useFetch;
|
|
510
660
|
exports.useLive = useLive;
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VDC={},e.Vue)}(this,(function(e,t){"use strict";class n{constructor(){this.localCache=new Map}getEntity(e,t,n,s){const i=t.key;this.localCache.has(i)||this.localCache.set(i,new Map);const r=this.localCache.get(i);return r.get(e)||s(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}}const s=Symbol("INVALID"),i={};function r(e){return null!==e&&void 0!==e.pk}const o=e=>e[0],a=e=>void 0!==e&&"symbol"!=typeof e,c=(e,t,n,s,i,r)=>{e=o(e);const a=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return a.map((t=>r(e,t,n,s,i)))},l=(e,t,n,s)=>(e=o(e),t.map?t.map((t=>s(e,t))).filter(a):t);function u(){}const h=(e,t,n,s,i,r)=>{const o={...t};return Object.keys(e).forEach((n=>{const s=e[n],a=r(s,t[n],t,n,i);void 0===a?delete o[n]:o[n]=a})),o},d=(e,t,n,i)=>{if(function(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}(t))return function(e,t,n,i){let r=!1;const o=Object.keys(e).reduce(((t,n)=>{const s=`${n}`,o=i(e[s],t.get(s));return"symbol"==typeof o&&(r=!0),t.has(s)?t.set(s,o):t}),t);return r?s:o}(e,t,0,i);const r={...t};let o=!1;return Object.keys(e).forEach((t=>{const n=i(e[t],r[t]);void 0!==r[t]&&(r[t]=n),"symbol"==typeof n&&(o=!0)})),o?s:r};function p(e,t,n,s){const i={};for(const r of Object.keys(e))i[r]=n(e[r],t,s);return i}const f=(e,t,n,s)=>function(r,o){const a="object"!=typeof o,c=a?e({key:r.key,pk:o}):o;if("symbol"==typeof c)return r.denormalize(c,n,s);if(void 0===c&&a&&""!==o&&"undefined"!==o)return t.getEntity(o,r,i,(e=>{e.set(o,void 0)}));if("object"!=typeof c||null===c)return c;let l=a?o:r.pk(c,void 0,void 0,n);return void 0===l||""===l||"undefined"===l?function(e){const t=new Map;return e(t),t.get("")}((e=>y(r,c,"",e,n,s))):("string"!=typeof l&&(l=`${l}`),t.getEntity(l,r,c,(e=>y(r,c,l,e,n,s))))};function y(e,t,n,i,r,o){const a=e.createIfValid(t);void 0===a?i.set(n,s):(i.set(n,a),i.set(n,e.denormalize(a,r,o)))}const g=(e,t,n)=>{const s=f(e,t,n,i);function i(e,t){if(!e)return t;if(null==t)return t;if("function"==typeof e.denormalize)return r(e)?s(e,t):e.denormalize(t,n,i);if("function"==typeof e)return e(t);if("object"==typeof e){return(Array.isArray(e)?l:d)(e,t,n,i)}return t}return(e,n)=>{const s=Object(n)===n&&Object(e)===e;return t.getResults(n,s,(()=>i(e,n)))}};class v{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,n=[{path:[""],entity:e}];return[{INVALID:s,getIndex(...e){const s=t.getIndex(...e);return n.push({path:e,entity:s}),t.getIndexEnd(s,e[2])},getEntity(...e){const s=t.getEntity(...e);return n.push({path:e,entity:s}),s},getEntities(e){const s=t.getEntitiesObject(e);return n.push({path:[e],entity:s}),t.getEntities(e)}},n]}}class m extends v{constructor(e){super(e)}getEntitiesObject(e){return this.entities[e]}getEntities(e){const t=this.entities[e];if(void 0!==t)return{keys:()=>Object.keys(t),entries:()=>Object.entries(t)}}getEntity(e,t){var n;return null==(n=this.entities[e])?void 0:n[t]}getIndex(e,t){var n;return null==(n=this.indexes[e])?void 0:n[t]}getIndexEnd(e,t){return null==e?void 0:e[t]}}const E={QueryDelegate:m,getEntities:e=>({key:t,pk:n})=>{var s;return null==(s=e[t])?void 0:s[n]}};class w{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return b;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return b}return[n.value,n.journey]}set(e,t){if(e.length<1)throw new k;let n=this;for(const{path:t,entity:s}of e){let e=n.next.get(s);e||(e=new x,n.next.set(null!=s?s:i,e)),n.nextPath=t,n=e}n.nextPath=void 0,n.value=t,n.journey=e.map((e=>e.path))}}const b=[void 0,void 0];class x{constructor(){this.next=new WeakMap,this.nextPath=void 0,this.value=void 0,this.journey=[]}}class k extends Error{constructor(...e){super(...e),this.message="Keys must include at least one member"}}class I extends m{constructor(e,t){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.meta=t,this.checkLoop=function(){const e=new Map;return function(t,n,s){e.has(t)||e.set(t,new Map);const i=e.get(t);i.has(n)||i.set(n,[]);const r=i.get(n);return!!r.some((e=>e===s))||(r.push(s),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){return this.newEntities.has(e)||(this.newEntities.set(e,new Map),this.entities[e]={...this.entities[e]},this.entitiesMeta[e]={...this.entitiesMeta[e]}),this.newEntities.get(e)}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]={...this.indexes[e]}),this.newIndexes.get(e)}mergeEntity(e,t,n){const s=e.key;let i=n,r=this.meta,o=this.getNewEntity(s,t);if(o)i=e.merge(o,n);else if(o=this.getEntity(s,t),o){const a=this.getMeta(s,t);i=e.mergeWithStore(a,r,o,n),r=e.mergeMetaWithStore(a,r,o,n)}this.setEntity(e,t,i,r)}setEntity(e,t,n,i=this.meta){const r=e.key,o=this.getNewEntities(r),a=!o.has(t);o.set(t,n),e.indexes&&function(e,t,n,i,r,o){for(const a of t){n.has(a)||n.set(a,i[a]={});const t=n.get(a);o[e]&&delete t[o[e][a]],o&&o[e]&&o[e][a]!==r[a]&&(t[o[e][a]]=s),a in r&&(t[r[a]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],n,this.entities[r]),this._setEntity(r,t,n),a&&this._setMeta(r,t,i)}invalidate({key:e},t){this.setEntity({key:e},t,s)}_setEntity(e,t,n){this.entities[e][t]=n}_setMeta(e,t,n){this.entitiesMeta[e][t]=n}getMeta(e,t){return this.entitiesMeta[e][t]}}const L=(e,t,n=[],{entities:s,indexes:i,entitiesMeta:r}=A,o={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:s,indexes:i,entitiesMeta:r};const a=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(e);if(null===t||typeof t!==a&&(void 0===e.key||void 0!==e.pk||"string"!=typeof t))throw new Error(`Unexpected input given to normalize. Expected type to be "${a}", found "${null===t?"null":typeof t}".`);const l={result:"",entities:{...s},indexes:{...i},entitiesMeta:{...r}},u=(e=>{const t=(n,s,i,r,o)=>s&&n?n.normalize&&"function"==typeof n.normalize?"object"!=typeof s?n.pk?`${s}`:s:n.normalize(s,i,r,o,t,e):"object"!=typeof s||"object"!=typeof n?s:(Array.isArray(n)?c:h)(n,s,i,r,o,t):s;return t})(new I(l,o));return l.result=u(e,t,t,void 0,n),l};const A={entities:{},indexes:{},entitiesMeta:{}};class S{constructor(e,t,n){this.dependencies=[],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._getEntity=e,this._getCache=t,this._resultCache=n}getEntity(e,t,n,s){const i=t.key,{localCacheKey:r,cycleCacheKey:o}=this.getCacheKey(i);if(r.get(e))o.has(e)?this.cycleIndex=o.get(e):this.dependencies.push({path:{key:i,pk:e},entity:n});else{const a=this._getCache(e,t),[c,l]=a.get(n,this._getEntity);if(l)return r.set(e,c.value),this.dependencies.push(...c.dependencies),c.value;{const t=this.dependencies.length;o.set(e,t),this.dependencies.push({path:{key:i,pk:e},entity:n}),s(r),o.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),l={dependencies:c,value:r.get(e)};a.set(c,l),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getCacheKey(e){this.localCache.has(e)||this.localCache.set(e,new Map),this.cycleCache.has(e)||this.cycleCache.set(e,new Map);return{localCacheKey:this.localCache.get(e),cycleCacheKey:this.cycleCache.get(e)}}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[s,i]=this._resultCache.get(e,this._getEntity);return void 0===i?(s=n(),i=this.paths(),this.dependencies.unshift({path:{key:"",pk:""},entity:e}),this._resultCache.set(this.dependencies,s)):i.shift(),{data:s,paths:i}}paths(){return this.dependencies.map((e=>e.path))}}function M(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(M))}class O{constructor(e=E){var t;this.endpoints=new w,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var s;const i=n.key,r=null!=(s=n.cacheWith)?s:n;t.has(i)||t.set(i,new Map);const o=t.get(i);o.has(e)||o.set(e,new WeakMap);const a=o.get(e);let c=a.get(r);return c||(c=new w,a.set(r,c)),c})}denormalize(e,t,n,s=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const i=this.policy.getEntities(n);return g(i,new S(i,this._getCache,this.endpoints),s)(e,t)}query(e,t,n,s=JSON.stringify(t)){const i=this.buildQueryKey(e,t,n,s);return i?this.denormalize(e,i,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,s=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;this.queryKeys.get(s)||this.queryKeys.set(s,new w);const i=this.queryKeys.get(s),r=new this.policy.QueryDelegate(n);let[o,a]=i.get(e,(c=r,e=>c[["","getEntitiesObject","getEntity","getIndex"][e.length]](...e)));var c;if(!a){const[n,s]=r.tracked(e);o=function(e){return function t(n,s){return function(e){return!!e&&"function"==typeof e.queryKey}(n)?n.queryKey(s,t,e):"object"==typeof n&&n?(Array.isArray(n)?u:p)(n,s,t,e):n}}(n)(e,t),i.set(s,o)}return o}}var R={Invalid:1,InvalidIfStale:2,Valid:3};function C(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const P="rdc/fetch",_="rdc/set",j="rdc/setresponse",T="rdc/optimistic",D="rdc/reset",q="rdc/subscribe",N="rdc/unsubscribe",K="rdc/invalidate",H="rdc/invalidateall",z="rdc/expireall",F="rdc/gc",U=P,V=_,B=j,Y=T,Q=D,$=q,W=N,X=K,J=H,G=z,Z=F;var ee=Object.freeze({__proto__:null,EXPIREALL:z,EXPIREALL_TYPE:G,FETCH:P,FETCH_TYPE:U,GC:F,GC_TYPE:Z,INVALIDATE:K,INVALIDATEALL:H,INVALIDATEALL_TYPE:J,INVALIDATE_TYPE:X,OPTIMISTIC:T,OPTIMISTIC_TYPE:Y,RESET:D,RESET_TYPE:Q,SET:_,SET_RESPONSE:j,SET_RESPONSE_TYPE:B,SET_TYPE:V,SUBSCRIBE:q,SUBSCRIBE_TYPE:$,UNSUBSCRIBE:N,UNSUBSCRIBE_TYPE:W});function te(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const o=(n=t.endpoint,s=t.args,i=t.meta.fetchedAt,{type:T,key:n.key(...s),args:s,endpoint:n,meta:C(null!=(r=n.dataExpiryLength)?r:6e4,i)});return{...e,optimistic:[...e.optimistic,o]}}var n,s,i,r;return e}class ne extends Error{}function se(e,t,n){return"AbortError"===n.name?{...e,optimistic:ie(e,t)}:{...e,meta:{...e.meta,[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,error:n,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(n)}},optimistic:ie(e,t)}}function ie(e,t){return e.optimistic.filter((e=>e.key!==t.key||(e.type===T?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function re(e){return function(t,n){switch(t||(t=oe),n.type){case F:return n.entities.forEach((({key:e,pk:n})=>{var s,i;null==(s=t.entities[e])||delete s[n],null==(i=t.entitiesMeta[e])||delete i[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case P:return te(t,n);case T:case j:return function(e,t,n){if(t.error)return se(e,t,t.response);try{var s;let i;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{i=t.endpoint.getOptimisticResponse.call(t.endpoint,n.snapshot(e,t.meta.fetchedAt),...t.args)}catch(t){if(t.constructor===ne)return e;throw t}}else i=t.response;const{result:r,entities:o,indexes:a,entitiesMeta:c}=L(t.endpoint.schema,i,t.args,e,t.meta),l={...e.endpoints,[t.key]:r};try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{l[t]=e[t](l[t])}))}}catch(e){console.error(`The following error occured during Endpoint.update() for ${t.key}`),console.error(e)}return{entities:o,endpoints:l,indexes:a,meta:{...e.meta,[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(s=e.meta[t.key])?void 0:s.expiresAt}},entitiesMeta:c,optimistic:ie(e,t),lastReset:e.lastReset}}catch(n){return"object"==typeof n&&(n.message=`Error processing ${t.key}\n\nFull Schema: ${JSON.stringify(t.endpoint.schema,void 0,2)}\n\nError:\n${n.message}`,"response"in t&&(n.response=t.response),n.status=400),se(e,t,n)}}(t,n,e);case _:return function(e,t,n){let s;if("function"==typeof t.value){const i=n.get(t.schema,...t.args,e);if(void 0===i)return e;s=t.value(i)}else s=t.value;try{const{entities:n,indexes:i,entitiesMeta:r}=L(t.schema,s,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:i,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case H:case K:return function(e,t){const n={...e.endpoints},s={...e.meta},i=e=>{delete n[e];const t={...s[e],expiresAt:0,invalidated:!0};delete t.error,s[e]=t};return t.type===K?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),{...e,endpoints:n,meta:s}}(t,n);case z:return function(e,t){const n={...e.meta};return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]={...n[e],expiresAt:1})})),{...e,meta:n}}(t,n);case D:return{...oe,lastReset:n.date};default:return t}}}const oe={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};const ae="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function ce(e,{args:t,fetchedAt:n,response:s,error:i=!1}){var r,o;const a=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(o=e.dataExpiryLength)?o:6e4;return{type:j,key:e.key(...t),response:s,args:t.map(ae),endpoint:e,meta:C(a,n),error:i}}class le{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function ue(e,t){return e.meta[t]}const he=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},de=()=>oe;class pe{constructor({dispatch:e=he,getState:t=de,memo:s=new O,gcPolicy:i=new le}={}){this.fetch=(e,...t)=>{const s=function(e,{args:t}){let n=0,s=0;const i=new Promise(((e,t)=>{[n,s]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:s,promise:i};return{type:P,key:e.key(...t),args:t,endpoint:e,meta:r}}(e,{args:t});return this.dispatch(s),e.schema?s.meta.promise.then((s=>function(e,t,s,i=[]){return void 0===e||void 0===t?t:g(E.getEntities(s),new n,i)(e,t).data}(e.schema,s,{},t))):s.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:s,expiryStatus:i}=this.getResponseMeta(e,...t,this.getState());return i!==R.Invalid&&Date.now()<=s?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:K,key:e.key(...t)}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:H,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:z,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:D,date:Date.now()}),this.setResponse=(e,...t)=>{const n=t[t.length-1],s=ce(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(s)},this.setError=(e,...t)=>{const n=t[t.length-1],s=ce(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(s)},this.resolve=(e,t)=>this.dispatch(ce(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:q,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new ye(this,e,t),this._dispatch=e,this.getState=t,this.memo=s,this.gcPolicy=i}set dispatch(e){this._dispatch=e}get dispatch(){return this._dispatch}bindMiddleware({dispatch:e,getState:t}){this._dispatch=e,this.getState=t}set(e,...t){const n=t[t.length-1],s=function(e,{args:t,fetchedAt:n,value:s}){return{type:_,value:s,args:t.map(ae),schema:e,meta:C(6e4,n)}}(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(s)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],s=t.slice(0,t.length-1),i=e.key(...s),r=ue(n,i);return void 0===n.endpoints[i]||"soft"!==(null==r?void 0:r.errorPolicy)?null==r?void 0:r.error:void 0}getResponse(e,...t){return this.getResponseMeta(e,...t)}getResponseMeta(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ae),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",o=i?n.endpoints[r]:void 0,a=e.schema,c=ue(n,r);let l=null==c?void 0:c.expiresAt;const u=void 0===o&&void 0!==a,h=u?this.memo.buildQueryKey(a,s,n,r):o;if(!i)return{data:h,expiryStatus:R.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(u)d=!M(h);else if(!a||!fe(a))return{data:o,expiryStatus:this.getExpiryStatus(!o,!!e.invalidIfStale,c),expiresAt:l||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(a,h,n.entities,s);return l||(l=d?1:function(e,t){let n=1/0;for(const{key:i,pk:r}of e){var s;const e=null==(s=t[i])||null==(s=s[r])?void 0:s.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:l,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ae),{data:i}=this.memo.query(e,s,n);return"symbol"==typeof i?void 0:i}getQueryMeta(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ae),{data:i,paths:r}=this.memo.query(e,s,n);return{data:"symbol"==typeof i?void 0:i,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?R.Invalid:e||t?R.InvalidIfStale:R.Valid}}function fe(e){if(r(e))return!0;if(Array.isArray(e))return 0!==e.length&&fe(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?fe(t):Object.values(t).some((e=>fe(e)))}return!1}class ye{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=ye.abort,this.state=t,this.controller=e,this.fetchedAt=n}getResponse(e,...t){return this.controller.getResponse(e,...t,this.state)}getResponseMeta(e,...t){return this.controller.getResponseMeta(e,...t,this.state)}getError(e,...t){return this.controller.getError(e,...t,this.state)}get(e,...t){return this.controller.get(e,...t,this.state)}getQueryMeta(e,...t){return this.controller.getQueryMeta(e,...t,this.state)}}ye.abort=new ne;class ge extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class ve{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new pe,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case P:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case j:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const s=null==(t=e.getState().meta[n.key])?void 0:t.error;s?this.handleSet(ce(n.endpoint,{args:n.args,response:s,fetchedAt:n.meta.fetchedAt,error:!0})):this.handleSet(n)}}));case D:{const e=Array.from(this.fetching.values());return this.clearAll(),t(n).then((()=>{for(const{reject:t}of e)t(new ge)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===P&&this.fetching.has(e.key)}allSettled(){if(this.fetching.size)return Promise.allSettled(this.fetching.values().map((({promise:e})=>e)))}clearAll(){for(const e of this.fetching.keys())this.clear(e)}clear(e){this.fetching.has(e)&&(this.fetching.get(e).promise.catch((()=>{})),this.fetching.delete(e))}getLastReset(){return this.cleanupDate?this.cleanupDate:this.controller.getState().lastReset}handleFetch(e){const{resolve:t,reject:n,fetchedAt:s}=e.meta,i=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return i||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s}),t})).catch((t=>{const n=this.getLastReset();throw s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s,error:!0}),t})),r};return i?this.throttle(e.key,r,s).then((e=>t(e))).catch((e=>n(e))):r().catch((()=>{}))}handleSet(e){if(this.fetching.has(e.key)){const{reject:t,resolve:n}=this.fetching.get(e.key);e.error?t(e.response):n(e.response),this.clear(e.key)}}throttle(e,t,n){const s=this.getLastReset();let i=this.fetching.get(e);return i&&i.fetchedAt>s||(i=function(e){const t={fetchedAt:e};return t.promise=new Promise(((e,n)=>{t.resolve=e,t.reject=n})),t}(n),this.fetching.set(e,i),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),i.promise}idleCallback(e,t){e()}}class me{isOnline(){return void 0===navigator.onLine||navigator.onLine}addOnlineListener(e){addEventListener("online",e)}removeOnlineListener(e){removeEventListener("online",e)}addOfflineListener(e){addEventListener("offline",e)}removeOfflineListener(e){removeEventListener("offline",e)}}class Ee{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}e.DefaultConnectionListener=void 0,"undefined"!=typeof navigator&&"function"==typeof addEventListener?e.DefaultConnectionListener=me:e.DefaultConnectionListener=Ee;class we{constructor(t,n,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===t.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=t.endpoint,this.frequency=t.endpoint.pollFrequency,this.args=t.args,this.key=t.key,this.frequencyHistogram.set(this.frequency,1),this.controller=n,this.connectionListener=s||new e.DefaultConnectionListener,this.connectionListener.isOnline()?this.onlineListener():this.offlineListener()}add(e){void 0!==e&&(this.frequencyHistogram.has(e)?this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)+1):(this.frequencyHistogram.set(e,1),e<this.frequency&&(this.frequency=e,this.run())))}remove(e){if(void 0===e)return!1;if(this.frequencyHistogram.has(e)&&(this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)-1),this.frequencyHistogram.get(e)<1)){if(this.frequencyHistogram.delete(e),0===this.frequencyHistogram.size)return this.cleanup(),!0;e<=this.frequency&&(this.frequency=Math.min(...this.frequencyHistogram.keys()),this.run())}return!1}cleanup(){this.intervalId&&(clearInterval(this.intervalId),delete this.intervalId),this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.startId&&(clearTimeout(this.startId),delete this.startId),this.connectionListener.removeOnlineListener(this.onlineListener),this.connectionListener.removeOfflineListener(this.offlineListener)}update(){const e=this.endpoint,t=function(...t){return e.call(this,...t)};Object.assign(t,this.endpoint),t.dataExpiryLength=this.frequency/2,t.errorExpiryLength=this.frequency/10,t.errorPolicy=()=>"soft",t.key=()=>this.key,this.controller.fetch(t,...this.args).catch((()=>null))}run(){this.startId||(this.intervalId&&(this.lastIntervalId=this.intervalId),this.intervalId=setInterval((()=>{this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.intervalId&&this.update()}),this.frequency))}lastFetchTime(){var e,t;return null!=(e=null==(t=this.controller.getState().meta[this.key])?void 0:t.date)?e:0}}class be{constructor(e){this.subscriptions={},this.controller=new pe,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case q:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case N:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}}),this.Subscription=e}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].add(n)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].remove(n)&&delete this.subscriptions[t]}}}let xe={};class ke{constructor(e,t){this.started=!1,this.actions=[],this.maxBufferLength=100,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect({...xe,...e}),null!=e&&e.maxAge&&(this.maxBufferLength=2*e.maxAge),t&&(this.skipLogging=t)}handleAction(e,t){this.started?this.devTools.send(e,t):(this.actions.length>this.maxBufferLength&&(this.actions=this.actions.slice(this.maxBufferLength/2)),this.actions.push([e,t]))}init(e){}cleanup(){}}ke.prototype.middleware=()=>e=>t=>e(t);const Ie=Symbol("DataClientState"),Le=Symbol("DataClientController"),Ae=t.shallowRef(oe);function Se(){const e=t.inject(Le,null);return e||new pe}function Me(){const e=t.inject(Ie,null);return e||Ae}async function Oe(e,...n){const s=Me(),i=Se(),r=t.computed((()=>null!==n[0]?e.key(...n):"")),o=t.computed((()=>r.value?i.getResponseMeta(e,...n,s.value):null)),a=async()=>{if(!r.value)return;const t=o.value;if(!t)return;const s=t.expiryStatus===R.Invalid;Date.now()<=t.expiresAt&&!s||await i.fetch(e,...n)};return await a(),t.watch((()=>{const e=o.value;return e?[e.expiresAt,e.expiryStatus,s.value.lastReset,r.value]:[r.value]}),(()=>a())),t.watch((()=>{var e;return null==(e=o.value)?void 0:e.data}),((e,t,n)=>{var s;const i=null==(s=o.value)?void 0:s.countRef();n((()=>null==i?void 0:i()))}),{immediate:!0}),t.readonly(t.computed((()=>{var e;return null==(e=o.value)?void 0:e.data})))}function Re(e,...n){const s=Se(),i=t.computed((()=>n.map((e=>t.unref(e))))),r=t.computed((()=>null===i.value[0]?"":e.key(...i.value)));t.watch(r,((t,n,o)=>{if(!r.value)return;const a=i.value;s.subscribe(e,...a),o((()=>{s.unsubscribe(e,...a)}))}),{immediate:!0})}let Ce=(e={})=>{const{networkManager:t,subscriptionManager:n=we}=e;return null===n?[Pe(ve,null!=t?t:{})]:[Pe(ve,null!=t?t:{}),Pe(be,n)]};function Pe(e,t){return t instanceof e?t:new e(t)}function _e(e={}){var n,s;const{Controller:i=pe,gcPolicy:r,app:o}=e,a=new i({gcPolicy:r}),c=null!=(n=e.managers)?n:Ce(),l=null!=(s=e.initialState)?s:oe,u=function(e,t,n){return()=>(e.forEach((e=>{null==e.init||e.init(n)})),t.gcPolicy.init(t),()=>{e.forEach((e=>{e.cleanup()})),t.gcPolicy.cleanup()})}(c,a,l),h=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),s=>(0===n&&t.bindMiddleware(s),e.middleware(t)))))}(c,a),d=re(a),p=t.shallowRef(l),f=t.shallowRef(b(l));let y=null;const g=()=>p.value,v=h.map((e=>e({getState:g,dispatch:e=>m(e)}))),m=(E=v,e=>E.reduceRight(((e,t)=>t(e)),e))((async e=>{const t=new Promise((e=>{y=e}));return await(async e=>{const t=d(p.value,e);if(p.value=t,f.value=b(t),y){const e=y;y=null,e()}})(e),t}));var E;let w;a.bindMiddleware({getState:g,dispatch:e=>m(e)});return o?(o.provide(Ie,f),o.provide(Le,a)):(t.provide(Ie,f),t.provide(Le,a)),{controller:a,stateRef:f,start:()=>{w=u()},stop:()=>{w&&w()}};function b(e){return e.optimistic.reduce(d,e)}}function je(){return je=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},je.apply(null,arguments)}const Te={install(e,t={}){const n=_e(je({},t,{app:e}));return e.mixin&&e.mixin({beforeMount(){n.start()},beforeUnmount(){n.stop()}}),n}};e.Controller=pe,e.DataClientPlugin=Te,e.DevToolsManager=ke,e.ExpiryStatus=R,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===j&&n.error&&this.shouldLogout(n.response)&&this.handleLogout(e)},e&&(this.handleLogout=e),t&&(this.shouldLogout=t)}cleanup(){}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=ve,e.PollingSubscription=we,e.SubscriptionManager=be,e.actionTypes=ee,e.createDataClient=_e,e.getDefaultManagers=Ce,e.useController=Se,e.useDebounce=function(e,n,s=!0){const i=t.ref("object"==typeof e&&null!==e&&"value"in e?e.value:e),r=t.ref(!1);let o=null;const a=()=>{null!==o&&(clearTimeout(o),o=null)};return t.watch([()=>"object"==typeof e&&null!==e&&"value"in e?e.value:e,()=>"object"==typeof s&&null!==s&&"value"in s?s.value:s,()=>n],(([e,t])=>{a(),t?(r.value=!0,o=setTimeout((()=>{i.value=e,r.value=!1,o=null}),n)):r.value=!1}),{immediate:!1}),t.onUnmounted((()=>{a()})),[i,r]},e.useFetch=function(e,...n){const s=Me(),i=Se(),r=t.computed((()=>null!==n[0]?e.key(...n):"")),o=t.computed((()=>r.value?i.getResponseMeta(e,...n,s.value):null)),a=t.ref(void 0),c=()=>{if(null===n[0])return;const t=o.value;if(!t)return;const s=t.expiryStatus===R.Invalid;Date.now()<=t.expiresAt&&!s||(a.value=i.fetch(e,...n))};return c(),t.watch((()=>{const e=o.value;return e?[e.expiresAt,e.expiryStatus,s.value.lastReset,r.value]:[r.value]}),(()=>{c()})),a},e.useLive=async function(e,...t){return Re(e,...t),Oe(e,...t)},e.useLoading=function(e){const n=t.ref(!1),s=t.ref(void 0),i=t.ref(!0);return t.onUnmounted((()=>{i.value=!1})),[async(...t)=>{let r;n.value=!0,s.value=void 0;try{r=await e(...t)}catch(e){s.value=e}finally{i.value&&(n.value=!1)}return r},n,s]},e.useQuery=function(e,...n){const s=Me(),i=Se(),r=t.computed((()=>i.getQueryMeta(e,...n,s.value)));return t.watch((()=>r.value.data),((e,t,n)=>{const s=r.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>r.value.data))},e.useSubscription=Re,e.useSuspense=Oe}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VDC={},e.Vue)}(this,(function(e,t){"use strict";class n{constructor(){this.localCache=new Map}getEntity(e,t,n,s){const i=t.key;this.localCache.has(i)||this.localCache.set(i,new Map);const r=this.localCache.get(i);return r.get(e)||s(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}}const s=Symbol("INVALID"),i={};function r(e){return null!==e&&void 0!==e.pk}const a=e=>e[0],o=e=>void 0!==e&&"symbol"!=typeof e,c=(e,t,n,s,i,r)=>{e=a(e);const o=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return o.map((t=>r(e,t,n,s,i)))},l=(e,t,n,s)=>(e=a(e),t.map?t.map((t=>s(e,t))).filter(o):t);function u(){}function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},h.apply(null,arguments)}const d=(e,t,n,s,i,r)=>{const a=h({},t);return Object.keys(e).forEach((n=>{const s=e[n],o=r(s,t[n],t,n,i);void 0===o?delete a[n]:a[n]=o})),a},p=(e,t,n,i)=>{if(function(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}(t))return function(e,t,n,i){let r=!1;const a=Object.keys(e).reduce(((t,n)=>{const s=`${n}`,a=i(e[s],t.get(s));return"symbol"==typeof a&&(r=!0),t.has(s)?t.set(s,a):t}),t);return r?s:a}(e,t,0,i);const r=h({},t);let a=!1;return Object.keys(e).forEach((t=>{const n=i(e[t],r[t]);void 0!==r[t]&&(r[t]=n),"symbol"==typeof n&&(a=!0)})),a?s:r};function f(e,t,n,s){const i={};for(const r of Object.keys(e))i[r]=n(e[r],t,s);return i}const y=(e,t,n,s)=>function(r,a){const o="object"!=typeof a,c=o?e({key:r.key,pk:a}):a;if("symbol"==typeof c)return r.denormalize(c,n,s);if(void 0===c&&o&&""!==a&&"undefined"!==a)return t.getEntity(a,r,i,(e=>{e.set(a,void 0)}));if("object"!=typeof c||null===c)return c;let l=o?a:r.pk(c,void 0,void 0,n);return void 0===l||""===l||"undefined"===l?function(e){const t=new Map;return e(t),t.get("")}((e=>g(r,c,"",e,n,s))):("string"!=typeof l&&(l=`${l}`),t.getEntity(l,r,c,(e=>g(r,c,l,e,n,s))))};function g(e,t,n,i,r,a){const o=e.createIfValid(t);void 0===o?i.set(n,s):(i.set(n,o),i.set(n,e.denormalize(o,r,a)))}const v=(e,t,n)=>{const s=y(e,t,n,i);function i(e,t){if(!e)return t;if(null==t)return t;if("function"==typeof e.denormalize)return r(e)?s(e,t):e.denormalize(t,n,i);if("function"==typeof e)return e(t);if("object"==typeof e){return(Array.isArray(e)?l:p)(e,t,n,i)}return t}return(e,n)=>{const s=Object(n)===n&&Object(e)===e;return t.getResults(n,s,(()=>i(e,n)))}};class m{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,n=[{path:[""],entity:e}];return[{INVALID:s,getIndex(...e){const s=t.getIndex(...e);return n.push({path:e,entity:s}),t.getIndexEnd(s,e[2])},getEntity(...e){const s=t.getEntity(...e);return n.push({path:e,entity:s}),s},getEntities(e){const s=t.getEntitiesObject(e);return n.push({path:[e],entity:s}),t.getEntities(e)}},n]}}class E extends m{constructor(e){super(e)}getEntitiesObject(e){return this.entities[e]}getEntities(e){const t=this.entities[e];if(void 0!==t)return{keys:()=>Object.keys(t),entries:()=>Object.entries(t)}}getEntity(e,t){var n;return null==(n=this.entities[e])?void 0:n[t]}getIndex(e,t){var n;return null==(n=this.indexes[e])?void 0:n[t]}getIndexEnd(e,t){return null==e?void 0:e[t]}}const w={QueryDelegate:E,getEntities:e=>({key:t,pk:n})=>{var s;return null==(s=e[t])?void 0:s[n]}};class x{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return b;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return b}return[n.value,n.journey]}set(e,t){if(e.length<1)throw new I;let n=this;for(const{path:t,entity:s}of e){let e=n.next.get(s);e||(e=new k,n.next.set(null!=s?s:i,e)),n.nextPath=t,n=e}n.nextPath=void 0,n.value=t,n.journey=e.map((e=>e.path))}}const b=[void 0,void 0];class k{constructor(){this.next=new WeakMap,this.nextPath=void 0,this.value=void 0,this.journey=[]}}class I extends Error{constructor(...e){super(...e),this.message="Keys must include at least one member"}}class L extends E{constructor(e,t){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.meta=t,this.checkLoop=function(){const e=new Map;return function(t,n,s){e.has(t)||e.set(t,new Map);const i=e.get(t);i.has(n)||i.set(n,[]);const r=i.get(n);return!!r.some((e=>e===s))||(r.push(s),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){return this.newEntities.has(e)||(this.newEntities.set(e,new Map),this.entities[e]=h({},this.entities[e]),this.entitiesMeta[e]=h({},this.entitiesMeta[e])),this.newEntities.get(e)}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]=h({},this.indexes[e])),this.newIndexes.get(e)}mergeEntity(e,t,n){const s=e.key;let i=n,r=this.meta,a=this.getNewEntity(s,t);if(a)i=e.merge(a,n);else if(a=this.getEntity(s,t),a){const o=this.getMeta(s,t);i=e.mergeWithStore(o,r,a,n),r=e.mergeMetaWithStore(o,r,a,n)}this.setEntity(e,t,i,r)}setEntity(e,t,n,i=this.meta){const r=e.key,a=this.getNewEntities(r),o=!a.has(t);a.set(t,n),e.indexes&&function(e,t,n,i,r,a){for(const o of t){n.has(o)||n.set(o,i[o]={});const t=n.get(o);a[e]&&delete t[a[e][o]],a&&a[e]&&a[e][o]!==r[o]&&(t[a[e][o]]=s),o in r&&(t[r[o]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],n,this.entities[r]),this._setEntity(r,t,n),o&&this._setMeta(r,t,i)}invalidate({key:e},t){this.setEntity({key:e},t,s)}_setEntity(e,t,n){this.entities[e][t]=n}_setMeta(e,t,n){this.entitiesMeta[e][t]=n}getMeta(e,t){return this.entitiesMeta[e][t]}}const S=(e,t,n=[],{entities:s,indexes:i,entitiesMeta:r}=A,a={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:s,indexes:i,entitiesMeta:r};const o=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(e);if(null===t||typeof t!==o&&(void 0===e.key||void 0!==e.pk||"string"!=typeof t))throw new Error(`Unexpected input given to normalize. Expected type to be "${o}", found "${null===t?"null":typeof t}".`);const l={result:"",entities:h({},s),indexes:h({},i),entitiesMeta:h({},r)},u=(e=>{const t=(n,s,i,r,a)=>s&&n?n.normalize&&"function"==typeof n.normalize?"object"!=typeof s?n.pk?`${s}`:s:n.normalize(s,i,r,a,t,e):"object"!=typeof s||"object"!=typeof n?s:(Array.isArray(n)?c:d)(n,s,i,r,a,t):s;return t})(new L(l,a));return l.result=u(e,t,t,void 0,n),l};const A={entities:{},indexes:{},entitiesMeta:{}};class M{constructor(e,t,n){this.dependencies=[],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._getEntity=e,this._getCache=t,this._resultCache=n}getEntity(e,t,n,s){const i=t.key,{localCacheKey:r,cycleCacheKey:a}=this.getCacheKey(i);if(r.get(e))a.has(e)?this.cycleIndex=a.get(e):this.dependencies.push({path:{key:i,pk:e},entity:n});else{const o=this._getCache(e,t),[c,l]=o.get(n,this._getEntity);if(l)return r.set(e,c.value),this.dependencies.push(...c.dependencies),c.value;{const t=this.dependencies.length;a.set(e,t),this.dependencies.push({path:{key:i,pk:e},entity:n}),s(r),a.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),l={dependencies:c,value:r.get(e)};o.set(c,l),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getCacheKey(e){this.localCache.has(e)||this.localCache.set(e,new Map),this.cycleCache.has(e)||this.cycleCache.set(e,new Map);return{localCacheKey:this.localCache.get(e),cycleCacheKey:this.cycleCache.get(e)}}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[s,i]=this._resultCache.get(e,this._getEntity);return void 0===i?(s=n(),i=this.paths(),this.dependencies.unshift({path:{key:"",pk:""},entity:e}),this._resultCache.set(this.dependencies,s)):i.shift(),{data:s,paths:i}}paths(){return this.dependencies.map((e=>e.path))}}function R(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(R))}class O{constructor(e=w){var t;this.endpoints=new x,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var s;const i=n.key,r=null!=(s=n.cacheWith)?s:n;t.has(i)||t.set(i,new Map);const a=t.get(i);a.has(e)||a.set(e,new WeakMap);const o=a.get(e);let c=o.get(r);return c||(c=new x,o.set(r,c)),c})}denormalize(e,t,n,s=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const i=this.policy.getEntities(n);return v(i,new M(i,this._getCache,this.endpoints),s)(e,t)}query(e,t,n,s=JSON.stringify(t)){const i=this.buildQueryKey(e,t,n,s);return i?this.denormalize(e,i,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,s=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;this.queryKeys.get(s)||this.queryKeys.set(s,new x);const i=this.queryKeys.get(s),r=new this.policy.QueryDelegate(n);let[a,o]=i.get(e,(c=r,e=>c[["","getEntitiesObject","getEntity","getIndex"][e.length]](...e)));var c;if(!o){const[n,s]=r.tracked(e);a=function(e){return function t(n,s){return function(e){return!!e&&"function"==typeof e.queryKey}(n)?n.queryKey(s,t,e):"object"==typeof n&&n?(Array.isArray(n)?u:f)(n,s,t,e):n}}(n)(e,t),i.set(s,a)}return a}}var C={Invalid:1,InvalidIfStale:2,Valid:3};function P(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const _="rdc/fetch",j="rdc/set",D="rdc/setresponse",T="rdc/optimistic",q="rdc/reset",N="rdc/subscribe",K="rdc/unsubscribe",V="rdc/invalidate",H="rdc/invalidateall",z="rdc/expireall",F="rdc/gc",U=_,B=j,Y=D,Q=T,$=q,W=N,X=K,J=V,G=H,Z=z,ee=F;var te=Object.freeze({__proto__:null,EXPIREALL:z,EXPIREALL_TYPE:Z,FETCH:_,FETCH_TYPE:U,GC:F,GC_TYPE:ee,INVALIDATE:V,INVALIDATEALL:H,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:J,OPTIMISTIC:T,OPTIMISTIC_TYPE:Q,RESET:q,RESET_TYPE:$,SET:j,SET_RESPONSE:D,SET_RESPONSE_TYPE:Y,SET_TYPE:B,SUBSCRIBE:N,SUBSCRIBE_TYPE:W,UNSUBSCRIBE:K,UNSUBSCRIBE_TYPE:X});function ne(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const a=(n=t.endpoint,s=t.args,i=t.meta.fetchedAt,{type:T,key:n.key(...s),args:s,endpoint:n,meta:P(null!=(r=n.dataExpiryLength)?r:6e4,i)});return h({},e,{optimistic:[...e.optimistic,a]})}var n,s,i,r;return e}class se extends Error{}function ie(e,t,n){return"AbortError"===n.name?h({},e,{optimistic:re(e,t)}):h({},e,{meta:h({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,error:n,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(n)}}),optimistic:re(e,t)})}function re(e,t){return e.optimistic.filter((e=>e.key!==t.key||(e.type===T?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function ae(e){return function(t,n){switch(t||(t=oe),n.type){case F:return n.entities.forEach((({key:e,pk:n})=>{var s,i;null==(s=t.entities[e])||delete s[n],null==(i=t.entitiesMeta[e])||delete i[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case _:return ne(t,n);case T:case D:return function(e,t,n){if(t.error)return ie(e,t,t.response);try{var s;let i;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{i=t.endpoint.getOptimisticResponse.call(t.endpoint,n.snapshot(e,t.meta.fetchedAt),...t.args)}catch(t){if(t.constructor===se)return e;throw t}}else i=t.response;const{result:r,entities:a,indexes:o,entitiesMeta:c}=S(t.endpoint.schema,i,t.args,e,t.meta),l=h({},e.endpoints,{[t.key]:r});try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{l[t]=e[t](l[t])}))}}catch(e){console.error(`The following error occured during Endpoint.update() for ${t.key}`),console.error(e)}return{entities:a,endpoints:l,indexes:o,meta:h({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(s=e.meta[t.key])?void 0:s.expiresAt}}),entitiesMeta:c,optimistic:re(e,t),lastReset:e.lastReset}}catch(n){return"object"==typeof n&&(n.message=`Error processing ${t.key}\n\nFull Schema: ${JSON.stringify(t.endpoint.schema,void 0,2)}\n\nError:\n${n.message}`,"response"in t&&(n.response=t.response),n.status=400),ie(e,t,n)}}(t,n,e);case j:return function(e,t,n){let s;if("function"==typeof t.value){const i=n.get(t.schema,...t.args,e);if(void 0===i)return e;s=t.value(i)}else s=t.value;try{const{entities:n,indexes:i,entitiesMeta:r}=S(t.schema,s,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:i,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case H:case V:return function(e,t){const n=h({},e.endpoints),s=h({},e.meta),i=e=>{delete n[e];const t=h({},s[e],{expiresAt:0,invalidated:!0});delete t.error,s[e]=t};return t.type===V?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),h({},e,{endpoints:n,meta:s})}(t,n);case z:return function(e,t){const n=h({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=h({},n[e],{expiresAt:1}))})),h({},e,{meta:n})}(t,n);case q:return h({},oe,{lastReset:n.date});default:return t}}}const oe={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};const ce="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function le(e,{args:t,fetchedAt:n,response:s,error:i=!1}){var r,a;const o=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(a=e.dataExpiryLength)?a:6e4;return{type:D,key:e.key(...t),response:s,args:t.map(ce),endpoint:e,meta:P(o,n),error:i}}class ue{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function he(e,t){return e.meta[t]}const de=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},pe=()=>oe;class fe{constructor({dispatch:e=de,getState:t=pe,memo:s=new O,gcPolicy:i=new ue}={}){this.fetch=(e,...t)=>{const s=function(e,{args:t}){let n=0,s=0;const i=new Promise(((e,t)=>{[n,s]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:s,promise:i};return{type:_,key:e.key(...t),args:t,endpoint:e,meta:r}}(e,{args:t});return this.dispatch(s),e.schema?s.meta.promise.then((s=>function(e,t,s,i=[]){return void 0===e||void 0===t?t:v(w.getEntities(s),new n,i)(e,t).data}(e.schema,s,{},t))):s.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:s,expiryStatus:i}=this.getResponseMeta(e,...t,this.getState());return i!==C.Invalid&&Date.now()<=s?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:V,key:e.key(...t)}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:H,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:z,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:q,date:Date.now()}),this.setResponse=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(s)},this.setError=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(s)},this.resolve=(e,t)=>this.dispatch(le(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:K,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new ge(this,e,t),this._dispatch=e,this.getState=t,this.memo=s,this.gcPolicy=i}set dispatch(e){this._dispatch=e}get dispatch(){return this._dispatch}bindMiddleware({dispatch:e,getState:t}){this._dispatch=e,this.getState=t}set(e,...t){const n=t[t.length-1],s=function(e,{args:t,fetchedAt:n,value:s}){return{type:j,value:s,args:t.map(ce),schema:e,meta:P(6e4,n)}}(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(s)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],s=t.slice(0,t.length-1),i=e.key(...s),r=he(n,i);return void 0===n.endpoints[i]||"soft"!==(null==r?void 0:r.errorPolicy)?null==r?void 0:r.error:void 0}getResponse(e,...t){return this.getResponseMeta(e,...t)}getResponseMeta(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ce),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",a=i?n.endpoints[r]:void 0,o=e.schema,c=he(n,r);let l=null==c?void 0:c.expiresAt;const u=void 0===a&&void 0!==o,h=u?this.memo.buildQueryKey(o,s,n,r):a;if(!i)return{data:h,expiryStatus:C.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(u)d=!R(h);else if(!o||!ye(o))return{data:a,expiryStatus:this.getExpiryStatus(!a,!!e.invalidIfStale,c),expiresAt:l||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(o,h,n.entities,s);return l||(l=d?1:function(e,t){let n=1/0;for(const{key:i,pk:r}of e){var s;const e=null==(s=t[i])||null==(s=s[r])?void 0:s.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:l,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ce),{data:i}=this.memo.query(e,s,n);return"symbol"==typeof i?void 0:i}getQueryMeta(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(ce),{data:i,paths:r}=this.memo.query(e,s,n);return{data:"symbol"==typeof i?void 0:i,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?C.Invalid:e||t?C.InvalidIfStale:C.Valid}}function ye(e){if(r(e))return!0;if(Array.isArray(e))return 0!==e.length&&ye(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?ye(t):Object.values(t).some((e=>ye(e)))}return!1}class ge{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=ge.abort,this.state=t,this.controller=e,this.fetchedAt=n}getResponse(e,...t){return this.controller.getResponse(e,...t,this.state)}getResponseMeta(e,...t){return this.controller.getResponseMeta(e,...t,this.state)}getError(e,...t){return this.controller.getError(e,...t,this.state)}get(e,...t){return this.controller.get(e,...t,this.state)}getQueryMeta(e,...t){return this.controller.getQueryMeta(e,...t,this.state)}}ge.abort=new se;class ve extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class me{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new fe,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case _:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case D:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const s=null==(t=e.getState().meta[n.key])?void 0:t.error;s?this.handleSet(le(n.endpoint,{args:n.args,response:s,fetchedAt:n.meta.fetchedAt,error:!0})):this.handleSet(n)}}));case q:{const e=Array.from(this.fetching.values());return this.clearAll(),t(n).then((()=>{for(const{reject:t}of e)t(new ve)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===_&&this.fetching.has(e.key)}allSettled(){if(this.fetching.size)return Promise.allSettled(this.fetching.values().map((({promise:e})=>e)))}clearAll(){for(const e of this.fetching.keys())this.clear(e)}clear(e){this.fetching.has(e)&&(this.fetching.get(e).promise.catch((()=>{})),this.fetching.delete(e))}getLastReset(){return this.cleanupDate?this.cleanupDate:this.controller.getState().lastReset}handleFetch(e){const{resolve:t,reject:n,fetchedAt:s}=e.meta,i=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return i||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s}),t})).catch((t=>{const n=this.getLastReset();throw s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s,error:!0}),t})),r};return i?this.throttle(e.key,r,s).then((e=>t(e))).catch((e=>n(e))):r().catch((()=>{}))}handleSet(e){if(this.fetching.has(e.key)){const{reject:t,resolve:n}=this.fetching.get(e.key);e.error?t(e.response):n(e.response),this.clear(e.key)}}throttle(e,t,n){const s=this.getLastReset();let i=this.fetching.get(e);return i&&i.fetchedAt>s||(i=function(e){const t={fetchedAt:e};return t.promise=new Promise(((e,n)=>{t.resolve=e,t.reject=n})),t}(n),this.fetching.set(e,i),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),i.promise}idleCallback(e,t){e()}}class Ee{isOnline(){return void 0===navigator.onLine||navigator.onLine}addOnlineListener(e){addEventListener("online",e)}removeOnlineListener(e){removeEventListener("online",e)}addOfflineListener(e){addEventListener("offline",e)}removeOfflineListener(e){removeEventListener("offline",e)}}class we{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}e.DefaultConnectionListener=void 0,"undefined"!=typeof navigator&&"function"==typeof addEventListener?e.DefaultConnectionListener=Ee:e.DefaultConnectionListener=we;class xe{constructor(t,n,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===t.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=t.endpoint,this.frequency=t.endpoint.pollFrequency,this.args=t.args,this.key=t.key,this.frequencyHistogram.set(this.frequency,1),this.controller=n,this.connectionListener=s||new e.DefaultConnectionListener,this.connectionListener.isOnline()?this.onlineListener():this.offlineListener()}add(e){void 0!==e&&(this.frequencyHistogram.has(e)?this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)+1):(this.frequencyHistogram.set(e,1),e<this.frequency&&(this.frequency=e,this.run())))}remove(e){if(void 0===e)return!1;if(this.frequencyHistogram.has(e)&&(this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)-1),this.frequencyHistogram.get(e)<1)){if(this.frequencyHistogram.delete(e),0===this.frequencyHistogram.size)return this.cleanup(),!0;e<=this.frequency&&(this.frequency=Math.min(...this.frequencyHistogram.keys()),this.run())}return!1}cleanup(){this.intervalId&&(clearInterval(this.intervalId),delete this.intervalId),this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.startId&&(clearTimeout(this.startId),delete this.startId),this.connectionListener.removeOnlineListener(this.onlineListener),this.connectionListener.removeOfflineListener(this.offlineListener)}update(){const e=this.endpoint,t=function(...t){return e.call(this,...t)};Object.assign(t,this.endpoint),t.dataExpiryLength=this.frequency/2,t.errorExpiryLength=this.frequency/10,t.errorPolicy=()=>"soft",t.key=()=>this.key,this.controller.fetch(t,...this.args).catch((()=>null))}run(){this.startId||(this.intervalId&&(this.lastIntervalId=this.intervalId),this.intervalId=setInterval((()=>{this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.intervalId&&this.update()}),this.frequency))}lastFetchTime(){var e,t;return null!=(e=null==(t=this.controller.getState().meta[this.key])?void 0:t.date)?e:0}}class be{constructor(e){this.subscriptions={},this.controller=new fe,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case N:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case K:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}}),this.Subscription=e}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].add(n)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].remove(n)&&delete this.subscriptions[t]}}}let ke={};class Ie{constructor(e,t){this.started=!1,this.actions=[],this.maxBufferLength=100,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(h({},ke,e)),null!=e&&e.maxAge&&(this.maxBufferLength=2*e.maxAge),t&&(this.skipLogging=t)}handleAction(e,t){this.started?this.devTools.send(e,t):(this.actions.length>this.maxBufferLength&&(this.actions=this.actions.slice(this.maxBufferLength/2)),this.actions.push([e,t]))}init(e){}cleanup(){}}Ie.prototype.middleware=()=>e=>t=>e(t);const Le=Symbol("DataClientState"),Se=Symbol("DataClientController"),Ae=t.shallowRef(oe);function Me(){const e=t.inject(Se,null);return e||new fe}function Re(){const e=t.inject(Le,null);return e||Ae}async function Oe(e,...n){const s=Re(),i=Me(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=async()=>{if(!a.value)return;const t=o.value,n=t.expiryStatus===C.Invalid;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value)};return t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>c())),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>null==s?void 0:s()))}),{immediate:!0}),await c(),t.readonly(t.computed((()=>o.value.data)))}function Ce(e,...n){const s=Me(),i=t.computed((()=>n.map((e=>t.unref(e))))),r=t.computed((()=>null===i.value[0]?"":e.key(...i.value)));t.watch(r,((t,n,a)=>{if(!r.value)return;const o=i.value;s.subscribe(e,...o),a((()=>{s.unsubscribe(e,...o)}))}),{immediate:!0})}let Pe=(e={})=>{const{networkManager:t,subscriptionManager:n=xe}=e;return null===n?[_e(me,null!=t?t:{})]:[_e(me,null!=t?t:{}),_e(be,n)]};function _e(e,t){return t instanceof e?t:new e(t)}function je(e={}){var n,s;const{Controller:i=fe,gcPolicy:r,app:a}=e,o=new i({gcPolicy:r}),c=null!=(n=e.managers)?n:Pe(),l=null!=(s=e.initialState)?s:oe,u=function(e,t,n){return()=>(e.forEach((e=>{null==e.init||e.init(n)})),t.gcPolicy.init(t),()=>{e.forEach((e=>{e.cleanup()})),t.gcPolicy.cleanup()})}(c,o,l),h=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),s=>(0===n&&t.bindMiddleware(s),e.middleware(t)))))}(c,o),d=ae(o),p=t.shallowRef(l),f=t.shallowRef(x(l));let y=null;const g=()=>p.value,v=h.map((e=>e({getState:g,dispatch:e=>m(e)}))),m=(E=v,e=>E.reduceRight(((e,t)=>t(e)),e))((async e=>{const t=new Promise((e=>{y=e}));return await(async e=>{const t=d(p.value,e);if(p.value=t,f.value=x(t),y){const e=y;y=null,e()}})(e),t}));var E;let w;o.bindMiddleware({getState:g,dispatch:e=>m(e)});return a?(a.provide(Le,f),a.provide(Se,o)):(t.provide(Le,f),t.provide(Se,o)),{controller:o,stateRef:f,start:()=>{w=u()},stop:()=>{w&&w()}};function x(e){return e.optimistic.reduce(d,e)}}const De={install(e,t={}){const n=je(h({},t,{app:e}));return e.config.globalProperties.$dataClient=n.controller,n.start(),e.onUnmount((()=>{n.stop()})),n}};e.Controller=fe,e.DataClientPlugin=De,e.DevToolsManager=Ie,e.ExpiryStatus=C,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===D&&n.error&&this.shouldLogout(n.response)&&this.handleLogout(e)},e&&(this.handleLogout=e),t&&(this.shouldLogout=t)}cleanup(){}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=me,e.PollingSubscription=xe,e.SubscriptionManager=be,e.actionTypes=te,e.createDataClient=je,e.getDefaultManagers=Pe,e.useCache=function(e,...n){const s=Re(),i=Me(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===C.Invalid)),l=t.computed((()=>(Date.now()>o.value.expiresAt||c.value)&&a.value)),u=t.computed((()=>o.value.expiryStatus!==C.Valid&&l.value));return t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>{if(u.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,h({},s.value,{entities:{}})).data}return o.value.data}))},e.useController=Me,e.useDLE=function(e,...n){const s=Re(),i=Me(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===C.Invalid)),l=t.computed((()=>!(!(Date.now()>o.value.expiresAt||c.value)||!a.value))),u=t.computed((()=>!(o.value.expiryStatus===C.Valid||!l.value)));t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(async()=>{if(!a.value)return;const t=o.value,n=c.value;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value).catch((()=>{}))}),{immediate:!0}),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0});const d=t.computed((()=>{if(u.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,h({},s.value,{entities:{}})).data}return o.value.data})),p=t.computed((()=>i.getError(e,...r.value,s.value)));return t.markRaw({data:d,loading:u,error:p})},e.useDebounce=function(e,n,s=!0){const i=t.ref("object"==typeof e&&null!==e&&"value"in e?e.value:e),r=t.ref(!1);let a=null;const o=()=>{null!==a&&(clearTimeout(a),a=null)};return t.watch([()=>"object"==typeof e&&null!==e&&"value"in e?e.value:e,()=>"object"==typeof s&&null!==s&&"value"in s?s.value:s,()=>n],(([e,t])=>{o(),t?(r.value=!0,a=setTimeout((()=>{i.value=e,r.value=!1,a=null}),n)):r.value=!1}),{immediate:!1}),t.onUnmounted((()=>{o()})),[i,r]},e.useFetch=function(e,...n){const s=Re(),i=Me(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.ref(void 0),l=()=>{if(!a.value)return;const t=o.value,n=t.expiryStatus===C.Invalid;Date.now()<=t.expiresAt&&!n||(c.value=i.fetch(e,...r.value))};return l(),t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>{l()})),c},e.useLive=async function(e,...t){return Ce(e,...t),Oe(e,...t)},e.useLoading=function(e){const n=t.ref(!1),s=t.ref(void 0),i=t.ref(!0);return t.onUnmounted((()=>{i.value=!1})),[async(...t)=>{let r;n.value=!0,s.value=void 0;try{r=await e(...t)}catch(e){s.value=e}finally{i.value&&(n.value=!1)}return r},n,s]},e.useQuery=function(e,...n){const s=Re(),i=Me(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>i.getQueryMeta(e,...r.value,s.value)));return t.watch((()=>a.value.data),((e,t,n)=>{const s=a.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>a.value.data))},e.useSubscription=Ce,e.useSuspense=Oe}));
|
package/lib/consumers/index.d.ts
CHANGED
|
@@ -5,5 +5,7 @@ export { default as useLive } from './useLive.js';
|
|
|
5
5
|
export { default as useLoading } from './useLoading.js';
|
|
6
6
|
export { default as useDebounce } from './useDebounce.js';
|
|
7
7
|
export { default as useFetch } from './useFetch.js';
|
|
8
|
+
export { default as useCache } from './useCache.js';
|
|
9
|
+
export { default as useDLE } from './useDLE.js';
|
|
8
10
|
export { useController as useController } from '../context.js';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/consumers/index.js
CHANGED
|
@@ -5,5 +5,7 @@ export { default as useLive } from './useLive.js';
|
|
|
5
5
|
export { default as useLoading } from './useLoading.js';
|
|
6
6
|
export { default as useDebounce } from './useDebounce.js';
|
|
7
7
|
export { default as useFetch } from './useFetch.js';
|
|
8
|
+
export { default as useCache } from './useCache.js';
|
|
9
|
+
export { default as useDLE } from './useDLE.js';
|
|
8
10
|
export { useController } from '../context.js';
|
|
9
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJkZWZhdWx0IiwidXNlU3VzcGVuc2UiLCJ1c2VTdWJzY3JpcHRpb24iLCJ1c2VRdWVyeSIsInVzZUxpdmUiLCJ1c2VMb2FkaW5nIiwidXNlRGVib3VuY2UiLCJ1c2VGZXRjaCIsInVzZUNhY2hlIiwidXNlRExFIiwidXNlQ29udHJvbGxlciJdLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb25zdW1lcnMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHsgZGVmYXVsdCBhcyB1c2VTdXNwZW5zZSB9IGZyb20gJy4vdXNlU3VzcGVuc2UuanMnO1xuZXhwb3J0IHsgZGVmYXVsdCBhcyB1c2VTdWJzY3JpcHRpb24gfSBmcm9tICcuL3VzZVN1YnNjcmlwdGlvbi5qcyc7XG5leHBvcnQgeyBkZWZhdWx0IGFzIHVzZVF1ZXJ5IH0gZnJvbSAnLi91c2VRdWVyeS5qcyc7XG5leHBvcnQgeyBkZWZhdWx0IGFzIHVzZUxpdmUgfSBmcm9tICcuL3VzZUxpdmUuanMnO1xuZXhwb3J0IHsgZGVmYXVsdCBhcyB1c2VMb2FkaW5nIH0gZnJvbSAnLi91c2VMb2FkaW5nLmpzJztcbmV4cG9ydCB7IGRlZmF1bHQgYXMgdXNlRGVib3VuY2UgfSBmcm9tICcuL3VzZURlYm91bmNlLmpzJztcbmV4cG9ydCB7IGRlZmF1bHQgYXMgdXNlRmV0Y2ggfSBmcm9tICcuL3VzZUZldGNoLmpzJztcbmV4cG9ydCB7IGRlZmF1bHQgYXMgdXNlQ2FjaGUgfSBmcm9tICcuL3VzZUNhY2hlLmpzJztcbmV4cG9ydCB7IGRlZmF1bHQgYXMgdXNlRExFIH0gZnJvbSAnLi91c2VETEUuanMnO1xuZXhwb3J0IHsgdXNlQ29udHJvbGxlciBhcyB1c2VDb250cm9sbGVyIH0gZnJvbSAnLi4vY29udGV4dC5qcyc7XG4iXSwibWFwcGluZ3MiOiJBQUFBLFNBQVNBLE9BQU8sSUFBSUMsV0FBVyxRQUFRLGtCQUFrQjtBQUN6RCxTQUFTRCxPQUFPLElBQUlFLGVBQWUsUUFBUSxzQkFBc0I7QUFDakUsU0FBU0YsT0FBTyxJQUFJRyxRQUFRLFFBQVEsZUFBZTtBQUNuRCxTQUFTSCxPQUFPLElBQUlJLE9BQU8sUUFBUSxjQUFjO0FBQ2pELFNBQVNKLE9BQU8sSUFBSUssVUFBVSxRQUFRLGlCQUFpQjtBQUN2RCxTQUFTTCxPQUFPLElBQUlNLFdBQVcsUUFBUSxrQkFBa0I7QUFDekQsU0FBU04sT0FBTyxJQUFJTyxRQUFRLFFBQVEsZUFBZTtBQUNuRCxTQUFTUCxPQUFPLElBQUlRLFFBQVEsUUFBUSxlQUFlO0FBQ25ELFNBQVNSLE9BQU8sSUFBSVMsTUFBTSxRQUFRLGFBQWE7QUFDL0MsU0FBU0MsYUFBOEIsUUFBUSxlQUFlIiwiaWdub3JlTGlzdCI6W119
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EndpointInterface, DenormalizeNullable, Schema, FetchFunction, ResolveType } from '@data-client/core';
|
|
2
|
+
import { type ComputedRef } from 'vue';
|
|
3
|
+
import type { MaybeRefsOrGetters, MaybeRefsOrGettersNullable } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Read an Endpoint's response if it is ready.
|
|
6
|
+
*
|
|
7
|
+
* `useCache` guarantees referential equality globally.
|
|
8
|
+
* @see https://dataclient.io/docs/api/useCache
|
|
9
|
+
*/
|
|
10
|
+
export default function useCache<E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, undefined | boolean>, 'key' | 'schema' | 'invalidIfStale'>>(endpoint: E, ...args: MaybeRefsOrGetters<Parameters<E['key']>>): ComputedRef<E['schema'] extends undefined | null ? E extends (...args: any) => any ? ResolveType<E> | undefined : any : DenormalizeNullable<E['schema']>>;
|
|
11
|
+
export default function useCache<E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, undefined | boolean>, 'key' | 'schema' | 'invalidIfStale'>>(endpoint: E, ...args: MaybeRefsOrGettersNullable<Parameters<E['key']>> | readonly [null]): ComputedRef<E['schema'] extends undefined | null ? E extends (...args: any) => any ? ResolveType<E> | undefined : any : DenormalizeNullable<E['schema']>>;
|
|
12
|
+
//# sourceMappingURL=useCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCache.d.ts","sourceRoot":"","sources":["../../src/consumers/useCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,MAAM,EACN,aAAa,EACb,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAG/D,OAAO,KAAK,EACV,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,CAAC,SAAS,IAAI,CACZ,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,EACzE,KAAK,GAAG,QAAQ,GAAG,gBAAgB,CACpC,EAED,QAAQ,EAAE,CAAC,EACX,GAAG,IAAI,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAChD,WAAW,CACZ,CAAC,CAAC,QAAQ,CAAC,SAAS,SAAS,GAAG,IAAI,GAClC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GAC7B,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,GAC1B,GAAG,GACL,mBAAmB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CACnC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,CAAC,SAAS,IAAI,CACZ,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,EACzE,KAAK,GAAG,QAAQ,GAAG,gBAAgB,CACpC,EAED,QAAQ,EAAE,CAAC,EACX,GAAG,IAAI,EAAE,0BAA0B,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAC1E,WAAW,CACZ,CAAC,CAAC,QAAQ,CAAC,SAAS,SAAS,GAAG,IAAI,GAClC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GAC7B,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,GAC1B,GAAG,GACL,mBAAmB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CACnC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ExpiryStatus } from '@data-client/core';
|
|
2
|
+
import { computed, unref, watch } from 'vue';
|
|
3
|
+
import { useController, injectState } from '../context.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read an Endpoint's response if it is ready.
|
|
7
|
+
*
|
|
8
|
+
* `useCache` guarantees referential equality globally.
|
|
9
|
+
* @see https://dataclient.io/docs/api/useCache
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default function useCache(endpoint, ...args) {
|
|
13
|
+
const stateRef = injectState();
|
|
14
|
+
const controller = useController();
|
|
15
|
+
|
|
16
|
+
// Track top-level reactive args (Refs are unwrapped). This allows props/refs to trigger updates.
|
|
17
|
+
const resolvedArgs = computed(() => args.map(a => unref(a)));
|
|
18
|
+
|
|
19
|
+
// Compute a key that changes when args change (including reactive props)
|
|
20
|
+
const argsKey = computed(() => resolvedArgs.value[0] !== null ? endpoint.key(...resolvedArgs.value) : '');
|
|
21
|
+
|
|
22
|
+
// Compute response meta reactively so we can respond to store updates
|
|
23
|
+
const responseMeta = computed(() => {
|
|
24
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, stateRef.value);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// If we are hard invalid we must fetch regardless of triggering or staleness
|
|
28
|
+
const forceFetch = computed(() => responseMeta.value.expiryStatus === ExpiryStatus.Invalid);
|
|
29
|
+
|
|
30
|
+
/*********** This block is to ensure results are only filled when they would not suspend **************/
|
|
31
|
+
// This computation reflects the behavior of useSuspense/useFetch
|
|
32
|
+
// It only changes the value when expiry or params change.
|
|
33
|
+
// This way, random unrelated re-renders don't cause the concept of expiry
|
|
34
|
+
// to change
|
|
35
|
+
const expired = computed(() => {
|
|
36
|
+
return (Date.now() > responseMeta.value.expiresAt || forceFetch.value) && argsKey.value;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// fully "valid" data will not suspend/loading even if it is not fresh
|
|
40
|
+
const loading = computed(() => responseMeta.value.expiryStatus !== ExpiryStatus.Valid && expired.value);
|
|
41
|
+
/****************************************************************************************************/
|
|
42
|
+
|
|
43
|
+
// Maintain GC refcounts on data mount/changes
|
|
44
|
+
watch(() => responseMeta.value.data, (_newVal, _oldVal, onCleanup) => {
|
|
45
|
+
const decrement = responseMeta.value.countRef();
|
|
46
|
+
onCleanup(() => decrement());
|
|
47
|
+
}, {
|
|
48
|
+
immediate: true
|
|
49
|
+
});
|
|
50
|
+
return computed(() => {
|
|
51
|
+
// if useSuspense() would suspend, don't include entities from cache
|
|
52
|
+
if (loading.value) {
|
|
53
|
+
if (!endpoint.schema) return undefined;
|
|
54
|
+
// TODO: use getResponse() once it just returns data
|
|
55
|
+
return controller.getResponseMeta(endpoint, ...resolvedArgs.value, {
|
|
56
|
+
...stateRef.value,
|
|
57
|
+
entities: {}
|
|
58
|
+
}).data;
|
|
59
|
+
}
|
|
60
|
+
return responseMeta.value.data;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJFeHBpcnlTdGF0dXMiLCJjb21wdXRlZCIsInVucmVmIiwid2F0Y2giLCJ1c2VDb250cm9sbGVyIiwiaW5qZWN0U3RhdGUiLCJ1c2VDYWNoZSIsImVuZHBvaW50IiwiYXJncyIsInN0YXRlUmVmIiwiY29udHJvbGxlciIsInJlc29sdmVkQXJncyIsIm1hcCIsImEiLCJhcmdzS2V5IiwidmFsdWUiLCJrZXkiLCJyZXNwb25zZU1ldGEiLCJnZXRSZXNwb25zZU1ldGEiLCJmb3JjZUZldGNoIiwiZXhwaXJ5U3RhdHVzIiwiSW52YWxpZCIsImV4cGlyZWQiLCJEYXRlIiwibm93IiwiZXhwaXJlc0F0IiwibG9hZGluZyIsIlZhbGlkIiwiZGF0YSIsIl9uZXdWYWwiLCJfb2xkVmFsIiwib25DbGVhbnVwIiwiZGVjcmVtZW50IiwiY291bnRSZWYiLCJpbW1lZGlhdGUiLCJzY2hlbWEiLCJ1bmRlZmluZWQiLCJlbnRpdGllcyJdLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb25zdW1lcnMvdXNlQ2FjaGUudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHR5cGUge1xuICBFbmRwb2ludEludGVyZmFjZSxcbiAgRGVub3JtYWxpemVOdWxsYWJsZSxcbiAgU2NoZW1hLFxuICBGZXRjaEZ1bmN0aW9uLFxuICBSZXNvbHZlVHlwZSxcbn0gZnJvbSAnQGRhdGEtY2xpZW50L2NvcmUnO1xuaW1wb3J0IHsgRXhwaXJ5U3RhdHVzIH0gZnJvbSAnQGRhdGEtY2xpZW50L2NvcmUnO1xuaW1wb3J0IHsgY29tcHV0ZW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