pg-mvc-service 2.0.43 → 2.0.44
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/index.d.ts +189 -0
- package/package.json +1 -5
- package/src/PoolManager.ts +48 -0
- package/src/Service.ts +276 -0
- package/src/Utils/DateTimeUtil.ts +146 -0
- package/src/Utils/NumberUtil.ts +23 -0
- package/src/Utils/StringUtil.ts +33 -0
- package/src/assets/favicon.ico +0 -0
- package/src/clients/AwsS3Client.ts +310 -0
- package/src/clients/Base64Client.ts +305 -0
- package/src/clients/EncryptClient.ts +100 -0
- package/src/clients/StringClient.ts +19 -0
- package/src/cron/BaseCron.ts +122 -0
- package/src/cron/CronExecuter.ts +34 -0
- package/src/cron/CronType.ts +25 -0
- package/src/documents/Swagger.ts +105 -0
- package/src/exceptions/Exception.ts +72 -0
- package/src/index.ts +23 -0
- package/src/models/ExpressionClient.ts +72 -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/UpdateExpression.ts +29 -0
- package/src/models/SqlUtils/ValidateValueUtil.ts +354 -0
- package/src/models/SqlUtils/WhereExpression.ts +421 -0
- package/src/models/TableDoc.ts +369 -0
- package/src/models/TableModel.ts +701 -0
- package/src/models/Type.ts +62 -0
- package/src/models/Utils/MessageUtil.ts +60 -0
- package/src/models/ValidateClient.ts +182 -0
- package/src/reqestResponse/ReqResType.ts +170 -0
- package/src/reqestResponse/RequestType.ts +918 -0
- package/src/reqestResponse/ResponseType.ts +420 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { TColumn, TColumnArrayType, TColumnType } from "../Type";
|
|
2
|
+
import DateTimeUtil from "../../Utils/DateTimeUtil";
|
|
3
|
+
import StringUtil from "../../Utils/StringUtil";
|
|
4
|
+
|
|
5
|
+
export default class ValidateValueUtil {
|
|
6
|
+
|
|
7
|
+
static validateId(columns: {[key: string]: TColumn}, id: any) {
|
|
8
|
+
if ('id' in columns === false) {
|
|
9
|
+
throw new Error("The 'id' is not set in Columns.");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const pkColumnsArray = Object.entries(columns).filter(([key, column]) => column.attribute === 'primary');
|
|
13
|
+
const pkColumns = Object.fromEntries(pkColumnsArray);
|
|
14
|
+
if ('id' in pkColumns === false) {
|
|
15
|
+
throw new Error("The 'id' is not set as a Primary Key.");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Object.keys(pkColumns).length > 1) {
|
|
19
|
+
throw new Error("This method cannot be used because there are other Primary Keys set besides 'id'.");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
ValidateValueUtil.validateValue(pkColumns['id'], id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static validateValue(column: TColumn, value: any) {
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
throw new Error(`The value is undefined.`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (value === null) {
|
|
32
|
+
if (column.attribute === 'nullable') {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error(`The specified column does not allow null values. (${column.attribute})`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// // 配列のチェック
|
|
40
|
+
// if (column.type.endsWith("[]")) {
|
|
41
|
+
// if (Array.isArray(value) === false) {
|
|
42
|
+
// throw new Error('The value must be an array.');
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// for (const v of value) {
|
|
46
|
+
// switch (column.type) {
|
|
47
|
+
// case "string[]":
|
|
48
|
+
// if (this.isErrorString(v)) {
|
|
49
|
+
// throw new Error('Please enter a value of type string.');
|
|
50
|
+
// }
|
|
51
|
+
// break;
|
|
52
|
+
// case "uuid[]":
|
|
53
|
+
// if (this.isErrorUUID(v)) {
|
|
54
|
+
// throw new Error('Please enter a value in UUID string format.');
|
|
55
|
+
// }
|
|
56
|
+
// break;
|
|
57
|
+
// case "date[]":
|
|
58
|
+
// if (this.isErrorDate(v)) {
|
|
59
|
+
// throw new Error('Please enter a valid date in "YYYY-MM-DD" or "YYYY-MM-DD hh:mi:ss" format or as a Date type.');
|
|
60
|
+
// }
|
|
61
|
+
// break;
|
|
62
|
+
// case "time[]":
|
|
63
|
+
// if (this.isErrorTime(v)) {
|
|
64
|
+
// throw new Error('Please enter a valid time in "hh:mi" or "hh:mi:ss" format.');
|
|
65
|
+
// }
|
|
66
|
+
// break;
|
|
67
|
+
// case "timestamp[]":
|
|
68
|
+
// if (this.isErrorTimestamp(v)) {
|
|
69
|
+
// throw new Error('Please enter a valid timestamp in "YYYY-MM-DD", "YYYY-MM-DD hh:mi:ss", or "YYYY-MM-DDThh:mi:ss" format or as a Date type.');
|
|
70
|
+
// }
|
|
71
|
+
// break;
|
|
72
|
+
// case "number[]":
|
|
73
|
+
// if (this.isErrorNumber(v)) {
|
|
74
|
+
// throw new Error('Please enter a value of type number or a string of half-width digits.');
|
|
75
|
+
// }
|
|
76
|
+
// break;
|
|
77
|
+
// case "bool[]":
|
|
78
|
+
// if (this.isErrorBool(v)) {
|
|
79
|
+
// throw new Error('Please enter a value of type bool, or a string "true" or "false", or a number 0 or 1.');
|
|
80
|
+
// }
|
|
81
|
+
// break;
|
|
82
|
+
// default:
|
|
83
|
+
// throw new Error(`The specified ColumnTypeEnum does not exist. (${column.type})`);
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
// if (v === true) {
|
|
87
|
+
// return true;
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// return false;
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
switch (column.type) {
|
|
95
|
+
case "string":
|
|
96
|
+
if (this.isErrorString(value)) {
|
|
97
|
+
throw new Error('Please enter a value of type string or number.');
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "uuid":
|
|
101
|
+
if (this.isErrorUUID(value)) {
|
|
102
|
+
throw new Error('Please enter a value in UUID string format.');
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
case "date":
|
|
106
|
+
if (this.isErrorDate(value)) {
|
|
107
|
+
throw new Error('Please enter a valid date in "YYYY-MM-DD" or "YYYY-MM-DD hh:mi:ss" format or as a Date type.');
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case "time":
|
|
111
|
+
if (this.isErrorTime(value)) {
|
|
112
|
+
throw new Error('Please enter a valid time in "hh:mi" or "hh:mi:ss" format.');
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case "timestamp":
|
|
116
|
+
if (this.isErrorTimestamp(value)) {
|
|
117
|
+
throw new Error('Please enter a valid timestamp in "YYYY-MM-DD", "YYYY-MM-DD hh:mi:ss", or "YYYY-MM-DDThh:mi:ss" format or as a Date type.');
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case "integer":
|
|
121
|
+
if (this.isErrorNumber(value)) {
|
|
122
|
+
throw new Error('Please enter a value of type number or a string of half-width digits.');
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case "bool":
|
|
126
|
+
if (this.isErrorBool(value)) {
|
|
127
|
+
throw new Error('Please enter a value of type bool, or a string "true" or "false", or a number 0 or 1.');
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "json":
|
|
131
|
+
case "jsonb":
|
|
132
|
+
if (this.isErrorJson(value)) {
|
|
133
|
+
throw new Error('Please enter a value as an Object or JSON string.');
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static isErrorValue(columnType: TColumnType | TColumnArrayType, value: any) {
|
|
140
|
+
|
|
141
|
+
// 配列のチェック
|
|
142
|
+
if (columnType.endsWith("[]")) {
|
|
143
|
+
if (Array.isArray(value) === false) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (const v of value) {
|
|
148
|
+
let isError = false;
|
|
149
|
+
switch (columnType) {
|
|
150
|
+
case "string[]":
|
|
151
|
+
isError = this.isErrorString(v);
|
|
152
|
+
break;
|
|
153
|
+
case "uuid[]":
|
|
154
|
+
isError = this.isErrorUUID(v);
|
|
155
|
+
break;
|
|
156
|
+
case "date[]":
|
|
157
|
+
isError = this.isErrorDate(v);
|
|
158
|
+
break;
|
|
159
|
+
case "time[]":
|
|
160
|
+
isError = this.isErrorTime(v);
|
|
161
|
+
break;
|
|
162
|
+
case "timestamp[]":
|
|
163
|
+
isError = this.isErrorTimestamp(v);
|
|
164
|
+
break;
|
|
165
|
+
case "integer[]": // TODO: ここ最大最小のチェックもしないと
|
|
166
|
+
case "real[]": // TODO: ここ最大最小 + 桁数のチェックもしないと
|
|
167
|
+
isError = this.isErrorNumber(v);
|
|
168
|
+
break;
|
|
169
|
+
case "bool[]":
|
|
170
|
+
isError = this.isErrorBool(v);
|
|
171
|
+
break;
|
|
172
|
+
case "json[]":
|
|
173
|
+
case "jsonb[]":
|
|
174
|
+
isError = this.isErrorJson(v);
|
|
175
|
+
break;
|
|
176
|
+
default:
|
|
177
|
+
throw new Error(`The specified ColumnTypeEnum does not exist. (${columnType})`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (isError) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
switch (columnType) {
|
|
189
|
+
case "string":
|
|
190
|
+
return this.isErrorString(value);
|
|
191
|
+
case "uuid":
|
|
192
|
+
return this.isErrorUUID(value);
|
|
193
|
+
case "date":
|
|
194
|
+
return this.isErrorDate(value);
|
|
195
|
+
case "time":
|
|
196
|
+
return this.isErrorTime(value);
|
|
197
|
+
case "timestamp":
|
|
198
|
+
return this.isErrorTimestamp(value);
|
|
199
|
+
case "integer": // TODO: ここ最大最小のチェックもしないと
|
|
200
|
+
case "real": // TODO: ここ最大最小 + 桁数のチェックもしないと
|
|
201
|
+
return this.isErrorNumber(value);
|
|
202
|
+
case "bool":
|
|
203
|
+
return this.isErrorBool(value);
|
|
204
|
+
case "json":
|
|
205
|
+
case "jsonb":
|
|
206
|
+
return this.isErrorJson(value);
|
|
207
|
+
default:
|
|
208
|
+
throw new Error(`The specified ColumnTypeEnum does not exist. (${columnType})`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static isErrorString(value: any): boolean {
|
|
213
|
+
if (typeof(value) == 'string' || typeof(value) == 'number') {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static isErrorInteger(value: any): boolean {
|
|
220
|
+
let numberValue: number;
|
|
221
|
+
if (typeof value === 'string') {
|
|
222
|
+
if (value.trim() === "" || isNaN(Number(value))) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
numberValue = Number(value);
|
|
227
|
+
} else if (typeof value === 'number') {
|
|
228
|
+
numberValue = value;
|
|
229
|
+
} else {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (Number.isInteger(numberValue) === false) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (numberValue < -2147483648 || numberValue > 2147483647) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static isErrorReal(value: any): boolean {
|
|
245
|
+
let numberValue: number;
|
|
246
|
+
if (typeof value === 'string') {
|
|
247
|
+
if (value.trim() === "" || isNaN(Number(value))) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
numberValue = Number(value);
|
|
252
|
+
} else if (typeof value === 'number') {
|
|
253
|
+
numberValue = value;
|
|
254
|
+
} else {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 特殊値チェック
|
|
259
|
+
if (isFinite(numberValue) === false) {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 範囲チェック(real型の範囲)
|
|
264
|
+
if (numberValue < -3.4e38 || numberValue > 3.4e38) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
static isErrorNumber(value: any): boolean {
|
|
272
|
+
if (typeof value === 'string') {
|
|
273
|
+
if (value.trim() === "" || isNaN(Number(value))) {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
} else if (typeof value === 'number') {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static isErrorBool(value: any): boolean {
|
|
285
|
+
switch (typeof(value)) {
|
|
286
|
+
case 'string':
|
|
287
|
+
return value !== 'true' && value !== 'false';
|
|
288
|
+
case 'number':
|
|
289
|
+
return value !== 0 && value !== 1;
|
|
290
|
+
case 'boolean':
|
|
291
|
+
return false;
|
|
292
|
+
default:
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static isErrorUUID(value: any) {
|
|
298
|
+
return StringUtil.isUUID(value) === false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
static isErrorDate(value: any): boolean {
|
|
302
|
+
if (value instanceof Date) {
|
|
303
|
+
return false;
|
|
304
|
+
} else if (DateTimeUtil.isYYYYMMDD(value)) {
|
|
305
|
+
return false;
|
|
306
|
+
} else if (DateTimeUtil.isYYYYMMDDhhmiss(value)) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
static isErrorTimestamp(value: any): boolean {
|
|
314
|
+
if (value instanceof Date) {
|
|
315
|
+
return false
|
|
316
|
+
} else if (DateTimeUtil.isYYYYMMDD(`${value}`)) {
|
|
317
|
+
return false;
|
|
318
|
+
} else if (DateTimeUtil.isYYYYMMDDhhmiss(value)) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
static isErrorTime(value: any): boolean {
|
|
326
|
+
if (value instanceof Date) {
|
|
327
|
+
return false
|
|
328
|
+
}
|
|
329
|
+
if (DateTimeUtil.isHHMMSS(value)) {
|
|
330
|
+
return false;
|
|
331
|
+
} else if (DateTimeUtil.isHHMM(value)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
static isErrorJson(value: any): boolean {
|
|
339
|
+
if (typeof value === 'object' && value !== null && Array.isArray(value) === false) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (typeof value === 'string') {
|
|
344
|
+
try {
|
|
345
|
+
JSON.parse(value);
|
|
346
|
+
return false;
|
|
347
|
+
} catch {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
}
|