@vaadin/hilla-generator-plugin-subtypes 24.6.5 → 24.7.0-alpha11
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 +3 -3
- package/ModelFixProcessor.d.ts.map +1 -1
- package/ModelFixProcessor.js +1 -6
- package/ModelFixProcessor.js.map +1 -1
- package/SubTypesProcessor.d.ts +3 -3
- package/SubTypesProcessor.d.ts.map +1 -1
- package/SubTypesProcessor.js +4 -5
- package/SubTypesProcessor.js.map +1 -1
- package/TypeFixProcessor.d.ts +2 -2
- package/TypeFixProcessor.d.ts.map +1 -1
- package/TypeFixProcessor.js +2 -7
- package/TypeFixProcessor.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +4 -2
- package/index.js.map +1 -1
- package/package.json +10 -29
- package/utils.d.ts +3 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +8 -0
- package/utils.js.map +1 -0
package/ModelFixProcessor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type SourceFile } from 'typescript';
|
|
2
2
|
export declare class ModelFixProcessor {
|
|
3
3
|
#private;
|
|
4
|
-
constructor(source:
|
|
5
|
-
process():
|
|
4
|
+
constructor(source: SourceFile);
|
|
5
|
+
process(): SourceFile;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=ModelFixProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelFixProcessor.d.ts","sourceRoot":"","sources":["src/ModelFixProcessor.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"ModelFixProcessor.d.ts","sourceRoot":"","sources":["src/ModelFixProcessor.ts"],"names":[],"mappings":"AACA,OAAW,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGjD,qBAAa,iBAAiB;;gBAGhB,MAAM,EAAE,UAAU;IAI9B,OAAO,IAAI,UAAU;CAsBtB"}
|
package/ModelFixProcessor.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
|
|
2
2
|
import ts, {} from 'typescript';
|
|
3
|
-
|
|
4
|
-
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
|
|
5
|
-
return node.text;
|
|
6
|
-
}
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
3
|
+
import { propertyNameToString } from './utils.js';
|
|
9
4
|
export class ModelFixProcessor {
|
|
10
5
|
#source;
|
|
11
6
|
constructor(source) {
|
package/ModelFixProcessor.js.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"ModelFixProcessor.js","sourceRoot":"","sources":["src/ModelFixProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,EAAE,EAAmB,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAAa;IAE7B,YAAY,MAAkB;QAC5B,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 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"]}
|
package/SubTypesProcessor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReferenceSchema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
-
import
|
|
2
|
+
import { type SourceFile } from 'typescript';
|
|
3
3
|
export declare class SubTypesProcessor {
|
|
4
4
|
#private;
|
|
5
|
-
constructor(typeName: string, source:
|
|
6
|
-
process():
|
|
5
|
+
constructor(typeName: string, source: SourceFile, oneOf: readonly ReferenceSchema[]);
|
|
6
|
+
process(): SourceFile;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=SubTypesProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubTypesProcessor.d.ts","sourceRoot":"","sources":["src/SubTypesProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"SubTypesProcessor.d.ts","sourceRoot":"","sources":["src/SubTypesProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,wCAAwC,CAAC;AAIhD,OAAW,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,iBAAiB;;gBAMhB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,eAAe,EAAE;IASnF,OAAO,IAAI,UAAU;CAyBtB"}
|
package/SubTypesProcessor.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
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';
|
|
2
|
+
import { convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, simplifyFullyQualifiedName, } from '@vaadin/hilla-generator-core/Schema.js';
|
|
4
3
|
import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
|
|
5
4
|
import DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
6
5
|
import PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';
|
|
7
|
-
import ts from 'typescript';
|
|
6
|
+
import ts, {} from 'typescript';
|
|
8
7
|
export class SubTypesProcessor {
|
|
9
8
|
#typeName;
|
|
10
9
|
#source;
|
|
@@ -18,13 +17,13 @@ export class SubTypesProcessor {
|
|
|
18
17
|
}
|
|
19
18
|
process() {
|
|
20
19
|
const { exports, imports, paths } = this.#dependencies;
|
|
21
|
-
// import all
|
|
20
|
+
// import all subtypes and return them
|
|
22
21
|
const subTypes = this.#oneOf.map((schema) => {
|
|
23
22
|
const path = paths.createRelativePath(convertReferenceSchemaToPath(schema));
|
|
24
23
|
const subType = convertReferenceSchemaToSpecifier(schema);
|
|
25
24
|
return imports.default.add(path, subType, true);
|
|
26
25
|
});
|
|
27
|
-
// create a union type from the
|
|
26
|
+
// create a union type from the subtypes
|
|
28
27
|
const union = ts.factory.createUnionTypeNode(subTypes.map((subType) => ts.factory.createTypeReferenceNode(subType)));
|
|
29
28
|
// create the statement
|
|
30
29
|
const { fileName, statements } = this.#source;
|
package/SubTypesProcessor.js.map
CHANGED
|
@@ -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,
|
|
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,EAEjC,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,iBAAiB,MAAM,iEAAiE,CAAC;AAChG,OAAO,WAAW,MAAM,2DAA2D,CAAC;AACpF,OAAO,EAAE,EAAE,EAAmB,MAAM,YAAY,CAAC;AAEjD,MAAM,OAAO,iBAAiB;IACnB,SAAS,CAAS;IAClB,OAAO,CAAa;IACpB,MAAM,CAA6B;IACnC,aAAa,CAAoB;IAE1C,YAAY,QAAgB,EAAE,MAAkB,EAAE,KAAiC;QACjF,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC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BAA0B,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 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"]}
|
package/TypeFixProcessor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
1
|
+
import ts, { type SourceFile } from 'typescript';
|
|
2
2
|
export declare class TypeFixProcessor {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(source: ts.SourceFile, typeValue: string);
|
|
5
|
-
process():
|
|
5
|
+
process(): SourceFile;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=TypeFixProcessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeFixProcessor.d.ts","sourceRoot":"","sources":["src/TypeFixProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeFixProcessor.d.ts","sourceRoot":"","sources":["src/TypeFixProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGjD,qBAAa,gBAAgB;;gBAIf,MAAM,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM;IAKpD,OAAO,IAAI,UAAU;CAgCtB"}
|
package/TypeFixProcessor.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
|
|
2
|
-
import ts from 'typescript';
|
|
3
|
-
|
|
4
|
-
if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
|
|
5
|
-
return node.text;
|
|
6
|
-
}
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
2
|
+
import ts, {} from 'typescript';
|
|
3
|
+
import { propertyNameToString } from './utils.js';
|
|
9
4
|
export class TypeFixProcessor {
|
|
10
5
|
#source;
|
|
11
6
|
#typeValue;
|
package/TypeFixProcessor.js.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"TypeFixProcessor.js","sourceRoot":"","sources":["src/TypeFixProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,EAAE,EAAmB,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,OAAO,gBAAgB;IAClB,OAAO,CAAa;IACpB,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, { 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"]}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
-
import type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
3
|
export default class SubTypesPlugin extends Plugin {
|
|
4
4
|
['constructor']: typeof SubTypesPlugin;
|
|
5
5
|
get path(): string;
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAKnF,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;CAwD9D"}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
-
import { convertFullyQualifiedNameToRelativePath } from '@vaadin/hilla-generator-core/
|
|
2
|
+
import { isReferenceSchema, convertFullyQualifiedNameToRelativePath } from '@vaadin/hilla-generator-core/Schema.js';
|
|
3
3
|
import { ModelFixProcessor } from './ModelFixProcessor.js';
|
|
4
4
|
import { SubTypesProcessor } from './SubTypesProcessor.js';
|
|
5
5
|
import { TypeFixProcessor } from './TypeFixProcessor.js';
|
|
@@ -16,7 +16,9 @@ export default class SubTypesPlugin extends Plugin {
|
|
|
16
16
|
}
|
|
17
17
|
Object.entries(components).forEach(([baseKey, baseComponent]) => {
|
|
18
18
|
// search for components with oneOf: those are union types
|
|
19
|
-
if ('oneOf' in baseComponent &&
|
|
19
|
+
if ('oneOf' in baseComponent &&
|
|
20
|
+
Array.isArray(baseComponent.oneOf) &&
|
|
21
|
+
baseComponent.oneOf.every((schema) => isReferenceSchema(schema))) {
|
|
20
22
|
const fn = `${convertFullyQualifiedNameToRelativePath(baseKey)}.ts`;
|
|
21
23
|
const source = sources.find(({ fileName }) => fileName === fn);
|
|
22
24
|
// replace the (empty) source with a newly-generated one
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,uCAAuC,EAAE,MAAM,wCAAwC,CAAC;AAEpH,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,EAAE,OAAO,CAAC;QAE3C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,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,CAAC,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 { 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-plugin-subtypes",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.7.0-alpha11",
|
|
4
4
|
"description": "A Hilla TypeScript Generator plugin to support JsonSubTypes",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
15
15
|
"lint": "eslint src test",
|
|
16
16
|
"lint:fix": "eslint src test --fix",
|
|
17
|
-
"test": "
|
|
18
|
-
"test:
|
|
19
|
-
"test:
|
|
17
|
+
"test": "vitest --run",
|
|
18
|
+
"test:coverage": "vitest --run --coverage",
|
|
19
|
+
"test:update": "vitest --run --update",
|
|
20
|
+
"test:watch": "vitest",
|
|
20
21
|
"typecheck": "tsc --noEmit"
|
|
21
22
|
},
|
|
22
23
|
"exports": {
|
|
@@ -50,32 +51,12 @@
|
|
|
50
51
|
"access": "public"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@vaadin/hilla-generator-core": "24.
|
|
54
|
-
"@vaadin/hilla-generator-plugin-client": "24.
|
|
55
|
-
"@vaadin/hilla-generator-plugin-model": "24.
|
|
56
|
-
"@vaadin/hilla-generator-utils": "24.
|
|
54
|
+
"@vaadin/hilla-generator-core": "24.7.0-alpha11",
|
|
55
|
+
"@vaadin/hilla-generator-plugin-client": "24.7.0-alpha11",
|
|
56
|
+
"@vaadin/hilla-generator-plugin-model": "24.7.0-alpha11",
|
|
57
|
+
"@vaadin/hilla-generator-utils": "24.7.0-alpha11",
|
|
57
58
|
"fast-deep-equal": "^3.1.3",
|
|
58
59
|
"openapi-types": "^12.1.3",
|
|
59
|
-
"typescript": "5.7.
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/chai": "^4.3.6",
|
|
63
|
-
"@types/mocha": "^10.0.2",
|
|
64
|
-
"@types/node": "^20.7.1",
|
|
65
|
-
"@types/sinon": "^10.0.17",
|
|
66
|
-
"@types/sinon-chai": "^3.2.10",
|
|
67
|
-
"@vaadin/hilla-generator-core": "24.6.5",
|
|
68
|
-
"@vaadin/hilla-generator-plugin-client": "24.6.5",
|
|
69
|
-
"@vaadin/hilla-generator-plugin-model": "24.6.5",
|
|
70
|
-
"c8": "^10.1.2",
|
|
71
|
-
"chai": "^4.3.10",
|
|
72
|
-
"concurrently": "^8.2.1",
|
|
73
|
-
"copyfiles": "^2.4.1",
|
|
74
|
-
"mocha": "^10.8.2",
|
|
75
|
-
"monocart-coverage-reports": "^2.11.5",
|
|
76
|
-
"pino": "^8.21.0",
|
|
77
|
-
"sinon": "^16.1.3",
|
|
78
|
-
"sinon-chai": "^3.7.0",
|
|
79
|
-
"type-fest": "^4.3.2"
|
|
60
|
+
"typescript": "5.7.3"
|
|
80
61
|
}
|
|
81
62
|
}
|
package/utils.d.ts
ADDED
package/utils.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAKtE"}
|
package/utils.js
ADDED
package/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAqB,MAAM,YAAY,CAAC;AAEnD,MAAM,UAAU,oBAAoB,CAAC,IAAkB;IACrD,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","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"]}
|