@vaadin/hilla-generator-plugin-subtypes 24.7.0-alpha9 → 24.7.0-beta3

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,7 +1,6 @@
1
- import ts from 'typescript';
1
+ import { type SourceFile } from "typescript";
2
2
  export declare class ModelFixProcessor {
3
- #private;
4
- constructor(source: ts.SourceFile);
5
- process(): ts.SourceFile;
3
+ #private;
4
+ constructor(source: SourceFile);
5
+ process(): SourceFile;
6
6
  }
7
- //# sourceMappingURL=ModelFixProcessor.d.ts.map
@@ -1,26 +1,20 @@
1
- import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
2
- import ts, {} from 'typescript';
3
- function propertyNameToString(node) {
4
- if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
5
- return node.text;
6
- }
7
- return null;
8
- }
1
+ import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
2
+ import ts from "typescript";
3
+ import { propertyNameToString } from "./utils.js";
9
4
  export class ModelFixProcessor {
10
- #source;
11
- constructor(source) {
12
- this.#source = source;
13
- }
14
- process() {
15
- const statements = this.#source.statements.map((statement) => {
16
- // filter out the @type property from all models
17
- if (ts.isClassDeclaration(statement)) {
18
- const members = statement.members.filter((member) => !(ts.isGetAccessor(member) && propertyNameToString(member.name) === '@type'));
19
- return ts.factory.createClassDeclaration(statement.modifiers, statement.name, statement.typeParameters, statement.heritageClauses, members);
20
- }
21
- return statement;
22
- });
23
- return createSourceFile(statements, this.#source.fileName);
24
- }
5
+ #source;
6
+ constructor(source) {
7
+ this.#source = source;
8
+ }
9
+ process() {
10
+ const statements = this.#source.statements.map((statement) => {
11
+ if (ts.isClassDeclaration(statement)) {
12
+ const members = statement.members.filter((member) => !(ts.isGetAccessor(member) && propertyNameToString(member.name) === "@type"));
13
+ return ts.factory.createClassDeclaration(statement.modifiers, statement.name, statement.typeParameters, statement.heritageClauses, members);
14
+ }
15
+ return statement;
16
+ });
17
+ return createSourceFile(statements, this.#source.fileName);
18
+ }
25
19
  }
26
- //# sourceMappingURL=ModelFixProcessor.js.map
20
+ //# sourceMappingURL=./ModelFixProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelFixProcessor.js","sourceRoot":"","sources":["src/ModelFixProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,EAAE,EAAsD,MAAM,YAAY,CAAC;AAEpF,SAAS,oBAAoB,CAAC,IAAqB;IACjD,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QACnF,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAAgB;IAEhC,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,OAAO;QACL,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC3D,gDAAgD;YAChD,IAAI,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACrC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CACtC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,CACzF,CAAC;gBAEF,OAAO,EAAE,CAAC,OAAO,CAAC,sBAAsB,CACtC,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,cAAc,EACxB,SAAS,CAAC,eAAe,EACzB,OAAO,CACR,CAAC;YACJ,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport ts, { type ClassDeclaration, type GetAccessorDeclaration } from 'typescript';\n\nfunction propertyNameToString(node: ts.PropertyName): string | null {\n if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n return node.text;\n }\n return null;\n}\n\nexport class ModelFixProcessor {\n readonly #source: ts.SourceFile;\n\n constructor(source: ts.SourceFile) {\n this.#source = source;\n }\n\n process(): ts.SourceFile {\n const statements = this.#source.statements.map((statement) => {\n // filter out the @type property from all models\n if (ts.isClassDeclaration(statement)) {\n const members = statement.members.filter(\n (member) => !(ts.isGetAccessor(member) && propertyNameToString(member.name) === '@type'),\n );\n\n return ts.factory.createClassDeclaration(\n statement.modifiers,\n statement.name,\n statement.typeParameters,\n statement.heritageClauses,\n members,\n );\n }\n\n return statement;\n });\n\n return createSourceFile(statements, this.#source.fileName);\n }\n}\n"]}
1
+ {"mappings":"AAAA,OAAO,yEAA0E;AACjF,OAAO,oBAA0C;AACjD,SAAS,wCAAyC;AAElD,OAAO,MAAM,kBAAkB;CAC7B,AAASA;CAET,YAAYC,QAAoB;AAC9B,OAAKD,UAAU;CAChB;CAED,UAAsB;EACpB,MAAM,aAAa,KAAKA,QAAQ,WAAW,IAAI,CAAC,cAAc;AAE5D,OAAI,GAAG,mBAAmB,UAAU,EAAE;IACpC,MAAM,UAAU,UAAU,QAAQ,OAChC,CAAC,aAAa,GAAG,cAAc,OAAO,IAAI,qBAAqB,OAAO,KAAK,KAAK,SACjF;AAED,WAAO,GAAG,QAAQ,uBAChB,UAAU,WACV,UAAU,MACV,UAAU,gBACV,UAAU,iBACV,QACD;GACF;AAED,UAAO;EACR,EAAC;AAEF,SAAO,iBAAiB,YAAY,KAAKA,QAAQ,SAAS;CAC3D;AACF","names":["#source","source: SourceFile"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-subtypes/src/ModelFixProcessor.ts"],"sourcesContent":["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport ts, { type SourceFile } from 'typescript';\nimport { propertyNameToString } from './utils.js';\n\nexport class ModelFixProcessor {\n readonly #source: SourceFile;\n\n constructor(source: SourceFile) {\n this.#source = source;\n }\n\n process(): SourceFile {\n const statements = this.#source.statements.map((statement) => {\n // filter out the @type property from all models\n if (ts.isClassDeclaration(statement)) {\n const members = statement.members.filter(\n (member) => !(ts.isGetAccessor(member) && propertyNameToString(member.name) === '@type'),\n );\n\n return ts.factory.createClassDeclaration(\n statement.modifiers,\n statement.name,\n statement.typeParameters,\n statement.heritageClauses,\n members,\n );\n }\n\n return statement;\n });\n\n return createSourceFile(statements, this.#source.fileName);\n }\n}\n"],"version":3}
@@ -1,8 +1,7 @@
1
- import { type ReferenceSchema } from '@vaadin/hilla-generator-core/Schema.js';
2
- import ts from 'typescript';
1
+ import { type ReferenceSchema } from "@vaadin/hilla-generator-core/Schema.js";
2
+ import { type SourceFile } from "typescript";
3
3
  export declare class SubTypesProcessor {
4
- #private;
5
- constructor(typeName: string, source: ts.SourceFile, oneOf: ReferenceSchema[]);
6
- process(): ts.SourceFile;
4
+ #private;
5
+ constructor(typeName: string, source: SourceFile, oneOf: readonly ReferenceSchema[]);
6
+ process(): SourceFile;
7
7
  }
8
- //# sourceMappingURL=SubTypesProcessor.d.ts.map
@@ -1,38 +1,42 @@
1
- import { dirname } from 'path/posix';
2
- import { convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, } from '@vaadin/hilla-generator-core/Schema.js';
3
- import { simplifyFullyQualifiedName } from '@vaadin/hilla-generator-core/utils.js';
4
- import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
5
- import DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
6
- import PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';
7
- import ts from 'typescript';
1
+ import { dirname } from "path/posix";
2
+ import { convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, simplifyFullyQualifiedName } from "@vaadin/hilla-generator-core/Schema.js";
3
+ import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
4
+ import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
5
+ import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
6
+ import ts from "typescript";
8
7
  export class SubTypesProcessor {
9
- #typeName;
10
- #source;
11
- #oneOf;
12
- #dependencies;
13
- constructor(typeName, source, oneOf) {
14
- this.#typeName = typeName;
15
- this.#source = source;
16
- this.#oneOf = oneOf;
17
- this.#dependencies = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(source.fileName) }));
18
- }
19
- process() {
20
- const { exports, imports, paths } = this.#dependencies;
21
- // import all sub types and return them
22
- const subTypes = this.#oneOf.map((schema) => {
23
- const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));
24
- const subType = convertReferenceSchemaToSpecifier(schema);
25
- return imports.default.add(path, subType, true);
26
- });
27
- // create a union type from the sub types
28
- const union = ts.factory.createUnionTypeNode(subTypes.map((subType) => ts.factory.createTypeReferenceNode(subType)));
29
- // create the statement
30
- const { fileName, statements } = this.#source;
31
- const unionTypeName = `${simplifyFullyQualifiedName(this.#typeName)}`;
32
- const unionIdentifier = ts.factory.createIdentifier(unionTypeName);
33
- const statement = ts.factory.createTypeAliasDeclaration(undefined, unionIdentifier, undefined, union);
34
- exports.default.set(unionTypeName);
35
- return createSourceFile([...imports.toCode(), ...statements, statement, ...exports.toCode()], fileName);
36
- }
8
+ #typeName;
9
+ #source;
10
+ #oneOf;
11
+ #dependencies;
12
+ constructor(typeName, source, oneOf) {
13
+ this.#typeName = typeName;
14
+ this.#source = source;
15
+ this.#oneOf = oneOf;
16
+ this.#dependencies = new DependencyManager(new PathManager({
17
+ extension: ".js",
18
+ relativeTo: dirname(source.fileName)
19
+ }));
20
+ }
21
+ process() {
22
+ const { exports, imports, paths } = this.#dependencies;
23
+ const subTypes = this.#oneOf.map((schema) => {
24
+ const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));
25
+ const subType = convertReferenceSchemaToSpecifier(schema);
26
+ return imports.default.add(path, subType, true);
27
+ });
28
+ const union = ts.factory.createUnionTypeNode(subTypes.map((subType) => ts.factory.createTypeReferenceNode(subType)));
29
+ const { fileName, statements } = this.#source;
30
+ const unionTypeName = `${simplifyFullyQualifiedName(this.#typeName)}`;
31
+ const unionIdentifier = ts.factory.createIdentifier(unionTypeName);
32
+ const statement = ts.factory.createTypeAliasDeclaration(undefined, unionIdentifier, undefined, union);
33
+ exports.default.set(unionTypeName);
34
+ return createSourceFile([
35
+ ...imports.toCode(),
36
+ ...statements,
37
+ statement,
38
+ ...exports.toCode()
39
+ ], fileName);
40
+ }
37
41
  }
38
- //# sourceMappingURL=SubTypesProcessor.js.map
42
+ //# sourceMappingURL=./SubTypesProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SubTypesProcessor.js","sourceRoot":"","sources":["src/SubTypesProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,4BAA4B,EAC5B,iCAAiC,GAElC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,iBAAiB,MAAM,iEAAiE,CAAC;AAChG,OAAO,WAAW,MAAM,2DAA2D,CAAC;AACpF,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,OAAO,iBAAiB;IACnB,SAAS,CAAS;IAClB,OAAO,CAAgB;IACvB,MAAM,CAAoB;IAC1B,aAAa,CA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OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACnE,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAEtG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAEnC,OAAO,gBAAgB,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC1G,CAAC;CACF","sourcesContent":["import { dirname } from 'path/posix';\nimport {\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n type ReferenceSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport { simplifyFullyQualifiedName } 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 from 'typescript';\n\nexport class SubTypesProcessor {\n readonly #typeName: string;\n readonly #source: ts.SourceFile;\n readonly #oneOf: ReferenceSchema[];\n readonly #dependencies;\n\n constructor(typeName: string, source: ts.SourceFile, oneOf: ReferenceSchema[]) {\n this.#typeName = typeName;\n this.#source = source;\n this.#oneOf = oneOf;\n this.#dependencies = new DependencyManager(\n new PathManager({ extension: '.js', relativeTo: dirname(source.fileName) }),\n );\n }\n\n process(): ts.SourceFile {\n const { exports, imports, paths } = this.#dependencies;\n\n // import all sub types and return them\n const subTypes = this.#oneOf.map((schema) => {\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n const subType = convertReferenceSchemaToSpecifier(schema);\n return imports.default.add(path, subType, true);\n });\n\n // create a union type from the sub types\n const union = ts.factory.createUnionTypeNode(\n subTypes.map((subType) => ts.factory.createTypeReferenceNode(subType)),\n );\n\n // create the statement\n const { fileName, statements } = this.#source;\n const unionTypeName = `${simplifyFullyQualifiedName(this.#typeName)}`;\n const unionIdentifier = ts.factory.createIdentifier(unionTypeName);\n const statement = ts.factory.createTypeAliasDeclaration(undefined, unionIdentifier, undefined, union);\n\n exports.default.set(unionTypeName);\n\n return createSourceFile([...imports.toCode(), ...statements, statement, ...exports.toCode()], fileName);\n }\n}\n"]}
1
+ {"mappings":"AAAA,SAAS,2BAA4B;AACrC,SACE,8BACA,mCAEA,0EAC8C;AAChD,OAAO,yEAA0E;AACjF,OAAO,wFAAyF;AAChG,OAAO,4EAA6E;AACpF,OAAO,oBAA0C;AAEjD,OAAO,MAAM,kBAAkB;CAC7B,AAASA;CACT,AAASC;CACT,AAASC;CACT,AAASC;CAET,YAAYC,UAAkBC,QAAoBC,OAAmC;AACnF,OAAKN,YAAY;AACjB,OAAKC,UAAU;AACf,OAAKC,SAAS;AACd,OAAKC,gBAAgB,IAAI,kBACvB,IAAI,YAAY;GAAE,WAAW;GAAO,YAAY,QAAQ,OAAO,SAAS;EAAE;CAE7E;CAED,UAAsB;EACpB,MAAM,EAAE,SAAS,SAAS,OAAO,GAAG,KAAKA;EAGzC,MAAM,WAAW,KAAKD,OAAO,IAAI,CAAC,WAAW;GAC3C,MAAM,OAAO,MAAM,mBAAmB,6BAA6B,OAAO,CAAC;GAC3E,MAAM,UAAU,kCAAkC,OAAO;AACzD,UAAO,QAAQ,QAAQ,IAAI,MAAM,SAAS,KAAK;EAChD,EAAC;EAGF,MAAM,QAAQ,GAAG,QAAQ,oBACvB,SAAS,IAAI,CAAC,YAAY,GAAG,QAAQ,wBAAwB,QAAQ,CAAC,CACvE;EAGD,MAAM,EAAE,UAAU,YAAY,GAAG,KAAKD;EACtC,MAAM,iBAAiB,EAAE,2BAA2B,KAAKD,UAAU,CAAC;EACpE,MAAM,kBAAkB,GAAG,QAAQ,iBAAiB,cAAc;EAClE,MAAM,YAAY,GAAG,QAAQ,2BAA2B,WAAW,iBAAiB,WAAW,MAAM;AAErG,UAAQ,QAAQ,IAAI,cAAc;AAElC,SAAO,iBAAiB;GAAC,GAAG,QAAQ,QAAQ;GAAE,GAAG;GAAY;GAAW,GAAG,QAAQ,QAAQ;EAAC,GAAE,SAAS;CACxG;AACF","names":["#typeName","#source","#oneOf","#dependencies","typeName: string","source: SourceFile","oneOf: readonly ReferenceSchema[]"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-subtypes/src/SubTypesProcessor.ts"],"sourcesContent":["import { dirname } from 'path/posix';\nimport {\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n type ReferenceSchema,\n simplifyFullyQualifiedName,\n} from '@vaadin/hilla-generator-core/Schema.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, { type SourceFile } from 'typescript';\n\nexport class SubTypesProcessor {\n readonly #typeName: string;\n readonly #source: SourceFile;\n readonly #oneOf: readonly ReferenceSchema[];\n readonly #dependencies: DependencyManager;\n\n constructor(typeName: string, source: SourceFile, oneOf: readonly ReferenceSchema[]) {\n this.#typeName = typeName;\n this.#source = source;\n this.#oneOf = oneOf;\n this.#dependencies = new DependencyManager(\n new PathManager({ extension: '.js', relativeTo: dirname(source.fileName) }),\n );\n }\n\n process(): SourceFile {\n const { exports, imports, paths } = this.#dependencies;\n\n // import all subtypes and return them\n const subTypes = this.#oneOf.map((schema) => {\n const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n const subType = convertReferenceSchemaToSpecifier(schema);\n return imports.default.add(path, subType, true);\n });\n\n // create a union type from the subtypes\n const union = ts.factory.createUnionTypeNode(\n subTypes.map((subType) => ts.factory.createTypeReferenceNode(subType)),\n );\n\n // create the statement\n const { fileName, statements } = this.#source;\n const unionTypeName = `${simplifyFullyQualifiedName(this.#typeName)}`;\n const unionIdentifier = ts.factory.createIdentifier(unionTypeName);\n const statement = ts.factory.createTypeAliasDeclaration(undefined, unionIdentifier, undefined, union);\n\n exports.default.set(unionTypeName);\n\n return createSourceFile([...imports.toCode(), ...statements, statement, ...exports.toCode()], fileName);\n }\n}\n"],"version":3}
@@ -1,7 +1,6 @@
1
- import ts from 'typescript';
1
+ import ts, { type SourceFile } from "typescript";
2
2
  export declare class TypeFixProcessor {
3
- #private;
4
- constructor(source: ts.SourceFile, typeValue: string);
5
- process(): ts.SourceFile;
3
+ #private;
4
+ constructor(source: ts.SourceFile, typeValue: string);
5
+ process(): SourceFile;
6
6
  }
7
- //# sourceMappingURL=TypeFixProcessor.d.ts.map
@@ -1,34 +1,27 @@
1
- import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
2
- import ts from 'typescript';
3
- function propertyNameToString(node) {
4
- if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
5
- return node.text;
6
- }
7
- return null;
8
- }
1
+ import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
2
+ import ts from "typescript";
3
+ import { propertyNameToString } from "./utils.js";
9
4
  export class TypeFixProcessor {
10
- #source;
11
- #typeValue;
12
- constructor(source, typeValue) {
13
- this.#source = source;
14
- this.#typeValue = typeValue;
15
- }
16
- process() {
17
- const statements = this.#source.statements.map((statement) => {
18
- // search in the interface definition
19
- if (ts.isInterfaceDeclaration(statement)) {
20
- const members = statement.members.map((member) => {
21
- // search for the @type property and replace it with a quoted string
22
- if (ts.isPropertySignature(member) && propertyNameToString(member.name) === '@type') {
23
- return ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral('@type'), undefined, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(this.#typeValue)));
24
- }
25
- return member;
26
- });
27
- return ts.factory.createInterfaceDeclaration(statement.modifiers, statement.name, statement.typeParameters, statement.heritageClauses, members);
28
- }
29
- return statement;
30
- });
31
- return createSourceFile(statements, this.#source.fileName);
32
- }
5
+ #source;
6
+ #typeValue;
7
+ constructor(source, typeValue) {
8
+ this.#source = source;
9
+ this.#typeValue = typeValue;
10
+ }
11
+ process() {
12
+ const statements = this.#source.statements.map((statement) => {
13
+ if (ts.isInterfaceDeclaration(statement)) {
14
+ const members = statement.members.map((member) => {
15
+ if (ts.isPropertySignature(member) && propertyNameToString(member.name) === "@type") {
16
+ return ts.factory.createPropertySignature(undefined, ts.factory.createStringLiteral("@type"), undefined, ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(this.#typeValue)));
17
+ }
18
+ return member;
19
+ });
20
+ return ts.factory.createInterfaceDeclaration(statement.modifiers, statement.name, statement.typeParameters, statement.heritageClauses, members);
21
+ }
22
+ return statement;
23
+ });
24
+ return createSourceFile(statements, this.#source.fileName);
25
+ }
33
26
  }
34
- //# sourceMappingURL=TypeFixProcessor.js.map
27
+ //# sourceMappingURL=./TypeFixProcessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TypeFixProcessor.js","sourceRoot":"","sources":["src/TypeFixProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,SAAS,oBAAoB,CAAC,IAAqB;IACjD,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QACnF,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,OAAO,gBAAgB;IAClB,OAAO,CAAgB;IACvB,UAAU,CAAS;IAE5B,YAAY,MAAqB,EAAE,SAAiB;QAClD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC3D,qCAAqC;YACrC,IAAI,EAAE,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACzC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC/C,oEAAoE;oBACpE,IAAI,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;wBACpF,OAAO,EAAE,CAAC,OAAO,CAAC,uBAAuB,CACvC,SAAS,EACT,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,EACvC,SAAS,EACT,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAClF,CAAC;oBACJ,CAAC;oBAED,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAC1C,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,cAAc,EACxB,SAAS,CAAC,eAAe,EACzB,OAAO,CACR,CAAC;YACJ,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport ts from 'typescript';\n\nfunction propertyNameToString(node: ts.PropertyName): string | null {\n if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n return node.text;\n }\n return null;\n}\n\nexport class TypeFixProcessor {\n readonly #source: ts.SourceFile;\n readonly #typeValue: string;\n\n constructor(source: ts.SourceFile, typeValue: string) {\n this.#source = source;\n this.#typeValue = typeValue;\n }\n\n process(): ts.SourceFile {\n const statements = this.#source.statements.map((statement) => {\n // search in the interface definition\n if (ts.isInterfaceDeclaration(statement)) {\n const members = statement.members.map((member) => {\n // search for the @type property and replace it with a quoted string\n if (ts.isPropertySignature(member) && propertyNameToString(member.name) === '@type') {\n return ts.factory.createPropertySignature(\n undefined,\n ts.factory.createStringLiteral('@type'),\n undefined,\n ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(this.#typeValue)),\n );\n }\n\n return member;\n });\n\n return ts.factory.createInterfaceDeclaration(\n statement.modifiers,\n statement.name,\n statement.typeParameters,\n statement.heritageClauses,\n members,\n );\n }\n\n return statement;\n });\n\n return createSourceFile(statements, this.#source.fileName);\n }\n}\n"]}
1
+ {"mappings":"AAAA,OAAO,yEAA0E;AACjF,OAAO,oBAA0C;AACjD,SAAS,wCAAyC;AAElD,OAAO,MAAM,iBAAiB;CAC5B,AAASA;CACT,AAASC;CAET,YAAYC,QAAuBC,WAAmB;AACpD,OAAKH,UAAU;AACf,OAAKC,aAAa;CACnB;CAED,UAAsB;EACpB,MAAM,aAAa,KAAKD,QAAQ,WAAW,IAAI,CAAC,cAAc;AAE5D,OAAI,GAAG,uBAAuB,UAAU,EAAE;IACxC,MAAM,UAAU,UAAU,QAAQ,IAAI,CAAC,WAAW;AAEhD,SAAI,GAAG,oBAAoB,OAAO,IAAI,qBAAqB,OAAO,KAAK,KAAK,SAAS;AACnF,aAAO,GAAG,QAAQ,wBAChB,WACA,GAAG,QAAQ,oBAAoB,QAAQ,EACvC,WACA,GAAG,QAAQ,sBAAsB,GAAG,QAAQ,oBAAoB,KAAKC,WAAW,CAAC,CAClF;KACF;AAED,YAAO;IACR,EAAC;AAEF,WAAO,GAAG,QAAQ,2BAChB,UAAU,WACV,UAAU,MACV,UAAU,gBACV,UAAU,iBACV,QACD;GACF;AAED,UAAO;EACR,EAAC;AAEF,SAAO,iBAAiB,YAAY,KAAKD,QAAQ,SAAS;CAC3D;AACF","names":["#source","#typeValue","source: ts.SourceFile","typeValue: string"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-subtypes/src/TypeFixProcessor.ts"],"sourcesContent":["import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport ts, { type SourceFile } from 'typescript';\nimport { propertyNameToString } from './utils.js';\n\nexport class TypeFixProcessor {\n readonly #source: SourceFile;\n readonly #typeValue: string;\n\n constructor(source: ts.SourceFile, typeValue: string) {\n this.#source = source;\n this.#typeValue = typeValue;\n }\n\n process(): SourceFile {\n const statements = this.#source.statements.map((statement) => {\n // search in the interface definition\n if (ts.isInterfaceDeclaration(statement)) {\n const members = statement.members.map((member) => {\n // search for the @type property and replace it with a quoted string\n if (ts.isPropertySignature(member) && propertyNameToString(member.name) === '@type') {\n return ts.factory.createPropertySignature(\n undefined,\n ts.factory.createStringLiteral('@type'),\n undefined,\n ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(this.#typeValue)),\n );\n }\n\n return member;\n });\n\n return ts.factory.createInterfaceDeclaration(\n statement.modifiers,\n statement.name,\n statement.typeParameters,\n statement.heritageClauses,\n members,\n );\n }\n\n return statement;\n });\n\n return createSourceFile(statements, this.#source.fileName);\n }\n}\n"],"version":3}
package/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';
1
+ import Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import type { SharedStorage } from "@vaadin/hilla-generator-core/SharedStorage.js";
3
3
  export default class SubTypesPlugin extends Plugin {
4
- ['constructor']: typeof SubTypesPlugin;
5
- get path(): string;
6
- execute(storage: SharedStorage): Promise<void>;
4
+ ["constructor"]: typeof SubTypesPlugin;
5
+ get path(): string;
6
+ execute(storage: SharedStorage): Promise<void>;
7
7
  }
8
- //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,58 +1,51 @@
1
- import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
2
- import { convertFullyQualifiedNameToRelativePath } from '@vaadin/hilla-generator-core/utils.js';
3
- import { ModelFixProcessor } from './ModelFixProcessor.js';
4
- import { SubTypesProcessor } from './SubTypesProcessor.js';
5
- import { TypeFixProcessor } from './TypeFixProcessor.js';
1
+ import Plugin from "@vaadin/hilla-generator-core/Plugin.js";
2
+ import { isReferenceSchema, convertFullyQualifiedNameToRelativePath } from "@vaadin/hilla-generator-core/Schema.js";
3
+ import { ModelFixProcessor } from "./ModelFixProcessor.js";
4
+ import { SubTypesProcessor } from "./SubTypesProcessor.js";
5
+ import { TypeFixProcessor } from "./TypeFixProcessor.js";
6
6
  export default class SubTypesPlugin extends Plugin {
7
- get path() {
8
- return import.meta.url;
9
- }
10
- // eslint-disable-next-line @typescript-eslint/require-await
11
- async execute(storage) {
12
- const { api, sources } = storage;
13
- const components = api.components?.schemas;
14
- if (!components) {
15
- return;
16
- }
17
- Object.entries(components).forEach(([baseKey, baseComponent]) => {
18
- // search for components with oneOf: those are union types
19
- if ('oneOf' in baseComponent && Array.isArray(baseComponent.oneOf)) {
20
- const fn = `${convertFullyQualifiedNameToRelativePath(baseKey)}.ts`;
21
- const source = sources.find(({ fileName }) => fileName === fn);
22
- // replace the (empty) source with a newly-generated one
23
- const newSource = new SubTypesProcessor(baseKey, source, baseComponent.oneOf).process();
24
- sources.splice(sources.indexOf(source), 1, newSource);
25
- // mentioned types in the oneOf need to be fixed as well
26
- baseComponent.oneOf.forEach((schema) => {
27
- if ('$ref' in schema) {
28
- const path = schema.$ref;
29
- Object.entries(components).forEach(([subKey, subComponent]) => {
30
- if ('anyOf' in subComponent && subKey === path.substring('#/components/schemas/'.length)) {
31
- subComponent.anyOf?.forEach((s) => {
32
- if ('properties' in s && '@type' in s.properties && 'example' in s.properties['@type']) {
33
- const typeValue = s.properties['@type'].example;
34
- const subFn = `${convertFullyQualifiedNameToRelativePath(subKey)}.ts`;
35
- const subSource = sources.find(({ fileName }) => fileName === subFn);
36
- // fix the source to replace the @type property name with a quoted string
37
- const fixedSource = new TypeFixProcessor(subSource, typeValue).process();
38
- sources.splice(sources.indexOf(subSource), 1, fixedSource);
39
- // fix the model to remove the @type property
40
- const modelFn = `${convertFullyQualifiedNameToRelativePath(subKey)}Model.ts`;
41
- const modelSource = sources.find(({ fileName }) => fileName === modelFn);
42
- const fixedModelSource = new ModelFixProcessor(modelSource).process();
43
- sources.splice(sources.indexOf(modelSource), 1, fixedModelSource);
44
- }
45
- });
46
- }
47
- });
48
- }
49
- });
50
- // remove the union type model file
51
- const unionFn = `${convertFullyQualifiedNameToRelativePath(baseKey)}Model.ts`;
52
- const unionSource = sources.find(({ fileName }) => fileName === unionFn);
53
- sources.splice(sources.indexOf(unionSource), 1);
54
- }
55
- });
56
- }
7
+ get path() {
8
+ return import.meta.url;
9
+ }
10
+ async execute(storage) {
11
+ const { api, sources } = storage;
12
+ const components = api.components?.schemas;
13
+ if (!components) {
14
+ return;
15
+ }
16
+ Object.entries(components).forEach(([baseKey, baseComponent]) => {
17
+ if ("oneOf" in baseComponent && Array.isArray(baseComponent.oneOf) && baseComponent.oneOf.every((schema) => isReferenceSchema(schema))) {
18
+ const fn = `${convertFullyQualifiedNameToRelativePath(baseKey)}.ts`;
19
+ const source = sources.find(({ fileName }) => fileName === fn);
20
+ const newSource = new SubTypesProcessor(baseKey, source, baseComponent.oneOf).process();
21
+ sources.splice(sources.indexOf(source), 1, newSource);
22
+ baseComponent.oneOf.forEach((schema) => {
23
+ if ("$ref" in schema) {
24
+ const path = schema.$ref;
25
+ Object.entries(components).forEach(([subKey, subComponent]) => {
26
+ if ("anyOf" in subComponent && subKey === path.substring("#/components/schemas/".length)) {
27
+ subComponent.anyOf?.forEach((s) => {
28
+ if ("properties" in s && "@type" in s.properties && "example" in s.properties["@type"]) {
29
+ const typeValue = s.properties["@type"].example;
30
+ const subFn = `${convertFullyQualifiedNameToRelativePath(subKey)}.ts`;
31
+ const subSource = sources.find(({ fileName }) => fileName === subFn);
32
+ const fixedSource = new TypeFixProcessor(subSource, typeValue).process();
33
+ sources.splice(sources.indexOf(subSource), 1, fixedSource);
34
+ const modelFn = `${convertFullyQualifiedNameToRelativePath(subKey)}Model.ts`;
35
+ const modelSource = sources.find(({ fileName }) => fileName === modelFn);
36
+ const fixedModelSource = new ModelFixProcessor(modelSource).process();
37
+ sources.splice(sources.indexOf(modelSource), 1, fixedModelSource);
38
+ }
39
+ });
40
+ }
41
+ });
42
+ }
43
+ });
44
+ const unionFn = `${convertFullyQualifiedNameToRelativePath(baseKey)}Model.ts`;
45
+ const unionSource = sources.find(({ fileName }) => fileName === unionFn);
46
+ sources.splice(sources.indexOf(unionSource), 1);
47
+ }
48
+ });
49
+ }
57
50
  }
58
- //# sourceMappingURL=index.js.map
51
+ //# sourceMappingURL=./index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAG5D,OAAO,EAAE,uCAAuC,EAAE,MAAM,uCAAuC,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;IAGhD,IAAa,IAAI;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,4DAA4D;IACnD,KAAK,CAAC,OAAO,CAAC,OAAsB;QAC3C,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEjC,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,E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AAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAE,CAAC;gBAC1E,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;YAClD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { ReferenceSchema } from '@vaadin/hilla-generator-core/Schema.js';\nimport type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport { convertFullyQualifiedNameToRelativePath } from '@vaadin/hilla-generator-core/utils.js';\nimport { ModelFixProcessor } from './ModelFixProcessor.js';\nimport { SubTypesProcessor } from './SubTypesProcessor.js';\nimport { TypeFixProcessor } from './TypeFixProcessor.js';\n\nexport default class SubTypesPlugin extends Plugin {\n declare ['constructor']: typeof SubTypesPlugin;\n\n override get path(): string {\n return import.meta.url;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n override async execute(storage: SharedStorage): Promise<void> {\n const { api, sources } = storage;\n\n const components = api.components?.schemas;\n\n if (!components) {\n return;\n }\n\n Object.entries(components).forEach(([baseKey, baseComponent]) => {\n // search for components with oneOf: those are union types\n if ('oneOf' in baseComponent && Array.isArray(baseComponent.oneOf)) {\n const fn = `${convertFullyQualifiedNameToRelativePath(baseKey)}.ts`;\n const source = sources.find(({ fileName }) => fileName === fn)!;\n // replace the (empty) source with a newly-generated one\n const newSource = new SubTypesProcessor(baseKey, source, baseComponent.oneOf).process();\n sources.splice(sources.indexOf(source), 1, newSource);\n\n // mentioned types in the oneOf need to be fixed as well\n baseComponent.oneOf.forEach((schema) => {\n if ('$ref' in schema) {\n const path = (schema as ReferenceSchema).$ref;\n Object.entries(components).forEach(([subKey, subComponent]) => {\n if ('anyOf' in subComponent && subKey === path.substring('#/components/schemas/'.length)) {\n subComponent.anyOf?.forEach((s) => {\n if ('properties' in s && '@type' in s.properties! && 'example' in s.properties['@type']) {\n const typeValue = s.properties['@type'].example as string;\n const subFn = `${convertFullyQualifiedNameToRelativePath(subKey)}.ts`;\n const subSource = sources.find(({ fileName }) => fileName === subFn)!;\n // fix the source to replace the @type property name with a quoted string\n const fixedSource = new TypeFixProcessor(subSource, typeValue).process();\n sources.splice(sources.indexOf(subSource), 1, fixedSource);\n\n // fix the model to remove the @type property\n const modelFn = `${convertFullyQualifiedNameToRelativePath(subKey)}Model.ts`;\n const modelSource = sources.find(({ fileName }) => fileName === modelFn)!;\n const fixedModelSource = new ModelFixProcessor(modelSource).process();\n sources.splice(sources.indexOf(modelSource), 1, fixedModelSource);\n }\n });\n }\n });\n }\n });\n\n // remove the union type model file\n const unionFn = `${convertFullyQualifiedNameToRelativePath(baseKey)}Model.ts`;\n const unionSource = sources.find(({ fileName }) => fileName === unionFn)!;\n sources.splice(sources.indexOf(unionSource), 1);\n }\n });\n }\n}\n"]}
1
+ {"mappings":"AAAA,OAAO,oDAAqD;AAC5D,SAAS,mBAAmB,uFAAwF;AAEpH,SAAS,iDAAkD;AAC3D,SAAS,iDAAkD;AAC3D,SAAS,+CAAgD;AAEzD,eAAe,MAAM,uBAAuB,OAAO;CAGjD,IAAa,OAAe;AAC1B,SAAO,OAAO,KAAK;CACpB;CAGD,MAAe,QAAQA,SAAuC;EAC5D,MAAM,EAAE,KAAK,SAAS,GAAG;EAEzB,MAAM,aAAa,IAAI,YAAY;AAEnC,OAAK,YAAY;AACf;EACD;AAED,SAAO,QAAQ,WAAW,CAAC,QAAQ,CAAC,CAAC,SAAS,cAAc,KAAK;AAE/D,OACE,WAAW,iBACX,MAAM,QAAQ,cAAc,MAAM,IAClC,cAAc,MAAM,MAAM,CAAC,WAAW,kBAAkB,OAAO,CAAC,EAChE;IACA,MAAM,MAAM,EAAE,wCAAwC,QAAQ,CAAC;IAC/D,MAAM,SAAS,QAAQ,KAAK,CAAC,EAAE,UAAU,KAAK,aAAa,GAAG;IAE9D,MAAM,YAAY,IAAI,kB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sourcesContent":["import Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport { isReferenceSchema, convertFullyQualifiedNameToRelativePath } from '@vaadin/hilla-generator-core/Schema.js';\nimport type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport { ModelFixProcessor } from './ModelFixProcessor.js';\nimport { SubTypesProcessor } from './SubTypesProcessor.js';\nimport { TypeFixProcessor } from './TypeFixProcessor.js';\n\nexport default class SubTypesPlugin extends Plugin {\n declare ['constructor']: typeof SubTypesPlugin;\n\n override get path(): string {\n return import.meta.url;\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n override async execute(storage: SharedStorage): Promise<void> {\n const { api, sources } = storage;\n\n const components = api.components?.schemas;\n\n if (!components) {\n return;\n }\n\n Object.entries(components).forEach(([baseKey, baseComponent]) => {\n // search for components with oneOf: those are union types\n if (\n 'oneOf' in baseComponent &&\n Array.isArray(baseComponent.oneOf) &&\n baseComponent.oneOf.every((schema) => isReferenceSchema(schema))\n ) {\n const fn = `${convertFullyQualifiedNameToRelativePath(baseKey)}.ts`;\n const source = sources.find(({ fileName }) => fileName === fn)!;\n // replace the (empty) source with a newly-generated one\n const newSource = new SubTypesProcessor(baseKey, source, baseComponent.oneOf).process();\n sources.splice(sources.indexOf(source), 1, newSource);\n\n // mentioned types in the oneOf need to be fixed as well\n baseComponent.oneOf.forEach((schema) => {\n if ('$ref' in schema) {\n const path = schema.$ref;\n Object.entries(components).forEach(([subKey, subComponent]) => {\n if ('anyOf' in subComponent && subKey === path.substring('#/components/schemas/'.length)) {\n subComponent.anyOf?.forEach((s) => {\n if ('properties' in s && '@type' in s.properties! && 'example' in s.properties['@type']) {\n const typeValue = s.properties['@type'].example as string;\n const subFn = `${convertFullyQualifiedNameToRelativePath(subKey)}.ts`;\n const subSource = sources.find(({ fileName }) => fileName === subFn)!;\n // fix the source to replace the @type property name with a quoted string\n const fixedSource = new TypeFixProcessor(subSource, typeValue).process();\n sources.splice(sources.indexOf(subSource), 1, fixedSource);\n\n // fix the model to remove the @type property\n const modelFn = `${convertFullyQualifiedNameToRelativePath(subKey)}Model.ts`;\n const modelSource = sources.find(({ fileName }) => fileName === modelFn)!;\n const fixedModelSource = new ModelFixProcessor(modelSource).process();\n sources.splice(sources.indexOf(modelSource), 1, fixedModelSource);\n }\n });\n }\n });\n }\n });\n\n // remove the union type model file\n const unionFn = `${convertFullyQualifiedNameToRelativePath(baseKey)}Model.ts`;\n const unionSource = sources.find(({ fileName }) => fileName === unionFn)!;\n sources.splice(sources.indexOf(unionSource), 1);\n }\n });\n }\n}\n"],"version":3}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-generator-plugin-subtypes",
3
- "version": "24.7.0-alpha9",
3
+ "version": "24.7.0-beta3",
4
4
  "description": "A Hilla TypeScript Generator plugin to support JsonSubTypes",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9,14 +9,13 @@
9
9
  },
10
10
  "scripts": {
11
11
  "clean:build": "git clean -fx . -e .vite -e node_modules",
12
- "build": "concurrently npm:build:*",
13
- "build:transpile": "tsc --isolatedModules -p tsconfig.build.json",
14
- "build:copy": "cd src && copyfiles **/*.d.ts ..",
12
+ "build": "tsx ../../../scripts/fast-build.ts",
15
13
  "lint": "eslint src test",
16
14
  "lint:fix": "eslint src test --fix",
17
- "test": "mocha test/**/*.spec.ts --config ../../../.mocharc.cjs",
18
- "test:update": "npm run test -- --update",
19
- "test:coverage": "c8 --experimental-monocart -c ../../../.c8rc.json npm test",
15
+ "test": "vitest --run",
16
+ "test:coverage": "vitest --run --coverage",
17
+ "test:update": "vitest --run --update",
18
+ "test:watch": "vitest",
20
19
  "typecheck": "tsc --noEmit"
21
20
  },
22
21
  "exports": {
@@ -50,32 +49,12 @@
50
49
  "access": "public"
51
50
  },
52
51
  "dependencies": {
53
- "@vaadin/hilla-generator-core": "24.7.0-alpha9",
54
- "@vaadin/hilla-generator-plugin-client": "24.7.0-alpha9",
55
- "@vaadin/hilla-generator-plugin-model": "24.7.0-alpha9",
56
- "@vaadin/hilla-generator-utils": "24.7.0-alpha9",
52
+ "@vaadin/hilla-generator-core": "24.7.0-beta3",
53
+ "@vaadin/hilla-generator-plugin-client": "24.7.0-beta3",
54
+ "@vaadin/hilla-generator-plugin-model": "24.7.0-beta3",
55
+ "@vaadin/hilla-generator-utils": "24.7.0-beta3",
57
56
  "fast-deep-equal": "^3.1.3",
58
57
  "openapi-types": "^12.1.3",
59
58
  "typescript": "5.7.3"
60
- },
61
- "devDependencies": {
62
- "@types/chai": "^4.3.20",
63
- "@types/mocha": "^10.0.10",
64
- "@types/node": "^20.17.12",
65
- "@types/sinon": "^10.0.20",
66
- "@types/sinon-chai": "^3.2.12",
67
- "@vaadin/hilla-generator-core": "24.7.0-alpha9",
68
- "@vaadin/hilla-generator-plugin-client": "24.7.0-alpha9",
69
- "@vaadin/hilla-generator-plugin-model": "24.7.0-alpha9",
70
- "c8": "^10.1.3",
71
- "chai": "^4.5.0",
72
- "concurrently": "^9.1.2",
73
- "copyfiles": "^2.4.1",
74
- "mocha": "^11.1.0",
75
- "monocart-coverage-reports": "^2.11.5",
76
- "pino": "^9.6.0",
77
- "sinon": "^16.1.3",
78
- "sinon-chai": "^3.7.0",
79
- "type-fest": "^4.32.0"
80
59
  }
81
60
  }
package/utils.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { type PropertyName } from "typescript";
2
+ export declare function propertyNameToString(node: PropertyName): string | null;
package/utils.js ADDED
@@ -0,0 +1,8 @@
1
+ import ts from "typescript";
2
+ export function propertyNameToString(node) {
3
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
4
+ return node.text;
5
+ }
6
+ return null;
7
+ }
8
+ //# sourceMappingURL=./utils.js.map
package/utils.js.map ADDED
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,OAAO,oBAA4C;AAEnD,OAAO,SAAS,qBAAqBA,MAAmC;AACtE,KAAI,GAAG,aAAa,KAAK,IAAI,GAAG,gBAAgB,KAAK,IAAI,GAAG,iBAAiB,KAAK,EAAE;AAClF,SAAO,KAAK;CACb;AACD,QAAO;AACR","names":["node: PropertyName"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-subtypes/src/utils.ts"],"sourcesContent":["import ts, { type PropertyName } from 'typescript';\n\nexport function propertyNameToString(node: PropertyName): string | null {\n if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {\n return node.text;\n }\n return null;\n}\n"],"version":3}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModelFixProcessor.d.ts","sourceRoot":"","sources":["src/ModelFixProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAA0D,MAAM,YAAY,CAAC;AASpF,qBAAa,iBAAiB;;gBAGhB,MAAM,EAAE,EAAE,CAAC,UAAU;IAIjC,OAAO,IAAI,EAAE,CAAC,UAAU;CAsBzB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SubTypesProcessor.d.ts","sourceRoot":"","sources":["src/SubTypesProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,wCAAwC,CAAC;AAKhD,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qBAAa,iBAAiB;;gBAMhB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE;IAS7E,OAAO,IAAI,EAAE,CAAC,UAAU;CAyBzB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeFixProcessor.d.ts","sourceRoot":"","sources":["src/TypeFixProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAS5B,qBAAa,gBAAgB;;gBAIf,MAAM,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM;IAKpD,OAAO,IAAI,EAAE,CAAC,UAAU;CAgCzB"}
package/index.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAE5D,OAAO,KAAK,aAAa,MAAM,+CAA+C,CAAC;AAM/E,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;IACxC,CAAC,aAAa,CAAC,EAAE,OAAO,cAAc,CAAC;IAE/C,IAAa,IAAI,IAAI,MAAM,CAE1B;IAGc,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAoD9D"}