@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
@@ -0,0 +1,132 @@
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 { __stringify, BadImplementationException, ImplementationMissingException, StaticLogger } from '@nu-art/ts-common';
19
+ const MqlComparatorMap = {
20
+ $nin: '$nin',
21
+ $in: '$in',
22
+ $ac: '$elemMatch',
23
+ $aca: '$in',
24
+ $gt: '$gt',
25
+ $gte: '$gte',
26
+ $lt: '$lt',
27
+ $lte: '$lte',
28
+ $eq: '$eq',
29
+ $neq: '$ne',
30
+ };
31
+ export class MongoInterface {
32
+ static buildQuery(query) {
33
+ try {
34
+ const result = { filter: {} };
35
+ if (query?.where)
36
+ result.filter = this.buildFilter(query.where);
37
+ if (query?.select)
38
+ result.projection = this.buildProjection(query.select);
39
+ if (query?.orderBy)
40
+ result.sort = this.buildSort(query.orderBy);
41
+ if (query?.limit !== undefined)
42
+ Object.assign(result, this.buildPagination(query.limit));
43
+ return result;
44
+ }
45
+ catch (e) {
46
+ StaticLogger.logError(`Query: ${JSON.stringify(query)}`);
47
+ StaticLogger.logError(`Error: ${e}`);
48
+ throw e;
49
+ }
50
+ }
51
+ static buildFilter(where, prefix) {
52
+ const filter = {};
53
+ for (const field of Object.keys(where)) {
54
+ const value = where[field];
55
+ if (value === undefined || value === null)
56
+ continue;
57
+ const key = prefix ? `${prefix}.${field}` : field;
58
+ if (Array.isArray(value)) {
59
+ if (value.length === 0)
60
+ throw new BadImplementationException(`Empty array in where clause for field '${key}'`);
61
+ if (value.length === 1)
62
+ filter[key] = value[0];
63
+ else
64
+ filter[key] = { $in: value };
65
+ continue;
66
+ }
67
+ if (this.isQueryComparator(value)) {
68
+ const comparatorKey = Object.keys(value)[0];
69
+ const mqlOp = MqlComparatorMap[comparatorKey];
70
+ if (!mqlOp)
71
+ throw new ImplementationMissingException(`No MQL comparator for: ${comparatorKey} in filter: ${__stringify(where)}`);
72
+ const operand = value[comparatorKey];
73
+ if (operand === undefined)
74
+ throw new ImplementationMissingException(`No value for comparator ${comparatorKey} in filter: ${__stringify(where)}`);
75
+ if (comparatorKey === '$ac') {
76
+ filter[key] = operand;
77
+ }
78
+ else {
79
+ filter[key] = { [mqlOp]: operand };
80
+ }
81
+ continue;
82
+ }
83
+ const valueType = typeof value;
84
+ if (valueType === 'string' || valueType === 'number' || valueType === 'boolean') {
85
+ filter[key] = value;
86
+ continue;
87
+ }
88
+ if (valueType === 'object') {
89
+ Object.assign(filter, this.buildFilter(value, key));
90
+ continue;
91
+ }
92
+ throw new ImplementationMissingException(`Cannot compile where clause for '${key}' with value type '${valueType}' in filter: ${__stringify(where)}`);
93
+ }
94
+ return filter;
95
+ }
96
+ static isQueryComparator(value) {
97
+ if (typeof value !== 'object' || Array.isArray(value))
98
+ return false;
99
+ const keys = Object.keys(value);
100
+ return keys.length === 1 && (value['$ac'] !== undefined ||
101
+ value['$aca'] !== undefined ||
102
+ value['$in'] !== undefined ||
103
+ value['$nin'] !== undefined ||
104
+ value['$gt'] !== undefined ||
105
+ value['$gte'] !== undefined ||
106
+ value['$lt'] !== undefined ||
107
+ value['$lte'] !== undefined ||
108
+ value['$neq'] !== undefined ||
109
+ value['$eq'] !== undefined);
110
+ }
111
+ static buildProjection(select) {
112
+ const projection = {};
113
+ for (const field of select)
114
+ projection[field] = 1;
115
+ return projection;
116
+ }
117
+ static buildSort(orderBy) {
118
+ const sort = {};
119
+ for (const entry of orderBy)
120
+ sort[entry.key] = entry.order === 'asc' ? 1 : -1;
121
+ return sort;
122
+ }
123
+ static buildPagination(limit) {
124
+ if (typeof limit === 'number')
125
+ return { limit };
126
+ const page = limit.page || 0;
127
+ const result = { limit: limit.itemsCount };
128
+ if (page > 0)
129
+ result.skip = limit.itemsCount * page;
130
+ return result;
131
+ }
132
+ }
@@ -0,0 +1,18 @@
1
+ import { Database, DB_Prototype } from '@nu-art/db-api-shared';
2
+ import { Logger } from '@nu-art/ts-common';
3
+ import { MongoCollection } from './MongoCollection.js';
4
+ import { FirestoreCollectionHooks } from './FirestoreCollection.js';
5
+ import type { Db as MongoDriverDb, MongoClient } from 'mongodb';
6
+ export declare const CONST_MONGODB_EMULATOR_HOST = "MONGODB_EMULATOR_HOST";
7
+ export declare class MongoWrapperBE extends Logger {
8
+ private static instances;
9
+ static isEmulator(): boolean;
10
+ static getOrCreate(client: MongoClient, dbName: string): MongoWrapperBE;
11
+ readonly client: MongoClient;
12
+ readonly db: MongoDriverDb;
13
+ private readonly collections;
14
+ constructor(client: MongoClient, dbName: string);
15
+ runTransaction: <ReturnType>(processor: () => Promise<ReturnType>, label?: string) => Promise<ReturnType>;
16
+ getCollection<Proto extends DB_Prototype>(dbDef: Database<Proto>, hooks?: FirestoreCollectionHooks<Proto['dbType']>): MongoCollection<Proto>;
17
+ listCollections(): Promise<string[]>;
18
+ }
@@ -0,0 +1,95 @@
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 { Logger, Promise_all_sequentially } from '@nu-art/ts-common';
19
+ import { MongoCollection } from './MongoCollection.js';
20
+ import { getActiveTransaction, MemKey_FirestoreTransaction } from './consts.js';
21
+ import { MemStorage } from '@nu-art/ts-common/mem-storage';
22
+ export const CONST_MONGODB_EMULATOR_HOST = 'MONGODB_EMULATOR_HOST';
23
+ export class MongoWrapperBE extends Logger {
24
+ static instances = {};
25
+ static isEmulator() {
26
+ return !!process.env[CONST_MONGODB_EMULATOR_HOST];
27
+ }
28
+ static getOrCreate(client, dbName) {
29
+ const key = dbName;
30
+ if (this.instances[key])
31
+ return this.instances[key];
32
+ return this.instances[key] = new MongoWrapperBE(client, dbName);
33
+ }
34
+ client;
35
+ db;
36
+ collections = {};
37
+ constructor(client, dbName) {
38
+ super();
39
+ this.client = client;
40
+ this.db = client.db(dbName);
41
+ }
42
+ runTransaction = async (processor, label) => {
43
+ if (getActiveTransaction())
44
+ return processor();
45
+ const tag = label ?? 'MongoWrapper';
46
+ const postTransactionActions = [];
47
+ const session = this.client.startSession();
48
+ this.logDebug(`TX-START [${tag}]`);
49
+ try {
50
+ let result;
51
+ const wrapper = {
52
+ transaction: session,
53
+ active: true,
54
+ writeCount: 0,
55
+ beginTransaction: () => session.startTransaction(),
56
+ };
57
+ const parentStorage = MemStorage.getStore();
58
+ try {
59
+ await new MemStorage().init(async () => {
60
+ MemKey_FirestoreTransaction.set(wrapper);
61
+ // @ts-ignore
62
+ session.postTransaction = (action) => {
63
+ postTransactionActions.push(action);
64
+ };
65
+ result = await processor();
66
+ }, parentStorage);
67
+ }
68
+ catch (e) {
69
+ wrapper.active = false;
70
+ if (wrapper.writeCount > 0)
71
+ await session.abortTransaction();
72
+ throw e;
73
+ }
74
+ wrapper.active = false;
75
+ if (wrapper.writeCount > 0)
76
+ await session.commitTransaction();
77
+ this.logDebug(`TX-END [${tag}] writes=${wrapper.writeCount}`);
78
+ await Promise_all_sequentially(postTransactionActions);
79
+ return result;
80
+ }
81
+ finally {
82
+ await session.endSession();
83
+ }
84
+ };
85
+ getCollection(dbDef, hooks) {
86
+ const existing = this.collections[dbDef.dbKey];
87
+ if (existing)
88
+ return existing;
89
+ return this.collections[dbDef.dbKey] = new MongoCollection(this.db, dbDef, hooks);
90
+ }
91
+ async listCollections() {
92
+ const collections = await this.db.listCollections().toArray();
93
+ return collections.map(c => c.name);
94
+ }
95
+ }
@@ -0,0 +1,23 @@
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
+ import { Transaction } from 'firebase-admin/firestore';
6
+ export declare const canDeleteDispatcher: Dispatcher<CanDeleteDBEntitiesProto, "__canDeleteEntitiesProto", [type: any, itemIds: string[]], import("@nu-art/firebase-shared").DB_EntityDependencyV2>;
7
+ export type TransactionWrapper = {
8
+ transaction: Transaction;
9
+ active: boolean;
10
+ writeCount?: number;
11
+ beginTransaction?: () => void;
12
+ };
13
+ export declare const MemKey_FirestoreTransaction: MemKey<TransactionWrapper>;
14
+ export declare function getActiveTransaction(): Transaction | undefined;
15
+ export declare function markTransactionWrite(): void;
16
+ export type MemKey_DeletedDocs_Type = {
17
+ transaction: Transaction;
18
+ deleted: {
19
+ [dbKey: string]: Set<UniqueId>;
20
+ };
21
+ };
22
+ export declare const MemKey_DeletedDocs: MemKey<MemKey_DeletedDocs_Type[]>;
23
+ export declare function addDeletedToTransaction(deleted: PotentialDependenciesToDelete): void;
@@ -0,0 +1,34 @@
1
+ import { Dispatcher } from '@nu-art/ts-common';
2
+ import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage';
3
+ export const canDeleteDispatcher = new Dispatcher('__canDeleteEntitiesProto');
4
+ export const MemKey_FirestoreTransaction = new MemKey('firestore--transaction');
5
+ export function getActiveTransaction() {
6
+ const wrapper = MemKey_FirestoreTransaction.peak();
7
+ if (!wrapper?.active)
8
+ return undefined;
9
+ return wrapper.transaction;
10
+ }
11
+ export function markTransactionWrite() {
12
+ const wrapper = MemKey_FirestoreTransaction.peak();
13
+ if (!wrapper?.active)
14
+ return;
15
+ if (wrapper.writeCount === 0)
16
+ wrapper.beginTransaction?.();
17
+ wrapper.writeCount = (wrapper.writeCount ?? 0) + 1;
18
+ }
19
+ export const MemKey_DeletedDocs = new MemKey('deleted--docs');
20
+ export function addDeletedToTransaction(deleted) {
21
+ const transaction = getActiveTransaction();
22
+ if (!transaction)
23
+ return;
24
+ const storage = MemKey_DeletedDocs.get([]);
25
+ let item = storage.find(i => i.transaction === transaction);
26
+ if (!item) {
27
+ item = { transaction, deleted: {} };
28
+ storage.push(item);
29
+ }
30
+ if (!item.deleted[deleted.dbKey])
31
+ item.deleted[deleted.dbKey] = new Set();
32
+ deleted.ids.forEach(id => item.deleted[deleted.dbKey].add(id));
33
+ MemKey_DeletedDocs.set(storage);
34
+ }
@@ -1,6 +1,11 @@
1
- import { CollectionReference, QueryDocumentSnapshot, Query, DocumentReference, Firestore, DocumentData } from 'firebase-admin/firestore';
1
+ import { DB_Prototype } from '@nu-art/db-api-shared';
2
+ import { DB_EntityDependencyV2 } from '@nu-art/firebase-shared';
3
+ import { CollectionReference, DocumentData, DocumentReference, Firestore, Query, QueryDocumentSnapshot } from 'firebase-admin/firestore';
2
4
  export type FirestoreType_Collection = CollectionReference;
3
5
  export type FirestoreType_DocumentSnapshot<T = DocumentData> = QueryDocumentSnapshot<T>;
4
6
  export type FirestoreType_Query = Query;
5
7
  export type FirestoreType_DocumentReference<T> = DocumentReference<T>;
6
8
  export type FirestoreType = Firestore;
9
+ export type CanDeleteDBEntitiesProto = {
10
+ __canDeleteEntitiesProto: <T extends DB_Prototype>(type: T['dbKey'], itemIds: string[]) => Promise<DB_EntityDependencyV2>;
11
+ };
@@ -1,25 +1 @@
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
1
  export {};
19
- // export type FirestoreType_Collection = admin.CollectionReference | firebase.firestore.CollectionReference;
20
- // export type FirestoreType_DocumentSnapshot = admin.firestore.QueryDocumentSnapshot | firebase.firestore.QueryDocumentSnapshot;
21
- // export type FirestoreType_Query = (admin.firestore.Query | firebase.firestore.Query) & { select?: (...field: string[]) => FirestoreType_Query };
22
- // export type FirestoreType_DocumentReference = admin.firestore.DocumentReference | firebase.firestore.DocumentReference;
23
- // export type FirestoreType = (admin.firestore.Firestore | firebase.firestore.Firestore) & ({ listCollections?: () => Promise<FirestoreType_Collection[]> });
24
- // export type FirestoreType_Transaction = admin.firestore.Transaction | firebase.firestore.Transaction;
25
- //
@@ -1,6 +1,9 @@
1
- import { Module } from '@nu-art/ts-common';
2
- import { FirebaseFunctionInterface } from '../functions/firebase-function.js';
3
- export declare abstract class ModuleBE_BaseFunction<Config = any> extends Module<Config> implements FirebaseFunctionInterface {
1
+ import { Module, TS_Object } from '@nu-art/ts-common';
2
+ export interface FirebaseFunctionInterface {
3
+ getFunction(): any;
4
+ onFunctionReady(): Promise<void>;
5
+ }
6
+ export declare abstract class ModuleBE_BaseFunction<Config extends TS_Object = any> extends Module<Config> implements FirebaseFunctionInterface {
4
7
  protected isReady: boolean;
5
8
  protected toBeExecuted: (() => Promise<any>)[];
6
9
  protected toBeResolved: (value?: (PromiseLike<any>)) => void;
@@ -5,6 +5,7 @@ export class ModuleBE_BaseFunction extends Module {
5
5
  toBeResolved;
6
6
  constructor(tag) {
7
7
  super(tag);
8
+ this.addToClassStack(ModuleBE_BaseFunction);
8
9
  this.onFunctionReady = this.onFunctionReady.bind(this);
9
10
  }
10
11
  async handleCallback(callback) {
@@ -1,11 +1,13 @@
1
1
  import { ModuleBE_BaseFunction } from './ModuleBE_BaseFunction.js';
2
2
  import { Express } from 'express';
3
3
  import { HttpsFunction, HttpsOptions } from 'firebase-functions/v2/https';
4
- export declare class ModuleBE_ExpressFunction_V2<Config = {}> extends ModuleBE_BaseFunction<{
4
+ export type ExpressResolver = () => Express;
5
+ export declare class ModuleBE_ExpressFunction_Class extends ModuleBE_BaseFunction<{
5
6
  options: HttpsOptions;
6
- } & Config> {
7
+ }> {
7
8
  private function;
8
- protected constructor(name?: string);
9
+ private readonly expressResolver;
10
+ constructor(name?: string, expressResolver?: ExpressResolver);
9
11
  getFunction: () => HttpsFunction;
10
12
  protected createFunction(_express: Express): HttpsFunction;
11
13
  }
@@ -2,15 +2,19 @@ import { ModuleBE_BaseFunction } from './ModuleBE_BaseFunction.js';
2
2
  import { addItemToArray } from '@nu-art/ts-common';
3
3
  import express from 'express';
4
4
  import { onRequest } from 'firebase-functions/v2/https';
5
- export class ModuleBE_ExpressFunction_V2 extends ModuleBE_BaseFunction {
5
+ export class ModuleBE_ExpressFunction_Class extends ModuleBE_BaseFunction {
6
6
  function;
7
- constructor(name = 'api') {
7
+ expressResolver;
8
+ constructor(name = 'api', expressResolver) {
8
9
  super(name);
10
+ this.setName(name);
11
+ this.expressResolver = expressResolver ?? (() => express());
12
+ this.addToClassStack(ModuleBE_ExpressFunction_Class);
9
13
  }
10
14
  getFunction = () => {
11
15
  if (this.function)
12
16
  return this.function;
13
- const _express = express();
17
+ const _express = this.expressResolver();
14
18
  const realFunction = this.createFunction(_express);
15
19
  return this.function = onRequest(this.config.options, (req, res) => {
16
20
  if (this.isReady) { // @ts-ignore
@@ -1,5 +1,6 @@
1
+ import { TS_Object } from '@nu-art/ts-common';
1
2
  import { ModuleBE_BaseFunction } from './ModuleBE_BaseFunction.js';
2
- export declare abstract class ModuleBE_FirebaseDBListener<DataType = any, ConfigType = any> extends ModuleBE_BaseFunction<ConfigType> {
3
+ export declare abstract class ModuleBE_FirebaseDBListener<DataType = any, ConfigType extends TS_Object = any> extends ModuleBE_BaseFunction<ConfigType> {
3
4
  private readonly listeningPath;
4
5
  private function;
5
6
  protected constructor(listeningPath: string, name?: string);
@@ -8,6 +8,7 @@ export class ModuleBE_FirebaseDBListener extends ModuleBE_BaseFunction {
8
8
  super();
9
9
  if (name)
10
10
  this.setName(name);
11
+ this.addToClassStack(ModuleBE_FirebaseDBListener);
11
12
  this.listeningPath = listeningPath;
12
13
  }
13
14
  getFunction = () => {
@@ -18,6 +18,7 @@ export class ModuleBE_FirebaseScheduler extends ModuleBE_BaseFunction {
18
18
  constructor(name, tag) {
19
19
  super(tag);
20
20
  name && this.setName(name);
21
+ this.addToClassStack(ModuleBE_FirebaseScheduler);
21
22
  }
22
23
  /**
23
24
  * Add a running condition to the list of conditions that must pass in order for the backup to execute
@@ -1,6 +1,10 @@
1
1
  import { TS_Object } from '@nu-art/ts-common';
2
- import { FirestoreConfigs } from '../functions/firebase-function.js';
3
2
  import { ModuleBE_BaseFunction } from './ModuleBE_BaseFunction.js';
3
+ import { HttpsOptions } from 'firebase-functions/v2/https';
4
+ export type FirestoreConfigs = {
5
+ runTimeOptions?: HttpsOptions;
6
+ configs: any;
7
+ };
4
8
  import { DocumentOptions, DocumentSnapshot, FirestoreEvent } from 'firebase-functions/v2/firestore';
5
9
  import { Change, CloudFunction } from 'firebase-functions/v2';
6
10
  export declare abstract class ModuleBE_FirestoreListener<DataType extends TS_Object, ConfigType extends FirestoreConfigs = FirestoreConfigs> extends ModuleBE_BaseFunction<ConfigType & DocumentOptions> {
@@ -6,6 +6,7 @@ export class ModuleBE_FirestoreListener extends ModuleBE_BaseFunction {
6
6
  constructor(collectionName, name, tag) {
7
7
  super(tag);
8
8
  name && this.setName(name);
9
+ this.addToClassStack(ModuleBE_FirestoreListener);
9
10
  this.setDefaultConfig({ document: `${collectionName}/{docId}` });
10
11
  }
11
12
  getFunction = () => {
@@ -1,6 +1,9 @@
1
- import { TS_Object } from '@nu-art/ts-common';
1
+ import { StringMap, TS_Object } from '@nu-art/ts-common';
2
2
  import { ModuleBE_BaseFunction } from './ModuleBE_BaseFunction.js';
3
- import { TopicMessage } from '../functions/firebase-function.js';
3
+ export type TopicMessage = {
4
+ data: string;
5
+ attributes: StringMap;
6
+ };
4
7
  import { CloudEvent, CloudFunction } from 'firebase-functions/v2';
5
8
  import { MessagePublishedData } from 'firebase-functions/v2/pubsub';
6
9
  export declare abstract class ModuleBE_PubSubFunction<T extends TS_Object> extends ModuleBE_BaseFunction {
@@ -7,6 +7,7 @@ export class ModuleBE_PubSubFunction extends ModuleBE_BaseFunction {
7
7
  constructor(topic, tag) {
8
8
  super(tag);
9
9
  this.topic = topic;
10
+ this.addToClassStack(ModuleBE_PubSubFunction);
10
11
  }
11
12
  _onPublish = async (object, originalMessage, event) => {
12
13
  try {
@@ -7,6 +7,7 @@ export class ModuleBE_StorageListener extends ModuleBE_BaseFunction {
7
7
  super();
8
8
  if (path)
9
9
  this.setDefaultConfig({ path: path, timeoutSeconds: 300, memory: '2GB' });
10
+ this.addToClassStack(ModuleBE_StorageListener);
10
11
  name && this.setName(name);
11
12
  }
12
13
  getFunction = () => {
package/index.d.ts CHANGED
@@ -2,20 +2,23 @@ export * from './auth/firebase-session.js';
2
2
  export * from './auth/FirebaseSession_Admin.js';
3
3
  export * from './database/DatabaseWrapperBE.js';
4
4
  export * from './storage/types.js';
5
- export * from './firestore-v3/consts.js';
6
- export * from './firestore-v3/DocWrapperV3.js';
7
- export * from './firestore-v3/FirestoreCollectionV3.js';
8
- export * from './firestore-v3/FirestoreInterfaceV3.js';
9
- export * from './firestore-v3/FirestoreWrapperBEV3.js';
10
- export * from './firestore-v3/types.js';
5
+ export * from './firestore/consts.js';
6
+ export * from './firestore/DocWrapper.js';
7
+ export * from './firestore/FirestoreCollection.js';
8
+ export * from './firestore/FirestoreInterface.js';
9
+ export * from './firestore/FirestoreWrapperBE.js';
10
+ export * from './firestore/MongoCollection.js';
11
+ export * from './firestore/MongoInterface.js';
12
+ export * from './firestore/MongoWrapperBE.js';
13
+ export * from './firestore/types.js';
11
14
  export * from './push/PushMessagesWrapperBE.js';
12
15
  export * from './push/types.js';
13
16
  export * from './storage/StorageWrapperBE.js';
14
- export * from './functions-v2/ModuleBE_BaseFunction.js';
15
- export * from './functions-v2/ModuleBE_ExpressFunction_V2.js';
16
- export * from './functions-v2/ModuleBE_FirebaseDBListener.js';
17
- export * from './functions-v2/ModuleBE_FirebaseScheduler.js';
18
- export * from './functions-v2/ModuleBE_FirestoreListener.js';
19
- export * from './functions-v2/ModuleBE_PubSubFunction.js';
20
- export * from './functions-v2/ModuleBE_StorageListener.js';
17
+ export * from './functions/ModuleBE_BaseFunction.js';
18
+ export * from './functions/ModuleBE_ExpressFunction_Class.js';
19
+ export * from './functions/ModuleBE_FirebaseDBListener.js';
20
+ export * from './functions/ModuleBE_FirebaseScheduler.js';
21
+ export * from './functions/ModuleBE_FirestoreListener.js';
22
+ export * from './functions/ModuleBE_PubSubFunction.js';
23
+ export * from './functions/ModuleBE_StorageListener.js';
21
24
  export * from './ModuleBE_Firebase.js';
package/index.js CHANGED
@@ -19,20 +19,23 @@ export * from './auth/firebase-session.js';
19
19
  export * from './auth/FirebaseSession_Admin.js';
20
20
  export * from './database/DatabaseWrapperBE.js';
21
21
  export * from './storage/types.js';
22
- export * from './firestore-v3/consts.js';
23
- export * from './firestore-v3/DocWrapperV3.js';
24
- export * from './firestore-v3/FirestoreCollectionV3.js';
25
- export * from './firestore-v3/FirestoreInterfaceV3.js';
26
- export * from './firestore-v3/FirestoreWrapperBEV3.js';
27
- export * from './firestore-v3/types.js';
22
+ export * from './firestore/consts.js';
23
+ export * from './firestore/DocWrapper.js';
24
+ export * from './firestore/FirestoreCollection.js';
25
+ export * from './firestore/FirestoreInterface.js';
26
+ export * from './firestore/FirestoreWrapperBE.js';
27
+ export * from './firestore/MongoCollection.js';
28
+ export * from './firestore/MongoInterface.js';
29
+ export * from './firestore/MongoWrapperBE.js';
30
+ export * from './firestore/types.js';
28
31
  export * from './push/PushMessagesWrapperBE.js';
29
32
  export * from './push/types.js';
30
33
  export * from './storage/StorageWrapperBE.js';
31
- export * from './functions-v2/ModuleBE_BaseFunction.js';
32
- export * from './functions-v2/ModuleBE_ExpressFunction_V2.js';
33
- export * from './functions-v2/ModuleBE_FirebaseDBListener.js';
34
- export * from './functions-v2/ModuleBE_FirebaseScheduler.js';
35
- export * from './functions-v2/ModuleBE_FirestoreListener.js';
36
- export * from './functions-v2/ModuleBE_PubSubFunction.js';
37
- export * from './functions-v2/ModuleBE_StorageListener.js';
34
+ export * from './functions/ModuleBE_BaseFunction.js';
35
+ export * from './functions/ModuleBE_ExpressFunction_Class.js';
36
+ export * from './functions/ModuleBE_FirebaseDBListener.js';
37
+ export * from './functions/ModuleBE_FirebaseScheduler.js';
38
+ export * from './functions/ModuleBE_FirestoreListener.js';
39
+ export * from './functions/ModuleBE_PubSubFunction.js';
40
+ export * from './functions/ModuleBE_StorageListener.js';
38
41
  export * from './ModuleBE_Firebase.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/firebase-backend",
3
- "version": "0.401.9",
3
+ "version": "0.500.6",
4
4
  "description": "Storm - Express & Typescript based backend framework Backend",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -30,28 +30,31 @@
30
30
  "scripts": {
31
31
  "build": "tsc",
32
32
  "run-tests": "firebase emulators:exec \"npm run test\"",
33
- "test": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files '**/*.ts' src/test/firestore-v2/__test.ts",
33
+ "test": "ts-mocha -p src/test/tsconfig.json --timeout 0 'src/test/**/*.test.firebase.ts'",
34
+ "test:watch": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files '**/*.ts' 'src/test/**/*.test.firebase.ts'",
34
35
  "rtv2": "firebase emulators:exec \"npm run test-v2\"",
35
- "test-v2": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files '**/*.ts' src/test/firestore-v2/__test.ts"
36
+ "test-v2": "ts-mocha -p src/test/tsconfig.json --timeout 0 'src/test/**/*.test.firebase.ts'"
36
37
  },
37
38
  "dependencies": {
38
- "@nu-art/firebase-shared": "0.401.9",
39
+ "@nu-art/db-api-shared": "0.500.6",
40
+ "@nu-art/firebase-shared": "0.500.6",
39
41
  "@google-cloud/common": "^5.0.2",
40
42
  "@google-cloud/firestore": "^7.11.0",
41
43
  "@google-cloud/storage": "^7.15.0",
42
- "@nu-art/google-services-backend": "0.401.9",
43
- "@nu-art/ts-common": "0.401.9",
44
+ "@nu-art/google-services-backend": "0.500.6",
45
+ "@nu-art/ts-common": "0.500.6",
44
46
  "express": "^4.18.2",
45
47
  "firebase": "^11.9.0",
46
48
  "firebase-admin": "13.4.0",
47
49
  "firebase-functions": "6.3.2",
48
50
  "google-auth-library": "^10.0.0",
51
+ "mongodb": "^7.1.1",
49
52
  "http-proxy": "1.18.1",
50
53
  "url": "0.11.3",
51
54
  "ws": "^8.13.0"
52
55
  },
53
56
  "devDependencies": {
54
- "@nu-art/testalot": "0.401.9",
57
+ "@nu-art/testalot": "0.500.6",
55
58
  "@types/compression": "^1.0.1",
56
59
  "@types/chai": "^4.3.4",
57
60
  "@types/mocha": "^10.0.1",