@api-client/core 0.14.8 → 0.14.10

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.
@@ -42062,10 +42062,10 @@
42062
42062
  "@id": "#209"
42063
42063
  },
42064
42064
  {
42065
- "@id": "#194"
42065
+ "@id": "#191"
42066
42066
  },
42067
42067
  {
42068
- "@id": "#191"
42068
+ "@id": "#194"
42069
42069
  },
42070
42070
  {
42071
42071
  "@id": "#197"
@@ -42810,16 +42810,16 @@
42810
42810
  "@id": "#219"
42811
42811
  },
42812
42812
  {
42813
- "@id": "#219"
42813
+ "@id": "#210"
42814
42814
  },
42815
42815
  {
42816
- "@id": "#210"
42816
+ "@id": "#213"
42817
42817
  },
42818
42818
  {
42819
42819
  "@id": "#216"
42820
42820
  },
42821
42821
  {
42822
- "@id": "#213"
42822
+ "@id": "#219"
42823
42823
  }
42824
42824
  ],
42825
42825
  "doc:root": false,
@@ -43436,7 +43436,7 @@
43436
43436
  "doc:ExternalDomainElement",
43437
43437
  "doc:DomainElement"
43438
43438
  ],
43439
- "doc:raw": "addressType: 'REGISTERED-OFFICE-ADDRESS'\nstreetName: 'UITBREIDINGSTRAAT'\nhouseNumber: '84'\nhouseNumberAddition: '/1'\npostalCode: '2600'\ncity: 'BERCHEM (ANTWERPEN)'\ncountry: 'Belgium'\ncountryCode: 'BE'\nfullFormatedAddress: \"UITBREIDINGSTRAAT 84 /1, 2600 BERCHEM (ANTWERPEN), BELIUM\"\n",
43439
+ "doc:raw": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
43440
43440
  "core:mediaType": "application/yaml",
43441
43441
  "sourcemaps:sources": [
43442
43442
  {
@@ -43457,7 +43457,7 @@
43457
43457
  "doc:ExternalDomainElement",
43458
43458
  "doc:DomainElement"
43459
43459
  ],
43460
- "doc:raw": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
43460
+ "doc:raw": "addressType: 'REGISTERED-OFFICE-ADDRESS'\nstreetName: 'UITBREIDINGSTRAAT'\nhouseNumber: '84'\nhouseNumberAddition: '/1'\npostalCode: '2600'\ncity: 'BERCHEM (ANTWERPEN)'\ncountry: 'Belgium'\ncountryCode: 'BE'\nfullFormatedAddress: \"UITBREIDINGSTRAAT 84 /1, 2600 BERCHEM (ANTWERPEN), BELIUM\"\n",
43461
43461
  "core:mediaType": "application/yaml",
43462
43462
  "sourcemaps:sources": [
43463
43463
  {
@@ -44232,7 +44232,7 @@
44232
44232
  "doc:ExternalDomainElement",
44233
44233
  "doc:DomainElement"
44234
44234
  ],
44235
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44235
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44236
44236
  "core:mediaType": "application/yaml",
44237
44237
  "sourcemaps:sources": [
44238
44238
  {
@@ -44253,7 +44253,7 @@
44253
44253
  "doc:ExternalDomainElement",
44254
44254
  "doc:DomainElement"
44255
44255
  ],
44256
- "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44256
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44257
44257
  "core:mediaType": "application/yaml",
44258
44258
  "sourcemaps:sources": [
44259
44259
  {
@@ -44295,7 +44295,7 @@
44295
44295
  "doc:ExternalDomainElement",
44296
44296
  "doc:DomainElement"
44297
44297
  ],
44298
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44298
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44299
44299
  "core:mediaType": "application/yaml",
44300
44300
  "sourcemaps:sources": [
44301
44301
  {
@@ -44756,12 +44756,12 @@
44756
44756
  {
44757
44757
  "@id": "#193/source-map/lexical/element_0",
44758
44758
  "sourcemaps:element": "amf://id#193",
44759
- "sourcemaps:value": "[(1,0)-(10,0)]"
44759
+ "sourcemaps:value": "[(1,0)-(7,0)]"
44760
44760
  },
44761
44761
  {
44762
44762
  "@id": "#196/source-map/lexical/element_0",
44763
44763
  "sourcemaps:element": "amf://id#196",
44764
- "sourcemaps:value": "[(1,0)-(7,0)]"
44764
+ "sourcemaps:value": "[(1,0)-(10,0)]"
44765
44765
  },
44766
44766
  {
44767
44767
  "@id": "#199/source-map/lexical/element_0",
@@ -45121,7 +45121,7 @@
45121
45121
  {
45122
45122
  "@id": "#215/source-map/lexical/element_0",
45123
45123
  "sourcemaps:element": "amf://id#215",
45124
- "sourcemaps:value": "[(1,0)-(3,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(6,0)]"
45125
45125
  },
45126
45126
  {
45127
45127
  "@id": "#218/source-map/lexical/element_0",
@@ -45131,7 +45131,7 @@
45131
45131
  {
45132
45132
  "@id": "#221/source-map/lexical/element_0",
45133
45133
  "sourcemaps:element": "amf://id#221",
45134
- "sourcemaps:value": "[(1,0)-(6,0)]"
45134
+ "sourcemaps:value": "[(1,0)-(3,0)]"
45135
45135
  },
45136
45136
  {
45137
45137
  "@id": "#338/source-map/synthesized-field/element_1",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.14.8",
4
+ "version": "0.14.10",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -394,6 +394,33 @@ export class DataDomain extends DependentModel {
394
394
  }
395
395
  }
396
396
 
397
+ /**
398
+ * Lists all namespaces in the graph that are part of specified domain.
399
+ *
400
+ * @param namespace The foreign namespace to search in. When not found, it throws an error.
401
+ * @returns A generator that yields each `DomainNamespace`.
402
+ * @throws Error When the foreign domain is not found.
403
+ * @example
404
+ * ```typescript
405
+ * for (const ns of dataDomain.listForeignNamespaces('foreignDomainKey')) {
406
+ * console.log(ns.key);
407
+ * }
408
+ * ```
409
+ */
410
+ *listForeignNamespaces(namespace: string): Generator<DomainNamespace> {
411
+ const foreignDomain = this.dependencies.get(namespace)
412
+ if (!foreignDomain) {
413
+ throw new Error(`Foreign domain ${namespace} not found`)
414
+ }
415
+ for (const node of foreignDomain.listNamespaces()) {
416
+ const key = `${namespace}:${node.key}`
417
+ const value = this.graph.node(key)
418
+ if (value) {
419
+ yield node
420
+ }
421
+ }
422
+ }
423
+
397
424
  /**
398
425
  * Checks if this data domain has any namespaces.
399
426
  *
@@ -661,8 +688,8 @@ export class DataDomain extends DependentModel {
661
688
  * @returns A generator that yields each `DomainModel`.
662
689
  * @example
663
690
  * ```typescript
664
- * for (const ns of namespace.listModels()) {
665
- * console.log(ns.key);
691
+ * for (const model of namespace.listModels()) {
692
+ * console.log(model.key);
666
693
  * }
667
694
  * ```
668
695
  */
@@ -679,6 +706,33 @@ export class DataDomain extends DependentModel {
679
706
  }
680
707
  }
681
708
 
709
+ /**
710
+ * Lists all models in the graph that are part of specified domain.
711
+ *
712
+ * @param namespace The foreign namespace to search in. When not found, it throws an error.
713
+ * @returns A generator that yields each `DomainModel`.
714
+ * @throws Error When the foreign domain is not found.
715
+ * @example
716
+ * ```typescript
717
+ * for (const model of dataDomain.listForeignModels('foreignDomainKey')) {
718
+ * console.log(model.key);
719
+ * }
720
+ * ```
721
+ */
722
+ *listForeignModels(namespace: string): Generator<DomainModel> {
723
+ const foreignDomain = this.dependencies.get(namespace)
724
+ if (!foreignDomain) {
725
+ throw new Error(`Foreign domain ${namespace} not found`)
726
+ }
727
+ for (const node of foreignDomain.listModels()) {
728
+ const key = `${namespace}:${node.key}`
729
+ const value = this.graph.node(key)
730
+ if (value) {
731
+ yield node
732
+ }
733
+ }
734
+ }
735
+
682
736
  /**
683
737
  * Checks if this data domain has any direct models.
684
738
  *
@@ -893,10 +947,37 @@ export class DataDomain extends DependentModel {
893
947
  }
894
948
  }
895
949
 
950
+ /**
951
+ * Lists all entities in the graph that are part of specified domain.
952
+ *
953
+ * @param namespace The foreign namespace to search in. When not found, it throws an error.
954
+ * @returns A generator that yields each `DomainEntity`.
955
+ * @throws Error When the foreign domain is not found.
956
+ * @example
957
+ * ```typescript
958
+ * for (const model of dataDomain.listForeignEntities('foreignDomainKey')) {
959
+ * console.log(model.key);
960
+ * }
961
+ * ```
962
+ */
963
+ *listForeignEntities(namespace: string): Generator<DomainEntity> {
964
+ const foreignDomain = this.dependencies.get(namespace)
965
+ if (!foreignDomain) {
966
+ throw new Error(`Foreign domain ${namespace} not found`)
967
+ }
968
+ for (const node of foreignDomain.listEntities()) {
969
+ const key = `${namespace}:${node.key}`
970
+ const value = this.graph.node(key)
971
+ if (value) {
972
+ yield node
973
+ }
974
+ }
975
+ }
976
+
896
977
  /**
897
978
  * Lists all entities in the graph that are not part of this domain.
898
979
  */
899
- *listForeignEntities(): Generator<DomainEntity> {
980
+ *listAllForeignEntities(): Generator<DomainEntity> {
900
981
  for (const node of this.graph.nodes()) {
901
982
  const value = this.graph.node(node) as DomainGraphNodeType
902
983
  if (value.kind === DomainEntityKind && value.domain.key !== this.key) {
@@ -39,6 +39,18 @@ export abstract class DomainElement implements DomainElementSchema {
39
39
  return this.#key
40
40
  }
41
41
 
42
+ #namespace: string
43
+
44
+ /**
45
+ * The key of the DataDomain this element belongs to.
46
+ * In a data domain that has foreign namespaces, this is the key of the namespace this element originally belongs to.
47
+ *
48
+ * It might be different from the `domain.key` if the element is a foreign object.
49
+ */
50
+ get namespace(): string {
51
+ return this.#namespace
52
+ }
53
+
42
54
  /**
43
55
  * @param root The root DataDomain instance.
44
56
  * @param key The unique key of the domain element.
@@ -46,5 +58,9 @@ export abstract class DomainElement implements DomainElementSchema {
46
58
  constructor(root: DataDomain, key: string) {
47
59
  this.root = root
48
60
  this.#key = key
61
+ // When dependencies are loaded, they all first belong to the root domain.
62
+ // When the foreign domain is merged, the object is transferred to the other domain,
63
+ // but the namespace is still the root domain key.
64
+ this.#namespace = root.key
49
65
  }
50
66
  }
@@ -225,7 +225,7 @@ export class EntityValidation {
225
225
  })
226
226
  }
227
227
  }
228
- for (const other of this.domain.listForeignEntities()) {
228
+ for (const other of this.domain.listAllForeignEntities()) {
229
229
  if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {
230
230
  const message = `The "${name}" entity name is already used in the foreign data domain.`
231
231
  const help = `The name must be unique. This includes references to other data domains.`
@@ -288,7 +288,7 @@ export class DataCatalogSdk extends SdkBase {
288
288
  async listDependencies(
289
289
  dependencies?: ForeignDomainDependency[],
290
290
  request: SdkOptions = {}
291
- ): Promise<ContextListResult<DataDomainSchema[]>> {
291
+ ): Promise<ContextListResult<DataDomainSchema>> {
292
292
  const { token } = request
293
293
  const url = this.sdk.getUrl(RouteBuilder.dataCatalogDependencies())
294
294
  const body = JSON.stringify({ items: dependencies })
@@ -308,7 +308,7 @@ export class DataCatalogSdk extends SdkBase {
308
308
  if (!result.body) {
309
309
  throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
310
310
  }
311
- let data: ContextListResult<DataDomainSchema[]>
311
+ let data: ContextListResult<DataDomainSchema>
312
312
  try {
313
313
  data = JSON.parse(result.body)
314
314
  } catch {
@@ -1,5 +1,6 @@
1
1
  import { test } from '@japa/runner'
2
2
  import { DataDomain } from '../../../src/modeling/DataDomain.js'
3
+ import type { DomainEntity } from '../../../src/modeling/DomainEntity.js'
3
4
 
4
5
  test.group('DataDomain.registerForeignDomain()', () => {
5
6
  test('registers a foreign domain', ({ assert }) => {
@@ -424,6 +425,180 @@ test.group('DataDomain.findEntity()', () => {
424
425
  })
425
426
  })
426
427
 
428
+ test.group('DataDomain.listForeignNamespaces()', () => {
429
+ test('lists all namespaces from a registered foreign domain', ({ assert }) => {
430
+ const localDomain = new DataDomain()
431
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
432
+ foreignDomain.info.version = '1.0.0'
433
+
434
+ const ns1Foreign = foreignDomain.addNamespace({ key: 'ns1' })
435
+ const ns2Foreign = foreignDomain.addNamespace({ key: 'ns2' })
436
+
437
+ localDomain.registerForeignDomain(foreignDomain)
438
+
439
+ const namespaces = [...localDomain.listForeignNamespaces(foreignDomain.key)]
440
+ assert.lengthOf(namespaces, 2)
441
+ assert.deepInclude(namespaces, ns1Foreign)
442
+ assert.deepInclude(namespaces, ns2Foreign)
443
+ })
444
+
445
+ test('returns an empty generator if the foreign domain has no namespaces', ({ assert }) => {
446
+ const localDomain = new DataDomain()
447
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
448
+ foreignDomain.info.version = '1.0.0'
449
+ localDomain.registerForeignDomain(foreignDomain)
450
+
451
+ const namespaces = [...localDomain.listForeignNamespaces(foreignDomain.key)]
452
+ assert.lengthOf(namespaces, 0)
453
+ })
454
+
455
+ test('returns an empty generator if foreign namespaces are not in the local graph', ({ assert }) => {
456
+ const localDomain = new DataDomain()
457
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
458
+ foreignDomain.info.version = '1.0.0'
459
+ foreignDomain.addNamespace({ key: 'ns1' })
460
+ localDomain.registerForeignDomain(foreignDomain)
461
+
462
+ // Simulate that the foreign namespaces are not in the local graph
463
+ localDomain.graph.removeNode(`${foreignDomain.key}:ns1`)
464
+
465
+ const namespacesAfterRemoval = [...localDomain.listForeignNamespaces(foreignDomain.key)]
466
+ assert.lengthOf(namespacesAfterRemoval, 0)
467
+ })
468
+
469
+ test('throws an error if the foreign domain key is not registered', ({ assert }) => {
470
+ const localDomain = new DataDomain()
471
+ assert.throws(
472
+ () => [...localDomain.listForeignNamespaces('nonExistentKey')],
473
+ 'Foreign domain nonExistentKey not found'
474
+ )
475
+ })
476
+ })
477
+
478
+ test.group('DataDomain.listForeignModels()', () => {
479
+ test('lists all models from a registered foreign domain', ({ assert }) => {
480
+ const localDomain = new DataDomain()
481
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
482
+ foreignDomain.info.version = '1.0.0'
483
+
484
+ const model1Foreign = foreignDomain.addModel({ key: 'model1' })
485
+ const model2Foreign = foreignDomain.addModel({ key: 'model2' })
486
+
487
+ localDomain.registerForeignDomain(foreignDomain)
488
+
489
+ // Ensure the foreign nodes are in the local graph (simulating mergeGraph)
490
+ localDomain.graph.setNode(`${foreignDomain.key}:${model1Foreign.key}`, model1Foreign)
491
+ localDomain.graph.setNode(`${foreignDomain.key}:${model2Foreign.key}`, model2Foreign)
492
+
493
+ const models = [...localDomain.listForeignModels(foreignDomain.key)]
494
+ assert.lengthOf(models, 2)
495
+ assert.deepInclude(models, model1Foreign)
496
+ assert.deepInclude(models, model2Foreign)
497
+ })
498
+
499
+ test('returns an empty generator if the foreign domain has no models', ({ assert }) => {
500
+ const localDomain = new DataDomain()
501
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
502
+ foreignDomain.info.version = '1.0.0'
503
+ localDomain.registerForeignDomain(foreignDomain)
504
+
505
+ const models = [...localDomain.listForeignModels(foreignDomain.key)]
506
+ assert.lengthOf(models, 0)
507
+ })
508
+
509
+ test('returns an empty generator if foreign models are not in the local graph', ({ assert }) => {
510
+ const localDomain = new DataDomain()
511
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
512
+ foreignDomain.info.version = '1.0.0'
513
+ foreignDomain.addModel({ key: 'model1' })
514
+ localDomain.registerForeignDomain(foreignDomain)
515
+
516
+ // Simulate that the foreign models are not in the local graph
517
+ localDomain.graph.removeNode(`${foreignDomain.key}:model1`)
518
+
519
+ const modelsAfterRemoval = [...localDomain.listForeignModels(foreignDomain.key)]
520
+ assert.lengthOf(modelsAfterRemoval, 0)
521
+ })
522
+
523
+ test('throws an error if the foreign domain key is not registered', ({ assert }) => {
524
+ const localDomain = new DataDomain()
525
+ assert.throws(() => [...localDomain.listForeignModels('nonExistentKey')], 'Foreign domain nonExistentKey not found')
526
+ })
527
+ })
528
+
529
+ test.group('DataDomain.listForeignEntities()', () => {
530
+ test('lists all entities from a registered foreign domain', ({ assert }) => {
531
+ const localDomain = new DataDomain()
532
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
533
+ foreignDomain.info.version = '1.0.0'
534
+
535
+ const modelForeign = foreignDomain.addModel({ key: 'modelF' })
536
+ const entity1Foreign = foreignDomain.addEntity(modelForeign.key, { key: 'entity1' })
537
+ const entity2Foreign = foreignDomain.addEntity(modelForeign.key, { key: 'entity2' })
538
+
539
+ localDomain.registerForeignDomain(foreignDomain)
540
+
541
+ // Ensure the foreign nodes are in the local graph (simulating mergeGraph)
542
+ localDomain.graph.setNode(`${foreignDomain.key}:${entity1Foreign.key}`, entity1Foreign)
543
+ localDomain.graph.setNode(`${foreignDomain.key}:${entity2Foreign.key}`, entity2Foreign)
544
+
545
+ const entities = [...localDomain.listForeignEntities(foreignDomain.key)]
546
+ assert.lengthOf(entities, 2)
547
+ assert.deepInclude(entities, entity1Foreign)
548
+ assert.deepInclude(entities, entity2Foreign)
549
+ })
550
+
551
+ test('returns an empty generator if the foreign domain has no entities', ({ assert }) => {
552
+ const localDomain = new DataDomain()
553
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
554
+ foreignDomain.info.version = '1.0.0'
555
+ localDomain.registerForeignDomain(foreignDomain)
556
+
557
+ const entities = [...localDomain.listForeignEntities(foreignDomain.key)]
558
+ assert.lengthOf(entities, 0)
559
+ })
560
+
561
+ test('returns an empty generator if foreign entities are not in the local graph', ({ assert }) => {
562
+ const localDomain = new DataDomain()
563
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
564
+ foreignDomain.info.version = '1.0.0'
565
+ const modelForeign = foreignDomain.addModel({ key: 'modelF' })
566
+ foreignDomain.addEntity(modelForeign.key, { key: 'entity1' })
567
+ localDomain.registerForeignDomain(foreignDomain)
568
+
569
+ // Simulate that the foreign entities are not in the local graph
570
+ localDomain.graph.removeNode(`${foreignDomain.key}:entity1`)
571
+
572
+ const entitiesAfterRemoval = [...localDomain.listForeignEntities(foreignDomain.key)]
573
+ assert.lengthOf(entitiesAfterRemoval, 0)
574
+ })
575
+
576
+ test('throws an error if the foreign domain key is not registered', ({ assert }) => {
577
+ const localDomain = new DataDomain()
578
+ assert.throws(
579
+ () => [...localDomain.listForeignEntities('nonExistentKey')],
580
+ 'Foreign domain nonExistentKey not found'
581
+ )
582
+ })
583
+
584
+ test('lists entities from a foreign domain even if local domain has entities', ({ assert }) => {
585
+ const localDomain = new DataDomain()
586
+ const modelLocal = localDomain.addModel({ key: 'modelL' })
587
+ localDomain.addEntity(modelLocal.key, { key: 'entityL' })
588
+
589
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
590
+ foreignDomain.info.version = '1.0.0'
591
+ const modelForeign = foreignDomain.addModel({ key: 'modelF' })
592
+ const entityForeign = foreignDomain.addEntity(modelForeign.key, { key: 'entityF' })
593
+ localDomain.registerForeignDomain(foreignDomain)
594
+
595
+ const entities = [...localDomain.listForeignEntities(foreignDomain.key)]
596
+ assert.lengthOf(entities, 1)
597
+ assert.deepInclude(entities, entityForeign)
598
+ assert.notDeepInclude(entities, localDomain.findEntity('entityL') as DomainEntity)
599
+ })
600
+ })
601
+
427
602
  test.group('DataDomain.findAssociation()', () => {
428
603
  test('finds a foreign association by its key and domain key', ({ assert }) => {
429
604
  const domain = new DataDomain()
@@ -486,3 +661,72 @@ test.group('DataDomain.findProperty()', () => {
486
661
  }, `Foreign domain non-existent-domain not found`)
487
662
  })
488
663
  })
664
+
665
+ test.group('DataDomain foreign elements namespace property', () => {
666
+ test('DomainNamespace retains its original namespace key after foreign registration', ({ assert }) => {
667
+ const localDomain = new DataDomain({ key: 'localKey' })
668
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
669
+ foreignDomain.addNamespace({ key: 'nsInForeign' })
670
+ foreignDomain.info.version = '1.0.0'
671
+ localDomain.registerForeignDomain(foreignDomain)
672
+
673
+ const retrievedNs = localDomain.findNamespace('nsInForeign', 'foreignKey')
674
+ assert.ok(retrievedNs, 'Foreign namespace should be found in local domain')
675
+ assert.equal(retrievedNs!.namespace, 'foreignKey', 'Namespace property should point to foreign domain key')
676
+ assert.equal(retrievedNs!.domain.key, 'foreignKey', 'Domain property should point to local domain key')
677
+ })
678
+
679
+ test('DomainModel retains its original namespace key after foreign registration', ({ assert }) => {
680
+ const localDomain = new DataDomain({ key: 'localKey' })
681
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
682
+ foreignDomain.info.version = '1.0.0'
683
+
684
+ foreignDomain.addModel({ key: 'modelInForeign' })
685
+ localDomain.registerForeignDomain(foreignDomain)
686
+
687
+ const retrievedModel = localDomain.findModel('modelInForeign', 'foreignKey')
688
+ assert.ok(retrievedModel, 'Foreign model should be found in local domain')
689
+ assert.equal(retrievedModel!.namespace, 'foreignKey', 'Namespace property should point to foreign domain key')
690
+ assert.equal(retrievedModel!.domain.key, 'foreignKey', 'Domain property should point to local domain key')
691
+ })
692
+
693
+ test('DomainEntity retains its original namespace key after foreign registration', ({ assert }) => {
694
+ const localDomain = new DataDomain({ key: 'localKey' })
695
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
696
+ foreignDomain.info.version = '1.0.0'
697
+
698
+ const parentForeignModel = foreignDomain.addModel({ key: 'parentModelInForeign' })
699
+ foreignDomain.addEntity(parentForeignModel.key, { key: 'entityInForeign' })
700
+ localDomain.registerForeignDomain(foreignDomain)
701
+
702
+ const retrievedEntity = localDomain.findEntity('entityInForeign', 'foreignKey')
703
+ assert.ok(retrievedEntity, 'Foreign entity should be found in local domain')
704
+ assert.equal(retrievedEntity!.namespace, 'foreignKey', 'Namespace property should point to foreign domain key')
705
+ assert.equal(retrievedEntity!.domain.key, 'foreignKey', 'Domain property should point to local domain key')
706
+ })
707
+
708
+ test('DomainProperty retains its original namespace key after foreign registration', ({ assert }) => {
709
+ const localDomain = new DataDomain({ key: 'localKey' })
710
+ const foreignDomain = new DataDomain({ key: 'foreignKey' })
711
+ foreignDomain.info.version = '1.0.0'
712
+
713
+ const parentForeignModel = foreignDomain.addModel({ key: 'parentModelInForeign' })
714
+ const parentForeignEntity = foreignDomain.addEntity(parentForeignModel.key, { key: 'parentEntityInForeign' })
715
+ foreignDomain.addProperty(parentForeignEntity.key, { key: 'propertyInForeign' })
716
+ localDomain.registerForeignDomain(foreignDomain)
717
+
718
+ const retrievedProperty = localDomain.findProperty('propertyInForeign', 'foreignKey')
719
+ assert.ok(retrievedProperty, 'Foreign property should be found in local domain')
720
+ assert.equal(retrievedProperty!.namespace, 'foreignKey', 'Namespace property should point to foreign domain key')
721
+ assert.equal(retrievedProperty!.domain.key, 'foreignKey', 'Domain property should point to local domain key')
722
+ })
723
+
724
+ test('DomainElement.namespace is the key of the domain it was created in', ({ assert }) => {
725
+ const domain = new DataDomain({ key: 'originalDomainKey' })
726
+ const model = domain.addModel({ key: 'myModel' })
727
+ const entity = model.addEntity({ key: 'myEntity' })
728
+
729
+ assert.equal(model.namespace, 'originalDomainKey')
730
+ assert.equal(entity.namespace, 'originalDomainKey')
731
+ })
732
+ })