@goast/typescript 0.9.0 → 0.9.1
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/dist/src/assets.d.ts +18 -0
- package/dist/src/assets.js +18 -0
- package/dist/src/ast/common.d.ts +6 -0
- package/dist/src/ast/node.d.ts +15 -0
- package/dist/src/ast/node.js +15 -0
- package/dist/src/ast/nodes/argument.d.ts +31 -0
- package/dist/src/ast/nodes/argument.js +31 -0
- package/dist/src/ast/nodes/array-type.d.ts +32 -0
- package/dist/src/ast/nodes/array-type.js +32 -0
- package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
- package/dist/src/ast/nodes/arrow-function.js +56 -0
- package/dist/src/ast/nodes/call.d.ts +34 -0
- package/dist/src/ast/nodes/call.js +34 -0
- package/dist/src/ast/nodes/class.d.ts +73 -0
- package/dist/src/ast/nodes/class.js +73 -0
- package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/constructor-parameter.js +37 -0
- package/dist/src/ast/nodes/constructor.d.ts +44 -0
- package/dist/src/ast/nodes/constructor.js +44 -0
- package/dist/src/ast/nodes/decorator.d.ts +35 -0
- package/dist/src/ast/nodes/decorator.js +35 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
- package/dist/src/ast/nodes/doc-tag.js +39 -0
- package/dist/src/ast/nodes/doc.d.ts +38 -0
- package/dist/src/ast/nodes/doc.js +38 -0
- package/dist/src/ast/nodes/enum-value.d.ts +37 -0
- package/dist/src/ast/nodes/enum-value.js +37 -0
- package/dist/src/ast/nodes/enum.d.ts +47 -0
- package/dist/src/ast/nodes/enum.js +47 -0
- package/dist/src/ast/nodes/export.d.ts +51 -0
- package/dist/src/ast/nodes/export.js +51 -0
- package/dist/src/ast/nodes/function-type.d.ts +35 -0
- package/dist/src/ast/nodes/function-type.js +35 -0
- package/dist/src/ast/nodes/function.d.ts +61 -0
- package/dist/src/ast/nodes/function.js +61 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
- package/dist/src/ast/nodes/generic-parameter.js +44 -0
- package/dist/src/ast/nodes/indexer.d.ts +41 -0
- package/dist/src/ast/nodes/indexer.js +41 -0
- package/dist/src/ast/nodes/interface.d.ts +57 -0
- package/dist/src/ast/nodes/interface.js +57 -0
- package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
- package/dist/src/ast/nodes/intersection-type.js +32 -0
- package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
- package/dist/src/ast/nodes/lookup-type.js +34 -0
- package/dist/src/ast/nodes/method.d.ts +90 -0
- package/dist/src/ast/nodes/method.js +90 -0
- package/dist/src/ast/nodes/object-type.d.ts +34 -0
- package/dist/src/ast/nodes/object-type.js +34 -0
- package/dist/src/ast/nodes/object.d.ts +34 -0
- package/dist/src/ast/nodes/object.js +34 -0
- package/dist/src/ast/nodes/parameter.d.ts +51 -0
- package/dist/src/ast/nodes/parameter.js +51 -0
- package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
- package/dist/src/ast/nodes/property-accessor.js +94 -0
- package/dist/src/ast/nodes/property.d.ts +113 -0
- package/dist/src/ast/nodes/property.js +113 -0
- package/dist/src/ast/nodes/reference.d.ts +90 -0
- package/dist/src/ast/nodes/reference.js +66 -0
- package/dist/src/ast/nodes/string.d.ts +35 -0
- package/dist/src/ast/nodes/string.js +35 -0
- package/dist/src/ast/nodes/tuple.d.ts +33 -0
- package/dist/src/ast/nodes/tuple.js +33 -0
- package/dist/src/ast/nodes/type-alias.d.ts +44 -0
- package/dist/src/ast/nodes/type-alias.js +44 -0
- package/dist/src/ast/nodes/typeof.d.ts +41 -0
- package/dist/src/ast/nodes/typeof.js +41 -0
- package/dist/src/ast/nodes/types.d.ts +12 -0
- package/dist/src/ast/nodes/union-type.d.ts +31 -0
- package/dist/src/ast/nodes/union-type.js +31 -0
- package/dist/src/ast/nodes/variable.d.ts +46 -0
- package/dist/src/ast/nodes/variable.js +46 -0
- package/dist/src/ast/references/angular.d.ts +7 -0
- package/dist/src/ast/references/angular.js +7 -0
- package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
- package/dist/src/ast/references/easy-network-stub.js +4 -0
- package/dist/src/ast/references/k6.d.ts +3 -0
- package/dist/src/ast/references/k6.js +3 -0
- package/dist/src/ast/references/rxjs.d.ts +5 -0
- package/dist/src/ast/references/rxjs.js +5 -0
- package/dist/src/ast/references/typescript.d.ts +30 -0
- package/dist/src/ast/references/typescript.js +30 -0
- package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
- package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
- package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
- package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
- package/dist/src/ast/utils/write-ts-members.js +12 -0
- package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
- package/dist/src/ast/utils/write-ts-nodes.js +16 -0
- package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-parameters.js +9 -0
- package/dist/src/common-results.d.ts +65 -0
- package/dist/src/config.d.ts +32 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +104 -0
- package/dist/src/file-builder.js +93 -0
- package/dist/src/generators/file-generator.d.ts +14 -0
- package/dist/src/generators/file-generator.js +9 -0
- package/dist/src/generators/models/model-generator.d.ts +24 -0
- package/dist/src/generators/models/model-generator.js +15 -0
- package/dist/src/generators/models/models-generator.d.ts +16 -0
- package/dist/src/generators/models/models-generator.js +16 -0
- package/dist/src/generators/models/models.d.ts +53 -0
- package/dist/src/generators/models/models.js +8 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
- package/dist/src/generators/services/angular-services/models.d.ts +70 -1
- package/dist/src/generators/services/angular-services/models.js +5 -0
- package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
- package/dist/src/generators/services/angular-services/refs.js +11 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
- package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
- package/dist/src/generators/services/easy-network-stub/models.js +5 -0
- package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
- package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
- package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
- package/dist/src/generators/services/fetch-clients/models.js +5 -0
- package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/fetch-clients/refs.js +7 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
- package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
- package/dist/src/generators/services/k6-clients/models.js +5 -0
- package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
- package/dist/src/generators/services/k6-clients/refs.js +8 -0
- package/dist/src/import-collection.d.ts +81 -0
- package/dist/src/import-collection.js +58 -0
- package/dist/src/utils.d.ts +62 -0
- package/dist/src/utils.js +47 -0
- package/package.json +2 -2
|
@@ -2,10 +2,29 @@ import { extname } from 'node:path';
|
|
|
2
2
|
import { compareString, StringBuilder } from '@goast/core';
|
|
3
3
|
import { defaultTypeScriptGeneratorConfig } from './config.js';
|
|
4
4
|
import { getModulePathRelativeToFile } from './utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* The default options of an `ImportExportCollection`. The transformer and the quote style are taken from
|
|
7
|
+
* `defaultTypeScriptGeneratorConfig`.
|
|
8
|
+
*/
|
|
5
9
|
export const defaultImportExportCollectionOptions = {
|
|
6
10
|
importModuleTransformer: defaultTypeScriptGeneratorConfig.importModuleTransformer,
|
|
7
11
|
useSingleQuotes: defaultTypeScriptGeneratorConfig.useSingleQuotes,
|
|
8
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Collects the imports and re-exports of a file, and writes them as import and export statements.
|
|
15
|
+
*
|
|
16
|
+
* Names are stored per module path, in one map for each form: `import`, `import type` and `@import` names, and the same
|
|
17
|
+
* for re-exports. Adding a name that is already present has no effect, so each name is written once per module.
|
|
18
|
+
*
|
|
19
|
+
* When the statements are written, a project file (a path ending in `.ts`, `.js` or `.json`) is turned into a relative
|
|
20
|
+
* path from the file that the statements are written to, and transformed with `importModuleTransformer`. A package
|
|
21
|
+
* name, such as `rxjs`, is written as it is. The statements are written in this order: value imports, type imports, the
|
|
22
|
+
* `@import` block, value re-exports and type re-exports. Module imports come before file imports, separated by a blank
|
|
23
|
+
* line.
|
|
24
|
+
*
|
|
25
|
+
* `TypeScriptFileBuilder` owns one of these collections. It adds the imports of every `TsReference` node that has a
|
|
26
|
+
* module or file path, and it passes its own `filePath` and options to the collection.
|
|
27
|
+
*/
|
|
9
28
|
export class ImportExportCollection {
|
|
10
29
|
_imports = new Map();
|
|
11
30
|
_typeImports = new Map();
|
|
@@ -13,15 +32,29 @@ export class ImportExportCollection {
|
|
|
13
32
|
_exports = new Map();
|
|
14
33
|
_typeExports = new Map();
|
|
15
34
|
_options;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes a new instance of the ImportExportCollection class.
|
|
37
|
+
* @param options The options of the collection. Options that are not given use the defaults.
|
|
38
|
+
*/
|
|
16
39
|
constructor(options) {
|
|
17
40
|
this._options = { ...defaultImportExportCollectionOptions, ...options };
|
|
18
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets a value indicating whether at least one import of any form has been added.
|
|
44
|
+
*/
|
|
19
45
|
get hasImports() {
|
|
20
46
|
return this._imports.size > 0 || this._typeImports.size > 0 || this._jsDocImports.size > 0;
|
|
21
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets a value indicating whether at least one re-export of any form has been added.
|
|
50
|
+
*/
|
|
22
51
|
get hasExports() {
|
|
23
52
|
return this._exports.size > 0 || this._typeExports.size > 0;
|
|
24
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets all collected imports as a flat list. The module paths are the unresolved ones, as they were passed to
|
|
56
|
+
* `addImport`, so they are not yet relative to the file.
|
|
57
|
+
*/
|
|
25
58
|
get imports() {
|
|
26
59
|
return [
|
|
27
60
|
...this.toImport('import', this._imports),
|
|
@@ -39,6 +72,12 @@ export class ImportExportCollection {
|
|
|
39
72
|
})))
|
|
40
73
|
.flat();
|
|
41
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a named import from a module or a file. Adding the same name from the same module again has no effect.
|
|
77
|
+
* @param importName The name to import.
|
|
78
|
+
* @param fromModule The module name, such as `rxjs`, or the path of the file that exports the name.
|
|
79
|
+
* @param options The options of the import, such as the import type. Defaults to a value import.
|
|
80
|
+
*/
|
|
42
81
|
addImport(importName, fromModule, options) {
|
|
43
82
|
const map = this.getImportMap(options?.type ?? 'import');
|
|
44
83
|
const existingImport = map.get(fromModule);
|
|
@@ -49,6 +88,12 @@ export class ImportExportCollection {
|
|
|
49
88
|
map.set(fromModule, new Set([importName]));
|
|
50
89
|
}
|
|
51
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Adds a named re-export from a module or a file. Adding the same name from the same module again has no effect.
|
|
93
|
+
* @param exportName The name to re-export.
|
|
94
|
+
* @param fromModule The module name, or the path of the file that exports the name.
|
|
95
|
+
* @param options The options of the export, such as the export type. Defaults to a value export.
|
|
96
|
+
*/
|
|
52
97
|
addExport(exportName, fromModule, options) {
|
|
53
98
|
const map = this.getExportMap(options?.type ?? 'export');
|
|
54
99
|
const existingExport = map.get(fromModule);
|
|
@@ -59,6 +104,9 @@ export class ImportExportCollection {
|
|
|
59
104
|
map.set(fromModule, new Set([exportName]));
|
|
60
105
|
}
|
|
61
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Removes all collected imports and re-exports.
|
|
109
|
+
*/
|
|
62
110
|
clear() {
|
|
63
111
|
this._imports.clear();
|
|
64
112
|
this._typeImports.clear();
|
|
@@ -66,11 +114,21 @@ export class ImportExportCollection {
|
|
|
66
114
|
this._exports.clear();
|
|
67
115
|
this._typeExports.clear();
|
|
68
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Renders the import and export statements as a string.
|
|
119
|
+
* @param options The options of the builder that the statements are written with.
|
|
120
|
+
* @returns The import and export statements.
|
|
121
|
+
*/
|
|
69
122
|
toString(options) {
|
|
70
123
|
const builder = new StringBuilder(options);
|
|
71
124
|
this.writeTo(builder);
|
|
72
125
|
return builder.toString();
|
|
73
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Writes the import and export statements to a builder. The statements are written in the order described for the
|
|
129
|
+
* class, and the groups are separated by a blank line.
|
|
130
|
+
* @param builder The builder to write the statements to.
|
|
131
|
+
*/
|
|
74
132
|
writeTo(builder) {
|
|
75
133
|
const { filePath, importModuleTransformer, useSingleQuotes } = this._options;
|
|
76
134
|
let hasPrevious = false;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,8 +1,70 @@
|
|
|
1
1
|
import type { ApiComponent, Nullable } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Describes how the module path of an import from a generated file into a project file is written. The path is always
|
|
4
|
+
* relative to the importing file and starts with `./` or `../`.
|
|
5
|
+
* - `'omit-extension'` removes the file extension.
|
|
6
|
+
* - `'with-extension'` keeps the file extension.
|
|
7
|
+
* - `'js-extension'` replaces the file extension with `.js`.
|
|
8
|
+
* - A function receives the relative path and returns the module path to write.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Importing `src/models/user.ts` from `src/services/api.ts` produces:
|
|
12
|
+
* // 'omit-extension': '../models/user'
|
|
13
|
+
* // 'with-extension': '../models/user.ts'
|
|
14
|
+
* // 'js-extension': '../models/user.js'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
2
17
|
export type ImportModuleTransformer = 'omit-extension' | 'with-extension' | 'js-extension' | ((module: string) => string);
|
|
18
|
+
/**
|
|
19
|
+
* Converts a string into a TypeScript string literal. The value is escaped the way JSON escapes it, and the literal is
|
|
20
|
+
* quoted with single quotes if `useSingleQuotes` is set, or with double quotes otherwise.
|
|
21
|
+
* @param value The string to convert.
|
|
22
|
+
* @param useSingleQuotes Whether to quote the literal with single quotes.
|
|
23
|
+
* @returns The string literal, including its quotes.
|
|
24
|
+
*/
|
|
3
25
|
export declare function toTypeScriptStringLiteral(value: string, useSingleQuotes: boolean): string;
|
|
26
|
+
/**
|
|
27
|
+
* Converts a name into a TypeScript object property name. A name that is a plain identifier is written as it is, and
|
|
28
|
+
* any other name is written as a string literal.
|
|
29
|
+
* @param value The property name to convert.
|
|
30
|
+
* @param useSingleQuotes Whether a string literal is quoted with single quotes.
|
|
31
|
+
* @returns The property name, quoted if it is not a plain identifier.
|
|
32
|
+
*/
|
|
4
33
|
export declare function toTypeScriptPropertyName(value: string, useSingleQuotes: boolean): string;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the module path that a file at `from` uses to import the file at `to`. The path is relative to the directory of
|
|
36
|
+
* `from`, uses forward slashes, and is transformed with `transformer`.
|
|
37
|
+
* @param from The path of the importing file.
|
|
38
|
+
* @param to The path of the imported file.
|
|
39
|
+
* @param transformer The transformer that writes the module path.
|
|
40
|
+
* @returns The module path, such as `./user` or `../models/user`.
|
|
41
|
+
*/
|
|
5
42
|
export declare function getModulePathRelativeToFile(from: string, to: string, transformer: ImportModuleTransformer): string;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the module path that imports the file at `to` from the directory `from`. The path is relative to `from`, uses
|
|
45
|
+
* forward slashes, and is transformed with `transformer`.
|
|
46
|
+
* @param from The directory that the import is written in.
|
|
47
|
+
* @param to The path of the imported file.
|
|
48
|
+
* @param transformer The transformer that writes the module path.
|
|
49
|
+
* @returns The module path, such as `./user` or `../models/user`.
|
|
50
|
+
*/
|
|
6
51
|
export declare function getModulePathRelativeToDirectory(from: string, to: string, transformer: ImportModuleTransformer): string;
|
|
52
|
+
/**
|
|
53
|
+
* Applies a modifier to a string. A string modifier replaces the value entirely. A RegExp keeps only the part of the
|
|
54
|
+
* value that it matches, or leaves the value as it is if it does not match. A function returns its own result for the
|
|
55
|
+
* value and the extra arguments. A nullish modifier leaves the value as it is.
|
|
56
|
+
* @template TArgs The types of the extra arguments that are passed to a function modifier.
|
|
57
|
+
* @param value The string to modify.
|
|
58
|
+
* @param modifier The modifier to apply.
|
|
59
|
+
* @param args The extra arguments that are passed to a function modifier.
|
|
60
|
+
* @returns The modified string.
|
|
61
|
+
*/
|
|
7
62
|
export declare function modifyString<TArgs extends unknown[]>(value: string, modifier: Nullable<string | RegExp | ((value: string, ...args: TArgs) => string)>, ...args: TArgs): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a documentation line that names the source location of a component in its OpenAPI document. The file path is
|
|
65
|
+
* relative to the current working directory and uses forward slashes.
|
|
66
|
+
* @template T The type of the value of the component.
|
|
67
|
+
* @param component The component to get the source location for.
|
|
68
|
+
* @returns A line that starts with `Source:` and names the file, the line, the column and the path of the component.
|
|
69
|
+
*/
|
|
8
70
|
export declare function getSourceDocLine<T>(component: ApiComponent<T>): string;
|
package/dist/src/utils.js
CHANGED
|
@@ -3,18 +3,48 @@ import process from 'node:process';
|
|
|
3
3
|
function doubleQuotedToSingleQuoted(value) {
|
|
4
4
|
return `'${value.slice(1, -1).replace(/'/g, "\\'")}'`;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Converts a string into a TypeScript string literal. The value is escaped the way JSON escapes it, and the literal is
|
|
8
|
+
* quoted with single quotes if `useSingleQuotes` is set, or with double quotes otherwise.
|
|
9
|
+
* @param value The string to convert.
|
|
10
|
+
* @param useSingleQuotes Whether to quote the literal with single quotes.
|
|
11
|
+
* @returns The string literal, including its quotes.
|
|
12
|
+
*/
|
|
6
13
|
export function toTypeScriptStringLiteral(value, useSingleQuotes) {
|
|
7
14
|
return useSingleQuotes ? doubleQuotedToSingleQuoted(JSON.stringify(value)) : JSON.stringify(value);
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts a name into a TypeScript object property name. A name that is a plain identifier is written as it is, and
|
|
18
|
+
* any other name is written as a string literal.
|
|
19
|
+
* @param value The property name to convert.
|
|
20
|
+
* @param useSingleQuotes Whether a string literal is quoted with single quotes.
|
|
21
|
+
* @returns The property name, quoted if it is not a plain identifier.
|
|
22
|
+
*/
|
|
9
23
|
export function toTypeScriptPropertyName(value, useSingleQuotes) {
|
|
10
24
|
if (value.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/)) {
|
|
11
25
|
return value;
|
|
12
26
|
}
|
|
13
27
|
return useSingleQuotes ? doubleQuotedToSingleQuoted(JSON.stringify(value)) : JSON.stringify(value);
|
|
14
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the module path that a file at `from` uses to import the file at `to`. The path is relative to the directory of
|
|
31
|
+
* `from`, uses forward slashes, and is transformed with `transformer`.
|
|
32
|
+
* @param from The path of the importing file.
|
|
33
|
+
* @param to The path of the imported file.
|
|
34
|
+
* @param transformer The transformer that writes the module path.
|
|
35
|
+
* @returns The module path, such as `./user` or `../models/user`.
|
|
36
|
+
*/
|
|
15
37
|
export function getModulePathRelativeToFile(from, to, transformer) {
|
|
16
38
|
return transformModulePath(relative(dirname(from), to).replace(/\\/g, '/'), transformer);
|
|
17
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets the module path that imports the file at `to` from the directory `from`. The path is relative to `from`, uses
|
|
42
|
+
* forward slashes, and is transformed with `transformer`.
|
|
43
|
+
* @param from The directory that the import is written in.
|
|
44
|
+
* @param to The path of the imported file.
|
|
45
|
+
* @param transformer The transformer that writes the module path.
|
|
46
|
+
* @returns The module path, such as `./user` or `../models/user`.
|
|
47
|
+
*/
|
|
18
48
|
export function getModulePathRelativeToDirectory(from, to, transformer) {
|
|
19
49
|
return transformModulePath(relative(from, to).replace(/\\/g, '/'), transformer);
|
|
20
50
|
}
|
|
@@ -36,6 +66,16 @@ function transformModulePath(modulePath, transformer) {
|
|
|
36
66
|
}
|
|
37
67
|
return modulePath;
|
|
38
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Applies a modifier to a string. A string modifier replaces the value entirely. A RegExp keeps only the part of the
|
|
71
|
+
* value that it matches, or leaves the value as it is if it does not match. A function returns its own result for the
|
|
72
|
+
* value and the extra arguments. A nullish modifier leaves the value as it is.
|
|
73
|
+
* @template TArgs The types of the extra arguments that are passed to a function modifier.
|
|
74
|
+
* @param value The string to modify.
|
|
75
|
+
* @param modifier The modifier to apply.
|
|
76
|
+
* @param args The extra arguments that are passed to a function modifier.
|
|
77
|
+
* @returns The modified string.
|
|
78
|
+
*/
|
|
39
79
|
export function modifyString(value, modifier, ...args) {
|
|
40
80
|
if (typeof modifier === 'string') {
|
|
41
81
|
return modifier;
|
|
@@ -49,6 +89,13 @@ export function modifyString(value, modifier, ...args) {
|
|
|
49
89
|
}
|
|
50
90
|
return value;
|
|
51
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets a documentation line that names the source location of a component in its OpenAPI document. The file path is
|
|
94
|
+
* relative to the current working directory and uses forward slashes.
|
|
95
|
+
* @template T The type of the value of the component.
|
|
96
|
+
* @param component The component to get the source location for.
|
|
97
|
+
* @returns A line that starts with `Source:` and names the file, the line, the column and the path of the component.
|
|
98
|
+
*/
|
|
52
99
|
export function getSourceDocLine(component) {
|
|
53
100
|
const file = path.relative(process.cwd(), component.$src.file).replace(/\\/g, '/');
|
|
54
101
|
const { line, col } = component.$src.pos;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/typescript",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Provides gOAst generators for generating TypeScript code from OpenAPI specifications.",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/MaSch0212/goast/issues"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"fs-extra": "^11.3.3",
|
|
35
|
-
"@goast/core": "^0.7.
|
|
35
|
+
"@goast/core": "^0.7.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/fs-extra": "^11.0.4",
|