@api-client/core 0.14.7 → 0.14.8

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,13 +42062,10 @@
42062
42062
  "@id": "#209"
42063
42063
  },
42064
42064
  {
42065
- "@id": "#191"
42066
- },
42067
- {
42068
42065
  "@id": "#194"
42069
42066
  },
42070
42067
  {
42071
- "@id": "#203"
42068
+ "@id": "#191"
42072
42069
  },
42073
42070
  {
42074
42071
  "@id": "#197"
@@ -42077,6 +42074,9 @@
42077
42074
  "@id": "#200"
42078
42075
  },
42079
42076
  {
42077
+ "@id": "#203"
42078
+ },
42079
+ {
42080
42080
  "@id": "#206"
42081
42081
  },
42082
42082
  {
@@ -42810,16 +42810,16 @@
42810
42810
  "@id": "#219"
42811
42811
  },
42812
42812
  {
42813
- "@id": "#210"
42813
+ "@id": "#219"
42814
42814
  },
42815
42815
  {
42816
- "@id": "#213"
42816
+ "@id": "#210"
42817
42817
  },
42818
42818
  {
42819
42819
  "@id": "#216"
42820
42820
  },
42821
42821
  {
42822
- "@id": "#219"
42822
+ "@id": "#213"
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": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
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",
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": "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",
43460
+ "doc:raw": "countryCode: \"BE\"\ngraydonEnterpriseId: 1057155523\nregistrationId: \"0422319093\"\nvatNumber: \"BE0422319093\"\ngraydonCompanyId: \"0422319093\"\nisBranchOffice: false\n",
43461
43461
  "core:mediaType": "application/yaml",
43462
43462
  "sourcemaps:sources": [
43463
43463
  {
@@ -43478,7 +43478,7 @@
43478
43478
  "doc:ExternalDomainElement",
43479
43479
  "doc:DomainElement"
43480
43480
  ],
43481
- "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43481
+ "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43482
43482
  "core:mediaType": "application/yaml",
43483
43483
  "sourcemaps:sources": [
43484
43484
  {
@@ -43499,7 +43499,7 @@
43499
43499
  "doc:ExternalDomainElement",
43500
43500
  "doc:DomainElement"
43501
43501
  ],
43502
- "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43502
+ "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43503
43503
  "core:mediaType": "application/yaml",
43504
43504
  "sourcemaps:sources": [
43505
43505
  {
@@ -43520,7 +43520,7 @@
43520
43520
  "doc:ExternalDomainElement",
43521
43521
  "doc:DomainElement"
43522
43522
  ],
43523
- "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43523
+ "doc:raw": "code: 'J'\ndescription: 'Information and communication'\n",
43524
43524
  "core:mediaType": "application/yaml",
43525
43525
  "sourcemaps:sources": [
43526
43526
  {
@@ -44232,7 +44232,7 @@
44232
44232
  "doc:ExternalDomainElement",
44233
44233
  "doc:DomainElement"
44234
44234
  ],
44235
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44235
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\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'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44256
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\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\"\nvalue: \"www.company.be\"\n",
44298
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
44299
44299
  "core:mediaType": "application/yaml",
44300
44300
  "sourcemaps:sources": [
44301
44301
  {
@@ -44756,22 +44756,22 @@
44756
44756
  {
44757
44757
  "@id": "#193/source-map/lexical/element_0",
44758
44758
  "sourcemaps:element": "amf://id#193",
44759
- "sourcemaps:value": "[(1,0)-(7,0)]"
44759
+ "sourcemaps:value": "[(1,0)-(10,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)-(10,0)]"
44764
+ "sourcemaps:value": "[(1,0)-(7,0)]"
44765
44765
  },
44766
44766
  {
44767
44767
  "@id": "#199/source-map/lexical/element_0",
44768
44768
  "sourcemaps:element": "amf://id#199",
44769
- "sourcemaps:value": "[(1,0)-(5,0)]"
44769
+ "sourcemaps:value": "[(1,0)-(3,0)]"
44770
44770
  },
44771
44771
  {
44772
44772
  "@id": "#202/source-map/lexical/element_0",
44773
44773
  "sourcemaps:element": "amf://id#202",
44774
- "sourcemaps:value": "[(1,0)-(3,0)]"
44774
+ "sourcemaps:value": "[(1,0)-(5,0)]"
44775
44775
  },
44776
44776
  {
44777
44777
  "@id": "#205/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)-(6,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(3,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)-(3,0)]"
45134
+ "sourcemaps:value": "[(1,0)-(6,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.7",
4
+ "version": "0.14.8",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -431,10 +431,41 @@ export class DataDomain extends DependentModel {
431
431
  }
432
432
  }
433
433
 
434
+ /**
435
+ * Builds a reference key for a domain object.
436
+ *
437
+ * If the namespace is provided and it is different from the domain key,
438
+ * it will return the key in the format `namespace:key`. The foreign namespace
439
+ * must be registered in the domain's dependencies otherwise an error will be thrown.
440
+ *
441
+ * @param key The key of the namespace or model.
442
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
443
+ * @returns The reference key in the format `namespace:key` or just `key` if no namespace is provided.
444
+ * @throws Error When the foreign domain is not found.
445
+ * @example
446
+ * ```typescript
447
+ * const refKey = dataDomain.buildReferenceKey('userModel', 'domainKey');
448
+ * ```
449
+ */
450
+ buildReferenceKey(key: string, namespace?: string): string {
451
+ if (namespace && namespace !== this.key) {
452
+ if (typeof namespace !== 'string' || namespace.length === 0) {
453
+ throw new Error(`Invalid namespace key. Expected a string, got ${typeof namespace}`)
454
+ }
455
+ const foreignDomain = this.dependencies.get(namespace)
456
+ if (!foreignDomain) {
457
+ throw new Error(`Foreign domain ${namespace} not found`)
458
+ }
459
+ return `${namespace}:${key}`
460
+ }
461
+ return key
462
+ }
463
+
434
464
  /**
435
465
  * Finds a namespace by its key.
436
466
  *
437
467
  * @param key The key of the namespace to find.
468
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
438
469
  * @returns The namespace instance or undefined if not
439
470
  * found.
440
471
  * @example
@@ -445,8 +476,8 @@ export class DataDomain extends DependentModel {
445
476
  * }
446
477
  * ```
447
478
  */
448
- findNamespace(key: string): DomainNamespace | undefined {
449
- const result = this.graph.node(key) as DomainNamespace | undefined
479
+ findNamespace(key: string, namespace?: string): DomainNamespace | undefined {
480
+ const result = this.graph.node(this.buildReferenceKey(key, namespace)) as DomainNamespace | undefined
450
481
  if (result && result.kind === DomainNamespaceKind) {
451
482
  return result
452
483
  }
@@ -689,6 +720,7 @@ export class DataDomain extends DependentModel {
689
720
  * Finds a data model by its key.
690
721
  *
691
722
  * @param key The key of the data model to find.
723
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
692
724
  * @returns The data model instance or undefined if not
693
725
  * found.
694
726
  * @example
@@ -699,8 +731,8 @@ export class DataDomain extends DependentModel {
699
731
  * }
700
732
  * ```
701
733
  */
702
- findModel(key: string): DomainModel | undefined {
703
- const value = this.graph.node(key) as DomainModel | undefined
734
+ findModel(key: string, namespace?: string): DomainModel | undefined {
735
+ const value = this.graph.node(this.buildReferenceKey(key, namespace)) as DomainModel | undefined
704
736
  if (value && value.kind === DomainModelKind) {
705
737
  return value
706
738
  }
@@ -877,6 +909,7 @@ export class DataDomain extends DependentModel {
877
909
  * Finds an entity by its key.
878
910
  *
879
911
  * @param key The key of the entity to find.
912
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
880
913
  * @returns The entity instance or undefined if not found.
881
914
  * @example
882
915
  * ```typescript
@@ -886,8 +919,8 @@ export class DataDomain extends DependentModel {
886
919
  * }
887
920
  * ```
888
921
  */
889
- findEntity(key: string): DomainEntity | undefined {
890
- const node = this.graph.node(key) as DomainEntity | undefined
922
+ findEntity(key: string, namespace?: string): DomainEntity | undefined {
923
+ const node = this.graph.node(this.buildReferenceKey(key, namespace)) as DomainEntity | undefined
891
924
  if (node && node.kind === DomainEntityKind) {
892
925
  return node
893
926
  }
@@ -1005,6 +1038,7 @@ export class DataDomain extends DependentModel {
1005
1038
  * Finds an association by its key.
1006
1039
  *
1007
1040
  * @param key The key of the association to find.
1041
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign association
1008
1042
  * @returns The association instance or undefined if not
1009
1043
  * found.
1010
1044
  * @example
@@ -1015,8 +1049,8 @@ export class DataDomain extends DependentModel {
1015
1049
  * }
1016
1050
  * ```
1017
1051
  */
1018
- findAssociation(key: string): DomainAssociation | undefined {
1019
- const node = this.graph.node(key) as DomainAssociation | undefined
1052
+ findAssociation(key: string, namespace?: string): DomainAssociation | undefined {
1053
+ const node = this.graph.node(this.buildReferenceKey(key, namespace)) as DomainAssociation | undefined
1020
1054
  if (node && node.kind === DomainAssociationKind) {
1021
1055
  return node
1022
1056
  }
@@ -1090,6 +1124,7 @@ export class DataDomain extends DependentModel {
1090
1124
  * Finds a property by its key.
1091
1125
  *
1092
1126
  * @param key The key of the property to find.
1127
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign property
1093
1128
  * @returns The property instance or undefined if not
1094
1129
  * found.
1095
1130
  * @example
@@ -1100,8 +1135,8 @@ export class DataDomain extends DependentModel {
1100
1135
  * }
1101
1136
  * ```
1102
1137
  */
1103
- findProperty(key: string): DomainProperty | undefined {
1104
- const node = this.graph.node(key) as DomainProperty | undefined
1138
+ findProperty(key: string, namespace?: string): DomainProperty | undefined {
1139
+ const node = this.graph.node(this.buildReferenceKey(key, namespace)) as DomainProperty | undefined
1105
1140
  if (node && node.kind === DomainPropertyKind) {
1106
1141
  return node
1107
1142
  }
@@ -1175,6 +1210,8 @@ export class DataDomain extends DependentModel {
1175
1210
  * console.log(foreignUser.key);
1176
1211
  * }
1177
1212
  * ```
1213
+ * @deprecated Use `findEntity` with the `namespace` parameter instead.
1214
+ * This method is kept for backward compatibility but will be removed in the future.
1178
1215
  */
1179
1216
  findForeignEntity(entityKey: string, domainKey: string): DomainEntity | undefined {
1180
1217
  const foreignDomain = this.dependencies.get(domainKey)
@@ -142,7 +142,66 @@ test.group('DataDomain.registerForeignDomain()', () => {
142
142
  })
143
143
  })
144
144
 
145
- test.group('DataDomain.findForeignEntity()', () => {
145
+ test.group('DataDomain.findNamespace()', () => {
146
+ test('finds a foreign namespace by its key and domain key', ({ assert }) => {
147
+ const domain = new DataDomain()
148
+ const fd = new DataDomain()
149
+ const ns = fd.addNamespace({ key: 'test-namespace' })
150
+ fd.info.version = '1.0.0'
151
+ domain.registerForeignDomain(fd)
152
+ const result = domain.findNamespace('test-namespace', fd.key)
153
+ assert.deepEqual(result, ns)
154
+ })
155
+
156
+ test('returns undefined when namespace not found', ({ assert }) => {
157
+ const domain = new DataDomain()
158
+ const fd = new DataDomain()
159
+ fd.info.version = '1.0.0'
160
+ domain.registerForeignDomain(fd)
161
+ const result = domain.findNamespace('other-namespace', fd.key)
162
+ assert.isUndefined(result)
163
+ })
164
+
165
+ test("throws when namespace's namespace not found", ({ assert }) => {
166
+ const domain = new DataDomain()
167
+ domain.addNamespace({ key: 'test-namespace' })
168
+ assert.throws(() => {
169
+ domain.findNamespace('test-namespace', 'non-existent-domain')
170
+ }, `Foreign domain non-existent-domain not found`)
171
+ })
172
+ })
173
+
174
+ test.group('DataDomain.findModel()', () => {
175
+ test('finds a foreign model by its key and domain key', ({ assert }) => {
176
+ const domain = new DataDomain()
177
+ const fd = new DataDomain()
178
+ const ns = fd.addNamespace({ key: 'test-namespace' })
179
+ const model = ns.addModel({ key: 'test-model' })
180
+ fd.info.version = '1.0.0'
181
+ domain.registerForeignDomain(fd)
182
+ const result = domain.findModel('test-model', fd.key)
183
+ assert.deepEqual(result, model)
184
+ })
185
+
186
+ test('returns undefined when model not found', ({ assert }) => {
187
+ const domain = new DataDomain()
188
+ const fd = new DataDomain()
189
+ fd.info.version = '1.0.0'
190
+ domain.registerForeignDomain(fd)
191
+ const result = domain.findModel('other-model', fd.key)
192
+ assert.isUndefined(result)
193
+ })
194
+
195
+ test("throws when model's namespace not found", ({ assert }) => {
196
+ const domain = new DataDomain()
197
+ domain.addNamespace({ key: 'test-namespace' })
198
+ assert.throws(() => {
199
+ domain.findModel('test-model', 'non-existent-domain')
200
+ }, `Foreign domain non-existent-domain not found`)
201
+ })
202
+ })
203
+
204
+ test.group('DataDomain.findEntity()', () => {
146
205
  test('finds a foreign entity by its key and domain key', ({ assert }) => {
147
206
  const dataDomain = new DataDomain()
148
207
  const foreignDomain = new DataDomain()
@@ -150,14 +209,16 @@ test.group('DataDomain.findForeignEntity()', () => {
150
209
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
151
210
  foreignDomain.info.version = '1.0.0'
152
211
  dataDomain.registerForeignDomain(foreignDomain)
153
- const foundEntity = dataDomain.findForeignEntity('test-entity', foreignDomain.key)
212
+ const foundEntity = dataDomain.findEntity('test-entity', foreignDomain.key)
154
213
  assert.deepEqual(foundEntity, entity)
155
214
  })
156
215
 
157
- test('returns undefined if the foreign domain does not exist', ({ assert }) => {
216
+ test('throws when the foreign domain does not exist', ({ assert }) => {
158
217
  const dataDomain = new DataDomain()
159
- const foundEntity = dataDomain.findForeignEntity('test-entity', 'non-existent-domain')
160
- assert.isUndefined(foundEntity)
218
+ assert.throws(
219
+ () => dataDomain.findEntity('test-entity', 'non-existent-domain'),
220
+ `Foreign domain non-existent-domain not found`
221
+ )
161
222
  })
162
223
 
163
224
  test('returns undefined if the entity does not exist in the foreign domain', ({ assert }) => {
@@ -165,7 +226,7 @@ test.group('DataDomain.findForeignEntity()', () => {
165
226
  const foreignDomain = new DataDomain()
166
227
  foreignDomain.info.version = '1.0.0'
167
228
  dataDomain.registerForeignDomain(foreignDomain)
168
- const foundEntity = dataDomain.findForeignEntity('non-existent-entity', foreignDomain.key)
229
+ const foundEntity = dataDomain.findEntity('non-existent-entity', foreignDomain.key)
169
230
  assert.isUndefined(foundEntity)
170
231
  })
171
232
 
@@ -175,7 +236,7 @@ test.group('DataDomain.findForeignEntity()', () => {
175
236
  const model = foreignDomain.addModel({ key: 'test-model' })
176
237
  foreignDomain.info.version = '1.0.0'
177
238
  dataDomain.registerForeignDomain(foreignDomain)
178
- const foundEntity = dataDomain.findForeignEntity(model.key, foreignDomain.key)
239
+ const foundEntity = dataDomain.findEntity(model.key, foreignDomain.key)
179
240
  assert.isUndefined(foundEntity)
180
241
  })
181
242
 
@@ -185,7 +246,7 @@ test.group('DataDomain.findForeignEntity()', () => {
185
246
  foreignDomain.info.version = '1.0.0'
186
247
  dataDomain.registerForeignDomain(foreignDomain)
187
248
  // @ts-expect-error For testing purposes
188
- const foundEntity = dataDomain.findForeignEntity(undefined, foreignDomain.key)
249
+ const foundEntity = dataDomain.findEntity(undefined, foreignDomain.key)
189
250
  assert.isUndefined(foundEntity)
190
251
  })
191
252
 
@@ -195,7 +256,7 @@ test.group('DataDomain.findForeignEntity()', () => {
195
256
  foreignDomain.info.version = '1.0.0'
196
257
  dataDomain.registerForeignDomain(foreignDomain)
197
258
  // @ts-expect-error For testing purposes
198
- const foundEntity = dataDomain.findForeignEntity(null, foreignDomain.key)
259
+ const foundEntity = dataDomain.findEntity(null, foreignDomain.key)
199
260
  assert.isUndefined(foundEntity)
200
261
  })
201
262
 
@@ -204,7 +265,7 @@ test.group('DataDomain.findForeignEntity()', () => {
204
265
  const foreignDomain = new DataDomain()
205
266
  foreignDomain.info.version = '1.0.0'
206
267
  dataDomain.registerForeignDomain(foreignDomain)
207
- const foundEntity = dataDomain.findForeignEntity('', foreignDomain.key)
268
+ const foundEntity = dataDomain.findEntity('', foreignDomain.key)
208
269
  assert.isUndefined(foundEntity)
209
270
  })
210
271
 
@@ -214,7 +275,7 @@ test.group('DataDomain.findForeignEntity()', () => {
214
275
  foreignDomain.info.version = '1.0.0'
215
276
  dataDomain.registerForeignDomain(foreignDomain)
216
277
  // @ts-expect-error For testing purposes
217
- const foundEntity = dataDomain.findForeignEntity(123, foreignDomain.key)
278
+ const foundEntity = dataDomain.findEntity(123, foreignDomain.key)
218
279
  assert.isUndefined(foundEntity)
219
280
  })
220
281
 
@@ -224,7 +285,7 @@ test.group('DataDomain.findForeignEntity()', () => {
224
285
  foreignDomain.info.version = '1.0.0'
225
286
  dataDomain.registerForeignDomain(foreignDomain)
226
287
  // @ts-expect-error For testing purposes
227
- const foundEntity = dataDomain.findForeignEntity(true, foreignDomain.key)
288
+ const foundEntity = dataDomain.findEntity(true, foreignDomain.key)
228
289
  assert.isUndefined(foundEntity)
229
290
  })
230
291
 
@@ -234,7 +295,7 @@ test.group('DataDomain.findForeignEntity()', () => {
234
295
  foreignDomain.info.version = '1.0.0'
235
296
  dataDomain.registerForeignDomain(foreignDomain)
236
297
  // @ts-expect-error For testing purposes
237
- const foundEntity = dataDomain.findForeignEntity({}, foreignDomain.key)
298
+ const foundEntity = dataDomain.findEntity({}, foreignDomain.key)
238
299
  assert.isUndefined(foundEntity)
239
300
  })
240
301
 
@@ -244,7 +305,7 @@ test.group('DataDomain.findForeignEntity()', () => {
244
305
  foreignDomain.info.version = '1.0.0'
245
306
  dataDomain.registerForeignDomain(foreignDomain)
246
307
  // @ts-expect-error For testing purposes
247
- const foundEntity = dataDomain.findForeignEntity([], foreignDomain.key)
308
+ const foundEntity = dataDomain.findEntity([], foreignDomain.key)
248
309
  assert.isUndefined(foundEntity)
249
310
  })
250
311
 
@@ -254,7 +315,7 @@ test.group('DataDomain.findForeignEntity()', () => {
254
315
  foreignDomain.info.version = '1.0.0'
255
316
  dataDomain.registerForeignDomain(foreignDomain)
256
317
  // @ts-expect-error For testing purposes
257
- const foundEntity = dataDomain.findForeignEntity(() => {}, foreignDomain.key)
318
+ const foundEntity = dataDomain.findEntity(() => {}, foreignDomain.key)
258
319
  assert.isUndefined(foundEntity)
259
320
  })
260
321
 
@@ -265,8 +326,7 @@ test.group('DataDomain.findForeignEntity()', () => {
265
326
  const model = foreignDomain.addModel({ key: 'test-model' })
266
327
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
267
328
  dataDomain.registerForeignDomain(foreignDomain)
268
- // @ts-expect-error For testing purposes
269
- const foundEntity = dataDomain.findForeignEntity(entity.key, undefined)
329
+ const foundEntity = dataDomain.findEntity(entity.key, undefined)
270
330
  assert.isUndefined(foundEntity)
271
331
  })
272
332
 
@@ -278,7 +338,7 @@ test.group('DataDomain.findForeignEntity()', () => {
278
338
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
279
339
  dataDomain.registerForeignDomain(foreignDomain)
280
340
  // @ts-expect-error For testing purposes
281
- const foundEntity = dataDomain.findForeignEntity(entity.key, null)
341
+ const foundEntity = dataDomain.findEntity(entity.key, null)
282
342
  assert.isUndefined(foundEntity)
283
343
  })
284
344
 
@@ -289,67 +349,140 @@ test.group('DataDomain.findForeignEntity()', () => {
289
349
  const model = foreignDomain.addModel({ key: 'test-model' })
290
350
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
291
351
  dataDomain.registerForeignDomain(foreignDomain)
292
- const foundEntity = dataDomain.findForeignEntity(entity.key, '')
352
+ const foundEntity = dataDomain.findEntity(entity.key, '')
293
353
  assert.isUndefined(foundEntity)
294
354
  })
295
355
 
296
- test('returns undefined if domainKey is a number', ({ assert }) => {
356
+ test('throws when domainKey is a number', ({ assert }) => {
297
357
  const dataDomain = new DataDomain()
298
358
  const foreignDomain = new DataDomain()
299
359
  foreignDomain.info.version = '1.0.0'
300
360
  const model = foreignDomain.addModel({ key: 'test-model' })
301
361
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
302
362
  dataDomain.registerForeignDomain(foreignDomain)
303
- // @ts-expect-error For testing purposes
304
- const foundEntity = dataDomain.findForeignEntity(entity.key, 123)
305
- assert.isUndefined(foundEntity)
363
+ assert.throws(
364
+ // @ts-expect-error For testing purposes
365
+ () => dataDomain.findEntity(entity.key, 123),
366
+ `Invalid namespace key. Expected a string, got number`
367
+ )
306
368
  })
307
369
 
308
- test('returns undefined if domainKey is a boolean', ({ assert }) => {
370
+ test('throws when domainKey is a boolean', ({ assert }) => {
309
371
  const dataDomain = new DataDomain()
310
372
  const foreignDomain = new DataDomain()
311
373
  foreignDomain.info.version = '1.0.0'
312
374
  const model = foreignDomain.addModel({ key: 'test-model' })
313
375
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
314
376
  dataDomain.registerForeignDomain(foreignDomain)
315
- // @ts-expect-error For testing purposes
316
- const foundEntity = dataDomain.findForeignEntity(entity.key, true)
317
- assert.isUndefined(foundEntity)
377
+ assert.throws(
378
+ // @ts-expect-error For testing purposes
379
+ () => dataDomain.findEntity(entity.key, true),
380
+ `Invalid namespace key. Expected a string, got boolean`
381
+ )
318
382
  })
319
383
 
320
- test('returns undefined if domainKey is an object', ({ assert }) => {
384
+ test('throws when domainKey is an object', ({ assert }) => {
321
385
  const dataDomain = new DataDomain()
322
386
  const foreignDomain = new DataDomain()
323
387
  foreignDomain.info.version = '1.0.0'
324
388
  const model = foreignDomain.addModel({ key: 'test-model' })
325
389
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
326
390
  dataDomain.registerForeignDomain(foreignDomain)
327
- // @ts-expect-error For testing purposes
328
- const foundEntity = dataDomain.findForeignEntity(entity.key, {})
329
- assert.isUndefined(foundEntity)
391
+ assert.throws(
392
+ // @ts-expect-error For testing purposes
393
+ () => dataDomain.findEntity(entity.key, {}),
394
+ `Invalid namespace key. Expected a string, got object`
395
+ )
330
396
  })
331
397
 
332
- test('returns undefined if domainKey is an array', ({ assert }) => {
398
+ test('throws when domainKey is an array', ({ assert }) => {
333
399
  const dataDomain = new DataDomain()
334
400
  const foreignDomain = new DataDomain()
335
401
  foreignDomain.info.version = '1.0.0'
336
402
  const model = foreignDomain.addModel({ key: 'test-model' })
337
403
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
338
404
  dataDomain.registerForeignDomain(foreignDomain)
339
- // @ts-expect-error For testing purposes
340
- const foundEntity = dataDomain.findForeignEntity(entity.key, [])
341
- assert.isUndefined(foundEntity)
405
+ assert.throws(
406
+ // @ts-expect-error For testing purposes
407
+ () => dataDomain.findEntity(entity.key, []),
408
+ `Invalid namespace key. Expected a string, got object`
409
+ )
342
410
  })
343
411
 
344
- test('returns undefined if domainKey is a function', ({ assert }) => {
412
+ test('throws when domainKey is a function', ({ assert }) => {
345
413
  const dataDomain = new DataDomain()
346
414
  const foreignDomain = new DataDomain()
347
415
  foreignDomain.info.version = '1.0.0'
348
416
  const model = foreignDomain.addModel({ key: 'test-model' })
349
417
  const entity = foreignDomain.addEntity(model.key, { key: 'test-entity' })
350
418
  dataDomain.registerForeignDomain(foreignDomain)
351
- // @ts-expect-error For testing purposes
352
- const foundEntity = dataDomain.findForeignEntity(entity.key, () => {})
353
- assert.isUndefined(foundEntity)
419
+ assert.throws(
420
+ // @ts-expect-error For testing purposes
421
+ () => dataDomain.findEntity(entity.key, () => {}),
422
+ `Invalid namespace key. Expected a string, got function`
423
+ )
424
+ })
425
+ })
426
+
427
+ test.group('DataDomain.findAssociation()', () => {
428
+ test('finds a foreign association by its key and domain key', ({ assert }) => {
429
+ const domain = new DataDomain()
430
+ const fd = new DataDomain()
431
+ const m1 = fd.addModel()
432
+ const e1 = m1.addEntity()
433
+ const e2 = m1.addEntity()
434
+ const a1 = e1.addAssociation({ key: e2.key })
435
+ fd.info.version = '1.0.0'
436
+ domain.registerForeignDomain(fd)
437
+ const result = domain.findAssociation(a1.key, fd.key)
438
+ assert.deepEqual(result, a1)
439
+ })
440
+
441
+ test('returns undefined when association not found', ({ assert }) => {
442
+ const domain = new DataDomain()
443
+ const fd = new DataDomain()
444
+ fd.info.version = '1.0.0'
445
+ domain.registerForeignDomain(fd)
446
+ const result = domain.findAssociation('other-association', fd.key)
447
+ assert.isUndefined(result)
448
+ })
449
+
450
+ test("throws when association's namespace not found", ({ assert }) => {
451
+ const domain = new DataDomain()
452
+ domain.addNamespace({ key: 'test-namespace' })
453
+ assert.throws(() => {
454
+ domain.findAssociation('test-association', 'non-existent-domain')
455
+ }, `Foreign domain non-existent-domain not found`)
456
+ })
457
+ })
458
+
459
+ test.group('DataDomain.findProperty()', () => {
460
+ test('finds a foreign property by its key and domain key', ({ assert }) => {
461
+ const domain = new DataDomain()
462
+ const fd = new DataDomain()
463
+ const m1 = fd.addModel()
464
+ const e1 = m1.addEntity()
465
+ const p1 = e1.addProperty()
466
+ fd.info.version = '1.0.0'
467
+ domain.registerForeignDomain(fd)
468
+ const result = domain.findProperty(p1.key, fd.key)
469
+ assert.deepEqual(result, p1)
470
+ })
471
+
472
+ test('returns undefined when property not found', ({ assert }) => {
473
+ const domain = new DataDomain()
474
+ const fd = new DataDomain()
475
+ fd.info.version = '1.0.0'
476
+ domain.registerForeignDomain(fd)
477
+ const result = domain.findProperty('other-property', fd.key)
478
+ assert.isUndefined(result)
479
+ })
480
+
481
+ test("throws when property's namespace not found", ({ assert }) => {
482
+ const domain = new DataDomain()
483
+ domain.addNamespace({ key: 'test-namespace' })
484
+ assert.throws(() => {
485
+ domain.findProperty('test-property', 'non-existent-domain')
486
+ }, `Foreign domain non-existent-domain not found`)
354
487
  })
355
488
  })