@api-client/core 0.17.6 → 0.18.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/build/src/amf/ApiSchemaGenerator.d.ts +2 -2
- package/build/src/amf/ApiSchemaGenerator.d.ts.map +1 -1
- package/build/src/amf/ApiSchemaGenerator.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts.map +1 -1
- package/build/src/amf/ApiSchemaValues.js +8 -1
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/amf/shape/ShapeBase.d.ts +1 -1
- package/build/src/amf/shape/ShapeBase.d.ts.map +1 -1
- package/build/src/amf/shape/ShapeBase.js.map +1 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +1 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts.map +1 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +7 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts.map +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +8 -2
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -1
- package/build/src/mocking/RandExp.d.ts +55 -0
- package/build/src/mocking/RandExp.d.ts.map +1 -0
- package/build/src/mocking/RandExp.js +302 -0
- package/build/src/mocking/RandExp.js.map +1 -0
- package/build/src/mocking/lib/ret.d.ts +16 -0
- package/build/src/mocking/lib/ret.d.ts.map +1 -0
- package/build/src/mocking/lib/ret.js +284 -0
- package/build/src/mocking/lib/ret.js.map +1 -0
- package/build/src/modeling/Bindings.d.ts +0 -4
- package/build/src/modeling/Bindings.d.ts.map +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DomainEntity.js +3 -3
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +18 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +31 -0
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +2 -1
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/src/modeling/amf/ShapeGenerator.js +3 -3
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
- package/build/src/modeling/types.d.ts +4 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +19 -19
- package/package.json +2 -2
- package/src/amf/ApiSchemaGenerator.ts +2 -2
- package/src/amf/ApiSchemaValues.ts +8 -1
- package/src/amf/shape/ShapeBase.ts +1 -1
- package/src/amf/shape/ShapeJsonSchemaGenerator.ts +7 -2
- package/src/amf/shape/ShapeXmlSchemaGenerator.ts +8 -3
- package/src/mocking/RandExp.ts +335 -0
- package/src/mocking/lib/ret.ts +279 -0
- package/src/modeling/Bindings.ts +0 -4
- package/src/modeling/DomainEntity.ts +3 -3
- package/src/modeling/DomainProperty.ts +33 -0
- package/src/modeling/Semantics.ts +2 -1
- package/src/modeling/amf/ShapeGenerator.ts +3 -3
- package/src/modeling/types.ts +4 -0
- package/tests/unit/modeling/amf/shape_generator.spec.ts +3 -8
- package/tests/unit/modeling/domain_property.spec.ts +335 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* randexp v0.4.6
|
|
4
|
+
* Create random strings that match a given regular expression.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2017 by fent (https://github.com/fent)
|
|
7
|
+
* MIT License
|
|
8
|
+
*/
|
|
9
|
+
import { ret, types } from './lib/ret.js';
|
|
10
|
+
class DRange {
|
|
11
|
+
low;
|
|
12
|
+
high;
|
|
13
|
+
length;
|
|
14
|
+
constructor(low, high) {
|
|
15
|
+
this.low = low;
|
|
16
|
+
this.high = high;
|
|
17
|
+
this.length = 1 + high - low;
|
|
18
|
+
}
|
|
19
|
+
overlaps(range) {
|
|
20
|
+
return !(this.high < range.low || this.low > range.high);
|
|
21
|
+
}
|
|
22
|
+
touches(range) {
|
|
23
|
+
return !(this.high + 1 < range.low || this.low - 1 > range.high);
|
|
24
|
+
}
|
|
25
|
+
add(range) {
|
|
26
|
+
if (this.touches(range)) {
|
|
27
|
+
return new DRange(Math.min(this.low, range.low), Math.max(this.high, range.high));
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
subtract(range) {
|
|
32
|
+
if (!this.overlaps(range)) {
|
|
33
|
+
return [this.clone()];
|
|
34
|
+
}
|
|
35
|
+
if (range.low <= this.low && range.high >= this.high) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
if (range.low > this.low && range.high < this.high) {
|
|
39
|
+
return [new DRange(this.low, range.low - 1), new DRange(range.high + 1, this.high)];
|
|
40
|
+
}
|
|
41
|
+
if (range.low <= this.low) {
|
|
42
|
+
return [new DRange(range.high + 1, this.high)];
|
|
43
|
+
}
|
|
44
|
+
// if (range.high >= this.high)
|
|
45
|
+
return [new DRange(this.low, range.low - 1)];
|
|
46
|
+
}
|
|
47
|
+
toString() {
|
|
48
|
+
return this.low === this.high ? String(this.low) : `${this.low}-${this.high}`;
|
|
49
|
+
}
|
|
50
|
+
clone() {
|
|
51
|
+
return new DRange(this.low, this.high);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class DiscontinuousRange {
|
|
55
|
+
ranges = [];
|
|
56
|
+
length = 0;
|
|
57
|
+
constructor(low, high) {
|
|
58
|
+
if (low !== undefined) {
|
|
59
|
+
this.add(low, high);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_setLength() {
|
|
63
|
+
this.length = this.ranges.reduce((sum, range) => sum + range.length, 0);
|
|
64
|
+
}
|
|
65
|
+
add(low, high) {
|
|
66
|
+
const addRange = (range) => {
|
|
67
|
+
const newRanges = [];
|
|
68
|
+
let i = 0;
|
|
69
|
+
while (i < this.ranges.length && !range.touches(this.ranges[i])) {
|
|
70
|
+
newRanges.push(this.ranges[i].clone());
|
|
71
|
+
i++;
|
|
72
|
+
}
|
|
73
|
+
while (i < this.ranges.length && range.touches(this.ranges[i])) {
|
|
74
|
+
range = range.add(this.ranges[i]);
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
newRanges.push(range);
|
|
78
|
+
while (i < this.ranges.length) {
|
|
79
|
+
newRanges.push(this.ranges[i].clone());
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
this.ranges = newRanges;
|
|
83
|
+
this._setLength();
|
|
84
|
+
};
|
|
85
|
+
if (low instanceof DiscontinuousRange) {
|
|
86
|
+
low.ranges.forEach(addRange);
|
|
87
|
+
}
|
|
88
|
+
else if (low instanceof DRange) {
|
|
89
|
+
addRange(low);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (high === undefined)
|
|
93
|
+
high = low;
|
|
94
|
+
addRange(new DRange(low, high));
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
subtract(low, high) {
|
|
99
|
+
const subtractRange = (range) => {
|
|
100
|
+
const newRanges = [];
|
|
101
|
+
let i = 0;
|
|
102
|
+
while (i < this.ranges.length && !range.overlaps(this.ranges[i])) {
|
|
103
|
+
newRanges.push(this.ranges[i].clone());
|
|
104
|
+
i++;
|
|
105
|
+
}
|
|
106
|
+
while (i < this.ranges.length && range.overlaps(this.ranges[i])) {
|
|
107
|
+
newRanges.push(...this.ranges[i].subtract(range));
|
|
108
|
+
i++;
|
|
109
|
+
}
|
|
110
|
+
while (i < this.ranges.length) {
|
|
111
|
+
newRanges.push(this.ranges[i].clone());
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
this.ranges = newRanges;
|
|
115
|
+
this._setLength();
|
|
116
|
+
};
|
|
117
|
+
if (low instanceof DiscontinuousRange) {
|
|
118
|
+
low.ranges.forEach(subtractRange);
|
|
119
|
+
}
|
|
120
|
+
else if (low instanceof DRange) {
|
|
121
|
+
subtractRange(low);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (high === undefined)
|
|
125
|
+
high = low;
|
|
126
|
+
subtractRange(new DRange(low, high));
|
|
127
|
+
}
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
index(i) {
|
|
131
|
+
let j = 0;
|
|
132
|
+
while (j < this.ranges.length && this.ranges[j].length <= i) {
|
|
133
|
+
i -= this.ranges[j].length;
|
|
134
|
+
j++;
|
|
135
|
+
}
|
|
136
|
+
if (j >= this.ranges.length) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return this.ranges[j].low + i;
|
|
140
|
+
}
|
|
141
|
+
toString() {
|
|
142
|
+
return `[ ${this.ranges.join(', ')} ]`;
|
|
143
|
+
}
|
|
144
|
+
clone() {
|
|
145
|
+
return new DiscontinuousRange(this);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class RandExp {
|
|
149
|
+
max = 10; // Reduced from 100 to 10 for more reasonable string lengths
|
|
150
|
+
defaultRange = new DiscontinuousRange(32, 126);
|
|
151
|
+
randInt = (min, max) => {
|
|
152
|
+
return min + Math.floor(Math.random() * (max - min + 1));
|
|
153
|
+
};
|
|
154
|
+
tokens;
|
|
155
|
+
ignoreCase;
|
|
156
|
+
multiline;
|
|
157
|
+
constructor(regexp, flags, options) {
|
|
158
|
+
this.defaultRange = this.defaultRange.clone();
|
|
159
|
+
// Apply options if provided
|
|
160
|
+
if (options) {
|
|
161
|
+
if (typeof options.max === 'number') {
|
|
162
|
+
this.max = options.max;
|
|
163
|
+
}
|
|
164
|
+
if (options.defaultRange instanceof DiscontinuousRange) {
|
|
165
|
+
this.defaultRange = options.defaultRange;
|
|
166
|
+
}
|
|
167
|
+
if (typeof options.randInt === 'function') {
|
|
168
|
+
this.randInt = options.randInt;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (regexp instanceof RegExp) {
|
|
172
|
+
this.ignoreCase = regexp.ignoreCase;
|
|
173
|
+
this.multiline = regexp.multiline;
|
|
174
|
+
this._setDefaults(regexp);
|
|
175
|
+
regexp = regexp.source;
|
|
176
|
+
}
|
|
177
|
+
else if (typeof regexp === 'string') {
|
|
178
|
+
this.ignoreCase = flags?.includes('i') ?? false;
|
|
179
|
+
this.multiline = flags?.includes('m') ?? false;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw new Error('Expected a regexp or string');
|
|
183
|
+
}
|
|
184
|
+
this.tokens = ret(regexp);
|
|
185
|
+
}
|
|
186
|
+
_setDefaults(regexp) {
|
|
187
|
+
if (typeof regexp.max === 'number') {
|
|
188
|
+
this.max = regexp.max;
|
|
189
|
+
}
|
|
190
|
+
if (regexp.defaultRange instanceof DiscontinuousRange) {
|
|
191
|
+
this.defaultRange = regexp.defaultRange;
|
|
192
|
+
}
|
|
193
|
+
if (typeof regexp.randInt === 'function') {
|
|
194
|
+
this.randInt = regexp.randInt;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
gen() {
|
|
198
|
+
return this._gen(this.tokens, []);
|
|
199
|
+
}
|
|
200
|
+
_gen(token, groups) {
|
|
201
|
+
let stack, str, i, l;
|
|
202
|
+
switch (token.type) {
|
|
203
|
+
case types.ROOT:
|
|
204
|
+
case types.GROUP:
|
|
205
|
+
if (token.followedBy || token.notFollowedBy)
|
|
206
|
+
return '';
|
|
207
|
+
if (token.remember && token.groupNumber === undefined) {
|
|
208
|
+
token.groupNumber = groups.push(null) - 1;
|
|
209
|
+
}
|
|
210
|
+
stack = token.options ? this._choice(token.options) : token.stack;
|
|
211
|
+
str = '';
|
|
212
|
+
for (i = 0, l = stack.length; i < l; i++) {
|
|
213
|
+
str += this._gen(stack[i], groups);
|
|
214
|
+
}
|
|
215
|
+
if (token.remember) {
|
|
216
|
+
groups[token.groupNumber] = str;
|
|
217
|
+
}
|
|
218
|
+
return str;
|
|
219
|
+
case types.POSITION:
|
|
220
|
+
return '';
|
|
221
|
+
case types.SET: {
|
|
222
|
+
const set = this._processSet(token);
|
|
223
|
+
if (!set.length)
|
|
224
|
+
return '';
|
|
225
|
+
return String.fromCharCode(this._choice(set));
|
|
226
|
+
}
|
|
227
|
+
case types.REPETITION: {
|
|
228
|
+
const n = this.randInt(token.min, token.max === Infinity ? token.min + this.max : token.max);
|
|
229
|
+
str = '';
|
|
230
|
+
for (i = 0; i < n; i++) {
|
|
231
|
+
str += this._gen(token.value, groups);
|
|
232
|
+
}
|
|
233
|
+
return str;
|
|
234
|
+
}
|
|
235
|
+
case types.REFERENCE:
|
|
236
|
+
return groups[token.value - 1] || '';
|
|
237
|
+
case types.CHAR: {
|
|
238
|
+
const code = this.ignoreCase && this._coin() ? RandExp._toCaseInverse(token.value) : token.value;
|
|
239
|
+
return String.fromCharCode(code);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return '';
|
|
243
|
+
}
|
|
244
|
+
_processSet(token) {
|
|
245
|
+
if (token.type === types.CHAR) {
|
|
246
|
+
return new DiscontinuousRange(token.value);
|
|
247
|
+
}
|
|
248
|
+
if (token.type === types.RANGE) {
|
|
249
|
+
return new DiscontinuousRange(token.from, token.to);
|
|
250
|
+
}
|
|
251
|
+
const dr = new DiscontinuousRange();
|
|
252
|
+
for (const char of token.set) {
|
|
253
|
+
const sub = this._processSet(char);
|
|
254
|
+
dr.add(sub);
|
|
255
|
+
if (this.ignoreCase) {
|
|
256
|
+
for (let j = 0; j < sub.length; j++) {
|
|
257
|
+
const charCode = sub.index(j);
|
|
258
|
+
const otherCase = RandExp._toCaseInverse(charCode);
|
|
259
|
+
if (charCode !== otherCase) {
|
|
260
|
+
dr.add(otherCase);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return token.not ? this.defaultRange.clone().subtract(dr) : dr;
|
|
266
|
+
}
|
|
267
|
+
static _toCaseInverse(code) {
|
|
268
|
+
if (code >= 97 && code <= 122)
|
|
269
|
+
return code - 32;
|
|
270
|
+
if (code >= 65 && code <= 90)
|
|
271
|
+
return code + 32;
|
|
272
|
+
return code;
|
|
273
|
+
}
|
|
274
|
+
_coin() {
|
|
275
|
+
return this.randInt(0, 1) === 0;
|
|
276
|
+
}
|
|
277
|
+
_choice(choices) {
|
|
278
|
+
if (choices instanceof DiscontinuousRange) {
|
|
279
|
+
return choices.index(this.randInt(0, choices.length - 1));
|
|
280
|
+
}
|
|
281
|
+
return choices[this.randInt(0, choices.length - 1)];
|
|
282
|
+
}
|
|
283
|
+
static randexp(regexp, flags, options) {
|
|
284
|
+
let randexpInstance;
|
|
285
|
+
if (regexp._randexp === undefined) {
|
|
286
|
+
randexpInstance = new RandExp(regexp, flags, options);
|
|
287
|
+
regexp._randexp = randexpInstance;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
randexpInstance = regexp._randexp;
|
|
291
|
+
}
|
|
292
|
+
randexpInstance._setDefaults(regexp);
|
|
293
|
+
return randexpInstance.gen();
|
|
294
|
+
}
|
|
295
|
+
static sugar() {
|
|
296
|
+
;
|
|
297
|
+
RegExp.prototype.gen = function () {
|
|
298
|
+
return RandExp.randexp(this);
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=RandExp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RandExp.js","sourceRoot":"","sources":["../../../src/mocking/RandExp.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAS,KAAK,EAAE,MAAM,cAAc,CAAA;AAEhD,MAAM,MAAM;IACV,GAAG,CAAQ;IACX,IAAI,CAAQ;IACZ,MAAM,CAAQ;IAEd,YAAY,GAA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AC,MAAuB,EAAE,KAAc,EAAE,OAAwB;QAC9E,IAAI,eAAe,CAAA;QACnB,IAAK,MAAc,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3C,eAAe,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CACpD;YAAC,MAAc,CAAC,QAAQ,GAAG,eAAe,CAAA;QAC7C,CAAC;aAAM,CAAC;YACN,eAAe,GAAI,MAAc,CAAC,QAAQ,CAAA;QAC5C,CAAC;QACD,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QACpC,OAAO,eAAe,CAAC,GAAG,EAAE,CAAA;IAC9B,CAAC;IAED,MAAM,CAAC,KAAK;QACV,CAAC;QAAC,MAAM,CAAC,SAAiB,CAAC,GAAG,GAAG;YAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC,CAAA;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * randexp v0.4.6\n * Create random strings that match a given regular expression.\n *\n * Copyright (C) 2017 by fent (https://github.com/fent)\n * MIT License\n */\n\nimport { ret, Token, types } from './lib/ret.js'\n\nclass DRange {\n low: number\n high: number\n length: number\n\n constructor(low: number, high: number) {\n this.low = low\n this.high = high\n this.length = 1 + high - low\n }\n\n overlaps(range: DRange): boolean {\n return !(this.high < range.low || this.low > range.high)\n }\n\n touches(range: DRange): boolean {\n return !(this.high + 1 < range.low || this.low - 1 > range.high)\n }\n\n add(range: DRange): DRange | null {\n if (this.touches(range)) {\n return new DRange(Math.min(this.low, range.low), Math.max(this.high, range.high))\n }\n return null\n }\n\n subtract(range: DRange): DRange[] {\n if (!this.overlaps(range)) {\n return [this.clone()]\n }\n if (range.low <= this.low && range.high >= this.high) {\n return []\n }\n if (range.low > this.low && range.high < this.high) {\n return [new DRange(this.low, range.low - 1), new DRange(range.high + 1, this.high)]\n }\n if (range.low <= this.low) {\n return [new DRange(range.high + 1, this.high)]\n }\n // if (range.high >= this.high)\n return [new DRange(this.low, range.low - 1)]\n }\n\n toString(): string {\n return this.low === this.high ? String(this.low) : `${this.low}-${this.high}`\n }\n\n clone(): DRange {\n return new DRange(this.low, this.high)\n }\n}\n\nclass DiscontinuousRange {\n ranges: DRange[] = []\n length = 0\n\n constructor(low?: number | DiscontinuousRange, high?: number) {\n if (low !== undefined) {\n this.add(low, high)\n }\n }\n\n private _setLength(): void {\n this.length = this.ranges.reduce((sum, range) => sum + range.length, 0)\n }\n\n add(low: number | DiscontinuousRange | DRange, high?: number): this {\n const addRange = (range: DRange) => {\n const newRanges: DRange[] = []\n let i = 0\n while (i < this.ranges.length && !range.touches(this.ranges[i])) {\n newRanges.push(this.ranges[i].clone())\n i++\n }\n while (i < this.ranges.length && range.touches(this.ranges[i])) {\n range = range.add(this.ranges[i]) as DRange\n i++\n }\n newRanges.push(range)\n while (i < this.ranges.length) {\n newRanges.push(this.ranges[i].clone())\n i++\n }\n this.ranges = newRanges\n this._setLength()\n }\n\n if (low instanceof DiscontinuousRange) {\n low.ranges.forEach(addRange)\n } else if (low instanceof DRange) {\n addRange(low)\n } else {\n if (high === undefined) high = low\n addRange(new DRange(low, high))\n }\n return this\n }\n\n subtract(low: number | DiscontinuousRange | DRange, high?: number): this {\n const subtractRange = (range: DRange) => {\n const newRanges: DRange[] = []\n let i = 0\n while (i < this.ranges.length && !range.overlaps(this.ranges[i])) {\n newRanges.push(this.ranges[i].clone())\n i++\n }\n while (i < this.ranges.length && range.overlaps(this.ranges[i])) {\n newRanges.push(...this.ranges[i].subtract(range))\n i++\n }\n while (i < this.ranges.length) {\n newRanges.push(this.ranges[i].clone())\n i++\n }\n this.ranges = newRanges\n this._setLength()\n }\n\n if (low instanceof DiscontinuousRange) {\n low.ranges.forEach(subtractRange)\n } else if (low instanceof DRange) {\n subtractRange(low)\n } else {\n if (high === undefined) high = low\n subtractRange(new DRange(low, high))\n }\n return this\n }\n\n index(i: number): number | null {\n let j = 0\n while (j < this.ranges.length && this.ranges[j].length <= i) {\n i -= this.ranges[j].length\n j++\n }\n if (j >= this.ranges.length) {\n return null\n }\n return this.ranges[j].low + i\n }\n\n toString(): string {\n return `[ ${this.ranges.join(', ')} ]`\n }\n\n clone(): DiscontinuousRange {\n return new DiscontinuousRange(this)\n }\n}\n\nexport interface RandExpOptions {\n max?: number\n defaultRange?: DiscontinuousRange\n randInt?: (min: number, max: number) => number\n}\n\nexport class RandExp {\n max = 10 // Reduced from 100 to 10 for more reasonable string lengths\n defaultRange: DiscontinuousRange = new DiscontinuousRange(32, 126)\n randInt: (min: number, max: number) => number = (min, max) => {\n return min + Math.floor(Math.random() * (max - min + 1))\n }\n\n private tokens: Token\n private ignoreCase: boolean\n private multiline: boolean\n\n constructor(regexp: RegExp | string, flags?: string, options?: RandExpOptions) {\n this.defaultRange = this.defaultRange.clone()\n\n // Apply options if provided\n if (options) {\n if (typeof options.max === 'number') {\n this.max = options.max\n }\n if (options.defaultRange instanceof DiscontinuousRange) {\n this.defaultRange = options.defaultRange\n }\n if (typeof options.randInt === 'function') {\n this.randInt = options.randInt\n }\n }\n\n if (regexp instanceof RegExp) {\n this.ignoreCase = regexp.ignoreCase\n this.multiline = regexp.multiline\n this._setDefaults(regexp)\n regexp = regexp.source\n } else if (typeof regexp === 'string') {\n this.ignoreCase = flags?.includes('i') ?? false\n this.multiline = flags?.includes('m') ?? false\n } else {\n throw new Error('Expected a regexp or string')\n }\n this.tokens = ret(regexp)\n }\n\n private _setDefaults(regexp: any): void {\n if (typeof regexp.max === 'number') {\n this.max = regexp.max\n }\n if (regexp.defaultRange instanceof DiscontinuousRange) {\n this.defaultRange = regexp.defaultRange\n }\n if (typeof regexp.randInt === 'function') {\n this.randInt = regexp.randInt\n }\n }\n\n gen(): string {\n return this._gen(this.tokens, [])\n }\n\n private _gen(token: Token, groups: (string | null)[]): string {\n let stack, str, i, l\n\n switch (token.type) {\n case types.ROOT:\n case types.GROUP:\n if (token.followedBy || token.notFollowedBy) return ''\n\n if (token.remember && token.groupNumber === undefined) {\n token.groupNumber = groups.push(null) - 1\n }\n\n stack = token.options ? this._choice(token.options) : token.stack\n str = ''\n for (i = 0, l = stack.length; i < l; i++) {\n str += this._gen(stack[i], groups)\n }\n\n if (token.remember) {\n groups[token.groupNumber] = str\n }\n return str\n\n case types.POSITION:\n return ''\n\n case types.SET: {\n const set = this._processSet(token)\n if (!set.length) return ''\n return String.fromCharCode(this._choice(set) as number)\n }\n case types.REPETITION: {\n const n = this.randInt(token.min, token.max === Infinity ? token.min + this.max : token.max)\n str = ''\n for (i = 0; i < n; i++) {\n str += this._gen(token.value, groups)\n }\n return str\n }\n case types.REFERENCE:\n return groups[token.value - 1] || ''\n\n case types.CHAR: {\n const code = this.ignoreCase && this._coin() ? RandExp._toCaseInverse(token.value) : token.value\n return String.fromCharCode(code)\n }\n }\n return ''\n }\n\n private _processSet(token: Token): DiscontinuousRange {\n if (token.type === types.CHAR) {\n return new DiscontinuousRange(token.value)\n }\n if (token.type === types.RANGE) {\n return new DiscontinuousRange(token.from, token.to)\n }\n\n const dr = new DiscontinuousRange()\n for (const char of token.set) {\n const sub = this._processSet(char)\n dr.add(sub)\n if (this.ignoreCase) {\n for (let j = 0; j < sub.length; j++) {\n const charCode = sub.index(j) as number\n const otherCase = RandExp._toCaseInverse(charCode)\n if (charCode !== otherCase) {\n dr.add(otherCase)\n }\n }\n }\n }\n\n return token.not ? this.defaultRange.clone().subtract(dr) : dr\n }\n\n private static _toCaseInverse(code: number): number {\n if (code >= 97 && code <= 122) return code - 32\n if (code >= 65 && code <= 90) return code + 32\n return code\n }\n\n private _coin(): boolean {\n return this.randInt(0, 1) === 0\n }\n\n private _choice(choices: any[] | DiscontinuousRange): any {\n if (choices instanceof DiscontinuousRange) {\n return choices.index(this.randInt(0, choices.length - 1))\n }\n return choices[this.randInt(0, choices.length - 1)]\n }\n\n static randexp(regexp: RegExp | string, flags?: string, options?: RandExpOptions): string {\n let randexpInstance\n if ((regexp as any)._randexp === undefined) {\n randexpInstance = new RandExp(regexp, flags, options)\n ;(regexp as any)._randexp = randexpInstance\n } else {\n randexpInstance = (regexp as any)._randexp\n }\n randexpInstance._setDefaults(regexp)\n return randexpInstance.gen()\n }\n\n static sugar(): void {\n ;(RegExp.prototype as any).gen = function () {\n return RandExp.randexp(this)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum types {
|
|
2
|
+
ROOT = 0,
|
|
3
|
+
GROUP = 1,
|
|
4
|
+
POSITION = 2,
|
|
5
|
+
SET = 3,
|
|
6
|
+
RANGE = 4,
|
|
7
|
+
REPETITION = 5,
|
|
8
|
+
REFERENCE = 6,
|
|
9
|
+
CHAR = 7
|
|
10
|
+
}
|
|
11
|
+
export interface Token {
|
|
12
|
+
type: types;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export declare const ret: (regexpStr: string) => Token;
|
|
16
|
+
//# sourceMappingURL=ret.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ret.d.ts","sourceRoot":"","sources":["../../../../src/mocking/lib/ret.ts"],"names":[],"mappings":"AAGA,oBAAY,KAAK;IACf,IAAI,IAAI;IACR,KAAK,IAAI;IACT,QAAQ,IAAI;IACZ,GAAG,IAAI;IACP,KAAK,IAAI;IACT,UAAU,IAAI;IACd,SAAS,IAAI;IACb,IAAI,IAAI;CACT;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,KAAK,CAAA;IAEX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AA6HD,eAAO,MAAM,GAAG,GAAI,WAAW,MAAM,KAAG,KAuIvC,CAAA"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Regular Expression Tokenizer
|
|
2
|
+
// https://github.com/fent/ret.js
|
|
3
|
+
export var types;
|
|
4
|
+
(function (types) {
|
|
5
|
+
types[types["ROOT"] = 0] = "ROOT";
|
|
6
|
+
types[types["GROUP"] = 1] = "GROUP";
|
|
7
|
+
types[types["POSITION"] = 2] = "POSITION";
|
|
8
|
+
types[types["SET"] = 3] = "SET";
|
|
9
|
+
types[types["RANGE"] = 4] = "RANGE";
|
|
10
|
+
types[types["REPETITION"] = 5] = "REPETITION";
|
|
11
|
+
types[types["REFERENCE"] = 6] = "REFERENCE";
|
|
12
|
+
types[types["CHAR"] = 7] = "CHAR";
|
|
13
|
+
})(types || (types = {}));
|
|
14
|
+
const wordBoundary = () => ({ type: types.POSITION, value: 'b' });
|
|
15
|
+
const nonWordBoundary = () => ({ type: types.POSITION, value: 'B' });
|
|
16
|
+
const begin = () => ({ type: types.POSITION, value: '^' });
|
|
17
|
+
const end = () => ({ type: types.POSITION, value: '$' });
|
|
18
|
+
const ints = () => [{ type: types.RANGE, from: 48, to: 57 }];
|
|
19
|
+
const words = () => [
|
|
20
|
+
{ type: types.CHAR, value: 95 },
|
|
21
|
+
{ type: types.RANGE, from: 97, to: 122 },
|
|
22
|
+
{ type: types.RANGE, from: 65, to: 90 },
|
|
23
|
+
...ints(),
|
|
24
|
+
];
|
|
25
|
+
const whitespace = () => [
|
|
26
|
+
{ type: types.CHAR, value: 9 },
|
|
27
|
+
{ type: types.CHAR, value: 10 },
|
|
28
|
+
{ type: types.CHAR, value: 11 },
|
|
29
|
+
{ type: types.CHAR, value: 12 },
|
|
30
|
+
{ type: types.CHAR, value: 13 },
|
|
31
|
+
{ type: types.CHAR, value: 32 },
|
|
32
|
+
{ type: types.CHAR, value: 160 },
|
|
33
|
+
{ type: types.CHAR, value: 5760 },
|
|
34
|
+
{ type: types.CHAR, value: 6158 },
|
|
35
|
+
{ type: types.CHAR, value: 8192 },
|
|
36
|
+
{ type: types.CHAR, value: 8193 },
|
|
37
|
+
{ type: types.CHAR, value: 8194 },
|
|
38
|
+
{ type: types.CHAR, value: 8195 },
|
|
39
|
+
{ type: types.CHAR, value: 8196 },
|
|
40
|
+
{ type: types.CHAR, value: 8197 },
|
|
41
|
+
{ type: types.CHAR, value: 8198 },
|
|
42
|
+
{ type: types.CHAR, value: 8199 },
|
|
43
|
+
{ type: types.CHAR, value: 8200 },
|
|
44
|
+
{ type: types.CHAR, value: 8201 },
|
|
45
|
+
{ type: types.CHAR, value: 8202 },
|
|
46
|
+
{ type: types.CHAR, value: 8232 },
|
|
47
|
+
{ type: types.CHAR, value: 8233 },
|
|
48
|
+
{ type: types.CHAR, value: 8239 },
|
|
49
|
+
{ type: types.CHAR, value: 8287 },
|
|
50
|
+
{ type: types.CHAR, value: 12288 },
|
|
51
|
+
{ type: types.CHAR, value: 65279 },
|
|
52
|
+
];
|
|
53
|
+
const notanychar = () => [
|
|
54
|
+
{ type: types.CHAR, value: 10 },
|
|
55
|
+
{ type: types.CHAR, value: 13 },
|
|
56
|
+
{ type: types.CHAR, value: 8232 },
|
|
57
|
+
{ type: types.CHAR, value: 8233 },
|
|
58
|
+
];
|
|
59
|
+
const words_ = () => ({ type: types.SET, set: words(), not: false });
|
|
60
|
+
const notWords = () => ({ type: types.SET, set: words(), not: true });
|
|
61
|
+
const ints_ = () => ({ type: types.SET, set: ints(), not: false });
|
|
62
|
+
const notInts = () => ({ type: types.SET, set: ints(), not: true });
|
|
63
|
+
const whitespace_ = () => ({ type: types.SET, set: whitespace(), not: false });
|
|
64
|
+
const notWhitespace = () => ({ type: types.SET, set: whitespace(), not: true });
|
|
65
|
+
const anyChar = () => ({ type: types.SET, set: notanychar(), not: true });
|
|
66
|
+
const specialChars = {
|
|
67
|
+
'0': 0,
|
|
68
|
+
't': 9,
|
|
69
|
+
'n': 10,
|
|
70
|
+
'v': 11,
|
|
71
|
+
'f': 12,
|
|
72
|
+
'r': 13,
|
|
73
|
+
};
|
|
74
|
+
const strToChars = (str) => {
|
|
75
|
+
const chars = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
|
|
76
|
+
return str.replace(chars, (match, b, s, uh, xh, o, c, sp) => {
|
|
77
|
+
if (s)
|
|
78
|
+
return match;
|
|
79
|
+
const code = b
|
|
80
|
+
? 8
|
|
81
|
+
: uh
|
|
82
|
+
? parseInt(uh, 16)
|
|
83
|
+
: xh
|
|
84
|
+
? parseInt(xh, 16)
|
|
85
|
+
: o
|
|
86
|
+
? parseInt(o, 8)
|
|
87
|
+
: c
|
|
88
|
+
? '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?'.indexOf(c)
|
|
89
|
+
: specialChars[sp];
|
|
90
|
+
let ch = String.fromCharCode(code);
|
|
91
|
+
if (/[[{}^$.|?*+()]/.test(ch)) {
|
|
92
|
+
ch = `\\${ch}`;
|
|
93
|
+
}
|
|
94
|
+
return ch;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const tokenizeClass = (str, regexpStr) => {
|
|
98
|
+
const tokens = [];
|
|
99
|
+
const classTokens = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?(.)/g;
|
|
100
|
+
let match;
|
|
101
|
+
let char;
|
|
102
|
+
while ((match = classTokens.exec(str)) !== null) {
|
|
103
|
+
if (match[1]) {
|
|
104
|
+
tokens.push(words_());
|
|
105
|
+
}
|
|
106
|
+
else if (match[2]) {
|
|
107
|
+
tokens.push(ints_());
|
|
108
|
+
}
|
|
109
|
+
else if (match[3]) {
|
|
110
|
+
tokens.push(whitespace_());
|
|
111
|
+
}
|
|
112
|
+
else if (match[4]) {
|
|
113
|
+
tokens.push(notWords());
|
|
114
|
+
}
|
|
115
|
+
else if (match[5]) {
|
|
116
|
+
tokens.push(notInts());
|
|
117
|
+
}
|
|
118
|
+
else if (match[6]) {
|
|
119
|
+
tokens.push(notWhitespace());
|
|
120
|
+
}
|
|
121
|
+
else if (match[7]) {
|
|
122
|
+
tokens.push({
|
|
123
|
+
type: types.RANGE,
|
|
124
|
+
from: (match[8] || match[9]).charCodeAt(0),
|
|
125
|
+
to: match[10].charCodeAt(0),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else if ((char = match[12])) {
|
|
129
|
+
tokens.push({ type: types.CHAR, value: char.charCodeAt(0) });
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return [tokens, classTokens.lastIndex];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated character class`);
|
|
136
|
+
};
|
|
137
|
+
const error = (regexpStr, msg) => {
|
|
138
|
+
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: ${msg}`);
|
|
139
|
+
};
|
|
140
|
+
export const ret = (regexpStr) => {
|
|
141
|
+
let i = 0;
|
|
142
|
+
const root = { type: types.ROOT, stack: [] };
|
|
143
|
+
let p = root;
|
|
144
|
+
let stack = root.stack;
|
|
145
|
+
const groupStack = [];
|
|
146
|
+
const repeatErr = (i) => error(regexpStr, `Nothing to repeat at column ${i - 1}`);
|
|
147
|
+
const chars = strToChars(regexpStr);
|
|
148
|
+
while (i < chars.length) {
|
|
149
|
+
let c = chars[i++];
|
|
150
|
+
switch (c) {
|
|
151
|
+
case '\\':
|
|
152
|
+
c = chars[i++];
|
|
153
|
+
switch (c) {
|
|
154
|
+
case 'b':
|
|
155
|
+
stack.push(wordBoundary());
|
|
156
|
+
break;
|
|
157
|
+
case 'B':
|
|
158
|
+
stack.push(nonWordBoundary());
|
|
159
|
+
break;
|
|
160
|
+
case 'w':
|
|
161
|
+
stack.push(words_());
|
|
162
|
+
break;
|
|
163
|
+
case 'W':
|
|
164
|
+
stack.push(notWords());
|
|
165
|
+
break;
|
|
166
|
+
case 'd':
|
|
167
|
+
stack.push(ints_());
|
|
168
|
+
break;
|
|
169
|
+
case 'D':
|
|
170
|
+
stack.push(notInts());
|
|
171
|
+
break;
|
|
172
|
+
case 's':
|
|
173
|
+
stack.push(whitespace_());
|
|
174
|
+
break;
|
|
175
|
+
case 'S':
|
|
176
|
+
stack.push(notWhitespace());
|
|
177
|
+
break;
|
|
178
|
+
default:
|
|
179
|
+
if (/\d/.test(c)) {
|
|
180
|
+
stack.push({ type: types.REFERENCE, value: parseInt(c, 10) });
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
stack.push({ type: types.CHAR, value: c.charCodeAt(0) });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
case '^':
|
|
188
|
+
stack.push(begin());
|
|
189
|
+
break;
|
|
190
|
+
case '$':
|
|
191
|
+
stack.push(end());
|
|
192
|
+
break;
|
|
193
|
+
case '[': {
|
|
194
|
+
let not = false;
|
|
195
|
+
if (chars[i] === '^') {
|
|
196
|
+
not = true;
|
|
197
|
+
i++;
|
|
198
|
+
}
|
|
199
|
+
const [set, lastIndex] = tokenizeClass(chars.slice(i), regexpStr);
|
|
200
|
+
i += lastIndex;
|
|
201
|
+
stack.push({ type: types.SET, set, not });
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case '.':
|
|
205
|
+
stack.push(anyChar());
|
|
206
|
+
break;
|
|
207
|
+
case '(': {
|
|
208
|
+
const group = { type: types.GROUP, stack: [], remember: true };
|
|
209
|
+
if (chars[i] === '?') {
|
|
210
|
+
c = chars[i + 1];
|
|
211
|
+
i += 2;
|
|
212
|
+
if (c === '=') {
|
|
213
|
+
group.followedBy = true;
|
|
214
|
+
}
|
|
215
|
+
else if (c === '!') {
|
|
216
|
+
group.notFollowedBy = true;
|
|
217
|
+
}
|
|
218
|
+
else if (c !== ':') {
|
|
219
|
+
error(regexpStr, `Invalid group, character '${c}' after '?' at column ${i - 1}`);
|
|
220
|
+
}
|
|
221
|
+
group.remember = false;
|
|
222
|
+
}
|
|
223
|
+
stack.push(group);
|
|
224
|
+
groupStack.push(p);
|
|
225
|
+
p = group;
|
|
226
|
+
stack = group.stack;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case ')':
|
|
230
|
+
if (groupStack.length === 0)
|
|
231
|
+
error(regexpStr, `Unmatched ) at column ${i - 1}`);
|
|
232
|
+
p = groupStack.pop();
|
|
233
|
+
stack = p.options ? p.options[p.options.length - 1] : p.stack;
|
|
234
|
+
break;
|
|
235
|
+
case '|':
|
|
236
|
+
if (!p.options) {
|
|
237
|
+
p.options = [p.stack];
|
|
238
|
+
delete p.stack;
|
|
239
|
+
}
|
|
240
|
+
{
|
|
241
|
+
const newStack = [];
|
|
242
|
+
p.options.push(newStack);
|
|
243
|
+
stack = newStack;
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
case '{': {
|
|
247
|
+
const repetition = /^(\d+)(,(\d+)?)?\}/.exec(chars.slice(i));
|
|
248
|
+
if (repetition) {
|
|
249
|
+
if (stack.length === 0)
|
|
250
|
+
repeatErr(i);
|
|
251
|
+
const min = parseInt(repetition[1], 10);
|
|
252
|
+
const max = repetition[2] ? (repetition[3] ? parseInt(repetition[3], 10) : Infinity) : min;
|
|
253
|
+
i += repetition[0].length;
|
|
254
|
+
stack.push({ type: types.REPETITION, min, max, value: stack.pop() });
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
stack.push({ type: types.CHAR, value: 123 });
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case '?':
|
|
262
|
+
if (stack.length === 0)
|
|
263
|
+
repeatErr(i);
|
|
264
|
+
stack.push({ type: types.REPETITION, min: 0, max: 1, value: stack.pop() });
|
|
265
|
+
break;
|
|
266
|
+
case '+':
|
|
267
|
+
if (stack.length === 0)
|
|
268
|
+
repeatErr(i);
|
|
269
|
+
stack.push({ type: types.REPETITION, min: 1, max: Infinity, value: stack.pop() });
|
|
270
|
+
break;
|
|
271
|
+
case '*':
|
|
272
|
+
if (stack.length === 0)
|
|
273
|
+
repeatErr(i);
|
|
274
|
+
stack.push({ type: types.REPETITION, min: 0, max: Infinity, value: stack.pop() });
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
stack.push({ type: types.CHAR, value: c.charCodeAt(0) });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (groupStack.length !== 0)
|
|
281
|
+
error(regexpStr, 'Unterminated group');
|
|
282
|
+
return root;
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=ret.js.map
|