pg-mvc-service 2.0.60 → 2.0.62

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.
@@ -202,8 +202,8 @@ class ReqResType {
202
202
  if (property.type === 'enum' || property.type === 'enum?') {
203
203
  propertyType = property.enumType;
204
204
  }
205
- else if (property.type === 'dictionary' || property.type === 'dictionary?') {
206
- propertyType = property.dictionaryType;
205
+ else if (property.type === 'map' || property.type === 'map?') {
206
+ propertyType = property.mapType;
207
207
  }
208
208
  propertyType = propertyType.replace('?', '');
209
209
  propertyType = propertyType.replace('number', 'integer');
@@ -33,7 +33,8 @@ class RequestType extends ReqResType_1.default {
33
33
  INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
34
34
  INVALID_BASE64: '{property} must be in Base64 format. ({value})',
35
35
  INVALID_ENUM: '{property} must be in {enums}. ({value})',
36
- INVALID_DICTIONAY: '{property} must be a valid dictionary key. ({value})',
36
+ INVALID_MAP_NUMBER: '{property} must be a valid number for a map key. ({value})',
37
+ INVALID_MAP_STRING: '{property} must be a valid string for a map key. ({value})',
37
38
  };
38
39
  this.ERROR_MESSAGE_JAPAN = {
39
40
  REQUIRED: '{property}は必須項目です。',
@@ -51,7 +52,8 @@ class RequestType extends ReqResType_1.default {
51
52
  INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
52
53
  INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
53
54
  INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})',
54
- INVALID_DICTIONAY: '{property}は有効なKey-Value形式で入力してください。({value}'
55
+ INVALID_MAP_NUMBER: '{property} は有効な数値のマップキーでなければなりません。({value})',
56
+ INVALID_MAP_STRING: '{property} は有効な文字列のマップキーでなければなりません。({value})',
55
57
  };
56
58
  this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
57
59
  this.paramProperties = [];
@@ -166,7 +168,8 @@ class RequestType extends ReqResType_1.default {
166
168
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
167
169
  "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
168
170
  "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
169
- "DICTIONARY_51": this.ERROR_MESSAGE.INVALID_DICTIONAY,
171
+ "MAP_011": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
172
+ "MAP_012": this.ERROR_MESSAGE.INVALID_MAP_STRING,
170
173
  "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
171
174
  "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
172
175
  "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
@@ -277,8 +280,35 @@ class RequestType extends ReqResType_1.default {
277
280
  }
278
281
  }
279
282
  break;
280
- case 'dictionary':
281
- case 'dictionary?':
283
+ case 'map':
284
+ case 'map?':
285
+ const mapData = {};
286
+ console.log('value', value[key]);
287
+ for (const [mapKey, mapValue] of value[key]) {
288
+ switch (this.properties[key].mapType) {
289
+ case 'number':
290
+ case 'number?':
291
+ if (this.isNumber(this.properties) === false) {
292
+ this.throwInputError("MAP_011", [key], value);
293
+ }
294
+ mapData[mapKey] = Number(mapValue);
295
+ break;
296
+ case 'string':
297
+ case 'string?':
298
+ switch (typeof value) {
299
+ case 'number':
300
+ mapData[mapKey] = value.toString();
301
+ break;
302
+ case 'string':
303
+ mapData[mapKey] = value;
304
+ break;
305
+ default:
306
+ this.throwInputError("MAP_012", [key], value);
307
+ }
308
+ }
309
+ }
310
+ console.log('mapData', mapData);
311
+ this.changeBody([key], mapData);
282
312
  break;
283
313
  case 'enum':
284
314
  case 'enum?':
@@ -256,8 +256,8 @@ class ResponseType extends ReqResType_1.default {
256
256
  return value;
257
257
  }
258
258
  return undefined;
259
- case 'dictionary':
260
- case 'dictionary?':
259
+ case 'map':
260
+ case 'map?':
261
261
  // if (Object.keys(property.enums).includes(value)) {
262
262
  // return value;
263
263
  // }
@@ -307,8 +307,8 @@ class ResponseType extends ReqResType_1.default {
307
307
  case 'array?':
308
308
  ymlString += this.makeSwaggerPropertyFromArray([key], tabCount + 1);
309
309
  break;
310
- case 'dictionary':
311
- case 'dictionary?':
310
+ case 'map':
311
+ case 'map?':
312
312
  ymlString += this.makeSwaggerPropertyFromDictionary([key], tabCount + 1);
313
313
  break;
314
314
  }
@@ -347,8 +347,8 @@ class ResponseType extends ReqResType_1.default {
347
347
  case 'array?':
348
348
  ymlString += this.makeSwaggerPropertyFromArray([...keys, key], tabCount + 2);
349
349
  break;
350
- case 'dictionary':
351
- case 'dictionary?':
350
+ case 'map':
351
+ case 'map?':
352
352
  ymlString += this.makeSwaggerPropertyFromDictionary([...keys, key], tabCount + 2);
353
353
  break;
354
354
  }
@@ -382,8 +382,8 @@ class ResponseType extends ReqResType_1.default {
382
382
  case 'array?':
383
383
  ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
384
384
  break;
385
- case 'dictionary':
386
- case 'dictionary?':
385
+ case 'map':
386
+ case 'map?':
387
387
  ymlString += this.makeSwaggerPropertyFromDictionary([...keys, 0], tabCount + 1);
388
388
  break;
389
389
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.60",
3
+ "version": "2.0.62",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -18,10 +18,10 @@ export type ArrayType = {
18
18
  description?: string;
19
19
  item: PropertyType;
20
20
  };
21
- export type DictionaryType = {
22
- type: 'dictionary' | 'dictionary?';
21
+ export type MapType = {
22
+ type: 'map' | 'map?';
23
23
  description?: string;
24
- dictionaryType: 'string' | 'number' | 'string?' | 'number?';
24
+ mapType: 'string' | 'number' | 'string?' | 'number?';
25
25
  };
26
26
  export type EnumType = {
27
27
  type: 'enum' | 'enum?';
@@ -30,7 +30,7 @@ export type EnumType = {
30
30
  enums: {[key: string | number]: string};
31
31
  };
32
32
 
33
- export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType | DictionaryType;
33
+ export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType | MapType;
34
34
 
35
35
  export default class ReqResType {
36
36
 
@@ -252,8 +252,8 @@ export default class ReqResType {
252
252
  let propertyType: string = property.type;
253
253
  if (property.type === 'enum' || property.type === 'enum?') {
254
254
  propertyType = property.enumType;
255
- } else if (property.type === 'dictionary' || property.type === 'dictionary?') {
256
- propertyType = property.dictionaryType;
255
+ } else if (property.type === 'map' || property.type === 'map?') {
256
+ propertyType = property.mapType;
257
257
  }
258
258
  propertyType = propertyType.replace('?', '');
259
259
  propertyType = propertyType.replace('number', 'integer');
@@ -21,7 +21,8 @@ export interface ErrorMessageType {
21
21
  INVALID_DATETIME: string;
22
22
  INVALID_BASE64: string;
23
23
  INVALID_ENUM: string;
24
- INVALID_DICTIONAY: string;
24
+ INVALID_MAP_NUMBER: string;
25
+ INVALID_MAP_STRING: string;
25
26
  }
26
27
 
27
28
  export class RequestType extends ReqResType {
@@ -48,7 +49,8 @@ export class RequestType extends ReqResType {
48
49
  INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
49
50
  INVALID_BASE64: '{property} must be in Base64 format. ({value})',
50
51
  INVALID_ENUM: '{property} must be in {enums}. ({value})',
51
- INVALID_DICTIONAY: '{property} must be a valid dictionary key. ({value})',
52
+ INVALID_MAP_NUMBER: '{property} must be a valid number for a map key. ({value})',
53
+ INVALID_MAP_STRING: '{property} must be a valid string for a map key. ({value})',
52
54
  }
53
55
  private readonly ERROR_MESSAGE_JAPAN: ErrorMessageType = {
54
56
  REQUIRED: '{property}は必須項目です。',
@@ -66,7 +68,8 @@ export class RequestType extends ReqResType {
66
68
  INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
67
69
  INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
68
70
  INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})',
69
- INVALID_DICTIONAY: '{property}は有効なKey-Value形式で入力してください。({value}'
71
+ INVALID_MAP_NUMBER: '{property} は有効な数値のマップキーでなければなりません。({value})',
72
+ INVALID_MAP_STRING: '{property} は有効な文字列のマップキーでなければなりません。({value})',
70
73
  }
71
74
  protected readonly ERROR_MESSAGE: ErrorMessageType = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
72
75
 
@@ -141,7 +144,7 @@ export class RequestType extends ReqResType {
141
144
  "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
142
145
  "REQUIRE_31" |
143
146
  "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
144
- "DICTIONARY_51" |
147
+ "MAP_011" | "MAP_012" |
145
148
  "NUMBER_91" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
146
149
  "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
147
150
  , keys: Array<string | number>, value: any): never {
@@ -174,7 +177,8 @@ export class RequestType extends ReqResType {
174
177
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
175
178
  "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
176
179
  "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
177
- "DICTIONARY_51": this.ERROR_MESSAGE.INVALID_DICTIONAY,
180
+ "MAP_011": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
181
+ "MAP_012": this.ERROR_MESSAGE.INVALID_MAP_STRING,
178
182
  "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
179
183
  "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
180
184
  "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
@@ -285,8 +289,36 @@ export class RequestType extends ReqResType {
285
289
  }
286
290
  }
287
291
  break;
288
- case 'dictionary':
289
- case 'dictionary?':
292
+ case 'map':
293
+ case 'map?':
294
+ const mapData: {[key: string]: string | number} = {};
295
+ console.log('value', value[key]);
296
+ for (const [mapKey, mapValue] of value[key]) {
297
+ switch (this.properties[key].mapType) {
298
+ case 'number':
299
+ case 'number?':
300
+ if (this.isNumber(this.properties) === false) {
301
+ this.throwInputError("MAP_011", [key], value);
302
+ }
303
+ mapData[mapKey] = Number(mapValue);
304
+ break;
305
+ case 'string':
306
+ case 'string?':
307
+ switch (typeof value) {
308
+ case 'number':
309
+ mapData[mapKey] = value.toString();
310
+ break;
311
+ case 'string':
312
+ mapData[mapKey] = value;
313
+ break;
314
+ default:
315
+ this.throwInputError("MAP_012", [key], value);
316
+ }
317
+ }
318
+ }
319
+
320
+ console.log('mapData', mapData);
321
+ this.changeBody([key], mapData);
290
322
  break;
291
323
  case 'enum':
292
324
  case 'enum?':
@@ -278,8 +278,8 @@ export class ResponseType extends ReqResType {
278
278
  return value;
279
279
  }
280
280
  return undefined;
281
- case 'dictionary':
282
- case 'dictionary?':
281
+ case 'map':
282
+ case 'map?':
283
283
  // if (Object.keys(property.enums).includes(value)) {
284
284
  // return value;
285
285
  // }
@@ -336,8 +336,8 @@ export class ResponseType extends ReqResType {
336
336
  case 'array?':
337
337
  ymlString += this.makeSwaggerPropertyFromArray([key], tabCount + 1);
338
338
  break;
339
- case 'dictionary':
340
- case 'dictionary?':
339
+ case 'map':
340
+ case 'map?':
341
341
  ymlString += this.makeSwaggerPropertyFromDictionary([key], tabCount + 1);
342
342
  break;
343
343
  }
@@ -381,8 +381,8 @@ export class ResponseType extends ReqResType {
381
381
  case 'array?':
382
382
  ymlString += this.makeSwaggerPropertyFromArray([...keys, key], tabCount + 2);
383
383
  break;
384
- case 'dictionary':
385
- case 'dictionary?':
384
+ case 'map':
385
+ case 'map?':
386
386
  ymlString += this.makeSwaggerPropertyFromDictionary([...keys, key], tabCount + 2);
387
387
  break;
388
388
  }
@@ -420,8 +420,8 @@ export class ResponseType extends ReqResType {
420
420
  case 'array?':
421
421
  ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
422
422
  break;
423
- case 'dictionary':
424
- case 'dictionary?':
423
+ case 'map':
424
+ case 'map?':
425
425
  ymlString += this.makeSwaggerPropertyFromDictionary([...keys, 0], tabCount + 1);
426
426
  break;
427
427
  }