pg-mvc-service 1.0.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/README.md +1 -0
- package/dist/PoolManager.js +57 -0
- package/dist/Service.js +257 -0
- package/dist/clients/AwsS3Client.js +249 -0
- package/dist/clients/Base64Client.js +153 -0
- package/dist/clients/EncryptClient.js +85 -0
- package/dist/clients/StringClient.js +13 -0
- package/dist/documents/Swagger.js +94 -0
- package/dist/exceptions/Exception.js +53 -0
- package/dist/index.js +16 -0
- package/dist/models/MigrateDatabase.js +138 -0
- package/dist/models/MigrateRollback.js +146 -0
- package/dist/models/MigrateTable.js +51 -0
- package/dist/models/SqlUtils/SelectExpression.js +92 -0
- package/dist/models/SqlUtils/ValidateValueUtil.js +250 -0
- package/dist/models/SqlUtils/WhereExpression.js +256 -0
- package/dist/models/TableDoc.js +353 -0
- package/dist/models/TableModel.js +636 -0
- package/dist/models/Type.js +2 -0
- package/dist/models/Utils/DateTimeUtil.js +134 -0
- package/dist/models/Utils/NumberUtil.js +28 -0
- package/dist/models/Utils/StringUtil.js +31 -0
- package/dist/models/ValidateClient.js +164 -0
- package/dist/models/index.js +14 -0
- package/dist/reqestResponse/ReqResType.js +196 -0
- package/dist/reqestResponse/RequestType.js +742 -0
- package/dist/reqestResponse/ResponseType.js +380 -0
- package/index.d.ts +306 -0
- package/package.json +36 -0
- package/src/PoolManager.ts +48 -0
- package/src/Service.ts +251 -0
- package/src/clients/AwsS3Client.ts +229 -0
- package/src/clients/Base64Client.ts +155 -0
- package/src/clients/EncryptClient.ts +100 -0
- package/src/clients/StringClient.ts +14 -0
- package/src/documents/Swagger.ts +111 -0
- package/src/exceptions/Exception.ts +54 -0
- package/src/index.ts +7 -0
- package/src/models/MigrateDatabase.ts +135 -0
- package/src/models/MigrateRollback.ts +151 -0
- package/src/models/MigrateTable.ts +56 -0
- package/src/models/SqlUtils/SelectExpression.ts +97 -0
- package/src/models/SqlUtils/ValidateValueUtil.ts +270 -0
- package/src/models/SqlUtils/WhereExpression.ts +286 -0
- package/src/models/TableDoc.ts +360 -0
- package/src/models/TableModel.ts +713 -0
- package/src/models/Type.ts +59 -0
- package/src/models/Utils/DateTimeUtil.ts +146 -0
- package/src/models/Utils/NumberUtil.ts +23 -0
- package/src/models/Utils/StringUtil.ts +33 -0
- package/src/models/ValidateClient.ts +182 -0
- package/src/models/index.ts +7 -0
- package/src/reqestResponse/ReqResType.ts +242 -0
- package/src/reqestResponse/RequestType.ts +851 -0
- package/src/reqestResponse/ResponseType.ts +418 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ResponseType = void 0;
|
|
7
|
+
const ReqResType_1 = __importDefault(require("./ReqResType"));
|
|
8
|
+
class ResponseType extends ReqResType_1.default {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
/**
|
|
12
|
+
* Property to store response data
|
|
13
|
+
* レスポンスデータを格納するためのプロパティ
|
|
14
|
+
*/
|
|
15
|
+
this.Data = {};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert and retrieve data according to the type definition
|
|
19
|
+
* 型定義に従ってデータを変換して取得
|
|
20
|
+
* @returns {Object.<string, any>} Converted data, 変換されたデータ
|
|
21
|
+
*/
|
|
22
|
+
get ResponseData() {
|
|
23
|
+
let data = {};
|
|
24
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
25
|
+
if (key in this.Data === false) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (this.Data[key] === undefined) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (this.Data[key] === null || (property.type.replace("?", "") !== "string" && this.Data[key] === "")) {
|
|
32
|
+
data[key] = property.type.endsWith('?') ? null : undefined;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
switch (property.type) {
|
|
36
|
+
case 'object':
|
|
37
|
+
case 'object?':
|
|
38
|
+
data[key] = this.getObject([key]);
|
|
39
|
+
break;
|
|
40
|
+
case 'array':
|
|
41
|
+
case 'array?':
|
|
42
|
+
data[key] = this.getArray([key]);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
data[key] = this.getValue([key]);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve object type data
|
|
53
|
+
* オブジェクト型のデータを取得
|
|
54
|
+
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
55
|
+
* @returns {Object.<string, any>} Retrieved object data, 取得されたオブジェクトデータ
|
|
56
|
+
*/
|
|
57
|
+
getObject(keys) {
|
|
58
|
+
let resData = {};
|
|
59
|
+
const data = this.getData(keys);
|
|
60
|
+
const properties = this.getProperty(keys).properties;
|
|
61
|
+
for (const key of Object.keys(properties)) {
|
|
62
|
+
if (key in data === false || data[key] === undefined) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const property = properties[key];
|
|
66
|
+
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
67
|
+
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
switch (property.type) {
|
|
71
|
+
case 'object':
|
|
72
|
+
case 'object?':
|
|
73
|
+
resData[key] = this.getObject([...keys, key]);
|
|
74
|
+
break;
|
|
75
|
+
case 'array':
|
|
76
|
+
case 'array?':
|
|
77
|
+
resData[key] = this.getArray([...keys, key]);
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
resData[key] = this.getValue([...keys, key]);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return resData;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve array type data
|
|
88
|
+
* 配列型のデータを取得
|
|
89
|
+
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
90
|
+
* @returns {Array<any> | undefined} Retrieved array data, 取得された配列データ
|
|
91
|
+
*/
|
|
92
|
+
getArray(keys) {
|
|
93
|
+
const data = this.getData(keys);
|
|
94
|
+
if (data === undefined || Array.isArray(data) === false) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const properties = this.getProperty(keys).properties;
|
|
98
|
+
let resData = [];
|
|
99
|
+
for (let i = 0; i < data.length; i++) {
|
|
100
|
+
switch (properties.type) {
|
|
101
|
+
case 'object':
|
|
102
|
+
case 'object?':
|
|
103
|
+
resData.push(this.getObject([...keys, i]));
|
|
104
|
+
break;
|
|
105
|
+
case 'array':
|
|
106
|
+
case 'array?':
|
|
107
|
+
resData.push(this.getArray([...keys, i]));
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
resData.push(this.getValue([...keys, i]));
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return resData;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Retrieve property type data
|
|
118
|
+
* プロパティ型のデータを取得
|
|
119
|
+
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
120
|
+
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
121
|
+
*/
|
|
122
|
+
getProperty(keys) {
|
|
123
|
+
let property = this.properties;
|
|
124
|
+
for (let i = 0; i < keys.length; i++) {
|
|
125
|
+
const key = keys[i];
|
|
126
|
+
if (typeof key === 'number') {
|
|
127
|
+
property = property.properties;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (i === 0) {
|
|
131
|
+
property = property[key];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
property = property.properties[key];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return property;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Retrieve data based on the provided keys
|
|
141
|
+
* 指定されたキーに基づいてデータを取得
|
|
142
|
+
* @param {Array.<string|number>} keys - Path to the data, データへのパス
|
|
143
|
+
* @returns {any} Retrieved data, 取得されたデータ
|
|
144
|
+
*/
|
|
145
|
+
getData(keys) {
|
|
146
|
+
let data = this.Data;
|
|
147
|
+
for (let i = 0; i < keys.length; i++) {
|
|
148
|
+
const key = keys[i];
|
|
149
|
+
if (typeof key === 'number') {
|
|
150
|
+
data = data[key];
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
data = data[key];
|
|
154
|
+
}
|
|
155
|
+
return data;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Retrieve value based on the provided keys
|
|
159
|
+
* 指定されたキーに基づいて値を取得
|
|
160
|
+
* @param {Array.<string|number>} keys - Path to the value, 値へのパス
|
|
161
|
+
* @returns {string | number | boolean | null | undefined} Retrieved value, 取得された値
|
|
162
|
+
*/
|
|
163
|
+
getValue(keys) {
|
|
164
|
+
const property = this.getProperty(keys);
|
|
165
|
+
const value = this.getData(keys);
|
|
166
|
+
if (value === null) {
|
|
167
|
+
return property.type.endsWith('?') ? null : undefined;
|
|
168
|
+
}
|
|
169
|
+
switch (property.type) {
|
|
170
|
+
case 'number':
|
|
171
|
+
case 'number?':
|
|
172
|
+
if (this.isNumber(value) === false) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
return Number(value);
|
|
176
|
+
case 'boolean':
|
|
177
|
+
case 'boolean?':
|
|
178
|
+
switch (typeof value) {
|
|
179
|
+
case 'boolean':
|
|
180
|
+
return value;
|
|
181
|
+
case 'number':
|
|
182
|
+
if (value !== 0 && value !== 1) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
return value === 1 ? true : false;
|
|
186
|
+
case 'string':
|
|
187
|
+
if (value !== 'true' && value !== 'false') {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
return value === 'true' ? true : false;
|
|
191
|
+
default:
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
case 'string':
|
|
195
|
+
case 'string?':
|
|
196
|
+
switch (typeof value) {
|
|
197
|
+
case 'number':
|
|
198
|
+
return value.toString();
|
|
199
|
+
case 'string':
|
|
200
|
+
return value;
|
|
201
|
+
default:
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
case 'uuid':
|
|
205
|
+
case 'uuid?':
|
|
206
|
+
if (this.isUUID(value)) {
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
case 'mail':
|
|
211
|
+
case 'mail?':
|
|
212
|
+
if (this.isMail(value)) {
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
return undefined;
|
|
216
|
+
case 'date':
|
|
217
|
+
case 'date?':
|
|
218
|
+
if (value instanceof Date) {
|
|
219
|
+
const year = value.getFullYear();
|
|
220
|
+
const month = String(value.getMonth() + 1).padStart(2, '0');
|
|
221
|
+
const day = String(value.getDate()).padStart(2, '0');
|
|
222
|
+
return `${year}-${month}-${day}`;
|
|
223
|
+
}
|
|
224
|
+
if (this.isYYYYMMDD(value) && this.isErrorDateTime(value) === false) {
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
case 'time':
|
|
229
|
+
case 'time?':
|
|
230
|
+
if (this.isHHMM(value)) {
|
|
231
|
+
return `${value}`;
|
|
232
|
+
}
|
|
233
|
+
if (this.isHHMMSS(value)) {
|
|
234
|
+
return value.slice(0, 5);
|
|
235
|
+
}
|
|
236
|
+
return undefined;
|
|
237
|
+
case 'datetime':
|
|
238
|
+
case 'datetime?':
|
|
239
|
+
if (value instanceof Date) {
|
|
240
|
+
const year = value.getFullYear();
|
|
241
|
+
const month = String(value.getMonth() + 1).padStart(2, '0');
|
|
242
|
+
const day = String(value.getDate()).padStart(2, '0');
|
|
243
|
+
const hours = String(value.getHours()).padStart(2, '0');
|
|
244
|
+
const minutes = String(value.getMinutes()).padStart(2, '0');
|
|
245
|
+
const seconds = String(value.getSeconds()).padStart(2, '0');
|
|
246
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
247
|
+
}
|
|
248
|
+
if (this.isYYYYMMDDhhmiss(value) && this.isErrorDateTime(value) === false) {
|
|
249
|
+
return value.replace('T', ' ');
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
case 'https':
|
|
253
|
+
case 'https?':
|
|
254
|
+
if (this.isHttps(value)) {
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
return undefined;
|
|
258
|
+
case 'base64':
|
|
259
|
+
case 'base64?':
|
|
260
|
+
if (this.isBase64(value)) {
|
|
261
|
+
return value;
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
case 'enum':
|
|
265
|
+
case 'enum?':
|
|
266
|
+
if (Object.keys(property.enums).includes(value)) {
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
default:
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// ****************************************************************************
|
|
275
|
+
// for create swagger
|
|
276
|
+
// ****************************************************************************
|
|
277
|
+
/**
|
|
278
|
+
* Generates Swagger response definition
|
|
279
|
+
* Swaggerのレスポンス定義を生成します
|
|
280
|
+
* @returns {string} Swagger format response definition
|
|
281
|
+
* Swagger形式のレスポンス定義
|
|
282
|
+
*/
|
|
283
|
+
createSwagger() {
|
|
284
|
+
let ymlString = ` responses:
|
|
285
|
+
'200':
|
|
286
|
+
description: 成功事レスポンス
|
|
287
|
+
content:
|
|
288
|
+
application/json:
|
|
289
|
+
schema:
|
|
290
|
+
type: object
|
|
291
|
+
properties:`;
|
|
292
|
+
if (Object.keys(this.properties).length === 0) {
|
|
293
|
+
ymlString += ' {}\n';
|
|
294
|
+
return ymlString;
|
|
295
|
+
}
|
|
296
|
+
ymlString += `\n`;
|
|
297
|
+
let tabCount = 9;
|
|
298
|
+
const space = ' '.repeat(tabCount);
|
|
299
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
300
|
+
ymlString += `${space}${key}:\n`;
|
|
301
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
302
|
+
if (property.description !== undefined) {
|
|
303
|
+
const joinSpace = `\n${space} `;
|
|
304
|
+
ymlString += `${space} description: |${joinSpace}${property.description.replaceAll("\n", joinSpace)}\n`;
|
|
305
|
+
}
|
|
306
|
+
switch (property.type) {
|
|
307
|
+
case 'object':
|
|
308
|
+
case 'object?':
|
|
309
|
+
ymlString += this.makeSwaggerProperyFromObject([key], tabCount + 1);
|
|
310
|
+
break;
|
|
311
|
+
case 'array':
|
|
312
|
+
case 'array?':
|
|
313
|
+
ymlString += this.makeSwaggerPropertyFromArray([key], tabCount + 1);
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return ymlString;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Generates Swagger properties from object type properties
|
|
321
|
+
* オブジェクト型のプロパティからSwaggerのプロパティを生成
|
|
322
|
+
* @param {Array.<string|number>} keys - Path to the properties
|
|
323
|
+
* プロパティへのパス
|
|
324
|
+
* @returns {string} Swagger format property definition
|
|
325
|
+
* Swagger形式のプロパティ定義
|
|
326
|
+
*/
|
|
327
|
+
makeSwaggerProperyFromObject(keys, tabCount) {
|
|
328
|
+
const space = ' '.repeat(tabCount);
|
|
329
|
+
let ymlString = `${space}properties:\n`;
|
|
330
|
+
const properties = this.getProperty(keys).properties;
|
|
331
|
+
for (const key of Object.keys(properties)) {
|
|
332
|
+
const property = properties[key];
|
|
333
|
+
ymlString += `${space} ${key}:\n`;
|
|
334
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
335
|
+
if (property.description !== undefined) {
|
|
336
|
+
const joinSpace = `\n${space} `;
|
|
337
|
+
ymlString += `${space} description: |${joinSpace}${property.description.replaceAll("\n", joinSpace)}\n`;
|
|
338
|
+
}
|
|
339
|
+
switch (property.type) {
|
|
340
|
+
case 'object':
|
|
341
|
+
case 'object?':
|
|
342
|
+
ymlString += this.makeSwaggerProperyFromObject([...keys, key], tabCount + 2);
|
|
343
|
+
break;
|
|
344
|
+
case 'array':
|
|
345
|
+
case 'array?':
|
|
346
|
+
ymlString += this.makeSwaggerPropertyFromArray([...keys, key], tabCount + 2);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return ymlString;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Generates Swagger properties from array type properties
|
|
354
|
+
* 配列型のプロパティからSwaggerのプロパティを生成
|
|
355
|
+
* @param {Array.<string|number>} keys - Path to the properties, プロパティへのパス
|
|
356
|
+
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
357
|
+
*/
|
|
358
|
+
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
359
|
+
const property = this.getProperty(keys).properties;
|
|
360
|
+
const space = ' '.repeat(tabCount);
|
|
361
|
+
let ymlString = `${space}items:\n`;
|
|
362
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
363
|
+
if (property.description !== undefined) {
|
|
364
|
+
const joinSpace = `\n${space} `;
|
|
365
|
+
ymlString += `${space} description: |${joinSpace}${property.description.replaceAll("\n", joinSpace)}\n`;
|
|
366
|
+
}
|
|
367
|
+
switch (property.type) {
|
|
368
|
+
case 'object':
|
|
369
|
+
case 'object?':
|
|
370
|
+
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
371
|
+
break;
|
|
372
|
+
case 'array':
|
|
373
|
+
case 'array?':
|
|
374
|
+
ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
return ymlString;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
exports.ResponseType = ResponseType;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { Request, Response } from 'express';
|
|
3
|
+
import { Pool, PoolClient } from 'pg';
|
|
4
|
+
import { IncomingHttpHeaders } from './src/reqestResponse/RequestType';
|
|
5
|
+
import { ArrayType, EnumType, ObjectType, PrimitiveType } from './src/reqestResponse/ReqResType';
|
|
6
|
+
import S3Client from './src/clients/AwsS3Client';
|
|
7
|
+
import Base64Client from './src/clients/Base64Client';
|
|
8
|
+
import StringClient from './src/clients/StringClient';
|
|
9
|
+
import EncryptClient from './src/clients/EncryptClient';
|
|
10
|
+
|
|
11
|
+
// models class
|
|
12
|
+
import ValidateClient from './src/models/ValidateClient';
|
|
13
|
+
|
|
14
|
+
declare module 'pg-mvc-service' {
|
|
15
|
+
export type MethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
16
|
+
|
|
17
|
+
export class Service {
|
|
18
|
+
protected readonly method: MethodType;
|
|
19
|
+
get Method(): MethodType;
|
|
20
|
+
protected readonly endpoint: string;
|
|
21
|
+
get Endpoint(): string;
|
|
22
|
+
protected readonly apiCode: string;
|
|
23
|
+
get ApiCode(): string;
|
|
24
|
+
protected readonly summary: string;
|
|
25
|
+
get Summary(): string;
|
|
26
|
+
protected readonly apiUserAvailable: string;
|
|
27
|
+
get ApiUserAvailable(): string;
|
|
28
|
+
protected readonly request: RequestType;
|
|
29
|
+
get AuthToken(): string;
|
|
30
|
+
protected readonly response: ResponseType;
|
|
31
|
+
protected readonly isTest: boolean;
|
|
32
|
+
protected readonly tags: Array<string>;
|
|
33
|
+
get Tags(): Array<string>;
|
|
34
|
+
|
|
35
|
+
protected readonly req: Request;
|
|
36
|
+
protected readonly res: Response;
|
|
37
|
+
constructor(request: Request, response: Response);
|
|
38
|
+
|
|
39
|
+
public inintialize(): void;
|
|
40
|
+
|
|
41
|
+
protected dbUser?: string;
|
|
42
|
+
protected dbHost?: string;
|
|
43
|
+
protected dbName?: string;
|
|
44
|
+
protected dbPassword?: string;
|
|
45
|
+
protected dbPort?: number;
|
|
46
|
+
protected dbIsSslConnect?: boolean;
|
|
47
|
+
protected checkMaintenance(): Promise<void>;
|
|
48
|
+
protected middleware(): Promise<void>;
|
|
49
|
+
|
|
50
|
+
public resSuccess(): void;
|
|
51
|
+
public handleException(ex: any): void;
|
|
52
|
+
protected outputErrorLog(ex: any): Promise<void>;
|
|
53
|
+
|
|
54
|
+
protected get Pool(): Pool;
|
|
55
|
+
protected get Client(): PoolClient;
|
|
56
|
+
|
|
57
|
+
public startConnect(): Promise<void>;
|
|
58
|
+
public commit(): Promise<void>;
|
|
59
|
+
public rollback(): Promise<void>;
|
|
60
|
+
public release(): Promise<void>;
|
|
61
|
+
|
|
62
|
+
get S3Client(): S3Client;
|
|
63
|
+
get Base64Client(): Base64Client;
|
|
64
|
+
get StringClient(): StringClient;
|
|
65
|
+
get EncryptClient(): EncryptClient;
|
|
66
|
+
|
|
67
|
+
public requestApi<TRequest=Record<string, any>, TResponse={[key: string]: any}>(
|
|
68
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', url: string, params: TRequest, header: {[key: string]: any}): Promise<AxiosResponse<TResponse>>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface IParams {
|
|
72
|
+
in: 'header' | 'path',
|
|
73
|
+
name: string,
|
|
74
|
+
require?: boolean,
|
|
75
|
+
description?: string,
|
|
76
|
+
example?: string
|
|
77
|
+
}
|
|
78
|
+
export function createSwagger(services: Service[], name: string, url: string, params: Array<IParams>): string;
|
|
79
|
+
|
|
80
|
+
export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType;
|
|
81
|
+
|
|
82
|
+
export class RequestType {
|
|
83
|
+
constructor();
|
|
84
|
+
|
|
85
|
+
protected properties: { [key: string]: PropertyType; };
|
|
86
|
+
|
|
87
|
+
public readonly INVALID_PATH_PARAM_UUID_ERROR_MESSAGE: string;
|
|
88
|
+
public readonly REQUIRED_ERROR_MESSAGE: string;
|
|
89
|
+
public readonly UNNECESSARY_INPUT_ERROR_MESSAGE: string;
|
|
90
|
+
public readonly INVALID_OBJECT_ERROR_MESSAGE: string;
|
|
91
|
+
public readonly INVALID_ARRAY_ERROR_MESSAGE: string;
|
|
92
|
+
public readonly INVALID_NUMBER_ERROR_MESSAGE: string;
|
|
93
|
+
public readonly INVALID_BOOL_ERROR_MESSAGE: string;
|
|
94
|
+
public readonly INVALID_STRING_ERROR_MESSAGE: string;
|
|
95
|
+
public readonly INVALID_UUID_ERROR_MESSAGE: string;
|
|
96
|
+
public readonly INVALID_MAIL_ERROR_MESSAGE: string;
|
|
97
|
+
public readonly INVALID_DATE_ERROR_MESSAGE: string;
|
|
98
|
+
public readonly INVALID_TIME_ERROR_MESSAGE: string;
|
|
99
|
+
public readonly INVALID_DATETIME_ERROR_MESSAGE: string;
|
|
100
|
+
public readonly INVALID_BASE64_ERROR_MESSAGE: string;
|
|
101
|
+
public readonly INVALID_ENUM_ERROR_MESSAGE: string;
|
|
102
|
+
|
|
103
|
+
protected throwException(code: string, message: string): never;
|
|
104
|
+
|
|
105
|
+
public setRequest(request: Request): void;
|
|
106
|
+
get Data(): { [key: string]: any };
|
|
107
|
+
get Headers(): IncomingHttpHeaders;
|
|
108
|
+
get Params(): { [key: string]: any };
|
|
109
|
+
get RemoteAddress(): string | undefined;
|
|
110
|
+
get Authorization(): string | null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class ResponseType {
|
|
114
|
+
public Data: { [key: string]: any };
|
|
115
|
+
|
|
116
|
+
protected properties: { [key: string]: PropertyType; };
|
|
117
|
+
get ResponseData(): { [key: string]: any };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class AuthException extends Error {
|
|
121
|
+
private id: string;
|
|
122
|
+
get Id(): string;
|
|
123
|
+
constructor(id: string, message?: string);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class ForbiddenException extends Error {
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export class InputErrorException extends Error {
|
|
130
|
+
private errorId: string;
|
|
131
|
+
get ErrorId(): string;
|
|
132
|
+
private errorLog: string;
|
|
133
|
+
get ErrorLog(): string;
|
|
134
|
+
constructor(errorId: string, message?: string, errorLog?: string);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export class MaintenanceException extends Error {
|
|
138
|
+
constructor(message?: string);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type TSqlValue = string | number | boolean | Date | null | Array<string | null> | Array<number | null> | Array<Date | null> | Array<Boolean | null>;
|
|
142
|
+
|
|
143
|
+
// column type
|
|
144
|
+
export type TColumnAttribute = "primary" | "nullable" | "hasDefault" | "noDefault";
|
|
145
|
+
export type TColumnType = "number" | "string" | "uuid" | "date" | "time" | "timestamp" | "bool";
|
|
146
|
+
export type TColumnArrayType = "number[]" | "string[]" | "uuid[]" | "date[]" | "time[]" | "timestamp[]" | "bool[]";
|
|
147
|
+
type TColumnBase = {
|
|
148
|
+
alias?: string,
|
|
149
|
+
type: TColumnType | TColumnArrayType,
|
|
150
|
+
attribute: TColumnAttribute,
|
|
151
|
+
default?: string,
|
|
152
|
+
comment?: string
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
type TStringColumn = TColumnBase & {
|
|
156
|
+
type: "string",
|
|
157
|
+
length: number
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
type TNonStringColumn = TColumnBase & {
|
|
161
|
+
type: Exclude<TColumnType, "string">,
|
|
162
|
+
length?: undefined
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
type TStringArrayColumn = TColumnBase & {
|
|
166
|
+
type: "string[]",
|
|
167
|
+
length: number,
|
|
168
|
+
attribute: Exclude<TColumnAttribute, "primary">
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
type TArrayColumn = TColumnBase & {
|
|
172
|
+
type: Exclude<TColumnArrayType, "string[]">,
|
|
173
|
+
length?: undefined,
|
|
174
|
+
attribute: Exclude<TColumnAttribute, "primary">
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export type TColumn = TStringColumn | TNonStringColumn | TStringArrayColumn | TArrayColumn;
|
|
178
|
+
|
|
179
|
+
export type TOperator = "=" | "!=" | ">" | ">=" | "<" | "<=" | "like" | "ilike" | "h2f_like" | "h2f_ilike" | "in" | "not in";
|
|
180
|
+
export type TColumnInfo = { model: TableModel, name: string }
|
|
181
|
+
export type TQuery = {sql: string, vars?: Array<any>};
|
|
182
|
+
export type TSelectExpression = { expression: string, alias: string }
|
|
183
|
+
export type TAggregateFuncType = 'sum' | 'avg' | 'max' | 'min' | 'count';
|
|
184
|
+
export type TCondition = string | {
|
|
185
|
+
l: string | TColumnInfo,
|
|
186
|
+
o: TOperator,
|
|
187
|
+
r: TSqlValue | Array<TSqlValue> | TColumnInfo
|
|
188
|
+
};
|
|
189
|
+
export type TNestedCondition = TCondition | ['AND' | 'OR', ...TNestedCondition[]] | TNestedCondition[];
|
|
190
|
+
export type TSortKeyword = 'desc' | 'asc';
|
|
191
|
+
export type TKeyFormat = 'snake' | 'lowerCamel';
|
|
192
|
+
export type TOption = {[key: string]: TSqlValue};
|
|
193
|
+
|
|
194
|
+
export class TableModel {
|
|
195
|
+
protected readonly dbName: string;
|
|
196
|
+
get DbName(): string;
|
|
197
|
+
protected readonly tableName: string;
|
|
198
|
+
get TableName(): string;
|
|
199
|
+
protected readonly tableDescription: string;
|
|
200
|
+
get TableDescription(): string;
|
|
201
|
+
protected readonly comment: string;
|
|
202
|
+
get Comment(): string;
|
|
203
|
+
protected readonly columns: { [key: string]: TColumn };
|
|
204
|
+
get Columns(): { [key: string]: TColumn };
|
|
205
|
+
protected readonly references: Array<{table: string, columns: Array<{target: string, ref: string}>}>;
|
|
206
|
+
get References(): Array<{table: string, columns: Array<{target: string, ref: string}>}>;
|
|
207
|
+
public GetReferences(columnName: string): Array<{table: string, columns: Array<{target: string, ref: string}>}>;
|
|
208
|
+
get TableAlias(): string;
|
|
209
|
+
public IsOutputLog: boolean;
|
|
210
|
+
public SortKeyword: TSortKeyword;
|
|
211
|
+
public Offset: number;
|
|
212
|
+
public Limit: number;
|
|
213
|
+
public PageCount: number;
|
|
214
|
+
set OffsetPage(value: number);
|
|
215
|
+
|
|
216
|
+
constructor(client: Pool);
|
|
217
|
+
constructor(client: Pool, tableAlias: string);
|
|
218
|
+
constructor(client: PoolClient);
|
|
219
|
+
constructor(client: PoolClient, tableAlias: string);
|
|
220
|
+
|
|
221
|
+
public select(): void;
|
|
222
|
+
public select(columls: Array<string | {name: string, alias?: string, func?: TAggregateFuncType}> | '*'): void;
|
|
223
|
+
public select(columls: Array<string | {name: string, alias?: string, func?: TAggregateFuncType}> | '*', model: TableModel): void;
|
|
224
|
+
public select(columls: Array<string | {name: string, alias?: string, func?: TAggregateFuncType}> | '*', keyFormat: TKeyFormat): void;
|
|
225
|
+
public select(columls: Array<string | {name: string, alias?: string, func?: TAggregateFuncType}> | '*', model: TableModel, keyFormat: TKeyFormat): void;
|
|
226
|
+
public select(expression: string, alias: string): void;
|
|
227
|
+
|
|
228
|
+
public join(joinType: 'left' | 'inner', joinModel: TableModel, conditions: Array<TNestedCondition>): void;
|
|
229
|
+
|
|
230
|
+
public where(expression: string): void;
|
|
231
|
+
public where(conditions: Array<TNestedCondition>): void;
|
|
232
|
+
public where(left: string, operator: TOperator, right: TSqlValue | Array<TSqlValue> | TColumnInfo | null): void;
|
|
233
|
+
public where(left: TColumnInfo, operator: TOperator, right: TSqlValue | Array<TSqlValue> | TColumnInfo | null): void;
|
|
234
|
+
|
|
235
|
+
public find<T = {[key: string]: any}>(pk: {[key: string]: any}, selectColumns: Array<string> | "*" | null, selectExpressions: Array<TSelectExpression> | null, keyFormat: TKeyFormat): Promise<T | null>;
|
|
236
|
+
public find<T = {[key: string]: any}>(pk: {[key: string]: any}, selectColumns: Array<string> | "*" | null, selectExpressions: Array<TSelectExpression> | null): Promise<T | null>;
|
|
237
|
+
public find<T = {[key: string]: any}>(pk: {[key: string]: any}, selectColumns: Array<string> | "*" | null): Promise<T | null>;
|
|
238
|
+
public find<T = {[key: string]: any}>(pk: {[key: string]: any}): Promise<T | null>;
|
|
239
|
+
|
|
240
|
+
public findId<T = {[key: string]: any}>(id: any, selectColumns: Array<string> | "*" | null, selectExpressions: Array<TSelectExpression> | null, keyFormat: TKeyFormat): Promise<T | null>;
|
|
241
|
+
public findId<T = {[key: string]: any}>(id: any, selectColumns: Array<string> | "*" | null, selectExpressions: Array<TSelectExpression> | null): Promise<T | null>;
|
|
242
|
+
public findId<T = {[key: string]: any}>(id: any, selectColumns: Array<string> | "*" | null): Promise<T | null>;
|
|
243
|
+
public findId<T = {[key: string]: any}>(id: any): Promise<T | null>;
|
|
244
|
+
|
|
245
|
+
protected readonly errorMessages: Record<TColumnType | 'length' | 'null' | 'notInput', string>
|
|
246
|
+
protected throwValidationError(code: string, message: string): never;
|
|
247
|
+
protected validateOptions(options: TOption, isInsert: boolean) : Promise<void>;
|
|
248
|
+
protected validateInsert(options: TOption) : Promise<void>;
|
|
249
|
+
protected validateUpdate(options: TOption) : Promise<void>;
|
|
250
|
+
protected validateUpdateId(id: any, options: TOption) : Promise<void>;
|
|
251
|
+
protected validateDelete() : Promise<void>;
|
|
252
|
+
protected validateDeleteId(id: any) : Promise<void>;
|
|
253
|
+
|
|
254
|
+
public executeInsert(options: TOption) : Promise<void>;
|
|
255
|
+
public executeUpdate(options: TOption) : Promise<number>;
|
|
256
|
+
public executeUpdateId(id: any, options: TOption) : Promise<void>;
|
|
257
|
+
public executeDelete() : Promise<number>;
|
|
258
|
+
public executeDeleteId(id: any) : Promise<void>;
|
|
259
|
+
|
|
260
|
+
public executeSelect<T = {[key: string]: any}>(): Promise<Array<T>>;
|
|
261
|
+
public executeSelectWithCount<T = any>(): Promise<{ datas: Array<T>, count: number, lastPage: number}>;
|
|
262
|
+
|
|
263
|
+
protected executeQuery(param1: string, vars?: Array<any>) : Promise<any>;
|
|
264
|
+
protected executeQuery(param1: TQuery) : Promise<any>;
|
|
265
|
+
|
|
266
|
+
public orderBy(column: string | TColumnInfo, sortKeyword: TSortKeyword): void;
|
|
267
|
+
public orderByList(column: string | TColumnInfo, list: Array<string | number | boolean | null>, sortKeyword: TSortKeyword): void;
|
|
268
|
+
public orderBySentence(query: string, sortKeyword: TSortKeyword): void;
|
|
269
|
+
|
|
270
|
+
public groupBy(column: string | TColumnInfo): void;
|
|
271
|
+
|
|
272
|
+
get ValidateClient(): ValidateClient;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function createTableDoc(models: Array<TableModel>, serviceName?: string): string;
|
|
276
|
+
export function migrate(migrates: Array<MigrateTable>, poolParam: {
|
|
277
|
+
host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
|
|
278
|
+
}): Promise<void>;
|
|
279
|
+
export function rollback(toNumber: number, poolParam: {
|
|
280
|
+
host: string, user: string, dbName: string, password: string, port?: number, isSsl?: boolean
|
|
281
|
+
}): Promise<void>;
|
|
282
|
+
export class MigrateTable {
|
|
283
|
+
protected readonly migrateSql: string;
|
|
284
|
+
protected readonly rollbackSql: string;
|
|
285
|
+
protected readonly addGrantTables: Array<string>;
|
|
286
|
+
protected readonly user: string;
|
|
287
|
+
|
|
288
|
+
constructor();
|
|
289
|
+
constructor(user: string);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class MigrateDatabase {
|
|
293
|
+
constructor(dbName: string, userName: string, pool: Pool);
|
|
294
|
+
|
|
295
|
+
get DbName(): string;
|
|
296
|
+
get UserName(): string;
|
|
297
|
+
get Password(): string | null;
|
|
298
|
+
|
|
299
|
+
public IsExistUser(): Promise<boolean>;
|
|
300
|
+
public CreateUser(password?: string): Promise<void>;
|
|
301
|
+
public IsExistDb(): Promise<boolean>;
|
|
302
|
+
public CreateDb(collateType?: string): Promise<void>;
|
|
303
|
+
public RollbackDbSql(): string;
|
|
304
|
+
public RollbackUserSql(otherUserName: string): string;
|
|
305
|
+
}
|
|
306
|
+
}
|