react-firebase-ql 0.1.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 +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +1366 -0
- package/dist/index.mjs +1359 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 breedware
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# react-firebase-ql
|
|
2
|
+
|
|
3
|
+
Small helpers/hooks for integrating Firebase with React.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
npm install firebase react
|
|
7
|
+
npm install my-react-firebase-lib
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
import { useFirebaseAuth } from 'my-react-firebase-lib';
|
|
11
|
+
|
|
12
|
+
function App() {
|
|
13
|
+
const user = useFirebaseAuth();
|
|
14
|
+
return <div>{user ? user.email : 'not signed in'}</div>;
|
|
15
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { WhereFilterOp, DocumentData, Firestore } from 'firebase/firestore';
|
|
2
|
+
import { User, MultiFactorResolver, Unsubscribe, Auth, ApplicationVerifier, ConfirmationResult } from 'firebase/auth';
|
|
3
|
+
import * as _firebase_firestore from '@firebase/firestore';
|
|
4
|
+
import { FirebaseStorage } from 'firebase/storage';
|
|
5
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
6
|
+
|
|
7
|
+
declare const fbsession: RegExp;
|
|
8
|
+
type whereClause = {
|
|
9
|
+
key: string;
|
|
10
|
+
operator: WhereFilterOp;
|
|
11
|
+
value: any;
|
|
12
|
+
};
|
|
13
|
+
type andOrWhereClause = {
|
|
14
|
+
key: string;
|
|
15
|
+
operator: WhereFilterOp;
|
|
16
|
+
value: any;
|
|
17
|
+
type: 'and' | 'or';
|
|
18
|
+
};
|
|
19
|
+
declare enum UPLOADTYPES {
|
|
20
|
+
IMAGES = "images",
|
|
21
|
+
DOCUMENTS = "documents",
|
|
22
|
+
VIDEOS = "videos",
|
|
23
|
+
AUDIOS = "audios"
|
|
24
|
+
}
|
|
25
|
+
type dbItems = {
|
|
26
|
+
reference?: string;
|
|
27
|
+
};
|
|
28
|
+
type FunctionReturn = {
|
|
29
|
+
data: any;
|
|
30
|
+
};
|
|
31
|
+
declare enum AUTH_PROVIDERS {
|
|
32
|
+
GOOGLE = 0,
|
|
33
|
+
APPLE = 1,
|
|
34
|
+
FACEBOOK = 2,
|
|
35
|
+
TWITTER = 3
|
|
36
|
+
}
|
|
37
|
+
type QueryReturn = {
|
|
38
|
+
data?: any;
|
|
39
|
+
status: 'error' | 'success';
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
type MFAVerifier = {
|
|
43
|
+
verificationId: string;
|
|
44
|
+
user?: User;
|
|
45
|
+
resolver?: MultiFactorResolver;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
interface Model {
|
|
49
|
+
data: object;
|
|
50
|
+
find(id: string): Promise<boolean>;
|
|
51
|
+
findAll(ids?: string[]): Promise<boolean>;
|
|
52
|
+
findWhereOrAnd({ wh, lim, order, offset }: {
|
|
53
|
+
wh?: {
|
|
54
|
+
type: 'or' | 'and' | 'andOr';
|
|
55
|
+
parameter: whereClause[];
|
|
56
|
+
};
|
|
57
|
+
lim?: number;
|
|
58
|
+
order?: {
|
|
59
|
+
parameter: string;
|
|
60
|
+
direction?: 'asc' | 'desc';
|
|
61
|
+
};
|
|
62
|
+
offset?: string;
|
|
63
|
+
}): Promise<boolean>;
|
|
64
|
+
findWhere({ wh, lim, order, offset }: {
|
|
65
|
+
wh?: whereClause[];
|
|
66
|
+
lim?: number;
|
|
67
|
+
order?: {
|
|
68
|
+
parameter: string;
|
|
69
|
+
direction?: 'asc' | 'desc';
|
|
70
|
+
};
|
|
71
|
+
offset?: string;
|
|
72
|
+
}): Promise<DocumentData[]>;
|
|
73
|
+
save(data: object, id?: string): Promise<string | boolean>;
|
|
74
|
+
delete(id: string): Promise<boolean>;
|
|
75
|
+
update(data: object, id: string): Promise<boolean>;
|
|
76
|
+
stream(callBack: (data: DocumentData | DocumentData[] | undefined) => void, id?: string): void;
|
|
77
|
+
streamWhere(wh: whereClause[], callBack: (data: DocumentData[]) => void, lim?: number, order?: {
|
|
78
|
+
parameter: string;
|
|
79
|
+
direction?: 'asc' | 'desc';
|
|
80
|
+
}, offset?: string): void;
|
|
81
|
+
countData(where: whereClause[]): Promise<number>;
|
|
82
|
+
saveBatch({ data }: {
|
|
83
|
+
data: object[];
|
|
84
|
+
}): Promise<boolean>;
|
|
85
|
+
updateBatch({ data }: {
|
|
86
|
+
data: object[];
|
|
87
|
+
callBack: () => void;
|
|
88
|
+
}): Promise<boolean>;
|
|
89
|
+
deleteBatch({ ids }: {
|
|
90
|
+
ids: string[];
|
|
91
|
+
}): Promise<boolean>;
|
|
92
|
+
incrementDecrement({ dbReference, key, isIncrement, incrementalValue }: {
|
|
93
|
+
dbReference: string;
|
|
94
|
+
key: string;
|
|
95
|
+
isIncrement?: boolean;
|
|
96
|
+
incrementalValue?: number;
|
|
97
|
+
}): Promise<boolean>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare class BaseModel implements Model {
|
|
101
|
+
data: any;
|
|
102
|
+
private firestorDB?;
|
|
103
|
+
private table;
|
|
104
|
+
constructor(table: string, db: Firestore);
|
|
105
|
+
saveBatch({ data }: {
|
|
106
|
+
data: object[];
|
|
107
|
+
}): Promise<boolean>;
|
|
108
|
+
updateBatch({ data }: {
|
|
109
|
+
data: object[];
|
|
110
|
+
}): Promise<boolean>;
|
|
111
|
+
deleteBatch({ ids }: {
|
|
112
|
+
ids: string[];
|
|
113
|
+
}): Promise<boolean>;
|
|
114
|
+
stream(callBack: (data: DocumentData | DocumentData[] | undefined) => void, id?: string): _firebase_firestore.Unsubscribe | undefined;
|
|
115
|
+
streamWhere(wh: whereClause[], callBack: (data: DocumentData[]) => void, lim?: number, order?: {
|
|
116
|
+
parameter: string;
|
|
117
|
+
direction?: 'asc' | 'desc';
|
|
118
|
+
}, offset?: string): Unsubscribe | undefined;
|
|
119
|
+
find(id: string): Promise<boolean>;
|
|
120
|
+
dataExists(id: string): Promise<boolean>;
|
|
121
|
+
update(data: any, id: string): Promise<boolean>;
|
|
122
|
+
updateAtomicArray(data: any[], reference: string, key: string): Promise<boolean>;
|
|
123
|
+
removeFromArray(data: any[], id: string, key: string): Promise<boolean>;
|
|
124
|
+
findAll(ids?: string[]): Promise<boolean>;
|
|
125
|
+
findWhereOrAnd({ wh, lim, order, offset }: {
|
|
126
|
+
wh?: {
|
|
127
|
+
type: 'or' | 'and' | 'andOr';
|
|
128
|
+
parameter: andOrWhereClause[];
|
|
129
|
+
};
|
|
130
|
+
lim?: number;
|
|
131
|
+
order?: {
|
|
132
|
+
parameter: string;
|
|
133
|
+
direction?: 'asc' | 'desc';
|
|
134
|
+
};
|
|
135
|
+
offset?: string;
|
|
136
|
+
}): Promise<boolean>;
|
|
137
|
+
findWhere({ wh, lim, order, offset }: {
|
|
138
|
+
wh?: whereClause[];
|
|
139
|
+
lim?: number;
|
|
140
|
+
order?: {
|
|
141
|
+
parameter: string;
|
|
142
|
+
direction?: 'asc' | 'desc';
|
|
143
|
+
};
|
|
144
|
+
offset?: string;
|
|
145
|
+
}): Promise<DocumentData[]>;
|
|
146
|
+
save(data: any, id?: string | undefined): Promise<string | boolean>;
|
|
147
|
+
delete(id: string): Promise<boolean>;
|
|
148
|
+
incrementDecrement({ dbReference, key, isIncrement, incrementalValue }: {
|
|
149
|
+
dbReference: string;
|
|
150
|
+
key: string;
|
|
151
|
+
isIncrement?: boolean;
|
|
152
|
+
incrementalValue?: number;
|
|
153
|
+
}): Promise<boolean>;
|
|
154
|
+
countData(wh: whereClause[]): Promise<number>;
|
|
155
|
+
streamCount(wh: whereClause[], callBack: (data: number) => void, order?: {
|
|
156
|
+
parameter: string;
|
|
157
|
+
direction?: 'asc' | 'desc';
|
|
158
|
+
}, offset?: string): Promise<() => void>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class Users extends BaseModel {
|
|
162
|
+
private user?;
|
|
163
|
+
registerWithEmailAndPassword({ auth, email, password, userData, persist, }: {
|
|
164
|
+
auth: Auth;
|
|
165
|
+
email: string;
|
|
166
|
+
password: string;
|
|
167
|
+
userData?: dbItems;
|
|
168
|
+
persist?: 'local' | 'session';
|
|
169
|
+
}): Promise<string | null>;
|
|
170
|
+
login({ email, password, auth, persist, verifyEmail }: {
|
|
171
|
+
email: string;
|
|
172
|
+
password: string;
|
|
173
|
+
auth: Auth;
|
|
174
|
+
persist?: 'session' | 'local';
|
|
175
|
+
verifyEmail?: boolean;
|
|
176
|
+
}): Promise<QueryReturn>;
|
|
177
|
+
signInWithPhoneNumber({ auth, phoneNumber, appVerifier }: {
|
|
178
|
+
auth: Auth;
|
|
179
|
+
phoneNumber: string;
|
|
180
|
+
appVerifier: ApplicationVerifier;
|
|
181
|
+
}): Promise<ConfirmationResult | boolean>;
|
|
182
|
+
isLoggedIn(auth: Auth): boolean;
|
|
183
|
+
resetPassword({ auth, newPassword }: {
|
|
184
|
+
auth: Auth;
|
|
185
|
+
newPassword: string;
|
|
186
|
+
}): Promise<boolean>;
|
|
187
|
+
sendPasswordResetMessage({ auth, email }: {
|
|
188
|
+
auth: Auth;
|
|
189
|
+
email: string;
|
|
190
|
+
}): Promise<boolean>;
|
|
191
|
+
logout({ auth }: {
|
|
192
|
+
auth: Auth;
|
|
193
|
+
}): Promise<boolean>;
|
|
194
|
+
loginWithMultiAuthFactor({ email, password, auth, recaptcha, getNumber, persist, verifyEmail }: {
|
|
195
|
+
email: string;
|
|
196
|
+
password: string;
|
|
197
|
+
auth: Auth;
|
|
198
|
+
recaptcha: ApplicationVerifier;
|
|
199
|
+
getNumber?: boolean;
|
|
200
|
+
persist?: boolean;
|
|
201
|
+
verifyEmail?: boolean;
|
|
202
|
+
}): Promise<MFAVerifier | null>;
|
|
203
|
+
private getPhoneNumber;
|
|
204
|
+
private setMultiFactorEnrollment;
|
|
205
|
+
confirmOTP: (verifier: MFAVerifier, userCode: string) => Promise<User | null>;
|
|
206
|
+
private sendOTP;
|
|
207
|
+
verifyEmail: (auth: Auth, actionCode: string) => Promise<boolean>;
|
|
208
|
+
verifyPasswordResetLink: (auth: Auth, actionCode: string) => Promise<string>;
|
|
209
|
+
deleteAccount(user: User): Promise<void>;
|
|
210
|
+
sendEmailVerification(user: User): Promise<string | null>;
|
|
211
|
+
doPasswordReset(auth: Auth, actionCode: string, newPassword: string): Promise<boolean>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare class StorageUpload {
|
|
215
|
+
uploadError?: string;
|
|
216
|
+
file?: File | string;
|
|
217
|
+
private additionalPath?;
|
|
218
|
+
private maxSize?;
|
|
219
|
+
fullPath?: string;
|
|
220
|
+
private storage;
|
|
221
|
+
constructor(props: {
|
|
222
|
+
storage: FirebaseStorage;
|
|
223
|
+
file: File | string;
|
|
224
|
+
basePath: UPLOADTYPES;
|
|
225
|
+
otherPath: string;
|
|
226
|
+
maxSize?: number;
|
|
227
|
+
});
|
|
228
|
+
private validateFile;
|
|
229
|
+
private sizeMetric;
|
|
230
|
+
private getExtensionName;
|
|
231
|
+
private getDocExtensionName;
|
|
232
|
+
private setUploadError;
|
|
233
|
+
private setFilePath;
|
|
234
|
+
doUpload(): Promise<string | boolean>;
|
|
235
|
+
private uploadAsString;
|
|
236
|
+
private uploadAsFile;
|
|
237
|
+
static deleteFile(filePath: string, storage: FirebaseStorage): Promise<boolean>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare const generateRandomString: (length: number) => string;
|
|
241
|
+
declare const camelToTitleCase: (key: string) => string;
|
|
242
|
+
declare function convertUnicode(input: string): string;
|
|
243
|
+
declare const moneyFormatter: (x: number | string, shorten?: boolean, decimailPlaces?: number) => string;
|
|
244
|
+
declare function getDaysAgo(startDate: Date, daysApart: number): Date;
|
|
245
|
+
declare function timeAgo(dateInput: Date | string | number): string;
|
|
246
|
+
declare const range: (start: number, end: number) => number[];
|
|
247
|
+
declare const nairaFormatter: (amount: number) => string;
|
|
248
|
+
declare const camelCaseToNormal: (camelCaseStr: string) => string;
|
|
249
|
+
declare const errorLogger: (...error: any) => void;
|
|
250
|
+
declare function isValidEmail(email: string): string | undefined;
|
|
251
|
+
declare function isValidPassword(password: string): string | undefined;
|
|
252
|
+
declare function numberToAlphabet(num: number): string;
|
|
253
|
+
declare const getNthNumberOfArray: (param: {
|
|
254
|
+
num: number;
|
|
255
|
+
step: number;
|
|
256
|
+
start?: number;
|
|
257
|
+
}) => number[];
|
|
258
|
+
declare const noEmptyField: (args: {
|
|
259
|
+
requiredFields: string[];
|
|
260
|
+
formData: any;
|
|
261
|
+
}) => boolean;
|
|
262
|
+
declare const getInitials: (fullName?: string) => string;
|
|
263
|
+
type TimeStamp = {
|
|
264
|
+
unix: number;
|
|
265
|
+
iso: string;
|
|
266
|
+
};
|
|
267
|
+
declare const fetchCurrentTimestamp: () => Promise<TimeStamp>;
|
|
268
|
+
declare const formHasError: (formError: Record<string, string | undefined>) => boolean;
|
|
269
|
+
|
|
270
|
+
declare function useAuth(auth: Auth, callback: (user: User | null) => void): void;
|
|
271
|
+
|
|
272
|
+
declare const useCount: <T extends BaseModel>(param: {
|
|
273
|
+
model: T | any;
|
|
274
|
+
where?: whereClause[];
|
|
275
|
+
}) => [number, boolean, Dispatch<SetStateAction<boolean>>];
|
|
276
|
+
|
|
277
|
+
declare const useFetch: <T extends BaseModel>(param: {
|
|
278
|
+
model: T | any;
|
|
279
|
+
where?: whereClause[];
|
|
280
|
+
reference?: string;
|
|
281
|
+
filter?: {
|
|
282
|
+
orderBy?: {
|
|
283
|
+
parameter: string;
|
|
284
|
+
direction?: "asc" | "desc";
|
|
285
|
+
};
|
|
286
|
+
offset?: string;
|
|
287
|
+
limit?: number;
|
|
288
|
+
};
|
|
289
|
+
}) => [typeof param.model.data, boolean, Dispatch<SetStateAction<boolean>>];
|
|
290
|
+
|
|
291
|
+
declare const useStream: <T extends BaseModel>(param: {
|
|
292
|
+
model: T | any;
|
|
293
|
+
where?: whereClause[];
|
|
294
|
+
reference?: string;
|
|
295
|
+
filter?: {
|
|
296
|
+
orderBy?: {
|
|
297
|
+
parameter: string;
|
|
298
|
+
direction?: "asc" | "desc";
|
|
299
|
+
};
|
|
300
|
+
offset?: string;
|
|
301
|
+
};
|
|
302
|
+
}, callback: (data: any) => void) => void;
|
|
303
|
+
|
|
304
|
+
export { AUTH_PROVIDERS, BaseModel, FunctionReturn, MFAVerifier, Model, QueryReturn, StorageUpload, UPLOADTYPES, Users, andOrWhereClause, camelCaseToNormal, camelToTitleCase, convertUnicode, dbItems, errorLogger, fbsession, fetchCurrentTimestamp, formHasError, generateRandomString, getDaysAgo, getInitials, getNthNumberOfArray, isValidEmail, isValidPassword, moneyFormatter, nairaFormatter, noEmptyField, numberToAlphabet, range, timeAgo, useAuth, useCount, useFetch, useStream, whereClause };
|