@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.
- package/.eslintrc.js +2 -4
- package/dist/app-factory.js +2 -2
- package/dist/app-factory.js.map +1 -1
- package/dist/context.js +18 -18
- package/dist/context.js.map +1 -1
- package/dist/decorators/controller/body.js.map +1 -1
- package/dist/decorators/controller/body.spec.js +1 -1
- package/dist/decorators/controller/body.spec.js.map +1 -1
- package/dist/decorators/controller/controller.spec.js.map +1 -1
- package/dist/decorators/controller/get.js +4 -1
- package/dist/decorators/controller/get.js.map +1 -1
- package/dist/decorators/controller/get.spec.js.map +1 -1
- package/dist/decorators/controller/param.js.map +1 -1
- package/dist/decorators/controller/param.spec.js +1 -1
- package/dist/decorators/controller/param.spec.js.map +1 -1
- package/dist/decorators/controller/post.js +4 -1
- package/dist/decorators/controller/post.js.map +1 -1
- package/dist/decorators/controller/post.spec.js.map +1 -1
- package/dist/decorators/controller/query.js.map +1 -1
- package/dist/decorators/controller/query.spec.js +1 -1
- package/dist/decorators/controller/query.spec.js.map +1 -1
- package/dist/decorators/handler/command-handler.js.map +1 -1
- package/dist/decorators/handler/command-handler.spec.js.map +1 -1
- package/dist/decorators/handler/event-handler.js.map +1 -1
- package/dist/decorators/handler/event-handler.spec.js.map +1 -1
- package/dist/firestore-client.js +47 -32
- package/dist/firestore-client.js.map +1 -1
- package/dist/interfaces/type.d.ts +1 -1
- package/dist/reflect.js +0 -1
- package/dist/reflect.js.map +1 -1
- package/dist/sanity-check/controller.js.map +1 -1
- package/dist/sanity-check/module.js +1 -3
- package/dist/sanity-check/module.js.map +1 -1
- package/dist/server/middlewares/authentication-middleware.js.map +1 -1
- package/dist/server/server.js.map +1 -1
- package/dist/zip-helper.js +1 -1
- package/dist/zip-helper.js.map +1 -1
- package/package.json +4 -4
- package/src/app-factory.ts +65 -48
- package/src/context.ts +2 -2
- package/src/decorators/controller/body.spec.ts +3 -3
- package/src/decorators/controller/body.ts +1 -1
- package/src/decorators/controller/controller.spec.ts +1 -3
- package/src/decorators/controller/get.spec.ts +0 -1
- package/src/decorators/controller/get.ts +5 -2
- package/src/decorators/controller/param.spec.ts +3 -2
- package/src/decorators/controller/param.ts +1 -1
- package/src/decorators/controller/post.spec.ts +0 -2
- package/src/decorators/controller/post.ts +5 -2
- package/src/decorators/controller/query.spec.ts +3 -2
- package/src/decorators/controller/query.ts +1 -1
- package/src/decorators/handler/command-handler.spec.ts +2 -11
- package/src/decorators/handler/command-handler.ts +1 -1
- package/src/decorators/handler/event-handler.spec.ts +2 -11
- package/src/decorators/handler/event-handler.ts +1 -1
- package/src/firestore-client.ts +67 -39
- package/src/interfaces/app-config.ts +0 -1
- package/src/interfaces/newable.ts +1 -1
- package/src/interfaces/type.ts +2 -2
- package/src/reflect.ts +7 -7
- package/src/sanity-check/controller.ts +0 -1
- package/src/sanity-check/module.ts +2 -6
- package/src/server/middlewares/authentication-middleware.ts +0 -1
- package/src/server/server.ts +0 -1
- package/src/zip-helper.ts +1 -1
- package/tsconfig.json +1 -4
package/src/firestore-client.ts
CHANGED
|
@@ -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>(
|
|
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>(
|
|
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, {
|
|
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, {
|
|
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, {
|
|
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>(
|
|
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
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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;
|
package/src/interfaces/type.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface Type<T = any>
|
|
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(
|
|
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
|
|
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,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;
|
package/src/server/server.ts
CHANGED
package/src/zip-helper.ts
CHANGED