@vaadin/hilla-generator-plugin-model 24.7.0-alpha9 → 24.7.0-beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityModelProcessor.d.ts +0 -1
- package/EntityModelProcessor.js +138 -207
- package/EntityModelProcessor.js.map +1 -7
- package/MetadataProcessor.d.ts +0 -1
- package/MetadataProcessor.js +23 -33
- package/MetadataProcessor.js.map +1 -7
- package/ModelSchemaProcessor.d.ts +0 -1
- package/ModelSchemaProcessor.js +181 -208
- package/ModelSchemaProcessor.js.map +1 -7
- package/ValidationConstraintProcessor.d.ts +0 -1
- package/ValidationConstraintProcessor.js +25 -33
- package/ValidationConstraintProcessor.js.map +1 -7
- package/index.d.ts +1 -2
- package/index.js +28 -33
- package/index.js.map +1 -7
- package/package.json +12 -33
- package/utils.d.ts +0 -1
- package/utils.js +11 -30
- package/utils.js.map +1 -7
- package/EntityModelProcessor.d.ts.map +0 -1
- package/MetadataProcessor.d.ts.map +0 -1
- package/ModelSchemaProcessor.d.ts.map +0 -1
- package/ValidationConstraintProcessor.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/utils.d.ts.map +0 -1
package/ModelSchemaProcessor.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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";
|
|
1
|
+
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
|
+
import { process } from './MetadataProcessor.js';
|
|
4
|
+
import { createModelBuildingCallback, importBuiltInFormModel } from './utils.js';
|
|
5
|
+
import { hasValidationConstraints, ValidationConstraintProcessor } from './ValidationConstraintProcessor.js';
|
|
20
6
|
const $dependencies = Symbol();
|
|
21
7
|
const $processArray = Symbol();
|
|
22
8
|
const $processRecord = Symbol();
|
|
@@ -27,201 +13,188 @@ const $processBoolean = Symbol();
|
|
|
27
13
|
const $processUnknown = Symbol();
|
|
28
14
|
const $originalSchema = Symbol();
|
|
29
15
|
const $schema = Symbol();
|
|
30
|
-
class ModelSchemaPartProcessor {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
16
|
+
export class ModelSchemaPartProcessor {
|
|
17
|
+
[$dependencies];
|
|
18
|
+
[$originalSchema];
|
|
19
|
+
[$schema];
|
|
20
|
+
constructor(schema, dependencies) {
|
|
21
|
+
this[$dependencies] = dependencies;
|
|
22
|
+
this[$originalSchema] = schema;
|
|
23
|
+
this[$schema] = isComposedSchema(schema) ? decomposeSchema(schema)[0] : schema;
|
|
24
|
+
}
|
|
25
|
+
process() {
|
|
26
|
+
const schema = this[$schema];
|
|
27
|
+
if (isReferenceSchema(schema)) {
|
|
28
|
+
return this[$processReference](schema);
|
|
29
|
+
}
|
|
30
|
+
if (isArraySchema(schema)) {
|
|
31
|
+
return this[$processArray](schema);
|
|
32
|
+
}
|
|
33
|
+
if (isMapSchema(schema)) {
|
|
34
|
+
return this[$processRecord](schema);
|
|
35
|
+
}
|
|
36
|
+
if (isStringSchema(schema)) {
|
|
37
|
+
return this[$processString](schema);
|
|
38
|
+
}
|
|
39
|
+
if (isNumberSchema(schema) || isIntegerSchema(schema)) {
|
|
40
|
+
return this[$processNumber](schema);
|
|
41
|
+
}
|
|
42
|
+
if (isBooleanSchema(schema)) {
|
|
43
|
+
return this[$processBoolean](schema);
|
|
44
|
+
}
|
|
45
|
+
return this[$processUnknown](schema);
|
|
46
|
+
}
|
|
61
47
|
}
|
|
62
48
|
function handleNullableInternalType(schema, typeNode) {
|
|
63
|
-
|
|
49
|
+
return isNullableSchema(schema)
|
|
50
|
+
? ts.factory.createUnionTypeNode([typeNode, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)])
|
|
51
|
+
: typeNode;
|
|
64
52
|
}
|
|
65
53
|
class ModelSchemaInternalTypeProcessor extends ModelSchemaPartProcessor {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
[$processUnknown](_) {
|
|
99
|
-
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
100
|
-
}
|
|
54
|
+
[$processArray](schema) {
|
|
55
|
+
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('ReadonlyArray'), [
|
|
56
|
+
handleNullableInternalType(schema.items, new ModelSchemaInternalTypeProcessor(schema.items, this[$dependencies]).process()),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
[$processBoolean](_) {
|
|
60
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword);
|
|
61
|
+
}
|
|
62
|
+
[$processNumber](_) {
|
|
63
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
64
|
+
}
|
|
65
|
+
[$processRecord]({ additionalProperties: props }) {
|
|
66
|
+
const valueType = typeof props === 'boolean'
|
|
67
|
+
? ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword)
|
|
68
|
+
: handleNullableInternalType(props, new ModelSchemaInternalTypeProcessor(props, this[$dependencies]).process());
|
|
69
|
+
return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Record'), [
|
|
70
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
71
|
+
valueType,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
[$processReference](schema) {
|
|
75
|
+
const { imports, paths } = this[$dependencies];
|
|
76
|
+
const typeName = convertReferenceSchemaToSpecifier(schema);
|
|
77
|
+
const typePath = paths.createRelativePath(convertReferenceSchemaToPath(schema));
|
|
78
|
+
return ts.factory.createTypeReferenceNode(imports.default.getIdentifier(typePath) ?? imports.default.add(typePath, typeName, true));
|
|
79
|
+
}
|
|
80
|
+
[$processString](_) {
|
|
81
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
|
|
82
|
+
}
|
|
83
|
+
[$processUnknown](_) {
|
|
84
|
+
return ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword);
|
|
85
|
+
}
|
|
101
86
|
}
|
|
102
87
|
class ModelSchemaIdentifierProcessor extends ModelSchemaPartProcessor {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
88
|
+
[$processArray](_) {
|
|
89
|
+
return importBuiltInFormModel('ArrayModel', this[$dependencies]);
|
|
90
|
+
}
|
|
91
|
+
[$processBoolean](_) {
|
|
92
|
+
return importBuiltInFormModel('BooleanModel', this[$dependencies]);
|
|
93
|
+
}
|
|
94
|
+
[$processNumber](_) {
|
|
95
|
+
return importBuiltInFormModel('NumberModel', this[$dependencies]);
|
|
96
|
+
}
|
|
97
|
+
[$processRecord](_) {
|
|
98
|
+
return importBuiltInFormModel('ObjectModel', this[$dependencies]);
|
|
99
|
+
}
|
|
100
|
+
[$processReference](schema) {
|
|
101
|
+
const { imports, paths } = this[$dependencies];
|
|
102
|
+
const name = `${convertReferenceSchemaToSpecifier(schema)}Model`;
|
|
103
|
+
const path = paths.createRelativePath(`${convertReferenceSchemaToPath(schema)}Model`);
|
|
104
|
+
return imports.default.getIdentifier(path) ?? imports.default.add(path, name);
|
|
105
|
+
}
|
|
106
|
+
[$processString](_) {
|
|
107
|
+
return importBuiltInFormModel('StringModel', this[$dependencies]);
|
|
108
|
+
}
|
|
109
|
+
[$processUnknown](_) {
|
|
110
|
+
return importBuiltInFormModel('ObjectModel', this[$dependencies]);
|
|
111
|
+
}
|
|
127
112
|
}
|
|
128
|
-
class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
113
|
+
export class ModelSchemaTypeProcessor extends ModelSchemaPartProcessor {
|
|
114
|
+
#id;
|
|
115
|
+
constructor(schema, dependencies) {
|
|
116
|
+
super(schema, dependencies);
|
|
117
|
+
this.#id = new ModelSchemaIdentifierProcessor(schema, dependencies);
|
|
118
|
+
}
|
|
119
|
+
[$processArray](schema) {
|
|
120
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processArray](schema), [
|
|
121
|
+
new ModelSchemaTypeProcessor(schema.items, this[$dependencies]).process(),
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
[$processBoolean](schema) {
|
|
125
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processBoolean](schema));
|
|
126
|
+
}
|
|
127
|
+
[$processNumber](schema) {
|
|
128
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processNumber](schema));
|
|
129
|
+
}
|
|
130
|
+
[$processRecord](schema) {
|
|
131
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processRecord](schema), [
|
|
132
|
+
new ModelSchemaInternalTypeProcessor(schema, this[$dependencies]).process(),
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
[$processReference](schema) {
|
|
136
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processReference](schema));
|
|
137
|
+
}
|
|
138
|
+
[$processString](schema) {
|
|
139
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processString](schema));
|
|
140
|
+
}
|
|
141
|
+
[$processUnknown](schema) {
|
|
142
|
+
return ts.factory.createTypeReferenceNode(this.#id[$processUnknown](schema));
|
|
143
|
+
}
|
|
159
144
|
}
|
|
160
|
-
class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
]
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
}
|
|
145
|
+
export class ModelSchemaExpressionProcessor extends ModelSchemaPartProcessor {
|
|
146
|
+
#validationConstraintProcessor;
|
|
147
|
+
constructor(schema, dependencies) {
|
|
148
|
+
super(schema, dependencies);
|
|
149
|
+
this.#validationConstraintProcessor = new ValidationConstraintProcessor((name) => importBuiltInFormModel(name, dependencies));
|
|
150
|
+
}
|
|
151
|
+
process() {
|
|
152
|
+
const originalSchema = this[$originalSchema];
|
|
153
|
+
let result = super.process();
|
|
154
|
+
const modelOptionsProperties = [
|
|
155
|
+
this.#createValidatorsProperty(originalSchema),
|
|
156
|
+
ModelSchemaExpressionProcessor.#createMetadataProperty(originalSchema),
|
|
157
|
+
].filter(Boolean);
|
|
158
|
+
if (modelOptionsProperties.length > 0) {
|
|
159
|
+
const optionsObject = ts.factory.createObjectLiteralExpression(modelOptionsProperties);
|
|
160
|
+
result = [...result, optionsObject];
|
|
161
|
+
}
|
|
162
|
+
return [isNullableSchema(originalSchema) ? ts.factory.createTrue() : ts.factory.createFalse(), ...result];
|
|
163
|
+
}
|
|
164
|
+
[$processArray](schema) {
|
|
165
|
+
const model = new ModelSchemaIdentifierProcessor(schema.items, this[$dependencies]).process();
|
|
166
|
+
return [
|
|
167
|
+
createModelBuildingCallback(model, new ModelSchemaExpressionProcessor(schema.items, this[$dependencies]).process()),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
[$processBoolean](_) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
[$processNumber](_) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
[$processRecord](_) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
[$processReference](_) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
[$processString](_) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
[$processUnknown](_) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
#createValidatorsProperty(schema) {
|
|
189
|
+
if (!hasValidationConstraints(schema)) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const constraints = schema['x-validation-constraints'].map((constraint) => this.#validationConstraintProcessor.process(constraint));
|
|
193
|
+
return ts.factory.createPropertyAssignment('validators', ts.factory.createArrayLiteralExpression(constraints));
|
|
194
|
+
}
|
|
195
|
+
static #createMetadataProperty(schema) {
|
|
196
|
+
const metadata = process(schema);
|
|
197
|
+
return metadata ? ts.factory.createPropertyAssignment('meta', metadata) : null;
|
|
198
|
+
}
|
|
221
199
|
}
|
|
222
|
-
|
|
223
|
-
ModelSchemaExpressionProcessor,
|
|
224
|
-
ModelSchemaPartProcessor,
|
|
225
|
-
ModelSchemaTypeProcessor
|
|
226
|
-
};
|
|
227
|
-
//# sourceMappingURL=ModelSchemaProcessor.js.map
|
|
200
|
+
//# sourceMappingURL=ModelSchemaProcessor.js.map
|
|
@@ -1,7 +1 @@
|
|
|
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,E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AI,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,37 +1,29 @@
|
|
|
1
|
-
import { template, transform } from
|
|
2
|
-
import ts, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { template, transform } from '@vaadin/hilla-generator-utils/ast.js';
|
|
2
|
+
import ts, {} from 'typescript';
|
|
3
|
+
export function hasValidationConstraints(schema) {
|
|
4
|
+
return ('x-validation-constraints' in schema &&
|
|
5
|
+
schema['x-validation-constraints'].length > 0);
|
|
6
6
|
}
|
|
7
7
|
function selector([statement]) {
|
|
8
|
-
|
|
8
|
+
return statement.declarationList.declarations[0].initializer;
|
|
9
9
|
}
|
|
10
|
-
const variableStatementVar =
|
|
11
|
-
class ValidationConstraintProcessor {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(node) => ts.isPropertyAssignment(node) && ts.isStringLiteral(node.name) ? ts.factory.createPropertyAssignment(node.name.text, node.initializer) : node
|
|
29
|
-
)
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
10
|
+
const variableStatementVar = 'const a';
|
|
11
|
+
export class ValidationConstraintProcessor {
|
|
12
|
+
#importer;
|
|
13
|
+
constructor(importer) {
|
|
14
|
+
this.#importer = importer;
|
|
15
|
+
}
|
|
16
|
+
process(constraint) {
|
|
17
|
+
return ts.factory.createNewExpression(this.#importer(constraint.simpleName), undefined, constraint.attributes ? [ValidationConstraintProcessor.#processAttributes(constraint.attributes)] : []);
|
|
18
|
+
}
|
|
19
|
+
static #processAttributes(attributes) {
|
|
20
|
+
const names = Object.keys(attributes);
|
|
21
|
+
const tpl = JSON.stringify(names.includes('value') && names.length === 1 ? attributes.value : attributes);
|
|
22
|
+
return template(`${variableStatementVar}=${tpl}`, selector, [
|
|
23
|
+
transform((node) => ts.isPropertyAssignment(node) && ts.isStringLiteral(node.name)
|
|
24
|
+
? ts.factory.createPropertyAssignment(node.name.text, node.initializer)
|
|
25
|
+
: node),
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
ValidationConstraintProcessor,
|
|
35
|
-
hasValidationConstraints
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=ValidationConstraintProcessor.js.map
|
|
29
|
+
//# sourceMappingURL=ValidationConstraintProcessor.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/ValidationConstraintProcessor.ts"],
|
|
4
|
-
"sourcesContent": ["import type { NonComposedRegularSchema, Schema } 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 '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": "AACA,SAAS,UAAU,iBAAiB;AACpC,OAAO;AAAA,OAMA;AAKA,SAAS,yBAAyB,QAAuD;AAC9F,SACE,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
|
-
}
|
|
1
|
+
{"version":3,"file":"ValidationConstraintProcessor.js","sourceRoot":"","sources":["src/ValidationConstraintProcessor.ts"],"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,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 type { NonComposedRegularSchema, Schema } 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 '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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Plugin from '@vaadin/hilla-generator-core/Plugin.js';
|
|
2
|
-
import type SharedStorage from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
2
|
+
import type { SharedStorage } from '@vaadin/hilla-generator-core/SharedStorage.js';
|
|
3
3
|
export declare enum ModelPluginSourceType {
|
|
4
4
|
Model = "model"
|
|
5
5
|
}
|
|
@@ -10,4 +10,3 @@ export default class ModelPlugin extends Plugin {
|
|
|
10
10
|
get path(): string;
|
|
11
11
|
execute(storage: SharedStorage): Promise<void>;
|
|
12
12
|
}
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|