pg-mvc-service 2.0.68 → 2.0.70

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.
@@ -168,7 +168,7 @@ class RequestType extends ReqResType_1.default {
168
168
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
169
169
  "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
170
170
  "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
171
- "MAP_01": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
171
+ "MAP_01": this.ERROR_MESSAGE.INVALID_MAP_NUMBER, // // tODO : mapのエラーメッセージどうするか
172
172
  "MAP_02": this.ERROR_MESSAGE.INVALID_MAP_STRING,
173
173
  "MAP_11": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
174
174
  "MAP_12": this.ERROR_MESSAGE.INVALID_MAP_STRING,
@@ -284,6 +284,7 @@ class RequestType extends ReqResType_1.default {
284
284
  break;
285
285
  case 'map':
286
286
  case 'map?':
287
+ // tODO : ここは共通化したい
287
288
  const mapData = {};
288
289
  for (const [mapKey, mapValue] of Object.entries(value)) {
289
290
  switch (this.properties[key].mapType) {
@@ -421,45 +422,40 @@ class RequestType extends ReqResType_1.default {
421
422
  this.setEnum([...keys, i], value);
422
423
  }
423
424
  break;
425
+ case 'map':
426
+ case 'map?':
427
+ const mapData = {};
428
+ for (const [mapKey, mapValue] of Object.entries(values[i])) {
429
+ switch (property.item.mapType) {
430
+ case 'number':
431
+ case 'number?':
432
+ if (this.isNumber(mapValue) === false) {
433
+ this.throwInputError("MAP_11", [...keys, i], values[i]);
434
+ }
435
+ mapData[mapKey] = Number(mapValue);
436
+ break;
437
+ case 'string':
438
+ case 'string?':
439
+ switch (typeof mapValue) {
440
+ case 'number':
441
+ mapData[mapKey] = mapValue.toString();
442
+ break;
443
+ case 'string':
444
+ mapData[mapKey] = mapValue;
445
+ break;
446
+ default:
447
+ this.throwInputError("MAP_12", [...keys, i], values[i]);
448
+ }
449
+ }
450
+ }
451
+ this.changeBody([...keys, i], mapData);
452
+ break;
424
453
  default:
425
454
  this.convertInput([...keys, i], values[i]);
426
455
  break;
427
456
  }
428
457
  }
429
458
  }
430
- setDictionary(keys, values) {
431
- // const property = this.getProperty(keys);
432
- // for (let i = 0;i < values.length; i++) {
433
- // // NULL Check
434
- // if (values[i] === undefined || values[i] === null || (property.properties.type.replace("?", "") !== "string" && values[i] === "")) {
435
- // if (property.properties.type.endsWith('?')) {
436
- // this.changeBody([...keys, i], values[i] === undefined ? undefined : null);
437
- // continue;
438
- // } else {
439
- // this.throwInputError("DICTIONARY_51", [...keys, i], "");
440
- // }
441
- // }
442
- // switch (property.properties.type) {
443
- // case 'object':
444
- // case 'object?':
445
- // this.setObject([...keys, i], values[i]);
446
- // break;
447
- // case 'array':
448
- // case 'array?':
449
- // this.setArray([...keys, i], values[i]);
450
- // break;
451
- // case 'enum':
452
- // case 'enum?':
453
- // for (const value of values) {
454
- // this.setEnum([...keys, i], value);
455
- // }
456
- // break;
457
- // default:
458
- // this.convertInput([...keys, i], values[i]);
459
- // break;
460
- // }
461
- // }
462
- }
463
459
  /**
464
460
  * Set the value of the request body to the specified path.
465
461
  * Automatically create intermediate objects or arrays as needed.
@@ -43,6 +43,10 @@ class ResponseType extends ReqResType_1.default {
43
43
  case 'array?':
44
44
  data[key] = this.getArray([key]);
45
45
  break;
46
+ case 'map':
47
+ case 'map?':
48
+ data[key] = this.getMap([key]);
49
+ break;
46
50
  default:
47
51
  data[key] = this.getValue([key]);
48
52
  break;
@@ -81,6 +85,10 @@ class ResponseType extends ReqResType_1.default {
81
85
  case 'array?':
82
86
  resData[key] = this.getArray([...keys, key]);
83
87
  break;
88
+ case 'map':
89
+ case 'map?':
90
+ resData[key] = this.getMap([...keys, key]);
91
+ break;
84
92
  default:
85
93
  resData[key] = this.getValue([...keys, key]);
86
94
  break;
@@ -114,6 +122,10 @@ class ResponseType extends ReqResType_1.default {
114
122
  case 'array?':
115
123
  resData.push(this.getArray([...keys, i]));
116
124
  break;
125
+ case 'map':
126
+ case 'map?':
127
+ resData.push(this.getMap([...keys, i]));
128
+ break;
117
129
  default:
118
130
  resData.push(this.getValue([...keys, i]));
119
131
  break;
@@ -122,6 +134,47 @@ class ResponseType extends ReqResType_1.default {
122
134
  return resData;
123
135
  }
124
136
  /**
137
+ * Retrieve array type data
138
+ * 配列型のデータを取得
139
+ * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
140
+ * @returns {Array<any> | undefined} Retrieved array data, 取得された配列データ
141
+ */
142
+ getMap(keys) {
143
+ const data = this.getData(keys);
144
+ if (data === undefined || Array.isArray(data) === false) {
145
+ return undefined;
146
+ }
147
+ const mapProperty = this.getProperty(keys);
148
+ if (mapProperty.type !== 'map' && mapProperty.type !== 'map?') {
149
+ throw new Error(`getMapメソッドでMap型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
150
+ }
151
+ const mapData = {};
152
+ for (const [key, value] of data) {
153
+ switch (mapProperty.mapType) {
154
+ case 'number':
155
+ case 'number?':
156
+ if (this.isNumber(value) === false) {
157
+ continue;
158
+ }
159
+ mapData[key] = Number(value);
160
+ break;
161
+ case 'string':
162
+ case 'string?':
163
+ switch (typeof value) {
164
+ case 'number':
165
+ mapData[key] = value.toString();
166
+ break;
167
+ case 'string':
168
+ mapData[key] = value;
169
+ break;
170
+ default:
171
+ continue;
172
+ }
173
+ }
174
+ }
175
+ return mapData;
176
+ }
177
+ /**
125
178
  * Retrieve data based on the provided keys
126
179
  * 指定されたキーに基づいてデータを取得
127
180
  * @param {Array.<string|number>} keys - Path to the data, データへのパス
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.68",
3
+ "version": "2.0.70",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -177,7 +177,7 @@ export class RequestType extends ReqResType {
177
177
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
178
178
  "ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
179
179
  "ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
180
- "MAP_01": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
180
+ "MAP_01": this.ERROR_MESSAGE.INVALID_MAP_NUMBER, // // tODO : mapのエラーメッセージどうするか
181
181
  "MAP_02": this.ERROR_MESSAGE.INVALID_MAP_STRING,
182
182
  "MAP_11": this.ERROR_MESSAGE.INVALID_MAP_NUMBER,
183
183
  "MAP_12": this.ERROR_MESSAGE.INVALID_MAP_STRING,
@@ -293,6 +293,7 @@ export class RequestType extends ReqResType {
293
293
  break;
294
294
  case 'map':
295
295
  case 'map?':
296
+ // tODO : ここは共通化したい
296
297
  const mapData: {[key: string]: string | number} = {};
297
298
  for (const [mapKey, mapValue] of Object.entries(value)) {
298
299
  switch (this.properties[key].mapType) {
@@ -439,6 +440,35 @@ export class RequestType extends ReqResType {
439
440
  this.setEnum([...keys, i], value);
440
441
  }
441
442
  break;
443
+ case 'map':
444
+ case 'map?':
445
+ const mapData: {[key: string]: string | number} = {};
446
+ for (const [mapKey, mapValue] of Object.entries(values[i])) {
447
+ switch (property.item.mapType) {
448
+ case 'number':
449
+ case 'number?':
450
+ if (this.isNumber(mapValue) === false) {
451
+ this.throwInputError("MAP_11", [...keys, i], values[i]);
452
+ }
453
+ mapData[mapKey] = Number(mapValue);
454
+ break;
455
+ case 'string':
456
+ case 'string?':
457
+ switch (typeof mapValue) {
458
+ case 'number':
459
+ mapData[mapKey] = mapValue.toString();
460
+ break;
461
+ case 'string':
462
+ mapData[mapKey] = mapValue;
463
+ break;
464
+ default:
465
+ this.throwInputError("MAP_12", [...keys, i], values[i]);
466
+ }
467
+ }
468
+ }
469
+
470
+ this.changeBody([...keys, i], mapData);
471
+ break;
442
472
  default:
443
473
  this.convertInput([...keys, i], values[i]);
444
474
  break;
@@ -40,6 +40,10 @@ export class ResponseType extends ReqResType {
40
40
  case 'array?':
41
41
  data[key] = this.getArray([key]);
42
42
  break;
43
+ case 'map':
44
+ case 'map?':
45
+ data[key] = this.getMap([key]);
46
+ break;
43
47
  default:
44
48
  data[key] = this.getValue([key]);
45
49
  break;
@@ -85,6 +89,10 @@ export class ResponseType extends ReqResType {
85
89
  case 'array?':
86
90
  resData[key] = this.getArray([...keys, key]);
87
91
  break;
92
+ case 'map':
93
+ case 'map?':
94
+ resData[key] = this.getMap([...keys, key]);
95
+ break;
88
96
  default:
89
97
  resData[key] = this.getValue([...keys, key]);
90
98
  break;
@@ -123,6 +131,10 @@ export class ResponseType extends ReqResType {
123
131
  case 'array?':
124
132
  resData.push(this.getArray([...keys, i]));
125
133
  break;
134
+ case 'map':
135
+ case 'map?':
136
+ resData.push(this.getMap([...keys, i]));
137
+ break;
126
138
  default:
127
139
  resData.push(this.getValue([...keys, i]));
128
140
  break;
@@ -132,6 +144,52 @@ export class ResponseType extends ReqResType {
132
144
  return resData;
133
145
  }
134
146
 
147
+ /**
148
+ * Retrieve array type data
149
+ * 配列型のデータを取得
150
+ * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
151
+ * @returns {Array<any> | undefined} Retrieved array data, 取得された配列データ
152
+ */
153
+ private getMap(keys: Array<string | number>) {
154
+
155
+ const data = this.getData(keys);
156
+ if (data === undefined || Array.isArray(data) === false) {
157
+ return undefined;
158
+ }
159
+
160
+ const mapProperty = this.getProperty(keys);
161
+ if (mapProperty.type !== 'map' && mapProperty.type !== 'map?') {
162
+ throw new Error(`getMapメソッドでMap型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
163
+ }
164
+
165
+ const mapData: {[key: string]: string | number} = {};
166
+ for (const [key, value] of data) {
167
+ switch (mapProperty.mapType) {
168
+ case 'number':
169
+ case 'number?':
170
+ if (this.isNumber(value) === false) {
171
+ continue;
172
+ }
173
+ mapData[key] = Number(value);
174
+ break;
175
+ case 'string':
176
+ case 'string?':
177
+ switch (typeof value) {
178
+ case 'number':
179
+ mapData[key] = value.toString();
180
+ break;
181
+ case 'string':
182
+ mapData[key] = value;
183
+ break;
184
+ default:
185
+ continue;
186
+ }
187
+ }
188
+ }
189
+
190
+ return mapData;
191
+ }
192
+
135
193
  /**
136
194
  * Retrieve data based on the provided keys
137
195
  * 指定されたキーに基づいてデータを取得