@api-client/core 0.11.4 → 0.11.7
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/oauth-popup.html +33 -0
- package/build/src/amf/definitions/Shapes.d.ts +1 -1
- package/build/src/amf/definitions/Shapes.js.map +1 -1
- package/build/src/modeling/DataAssociation.d.ts +7 -3
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +22 -6
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataEntity.d.ts +14 -1
- package/build/src/modeling/DataEntity.d.ts.map +1 -1
- package/build/src/modeling/DataEntity.js +39 -9
- package/build/src/modeling/DataEntity.js.map +1 -1
- package/build/src/modeling/DataModel.d.ts +5 -1
- package/build/src/modeling/DataModel.d.ts.map +1 -1
- package/build/src/modeling/DataModel.js +15 -11
- package/build/src/modeling/DataModel.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +12 -1
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +45 -6
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/build/src/modeling/DataProperty.js +2 -2
- package/build/src/modeling/DataProperty.js.map +1 -1
- package/data/models/example-generator-api.json +27 -27
- package/package.json +6 -16
- package/src/amf/definitions/Shapes.ts +1 -1
- package/src/modeling/DataAssociation.ts +26 -6
- package/src/modeling/DataEntity.ts +44 -9
- package/src/modeling/DataModel.ts +16 -11
- package/src/modeling/DataNamespace.ts +46 -6
- package/src/modeling/DataProperty.ts +2 -2
- package/tests/unit/modeling/data_association.spec.ts +2 -2
- package/tests/unit/modeling/data_entity.spec.ts +3 -3
- package/tests/unit/modeling/data_model.spec.ts +3 -3
- package/tests/unit/modeling/data_namespace.spec.ts +72 -3
- package/tsconfig.browser.json +2 -1
- package/Local.session.sql +0 -0
|
@@ -68,7 +68,7 @@ export interface IApiAssociationShape {
|
|
|
68
68
|
* - anyOf - To validate against `anyOf`, the given data must be valid against
|
|
69
69
|
* any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.
|
|
70
70
|
* - oneOf - To validate against `oneOf`, the given data must be valid against
|
|
71
|
-
* exactly one of the given sub-schemas. It behaves the same as `
|
|
71
|
+
* exactly one of the given sub-schemas. It behaves the same as `anyOf` when generating a schema
|
|
72
72
|
* - not - The `not` keyword declares that an instance validates if it doesn’t
|
|
73
73
|
* validate against the given sub-schema. It has no use when generating a schema.
|
|
74
74
|
*
|
|
@@ -358,9 +358,9 @@ export class DataAssociation {
|
|
|
358
358
|
*/
|
|
359
359
|
remove(): void {
|
|
360
360
|
const { root } = this
|
|
361
|
-
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j === this))
|
|
361
|
+
const entity = root.definitions.entities.find((i) => i.associations.some((j) => j.key === this.key))
|
|
362
362
|
if (entity) {
|
|
363
|
-
const assocIndex = entity.associations.findIndex((i) => i === this)
|
|
363
|
+
const assocIndex = entity.associations.findIndex((i) => i.key === this.key)
|
|
364
364
|
entity.associations.splice(assocIndex, 1)
|
|
365
365
|
}
|
|
366
366
|
const defIndex = this.root.definitions.associations.findIndex((i) => i.key === this.key)
|
|
@@ -402,6 +402,19 @@ export class DataAssociation {
|
|
|
402
402
|
namespace = typed.root.key
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
+
if (this.targets.some((i) => i.key === key)) {
|
|
406
|
+
const message = `Target ${key} already exists.`
|
|
407
|
+
throw new ValidationError(
|
|
408
|
+
[
|
|
409
|
+
{
|
|
410
|
+
field: 'targets',
|
|
411
|
+
message,
|
|
412
|
+
rule: 'unique',
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
{ message }
|
|
416
|
+
)
|
|
417
|
+
}
|
|
405
418
|
if (namespace && namespace !== this.root.key) {
|
|
406
419
|
const foreignNamespace = this.root.foreign.find((ns) => ns.key === namespace)
|
|
407
420
|
if (!foreignNamespace) {
|
|
@@ -450,15 +463,22 @@ export class DataAssociation {
|
|
|
450
463
|
return serializer.associationProperty(this)
|
|
451
464
|
}
|
|
452
465
|
|
|
466
|
+
/**
|
|
467
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
468
|
+
*/
|
|
469
|
+
getParent(): DataEntity {
|
|
470
|
+
return this.getParentInstance()
|
|
471
|
+
}
|
|
472
|
+
|
|
453
473
|
/**
|
|
454
474
|
* Retrieves the parent entity of this association.
|
|
455
475
|
*
|
|
456
476
|
* @returns The `DataEntity` instance that contains this association.
|
|
457
477
|
*/
|
|
458
|
-
|
|
478
|
+
getParentInstance(): DataEntity {
|
|
459
479
|
// this is forced as an association is only created when an entity is created
|
|
460
480
|
// so it has to be defined.
|
|
461
|
-
return this.root.definitions.entities.find((i) => i.associations.
|
|
481
|
+
return this.root.definitions.entities.find((i) => i.associations.some((a) => a.key === this.key)) as DataEntity
|
|
462
482
|
}
|
|
463
483
|
|
|
464
484
|
/**
|
|
@@ -473,9 +493,9 @@ export class DataAssociation {
|
|
|
473
493
|
}
|
|
474
494
|
|
|
475
495
|
/**
|
|
476
|
-
* Checks whether the passed value is one of the supported data
|
|
496
|
+
* Checks whether the passed value is one of the supported data property attributes.
|
|
477
497
|
* @param value The value to test
|
|
478
|
-
* @returns True when the passed value is one of the supported data
|
|
498
|
+
* @returns True when the passed value is one of the supported data property attributes.
|
|
479
499
|
*/
|
|
480
500
|
static isValidAttribute(value: unknown): value is DataAttributeAttribute {
|
|
481
501
|
if (typeof value !== 'string') {
|
|
@@ -585,7 +585,7 @@ export class DataEntity {
|
|
|
585
585
|
)
|
|
586
586
|
if (associationsToEntity.length > 0) {
|
|
587
587
|
const entitiesNames = associationsToEntity.reduce<string[]>((acc, association) => {
|
|
588
|
-
const entity = root.definitions.entities.find((e) => e.associations.
|
|
588
|
+
const entity = root.definitions.entities.find((e) => e.associations.some((a) => a.key === association.key))
|
|
589
589
|
if (entity) {
|
|
590
590
|
acc.push(entity.info.name as string)
|
|
591
591
|
}
|
|
@@ -605,18 +605,26 @@ export class DataEntity {
|
|
|
605
605
|
root.definitions.entities.splice(index, 1)
|
|
606
606
|
}
|
|
607
607
|
// remove from the parent
|
|
608
|
-
const model = this.
|
|
608
|
+
const model = this.getParentInstance()
|
|
609
609
|
if (model) {
|
|
610
|
-
const entityIndex = model.entities.findIndex((e) => e === this)
|
|
610
|
+
const entityIndex = model.entities.findIndex((e) => e.key === this.key)
|
|
611
611
|
model.entities.splice(entityIndex, 1)
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
/**
|
|
616
|
-
*
|
|
616
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
617
617
|
*/
|
|
618
|
+
// This method name collides with the `getParents()` method.
|
|
618
619
|
getParent(): DataModel | undefined {
|
|
619
|
-
return this.
|
|
620
|
+
return this.getParentInstance()
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Returns a parent data model where this entity exist.
|
|
625
|
+
*/
|
|
626
|
+
getParentInstance(): DataModel | undefined {
|
|
627
|
+
return this.root.definitions.models.find((m) => m.entities.some((e) => e.key === this.key))
|
|
620
628
|
}
|
|
621
629
|
|
|
622
630
|
/**
|
|
@@ -677,7 +685,7 @@ export class DataEntity {
|
|
|
677
685
|
{
|
|
678
686
|
field: 'parents',
|
|
679
687
|
message,
|
|
680
|
-
rule: '
|
|
688
|
+
rule: 'unique',
|
|
681
689
|
},
|
|
682
690
|
],
|
|
683
691
|
{ message }
|
|
@@ -687,6 +695,33 @@ export class DataEntity {
|
|
|
687
695
|
return this
|
|
688
696
|
}
|
|
689
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Removes a parent reference from this entity.
|
|
700
|
+
* It keeps the parent as is.
|
|
701
|
+
*
|
|
702
|
+
* @param key The key of the parent entity to remove.
|
|
703
|
+
* @throws ValidationError when the parent is not found.
|
|
704
|
+
* @returns Self for chaining.
|
|
705
|
+
*/
|
|
706
|
+
removeParent(key: string): this {
|
|
707
|
+
const index = this.parents.findIndex((i) => i === key)
|
|
708
|
+
if (index < 0) {
|
|
709
|
+
const message = `Parent ${key} not found.`
|
|
710
|
+
throw new ValidationError(
|
|
711
|
+
[
|
|
712
|
+
{
|
|
713
|
+
field: 'parents',
|
|
714
|
+
message,
|
|
715
|
+
rule: 'not-found',
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
{ message }
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
this.parents.splice(index, 1)
|
|
722
|
+
return this
|
|
723
|
+
}
|
|
724
|
+
|
|
690
725
|
/**
|
|
691
726
|
* Checks if the entity has a circular parent relationship when attempting to add a new parent.
|
|
692
727
|
* @param key The key of the parent being added.
|
|
@@ -808,21 +843,21 @@ export class DataEntity {
|
|
|
808
843
|
name: this.info.name || 'Unnamed entity',
|
|
809
844
|
kind: DataEntityKind,
|
|
810
845
|
})
|
|
811
|
-
const model = this.
|
|
846
|
+
const model = this.getParentInstance()
|
|
812
847
|
if (model) {
|
|
813
848
|
result.push({
|
|
814
849
|
key: model.key,
|
|
815
850
|
kind: model.kind,
|
|
816
851
|
name: model.info.name || 'Unnamed data model',
|
|
817
852
|
})
|
|
818
|
-
let parent = model.
|
|
853
|
+
let parent = model.getParentInstance()
|
|
819
854
|
while (parent && parent !== this.root) {
|
|
820
855
|
result.push({
|
|
821
856
|
key: parent.key,
|
|
822
857
|
kind: parent.kind,
|
|
823
858
|
name: parent.info.name || 'Unnamed namespace',
|
|
824
859
|
})
|
|
825
|
-
parent = parent.
|
|
860
|
+
parent = parent.getParentInstance()
|
|
826
861
|
}
|
|
827
862
|
}
|
|
828
863
|
result.push({
|
|
@@ -135,7 +135,7 @@ export class DataModel {
|
|
|
135
135
|
entities.forEach((e) => e.remove())
|
|
136
136
|
|
|
137
137
|
// remove self from the parent
|
|
138
|
-
const parent = this.
|
|
138
|
+
const parent = this.getParentInstance()
|
|
139
139
|
if (parent) {
|
|
140
140
|
const itemIndex = parent.items.findIndex((i) => i.key === key)
|
|
141
141
|
if (itemIndex >= 0) {
|
|
@@ -169,17 +169,15 @@ export class DataModel {
|
|
|
169
169
|
if (entity.root !== this.root) {
|
|
170
170
|
throw new Error(`The entity ${entity.key} is not in the same namespace as this data model.`)
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
throw new Error(`The entity ${entity.key} is already adapted by this data model.`)
|
|
174
|
-
}
|
|
175
|
-
const parent = entity.getParent()
|
|
172
|
+
const parent = entity.getParentInstance()
|
|
176
173
|
if (!parent) {
|
|
177
174
|
throw new Error(`The entity ${entity.key} has no parent.`)
|
|
178
175
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
throw new Error(`The entity ${entity.key} is not in the parent data model.`)
|
|
176
|
+
if (parent.key === this.key) {
|
|
177
|
+
throw new Error(`The entity ${entity.key} is already adapted by this data model.`)
|
|
182
178
|
}
|
|
179
|
+
// it has a parent (above check) so it has the index.
|
|
180
|
+
const index = parent.entities.findIndex((i) => i.key === entity.key)
|
|
183
181
|
parent.entities.splice(index, 1)
|
|
184
182
|
if (opts.index !== undefined) {
|
|
185
183
|
this.entities.splice(opts.index, 0, entity)
|
|
@@ -209,9 +207,16 @@ export class DataModel {
|
|
|
209
207
|
}
|
|
210
208
|
|
|
211
209
|
/**
|
|
212
|
-
*
|
|
210
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
213
211
|
*/
|
|
214
212
|
getParent(): DataNamespace | undefined {
|
|
213
|
+
return this.getParentInstance()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Returns the parent namespace where this data model exist.
|
|
218
|
+
*/
|
|
219
|
+
getParentInstance(): DataNamespace | undefined {
|
|
215
220
|
if (this.root.items.some((e) => e.key === this.key)) {
|
|
216
221
|
return this.root
|
|
217
222
|
}
|
|
@@ -228,14 +233,14 @@ export class DataModel {
|
|
|
228
233
|
name: this.info.name || 'Unnamed data model',
|
|
229
234
|
kind: DataModelKind,
|
|
230
235
|
})
|
|
231
|
-
let parent = this.
|
|
236
|
+
let parent = this.getParentInstance()
|
|
232
237
|
while (parent && parent !== this.root) {
|
|
233
238
|
result.push({
|
|
234
239
|
key: parent.key,
|
|
235
240
|
kind: parent.kind,
|
|
236
241
|
name: parent.info.name || 'Unnamed namespace',
|
|
237
242
|
})
|
|
238
|
-
parent = parent.
|
|
243
|
+
parent = parent.getParentInstance()
|
|
239
244
|
}
|
|
240
245
|
result.push({
|
|
241
246
|
key: this.root.key,
|
|
@@ -127,9 +127,16 @@ class DataNamespaceParent {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* @
|
|
130
|
+
* @deprecated Use the `getParentInstance()` method instead.
|
|
131
131
|
*/
|
|
132
132
|
getParent(): DataNamespace | undefined {
|
|
133
|
+
return this.getParentInstance()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
138
|
+
*/
|
|
139
|
+
getParentInstance(): DataNamespace | undefined {
|
|
133
140
|
const { root, key } = this
|
|
134
141
|
if (root) {
|
|
135
142
|
const result = (root as DataNamespace).findParent(key)
|
|
@@ -523,7 +530,7 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
523
530
|
if (ns.root !== this.root) {
|
|
524
531
|
throw new Error(`The namespace ${ns.key} is not in the same namespace as this data namespace.`)
|
|
525
532
|
}
|
|
526
|
-
if (ns.
|
|
533
|
+
if (ns.getParentInstance() === this) {
|
|
527
534
|
throw new Error(`The namespace ${ns.key} is already adapted by this data namespace.`)
|
|
528
535
|
}
|
|
529
536
|
// Check for circular dependency
|
|
@@ -532,16 +539,49 @@ export class DataNamespace extends DataNamespaceParent {
|
|
|
532
539
|
if (current === ns) {
|
|
533
540
|
throw new Error(`Unable to adapt namespace ${ns.key} under itself or one of its children.`)
|
|
534
541
|
}
|
|
535
|
-
current = current.
|
|
542
|
+
current = current.getParentInstance()
|
|
536
543
|
}
|
|
537
|
-
const parent = ns.
|
|
544
|
+
const parent = ns.getParentInstance() || this.root
|
|
538
545
|
if (!parent) {
|
|
539
546
|
throw new Error(`The namespace ${ns.key} has no parent.`)
|
|
540
547
|
}
|
|
548
|
+
// it has a parent (above check) so it has the index.
|
|
541
549
|
const index = parent.items.findIndex((i) => i.key === ns.key)
|
|
542
|
-
|
|
543
|
-
|
|
550
|
+
const [item] = parent.items.splice(index, 1)
|
|
551
|
+
if (opts.index !== undefined) {
|
|
552
|
+
this.items.splice(opts.index, 0, item)
|
|
553
|
+
} else {
|
|
554
|
+
this.items.push(item)
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Adapts an existing data model to this namespace.
|
|
560
|
+
* This will remove the data model from the parent namespace and add it to this one.
|
|
561
|
+
* @param model The data model to adapt.
|
|
562
|
+
* @param opts The adapting options.
|
|
563
|
+
*/
|
|
564
|
+
adaptDataModel(model: DataModel, opts: DataItemAdaptingOptions = {}): void {
|
|
565
|
+
if (opts.index !== undefined) {
|
|
566
|
+
if (opts.index < 0) {
|
|
567
|
+
throw new Error(`The index ${opts.index} cannot be below 0.`)
|
|
568
|
+
}
|
|
569
|
+
if (opts.index >= this.items.length) {
|
|
570
|
+
throw new Error(`The index ${opts.index} is not valid.`)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (model.root !== this.root) {
|
|
574
|
+
throw new Error(`The data model ${model.key} is not in the same namespace as this data namespace.`)
|
|
575
|
+
}
|
|
576
|
+
const parent = model.getParentInstance()
|
|
577
|
+
if (!parent) {
|
|
578
|
+
throw new Error(`The data model ${model.key} has no parent.`)
|
|
579
|
+
}
|
|
580
|
+
if (parent === this) {
|
|
581
|
+
throw new Error(`The data model ${model.key} is already adapted by this data namespace.`)
|
|
544
582
|
}
|
|
583
|
+
// it has a parent (above check) so it has the index.
|
|
584
|
+
const index = parent.items.findIndex((i) => i.key === model.key)
|
|
545
585
|
const [item] = parent.items.splice(index, 1)
|
|
546
586
|
if (opts.index !== undefined) {
|
|
547
587
|
this.items.splice(opts.index, 0, item)
|
|
@@ -445,9 +445,9 @@ export class DataProperty {
|
|
|
445
445
|
*/
|
|
446
446
|
remove(): void {
|
|
447
447
|
const { root } = this
|
|
448
|
-
const entity = root.definitions.entities.find((i) => i.properties.some((j) => j === this))
|
|
448
|
+
const entity = root.definitions.entities.find((i) => i.properties.some((j) => j.key === this.key))
|
|
449
449
|
if (entity) {
|
|
450
|
-
const assocIndex = entity.properties.findIndex((i) => i === this)
|
|
450
|
+
const assocIndex = entity.properties.findIndex((i) => i.key === this.key)
|
|
451
451
|
entity.properties.splice(assocIndex, 1)
|
|
452
452
|
}
|
|
453
453
|
const defIndex = this.root.definitions.properties.findIndex((i) => i.key === this.key)
|
|
@@ -510,7 +510,7 @@ test.group('toApiShape()', (g) => {
|
|
|
510
510
|
})
|
|
511
511
|
})
|
|
512
512
|
|
|
513
|
-
test.group('
|
|
513
|
+
test.group('getParentInstance()', (g) => {
|
|
514
514
|
let root: DataNamespace
|
|
515
515
|
let m1: DataModel
|
|
516
516
|
let e1: DataEntity
|
|
@@ -525,7 +525,7 @@ test.group('getParent()', (g) => {
|
|
|
525
525
|
|
|
526
526
|
test('returns the reference to the parent entity', ({ assert }) => {
|
|
527
527
|
const a1 = e1.addTargetAssociation(e2.key)
|
|
528
|
-
const result = a1.
|
|
528
|
+
const result = a1.getParentInstance()
|
|
529
529
|
assert.deepEqual(result, e1)
|
|
530
530
|
})
|
|
531
531
|
})
|
|
@@ -1616,7 +1616,7 @@ test.group('addParent()', (group) => {
|
|
|
1616
1616
|
})
|
|
1617
1617
|
})
|
|
1618
1618
|
|
|
1619
|
-
test.group('
|
|
1619
|
+
test.group('getParentInstance()', (group) => {
|
|
1620
1620
|
let root: DataNamespace
|
|
1621
1621
|
let model: DataModel
|
|
1622
1622
|
let entity1: DataEntity
|
|
@@ -1628,12 +1628,12 @@ test.group('DataEntity - getParent()', (group) => {
|
|
|
1628
1628
|
})
|
|
1629
1629
|
|
|
1630
1630
|
test('returns undefined when the entity is not in a model', ({ assert }) => {
|
|
1631
|
-
const result = new DataEntity(root).
|
|
1631
|
+
const result = new DataEntity(root).getParentInstance()
|
|
1632
1632
|
assert.isUndefined(result)
|
|
1633
1633
|
})
|
|
1634
1634
|
|
|
1635
1635
|
test('returns the parent data model', ({ assert }) => {
|
|
1636
|
-
const result = entity1.
|
|
1636
|
+
const result = entity1.getParentInstance()
|
|
1637
1637
|
assert.instanceOf(result, DataModel)
|
|
1638
1638
|
})
|
|
1639
1639
|
})
|
|
@@ -227,7 +227,7 @@ test.group('addEntity()', (group) => {
|
|
|
227
227
|
})
|
|
228
228
|
})
|
|
229
229
|
|
|
230
|
-
test.group('
|
|
230
|
+
test.group('getParentInstance()', (group) => {
|
|
231
231
|
let root: DataNamespace
|
|
232
232
|
|
|
233
233
|
group.each.setup(() => {
|
|
@@ -236,14 +236,14 @@ test.group('getParent()', (group) => {
|
|
|
236
236
|
|
|
237
237
|
test('returns the parent as root', ({ assert }) => {
|
|
238
238
|
const m1 = root.addDataModel('m1')
|
|
239
|
-
const result = m1.
|
|
239
|
+
const result = m1.getParentInstance()
|
|
240
240
|
assert.isTrue(result === root)
|
|
241
241
|
})
|
|
242
242
|
|
|
243
243
|
test('returns the parent is as sub-namespace', ({ assert }) => {
|
|
244
244
|
const n1 = root.addNamespace('n1')
|
|
245
245
|
const m1 = n1.addDataModel('m1')
|
|
246
|
-
const result = m1.
|
|
246
|
+
const result = m1.getParentInstance()
|
|
247
247
|
assert.isTrue(result === n1)
|
|
248
248
|
})
|
|
249
249
|
})
|
|
@@ -1033,7 +1033,7 @@ test.group('getRoot()', (group) => {
|
|
|
1033
1033
|
})
|
|
1034
1034
|
})
|
|
1035
1035
|
|
|
1036
|
-
test.group('
|
|
1036
|
+
test.group('getParentInstance()', (group) => {
|
|
1037
1037
|
let root: DataNamespace
|
|
1038
1038
|
let n1: DataNamespace
|
|
1039
1039
|
let n2: DataNamespace
|
|
@@ -1045,12 +1045,12 @@ test.group('getParent()', (group) => {
|
|
|
1045
1045
|
})
|
|
1046
1046
|
|
|
1047
1047
|
test('returns undefined when called on the root namespace', ({ assert }) => {
|
|
1048
|
-
const result = root.
|
|
1048
|
+
const result = root.getParentInstance()
|
|
1049
1049
|
assert.isUndefined(result)
|
|
1050
1050
|
})
|
|
1051
1051
|
|
|
1052
1052
|
test('returns the parent namespace when called on a sub-namespace', ({ assert }) => {
|
|
1053
|
-
const result = n2.
|
|
1053
|
+
const result = n2.getParentInstance()
|
|
1054
1054
|
assert.deepEqual(result, n1)
|
|
1055
1055
|
})
|
|
1056
1056
|
})
|
|
@@ -1203,3 +1203,72 @@ test.group('adaptNamespace() - Circular Dependency', (group) => {
|
|
|
1203
1203
|
assert.doesNotThrow(() => n5.adaptNamespace(n2))
|
|
1204
1204
|
})
|
|
1205
1205
|
})
|
|
1206
|
+
|
|
1207
|
+
test.group('adaptDataModel()', (group) => {
|
|
1208
|
+
let root: DataNamespace
|
|
1209
|
+
let n1: DataNamespace
|
|
1210
|
+
let n2: DataNamespace
|
|
1211
|
+
let m1: DataModel
|
|
1212
|
+
let m2: DataModel
|
|
1213
|
+
|
|
1214
|
+
group.each.setup(() => {
|
|
1215
|
+
root = new DataNamespace()
|
|
1216
|
+
n1 = root.addNamespace('n1')
|
|
1217
|
+
n2 = root.addNamespace('n2')
|
|
1218
|
+
m1 = n1.addDataModel('m1')
|
|
1219
|
+
m2 = n1.addDataModel('m2')
|
|
1220
|
+
m1.addEntity('e1')
|
|
1221
|
+
})
|
|
1222
|
+
|
|
1223
|
+
test('moves a data model to a new parent', ({ assert }) => {
|
|
1224
|
+
n2.adaptDataModel(m1)
|
|
1225
|
+
const item1 = DataItem.dataModel(root, m1.key)
|
|
1226
|
+
const item2 = DataItem.dataModel(root, m2.key)
|
|
1227
|
+
assert.deepEqual(n1.items, [item2], 'removes from the old parent')
|
|
1228
|
+
assert.deepEqual(n2.items, [item1], 'adds to the new parent')
|
|
1229
|
+
assert.deepEqual(root.definitions.models, [m1, m2], 'keeps the data model in the root definitions')
|
|
1230
|
+
})
|
|
1231
|
+
|
|
1232
|
+
test('moves a data model to a new index', ({ assert }) => {
|
|
1233
|
+
const m3 = n2.addDataModel('m3')
|
|
1234
|
+
n2.adaptDataModel(m1, { index: 0 })
|
|
1235
|
+
const item1 = DataItem.dataModel(root, m1.key)
|
|
1236
|
+
const item2 = DataItem.dataModel(root, m2.key)
|
|
1237
|
+
const item3 = DataItem.dataModel(root, m3.key)
|
|
1238
|
+
assert.deepEqual(n1.items, [item2], 'removes from the old parent')
|
|
1239
|
+
assert.deepEqual(n2.items, [item1, item3], 'adds to the new parent')
|
|
1240
|
+
assert.deepEqual(root.definitions.models, [m1, m2, m3], 'keeps the data model in the root definitions')
|
|
1241
|
+
})
|
|
1242
|
+
|
|
1243
|
+
test('throws when adapting a data model from another root', ({ assert }) => {
|
|
1244
|
+
const otherRoot = new DataNamespace()
|
|
1245
|
+
const otherNs = otherRoot.addNamespace('other')
|
|
1246
|
+
const otherModel = otherNs.addDataModel('Other Data Model')
|
|
1247
|
+
assert.throws(
|
|
1248
|
+
() => n1.adaptDataModel(otherModel),
|
|
1249
|
+
`The data model ${otherModel.key} is not in the same namespace as this data namespace.`
|
|
1250
|
+
)
|
|
1251
|
+
})
|
|
1252
|
+
|
|
1253
|
+
test('throws when adapting a data model that is already adapted', ({ assert }) => {
|
|
1254
|
+
n2.adaptDataModel(m1)
|
|
1255
|
+
assert.throws(() => n2.adaptDataModel(m1), `The data model ${m1.key} is already adapted by this data namespace.`)
|
|
1256
|
+
})
|
|
1257
|
+
|
|
1258
|
+
test('throws when index is out of range (minimum)', ({ assert }) => {
|
|
1259
|
+
assert.throws(() => n2.adaptDataModel(m1, { index: -1 }), `The index -1 cannot be below 0.`)
|
|
1260
|
+
})
|
|
1261
|
+
|
|
1262
|
+
test('throws when index is out of range (maximum)', ({ assert }) => {
|
|
1263
|
+
assert.throws(() => n2.adaptDataModel(m1, { index: 1 }), `The index 1 is not valid.`)
|
|
1264
|
+
})
|
|
1265
|
+
|
|
1266
|
+
test('throws when adapting a data model from another namepsace', ({ assert }) => {
|
|
1267
|
+
const otherRoot = new DataNamespace()
|
|
1268
|
+
const otherModel = new DataModel(otherRoot)
|
|
1269
|
+
assert.throws(
|
|
1270
|
+
() => n1.adaptDataModel(otherModel),
|
|
1271
|
+
`The data model ${otherModel.key} is not in the same namespace as this data namespace.`
|
|
1272
|
+
)
|
|
1273
|
+
})
|
|
1274
|
+
})
|
package/tsconfig.browser.json
CHANGED
|
@@ -28,5 +28,6 @@
|
|
|
28
28
|
"resolveJsonModule": true,
|
|
29
29
|
"skipLibCheck": true
|
|
30
30
|
},
|
|
31
|
-
"include": ["src/**/*", "test/**/*"]
|
|
31
|
+
"include": ["src/**/*", "test/**/*"],
|
|
32
|
+
"exclude": ["node_modules", "build", "coverage", ".tmp", ".wireit", "amf-models", "bin", "data", "docs", "scripts"],
|
|
32
33
|
}
|
package/Local.session.sql
DELETED
|
File without changes
|