@my-devkit/firebase 1.0.193 → 1.0.195

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 (66) hide show
  1. package/.eslintrc.js +2 -4
  2. package/dist/app-factory.js +2 -2
  3. package/dist/app-factory.js.map +1 -1
  4. package/dist/context.js +18 -18
  5. package/dist/context.js.map +1 -1
  6. package/dist/decorators/controller/body.js.map +1 -1
  7. package/dist/decorators/controller/body.spec.js +1 -1
  8. package/dist/decorators/controller/body.spec.js.map +1 -1
  9. package/dist/decorators/controller/controller.spec.js.map +1 -1
  10. package/dist/decorators/controller/get.js +4 -1
  11. package/dist/decorators/controller/get.js.map +1 -1
  12. package/dist/decorators/controller/get.spec.js.map +1 -1
  13. package/dist/decorators/controller/param.js.map +1 -1
  14. package/dist/decorators/controller/param.spec.js +1 -1
  15. package/dist/decorators/controller/param.spec.js.map +1 -1
  16. package/dist/decorators/controller/post.js +4 -1
  17. package/dist/decorators/controller/post.js.map +1 -1
  18. package/dist/decorators/controller/post.spec.js.map +1 -1
  19. package/dist/decorators/controller/query.js.map +1 -1
  20. package/dist/decorators/controller/query.spec.js +1 -1
  21. package/dist/decorators/controller/query.spec.js.map +1 -1
  22. package/dist/decorators/handler/command-handler.js.map +1 -1
  23. package/dist/decorators/handler/command-handler.spec.js.map +1 -1
  24. package/dist/decorators/handler/event-handler.js.map +1 -1
  25. package/dist/decorators/handler/event-handler.spec.js.map +1 -1
  26. package/dist/firestore-client.js +47 -32
  27. package/dist/firestore-client.js.map +1 -1
  28. package/dist/interfaces/type.d.ts +1 -1
  29. package/dist/reflect.js +0 -1
  30. package/dist/reflect.js.map +1 -1
  31. package/dist/sanity-check/controller.js.map +1 -1
  32. package/dist/sanity-check/module.js +1 -3
  33. package/dist/sanity-check/module.js.map +1 -1
  34. package/dist/server/middlewares/authentication-middleware.js.map +1 -1
  35. package/dist/server/server.js.map +1 -1
  36. package/dist/zip-helper.js +1 -1
  37. package/dist/zip-helper.js.map +1 -1
  38. package/package.json +4 -4
  39. package/src/app-factory.ts +65 -48
  40. package/src/context.ts +2 -2
  41. package/src/decorators/controller/body.spec.ts +3 -3
  42. package/src/decorators/controller/body.ts +1 -1
  43. package/src/decorators/controller/controller.spec.ts +1 -3
  44. package/src/decorators/controller/get.spec.ts +0 -1
  45. package/src/decorators/controller/get.ts +5 -2
  46. package/src/decorators/controller/param.spec.ts +3 -2
  47. package/src/decorators/controller/param.ts +1 -1
  48. package/src/decorators/controller/post.spec.ts +0 -2
  49. package/src/decorators/controller/post.ts +5 -2
  50. package/src/decorators/controller/query.spec.ts +3 -2
  51. package/src/decorators/controller/query.ts +1 -1
  52. package/src/decorators/handler/command-handler.spec.ts +2 -11
  53. package/src/decorators/handler/command-handler.ts +1 -1
  54. package/src/decorators/handler/event-handler.spec.ts +2 -11
  55. package/src/decorators/handler/event-handler.ts +1 -1
  56. package/src/firestore-client.ts +67 -39
  57. package/src/interfaces/app-config.ts +0 -1
  58. package/src/interfaces/newable.ts +1 -1
  59. package/src/interfaces/type.ts +2 -2
  60. package/src/reflect.ts +7 -7
  61. package/src/sanity-check/controller.ts +0 -1
  62. package/src/sanity-check/module.ts +2 -6
  63. package/src/server/middlewares/authentication-middleware.ts +0 -1
  64. package/src/server/server.ts +0 -1
  65. package/src/zip-helper.ts +1 -1
  66. package/tsconfig.json +1 -4
@@ -4,7 +4,6 @@ import { getFirestore } from 'firebase-admin/firestore';
4
4
  import { Injectable, TransactionalClient } from './decorators';
5
5
  import { ITransactionalClient } from './interfaces';
6
6
 
7
-
8
7
  @TransactionalClient()
9
8
  @Injectable()
10
9
  export class FirestoreClient implements ITransactionalClient {
@@ -45,7 +44,11 @@ export class FirestoreClient implements ITransactionalClient {
45
44
  return this.queryDocument<T>(path);
46
45
  }
47
46
 
48
- public async _findWhere<T extends Document>(collection: string, whereClauses: [string, FirestoreClient.Operator, any | any[]][] = [], options?: FirestoreClient.QueryOptions): Promise<T> {
47
+ public async _findWhere<T extends Document>(
48
+ collection: string,
49
+ whereClauses: [string, FirestoreClient.Operator, any | any[]][] = [],
50
+ options?: FirestoreClient.QueryOptions
51
+ ): Promise<T> {
49
52
  const documents = await this._getWhere<T>(collection, whereClauses, options);
50
53
 
51
54
  if (documents.length > 1) {
@@ -69,7 +72,11 @@ export class FirestoreClient implements ITransactionalClient {
69
72
  return this._getWhere(collection, [], options);
70
73
  }
71
74
 
72
- public async _getWhere<T extends Document>(collection: string, whereClauses: [string, FirestoreClient.Operator, any | any[]][] = [], options?: FirestoreClient.QueryOptions): Promise<T[]> {
75
+ public async _getWhere<T extends Document>(
76
+ collection: string,
77
+ whereClauses: [string, FirestoreClient.Operator, any | any[]][] = [],
78
+ options?: FirestoreClient.QueryOptions
79
+ ): Promise<T[]> {
73
80
  Logger.info(`Repository: getWhere ${collection} whereClauses: ${JSON.stringify(whereClauses)}`);
74
81
  const documentMap = await this.queryCollection<T>(collection, whereClauses, options);
75
82
 
@@ -118,7 +125,6 @@ export class FirestoreClient implements ITransactionalClient {
118
125
  return documents;
119
126
  }
120
127
 
121
-
122
128
  public createDocument<T extends Document>(document: T): void {
123
129
  const existingOperation = this.operations.get(document._path);
124
130
 
@@ -136,7 +142,11 @@ export class FirestoreClient implements ITransactionalClient {
136
142
  throw new Error(`FirestoreClient: Unhandled existing operation ${existingOperation.action} on ${document._path}`);
137
143
  }
138
144
  } else {
139
- this.operations.set(document._path, { document, action: FirestoreClient.Action.Create, committed: false });
145
+ this.operations.set(document._path, {
146
+ document,
147
+ action: FirestoreClient.Action.Create,
148
+ committed: false
149
+ });
140
150
  }
141
151
  }
142
152
 
@@ -155,7 +165,11 @@ export class FirestoreClient implements ITransactionalClient {
155
165
  throw new Error(`FirestoreClient: Unhandled existing operation ${existingOperation.action} on ${document._path}`);
156
166
  }
157
167
  } else {
158
- this.operations.set(document._path, { document, action: FirestoreClient.Action.Update, committed: false });
168
+ this.operations.set(document._path, {
169
+ document,
170
+ action: FirestoreClient.Action.Update,
171
+ committed: false
172
+ });
159
173
  }
160
174
  }
161
175
 
@@ -177,7 +191,11 @@ export class FirestoreClient implements ITransactionalClient {
177
191
  throw new Error(`FirestoreClient: Unhandled existing operation ${existingOperation.action} on ${document._path}`);
178
192
  }
179
193
  } else {
180
- this.operations.set(document._path, { document, action: FirestoreClient.Action.Delete, committed: false });
194
+ this.operations.set(document._path, {
195
+ document,
196
+ action: FirestoreClient.Action.Delete,
197
+ committed: false
198
+ });
181
199
  }
182
200
  }
183
201
 
@@ -226,39 +244,50 @@ export class FirestoreClient implements ITransactionalClient {
226
244
  return result ? deserialize<T>(result) : null;
227
245
  }
228
246
 
229
- private doesDocumentMatchQuery<T extends Document>(document: T, collection: string, whereClauses: [string, FirestoreClient.Operator, any | any[]][]): boolean {
247
+ private doesDocumentMatchQuery<T extends Document>(
248
+ document: T,
249
+ collection: string,
250
+ whereClauses: [string, FirestoreClient.Operator, any | any[]][]
251
+ ): boolean {
230
252
  const serializedDocument = serialize(document);
231
253
 
232
- return document._path.startsWith(`${collection}/`) && whereClauses.every(wc => {
233
- const documentValue = serializedDocument[wc[0]];
234
- const operator = wc[1];
235
- const expectedValue = wc[2];
236
-
237
- switch (operator) {
238
- case '==':
239
- return documentValue === expectedValue;
240
- case '!=':
241
- return documentValue !== undefined && documentValue !== expectedValue;
242
- case '>':
243
- return documentValue > expectedValue;
244
- case '>=':
245
- return documentValue >= expectedValue;
246
- case '<':
247
- return documentValue < expectedValue;
248
- case '<=':
249
- return documentValue <= expectedValue;
250
- case 'array-contains':
251
- return Array.isArray(documentValue) && documentValue.includes(expectedValue);
252
- case 'array-contains-any':
253
- return Array.isArray(documentValue) && Array.isArray(expectedValue) && documentValue.some(v => expectedValue.includes(v));
254
- case 'in':
255
- return Array.isArray(expectedValue) && expectedValue.includes(documentValue);
256
- case 'not-in':
257
- return Array.isArray(expectedValue) && !expectedValue.includes(documentValue);
258
- default:
259
- throw new Error(`Operator ${operator} not handled!`);
260
- }
261
- });
254
+ return (
255
+ document._path.startsWith(`${collection}/`) &&
256
+ whereClauses.every(wc => {
257
+ const documentValue = serializedDocument[wc[0]];
258
+ const operator = wc[1];
259
+ const expectedValue = wc[2];
260
+
261
+ switch (operator) {
262
+ case '==':
263
+ return documentValue === expectedValue;
264
+ case '!=':
265
+ return documentValue !== undefined && documentValue !== expectedValue;
266
+ case '>':
267
+ return documentValue > expectedValue;
268
+ case '>=':
269
+ return documentValue >= expectedValue;
270
+ case '<':
271
+ return documentValue < expectedValue;
272
+ case '<=':
273
+ return documentValue <= expectedValue;
274
+ case 'array-contains':
275
+ return Array.isArray(documentValue) && documentValue.includes(expectedValue);
276
+ case 'array-contains-any':
277
+ return (
278
+ Array.isArray(documentValue) &&
279
+ Array.isArray(expectedValue) &&
280
+ documentValue.some(v => expectedValue.includes(v))
281
+ );
282
+ case 'in':
283
+ return Array.isArray(expectedValue) && expectedValue.includes(documentValue);
284
+ case 'not-in':
285
+ return Array.isArray(expectedValue) && !expectedValue.includes(documentValue);
286
+ default:
287
+ throw new Error(`Operator ${operator} not handled!`);
288
+ }
289
+ })
290
+ );
262
291
  }
263
292
 
264
293
  private isCreateOperation(operation: FirestoreClient.Operation): boolean {
@@ -275,7 +304,6 @@ export class FirestoreClient implements ITransactionalClient {
275
304
  }
276
305
 
277
306
  export namespace FirestoreClient {
278
-
279
307
  export interface Operation {
280
308
  document: Document;
281
309
  action: Action;
@@ -1 +0,0 @@
1
-
@@ -1 +1 @@
1
- export type Newable<T> = new () => T;
1
+ export type Newable<T> = new () => T;
@@ -1,3 +1,3 @@
1
- export interface Type<T = any> extends Function {
2
- new(...args: any[]): T;
1
+ export interface Type<T = any> {
2
+ new (...args: any[]): T;
3
3
  }
package/src/reflect.ts CHANGED
@@ -7,16 +7,16 @@ import { Type } from './interfaces';
7
7
  import { RequestMethod } from './request-method.enum';
8
8
  import { Server } from './server';
9
9
 
10
- /* eslint-disable @typescript-eslint/ban-types */
11
10
  class ReflectHelper<T extends ReflectTarget<any>> {
12
11
  private readonly HANDLER_META_DATA = '__handler__';
13
12
  private readonly CONTROLLER_META_DATA = '__controller__';
14
13
  private readonly INJECTABLE_META_DATA = '__injectable__';
15
14
  private readonly TRANSACTIONAL_CLIENT_META_DATA = '__transactional_client__';
16
15
 
17
- constructor(private target: T, private methodName: string | symbol) {
18
-
19
- }
16
+ constructor(
17
+ private target: T,
18
+ private methodName: string | symbol
19
+ ) {}
20
20
 
21
21
  public getParameters(): Type[] {
22
22
  return Reflect.getMetadata('design:paramtypes', this.target, this.methodName) || [];
@@ -27,7 +27,7 @@ class ReflectHelper<T extends ReflectTarget<any>> {
27
27
  }
28
28
 
29
29
  public getInjectableId(): string {
30
- return this.getMetaData<string>(this.INJECTABLE_META_DATA)
30
+ return this.getMetaData<string>(this.INJECTABLE_META_DATA);
31
31
  }
32
32
 
33
33
  public registerTransactionalClient(): void {
@@ -35,7 +35,7 @@ class ReflectHelper<T extends ReflectTarget<any>> {
35
35
  }
36
36
 
37
37
  public isTransactionalClient(): boolean {
38
- return this.hasMetaData(this.TRANSACTIONAL_CLIENT_META_DATA)
38
+ return this.hasMetaData(this.TRANSACTIONAL_CLIENT_META_DATA);
39
39
  }
40
40
 
41
41
  public getControllerConfiguration(): ControllerConfiguration {
@@ -53,7 +53,7 @@ class ReflectHelper<T extends ReflectTarget<any>> {
53
53
  this.getControllerConfiguration().basePath = basePath;
54
54
  }
55
55
 
56
- public registerControllerRoute(route: { path: string, requestMethod: RequestMethod }): void {
56
+ public registerControllerRoute(route: { path: string; requestMethod: RequestMethod }): void {
57
57
  this.getControllerRoute().path = route.path;
58
58
  this.getControllerRoute().requestMethod = route.requestMethod;
59
59
  }
@@ -3,7 +3,6 @@ import { Controller, Get, Post } from '../decorators';
3
3
 
4
4
  @Controller('sanity-check')
5
5
  export class SanityCheckController {
6
-
7
6
  @Post('warm-up')
8
7
  public async postWarmUp(): Promise<string> {
9
8
  return 'Warm Up succeeded! :-)';
@@ -3,10 +3,6 @@ import { Module } from '../decorators';
3
3
  import { SanityCheckController } from './controller';
4
4
 
5
5
  @Module({
6
- controllers: [
7
- SanityCheckController,
8
- ],
6
+ controllers: [SanityCheckController]
9
7
  })
10
- export class SanityCheckModule {
11
-
12
- }
8
+ export class SanityCheckModule {}
@@ -4,7 +4,6 @@ import { Auth } from 'firebase-admin/auth';
4
4
  import { Context } from '../../context';
5
5
  import { Server } from '../server';
6
6
 
7
-
8
7
  export function AuthenticationMiddleware(auth: Auth, publicPaths: string[]): Server.RequestHandler {
9
8
  return async (request: Server.Request, _response: Server.Response, next: Server.NextFunction): Promise<void> => {
10
9
  const authorizationHeader = request.headers.authorization ? request.headers.authorization.toString() : null;
@@ -56,7 +56,6 @@ export class Server {
56
56
  }
57
57
 
58
58
  export namespace Server {
59
-
60
59
  export interface Options {
61
60
  bus: Bus;
62
61
  firebaseAuth: auth.Auth;
package/src/zip-helper.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as zlib from 'zlib';
1
+ import * as zlib from 'node:zlib';
2
2
 
3
3
  export class ZipHelper {
4
4
  public static zip(content: string): string {
package/tsconfig.json CHANGED
@@ -11,8 +11,5 @@
11
11
  "emitDecoratorMetadata": true,
12
12
  "experimentalDecorators": true
13
13
  },
14
- "types": [
15
- "reflect-metadata",
16
- "mocha"
17
- ],
14
+ "types": ["reflect-metadata", "mocha"]
18
15
  }