@nu-art/firebase-backend 0.401.9 → 0.500.6

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 (56) hide show
  1. package/ModuleBE_Firebase.d.ts +15 -1
  2. package/ModuleBE_Firebase.js +39 -3
  3. package/auth/firebase-session.d.ts +12 -8
  4. package/auth/firebase-session.js +53 -15
  5. package/firestore/DocWrapper.d.ts +30 -0
  6. package/{firestore-v3/DocWrapperV3.js → firestore/DocWrapper.js} +30 -32
  7. package/firestore/FirestoreCollection.d.ts +141 -59
  8. package/firestore/FirestoreCollection.js +419 -147
  9. package/firestore/FirestoreInterface.d.ts +2 -3
  10. package/firestore/FirestoreInterface.js +1 -5
  11. package/firestore/FirestoreWrapperBE.d.ts +5 -6
  12. package/firestore/FirestoreWrapperBE.js +119 -9
  13. package/firestore/MongoCollection.d.ts +81 -0
  14. package/firestore/MongoCollection.js +426 -0
  15. package/firestore/MongoInterface.d.ts +18 -0
  16. package/firestore/MongoInterface.js +132 -0
  17. package/firestore/MongoWrapperBE.d.ts +18 -0
  18. package/firestore/MongoWrapperBE.js +95 -0
  19. package/firestore/consts.d.ts +23 -0
  20. package/firestore/consts.js +34 -0
  21. package/firestore/types.d.ts +6 -1
  22. package/firestore/types.js +0 -24
  23. package/{functions-v2 → functions}/ModuleBE_BaseFunction.d.ts +6 -3
  24. package/{functions-v2 → functions}/ModuleBE_BaseFunction.js +1 -0
  25. package/{functions-v2/ModuleBE_ExpressFunction_V2.d.ts → functions/ModuleBE_ExpressFunction_Class.d.ts} +5 -3
  26. package/{functions-v2/ModuleBE_ExpressFunction_V2.js → functions/ModuleBE_ExpressFunction_Class.js} +7 -3
  27. package/{functions-v2 → functions}/ModuleBE_FirebaseDBListener.d.ts +2 -1
  28. package/{functions-v2 → functions}/ModuleBE_FirebaseDBListener.js +1 -0
  29. package/{functions-v2 → functions}/ModuleBE_FirebaseScheduler.js +1 -0
  30. package/{functions-v2 → functions}/ModuleBE_FirestoreListener.d.ts +5 -1
  31. package/{functions-v2 → functions}/ModuleBE_FirestoreListener.js +1 -0
  32. package/{functions-v2 → functions}/ModuleBE_PubSubFunction.d.ts +5 -2
  33. package/{functions-v2 → functions}/ModuleBE_PubSubFunction.js +1 -0
  34. package/{functions-v2 → functions}/ModuleBE_StorageListener.js +1 -0
  35. package/index.d.ts +16 -13
  36. package/index.js +16 -13
  37. package/package.json +10 -7
  38. package/firestore/FirestoreTransaction.d.ts +0 -30
  39. package/firestore/FirestoreTransaction.js +0 -153
  40. package/firestore-v3/DocWrapperV3.d.ts +0 -32
  41. package/firestore-v3/FirestoreCollectionV3.d.ts +0 -154
  42. package/firestore-v3/FirestoreCollectionV3.js +0 -470
  43. package/firestore-v3/FirestoreInterfaceV3.d.ts +0 -10
  44. package/firestore-v3/FirestoreInterfaceV3.js +0 -107
  45. package/firestore-v3/FirestoreWrapperBEV3.d.ts +0 -16
  46. package/firestore-v3/FirestoreWrapperBEV3.js +0 -154
  47. package/firestore-v3/consts.d.ts +0 -13
  48. package/firestore-v3/consts.js +0 -18
  49. package/firestore-v3/types.d.ts +0 -6
  50. package/firestore-v3/types.js +0 -1
  51. package/functions/firebase-function.d.ts +0 -38
  52. package/functions/firebase-function.js +0 -53
  53. package/v1.d.ts +0 -21
  54. package/v1.js +0 -38
  55. /package/{functions-v2 → functions}/ModuleBE_FirebaseScheduler.d.ts +0 -0
  56. /package/{functions-v2 → functions}/ModuleBE_StorageListener.d.ts +0 -0
@@ -1,154 +0,0 @@
1
- /*
2
- * Firebase is a simpler Typescript wrapper to all of firebase services.
3
- *
4
- * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- import { FirestoreCollectionV3, } from './FirestoreCollectionV3.js';
19
- import { FirebaseBaseWrapper } from '../auth/FirebaseBaseWrapper.js';
20
- import { Promise_all_sequentially } from '@nu-art/ts-common';
21
- import { DocumentReference, DocumentSnapshot, getFirestore, QuerySnapshot, } from 'firebase-admin/firestore';
22
- export class FirestoreWrapperBEV3 extends FirebaseBaseWrapper {
23
- firestore;
24
- collections = {};
25
- constructor(firebaseSession, dbName) {
26
- super(firebaseSession);
27
- if (dbName)
28
- this.firestore = getFirestore(firebaseSession.app, dbName);
29
- else
30
- this.firestore = getFirestore(firebaseSession.app);
31
- }
32
- runTransaction = async (processor, transaction) => {
33
- if (transaction) // if a transaction was provided to be used, use it
34
- return processor(transaction);
35
- const postTransactionActions = [];
36
- const toRet = await this.firestore.runTransaction(async (transaction) => {
37
- const writeActions = [];
38
- const transactionUpdates = {};
39
- // @ts-ignore
40
- transaction.postTransaction = (action) => {
41
- return postTransactionActions.push(action);
42
- };
43
- // @ts-ignore
44
- transaction.__nu_art__WriteActions = writeActions;
45
- const originSet = transaction.set.bind(transaction);
46
- const originDelete = transaction.delete.bind(transaction);
47
- const originCreate = transaction.create.bind(transaction);
48
- const originGet = transaction.get.bind(transaction);
49
- const originGetAll = transaction.getAll.bind(transaction);
50
- const getMockDocumentSnapshot = (data, _id, exists = true) => {
51
- return {
52
- id: _id,
53
- ref: {}, // Mock DocumentReference
54
- exists,
55
- data: () => (exists ? data : undefined),
56
- get: (fieldPath) => data[fieldPath],
57
- metadata: {}, // Mock metadata
58
- };
59
- };
60
- const updateTransactionUpdates = async (data, exists = true) => {
61
- let _data;
62
- let _id;
63
- if (data instanceof DocumentReference) {
64
- _id = data.id;
65
- _data = (await data.get()).data();
66
- }
67
- else {
68
- _id = data._id;
69
- _data = data;
70
- }
71
- transactionUpdates[_id] = getMockDocumentSnapshot(_data, _id, exists);
72
- };
73
- transaction.set = (documentRef, data) => {
74
- updateTransactionUpdates(data);
75
- writeActions.push(() => originSet(documentRef, data));
76
- return transaction;
77
- };
78
- transaction.create = (documentRef, data) => {
79
- updateTransactionUpdates(data);
80
- writeActions.push(() => originCreate(documentRef, data));
81
- return transaction;
82
- };
83
- transaction.delete = (documentRef, precondition) => {
84
- // update deletions
85
- updateTransactionUpdates(documentRef, false);
86
- writeActions.push(() => originDelete(documentRef, precondition));
87
- return transaction;
88
- };
89
- // @ts-ignore
90
- transaction.get = async (args) => {
91
- // @ts-ignore
92
- const doc = await originGet(args);
93
- // handle doc snapshot
94
- if (doc instanceof DocumentSnapshot) {
95
- const document = doc.data();
96
- if (!document)
97
- return doc;
98
- return transactionUpdates[document._id] ?? doc;
99
- }
100
- // handle query snapshot
101
- if (doc instanceof QuerySnapshot) {
102
- const docs = doc.docs;
103
- // @ts-ignore
104
- return {
105
- docs: docs.map(doc => {
106
- const _doc = doc.data();
107
- if (!_doc)
108
- return doc;
109
- return transactionUpdates[_doc._id] ?? doc;
110
- })
111
- };
112
- }
113
- return doc;
114
- };
115
- // @ts-ignore
116
- transaction.getAll = async (...documentRefsOrReadOptions) => {
117
- const docs = await originGetAll(...documentRefsOrReadOptions);
118
- return docs.map(doc => {
119
- const _doc = doc.data();
120
- if (!_doc)
121
- return doc;
122
- return transactionUpdates[_doc._id] ?? doc;
123
- });
124
- };
125
- const toRet = await processor(transaction);
126
- writeActions.forEach(action => action());
127
- return toRet;
128
- });
129
- await Promise_all_sequentially(postTransactionActions);
130
- return toRet;
131
- };
132
- getCollection(dbDef, hooks) {
133
- const collection = this.collections[dbDef.dbKey];
134
- if (collection)
135
- return collection;
136
- return this.collections[dbDef.dbKey] = new FirestoreCollectionV3(this, dbDef, hooks);
137
- }
138
- listen(collection, doc) {
139
- collection.wrapper.firestore.doc(`${collection.collection.path}/${doc}`).onSnapshot(() => {
140
- this.logInfo('received snapshot!');
141
- });
142
- }
143
- // public async deleteCollection(name: string) {
144
- // return this.getCollection(name).deleteAll();
145
- // }
146
- async listCollections() {
147
- if (!this.firestore.listCollections)
148
- return [];
149
- return this.firestore.listCollections();
150
- }
151
- isEmulator() {
152
- return !!process.env.FIRESTORE_EMULATOR_HOST || false;
153
- }
154
- }
@@ -1,13 +0,0 @@
1
- import { Dispatcher, UniqueId } from '@nu-art/ts-common';
2
- import { CanDeleteDBEntitiesProto } from './types.js';
3
- import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage';
4
- import { PotentialDependenciesToDelete } from '@nu-art/firebase-shared';
5
- export declare const canDeleteDispatcherV3: Dispatcher<CanDeleteDBEntitiesProto, "__canDeleteEntitiesProto", [type: any, itemIds: string[], transaction?: FirebaseFirestore.Transaction | undefined], import("@nu-art/firebase-shared").DB_EntityDependencyV2>;
6
- export type MemKey_DeletedDocs_Type = {
7
- transaction: FirebaseFirestore.Transaction;
8
- deleted: {
9
- [dbKey: string]: Set<UniqueId>;
10
- };
11
- };
12
- export declare const MemKey_DeletedDocs: MemKey<MemKey_DeletedDocs_Type[]>;
13
- export declare function addDeletedToTransaction(transaction: FirebaseFirestore.Transaction | undefined, deleted: PotentialDependenciesToDelete): void;
@@ -1,18 +0,0 @@
1
- import { Dispatcher } from '@nu-art/ts-common';
2
- import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage';
3
- export const canDeleteDispatcherV3 = new Dispatcher('__canDeleteEntitiesProto');
4
- export const MemKey_DeletedDocs = new MemKey('deleted--docs');
5
- export function addDeletedToTransaction(transaction, deleted) {
6
- if (!transaction)
7
- return;
8
- const storage = MemKey_DeletedDocs.get([]);
9
- let item = storage.find(i => i.transaction === transaction);
10
- if (!item) {
11
- item = { transaction, deleted: {} };
12
- storage.push(item);
13
- }
14
- if (!item.deleted[deleted.dbKey])
15
- item.deleted[deleted.dbKey] = new Set();
16
- deleted.ids.forEach(id => item.deleted[deleted.dbKey].add(id));
17
- MemKey_DeletedDocs.set(storage);
18
- }
@@ -1,6 +0,0 @@
1
- import { DBProto } from '@nu-art/ts-common';
2
- import { DB_EntityDependencyV2 } from '@nu-art/firebase-shared';
3
- import { Transaction } from 'firebase-admin/firestore';
4
- export type CanDeleteDBEntitiesProto = {
5
- __canDeleteEntitiesProto: <T extends DBProto<any>>(type: T['dbKey'], itemIds: string[], transaction?: Transaction) => Promise<DB_EntityDependencyV2>;
6
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- import { Express } from 'express';
2
- import { StringMap } from '@nu-art/ts-common';
3
- import { HttpsFunction, HttpsOptions } from 'firebase-functions/v2/https';
4
- export interface TBR_ExpressFunctionInterface {
5
- getExpressFunction(): Firebase_ExpressFunction;
6
- }
7
- export interface FirebaseFunctionInterface {
8
- getFunction(): HttpsFunction;
9
- onFunctionReady(): Promise<void>;
10
- }
11
- export declare class Firebase_ExpressFunction implements FirebaseFunctionInterface {
12
- private readonly express;
13
- private function;
14
- private toBeExecuted;
15
- private isReady;
16
- private toBeResolved;
17
- private name;
18
- static config: HttpsOptions;
19
- constructor(_express: Express);
20
- setName(name: string): this;
21
- static setConfig(config: HttpsOptions): void;
22
- getName(): string;
23
- getFunction: () => HttpsFunction;
24
- onFunctionReady: () => Promise<void>;
25
- }
26
- export type FirestoreConfigs = {
27
- runTimeOptions?: HttpsOptions;
28
- configs: any;
29
- };
30
- export type BucketConfigs = {
31
- runtimeOpts?: HttpsOptions;
32
- path: string;
33
- bucketName?: string;
34
- };
35
- export type TopicMessage = {
36
- data: string;
37
- attributes: StringMap;
38
- };
@@ -1,53 +0,0 @@
1
- import { addItemToArray } from '@nu-art/ts-common';
2
- import { onRequest } from 'firebase-functions/v2/https';
3
- export class Firebase_ExpressFunction {
4
- express;
5
- function;
6
- toBeExecuted = [];
7
- isReady = false;
8
- toBeResolved;
9
- name = 'api';
10
- static config = {};
11
- constructor(_express) {
12
- this.express = _express;
13
- }
14
- setName(name) {
15
- this.name = name;
16
- return this;
17
- }
18
- static setConfig(config) {
19
- this.config = config;
20
- }
21
- getName() {
22
- return this.name;
23
- }
24
- getFunction = () => {
25
- if (this.function)
26
- return this.function;
27
- const realFunction = onRequest(Firebase_ExpressFunction.config, this.express);
28
- return this.function = onRequest(Firebase_ExpressFunction.config, (req, res) => {
29
- if (this.isReady) {
30
- return realFunction(req, res);
31
- }
32
- return new Promise((resolve) => {
33
- // @ts-ignore
34
- addItemToArray(this.toBeExecuted, () => realFunction(req, res));
35
- this.toBeResolved = resolve;
36
- });
37
- });
38
- };
39
- onFunctionReady = async () => {
40
- this.isReady = true;
41
- const toBeExecuted = this.toBeExecuted;
42
- this.toBeExecuted = [];
43
- for (const toExecute of toBeExecuted) {
44
- try {
45
- await toExecute();
46
- }
47
- catch (e) {
48
- console.error('Error running function: ', e);
49
- }
50
- }
51
- this.toBeResolved && this.toBeResolved();
52
- };
53
- }
package/v1.d.ts DELETED
@@ -1,21 +0,0 @@
1
- export * from './auth/firebase-session.js';
2
- export * from './auth/FirebaseSession_Admin.js';
3
- export * from './functions/firebase-function.js';
4
- export * from './ModuleBE_Firebase.js';
5
- export * from './firestore/FirestoreInterface.js';
6
- export * from './firestore/FirestoreCollection.js';
7
- export * from './firestore/FirestoreTransaction.js';
8
- export * from './firestore/FirestoreWrapperBE.js';
9
- export * from './firestore/types.js';
10
- export * from './database/DatabaseWrapperBE.js';
11
- export * from './storage/types.js';
12
- export * from './storage/StorageWrapperBE.js';
13
- export * from './push/PushMessagesWrapperBE.js';
14
- export * from './push/types.js';
15
- export * from './functions-v2/ModuleBE_BaseFunction.js';
16
- export * from './functions-v2/ModuleBE_ExpressFunction_V2.js';
17
- export * from './functions-v2/ModuleBE_FirebaseDBListener.js';
18
- export * from './functions-v2/ModuleBE_FirebaseScheduler.js';
19
- export * from './functions-v2/ModuleBE_FirestoreListener.js';
20
- export * from './functions-v2/ModuleBE_PubSubFunction.js';
21
- export * from './functions-v2/ModuleBE_StorageListener.js';
package/v1.js DELETED
@@ -1,38 +0,0 @@
1
- /*
2
- * Firebase is a simpler Typescript wrapper to all of firebase services.
3
- *
4
- * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
- export * from './auth/firebase-session.js';
19
- export * from './auth/FirebaseSession_Admin.js';
20
- export * from './functions/firebase-function.js';
21
- export * from './ModuleBE_Firebase.js';
22
- export * from './firestore/FirestoreInterface.js';
23
- export * from './firestore/FirestoreCollection.js';
24
- export * from './firestore/FirestoreTransaction.js';
25
- export * from './firestore/FirestoreWrapperBE.js';
26
- export * from './firestore/types.js';
27
- export * from './database/DatabaseWrapperBE.js';
28
- export * from './storage/types.js';
29
- export * from './storage/StorageWrapperBE.js';
30
- export * from './push/PushMessagesWrapperBE.js';
31
- export * from './push/types.js';
32
- export * from './functions-v2/ModuleBE_BaseFunction.js';
33
- export * from './functions-v2/ModuleBE_ExpressFunction_V2.js';
34
- export * from './functions-v2/ModuleBE_FirebaseDBListener.js';
35
- export * from './functions-v2/ModuleBE_FirebaseScheduler.js';
36
- export * from './functions-v2/ModuleBE_FirestoreListener.js';
37
- export * from './functions-v2/ModuleBE_PubSubFunction.js';
38
- export * from './functions-v2/ModuleBE_StorageListener.js';