type-crafter 0.9.3 → 0.9.5

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 CHANGED
@@ -20513,7 +20513,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
20513
20513
  }
20514
20514
  }
20515
20515
  greeting();
20516
- const program = new Command().version('0.9.2');
20516
+ const program = new Command().version('0.9.5');
20517
20517
  program
20518
20518
  .command('generate')
20519
20519
  .description('Generate types for your language from a type spec file')
@@ -39,7 +39,7 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
39
39
  if (isJSON(rawInput)) {
40
40
  {{#each properties}}
41
41
  const decoded{{variableName @key}} = {{#if this.referenced ~}}
42
- decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}]);
42
+ {{#if this.optional}}_{{/if}}decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}]);
43
43
  {{~else~}}
44
44
  {{~#if (eq this.primitiveType 'array')~}}
45
45
  decodeArray(rawInput[{{{indexKey @key}}}], decode{{{toPascalCase this.composerType}}})
@@ -71,3 +71,41 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
71
71
  }
72
72
  return null;
73
73
  }
74
+
75
+
76
+ export function _decode{{typeName}}(rawInput: unknown): {{typeName}} | undefined {
77
+ if (isJSON(rawInput)) {
78
+ {{#each properties}}
79
+ const decoded{{variableName @key}} = {{#if this.referenced ~}}
80
+ {{#if this.optional}}_{{/if}}decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}]);
81
+ {{~else~}}
82
+ {{~#if (eq this.primitiveType 'array')~}}
83
+ decodeArray(rawInput[{{{indexKey @key}}}], decode{{{toPascalCase this.composerType}}})
84
+ {{~else~}}
85
+ {{#if this.optional}}_{{/if}}decode{{{toPascalCase this.type}}}(rawInput[{{{indexKey @key}}}])
86
+ {{~/if~}};
87
+ {{~/if}}
88
+
89
+ {{/each}}
90
+
91
+ {{#if (areRequiredKeysPresent properties)}}
92
+ if (
93
+ {{#each (getRequiredKeys properties)}}
94
+ decoded{{toPascalCase this}} === null{{#unless @last}} ||{{/unless}}
95
+ {{/each}}
96
+ ) {
97
+ return null;
98
+ }
99
+ {{/if}}
100
+
101
+ return {
102
+ {{#if additionalProperties}}
103
+ ...rawInput,
104
+ {{/if}}
105
+ {{#each properties}}
106
+ {{{jsonKey @key}}}: decoded{{{variableName @key}}}{{#unless @last}},{{/unless}}
107
+ {{/each}}
108
+ };
109
+ }
110
+ return;
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-crafter",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
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",