@goast/core 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/cjs/index.js +1 -0
  2. package/cjs/lib/ast/index.js +4 -0
  3. package/cjs/lib/ast/node.js +27 -0
  4. package/cjs/lib/parse/parser.js +1 -1
  5. package/cjs/lib/transform/transform-endpoint.js +1 -1
  6. package/cjs/lib/transform/transform-schema.js +4 -2
  7. package/cjs/lib/utils/array.utils.js +11 -0
  8. package/cjs/lib/utils/class.utils.js +33 -0
  9. package/cjs/lib/utils/common.utils.js +75 -1
  10. package/cjs/lib/utils/error.utils.js +7 -0
  11. package/cjs/lib/utils/index.js +4 -0
  12. package/cjs/lib/utils/object.utils.js +6 -2
  13. package/cjs/lib/utils/schema.utils.js +2 -1
  14. package/cjs/lib/utils/source-builder.js +171 -81
  15. package/cjs/lib/utils/string-builder/index.js +8 -0
  16. package/cjs/lib/utils/string-builder/options.js +7 -0
  17. package/cjs/lib/utils/string-builder/string-builder.js +142 -0
  18. package/cjs/lib/utils/string-builder/utils.js +38 -0
  19. package/cjs/lib/utils/string.utils.js +123 -107
  20. package/cjs/lib/utils/type.utils.js +9 -0
  21. package/esm/index.js +1 -0
  22. package/esm/lib/ast/index.js +1 -0
  23. package/esm/lib/ast/node.js +23 -0
  24. package/esm/lib/parse/parser.js +1 -1
  25. package/esm/lib/transform/transform-endpoint.js +1 -1
  26. package/esm/lib/transform/transform-schema.js +4 -2
  27. package/esm/lib/utils/array.utils.js +7 -0
  28. package/esm/lib/utils/class.utils.js +27 -0
  29. package/esm/lib/utils/common.utils.js +64 -0
  30. package/esm/lib/utils/error.utils.js +3 -0
  31. package/esm/lib/utils/index.js +4 -0
  32. package/esm/lib/utils/object.utils.js +6 -2
  33. package/esm/lib/utils/schema.utils.js +2 -1
  34. package/esm/lib/utils/source-builder.js +170 -80
  35. package/esm/lib/utils/string-builder/index.js +3 -0
  36. package/esm/lib/utils/string-builder/options.js +4 -0
  37. package/esm/lib/utils/string-builder/string-builder.js +138 -0
  38. package/esm/lib/utils/string-builder/utils.js +30 -0
  39. package/esm/lib/utils/string.utils.js +111 -105
  40. package/esm/lib/utils/type.utils.js +6 -1
  41. package/package.json +5 -5
  42. package/types/index.d.ts +1 -0
  43. package/types/lib/ast/index.d.ts +1 -0
  44. package/types/lib/ast/node.d.ts +14 -0
  45. package/types/lib/transform/api-types.d.ts +3 -1
  46. package/types/lib/utils/array.utils.d.ts +1 -0
  47. package/types/lib/utils/class.utils.d.ts +7 -0
  48. package/types/lib/utils/common.utils.d.ts +14 -2
  49. package/types/lib/utils/error.utils.d.ts +1 -0
  50. package/types/lib/utils/index.d.ts +4 -0
  51. package/types/lib/utils/object.utils.d.ts +1 -1
  52. package/types/lib/utils/source-builder.d.ts +55 -37
  53. package/types/lib/utils/string-builder/index.d.ts +3 -0
  54. package/types/lib/utils/string-builder/options.d.ts +8 -0
  55. package/types/lib/utils/string-builder/string-builder.d.ts +72 -0
  56. package/types/lib/utils/string-builder/utils.d.ts +21 -0
  57. package/types/lib/utils/string.utils.d.ts +20 -66
  58. package/types/lib/utils/type.utils.d.ts +43 -1
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultStringBuilderOptions = void 0;
4
+ const os_1 = require("os");
5
+ exports.defaultStringBuilderOptions = {
6
+ newLine: os_1.EOL,
7
+ };
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringBuilder = exports.AdditionalAppendsSymbol = void 0;
4
+ const options_1 = require("./options");
5
+ const common_utils_1 = require("../common.utils");
6
+ exports.AdditionalAppendsSymbol = Symbol('AdditionalAppends');
7
+ /**
8
+ * Represents a mutable string of characters.
9
+ */
10
+ class StringBuilder {
11
+ [exports.AdditionalAppendsSymbol](_) {
12
+ throw new Error('This method should never be called.');
13
+ }
14
+ get options() {
15
+ return this._options;
16
+ }
17
+ /**
18
+ * Initializes a new instance of the StringBuilder class.
19
+ * @param options The options.
20
+ */
21
+ constructor(options) {
22
+ this.str = '';
23
+ this._options = Object.assign(Object.assign({}, options_1.defaultStringBuilderOptions), options);
24
+ }
25
+ /**
26
+ * Creates a new StringBuilder instance and appends the specified string to it.
27
+ * @param str The string to append.
28
+ * @param options The options.
29
+ * @returns A new StringBuilder instance.
30
+ */
31
+ static fromString(str, options) {
32
+ const builder = new StringBuilder(options);
33
+ builder.append(str);
34
+ return builder;
35
+ }
36
+ /**
37
+ * Builds a string using a StringBuilder build action.
38
+ * @param buildAction The build action to perform on the StringBuilder instance.
39
+ * @param options The options for the StringBuilder instance.
40
+ * @returns The built string.
41
+ */
42
+ static build(buildAction, options) {
43
+ const builder = new StringBuilder(options);
44
+ builder.append(buildAction);
45
+ return builder.toString();
46
+ }
47
+ appendSingle(value) {
48
+ if ((0, common_utils_1.isNullish)(value))
49
+ return;
50
+ if (Array.isArray(value)) {
51
+ for (const part of value) {
52
+ this.appendSingle(part);
53
+ }
54
+ }
55
+ else if (typeof value === 'string') {
56
+ this.str += value;
57
+ }
58
+ else if (typeof value === 'number' || typeof value === 'boolean') {
59
+ this.str += value.toString();
60
+ }
61
+ else if (typeof value === 'function') {
62
+ value(this);
63
+ }
64
+ else if (typeof value === 'object' &&
65
+ value !== null &&
66
+ '__type' in value &&
67
+ value.__type === 'append-value-group') {
68
+ let isFirst = true;
69
+ for (const part of value.values) {
70
+ if (!isFirst && value.separator) {
71
+ this.append(value.separator);
72
+ }
73
+ this.appendSingle(part);
74
+ isFirst = false;
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Appends one or more strings to the end of the current StringBuilder.
80
+ * @param value The string(s) to append.
81
+ * @returns The current StringBuilder.
82
+ */
83
+ append(...value) {
84
+ for (const part of value) {
85
+ this.appendSingle(part);
86
+ }
87
+ return this;
88
+ }
89
+ /**
90
+ * Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
91
+ * @param value
92
+ * @returns
93
+ */
94
+ appendLine(...value) {
95
+ return this.append(...value, '\n');
96
+ }
97
+ /**
98
+ * Prepends one or more strings to the beginning of the current StringBuilder.
99
+ * @param value The string(s) to prepend.
100
+ * @returns The current StringBuilder.
101
+ */
102
+ prepend(...value) {
103
+ for (const part of value.reverse()) {
104
+ if ((0, common_utils_1.isNullish)(part))
105
+ continue;
106
+ if (typeof part === 'function') {
107
+ const builder = new StringBuilder(this.options);
108
+ part(builder);
109
+ this.str = builder.str + this.str;
110
+ }
111
+ else if (typeof part === 'string') {
112
+ this.str = part + this.str;
113
+ }
114
+ else {
115
+ this.str = part.toString() + this.str;
116
+ }
117
+ }
118
+ return this;
119
+ }
120
+ /**
121
+ * Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
122
+ * @param value The string(s) to prepend.
123
+ * @returns The current StringBuilder.
124
+ */
125
+ prependLine(...value) {
126
+ return this.prepend(...value, '\n');
127
+ }
128
+ /**
129
+ * Converts the value of this instance to a string.
130
+ * @returns A string whose value is the same as this instance.
131
+ */
132
+ toString() {
133
+ return this.str.replace(/\r?\n/g, this._options.newLine);
134
+ }
135
+ /**
136
+ * Removes all characters from the current StringBuilder.
137
+ */
138
+ clear() {
139
+ this.str = '';
140
+ }
141
+ }
142
+ exports.StringBuilder = StringBuilder;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.concatAppendValues = exports.isAppendValueGroup = exports.isAppendValue = exports.appendValueGroup = exports.basicAppendValueGroup = void 0;
4
+ const common_utils_1 = require("../common.utils");
5
+ function basicAppendValueGroup(values, separator) {
6
+ var _a;
7
+ return {
8
+ __type: 'append-value-group',
9
+ values: (_a = values === null || values === void 0 ? void 0 : values.filter(common_utils_1.notNullish)) !== null && _a !== void 0 ? _a : [],
10
+ separator: separator !== null && separator !== void 0 ? separator : null,
11
+ };
12
+ }
13
+ exports.basicAppendValueGroup = basicAppendValueGroup;
14
+ function appendValueGroup(values, separator) {
15
+ var _a;
16
+ return {
17
+ __type: 'append-value-group',
18
+ values: (_a = values === null || values === void 0 ? void 0 : values.filter(common_utils_1.notNullish)) !== null && _a !== void 0 ? _a : [],
19
+ separator: separator !== null && separator !== void 0 ? separator : null,
20
+ };
21
+ }
22
+ exports.appendValueGroup = appendValueGroup;
23
+ function isAppendValue(value) {
24
+ return (typeof value === 'string' ||
25
+ typeof value === 'number' ||
26
+ typeof value === 'boolean' ||
27
+ typeof value === 'function' ||
28
+ isAppendValueGroup(value));
29
+ }
30
+ exports.isAppendValue = isAppendValue;
31
+ function isAppendValueGroup(value) {
32
+ return typeof value === 'object' && value !== null && '__type' in value && value.__type === 'append-value-group';
33
+ }
34
+ exports.isAppendValueGroup = isAppendValueGroup;
35
+ function concatAppendValues(...values) {
36
+ return (0, common_utils_1.concatSingleOrMultiple)(...values);
37
+ }
38
+ exports.concatAppendValues = concatAppendValues;
@@ -1,8 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringBuilder = exports.defaultStringBuilderOptions = exports.escapeRegExp = exports.toCustomCase = exports.toSnakeCase = exports.toKebabCase = exports.toPascalCase = exports.toCamelCase = exports.toCasing = exports.wordToCasing = exports.getWords = void 0;
4
- const os_1 = require("os");
3
+ exports.removeStr = exports.trim = exports.trimStart = exports.trimEnd = exports.trimIndent = exports.spliceString = exports.escapeRegExp = exports.toCustomCase = exports.toSnakeCase = exports.toKebabCase = exports.toPascalCase = exports.toCamelCase = exports.toCasing = exports.wordToCasing = exports.getWords = exports.uncapitalize = exports.capitalize = exports.uppercase = exports.lowercase = exports.adjustCasing = void 0;
5
4
  const common_utils_1 = require("./common.utils");
5
+ function adjustCasing(a, b) {
6
+ if (typeof a === 'string') {
7
+ if (typeof b === 'string') {
8
+ return b;
9
+ }
10
+ else {
11
+ return Object.assign({ casing: a }, b);
12
+ }
13
+ }
14
+ else if (typeof b === 'string') {
15
+ return Object.assign(Object.assign({}, a), { casing: b });
16
+ }
17
+ else {
18
+ return Object.assign(Object.assign({}, a), b);
19
+ }
20
+ }
21
+ exports.adjustCasing = adjustCasing;
22
+ function lowercase(str) {
23
+ return str.toLowerCase();
24
+ }
25
+ exports.lowercase = lowercase;
26
+ function uppercase(str) {
27
+ return str.toUpperCase();
28
+ }
29
+ exports.uppercase = uppercase;
30
+ function capitalize(str) {
31
+ return (str.charAt(0).toUpperCase() + str.slice(1));
32
+ }
33
+ exports.capitalize = capitalize;
34
+ function uncapitalize(str) {
35
+ return (str.charAt(0).toLowerCase() + str.slice(1));
36
+ }
37
+ exports.uncapitalize = uncapitalize;
6
38
  /**
7
39
  * Gets the words from a string. Words are separated by capital letters. Leading numbers are removed. Non-alphanumerical characters are removed and interpreted as word seperators. Multiple uppercase letters are interpreted as one word.
8
40
  * @param str The string to get the words from.
@@ -230,112 +262,96 @@ function escapeRegExp(str) {
230
262
  return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
231
263
  }
232
264
  exports.escapeRegExp = escapeRegExp;
233
- exports.defaultStringBuilderOptions = {
234
- newLine: os_1.EOL,
235
- };
236
265
  /**
237
- * Represents a mutable string of characters.
266
+ * Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
267
+ * @param str The string to splice.
268
+ * @param start The index at which to start changing the string.
269
+ * @param deleteCount The number of characters to remove.
270
+ * @param insert The string to insert.
271
+ * @returns The spliced string.
238
272
  */
239
- class StringBuilder {
240
- get options() {
241
- return this._options;
242
- }
243
- /**
244
- * Initializes a new instance of the StringBuilder class.
245
- * @param options The options.
246
- */
247
- constructor(options) {
248
- this._str = '';
249
- this._options = Object.assign(Object.assign({}, exports.defaultStringBuilderOptions), options);
250
- }
251
- /**
252
- * Creates a new StringBuilder instance and appends the specified string to it.
253
- * @param str The string to append.
254
- * @param options The options.
255
- * @returns A new StringBuilder instance.
256
- */
257
- static fromString(str, options) {
258
- const builder = new StringBuilder(options);
259
- builder.append(str);
260
- return builder;
261
- }
262
- /**
263
- * Builds a string using a StringBuilder build action.
264
- * @param buildAction The build action to perform on the StringBuilder instance.
265
- * @param options The options for the StringBuilder instance.
266
- * @returns The built string.
267
- */
268
- static build(buildAction, options) {
269
- const builder = new StringBuilder(options);
270
- buildAction(builder);
271
- return builder.toString();
272
- }
273
- /**
274
- * Appends one or more strings to the end of the current StringBuilder.
275
- * @param value The string(s) to append.
276
- * @returns The current StringBuilder.
277
- */
278
- append(...value) {
279
- for (const part of value) {
280
- if (!part)
281
- continue;
282
- if (typeof part === 'string') {
283
- this._str += part;
284
- }
285
- else {
286
- part(this);
287
- }
288
- }
289
- return this;
290
- }
291
- /**
292
- * Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
293
- * @param value
294
- * @returns
295
- */
296
- appendLine(...value) {
297
- return this.append(...value, this._options.newLine);
298
- }
299
- /**
300
- * Prepends one or more strings to the beginning of the current StringBuilder.
301
- * @param value The string(s) to prepend.
302
- * @returns The current StringBuilder.
303
- */
304
- prepend(...value) {
305
- for (const part of value.reverse()) {
306
- if ((0, common_utils_1.isNullish)(part))
307
- continue;
308
- if (typeof part === 'function') {
309
- const builder = new StringBuilder(this.options);
310
- part(builder);
311
- this._str = builder.toString() + this._str;
312
- }
313
- else if (part.length > 0) {
314
- this._str = part + this._str;
315
- }
316
- }
317
- return this;
318
- }
319
- /**
320
- * Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
321
- * @param value The string(s) to prepend.
322
- * @returns The current StringBuilder.
323
- */
324
- prependLine(...value) {
325
- return this.prepend(...value, this._options.newLine);
326
- }
327
- /**
328
- * Converts the value of this instance to a string.
329
- * @returns A string whose value is the same as this instance.
330
- */
331
- toString() {
332
- return this._str;
333
- }
334
- /**
335
- * Removes all characters from the current StringBuilder.
336
- */
337
- clear() {
338
- this._str = '';
273
+ function spliceString(str, start, deleteCount, insert) {
274
+ return str.slice(0, start) + insert + str.slice(start + deleteCount);
275
+ }
276
+ exports.spliceString = spliceString;
277
+ /**
278
+ * Removes leading indentation based on the last line. Also removes the first line if it is empty.
279
+ * @param str The string to trim.
280
+ */
281
+ function trimIndent(str) {
282
+ var _a, _b;
283
+ const indent = (_b = (_a = str.match(/\n( *).*$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
284
+ if (indent.length === 0)
285
+ return str;
286
+ return str.replace(/^\r?\n/, '').replace(new RegExp(`^ {0,${indent.length}}`, 'gm'), '');
287
+ }
288
+ exports.trimIndent = trimIndent;
289
+ function isNonLineBreakWhitespaceChar(char) {
290
+ return (char === ' ' ||
291
+ char === '\t' ||
292
+ char === '\f' ||
293
+ char === '\v' ||
294
+ char === '\u00a0' ||
295
+ char === '\u1680' ||
296
+ char === '\u2000' ||
297
+ char === '\u2001' ||
298
+ char === '\u2002' ||
299
+ char === '\u2003' ||
300
+ char === '\u2004' ||
301
+ char === '\u2005' ||
302
+ char === '\u2006' ||
303
+ char === '\u2007' ||
304
+ char === '\u2008' ||
305
+ char === '\u2009' ||
306
+ char === '\u200a' ||
307
+ char === '\u2028' ||
308
+ char === '\u2029' ||
309
+ char === '\u202f' ||
310
+ char === '\u205f' ||
311
+ char === '\u3000' ||
312
+ char === '\ufeff');
313
+ }
314
+ function trimEnd(str, includeNewLine = true) {
315
+ if (includeNewLine)
316
+ return str.trimEnd();
317
+ let i = str.length;
318
+ for (; isNonLineBreakWhitespaceChar(str[i - 1]); i--)
319
+ ;
320
+ return str.substring(0, i);
321
+ }
322
+ exports.trimEnd = trimEnd;
323
+ function trimStart(str, includeNewLine = true) {
324
+ if (includeNewLine)
325
+ return str.trimStart();
326
+ let i = 0;
327
+ for (; isNonLineBreakWhitespaceChar(str[i]); i++)
328
+ ;
329
+ return str.substring(i);
330
+ }
331
+ exports.trimStart = trimStart;
332
+ function trim(str, includeNewLine = true) {
333
+ if (includeNewLine)
334
+ return str.trim();
335
+ let s = 0;
336
+ for (; isNonLineBreakWhitespaceChar(str[s]); s++)
337
+ ;
338
+ let e = str.length;
339
+ for (; isNonLineBreakWhitespaceChar(str[e - 1]); e--)
340
+ ;
341
+ return str.substring(s, e);
342
+ }
343
+ exports.trim = trim;
344
+ function removeStr(str, rem) {
345
+ let i = str.indexOf(rem);
346
+ if (i === -1)
347
+ return str;
348
+ let result = '';
349
+ let s = 0;
350
+ while (i !== -1) {
351
+ result += str.substring(s, i);
352
+ s = i + rem.length;
353
+ i = str.indexOf(rem, s);
339
354
  }
355
+ return result + str.substring(s);
340
356
  }
341
- exports.StringBuilder = StringBuilder;
357
+ exports.removeStr = removeStr;
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.suggestionsAsString = exports.stringUnionToArray = void 0;
4
+ function stringUnionToArray() {
5
+ return (...elements) => elements;
6
+ }
7
+ exports.stringUnionToArray = stringUnionToArray;
8
+ function suggestionsAsString(value) {
9
+ return value;
10
+ }
11
+ exports.suggestionsAsString = suggestionsAsString;
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/ast';
1
2
  export * from './lib/codegen';
2
3
  export * from './lib/parse';
3
4
  export * from './lib/transform';
@@ -0,0 +1 @@
1
+ export * from './node';
@@ -0,0 +1,23 @@
1
+ const NODE_HISTORY_SYMBOL = Symbol('node-history');
2
+ export class AstNode {
3
+ constructor(options) {
4
+ var _a;
5
+ this.inject = (_a = options.inject) !== null && _a !== void 0 ? _a : {};
6
+ }
7
+ write(builder) {
8
+ let history = builder[NODE_HISTORY_SYMBOL];
9
+ if (!history) {
10
+ history = [];
11
+ builder[NODE_HISTORY_SYMBOL] = history;
12
+ }
13
+ history.push(this);
14
+ builder.append(this.inject.before);
15
+ this.onWrite(builder);
16
+ builder.append(this.inject.after);
17
+ history.pop();
18
+ }
19
+ getParentNode(builder) {
20
+ const history = builder[NODE_HISTORY_SYMBOL];
21
+ return history === null || history === void 0 ? void 0 : history.at(-2);
22
+ }
23
+ }
@@ -53,7 +53,7 @@ export class OpenApiParser {
53
53
  });
54
54
  existingDocument.dereferencedComponents.set(path, result);
55
55
  if (value.$ref) {
56
- result.$ref = yield this.resolveReference(file, value);
56
+ result.$ref = (yield this.resolveReference(file, value));
57
57
  }
58
58
  for (const key of Object.keys(value)) {
59
59
  if (key === '$ref')
@@ -141,7 +141,7 @@ function transformResponse(context, response, status) {
141
141
  $src: Object.assign(Object.assign({}, response.$src), { component: response }),
142
142
  $ref: ref,
143
143
  id: context.idGenerator.generateId('response'),
144
- statusCode: Number(status),
144
+ statusCode: Number(status) || undefined,
145
145
  description: response.description,
146
146
  headers: transformHeaders(context, response.headers),
147
147
  contentOptions: transformContent(context, response.content),
@@ -153,7 +153,9 @@ function resolveDescriminatorMapping(context, schema) {
153
153
  for (const key of Object.keys(discriminator.mapping)) {
154
154
  const mappedSchemaRef = discriminator.mapping[key];
155
155
  const mappedSchema = transformSchema(context, mappedSchemaRef);
156
- schema.discriminator.mapping[key] = mappedSchema;
157
- mappedSchema.inheritedSchemas.push(schema);
156
+ if (schema.discriminator) {
157
+ schema.discriminator.mapping[key] = mappedSchema;
158
+ mappedSchema.inheritedSchemas.push(schema);
159
+ }
158
160
  }
159
161
  }
@@ -0,0 +1,7 @@
1
+ export function removeItems(array, predicate) {
2
+ for (let i = array.length - 1; i >= 0; i--) {
3
+ if (predicate(array[i])) {
4
+ array.splice(i, 1);
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,27 @@
1
+ export function classifyArray(items, classification) {
2
+ const result = { rest: [] };
3
+ for (const key in classification) {
4
+ result[key] = [];
5
+ }
6
+ for (const item of items) {
7
+ let classified = false;
8
+ for (const key in classification) {
9
+ const type = classification[key];
10
+ if (item instanceof type) {
11
+ result[key].push(item);
12
+ classified = true;
13
+ break;
14
+ }
15
+ }
16
+ if (!classified) {
17
+ result.rest.push(item);
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ export function isInstanceOf(item, type) {
23
+ return item instanceof type;
24
+ }
25
+ export function getIsInstanceOf(type) {
26
+ return (item) => item instanceof type;
27
+ }
@@ -4,3 +4,67 @@ export function isNullish(value) {
4
4
  export function notNullish(value) {
5
5
  return !isNullish(value);
6
6
  }
7
+ export function concatSingleOrMultiple(...values) {
8
+ if (values.length === 1) {
9
+ return values[0];
10
+ }
11
+ const result = [];
12
+ for (const value of values) {
13
+ if (Array.isArray(value)) {
14
+ result.push(...value);
15
+ }
16
+ else {
17
+ result.push(value);
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ export function isIterable(value) {
23
+ return typeof value === 'object' && value !== null && Symbol.iterator in value;
24
+ }
25
+ export function toArray(value) {
26
+ if (Array.isArray(value)) {
27
+ return value;
28
+ }
29
+ if (isIterable(value)) {
30
+ return Array.from(value);
31
+ }
32
+ return [value];
33
+ }
34
+ export function modify(value, callback) {
35
+ if (notNullish(value)) {
36
+ callback(value);
37
+ }
38
+ return value;
39
+ }
40
+ export function run(value, callback) {
41
+ callback(value);
42
+ return value;
43
+ }
44
+ export function transform(value, callback) {
45
+ return callback(value);
46
+ }
47
+ export function modifyEach(values, callback) {
48
+ for (const value of values) {
49
+ if (notNullish(value)) {
50
+ callback(value);
51
+ }
52
+ }
53
+ return values;
54
+ }
55
+ export function runEach(values, callback) {
56
+ for (const value of values) {
57
+ callback(value);
58
+ }
59
+ return values;
60
+ }
61
+ export function transformEach(values, callback) {
62
+ const result = [];
63
+ for (const value of values) {
64
+ result.push(callback(value));
65
+ }
66
+ return result;
67
+ }
68
+ export function asVoid(_) {
69
+ // Do nothing
70
+ }
@@ -0,0 +1,3 @@
1
+ export function throwExp(message) {
2
+ throw new Error(message);
3
+ }
@@ -1,10 +1,14 @@
1
+ export * from './array.utils';
2
+ export * from './class.utils';
1
3
  export * from './common.utils';
2
4
  export * from './endpoint.utils';
5
+ export * from './error.utils';
3
6
  export * from './factory';
4
7
  export * from './generator.utils';
5
8
  export * from './object.utils';
6
9
  export * from './schema.utils';
7
10
  export * from './source-builder';
11
+ export * from './string-builder';
8
12
  export * from './string.utils';
9
13
  export * from './string.utils.types';
10
14
  export * from './type.utils';
@@ -1,5 +1,9 @@
1
- export function createOverwriteProxy(target) {
2
- return new Proxy(target, new OverwriteProxyHandler());
1
+ export function createOverwriteProxy(target, values) {
2
+ const proxy = new Proxy(target, new OverwriteProxyHandler());
3
+ if (values) {
4
+ Object.assign(proxy, values);
5
+ }
6
+ return proxy;
3
7
  }
4
8
  class OverwriteProxyHandler {
5
9
  constructor() {
@@ -33,7 +33,8 @@ function collectSubSchemaProperties(subSchemas, properties, required, optional)
33
33
  }
34
34
  }
35
35
  function hasInvalidSubSchema(subSchemas) {
36
- return subSchemas.some((x) => x.kind !== 'object' && (x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
36
+ return subSchemas.some((x) => x.kind !== 'object' &&
37
+ (x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
37
38
  }
38
39
  /**
39
40
  * Retrieves the first schema reference and the reference chain of a given schema that