pg-mvc-service 2.1.3 → 2.1.5
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/Service.d.ts +12 -8
- package/dist/Service.d.ts.map +1 -1
- package/dist/Service.js +95 -31
- package/package.json +1 -1
package/dist/Service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
import { Context } from 'hono';
|
|
3
|
+
import { Context, TypedResponse } from 'hono';
|
|
4
4
|
import { Pool, type PoolClient } from 'pg';
|
|
5
5
|
import { RequestType } from './reqestResponse/RequestType';
|
|
6
6
|
import { ResponseType } from './reqestResponse/ResponseType';
|
|
@@ -15,7 +15,6 @@ export interface IError {
|
|
|
15
15
|
description: string;
|
|
16
16
|
}
|
|
17
17
|
export declare class Service {
|
|
18
|
-
protected readonly module: 'express' | 'hono';
|
|
19
18
|
protected readonly method: MethodType;
|
|
20
19
|
get Method(): MethodType;
|
|
21
20
|
protected readonly endpoint: string;
|
|
@@ -35,10 +34,13 @@ export declare class Service {
|
|
|
35
34
|
get Tags(): Array<string>;
|
|
36
35
|
protected readonly errorList: Array<IError>;
|
|
37
36
|
get ErrorList(): Array<IError>;
|
|
38
|
-
|
|
39
|
-
protected
|
|
40
|
-
|
|
41
|
-
protected
|
|
37
|
+
private readonly req?;
|
|
38
|
+
protected get Req(): Request;
|
|
39
|
+
private readonly res?;
|
|
40
|
+
protected get Res(): Response;
|
|
41
|
+
private readonly c?;
|
|
42
|
+
protected get C(): Context;
|
|
43
|
+
get Module(): 'express' | 'hono';
|
|
42
44
|
constructor(request: Request, response: Response);
|
|
43
45
|
constructor(c: Context);
|
|
44
46
|
inintialize(): Promise<void>;
|
|
@@ -51,9 +53,11 @@ export declare class Service {
|
|
|
51
53
|
private setPool;
|
|
52
54
|
protected checkMaintenance(): Promise<void>;
|
|
53
55
|
protected middleware(): Promise<void>;
|
|
54
|
-
|
|
56
|
+
resSuccessExpress(): void;
|
|
57
|
+
resSuccessHono(): TypedResponse<any>;
|
|
55
58
|
protected outputErrorLog(ex: any): Promise<void>;
|
|
56
|
-
|
|
59
|
+
handleExceptionExpress(ex: any): void;
|
|
60
|
+
handleExceptionHono(ex: any): TypedResponse<any>;
|
|
57
61
|
private pool?;
|
|
58
62
|
protected get Pool(): Pool;
|
|
59
63
|
private client?;
|
package/dist/Service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../src/Service.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAQ,OAAO,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../src/Service.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAQ,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,KAAK,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,G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C,CAAa;IAC5B,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,SAAS,KAAK,MAAM,IAAI,UAAU,CAKjC;IAEY,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAM7B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAKvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAOzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,OAAO,CAAC,QAAQ,CAAC,CAAc;IAC/B,IAAI,QAAQ,IAAI,WAAW,CAU1B;IAED,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,IAAI,YAAY,IAAI,YAAY,CAK/B;IAED,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,IAAI,aAAa,IAAI,aAAa,CASjC;IAEY,UAAU,CAAC,QAAQ,GAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,GAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAChF,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;CA0C1H"}
|
package/dist/Service.js
CHANGED
|
@@ -40,17 +40,35 @@ class Service {
|
|
|
40
40
|
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
41
41
|
}];
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(_a = this.res) === null || _a === void 0 ? void 0 : _a.status(status).json(data);
|
|
43
|
+
get Req() {
|
|
44
|
+
if (this.req === undefined) {
|
|
45
|
+
throw new Error('This method can only be used when module is "express".');
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return this.req;
|
|
48
|
+
}
|
|
49
|
+
get Res() {
|
|
50
|
+
if (this.res === undefined) {
|
|
51
|
+
throw new Error('This method can only be used when module is "express".');
|
|
52
|
+
}
|
|
53
|
+
return this.res;
|
|
54
|
+
}
|
|
55
|
+
get C() {
|
|
56
|
+
if (this.c === undefined) {
|
|
57
|
+
throw new Error('This method can only be used when module is "hono".');
|
|
58
|
+
}
|
|
59
|
+
return this.c;
|
|
60
|
+
}
|
|
61
|
+
get Module() {
|
|
62
|
+
if (this.c !== undefined) {
|
|
63
|
+
return 'hono';
|
|
50
64
|
}
|
|
65
|
+
else if (this.req !== undefined && this.res !== undefined) {
|
|
66
|
+
return 'express';
|
|
67
|
+
}
|
|
68
|
+
throw new Error('Failed to determine whether the module is "express" or "hono".');
|
|
51
69
|
}
|
|
70
|
+
;
|
|
52
71
|
constructor(param1, param2) {
|
|
53
|
-
this.module = 'express';
|
|
54
72
|
this.method = 'GET';
|
|
55
73
|
this.endpoint = '';
|
|
56
74
|
this.apiCode = '';
|
|
@@ -69,23 +87,21 @@ class Service {
|
|
|
69
87
|
this.isExecuteRollback = false;
|
|
70
88
|
if (param2 !== undefined) {
|
|
71
89
|
// Express の場合: (request, response)
|
|
72
|
-
this.module = 'express';
|
|
73
90
|
this.req = param1;
|
|
74
91
|
this.res = param2;
|
|
75
92
|
}
|
|
76
93
|
else {
|
|
77
94
|
// Hono の場合: (c)
|
|
78
|
-
this.module = 'hono';
|
|
79
95
|
this.c = param1;
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
inintialize() {
|
|
83
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
if (this.
|
|
85
|
-
yield this.request.setRequest(this.
|
|
100
|
+
if (this.Module === "express") {
|
|
101
|
+
yield this.request.setRequest(this.Module, this.Req);
|
|
86
102
|
}
|
|
87
103
|
else {
|
|
88
|
-
yield this.request.setRequest(this.
|
|
104
|
+
yield this.request.setRequest(this.Module, this.C);
|
|
89
105
|
}
|
|
90
106
|
yield this.checkMaintenance();
|
|
91
107
|
yield this.middleware();
|
|
@@ -120,67 +136,115 @@ class Service {
|
|
|
120
136
|
middleware() {
|
|
121
137
|
return __awaiter(this, void 0, void 0, function* () { });
|
|
122
138
|
}
|
|
123
|
-
|
|
124
|
-
this.
|
|
139
|
+
resSuccessExpress() {
|
|
140
|
+
this.Res.status(200).json(this.response.ResponseData);
|
|
141
|
+
}
|
|
142
|
+
resSuccessHono() {
|
|
143
|
+
return this.C.json(this.response.ResponseData, 200);
|
|
125
144
|
}
|
|
126
145
|
outputErrorLog(ex) {
|
|
127
146
|
return __awaiter(this, void 0, void 0, function* () { });
|
|
128
147
|
}
|
|
129
|
-
|
|
148
|
+
handleExceptionExpress(ex) {
|
|
130
149
|
// To avoid slowing down the response, make this asynchronous
|
|
131
150
|
this.outputErrorLog(ex).catch((ex) => {
|
|
132
151
|
console.error(ex);
|
|
133
152
|
});
|
|
134
153
|
if (ex instanceof Exception_1.AuthException) {
|
|
135
|
-
this.
|
|
154
|
+
this.Res.status(401).json({
|
|
136
155
|
message: "Authentication expired. Please login again."
|
|
137
156
|
});
|
|
138
|
-
return;
|
|
139
157
|
}
|
|
140
158
|
else if (ex instanceof Exception_1.ForbiddenException) {
|
|
141
|
-
this.
|
|
159
|
+
this.Res.status(403).json({
|
|
142
160
|
message: 'Forbidden error'
|
|
143
161
|
});
|
|
144
|
-
return;
|
|
145
162
|
}
|
|
146
163
|
else if (ex instanceof Exception_1.InputErrorException) {
|
|
147
|
-
this.
|
|
164
|
+
this.Res.status(400).json({
|
|
148
165
|
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
149
166
|
errorMessage: ex.message
|
|
150
167
|
});
|
|
151
168
|
return;
|
|
152
169
|
}
|
|
153
170
|
else if (ex instanceof Exception_1.DbConflictException) {
|
|
154
|
-
this.
|
|
171
|
+
this.Res.status(409).json({
|
|
155
172
|
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
156
173
|
errorMessage: ex.message
|
|
157
174
|
});
|
|
158
|
-
return;
|
|
159
175
|
}
|
|
160
176
|
else if (ex instanceof Exception_1.UnprocessableException) {
|
|
161
|
-
this.
|
|
177
|
+
this.Res.status(422).json({
|
|
162
178
|
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
163
179
|
errorMessage: ex.message
|
|
164
180
|
});
|
|
165
|
-
return;
|
|
166
181
|
}
|
|
167
182
|
else if (ex instanceof Exception_1.MaintenanceException) {
|
|
168
|
-
this.
|
|
183
|
+
this.Res.status(503).json({
|
|
169
184
|
errorMessage: ex.message
|
|
170
185
|
});
|
|
171
|
-
return;
|
|
172
186
|
}
|
|
173
187
|
else if (ex instanceof Exception_1.NotFoundException) {
|
|
174
|
-
this.
|
|
188
|
+
this.Res.status(404).json({
|
|
175
189
|
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
176
190
|
errorMessage: ex.message
|
|
177
191
|
});
|
|
178
|
-
return;
|
|
179
192
|
}
|
|
180
|
-
|
|
181
|
-
|
|
193
|
+
else {
|
|
194
|
+
this.Res.status(500).json({
|
|
195
|
+
message: 'Internal server error'
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
handleExceptionHono(ex) {
|
|
200
|
+
// To avoid slowing down the response, make this asynchronous
|
|
201
|
+
this.outputErrorLog(ex).catch((ex) => {
|
|
202
|
+
console.error(ex);
|
|
182
203
|
});
|
|
183
|
-
|
|
204
|
+
if (ex instanceof Exception_1.AuthException) {
|
|
205
|
+
return this.C.json({
|
|
206
|
+
message: "Authentication expired. Please login again."
|
|
207
|
+
}, 401);
|
|
208
|
+
}
|
|
209
|
+
else if (ex instanceof Exception_1.ForbiddenException) {
|
|
210
|
+
return this.C.json({
|
|
211
|
+
message: 'Forbidden error'
|
|
212
|
+
}, 403);
|
|
213
|
+
}
|
|
214
|
+
else if (ex instanceof Exception_1.InputErrorException) {
|
|
215
|
+
return this.C.json({
|
|
216
|
+
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
217
|
+
errorMessage: ex.message
|
|
218
|
+
}, 400);
|
|
219
|
+
}
|
|
220
|
+
else if (ex instanceof Exception_1.DbConflictException) {
|
|
221
|
+
return this.C.json({
|
|
222
|
+
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
223
|
+
errorMessage: ex.message
|
|
224
|
+
}, 409);
|
|
225
|
+
}
|
|
226
|
+
else if (ex instanceof Exception_1.UnprocessableException) {
|
|
227
|
+
return this.C.json({
|
|
228
|
+
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
229
|
+
errorMessage: ex.message
|
|
230
|
+
}, 422);
|
|
231
|
+
}
|
|
232
|
+
else if (ex instanceof Exception_1.MaintenanceException) {
|
|
233
|
+
return this.C.json({
|
|
234
|
+
errorMessage: ex.message
|
|
235
|
+
}, 503);
|
|
236
|
+
}
|
|
237
|
+
else if (ex instanceof Exception_1.NotFoundException) {
|
|
238
|
+
return this.C.json({
|
|
239
|
+
errorCode: `${this.apiCode}-${ex.ErrorId}`,
|
|
240
|
+
errorMessage: ex.message
|
|
241
|
+
}, 404);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return this.C.json({
|
|
245
|
+
message: 'Internal server error'
|
|
246
|
+
}, 500);
|
|
247
|
+
}
|
|
184
248
|
}
|
|
185
249
|
get Pool() {
|
|
186
250
|
var _a;
|