@pinia/colada-plugin-delay 0.1.2 → 0.1.3
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/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -11
- package/dist/index.d.mts +29 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue0 from "vue";
|
|
2
2
|
import { ComponentInternalInstance, ComputedRef, EffectScope, MaybeRefOrGetter, Plugin, ShallowRef } from "vue";
|
|
3
3
|
import * as pinia0 from "pinia";
|
|
4
4
|
import { Pinia } from "pinia";
|
|
@@ -267,6 +267,33 @@ interface UseQueryOptions<TData = unknown, TError = ErrorDefault, TDataInitial e
|
|
|
267
267
|
* @see {@link placeholderData}
|
|
268
268
|
*/
|
|
269
269
|
initialData?: () => TDataInitial;
|
|
270
|
+
/**
|
|
271
|
+
* The timestamp (in milliseconds) when the initial data was last updated.
|
|
272
|
+
* This determines the staleness of the {@link initialData}. If not provided,
|
|
273
|
+
* defaults to `Date.now()` when initial data is set.
|
|
274
|
+
*
|
|
275
|
+
* @default Date.now() when {@link initialData} is used
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* // Using a static timestamp
|
|
280
|
+
* useQuery({
|
|
281
|
+
* key: ['user'],
|
|
282
|
+
* query: () => fetchUser(),
|
|
283
|
+
* initialData: () => cachedUser,
|
|
284
|
+
* initialDataUpdatedAt: 1234567890000
|
|
285
|
+
* })
|
|
286
|
+
*
|
|
287
|
+
* // Using a function
|
|
288
|
+
* useQuery({
|
|
289
|
+
* key: ['user'],
|
|
290
|
+
* query: () => fetchUser(),
|
|
291
|
+
* initialData: () => cachedUser,
|
|
292
|
+
* initialDataUpdatedAt: () => Number(localStorage.getItem('userTimestamp'))
|
|
293
|
+
* })
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
initialDataUpdatedAt?: number | (() => number);
|
|
270
297
|
/**
|
|
271
298
|
* A placeholder data that is initially shown while the query is loading for
|
|
272
299
|
* the first time. This will also show the `status` as `success` until the
|
|
@@ -487,7 +514,8 @@ interface UseQueryEntry<TData = unknown, TError = unknown, TDataInitial extends
|
|
|
487
514
|
*/
|
|
488
515
|
meta: QueryMeta;
|
|
489
516
|
/**
|
|
490
|
-
* Extensions to the query entry added by plugins.
|
|
517
|
+
* Extensions to the query entry added by plugins. Must be extended in the
|
|
518
|
+
* `extend` action.
|
|
491
519
|
*/
|
|
492
520
|
ext: UseQueryEntryExtensions<TData, TError, TDataInitial>;
|
|
493
521
|
/**
|
|
@@ -528,7 +556,7 @@ declare const useQueryCache: pinia0.StoreDefinition<"_pc_query", Pick<{
|
|
|
528
556
|
* Scope to track effects and components that use the query cache.
|
|
529
557
|
* @internal
|
|
530
558
|
*/
|
|
531
|
-
_s:
|
|
559
|
+
_s: vue0.Raw<EffectScope>;
|
|
532
560
|
setQueryData: <TData = unknown, TError = {
|
|
533
561
|
custom: Error;
|
|
534
562
|
}, TDataInitial extends TData | undefined = undefined>(key: EntryKeyTagged<TData, TError, TDataInitial> | EntryKey, data: NoInfer<TData> | Exclude<NoInfer<TDataInitial>, undefined> | ((oldData: TData | TDataInitial | undefined) => TData | Exclude<TDataInitial, undefined>)) => void;
|
|
@@ -564,7 +592,7 @@ declare const useQueryCache: pinia0.StoreDefinition<"_pc_query", Pick<{
|
|
|
564
592
|
* Scope to track effects and components that use the query cache.
|
|
565
593
|
* @internal
|
|
566
594
|
*/
|
|
567
|
-
_s:
|
|
595
|
+
_s: vue0.Raw<EffectScope>;
|
|
568
596
|
setQueryData: <TData = unknown, TError = {
|
|
569
597
|
custom: Error;
|
|
570
598
|
}, TDataInitial extends TData | undefined = undefined>(key: EntryKeyTagged<TData, TError, TDataInitial> | EntryKey, data: NoInfer<TData> | Exclude<NoInfer<TDataInitial>, undefined> | ((oldData: TData | TDataInitial | undefined) => TData | Exclude<TDataInitial, undefined>)) => void;
|
|
@@ -600,7 +628,7 @@ declare const useQueryCache: pinia0.StoreDefinition<"_pc_query", Pick<{
|
|
|
600
628
|
* Scope to track effects and components that use the query cache.
|
|
601
629
|
* @internal
|
|
602
630
|
*/
|
|
603
|
-
_s:
|
|
631
|
+
_s: vue0.Raw<EffectScope>;
|
|
604
632
|
setQueryData: <TData = unknown, TError = {
|
|
605
633
|
custom: Error;
|
|
606
634
|
}, TDataInitial extends TData | undefined = undefined>(key: EntryKeyTagged<TData, TError, TDataInitial> | EntryKey, data: NoInfer<TData> | Exclude<NoInfer<TDataInitial>, undefined> | ((oldData: TData | TDataInitial | undefined) => TData | Exclude<TDataInitial, undefined>)) => void;
|
|
@@ -1352,7 +1380,7 @@ type UseMutationEntryFilter = EntryFilter<UseMutationEntry>;
|
|
|
1352
1380
|
* composable, or in injectable contexts like stores and navigation guards.
|
|
1353
1381
|
*/
|
|
1354
1382
|
declare const useMutationCache: pinia0.StoreDefinition<"_pc_mutation", Pick<{
|
|
1355
|
-
caches:
|
|
1383
|
+
caches: vue0.Ref<Map<number, UseMutationEntry<unknown, any, unknown, any>>, Map<number, UseMutationEntry<unknown, any, unknown, any>>>;
|
|
1356
1384
|
create: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(options: UseMutationOptionsWithDefaults<TData, TVars, TError, TContext>, key?: EntryKey | undefined, vars?: TVars) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1357
1385
|
ensure: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(entry: UseMutationEntry<TData, TVars, TError, TContext>, vars: NoInfer<TVars>) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1358
1386
|
ensureDefinedMutation: <T>(fn: () => T) => unknown;
|
|
@@ -1367,9 +1395,9 @@ declare const useMutationCache: pinia0.StoreDefinition<"_pc_mutation", Pick<{
|
|
|
1367
1395
|
* Scope to track effects and components that use the mutation cache.
|
|
1368
1396
|
* @internal
|
|
1369
1397
|
*/
|
|
1370
|
-
_s:
|
|
1398
|
+
_s: vue0.EffectScope;
|
|
1371
1399
|
}, "caches" | "_s">, Pick<{
|
|
1372
|
-
caches:
|
|
1400
|
+
caches: vue0.Ref<Map<number, UseMutationEntry<unknown, any, unknown, any>>, Map<number, UseMutationEntry<unknown, any, unknown, any>>>;
|
|
1373
1401
|
create: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(options: UseMutationOptionsWithDefaults<TData, TVars, TError, TContext>, key?: EntryKey | undefined, vars?: TVars) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1374
1402
|
ensure: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(entry: UseMutationEntry<TData, TVars, TError, TContext>, vars: NoInfer<TVars>) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1375
1403
|
ensureDefinedMutation: <T>(fn: () => T) => unknown;
|
|
@@ -1384,9 +1412,9 @@ declare const useMutationCache: pinia0.StoreDefinition<"_pc_mutation", Pick<{
|
|
|
1384
1412
|
* Scope to track effects and components that use the mutation cache.
|
|
1385
1413
|
* @internal
|
|
1386
1414
|
*/
|
|
1387
|
-
_s:
|
|
1415
|
+
_s: vue0.EffectScope;
|
|
1388
1416
|
}, never>, Pick<{
|
|
1389
|
-
caches:
|
|
1417
|
+
caches: vue0.Ref<Map<number, UseMutationEntry<unknown, any, unknown, any>>, Map<number, UseMutationEntry<unknown, any, unknown, any>>>;
|
|
1390
1418
|
create: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(options: UseMutationOptionsWithDefaults<TData, TVars, TError, TContext>, key?: EntryKey | undefined, vars?: TVars) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1391
1419
|
ensure: <TData = unknown, TVars = unknown, TError = unknown, TContext extends Record<any, any> = _EmptyObject>(entry: UseMutationEntry<TData, TVars, TError, TContext>, vars: NoInfer<TVars>) => UseMutationEntry<TData, TVars, TError, TContext>;
|
|
1392
1420
|
ensureDefinedMutation: <T>(fn: () => T) => unknown;
|
|
@@ -1401,7 +1429,7 @@ declare const useMutationCache: pinia0.StoreDefinition<"_pc_mutation", Pick<{
|
|
|
1401
1429
|
* Scope to track effects and components that use the mutation cache.
|
|
1402
1430
|
* @internal
|
|
1403
1431
|
*/
|
|
1404
|
-
_s:
|
|
1432
|
+
_s: vue0.EffectScope;
|
|
1405
1433
|
}, "get" | "create" | "ensure" | "ensureDefinedMutation" | "mutate" | "remove" | "extend" | "setEntryState" | "getEntries" | "untrack">>;
|
|
1406
1434
|
/**
|
|
1407
1435
|
* The cache of the mutations. It's the store returned by {@link useMutationCache}.
|
package/dist/index.d.mts
CHANGED
|
@@ -267,6 +267,33 @@ interface UseQueryOptions<TData = unknown, TError = ErrorDefault, TDataInitial e
|
|
|
267
267
|
* @see {@link placeholderData}
|
|
268
268
|
*/
|
|
269
269
|
initialData?: () => TDataInitial;
|
|
270
|
+
/**
|
|
271
|
+
* The timestamp (in milliseconds) when the initial data was last updated.
|
|
272
|
+
* This determines the staleness of the {@link initialData}. If not provided,
|
|
273
|
+
* defaults to `Date.now()` when initial data is set.
|
|
274
|
+
*
|
|
275
|
+
* @default Date.now() when {@link initialData} is used
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* // Using a static timestamp
|
|
280
|
+
* useQuery({
|
|
281
|
+
* key: ['user'],
|
|
282
|
+
* query: () => fetchUser(),
|
|
283
|
+
* initialData: () => cachedUser,
|
|
284
|
+
* initialDataUpdatedAt: 1234567890000
|
|
285
|
+
* })
|
|
286
|
+
*
|
|
287
|
+
* // Using a function
|
|
288
|
+
* useQuery({
|
|
289
|
+
* key: ['user'],
|
|
290
|
+
* query: () => fetchUser(),
|
|
291
|
+
* initialData: () => cachedUser,
|
|
292
|
+
* initialDataUpdatedAt: () => Number(localStorage.getItem('userTimestamp'))
|
|
293
|
+
* })
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
initialDataUpdatedAt?: number | (() => number);
|
|
270
297
|
/**
|
|
271
298
|
* A placeholder data that is initially shown while the query is loading for
|
|
272
299
|
* the first time. This will also show the `status` as `success` until the
|
|
@@ -487,7 +514,8 @@ interface UseQueryEntry<TData = unknown, TError = unknown, TDataInitial extends
|
|
|
487
514
|
*/
|
|
488
515
|
meta: QueryMeta;
|
|
489
516
|
/**
|
|
490
|
-
* Extensions to the query entry added by plugins.
|
|
517
|
+
* Extensions to the query entry added by plugins. Must be extended in the
|
|
518
|
+
* `extend` action.
|
|
491
519
|
*/
|
|
492
520
|
ext: UseQueryEntryExtensions<TData, TError, TDataInitial>;
|
|
493
521
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -41,7 +41,7 @@ function* find$1(map, partialKey) {
|
|
|
41
41
|
*
|
|
42
42
|
* @internal
|
|
43
43
|
*/
|
|
44
|
-
const START_EXT = {};
|
|
44
|
+
const START_EXT = Object.freeze({});
|
|
45
45
|
|
|
46
46
|
//#endregion
|
|
47
47
|
//#region ../../src/define-query-options.ts
|
|
@@ -194,7 +194,7 @@ const useQueryCache = /* @__PURE__ */ defineStore(QUERY_STORE_ID, ({ action }) =
|
|
|
194
194
|
* @param [options] - options attached to the query
|
|
195
195
|
* @param [initialData] - initial data of the query if any
|
|
196
196
|
* @param [error] - initial error of the query if any
|
|
197
|
-
* @param [when] - relative when was the data or error fetched (will be
|
|
197
|
+
* @param [when] - relative when was the data or error fetched (will be substracted to Date.now())
|
|
198
198
|
* @param [meta] - resolved meta information for the query
|
|
199
199
|
*/
|
|
200
200
|
const create$1 = action((key, options = null, initialData, error = null, when = 0, meta = {}) => scope.run(() => {
|
|
@@ -351,7 +351,8 @@ const useQueryCache = /* @__PURE__ */ defineStore(QUERY_STORE_ID, ({ action }) =
|
|
|
351
351
|
if (previousEntry && keyHash === previousEntry.keyHash) return previousEntry;
|
|
352
352
|
let entry = cachesRaw.get(keyHash);
|
|
353
353
|
if (!entry) {
|
|
354
|
-
|
|
354
|
+
const initialDataUpdatedAt = toValue(options.initialDataUpdatedAt);
|
|
355
|
+
cachesRaw.set(keyHash, entry = create$1(key, options, options.initialData?.(), null, initialDataUpdatedAt != null ? Date.now() - initialDataUpdatedAt : 0, toValue(options.meta)));
|
|
355
356
|
if (options.placeholderData && entry.state.value.status === "pending") entry.placeholderData = toValueWithArgs(options.placeholderData, isEntryUsingPlaceholderData(previousEntry) ? previousEntry.placeholderData : previousEntry?.state.value.data);
|
|
356
357
|
triggerRef(caches);
|
|
357
358
|
}
|