@ccci/micro-server 0.0.38 → 0.0.39
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/decorators/Endpoints.d.ts +12 -0
- package/dist/types/BaseControllerTypes.d.ts +39 -0
- package/dist/types/BaseModelTypes.d.ts +33 -0
- package/dist/types/BaseRouterTypes.d.ts +9 -0
- package/dist/utils/ApplicationServer.d.ts +9 -0
- package/dist/utils/BaseController.d.ts +76 -0
- package/dist/utils/BaseControllerHelper.d.ts +7 -0
- package/dist/utils/BaseModel.d.ts +27 -0
- package/dist/utils/BaseRouter.d.ts +77 -0
- package/dist/utils/DatabaseConnector.d.ts +22 -0
- package/dist/utils/ErrorHandler.d.ts +5 -0
- package/dist/utils/IBaseModel.d.ts +9 -0
- package/dist/utils/Logger.d.ts +7 -0
- package/dist/utils/RouterFactory.d.ts +12 -0
- package/dist/utils/TokenGenerator.d.ts +11 -0
- package/package.json +4 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const endpoint: (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
2
|
+
export declare const PublicAccess: <T extends new (...args: any[]) => {}>(constructor: T) => {
|
|
3
|
+
new (...args: any[]): {
|
|
4
|
+
grantPublicAccess: boolean;
|
|
5
|
+
};
|
|
6
|
+
} & T;
|
|
7
|
+
export declare const PrivateAccess: <T extends new (...args: any[]) => {}>(constructor: T) => {
|
|
8
|
+
new (...args: any[]): {
|
|
9
|
+
grantPublicAccess: boolean;
|
|
10
|
+
};
|
|
11
|
+
} & T;
|
|
12
|
+
//# sourceMappingURL=Endpoints.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Order, WhereOptions } from "sequelize";
|
|
2
|
+
export type RequestQuery = {
|
|
3
|
+
search?: string;
|
|
4
|
+
limit?: number;
|
|
5
|
+
page?: number;
|
|
6
|
+
includes?: string;
|
|
7
|
+
fields?: string;
|
|
8
|
+
sort?: string;
|
|
9
|
+
paginate?: string;
|
|
10
|
+
date_range?: string;
|
|
11
|
+
others?: any;
|
|
12
|
+
scan?: string;
|
|
13
|
+
};
|
|
14
|
+
export type QueryOptions = {
|
|
15
|
+
where?: WhereOptions<any>;
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
attributes?: Array<string>;
|
|
19
|
+
order?: Order;
|
|
20
|
+
includes?: Array<string | IncludeType>;
|
|
21
|
+
};
|
|
22
|
+
export type ResponseType = {
|
|
23
|
+
success: boolean;
|
|
24
|
+
error?: number;
|
|
25
|
+
statusCode?: number;
|
|
26
|
+
errorMessage?: string;
|
|
27
|
+
errorDescription?: string;
|
|
28
|
+
response?: object;
|
|
29
|
+
version?: string;
|
|
30
|
+
errors?: string[];
|
|
31
|
+
};
|
|
32
|
+
export type IncludeType = {
|
|
33
|
+
association?: string;
|
|
34
|
+
include?: Array<IncludeType>;
|
|
35
|
+
};
|
|
36
|
+
export type CommonType = {
|
|
37
|
+
[x: string | symbol]: any;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=BaseControllerTypes.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare enum FindTypeEnum {
|
|
2
|
+
FIND_ALL = "findAndCountAll",
|
|
3
|
+
FIND_PK = "findByPk",
|
|
4
|
+
FIND_ONE = "findOne",
|
|
5
|
+
COUNT = "count"
|
|
6
|
+
}
|
|
7
|
+
export type IncludesType = {
|
|
8
|
+
path?: string;
|
|
9
|
+
association?: AssociationType;
|
|
10
|
+
};
|
|
11
|
+
export type AssociationType = {
|
|
12
|
+
include: Array<string> | Array<object>;
|
|
13
|
+
association?: string;
|
|
14
|
+
where?: object;
|
|
15
|
+
};
|
|
16
|
+
export type QueryType = {
|
|
17
|
+
where?: object;
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
select?: object;
|
|
21
|
+
order?: object;
|
|
22
|
+
attributes?: object;
|
|
23
|
+
returning?: boolean;
|
|
24
|
+
raw?: boolean;
|
|
25
|
+
nest?: boolean;
|
|
26
|
+
distinct?: string;
|
|
27
|
+
include?: object;
|
|
28
|
+
};
|
|
29
|
+
export type RequestUserType = {
|
|
30
|
+
id?: number;
|
|
31
|
+
email?: string;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=BaseModelTypes.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { ResponseType } from './BaseControllerTypes';
|
|
3
|
+
export type Mappings = {
|
|
4
|
+
path: string;
|
|
5
|
+
method: string;
|
|
6
|
+
function: (req: Request, res: Response, next: NextFunction) => Promise<void | ResponseType>;
|
|
7
|
+
middleware?: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=BaseRouterTypes.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class ApplicationServer {
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the application server
|
|
4
|
+
* @param path root directory
|
|
5
|
+
* @param port port for the micro service
|
|
6
|
+
*/
|
|
7
|
+
static bootstrap(path: string, port: number): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ApplicationServer.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { ResponseType } from '../types/BaseControllerTypes';
|
|
3
|
+
export default class BaseController {
|
|
4
|
+
protected _model: import("sequelize").ModelCtor<import("sequelize").Model<any, any>> | undefined;
|
|
5
|
+
_modelName: string | undefined;
|
|
6
|
+
protected broadcastOnCreate: boolean;
|
|
7
|
+
protected broadcastOnUpdate: boolean;
|
|
8
|
+
protected broadcastOnDelete: boolean;
|
|
9
|
+
constructor(model?: string);
|
|
10
|
+
/**
|
|
11
|
+
* Find all the rows matching your query, within a specified offset / limit,
|
|
12
|
+
* and get the total number of rows matching your query.
|
|
13
|
+
* ```js
|
|
14
|
+
* Controller.find(req, res, next)
|
|
15
|
+
* ```
|
|
16
|
+
* @param req
|
|
17
|
+
* @param res
|
|
18
|
+
* @param next
|
|
19
|
+
*/
|
|
20
|
+
find(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
21
|
+
/**
|
|
22
|
+
* Search for a single instance by its primary key.
|
|
23
|
+
* This applies LIMIT 1, so the listener will always be called with a single instance.
|
|
24
|
+
* @param req
|
|
25
|
+
* @param res
|
|
26
|
+
* @param next
|
|
27
|
+
*/
|
|
28
|
+
findById(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param req
|
|
32
|
+
* @param res
|
|
33
|
+
* @param next
|
|
34
|
+
*/
|
|
35
|
+
create(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
36
|
+
/**
|
|
37
|
+
* Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number of affected rows, while the second element is the actual affected rows (only supported in postgres and mssql with options.returning true.)
|
|
38
|
+
* @param req
|
|
39
|
+
* @param res
|
|
40
|
+
* @param next
|
|
41
|
+
*/
|
|
42
|
+
update(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete multiple instances, or set their deletedAt timestamp to the current time if paranoid is enabled.
|
|
45
|
+
* @param req
|
|
46
|
+
* @param res
|
|
47
|
+
* @param next
|
|
48
|
+
*/
|
|
49
|
+
delete(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
50
|
+
/**
|
|
51
|
+
* Find all the rows matching your query, within a specified offset / limit,
|
|
52
|
+
* and get the total number of rows matching your query.
|
|
53
|
+
* ```js
|
|
54
|
+
* Controller.find(req, res, next)
|
|
55
|
+
* ```
|
|
56
|
+
* @param req
|
|
57
|
+
* @param res
|
|
58
|
+
* @param next
|
|
59
|
+
*/
|
|
60
|
+
archives(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
61
|
+
restore(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
|
|
62
|
+
/**
|
|
63
|
+
* ###############################################################
|
|
64
|
+
* ###################### LIFE CYCLE HOOKS #######################
|
|
65
|
+
* ###############################################################
|
|
66
|
+
*/
|
|
67
|
+
beforeCreate(req: Request): Promise<void>;
|
|
68
|
+
afterCreate(req: Request, rec: any): Promise<void>;
|
|
69
|
+
beforeUpdate(req: Request): Promise<void>;
|
|
70
|
+
afterUpdate(req: Request, rec: any, orig: any): Promise<void>;
|
|
71
|
+
beforeDelete(req: Request): Promise<void>;
|
|
72
|
+
afterDelete(req: Request, rec: any): Promise<void>;
|
|
73
|
+
beforeFind(req: Request): Promise<void>;
|
|
74
|
+
afterFind(req: Request): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=BaseController.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseError, UniqueConstraintError } from "sequelize";
|
|
2
|
+
import { RequestQuery, QueryOptions, ResponseType } from "../types/BaseControllerTypes";
|
|
3
|
+
export declare function ConstructQuery(query: RequestQuery): QueryOptions;
|
|
4
|
+
export declare function ResponseHelper(response?: any): ResponseType;
|
|
5
|
+
export declare function ErrorResponseHandler(error: UniqueConstraintError | BaseError | Error | any): ResponseType;
|
|
6
|
+
export { ResponseType };
|
|
7
|
+
//# sourceMappingURL=BaseControllerHelper.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DataTypes, Model } from 'sequelize';
|
|
2
|
+
import type { ModelAttributes } from "sequelize";
|
|
3
|
+
import type IBaseModel from './IBaseModel';
|
|
4
|
+
export default class BaseModel extends Model implements IBaseModel {
|
|
5
|
+
id?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Sets common model attributes
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
static getCommonAttributes(): {
|
|
11
|
+
createdById: {
|
|
12
|
+
type: DataTypes.IntegerDataType;
|
|
13
|
+
comment: string;
|
|
14
|
+
};
|
|
15
|
+
updatedById: {
|
|
16
|
+
type: DataTypes.IntegerDataType;
|
|
17
|
+
comment: string;
|
|
18
|
+
};
|
|
19
|
+
isActive: {
|
|
20
|
+
type: DataTypes.AbstractDataType;
|
|
21
|
+
comment: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
static getCommonAssociations(): void;
|
|
25
|
+
static initialize(fields: ModelAttributes, name: string): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=BaseModel.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Request, Response, NextFunction, Router } from 'express';
|
|
2
|
+
import BaseController from './BaseController';
|
|
3
|
+
import { Mappings } from '../types/BaseRouterTypes';
|
|
4
|
+
export default class BaseRouter<T extends BaseController> {
|
|
5
|
+
grantPublicAccess: boolean;
|
|
6
|
+
controller: T;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {Controller} controller
|
|
10
|
+
*/
|
|
11
|
+
constructor(controller: T);
|
|
12
|
+
/**
|
|
13
|
+
* @description GET route
|
|
14
|
+
* @param {Request} req
|
|
15
|
+
* @param {Response} res
|
|
16
|
+
* @param {NextFunction} next
|
|
17
|
+
*/
|
|
18
|
+
get(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* @description GET ARCHIVES route
|
|
21
|
+
* @param {Request} req
|
|
22
|
+
* @param {Response} res
|
|
23
|
+
* @param {NextFunction} next
|
|
24
|
+
*/
|
|
25
|
+
archives(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* @description POST route
|
|
28
|
+
* @param {Request} req
|
|
29
|
+
* @param {Response} res
|
|
30
|
+
* @param {NextFunction} next
|
|
31
|
+
*/
|
|
32
|
+
post(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* @description GET route (/:id)
|
|
35
|
+
* @param {HttpRequest} req
|
|
36
|
+
* @param {HttpResponse} res
|
|
37
|
+
* @param {*} next
|
|
38
|
+
*/
|
|
39
|
+
getId(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* @description PUT route (/:id)
|
|
42
|
+
* @param {HttpRequest} req
|
|
43
|
+
* @param {HttpResponse} res
|
|
44
|
+
* @param {*} next
|
|
45
|
+
*/
|
|
46
|
+
update(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param req
|
|
50
|
+
* @param res
|
|
51
|
+
* @param next
|
|
52
|
+
*/
|
|
53
|
+
delete(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param req
|
|
57
|
+
* @param res
|
|
58
|
+
* @param next
|
|
59
|
+
*/
|
|
60
|
+
restore(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* @description default mappings that will be inherited across all router class
|
|
63
|
+
* @returns {Array} mappings
|
|
64
|
+
*/
|
|
65
|
+
getMapping: () => Mappings[];
|
|
66
|
+
/**
|
|
67
|
+
* @description additional mappings placeholder, designed to be overriden
|
|
68
|
+
* @returns {Array} mappings
|
|
69
|
+
*/
|
|
70
|
+
getAdditionalMapping: () => Mappings[];
|
|
71
|
+
/**
|
|
72
|
+
* @description create the express router
|
|
73
|
+
* @returns {Router} router
|
|
74
|
+
*/
|
|
75
|
+
getRoutes(): Router;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=BaseRouter.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Model, ModelStatic, Sequelize } from "sequelize";
|
|
2
|
+
export default class DatabaseConnector {
|
|
3
|
+
private static connections;
|
|
4
|
+
private static connection;
|
|
5
|
+
private static rootDir;
|
|
6
|
+
constructor(path: string);
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param path
|
|
10
|
+
*/
|
|
11
|
+
static init(): Promise<Array<Sequelize>>;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param path root dir
|
|
15
|
+
*/
|
|
16
|
+
initializeModels(): Promise<void>;
|
|
17
|
+
getConnections(): Array<Sequelize>;
|
|
18
|
+
static getConnection(): Sequelize;
|
|
19
|
+
connect(connection: Sequelize): Promise<void>;
|
|
20
|
+
static getModel(modelName: string): ModelStatic<Model>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=DatabaseConnector.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Application, Request, Response, NextFunction } from 'express';
|
|
2
|
+
export default class RouterFactory {
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param app express application instance
|
|
6
|
+
* @param pathName root path of the application
|
|
7
|
+
* @param folderName path of the routers (default: routes)
|
|
8
|
+
*/
|
|
9
|
+
constructor(app: Application, pathName: string, folderName?: string, context?: string);
|
|
10
|
+
authenticate(req: Request, res: Response, next: NextFunction, grantPublicAccess?: boolean): Response<any, Record<string, any>> | undefined;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=RouterFactory.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import { RequestUserType } from '../types/BaseModelTypes';
|
|
3
|
+
/**
|
|
4
|
+
* generate jwt token from the payload
|
|
5
|
+
* @param payload
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function generate(payload: object): string;
|
|
9
|
+
export declare function verify(token: string): RequestUserType;
|
|
10
|
+
export declare function decode(val: string | Request): RequestUserType;
|
|
11
|
+
//# sourceMappingURL=TokenGenerator.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ccci/micro-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"files": [
|
|
30
30
|
"dist/*.js",
|
|
31
|
-
"dist/*.d.ts"
|
|
31
|
+
"dist/*.d.ts",
|
|
32
|
+
"dist/*/*.js",
|
|
33
|
+
"dist/*/*.d.ts"
|
|
32
34
|
],
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"cors": "^2.8.5",
|