@api-client/core 0.12.1 → 0.12.3
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/bin/plugins/sinon/assert.ts +29 -0
- package/bin/test.ts +2 -0
- package/build/src/browser.d.ts +4 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +3 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +4 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +3 -0
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +4 -0
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js +11 -0
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainAssociation.js +1 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +46 -0
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +71 -0
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts +31 -8
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +118 -46
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainProperty.js +1 -1
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/validation/association_validation.d.ts +38 -0
- package/build/src/modeling/validation/association_validation.d.ts.map +1 -0
- package/build/src/modeling/validation/association_validation.js +108 -0
- package/build/src/modeling/validation/association_validation.js.map +1 -0
- package/build/src/modeling/validation/entity_validation.d.ts +52 -0
- package/build/src/modeling/validation/entity_validation.d.ts.map +1 -0
- package/build/src/modeling/validation/entity_validation.js +241 -0
- package/build/src/modeling/validation/entity_validation.js.map +1 -0
- package/build/src/modeling/validation/postgresql.d.ts +2 -0
- package/build/src/modeling/validation/postgresql.d.ts.map +1 -0
- package/build/src/modeling/validation/postgresql.js +58 -0
- package/build/src/modeling/validation/postgresql.js.map +1 -0
- package/build/src/modeling/validation/property_validation.d.ts +29 -0
- package/build/src/modeling/validation/property_validation.d.ts.map +1 -0
- package/build/src/modeling/validation/property_validation.js +58 -0
- package/build/src/modeling/validation/property_validation.js.map +1 -0
- package/build/src/modeling/validation/rules.d.ts +55 -0
- package/build/src/modeling/validation/rules.d.ts.map +1 -0
- package/build/src/modeling/validation/rules.js +110 -0
- package/build/src/modeling/validation/rules.js.map +1 -0
- package/package.json +1 -1
- package/src/modeling/DataDomain.ts +12 -0
- package/src/modeling/DomainAssociation.ts +1 -1
- package/src/modeling/DomainEntity.ts +75 -0
- package/src/modeling/DomainImpactAnalysis.ts +144 -54
- package/src/modeling/DomainProperty.ts +1 -1
- package/src/modeling/validation/association_validation.ts +109 -0
- package/src/modeling/validation/entity_validation.ts +246 -0
- package/src/modeling/validation/postgresql.ts +57 -0
- package/src/modeling/validation/property_validation.ts +58 -0
- package/src/modeling/validation/rules.ts +152 -0
- package/tests/unit/modeling/data_domain_associations.spec.ts +1 -1
- package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
- package/tests/unit/modeling/domain.property.spec.ts +7 -7
- package/tests/unit/modeling/domain_asociation.spec.ts +3 -3
- package/tests/unit/modeling/domain_entity_associations.spec.ts +1 -1
- package/tests/unit/modeling/domain_entity_properties.spec.ts +2 -2
- package/tests/unit/modeling/domain_impact_analysis.spec.ts +138 -29
- package/tests/unit/modeling/validation/association_validation.spec.ts +157 -0
- package/tests/unit/modeling/validation/entity_validation.spec.ts +192 -0
- package/tests/unit/modeling/validation/property_validation.spec.ts +135 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { DomainEntityKind } from '../../models/kinds.js';
|
|
2
|
+
import { ReservedKeywords } from './postgresql.js';
|
|
3
|
+
/**
|
|
4
|
+
* EntityValidation is a class that performs validation on entities in a data domain.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* - We do not need to check for parent uniqueness here, because in the graph there can only be one edge
|
|
8
|
+
* between two nodes. Parent relationships are described by an edge in the graph.
|
|
9
|
+
*/
|
|
10
|
+
export class EntityValidation {
|
|
11
|
+
domain;
|
|
12
|
+
constructor(domain) {
|
|
13
|
+
this.domain = domain;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Performs all the validation rules on the entity.
|
|
17
|
+
* If you are interested in a specific rule, use the specific method.
|
|
18
|
+
* @param target The target entity to validate. Can be a string with the entity key or a DomainEntity object.
|
|
19
|
+
*/
|
|
20
|
+
validate(target) {
|
|
21
|
+
const results = [];
|
|
22
|
+
let entity;
|
|
23
|
+
if (typeof target === 'string') {
|
|
24
|
+
entity = this.domain.findEntity(target);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
entity = target;
|
|
28
|
+
}
|
|
29
|
+
if (!entity) {
|
|
30
|
+
const message = `The "${target}" entity does not exist.`;
|
|
31
|
+
const help = `The entity must be defined in the domain.`;
|
|
32
|
+
results.push({
|
|
33
|
+
field: '*',
|
|
34
|
+
rule: 'exists',
|
|
35
|
+
message,
|
|
36
|
+
help,
|
|
37
|
+
key: target,
|
|
38
|
+
kind: DomainEntityKind,
|
|
39
|
+
severity: 'error',
|
|
40
|
+
});
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
const primary = this.validatePrimaryKey(entity);
|
|
44
|
+
results.push(...primary);
|
|
45
|
+
const minimum = this.minimumRequiredProperties(entity);
|
|
46
|
+
results.push(...minimum);
|
|
47
|
+
const name = this.validateName(entity);
|
|
48
|
+
results.push(...name);
|
|
49
|
+
const uniqueName = this.uniqueName(entity);
|
|
50
|
+
results.push(...uniqueName);
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates the entity against the primary key validation rules.
|
|
55
|
+
* @param entity The entity to validate
|
|
56
|
+
* @returns The list of validation messages.
|
|
57
|
+
*/
|
|
58
|
+
validatePrimaryKey(entity) {
|
|
59
|
+
const results = [];
|
|
60
|
+
const primary = entity.primaryKey();
|
|
61
|
+
if (!primary) {
|
|
62
|
+
const message = `The "${entity.info.getLabel()}" entity has no identifier.`;
|
|
63
|
+
const help = `An entity that can exists by itself must have identifier defined.`;
|
|
64
|
+
results.push({
|
|
65
|
+
field: 'properties',
|
|
66
|
+
rule: 'primary_key',
|
|
67
|
+
message,
|
|
68
|
+
help,
|
|
69
|
+
severity: 'error',
|
|
70
|
+
key: entity.key,
|
|
71
|
+
kind: entity.kind,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return results;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the entity has the minimum required properties.
|
|
78
|
+
* @param entity The entity to validate
|
|
79
|
+
*/
|
|
80
|
+
minimumRequiredProperties(entity) {
|
|
81
|
+
const results = [];
|
|
82
|
+
if (!entity.hasProperties() && !entity.hasAssociations()) {
|
|
83
|
+
const message = `The "${entity.info.getLabel()}" entity has no properties. It will be ignored.`;
|
|
84
|
+
const help = `Entities that have no properties are ignored in the data domain. No schema will be generated for it.`;
|
|
85
|
+
results.push({
|
|
86
|
+
field: 'properties',
|
|
87
|
+
rule: 'required',
|
|
88
|
+
message,
|
|
89
|
+
help,
|
|
90
|
+
severity: 'warning',
|
|
91
|
+
key: entity.key,
|
|
92
|
+
kind: entity.kind,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Validates the entity name.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* - An entity must have a name defined.
|
|
102
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
103
|
+
* - Table names must start with a letter (a-z) or underscore (_).
|
|
104
|
+
* - Subsequent characters can be letters, digits (0-9), or underscores (_).
|
|
105
|
+
* - Names are case-insensitive.
|
|
106
|
+
* - The maximum length of a table name is 31 characters
|
|
107
|
+
* - Should be snake case (it's a convention, not an error).
|
|
108
|
+
* - Should not be a reserved word (for example: "IN", "SELECT", "FROM", etc.).
|
|
109
|
+
* @param entity The entity to validate
|
|
110
|
+
*/
|
|
111
|
+
validateName(entity) {
|
|
112
|
+
const results = [];
|
|
113
|
+
const label = entity.info.getLabel();
|
|
114
|
+
if (!entity.info.name) {
|
|
115
|
+
const message = `The "${label}" entity has no name.`;
|
|
116
|
+
const help = `An entity must have a name.`;
|
|
117
|
+
results.push({
|
|
118
|
+
field: 'name',
|
|
119
|
+
rule: 'required',
|
|
120
|
+
message,
|
|
121
|
+
help,
|
|
122
|
+
severity: 'error',
|
|
123
|
+
key: entity.key,
|
|
124
|
+
kind: entity.kind,
|
|
125
|
+
});
|
|
126
|
+
return results;
|
|
127
|
+
}
|
|
128
|
+
const name = entity.info.name;
|
|
129
|
+
if (name.length < 2) {
|
|
130
|
+
const message = `The "${label}" entity name is too short.`;
|
|
131
|
+
const help = `The name must be at least 2 characters long.`;
|
|
132
|
+
results.push({
|
|
133
|
+
field: 'name',
|
|
134
|
+
rule: 'length',
|
|
135
|
+
message,
|
|
136
|
+
help,
|
|
137
|
+
severity: 'error',
|
|
138
|
+
key: entity.key,
|
|
139
|
+
kind: entity.kind,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (name.length > 31) {
|
|
143
|
+
const message = `The "${label}" entity name is too long.`;
|
|
144
|
+
const help = `The name must be at most 31 characters long.`;
|
|
145
|
+
results.push({
|
|
146
|
+
field: 'name',
|
|
147
|
+
rule: 'length',
|
|
148
|
+
message,
|
|
149
|
+
help,
|
|
150
|
+
severity: 'error',
|
|
151
|
+
key: entity.key,
|
|
152
|
+
kind: entity.kind,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
156
|
+
const message = `The "${label}" entity name is invalid.`;
|
|
157
|
+
const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`;
|
|
158
|
+
results.push({
|
|
159
|
+
field: 'name',
|
|
160
|
+
rule: 'format',
|
|
161
|
+
message,
|
|
162
|
+
help,
|
|
163
|
+
severity: 'error',
|
|
164
|
+
key: entity.key,
|
|
165
|
+
kind: entity.kind,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (/^[A-Z]/.test(name)) {
|
|
169
|
+
const message = `The "${label}" entity name is not in snake case.`;
|
|
170
|
+
const help = `The name should be in snake case (lowercase letters and underscores).`;
|
|
171
|
+
results.push({
|
|
172
|
+
field: 'name',
|
|
173
|
+
rule: 'snake_case',
|
|
174
|
+
message,
|
|
175
|
+
help,
|
|
176
|
+
severity: 'info',
|
|
177
|
+
key: entity.key,
|
|
178
|
+
kind: entity.kind,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (ReservedKeywords.has(name.toUpperCase())) {
|
|
182
|
+
const message = `The "${label}" entity name is a reserved keyword.`;
|
|
183
|
+
const help = `The name should not be a reserved keyword.`;
|
|
184
|
+
results.push({
|
|
185
|
+
field: 'name',
|
|
186
|
+
rule: 'reserved',
|
|
187
|
+
message,
|
|
188
|
+
help,
|
|
189
|
+
severity: 'error',
|
|
190
|
+
key: entity.key,
|
|
191
|
+
kind: entity.kind,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return results;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Checks if the entity name is unique in the data domain.
|
|
198
|
+
* @param entity The entity to validate
|
|
199
|
+
*/
|
|
200
|
+
uniqueName(entity) {
|
|
201
|
+
const results = [];
|
|
202
|
+
const name = entity.info.name?.toLowerCase();
|
|
203
|
+
if (!name) {
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
// We need to check the unique names in all entities, including foreign ones.
|
|
207
|
+
for (const other of this.domain.listEntities()) {
|
|
208
|
+
if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {
|
|
209
|
+
const message = `The "${name}" entity name is already used in the data domain.`;
|
|
210
|
+
const help = `The name must be unique. This includes references to other data domains.`;
|
|
211
|
+
results.push({
|
|
212
|
+
field: 'name',
|
|
213
|
+
rule: 'unique',
|
|
214
|
+
message,
|
|
215
|
+
help,
|
|
216
|
+
severity: 'error',
|
|
217
|
+
key: other.key,
|
|
218
|
+
kind: other.kind,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const other of this.domain.listForeignEntities()) {
|
|
223
|
+
if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {
|
|
224
|
+
const message = `The "${name}" entity name is already used in the foreign data domain.`;
|
|
225
|
+
const help = `The name must be unique. This includes references to other data domains.`;
|
|
226
|
+
results.push({
|
|
227
|
+
field: 'name',
|
|
228
|
+
rule: 'unique',
|
|
229
|
+
message,
|
|
230
|
+
help,
|
|
231
|
+
severity: 'error',
|
|
232
|
+
key: other.key,
|
|
233
|
+
kind: other.kind,
|
|
234
|
+
parent: other.domain.key,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return results;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=entity_validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/entity_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACL;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;OAIG;IACH,QAAQ,CAAC,MAA6B;QACpC,MAAM,OAAO,GAAuB,EAAE,CAAA;QACtC,IAAI,MAAgC,CAAA;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,G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","sourcesContent":["import { DomainEntityKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { ReservedKeywords } from './postgresql.js'\nimport type { DomainValidation } from './rules.js'\n\n/**\n * EntityValidation is a class that performs validation on entities in a data domain.\n *\n * @remarks\n * - We do not need to check for parent uniqueness here, because in the graph there can only be one edge\n * between two nodes. Parent relationships are described by an edge in the graph.\n */\nexport class EntityValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the entity.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target entity to validate. Can be a string with the entity key or a DomainEntity object.\n */\n validate(target: string | DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n let entity: DomainEntity | undefined\n if (typeof target === 'string') {\n entity = this.domain.findEntity(target)\n } else {\n entity = target\n }\n if (!entity) {\n const message = `The \"${target}\" entity does not exist.`\n const help = `The entity must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainEntityKind,\n severity: 'error',\n })\n return results\n }\n const primary = this.validatePrimaryKey(entity)\n results.push(...primary)\n const minimum = this.minimumRequiredProperties(entity)\n results.push(...minimum)\n const name = this.validateName(entity)\n results.push(...name)\n const uniqueName = this.uniqueName(entity)\n results.push(...uniqueName)\n return results\n }\n\n /**\n * Validates the entity against the primary key validation rules.\n * @param entity The entity to validate\n * @returns The list of validation messages.\n */\n validatePrimaryKey(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const primary = entity.primaryKey()\n if (!primary) {\n const message = `The \"${entity.info.getLabel()}\" entity has no identifier.`\n const help = `An entity that can exists by itself must have identifier defined.`\n results.push({\n field: 'properties',\n rule: 'primary_key',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if the entity has the minimum required properties.\n * @param entity The entity to validate\n */\n minimumRequiredProperties(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n if (!entity.hasProperties() && !entity.hasAssociations()) {\n const message = `The \"${entity.info.getLabel()}\" entity has no properties. It will be ignored.`\n const help = `Entities that have no properties are ignored in the data domain. No schema will be generated for it.`\n results.push({\n field: 'properties',\n rule: 'required',\n message,\n help,\n severity: 'warning',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Validates the entity name.\n *\n * @remarks\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Table names must start with a letter (a-z) or underscore (_).\n * - Subsequent characters can be letters, digits (0-9), or underscores (_).\n * - Names are case-insensitive.\n * - The maximum length of a table name is 31 characters\n * - Should be snake case (it's a convention, not an error).\n * - Should not be a reserved word (for example: \"IN\", \"SELECT\", \"FROM\", etc.).\n * @param entity The entity to validate\n */\n validateName(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const label = entity.info.getLabel()\n if (!entity.info.name) {\n const message = `The \"${label}\" entity has no name.`\n const help = `An entity must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n return results\n }\n\n const name = entity.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" entity name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (name.length > 31) {\n const message = `The \"${label}\" entity name is too long.`\n const help = `The name must be at most 31 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" entity name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" entity name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" entity name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if the entity name is unique in the data domain.\n * @param entity The entity to validate\n */\n uniqueName(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const name = entity.info.name?.toLowerCase()\n if (!name) {\n return results\n }\n // We need to check the unique names in all entities, including foreign ones.\n for (const other of this.domain.listEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n })\n }\n }\n for (const other of this.domain.listForeignEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the foreign data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n parent: other.domain.key,\n })\n }\n }\n return results\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresql.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/postgresql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,aAwD3B,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const ReservedKeywords = new Set([
|
|
2
|
+
'IN',
|
|
3
|
+
'EXISTS',
|
|
4
|
+
'SELECT',
|
|
5
|
+
'FROM',
|
|
6
|
+
'WHERE',
|
|
7
|
+
'AND',
|
|
8
|
+
'OR',
|
|
9
|
+
'NOT',
|
|
10
|
+
'NULL',
|
|
11
|
+
'TRUE',
|
|
12
|
+
'FALSE',
|
|
13
|
+
'BETWEEN',
|
|
14
|
+
'LIKE',
|
|
15
|
+
'INTO',
|
|
16
|
+
'JOIN',
|
|
17
|
+
'INNER JOIN',
|
|
18
|
+
'LEFT JOIN',
|
|
19
|
+
'RIGHT JOIN',
|
|
20
|
+
'FULL JOIN',
|
|
21
|
+
'CROSS JOIN',
|
|
22
|
+
'UNION',
|
|
23
|
+
'INTERSECT',
|
|
24
|
+
'EXCEPT',
|
|
25
|
+
'ORDER BY',
|
|
26
|
+
'GROUP BY',
|
|
27
|
+
'HAVING',
|
|
28
|
+
'DISTINCT',
|
|
29
|
+
'LIMIT',
|
|
30
|
+
'OFFSET',
|
|
31
|
+
'INSERT',
|
|
32
|
+
'UPDATE',
|
|
33
|
+
'DELETE',
|
|
34
|
+
'CREATE',
|
|
35
|
+
'ALTER',
|
|
36
|
+
'DROP',
|
|
37
|
+
'TRUNCATE',
|
|
38
|
+
'RENAME',
|
|
39
|
+
'GRANT',
|
|
40
|
+
'REVOKE',
|
|
41
|
+
'COMMIT',
|
|
42
|
+
'ROLLBACK',
|
|
43
|
+
'SAVEPOINT',
|
|
44
|
+
'TRANSACTION',
|
|
45
|
+
'BEGIN',
|
|
46
|
+
'END',
|
|
47
|
+
'CASE',
|
|
48
|
+
'WHEN',
|
|
49
|
+
'THEN',
|
|
50
|
+
'ELSE',
|
|
51
|
+
'END CASE',
|
|
52
|
+
'EXCEPTION',
|
|
53
|
+
'RAISE',
|
|
54
|
+
'RETURN',
|
|
55
|
+
'FUNCTION',
|
|
56
|
+
'PROCEDURE',
|
|
57
|
+
]);
|
|
58
|
+
//# sourceMappingURL=postgresql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresql.js","sourceRoot":"","sources":["../../../../src/modeling/validation/postgresql.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IACtC,IAAI;IACJ,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,KAAK;IACL,IAAI;IACJ,KAAK;IACL,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,MAAM;IACN,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,OAAO;IACP,WAAW;IACX,QAAQ;IACR,UAAU;IACV,UAAU;IACV,QAAQ;IACR,UAAU;IACV,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IACN,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,WAAW;IACX,aAAa;IACb,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,WAAW;IACX,OAAO;IACP,QAAQ;IACR,UAAU;IACV,WAAW;CACZ,CAAC,CAAA","sourcesContent":["export const ReservedKeywords = new Set([\n 'IN',\n 'EXISTS',\n 'SELECT',\n 'FROM',\n 'WHERE',\n 'AND',\n 'OR',\n 'NOT',\n 'NULL',\n 'TRUE',\n 'FALSE',\n 'BETWEEN',\n 'LIKE',\n 'INTO',\n 'JOIN',\n 'INNER JOIN',\n 'LEFT JOIN',\n 'RIGHT JOIN',\n 'FULL JOIN',\n 'CROSS JOIN',\n 'UNION',\n 'INTERSECT',\n 'EXCEPT',\n 'ORDER BY',\n 'GROUP BY',\n 'HAVING',\n 'DISTINCT',\n 'LIMIT',\n 'OFFSET',\n 'INSERT',\n 'UPDATE',\n 'DELETE',\n 'CREATE',\n 'ALTER',\n 'DROP',\n 'TRUNCATE',\n 'RENAME',\n 'GRANT',\n 'REVOKE',\n 'COMMIT',\n 'ROLLBACK',\n 'SAVEPOINT',\n 'TRANSACTION',\n 'BEGIN',\n 'END',\n 'CASE',\n 'WHEN',\n 'THEN',\n 'ELSE',\n 'END CASE',\n 'EXCEPTION',\n 'RAISE',\n 'RETURN',\n 'FUNCTION',\n 'PROCEDURE',\n])\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DataDomain } from '../DataDomain.js';
|
|
2
|
+
import type { DomainProperty } from '../DomainProperty.js';
|
|
3
|
+
import { type DomainValidation } from './rules.js';
|
|
4
|
+
export declare class PropertyValidation {
|
|
5
|
+
protected domain: DataDomain;
|
|
6
|
+
constructor(domain: DataDomain);
|
|
7
|
+
/**
|
|
8
|
+
* Performs all the validation rules on the property.
|
|
9
|
+
* If you are interested in a specific rule, use the specific method.
|
|
10
|
+
* @param target The target property to validate. Can be a string with
|
|
11
|
+
* the property key or a DomainProperty object.
|
|
12
|
+
*/
|
|
13
|
+
validate(target: string | DomainProperty): DomainValidation[];
|
|
14
|
+
/**
|
|
15
|
+
* Validates the property name.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* - A property must have a name defined.
|
|
19
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
20
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
21
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
22
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
23
|
+
* - (our rule) Column names are case insensitive.
|
|
24
|
+
* - (recommendation) Column names should be in lower case.
|
|
25
|
+
* @param property The property to validate
|
|
26
|
+
*/
|
|
27
|
+
validateName(property: DomainProperty): DomainValidation[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=property_validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property_validation.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AAExE,qBAAa,kBAAkB;IACjB,SAAS,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,gBAAgB,EAAE;IA2B7D;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,gBAAgB,EAAE;CAG3D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DomainPropertyKind } from '../../models/kinds.js';
|
|
2
|
+
import { validatePropertyName } from './rules.js';
|
|
3
|
+
export class PropertyValidation {
|
|
4
|
+
domain;
|
|
5
|
+
constructor(domain) {
|
|
6
|
+
this.domain = domain;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Performs all the validation rules on the property.
|
|
10
|
+
* If you are interested in a specific rule, use the specific method.
|
|
11
|
+
* @param target The target property to validate. Can be a string with
|
|
12
|
+
* the property key or a DomainProperty object.
|
|
13
|
+
*/
|
|
14
|
+
validate(target) {
|
|
15
|
+
const results = [];
|
|
16
|
+
let property;
|
|
17
|
+
if (typeof target === 'string') {
|
|
18
|
+
property = this.domain.findProperty(target);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
property = target;
|
|
22
|
+
}
|
|
23
|
+
if (!property) {
|
|
24
|
+
const message = `The "${target}" property does not exist.`;
|
|
25
|
+
const help = `The property must be defined in the domain.`;
|
|
26
|
+
results.push({
|
|
27
|
+
field: '*',
|
|
28
|
+
rule: 'exists',
|
|
29
|
+
message,
|
|
30
|
+
help,
|
|
31
|
+
key: target,
|
|
32
|
+
kind: DomainPropertyKind,
|
|
33
|
+
severity: 'error',
|
|
34
|
+
});
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
const name = this.validateName(property);
|
|
38
|
+
results.push(...name);
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validates the property name.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* - A property must have a name defined.
|
|
46
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
47
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
48
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
49
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
50
|
+
* - (our rule) Column names are case insensitive.
|
|
51
|
+
* - (recommendation) Column names should be in lower case.
|
|
52
|
+
* @param property The property to validate
|
|
53
|
+
*/
|
|
54
|
+
validateName(property) {
|
|
55
|
+
return validatePropertyName(property);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=property_validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,OAAO,EAAyB,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAExE,MAAM,OAAO,kBAAkB;IACP;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,MAA+B;QACtC,MAAM,OAAO,GAAuB,EAAE,CAAA;QACtC,IAAI,QAAoC,CAAA;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAC7C,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,MAAM,CAAA;QACnB,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,QAAQ,MAAM,4BAA4B,CAAA;YAC1D,MAAM,IAAI,GAAG,6CAA6C,CAAA;YAC1D,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO;gBACP,IAAI;gBACJ,GAAG,EAAE,MAAgB;gBACrB,IAAI,EAAE,kBAAkB;gBACxB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACrB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAwB;QACnC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACvC,CAAC;CACF","sourcesContent":["import { DomainPropertyKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport { type DomainValidation, validatePropertyName } from './rules.js'\n\nexport class PropertyValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the property.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target property to validate. Can be a string with\n * the property key or a DomainProperty object.\n */\n validate(target: string | DomainProperty): DomainValidation[] {\n const results: DomainValidation[] = []\n let property: DomainProperty | undefined\n if (typeof target === 'string') {\n property = this.domain.findProperty(target)\n } else {\n property = target\n }\n if (!property) {\n const message = `The \"${target}\" property does not exist.`\n const help = `The property must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainPropertyKind,\n severity: 'error',\n })\n return results\n }\n const name = this.validateName(property)\n results.push(...name)\n return results\n }\n\n /**\n * Validates the property name.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n * @param property The property to validate\n */\n validateName(property: DomainProperty): DomainValidation[] {\n return validatePropertyName(property)\n }\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DomainProperty } from '../DomainProperty.js';
|
|
2
|
+
import type { DomainAssociation } from '../DomainAssociation.js';
|
|
3
|
+
import type { DomainImpactItem } from '../DomainImpactAnalysis.js';
|
|
4
|
+
/**
|
|
5
|
+
* `DomainImpactItem` mapping:
|
|
6
|
+
* - `impact` -> `message`
|
|
7
|
+
* - `resolution` -> `help`
|
|
8
|
+
* - `type` -> unused
|
|
9
|
+
* - `blocking` -> unused (deprecated)
|
|
10
|
+
* - `relationship` -> unused
|
|
11
|
+
*/
|
|
12
|
+
export interface DomainValidation extends Omit<DomainImpactItem, 'type' | 'impact' | 'blocking' | 'relationship' | 'resolution'> {
|
|
13
|
+
/**
|
|
14
|
+
* The field that did not pass validation.
|
|
15
|
+
*/
|
|
16
|
+
field: string;
|
|
17
|
+
/**
|
|
18
|
+
* The name of the rule that was violated.
|
|
19
|
+
*/
|
|
20
|
+
rule: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional help message that can be used to provide
|
|
23
|
+
* more information about the error.
|
|
24
|
+
*/
|
|
25
|
+
help?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional URL that can be used to provide more information
|
|
28
|
+
* about the error.
|
|
29
|
+
*/
|
|
30
|
+
url?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The validation error message.
|
|
33
|
+
* This message should be user-friendly and should not
|
|
34
|
+
* contain any technical details.
|
|
35
|
+
* It should be used to display the error to the user.
|
|
36
|
+
* It should be short and concise.
|
|
37
|
+
*/
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validates the property name. This includes associations.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* - A property must have a name defined.
|
|
45
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
46
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
47
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
48
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
49
|
+
* - (our rule) Column names are case insensitive.
|
|
50
|
+
* - (recommendation) Column names should be in lower case.
|
|
51
|
+
*
|
|
52
|
+
* @param property The property to validate
|
|
53
|
+
*/
|
|
54
|
+
export declare function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidation[];
|
|
55
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAIlE;;;;;;;GAOG;AACH,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,cAAc,GAAG,YAAY,CAAC;IAC9F;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,GAAG,iBAAiB,GAAG,gBAAgB,EAAE,CA4FrG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ReservedKeywords } from './postgresql.js';
|
|
2
|
+
import { DomainPropertyKind } from '../../models/kinds.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates the property name. This includes associations.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* - A property must have a name defined.
|
|
8
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
9
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
10
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
11
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
12
|
+
* - (our rule) Column names are case insensitive.
|
|
13
|
+
* - (recommendation) Column names should be in lower case.
|
|
14
|
+
*
|
|
15
|
+
* @param property The property to validate
|
|
16
|
+
*/
|
|
17
|
+
export function validatePropertyName(property) {
|
|
18
|
+
const results = [];
|
|
19
|
+
const label = property.info.getLabel();
|
|
20
|
+
const parentEntity = property.getParentInstance();
|
|
21
|
+
const type = property.kind === DomainPropertyKind ? 'property' : 'association';
|
|
22
|
+
if (!property.info.name) {
|
|
23
|
+
const message = `The "${label}" ${type} has no name.`;
|
|
24
|
+
const help = `The ${type} must have a name.`;
|
|
25
|
+
results.push({
|
|
26
|
+
field: 'name',
|
|
27
|
+
rule: 'required',
|
|
28
|
+
message,
|
|
29
|
+
help,
|
|
30
|
+
severity: 'error',
|
|
31
|
+
key: property.key,
|
|
32
|
+
kind: property.kind,
|
|
33
|
+
parent: parentEntity.key,
|
|
34
|
+
});
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
const name = property.info.name;
|
|
38
|
+
if (name.length < 2) {
|
|
39
|
+
const message = `The "${label}" ${type} name is too short.`;
|
|
40
|
+
const help = `The name must be at least 2 characters long.`;
|
|
41
|
+
results.push({
|
|
42
|
+
field: 'name',
|
|
43
|
+
rule: 'length',
|
|
44
|
+
message,
|
|
45
|
+
help,
|
|
46
|
+
severity: 'error',
|
|
47
|
+
key: property.key,
|
|
48
|
+
kind: property.kind,
|
|
49
|
+
parent: parentEntity.key,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (name.length > 59) {
|
|
53
|
+
const message = `The "${label}" ${type} name is too long.`;
|
|
54
|
+
const help = `The name must be at most 59 characters long.`;
|
|
55
|
+
results.push({
|
|
56
|
+
field: 'name',
|
|
57
|
+
rule: 'length',
|
|
58
|
+
message,
|
|
59
|
+
help,
|
|
60
|
+
severity: 'error',
|
|
61
|
+
key: property.key,
|
|
62
|
+
kind: property.kind,
|
|
63
|
+
parent: parentEntity.key,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
67
|
+
const message = `The "${label}" ${type} name is invalid.`;
|
|
68
|
+
const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`;
|
|
69
|
+
results.push({
|
|
70
|
+
field: 'name',
|
|
71
|
+
rule: 'format',
|
|
72
|
+
message,
|
|
73
|
+
help,
|
|
74
|
+
severity: 'error',
|
|
75
|
+
key: property.key,
|
|
76
|
+
kind: property.kind,
|
|
77
|
+
parent: parentEntity.key,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (/^[A-Z]/.test(name)) {
|
|
81
|
+
const message = `The "${label}" ${type} name is not in snake case.`;
|
|
82
|
+
const help = `The name should be in snake case (lowercase letters and underscores).`;
|
|
83
|
+
results.push({
|
|
84
|
+
field: 'name',
|
|
85
|
+
rule: 'snake_case',
|
|
86
|
+
message,
|
|
87
|
+
help,
|
|
88
|
+
severity: 'info',
|
|
89
|
+
key: property.key,
|
|
90
|
+
kind: property.kind,
|
|
91
|
+
parent: parentEntity.key,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (ReservedKeywords.has(name.toUpperCase())) {
|
|
95
|
+
const message = `The "${label}" ${type} name is a reserved keyword.`;
|
|
96
|
+
const help = `The name should not be a reserved keyword.`;
|
|
97
|
+
results.push({
|
|
98
|
+
field: 'name',
|
|
99
|
+
rule: 'reserved',
|
|
100
|
+
message,
|
|
101
|
+
help,
|
|
102
|
+
severity: 'error',
|
|
103
|
+
key: property.key,
|
|
104
|
+
kind: property.kind,
|
|
105
|
+
parent: parentEntity.key,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return results;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAKlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAwC1D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAA4C;IAC/E,MAAM,OAAO,GAAuB,EAAE,CAAA;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;IACtC,MAAM,YAAY,GAAG,QAAQ,CAAC,iBAAiB,EAAkB,CAAA;IACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAA;IAC9E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,QAAQ,KAAK,KAAK,IAAI,eAAe,CAAA;QACrD,MAAM,IAAI,GAAG,OAAO,IAAI,oBAAoB,CAAA;QAC5C,OAAO,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,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,CAAC","sourcesContent":["import { ReservedKeywords } from './postgresql.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport type { DomainAssociation } from '../DomainAssociation.js'\nimport type { DomainImpactItem } from '../DomainImpactAnalysis.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { DomainPropertyKind } from '../../models/kinds.js'\n\n/**\n * `DomainImpactItem` mapping:\n * - `impact` -> `message`\n * - `resolution` -> `help`\n * - `type` -> unused\n * - `blocking` -> unused (deprecated)\n * - `relationship` -> unused\n */\nexport interface DomainValidation\n extends Omit<DomainImpactItem, 'type' | 'impact' | 'blocking' | 'relationship' | 'resolution'> {\n /**\n * The field that did not pass validation.\n */\n field: string\n /**\n * The name of the rule that was violated.\n */\n rule: string\n /**\n * Optional help message that can be used to provide\n * more information about the error.\n */\n help?: string\n /**\n * Optional URL that can be used to provide more information\n * about the error.\n */\n url?: string\n /**\n * The validation error message.\n * This message should be user-friendly and should not\n * contain any technical details.\n * It should be used to display the error to the user.\n * It should be short and concise.\n */\n message: string\n}\n\n/**\n * Validates the property name. This includes associations.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n *\n * @param property The property to validate\n */\nexport function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidation[] {\n const results: DomainValidation[] = []\n const label = property.info.getLabel()\n const parentEntity = property.getParentInstance() as DomainEntity\n const type = property.kind === DomainPropertyKind ? 'property' : 'association'\n if (!property.info.name) {\n const message = `The \"${label}\" ${type} has no name.`\n const help = `The ${type} must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n return results\n }\n const name = property.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" ${type} name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (name.length > 59) {\n const message = `The \"${label}\" ${type} name is too long.`\n const help = `The name must be at most 59 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" ${type} name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" ${type} name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" ${type} name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n return results\n}\n"]}
|
package/package.json
CHANGED