@api-client/core 0.13.6 → 0.14.1
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/build/src/amf/AmfTypes.d.ts +1 -1
- package/build/src/amf/AmfTypes.js +1 -1
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/Utils.d.ts +0 -6
- package/build/src/amf/Utils.d.ts.map +1 -1
- package/build/src/amf/Utils.js +0 -14
- package/build/src/amf/Utils.js.map +1 -1
- package/build/src/browser.d.ts +1 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/legacy.d.ts +0 -8
- package/build/src/legacy.d.ts.map +1 -1
- package/build/src/legacy.js +0 -9
- package/build/src/legacy.js.map +1 -1
- package/build/src/modeling/Bindings.d.ts +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataDomain.js +2 -2
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DataFormat.d.ts +0 -40
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +0 -27
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +28 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +73 -4
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +25 -9
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +65 -21
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.d.ts +3 -4
- package/build/src/modeling/DomainFile.d.ts.map +1 -1
- package/build/src/modeling/DomainFile.js +5 -9
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +3 -3
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +2 -2
- package/build/src/modeling/DomainModel.js +2 -2
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +28 -12
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +61 -26
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts +109 -0
- package/build/src/modeling/Semantics.d.ts.map +1 -0
- package/build/src/modeling/Semantics.js +97 -0
- package/build/src/modeling/Semantics.js.map +1 -0
- package/build/src/models/CertificateFile.d.ts +2 -3
- package/build/src/models/CertificateFile.d.ts.map +1 -1
- package/build/src/models/CertificateFile.js +4 -8
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/Folder.d.ts +1 -2
- package/build/src/models/Folder.d.ts.map +1 -1
- package/build/src/models/Folder.js +2 -4
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/Project.d.ts +2 -3
- package/build/src/models/Project.d.ts.map +1 -1
- package/build/src/models/Project.js +4 -8
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/kinds.d.ts +0 -24
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +0 -24
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/File.d.ts +1 -21
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +3 -23
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/data_catalog.d.ts +1 -1
- package/build/src/models/store/data_catalog.js.map +1 -1
- package/build/src/sdk/FilesSdk.js +1 -1
- package/build/src/sdk/FilesSdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +22 -22
- package/eslint.config.js +1 -0
- package/package.json +5 -5
- package/src/amf/AmfTypes.ts +1 -1
- package/src/amf/Utils.ts +0 -15
- package/src/modeling/Bindings.ts +1 -1
- package/src/modeling/DataDomain.ts +2 -2
- package/src/modeling/DataFormat.ts +0 -48
- package/src/modeling/DomainAssociation.ts +66 -3
- package/src/modeling/DomainEntity.ts +56 -17
- package/src/modeling/DomainFile.ts +5 -9
- package/src/modeling/DomainImpactAnalysis.ts +3 -3
- package/src/modeling/DomainModel.ts +2 -2
- package/src/modeling/DomainProperty.ts +60 -21
- package/src/modeling/Semantics.ts +178 -0
- package/src/modeling/graph.md +14 -14
- package/src/modeling/readme.md +29 -29
- package/src/models/CertificateFile.ts +4 -12
- package/src/models/Folder.ts +2 -4
- package/src/models/Project.ts +4 -8
- package/src/models/kinds.ts +0 -25
- package/src/models/store/File.ts +4 -35
- package/src/models/store/data_catalog.ts +1 -1
- package/src/sdk/FilesSdk.ts +1 -1
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
- package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
- package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
- package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
- package/tests/unit/modeling/domain_entity.spec.ts +27 -26
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
- package/tests/unit/modeling/domain_file.spec.ts +4 -27
- package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
- package/tests/unit/models/Certificate/from_name.spec.ts +3 -15
- package/tests/unit/models/File/constructor.spec.ts +0 -1
- package/tests/unit/models/File/new.spec.ts +0 -13
- package/tests/unit/models/File/shortcutTo.spec.ts +1 -2
- package/tests/unit/models/File/toJSON.spec.ts +0 -13
- package/tests/unit/models/File/updateByMeMeta.spec.ts +4 -6
- package/tests/unit/models/Folder/create.spec.ts +2 -23
- package/tests/unit/models/Project/create.spec.ts +6 -32
- package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
- package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
- package/build/src/amf/AmfShapeGenerator.js +0 -416
- package/build/src/amf/AmfShapeGenerator.js.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
- package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.js +0 -443
- package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
- package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
- package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntity.js +0 -855
- package/build/src/modeling/legacy/DataEntity.js.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
- package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
- package/build/src/modeling/legacy/DataModel.d.ts +0 -99
- package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataModel.js +0 -237
- package/build/src/modeling/legacy/DataModel.js.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
- package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.js +0 -784
- package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
- package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
- package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataProperty.js +0 -415
- package/build/src/modeling/legacy/DataProperty.js.map +0 -1
- package/build/src/models/store/DataFile.d.ts +0 -31
- package/build/src/models/store/DataFile.d.ts.map +0 -1
- package/build/src/models/store/DataFile.js +0 -92
- package/build/src/models/store/DataFile.js.map +0 -1
- package/src/amf/AmfShapeGenerator.ts +0 -477
- package/src/modeling/legacy/DataAssociation.ts +0 -554
- package/src/modeling/legacy/DataEntity.ts +0 -1019
- package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
- package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
- package/src/modeling/legacy/DataModel.ts +0 -276
- package/src/modeling/legacy/DataNamespace.ts +0 -929
- package/src/modeling/legacy/DataProperty.ts +0 -630
- package/src/models/store/DataFile.ts +0 -100
- package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
- package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
- package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
- package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
- package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
- package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
- package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
- package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
- package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
|
@@ -1,1312 +0,0 @@
|
|
|
1
|
-
import { test } from '@japa/runner'
|
|
2
|
-
import { Thing, DataNamespaceKind } from '../../../../src/index.js'
|
|
3
|
-
import { DataEntity, DataItem, DataModel, DataNamespace, IDataNamespace } from '../../../../src/legacy.js'
|
|
4
|
-
|
|
5
|
-
test.group('constructor() defaults', () => {
|
|
6
|
-
test('sets the kind', ({ assert }) => {
|
|
7
|
-
const ns = new DataNamespace()
|
|
8
|
-
assert.equal(ns.kind, DataNamespaceKind)
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('sets the key', ({ assert }) => {
|
|
12
|
-
const ns = new DataNamespace()
|
|
13
|
-
assert.typeOf(ns.key, 'string')
|
|
14
|
-
assert.isNotEmpty(ns.key)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test('sets the default "info"', ({ assert }) => {
|
|
18
|
-
const ns = new DataNamespace()
|
|
19
|
-
assert.typeOf(ns.info, 'EventTarget')
|
|
20
|
-
assert.equal(ns.info.name, '')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('sets the default "items"', ({ assert }) => {
|
|
24
|
-
const ns = new DataNamespace()
|
|
25
|
-
assert.deepEqual(ns.items, [])
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('has no "root" when no parent', ({ assert }) => {
|
|
29
|
-
const ns = new DataNamespace()
|
|
30
|
-
assert.isUndefined(ns.root)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
test('sets the "root" when passed parent', ({ assert }) => {
|
|
34
|
-
const parent = new DataNamespace()
|
|
35
|
-
const ns = new DataNamespace(undefined, parent)
|
|
36
|
-
assert.deepEqual(ns.root, parent)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('sets the default "definitions"', ({ assert }) => {
|
|
40
|
-
const ns = new DataNamespace()
|
|
41
|
-
assert.typeOf(ns.definitions, 'object')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('sets the default "definitions.models"', ({ assert }) => {
|
|
45
|
-
const ns = new DataNamespace()
|
|
46
|
-
assert.deepEqual(ns.definitions.models, [])
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
test('sets the default "definitions.tags"', ({ assert }) => {
|
|
50
|
-
const ns = new DataNamespace()
|
|
51
|
-
assert.deepEqual(ns.definitions.tags, [])
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('sets the default "definitions.associations"', ({ assert }) => {
|
|
55
|
-
const ns = new DataNamespace()
|
|
56
|
-
assert.deepEqual(ns.definitions.associations, [])
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test('sets the default "definitions.entities"', ({ assert }) => {
|
|
60
|
-
const ns = new DataNamespace()
|
|
61
|
-
assert.deepEqual(ns.definitions.entities, [])
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('sets the default "definitions.properties"', ({ assert }) => {
|
|
65
|
-
const ns = new DataNamespace()
|
|
66
|
-
assert.deepEqual(ns.definitions.properties, [])
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test('sets the default "definitions.namespaces"', ({ assert }) => {
|
|
70
|
-
const ns = new DataNamespace()
|
|
71
|
-
assert.deepEqual(ns.definitions.namespaces, [])
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test.group('constructor() from schema initialization', () => {
|
|
76
|
-
test('sets the key', ({ assert }) => {
|
|
77
|
-
const orig = new DataNamespace().toJSON()
|
|
78
|
-
orig.key = 'test'
|
|
79
|
-
const instance = new DataNamespace(orig)
|
|
80
|
-
assert.equal(instance.key, 'test')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test('sets the info', ({ assert }) => {
|
|
84
|
-
const orig = new DataNamespace().toJSON()
|
|
85
|
-
orig.info.name = 'test'
|
|
86
|
-
const instance = new DataNamespace(orig)
|
|
87
|
-
assert.equal(instance.info.name, 'test')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('initializes from JSON schema ', ({ assert }) => {
|
|
91
|
-
const orig = new DataNamespace().toJSON()
|
|
92
|
-
orig.key = 'test'
|
|
93
|
-
const instance = new DataNamespace(JSON.stringify(orig))
|
|
94
|
-
assert.equal(instance.key, 'test')
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
test.group('fromName()', () => {
|
|
99
|
-
test('sets the name', ({ assert }) => {
|
|
100
|
-
const ns = DataNamespace.fromName('test')
|
|
101
|
-
assert.equal(ns.info.name, 'test')
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test.group('new()', (group) => {
|
|
106
|
-
let base: IDataNamespace
|
|
107
|
-
group.each.setup(() => {
|
|
108
|
-
base = {
|
|
109
|
-
info: Thing.fromName('test name').toJSON(),
|
|
110
|
-
key: 'test123',
|
|
111
|
-
kind: DataNamespaceKind,
|
|
112
|
-
items: [],
|
|
113
|
-
definitions: {},
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('sets the key', ({ assert }) => {
|
|
118
|
-
const ns = new DataNamespace()
|
|
119
|
-
ns.new(base)
|
|
120
|
-
assert.equal(ns.key, 'test123')
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test('sets the info', ({ assert }) => {
|
|
124
|
-
const ns = new DataNamespace()
|
|
125
|
-
ns.new(base)
|
|
126
|
-
assert.equal(ns.info.name, 'test name')
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test('sets default info', ({ assert }) => {
|
|
130
|
-
const ns = new DataNamespace()
|
|
131
|
-
// @ts-expect-error Used in testing
|
|
132
|
-
delete base.info
|
|
133
|
-
ns.new(base)
|
|
134
|
-
assert.equal(ns.info.name, '')
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test('throws when unknown input', ({ assert }) => {
|
|
138
|
-
const ns = new DataNamespace()
|
|
139
|
-
assert.throws(() => {
|
|
140
|
-
// @ts-expect-error Used in testing
|
|
141
|
-
ns.new({})
|
|
142
|
-
}, 'Not a data namespace.')
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
test('sets the "definitions.namespaces"', ({ assert }) => {
|
|
146
|
-
const ns = new DataNamespace()
|
|
147
|
-
ns.addNamespace('n1')
|
|
148
|
-
const instance = new DataNamespace()
|
|
149
|
-
instance.new(ns.toJSON())
|
|
150
|
-
assert.lengthOf(instance.definitions.namespaces, 1)
|
|
151
|
-
instance.new(base)
|
|
152
|
-
assert.lengthOf(instance.definitions.namespaces, 0)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('sets the "definitions.models"', ({ assert }) => {
|
|
156
|
-
const ns = new DataNamespace()
|
|
157
|
-
ns.addDataModel('d1')
|
|
158
|
-
const instance = new DataNamespace()
|
|
159
|
-
instance.new(ns.toJSON())
|
|
160
|
-
assert.lengthOf(instance.definitions.models, 1)
|
|
161
|
-
instance.new(base)
|
|
162
|
-
assert.lengthOf(instance.definitions.models, 0)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
test('sets the "definitions.tags"', ({ assert }) => {
|
|
166
|
-
const ns = new DataNamespace()
|
|
167
|
-
ns.definitions.tags = ['a']
|
|
168
|
-
const instance = new DataNamespace()
|
|
169
|
-
instance.new(ns.toJSON())
|
|
170
|
-
assert.lengthOf(instance.definitions.tags, 1)
|
|
171
|
-
instance.new(base)
|
|
172
|
-
assert.lengthOf(instance.definitions.tags, 0)
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
test('sets the "definitions.entities"', ({ assert }) => {
|
|
176
|
-
const ns = new DataNamespace()
|
|
177
|
-
const d1 = ns.addDataModel('d1')
|
|
178
|
-
d1.addEntity('e1')
|
|
179
|
-
const instance = new DataNamespace()
|
|
180
|
-
instance.new(ns.toJSON())
|
|
181
|
-
assert.lengthOf(instance.definitions.entities, 1)
|
|
182
|
-
instance.new(base)
|
|
183
|
-
assert.lengthOf(instance.definitions.entities, 0)
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
test('sets entities on the corresponding data model', ({ assert }) => {
|
|
187
|
-
const ns = new DataNamespace()
|
|
188
|
-
const d1 = ns.addDataModel('d1')
|
|
189
|
-
const e1 = d1.addEntity('e1')
|
|
190
|
-
const instance = new DataNamespace()
|
|
191
|
-
instance.new(ns.toJSON())
|
|
192
|
-
const model = instance.findDataModel(d1.key)!
|
|
193
|
-
const [entity] = model.entities
|
|
194
|
-
assert.deepEqual(entity, e1)
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
test('sets the "definitions.properties"', ({ assert }) => {
|
|
198
|
-
const ns = new DataNamespace()
|
|
199
|
-
const d1 = ns.addDataModel('d1')
|
|
200
|
-
const e1 = d1.addEntity('e1')
|
|
201
|
-
e1.addNamedProperty('p1')
|
|
202
|
-
const instance = new DataNamespace()
|
|
203
|
-
instance.new(ns.toJSON())
|
|
204
|
-
assert.lengthOf(instance.definitions.properties, 1)
|
|
205
|
-
instance.new(base)
|
|
206
|
-
assert.lengthOf(instance.definitions.properties, 0)
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
test('sets the properties on the corresponding entity', ({ assert }) => {
|
|
210
|
-
const ns = new DataNamespace()
|
|
211
|
-
const d1 = ns.addDataModel('d1')
|
|
212
|
-
const e1 = d1.addEntity('e1')
|
|
213
|
-
const p1 = e1.addNamedProperty('p1')
|
|
214
|
-
const instance = new DataNamespace()
|
|
215
|
-
instance.new(ns.toJSON())
|
|
216
|
-
|
|
217
|
-
const model = instance.findDataModel(d1.key)!
|
|
218
|
-
const [entity] = model.entities
|
|
219
|
-
assert.lengthOf(entity.properties, 1, 'has the properties')
|
|
220
|
-
assert.deepEqual(entity.properties[0], p1, 'has the property')
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
test('sets the "definitions.associations"', ({ assert }) => {
|
|
224
|
-
const ns = new DataNamespace()
|
|
225
|
-
const d1 = ns.addDataModel('d1')
|
|
226
|
-
const e1 = d1.addEntity('e1')
|
|
227
|
-
e1.addNamedAssociation('a1')
|
|
228
|
-
const instance = new DataNamespace()
|
|
229
|
-
instance.new(ns.toJSON())
|
|
230
|
-
assert.lengthOf(instance.definitions.associations, 1)
|
|
231
|
-
instance.new(base)
|
|
232
|
-
assert.lengthOf(instance.definitions.associations, 0)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
test('sets the associations on the corresponding entity', ({ assert }) => {
|
|
236
|
-
const ns = new DataNamespace()
|
|
237
|
-
const d1 = ns.addDataModel('d1')
|
|
238
|
-
const e1 = d1.addEntity('e1')
|
|
239
|
-
const a1 = e1.addNamedAssociation('a1')
|
|
240
|
-
const instance = new DataNamespace()
|
|
241
|
-
instance.new(ns.toJSON())
|
|
242
|
-
|
|
243
|
-
const model = instance.findDataModel(d1.key)!
|
|
244
|
-
const [entity] = model.entities
|
|
245
|
-
assert.lengthOf(entity.associations, 1, 'has the associations')
|
|
246
|
-
assert.deepEqual(entity.associations[0], a1, 'has the association')
|
|
247
|
-
})
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
test.group('toJSON()', (group) => {
|
|
251
|
-
let base: DataNamespace
|
|
252
|
-
group.each.setup(() => {
|
|
253
|
-
base = new DataNamespace({
|
|
254
|
-
info: Thing.fromName('test name').toJSON(),
|
|
255
|
-
key: 'test123',
|
|
256
|
-
kind: DataNamespaceKind,
|
|
257
|
-
definitions: {},
|
|
258
|
-
items: [],
|
|
259
|
-
})
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
test('serializes the kind', ({ assert }) => {
|
|
263
|
-
const result = base.toJSON()
|
|
264
|
-
assert.equal(result.kind, DataNamespaceKind)
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
test('serializes the key', ({ assert }) => {
|
|
268
|
-
const result = base.toJSON()
|
|
269
|
-
assert.equal(result.key, base.key)
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
test('serializes the info', ({ assert }) => {
|
|
273
|
-
const result = base.toJSON()
|
|
274
|
-
assert.equal(result.info.name, 'test name')
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
test('serializes the "items"', ({ assert }) => {
|
|
278
|
-
const created = base.addNamespace('n1')
|
|
279
|
-
const result = base.toJSON()
|
|
280
|
-
assert.lengthOf(result.items, 1)
|
|
281
|
-
assert.equal(result.items[0].key, created.key)
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
test('serializes the "definitions"', ({ assert }) => {
|
|
285
|
-
const result = base.toJSON()
|
|
286
|
-
assert.typeOf(result.definitions, 'object')
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
test('serializes the "definitions.namespaces"', ({ assert }) => {
|
|
290
|
-
const created = base.addNamespace('n1')
|
|
291
|
-
const result = base.toJSON()
|
|
292
|
-
assert.typeOf(result.definitions.namespaces, 'array', 'has the array')
|
|
293
|
-
assert.lengthOf(result.definitions.namespaces!, 1, 'has a single namespace item')
|
|
294
|
-
assert.deepEqual(result.definitions.namespaces, [created.toJSON()], 'has the namespace item')
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
test('serializes the "definitions.models"', ({ assert }) => {
|
|
298
|
-
const created = base.addDataModel('d1')
|
|
299
|
-
const result = base.toJSON()
|
|
300
|
-
assert.typeOf(result.definitions.models, 'array', 'has the array')
|
|
301
|
-
assert.lengthOf(result.definitions.models!, 1, 'has a single models item')
|
|
302
|
-
assert.deepEqual(result.definitions.models, [created.toJSON()], 'has the models item')
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
test('serializes the "definitions.tags"', ({ assert }) => {
|
|
306
|
-
base.definitions.tags = ['a']
|
|
307
|
-
const result = base.toJSON()
|
|
308
|
-
assert.typeOf(result.definitions.tags, 'array', 'has the array')
|
|
309
|
-
assert.lengthOf(result.definitions.tags!, 1, 'has a single tags item')
|
|
310
|
-
assert.deepEqual(result.definitions.tags, ['a'], 'has the tags item')
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
test('serializes the "definitions.entities"', ({ assert }) => {
|
|
314
|
-
const d1 = base.addDataModel('d1')
|
|
315
|
-
const created = d1.addEntity('e1')
|
|
316
|
-
const result = base.toJSON()
|
|
317
|
-
assert.typeOf(result.definitions.entities, 'array', 'has the array')
|
|
318
|
-
assert.lengthOf(result.definitions.entities!, 1, 'has a single entity item')
|
|
319
|
-
assert.deepEqual(result.definitions.entities, [created.toJSON()], 'has the entity item')
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
test('serializes the "definitions.properties"', ({ assert }) => {
|
|
323
|
-
const d1 = base.addDataModel('d1')
|
|
324
|
-
const e1 = d1.addEntity('e1')
|
|
325
|
-
const created = e1.addNamedProperty('p1')
|
|
326
|
-
const result = base.toJSON()
|
|
327
|
-
assert.typeOf(result.definitions.properties, 'array', 'has the array')
|
|
328
|
-
assert.lengthOf(result.definitions.properties!, 1, 'has a single property item')
|
|
329
|
-
assert.deepEqual(result.definitions.properties, [created.toJSON()], 'has the property item')
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
test('serializes the "definitions.associations"', ({ assert }) => {
|
|
333
|
-
const d1 = base.addDataModel('d1')
|
|
334
|
-
const e1 = d1.addEntity('e1')
|
|
335
|
-
const created = e1.addNamedAssociation('p1')
|
|
336
|
-
const result = base.toJSON()
|
|
337
|
-
assert.typeOf(result.definitions.associations, 'array', 'has the array')
|
|
338
|
-
assert.lengthOf(result.definitions.associations!, 1, 'has a single association item')
|
|
339
|
-
assert.deepEqual(result.definitions.associations, [created.toJSON()], 'has the association item')
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
test('has no "definitions.models" when empty', ({ assert }) => {
|
|
343
|
-
const result = base.toJSON()
|
|
344
|
-
assert.isUndefined(result.definitions.models)
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
test('has no "definitions.tags" when empty', ({ assert }) => {
|
|
348
|
-
const result = base.toJSON()
|
|
349
|
-
assert.isUndefined(result.definitions.tags)
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
test('has no "definitions.entities" when empty', ({ assert }) => {
|
|
353
|
-
const result = base.toJSON()
|
|
354
|
-
assert.isUndefined(result.definitions.entities)
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
test('has no "definitions.properties" when empty', ({ assert }) => {
|
|
358
|
-
const result = base.toJSON()
|
|
359
|
-
assert.isUndefined(result.definitions.properties)
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
test('has no "definitions.associations" when empty', ({ assert }) => {
|
|
363
|
-
const result = base.toJSON()
|
|
364
|
-
assert.isUndefined(result.definitions.associations)
|
|
365
|
-
})
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
test.group('remove()', (group) => {
|
|
369
|
-
let root: DataNamespace
|
|
370
|
-
|
|
371
|
-
group.each.setup(() => {
|
|
372
|
-
root = new DataNamespace()
|
|
373
|
-
})
|
|
374
|
-
|
|
375
|
-
test('removes a child namespace', ({ assert }) => {
|
|
376
|
-
const n1 = root.addNamespace('n1')
|
|
377
|
-
n1.remove()
|
|
378
|
-
assert.deepEqual(root.definitions.namespaces, [])
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
test('removes a child namespace and its contents', ({ assert }) => {
|
|
382
|
-
const n1 = root.addNamespace('n1')
|
|
383
|
-
const d1 = n1.addDataModel('d1')
|
|
384
|
-
d1.addEntity('e1')
|
|
385
|
-
n1.remove()
|
|
386
|
-
assert.deepEqual(root.definitions.namespaces, [])
|
|
387
|
-
assert.deepEqual(root.definitions.models, [])
|
|
388
|
-
assert.deepEqual(root.definitions.entities, [])
|
|
389
|
-
})
|
|
390
|
-
|
|
391
|
-
test('throws when trying to remove the root namespace', ({ assert }) => {
|
|
392
|
-
assert.throws(() => {
|
|
393
|
-
root.remove()
|
|
394
|
-
}, 'Unable to remove the root namespace this way.')
|
|
395
|
-
})
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
test.group('findParent()', (group) => {
|
|
399
|
-
let root: DataNamespace
|
|
400
|
-
|
|
401
|
-
group.each.setup(() => {
|
|
402
|
-
root = new DataNamespace()
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
test('returns undefined when requesting self', ({ assert }) => {
|
|
406
|
-
const result = root.findParent(root.key)
|
|
407
|
-
assert.isUndefined(result)
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
test('returns self when a direct child', ({ assert }) => {
|
|
411
|
-
const n1 = root.addNamespace('n1')
|
|
412
|
-
const result = root.findParent(n1.key)
|
|
413
|
-
assert.isTrue(result === root)
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
test('returns the parent for a child', ({ assert }) => {
|
|
417
|
-
const n1 = root.addNamespace('n1')
|
|
418
|
-
const n2 = n1.addNamespace('n2')
|
|
419
|
-
const result = root.findParent(n2.key)
|
|
420
|
-
assert.isTrue(result === n1)
|
|
421
|
-
})
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
test.group('addNamespace()', (group) => {
|
|
425
|
-
let root: DataNamespace
|
|
426
|
-
|
|
427
|
-
group.each.setup(() => {
|
|
428
|
-
root = new DataNamespace()
|
|
429
|
-
})
|
|
430
|
-
|
|
431
|
-
test('adds a namespace to a root by the name', ({ assert }) => {
|
|
432
|
-
const result = root.addNamespace('an ns')
|
|
433
|
-
assert.typeOf(result, 'object', 'returns the created namespace')
|
|
434
|
-
assert.deepEqual(root.definitions.namespaces, [result], 'has the ns in definitions')
|
|
435
|
-
assert.lengthOf(root.items, 1, 'the root has an item')
|
|
436
|
-
assert.equal(root.items[0].key, result.key, 'the root has the created item')
|
|
437
|
-
assert.equal(root.items[0].kind, result.kind, 'the root item has the proper kind')
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
test('adds a namespace to a root by the instance', ({ assert }) => {
|
|
441
|
-
const instance = new DataNamespace()
|
|
442
|
-
const result = root.addNamespace(instance)
|
|
443
|
-
assert.deepEqual(result, instance, 'returns the same namespace')
|
|
444
|
-
assert.deepEqual(root.definitions.namespaces, [instance], 'has the ns in definitions')
|
|
445
|
-
assert.lengthOf(root.items, 1, 'the root has an item')
|
|
446
|
-
assert.equal(root.items[0].key, result.key, 'the root has the created item')
|
|
447
|
-
assert.equal(root.items[0].kind, result.kind, 'the root item has the proper kind')
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
test('adds a namespace to a root by the schema', ({ assert }) => {
|
|
451
|
-
const instance = new DataNamespace().toJSON()
|
|
452
|
-
const result = root.addNamespace(instance)
|
|
453
|
-
assert.deepEqual(result.toJSON(), instance, 'returns the created namespace')
|
|
454
|
-
})
|
|
455
|
-
|
|
456
|
-
test('adds a namespace to a parent namespace', ({ assert }) => {
|
|
457
|
-
const parent = root.addNamespace('parent')
|
|
458
|
-
const child = parent.addNamespace('child')
|
|
459
|
-
assert.typeOf(child, 'object', 'returns the child namespace')
|
|
460
|
-
assert.lengthOf(root.definitions.namespaces, 2, 'root has both namespaces')
|
|
461
|
-
assert.deepEqual(root.definitions.namespaces, [parent, child], 'has both namespace definitions')
|
|
462
|
-
assert.lengthOf(root.items, 1, 'the root has only one item')
|
|
463
|
-
assert.equal(root.items[0].key, parent.key, 'the root has its own item')
|
|
464
|
-
assert.lengthOf(parent.items, 1, 'the parent has only one item')
|
|
465
|
-
assert.equal(parent.items[0].key, child.key, 'the parent has its own item')
|
|
466
|
-
})
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
test.group('findNamespace()', (group) => {
|
|
470
|
-
let root: DataNamespace
|
|
471
|
-
|
|
472
|
-
group.each.setup(() => {
|
|
473
|
-
root = new DataNamespace()
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
test('finds a direct child namespace', ({ assert }) => {
|
|
477
|
-
const n1 = root.addNamespace('n1')
|
|
478
|
-
const result = root.findNamespace(n1.key)
|
|
479
|
-
assert.deepEqual(result, n1)
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
test('finds a sub-ns child namespace', ({ assert }) => {
|
|
483
|
-
const n1 = root.addNamespace('n1')
|
|
484
|
-
const n2 = n1.addNamespace('n2')
|
|
485
|
-
const result = root.findNamespace(n2.key)
|
|
486
|
-
assert.deepEqual(result, n2)
|
|
487
|
-
})
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
test.group('removeNamespace()', (group) => {
|
|
491
|
-
let root: DataNamespace
|
|
492
|
-
|
|
493
|
-
group.each.setup(() => {
|
|
494
|
-
root = new DataNamespace()
|
|
495
|
-
})
|
|
496
|
-
|
|
497
|
-
test('removes a child namespace', ({ assert }) => {
|
|
498
|
-
const n1 = root.addNamespace('n1')
|
|
499
|
-
root.removeNamespace(n1.key)
|
|
500
|
-
assert.deepEqual(root.definitions.namespaces, [])
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
test('removes a child namespace and its contents', ({ assert }) => {
|
|
504
|
-
const n1 = root.addNamespace('n1')
|
|
505
|
-
const d1 = n1.addDataModel('d1')
|
|
506
|
-
d1.addEntity('e1')
|
|
507
|
-
root.removeNamespace(n1.key)
|
|
508
|
-
assert.deepEqual(root.definitions.namespaces, [])
|
|
509
|
-
assert.deepEqual(root.definitions.models, [])
|
|
510
|
-
assert.deepEqual(root.definitions.entities, [])
|
|
511
|
-
})
|
|
512
|
-
|
|
513
|
-
test('throws when trying to remove the root namespace', ({ assert }) => {
|
|
514
|
-
assert.throws(() => {
|
|
515
|
-
root.removeNamespace(root.key)
|
|
516
|
-
}, 'Unable to remove the root namespace this way.')
|
|
517
|
-
})
|
|
518
|
-
})
|
|
519
|
-
|
|
520
|
-
test.group('addDataModel()', (group) => {
|
|
521
|
-
let root: DataNamespace
|
|
522
|
-
|
|
523
|
-
group.each.setup(() => {
|
|
524
|
-
root = new DataNamespace()
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
test('adds data model to the root ns by name', ({ assert }) => {
|
|
528
|
-
const d1 = root.addDataModel('d1')
|
|
529
|
-
assert.typeOf(d1, 'object', 'returns the created model')
|
|
530
|
-
assert.deepEqual(root.definitions.models, [d1], 'adds the definition')
|
|
531
|
-
assert.lengthOf(root.items, 1, 'adds the item')
|
|
532
|
-
assert.equal(root.items[0].key, d1.key, 'the item has the key')
|
|
533
|
-
assert.equal(root.items[0].kind, d1.kind, 'the item has the kind')
|
|
534
|
-
})
|
|
535
|
-
|
|
536
|
-
test('adds data model to the root ns by instance', ({ assert }) => {
|
|
537
|
-
const m1 = DataModel.fromName(root, 'm1')
|
|
538
|
-
const d1 = root.addDataModel(m1)
|
|
539
|
-
assert.deepEqual(d1, m1, 'returns the same model')
|
|
540
|
-
assert.deepEqual(root.definitions.models, [m1], 'adds the definition')
|
|
541
|
-
assert.lengthOf(root.items, 1, 'adds the item')
|
|
542
|
-
assert.equal(root.items[0].key, d1.key, 'the item has the key')
|
|
543
|
-
assert.equal(root.items[0].kind, d1.kind, 'the item has the kind')
|
|
544
|
-
})
|
|
545
|
-
|
|
546
|
-
test('adds data model to the root ns by schema', ({ assert }) => {
|
|
547
|
-
const m1 = DataModel.fromName(root, 'm1').toJSON()
|
|
548
|
-
const d1 = root.addDataModel(m1)
|
|
549
|
-
assert.deepEqual(d1.toJSON(), m1, 'returns the same model')
|
|
550
|
-
assert.deepEqual(root.definitions.models[0].toJSON(), m1, 'adds the definition')
|
|
551
|
-
assert.lengthOf(root.items, 1, 'adds the item')
|
|
552
|
-
assert.equal(root.items[0].key, d1.key, 'the item has the key')
|
|
553
|
-
assert.equal(root.items[0].kind, d1.kind, 'the item has the kind')
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
test('adds a data model to the child namespace', ({ assert }) => {
|
|
557
|
-
const n1 = root.addNamespace('n1')
|
|
558
|
-
const d1 = n1.addDataModel('d1')
|
|
559
|
-
assert.typeOf(d1, 'object', 'returns the created model')
|
|
560
|
-
assert.deepEqual(root.definitions.models, [d1], 'adds the definition')
|
|
561
|
-
assert.lengthOf(n1.items, 1, 'adds the item')
|
|
562
|
-
assert.equal(n1.items[0].key, d1.key, 'the item has the key')
|
|
563
|
-
assert.equal(n1.items[0].kind, d1.kind, 'the item has the kind')
|
|
564
|
-
assert.lengthOf(root.items, 1, 'the root has only 1 item')
|
|
565
|
-
})
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
test.group('findDataModel()', (group) => {
|
|
569
|
-
let root: DataNamespace
|
|
570
|
-
let m1: DataModel
|
|
571
|
-
let m2: DataModel
|
|
572
|
-
|
|
573
|
-
group.each.setup(() => {
|
|
574
|
-
root = new DataNamespace()
|
|
575
|
-
m1 = root.addDataModel('m1')
|
|
576
|
-
const parent = root.addNamespace('n1')
|
|
577
|
-
m2 = parent.addDataModel('m2')
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
test('returns the data model', ({ assert }) => {
|
|
581
|
-
const result = root.findDataModel(m1.key)
|
|
582
|
-
assert.deepEqual(result, m1)
|
|
583
|
-
})
|
|
584
|
-
|
|
585
|
-
test('returns child data model', ({ assert }) => {
|
|
586
|
-
const result = root.findDataModel(m2.key)
|
|
587
|
-
assert.deepEqual(result, m2)
|
|
588
|
-
})
|
|
589
|
-
|
|
590
|
-
test('returns undefined when not found', ({ assert }) => {
|
|
591
|
-
const result = root.findDataModel('other')
|
|
592
|
-
assert.isUndefined(result)
|
|
593
|
-
})
|
|
594
|
-
})
|
|
595
|
-
|
|
596
|
-
test.group('removeDataModel()', (group) => {
|
|
597
|
-
let root: DataNamespace
|
|
598
|
-
let m1: DataModel
|
|
599
|
-
let m2: DataModel
|
|
600
|
-
|
|
601
|
-
group.each.setup(() => {
|
|
602
|
-
root = new DataNamespace()
|
|
603
|
-
m1 = root.addDataModel('m1')
|
|
604
|
-
const parent = root.addNamespace('n1')
|
|
605
|
-
m2 = parent.addDataModel('m2')
|
|
606
|
-
})
|
|
607
|
-
|
|
608
|
-
test('removes the root data model', ({ assert }) => {
|
|
609
|
-
root.removeDataModel(m1.key)
|
|
610
|
-
assert.lengthOf(root.definitions.models, 1, 'has the remaining data model')
|
|
611
|
-
})
|
|
612
|
-
|
|
613
|
-
test('returns child data model', ({ assert }) => {
|
|
614
|
-
root.removeDataModel(m2.key)
|
|
615
|
-
assert.lengthOf(root.definitions.models, 1, 'has the remaining data model')
|
|
616
|
-
})
|
|
617
|
-
|
|
618
|
-
test('does nothing when not found', ({ assert }) => {
|
|
619
|
-
root.removeDataModel('other')
|
|
620
|
-
assert.lengthOf(root.definitions.models, 2, 'has all data models')
|
|
621
|
-
})
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
test.group('associationGraph()', (group) => {
|
|
625
|
-
let root: DataNamespace
|
|
626
|
-
let d1: DataModel
|
|
627
|
-
let d2: DataModel
|
|
628
|
-
|
|
629
|
-
group.each.setup(() => {
|
|
630
|
-
root = new DataNamespace()
|
|
631
|
-
d1 = root.addDataModel('d1')
|
|
632
|
-
d2 = root.addDataModel('d2')
|
|
633
|
-
})
|
|
634
|
-
|
|
635
|
-
test('returns empty object when no entities and associations', ({ assert }) => {
|
|
636
|
-
const result = root.associationGraph()
|
|
637
|
-
assert.deepEqual(result, {})
|
|
638
|
-
})
|
|
639
|
-
|
|
640
|
-
test('returns empty object when no associations', ({ assert }) => {
|
|
641
|
-
d1.addEntity('e1')
|
|
642
|
-
d2.addEntity('e2')
|
|
643
|
-
const result = root.associationGraph()
|
|
644
|
-
assert.deepEqual(result, {})
|
|
645
|
-
})
|
|
646
|
-
|
|
647
|
-
test('returns simple association graph', ({ assert }) => {
|
|
648
|
-
const e1 = d1.addEntity('e1')
|
|
649
|
-
const e2 = d2.addEntity('e2')
|
|
650
|
-
e1.addTargetAssociation(e2.key)
|
|
651
|
-
const result = root.associationGraph()
|
|
652
|
-
assert.deepEqual(result, {
|
|
653
|
-
[e1.key]: [e2.key],
|
|
654
|
-
})
|
|
655
|
-
})
|
|
656
|
-
|
|
657
|
-
test('returns multiple associations from the same entity', ({ assert }) => {
|
|
658
|
-
const e1 = d1.addEntity('e1')
|
|
659
|
-
const e2 = d2.addEntity('e2')
|
|
660
|
-
const e3 = d2.addEntity('e3')
|
|
661
|
-
e1.addTargetAssociation(e2.key)
|
|
662
|
-
e1.addTargetAssociation(e3.key)
|
|
663
|
-
const result = root.associationGraph()
|
|
664
|
-
assert.deepEqual(result, {
|
|
665
|
-
[e1.key]: [e3.key, e2.key],
|
|
666
|
-
})
|
|
667
|
-
})
|
|
668
|
-
|
|
669
|
-
test('returns multiple associations to the same entity', ({ assert }) => {
|
|
670
|
-
const e1 = d1.addEntity('e1')
|
|
671
|
-
const e2 = d2.addEntity('e2')
|
|
672
|
-
const e3 = d2.addEntity('e3')
|
|
673
|
-
e2.addTargetAssociation(e1.key)
|
|
674
|
-
e3.addTargetAssociation(e1.key)
|
|
675
|
-
const result = root.associationGraph()
|
|
676
|
-
assert.deepEqual(result, {
|
|
677
|
-
[e2.key]: [e1.key],
|
|
678
|
-
[e3.key]: [e1.key],
|
|
679
|
-
})
|
|
680
|
-
})
|
|
681
|
-
|
|
682
|
-
test('captures self-association', ({ assert }) => {
|
|
683
|
-
const e1 = d1.addEntity('e1')
|
|
684
|
-
e1.addTargetAssociation(e1.key)
|
|
685
|
-
const result = root.associationGraph()
|
|
686
|
-
assert.deepEqual(result, {
|
|
687
|
-
[e1.key]: [e1.key],
|
|
688
|
-
})
|
|
689
|
-
})
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
test.group('associationPath()', (group) => {
|
|
693
|
-
let root: DataNamespace
|
|
694
|
-
let m1: DataModel
|
|
695
|
-
let e1: DataEntity
|
|
696
|
-
let e2: DataEntity
|
|
697
|
-
let e3: DataEntity
|
|
698
|
-
let e4: DataEntity
|
|
699
|
-
let e5: DataEntity
|
|
700
|
-
|
|
701
|
-
group.each.setup(() => {
|
|
702
|
-
root = new DataNamespace()
|
|
703
|
-
m1 = root.addDataModel('m1')
|
|
704
|
-
e1 = m1.addEntity('e1')
|
|
705
|
-
e2 = m1.addEntity('e2')
|
|
706
|
-
e3 = m1.addEntity('e3')
|
|
707
|
-
e4 = m1.addEntity('e4')
|
|
708
|
-
e5 = m1.addEntity('e5')
|
|
709
|
-
})
|
|
710
|
-
|
|
711
|
-
test('finds a direct connection', ({ assert }) => {
|
|
712
|
-
e1.addTargetAssociation(e2.key)
|
|
713
|
-
const graph = root.associationGraph()
|
|
714
|
-
const paths: string[][] = []
|
|
715
|
-
for (const path of root.associationPath(e1.key, e2.key, graph)) {
|
|
716
|
-
paths.push(path)
|
|
717
|
-
}
|
|
718
|
-
assert.lengthOf(paths, 1, 'has a single path')
|
|
719
|
-
assert.deepEqual(paths[0], [e1.key, e2.key], 'has the path')
|
|
720
|
-
})
|
|
721
|
-
|
|
722
|
-
test('finds a connection through another entity', ({ assert }) => {
|
|
723
|
-
e1.addTargetAssociation(e2.key)
|
|
724
|
-
e2.addTargetAssociation(e3.key)
|
|
725
|
-
const graph = root.associationGraph()
|
|
726
|
-
const paths: string[][] = []
|
|
727
|
-
for (const path of root.associationPath(e1.key, e3.key, graph)) {
|
|
728
|
-
paths.push(path)
|
|
729
|
-
}
|
|
730
|
-
assert.lengthOf(paths, 1, 'has a single path')
|
|
731
|
-
assert.deepEqual(paths[0], [e1.key, e2.key, e3.key], 'has the path')
|
|
732
|
-
})
|
|
733
|
-
|
|
734
|
-
test('returns a connection to self', ({ assert }) => {
|
|
735
|
-
e1.addTargetAssociation(e1.key)
|
|
736
|
-
const graph = root.associationGraph()
|
|
737
|
-
const paths: string[][] = []
|
|
738
|
-
for (const path of root.associationPath(e1.key, e1.key, graph)) {
|
|
739
|
-
paths.push(path)
|
|
740
|
-
}
|
|
741
|
-
assert.lengthOf(paths, 1, 'has a single path')
|
|
742
|
-
assert.deepEqual(paths[0], [e1.key], 'has the path')
|
|
743
|
-
})
|
|
744
|
-
|
|
745
|
-
test('yields multiple directions', ({ assert }) => {
|
|
746
|
-
e1.addTargetAssociation(e5.key)
|
|
747
|
-
e1.addTargetAssociation(e2.key)
|
|
748
|
-
e2.addTargetAssociation(e3.key)
|
|
749
|
-
e3.addTargetAssociation(e4.key)
|
|
750
|
-
e4.addTargetAssociation(e5.key)
|
|
751
|
-
const graph = root.associationGraph()
|
|
752
|
-
const paths: string[][] = []
|
|
753
|
-
for (const path of root.associationPath(e1.key, e5.key, graph)) {
|
|
754
|
-
paths.push(path)
|
|
755
|
-
}
|
|
756
|
-
assert.lengthOf(paths, 2, 'has both paths')
|
|
757
|
-
assert.deepEqual(paths[0], [e1.key, e2.key, e3.key, e4.key, e5.key], 'has the 1st path')
|
|
758
|
-
assert.deepEqual(paths[1], [e1.key, e5.key], 'has the 2nd path')
|
|
759
|
-
})
|
|
760
|
-
|
|
761
|
-
test('ignores broken paths', ({ assert }) => {
|
|
762
|
-
e1.addTargetAssociation(e5.key)
|
|
763
|
-
e1.addTargetAssociation(e2.key)
|
|
764
|
-
e2.addTargetAssociation(e3.key)
|
|
765
|
-
// no e3 -> e4
|
|
766
|
-
e4.addTargetAssociation(e5.key)
|
|
767
|
-
const graph = root.associationGraph()
|
|
768
|
-
const paths: string[][] = []
|
|
769
|
-
for (const path of root.associationPath(e1.key, e5.key, graph)) {
|
|
770
|
-
paths.push(path)
|
|
771
|
-
}
|
|
772
|
-
assert.lengthOf(paths, 1, 'has both paths')
|
|
773
|
-
assert.deepEqual(paths[0], [e1.key, e5.key], 'has the 1st path')
|
|
774
|
-
})
|
|
775
|
-
|
|
776
|
-
test('respects the order of nodes in paths', ({ assert }) => {
|
|
777
|
-
e1.addTargetAssociation(e2.key)
|
|
778
|
-
e2.addTargetAssociation(e1.key)
|
|
779
|
-
const paths: string[][] = []
|
|
780
|
-
const graph = root.associationGraph()
|
|
781
|
-
for (const path of root.associationPath(e1.key, e2.key, graph)) {
|
|
782
|
-
paths.push(path)
|
|
783
|
-
}
|
|
784
|
-
for (const path of root.associationPath(e2.key, e1.key, graph)) {
|
|
785
|
-
paths.push(path)
|
|
786
|
-
}
|
|
787
|
-
assert.lengthOf(paths, 2, 'has only 2 paths')
|
|
788
|
-
const [p1, p2] = paths
|
|
789
|
-
assert.deepEqual(p1, [e1.key, e2.key], 'has ordered paths from e1 to e2')
|
|
790
|
-
assert.deepEqual(p2, [e2.key, e1.key], 'has ordered paths from e2 to e1')
|
|
791
|
-
})
|
|
792
|
-
})
|
|
793
|
-
|
|
794
|
-
test.group('computeForeignNamespaceKeys()', () => {
|
|
795
|
-
test('returns an empty array when no associations', ({ assert }) => {
|
|
796
|
-
const n1 = new DataNamespace()
|
|
797
|
-
const result = n1.computeForeignNamespaceKeys()
|
|
798
|
-
assert.deepEqual(result, [])
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
test('returns an empty array when no foreign associations', ({ assert }) => {
|
|
802
|
-
const n1 = new DataNamespace()
|
|
803
|
-
const d1 = n1.addDataModel('d1')
|
|
804
|
-
const e1 = d1.addEntity('e1')
|
|
805
|
-
const e2 = d1.addEntity('e2')
|
|
806
|
-
e1.addTargetAssociation(e2.key)
|
|
807
|
-
const result = n1.computeForeignNamespaceKeys()
|
|
808
|
-
assert.deepEqual(result, [])
|
|
809
|
-
})
|
|
810
|
-
|
|
811
|
-
test('returns ids of foreign namespaces', ({ assert }) => {
|
|
812
|
-
const n1 = new DataNamespace()
|
|
813
|
-
const d1 = n1.addDataModel('d1')
|
|
814
|
-
const e1 = d1.addEntity('e1')
|
|
815
|
-
const n2 = new DataNamespace()
|
|
816
|
-
const d2 = n2.addDataModel('d2')
|
|
817
|
-
const e2 = d2.addEntity('e2')
|
|
818
|
-
n1.addForeign(n2)
|
|
819
|
-
e1.addForeignAssociation(e2.key, n2.key)
|
|
820
|
-
|
|
821
|
-
const result = n1.computeForeignNamespaceKeys()
|
|
822
|
-
assert.deepEqual(result, [n2.key])
|
|
823
|
-
})
|
|
824
|
-
})
|
|
825
|
-
|
|
826
|
-
test.group('findAssociatedEntity()', (group) => {
|
|
827
|
-
let root: DataNamespace
|
|
828
|
-
let foreign: DataNamespace
|
|
829
|
-
let e1: DataEntity
|
|
830
|
-
let e2: DataEntity
|
|
831
|
-
|
|
832
|
-
group.each.setup(() => {
|
|
833
|
-
root = new DataNamespace()
|
|
834
|
-
foreign = new DataNamespace()
|
|
835
|
-
root.addForeign(foreign)
|
|
836
|
-
const model1 = root.addDataModel('m1')
|
|
837
|
-
const model2 = foreign.addDataModel('m2')
|
|
838
|
-
e1 = model1.addEntity('e1')
|
|
839
|
-
e2 = model2.addEntity('e2')
|
|
840
|
-
})
|
|
841
|
-
|
|
842
|
-
test('finds an entity in the current namespace', ({ assert }) => {
|
|
843
|
-
const result = root.findAssociatedEntity(e1.key)
|
|
844
|
-
assert.deepEqual(result, e1)
|
|
845
|
-
})
|
|
846
|
-
|
|
847
|
-
test('finds an entity in a foreign namespace', ({ assert }) => {
|
|
848
|
-
const result = root.findAssociatedEntity(e2.key, foreign.key)
|
|
849
|
-
assert.deepEqual(result, e2)
|
|
850
|
-
})
|
|
851
|
-
|
|
852
|
-
test('returns undefined when the entity is not found in the current namespace', ({ assert }) => {
|
|
853
|
-
const result = root.findAssociatedEntity('non-existent-key')
|
|
854
|
-
assert.isUndefined(result)
|
|
855
|
-
})
|
|
856
|
-
|
|
857
|
-
test('returns undefined when the entity is not found in a foreign namespace', ({ assert }) => {
|
|
858
|
-
const result = root.findAssociatedEntity('non-existent-key', foreign.key)
|
|
859
|
-
assert.isUndefined(result)
|
|
860
|
-
})
|
|
861
|
-
|
|
862
|
-
test('returns undefined when the foreign namespace does not exist', ({ assert }) => {
|
|
863
|
-
const result = root.findAssociatedEntity(e2.key, 'non-existent-namespace')
|
|
864
|
-
assert.isUndefined(result)
|
|
865
|
-
})
|
|
866
|
-
|
|
867
|
-
test('returns undefined when no namespace is provided and the entity is in a foreign namespace', ({ assert }) => {
|
|
868
|
-
const result = root.findAssociatedEntity(e2.key)
|
|
869
|
-
assert.isUndefined(result)
|
|
870
|
-
})
|
|
871
|
-
})
|
|
872
|
-
|
|
873
|
-
test.group('addForeign()', (group) => {
|
|
874
|
-
let root: DataNamespace
|
|
875
|
-
let foreign: DataNamespace
|
|
876
|
-
|
|
877
|
-
group.each.setup(() => {
|
|
878
|
-
root = new DataNamespace()
|
|
879
|
-
foreign = new DataNamespace()
|
|
880
|
-
})
|
|
881
|
-
|
|
882
|
-
test('adds a foreign namespace', ({ assert }) => {
|
|
883
|
-
root.addForeign(foreign)
|
|
884
|
-
assert.deepEqual(root.foreign, [foreign])
|
|
885
|
-
})
|
|
886
|
-
|
|
887
|
-
test('does not add the same foreign namespace twice', ({ assert }) => {
|
|
888
|
-
root.addForeign(foreign)
|
|
889
|
-
root.addForeign(foreign)
|
|
890
|
-
assert.deepEqual(root.foreign, [foreign])
|
|
891
|
-
})
|
|
892
|
-
})
|
|
893
|
-
|
|
894
|
-
test.group('removeForeign()', (group) => {
|
|
895
|
-
let root: DataNamespace
|
|
896
|
-
let foreign: DataNamespace
|
|
897
|
-
let foreign2: DataNamespace
|
|
898
|
-
|
|
899
|
-
group.each.setup(() => {
|
|
900
|
-
root = new DataNamespace()
|
|
901
|
-
foreign = new DataNamespace()
|
|
902
|
-
foreign2 = new DataNamespace()
|
|
903
|
-
root.addForeign(foreign)
|
|
904
|
-
root.addForeign(foreign2)
|
|
905
|
-
})
|
|
906
|
-
|
|
907
|
-
test('removes a foreign namespace', ({ assert }) => {
|
|
908
|
-
root.removeForeign(foreign)
|
|
909
|
-
assert.deepEqual(root.foreign, [foreign2])
|
|
910
|
-
})
|
|
911
|
-
|
|
912
|
-
test('does nothing when the foreign namespace does not exist', ({ assert }) => {
|
|
913
|
-
const other = new DataNamespace()
|
|
914
|
-
root.removeForeign(other)
|
|
915
|
-
assert.deepEqual(root.foreign, [foreign, foreign2])
|
|
916
|
-
})
|
|
917
|
-
})
|
|
918
|
-
|
|
919
|
-
test.group('hasForeignNamespace()', (group) => {
|
|
920
|
-
let root: DataNamespace
|
|
921
|
-
let foreign: DataNamespace
|
|
922
|
-
|
|
923
|
-
group.each.setup(() => {
|
|
924
|
-
root = new DataNamespace()
|
|
925
|
-
foreign = new DataNamespace()
|
|
926
|
-
root.addForeign(foreign)
|
|
927
|
-
})
|
|
928
|
-
|
|
929
|
-
test('returns true when the foreign namespace exists', ({ assert }) => {
|
|
930
|
-
const result = root.hasForeignNamespace(foreign.key)
|
|
931
|
-
assert.isTrue(result)
|
|
932
|
-
})
|
|
933
|
-
|
|
934
|
-
test('returns false when the foreign namespace does not exist', ({ assert }) => {
|
|
935
|
-
const result = root.hasForeignNamespace('non-existent-key')
|
|
936
|
-
assert.isFalse(result)
|
|
937
|
-
})
|
|
938
|
-
})
|
|
939
|
-
|
|
940
|
-
test.group('listNamespaces()', (group) => {
|
|
941
|
-
let root: DataNamespace
|
|
942
|
-
let n1: DataNamespace
|
|
943
|
-
let n2: DataNamespace
|
|
944
|
-
let m1: DataModel
|
|
945
|
-
|
|
946
|
-
group.each.setup(() => {
|
|
947
|
-
root = new DataNamespace()
|
|
948
|
-
n1 = root.addNamespace('n1')
|
|
949
|
-
n2 = root.addNamespace('n2')
|
|
950
|
-
m1 = root.addDataModel('m1')
|
|
951
|
-
})
|
|
952
|
-
|
|
953
|
-
test('lists all namespaces', ({ assert }) => {
|
|
954
|
-
const result = root.listNamespaces()
|
|
955
|
-
assert.deepEqual(result, [n1, n2])
|
|
956
|
-
})
|
|
957
|
-
|
|
958
|
-
test('lists namespaces in a sub-namespace', ({ assert }) => {
|
|
959
|
-
const n3 = n1.addNamespace('n3')
|
|
960
|
-
const result = n1.listNamespaces()
|
|
961
|
-
assert.deepEqual(result, [n3])
|
|
962
|
-
})
|
|
963
|
-
|
|
964
|
-
test('does not list data models', ({ assert }) => {
|
|
965
|
-
const result = root.listNamespaces()
|
|
966
|
-
assert.notDeepInclude(result, m1)
|
|
967
|
-
})
|
|
968
|
-
})
|
|
969
|
-
|
|
970
|
-
test.group('listDataModels()', (group) => {
|
|
971
|
-
let root: DataNamespace
|
|
972
|
-
let n1: DataNamespace
|
|
973
|
-
let m1: DataModel
|
|
974
|
-
let m2: DataModel
|
|
975
|
-
let e1: DataEntity
|
|
976
|
-
|
|
977
|
-
group.each.setup(() => {
|
|
978
|
-
root = new DataNamespace()
|
|
979
|
-
n1 = root.addNamespace('n1')
|
|
980
|
-
m1 = root.addDataModel('m1')
|
|
981
|
-
m2 = n1.addDataModel('m2')
|
|
982
|
-
e1 = m2.addEntity('e1')
|
|
983
|
-
})
|
|
984
|
-
|
|
985
|
-
test('lists all data models', ({ assert }) => {
|
|
986
|
-
const result = root.listDataModels()
|
|
987
|
-
assert.deepEqual(result, [m1])
|
|
988
|
-
})
|
|
989
|
-
|
|
990
|
-
test('lists data models in a sub-namespace', ({ assert }) => {
|
|
991
|
-
const m3 = n1.addDataModel('m3')
|
|
992
|
-
const result = n1.listDataModels()
|
|
993
|
-
assert.deepEqual(result, [m2, m3])
|
|
994
|
-
})
|
|
995
|
-
|
|
996
|
-
test('does not list entities', ({ assert }) => {
|
|
997
|
-
const result = root.listDataModels()
|
|
998
|
-
assert.notDeepInclude(result, e1)
|
|
999
|
-
})
|
|
1000
|
-
})
|
|
1001
|
-
|
|
1002
|
-
test.group('getRoot()', (group) => {
|
|
1003
|
-
let root: DataNamespace
|
|
1004
|
-
let n1: DataNamespace
|
|
1005
|
-
let n2: DataNamespace
|
|
1006
|
-
|
|
1007
|
-
group.each.setup(() => {
|
|
1008
|
-
root = new DataNamespace()
|
|
1009
|
-
n1 = root.addNamespace('n1')
|
|
1010
|
-
n2 = n1.addNamespace('n2')
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
test('returns self when called on the root namespace', ({ assert }) => {
|
|
1014
|
-
const result = root.getRoot()
|
|
1015
|
-
assert.deepEqual(result, root)
|
|
1016
|
-
})
|
|
1017
|
-
|
|
1018
|
-
test('returns the root namespace when called on a sub-namespace', ({ assert }) => {
|
|
1019
|
-
const result = n1.getRoot()
|
|
1020
|
-
assert.deepEqual(result, root)
|
|
1021
|
-
})
|
|
1022
|
-
|
|
1023
|
-
test('returns the root namespace when called on a sub-sub-namespace', ({ assert }) => {
|
|
1024
|
-
const result = n2.getRoot()
|
|
1025
|
-
assert.deepEqual(result, root)
|
|
1026
|
-
})
|
|
1027
|
-
})
|
|
1028
|
-
|
|
1029
|
-
test.group('getParentInstance()', (group) => {
|
|
1030
|
-
let root: DataNamespace
|
|
1031
|
-
let n1: DataNamespace
|
|
1032
|
-
let n2: DataNamespace
|
|
1033
|
-
|
|
1034
|
-
group.each.setup(() => {
|
|
1035
|
-
root = new DataNamespace()
|
|
1036
|
-
n1 = root.addNamespace('n1')
|
|
1037
|
-
n2 = n1.addNamespace('n2')
|
|
1038
|
-
})
|
|
1039
|
-
|
|
1040
|
-
test('returns undefined when called on the root namespace', ({ assert }) => {
|
|
1041
|
-
const result = root.getParentInstance()
|
|
1042
|
-
assert.isUndefined(result)
|
|
1043
|
-
})
|
|
1044
|
-
|
|
1045
|
-
test('returns the parent namespace when called on a sub-namespace', ({ assert }) => {
|
|
1046
|
-
const result = n2.getParentInstance()
|
|
1047
|
-
assert.deepEqual(result, n1)
|
|
1048
|
-
})
|
|
1049
|
-
})
|
|
1050
|
-
|
|
1051
|
-
test.group('isRoot()', (group) => {
|
|
1052
|
-
let root: DataNamespace
|
|
1053
|
-
let n1: DataNamespace
|
|
1054
|
-
|
|
1055
|
-
group.each.setup(() => {
|
|
1056
|
-
root = new DataNamespace()
|
|
1057
|
-
n1 = root.addNamespace('n1')
|
|
1058
|
-
})
|
|
1059
|
-
|
|
1060
|
-
test('returns true when called on the root namespace', ({ assert }) => {
|
|
1061
|
-
const result = root.isRoot()
|
|
1062
|
-
assert.isTrue(result)
|
|
1063
|
-
})
|
|
1064
|
-
|
|
1065
|
-
test('returns false when called on a sub-namespace', ({ assert }) => {
|
|
1066
|
-
const result = n1.isRoot()
|
|
1067
|
-
assert.isFalse(result)
|
|
1068
|
-
})
|
|
1069
|
-
})
|
|
1070
|
-
|
|
1071
|
-
test.group('adaptNamespace()', (group) => {
|
|
1072
|
-
let root: DataNamespace
|
|
1073
|
-
let n1: DataNamespace
|
|
1074
|
-
let n2: DataNamespace
|
|
1075
|
-
|
|
1076
|
-
group.each.setup(() => {
|
|
1077
|
-
root = new DataNamespace()
|
|
1078
|
-
n1 = root.addNamespace('n1')
|
|
1079
|
-
n2 = root.addNamespace('n2')
|
|
1080
|
-
})
|
|
1081
|
-
|
|
1082
|
-
test('moves a namespace to a new parent', ({ assert }) => {
|
|
1083
|
-
const n3 = n1.addNamespace('n3')
|
|
1084
|
-
n2.adaptNamespace(n3)
|
|
1085
|
-
assert.deepEqual(n1.items, [], 'removes from the old parent')
|
|
1086
|
-
const item = DataItem.dataNamespace(root, n3.key)
|
|
1087
|
-
assert.deepEqual(n2.items, [item], 'adds to the new parent')
|
|
1088
|
-
assert.deepEqual(root.definitions.namespaces, [n1, n2, n3], 'keeps the namespace in the root definitions')
|
|
1089
|
-
})
|
|
1090
|
-
|
|
1091
|
-
test('moves a namespace to a new index', ({ assert }) => {
|
|
1092
|
-
const n3 = n1.addNamespace('n3')
|
|
1093
|
-
const n4 = n1.addNamespace('n4')
|
|
1094
|
-
const n5 = n2.addNamespace('n5')
|
|
1095
|
-
n2.adaptNamespace(n3, { index: 0 })
|
|
1096
|
-
const item3 = DataItem.dataNamespace(root, n3.key)
|
|
1097
|
-
const item4 = DataItem.dataNamespace(root, n4.key)
|
|
1098
|
-
const item5 = DataItem.dataNamespace(root, n5.key)
|
|
1099
|
-
assert.deepEqual(n1.items, [item4], 'removes from the old parent')
|
|
1100
|
-
assert.deepEqual(n2.items, [item3, item5], 'adds to the new parent')
|
|
1101
|
-
assert.deepEqual(root.definitions.namespaces, [n1, n2, n3, n4, n5], 'keeps the namespace in the root definitions')
|
|
1102
|
-
})
|
|
1103
|
-
|
|
1104
|
-
test('throws when adapting self', ({ assert }) => {
|
|
1105
|
-
assert.throws(() => n1.adaptNamespace(n1), 'Unable to adapt a namespace that is self.')
|
|
1106
|
-
})
|
|
1107
|
-
|
|
1108
|
-
test('throws when adapting a namespace from another root', ({ assert }) => {
|
|
1109
|
-
const otherRoot = new DataNamespace()
|
|
1110
|
-
const otherNs = otherRoot.addNamespace('other')
|
|
1111
|
-
assert.throws(
|
|
1112
|
-
() => n1.adaptNamespace(otherNs),
|
|
1113
|
-
`The namespace ${otherNs.key} is not in the same namespace as this data namespace.`
|
|
1114
|
-
)
|
|
1115
|
-
})
|
|
1116
|
-
|
|
1117
|
-
test('throws when adapting a namespace that is already adapted', ({ assert }) => {
|
|
1118
|
-
const n3 = n1.addNamespace('n3')
|
|
1119
|
-
n2.adaptNamespace(n3)
|
|
1120
|
-
assert.throws(() => n2.adaptNamespace(n3), `The namespace ${n3.key} is already adapted by this data namespace.`)
|
|
1121
|
-
})
|
|
1122
|
-
|
|
1123
|
-
test('throws when index is out of range (minimum)', ({ assert }) => {
|
|
1124
|
-
assert.throws(() => n1.adaptNamespace(n2, { index: -1 }), `The index -1 cannot be below 0.`)
|
|
1125
|
-
})
|
|
1126
|
-
|
|
1127
|
-
test('throws when index is out of range (maximum)', ({ assert }) => {
|
|
1128
|
-
assert.throws(() => n1.adaptNamespace(n2, { index: 1 }), `The index 1 is not valid.`)
|
|
1129
|
-
})
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
test.group('adaptNamespace() - Circular Dependency', (group) => {
|
|
1133
|
-
let root: DataNamespace
|
|
1134
|
-
let n1: DataNamespace
|
|
1135
|
-
let n2: DataNamespace
|
|
1136
|
-
let n3: DataNamespace
|
|
1137
|
-
let n4: DataNamespace
|
|
1138
|
-
|
|
1139
|
-
// Root
|
|
1140
|
-
// ├── n1
|
|
1141
|
-
// │ ├── n3
|
|
1142
|
-
// │ │ └── n4
|
|
1143
|
-
// └── n2
|
|
1144
|
-
|
|
1145
|
-
group.each.setup(() => {
|
|
1146
|
-
root = new DataNamespace()
|
|
1147
|
-
n1 = root.addNamespace('n1')
|
|
1148
|
-
n2 = root.addNamespace('n2')
|
|
1149
|
-
n3 = n1.addNamespace('n3')
|
|
1150
|
-
n4 = n3.addNamespace('n4')
|
|
1151
|
-
})
|
|
1152
|
-
|
|
1153
|
-
test('throws when adapting a namespace under itself', ({ assert }) => {
|
|
1154
|
-
assert.throws(() => n1.adaptNamespace(n1), 'Unable to adapt a namespace that is self.')
|
|
1155
|
-
})
|
|
1156
|
-
|
|
1157
|
-
test('throws when adapting a namespace under its child', ({ assert }) => {
|
|
1158
|
-
assert.throws(
|
|
1159
|
-
() => n3.adaptNamespace(n1),
|
|
1160
|
-
`Unable to adapt namespace ${n1.key} under itself or one of its children.`
|
|
1161
|
-
)
|
|
1162
|
-
})
|
|
1163
|
-
|
|
1164
|
-
test('throws when adapting a namespace under its grandchild', ({ assert }) => {
|
|
1165
|
-
assert.throws(
|
|
1166
|
-
() => n4.adaptNamespace(n1),
|
|
1167
|
-
`Unable to adapt namespace ${n1.key} under itself or one of its children.`
|
|
1168
|
-
)
|
|
1169
|
-
})
|
|
1170
|
-
|
|
1171
|
-
test('does not throw when adapting a namespace under its sibling', ({ assert }) => {
|
|
1172
|
-
const n5 = n1.addNamespace('n5')
|
|
1173
|
-
assert.doesNotThrow(() => n2.adaptNamespace(n5))
|
|
1174
|
-
})
|
|
1175
|
-
|
|
1176
|
-
test("does not throw when adapting a namespace under its sibling's child", ({ assert }) => {
|
|
1177
|
-
const n5 = n1.addNamespace('n5')
|
|
1178
|
-
const n6 = n5.addNamespace('n6')
|
|
1179
|
-
assert.doesNotThrow(() => n2.adaptNamespace(n6))
|
|
1180
|
-
})
|
|
1181
|
-
|
|
1182
|
-
test("does not throw when adapting a namespace under its sibling's parent", ({ assert }) => {
|
|
1183
|
-
const n5 = n1.addNamespace('n5')
|
|
1184
|
-
// Root (before)
|
|
1185
|
-
// ├── n1
|
|
1186
|
-
// │ ├── n3
|
|
1187
|
-
// │ │ └── n4
|
|
1188
|
-
// │ └── n5
|
|
1189
|
-
// └── n2
|
|
1190
|
-
// Root (after)
|
|
1191
|
-
// └── n1
|
|
1192
|
-
// ├── n3
|
|
1193
|
-
// │ └── n4
|
|
1194
|
-
// └── n5
|
|
1195
|
-
// └── n2
|
|
1196
|
-
assert.doesNotThrow(() => n5.adaptNamespace(n2))
|
|
1197
|
-
})
|
|
1198
|
-
})
|
|
1199
|
-
|
|
1200
|
-
test.group('adaptDataModel()', (group) => {
|
|
1201
|
-
let root: DataNamespace
|
|
1202
|
-
let n1: DataNamespace
|
|
1203
|
-
let n2: DataNamespace
|
|
1204
|
-
let m1: DataModel
|
|
1205
|
-
let m2: DataModel
|
|
1206
|
-
|
|
1207
|
-
group.each.setup(() => {
|
|
1208
|
-
root = new DataNamespace()
|
|
1209
|
-
n1 = root.addNamespace('n1')
|
|
1210
|
-
n2 = root.addNamespace('n2')
|
|
1211
|
-
m1 = n1.addDataModel('m1')
|
|
1212
|
-
m2 = n1.addDataModel('m2')
|
|
1213
|
-
m1.addEntity('e1')
|
|
1214
|
-
})
|
|
1215
|
-
|
|
1216
|
-
test('moves a data model to a new parent', ({ assert }) => {
|
|
1217
|
-
n2.adaptDataModel(m1)
|
|
1218
|
-
const item1 = DataItem.dataModel(root, m1.key)
|
|
1219
|
-
const item2 = DataItem.dataModel(root, m2.key)
|
|
1220
|
-
assert.deepEqual(n1.items, [item2], 'removes from the old parent')
|
|
1221
|
-
assert.deepEqual(n2.items, [item1], 'adds to the new parent')
|
|
1222
|
-
assert.deepEqual(root.definitions.models, [m1, m2], 'keeps the data model in the root definitions')
|
|
1223
|
-
})
|
|
1224
|
-
|
|
1225
|
-
test('moves a data model to a new index', ({ assert }) => {
|
|
1226
|
-
const m3 = n2.addDataModel('m3')
|
|
1227
|
-
n2.adaptDataModel(m1, { index: 0 })
|
|
1228
|
-
const item1 = DataItem.dataModel(root, m1.key)
|
|
1229
|
-
const item2 = DataItem.dataModel(root, m2.key)
|
|
1230
|
-
const item3 = DataItem.dataModel(root, m3.key)
|
|
1231
|
-
assert.deepEqual(n1.items, [item2], 'removes from the old parent')
|
|
1232
|
-
assert.deepEqual(n2.items, [item1, item3], 'adds to the new parent')
|
|
1233
|
-
assert.deepEqual(root.definitions.models, [m1, m2, m3], 'keeps the data model in the root definitions')
|
|
1234
|
-
})
|
|
1235
|
-
|
|
1236
|
-
test('throws when adapting a data model from another root', ({ assert }) => {
|
|
1237
|
-
const otherRoot = new DataNamespace()
|
|
1238
|
-
const otherNs = otherRoot.addNamespace('other')
|
|
1239
|
-
const otherModel = otherNs.addDataModel('Other Data Model')
|
|
1240
|
-
assert.throws(
|
|
1241
|
-
() => n1.adaptDataModel(otherModel),
|
|
1242
|
-
`The data model ${otherModel.key} is not in the same namespace as this data namespace.`
|
|
1243
|
-
)
|
|
1244
|
-
})
|
|
1245
|
-
|
|
1246
|
-
test('throws when adapting a data model that is already adapted', ({ assert }) => {
|
|
1247
|
-
n2.adaptDataModel(m1)
|
|
1248
|
-
assert.throws(() => n2.adaptDataModel(m1), `The data model ${m1.key} is already adapted by this data namespace.`)
|
|
1249
|
-
})
|
|
1250
|
-
|
|
1251
|
-
test('throws when index is out of range (minimum)', ({ assert }) => {
|
|
1252
|
-
assert.throws(() => n2.adaptDataModel(m1, { index: -1 }), `The index -1 cannot be below 0.`)
|
|
1253
|
-
})
|
|
1254
|
-
|
|
1255
|
-
test('throws when index is out of range (maximum)', ({ assert }) => {
|
|
1256
|
-
assert.throws(() => n2.adaptDataModel(m1, { index: 1 }), `The index 1 is not valid.`)
|
|
1257
|
-
})
|
|
1258
|
-
|
|
1259
|
-
test('throws when adapting a data model from another namespace', ({ assert }) => {
|
|
1260
|
-
const otherRoot = new DataNamespace()
|
|
1261
|
-
const otherModel = new DataModel(otherRoot)
|
|
1262
|
-
assert.throws(
|
|
1263
|
-
() => n1.adaptDataModel(otherModel),
|
|
1264
|
-
`The data model ${otherModel.key} is not in the same namespace as this data namespace.`
|
|
1265
|
-
)
|
|
1266
|
-
})
|
|
1267
|
-
})
|
|
1268
|
-
|
|
1269
|
-
test.group('isChildOf()', (group) => {
|
|
1270
|
-
let root: DataNamespace
|
|
1271
|
-
let n1: DataNamespace
|
|
1272
|
-
let n2: DataNamespace
|
|
1273
|
-
let n3: DataNamespace
|
|
1274
|
-
|
|
1275
|
-
group.each.setup(() => {
|
|
1276
|
-
root = new DataNamespace()
|
|
1277
|
-
n1 = root.addNamespace('n1')
|
|
1278
|
-
n2 = n1.addNamespace('n2')
|
|
1279
|
-
n3 = n2.addNamespace('n3')
|
|
1280
|
-
})
|
|
1281
|
-
|
|
1282
|
-
test('returns false when called on the root namespace', ({ assert }) => {
|
|
1283
|
-
const result = root.isChildOf('some-key')
|
|
1284
|
-
assert.isFalse(result)
|
|
1285
|
-
})
|
|
1286
|
-
|
|
1287
|
-
test('returns true when called on a direct child', ({ assert }) => {
|
|
1288
|
-
const result = n1.isChildOf(root.key)
|
|
1289
|
-
assert.isTrue(result)
|
|
1290
|
-
})
|
|
1291
|
-
|
|
1292
|
-
test('returns true when called on a grandchild', ({ assert }) => {
|
|
1293
|
-
const result = n3.isChildOf(root.key)
|
|
1294
|
-
assert.isTrue(result)
|
|
1295
|
-
})
|
|
1296
|
-
|
|
1297
|
-
test('returns false when called on a sibling', ({ assert }) => {
|
|
1298
|
-
const n4 = root.addNamespace('n4')
|
|
1299
|
-
const result = n1.isChildOf(n4.key)
|
|
1300
|
-
assert.isFalse(result)
|
|
1301
|
-
})
|
|
1302
|
-
|
|
1303
|
-
test('returns false when called on a parent', ({ assert }) => {
|
|
1304
|
-
const result = root.isChildOf(n1.key)
|
|
1305
|
-
assert.isFalse(result)
|
|
1306
|
-
})
|
|
1307
|
-
|
|
1308
|
-
test('returns false when called on a non-existent namespace', ({ assert }) => {
|
|
1309
|
-
const result = n1.isChildOf('non-existent-key')
|
|
1310
|
-
assert.isFalse(result)
|
|
1311
|
-
})
|
|
1312
|
-
})
|