@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.
- package/ModelFixProcessor.d.ts +4 -5
- package/ModelFixProcessor.js +18 -24
- package/ModelFixProcessor.js.map +1 -1
- package/SubTypesProcessor.d.ts +5 -6
- package/SubTypesProcessor.js +40 -36
- package/SubTypesProcessor.js.map +1 -1
- package/TypeFixProcessor.d.ts +4 -5
- package/TypeFixProcessor.js +25 -32
- package/TypeFixProcessor.js.map +1 -1
- package/index.d.ts +5 -6
- package/index.js +49 -56
- package/index.js.map +1 -1
- package/package.json +10 -31
- package/utils.d.ts +2 -0
- package/utils.js +8 -0
- package/utils.js.map +1 -0
- package/ModelFixProcessor.d.ts.map +0 -1
- package/SubTypesProcessor.d.ts.map +0 -1
- package/TypeFixProcessor.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
package/ModelFixProcessor.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type SourceFile } from "typescript";
|
|
2
2
|
export declare class ModelFixProcessor {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
#private;
|
|
4
|
+
constructor(source: SourceFile);
|
|
5
|
+
process(): SourceFile;
|
|
6
6
|
}
|
|
7
|
-
//# sourceMappingURL=ModelFixProcessor.d.ts.map
|
package/ModelFixProcessor.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import createSourceFile from
|
|
2
|
-
import ts
|
|
3
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
20
|
+
//# sourceMappingURL=./ModelFixProcessor.js.map
|
package/ModelFixProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
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}
|
package/SubTypesProcessor.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { type ReferenceSchema } from
|
|
2
|
-
import
|
|
1
|
+
import { type ReferenceSchema } from "@vaadin/hilla-generator-core/Schema.js";
|
|
2
|
+
import { type SourceFile } from "typescript";
|
|
3
3
|
export declare class SubTypesProcessor {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
#private;
|
|
5
|
+
constructor(typeName: string, source: SourceFile, oneOf: readonly ReferenceSchema[]);
|
|
6
|
+
process(): SourceFile;
|
|
7
7
|
}
|
|
8
|
-
//# sourceMappingURL=SubTypesProcessor.d.ts.map
|
package/SubTypesProcessor.js
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
import { dirname } from
|
|
2
|
-
import { convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
42
|
+
//# sourceMappingURL=./SubTypesProcessor.js.map
|
package/SubTypesProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
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}
|
package/TypeFixProcessor.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import ts from
|
|
1
|
+
import ts, { type SourceFile } from "typescript";
|
|
2
2
|
export declare class TypeFixProcessor {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
#private;
|
|
4
|
+
constructor(source: ts.SourceFile, typeValue: string);
|
|
5
|
+
process(): SourceFile;
|
|
6
6
|
}
|
|
7
|
-
//# sourceMappingURL=TypeFixProcessor.d.ts.map
|
package/TypeFixProcessor.js
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
import createSourceFile from
|
|
2
|
-
import ts from
|
|
3
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
27
|
+
//# sourceMappingURL=./TypeFixProcessor.js.map
|
package/TypeFixProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
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
|
|
2
|
-
import type SharedStorage from
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
2
|
-
import { convertFullyQualifiedNameToRelativePath } from
|
|
3
|
-
import { ModelFixProcessor } from
|
|
4
|
-
import { SubTypesProcessor } from
|
|
5
|
-
import { TypeFixProcessor } from
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
51
|
+
//# sourceMappingURL=./index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
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,kBAAkB,SAAS,QAAQ,cAAc,OAAO,SAAS;AACvF,YAAQ,OAAO,QAAQ,QAAQ,OAAO,EAAE,GAAG,UAAU;AAGrD,kBAAc,MAAM,QAAQ,CAAC,WAAW;AACtC,SAAI,UAAU,QAAQ;MACpB,MAAM,OAAO,OAAO;AACpB,aAAO,QAAQ,WAAW,CAAC,QAAQ,CAAC,CAAC,QAAQ,aAAa,KAAK;AAC7D,WAAI,WAAW,gBAAgB,WAAW,KAAK,UAAU,wBAAwB,OAAO,EAAE;AACxF,qBAAa,OAAO,QAAQ,CAAC,MAAM;AACjC,aAAI,gBAAgB,KAAK,WAAW,EAAE,cAAe,aAAa,EAAE,WAAW,UAAU;UACvF,MAAM,YAAY,EAAE,WAAW,SAAS;UACxC,MAAM,SAAS,EAAE,wCAAwC,OAAO,CAAC;UACjE,MAAM,YAAY,QAAQ,KAAK,CAAC,EAAE,UAAU,KAAK,aAAa,MAAM;UAEpE,MAAM,cAAc,IAAI,iBAAiB,WAAW,WAAW,SAAS;AACxE,kBAAQ,OAAO,QAAQ,QAAQ,UAAU,EAAE,GAAG,YAAY;UAG1D,MAAM,WAAW,EAAE,wCAAwC,OAAO,CAAC;UACnE,MAAM,cAAc,QAAQ,KAAK,CAAC,EAAE,UAAU,KAAK,aAAa,QAAQ;UACxE,MAAM,mBAAmB,IAAI,kBAAkB,aAAa,SAAS;AACrE,kBAAQ,OAAO,QAAQ,QAAQ,YAAY,EAAE,GAAG,iBAAiB;SAClE;QACF,EAAC;OACH;MACF,EAAC;KACH;IACF,EAAC;IAGF,MAAM,WAAW,EAAE,wCAAwC,QAAQ,CAAC;IACpE,MAAM,cAAc,QAAQ,KAAK,CAAC,EAAE,UAAU,KAAK,aAAa,QAAQ;AACxE,YAAQ,OAAO,QAAQ,QAAQ,YAAY,EAAE,EAAE;GAChD;EACF,EAAC;CACH;AACF","names":["storage: SharedStorage"],"sources":["/opt/agent/work/1af72d8adc613024/hilla/packages/ts/generator-plugin-subtypes/src/index.ts"],"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-
|
|
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": "
|
|
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": "
|
|
18
|
-
"test:
|
|
19
|
-
"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-
|
|
54
|
-
"@vaadin/hilla-generator-plugin-client": "24.7.0-
|
|
55
|
-
"@vaadin/hilla-generator-plugin-model": "24.7.0-
|
|
56
|
-
"@vaadin/hilla-generator-utils": "24.7.0-
|
|
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
package/utils.js
ADDED
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"}
|