@goast/core 0.1.0 → 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.
- package/cjs/index.js +1 -0
- package/cjs/lib/ast/index.js +4 -0
- package/cjs/lib/ast/node.js +27 -0
- package/cjs/lib/parse/deref-proxy.js +9 -3
- package/cjs/lib/parse/parser.js +1 -1
- package/cjs/lib/transform/transform-endpoint.js +1 -1
- package/cjs/lib/transform/transform-schema.js +10 -5
- package/cjs/lib/utils/array.utils.js +11 -0
- package/cjs/lib/utils/class.utils.js +33 -0
- package/cjs/lib/utils/common.utils.js +75 -1
- package/cjs/lib/utils/error.utils.js +7 -0
- package/cjs/lib/utils/index.js +4 -0
- package/cjs/lib/utils/object.utils.js +6 -2
- package/cjs/lib/utils/schema.utils.js +2 -1
- package/cjs/lib/utils/source-builder.js +171 -81
- package/cjs/lib/utils/string-builder/index.js +8 -0
- package/cjs/lib/utils/string-builder/options.js +7 -0
- package/cjs/lib/utils/string-builder/string-builder.js +142 -0
- package/cjs/lib/utils/string-builder/utils.js +38 -0
- package/cjs/lib/utils/string.utils.js +123 -107
- package/cjs/lib/utils/type.utils.js +9 -0
- package/esm/index.js +1 -0
- package/esm/lib/ast/index.js +1 -0
- package/esm/lib/ast/node.js +23 -0
- package/esm/lib/parse/deref-proxy.js +9 -3
- package/esm/lib/parse/parser.js +1 -1
- package/esm/lib/transform/transform-endpoint.js +1 -1
- package/esm/lib/transform/transform-schema.js +10 -5
- package/esm/lib/utils/array.utils.js +7 -0
- package/esm/lib/utils/class.utils.js +27 -0
- package/esm/lib/utils/common.utils.js +64 -0
- package/esm/lib/utils/error.utils.js +3 -0
- package/esm/lib/utils/index.js +4 -0
- package/esm/lib/utils/object.utils.js +6 -2
- package/esm/lib/utils/schema.utils.js +2 -1
- package/esm/lib/utils/source-builder.js +170 -80
- package/esm/lib/utils/string-builder/index.js +3 -0
- package/esm/lib/utils/string-builder/options.js +4 -0
- package/esm/lib/utils/string-builder/string-builder.js +138 -0
- package/esm/lib/utils/string-builder/utils.js +30 -0
- package/esm/lib/utils/string.utils.js +111 -105
- package/esm/lib/utils/type.utils.js +6 -1
- package/package.json +5 -5
- package/types/index.d.ts +1 -0
- package/types/lib/ast/index.d.ts +1 -0
- package/types/lib/ast/node.d.ts +14 -0
- package/types/lib/transform/api-types.d.ts +3 -1
- package/types/lib/utils/array.utils.d.ts +1 -0
- package/types/lib/utils/class.utils.d.ts +7 -0
- package/types/lib/utils/common.utils.d.ts +14 -2
- package/types/lib/utils/error.utils.d.ts +1 -0
- package/types/lib/utils/index.d.ts +4 -0
- package/types/lib/utils/object.utils.d.ts +1 -1
- package/types/lib/utils/source-builder.d.ts +55 -37
- package/types/lib/utils/string-builder/index.d.ts +3 -0
- package/types/lib/utils/string-builder/options.d.ts +8 -0
- package/types/lib/utils/string-builder/string-builder.d.ts +72 -0
- package/types/lib/utils/string-builder/utils.d.ts +21 -0
- package/types/lib/utils/string.utils.d.ts +20 -66
- package/types/lib/utils/type.utils.d.ts +43 -1
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/ast"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./lib/codegen"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/parse"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/transform"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AstNode = void 0;
|
|
4
|
+
const NODE_HISTORY_SYMBOL = Symbol('node-history');
|
|
5
|
+
class AstNode {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
var _a;
|
|
8
|
+
this.inject = (_a = options.inject) !== null && _a !== void 0 ? _a : {};
|
|
9
|
+
}
|
|
10
|
+
write(builder) {
|
|
11
|
+
let history = builder[NODE_HISTORY_SYMBOL];
|
|
12
|
+
if (!history) {
|
|
13
|
+
history = [];
|
|
14
|
+
builder[NODE_HISTORY_SYMBOL] = history;
|
|
15
|
+
}
|
|
16
|
+
history.push(this);
|
|
17
|
+
builder.append(this.inject.before);
|
|
18
|
+
this.onWrite(builder);
|
|
19
|
+
builder.append(this.inject.after);
|
|
20
|
+
history.pop();
|
|
21
|
+
}
|
|
22
|
+
getParentNode(builder) {
|
|
23
|
+
const history = builder[NODE_HISTORY_SYMBOL];
|
|
24
|
+
return history === null || history === void 0 ? void 0 : history.at(-2);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AstNode = AstNode;
|
|
@@ -14,16 +14,22 @@ class DerefProxyHandler {
|
|
|
14
14
|
this._overwrittenValues = {};
|
|
15
15
|
}
|
|
16
16
|
get(target, prop) {
|
|
17
|
-
var _a
|
|
17
|
+
var _a;
|
|
18
18
|
if (prop === '$ref') {
|
|
19
19
|
return this._ref;
|
|
20
20
|
}
|
|
21
21
|
else if (prop === '$src') {
|
|
22
22
|
return this._source;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
if (this._overwrittenValues[prop] !== undefined) {
|
|
25
|
+
return this._overwrittenValues[prop];
|
|
26
|
+
}
|
|
27
|
+
if (target[prop] !== undefined) {
|
|
28
|
+
return target[prop];
|
|
29
|
+
}
|
|
30
|
+
return propertiesNotDerivedFromRef.includes(prop)
|
|
25
31
|
? undefined
|
|
26
|
-
: (
|
|
32
|
+
: (_a = this._ref) === null || _a === void 0 ? void 0 : _a[prop];
|
|
27
33
|
}
|
|
28
34
|
set(target, prop, value) {
|
|
29
35
|
if (prop === '$ref' && (typeof value === 'object' || typeof value === 'undefined')) {
|
package/cjs/lib/parse/parser.js
CHANGED
|
@@ -56,7 +56,7 @@ class OpenApiParser {
|
|
|
56
56
|
});
|
|
57
57
|
existingDocument.dereferencedComponents.set(path, result);
|
|
58
58
|
if (value.$ref) {
|
|
59
|
-
result.$ref = yield this.resolveReference(file, value);
|
|
59
|
+
result.$ref = (yield this.resolveReference(file, value));
|
|
60
60
|
}
|
|
61
61
|
for (const key of Object.keys(value)) {
|
|
62
62
|
if (key === '$ref')
|
|
@@ -145,7 +145,7 @@ function transformResponse(context, response, status) {
|
|
|
145
145
|
$src: Object.assign(Object.assign({}, response.$src), { component: response }),
|
|
146
146
|
$ref: ref,
|
|
147
147
|
id: context.idGenerator.generateId('response'),
|
|
148
|
-
statusCode: Number(status),
|
|
148
|
+
statusCode: Number(status) || undefined,
|
|
149
149
|
description: response.description,
|
|
150
150
|
headers: transformHeaders(context, response.headers),
|
|
151
151
|
contentOptions: transformContent(context, response.content),
|
|
@@ -17,14 +17,14 @@ function transformSchema(context, schema) {
|
|
|
17
17
|
if (existing)
|
|
18
18
|
return existing;
|
|
19
19
|
let kind = (0, helpers_1.determineSchemaKind)(schema);
|
|
20
|
-
let nullable =
|
|
20
|
+
let nullable = kind === 'null';
|
|
21
21
|
if (kind === 'multi-type') {
|
|
22
22
|
const types = schema.type;
|
|
23
23
|
let isSingleType = types.length === 1;
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
|
-
if (types.
|
|
25
|
+
if (types.includes('null') || types.includes(null)) {
|
|
26
26
|
nullable = true;
|
|
27
|
-
isSingleType =
|
|
27
|
+
isSingleType = types.length === 2;
|
|
28
28
|
}
|
|
29
29
|
if (isSingleType) {
|
|
30
30
|
const newType = types.filter((t) => t !== 'null' && t !== null)[0];
|
|
@@ -32,6 +32,9 @@ function transformSchema(context, schema) {
|
|
|
32
32
|
schema.type = newType;
|
|
33
33
|
kind = (0, helpers_1.determineSchemaKind)(schema);
|
|
34
34
|
}
|
|
35
|
+
else {
|
|
36
|
+
schema.type = types.filter((t) => t !== 'null' && t !== null);
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
39
|
const id = context.idGenerator.generateId('schema');
|
|
37
40
|
const nameInfo = (0, helpers_1.determineSchemaName)(schema, id);
|
|
@@ -154,7 +157,9 @@ function resolveDescriminatorMapping(context, schema) {
|
|
|
154
157
|
for (const key of Object.keys(discriminator.mapping)) {
|
|
155
158
|
const mappedSchemaRef = discriminator.mapping[key];
|
|
156
159
|
const mappedSchema = transformSchema(context, mappedSchemaRef);
|
|
157
|
-
schema.discriminator
|
|
158
|
-
|
|
160
|
+
if (schema.discriminator) {
|
|
161
|
+
schema.discriminator.mapping[key] = mappedSchema;
|
|
162
|
+
mappedSchema.inheritedSchemas.push(schema);
|
|
163
|
+
}
|
|
159
164
|
}
|
|
160
165
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeItems = void 0;
|
|
4
|
+
function removeItems(array, predicate) {
|
|
5
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
6
|
+
if (predicate(array[i])) {
|
|
7
|
+
array.splice(i, 1);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.removeItems = removeItems;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsInstanceOf = exports.isInstanceOf = exports.classifyArray = void 0;
|
|
4
|
+
function classifyArray(items, classification) {
|
|
5
|
+
const result = { rest: [] };
|
|
6
|
+
for (const key in classification) {
|
|
7
|
+
result[key] = [];
|
|
8
|
+
}
|
|
9
|
+
for (const item of items) {
|
|
10
|
+
let classified = false;
|
|
11
|
+
for (const key in classification) {
|
|
12
|
+
const type = classification[key];
|
|
13
|
+
if (item instanceof type) {
|
|
14
|
+
result[key].push(item);
|
|
15
|
+
classified = true;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!classified) {
|
|
20
|
+
result.rest.push(item);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
exports.classifyArray = classifyArray;
|
|
26
|
+
function isInstanceOf(item, type) {
|
|
27
|
+
return item instanceof type;
|
|
28
|
+
}
|
|
29
|
+
exports.isInstanceOf = isInstanceOf;
|
|
30
|
+
function getIsInstanceOf(type) {
|
|
31
|
+
return (item) => item instanceof type;
|
|
32
|
+
}
|
|
33
|
+
exports.getIsInstanceOf = getIsInstanceOf;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.notNullish = exports.isNullish = void 0;
|
|
3
|
+
exports.asVoid = exports.transformEach = exports.runEach = exports.modifyEach = exports.transform = exports.run = exports.modify = exports.toArray = exports.isIterable = exports.concatSingleOrMultiple = exports.notNullish = exports.isNullish = void 0;
|
|
4
4
|
function isNullish(value) {
|
|
5
5
|
return value === null || value === undefined;
|
|
6
6
|
}
|
|
@@ -9,3 +9,77 @@ function notNullish(value) {
|
|
|
9
9
|
return !isNullish(value);
|
|
10
10
|
}
|
|
11
11
|
exports.notNullish = notNullish;
|
|
12
|
+
function concatSingleOrMultiple(...values) {
|
|
13
|
+
if (values.length === 1) {
|
|
14
|
+
return values[0];
|
|
15
|
+
}
|
|
16
|
+
const result = [];
|
|
17
|
+
for (const value of values) {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
result.push(...value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
result.push(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
exports.concatSingleOrMultiple = concatSingleOrMultiple;
|
|
28
|
+
function isIterable(value) {
|
|
29
|
+
return typeof value === 'object' && value !== null && Symbol.iterator in value;
|
|
30
|
+
}
|
|
31
|
+
exports.isIterable = isIterable;
|
|
32
|
+
function toArray(value) {
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (isIterable(value)) {
|
|
37
|
+
return Array.from(value);
|
|
38
|
+
}
|
|
39
|
+
return [value];
|
|
40
|
+
}
|
|
41
|
+
exports.toArray = toArray;
|
|
42
|
+
function modify(value, callback) {
|
|
43
|
+
if (notNullish(value)) {
|
|
44
|
+
callback(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
exports.modify = modify;
|
|
49
|
+
function run(value, callback) {
|
|
50
|
+
callback(value);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
exports.run = run;
|
|
54
|
+
function transform(value, callback) {
|
|
55
|
+
return callback(value);
|
|
56
|
+
}
|
|
57
|
+
exports.transform = transform;
|
|
58
|
+
function modifyEach(values, callback) {
|
|
59
|
+
for (const value of values) {
|
|
60
|
+
if (notNullish(value)) {
|
|
61
|
+
callback(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return values;
|
|
65
|
+
}
|
|
66
|
+
exports.modifyEach = modifyEach;
|
|
67
|
+
function runEach(values, callback) {
|
|
68
|
+
for (const value of values) {
|
|
69
|
+
callback(value);
|
|
70
|
+
}
|
|
71
|
+
return values;
|
|
72
|
+
}
|
|
73
|
+
exports.runEach = runEach;
|
|
74
|
+
function transformEach(values, callback) {
|
|
75
|
+
const result = [];
|
|
76
|
+
for (const value of values) {
|
|
77
|
+
result.push(callback(value));
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
exports.transformEach = transformEach;
|
|
82
|
+
function asVoid(_) {
|
|
83
|
+
// Do nothing
|
|
84
|
+
}
|
|
85
|
+
exports.asVoid = asVoid;
|
package/cjs/lib/utils/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./array.utils"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./class.utils"), exports);
|
|
4
6
|
tslib_1.__exportStar(require("./common.utils"), exports);
|
|
5
7
|
tslib_1.__exportStar(require("./endpoint.utils"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./error.utils"), exports);
|
|
6
9
|
tslib_1.__exportStar(require("./factory"), exports);
|
|
7
10
|
tslib_1.__exportStar(require("./generator.utils"), exports);
|
|
8
11
|
tslib_1.__exportStar(require("./object.utils"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./schema.utils"), exports);
|
|
10
13
|
tslib_1.__exportStar(require("./source-builder"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./string-builder"), exports);
|
|
11
15
|
tslib_1.__exportStar(require("./string.utils"), exports);
|
|
12
16
|
tslib_1.__exportStar(require("./string.utils.types"), exports);
|
|
13
17
|
tslib_1.__exportStar(require("./type.utils"), exports);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOverwriteProxy = void 0;
|
|
4
|
-
function createOverwriteProxy(target) {
|
|
5
|
-
|
|
4
|
+
function createOverwriteProxy(target, values) {
|
|
5
|
+
const proxy = new Proxy(target, new OverwriteProxyHandler());
|
|
6
|
+
if (values) {
|
|
7
|
+
Object.assign(proxy, values);
|
|
8
|
+
}
|
|
9
|
+
return proxy;
|
|
6
10
|
}
|
|
7
11
|
exports.createOverwriteProxy = createOverwriteProxy;
|
|
8
12
|
class OverwriteProxyHandler {
|
|
@@ -37,7 +37,8 @@ function collectSubSchemaProperties(subSchemas, properties, required, optional)
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
function hasInvalidSubSchema(subSchemas) {
|
|
40
|
-
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
40
|
+
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
41
|
+
(x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Retrieves the first schema reference and the reference chain of a given schema that
|