@goast/core 0.6.0-beta.1 → 0.6.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/LICENSE +21 -21
- package/README.md +67 -67
- package/esm/src/codegen/config.d.ts +11 -2
- package/esm/src/codegen/config.d.ts.map +1 -1
- package/esm/src/parse/openapi-types.d.ts +4 -0
- package/esm/src/parse/openapi-types.d.ts.map +1 -1
- package/esm/src/transform/api-types.d.ts +14 -0
- package/esm/src/transform/api-types.d.ts.map +1 -1
- package/esm/src/transform/helpers.d.ts +6 -0
- package/esm/src/transform/helpers.d.ts.map +1 -1
- package/esm/src/transform/helpers.js +34 -5
- package/esm/src/transform/transform-endpoint.js +1 -0
- package/esm/src/transform/transform-schema.d.ts.map +1 -1
- package/esm/src/transform/transform-schema.js +32 -21
- package/esm/src/utils/file-system.utils.d.ts.map +1 -1
- package/esm/src/utils/file-system.utils.js +36 -4
- package/esm/src/utils/schema.utils.d.ts.map +1 -1
- package/esm/src/utils/schema.utils.js +91 -11
- package/esm/src/utils/string.utils.d.ts +19 -0
- package/esm/src/utils/string.utils.d.ts.map +1 -1
- package/esm/src/utils/string.utils.js +25 -0
- package/package.json +1 -1
- package/script/src/codegen/config.d.ts +11 -2
- package/script/src/codegen/config.d.ts.map +1 -1
- package/script/src/parse/openapi-types.d.ts +4 -0
- package/script/src/parse/openapi-types.d.ts.map +1 -1
- package/script/src/transform/api-types.d.ts +14 -0
- package/script/src/transform/api-types.d.ts.map +1 -1
- package/script/src/transform/helpers.d.ts +6 -0
- package/script/src/transform/helpers.d.ts.map +1 -1
- package/script/src/transform/helpers.js +37 -5
- package/script/src/transform/transform-endpoint.js +1 -0
- package/script/src/transform/transform-schema.d.ts.map +1 -1
- package/script/src/transform/transform-schema.js +31 -20
- package/script/src/utils/file-system.utils.d.ts.map +1 -1
- package/script/src/utils/file-system.utils.js +35 -3
- package/script/src/utils/schema.utils.d.ts.map +1 -1
- package/script/src/utils/schema.utils.js +91 -11
- package/script/src/utils/string.utils.d.ts +19 -0
- package/script/src/utils/string.utils.d.ts.map +1 -1
- package/script/src/utils/string.utils.js +26 -0
- package/src/_dnt.shims.ts +69 -0
- package/src/mod.ts +35 -0
- package/src/src/ast/node.ts +46 -0
- package/src/src/codegen/config.ts +50 -0
- package/src/src/codegen/endpoints-generator.ts +72 -0
- package/src/src/codegen/generator.ts +192 -0
- package/src/src/codegen/internal-utils.ts +6 -0
- package/src/src/codegen/schemas-generator.ts +87 -0
- package/src/src/codegen/services-generator.ts +77 -0
- package/src/src/codegen/types.ts +37 -0
- package/src/src/collect/collector.ts +142 -0
- package/src/src/collect/helpers.ts +36 -0
- package/src/src/collect/types.ts +21 -0
- package/src/src/internal-utils.ts +5 -0
- package/src/src/parse/deref-proxy.ts +70 -0
- package/src/src/parse/openapi-types.ts +953 -0
- package/src/src/parse/parser.ts +206 -0
- package/src/src/parse/types.ts +28 -0
- package/src/src/transform/api-types.ts +259 -0
- package/src/src/transform/helpers.ts +251 -0
- package/src/src/transform/transform-document.ts +35 -0
- package/src/src/transform/transform-endpoint.ts +332 -0
- package/src/src/transform/transform-schema.ts +232 -0
- package/src/src/transform/transformer.ts +53 -0
- package/src/src/transform/types.ts +52 -0
- package/src/src/utils/action-provider.ts +58 -0
- package/src/src/utils/api-data.utils.ts +48 -0
- package/src/src/utils/array.utils.ts +7 -0
- package/src/src/utils/asset-manager.ts +51 -0
- package/src/src/utils/class.utils.ts +40 -0
- package/src/src/utils/common.utils.ts +86 -0
- package/src/src/utils/condition.ts +7 -0
- package/src/src/utils/endpoint.utils.ts +10 -0
- package/src/src/utils/error.utils.ts +3 -0
- package/src/src/utils/factory.ts +42 -0
- package/src/src/utils/file-system.utils.ts +97 -0
- package/src/src/utils/generator.utils.ts +6 -0
- package/src/src/utils/object.utils.ts +32 -0
- package/src/src/utils/schema.utils.ts +240 -0
- package/src/src/utils/source-builder.ts +597 -0
- package/src/src/utils/string-builder/options.ts +19 -0
- package/src/src/utils/string-builder/string-builder.ts +165 -0
- package/src/src/utils/string-builder/utils.ts +69 -0
- package/src/src/utils/string.utils.ts +394 -0
- package/src/src/utils/string.utils.types.ts +179 -0
- package/src/src/utils/type.utils.ts +93 -0
- package/src/src/utils/yaml-info.ts +48 -0
|
@@ -35,13 +35,45 @@ async function getFilesImpl(dir, options, files, currentDepth) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Splits a file name into its base and extension, treating the extension as everything from the last dot onward
|
|
40
|
+
* (including the dot). A name with no dot has an empty extension. A name that is nothing but an extension (e.g.
|
|
41
|
+
* `.kt`) has an empty base.
|
|
42
|
+
*/
|
|
43
|
+
function splitFileName(fileName) {
|
|
44
|
+
const dotIndex = fileName.lastIndexOf('.');
|
|
45
|
+
if (dotIndex === -1) {
|
|
46
|
+
return { base: fileName, ext: '' };
|
|
47
|
+
}
|
|
48
|
+
return { base: fileName.slice(0, dotIndex), ext: fileName.slice(dotIndex) };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Finds an unused path derived from `filePath` by inserting `_1` before the extension, then `_2`, and so on, until
|
|
52
|
+
* a path that does not yet exist is found.
|
|
53
|
+
*/
|
|
54
|
+
function getCountedFilePath(filePath) {
|
|
55
|
+
const dir = (0, node_path_1.dirname)(filePath);
|
|
56
|
+
const { base, ext } = splitFileName((0, node_path_1.basename)(filePath));
|
|
57
|
+
let counter = 1;
|
|
58
|
+
let candidate = (0, node_path_1.join)(dir, `${base}_${counter}${ext}`);
|
|
59
|
+
while (fs_extra_1.default.existsSync(candidate)) {
|
|
60
|
+
counter++;
|
|
61
|
+
candidate = (0, node_path_1.join)(dir, `${base}_${counter}${ext}`);
|
|
62
|
+
}
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
38
65
|
function writeGeneratedFile(config, filePath, content) {
|
|
66
|
+
let targetPath = filePath;
|
|
39
67
|
if (config.existingFileBehavior !== 'override' && fs_extra_1.default.existsSync(filePath)) {
|
|
40
68
|
if (config.existingFileBehavior === 'error') {
|
|
41
69
|
throw new Error(`File already exists: ${filePath}`);
|
|
42
70
|
}
|
|
43
|
-
|
|
71
|
+
if (config.existingFileBehavior === 'skip') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// config.existingFileBehavior === 'count'
|
|
75
|
+
targetPath = getCountedFilePath(filePath);
|
|
44
76
|
}
|
|
45
|
-
fs_extra_1.default.ensureDirSync((0, node_path_1.dirname)(
|
|
46
|
-
fs_extra_1.default.writeFileSync(
|
|
77
|
+
fs_extra_1.default.ensureDirSync((0, node_path_1.dirname)(targetPath));
|
|
78
|
+
fs_extra_1.default.writeFileSync(targetPath, content);
|
|
47
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/schema.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAA0C,MAAM,2BAA2B,CAAC;AAEnG,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,EACxC,oBAAoB,EAAE,OAAO,GAC5B,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAgCjC;
|
|
1
|
+
{"version":3,"file":"schema.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/schema.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAA0C,MAAM,2BAA2B,CAAC;AAEnG,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,QAAQ,CAAC,EACxC,oBAAoB,EAAE,OAAO,GAC5B,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAgCjC;AAsLD,eAAO,MAAM,iCAAiC,EAAE,CAAC,MAAM,aAAa,CAAC,EAIpE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,MAAM,aAAa,CAAC,EAAE,GAAG,SAAS,CAM5G"}
|
|
@@ -33,30 +33,105 @@ function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
|
33
33
|
additionalProperties,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
36
|
+
function collectSubSchemaProperties(subSchemas, properties, required, optional, collected = { required: new Set(), optional: new Set() }) {
|
|
37
|
+
const seen = optional ? collected.optional : collected.required;
|
|
37
38
|
for (const subSchema of subSchemas) {
|
|
39
|
+
if (seen.has(subSchema))
|
|
40
|
+
continue;
|
|
41
|
+
seen.add(subSchema);
|
|
38
42
|
if (subSchema.kind === 'object') {
|
|
39
43
|
for (const prop of subSchema.properties.values()) {
|
|
40
|
-
|
|
44
|
+
const existing = properties.get(prop.name);
|
|
45
|
+
if (!existing) {
|
|
41
46
|
properties.set(prop.name, prop);
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
else if (hasConflictingType(existing.schema, prop.schema)) {
|
|
49
|
+
// Two branches declare the same property with types that cannot both hold. Picking one and
|
|
50
|
+
// discarding the other would make the merged schema assert something the source contradicts, so
|
|
51
|
+
// widen to a schema that admits both instead.
|
|
52
|
+
properties.set(prop.name, { name: prop.name, schema: widenSchemas(existing.schema, prop.schema) });
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
}
|
|
56
|
+
// A branch does not have to contribute properties to contribute requiredness: `allOf: [{ required: [x] }]`
|
|
57
|
+
// only tightens a property inherited from a sibling branch and has no type or properties of its own.
|
|
58
|
+
if (!optional) {
|
|
59
|
+
for (const prop of subSchema.required) {
|
|
60
|
+
required.add(prop);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
51
|
-
collectSubSchemaProperties(subSchema.allOf, properties, required, optional);
|
|
52
|
-
collectSubSchemaProperties(subSchema.anyOf, properties, required, true);
|
|
64
|
+
collectSubSchemaProperties(subSchema.allOf, properties, required, optional, collected);
|
|
65
|
+
collectSubSchemaProperties(subSchema.anyOf, properties, required, true, collected);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Exactly one branch of a composed `oneOf` applies to any given instance, so its properties are
|
|
69
|
+
// collected but none of its requiredness is — the same treatment an `anyOf` branch gets.
|
|
70
|
+
const oneOf = composedOneOf(subSchema);
|
|
71
|
+
if (oneOf)
|
|
72
|
+
collectSubSchemaProperties(oneOf, properties, required, true, collected);
|
|
53
73
|
}
|
|
54
74
|
}
|
|
55
75
|
}
|
|
56
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The branches of a `oneOf` sub-schema that describe the same instance as the schema composing it, or
|
|
78
|
+
* `undefined` if it has none.
|
|
79
|
+
*
|
|
80
|
+
* An undiscriminated `oneOf` inside a composition constrains the very instance being composed:
|
|
81
|
+
* `allOf: [{ oneOf: [A, B] }, C]` is "A or B, *and* C", so whichever branch applies contributes its
|
|
82
|
+
* properties to the whole. A `oneOf` that declares a `discriminator` is not a composition but a list of
|
|
83
|
+
* subtypes, and `allOf: [Base]` against such a schema means "is a Base" — the sibling subtypes' properties
|
|
84
|
+
* belong to those siblings, not to the schema inheriting from the base.
|
|
85
|
+
*/
|
|
86
|
+
function composedOneOf(schema) {
|
|
87
|
+
return schema.kind === 'oneOf' && !schema.discriminator ? schema.oneOf : undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether two declarations of one property name state types that cannot both hold. A branch that says
|
|
91
|
+
* nothing about the type (`unknown`) constrains nothing and so never conflicts, and two declarations of the
|
|
92
|
+
* same kind are treated as a refinement of one another rather than a conflict, so the first still wins.
|
|
93
|
+
*/
|
|
94
|
+
function hasConflictingType(a, b) {
|
|
95
|
+
return a.kind !== b.kind && a.kind !== 'unknown' && b.kind !== 'unknown';
|
|
96
|
+
}
|
|
97
|
+
/** The branches a schema contributes to a widened `oneOf`, flattened so widening stays a single level. */
|
|
98
|
+
function conflictBranches(schema) {
|
|
99
|
+
return schema.kind === 'oneOf' ? schema.oneOf : [schema];
|
|
100
|
+
}
|
|
101
|
+
/** A `oneOf` admitting either side of a conflicting merge, so neither side is silently discarded. */
|
|
102
|
+
function widenSchemas(a, b) {
|
|
103
|
+
const oneOf = [];
|
|
104
|
+
for (const branch of [...conflictBranches(a), ...conflictBranches(b)]) {
|
|
105
|
+
if (!oneOf.some((x) => x.id === branch.id))
|
|
106
|
+
oneOf.push(branch);
|
|
107
|
+
}
|
|
108
|
+
// Derived from the branch ids rather than generated, so the same conflict always yields the same schema.
|
|
109
|
+
const id = `conflict-${oneOf.map((x) => x.id).join('+')}`;
|
|
110
|
+
return {
|
|
111
|
+
...a,
|
|
112
|
+
$ref: undefined,
|
|
113
|
+
id,
|
|
114
|
+
name: id,
|
|
115
|
+
isNameGenerated: true,
|
|
116
|
+
kind: 'oneOf',
|
|
117
|
+
enum: undefined,
|
|
118
|
+
const: undefined,
|
|
119
|
+
default: undefined,
|
|
120
|
+
discriminator: undefined,
|
|
121
|
+
inheritedSchemas: [],
|
|
122
|
+
nullable: a.nullable || b.nullable,
|
|
123
|
+
oneOf,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function combineAdditionalProperties(subSchemas, current,
|
|
127
|
+
/** Guards the same composition cycle `collectSubSchemaProperties` guards; see `CollectedSubSchemas`. */
|
|
128
|
+
visited = new Set()) {
|
|
57
129
|
if (current === true)
|
|
58
130
|
return true;
|
|
59
131
|
for (const subSchema of subSchemas) {
|
|
132
|
+
if (visited.has(subSchema))
|
|
133
|
+
continue;
|
|
134
|
+
visited.add(subSchema);
|
|
60
135
|
if (subSchema.kind === 'object' && subSchema.additionalProperties) {
|
|
61
136
|
if (subSchema.additionalProperties === true)
|
|
62
137
|
return true;
|
|
@@ -95,8 +170,13 @@ function combineAdditionalProperties(subSchemas, current) {
|
|
|
95
170
|
}
|
|
96
171
|
}
|
|
97
172
|
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
98
|
-
current = combineAdditionalProperties(subSchema.allOf, current);
|
|
99
|
-
current = combineAdditionalProperties(subSchema.anyOf, current);
|
|
173
|
+
current = combineAdditionalProperties(subSchema.allOf, current, visited);
|
|
174
|
+
current = combineAdditionalProperties(subSchema.anyOf, current, visited);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const oneOf = composedOneOf(subSchema);
|
|
178
|
+
if (oneOf)
|
|
179
|
+
current = combineAdditionalProperties(oneOf, current, visited);
|
|
100
180
|
}
|
|
101
181
|
if (current === true)
|
|
102
182
|
return true;
|
|
@@ -109,6 +109,25 @@ export declare function toCustomCase(str: Nullable<string>, options: CustomCaseO
|
|
|
109
109
|
* @param str The string to escape.
|
|
110
110
|
*/
|
|
111
111
|
export declare function escapeRegExp(str: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
114
|
+
*
|
|
115
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
116
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
117
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
118
|
+
* locale dependency.
|
|
119
|
+
*
|
|
120
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
121
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
122
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
123
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
124
|
+
* locale collation but entirely reproducible.
|
|
125
|
+
*
|
|
126
|
+
* @param a The first string.
|
|
127
|
+
* @param b The second string.
|
|
128
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
129
|
+
*/
|
|
130
|
+
export declare function compareString(a: string, b: string): number;
|
|
112
131
|
/**
|
|
113
132
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
114
133
|
* @param str The string to splice.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.utils.d.ts","sourceRoot":"","sources":["../../../src/src/utils/string.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,gBAAgB,EAEhB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EACvB,UAAU,EACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,CAAC;AAC7E,wBAAgB,YAAY,CAC1B,CAAC,EAAE,YAAY,GAAG,uBAAuB,EACzC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,uBAAuB,CAAC,GACjD,uBAAuB,CAAC;AAkB3B,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QA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AO,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAS9F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAUtF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpG;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI9C;AA6BD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK3E;AACD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAK7E;AACD,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,MAAM,CAOxE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAW1D"}
|
|
@@ -14,6 +14,7 @@ exports.toKebabCase = toKebabCase;
|
|
|
14
14
|
exports.toSnakeCase = toSnakeCase;
|
|
15
15
|
exports.toCustomCase = toCustomCase;
|
|
16
16
|
exports.escapeRegExp = escapeRegExp;
|
|
17
|
+
exports.compareString = compareString;
|
|
17
18
|
exports.spliceString = spliceString;
|
|
18
19
|
exports.trimIndent = trimIndent;
|
|
19
20
|
exports.trimEnd = trimEnd;
|
|
@@ -267,6 +268,31 @@ function toCustomCase(str, options) {
|
|
|
267
268
|
function escapeRegExp(str) {
|
|
268
269
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
269
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Compares two strings for sorting, case-insensitively, without any dependency on the host locale.
|
|
273
|
+
*
|
|
274
|
+
* Deliberately not `String.prototype.localeCompare`: its collation depends on the host locale and ICU
|
|
275
|
+
* version, so the same input would sort differently on different machines — which would make
|
|
276
|
+
* generated output non-reproducible. `toLowerCase` is Unicode default case conversion and carries no
|
|
277
|
+
* locale dependency.
|
|
278
|
+
*
|
|
279
|
+
* Comparison is case-insensitive so that, for example, `awaitBody` sorts alphabetically beside
|
|
280
|
+
* `WebClient` rather than after every capitalized name. Strings differing only in case fall back to a
|
|
281
|
+
* case-sensitive comparison, so their relative order is still stable. Non-ASCII characters order by
|
|
282
|
+
* code point rather than alphabetically — `Ähre` sorts after `Zebra` — which is less pretty than
|
|
283
|
+
* locale collation but entirely reproducible.
|
|
284
|
+
*
|
|
285
|
+
* @param a The first string.
|
|
286
|
+
* @param b The second string.
|
|
287
|
+
* @returns A negative number if `a` sorts first, a positive number if `b` does, otherwise 0.
|
|
288
|
+
*/
|
|
289
|
+
function compareString(a, b) {
|
|
290
|
+
const lowerA = a.toLowerCase();
|
|
291
|
+
const lowerB = b.toLowerCase();
|
|
292
|
+
if (lowerA !== lowerB)
|
|
293
|
+
return lowerA < lowerB ? -1 : 1;
|
|
294
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
295
|
+
}
|
|
270
296
|
/**
|
|
271
297
|
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
272
298
|
* @param str The string to splice.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
2
|
+
export { fetch, File, FormData, Headers, Request, Response, type BodyInit, type HeadersInit, type ReferrerPolicy, type RequestInit, type RequestCache, type RequestMode, type RequestRedirect, type ResponseInit } from "undici";
|
|
3
|
+
|
|
4
|
+
const dntGlobals = {
|
|
5
|
+
fetch,
|
|
6
|
+
File,
|
|
7
|
+
FormData,
|
|
8
|
+
Headers,
|
|
9
|
+
Request,
|
|
10
|
+
Response,
|
|
11
|
+
};
|
|
12
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
13
|
+
|
|
14
|
+
function createMergeProxy<T extends object, U extends object>(
|
|
15
|
+
baseObj: T,
|
|
16
|
+
extObj: U,
|
|
17
|
+
): Omit<T, keyof U> & U {
|
|
18
|
+
return new Proxy(baseObj, {
|
|
19
|
+
get(_target, prop, _receiver) {
|
|
20
|
+
if (prop in extObj) {
|
|
21
|
+
return (extObj as any)[prop];
|
|
22
|
+
} else {
|
|
23
|
+
return (baseObj as any)[prop];
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
set(_target, prop, value) {
|
|
27
|
+
if (prop in extObj) {
|
|
28
|
+
delete (extObj as any)[prop];
|
|
29
|
+
}
|
|
30
|
+
(baseObj as any)[prop] = value;
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
deleteProperty(_target, prop) {
|
|
34
|
+
let success = false;
|
|
35
|
+
if (prop in extObj) {
|
|
36
|
+
delete (extObj as any)[prop];
|
|
37
|
+
success = true;
|
|
38
|
+
}
|
|
39
|
+
if (prop in baseObj) {
|
|
40
|
+
delete (baseObj as any)[prop];
|
|
41
|
+
success = true;
|
|
42
|
+
}
|
|
43
|
+
return success;
|
|
44
|
+
},
|
|
45
|
+
ownKeys(_target) {
|
|
46
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
47
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
48
|
+
const extKeysSet = new Set(extKeys);
|
|
49
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
50
|
+
},
|
|
51
|
+
defineProperty(_target, prop, desc) {
|
|
52
|
+
if (prop in extObj) {
|
|
53
|
+
delete (extObj as any)[prop];
|
|
54
|
+
}
|
|
55
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
56
|
+
return true;
|
|
57
|
+
},
|
|
58
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
59
|
+
if (prop in extObj) {
|
|
60
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
61
|
+
} else {
|
|
62
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
has(_target, prop) {
|
|
66
|
+
return prop in extObj || prop in baseObj;
|
|
67
|
+
},
|
|
68
|
+
}) as any;
|
|
69
|
+
}
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * from './src/ast/node.js';
|
|
2
|
+
|
|
3
|
+
export * from './src/codegen/config.js';
|
|
4
|
+
export * from './src/codegen/endpoints-generator.js';
|
|
5
|
+
export * from './src/codegen/generator.js';
|
|
6
|
+
export * from './src/codegen/schemas-generator.js';
|
|
7
|
+
export * from './src/codegen/services-generator.js';
|
|
8
|
+
export * from './src/codegen/types.js';
|
|
9
|
+
|
|
10
|
+
export * from './src/parse/openapi-types.js';
|
|
11
|
+
export * from './src/parse/parser.js';
|
|
12
|
+
export * from './src/parse/types.js';
|
|
13
|
+
|
|
14
|
+
export * from './src/transform/api-types.js';
|
|
15
|
+
export * from './src/transform/transformer.js';
|
|
16
|
+
|
|
17
|
+
export * from './src/utils/api-data.utils.js';
|
|
18
|
+
export * from './src/utils/array.utils.js';
|
|
19
|
+
export * from './src/utils/asset-manager.js';
|
|
20
|
+
export * from './src/utils/class.utils.js';
|
|
21
|
+
export * from './src/utils/common.utils.js';
|
|
22
|
+
export * from './src/utils/endpoint.utils.js';
|
|
23
|
+
export * from './src/utils/error.utils.js';
|
|
24
|
+
export * from './src/utils/factory.js';
|
|
25
|
+
export * from './src/utils/file-system.utils.js';
|
|
26
|
+
export * from './src/utils/generator.utils.js';
|
|
27
|
+
export * from './src/utils/object.utils.js';
|
|
28
|
+
export * from './src/utils/schema.utils.js';
|
|
29
|
+
export * from './src/utils/source-builder.js';
|
|
30
|
+
export * from './src/utils/string-builder/options.js';
|
|
31
|
+
export { type AppendParam, StringBuilder } from './src/utils/string-builder/string-builder.js';
|
|
32
|
+
export * from './src/utils/string-builder/utils.js';
|
|
33
|
+
export * from './src/utils/string.utils.js';
|
|
34
|
+
export * from './src/utils/string.utils.types.js';
|
|
35
|
+
export * from './src/utils/type.utils.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { StringBuilder } from '../utils/string-builder/string-builder.js';
|
|
2
|
+
import type { AppendValue } from '../utils/string-builder/utils.js';
|
|
3
|
+
import type { Prettify } from '../utils/type.utils.js';
|
|
4
|
+
|
|
5
|
+
const NODE_HISTORY_SYMBOL = Symbol('node-history');
|
|
6
|
+
type BuilderWithHistory<T extends StringBuilder = StringBuilder> = T & { [NODE_HISTORY_SYMBOL]?: AstNode[] };
|
|
7
|
+
|
|
8
|
+
export type AstNodeInject<TBuilder extends StringBuilder, TInjects extends string> = {
|
|
9
|
+
[K in `${'after' | 'before'}${Capitalize<TInjects>}`]?: AppendValue<TBuilder>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AstNodeOptions<
|
|
13
|
+
// deno-lint-ignore no-explicit-any
|
|
14
|
+
TBase extends abstract new (...args: any) => any,
|
|
15
|
+
// deno-lint-ignore ban-types
|
|
16
|
+
TExtensions extends object = {},
|
|
17
|
+
> = Prettify<TExtensions & ConstructorParameters<TBase>[0]>;
|
|
18
|
+
|
|
19
|
+
export abstract class AstNode<TBuilder extends StringBuilder = StringBuilder, TInjects extends string = never> {
|
|
20
|
+
public inject: AstNodeInject<TBuilder, TInjects | ''>;
|
|
21
|
+
|
|
22
|
+
constructor(options: { inject?: AstNode<TBuilder, TInjects>['inject'] }) {
|
|
23
|
+
this.inject = options.inject ?? {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public write(builder: TBuilder): void {
|
|
27
|
+
let history = (builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL];
|
|
28
|
+
if (!history) {
|
|
29
|
+
history = [];
|
|
30
|
+
(builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL] = history;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
history.push(this);
|
|
34
|
+
builder.append(this.inject.before);
|
|
35
|
+
this.onWrite(builder);
|
|
36
|
+
builder.append(this.inject.after);
|
|
37
|
+
history.pop();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected getParentNode(builder: TBuilder): AstNode | undefined {
|
|
41
|
+
const history = (builder as BuilderWithHistory)[NODE_HISTORY_SYMBOL];
|
|
42
|
+
return history?.at(-2);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected abstract onWrite(builder: TBuilder): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { OpenApiParserOptions } from '../parse/types.js';
|
|
2
|
+
import { defaultOpenApiTransformerOptions } from '../transform/types.js';
|
|
3
|
+
import { defaultSourceBuilderOptions, type SourceBuilderOptions } from '../utils/source-builder.js';
|
|
4
|
+
|
|
5
|
+
export type OpenApiGeneratorConfig =
|
|
6
|
+
& SourceBuilderOptions
|
|
7
|
+
& OpenApiParserOptions
|
|
8
|
+
& {
|
|
9
|
+
/**
|
|
10
|
+
* The directory where the generated files should be saved.
|
|
11
|
+
* @default 'generated'
|
|
12
|
+
*/
|
|
13
|
+
outputDir: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether to clear the output directory before generating the files.
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
clearOutputDir: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How to handle existing files in the output directory.
|
|
23
|
+
* - 'override': overwrite existing files.
|
|
24
|
+
* - 'skip': skip generating files that already exist.
|
|
25
|
+
* - 'error': throw an error if a file already exists.
|
|
26
|
+
* - 'count': write to a new path derived by inserting `_1` before the file extension (`_2`, `_3`, ... if that
|
|
27
|
+
* path is also taken). A counted file is written under a name no other generated file references. The
|
|
28
|
+
* generators compute a schema's file path from its name and use that same path when they emit an import or
|
|
29
|
+
* type reference, so the reference still points at the first file written. `'count'` makes a collision
|
|
30
|
+
* inspectable instead of fatal; it does not make the output correct. It also has a second failure mode
|
|
31
|
+
* unrelated to collisions: with `clearOutputDir: false`, every regeneration finds the previous run's file
|
|
32
|
+
* already on disk and counts up again, so re-running the generator against the same output directory silently
|
|
33
|
+
* accumulates another `_N` file per schema on every run, forever, with no error to signal it.
|
|
34
|
+
*
|
|
35
|
+
* Is is recommended to use `'error'` to prevent issues of two schemas generating the same file and overwriting each other.
|
|
36
|
+
* If `clearOutputDir` is set to `false`, it is recommended to use `'override'` instead of `'count'` to ensure
|
|
37
|
+
* that the generated files are up to date without accumulating stale counted copies on every run.
|
|
38
|
+
* @default 'error'
|
|
39
|
+
*/
|
|
40
|
+
existingFileBehavior: 'override' | 'skip' | 'error' | 'count';
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const defaultOpenApiGeneratorConfig: OpenApiGeneratorConfig = {
|
|
44
|
+
...defaultSourceBuilderOptions,
|
|
45
|
+
...defaultOpenApiTransformerOptions,
|
|
46
|
+
|
|
47
|
+
outputDir: 'generated',
|
|
48
|
+
clearOutputDir: true,
|
|
49
|
+
existingFileBehavior: 'error',
|
|
50
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ApiEndpoint } from '../transform/api-types.js';
|
|
2
|
+
import type { MaybePromise } from '../utils/type.utils.js';
|
|
3
|
+
import { type DefaultGenerationProviderConfig, OpenApiGenerationProviderBase } from './generator.js';
|
|
4
|
+
import { addSourceIfTest } from './internal-utils.js';
|
|
5
|
+
import type {
|
|
6
|
+
AnyConfig,
|
|
7
|
+
OpenApiGenerationProviderContext,
|
|
8
|
+
OpenApiGeneratorContext,
|
|
9
|
+
OpenApiGeneratorInput,
|
|
10
|
+
OpenApiGeneratorOutput,
|
|
11
|
+
} from './types.js';
|
|
12
|
+
|
|
13
|
+
export type OpenApiEndpointsGenerationProviderContext<
|
|
14
|
+
TInput extends OpenApiGeneratorInput,
|
|
15
|
+
TOutput extends OpenApiGeneratorOutput,
|
|
16
|
+
TConfig extends AnyConfig,
|
|
17
|
+
TEndpointOutput extends OpenApiGeneratorOutput,
|
|
18
|
+
> = OpenApiGenerationProviderContext<TInput, TConfig> & {
|
|
19
|
+
existingEndpointResults: Map<string, TEndpointOutput>;
|
|
20
|
+
output: TOutput;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export abstract class OpenApiEndpointsGenerationProviderBase<
|
|
24
|
+
TInput extends OpenApiGeneratorInput,
|
|
25
|
+
TOutput extends OpenApiGeneratorOutput,
|
|
26
|
+
TConfig extends AnyConfig,
|
|
27
|
+
TEndpointOutput extends OpenApiGeneratorOutput,
|
|
28
|
+
TContext extends OpenApiEndpointsGenerationProviderContext<TInput, TOutput, TConfig, TEndpointOutput>,
|
|
29
|
+
> extends OpenApiGenerationProviderBase<TInput, TOutput, TConfig, TContext> {
|
|
30
|
+
protected override getProviderContext(
|
|
31
|
+
context: OpenApiGeneratorContext<TInput>,
|
|
32
|
+
config: Partial<TConfig> | undefined,
|
|
33
|
+
defaultConfig: DefaultGenerationProviderConfig<TConfig>,
|
|
34
|
+
): OpenApiEndpointsGenerationProviderContext<TInput, TOutput, TConfig, TEndpointOutput> {
|
|
35
|
+
const ctx = super.getProviderContext(context, config, defaultConfig);
|
|
36
|
+
return Object.assign(ctx, {
|
|
37
|
+
existingEndpointResults: new Map<string, TEndpointOutput>(),
|
|
38
|
+
output: this.initResult(ctx),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected override async onGenerate(ctx: TContext): Promise<TOutput> {
|
|
43
|
+
for (const endpoint of ctx.data.endpoints) {
|
|
44
|
+
await this.getEndpointResult(ctx, endpoint);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await this.generateAdditionalFiles(ctx);
|
|
48
|
+
|
|
49
|
+
return ctx.output;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async getEndpointResult(ctx: TContext, endpoint: ApiEndpoint): Promise<TEndpointOutput> {
|
|
53
|
+
const existingResult = ctx.existingEndpointResults.get(endpoint.id);
|
|
54
|
+
if (existingResult) return existingResult;
|
|
55
|
+
|
|
56
|
+
const result = await this.generateEndpoint(ctx, endpoint);
|
|
57
|
+
addSourceIfTest(ctx.config, result, () => `${endpoint.$src.file}#${endpoint.$src.path}`);
|
|
58
|
+
this.addEndpointResult(ctx, endpoint, result);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected abstract initResult(ctx: OpenApiGenerationProviderContext<TInput, TConfig>): TOutput;
|
|
63
|
+
|
|
64
|
+
protected abstract generateEndpoint(ctx: TContext, endpoint: ApiEndpoint): Promise<TEndpointOutput>;
|
|
65
|
+
|
|
66
|
+
protected abstract addEndpointResult(ctx: TContext, endpoint: ApiEndpoint, result: TEndpointOutput): void;
|
|
67
|
+
|
|
68
|
+
// deno-lint-ignore no-unused-vars
|
|
69
|
+
protected generateAdditionalFiles(ctx: TContext): MaybePromise<void> {
|
|
70
|
+
// Override if needed
|
|
71
|
+
}
|
|
72
|
+
}
|