@hyper-fetch/firebase-admin 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 +59 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# 🔥 Hyper Fetch Firebase Admin
|
|
2
2
|
|
|
3
|
-
<p>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Type-safe Firebase Admin SDK adapter for HyperFetch. Server-side Firestore and Realtime Database — fully 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,106 +17,98 @@
|
|
|
13
17
|
<a href="https://www.npmjs.com/package/@hyper-fetch/firebase-admin">
|
|
14
18
|
<img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/firebase-admin.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-admin">
|
|
21
|
+
<img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/firebase-admin?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-admin">
|
|
23
27
|
<img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/firebase-admin?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
|
-
|
|
28
|
-
|
|
29
|
-
## Description
|
|
30
|
-
|
|
31
|
-
`@hyper-fetch/firebase-admin` is the **official Firebase Admin SDK adapter** for
|
|
32
|
-
[Hyper Fetch](https://hyperfetch.bettertyped.com). It brings the same declarative, type-safe API you use on the client
|
|
33
|
-
to your server or cloud functions.
|
|
34
|
-
|
|
35
|
-
---
|
|
34
|
+
## 📖 About
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
This adapter brings HyperFetch to server-side Firebase. Share request patterns between browser and Node.js, use the same typed API for Firestore and Realtime Database, and leverage HyperFetch's queuing and retry capabilities on top of the Firebase Admin SDK.
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
2. **First-class TypeScript** – strong typing for parameters, payloads and responses out of the box.
|
|
41
|
-
3. **Queue & Retry** – leverage Hyper Fetch queueing on top of Firebase Admin SDK.
|
|
42
|
-
4. **Unified tooling** – logging, events and interceptors identical on both sides.
|
|
43
|
-
5. **Works with Firestore _and_ Realtime Database** – pick the storage that fits your use-case.
|
|
38
|
+
## 🎯 Key Capabilities
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
- 🔮 **Same code, server-side** — Identical HyperFetch patterns for server and client Firebase operations
|
|
41
|
+
- 🔥 **Firestore & Realtime Database** — Both engines through one typed adapter
|
|
42
|
+
- 🔁 **Server-side retry and queuing** — Automatic retries with backoff for flaky Firebase calls in backend services
|
|
43
|
+
- ✨ **Full TypeScript types** — Parameters, payloads, and responses typed for every database operation
|
|
46
44
|
|
|
47
|
-
##
|
|
45
|
+
## 🚀 Quick Start
|
|
48
46
|
|
|
49
47
|
```bash
|
|
50
48
|
npm install @hyper-fetch/core @hyper-fetch/firebase-admin firebase-admin
|
|
51
|
-
# or
|
|
52
|
-
yarn add @hyper-fetch/core @hyper-fetch/firebase-admin firebase-admin
|
|
53
49
|
```
|
|
54
50
|
|
|
55
|
-
> `firebase-admin` is a peer dependency and must be installed separately.
|
|
56
|
-
|
|
57
|
-
## Quick start
|
|
58
|
-
|
|
59
|
-
### 1. Initialize Firebase Admin SDK
|
|
60
|
-
|
|
61
51
|
```ts
|
|
62
|
-
import {
|
|
52
|
+
import { createClient } from "@hyper-fetch/core";
|
|
53
|
+
import { FirebaseAdminAdapter } from "@hyper-fetch/firebase-admin";
|
|
63
54
|
import { getFirestore } from "firebase-admin/firestore";
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
export const db = getFirestore();
|
|
56
|
+
const db = getFirestore();
|
|
57
|
+
const client = createClient({ url: "" }).setAdapter(FirebaseAdminAdapter(db));
|
|
70
58
|
```
|
|
71
59
|
|
|
72
|
-
|
|
60
|
+
## 📚 Documentation
|
|
73
61
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
import { db } from "./firebase";
|
|
62
|
+
- [Firebase Admin Adapter Docs](https://hyperfetch.bettertyped.com/docs/integrations/adapter-firebase-admin)
|
|
63
|
+
- [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
|
|
64
|
+
- [API Reference](https://hyperfetch.bettertyped.com/api/)
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
```
|
|
66
|
+
## 💡 Examples
|
|
81
67
|
|
|
82
|
-
###
|
|
68
|
+
### Server-side CRUD
|
|
83
69
|
|
|
84
70
|
```ts
|
|
85
|
-
interface
|
|
71
|
+
interface Message {
|
|
86
72
|
text: string;
|
|
73
|
+
author: string;
|
|
74
|
+
createdAt: number;
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
|
|
77
|
+
const addMessage = client.createRequest<{ payload: Message; response: null }>()({
|
|
90
78
|
endpoint: "/messages",
|
|
91
79
|
method: "addDoc",
|
|
92
80
|
});
|
|
93
81
|
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
const getMessages = client.createRequest<{ response: Message[] }>()({
|
|
83
|
+
endpoint: "/messages",
|
|
84
|
+
method: "getDocs",
|
|
85
|
+
});
|
|
96
86
|
|
|
97
|
-
|
|
87
|
+
await addMessage.send({
|
|
88
|
+
data: { text: "Hello from server!", author: "system", createdAt: Date.now() },
|
|
89
|
+
});
|
|
98
90
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
| `setDoc`, `addDoc` | `set`, `push` |
|
|
103
|
-
| `updateDoc`, `deleteDoc` | `update`, `remove` |
|
|
91
|
+
const { data: messages } = await getMessages.send();
|
|
92
|
+
messages.forEach((msg) => console.log(`${msg.author}: ${msg.text}`));
|
|
93
|
+
```
|
|
104
94
|
|
|
105
|
-
|
|
95
|
+
### Update and delete
|
|
106
96
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
```ts
|
|
98
|
+
const updateMessage = client.createRequest<{ payload: Partial<Message>; response: null }>()({
|
|
99
|
+
endpoint: "/messages/:messageId",
|
|
100
|
+
method: "updateDoc",
|
|
101
|
+
});
|
|
111
102
|
|
|
112
|
-
|
|
103
|
+
const deleteMessage = client.createRequest<{ response: null }>()({
|
|
104
|
+
endpoint: "/messages/:messageId",
|
|
105
|
+
method: "deleteDoc",
|
|
106
|
+
});
|
|
113
107
|
|
|
114
|
-
|
|
108
|
+
await updateMessage.setParams({ messageId: "abc" }).send({ data: { text: "Updated!" } });
|
|
109
|
+
await deleteMessage.setParams({ messageId: "abc" }).send();
|
|
110
|
+
```
|
|
115
111
|
|
|
116
|
-
|
|
112
|
+
## License
|
|
117
113
|
|
|
118
|
-
|
|
114
|
+
[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-admin",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "First class Firebase Admin 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/",
|