@qiaopeng/tanstack-query-plus 0.5.9 → 0.5.10
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 +86 -55
- package/dist/{types/base.d.ts → base-CHnwqfyz.d.cts} +12 -14
- package/dist/base-CHnwqfyz.d.ts +52 -0
- package/dist/chunk-52ZO6Y67.cjs +1121 -0
- package/dist/chunk-52ZO6Y67.cjs.map +1 -0
- package/dist/chunk-5J6OXSLW.cjs +36 -0
- package/dist/chunk-5J6OXSLW.cjs.map +1 -0
- package/dist/chunk-6MAYHLTE.cjs +310 -0
- package/dist/chunk-6MAYHLTE.cjs.map +1 -0
- package/dist/chunk-ADS2QTMP.js +144 -0
- package/dist/chunk-ADS2QTMP.js.map +1 -0
- package/dist/chunk-APXNNHBD.cjs +374 -0
- package/dist/chunk-APXNNHBD.cjs.map +1 -0
- package/dist/chunk-AXMWOGNX.js +134 -0
- package/dist/chunk-AXMWOGNX.js.map +1 -0
- package/dist/chunk-B4KO3K3E.cjs +521 -0
- package/dist/chunk-B4KO3K3E.cjs.map +1 -0
- package/dist/chunk-BK3OTIBD.cjs +15 -0
- package/dist/chunk-BK3OTIBD.cjs.map +1 -0
- package/dist/chunk-BYAOQALW.js +13 -0
- package/dist/chunk-BYAOQALW.js.map +1 -0
- package/dist/chunk-CRTVS7VI.cjs +162 -0
- package/dist/chunk-CRTVS7VI.cjs.map +1 -0
- package/dist/chunk-EXITP7QO.js +288 -0
- package/dist/chunk-EXITP7QO.js.map +1 -0
- package/dist/chunk-GMO3PRZZ.js +565 -0
- package/dist/chunk-GMO3PRZZ.js.map +1 -0
- package/dist/chunk-HRO2DWKZ.js +12 -0
- package/dist/chunk-HRO2DWKZ.js.map +1 -0
- package/dist/chunk-JHDKUQSB.js +1069 -0
- package/dist/chunk-JHDKUQSB.js.map +1 -0
- package/dist/chunk-JN2Y6RSY.js +23 -0
- package/dist/chunk-JN2Y6RSY.js.map +1 -0
- package/dist/chunk-JRJSKRZW.cjs +29 -0
- package/dist/chunk-JRJSKRZW.cjs.map +1 -0
- package/dist/chunk-KC62H4VJ.js +123 -0
- package/dist/chunk-KC62H4VJ.js.map +1 -0
- package/dist/chunk-LHEHSLD5.js +31 -0
- package/dist/chunk-LHEHSLD5.js.map +1 -0
- package/dist/chunk-N4264P7N.cjs +156 -0
- package/dist/chunk-N4264P7N.cjs.map +1 -0
- package/dist/chunk-NF5QYPYC.cjs +133 -0
- package/dist/chunk-NF5QYPYC.cjs.map +1 -0
- package/dist/chunk-OFLCHKKE.cjs +28 -0
- package/dist/chunk-OFLCHKKE.cjs.map +1 -0
- package/dist/chunk-PCNSWVA5.cjs +602 -0
- package/dist/chunk-PCNSWVA5.cjs.map +1 -0
- package/dist/chunk-STOMAA2X.js +85 -0
- package/dist/chunk-STOMAA2X.js.map +1 -0
- package/dist/chunk-UVF5S6LX.cjs +15 -0
- package/dist/chunk-UVF5S6LX.cjs.map +1 -0
- package/dist/chunk-WEIXCDCA.cjs +90 -0
- package/dist/chunk-WEIXCDCA.cjs.map +1 -0
- package/dist/chunk-X3ZTSLBQ.js +355 -0
- package/dist/chunk-X3ZTSLBQ.js.map +1 -0
- package/dist/chunk-YEV73J4J.js +504 -0
- package/dist/chunk-YEV73J4J.js.map +1 -0
- package/dist/chunk-YW5PNTRU.cjs +14 -0
- package/dist/chunk-YW5PNTRU.cjs.map +1 -0
- package/dist/chunk-ZNXSWUIS.js +12 -0
- package/dist/chunk-ZNXSWUIS.js.map +1 -0
- package/dist/chunk-ZUEMBY4W.js +21 -0
- package/dist/chunk-ZUEMBY4W.js.map +1 -0
- package/dist/components/index.cjs +60 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +43 -0
- package/dist/components/index.d.ts +43 -4
- package/dist/components/index.js +3 -4
- package/dist/components/index.js.map +1 -0
- package/dist/core/devtools.cjs +25 -0
- package/dist/core/devtools.cjs.map +1 -0
- package/dist/core/devtools.d.cts +17 -0
- package/dist/core/devtools.d.ts +9 -7
- package/dist/core/devtools.js +4 -16
- package/dist/core/devtools.js.map +1 -0
- package/dist/core/index.cjs +220 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +196 -0
- package/dist/core/index.d.ts +196 -9
- package/dist/core/index.js +7 -8
- package/dist/core/index.js.map +1 -0
- package/dist/features/index.cjs +76 -0
- package/dist/features/index.cjs.map +1 -0
- package/dist/features/index.d.cts +86 -0
- package/dist/features/index.d.ts +86 -4
- package/dist/features/index.js +7 -3
- package/dist/features/index.js.map +1 -0
- package/dist/hooks/index.cjs +209 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +377 -0
- package/dist/hooks/index.d.ts +377 -10
- package/dist/hooks/index.js +8 -9
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useInViewPrefetch.cjs +33 -0
- package/dist/hooks/useInViewPrefetch.cjs.map +1 -0
- package/dist/hooks/useInViewPrefetch.d.cts +12 -0
- package/dist/hooks/useInViewPrefetch.d.ts +6 -4
- package/dist/hooks/useInViewPrefetch.js +30 -20
- package/dist/hooks/useInViewPrefetch.js.map +1 -0
- package/dist/index.cjs +811 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.js +89 -7
- package/dist/index.js.map +1 -0
- package/dist/{types/offline.d.ts → offline-DVPtgoAS.d.ts} +15 -13
- package/dist/offline-xxeA_-6V.d.cts +99 -0
- package/dist/persistence-MRtkmhqq.d.cts +216 -0
- package/dist/persistence-tIrEb0pR.d.ts +216 -0
- package/dist/react-query/index.cjs +52 -0
- package/dist/react-query/index.cjs.map +1 -0
- package/dist/react-query/index.d.cts +1 -0
- package/dist/react-query/index.d.ts +1 -3
- package/dist/react-query/index.js +3 -1
- package/dist/react-query/index.js.map +1 -0
- package/dist/types/index.cjs +43 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +157 -0
- package/dist/types/index.d.ts +116 -12
- package/dist/types/index.js +6 -8
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +234 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +272 -0
- package/dist/utils/index.d.ts +272 -10
- package/dist/utils/index.js +9 -9
- package/dist/utils/index.js.map +1 -0
- package/package.json +13 -3
- package/dist/PersistQueryClientProvider.d.ts +0 -22
- package/dist/PersistQueryClientProvider.d.ts.map +0 -1
- package/dist/PersistQueryClientProvider.js +0 -57
- package/dist/components/LoadingFallback.d.ts +0 -16
- package/dist/components/LoadingFallback.d.ts.map +0 -1
- package/dist/components/LoadingFallback.js +0 -27
- package/dist/components/QueryErrorBoundary.d.ts +0 -12
- package/dist/components/QueryErrorBoundary.d.ts.map +0 -1
- package/dist/components/QueryErrorBoundary.js +0 -9
- package/dist/components/SuspenseWrapper.d.ts +0 -14
- package/dist/components/SuspenseWrapper.d.ts.map +0 -1
- package/dist/components/SuspenseWrapper.js +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/internal/ErrorBoundary.d.ts +0 -27
- package/dist/components/internal/ErrorBoundary.d.ts.map +0 -1
- package/dist/components/internal/ErrorBoundary.js +0 -37
- package/dist/core/config.d.ts +0 -80
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js +0 -327
- package/dist/core/devtools.d.ts.map +0 -1
- package/dist/core/env.d.ts +0 -4
- package/dist/core/env.d.ts.map +0 -1
- package/dist/core/env.js +0 -26
- package/dist/core/focusManager.d.ts +0 -33
- package/dist/core/focusManager.d.ts.map +0 -1
- package/dist/core/focusManager.js +0 -122
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/keys.d.ts +0 -59
- package/dist/core/keys.d.ts.map +0 -1
- package/dist/core/keys.js +0 -107
- package/dist/core/queryOptions.d.ts +0 -19
- package/dist/core/queryOptions.d.ts.map +0 -1
- package/dist/core/queryOptions.js +0 -32
- package/dist/features/index.d.ts.map +0 -1
- package/dist/features/offline.d.ts +0 -49
- package/dist/features/offline.d.ts.map +0 -1
- package/dist/features/offline.js +0 -300
- package/dist/features/persistence.d.ts +0 -36
- package/dist/features/persistence.d.ts.map +0 -1
- package/dist/features/persistence.js +0 -187
- package/dist/hooks/batchQueries.d.ts +0 -129
- package/dist/hooks/batchQueries.d.ts.map +0 -1
- package/dist/hooks/batchQueries.js +0 -301
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/useDataGuardMutation.d.ts +0 -39
- package/dist/hooks/useDataGuardMutation.d.ts.map +0 -1
- package/dist/hooks/useDataGuardMutation.js +0 -137
- package/dist/hooks/useDataGuardQuery.d.ts +0 -28
- package/dist/hooks/useDataGuardQuery.d.ts.map +0 -1
- package/dist/hooks/useDataGuardQuery.js +0 -71
- package/dist/hooks/useFocusManager.d.ts +0 -41
- package/dist/hooks/useFocusManager.d.ts.map +0 -1
- package/dist/hooks/useFocusManager.js +0 -109
- package/dist/hooks/useInViewPrefetch.d.ts.map +0 -1
- package/dist/hooks/useInfiniteQuery.d.ts +0 -33
- package/dist/hooks/useInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useInfiniteQuery.js +0 -61
- package/dist/hooks/useMutation.d.ts +0 -25
- package/dist/hooks/useMutation.d.ts.map +0 -1
- package/dist/hooks/useMutation.js +0 -180
- package/dist/hooks/usePrefetch.d.ts +0 -54
- package/dist/hooks/usePrefetch.d.ts.map +0 -1
- package/dist/hooks/usePrefetch.js +0 -229
- package/dist/hooks/useQuery.d.ts +0 -21
- package/dist/hooks/useQuery.d.ts.map +0 -1
- package/dist/hooks/useQuery.js +0 -46
- package/dist/hooks/useSuspenseQuery.d.ts +0 -11
- package/dist/hooks/useSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useSuspenseQuery.js +0 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/react-query/index.d.ts.map +0 -1
- package/dist/types/base.d.ts.map +0 -1
- package/dist/types/base.js +0 -26
- package/dist/types/dataGuard.d.ts +0 -69
- package/dist/types/dataGuard.d.ts.map +0 -1
- package/dist/types/dataGuard.js +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/infinite.d.ts +0 -39
- package/dist/types/infinite.d.ts.map +0 -1
- package/dist/types/infinite.js +0 -1
- package/dist/types/offline.d.ts.map +0 -1
- package/dist/types/offline.js +0 -8
- package/dist/types/optimistic.d.ts +0 -126
- package/dist/types/optimistic.d.ts.map +0 -1
- package/dist/types/optimistic.js +0 -7
- package/dist/types/persistence.d.ts +0 -9
- package/dist/types/persistence.d.ts.map +0 -1
- package/dist/types/persistence.js +0 -1
- package/dist/types/selectors.d.ts +0 -11
- package/dist/types/selectors.d.ts.map +0 -1
- package/dist/types/selectors.js +0 -1
- package/dist/types/suspense.d.ts +0 -67
- package/dist/types/suspense.d.ts.map +0 -1
- package/dist/types/suspense.js +0 -1
- package/dist/utils/dataGuard.d.ts +0 -37
- package/dist/utils/dataGuard.d.ts.map +0 -1
- package/dist/utils/dataGuard.js +0 -251
- package/dist/utils/fieldMapper.d.ts +0 -9
- package/dist/utils/fieldMapper.d.ts.map +0 -1
- package/dist/utils/fieldMapper.js +0 -27
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/network.d.ts +0 -9
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -43
- package/dist/utils/optimisticUtils.d.ts +0 -45
- package/dist/utils/optimisticUtils.d.ts.map +0 -1
- package/dist/utils/optimisticUtils.js +0 -116
- package/dist/utils/placeholderData.d.ts +0 -3
- package/dist/utils/placeholderData.d.ts.map +0 -1
- package/dist/utils/placeholderData.js +0 -28
- package/dist/utils/prefetchManager.d.ts +0 -111
- package/dist/utils/prefetchManager.d.ts.map +0 -1
- package/dist/utils/prefetchManager.js +0 -246
- package/dist/utils/queryKey.d.ts +0 -26
- package/dist/utils/queryKey.d.ts.map +0 -1
- package/dist/utils/queryKey.js +0 -89
- package/dist/utils/selectors.d.ts +0 -30
- package/dist/utils/selectors.d.ts.map +0 -1
- package/dist/utils/selectors.js +0 -18
- package/dist/utils/storage.d.ts +0 -7
- package/dist/utils/storage.d.ts.map +0 -1
- package/dist/utils/storage.js +0 -84
package/dist/core/keys.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { QueryKey } from "@tanstack/react-query";
|
|
2
|
-
export declare const queryKeys: {
|
|
3
|
-
all: readonly ["tanstack-query"];
|
|
4
|
-
users: () => readonly ["tanstack-query", "users"];
|
|
5
|
-
user: (id: string) => readonly ["tanstack-query", "users", string];
|
|
6
|
-
userProfile: (id: string) => readonly ["tanstack-query", "users", string, "profile"];
|
|
7
|
-
userSettings: (id: string) => readonly ["tanstack-query", "users", string, "settings"];
|
|
8
|
-
usersByRole: (role: string) => readonly ["tanstack-query", "users", "by-role", string];
|
|
9
|
-
posts: () => readonly ["tanstack-query", "posts"];
|
|
10
|
-
post: (id: string) => readonly ["tanstack-query", "posts", string];
|
|
11
|
-
postsByUser: (userId: string) => readonly ["tanstack-query", "posts", "by-user", string];
|
|
12
|
-
postsByTag: (tag: string) => readonly ["tanstack-query", "posts", "by-tag", string];
|
|
13
|
-
postComments: (postId: string) => readonly ["tanstack-query", "posts", string, "comments"];
|
|
14
|
-
search: (query: string, type?: string) => readonly ["tanstack-query", "search", {
|
|
15
|
-
readonly query: string;
|
|
16
|
-
readonly type: string | undefined;
|
|
17
|
-
}];
|
|
18
|
-
notifications: () => readonly ["tanstack-query", "notifications"];
|
|
19
|
-
notification: (id: string) => readonly ["tanstack-query", "notifications", string];
|
|
20
|
-
unreadNotifications: () => readonly ["tanstack-query", "notifications", "unread"];
|
|
21
|
-
settings: () => readonly ["tanstack-query", "settings"];
|
|
22
|
-
appSettings: () => readonly ["tanstack-query", "settings", "app"];
|
|
23
|
-
userPreferences: (userId: string) => readonly ["tanstack-query", "settings", "preferences", string];
|
|
24
|
-
};
|
|
25
|
-
export declare function createFilteredKey(baseKey: QueryKey, filters: Record<string, unknown>): QueryKey;
|
|
26
|
-
export declare function createPaginatedKey(baseKey: QueryKey, page: number, pageSize: number): QueryKey;
|
|
27
|
-
export declare function createSortedKey(baseKey: QueryKey, sortBy: string, sortOrder?: "asc" | "desc"): QueryKey;
|
|
28
|
-
export declare function createSearchKey(baseKey: QueryKey, searchTerm: string, searchFields?: string[]): QueryKey;
|
|
29
|
-
export declare function createComplexKey(baseKey: QueryKey, options: {
|
|
30
|
-
page?: number;
|
|
31
|
-
pageSize?: number;
|
|
32
|
-
filters?: Record<string, unknown>;
|
|
33
|
-
sortBy?: string;
|
|
34
|
-
sortOrder?: "asc" | "desc";
|
|
35
|
-
search?: string;
|
|
36
|
-
}): QueryKey;
|
|
37
|
-
export declare function matchesKeyPattern(queryKey: QueryKey, pattern: QueryKey): boolean;
|
|
38
|
-
export declare function validateQueryKey(queryKey: QueryKey): boolean;
|
|
39
|
-
export declare function containsEntity(queryKey: QueryKey, entity: string): boolean;
|
|
40
|
-
export declare function extractEntityId(queryKey: QueryKey, entityIndex: number): string | undefined;
|
|
41
|
-
export declare function normalizeQueryKey(queryKey: QueryKey): QueryKey;
|
|
42
|
-
export declare function areKeysEqual(key1: QueryKey, key2: QueryKey): boolean;
|
|
43
|
-
export declare function createDomainKeyFactory(domain: string): {
|
|
44
|
-
all: () => readonly ["tanstack-query", string];
|
|
45
|
-
lists: () => readonly ["tanstack-query", string, "list"];
|
|
46
|
-
list: (params?: Record<string, unknown>) => readonly ["tanstack-query", string, "list"] | readonly ["tanstack-query", string, "list", Record<string, unknown>];
|
|
47
|
-
details: () => readonly ["tanstack-query", string, "detail"];
|
|
48
|
-
detail: (id: string | number) => readonly ["tanstack-query", string, "detail", string | number];
|
|
49
|
-
subResource: (id: string | number, resource: string) => readonly ["tanstack-query", string, "detail", string | number, string];
|
|
50
|
-
byRelation: (relation: string, relationId: string | number) => readonly ["tanstack-query", string, `by-${string}`, string | number];
|
|
51
|
-
};
|
|
52
|
-
export declare function createMutationKeyFactory(domain: string): {
|
|
53
|
-
create: () => readonly [string, "create"];
|
|
54
|
-
update: (id?: string | number) => readonly [string, "update", string | number] | readonly [string, "update"];
|
|
55
|
-
delete: (id?: string | number) => readonly [string, "delete", string | number] | readonly [string, "delete"];
|
|
56
|
-
batch: (operation: string) => readonly [string, "batch", string];
|
|
57
|
-
custom: (operation: string, id?: string | number) => readonly [string, string, string | number] | readonly [string, string];
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=keys.d.ts.map
|
package/dist/core/keys.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/core/keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,eAAO,MAAM,SAAS;;;eAGT,MAAM;sBACC,MAAM;uBACL,MAAM;wBACL,MAAM;;eAEf,MAAM;0BACK,MAAM;sBACV,MAAM;2BACD,MAAM;oBACb,MAAM,SAAS,MAAM;;;;;uBAElB,MAAM;;;;8BAIC,MAAM;CACjC,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAE/F;AACD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAE9F;AACD,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,KAAK,GAAG,MAAc,GAAG,QAAQ,CAE9G;AACD,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,CAExG;AACD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7I,QAAQ,CAiBV;AACD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAShF;AACD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAK5D;AACD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1E;AACD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3F;AACD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAE9D;AACD,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CASpE;AACD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM;;;oBAIjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;iBAE1B,MAAM,GAAG,MAAM;sBACV,MAAM,GAAG,MAAM,YAAY,MAAM;2BAC5B,MAAM,cAAc,MAAM,GAAG,MAAM;EAE7D;AACD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM;;kBAGrC,MAAM,GAAG,MAAM;kBACf,MAAM,GAAG,MAAM;uBACV,MAAM;wBACL,MAAM,OAAO,MAAM,GAAG,MAAM;EAEnD"}
|
package/dist/core/keys.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
export const queryKeys = {
|
|
2
|
-
all: ["tanstack-query"],
|
|
3
|
-
users: () => [...queryKeys.all, "users"],
|
|
4
|
-
user: (id) => [...queryKeys.users(), id],
|
|
5
|
-
userProfile: (id) => [...queryKeys.user(id), "profile"],
|
|
6
|
-
userSettings: (id) => [...queryKeys.user(id), "settings"],
|
|
7
|
-
usersByRole: (role) => [...queryKeys.users(), "by-role", role],
|
|
8
|
-
posts: () => [...queryKeys.all, "posts"],
|
|
9
|
-
post: (id) => [...queryKeys.posts(), id],
|
|
10
|
-
postsByUser: (userId) => [...queryKeys.posts(), "by-user", userId],
|
|
11
|
-
postsByTag: (tag) => [...queryKeys.posts(), "by-tag", tag],
|
|
12
|
-
postComments: (postId) => [...queryKeys.post(postId), "comments"],
|
|
13
|
-
search: (query, type) => [...queryKeys.all, "search", { query, type }],
|
|
14
|
-
notifications: () => [...queryKeys.all, "notifications"],
|
|
15
|
-
notification: (id) => [...queryKeys.notifications(), id],
|
|
16
|
-
unreadNotifications: () => [...queryKeys.notifications(), "unread"],
|
|
17
|
-
settings: () => [...queryKeys.all, "settings"],
|
|
18
|
-
appSettings: () => [...queryKeys.settings(), "app"],
|
|
19
|
-
userPreferences: (userId) => [...queryKeys.settings(), "preferences", userId]
|
|
20
|
-
};
|
|
21
|
-
export function createFilteredKey(baseKey, filters) {
|
|
22
|
-
return [...baseKey, "filtered", filters];
|
|
23
|
-
}
|
|
24
|
-
export function createPaginatedKey(baseKey, page, pageSize) {
|
|
25
|
-
return [...baseKey, "paginated", { page, pageSize }];
|
|
26
|
-
}
|
|
27
|
-
export function createSortedKey(baseKey, sortBy, sortOrder = "asc") {
|
|
28
|
-
return [...baseKey, "sorted", { sortBy, sortOrder }];
|
|
29
|
-
}
|
|
30
|
-
export function createSearchKey(baseKey, searchTerm, searchFields) {
|
|
31
|
-
return [...baseKey, "search", { term: searchTerm, fields: searchFields }];
|
|
32
|
-
}
|
|
33
|
-
export function createComplexKey(baseKey, options) {
|
|
34
|
-
const params = {};
|
|
35
|
-
if (options.page !== undefined && options.pageSize !== undefined) {
|
|
36
|
-
params.page = options.page;
|
|
37
|
-
params.pageSize = options.pageSize;
|
|
38
|
-
}
|
|
39
|
-
if (options.filters && Object.keys(options.filters).length > 0) {
|
|
40
|
-
params.filters = options.filters;
|
|
41
|
-
}
|
|
42
|
-
if (options.sortBy) {
|
|
43
|
-
params.sortBy = options.sortBy;
|
|
44
|
-
params.sortOrder = options.sortOrder || "asc";
|
|
45
|
-
}
|
|
46
|
-
if (options.search) {
|
|
47
|
-
params.search = options.search;
|
|
48
|
-
}
|
|
49
|
-
return [...baseKey, "complex", params];
|
|
50
|
-
}
|
|
51
|
-
export function matchesKeyPattern(queryKey, pattern) {
|
|
52
|
-
if (pattern.length > queryKey.length)
|
|
53
|
-
return false;
|
|
54
|
-
return pattern.every((patternPart, index) => {
|
|
55
|
-
const keyPart = queryKey[index];
|
|
56
|
-
if (typeof patternPart === "object" && typeof keyPart === "object") {
|
|
57
|
-
return JSON.stringify(patternPart) === JSON.stringify(keyPart);
|
|
58
|
-
}
|
|
59
|
-
return patternPart === keyPart;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
export function validateQueryKey(queryKey) {
|
|
63
|
-
if (!Array.isArray(queryKey) || queryKey.length === 0)
|
|
64
|
-
return false;
|
|
65
|
-
return queryKey.every((part) => part !== null && part !== undefined && (typeof part === "string" || typeof part === "number" || typeof part === "boolean" || (typeof part === "object" && part !== null)));
|
|
66
|
-
}
|
|
67
|
-
export function containsEntity(queryKey, entity) {
|
|
68
|
-
return queryKey.includes(entity);
|
|
69
|
-
}
|
|
70
|
-
export function extractEntityId(queryKey, entityIndex) {
|
|
71
|
-
const value = queryKey[entityIndex];
|
|
72
|
-
return typeof value === "string" ? value : undefined;
|
|
73
|
-
}
|
|
74
|
-
export function normalizeQueryKey(queryKey) {
|
|
75
|
-
return queryKey.filter((part) => part !== null && part !== undefined);
|
|
76
|
-
}
|
|
77
|
-
export function areKeysEqual(key1, key2) {
|
|
78
|
-
if (key1.length !== key2.length)
|
|
79
|
-
return false;
|
|
80
|
-
return key1.every((part, index) => {
|
|
81
|
-
const otherPart = key2[index];
|
|
82
|
-
if (typeof part === "object" && typeof otherPart === "object") {
|
|
83
|
-
return JSON.stringify(part) === JSON.stringify(otherPart);
|
|
84
|
-
}
|
|
85
|
-
return part === otherPart;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export function createDomainKeyFactory(domain) {
|
|
89
|
-
return {
|
|
90
|
-
all: () => [...queryKeys.all, domain],
|
|
91
|
-
lists: () => [...queryKeys.all, domain, "list"],
|
|
92
|
-
list: (params) => (params ? [...queryKeys.all, domain, "list", params] : [...queryKeys.all, domain, "list"]),
|
|
93
|
-
details: () => [...queryKeys.all, domain, "detail"],
|
|
94
|
-
detail: (id) => [...queryKeys.all, domain, "detail", id],
|
|
95
|
-
subResource: (id, resource) => [...queryKeys.all, domain, "detail", id, resource],
|
|
96
|
-
byRelation: (relation, relationId) => [...queryKeys.all, domain, `by-${relation}`, relationId]
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
export function createMutationKeyFactory(domain) {
|
|
100
|
-
return {
|
|
101
|
-
create: () => [domain, "create"],
|
|
102
|
-
update: (id) => (id ? [domain, "update", id] : [domain, "update"]),
|
|
103
|
-
delete: (id) => (id ? [domain, "delete", id] : [domain, "delete"]),
|
|
104
|
-
batch: (operation) => [domain, "batch", operation],
|
|
105
|
-
custom: (operation, id) => (id ? [domain, operation, id] : [domain, operation])
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { DefaultError, QueryFunction, QueryKey, UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
-
export interface BaseQueryConfig<TData> {
|
|
3
|
-
queryKey: QueryKey;
|
|
4
|
-
queryFn: QueryFunction<TData, QueryKey>;
|
|
5
|
-
staleTime?: number;
|
|
6
|
-
gcTime?: number;
|
|
7
|
-
enabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function createAppQueryOptions<TData>(config: BaseQueryConfig<TData>): UseQueryOptions<TData, DefaultError, TData, QueryKey>;
|
|
10
|
-
export interface SelectQueryConfig<TData, TSelected = TData> extends Omit<BaseQueryConfig<TData>, "enabled"> {
|
|
11
|
-
select: (data: TData) => TSelected;
|
|
12
|
-
}
|
|
13
|
-
export declare function createAppQueryOptionsWithSelect<TData, TSelected = TData>(config: SelectQueryConfig<TData, TSelected>): UseQueryOptions<TData, DefaultError, TSelected, QueryKey>;
|
|
14
|
-
export interface ListQueryConfig<TData> extends Omit<BaseQueryConfig<TData>, "staleTime" | "gcTime"> {
|
|
15
|
-
staleTime?: number;
|
|
16
|
-
gcTime?: number;
|
|
17
|
-
}
|
|
18
|
-
export declare function createListQueryOptions<TData>(config: ListQueryConfig<TData>): UseQueryOptions<TData, DefaultError, TData, QueryKey>;
|
|
19
|
-
//# sourceMappingURL=queryOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queryOptions.d.ts","sourceRoot":"","sources":["../../src/core/queryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIpG,MAAM,WAAW,eAAe,CAAC,KAAK;IACpC,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,CASlI;AAED,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAE,SAAQ,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC1G,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,SAAS,CAAC;CACpC;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC,CAShL;AAED,MAAM,WAAW,eAAe,CAAC,KAAK,CAAE,SAAQ,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IAClG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,CASnI"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { queryOptions } from "@tanstack/react-query";
|
|
2
|
-
import { DEFAULT_GC_TIME, DEFAULT_QUERY_CONFIG, DEFAULT_STALE_TIME } from "./config.js";
|
|
3
|
-
export function createAppQueryOptions(config) {
|
|
4
|
-
return queryOptions({
|
|
5
|
-
...DEFAULT_QUERY_CONFIG,
|
|
6
|
-
queryKey: config.queryKey,
|
|
7
|
-
queryFn: config.queryFn,
|
|
8
|
-
staleTime: config.staleTime ?? DEFAULT_QUERY_CONFIG.staleTime ?? DEFAULT_STALE_TIME,
|
|
9
|
-
gcTime: config.gcTime ?? DEFAULT_QUERY_CONFIG.gcTime ?? DEFAULT_GC_TIME,
|
|
10
|
-
enabled: config.enabled,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
export function createAppQueryOptionsWithSelect(config) {
|
|
14
|
-
return queryOptions({
|
|
15
|
-
...DEFAULT_QUERY_CONFIG,
|
|
16
|
-
queryKey: config.queryKey,
|
|
17
|
-
queryFn: config.queryFn,
|
|
18
|
-
select: config.select,
|
|
19
|
-
staleTime: config.staleTime ?? DEFAULT_QUERY_CONFIG.staleTime ?? DEFAULT_STALE_TIME,
|
|
20
|
-
gcTime: config.gcTime ?? DEFAULT_QUERY_CONFIG.gcTime ?? DEFAULT_GC_TIME,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export function createListQueryOptions(config) {
|
|
24
|
-
return queryOptions({
|
|
25
|
-
...DEFAULT_QUERY_CONFIG,
|
|
26
|
-
queryKey: config.queryKey,
|
|
27
|
-
queryFn: config.queryFn,
|
|
28
|
-
staleTime: config.staleTime ?? 0,
|
|
29
|
-
gcTime: config.gcTime ?? DEFAULT_QUERY_CONFIG.gcTime ?? DEFAULT_GC_TIME,
|
|
30
|
-
enabled: config.enabled,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/features/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACxG,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACnO,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { QueryClient } from "@tanstack/react-query";
|
|
2
|
-
import type { MutationFunctionRegistry, OfflineMutationOperation, OfflineQueueConfig, OfflineState } from "../types/offline";
|
|
3
|
-
export declare function setupOnlineManager(): void;
|
|
4
|
-
export declare const isOnline: () => boolean;
|
|
5
|
-
export declare function subscribeToOnlineStatus(callback: (online: boolean) => void): () => void;
|
|
6
|
-
export declare function configureOfflineQueries(_queryClient: QueryClient): void;
|
|
7
|
-
export declare function serializeMutationKey(mutationKey: unknown): string;
|
|
8
|
-
export declare function calculateExponentialBackoff(attempt: number, baseDelay?: number, maxDelay?: number): number;
|
|
9
|
-
declare class MutationRegistry implements MutationFunctionRegistry {
|
|
10
|
-
private registry;
|
|
11
|
-
register(key: string, fn: () => Promise<unknown>): void;
|
|
12
|
-
get(key: string): (() => Promise<unknown>) | undefined;
|
|
13
|
-
unregister(key: string): void;
|
|
14
|
-
clear(): void;
|
|
15
|
-
getKeys(): string[];
|
|
16
|
-
}
|
|
17
|
-
export declare const mutationRegistry: MutationRegistry;
|
|
18
|
-
export declare class OfflineQueueManager {
|
|
19
|
-
private queue;
|
|
20
|
-
private config;
|
|
21
|
-
private isExecuting;
|
|
22
|
-
private executionTimer;
|
|
23
|
-
private unsubscribeOnline;
|
|
24
|
-
private executingOperations;
|
|
25
|
-
constructor(config?: Partial<OfflineQueueConfig>);
|
|
26
|
-
add(operation: Omit<OfflineMutationOperation, "id" | "createdAt" | "retryCount">): Promise<string>;
|
|
27
|
-
remove(operationId: string): Promise<boolean>;
|
|
28
|
-
getState(): OfflineState;
|
|
29
|
-
getOperations(): OfflineMutationOperation[];
|
|
30
|
-
clear(): Promise<void>;
|
|
31
|
-
execute(): Promise<{
|
|
32
|
-
success: number;
|
|
33
|
-
failed: number;
|
|
34
|
-
skipped: number;
|
|
35
|
-
}>;
|
|
36
|
-
private executeOperation;
|
|
37
|
-
private sortOperationsByDependency;
|
|
38
|
-
private createBatches;
|
|
39
|
-
private persistQueue;
|
|
40
|
-
private loadQueue;
|
|
41
|
-
private cleanupOldOperations;
|
|
42
|
-
private setupOnlineListener;
|
|
43
|
-
private startAutoExecution;
|
|
44
|
-
private stopAutoExecution;
|
|
45
|
-
destroy(): void;
|
|
46
|
-
}
|
|
47
|
-
export declare function createOfflineQueueManager(config?: Partial<OfflineQueueConfig>): OfflineQueueManager;
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=offline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"offline.d.ts","sourceRoot":"","sources":["../../src/features/offline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAK7H,wBAAgB,kBAAkB,SAYjC;AACD,eAAO,MAAM,QAAQ,eAAiC,CAAC;AACvD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,cAA+C;AAC1H,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,WAAW,QAAI;AAWrE,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,CAOjE;AAGD,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAO,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAIvG;AACD,cAAM,gBAAiB,YAAW,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAA6C;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI;IACvD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS;IACtD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAC7B,KAAK,IAAI,IAAI;IACb,OAAO,IAAI,MAAM,EAAE;CACpB;AACD,eAAO,MAAM,gBAAgB,kBAAyB,CAAC;AAEvD,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,mBAAmB,CAAqB;gBACpC,MAAM,GAAE,OAAO,CAAC,kBAAkB,CAAM;IAO9C,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,GAAG,WAAW,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAUlG,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOnD,QAAQ,IAAI,YAAY;IAIxB,aAAa,IAAI,wBAAwB,EAAE;IACrC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;YAoBhE,gBAAgB;IAuB9B,OAAO,CAAC,0BAA0B;IAsBlC,OAAO,CAAC,aAAa;YAKP,YAAY;IAe1B,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,mBAAmB;IAG3B,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,iBAAiB;IAGzB,OAAO,IAAI,IAAI;CAKhB;AACD,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,mBAAmB,CAA4C"}
|
package/dist/features/offline.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { onlineManager } from "@tanstack/react-query";
|
|
2
|
-
import { ConnectionQuality, StorageType } from "../types/base.js";
|
|
3
|
-
import { isStorageAvailable } from "../utils/storage.js";
|
|
4
|
-
export function setupOnlineManager() {
|
|
5
|
-
if (typeof window === "undefined")
|
|
6
|
-
return;
|
|
7
|
-
onlineManager.setEventListener((setOnline) => {
|
|
8
|
-
const handleOnline = () => setOnline(true);
|
|
9
|
-
const handleOffline = () => setOnline(false);
|
|
10
|
-
window.addEventListener("online", handleOnline);
|
|
11
|
-
window.addEventListener("offline", handleOffline);
|
|
12
|
-
return () => {
|
|
13
|
-
window.removeEventListener("online", handleOnline);
|
|
14
|
-
window.removeEventListener("offline", handleOffline);
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
export const isOnline = () => onlineManager.isOnline();
|
|
19
|
-
export function subscribeToOnlineStatus(callback) { return onlineManager.subscribe(callback); }
|
|
20
|
-
export function configureOfflineQueries(_queryClient) { }
|
|
21
|
-
function sortObjectKeys(value) {
|
|
22
|
-
if (value === null || value === undefined)
|
|
23
|
-
return value;
|
|
24
|
-
if (typeof value !== "object")
|
|
25
|
-
return value;
|
|
26
|
-
if (Array.isArray(value))
|
|
27
|
-
return value.map(sortObjectKeys);
|
|
28
|
-
const sorted = {};
|
|
29
|
-
Object.keys(value).sort().forEach((key) => { sorted[key] = sortObjectKeys(value[key]); });
|
|
30
|
-
return sorted;
|
|
31
|
-
}
|
|
32
|
-
export function serializeMutationKey(mutationKey) {
|
|
33
|
-
try {
|
|
34
|
-
if (typeof mutationKey === "string")
|
|
35
|
-
return mutationKey;
|
|
36
|
-
return JSON.stringify(sortObjectKeys(mutationKey));
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return String(mutationKey);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const DEFAULT_QUEUE_CONFIG = { enabled: true, maxSize: 100, persist: true, storageKey: "tanstack-query-offline-queue", autoExecuteInterval: 5000, executeOnReconnect: true, operationTimeout: 30000, concurrency: 3 };
|
|
43
|
-
export function calculateExponentialBackoff(attempt, baseDelay = 1000, maxDelay = 30000) {
|
|
44
|
-
const delay = Math.min(baseDelay * 2 ** attempt, maxDelay);
|
|
45
|
-
const jitter = Math.random() * 0.3 * delay;
|
|
46
|
-
return Math.floor(delay + jitter);
|
|
47
|
-
}
|
|
48
|
-
class MutationRegistry {
|
|
49
|
-
constructor() {
|
|
50
|
-
this.registry = new Map();
|
|
51
|
-
}
|
|
52
|
-
register(key, fn) { this.registry.set(key, fn); }
|
|
53
|
-
get(key) { return this.registry.get(key); }
|
|
54
|
-
unregister(key) { this.registry.delete(key); }
|
|
55
|
-
clear() { this.registry.clear(); }
|
|
56
|
-
getKeys() { return Array.from(this.registry.keys()); }
|
|
57
|
-
}
|
|
58
|
-
export const mutationRegistry = new MutationRegistry();
|
|
59
|
-
export class OfflineQueueManager {
|
|
60
|
-
constructor(config = {}) {
|
|
61
|
-
this.queue = [];
|
|
62
|
-
this.isExecuting = false;
|
|
63
|
-
this.executionTimer = null;
|
|
64
|
-
this.unsubscribeOnline = null;
|
|
65
|
-
this.executingOperations = new Set();
|
|
66
|
-
this.config = { ...DEFAULT_QUEUE_CONFIG, ...config };
|
|
67
|
-
if (!this.config.enabled) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (this.config.persist) {
|
|
71
|
-
this.loadQueue();
|
|
72
|
-
}
|
|
73
|
-
if (this.config.executeOnReconnect) {
|
|
74
|
-
this.setupOnlineListener();
|
|
75
|
-
}
|
|
76
|
-
if (this.config.autoExecuteInterval > 0) {
|
|
77
|
-
this.startAutoExecution();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async add(operation) {
|
|
81
|
-
if (!this.config.enabled) {
|
|
82
|
-
throw new Error("Offline queue is disabled");
|
|
83
|
-
}
|
|
84
|
-
const id = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
85
|
-
const newOperation = { ...operation, id, createdAt: new Date(), retryCount: 0 };
|
|
86
|
-
if (this.queue.length >= this.config.maxSize) {
|
|
87
|
-
throw new Error(`Queue is full (max size: ${this.config.maxSize})`);
|
|
88
|
-
}
|
|
89
|
-
const insertIndex = this.queue.findIndex((op) => op.priority < newOperation.priority);
|
|
90
|
-
if (insertIndex === -1) {
|
|
91
|
-
this.queue.push(newOperation);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.queue.splice(insertIndex, 0, newOperation);
|
|
95
|
-
}
|
|
96
|
-
if (this.config.persist) {
|
|
97
|
-
await this.persistQueue();
|
|
98
|
-
}
|
|
99
|
-
return id;
|
|
100
|
-
}
|
|
101
|
-
async remove(operationId) {
|
|
102
|
-
const index = this.queue.findIndex((op) => op.id === operationId);
|
|
103
|
-
if (index === -1)
|
|
104
|
-
return false;
|
|
105
|
-
this.queue.splice(index, 1);
|
|
106
|
-
if (this.config.persist) {
|
|
107
|
-
await this.persistQueue();
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
getState() {
|
|
112
|
-
const online = isOnline();
|
|
113
|
-
return { isOffline: !online, networkStatus: { isOnline: online, isOffline: !online, connectionQuality: ConnectionQuality.UNKNOWN }, queuedOperations: this.queue.length, failedQueries: this.queue.filter((op) => op.lastError).length, lastSyncAt: this.queue.length === 0 ? new Date() : undefined, isRecovering: this.isExecuting };
|
|
114
|
-
}
|
|
115
|
-
getOperations() { return [...this.queue]; }
|
|
116
|
-
async clear() { this.queue = []; if (this.config.persist) {
|
|
117
|
-
await this.persistQueue();
|
|
118
|
-
} }
|
|
119
|
-
async execute() {
|
|
120
|
-
if (!this.config.enabled) {
|
|
121
|
-
return { success: 0, failed: 0, skipped: this.queue.length };
|
|
122
|
-
}
|
|
123
|
-
if (this.isExecuting) {
|
|
124
|
-
return { success: 0, failed: 0, skipped: this.queue.length };
|
|
125
|
-
}
|
|
126
|
-
if (!isOnline()) {
|
|
127
|
-
return { success: 0, failed: 0, skipped: this.queue.length };
|
|
128
|
-
}
|
|
129
|
-
this.isExecuting = true;
|
|
130
|
-
let successCount = 0;
|
|
131
|
-
let failedCount = 0;
|
|
132
|
-
let skippedCount = 0;
|
|
133
|
-
try {
|
|
134
|
-
const sortedOperations = this.sortOperationsByDependency();
|
|
135
|
-
const batches = this.createBatches(sortedOperations, this.config.concurrency);
|
|
136
|
-
for (const batch of batches) {
|
|
137
|
-
const results = await Promise.allSettled(batch.map((op) => this.executeOperation(op)));
|
|
138
|
-
results.forEach((result) => {
|
|
139
|
-
if (result.status === "fulfilled") {
|
|
140
|
-
if (result.value) {
|
|
141
|
-
successCount++;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
skippedCount++;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
failedCount++;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
this.queue = this.queue.filter((op) => op.lastError !== undefined);
|
|
153
|
-
if (this.config.persist) {
|
|
154
|
-
await this.persistQueue();
|
|
155
|
-
}
|
|
156
|
-
return { success: successCount, failed: failedCount, skipped: skippedCount };
|
|
157
|
-
}
|
|
158
|
-
finally {
|
|
159
|
-
this.isExecuting = false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async executeOperation(operation) {
|
|
163
|
-
if (this.executingOperations.has(operation.id)) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
if (operation.dependsOn && operation.dependsOn.length > 0) {
|
|
167
|
-
const dependenciesMet = operation.dependsOn.every((depId) => !this.queue.find((op) => op.id === depId));
|
|
168
|
-
if (!dependenciesMet) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
this.executingOperations.add(operation.id);
|
|
173
|
-
try {
|
|
174
|
-
const mutationKey = serializeMutationKey(operation.mutationKey);
|
|
175
|
-
const legacyMutationKey = Array.isArray(operation.mutationKey) ? operation.mutationKey.join("-") : String(operation.mutationKey);
|
|
176
|
-
const mutationFn = mutationRegistry.get(mutationKey) || mutationRegistry.get(legacyMutationKey) || operation.mutationFn;
|
|
177
|
-
const timeoutPromise = new Promise((_, reject) => { setTimeout(() => reject(new Error("Operation timeout")), this.config.operationTimeout); });
|
|
178
|
-
await Promise.race([mutationFn(), timeoutPromise]);
|
|
179
|
-
await this.remove(operation.id);
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
operation.retryCount++;
|
|
184
|
-
operation.lastError = error instanceof Error ? error : new Error(String(error));
|
|
185
|
-
if (operation.retryCount >= 5) { /* noop */ }
|
|
186
|
-
if (this.config.persist) {
|
|
187
|
-
await this.persistQueue();
|
|
188
|
-
}
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
finally {
|
|
192
|
-
this.executingOperations.delete(operation.id);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
sortOperationsByDependency() {
|
|
196
|
-
const sorted = [];
|
|
197
|
-
const visited = new Set();
|
|
198
|
-
const visiting = new Set();
|
|
199
|
-
const visit = (operation) => {
|
|
200
|
-
if (visited.has(operation.id))
|
|
201
|
-
return;
|
|
202
|
-
if (visiting.has(operation.id)) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
visiting.add(operation.id);
|
|
206
|
-
if (operation.dependsOn) {
|
|
207
|
-
for (const depId of operation.dependsOn) {
|
|
208
|
-
const dep = this.queue.find((op) => op.id === depId);
|
|
209
|
-
if (dep) {
|
|
210
|
-
visit(dep);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
visiting.delete(operation.id);
|
|
215
|
-
visited.add(operation.id);
|
|
216
|
-
sorted.push(operation);
|
|
217
|
-
};
|
|
218
|
-
const prioritySorted = [...this.queue].sort((a, b) => b.priority - a.priority);
|
|
219
|
-
for (const operation of prioritySorted) {
|
|
220
|
-
visit(operation);
|
|
221
|
-
}
|
|
222
|
-
return sorted;
|
|
223
|
-
}
|
|
224
|
-
createBatches(operations, batchSize) {
|
|
225
|
-
const batches = [];
|
|
226
|
-
for (let i = 0; i < operations.length; i += batchSize) {
|
|
227
|
-
batches.push(operations.slice(i, i + batchSize));
|
|
228
|
-
}
|
|
229
|
-
return batches;
|
|
230
|
-
}
|
|
231
|
-
async persistQueue() {
|
|
232
|
-
if (!isStorageAvailable(StorageType.LOCAL)) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
try {
|
|
236
|
-
const serialized = JSON.stringify(this.queue.map((op) => ({ ...op, createdAt: op.createdAt.toISOString(), mutationFn: undefined })));
|
|
237
|
-
localStorage.setItem(this.config.storageKey, serialized);
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
if (error instanceof Error && error.name === "QuotaExceededError") {
|
|
241
|
-
this.cleanupOldOperations();
|
|
242
|
-
try {
|
|
243
|
-
const serialized = JSON.stringify(this.queue.map((op) => ({ ...op, createdAt: op.createdAt.toISOString(), mutationFn: undefined })));
|
|
244
|
-
localStorage.setItem(this.config.storageKey, serialized);
|
|
245
|
-
}
|
|
246
|
-
catch { }
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
loadQueue() {
|
|
251
|
-
if (!isStorageAvailable(StorageType.LOCAL)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
try {
|
|
255
|
-
const stored = localStorage.getItem(this.config.storageKey);
|
|
256
|
-
if (!stored)
|
|
257
|
-
return;
|
|
258
|
-
const parsed = JSON.parse(stored);
|
|
259
|
-
if (!Array.isArray(parsed)) {
|
|
260
|
-
this.queue = [];
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
this.queue = parsed.map((op) => ({ ...op, createdAt: new Date(op.createdAt), mutationFn: op.mutationFn || (() => Promise.reject(new Error("Mutation function not registered"))) }));
|
|
264
|
-
}
|
|
265
|
-
catch {
|
|
266
|
-
this.queue = [];
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
cleanupOldOperations() {
|
|
270
|
-
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
271
|
-
this.queue = this.queue.filter((op) => op.createdAt > oneDayAgo);
|
|
272
|
-
}
|
|
273
|
-
setupOnlineListener() {
|
|
274
|
-
this.unsubscribeOnline = subscribeToOnlineStatus((online) => { if (online && this.queue.length > 0) {
|
|
275
|
-
this.execute().catch(() => { });
|
|
276
|
-
} });
|
|
277
|
-
}
|
|
278
|
-
startAutoExecution() {
|
|
279
|
-
this.executionTimer = setInterval(() => {
|
|
280
|
-
if (isOnline() && this.queue.length > 0 && !this.isExecuting) {
|
|
281
|
-
this.execute().catch(() => { });
|
|
282
|
-
}
|
|
283
|
-
}, this.config.autoExecuteInterval);
|
|
284
|
-
}
|
|
285
|
-
stopAutoExecution() {
|
|
286
|
-
if (this.executionTimer) {
|
|
287
|
-
clearInterval(this.executionTimer);
|
|
288
|
-
this.executionTimer = null;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
destroy() {
|
|
292
|
-
this.stopAutoExecution();
|
|
293
|
-
if (this.unsubscribeOnline) {
|
|
294
|
-
this.unsubscribeOnline();
|
|
295
|
-
this.unsubscribeOnline = null;
|
|
296
|
-
}
|
|
297
|
-
this.executingOperations.clear();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
export function createOfflineQueueManager(config) { return new OfflineQueueManager(config); }
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Query } from "@tanstack/react-query";
|
|
2
|
-
import type { PersistedClient, Persister } from "@tanstack/react-query-persist-client";
|
|
3
|
-
export interface PersistOptions {
|
|
4
|
-
maxAge?: number;
|
|
5
|
-
onlyPersistSuccess?: boolean;
|
|
6
|
-
dehydrateOptions?: {
|
|
7
|
-
shouldDehydrateQuery?: (query: Query) => boolean;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export declare function createPersistOptions(config?: Partial<PersistOptions>): {
|
|
11
|
-
maxAge: number;
|
|
12
|
-
dehydrateOptions?: {
|
|
13
|
-
shouldDehydrateQuery?: (query: Query) => boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare function createPersister(storageKey?: string, storage?: Storage, onError?: (error: Error) => void): Persister | undefined;
|
|
17
|
-
export declare function clearCache(key?: string): void;
|
|
18
|
-
export declare function clearExpiredCache(key?: string, maxAge?: number): void;
|
|
19
|
-
export declare function migrateToIndexedDB(localStorageKey: string | undefined, indexedDBKey: string | undefined, indexedDBStorage: Storage | {
|
|
20
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
21
|
-
}): Promise<boolean>;
|
|
22
|
-
export declare function checkStorageSize(key?: string): {
|
|
23
|
-
sizeInBytes: number;
|
|
24
|
-
sizeInMB: number;
|
|
25
|
-
shouldMigrate: boolean;
|
|
26
|
-
message: string;
|
|
27
|
-
};
|
|
28
|
-
export declare function getStorageStats(key?: string): {
|
|
29
|
-
exists: boolean;
|
|
30
|
-
age?: number;
|
|
31
|
-
queriesCount?: number;
|
|
32
|
-
mutationsCount?: number;
|
|
33
|
-
sizeInfo: ReturnType<typeof checkStorageSize>;
|
|
34
|
-
};
|
|
35
|
-
export type { PersistedClient, Persister };
|
|
36
|
-
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../src/features/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAuBvF,MAAM,WAAW,cAAc;IAAG,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,gBAAgB,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAA;KAAE,CAAA;CAAE;AAC1J,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAA;KAAE,CAAA;CAAE,CAiBtK;AACD,wBAAgB,eAAe,CAAC,UAAU,SAAyB,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,SAAS,GAAG,SAAS,CAa/I;AACD,wBAAgB,UAAU,CAAC,GAAG,SAAyB,GAAG,IAAI,CAA0D;AACxH,wBAAgB,iBAAiB,CAAC,GAAG,SAAyB,EAAE,MAAM,SAAyB,GAAG,IAAI,CAQrG;AACD,wBAAsB,kBAAkB,CAAC,eAAe,oBAAyB,EAAE,YAAY,oBAAyB,EAAE,gBAAgB,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAWlO;AACD,wBAAgB,gBAAgB,CAAC,GAAG,SAAyB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CASjJ;AACD,wBAAgB,eAAe,CAAC,GAAG,SAAyB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;CAAE,CAS9L;AACD,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC"}
|