@api-client/core 0.6.14 → 0.6.15
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/browser.d.ts +9 -2
- package/build/browser.js +12 -2
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +9 -2
- package/build/index.js +12 -2
- package/build/index.js.map +1 -1
- package/build/src/amf/AmfMixin.d.ts +395 -0
- package/build/src/amf/AmfMixin.js +1146 -0
- package/build/src/amf/AmfMixin.js.map +1 -0
- package/build/src/amf/AmfSerializer.d.ts +136 -0
- package/build/src/amf/AmfSerializer.js +1913 -0
- package/build/src/amf/AmfSerializer.js.map +1 -0
- package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
- package/build/src/amf/AmfShapeGenerator.js +385 -0
- package/build/src/amf/AmfShapeGenerator.js.map +1 -0
- package/build/src/amf/AmfTypes.d.ts +24 -0
- package/build/src/amf/AmfTypes.js +122 -0
- package/build/src/amf/AmfTypes.js.map +1 -0
- package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
- package/build/src/amf/ApiExampleGenerator.js +109 -0
- package/build/src/amf/ApiExampleGenerator.js.map +1 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
- package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
- package/build/src/amf/ApiSchemaGenerator.js +94 -0
- package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
- package/build/src/amf/ApiSchemaValues.d.ts +98 -0
- package/build/src/amf/ApiSchemaValues.js +382 -0
- package/build/src/amf/ApiSchemaValues.js.map +1 -0
- package/build/src/amf/Utils.d.ts +41 -0
- package/build/src/amf/Utils.js +176 -0
- package/build/src/amf/Utils.js.map +1 -0
- package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
- package/build/src/amf/data-node/DataNodeBase.js +77 -0
- package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
- package/build/src/amf/definitions/Amf.d.ts +362 -0
- package/build/src/amf/definitions/Amf.js +2 -0
- package/build/src/amf/definitions/Amf.js.map +1 -0
- package/build/src/amf/definitions/Api.d.ts +381 -0
- package/build/src/amf/definitions/Api.js +2 -0
- package/build/src/amf/definitions/Api.js.map +1 -0
- package/build/src/amf/definitions/Base.d.ts +11 -0
- package/build/src/amf/definitions/Base.js +2 -0
- package/build/src/amf/definitions/Base.js.map +1 -0
- package/build/src/amf/definitions/Namespace.d.ts +311 -0
- package/build/src/amf/definitions/Namespace.js +330 -0
- package/build/src/amf/definitions/Namespace.js.map +1 -0
- package/build/src/amf/definitions/Shapes.d.ts +309 -0
- package/build/src/amf/definitions/Shapes.js +87 -0
- package/build/src/amf/definitions/Shapes.js.map +1 -0
- package/build/src/amf/models/AmfDataNode.d.ts +68 -0
- package/build/src/amf/models/AmfDataNode.js +188 -0
- package/build/src/amf/models/AmfDataNode.js.map +1 -0
- package/build/src/amf/shape/ShapeBase.d.ts +75 -0
- package/build/src/amf/shape/ShapeBase.js +90 -0
- package/build/src/amf/shape/ShapeBase.js.map +1 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
- package/build/src/models/data/Bindings.d.ts +161 -0
- package/build/src/models/data/Bindings.js +2 -0
- package/build/src/models/data/Bindings.js.map +1 -0
- package/build/src/models/data/DataAssociation.d.ts +135 -14
- package/build/src/models/data/DataAssociation.js +154 -21
- package/build/src/models/data/DataAssociation.js.map +1 -1
- package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
- package/build/src/models/data/DataEntity.d.ts +54 -4
- package/build/src/models/data/DataEntity.js +85 -9
- package/build/src/models/data/DataEntity.js.map +1 -1
- package/build/src/models/data/DataFile.d.ts +3 -0
- package/build/src/models/data/DataFile.js +3 -0
- package/build/src/models/data/DataFile.js.map +1 -1
- package/build/src/models/data/DataModel.d.ts +1 -1
- package/build/src/models/data/DataModel.js.map +1 -1
- package/build/src/models/data/DataProperty.d.ts +107 -36
- package/build/src/models/data/DataProperty.js +147 -17
- package/build/src/models/data/DataProperty.js.map +1 -1
- package/data/apis/oas-date/oas-date.yaml +28 -0
- package/data/apis/oas-types/oas-types.yaml +159 -0
- package/data/apis/oas-unions/oas-unions.yaml +75 -0
- package/data/apis/raml-date/raml-date.raml +28 -0
- package/data/apis/recursive/recursive.raml +14 -0
- package/data/apis/schema-api/examples/person.json +14 -0
- package/data/apis/schema-api/examples/person.raml +14 -0
- package/data/apis/schema-api/examples/person.url.encoded +1 -0
- package/data/apis/schema-api/examples/person.xml +14 -0
- package/data/apis/schema-api/library/demo-types.raml +43 -0
- package/data/apis/schema-api/schema-api.raml +644 -0
- package/data/apis/schema-api/schemas/person.json +104 -0
- package/data/apis/schema-api/schemas/person.xsd +26 -0
- package/data/apis/schema-api/types/DemoPerson.raml +67 -0
- package/data/model.js +106 -0
- package/data/models/oas-date.json +637 -0
- package/data/models/oas-types.json +5352 -0
- package/data/models/oas-unions.json +1881 -0
- package/data/models/raml-date.json +1096 -0
- package/data/models/recursive.json +610 -0
- package/data/models/schema-api.json +37319 -0
- package/package.json +9 -6
- package/src/amf/AmfMixin.ts +1623 -0
- package/src/amf/AmfSerializer.ts +2028 -0
- package/src/amf/AmfShapeGenerator.ts +400 -0
- package/src/amf/AmfTypes.ts +126 -0
- package/src/amf/ApiExampleGenerator.ts +112 -0
- package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
- package/src/amf/ApiSchemaGenerator.ts +108 -0
- package/src/amf/ApiSchemaValues.ts +411 -0
- package/src/amf/Utils.ts +182 -0
- package/src/amf/data-node/DataNodeBase.ts +81 -0
- package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
- package/src/amf/data-node/README.md +3 -0
- package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
- package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
- package/src/amf/definitions/Amf.ts +443 -0
- package/src/amf/definitions/Api.ts +427 -0
- package/src/amf/definitions/Base.ts +13 -0
- package/src/amf/definitions/Namespace.ts +341 -0
- package/src/amf/definitions/Shapes.ts +414 -0
- package/src/amf/models/AmfDataNode.ts +200 -0
- package/src/amf/shape/README.md +4 -0
- package/src/amf/shape/ShapeBase.ts +160 -0
- package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
- package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
- package/src/models/data/Bindings.ts +186 -0
- package/src/models/data/DataAssociation.ts +226 -29
- package/src/models/data/DataAssociationSchema.ts +38 -0
- package/src/models/data/DataEntity.ts +112 -14
- package/src/models/data/DataFile.ts +3 -0
- package/src/models/data/DataModel.ts +1 -1
- package/src/models/data/DataProperty.ts +191 -47
- package/build/src/models/data/DataPropertySchema.d.ts +0 -125
- package/build/src/models/data/DataPropertySchema.js +0 -33
- package/build/src/models/data/DataPropertySchema.js.map +0 -1
- package/src/models/data/DataPropertySchema.ts +0 -156
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import { Core as JsonCore } from '@api-client/json';
|
|
2
|
+
import { AmfShapeGenerator } from '../../amf/AmfShapeGenerator.js';
|
|
1
3
|
import v4 from '../../lib/uuid.js';
|
|
2
4
|
import { Thing } from "../Thing.js";
|
|
3
5
|
export const Kind = 'Core#DataAssociation';
|
|
6
|
+
/**
|
|
7
|
+
* Describes an association between entities. An association is another property of an entity. The `name` is the name of the
|
|
8
|
+
* property and the value is the associated target or targets.
|
|
9
|
+
*
|
|
10
|
+
* An association can have multiple targets to allow describing the model as `allOf`, `anyOf` and `oneOf` schemas.
|
|
11
|
+
* When the association has only one target, then generated schema cannot have union types.
|
|
12
|
+
*
|
|
13
|
+
* Depending on the schema translation an association can be embedded as a sub-object in the generated schema
|
|
14
|
+
* or can be references via a primary key.
|
|
15
|
+
*/
|
|
4
16
|
export class DataAssociation {
|
|
5
17
|
root;
|
|
6
18
|
kind = Kind;
|
|
7
19
|
key = '';
|
|
8
20
|
/**
|
|
9
|
-
* The description of the data
|
|
21
|
+
* The description of the data association.
|
|
10
22
|
*/
|
|
11
23
|
info = Thing.fromName('');
|
|
12
24
|
/**
|
|
@@ -18,22 +30,59 @@ export class DataAssociation {
|
|
|
18
30
|
*/
|
|
19
31
|
multiple;
|
|
20
32
|
/**
|
|
21
|
-
*
|
|
33
|
+
* Whether the attribute is hidden in the schema (not a part of it).
|
|
34
|
+
* The hidden attribute should only appear in the adapted attribute.
|
|
35
|
+
* Has no effect when added to the "main" attribute.
|
|
36
|
+
*/
|
|
37
|
+
hidden;
|
|
38
|
+
/**
|
|
39
|
+
* The list of keys associated with the entity through this association.
|
|
22
40
|
* An association without a target is considered invalid and discarded when processing the values.
|
|
23
41
|
*/
|
|
24
|
-
|
|
42
|
+
targets = [];
|
|
25
43
|
/**
|
|
26
44
|
* The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)
|
|
27
45
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
46
|
+
* When this is defined then it is used as the schema. When this is not defined it uses
|
|
47
|
+
* referenced entities schemas. Note, changes in the referenced entities may not be propagated
|
|
48
|
+
* to schemas altered by the user.
|
|
49
|
+
*
|
|
50
|
+
* Note, schema can only occur on an adapted property. Has no effect on the "main"
|
|
51
|
+
* property.
|
|
30
52
|
*/
|
|
31
53
|
schema;
|
|
54
|
+
/**
|
|
55
|
+
* The key of the association that is adapted by this association.
|
|
56
|
+
* Adapted associations can manipulate the shape of the schema for the association.
|
|
57
|
+
*
|
|
58
|
+
* Each value defined on the adapted association changes the original value defined on
|
|
59
|
+
* the association.
|
|
60
|
+
*/
|
|
61
|
+
adapts;
|
|
62
|
+
/**
|
|
63
|
+
* Returns true when the association has 0 or 1 targets.
|
|
64
|
+
*/
|
|
65
|
+
get isSingle() {
|
|
66
|
+
return this.targets.length < 2;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates an instance of DataAssociation from a target entity key.
|
|
70
|
+
* Note, this entity will have no name. The default name is used instead.
|
|
71
|
+
*
|
|
72
|
+
* @param root The namespace root.
|
|
73
|
+
* @param target The target entity key.
|
|
74
|
+
*/
|
|
32
75
|
static fromTarget(root, target) {
|
|
33
76
|
const assoc = new DataAssociation(root);
|
|
34
|
-
assoc.
|
|
77
|
+
assoc.targets = [target];
|
|
35
78
|
return assoc;
|
|
36
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates an instance of DataAssociation from a name, without defining a target.
|
|
82
|
+
*
|
|
83
|
+
* @param root The namespace root.
|
|
84
|
+
* @param name The name of the association.
|
|
85
|
+
*/
|
|
37
86
|
static fromName(root, name) {
|
|
38
87
|
const assoc = new DataAssociation(root);
|
|
39
88
|
assoc.info = Thing.fromName(name);
|
|
@@ -55,7 +104,7 @@ export class DataAssociation {
|
|
|
55
104
|
init = {
|
|
56
105
|
kind: Kind,
|
|
57
106
|
key: v4(),
|
|
58
|
-
info: Thing.fromName('').toJSON(),
|
|
107
|
+
info: Thing.fromName('Unnamed association').toJSON(),
|
|
59
108
|
};
|
|
60
109
|
}
|
|
61
110
|
this.new(init);
|
|
@@ -64,7 +113,7 @@ export class DataAssociation {
|
|
|
64
113
|
if (!DataAssociation.isDataAssociation(init)) {
|
|
65
114
|
throw new Error(`Not a data association.`);
|
|
66
115
|
}
|
|
67
|
-
const { info, key = v4(), kind = Kind, schema, multiple, required,
|
|
116
|
+
const { info, key = v4(), kind = Kind, schema, multiple, required, targets, adapts, hidden, } = init;
|
|
68
117
|
this.kind = kind;
|
|
69
118
|
this.key = key;
|
|
70
119
|
if (info) {
|
|
@@ -74,7 +123,7 @@ export class DataAssociation {
|
|
|
74
123
|
this.info = Thing.fromName('');
|
|
75
124
|
}
|
|
76
125
|
if (schema) {
|
|
77
|
-
this.schema =
|
|
126
|
+
this.schema = JsonCore.clone(schema);
|
|
78
127
|
}
|
|
79
128
|
else {
|
|
80
129
|
this.schema = undefined;
|
|
@@ -91,11 +140,23 @@ export class DataAssociation {
|
|
|
91
140
|
else {
|
|
92
141
|
this.required = undefined;
|
|
93
142
|
}
|
|
94
|
-
if (
|
|
95
|
-
this.
|
|
143
|
+
if (Array.isArray(targets)) {
|
|
144
|
+
this.targets = [...targets];
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.targets = [];
|
|
148
|
+
}
|
|
149
|
+
if (typeof hidden === 'boolean') {
|
|
150
|
+
this.hidden = hidden;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.hidden = undefined;
|
|
154
|
+
}
|
|
155
|
+
if (typeof adapts === 'string') {
|
|
156
|
+
this.adapts = adapts;
|
|
96
157
|
}
|
|
97
158
|
else {
|
|
98
|
-
this.
|
|
159
|
+
this.adapts = undefined;
|
|
99
160
|
}
|
|
100
161
|
}
|
|
101
162
|
static isDataAssociation(input) {
|
|
@@ -112,7 +173,7 @@ export class DataAssociation {
|
|
|
112
173
|
info: this.info.toJSON(),
|
|
113
174
|
};
|
|
114
175
|
if (this.schema) {
|
|
115
|
-
result.schema =
|
|
176
|
+
result.schema = JsonCore.clone(this.schema);
|
|
116
177
|
}
|
|
117
178
|
if (typeof this.multiple === 'boolean') {
|
|
118
179
|
result.multiple = this.multiple;
|
|
@@ -120,17 +181,23 @@ export class DataAssociation {
|
|
|
120
181
|
if (typeof this.required === 'boolean') {
|
|
121
182
|
result.required = this.required;
|
|
122
183
|
}
|
|
123
|
-
if (
|
|
124
|
-
result.
|
|
184
|
+
if (Array.isArray(this.targets) && this.targets.length) {
|
|
185
|
+
result.targets = [...this.targets];
|
|
186
|
+
}
|
|
187
|
+
if (typeof this.hidden === 'boolean') {
|
|
188
|
+
result.hidden = this.hidden;
|
|
189
|
+
}
|
|
190
|
+
if (this.adapts) {
|
|
191
|
+
result.adapts = this.adapts;
|
|
125
192
|
}
|
|
126
193
|
return result;
|
|
127
194
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
return root.definitions.entities.
|
|
195
|
+
/**
|
|
196
|
+
* @returns The list of DataEntity definitions for the current targets.
|
|
197
|
+
*/
|
|
198
|
+
getTargets() {
|
|
199
|
+
const { root, targets } = this;
|
|
200
|
+
return root.definitions.entities.filter(item => targets.some(i => i === item.key));
|
|
134
201
|
}
|
|
135
202
|
/**
|
|
136
203
|
* Removes self from the parent entity and the namespace definition.
|
|
@@ -147,5 +214,71 @@ export class DataAssociation {
|
|
|
147
214
|
this.root.definitions.associations.splice(defIndex, 1);
|
|
148
215
|
}
|
|
149
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* @param init The key of an entity, its instance, or schema.
|
|
219
|
+
*/
|
|
220
|
+
addTarget(init) {
|
|
221
|
+
if (typeof init === 'string') {
|
|
222
|
+
this.targets.push(init);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const { key } = init;
|
|
226
|
+
this.targets.push(key);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Removes a target entity from the targets list.
|
|
231
|
+
*
|
|
232
|
+
* @param init The key of an entity, its instance, or schema.
|
|
233
|
+
*/
|
|
234
|
+
removeTarget(init) {
|
|
235
|
+
let key;
|
|
236
|
+
if (typeof init === 'string') {
|
|
237
|
+
key = init;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
key = init.key;
|
|
241
|
+
}
|
|
242
|
+
const index = this.targets.indexOf(key);
|
|
243
|
+
if (index >= 0) {
|
|
244
|
+
this.targets.splice(index, 1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Creates a Property Shape of AMF.
|
|
249
|
+
* The property itself is auto-generated. If the `schema` is defined then it is used
|
|
250
|
+
* as the `range` of the property. Otherwise basic shape is generated for the range.
|
|
251
|
+
*
|
|
252
|
+
* This is a preferred way of reading the AMF shape as this synchronizes changed
|
|
253
|
+
* data properties with the shape definition.
|
|
254
|
+
*
|
|
255
|
+
* @returns AMF property shape definition.
|
|
256
|
+
*/
|
|
257
|
+
toApiShape() {
|
|
258
|
+
const serializer = new AmfShapeGenerator();
|
|
259
|
+
return serializer.associationProperty(this);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* @returns The adapted association, if any
|
|
263
|
+
*/
|
|
264
|
+
readAdapted() {
|
|
265
|
+
const { adapts } = this;
|
|
266
|
+
if (!adapts) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
return this.root.definitions.associations.find(i => i.key === adapts);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Creates new adapted association and associates it with this association.
|
|
273
|
+
* @returns The instance of the created association.
|
|
274
|
+
*/
|
|
275
|
+
createAdapted() {
|
|
276
|
+
const association = new DataAssociation(this.root);
|
|
277
|
+
// disallow defaults as this would influence the schema generation
|
|
278
|
+
association.info.name = undefined;
|
|
279
|
+
this.root.definitions.associations.push(association);
|
|
280
|
+
this.adapts = association.key;
|
|
281
|
+
return association;
|
|
282
|
+
}
|
|
150
283
|
}
|
|
151
284
|
//# sourceMappingURL=DataAssociation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataAssociation.js","sourceRoot":"","sources":["../../../../src/models/data/DataAssociation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACnC,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"DataAssociation.js","sourceRoot":"","sources":["../../../../src/models/data/DataAssociation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACnC,OAAO,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AAI5C,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAC;AA8D3C;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAe;IAyFP;IAxFnB,IAAI,GAAG,IAAI,CAAC;IAEZ,GAAG,GAAG,EAAE,CAAC;IAET;;OAEG;IACH,IAAI,GAAU,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAW;IAEnB;;OAEG;IACH,QAAQ,CAAW;IAEnB;;;;OAIG;IACH,MAAM,CAAW;IAEjB;;;OAGG;IACH,OAAO,GAAa,EAAE,CAAC;IAEvB;;;;;;;;;OASG;IACH,MAAM,CAAqB;IAE3B;;;;;;OAMG;IACH,MAAM,CAAU;IAEhB;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,IAAmB,EAAE,MAAc;QACnD,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,CAAC,OAAO,GAAG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AE;YAC5B,GAAG,GAAG,IAAI,CAAC;SACZ;aAAM;YACL,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;SAChB;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SAC/B;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,UAAU;QACR,MAAM,UAAU,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAC3C,OAAO,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,kEAAkE;QAClE,WAAW,CAAC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC;QAC9B,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -29,4 +29,40 @@ export interface IDataAssociationSchema {
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
embedded?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Describes XML specific serialization.
|
|
34
|
+
*/
|
|
35
|
+
xml?: {
|
|
36
|
+
/**
|
|
37
|
+
* The name of the attribute or a wrapped property to use when serializing the property.
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* <Person fullName="John Doe"></Person>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
name?: string;
|
|
44
|
+
/**
|
|
45
|
+
* When the property is an array (has the `multiple` set to true)
|
|
46
|
+
* then it tells that the list of values should be wrapped with a parent
|
|
47
|
+
* element:
|
|
48
|
+
*
|
|
49
|
+
* ```
|
|
50
|
+
* <Person>
|
|
51
|
+
* <Person fullName="John Doe"></Person>
|
|
52
|
+
* </Person>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Use this with the combination with `name` to describe the name of the wrapped
|
|
56
|
+
* element
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
* <people>
|
|
60
|
+
* <Person fullName="John Doe"></Person>
|
|
61
|
+
* </people>
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* Note, this is mutually exclusive with `attribute`.
|
|
65
|
+
*/
|
|
66
|
+
wrapped?: boolean;
|
|
67
|
+
};
|
|
32
68
|
}
|
|
@@ -4,6 +4,7 @@ import { DataProperty, DataPropertyType } from "./DataProperty.js";
|
|
|
4
4
|
import { DataAssociation } from "./DataAssociation.js";
|
|
5
5
|
import { IBreadcrumb } from "../store/Breadcrumb.js";
|
|
6
6
|
import { DataModel } from "./DataModel.js";
|
|
7
|
+
import { INodeShape, IShapeUnion } from "../../amf/definitions/Shapes.js";
|
|
7
8
|
export declare const Kind = "Core#DataEntity";
|
|
8
9
|
/**
|
|
9
10
|
* Data entity is the smallest description of a data in the system
|
|
@@ -51,13 +52,29 @@ export interface IDataEntity {
|
|
|
51
52
|
* Whether this entity is deprecated.
|
|
52
53
|
*/
|
|
53
54
|
deprecated?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)
|
|
57
|
+
*
|
|
58
|
+
* Schema limitations:
|
|
59
|
+
*
|
|
60
|
+
* - can only occur on an adapted property. Has no effect on the "main" property.
|
|
61
|
+
*/
|
|
62
|
+
schema?: INodeShape;
|
|
63
|
+
/**
|
|
64
|
+
* The key of the entity that is adapted by this entity.
|
|
65
|
+
* Adapted entities can manipulate the shape of the schema for the entity.
|
|
66
|
+
*
|
|
67
|
+
* Each value defined on the adapted entity changes the original value defined on
|
|
68
|
+
* the entity.
|
|
69
|
+
*/
|
|
70
|
+
adapts?: string;
|
|
54
71
|
}
|
|
55
72
|
/**
|
|
56
73
|
* Data entity is the smallest description of a data in the system
|
|
57
74
|
* It contains properties and associations. At least one entity describe a data model.
|
|
58
75
|
*/
|
|
59
76
|
export declare class DataEntity {
|
|
60
|
-
|
|
77
|
+
root: DataNamespace;
|
|
61
78
|
kind: string;
|
|
62
79
|
key: string;
|
|
63
80
|
/**
|
|
@@ -96,6 +113,14 @@ export declare class DataEntity {
|
|
|
96
113
|
* Whether this entity is deprecated.
|
|
97
114
|
*/
|
|
98
115
|
deprecated?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The key of the entity that is adapted by this entity.
|
|
118
|
+
* Adapted entities can manipulate the shape of the schema for the entity.
|
|
119
|
+
*
|
|
120
|
+
* Each value defined on the adapted entity changes the original value defined on
|
|
121
|
+
* the entity.
|
|
122
|
+
*/
|
|
123
|
+
adapts?: string;
|
|
99
124
|
static fromName(root: DataNamespace, name: string): DataEntity;
|
|
100
125
|
/**
|
|
101
126
|
* @param input The data entity definition to restore.
|
|
@@ -111,7 +136,7 @@ export declare class DataEntity {
|
|
|
111
136
|
* @param type The type of the property
|
|
112
137
|
* @returns The created property
|
|
113
138
|
*/
|
|
114
|
-
addTypedProperty(type: DataPropertyType): DataProperty;
|
|
139
|
+
addTypedProperty(type: DataPropertyType, name?: string): DataProperty;
|
|
115
140
|
/**
|
|
116
141
|
* Creates a property with a passed type.
|
|
117
142
|
* @param name The name of the property.
|
|
@@ -134,7 +159,7 @@ export declare class DataEntity {
|
|
|
134
159
|
* @param target The target entity key of the association
|
|
135
160
|
* @returns The created association
|
|
136
161
|
*/
|
|
137
|
-
addTargetAssociation(target: string): DataAssociation;
|
|
162
|
+
addTargetAssociation(target: string, name?: string): DataAssociation;
|
|
138
163
|
/**
|
|
139
164
|
* Removes an association from the entity and namespace definitions.
|
|
140
165
|
* @param key The key of the association to remove.
|
|
@@ -143,8 +168,9 @@ export declare class DataEntity {
|
|
|
143
168
|
/**
|
|
144
169
|
* Reads the list of parents for the entity, inside the root namespace. The computed list contains the list of all
|
|
145
170
|
* parents in the inheritance chain in no particular order.
|
|
171
|
+
* @param recursive Whether to include parent parents as well.
|
|
146
172
|
*/
|
|
147
|
-
getComputedParents(): DataEntity[];
|
|
173
|
+
getComputedParents(recursive?: boolean): DataEntity[];
|
|
148
174
|
/**
|
|
149
175
|
* Computes list of all children, inside the root namespace, that extends this entity.
|
|
150
176
|
* The children are not ordered.
|
|
@@ -214,4 +240,28 @@ export declare class DataEntity {
|
|
|
214
240
|
* @param tag The tag to remove.
|
|
215
241
|
*/
|
|
216
242
|
removeTag(tag: string): void;
|
|
243
|
+
/**
|
|
244
|
+
* Creates a Shape of AMF.
|
|
245
|
+
* The property itself is auto-generated. If the `schema` is defined then it is used
|
|
246
|
+
* as the `range` of the property. Otherwise basic shape is generated for the range.
|
|
247
|
+
*
|
|
248
|
+
* This is a preferred way of reading the AMF shape as this synchronizes changed
|
|
249
|
+
* data properties with the shape definition.
|
|
250
|
+
*
|
|
251
|
+
* @returns AMF property shape definition.
|
|
252
|
+
*/
|
|
253
|
+
toApiShape(): IShapeUnion;
|
|
254
|
+
/**
|
|
255
|
+
* Reads the schema of the Entity and generates an example for it.
|
|
256
|
+
*/
|
|
257
|
+
toExample(mime: string): string | number | boolean | null | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* @returns The adapted entity, if any
|
|
260
|
+
*/
|
|
261
|
+
readAdapted(): DataEntity | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* Creates new adapted entity and associates it with this entity.
|
|
264
|
+
* @returns The instance of the created entity.
|
|
265
|
+
*/
|
|
266
|
+
createAdapted(): DataEntity;
|
|
217
267
|
}
|
|
@@ -2,6 +2,8 @@ import { Thing } from "../Thing.js";
|
|
|
2
2
|
import v4 from '../../lib/uuid.js';
|
|
3
3
|
import { DataProperty } from "./DataProperty.js";
|
|
4
4
|
import { DataAssociation } from "./DataAssociation.js";
|
|
5
|
+
import { AmfShapeGenerator } from "../../amf/AmfShapeGenerator.js";
|
|
6
|
+
import { ApiSchemaGenerator } from "../../amf/ApiSchemaGenerator.js";
|
|
5
7
|
export const Kind = 'Core#DataEntity';
|
|
6
8
|
/**
|
|
7
9
|
* Data entity is the smallest description of a data in the system
|
|
@@ -47,6 +49,14 @@ export class DataEntity {
|
|
|
47
49
|
* Whether this entity is deprecated.
|
|
48
50
|
*/
|
|
49
51
|
deprecated;
|
|
52
|
+
/**
|
|
53
|
+
* The key of the entity that is adapted by this entity.
|
|
54
|
+
* Adapted entities can manipulate the shape of the schema for the entity.
|
|
55
|
+
*
|
|
56
|
+
* Each value defined on the adapted entity changes the original value defined on
|
|
57
|
+
* the entity.
|
|
58
|
+
*/
|
|
59
|
+
adapts;
|
|
50
60
|
static fromName(root, name) {
|
|
51
61
|
const entity = new DataEntity(root);
|
|
52
62
|
entity.info = Thing.fromName(name);
|
|
@@ -77,7 +87,7 @@ export class DataEntity {
|
|
|
77
87
|
if (!DataEntity.isDataEntity(init)) {
|
|
78
88
|
throw new Error(`Not a data entity.`);
|
|
79
89
|
}
|
|
80
|
-
const { info, key = v4(), kind = Kind, tags, taxonomy, parents, properties, associations, deprecated } = init;
|
|
90
|
+
const { info, key = v4(), kind = Kind, tags, taxonomy, parents, properties, associations, deprecated, adapts, } = init;
|
|
81
91
|
this.kind = kind;
|
|
82
92
|
this.key = key;
|
|
83
93
|
if (info) {
|
|
@@ -128,6 +138,12 @@ export class DataEntity {
|
|
|
128
138
|
else {
|
|
129
139
|
this.deprecated = undefined;
|
|
130
140
|
}
|
|
141
|
+
if (typeof adapts === 'string') {
|
|
142
|
+
this.adapts = adapts;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.adapts = undefined;
|
|
146
|
+
}
|
|
131
147
|
}
|
|
132
148
|
static isDataEntity(input) {
|
|
133
149
|
const typed = input;
|
|
@@ -160,6 +176,9 @@ export class DataEntity {
|
|
|
160
176
|
if (typeof this.deprecated === 'boolean') {
|
|
161
177
|
result.deprecated = this.deprecated;
|
|
162
178
|
}
|
|
179
|
+
if (this.adapts) {
|
|
180
|
+
result.adapts = this.adapts;
|
|
181
|
+
}
|
|
163
182
|
return result;
|
|
164
183
|
}
|
|
165
184
|
_readAssociation(key) {
|
|
@@ -173,8 +192,11 @@ export class DataEntity {
|
|
|
173
192
|
* @param type The type of the property
|
|
174
193
|
* @returns The created property
|
|
175
194
|
*/
|
|
176
|
-
addTypedProperty(type) {
|
|
195
|
+
addTypedProperty(type, name) {
|
|
177
196
|
const property = DataProperty.fromType(this.root, type);
|
|
197
|
+
if (name) {
|
|
198
|
+
property.info.name = name;
|
|
199
|
+
}
|
|
178
200
|
this.root.definitions.properties.push(property);
|
|
179
201
|
this.properties.push(property);
|
|
180
202
|
return property;
|
|
@@ -221,8 +243,11 @@ export class DataEntity {
|
|
|
221
243
|
* @param target The target entity key of the association
|
|
222
244
|
* @returns The created association
|
|
223
245
|
*/
|
|
224
|
-
addTargetAssociation(target) {
|
|
246
|
+
addTargetAssociation(target, name) {
|
|
225
247
|
const result = DataAssociation.fromTarget(this.root, target);
|
|
248
|
+
if (name) {
|
|
249
|
+
result.info.name = name;
|
|
250
|
+
}
|
|
226
251
|
this.root.definitions.associations.push(result);
|
|
227
252
|
this.associations.push(result);
|
|
228
253
|
return result;
|
|
@@ -245,15 +270,18 @@ export class DataEntity {
|
|
|
245
270
|
/**
|
|
246
271
|
* Reads the list of parents for the entity, inside the root namespace. The computed list contains the list of all
|
|
247
272
|
* parents in the inheritance chain in no particular order.
|
|
273
|
+
* @param recursive Whether to include parent parents as well.
|
|
248
274
|
*/
|
|
249
|
-
getComputedParents() {
|
|
275
|
+
getComputedParents(recursive) {
|
|
250
276
|
const { entities } = this.root.definitions;
|
|
251
277
|
let result = [];
|
|
252
278
|
this.parents.forEach((key) => {
|
|
253
279
|
const parent = entities.find(i => i.key === key);
|
|
254
280
|
if (parent) {
|
|
255
281
|
result.push(parent);
|
|
256
|
-
|
|
282
|
+
if (recursive) {
|
|
283
|
+
result = result.concat(parent.getComputedParents());
|
|
284
|
+
}
|
|
257
285
|
}
|
|
258
286
|
});
|
|
259
287
|
return result;
|
|
@@ -274,10 +302,10 @@ export class DataEntity {
|
|
|
274
302
|
const { entities } = root.definitions;
|
|
275
303
|
const result = [];
|
|
276
304
|
associations.forEach((assoc) => {
|
|
277
|
-
if (!assoc.
|
|
305
|
+
if (!assoc.targets.length) {
|
|
278
306
|
return;
|
|
279
307
|
}
|
|
280
|
-
const entity = entities.find(i => i.key
|
|
308
|
+
const entity = entities.find(i => assoc.targets.includes(i.key));
|
|
281
309
|
if (entity) {
|
|
282
310
|
result.push(entity);
|
|
283
311
|
}
|
|
@@ -376,7 +404,7 @@ export class DataEntity {
|
|
|
376
404
|
const graph = {};
|
|
377
405
|
const { associations, entities } = this.root.definitions;
|
|
378
406
|
for (const assoc of associations) {
|
|
379
|
-
if (!assoc.
|
|
407
|
+
if (!assoc.targets.length) {
|
|
380
408
|
continue;
|
|
381
409
|
}
|
|
382
410
|
const srcEntity = entities.find(i => i.associations.some(a => a === assoc));
|
|
@@ -386,7 +414,7 @@ export class DataEntity {
|
|
|
386
414
|
if (!graph[srcEntity.key]) {
|
|
387
415
|
graph[srcEntity.key] = [];
|
|
388
416
|
}
|
|
389
|
-
graph[srcEntity.key].
|
|
417
|
+
graph[srcEntity.key].splice(0, 0, ...assoc.targets);
|
|
390
418
|
}
|
|
391
419
|
return graph;
|
|
392
420
|
}
|
|
@@ -462,5 +490,53 @@ export class DataEntity {
|
|
|
462
490
|
tags.splice(index, 1);
|
|
463
491
|
}
|
|
464
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Creates a Shape of AMF.
|
|
495
|
+
* The property itself is auto-generated. If the `schema` is defined then it is used
|
|
496
|
+
* as the `range` of the property. Otherwise basic shape is generated for the range.
|
|
497
|
+
*
|
|
498
|
+
* This is a preferred way of reading the AMF shape as this synchronizes changed
|
|
499
|
+
* data properties with the shape definition.
|
|
500
|
+
*
|
|
501
|
+
* @returns AMF property shape definition.
|
|
502
|
+
*/
|
|
503
|
+
toApiShape() {
|
|
504
|
+
const serializer = new AmfShapeGenerator();
|
|
505
|
+
return serializer.entity(this);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Reads the schema of the Entity and generates an example for it.
|
|
509
|
+
*/
|
|
510
|
+
toExample(mime) {
|
|
511
|
+
const shape = this.toApiShape();
|
|
512
|
+
const generator = new ApiSchemaGenerator(mime, {
|
|
513
|
+
renderExamples: true,
|
|
514
|
+
renderMocked: true,
|
|
515
|
+
renderOptional: true,
|
|
516
|
+
});
|
|
517
|
+
return generator.generate(shape);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* @returns The adapted entity, if any
|
|
521
|
+
*/
|
|
522
|
+
readAdapted() {
|
|
523
|
+
const { adapts } = this;
|
|
524
|
+
if (!adapts) {
|
|
525
|
+
return undefined;
|
|
526
|
+
}
|
|
527
|
+
return this.root.definitions.entities.find(i => i.key === adapts);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Creates new adapted entity and associates it with this entity.
|
|
531
|
+
* @returns The instance of the created entity.
|
|
532
|
+
*/
|
|
533
|
+
createAdapted() {
|
|
534
|
+
const entity = new DataEntity(this.root);
|
|
535
|
+
// disallow defaults as this would influence the schema generation
|
|
536
|
+
entity.info.name = undefined;
|
|
537
|
+
this.root.definitions.entities.push(entity);
|
|
538
|
+
this.adapts = entity.key;
|
|
539
|
+
return entity;
|
|
540
|
+
}
|
|
465
541
|
}
|
|
466
542
|
//# sourceMappingURL=DataEntity.js.map
|