@api-client/core 0.13.6 → 0.14.1
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.
- package/build/src/amf/AmfTypes.d.ts +1 -1
- package/build/src/amf/AmfTypes.js +1 -1
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/Utils.d.ts +0 -6
- package/build/src/amf/Utils.d.ts.map +1 -1
- package/build/src/amf/Utils.js +0 -14
- package/build/src/amf/Utils.js.map +1 -1
- package/build/src/browser.d.ts +1 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/legacy.d.ts +0 -8
- package/build/src/legacy.d.ts.map +1 -1
- package/build/src/legacy.js +0 -9
- package/build/src/legacy.js.map +1 -1
- package/build/src/modeling/Bindings.d.ts +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataDomain.js +2 -2
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DataFormat.d.ts +0 -40
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +0 -27
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +28 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +73 -4
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +25 -9
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +65 -21
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainFile.d.ts +3 -4
- package/build/src/modeling/DomainFile.d.ts.map +1 -1
- package/build/src/modeling/DomainFile.js +5 -9
- package/build/src/modeling/DomainFile.js.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts +1 -1
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +3 -3
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +2 -2
- package/build/src/modeling/DomainModel.js +2 -2
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +28 -12
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +61 -26
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts +109 -0
- package/build/src/modeling/Semantics.d.ts.map +1 -0
- package/build/src/modeling/Semantics.js +97 -0
- package/build/src/modeling/Semantics.js.map +1 -0
- package/build/src/models/CertificateFile.d.ts +2 -3
- package/build/src/models/CertificateFile.d.ts.map +1 -1
- package/build/src/models/CertificateFile.js +4 -8
- package/build/src/models/CertificateFile.js.map +1 -1
- package/build/src/models/Folder.d.ts +1 -2
- package/build/src/models/Folder.d.ts.map +1 -1
- package/build/src/models/Folder.js +2 -4
- package/build/src/models/Folder.js.map +1 -1
- package/build/src/models/Project.d.ts +2 -3
- package/build/src/models/Project.d.ts.map +1 -1
- package/build/src/models/Project.js +4 -8
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/kinds.d.ts +0 -24
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +0 -24
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/File.d.ts +1 -21
- package/build/src/models/store/File.d.ts.map +1 -1
- package/build/src/models/store/File.js +3 -23
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/data_catalog.d.ts +1 -1
- package/build/src/models/store/data_catalog.js.map +1 -1
- package/build/src/sdk/FilesSdk.js +1 -1
- package/build/src/sdk/FilesSdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +22 -22
- package/eslint.config.js +1 -0
- package/package.json +5 -5
- package/src/amf/AmfTypes.ts +1 -1
- package/src/amf/Utils.ts +0 -15
- package/src/modeling/Bindings.ts +1 -1
- package/src/modeling/DataDomain.ts +2 -2
- package/src/modeling/DataFormat.ts +0 -48
- package/src/modeling/DomainAssociation.ts +66 -3
- package/src/modeling/DomainEntity.ts +56 -17
- package/src/modeling/DomainFile.ts +5 -9
- package/src/modeling/DomainImpactAnalysis.ts +3 -3
- package/src/modeling/DomainModel.ts +2 -2
- package/src/modeling/DomainProperty.ts +60 -21
- package/src/modeling/Semantics.ts +178 -0
- package/src/modeling/graph.md +14 -14
- package/src/modeling/readme.md +29 -29
- package/src/models/CertificateFile.ts +4 -12
- package/src/models/Folder.ts +2 -4
- package/src/models/Project.ts +4 -8
- package/src/models/kinds.ts +0 -25
- package/src/models/store/File.ts +4 -35
- package/src/models/store/data_catalog.ts +1 -1
- package/src/sdk/FilesSdk.ts +1 -1
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +11 -10
- package/tests/unit/modeling/data_domain_entities.spec.ts +129 -1
- package/tests/unit/modeling/data_domain_property.spec.ts +1 -1
- package/tests/unit/modeling/domain_asociation.spec.ts +177 -0
- package/tests/unit/modeling/domain_entity.spec.ts +27 -26
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +11 -11
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +10 -10
- package/tests/unit/modeling/domain_file.spec.ts +4 -27
- package/tests/unit/modeling/{domain.property.spec.ts → domain_property.spec.ts} +139 -23
- package/tests/unit/models/Certificate/from_name.spec.ts +3 -15
- package/tests/unit/models/File/constructor.spec.ts +0 -1
- package/tests/unit/models/File/new.spec.ts +0 -13
- package/tests/unit/models/File/shortcutTo.spec.ts +1 -2
- package/tests/unit/models/File/toJSON.spec.ts +0 -13
- package/tests/unit/models/File/updateByMeMeta.spec.ts +4 -6
- package/tests/unit/models/Folder/create.spec.ts +2 -23
- package/tests/unit/models/Project/create.spec.ts +6 -32
- package/build/src/amf/AmfShapeGenerator.d.ts +0 -103
- package/build/src/amf/AmfShapeGenerator.d.ts.map +0 -1
- package/build/src/amf/AmfShapeGenerator.js +0 -416
- package/build/src/amf/AmfShapeGenerator.js.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.d.ts +0 -284
- package/build/src/modeling/legacy/DataAssociation.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataAssociation.js +0 -443
- package/build/src/modeling/legacy/DataAssociation.js.map +0 -1
- package/build/src/modeling/legacy/DataEntity.d.ts +0 -358
- package/build/src/modeling/legacy/DataEntity.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntity.js +0 -855
- package/build/src/modeling/legacy/DataEntity.js.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts +0 -162
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataEntityBuilder.js +0 -221
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +0 -298
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataImpactAnalysis.js +0 -441
- package/build/src/modeling/legacy/DataImpactAnalysis.js.map +0 -1
- package/build/src/modeling/legacy/DataModel.d.ts +0 -99
- package/build/src/modeling/legacy/DataModel.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataModel.js +0 -237
- package/build/src/modeling/legacy/DataModel.js.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.d.ts +0 -340
- package/build/src/modeling/legacy/DataNamespace.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataNamespace.js +0 -784
- package/build/src/modeling/legacy/DataNamespace.js.map +0 -1
- package/build/src/modeling/legacy/DataProperty.d.ts +0 -332
- package/build/src/modeling/legacy/DataProperty.d.ts.map +0 -1
- package/build/src/modeling/legacy/DataProperty.js +0 -415
- package/build/src/modeling/legacy/DataProperty.js.map +0 -1
- package/build/src/models/store/DataFile.d.ts +0 -31
- package/build/src/models/store/DataFile.d.ts.map +0 -1
- package/build/src/models/store/DataFile.js +0 -92
- package/build/src/models/store/DataFile.js.map +0 -1
- package/src/amf/AmfShapeGenerator.ts +0 -477
- package/src/modeling/legacy/DataAssociation.ts +0 -554
- package/src/modeling/legacy/DataEntity.ts +0 -1019
- package/src/modeling/legacy/DataEntityBuilder.ts +0 -236
- package/src/modeling/legacy/DataImpactAnalysis.ts +0 -530
- package/src/modeling/legacy/DataModel.ts +0 -276
- package/src/modeling/legacy/DataNamespace.ts +0 -929
- package/src/modeling/legacy/DataProperty.ts +0 -630
- package/src/models/store/DataFile.ts +0 -100
- package/tests/unit/modeling/legacy/amf_shape_generator.spec.ts +0 -1041
- package/tests/unit/modeling/legacy/data_association.spec.ts +0 -710
- package/tests/unit/modeling/legacy/data_entity.spec.ts +0 -2061
- package/tests/unit/modeling/legacy/data_entity_generator_json.spec.ts +0 -987
- package/tests/unit/modeling/legacy/data_entity_generator_xml.spec.ts +0 -1451
- package/tests/unit/modeling/legacy/data_model.spec.ts +0 -395
- package/tests/unit/modeling/legacy/data_namespace.spec.ts +0 -1312
- package/tests/unit/modeling/legacy/data_property.spec.ts +0 -887
- package/tests/unit/modeling/legacy/impact_analysis.spec.ts +0 -373
|
@@ -1,784 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
2
|
-
import { Thing } from '../../models/Thing.js';
|
|
3
|
-
import { DataAssociation } from './DataAssociation.js';
|
|
4
|
-
import { DataEntity } from './DataEntity.js';
|
|
5
|
-
import { DataModel } from './DataModel.js';
|
|
6
|
-
import { DataProperty } from './DataProperty.js';
|
|
7
|
-
import { DataNamespaceKind, DataModelKind, DataEntityKind, DataPropertyKind, DataAssociationKind, } from '../../models/kinds.js';
|
|
8
|
-
import { nanoid } from '../../nanoid.js';
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated
|
|
11
|
-
*/
|
|
12
|
-
export class DataItem {
|
|
13
|
-
kind = DataModelKind;
|
|
14
|
-
key = '';
|
|
15
|
-
/**
|
|
16
|
-
* A reference to the top level namespace.
|
|
17
|
-
*/
|
|
18
|
-
root;
|
|
19
|
-
static isDataItem(input) {
|
|
20
|
-
const typed = input;
|
|
21
|
-
if (!input || ![DataModelKind, DataNamespaceKind].includes(typed.kind)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
static dataNamespace(root, key) {
|
|
27
|
-
const item = new DataItem(root, {
|
|
28
|
-
kind: DataNamespaceKind,
|
|
29
|
-
key,
|
|
30
|
-
});
|
|
31
|
-
return item;
|
|
32
|
-
}
|
|
33
|
-
static dataModel(root, key) {
|
|
34
|
-
const item = new DataItem(root, {
|
|
35
|
-
kind: DataModelKind,
|
|
36
|
-
key,
|
|
37
|
-
});
|
|
38
|
-
return item;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @param root The top-most data namespace.
|
|
42
|
-
* @param input The project item definition used to restore the state.
|
|
43
|
-
*/
|
|
44
|
-
constructor(root, input) {
|
|
45
|
-
this.root = root;
|
|
46
|
-
let init;
|
|
47
|
-
if (typeof input === 'string') {
|
|
48
|
-
init = JSON.parse(input);
|
|
49
|
-
}
|
|
50
|
-
else if (typeof input === 'object') {
|
|
51
|
-
init = input;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
throw new Error('Specify the type of the item.');
|
|
55
|
-
}
|
|
56
|
-
this.new(init);
|
|
57
|
-
}
|
|
58
|
-
new(init) {
|
|
59
|
-
if (!DataItem.isDataItem(init)) {
|
|
60
|
-
throw new Error(`Not a data item.`);
|
|
61
|
-
}
|
|
62
|
-
const { kind, key } = init;
|
|
63
|
-
this.kind = kind;
|
|
64
|
-
this.key = key;
|
|
65
|
-
}
|
|
66
|
-
toJSON() {
|
|
67
|
-
const result = {
|
|
68
|
-
kind: this.kind,
|
|
69
|
-
key: this.key,
|
|
70
|
-
};
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
getItem() {
|
|
74
|
-
const { root, key, kind } = this;
|
|
75
|
-
const { definitions } = root;
|
|
76
|
-
if (kind === DataModelKind) {
|
|
77
|
-
return definitions.models.find((i) => i.key === key);
|
|
78
|
-
}
|
|
79
|
-
if (kind === kind) {
|
|
80
|
-
return definitions.namespaces.find((i) => i.key === key);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Data namespace is a logical description of the hierarchy in the data.
|
|
86
|
-
* @deprecated
|
|
87
|
-
*/
|
|
88
|
-
export class DataNamespace {
|
|
89
|
-
kind = DataNamespaceKind;
|
|
90
|
-
key = '';
|
|
91
|
-
/**
|
|
92
|
-
* The ordered list of items in this namespace.
|
|
93
|
-
*/
|
|
94
|
-
items = [];
|
|
95
|
-
/**
|
|
96
|
-
* The description of the data namespace.
|
|
97
|
-
*/
|
|
98
|
-
info = Thing.fromName('');
|
|
99
|
-
/**
|
|
100
|
-
* When a namespace is a sub-namespace this is the reference to the
|
|
101
|
-
* root namespace with all definitions.
|
|
102
|
-
*/
|
|
103
|
-
root;
|
|
104
|
-
/**
|
|
105
|
-
* The list of definitions used in the namespace.
|
|
106
|
-
*/
|
|
107
|
-
definitions;
|
|
108
|
-
/**
|
|
109
|
-
* The list of foreign namespaces.
|
|
110
|
-
* This is used to find entities from foreign namespaces.
|
|
111
|
-
* Values here are treated as read only (objects can be frozen).
|
|
112
|
-
*
|
|
113
|
-
* This should be set by the application and the namespace will do
|
|
114
|
-
* nothing to populate this value.
|
|
115
|
-
*/
|
|
116
|
-
foreign = [];
|
|
117
|
-
/**
|
|
118
|
-
* Creates a new data namespace from a name.
|
|
119
|
-
* @param name The name to set.
|
|
120
|
-
*/
|
|
121
|
-
static fromName(name, root) {
|
|
122
|
-
const ns = new DataNamespace(undefined, root);
|
|
123
|
-
const info = Thing.fromName(name);
|
|
124
|
-
ns.info = info;
|
|
125
|
-
return ns;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @deprecated
|
|
129
|
-
*/
|
|
130
|
-
static definitions() {
|
|
131
|
-
return {
|
|
132
|
-
models: [],
|
|
133
|
-
associations: [],
|
|
134
|
-
entities: [],
|
|
135
|
-
properties: [],
|
|
136
|
-
namespaces: [],
|
|
137
|
-
tags: [],
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
constructor(input, root) {
|
|
141
|
-
this.root = root;
|
|
142
|
-
this.definitions = {
|
|
143
|
-
models: [],
|
|
144
|
-
associations: [],
|
|
145
|
-
entities: [],
|
|
146
|
-
properties: [],
|
|
147
|
-
namespaces: [],
|
|
148
|
-
tags: [],
|
|
149
|
-
};
|
|
150
|
-
let init;
|
|
151
|
-
if (typeof input === 'string') {
|
|
152
|
-
init = JSON.parse(input);
|
|
153
|
-
}
|
|
154
|
-
else if (typeof input === 'object') {
|
|
155
|
-
init = input;
|
|
156
|
-
if (!init.kind) {
|
|
157
|
-
init.kind = DataNamespaceKind;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
init = {
|
|
162
|
-
kind: DataNamespaceKind,
|
|
163
|
-
key: nanoid(),
|
|
164
|
-
definitions: {},
|
|
165
|
-
items: [],
|
|
166
|
-
info: Thing.fromName('').toJSON(),
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
this.new(init);
|
|
170
|
-
}
|
|
171
|
-
new(init) {
|
|
172
|
-
if (!init || !init.definitions || !init.items) {
|
|
173
|
-
throw new Error(`Not a data namespace.`);
|
|
174
|
-
}
|
|
175
|
-
const { key = nanoid(), definitions = {}, items, info } = init;
|
|
176
|
-
this.key = key;
|
|
177
|
-
if (info) {
|
|
178
|
-
this.info = new Thing(info);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
this.info = Thing.fromName('');
|
|
182
|
-
}
|
|
183
|
-
if (Array.isArray(items)) {
|
|
184
|
-
this.items = items.map((i) => new DataItem(this, i));
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
this.items = [];
|
|
188
|
-
}
|
|
189
|
-
if (Array.isArray(definitions.associations)) {
|
|
190
|
-
this.definitions.associations = definitions.associations.map((i) => new DataAssociation(this, i));
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
this.definitions.associations = [];
|
|
194
|
-
}
|
|
195
|
-
if (Array.isArray(definitions.properties)) {
|
|
196
|
-
this.definitions.properties = definitions.properties.map((i) => new DataProperty(this, i));
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
this.definitions.properties = [];
|
|
200
|
-
}
|
|
201
|
-
// note, entities must be restored after properties / associations
|
|
202
|
-
if (Array.isArray(definitions.entities)) {
|
|
203
|
-
this.definitions.entities = definitions.entities.map((i) => new DataEntity(this, i));
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this.definitions.entities = [];
|
|
207
|
-
}
|
|
208
|
-
// must be set after entities.
|
|
209
|
-
if (Array.isArray(definitions.models)) {
|
|
210
|
-
this.definitions.models = definitions.models.map((i) => new DataModel(this, i));
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
this.definitions.models = [];
|
|
214
|
-
}
|
|
215
|
-
if (Array.isArray(definitions.namespaces)) {
|
|
216
|
-
this.definitions.namespaces = definitions.namespaces.map((i) => new DataNamespace(i, this));
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
this.definitions.namespaces = [];
|
|
220
|
-
}
|
|
221
|
-
if (Array.isArray(definitions.tags)) {
|
|
222
|
-
this.definitions.tags = [...definitions.tags];
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
this.definitions.tags = [];
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
toJSON() {
|
|
229
|
-
const result = {
|
|
230
|
-
key: this.key,
|
|
231
|
-
kind: DataNamespaceKind,
|
|
232
|
-
info: this.info.toJSON(),
|
|
233
|
-
items: this.items.map((i) => i.toJSON()),
|
|
234
|
-
definitions: {},
|
|
235
|
-
};
|
|
236
|
-
const { associations, entities, models, namespaces, properties, tags } = this.definitions;
|
|
237
|
-
if (Array.isArray(associations) && associations.length) {
|
|
238
|
-
result.definitions.associations = associations.map((i) => i.toJSON());
|
|
239
|
-
}
|
|
240
|
-
if (Array.isArray(entities) && entities.length) {
|
|
241
|
-
result.definitions.entities = entities.map((i) => i.toJSON());
|
|
242
|
-
}
|
|
243
|
-
if (Array.isArray(models) && models.length) {
|
|
244
|
-
result.definitions.models = models.map((i) => i.toJSON());
|
|
245
|
-
}
|
|
246
|
-
if (Array.isArray(namespaces) && namespaces.length) {
|
|
247
|
-
result.definitions.namespaces = namespaces.map((i) => i.toJSON());
|
|
248
|
-
}
|
|
249
|
-
if (Array.isArray(properties) && properties.length) {
|
|
250
|
-
result.definitions.properties = properties.map((i) => i.toJSON());
|
|
251
|
-
}
|
|
252
|
-
if (Array.isArray(tags) && tags.length) {
|
|
253
|
-
result.definitions.tags = [...tags];
|
|
254
|
-
}
|
|
255
|
-
return result;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* @deprecated Use the `getParentInstance()` method instead.
|
|
259
|
-
*/
|
|
260
|
-
getParent() {
|
|
261
|
-
return this.getParentInstance();
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* @returns The parent namespace of this namespace. It returns `undefined` when this is the root namespace.
|
|
265
|
-
*/
|
|
266
|
-
getParentInstance() {
|
|
267
|
-
const { root, key } = this;
|
|
268
|
-
if (root) {
|
|
269
|
-
return root.findParent(key);
|
|
270
|
-
}
|
|
271
|
-
// we are the root namespace.
|
|
272
|
-
return undefined;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Lists namespaces that are in this namespace items.
|
|
276
|
-
*/
|
|
277
|
-
listNamespaces() {
|
|
278
|
-
const result = [];
|
|
279
|
-
const { items } = this;
|
|
280
|
-
const root = this.getRoot();
|
|
281
|
-
const { namespaces } = root.definitions;
|
|
282
|
-
items.forEach((i) => {
|
|
283
|
-
if (i.kind !== DataNamespaceKind) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const def = namespaces.find((j) => j.key === i.key);
|
|
287
|
-
if (def) {
|
|
288
|
-
result.push(def);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Lists namespaces that are in this namespace items.
|
|
295
|
-
*/
|
|
296
|
-
listDataModels() {
|
|
297
|
-
const result = [];
|
|
298
|
-
const { items } = this;
|
|
299
|
-
const root = this.getRoot();
|
|
300
|
-
const { models } = root.definitions;
|
|
301
|
-
items.forEach((i) => {
|
|
302
|
-
if (i.kind !== DataModelKind) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const def = models.find((j) => j.key === i.key);
|
|
306
|
-
if (def) {
|
|
307
|
-
result.push(def);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
return result;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* @returns The root of the namespaces tree. It might be the same object.
|
|
314
|
-
*/
|
|
315
|
-
getRoot() {
|
|
316
|
-
if (this.root) {
|
|
317
|
-
return this.root;
|
|
318
|
-
}
|
|
319
|
-
return this;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Removes self from the parent namespace with all data models.
|
|
323
|
-
* This does noting for the root namespace.
|
|
324
|
-
*/
|
|
325
|
-
remove(opts) {
|
|
326
|
-
const { root } = this;
|
|
327
|
-
if (!root) {
|
|
328
|
-
throw new Error(`Unable to remove the root namespace this way.`);
|
|
329
|
-
}
|
|
330
|
-
const models = this.listDataModels();
|
|
331
|
-
const children = this.listNamespaces();
|
|
332
|
-
models.forEach((m) => m.remove(opts));
|
|
333
|
-
children.forEach((c) => c.remove(opts));
|
|
334
|
-
const index = root.definitions.namespaces.findIndex((i) => i.key === this.key);
|
|
335
|
-
if (index >= 0) {
|
|
336
|
-
root.definitions.namespaces.splice(index, 1);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Checks if this is the root namespace.
|
|
341
|
-
* @returns True if this is the root namespace.
|
|
342
|
-
*/
|
|
343
|
-
isRoot() {
|
|
344
|
-
return this.root === undefined;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Finds a parent namespace for the given namespace.
|
|
348
|
-
* @param key The namespace key to find the parent for.
|
|
349
|
-
* @returns The parent namespace or undefined when the namespace does not exist. It may return the root namespace.
|
|
350
|
-
*/
|
|
351
|
-
findParent(key) {
|
|
352
|
-
const { definitions, items = [] } = this;
|
|
353
|
-
const rootIndex = items.findIndex((i) => i.key === key);
|
|
354
|
-
if (rootIndex >= 0) {
|
|
355
|
-
return this;
|
|
356
|
-
}
|
|
357
|
-
const definition = definitions.namespaces.find((i) => i.items.some((item) => item.key === key));
|
|
358
|
-
if (definition) {
|
|
359
|
-
return definition;
|
|
360
|
-
}
|
|
361
|
-
return undefined;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Adds a data namespace to the structure.
|
|
365
|
-
* @param init The name of the namespace to add, namespace's schema, or instance.
|
|
366
|
-
* @param parent The optional key of the parent namespace to add the new namespace to.
|
|
367
|
-
*/
|
|
368
|
-
addNamespace(init, parent) {
|
|
369
|
-
let root;
|
|
370
|
-
if (parent) {
|
|
371
|
-
const rootCandidate = this.findNamespace(parent);
|
|
372
|
-
if (!rootCandidate) {
|
|
373
|
-
throw new Error(`Unable to find the parent namespace ${parent}`);
|
|
374
|
-
}
|
|
375
|
-
root = rootCandidate;
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
root = this;
|
|
379
|
-
}
|
|
380
|
-
let definition;
|
|
381
|
-
if (typeof init === 'string') {
|
|
382
|
-
definition = DataNamespace.fromName(init, this.root || this);
|
|
383
|
-
}
|
|
384
|
-
else if (init instanceof DataNamespace) {
|
|
385
|
-
definition = init;
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
definition = new DataNamespace(init, this.root || this);
|
|
389
|
-
}
|
|
390
|
-
;
|
|
391
|
-
(this.root || this).definitions.namespaces.push(definition);
|
|
392
|
-
const item = DataItem.dataNamespace(this.root || this, definition.key);
|
|
393
|
-
if (!Array.isArray(root.items)) {
|
|
394
|
-
root.items = [];
|
|
395
|
-
}
|
|
396
|
-
root.items.push(item);
|
|
397
|
-
return definition;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Adapts an existing namespace to this namespace.
|
|
401
|
-
* This will remove the namespace from the parent namespace and add it to this one.
|
|
402
|
-
*
|
|
403
|
-
* @param ns The namespace to adapt.
|
|
404
|
-
* @param opts Adapting options.
|
|
405
|
-
*/
|
|
406
|
-
adaptNamespace(ns, opts = {}) {
|
|
407
|
-
if (opts.index !== undefined) {
|
|
408
|
-
if (opts.index < 0) {
|
|
409
|
-
throw new Error(`The index ${opts.index} cannot be below 0.`);
|
|
410
|
-
}
|
|
411
|
-
if (opts.index >= this.items.length) {
|
|
412
|
-
throw new Error(`The index ${opts.index} is not valid.`);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
if (ns === this) {
|
|
416
|
-
throw new Error(`Unable to adapt a namespace that is self.`);
|
|
417
|
-
}
|
|
418
|
-
if (ns.root !== this.root) {
|
|
419
|
-
throw new Error(`The namespace ${ns.key} is not in the same namespace as this data namespace.`);
|
|
420
|
-
}
|
|
421
|
-
if (ns.getParentInstance() === this) {
|
|
422
|
-
throw new Error(`The namespace ${ns.key} is already adapted by this data namespace.`);
|
|
423
|
-
}
|
|
424
|
-
// Check for circular dependency
|
|
425
|
-
let current = this;
|
|
426
|
-
while (current) {
|
|
427
|
-
if (current === ns) {
|
|
428
|
-
throw new Error(`Unable to adapt namespace ${ns.key} under itself or one of its children.`);
|
|
429
|
-
}
|
|
430
|
-
current = current.getParentInstance();
|
|
431
|
-
}
|
|
432
|
-
const parent = ns.getParentInstance() || this.root;
|
|
433
|
-
if (!parent) {
|
|
434
|
-
throw new Error(`The namespace ${ns.key} has no parent.`);
|
|
435
|
-
}
|
|
436
|
-
// it has a parent (above check) so it has the index.
|
|
437
|
-
const index = parent.items.findIndex((i) => i.key === ns.key);
|
|
438
|
-
const [item] = parent.items.splice(index, 1);
|
|
439
|
-
if (opts.index !== undefined) {
|
|
440
|
-
this.items.splice(opts.index, 0, item);
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
this.items.push(item);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Adapts an existing data model to this namespace.
|
|
448
|
-
* This will remove the data model from the parent namespace and add it to this one.
|
|
449
|
-
* @param model The data model to adapt.
|
|
450
|
-
* @param opts The adapting options.
|
|
451
|
-
*/
|
|
452
|
-
adaptDataModel(model, opts = {}) {
|
|
453
|
-
if (opts.index !== undefined) {
|
|
454
|
-
if (opts.index < 0) {
|
|
455
|
-
throw new Error(`The index ${opts.index} cannot be below 0.`);
|
|
456
|
-
}
|
|
457
|
-
if (opts.index >= this.items.length) {
|
|
458
|
-
throw new Error(`The index ${opts.index} is not valid.`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
if (model.root !== this.root) {
|
|
462
|
-
throw new Error(`The data model ${model.key} is not in the same namespace as this data namespace.`);
|
|
463
|
-
}
|
|
464
|
-
const parent = model.getParentInstance();
|
|
465
|
-
if (!parent) {
|
|
466
|
-
throw new Error(`The data model ${model.key} has no parent.`);
|
|
467
|
-
}
|
|
468
|
-
if (parent === this) {
|
|
469
|
-
throw new Error(`The data model ${model.key} is already adapted by this data namespace.`);
|
|
470
|
-
}
|
|
471
|
-
// it has a parent (above check) so it has the index.
|
|
472
|
-
const index = parent.items.findIndex((i) => i.key === model.key);
|
|
473
|
-
const [item] = parent.items.splice(index, 1);
|
|
474
|
-
if (opts.index !== undefined) {
|
|
475
|
-
this.items.splice(opts.index, 0, item);
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
this.items.push(item);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Finds a namespace in the definitions.
|
|
483
|
-
* @param key The key of the namespace to find.
|
|
484
|
-
* @returns The namespace definition or undefined when not found.
|
|
485
|
-
*/
|
|
486
|
-
findNamespace(key) {
|
|
487
|
-
const { definitions } = this.root || this;
|
|
488
|
-
return definitions.namespaces.find((i) => i.key === key);
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Finds a namespace and calls the `remove()` on it.
|
|
492
|
-
* @param key The key of the namespace to find.
|
|
493
|
-
*/
|
|
494
|
-
removeNamespace(key, opts) {
|
|
495
|
-
const root = this.root || this;
|
|
496
|
-
if (root.key === key) {
|
|
497
|
-
throw new Error(`Unable to remove the root namespace this way.`);
|
|
498
|
-
}
|
|
499
|
-
const { definitions } = root;
|
|
500
|
-
const ns = definitions.namespaces.find((i) => i.key === key);
|
|
501
|
-
if (ns) {
|
|
502
|
-
ns.remove(opts);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Adds a data model to a namespace.
|
|
507
|
-
* @param init The name of the data model to add, data model's schema, or its instance.
|
|
508
|
-
* @param parent The optional key of the parent namespace to add the new data model to.
|
|
509
|
-
*/
|
|
510
|
-
addDataModel(init, parent) {
|
|
511
|
-
let root;
|
|
512
|
-
if (parent) {
|
|
513
|
-
const rootCandidate = this.findNamespace(parent);
|
|
514
|
-
if (!rootCandidate) {
|
|
515
|
-
throw new Error(`Unable to find the parent namespace ${parent}`);
|
|
516
|
-
}
|
|
517
|
-
root = rootCandidate;
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
root = this;
|
|
521
|
-
}
|
|
522
|
-
let definition;
|
|
523
|
-
if (typeof init === 'string') {
|
|
524
|
-
definition = DataModel.fromName(this.root || this, init);
|
|
525
|
-
}
|
|
526
|
-
else if (init instanceof DataModel) {
|
|
527
|
-
definition = init;
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
definition = new DataModel(this.root || this, init);
|
|
531
|
-
}
|
|
532
|
-
;
|
|
533
|
-
(this.root || this).definitions.models.push(definition);
|
|
534
|
-
const item = DataItem.dataModel(this.root || this, definition.key);
|
|
535
|
-
if (!Array.isArray(root.items)) {
|
|
536
|
-
root.items = [];
|
|
537
|
-
}
|
|
538
|
-
root.items.push(item);
|
|
539
|
-
return definition;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Finds a data model in the definitions.
|
|
543
|
-
* @param key The key of the data model to find.
|
|
544
|
-
* @returns The data model definition or undefined when not found.
|
|
545
|
-
*/
|
|
546
|
-
findDataModel(key) {
|
|
547
|
-
const { definitions } = this.root || this;
|
|
548
|
-
return definitions.models.find((i) => i.key === key);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* A convenience function to remove an object from the namespace.
|
|
552
|
-
* @param key The key of the object to remove.
|
|
553
|
-
* @param kind The kind of the object to remove.
|
|
554
|
-
* @param opts The options for the removal.
|
|
555
|
-
* @throws Error when the kind is not known.
|
|
556
|
-
*/
|
|
557
|
-
removeObject(key, kind, opts) {
|
|
558
|
-
switch (kind) {
|
|
559
|
-
case DataNamespaceKind:
|
|
560
|
-
this.findNamespace(key)?.remove(opts);
|
|
561
|
-
break;
|
|
562
|
-
case DataModelKind:
|
|
563
|
-
this.findDataModel(key)?.remove(opts);
|
|
564
|
-
break;
|
|
565
|
-
case DataEntityKind:
|
|
566
|
-
this.findEntity(key)?.remove(opts);
|
|
567
|
-
break;
|
|
568
|
-
case DataPropertyKind:
|
|
569
|
-
this.findProperty(key)?.remove();
|
|
570
|
-
break;
|
|
571
|
-
case DataAssociationKind:
|
|
572
|
-
this.findAssociation(key)?.remove();
|
|
573
|
-
break;
|
|
574
|
-
default:
|
|
575
|
-
throw new Error(`Unknown kind ${kind} for the object ${key}.`);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Finds a data model and calls the `remove()` on it.
|
|
580
|
-
* @param key The key of the data model to find.
|
|
581
|
-
*/
|
|
582
|
-
removeDataModel(key, opts) {
|
|
583
|
-
const { definitions } = this.root || this;
|
|
584
|
-
const model = definitions.models.find((i) => i.key === key);
|
|
585
|
-
if (model) {
|
|
586
|
-
model.remove(opts);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* @returns The graph of associations where keys are the source
|
|
591
|
-
* entities and the value is the list of all target entities.
|
|
592
|
-
*/
|
|
593
|
-
associationGraph() {
|
|
594
|
-
const graph = {};
|
|
595
|
-
const { definitions } = this.root || this;
|
|
596
|
-
const { associations, entities } = definitions;
|
|
597
|
-
for (const assoc of associations) {
|
|
598
|
-
if (!assoc.targets.length) {
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
const srcEntity = entities.find((i) => i.associations.some((a) => a === assoc));
|
|
602
|
-
if (!srcEntity) {
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
if (!graph[srcEntity.key]) {
|
|
606
|
-
graph[srcEntity.key] = [];
|
|
607
|
-
}
|
|
608
|
-
const targetIds = assoc.targets.map((i) => i.key);
|
|
609
|
-
graph[srcEntity.key].splice(0, 0, ...targetIds);
|
|
610
|
-
}
|
|
611
|
-
return graph;
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* Prints out all associations from one entity to another through all entities that may be in between.
|
|
615
|
-
*
|
|
616
|
-
* @param from The key of the from entity
|
|
617
|
-
* @param to The key of the target entity
|
|
618
|
-
* @param g The graph generated with `associationGraph()`
|
|
619
|
-
* @param path The current list of entity ids. Do not set this, it is for the recursive processing of the graph.
|
|
620
|
-
* @param visited The list of visited paths to avoid cycles.
|
|
621
|
-
* Do not set this, it is for the recursive processing of the graph.
|
|
622
|
-
*/
|
|
623
|
-
*associationPath(from, to, g, path = [], visited = new Set()) {
|
|
624
|
-
if (from === to) {
|
|
625
|
-
yield path.concat(to);
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
if (visited.has(from)) {
|
|
629
|
-
// it's a cycle
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
632
|
-
if (g[from]) {
|
|
633
|
-
visited.add(from);
|
|
634
|
-
path.push(from);
|
|
635
|
-
for (const neighbor of g[from]) {
|
|
636
|
-
yield* this.associationPath(neighbor, to, g, path, visited);
|
|
637
|
-
}
|
|
638
|
-
visited.delete(from);
|
|
639
|
-
path.pop();
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* Scans all associations for foreign namespaces and returns
|
|
644
|
-
* the list of all namespaces used in the association graph.
|
|
645
|
-
* This will never add this namespace's key.
|
|
646
|
-
*
|
|
647
|
-
* This function should be used to read keys for all related
|
|
648
|
-
* namespaces through associations.
|
|
649
|
-
*
|
|
650
|
-
* @returns All keys of foreign namespaces.
|
|
651
|
-
*/
|
|
652
|
-
computeForeignNamespaceKeys() {
|
|
653
|
-
const result = [];
|
|
654
|
-
const { associations = [] } = this.definitions;
|
|
655
|
-
associations.forEach((association) => {
|
|
656
|
-
const { targets = [] } = association;
|
|
657
|
-
targets.forEach((target) => {
|
|
658
|
-
const { namespace } = target;
|
|
659
|
-
if (!namespace || namespace === this.key) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
result.push(namespace);
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
return result;
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Finds an entity in this namespace.
|
|
669
|
-
* @param key The key of the entity to find.
|
|
670
|
-
*/
|
|
671
|
-
findEntity(key) {
|
|
672
|
-
const { definitions } = this.root || this;
|
|
673
|
-
return definitions.entities.find((i) => i.key === key);
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Finds a property by its key.
|
|
677
|
-
* @param key The key of the property to find
|
|
678
|
-
* @returns The property or undefined if not found.
|
|
679
|
-
*/
|
|
680
|
-
findProperty(key) {
|
|
681
|
-
const { definitions } = this.root || this;
|
|
682
|
-
return definitions.properties.find((i) => i.key === key);
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Finds an association by its key.
|
|
686
|
-
* @param key The key of the property to find
|
|
687
|
-
* @returns The property or undefined if not found.
|
|
688
|
-
*/
|
|
689
|
-
findAssociation(key) {
|
|
690
|
-
const { definitions } = this.root || this;
|
|
691
|
-
return definitions.associations.find((i) => i.key === key);
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Searches for entities for association targets.
|
|
695
|
-
* This is a helper function to discover entities in the current and foreign namespaces.
|
|
696
|
-
*
|
|
697
|
-
* @param targets The list of targets
|
|
698
|
-
* @returns A list of entities. An `undefined` is put at the index where an entity cannot be found
|
|
699
|
-
*/
|
|
700
|
-
findAssociatedEntities(targets) {
|
|
701
|
-
const result = [];
|
|
702
|
-
targets.forEach((target) => {
|
|
703
|
-
let ns;
|
|
704
|
-
if (target.namespace) {
|
|
705
|
-
ns = this.foreign.find((i) => i.key === target.namespace);
|
|
706
|
-
}
|
|
707
|
-
else {
|
|
708
|
-
ns = this;
|
|
709
|
-
}
|
|
710
|
-
if (!ns) {
|
|
711
|
-
result.push(undefined);
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
const entity = ns.findEntity(target.key);
|
|
715
|
-
if (entity) {
|
|
716
|
-
result.push(entity);
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
result.push(undefined);
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
return result;
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* Finds an associated entity in the current or foreign namespace.
|
|
726
|
-
* This is a helper function to discover entities in the current and foreign namespaces.
|
|
727
|
-
*
|
|
728
|
-
* @param key The key of the entity to find.
|
|
729
|
-
* @param namespace The optional namespace to search in.
|
|
730
|
-
* If not set, the current namespace is used.
|
|
731
|
-
* This is used to find entities in foreign namespaces.
|
|
732
|
-
* @returns The entity or undefined if not found.
|
|
733
|
-
*/
|
|
734
|
-
findAssociatedEntity(key, namespace) {
|
|
735
|
-
let ns;
|
|
736
|
-
if (namespace) {
|
|
737
|
-
ns = this.foreign.find((i) => i.key === namespace);
|
|
738
|
-
}
|
|
739
|
-
else {
|
|
740
|
-
ns = this;
|
|
741
|
-
}
|
|
742
|
-
if (!ns) {
|
|
743
|
-
return undefined;
|
|
744
|
-
}
|
|
745
|
-
return ns.findEntity(key);
|
|
746
|
-
}
|
|
747
|
-
addForeign(ns) {
|
|
748
|
-
const exists = this.foreign.some((i) => i.key === ns.key);
|
|
749
|
-
if (exists) {
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
this.foreign.push(ns);
|
|
753
|
-
}
|
|
754
|
-
removeForeign(ns) {
|
|
755
|
-
const index = this.foreign.findIndex((i) => i === ns);
|
|
756
|
-
if (index >= 0) {
|
|
757
|
-
this.foreign.splice(index, 1);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
hasForeignNamespace(key) {
|
|
761
|
-
return this.foreign.some((i) => i.key === key);
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Checks whether the namespace is a child of the given namespace.
|
|
765
|
-
* The relationship doesn't have to be direct, as long as the namespace is in the hierarchy it will return true.
|
|
766
|
-
*
|
|
767
|
-
* @param key The key of the parent namespace to check.
|
|
768
|
-
* @returns True if this namespace is a child of the given namespace.
|
|
769
|
-
*/
|
|
770
|
-
isChildOf(key) {
|
|
771
|
-
if (this.key === key) {
|
|
772
|
-
return false;
|
|
773
|
-
}
|
|
774
|
-
const parent = this.getParentInstance();
|
|
775
|
-
if (!parent) {
|
|
776
|
-
return false;
|
|
777
|
-
}
|
|
778
|
-
if (parent.key === key) {
|
|
779
|
-
return true;
|
|
780
|
-
}
|
|
781
|
-
return parent.isChildOf(key);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
//# sourceMappingURL=DataNamespace.js.map
|