type-crafter 0.15.0 → 0.16.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/index.js +7 -4
- package/dist/templates/typescript-with-decoders/allOf-syntax.hbs +2 -0
- package/dist/templates/typescript-with-decoders/enum-syntax.hbs +4 -0
- package/dist/templates/typescript-with-decoders/oneOf-syntax.hbs +6 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21707,7 +21707,8 @@ function generateEnumType(typeName, typeInfo) {
|
|
|
21707
21707
|
values: typeInfo.enum,
|
|
21708
21708
|
example: typeInfo.example,
|
|
21709
21709
|
description: typeInfo.description,
|
|
21710
|
-
summary: typeInfo.summary
|
|
21710
|
+
summary: typeInfo.summary,
|
|
21711
|
+
customAttributes: typeInfo.customAttributes ?? null
|
|
21711
21712
|
};
|
|
21712
21713
|
const result = {
|
|
21713
21714
|
content: '',
|
|
@@ -21841,7 +21842,8 @@ async function generateOneOfTypes(typeName, typeInfo, parentTypes) {
|
|
|
21841
21842
|
compositions: [],
|
|
21842
21843
|
description: typeInfo.description,
|
|
21843
21844
|
example: typeInfo.example,
|
|
21844
|
-
summary: typeInfo.summary
|
|
21845
|
+
summary: typeInfo.summary,
|
|
21846
|
+
customAttributes: typeInfo.customAttributes ?? null
|
|
21845
21847
|
};
|
|
21846
21848
|
const result = {
|
|
21847
21849
|
content: '',
|
|
@@ -21893,7 +21895,8 @@ async function generateAllOfTypes(typeName, typeInfo, parentTypes) {
|
|
|
21893
21895
|
compositions: [],
|
|
21894
21896
|
description: typeInfo.description,
|
|
21895
21897
|
example: typeInfo.example,
|
|
21896
|
-
summary: typeInfo.summary
|
|
21898
|
+
summary: typeInfo.summary,
|
|
21899
|
+
customAttributes: typeInfo.customAttributes ?? null
|
|
21897
21900
|
};
|
|
21898
21901
|
const result = {
|
|
21899
21902
|
content: '',
|
|
@@ -22544,7 +22547,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
22544
22547
|
}
|
|
22545
22548
|
}
|
|
22546
22549
|
greeting();
|
|
22547
|
-
const program = new Command().version('0.
|
|
22550
|
+
const program = new Command().version('0.16.0');
|
|
22548
22551
|
program
|
|
22549
22552
|
.command('generate')
|
|
22550
22553
|
.description('Generate types for your language from a type spec file')
|
|
@@ -18,6 +18,7 @@ export type {{typeName}} =
|
|
|
18
18
|
{{/if}}
|
|
19
19
|
{{/each}}
|
|
20
20
|
|
|
21
|
+
{{#unless customAttributes.skipDecoderGeneration}}
|
|
21
22
|
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
22
23
|
{{#each compositions}}
|
|
23
24
|
{{#if (eq this.source 'referenced')}}
|
|
@@ -40,3 +41,4 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
|
40
41
|
}
|
|
41
42
|
return null;
|
|
42
43
|
}
|
|
44
|
+
{{/unless}}
|
|
@@ -12,6 +12,7 @@ export type {{typeName}} =
|
|
|
12
12
|
| {{#if (eq ../type 'string') }}'{{/if}}{{{this}}}{{#if (eq ../type 'string')}}'{{/if}}
|
|
13
13
|
{{/each}};
|
|
14
14
|
|
|
15
|
+
{{#unless customAttributes.skipDecoderGeneration}}
|
|
15
16
|
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
16
17
|
switch (rawInput) {
|
|
17
18
|
{{#each values}}
|
|
@@ -21,7 +22,9 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
|
21
22
|
}
|
|
22
23
|
return null;
|
|
23
24
|
}
|
|
25
|
+
{{/unless}}
|
|
24
26
|
|
|
27
|
+
{{#if customAttributes.generateOptionalDecoder}}
|
|
25
28
|
export function _decode{{typeName}}(rawInput: unknown): {{typeName}} | undefined {
|
|
26
29
|
switch (rawInput) {
|
|
27
30
|
{{#each values}}
|
|
@@ -31,3 +34,4 @@ export function _decode{{typeName}}(rawInput: unknown): {{typeName}} | undefined
|
|
|
31
34
|
}
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
37
|
+
{{/if}}
|
|
@@ -19,6 +19,7 @@ export type {{typeName}} =
|
|
|
19
19
|
{{/if}}
|
|
20
20
|
{{/each}};
|
|
21
21
|
|
|
22
|
+
{{#unless customAttributes.skipDecoderGeneration}}
|
|
22
23
|
export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
23
24
|
const result: {{typeName}} | null =
|
|
24
25
|
{{#each compositions}}
|
|
@@ -36,6 +37,7 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
|
|
|
36
37
|
{{/each}};
|
|
37
38
|
return result;
|
|
38
39
|
}
|
|
40
|
+
{{/unless}}
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
{{#each compositions}}
|
|
@@ -50,6 +52,7 @@ export class C{{../typeName}}{{referencedType}} {
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
{{#unless ../customAttributes.skipDecoderGeneration}}
|
|
53
56
|
export function decodeC{{../typeName}}{{referencedType}}(rawInput: unknown): C{{../typeName}}{{referencedType}} | null {
|
|
54
57
|
const result = decode{{referencedType}}(rawInput);
|
|
55
58
|
if (result === null) {
|
|
@@ -57,6 +60,7 @@ export function decodeC{{../typeName}}{{referencedType}}(rawInput: unknown): C{{
|
|
|
57
60
|
}
|
|
58
61
|
return new C{{../typeName}}{{referencedType}}(result);
|
|
59
62
|
}
|
|
63
|
+
{{/unless}}
|
|
60
64
|
|
|
61
65
|
{{else if (eq this.dataType 'object')}}
|
|
62
66
|
|
|
@@ -69,6 +73,7 @@ export class C{{../typeName}}{{this.templateInput.typeName}} {
|
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
{{#unless ../customAttributes.skipDecoderGeneration}}
|
|
72
77
|
export function decodeC{{this.templateInput.typeName}}(rawInput: unknown) {
|
|
73
78
|
const result = decode{{this.templateInput.typeName}}(rawInput);
|
|
74
79
|
if (result === null) {
|
|
@@ -76,6 +81,7 @@ export function decodeC{{this.templateInput.typeName}}(rawInput: unknown) {
|
|
|
76
81
|
}
|
|
77
82
|
return new C{{../typeName}}{{this.templateInput.typeName}}(result);
|
|
78
83
|
}
|
|
84
|
+
{{/unless}}
|
|
79
85
|
|
|
80
86
|
{{/if}}
|
|
81
87
|
{{/each}}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -165,11 +165,13 @@ export type EnumTemplateInput = TypeDescriptors & {
|
|
|
165
165
|
typeName: string;
|
|
166
166
|
type: string;
|
|
167
167
|
values: string[] | number[];
|
|
168
|
+
customAttributes?: Record<string, unknown> | null;
|
|
168
169
|
};
|
|
169
170
|
export type OneOfTemplateInput = TypeDescriptors & {
|
|
170
171
|
typeName: string;
|
|
171
172
|
type: string;
|
|
172
173
|
compositions: OneOfTemplateInputComposition[];
|
|
174
|
+
customAttributes?: Record<string, unknown> | null;
|
|
173
175
|
};
|
|
174
176
|
export type OneOfTemplateInputComposition = {
|
|
175
177
|
dataType?: TypeDataType | null;
|
|
@@ -182,6 +184,7 @@ export type AllOfTemplateInput = TypeDescriptors & {
|
|
|
182
184
|
typeName: string;
|
|
183
185
|
type: string;
|
|
184
186
|
compositions: AllOfTemplateInputComposition[];
|
|
187
|
+
customAttributes?: Record<string, unknown> | null;
|
|
185
188
|
};
|
|
186
189
|
export type AllOfTemplateInputComposition = {
|
|
187
190
|
dataType?: TypeDataType | null;
|