@my-devkit/firebase 1.0.76 → 1.0.80
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/{dist/aggregate.d.ts → aggregate.d.ts} +0 -0
- package/{dist/aggregate.js → aggregate.js} +0 -0
- package/{dist/aggregate.js.map → aggregate.js.map} +0 -0
- package/{dist/app-factory.d.ts → app-factory.d.ts} +0 -0
- package/{dist/app-factory.js → app-factory.js} +0 -0
- package/{dist/app-factory.js.map → app-factory.js.map} +0 -0
- package/{dist/bus.d.ts → bus.d.ts} +0 -0
- package/{dist/bus.js → bus.js} +0 -0
- package/{dist/bus.js.map → bus.js.map} +0 -0
- package/{dist/constants.d.ts → constants.d.ts} +0 -0
- package/{dist/constants.js → constants.js} +0 -0
- package/{dist/constants.js.map → constants.js.map} +0 -0
- package/{dist/context.d.ts → context.d.ts} +0 -0
- package/{dist/context.js → context.js} +0 -0
- package/{dist/context.js.map → context.js.map} +0 -0
- package/{dist/decorators → decorators}/controller/body.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/body.js +0 -0
- package/{dist/decorators → decorators}/controller/body.js.map +0 -0
- package/{dist/decorators → decorators}/controller/body.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/body.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/body.spec.js.map +0 -0
- package/{dist/decorators → decorators}/controller/controller.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/controller.js +0 -0
- package/{dist/decorators → decorators}/controller/controller.js.map +0 -0
- package/{dist/decorators → decorators}/controller/controller.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/controller.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/controller.spec.js.map +0 -0
- package/{dist/decorators → decorators}/controller/get.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/get.js +0 -0
- package/{dist/decorators → decorators}/controller/get.js.map +0 -0
- package/{dist/decorators → decorators}/controller/get.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/get.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/get.spec.js.map +0 -0
- package/{dist/decorators → decorators}/controller/index.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/index.js +0 -0
- package/{dist/decorators → decorators}/controller/index.js.map +0 -0
- package/{dist/decorators → decorators}/controller/param.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/param.js +0 -0
- package/{dist/decorators → decorators}/controller/param.js.map +0 -0
- package/{dist/decorators → decorators}/controller/param.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/param.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/param.spec.js.map +0 -0
- package/{dist/decorators → decorators}/controller/post.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/post.js +0 -0
- package/{dist/decorators → decorators}/controller/post.js.map +0 -0
- package/{dist/decorators → decorators}/controller/post.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/post.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/post.spec.js.map +0 -0
- package/{dist/decorators → decorators}/controller/query.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/query.js +0 -0
- package/{dist/decorators → decorators}/controller/query.js.map +0 -0
- package/{dist/decorators → decorators}/controller/query.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/controller/query.spec.js +0 -0
- package/{dist/decorators → decorators}/controller/query.spec.js.map +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.d.ts +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.js +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.js.map +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.spec.js +0 -0
- package/{dist/decorators → decorators}/handler/command-handler.spec.js.map +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.d.ts +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.js +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.js.map +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.spec.d.ts +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.spec.js +0 -0
- package/{dist/decorators → decorators}/handler/event-handler.spec.js.map +0 -0
- package/{dist/decorators → decorators}/handler/index.d.ts +0 -0
- package/{dist/decorators → decorators}/handler/index.js +0 -0
- package/{dist/decorators → decorators}/handler/index.js.map +0 -0
- package/{dist/decorators → decorators}/index.d.ts +0 -0
- package/{dist/decorators → decorators}/index.js +0 -0
- package/{dist/decorators → decorators}/index.js.map +0 -0
- package/{dist/decorators → decorators}/injectable.d.ts +0 -0
- package/{dist/decorators → decorators}/injectable.js +0 -0
- package/{dist/decorators → decorators}/injectable.js.map +0 -0
- package/{dist/decorators → decorators}/module.d.ts +0 -0
- package/{dist/decorators → decorators}/module.js +0 -0
- package/{dist/decorators → decorators}/module.js.map +0 -0
- package/{dist/decorators → decorators}/transactional-client.d.ts +0 -0
- package/{dist/decorators → decorators}/transactional-client.js +0 -0
- package/{dist/decorators → decorators}/transactional-client.js.map +0 -0
- package/{dist/execution-mode-enum.d.ts → execution-mode-enum.d.ts} +0 -0
- package/{dist/execution-mode-enum.js → execution-mode-enum.js} +0 -0
- package/{dist/execution-mode-enum.js.map → execution-mode-enum.js.map} +0 -0
- package/{dist/firestore-client.d.ts → firestore-client.d.ts} +0 -0
- package/{dist/firestore-client.js → firestore-client.js} +0 -0
- package/{dist/firestore-client.js.map → firestore-client.js.map} +0 -0
- package/{dist/handler-helper.d.ts → handler-helper.d.ts} +0 -0
- package/{dist/handler-helper.js → handler-helper.js} +0 -0
- package/{dist/handler-helper.js.map → handler-helper.js.map} +0 -0
- package/{dist/index.d.ts → index.d.ts} +0 -0
- package/{dist/index.js → index.js} +0 -0
- package/{dist/index.js.map → index.js.map} +0 -0
- package/{dist/injector.d.ts → injector.d.ts} +0 -0
- package/{dist/injector.js → injector.js} +0 -0
- package/{dist/injector.js.map → injector.js.map} +0 -0
- package/{dist/interfaces → interfaces}/app-config.d.ts +0 -0
- package/{dist/interfaces → interfaces}/app-config.js +0 -0
- package/{dist/interfaces → interfaces}/app-config.js.map +0 -0
- package/{dist/interfaces → interfaces}/from-array.d.ts +0 -0
- package/{dist/interfaces → interfaces}/from-array.js +0 -0
- package/{dist/interfaces → interfaces}/from-array.js.map +0 -0
- package/{dist/interfaces → interfaces}/index.d.ts +0 -0
- package/{dist/interfaces → interfaces}/index.js +0 -0
- package/{dist/interfaces → interfaces}/index.js.map +0 -0
- package/{dist/interfaces → interfaces}/newable.d.ts +0 -0
- package/{dist/interfaces → interfaces}/newable.js +0 -0
- package/{dist/interfaces → interfaces}/newable.js.map +0 -0
- package/{dist/interfaces → interfaces}/transactional-client.d.ts +0 -0
- package/{dist/interfaces → interfaces}/transactional-client.js +0 -0
- package/{dist/interfaces → interfaces}/transactional-client.js.map +0 -0
- package/{dist/interfaces → interfaces}/type.d.ts +0 -0
- package/{dist/interfaces → interfaces}/type.js +0 -0
- package/{dist/interfaces → interfaces}/type.js.map +0 -0
- package/package.json +6 -6
- package/{dist/reflect.d.ts → reflect.d.ts} +0 -0
- package/{dist/reflect.js → reflect.js} +0 -0
- package/{dist/reflect.js.map → reflect.js.map} +0 -0
- package/{dist/request-method.enum.d.ts → request-method.enum.d.ts} +0 -0
- package/{dist/request-method.enum.js → request-method.enum.js} +0 -0
- package/{dist/request-method.enum.js.map → request-method.enum.js.map} +0 -0
- package/{dist/server → server}/index.d.ts +0 -0
- package/{dist/server → server}/index.js +0 -0
- package/{dist/server → server}/index.js.map +0 -0
- package/{dist/server → server}/middlewares/authentication-middleware.d.ts +0 -0
- package/{dist/server → server}/middlewares/authentication-middleware.js +0 -0
- package/{dist/server → server}/middlewares/authentication-middleware.js.map +0 -0
- package/{dist/server → server}/middlewares/create-context-middleware.d.ts +0 -0
- package/{dist/server → server}/middlewares/create-context-middleware.js +0 -0
- package/{dist/server → server}/middlewares/create-context-middleware.js.map +0 -0
- package/{dist/server → server}/middlewares/error-middleware.d.ts +0 -0
- package/{dist/server → server}/middlewares/error-middleware.js +0 -0
- package/{dist/server → server}/middlewares/error-middleware.js.map +0 -0
- package/{dist/server → server}/middlewares/headers-middleware.d.ts +0 -0
- package/{dist/server → server}/middlewares/headers-middleware.js +0 -0
- package/{dist/server → server}/middlewares/headers-middleware.js.map +0 -0
- package/{dist/server → server}/middlewares/index.d.ts +0 -0
- package/{dist/server → server}/middlewares/index.js +0 -0
- package/{dist/server → server}/middlewares/index.js.map +0 -0
- package/{dist/server → server}/middlewares/not-found-middleware.d.ts +0 -0
- package/{dist/server → server}/middlewares/not-found-middleware.js +0 -0
- package/{dist/server → server}/middlewares/not-found-middleware.js.map +0 -0
- package/{dist/server → server}/server.d.ts +0 -0
- package/{dist/server → server}/server.js +0 -0
- package/{dist/server → server}/server.js.map +0 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/.eslintrc.js +0 -15
- package/.vscode/settings.json +0 -7
- package/dist/package.json +0 -54
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/my-devkit-firebase-1.0.76.tgz +0 -0
- package/src/aggregate.ts +0 -54
- package/src/app-factory.ts +0 -252
- package/src/bus.ts +0 -70
- package/src/constants.ts +0 -5
- package/src/context.ts +0 -108
- package/src/decorators/controller/body.spec.ts +0 -52
- package/src/decorators/controller/body.ts +0 -17
- package/src/decorators/controller/controller.spec.ts +0 -19
- package/src/decorators/controller/controller.ts +0 -10
- package/src/decorators/controller/get.spec.ts +0 -32
- package/src/decorators/controller/get.ts +0 -8
- package/src/decorators/controller/index.ts +0 -8
- package/src/decorators/controller/param.spec.ts +0 -51
- package/src/decorators/controller/param.ts +0 -21
- package/src/decorators/controller/post.spec.ts +0 -60
- package/src/decorators/controller/post.ts +0 -8
- package/src/decorators/controller/query.spec.ts +0 -51
- package/src/decorators/controller/query.ts +0 -21
- package/src/decorators/handler/command-handler.spec.ts +0 -101
- package/src/decorators/handler/command-handler.ts +0 -21
- package/src/decorators/handler/event-handler.spec.ts +0 -104
- package/src/decorators/handler/event-handler.ts +0 -22
- package/src/decorators/handler/index.ts +0 -2
- package/src/decorators/index.ts +0 -5
- package/src/decorators/injectable.ts +0 -7
- package/src/decorators/module.ts +0 -29
- package/src/decorators/transactional-client.ts +0 -7
- package/src/execution-mode-enum.ts +0 -4
- package/src/firestore-client.ts +0 -125
- package/src/handler-helper.ts +0 -68
- package/src/index.ts +0 -7
- package/src/injector.ts +0 -31
- package/src/interfaces/app-config.ts +0 -1
- package/src/interfaces/from-array.ts +0 -1
- package/src/interfaces/index.ts +0 -4
- package/src/interfaces/newable.ts +0 -1
- package/src/interfaces/transactional-client.ts +0 -3
- package/src/interfaces/type.ts +0 -3
- package/src/reflect.ts +0 -164
- package/src/request-method.enum.ts +0 -4
- package/src/server/index.ts +0 -1
- package/src/server/middlewares/authentication-middleware.ts +0 -47
- package/src/server/middlewares/create-context-middleware.ts +0 -16
- package/src/server/middlewares/error-middleware.ts +0 -33
- package/src/server/middlewares/headers-middleware.ts +0 -16
- package/src/server/middlewares/index.ts +0 -5
- package/src/server/middlewares/not-found-middleware.ts +0 -9
- package/src/server/server.ts +0 -96
- package/tsconfig.json +0 -24
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { reflect } from '../../reflect';
|
|
4
|
-
import { Controller } from './controller';
|
|
5
|
-
import { Get } from './get';
|
|
6
|
-
import { Param } from './param';
|
|
7
|
-
|
|
8
|
-
describe('Given a Param decorator', () => {
|
|
9
|
-
|
|
10
|
-
enum Gender {
|
|
11
|
-
Male = 0,
|
|
12
|
-
Female = 'Female'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@Controller('test')
|
|
16
|
-
class TestClass {
|
|
17
|
-
@Get(':id')
|
|
18
|
-
public getById(@Param('id') id: string): string {
|
|
19
|
-
return `getById: ${id}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Get(':gender/:minDate')
|
|
23
|
-
public getByGenderOlderThan(@Param('minDate') minDate: Date, @Param('gender') gender: Gender): string {
|
|
24
|
-
return `getByGenderOlderThan: ${gender} ${minDate.toISOString()}`;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('When decorator is called', () => {
|
|
29
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
30
|
-
const config = reflect(TestClass).getControllerConfiguration();
|
|
31
|
-
expect(config.routes.length).equal(2, 'Wrong route count detected');
|
|
32
|
-
|
|
33
|
-
const request1 = <any>{ params: { id: 'guid 1' } };
|
|
34
|
-
expect(config.routes[0].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length for getById');
|
|
35
|
-
expect(config.routes[0].argumentInjectors[0](request1)).to.be.a('string');
|
|
36
|
-
expect(config.routes[0].argumentInjectors[0](request1)).equals('guid 1');
|
|
37
|
-
|
|
38
|
-
const request2 = <any>{ params: { gender: 0, minDate: '2021-02-15T14:23:00.318Z' } };
|
|
39
|
-
|
|
40
|
-
expect(config.routes[1].argumentInjectors.length).equal(2, 'Wrong argumentInjectors length for getByGenderOlderThan');
|
|
41
|
-
|
|
42
|
-
expect(config.routes[1].argumentInjectors[0](request2)).to.be.a('Date');
|
|
43
|
-
expect(config.routes[1].argumentInjectors[0](request2).toISOString()).equals((new Date('2021-02-15T14:23:00.318Z')).toISOString());
|
|
44
|
-
|
|
45
|
-
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Male);
|
|
46
|
-
|
|
47
|
-
request2.params.gender = 'Female';
|
|
48
|
-
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Female);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { deserialize } from '@my-devkit/core';
|
|
2
|
-
|
|
3
|
-
import { reflect, RequestArgumentInjector } from '../../reflect';
|
|
4
|
-
import { Server } from '../../server';
|
|
5
|
-
|
|
6
|
-
export function Param(key: string): ParameterDecorator {
|
|
7
|
-
return (target, propertyKey, parameterIndex) => {
|
|
8
|
-
const methodArguments = reflect(target, propertyKey).getParameters();
|
|
9
|
-
if (!methodArguments.hasOwnProperty(parameterIndex)) {
|
|
10
|
-
throw new Error(`Param: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const injector: RequestArgumentInjector = (req: Server.Request) => {
|
|
14
|
-
if (req.params.hasOwnProperty(key)) {
|
|
15
|
-
return deserialize(req.params[key], methodArguments[parameterIndex]);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
reflect(target, propertyKey).registerControllerRouteArgumentInjector(injector, parameterIndex);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { autoserializeAs, guid } from '@my-devkit/core';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import { reflect } from '../../reflect';
|
|
5
|
-
import { RequestMethod } from '../../request-method.enum';
|
|
6
|
-
import { Body } from './body';
|
|
7
|
-
import { Controller } from './controller';
|
|
8
|
-
import { Post } from './post';
|
|
9
|
-
|
|
10
|
-
describe('Given a Post decorator', () => {
|
|
11
|
-
|
|
12
|
-
class Command {
|
|
13
|
-
@autoserializeAs(String)
|
|
14
|
-
public testString: string = null;
|
|
15
|
-
|
|
16
|
-
@autoserializeAs(Date)
|
|
17
|
-
public testDate: Date = null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@Controller('test')
|
|
22
|
-
class TestClass {
|
|
23
|
-
public test = guid();
|
|
24
|
-
|
|
25
|
-
@Post('create')
|
|
26
|
-
public createMethod(@Body() param1: Date): string {
|
|
27
|
-
return `createMethod: ${param1}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Post('update')
|
|
31
|
-
public updateMethod(@Body() param1: Command): string {
|
|
32
|
-
return `updateMethod: ${param1}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Post('delete')
|
|
36
|
-
public deleteMethod(@Body() param1: Command): string {
|
|
37
|
-
return `deleteMethod: ${param1}`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
describe('When decorator is called', () => {
|
|
42
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
43
|
-
const config = reflect(TestClass).getControllerConfiguration();
|
|
44
|
-
|
|
45
|
-
expect(config.routes.length).equal(3, 'Wrong route count detected');
|
|
46
|
-
|
|
47
|
-
expect(config.routes[0].path).equal('create');
|
|
48
|
-
expect(config.routes[0].methodName).equal('createMethod');
|
|
49
|
-
expect(config.routes[0].requestMethod).equal(RequestMethod.POST);
|
|
50
|
-
|
|
51
|
-
expect(config.routes[1].path).equal('update');
|
|
52
|
-
expect(config.routes[1].methodName).equal('updateMethod');
|
|
53
|
-
expect(config.routes[1].requestMethod).equal(RequestMethod.POST);
|
|
54
|
-
|
|
55
|
-
expect(config.routes[2].path).equal('delete');
|
|
56
|
-
expect(config.routes[2].methodName).equal('deleteMethod');
|
|
57
|
-
expect(config.routes[2].requestMethod).equal(RequestMethod.POST);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { reflect } from '../../reflect';
|
|
2
|
-
import { RequestMethod } from '../../request-method.enum';
|
|
3
|
-
|
|
4
|
-
export function Post(path: string): MethodDecorator {
|
|
5
|
-
return (target, propertyKey) => {
|
|
6
|
-
reflect(target.constructor, propertyKey).registerControllerRoute({ path, requestMethod: RequestMethod.POST });
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import { reflect } from '../../reflect';
|
|
4
|
-
import { Controller } from './controller';
|
|
5
|
-
import { Get } from './get';
|
|
6
|
-
import { Query } from './query';
|
|
7
|
-
|
|
8
|
-
describe('Given a Query decorator', () => {
|
|
9
|
-
|
|
10
|
-
enum Gender {
|
|
11
|
-
Male = 0,
|
|
12
|
-
Female = 'Female'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@Controller('test')
|
|
16
|
-
class TestClass {
|
|
17
|
-
@Get('by-id')
|
|
18
|
-
public getById(@Query('id') id: string): string {
|
|
19
|
-
return `getById: ${id}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Get('all')
|
|
23
|
-
public all(@Query('minDate') minDate: Date, @Query('gender') gender: Gender): string {
|
|
24
|
-
return `getByGenderOlderThan: ${gender} ${minDate.toISOString()}`;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('When decorator is called', () => {
|
|
29
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
30
|
-
const config = reflect(TestClass).getControllerConfiguration();
|
|
31
|
-
expect(config.routes.length).equal(2, 'Wrong route count detected');
|
|
32
|
-
|
|
33
|
-
const request1 = <any>{ query: { id: 'guid 1' } };
|
|
34
|
-
expect(config.routes[0].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length for getById');
|
|
35
|
-
expect(config.routes[0].argumentInjectors[0](request1)).to.be.a('string');
|
|
36
|
-
expect(config.routes[0].argumentInjectors[0](request1)).equals('guid 1');
|
|
37
|
-
|
|
38
|
-
const request2 = <any>{ query: { gender: 0, minDate: '2021-02-15T14:23:00.318Z' } };
|
|
39
|
-
|
|
40
|
-
expect(config.routes[1].argumentInjectors.length).equal(2, 'Wrong argumentInjectors length for getByGenderOlderThan');
|
|
41
|
-
|
|
42
|
-
expect(config.routes[1].argumentInjectors[0](request2)).to.be.a('Date');
|
|
43
|
-
expect(config.routes[1].argumentInjectors[0](request2).toISOString()).equals((new Date('2021-02-15T14:23:00.318Z')).toISOString());
|
|
44
|
-
|
|
45
|
-
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Male);
|
|
46
|
-
|
|
47
|
-
request2.query.gender = 'Female';
|
|
48
|
-
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Female);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { deserialize } from '@my-devkit/core';
|
|
2
|
-
|
|
3
|
-
import { reflect, RequestArgumentInjector } from '../../reflect';
|
|
4
|
-
import { Server } from '../../server';
|
|
5
|
-
|
|
6
|
-
export function Query(key: string): ParameterDecorator {
|
|
7
|
-
return (target, propertyKey, parameterIndex) => {
|
|
8
|
-
const methodArguments = reflect(target, propertyKey).getParameters();
|
|
9
|
-
if (!methodArguments.hasOwnProperty(parameterIndex)) {
|
|
10
|
-
throw new Error(`Query: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const injector: RequestArgumentInjector = (req: Server.Request) => {
|
|
14
|
-
if (req.query.hasOwnProperty(key)) {
|
|
15
|
-
return deserialize(req.query[key], methodArguments[parameterIndex]);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
reflect(target, propertyKey).registerControllerRouteArgumentInjector(injector, parameterIndex);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Command } from '@my-devkit/core';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import { reflect } from '../../reflect';
|
|
5
|
-
import { CommandHandler } from './command-handler';
|
|
6
|
-
|
|
7
|
-
describe('Given a CommandHandler decorator', () => {
|
|
8
|
-
|
|
9
|
-
describe('When decorator is called', () => {
|
|
10
|
-
|
|
11
|
-
describe('And decorated method has no parameter', () => {
|
|
12
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
class TestClass {
|
|
16
|
-
@CommandHandler()
|
|
17
|
-
public create(): string {
|
|
18
|
-
return `create`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
23
|
-
} catch (error) {
|
|
24
|
-
expect(error.message).equal('TestClass.create should have one argument!');
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('And decorated method has more than 1 parameter', () => {
|
|
30
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
class TestClass {
|
|
34
|
-
@CommandHandler()
|
|
35
|
-
public create(param1: string, param2: string): string {
|
|
36
|
-
return `create ${param1} / ${param2}`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
41
|
-
} catch (error) {
|
|
42
|
-
expect(error.message).equal('TestClass.create should have only one argument!');
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('And decorated method parameter is not a command', () => {
|
|
48
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
class FakeCommand {
|
|
52
|
-
test: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class TestClass {
|
|
56
|
-
@CommandHandler()
|
|
57
|
-
public create(fakeCommand: FakeCommand): string {
|
|
58
|
-
return `create ${fakeCommand}`;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
63
|
-
} catch (error) {
|
|
64
|
-
expect(error.message).equal('TestClass.create should have a command as argument!');
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('And handler is correctly implemented', () => {
|
|
70
|
-
|
|
71
|
-
class CreateCommand extends Command {
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class UpdateCommand extends Command {
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
class TestClass {
|
|
78
|
-
@CommandHandler()
|
|
79
|
-
public create(command: CreateCommand): string {
|
|
80
|
-
return `create: ${command}`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@CommandHandler()
|
|
84
|
-
public update(command: UpdateCommand): string {
|
|
85
|
-
return `update: ${command}`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
89
|
-
const config = reflect(TestClass).getHandlerConfiguration();
|
|
90
|
-
expect(config.commandHandlers.size).equal(2, 'Wrong route count detected');
|
|
91
|
-
|
|
92
|
-
expect(config.commandHandlers[0].methodName).equal('create');
|
|
93
|
-
expect(config.commandHandlers[0].command.constructor.name).equal('CreateCommand');
|
|
94
|
-
|
|
95
|
-
expect(config.commandHandlers[1].methodName).equal('update');
|
|
96
|
-
expect(config.commandHandlers[1].command.constructor.name).equal('UpdateCommand');
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { reflect } from '../../reflect';
|
|
2
|
-
|
|
3
|
-
export function CommandHandler(): MethodDecorator {
|
|
4
|
-
return (target, propertyKey) => {
|
|
5
|
-
const paramTypes = reflect(target, propertyKey).getParameters();
|
|
6
|
-
|
|
7
|
-
if (paramTypes.length === 0) {
|
|
8
|
-
throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have one argument!`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (paramTypes.length > 1) {
|
|
12
|
-
throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have only one argument!`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// if (!(paramTypes[0].prototype instanceof Command)) {
|
|
16
|
-
// throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have a command as argument!`);
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
reflect(target, propertyKey).registerCommandHandler(<any>paramTypes[0].prototype);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Event } from '@my-devkit/core';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
import { ExecutionMode } from '../../execution-mode-enum';
|
|
5
|
-
import { reflect } from '../../reflect';
|
|
6
|
-
import { EventHandler } from './event-handler';
|
|
7
|
-
|
|
8
|
-
describe('Given a EventHandler decorator', () => {
|
|
9
|
-
|
|
10
|
-
describe('When decorator is called', () => {
|
|
11
|
-
|
|
12
|
-
describe('And decorated method has no parameter', () => {
|
|
13
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
class TestClass {
|
|
17
|
-
@EventHandler(ExecutionMode.Asynchronous)
|
|
18
|
-
public created(): string {
|
|
19
|
-
return `created`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
24
|
-
} catch (error) {
|
|
25
|
-
expect(error.message).equal('TestClass.created should have one argument!');
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('And decorated method has more than 1 parameter', () => {
|
|
31
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
class TestClass {
|
|
35
|
-
@EventHandler(ExecutionMode.Asynchronous)
|
|
36
|
-
public created(param1: string, param2: string): string {
|
|
37
|
-
return `created ${param1} / ${param2}`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
42
|
-
} catch (error) {
|
|
43
|
-
expect(error.message).equal('TestClass.created should have only one argument!');
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('And decorated method parameter is not a command', () => {
|
|
49
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
class FakeEvent {
|
|
53
|
-
test: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class TestClass {
|
|
57
|
-
@EventHandler(ExecutionMode.Asynchronous)
|
|
58
|
-
public created(fakeEvent: FakeEvent): string {
|
|
59
|
-
return `created ${fakeEvent}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
reflect(TestClass).getHandlerConfiguration();
|
|
64
|
-
} catch (error) {
|
|
65
|
-
expect(error.message).equal('TestClass.created should have an event as argument!');
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('And handler is correctly implemented', () => {
|
|
71
|
-
|
|
72
|
-
class CreatedEvent extends Event {
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
class UpdatedEvent extends Event {
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
class TestClass {
|
|
79
|
-
@EventHandler(ExecutionMode.Asynchronous)
|
|
80
|
-
public created(event: CreatedEvent): string {
|
|
81
|
-
return `created: ${event}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@EventHandler(ExecutionMode.Synchronous)
|
|
85
|
-
public updated(event: UpdatedEvent): string {
|
|
86
|
-
return `updated: ${event}`;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
it('Then we should retrieve information via reflect', async () => {
|
|
90
|
-
const config = reflect(TestClass).getHandlerConfiguration();
|
|
91
|
-
expect(config.eventHandlers.size).equal(2, 'Wrong route count detected');
|
|
92
|
-
|
|
93
|
-
expect(config.eventHandlers[0].methodName).equal('created');
|
|
94
|
-
expect(config.eventHandlers[0].executionMode).equal(ExecutionMode.Asynchronous);
|
|
95
|
-
expect(config.eventHandlers[0].event.constructor.name).equal('CreatedEvent');
|
|
96
|
-
|
|
97
|
-
expect(config.eventHandlers[1].methodName).equal('updated');
|
|
98
|
-
expect(config.eventHandlers[1].executionMode).equal(ExecutionMode.Synchronous);
|
|
99
|
-
expect(config.eventHandlers[1].event.constructor.name).equal('UpdatedEvent');
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExecutionMode } from '../../execution-mode-enum';
|
|
2
|
-
import { reflect } from '../../reflect';
|
|
3
|
-
|
|
4
|
-
export function EventHandler(mode: ExecutionMode): MethodDecorator {
|
|
5
|
-
return (target, propertyKey) => {
|
|
6
|
-
const paramTypes = reflect(target, propertyKey).getParameters();
|
|
7
|
-
|
|
8
|
-
if (paramTypes.length === 0) {
|
|
9
|
-
throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have one argument!`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (paramTypes.length > 1) {
|
|
13
|
-
throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have only one argument!`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// if (!(paramTypes[0].prototype instanceof Event)) {
|
|
17
|
-
// throw new Error(`${target.constructor.name}.${propertyKey.toString()} should have an event as argument!`);
|
|
18
|
-
// }
|
|
19
|
-
|
|
20
|
-
reflect(target, propertyKey).registerEventHandler(<any>paramTypes[0].prototype, mode);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/decorators/index.ts
DELETED
package/src/decorators/module.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Type } from '../interfaces';
|
|
2
|
-
|
|
3
|
-
export interface ModuleOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Optional list of imported modules that export the providers which are
|
|
6
|
-
* required in this module.
|
|
7
|
-
*/
|
|
8
|
-
imports?: Type[];
|
|
9
|
-
/**
|
|
10
|
-
* Optional list of controllers defined in this module which have to be
|
|
11
|
-
* instantiated.
|
|
12
|
-
*/
|
|
13
|
-
controllers?: Type[];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Optional list of handlers defined in this module which have to be instantiated.
|
|
17
|
-
*/
|
|
18
|
-
handlers?: Type[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function Module(options: ModuleOptions): ClassDecorator {
|
|
22
|
-
return target => {
|
|
23
|
-
for (const key in options) {
|
|
24
|
-
if (options.hasOwnProperty(key)) {
|
|
25
|
-
Reflect.defineMetadata(key, options[key], target);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
package/src/firestore-client.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { deserialize, Document, Logger, NotFoundError, serialize } from '@my-devkit/core';
|
|
2
|
-
import { getFirestore } from 'firebase-admin/firestore';
|
|
3
|
-
|
|
4
|
-
import { Injectable, TransactionalClient } from './decorators';
|
|
5
|
-
import { ITransactionalClient } from './interfaces';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@TransactionalClient()
|
|
9
|
-
@Injectable()
|
|
10
|
-
export class FirestoreClient implements ITransactionalClient {
|
|
11
|
-
private db = getFirestore();
|
|
12
|
-
private operations: FirestoreClient.Operation[] = [];
|
|
13
|
-
private cachedDocuments = new Map<string, Document>();
|
|
14
|
-
|
|
15
|
-
public async save(): Promise<void> {
|
|
16
|
-
Logger.info(`Saving ${this.operations.length} operations`);
|
|
17
|
-
|
|
18
|
-
for (const operation of this.operations) {
|
|
19
|
-
if (operation.action === FirestoreClient.Action.Create) {
|
|
20
|
-
Logger.info(`Create document ${operation.document._path}`);
|
|
21
|
-
await this.db.doc(operation.document._path).set(serialize(operation.document));
|
|
22
|
-
} else if (operation.action === FirestoreClient.Action.Update) {
|
|
23
|
-
Logger.info(`Update document ${operation.document._path}`);
|
|
24
|
-
await this.db.doc(operation.document._path).set(serialize(operation.document));
|
|
25
|
-
} else if (operation.action === FirestoreClient.Action.Delete) {
|
|
26
|
-
Logger.info(`Delete document ${operation.document._path}`);
|
|
27
|
-
await this.db.doc(operation.document._path).delete();
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error(`Transactional Repository: Not supported action ${operation.action}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public async _find<T>(path: string): Promise<T> {
|
|
35
|
-
Logger.info(`Repository: find ${path}`);
|
|
36
|
-
if (this.cachedDocuments.has(path)) {
|
|
37
|
-
Logger.info(`Repository: document returned from transaction`);
|
|
38
|
-
return <any>this.cachedDocuments.get(path);
|
|
39
|
-
}
|
|
40
|
-
const doc = await this.db.doc(path).get();
|
|
41
|
-
const result = doc.data();
|
|
42
|
-
return result ? deserialize(result) : null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public async _get<T>(path: string): Promise<T> {
|
|
46
|
-
Logger.info(`Repository: get ${path}`);
|
|
47
|
-
const result = await this._find<T>(path);
|
|
48
|
-
if (!result) {
|
|
49
|
-
throw new NotFoundError(`Repository: document ${path} not found`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public async _getAll<T>(collection: string): Promise<T[]> {
|
|
56
|
-
Logger.info(`Repository: getAll ${collection}`);
|
|
57
|
-
const documents: T[] = [];
|
|
58
|
-
const querySnapshot = await this.getCollectionReference(collection).get();
|
|
59
|
-
querySnapshot.forEach(doc => {
|
|
60
|
-
documents.push(deserialize(doc.data()));
|
|
61
|
-
});
|
|
62
|
-
return documents;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public async _getWhere<T>(collection: string, whereClauses: [string, FirestoreClient.Operator, any | any[]][] = [], orderBy: string = null): Promise<T[]> {
|
|
66
|
-
Logger.info(`Repository: getWhere ${collection} whereClauses: ${JSON.stringify(whereClauses)}`);
|
|
67
|
-
const documents: T[] = [];
|
|
68
|
-
|
|
69
|
-
let query = this.getCollectionReference(collection);
|
|
70
|
-
|
|
71
|
-
whereClauses.forEach(where => {
|
|
72
|
-
query = query.where(where[0], where[1], where[2]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
if (orderBy) {
|
|
76
|
-
query = query.orderBy(orderBy);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const querySnapshot = await query.get();
|
|
80
|
-
querySnapshot.forEach(doc => {
|
|
81
|
-
documents.push(deserialize(doc.data()));
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return documents;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
public createDocument(document: Document): void {
|
|
89
|
-
this.operations.push({ document, action: FirestoreClient.Action.Create });
|
|
90
|
-
this.cachedDocuments.set(document._path, document);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public updateDocument(document: Document): void {
|
|
94
|
-
this.operations.push({ document, action: FirestoreClient.Action.Update });
|
|
95
|
-
this.cachedDocuments.set(document._path, document);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public deleteDocument(document: Document): void {
|
|
99
|
-
this.operations.push({ document, action: FirestoreClient.Action.Delete });
|
|
100
|
-
this.cachedDocuments.delete(document._path);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private getCollectionReference(collection: string): FirebaseFirestore.CollectionReference | FirebaseFirestore.Query {
|
|
104
|
-
if (collection.startsWith('**/')) {
|
|
105
|
-
return this.db.collectionGroup(collection.replace('**/', ''));
|
|
106
|
-
} else {
|
|
107
|
-
return this.db.collection(collection);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export namespace FirestoreClient {
|
|
113
|
-
|
|
114
|
-
export interface Operation {
|
|
115
|
-
document: Document;
|
|
116
|
-
action: Action;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export enum Action {
|
|
120
|
-
Create = <any>'Create',
|
|
121
|
-
Update = <any>'Update',
|
|
122
|
-
Delete = <any>'Delete'
|
|
123
|
-
}
|
|
124
|
-
export type Operator = FirebaseFirestore.WhereFilterOp;
|
|
125
|
-
}
|