@vaadin/hilla-generator-plugin-model 24.4.0-alpha1
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/.lintstagedrc.js +6 -0
- package/EntityModelProcessor.d.ts +35 -0
- package/EntityModelProcessor.d.ts.map +1 -0
- package/EntityModelProcessor.js +222 -0
- package/EntityModelProcessor.js.map +7 -0
- package/LICENSE +201 -0
- package/MetadataProcessor.d.ts +13 -0
- package/MetadataProcessor.d.ts.map +1 -0
- package/MetadataProcessor.js +38 -0
- package/MetadataProcessor.js.map +7 -0
- package/ModelSchemaProcessor.d.ts +52 -0
- package/ModelSchemaProcessor.d.ts.map +1 -0
- package/ModelSchemaProcessor.js +227 -0
- package/ModelSchemaProcessor.js.map +7 -0
- package/README.md +1 -0
- package/ValidationConstraintProcessor.d.ts +17 -0
- package/ValidationConstraintProcessor.d.ts.map +1 -0
- package/ValidationConstraintProcessor.js +40 -0
- package/ValidationConstraintProcessor.js.map +7 -0
- package/index.d.ts +13 -0
- package/index.d.ts.map +1 -0
- package/index.js +35 -0
- package/index.js.map +7 -0
- package/package.json +83 -0
- package/utils.d.ts +11 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +33 -0
- package/utils.js.map +7 -0
package/.lintstagedrc.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
+
import DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
+
import { type ClassDeclaration, type Identifier, type SourceFile } from 'typescript';
|
|
4
|
+
import { type Context } from './utils.js';
|
|
5
|
+
export type DependencyData = Readonly<{
|
|
6
|
+
id: Identifier;
|
|
7
|
+
path: string;
|
|
8
|
+
}>;
|
|
9
|
+
declare const $dependencies: unique symbol;
|
|
10
|
+
declare const $entity: unique symbol;
|
|
11
|
+
declare const $fullyQualifiedName: unique symbol;
|
|
12
|
+
declare const $model: unique symbol;
|
|
13
|
+
declare const $processDeclaration: unique symbol;
|
|
14
|
+
export declare abstract class EntityModelProcessor {
|
|
15
|
+
#private;
|
|
16
|
+
static process(name: string, component: Schema, context: Context): SourceFile;
|
|
17
|
+
protected readonly [$dependencies]: DependencyManager;
|
|
18
|
+
protected readonly [$entity]: DependencyData;
|
|
19
|
+
protected readonly [$fullyQualifiedName]: string;
|
|
20
|
+
protected readonly [$model]: DependencyData;
|
|
21
|
+
protected constructor(name: string, shouldImportEntityAsType: boolean);
|
|
22
|
+
process(): SourceFile;
|
|
23
|
+
protected abstract [$processDeclaration](): ClassDeclaration | undefined;
|
|
24
|
+
}
|
|
25
|
+
export declare class EntityClassModelProcessor extends EntityModelProcessor {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(name: string, component: Schema, context: Context);
|
|
28
|
+
protected [$processDeclaration](): ClassDeclaration | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare class EntityEnumModelProcessor extends EntityModelProcessor {
|
|
31
|
+
constructor(name: string);
|
|
32
|
+
protected [$processDeclaration](): ClassDeclaration;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=EntityModelProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityModelProcessor.d.ts","sourceRoot":"","sources":["src/EntityModelProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAWL,KAAK,MAAM,EACZ,MAAM,wCAAwC,CAAC;AAMhD,OAAO,iBAAiB,MAAM,iEAAiE,CAAC;AAEhG,OAAW,EACT,KAAK,gBAAgB,EAErB,KAAK,UAAU,EACf,KAAK,UAAU,EAEhB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAA0B,KAAK,OAAO,EAAsD,MAAM,YAAY,CAAC;AAEtH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;IACpC,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAEH,QAA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
|
6
|
+
isComposedSchema,
|
|
7
|
+
isEmptyObject,
|
|
8
|
+
isEnumSchema,
|
|
9
|
+
isObjectSchema,
|
|
10
|
+
isReferenceSchema
|
|
11
|
+
} from "@vaadin/hilla-generator-core/Schema.js";
|
|
12
|
+
import {
|
|
13
|
+
convertFullyQualifiedNameToRelativePath,
|
|
14
|
+
simplifyFullyQualifiedName
|
|
15
|
+
} from "@vaadin/hilla-generator-core/utils.js";
|
|
16
|
+
import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
|
|
17
|
+
import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
|
|
18
|
+
import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
|
|
19
|
+
import ts, {
|
|
20
|
+
} from "typescript";
|
|
21
|
+
import { ModelSchemaExpressionProcessor, ModelSchemaTypeProcessor } from "./ModelSchemaProcessor.js";
|
|
22
|
+
import { importBuiltInFormModel, createModelBuildingCallback, createEmptyValueMaker } from "./utils.js";
|
|
23
|
+
const $dependencies = Symbol();
|
|
24
|
+
const $entity = Symbol();
|
|
25
|
+
const $fullyQualifiedName = Symbol();
|
|
26
|
+
const $model = Symbol();
|
|
27
|
+
const $processDeclaration = Symbol();
|
|
28
|
+
class EntityModelProcessor {
|
|
29
|
+
static process(name, component, context) {
|
|
30
|
+
context.owner.logger.debug(`Processing model for entity: ${name}`);
|
|
31
|
+
const schema = isComposedSchema(component) ? decomposeSchema(component)[0] : component;
|
|
32
|
+
return isEnumSchema(schema) ? (
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
34
|
+
new EntityEnumModelProcessor(name).process()
|
|
35
|
+
) : (
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
37
|
+
new EntityClassModelProcessor(name, component, context).process()
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
[$dependencies];
|
|
41
|
+
[$entity];
|
|
42
|
+
[$fullyQualifiedName];
|
|
43
|
+
[$model];
|
|
44
|
+
#outputPathManager = new PathManager({ extension: "ts" });
|
|
45
|
+
constructor(name, shouldImportEntityAsType) {
|
|
46
|
+
this[$fullyQualifiedName] = name;
|
|
47
|
+
const entityName = simplifyFullyQualifiedName(name);
|
|
48
|
+
const entityPath = convertFullyQualifiedNameToRelativePath(name);
|
|
49
|
+
const modelName = `${entityName}Model`;
|
|
50
|
+
const modelPath = `${entityPath}Model`;
|
|
51
|
+
this[$dependencies] = new DependencyManager(new PathManager({ extension: ".js", relativeTo: dirname(modelPath) }));
|
|
52
|
+
const { exports, imports, paths } = this[$dependencies];
|
|
53
|
+
this[$model] = {
|
|
54
|
+
id: exports.default.set(modelName),
|
|
55
|
+
path: modelPath
|
|
56
|
+
};
|
|
57
|
+
this[$entity] = {
|
|
58
|
+
id: imports.default.add(paths.createRelativePath(entityPath), entityName, shouldImportEntityAsType),
|
|
59
|
+
path: entityPath
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
process() {
|
|
63
|
+
const declaration = this[$processDeclaration]();
|
|
64
|
+
const { exports, imports } = this[$dependencies];
|
|
65
|
+
const importStatements = imports.toCode();
|
|
66
|
+
const exportStatement = exports.toCode();
|
|
67
|
+
return createSourceFile(
|
|
68
|
+
[...importStatements, declaration, ...exportStatement].filter(Boolean),
|
|
69
|
+
this.#outputPathManager.createRelativePath(this[$model].path)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class EntityClassModelProcessor extends EntityModelProcessor {
|
|
74
|
+
#component;
|
|
75
|
+
#context;
|
|
76
|
+
#fullyQualifiedName;
|
|
77
|
+
#getPropertyModelSymbol;
|
|
78
|
+
#makeObjectEmptyValueCreator;
|
|
79
|
+
constructor(name, component, context) {
|
|
80
|
+
super(name, true);
|
|
81
|
+
this.#component = component;
|
|
82
|
+
this.#context = context;
|
|
83
|
+
this.#fullyQualifiedName = name;
|
|
84
|
+
this.#getPropertyModelSymbol = this[$dependencies].imports.named.add("@vaadin/hilla-lit-form", "_getPropertyModel");
|
|
85
|
+
this.#makeObjectEmptyValueCreator = this[$dependencies].imports.named.add(
|
|
86
|
+
"@vaadin/hilla-lit-form",
|
|
87
|
+
"makeObjectEmptyValueCreator"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
[$processDeclaration]() {
|
|
91
|
+
const { logger } = this.#context.owner;
|
|
92
|
+
let entitySchema = this.#component;
|
|
93
|
+
let parent;
|
|
94
|
+
if (isComposedSchema(this.#component)) {
|
|
95
|
+
const decomposed = decomposeSchema(this.#component);
|
|
96
|
+
if (decomposed.length > 2) {
|
|
97
|
+
logger.debug(
|
|
98
|
+
this.#component,
|
|
99
|
+
`The schema for a class component ${this.#fullyQualifiedName} has more than two components. This plugin will ignore it.`
|
|
100
|
+
);
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
const [parentSchema, childSchema] = decomposed;
|
|
104
|
+
if (!isReferenceSchema(parentSchema)) {
|
|
105
|
+
logger.debug(parentSchema, "Only reference schema allowed for parent class");
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
entitySchema = childSchema;
|
|
109
|
+
parent = this.#processParentClass(parentSchema);
|
|
110
|
+
} else {
|
|
111
|
+
parent = importBuiltInFormModel("ObjectModel", this[$dependencies]);
|
|
112
|
+
}
|
|
113
|
+
return this.#processModelClass(entitySchema, this[$entity].id, parent);
|
|
114
|
+
}
|
|
115
|
+
#processClassElements({ properties }) {
|
|
116
|
+
if (!properties) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return Object.entries(properties).map(([name, schema]) => {
|
|
120
|
+
const type = new ModelSchemaTypeProcessor(schema, this[$dependencies]).process();
|
|
121
|
+
const args = new ModelSchemaExpressionProcessor(schema, this[$dependencies]).process();
|
|
122
|
+
return ts.factory.createGetAccessorDeclaration(
|
|
123
|
+
void 0,
|
|
124
|
+
ts.factory.createIdentifier(name),
|
|
125
|
+
[],
|
|
126
|
+
type,
|
|
127
|
+
ts.factory.createBlock(
|
|
128
|
+
[
|
|
129
|
+
ts.factory.createReturnStatement(
|
|
130
|
+
ts.factory.createCallExpression(
|
|
131
|
+
ts.factory.createElementAccessExpression(ts.factory.createThis(), this.#getPropertyModelSymbol),
|
|
132
|
+
void 0,
|
|
133
|
+
[ts.factory.createStringLiteral(name), createModelBuildingCallback(type.typeName, args)]
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
],
|
|
137
|
+
true
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
#processModelClass(schema, entity, parent) {
|
|
143
|
+
const { logger } = this.#context.owner;
|
|
144
|
+
if (!isObjectSchema(schema)) {
|
|
145
|
+
logger.debug(schema, `Component is not an object: ${this.#fullyQualifiedName}`);
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
if (isEmptyObject(schema)) {
|
|
149
|
+
logger.warn(`Component has no properties: ${this.#fullyQualifiedName}`);
|
|
150
|
+
}
|
|
151
|
+
const typeT = ts.factory.createIdentifier("T");
|
|
152
|
+
const modelTypeParameters = ts.factory.createTypeParameterDeclaration(
|
|
153
|
+
void 0,
|
|
154
|
+
typeT,
|
|
155
|
+
ts.factory.createTypeReferenceNode(entity),
|
|
156
|
+
ts.factory.createTypeReferenceNode(entity)
|
|
157
|
+
);
|
|
158
|
+
return ts.factory.createClassDeclaration(
|
|
159
|
+
void 0,
|
|
160
|
+
this[$model].id,
|
|
161
|
+
[modelTypeParameters],
|
|
162
|
+
[
|
|
163
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
164
|
+
ts.factory.createExpressionWithTypeArguments(parent, [ts.factory.createTypeReferenceNode(typeT)])
|
|
165
|
+
])
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
createEmptyValueMaker(this.#makeObjectEmptyValueCreator, this[$model].id),
|
|
169
|
+
...this.#processClassElements(schema)
|
|
170
|
+
]
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
#processParentClass(schema) {
|
|
174
|
+
const { imports, paths } = this[$dependencies];
|
|
175
|
+
const specifier = convertReferenceSchemaToSpecifier(schema);
|
|
176
|
+
const path = convertReferenceSchemaToPath(schema);
|
|
177
|
+
const modelPath = paths.createRelativePath(`${path}Model`);
|
|
178
|
+
const modelSpecifier = `${specifier}Model`;
|
|
179
|
+
return imports.default.add(modelPath, modelSpecifier, false);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
class EntityEnumModelProcessor extends EntityModelProcessor {
|
|
183
|
+
constructor(name) {
|
|
184
|
+
super(name, false);
|
|
185
|
+
}
|
|
186
|
+
[$processDeclaration]() {
|
|
187
|
+
const enumModel = importBuiltInFormModel("EnumModel", this[$dependencies]);
|
|
188
|
+
const enumPropertySymbol = this[$dependencies].imports.named.add("@vaadin/hilla-lit-form", "_enum");
|
|
189
|
+
const makeEnumEmptyValueCreator = this[$dependencies].imports.named.add(
|
|
190
|
+
"@vaadin/hilla-lit-form",
|
|
191
|
+
"makeEnumEmptyValueCreator"
|
|
192
|
+
);
|
|
193
|
+
return ts.factory.createClassDeclaration(
|
|
194
|
+
void 0,
|
|
195
|
+
this[$model].id,
|
|
196
|
+
void 0,
|
|
197
|
+
[
|
|
198
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
199
|
+
ts.factory.createExpressionWithTypeArguments(enumModel, [
|
|
200
|
+
ts.factory.createTypeQueryNode(this[$entity].id, void 0)
|
|
201
|
+
])
|
|
202
|
+
])
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
createEmptyValueMaker(makeEnumEmptyValueCreator, this[$model].id),
|
|
206
|
+
ts.factory.createPropertyDeclaration(
|
|
207
|
+
[ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)],
|
|
208
|
+
ts.factory.createComputedPropertyName(enumPropertySymbol),
|
|
209
|
+
void 0,
|
|
210
|
+
void 0,
|
|
211
|
+
this[$entity].id
|
|
212
|
+
)
|
|
213
|
+
]
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
EntityClassModelProcessor,
|
|
219
|
+
EntityEnumModelProcessor,
|
|
220
|
+
EntityModelProcessor
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=EntityModelProcessor.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/EntityModelProcessor.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable symbol-description */\nimport { dirname } from 'path/posix';\nimport {\n convertReferenceSchemaToPath,\n convertReferenceSchemaToSpecifier,\n decomposeSchema,\n isComposedSchema,\n isEmptyObject,\n isEnumSchema,\n isObjectSchema,\n isReferenceSchema,\n type ObjectSchema,\n type ReferenceSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport {\n convertFullyQualifiedNameToRelativePath,\n simplifyFullyQualifiedName,\n} from '@vaadin/hilla-generator-core/utils.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, {\n type ClassDeclaration,\n type ClassElement,\n type Identifier,\n type SourceFile,\n type Statement,\n} from 'typescript';\nimport { ModelSchemaExpressionProcessor, ModelSchemaTypeProcessor } from './ModelSchemaProcessor.js';\nimport { importBuiltInFormModel, type Context, createModelBuildingCallback, createEmptyValueMaker } 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 if (isEmptyObject(schema)) {\n logger.warn(`Component has no properties: ${this.#fullyQualifiedName}`);\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.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
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
+
import { type ObjectLiteralExpression } from 'typescript';
|
|
3
|
+
interface Annotation {
|
|
4
|
+
name: string;
|
|
5
|
+
attributes?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export type SchemaWithMetadata = Schema & {
|
|
8
|
+
'x-annotations'?: Annotation[];
|
|
9
|
+
'x-java-type'?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function process(schema: Schema): ObjectLiteralExpression | null;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=MetadataProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataProcessor.d.ts","sourceRoot":"","sources":["src/MetadataProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAW,EAAE,KAAK,uBAAuB,EAA2B,MAAM,YAAY,CAAC;AAEvF,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG;IACxC,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA8BF,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CAYtE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ts, {} from "typescript";
|
|
2
|
+
function createAnnotationsProperty(schema) {
|
|
3
|
+
const annotations = schema["x-annotations"];
|
|
4
|
+
const hasAnnotations = annotations && annotations.length > 0;
|
|
5
|
+
if (!hasAnnotations) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const annotationLiterals = annotations.map(
|
|
9
|
+
(annotation) => ts.factory.createObjectLiteralExpression([
|
|
10
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(annotation.name))
|
|
11
|
+
])
|
|
12
|
+
);
|
|
13
|
+
return ts.factory.createPropertyAssignment(
|
|
14
|
+
"annotations",
|
|
15
|
+
ts.factory.createArrayLiteralExpression(annotationLiterals)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function createJavaTypeProperty(schema) {
|
|
19
|
+
const javaType = schema["x-java-type"];
|
|
20
|
+
if (!javaType) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return ts.factory.createPropertyAssignment("javaType", ts.factory.createStringLiteral(javaType));
|
|
24
|
+
}
|
|
25
|
+
function process(schema) {
|
|
26
|
+
const schemaWithMetadata = schema;
|
|
27
|
+
const properties = [createAnnotationsProperty(schemaWithMetadata), createJavaTypeProperty(schemaWithMetadata)].filter(
|
|
28
|
+
Boolean
|
|
29
|
+
);
|
|
30
|
+
if (properties.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return ts.factory.createObjectLiteralExpression(properties);
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
process
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=MetadataProcessor.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/MetadataProcessor.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Schema } from '@vaadin/hilla-generator-core/Schema.js';\nimport ts, { type ObjectLiteralExpression, type PropertyAssignment } from 'typescript';\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"],
|
|
5
|
+
"mappings": "AACA,OAAO,YAAmE;AAY1E,SAAS,0BAA0B,QAAuD;AACxF,QAAM,cAAc,OAAO,eAAe;AAC1C,QAAM,iBAAiB,eAAe,YAAY,SAAS;AAC3D,MAAI,CAAC,gBAAgB;AACnB,WAAO;AAAA,EACT;AAEA,QAAM,qBAAqB,YAAY;AAAA,IAAI,CAAC,eAC1C,GAAG,QAAQ,8BAA8B;AAAA,MACvC,GAAG,QAAQ,yBAAyB,QAAQ,GAAG,QAAQ,oBAAoB,WAAW,IAAI,CAAC;AAAA,IAC7F,CAAC;AAAA,EACH;AAEA,SAAO,GAAG,QAAQ;AAAA,IAChB;AAAA,IACA,GAAG,QAAQ,6BAA6B,kBAAkB;AAAA,EAC5D;AACF;AAEA,SAAS,uBAAuB,QAAuD;AACrF,QAAM,WAAW,OAAO,aAAa;AACrC,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,QAAQ,yBAAyB,YAAY,GAAG,QAAQ,oBAAoB,QAAQ,CAAC;AACjG;AAEO,SAAS,QAAQ,QAAgD;AACtE,QAAM,qBAAqB;AAE3B,QAAM,aAAa,CAAC,0BAA0B,kBAAkB,GAAG,uBAAuB,kBAAkB,CAAC,EAAE;AAAA,IAC7G;AAAA,EACF;AAEA,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,QAAQ,8BAA8B,UAAU;AAC5D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
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
|
+
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
+
import ts, { type Expression, type TypeReferenceNode } from 'typescript';
|
|
4
|
+
declare const $dependencies: unique symbol;
|
|
5
|
+
declare const $processArray: unique symbol;
|
|
6
|
+
declare const $processRecord: unique symbol;
|
|
7
|
+
declare const $processReference: unique symbol;
|
|
8
|
+
declare const $processString: unique symbol;
|
|
9
|
+
declare const $processNumber: unique symbol;
|
|
10
|
+
declare const $processBoolean: unique symbol;
|
|
11
|
+
declare const $processUnknown: unique symbol;
|
|
12
|
+
declare const $originalSchema: unique symbol;
|
|
13
|
+
declare const $schema: unique symbol;
|
|
14
|
+
export declare abstract class ModelSchemaPartProcessor<T> {
|
|
15
|
+
protected readonly [$dependencies]: DependencyManager;
|
|
16
|
+
protected readonly [$originalSchema]: Schema;
|
|
17
|
+
protected readonly [$schema]: Schema;
|
|
18
|
+
constructor(schema: Schema, dependencies: DependencyManager);
|
|
19
|
+
process(): T;
|
|
20
|
+
protected abstract [$processArray](schema: ArraySchema): T;
|
|
21
|
+
protected abstract [$processBoolean](schema: BooleanSchema): T;
|
|
22
|
+
protected abstract [$processNumber](schema: IntegerSchema | NumberSchema): T;
|
|
23
|
+
protected abstract [$processRecord](schema: MapSchema): T;
|
|
24
|
+
protected abstract [$processReference](schema: ReferenceSchema): T;
|
|
25
|
+
protected abstract [$processString](schema: StringSchema): T;
|
|
26
|
+
protected abstract [$processUnknown](schema: Schema): T;
|
|
27
|
+
}
|
|
28
|
+
export declare class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor<TypeReferenceNode> {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(schema: Schema, dependencies: DependencyManager);
|
|
31
|
+
protected [$processArray](schema: ArraySchema): TypeReferenceNode;
|
|
32
|
+
protected [$processBoolean](schema: BooleanSchema): TypeReferenceNode;
|
|
33
|
+
protected [$processNumber](schema: IntegerSchema | NumberSchema): TypeReferenceNode;
|
|
34
|
+
protected [$processRecord](schema: MapSchema): TypeReferenceNode;
|
|
35
|
+
protected [$processReference](schema: ReferenceSchema): TypeReferenceNode;
|
|
36
|
+
protected [$processString](schema: StringSchema): TypeReferenceNode;
|
|
37
|
+
protected [$processUnknown](schema: Schema): TypeReferenceNode;
|
|
38
|
+
}
|
|
39
|
+
export declare class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor<readonly Expression[]> {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(schema: Schema, dependencies: DependencyManager);
|
|
42
|
+
process(): readonly ts.Expression[];
|
|
43
|
+
protected [$processArray](schema: ArraySchema): readonly Expression[];
|
|
44
|
+
protected [$processBoolean](_: BooleanSchema): readonly Expression[];
|
|
45
|
+
protected [$processNumber](_: IntegerSchema | NumberSchema): readonly Expression[];
|
|
46
|
+
protected [$processRecord](_: MapSchema): readonly Expression[];
|
|
47
|
+
protected [$processReference](_: ReferenceSchema): readonly Expression[];
|
|
48
|
+
protected [$processString](_: StringSchema): readonly Expression[];
|
|
49
|
+
protected [$processUnknown](_: Schema): readonly Expression[];
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52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EAAE,YAAY,EAAE,iBAAiB;IAOlD,OAAO,IAAI,SAAS,EAAE,CAAC,UAAU,EAAE;cAmBzB,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,UAAU,EAAE;cAW3D,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,aAAa,GAAG,SAAS,UAAU,EAAE;cAI1D,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,UAAU,EAAE;cAIxE,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,UAAU,EAAE;cAIrD,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,eAAe,GAAG,SAAS,UAAU,EAAE;cAI9D,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,YAAY,GAAG,SAAS,UAAU,EAAE;cAIxD,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE;CAmBvE"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
convertReferenceSchemaToPath,
|
|
3
|
+
convertReferenceSchemaToSpecifier,
|
|
4
|
+
decomposeSchema,
|
|
5
|
+
isArraySchema,
|
|
6
|
+
isBooleanSchema,
|
|
7
|
+
isComposedSchema,
|
|
8
|
+
isIntegerSchema,
|
|
9
|
+
isMapSchema,
|
|
10
|
+
isNullableSchema,
|
|
11
|
+
isNumberSchema,
|
|
12
|
+
isReferenceSchema,
|
|
13
|
+
isStringSchema
|
|
14
|
+
} from "@vaadin/hilla-generator-core/Schema.js";
|
|
15
|
+
import ts, {
|
|
16
|
+
} from "typescript";
|
|
17
|
+
import { process } from "./MetadataProcessor.js";
|
|
18
|
+
import { createModelBuildingCallback, importBuiltInFormModel } from "./utils.js";
|
|
19
|
+
import { hasValidationConstraints, ValidationConstraintProcessor } from "./ValidationConstraintProcessor.js";
|
|
20
|
+
const $dependencies = Symbol();
|
|
21
|
+
const $processArray = Symbol();
|
|
22
|
+
const $processRecord = Symbol();
|
|
23
|
+
const $processReference = Symbol();
|
|
24
|
+
const $processString = Symbol();
|
|
25
|
+
const $processNumber = Symbol();
|
|
26
|
+
const $processBoolean = Symbol();
|
|
27
|
+
const $processUnknown = Symbol();
|
|
28
|
+
const $originalSchema = Symbol();
|
|
29
|
+
const $schema = Symbol();
|
|
30
|
+
class ModelSchemaPartProcessor {
|
|
31
|
+
[$dependencies];
|
|
32
|
+
[$originalSchema];
|
|
33
|
+
[$schema];
|
|
34
|
+
constructor(schema, dependencies) {
|
|
35
|
+
this[$dependencies] = dependencies;
|
|
36
|
+
this[$originalSchema] = schema;
|
|
37
|
+
this[$schema] = isComposedSchema(schema) ? decomposeSchema(schema)[0] : schema;
|
|
38
|
+
}
|
|
39
|
+
process() {
|
|
40
|
+
const schema = this[$schema];
|
|
41
|
+
if (isReferenceSchema(schema)) {
|
|
42
|
+
return this[$processReference](schema);
|
|
43
|
+
}
|
|
44
|
+
if (isArraySchema(schema)) {
|
|
45
|
+
return this[$processArray](schema);
|
|
46
|
+
}
|
|
47
|
+
if (isMapSchema(schema)) {
|
|
48
|
+
return this[$processRecord](schema);
|
|
49
|
+
}
|
|
50
|
+
if (isStringSchema(schema)) {
|
|
51
|
+
return this[$processString](schema);
|
|
52
|
+
}
|
|
53
|
+
if (isNumberSchema(schema) || isIntegerSchema(schema)) {
|
|
54
|
+
return this[$processNumber](schema);
|
|
55
|
+
}
|
|
56
|
+
if (isBooleanSchema(schema)) {
|
|
57
|
+
return this[$processBoolean](schema);
|
|
58
|
+
}
|
|
59
|
+
return this[$processUnknown](schema);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function handleNullableInternalType(schema, typeNode) {
|
|
63
|
+
return isNullableSchema(schema) ? ts.factory.createUnionTypeNode([typeNode, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)]) : typeNode;
|
|
64
|
+
}
|
|
65
|
+
class ModelSchemaInternalTypeProcessor extends ModelSchemaPartProcessor {
|
|
66
|
+
[$processArray](schema) {
|
|
67
|
+
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("ReadonlyArray"), [
|
|
68
|
+
handleNullableInternalType(
|
|
69
|
+
schema.items,
|
|
70
|
+
new ModelSchemaInternalTypeProcessor(schema.items, this[$dependencies]).process()
|
|
71
|
+
)
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
[$processBoolean](_) {
|
|
75
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);
|
|
76
|
+
}
|
|
77
|
+
[$processNumber](_) {
|
|
78
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
79
|
+
}
|
|
80
|
+
[$processRecord]({ additionalProperties: props }) {
|
|
81
|
+
const valueType = typeof props === "boolean" ? ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword) : handleNullableInternalType(props, new ModelSchemaInternalTypeProcessor(props, this[$dependencies]).process());
|
|
82
|
+
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Record"), [
|
|
83
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
84
|
+
valueType
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
[$processReference](schema) {
|
|
88
|
+
const { imports, paths } = this[$dependencies];
|
|
89
|
+
const typeName = convertReferenceSchemaToSpecifier(schema);
|
|
90
|
+
const typePath = paths.createRelativePath(convertReferenceSchemaToPath(schema));
|
|
91
|
+
return ts.factory.createTypeReferenceNode(
|
|
92
|
+
imports.default.getIdentifier(typePath) ?? imports.default.add(typePath, typeName, true)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
[$processString](_) {
|
|
96
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
|
|
97
|
+
}
|
|
98
|
+
[$processUnknown](_) {
|
|
99
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class ModelSchemaIdentifierProcessor extends ModelSchemaPartProcessor {
|
|
103
|
+
[$processArray](_) {
|
|
104
|
+
return importBuiltInFormModel("ArrayModel", this[$dependencies]);
|
|
105
|
+
}
|
|
106
|
+
[$processBoolean](_) {
|
|
107
|
+
return importBuiltInFormModel("BooleanModel", this[$dependencies]);
|
|
108
|
+
}
|
|
109
|
+
[$processNumber](_) {
|
|
110
|
+
return importBuiltInFormModel("NumberModel", this[$dependencies]);
|
|
111
|
+
}
|
|
112
|
+
[$processRecord](_) {
|
|
113
|
+
return importBuiltInFormModel("ObjectModel", this[$dependencies]);
|
|
114
|
+
}
|
|
115
|
+
[$processReference](schema) {
|
|
116
|
+
const { imports, paths } = this[$dependencies];
|
|
117
|
+
const name = `${convertReferenceSchemaToSpecifier(schema)}Model`;
|
|
118
|
+
const path = paths.createRelativePath(`${convertReferenceSchemaToPath(schema)}Model`);
|
|
119
|
+
return imports.default.getIdentifier(path) ?? imports.default.add(path, name);
|
|
120
|
+
}
|
|
121
|
+
[$processString](_) {
|
|
122
|
+
return importBuiltInFormModel("StringModel", this[$dependencies]);
|
|
123
|
+
}
|
|
124
|
+
[$processUnknown](_) {
|
|
125
|
+
return importBuiltInFormModel("ObjectModel", this[$dependencies]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor {
|
|
129
|
+
#id;
|
|
130
|
+
constructor(schema, dependencies) {
|
|
131
|
+
super(schema, dependencies);
|
|
132
|
+
this.#id = new ModelSchemaIdentifierProcessor(schema, dependencies);
|
|
133
|
+
}
|
|
134
|
+
[$processArray](schema) {
|
|
135
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processArray](schema), [
|
|
136
|
+
new ModelSchemaTypeProcessor(schema.items, this[$dependencies]).process()
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
[$processBoolean](schema) {
|
|
140
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processBoolean](schema));
|
|
141
|
+
}
|
|
142
|
+
[$processNumber](schema) {
|
|
143
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processNumber](schema));
|
|
144
|
+
}
|
|
145
|
+
[$processRecord](schema) {
|
|
146
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processRecord](schema), [
|
|
147
|
+
new ModelSchemaInternalTypeProcessor(schema, this[$dependencies]).process()
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
[$processReference](schema) {
|
|
151
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processReference](schema));
|
|
152
|
+
}
|
|
153
|
+
[$processString](schema) {
|
|
154
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processString](schema));
|
|
155
|
+
}
|
|
156
|
+
[$processUnknown](schema) {
|
|
157
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processUnknown](schema));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor {
|
|
161
|
+
#validationConstraintProcessor;
|
|
162
|
+
constructor(schema, dependencies) {
|
|
163
|
+
super(schema, dependencies);
|
|
164
|
+
this.#validationConstraintProcessor = new ValidationConstraintProcessor(
|
|
165
|
+
(name) => importBuiltInFormModel(name, dependencies)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
process() {
|
|
169
|
+
const originalSchema = this[$originalSchema];
|
|
170
|
+
let result = super.process();
|
|
171
|
+
const modelOptionsProperties = [
|
|
172
|
+
this.#createValidatorsProperty(originalSchema),
|
|
173
|
+
ModelSchemaExpressionProcessor.#createMetadataProperty(originalSchema)
|
|
174
|
+
].filter(Boolean);
|
|
175
|
+
if (modelOptionsProperties.length > 0) {
|
|
176
|
+
const optionsObject = ts.factory.createObjectLiteralExpression(modelOptionsProperties);
|
|
177
|
+
result = [...result, optionsObject];
|
|
178
|
+
}
|
|
179
|
+
return [isNullableSchema(originalSchema) ? ts.factory.createTrue() : ts.factory.createFalse(), ...result];
|
|
180
|
+
}
|
|
181
|
+
[$processArray](schema) {
|
|
182
|
+
const model = new ModelSchemaIdentifierProcessor(schema.items, this[$dependencies]).process();
|
|
183
|
+
return [
|
|
184
|
+
createModelBuildingCallback(
|
|
185
|
+
model,
|
|
186
|
+
new ModelSchemaExpressionProcessor(schema.items, this[$dependencies]).process()
|
|
187
|
+
)
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
[$processBoolean](_) {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
[$processNumber](_) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
[$processRecord](_) {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
[$processReference](_) {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
[$processString](_) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
[$processUnknown](_) {
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
#createValidatorsProperty(schema) {
|
|
209
|
+
if (!hasValidationConstraints(schema)) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
const constraints = schema["x-validation-constraints"].map(
|
|
213
|
+
(constraint) => this.#validationConstraintProcessor.process(constraint)
|
|
214
|
+
);
|
|
215
|
+
return ts.factory.createPropertyAssignment("validators", ts.factory.createArrayLiteralExpression(constraints));
|
|
216
|
+
}
|
|
217
|
+
static #createMetadataProperty(schema) {
|
|
218
|
+
const metadata = process(schema);
|
|
219
|
+
return metadata ? ts.factory.createPropertyAssignment("meta", metadata) : null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
ModelSchemaExpressionProcessor,
|
|
224
|
+
ModelSchemaPartProcessor,
|
|
225
|
+
ModelSchemaTypeProcessor
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=ModelSchemaProcessor.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/ModelSchemaProcessor.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAEP,OAAO;AAAA,OAMA;AACP,SAAS,eAAe;AACxB,SAAS,6BAA6B,8BAA8B;AACpE,SAAS,0BAA0B,qCAAqC;AAExE,MAAM,gBAAgB,OAAO;AAC7B,MAAM,gBAAgB,OAAO;AAC7B,MAAM,iBAAiB,OAAO;AAC9B,MAAM,oBAAoB,OAAO;AACjC,MAAM,iBAAiB,OAAO;AAC9B,MAAM,iBAAiB,OAAO;AAC9B,MAAM,kBAAkB,OAAO;AAC/B,MAAM,kBAAkB,OAAO;AAC/B,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AA2C;AACxE,UAAM,WAAW,QAAQ,MAAM;AAC/B,WAAO,WAAW,GAAG,QAAQ,yBAAyB,QAAQ,QAAQ,IAAI;AAAA,EAC5E;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Hilla TypeScript Generator Backbone Plugin
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type NonComposedRegularSchema, type Schema } from '@vaadin/hilla-generator-core/Schema.js';
|
|
2
|
+
import { type Identifier, type NewExpression } from 'typescript';
|
|
3
|
+
export type ValidationConstrainedSchema = NonComposedRegularSchema & Readonly<{
|
|
4
|
+
'x-validation-constraints': readonly ValidationConstraint[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare function hasValidationConstraints(schema: Schema): schema is ValidationConstrainedSchema;
|
|
7
|
+
export interface ValidationConstraint {
|
|
8
|
+
simpleName: string;
|
|
9
|
+
attributes?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export type ValidationConstraintImporter = (name: string) => Identifier;
|
|
12
|
+
export declare class ValidationConstraintProcessor {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(importer: ValidationConstraintImporter);
|
|
15
|
+
process(constraint: ValidationConstraint): NewExpression;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ValidationConstraintProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationConstraintProcessor.d.ts","sourceRoot":"","sources":["src/ValidationConstraintProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,MAAM,EACZ,MAAM,wCAAwC,CAAC;AAEhD,OAAW,EAET,KAAK,UAAU,EACf,KAAK,aAAa,EAGnB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,GAChE,QAAQ,CAAC;IAAE,0BAA0B,EAAE,SAAS,oBAAoB,EAAE,CAAA;CAAE,CAAC,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,2BAA2B,CAM9F;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,MAAM,4BAA4B,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAAC;AAQxE,qBAAa,6BAA6B;;gBAG5B,QAAQ,EAAE,4BAA4B;IAIlD,OAAO,CAAC,UAAU,EAAE,oBAAoB,GAAG,aAAa;CAoBzD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isNonComposedRegularSchema
|
|
3
|
+
} from "@vaadin/hilla-generator-core/Schema.js";
|
|
4
|
+
import { template, transform } from "@vaadin/hilla-generator-utils/ast.js";
|
|
5
|
+
import ts, {
|
|
6
|
+
} from "typescript";
|
|
7
|
+
function hasValidationConstraints(schema) {
|
|
8
|
+
return isNonComposedRegularSchema(schema) && "x-validation-constraints" in schema && schema["x-validation-constraints"].length > 0;
|
|
9
|
+
}
|
|
10
|
+
function selector([statement]) {
|
|
11
|
+
return statement.declarationList.declarations[0].initializer;
|
|
12
|
+
}
|
|
13
|
+
const variableStatementVar = "const a";
|
|
14
|
+
class ValidationConstraintProcessor {
|
|
15
|
+
#importer;
|
|
16
|
+
constructor(importer) {
|
|
17
|
+
this.#importer = importer;
|
|
18
|
+
}
|
|
19
|
+
process(constraint) {
|
|
20
|
+
return ts.factory.createNewExpression(
|
|
21
|
+
this.#importer(constraint.simpleName),
|
|
22
|
+
void 0,
|
|
23
|
+
constraint.attributes ? [ValidationConstraintProcessor.#processAttributes(constraint.attributes)] : []
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
static #processAttributes(attributes) {
|
|
27
|
+
const names = Object.keys(attributes);
|
|
28
|
+
const tpl = JSON.stringify(names.includes("value") && names.length === 1 ? attributes.value : attributes);
|
|
29
|
+
return template(`${variableStatementVar}=${tpl}`, selector, [
|
|
30
|
+
transform(
|
|
31
|
+
(node) => ts.isPropertyAssignment(node) && ts.isStringLiteral(node.name) ? ts.factory.createPropertyAssignment(node.name.text, node.initializer) : node
|
|
32
|
+
)
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
ValidationConstraintProcessor,
|
|
38
|
+
hasValidationConstraints
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=ValidationConstraintProcessor.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/ValidationConstraintProcessor.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n isNonComposedRegularSchema,\n type NonComposedRegularSchema,\n type Schema,\n} from '@vaadin/hilla-generator-core/Schema.js';\nimport { template, transform } from '@vaadin/hilla-generator-utils/ast.js';\nimport ts, {\n type Expression,\n type Identifier,\n type NewExpression,\n type Statement,\n type VariableStatement,\n} from 'typescript';\n\nexport type ValidationConstrainedSchema = NonComposedRegularSchema &\n Readonly<{ 'x-validation-constraints': readonly ValidationConstraint[] }>;\n\nexport function hasValidationConstraints(schema: Schema): schema is ValidationConstrainedSchema {\n return (\n isNonComposedRegularSchema(schema) &&\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"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,UAAU,iBAAiB;AACpC,OAAO;AAAA,OAMA;AAKA,SAAS,yBAAyB,QAAuD;AAC9F,SACE,2BAA2B,MAAM,KACjC,8BAA8B,UAC7B,OAAuC,0BAA0B,EAAE,SAAS;AAEjF;AASA,SAAS,SAA+B,CAAC,SAAS,GAA4B;AAC5E,SAAQ,UAAgC,gBAAgB,aAAa,CAAC,EAAE;AAC1E;AAEA,MAAM,uBAAuB;AAEtB,MAAM,8BAA8B;AAAA,EAChC;AAAA,EAET,YAAY,UAAwC;AAClD,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,QAAQ,YAAiD;AACvD,WAAO,GAAG,QAAQ;AAAA,MAChB,KAAK,UAAU,WAAW,UAAU;AAAA,MACpC;AAAA,MACA,WAAW,aAAa,CAAC,8BAA8B,mBAAmB,WAAW,UAAU,CAAC,IAAI,CAAC;AAAA,IACvG;AAAA,EACF;AAAA,EAEA,OAAO,mBAAmB,YAAiD;AACzE,UAAM,QAAQ,OAAO,KAAK,UAAU;AACpC,UAAM,MAAM,KAAK,UAAU,MAAM,SAAS,OAAO,KAAK,MAAM,WAAW,IAAI,WAAW,QAAQ,UAAU;AAExG,WAAO,SAAS,GAAG,oBAAoB,IAAI,GAAG,IAAI,UAAU;AAAA,MAC1D;AAAA,QAAU,CAAC,SACT,GAAG,qBAAqB,IAAI,KAAK,GAAG,gBAAgB,KAAK,IAAI,IACzD,GAAG,QAAQ,yBAAyB,KAAK,KAAK,MAAM,KAAK,WAAW,IACpE;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
|
+
export declare enum ModelPluginSourceType {
|
|
4
|
+
Model = "model"
|
|
5
|
+
}
|
|
6
|
+
export default class ModelPlugin extends Plugin {
|
|
7
|
+
#private;
|
|
8
|
+
static readonly MODEL_PLUGIN_FILE_TAGS = "MODEL_PLUGIN_FILE_TAGS";
|
|
9
|
+
['constructor']: typeof ModelPlugin;
|
|
10
|
+
get path(): string;
|
|
11
|
+
execute(storage: SharedStorage): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wCAAwC,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,+CAA+C,CAAC;AAO/E,oBAAY,qBAAqB;IAC/B,KAAK,UAAU;CAChB;AAED,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,MAAM;;IAC7C,MAAM,CAAC,QAAQ,CAAC,sBAAsB,4BAA4B;IAC1D,CAAC,aAAa,CAAC,EAAE,OAAO,WAAW,CAAC;IAG5C,IAAa,IAAI,IAAI,MAAM,CAE1B;IAGc,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB9D"}
|
package/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Plugin from "@vaadin/hilla-generator-core/Plugin.js";
|
|
2
|
+
import { EntityModelProcessor } from "./EntityModelProcessor.js";
|
|
3
|
+
var ModelPluginSourceType = /* @__PURE__ */ ((ModelPluginSourceType2) => {
|
|
4
|
+
ModelPluginSourceType2["Model"] = "model";
|
|
5
|
+
return ModelPluginSourceType2;
|
|
6
|
+
})(ModelPluginSourceType || {});
|
|
7
|
+
class ModelPlugin extends Plugin {
|
|
8
|
+
static MODEL_PLUGIN_FILE_TAGS = "MODEL_PLUGIN_FILE_TAGS";
|
|
9
|
+
#tags = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
get path() {
|
|
11
|
+
return import.meta.url;
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
14
|
+
async execute(storage) {
|
|
15
|
+
const files = this.#processEntities(storage.api.components?.schemas);
|
|
16
|
+
files.forEach((file) => this.#tags.set(file, "model" /* Model */));
|
|
17
|
+
storage.sources.push(...files);
|
|
18
|
+
storage.pluginStorage.set(this.constructor.MODEL_PLUGIN_FILE_TAGS, this.#tags);
|
|
19
|
+
}
|
|
20
|
+
#processEntities(schemas) {
|
|
21
|
+
this.logger.debug("Processing entities");
|
|
22
|
+
if (!schemas) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const ctx = {
|
|
26
|
+
owner: this
|
|
27
|
+
};
|
|
28
|
+
return Object.entries(schemas).map(([name, component]) => EntityModelProcessor.process(name, component, ctx));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
ModelPluginSourceType,
|
|
33
|
+
ModelPlugin as default
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import 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 type { ReadonlyDeep } from 'type-fest';\nimport type { SourceFile } from 'typescript';\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: ReadonlyDeep<OpenAPIV3.ComponentsObject>['schemas'] | undefined): 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"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAY;AAKnB,SAAS,4BAA4B;AAG9B,IAAK,wBAAL,kBAAKA,2BAAL;AACL,EAAAA,uBAAA,WAAQ;AADE,SAAAA;AAAA,GAAA;AAIZ,MAAO,oBAAkC,OAAO;AAAA,EAC9C,OAAgB,yBAAyB;AAAA,EAEhC,QAAQ,oBAAI,QAA2C;AAAA,EAEhE,IAAa,OAAe;AAC1B,WAAO,YAAY;AAAA,EACrB;AAAA;AAAA,EAGA,MAAe,QAAQ,SAAuC;AAC5D,UAAM,QAAQ,KAAK,iBAAiB,QAAQ,IAAI,YAAY,OAAO;AACnE,UAAM,QAAQ,CAAC,SAAS,KAAK,MAAM,IAAI,MAAM,mBAA2B,CAAC;AACzE,YAAQ,QAAQ,KAAK,GAAG,KAAK;AAC7B,YAAQ,cAAc,IAAI,KAAK,YAAY,wBAAwB,KAAK,KAAK;AAAA,EAC/E;AAAA,EAEA,iBAAiB,SAAiG;AAChH,SAAK,OAAO,MAAM,qBAAqB;AAEvC,QAAI,CAAC,SAAS;AACZ,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,MAAe;AAAA,MACnB,OAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,SAAS,MAAM,qBAAqB,QAAQ,MAAM,WAAW,GAAG,CAAC;AAAA,EAC9G;AACF;",
|
|
6
|
+
"names": ["ModelPluginSourceType"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vaadin/hilla-generator-plugin-model",
|
|
3
|
+
"version": "24.4.0-alpha1",
|
|
4
|
+
"description": "A Hilla TypeScript Generator plugin to generate form models",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">= 16.13"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean:build": "git clean -fx . -e .vite -e node_modules",
|
|
12
|
+
"build": "concurrently npm:build:*",
|
|
13
|
+
"build:esbuild": "tsx ../../../scripts/build.ts",
|
|
14
|
+
"build:dts": "tsc --isolatedModules -p tsconfig.build.json",
|
|
15
|
+
"build:copy": "cd src && copyfiles **/*.d.ts ..",
|
|
16
|
+
"lint": "eslint src test",
|
|
17
|
+
"lint:fix": "eslint src test --fix",
|
|
18
|
+
"test": "mocha test/**/*.spec.ts --config ../../../.mocharc.cjs",
|
|
19
|
+
"test:update": "npm run test -- --update",
|
|
20
|
+
"test:coverage": "c8 -c ../../../.c8rc.json npm test",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"default": "./index.js"
|
|
26
|
+
},
|
|
27
|
+
"./index.js": {
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/vaadin/hilla.git",
|
|
34
|
+
"directory": "packages/ts/generator-plugin-model"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"hilla",
|
|
38
|
+
"typescript",
|
|
39
|
+
"generator"
|
|
40
|
+
],
|
|
41
|
+
"author": "Vaadin Ltd.",
|
|
42
|
+
"license": "Apache 2.0",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/vaadin/hilla/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://hilla.dev",
|
|
47
|
+
"files": [
|
|
48
|
+
"*.{d.ts.map,d.ts,js.map,js}"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@vaadin/hilla-lit-form": "24.4.0-alpha1",
|
|
55
|
+
"@vaadin/hilla-generator-core": "24.4.0-alpha1",
|
|
56
|
+
"@vaadin/hilla-generator-plugin-backbone": "24.4.0-alpha1"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@vaadin/hilla-generator-utils": "24.4.0-alpha1",
|
|
60
|
+
"fast-deep-equal": "^3.1.3",
|
|
61
|
+
"openapi-types": "^12.1.3",
|
|
62
|
+
"typescript": "5.3.2"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@vaadin/hilla-generator-core": "24.4.0-alpha1",
|
|
66
|
+
"@vaadin/hilla-generator-plugin-client": "24.4.0-alpha1",
|
|
67
|
+
"@types/chai": "^4.3.6",
|
|
68
|
+
"@types/mocha": "^10.0.2",
|
|
69
|
+
"@types/node": "^20.7.1",
|
|
70
|
+
"@types/sinon": "^10.0.17",
|
|
71
|
+
"@types/sinon-chai": "^3.2.10",
|
|
72
|
+
"c8": "^8.0.1",
|
|
73
|
+
"chai": "^4.3.10",
|
|
74
|
+
"concurrently": "^8.2.1",
|
|
75
|
+
"copyfiles": "^2.4.1",
|
|
76
|
+
"mocha": "^10.2.0",
|
|
77
|
+
"pino": "^8.15.1",
|
|
78
|
+
"rimraf": "^5.0.5",
|
|
79
|
+
"sinon": "^16.0.0",
|
|
80
|
+
"sinon-chai": "^3.7.0",
|
|
81
|
+
"type-fest": "^4.3.2"
|
|
82
|
+
}
|
|
83
|
+
}
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
+
import type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';
|
|
3
|
+
import { type ArrowFunction, type Expression, type Identifier, type PropertyDeclaration } from 'typescript';
|
|
4
|
+
export type Context = Readonly<{
|
|
5
|
+
owner: Plugin;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const defaultMediaType = "application/json";
|
|
8
|
+
export declare function importBuiltInFormModel(specifier: string, { imports, paths }: DependencyManager): Identifier;
|
|
9
|
+
export declare function createModelBuildingCallback(name: Identifier, args: readonly Expression[]): ArrowFunction;
|
|
10
|
+
export declare function createEmptyValueMaker(maker: Identifier, model: Identifier): PropertyDeclaration;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/utils.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,wCAAwC,CAAC;AACjE,OAAO,KAAK,iBAAiB,MAAM,iEAAiE,CAAC;AACrG,OAAW,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhH,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,iBAAiB,GAAG,UAAU,CAG3G;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,aAAa,CAWxG;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,mBAAmB,CAQ/F"}
|
package/utils.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts, {} from "typescript";
|
|
2
|
+
const defaultMediaType = "application/json";
|
|
3
|
+
function importBuiltInFormModel(specifier, { imports, paths }) {
|
|
4
|
+
const modelPath = paths.createBareModulePath("@vaadin/hilla-lit-form", false);
|
|
5
|
+
return imports.named.getIdentifier(modelPath, specifier) ?? imports.named.add(modelPath, specifier);
|
|
6
|
+
}
|
|
7
|
+
function createModelBuildingCallback(name, args) {
|
|
8
|
+
const defaults = [ts.factory.createIdentifier("parent"), ts.factory.createIdentifier("key")];
|
|
9
|
+
return ts.factory.createArrowFunction(
|
|
10
|
+
void 0,
|
|
11
|
+
void 0,
|
|
12
|
+
defaults.map((arg) => ts.factory.createParameterDeclaration(void 0, void 0, arg)),
|
|
13
|
+
void 0,
|
|
14
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
|
|
15
|
+
ts.factory.createNewExpression(name, void 0, [...defaults, ...args])
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function createEmptyValueMaker(maker, model) {
|
|
19
|
+
return ts.factory.createPropertyDeclaration(
|
|
20
|
+
[ts.factory.createModifier(ts.SyntaxKind.StaticKeyword), ts.factory.createModifier(ts.SyntaxKind.OverrideKeyword)],
|
|
21
|
+
"createEmptyValue",
|
|
22
|
+
void 0,
|
|
23
|
+
void 0,
|
|
24
|
+
ts.factory.createCallExpression(maker, void 0, [model])
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
createEmptyValueMaker,
|
|
29
|
+
createModelBuildingCallback,
|
|
30
|
+
defaultMediaType,
|
|
31
|
+
importBuiltInFormModel
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import type Plugin from '@vaadin/hilla-generator-core/Plugin.js';\nimport type DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport ts, { type ArrowFunction, type Expression, type Identifier, type PropertyDeclaration } from 'typescript';\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"],
|
|
5
|
+
"mappings": "AAEA,OAAO,YAA4F;AAM5F,MAAM,mBAAmB;AAEzB,SAAS,uBAAuB,WAAmB,EAAE,SAAS,MAAM,GAAkC;AAC3G,QAAM,YAAY,MAAM,qBAAqB,0BAA0B,KAAK;AAC5E,SAAO,QAAQ,MAAM,cAAc,WAAW,SAAS,KAAK,QAAQ,MAAM,IAAI,WAAW,SAAS;AACpG;AAEO,SAAS,4BAA4B,MAAkB,MAA4C;AACxG,QAAM,WAAW,CAAC,GAAG,QAAQ,iBAAiB,QAAQ,GAAG,GAAG,QAAQ,iBAAiB,KAAK,CAAC;AAE3F,SAAO,GAAG,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,IACA,SAAS,IAAI,CAAC,QAAQ,GAAG,QAAQ,2BAA2B,QAAW,QAAW,GAAG,CAAC;AAAA,IACtF;AAAA,IACA,GAAG,QAAQ,YAAY,GAAG,WAAW,sBAAsB;AAAA,IAC3D,GAAG,QAAQ,oBAAoB,MAAM,QAAW,CAAC,GAAG,UAAU,GAAG,IAAI,CAAC;AAAA,EACxE;AACF;AAEO,SAAS,sBAAsB,OAAmB,OAAwC;AAC/F,SAAO,GAAG,QAAQ;AAAA,IAChB,CAAC,GAAG,QAAQ,eAAe,GAAG,WAAW,aAAa,GAAG,GAAG,QAAQ,eAAe,GAAG,WAAW,eAAe,CAAC;AAAA,IACjH;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,QAAQ,qBAAqB,OAAO,QAAW,CAAC,KAAK,CAAC;AAAA,EAC3D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|