@api-client/core 0.6.5 → 0.6.6

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 (39) hide show
  1. package/build/browser.d.ts +6 -0
  2. package/build/browser.js +6 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +6 -0
  5. package/build/index.js +6 -0
  6. package/build/index.js.map +1 -1
  7. package/build/src/models/data/DataAssociation.d.ts +76 -0
  8. package/build/src/models/data/DataAssociation.js +151 -0
  9. package/build/src/models/data/DataAssociation.js.map +1 -0
  10. package/build/src/models/data/DataAssociationSchema.d.ts +32 -0
  11. package/build/src/models/data/DataAssociationSchema.js +2 -0
  12. package/build/src/models/data/DataAssociationSchema.js.map +1 -0
  13. package/build/src/models/data/DataEntity.d.ts +195 -0
  14. package/build/src/models/data/DataEntity.js +415 -0
  15. package/build/src/models/data/DataEntity.js.map +1 -0
  16. package/build/src/models/data/DataModel.d.ts +74 -0
  17. package/build/src/models/data/DataModel.js +173 -0
  18. package/build/src/models/data/DataModel.js.map +1 -0
  19. package/build/src/models/data/DataNamespace.d.ts +174 -0
  20. package/build/src/models/data/DataNamespace.js +424 -0
  21. package/build/src/models/data/DataNamespace.js.map +1 -0
  22. package/build/src/models/data/DataProperty.d.ts +159 -0
  23. package/build/src/models/data/DataProperty.js +216 -0
  24. package/build/src/models/data/DataProperty.js.map +1 -0
  25. package/build/src/models/data/DataPropertySchema.d.ts +125 -0
  26. package/build/src/models/data/DataPropertySchema.js +33 -0
  27. package/build/src/models/data/DataPropertySchema.js.map +1 -0
  28. package/build/src/runtime/store/FilesSdk.d.ts +4 -2
  29. package/build/src/runtime/store/FilesSdk.js +1 -1
  30. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/models/data/DataAssociation.ts +189 -0
  33. package/src/models/data/DataAssociationSchema.ts +32 -0
  34. package/src/models/data/DataEntity.ts +496 -0
  35. package/src/models/data/DataModel.ts +206 -0
  36. package/src/models/data/DataNamespace.ts +503 -0
  37. package/src/models/data/DataProperty.ts +306 -0
  38. package/src/models/data/DataPropertySchema.ts +156 -0
  39. package/src/runtime/store/FilesSdk.ts +5 -2
@@ -0,0 +1,415 @@
1
+ import { Thing } from "../Thing.js";
2
+ import v4 from '../../lib/uuid.js';
3
+ import { DataProperty } from "./DataProperty.js";
4
+ import { DataAssociation } from "./DataAssociation.js";
5
+ export const Kind = 'Core#DataEntity';
6
+ /**
7
+ * Data entity is the smallest description of a data in the system
8
+ * It contains properties and associations. At least one entity describe a data model.
9
+ */
10
+ export class DataEntity {
11
+ root;
12
+ kind = Kind;
13
+ key = '';
14
+ /**
15
+ * The description of the data namespace.
16
+ */
17
+ info = Thing.fromName('');
18
+ /**
19
+ * Optional general purpose tags for the UI.
20
+ */
21
+ tags = [];
22
+ /**
23
+ * Reserved for future use.
24
+ *
25
+ * The keys of the taxonomy items associated with the entity.
26
+ */
27
+ taxonomy = [];
28
+ /**
29
+ * The list of keys of properties that belong to this entity.
30
+ */
31
+ properties = [];
32
+ /**
33
+ * The list of keys of associations that belong to this entity.
34
+ */
35
+ associations = [];
36
+ /**
37
+ * The list of keys of entities that are parents to this entity.
38
+ *
39
+ * This potentially may cause a conflict when two parents declare the same
40
+ * property. In such situation this entity should define own property
41
+ * with the same name to shadow parent property. When the property is
42
+ * not shadowed this may cause unexpected results as the processing could result
43
+ * with inconsistent definition of a schema because the last read property wins.
44
+ */
45
+ parents = [];
46
+ static fromName(root, name) {
47
+ const entity = new DataEntity(root);
48
+ entity.info = Thing.fromName(name);
49
+ return entity;
50
+ }
51
+ /**
52
+ * @param input The data entity definition to restore.
53
+ */
54
+ constructor(root, input) {
55
+ this.root = root;
56
+ let init;
57
+ if (typeof input === 'string') {
58
+ init = JSON.parse(input);
59
+ }
60
+ else if (typeof input === 'object') {
61
+ init = input;
62
+ }
63
+ else {
64
+ init = {
65
+ kind: Kind,
66
+ key: v4(),
67
+ info: Thing.fromName('').toJSON(),
68
+ };
69
+ }
70
+ this.new(init);
71
+ }
72
+ new(init) {
73
+ if (!DataEntity.isDataEntity(init)) {
74
+ throw new Error(`Not a data entity.`);
75
+ }
76
+ const { info, key = v4(), kind = Kind, tags, taxonomy, parents, properties, associations } = init;
77
+ this.kind = kind;
78
+ this.key = key;
79
+ if (info) {
80
+ this.info = new Thing(info);
81
+ }
82
+ else {
83
+ this.info = Thing.fromName('');
84
+ }
85
+ if (Array.isArray(tags)) {
86
+ this.tags = [...tags];
87
+ }
88
+ else {
89
+ this.tags = [];
90
+ }
91
+ if (Array.isArray(taxonomy)) {
92
+ this.taxonomy = [...taxonomy];
93
+ }
94
+ else {
95
+ this.taxonomy = [];
96
+ }
97
+ if (Array.isArray(parents)) {
98
+ this.parents = [...parents];
99
+ }
100
+ else {
101
+ this.parents = [];
102
+ }
103
+ this.properties = [];
104
+ if (Array.isArray(properties)) {
105
+ properties.forEach(key => {
106
+ const value = this._readProperty(key);
107
+ if (value) {
108
+ this.properties.push(value);
109
+ }
110
+ });
111
+ }
112
+ this.associations = [];
113
+ if (Array.isArray(associations)) {
114
+ associations.forEach(key => {
115
+ const value = this._readAssociation(key);
116
+ if (value) {
117
+ this.associations.push(value);
118
+ }
119
+ });
120
+ }
121
+ }
122
+ static isDataEntity(input) {
123
+ const typed = input;
124
+ if (!input || typed.kind !== Kind) {
125
+ return false;
126
+ }
127
+ return true;
128
+ }
129
+ toJSON() {
130
+ const result = {
131
+ kind: Kind,
132
+ key: this.key,
133
+ info: this.info.toJSON(),
134
+ };
135
+ if (Array.isArray(this.tags) && this.tags.length) {
136
+ result.tags = [...this.tags];
137
+ }
138
+ if (Array.isArray(this.taxonomy) && this.taxonomy.length) {
139
+ result.taxonomy = [...this.taxonomy];
140
+ }
141
+ if (Array.isArray(this.parents) && this.parents.length) {
142
+ result.parents = [...this.parents];
143
+ }
144
+ if (Array.isArray(this.properties) && this.properties.length) {
145
+ result.properties = this.properties.map(i => i.key);
146
+ }
147
+ if (Array.isArray(this.associations) && this.associations.length) {
148
+ result.associations = this.associations.map(i => i.key);
149
+ }
150
+ return result;
151
+ }
152
+ _readAssociation(key) {
153
+ return this.root.definitions.associations.find(i => i.key === key);
154
+ }
155
+ _readProperty(key) {
156
+ return this.root.definitions.properties.find(i => i.key === key);
157
+ }
158
+ /**
159
+ * Creates a property with a passed type.
160
+ * @param type The type of the property
161
+ * @returns The created property
162
+ */
163
+ addTypedProperty(type) {
164
+ const property = DataProperty.fromType(this.root, type);
165
+ this.root.definitions.properties.push(property);
166
+ this.properties.push(property);
167
+ return property;
168
+ }
169
+ /**
170
+ * Creates a property with a passed type.
171
+ * @param name The name of the property.
172
+ * @returns The created property
173
+ */
174
+ addNamedProperty(name) {
175
+ const property = DataProperty.fromName(this.root, name);
176
+ this.root.definitions.properties.push(property);
177
+ this.properties.push(property);
178
+ return property;
179
+ }
180
+ /**
181
+ * Removes the property from the entity and namespace definitions.
182
+ * @param key The key of the property to remove.
183
+ */
184
+ removeProperty(key) {
185
+ const thisIndex = this.properties.findIndex(i => i.key === key);
186
+ if (thisIndex < 0) {
187
+ return;
188
+ }
189
+ this.properties.splice(thisIndex, 1);
190
+ const defIndex = this.root.definitions.properties.findIndex(i => i.key === key);
191
+ if (defIndex >= 0) {
192
+ this.root.definitions.properties.splice(defIndex, 1);
193
+ }
194
+ }
195
+ /**
196
+ * Creates an association for a given name, adds it to definitions, and returns it.
197
+ * @param name The name of the association
198
+ * @returns The created association
199
+ */
200
+ addNamedAssociation(name) {
201
+ const result = DataAssociation.fromName(this.root, name);
202
+ this.root.definitions.associations.push(result);
203
+ this.associations.push(result);
204
+ return result;
205
+ }
206
+ /**
207
+ * Creates an association for a given target, adds it to definitions, and returns it.
208
+ * @param target The target entity key of the association
209
+ * @returns The created association
210
+ */
211
+ addTargetAssociation(target) {
212
+ const result = DataAssociation.fromTarget(this.root, target);
213
+ this.root.definitions.associations.push(result);
214
+ this.associations.push(result);
215
+ return result;
216
+ }
217
+ /**
218
+ * Removes an association from the entity and namespace definitions.
219
+ * @param key The key of the association to remove.
220
+ */
221
+ removeAssociation(key) {
222
+ const thisIndex = this.associations.findIndex(i => i.key === key);
223
+ if (thisIndex < 0) {
224
+ return;
225
+ }
226
+ this.associations.splice(thisIndex, 1);
227
+ const defIndex = this.root.definitions.associations.findIndex(i => i.key === key);
228
+ if (defIndex >= 0) {
229
+ this.root.definitions.associations.splice(defIndex, 1);
230
+ }
231
+ }
232
+ /**
233
+ * Reads the list of parents for the entity, inside the root namespace. The computed list contains the list of all
234
+ * parents in the inheritance chain in no particular order.
235
+ */
236
+ getComputedParents() {
237
+ const { entities } = this.root.definitions;
238
+ let result = [];
239
+ this.parents.forEach((key) => {
240
+ const parent = entities.find(i => i.key === key);
241
+ if (parent) {
242
+ result.push(parent);
243
+ result = result.concat(parent.getComputedParents());
244
+ }
245
+ });
246
+ return result;
247
+ }
248
+ /**
249
+ * Computes list of all children, inside the root namespace, that extends this entity.
250
+ * The children are not ordered.
251
+ */
252
+ getComputedChildren() {
253
+ const { entities } = this.root.definitions;
254
+ return entities.filter(i => i.parents.includes(this.key));
255
+ }
256
+ /**
257
+ * Computes a list of entities that are associated with the current entity.
258
+ */
259
+ getComputedAssociations() {
260
+ const { root, associations } = this;
261
+ const { entities } = root.definitions;
262
+ const result = [];
263
+ associations.forEach((assoc) => {
264
+ if (!assoc.target) {
265
+ return;
266
+ }
267
+ const entity = entities.find(i => i.key === assoc.target);
268
+ if (entity) {
269
+ result.push(entity);
270
+ }
271
+ });
272
+ return result;
273
+ }
274
+ /**
275
+ * Removes self from the namespace with all properties and attributes.
276
+ */
277
+ remove() {
278
+ const { key, properties, associations, root } = this;
279
+ // remove own stuff
280
+ properties.forEach(p => this.removeProperty(p.key));
281
+ associations.forEach(a => this.removeAssociation(a.key));
282
+ // remove from the root
283
+ const index = root.definitions.entities.findIndex(i => i.key === key);
284
+ if (index >= 0) {
285
+ root.definitions.entities.splice(index, 1);
286
+ }
287
+ // remove from the parent
288
+ const model = this.getParent();
289
+ if (model) {
290
+ const entityIndex = model.entities.findIndex(e => e === this);
291
+ model.entities.splice(entityIndex, 1);
292
+ }
293
+ }
294
+ /**
295
+ * Returns a parent data model where this entity exist.
296
+ */
297
+ getParent() {
298
+ return this.root.definitions.models.find(m => m.entities.some(e => e === this));
299
+ }
300
+ /**
301
+ * Tests whether one entity is associated with another.
302
+ *
303
+ * @param entity1 The source entity
304
+ * @param entity2 The target entity
305
+ * @returns true when there's any path from one entity to another.
306
+ */
307
+ static isAssociated(entity1, entity2) {
308
+ return entity1.isAssociated(entity2.key);
309
+ }
310
+ /**
311
+ * Tests whether this entity is somehow associated with another entity.
312
+ * @param target The key of the target entity to test for association with.
313
+ * @returns true if this entity has any association to the `target` entity.
314
+ */
315
+ isAssociated(target) {
316
+ const it = this.associationPath(target);
317
+ const path = it.next().value;
318
+ return !!path;
319
+ }
320
+ /**
321
+ * Prints out all associations from one entity to another through all entities that may be in between.
322
+ * @param toEntity The key to the target entity
323
+ * @yields The path containing keys of entities from this entity to the `toEntity` (inclusive) and all entities in between.
324
+ */
325
+ *associationPath(toEntity) {
326
+ const graph = this._associationGraph();
327
+ for (const path of this._associationPath(this.key, toEntity, graph)) {
328
+ yield path;
329
+ }
330
+ }
331
+ /**
332
+ * The actual implementation of the graph search.
333
+ *
334
+ * @param from The current from node
335
+ * @param to The target node
336
+ * @param g The graph
337
+ * @param path The current list of entity ids.
338
+ * @param visited The list of visited paths to avoid cycles
339
+ */
340
+ *_associationPath(from, to, g, path = [], visited = new Set()) {
341
+ if (from === to) {
342
+ yield path.concat(to);
343
+ return;
344
+ }
345
+ if (visited.has(from)) {
346
+ // it's a cycle
347
+ return;
348
+ }
349
+ if (g[from]) {
350
+ visited.add(from);
351
+ path.push(from);
352
+ for (const neighbor of g[from]) {
353
+ yield* this._associationPath(neighbor, to, g, path, visited);
354
+ }
355
+ visited.delete(from);
356
+ path.pop();
357
+ }
358
+ }
359
+ /**
360
+ * @returns The graph of associations where keys are the source entities and the value is the list of all target entities.
361
+ */
362
+ _associationGraph() {
363
+ const graph = {};
364
+ const { associations, entities } = this.root.definitions;
365
+ for (const assoc of associations) {
366
+ if (!assoc.target) {
367
+ continue;
368
+ }
369
+ const srcEntity = entities.find(i => i.associations.some(a => a === assoc));
370
+ if (!srcEntity) {
371
+ continue;
372
+ }
373
+ if (!graph[srcEntity.key]) {
374
+ graph[srcEntity.key] = [];
375
+ }
376
+ graph[srcEntity.key].push(assoc.target);
377
+ }
378
+ return graph;
379
+ }
380
+ /**
381
+ * Creates breadcrumbs from this entity to the root namespace.
382
+ */
383
+ breadcrumbs() {
384
+ const result = [];
385
+ result.push({
386
+ key: this.key,
387
+ displayName: this.info.name || 'Unnamed entity',
388
+ kind: Kind,
389
+ });
390
+ const model = this.getParent();
391
+ if (model) {
392
+ result.push({
393
+ key: model.key,
394
+ kind: model.kind,
395
+ displayName: model.info.name || 'Unnamed data model',
396
+ });
397
+ let parent = model.getParent();
398
+ while (parent && parent !== this.root) {
399
+ result.push({
400
+ key: parent.key,
401
+ kind: parent.kind,
402
+ displayName: parent.info.name || 'Unnamed namespace',
403
+ });
404
+ parent = parent.getParent();
405
+ }
406
+ }
407
+ result.push({
408
+ key: this.root.key,
409
+ displayName: this.root.info.name || 'Unnamed namespace',
410
+ kind: this.root.kind,
411
+ });
412
+ return result.reverse();
413
+ }
414
+ }
415
+ //# sourceMappingURL=DataEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataEntity.js","sourceRoot":"","sources":["../../../../src/models/data/DataEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAmDtC;;;GAGG;AACH,MAAM,OAAO,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GAAG,EAAE,MAAM,CAAC,GAAG;oBACf,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;iBACrD,CAAC,CAAC;gBACH,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;aAC7B;SACF;QACD,MAAM,CAAC,IAAI,CAAC;YACV,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;YAClB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,mBAAmB;YACvD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,74 @@
1
+ import { IThing, Thing } from "../Thing.js";
2
+ import { DataEntity, IDataEntity } from "./DataEntity.js";
3
+ import { DataNamespace } from "./DataNamespace.js";
4
+ import { IBreadcrumb } from "../store/Breadcrumb.js";
5
+ export declare const Kind = "Core#DataModel";
6
+ /**
7
+ * Data model creates a logical structure around data entities.
8
+ * It groups entities that represents a whole schema, like a Product data model
9
+ * can have entities that describe: the product entity, price history entity,
10
+ * product location, etc.
11
+ */
12
+ export interface IDataModel {
13
+ kind: typeof Kind;
14
+ /**
15
+ * The key of the namespace.
16
+ */
17
+ key: string;
18
+ /**
19
+ * The data model description.
20
+ */
21
+ info: IThing;
22
+ /**
23
+ * The list of keys of entities that this data model contain.
24
+ */
25
+ entities?: string[];
26
+ }
27
+ /**
28
+ * Data model creates a logical structure around data entities.
29
+ * It groups entities that represents a whole schema, like a Product data model
30
+ * can have entities that describe: the product entity, price history entity,
31
+ * product location, etc.
32
+ */
33
+ export declare class DataModel {
34
+ protected root: DataNamespace;
35
+ kind: string;
36
+ key: string;
37
+ /**
38
+ * The description of the data namespace.
39
+ */
40
+ info: Thing;
41
+ /**
42
+ * The list of keys of entities that this data model contain.
43
+ */
44
+ entities: DataEntity[];
45
+ static fromName(root: DataNamespace, name: string): DataModel;
46
+ /**
47
+ * @param root the root namespace.
48
+ * @param input The data model definition to restore.
49
+ */
50
+ constructor(root: DataNamespace, input?: string | IDataModel);
51
+ new(init: IDataModel): void;
52
+ static isDataModel(input: unknown): boolean;
53
+ toJSON(): IDataModel;
54
+ protected _readEntity(key: string): DataEntity | undefined;
55
+ /**
56
+ * Removes self from the namespace with all entities.
57
+ */
58
+ remove(): void;
59
+ /**
60
+ * Adds an entity to this data model.
61
+ *
62
+ * @param init The name of the entity to create, the instance of the entity or its schema
63
+ * @returns A reference to the created entity.
64
+ */
65
+ addEntity(init: string | DataEntity | IDataEntity): DataEntity;
66
+ /**
67
+ * Returns a parent namespace where this data model exist.
68
+ */
69
+ getParent(): DataNamespace | undefined;
70
+ /**
71
+ * Creates breadcrumbs from this data model to the root namespace.
72
+ */
73
+ breadcrumbs(): IBreadcrumb[];
74
+ }
@@ -0,0 +1,173 @@
1
+ import { Thing } from "../Thing.js";
2
+ import v4 from '../../lib/uuid.js';
3
+ import { DataEntity } from "./DataEntity.js";
4
+ export const Kind = 'Core#DataModel';
5
+ /**
6
+ * Data model creates a logical structure around data entities.
7
+ * It groups entities that represents a whole schema, like a Product data model
8
+ * can have entities that describe: the product entity, price history entity,
9
+ * product location, etc.
10
+ */
11
+ export class DataModel {
12
+ root;
13
+ kind = Kind;
14
+ key = '';
15
+ /**
16
+ * The description of the data namespace.
17
+ */
18
+ info = Thing.fromName('');
19
+ /**
20
+ * The list of keys of entities that this data model contain.
21
+ */
22
+ entities = [];
23
+ static fromName(root, name) {
24
+ const entity = new DataModel(root);
25
+ entity.info = Thing.fromName(name);
26
+ return entity;
27
+ }
28
+ /**
29
+ * @param root the root namespace.
30
+ * @param input The data model definition to restore.
31
+ */
32
+ constructor(root, input) {
33
+ this.root = root;
34
+ let init;
35
+ if (typeof input === 'string') {
36
+ init = JSON.parse(input);
37
+ }
38
+ else if (typeof input === 'object') {
39
+ init = input;
40
+ }
41
+ else {
42
+ init = {
43
+ kind: Kind,
44
+ key: v4(),
45
+ info: Thing.fromName('').toJSON(),
46
+ entities: [],
47
+ };
48
+ }
49
+ this.new(init);
50
+ }
51
+ new(init) {
52
+ if (!DataModel.isDataModel(init)) {
53
+ throw new Error(`Not a data model.`);
54
+ }
55
+ const { info, key = v4(), kind = Kind, entities } = init;
56
+ this.kind = kind;
57
+ this.key = key;
58
+ if (info) {
59
+ this.info = new Thing(info);
60
+ }
61
+ else {
62
+ this.info = Thing.fromName('');
63
+ }
64
+ this.entities = [];
65
+ if (Array.isArray(entities)) {
66
+ entities.forEach(key => {
67
+ const value = this._readEntity(key);
68
+ if (value) {
69
+ this.entities.push(value);
70
+ }
71
+ });
72
+ }
73
+ }
74
+ static isDataModel(input) {
75
+ const typed = input;
76
+ if (!input || typed.kind !== Kind) {
77
+ return false;
78
+ }
79
+ return true;
80
+ }
81
+ toJSON() {
82
+ const result = {
83
+ kind: Kind,
84
+ key: this.key,
85
+ info: this.info.toJSON(),
86
+ };
87
+ if (Array.isArray(this.entities) && this.entities.length) {
88
+ result.entities = this.entities.map(i => i.key);
89
+ }
90
+ return result;
91
+ }
92
+ _readEntity(key) {
93
+ return this.root.definitions.entities.find(i => i.key === key);
94
+ }
95
+ /**
96
+ * Removes self from the namespace with all entities.
97
+ */
98
+ remove() {
99
+ const { key, entities, root } = this;
100
+ // remove children
101
+ entities.forEach(e => e.remove());
102
+ // remove self from the parent
103
+ const parent = this.getParent();
104
+ if (parent) {
105
+ const itemIndex = parent.items.findIndex(i => i.key === key);
106
+ if (itemIndex >= 0) {
107
+ parent.items.splice(itemIndex, 1);
108
+ }
109
+ }
110
+ // remove self from definitions
111
+ const index = root.definitions.models.findIndex(i => i.key === key);
112
+ if (index >= 0) {
113
+ root.definitions.models.splice(index, 1);
114
+ }
115
+ }
116
+ /**
117
+ * Adds an entity to this data model.
118
+ *
119
+ * @param init The name of the entity to create, the instance of the entity or its schema
120
+ * @returns A reference to the created entity.
121
+ */
122
+ addEntity(init) {
123
+ let definition;
124
+ if (typeof init === 'string') {
125
+ definition = DataEntity.fromName(this.root, init);
126
+ }
127
+ else if (init instanceof DataEntity) {
128
+ definition = init;
129
+ }
130
+ else {
131
+ definition = new DataEntity(this.root, init);
132
+ }
133
+ this.root.definitions.entities.push(definition);
134
+ this.entities.push(definition);
135
+ return definition;
136
+ }
137
+ /**
138
+ * Returns a parent namespace where this data model exist.
139
+ */
140
+ getParent() {
141
+ if (this.root.items.some(e => e.key === this.key)) {
142
+ return this.root;
143
+ }
144
+ return this.root.definitions.namespaces.find(n => n.items.some(e => e.key === this.key));
145
+ }
146
+ /**
147
+ * Creates breadcrumbs from this data model to the root namespace.
148
+ */
149
+ breadcrumbs() {
150
+ const result = [];
151
+ result.push({
152
+ key: this.key,
153
+ displayName: this.info.name || 'Unnamed data model',
154
+ kind: Kind,
155
+ });
156
+ let parent = this.getParent();
157
+ while (parent && parent !== this.root) {
158
+ result.push({
159
+ key: parent.key,
160
+ kind: parent.kind,
161
+ displayName: parent.info.name || 'Unnamed namespace',
162
+ });
163
+ parent = parent.getParent();
164
+ }
165
+ result.push({
166
+ key: this.root.key,
167
+ displayName: this.root.info.name || 'Unnamed namespace',
168
+ kind: this.root.kind,
169
+ });
170
+ return result.reverse();
171
+ }
172
+ }
173
+ //# sourceMappingURL=DataModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../../../src/models/data/DataModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAe,MAAM,iBAAiB,CAAC;AAI1D,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAwBrC;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IAyBE;IAxBtB,IAAI,GAAG,IAAI,CAAC;IAEZ,GAAG,GAAG,EAAE,CA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