@api-client/core 0.12.0 → 0.12.2
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/amf/AmfShapeGenerator.js +3 -3
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
- package/build/src/amf/DataValueGenerator.js +3 -2
- package/build/src/amf/DataValueGenerator.js.map +1 -1
- package/build/src/amf/models/AmfDataNode.d.ts.map +1 -1
- package/build/src/amf/models/AmfDataNode.js +2 -2
- package/build/src/amf/models/AmfDataNode.js.map +1 -1
- 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/lib/uuid.d.ts +1 -1
- package/build/src/lib/uuid.js +1 -1
- package/build/src/lib/uuid.js.map +1 -1
- package/build/src/mocking/lib/History.js +8 -8
- package/build/src/mocking/lib/History.js.map +1 -1
- package/build/src/mocking/lib/HostRules.js +1 -1
- package/build/src/mocking/lib/HostRules.js.map +1 -1
- package/build/src/mocking/lib/User.js +2 -2
- package/build/src/mocking/lib/User.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 +13 -3
- 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/DomainFile.js +2 -2
- package/build/src/modeling/DomainFile.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/legacy/DataAssociation.js +3 -3
- package/build/src/modeling/legacy/DataAssociation.js.map +1 -1
- package/build/src/modeling/legacy/DataEntity.js +3 -3
- package/build/src/modeling/legacy/DataEntity.js.map +1 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js +2 -2
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -1
- package/build/src/modeling/legacy/DataModel.js +3 -3
- package/build/src/modeling/legacy/DataModel.js.map +1 -1
- package/build/src/modeling/legacy/DataNamespace.js +3 -3
- package/build/src/modeling/legacy/DataNamespace.js.map +1 -1
- package/build/src/modeling/legacy/DataProperty.js +3 -3
- package/build/src/modeling/legacy/DataProperty.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/build/src/models/AuthorizationData.js +3 -3
- package/build/src/models/AuthorizationData.js.map +1 -1
- package/build/src/models/CertificateFile.js +2 -2
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/ClientCertificate.js +5 -5
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.js +6 -6
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Folder.js +2 -2
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/HostRule.js +4 -4
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpProject.js +12 -12
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/Project.d.ts.map +1 -1
- package/build/src/models/Project.js +2 -2
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts.map +1 -1
- package/build/src/models/ProjectFolder.js +6 -6
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts.map +1 -1
- package/build/src/models/ProjectRequest.js +8 -8
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.js +6 -6
- package/build/src/models/ProjectSchema.js.map +1 -1
- package/build/src/models/store/DataFile.js +2 -2
- package/build/src/models/store/DataFile.js.map +1 -1
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +3 -3
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Organization.js +3 -3
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/models/store/Permission.js +7 -7
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/store/UserIdentity.js +3 -3
- package/build/src/models/store/UserIdentity.js.map +1 -1
- package/build/src/models/transformers/ArcDexieTransformer.js +4 -4
- package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js +3 -3
- package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
- package/build/src/models/transformers/ArcPouchTransformer.js +2 -2
- package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -2
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/patch/PatchClient.js +2 -2
- package/build/src/patch/PatchClient.js.map +1 -1
- package/build/src/runtime/store/FilesSdk.js +3 -3
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/data/models/example-generator-api.json +20 -20
- package/package.json +1 -1
- package/src/amf/AmfShapeGenerator.ts +3 -3
- package/src/amf/DataValueGenerator.ts +3 -2
- package/src/amf/models/AmfDataNode.ts +2 -2
- package/src/lib/uuid.ts +1 -1
- package/src/mocking/lib/History.ts +8 -8
- package/src/mocking/lib/HostRules.ts +1 -1
- package/src/mocking/lib/User.ts +2 -2
- package/src/modeling/DataDomain.ts +14 -3
- package/src/modeling/DomainAssociation.ts +1 -1
- package/src/modeling/DomainEntity.ts +75 -0
- package/src/modeling/DomainFile.ts +2 -2
- package/src/modeling/DomainImpactAnalysis.ts +144 -54
- package/src/modeling/DomainProperty.ts +1 -1
- package/src/modeling/legacy/DataAssociation.ts +3 -3
- package/src/modeling/legacy/DataEntity.ts +3 -3
- package/src/modeling/legacy/DataEntityBuilder.ts +2 -2
- package/src/modeling/legacy/DataModel.ts +3 -3
- package/src/modeling/legacy/DataNamespace.ts +3 -3
- package/src/modeling/legacy/DataProperty.ts +3 -3
- 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/src/models/AuthorizationData.ts +3 -3
- package/src/models/CertificateFile.ts +2 -2
- package/src/models/ClientCertificate.ts +5 -5
- package/src/models/Environment.ts +6 -6
- package/src/models/Folder.ts +2 -2
- package/src/models/HostRule.ts +4 -4
- package/src/models/HttpProject.ts +12 -12
- package/src/models/Project.ts +2 -2
- package/src/models/ProjectFolder.ts +6 -6
- package/src/models/ProjectRequest.ts +8 -8
- package/src/models/ProjectSchema.ts +6 -6
- package/src/models/store/DataFile.ts +2 -2
- package/src/models/store/File.ts +3 -3
- package/src/models/store/Organization.ts +3 -3
- package/src/models/store/Permission.ts +7 -7
- package/src/models/store/UserIdentity.ts +3 -3
- package/src/models/transformers/ArcDexieTransformer.ts +4 -4
- package/src/models/transformers/ArcLegacyTransformer.ts +3 -3
- package/src/models/transformers/ArcPouchTransformer.ts +2 -2
- package/src/models/transformers/PostmanV21Transformer.ts +2 -2
- package/src/models/transformers/PostmanV2Transformer.ts +2 -2
- package/src/patch/PatchClient.ts +2 -2
- package/src/runtime/store/FilesSdk.ts +3 -3
- 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 +140 -0
- package/tests/unit/modeling/validation/entity_validation.spec.ts +192 -0
- package/tests/unit/modeling/validation/property_validation.spec.ts +125 -0
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +8 -8
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { DomainEntityKind } from '../../models/kinds.js'
|
|
2
|
+
import type { DataDomain } from '../DataDomain.js'
|
|
3
|
+
import type { DomainEntity } from '../DomainEntity.js'
|
|
4
|
+
import { ReservedKeywords } from './postgresql.js'
|
|
5
|
+
import type { DomainValidation } from './rules.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* EntityValidation is a class that performs validation on entities in a data domain.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* - We do not need to check for parent uniqueness here, because in the graph there can only be one edge
|
|
12
|
+
* between two nodes. Parent relationships are described by an edge in the graph.
|
|
13
|
+
*/
|
|
14
|
+
export class EntityValidation {
|
|
15
|
+
constructor(protected domain: DataDomain) {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Performs all the validation rules on the entity.
|
|
19
|
+
* If you are interested in a specific rule, use the specific method.
|
|
20
|
+
* @param target The target entity to validate. Can be a string with the entity key or a DomainEntity object.
|
|
21
|
+
*/
|
|
22
|
+
validate(target: string | DomainEntity): DomainValidation[] {
|
|
23
|
+
const results: DomainValidation[] = []
|
|
24
|
+
let entity: DomainEntity | undefined
|
|
25
|
+
if (typeof target === 'string') {
|
|
26
|
+
entity = this.domain.findEntity(target)
|
|
27
|
+
} else {
|
|
28
|
+
entity = target
|
|
29
|
+
}
|
|
30
|
+
if (!entity) {
|
|
31
|
+
const message = `The "${target}" entity does not exist.`
|
|
32
|
+
const help = `The entity must be defined in the domain.`
|
|
33
|
+
results.push({
|
|
34
|
+
field: '*',
|
|
35
|
+
rule: 'exists',
|
|
36
|
+
message,
|
|
37
|
+
help,
|
|
38
|
+
key: target as string,
|
|
39
|
+
kind: DomainEntityKind,
|
|
40
|
+
severity: 'error',
|
|
41
|
+
})
|
|
42
|
+
return results
|
|
43
|
+
}
|
|
44
|
+
const primary = this.validatePrimaryKey(entity)
|
|
45
|
+
results.push(...primary)
|
|
46
|
+
const minimum = this.minimumRequiredProperties(entity)
|
|
47
|
+
results.push(...minimum)
|
|
48
|
+
const name = this.validateName(entity)
|
|
49
|
+
results.push(...name)
|
|
50
|
+
const uniqueName = this.uniqueName(entity)
|
|
51
|
+
results.push(...uniqueName)
|
|
52
|
+
return results
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Validates the entity against the primary key validation rules.
|
|
57
|
+
* @param entity The entity to validate
|
|
58
|
+
* @returns The list of validation messages.
|
|
59
|
+
*/
|
|
60
|
+
validatePrimaryKey(entity: DomainEntity): DomainValidation[] {
|
|
61
|
+
const results: DomainValidation[] = []
|
|
62
|
+
const primary = entity.primaryKey()
|
|
63
|
+
if (!primary) {
|
|
64
|
+
const message = `The "${entity.info.getLabel()}" entity has no identifier.`
|
|
65
|
+
const help = `An entity that can exists by itself must have identifier defined.`
|
|
66
|
+
results.push({
|
|
67
|
+
field: 'properties',
|
|
68
|
+
rule: 'primary_key',
|
|
69
|
+
message,
|
|
70
|
+
help,
|
|
71
|
+
severity: 'error',
|
|
72
|
+
key: entity.key,
|
|
73
|
+
kind: entity.kind,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
return results
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the entity has the minimum required properties.
|
|
81
|
+
* @param entity The entity to validate
|
|
82
|
+
*/
|
|
83
|
+
minimumRequiredProperties(entity: DomainEntity): DomainValidation[] {
|
|
84
|
+
const results: DomainValidation[] = []
|
|
85
|
+
if (!entity.hasProperties() && !entity.hasAssociations()) {
|
|
86
|
+
const message = `The "${entity.info.getLabel()}" entity has no properties. It will be ignored.`
|
|
87
|
+
const help = `Entities that have no properties are ignored in the data domain. No schema will be generated for it.`
|
|
88
|
+
results.push({
|
|
89
|
+
field: 'properties',
|
|
90
|
+
rule: 'required',
|
|
91
|
+
message,
|
|
92
|
+
help,
|
|
93
|
+
severity: 'warning',
|
|
94
|
+
key: entity.key,
|
|
95
|
+
kind: entity.kind,
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
return results
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Validates the entity name.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* - An entity must have a name defined.
|
|
106
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
107
|
+
* - Table names must start with a letter (a-z) or underscore (_).
|
|
108
|
+
* - Subsequent characters can be letters, digits (0-9), or underscores (_).
|
|
109
|
+
* - Names are case-insensitive.
|
|
110
|
+
* - The maximum length of a table name is 31 characters
|
|
111
|
+
* - Should be snake case (it's a convention, not an error).
|
|
112
|
+
* - Should not be a reserved word (for example: "IN", "SELECT", "FROM", etc.).
|
|
113
|
+
* @param entity The entity to validate
|
|
114
|
+
*/
|
|
115
|
+
validateName(entity: DomainEntity): DomainValidation[] {
|
|
116
|
+
const results: DomainValidation[] = []
|
|
117
|
+
const label = entity.info.getLabel()
|
|
118
|
+
if (!entity.info.name) {
|
|
119
|
+
const message = `The "${label}" entity has no name.`
|
|
120
|
+
const help = `An entity must have a name.`
|
|
121
|
+
results.push({
|
|
122
|
+
field: 'name',
|
|
123
|
+
rule: 'required',
|
|
124
|
+
message,
|
|
125
|
+
help,
|
|
126
|
+
severity: 'error',
|
|
127
|
+
key: entity.key,
|
|
128
|
+
kind: entity.kind,
|
|
129
|
+
})
|
|
130
|
+
return results
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const name = entity.info.name
|
|
134
|
+
if (name.length < 3) {
|
|
135
|
+
const message = `The "${label}" entity name is too short.`
|
|
136
|
+
const help = `The name must be at least 3 characters long.`
|
|
137
|
+
results.push({
|
|
138
|
+
field: 'name',
|
|
139
|
+
rule: 'length',
|
|
140
|
+
message,
|
|
141
|
+
help,
|
|
142
|
+
severity: 'error',
|
|
143
|
+
key: entity.key,
|
|
144
|
+
kind: entity.kind,
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
if (name.length > 31) {
|
|
148
|
+
const message = `The "${label}" entity name is too long.`
|
|
149
|
+
const help = `The name must be at most 31 characters long.`
|
|
150
|
+
results.push({
|
|
151
|
+
field: 'name',
|
|
152
|
+
rule: 'length',
|
|
153
|
+
message,
|
|
154
|
+
help,
|
|
155
|
+
severity: 'error',
|
|
156
|
+
key: entity.key,
|
|
157
|
+
kind: entity.kind,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
161
|
+
const message = `The "${label}" entity name is invalid.`
|
|
162
|
+
const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`
|
|
163
|
+
results.push({
|
|
164
|
+
field: 'name',
|
|
165
|
+
rule: 'format',
|
|
166
|
+
message,
|
|
167
|
+
help,
|
|
168
|
+
severity: 'error',
|
|
169
|
+
key: entity.key,
|
|
170
|
+
kind: entity.kind,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
if (/^[A-Z]/.test(name)) {
|
|
174
|
+
const message = `The "${label}" entity name is not in snake case.`
|
|
175
|
+
const help = `The name should be in snake case (lowercase letters and underscores).`
|
|
176
|
+
results.push({
|
|
177
|
+
field: 'name',
|
|
178
|
+
rule: 'snake_case',
|
|
179
|
+
message,
|
|
180
|
+
help,
|
|
181
|
+
severity: 'info',
|
|
182
|
+
key: entity.key,
|
|
183
|
+
kind: entity.kind,
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
if (ReservedKeywords.has(name.toUpperCase())) {
|
|
187
|
+
const message = `The "${label}" entity name is a reserved keyword.`
|
|
188
|
+
const help = `The name should not be a reserved keyword.`
|
|
189
|
+
results.push({
|
|
190
|
+
field: 'name',
|
|
191
|
+
rule: 'reserved',
|
|
192
|
+
message,
|
|
193
|
+
help,
|
|
194
|
+
severity: 'error',
|
|
195
|
+
key: entity.key,
|
|
196
|
+
kind: entity.kind,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
return results
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Checks if the entity name is unique in the data domain.
|
|
204
|
+
* @param entity The entity to validate
|
|
205
|
+
*/
|
|
206
|
+
uniqueName(entity: DomainEntity): DomainValidation[] {
|
|
207
|
+
const results: DomainValidation[] = []
|
|
208
|
+
const name = entity.info.name?.toLowerCase()
|
|
209
|
+
if (!name) {
|
|
210
|
+
return results
|
|
211
|
+
}
|
|
212
|
+
// We need to check the unique names in all entities, including foreign ones.
|
|
213
|
+
for (const other of this.domain.listEntities()) {
|
|
214
|
+
if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {
|
|
215
|
+
const message = `The "${name}" entity name is already used in the data domain.`
|
|
216
|
+
const help = `The name must be unique. This includes references to other data domains.`
|
|
217
|
+
results.push({
|
|
218
|
+
field: 'name',
|
|
219
|
+
rule: 'unique',
|
|
220
|
+
message,
|
|
221
|
+
help,
|
|
222
|
+
severity: 'error',
|
|
223
|
+
key: other.key,
|
|
224
|
+
kind: other.kind,
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
for (const other of this.domain.listForeignEntities()) {
|
|
229
|
+
if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {
|
|
230
|
+
const message = `The "${name}" entity name is already used in the foreign data domain.`
|
|
231
|
+
const help = `The name must be unique. This includes references to other data domains.`
|
|
232
|
+
results.push({
|
|
233
|
+
field: 'name',
|
|
234
|
+
rule: 'unique',
|
|
235
|
+
message,
|
|
236
|
+
help,
|
|
237
|
+
severity: 'error',
|
|
238
|
+
key: other.key,
|
|
239
|
+
kind: other.kind,
|
|
240
|
+
parent: other.domain.key,
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return results
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
])
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DomainPropertyKind } from '../../models/kinds.js'
|
|
2
|
+
import type { DataDomain } from '../DataDomain.js'
|
|
3
|
+
import type { DomainProperty } from '../DomainProperty.js'
|
|
4
|
+
import { type DomainValidation, validatePropertyName } from './rules.js'
|
|
5
|
+
|
|
6
|
+
export class PropertyValidation {
|
|
7
|
+
constructor(protected domain: DataDomain) {}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Performs all the validation rules on the property.
|
|
11
|
+
* If you are interested in a specific rule, use the specific method.
|
|
12
|
+
* @param target The target property to validate. Can be a string with
|
|
13
|
+
* the property key or a DomainProperty object.
|
|
14
|
+
*/
|
|
15
|
+
validate(target: string | DomainProperty): DomainValidation[] {
|
|
16
|
+
const results: DomainValidation[] = []
|
|
17
|
+
let property: DomainProperty | undefined
|
|
18
|
+
if (typeof target === 'string') {
|
|
19
|
+
property = this.domain.findProperty(target)
|
|
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 as string,
|
|
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
|
+
/**
|
|
43
|
+
* Validates the property name.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* - A property must have a name defined.
|
|
47
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
48
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
49
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
50
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
51
|
+
* - (our rule) Column names are case insensitive.
|
|
52
|
+
* - (recommendation) Column names should be in lower case.
|
|
53
|
+
* @param property The property to validate
|
|
54
|
+
*/
|
|
55
|
+
validateName(property: DomainProperty): DomainValidation[] {
|
|
56
|
+
return validatePropertyName(property)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { ReservedKeywords } from './postgresql.js'
|
|
2
|
+
import type { DomainProperty } from '../DomainProperty.js'
|
|
3
|
+
import type { DomainAssociation } from '../DomainAssociation.js'
|
|
4
|
+
import type { DomainImpactItem } from '../DomainImpactAnalysis.js'
|
|
5
|
+
import type { DomainEntity } from '../DomainEntity.js'
|
|
6
|
+
import { DomainPropertyKind } from '../../models/kinds.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `DomainImpactItem` mapping:
|
|
10
|
+
* - `impact` -> `message`
|
|
11
|
+
* - `resolution` -> `help`
|
|
12
|
+
* - `type` -> unused
|
|
13
|
+
* - `blocking` -> unused (deprecated)
|
|
14
|
+
* - `relationship` -> unused
|
|
15
|
+
*/
|
|
16
|
+
export interface DomainValidation
|
|
17
|
+
extends Omit<DomainImpactItem, 'type' | 'impact' | 'blocking' | 'relationship' | 'resolution'> {
|
|
18
|
+
/**
|
|
19
|
+
* The field that did not pass validation.
|
|
20
|
+
*/
|
|
21
|
+
field: string
|
|
22
|
+
/**
|
|
23
|
+
* The name of the rule that was violated.
|
|
24
|
+
*/
|
|
25
|
+
rule: string
|
|
26
|
+
/**
|
|
27
|
+
* Optional help message that can be used to provide
|
|
28
|
+
* more information about the error.
|
|
29
|
+
*/
|
|
30
|
+
help?: string
|
|
31
|
+
/**
|
|
32
|
+
* Optional URL that can be used to provide more information
|
|
33
|
+
* about the error.
|
|
34
|
+
*/
|
|
35
|
+
url?: string
|
|
36
|
+
/**
|
|
37
|
+
* The validation error message.
|
|
38
|
+
* This message should be user-friendly and should not
|
|
39
|
+
* contain any technical details.
|
|
40
|
+
* It should be used to display the error to the user.
|
|
41
|
+
* It should be short and concise.
|
|
42
|
+
*/
|
|
43
|
+
message: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Validates the property name. This includes associations.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* - A property must have a name defined.
|
|
51
|
+
* - The name has to follow the same rules as the names in a PostgreSQL database.
|
|
52
|
+
* - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).
|
|
53
|
+
* - The name must start with a letter (a-z, A-Z) or an underscore (_).
|
|
54
|
+
* - PostgreSQL limits column names to a maximum of 59 characters.
|
|
55
|
+
* - (our rule) Column names are case insensitive.
|
|
56
|
+
* - (recommendation) Column names should be in lower case.
|
|
57
|
+
*
|
|
58
|
+
* @param property The property to validate
|
|
59
|
+
*/
|
|
60
|
+
export function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidation[] {
|
|
61
|
+
const results: DomainValidation[] = []
|
|
62
|
+
const label = property.info.getLabel()
|
|
63
|
+
const parentEntity = property.getParentInstance() as DomainEntity
|
|
64
|
+
const type = property.kind === DomainPropertyKind ? 'property' : 'association'
|
|
65
|
+
if (!property.info.name) {
|
|
66
|
+
const message = `The "${label}" ${type} has no name.`
|
|
67
|
+
const help = `The ${type} must have a name.`
|
|
68
|
+
results.push({
|
|
69
|
+
field: 'name',
|
|
70
|
+
rule: 'required',
|
|
71
|
+
message,
|
|
72
|
+
help,
|
|
73
|
+
severity: 'error',
|
|
74
|
+
key: property.key,
|
|
75
|
+
kind: property.kind,
|
|
76
|
+
parent: parentEntity.key,
|
|
77
|
+
})
|
|
78
|
+
return results
|
|
79
|
+
}
|
|
80
|
+
const name = property.info.name
|
|
81
|
+
if (name.length < 3) {
|
|
82
|
+
const message = `The "${label}" ${type} name is too short.`
|
|
83
|
+
const help = `The name must be at least 3 characters long.`
|
|
84
|
+
results.push({
|
|
85
|
+
field: 'name',
|
|
86
|
+
rule: 'length',
|
|
87
|
+
message,
|
|
88
|
+
help,
|
|
89
|
+
severity: 'error',
|
|
90
|
+
key: property.key,
|
|
91
|
+
kind: property.kind,
|
|
92
|
+
parent: parentEntity.key,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
if (name.length > 59) {
|
|
96
|
+
const message = `The "${label}" ${type} name is too long.`
|
|
97
|
+
const help = `The name must be at most 59 characters long.`
|
|
98
|
+
results.push({
|
|
99
|
+
field: 'name',
|
|
100
|
+
rule: 'length',
|
|
101
|
+
message,
|
|
102
|
+
help,
|
|
103
|
+
severity: 'error',
|
|
104
|
+
key: property.key,
|
|
105
|
+
kind: property.kind,
|
|
106
|
+
parent: parentEntity.key,
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
110
|
+
const message = `The "${label}" ${type} name is invalid.`
|
|
111
|
+
const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`
|
|
112
|
+
results.push({
|
|
113
|
+
field: 'name',
|
|
114
|
+
rule: 'format',
|
|
115
|
+
message,
|
|
116
|
+
help,
|
|
117
|
+
severity: 'error',
|
|
118
|
+
key: property.key,
|
|
119
|
+
kind: property.kind,
|
|
120
|
+
parent: parentEntity.key,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
if (/^[A-Z]/.test(name)) {
|
|
124
|
+
const message = `The "${label}" ${type} name is not in snake case.`
|
|
125
|
+
const help = `The name should be in snake case (lowercase letters and underscores).`
|
|
126
|
+
results.push({
|
|
127
|
+
field: 'name',
|
|
128
|
+
rule: 'snake_case',
|
|
129
|
+
message,
|
|
130
|
+
help,
|
|
131
|
+
severity: 'info',
|
|
132
|
+
key: property.key,
|
|
133
|
+
kind: property.kind,
|
|
134
|
+
parent: parentEntity.key,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
if (ReservedKeywords.has(name.toUpperCase())) {
|
|
138
|
+
const message = `The "${label}" ${type} name is a reserved keyword.`
|
|
139
|
+
const help = `The name should not be a reserved keyword.`
|
|
140
|
+
results.push({
|
|
141
|
+
field: 'name',
|
|
142
|
+
rule: 'reserved',
|
|
143
|
+
message,
|
|
144
|
+
help,
|
|
145
|
+
severity: 'error',
|
|
146
|
+
key: property.key,
|
|
147
|
+
kind: property.kind,
|
|
148
|
+
parent: parentEntity.key,
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
return results
|
|
152
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
2
|
|
|
3
3
|
export interface IAuthorizationData {
|
|
4
4
|
key: string
|
|
@@ -30,7 +30,7 @@ export class AuthorizationData {
|
|
|
30
30
|
init = input
|
|
31
31
|
} else {
|
|
32
32
|
init = {
|
|
33
|
-
key:
|
|
33
|
+
key: nanoid(),
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
this.new(init)
|
|
@@ -42,7 +42,7 @@ export class AuthorizationData {
|
|
|
42
42
|
* Note, this throws an error when the provider is not an API Client provider object.
|
|
43
43
|
*/
|
|
44
44
|
new(init: IAuthorizationData): void {
|
|
45
|
-
const { username, password, domain, key =
|
|
45
|
+
const { username, password, domain, key = nanoid() } = init
|
|
46
46
|
this.username = username
|
|
47
47
|
this.password = password
|
|
48
48
|
this.domain = domain
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
2
|
import { Certificate, ICertificate } from './ClientCertificate.js'
|
|
3
3
|
import { CertificateFileKind } from './kinds.js'
|
|
4
4
|
import { IFile, File } from './store/File.js'
|
|
@@ -48,7 +48,7 @@ export class CertificateFile extends File {
|
|
|
48
48
|
} else {
|
|
49
49
|
init = {
|
|
50
50
|
kind: CertificateFileKind,
|
|
51
|
-
key:
|
|
51
|
+
key: nanoid(),
|
|
52
52
|
organization: '',
|
|
53
53
|
info: Thing.fromName('').toJSON(),
|
|
54
54
|
parents: [],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base64ToBuffer, bufferToBase64 } from '../lib/Buffer.js'
|
|
2
|
-
import
|
|
2
|
+
import { nanoid } from 'nanoid'
|
|
3
3
|
import {
|
|
4
4
|
Certificate as LegacyCertificate,
|
|
5
5
|
ARCCertificateIndex,
|
|
@@ -177,7 +177,7 @@ export class Certificate {
|
|
|
177
177
|
certKey: {
|
|
178
178
|
data: key,
|
|
179
179
|
},
|
|
180
|
-
key:
|
|
180
|
+
key: nanoid(),
|
|
181
181
|
name,
|
|
182
182
|
type: 'pem',
|
|
183
183
|
created: Date.now(),
|
|
@@ -201,7 +201,7 @@ export class Certificate {
|
|
|
201
201
|
cert: {
|
|
202
202
|
data: cert,
|
|
203
203
|
},
|
|
204
|
-
key:
|
|
204
|
+
key: nanoid(),
|
|
205
205
|
name,
|
|
206
206
|
type: 'p12',
|
|
207
207
|
created: Date.now(),
|
|
@@ -220,7 +220,7 @@ export class Certificate {
|
|
|
220
220
|
* to its original format.
|
|
221
221
|
*/
|
|
222
222
|
static fromLegacy(index: ARCCertificateIndex, cert: RequestCertificate): Certificate {
|
|
223
|
-
const { name = '', type, created = Date.now(), _id =
|
|
223
|
+
const { name = '', type, created = Date.now(), _id = nanoid() } = index
|
|
224
224
|
if (type === 'pem') {
|
|
225
225
|
const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert
|
|
226
226
|
const key = Array.isArray(cert.key) ? cert.key[0] : (cert.key as LegacyCertificate)
|
|
@@ -253,7 +253,7 @@ export class Certificate {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
constructor(certificate: HttpCertificate) {
|
|
256
|
-
const { type, cert, key =
|
|
256
|
+
const { type, cert, key = nanoid(), name = '', created = Date.now() } = certificate
|
|
257
257
|
this.key = key
|
|
258
258
|
this.name = name
|
|
259
259
|
this.type = type
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Property, IProperty } from './Property.js'
|
|
2
2
|
import { Server, IServer } from './Server.js'
|
|
3
3
|
import { IThing, Thing } from './Thing.js'
|
|
4
|
-
import
|
|
4
|
+
import { nanoid } from 'nanoid'
|
|
5
5
|
import { ARCVariable } from './legacy/models/Variable.js'
|
|
6
6
|
import { IRequestAuthorization, RequestAuthorization } from './RequestAuthorization.js'
|
|
7
7
|
|
|
@@ -91,7 +91,7 @@ export class Environment {
|
|
|
91
91
|
* @param name The name to set.
|
|
92
92
|
*/
|
|
93
93
|
static fromName(name: string): Environment {
|
|
94
|
-
const key =
|
|
94
|
+
const key = nanoid()
|
|
95
95
|
const info = Thing.fromName(name)
|
|
96
96
|
const definition = new Environment({
|
|
97
97
|
key,
|
|
@@ -103,7 +103,7 @@ export class Environment {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
static fromLegacyVariables(name: string, variables: ARCVariable[]): Environment {
|
|
106
|
-
const key =
|
|
106
|
+
const key = nanoid()
|
|
107
107
|
const info = Thing.fromName(name)
|
|
108
108
|
const definition = new Environment({
|
|
109
109
|
key,
|
|
@@ -132,7 +132,7 @@ export class Environment {
|
|
|
132
132
|
} else {
|
|
133
133
|
init = {
|
|
134
134
|
kind: Kind,
|
|
135
|
-
key:
|
|
135
|
+
key: nanoid(),
|
|
136
136
|
info: Thing.fromName('').toJSON(),
|
|
137
137
|
variables: [],
|
|
138
138
|
}
|
|
@@ -149,7 +149,7 @@ export class Environment {
|
|
|
149
149
|
if (!Environment.isEnvironment(init)) {
|
|
150
150
|
throw new Error(`Not an environment.`)
|
|
151
151
|
}
|
|
152
|
-
const { key =
|
|
152
|
+
const { key = nanoid(), variables, info, server, encapsulated = false, authorization } = init
|
|
153
153
|
this.kind = Kind
|
|
154
154
|
this.key = key
|
|
155
155
|
this.encapsulated = encapsulated
|
|
@@ -262,7 +262,7 @@ export class Environment {
|
|
|
262
262
|
clone(opts: IEnvironmentCloneOptions = {}): Environment {
|
|
263
263
|
const copy = new Environment(this.toJSON())
|
|
264
264
|
if (!opts.withoutRevalidate) {
|
|
265
|
-
copy.key =
|
|
265
|
+
copy.key = nanoid()
|
|
266
266
|
}
|
|
267
267
|
return copy
|
|
268
268
|
}
|
package/src/models/Folder.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFile, File } from './store/File.js'
|
|
2
|
-
import
|
|
2
|
+
import { nanoid } from 'nanoid'
|
|
3
3
|
import { Thing } from './Thing.js'
|
|
4
4
|
import { FolderKind } from './kinds.js'
|
|
5
5
|
|
|
@@ -39,7 +39,7 @@ export class Folder extends File {
|
|
|
39
39
|
} else {
|
|
40
40
|
init = {
|
|
41
41
|
kind: FolderKind,
|
|
42
|
-
key:
|
|
42
|
+
key: nanoid(),
|
|
43
43
|
organization: '',
|
|
44
44
|
info: Thing.fromName('').toJSON(),
|
|
45
45
|
parents: [],
|
package/src/models/HostRule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
2
|
|
|
3
3
|
export const Kind = 'Core#HostRule'
|
|
4
4
|
|
|
@@ -56,7 +56,7 @@ export class HostRule {
|
|
|
56
56
|
|
|
57
57
|
static fromValues(from: string, to: string): HostRule {
|
|
58
58
|
const result = new HostRule({
|
|
59
|
-
key:
|
|
59
|
+
key: nanoid(),
|
|
60
60
|
kind: Kind,
|
|
61
61
|
from,
|
|
62
62
|
to,
|
|
@@ -76,7 +76,7 @@ export class HostRule {
|
|
|
76
76
|
init = input
|
|
77
77
|
} else {
|
|
78
78
|
init = {
|
|
79
|
-
key:
|
|
79
|
+
key: nanoid(),
|
|
80
80
|
kind: Kind,
|
|
81
81
|
from: '',
|
|
82
82
|
to: '',
|
|
@@ -94,7 +94,7 @@ export class HostRule {
|
|
|
94
94
|
if (!HostRule.isHostRule(init)) {
|
|
95
95
|
throw new Error(`Not a HostRule.`)
|
|
96
96
|
}
|
|
97
|
-
const { from = '', to = '', enabled, comment, key =
|
|
97
|
+
const { from = '', to = '', enabled, comment, key = nanoid() } = init
|
|
98
98
|
this.kind = Kind
|
|
99
99
|
this.key = key
|
|
100
100
|
this.from = from
|