type-crafter 0.4.0 → 0.5.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/dist/generators/generic.d.ts +1 -1
- package/dist/generators/helpers.d.ts +6 -2
- package/dist/index.js +13501 -13417
- package/dist/runtime.d.ts +7 -1
- package/dist/templates/typescript/enum-syntax.hbs +1 -1
- package/dist/templates/typescript-with-decoders/enum-syntax.hbs +2 -2
- package/dist/types/decoders.d.ts +2 -1
- package/dist/types/index.d.ts +27 -21
- package/dist/utils/file-system.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/package.json +2 -2
package/dist/runtime.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Configuration, EnumTemplateInput, ExporterModuleTemplateInput, ObjectTemplateInput, OneOfTemplateInput, SpecFileData, TypeFilePath, TypesFileTemplateInput } from '$types';
|
|
1
|
+
import type { Configuration, EnumTemplateInput, ExporterModuleTemplateInput, GeneratedReferencedType, ObjectTemplateInput, OneOfTemplateInput, SpecFileData, TypeFilePath, TypesFileTemplateInput } from '$types';
|
|
2
2
|
declare function setConfig(newConfig: Configuration): void;
|
|
3
3
|
declare function getConfig(): Configuration;
|
|
4
4
|
declare function setSpecFileData(newSpecFileData: SpecFileData): void;
|
|
@@ -11,6 +11,9 @@ declare function getEnumTemplate(): HandlebarsTemplateDelegate<EnumTemplateInput
|
|
|
11
11
|
declare function getOneOfTemplate(): HandlebarsTemplateDelegate<OneOfTemplateInput>;
|
|
12
12
|
declare function setExpectedOutputFiles(newExpectedOutputFiles: Map<string, TypeFilePath>): void;
|
|
13
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;
|
|
14
17
|
declare const _default: {
|
|
15
18
|
getConfig: typeof getConfig;
|
|
16
19
|
setConfig: typeof setConfig;
|
|
@@ -24,5 +27,8 @@ declare const _default: {
|
|
|
24
27
|
getExpectedOutputFiles: typeof getExpectedOutputFiles;
|
|
25
28
|
compileTemplates: typeof compileTemplates;
|
|
26
29
|
getOneOfTemplate: typeof getOneOfTemplate;
|
|
30
|
+
getCachedReferencedTypes: typeof getCachedReferencedTypes;
|
|
31
|
+
getCachedReferenceType: typeof getCachedReferenceType;
|
|
32
|
+
cacheReferenceType: typeof cacheReferenceType;
|
|
27
33
|
};
|
|
28
34
|
export default _default;
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type {{typeName}} =
|
|
11
11
|
{{#each values}}
|
|
12
|
-
| {{#if (eq ../
|
|
12
|
+
| {{#if (eq ../type 'string') }}'{{/if}}{{{this}}}{{#if (eq ../type 'string')}}'{{/if}}
|
|
13
13
|
{{/each}};
|
|
14
14
|
|
|
15
15
|
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
16
16
|
switch (rawInput) {
|
|
17
17
|
{{#each values}}
|
|
18
|
-
case {{#if (eq ../
|
|
18
|
+
case {{#if (eq ../type 'string') }}'{{/if}}{{this}}{{#if (eq ../type 'string')}}'{{/if}}:
|
|
19
19
|
{{/each}}
|
|
20
20
|
return rawInput;
|
|
21
21
|
}
|
package/dist/types/decoders.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { EnumTemplateInput, GroupedTypesWriterMode, ObjectTemplateInputProperties, SpecFileData, TypesWriterMode } from '.';
|
|
1
|
+
import type { EnumTemplateInput, GroupedTypesWriterMode, ObjectTemplateInputProperties, SpecFileData, TypeInfo, TypesWriterMode } from '.';
|
|
2
2
|
export declare function decodeGroupedTypesWriterMode(rawInput: unknown): GroupedTypesWriterMode | null;
|
|
3
3
|
export declare function decodeTypesWriterMode(rawInput: unknown): TypesWriterMode | null;
|
|
4
4
|
export declare function decodeSpecFileData(rawInput: unknown): SpecFileData | null;
|
|
5
|
+
export declare function decodeTypeInfo(rawInput: unknown): TypeInfo | null;
|
|
5
6
|
export declare function decodeObjectTemplateInputProperties(rawInput: unknown): ObjectTemplateInputProperties | null;
|
|
6
7
|
export declare function decodeEnumTemplateInput(rawInput: unknown): EnumTemplateInput | null;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -36,6 +36,14 @@ export type FormatType = {
|
|
|
36
36
|
default: string;
|
|
37
37
|
[format: string]: string | undefined;
|
|
38
38
|
};
|
|
39
|
+
export type ResolveReferenceData = {
|
|
40
|
+
typeInfo: TypeInfo;
|
|
41
|
+
referenceName: string;
|
|
42
|
+
sourceFile?: string;
|
|
43
|
+
};
|
|
44
|
+
export type GeneratedReferencedType = ResolveReferenceData & {
|
|
45
|
+
templateData: GeneratedType<TemplateInput>;
|
|
46
|
+
};
|
|
39
47
|
export type SpecFileData = {
|
|
40
48
|
info: SpecInfo;
|
|
41
49
|
groupedTypes: GroupedTypes | null;
|
|
@@ -49,7 +57,7 @@ type GroupName = string;
|
|
|
49
57
|
export type GroupedTypes = Record<GroupName, Types>;
|
|
50
58
|
type TypeName = string;
|
|
51
59
|
export type Types = Record<TypeName, TypeInfo>;
|
|
52
|
-
export type TypeInfo = {
|
|
60
|
+
export type TypeInfo = TypeDescriptors & {
|
|
53
61
|
required: string[] | null;
|
|
54
62
|
type: TypeDataType | null;
|
|
55
63
|
format: string | null;
|
|
@@ -58,27 +66,27 @@ export type TypeInfo = {
|
|
|
58
66
|
$ref: string | null;
|
|
59
67
|
oneOf: TypeInfo[] | null;
|
|
60
68
|
enum: string[] | number[] | null;
|
|
61
|
-
description: string | null;
|
|
62
|
-
example: string | number | null;
|
|
63
69
|
};
|
|
64
70
|
type PropertyName = string;
|
|
65
71
|
export type TypeProperties = Record<PropertyName, TypeInfo>;
|
|
66
72
|
export type TypeDataType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'unknown';
|
|
67
|
-
export type
|
|
68
|
-
|
|
73
|
+
export type TypeDescriptors = {
|
|
74
|
+
summary: string | null;
|
|
69
75
|
example: string | number | null;
|
|
70
76
|
description: string | null;
|
|
77
|
+
};
|
|
78
|
+
export type ObjectTemplateInput = TypeDescriptors & {
|
|
79
|
+
typeName: string;
|
|
80
|
+
type: string;
|
|
71
81
|
properties: ObjectTemplateInputProperties;
|
|
72
82
|
};
|
|
73
83
|
export type ObjectTemplateInputProperties = Record<PropertyName, ObjectTemplateInputProperty>;
|
|
74
|
-
export type ObjectTemplateInputProperty = {
|
|
84
|
+
export type ObjectTemplateInputProperty = TypeDescriptors & {
|
|
75
85
|
type: string;
|
|
76
86
|
required: boolean;
|
|
77
87
|
referenced: boolean;
|
|
78
88
|
primitiveType: string;
|
|
79
89
|
composerType: string | null;
|
|
80
|
-
example: string | number | null;
|
|
81
|
-
description: string | null;
|
|
82
90
|
};
|
|
83
91
|
export type ExporterModuleTemplateInput = {
|
|
84
92
|
modules: string[];
|
|
@@ -94,15 +102,14 @@ export type ReferencedModule = {
|
|
|
94
102
|
moduleRelativePath: string;
|
|
95
103
|
referencedTypes: string[];
|
|
96
104
|
};
|
|
97
|
-
export type EnumTemplateInput = {
|
|
105
|
+
export type EnumTemplateInput = TypeDescriptors & {
|
|
98
106
|
typeName: string;
|
|
99
|
-
|
|
107
|
+
type: string;
|
|
100
108
|
values: string[] | number[];
|
|
101
|
-
example: string | number | null;
|
|
102
|
-
description: string | null;
|
|
103
109
|
};
|
|
104
|
-
export type OneOfTemplateInput = {
|
|
110
|
+
export type OneOfTemplateInput = TypeDescriptors & {
|
|
105
111
|
typeName: string;
|
|
112
|
+
type: string;
|
|
106
113
|
compositions: OneOfTemplateInputComposition[];
|
|
107
114
|
};
|
|
108
115
|
export type OneOfTemplateInputComposition = {
|
|
@@ -112,25 +119,24 @@ export type OneOfTemplateInputComposition = {
|
|
|
112
119
|
referencedType?: string;
|
|
113
120
|
content?: string;
|
|
114
121
|
};
|
|
115
|
-
export type VariableTemplateInput = {
|
|
122
|
+
export type VariableTemplateInput = TypeDescriptors & {
|
|
116
123
|
typeName: string;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
itemType?: string;
|
|
124
|
+
type: string;
|
|
125
|
+
composerType?: string;
|
|
120
126
|
};
|
|
121
|
-
export type TemplateInput = ObjectTemplateInput | EnumTemplateInput | VariableTemplateInput;
|
|
127
|
+
export type TemplateInput = ObjectTemplateInput | EnumTemplateInput | OneOfTemplateInput | VariableTemplateInput;
|
|
122
128
|
export type GenerationResult = {
|
|
123
129
|
groupedTypes: GroupedTypesOutput;
|
|
124
130
|
types: GeneratedTypes;
|
|
125
131
|
};
|
|
126
|
-
export type GeneratedType = {
|
|
132
|
+
export type GeneratedType<TemplateType extends TemplateInput> = {
|
|
127
133
|
content: string;
|
|
128
134
|
references: Set<string>;
|
|
129
135
|
primitives: Set<string>;
|
|
130
|
-
templateInput
|
|
136
|
+
templateInput: TemplateType;
|
|
131
137
|
};
|
|
132
138
|
export type GroupedTypesOutput = Record<GroupName, GeneratedTypes>;
|
|
133
|
-
export type GeneratedTypes = Record<TypeName, GeneratedType
|
|
139
|
+
export type GeneratedTypes = Record<TypeName, GeneratedType<TemplateInput>>;
|
|
134
140
|
export type TypeFilePath = {
|
|
135
141
|
modulePath: string;
|
|
136
142
|
filePath: string;
|
|
@@ -6,3 +6,4 @@ export declare function deleteFolder(folderPath: string): Promise<void>;
|
|
|
6
6
|
export declare function getCompleteFolderPath(folderName: string): Promise<string>;
|
|
7
7
|
export declare function getExpectedWrittenPath(basePath: string, fileName: string): Promise<string>;
|
|
8
8
|
export declare function writeFile(basePath: string, fileName: string, content: string): Promise<void>;
|
|
9
|
+
export declare function readYaml(filePath: string): Promise<unknown>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export declare function getReferencedTypeModules(_referencedTypes: unknown, _wri
|
|
|
9
9
|
export declare function toPascalCase(input: string): string;
|
|
10
10
|
export declare function toPascalCaseHelper(input: unknown): string | unknown;
|
|
11
11
|
export declare function registerTemplateHelpers(): void;
|
|
12
|
-
export declare function readNestedValue(json:
|
|
12
|
+
export declare function readNestedValue(json: unknown, keyPath: string[]): JSONObject;
|
|
13
13
|
export declare function generateRelativePath(fromPath: string, toPath: string): string;
|
|
14
14
|
export declare function stripPrefix(value: string, prefix: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-crafter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"rollup": "^4.5.1",
|
|
69
69
|
"rollup-plugin-copy": "^3.5.0",
|
|
70
70
|
"tslib": "^2.6.2",
|
|
71
|
-
"type-decoder": "^
|
|
71
|
+
"type-decoder": "^2.0.1",
|
|
72
72
|
"typescript": "^5.2.2",
|
|
73
73
|
"yaml": "^2.3.2"
|
|
74
74
|
}
|