@data-client/vue 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/index.js +114 -34
- package/dist/index.umd.min.js +1 -1
- package/lib/consumers/useFetch.js +12 -8
- package/lib/consumers/useSuspense.js +38 -13
- package/lib/context.d.ts.map +1 -1
- package/lib/context.js +3 -1
- package/lib/providers/DataClientPlugin.d.ts +22 -0
- package/lib/providers/DataClientPlugin.d.ts.map +1 -0
- package/lib/providers/DataClientPlugin.js +40 -0
- package/lib/providers/{provideDataClient.d.ts → createDataClient.d.ts} +10 -6
- package/lib/providers/createDataClient.d.ts.map +1 -0
- package/lib/providers/createDataClient.js +103 -0
- package/lib/providers/index.d.ts +2 -1
- package/lib/providers/index.d.ts.map +1 -1
- package/lib/providers/index.js +3 -2
- package/lib/test/MockController.d.ts +8 -0
- package/lib/test/MockController.d.ts.map +1 -0
- package/lib/test/MockController.js +125 -0
- package/lib/test/collapseFixture.d.ts +6 -0
- package/lib/test/collapseFixture.d.ts.map +1 -0
- package/lib/test/collapseFixture.js +19 -0
- package/lib/test/createFixtureMap.d.ts +3 -0
- package/lib/test/createFixtureMap.d.ts.map +1 -0
- package/lib/test/createFixtureMap.js +23 -0
- package/lib/test/fixtureTypes.d.ts +99 -0
- package/lib/test/fixtureTypes.d.ts.map +1 -0
- package/lib/test/fixtureTypes.js +2 -0
- package/lib/test/index.d.ts +8 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +7 -0
- package/lib/test/mockState.d.ts +4 -0
- package/lib/test/mockState.d.ts.map +1 -0
- package/lib/test/mockState.js +44 -0
- package/lib/test/renderDataClient.d.ts +40 -0
- package/lib/test/renderDataClient.d.ts.map +1 -0
- package/lib/test/renderDataClient.js +264 -0
- package/package.json +13 -6
- package/src/__tests__/__snapshots__/useQuery.web.ts.snap +126 -0
- package/src/__tests__/__snapshots__/useSubscription.web.ts.snap +7 -0
- package/src/__tests__/integration-garbage-collection.web.ts +155 -0
- package/src/__tests__/useFetch.web.ts +192 -51
- package/src/__tests__/useLive.web.ts +66 -34
- package/src/__tests__/useQuery.web.ts +263 -109
- package/src/__tests__/useSubscription.web.ts +16 -3
- package/src/__tests__/useSuspense.web.ts +141 -70
- package/src/consumers/useFetch.ts +16 -9
- package/src/consumers/useSuspense.ts +37 -15
- package/src/context.ts +2 -0
- package/src/providers/DataClientPlugin.ts +39 -0
- package/src/providers/__tests__/DataClientPlugin.test.ts +387 -0
- package/src/providers/{provideDataClient.ts → createDataClient.ts} +33 -24
- package/src/providers/index.ts +2 -1
- package/src/test/MockController.ts +151 -0
- package/src/test/README.md +245 -0
- package/src/test/collapseFixture.ts +21 -0
- package/src/test/createFixtureMap.ts +26 -0
- package/src/test/fixtureTypes.ts +121 -0
- package/src/test/index.ts +23 -0
- package/src/test/mockState.ts +57 -0
- package/src/test/renderDataClient.ts +316 -0
- package/ts3.4/providers/DataClientPlugin.d.ts +22 -0
- package/ts3.4/providers/createDataClient.d.ts +25 -0
- package/ts3.4/providers/index.d.ts +2 -1
- package/ts3.4/test/MockController.d.ts +8 -0
- package/ts3.4/test/collapseFixture.d.ts +6 -0
- package/ts3.4/test/createFixtureMap.d.ts +6 -0
- package/ts3.4/test/fixtureTypes.d.ts +99 -0
- package/ts3.4/test/index.d.ts +8 -0
- package/ts3.4/test/mockState.d.ts +4 -0
- package/ts3.4/test/renderDataClient.d.ts +40 -0
- package/lib/providers/provideDataClient.d.ts.map +0 -1
- package/lib/providers/provideDataClient.js +0 -94
- package/ts3.4/providers/provideDataClient.d.ts +0 -21
package/README.md
CHANGED
|
@@ -80,19 +80,25 @@ const ArticleResource = resource({
|
|
|
80
80
|
|
|
81
81
|
### Provide the Data Client
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
Install the plugin globally in your main app file for automatic setup across your entire application:
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
-
//
|
|
87
|
-
import {
|
|
86
|
+
// main.ts
|
|
87
|
+
import { createApp } from 'vue';
|
|
88
|
+
import { DataClientPlugin } from '@data-client/vue';
|
|
89
|
+
import App from './App.vue';
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
const app = createApp(App);
|
|
92
|
+
|
|
93
|
+
app.use(DataClientPlugin, {
|
|
90
94
|
// optional overrides
|
|
91
95
|
// managers: getDefaultManagers(),
|
|
92
96
|
// initialState,
|
|
93
97
|
// Controller,
|
|
94
98
|
// gcPolicy,
|
|
95
99
|
});
|
|
100
|
+
|
|
101
|
+
app.mount('#app');
|
|
96
102
|
```
|
|
97
103
|
|
|
98
104
|
### One line [data binding](https://dataclient.io/docs/getting-started/data-dependency)
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const FallbackStateRef = vue.shallowRef(core.initialState);
|
|
|
11
11
|
function useController() {
|
|
12
12
|
const ctrl = vue.inject(ControllerKey, null);
|
|
13
13
|
if (!ctrl) {
|
|
14
|
+
/* istanbul ignore else */
|
|
14
15
|
if (process.env.NODE_ENV !== 'production') {
|
|
15
16
|
console.error('It appears you are trying to use Reactive Data Client (Vue) without a provider.\n' + 'Follow instructions: https://dataclient.io/docs/getting-started/installation#add-provider-at-top-level-component');
|
|
16
17
|
}
|
|
@@ -21,6 +22,7 @@ function useController() {
|
|
|
21
22
|
function injectState() {
|
|
22
23
|
const state = vue.inject(StateKey, null);
|
|
23
24
|
if (!state) {
|
|
25
|
+
/* istanbul ignore else */
|
|
24
26
|
if (process.env.NODE_ENV !== 'production') {
|
|
25
27
|
console.error('It appears you are trying to use Reactive Data Client (Vue) without a provider.\n' + 'Follow instructions: https://dataclient.io/docs/getting-started/installation#add-provider-at-top-level-component');
|
|
26
28
|
}
|
|
@@ -32,27 +34,52 @@ function injectState() {
|
|
|
32
34
|
async function useSuspense(endpoint, ...args) {
|
|
33
35
|
const stateRef = injectState();
|
|
34
36
|
const controller = useController();
|
|
35
|
-
const key = args[0] !== null ? endpoint.key(...args) : '';
|
|
36
|
-
const responseMeta = vue.computed(() => controller.getResponseMeta(endpoint, ...args, stateRef.value));
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
const
|
|
40
|
-
|
|
38
|
+
// Compute a key that changes when args change (including reactive props)
|
|
39
|
+
const argsKey = vue.computed(() => args[0] !== null ? endpoint.key(...args) : '');
|
|
40
|
+
|
|
41
|
+
// Compute response meta reactively so we can respond to store updates
|
|
42
|
+
const responseMeta = vue.computed(() => {
|
|
43
|
+
return argsKey.value ? controller.getResponseMeta(endpoint, ...args, stateRef.value) : null;
|
|
44
|
+
});
|
|
45
|
+
const maybeFetch = async () => {
|
|
46
|
+
const currentKey = argsKey.value;
|
|
47
|
+
if (!currentKey) return;
|
|
48
|
+
const meta = responseMeta.value;
|
|
49
|
+
if (!meta) return;
|
|
50
|
+
const forceFetch = meta.expiryStatus === core.ExpiryStatus.Invalid;
|
|
51
|
+
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
41
52
|
await controller.fetch(endpoint, ...args);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Trigger on initial call
|
|
56
|
+
await maybeFetch();
|
|
57
|
+
|
|
58
|
+
// Watch for changes to key, expiry, or store state that require refetch
|
|
59
|
+
vue.watch(() => {
|
|
60
|
+
const m = responseMeta.value;
|
|
61
|
+
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value] : [argsKey.value];
|
|
62
|
+
}, () => {
|
|
63
|
+
return maybeFetch();
|
|
64
|
+
});
|
|
45
65
|
|
|
46
66
|
// Maintain GC refcounts on data mount/changes
|
|
47
|
-
vue.watch(() =>
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
vue.watch(() => {
|
|
68
|
+
var _responseMeta$value;
|
|
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();
|
|
73
|
+
onCleanup(() => decrement == null ? void 0 : decrement());
|
|
50
74
|
}, {
|
|
51
75
|
immediate: true
|
|
52
76
|
});
|
|
53
77
|
|
|
54
78
|
// Return readonly computed ref - Vue automatically unwraps in templates and reactive contexts
|
|
55
|
-
return vue.readonly(vue.computed(() =>
|
|
79
|
+
return vue.readonly(vue.computed(() => {
|
|
80
|
+
var _responseMeta$value3;
|
|
81
|
+
return (_responseMeta$value3 = responseMeta.value) == null ? void 0 : _responseMeta$value3.data;
|
|
82
|
+
}));
|
|
56
83
|
}
|
|
57
84
|
|
|
58
85
|
/**
|
|
@@ -223,18 +250,22 @@ function useDebounce(value, delay, updatable = true) {
|
|
|
223
250
|
function useFetch(endpoint, ...args) {
|
|
224
251
|
const stateRef = injectState();
|
|
225
252
|
const controller = useController();
|
|
226
|
-
|
|
253
|
+
|
|
254
|
+
// Compute a key that changes when args change (including reactive props)
|
|
255
|
+
const argsKey = vue.computed(() => args[0] !== null ? endpoint.key(...args) : '');
|
|
227
256
|
|
|
228
257
|
// Compute response meta reactively so we can respond to store updates
|
|
229
|
-
const responseMeta = vue.computed(() =>
|
|
230
|
-
|
|
258
|
+
const responseMeta = vue.computed(() => {
|
|
259
|
+
return argsKey.value ? controller.getResponseMeta(endpoint, ...args, stateRef.value) : null;
|
|
260
|
+
});
|
|
261
|
+
const lastPromise = vue.ref(undefined);
|
|
231
262
|
const maybeFetch = () => {
|
|
232
|
-
if (
|
|
263
|
+
if (args[0] === null) return;
|
|
233
264
|
const meta = responseMeta.value;
|
|
234
265
|
if (!meta) return;
|
|
235
266
|
const forceFetch = meta.expiryStatus === core.ExpiryStatus.Invalid;
|
|
236
267
|
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
237
|
-
lastPromise = controller.fetch(endpoint, ...args);
|
|
268
|
+
lastPromise.value = controller.fetch(endpoint, ...args);
|
|
238
269
|
};
|
|
239
270
|
|
|
240
271
|
// Trigger on initial call
|
|
@@ -243,7 +274,7 @@ function useFetch(endpoint, ...args) {
|
|
|
243
274
|
// Also watch for store changes that might require refetch (e.g., invalidation)
|
|
244
275
|
vue.watch(() => {
|
|
245
276
|
const m = responseMeta.value;
|
|
246
|
-
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset] :
|
|
277
|
+
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value] : [argsKey.value];
|
|
247
278
|
}, () => {
|
|
248
279
|
maybeFetch();
|
|
249
280
|
});
|
|
@@ -299,14 +330,15 @@ function constructManager(Mgr, optionOrInstance) {
|
|
|
299
330
|
}
|
|
300
331
|
|
|
301
332
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
333
|
+
* Core provider logic that can be used by both composable and plugin.
|
|
334
|
+
* This function handles the actual setup of the data client without Vue-specific concerns.
|
|
304
335
|
*/
|
|
305
|
-
function
|
|
336
|
+
function createDataClient(options = {}) {
|
|
306
337
|
var _options$managers, _options$initialState;
|
|
307
338
|
const {
|
|
308
339
|
Controller = core.Controller,
|
|
309
|
-
gcPolicy
|
|
340
|
+
gcPolicy,
|
|
341
|
+
app
|
|
310
342
|
} = options;
|
|
311
343
|
|
|
312
344
|
// stable singletons for this provider scope
|
|
@@ -363,30 +395,77 @@ function provideDataClient(options = {}) {
|
|
|
363
395
|
dispatch: a => outerDispatch(a)
|
|
364
396
|
});
|
|
365
397
|
|
|
366
|
-
//
|
|
367
|
-
vue.provide(StateKey, stateRef);
|
|
368
|
-
vue.provide(ControllerKey, controller);
|
|
369
|
-
|
|
370
|
-
// run managers after mount and cleanup on unmount
|
|
398
|
+
// setup lifecycle management
|
|
371
399
|
let cleanup;
|
|
372
|
-
|
|
400
|
+
const start = () => {
|
|
373
401
|
cleanup = mgrEffect();
|
|
374
|
-
}
|
|
375
|
-
|
|
402
|
+
};
|
|
403
|
+
const stop = () => {
|
|
376
404
|
if (cleanup) cleanup();
|
|
377
|
-
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// provide to children using Vue's provide or app.provide
|
|
408
|
+
if (app) {
|
|
409
|
+
// Plugin mode: use app.provide
|
|
410
|
+
app.provide(StateKey, stateRef);
|
|
411
|
+
app.provide(ControllerKey, controller);
|
|
412
|
+
} else {
|
|
413
|
+
// Composable mode: use provide (must be called within setup)
|
|
414
|
+
vue.provide(StateKey, stateRef);
|
|
415
|
+
vue.provide(ControllerKey, controller);
|
|
416
|
+
}
|
|
378
417
|
return {
|
|
379
418
|
controller: controller,
|
|
380
|
-
stateRef
|
|
419
|
+
stateRef,
|
|
420
|
+
start,
|
|
421
|
+
stop
|
|
381
422
|
};
|
|
382
423
|
function computeOptimistic(state) {
|
|
383
|
-
// mirror React
|
|
424
|
+
// mirror React's optimistic overlay
|
|
384
425
|
// reduce over pending optimistic actions to derive the effective state
|
|
385
426
|
// reducer is stable from closure
|
|
386
427
|
return state.optimistic.reduce(reducer, state);
|
|
387
428
|
}
|
|
388
429
|
}
|
|
389
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Vue 3 Plugin for Reactive Data Client
|
|
433
|
+
*
|
|
434
|
+
* Usage:
|
|
435
|
+
* ```ts
|
|
436
|
+
* import { createApp } from 'vue';
|
|
437
|
+
* import { DataClientPlugin } from '@data-client/vue';
|
|
438
|
+
*
|
|
439
|
+
* const app = createApp(App);
|
|
440
|
+
* app.use(DataClientPlugin, {
|
|
441
|
+
* managers: getDefaultManagers(),
|
|
442
|
+
* initialState: customInitialState,
|
|
443
|
+
* });
|
|
444
|
+
* app.mount('#app');
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
const DataClientPlugin = {
|
|
448
|
+
install(app, options = {}) {
|
|
449
|
+
const provider = createDataClient({
|
|
450
|
+
...options,
|
|
451
|
+
app
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// Handle lifecycle in plugin mode
|
|
455
|
+
if (app.mixin) {
|
|
456
|
+
app.mixin({
|
|
457
|
+
beforeMount() {
|
|
458
|
+
provider.start();
|
|
459
|
+
},
|
|
460
|
+
beforeUnmount() {
|
|
461
|
+
provider.stop();
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
return provider;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
390
469
|
Object.defineProperty(exports, "Controller", {
|
|
391
470
|
enumerable: true,
|
|
392
471
|
get: function () { return core.Controller; }
|
|
@@ -423,7 +502,8 @@ Object.defineProperty(exports, "actionTypes", {
|
|
|
423
502
|
enumerable: true,
|
|
424
503
|
get: function () { return core.actionTypes; }
|
|
425
504
|
});
|
|
426
|
-
exports.
|
|
505
|
+
exports.DataClientPlugin = DataClientPlugin;
|
|
506
|
+
exports.createDataClient = createDataClient;
|
|
427
507
|
exports.useController = useController;
|
|
428
508
|
exports.useDebounce = useDebounce;
|
|
429
509
|
exports.useFetch = useFetch;
|
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 h(){}const u=(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 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 v 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 E={QueryDelegate:v,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 x;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return x}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 b,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 x=[void 0,void 0];class b{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 v{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}},h=(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:u)(n,s,i,r,o,t):s;return t})(new I(l,o));return l.result=h(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)?h: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 _="rdc/fetch",P="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=_,V=P,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:_,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:P,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 _: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 P: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 he(e,t){return e.meta[t]}const ue=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=ue,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:_,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:P,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=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(ae),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",o=i?n.endpoints[r]:void 0,a=e.schema,c=he(n,r);let l=null==c?void 0:c.expiresAt;const h=void 0===o&&void 0!==a,u=h?this.memo.buildQueryKey(a,s,n,r):o;if(!i)return{data:u,expiryStatus:R.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(h)d=!M(u);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,u,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 me{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 _: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===_&&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 ve{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=ve: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 xe{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 be={};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({...be,...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=null!==n[0]?e.key(...n):"",o=t.computed((()=>i.getResponseMeta(e,...n,s.value))),a=o.value.expiryStatus===R.Invalid||Date.now()>o.value.expiresAt;r&&a&&await i.fetch(e,...n);const c=i.getError(e,...n,s.value);if(c)throw c;return t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0}),t.readonly(t.computed((()=>o.value.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?[_e(me,null!=t?t:{})]:[_e(me,null!=t?t:{}),_e(xe,n)]};function _e(e,t){return t instanceof e?t:new e(t)}e.Controller=pe,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=me,e.PollingSubscription=we,e.SubscriptionManager=xe,e.actionTypes=ee,e.getDefaultManagers=Ce,e.provideDataClient=function(e={}){var n,s;const{Controller:i=pe,gcPolicy:r}=e,o=new i({gcPolicy:r}),a=null!=(n=e.managers)?n:Ce(),c=null!=(s=e.initialState)?s:oe,l=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()})}(a,o,c),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)))))}(a,o),u=re(o),d=t.shallowRef(c),p=t.shallowRef(w(c));let f=null;const y=()=>d.value,g=h.map((e=>e({getState:y,dispatch:e=>m(e)}))),m=(v=g,e=>v.reduceRight(((e,t)=>t(e)),e))((async e=>{const t=new Promise((e=>{f=e}));return await(async e=>{const t=u(d.value,e);if(d.value=t,p.value=w(t),f){const e=f;f=null,e()}})(e),t}));var v;let E;return o.bindMiddleware({getState:y,dispatch:e=>m(e)}),t.provide(Ie,p),t.provide(Le,o),t.onMounted((()=>{E=l()})),t.onUnmounted((()=>{E&&E()})),{controller:o,stateRef:p};function w(e){return e.optimistic.reduce(u,e)}},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=null!==n[0]?e.key(...n):"",o=t.computed((()=>r?i.getResponseMeta(e,...n,s.value):null));let a;const c=()=>{if(!r)return;const t=o.value;if(!t)return;const s=t.expiryStatus===R.Invalid;Date.now()<=t.expiresAt&&!s||(a=i.fetch(e,...n))};return c(),t.watch((()=>{const e=o.value;return e?[e.expiresAt,e.expiryStatus,s.value.lastReset]:r}),(()=>{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 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(){}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 o=h({},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},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 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=h({},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 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,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=>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,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 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 b{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return x;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return x}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 x=[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,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 A=(e,t,n=[],{entities:s,indexes:i,entitiesMeta:r}=S,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:h({},s),indexes:h({},i),entitiesMeta:h({},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:d)(n,s,i,r,o,t):s;return t})(new L(l,o));return l.result=u(e,t,t,void 0,n),l};const S={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: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 O(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(O))}class R{constructor(e=w){var t;this.endpoints=new b,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 b,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 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 b);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:f)(n,s,t,e):n}}(n)(e,t),i.set(s,o)}return o}}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",T="rdc/setresponse",D="rdc/optimistic",q="rdc/reset",N="rdc/subscribe",K="rdc/unsubscribe",H="rdc/invalidate",z="rdc/invalidateall",F="rdc/expireall",U="rdc/gc",V=_,B=j,Y=T,Q=D,$=q,W=N,X=K,J=H,G=z,Z=F,ee=U;var te=Object.freeze({__proto__:null,EXPIREALL:F,EXPIREALL_TYPE:Z,FETCH:_,FETCH_TYPE:V,GC:U,GC_TYPE:ee,INVALIDATE:H,INVALIDATEALL:z,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:J,OPTIMISTIC:D,OPTIMISTIC_TYPE:Q,RESET:q,RESET_TYPE:$,SET:j,SET_RESPONSE:T,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 o=(n=t.endpoint,s=t.args,i=t.meta.fetchedAt,{type:D,key:n.key(...s),args:s,endpoint:n,meta:P(null!=(r=n.dataExpiryLength)?r:6e4,i)});return h({},e,{optimistic:[...e.optimistic,o]})}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===D?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function oe(e){return function(t,n){switch(t||(t=ae),n.type){case U: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 D:case T:return function(e,t,n){if(t.error)return ie(e,t,t.response);try{var s;let i;if(t.type===D){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:o,indexes:a,entitiesMeta:c}=A(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:o,endpoints:l,indexes:a,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}=A(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 z:case H: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===H?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),h({},e,{endpoints:n,meta:s})}(t,n);case F: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({},ae,{lastReset:n.date});default:return t}}}const ae={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,o;const a=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(o=e.dataExpiryLength)?o:6e4;return{type:T,key:e.key(...t),response:s,args:t.map(ce),endpoint:e,meta:P(a,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=()=>ae;class fe{constructor({dispatch:e=de,getState:t=pe,memo:s=new R,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:H,key:e.key(...t)}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:z,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:F,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):"",o=i?n.endpoints[r]:void 0,a=e.schema,c=he(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:C.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(u)d=!O(h);else if(!a||!ye(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(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 T: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 be{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 xe{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"),Ae=Symbol("DataClientController"),Se=t.shallowRef(ae);function Me(){const e=t.inject(Ae,null);return e||new fe}function Oe(){const e=t.inject(Le,null);return e||Se}async function Re(e,...n){const s=Oe(),i=Me(),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===C.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 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,o)=>{if(!r.value)return;const a=i.value;s.subscribe(e,...a),o((()=>{s.unsubscribe(e,...a)}))}),{immediate:!0})}let Pe=(e={})=>{const{networkManager:t,subscriptionManager:n=be}=e;return null===n?[_e(me,null!=t?t:{})]:[_e(me,null!=t?t:{}),_e(xe,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:o}=e,a=new i({gcPolicy:r}),c=null!=(n=e.managers)?n:Pe(),l=null!=(s=e.initialState)?s:ae,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=oe(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(Le,f),o.provide(Ae,a)):(t.provide(Le,f),t.provide(Ae,a)),{controller:a,stateRef:f,start:()=>{w=u()},stop:()=>{w&&w()}};function b(e){return e.optimistic.reduce(d,e)}}const Te={install(e,t={}){const n=je(h({},t,{app:e}));return e.mixin&&e.mixin({beforeMount(){n.start()},beforeUnmount(){n.stop()}}),n}};e.Controller=fe,e.DataClientPlugin=Te,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===T&&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=be,e.SubscriptionManager=xe,e.actionTypes=te,e.createDataClient=je,e.getDefaultManagers=Pe,e.useController=Me,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=Oe(),i=Me(),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===C.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 Ce(e,...t),Re(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=Oe(),i=Me(),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=Ce,e.useSuspense=Re}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExpiryStatus } from '@data-client/core';
|
|
2
|
-
import { computed, watch } from 'vue';
|
|
2
|
+
import { computed, watch, ref } from 'vue';
|
|
3
3
|
import { useController, injectState } from '../context.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,18 +12,22 @@ import { useController, injectState } from '../context.js';
|
|
|
12
12
|
export default function useFetch(endpoint, ...args) {
|
|
13
13
|
const stateRef = injectState();
|
|
14
14
|
const controller = useController();
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
// Compute a key that changes when args change (including reactive props)
|
|
17
|
+
const argsKey = computed(() => args[0] !== null ? endpoint.key(...args) : '');
|
|
16
18
|
|
|
17
19
|
// Compute response meta reactively so we can respond to store updates
|
|
18
|
-
const responseMeta = computed(() =>
|
|
19
|
-
|
|
20
|
+
const responseMeta = computed(() => {
|
|
21
|
+
return argsKey.value ? controller.getResponseMeta(endpoint, ...args, stateRef.value) : null;
|
|
22
|
+
});
|
|
23
|
+
const lastPromise = ref(undefined);
|
|
20
24
|
const maybeFetch = () => {
|
|
21
|
-
if (
|
|
25
|
+
if (args[0] === null) return;
|
|
22
26
|
const meta = responseMeta.value;
|
|
23
27
|
if (!meta) return;
|
|
24
28
|
const forceFetch = meta.expiryStatus === ExpiryStatus.Invalid;
|
|
25
29
|
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
26
|
-
lastPromise = controller.fetch(endpoint, ...args);
|
|
30
|
+
lastPromise.value = controller.fetch(endpoint, ...args);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
// Trigger on initial call
|
|
@@ -32,10 +36,10 @@ export default function useFetch(endpoint, ...args) {
|
|
|
32
36
|
// Also watch for store changes that might require refetch (e.g., invalidation)
|
|
33
37
|
watch(() => {
|
|
34
38
|
const m = responseMeta.value;
|
|
35
|
-
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset] :
|
|
39
|
+
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value] : [argsKey.value];
|
|
36
40
|
}, () => {
|
|
37
41
|
maybeFetch();
|
|
38
42
|
});
|
|
39
43
|
return lastPromise;
|
|
40
44
|
}
|
|
41
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJFeHBpcnlTdGF0dXMiLCJjb21wdXRlZCIsIndhdGNoIiwicmVmIiwidXNlQ29udHJvbGxlciIsImluamVjdFN0YXRlIiwidXNlRmV0Y2giLCJlbmRwb2ludCIsImFyZ3MiLCJzdGF0ZVJlZiIsImNvbnRyb2xsZXIiLCJhcmdzS2V5Iiwia2V5IiwicmVzcG9uc2VNZXRhIiwidmFsdWUiLCJnZXRSZXNwb25zZU1ldGEiLCJsYXN0UHJvbWlzZSIsInVuZGVmaW5lZCIsIm1heWJlRmV0Y2giLCJtZXRhIiwiZm9yY2VGZXRjaCIsImV4cGlyeVN0YXR1cyIsIkludmFsaWQiLCJEYXRlIiwibm93IiwiZXhwaXJlc0F0IiwiZmV0Y2giLCJtIiwibGFzdFJlc2V0Il0sInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnN1bWVycy91c2VGZXRjaC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBFeHBpcnlTdGF0dXMgfSBmcm9tICdAZGF0YS1jbGllbnQvY29yZSc7XG5pbXBvcnQgdHlwZSB7XG4gIEVuZHBv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BQUssSUFBSSxFQUFFO0lBQ3RCLE1BQU1XLElBQUksR0FBR04sWUFBWSxDQUFDQyxLQUFLO0lBQy9CLElBQUksQ0FBQ0ssSUFBSSxFQUFFO0lBQ1gsTUFBTUMsVUFBVSxHQUFHRCxJQUFJLENBQUNFLFlBQVksS0FBS3JCLFlBQVksQ0FBQ3NCLE9BQU87SUFDN0QsSUFBSUMsSUFBSSxDQUFDQyxHQUFHLENBQUMsQ0FBQyxJQUFJTCxJQUFJLENBQUNNLFNBQVMsSUFBSSxDQUFDTCxVQUFVLEVBQUU7SUFDakRKLFdBQVcsQ0FBQ0YsS0FBSyxHQUFHSixVQUFVLENBQUNnQixLQUFLLENBQUNuQixRQUFRLEVBQUUsR0FBSUMsSUFBWSxDQUFDO0VBQ2xFLENBQUM7O0VBRUQ7RUFDQVUsVUFBVSxDQUFDLENBQUM7O0VBRVo7RUFDQWhCLEtBQUssQ0FDSCxNQUFNO0lBQ0osTUFBTXlCLENBQUMsR0FBR2QsWUFBWSxDQUFDQyxLQUFLO0lBQzVCLE9BQU9hLENBQUMsR0FDSixDQUFDQSxDQUFDLENBQUNGLFNBQVMsRUFBRUUsQ0FBQyxDQUFDTixZQUFZLEVBQUVaLFFBQVEsQ0FBQ0ssS0FBSyxDQUFDYyxTQUFTLEVBQUVqQixPQUFPLENBQUNHLEtBQUssQ0FBQyxHQUN0RSxDQUFDSCxPQUFPLENBQUNHLEtBQUssQ0FBQztFQUNyQixDQUFDLEVBQ0QsTUFBTTtJQUNKSSxVQUFVLENBQUMsQ0FBQztFQUNkLENBQ0YsQ0FBQztFQUVELE9BQU9GLFdBQVc7QUFDcEIiLCJpZ25vcmVMaXN0IjpbXX0=
|
|
@@ -4,26 +4,51 @@ import { useController, injectState } from '../context.js';
|
|
|
4
4
|
export default async function useSuspense(endpoint, ...args) {
|
|
5
5
|
const stateRef = injectState();
|
|
6
6
|
const controller = useController();
|
|
7
|
-
const key = args[0] !== null ? endpoint.key(...args) : '';
|
|
8
|
-
const responseMeta = computed(() => controller.getResponseMeta(endpoint, ...args, stateRef.value));
|
|
9
7
|
|
|
10
|
-
//
|
|
11
|
-
const
|
|
12
|
-
|
|
8
|
+
// Compute a key that changes when args change (including reactive props)
|
|
9
|
+
const argsKey = computed(() => args[0] !== null ? endpoint.key(...args) : '');
|
|
10
|
+
|
|
11
|
+
// Compute response meta reactively so we can respond to store updates
|
|
12
|
+
const responseMeta = computed(() => {
|
|
13
|
+
return argsKey.value ? controller.getResponseMeta(endpoint, ...args, stateRef.value) : null;
|
|
14
|
+
});
|
|
15
|
+
const maybeFetch = async () => {
|
|
16
|
+
const currentKey = argsKey.value;
|
|
17
|
+
if (!currentKey) return;
|
|
18
|
+
const meta = responseMeta.value;
|
|
19
|
+
if (!meta) return;
|
|
20
|
+
const forceFetch = meta.expiryStatus === ExpiryStatus.Invalid;
|
|
21
|
+
if (Date.now() <= meta.expiresAt && !forceFetch) return;
|
|
13
22
|
await controller.fetch(endpoint, ...args);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Trigger on initial call
|
|
26
|
+
await maybeFetch();
|
|
27
|
+
|
|
28
|
+
// Watch for changes to key, expiry, or store state that require refetch
|
|
29
|
+
watch(() => {
|
|
30
|
+
const m = responseMeta.value;
|
|
31
|
+
return m ? [m.expiresAt, m.expiryStatus, stateRef.value.lastReset, argsKey.value] : [argsKey.value];
|
|
32
|
+
}, () => {
|
|
33
|
+
return maybeFetch();
|
|
34
|
+
});
|
|
17
35
|
|
|
18
36
|
// Maintain GC refcounts on data mount/changes
|
|
19
|
-
watch(() =>
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
watch(() => {
|
|
38
|
+
var _responseMeta$value;
|
|
39
|
+
return (_responseMeta$value = responseMeta.value) == null ? void 0 : _responseMeta$value.data;
|
|
40
|
+
}, (_newVal, _oldVal, onCleanup) => {
|
|
41
|
+
var _responseMeta$value2;
|
|
42
|
+
const decrement = (_responseMeta$value2 = responseMeta.value) == null ? void 0 : _responseMeta$value2.countRef();
|
|
43
|
+
onCleanup(() => decrement == null ? void 0 : decrement());
|
|
22
44
|
}, {
|
|
23
45
|
immediate: true
|
|
24
46
|
});
|
|
25
47
|
|
|
26
48
|
// Return readonly computed ref - Vue automatically unwraps in templates and reactive contexts
|
|
27
|
-
return readonly(computed(() =>
|
|
49
|
+
return readonly(computed(() => {
|
|
50
|
+
var _responseMeta$value3;
|
|
51
|
+
return (_responseMeta$value3 = responseMeta.value) == null ? void 0 : _responseMeta$value3.data;
|
|
52
|
+
}));
|
|
28
53
|
}
|
|
29
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
54
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJFeHBpcnlTdGF0dXMiLCJjb21wdXRlZCIsIndhdGNoIiwicmVhZG9ubHkiLCJ1c2VDb250cm9sbGVyIiwiaW5qZWN0U3RhdGUiLCJ1c2VTdXNwZW5zZSIsImVuZHBvaW50IiwiYXJncyIsInN0YXRlUmVmIiwiY29udHJvbGxlciIsImFyZ3NLZXkiLCJrZXkiLCJyZXNwb25zZU1ldGEiLCJ2YWx1ZSIsImdldFJlc3BvbnNlTWV0YSIsIm1heWJlRmV0Y2giLCJjdXJyZW50S2V5IiwibWV0YSIsImZvcmNlRmV0Y2giLCJleHBpcnlTdGF0dXMiLCJJbnZhbGlkIiwiRGF0ZSIsIm5vdyIsImV4cGlyZXNBdCIsImZldGNoIiwibSIsImxhc3RSZXNldCIsIl9yZXNwb25zZU1ldGEkdmFsdWUiLCJkYXRhIiwiX25ld1ZhbCIsIl9vbGRWYWwiLCJvbkNsZWFudXAiLCJfcmVzcG9uc2VNZXRhJHZhbHVlMiIsImRlY3JlbWVudCIsImNvdW50UmVmIiwiaW1tZWRpYXRlIiwiX3Jlc3BvbnNlTWV0YSR2YWx1ZTMiXSwic291cmNlcyI6WyIuLi8uLi9zcmMvY29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ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAU,KAAK,YAAY,EAAc,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAE7E,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAEtD,CAAC;AACT,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,UAAU,CAE3C,CAAC;AAET,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAC9B,CAAC;AAE3B,wBAAgB,aAAa,IAAI,UAAU,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAU,KAAK,YAAY,EAAc,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAE7E,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAEtD,CAAC;AACT,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,UAAU,CAE3C,CAAC;AAET,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAC9B,CAAC;AAE3B,wBAAgB,aAAa,IAAI,UAAU,CAa1C;AAED,wBAAgB,WAAW,IAAI,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAaxD"}
|
package/lib/context.js
CHANGED
|
@@ -8,6 +8,7 @@ export const FallbackStateRef = shallowRef(initialState);
|
|
|
8
8
|
export function useController() {
|
|
9
9
|
const ctrl = inject(ControllerKey, null);
|
|
10
10
|
if (!ctrl) {
|
|
11
|
+
/* istanbul ignore else */
|
|
11
12
|
if (process.env.NODE_ENV !== 'production') {
|
|
12
13
|
console.error('It appears you are trying to use Reactive Data Client (Vue) without a provider.\n' + 'Follow instructions: https://dataclient.io/docs/getting-started/installation#add-provider-at-top-level-component');
|
|
13
14
|
}
|
|
@@ -18,6 +19,7 @@ export function useController() {
|
|
|
18
19
|
export function injectState() {
|
|
19
20
|
const state = inject(StateKey, null);
|
|
20
21
|
if (!state) {
|
|
22
|
+
/* istanbul ignore else */
|
|
21
23
|
if (process.env.NODE_ENV !== 'production') {
|
|
22
24
|
console.error('It appears you are trying to use Reactive Data Client (Vue) without a provider.\n' + 'Follow instructions: https://dataclient.io/docs/getting-started/installation#add-provider-at-top-level-component');
|
|
23
25
|
}
|
|
@@ -25,4 +27,4 @@ export function injectState() {
|
|
|
25
27
|
}
|
|
26
28
|
return state;
|
|
27
29
|
}
|
|
28
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJpbml0aWFsU3RhdGUiLCJDb250cm9sbGVyIiwiaW5qZWN0Iiwic2hhbGxvd1JlZiIsIlN0YXRlS2V5IiwiU3ltYm9sIiwiQ29udHJvbGxlcktleSIsIkZhbGxiYWNrU3RhdGVSZWYiLCJ1c2VDb250cm9sbGVyIiwiY3RybCIsInByb2Nlc3MiLCJlbnYiLCJOT0RFX0VOViIsImNvbnNvbGUiLCJlcnJvciIsImluamVjdFN0YXRlIiwic3RhdGUiXSwic291cmNlcyI6WyIuLi9zcmMvY29udGV4dC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBpbml0aWFsU3RhdGUsIENvbnRyb2xsZXIgfSBmcm9tICdAZGF0YS1jbGllbnQvY29yZSc7XG5pbXBvcnQgdHlwZSB7IFN0YXRlIH0gZnJvbSAnQGRhdGEtY2xpZW50L2Nvcm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