@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.
Files changed (187) hide show
  1. package/bin/plugins/sinon/assert.ts +29 -0
  2. package/bin/test.ts +2 -0
  3. package/build/src/amf/AmfShapeGenerator.js +3 -3
  4. package/build/src/amf/AmfShapeGenerator.js.map +1 -1
  5. package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
  6. package/build/src/amf/DataValueGenerator.js +3 -2
  7. package/build/src/amf/DataValueGenerator.js.map +1 -1
  8. package/build/src/amf/models/AmfDataNode.d.ts.map +1 -1
  9. package/build/src/amf/models/AmfDataNode.js +2 -2
  10. package/build/src/amf/models/AmfDataNode.js.map +1 -1
  11. package/build/src/browser.d.ts +4 -0
  12. package/build/src/browser.d.ts.map +1 -1
  13. package/build/src/browser.js +3 -0
  14. package/build/src/browser.js.map +1 -1
  15. package/build/src/index.d.ts +4 -0
  16. package/build/src/index.d.ts.map +1 -1
  17. package/build/src/index.js +3 -0
  18. package/build/src/index.js.map +1 -1
  19. package/build/src/lib/uuid.d.ts +1 -1
  20. package/build/src/lib/uuid.js +1 -1
  21. package/build/src/lib/uuid.js.map +1 -1
  22. package/build/src/mocking/lib/History.js +8 -8
  23. package/build/src/mocking/lib/History.js.map +1 -1
  24. package/build/src/mocking/lib/HostRules.js +1 -1
  25. package/build/src/mocking/lib/HostRules.js.map +1 -1
  26. package/build/src/mocking/lib/User.js +2 -2
  27. package/build/src/mocking/lib/User.js.map +1 -1
  28. package/build/src/modeling/DataDomain.d.ts +4 -0
  29. package/build/src/modeling/DataDomain.d.ts.map +1 -1
  30. package/build/src/modeling/DataDomain.js +13 -3
  31. package/build/src/modeling/DataDomain.js.map +1 -1
  32. package/build/src/modeling/DomainAssociation.js +1 -1
  33. package/build/src/modeling/DomainAssociation.js.map +1 -1
  34. package/build/src/modeling/DomainEntity.d.ts +46 -0
  35. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  36. package/build/src/modeling/DomainEntity.js +71 -0
  37. package/build/src/modeling/DomainEntity.js.map +1 -1
  38. package/build/src/modeling/DomainFile.js +2 -2
  39. package/build/src/modeling/DomainFile.js.map +1 -1
  40. package/build/src/modeling/DomainImpactAnalysis.d.ts +31 -8
  41. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  42. package/build/src/modeling/DomainImpactAnalysis.js +118 -46
  43. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  44. package/build/src/modeling/DomainProperty.js +1 -1
  45. package/build/src/modeling/DomainProperty.js.map +1 -1
  46. package/build/src/modeling/legacy/DataAssociation.js +3 -3
  47. package/build/src/modeling/legacy/DataAssociation.js.map +1 -1
  48. package/build/src/modeling/legacy/DataEntity.js +3 -3
  49. package/build/src/modeling/legacy/DataEntity.js.map +1 -1
  50. package/build/src/modeling/legacy/DataEntityBuilder.js +2 -2
  51. package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -1
  52. package/build/src/modeling/legacy/DataModel.js +3 -3
  53. package/build/src/modeling/legacy/DataModel.js.map +1 -1
  54. package/build/src/modeling/legacy/DataNamespace.js +3 -3
  55. package/build/src/modeling/legacy/DataNamespace.js.map +1 -1
  56. package/build/src/modeling/legacy/DataProperty.js +3 -3
  57. package/build/src/modeling/legacy/DataProperty.js.map +1 -1
  58. package/build/src/modeling/validation/association_validation.d.ts +38 -0
  59. package/build/src/modeling/validation/association_validation.d.ts.map +1 -0
  60. package/build/src/modeling/validation/association_validation.js +108 -0
  61. package/build/src/modeling/validation/association_validation.js.map +1 -0
  62. package/build/src/modeling/validation/entity_validation.d.ts +52 -0
  63. package/build/src/modeling/validation/entity_validation.d.ts.map +1 -0
  64. package/build/src/modeling/validation/entity_validation.js +241 -0
  65. package/build/src/modeling/validation/entity_validation.js.map +1 -0
  66. package/build/src/modeling/validation/postgresql.d.ts +2 -0
  67. package/build/src/modeling/validation/postgresql.d.ts.map +1 -0
  68. package/build/src/modeling/validation/postgresql.js +58 -0
  69. package/build/src/modeling/validation/postgresql.js.map +1 -0
  70. package/build/src/modeling/validation/property_validation.d.ts +29 -0
  71. package/build/src/modeling/validation/property_validation.d.ts.map +1 -0
  72. package/build/src/modeling/validation/property_validation.js +58 -0
  73. package/build/src/modeling/validation/property_validation.js.map +1 -0
  74. package/build/src/modeling/validation/rules.d.ts +55 -0
  75. package/build/src/modeling/validation/rules.d.ts.map +1 -0
  76. package/build/src/modeling/validation/rules.js +110 -0
  77. package/build/src/modeling/validation/rules.js.map +1 -0
  78. package/build/src/models/AuthorizationData.js +3 -3
  79. package/build/src/models/AuthorizationData.js.map +1 -1
  80. package/build/src/models/CertificateFile.js +2 -2
  81. package/build/src/models/CertificateFile.js.map +1 -1
  82. package/build/src/models/ClientCertificate.js +5 -5
  83. package/build/src/models/ClientCertificate.js.map +1 -1
  84. package/build/src/models/Environment.js +6 -6
  85. package/build/src/models/Environment.js.map +1 -1
  86. package/build/src/models/Folder.js +2 -2
  87. package/build/src/models/Folder.js.map +1 -1
  88. package/build/src/models/HostRule.js +4 -4
  89. package/build/src/models/HostRule.js.map +1 -1
  90. package/build/src/models/HttpProject.js +12 -12
  91. package/build/src/models/HttpProject.js.map +1 -1
  92. package/build/src/models/Project.d.ts.map +1 -1
  93. package/build/src/models/Project.js +2 -2
  94. package/build/src/models/Project.js.map +1 -1
  95. package/build/src/models/ProjectFolder.d.ts.map +1 -1
  96. package/build/src/models/ProjectFolder.js +6 -6
  97. package/build/src/models/ProjectFolder.js.map +1 -1
  98. package/build/src/models/ProjectRequest.d.ts.map +1 -1
  99. package/build/src/models/ProjectRequest.js +8 -8
  100. package/build/src/models/ProjectRequest.js.map +1 -1
  101. package/build/src/models/ProjectSchema.js +6 -6
  102. package/build/src/models/ProjectSchema.js.map +1 -1
  103. package/build/src/models/store/DataFile.js +2 -2
  104. package/build/src/models/store/DataFile.js.map +1 -1
  105. package/build/src/models/store/File.d.ts.map +1 -1
  106. package/build/src/models/store/File.js +3 -3
  107. package/build/src/models/store/File.js.map +1 -1
  108. package/build/src/models/store/Organization.js +3 -3
  109. package/build/src/models/store/Organization.js.map +1 -1
  110. package/build/src/models/store/Permission.js +7 -7
  111. package/build/src/models/store/Permission.js.map +1 -1
  112. package/build/src/models/store/UserIdentity.js +3 -3
  113. package/build/src/models/store/UserIdentity.js.map +1 -1
  114. package/build/src/models/transformers/ArcDexieTransformer.js +4 -4
  115. package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
  116. package/build/src/models/transformers/ArcLegacyTransformer.js +3 -3
  117. package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
  118. package/build/src/models/transformers/ArcPouchTransformer.js +2 -2
  119. package/build/src/models/transformers/ArcPouchTransformer.js.map +1 -1
  120. package/build/src/models/transformers/PostmanV21Transformer.js +2 -2
  121. package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
  122. package/build/src/models/transformers/PostmanV2Transformer.js +2 -2
  123. package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
  124. package/build/src/patch/PatchClient.js +2 -2
  125. package/build/src/patch/PatchClient.js.map +1 -1
  126. package/build/src/runtime/store/FilesSdk.js +3 -3
  127. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  128. package/data/models/example-generator-api.json +20 -20
  129. package/package.json +1 -1
  130. package/src/amf/AmfShapeGenerator.ts +3 -3
  131. package/src/amf/DataValueGenerator.ts +3 -2
  132. package/src/amf/models/AmfDataNode.ts +2 -2
  133. package/src/lib/uuid.ts +1 -1
  134. package/src/mocking/lib/History.ts +8 -8
  135. package/src/mocking/lib/HostRules.ts +1 -1
  136. package/src/mocking/lib/User.ts +2 -2
  137. package/src/modeling/DataDomain.ts +14 -3
  138. package/src/modeling/DomainAssociation.ts +1 -1
  139. package/src/modeling/DomainEntity.ts +75 -0
  140. package/src/modeling/DomainFile.ts +2 -2
  141. package/src/modeling/DomainImpactAnalysis.ts +144 -54
  142. package/src/modeling/DomainProperty.ts +1 -1
  143. package/src/modeling/legacy/DataAssociation.ts +3 -3
  144. package/src/modeling/legacy/DataEntity.ts +3 -3
  145. package/src/modeling/legacy/DataEntityBuilder.ts +2 -2
  146. package/src/modeling/legacy/DataModel.ts +3 -3
  147. package/src/modeling/legacy/DataNamespace.ts +3 -3
  148. package/src/modeling/legacy/DataProperty.ts +3 -3
  149. package/src/modeling/validation/association_validation.ts +109 -0
  150. package/src/modeling/validation/entity_validation.ts +246 -0
  151. package/src/modeling/validation/postgresql.ts +57 -0
  152. package/src/modeling/validation/property_validation.ts +58 -0
  153. package/src/modeling/validation/rules.ts +152 -0
  154. package/src/models/AuthorizationData.ts +3 -3
  155. package/src/models/CertificateFile.ts +2 -2
  156. package/src/models/ClientCertificate.ts +5 -5
  157. package/src/models/Environment.ts +6 -6
  158. package/src/models/Folder.ts +2 -2
  159. package/src/models/HostRule.ts +4 -4
  160. package/src/models/HttpProject.ts +12 -12
  161. package/src/models/Project.ts +2 -2
  162. package/src/models/ProjectFolder.ts +6 -6
  163. package/src/models/ProjectRequest.ts +8 -8
  164. package/src/models/ProjectSchema.ts +6 -6
  165. package/src/models/store/DataFile.ts +2 -2
  166. package/src/models/store/File.ts +3 -3
  167. package/src/models/store/Organization.ts +3 -3
  168. package/src/models/store/Permission.ts +7 -7
  169. package/src/models/store/UserIdentity.ts +3 -3
  170. package/src/models/transformers/ArcDexieTransformer.ts +4 -4
  171. package/src/models/transformers/ArcLegacyTransformer.ts +3 -3
  172. package/src/models/transformers/ArcPouchTransformer.ts +2 -2
  173. package/src/models/transformers/PostmanV21Transformer.ts +2 -2
  174. package/src/models/transformers/PostmanV2Transformer.ts +2 -2
  175. package/src/patch/PatchClient.ts +2 -2
  176. package/src/runtime/store/FilesSdk.ts +3 -3
  177. package/tests/unit/modeling/data_domain_associations.spec.ts +1 -1
  178. package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
  179. package/tests/unit/modeling/domain.property.spec.ts +7 -7
  180. package/tests/unit/modeling/domain_asociation.spec.ts +3 -3
  181. package/tests/unit/modeling/domain_entity_associations.spec.ts +1 -1
  182. package/tests/unit/modeling/domain_entity_properties.spec.ts +2 -2
  183. package/tests/unit/modeling/domain_impact_analysis.spec.ts +138 -29
  184. package/tests/unit/modeling/validation/association_validation.spec.ts +140 -0
  185. package/tests/unit/modeling/validation/entity_validation.spec.ts +192 -0
  186. package/tests/unit/modeling/validation/property_validation.spec.ts +125 -0
  187. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +8 -8
@@ -0,0 +1,192 @@
1
+ import { test } from '@japa/runner'
2
+ import { DataDomain, EntityValidation } from '../../../../src/index.js'
3
+
4
+ test.group('EntityValidation', (group) => {
5
+ let domain: DataDomain
6
+ let validation: EntityValidation
7
+
8
+ group.each.setup(() => {
9
+ domain = new DataDomain()
10
+ validation = new EntityValidation(domain)
11
+ })
12
+
13
+ test('validate() should return an error when the entity does not exist', ({ assert }) => {
14
+ const results = validation.validate('nonExistentEntity')
15
+ assert.lengthOf(results, 1)
16
+ assert.equal(results[0].rule, 'exists')
17
+ assert.equal(results[0].severity, 'error')
18
+ })
19
+
20
+ test('validate() should call other validation methods', ({ assert, sinon }) => {
21
+ const model = domain.addModel({ key: 'model' })
22
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
23
+ const primaryKeySpy = sinon.spy(validation, 'validatePrimaryKey')
24
+ const minimumRequiredPropertiesSpy = sinon.spy(validation, 'minimumRequiredProperties')
25
+ const validateNameSpy = sinon.spy(validation, 'validateName')
26
+ const uniqueNameSpy = sinon.spy(validation, 'uniqueName')
27
+
28
+ validation.validate(entity)
29
+
30
+ assert.calledWith(primaryKeySpy, entity)
31
+ assert.calledWith(minimumRequiredPropertiesSpy, entity)
32
+ assert.calledWith(validateNameSpy, entity)
33
+ assert.calledWith(uniqueNameSpy, entity)
34
+ sinon.restore()
35
+ })
36
+
37
+ test('validatePrimaryKey() should return an error when the entity has no primary key', ({ assert }) => {
38
+ const model = domain.addModel({ key: 'model' })
39
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
40
+ const results = validation.validatePrimaryKey(entity)
41
+ assert.lengthOf(results, 1)
42
+ assert.equal(results[0].rule, 'primary_key')
43
+ assert.equal(results[0].severity, 'error')
44
+ })
45
+
46
+ test('validatePrimaryKey() should return no errors when the entity has a primary key', ({ assert }) => {
47
+ const model = domain.addModel({ key: 'model' })
48
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
49
+ entity.addProperty({ key: 'id', type: 'string', primary: true })
50
+ const results = validation.validatePrimaryKey(entity)
51
+ assert.lengthOf(results, 0)
52
+ })
53
+
54
+ test('validatePrimaryKey() should return no errors when the entity inherits a primary key', ({ assert }) => {
55
+ const model = domain.addModel({ key: 'model' })
56
+ const parent = model.addEntity({ key: 'parent', info: { name: 'Parent' } })
57
+ parent.addProperty({ key: 'id', type: 'string', primary: true })
58
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
59
+ entity.addParent(parent.key)
60
+ const results = validation.validatePrimaryKey(entity)
61
+ assert.lengthOf(results, 0)
62
+ })
63
+
64
+ test('minimumRequiredProperties() should return a warning when the entity has no properties', ({ assert }) => {
65
+ const model = domain.addModel({ key: 'model' })
66
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
67
+ const results = validation.minimumRequiredProperties(entity)
68
+ assert.lengthOf(results, 1)
69
+ assert.equal(results[0].rule, 'required')
70
+ assert.equal(results[0].severity, 'warning')
71
+ })
72
+
73
+ test('minimumRequiredProperties() should return no errors when the entity has properties', ({ assert }) => {
74
+ const model = domain.addModel({ key: 'model' })
75
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
76
+ entity.addProperty({ key: 'name', type: 'string' })
77
+ const results = validation.minimumRequiredProperties(entity)
78
+ assert.lengthOf(results, 0)
79
+ })
80
+
81
+ test('validateName() should return an error when the entity has no name', ({ assert }) => {
82
+ const model = domain.addModel({ key: 'model' })
83
+ const entity = model.addEntity({ key: 'entity', info: {} })
84
+ entity.info.name = undefined
85
+ const results = validation.validateName(entity)
86
+ assert.lengthOf(results, 1)
87
+ assert.equal(results[0].rule, 'required')
88
+ assert.equal(results[0].severity, 'error')
89
+ })
90
+
91
+ test('validateName() should return an error when the entity name is too short', ({ assert }) => {
92
+ const model = domain.addModel({ key: 'model' })
93
+ const entity = model.addEntity({ key: 'entity', info: { name: 'ab' } })
94
+ const results = validation.validateName(entity)
95
+ assert.lengthOf(results, 1)
96
+ assert.equal(results[0].rule, 'length')
97
+ assert.equal(results[0].severity, 'error')
98
+ })
99
+
100
+ test('validateName() should return an error when the entity name is too long', ({ assert }) => {
101
+ const model = domain.addModel({ key: 'model' })
102
+ const entity = model.addEntity({ key: 'entity', info: { name: 'a'.repeat(32) } })
103
+ const results = validation.validateName(entity)
104
+ assert.lengthOf(results, 1)
105
+ assert.equal(results[0].rule, 'length')
106
+ assert.equal(results[0].severity, 'error')
107
+ })
108
+
109
+ test('validateName() should return an error when the entity name has invalid characters', ({ assert }) => {
110
+ const model = domain.addModel({ key: 'model' })
111
+ const entity = model.addEntity({ key: 'entity', info: { name: 'invalid-name' } })
112
+ const results = validation.validateName(entity)
113
+ assert.lengthOf(results, 1)
114
+ assert.equal(results[0].rule, 'format')
115
+ assert.equal(results[0].severity, 'error')
116
+ })
117
+
118
+ test('validateName() should return an info when the entity name is not in snake case', ({ assert }) => {
119
+ const model = domain.addModel({ key: 'model' })
120
+ const entity = model.addEntity({ key: 'entity', info: { name: 'EntityName' } })
121
+ const results = validation.validateName(entity)
122
+ assert.lengthOf(results, 1)
123
+ assert.equal(results[0].rule, 'snake_case')
124
+ assert.equal(results[0].severity, 'info')
125
+ })
126
+
127
+ test('validateName() should return an error when the entity name is a reserved keyword', ({ assert }) => {
128
+ const model = domain.addModel({ key: 'model' })
129
+ const entity = model.addEntity({ key: 'entity', info: { name: 'select' } })
130
+ const results = validation.validateName(entity)
131
+ assert.lengthOf(results, 1)
132
+ assert.equal(results[0].rule, 'reserved')
133
+ assert.equal(results[0].severity, 'error')
134
+ })
135
+
136
+ test('validateName() should return no errors when the entity name is valid', ({ assert }) => {
137
+ const model = domain.addModel({ key: 'model' })
138
+ const entity = model.addEntity({ key: 'entity', info: { name: 'valid_name' } })
139
+ const results = validation.validateName(entity)
140
+ assert.lengthOf(results, 0)
141
+ })
142
+
143
+ test('uniqueName() should return an error when the entity name is not unique', ({ assert }) => {
144
+ const model = domain.addModel({ key: 'model' })
145
+ model.addEntity({ key: 'entity1', info: { name: 'entity_name' } })
146
+ const entity2 = model.addEntity({ key: 'entity2', info: { name: 'entity_name' } })
147
+ const results = validation.uniqueName(entity2)
148
+ assert.lengthOf(results, 1)
149
+ assert.equal(results[0].rule, 'unique')
150
+ assert.equal(results[0].severity, 'error')
151
+ })
152
+
153
+ test('uniqueName() should return no errors when the entity name is unique', ({ assert }) => {
154
+ const model = domain.addModel({ key: 'model' })
155
+ model.addEntity({ key: 'entity1', info: { name: 'entity_name_1' } })
156
+ const entity2 = model.addEntity({ key: 'entity2', info: { name: 'entity_name_2' } })
157
+ const results = validation.uniqueName(entity2)
158
+ assert.lengthOf(results, 0)
159
+ })
160
+
161
+ test('uniqueName() should return an error when the entity name is not unique (case insensitive)', ({ assert }) => {
162
+ const model = domain.addModel({ key: 'model' })
163
+ model.addEntity({ key: 'entity1', info: { name: 'Entity_Name1' } })
164
+ const entity2 = model.addEntity({ key: 'entity2', info: { name: 'entity_name1' } })
165
+ const results = validation.uniqueName(entity2)
166
+ assert.lengthOf(results, 1)
167
+ assert.equal(results[0].rule, 'unique')
168
+ assert.equal(results[0].severity, 'error')
169
+ })
170
+
171
+ test('uniqueName() should return no errors when the entity name is not set', ({ assert }) => {
172
+ const model = domain.addModel({ key: 'model' })
173
+ model.addEntity({ key: 'entity1', info: { name: 'EntityName1' } })
174
+ const entity2 = model.addEntity({ key: 'entity2', info: {} })
175
+ const results = validation.uniqueName(entity2)
176
+ assert.lengthOf(results, 0)
177
+ })
178
+
179
+ test('uniqueName() should return an error when the entity name is not unique in a foreign domain', ({ assert }) => {
180
+ const foreignDomain = new DataDomain()
181
+ const foreignModel = foreignDomain.addModel({ key: 'foreignModel' })
182
+ foreignModel.addEntity({ key: 'foreignEntity', info: { name: 'entity_name' } })
183
+ foreignDomain.info.version = '1.0.0'
184
+ domain.registerForeignDomain(foreignDomain)
185
+ const model = domain.addModel({ key: 'model' })
186
+ const entity2 = model.addEntity({ key: 'entity2', info: { name: 'entity_name' } })
187
+ const results = validation.uniqueName(entity2)
188
+ assert.lengthOf(results, 1)
189
+ assert.equal(results[0].rule, 'unique')
190
+ assert.equal(results[0].severity, 'error')
191
+ })
192
+ })
@@ -0,0 +1,125 @@
1
+ import { test } from '@japa/runner'
2
+ import { DataDomain, PropertyValidation } from '../../../../src/index.js'
3
+
4
+ test.group('PropertyValidation', (group) => {
5
+ let domain: DataDomain
6
+ let validation: PropertyValidation
7
+
8
+ group.each.setup(() => {
9
+ domain = new DataDomain()
10
+ validation = new PropertyValidation(domain)
11
+ })
12
+
13
+ test('validate() should return an error when the property does not exist', ({ assert }) => {
14
+ const results = validation.validate('nonExistentProperty')
15
+ assert.lengthOf(results, 1)
16
+ assert.equal(results[0].rule, 'exists')
17
+ assert.equal(results[0].severity, 'error')
18
+ })
19
+
20
+ test('validate() should call other validation methods', ({ assert, sinon }) => {
21
+ const model = domain.addModel({ key: 'model' })
22
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
23
+ const property = entity.addProperty({ key: 'property', type: 'string', info: { name: 'property' } })
24
+ const validateNameSpy = sinon.spy(validation, 'validateName')
25
+
26
+ validation.validate(property)
27
+
28
+ assert.calledWith(validateNameSpy, property)
29
+ sinon.restore()
30
+ })
31
+
32
+ test('validateName() should return an error when the property has no name', ({ assert }) => {
33
+ const model = domain.addModel({ key: 'model' })
34
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
35
+ const property = entity.addProperty({ key: 'property', type: 'string' })
36
+ property.info.name = undefined
37
+ const results = validation.validateName(property)
38
+ assert.lengthOf(results, 1)
39
+ assert.equal(results[0].rule, 'required')
40
+ assert.equal(results[0].severity, 'error')
41
+ })
42
+
43
+ test('validateName() should return an error when the property name starts with a number', ({ assert }) => {
44
+ const model = domain.addModel({ key: 'model' })
45
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
46
+ const property = entity.addProperty({ key: '1property', type: 'string', info: { name: '1property' } })
47
+ const results = validation.validateName(property)
48
+ assert.lengthOf(results, 1)
49
+ assert.equal(results[0].rule, 'format')
50
+ assert.equal(results[0].severity, 'error')
51
+ })
52
+
53
+ test('validateName() should return an error when the property name contains invalid characters', ({ assert }) => {
54
+ const model = domain.addModel({ key: 'model' })
55
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
56
+ const property = entity.addProperty({
57
+ key: 'invalid-property!',
58
+ type: 'string',
59
+ info: { name: 'invalid-property!' },
60
+ })
61
+ const results = validation.validateName(property)
62
+ assert.lengthOf(results, 1)
63
+ assert.equal(results[0].rule, 'format')
64
+ assert.equal(results[0].severity, 'error')
65
+ })
66
+
67
+ test('validateName() should return an error when the property name is too long', ({ assert }) => {
68
+ const model = domain.addModel({ key: 'model' })
69
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
70
+ const property = entity.addProperty({ key: 'a'.repeat(60), type: 'string', info: { name: 'a'.repeat(60) } })
71
+ const results = validation.validateName(property)
72
+ assert.lengthOf(results, 1)
73
+ assert.equal(results[0].rule, 'length')
74
+ assert.equal(results[0].severity, 'error')
75
+ })
76
+
77
+ test('validateName() should return no errors when the property name is valid', ({ assert }) => {
78
+ const model = domain.addModel({ key: 'model' })
79
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
80
+ const property = entity.addProperty({
81
+ key: 'valid_property123',
82
+ type: 'string',
83
+ info: { name: 'valid_property123' },
84
+ })
85
+ const results = validation.validateName(property)
86
+ assert.lengthOf(results, 0)
87
+ })
88
+
89
+ test('validateName() should return no errors when the property name starts with underscore', ({ assert }) => {
90
+ const model = domain.addModel({ key: 'model' })
91
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
92
+ const property = entity.addProperty({ key: '_property', type: 'string', info: { name: '_property' } })
93
+ const results = validation.validateName(property)
94
+ assert.lengthOf(results, 0)
95
+ })
96
+
97
+ test('validate() should return an error when the target property is not found (string)', ({ assert }) => {
98
+ const model = domain.addModel({ key: 'model' })
99
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
100
+ entity.addProperty({ key: 'existingProperty', type: 'string', info: { name: 'existing_property' } })
101
+ const results = validation.validate('nonExistingProperty')
102
+ assert.lengthOf(results, 1)
103
+ assert.equal(results[0].rule, 'exists')
104
+ assert.equal(results[0].severity, 'error')
105
+ assert.equal(results[0].key, 'nonExistingProperty')
106
+ })
107
+
108
+ test('validate() should return validation errors for an invalid property name', ({ assert }) => {
109
+ const model = domain.addModel({ key: 'model' })
110
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
111
+ const property = entity.addProperty({ key: 'invalid-name', type: 'string', info: { name: 'invalid-name' } })
112
+ const results = validation.validate(property)
113
+ assert.lengthOf(results, 1)
114
+ assert.equal(results[0].rule, 'format')
115
+ assert.equal(results[0].severity, 'error')
116
+ })
117
+
118
+ test('validate() should return no errors for a valid property name', ({ assert }) => {
119
+ const model = domain.addModel({ key: 'model' })
120
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
121
+ const property = entity.addProperty({ key: 'valid_name', type: 'string', info: { name: 'valid_name' } })
122
+ const results = validation.validate(property)
123
+ assert.lengthOf(results, 0)
124
+ })
125
+ })
@@ -1,6 +1,6 @@
1
1
  import nock from 'nock'
2
2
  import { test } from '@japa/runner'
3
- import { randomUUID } from 'node:crypto'
3
+ import { nanoid } from 'nanoid'
4
4
  import {
5
5
  HttpProject,
6
6
  HttpProjectKind,
@@ -36,7 +36,7 @@ test.group('net-store project', (group) => {
36
36
  test('returns an error when no pid', async ({ assert }) => {
37
37
  const message: IHttpProjectStoreProxyInit = {
38
38
  kind: HttpProjectKind,
39
- organization: randomUUID(),
39
+ organization: nanoid(),
40
40
  pid: '',
41
41
  options: {},
42
42
  }
@@ -61,7 +61,7 @@ test.group('net-store project', (group) => {
61
61
  const message: IHttpProjectStoreProxyInit = {
62
62
  kind: HttpProjectKind,
63
63
  pid: project.key,
64
- organization: randomUUID(),
64
+ organization: nanoid(),
65
65
  }
66
66
  const path = RouteBuilder.fileMedia(message.organization, project.key)
67
67
  const scope = nock(storeHostname).get(path).reply(200, project.toJSON())
@@ -84,7 +84,7 @@ test.group('net-store project', (group) => {
84
84
  kind: HttpProjectKind,
85
85
  pid: project.key,
86
86
  options: {},
87
- organization: randomUUID(),
87
+ organization: nanoid(),
88
88
  }
89
89
  const path = RouteBuilder.fileMedia(message.organization, project.key)
90
90
  const scope = nock(storeHostname).get(path).reply(200, project.toJSON())
@@ -106,7 +106,7 @@ test.group('net-store project', (group) => {
106
106
  kind: HttpProjectKind,
107
107
  pid: project.key,
108
108
  options: {},
109
- organization: randomUUID(),
109
+ organization: nanoid(),
110
110
  }
111
111
  const path = RouteBuilder.fileMedia(message.organization, project.key)
112
112
  const scope = nock(storeHostname).get(path).reply(200, project.toJSON())
@@ -129,7 +129,7 @@ test.group('net-store project', (group) => {
129
129
  kind: HttpProjectKind,
130
130
  pid: project.key,
131
131
  options: {},
132
- organization: randomUUID(),
132
+ organization: nanoid(),
133
133
  }
134
134
  const path = RouteBuilder.fileMedia(message.organization, project.key)
135
135
  const scope = nock(storeHostname).get(path).reply(200, project.toJSON())
@@ -152,7 +152,7 @@ test.group('net-store project', (group) => {
152
152
  kind: HttpProjectKind,
153
153
  pid: project.key,
154
154
  options: {},
155
- organization: randomUUID(),
155
+ organization: nanoid(),
156
156
  }
157
157
  const path = RouteBuilder.fileMedia(message.organization, project.key)
158
158
  nock(storeHostname).get(path).reply(404, new ApiError('Not found', 404).toJSON())
@@ -173,7 +173,7 @@ test.group('net-store project', (group) => {
173
173
  kind: HttpProjectKind,
174
174
  pid: project.key,
175
175
  options: {},
176
- organization: randomUUID(),
176
+ organization: nanoid(),
177
177
  }
178
178
  const path = RouteBuilder.fileMedia(message.organization, project.key)
179
179
  nock(storeHostname).get(path).reply(200, project.toJSON(), { 'x-version': '1' })