@tatsuokaniwa/swr-firestore 1.1.0 → 1.1.1
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 +6 -3
- package/dist/hooks/useCollection.d.ts +2 -1
- package/dist/hooks/useCollectionCount.d.ts +32 -2
- package/dist/hooks/useCollectionGroup.d.ts +2 -1
- package/dist/hooks/useCollectionGroupCount.d.ts +32 -2
- package/dist/hooks/useDoc.d.ts +2 -1
- package/dist/hooks/useGetDoc.d.ts +32 -2
- package/dist/hooks/useGetDocs.d.ts +32 -2
- package/dist/index.js +33 -20
- package/dist/index.umd.cjs +33 -20
- package/dist/middleware/serializeMiddleware.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,13 +140,14 @@ import type { QueryDocumentSnapshot } from "firebase/firestore";
|
|
|
140
140
|
type DocumentData<T> = T & Pick<QueryDocumentSnapshot, "exists" | "id" | "ref">;
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
### `useCollection(params)`
|
|
143
|
+
### `useCollection(params, swrOptions)`
|
|
144
144
|
|
|
145
145
|
Subscription for collection
|
|
146
146
|
|
|
147
147
|
#### Parameters
|
|
148
148
|
|
|
149
149
|
- `params`: KeyParams | null
|
|
150
|
+
- `swrOptions`: [Options for SWR hook](https://swr.vercel.app/docs/api#options) except `fetcher`
|
|
150
151
|
|
|
151
152
|
#### Return values
|
|
152
153
|
|
|
@@ -192,13 +193,14 @@ const {
|
|
|
192
193
|
});
|
|
193
194
|
```
|
|
194
195
|
|
|
195
|
-
### `useCollectionGroup(params)`
|
|
196
|
+
### `useCollectionGroup(params, swrOptions)`
|
|
196
197
|
|
|
197
198
|
Subscription for collectionGroup
|
|
198
199
|
|
|
199
200
|
#### Parameters
|
|
200
201
|
|
|
201
202
|
- `params`: KeyParams | null
|
|
203
|
+
- `swrOptions`: [Options for SWR hook](https://swr.vercel.app/docs/api#options) except `fetcher`
|
|
202
204
|
|
|
203
205
|
#### Return values
|
|
204
206
|
|
|
@@ -224,13 +226,14 @@ Returns [`SWRResponse`](https://swr.vercel.app/docs/api#return-values)
|
|
|
224
226
|
- `isValidating`: if there's a request or revalidation loading
|
|
225
227
|
- `mutate(data?, options?)`: function to mutate the cached data (details)
|
|
226
228
|
|
|
227
|
-
### `useDoc(params)`
|
|
229
|
+
### `useDoc(params, swrOptions)`
|
|
228
230
|
|
|
229
231
|
Subscription for document
|
|
230
232
|
|
|
231
233
|
#### Parameters
|
|
232
234
|
|
|
233
235
|
- `params`: KeyParams except `where`, `orderBy`, `limit` | null
|
|
236
|
+
- `swrOptions`: [Options for SWR hook](https://swr.vercel.app/docs/api#options) except `fetcher`
|
|
234
237
|
|
|
235
238
|
#### Return values
|
|
236
239
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SWRSubscriptionResponse } from "swr/subscription";
|
|
2
2
|
import type { FirestoreError } from "firebase/firestore";
|
|
3
3
|
import type { DocumentData, KeyParams } from "../util/type";
|
|
4
|
-
|
|
4
|
+
import type { SWRConfiguration } from "swr";
|
|
5
|
+
declare const useCollection: <T>(params: KeyParams<T> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => SWRSubscriptionResponse<DocumentData<T>[], FirestoreError>;
|
|
5
6
|
export default useCollection;
|
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SWRConfiguration } from "swr";
|
|
2
2
|
import type { KeyParamsForCount } from "../util/type";
|
|
3
|
-
declare const useCollectionCount: <T>(params: KeyParamsForCount<T> | null, swrOptions?: Omit<
|
|
3
|
+
declare const useCollectionCount: <T>(params: KeyParamsForCount<T> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => import("swr/_internal").SWRResponse<number | undefined, any, {
|
|
4
|
+
use: import("swr/_internal").Middleware[];
|
|
5
|
+
errorRetryInterval?: number | undefined;
|
|
6
|
+
errorRetryCount?: number | undefined;
|
|
7
|
+
loadingTimeout?: number | undefined;
|
|
8
|
+
focusThrottleInterval?: number | undefined;
|
|
9
|
+
dedupingInterval?: number | undefined;
|
|
10
|
+
refreshInterval?: number | ((latestData: any) => number) | undefined;
|
|
11
|
+
refreshWhenHidden?: boolean | undefined;
|
|
12
|
+
refreshWhenOffline?: boolean | undefined;
|
|
13
|
+
revalidateOnFocus?: boolean | undefined;
|
|
14
|
+
revalidateOnReconnect?: boolean | undefined;
|
|
15
|
+
revalidateOnMount?: boolean | undefined;
|
|
16
|
+
revalidateIfStale?: boolean | undefined;
|
|
17
|
+
shouldRetryOnError?: boolean | ((err: any) => boolean) | undefined;
|
|
18
|
+
keepPreviousData?: boolean | undefined;
|
|
19
|
+
suspense?: boolean | undefined;
|
|
20
|
+
fallbackData?: any;
|
|
21
|
+
fallback?: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
} | undefined;
|
|
24
|
+
isPaused?: (() => boolean) | undefined;
|
|
25
|
+
onLoadingSlow?: ((key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
26
|
+
onSuccess?: ((data: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
27
|
+
onError?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
28
|
+
onErrorRetry?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>, revalidate: import("swr/_internal").Revalidator, revalidateOpts: Required<import("swr/_internal").RevalidatorOptions>) => void) | undefined;
|
|
29
|
+
onDiscarded?: ((key: string) => void) | undefined;
|
|
30
|
+
compare?: ((a: any, b: any) => boolean) | undefined;
|
|
31
|
+
isOnline?: (() => boolean) | undefined;
|
|
32
|
+
isVisible?: (() => boolean) | undefined;
|
|
33
|
+
}>;
|
|
4
34
|
export default useCollectionCount;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SWRSubscriptionResponse } from "swr/subscription";
|
|
2
2
|
import type { FirestoreError } from "firebase/firestore";
|
|
3
3
|
import type { DocumentData, KeyParams } from "../util/type";
|
|
4
|
-
|
|
4
|
+
import type { SWRConfiguration } from "swr";
|
|
5
|
+
declare const useCollectionGroup: <T>(params: KeyParams<T> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => SWRSubscriptionResponse<DocumentData<T>[], FirestoreError>;
|
|
5
6
|
export default useCollectionGroup;
|
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SWRConfiguration } from "swr";
|
|
2
2
|
import type { KeyParamsForCount } from "../util/type";
|
|
3
|
-
declare const useCollectionGroupCount: <T>(params: KeyParamsForCount<T> | null, swrOptions?: Omit<
|
|
3
|
+
declare const useCollectionGroupCount: <T>(params: KeyParamsForCount<T> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => import("swr/_internal").SWRResponse<number | undefined, any, {
|
|
4
|
+
use: import("swr/_internal").Middleware[];
|
|
5
|
+
errorRetryInterval?: number | undefined;
|
|
6
|
+
errorRetryCount?: number | undefined;
|
|
7
|
+
loadingTimeout?: number | undefined;
|
|
8
|
+
focusThrottleInterval?: number | undefined;
|
|
9
|
+
dedupingInterval?: number | undefined;
|
|
10
|
+
refreshInterval?: number | ((latestData: any) => number) | undefined;
|
|
11
|
+
refreshWhenHidden?: boolean | undefined;
|
|
12
|
+
refreshWhenOffline?: boolean | undefined;
|
|
13
|
+
revalidateOnFocus?: boolean | undefined;
|
|
14
|
+
revalidateOnReconnect?: boolean | undefined;
|
|
15
|
+
revalidateOnMount?: boolean | undefined;
|
|
16
|
+
revalidateIfStale?: boolean | undefined;
|
|
17
|
+
shouldRetryOnError?: boolean | ((err: any) => boolean) | undefined;
|
|
18
|
+
keepPreviousData?: boolean | undefined;
|
|
19
|
+
suspense?: boolean | undefined;
|
|
20
|
+
fallbackData?: any;
|
|
21
|
+
fallback?: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
} | undefined;
|
|
24
|
+
isPaused?: (() => boolean) | undefined;
|
|
25
|
+
onLoadingSlow?: ((key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
26
|
+
onSuccess?: ((data: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
27
|
+
onError?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
28
|
+
onErrorRetry?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>, revalidate: import("swr/_internal").Revalidator, revalidateOpts: Required<import("swr/_internal").RevalidatorOptions>) => void) | undefined;
|
|
29
|
+
onDiscarded?: ((key: string) => void) | undefined;
|
|
30
|
+
compare?: ((a: any, b: any) => boolean) | undefined;
|
|
31
|
+
isOnline?: (() => boolean) | undefined;
|
|
32
|
+
isVisible?: (() => boolean) | undefined;
|
|
33
|
+
}>;
|
|
4
34
|
export default useCollectionGroupCount;
|
package/dist/hooks/useDoc.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FirestoreError } from "firebase/firestore";
|
|
2
2
|
import type { SWRSubscriptionResponse } from "swr/subscription";
|
|
3
3
|
import type { DocumentData, KeyParams } from "../util/type";
|
|
4
|
-
|
|
4
|
+
import type { SWRConfiguration } from "swr";
|
|
5
|
+
declare const useDoc: <T>(params: Omit<KeyParams<T>, "orderBy" | "where" | "limit"> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => SWRSubscriptionResponse<DocumentData<T>, FirestoreError>;
|
|
5
6
|
export default useDoc;
|
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SWRConfiguration } from "swr";
|
|
2
2
|
import type { DocumentData, GetDocKeyParams } from "../util/type";
|
|
3
|
-
declare const useGetDoc: <T>(params: Omit<GetDocKeyParams<T>, "orderBy" | "where" | "limit"> | null, swrOptions?: Omit<
|
|
3
|
+
declare const useGetDoc: <T>(params: Omit<GetDocKeyParams<T>, "orderBy" | "where" | "limit"> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => import("swr/_internal").SWRResponse<DocumentData<T> | undefined, any, {
|
|
4
|
+
use: import("swr/_internal").Middleware[];
|
|
5
|
+
errorRetryInterval?: number | undefined;
|
|
6
|
+
errorRetryCount?: number | undefined;
|
|
7
|
+
loadingTimeout?: number | undefined;
|
|
8
|
+
focusThrottleInterval?: number | undefined;
|
|
9
|
+
dedupingInterval?: number | undefined;
|
|
10
|
+
refreshInterval?: number | ((latestData: any) => number) | undefined;
|
|
11
|
+
refreshWhenHidden?: boolean | undefined;
|
|
12
|
+
refreshWhenOffline?: boolean | undefined;
|
|
13
|
+
revalidateOnFocus?: boolean | undefined;
|
|
14
|
+
revalidateOnReconnect?: boolean | undefined;
|
|
15
|
+
revalidateOnMount?: boolean | undefined;
|
|
16
|
+
revalidateIfStale?: boolean | undefined;
|
|
17
|
+
shouldRetryOnError?: boolean | ((err: any) => boolean) | undefined;
|
|
18
|
+
keepPreviousData?: boolean | undefined;
|
|
19
|
+
suspense?: boolean | undefined;
|
|
20
|
+
fallbackData?: any;
|
|
21
|
+
fallback?: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
} | undefined;
|
|
24
|
+
isPaused?: (() => boolean) | undefined;
|
|
25
|
+
onLoadingSlow?: ((key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
26
|
+
onSuccess?: ((data: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
27
|
+
onError?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
28
|
+
onErrorRetry?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>, revalidate: import("swr/_internal").Revalidator, revalidateOpts: Required<import("swr/_internal").RevalidatorOptions>) => void) | undefined;
|
|
29
|
+
onDiscarded?: ((key: string) => void) | undefined;
|
|
30
|
+
compare?: ((a: any, b: any) => boolean) | undefined;
|
|
31
|
+
isOnline?: (() => boolean) | undefined;
|
|
32
|
+
isVisible?: (() => boolean) | undefined;
|
|
33
|
+
}>;
|
|
4
34
|
export default useGetDoc;
|
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SWRConfiguration } from "swr";
|
|
2
2
|
import type { DocumentData, GetDocKeyParams } from "../util/type";
|
|
3
|
-
declare const useGetDocs: <T>(params: GetDocKeyParams<T> | null, swrOptions?: Omit<
|
|
3
|
+
declare const useGetDocs: <T>(params: GetDocKeyParams<T> | null, swrOptions?: Omit<SWRConfiguration, "fetcher">) => import("swr/_internal").SWRResponse<DocumentData<T>[] | undefined, any, {
|
|
4
|
+
use: import("swr/_internal").Middleware[];
|
|
5
|
+
errorRetryInterval?: number | undefined;
|
|
6
|
+
errorRetryCount?: number | undefined;
|
|
7
|
+
loadingTimeout?: number | undefined;
|
|
8
|
+
focusThrottleInterval?: number | undefined;
|
|
9
|
+
dedupingInterval?: number | undefined;
|
|
10
|
+
refreshInterval?: number | ((latestData: any) => number) | undefined;
|
|
11
|
+
refreshWhenHidden?: boolean | undefined;
|
|
12
|
+
refreshWhenOffline?: boolean | undefined;
|
|
13
|
+
revalidateOnFocus?: boolean | undefined;
|
|
14
|
+
revalidateOnReconnect?: boolean | undefined;
|
|
15
|
+
revalidateOnMount?: boolean | undefined;
|
|
16
|
+
revalidateIfStale?: boolean | undefined;
|
|
17
|
+
shouldRetryOnError?: boolean | ((err: any) => boolean) | undefined;
|
|
18
|
+
keepPreviousData?: boolean | undefined;
|
|
19
|
+
suspense?: boolean | undefined;
|
|
20
|
+
fallbackData?: any;
|
|
21
|
+
fallback?: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
} | undefined;
|
|
24
|
+
isPaused?: (() => boolean) | undefined;
|
|
25
|
+
onLoadingSlow?: ((key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
26
|
+
onSuccess?: ((data: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
27
|
+
onError?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>) => void) | undefined;
|
|
28
|
+
onErrorRetry?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>>, revalidate: import("swr/_internal").Revalidator, revalidateOpts: Required<import("swr/_internal").RevalidatorOptions>) => void) | undefined;
|
|
29
|
+
onDiscarded?: ((key: string) => void) | undefined;
|
|
30
|
+
compare?: ((a: any, b: any) => boolean) | undefined;
|
|
31
|
+
isOnline?: (() => boolean) | undefined;
|
|
32
|
+
isVisible?: (() => boolean) | undefined;
|
|
33
|
+
}>;
|
|
4
34
|
export default useGetDocs;
|
package/dist/index.js
CHANGED
|
@@ -27,12 +27,17 @@ const getFirestoreConverter = (parseDates) => ({
|
|
|
27
27
|
const isQueryConstraintParams = (params) => {
|
|
28
28
|
return params.queryConstraints != null;
|
|
29
29
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const serializeMiddleware = (useSWRNext) => {
|
|
31
|
+
return (key, fetcher, config) => {
|
|
32
|
+
let swrKey = key;
|
|
33
|
+
if (key != null && typeof key === "object" && "queryConstraints" in key) {
|
|
34
|
+
swrKey = JSON.parse(JSON.stringify(key));
|
|
35
|
+
}
|
|
36
|
+
return useSWRNext(swrKey, fetcher, config);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const useCollection = (params, swrOptions) => {
|
|
40
|
+
return useSWRSubscription(params, (_, { next }) => {
|
|
36
41
|
if (params == null) {
|
|
37
42
|
return () => {
|
|
38
43
|
};
|
|
@@ -53,7 +58,7 @@ const useCollection = (params) => {
|
|
|
53
58
|
next(error);
|
|
54
59
|
});
|
|
55
60
|
return () => unsub && unsub();
|
|
56
|
-
});
|
|
61
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
57
62
|
};
|
|
58
63
|
const useCollectionCount = (params, swrOptions) => {
|
|
59
64
|
let swrKey = params;
|
|
@@ -76,14 +81,13 @@ const useCollectionCount = (params, swrOptions) => {
|
|
|
76
81
|
const sn = await getCountFromServer(q);
|
|
77
82
|
return sn.data().count;
|
|
78
83
|
};
|
|
79
|
-
return useSWR(swrKey, fetcher,
|
|
84
|
+
return useSWR(swrKey, fetcher, {
|
|
85
|
+
...swrOptions,
|
|
86
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
87
|
+
});
|
|
80
88
|
};
|
|
81
|
-
const useCollectionGroup = (params) => {
|
|
82
|
-
|
|
83
|
-
if (params != null && isQueryConstraintParams(params)) {
|
|
84
|
-
swrKey = JSON.parse(JSON.stringify(params));
|
|
85
|
-
}
|
|
86
|
-
return useSWRSubscription(swrKey, (_, { next }) => {
|
|
89
|
+
const useCollectionGroup = (params, swrOptions) => {
|
|
90
|
+
return useSWRSubscription(params, (_, { next }) => {
|
|
87
91
|
if (params == null) {
|
|
88
92
|
return () => {
|
|
89
93
|
};
|
|
@@ -104,7 +108,7 @@ const useCollectionGroup = (params) => {
|
|
|
104
108
|
next(error);
|
|
105
109
|
});
|
|
106
110
|
return () => unsub && unsub();
|
|
107
|
-
});
|
|
111
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
108
112
|
};
|
|
109
113
|
const useCollectionGroupCount = (params, swrOptions) => {
|
|
110
114
|
let swrKey = params;
|
|
@@ -127,9 +131,12 @@ const useCollectionGroupCount = (params, swrOptions) => {
|
|
|
127
131
|
const sn = await getCountFromServer(q);
|
|
128
132
|
return sn.data().count;
|
|
129
133
|
};
|
|
130
|
-
return useSWR(swrKey, fetcher,
|
|
134
|
+
return useSWR(swrKey, fetcher, {
|
|
135
|
+
...swrOptions,
|
|
136
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
137
|
+
});
|
|
131
138
|
};
|
|
132
|
-
const useDoc = (params) => {
|
|
139
|
+
const useDoc = (params, swrOptions) => {
|
|
133
140
|
return useSWRSubscription(params, (_, { next }) => {
|
|
134
141
|
if (params == null) {
|
|
135
142
|
return () => {
|
|
@@ -144,7 +151,7 @@ const useDoc = (params) => {
|
|
|
144
151
|
next(error);
|
|
145
152
|
});
|
|
146
153
|
return () => unsub && unsub();
|
|
147
|
-
});
|
|
154
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
148
155
|
};
|
|
149
156
|
const useGetDoc = (params, swrOptions) => {
|
|
150
157
|
const fetcher = async () => {
|
|
@@ -158,7 +165,10 @@ const useGetDoc = (params, swrOptions) => {
|
|
|
158
165
|
const sn = await getFn(ref.withConverter(converter));
|
|
159
166
|
return sn.data();
|
|
160
167
|
};
|
|
161
|
-
return useSWR(params, fetcher,
|
|
168
|
+
return useSWR(params, fetcher, {
|
|
169
|
+
...swrOptions,
|
|
170
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
171
|
+
});
|
|
162
172
|
};
|
|
163
173
|
const useGetDocs = (params, swrOptions) => {
|
|
164
174
|
let swrKey = params;
|
|
@@ -183,7 +193,10 @@ const useGetDocs = (params, swrOptions) => {
|
|
|
183
193
|
const sn = await getFn(q.withConverter(converter));
|
|
184
194
|
return sn.docs.map((x) => x.data());
|
|
185
195
|
};
|
|
186
|
-
return useSWR(swrKey, fetcher,
|
|
196
|
+
return useSWR(swrKey, fetcher, {
|
|
197
|
+
...swrOptions,
|
|
198
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
199
|
+
});
|
|
187
200
|
};
|
|
188
201
|
export {
|
|
189
202
|
useCollection,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -27,12 +27,17 @@
|
|
|
27
27
|
const isQueryConstraintParams = (params) => {
|
|
28
28
|
return params.queryConstraints != null;
|
|
29
29
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const serializeMiddleware = (useSWRNext) => {
|
|
31
|
+
return (key, fetcher, config) => {
|
|
32
|
+
let swrKey = key;
|
|
33
|
+
if (key != null && typeof key === "object" && "queryConstraints" in key) {
|
|
34
|
+
swrKey = JSON.parse(JSON.stringify(key));
|
|
35
|
+
}
|
|
36
|
+
return useSWRNext(swrKey, fetcher, config);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const useCollection = (params, swrOptions) => {
|
|
40
|
+
return useSWRSubscription(params, (_, { next }) => {
|
|
36
41
|
if (params == null) {
|
|
37
42
|
return () => {
|
|
38
43
|
};
|
|
@@ -53,7 +58,7 @@
|
|
|
53
58
|
next(error);
|
|
54
59
|
});
|
|
55
60
|
return () => unsub && unsub();
|
|
56
|
-
});
|
|
61
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
57
62
|
};
|
|
58
63
|
const useCollectionCount = (params, swrOptions) => {
|
|
59
64
|
let swrKey = params;
|
|
@@ -76,14 +81,13 @@
|
|
|
76
81
|
const sn = await firestore.getCountFromServer(q);
|
|
77
82
|
return sn.data().count;
|
|
78
83
|
};
|
|
79
|
-
return useSWR(swrKey, fetcher,
|
|
84
|
+
return useSWR(swrKey, fetcher, {
|
|
85
|
+
...swrOptions,
|
|
86
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
87
|
+
});
|
|
80
88
|
};
|
|
81
|
-
const useCollectionGroup = (params) => {
|
|
82
|
-
|
|
83
|
-
if (params != null && isQueryConstraintParams(params)) {
|
|
84
|
-
swrKey = JSON.parse(JSON.stringify(params));
|
|
85
|
-
}
|
|
86
|
-
return useSWRSubscription(swrKey, (_, { next }) => {
|
|
89
|
+
const useCollectionGroup = (params, swrOptions) => {
|
|
90
|
+
return useSWRSubscription(params, (_, { next }) => {
|
|
87
91
|
if (params == null) {
|
|
88
92
|
return () => {
|
|
89
93
|
};
|
|
@@ -104,7 +108,7 @@
|
|
|
104
108
|
next(error);
|
|
105
109
|
});
|
|
106
110
|
return () => unsub && unsub();
|
|
107
|
-
});
|
|
111
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
108
112
|
};
|
|
109
113
|
const useCollectionGroupCount = (params, swrOptions) => {
|
|
110
114
|
let swrKey = params;
|
|
@@ -127,9 +131,12 @@
|
|
|
127
131
|
const sn = await firestore.getCountFromServer(q);
|
|
128
132
|
return sn.data().count;
|
|
129
133
|
};
|
|
130
|
-
return useSWR(swrKey, fetcher,
|
|
134
|
+
return useSWR(swrKey, fetcher, {
|
|
135
|
+
...swrOptions,
|
|
136
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
137
|
+
});
|
|
131
138
|
};
|
|
132
|
-
const useDoc = (params) => {
|
|
139
|
+
const useDoc = (params, swrOptions) => {
|
|
133
140
|
return useSWRSubscription(params, (_, { next }) => {
|
|
134
141
|
if (params == null) {
|
|
135
142
|
return () => {
|
|
@@ -144,7 +151,7 @@
|
|
|
144
151
|
next(error);
|
|
145
152
|
});
|
|
146
153
|
return () => unsub && unsub();
|
|
147
|
-
});
|
|
154
|
+
}, { ...swrOptions, use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []] });
|
|
148
155
|
};
|
|
149
156
|
const useGetDoc = (params, swrOptions) => {
|
|
150
157
|
const fetcher = async () => {
|
|
@@ -158,7 +165,10 @@
|
|
|
158
165
|
const sn = await getFn(ref.withConverter(converter));
|
|
159
166
|
return sn.data();
|
|
160
167
|
};
|
|
161
|
-
return useSWR(params, fetcher,
|
|
168
|
+
return useSWR(params, fetcher, {
|
|
169
|
+
...swrOptions,
|
|
170
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
171
|
+
});
|
|
162
172
|
};
|
|
163
173
|
const useGetDocs = (params, swrOptions) => {
|
|
164
174
|
let swrKey = params;
|
|
@@ -183,7 +193,10 @@
|
|
|
183
193
|
const sn = await getFn(q.withConverter(converter));
|
|
184
194
|
return sn.docs.map((x) => x.data());
|
|
185
195
|
};
|
|
186
|
-
return useSWR(swrKey, fetcher,
|
|
196
|
+
return useSWR(swrKey, fetcher, {
|
|
197
|
+
...swrOptions,
|
|
198
|
+
use: [serializeMiddleware, ...(swrOptions == null ? void 0 : swrOptions.use) ?? []]
|
|
199
|
+
});
|
|
187
200
|
};
|
|
188
201
|
exports2.useCollection = useCollection;
|
|
189
202
|
exports2.useCollectionCount = useCollectionCount;
|
package/package.json
CHANGED