react-firebase-ql 0.2.0 → 2.0.7
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 +11 -17
- package/dist/index.d.ts +3 -268
- package/dist/index.js +6100 -1081
- package/dist/index.mjs +6098 -1102
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -93,22 +93,22 @@ export enum FIREBASETABLE {
|
|
|
93
93
|
---
|
|
94
94
|
}
|
|
95
95
|
```
|
|
96
|
-
##
|
|
96
|
+
## Creating Models
|
|
97
97
|
|
|
98
98
|
Organize your models in a dedicated folder
|
|
99
99
|
src/ or app/ - for nextjs developers
|
|
100
100
|
|
|
101
|
+
```css
|
|
101
102
|
src/
|
|
102
|
-
|
|
103
103
|
└── models/
|
|
104
|
-
|
|
105
|
-
├── Users.model.ts
|
|
106
|
-
|
|
104
|
+
├── Users.model.ts
|
|
107
105
|
├── Posts.model.ts
|
|
108
|
-
|
|
109
106
|
└── ...other models
|
|
110
|
-
|
|
111
107
|
```
|
|
108
|
+
|
|
109
|
+
## Example: Users Model
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
112
|
// src/models/Users.model.ts
|
|
113
113
|
import { firestoreDB } from "../firebase.config";
|
|
114
114
|
import { FIREBASETABLE } from "../firebase.config";
|
|
@@ -119,6 +119,7 @@ export interface YourFirestoreDocumentStructure {
|
|
|
119
119
|
firstName: string;
|
|
120
120
|
---
|
|
121
121
|
}
|
|
122
|
+
|
|
122
123
|
export class UsersModel extends BaseModel {
|
|
123
124
|
|
|
124
125
|
data: YourFirestoreDocumentStructure | YourFirestoreDocumentStructure[] | undefined;
|
|
@@ -136,10 +137,10 @@ export class UsersModel extends BaseModel {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
```
|
|
140
|
+
## Using Hooks
|
|
141
|
+
Fetch a single user record by reference
|
|
139
142
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
+
```ts
|
|
143
144
|
import { useFetch } from "react-firebase-ql";
|
|
144
145
|
import { UsersModel } from "../models/Users.model";
|
|
145
146
|
|
|
@@ -161,13 +162,6 @@ export default function UserProfile() {
|
|
|
161
162
|
|
|
162
163
|
```
|
|
163
164
|
|
|
164
|
-
## Acknowledgements
|
|
165
|
-
|
|
166
|
-
- [Awesome Readme Templates](https://awesomeopensource.com/project/elangosundar/awesome-README-templates)
|
|
167
|
-
- [Awesome README](https://github.com/matiassingers/awesome-readme)
|
|
168
|
-
- [How to write a Good readme](https://bulldogjob.com/news/449-how-to-write-a-good-readme-for-your-github-project)
|
|
169
|
-
|
|
170
|
-
Breedware Limited
|
|
171
165
|
## Authors
|
|
172
166
|
|
|
173
167
|
- [@breedware](https://www.github.com/breedware)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,272 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import * as _firebase_firestore from '@firebase/firestore';
|
|
4
|
-
import { FirebaseStorage } from 'firebase/storage';
|
|
1
|
+
import { Auth, User } from 'firebase/auth';
|
|
2
|
+
import { BaseModel, whereClause } from 'firebase-client-ql';
|
|
5
3
|
import { Dispatch, SetStateAction } from 'react';
|
|
6
4
|
|
|
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
5
|
declare function useAuth(auth: Auth, callback: (user: User | null) => void): void;
|
|
271
6
|
|
|
272
7
|
declare const useCount: <T extends BaseModel>(param: {
|
|
@@ -301,4 +36,4 @@ declare const useStream: <T extends BaseModel>(param: {
|
|
|
301
36
|
};
|
|
302
37
|
}, callback: (data: any) => void) => void;
|
|
303
38
|
|
|
304
|
-
export {
|
|
39
|
+
export { useAuth, useCount, useFetch, useStream };
|