@loadmill/core 0.3.49 → 0.3.52

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 (84) hide show
  1. package/dist/conf/extrema.d.ts +1 -1
  2. package/dist/conf/extrema.js +2 -2
  3. package/dist/conf/extrema.js.map +1 -1
  4. package/dist/conf/types.d.ts +12 -0
  5. package/dist/conf/validate.d.ts +2 -1
  6. package/dist/conf/validate.js +6 -1
  7. package/dist/conf/validate.js.map +1 -1
  8. package/dist/multipart-form-data/form-data-utils.js +2 -2
  9. package/dist/multipart-form-data/form-data-utils.js.map +1 -1
  10. package/dist/multipart-form-data/is-binary-file.d.ts +2 -0
  11. package/dist/multipart-form-data/is-binary-file.js +215 -0
  12. package/dist/multipart-form-data/is-binary-file.js.map +1 -0
  13. package/dist/multipart-form-data/multipart-text-to-post-form-data.d.ts +5 -1
  14. package/dist/multipart-form-data/multipart-text-to-post-form-data.js +96 -35
  15. package/dist/multipart-form-data/multipart-text-to-post-form-data.js.map +1 -1
  16. package/dist/parameters/extractions.d.ts +2 -1
  17. package/dist/parameters/extractions.js.map +1 -1
  18. package/dist/parameters/index.d.ts +1 -1
  19. package/dist/parameters/index.js +4 -0
  20. package/dist/parameters/index.js.map +1 -1
  21. package/dist/parameters/parameter-regex-providers.d.ts +2 -0
  22. package/dist/parameters/parameter-regex-providers.js +3 -1
  23. package/dist/parameters/parameter-regex-providers.js.map +1 -1
  24. package/dist/request/index.d.ts +1 -0
  25. package/dist/request/index.js +5 -5
  26. package/dist/request/index.js.map +1 -1
  27. package/package.json +7 -2
  28. package/src/conf/defaults.ts +0 -25
  29. package/src/conf/extrema.ts +0 -35
  30. package/src/conf/index.ts +0 -95
  31. package/src/conf/notifications.ts +0 -17
  32. package/src/conf/types.ts +0 -86
  33. package/src/conf/validate.ts +0 -548
  34. package/src/distributed-logger-reporter.ts +0 -19
  35. package/src/echo/firehose.ts +0 -64
  36. package/src/echo/index.ts +0 -4
  37. package/src/echo/stats.ts +0 -84
  38. package/src/har/index.ts +0 -81
  39. package/src/multipart-form-data/form-data-utils.ts +0 -81
  40. package/src/multipart-form-data/multipart-text-to-post-form-data.ts +0 -89
  41. package/src/parameters/extractions.ts +0 -51
  42. package/src/parameters/extractors/cheerio-extractor.ts +0 -57
  43. package/src/parameters/extractors/expression-extractor.ts +0 -13
  44. package/src/parameters/extractors/extractor.ts +0 -3
  45. package/src/parameters/extractors/header-extractor.ts +0 -24
  46. package/src/parameters/extractors/index.ts +0 -10
  47. package/src/parameters/extractors/json-path-extractor.ts +0 -63
  48. package/src/parameters/extractors/parametrized-extractor.ts +0 -27
  49. package/src/parameters/extractors/regex-extractor.ts +0 -18
  50. package/src/parameters/extractors/regex-matcher.ts +0 -17
  51. package/src/parameters/extractors/ws-extractor.ts +0 -91
  52. package/src/parameters/generate-random.ts +0 -114
  53. package/src/parameters/index.ts +0 -621
  54. package/src/parameters/json-path-utils.ts +0 -20
  55. package/src/parameters/operators/binary-operator.ts +0 -23
  56. package/src/parameters/operators/index.ts +0 -39
  57. package/src/parameters/parameter-functions/boolean-parameter-functions.ts +0 -24
  58. package/src/parameters/parameter-functions/crypto.ts +0 -55
  59. package/src/parameters/parameter-functions/json-schema.ts +0 -29
  60. package/src/parameters/parameter-functions/numeric-input-parameter-functions.ts +0 -22
  61. package/src/parameters/parameter-functions/numeric-parameter-functions.ts +0 -37
  62. package/src/parameters/parameter-functions/parameter-function-utils.ts +0 -55
  63. package/src/parameters/parameter-functions/parameter-function.ts +0 -7
  64. package/src/parameters/parameter-functions/parameter-functions.ts +0 -54
  65. package/src/parameters/parameter-functions/random-parameter-functions.ts +0 -22
  66. package/src/parameters/parameter-functions/textual-parameter-functions.ts +0 -464
  67. package/src/parameters/parameter-regex-providers.ts +0 -74
  68. package/src/parameters/resolvers/random-parameters-resolver.ts +0 -8
  69. package/src/parameters/type.ts +0 -7
  70. package/src/parameters/value-utils.ts +0 -47
  71. package/src/request/index.ts +0 -525
  72. package/src/schema/json-schema-generator.ts +0 -76
  73. package/test/conf/validate.spec.js +0 -141
  74. package/test/har/is-har.spec.js +0 -33
  75. package/test/multipart-form-data/form-data-utils.spec.ts +0 -121
  76. package/test/multipart-form-data/resources/multipart-form-data-file-text-content.json +0 -5
  77. package/test/parameters/builtin-functions.spec.js +0 -85
  78. package/test/parameters/json-path-utils.spec.ts +0 -50
  79. package/test/parameters/parameter-functions.spec.js +0 -48
  80. package/test/parameters/parameter-utils.spec.js +0 -185
  81. package/test/parameters/regex-functions.spec.ts +0 -57
  82. package/test/parameters/value-utils.spec.js +0 -73
  83. package/test/schema/json-schema-generator.spec.js +0 -227
  84. package/tsconfig.json +0 -9
@@ -1,464 +0,0 @@
1
- import defaultTo = require('lodash/defaultTo');
2
- import isEmpty = require('lodash/isEmpty');
3
- import isEqual = require('lodash/isEqual');
4
- import uniqWith = require('lodash/uniqWith');
5
- import escapeRegExp = require('lodash/escapeRegExp');
6
- import isNaN = require('lodash/isNaN');
7
-
8
- import { RegexExtractor } from '../extractors/regex-extractor';
9
- import { CheerioExtractor } from '../extractors/cheerio-extractor';
10
- import { BasicParameterFunction } from './parameter-function-utils';
11
- import { JsonPathExtractor } from '../extractors/json-path-extractor';
12
- import {
13
- isTruthyParameterValue,
14
- parameterValueToNumber,
15
- pickRandom,
16
- RANDOM_SELECT_OPT,
17
- } from '../value-utils';
18
- import isUUID from 'validator/lib/isUUID';
19
- import * as uriUtils from '@loadmill/universal/dist/uri-utils';
20
- import { PresentableError } from '@loadmill/universal/dist/errors';
21
- import { nodeBtoa } from '@loadmill/universal/dist/string-utils';
22
- import { applyJSONSchema } from './json-schema';
23
- import { toSha, toHMAC, FORMATS, HASH } from './crypto';
24
-
25
- const MAX_NOW_LENGTH = 13; // max length UTC until 2286
26
-
27
- const nowParameterFunction = new BasicParameterFunction((length) => {
28
- const now = Date.now();
29
- if (length && +length > 0) {
30
- return ('' + now).substring(0, Math.min(+length, MAX_NOW_LENGTH));
31
- }
32
- return now;
33
- }, 0, 1);
34
-
35
- const nodeAtob = (text = '') => Buffer.from(text, 'base64').toString('utf8');
36
- export const base64decode = typeof atob !== 'undefined' ? atob : nodeAtob;
37
-
38
- export const base64encode = typeof btoa !== 'undefined' ? btoa : nodeBtoa;
39
-
40
- export const textualParameterFunctions = {
41
- __usd: new BasicParameterFunction(() => '$', 0, 0),
42
-
43
- __eq: new BasicParameterFunction((x, y) => x === y, 2, 2),
44
- __neq: new BasicParameterFunction((x, y) => x !== y, 2, 2),
45
- __eqi: new BasicParameterFunction(
46
- (x, y) => x.toLowerCase() === y.toLowerCase(),
47
- 2,
48
- 2
49
- ),
50
- __neqi: new BasicParameterFunction(
51
- (x, y) => x.toLowerCase() !== y.toLowerCase(),
52
- 2,
53
- 2
54
- ),
55
- __to_number: new BasicParameterFunction((str) => Number(str), 1, 1),
56
- __matches: new BasicParameterFunction(
57
- (target, regexStr) => new RegExp(regexStr).test(target),
58
- 2,
59
- 2
60
- ),
61
-
62
- __array_matches: new BasicParameterFunction(
63
- (arrayAsStr, regex) => {
64
- const arr: Array<string> = toArray(arrayAsStr);
65
- return arr.length === 0 ? false : arr.every(a => RegExp(regex).test(JSON.stringify(a)));
66
- },
67
- 2,
68
- 2
69
- ),
70
-
71
- __array_pluck: new BasicParameterFunction(
72
- (arrayAsStr, ...keys) => {
73
- if (!arrayAsStr) {
74
- return JSON.stringify([]);
75
- }
76
- const arr: Array<object> = toArray(arrayAsStr);
77
- return JSON.stringify(arr.length === 0 ? [] : arr.map((o => mapObject(o, keys))));
78
- },
79
- 2
80
- ),
81
-
82
- __array_in_range: new BasicParameterFunction(
83
- (arrayAsStr, start, end) => {
84
- const arr: Array<string> = toArray(arrayAsStr);
85
- return arr.length === 0 ? false : arr.every(el => Number(el) >= Number(start) && Number(el) <= Number(end));
86
- },
87
- 3,
88
- 3
89
- ),
90
-
91
- // all parts of target are in src
92
- __array_includes: new BasicParameterFunction(
93
- (srcArrayAsStr, targetArrayAsStr) => {
94
- const srcArr = toArray(srcArrayAsStr);
95
- const tarArr = toArray(targetArrayAsStr);
96
- return tarArr.every(el => srcArr.some(el2 => isEqual(el, el2)));
97
- },
98
- 2,
99
- 2
100
- ),
101
-
102
- __array_sum: new BasicParameterFunction(
103
- (arrayAsStr) => {
104
- const arr = toArray(arrayAsStr);
105
- return arr.reduce((x, y) => x + Number(y), 0);
106
- },
107
- 1,
108
- 1
109
- ),
110
-
111
- __array_sort: new BasicParameterFunction(
112
- (arrayAsStr) => {
113
- const arr = toArray(arrayAsStr);
114
- return JSON.stringify(arr.sort());
115
- },
116
- 1,
117
- 1
118
- ),
119
-
120
- __array_sort_numbers: new BasicParameterFunction(
121
- (arrayAsStr) => {
122
- const arr = toNumbersArray(arrayAsStr);
123
- return JSON.stringify(arr.sort(numbersComparator));
124
- },
125
- 1,
126
- 1
127
- ),
128
-
129
- __array_is_unique: new BasicParameterFunction(
130
- (arrayAsStr) => {
131
- const arr = toArray(arrayAsStr);
132
- return uniqWith(arr, isEqual).length === arr.length;
133
- },
134
- 1,
135
- 1
136
- ),
137
-
138
- __contains: new BasicParameterFunction(
139
- (str1, str2) => contains(str1, str2),
140
- 2,
141
- 2
142
- ),
143
- __containsi: new BasicParameterFunction(
144
- (str1, str2) => contains(str1, str2, { ignoreCase: true }),
145
- 2,
146
- 2
147
- ),
148
-
149
- __is_uuid: new BasicParameterFunction((x) => isUUID(x), 1, 1),
150
-
151
- __is_number: new BasicParameterFunction((x) => x != '' && !isNaN(Number(x)), 1, 1),
152
-
153
- __length: new BasicParameterFunction((x) => x.length, 1, 1),
154
-
155
- __array_length: new BasicParameterFunction((str) => toArray(str).length, 1, 1),
156
-
157
- __escape_regexp: new BasicParameterFunction((x) => escapeRegExp(x), 1, 1),
158
-
159
- __escape_quotes: new BasicParameterFunction(
160
- (x) =>
161
- x
162
- .replace(/"/g, '\\$&')
163
- //.replace(/\b/g, '\\b')
164
- //.replace(/\f/g, '\\f')
165
- .replace(/\n/g, '\\n')
166
- .replace(/\r/g, '\\r')
167
- .replace(/\t/g, '\\t'),
168
- //.replace(/\\/g, '\\\\')
169
- 1,
170
- 1
171
- ),
172
-
173
- __encode_url: new BasicParameterFunction(uriUtils.encodePart, 1, 1),
174
- __decode_url: new BasicParameterFunction(uriUtils.decodePart, 1, 1),
175
-
176
- __decode_base64: new BasicParameterFunction(base64decode, 1, 1),
177
- __encode_base64: new BasicParameterFunction(base64encode, 1, 1),
178
-
179
- __lower: new BasicParameterFunction((x) => x.toLowerCase(), 1, 1),
180
- __upper: new BasicParameterFunction((x) => x.toUpperCase(), 1, 1),
181
-
182
- __if_then_else: new BasicParameterFunction(
183
- (condition, onTrue, onFalse) =>
184
- isTruthyParameterValue(condition) ? onTrue : onFalse,
185
- 3,
186
- 3
187
- ),
188
-
189
- __switch: new BasicParameterFunction(
190
- (target, ...pairsAndDef) => switchSelect(target, pairsAndDef),
191
- 1
192
- ),
193
- __switchi: new BasicParameterFunction(
194
- (target, ...pairsAndDef) =>
195
- switchSelect(target, pairsAndDef, { ignoreCase: true }),
196
- 1
197
- ),
198
-
199
- __pick: new BasicParameterFunction(
200
- (selection, ...pickFrom) => pick(selection, pickFrom),
201
- 2
202
- ),
203
-
204
- __pick_random: new BasicParameterFunction(
205
- (...args) => pick(RANDOM_SELECT_OPT, args),
206
- 1
207
- ),
208
-
209
- __sha1: new BasicParameterFunction(
210
- (secret, secretFormat = FORMATS.UTF8) => toSha(secret, HASH.SHA1, secretFormat),
211
- 1,
212
- 2
213
- ),
214
-
215
- __sha256: new BasicParameterFunction(
216
- (secret, secretFormat = FORMATS.UTF8) => toSha(secret, HASH.SHA256, secretFormat),
217
- 1,
218
- 2
219
- ),
220
-
221
- __hmacSha1: new BasicParameterFunction(
222
- (secret, secretFormat = FORMATS.UTF8, salt = '') => toHMAC(secret, HASH.SHA1, secretFormat, salt),
223
- 1,
224
- 3
225
- ),
226
-
227
- __hmacSha256: new BasicParameterFunction(
228
- (secret, secretFormat = FORMATS.UTF8, salt = '') => toHMAC(secret, HASH.SHA256, secretFormat, salt),
229
- 1,
230
- 3
231
- ),
232
-
233
- __split_pick: new BasicParameterFunction(
234
- (str: string, delim: string, selection = '0') =>
235
- pick(selection, str.split(delim)),
236
- 2,
237
- 3
238
- ),
239
-
240
- __slice: new BasicParameterFunction(
241
- (str, begin?, end?) => {
242
- let beg;
243
- if (begin != null) {
244
- beg = toIndex('begin', begin);
245
- }
246
-
247
- let en;
248
- if (end != null) {
249
- en = toIndex('end', end);
250
- }
251
-
252
- return str.slice(beg, en);
253
- },
254
- 1,
255
- 3
256
- ),
257
-
258
- __regexp: new BasicParameterFunction(
259
- (target, query, def = '') => {
260
- return defaultTo(
261
- new RegexExtractor(() => target, {}).extractResolved(query),
262
- def
263
- );
264
- },
265
- 2,
266
- 3
267
- ),
268
-
269
- __json_keys: new BasicParameterFunction(
270
- (target, def = '') => defaultTo(objectStrToObjectKeysStr(target), def),
271
- 1,
272
- 2
273
- ),
274
-
275
- __jsonpath_keys: new BasicParameterFunction(
276
- (target, query, def = '') => {
277
- return defaultTo(
278
- (() => {
279
- const json = defaultTo(
280
- new JsonPathExtractor(target, {}).extractResolved(query),
281
- '{}'
282
- );
283
- return objectStrToObjectKeysStr(json);
284
- })(),
285
- def
286
- );
287
- },
288
- 2,
289
- 3
290
- ),
291
-
292
- __jsonpath: new BasicParameterFunction(
293
- (target, query, def = '') => {
294
- return defaultTo(
295
- new JsonPathExtractor(target, {}).extractResolved(query),
296
- def
297
- );
298
- },
299
- 2,
300
- 3
301
- ),
302
-
303
- __jsonpath_all: new BasicParameterFunction(
304
- (target, query, def = '') => {
305
- return defaultTo(
306
- new JsonPathExtractor(target, {}).extractResolved(query, true),
307
- def
308
- );
309
- },
310
- 2,
311
- 3
312
- ),
313
-
314
- __jsonpath_apply: new BasicParameterFunction(
315
- (target, query, value) => {
316
- return new JsonPathExtractor(target, {}).apply(query, value);
317
- },
318
- 3,
319
- 3
320
- ),
321
-
322
- __jsonschema: new BasicParameterFunction(
323
- (instance, schema) => {
324
- return applyJSONSchema(instance, schema);
325
- },
326
- 2,
327
- 2
328
- ),
329
-
330
- __jquery: new BasicParameterFunction(
331
- (target, query, selection?, attr?, def = '') => {
332
- return defaultTo(
333
- new CheerioExtractor(target, {}).extractResolved(
334
- query,
335
- selection,
336
- attr
337
- ),
338
- def
339
- );
340
- },
341
- 2,
342
- 5
343
- ),
344
-
345
- __now: nowParameterFunction,
346
-
347
- __now_ms: nowParameterFunction,
348
-
349
- __now_iso: new BasicParameterFunction(
350
- (addedMinutes = '0') => new Date(new Date().getTime() + (Number(addedMinutes) * 1000 * 60)).toISOString(),
351
- 0,
352
- 1
353
- ),
354
-
355
- __date_iso: new BasicParameterFunction(
356
- (addedDays = '0') => new Date(new Date().getTime() + (Number(addedDays) * 1000 * 60 * 60 * 24)).toISOString().substring(0, 10),
357
- 0,
358
- 1
359
- ),
360
- };
361
-
362
- function pick(selection: string, pickFrom: any[]) {
363
- if (selection === RANDOM_SELECT_OPT) {
364
- return pickRandom(pickFrom);
365
- } else {
366
- const selectionIndex = toIndex('selection', selection);
367
- if (pickFrom[selectionIndex] !== undefined) {
368
- //empty string is ok to return
369
- return pickFrom[selectionIndex];
370
- } else {
371
- throw new PresentableError(`Invalid selection index '${selection}'`);
372
- }
373
- }
374
- }
375
-
376
- function switchSelect(
377
- target,
378
- pairsAndDef: string[],
379
- { ignoreCase } = { ignoreCase: false }
380
- ) {
381
- let matches = (key) => key === target;
382
-
383
- if (ignoreCase) {
384
- const compareTarget = target.toLowerCase();
385
- matches = (key) => key.toLowerCase() === compareTarget;
386
- }
387
-
388
- const def = pairsAndDef.length % 2 > 0 ? pairsAndDef.pop() : '';
389
-
390
- while (!isEmpty(pairsAndDef)) {
391
- const [key, value, ...rest] = pairsAndDef;
392
-
393
- if (matches(key)) {
394
- return value;
395
- }
396
-
397
- pairsAndDef = rest;
398
- }
399
-
400
- return def;
401
- }
402
-
403
- function contains(str1, str2, { ignoreCase } = { ignoreCase: false }) {
404
- if (ignoreCase) {
405
- return str1.toLowerCase().includes(str2.toLowerCase());
406
- } else {
407
- return str1.includes(str2);
408
- }
409
- }
410
-
411
- function toIndex(name: string, value: string) {
412
- const numeric = parameterValueToNumber(value, { integer: true });
413
-
414
- if (numeric == null) {
415
- throw new PresentableError(`Invalid ${name} index '${value}'`);
416
- }
417
-
418
- return numeric;
419
- }
420
-
421
- const toNumbersArray = (arrayAsStr: string): number[] => {
422
- const arr = toArray(arrayAsStr);
423
- const numbersArr = arr.map(Number);
424
- if (numbersArr.some(x => isNaN(x))) {
425
- throw new PresentableError('Elements must be numbers [1,2] or numerical strings ["1","2"] or combination of both [1,"2"]');
426
- }
427
- return numbersArr;
428
- };
429
-
430
- const toArray = (arrayAsStr: string): Array<any> => {
431
- try {
432
- const arr: Array<any> = JSON.parse(arrayAsStr);
433
- if (!Array.isArray(arr)) {
434
- throw new PresentableError('must be a valid array: ex. [ 1, "str", true, null ]');
435
- }
436
- return arr;
437
- } catch {
438
- throw new PresentableError('must be a valid array: ex. [ 1, "str", true, null ]');
439
- }
440
- };
441
-
442
- const objectStrToObjectKeysStr = (stringifiedObject: string): string => {
443
- try {
444
- const json = JSON.parse(stringifiedObject);
445
- return JSON.stringify(Object.keys(json));
446
- } catch {
447
- throw new PresentableError('Not a valid JSON object');
448
- }
449
- };
450
-
451
- const mapObject = (srcObj: object, keys: string[]) => {
452
- const result = {};
453
- for (const key of keys) {
454
- if (key.includes(':')) {
455
- const [src, target] = key.split(':');
456
- result[target] = srcObj[src];
457
- } else {
458
- result[key] = srcObj[key];
459
- }
460
- }
461
- return result;
462
- };
463
-
464
- const numbersComparator = (x: number, y: number) => x - y;
@@ -1,74 +0,0 @@
1
- import { operators } from './operators';
2
-
3
- class OneOffRegExpProvider {
4
- constructor(private regExp: RegExp) {}
5
-
6
- use = (callback) => {
7
- this.regExp.lastIndex = 0;
8
- return callback(this.regExp);
9
- };
10
- }
11
-
12
- const SPACES = '(?: +)';
13
- const LITERAL = '(?:\'[^,\'\\s]*\')';
14
-
15
- export const LEGAL_PARAM_CHARS = '_a-zA-Z0-9';
16
- const PARAMETER = '(?:[_a-zA-Z][' + LEGAL_PARAM_CHARS + ']*)';
17
- const PARAMETER_OR_LITERAL = `(?:${PARAMETER}|${LITERAL})`;
18
-
19
- const EXPRESSION = `(?:${LITERAL}|(?:(?:${PARAMETER}(?:\\((?:${PARAMETER_OR_LITERAL}(?:,${PARAMETER_OR_LITERAL})*)?\\))?)))`;
20
-
21
- const OPERATOR =
22
- '(?:' + Object.values(operators).map((op) => op.regexSymbol).join('|') + ')';
23
- export const SPACED_OPERATOR = `${SPACES}${OPERATOR}${SPACES}`;
24
-
25
- // Capture groups designed to work with code mirror parser - be minded!
26
- export const PARAMETER_USAGE_PATTERN = `(\\\${)((?: *)(?:${EXPRESSION}(?:${SPACED_OPERATOR}${EXPRESSION})*)(?: *))(})`;
27
-
28
- export const spacesRegExpProvider = new OneOffRegExpProvider(
29
- new RegExp(SPACES)
30
- );
31
- export const usageRegExpProvider = new OneOffRegExpProvider(
32
- new RegExp(PARAMETER_USAGE_PATTERN)
33
- );
34
- export const globalUsageRegExpProvider = new OneOffRegExpProvider(
35
- new RegExp(PARAMETER_USAGE_PATTERN, 'g')
36
- );
37
-
38
- const PARAM_USAGE_REGEXP_PREFIX = '\\${(.[^}]*)?';
39
- const PARAM_USAGE_REGEXP_SUFFIX = '([\\),\\s].*?)?}';
40
-
41
- const PARAM_GROUPING_REGEXP_PREFIX = '(?<pre>\\${.*?[\\(,])(?<param>';
42
- const PARAM_GROUPING_REGEXP_SUFFIX = ')(?<suff>[\\),].*?})';
43
-
44
- const PARAM_OPERATORS_GROUPING_REGEXP_PREFIX = `\\\${(?<pre>.*?${SPACED_OPERATOR}.*)?(?<param>.*`;
45
- const PARAM_OPERATORS_GROUPING_REGEXP_SUFFIX = `)(?<suff>${SPACED_OPERATOR}.*)?}`;
46
-
47
- export const getParameterUsageRegexp = (parameterName) =>
48
- new RegExp(
49
- `${PARAM_USAGE_REGEXP_PREFIX}${parameterName}${PARAM_USAGE_REGEXP_SUFFIX}`,
50
- 'g'
51
- );
52
-
53
- export const getParameterfunctionGroupingRegexp = (parameterName) =>
54
- new RegExp(
55
- `${PARAM_GROUPING_REGEXP_PREFIX}${parameterName}${PARAM_GROUPING_REGEXP_SUFFIX}`
56
- );
57
-
58
- export const getParameterOperatorsGroupingRegexp = (parameterName) =>
59
- new RegExp(
60
- `${PARAM_OPERATORS_GROUPING_REGEXP_PREFIX}${parameterName}${PARAM_OPERATORS_GROUPING_REGEXP_SUFFIX}`
61
- );
62
-
63
- export const CAPTURE_REGEX = /(([^\\]\(|^\().*[^\\]\))/;
64
-
65
- export const PARAM_USAGE_REGEXP = /\$\{(.+)\}/;
66
-
67
- export const CAPTURE_ALL_REGEX = /(.*)/;
68
-
69
- export function isCaptureAllRegExp(regexp: RegExp): boolean {
70
- return String(CAPTURE_ALL_REGEX) === String(regexp);
71
- }
72
-
73
- export const CSRF_REGEXP = '[^,; ]*?[cCxX](?:srf|SRF)[^\'" =:]*? *\\\\?["\']?(?:=|:) *\\\\?["\']([^\'"]+?)\\\\?["\']';
74
- export const getCsrfTokenByRegexp = (data: string) => new RegExp(CSRF_REGEXP).exec(data);
@@ -1,8 +0,0 @@
1
- import { generateRandom } from '../generate-random';
2
-
3
- export function resolveRandomParameter(parameterName: string) {
4
- if (parameterName.startsWith('__random_')) {
5
- const [, , , kind, arg1, arg2] = parameterName.split('_');
6
- return generateRandom(kind, arg1, arg2);
7
- }
8
- }
@@ -1,7 +0,0 @@
1
- export type Parameters = { [name: string]: string | string[] };
2
- export type SequenceExecutorParameters = { [name: string]: any };
3
-
4
- export enum ParametersScope {
5
- SUITE = 'SUITE',
6
- FLOW = 'FLOW',
7
- }
@@ -1,47 +0,0 @@
1
- import random = require('lodash/random');
2
-
3
- export const RANDOM_SELECT_OPT = 'random';
4
-
5
- const FALSY_AS_LOWERCASE_STRINGS = ['undefined','null','false','nan'];
6
-
7
- export function isTruthyParameterValue(value: any): boolean {
8
- if (value && typeof value === 'string') {
9
- const str = value.toLowerCase();
10
- return !FALSY_AS_LOWERCASE_STRINGS.includes(str);
11
- }
12
- return !!value;
13
- }
14
-
15
- export function isFalsyParameterValue(value?: string | boolean) {
16
- return (
17
- value == null ||
18
- value === false ||
19
- (typeof value === 'string' && value.toLowerCase() === 'false') ||
20
- value === ''
21
- );
22
- }
23
-
24
- export function pickRandom(array: any[]) {
25
- return array[random(0, array.length - 1)];
26
- }
27
-
28
- export function parameterValueToNumber(value?: string | null, options?) {
29
- if (value == null || value === '') {
30
- return null;
31
- }
32
-
33
- const numeric = Number(value);
34
-
35
- if (Number.isFinite(numeric)) {
36
- if (
37
- options &&
38
- ((options.integer && !Number.isSafeInteger(numeric)) ||
39
- (options.nonNegative && numeric < 0))
40
- ) {
41
- return null;
42
- }
43
- return numeric;
44
- } else {
45
- return null;
46
- }
47
- }