lemon-core 4.1.14 → 4.2.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 (154) hide show
  1. package/dist/common/test-helper.d.ts +2 -2
  2. package/dist/common/test-helper.js +24 -26
  3. package/dist/common/test-helper.js.map +1 -1
  4. package/dist/controllers/dummy-controller.js +39 -46
  5. package/dist/controllers/dummy-controller.js.map +1 -1
  6. package/dist/controllers/general-api-controller.js +95 -100
  7. package/dist/controllers/general-api-controller.js.map +1 -1
  8. package/dist/controllers/general-controller.js +81 -82
  9. package/dist/controllers/general-controller.js.map +1 -1
  10. package/dist/cores/api/api-service.d.ts +1 -1
  11. package/dist/cores/api/api-service.js +228 -269
  12. package/dist/cores/api/api-service.js.map +1 -1
  13. package/dist/cores/aws/aws-kms-service.d.ts +1 -2
  14. package/dist/cores/aws/aws-kms-service.js +143 -153
  15. package/dist/cores/aws/aws-kms-service.js.map +1 -1
  16. package/dist/cores/aws/aws-s3-service.d.ts +2 -4
  17. package/dist/cores/aws/aws-s3-service.js +306 -330
  18. package/dist/cores/aws/aws-s3-service.js.map +1 -1
  19. package/dist/cores/aws/aws-sns-service.js +147 -153
  20. package/dist/cores/aws/aws-sns-service.js.map +1 -1
  21. package/dist/cores/aws/aws-sqs-service.js +149 -170
  22. package/dist/cores/aws/aws-sqs-service.js.map +1 -1
  23. package/dist/cores/aws/index.js +10 -20
  24. package/dist/cores/aws/index.js.map +1 -1
  25. package/dist/cores/cache/cache-service.d.ts +2 -2
  26. package/dist/cores/cache/cache-service.js +435 -499
  27. package/dist/cores/cache/cache-service.js.map +1 -1
  28. package/dist/cores/config/config-service.d.ts +1 -1
  29. package/dist/cores/config/config-service.js +56 -63
  30. package/dist/cores/config/config-service.js.map +1 -1
  31. package/dist/cores/config/index.js +14 -24
  32. package/dist/cores/config/index.js.map +1 -1
  33. package/dist/cores/core-services.d.ts +1 -1
  34. package/dist/cores/dynamo/dynamo-query-service.js +37 -51
  35. package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
  36. package/dist/cores/dynamo/dynamo-scan-service.d.ts +2 -2
  37. package/dist/cores/dynamo/dynamo-scan-service.js +29 -40
  38. package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
  39. package/dist/cores/dynamo/dynamo-service.d.ts +2 -2
  40. package/dist/cores/dynamo/dynamo-service.js +528 -601
  41. package/dist/cores/dynamo/dynamo-service.js.map +1 -1
  42. package/dist/cores/dynamo/tools/expressions.js +17 -7
  43. package/dist/cores/dynamo/tools/expressions.js.map +1 -1
  44. package/dist/cores/dynamo/tools/query.js +142 -127
  45. package/dist/cores/dynamo/tools/query.js.map +1 -1
  46. package/dist/cores/dynamo/tools/scan.js +111 -97
  47. package/dist/cores/dynamo/tools/scan.js.map +1 -1
  48. package/dist/cores/dynamo/tools/serializer.js +17 -7
  49. package/dist/cores/dynamo/tools/serializer.js.map +1 -1
  50. package/dist/cores/dynamo/tools/utils.d.ts +0 -2
  51. package/dist/cores/dynamo/tools/utils.js.map +1 -1
  52. package/dist/cores/elastic/elastic6-query-service.js +307 -324
  53. package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
  54. package/dist/cores/elastic/elastic6-service.d.ts +3 -3
  55. package/dist/cores/elastic/elastic6-service.js +568 -647
  56. package/dist/cores/elastic/elastic6-service.js.map +1 -1
  57. package/dist/cores/elastic/hangul-service.js +52 -54
  58. package/dist/cores/elastic/hangul-service.js.map +1 -1
  59. package/dist/cores/lambda/index.js +42 -36
  60. package/dist/cores/lambda/index.js.map +1 -1
  61. package/dist/cores/lambda/lambda-alb-handler.d.ts +2 -2
  62. package/dist/cores/lambda/lambda-alb-handler.js +59 -72
  63. package/dist/cores/lambda/lambda-alb-handler.js.map +1 -1
  64. package/dist/cores/lambda/lambda-cognito-handler.js +10 -19
  65. package/dist/cores/lambda/lambda-cognito-handler.js.map +1 -1
  66. package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -1
  67. package/dist/cores/lambda/lambda-cron-handler.js +14 -23
  68. package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
  69. package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
  70. package/dist/cores/lambda/lambda-dynamo-stream-handler.js +57 -67
  71. package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
  72. package/dist/cores/lambda/lambda-handler.d.ts +22 -22
  73. package/dist/cores/lambda/lambda-handler.js +93 -106
  74. package/dist/cores/lambda/lambda-handler.js.map +1 -1
  75. package/dist/cores/lambda/lambda-notification-handler.d.ts +1 -1
  76. package/dist/cores/lambda/lambda-notification-handler.js +39 -50
  77. package/dist/cores/lambda/lambda-notification-handler.js.map +1 -1
  78. package/dist/cores/lambda/lambda-sns-handler.js +79 -88
  79. package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
  80. package/dist/cores/lambda/lambda-sqs-handler.js +79 -88
  81. package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
  82. package/dist/cores/lambda/lambda-web-handler.d.ts +21 -43
  83. package/dist/cores/lambda/lambda-web-handler.js +392 -482
  84. package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
  85. package/dist/cores/lambda/lambda-wss-handler.js +23 -32
  86. package/dist/cores/lambda/lambda-wss-handler.js.map +1 -1
  87. package/dist/cores/protocol/index.js +10 -20
  88. package/dist/cores/protocol/index.js.map +1 -1
  89. package/dist/cores/protocol/protocol-service.d.ts +3 -3
  90. package/dist/cores/protocol/protocol-service.js +235 -227
  91. package/dist/cores/protocol/protocol-service.js.map +1 -1
  92. package/dist/cores/storage/http-storage-service.js +65 -85
  93. package/dist/cores/storage/http-storage-service.js.map +1 -1
  94. package/dist/cores/storage/model-manager.js +66 -85
  95. package/dist/cores/storage/model-manager.js.map +1 -1
  96. package/dist/cores/storage/proxy-storage-service.d.ts +2 -2
  97. package/dist/cores/storage/proxy-storage-service.js +562 -599
  98. package/dist/cores/storage/proxy-storage-service.js.map +1 -1
  99. package/dist/cores/storage/redis-storage-service.js +163 -177
  100. package/dist/cores/storage/redis-storage-service.js.map +1 -1
  101. package/dist/cores/storage/storage-service.js +281 -322
  102. package/dist/cores/storage/storage-service.js.map +1 -1
  103. package/dist/engine/builder.d.ts +1 -1
  104. package/dist/engine/builder.js +59 -63
  105. package/dist/engine/builder.js.map +1 -1
  106. package/dist/engine/engine.d.ts +4 -4
  107. package/dist/engine/engine.js +9 -18
  108. package/dist/engine/engine.js.map +1 -1
  109. package/dist/engine/types.d.ts +1 -1
  110. package/dist/engine/utilities.d.ts +14 -10
  111. package/dist/engine/utilities.js +301 -280
  112. package/dist/engine/utilities.js.map +1 -1
  113. package/dist/environ.js +4 -6
  114. package/dist/environ.js.map +1 -1
  115. package/dist/extended/abstract-service.js +595 -645
  116. package/dist/extended/abstract-service.js.map +1 -1
  117. package/dist/extended/libs/sig-v4.js.map +1 -1
  118. package/dist/generated/field-registry.d.ts +10 -0
  119. package/dist/generated/field-registry.js +17 -0
  120. package/dist/generated/field-registry.js.map +1 -0
  121. package/dist/helpers/helpers.d.ts +17 -9
  122. package/dist/helpers/helpers.js +88 -78
  123. package/dist/helpers/helpers.js.map +1 -1
  124. package/dist/index.js +17 -7
  125. package/dist/index.js.map +1 -1
  126. package/dist/lib/dynamodb-value.js +2 -3
  127. package/dist/lib/dynamodb-value.js.map +1 -1
  128. package/dist/tools/express.js +4 -5
  129. package/dist/tools/express.js.map +1 -1
  130. package/dist/tools/tools.d.ts +3 -1
  131. package/dist/tools/tools.js +14 -21
  132. package/dist/tools/tools.js.map +1 -1
  133. package/package.json +19 -18
  134. package/dist/exec-cli.d.ts +0 -2
  135. package/dist/exec-cli.js +0 -211
  136. package/dist/exec-cli.js.map +0 -1
  137. package/dist/lib/dynamo/expressions.d.ts +0 -14
  138. package/dist/lib/dynamo/expressions.js +0 -212
  139. package/dist/lib/dynamo/expressions.js.map +0 -1
  140. package/dist/lib/dynamo/query.d.ts +0 -43
  141. package/dist/lib/dynamo/query.js +0 -246
  142. package/dist/lib/dynamo/query.js.map +0 -1
  143. package/dist/lib/dynamo/scan.d.ts +0 -33
  144. package/dist/lib/dynamo/scan.js +0 -172
  145. package/dist/lib/dynamo/scan.js.map +0 -1
  146. package/dist/lib/dynamo/serializer.d.ts +0 -12
  147. package/dist/lib/dynamo/serializer.js +0 -243
  148. package/dist/lib/dynamo/serializer.js.map +0 -1
  149. package/dist/lib/dynamo/utils.d.ts +0 -15
  150. package/dist/lib/dynamo/utils.js +0 -129
  151. package/dist/lib/dynamo/utils.js.map +0 -1
  152. package/dist/tools/shared.d.ts +0 -37
  153. package/dist/tools/shared.js +0 -130
  154. package/dist/tools/shared.js.map +0 -1
@@ -1,17 +1,7 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
- var _a, _b;
15
5
  Object.defineProperty(exports, "__esModule", { value: true });
16
6
  exports.MocksAPIService = exports.createHttpWebProxy = exports.APIService = exports.APIProxyClient = void 0;
17
7
  /**
@@ -37,10 +27,11 @@ const NS = engine_1.$U.NS('APIS', 'green'); // NAMESPACE TO BE PRINTED.
37
27
  * - proxed APIServiceClient
38
28
  */
39
29
  class APIProxyClient {
30
+ service;
40
31
  constructor(service) {
41
- this.hello = () => this.service.hello();
42
32
  this.service = service;
43
33
  }
34
+ hello = () => this.service.hello();
44
35
  doGet(id, cmd, param, body, hash) {
45
36
  return this.service.doGet(id, cmd, param, body, hash);
46
37
  }
@@ -63,6 +54,10 @@ exports.APIProxyClient = APIProxyClient;
63
54
  * - use internal http-proxy service due to restriction internet-face in VPC lambda.
64
55
  */
65
56
  class APIService {
57
+ type;
58
+ endpoint;
59
+ headers;
60
+ client;
66
61
  /**
67
62
  * create API service.
68
63
  *
@@ -87,8 +82,6 @@ class APIService {
87
82
  * @param proxy proxy-service to use if there is no client (or use backbone server)
88
83
  */
89
84
  constructor(type, endpoint, headers, client, proxy) {
90
- //* relay hello.
91
- this.hello = () => `api-service:${this.client.hello()}`;
92
85
  if (!endpoint)
93
86
  throw new Error('@endpoint (url) is required');
94
87
  if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://'))
@@ -108,6 +101,8 @@ class APIService {
108
101
  this.client = APIService.buildClient(this.type, this.endpoint, this.headers, BACKBONE);
109
102
  }
110
103
  }
104
+ //* relay hello.
105
+ hello = () => `api-service:${this.client.hello()}`;
111
106
  /**
112
107
  * helper to make http client
113
108
  *
@@ -162,55 +157,20 @@ class APIService {
162
157
  return new APIService.APIServiceClientRecorder(this, this.endpoint, folder);
163
158
  }
164
159
  /**
165
- * GET HOST/PATH?$param
166
- */
167
- doGet(id, cmd, $param, $body, hash) {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- return this.client.doGet(id, cmd, $param, $body, hash);
170
- });
171
- }
172
- /**
173
- * PUT HOST/PATH?$param
160
+ * class: `TypedEndpoint`
161
+ * - by using common proxy, extends endpoint by type.
162
+ * - endpoint := base+'/'+type.
174
163
  */
175
- doPut(id, cmd, $param, $body, hash) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- return this.client.doPut(id, cmd, $param, $body, hash);
178
- });
179
- }
180
- /**
181
- * POST HOST/PATH?$param
182
- */
183
- doPost(id, cmd, $param, $body, hash) {
184
- return __awaiter(this, void 0, void 0, function* () {
185
- return this.client.doPost(id, cmd, $param, $body, hash);
186
- });
187
- }
188
- /**
189
- * PATCH HOST/PATH?$param
190
- */
191
- doPatch(id, cmd, $param, $body, hash) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- return this.client.doPatch(id, cmd, $param, $body, hash);
194
- });
195
- }
196
- /**
197
- * DELETE HOST/PATH?$param
198
- */
199
- doDelete(id, cmd, $param, $body, hash) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- return this.client.doDelete(id, cmd, $param, $body, hash);
202
- });
203
- }
204
- }
205
- exports.APIService = APIService;
206
- /**
207
- * class: `TypedEndpoint`
208
- * - by using common proxy, extends endpoint by type.
209
- * - endpoint := base+'/'+type.
210
- */
211
- APIService.ProxyServiceClient = class {
212
- constructor(proxy, base, type) {
213
- this.asPath = (id, cmd) => {
164
+ static ProxyServiceClient = class {
165
+ proxy;
166
+ base;
167
+ type;
168
+ constructor(proxy, base, type) {
169
+ this.proxy = proxy;
170
+ this.base = base;
171
+ this.type = type;
172
+ }
173
+ asPath = (id, cmd) => {
214
174
  const type = this.type;
215
175
  const _isNa = (a) => a === undefined || a === null;
216
176
  return ('' +
@@ -219,14 +179,14 @@ APIService.ProxyServiceClient = class {
219
179
  (_isNa(type) || _isNa(id) || _isNa(cmd) ? '' : '/' + encodeURI(cmd)) + //NOTE - cmd could have additional '/' char.
220
180
  '');
221
181
  };
222
- this.asPath2 = (id, cmd) => {
182
+ asPath2 = (id, cmd) => {
223
183
  const _isNa = (a) => a === undefined || a === null;
224
184
  return ('' +
225
185
  (_isNa(id) ? '' : encodeURIComponent(id)) +
226
186
  (_isNa(id) || _isNa(cmd) ? '' : '/' + encodeURI(cmd)) + //NOTE - cmd could have additional '/' char.
227
187
  '');
228
188
  };
229
- this.asHostPath = (id, cmd) => {
189
+ asHostPath = (id, cmd) => {
230
190
  let host = this.base ? this.base : this.type;
231
191
  let path = this.base ? this.asPath(id, cmd) : this.asPath2(id, cmd);
232
192
  if (this.base) {
@@ -241,216 +201,215 @@ APIService.ProxyServiceClient = class {
241
201
  }
242
202
  return { host, path };
243
203
  };
244
- this.hello = () => `api-client:${this.proxy.hello()}`;
245
- this.proxy = proxy;
246
- this.base = base;
247
- this.type = type;
248
- }
249
- doGet(id, cmd, param, body, hash) {
250
- return __awaiter(this, void 0, void 0, function* () {
204
+ hello = () => `api-client:${this.proxy.hello()}`;
205
+ async doGet(id, cmd, param, body, hash) {
251
206
  const { host, path } = this.asHostPath(id, cmd);
252
207
  return this.proxy.doProxy('GET', host, path, param, body, null, hash);
253
- });
254
- }
255
- doPut(id, cmd, param, body, hash) {
256
- return __awaiter(this, void 0, void 0, function* () {
208
+ }
209
+ async doPut(id, cmd, param, body, hash) {
257
210
  const { host, path } = this.asHostPath(id, cmd);
258
211
  return this.proxy.doProxy('PUT', host, path, param, body, null, hash);
259
- });
260
- }
261
- doPost(id, cmd, param, body, hash) {
262
- return __awaiter(this, void 0, void 0, function* () {
212
+ }
213
+ async doPost(id, cmd, param, body, hash) {
263
214
  const { host, path } = this.asHostPath(id, cmd);
264
215
  return this.proxy.doProxy('POST', host, path, param, body, null, hash);
265
- });
266
- }
267
- doPatch(id, cmd, param, body, hash) {
268
- return __awaiter(this, void 0, void 0, function* () {
216
+ }
217
+ async doPatch(id, cmd, param, body, hash) {
269
218
  const { host, path } = this.asHostPath(id, cmd);
270
219
  return this.proxy.doProxy('PATCH', host, path, param, body, null, hash);
271
- });
272
- }
273
- doDelete(id, cmd, param, body, hash) {
274
- return __awaiter(this, void 0, void 0, function* () {
220
+ }
221
+ async doDelete(id, cmd, param, body, hash) {
275
222
  const { host, path } = this.asHostPath(id, cmd);
276
223
  return this.proxy.doProxy('DELETE', host, path, param, body, null, hash);
277
- });
278
- }
279
- };
280
- /**
281
- * use sub-typed endpoint.
282
- * - extends as endpoint := parent.endpoint + '/' + type
283
- */
284
- APIService.SubTypeClient = class {
285
- constructor(parent, type) {
286
- this.hello = () => `sub-typed:${this.parent.hello()}`;
287
- this.asCmd = (id, cmd) => {
224
+ }
225
+ };
226
+ /**
227
+ * use sub-typed endpoint.
228
+ * - extends as endpoint := parent.endpoint + '/' + type
229
+ */
230
+ static SubTypeClient = class {
231
+ parent;
232
+ type;
233
+ constructor(parent, type) {
234
+ this.parent = parent;
235
+ this.type = `${type || ''}`;
236
+ }
237
+ hello = () => `sub-typed:${this.parent.hello()}`;
238
+ asCmd = (id, cmd) => {
288
239
  if (id === undefined || id === null)
289
240
  return '';
290
241
  if (id != encodeURI(id))
291
242
  throw new Error(`@id (string) is not valid format.`);
292
243
  return cmd !== undefined && cmd !== null ? `${id || ''}/${cmd}` : `${id || ''}`;
293
244
  };
294
- this.parent = parent;
295
- this.type = `${type || ''}`;
296
- }
297
- doGet(id, cmd, param, body, hash) {
298
- return __awaiter(this, void 0, void 0, function* () {
245
+ async doGet(id, cmd, param, body, hash) {
299
246
  return this.parent.doGet(this.type, this.asCmd(id, cmd), param, body, hash);
300
- });
301
- }
302
- doPut(id, cmd, param, body, hash) {
303
- return __awaiter(this, void 0, void 0, function* () {
247
+ }
248
+ async doPut(id, cmd, param, body, hash) {
304
249
  return this.parent.doPut(this.type, this.asCmd(id, cmd), param, body, hash);
305
- });
306
- }
307
- doPost(id, cmd, param, body, hash) {
308
- return __awaiter(this, void 0, void 0, function* () {
250
+ }
251
+ async doPost(id, cmd, param, body, hash) {
309
252
  return this.parent.doPost(this.type, this.asCmd(id, cmd), param, body, hash);
310
- });
311
- }
312
- doPatch(id, cmd, param, body, hash) {
313
- return __awaiter(this, void 0, void 0, function* () {
253
+ }
254
+ async doPatch(id, cmd, param, body, hash) {
314
255
  return this.parent.doPatch(this.type, this.asCmd(id, cmd), param, body, hash);
315
- });
316
- }
317
- doDelete(id, cmd, param, body, hash) {
318
- return __awaiter(this, void 0, void 0, function* () {
256
+ }
257
+ async doDelete(id, cmd, param, body, hash) {
319
258
  return this.parent.doDelete(this.type, this.asCmd(id, cmd), param, body, hash);
320
- });
321
- }
322
- };
323
- /**
324
- * recorder of api-http-proxy client.
325
- */
326
- APIService.ApiHttpProxyRecorder = (_a = class {
259
+ }
260
+ };
261
+ /**
262
+ * recorder of api-http-proxy client.
263
+ */
264
+ static ApiHttpProxyRecorder = class {
265
+ target;
266
+ folder;
267
+ static next = 1;
327
268
  constructor(target, folder) {
328
- this.hello = () => `recorder:${this.target.hello()}`;
329
269
  this.target = target;
330
270
  this.folder = `${folder || './logs'}`;
331
271
  }
332
- doProxy(method, host, path, param, body, context, hash) {
333
- return __awaiter(this, void 0, void 0, function* () {
334
- const endpoint = host.startsWith('http://') || host.startsWith('https://') ? `${host}${path}` : `http://${host}${path}`;
335
- const index = APIService.ApiHttpProxyRecorder.next++;
336
- const load = { method, endpoint, param, body, context };
337
- return this.target
338
- .doProxy(method, host, path, param, body, context, hash)
339
- .then((data) => ({ index, load, data, error: null }))
340
- .catch((error) => ({ index, load, data: null, error }))
341
- .then(({ index, load, data, error }) => {
342
- const baseDir = (() => {
343
- // eslint-disable-next-line prettier/prettier
344
- const ts = engine_1.$U.ts().substring(0, '1999-01-01'.length).replace(/\-/ig, '');
345
- const fn = `${this.folder}/R${ts}`;
346
- if (index <= 1 && !fs_1.default.existsSync(`${this.folder}`))
347
- fs_1.default.mkdirSync(`${this.folder}`);
348
- if (index <= 1 && !fs_1.default.existsSync(fn))
349
- fs_1.default.mkdirSync(fn);
350
- return fn;
351
- })();
272
+ hello = () => `recorder:${this.target.hello()}`;
273
+ async doProxy(method, host, path, param, body, context, hash) {
274
+ const endpoint = host.startsWith('http://') || host.startsWith('https://') ? `${host}${path}` : `http://${host}${path}`;
275
+ const index = APIService.ApiHttpProxyRecorder.next++;
276
+ const load = { method, endpoint, param, body, context };
277
+ return this.target
278
+ .doProxy(method, host, path, param, body, context, hash)
279
+ .then((data) => ({ index, load, data, error: null }))
280
+ .catch((error) => ({ index, load, data: null, error }))
281
+ .then(({ index, load, data, error }) => {
282
+ const baseDir = (() => {
352
283
  // eslint-disable-next-line prettier/prettier
353
- const message = error instanceof Error ? `${error.message}` : typeof error != 'object' ? `${error}` : error ? JSON.stringify(error) : '';
354
- const fn = (n) => {
355
- const [S, s] = ['00000', `${n}`];
356
- return n > 0 ? `${S.substring(s.length)}${s}` : s.startsWith('-') ? `N${s.substring(1)}` : s;
357
- };
358
- const file = `${baseDir}/P${fn(index)}.json`;
359
- fs_1.default.writeFileSync(file, JSON.stringify({ param: load, data, error: message }, null, ' '), 'utf8');
360
- if (error)
361
- throw error;
362
- else
363
- return data;
364
- });
284
+ const ts = engine_1.$U.ts().substring(0, '1999-01-01'.length).replace(/\-/ig, '');
285
+ const fn = `${this.folder}/R${ts}`;
286
+ if (index <= 1 && !fs_1.default.existsSync(`${this.folder}`))
287
+ fs_1.default.mkdirSync(`${this.folder}`);
288
+ if (index <= 1 && !fs_1.default.existsSync(fn))
289
+ fs_1.default.mkdirSync(fn);
290
+ return fn;
291
+ })();
292
+ // eslint-disable-next-line prettier/prettier
293
+ const message = error instanceof Error ? `${error.message}` : typeof error != 'object' ? `${error}` : error ? JSON.stringify(error) : '';
294
+ const fn = (n) => {
295
+ const [S, s] = ['00000', `${n}`];
296
+ return n > 0 ? `${S.substring(s.length)}${s}` : s.startsWith('-') ? `N${s.substring(1)}` : s;
297
+ };
298
+ const file = `${baseDir}/P${fn(index)}.json`;
299
+ fs_1.default.writeFileSync(file, JSON.stringify({ param: load, data, error: message }, null, ' '), 'utf8');
300
+ if (error)
301
+ throw error;
302
+ else
303
+ return data;
365
304
  });
366
305
  }
367
- },
368
- _a.next = 1,
369
- _a);
370
- /**
371
- * recorder of api-service client.
372
- */
373
- APIService.APIServiceClientRecorder = (_b = class {
306
+ };
307
+ /**
308
+ * recorder of api-service client.
309
+ */
310
+ static APIServiceClientRecorder = class {
311
+ target;
312
+ endpoint;
313
+ folder;
314
+ static next = 1;
374
315
  constructor(target, endpoint, folder) {
375
- this.hello = () => `recorder:${this.target.hello()}`;
376
316
  this.target = target;
377
317
  this.endpoint = `${endpoint || ''}`;
378
318
  this.folder = `${folder || './logs'}`;
379
319
  }
380
- doRecord(method, id, cmd, param, body, hash) {
381
- return __awaiter(this, void 0, void 0, function* () {
382
- const index = APIService.APIServiceClientRecorder.next++;
383
- const load = { method, endpoint: `${this.endpoint || ''}`, id, cmd, param, body };
384
- const call = (method) => __awaiter(this, void 0, void 0, function* () {
385
- if (method == 'GET')
386
- return this.target.doGet(id, cmd, param, body, hash);
387
- if (method == 'PUT')
388
- return this.target.doPut(id, cmd, param, body, hash);
389
- if (method == 'POST')
390
- return this.target.doPost(id, cmd, param, body, hash);
391
- if (method == 'PATCH')
392
- return this.target.doPatch(id, cmd, param, body, hash);
393
- if (method == 'DELETE')
394
- return this.target.doDelete(id, cmd, param, body, hash);
395
- throw new Error(`@method is not valid. method:${method}`);
396
- });
397
- return call(method)
398
- .then((data) => ({ index, load, data, error: null }))
399
- .catch((error) => ({ index, load, data: null, error }))
400
- .then(({ index, load, data, error }) => {
401
- const baseDir = (() => {
402
- // eslint-disable-next-line prettier/prettier
403
- const ts = engine_1.$U.ts().substring(0, '1999-01-01'.length).replace(/\-/ig, '');
404
- const fn = `${this.folder}/R${ts}`;
405
- if (index <= 1 && !fs_1.default.existsSync(`${this.folder}`))
406
- fs_1.default.mkdirSync(`${this.folder}`);
407
- if (index <= 1 && !fs_1.default.existsSync(fn))
408
- fs_1.default.mkdirSync(fn);
409
- return fn;
410
- })();
320
+ hello = () => `recorder:${this.target.hello()}`;
321
+ async doRecord(method, id, cmd, param, body, hash) {
322
+ const index = APIService.APIServiceClientRecorder.next++;
323
+ const load = { method, endpoint: `${this.endpoint || ''}`, id, cmd, param, body };
324
+ const call = async (method) => {
325
+ if (method == 'GET')
326
+ return this.target.doGet(id, cmd, param, body, hash);
327
+ if (method == 'PUT')
328
+ return this.target.doPut(id, cmd, param, body, hash);
329
+ if (method == 'POST')
330
+ return this.target.doPost(id, cmd, param, body, hash);
331
+ if (method == 'PATCH')
332
+ return this.target.doPatch(id, cmd, param, body, hash);
333
+ if (method == 'DELETE')
334
+ return this.target.doDelete(id, cmd, param, body, hash);
335
+ throw new Error(`@method is not valid. method:${method}`);
336
+ };
337
+ return call(method)
338
+ .then((data) => ({ index, load, data, error: null }))
339
+ .catch((error) => ({ index, load, data: null, error }))
340
+ .then(({ index, load, data, error }) => {
341
+ const baseDir = (() => {
411
342
  // eslint-disable-next-line prettier/prettier
412
- const message = error instanceof Error ? `${error.message}` : typeof error != 'object' ? `${error}` : error ? JSON.stringify(error) : '';
413
- const fn = (n) => {
414
- const [S, s] = ['00000', `${n}`];
415
- return n > 0 ? `${S.substring(s.length)}${s}` : s.startsWith('-') ? `N${s.substring(1)}` : s;
416
- };
417
- const file = `${baseDir}/D${fn(index)}.json`;
418
- fs_1.default.writeFileSync(file, JSON.stringify({ param: load, data, error: message }, null, ' '), 'utf8');
419
- if (error)
420
- throw error;
421
- else
422
- return data;
423
- });
343
+ const ts = engine_1.$U.ts().substring(0, '1999-01-01'.length).replace(/\-/ig, '');
344
+ const fn = `${this.folder}/R${ts}`;
345
+ if (index <= 1 && !fs_1.default.existsSync(`${this.folder}`))
346
+ fs_1.default.mkdirSync(`${this.folder}`);
347
+ if (index <= 1 && !fs_1.default.existsSync(fn))
348
+ fs_1.default.mkdirSync(fn);
349
+ return fn;
350
+ })();
351
+ // eslint-disable-next-line prettier/prettier
352
+ const message = error instanceof Error ? `${error.message}` : typeof error != 'object' ? `${error}` : error ? JSON.stringify(error) : '';
353
+ const fn = (n) => {
354
+ const [S, s] = ['00000', `${n}`];
355
+ return n > 0 ? `${S.substring(s.length)}${s}` : s.startsWith('-') ? `N${s.substring(1)}` : s;
356
+ };
357
+ const file = `${baseDir}/D${fn(index)}.json`;
358
+ fs_1.default.writeFileSync(file, JSON.stringify({ param: load, data, error: message }, null, ' '), 'utf8');
359
+ if (error)
360
+ throw error;
361
+ else
362
+ return data;
424
363
  });
425
364
  }
426
- doGet(id, cmd, param, body, hash) {
427
- return __awaiter(this, void 0, void 0, function* () {
428
- return this.doRecord('GET', id, cmd, param, body, hash);
429
- });
365
+ async doGet(id, cmd, param, body, hash) {
366
+ return this.doRecord('GET', id, cmd, param, body, hash);
430
367
  }
431
- doPut(id, cmd, param, body, hash) {
432
- return __awaiter(this, void 0, void 0, function* () {
433
- return this.doRecord('PUT', id, cmd, param, body, hash);
434
- });
368
+ async doPut(id, cmd, param, body, hash) {
369
+ return this.doRecord('PUT', id, cmd, param, body, hash);
435
370
  }
436
- doPost(id, cmd, param, body, hash) {
437
- return __awaiter(this, void 0, void 0, function* () {
438
- return this.doRecord('POST', id, cmd, param, body, hash);
439
- });
371
+ async doPost(id, cmd, param, body, hash) {
372
+ return this.doRecord('POST', id, cmd, param, body, hash);
440
373
  }
441
- doPatch(id, cmd, param, body, hash) {
442
- return __awaiter(this, void 0, void 0, function* () {
443
- return this.doRecord('PATCH', id, cmd, param, body, hash);
444
- });
374
+ async doPatch(id, cmd, param, body, hash) {
375
+ return this.doRecord('PATCH', id, cmd, param, body, hash);
445
376
  }
446
- doDelete(id, cmd, param, body, hash) {
447
- return __awaiter(this, void 0, void 0, function* () {
448
- return this.doRecord('DELETE', id, cmd, param, body, hash);
449
- });
377
+ async doDelete(id, cmd, param, body, hash) {
378
+ return this.doRecord('DELETE', id, cmd, param, body, hash);
450
379
  }
451
- },
452
- _b.next = 1,
453
- _b);
380
+ };
381
+ /**
382
+ * GET HOST/PATH?$param
383
+ */
384
+ async doGet(id, cmd, $param, $body, hash) {
385
+ return this.client.doGet(id, cmd, $param, $body, hash);
386
+ }
387
+ /**
388
+ * PUT HOST/PATH?$param
389
+ */
390
+ async doPut(id, cmd, $param, $body, hash) {
391
+ return this.client.doPut(id, cmd, $param, $body, hash);
392
+ }
393
+ /**
394
+ * POST HOST/PATH?$param
395
+ */
396
+ async doPost(id, cmd, $param, $body, hash) {
397
+ return this.client.doPost(id, cmd, $param, $body, hash);
398
+ }
399
+ /**
400
+ * PATCH HOST/PATH?$param
401
+ */
402
+ async doPatch(id, cmd, $param, $body, hash) {
403
+ return this.client.doPatch(id, cmd, $param, $body, hash);
404
+ }
405
+ /**
406
+ * DELETE HOST/PATH?$param
407
+ */
408
+ async doDelete(id, cmd, $param, $body, hash) {
409
+ return this.client.doDelete(id, cmd, $param, $body, hash);
410
+ }
411
+ }
412
+ exports.APIService = APIService;
454
413
  /** ********************************************************************************************************************
455
414
  * BODY IMPLEMENTATION.
456
415
  ** ********************************************************************************************************************/
@@ -482,9 +441,8 @@ const createHttpWebProxy = (name, endpoint, headers, encoder, relayHeaderKey, re
482
441
  * - http proxy client via backbone's web.
483
442
  */
484
443
  return new (class {
485
- constructor() {
486
- this.hello = () => `http-web-proxy:${name}`;
487
- }
444
+ constructor() { }
445
+ hello = () => `http-web-proxy:${name}`;
488
446
  doProxy(method, path1, path2, $param, $body, ctx) {
489
447
  // const _log = console.info;
490
448
  if (!method)
@@ -593,13 +551,10 @@ exports.createHttpWebProxy = createHttpWebProxy;
593
551
  * ```
594
552
  */
595
553
  class MocksAPIService {
554
+ $map;
555
+ type;
556
+ endpoint;
596
557
  constructor(type, endpoint) {
597
- this.asPath = (id, cmd) => {
598
- const _isNa = (a) => a === undefined || a === null;
599
- return (_isNa(id) ? '' : encodeURIComponent(id)) + (_isNa(id) || !cmd ? '' : '/' + encodeURI(cmd));
600
- };
601
- this.na = (a, x, y) => (a === undefined || a === null ? x : y);
602
- this.hello = () => `mocks-api-service:${this.endpoint}${this.na(this.type, '', '/')}${this.type || ''}`;
603
558
  this.type = type;
604
559
  this.endpoint = endpoint;
605
560
  }
@@ -633,35 +588,39 @@ class MocksAPIService {
633
588
  // console.log(NS, '> $map =', $map);
634
589
  this.$map = $map;
635
590
  }
636
- doProxy(method, type, path, param, body, ctx, hash) {
637
- return __awaiter(this, void 0, void 0, function* () {
638
- // console.info(`! mocks.proxy(${method},${type},${path})...`);
639
- this.loadSync();
640
- const file = path && path.endsWith('.json') ? path.split('/').pop() : '';
641
- // eslint-disable-next-line prettier/prettier
642
- const key = `${method} ${this.endpoint}${this.na(type, '', '/')}${type || ''}${!path || path.startsWith('/') ? '' : '/'}${path || ''}`;
643
- const qs = param ? engine_1.$U.qs.stringify(param) : '';
644
- const key2 = qs ? `${key}${path.indexOf('?') > 0 ? '&' : '?'}${qs}` : key;
645
- const key3 = hash ? `${key2}${hash.startsWith('#') ? '' : '#'}${hash}` : key2;
646
- // if (param) console.info('!key[] =', [key3, key2, key]);
647
- // if (hash) console.info(`! hash[${hash}].keys =`, [key3, key2, key]);
648
- const data = this.$map[file] || this.$map[key3] || this.$map[key2] || this.$map[key];
649
- if (!data)
650
- throw new Error(`404 NOT FOUND - ${key3}`);
651
- const err = data.error;
652
- if (err && typeof err == 'string') {
653
- if (err.startsWith('{') && err.endsWith('}'))
654
- throw JSON.parse(err);
655
- else
656
- throw new Error(err);
657
- }
658
- else if (err) {
659
- throw err;
660
- }
661
- //* returns data.
662
- return data.data ? JSON.parse(engine_1.$U.json(data.data)) : data.data;
663
- });
591
+ asPath = (id, cmd) => {
592
+ const _isNa = (a) => a === undefined || a === null;
593
+ return (_isNa(id) ? '' : encodeURIComponent(id)) + (_isNa(id) || !cmd ? '' : '/' + encodeURI(cmd));
594
+ };
595
+ async doProxy(method, type, path, param, body, ctx, hash) {
596
+ // console.info(`! mocks.proxy(${method},${type},${path})...`);
597
+ this.loadSync();
598
+ const file = path && path.endsWith('.json') ? path.split('/').pop() : '';
599
+ // eslint-disable-next-line prettier/prettier
600
+ const key = `${method} ${this.endpoint}${this.na(type, '', '/')}${type || ''}${!path || path.startsWith('/') ? '' : '/'}${path || ''}`;
601
+ const qs = param ? engine_1.$U.qs.stringify(param) : '';
602
+ const key2 = qs ? `${key}${path.indexOf('?') > 0 ? '&' : '?'}${qs}` : key;
603
+ const key3 = hash ? `${key2}${hash.startsWith('#') ? '' : '#'}${hash}` : key2;
604
+ // if (param) console.info('!key[] =', [key3, key2, key]);
605
+ // if (hash) console.info(`! hash[${hash}].keys =`, [key3, key2, key]);
606
+ const data = this.$map[file] || this.$map[key3] || this.$map[key2] || this.$map[key];
607
+ if (!data)
608
+ throw new Error(`404 NOT FOUND - ${key3}`);
609
+ const err = data.error;
610
+ if (err && typeof err == 'string') {
611
+ if (err.startsWith('{') && err.endsWith('}'))
612
+ throw JSON.parse(err);
613
+ else
614
+ throw new Error(err);
615
+ }
616
+ else if (err) {
617
+ throw err;
618
+ }
619
+ //* returns data.
620
+ return data.data ? JSON.parse(engine_1.$U.json(data.data)) : data.data;
664
621
  }
622
+ na = (a, x, y) => (a === undefined || a === null ? x : y);
623
+ hello = () => `mocks-api-service:${this.endpoint}${this.na(this.type, '', '/')}${this.type || ''}`;
665
624
  doGet(id, cmd, param, body, hash) {
666
625
  const path = this.asPath(id, cmd); // use mocks.type infor
667
626
  return this.doProxy('GET', this.type, path, param, body, null, hash);