@hyper-fetch/firebase 8.1.1 โ 8.2.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 +90 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
# ๐ฅ Hyper Fetch Firebase
|
|
1
|
+
# ๐ฅ Hyper Fetch Firebase
|
|
2
2
|
|
|
3
|
-
<p>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Type-safe Firebase/Firestore client built on HyperFetch. CRUD, realtime listeners, auth โ all typed.</b>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
4
8
|
<a href="https://bettertyped.com/">
|
|
5
9
|
<img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
|
|
6
10
|
</a>
|
|
@@ -13,58 +17,112 @@
|
|
|
13
17
|
<a href="https://www.npmjs.com/package/@hyper-fetch/firebase">
|
|
14
18
|
<img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/firebase.svg?logo=npm&color=e76f51" />
|
|
15
19
|
</a>
|
|
16
|
-
<a href="https://
|
|
17
|
-
<img src="https://custom-icon-badges.demolab.com/
|
|
20
|
+
<a href="https://www.npmjs.com/package/@hyper-fetch/firebase">
|
|
21
|
+
<img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/firebase?logoColor=fff&logo=trending-up" />
|
|
18
22
|
</a>
|
|
19
23
|
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
20
|
-
<img src="https://custom-icon-badges.demolab.com/badge
|
|
24
|
+
<img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
|
|
21
25
|
</a>
|
|
22
|
-
<a href="https://
|
|
26
|
+
<a href="https://bundlephobia.com/package/@hyper-fetch/firebase">
|
|
23
27
|
<img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/firebase?color=64BC4B&logo=package" />
|
|
24
28
|
</a>
|
|
29
|
+
<a href="https://github.com/BetterTyped/hyper-fetch">
|
|
30
|
+
<img src="https://img.shields.io/badge/firebase-ffca28?logo=firebase&logoColor=black" alt="Firebase" />
|
|
31
|
+
</a>
|
|
25
32
|
</p>
|
|
26
33
|
|
|
27
|
-
## About
|
|
34
|
+
## ๐ About
|
|
35
|
+
|
|
36
|
+
This adapter brings HyperFetch's typed request system to Firebase. Use the same `createRequest` / `.send()` patterns for Firestore and Realtime Database operations with typed responses, caching, queuing, and React hooks โ the same API you use for REST.
|
|
37
|
+
|
|
38
|
+
## ๐ฏ Key Capabilities
|
|
39
|
+
|
|
40
|
+
- ๐ฅ **Same API for Firebase** โ Use `createRequest` / `.send()` for Firestore and Realtime Database, just like REST
|
|
41
|
+
- ๐ฎ **Typed CRUD** โ `getDoc`, `addDoc`, `updateDoc`, `deleteDoc` with full TypeScript types on every field
|
|
42
|
+
- ๐ก **Realtime subscriptions** โ Listen to document and collection changes with typed data flowing in
|
|
43
|
+
- โ๏ธ **React hooks for Firebase** โ `useFetch` and `useSubmit` work with Firebase operations โ same patterns, different backend
|
|
44
|
+
- ๐พ **Cache and offline support** โ HyperFetch's caching and offline queue work with Firebase out of the box
|
|
45
|
+
|
|
46
|
+
## ๐ Quick Start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @hyper-fetch/core @hyper-fetch/firebase firebase
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { createClient } from "@hyper-fetch/core";
|
|
54
|
+
import { FirebaseAdapter } from "@hyper-fetch/firebase";
|
|
55
|
+
import { getFirestore } from "firebase/firestore";
|
|
56
|
+
|
|
57
|
+
const db = getFirestore();
|
|
58
|
+
const client = createClient({ url: "" }).setAdapter(FirebaseAdapter(db));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## ๐ Documentation
|
|
28
62
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
63
|
+
- [Firebase Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-firebase)
|
|
64
|
+
- [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
|
|
65
|
+
- [API Reference](https://hyperfetch.bettertyped.com/api/)
|
|
32
66
|
|
|
33
|
-
##
|
|
67
|
+
## ๐ก Examples
|
|
34
68
|
|
|
35
|
-
|
|
69
|
+
### Read a document
|
|
36
70
|
|
|
37
|
-
|
|
71
|
+
```ts
|
|
72
|
+
interface User {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
email: string;
|
|
76
|
+
}
|
|
38
77
|
|
|
39
|
-
|
|
40
|
-
|
|
78
|
+
const getUser = client.createRequest<{ response: User }>()({
|
|
79
|
+
endpoint: "/users/:userId",
|
|
80
|
+
method: "getDoc",
|
|
81
|
+
});
|
|
41
82
|
|
|
42
|
-
|
|
83
|
+
const { data } = await getUser.setParams({ userId: "abc123" }).send();
|
|
84
|
+
console.log(data.name, data.email);
|
|
85
|
+
```
|
|
43
86
|
|
|
44
|
-
|
|
87
|
+
### Write a document
|
|
45
88
|
|
|
46
|
-
|
|
89
|
+
```ts
|
|
90
|
+
const createUser = client.createRequest<{
|
|
91
|
+
payload: { name: string; email: string };
|
|
92
|
+
response: null;
|
|
93
|
+
}>()({
|
|
94
|
+
endpoint: "/users",
|
|
95
|
+
method: "addDoc",
|
|
96
|
+
});
|
|
47
97
|
|
|
48
|
-
|
|
98
|
+
await createUser.send({ data: { name: "Jane", email: "jane@example.com" } });
|
|
99
|
+
```
|
|
49
100
|
|
|
50
|
-
|
|
101
|
+
### List documents
|
|
51
102
|
|
|
52
|
-
|
|
103
|
+
```ts
|
|
104
|
+
const listUsers = client.createRequest<{ response: User[] }>()({
|
|
105
|
+
endpoint: "/users",
|
|
106
|
+
method: "getDocs",
|
|
107
|
+
});
|
|
53
108
|
|
|
54
|
-
|
|
109
|
+
const { data: users } = await listUsers.send();
|
|
110
|
+
users.forEach((user) => console.log(user.name));
|
|
111
|
+
```
|
|
55
112
|
|
|
56
|
-
|
|
113
|
+
### Use with React hooks
|
|
57
114
|
|
|
58
|
-
|
|
115
|
+
```tsx
|
|
116
|
+
import { useFetch } from "@hyper-fetch/react";
|
|
59
117
|
|
|
60
|
-
|
|
118
|
+
const UserProfile = ({ userId }: { userId: string }) => {
|
|
119
|
+
const { data, loading } = useFetch(getUser.setParams({ userId }));
|
|
61
120
|
|
|
62
|
-
|
|
121
|
+
if (loading) return <p>Loading...</p>;
|
|
122
|
+
return <h1>{data?.name}</h1>;
|
|
123
|
+
};
|
|
124
|
+
```
|
|
63
125
|
|
|
64
|
-
##
|
|
126
|
+
## License
|
|
65
127
|
|
|
66
|
-
|
|
67
|
-
- #### [Docs](https://hyperfetch.bettertyped.com/docs/react/overview)
|
|
68
|
-
- #### [API](https://hyperfetch.bettertyped.com/api/)
|
|
69
|
-
- #### [NPM](https://www.npmjs.com/package/@hyper-fetch/firebase)
|
|
70
|
-
- #### [Guides](https://hyperfetch.bettertyped.com/guides/basic/setup)
|
|
128
|
+
[MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/firebase",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "First class Firebase Web adapter for Hyper Fetch",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|