@vaadin/hilla-generator-plugin-backbone 24.5.0-alpha13 → 24.5.0-alpha15

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.
@@ -1 +1 @@
1
- {"version":3,"file":"EntityProcessor.d.ts","sourceRoot":"","sources":["src/EntityProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,wCAAwC,CAAC;AAQhD,OAAW,EAGT,KAAK,UAAU,EAGhB,MAAM,YAAY,CAAC;AAGpB,qBAAa,eAAe;;gBASd,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAiB1D,OAAO,IAAI,UAAU;CA+GtB"}
1
+ {"version":3,"file":"EntityProcessor.d.ts","sourceRoot":"","sources":["src/EntityProcessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,wCAAwC,CAAC;AAQhD,OAAW,EAGT,KAAK,UAAU,EAGhB,MAAM,YAAY,CAAC;AAIpB,qBAAa,eAAe;;gBASd,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAiB1D,OAAO,IAAI,UAAU;CA4HtB"}
@@ -20,6 +20,7 @@ import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.
20
20
  import ts, {
21
21
  } from "typescript";
22
22
  import TypeSchemaProcessor from "./TypeSchemaProcessor.js";
23
+ import { findTypeParameters } from "./utils.js";
23
24
  class EntityProcessor {
24
25
  #component;
25
26
  #dependencies;
@@ -63,7 +64,7 @@ class EntityProcessor {
63
64
  return ts.factory.createInterfaceDeclaration(
64
65
  void 0,
65
66
  this.#id,
66
- void 0,
67
+ EntityProcessor.#processTypeParameters(schema),
67
68
  void 0,
68
69
  this.#processTypeElements(schema)
69
70
  );
@@ -97,7 +98,7 @@ class EntityProcessor {
97
98
  declaration,
98
99
  declaration.modifiers,
99
100
  declaration.name,
100
- void 0,
101
+ declaration.typeParameters,
101
102
  [
102
103
  ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
103
104
  ts.factory.createExpressionWithTypeArguments(identifier, void 0)
@@ -125,6 +126,16 @@ class EntityProcessor {
125
126
  );
126
127
  });
127
128
  }
129
+ static #processTypeParameters(schema) {
130
+ return findTypeParameters(schema)?.map(String).map(
131
+ (name) => ts.factory.createTypeParameterDeclaration(
132
+ void 0,
133
+ name,
134
+ void 0,
135
+ ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)
136
+ )
137
+ );
138
+ }
128
139
  }
129
140
  export {
130
141
  EntityProcessor
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/EntityProcessor.ts"],
4
- "sourcesContent": ["import { dirname } from 'path/posix';\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n type EnumSchema,\n type ReferenceSchema,\n type Schema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEmptyObject,\n isEnumSchema,\n isNullableSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport {\n convertFullyQualifiedNameToRelativePath,\n simplifyFullyQualifiedName,\n} from '@vaadin/hilla-generator-core/utils.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, {\n type Identifier,\n type InterfaceDeclaration,\n type SourceFile,\n type Statement,\n type TypeElement,\n} from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\n\nexport class EntityProcessor {\n readonly #component: Schema;\n readonly #dependencies;\n readonly #fullyQualifiedName: string;\n readonly #name: string;\n readonly #outputPathManager = new PathManager({ extension: 'ts' });\n readonly #owner: Plugin;\n readonly #path: string;\n\n constructor(name: string, component: Schema, owner: Plugin) {\n this.#component = component;\n this.#owner = owner;\n this.#fullyQualifiedName = name;\n this.#name = simplifyFullyQualifiedName(name);\n this.#path = convertFullyQualifiedNameToRelativePath(name);\n this.#dependencies = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(this.#path) }));\n }\n\n get #id(): Identifier {\n const id = ts.factory.createIdentifier(this.#name);\n\n this.#dependencies.exports.default.set(id);\n\n return id;\n }\n\n process(): SourceFile {\n this.#owner.logger.debug(`Processing entity: ${this.#name}`);\n\n const declaration = isEnumSchema(this.#component)\n ? this.#processEnum(this.#component)\n : this.#processExtendedClass(this.#component);\n\n const statements = declaration ? [declaration] : [];\n\n const { exports, imports } = this.#dependencies;\n\n return createSourceFile(\n [...imports.toCode(), ...statements, ...exports.toCode()],\n this.#outputPathManager.createRelativePath(this.#path),\n );\n }\n\n #processClass(schema: Schema): InterfaceDeclaration | undefined {\n const { logger } = this.#owner;\n\n if (!isObjectSchema(schema)) {\n logger.debug(schema, `Component is not an object: '${this.#fullyQualifiedName}'`);\n return undefined;\n }\n\n if (isEmptyObject(schema)) {\n logger.debug(`Component has no properties:' ${this.#fullyQualifiedName}'`);\n }\n\n return ts.factory.createInterfaceDeclaration(\n undefined,\n this.#id,\n undefined,\n undefined,\n this.#processTypeElements(schema as ObjectSchema),\n );\n }\n\n #processEnum({ enum: members }: EnumSchema): Statement {\n return ts.factory.createEnumDeclaration(\n undefined,\n this.#id,\n members.map((member) => ts.factory.createEnumMember(member, ts.factory.createStringLiteral(member))),\n );\n }\n\n #processExtendedClass(schema: Schema): Statement | undefined {\n const { logger } = this.#owner;\n\n if (isComposedSchema(schema)) {\n const decomposed = decomposeSchema(schema);\n\n if (decomposed.length > 2) {\n logger.debug(\n schema,\n `Schema for '${this.#fullyQualifiedName}' has more than two components. This plugin will ignore it.`,\n );\n return undefined;\n }\n\n const [parent, child] = decomposed;\n\n if (!isReferenceSchema(parent)) {\n logger.debug(parent, 'Only reference schema allowed for parent class');\n return undefined;\n }\n\n const declaration = this.#processClass(child);\n const identifier = this.#processParentClass(parent);\n\n return (\n declaration &&\n ts.factory.updateInterfaceDeclaration(\n declaration,\n declaration.modifiers,\n declaration.name,\n undefined,\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(identifier, undefined),\n ]),\n ],\n declaration.members,\n )\n );\n }\n\n return this.#processClass(schema);\n }\n\n #processParentClass(schema: ReferenceSchema): Identifier {\n const { imports, paths } = this.#dependencies;\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n\n return imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n }\n\n #processTypeElements({ properties }: ObjectSchema): readonly TypeElement[] {\n return Object.entries(properties ?? {}).map(([name, schema]) => {\n const [type] = new TypeSchemaProcessor(schema, this.#dependencies).process();\n\n return ts.factory.createPropertySignature(\n undefined,\n name,\n isNullableSchema(schema) ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,\n type,\n );\n });\n }\n}\n"],
5
- "mappings": "AAAA,SAAS,eAAe;AAExB;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO;AAAA,OAMA;AACP,OAAO,yBAAyB;AAEzB,MAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB,IAAI,YAAY,EAAE,WAAW,KAAK,CAAC;AAAA,EACxD;AAAA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AAQ,QAAQ,IAAI,MAAM,WAAW,IAAI;AAAA,EACzF;AAAA,EAEA,qBAAqB,EAAE,WAAW,GAAyC;AACzE,WAAO,OAAO,QAAQ,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM;AAC9D,YAAM,CAAC,IAAI,IAAI,IAAI,oBAAoB,QAAQ,KAAK,aAAa,EAAE,QAAQ;AAE3E,aAAO,GAAG,QAAQ;AAAA,QAChB;AAAA,QACA;AAAA,QACA,iBAAiB,MAAM,IAAI,GAAG,QAAQ,YAAY,GAAG,WAAW,aAAa,IAAI;AAAA,QACjF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
4
+ "sourcesContent": ["import { dirname } from 'path/posix';\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport {\n type EnumSchema,\n type ReferenceSchema,\n type Schema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEmptyObject,\n isEnumSchema,\n isNullableSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport {\n convertFullyQualifiedNameToRelativePath,\n simplifyFullyQualifiedName,\n} from '@vaadin/hilla-generator-core/utils.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, {\n type Identifier,\n type InterfaceDeclaration,\n type SourceFile,\n type Statement,\n type TypeElement,\n} from 'typescript';\nimport TypeSchemaProcessor from './TypeSchemaProcessor.js';\nimport { findTypeParameters } from './utils.js';\n\nexport class EntityProcessor {\n readonly #component: Schema;\n readonly #dependencies;\n readonly #fullyQualifiedName: string;\n readonly #name: string;\n readonly #outputPathManager = new PathManager({ extension: 'ts' });\n readonly #owner: Plugin;\n readonly #path: string;\n\n constructor(name: string, component: Schema, owner: Plugin) {\n this.#component = component;\n this.#owner = owner;\n this.#fullyQualifiedName = name;\n this.#name = simplifyFullyQualifiedName(name);\n this.#path = convertFullyQualifiedNameToRelativePath(name);\n this.#dependencies = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(this.#path) }));\n }\n\n get #id(): Identifier {\n const id = ts.factory.createIdentifier(this.#name);\n\n this.#dependencies.exports.default.set(id);\n\n return id;\n }\n\n process(): SourceFile {\n this.#owner.logger.debug(`Processing entity: ${this.#name}`);\n\n const declaration = isEnumSchema(this.#component)\n ? this.#processEnum(this.#component)\n : this.#processExtendedClass(this.#component);\n\n const statements = declaration ? [declaration] : [];\n\n const { exports, imports } = this.#dependencies;\n\n return createSourceFile(\n [...imports.toCode(), ...statements, ...exports.toCode()],\n this.#outputPathManager.createRelativePath(this.#path),\n );\n }\n\n #processClass(schema: Schema): InterfaceDeclaration | undefined {\n const { logger } = this.#owner;\n\n if (!isObjectSchema(schema)) {\n logger.debug(schema, `Component is not an object: '${this.#fullyQualifiedName}'`);\n return undefined;\n }\n\n if (isEmptyObject(schema)) {\n logger.debug(`Component has no properties:' ${this.#fullyQualifiedName}'`);\n }\n\n return ts.factory.createInterfaceDeclaration(\n undefined,\n this.#id,\n EntityProcessor.#processTypeParameters(schema),\n undefined,\n this.#processTypeElements(schema as ObjectSchema),\n );\n }\n\n #processEnum({ enum: members }: EnumSchema): Statement {\n return ts.factory.createEnumDeclaration(\n undefined,\n this.#id,\n members.map((member) => ts.factory.createEnumMember(member, ts.factory.createStringLiteral(member))),\n );\n }\n\n #processExtendedClass(schema: Schema): Statement | undefined {\n const { logger } = this.#owner;\n\n if (isComposedSchema(schema)) {\n const decomposed = decomposeSchema(schema);\n\n if (decomposed.length > 2) {\n logger.debug(\n schema,\n `Schema for '${this.#fullyQualifiedName}' has more than two components. This plugin will ignore it.`,\n );\n return undefined;\n }\n\n const [parent, child] = decomposed;\n\n if (!isReferenceSchema(parent)) {\n logger.debug(parent, 'Only reference schema allowed for parent class');\n return undefined;\n }\n\n const declaration = this.#processClass(child);\n const identifier = this.#processParentClass(parent);\n\n return (\n declaration &&\n ts.factory.updateInterfaceDeclaration(\n declaration,\n declaration.modifiers,\n declaration.name,\n declaration.typeParameters,\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(identifier, undefined),\n ]),\n ],\n declaration.members,\n )\n );\n }\n\n return this.#processClass(schema);\n }\n\n #processParentClass(schema: ReferenceSchema): Identifier {\n const { imports, paths } = this.#dependencies;\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n\n return imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n }\n\n #processTypeElements({ properties }: ObjectSchema): readonly TypeElement[] {\n return Object.entries(properties ?? {}).map(([name, schema]) => {\n const [type] = new TypeSchemaProcessor(schema, this.#dependencies).process();\n\n return ts.factory.createPropertySignature(\n undefined,\n name,\n isNullableSchema(schema) ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined,\n type,\n );\n });\n }\n\n static #processTypeParameters(schema: Schema): readonly ts.TypeParameterDeclaration[] | undefined {\n return findTypeParameters(schema)\n ?.map(String)\n .map((name) =>\n ts.factory.createTypeParameterDeclaration(\n undefined,\n name,\n undefined,\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n ),\n );\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,eAAe;AAExB;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO;AAAA,OAMA;AACP,OAAO,yBAAyB;AAChC,SAAS,0BAA0B;AAE5B,MAAM,g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,EAAE,YAAY,EAAE,iBAAiB;IAK3D,OAAO,IAAI,SAAS,QAAQ,EAAE;CAwD/B"}
1
+ {"version":3,"file":"TypeSchemaProcessor.d.ts","sourceRoot":"","sources":["src/TypeSchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAiBL,KAAK,MAAM,EACZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AACrG,OAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiC/C,MAAM,CAAC,OAAO,OAAO,mBAAmB;;IAC9B,CAAC,aAAa,CAAC,EAAE,OAAO,mBAAmB,CAAC;gBAIxC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB;IAK3D,OAAO,IAAI,SAAS,QAAQ,EAAE;CAsE/B"}
@@ -13,6 +13,7 @@ import {
13
13
  isStringSchema
14
14
  } from "@vaadin/hilla-generator-core/Schema.js";
15
15
  import ts, {} from "typescript";
16
+ import { findTypeArguments, findTypeVariable } from "./utils.js";
16
17
  function createBoolean() {
17
18
  return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);
18
19
  }
@@ -45,8 +46,13 @@ class TypeSchemaProcessor {
45
46
  process() {
46
47
  let node;
47
48
  const unwrappedSchema = unwrapPossiblyNullableSchema(this.#schema);
49
+ const typeVariable = findTypeVariable(this.#schema);
50
+ if (typeVariable) {
51
+ return [ts.factory.createTypeReferenceNode(typeVariable)];
52
+ }
48
53
  if (isReferenceSchema(unwrappedSchema)) {
49
- node = this.#processReference(unwrappedSchema);
54
+ const typeArguments = this.#processTypeArguments(this.#schema);
55
+ node = this.#processReference(unwrappedSchema, typeArguments);
50
56
  } else if (isArraySchema(unwrappedSchema)) {
51
57
  node = this.#processArray(unwrappedSchema);
52
58
  } else if (isMapSchema(unwrappedSchema)) {
@@ -79,12 +85,15 @@ class TypeSchemaProcessor {
79
85
  valuesTypeNode
80
86
  ]);
81
87
  }
82
- #processReference(schema) {
88
+ #processTypeArguments(schema) {
89
+ return findTypeArguments(schema)?.allOf.map((s) => new TypeSchemaProcessor(s, this.#dependencies).process()).map((t) => ts.factory.createUnionTypeNode(t));
90
+ }
91
+ #processReference(schema, typeArguments) {
83
92
  const { imports, paths } = this.#dependencies;
84
93
  const specifier = convertReferenceSchemaToSpecifier(schema);
85
94
  const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));
86
95
  const identifier = imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);
87
- return ts.factory.createTypeReferenceNode(identifier);
96
+ return ts.factory.createTypeReferenceNode(identifier, typeArguments);
88
97
  }
89
98
  }
90
99
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/TypeSchemaProcessor.ts"],
4
- "sourcesContent": ["import {\n type ArraySchema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isArraySchema,\n isBooleanSchema,\n isComposedSchema,\n isIntegerSchema,\n isMapSchema,\n isNullableSchema,\n isNumberSchema,\n isReferenceSchema,\n isStringSchema,\n type MapSchema,\n type NonComposedSchema,\n type ReferenceSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport ts, { type TypeNode } from 'typescript';\n\nfunction createBoolean(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);\n}\n\nfunction createNumber(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);\n}\n\nfunction createString(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);\n}\n\nfunction createUndefined(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);\n}\n\nfunction createUnknown(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n}\n\nfunction unwrapPossiblyNullableSchema(schema: Schema): NonComposedSchema {\n if (isComposedSchema(schema)) {\n const [result] = decomposeSchema(schema);\n\n return result as NonComposedSchema;\n }\n\n return schema as NonComposedSchema;\n}\n\nexport default class TypeSchemaProcessor {\n declare ['constructor']: typeof TypeSchemaProcessor;\n readonly #dependencies: DependencyManager;\n readonly #schema: Schema;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n this.#schema = schema;\n this.#dependencies = dependencies;\n }\n\n process(): readonly TypeNode[] {\n let node: TypeNode;\n\n const unwrappedSchema = unwrapPossiblyNullableSchema(this.#schema);\n\n if (isReferenceSchema(unwrappedSchema)) {\n node = this.#processReference(unwrappedSchema);\n } else if (isArraySchema(unwrappedSchema)) {\n node = this.#processArray(unwrappedSchema);\n } else if (isMapSchema(unwrappedSchema)) {\n node = this.#processMap(unwrappedSchema);\n } else if (isBooleanSchema(unwrappedSchema)) {\n node = createBoolean();\n } else if (isIntegerSchema(unwrappedSchema) || isNumberSchema(unwrappedSchema)) {\n node = createNumber();\n } else if (isStringSchema(unwrappedSchema)) {\n node = createString();\n } else {\n node = createUnknown();\n }\n\n return isNullableSchema(this.#schema) ? [node, createUndefined()] : [node];\n }\n\n #processArray(schema: ArraySchema): TypeNode {\n const nodes = new TypeSchemaProcessor(schema.items, this.#dependencies).process();\n\n return ts.factory.createTypeReferenceNode('Array', [ts.factory.createUnionTypeNode(nodes)]);\n }\n\n #processMap({ additionalProperties: valuesType }: MapSchema): TypeNode {\n let valuesTypeNode: TypeNode;\n\n if (typeof valuesType !== 'boolean') {\n const nodes = new TypeSchemaProcessor(valuesType, this.#dependencies).process();\n valuesTypeNode = ts.factory.createUnionTypeNode(nodes);\n } else {\n valuesTypeNode = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n }\n\n return ts.factory.createTypeReferenceNode('Record', [\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n valuesTypeNode,\n ]);\n }\n\n #processReference(schema: ReferenceSchema): TypeNode {\n const { imports, paths } = this.#dependencies;\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n\n const identifier = imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n\n return ts.factory.createTypeReferenceNode(identifier);\n }\n}\n"],
5
- "mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAEP,OAAO,YAA2B;AAElC,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,kBAA4B;AACnC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AACxE;AAEA,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,6BAA6B,QAAmC;AACvE,MAAI,iBAAiB,MAAM,GAAG;AAC5B,UAAM,CAAC,MAAM,IAAI,gBAAgB,MAAM;AAEvC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,MAAO,oBAAkC;AAAA,EAE9B;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,cAAiC;AAC3D,SAAK,UAAU;AACf,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,UAA+B;AAC7B,QAAI;AAEJ,UAAM,kBAAkB,6BAA6B,KAAK,OAAO;AAEjE,QAAI,kBAAkB,eAAe,GAAG;AACtC,aAAO,KAAK,kBAAkB,eAAe;AAAA,IAC/C,WAAW,cAAc,eAAe,GAAG;AACzC,aAAO,KAAK,cAA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,QAAQ,IAAI,MAAM,WAAW,IAAI;AAEnG,WAAO,GAAG,QAAQ,wBAAwB,UAAU;AAAA,EACtD;AACF;",
4
+ "sourcesContent": ["import {\n type ArraySchema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isArraySchema,\n isBooleanSchema,\n isComposedSchema,\n isIntegerSchema,\n isMapSchema,\n isNullableSchema,\n isNumberSchema,\n isReferenceSchema,\n isStringSchema,\n type MapSchema,\n type NonComposedSchema,\n type ReferenceSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport ts, { type TypeNode } from 'typescript';\nimport { findTypeArguments, findTypeVariable } from './utils.js';\n\nfunction createBoolean(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);\n}\n\nfunction createNumber(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);\n}\n\nfunction createString(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);\n}\n\nfunction createUndefined(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);\n}\n\nfunction createUnknown(): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n}\n\nfunction unwrapPossiblyNullableSchema(schema: Schema): NonComposedSchema {\n if (isComposedSchema(schema)) {\n const [result] = decomposeSchema(schema);\n\n return result as NonComposedSchema;\n }\n\n return schema as NonComposedSchema;\n}\n\nexport default class TypeSchemaProcessor {\n declare ['constructor']: typeof TypeSchemaProcessor;\n readonly #dependencies: DependencyManager;\n readonly #schema: Schema;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n this.#schema = schema;\n this.#dependencies = dependencies;\n }\n\n process(): readonly TypeNode[] {\n let node: TypeNode;\n\n const unwrappedSchema = unwrapPossiblyNullableSchema(this.#schema);\n\n const typeVariable = findTypeVariable(this.#schema);\n if (typeVariable) {\n // Type variables are returned directly as they are, no further processing is needed\n return [ts.factory.createTypeReferenceNode(typeVariable)];\n }\n\n if (isReferenceSchema(unwrappedSchema)) {\n const typeArguments = this.#processTypeArguments(this.#schema);\n node = this.#processReference(unwrappedSchema, typeArguments);\n } else if (isArraySchema(unwrappedSchema)) {\n node = this.#processArray(unwrappedSchema);\n } else if (isMapSchema(unwrappedSchema)) {\n node = this.#processMap(unwrappedSchema);\n } else if (isBooleanSchema(unwrappedSchema)) {\n node = createBoolean();\n } else if (isIntegerSchema(unwrappedSchema) || isNumberSchema(unwrappedSchema)) {\n node = createNumber();\n } else if (isStringSchema(unwrappedSchema)) {\n node = createString();\n } else {\n node = createUnknown();\n }\n\n return isNullableSchema(this.#schema) ? [node, createUndefined()] : [node];\n }\n\n #processArray(schema: ArraySchema): TypeNode {\n const nodes = new TypeSchemaProcessor(schema.items, this.#dependencies).process();\n\n return ts.factory.createTypeReferenceNode('Array', [ts.factory.createUnionTypeNode(nodes)]);\n }\n\n #processMap({ additionalProperties: valuesType }: MapSchema): TypeNode {\n let valuesTypeNode: TypeNode;\n\n if (typeof valuesType !== 'boolean') {\n const nodes = new TypeSchemaProcessor(valuesType, this.#dependencies).process();\n valuesTypeNode = ts.factory.createUnionTypeNode(nodes);\n } else {\n valuesTypeNode = ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n }\n\n return ts.factory.createTypeReferenceNode('Record', [\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n valuesTypeNode,\n ]);\n }\n\n #processTypeArguments(schema: Schema): readonly ts.TypeNode[] | undefined {\n // Type arguments are processed recursively\n return findTypeArguments(schema)\n ?.allOf.map((s) => new TypeSchemaProcessor(s, this.#dependencies).process())\n .map((t) => ts.factory.createUnionTypeNode(t));\n }\n\n #processReference(schema: ReferenceSchema, typeArguments: readonly ts.TypeNode[] | undefined): TypeNode {\n const { imports, paths } = this.#dependencies;\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n\n const identifier = imports.default.getIdentifier(path) ?? imports.default.add(path, specifier, true);\n\n return ts.factory.createTypeReferenceNode(identifier, typeArguments);\n }\n}\n"],
5
+ "mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAEP,OAAO,YAA2B;AAClC,SAAS,mBAAmB,wBAAwB;AAEpD,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,eAAyB;AAChC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,aAAa;AACrE;AAEA,SAAS,kBAA4B;AACnC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,gBAAgB;AACxE;AAEA,SAAS,gBAA0B;AACjC,SAAO,GAAG,QAAQ,sBAAsB,GAAG,WAAW,cAAc;AACtE;AAEA,SAAS,6BAA6B,QAAmC;AACvE,MAAI,iBAAiB,MAAM,GAAG;AAC5B,UAAM,CAAC,MAAM,IAAI,gBAAgB,MAAM;AAEvC,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,MAAO,oBAAkC;AAAA,EAE9B;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,cAAiC;AAC3D,SAAK,UAAU;AACf,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,UAA+B;AAC7B,QAAI;AAEJ,UAAM,kBAAkB,6BAA6B,KAAK,OAAO;AAEjE,UAAM,eAAe,iBAAiB,KAAK,OAAO;AAClD,QAAI,cAAc;AAEhB,aAAO,CAAC,GAAG,QAAQ,wBAAwB,YAAY,CAAC;A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AAoD;AAExE,WAAO,kBAAkB,MAAM,GAC3B,MAAM,IAAI,CAAC,MAAM,IAAI,oBAAoB,GAAG,KAAK,aAAa,EAAE,QAAQ,CAAC,EAC1E,IAAI,CAAC,MAAM,GAAG,QAAQ,oBAAoB,CAAC,CAAC;AAAA,EACjD;AAAA,EAEA,kBAAkB,QAAyB,eAA6D;AACtG,UAAM,EAAE,SAAS,MAAM,IAAI,KAAK;AAEhC,UAAM,YAAY,kCAAkC,MAAM;AAC1D,UAAM,OAAO,MAAM,mBAAmB,6BAA6B,MAAM,CAAC;AAE1E,UAAM,aAAa,QAAQ,QAAQ,cAAc,IAAI,KAAK,QAAQ,QAAQ,IAAI,MAAM,WAAW,IAAI;AAEnG,WAAO,GAAG,QAAQ,wBAAwB,YAAY,aAAa;AAAA,EACrE;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-generator-plugin-backbone",
3
- "version": "24.5.0-alpha13",
3
+ "version": "24.5.0-alpha15",
4
4
  "description": "A Hilla TypeScript Generator plugin to generate basic code",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -51,12 +51,12 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vaadin/hilla-generator-core": "24.5.0-alpha13",
55
- "@vaadin/hilla-generator-plugin-client": "24.5.0-alpha13",
56
- "@vaadin/hilla-generator-utils": "24.5.0-alpha13",
54
+ "@vaadin/hilla-generator-core": "24.5.0-alpha15",
55
+ "@vaadin/hilla-generator-plugin-client": "24.5.0-alpha15",
56
+ "@vaadin/hilla-generator-utils": "24.5.0-alpha15",
57
57
  "fast-deep-equal": "^3.1.3",
58
58
  "openapi-types": "^12.1.3",
59
- "typescript": "5.5.2"
59
+ "typescript": "5.6.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/chai": "^4.3.6",
@@ -64,8 +64,8 @@
64
64
  "@types/node": "^20.7.1",
65
65
  "@types/sinon": "^10.0.17",
66
66
  "@types/sinon-chai": "^3.2.10",
67
- "@vaadin/hilla-generator-core": "24.5.0-alpha13",
68
- "@vaadin/hilla-generator-plugin-client": "24.5.0-alpha13",
67
+ "@vaadin/hilla-generator-core": "24.5.0-alpha15",
68
+ "@vaadin/hilla-generator-plugin-client": "24.5.0-alpha15",
69
69
  "c8": "^10.1.2",
70
70
  "chai": "^4.3.10",
71
71
  "concurrently": "^8.2.1",
package/utils.d.ts CHANGED
@@ -1,2 +1,18 @@
1
+ import { type AllOfRuleComposedSchema, type Schema } from '@vaadin/hilla-generator-core/Schema.js';
1
2
  export declare const defaultMediaType = "application/json";
3
+ export type SchemaWithTypeArguments = Readonly<{
4
+ 'x-type-arguments': AllOfRuleComposedSchema;
5
+ }> & Schema;
6
+ export type SchemaWithTypeParameters = Readonly<{
7
+ 'x-type-parameters': Schema[];
8
+ }> & Schema;
9
+ export type SchemaWithTypeVariable = Readonly<{
10
+ 'x-type-variable': string;
11
+ }> & Schema;
12
+ export declare function isSchemaWithTypeArguments(schema: Schema): schema is SchemaWithTypeArguments;
13
+ export declare function isSchemaWithTypeParameters(schema: Schema): schema is SchemaWithTypeParameters;
14
+ export declare function isSchemaWithTypeVariable(schema: Schema): schema is SchemaWithTypeVariable;
15
+ export declare function findTypeArguments(schema: Schema): AllOfRuleComposedSchema | undefined;
16
+ export declare function findTypeParameters(schema: Schema): readonly Schema[] | undefined;
17
+ export declare function findTypeVariable(schema: Schema): string | undefined;
2
18
  //# sourceMappingURL=utils.d.ts.map
package/utils.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,qBAAqB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,MAAM,EACZ,MAAM,wCAAwC,CAAC;AAEhD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAAE,kBAAkB,EAAE,uBAAuB,CAAA;CAAE,CAAC,GAAG,MAAM,CAAC;AACzG,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAAE,mBAAmB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,GAAG,MAAM,CAAC;AAC5F,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAAC;AAEtF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,uBAAuB,CAE3F;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,wBAAwB,CAE7F;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,sBAAsB,CAEzF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAWrF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAMhF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMnE"}
package/utils.js CHANGED
@@ -1,5 +1,44 @@
1
+ import {
2
+ isAnyOfRuleComposedSchema
3
+ } from "@vaadin/hilla-generator-core/Schema.js";
1
4
  const defaultMediaType = "application/json";
5
+ function isSchemaWithTypeArguments(schema) {
6
+ return "x-type-arguments" in schema;
7
+ }
8
+ function isSchemaWithTypeParameters(schema) {
9
+ return "x-type-parameters" in schema;
10
+ }
11
+ function isSchemaWithTypeVariable(schema) {
12
+ return "x-type-variable" in schema;
13
+ }
14
+ function findTypeArguments(schema) {
15
+ if (isSchemaWithTypeArguments(schema)) {
16
+ return schema["x-type-arguments"];
17
+ }
18
+ if (isAnyOfRuleComposedSchema(schema)) {
19
+ return schema.anyOf.find(isSchemaWithTypeArguments)?.["x-type-arguments"];
20
+ }
21
+ return void 0;
22
+ }
23
+ function findTypeParameters(schema) {
24
+ if (isSchemaWithTypeParameters(schema)) {
25
+ return schema["x-type-parameters"];
26
+ }
27
+ return void 0;
28
+ }
29
+ function findTypeVariable(schema) {
30
+ if (isSchemaWithTypeVariable(schema)) {
31
+ return schema["x-type-variable"];
32
+ }
33
+ return void 0;
34
+ }
2
35
  export {
3
- defaultMediaType
36
+ defaultMediaType,
37
+ findTypeArguments,
38
+ findTypeParameters,
39
+ findTypeVariable,
40
+ isSchemaWithTypeArguments,
41
+ isSchemaWithTypeParameters,
42
+ isSchemaWithTypeVariable
4
43
  };
5
44
  //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/utils.ts"],
4
- "sourcesContent": ["export const defaultMediaType = 'application/json';\n"],
5
- "mappings": "AAAO,MAAM,mBAAmB;",
4
+ "sourcesContent": ["import {\n isAnyOfRuleComposedSchema,\n type AllOfRuleComposedSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\n\nexport const defaultMediaType = 'application/json';\n\nexport type SchemaWithTypeArguments = Readonly<{ 'x-type-arguments': AllOfRuleComposedSchema }> & Schema;\nexport type SchemaWithTypeParameters = Readonly<{ 'x-type-parameters': Schema[] }> & Schema;\nexport type SchemaWithTypeVariable = Readonly<{ 'x-type-variable': string }> & Schema;\n\nexport function isSchemaWithTypeArguments(schema: Schema): schema is SchemaWithTypeArguments {\n return 'x-type-arguments' in schema;\n}\n\nexport function isSchemaWithTypeParameters(schema: Schema): schema is SchemaWithTypeParameters {\n return 'x-type-parameters' in schema;\n}\n\nexport function isSchemaWithTypeVariable(schema: Schema): schema is SchemaWithTypeVariable {\n return 'x-type-variable' in schema;\n}\n\nexport function findTypeArguments(schema: Schema): AllOfRuleComposedSchema | undefined {\n if (isSchemaWithTypeArguments(schema)) {\n return schema['x-type-arguments'];\n }\n\n // Type arguments are defined as part of anyOf schemas\n if (isAnyOfRuleComposedSchema(schema)) {\n return schema.anyOf.find(isSchemaWithTypeArguments)?.['x-type-arguments'];\n }\n\n return undefined;\n}\n\nexport function findTypeParameters(schema: Schema): readonly Schema[] | undefined {\n if (isSchemaWithTypeParameters(schema)) {\n return schema['x-type-parameters'];\n }\n\n return undefined;\n}\n\nexport function findTypeVariable(schema: Schema): string | undefined {\n if (isSchemaWithTypeVariable(schema)) {\n return schema['x-type-variable'];\n }\n\n return undefined;\n}\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,OAGK;AAEA,MAAM,mBAAmB;AAMzB,SAAS,0BAA0B,QAAmD;AAC3F,SAAO,sBAAsB;AAC/B;AAEO,SAAS,2BAA2B,QAAoD;AAC7F,SAAO,uBAAuB;AAChC;AAEO,SAAS,yBAAyB,QAAkD;AACzF,SAAO,qBAAqB;AAC9B;AAEO,SAAS,kBAAkB,QAAqD;AACrF,MAAI,0BAA0B,MAAM,GAAG;AACrC,WAAO,OAAO,kBAAkB;AAAA,EAClC;AAGA,MAAI,0BAA0B,MAAM,GAAG;AACrC,WAAO,OAAO,MAAM,KAAK,yBAAyB,IAAI,kBAAkB;AAAA,EAC1E;AAEA,SAAO;AACT;AAEO,SAAS,mBAAmB,QAA+C;AAChF,MAAI,2BAA2B,MAAM,GAAG;AACtC,WAAO,OAAO,mBAAmB;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,iBAAiB,QAAoC;AACnE,MAAI,yBAAyB,MAAM,GAAG;AACpC,WAAO,OAAO,iBAAiB;AAAA,EACjC;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }