pg-mvc-service 2.1.0 → 2.1.1
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/PoolManager.d.ts +7 -0
- package/dist/PoolManager.d.ts.map +1 -0
- package/dist/Service.d.ts +82 -0
- package/dist/Service.d.ts.map +1 -0
- package/dist/Utils/DateTimeUtil.d.ts +58 -0
- package/dist/Utils/DateTimeUtil.d.ts.map +1 -0
- package/dist/Utils/NumberUtil.d.ts +10 -0
- package/dist/Utils/NumberUtil.d.ts.map +1 -0
- package/dist/Utils/StringUtil.d.ts +16 -0
- package/dist/Utils/StringUtil.d.ts.map +1 -0
- package/dist/clients/AwsS3Client.d.ts +35 -0
- package/dist/clients/AwsS3Client.d.ts.map +1 -0
- package/dist/clients/Base64Client.d.ts +31 -0
- package/dist/clients/Base64Client.d.ts.map +1 -0
- package/dist/clients/EncryptClient.d.ts +18 -0
- package/dist/clients/EncryptClient.d.ts.map +1 -0
- package/dist/clients/StringClient.d.ts +6 -0
- package/dist/clients/StringClient.d.ts.map +1 -0
- package/dist/cron/BaseCron.d.ts +35 -0
- package/dist/cron/BaseCron.d.ts.map +1 -0
- package/dist/cron/CronExecuter.d.ts +2 -0
- package/dist/cron/CronExecuter.d.ts.map +1 -0
- package/dist/cron/CronType.d.ts +6 -0
- package/dist/cron/CronType.d.ts.map +1 -0
- package/dist/documents/Swagger.d.ts +10 -0
- package/dist/documents/Swagger.d.ts.map +1 -0
- package/dist/exceptions/Exception.d.ts +31 -0
- package/dist/exceptions/Exception.d.ts.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +2 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/models/ExpressionClient.d.ts +12 -0
- package/dist/models/ExpressionClient.d.ts.map +1 -0
- package/dist/models/MigrateDatabase.d.ts +19 -0
- package/dist/models/MigrateDatabase.d.ts.map +1 -0
- package/dist/models/MigrateRollback.d.ts +18 -0
- package/dist/models/MigrateRollback.d.ts.map +1 -0
- package/dist/models/MigrateTable.d.ts +13 -0
- package/dist/models/MigrateTable.d.ts.map +1 -0
- package/dist/models/SqlUtils/SelectExpression.d.ts +31 -0
- package/dist/models/SqlUtils/SelectExpression.d.ts.map +1 -0
- package/dist/models/SqlUtils/UpdateExpression.d.ts +8 -0
- package/dist/models/SqlUtils/UpdateExpression.d.ts.map +1 -0
- package/dist/models/SqlUtils/ValidateValueUtil.d.ts +19 -0
- package/dist/models/SqlUtils/ValidateValueUtil.d.ts.map +1 -0
- package/dist/models/SqlUtils/WhereExpression.d.ts +30 -0
- package/dist/models/SqlUtils/WhereExpression.d.ts.map +1 -0
- package/dist/models/TableDoc.d.ts +3 -0
- package/dist/models/TableDoc.d.ts.map +1 -0
- package/dist/models/TableModel.d.ts +196 -0
- package/dist/models/TableModel.d.ts.map +1 -0
- package/dist/models/Type.d.ts +64 -0
- package/dist/models/Type.d.ts.map +1 -0
- package/dist/models/Utils/MessageUtil.d.ts +7 -0
- package/dist/models/Utils/MessageUtil.d.ts.map +1 -0
- package/dist/models/ValidateClient.d.ts +27 -0
- package/dist/models/ValidateClient.d.ts.map +1 -0
- package/dist/reqestResponse/ReqResType.d.ts +113 -0
- package/dist/reqestResponse/ReqResType.d.ts.map +1 -0
- package/dist/reqestResponse/RequestType.d.ts +247 -0
- package/dist/reqestResponse/RequestType.d.ts.map +1 -0
- package/dist/reqestResponse/ResponseType.d.ts +85 -0
- package/dist/reqestResponse/ResponseType.d.ts.map +1 -0
- package/package.json +7 -1
- package/index.d.ts +0 -192
- package/src/PoolManager.ts +0 -48
- package/src/Service.ts +0 -307
- package/src/Utils/DateTimeUtil.ts +0 -146
- package/src/Utils/NumberUtil.ts +0 -23
- package/src/Utils/StringUtil.ts +0 -33
- package/src/clients/AwsS3Client.ts +0 -310
- package/src/clients/Base64Client.ts +0 -305
- package/src/clients/EncryptClient.ts +0 -100
- package/src/clients/StringClient.ts +0 -19
- package/src/cron/BaseCron.ts +0 -122
- package/src/cron/CronExecuter.ts +0 -34
- package/src/cron/CronType.ts +0 -25
- package/src/documents/Swagger.ts +0 -106
- package/src/exceptions/Exception.ts +0 -72
- package/src/models/ExpressionClient.ts +0 -72
- package/src/models/MigrateDatabase.ts +0 -135
- package/src/models/MigrateRollback.ts +0 -151
- package/src/models/MigrateTable.ts +0 -56
- package/src/models/SqlUtils/SelectExpression.ts +0 -102
- package/src/models/SqlUtils/UpdateExpression.ts +0 -29
- package/src/models/SqlUtils/ValidateValueUtil.ts +0 -354
- package/src/models/SqlUtils/WhereExpression.ts +0 -455
- package/src/models/TableDoc.ts +0 -372
- package/src/models/TableModel.ts +0 -749
- package/src/models/Type.ts +0 -62
- package/src/models/Utils/MessageUtil.ts +0 -60
- package/src/models/ValidateClient.ts +0 -182
- package/src/reqestResponse/ReqResType.ts +0 -241
- package/src/reqestResponse/RequestType.ts +0 -1619
- package/src/reqestResponse/ResponseType.ts +0 -549
- package/tsconfig.json +0 -14
package/src/models/Type.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { TableModel } from "./TableModel";
|
|
2
|
-
|
|
3
|
-
// column type
|
|
4
|
-
export type TColumnAttribute = "primary" | "nullable" | "hasDefault" | "noDefault";
|
|
5
|
-
export type TColumnType = "integer" | "real" | "string" | "uuid" | "date" | "time" | "timestamp" | "bool" | "json" | "jsonb";
|
|
6
|
-
export type TColumnArrayType = "integer[]" | "real[]" | "string[]" | "uuid[]" | "date[]" | "time[]" | "timestamp[]" | "bool[]" | "json[]" | "jsonb[]";
|
|
7
|
-
type TColumnBase = {
|
|
8
|
-
alias?: string,
|
|
9
|
-
type: TColumnType | TColumnArrayType,
|
|
10
|
-
attribute: TColumnAttribute,
|
|
11
|
-
default?: string,
|
|
12
|
-
comment?: string
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type TStringColumn = TColumnBase & {
|
|
16
|
-
type: "string",
|
|
17
|
-
length: number,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type TJsonColumn = TColumnBase & {
|
|
21
|
-
type: "json" | "jsonb"
|
|
22
|
-
length?: undefined,
|
|
23
|
-
attribute: Exclude<TColumnAttribute, "primary">
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type TBasicColumn = TColumnBase & {
|
|
27
|
-
type: Exclude<TColumnType, "string">,
|
|
28
|
-
length?: undefined,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type TStringArrayColumn = TColumnBase & {
|
|
32
|
-
type: "string[]",
|
|
33
|
-
length: number,
|
|
34
|
-
attribute: Exclude<TColumnAttribute, "primary">
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type TArrayColumn = TColumnBase & {
|
|
38
|
-
type: Exclude<TColumnArrayType, "string[]">,
|
|
39
|
-
length?: undefined,
|
|
40
|
-
attribute: Exclude<TColumnAttribute, "primary">
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type TColumn = TStringColumn | TJsonColumn | TBasicColumn | TStringArrayColumn | TArrayColumn;
|
|
44
|
-
export type TColumnDetail = TColumn & {
|
|
45
|
-
columnName: string,
|
|
46
|
-
tableName: string,
|
|
47
|
-
expression: string
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type TOperator = "=" | "!=" | ">" | ">=" | "<" | "<=" | "like" | "ilike" | "h2f_like" | "h2f_ilike" | "in" | "not in" | "any" | "@>" | "&&";
|
|
51
|
-
export type TColumnInfo = { model: TableModel, name: string }
|
|
52
|
-
export type TQuery = {expression: string, vars?: Array<any>};
|
|
53
|
-
export type TSelectExpression = { expression: string, alias: string }
|
|
54
|
-
export type TAggregateFuncType = 'sum' | 'avg' | 'max' | 'min' | 'count';
|
|
55
|
-
export type TCondition = string | {
|
|
56
|
-
l: string | TColumnInfo,
|
|
57
|
-
o: TOperator,
|
|
58
|
-
r: any | TColumnInfo
|
|
59
|
-
};
|
|
60
|
-
export type TNestedCondition = TCondition | ['AND' | 'OR', ...TNestedCondition[]] | TNestedCondition[];
|
|
61
|
-
export type TSortKeyword = 'desc' | 'asc';
|
|
62
|
-
export type TKeyFormat = 'snake' | 'lowerCamel';
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { TColumnArrayType, TColumnType } from "../Type"
|
|
2
|
-
|
|
3
|
-
export type TOptionErrorMessage = Record<TColumnType | TColumnArrayType | 'length' | 'null' | 'notInput' | 'fk' | 'find', string>;
|
|
4
|
-
|
|
5
|
-
export default class MessageUtil {
|
|
6
|
-
public static readonly optionErrorMessageEnglish: TOptionErrorMessage = {
|
|
7
|
-
'string': '{name} should be entered as a string or number type.',
|
|
8
|
-
'string[]': '{name} should be entered as an array of string or number types.',
|
|
9
|
-
'uuid': '{name} should be entered as a UUID.',
|
|
10
|
-
'uuid[]': '{name} should be entered as an array of UUIDs.',
|
|
11
|
-
'integer': '{name} should be entered as a number.',
|
|
12
|
-
'integer[]': '{name} should be entered as an array of numbers.',
|
|
13
|
-
'real': '{name} should be entered as a number.',
|
|
14
|
-
'real[]': '{name} should be entered as an array of numbers.',
|
|
15
|
-
'bool': '{name} should be entered as a bool type, "true", "false", 0, or 1.',
|
|
16
|
-
'bool[]': '{name} should be entered as an array of bool types, "true", "false", 0, or 1.',
|
|
17
|
-
'date': '{name} should be entered in "YYYY-MM-DD" or "YYYY-MM-DD hh:mi:ss" format or as a Date type.',
|
|
18
|
-
'date[]': '{name} should be entered as an array of dates in "YYYY-MM-DD" or "YYYY-MM-DD hh:mi:ss" format or as Date types.',
|
|
19
|
-
'time': '{name} should be entered in "hh:mi" format or "hh:mi:ss" format.',
|
|
20
|
-
'time[]': '{name} should be entered as an array of times in "hh:mi" format or "hh:mi:ss" format.',
|
|
21
|
-
'timestamp': '{name} should be entered in "YYYY-MM-DD" format, "YYYY-MM-DD hh:mi:ss" format, "YYYY-MM-DDThh:mi:ss" format, or as a Date type.',
|
|
22
|
-
'timestamp[]': '{name} should be entered as an array of timestamps in "YYYY-MM-DD" format, "YYYY-MM-DD hh:mi:ss" format, "YYYY-MM-DDThh:mi:ss" format, or as Date types.',
|
|
23
|
-
'json': '{name} should be entered as an Object or JSON string.',
|
|
24
|
-
'json[]': '{name} should be entered as an array of Objects or JSON strings.',
|
|
25
|
-
'jsonb': '{name} should be entered as an Object or JSON string.',
|
|
26
|
-
'jsonb[]': '{name} should be entered as an array of Objects or JSON strings.',
|
|
27
|
-
'length': '{name} should be entered within {length} characters.',
|
|
28
|
-
'null': '{name} is not allowed to be null.',
|
|
29
|
-
'notInput': 'Please enter {name}.',
|
|
30
|
-
'fk': 'The value of {name} does not exist in the table.',
|
|
31
|
-
'find': 'The specified data does not exist in the table. ({pks})'
|
|
32
|
-
}
|
|
33
|
-
public static readonly optionErrorMessageJapan: TOptionErrorMessage = {
|
|
34
|
-
'string': '{name}はstringかnumberで入力してください。',
|
|
35
|
-
'string[]': '{name}はstringかnumberの配列で入力してください。',
|
|
36
|
-
'uuid': '{name}はuuidで入力してください。',
|
|
37
|
-
'uuid[]': '{name}はuuidの配列で入力してください。',
|
|
38
|
-
'integer': '{name}はnumberか半角数字のstring型で入力してください。',
|
|
39
|
-
'integer[]': '{name}はnumberか半角数字のstring型の配列で入力してください。',
|
|
40
|
-
'real': '{name}はnumberか半角数字のstring型で入力してください。',
|
|
41
|
-
'real[]': '{name}はnumberか半角数字のstring型の配列で入力してください。',
|
|
42
|
-
'bool': '{name}はbool型、"true"、"false"、0、または1で入力してください。',
|
|
43
|
-
'bool[]': '{name}はbool型、"true"、"false"、0、または1の配列で入力してください。',
|
|
44
|
-
'date': '{name}は"YYYY-MM-DD"形式、"YYYY-MM-DD hh:mi:ss"形式、またはDate型で入力してください。',
|
|
45
|
-
'date[]': '{name}は"YYYY-MM-DD"形式、"YYYY-MM-DD hh:mi:ss"形式、またはDate型の配列で入力してください。',
|
|
46
|
-
'time': '{name}は"hh:mi"形式または"hh:mi:ss"形式で入力してください。',
|
|
47
|
-
'time[]': '{name}は"hh:mi"形式または"hh:mi:ss"形式の配列で入力してください。',
|
|
48
|
-
'timestamp': '{name}は"YYYY-MM-DD"形式、"YYYY-MM-DD hh:mi:ss"形式、"YYYY-MM-DDThh:mi:ss"形式、またはDate型で入力してください。',
|
|
49
|
-
'timestamp[]': '{name}は"YYYY-MM-DD"形式、"YYYY-MM-DD hh:mi:ss"形式、"YYYY-MM-DDThh:mi:ss"形式、またはDate型の配列で入力してください。',
|
|
50
|
-
'json': '{name}はObject形またはJSON文字列で入力してください。',
|
|
51
|
-
'json[]': '{name}はObject形またはJSON文字列の配列で入力してください。',
|
|
52
|
-
'jsonb': '{name}はObject形またはJSON文字列で入力してください。',
|
|
53
|
-
'jsonb[]': '{name}はObject形またはJSON文字列の配列で入力してください。',
|
|
54
|
-
'length': '{name}は{length}文字以内で入力してください。',
|
|
55
|
-
'null': '{name}はnullを許可されていません。',
|
|
56
|
-
'notInput': '{name}を入力してください。',
|
|
57
|
-
'fk': '{name}の値がテーブルに存在しません。',
|
|
58
|
-
'find': '指定されたデータはテーブルに存在しません。({pks})'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { UnprocessableException } from "../exceptions/Exception";
|
|
2
|
-
import { TableModel } from "./TableModel";
|
|
3
|
-
|
|
4
|
-
type TError = {code?: string; message?: string;};
|
|
5
|
-
|
|
6
|
-
export default class ValidateClient {
|
|
7
|
-
private model: TableModel;
|
|
8
|
-
constructor(model: TableModel) {
|
|
9
|
-
this.model = model;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public tryDate(value: any, isExcludeTime: boolean = false): Date | false {
|
|
13
|
-
if (value instanceof Date) {
|
|
14
|
-
return value;
|
|
15
|
-
} else if (typeof value !== 'string') {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const [datePart, timePart] = value.split(' ');
|
|
21
|
-
const [year, month, day] = datePart.split('-').map(Number);
|
|
22
|
-
let [hours, minutes, seconds] = [0, 0, 0];
|
|
23
|
-
if (timePart !== undefined && isExcludeTime === false) {
|
|
24
|
-
[hours, minutes, seconds] = timePart.split(':').map(Number);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 日付の整合性チェック
|
|
28
|
-
const date = new Date(year, month - 1, day, hours, minutes, seconds);
|
|
29
|
-
if (date.getFullYear() !== year ||
|
|
30
|
-
date.getMonth() + 1 !== month ||
|
|
31
|
-
date.getDate() !== day ||
|
|
32
|
-
date.getHours() !== hours ||
|
|
33
|
-
date.getMinutes() !== minutes ||
|
|
34
|
-
date.getSeconds() !== seconds
|
|
35
|
-
) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return date;
|
|
40
|
-
} catch (ex) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public validateInList(options: {[key: string]: any}, key: string, list: Array<number | string | boolean>, error?: TError) {
|
|
46
|
-
const column = this.model.getColumn(key);
|
|
47
|
-
const value = options[key];
|
|
48
|
-
if (value === undefined || value === null || value === "") {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (list.includes(value) === false) {
|
|
53
|
-
const code = error?.code ?? "000";
|
|
54
|
-
let message = error?.message;
|
|
55
|
-
if (message === undefined) {
|
|
56
|
-
message = `{column} must be one of the items in the {list}. ({value})`;
|
|
57
|
-
}
|
|
58
|
-
message = message.replace('{column}', column.alias ?? column.columnName);
|
|
59
|
-
message = message.replace('{value}', value.toString());
|
|
60
|
-
message = message.replace('{list}', list.join(', '));
|
|
61
|
-
throw new UnprocessableException(code, message);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public validateUnderNow(options: {[key: string]: any}, key: string, error?: TError) {
|
|
66
|
-
const column = this.model.getColumn(key);
|
|
67
|
-
const value = options[key];
|
|
68
|
-
if (value === undefined || value === null || value === "") {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const date = this.tryDate(value);
|
|
73
|
-
if (date === false) {
|
|
74
|
-
throw new Error("The value must be a Date or a valid date string when using validateUnderNow.");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const now = new Date();
|
|
78
|
-
if (date > now) {
|
|
79
|
-
const code = error?.code ?? "000";
|
|
80
|
-
let message = error?.message;
|
|
81
|
-
if (message === undefined) {
|
|
82
|
-
message = `{column} should be entered on or before now. ({value})`;
|
|
83
|
-
}
|
|
84
|
-
message = message.replace('{column}', column.alias ?? column.columnName);
|
|
85
|
-
message = message.replace('{value}', value.toString());
|
|
86
|
-
throw new UnprocessableException(code, message);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public validateUnderToday(options: {[key: string]: any}, key: string, isErrorToday: boolean, error?: TError): void {
|
|
91
|
-
const column = this.model.getColumn(key);
|
|
92
|
-
const value = options[key];
|
|
93
|
-
if (value === undefined || value === null || value === "") {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const date = this.tryDate(value);
|
|
98
|
-
if (date === false) {
|
|
99
|
-
throw new Error("The value must be a Date or a valid date string when using validateUnderToday.");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
date.setHours(0);
|
|
103
|
-
date.setMinutes(0);
|
|
104
|
-
date.setSeconds(0);
|
|
105
|
-
date.setMilliseconds(0);
|
|
106
|
-
|
|
107
|
-
const today = new Date();
|
|
108
|
-
today.setHours(0);
|
|
109
|
-
today.setMinutes(0);
|
|
110
|
-
today.setSeconds(0);
|
|
111
|
-
today.setMilliseconds(isErrorToday ? 0 : 1);
|
|
112
|
-
|
|
113
|
-
if (date >= today) {
|
|
114
|
-
const code = error?.code ?? "000";
|
|
115
|
-
let message = error?.message;
|
|
116
|
-
if (message === undefined) {
|
|
117
|
-
if (isErrorToday) {
|
|
118
|
-
message = `{column} should be entered before today. ({value})`;
|
|
119
|
-
} else {
|
|
120
|
-
message = `{column} should be entered on or before today. ({value})`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
message = message.replace('{column}', column.alias ?? column.columnName);
|
|
124
|
-
message = message.replace('{value}', value.toString());
|
|
125
|
-
throw new UnprocessableException(code, message);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public validateRegExp(options: {[key: string]: any}, key: string, regExp: RegExp | string, error?: TError): void {
|
|
130
|
-
const column = this.model.getColumn(key);
|
|
131
|
-
const value = options[key];
|
|
132
|
-
if (value === undefined || value === null || value === "") {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (typeof value !== 'string') {
|
|
137
|
-
throw new Error("The value must be a string when using validateStringRegExp.");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (typeof regExp === 'string') {
|
|
141
|
-
regExp = new RegExp(regExp);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (regExp.test(value) === false) {
|
|
145
|
-
const code = error?.code ?? "000";
|
|
146
|
-
let message = error?.message;
|
|
147
|
-
if (message === undefined) {
|
|
148
|
-
message = `{column} is invalid. ({value})`;
|
|
149
|
-
}
|
|
150
|
-
message = message.replace('{column}', column.alias ?? column.columnName);
|
|
151
|
-
message = message.replace('{value}', value.toString());
|
|
152
|
-
throw new UnprocessableException(code, message);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public validatePositiveNumber(options: {[key: string]: any}, key: string, error?: TError) {
|
|
157
|
-
const column = this.model.getColumn(key);
|
|
158
|
-
const value = options[key];
|
|
159
|
-
if (value === undefined || value === null || value === "") {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
164
|
-
throw new Error("The value must be a valid number string or number when using validatePositiveNumber.");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isNaN(Number(value))) {
|
|
168
|
-
throw new Error("The value must be a valid number string or number when using validatePositiveNumber.");
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (Number(value) <= 0) {
|
|
172
|
-
const code = error?.code ?? "000";
|
|
173
|
-
let message = error?.message;
|
|
174
|
-
if (message === undefined) {
|
|
175
|
-
message = `Please enter a value greater than 0 for {column}. ({value})`;
|
|
176
|
-
}
|
|
177
|
-
message = message.replace('{column}', column.alias ?? column.columnName);
|
|
178
|
-
message = message.replace('{value}', value.toString());
|
|
179
|
-
throw new UnprocessableException(code, message);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
type PrimitiveKeyType =
|
|
2
|
-
'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
|
|
3
|
-
'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
|
|
4
|
-
|
|
5
|
-
export type PrimitiveType = {
|
|
6
|
-
type: PrimitiveKeyType;
|
|
7
|
-
description?: string;
|
|
8
|
-
};
|
|
9
|
-
export type StringType = {
|
|
10
|
-
type: 'string' | 'string?';
|
|
11
|
-
description?: string;
|
|
12
|
-
maxLength?: number;
|
|
13
|
-
regExp?: RegExp;
|
|
14
|
-
};
|
|
15
|
-
export type NumberType = {
|
|
16
|
-
type: 'number' | 'number?';
|
|
17
|
-
description?: string;
|
|
18
|
-
max?: number;
|
|
19
|
-
min?: number;
|
|
20
|
-
};
|
|
21
|
-
export type ObjectType = {
|
|
22
|
-
type: 'object' | 'object?';
|
|
23
|
-
description?: string;
|
|
24
|
-
properties: {
|
|
25
|
-
[key: string]: PropertyType;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export type ArrayType = {
|
|
29
|
-
type: 'array' | 'array?';
|
|
30
|
-
description?: string;
|
|
31
|
-
item: PropertyType;
|
|
32
|
-
};
|
|
33
|
-
export type MapType = {
|
|
34
|
-
type: 'map' | 'map?';
|
|
35
|
-
description?: string;
|
|
36
|
-
mapType: 'string' | 'number' | 'bool';
|
|
37
|
-
};
|
|
38
|
-
export type EnumType = {
|
|
39
|
-
type: 'enum' | 'enum?';
|
|
40
|
-
description?: string;
|
|
41
|
-
enumType: 'string' | 'number' | 'string?' | 'number?';
|
|
42
|
-
enums: {[key: string | number]: string};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type PropertyType = PrimitiveType | StringType | NumberType | ObjectType | ArrayType | EnumType | MapType;
|
|
46
|
-
|
|
47
|
-
export default class ReqResType {
|
|
48
|
-
|
|
49
|
-
protected properties: { [key: string]: PropertyType; } = {};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Retrieve property type data
|
|
53
|
-
* プロパティ型のデータを取得
|
|
54
|
-
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
55
|
-
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
56
|
-
*/
|
|
57
|
-
protected getProperty(keys: Array<string | number>) {
|
|
58
|
-
if (keys.length === 0) {
|
|
59
|
-
throw new Error(`getPropertyメソッドでは1以上のkeysからしか入力を受け付けない。`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const firstKey = keys[0];
|
|
63
|
-
let property = this.properties[firstKey];
|
|
64
|
-
|
|
65
|
-
for (let i = 1;i < keys.length;i++) {
|
|
66
|
-
const key = keys[i];
|
|
67
|
-
if (typeof key === 'number') {
|
|
68
|
-
if (property.type === 'array' || property.type === 'array?') {
|
|
69
|
-
property = property.item;
|
|
70
|
-
continue;
|
|
71
|
-
} else {
|
|
72
|
-
throw new Error(`getPropertyでnumber型のINPUTにも関わらず、array以外のtypeの場合のエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
switch (property.type) {
|
|
77
|
-
case 'array':
|
|
78
|
-
case 'array?':
|
|
79
|
-
if (typeof key !== 'number') {
|
|
80
|
-
throw new Error(`getPropertyでnumber型のINPUTで、array以外の場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
81
|
-
}
|
|
82
|
-
property = property.item;
|
|
83
|
-
continue;
|
|
84
|
-
case 'object':
|
|
85
|
-
case 'object?':
|
|
86
|
-
if (typeof key !== 'string') {
|
|
87
|
-
throw new Error(`getPropertyでnumber型のINPUTで、arrayの場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
88
|
-
}
|
|
89
|
-
property = property.properties[key];
|
|
90
|
-
continue;
|
|
91
|
-
default:
|
|
92
|
-
throw new Error(`getPropertyでarray,object以外のtypeを読み込もうとしている。\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
93
|
-
// property = property[key];
|
|
94
|
-
// continue;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return property;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Checks if the value is a valid date-time format
|
|
103
|
-
* 値が有効な日付時間形式かどうかを確認します
|
|
104
|
-
* @param value - 検証する値, The value to be validated
|
|
105
|
-
* @returns {boolean} - 値が有効な日付時間形式であるかどうか, Whether the value is a valid date-time format
|
|
106
|
-
*/
|
|
107
|
-
protected isErrorDateTime(value: string): boolean {
|
|
108
|
-
try {
|
|
109
|
-
const [datePart, timePart] = value.split(/[ T]/);
|
|
110
|
-
const [year, month, day] = datePart.split('-').map(Number);
|
|
111
|
-
let [hour, minute, sec] = [0, 0, 0];
|
|
112
|
-
if (timePart !== undefined) {
|
|
113
|
-
[hour, minute, sec] = timePart.split(':').map(Number);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const date = new Date(year, month - 1, day, hour, minute, sec);
|
|
117
|
-
return year !== date.getFullYear() ||
|
|
118
|
-
month !== date.getMonth() + 1 ||
|
|
119
|
-
day !== date.getDate() ||
|
|
120
|
-
hour !== date.getHours() ||
|
|
121
|
-
minute !== date.getMinutes() ||
|
|
122
|
-
sec !== date.getSeconds()
|
|
123
|
-
} catch (error) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Validates if the given value is in the format YYYY-MM-DD
|
|
130
|
-
* 与えられた値がYYYY-MM-DD形式であるかどうかを検証します
|
|
131
|
-
* @param value - The value to be validated, 検証する値
|
|
132
|
-
* @returns {boolean} - Whether the value is in the format YYYY-MM-DD, 値がYYYY-MM-DD形式であるかどうか
|
|
133
|
-
*/
|
|
134
|
-
protected isYYYYMMDD(value: any) {
|
|
135
|
-
if (typeof value !== 'string') {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}$');
|
|
140
|
-
return pattern.test(value);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
|
|
145
|
-
* 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
|
|
146
|
-
* @param value - The value to be validated, 検証する値
|
|
147
|
-
* @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
|
|
148
|
-
*/
|
|
149
|
-
protected isYYYYMMDDhhmiss(value: any) {
|
|
150
|
-
if (typeof value !== 'string') {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}$');
|
|
155
|
-
return pattern.test(value);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Validates if the given value is in the format YYYY-MM-DD hh:mm
|
|
160
|
-
* 与えられた値がYYYY-MM-DD hh:mm形式であるかどうかを検証します
|
|
161
|
-
* @param value - The value to be validated, 検証する値
|
|
162
|
-
* @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm, 値がYYYY-MM-DD hh:mm形式であるかどうか
|
|
163
|
-
*/
|
|
164
|
-
protected isYYYYMMDDhhmi(value: any) {
|
|
165
|
-
if (typeof value !== 'string') {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}$');
|
|
170
|
-
return pattern.test(value);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
|
|
175
|
-
* 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
|
|
176
|
-
* @param value - The value to be validated, 検証する値
|
|
177
|
-
* @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
|
|
178
|
-
*/
|
|
179
|
-
protected isHHMM(value: any) {
|
|
180
|
-
if (typeof value !== 'string') {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d$');
|
|
185
|
-
return pattern.test(value);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Validates if the given value is in the format HH:MM:SS
|
|
190
|
-
* 与えられた値がHH:MM:SS形式であるかどうかを検証します
|
|
191
|
-
* @param value - The value to be validated, 検証する値
|
|
192
|
-
* @returns {boolean} - Whether the value is in the format HH:MM:SS, 値がHH:MM:SS形式であるかどうか
|
|
193
|
-
*/
|
|
194
|
-
protected isHHMMSS(value: any) {
|
|
195
|
-
if (typeof value !== 'string') {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$');
|
|
200
|
-
return pattern.test(value);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Validates if the given value is a number
|
|
205
|
-
* 与えられた値が数値であるかどうかを検証します
|
|
206
|
-
* @param value - The value to be validated, 検証する値
|
|
207
|
-
* @returns {boolean} - Whether the value is a number, 値が数値であるかどうか
|
|
208
|
-
*/
|
|
209
|
-
protected isNumber(value: any) {
|
|
210
|
-
switch (typeof value) {
|
|
211
|
-
case 'string':
|
|
212
|
-
if (value == "") {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
return isNaN(Number(value)) == false;
|
|
216
|
-
case 'number':
|
|
217
|
-
return true;
|
|
218
|
-
default:
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* プロパティの型をSwagger形式に変換します
|
|
225
|
-
* Converts the property type to Swagger format
|
|
226
|
-
* @param {string} value - 変換する値, The value to be converted
|
|
227
|
-
* @returns {string} - Swagger形式の値, The value in Swagger format
|
|
228
|
-
*/
|
|
229
|
-
protected replaceFromPropertyTypeToSwagger(property: PropertyType): string {
|
|
230
|
-
let propertyType: string = property.type;
|
|
231
|
-
if (property.type === 'enum' || property.type === 'enum?') {
|
|
232
|
-
propertyType = property.enumType;
|
|
233
|
-
} else if (property.type === 'map' || property.type === 'map?') {
|
|
234
|
-
propertyType = property.mapType;
|
|
235
|
-
}
|
|
236
|
-
propertyType = propertyType.replace('?', '');
|
|
237
|
-
propertyType = propertyType.replace('number', 'integer');
|
|
238
|
-
propertyType = propertyType.replace(/datetime|date|time|uuid|mail|https|base64/g, 'string');
|
|
239
|
-
return propertyType;
|
|
240
|
-
}
|
|
241
|
-
}
|