react-firebase-ql 0.1.0 → 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.
Files changed (2) hide show
  1. package/README.md +163 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,15 +1,169 @@
1
+
1
2
  # react-firebase-ql
2
3
 
3
- Small helpers/hooks for integrating Firebase with React.
4
+ [![npm version](https://img.shields.io/npm/v/react-firebase-ql)](https://www.npmjs.com/package/react-firebase-ql) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ React Firebase QL is a lightweight library that **simplifies working with Firebase in React apps**. It wraps Firebase queries and updates inside **React hooks**, giving developers a feel of using Firebase like a **SQL environment**, where you can quickly call methods like `.save()` or `.find()` on your models.
7
+
8
+ It also provides simple utilities for **Firebase Authentication, Firestore, and Storage** — including easy file uploads via the `.doUpload` method.
9
+
10
+ ## 🔹 Features
11
+
12
+ - **React hooks for Firebase**: `useFetch`, `useStream`, `useAuth`, `useCount`.
13
+ - **Model-based API**: Create classes extending `BaseModel` to interact with Firestore.
14
+ - **SQL-like operations**: Quickly `save()` or `find()` data without boilerplate.
15
+ - **File uploads**: Simple `.doUpload` on the `Storage` class.
16
+ - Supports **Firebase Authentication, Firestore, and Storage**.
17
+ - Written in **TypeScript** with full type support.
18
+
19
+ ## ⚙️ Installation
20
+
21
+ Install via npm or yarn:
22
+
23
+ ```bash
24
+ npm install react-firebase-ql firebase
25
+ # or
26
+ yarn add react-firebase-ql firebase
27
+ ```
28
+
29
+
30
+
31
+
32
+ ## 🛠️ Setup
33
+ **Initialize Firebase**
34
+
35
+ Make sure you have Firebase initialized in your project:
36
+
37
+ ```ts
38
+ // firebase.config.ts
39
+ import { initializeApp } from "firebase/app";
40
+ import { AppCheck, initializeAppCheck, ReCaptchaEnterpriseProvider } from "firebase/app-check";
41
+ import { connectAuthEmulator, getAuth } from "firebase/auth";
42
+ import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
43
+ import { connectFunctionsEmulator, getFunctions } from "firebase/functions";
44
+ import { connectStorageEmulator, getStorage } from "firebase/storage"
45
+
46
+ declare global {
47
+ // eslint-disable-next-line no-var
48
+ var FIREBASE_APPCHECK_DEBUG_TOKEN: boolean | string | undefined;
49
+ }
50
+
51
+ const firebaseConfig = {
52
+ apiKey: "...",
53
+ authDomain: "...",
54
+ projectId: "...",
55
+ storageBucket: "...",
56
+ messagingSenderId: "...",
57
+ appId: "..."
58
+ };
59
+
60
+ // Initialize Firebase
61
+ const app = initializeApp(firebaseConfig);
62
+ let appCheck: AppCheck;
63
+
64
+ // for appcheck (recommended)
65
+ if (typeof window !== "undefined") {
66
+ self.FIREBASE_APPCHECK_DEBUG_TOKEN = window.location.hostname==='localhost';
67
+
68
+ appCheck = initializeAppCheck(app, {
69
+ provider: new ReCaptchaEnterpriseProvider('YOUR-APPCHECK-KEY'),
70
+ isTokenAutoRefreshEnabled: true // Set to true to allow auto-refresh.
71
+ });
72
+ }
73
+
74
+ // initialize other firebase resources
75
+ export const firebaseAuth = getAuth(app)
76
+ export const firestoreDB = getFirestore(app)
77
+ export const server = getFunctions(app)
78
+ export const storage = getStorage(app)
4
79
 
5
- ## Install
6
- npm install firebase react
7
- npm install my-react-firebase-lib
80
+ // set emulator for local environment
81
+ if(typeof window !== 'undefined' && window.location.hostname === 'localhost'){
82
+ const host = "127.0.0.1";
83
+ connectAuthEmulator(firebaseAuth, `http://${host}:9099`);
84
+ connectFunctionsEmulator(server, host, 5001);
85
+ connectFirestoreEmulator(firestoreDB, host, 8080);
86
+ connectStorageEmulator(storage, host, 9199);
87
+ }
88
+
89
+
90
+ // Create and export firestore documents like this
91
+ export enum FIREBASETABLE {
92
+ USERS = 'users',
93
+ ---
94
+ }
95
+ ```
96
+ ## Creating Models
97
+
98
+ Organize your models in a dedicated folder
99
+ src/ or app/ - for nextjs developers
100
+
101
+ ```css
102
+ src/
103
+ └── models/
104
+ ├── Users.model.ts
105
+ ├── Posts.model.ts
106
+ └── ...other models
107
+ ```
108
+
109
+ ## Example: Users Model
110
+
111
+ ```ts
112
+ // src/models/Users.model.ts
113
+ import { firestoreDB } from "../firebase.config";
114
+ import { FIREBASETABLE } from "../firebase.config";
115
+ import { BaseModel, errorLogger } from "react-firebase-ql";
116
+
117
+ export interface YourFirestoreDocumentStructure {
118
+ reference?: string,
119
+ firstName: string;
120
+ ---
121
+ }
122
+
123
+ export class UsersModel extends BaseModel {
8
124
 
9
- ## Usage
10
- import { useFirebaseAuth } from 'my-react-firebase-lib';
125
+ data: YourFirestoreDocumentStructure | YourFirestoreDocumentStructure[] | undefined;
126
+
127
+
128
+ constructor(){
129
+ super(FIREBASETABLE.users, firestoreDB);
130
+ }
11
131
 
12
- function App() {
13
- const user = useFirebaseAuth();
14
- return <div>{user ? user.email : 'not signed in'}</div>;
132
+ otherMethods(){
133
+ ...
134
+ }
135
+
136
+
15
137
  }
138
+
139
+ ```
140
+ ## Using Hooks
141
+ Fetch a single user record by reference
142
+
143
+ ```ts
144
+ import { useFetch } from "react-firebase-ql";
145
+ import { UsersModel } from "../models/Users.model";
146
+
147
+ export default function UserProfile() {
148
+ const [user, loading] = useFetch({
149
+ model: new UsersModel(),
150
+ reference: reference! --document reference
151
+ });
152
+
153
+ if (loading) return <p>Loading...</p>;
154
+ if (error) return <p>Error: {error.message}</p>;
155
+
156
+ return (
157
+ <p>
158
+ {user.firstName}
159
+ </p>
160
+ );
161
+ }
162
+
163
+ ```
164
+
165
+ ## Authors
166
+
167
+ - [@breedware](https://www.github.com/breedware)
168
+
169
+ Breedware Limited
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-firebase-ql",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "A React helper library that simplifies using Firebase with side effects and live queries.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",