@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,18 +1,18 @@
1
1
  import { Graph } from '@api-client/graph/graph/Graph.js';
2
2
  import { DataDomainKind } from '../models/kinds.js';
3
- import type { AssociationAddOptions, DomainGraphEdge, DomainGraphNodeType, ForeignDomainDependency, SerializedGraph } from './types.js';
3
+ import type { AssociationAddOptions, DomainGraphEdge, DomainGraphNodeType, SerializedGraph } from './types.js';
4
4
  import { type DomainNamespaceSchema, DomainNamespace, type NamespaceOrderedItem } from './DomainNamespace.js';
5
5
  import { type DomainModelSchema, DomainModel } from './DomainModel.js';
6
6
  import { type DomainEntitySchema, DomainEntity } from './DomainEntity.js';
7
7
  import { DomainAssociation } from './DomainAssociation.js';
8
8
  import { DomainProperty, DomainPropertySchema } from './DomainProperty.js';
9
9
  import { type IThing, Thing } from '../models/Thing.js';
10
- export interface DataDomainSchema {
10
+ import { DependentModel, type DependentModelSchema, type DomainDependency } from './DependentModel.js';
11
+ export interface DataDomainSchema extends DependentModelSchema {
11
12
  info: IThing;
12
13
  kind: typeof DataDomainKind;
13
14
  key: string;
14
15
  graph?: SerializedGraph;
15
- dependencyList?: ForeignDomainDependency[];
16
16
  /**
17
17
  * The ordered list of fields (namespace and models) in the schema.
18
18
  * These only keep references to define the order of these properties
@@ -86,7 +86,7 @@ export interface DataDomainSchema {
86
86
  * @todo: Implement a mechanism to move an entity to a new
87
87
  * parent model.
88
88
  */
89
- export declare class DataDomain extends EventTarget {
89
+ export declare class DataDomain extends DependentModel {
90
90
  #private;
91
91
  /**
92
92
  * The kind of the domain element.
@@ -100,16 +100,6 @@ export declare class DataDomain extends EventTarget {
100
100
  * The graph used to store the data domain structure.
101
101
  */
102
102
  graph: Graph<unknown, DomainGraphNodeType, DomainGraphEdge>;
103
- /**
104
- * A map of foreign data domains.
105
- * Key: The unique identifier of the foreign domain.
106
- * Value: The foreign DataDomain instance.
107
- */
108
- dependencies: Map<string, DataDomain>;
109
- /**
110
- * The list of foreign domain dependencies.
111
- */
112
- dependencyList: ForeignDomainDependency[];
113
103
  /**
114
104
  * The description of the domain property.
115
105
  */
@@ -137,7 +127,7 @@ export declare class DataDomain extends EventTarget {
137
127
  * @param state The previously serialized state of the graph.
138
128
  * @param dependencies An array of foreign data domains to register with this domain.
139
129
  */
140
- constructor(state?: Partial<DataDomainSchema>, dependencies?: DataDomain[]);
130
+ constructor(state?: Partial<DataDomainSchema>, dependencies?: DomainDependency[]);
141
131
  /**
142
132
  * Serializes the DataDomain instance to a JSON object.
143
133
  * It does not serialize the foreign domain dependencies. The serialized nodes
@@ -247,10 +237,28 @@ export declare class DataDomain extends EventTarget {
247
237
  * ```
248
238
  */
249
239
  listGraphNamespaces(parent?: string): Generator<DomainNamespace>;
240
+ /**
241
+ * Builds a reference key for a domain object.
242
+ *
243
+ * If the namespace is provided and it is different from the domain key,
244
+ * it will return the key in the format `namespace:key`. The foreign namespace
245
+ * must be registered in the domain's dependencies otherwise an error will be thrown.
246
+ *
247
+ * @param key The key of the namespace or model.
248
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
249
+ * @returns The reference key in the format `namespace:key` or just `key` if no namespace is provided.
250
+ * @throws Error When the foreign domain is not found.
251
+ * @example
252
+ * ```typescript
253
+ * const refKey = dataDomain.buildReferenceKey('userModel', 'domainKey');
254
+ * ```
255
+ */
256
+ buildReferenceKey(key: string, namespace?: string): string;
250
257
  /**
251
258
  * Finds a namespace by its key.
252
259
  *
253
260
  * @param key The key of the namespace to find.
261
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
254
262
  * @returns The namespace instance or undefined if not
255
263
  * found.
256
264
  * @example
@@ -261,7 +269,7 @@ export declare class DataDomain extends EventTarget {
261
269
  * }
262
270
  * ```
263
271
  */
264
- findNamespace(key: string): DomainNamespace | undefined;
272
+ findNamespace(key: string, namespace?: string): DomainNamespace | undefined;
265
273
  /**
266
274
  * Moves a namespace to a new parent.
267
275
  *
@@ -360,6 +368,7 @@ export declare class DataDomain extends EventTarget {
360
368
  * Finds a data model by its key.
361
369
  *
362
370
  * @param key The key of the data model to find.
371
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
363
372
  * @returns The data model instance or undefined if not
364
373
  * found.
365
374
  * @example
@@ -370,7 +379,7 @@ export declare class DataDomain extends EventTarget {
370
379
  * }
371
380
  * ```
372
381
  */
373
- findModel(key: string): DomainModel | undefined;
382
+ findModel(key: string, namespace?: string): DomainModel | undefined;
374
383
  /**
375
384
  * Moves a data model to a new parent.
376
385
  *
@@ -436,6 +445,7 @@ export declare class DataDomain extends EventTarget {
436
445
  * Finds an entity by its key.
437
446
  *
438
447
  * @param key The key of the entity to find.
448
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
439
449
  * @returns The entity instance or undefined if not found.
440
450
  * @example
441
451
  * ```typescript
@@ -445,7 +455,7 @@ export declare class DataDomain extends EventTarget {
445
455
  * }
446
456
  * ```
447
457
  */
448
- findEntity(key: string): DomainEntity | undefined;
458
+ findEntity(key: string, namespace?: string): DomainEntity | undefined;
449
459
  /**
450
460
  * Moves an entity from one model to another.
451
461
  *
@@ -493,6 +503,7 @@ export declare class DataDomain extends EventTarget {
493
503
  * Finds an association by its key.
494
504
  *
495
505
  * @param key The key of the association to find.
506
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign association
496
507
  * @returns The association instance or undefined if not
497
508
  * found.
498
509
  * @example
@@ -503,7 +514,7 @@ export declare class DataDomain extends EventTarget {
503
514
  * }
504
515
  * ```
505
516
  */
506
- findAssociation(key: string): DomainAssociation | undefined;
517
+ findAssociation(key: string, namespace?: string): DomainAssociation | undefined;
507
518
  /**
508
519
  * Adds a property to an entity.
509
520
  *
@@ -537,6 +548,7 @@ export declare class DataDomain extends EventTarget {
537
548
  * Finds a property by its key.
538
549
  *
539
550
  * @param key The key of the property to find.
551
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign property
540
552
  * @returns The property instance or undefined if not
541
553
  * found.
542
554
  * @example
@@ -547,7 +559,7 @@ export declare class DataDomain extends EventTarget {
547
559
  * }
548
560
  * ```
549
561
  */
550
- findProperty(key: string): DomainProperty | undefined;
562
+ findProperty(key: string, namespace?: string): DomainProperty | undefined;
551
563
  /**
552
564
  * Registers a foreign DataDomain.
553
565
  *
@@ -586,6 +598,8 @@ export declare class DataDomain extends EventTarget {
586
598
  * console.log(foreignUser.key);
587
599
  * }
588
600
  * ```
601
+ * @deprecated Use `findEntity` with the `namespace` parameter instead.
602
+ * This method is kept for backward compatibility but will be removed in the future.
589
603
  */
590
604
  findForeignEntity(entityKey: string, domainKey: string): DomainEntity | undefined;
591
605
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"DataDomain.d.ts","sourceRoot":"","sources":["../../../src/modeling/DataDomain.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAA;AACxD,OAAO,EAEL,cAAc,EAKf,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,qBAAqB,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC7G,OAAO,EAAE,KAAK,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAIvD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,cAAc,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,cAAc,CAAC,EAAE,uBAAuB,EAAE,CAAA;IAC1C;;;;OAIG;IACH,MAAM,CAAC,EAAE,oBA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G,YAAY,GAAG,SAAS;IAajF;;;;;;;;;;;OAWG;IACH,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;CAqBrD"}
@@ -5,6 +5,7 @@ import { DomainModel } from './DomainModel.js';
5
5
  import { Thing } from '../models/Thing.js';
6
6
  import { removeGraphNode } from './GraphUtils.js';
7
7
  import { serialize, deserialize, mergeGraph, removeForeignGraph } from './DomainSerialization.js';
8
+ import { DependentModel } from './DependentModel.js';
8
9
  /**
9
10
  * Represents the root of a data domain model.
10
11
  *
@@ -71,7 +72,7 @@ import { serialize, deserialize, mergeGraph, removeForeignGraph } from './Domain
71
72
  * @todo: Implement a mechanism to move an entity to a new
72
73
  * parent model.
73
74
  */
74
- export class DataDomain extends EventTarget {
75
+ export class DataDomain extends DependentModel {
75
76
  /**
76
77
  * The kind of the domain element.
77
78
  */
@@ -84,16 +85,6 @@ export class DataDomain extends EventTarget {
84
85
  * The graph used to store the data domain structure.
85
86
  */
86
87
  graph;
87
- /**
88
- * A map of foreign data domains.
89
- * Key: The unique identifier of the foreign domain.
90
- * Value: The foreign DataDomain instance.
91
- */
92
- dependencies = new Map();
93
- /**
94
- * The list of foreign domain dependencies.
95
- */
96
- dependencyList = [];
97
88
  /**
98
89
  * The description of the domain property.
99
90
  */
@@ -155,13 +146,26 @@ export class DataDomain extends EventTarget {
155
146
  * @param state The previously serialized state of the graph.
156
147
  * @param dependencies An array of foreign data domains to register with this domain.
157
148
  */
158
- constructor(state, dependencies) {
159
- super();
149
+ constructor(state, dependencies = []) {
160
150
  const init = DataDomain.createSchema(state);
151
+ const instances = [];
152
+ for (const dep of dependencies) {
153
+ if (dep instanceof DataDomain) {
154
+ instances.push(dep);
155
+ }
156
+ else if (typeof dep === 'object' && dep.kind === DataDomainKind && dep.key) {
157
+ const domain = new DataDomain(dep);
158
+ instances.push(domain);
159
+ }
160
+ else {
161
+ throw new Error(`Invalid foreign domain dependency: ${dep}`);
162
+ }
163
+ }
164
+ super(init.dependencyList, instances);
161
165
  this.kind = init.kind;
162
166
  this.key = init.key;
163
167
  this.info = new Thing(init.info);
164
- this.graph = deserialize(this, init.graph, dependencies);
168
+ this.graph = deserialize(this, init.graph, instances);
165
169
  if (Array.isArray(init.fields)) {
166
170
  this.fields = [...init.fields];
167
171
  }
@@ -389,10 +393,40 @@ export class DataDomain extends EventTarget {
389
393
  }
390
394
  }
391
395
  }
396
+ /**
397
+ * Builds a reference key for a domain object.
398
+ *
399
+ * If the namespace is provided and it is different from the domain key,
400
+ * it will return the key in the format `namespace:key`. The foreign namespace
401
+ * must be registered in the domain's dependencies otherwise an error will be thrown.
402
+ *
403
+ * @param key The key of the namespace or model.
404
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
405
+ * @returns The reference key in the format `namespace:key` or just `key` if no namespace is provided.
406
+ * @throws Error When the foreign domain is not found.
407
+ * @example
408
+ * ```typescript
409
+ * const refKey = dataDomain.buildReferenceKey('userModel', 'domainKey');
410
+ * ```
411
+ */
412
+ buildReferenceKey(key, namespace) {
413
+ if (namespace && namespace !== this.key) {
414
+ if (typeof namespace !== 'string' || namespace.length === 0) {
415
+ throw new Error(`Invalid namespace key. Expected a string, got ${typeof namespace}`);
416
+ }
417
+ const foreignDomain = this.dependencies.get(namespace);
418
+ if (!foreignDomain) {
419
+ throw new Error(`Foreign domain ${namespace} not found`);
420
+ }
421
+ return `${namespace}:${key}`;
422
+ }
423
+ return key;
424
+ }
392
425
  /**
393
426
  * Finds a namespace by its key.
394
427
  *
395
428
  * @param key The key of the namespace to find.
429
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign namespace.
396
430
  * @returns The namespace instance or undefined if not
397
431
  * found.
398
432
  * @example
@@ -403,8 +437,8 @@ export class DataDomain extends EventTarget {
403
437
  * }
404
438
  * ```
405
439
  */
406
- findNamespace(key) {
407
- const result = this.graph.node(key);
440
+ findNamespace(key, namespace) {
441
+ const result = this.graph.node(this.buildReferenceKey(key, namespace));
408
442
  if (result && result.kind === DomainNamespaceKind) {
409
443
  return result;
410
444
  }
@@ -637,6 +671,7 @@ export class DataDomain extends EventTarget {
637
671
  * Finds a data model by its key.
638
672
  *
639
673
  * @param key The key of the data model to find.
674
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
640
675
  * @returns The data model instance or undefined if not
641
676
  * found.
642
677
  * @example
@@ -647,8 +682,8 @@ export class DataDomain extends EventTarget {
647
682
  * }
648
683
  * ```
649
684
  */
650
- findModel(key) {
651
- const value = this.graph.node(key);
685
+ findModel(key, namespace) {
686
+ const value = this.graph.node(this.buildReferenceKey(key, namespace));
652
687
  if (value && value.kind === DomainModelKind) {
653
688
  return value;
654
689
  }
@@ -815,6 +850,7 @@ export class DataDomain extends EventTarget {
815
850
  * Finds an entity by its key.
816
851
  *
817
852
  * @param key The key of the entity to find.
853
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign entity.
818
854
  * @returns The entity instance or undefined if not found.
819
855
  * @example
820
856
  * ```typescript
@@ -824,8 +860,8 @@ export class DataDomain extends EventTarget {
824
860
  * }
825
861
  * ```
826
862
  */
827
- findEntity(key) {
828
- const node = this.graph.node(key);
863
+ findEntity(key, namespace) {
864
+ const node = this.graph.node(this.buildReferenceKey(key, namespace));
829
865
  if (node && node.kind === DomainEntityKind) {
830
866
  return node;
831
867
  }
@@ -936,6 +972,7 @@ export class DataDomain extends EventTarget {
936
972
  * Finds an association by its key.
937
973
  *
938
974
  * @param key The key of the association to find.
975
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign association
939
976
  * @returns The association instance or undefined if not
940
977
  * found.
941
978
  * @example
@@ -946,8 +983,8 @@ export class DataDomain extends EventTarget {
946
983
  * }
947
984
  * ```
948
985
  */
949
- findAssociation(key) {
950
- const node = this.graph.node(key);
986
+ findAssociation(key, namespace) {
987
+ const node = this.graph.node(this.buildReferenceKey(key, namespace));
951
988
  if (node && node.kind === DomainAssociationKind) {
952
989
  return node;
953
990
  }
@@ -1018,6 +1055,7 @@ export class DataDomain extends EventTarget {
1018
1055
  * Finds a property by its key.
1019
1056
  *
1020
1057
  * @param key The key of the property to find.
1058
+ * @param namespace The namespace to search in. When different from the domain key, it looks for a foreign property
1021
1059
  * @returns The property instance or undefined if not
1022
1060
  * found.
1023
1061
  * @example
@@ -1028,8 +1066,8 @@ export class DataDomain extends EventTarget {
1028
1066
  * }
1029
1067
  * ```
1030
1068
  */
1031
- findProperty(key) {
1032
- const node = this.graph.node(key);
1069
+ findProperty(key, namespace) {
1070
+ const node = this.graph.node(this.buildReferenceKey(key, namespace));
1033
1071
  if (node && node.kind === DomainPropertyKind) {
1034
1072
  return node;
1035
1073
  }
@@ -1100,6 +1138,8 @@ export class DataDomain extends EventTarget {
1100
1138
  * console.log(foreignUser.key);
1101
1139
  * }
1102
1140
  * ```
1141
+ * @deprecated Use `findEntity` with the `namespace` parameter instead.
1142
+ * This method is kept for backward compatibility but will be removed in the future.
1103
1143
  */
1104
1144
  findForeignEntity(entityKey, domainKey) {
1105
1145
  const foreignDomain = this.dependencies.get(domainKey);