@tatsuokaniwa/swr-firestore 0.2.2 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tatsuo Kaniwa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -66,6 +66,18 @@ export default function App() {
66
66
 
67
67
  ## API
68
68
 
69
+ ```ts
70
+ import {
71
+ useCollection, // Subscription for collection
72
+ useCollectionCount, // Wrapper for getCountFromServer for collection
73
+ useCollectionGroup, // Subscription for collectionGroup
74
+ useCollectionGroupCount, // Wrapper for getCountFromServer for collectionGroup
75
+ useDoc, // Subscription for document
76
+ useGetDocs, // Fetch documents with firestore's getDocs
77
+ useGetDoc, // Fetch documents with firestore's getDoc
78
+ } from "@tatsuokaniwa/swr-firestore";
79
+ ```
80
+
69
81
  ### Type definitions for parameters
70
82
 
71
83
  ```ts
@@ -74,11 +86,12 @@ import type { orderBy, where } from "firebase/firestore";
74
86
  type KeyParams<T> = {
75
87
  // The path to the collection or document of Firestore.
76
88
  path: string;
77
- where?: [Extract<keyof T, string>, Parameters<typeof where>[1], ValueOf<T>][];
78
- orderBy?: [Extract<keyof T, string>, Parameters<typeof orderBy>[1]][];
89
+ // `Paths` means object's property path, including nested object
90
+ where?: [Paths<T>, Parameters<typeof where>[1], ValueOf<T>][];
91
+ orderBy?: [Paths<T>, Parameters<typeof orderBy>[1]][];
79
92
  limit?: number;
80
93
  // Array of field names that should be parsed as dates.
81
- parseDates?: Extract<keyof T, string>[];
94
+ parseDates?: Paths<T>[];
82
95
  };
83
96
  ```
84
97
 
@@ -214,7 +227,6 @@ Returns [`SWRResponse`](https://swr.vercel.app/docs/api#return-values)
214
227
  - `isValidating`: if there's a request or revalidation loading
215
228
  - `mutate(data?, options?)`: function to mutate the cached data (details)
216
229
 
217
-
218
230
  ```ts
219
231
  import { useGetDocs } from "@tatsuokaniwa/swr-firestore";
220
232
 
@@ -222,6 +234,7 @@ const { data, error } = useGetDocs<Post>({
222
234
  path: `Posts`,
223
235
  });
224
236
  ```
237
+
225
238
  ### `useGetDoc(params, swrOptions)`
226
239
 
227
240
  Fetch the document with firestore's [getDoc](https://firebase.google.com/docs/reference/js/firestore_.md#getdoc) function