@goatlab/fluent-firebase 0.7.17 → 0.7.19

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) GOAT, SPA. and its affiliates.
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 CHANGED
File without changes
package/package.json CHANGED
@@ -1,39 +1,27 @@
1
1
  {
2
2
  "name": "@goatlab/fluent-firebase",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
4
4
  "description": "Readable query Interface & API generator for TS and Node",
5
5
  "dependencies": {
6
- "@goatlab/fluent": "^0.7.31",
7
- "@goatlab/js-utils": "^0.8.24",
6
+ "@goatlab/fluent": "^0.7.33",
8
7
  "@google-cloud/firestore": "^6.0.0",
9
- "firebase-admin": "^11.0.1"
8
+ "firebase-admin": "^11.0.1",
9
+ "@goatlab/js-utils": "0.8.35"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/jest": "^27.4.1",
13
13
  "@types/node": "^17.0.23",
14
14
  "dotenv-cli": "^5.1.0",
15
15
  "eslint": "^8.5.0",
16
- "jest": "^27.5.1",
16
+ "jest": "^29.7.0",
17
17
  "jest-environment-node": "^27.5.1",
18
18
  "prettier": "^2.6.1",
19
19
  "pretty-quick": "^3.1.3",
20
- "ts-jest": "^27.1.4",
21
- "ts-node": "^10.7.0",
20
+ "ts-jest": "^29.2.6",
21
+ "ts-node": "^10.9.2",
22
22
  "turbo": "^1.1.10",
23
- "typescript": "^4.6.3"
24
- },
25
- "scripts": {
26
- "install-p": "yarn",
27
- "prebuild": "rimraf dist",
28
- "prestart": "rimraf dist",
29
- "predev": "rimraf dist",
30
- "test": "jest --forceExit --passWithNoTests",
31
- "dev": "tsc --watch",
32
- "lint": "eslint src --fix",
33
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
34
- "update:packages": "npm-check-updates -u && yarn",
35
- "serve": "tsc -w",
36
- "build": "tsc"
23
+ "typescript": "^4.6.3",
24
+ "@goatlab/tsconfig": "0.0.11"
37
25
  },
38
26
  "homepage": "https://docs.goatlab.io",
39
27
  "main": "dist/index.js",
@@ -53,5 +41,17 @@
53
41
  "license": "MIT",
54
42
  "engines": {
55
43
  "node": ">=14.16.0"
44
+ },
45
+ "scripts": {
46
+ "prebuild": "rimraf dist",
47
+ "prestart": "rimraf dist",
48
+ "predev": "rimraf dist",
49
+ "test": "echo 'skip'",
50
+ "dev": "tsc --watch",
51
+ "lint": "echo 'skip'",
52
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
53
+ "update:packages": "npm-check-updates -u && yarn",
54
+ "serve": "tsc -w",
55
+ "build": "echo 'skip'"
56
56
  }
57
- }
57
+ }
@@ -1,9 +0,0 @@
1
- import * as admin from 'firebase-admin';
2
- import { getAuth as firebaseGetAuth } from 'firebase-admin/auth';
3
- export declare type FirebaseUser = admin.auth.DecodedIdToken;
4
- declare class FirebaseClass {
5
- verifyIdToken: (token: string) => Promise<import("firebase-admin/auth").DecodedIdToken>;
6
- getAuth: typeof firebaseGetAuth;
7
- }
8
- export declare const Firebase: FirebaseClass;
9
- export {};
package/dist/Firebase.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Firebase = void 0;
4
- const tslib_1 = require("tslib");
5
- const admin = tslib_1.__importStar(require("firebase-admin"));
6
- const auth_1 = require("firebase-admin/auth");
7
- class FirebaseClass {
8
- constructor() {
9
- this.verifyIdToken = (token) => admin.auth().verifyIdToken(token);
10
- this.getAuth = auth_1.getAuth;
11
- }
12
- }
13
- exports.Firebase = new FirebaseClass();
@@ -1,33 +0,0 @@
1
- import * as admin from 'firebase-admin';
2
- import { AnyObject, FluentQuery, LoadedResult, QueryOutput } from '@goatlab/fluent';
3
- import { BaseConnector, FluentConnectorInterface } from '@goatlab/fluent';
4
- import { z } from 'zod';
5
- export interface FirebaseConnectorParams<Input, Output> {
6
- entity: any;
7
- inputSchema: z.ZodType<Input>;
8
- outputSchema?: z.ZodType<Output>;
9
- }
10
- export declare class FirebaseConnector<ModelDTO = AnyObject, InputDTO = ModelDTO, OutputDTO = InputDTO> extends BaseConnector<ModelDTO, InputDTO, OutputDTO> implements FluentConnectorInterface<ModelDTO, InputDTO, OutputDTO> {
11
- private readonly inputSchema;
12
- private readonly outputSchema;
13
- private collection;
14
- private readonly entity;
15
- constructor({ entity, inputSchema, outputSchema }: FirebaseConnectorParams<InputDTO, OutputDTO>);
16
- initDB(): number;
17
- insert(data: InputDTO): Promise<OutputDTO>;
18
- insertMany(data: InputDTO[]): Promise<OutputDTO[]>;
19
- findMany<T extends FluentQuery<ModelDTO>>(query?: T): Promise<QueryOutput<T, ModelDTO>[]>;
20
- updateById(id: string, data: InputDTO): Promise<OutputDTO>;
21
- replaceById(id: string, data: InputDTO): Promise<OutputDTO>;
22
- deleteById(id: string): Promise<string>;
23
- clear(): Promise<boolean>;
24
- loadFirst(query?: FluentQuery<ModelDTO>): LoadedResult<this>;
25
- loadById(id: string): LoadedResult<this>;
26
- raw(): admin.firestore.CollectionReference<ModelDTO>;
27
- rawFirebase(): admin.firestore.Firestore;
28
- private deleteQueryBatch;
29
- protected clone(): any;
30
- protected loadRelatedData(data: any[], loadedKeys: AnyObject): Promise<admin.firestore.DocumentData[]>;
31
- private getGeneratedQueries;
32
- private getFirebaseWhereQuery;
33
- }
@@ -1,434 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FirebaseConnector = void 0;
4
- const tslib_1 = require("tslib");
5
- const admin = tslib_1.__importStar(require("firebase-admin"));
6
- const fluent_1 = require("@goatlab/fluent");
7
- const fluent_2 = require("@goatlab/fluent");
8
- const js_utils_1 = require("@goatlab/js-utils");
9
- class FirebaseConnector extends fluent_2.BaseConnector {
10
- constructor({ entity, inputSchema, outputSchema }) {
11
- super();
12
- this.inputSchema = inputSchema;
13
- this.outputSchema =
14
- outputSchema || inputSchema;
15
- this.entity = entity;
16
- }
17
- initDB() {
18
- const relationShipBuilder = fluent_1.modelGeneratorDataSource.getRepository(this.entity);
19
- const name = relationShipBuilder.metadata.givenTableName;
20
- if (!name) {
21
- throw new Error(`Could not find table by name. Did you include @f.entity in your model?`);
22
- }
23
- this.collection = admin
24
- .firestore()
25
- .collection(name);
26
- const { relations } = (0, fluent_1.getRelationsFromModelGenerator)(relationShipBuilder);
27
- this.modelRelations = relations;
28
- this.outputKeys = (0, fluent_2.getOutputKeys)(relationShipBuilder) || [];
29
- return 1;
30
- }
31
- async insert(data) {
32
- this.initDB();
33
- const validatedData = this.inputSchema.parse(data);
34
- if (data['id']) {
35
- const found = await this.findById(data['id']);
36
- if (found) {
37
- throw new Error(`A document with id ${found[0]['id']} already exists.`);
38
- }
39
- }
40
- const id = data['id'] || js_utils_1.Ids.objectIdString();
41
- const item = {
42
- id,
43
- ...validatedData
44
- };
45
- await this.collection.doc(id).set(item);
46
- return this.outputSchema.parse(js_utils_1.Objects.clearEmpties(js_utils_1.Objects.deleteNulls(item)));
47
- }
48
- async insertMany(data) {
49
- this.initDB();
50
- const validatedData = this.inputSchema.array().parse(data);
51
- const batch = admin.firestore().batch();
52
- const batchInserted = [];
53
- validatedData.forEach(d => {
54
- const id = d['id'] || js_utils_1.Ids.objectIdString();
55
- const item = { id, ...d };
56
- const insert = this.collection.doc(id);
57
- batch.set(insert, item);
58
- batchInserted.push(item);
59
- });
60
- await batch.commit();
61
- return this.outputSchema.array().parse(batchInserted.map(d => {
62
- return js_utils_1.Objects.clearEmpties(js_utils_1.Objects.deleteNulls(d));
63
- }));
64
- }
65
- async findMany(query) {
66
- this.initDB();
67
- const [andQuery, orQueries] = this.getGeneratedQueries(query);
68
- const results = [];
69
- if (andQuery) {
70
- const snapshot = await andQuery.get();
71
- snapshot.forEach(doc => {
72
- results.push(doc.data());
73
- });
74
- }
75
- const promises = [];
76
- for (const orQuery of orQueries) {
77
- promises.push(orQuery.get());
78
- }
79
- const orSnapshots = await Promise.all(promises);
80
- for (const orSnapshot of orSnapshots) {
81
- orSnapshot.forEach(doc => {
82
- results.push(doc.data());
83
- });
84
- }
85
- let found = [...new Map(results.map(v => [v.id, v])).values()];
86
- found.map(d => {
87
- js_utils_1.Objects.clearEmpties(js_utils_1.Objects.deleteNulls(d));
88
- });
89
- if (query?.include) {
90
- found = await this.loadRelatedData(found, js_utils_1.Objects.flatten(query?.include || {}));
91
- }
92
- if (query?.paginated) {
93
- const paginationInfo = {
94
- total: 0,
95
- perPage: query.paginated.perPage,
96
- currentPage: query.paginated.page,
97
- nextPage: query.paginated.page + 1,
98
- firstPage: 1,
99
- lastPage: Math.ceil(0 / query.paginated.perPage),
100
- prevPage: query.paginated.page === 1 ? null : query.paginated.page - 1,
101
- from: (query.paginated.page - 1) * query.paginated.perPage + 1,
102
- to: query.paginated.perPage * query.paginated.page,
103
- data: found
104
- };
105
- return paginationInfo;
106
- }
107
- if (query?.select) {
108
- return found;
109
- }
110
- return this.outputSchema?.array().parse(found);
111
- }
112
- async updateById(id, data) {
113
- this.initDB();
114
- const dataToInsert = this.outputKeys.includes('updated')
115
- ? {
116
- ...data,
117
- ...{ updated: new Date() }
118
- }
119
- : data;
120
- const validatedData = this.inputSchema.parse(dataToInsert);
121
- await this.collection.doc(id).update({
122
- ...validatedData,
123
- id
124
- });
125
- const dbResult = await this.findById(id);
126
- if (!dbResult) {
127
- throw new Error(`Object not found: ${id}`);
128
- }
129
- return this.outputSchema?.parse(js_utils_1.Objects.clearEmpties(js_utils_1.Objects.deleteNulls(dbResult)));
130
- }
131
- async replaceById(id, data) {
132
- this.initDB();
133
- const value = await this.findById(id);
134
- const flatValue = js_utils_1.Objects.flatten(JSON.parse(JSON.stringify(value)));
135
- Object.keys(flatValue).forEach(key => {
136
- flatValue[key] = null;
137
- });
138
- const nullObject = js_utils_1.Objects.nest(flatValue);
139
- const newValue = { ...nullObject, ...data };
140
- delete newValue._id;
141
- delete newValue.id;
142
- delete newValue.created;
143
- delete newValue.updated;
144
- const dataToInsert = this.outputKeys.includes('updated')
145
- ? {
146
- ...data,
147
- ...{ updated: new Date() }
148
- }
149
- : data;
150
- const validatedData = this.inputSchema.parse(dataToInsert);
151
- await this.collection
152
- .doc(id)
153
- .update(validatedData);
154
- const val = await this.requireById(id);
155
- return this.outputSchema.parse(js_utils_1.Objects.clearEmpties(js_utils_1.Objects.deleteNulls(val)));
156
- }
157
- async deleteById(id) {
158
- this.initDB();
159
- await this.collection.doc(id).delete();
160
- return id;
161
- }
162
- async clear() {
163
- this.initDB();
164
- const query = this.collection.orderBy('__name__').limit(300);
165
- return new Promise((resolve, reject) => {
166
- this.deleteQueryBatch(admin.firestore(), query, 300, resolve, reject);
167
- });
168
- }
169
- loadFirst(query) {
170
- this.initDB();
171
- const newInstance = this.clone();
172
- newInstance.setRelatedQuery({
173
- entity: this.entity,
174
- repository: this,
175
- query: {
176
- ...query,
177
- limit: 1
178
- }
179
- });
180
- return newInstance;
181
- }
182
- loadById(id) {
183
- this.initDB();
184
- const newInstance = this.clone();
185
- newInstance.setRelatedQuery({
186
- entity: this.entity,
187
- repository: this,
188
- query: {
189
- where: {
190
- id
191
- }
192
- }
193
- });
194
- return newInstance;
195
- }
196
- raw() {
197
- this.initDB();
198
- return this.collection;
199
- }
200
- rawFirebase() {
201
- this.initDB();
202
- return admin.firestore();
203
- }
204
- deleteQueryBatch(db, query, batchSize, resolve, reject) {
205
- this.initDB();
206
- query
207
- .get()
208
- .then(snapshot => {
209
- if (snapshot.size == 0) {
210
- return 0;
211
- }
212
- const batch = db.batch();
213
- snapshot.docs.forEach(doc => {
214
- batch.delete(doc.ref);
215
- });
216
- return batch.commit().then(() => snapshot.size);
217
- })
218
- .then(numDeleted => {
219
- if (numDeleted === 0) {
220
- resolve();
221
- return;
222
- }
223
- process.nextTick(() => {
224
- this.deleteQueryBatch(db, query, batchSize, resolve, reject);
225
- });
226
- })
227
- .catch(reject);
228
- }
229
- clone() {
230
- this.initDB();
231
- return new this.constructor();
232
- }
233
- async loadRelatedData(data, loadedKeys) {
234
- const result = await (0, fluent_2.loadRelations)({
235
- data,
236
- relations: loadedKeys,
237
- modelRelations: this.modelRelations,
238
- provider: 'firebase',
239
- self: this,
240
- returnPivot: false
241
- });
242
- return result;
243
- }
244
- getGeneratedQueries(query) {
245
- let { andWhere, orWhere } = this.getFirebaseWhereQuery(query?.where);
246
- let mergedQueries = [];
247
- if (andWhere) {
248
- mergedQueries = [andWhere, ...orWhere];
249
- }
250
- else {
251
- mergedQueries = orWhere;
252
- }
253
- const select = Object.keys(js_utils_1.Objects.flatten(query?.select || {}));
254
- for (const [index] of mergedQueries.entries()) {
255
- if (select?.length > 0) {
256
- mergedQueries[index] = mergedQueries[index].select(...['id', ...select]);
257
- }
258
- mergedQueries[index] = mergedQueries[index].limit(query?.limit || 10);
259
- mergedQueries[index] = mergedQueries[index].offset(query?.offset || 0);
260
- if (query?.orderBy) {
261
- for (const order of query?.orderBy) {
262
- const flattenObject = js_utils_1.Objects.flatten(order);
263
- for (const attribute of Object.keys(flattenObject)) {
264
- mergedQueries[index] = mergedQueries[index].orderBy(attribute, flattenObject[attribute]);
265
- }
266
- }
267
- }
268
- }
269
- const cloned = [...mergedQueries];
270
- if (andWhere) {
271
- cloned.shift();
272
- }
273
- return [andWhere ? mergedQueries[0] : undefined, cloned];
274
- }
275
- getFirebaseWhereQuery(where) {
276
- if (!where || Object.keys(where).length === 0) {
277
- return { andWhere: this.collection, orWhere: [] };
278
- }
279
- let andWhereQuery = this.collection;
280
- let orWhereQueries = [];
281
- const orConditions = (0, fluent_1.extractConditions)(where['OR']);
282
- const andConditions = (0, fluent_1.extractConditions)(where['AND']);
283
- const copy = js_utils_1.Objects.clone(where);
284
- if (!!copy['AND']) {
285
- delete copy['AND'];
286
- }
287
- if (!!copy['OR']) {
288
- delete copy['OR'];
289
- }
290
- const rootLevelConditions = (0, fluent_1.extractConditions)([copy]);
291
- for (const condition of andConditions) {
292
- const { element, operator, value } = condition;
293
- switch (operator) {
294
- case fluent_1.LogicOperator.equals:
295
- andWhereQuery = andWhereQuery.where(element, '==', value);
296
- break;
297
- case fluent_1.LogicOperator.isNot:
298
- andWhereQuery = andWhereQuery.where(element, '!=', value);
299
- break;
300
- case fluent_1.LogicOperator.greaterThan:
301
- andWhereQuery = andWhereQuery.where(element, '>', value);
302
- break;
303
- case fluent_1.LogicOperator.greaterOrEqualThan:
304
- andWhereQuery = andWhereQuery.where(element, '>=', value);
305
- break;
306
- case fluent_1.LogicOperator.lessThan:
307
- andWhereQuery = andWhereQuery.where(element, '<', value);
308
- break;
309
- case fluent_1.LogicOperator.lessOrEqualThan:
310
- andWhereQuery = andWhereQuery.where(element, '<=', value);
311
- break;
312
- case fluent_1.LogicOperator.in:
313
- andWhereQuery = andWhereQuery.where(element, 'in', value);
314
- break;
315
- case fluent_1.LogicOperator.arrayContains:
316
- andWhereQuery = andWhereQuery.where(element, 'array-contains', value);
317
- break;
318
- case fluent_1.LogicOperator.notIn:
319
- andWhereQuery = andWhereQuery.where(element, 'not-in', value);
320
- break;
321
- case fluent_1.LogicOperator.exists:
322
- throw new Error('The nin Operator cannot be used in Firabase');
323
- case fluent_1.LogicOperator.notExists:
324
- throw new Error('The !exists Operator cannot be used in Firabase');
325
- case fluent_1.LogicOperator.regexp:
326
- throw new Error('The regexp Operator cannot be used in Firabase');
327
- default:
328
- throw new Error('The regexp Operator cannot be used in Firabase');
329
- }
330
- }
331
- for (const condition of rootLevelConditions) {
332
- const { element, operator, value } = condition;
333
- switch (operator) {
334
- case fluent_1.LogicOperator.equals:
335
- andWhereQuery = andWhereQuery.where(element, '==', value);
336
- break;
337
- case fluent_1.LogicOperator.isNot:
338
- andWhereQuery = andWhereQuery.where(element, '!=', value);
339
- break;
340
- case fluent_1.LogicOperator.greaterThan:
341
- andWhereQuery = andWhereQuery.where(element, '>', value);
342
- break;
343
- case fluent_1.LogicOperator.greaterOrEqualThan:
344
- andWhereQuery = andWhereQuery.where(element, '>=', value);
345
- break;
346
- case fluent_1.LogicOperator.lessThan:
347
- andWhereQuery = andWhereQuery.where(element, '<', value);
348
- break;
349
- case fluent_1.LogicOperator.lessOrEqualThan:
350
- andWhereQuery = andWhereQuery.where(element, '<=', value);
351
- break;
352
- case fluent_1.LogicOperator.in:
353
- andWhereQuery = andWhereQuery.where(element, 'in', value);
354
- break;
355
- case fluent_1.LogicOperator.arrayContains:
356
- andWhereQuery = andWhereQuery.where(element, 'array-contains', value);
357
- break;
358
- case fluent_1.LogicOperator.notIn:
359
- andWhereQuery = andWhereQuery.where(element, 'not-in', value);
360
- break;
361
- case fluent_1.LogicOperator.exists:
362
- throw new Error('The nin Operator cannot be used in Firabase');
363
- case fluent_1.LogicOperator.notExists:
364
- throw new Error('The !exists Operator cannot be used in Firabase');
365
- case fluent_1.LogicOperator.regexp:
366
- throw new Error('The regexp Operator cannot be used in Firabase');
367
- default:
368
- throw new Error('The regexp Operator cannot be used in Firabase');
369
- }
370
- }
371
- for (const condition of orConditions) {
372
- const { element, operator, value } = condition;
373
- let orQuery = this.collection;
374
- switch (operator) {
375
- case fluent_1.LogicOperator.equals:
376
- orQuery = orQuery.where(element, '==', value);
377
- break;
378
- case fluent_1.LogicOperator.isNot:
379
- orQuery = orQuery.where(element, '!=', value);
380
- break;
381
- case fluent_1.LogicOperator.greaterThan:
382
- orQuery = orQuery.where(element, '>', value);
383
- break;
384
- case fluent_1.LogicOperator.greaterOrEqualThan:
385
- orQuery = orQuery.where(element, '>=', value);
386
- break;
387
- case fluent_1.LogicOperator.lessThan:
388
- orQuery = orQuery.where(element, '<', value);
389
- break;
390
- case fluent_1.LogicOperator.lessOrEqualThan:
391
- orQuery = orQuery.where(element, '<=', value);
392
- break;
393
- case fluent_1.LogicOperator.in:
394
- orQuery = orQuery.where(element, 'in', value);
395
- break;
396
- case fluent_1.LogicOperator.arrayContains:
397
- orQuery = orQuery.where(element, 'array-contains', value);
398
- break;
399
- case fluent_1.LogicOperator.notIn:
400
- orQuery = orQuery.where(element, 'not-in', value);
401
- break;
402
- case fluent_1.LogicOperator.exists:
403
- throw new Error('The nin Operator cannot be used in Firabase');
404
- case fluent_1.LogicOperator.notExists:
405
- throw new Error('The !exists Operator cannot be used in Firabase');
406
- case fluent_1.LogicOperator.regexp:
407
- throw new Error('The regexp Operator cannot be used in Firabase');
408
- default:
409
- throw new Error('The regexp Operator cannot be used in Firabase');
410
- }
411
- orWhereQueries.push(orQuery);
412
- }
413
- let andWhereCondition = undefined;
414
- if (!andConditions?.length &&
415
- !rootLevelConditions?.length &&
416
- !orConditions?.length) {
417
- andWhereCondition = this.collection;
418
- }
419
- if (andConditions?.length || rootLevelConditions?.length) {
420
- andWhereCondition = andWhereQuery;
421
- }
422
- return {
423
- andWhere: andWhereCondition,
424
- orWhere: orWhereQueries
425
- };
426
- }
427
- }
428
- tslib_1.__decorate([
429
- js_utils_1.Memo.syncMethod(),
430
- tslib_1.__metadata("design:type", Function),
431
- tslib_1.__metadata("design:paramtypes", []),
432
- tslib_1.__metadata("design:returntype", void 0)
433
- ], FirebaseConnector.prototype, "initDB", null);
434
- exports.FirebaseConnector = FirebaseConnector;
@@ -1,8 +0,0 @@
1
- interface ConnectionOptions {
2
- host?: string;
3
- port?: number;
4
- databaseName?: string;
5
- serviceAccount?: string;
6
- }
7
- export declare const FirebaseInit: ({ host, port, databaseName, serviceAccount }: ConnectionOptions) => void;
8
- export {};
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FirebaseInit = void 0;
4
- const tslib_1 = require("tslib");
5
- const admin = tslib_1.__importStar(require("firebase-admin"));
6
- const FirebaseInit = ({ host, port, databaseName, serviceAccount }) => {
7
- if (admin.apps.length) {
8
- return;
9
- }
10
- if (host && port) {
11
- process.env.FIRESTORE_EMULATOR_HOST = `${host}:${port}`;
12
- }
13
- admin.initializeApp({
14
- projectId: databaseName,
15
- credential: serviceAccount
16
- ? admin.credential.cert(serviceAccount)
17
- : admin.credential.applicationDefault()
18
- });
19
- const fireStore = admin.firestore();
20
- fireStore.settings({ ignoreUndefinedProperties: true });
21
- if (!fireStore) {
22
- throw new Error('Could not initialize FireStore');
23
- }
24
- };
25
- exports.FirebaseInit = FirebaseInit;
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Firebase } from './Firebase';
2
- import { FirebaseConnector } from './FirebaseConnector';
3
- import { FirebaseInit } from './FirebaseInit';
4
- export { FirebaseConnector, FirebaseInit, Firebase };
package/dist/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Firebase = exports.FirebaseInit = exports.FirebaseConnector = void 0;
4
- const Firebase_1 = require("./Firebase");
5
- Object.defineProperty(exports, "Firebase", { enumerable: true, get: function () { return Firebase_1.Firebase; } });
6
- const FirebaseConnector_1 = require("./FirebaseConnector");
7
- Object.defineProperty(exports, "FirebaseConnector", { enumerable: true, get: function () { return FirebaseConnector_1.FirebaseConnector; } });
8
- const FirebaseInit_1 = require("./FirebaseInit");
9
- Object.defineProperty(exports, "FirebaseInit", { enumerable: true, get: function () { return FirebaseInit_1.FirebaseInit; } });