@vaadin/hilla-generator-plugin-model 25.3.0-alpha8 → 25.3.0-beta1
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/EntityModelProcessor.d.ts +1 -1
- package/EntityModelProcessor.js +1 -1
- package/EntityModelProcessor.js.map +1 -1
- package/MetadataProcessor.d.ts +1 -1
- package/MetadataProcessor.js +1 -1
- package/MetadataProcessor.js.map +1 -1
- package/ModelSchemaProcessor.d.ts +1 -1
- package/ModelSchemaProcessor.js +1 -1
- package/ModelSchemaProcessor.js.map +1 -1
- package/ValidationConstraintProcessor.d.ts +1 -1
- package/ValidationConstraintProcessor.js +1 -1
- package/ValidationConstraintProcessor.js.map +1 -1
- package/index.js.map +1 -1
- package/package.json +7 -7
- package/utils.d.ts +1 -1
- package/utils.js +1 -1
- package/utils.js.map +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type ClassDeclaration, type Identifier, type SourceFile } from '@typescript/typescript6';
|
|
1
2
|
import { type Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
3
|
import DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
-
import { type ClassDeclaration, type Identifier, type SourceFile } from 'typescript';
|
|
4
4
|
import { type Context } from './utils.js';
|
|
5
5
|
export type DependencyData = Readonly<{
|
|
6
6
|
id: Identifier;
|
package/EntityModelProcessor.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dirname } from 'path/posix';
|
|
2
|
+
import ts, {} from '@typescript/typescript6';
|
|
2
3
|
import { convertFullyQualifiedNameToRelativePath, convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, decomposeSchema, isComposedSchema, isEnumSchema, isObjectSchema, isReferenceSchema, simplifyFullyQualifiedName, } from '@vaadin/hilla-generator-core/Schema.js';
|
|
3
4
|
import createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';
|
|
4
5
|
import DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
5
6
|
import PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';
|
|
6
|
-
import ts, {} from 'typescript';
|
|
7
7
|
import { ModelSchemaExpressionProcessor, ModelSchemaTypeProcessor } from './ModelSchemaProcessor.js';
|
|
8
8
|
import { createEmptyValueMaker, createModelBuildingCallback, importBuiltInFormModel } from './utils.js';
|
|
9
9
|
const $dependencies = Symbol();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityModelProcessor.js","sourceRoot":"","sources":["src/EntityModelProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,iCAAiC,EACjC,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,iBAAiB,EAIjB,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,EAMV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrG,OAAO,EAAgB,qBAAqB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAOtH,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AACzB,MAAM,mBAAmB,GAAG,MAAM,EAAE,CAAC;AACrC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;AACxB,MAAM,mBAAmB,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,OAAgB,oBAAoB;IACxC,MAAM,CAAC,OAAO,CAAC,IAAY,EAAE,SAAiB,EAAE,OAAgB;QAC9D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EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,EAC1D,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,EACzD,SAAS,EACT,SAAS,EACT,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CACjB;SACF,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["/* eslint-disable symbol-description */\nimport { dirname } from 'path/posix';\nimport {\n convertFullyQualifiedNameToRelativePath,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEnumSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n type ReferenceSchema,\n type Schema,\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, {\n type ClassDeclaration,\n type ClassElement,\n type Identifier,\n type SourceFile,\n type Statement,\n} from 'typescript';\nimport { ModelSchemaExpressionProcessor, ModelSchemaTypeProcessor } from './ModelSchemaProcessor.js';\nimport { type Context, createEmptyValueMaker, createModelBuildingCallback, importBuiltInFormModel } from './utils.js';\n\nexport type DependencyData = Readonly<{\n id: Identifier;\n path: string;\n}>;\n\nconst $dependencies = Symbol();\nconst $entity = Symbol();\nconst $fullyQualifiedName = Symbol();\nconst $model = Symbol();\nconst $processDeclaration = Symbol();\n\nexport abstract class EntityModelProcessor {\n static process(name: string, component: Schema, context: Context): SourceFile {\n context.owner.logger.debug(`Processing model for entity: ${name}`);\n\n const schema = isComposedSchema(component) ? decomposeSchema(component)[0] : component;\n\n return isEnumSchema(schema)\n ? // eslint-disable-next-line @typescript-eslint/no-use-before-define\n new EntityEnumModelProcessor(name).process() // eslint-disable-line no-use-before-define\n : // eslint-disable-next-line @typescript-eslint/no-use-before-define\n new EntityClassModelProcessor(name, component, context).process(); // eslint-disable-line no-use-before-define\n }\n\n protected readonly [$dependencies]: DependencyManager;\n protected readonly [$entity]: DependencyData;\n protected readonly [$fullyQualifiedName]: string;\n protected readonly [$model]: DependencyData;\n readonly #outputPathManager = new PathManager({ extension: 'ts' });\n\n protected constructor(name: string, shouldImportEntityAsType: boolean) {\n this[$fullyQualifiedName] = name;\n\n const entityName = simplifyFullyQualifiedName(name);\n const entityPath = convertFullyQualifiedNameToRelativePath(name);\n\n const modelName = `${entityName}Model`;\n const modelPath = `${entityPath}Model`;\n this[$dependencies] = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(modelPath) }));\n\n const { exports, imports, paths } = this[$dependencies];\n\n this[$model] = {\n id: exports.default.set(modelName),\n path: modelPath,\n };\n\n this[$entity] = {\n id: imports.default.add(paths.createRelativePath(entityPath), entityName, shouldImportEntityAsType),\n path: entityPath,\n };\n }\n\n process(): SourceFile {\n const declaration = this[$processDeclaration]();\n\n const { exports, imports } = this[$dependencies];\n const importStatements = imports.toCode();\n const exportStatement = exports.toCode();\n\n return createSourceFile(\n [...importStatements, declaration, ...exportStatement].filter(Boolean) as readonly Statement[],\n this.#outputPathManager.createRelativePath(this[$model].path),\n );\n }\n\n protected abstract [$processDeclaration](): ClassDeclaration | undefined;\n}\n\nexport class EntityClassModelProcessor extends EntityModelProcessor {\n readonly #component: Schema;\n readonly #context: Context;\n readonly #fullyQualifiedName: string;\n readonly #getPropertyModelSymbol: Identifier;\n readonly #makeObjectEmptyValueCreator: Identifier;\n\n constructor(name: string, component: Schema, context: Context) {\n super(name, true);\n\n this.#component = component;\n this.#context = context;\n this.#fullyQualifiedName = name;\n\n this.#getPropertyModelSymbol = this[$dependencies].imports.named.add('@vaadin/hilla-lit-form', '_getPropertyModel');\n this.#makeObjectEmptyValueCreator = this[$dependencies].imports.named.add(\n '@vaadin/hilla-lit-form',\n 'makeObjectEmptyValueCreator',\n );\n }\n\n protected [$processDeclaration](): ClassDeclaration | undefined {\n const { logger } = this.#context.owner;\n\n let entitySchema = this.#component;\n let parent;\n\n if (isComposedSchema(this.#component)) {\n const decomposed = decomposeSchema(this.#component);\n\n if (decomposed.length > 2) {\n logger.debug(\n this.#component,\n `The schema for a class component ${this.#fullyQualifiedName} has more than two components. This plugin will ignore it.`,\n );\n return undefined;\n }\n\n const [parentSchema, childSchema] = decomposed;\n\n if (!isReferenceSchema(parentSchema)) {\n logger.debug(parentSchema, 'Only reference schema allowed for parent class');\n return undefined;\n }\n\n entitySchema = childSchema;\n parent = this.#processParentClass(parentSchema);\n } else {\n parent = importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n\n return this.#processModelClass(entitySchema, this[$entity].id, parent);\n }\n\n #processClassElements({ properties }: ObjectSchema): readonly ClassElement[] {\n if (!properties) {\n return [];\n }\n\n return Object.entries(properties).map(([name, schema]) => {\n const type = new ModelSchemaTypeProcessor(schema, this[$dependencies]).process();\n const args = new ModelSchemaExpressionProcessor(schema, this[$dependencies]).process();\n\n return ts.factory.createGetAccessorDeclaration(\n undefined,\n ts.factory.createIdentifier(name),\n [],\n type,\n ts.factory.createBlock(\n [\n ts.factory.createReturnStatement(\n ts.factory.createCallExpression(\n ts.factory.createElementAccessExpression(ts.factory.createThis(), this.#getPropertyModelSymbol),\n undefined,\n [ts.factory.createStringLiteral(name), createModelBuildingCallback(type.typeName as Identifier, args)],\n ),\n ),\n ],\n true,\n ),\n );\n });\n }\n\n #processModelClass(schema: Schema, entity: Identifier, parent: Identifier): ClassDeclaration | undefined {\n const { logger } = this.#context.owner;\n\n if (!isObjectSchema(schema)) {\n logger.debug(schema, `Component is not an object: ${this.#fullyQualifiedName}`);\n return undefined;\n }\n\n const typeT = ts.factory.createIdentifier('T');\n const modelTypeParameters = ts.factory.createTypeParameterDeclaration(\n undefined,\n typeT,\n ts.factory.createTypeReferenceNode(entity),\n ts.factory.createTypeReferenceNode(entity),\n );\n\n return ts.factory.createClassDeclaration(\n undefined,\n this[$model].id,\n [modelTypeParameters],\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(parent, [ts.factory.createTypeReferenceNode(typeT)]),\n ]),\n ],\n [\n createEmptyValueMaker(this.#makeObjectEmptyValueCreator, this[$model].id),\n ...this.#processClassElements(schema),\n ],\n );\n }\n\n #processParentClass(schema: ReferenceSchema): Identifier {\n const { imports, paths } = this[$dependencies];\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = convertReferenceSchemaToPath(schema);\n const modelPath = paths.createRelativePath(`${path}Model`);\n const modelSpecifier = `${specifier}Model`;\n\n return imports.default.add(modelPath, modelSpecifier, false);\n }\n}\n\nexport class EntityEnumModelProcessor extends EntityModelProcessor {\n constructor(name: string) {\n super(name, false);\n }\n\n protected [$processDeclaration](): ClassDeclaration {\n const enumModel = importBuiltInFormModel('EnumModel', this[$dependencies]);\n const enumPropertySymbol = this[$dependencies].imports.named.add('@vaadin/hilla-lit-form', '_enum');\n const makeEnumEmptyValueCreator = this[$dependencies].imports.named.add(\n '@vaadin/hilla-lit-form',\n 'makeEnumEmptyValueCreator',\n );\n\n return ts.factory.createClassDeclaration(\n undefined,\n this[$model].id,\n undefined,\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(enumModel, [\n ts.factory.createTypeQueryNode(this[$entity].id, undefined),\n ]),\n ]),\n ],\n [\n createEmptyValueMaker(makeEnumEmptyValueCreator, this[$model].id),\n ts.factory.createPropertyDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n ts.factory.createComputedPropertyName(enumPropertySymbol),\n undefined,\n undefined,\n this[$entity].id,\n ),\n ],\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EntityModelProcessor.js","sourceRoot":"","sources":["src/EntityModelProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAA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G,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;QACpG,MAAM,yBAAyB,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CACrE,wBAAwB,EACxB,2BAA2B,CAC5B,CAAC;QAEF,OAAO,EAAE,CAAC,OAAO,CAAC,sBAAsB,CACtC,SAAS,EACT,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EACf,SAAS,EACT;YACE,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE;gBAC5D,EAAE,CAAC,OAAO,CAAC,iCAAiC,CAAC,SAAS,EAAE;oBACtD,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,CAAC;iBAC5D,CAAC;aACH,CAAC;SACH,EACD;YACE,qBAAqB,CAAC,yBAAyB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YACjE,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAClC,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,EAC1D,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,kBAAkB,CAAC,EACzD,SAAS,EACT,SAAS,EACT,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CACjB;SACF,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["/* eslint-disable symbol-description */\nimport { dirname } from 'path/posix';\nimport ts, {\n type ClassDeclaration,\n type ClassElement,\n type Identifier,\n type SourceFile,\n type Statement,\n} from '@typescript/typescript6';\nimport {\n convertFullyQualifiedNameToRelativePath,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEnumSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n type ReferenceSchema,\n type Schema,\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 { ModelSchemaExpressionProcessor, ModelSchemaTypeProcessor } from './ModelSchemaProcessor.js';\nimport { type Context, createEmptyValueMaker, createModelBuildingCallback, importBuiltInFormModel } from './utils.js';\n\nexport type DependencyData = Readonly<{\n id: Identifier;\n path: string;\n}>;\n\nconst $dependencies = Symbol();\nconst $entity = Symbol();\nconst $fullyQualifiedName = Symbol();\nconst $model = Symbol();\nconst $processDeclaration = Symbol();\n\nexport abstract class EntityModelProcessor {\n static process(name: string, component: Schema, context: Context): SourceFile {\n context.owner.logger.debug(`Processing model for entity: ${name}`);\n\n const schema = isComposedSchema(component) ? decomposeSchema(component)[0] : component;\n\n return isEnumSchema(schema)\n ? // eslint-disable-next-line @typescript-eslint/no-use-before-define\n new EntityEnumModelProcessor(name).process() // eslint-disable-line no-use-before-define\n : // eslint-disable-next-line @typescript-eslint/no-use-before-define\n new EntityClassModelProcessor(name, component, context).process(); // eslint-disable-line no-use-before-define\n }\n\n protected readonly [$dependencies]: DependencyManager;\n protected readonly [$entity]: DependencyData;\n protected readonly [$fullyQualifiedName]: string;\n protected readonly [$model]: DependencyData;\n readonly #outputPathManager = new PathManager({ extension: 'ts' });\n\n protected constructor(name: string, shouldImportEntityAsType: boolean) {\n this[$fullyQualifiedName] = name;\n\n const entityName = simplifyFullyQualifiedName(name);\n const entityPath = convertFullyQualifiedNameToRelativePath(name);\n\n const modelName = `${entityName}Model`;\n const modelPath = `${entityPath}Model`;\n this[$dependencies] = new DependencyManager(new PathManager({ extension: '.js', relativeTo: dirname(modelPath) }));\n\n const { exports, imports, paths } = this[$dependencies];\n\n this[$model] = {\n id: exports.default.set(modelName),\n path: modelPath,\n };\n\n this[$entity] = {\n id: imports.default.add(paths.createRelativePath(entityPath), entityName, shouldImportEntityAsType),\n path: entityPath,\n };\n }\n\n process(): SourceFile {\n const declaration = this[$processDeclaration]();\n\n const { exports, imports } = this[$dependencies];\n const importStatements = imports.toCode();\n const exportStatement = exports.toCode();\n\n return createSourceFile(\n [...importStatements, declaration, ...exportStatement].filter(Boolean) as readonly Statement[],\n this.#outputPathManager.createRelativePath(this[$model].path),\n );\n }\n\n protected abstract [$processDeclaration](): ClassDeclaration | undefined;\n}\n\nexport class EntityClassModelProcessor extends EntityModelProcessor {\n readonly #component: Schema;\n readonly #context: Context;\n readonly #fullyQualifiedName: string;\n readonly #getPropertyModelSymbol: Identifier;\n readonly #makeObjectEmptyValueCreator: Identifier;\n\n constructor(name: string, component: Schema, context: Context) {\n super(name, true);\n\n this.#component = component;\n this.#context = context;\n this.#fullyQualifiedName = name;\n\n this.#getPropertyModelSymbol = this[$dependencies].imports.named.add('@vaadin/hilla-lit-form', '_getPropertyModel');\n this.#makeObjectEmptyValueCreator = this[$dependencies].imports.named.add(\n '@vaadin/hilla-lit-form',\n 'makeObjectEmptyValueCreator',\n );\n }\n\n protected [$processDeclaration](): ClassDeclaration | undefined {\n const { logger } = this.#context.owner;\n\n let entitySchema = this.#component;\n let parent;\n\n if (isComposedSchema(this.#component)) {\n const decomposed = decomposeSchema(this.#component);\n\n if (decomposed.length > 2) {\n logger.debug(\n this.#component,\n `The schema for a class component ${this.#fullyQualifiedName} has more than two components. This plugin will ignore it.`,\n );\n return undefined;\n }\n\n const [parentSchema, childSchema] = decomposed;\n\n if (!isReferenceSchema(parentSchema)) {\n logger.debug(parentSchema, 'Only reference schema allowed for parent class');\n return undefined;\n }\n\n entitySchema = childSchema;\n parent = this.#processParentClass(parentSchema);\n } else {\n parent = importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n\n return this.#processModelClass(entitySchema, this[$entity].id, parent);\n }\n\n #processClassElements({ properties }: ObjectSchema): readonly ClassElement[] {\n if (!properties) {\n return [];\n }\n\n return Object.entries(properties).map(([name, schema]) => {\n const type = new ModelSchemaTypeProcessor(schema, this[$dependencies]).process();\n const args = new ModelSchemaExpressionProcessor(schema, this[$dependencies]).process();\n\n return ts.factory.createGetAccessorDeclaration(\n undefined,\n ts.factory.createIdentifier(name),\n [],\n type,\n ts.factory.createBlock(\n [\n ts.factory.createReturnStatement(\n ts.factory.createCallExpression(\n ts.factory.createElementAccessExpression(ts.factory.createThis(), this.#getPropertyModelSymbol),\n undefined,\n [ts.factory.createStringLiteral(name), createModelBuildingCallback(type.typeName as Identifier, args)],\n ),\n ),\n ],\n true,\n ),\n );\n });\n }\n\n #processModelClass(schema: Schema, entity: Identifier, parent: Identifier): ClassDeclaration | undefined {\n const { logger } = this.#context.owner;\n\n if (!isObjectSchema(schema)) {\n logger.debug(schema, `Component is not an object: ${this.#fullyQualifiedName}`);\n return undefined;\n }\n\n const typeT = ts.factory.createIdentifier('T');\n const modelTypeParameters = ts.factory.createTypeParameterDeclaration(\n undefined,\n typeT,\n ts.factory.createTypeReferenceNode(entity),\n ts.factory.createTypeReferenceNode(entity),\n );\n\n return ts.factory.createClassDeclaration(\n undefined,\n this[$model].id,\n [modelTypeParameters],\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(parent, [ts.factory.createTypeReferenceNode(typeT)]),\n ]),\n ],\n [\n createEmptyValueMaker(this.#makeObjectEmptyValueCreator, this[$model].id),\n ...this.#processClassElements(schema),\n ],\n );\n }\n\n #processParentClass(schema: ReferenceSchema): Identifier {\n const { imports, paths } = this[$dependencies];\n\n const specifier = convertReferenceSchemaToSpecifier(schema);\n const path = convertReferenceSchemaToPath(schema);\n const modelPath = paths.createRelativePath(`${path}Model`);\n const modelSpecifier = `${specifier}Model`;\n\n return imports.default.add(modelPath, modelSpecifier, false);\n }\n}\n\nexport class EntityEnumModelProcessor extends EntityModelProcessor {\n constructor(name: string) {\n super(name, false);\n }\n\n protected [$processDeclaration](): ClassDeclaration {\n const enumModel = importBuiltInFormModel('EnumModel', this[$dependencies]);\n const enumPropertySymbol = this[$dependencies].imports.named.add('@vaadin/hilla-lit-form', '_enum');\n const makeEnumEmptyValueCreator = this[$dependencies].imports.named.add(\n '@vaadin/hilla-lit-form',\n 'makeEnumEmptyValueCreator',\n );\n\n return ts.factory.createClassDeclaration(\n undefined,\n this[$model].id,\n undefined,\n [\n ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [\n ts.factory.createExpressionWithTypeArguments(enumModel, [\n ts.factory.createTypeQueryNode(this[$entity].id, undefined),\n ]),\n ]),\n ],\n [\n createEmptyValueMaker(makeEnumEmptyValueCreator, this[$model].id),\n ts.factory.createPropertyDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],\n ts.factory.createComputedPropertyName(enumPropertySymbol),\n undefined,\n undefined,\n this[$entity].id,\n ),\n ],\n );\n }\n}\n"]}
|
package/MetadataProcessor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type ObjectLiteralExpression } from '@typescript/typescript6';
|
|
1
2
|
import type { Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
-
import { type ObjectLiteralExpression } from 'typescript';
|
|
3
3
|
interface Annotation {
|
|
4
4
|
name: string;
|
|
5
5
|
attributes?: Record<string, unknown>;
|
package/MetadataProcessor.js
CHANGED
package/MetadataProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetadataProcessor.js","sourceRoot":"","sources":["src/MetadataProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MetadataProcessor.js","sourceRoot":"","sources":["src/MetadataProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAyD,MAAM,yBAAyB,CAAC;AAapG,SAAS,yBAAyB,CAAC,MAA0B;IAC3D,MAAM,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6B,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import ts, { type ObjectLiteralExpression, type PropertyAssignment } from '@typescript/typescript6';\nimport type { Schema } from '@vaadin/hilla-generator-core/Schema.js';\n\ninterface Annotation {\n name: string;\n attributes?: Record<string, unknown>;\n}\n\nexport type SchemaWithMetadata = Schema & {\n 'x-annotations'?: Annotation[];\n 'x-java-type'?: string;\n};\n\nfunction createAnnotationsProperty(schema: SchemaWithMetadata): PropertyAssignment | null {\n const annotations = schema['x-annotations'];\n const hasAnnotations = annotations && annotations.length > 0;\n if (!hasAnnotations) {\n return null;\n }\n\n const annotationLiterals = annotations.map((annotation) =>\n ts.factory.createObjectLiteralExpression([\n ts.factory.createPropertyAssignment('name', ts.factory.createStringLiteral(annotation.name)),\n ]),\n );\n\n return ts.factory.createPropertyAssignment(\n 'annotations',\n ts.factory.createArrayLiteralExpression(annotationLiterals),\n );\n}\n\nfunction createJavaTypeProperty(schema: SchemaWithMetadata): PropertyAssignment | null {\n const javaType = schema['x-java-type'];\n if (!javaType) {\n return null;\n }\n\n return ts.factory.createPropertyAssignment('javaType', ts.factory.createStringLiteral(javaType));\n}\n\nexport function process(schema: Schema): ObjectLiteralExpression | null {\n const schemaWithMetadata = schema as SchemaWithMetadata;\n\n const properties = [createAnnotationsProperty(schemaWithMetadata), createJavaTypeProperty(schemaWithMetadata)].filter(\n Boolean,\n ) as PropertyAssignment[];\n\n if (properties.length === 0) {\n return null;\n }\n\n return ts.factory.createObjectLiteralExpression(properties);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import ts, { type Expression, type TypeReferenceNode } from '@typescript/typescript6';
|
|
1
2
|
import { type ArraySchema, type BooleanSchema, type IntegerSchema, type MapSchema, type NumberSchema, type ReferenceSchema, type Schema, type StringSchema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
-
import ts, { type Expression, type TypeReferenceNode } from 'typescript';
|
|
4
4
|
declare const $dependencies: unique symbol;
|
|
5
5
|
declare const $processArray: unique symbol;
|
|
6
6
|
declare const $processRecord: unique symbol;
|
package/ModelSchemaProcessor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import ts, {} from '@typescript/typescript6';
|
|
1
2
|
import { convertReferenceSchemaToPath, convertReferenceSchemaToSpecifier, decomposeSchema, isArraySchema, isBooleanSchema, isComposedSchema, isIntegerSchema, isMapSchema, isNullableSchema, isNumberSchema, isReferenceSchema, isStringSchema, } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
-
import ts, {} from 'typescript';
|
|
3
3
|
import { process } from './MetadataProcessor.js';
|
|
4
4
|
import { createModelBuildingCallback, importBuiltInFormModel } from './utils.js';
|
|
5
5
|
import { hasValidationConstraints, ValidationConstraintProcessor } from './ValidationConstraintProcessor.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelSchemaProcessor.js","sourceRoot":"","sources":["src/ModelSchemaProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,4BAA4B,EAC5B,iCAAiC,EACjC,eAAe,EAEf,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,GAMf,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,EAAE,EAMV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAE7G,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC;AAChC,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G,MAAM,CAAC,0BAA0B,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACxE,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,UAAU,CAAC,CACxD,CAAC;QACF,OAAO,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,4BAA4B,CAAC,WAAW,CAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,MAAc;QAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjF,CAAC;CACF","sourcesContent":["import {\n type ArraySchema,\n type BooleanSchema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n type IntegerSchema,\n isArraySchema,\n isBooleanSchema,\n isComposedSchema,\n isIntegerSchema,\n isMapSchema,\n isNullableSchema,\n isNumberSchema,\n isReferenceSchema,\n isStringSchema,\n type MapSchema,\n type NumberSchema,\n type ReferenceSchema,\n type Schema,\n type StringSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport ts, {\n type Expression,\n type Identifier,\n type PropertyAssignment,\n type TypeNode,\n type TypeReferenceNode,\n} from 'typescript';\nimport { process } from './MetadataProcessor.js';\nimport { createModelBuildingCallback, importBuiltInFormModel } from './utils.js';\nimport { hasValidationConstraints, ValidationConstraintProcessor } from './ValidationConstraintProcessor.js';\n\nconst $dependencies = Symbol();\nconst $processArray = Symbol();\nconst $processRecord = Symbol();\nconst $processReference = Symbol();\nconst $processString = Symbol();\nconst $processNumber = Symbol();\nconst $processBoolean = Symbol();\nconst $processUnknown = Symbol();\nconst $originalSchema = Symbol();\nconst $schema = Symbol();\n\nexport abstract class ModelSchemaPartProcessor<T> {\n protected readonly [$dependencies]: DependencyManager;\n protected readonly [$originalSchema]: Schema;\n protected readonly [$schema]: Schema;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n this[$dependencies] = dependencies;\n this[$originalSchema] = schema;\n this[$schema] = isComposedSchema(schema) ? decomposeSchema(schema)[0] : schema;\n }\n\n process(): T {\n const schema = this[$schema];\n\n if (isReferenceSchema(schema)) {\n return this[$processReference](schema);\n }\n\n if (isArraySchema(schema)) {\n return this[$processArray](schema);\n }\n\n if (isMapSchema(schema)) {\n return this[$processRecord](schema);\n }\n\n if (isStringSchema(schema)) {\n return this[$processString](schema);\n }\n\n if (isNumberSchema(schema) || isIntegerSchema(schema)) {\n return this[$processNumber](schema);\n }\n\n if (isBooleanSchema(schema)) {\n return this[$processBoolean](schema);\n }\n\n return this[$processUnknown](schema);\n }\n\n protected abstract [$processArray](schema: ArraySchema): T;\n protected abstract [$processBoolean](schema: BooleanSchema): T;\n protected abstract [$processNumber](schema: IntegerSchema | NumberSchema): T;\n protected abstract [$processRecord](schema: MapSchema): T;\n protected abstract [$processReference](schema: ReferenceSchema): T;\n protected abstract [$processString](schema: StringSchema): T;\n protected abstract [$processUnknown](schema: Schema): T;\n}\n\nfunction handleNullableInternalType(schema: Schema, typeNode: TypeNode): TypeNode {\n return isNullableSchema(schema)\n ? ts.factory.createUnionTypeNode([typeNode, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)])\n : typeNode;\n}\n\nclass ModelSchemaInternalTypeProcessor extends ModelSchemaPartProcessor<TypeNode> {\n protected override [$processArray](schema: ArraySchema): TypeNode {\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('ReadonlyArray'), [\n handleNullableInternalType(\n schema.items,\n new ModelSchemaInternalTypeProcessor(schema.items, this[$dependencies]).process(),\n ),\n ]);\n }\n\n protected override [$processBoolean](_: BooleanSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);\n }\n\n protected override [$processNumber](_: IntegerSchema | NumberSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);\n }\n\n protected override [$processRecord]({ additionalProperties: props }: MapSchema): TypeNode {\n const valueType =\n typeof props === 'boolean'\n ? ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)\n : handleNullableInternalType(props, new ModelSchemaInternalTypeProcessor(props, this[$dependencies]).process());\n\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Record'), [\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n valueType,\n ]);\n }\n\n protected override [$processReference](schema: ReferenceSchema): TypeNode {\n const { imports, paths } = this[$dependencies];\n const typeName = convertReferenceSchemaToSpecifier(schema);\n const typePath = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n return ts.factory.createTypeReferenceNode(\n imports.default.getIdentifier(typePath) ?? imports.default.add(typePath, typeName, true),\n );\n }\n\n protected override [$processString](_: StringSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);\n }\n\n protected override [$processUnknown](_: Schema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n }\n}\n\nclass ModelSchemaIdentifierProcessor extends ModelSchemaPartProcessor<Identifier> {\n override [$processArray](_: ArraySchema): Identifier {\n return importBuiltInFormModel('ArrayModel', this[$dependencies]);\n }\n\n override [$processBoolean](_: BooleanSchema): Identifier {\n return importBuiltInFormModel('BooleanModel', this[$dependencies]);\n }\n\n override [$processNumber](_: IntegerSchema | NumberSchema): Identifier {\n return importBuiltInFormModel('NumberModel', this[$dependencies]);\n }\n\n override [$processRecord](_: MapSchema): Identifier {\n return importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n\n override [$processReference](schema: ReferenceSchema): Identifier {\n const { imports, paths } = this[$dependencies];\n\n const name = `${convertReferenceSchemaToSpecifier(schema)}Model`;\n const path = paths.createRelativePath(`${convertReferenceSchemaToPath(schema)}Model`);\n\n return imports.default.getIdentifier(path) ?? imports.default.add(path, name);\n }\n\n override [$processString](_: StringSchema): Identifier {\n return importBuiltInFormModel('StringModel', this[$dependencies]);\n }\n\n override [$processUnknown](_: Schema): Identifier {\n return importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n}\n\nexport class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor<TypeReferenceNode> {\n readonly #id: ModelSchemaIdentifierProcessor;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n super(schema, dependencies);\n this.#id = new ModelSchemaIdentifierProcessor(schema, dependencies);\n }\n\n protected override [$processArray](schema: ArraySchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processArray](schema), [\n new ModelSchemaTypeProcessor(schema.items, this[$dependencies]).process(),\n ]);\n }\n\n protected override [$processBoolean](schema: BooleanSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processBoolean](schema));\n }\n\n protected override [$processNumber](schema: IntegerSchema | NumberSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processNumber](schema));\n }\n\n protected override [$processRecord](schema: MapSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processRecord](schema), [\n new ModelSchemaInternalTypeProcessor(schema, this[$dependencies]).process(),\n ]);\n }\n\n protected override [$processReference](schema: ReferenceSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processReference](schema));\n }\n\n protected override [$processString](schema: StringSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processString](schema));\n }\n\n protected override [$processUnknown](schema: Schema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processUnknown](schema));\n }\n}\n\nexport class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor<readonly Expression[]> {\n readonly #validationConstraintProcessor: ValidationConstraintProcessor;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n super(schema, dependencies);\n this.#validationConstraintProcessor = new ValidationConstraintProcessor((name) =>\n importBuiltInFormModel(name, dependencies),\n );\n }\n\n override process(): readonly ts.Expression[] {\n const originalSchema = this[$originalSchema];\n\n let result = super.process();\n\n const modelOptionsProperties = [\n this.#createValidatorsProperty(originalSchema),\n ModelSchemaExpressionProcessor.#createMetadataProperty(originalSchema),\n ].filter(Boolean) as PropertyAssignment[];\n\n if (modelOptionsProperties.length > 0) {\n const optionsObject = ts.factory.createObjectLiteralExpression(modelOptionsProperties);\n\n result = [...result, optionsObject];\n }\n\n return [isNullableSchema(originalSchema) ? ts.factory.createTrue() : ts.factory.createFalse(), ...result];\n }\n\n protected override [$processArray](schema: ArraySchema): readonly Expression[] {\n const model = new ModelSchemaIdentifierProcessor(schema.items, this[$dependencies]).process();\n\n return [\n createModelBuildingCallback(\n model,\n new ModelSchemaExpressionProcessor(schema.items, this[$dependencies]).process(),\n ),\n ];\n }\n\n protected override [$processBoolean](_: BooleanSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processNumber](_: IntegerSchema | NumberSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processRecord](_: MapSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processReference](_: ReferenceSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processString](_: StringSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processUnknown](_: Schema): readonly Expression[] {\n return [];\n }\n\n #createValidatorsProperty(schema: Schema): PropertyAssignment | null {\n if (!hasValidationConstraints(schema)) {\n return null;\n }\n\n const constraints = schema['x-validation-constraints'].map((constraint) =>\n this.#validationConstraintProcessor.process(constraint),\n );\n return ts.factory.createPropertyAssignment('validators', ts.factory.createArrayLiteralExpression(constraints));\n }\n\n static #createMetadataProperty(schema: Schema): PropertyAssignment | null {\n const metadata = process(schema);\n return metadata ? ts.factory.createPropertyAssignment('meta', metadata) : null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelSchemaProcessor.js","sour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SACF,CAAC;IACJ,CAAC;IAEkB,CAAC,eAAe,CAAC,CAAC,CAAgB;QACnD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEkB,CAAC,cAAc,CAAC,CAAC,CAA+B;QACjE,OAAO,EAAE,CAAC;IACZ,CAAC;IAEkB,CAAC,cAAc,CAAC,CAAC,CAAY;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC;IAEkB,CAAC,iBAAiB,CAAC,CAAC,CAAkB;QACvD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEkB,CAAC,cAAc,CAAC,CAAC,CAAe;QACjD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEkB,CAAC,eAAe,CAAC,CAAC,CAAS;QAC5C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,yBAAyB,CAAC,MAAc;QACtC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACxE,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,UAAU,CAAC,CACxD,CAAC;QACF,OAAO,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,4BAA4B,CAAC,WAAW,CAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,MAAc;QAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjF,CAAC;CACF","sourcesContent":["import ts, {\n type Expression,\n type Identifier,\n type PropertyAssignment,\n type TypeNode,\n type TypeReferenceNode,\n} from '@typescript/typescript6';\nimport {\n type ArraySchema,\n type BooleanSchema,\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n type IntegerSchema,\n isArraySchema,\n isBooleanSchema,\n isComposedSchema,\n isIntegerSchema,\n isMapSchema,\n isNullableSchema,\n isNumberSchema,\n isReferenceSchema,\n isStringSchema,\n type MapSchema,\n type NumberSchema,\n type ReferenceSchema,\n type Schema,\n type StringSchema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport { process } from './MetadataProcessor.js';\nimport { createModelBuildingCallback, importBuiltInFormModel } from './utils.js';\nimport { hasValidationConstraints, ValidationConstraintProcessor } from './ValidationConstraintProcessor.js';\n\nconst $dependencies = Symbol();\nconst $processArray = Symbol();\nconst $processRecord = Symbol();\nconst $processReference = Symbol();\nconst $processString = Symbol();\nconst $processNumber = Symbol();\nconst $processBoolean = Symbol();\nconst $processUnknown = Symbol();\nconst $originalSchema = Symbol();\nconst $schema = Symbol();\n\nexport abstract class ModelSchemaPartProcessor<T> {\n protected readonly [$dependencies]: DependencyManager;\n protected readonly [$originalSchema]: Schema;\n protected readonly [$schema]: Schema;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n this[$dependencies] = dependencies;\n this[$originalSchema] = schema;\n this[$schema] = isComposedSchema(schema) ? decomposeSchema(schema)[0] : schema;\n }\n\n process(): T {\n const schema = this[$schema];\n\n if (isReferenceSchema(schema)) {\n return this[$processReference](schema);\n }\n\n if (isArraySchema(schema)) {\n return this[$processArray](schema);\n }\n\n if (isMapSchema(schema)) {\n return this[$processRecord](schema);\n }\n\n if (isStringSchema(schema)) {\n return this[$processString](schema);\n }\n\n if (isNumberSchema(schema) || isIntegerSchema(schema)) {\n return this[$processNumber](schema);\n }\n\n if (isBooleanSchema(schema)) {\n return this[$processBoolean](schema);\n }\n\n return this[$processUnknown](schema);\n }\n\n protected abstract [$processArray](schema: ArraySchema): T;\n protected abstract [$processBoolean](schema: BooleanSchema): T;\n protected abstract [$processNumber](schema: IntegerSchema | NumberSchema): T;\n protected abstract [$processRecord](schema: MapSchema): T;\n protected abstract [$processReference](schema: ReferenceSchema): T;\n protected abstract [$processString](schema: StringSchema): T;\n protected abstract [$processUnknown](schema: Schema): T;\n}\n\nfunction handleNullableInternalType(schema: Schema, typeNode: TypeNode): TypeNode {\n return isNullableSchema(schema)\n ? ts.factory.createUnionTypeNode([typeNode, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)])\n : typeNode;\n}\n\nclass ModelSchemaInternalTypeProcessor extends ModelSchemaPartProcessor<TypeNode> {\n protected override [$processArray](schema: ArraySchema): TypeNode {\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('ReadonlyArray'), [\n handleNullableInternalType(\n schema.items,\n new ModelSchemaInternalTypeProcessor(schema.items, this[$dependencies]).process(),\n ),\n ]);\n }\n\n protected override [$processBoolean](_: BooleanSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);\n }\n\n protected override [$processNumber](_: IntegerSchema | NumberSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);\n }\n\n protected override [$processRecord]({ additionalProperties: props }: MapSchema): TypeNode {\n const valueType =\n typeof props === 'boolean'\n ? ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)\n : handleNullableInternalType(props, new ModelSchemaInternalTypeProcessor(props, this[$dependencies]).process());\n\n return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Record'), [\n ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n valueType,\n ]);\n }\n\n protected override [$processReference](schema: ReferenceSchema): TypeNode {\n const { imports, paths } = this[$dependencies];\n const typeName = convertReferenceSchemaToSpecifier(schema);\n const typePath = paths.createRelativePath(convertReferenceSchemaToPath(schema));\n return ts.factory.createTypeReferenceNode(\n imports.default.getIdentifier(typePath) ?? imports.default.add(typePath, typeName, true),\n );\n }\n\n protected override [$processString](_: StringSchema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);\n }\n\n protected override [$processUnknown](_: Schema): TypeNode {\n return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);\n }\n}\n\nclass ModelSchemaIdentifierProcessor extends ModelSchemaPartProcessor<Identifier> {\n override [$processArray](_: ArraySchema): Identifier {\n return importBuiltInFormModel('ArrayModel', this[$dependencies]);\n }\n\n override [$processBoolean](_: BooleanSchema): Identifier {\n return importBuiltInFormModel('BooleanModel', this[$dependencies]);\n }\n\n override [$processNumber](_: IntegerSchema | NumberSchema): Identifier {\n return importBuiltInFormModel('NumberModel', this[$dependencies]);\n }\n\n override [$processRecord](_: MapSchema): Identifier {\n return importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n\n override [$processReference](schema: ReferenceSchema): Identifier {\n const { imports, paths } = this[$dependencies];\n\n const name = `${convertReferenceSchemaToSpecifier(schema)}Model`;\n const path = paths.createRelativePath(`${convertReferenceSchemaToPath(schema)}Model`);\n\n return imports.default.getIdentifier(path) ?? imports.default.add(path, name);\n }\n\n override [$processString](_: StringSchema): Identifier {\n return importBuiltInFormModel('StringModel', this[$dependencies]);\n }\n\n override [$processUnknown](_: Schema): Identifier {\n return importBuiltInFormModel('ObjectModel', this[$dependencies]);\n }\n}\n\nexport class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor<TypeReferenceNode> {\n readonly #id: ModelSchemaIdentifierProcessor;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n super(schema, dependencies);\n this.#id = new ModelSchemaIdentifierProcessor(schema, dependencies);\n }\n\n protected override [$processArray](schema: ArraySchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processArray](schema), [\n new ModelSchemaTypeProcessor(schema.items, this[$dependencies]).process(),\n ]);\n }\n\n protected override [$processBoolean](schema: BooleanSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processBoolean](schema));\n }\n\n protected override [$processNumber](schema: IntegerSchema | NumberSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processNumber](schema));\n }\n\n protected override [$processRecord](schema: MapSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processRecord](schema), [\n new ModelSchemaInternalTypeProcessor(schema, this[$dependencies]).process(),\n ]);\n }\n\n protected override [$processReference](schema: ReferenceSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processReference](schema));\n }\n\n protected override [$processString](schema: StringSchema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processString](schema));\n }\n\n protected override [$processUnknown](schema: Schema): TypeReferenceNode {\n return ts.factory.createTypeReferenceNode(this.#id[$processUnknown](schema));\n }\n}\n\nexport class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor<readonly Expression[]> {\n readonly #validationConstraintProcessor: ValidationConstraintProcessor;\n\n constructor(schema: Schema, dependencies: DependencyManager) {\n super(schema, dependencies);\n this.#validationConstraintProcessor = new ValidationConstraintProcessor((name) =>\n importBuiltInFormModel(name, dependencies),\n );\n }\n\n override process(): readonly ts.Expression[] {\n const originalSchema = this[$originalSchema];\n\n let result = super.process();\n\n const modelOptionsProperties = [\n this.#createValidatorsProperty(originalSchema),\n ModelSchemaExpressionProcessor.#createMetadataProperty(originalSchema),\n ].filter(Boolean) as PropertyAssignment[];\n\n if (modelOptionsProperties.length > 0) {\n const optionsObject = ts.factory.createObjectLiteralExpression(modelOptionsProperties);\n\n result = [...result, optionsObject];\n }\n\n return [isNullableSchema(originalSchema) ? ts.factory.createTrue() : ts.factory.createFalse(), ...result];\n }\n\n protected override [$processArray](schema: ArraySchema): readonly Expression[] {\n const model = new ModelSchemaIdentifierProcessor(schema.items, this[$dependencies]).process();\n\n return [\n createModelBuildingCallback(\n model,\n new ModelSchemaExpressionProcessor(schema.items, this[$dependencies]).process(),\n ),\n ];\n }\n\n protected override [$processBoolean](_: BooleanSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processNumber](_: IntegerSchema | NumberSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processRecord](_: MapSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processReference](_: ReferenceSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processString](_: StringSchema): readonly Expression[] {\n return [];\n }\n\n protected override [$processUnknown](_: Schema): readonly Expression[] {\n return [];\n }\n\n #createValidatorsProperty(schema: Schema): PropertyAssignment | null {\n if (!hasValidationConstraints(schema)) {\n return null;\n }\n\n const constraints = schema['x-validation-constraints'].map((constraint) =>\n this.#validationConstraintProcessor.process(constraint),\n );\n return ts.factory.createPropertyAssignment('validators', ts.factory.createArrayLiteralExpression(constraints));\n }\n\n static #createMetadataProperty(schema: Schema): PropertyAssignment | null {\n const metadata = process(schema);\n return metadata ? ts.factory.createPropertyAssignment('meta', metadata) : null;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type Identifier, type NewExpression } from '@typescript/typescript6';
|
|
1
2
|
import type { NonComposedRegularSchema, Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
-
import { type Identifier, type NewExpression } from 'typescript';
|
|
3
3
|
export type ValidationConstrainedSchema = NonComposedRegularSchema & Readonly<{
|
|
4
4
|
'x-validation-constraints': readonly ValidationConstraint[];
|
|
5
5
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import ts, {} from '@typescript/typescript6';
|
|
1
2
|
import { template, transform } from '@vaadin/hilla-generator-utils/ast.js';
|
|
2
|
-
import ts, {} from 'typescript';
|
|
3
3
|
export function hasValidationConstraints(schema) {
|
|
4
4
|
return ('x-validation-constraints' in schema &&
|
|
5
5
|
schema['x-validation-constraints'].length > 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationConstraintProcessor.js","sourceRoot":"","sources":["src/ValidationConstraintProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":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AAC,CAAC;QAE1G,OAAO,QAAQ,CAAC,GAAG,oBAAoB,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE;YAC1D,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CACjB,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC5D,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC;gBACvE,CAAC,CAAC,IAAI,CACT;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import ts, {\n type Expression,\n type Identifier,\n type NewExpression,\n type Statement,\n type VariableStatement,\n} from '@typescript/typescript6';\nimport type { NonComposedRegularSchema, Schema } from '@vaadin/hilla-generator-core/Schema.js';\nimport { template, transform } from '@vaadin/hilla-generator-utils/ast.js';\n\nexport type ValidationConstrainedSchema = NonComposedRegularSchema &\n Readonly<{ 'x-validation-constraints': readonly ValidationConstraint[] }>;\n\nexport function hasValidationConstraints(schema: Schema): schema is ValidationConstrainedSchema {\n return (\n 'x-validation-constraints' in schema &&\n (schema as ValidationConstrainedSchema)['x-validation-constraints'].length > 0\n );\n}\n\nexport interface ValidationConstraint {\n simpleName: string;\n attributes?: Record<string, unknown>;\n}\n\nexport type ValidationConstraintImporter = (name: string) => Identifier;\n\nfunction selector<T extends Expression>([statement]: readonly Statement[]): T {\n return (statement as VariableStatement).declarationList.declarations[0].initializer as T;\n}\n\nconst variableStatementVar = 'const a';\n\nexport class ValidationConstraintProcessor {\n readonly #importer: ValidationConstraintImporter;\n\n constructor(importer: ValidationConstraintImporter) {\n this.#importer = importer;\n }\n\n process(constraint: ValidationConstraint): NewExpression {\n return ts.factory.createNewExpression(\n this.#importer(constraint.simpleName),\n undefined,\n constraint.attributes ? [ValidationConstraintProcessor.#processAttributes(constraint.attributes)] : [],\n );\n }\n\n static #processAttributes(attributes: Record<string, unknown>): Expression {\n const names = Object.keys(attributes);\n const tpl = JSON.stringify(names.includes('value') && names.length === 1 ? attributes.value : attributes);\n\n return template(`${variableStatementVar}=${tpl}`, selector, [\n transform((node) =>\n ts.isPropertyAssignment(node) && ts.isStringLiteral(node.name)\n ? ts.factory.createPropertyAssignment(node.name.text, node.initializer)\n : node,\n ),\n ]);\n }\n}\n"]}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAG5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,MAAM,CAAN,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,wCAAe,CAAA;AACjB,CAAC,EAFW,qBAAqB,KAArB,qBAAqB,QAEhC;AAED,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,MAAM;IAC7C,MAAM,CAAU,sBAAsB,GAAG,wBAAwB,CAAC;IAEzD,KAAK,GAAG,IAAI,OAAO,EAAqC,CAAC;IAElE,IAAa,IAAI;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAGQ,KAAK,CAAC,OAAO,CAAC,OAAsB;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACrE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3E,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC/B,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,sBAAsB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACjF,CAAC;IAED,gBAAgB,CAAC,OAA8C;QAC7D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,GAAG,GAAY;YACnB,KAAK,EAAE,IAAI;SACZ,CAAC;QAEF,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAChH,CAAC","sourcesContent":["import type { SourceFile } from '@typescript/typescript6';\nimport Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport { EntityModelProcessor } from './EntityModelProcessor.js';\nimport type { Context } from './utils.js';\n\nexport enum ModelPluginSourceType {\n Model = 'model',\n}\n\nexport default class ModelPlugin extends Plugin {\n static readonly MODEL_PLUGIN_FILE_TAGS = 'MODEL_PLUGIN_FILE_TAGS';\n declare ['constructor']: typeof ModelPlugin;\n readonly #tags = new WeakMap<SourceFile, ModelPluginSourceType>();\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 files = this.#processEntities(storage.api.components?.schemas);\n files.forEach((file) => this.#tags.set(file, ModelPluginSourceType.Model));\n storage.sources.push(...files);\n storage.pluginStorage.set(this.constructor.MODEL_PLUGIN_FILE_TAGS, this.#tags);\n }\n\n #processEntities(schemas: OpenAPIV3.ComponentsObject['schemas']): readonly SourceFile[] {\n this.logger.debug('Processing entities');\n\n if (!schemas) {\n return [];\n }\n\n const ctx: Context = {\n owner: this,\n };\n\n return Object.entries(schemas).map(([name, component]) => EntityModelProcessor.process(name, component, ctx));\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-generator-plugin-model",
|
|
3
|
-
"version": "25.3.0-
|
|
3
|
+
"version": "25.3.0-beta1",
|
|
4
4
|
"description": "A Hilla TypeScript Generator plugin to generate form models",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@vaadin/hilla-generator-
|
|
54
|
-
"@vaadin/hilla-generator-
|
|
55
|
-
"@vaadin/hilla-
|
|
52
|
+
"@typescript/typescript6": "6.0.2",
|
|
53
|
+
"@vaadin/hilla-generator-core": "25.3.0-beta1",
|
|
54
|
+
"@vaadin/hilla-generator-plugin-backbone": "25.3.0-beta1",
|
|
55
|
+
"@vaadin/hilla-generator-utils": "25.3.0-beta1",
|
|
56
|
+
"@vaadin/hilla-lit-form": "25.3.0-beta1",
|
|
56
57
|
"fast-deep-equal": "3.1.3",
|
|
57
|
-
"openapi-types": "12.1.3"
|
|
58
|
-
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
58
|
+
"openapi-types": "12.1.3"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type ArrowFunction, type Expression, type Identifier, type PropertyDeclaration } from '@typescript/typescript6';
|
|
1
2
|
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
3
|
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
-
import { type ArrowFunction, type Expression, type Identifier, type PropertyDeclaration } from 'typescript';
|
|
4
4
|
export type Context = Readonly<{
|
|
5
5
|
owner: Plugin;
|
|
6
6
|
}>;
|
package/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ts, {} from 'typescript';
|
|
1
|
+
import ts, {} from '@typescript/typescript6';
|
|
2
2
|
export const defaultMediaType = 'application/json';
|
|
3
3
|
export function importBuiltInFormModel(specifier, { imports, paths }) {
|
|
4
4
|
const modelPath = paths.createBareModulePath('@vaadin/hilla-lit-form', false);
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAKV,MAAM,yBAAyB,CAAC;AAQjC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD,MAAM,UAAU,sBAAsB,CAAC,SAAiB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAqB;IAC7F,MAAM,SAAS,GAAG,KAAK,CAAC,oBAAoB,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC9E,OAAO,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAgB,EAAE,IAA2B;IACvF,MAAM,QAAQ,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7F,OAAO,EAAE,CAAC,OAAO,CAAC,mBAAmB,CACnC,SAAS,EACT,SAAS,EACT,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,EACvF,SAAS,EACT,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAC5D,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC,CACxE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAiB,EAAE,KAAiB;IACxE,OAAO,EAAE,CAAC,OAAO,CAAC,yBAAyB,CACzC,CAAC,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,EAClH,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAC3D,CAAC;AACJ,CAAC","sourcesContent":["import ts, {\n type ArrowFunction,\n type Expression,\n type Identifier,\n type PropertyDeclaration,\n} from '@typescript/typescript6';\nimport type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\n\nexport type Context = Readonly<{\n owner: Plugin;\n}>;\n\nexport const defaultMediaType = 'application/json';\n\nexport function importBuiltInFormModel(specifier: string, { imports, paths }: DependencyManager): Identifier {\n const modelPath = paths.createBareModulePath('@vaadin/hilla-lit-form', false);\n return imports.named.getIdentifier(modelPath, specifier) ?? imports.named.add(modelPath, specifier);\n}\n\nexport function createModelBuildingCallback(name: Identifier, args: readonly Expression[]): ArrowFunction {\n const defaults = [ts.factory.createIdentifier('parent'), ts.factory.createIdentifier('key')];\n\n return ts.factory.createArrowFunction(\n undefined,\n undefined,\n defaults.map((arg) => ts.factory.createParameterDeclaration(undefined, undefined, arg)),\n undefined,\n ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),\n ts.factory.createNewExpression(name, undefined, [...defaults, ...args]),\n );\n}\n\nexport function createEmptyValueMaker(maker: Identifier, model: Identifier): PropertyDeclaration {\n return ts.factory.createPropertyDeclaration(\n [ts.factory.createModifier(ts.SyntaxKind.StaticKeyword), ts.factory.createModifier(ts.SyntaxKind.OverrideKeyword)],\n 'createEmptyValue',\n undefined,\n undefined,\n ts.factory.createCallExpression(maker, undefined, [model]),\n );\n}\n"]}
|