pg-mvc-service 2.0.92 → 2.0.94

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.js CHANGED
@@ -200,10 +200,6 @@ class Service {
200
200
  if (this.client !== undefined) {
201
201
  yield this.client.release();
202
202
  }
203
- if (this.isTest) {
204
- // In tests, the connection is terminated because it is shut down every time
205
- yield this.Pool.end();
206
- }
207
203
  });
208
204
  }
209
205
  get S3Client() {
@@ -28,6 +28,7 @@ class RequestType extends ReqResType_1.default {
28
28
  INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
29
29
  INVALID_STRING: '{property} must be of type string. ({value})',
30
30
  INVALID_STRING_MAX_LENGTH: '{property} must be less than or equal to {maxLength} characters. ({value})',
31
+ INVALID_STRING_REG_EXP: '{property} is invalid because it does not match the pattern {regExp}. ({value})',
31
32
  INVALID_UUID: '{property} must be a UUID. ({value})',
32
33
  INVALID_MAIL: '{property} must be an email. ({value})',
33
34
  INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
@@ -51,6 +52,7 @@ class RequestType extends ReqResType_1.default {
51
52
  INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
52
53
  INVALID_STRING: '{property}はstring型で入力してください。({value})',
53
54
  INVALID_STRING_MAX_LENGTH: '{property}は{maxLength}文字以内で入力してください。({value})',
55
+ INVALID_STRING_REG_EXP: '{property} は {regExp} のパターンに一致しないため無効です。({value})',
54
56
  INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
55
57
  INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
56
58
  INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
@@ -146,7 +148,7 @@ class RequestType extends ReqResType_1.default {
146
148
  * @returns {string} The generated error message. 生成されたエラーメッセージ
147
149
  */
148
150
  throwInputError(code, keys, value) {
149
- var _a, _b, _c, _d;
151
+ var _a, _b, _c, _d, _e;
150
152
  const list = {
151
153
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
152
154
  "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
@@ -165,6 +167,7 @@ class RequestType extends ReqResType_1.default {
165
167
  "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
166
168
  "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
167
169
  "STRING_22": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
170
+ "STRING_23": this.ERROR_MESSAGE.INVALID_STRING_REG_EXP,
168
171
  "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
169
172
  "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
170
173
  "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
@@ -203,6 +206,7 @@ class RequestType extends ReqResType_1.default {
203
206
  "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
204
207
  "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
205
208
  "STRING_92": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
209
+ "STRING_93": this.ERROR_MESSAGE.INVALID_STRING_REG_EXP,
206
210
  "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
207
211
  "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
208
212
  "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
@@ -223,11 +227,12 @@ class RequestType extends ReqResType_1.default {
223
227
  case 'string':
224
228
  case 'string?':
225
229
  errorMessage = errorMessage.replace('{maxLength}', ((_b = property.maxLength) !== null && _b !== void 0 ? _b : '[未指定]').toString());
230
+ errorMessage = errorMessage.replace('{regExp}', ((_c = property.regExp) !== null && _c !== void 0 ? _c : '[未指定]').toString());
226
231
  break;
227
232
  case 'number':
228
233
  case 'number?':
229
- errorMessage = errorMessage.replace('{max}', ((_c = property.max) !== null && _c !== void 0 ? _c : '[未指定]').toString());
230
- errorMessage = errorMessage.replace('{min}', ((_d = property.min) !== null && _d !== void 0 ? _d : '[未指定]').toString());
234
+ errorMessage = errorMessage.replace('{max}', ((_d = property.max) !== null && _d !== void 0 ? _d : '[未指定]').toString());
235
+ errorMessage = errorMessage.replace('{min}', ((_e = property.min) !== null && _e !== void 0 ? _e : '[未指定]').toString());
231
236
  break;
232
237
  }
233
238
  errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
@@ -331,6 +336,7 @@ class RequestType extends ReqResType_1.default {
331
336
  type: type,
332
337
  description: this.properties[key].item.description,
333
338
  maxLength: this.properties[key].item.maxLength,
339
+ regExp: this.properties[key].item.regExp
334
340
  };
335
341
  this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
336
342
  }
@@ -769,6 +775,9 @@ class RequestType extends ReqResType_1.default {
769
775
  if (property.maxLength !== undefined && stringValue.length > property.maxLength) {
770
776
  this.throwInputError(isRequestBody ? "STRING_22" : "STRING_92", keys, value);
771
777
  }
778
+ if (property.regExp !== undefined && !property.regExp.test(stringValue)) {
779
+ this.throwInputError(isRequestBody ? "STRING_23" : "STRING_93", keys, value);
780
+ }
772
781
  return stringValue;
773
782
  case 'uuid':
774
783
  case 'uuid?':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.92",
3
+ "version": "2.0.94",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
package/src/Service.ts CHANGED
@@ -182,11 +182,6 @@ export class Service {
182
182
  if (this.client !== undefined) {
183
183
  await this.client.release();
184
184
  }
185
-
186
- if (this.isTest) {
187
- // In tests, the connection is terminated because it is shut down every time
188
- await this.Pool.end();
189
- }
190
185
  }
191
186
 
192
187
  private s3Client?: AwsS3Client;
@@ -10,6 +10,7 @@ export type StringType = {
10
10
  type: 'string' | 'string?';
11
11
  description?: string;
12
12
  maxLength?: number;
13
+ regExp?: RegExp;
13
14
  };
14
15
  export type NumberType = {
15
16
  type: 'number' | 'number?';
@@ -16,6 +16,7 @@ export interface ErrorMessageType {
16
16
  INVALID_BOOL: string;
17
17
  INVALID_STRING: string;
18
18
  INVALID_STRING_MAX_LENGTH: string;
19
+ INVALID_STRING_REG_EXP: string;
19
20
  INVALID_UUID: string;
20
21
  INVALID_MAIL: string;
21
22
  INVALID_HTTPS: string;
@@ -48,6 +49,7 @@ export class RequestType extends ReqResType {
48
49
  INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
49
50
  INVALID_STRING: '{property} must be of type string. ({value})',
50
51
  INVALID_STRING_MAX_LENGTH: '{property} must be less than or equal to {maxLength} characters. ({value})',
52
+ INVALID_STRING_REG_EXP: '{property} is invalid because it does not match the pattern {regExp}. ({value})',
51
53
  INVALID_UUID: '{property} must be a UUID. ({value})',
52
54
  INVALID_MAIL: '{property} must be an email. ({value})',
53
55
  INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
@@ -71,6 +73,7 @@ export class RequestType extends ReqResType {
71
73
  INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
72
74
  INVALID_STRING: '{property}はstring型で入力してください。({value})',
73
75
  INVALID_STRING_MAX_LENGTH: '{property}は{maxLength}文字以内で入力してください。({value})',
76
+ INVALID_STRING_REG_EXP: '{property} は {regExp} のパターンに一致しないため無効です。({value})',
74
77
  INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
75
78
  INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
76
79
  INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
@@ -152,13 +155,13 @@ export class RequestType extends ReqResType {
152
155
  private throwInputError(code:
153
156
  "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
154
157
  "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
155
- "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
158
+ "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "STRING_23" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
156
159
  "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
157
160
  "REQUIRE_31" |
158
161
  "ENUM_32" | "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
159
162
  "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
160
163
  "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
161
- "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
164
+ "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "STRING_93" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
162
165
  "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
163
166
  , keys: Array<string | number>, value: any): never {
164
167
  const list = {
@@ -179,6 +182,7 @@ export class RequestType extends ReqResType {
179
182
  "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
180
183
  "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
181
184
  "STRING_22": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
185
+ "STRING_23": this.ERROR_MESSAGE.INVALID_STRING_REG_EXP,
182
186
  "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
183
187
  "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
184
188
  "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
@@ -217,6 +221,7 @@ export class RequestType extends ReqResType {
217
221
  "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
218
222
  "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
219
223
  "STRING_92": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
224
+ "STRING_93": this.ERROR_MESSAGE.INVALID_STRING_REG_EXP,
220
225
  "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
221
226
  "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
222
227
  "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
@@ -238,6 +243,7 @@ export class RequestType extends ReqResType {
238
243
  case 'string':
239
244
  case 'string?':
240
245
  errorMessage = errorMessage.replace('{maxLength}', (property.maxLength ?? '[未指定]').toString());
246
+ errorMessage = errorMessage.replace('{regExp}', (property.regExp ?? '[未指定]').toString());
241
247
  break;
242
248
  case 'number':
243
249
  case 'number?':
@@ -346,6 +352,7 @@ export class RequestType extends ReqResType {
346
352
  type: type,
347
353
  description: this.properties[key].item.description,
348
354
  maxLength: this.properties[key].item.maxLength,
355
+ regExp: this.properties[key].item.regExp
349
356
  };
350
357
  this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
351
358
  } else if (type === 'number' || type === 'number?') {
@@ -801,6 +808,11 @@ export class RequestType extends ReqResType {
801
808
  if (property.maxLength !== undefined && stringValue.length > property.maxLength) {
802
809
  this.throwInputError(isRequestBody ? "STRING_22" : "STRING_92", keys, value);
803
810
  }
811
+
812
+ if (property.regExp !== undefined && !property.regExp.test(stringValue)) {
813
+ this.throwInputError(isRequestBody ? "STRING_23" : "STRING_93", keys, value);
814
+ }
815
+
804
816
  return stringValue;
805
817
  case 'uuid':
806
818
  case 'uuid?':