@api-client/core 0.14.6 → 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.
Files changed (31) hide show
  1. package/build/src/amf/ApiSchemaValues.js.map +1 -1
  2. package/build/src/modeling/ApiModel.d.ts +27 -17
  3. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  4. package/build/src/modeling/ApiModel.js +69 -20
  5. package/build/src/modeling/ApiModel.js.map +1 -1
  6. package/build/src/modeling/DataDomain.d.ts +34 -20
  7. package/build/src/modeling/DataDomain.d.ts.map +1 -1
  8. package/build/src/modeling/DataDomain.js +64 -24
  9. package/build/src/modeling/DataDomain.js.map +1 -1
  10. package/build/src/modeling/DependentModel.d.ts +26 -0
  11. package/build/src/modeling/DependentModel.d.ts.map +1 -0
  12. package/build/src/modeling/DependentModel.js +23 -0
  13. package/build/src/modeling/DependentModel.js.map +1 -0
  14. package/build/src/modeling/types.d.ts +2 -0
  15. package/build/src/modeling/types.d.ts.map +1 -1
  16. package/build/src/modeling/types.js.map +1 -1
  17. package/build/src/models/store/Backend.d.ts +0 -168
  18. package/build/src/models/store/Backend.d.ts.map +1 -1
  19. package/build/src/models/store/Backend.js +1 -12
  20. package/build/src/models/store/Backend.js.map +1 -1
  21. package/build/tsconfig.tsbuildinfo +1 -1
  22. package/data/models/example-generator-api.json +16 -16
  23. package/package.json +1 -1
  24. package/src/amf/ApiSchemaValues.ts +1 -1
  25. package/src/modeling/ApiModel.ts +74 -31
  26. package/src/modeling/DataDomain.ts +65 -35
  27. package/src/modeling/DependentModel.ts +36 -0
  28. package/src/modeling/types.ts +2 -0
  29. package/src/models/store/Backend.ts +0 -176
  30. package/tests/unit/modeling/api_model.spec.ts +17 -15
  31. package/tests/unit/modeling/data_domain_foreign.spec.ts +172 -39
@@ -1,180 +1,4 @@
1
1
  import type { PatchInfo } from '../../patch/types.js'
2
- import { type IPatchRevision } from '../../events/BaseEvents.js'
3
- import { type IHttpHistory, Kind as HttpHistoryKind } from '../HttpHistory.js'
4
- import { Kind as ProjectExecutionKind } from '../ProjectExecution.js'
5
- import type { IFile } from './File.js'
6
- import type { IPermission } from './Permission.js'
7
- import type { IRevision } from './Revision.js'
8
- /**
9
- * @deprecated
10
- */
11
- export enum BackendCommandType {
12
- observe,
13
- unobserve,
14
- }
15
- /**
16
- * @deprecated
17
- */
18
- export const BackendCommandKind = 'Core#BackendCommand'
19
- /**
20
- * @deprecated
21
- */
22
- export interface IBackendCommand {
23
- kind: typeof BackendCommandKind
24
- cmd: BackendCommandType
25
- }
26
- /**
27
- * @deprecated
28
- */
29
- export interface IBackendObserveCommand extends IBackendCommand {
30
- path: string // includes query parameters
31
- }
32
- /**
33
- * @deprecated
34
- */
35
- export interface BroadcastEvent {
36
- type: 'event'
37
- operation: string
38
- kind: string
39
- key: string
40
- path: string
41
- organization: string // empty string for `/organizations`
42
- }
43
- /**
44
- * @deprecated
45
- */
46
- export interface BackendErrorEvent {
47
- type: 'error'
48
- cause: string
49
- time: number
50
- }
51
- /**
52
- * @deprecated
53
- */
54
- export interface ClearedBroadcastEvent {
55
- type: 'event'
56
- operation: 'cleared'
57
- name: string
58
- organization: string
59
- path: string
60
- }
61
- /**
62
- * @deprecated
63
- */
64
- export interface BroadcastFileData {
65
- parent?: string
66
- }
67
- /**
68
- * @deprecated
69
- */
70
- export interface BroadcastCreatedEvent extends BroadcastEvent {
71
- operation: 'created'
72
- data: unknown
73
- // path: string; -> /files, /certificates, /history, /project/executions, /organizations, /trash
74
- }
75
- /**
76
- * @deprecated
77
- */
78
- export interface FileCreatedBroadcastEvent extends BroadcastCreatedEvent, BroadcastFileData {}
79
- /**
80
- * @deprecated
81
- */
82
- export interface FileMetaCreatedBroadcastEvent extends FileCreatedBroadcastEvent {
83
- data: IFile
84
- alt: 'meta'
85
- }
86
- /**
87
- * @deprecated
88
- */
89
- export interface FileMediaCreatedBroadcastEvent extends FileCreatedBroadcastEvent {
90
- alt: 'media'
91
- }
92
- /**
93
- * @deprecated
94
- */
95
- export interface HistoryCreatedBroadcastEvent extends BroadcastCreatedEvent {
96
- project: string
97
- request: string
98
- app: string
99
- kind: typeof HttpHistoryKind
100
- data: IHttpHistory
101
- }
102
- /**
103
- * @deprecated
104
- */
105
- export interface FileRevisionCreatedBroadcastEvent extends BroadcastCreatedEvent, BroadcastFileData {
106
- parent: string
107
- data: IRevision
108
- }
109
- /**
110
- * @deprecated
111
- */
112
- export interface ProjectExecutionCreatedBroadcastEvent extends BroadcastCreatedEvent {
113
- project: string
114
- kind: typeof ProjectExecutionKind
115
- }
116
- /**
117
- * @deprecated
118
- */
119
- export interface BroadcastPatchEvent extends BroadcastEvent {
120
- operation: 'patch'
121
- data: IPatchRevision
122
- // path: string; -> /files, /organizations
123
- }
124
- /**
125
- * @deprecated
126
- */
127
- export interface FilePatchBroadcastEvent extends BroadcastPatchEvent, BroadcastFileData {}
128
-
129
- /**
130
- * @deprecated
131
- */
132
- export interface AccessBroadcastEvent extends BroadcastEvent {
133
- operation: 'access-granted' | 'access-removed'
134
- data?: IPermission
135
- // path: string; -> /files, /organizations, /organizations
136
- }
137
-
138
- /**
139
- * @deprecated
140
- */
141
- export interface FileAccessBroadcastEvent extends AccessBroadcastEvent {
142
- parent?: string
143
- }
144
-
145
- /**
146
- * @deprecated
147
- */
148
- export interface DeletedBroadcastEvent extends BroadcastEvent {
149
- operation: 'deleted'
150
- // path: string; -> /files, /certificates, /history, /project/executions, /organizations, /trash
151
- }
152
-
153
- /**
154
- * @deprecated
155
- */
156
- export interface FileDeletedBroadcastEvent extends DeletedBroadcastEvent, BroadcastFileData {
157
- /**
158
- * The key of the created trash entry for the deleted object.
159
- * This is **always** populated when the file alt is `meta`.
160
- */
161
- trash?: string
162
- }
163
-
164
- /**
165
- * @deprecated
166
- */
167
- export interface ProjectExecutionDeleteBroadcastEvent extends DeletedBroadcastEvent {
168
- project: string
169
- }
170
-
171
- /**
172
- * @deprecated
173
- */
174
- export interface HistoryDeletedBroadcastEvent extends DeletedBroadcastEvent {
175
- project: string
176
- request: string
177
- }
178
2
 
179
3
  export interface ServerEvent {
180
4
  kind: string
@@ -17,7 +17,7 @@ test.group('ApiModel.createSchema()', () => {
17
17
  assert.deepInclude(schema.info, { name: 'Unnamed API' })
18
18
  assert.deepEqual(schema.exposes, [])
19
19
  assert.isUndefined(schema.userKey)
20
- assert.isUndefined(schema.domain)
20
+ assert.isUndefined(schema.dependencyList)
21
21
  assert.isUndefined(schema.authentication)
22
22
  assert.isUndefined(schema.authorization)
23
23
  assert.isUndefined(schema.session)
@@ -31,7 +31,7 @@ test.group('ApiModel.createSchema()', () => {
31
31
  info: { name: 'Test API', description: 'A test API' },
32
32
  exposes: [{ key: 'entity1', actions: [] }],
33
33
  userKey: 'user-entity',
34
- domain: { key: 'domain1', version: '1.0.0' },
34
+ dependencyList: [{ key: 'domain1', version: '1.0.0' }],
35
35
  authentication: { strategy: 'UsernamePassword' },
36
36
  authorization: { strategy: 'RBAC', roleKey: 'role' } as RolesBasedAccessControl,
37
37
  session: { secret: 'secret', properties: ['email'] },
@@ -45,7 +45,7 @@ test.group('ApiModel.createSchema()', () => {
45
45
  assert.deepInclude(schema.info, { name: 'Test API', description: 'A test API' })
46
46
  assert.deepEqual(schema.exposes, [{ key: 'entity1', actions: [] }])
47
47
  assert.equal(schema.userKey, 'user-entity')
48
- assert.deepEqual(schema.domain, { key: 'domain1', version: '1.0.0' })
48
+ assert.deepEqual(schema.dependencyList, [{ key: 'domain1', version: '1.0.0' }])
49
49
  assert.deepEqual(schema.authentication, { strategy: 'UsernamePassword' })
50
50
  assert.deepEqual(schema.authorization, { strategy: 'RBAC', roleKey: 'role' })
51
51
  assert.deepEqual(schema.session, { secret: 'secret', properties: ['email'] })
@@ -73,13 +73,12 @@ test.group('ApiModel.constructor()', () => {
73
73
  assert.equal(model.info.name, 'Unnamed API')
74
74
  assert.deepEqual(model.exposes, [])
75
75
  assert.isUndefined(model.userKey)
76
- assert.isUndefined(model.domain)
77
76
  assert.isUndefined(model.authentication)
78
77
  assert.isUndefined(model.authorization)
79
78
  assert.isUndefined(model.session)
80
79
  assert.isUndefined(model.accessRule)
81
80
  assert.isUndefined(model.rateLimiting)
82
- assert.isUndefined(model.dataDomain)
81
+ assert.deepEqual(model.dependencyList, [])
83
82
  })
84
83
 
85
84
  test('creates an instance with provided schema values', ({ assert }) => {
@@ -89,7 +88,7 @@ test.group('ApiModel.constructor()', () => {
89
88
  info: { name: 'Test API', description: 'A test API' },
90
89
  exposes: [{ key: 'entity1', actions: [] }],
91
90
  userKey: 'user-entity',
92
- domain: { key: 'domain1', version: '1.0.0' },
91
+ dependencyList: [{ key: 'domain1', version: '1.0.0' }],
93
92
  authentication: { strategy: 'UsernamePassword' },
94
93
  authorization: { strategy: 'RBAC', roleKey: 'role' } as RolesBasedAccessControl,
95
94
  session: { secret: 'secret', properties: ['email'] },
@@ -102,21 +101,24 @@ test.group('ApiModel.constructor()', () => {
102
101
  assert.equal(model.info.name, 'Test API')
103
102
  assert.deepEqual(model.exposes, [{ key: 'entity1', actions: [] }])
104
103
  assert.equal(model.userKey, 'user-entity')
105
- assert.deepEqual(model.domain, { key: 'domain1', version: '1.0.0' })
104
+ assert.deepEqual(model.dependencyList, [{ key: 'domain1', version: '1.0.0' }])
106
105
  assert.deepEqual(model.authentication, { strategy: 'UsernamePassword' })
107
106
  assert.deepEqual(model.authorization, { strategy: 'RBAC', roleKey: 'role' })
108
107
  assert.deepEqual(model.session, { secret: 'secret', properties: ['email'] })
109
108
  assert.deepEqual(model.accessRule, [{ type: 'public' }])
110
109
  assert.deepEqual(model.rateLimiting, { rules: [] })
111
- assert.isUndefined(model.dataDomain)
112
110
  })
113
111
 
114
112
  test('creates an instance with a DataDomain', ({ assert }) => {
115
113
  const domainSchema = DataDomain.createSchema({ key: 'my-domain' })
116
- const model = new ApiModel({}, domainSchema)
117
- assert.isDefined(model.dataDomain)
118
- assert.instanceOf(model.dataDomain, DataDomain)
119
- assert.equal(model.dataDomain!.key, 'my-domain')
114
+ domainSchema.info.version = '1.0.0'
115
+ const model = new ApiModel(
116
+ { dependencyList: [{ version: domainSchema.info.version, key: domainSchema.key }] },
117
+ domainSchema
118
+ )
119
+ assert.isDefined(model.domain)
120
+ assert.instanceOf(model.domain, DataDomain)
121
+ assert.equal(model.domain!.key, 'my-domain')
120
122
  })
121
123
 
122
124
  test('notifies change when info is modified', async ({ assert }) => {
@@ -141,7 +143,7 @@ test.group('ApiModel.toJSON()', () => {
141
143
  assert.deepInclude(json.info, { name: 'Unnamed API' })
142
144
  assert.deepEqual(json.exposes, [])
143
145
  assert.isUndefined(json.userKey)
144
- assert.isUndefined(json.domain)
146
+ assert.isUndefined(json.dependencyList)
145
147
  assert.isUndefined(json.authentication)
146
148
  assert.isUndefined(json.authorization)
147
149
  assert.isUndefined(json.session)
@@ -156,7 +158,7 @@ test.group('ApiModel.toJSON()', () => {
156
158
  info: { name: 'Test API', description: 'A test API' },
157
159
  exposes: [{ key: 'entity1', actions: [] }],
158
160
  userKey: 'user-entity',
159
- domain: { key: 'domain1', version: '1.0.0' },
161
+ dependencyList: [{ key: 'domain1', version: '1.0.0' }],
160
162
  authentication: { strategy: 'UsernamePassword' },
161
163
  authorization: { strategy: 'RBAC', roleKey: 'role' } as RolesBasedAccessControl,
162
164
  session: { secret: 'secret', properties: ['email'] },
@@ -170,7 +172,7 @@ test.group('ApiModel.toJSON()', () => {
170
172
  assert.deepInclude(json.info, { name: 'Test API', description: 'A test API' })
171
173
  assert.deepEqual(json.exposes, [{ key: 'entity1', actions: [] }])
172
174
  assert.equal(json.userKey, 'user-entity')
173
- assert.deepEqual(json.domain, { key: 'domain1', version: '1.0.0' })
175
+ assert.deepEqual(json.dependencyList, [{ key: 'domain1', version: '1.0.0' }])
174
176
  assert.deepEqual(json.authentication, { strategy: 'UsernamePassword' })
175
177
  assert.deepEqual(json.authorization, { strategy: 'RBAC', roleKey: 'role' })
176
178
  assert.deepEqual(json.session, { secret: 'secret', properties: ['email'] })
@@ -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
  })