@api-client/core 0.6.13 → 0.6.16
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/Thing.d.ts +17 -0
- package/build/src/models/Thing.js +19 -1
- package/build/src/models/Thing.js.map +1 -1
- 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 +76 -4
- package/build/src/models/data/DataEntity.js +136 -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/DataNamespace.d.ts +6 -0
- package/build/src/models/data/DataNamespace.js +11 -1
- package/build/src/models/data/DataNamespace.js.map +1 -1
- package/build/src/models/data/DataProperty.d.ts +131 -36
- package/build/src/models/data/DataProperty.js +200 -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/Thing.ts +25 -1
- 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 +170 -13
- package/src/models/data/DataFile.ts +3 -0
- package/src/models/data/DataModel.ts +1 -1
- package/src/models/data/DataNamespace.ts +16 -1
- package/src/models/data/DataProperty.ts +250 -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
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { AnyTypes, ArrayTypes, FileTypes, NodeTypes, PropertyTypes, RecursiveTypes, ScalarTypes, TupleTypes, UnionTypes, XmlSerializationTypes } from '../AmfTypes.js';
|
|
2
|
+
import { ApiDocumentation, ApiDocumentSourceMaps } from './Api.js';
|
|
3
|
+
import { IDomainProperty } from './Base.js';
|
|
4
|
+
|
|
5
|
+
export type IShapeUnion = IScalarShape | INodeShape | IUnionShape | IFileShape | ISchemaShape | IAnyShape | IArrayShape | ITupleShape | IRecursiveShape;
|
|
6
|
+
|
|
7
|
+
export interface IAssociationShape {
|
|
8
|
+
/**
|
|
9
|
+
* This is custom property not available in AMF and used with data associations.
|
|
10
|
+
*
|
|
11
|
+
* Whether the target entity should be embedded under the property name.
|
|
12
|
+
* When false, this association is just an information that one entity depend on another.
|
|
13
|
+
* When true, it changes the definition of the schema having this association to
|
|
14
|
+
* add the target schema properties inline with this property.
|
|
15
|
+
*
|
|
16
|
+
* **When true**
|
|
17
|
+
*
|
|
18
|
+
* ```javascript
|
|
19
|
+
* // generated schema for `address` association
|
|
20
|
+
* {
|
|
21
|
+
* "name": "example value",
|
|
22
|
+
* "address": {
|
|
23
|
+
* "city": "example value",
|
|
24
|
+
* ...
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* **When false**
|
|
30
|
+
*
|
|
31
|
+
* ```javascript
|
|
32
|
+
* // generated schema for `address` association
|
|
33
|
+
* {
|
|
34
|
+
* "name": "example value",
|
|
35
|
+
* "address": "the key of the referenced schema"
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
linked?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* When the association has multiple targets the union type should be
|
|
42
|
+
* set to describe which union this is.
|
|
43
|
+
*
|
|
44
|
+
* Possible values are:
|
|
45
|
+
*
|
|
46
|
+
* - allOf - To validate against `allOf`, the given data must be valid against all of the given sub-schemas. When generating, it's a sum of all properties.
|
|
47
|
+
* - anyOf - To validate against `anyOf`, the given data must be valid against any (one or more) of the given sub-schemas. When generation a schema, it takes first union schema.
|
|
48
|
+
* - oneOf - To validate against `oneOf`, the given data must be valid against exactly one of the given sub-schemas. It behaves the same as `oneOf` when generating a schema
|
|
49
|
+
* - not - The `not` keyword declares that an instance validates if it doesn’t validate against the given sub-schema. It has no use when generating a schema.
|
|
50
|
+
*
|
|
51
|
+
* @default anyOf
|
|
52
|
+
*/
|
|
53
|
+
unionType?: 'allOf' | 'anyOf' | 'oneOf' | 'not';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IDataExample extends IDomainProperty {
|
|
57
|
+
name?: string;
|
|
58
|
+
displayName?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
/**
|
|
61
|
+
* This is the "raw" property of AMF
|
|
62
|
+
*/
|
|
63
|
+
value?: string;
|
|
64
|
+
structuredValue?: IDataNodeUnion;
|
|
65
|
+
strict: boolean;
|
|
66
|
+
mediaType?: string;
|
|
67
|
+
location?: string;
|
|
68
|
+
sourceMaps?: ApiDocumentSourceMaps;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function xmlSerializer(id: string): IXmlSerializer {
|
|
72
|
+
return {
|
|
73
|
+
id: `xml-serializer-${id}`,
|
|
74
|
+
types: XmlSerializationTypes,
|
|
75
|
+
customDomainProperties: [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function shape(id: string): IShape {
|
|
80
|
+
const result: IShape = {
|
|
81
|
+
id,
|
|
82
|
+
types: [],
|
|
83
|
+
values: [],
|
|
84
|
+
inherits: [],
|
|
85
|
+
or: [],
|
|
86
|
+
and: [],
|
|
87
|
+
xone: [],
|
|
88
|
+
customDomainProperties: [],
|
|
89
|
+
};
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function anyShape(id: string): IAnyShape {
|
|
94
|
+
const result: IAnyShape = {
|
|
95
|
+
...shape(id),
|
|
96
|
+
types: AnyTypes,
|
|
97
|
+
examples: [],
|
|
98
|
+
xmlSerialization: xmlSerializer(id),
|
|
99
|
+
};
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function nodeShape(id: string): INodeShape {
|
|
104
|
+
const result = anyShape(id);
|
|
105
|
+
result.types = NodeTypes;
|
|
106
|
+
result.id = `node-shape-${id}`;
|
|
107
|
+
return {
|
|
108
|
+
...result,
|
|
109
|
+
properties: [],
|
|
110
|
+
dependencies: [],
|
|
111
|
+
customShapeProperties: [],
|
|
112
|
+
customShapePropertyDefinitions: [],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function scalarShape(id: string): IScalarShape {
|
|
117
|
+
const result = anyShape(id);
|
|
118
|
+
result.id = `scalar-shape-${id}`;
|
|
119
|
+
result.types = ScalarTypes;
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function unionShape(id: string): IUnionShape {
|
|
124
|
+
const result = anyShape(id);
|
|
125
|
+
result.id = `union-shape-${id}`;
|
|
126
|
+
result.types = UnionTypes;
|
|
127
|
+
return { ...result, anyOf: [] };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function fileShape(id: string): IFileShape {
|
|
131
|
+
const result = anyShape(id);
|
|
132
|
+
result.id = `file-shape-${id}`;
|
|
133
|
+
result.types = FileTypes;
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function arrayShape(id: string): IArrayShape {
|
|
138
|
+
const result = anyShape(id);
|
|
139
|
+
result.id = `array-shape-${id}`;
|
|
140
|
+
result.types = ArrayTypes;
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function tupleShape(id: string): ITupleShape {
|
|
145
|
+
const result = anyShape(id);
|
|
146
|
+
result.id = `tuple-shape-${id}`;
|
|
147
|
+
result.types = TupleTypes;
|
|
148
|
+
return { ...result, items: [] };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function propertyShape(id: string): IPropertyShape {
|
|
152
|
+
const result = anyShape(id);
|
|
153
|
+
result.types = PropertyTypes;
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function recursiveShape(id: string, fixedId?: string): IRecursiveShape {
|
|
158
|
+
const result: IRecursiveShape = {
|
|
159
|
+
...shape(id),
|
|
160
|
+
id: `recursive-${id}`,
|
|
161
|
+
types: RecursiveTypes,
|
|
162
|
+
fixPoint: fixedId || '',
|
|
163
|
+
};
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface IShape extends IDomainProperty {
|
|
168
|
+
/**
|
|
169
|
+
* Enum values for this shape.
|
|
170
|
+
*/
|
|
171
|
+
values: IDataNodeUnion[];
|
|
172
|
+
/**
|
|
173
|
+
* The list of shapes that this shape inherits from
|
|
174
|
+
*/
|
|
175
|
+
inherits: IShapeUnion[];
|
|
176
|
+
/**
|
|
177
|
+
* The `anyOf` union type.
|
|
178
|
+
*/
|
|
179
|
+
or: IShapeUnion[];
|
|
180
|
+
/**
|
|
181
|
+
* The `allOf` union type.
|
|
182
|
+
*/
|
|
183
|
+
and: IShapeUnion[];
|
|
184
|
+
/**
|
|
185
|
+
* The `oneOf` union type.
|
|
186
|
+
*/
|
|
187
|
+
xone: IShapeUnion[];
|
|
188
|
+
/**
|
|
189
|
+
* The name of the shape in the system.
|
|
190
|
+
*/
|
|
191
|
+
name?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The display name for the shape in the UI.
|
|
194
|
+
*/
|
|
195
|
+
displayName?: string;
|
|
196
|
+
/**
|
|
197
|
+
* The description of the shape.
|
|
198
|
+
*/
|
|
199
|
+
description?: string;
|
|
200
|
+
/**
|
|
201
|
+
* The default value encoded as a string
|
|
202
|
+
*/
|
|
203
|
+
defaultValueStr?: string;
|
|
204
|
+
/**
|
|
205
|
+
* The description of the default value of the shape.
|
|
206
|
+
*/
|
|
207
|
+
defaultValue?: IDataNodeUnion;
|
|
208
|
+
/**
|
|
209
|
+
* Whether the shape is deprecated.
|
|
210
|
+
*/
|
|
211
|
+
deprecated?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Whether the shape is a read only shape (disallow writes to the value)
|
|
214
|
+
*/
|
|
215
|
+
readOnly?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Whether the shape can only be written to (disallow reading the value)
|
|
218
|
+
*/
|
|
219
|
+
writeOnly?: boolean;
|
|
220
|
+
not?: IShapeUnion;
|
|
221
|
+
/**
|
|
222
|
+
* A label that appeared on a link.
|
|
223
|
+
*/
|
|
224
|
+
linkLabel?: string;
|
|
225
|
+
sourceMaps?: ApiDocumentSourceMaps;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A property of an API operation.
|
|
230
|
+
*/
|
|
231
|
+
export interface IPropertyShape<T = IShapeUnion> extends IShape {
|
|
232
|
+
/**
|
|
233
|
+
* The path of the property. Essentially, it is link generated by the AMF library
|
|
234
|
+
* where the fragment part is the name of the property.
|
|
235
|
+
*/
|
|
236
|
+
path?: string;
|
|
237
|
+
/**
|
|
238
|
+
* The parameter shape definition
|
|
239
|
+
*/
|
|
240
|
+
range?: T;
|
|
241
|
+
/**
|
|
242
|
+
* When > 0 then the parameter is required.
|
|
243
|
+
*/
|
|
244
|
+
minCount?: number;
|
|
245
|
+
maxCount?: number;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface IAnyShape extends IShape {
|
|
249
|
+
documentation?: ApiDocumentation;
|
|
250
|
+
/**
|
|
251
|
+
* Description of how the shape should be serialized as XML.
|
|
252
|
+
*/
|
|
253
|
+
xmlSerialization: IXmlSerializer;
|
|
254
|
+
/**
|
|
255
|
+
* Examples defined for the shape.
|
|
256
|
+
*/
|
|
257
|
+
examples: IDataExample[];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Describes an object shape.
|
|
262
|
+
*/
|
|
263
|
+
export interface INodeShape extends IAnyShape {
|
|
264
|
+
minProperties?: number;
|
|
265
|
+
maxProperties?: number;
|
|
266
|
+
closed?: boolean;
|
|
267
|
+
customShapeProperties: string[];
|
|
268
|
+
customShapePropertyDefinitions: string[];
|
|
269
|
+
discriminator?: string;
|
|
270
|
+
discriminatorValue?: string;
|
|
271
|
+
properties: IPropertyShape[];
|
|
272
|
+
dependencies: string[];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface IXmlSerializer extends IDomainProperty {
|
|
276
|
+
/**
|
|
277
|
+
* Whether this property should be represented as an attribute of the parent shape.
|
|
278
|
+
*
|
|
279
|
+
* ```
|
|
280
|
+
* <Person name="John Doe"></Person>
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
attribute?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* When the property is an array (has the `multiple` set to true in the data model)
|
|
286
|
+
* then it tells that the list of values should be wrapped with a parent
|
|
287
|
+
* element:
|
|
288
|
+
*
|
|
289
|
+
* ```
|
|
290
|
+
* <Person>
|
|
291
|
+
* <Person fullName="John Doe"></Person>
|
|
292
|
+
* <Person fullName="Other Doe"></Person>
|
|
293
|
+
* </Person>
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* Use this with the combination with `name` to describe the name of the wrapped
|
|
297
|
+
* element
|
|
298
|
+
*
|
|
299
|
+
* ```
|
|
300
|
+
* <people>
|
|
301
|
+
* <Person fullName="John Doe"></Person>
|
|
302
|
+
* </people>
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* Note, this is mutually exclusive with `attribute`.
|
|
306
|
+
*/
|
|
307
|
+
wrapped?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* The name of the attribute or a wrapped property to use when serializing the property.
|
|
310
|
+
*
|
|
311
|
+
* Attribute name
|
|
312
|
+
* ```xml
|
|
313
|
+
* <Person fullName="John Doe"></Person>
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* Wrapped name
|
|
317
|
+
* ```xml
|
|
318
|
+
* <people>
|
|
319
|
+
* <Person name="John Doe"></Person>
|
|
320
|
+
* </people>
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
name?: string;
|
|
324
|
+
/**
|
|
325
|
+
* The XML namespace to use.
|
|
326
|
+
*
|
|
327
|
+
* ```xml
|
|
328
|
+
* <Person ns:name="John Doe"></Person>
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
namespace?: string;
|
|
332
|
+
/**
|
|
333
|
+
* Name prefix
|
|
334
|
+
*
|
|
335
|
+
* ```xml
|
|
336
|
+
* <ns:Person name="John Doe"></ns:Person>
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
prefix?: string;
|
|
340
|
+
sourceMaps?: ApiDocumentSourceMaps;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface IScalarShape extends IAnyShape {
|
|
344
|
+
dataType?: string;
|
|
345
|
+
pattern?: string;
|
|
346
|
+
minLength?: number;
|
|
347
|
+
maxLength?: number;
|
|
348
|
+
minimum?: number;
|
|
349
|
+
maximum?: number;
|
|
350
|
+
exclusiveMinimum?: boolean;
|
|
351
|
+
exclusiveMaximum?: boolean;
|
|
352
|
+
format?: string;
|
|
353
|
+
multipleOf?: number;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export interface IFileShape extends IAnyShape {
|
|
357
|
+
fileTypes?: string[];
|
|
358
|
+
pattern?: string;
|
|
359
|
+
minLength?: number;
|
|
360
|
+
maxLength?: number;
|
|
361
|
+
minimum?: number;
|
|
362
|
+
maximum?: number;
|
|
363
|
+
exclusiveMinimum?: boolean;
|
|
364
|
+
exclusiveMaximum?: boolean;
|
|
365
|
+
format?: string;
|
|
366
|
+
multipleOf?: number;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface ISchemaShape extends IAnyShape {
|
|
370
|
+
mediaType?: string;
|
|
371
|
+
raw?: string;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface IUnionShape extends IAnyShape {
|
|
375
|
+
anyOf: IShapeUnion[];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface IDataArrangeShape extends IAnyShape {
|
|
379
|
+
minItems?: number;
|
|
380
|
+
maxItems?: number;
|
|
381
|
+
uniqueItems?: boolean;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface IArrayShape<T = IShapeUnion> extends IDataArrangeShape {
|
|
385
|
+
items?: T;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export interface ITupleShape<T = IShapeUnion> extends IDataArrangeShape {
|
|
389
|
+
items: T[];
|
|
390
|
+
additionalItems?: boolean;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export interface IRecursiveShape extends IShape {
|
|
394
|
+
fixPoint: string;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface IDataNode extends IDomainProperty {
|
|
398
|
+
name?: string;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface IObjectNode extends IDataNode {
|
|
402
|
+
properties: { [key: string]: IDataNodeUnion };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export interface IScalarNode extends IDataNode {
|
|
406
|
+
value?: string;
|
|
407
|
+
dataType?: string;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface IArrayNode extends IDataNode {
|
|
411
|
+
members: IDataNodeUnion[];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export type IDataNodeUnion = IDataNode | IObjectNode | IScalarNode | IArrayNode;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import v4 from '../../lib/uuid.js';
|
|
2
|
+
import { ArrayNodeTypes, ObjectNodeTypes, ScalarNodeTypes } from '../AmfTypes.js';
|
|
3
|
+
import { ICustomDomainProperty } from '../definitions/Base.js';
|
|
4
|
+
import { AmfNamespace } from '../definitions/Namespace.js';
|
|
5
|
+
import { IArrayNode, IDataNode, IDataNodeUnion, IObjectNode, IScalarNode } from '../definitions/Shapes.js';
|
|
6
|
+
|
|
7
|
+
export type IDataNodeInit = 'scalar' | 'object' | 'array';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A class that manipulates the AMF's DataNode node.
|
|
11
|
+
*/
|
|
12
|
+
export class AmfDataNode {
|
|
13
|
+
id = v4();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* AMF domain types.
|
|
17
|
+
* This is set in the constructor
|
|
18
|
+
*/
|
|
19
|
+
types: string[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The name of this data node.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Set when the object node type
|
|
28
|
+
*/
|
|
29
|
+
properties?: { [key: string]: AmfDataNode };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Scalar type value. Always a string.
|
|
33
|
+
*/
|
|
34
|
+
value?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Scalar type value data type.
|
|
38
|
+
*/
|
|
39
|
+
dataType?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Set when the type is array.
|
|
43
|
+
*/
|
|
44
|
+
members?: AmfDataNode[];
|
|
45
|
+
|
|
46
|
+
customDomainProperties: ICustomDomainProperty[] = [];
|
|
47
|
+
|
|
48
|
+
static scalar(value: string, type: string): AmfDataNode {
|
|
49
|
+
const result = new AmfDataNode('scalar');
|
|
50
|
+
result.value = value;
|
|
51
|
+
result.dataType = type;
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
constructor(init: IDataNodeUnion | IDataNodeInit) {
|
|
56
|
+
if (typeof init === 'string') {
|
|
57
|
+
if (init === 'scalar') {
|
|
58
|
+
this.types = ScalarNodeTypes;
|
|
59
|
+
} else if (init === 'array') {
|
|
60
|
+
this.types = ArrayNodeTypes;
|
|
61
|
+
} else if (init === 'object') {
|
|
62
|
+
this.types = ObjectNodeTypes;
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error(`Invalid data node init option: ${init}`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!init) {
|
|
69
|
+
throw new Error(`Expected an initialization option.`);
|
|
70
|
+
}
|
|
71
|
+
const union = init as IDataNodeUnion;
|
|
72
|
+
const { id, types, customDomainProperties } = union;
|
|
73
|
+
this.id = id;
|
|
74
|
+
this.types = types;
|
|
75
|
+
this.customDomainProperties = customDomainProperties;
|
|
76
|
+
if (types.includes(AmfNamespace.aml.vocabularies.data.Scalar)) {
|
|
77
|
+
const typed = union as IScalarNode;
|
|
78
|
+
this.value = typed.value;
|
|
79
|
+
this.dataType = typed.dataType;
|
|
80
|
+
} else if (types.includes(AmfNamespace.aml.vocabularies.data.Object)) {
|
|
81
|
+
const typed = union as IObjectNode;
|
|
82
|
+
this.properties = {};
|
|
83
|
+
Object.keys(typed.properties).forEach((key) => {
|
|
84
|
+
const instance = new AmfDataNode(typed.properties[key]);
|
|
85
|
+
this.properties![key] = instance;
|
|
86
|
+
});
|
|
87
|
+
} else if (types.includes(AmfNamespace.aml.vocabularies.data.Array)) {
|
|
88
|
+
const typed = union as IArrayNode;
|
|
89
|
+
this.members = [];
|
|
90
|
+
if (Array.isArray(typed.members)) {
|
|
91
|
+
typed.members.forEach((member) => {
|
|
92
|
+
const instance = new AmfDataNode(member);
|
|
93
|
+
this.members!.push(instance);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
toJSON(): IDataNodeUnion {
|
|
100
|
+
const { id, customDomainProperties, types, name } = this;
|
|
101
|
+
const result: IDataNode = {
|
|
102
|
+
id,
|
|
103
|
+
types,
|
|
104
|
+
customDomainProperties,
|
|
105
|
+
};
|
|
106
|
+
if (name) {
|
|
107
|
+
result.name = name;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (types.includes(AmfNamespace.aml.vocabularies.data.Scalar)) {
|
|
111
|
+
const typed = result as IScalarNode;
|
|
112
|
+
typed.dataType = this.dataType;
|
|
113
|
+
typed.value = this.value;
|
|
114
|
+
} else if (types.includes(AmfNamespace.aml.vocabularies.data.Object)) {
|
|
115
|
+
const typed = result as IObjectNode;
|
|
116
|
+
typed.properties = {};
|
|
117
|
+
if (this.properties) {
|
|
118
|
+
Object.keys(this.properties).forEach((key) => {
|
|
119
|
+
typed.properties[key] = this.properties![key].toJSON();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
} else if (types.includes(AmfNamespace.aml.vocabularies.data.Array)) {
|
|
123
|
+
const typed = result as IArrayNode;
|
|
124
|
+
typed.members = [];
|
|
125
|
+
if (this.members) {
|
|
126
|
+
this.members.forEach((member) => {
|
|
127
|
+
typed.members.push(member.toJSON());
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Adds a member to the list of members.
|
|
136
|
+
* It throws when this is not an array node.
|
|
137
|
+
*
|
|
138
|
+
* @param init The member to add.
|
|
139
|
+
*/
|
|
140
|
+
addMember(init: AmfDataNode): void {
|
|
141
|
+
if (!this.types.includes(AmfNamespace.aml.vocabularies.data.Array)) {
|
|
142
|
+
throw new Error(`Not an ArrayNode.`);
|
|
143
|
+
}
|
|
144
|
+
if (!this.members) {
|
|
145
|
+
this.members = [];
|
|
146
|
+
}
|
|
147
|
+
this.members.push(init);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Removes a member from the list of members.
|
|
152
|
+
* It throws when this is not an array node.
|
|
153
|
+
*
|
|
154
|
+
* @param id The domain id of the member to remove.
|
|
155
|
+
*/
|
|
156
|
+
removeMember(id: string): void {
|
|
157
|
+
if (!this.types.includes(AmfNamespace.aml.vocabularies.data.Array)) {
|
|
158
|
+
throw new Error(`Not an ArrayNode.`);
|
|
159
|
+
}
|
|
160
|
+
if (!this.members) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const index = this.members.findIndex(i => i.id === id);
|
|
164
|
+
if (index >= 0) {
|
|
165
|
+
this.members.splice(index, 1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Adds a property to the ObjectNode.
|
|
171
|
+
* It throws when this is not an object node.
|
|
172
|
+
*
|
|
173
|
+
* @param name The name of the property.
|
|
174
|
+
* @param value The instance of the DataNode to set.
|
|
175
|
+
*/
|
|
176
|
+
addProperty(name: string, value: AmfDataNode): void {
|
|
177
|
+
if (!this.types.includes(AmfNamespace.aml.vocabularies.data.Object)) {
|
|
178
|
+
throw new Error(`Not an ObjectNode.`);
|
|
179
|
+
}
|
|
180
|
+
if (!this.properties) {
|
|
181
|
+
this.properties = {};
|
|
182
|
+
}
|
|
183
|
+
this.properties[name] = value;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Deletes a property by name.
|
|
188
|
+
*
|
|
189
|
+
* @param name The name of the property to delete.
|
|
190
|
+
*/
|
|
191
|
+
removeProperty(name: string): void {
|
|
192
|
+
if (!this.types.includes(AmfNamespace.aml.vocabularies.data.Object)) {
|
|
193
|
+
throw new Error(`Not an ObjectNode.`);
|
|
194
|
+
}
|
|
195
|
+
if (!this.properties) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
delete this.properties[name];
|
|
199
|
+
}
|
|
200
|
+
}
|