kool-koala 1.2.0 → 1.3.0
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/common/configuration-parameters.d.ts +7 -11
- package/common/configuration-parameters.js.map +1 -1
- package/common/configuration.d.ts +9 -14
- package/common/configuration.js.map +1 -1
- package/common/database-configuration-paramters.d.ts +5 -0
- package/common/database-configuration-paramters.js +4 -0
- package/common/database-configuration-paramters.js.map +1 -0
- package/common/jwt-configuration-parameters.d.ts +4 -0
- package/common/jwt-configuration-parameters.js +4 -0
- package/common/jwt-configuration-parameters.js.map +1 -0
- package/common/koalapp.d.ts +7 -2
- package/common/koalapp.js +14 -4
- package/common/koalapp.js.map +1 -1
- package/controllers/rest-controller-base.d.ts +6 -2
- package/controllers/rest-controller-base.js.map +1 -1
- package/database/repositories/repository-base.d.ts +2 -2
- package/database/repositories/repository-base.js +2 -2
- package/database/repositories/repository-base.js.map +1 -1
- package/package.json +11 -8
- package/services/router-service.d.ts +1 -0
- package/services/router-service.js +3 -0
- package/services/router-service.js.map +1 -1
- package/types/common/string-enum.d.ts +3 -0
- package/types/common/string-enum.js +4 -0
- package/types/common/string-enum.js.map +1 -0
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { DataSource, Repository } from "typeorm";
|
|
2
1
|
import { ControllerConstructor } from "../controllers";
|
|
3
2
|
import { AuthenticableEntity } from "../types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export interface ConfigurationParameters<U extends AuthenticableEntity, P extends
|
|
3
|
+
import { StringEnum } from "../types/common/string-enum";
|
|
4
|
+
import { JwtConfigurationParameters } from "./jwt-configuration-parameters";
|
|
5
|
+
import { DatabaseConfigurationParamters } from "./database-configuration-paramters";
|
|
6
|
+
import { RepositoryBase } from "../database";
|
|
7
|
+
export interface ConfigurationParameters<U extends AuthenticableEntity = AuthenticableEntity, P extends StringEnum = {}> {
|
|
9
8
|
port: number;
|
|
10
9
|
controllers?: (ControllerConstructor)[];
|
|
11
10
|
database?: DatabaseConfigurationParamters;
|
|
12
|
-
jwt?:
|
|
13
|
-
|
|
14
|
-
secretKey: string;
|
|
15
|
-
};
|
|
16
|
-
userRepository?: Repository<U>;
|
|
11
|
+
jwt?: JwtConfigurationParameters;
|
|
12
|
+
userRepository?: RepositoryBase<U>;
|
|
17
13
|
permissionType?: P;
|
|
18
14
|
restPrefix?: string;
|
|
19
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/../src/common/configuration-parameters.ts"],"names":[],"mappings":"","file":"configuration-parameters.js","sourcesContent":["import { ControllerConstructor } from \"../controllers\";\nimport { AuthenticableEntity } from \"../types\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\nimport { DatabaseConfigurationParamters } from \"./database-configuration-paramters\";\nimport { RepositoryBase } from \"../database\";\n\nexport interface ConfigurationParameters<\n U extends AuthenticableEntity = AuthenticableEntity,\n P extends StringEnum = {}\n> {\n port: number,\n controllers?: (ControllerConstructor)[],\n database?: DatabaseConfigurationParamters,\n jwt?: JwtConfigurationParameters,\n userRepository?: RepositoryBase<U>,\n permissionType?: P,\n restPrefix?: string,\n}"]}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { Repository } from "typeorm";
|
|
2
|
-
import { ControllerConstructor } from "../controllers/controller-base";
|
|
3
1
|
import { AuthenticableEntity } from "../types/entities/authenticable-entity";
|
|
4
|
-
import { ConfigurationParameters
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export declare class Configuration<U extends AuthenticableEntity, P extends Record<string, string | number>> {
|
|
2
|
+
import { ConfigurationParameters } from "./configuration-parameters";
|
|
3
|
+
import { StringEnum } from "../types/common/string-enum";
|
|
4
|
+
import { JwtConfigurationParameters } from "./jwt-configuration-parameters";
|
|
5
|
+
export declare class Configuration<U extends AuthenticableEntity, P extends StringEnum> {
|
|
10
6
|
private parameters;
|
|
11
7
|
constructor(parameters: ConfigurationParameters<U, P>);
|
|
12
|
-
static instantiate<T extends AuthenticableEntity, Q extends
|
|
13
|
-
getControllers(): ControllerConstructor[];
|
|
14
|
-
getDatabase(): DatabaseConfigurationParamters;
|
|
8
|
+
static instantiate<T extends AuthenticableEntity, Q extends StringEnum>(configurationParameters: ConfigurationParameters<T, Q>): Configuration<T, Q>;
|
|
9
|
+
getControllers(): import("..").ControllerConstructor[];
|
|
10
|
+
getDatabase(): import("./database-configuration-paramters").DatabaseConfigurationParamters;
|
|
15
11
|
getPort(): number;
|
|
16
|
-
getJwtParameters():
|
|
17
|
-
getUserRepository():
|
|
12
|
+
getJwtParameters(): JwtConfigurationParameters;
|
|
13
|
+
getUserRepository(): import("..").RepositoryBase<U>;
|
|
18
14
|
getPermissionType(): P;
|
|
19
15
|
getRestPrefix(): string;
|
|
20
16
|
}
|
|
21
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/common/configuration.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/../src/common/configuration.ts"],"names":[],"mappings":";;;AAKA,MAAa,aAAa;IAIxB,YACU,UAAyC;QAAzC,eAAU,GAAV,UAAU,CAA+B;IAC/C,CAAC;IACL,MAAM,CAAC,WAAW,CAGhB,uBAAsD;QACtD,OAAO,IAAI,aAAa,CACtB,uBAAuB,CACxB,CAAC;IACJ,CAAC;IACD,cAAc;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACrC,CAAC;IACD,WAAW;QACT,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IAClC,CAAC;IACD,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,gBAAgB;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;IACxC,CAAC;IACD,aAAa;;QACX,OAAO,MAAA,IAAI,CAAC,UAAU,CAAC,UAAU,mCAAI,MAAM,CAAC;IAC9C,CAAC;CACF;AApCD,sCAoCC","file":"configuration.js","sourcesContent":["import { AuthenticableEntity } from \"../types/entities/authenticable-entity\";\nimport { ConfigurationParameters } from \"./configuration-parameters\";\nimport { StringEnum } from \"../types/common/string-enum\";\nimport { JwtConfigurationParameters } from \"./jwt-configuration-parameters\";\n\nexport class Configuration<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n constructor(\n private parameters: ConfigurationParameters<U, P>\n ) { }\n static instantiate<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configurationParameters: ConfigurationParameters<T, Q>): Configuration<T, Q> {\n return new Configuration<T, Q>(\n configurationParameters\n );\n }\n getControllers() {\n return this.parameters.controllers;\n }\n getDatabase() {\n return this.parameters.database;\n }\n getPort(): number {\n return this.parameters.port;\n }\n getJwtParameters(): JwtConfigurationParameters {\n return this.parameters.jwt;\n }\n getUserRepository() {\n return this.parameters.userRepository;\n }\n getPermissionType() {\n return this.parameters.permissionType;\n }\n getRestPrefix() {\n return this.parameters.restPrefix ?? '/api';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/../src/common/database-configuration-paramters.ts"],"names":[],"mappings":"","file":"database-configuration-paramters.js","sourcesContent":["import { DataSource } from \"typeorm\";\n\nexport interface DatabaseConfigurationParamters {\n dataSource: DataSource,\n shouldRunMigrations: boolean\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/../src/common/jwt-configuration-parameters.ts"],"names":[],"mappings":"","file":"jwt-configuration-parameters.js","sourcesContent":["export interface JwtConfigurationParameters {\n saltRounds: number,\n secretKey: string\n}\n"]}
|
package/common/koalapp.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Next, ParameterizedContext } from 'koa';
|
|
2
2
|
import { Configuration } from './configuration';
|
|
3
|
+
import { RouterService } from '../services/router-service';
|
|
3
4
|
import { AuthenticableEntity } from '../types/entities/authenticable-entity';
|
|
4
5
|
import { DataSource } from 'typeorm';
|
|
5
6
|
import { AuthorizationService } from '../services';
|
|
6
|
-
|
|
7
|
+
import { StringEnum } from '../types/common/string-enum';
|
|
8
|
+
export declare class KoalApp<U extends AuthenticableEntity, P extends StringEnum> {
|
|
7
9
|
private configuration;
|
|
8
10
|
private static instance;
|
|
9
11
|
private koa;
|
|
@@ -11,11 +13,14 @@ export declare class KoalApp<U extends AuthenticableEntity, P extends Record<str
|
|
|
11
13
|
private databaseConnection;
|
|
12
14
|
private authorizationService;
|
|
13
15
|
private constructor();
|
|
14
|
-
static getInstance<T extends AuthenticableEntity, Q extends
|
|
16
|
+
static getInstance<T extends AuthenticableEntity, Q extends StringEnum>(configuration?: Configuration<T, Q>): KoalApp<T, Q>;
|
|
17
|
+
static resetInstance(): void;
|
|
15
18
|
getConfiguration(): Configuration<U, P>;
|
|
19
|
+
getRouterService(): RouterService;
|
|
16
20
|
getDatabaseConnection(): DataSource;
|
|
17
21
|
initialize(): Promise<void>;
|
|
18
22
|
registerStaticFileServerMiddleware(): void;
|
|
23
|
+
registerEndpoints(): void;
|
|
19
24
|
start(callback?: (configuration: Configuration<U, P>) => void): Promise<void>;
|
|
20
25
|
authorizationHeaderParser(context: ParameterizedContext, next: Next): Promise<void>;
|
|
21
26
|
errorHandler(context: ParameterizedContext, next: Next): Promise<void>;
|
package/common/koalapp.js
CHANGED
|
@@ -36,9 +36,15 @@ class KoalApp {
|
|
|
36
36
|
}
|
|
37
37
|
return KoalApp.instance;
|
|
38
38
|
}
|
|
39
|
+
static resetInstance() {
|
|
40
|
+
KoalApp.instance = undefined;
|
|
41
|
+
}
|
|
39
42
|
getConfiguration() {
|
|
40
43
|
return this.configuration;
|
|
41
44
|
}
|
|
45
|
+
getRouterService() {
|
|
46
|
+
return this.routerService;
|
|
47
|
+
}
|
|
42
48
|
getDatabaseConnection() {
|
|
43
49
|
return this.databaseConnection;
|
|
44
50
|
}
|
|
@@ -62,6 +68,8 @@ class KoalApp {
|
|
|
62
68
|
console.log("Error handler initialized.");
|
|
63
69
|
this.registerStaticFileServerMiddleware();
|
|
64
70
|
console.log("Static file server initialized.");
|
|
71
|
+
this.registerEndpoints();
|
|
72
|
+
console.log("Endpoints registered.");
|
|
65
73
|
}
|
|
66
74
|
catch (error) {
|
|
67
75
|
console.log("Error during database initialization...", error);
|
|
@@ -83,12 +91,14 @@ class KoalApp {
|
|
|
83
91
|
}
|
|
84
92
|
}));
|
|
85
93
|
}
|
|
94
|
+
registerEndpoints() {
|
|
95
|
+
this.routerService = new router_service_1.RouterService(this.configuration.getControllers());
|
|
96
|
+
this.koa
|
|
97
|
+
.use(this.routerService.getRoutes())
|
|
98
|
+
.use(this.routerService.allowedMethods());
|
|
99
|
+
}
|
|
86
100
|
start(callback) {
|
|
87
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
this.routerService = new router_service_1.RouterService(this.configuration.getControllers());
|
|
89
|
-
this.koa
|
|
90
|
-
.use(this.routerService.getRoutes())
|
|
91
|
-
.use(this.routerService.allowedMethods());
|
|
92
102
|
this.koa.listen(this.configuration.getPort(), () => {
|
|
93
103
|
if (callback) {
|
|
94
104
|
callback(this.configuration);
|
package/common/koalapp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/common/koalapp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAsD;AAEtD,+DAA2D;AAG3D,+CAA2C;AAC3C,gEAA+B;AAC/B,oEAAwC;AACxC,oCAAmD;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BACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;CACF;AAnJD,0BAmJC","file":"koalapp.js","sourcesContent":["import Koa, { Next, ParameterizedContext } from 'koa';\nimport { Configuration } from './configuration';\nimport { RouterService } from '../services/router-service';\nimport { AuthenticableEntity } from '../types/entities/authenticable-entity';\nimport { DataSource } from 'typeorm';\nimport { StatusCode } from './status-code';\nimport jwt from 'jsonwebtoken';\nimport bodyParser from 'koa-bodyparser';\nimport { BaseResponse, ErrorBase } from '../types';\nimport serve from \"koa-static\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { AuthorizationService } from '../services';\nimport { StringEnum } from '../types/common/string-enum';\n\nexport class KoalApp<\n U extends AuthenticableEntity,\n P extends StringEnum\n> {\n private static instance: KoalApp<any, any>;\n\n private koa = new Koa();\n private routerService: RouterService;\n private databaseConnection: DataSource;\n\n private authorizationService: AuthorizationService<U, P>;\n\n private constructor(private configuration: Configuration<U, P>) {\n }\n\n public static getInstance<\n T extends AuthenticableEntity,\n Q extends StringEnum\n >(configuration?: Configuration<T, Q>): KoalApp<T, Q> {\n if (!KoalApp.instance) {\n if (!configuration) {\n throw new Error(\"Configuration is required\");\n }\n KoalApp.instance = new KoalApp(configuration!);\n }\n return KoalApp.instance;\n }\n\n public static resetInstance() {\n KoalApp.instance = undefined;\n }\n\n public getConfiguration(): Configuration<U, P> {\n return this.configuration;\n }\n\n public getRouterService(): RouterService {\n return this.routerService;\n }\n\n public getDatabaseConnection(): DataSource {\n return this.databaseConnection;\n }\n\n async initialize() {\n try {\n if (this.configuration.getDatabase()) {\n this.databaseConnection = await this.configuration.getDatabase().dataSource.initialize();\n if (this.configuration.getDatabase().shouldRunMigrations) {\n console.log(\"Executing database migrations...\");\n await this.databaseConnection.runMigrations();\n console.log(\"Database migrations executed.\");\n }\n console.log(\"Database connection initialized.\");\n }\n this.koa.use(this.authorizationHeaderParser.bind(this));\n console.log(\"Authorization header parser initialized.\");\n this.koa.use(bodyParser());\n console.log(\"Body parser initialized.\");\n this.koa.use(this.errorHandler.bind(this));\n console.log(\"Error handler initialized.\");\n this.registerStaticFileServerMiddleware();\n console.log(\"Static file server initialized.\");\n this.registerEndpoints();\n console.log(\"Endpoints registered.\");\n } catch (error) {\n console.log(\"Error during database initialization...\", error);\n throw new Error('Error during application intialization...');\n }\n }\n\n registerStaticFileServerMiddleware() {\n this.koa.use(serve(path.join(__dirname, '../client', 'browser')));\n this.koa.use(serve(path.join(__dirname, '../../static')));\n this.koa.use(async (ctx, next) => {\n const requestPath = ctx.request.path;\n\n if (!requestPath.startsWith(this.configuration.getRestPrefix()) && !/\\.[a-z]+$/.test(requestPath)) {\n ctx.type = 'html';\n ctx.body = fs.createReadStream(path.join(__dirname, '../client', 'browser', 'index.html'));\n } else {\n await next();\n }\n });\n }\n\n registerEndpoints() {\n this.routerService = new RouterService(\n this.configuration.getControllers()\n );\n this.koa\n .use(this.routerService.getRoutes())\n .use(this.routerService.allowedMethods());\n }\n\n async start(callback?: (configuration: Configuration<U, P>) => void) {\n this.koa.listen(this.configuration.getPort(), () => {\n if (callback) {\n callback(this.configuration);\n }\n });\n }\n\n async authorizationHeaderParser(context: ParameterizedContext, next: Next) {\n const authHeader = context.headers.authorization;\n if (authHeader) {\n const token = authHeader.split(' ')[1];\n try {\n context.state.user = jwt.verify(token, this.configuration.getJwtParameters().secretKey);\n await next();\n } catch (error) {\n context.status = StatusCode.UNAUTHORIZED;\n context.body = {\n success: false,\n message: 'Invalid token'\n }\n }\n }\n else {\n await next();\n }\n }\n\n async errorHandler(context: ParameterizedContext, next: Next) {\n try {\n await next();\n } catch (error) {\n if (error instanceof ErrorBase) {\n context.status = error.getStatusCode();\n context.body = <BaseResponse>{\n success: false,\n message: error.message\n };\n }\n else {\n console.log(error);\n context.status = StatusCode.INTERNAL_SERVER_ERROR;\n context.body = <BaseResponse>{\n success: false\n };\n }\n }\n }\n\n getAuthorizationService() {\n return this.authorizationService;\n }\n}"]}
|
|
@@ -3,11 +3,15 @@ import { RepositoryBase } from "../database/repositories";
|
|
|
3
3
|
import { IdentifiableEntity } from "../types";
|
|
4
4
|
import { ControllerBase } from "./controller-base";
|
|
5
5
|
import { DeepPartial } from "typeorm";
|
|
6
|
-
export declare abstract class RestControllerBase<T extends IdentifiableEntity, RouteType extends
|
|
6
|
+
export declare abstract class RestControllerBase<T extends IdentifiableEntity, RouteType extends {
|
|
7
|
+
[J in keyof RouteType]: string;
|
|
8
|
+
}, PermissionType extends {
|
|
9
|
+
[K in keyof PermissionType]: string;
|
|
10
|
+
}, CreateRequest extends any = Omit<T, 'id'>, EditRequest = T> extends ControllerBase {
|
|
7
11
|
abstract getEndpoint(): RouteType[keyof RouteType];
|
|
8
12
|
abstract getRepository(): RepositoryBase<T>;
|
|
9
13
|
registerEndpoints(): void;
|
|
10
|
-
protected getAuthorizationService(): import("..").AuthorizationService<import("../types").AuthenticableEntity,
|
|
14
|
+
protected getAuthorizationService(): import("..").AuthorizationService<import("../types").AuthenticableEntity, import("../types/common/string-enum").StringEnum>;
|
|
11
15
|
listEntities(context: ParameterizedContext): Promise<void>;
|
|
12
16
|
viewEntity(context: ParameterizedContext): Promise<void>;
|
|
13
17
|
createEntity(context: ParameterizedContext): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/controllers/rest-controller-base.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,oCAAuE;AACvE,uDAAmD;AACnD,sCAAgD;AAGhD,MAAsB,kBAAsM,SAAQ,gCAAc;IAGhP,iBAAiB;QACf,IAAI,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC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;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IACS,iBAAiB;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACS,mBAAmB;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAES,0BAA0B;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACS,0BAA0B;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACS,4BAA4B;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACS,0BAA0B;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACS,4BAA4B;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACe,kBAAkB,CAAC,IAAmB;;YACpD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IACe,iBAAiB,CAAC,MAAS,EAAE,IAAiB;;YAC5D,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IACe,kBAAkB,CAAC,MAAS;;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IACe,qBAAqB,CAAC,IAAmB;;YACvD,OAAO,IAAsB,CAAC;QAChC,CAAC;KAAA;IACe,qBAAqB,CAAC,MAAS,EAAE,IAAiB;;YAChE,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AAzJD,gDAyJC","file":"rest-controller-base.js","sourcesContent":["import { ParameterizedContext } from \"koa\";\nimport { RepositoryBase } from \"../database/repositories\";\nimport { BaseResponse, ErrorBase, IdentifiableEntity } from \"../types\";\nimport { ControllerBase } from \"./controller-base\";\nimport { KoalApp, StatusCode } from \"../common\";\nimport { DeepPartial } from \"typeorm\";\n\nexport abstract class RestControllerBase<T extends IdentifiableEntity, RouteType extends Record<string, string>, PermissionType extends Record<string, string>, CreateRequest extends any = Omit<T, 'id'>, EditRequest = T> extends ControllerBase {\n abstract getEndpoint(): RouteType[keyof RouteType];\n abstract getRepository(): RepositoryBase<T>;\n registerEndpoints(): void {\n if (this.shouldRegisterListEndpoint()) {\n this.router.get(this.getApiUrl(this.getEndpoint()), this.listEntities.bind(this));\n }\n if (this.shouldRegisterViewEndpoint()) {\n this.router.get(this.getApiUrl(`${this.getEndpoint()}/:id`), this.viewEntity.bind(this));\n }\n if (this.shouldRegisterCreateEndpoint()) {\n this.router.post(this.getApiUrl(this.getEndpoint()), this.createEntity.bind(this));\n }\n if (this.shouldRegisterEditEndpoint()) {\n this.router.put(this.getApiUrl(`${this.getEndpoint()}/:id`), this.editEntity.bind(this));\n }\n if (this.shouldRegisterDeleteEndpoint()) {\n this.router.delete(this.getApiUrl(`${this.getEndpoint()}/:id`), this.deleteEntity.bind(this));\n }\n }\n protected getAuthorizationService() {\n return KoalApp.getInstance().getAuthorizationService();\n }\n async listEntities(context: ParameterizedContext): Promise<void> {\n if (this.getListPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getListPermission());\n }\n context.body = await this.getEntities(context);\n }\n async viewEntity(context: ParameterizedContext): Promise<void> {\n if (this.getViewPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getViewPermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n context.body = entity;\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n async createEntity(context: ParameterizedContext): Promise<T> {\n if (this.getCreatePermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getCreatePermission());\n }\n const errorMessage = await this.entityCanBeCreated(context.request.body as CreateRequest);\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n const entity = await this.getRepository().save(await this.modifyEntityForCreate(context.request.body as CreateRequest));\n context.status = StatusCode.CREATED;\n context.body = {\n success: true,\n entity\n };\n return entity;\n }\n async editEntity(context: ParameterizedContext): Promise<void> {\n if (this.getEditPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getEditPermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n const errorMessage = await this.entityCanBeEdited(entity, context.request.body as EditRequest);\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n await this.getRepository().save(await this.modifyEntityForUpdate(entity, context.request.body as EditRequest));\n context.status = StatusCode.OK\n context.body = <BaseResponse>{\n success: true\n };\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n async deleteEntity(context: ParameterizedContext) {\n if (this.getDeletePermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getDeletePermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n const errorMessage = await this.entityCanBeDeleted(entity)\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n await this.delete(entity);\n context.status = StatusCode.OK;\n context.body = <BaseResponse>{\n success: true\n };\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n protected async delete(entity: T) {\n await this.getRepository().delete(entity);\n }\n getEntities(context: ParameterizedContext): Promise<T[]> {\n return this.getRepository().getAll();\n }\n getById(context: ParameterizedContext): Promise<T> {\n return this.getRepository().getById(context.params.id);\n }\n\n protected getListPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getViewPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getCreatePermission(): PermissionType | undefined {\n return undefined;\n }\n protected getEditPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getDeletePermission(): PermissionType | undefined {\n return undefined;\n }\n\n protected shouldRegisterListEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterViewEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterCreateEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterEditEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterDeleteEndpoint(): boolean {\n return true;\n }\n protected async entityCanBeCreated(body: CreateRequest): Promise<string | null> {\n return null;\n }\n protected async entityCanBeEdited(entity: T, body: EditRequest): Promise<string | null> {\n return null;\n }\n protected async entityCanBeDeleted(entity: T): Promise<string | null> {\n return null;\n }\n protected async modifyEntityForCreate(body: CreateRequest): Promise<DeepPartial<T>> {\n return body as DeepPartial<T>;\n }\n protected async modifyEntityForUpdate(entity: T, body: EditRequest): Promise<T> {\n return entity;\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["../src/../src/controllers/rest-controller-base.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,oCAAuE;AACvE,uDAAmD;AACnD,sCAAgD;AAGhD,MAAsB,kBAMpB,SAAQ,gCAAc;IAGtB,iBAAiB;QACf,IAAI,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,IAAI,CAAC,4BAA4B,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3F,CAAC;QACD,IAAI,IAAI,CAAC,4BAA4B,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,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controller-base.js","sourcesContent":["import { ParameterizedContext } from \"koa\";\nimport { RepositoryBase } from \"../database/repositories\";\nimport { BaseResponse, ErrorBase, IdentifiableEntity } from \"../types\";\nimport { ControllerBase } from \"./controller-base\";\nimport { KoalApp, StatusCode } from \"../common\";\nimport { DeepPartial } from \"typeorm\";\n\nexport abstract class RestControllerBase<\n T extends IdentifiableEntity,\n RouteType extends { [J in keyof RouteType]: string },\n PermissionType extends { [K in keyof PermissionType]: string },\n CreateRequest extends any = Omit<T, 'id'>,\n EditRequest = T\n> extends ControllerBase {\n abstract getEndpoint(): RouteType[keyof RouteType];\n abstract getRepository(): RepositoryBase<T>;\n registerEndpoints(): void {\n if (this.shouldRegisterListEndpoint()) {\n this.router.get(this.getApiUrl(this.getEndpoint()), this.listEntities.bind(this));\n }\n if (this.shouldRegisterViewEndpoint()) {\n this.router.get(this.getApiUrl(`${this.getEndpoint()}/:id`), this.viewEntity.bind(this));\n }\n if (this.shouldRegisterCreateEndpoint()) {\n this.router.post(this.getApiUrl(this.getEndpoint()), this.createEntity.bind(this));\n }\n if (this.shouldRegisterEditEndpoint()) {\n this.router.put(this.getApiUrl(`${this.getEndpoint()}/:id`), this.editEntity.bind(this));\n }\n if (this.shouldRegisterDeleteEndpoint()) {\n this.router.delete(this.getApiUrl(`${this.getEndpoint()}/:id`), this.deleteEntity.bind(this));\n }\n }\n protected getAuthorizationService() {\n return KoalApp.getInstance().getAuthorizationService();\n }\n async listEntities(context: ParameterizedContext): Promise<void> {\n if (this.getListPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getListPermission());\n }\n context.body = await this.getEntities(context);\n }\n async viewEntity(context: ParameterizedContext): Promise<void> {\n if (this.getViewPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getViewPermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n context.body = entity;\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n async createEntity(context: ParameterizedContext): Promise<T> {\n if (this.getCreatePermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getCreatePermission());\n }\n const errorMessage = await this.entityCanBeCreated(context.request.body as CreateRequest);\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n const entity = await this.getRepository().save(await this.modifyEntityForCreate(context.request.body as CreateRequest));\n context.status = StatusCode.CREATED;\n context.body = {\n success: true,\n entity\n };\n return entity;\n }\n async editEntity(context: ParameterizedContext): Promise<void> {\n if (this.getEditPermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getEditPermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n const errorMessage = await this.entityCanBeEdited(entity, context.request.body as EditRequest);\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n await this.getRepository().save(await this.modifyEntityForUpdate(entity, context.request.body as EditRequest));\n context.status = StatusCode.OK\n context.body = <BaseResponse>{\n success: true\n };\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n async deleteEntity(context: ParameterizedContext) {\n if (this.getDeletePermission() !== undefined) {\n await this.getAuthorizationService().userHasRight(context.state.user, this.getDeletePermission());\n }\n const entity = await this.getById(context);\n if (entity) {\n const errorMessage = await this.entityCanBeDeleted(entity)\n if (errorMessage !== null) {\n throw new ErrorBase(errorMessage, StatusCode.BAD_REQUEST);\n }\n await this.delete(entity);\n context.status = StatusCode.OK;\n context.body = <BaseResponse>{\n success: true\n };\n }\n else {\n context.status = StatusCode.NOT_FOUND;\n }\n }\n protected async delete(entity: T) {\n await this.getRepository().delete(entity);\n }\n getEntities(context: ParameterizedContext): Promise<T[]> {\n return this.getRepository().getAll();\n }\n getById(context: ParameterizedContext): Promise<T> {\n return this.getRepository().getById(context.params.id);\n }\n\n protected getListPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getViewPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getCreatePermission(): PermissionType | undefined {\n return undefined;\n }\n protected getEditPermission(): PermissionType | undefined {\n return undefined;\n }\n protected getDeletePermission(): PermissionType | undefined {\n return undefined;\n }\n\n protected shouldRegisterListEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterViewEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterCreateEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterEditEndpoint(): boolean {\n return true;\n }\n protected shouldRegisterDeleteEndpoint(): boolean {\n return true;\n }\n protected async entityCanBeCreated(body: CreateRequest): Promise<string | null> {\n return null;\n }\n protected async entityCanBeEdited(entity: T, body: EditRequest): Promise<string | null> {\n return null;\n }\n protected async entityCanBeDeleted(entity: T): Promise<string | null> {\n return null;\n }\n protected async modifyEntityForCreate(body: CreateRequest): Promise<DeepPartial<T>> {\n return body as DeepPartial<T>;\n }\n protected async modifyEntityForUpdate(entity: T, body: EditRequest): Promise<T> {\n return entity;\n }\n}"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DeepPartial, FindManyOptions, FindOneOptions, FindOptionsRelations, Repository } from "typeorm";
|
|
1
|
+
import { DataSource, DeepPartial, FindManyOptions, FindOneOptions, FindOptionsRelations, Repository } from "typeorm";
|
|
2
2
|
import { IdentifiableEntity } from "../../types";
|
|
3
3
|
export declare abstract class RepositoryBase<T extends IdentifiableEntity> {
|
|
4
4
|
private _repository;
|
|
5
|
-
constructor();
|
|
5
|
+
constructor(databaseConnection?: DataSource);
|
|
6
6
|
getRepository(): Repository<T>;
|
|
7
7
|
abstract getEntityType(): new () => T;
|
|
8
8
|
getAll(): Promise<T[]>;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RepositoryBase = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
class RepositoryBase {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._repository = common_1.KoalApp.getInstance().getDatabaseConnection().getRepository(this.getEntityType());
|
|
6
|
+
constructor(databaseConnection) {
|
|
7
|
+
this._repository = (databaseConnection !== null && databaseConnection !== void 0 ? databaseConnection : common_1.KoalApp.getInstance().getDatabaseConnection()).getRepository(this.getEntityType());
|
|
8
8
|
}
|
|
9
9
|
getRepository() {
|
|
10
10
|
return this._repository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/database/repositories/repository-base.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAEvC,MAAsB,cAAc;IAElC;
|
|
1
|
+
{"version":3,"sources":["../src/../src/database/repositories/repository-base.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAEvC,MAAsB,cAAc;IAElC,YAAY,kBAA+B;QACzC,IAAI,CAAC,WAAW,GAAG,CAAC,kBAAkB,aAAlB,kBAAkB,cAAlB,kBAAkB,GAAI,gBAAO,CAAC,WAAW,EAAE,CAAC,qBAAqB,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/H,CAAC;IACD,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IACD,QAAQ,CAAC,OAA2B;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,CAAC,OAA0B;QACpC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,CAAC,EAAU,EAAE,SAAmC;QACrD,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,CAAoB;YACrD,KAAK,EAAE;gBACL,EAAE;aACH;YACD,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,MAA0B;QAC7B,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,KAAyB;QAC5B,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,CAAC,KAAwB;QAC9B,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,MAAS;QACd,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;CACF;AAtCD,wCAsCC","file":"repository-base.js","sourcesContent":["import { DataSource, DeepPartial, FindManyOptions, FindOneOptions, FindOptionsRelations, Repository } from \"typeorm\";\nimport { IdentifiableEntity } from \"../../types\";\nimport { KoalApp } from \"../../common\";\n\nexport abstract class RepositoryBase<T extends IdentifiableEntity> {\n private _repository: Repository<T>;\n constructor(databaseConnection?: DataSource) {\n this._repository = (databaseConnection ?? KoalApp.getInstance().getDatabaseConnection()).getRepository(this.getEntityType());\n }\n getRepository() {\n return this._repository;\n }\n abstract getEntityType(): new () => T;\n getAll() {\n return this._repository.find();\n }\n getWhere(options: FindManyOptions<T>) {\n return this._repository.find(options);\n }\n getOneWhere(options: FindOneOptions<T>) {\n return this._repository.findOne(options);\n }\n getById(id: number, relations?: FindOptionsRelations<T>) {\n return this.getRepository().findOne(<FindOneOptions<T>>{\n where: {\n id\n },\n relations\n });\n }\n save(entity: T | DeepPartial<T>) {\n return this.getRepository().save(entity);\n }\n find(where: FindManyOptions<T>) {\n return this.getRepository().find(where);\n }\n findOne(where: FindOneOptions<T>) {\n return this.getRepository().findOne(where);\n }\n delete(entity: T) {\n return this.getRepository().delete(entity.id);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kool-koala",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Full-stack framework to create NodeJS applications on server side and Angular applications on the client side with ease.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dev": "gulp --gulpfile build/gulpfile.ts dev",
|
|
13
13
|
"compile": "gulp --gulpfile build/gulpfile.ts compile",
|
|
14
14
|
"compile-release": "gulp --gulpfile build/gulpfile.ts compile-release",
|
|
15
|
-
"test": "
|
|
15
|
+
"test": "mocha --config tests/.mocharc.json",
|
|
16
16
|
"prepare": "husky",
|
|
17
17
|
"postversion": "cp -r package.json .."
|
|
18
18
|
},
|
|
@@ -35,12 +35,15 @@
|
|
|
35
35
|
"@semantic-release/github": "^11.0.1",
|
|
36
36
|
"@semantic-release/npm": "^12.0.1",
|
|
37
37
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
38
|
+
"@types/chai": "^5.2.1",
|
|
38
39
|
"@types/gulp": "^4.0.17",
|
|
39
40
|
"@types/gulp-nodemon": "^0.0.37",
|
|
40
41
|
"@types/gulp-rename": "^2.0.6",
|
|
41
42
|
"@types/gulp-sourcemaps": "^0.0.38",
|
|
42
43
|
"@types/jsonwebtoken": "^9.0.9",
|
|
44
|
+
"@types/mocha": "^10.0.10",
|
|
43
45
|
"@types/yargs": "^17.0.33",
|
|
46
|
+
"chai": "^5.2.0",
|
|
44
47
|
"commitizen": "^4.3.1",
|
|
45
48
|
"cz-git": "^1.11.1",
|
|
46
49
|
"gulp": "^5.0.0",
|
|
@@ -49,8 +52,10 @@
|
|
|
49
52
|
"gulp-sourcemaps": "^3.0.0",
|
|
50
53
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
51
54
|
"husky": "^9.1.7",
|
|
55
|
+
"mocha": "^11.1.0",
|
|
52
56
|
"rimraf": "^6.0.1",
|
|
53
57
|
"semantic-release": "^24.2.3",
|
|
58
|
+
"sqlite3": "^5.1.7",
|
|
54
59
|
"ts-node": "^10.9.2",
|
|
55
60
|
"yargs": "^17.7.2"
|
|
56
61
|
},
|
|
@@ -59,18 +64,16 @@
|
|
|
59
64
|
"path": "./node_modules/cz-git"
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"koa": "^2.16.0",
|
|
64
|
-
"koa-router": "^13.0.1",
|
|
65
|
-
"typeorm": "^0.3.21"
|
|
66
|
-
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@types/koa": "^2.15.0",
|
|
69
69
|
"@types/koa-bodyparser": "^4.3.12",
|
|
70
70
|
"@types/koa-router": "^7.4.8",
|
|
71
71
|
"@types/koa-static": "^4.0.4",
|
|
72
72
|
"jsonwebtoken": "^9.0.2",
|
|
73
|
+
"koa": "^2.16.0",
|
|
73
74
|
"koa-bodyparser": "^4.4.1",
|
|
74
|
-
"koa-
|
|
75
|
+
"koa-router": "^13.0.1",
|
|
76
|
+
"koa-static": "^5.0.0",
|
|
77
|
+
"typeorm": "^0.3.22"
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/../src/services/router-service.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAgC;AAGhC,MAAa,aAAa;IAExB,YAAoB,WAAsC;;QAAtC,gBAAW,GAAX,WAAW,CAA2B;QACxD,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAM,EAAE,CAAC;QAC3B,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;YAClD,OAAO,CAAC,GAAG,CAAC,0BAA0B,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;YAC9D,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnD,UAAU,CAAC,iBAAiB,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF;
|
|
1
|
+
{"version":3,"sources":["../src/../src/services/router-service.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAgC;AAGhC,MAAa,aAAa;IAExB,YAAoB,WAAsC;;QAAtC,gBAAW,GAAX,WAAW,CAA2B;QACxD,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAM,EAAE,CAAC;QAC3B,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;YAClD,OAAO,CAAC,GAAG,CAAC,0BAA0B,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;YAC9D,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnD,UAAU,CAAC,iBAAiB,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;CACF;AAtBD,sCAsBC","file":"router-service.js","sourcesContent":["import Router from \"koa-router\";\nimport { ControllerConstructor } from \"../controllers/controller-base\";\n\nexport class RouterService {\n private router: Router;\n constructor(private controllers: (ControllerConstructor)[]) {\n this.router = new Router();\n (this.controllers ?? []).forEach((controllerType) => {\n console.log(`Register endpoints of '${controllerType.name}'`);\n const controller = new controllerType(this.router);\n controller.registerEndpoints();\n });\n }\n\n getRouter() {\n return this.router;\n }\n\n getRoutes() {\n return this.router.routes();\n }\n\n allowedMethods() {\n return this.router.allowedMethods();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/../src/types/common/string-enum.ts"],"names":[],"mappings":"","file":"string-enum.js","sourcesContent":["export type StringEnum = { [key: string]: string };\n"]}
|