lemon-core 4.1.15 → 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.
- package/dist/common/test-helper.d.ts +2 -2
- package/dist/common/test-helper.js +24 -26
- package/dist/common/test-helper.js.map +1 -1
- package/dist/controllers/dummy-controller.js +39 -46
- package/dist/controllers/dummy-controller.js.map +1 -1
- package/dist/controllers/general-api-controller.js +95 -100
- package/dist/controllers/general-api-controller.js.map +1 -1
- package/dist/controllers/general-controller.js +81 -82
- package/dist/controllers/general-controller.js.map +1 -1
- package/dist/cores/api/api-service.d.ts +1 -1
- package/dist/cores/api/api-service.js +228 -269
- package/dist/cores/api/api-service.js.map +1 -1
- package/dist/cores/aws/aws-kms-service.d.ts +1 -2
- package/dist/cores/aws/aws-kms-service.js +143 -153
- package/dist/cores/aws/aws-kms-service.js.map +1 -1
- package/dist/cores/aws/aws-s3-service.d.ts +2 -4
- package/dist/cores/aws/aws-s3-service.js +306 -330
- package/dist/cores/aws/aws-s3-service.js.map +1 -1
- package/dist/cores/aws/aws-sns-service.js +147 -153
- package/dist/cores/aws/aws-sns-service.js.map +1 -1
- package/dist/cores/aws/aws-sqs-service.js +149 -170
- package/dist/cores/aws/aws-sqs-service.js.map +1 -1
- package/dist/cores/aws/index.js +10 -20
- package/dist/cores/aws/index.js.map +1 -1
- package/dist/cores/cache/cache-service.d.ts +2 -2
- package/dist/cores/cache/cache-service.js +435 -499
- package/dist/cores/cache/cache-service.js.map +1 -1
- package/dist/cores/config/config-service.d.ts +1 -1
- package/dist/cores/config/config-service.js +56 -63
- package/dist/cores/config/config-service.js.map +1 -1
- package/dist/cores/config/index.js +14 -24
- package/dist/cores/config/index.js.map +1 -1
- package/dist/cores/core-services.d.ts +1 -1
- package/dist/cores/dynamo/dynamo-query-service.js +37 -51
- package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
- package/dist/cores/dynamo/dynamo-scan-service.d.ts +2 -2
- package/dist/cores/dynamo/dynamo-scan-service.js +29 -40
- package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
- package/dist/cores/dynamo/dynamo-service.d.ts +2 -2
- package/dist/cores/dynamo/dynamo-service.js +528 -601
- package/dist/cores/dynamo/dynamo-service.js.map +1 -1
- package/dist/cores/dynamo/tools/expressions.js +17 -7
- package/dist/cores/dynamo/tools/expressions.js.map +1 -1
- package/dist/cores/dynamo/tools/query.js +142 -127
- package/dist/cores/dynamo/tools/query.js.map +1 -1
- package/dist/cores/dynamo/tools/scan.js +111 -97
- package/dist/cores/dynamo/tools/scan.js.map +1 -1
- package/dist/cores/dynamo/tools/serializer.js +17 -7
- package/dist/cores/dynamo/tools/serializer.js.map +1 -1
- package/dist/cores/dynamo/tools/utils.d.ts +0 -2
- package/dist/cores/dynamo/tools/utils.js.map +1 -1
- package/dist/cores/elastic/elastic6-query-service.js +307 -324
- package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
- package/dist/cores/elastic/elastic6-service.d.ts +3 -3
- package/dist/cores/elastic/elastic6-service.js +568 -647
- package/dist/cores/elastic/elastic6-service.js.map +1 -1
- package/dist/cores/elastic/hangul-service.js +52 -54
- package/dist/cores/elastic/hangul-service.js.map +1 -1
- package/dist/cores/lambda/index.js +42 -36
- package/dist/cores/lambda/index.js.map +1 -1
- package/dist/cores/lambda/lambda-alb-handler.d.ts +2 -2
- package/dist/cores/lambda/lambda-alb-handler.js +59 -72
- package/dist/cores/lambda/lambda-alb-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-cognito-handler.js +10 -19
- package/dist/cores/lambda/lambda-cognito-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -1
- package/dist/cores/lambda/lambda-cron-handler.js +14 -23
- package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js +57 -67
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-handler.d.ts +22 -22
- package/dist/cores/lambda/lambda-handler.js +93 -106
- package/dist/cores/lambda/lambda-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-notification-handler.d.ts +1 -1
- package/dist/cores/lambda/lambda-notification-handler.js +39 -50
- package/dist/cores/lambda/lambda-notification-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sns-handler.js +79 -88
- package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sqs-handler.js +79 -88
- package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-web-handler.d.ts +6 -6
- package/dist/cores/lambda/lambda-web-handler.js +387 -412
- package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-wss-handler.js +23 -32
- package/dist/cores/lambda/lambda-wss-handler.js.map +1 -1
- package/dist/cores/protocol/index.js +10 -20
- package/dist/cores/protocol/index.js.map +1 -1
- package/dist/cores/protocol/protocol-service.d.ts +3 -3
- package/dist/cores/protocol/protocol-service.js +235 -227
- package/dist/cores/protocol/protocol-service.js.map +1 -1
- package/dist/cores/storage/http-storage-service.js +65 -85
- package/dist/cores/storage/http-storage-service.js.map +1 -1
- package/dist/cores/storage/model-manager.js +66 -85
- package/dist/cores/storage/model-manager.js.map +1 -1
- package/dist/cores/storage/proxy-storage-service.d.ts +2 -2
- package/dist/cores/storage/proxy-storage-service.js +562 -599
- package/dist/cores/storage/proxy-storage-service.js.map +1 -1
- package/dist/cores/storage/redis-storage-service.js +163 -177
- package/dist/cores/storage/redis-storage-service.js.map +1 -1
- package/dist/cores/storage/storage-service.js +281 -322
- package/dist/cores/storage/storage-service.js.map +1 -1
- package/dist/engine/builder.d.ts +1 -1
- package/dist/engine/builder.js +59 -63
- package/dist/engine/builder.js.map +1 -1
- package/dist/engine/engine.d.ts +4 -4
- package/dist/engine/engine.js +9 -18
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/types.d.ts +1 -1
- package/dist/engine/utilities.d.ts +5 -5
- package/dist/engine/utilities.js +301 -293
- package/dist/engine/utilities.js.map +1 -1
- package/dist/environ.js +4 -6
- package/dist/environ.js.map +1 -1
- package/dist/extended/abstract-service.js +595 -645
- package/dist/extended/abstract-service.js.map +1 -1
- package/dist/extended/libs/sig-v4.js.map +1 -1
- package/dist/generated/field-registry.d.ts +10 -0
- package/dist/generated/field-registry.js +17 -0
- package/dist/generated/field-registry.js.map +1 -0
- package/dist/helpers/helpers.d.ts +17 -9
- package/dist/helpers/helpers.js +88 -78
- package/dist/helpers/helpers.js.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/dynamodb-value.js +2 -3
- package/dist/lib/dynamodb-value.js.map +1 -1
- package/dist/tools/express.js +4 -5
- package/dist/tools/express.js.map +1 -1
- package/dist/tools/tools.d.ts +3 -1
- package/dist/tools/tools.js +14 -21
- package/dist/tools/tools.js.map +1 -1
- package/package.json +19 -18
- package/dist/exec-cli.d.ts +0 -2
- package/dist/exec-cli.js +0 -211
- package/dist/exec-cli.js.map +0 -1
- package/dist/lib/dynamo/expressions.d.ts +0 -14
- package/dist/lib/dynamo/expressions.js +0 -212
- package/dist/lib/dynamo/expressions.js.map +0 -1
- package/dist/lib/dynamo/query.d.ts +0 -43
- package/dist/lib/dynamo/query.js +0 -246
- package/dist/lib/dynamo/query.js.map +0 -1
- package/dist/lib/dynamo/scan.d.ts +0 -33
- package/dist/lib/dynamo/scan.js +0 -172
- package/dist/lib/dynamo/scan.js.map +0 -1
- package/dist/lib/dynamo/serializer.d.ts +0 -12
- package/dist/lib/dynamo/serializer.js +0 -243
- package/dist/lib/dynamo/serializer.js.map +0 -1
- package/dist/lib/dynamo/utils.d.ts +0 -15
- package/dist/lib/dynamo/utils.js +0 -129
- package/dist/lib/dynamo/utils.js.map +0 -1
- package/dist/tools/shared.d.ts +0 -28
- package/dist/tools/shared.js +0 -143
- 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
|
-
*
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
|
354
|
-
const fn =
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
|
413
|
-
const fn =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
453
|
-
|
|
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
|
-
|
|
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
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
else
|
|
659
|
-
throw err;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
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);
|