type-crafter 0.17.0 → 0.19.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 CHANGED
@@ -21560,7 +21560,8 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
21560
21560
  valuePrimitiveType: 'unknown',
21561
21561
  valueComposerType: null
21562
21562
  },
21563
- primitives: unknownType.primitives
21563
+ primitives: unknownType.primitives,
21564
+ references: new Set()
21564
21565
  };
21565
21566
  }
21566
21567
  else if (valueIsKeyedAdditionalProperties(typeInfo.additionalProperties)) {
@@ -21584,7 +21585,10 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
21584
21585
  ? (generatedValueType.templateInput.arrayNestingDepth ?? 0)
21585
21586
  : 0
21586
21587
  },
21587
- primitives: generatedValueType.primitives
21588
+ primitives: generatedValueType.primitives,
21589
+ references: isReferenced
21590
+ ? new Set([generatedValueType.templateInput.typeName])
21591
+ : generatedValueType.references
21588
21592
  };
21589
21593
  }
21590
21594
  else if (valueIsTypeInfo(typeInfo.additionalProperties)) {
@@ -21605,7 +21609,10 @@ async function generateAdditionalPropertiesType(typeName, typeInfo, parentTypes)
21605
21609
  ? (generatedValueType.templateInput.arrayNestingDepth ?? 0)
21606
21610
  : 0
21607
21611
  },
21608
- primitives: generatedValueType.primitives
21612
+ primitives: generatedValueType.primitives,
21613
+ references: isReferenced
21614
+ ? new Set([generatedValueType.templateInput.typeName])
21615
+ : generatedValueType.references
21609
21616
  };
21610
21617
  }
21611
21618
  return null;
@@ -21704,6 +21711,7 @@ async function generateObjectType(typeName, typeInfo, parentTypes) {
21704
21711
  if (additionalPropertiesResult !== null) {
21705
21712
  templateInput.additionalProperties = additionalPropertiesResult.templateInput;
21706
21713
  primitives.push(...additionalPropertiesResult.primitives);
21714
+ references.push(...additionalPropertiesResult.references);
21707
21715
  }
21708
21716
  const result = {
21709
21717
  content: Runtime.getObjectTemplate()(templateInput) +
@@ -22199,6 +22207,7 @@ async function writeExporterModules(files, folder) {
22199
22207
  const exporterModuleContent = Runtime.getExporterModuleTemplate()({
22200
22208
  modules: [...files]
22201
22209
  .map((file) => file.replace(Runtime.getConfig().output.fileExtension, ''))
22210
+ .filter((name) => name !== Runtime.getConfig().language.exporterModuleName)
22202
22211
  .sort()
22203
22212
  });
22204
22213
  const config = Runtime.getConfig();
@@ -22573,7 +22582,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
22573
22582
  }
22574
22583
  }
22575
22584
  greeting();
22576
- const program = new Command().version('0.17.0');
22585
+ const program = new Command().version('0.19.0');
22577
22586
  program
22578
22587
  .command('generate')
22579
22588
  .description('Generate types for your language from a type spec file')
@@ -2,6 +2,9 @@
2
2
  /// {{{description}}}
3
3
  {{/if}}
4
4
  #[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
5
+ {{#each customAttributes.[x-attributes]}}
6
+ #[{{{this}}}]
7
+ {{/each}}
5
8
  pub struct {{typeName}} {
6
9
  {{#each compositions}}
7
10
  {{#if (eq this.source 'referenced')}}
@@ -5,6 +5,9 @@
5
5
  /// Example: {{{example}}}
6
6
  {{/if}}
7
7
  #[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
8
+ {{#each customAttributes.[x-attributes]}}
9
+ #[{{{this}}}]
10
+ {{/each}}
8
11
  pub enum {{typeName}} {
9
12
  {{#each values}}
10
13
  {{#if (eq ../type 'string')}}
@@ -5,6 +5,9 @@
5
5
  /// Example: {{{example}}}
6
6
  {{/if}}
7
7
  #[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
8
+ {{#each customAttributes.[x-attributes]}}
9
+ #[{{{this}}}]
10
+ {{/each}}
8
11
  {{#if customAttributes.renameAll}}
9
12
  #[serde(rename_all = "{{{customAttributes.renameAll}}}")]
10
13
  {{/if}}
@@ -2,6 +2,9 @@
2
2
  /// {{{description}}}
3
3
  {{/if}}
4
4
  #[derive({{{appendUnique "Debug, Clone, Serialize, Deserialize" customAttributes.[x-derive]}}})]
5
+ {{#each customAttributes.[x-attributes]}}
6
+ #[{{{this}}}]
7
+ {{/each}}
5
8
  #[serde(untagged)]
6
9
  pub enum {{typeName}} {
7
10
  {{#each compositions}}
@@ -5,14 +5,14 @@
5
5
  decode{{{toPascalCase composerType}}}
6
6
  {{~/if~}}
7
7
  {{/inline}}
8
+ {{#*inline "composerClassName"}}C{{#if (eq prefix false)}}{{else if (eq prefix "")}}{{else if prefix}}{{prefix}}{{else}}{{typeName}}{{/if}}{{member}}{{/inline}}
8
9
  export type {{typeName}} =
9
10
  {{#each compositions}}
10
- | {{#if (eq this.source 'referenced')}}C{{../typeName}}{{referencedType}}
11
+ | {{#if (eq this.source 'referenced')}}{{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}}
11
12
  {{else if (eq this.source 'inline')}}
12
13
  {{#if this.templateInput.values}}
13
14
  {{this.templateInput.typeName}}
14
- {{else if (eq this.dataType 'object')}}
15
- C{{typeName}}{{this.templateInput.typeName}}
15
+ {{else if (eq this.dataType 'object')}}{{> composerClassName typeName=../typeName member=this.templateInput.typeName prefix=../customAttributes.[x-class-name-prefix]}}
16
16
  {{else}}
17
17
  {{this.templateInput.type}}
18
18
  {{/if}}
@@ -24,7 +24,7 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
24
24
  const result: {{typeName}} | null =
25
25
  {{#each compositions}}
26
26
  {{#if (eq this.source 'referenced')}}
27
- decodeC{{../typeName}}{{referencedType}}(rawInput)
27
+ decode{{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}}(rawInput)
28
28
  {{else if (eq this.dataType 'object')}}
29
29
  decodeC{{this.templateInput.typeName}}(rawInput)
30
30
  {{else if (eq this.dataType 'array')}}
@@ -45,7 +45,7 @@ export function decode{{typeName}}(rawInput: unknown): {{typeName}} | null {
45
45
  {{#if this.templateInput.values}}
46
46
  {{{this.content}}}
47
47
  {{else if (eq this.source 'referenced')}}
48
- export class C{{../typeName}}{{referencedType}} {
48
+ export class {{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}} {
49
49
  data: {{referencedType}};
50
50
  constructor(data: {{referencedType}}) {
51
51
  this.data = data;
@@ -53,12 +53,12 @@ export class C{{../typeName}}{{referencedType}} {
53
53
  }
54
54
 
55
55
  {{#unless ../customAttributes.skipDecoderGeneration}}
56
- export function decodeC{{../typeName}}{{referencedType}}(rawInput: unknown): C{{../typeName}}{{referencedType}} | null {
56
+ export function decode{{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}}(rawInput: unknown): {{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}} | null {
57
57
  const result = decode{{referencedType}}(rawInput);
58
58
  if (result === null) {
59
59
  return null;
60
60
  }
61
- return new C{{../typeName}}{{referencedType}}(result);
61
+ return new {{> composerClassName typeName=../typeName member=this.referencedType prefix=../customAttributes.[x-class-name-prefix]}}(result);
62
62
  }
63
63
  {{/unless}}
64
64
 
@@ -66,7 +66,7 @@ export function decodeC{{../typeName}}{{referencedType}}(rawInput: unknown): C{{
66
66
 
67
67
  {{{this.content}}}
68
68
 
69
- export class C{{../typeName}}{{this.templateInput.typeName}} {
69
+ export class {{> composerClassName typeName=../typeName member=this.templateInput.typeName prefix=../customAttributes.[x-class-name-prefix]}} {
70
70
  data: {{this.templateInput.typeName}};
71
71
  constructor(data: {{this.templateInput.typeName}}) {
72
72
  this.data = data;
@@ -79,7 +79,7 @@ export function decodeC{{this.templateInput.typeName}}(rawInput: unknown) {
79
79
  if (result === null) {
80
80
  return null;
81
81
  }
82
- return new C{{../typeName}}{{this.templateInput.typeName}}(result);
82
+ return new {{> composerClassName typeName=../typeName member=this.templateInput.typeName prefix=../customAttributes.[x-class-name-prefix]}}(result);
83
83
  }
84
84
  {{/unless}}
85
85
 
@@ -144,6 +144,7 @@ export type AdditionalPropertiesTemplateInput = {
144
144
  export type AdditionalPropertiesGenerationResult = {
145
145
  templateInput: AdditionalPropertiesTemplateInput;
146
146
  primitives: Set<string>;
147
+ references: Set<string>;
147
148
  };
148
149
  export type ExporterModuleTemplateInput = {
149
150
  modules: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-crafter",
3
- "version": "0.17.0",
3
+ "version": "0.19.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",