namirasoft-node 1.1.44 → 1.1.46
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/BaseController.d.ts +6 -6
- package/dist/BaseController.js +10 -7
- package/dist/BaseController.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseController.ts +16 -13
package/dist/BaseController.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare abstract class BaseController<D extends BaseDatabase, State, Prop
|
|
|
20
20
|
protected state: State;
|
|
21
21
|
protected props: Props;
|
|
22
22
|
constructor(app: BaseApplication<D>, req: express.Request, res: express.Response);
|
|
23
|
-
|
|
23
|
+
protected getAnomaly(): AnomalyDetector | null;
|
|
24
24
|
abstract getDatabase(): D;
|
|
25
25
|
abstract getLogger(): ILogger;
|
|
26
26
|
abstract getInfo(): {
|
|
@@ -30,11 +30,11 @@ export declare abstract class BaseController<D extends BaseDatabase, State, Prop
|
|
|
30
30
|
path: string;
|
|
31
31
|
summary: string;
|
|
32
32
|
};
|
|
33
|
-
abstract getHeadersSchema(): BaseVariableSchema[]
|
|
34
|
-
abstract getParametersSchema(): BaseVariableSchema[]
|
|
35
|
-
abstract getBodySchema(): BaseTypeSchema | null
|
|
36
|
-
abstract getQueriesSchema(): BaseVariableSchema[]
|
|
37
|
-
abstract getOutputSchema(): BaseTypeSchema | null
|
|
33
|
+
abstract getHeadersSchema(): Promise<BaseVariableSchema[]>;
|
|
34
|
+
abstract getParametersSchema(): Promise<BaseVariableSchema[]>;
|
|
35
|
+
abstract getBodySchema(): Promise<BaseTypeSchema | null>;
|
|
36
|
+
abstract getQueriesSchema(): Promise<BaseVariableSchema[]>;
|
|
37
|
+
abstract getOutputSchema(): Promise<BaseTypeSchema | null>;
|
|
38
38
|
abstract getState(): Promise<State>;
|
|
39
39
|
abstract getProps(): Promise<Props>;
|
|
40
40
|
abstract preHandle(): Promise<void>;
|
package/dist/BaseController.js
CHANGED
|
@@ -22,6 +22,9 @@ class BaseController {
|
|
|
22
22
|
this.res = res;
|
|
23
23
|
this.logger = this.getLogger();
|
|
24
24
|
}
|
|
25
|
+
getAnomaly() {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
25
28
|
run() {
|
|
26
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
30
|
this.meta = new Meta_1.Meta(this.req);
|
|
@@ -46,8 +49,8 @@ class BaseController {
|
|
|
46
49
|
if (anomaly.isAnomaly(this.meta.ip, this.meta.url))
|
|
47
50
|
namirasoft_core_1.ErrorOperation.throwHTTP(403, 'Suspicious activity detected.');
|
|
48
51
|
// check
|
|
49
|
-
namirasoft_schema_1.JoiValidator.check(this.getBodySchema(), this.req.body);
|
|
50
|
-
namirasoft_schema_1.JoiValidator.checkArray(this.getQueriesSchema(), this.req.query);
|
|
52
|
+
namirasoft_schema_1.JoiValidator.check(yield this.getBodySchema(), this.req.body);
|
|
53
|
+
namirasoft_schema_1.JoiValidator.checkArray(yield this.getQueriesSchema(), this.req.query);
|
|
51
54
|
// call controller
|
|
52
55
|
this.output = yield this.handle();
|
|
53
56
|
// postHandle
|
|
@@ -94,11 +97,11 @@ class BaseController {
|
|
|
94
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
98
|
let info = this.getInfo();
|
|
96
99
|
let schema = new namirasoft_schema_1.ControllerSchema(info.name, info.tag, info.method, info.path, info.summary);
|
|
97
|
-
schema.headers = this.getHeadersSchema();
|
|
98
|
-
schema.parameters = this.getParametersSchema();
|
|
99
|
-
schema.body = this.getBodySchema();
|
|
100
|
-
schema.queries = this.getQueriesSchema();
|
|
101
|
-
schema.output = this.getOutputSchema();
|
|
100
|
+
schema.headers = yield this.getHeadersSchema();
|
|
101
|
+
schema.parameters = yield this.getParametersSchema();
|
|
102
|
+
schema.body = yield this.getBodySchema();
|
|
103
|
+
schema.queries = yield this.getQueriesSchema();
|
|
104
|
+
schema.output = yield this.getOutputSchema();
|
|
102
105
|
schema.check();
|
|
103
106
|
return schema;
|
|
104
107
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../src/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,iCAA8B;AAC9B,qDAAwE;AAExE,yDAAuG;AAEvG,MAAsB,cAAc;IAchC,YAAY,GAAuB,EAAE,GAAoB,EAAE,GAAqB;QAZtE,0BAAqB,GAAY,KAAK,CAAC;QACvC,oBAAe,GAAY,IAAI,CAAC;QAatC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../src/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,iCAA8B;AAC9B,qDAAwE;AAExE,yDAAuG;AAEvG,MAAsB,cAAc;IAchC,YAAY,GAAuB,EAAE,GAAoB,EAAE,GAAqB;QAZtE,0BAAqB,GAAY,KAAK,CAAC;QACvC,oBAAe,GAAY,IAAI,CAAC;QAatC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,CAAC;IACS,UAAU;QAEhB,OAAO,IAAI,CAAC;IAChB,CAAC;IAeK,GAAG;;YAEL,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC/B,SAAS;YACT,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IACA;gBACI,OAAO;gBACP,IAAI,CAAC,IAAI,C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IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7D,CAAC;KAAA;IACK,SAAS;;YAEX,IAAI,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,MAAM,GAAG,IAAI,oCAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7F,MAAM,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC/C,MAAM,CAAC,UAAU,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACzC,MAAM,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC/C,MAAM,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YAC7C,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,MAAM,CAAC;QAClB,CAAC;KAAA;CACJ;AAjID,wCAiIC"}
|
package/package.json
CHANGED
package/src/BaseController.ts
CHANGED
|
@@ -28,15 +28,18 @@ export abstract class BaseController<D extends BaseDatabase, State, Props, Outpu
|
|
|
28
28
|
this.res = res;
|
|
29
29
|
this.logger = this.getLogger();
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
protected getAnomaly(): AnomalyDetector | null
|
|
32
|
+
{
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
32
35
|
abstract getDatabase(): D;
|
|
33
36
|
abstract getLogger(): ILogger;
|
|
34
37
|
abstract getInfo(): { name: string, tag: string, method: HTTPMethod, path: string, summary: string };
|
|
35
|
-
abstract getHeadersSchema(): BaseVariableSchema[]
|
|
36
|
-
abstract getParametersSchema(): BaseVariableSchema[]
|
|
37
|
-
abstract getBodySchema(): BaseTypeSchema | null
|
|
38
|
-
abstract getQueriesSchema(): BaseVariableSchema[]
|
|
39
|
-
abstract getOutputSchema(): BaseTypeSchema | null
|
|
38
|
+
abstract getHeadersSchema(): Promise<BaseVariableSchema[]>;
|
|
39
|
+
abstract getParametersSchema(): Promise<BaseVariableSchema[]>;
|
|
40
|
+
abstract getBodySchema(): Promise<BaseTypeSchema | null>;
|
|
41
|
+
abstract getQueriesSchema(): Promise<BaseVariableSchema[]>;
|
|
42
|
+
abstract getOutputSchema(): Promise<BaseTypeSchema | null>;
|
|
40
43
|
abstract getState(): Promise<State>;
|
|
41
44
|
abstract getProps(): Promise<Props>;
|
|
42
45
|
abstract preHandle(): Promise<void>;
|
|
@@ -71,8 +74,8 @@ export abstract class BaseController<D extends BaseDatabase, State, Props, Outpu
|
|
|
71
74
|
ErrorOperation.throwHTTP(403, 'Suspicious activity detected.');
|
|
72
75
|
|
|
73
76
|
// check
|
|
74
|
-
JoiValidator.check(this.getBodySchema(), this.req.body);
|
|
75
|
-
JoiValidator.checkArray(this.getQueriesSchema(), this.req.query);
|
|
77
|
+
JoiValidator.check(await this.getBodySchema(), this.req.body);
|
|
78
|
+
JoiValidator.checkArray(await this.getQueriesSchema(), this.req.query);
|
|
76
79
|
|
|
77
80
|
// call controller
|
|
78
81
|
this.output = await this.handle();
|
|
@@ -125,11 +128,11 @@ export abstract class BaseController<D extends BaseDatabase, State, Props, Outpu
|
|
|
125
128
|
{
|
|
126
129
|
let info = this.getInfo();
|
|
127
130
|
let schema = new ControllerSchema(info.name, info.tag, info.method, info.path, info.summary);
|
|
128
|
-
schema.headers = this.getHeadersSchema();
|
|
129
|
-
schema.parameters = this.getParametersSchema();
|
|
130
|
-
schema.body = this.getBodySchema();
|
|
131
|
-
schema.queries = this.getQueriesSchema();
|
|
132
|
-
schema.output = this.getOutputSchema();
|
|
131
|
+
schema.headers = await this.getHeadersSchema();
|
|
132
|
+
schema.parameters = await this.getParametersSchema();
|
|
133
|
+
schema.body = await this.getBodySchema();
|
|
134
|
+
schema.queries = await this.getQueriesSchema();
|
|
135
|
+
schema.output = await this.getOutputSchema();
|
|
133
136
|
schema.check();
|
|
134
137
|
return schema;
|
|
135
138
|
}
|