record-replay-req-res-scenario 16.5.12 → 16.5.15

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 (44) hide show
  1. package/assets/shared/shared_folder_info.txt +1 -1
  2. package/browser/esm2022/lib/index.mjs +3 -2
  3. package/browser/esm2022/public-api.mjs +1 -1
  4. package/browser/esm2022/record-replay-req-res-scenario.mjs +1 -1
  5. package/browser/fesm2022/record-replay-req-res-scenario.mjs +2 -18
  6. package/browser/fesm2022/record-replay-req-res-scenario.mjs.map +1 -1
  7. package/browser/lib/index.d.ts +1 -1
  8. package/client/esm2022/lib/index.mjs +3 -2
  9. package/client/esm2022/public-api.mjs +1 -1
  10. package/client/esm2022/record-replay-req-res-scenario.mjs +1 -1
  11. package/client/fesm2022/record-replay-req-res-scenario.mjs +2 -18
  12. package/client/fesm2022/record-replay-req-res-scenario.mjs.map +1 -1
  13. package/client/lib/index.d.ts +1 -1
  14. package/client/package.json +37 -34
  15. package/lib/index.d.ts +1 -3
  16. package/lib/index.js +9 -8
  17. package/lib/index.js.map +1 -1
  18. package/lib/record-replay-req-res-scenario.d.ts +0 -52
  19. package/lib/record-replay-req-res-scenario.js +371 -365
  20. package/lib/record-replay-req-res-scenario.js.map +1 -1
  21. package/lib/scenario.backend.d.ts +0 -42
  22. package/lib/scenario.backend.js +231 -250
  23. package/lib/scenario.backend.js.map +1 -1
  24. package/lib/start.backend.d.ts +0 -1
  25. package/lib/start.backend.js +19 -46
  26. package/lib/start.backend.js.map +1 -1
  27. package/lib/tape.backend.d.ts +0 -15
  28. package/lib/tape.backend.js +27 -20
  29. package/lib/tape.backend.js.map +1 -1
  30. package/package.json +8 -5
  31. package/package.json_tnp.json5 +3 -0
  32. package/tmp-environment.json +41 -45
  33. package/websql/esm2022/lib/index.mjs +3 -2
  34. package/websql/esm2022/public-api.mjs +1 -1
  35. package/websql/esm2022/record-replay-req-res-scenario.mjs +1 -1
  36. package/websql/fesm2022/record-replay-req-res-scenario.mjs +2 -18
  37. package/websql/fesm2022/record-replay-req-res-scenario.mjs.map +1 -1
  38. package/websql/lib/index.d.ts +1 -1
  39. package/browser/esm2022/lib/record-replay-req-res-scenario.mjs +0 -18
  40. package/browser/lib/record-replay-req-res-scenario.d.ts +0 -19
  41. package/client/esm2022/lib/record-replay-req-res-scenario.mjs +0 -18
  42. package/client/lib/record-replay-req-res-scenario.d.ts +0 -19
  43. package/websql/esm2022/lib/record-replay-req-res-scenario.mjs +0 -18
  44. package/websql/lib/record-replay-req-res-scenario.d.ts +0 -19
@@ -1,366 +1,372 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecordReplayReqResScenario = void 0;
4
- var tslib_1 = require("tslib");
5
- //#region imports
6
- //#region @backend
7
- var _ = require("lodash");
8
- var path = require("path");
9
- var tnp_helpers_1 = require("tnp-helpers");
10
- var url_1 = require("url");
11
- var tnp_config_1 = require("tnp-config");
12
- var moment = require("moment");
13
- var ng_talkback_1 = require("ng-talkback");
14
- var glob = require("glob");
15
- var scenario_backend_1 = require("./scenario.backend");
16
- var chalk_1 = require("chalk");
17
- var inquirer = require("inquirer");
18
- //#endregion
19
- var RecordReplayReqResScenario = exports.RecordReplayReqResScenario = /** @class */ (function () {
20
- function RecordReplayReqResScenario(cwd) {
21
- if (cwd === void 0) { cwd = process.cwd(); }
22
- this.cwd = cwd;
23
- //#region @backend
24
- //#region consts
25
- /**
26
- * by pinging to http://localhost:5544/path/to/something
27
- * you are actually recording request from
28
- * by pinging to http://< host for recording >/path/to/something
29
- */
30
- this.DEFAULT_TALKBACK_PROXY_SERVER_PORT = 5544;
31
- var pathToScenarios = path.join(cwd, tnp_config_1.config.folder.scenarios);
32
- var pathToScenariosTemp = path.join(cwd, tnp_config_1.config.folder.tmpScenarios);
33
- if (!tnp_helpers_1.Helpers.exists(pathToScenarios)) {
34
- tnp_helpers_1.Helpers.createSymLink(pathToScenariosTemp, pathToScenarios, { continueWhenExistedFolderDoesntExists: true });
35
- }
36
- }
37
- RecordReplayReqResScenario.Instance = function (cwd) {
38
- if (cwd === void 0) { cwd = process.cwd(); }
39
- if (!RecordReplayReqResScenario._instances[cwd]) {
40
- RecordReplayReqResScenario._instances[cwd] = new RecordReplayReqResScenario(cwd);
41
- }
42
- return RecordReplayReqResScenario._instances[cwd];
43
- };
44
- //#endregion
45
- //#region resolve recoard args
46
- RecordReplayReqResScenario.prototype.resolveArgsRecord = function (serverHostOrPort) {
47
- var _a;
48
- var results = [];
49
- var configMeta = ((_.isObject(serverHostOrPort) && !_.isArray(serverHostOrPort))
50
- ? serverHostOrPort : void 0);
51
- var scenarioName = '';
52
- var talkbackPorts = [this.DEFAULT_TALKBACK_PROXY_SERVER_PORT];
53
- if (configMeta) {
54
- //#region by config
55
- scenarioName = configMeta.scenarioName;
56
- _.keys(configMeta)
57
- .filter(function (key) { return _.isObject(configMeta[key]); })
58
- .forEach(function (name, i) {
59
- var url = tnp_helpers_1.Helpers.urlParse(configMeta[name].host);
60
- results.push({
61
- record: {
62
- name: name,
63
- url: url
64
- },
65
- talkbackProxyPort: Number(configMeta[name].talkbackProxyPort) + i
66
- });
67
- });
68
- //#endregion
69
- }
70
- else {
71
- //#region by command line argument
72
- var commandString = (_a = tnp_helpers_1.Helpers.cliTool.argsFromBegin(serverHostOrPort, function (a) { return tnp_helpers_1.Helpers.urlParse(a); }), _a.commandString), resolved = _a.resolved;
73
- scenarioName = commandString;
74
- var options = tnp_helpers_1.Helpers.cliTool.argsFrom(scenarioName);
75
- scenarioName = tnp_helpers_1.Helpers.cliTool.cleanCommand(scenarioName, options);
76
- if (_.isArray(options.port)) {
77
- talkbackPorts = options.port;
78
- }
79
- else if (!isNaN(Number(options.port))) {
80
- talkbackPorts = [Number(options.port)];
81
- }
82
- var hostName_1 = _.isString(options.hostName) ? [options.hostName]
83
- : (_.isArray(options.hostName) ? options.hostName : []);
84
- if (talkbackPorts.length === 0) {
85
- tnp_helpers_1.Helpers.error("[rec-scenario-rep-rec] Incorrect configuration of ports:\n recordHosts = ".concat(resolved.map(function (c) { return tnp_helpers_1.Helpers.urlParse(c); }).join(', '), "\n talkback ports = ").concat(talkbackPorts.join(', '), "\n\n "), false, true);
86
- }
87
- if (talkbackPorts.length < resolved.length) {
88
- var lastN_1 = talkbackPorts[talkbackPorts.length - 1];
89
- _.times((resolved.length - talkbackPorts.length), function (i) { return talkbackPorts.push(lastN_1 + (i + 1)); });
90
- }
91
- resolved.forEach(function (recordHost, i) {
92
- results.push({
93
- record: {
94
- name: hostName_1[i] ? hostName_1[i] : '',
95
- url: recordHost
96
- },
97
- talkbackProxyPort: talkbackPorts[i]
98
- });
99
- });
100
- //#endregion
101
- }
102
- return { args: results, scenarioName: scenarioName };
103
- };
104
- //#endregion
105
- //#region command from config
106
- RecordReplayReqResScenario.prototype.recordAsWorker = function (config, cwd) {
107
- if (cwd === void 0) { cwd = process.cwd(); }
108
- var hosts = Object
109
- .keys(config)
110
- .filter(function (hostName) { return _.isObject(config[hostName]); })
111
- .map(function (hostName) {
112
- var v = config[hostName];
113
- return v.host.origin;
114
- });
115
- var portName = Object
116
- .keys(config)
117
- .filter(function (hostName) { return _.isObject(config[hostName]); })
118
- .map(function (hostName) {
119
- var v = config[hostName];
120
- return "--port ".concat(v.talkbackProxyPort, " --hostName ").concat(hostName);
121
- });
122
- var command = "record-replay-req-res-scenario record ".concat(hosts.join(' '), " '").concat(config.scenarioName, "' ").concat(portName.join(' '));
123
- tnp_helpers_1.Helpers.run(command, { cwd: cwd }).async();
124
- };
125
- //#endregion
126
- //#region record
127
- /**
128
- * rest-scenario-rep-rec record http://localhost:4444 Recording localhost data
129
- * rest-scenario-rep-rec record http://192.168.10.22:4444 Test scenario
130
- * rest-scenario-rep-rec record 4444 local setup test
131
- * rest-scenario-rep-rec record 4444 5555 http://192.168.12.3 "my super scenario"
132
- * rest-scenario-rep-rec record 4444 5555 http://192.168.12.3 192.158.32.3 'my super scenario --port 6767'
133
- * <port or host for record > <scenario name > < talkbback server ports for proxy >
134
- * rest-scenario-rep-rec record 4444 5555 http://my.api.com 'my super scenario --port 6767 --port 7777 --port 8888'
135
- * ins.record( { portOrHost: http://192.129.23.12; name: 'localApiProxy' }, 'super scenario')
136
- */
137
- RecordReplayReqResScenario.prototype.record = function (serverHostOrPort, debug) {
138
- if (debug === void 0) { debug = false; }
139
- return tslib_1.__awaiter(this, void 0, void 0, function () {
140
- var _this = this;
141
- return tslib_1.__generator(this, function (_a) {
142
- return [2 /*return*/, new Promise(function (resolve, reject) {
143
- var _a;
144
- var currentDate = new Date();
145
- var args = (_a = _this.resolveArgsRecord(serverHostOrPort), _a.args), scenarioName = _a.scenarioName;
146
- //#region prepare main scenario folder
147
- var description = scenarioName;
148
- if (!_.isString(scenarioName) || scenarioName.trim() === '') {
149
- scenarioName = "new-scenario-".concat(_.kebabCase(moment(currentDate).format('MMMM Do YYYY, h:mm:ss a')));
150
- ;
151
- description = _.startCase(scenarioName);
152
- }
153
- var scenarioNameKebabKase = _.kebabCase(scenarioName);
154
- var scenariosFolder = path.join(_this.cwd, tnp_config_1.config.folder.tmpScenarios);
155
- var scenarioKebabPath = path.join(scenariosFolder, scenarioNameKebabKase);
156
- var packageJsonFroScenario = path.join(scenarioKebabPath, tnp_config_1.config.file.package_json);
157
- if (!tnp_helpers_1.Helpers.exists(scenariosFolder)) {
158
- tnp_helpers_1.Helpers.mkdirp(scenariosFolder);
159
- }
160
- tnp_helpers_1.Helpers.removeFolderIfExists(scenarioKebabPath);
161
- //#endregion
162
- //#region write package.json
163
- tnp_helpers_1.Helpers.writeFile(packageJsonFroScenario, {
164
- name: scenarioNameKebabKase,
165
- description: description,
166
- version: '0.0.0',
167
- creationDate: currentDate.toDateString(),
168
- scripts: {
169
- start: 'firedev serve',
170
- },
171
- tnp: {
172
- type: 'scenario',
173
- },
174
- });
175
- //#endregion
176
- args.forEach(function (recData) {
177
- tnp_helpers_1.Helpers.log("RECORD FROM: ".concat(recData.record.url.href));
178
- var scenarioPath = path.join(_this.cwd, tnp_config_1.config.folder.tmpScenarios, scenarioNameKebabKase, "".concat((_.kebabCase(recData.record.url.href)).toString(), "__").concat(_.camelCase(recData.record.name)));
179
- tnp_helpers_1.Helpers.remove(scenarioPath);
180
- var talkbackHost = recData.record.url.origin;
181
- debug && tnp_helpers_1.Helpers.info("Talkback host: ".concat(talkbackHost));
182
- var server = (0, ng_talkback_1.talkback)({
183
- host: talkbackHost,
184
- record: ng_talkback_1.RecordMode.NEW,
185
- port: recData.talkbackProxyPort,
186
- path: scenarioPath,
187
- silent: true,
188
- // debug: true
189
- });
190
- server.start(function () {
191
- var _a;
192
- tnp_helpers_1.Helpers.info("\"Talkback Started\" on port ".concat(recData.talkbackProxyPort, " ")
193
- + "( click for test ".concat(chalk_1.default.bold(((_a = recData.record) === null || _a === void 0 ? void 0 : _a.name) ? recData.record.name : ''), " ")
194
- + "http://localhost:".concat(recData.talkbackProxyPort, "/ng-talkback-test ) => proxy to ").concat(recData.record.url.href));
195
- resolve(void 0);
196
- });
197
- });
198
- })];
199
- });
200
- });
201
- };
202
- Object.defineProperty(RecordReplayReqResScenario.prototype, "allScenarios", {
203
- //#endregion
204
- //#region all scenaroios
205
- get: function () {
206
- return glob.sync("".concat(path.join(this.cwd, tnp_config_1.config.folder.tmpScenarios), "/*"))
207
- .filter(function (f) { return !!tnp_helpers_1.Project.From(f); })
208
- .map(function (f) { return scenario_backend_1.Scenario.From(f); })
209
- .filter(function (f) { return !!f; });
210
- },
211
- enumerable: false,
212
- configurable: true
213
- });
214
- //#endregion
215
- //#region select scenario
216
- RecordReplayReqResScenario.prototype.selectScenario = function (goBackButtonOnList) {
217
- return tslib_1.__awaiter(this, void 0, void 0, function () {
218
- var mainMessage, choices, res;
219
- return tslib_1.__generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0:
222
- mainMessage = "Select scenario from list:";
223
- choices = scenario_backend_1.Scenario.allCurrent.map(function (c) {
224
- return { name: "\"".concat(c.description, "\""), value: c };
225
- });
226
- if (goBackButtonOnList) {
227
- choices.push({ name: '<= Go back', value: void 0 });
228
- }
229
- return [4 /*yield*/, inquirer.prompt({
230
- type: 'list',
231
- name: 'value',
232
- message: mainMessage,
233
- choices: choices
234
- })];
235
- case 1:
236
- res = _a.sent();
237
- return [2 /*return*/, res.value];
238
- }
239
- });
240
- });
241
- };
242
- //#endregion
243
- //#region resolve replay args
244
- RecordReplayReqResScenario.prototype.resolveReplayData = function (nameOrPathOrDescription, showListIfNotMatch, goBackButtonOnList) {
245
- if (showListIfNotMatch === void 0) { showListIfNotMatch = false; }
246
- if (goBackButtonOnList === void 0) { goBackButtonOnList = false; }
247
- return tslib_1.__awaiter(this, void 0, void 0, function () {
248
- var returnValue, configMeta, scenario, options, resolved, commandString, scenarios, list, matches, results, hostName, portsOrUrlsForReplayServer_1, params, maxPort_1, selectedScenario;
249
- var _a, _b;
250
- var _this = this;
251
- return tslib_1.__generator(this, function (_c) {
252
- switch (_c.label) {
253
- case 0:
254
- returnValue = { scenarios: [], params: void 0 };
255
- if (_.isObject(nameOrPathOrDescription) && !_.isArray(nameOrPathOrDescription)) {
256
- configMeta = nameOrPathOrDescription;
257
- scenario = scenario_backend_1.Scenario.From(configMeta.scenarioPath);
258
- if (!scenario) {
259
- tnp_helpers_1.Helpers.error("[rest-scenario...] Scenario not found in \"".concat(configMeta.scenarioPath, "\""), false, true);
260
- }
261
- returnValue.scenarios = [scenario];
262
- returnValue.params = _.pickBy(configMeta, _.isObject);
263
- //#endregion
264
- }
265
- else {
266
- //#region from command line
267
- nameOrPathOrDescription = (_.isArray(nameOrPathOrDescription)
268
- ? nameOrPathOrDescription.join(' ') : nameOrPathOrDescription);
269
- options = tnp_helpers_1.Helpers.cliTool.argsFrom(nameOrPathOrDescription);
270
- nameOrPathOrDescription = tnp_helpers_1.Helpers.cliTool.cleanCommand(nameOrPathOrDescription, options);
271
- resolved = (_a = tnp_helpers_1.Helpers.cliTool
272
- .argsFromBegin(nameOrPathOrDescription, function (possiblePathToScenario) {
273
- var scenarioFromPath = (path.isAbsolute(possiblePathToScenario || '') &&
274
- tnp_helpers_1.Helpers.exists(possiblePathToScenario))
275
- ? possiblePathToScenario
276
- : path.join(_this.cwd, tnp_config_1.config.folder.tmpScenarios, (possiblePathToScenario || '').trim());
277
- return scenario_backend_1.Scenario.From(scenarioFromPath);
278
- }), _a.resolved), commandString = _a.commandString;
279
- nameOrPathOrDescription = commandString;
280
- scenarios = resolved;
281
- if (scenarios.length === 0 && commandString.trim() !== '') {
282
- list = this.allScenarios;
283
- matches = (_b = tnp_helpers_1.Helpers
284
- .arrays
285
- .fuzzy(nameOrPathOrDescription, list, function (m) { return m.description; }), _b.matches), results = _b.results;
286
- scenarios = scenarios.concat(results);
287
- }
288
- hostName = _.isString(options.hostName) ? [options.hostName]
289
- : (_.isArray(options.hostName) ? options.hostName : []);
290
- portsOrUrlsForReplayServer_1 = (_.isString(options.port) ? [tnp_helpers_1.Helpers.urlParse(options.port)]
291
- : (_.isArray(options.port) ? options.port.map(function (p) { return tnp_helpers_1.Helpers.urlParse(p); })
292
- : [tnp_helpers_1.Helpers.urlParse(this.DEFAULT_TALKBACK_PROXY_SERVER_PORT)])).filter(function (u) { return u instanceof url_1.URL; });
293
- if (portsOrUrlsForReplayServer_1.length === 0) {
294
- tnp_helpers_1.Helpers.error("Please provide correct number or ports and hostnames\n host names = ".concat(hostName.map(function (c) { return tnp_helpers_1.Helpers.urlParse(c); }).join(', '), "\n talkback ports = ").concat(portsOrUrlsForReplayServer_1.join(', '), "\n "), false, true);
295
- }
296
- params = portsOrUrlsForReplayServer_1;
297
- if (hostName.length > 0) {
298
- if (hostName.length > portsOrUrlsForReplayServer_1.length) {
299
- maxPort_1 = _.maxBy(portsOrUrlsForReplayServer_1, function (p) { return Number(p.port); });
300
- _.times(hostName.length - portsOrUrlsForReplayServer_1.length, function (n) {
301
- portsOrUrlsForReplayServer_1.push(tnp_helpers_1.Helpers.urlParse(Number(maxPort_1.port) + (n + 1)));
302
- });
303
- }
304
- params = hostName.reduce(function (prev, name, i) {
305
- var _a;
306
- return _.merge(prev, (_a = {}, _a[name] = portsOrUrlsForReplayServer_1[i], _a));
307
- }, {});
308
- }
309
- returnValue.params = params;
310
- returnValue.scenarios = scenarios;
311
- //#endregion
312
- }
313
- if (!(returnValue.scenarios.length === 0)) return [3 /*break*/, 2];
314
- if (!showListIfNotMatch) return [3 /*break*/, 2];
315
- return [4 /*yield*/, this.selectScenario(goBackButtonOnList)];
316
- case 1:
317
- selectedScenario = _c.sent();
318
- returnValue.scenarios.push(selectedScenario);
319
- _c.label = 2;
320
- case 2:
321
- //#endregion
322
- return [2 /*return*/, returnValue];
323
- }
324
- });
325
- });
326
- };
327
- //#endregion
328
- //#region replay
329
- RecordReplayReqResScenario.prototype.resolveScenariosData = function (nameOrPathOrDescription, showListIfNotMatch, goBackButtonOnList) {
330
- if (showListIfNotMatch === void 0) { showListIfNotMatch = false; }
331
- if (goBackButtonOnList === void 0) { goBackButtonOnList = false; }
332
- return tslib_1.__awaiter(this, void 0, void 0, function () {
333
- var scenarios, params;
334
- var _a;
335
- return tslib_1.__generator(this, function (_b) {
336
- switch (_b.label) {
337
- case 0: return [4 /*yield*/, this.resolveReplayData(nameOrPathOrDescription, showListIfNotMatch, goBackButtonOnList)];
338
- case 1:
339
- scenarios = (_a = _b.sent(), _a.scenarios), params = _a.params;
340
- if (scenarios.length === 0) {
341
- tnp_helpers_1.Helpers.error("[record - replay - req - res - scenario]"
342
- + "Not able to find scenario by name or path \"".concat(nameOrPathOrDescription, "\""), false, true);
343
- }
344
- // const tmpScenarioInfo = (s: Scenario) => {
345
- // const paramsTmpls = _.isArray(params) ? params.map(p => ` replay on ${p}`).join(',')
346
- // : _.keys(params).reduce((a, b) => {
347
- // return `${a}\n\t${chalk.bold(b)}:${params[b].href}`
348
- // }, '')
349
- // return `> ${chalk.bold(s.basename)} "${s.description}"` +
350
- // paramsTmpls;
351
- // };
352
- // Helpers.info(`
353
- // (${chalk.bold(scenarios.length.toString())}) scenario(s) to replay: `
354
- // + `${scenarios.map(s => tmpScenarioInfo(s)).join('\n')}`
355
- // );
356
- return [2 /*return*/, { scenario: _.first(scenarios), scenarios: scenarios, params: params }];
357
- }
358
- });
359
- });
360
- };
361
- //#endregion
362
- //#region singleton
363
- RecordReplayReqResScenario._instances = {};
364
- return RecordReplayReqResScenario;
365
- }());
1
+ // //#region imports
2
+ // //#region @backend
3
+ // import * as _ from 'lodash';
4
+ // import * as path from 'path';
5
+ // import { Helpers, BaseProject as Project } from 'tnp-helpers';
6
+ // import { URL } from 'url';
7
+ // import { config } from 'tnp-config';
8
+ // import * as moment from 'moment';
9
+ // import { talkback, Options, RecordMode } from 'ng-talkback';
10
+ // import * as glob from 'glob';
11
+ // import { Scenario, ScenarioParam, ScenarioParams, ScenarioParamsReturn } from './scenario.backend';
12
+ // import chalk from 'chalk';
13
+ // import * as inquirer from 'inquirer';
14
+ // // import { Models } from 'tnp-models';
15
+ // //#endregion
16
+ // //#endregion
17
+ // //#region models
18
+ // export type RecordData = { host: number | string | URL; talkbackProxyPort?: number | string; }
19
+ // export type RecorderConfigMeta = {
20
+ // [recordHostName: string]: RecordData;
21
+ // } & { scenarioName: string; }
22
+ // export type ReplayConfigMeta = {
23
+ // [recordHostName: string]: { talkbackProxyPort?: number | string; }
24
+ // } & { scenarioPath: string; }
25
+ // type ArgsOptReplayRecordArgType = { port: string | string[]; hostName: string | string[]; };
26
+ // interface RecordArgType {
27
+ // record: {
28
+ // /**
29
+ // * url with host to record
30
+ // */
31
+ // url: URL;
32
+ // /**
33
+ // * Identifier of what was the name or id of server.
34
+ // * this metadata is usefull to replay back multiple servers
35
+ // * on different talkback ports
36
+ // */
37
+ // name: string;
38
+ // };
39
+ // /**
40
+ // * talkback port for localhost proxy
41
+ // */
42
+ // talkbackProxyPort: number;
43
+ // }
44
+ // //#endregion
45
+ // export class RecordReplayReqResScenario {
46
+ // //#region @backend
47
+ // //#region consts
48
+ // /**
49
+ // * by pinging to http://localhost:5544/path/to/something
50
+ // * you are actually recording request from
51
+ // * by pinging to http://< host for recording >/path/to/something
52
+ // */
53
+ // readonly DEFAULT_TALKBACK_PROXY_SERVER_PORT = 5544;
54
+ // //#endregion
55
+ // //#region singleton
56
+ // private static _instances = {};
57
+ // private constructor(
58
+ // protected readonly cwd = process.cwd()
59
+ // ) {
60
+ // const pathToScenarios = path.join(cwd, config.folder.scenarios);
61
+ // const pathToScenariosTemp = path.join(cwd, config.folder.tmpScenarios);
62
+ // if (!Helpers.exists(pathToScenarios)) {
63
+ // Helpers.createSymLink(pathToScenariosTemp, pathToScenarios,
64
+ // { continueWhenExistedFolderDoesntExists: true })
65
+ // }
66
+ // }
67
+ // public static Instance(cwd = process.cwd()) {
68
+ // if (!RecordReplayReqResScenario._instances[cwd]) {
69
+ // RecordReplayReqResScenario._instances[cwd] = new RecordReplayReqResScenario(cwd);
70
+ // }
71
+ // return RecordReplayReqResScenario._instances[cwd] as RecordReplayReqResScenario;
72
+ // }
73
+ // //#endregion
74
+ // //#region resolve recoard args
75
+ // private resolveArgsRecord(serverHostOrPort: string | string[] | RecorderConfigMeta)
76
+ // : { args: RecordArgType[]; scenarioName: string; } {
77
+ // const results = [] as RecordArgType[];
78
+ // const configMeta = ((_.isObject(serverHostOrPort) && !_.isArray(serverHostOrPort))
79
+ // ? serverHostOrPort : void 0) as RecorderConfigMeta;
80
+ // let scenarioName = '' as string;
81
+ // let talkbackPorts = [this.DEFAULT_TALKBACK_PROXY_SERVER_PORT];
82
+ // if (configMeta) {
83
+ // //#region by config
84
+ // scenarioName = configMeta.scenarioName;
85
+ // _.keys(configMeta)
86
+ // .filter(key => _.isObject(configMeta[key]))
87
+ // .forEach((name, i) => {
88
+ // const url = Helpers.urlParse(configMeta[name].host);
89
+ // results.push({
90
+ // record: {
91
+ // name,
92
+ // url
93
+ // },
94
+ // talkbackProxyPort: Number(configMeta[name].talkbackProxyPort) + i
95
+ // })
96
+ // })
97
+ // //#endregion
98
+ // } else {
99
+ // //#region by command line argument
100
+ // const { commandString, resolved } = Helpers.cliTool.argsFromBegin<URL>(
101
+ // serverHostOrPort as string,
102
+ // a => Helpers.urlParse(a)
103
+ // );
104
+ // scenarioName = commandString;
105
+ // let options = Helpers.cliTool.argsFrom<{ port: string; hostName: string; }>(scenarioName);
106
+ // scenarioName = Helpers.cliTool.cleanCommand(scenarioName, options);
107
+ // if (_.isArray(options.port)) {
108
+ // talkbackPorts = options.port;
109
+ // } else if (!isNaN(Number(options.port))) {
110
+ // talkbackPorts = [Number(options.port)];
111
+ // }
112
+ // const hostName = _.isString(options.hostName) ? [options.hostName]
113
+ // : (_.isArray(options.hostName) ? options.hostName : [])
114
+ // if (talkbackPorts.length === 0) {
115
+ // Helpers.error(`[rec-scenario-rep-rec] Incorrect configuration of ports:
116
+ // recordHosts = ${resolved.map(c => Helpers.urlParse(c)).join(', ')}
117
+ // talkback ports = ${talkbackPorts.join(', ')}
118
+ // `, false, true);
119
+ // }
120
+ // if (talkbackPorts.length < resolved.length) {
121
+ // const lastN = talkbackPorts[talkbackPorts.length - 1];
122
+ // _.times((resolved.length - talkbackPorts.length), (i) => talkbackPorts.push(lastN + (i + 1)));
123
+ // }
124
+ // resolved.forEach((recordHost, i) => {
125
+ // results.push({
126
+ // record: {
127
+ // name: hostName[i] ? hostName[i] : '',
128
+ // url: recordHost
129
+ // },
130
+ // talkbackProxyPort: talkbackPorts[i]
131
+ // })
132
+ // });
133
+ // //#endregion
134
+ // }
135
+ // return { args: results, scenarioName };
136
+ // }
137
+ // //#endregion
138
+ // //#region command from config
139
+ // public recordAsWorker(config: RecorderConfigMeta, cwd: string = process.cwd()) {
140
+ // const hosts = Object
141
+ // .keys(config)
142
+ // .filter(hostName => _.isObject(config[hostName]))
143
+ // .map(hostName => {
144
+ // const v = config[hostName] as RecordData;
145
+ // return (v.host as URL).origin;
146
+ // });
147
+ // const portName = Object
148
+ // .keys(config)
149
+ // .filter(hostName => _.isObject(config[hostName]))
150
+ // .map(hostName => {
151
+ // const v = config[hostName] as RecordData;
152
+ // return `--port ${v.talkbackProxyPort} --hostName ${hostName}`
153
+ // })
154
+ // let command = `record-replay-req-res-scenario record ${hosts.join(' ')} '${config.scenarioName}' ${portName.join(' ')}`;
155
+ // Helpers.run(command, { cwd }).async();
156
+ // }
157
+ // //#endregion
158
+ // //#region record
159
+ // /**
160
+ // * rest-scenario-rep-rec record http://localhost:4444 Recording localhost data
161
+ // * rest-scenario-rep-rec record http://192.168.10.22:4444 Test scenario
162
+ // * rest-scenario-rep-rec record 4444 local setup test
163
+ // * rest-scenario-rep-rec record 4444 5555 http://192.168.12.3 "my super scenario"
164
+ // * rest-scenario-rep-rec record 4444 5555 http://192.168.12.3 192.158.32.3 'my super scenario --port 6767'
165
+ // * <port or host for record > <scenario name > < talkbback server ports for proxy >
166
+ // * rest-scenario-rep-rec record 4444 5555 http://my.api.com 'my super scenario --port 6767 --port 7777 --port 8888'
167
+ // * ins.record( { portOrHost: http://192.129.23.12; name: 'localApiProxy' }, 'super scenario')
168
+ // */
169
+ // async record(serverHostOrPort: string | string[] | RecorderConfigMeta, debug = false) {
170
+ // return new Promise((resolve, reject) => {
171
+ // const currentDate = new Date();
172
+ // let { args, scenarioName } = this.resolveArgsRecord(serverHostOrPort);
173
+ // //#region prepare main scenario folder
174
+ // let description = scenarioName;
175
+ // if (!_.isString(scenarioName) || scenarioName.trim() === '') {
176
+ // scenarioName = `new-scenario-${_.kebabCase(moment(currentDate).format('MMMM Do YYYY, h:mm:ss a'))}`;;
177
+ // description = _.startCase(scenarioName);
178
+ // }
179
+ // const scenarioNameKebabKase = _.kebabCase(scenarioName);
180
+ // const scenariosFolder = path.join(this.cwd, config.folder.tmpScenarios);
181
+ // const scenarioKebabPath = path.join(scenariosFolder, scenarioNameKebabKase);
182
+ // const packageJsonFroScenario = path.join(scenarioKebabPath, config.file.package_json);
183
+ // if (!Helpers.exists(scenariosFolder)) {
184
+ // Helpers.mkdirp(scenariosFolder);
185
+ // }
186
+ // Helpers.removeFolderIfExists(scenarioKebabPath);
187
+ // //#endregion
188
+ // //#region write package.json
189
+ // Helpers.writeFile(packageJsonFroScenario, {
190
+ // name: scenarioNameKebabKase,
191
+ // description,
192
+ // version: '0.0.0',
193
+ // creationDate: currentDate.toDateString(),
194
+ // scripts: {
195
+ // start: 'firedev serve',
196
+ // },
197
+ // tnp: {
198
+ // type: 'scenario',
199
+ // } as any,
200
+ // } as Partial<Models.npm.IPackageJSON>);
201
+ // //#endregion
202
+ // args.forEach(recData => {
203
+ // Helpers.log(`RECORD FROM: ${recData.record.url.href}`)
204
+ // const scenarioPath = path.join(
205
+ // this.cwd,
206
+ // config.folder.tmpScenarios,
207
+ // scenarioNameKebabKase,
208
+ // `${(_.kebabCase(recData.record.url.href)).toString()}__${_.camelCase(recData.record.name)}`
209
+ // );
210
+ // Helpers.remove(scenarioPath);
211
+ // const talkbackHost = recData.record.url.origin;
212
+ // debug && Helpers.info(`Talkback host: ${talkbackHost}`)
213
+ // const server = talkback({
214
+ // host: talkbackHost,
215
+ // record: RecordMode.NEW,
216
+ // port: recData.talkbackProxyPort,
217
+ // path: scenarioPath,
218
+ // silent: true,
219
+ // // debug: true
220
+ // } as Options);
221
+ // server.start(() => {
222
+ // Helpers.info(`"Talkback Started" on port ${recData.talkbackProxyPort} `
223
+ // + `( click for test ${chalk.bold(recData.record?.name ? recData.record.name : '')} `
224
+ // + `http://localhost:${recData.talkbackProxyPort}/ng-talkback-test ) => proxy to ${recData.record.url.href}`);
225
+ // resolve(void 0);
226
+ // });
227
+ // })
228
+ // });
229
+ // }
230
+ // //#endregion
231
+ // //#region all scenaroios
232
+ // public get allScenarios() {
233
+ // return glob.sync(`${path.join(this.cwd, config.folder.tmpScenarios)}/*`)
234
+ // .filter(f => !!Project.ins.From(f))
235
+ // .map(f => Scenario.From(f))
236
+ // .filter(f => !!f)
237
+ // }
238
+ // //#endregion
239
+ // //#region select scenario
240
+ // async selectScenario(goBackButtonOnList?: boolean): Promise<Scenario> {
241
+ // const mainMessage = `Select scenario from list:`;
242
+ // const choices = Scenario.allCurrent.map(c => {
243
+ // return { name: `"${c.description}"`, value: c }
244
+ // });
245
+ // if (goBackButtonOnList) {
246
+ // choices.push({ name: '<= Go back', value: void 0 });
247
+ // }
248
+ // const res = await inquirer.prompt({
249
+ // type: 'list',
250
+ // name: 'value',
251
+ // message: mainMessage,
252
+ // choices
253
+ // } as any) as any;
254
+ // return res.value;
255
+ // }
256
+ // //#endregion
257
+ // //#region resolve replay args
258
+ // private async resolveReplayData(
259
+ // nameOrPathOrDescription: string | string[] | ReplayConfigMeta,
260
+ // showListIfNotMatch = false,
261
+ // goBackButtonOnList = false,
262
+ // ) {
263
+ // const returnValue = { scenarios: [] as Scenario[], params: void 0 as ScenarioParamsReturn }
264
+ // if (_.isObject(nameOrPathOrDescription) && !_.isArray(nameOrPathOrDescription)) {
265
+ // //#region config
266
+ // const configMeta = nameOrPathOrDescription as ReplayConfigMeta;
267
+ // const scenario = Scenario.From(configMeta.scenarioPath)
268
+ // if (!scenario) {
269
+ // Helpers.error(`[rest-scenario...] Scenario not found in "${configMeta.scenarioPath}"`
270
+ // , false, true)
271
+ // }
272
+ // returnValue.scenarios = [scenario];
273
+ // returnValue.params = _.pickBy(configMeta, _.isObject) as ScenarioParamsReturn;
274
+ // //#endregion
275
+ // } else {
276
+ // //#region from command line
277
+ // nameOrPathOrDescription = (_.isArray(nameOrPathOrDescription)
278
+ // ? nameOrPathOrDescription.join(' ') : nameOrPathOrDescription) as string;
279
+ // const options = Helpers.cliTool.argsFrom<ArgsOptReplayRecordArgType>(nameOrPathOrDescription);
280
+ // nameOrPathOrDescription = Helpers.cliTool.cleanCommand(nameOrPathOrDescription, options);
281
+ // const { resolved, commandString } = Helpers.cliTool
282
+ // .argsFromBegin<Scenario>(nameOrPathOrDescription, possiblePathToScenario => {
283
+ // const scenarioFromPath = (
284
+ // path.isAbsolute(possiblePathToScenario || '') &&
285
+ // Helpers.exists(possiblePathToScenario))
286
+ // ? possiblePathToScenario
287
+ // : path.join(
288
+ // this.cwd,
289
+ // config.folder.tmpScenarios,
290
+ // (possiblePathToScenario || '').trim());
291
+ // return Scenario.From(scenarioFromPath);
292
+ // });
293
+ // nameOrPathOrDescription = commandString;
294
+ // let scenarios = resolved;
295
+ // if (scenarios.length === 0 && commandString.trim() !== '') {
296
+ // const list = this.allScenarios;
297
+ // const { matches, results } = Helpers
298
+ // .arrays
299
+ // .fuzzy<Scenario>(nameOrPathOrDescription, list, (m) => m.description);
300
+ // scenarios = scenarios.concat(results);
301
+ // }
302
+ // const hostName = _.isString(options.hostName) ? [options.hostName]
303
+ // : (_.isArray(options.hostName) ? options.hostName : []);
304
+ // const portsOrUrlsForReplayServer = (_.isString(options.port) ? [Helpers.urlParse(options.port)]
305
+ // : (_.isArray(options.port) ? options.port.map(p => Helpers.urlParse(p))
306
+ // : [Helpers.urlParse(this.DEFAULT_TALKBACK_PROXY_SERVER_PORT)])).filter(u => u instanceof URL);
307
+ // if (portsOrUrlsForReplayServer.length === 0) {
308
+ // Helpers.error(`Please provide correct number or ports and hostnames
309
+ // host names = ${hostName.map(c => Helpers.urlParse(c)).join(', ')}
310
+ // talkback ports = ${portsOrUrlsForReplayServer.join(', ')}
311
+ // `, false, true);
312
+ // }
313
+ // let params = portsOrUrlsForReplayServer;
314
+ // if (hostName.length > 0) {
315
+ // if (hostName.length > portsOrUrlsForReplayServer.length) {
316
+ // const maxPort = _.maxBy(portsOrUrlsForReplayServer, p => Number(p.port));
317
+ // _.times(hostName.length - portsOrUrlsForReplayServer.length, n => {
318
+ // portsOrUrlsForReplayServer.push(Helpers.urlParse(Number(maxPort.port) + (n + 1)))
319
+ // });
320
+ // }
321
+ // params = hostName.reduce((prev, name, i) => {
322
+ // return _.merge(prev, { [name]: portsOrUrlsForReplayServer[i] })
323
+ // }, {}) as any;
324
+ // }
325
+ // returnValue.params = params as any;
326
+ // returnValue.scenarios = scenarios;
327
+ // //#endregion
328
+ // }
329
+ // //#region select menu scenraios
330
+ // if (returnValue.scenarios.length === 0) {
331
+ // if (showListIfNotMatch) {
332
+ // const selectedScenario = await this.selectScenario(goBackButtonOnList);
333
+ // returnValue.scenarios.push(selectedScenario);
334
+ // }
335
+ // }
336
+ // //#endregion
337
+ // return returnValue;
338
+ // }
339
+ // //#endregion
340
+ // //#region replay
341
+ // public async resolveScenariosData(
342
+ // nameOrPathOrDescription: string | string[] | ReplayConfigMeta,
343
+ // showListIfNotMatch = false,
344
+ // goBackButtonOnList = false,
345
+ // ) {
346
+ // const { scenarios, params } = await this.resolveReplayData(
347
+ // nameOrPathOrDescription,
348
+ // showListIfNotMatch,
349
+ // goBackButtonOnList,
350
+ // );
351
+ // if (scenarios.length === 0) {
352
+ // Helpers.error(`[record - replay - req - res - scenario]`
353
+ // + `Not able to find scenario by name or path "${nameOrPathOrDescription}"`, false, true);
354
+ // }
355
+ // // const tmpScenarioInfo = (s: Scenario) => {
356
+ // // const paramsTmpls = _.isArray(params) ? params.map(p => ` replay on ${p}`).join(',')
357
+ // // : _.keys(params).reduce((a, b) => {
358
+ // // return `${a}\n\t${chalk.bold(b)}:${params[b].href}`
359
+ // // }, '')
360
+ // // return `> ${chalk.bold(s.basename)} "${s.description}"` +
361
+ // // paramsTmpls;
362
+ // // };
363
+ // // Helpers.info(`
364
+ // // (${chalk.bold(scenarios.length.toString())}) scenario(s) to replay: `
365
+ // // + `${scenarios.map(s => tmpScenarioInfo(s)).join('\n')}`
366
+ // // );
367
+ // return { scenario: _.first(scenarios), scenarios, params };
368
+ // }
369
+ // //#endregion
370
+ // //#endregion
371
+ // }
366
372
  //# sourceMappingURL=record-replay-req-res-scenario.js.map