type-crafter 0.9.2 → 0.9.3
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/generators/generic.d.ts +2 -0
- package/dist/generators/helpers.d.ts +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20528 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/typescript/allOf-syntax.hbs +19 -0
- package/dist/templates/typescript/enum-syntax.hbs +13 -0
- package/dist/templates/typescript/exporter-module-syntax.hbs +3 -0
- package/dist/templates/typescript/index.d.ts +2 -0
- package/dist/templates/typescript/object-syntax.hbs +27 -0
- package/dist/templates/typescript/oneOf-syntax.hbs +19 -0
- package/dist/templates/typescript/types-file-syntax.hbs +5 -0
- package/dist/templates/typescript-with-decoders/allOf-syntax.hbs +42 -0
- package/dist/templates/typescript-with-decoders/enum-syntax.hbs +33 -0
- package/dist/templates/typescript-with-decoders/index.d.ts +2 -0
- package/dist/templates/typescript-with-decoders/object-syntax.hbs +73 -0
- package/dist/templates/typescript-with-decoders/oneOf-syntax.hbs +74 -0
- package/dist/templates/typescript-with-decoders/types-file-syntax.hbs +7 -0
- package/dist/types/decoders.d.ts +12 -0
- package/dist/types/index.d.ts +185 -0
- package/dist/utils/error-handler.d.ts +16 -0
- package/dist/utils/file-system.d.ts +9 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/writer/helpers.d.ts +3 -0
- package/dist/writer/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AllOfTemplateInput, Configuration, EnumTemplateInput, ExporterModuleTemplateInput, GeneratedReferencedType, ObjectTemplateInput, OneOfTemplateInput, SpecFileData, TypeFilePath, TypesFileTemplateInput } from '$types';
|
|
2
|
+
declare function setConfig(newConfig: Configuration): void;
|
|
3
|
+
declare function getConfig(): Configuration;
|
|
4
|
+
declare function setSpecFileData(newSpecFileData: SpecFileData): void;
|
|
5
|
+
declare function getSpecFileData(): SpecFileData;
|
|
6
|
+
declare function compileTemplates(): void;
|
|
7
|
+
declare function getObjectTemplate(): HandlebarsTemplateDelegate<ObjectTemplateInput>;
|
|
8
|
+
declare function getExporterModuleTemplate(): HandlebarsTemplateDelegate<ExporterModuleTemplateInput>;
|
|
9
|
+
declare function getTypesFileTemplate(): HandlebarsTemplateDelegate<TypesFileTemplateInput>;
|
|
10
|
+
declare function getEnumTemplate(): HandlebarsTemplateDelegate<EnumTemplateInput>;
|
|
11
|
+
declare function getOneOfTemplate(): HandlebarsTemplateDelegate<OneOfTemplateInput>;
|
|
12
|
+
declare function setExpectedOutputFiles(newExpectedOutputFiles: Map<string, TypeFilePath>): void;
|
|
13
|
+
declare function getExpectedOutputFiles(): Map<string, TypeFilePath>;
|
|
14
|
+
declare function getCachedReferencedTypes(): Map<string, GeneratedReferencedType>;
|
|
15
|
+
declare function getCachedReferenceType(referencePath: string): GeneratedReferencedType | null;
|
|
16
|
+
declare function cacheReferenceType(referencePath: string, generatedData: GeneratedReferencedType): void;
|
|
17
|
+
declare function getInputFilePath(absolutePath?: boolean): string;
|
|
18
|
+
declare function getAllOfTemplate(): HandlebarsTemplateDelegate<AllOfTemplateInput>;
|
|
19
|
+
declare const _default: {
|
|
20
|
+
getConfig: typeof getConfig;
|
|
21
|
+
setConfig: typeof setConfig;
|
|
22
|
+
setSpecFileData: typeof setSpecFileData;
|
|
23
|
+
setExpectedOutputFiles: typeof setExpectedOutputFiles;
|
|
24
|
+
getSpecFileData: typeof getSpecFileData;
|
|
25
|
+
getObjectTemplate: typeof getObjectTemplate;
|
|
26
|
+
getExporterModuleTemplate: typeof getExporterModuleTemplate;
|
|
27
|
+
getTypesFileTemplate: typeof getTypesFileTemplate;
|
|
28
|
+
getEnumTemplate: typeof getEnumTemplate;
|
|
29
|
+
getExpectedOutputFiles: typeof getExpectedOutputFiles;
|
|
30
|
+
compileTemplates: typeof compileTemplates;
|
|
31
|
+
getOneOfTemplate: typeof getOneOfTemplate;
|
|
32
|
+
getCachedReferencedTypes: typeof getCachedReferencedTypes;
|
|
33
|
+
getCachedReferenceType: typeof getCachedReferenceType;
|
|
34
|
+
cacheReferenceType: typeof cacheReferenceType;
|
|
35
|
+
getInputFilePath: typeof getInputFilePath;
|
|
36
|
+
getAllOfTemplate: typeof getAllOfTemplate;
|
|
37
|
+
};
|
|
38
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type {{typeName}} =
|
|
2
|
+
{{#each compositions}}
|
|
3
|
+
{{#if (eq this.source 'referenced')}}{{referencedType}}
|
|
4
|
+
{{else if (eq this.source 'inline')}}
|
|
5
|
+
{{#if this.templateInput.values}}
|
|
6
|
+
{{this.templateInput.typeName}}
|
|
7
|
+
{{else if (eq this.dataType 'object')}}
|
|
8
|
+
{{this.templateInput.typeName}}
|
|
9
|
+
{{else}}
|
|
10
|
+
{{this.templateInput.type}}
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{/if}} {{#unless @last}} & {{/unless}}
|
|
13
|
+
{{/each}};
|
|
14
|
+
|
|
15
|
+
{{#each compositions}}
|
|
16
|
+
{{#if (eq this.dataType 'object')}}
|
|
17
|
+
{{{this.content}}}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{/each}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type { {{typeName}} }
|
|
3
|
+
{{#if description}}
|
|
4
|
+
* @description {{{description}}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if example}}
|
|
7
|
+
* @example {{{example}}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
*/
|
|
10
|
+
export type {{typeName}} =
|
|
11
|
+
{{#each values}}
|
|
12
|
+
| {{#if (eq ../type 'string') }}'{{/if}}{{{this}}}{{#if (eq ../type 'string')}}'{{/if}}
|
|
13
|
+
{{/each}};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type { {{typeName}} }
|
|
3
|
+
{{#if description}}
|
|
4
|
+
* @description {{{description}}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if example}}
|
|
7
|
+
* @example {{{example}}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
*/
|
|
10
|
+
export type {{typeName}} = {
|
|
11
|
+
{{#each properties}}
|
|
12
|
+
/**
|
|
13
|
+
{{#if this.description}}
|
|
14
|
+
* @description {{{this.description}}}
|
|
15
|
+
{{/if}}
|
|
16
|
+
* @type { {{this.type}} }
|
|
17
|
+
* @memberof {{../typeName}}
|
|
18
|
+
{{#if this.example}}
|
|
19
|
+
* @example {{{this.example}}}
|
|
20
|
+
{{/if}}
|
|
21
|
+
*/
|
|
22
|
+
{{{jsonKey @key}}}: {{{this.type}}}{{#unless this.required}} | null{{/unless}};
|
|
23
|
+
{{/each}}
|
|
24
|
+
{{#if additionalProperties}}
|
|
25
|
+
[keys: {{jsonKey additionalProperties.keyType}}]: {{additionalProperties.valueType}};
|
|
26
|
+
{{/if}}
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type {{typeName}} =
|
|
2
|
+
{{#each compositions}}
|
|
3
|
+
| {{#if (eq this.source 'referenced')}}{{referencedType}}
|
|
4
|
+
{{else if (eq this.source 'inline')}}
|
|
5
|
+
{{#if this.templateInput.values}}
|
|
6
|
+
{{#each this.templateInput.values}}
|
|
7
|
+
{{#unless @first}}|{{/unless}} {{#if (eq ../this.templateInput.type 'string') }}'{{/if}}{{{this}}}{{#if (eq ../this.templateInput/type 'string')}}'{{/if}}
|
|
8
|
+
{{/each}}
|
|
9
|
+
{{else if (eq this.dataType 'object')}}
|
|
10
|
+
{
|
|
11
|
+
{{#each this.templateInput.properties}}
|
|
12
|
+
{{@key}}: {{{this.type}}}{{#unless this.required}} | null{{/unless}};
|
|
13
|
+
{{/each}}
|
|
14
|
+
}
|
|
15
|
+
{{else}}
|
|
16
|
+
{{this.templateInput.type}}
|
|
17
|
+
{{/if}}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{/each}};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type {{typeName}} =
|
|
2
|
+
{{#each compositions}}
|
|
3
|
+
{{#if (eq this.source 'referenced')}}{{referencedType}}
|
|
4
|
+
{{else if (eq this.source 'inline')}}
|
|
5
|
+
{{#if this.templateInput.values}}
|
|
6
|
+
{{this.templateInput.typeName}}
|
|
7
|
+
{{else if (eq this.dataType 'object')}}
|
|
8
|
+
{{this.templateInput.typeName}}
|
|
9
|
+
{{else}}
|
|
10
|
+
{{this.templateInput.type}}
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{/if}} {{#unless @last}} & {{/unless}}
|
|
13
|
+
{{/each}};
|
|
14
|
+
|
|
15
|
+
{{#each compositions}}
|
|
16
|
+
{{#if (eq this.dataType 'object')}}
|
|
17
|
+
{{{this.content}}}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{/each}}
|
|
20
|
+
|
|
21
|
+
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
22
|
+
{{#each compositions}}
|
|
23
|
+
{{#if (eq this.source 'referenced')}}
|
|
24
|
+
const decoded{{referencedType}} = decode{{referencedType}}(rawInput);
|
|
25
|
+
{{else if (eq this.source 'inline')}}
|
|
26
|
+
const decoded{{toPascalCase this.templateInput.typeName}} = decode{{this.templateInput.typeName}}(rawInput);
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{/each}}
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
{{#each compositions}}decoded{{#if (eq this.source 'referenced')}}{{referencedType}}{{else}}{{toPascalCase this.templateInput.typeName}}{{/if}} !== null {{#unless @last}} && {{/unless}} {{/each}}
|
|
32
|
+
) {
|
|
33
|
+
return {
|
|
34
|
+
{{#each compositions}}
|
|
35
|
+
{{#if (eq this.source 'referenced')}}...decoded{{referencedType}},
|
|
36
|
+
{{else}}...decoded{{toPascalCase this.templateInput.typeName}},
|
|
37
|
+
{{/if}}
|
|
38
|
+
{{/each}}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type { {{typeName}} }
|
|
3
|
+
{{#if description}}
|
|
4
|
+
* @description {{{description}}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if example}}
|
|
7
|
+
* @example {{{example}}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
*/
|
|
10
|
+
export type {{typeName}} =
|
|
11
|
+
{{#each values}}
|
|
12
|
+
| {{#if (eq ../type 'string') }}'{{/if}}{{{this}}}{{#if (eq ../type 'string')}}'{{/if}}
|
|
13
|
+
{{/each}};
|
|
14
|
+
|
|
15
|
+
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
16
|
+
switch (rawInput) {
|
|
17
|
+
{{#each values}}
|
|
18
|
+
case {{#if (eq ../type 'string') }}'{{/if}}{{this}}{{#if (eq ../type 'string')}}'{{/if}}:
|
|
19
|
+
{{/each}}
|
|
20
|
+
return rawInput;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function _decode{{typeName}}(rawInput: unknown): {{typeName}} | undefined {
|
|
26
|
+
switch (rawInput) {
|
|
27
|
+
{{#each values}}
|
|
28
|
+
case {{#if (eq ../type 'string') }}'{{/if}}{{this}}{{#if (eq ../type 'string')}}'{{/if}}:
|
|
29
|
+
{{/each}}
|
|
30
|
+
return rawInput;
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type { {{typeName}} }
|
|
3
|
+
{{#if description}}
|
|
4
|
+
* @description {{{description}}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if example}}
|
|
7
|
+
* @example {{{example}}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
*/
|
|
10
|
+
export type {{typeName}} = {{#if (not (isEmptyObject properties))}}{
|
|
11
|
+
{{#each properties}}
|
|
12
|
+
/**
|
|
13
|
+
{{#if this.description}}
|
|
14
|
+
* @description {{{this.description}}}
|
|
15
|
+
{{/if}}
|
|
16
|
+
* @type { {{this.type}} }
|
|
17
|
+
* @memberof {{../typeName}}
|
|
18
|
+
{{#if this.example}}
|
|
19
|
+
* @example {{{this.example}}}
|
|
20
|
+
{{/if}}
|
|
21
|
+
*/
|
|
22
|
+
{{#if this.required}}
|
|
23
|
+
{{{jsonKey @key}}}: {{{this.type}}};
|
|
24
|
+
{{else if this.optional}}
|
|
25
|
+
{{{jsonKey @key}}}?: {{{this.type}}};
|
|
26
|
+
{{else}}
|
|
27
|
+
{{{jsonKey @key}}}: {{{this.type}}} | null;
|
|
28
|
+
{{/if}}
|
|
29
|
+
{{/each}}
|
|
30
|
+
{{#if additionalProperties}}
|
|
31
|
+
[keys: {{jsonKey additionalProperties.keyType}}]: {{additionalProperties.valueType}};
|
|
32
|
+
{{/if}}
|
|
33
|
+
};
|
|
34
|
+
{{else if (or (notEq length additionalProperties 0) (not (isEmptyObject additionalProperties)))}}
|
|
35
|
+
Record<{{jsonKey additionalProperties.keyType}}, {{additionalProperties.valueType}}>;
|
|
36
|
+
{{/if}}
|
|
37
|
+
|
|
38
|
+
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
39
|
+
if (isJSON(rawInput)) {
|
|
40
|
+
{{#each properties}}
|
|
41
|
+
const decoded{{variableName @key}} = {{#if this.referenced ~}}
|
|
42
|
+
decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}]);
|
|
43
|
+
{{~else~}}
|
|
44
|
+
{{~#if (eq this.primitiveType 'array')~}}
|
|
45
|
+
decodeArray(rawInput[{{{indexKey @key}}}], decode{{{toPascalCase this.composerType}}})
|
|
46
|
+
{{~else~}}
|
|
47
|
+
{{#if this.optional}}_{{/if}}decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}])
|
|
48
|
+
{{~/if~}};
|
|
49
|
+
{{~/if}}
|
|
50
|
+
|
|
51
|
+
{{/each}}
|
|
52
|
+
|
|
53
|
+
{{#if (areRequiredKeysPresent properties)}}
|
|
54
|
+
if (
|
|
55
|
+
{{#each (getRequiredKeys properties)}}
|
|
56
|
+
decoded{{toPascalCase this}} === null{{#unless @last}} ||{{/unless}}
|
|
57
|
+
{{/each}}
|
|
58
|
+
) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
{{/if}}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
{{#if additionalProperties}}
|
|
65
|
+
...rawInput,
|
|
66
|
+
{{/if}}
|
|
67
|
+
{{#each properties}}
|
|
68
|
+
{{{jsonKey @key}}}: decoded{{{variableName @key}}}{{#unless @last}},{{/unless}}
|
|
69
|
+
{{/each}}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type {{typeName}} =
|
|
2
|
+
{{#each compositions}}
|
|
3
|
+
| {{#if (eq this.source 'referenced')}}C{{../typeName}}{{referencedType}}
|
|
4
|
+
{{else if (eq this.source 'inline')}}
|
|
5
|
+
{{#if this.templateInput.values}}
|
|
6
|
+
{{this.templateInput.typeName}}
|
|
7
|
+
{{else if (eq this.dataType 'object')}}
|
|
8
|
+
C{{typeName}}{{this.templateInput.typeName}}
|
|
9
|
+
{{else}}
|
|
10
|
+
{{this.templateInput.type}}
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{/each}};
|
|
14
|
+
|
|
15
|
+
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
16
|
+
const result: {{typeName}} | null =
|
|
17
|
+
{{#each compositions}}
|
|
18
|
+
{{#if (eq this.source 'referenced')}}
|
|
19
|
+
decodeC{{../typeName}}{{referencedType}}(rawInput)
|
|
20
|
+
{{else if (eq this.dataType 'object')}}
|
|
21
|
+
decodeC{{this.templateInput.typeName}}(rawInput)
|
|
22
|
+
{{else if (eq this.dataType 'array')}}
|
|
23
|
+
decodeArray(rawInput, decode{{{toPascalCase this.templateInput.composerType}}})
|
|
24
|
+
{{else if this.templateInput.values}}
|
|
25
|
+
decode{{this.templateInput.typeName}}(rawInput)
|
|
26
|
+
{{else}}
|
|
27
|
+
decode{{{toPascalCase this.templateInput.type}}}(rawInput)
|
|
28
|
+
{{/if}}{{#unless @last}}??{{/unless}}
|
|
29
|
+
{{/each}};
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
{{#each compositions}}
|
|
35
|
+
|
|
36
|
+
{{#if this.templateInput.values}}
|
|
37
|
+
{{{this.content}}}
|
|
38
|
+
{{else if (eq this.source 'referenced')}}
|
|
39
|
+
export class C{{../typeName}}{{referencedType}} {
|
|
40
|
+
data: {{referencedType}};
|
|
41
|
+
constructor(data: {{referencedType}}) {
|
|
42
|
+
this.data = data;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function decodeC{{../typeName}}{{referencedType}}(rawInput: unknown): C{{../typeName}}{{referencedType}} | null {
|
|
47
|
+
const result = decode{{referencedType}}(rawInput);
|
|
48
|
+
if (result === null) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return new C{{../typeName}}{{referencedType}}(result);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
{{else if (eq this.dataType 'object')}}
|
|
55
|
+
|
|
56
|
+
{{{this.content}}}
|
|
57
|
+
|
|
58
|
+
export class C{{../typeName}}{{this.templateInput.typeName}} {
|
|
59
|
+
data: {{this.templateInput.typeName}};
|
|
60
|
+
constructor(data: {{this.templateInput.typeName}}) {
|
|
61
|
+
this.data = data;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function decodeC{{this.templateInput.typeName}}(rawInput: unknown) {
|
|
66
|
+
const result = decode{{this.templateInput.typeName}}(rawInput);
|
|
67
|
+
if (result === null) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return new C{{../typeName}}{{this.templateInput.typeName}}(result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
{{/if}}
|
|
74
|
+
{{/each}}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{{#each (getReferencedTypeModules referencedTypes writtenAt)}}
|
|
2
|
+
import { {{#each this.referencedTypes}}type {{this}}, decode{{this}}{{#unless @last}}, {{/unless}} {{/each}} } from '{{this.moduleRelativePath}}';
|
|
3
|
+
{{/each}}
|
|
4
|
+
import { isJSON, {{#each primitives}}decode{{{toPascalCase this}}}, _decode{{{toPascalCase this}}} {{#unless @last}}, {{/unless}}{{/each}} } from 'type-decoder';
|
|
5
|
+
|
|
6
|
+
{{{typesContent}}}
|
|
7
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GroupRef, EnumTemplateInput, GroupedTypesWriterMode, ObjectTemplateInputProperties, SpecFileData, TypeInfo, Types, TypesWriterMode, GroupTypesData, KeyedAdditionalProperties, AdditionalPropertiesKeyType } from '.';
|
|
2
|
+
export declare function decodeGroupedTypesWriterMode(rawInput: unknown): GroupedTypesWriterMode | null;
|
|
3
|
+
export declare function decodeTypesWriterMode(rawInput: unknown): TypesWriterMode | null;
|
|
4
|
+
export declare function decodeSpecFileData(rawInput: unknown): SpecFileData | null;
|
|
5
|
+
export declare function valueIsGroupRef(value: GroupTypesData): value is GroupRef;
|
|
6
|
+
export declare function decodeTypes(rawInput: unknown): Types | null;
|
|
7
|
+
export declare function decodeAdditionalPropertiesKeyType(rawInput: unknown): AdditionalPropertiesKeyType | null;
|
|
8
|
+
export declare function decodeTypeInfo(rawInput: unknown): TypeInfo | null;
|
|
9
|
+
export declare function valueIsKeyedAdditionalProperties(value: unknown): value is KeyedAdditionalProperties;
|
|
10
|
+
export declare function valueIsTypeInfo(value: unknown): value is TypeInfo;
|
|
11
|
+
export declare function decodeObjectTemplateInputProperties(rawInput: unknown): ObjectTemplateInputProperties | null;
|
|
12
|
+
export declare function decodeEnumTemplateInput(rawInput: unknown): EnumTemplateInput | null;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
export * from './decoders';
|
|
2
|
+
export type Configuration = {
|
|
3
|
+
input: string;
|
|
4
|
+
output: OutputConfig;
|
|
5
|
+
template: Template;
|
|
6
|
+
language: LanguageConfig;
|
|
7
|
+
};
|
|
8
|
+
export type OutputConfig = {
|
|
9
|
+
cleanWrite: boolean;
|
|
10
|
+
fileExtension: string;
|
|
11
|
+
directory: string;
|
|
12
|
+
writerMode: {
|
|
13
|
+
groupedTypes: GroupedTypesWriterMode;
|
|
14
|
+
types: TypesWriterMode;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type GroupedTypesWriterMode = 'FolderWithFiles' | 'SingleFile';
|
|
18
|
+
export type TypesWriterMode = 'SingleFile' | 'Files';
|
|
19
|
+
export type Template = {
|
|
20
|
+
objectSyntax: string;
|
|
21
|
+
exporterModuleSyntax: string;
|
|
22
|
+
typesFileSyntax: string;
|
|
23
|
+
enumSyntax: string;
|
|
24
|
+
oneOfSyntax: string;
|
|
25
|
+
allOfSyntax: string;
|
|
26
|
+
};
|
|
27
|
+
export type LanguageConfig = {
|
|
28
|
+
exporterModuleName: string;
|
|
29
|
+
typeMapper: LanguageTypeMapper;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @description Mappers for all the types supported by OpenAPI 3.0.0
|
|
33
|
+
* @see https://swagger.io/docs/specification/data-models/data-types/
|
|
34
|
+
*/
|
|
35
|
+
export type LanguageTypeMapper = Record<TypeDataType, FormatType | string>;
|
|
36
|
+
export type FormatType = {
|
|
37
|
+
default: string;
|
|
38
|
+
[format: string]: string | undefined;
|
|
39
|
+
};
|
|
40
|
+
export type ReferenceType = 'local' | 'remote' | 'url';
|
|
41
|
+
export type ReferenceMeta = {
|
|
42
|
+
completeSource: string;
|
|
43
|
+
sourceFile: string;
|
|
44
|
+
path: string;
|
|
45
|
+
type: ReferenceType;
|
|
46
|
+
name: string;
|
|
47
|
+
};
|
|
48
|
+
export type ResolvedTypeReferenceData = ReferenceMeta & {
|
|
49
|
+
typeInfo: TypeInfo;
|
|
50
|
+
};
|
|
51
|
+
export type ResolvedGroupReferenceData = ReferenceMeta & {
|
|
52
|
+
groupedTypes: Types;
|
|
53
|
+
};
|
|
54
|
+
export type GeneratedReferencedType = ResolvedTypeReferenceData & {
|
|
55
|
+
templateData: GeneratedType<TemplateInput>;
|
|
56
|
+
};
|
|
57
|
+
export type SpecFileData = {
|
|
58
|
+
info: SpecInfo;
|
|
59
|
+
groupedTypes: GroupedTypes | null;
|
|
60
|
+
types: Types | null;
|
|
61
|
+
};
|
|
62
|
+
export type SpecInfo = {
|
|
63
|
+
version: string;
|
|
64
|
+
title: string;
|
|
65
|
+
};
|
|
66
|
+
type GroupName = string;
|
|
67
|
+
export type GroupedTypes = Record<GroupName, GroupTypesData>;
|
|
68
|
+
export type GroupTypesData = Types | GroupRef;
|
|
69
|
+
export type GroupRef = {
|
|
70
|
+
$ref: string;
|
|
71
|
+
};
|
|
72
|
+
type TypeName = string;
|
|
73
|
+
export type Types = Record<TypeName, TypeInfo>;
|
|
74
|
+
export type TypeInfo = TypeDescriptors & {
|
|
75
|
+
required: string[] | null;
|
|
76
|
+
optional: string[] | null;
|
|
77
|
+
type: TypeDataType | null;
|
|
78
|
+
format: string | null;
|
|
79
|
+
items: TypeInfo | null;
|
|
80
|
+
properties: TypeProperties | null;
|
|
81
|
+
$ref: string | null;
|
|
82
|
+
oneOf: TypeInfo[] | null;
|
|
83
|
+
allOf: TypeInfo[] | null;
|
|
84
|
+
enum: string[] | number[] | null;
|
|
85
|
+
additionalProperties: AdditionalProperties | null;
|
|
86
|
+
};
|
|
87
|
+
export type AdditionalProperties = KeyedAdditionalProperties | TypeInfo | boolean;
|
|
88
|
+
export type KeyedAdditionalProperties = {
|
|
89
|
+
keyType: AdditionalPropertiesKeyType;
|
|
90
|
+
valueType: TypeInfo;
|
|
91
|
+
};
|
|
92
|
+
export type AdditionalPropertiesKeyType = 'string' | 'number';
|
|
93
|
+
type PropertyName = string;
|
|
94
|
+
export type TypeProperties = Record<PropertyName, TypeInfo>;
|
|
95
|
+
export type TypeDataType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'unknown';
|
|
96
|
+
export type TypeDescriptors = {
|
|
97
|
+
summary: string | null;
|
|
98
|
+
example: string | number | null;
|
|
99
|
+
description: string | null;
|
|
100
|
+
};
|
|
101
|
+
export type ObjectTemplateInput = TypeDescriptors & {
|
|
102
|
+
typeName: string;
|
|
103
|
+
type: string;
|
|
104
|
+
properties: ObjectTemplateInputProperties;
|
|
105
|
+
additionalProperties?: AdditionalPropertiesTemplateInput;
|
|
106
|
+
};
|
|
107
|
+
export type ObjectTemplateInputProperties = Record<PropertyName, ObjectTemplateInputProperty>;
|
|
108
|
+
export type ObjectTemplateInputProperty = TypeDescriptors & {
|
|
109
|
+
type: string;
|
|
110
|
+
required: boolean;
|
|
111
|
+
referenced: boolean;
|
|
112
|
+
primitiveType: string;
|
|
113
|
+
composerType: string | null;
|
|
114
|
+
optional: boolean;
|
|
115
|
+
};
|
|
116
|
+
export type AdditionalPropertiesTemplateInput = {
|
|
117
|
+
keyType: string;
|
|
118
|
+
valueType: string;
|
|
119
|
+
};
|
|
120
|
+
export type ExporterModuleTemplateInput = {
|
|
121
|
+
modules: string[];
|
|
122
|
+
};
|
|
123
|
+
export type TypesFileTemplateInput = {
|
|
124
|
+
referencedTypes: string[];
|
|
125
|
+
primitives: string[];
|
|
126
|
+
typesContent: string;
|
|
127
|
+
writtenAt: string;
|
|
128
|
+
};
|
|
129
|
+
export type ReferencedModule = {
|
|
130
|
+
modulePath: string;
|
|
131
|
+
moduleRelativePath: string;
|
|
132
|
+
referencedTypes: string[];
|
|
133
|
+
};
|
|
134
|
+
export type EnumTemplateInput = TypeDescriptors & {
|
|
135
|
+
typeName: string;
|
|
136
|
+
type: string;
|
|
137
|
+
values: string[] | number[];
|
|
138
|
+
};
|
|
139
|
+
export type OneOfTemplateInput = TypeDescriptors & {
|
|
140
|
+
typeName: string;
|
|
141
|
+
type: string;
|
|
142
|
+
compositions: OneOfTemplateInputComposition[];
|
|
143
|
+
};
|
|
144
|
+
export type OneOfTemplateInputComposition = {
|
|
145
|
+
dataType?: TypeDataType | null;
|
|
146
|
+
templateInput?: TemplateInput;
|
|
147
|
+
source: 'inline' | 'referenced';
|
|
148
|
+
referencedType?: string;
|
|
149
|
+
content?: string;
|
|
150
|
+
};
|
|
151
|
+
export type AllOfTemplateInput = TypeDescriptors & {
|
|
152
|
+
typeName: string;
|
|
153
|
+
type: string;
|
|
154
|
+
compositions: AllOfTemplateInputComposition[];
|
|
155
|
+
};
|
|
156
|
+
export type AllOfTemplateInputComposition = {
|
|
157
|
+
dataType?: TypeDataType | null;
|
|
158
|
+
templateInput?: TemplateInput;
|
|
159
|
+
source: 'inline' | 'referenced';
|
|
160
|
+
referencedType?: string;
|
|
161
|
+
content?: string;
|
|
162
|
+
};
|
|
163
|
+
export type VariableTemplateInput = TypeDescriptors & {
|
|
164
|
+
typeName: string;
|
|
165
|
+
type: string;
|
|
166
|
+
composerType?: string;
|
|
167
|
+
};
|
|
168
|
+
export type TemplateInput = ObjectTemplateInput | EnumTemplateInput | OneOfTemplateInput | AllOfTemplateInput | VariableTemplateInput;
|
|
169
|
+
export type GenerationResult = {
|
|
170
|
+
groupedTypes: GroupedTypesOutput;
|
|
171
|
+
types: GeneratedTypes;
|
|
172
|
+
};
|
|
173
|
+
export type GeneratedType<TemplateType extends TemplateInput> = {
|
|
174
|
+
content: string;
|
|
175
|
+
references: Set<string>;
|
|
176
|
+
primitives: Set<string>;
|
|
177
|
+
templateInput: TemplateType;
|
|
178
|
+
};
|
|
179
|
+
export type GroupedTypesOutput = Record<GroupName, GeneratedTypes>;
|
|
180
|
+
export type GeneratedTypes = Record<TypeName, GeneratedType<TemplateInput>>;
|
|
181
|
+
export type TypeFilePath = {
|
|
182
|
+
modulePath: string;
|
|
183
|
+
filePath: string;
|
|
184
|
+
extension: string;
|
|
185
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class LanguageNotSupportedError extends Error {
|
|
2
|
+
constructor(language: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidParamError extends Error {
|
|
5
|
+
constructor(key: string, value: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class InvalidSpecFileError extends Error {
|
|
8
|
+
constructor(param: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class RuntimeError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class UnsupportedFeatureError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare function handleErrors(error: unknown): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function resolveFilePath(filePath: string, useCurrentDirectory?: boolean): string;
|
|
2
|
+
export declare function readFile(filePath: string, useCurrentWorkingDirectory?: boolean, caseSensitive?: boolean): Promise<string>;
|
|
3
|
+
export declare function createFolderWithBasePath(basePath: string, folderName: string): Promise<void>;
|
|
4
|
+
export declare function createFolder(folderPath: string): Promise<void>;
|
|
5
|
+
export declare function deleteFolder(folderPath: string): Promise<void>;
|
|
6
|
+
export declare function getCompleteFolderPath(folderName: string): Promise<string>;
|
|
7
|
+
export declare function getExpectedWrittenPath(basePath: string, fileName: string): Promise<string>;
|
|
8
|
+
export declare function writeFile(basePath: string, fileName: string, content: string): Promise<void>;
|
|
9
|
+
export declare function readYaml(filePath: string): Promise<unknown>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type JSONObject } from 'type-decoder';
|
|
2
|
+
export * from './file-system';
|
|
3
|
+
export * from './logger';
|
|
4
|
+
export declare function addValuesToMappedSet(map: Map<string, Set<string>>, key: string, values: string[]): void;
|
|
5
|
+
export declare function getOptionalKeys(object: unknown): string[];
|
|
6
|
+
export declare function getRequiredKeys(object: unknown): string[];
|
|
7
|
+
export declare function getReferencedTypes(object: unknown): string[];
|
|
8
|
+
export declare function getReferencedTypeModules(_referencedTypes: unknown, _writtenAt: string): unknown[];
|
|
9
|
+
export declare function toPascalCase(input: string): string;
|
|
10
|
+
export declare function toPascalCaseHelper(input: unknown): string | unknown;
|
|
11
|
+
export declare function refineJSONKey(input: unknown): unknown;
|
|
12
|
+
export declare function refineVariableName(input: unknown): unknown;
|
|
13
|
+
export declare function refineIndexKey(input: unknown): unknown;
|
|
14
|
+
export declare function registerTemplateHelpers(): void;
|
|
15
|
+
export declare function readNestedValue(json: unknown, keyPath: string[]): JSONObject;
|
|
16
|
+
export declare function generateRelativePath(fromPath: string, toPath: string): string;
|
|
17
|
+
export declare function stripPrefix(value: string, prefix: string): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function logError(header: string, message?: string | null): void;
|
|
2
|
+
export declare function logWarning(header: string, message: string): void;
|
|
3
|
+
export declare function logSuccess(header: string, message: string): void;
|
|
4
|
+
export declare function greeting(): void;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-crafter",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "A tool to generate types from a yaml schema for any language",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"type-crafter": "dist/index.js"
|
|
8
|
+
"type-crafter": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|