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.
Files changed (56) hide show
  1. package/README.md +1 -0
  2. package/dist/PoolManager.js +57 -0
  3. package/dist/Service.js +257 -0
  4. package/dist/clients/AwsS3Client.js +249 -0
  5. package/dist/clients/Base64Client.js +153 -0
  6. package/dist/clients/EncryptClient.js +85 -0
  7. package/dist/clients/StringClient.js +13 -0
  8. package/dist/documents/Swagger.js +94 -0
  9. package/dist/exceptions/Exception.js +53 -0
  10. package/dist/index.js +16 -0
  11. package/dist/models/MigrateDatabase.js +138 -0
  12. package/dist/models/MigrateRollback.js +146 -0
  13. package/dist/models/MigrateTable.js +51 -0
  14. package/dist/models/SqlUtils/SelectExpression.js +92 -0
  15. package/dist/models/SqlUtils/ValidateValueUtil.js +250 -0
  16. package/dist/models/SqlUtils/WhereExpression.js +256 -0
  17. package/dist/models/TableDoc.js +353 -0
  18. package/dist/models/TableModel.js +636 -0
  19. package/dist/models/Type.js +2 -0
  20. package/dist/models/Utils/DateTimeUtil.js +134 -0
  21. package/dist/models/Utils/NumberUtil.js +28 -0
  22. package/dist/models/Utils/StringUtil.js +31 -0
  23. package/dist/models/ValidateClient.js +164 -0
  24. package/dist/models/index.js +14 -0
  25. package/dist/reqestResponse/ReqResType.js +196 -0
  26. package/dist/reqestResponse/RequestType.js +742 -0
  27. package/dist/reqestResponse/ResponseType.js +380 -0
  28. package/index.d.ts +306 -0
  29. package/package.json +36 -0
  30. package/src/PoolManager.ts +48 -0
  31. package/src/Service.ts +251 -0
  32. package/src/clients/AwsS3Client.ts +229 -0
  33. package/src/clients/Base64Client.ts +155 -0
  34. package/src/clients/EncryptClient.ts +100 -0
  35. package/src/clients/StringClient.ts +14 -0
  36. package/src/documents/Swagger.ts +111 -0
  37. package/src/exceptions/Exception.ts +54 -0
  38. package/src/index.ts +7 -0
  39. package/src/models/MigrateDatabase.ts +135 -0
  40. package/src/models/MigrateRollback.ts +151 -0
  41. package/src/models/MigrateTable.ts +56 -0
  42. package/src/models/SqlUtils/SelectExpression.ts +97 -0
  43. package/src/models/SqlUtils/ValidateValueUtil.ts +270 -0
  44. package/src/models/SqlUtils/WhereExpression.ts +286 -0
  45. package/src/models/TableDoc.ts +360 -0
  46. package/src/models/TableModel.ts +713 -0
  47. package/src/models/Type.ts +59 -0
  48. package/src/models/Utils/DateTimeUtil.ts +146 -0
  49. package/src/models/Utils/NumberUtil.ts +23 -0
  50. package/src/models/Utils/StringUtil.ts +33 -0
  51. package/src/models/ValidateClient.ts +182 -0
  52. package/src/models/index.ts +7 -0
  53. package/src/reqestResponse/ReqResType.ts +242 -0
  54. package/src/reqestResponse/RequestType.ts +851 -0
  55. package/src/reqestResponse/ResponseType.ts +418 -0
  56. package/tsconfig.json +14 -0
@@ -0,0 +1,242 @@
1
+ export type PrimitiveType = {
2
+ type:
3
+ 'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
4
+ 'string?' | 'number?' | 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
5
+ description?: string;
6
+ };
7
+
8
+ export type ObjectType = {
9
+ type: 'object' | 'object?';
10
+ description?: string;
11
+ properties: {
12
+ [key: string]: PropertyType;
13
+ };
14
+ };
15
+ export type ArrayType = {
16
+ type: 'array' | 'array?';
17
+ description?: string;
18
+ properties: PropertyType;
19
+ };
20
+ export type EnumType = {
21
+ type: 'enum' | 'enum?';
22
+ description?: string;
23
+ enumType: 'string' | 'number' | 'string?' | 'number?';
24
+ enums: {[key: string | number]: string};
25
+ };
26
+
27
+ export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType;
28
+
29
+ export default class ReqResType {
30
+
31
+ protected properties: { [key: string]: PropertyType; } = {};
32
+
33
+ /**
34
+ * Checks if the value is a valid date-time format
35
+ * 値が有効な日付時間形式かどうかを確認します
36
+ * @param value - 検証する値, The value to be validated
37
+ * @returns {boolean} - 値が有効な日付時間形式であるかどうか, Whether the value is a valid date-time format
38
+ */
39
+ protected isErrorDateTime(value: string): boolean {
40
+ try {
41
+ const [datePart, timePart] = value.split(/[ T]/);
42
+ const [year, month, day] = datePart.split('-').map(Number);
43
+ let [hour, minute, sec] = [0, 0, 0];
44
+ if (timePart !== undefined) {
45
+ [hour, minute, sec] = timePart.split(':').map(Number);
46
+ }
47
+
48
+ const date = new Date(year, month - 1, day, hour, minute, sec);
49
+ return year !== date.getFullYear() ||
50
+ month !== date.getMonth() + 1 ||
51
+ day !== date.getDate() ||
52
+ hour !== date.getHours() ||
53
+ minute !== date.getMinutes() ||
54
+ sec !== date.getSeconds()
55
+ } catch (error) {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Validates if the given value is in the format YYYY-MM-DD
62
+ * 与えられた値がYYYY-MM-DD形式であるかどうかを検証します
63
+ * @param value - The value to be validated, 検証する値
64
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD, 値がYYYY-MM-DD形式であるかどうか
65
+ */
66
+ protected isYYYYMMDD(value: any) {
67
+ if (typeof value !== 'string') {
68
+ return false;
69
+ }
70
+
71
+ const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}$');
72
+ return pattern.test(value);
73
+ }
74
+
75
+ /**
76
+ * Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
77
+ * 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
78
+ * @param value - The value to be validated, 検証する値
79
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
80
+ */
81
+ protected isYYYYMMDDhhmiss(value: any) {
82
+ if (typeof value !== 'string') {
83
+ return false;
84
+ }
85
+
86
+ const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}$');
87
+ return pattern.test(value);
88
+ }
89
+
90
+ /**
91
+ * Validates if the given value is in the format YYYY-MM-DD hh:mm
92
+ * 与えられた値がYYYY-MM-DD hh:mm形式であるかどうかを検証します
93
+ * @param value - The value to be validated, 検証する値
94
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm, 値がYYYY-MM-DD hh:mm形式であるかどうか
95
+ */
96
+ protected isYYYYMMDDhhmi(value: any) {
97
+ if (typeof value !== 'string') {
98
+ return false;
99
+ }
100
+
101
+ const pattern = new RegExp('^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}$');
102
+ return pattern.test(value);
103
+ }
104
+
105
+ /**
106
+ * Validates if the given value is in the format YYYY-MM-DD hh:mm:ss
107
+ * 与えられた値がYYYY-MM-DD hh:mm:ss形式であるかどうかを検証します
108
+ * @param value - The value to be validated, 検証する値
109
+ * @returns {boolean} - Whether the value is in the format YYYY-MM-DD hh:mm:ss, 値がYYYY-MM-DD hh:mm:ss形式であるかどうか
110
+ */
111
+ protected isHHMM(value: any) {
112
+ if (typeof value !== 'string') {
113
+ return false;
114
+ }
115
+
116
+ const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d$');
117
+ return pattern.test(value);
118
+ }
119
+
120
+ /**
121
+ * Validates if the given value is in the format HH:MM:SS
122
+ * 与えられた値がHH:MM:SS形式であるかどうかを検証します
123
+ * @param value - The value to be validated, 検証する値
124
+ * @returns {boolean} - Whether the value is in the format HH:MM:SS, 値がHH:MM:SS形式であるかどうか
125
+ */
126
+ protected isHHMMSS(value: any) {
127
+ if (typeof value !== 'string') {
128
+ return false;
129
+ }
130
+
131
+ const pattern = new RegExp('^(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$');
132
+ return pattern.test(value);
133
+ }
134
+
135
+ /**
136
+ * Validates if the given value is a number
137
+ * 与えられた値が数値であるかどうかを検証します
138
+ * @param value - The value to be validated, 検証する値
139
+ * @returns {boolean} - Whether the value is a number, 値が数値であるかどうか
140
+ */
141
+ protected isNumber(value: any) {
142
+ switch (typeof value) {
143
+ case 'string':
144
+ if (value == "") {
145
+ return false;
146
+ }
147
+ return isNaN(Number(value)) == false;
148
+ case 'number':
149
+ return true;
150
+ default:
151
+ return false;
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Validates if the given value is a valid UUID
157
+ * 与えられた値が有効なUUIDであるかどうかを検証します
158
+ * @param value - The value to be validated, 検証する値
159
+ * @returns {boolean} - Whether the value is a valid UUID, 値が有効なUUIDであるかどうか
160
+ */
161
+ protected isUUID(value: any) {
162
+ if (typeof value !== 'string') {
163
+ return false;
164
+ }
165
+
166
+ const pattern = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$');
167
+ return pattern.test(value);
168
+ }
169
+
170
+ /**
171
+ * 値がメールアドレス形式であるかどうかを検証します
172
+ * Validates if the given value is in the format of an email address
173
+ * @param value - 検証する値, The value to be validated
174
+ * @returns {boolean} - 値がメールアドレス形式であるかどうか, Whether the value is in the format of an email address
175
+ */
176
+ protected isMail(value: any) {
177
+ if (typeof value !== 'string') {
178
+ return false;
179
+ }
180
+
181
+ const pattern = new RegExp('^[a-zA-Z0-9_%+-]+([.][a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9]+([-.]?[a-zA-Z0-9]+)*\\.[a-zA-Z]{2,}$');
182
+ return pattern.test(value);
183
+ }
184
+
185
+ /**
186
+ * 値がHTTPS URLであるかどうかを検証します
187
+ * Validates if the given value is an HTTPS URL
188
+ * @param value - 検証する値, The value to be validated
189
+ * @returns {boolean} - 値がHTTPS URLであるかどうか, Whether the value is an HTTPS URL
190
+ */
191
+ protected isHttps(value: any) {
192
+ if (typeof value !== 'string') {
193
+ return false;
194
+ }
195
+
196
+ const urlPattern = new RegExp('^(https?:\\/\\/[^\\s/$.?#].[^\\s]*)$');
197
+ return urlPattern.test(value);
198
+ }
199
+
200
+ /**
201
+ * 値がBase64形式であるかどうかを検証します
202
+ * Validates if the given value is in Base64 format
203
+ * @param value - 検証する値, The value to be validated
204
+ * @returns {boolean} - 値がBase64形式であるかどうか, Whether the value is in Base64 format
205
+ */
206
+ protected isBase64(value: any) {
207
+ if (typeof value !== 'string') {
208
+ return false;
209
+ }
210
+
211
+ // base64は4倍の長さである必要がある
212
+ if (value.length % 4 !== 0) {
213
+ return false;
214
+ }
215
+
216
+ // 基本的なbase64パターン
217
+ // 使用可能な文字
218
+ // ・ アルファベット(A-Z, a-z)
219
+ // ・ 数字(0-9)
220
+ // ・ +と/(基本文字)
221
+ // ・ =(パディング文字)
222
+ const base64Pattern = /^[A-Za-z0-9+/]*={0,2}$/;
223
+ return base64Pattern.test(value);
224
+ }
225
+
226
+ /**
227
+ * プロパティの型をSwagger形式に変換します
228
+ * Converts the property type to Swagger format
229
+ * @param {string} value - 変換する値, The value to be converted
230
+ * @returns {string} - Swagger形式の値, The value in Swagger format
231
+ */
232
+ protected replaceFromPropertyTypeToSwagger(property: PropertyType): string {
233
+ let propertyType: string = property.type;
234
+ if (property.type === 'enum' || property.type === 'enum?') {
235
+ propertyType = property.enumType;
236
+ }
237
+ propertyType = propertyType.replace('?', '');
238
+ propertyType = propertyType.replace('number', 'integer');
239
+ propertyType = propertyType.replace(/datetime|date|time|uuid|mail|https|base64/g, 'string');
240
+ return propertyType;
241
+ }
242
+ }