@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.
Files changed (155) hide show
  1. package/build/browser.d.ts +9 -2
  2. package/build/browser.js +12 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +9 -2
  5. package/build/index.js +12 -2
  6. package/build/index.js.map +1 -1
  7. package/build/src/amf/AmfMixin.d.ts +395 -0
  8. package/build/src/amf/AmfMixin.js +1146 -0
  9. package/build/src/amf/AmfMixin.js.map +1 -0
  10. package/build/src/amf/AmfSerializer.d.ts +136 -0
  11. package/build/src/amf/AmfSerializer.js +1913 -0
  12. package/build/src/amf/AmfSerializer.js.map +1 -0
  13. package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
  14. package/build/src/amf/AmfShapeGenerator.js +385 -0
  15. package/build/src/amf/AmfShapeGenerator.js.map +1 -0
  16. package/build/src/amf/AmfTypes.d.ts +24 -0
  17. package/build/src/amf/AmfTypes.js +122 -0
  18. package/build/src/amf/AmfTypes.js.map +1 -0
  19. package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
  20. package/build/src/amf/ApiExampleGenerator.js +109 -0
  21. package/build/src/amf/ApiExampleGenerator.js.map +1 -0
  22. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
  23. package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
  24. package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
  25. package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
  26. package/build/src/amf/ApiSchemaGenerator.js +94 -0
  27. package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
  28. package/build/src/amf/ApiSchemaValues.d.ts +98 -0
  29. package/build/src/amf/ApiSchemaValues.js +382 -0
  30. package/build/src/amf/ApiSchemaValues.js.map +1 -0
  31. package/build/src/amf/Utils.d.ts +41 -0
  32. package/build/src/amf/Utils.js +176 -0
  33. package/build/src/amf/Utils.js.map +1 -0
  34. package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
  35. package/build/src/amf/data-node/DataNodeBase.js +77 -0
  36. package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
  37. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
  38. package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
  39. package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
  40. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
  41. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
  42. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
  43. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
  44. package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
  45. package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
  46. package/build/src/amf/definitions/Amf.d.ts +362 -0
  47. package/build/src/amf/definitions/Amf.js +2 -0
  48. package/build/src/amf/definitions/Amf.js.map +1 -0
  49. package/build/src/amf/definitions/Api.d.ts +381 -0
  50. package/build/src/amf/definitions/Api.js +2 -0
  51. package/build/src/amf/definitions/Api.js.map +1 -0
  52. package/build/src/amf/definitions/Base.d.ts +11 -0
  53. package/build/src/amf/definitions/Base.js +2 -0
  54. package/build/src/amf/definitions/Base.js.map +1 -0
  55. package/build/src/amf/definitions/Namespace.d.ts +311 -0
  56. package/build/src/amf/definitions/Namespace.js +330 -0
  57. package/build/src/amf/definitions/Namespace.js.map +1 -0
  58. package/build/src/amf/definitions/Shapes.d.ts +309 -0
  59. package/build/src/amf/definitions/Shapes.js +87 -0
  60. package/build/src/amf/definitions/Shapes.js.map +1 -0
  61. package/build/src/amf/models/AmfDataNode.d.ts +68 -0
  62. package/build/src/amf/models/AmfDataNode.js +188 -0
  63. package/build/src/amf/models/AmfDataNode.js.map +1 -0
  64. package/build/src/amf/shape/ShapeBase.d.ts +75 -0
  65. package/build/src/amf/shape/ShapeBase.js +90 -0
  66. package/build/src/amf/shape/ShapeBase.js.map +1 -0
  67. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
  68. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
  69. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
  70. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
  71. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
  72. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
  73. package/build/src/models/Thing.d.ts +17 -0
  74. package/build/src/models/Thing.js +19 -1
  75. package/build/src/models/Thing.js.map +1 -1
  76. package/build/src/models/data/Bindings.d.ts +161 -0
  77. package/build/src/models/data/Bindings.js +2 -0
  78. package/build/src/models/data/Bindings.js.map +1 -0
  79. package/build/src/models/data/DataAssociation.d.ts +135 -14
  80. package/build/src/models/data/DataAssociation.js +154 -21
  81. package/build/src/models/data/DataAssociation.js.map +1 -1
  82. package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
  83. package/build/src/models/data/DataEntity.d.ts +76 -4
  84. package/build/src/models/data/DataEntity.js +136 -9
  85. package/build/src/models/data/DataEntity.js.map +1 -1
  86. package/build/src/models/data/DataFile.d.ts +3 -0
  87. package/build/src/models/data/DataFile.js +3 -0
  88. package/build/src/models/data/DataFile.js.map +1 -1
  89. package/build/src/models/data/DataModel.d.ts +1 -1
  90. package/build/src/models/data/DataModel.js.map +1 -1
  91. package/build/src/models/data/DataNamespace.d.ts +6 -0
  92. package/build/src/models/data/DataNamespace.js +11 -1
  93. package/build/src/models/data/DataNamespace.js.map +1 -1
  94. package/build/src/models/data/DataProperty.d.ts +131 -36
  95. package/build/src/models/data/DataProperty.js +200 -17
  96. package/build/src/models/data/DataProperty.js.map +1 -1
  97. package/data/apis/oas-date/oas-date.yaml +28 -0
  98. package/data/apis/oas-types/oas-types.yaml +159 -0
  99. package/data/apis/oas-unions/oas-unions.yaml +75 -0
  100. package/data/apis/raml-date/raml-date.raml +28 -0
  101. package/data/apis/recursive/recursive.raml +14 -0
  102. package/data/apis/schema-api/examples/person.json +14 -0
  103. package/data/apis/schema-api/examples/person.raml +14 -0
  104. package/data/apis/schema-api/examples/person.url.encoded +1 -0
  105. package/data/apis/schema-api/examples/person.xml +14 -0
  106. package/data/apis/schema-api/library/demo-types.raml +43 -0
  107. package/data/apis/schema-api/schema-api.raml +644 -0
  108. package/data/apis/schema-api/schemas/person.json +104 -0
  109. package/data/apis/schema-api/schemas/person.xsd +26 -0
  110. package/data/apis/schema-api/types/DemoPerson.raml +67 -0
  111. package/data/model.js +106 -0
  112. package/data/models/oas-date.json +637 -0
  113. package/data/models/oas-types.json +5352 -0
  114. package/data/models/oas-unions.json +1881 -0
  115. package/data/models/raml-date.json +1096 -0
  116. package/data/models/recursive.json +610 -0
  117. package/data/models/schema-api.json +37319 -0
  118. package/package.json +9 -6
  119. package/src/amf/AmfMixin.ts +1623 -0
  120. package/src/amf/AmfSerializer.ts +2028 -0
  121. package/src/amf/AmfShapeGenerator.ts +400 -0
  122. package/src/amf/AmfTypes.ts +126 -0
  123. package/src/amf/ApiExampleGenerator.ts +112 -0
  124. package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
  125. package/src/amf/ApiSchemaGenerator.ts +108 -0
  126. package/src/amf/ApiSchemaValues.ts +411 -0
  127. package/src/amf/Utils.ts +182 -0
  128. package/src/amf/data-node/DataNodeBase.ts +81 -0
  129. package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
  130. package/src/amf/data-node/README.md +3 -0
  131. package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
  132. package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
  133. package/src/amf/definitions/Amf.ts +443 -0
  134. package/src/amf/definitions/Api.ts +427 -0
  135. package/src/amf/definitions/Base.ts +13 -0
  136. package/src/amf/definitions/Namespace.ts +341 -0
  137. package/src/amf/definitions/Shapes.ts +414 -0
  138. package/src/amf/models/AmfDataNode.ts +200 -0
  139. package/src/amf/shape/README.md +4 -0
  140. package/src/amf/shape/ShapeBase.ts +160 -0
  141. package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
  142. package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
  143. package/src/models/Thing.ts +25 -1
  144. package/src/models/data/Bindings.ts +186 -0
  145. package/src/models/data/DataAssociation.ts +226 -29
  146. package/src/models/data/DataAssociationSchema.ts +38 -0
  147. package/src/models/data/DataEntity.ts +170 -13
  148. package/src/models/data/DataFile.ts +3 -0
  149. package/src/models/data/DataModel.ts +1 -1
  150. package/src/models/data/DataNamespace.ts +16 -1
  151. package/src/models/data/DataProperty.ts +250 -47
  152. package/build/src/models/data/DataPropertySchema.d.ts +0 -125
  153. package/build/src/models/data/DataPropertySchema.js +0 -33
  154. package/build/src/models/data/DataPropertySchema.js.map +0 -1
  155. package/src/models/data/DataPropertySchema.ts +0 -156
@@ -0,0 +1,1623 @@
1
+ /**
2
+ @license
3
+ Copyright 2018 The Advanced REST client authors <arc@mulesoft.com>
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ use this file except in compliance with the License. You may obtain a copy of
6
+ the License at
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
+ License for the specific language governing permissions and limitations under
12
+ the License.
13
+ */
14
+ // @ts-ignore
15
+ import { AmfModelExpander, JsonLdOptions, JsonLd } from 'amf-json-ld-lib';
16
+ import { AmfDocument, DomainElement, EndPoint, LdValue, SecurityScheme, Shape, WebApi, Operation, AsyncApi, Server, Request } from './definitions/Amf.js';
17
+ import { AmfNamespace as ns } from './definitions/Namespace.js';
18
+
19
+ export const expandKey = Symbol('expandKey');
20
+ export const findAmfType = Symbol('findAmfType');
21
+ export const findReferenceObject = Symbol('findReferenceObject');
22
+ export const getArrayItems = Symbol('getArrayItems');
23
+ export const computeReferenceSecurity = Symbol('computeReferenceSecurity');
24
+
25
+ export interface ServersQueryOptions {
26
+ /**
27
+ * An EndPoint to look for the servers in
28
+ */
29
+ endpointId?: string
30
+ /**
31
+ * An Operation to look for the servers in
32
+ */
33
+ methodId?: string
34
+ }
35
+
36
+ export interface ServerQueryOptions {
37
+ /**
38
+ * An EndPoint to look for the servers in. Required if Operation is provided
39
+ */
40
+ endpointId?: string
41
+ /**
42
+ * An Operation to look for the servers in
43
+ */
44
+ methodId?: string
45
+ /**
46
+ * Optional selected server id
47
+ */
48
+ id?: string;
49
+ }
50
+
51
+ type Constructor<T = {}> = new (...args: any[]) => T;
52
+
53
+ export declare class AmfMixinInterface {
54
+ amf?: AmfDocument;
55
+ /**
56
+ * This is an abstract method to be implemented by the components.
57
+ * If, instead, the component uses `amf` setter you must use `super.amf` to
58
+ * set the value.
59
+ * @param amf Current AMF model. Can be undefined.
60
+ */
61
+ _amfChanged(amf?: AmfDocument): void;
62
+
63
+ /**
64
+ * Expands flattened AMF model
65
+ */
66
+ _expand(amf: any): any;
67
+
68
+ /**
69
+ * Returns compact model key for given value.
70
+ * @param property AMF original property
71
+ * @param context A context to use. If not set, it looks for the context of the passed model
72
+ * @returns Compact model property name or the same value if value not found in the context.
73
+ */
74
+ _getAmfKey(property?: string, context?: Record<string, string>): string | undefined;
75
+
76
+ /**
77
+ * Ensures that the model is AMF object.
78
+ *
79
+ * @param amf AMF json/ld model
80
+ * @returns The API spec
81
+ */
82
+ _ensureAmfModel(amf: any): AmfDocument | undefined;
83
+
84
+ /**
85
+ * Ensures that the value is an array.
86
+ * It returns undefined when there's no value.
87
+ * It returns the same array if the value is already an array.
88
+ * It returns new array of the item is not an array.
89
+ *
90
+ * @param value An item to test
91
+ */
92
+ _ensureArray(value?: any): unknown[] | undefined;
93
+
94
+ /**
95
+ * Gets a single scalar value from a model.
96
+ * @param model Amf model to extract the value from.
97
+ * @param untrustedKey Model key to search for the value
98
+ * @param context A context to use. If not set, it looks for the context of the passed model
99
+ * @returns Value for key
100
+ */
101
+ _getValue(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string | number | boolean | undefined | null;
102
+
103
+ /**
104
+ * Gets values from a model as an array of `@value` properties.
105
+ * @param model Amf model to extract the value from.
106
+ * @param untrustedKey Model key to search for the value
107
+ * @param context A context to use. If not set, it looks for the context of the passed model
108
+ * @returns The value for key
109
+ */
110
+ _getValueArray(model: DomainElement, untrustedKey: string, context?: Record<string, string>): (string | number | boolean | null)[] | undefined;
111
+
112
+ /**
113
+ * Reads an array from the model.
114
+ *
115
+ * @param model Amf model to extract the value from.
116
+ * @param untrustedKey Model key to search for the value
117
+ * @param context A context to use. If not set, it looks for the context of the passed model
118
+ * @returns Value for the key
119
+ */
120
+ [getArrayItems](model?: DomainElement, untrustedKey?: string, context?: Record<string, string>): DomainElement[] | undefined;
121
+
122
+ /**
123
+ * Reads the value of the `@id` property.
124
+ * @param model Amf model to extract the value from.
125
+ * @param untrustedKey Model key to search for the @id
126
+ * @param context A context to use. If not set, it looks for the context of the passed model
127
+ */
128
+ _getLinkValue(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string | undefined;
129
+
130
+ /**
131
+ * Reads the list of value for the `@id` property.
132
+ * @param model Amf model to extract the value from.
133
+ * @param untrustedKey Model key to search for the @id
134
+ * @param context A context to use. If not set, it looks for the context of the passed model
135
+ */
136
+ _getLinkValues(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string[] | undefined;
137
+
138
+ /**
139
+ * Checks if a model has a type.
140
+ * @param model Model to test
141
+ * @param type Type name
142
+ * @param context A context to use. If not set, it looks for the context of the passed model
143
+ * @returns True if model has a type.
144
+ */
145
+ _hasType(model?: DomainElement, type?: string, context?: Record<string, string>): boolean;
146
+
147
+ /**
148
+ * Checks if a shape has a property.
149
+ * @param shape The shape to test
150
+ * @param untrustedKey Property name to test
151
+ * @param context A context to use. If not set, it looks for the context of the passed model
152
+ */
153
+ _hasProperty(shape: DomainElement, untrustedKey: string, context?: Record<string, string>): boolean;
154
+
155
+ /**
156
+ * Computes array value of a property in a model (shape).
157
+ *
158
+ * @param shape AMF shape object
159
+ * @param untrustedKey Property name
160
+ * @param context A context to use. If not set, it looks for the context of the passed model
161
+ */
162
+ _computePropertyArray(shape?: DomainElement, untrustedKey?: string, context?: Record<string, string>): (string|number|boolean|null|Object)[] | undefined;
163
+
164
+ /**
165
+ * Computes API version from the AMF model.
166
+ *
167
+ * @param amf
168
+ * @param context A context to use. If not set, it looks for the context of the passed model
169
+ */
170
+ _computeApiVersion(amf?: AmfDocument, context?: Record<string, string>): string | undefined;
171
+
172
+ /**
173
+ * Computes model's `encodes` property.
174
+ *
175
+ * @param model AMF data model
176
+ * @param context A context to use. If not set, it looks for the context of the passed model
177
+ * @returns List of encodes
178
+ */
179
+ _computeEncodes(model?: AmfDocument, context?: Record<string, string>): DomainElement | undefined;
180
+
181
+ /**
182
+ * Computes list of declarations in the AMF api model.
183
+ *
184
+ * @param model AMF json/ld model for an API
185
+ * @param context A context to use. If not set, it looks for the context of the passed model
186
+ * @returns List of declarations
187
+ */
188
+ _computeDeclares(model?: AmfDocument, context?: Record<string, string>): DomainElement[] | undefined;
189
+
190
+ /**
191
+ * Computes list of references in the AMF api model.
192
+ *
193
+ * @param model AMF json/ld model for an API
194
+ * @param context A context to use. If not set, it looks for the context of the passed model
195
+ * @returns List of declarations
196
+ */
197
+ _computeReferences(model?: AmfDocument, context?: Record<string, string>): DomainElement[] | undefined;
198
+
199
+ /**
200
+ * Computes AMF's `http://schema.org/WebAPI` model
201
+ *
202
+ * @param model AMF json/ld model for an API
203
+ * @param context A context to use. If not set, it looks for the context of the passed model
204
+ * @returns Web API declaration.
205
+ */
206
+ _computeWebApi(model?: AmfDocument, context?: Record<string, string>): WebApi|undefined;
207
+
208
+ /**
209
+ * Computes AMF's `http://schema.org/API` model
210
+ *
211
+ * @param model AMF json/ld model for an API
212
+ * @param context A context to use. If not set, it looks for the context of the passed model
213
+ * @returns API declaration.
214
+ */
215
+ _computeApi(model?: AmfDocument, context?: Record<string, string>): AsyncApi|WebApi|undefined;
216
+
217
+ /**
218
+ * Returns whether an AMF node is a WebAPI node
219
+ *
220
+ * @param model AMF json/ld model for an API
221
+ * @param context A context to use. If not set, it looks for the context of the passed model
222
+ */
223
+ _isWebAPI(model?: AmfDocument, context?: Record<string, string>): boolean;
224
+
225
+ /**
226
+ * Returns whether an AMF node is an AsyncAPI node
227
+ *
228
+ * @param model AMF json/ld model for an API
229
+ * @param context A context to use. If not set, it looks for the context of the passed model
230
+ */
231
+ _isAsyncAPI(model?: AmfDocument, context?: Record<string, string>): boolean;
232
+
233
+ /**
234
+ * Returns whether an AMF node is an API node
235
+ *
236
+ * @param model AMF json/ld model for an API
237
+ * @param context A context to use. If not set, it looks for the context of the passed model
238
+ */
239
+ _isAPI(model?: AmfDocument, context?: Record<string, string>): boolean;
240
+
241
+ /**
242
+ * Determines whether a partial model is valid for reading servers from
243
+ * Current valid values:
244
+ * - Operation
245
+ * - Endpoint
246
+ * @param model The partial model to evaluate
247
+ * @param context A context to use. If not set, it looks for the context of the passed model
248
+ * @returns Whether the model's type is part of the array of valid node types from which
249
+ * to read servers
250
+ * @private
251
+ */
252
+ _isValidServerPartial(model: DomainElement, context?: Record<string, string>): boolean;
253
+
254
+ /**
255
+ * @param options Server query options
256
+ * @param context A context to use. If not set, it looks for the context of the passed model
257
+ * @returns List of servers for method, if defined, or endpoint, if defined, or root level
258
+ */
259
+ _getServers(options?: ServersQueryOptions, context?: Record<string, string>): Server[] | undefined;
260
+
261
+ /**
262
+ * Computes value for the `expects` property.
263
+ *
264
+ * @param method AMF `supportedOperation` model
265
+ * @param context A context to use. If not set, it looks for the context of the passed model
266
+ */
267
+ _computeExpects(method?: Operation, context?: Record<string, string>): Request | undefined;
268
+
269
+ /**
270
+ * Computes list of endpoints from a WebApi model.
271
+ * @param webApi
272
+ * @param context A context to use. If not set, it looks for the context of the passed model
273
+ * @returns An array of endpoints.
274
+ */
275
+ _computeEndpoints(webApi?: WebApi, context?: Record<string, string>): EndPoint[] | undefined;
276
+ /**
277
+ * Computes model for an endpoint documentation.
278
+ *
279
+ * @param webApi Current value of `webApi` property
280
+ * @param id Selected shape ID
281
+ * @param context A context to use. If not set, it looks for the context of the passed model
282
+ * @returns An endpoint definition
283
+ */
284
+ _computeEndpointModel(webApi?: WebApi, id?: string, context?: Record<string, string>): EndPoint | undefined;
285
+
286
+ /**
287
+ * Computes method for the method documentation.
288
+ *
289
+ * @param webApi Current value of `webApi` property
290
+ * @param selected Selected shape
291
+ * @param context A context to use. If not set, it looks for the context of the passed model
292
+ * @returns A method definition
293
+ */
294
+ _computeMethodModel(webApi?: WebApi, selected?: string, context?: Record<string, string>): Operation | undefined;
295
+
296
+ /**
297
+ * Computes an endpoint for a method.
298
+ * @param webApi The WebApi AMF model
299
+ * @param methodId Method id
300
+ * @param context A context to use. If not set, it looks for the context of the passed model
301
+ * @returns An endpoint model of undefined.
302
+ */
303
+ _computeMethodEndpoint(webApi?: WebApi, methodId?: string, context?: Record<string, string>): EndPoint|undefined;
304
+
305
+ /**
306
+ * Computes a list of methods for an endpoint that contains a method with
307
+ * given id.
308
+ *
309
+ * @param webApi WebApi model
310
+ * @param methodId Method id.
311
+ * @param context A context to use. If not set, it looks for the context of the passed model
312
+ * @returns A list of sibling methods or undefined.
313
+ */
314
+ __computeMethodsListForMethod(webApi?: WebApi, methodId?: string, context?: Record<string, string>): Operation[] | undefined;
315
+
316
+ /**
317
+ * Computes a type documentation model.
318
+ *
319
+ * @param declares Current value of `declares` property
320
+ * @param references Current value of `references` property
321
+ * @param selected Selected shape
322
+ * @param context A context to use. If not set, it looks for the context of the passed model
323
+ * @returns A type definition
324
+ */
325
+ _computeType(declares?: DomainElement[], references?: DomainElement[], selected?: string, context?: Record<string, string>): Shape | undefined;
326
+
327
+ /**
328
+ * Finds a type in the model declares and references.
329
+ * @param domainId The domain id of the type (AMF's shape).
330
+ * @param context A context to use. If not set, it looks for the context of the passed model
331
+ * @returns The AMF shape or undefined when not found.
332
+ */
333
+ [findAmfType](domainId?: string, context?: Record<string, string>): Shape|undefined;
334
+
335
+ /**
336
+ * Searches for an object in model's references list.
337
+ * It does not resolve the object (useful for handling links correctly).
338
+ *
339
+ * @param domainId The domain of the object to find in the references.
340
+ * @param context A context to use. If not set, it looks for the context of the passed model
341
+ * @returns The domain object or undefined.
342
+ */
343
+ [findReferenceObject](domainId: string, context?: Record<string, string>): DomainElement | undefined;
344
+
345
+ /**
346
+ * Computes a type model from a reference (library for example).
347
+ * @param reference AMF model for a reference to extract the data from
348
+ * @param selected Node ID to look for
349
+ * @param context A context to use. If not set, it looks for the context of the passed model
350
+ * @returns Type definition or undefined if not found.
351
+ */
352
+ _computeReferenceType(reference?: DomainElement, selected?: string, context?: Record<string, string>): Shape|undefined;
353
+
354
+ /**
355
+ * Computes a documentation model.
356
+ *
357
+ * @param webApi Current value of `webApi` property
358
+ * @param selected Selected shape
359
+ * @param context A context to use. If not set, it looks for the context of the passed model
360
+ */
361
+ _computeDocument(webApi?: DomainElement, selected?: string, context?: Record<string, string>): DomainElement|undefined;
362
+
363
+ /**
364
+ * Resolves a reference to an external fragment.
365
+ *
366
+ * @param shape A shape to resolve
367
+ * @param context A context to use. If not set, it looks for the context of the passed model
368
+ * @returns Resolved shape.
369
+ */
370
+ _resolve(shape: any, context?: Record<string, string>): any;
371
+
372
+ /**
373
+ * @param amf References object to search in
374
+ * @param id Id of the shape to resolve
375
+ * @param context A context to use. If not set, it looks for the context of the passed model
376
+ * @returns Resolved shape for given reference, undefined otherwise
377
+ */
378
+ _getLinkTarget(amf?: AmfDocument, id?: string , context?: Record<string, string>): DomainElement | undefined;
379
+
380
+ /**
381
+ * Resolves the shape of a given reference.
382
+ *
383
+ * @param references References object to search in
384
+ * @param id Id of the shape to resolve
385
+ * @param context A context to use. If not set, it looks for the context of the passed model
386
+ * @returns Resolved shape for given reference, undefined otherwise
387
+ */
388
+ _obtainShapeFromReferences(references?: DomainElement[], id?: string, context?: Record<string, string>): DomainElement | undefined;
389
+
390
+ /**
391
+ * Searches a node with a given ID in an array
392
+ *
393
+ * @param array Array to search for a given ID
394
+ * @param id Id to search for
395
+ * @returns Node with the given ID when found, undefined otherwise
396
+ */
397
+ _findById(array?: DomainElement[], id?: string): DomainElement | undefined;
398
+
399
+ _getReferenceId(amf?: AmfDocument, id?: string, context?: Record<string, string>): DomainElement | undefined;
400
+
401
+ _resolveRecursive(shape: any, context?: Record<string, string>): void;
402
+
403
+ /**
404
+ * Merge two shapes together. If the resulting shape has one of the "special merge" keys,
405
+ * then the special merge function for that key will be used to match that property
406
+ * @param shapeA AMF node
407
+ * @param shapeB AMF node
408
+ * @param context A context to use. If not set, it looks for the context of the passed model
409
+ * @returns Merged AMF node
410
+ */
411
+ _mergeShapes(shapeA: any, shapeB: any, context?: Record<string, string>): any;
412
+
413
+ /**
414
+ * Obtains source map sources value from two shapes and returns the merged result
415
+ * If neither shape has a sources node, then an empty object will be returned.
416
+ * Result is wrapped in an array as per AMF model standard
417
+ * @param shapeA AMF node
418
+ * @param shapeB AMF node
419
+ * @param context A context to use. If not set, it looks for the context of the passed model
420
+ * @returns Empty object or resulting merge, wrapped in an array
421
+ * @private
422
+ */
423
+ _mergeSourceMapsSources(shapeA: any, shapeB: any, context?: Record<string, string>): (any | {})[];
424
+
425
+ /**
426
+ * Expands the key property from compacted mode to full mode.
427
+ * @param value The value to process
428
+ * @returns The expanded value.
429
+ */
430
+ [expandKey](value: string, context?: Record<string, string>): string;
431
+
432
+ /**
433
+ * Computes a security model from a reference (library for example).
434
+ * @param domainId Domain id of the security requirement to find.
435
+ * @param context A context to use. If not set, it looks for the context of the passed model
436
+ * @returns Type definition or undefined if not found.
437
+ */
438
+ findSecurityScheme(domainId: string, context?: Record<string, string>): SecurityScheme | undefined;
439
+
440
+ /**
441
+ * Computes a security model from a reference (library for example).
442
+ * @param reference AMF model for a reference to extract the data from
443
+ * @param selected Node ID to look for
444
+ * @param context A context to use. If not set, it looks for the context of the passed model
445
+ * @returns Type definition or undefined if not found.
446
+ */
447
+ [computeReferenceSecurity](reference: DomainElement, selected: string, context?: Record<string, string>): SecurityScheme | undefined;
448
+
449
+ /**
450
+ * Collects domain objects by a domain type.
451
+ * @param source The element to search for declare/encoded objects.
452
+ * @param type The domain type
453
+ * @param context A context to use. If not set, it looks for the context of the passed model
454
+ */
455
+ getByType(source: DomainElement, type: string, context?: Record<string, string>): DomainElement[];
456
+ }
457
+
458
+ /**
459
+ * Common functions used by AMF components to compute AMF values.
460
+ */
461
+ export const AmfMixin = <T extends Constructor<any>>(superClass: T): Constructor<AmfMixinInterface> & T => {
462
+ class AmfMixin extends superClass {
463
+ _amf?: AmfDocument;
464
+ _flattenedAmf?: any;
465
+ __cachedKeys?: any;
466
+
467
+ get amf(): AmfDocument | undefined {
468
+ return this._amf;
469
+ }
470
+
471
+ set amf(value: AmfDocument | undefined) {
472
+ const old = this._amf;
473
+ if (old === value) {
474
+ return;
475
+ }
476
+ let expanded;
477
+ if (!value || AmfModelExpander.isInExpandedForm(value)) {
478
+ this._flattenedAmf = undefined;
479
+ expanded = value;
480
+ } else {
481
+ const oldFlattened = this._flattenedAmf;
482
+ if (oldFlattened === value) {
483
+ return;
484
+ }
485
+ this._flattenedAmf = value;
486
+ expanded = this._expand(value);
487
+ }
488
+ // Cached keys cannot be static as this element can be using in the sane
489
+ // document with different AMF models
490
+ this.__cachedKeys = {};
491
+ this._amf = expanded;
492
+ this._amfChanged(expanded);
493
+ }
494
+
495
+ /**
496
+ * This is an abstract method to be implemented by the components.
497
+ * If, instead, the component uses `amf` setter you must use `super.amf` to
498
+ * set the value.
499
+ * @param amf Current AMF model. Can be undefined.
500
+ */
501
+ /* eslint-disable-next-line no-unused-vars */
502
+ _amfChanged(amf?: AmfDocument): void { }
503
+
504
+ /**
505
+ * Expands flattened AMF model
506
+ */
507
+ _expand(amf: any): any {
508
+ AmfModelExpander.preprocessLegacyRootNodeId(amf)
509
+ const linkEmbeddingFilter = (key: string): boolean => !key.endsWith("fixPoint")
510
+ const rootNode = amf['@context'] ? '' : "amf://id";
511
+ const options = JsonLdOptions.apply()
512
+ .withEmbeddedLinks(linkEmbeddingFilter)
513
+ .withCompactedIris()
514
+ .withExpandedStructure()
515
+ .withRootNode(rootNode)
516
+ return JsonLd.process(amf, options)
517
+ }
518
+
519
+ /**
520
+ * Returns compact model key for given value.
521
+ * @param property AMF original property
522
+ * @param context A context to use. If not set, it looks for the context of the passed model
523
+ * @returns Compact model property name or the same value if value not found in the context.
524
+ */
525
+ _getAmfKey(property?: string, context?: Record<string, string>): string | undefined {
526
+ if (!property) {
527
+ return undefined;
528
+ }
529
+ let { amf } = this;
530
+ if (!amf && !context) {
531
+ return property;
532
+ }
533
+ if (Array.isArray(amf)) {
534
+ [amf] = amf;
535
+ }
536
+ if (!this.__cachedKeys) {
537
+ this.__cachedKeys = {};
538
+ }
539
+ const ctx = (context || amf && amf['@context']) as Record<string, string> | undefined;
540
+ if (!ctx || !property) {
541
+ return property;
542
+ }
543
+ const cache = this.__cachedKeys;
544
+ if (property in cache) {
545
+ return cache[property];
546
+ }
547
+ property = String(property);
548
+ const hashIndex = property.indexOf('#');
549
+ const hashProperty = property.substring(0, hashIndex + 1);
550
+ const keys = Object.keys(ctx);
551
+ for (let i = 0, len = keys.length; i < len; i++) {
552
+ const k = keys[i];
553
+ if (ctx[k] === property) {
554
+ cache[property] = k;
555
+ return k;
556
+ } if (hashIndex === -1 && property.indexOf(ctx[k]) === 0) {
557
+ const result = property.replace(ctx[k], `${k}:`);
558
+ cache[property] = result;
559
+ return result;
560
+ } if (ctx[k] === hashProperty) {
561
+ const result = `${k}:${property.substring(hashIndex + 1)}`;
562
+ cache[property] = result;
563
+ return result;
564
+ }
565
+ }
566
+ return property;
567
+ }
568
+
569
+ /**
570
+ * Ensures that the model is AMF object.
571
+ *
572
+ * @param amf AMF json/ld model
573
+ * @returns The API spec
574
+ */
575
+ _ensureAmfModel(amf: any): AmfDocument | undefined {
576
+ if (!amf) {
577
+ return undefined;
578
+ }
579
+ if (Array.isArray(amf)) {
580
+ [amf] = amf;
581
+ }
582
+ if (this._hasType(amf, ns.aml.vocabularies.document.Document)) {
583
+ return amf;
584
+ }
585
+ return undefined;
586
+ }
587
+
588
+ /**
589
+ * Ensures that the value is an array.
590
+ * It returns undefined when there's no value.
591
+ * It returns the same array if the value is already an array.
592
+ * It returns new array of the item is not an array.
593
+ *
594
+ * @param value An item to test
595
+ */
596
+ _ensureArray(value?: any): unknown[] | undefined {
597
+ if (!value) {
598
+ return undefined;
599
+ }
600
+ if (value instanceof Array) {
601
+ return value;
602
+ }
603
+ return [value];
604
+ }
605
+
606
+ /**
607
+ * Gets a single scalar value from a model.
608
+ * @param model Amf model to extract the value from.
609
+ * @param untrustedKey Model key to search for the value
610
+ * @param context A context to use. If not set, it looks for the context of the passed model
611
+ * @returns Value for key
612
+ */
613
+ _getValue(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string | number | boolean | undefined | null {
614
+ const key = this._getAmfKey(untrustedKey, context);
615
+ if (!key) {
616
+ return undefined;
617
+ }
618
+ let data = model && model[key as keyof DomainElement] as string | number | boolean | undefined | null;
619
+ if (!data) {
620
+ // This includes "undefined", "false", "null" and "0"
621
+ return data;
622
+ }
623
+ if (Array.isArray(data)) {
624
+ [data] = data;
625
+ }
626
+ if (!data) {
627
+ return undefined;
628
+ }
629
+ const type = typeof data;
630
+ if (['string', 'number', 'boolean', 'undefined'].includes(type)) {
631
+ return data;
632
+ }
633
+ return ((data as unknown) as LdValue<any>)['@value'];
634
+ }
635
+
636
+ /**
637
+ * Gets values from a model as an array of `@value` properties.
638
+ * @param model Amf model to extract the value from.
639
+ * @param untrustedKey Model key to search for the value
640
+ * @param context A context to use. If not set, it looks for the context of the passed model
641
+ * @returns The value for key
642
+ */
643
+ _getValueArray(model: DomainElement, untrustedKey: string, context?: Record<string, string>): (string | number | boolean | null)[] | undefined {
644
+ const key = this._getAmfKey(untrustedKey, context);
645
+ if (!key) {
646
+ return undefined;
647
+ }
648
+ const data = model && this._ensureArray((model as any)[key]) as any[];
649
+ if (!Array.isArray(data)) {
650
+ return undefined;
651
+ }
652
+ return data.map((item) => item['@value'] || item);
653
+ }
654
+
655
+ /**
656
+ * Reads an array from the model.
657
+ *
658
+ * @param model Amf model to extract the value from.
659
+ * @param untrustedKey Model key to search for the value
660
+ * @param context A context to use. If not set, it looks for the context of the passed model
661
+ * @returns Value for the key
662
+ */
663
+ [getArrayItems](model?: DomainElement, untrustedKey?: string, context?: Record<string, string>): DomainElement[] | undefined {
664
+ const k = this._getAmfKey(untrustedKey, context);
665
+ if (!k) {
666
+ return undefined;
667
+ }
668
+ const data = model && this._ensureArray((model as any)[k]) as DomainElement[];
669
+ if (!Array.isArray(data)) {
670
+ return undefined;
671
+ }
672
+ return data;
673
+ }
674
+
675
+ /**
676
+ * Reads the value of the `@id` property.
677
+ * @param model Amf model to extract the value from.
678
+ * @param untrustedKey Model key to search for the @id
679
+ * @param context A context to use. If not set, it looks for the context of the passed model
680
+ */
681
+ _getLinkValue(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string | undefined {
682
+ const k = this._getAmfKey(untrustedKey, context);
683
+ if (!k) {
684
+ return undefined;
685
+ }
686
+ let data = model && (model as any)[k];
687
+ if (!data) {
688
+ return undefined;
689
+ }
690
+ if (Array.isArray(data)) {
691
+ [data] = data;
692
+ }
693
+ if (!data) {
694
+ return undefined;
695
+ }
696
+ return data['@id'];
697
+ }
698
+
699
+ /**
700
+ * Reads the list of value for the `@id` property.
701
+ * @param model Amf model to extract the value from.
702
+ * @param untrustedKey Model key to search for the @id
703
+ * @param context A context to use. If not set, it looks for the context of the passed model
704
+ */
705
+ _getLinkValues(model: DomainElement, untrustedKey: string, context?: Record<string, string>): string[] | undefined {
706
+ const k = this._getAmfKey(untrustedKey, context);
707
+ if (!k) {
708
+ return undefined;
709
+ }
710
+ let data = (model && (model as any)[k]) as DomainElement[] | undefined;
711
+ if (!data) {
712
+ return undefined;
713
+ }
714
+ if (!Array.isArray(data)) {
715
+ data = [data];
716
+ }
717
+ return data.map(i => i['@id']);
718
+ }
719
+
720
+ /**
721
+ * Checks if a model has a type.
722
+ * @param model Model to test
723
+ * @param type Type name
724
+ * @param context A context to use. If not set, it looks for the context of the passed model
725
+ * @returns True if model has a type.
726
+ */
727
+ _hasType(model?: DomainElement, type?: string, context?: Record<string, string>): boolean {
728
+ const types = this._ensureArray(model && model['@type']);
729
+ if (!types || !types.length) {
730
+ return false;
731
+ }
732
+ const key = this._getAmfKey(type, context);
733
+ for (let i = 0; i < types.length; i++) {
734
+ if (types[i] === key) {
735
+ return true;
736
+ }
737
+ }
738
+ return false;
739
+ }
740
+
741
+ /**
742
+ * Checks if a shape has a property.
743
+ * @param shape The shape to test
744
+ * @param untrustedKey Property name to test
745
+ * @param context A context to use. If not set, it looks for the context of the passed model
746
+ */
747
+ _hasProperty(shape: DomainElement, untrustedKey: string, context?: Record<string, string>): boolean {
748
+ const key = this._getAmfKey(untrustedKey, context)!;
749
+ return !!(shape && key && key in shape);
750
+ }
751
+
752
+ /**
753
+ * Computes array value of a property in a model (shape).
754
+ *
755
+ * @param shape AMF shape object
756
+ * @param untrustedKey Property name
757
+ * @param context A context to use. If not set, it looks for the context of the passed model
758
+ */
759
+ _computePropertyArray(shape?: DomainElement, untrustedKey?: string, context?: Record<string, string>): (string|number|boolean|null|Object)[] | undefined {
760
+ if (!shape) {
761
+ return undefined;
762
+ }
763
+ /* eslint-disable-next-line no-param-reassign */
764
+ const key = this._getAmfKey(untrustedKey, context);
765
+ if (!key) {
766
+ return undefined;
767
+ }
768
+ const data = this._ensureArray(shape && (shape as any)[key]);
769
+ if (!data || !Array.isArray(data)) {
770
+ return undefined;
771
+ }
772
+ return data;
773
+ }
774
+
775
+ /**
776
+ * Computes API version from the AMF model.
777
+ *
778
+ * @param amf
779
+ * @param context A context to use. If not set, it looks for the context of the passed model
780
+ */
781
+ _computeApiVersion(amf?: AmfDocument, context?: Record<string, string>): string | undefined {
782
+ const api = this._computeApi(amf);
783
+ if (!api) {
784
+ return undefined;
785
+ }
786
+ return this._getValue(api, ns.aml.vocabularies.core.version, context) as string;
787
+ }
788
+
789
+ /**
790
+ * Computes model's `encodes` property.
791
+ *
792
+ * @param model AMF data model
793
+ * @param context A context to use. If not set, it looks for the context of the passed model
794
+ * @returns List of encodes
795
+ */
796
+ _computeEncodes(model?: AmfDocument, context?: Record<string, string>): DomainElement | undefined {
797
+ if (!model) {
798
+ return undefined;
799
+ }
800
+ if (Array.isArray(model)) {
801
+ [model] = model;
802
+ }
803
+ const key = this._getAmfKey(ns.aml.vocabularies.document.encodes, context);
804
+ if (!key) {
805
+ return undefined;
806
+ }
807
+ const data = (model as any)[key];
808
+ if (data) {
809
+ return Array.isArray(data) ? data[0] : data;
810
+ }
811
+ return undefined;
812
+ }
813
+
814
+ /**
815
+ * Computes list of declarations in the AMF api model.
816
+ *
817
+ * @param model AMF json/ld model for an API
818
+ * @param context A context to use. If not set, it looks for the context of the passed model
819
+ * @returns List of declarations
820
+ */
821
+ _computeDeclares(model?: AmfDocument, context?: Record<string, string>): DomainElement[] | undefined {
822
+ if (!model) {
823
+ return undefined;
824
+ }
825
+ if (Array.isArray(model)) {
826
+ [model] = model;
827
+ }
828
+ if (!model) {
829
+ return undefined;
830
+ }
831
+ const key = this._getAmfKey(ns.aml.vocabularies.document.declares, context);
832
+ if (!key) {
833
+ return undefined;
834
+ }
835
+ const data = this._ensureArray((model as any)[key]) as DomainElement[];
836
+ return Array.isArray(data) ? data : undefined;
837
+ }
838
+
839
+ /**
840
+ * Computes list of references in the AMF api model.
841
+ *
842
+ * @param model AMF json/ld model for an API
843
+ * @param context A context to use. If not set, it looks for the context of the passed model
844
+ * @returns List of declarations
845
+ */
846
+ _computeReferences(model?: AmfDocument, context?: Record<string, string>): DomainElement[] | undefined {
847
+ if (!model) {
848
+ return undefined;
849
+ }
850
+ if (Array.isArray(model)) {
851
+ [model] = model;
852
+ }
853
+ if (!model) {
854
+ return undefined;
855
+ }
856
+ const key = this._getAmfKey(ns.aml.vocabularies.document.references, context);
857
+ if (!key) {
858
+ return undefined;
859
+ }
860
+ const data = this._ensureArray((model as any)[key]) as DomainElement[];
861
+ return data instanceof Array ? data : undefined;
862
+ }
863
+
864
+ /**
865
+ * Computes AMF's `http://schema.org/WebAPI` model
866
+ *
867
+ * @param model AMF json/ld model for an API
868
+ * @param context A context to use. If not set, it looks for the context of the passed model
869
+ * @returns Web API declaration.
870
+ */
871
+ _computeWebApi(model?: AmfDocument, context?: Record<string, string>): WebApi|undefined {
872
+ const enc = this._computeEncodes(model, context);
873
+ if (!enc) {
874
+ return undefined;
875
+ }
876
+ if (this._hasType(enc, ns.aml.vocabularies.apiContract.WebAPI, context)) {
877
+ return enc;
878
+ }
879
+ return undefined;
880
+ }
881
+
882
+ /**
883
+ * Computes AMF's `http://schema.org/API` model
884
+ *
885
+ * @param model AMF json/ld model for an API
886
+ * @param context A context to use. If not set, it looks for the context of the passed model
887
+ * @returns API declaration.
888
+ */
889
+ _computeApi(model?: AmfDocument, context?: Record<string, string>): AsyncApi|WebApi|undefined {
890
+ const enc = this._computeEncodes(model, context);
891
+ if (!enc) {
892
+ return undefined;
893
+ }
894
+ if (this._isAPI(model, context) || this._isWebAPI(model, context) || this._isAsyncAPI(model, context)) {
895
+ return enc;
896
+ }
897
+ return undefined;
898
+ }
899
+
900
+ /**
901
+ * Returns whether an AMF node is a WebAPI node
902
+ *
903
+ * @param model AMF json/ld model for an API
904
+ * @param context A context to use. If not set, it looks for the context of the passed model
905
+ */
906
+ _isWebAPI(model?: AmfDocument, context?: Record<string, string>): boolean {
907
+ const enc = this._computeEncodes(model, context);
908
+ if (!enc) {
909
+ return false;
910
+ }
911
+ return this._hasType(enc, ns.aml.vocabularies.apiContract.WebAPI, context);
912
+ }
913
+
914
+ /**
915
+ * Returns whether an AMF node is an AsyncAPI node
916
+ *
917
+ * @param model AMF json/ld model for an API
918
+ * @param context A context to use. If not set, it looks for the context of the passed model
919
+ */
920
+ _isAsyncAPI(model?: AmfDocument, context?: Record<string, string>): boolean {
921
+ const enc = this._computeEncodes(model, context);
922
+ if (!enc) {
923
+ return false;
924
+ }
925
+ return this._hasType(enc, ns.aml.vocabularies.apiContract.AsyncAPI, context);
926
+ }
927
+
928
+ /**
929
+ * Returns whether an AMF node is an API node
930
+ *
931
+ * @param model AMF json/ld model for an API
932
+ * @param context A context to use. If not set, it looks for the context of the passed model
933
+ */
934
+ _isAPI(model?: AmfDocument, context?: Record<string, string>): boolean {
935
+ const enc = this._computeEncodes(model, context);
936
+ if (!enc) {
937
+ return false;
938
+ }
939
+ return this._hasType(enc, ns.aml.vocabularies.apiContract.API, context);
940
+ }
941
+
942
+ /**
943
+ * Determines whether a partial model is valid for reading servers from
944
+ * Current valid values:
945
+ * - Operation
946
+ * - Endpoint
947
+ * @param model The partial model to evaluate
948
+ * @param context A context to use. If not set, it looks for the context of the passed model
949
+ * @returns Whether the model's type is part of the array of valid node types from which
950
+ * to read servers
951
+ * @private
952
+ */
953
+ _isValidServerPartial(model: DomainElement, context?: Record<string, string>): boolean {
954
+ if (Array.isArray(model)) {
955
+ [model] = model;
956
+ }
957
+ if (!model) {
958
+ return false;
959
+ }
960
+ const oKey = ns.aml.vocabularies.apiContract.Operation;
961
+ const eKey = ns.aml.vocabularies.apiContract.EndPoint;
962
+ const allowedPartialModelTypes = [this._getAmfKey(oKey, context), this._getAmfKey(eKey, context)];
963
+ const types = model['@type'];
964
+ for (const type of types) {
965
+ if (allowedPartialModelTypes.indexOf(type) !== -1) {
966
+ return true;
967
+ }
968
+ }
969
+ return false;
970
+ }
971
+
972
+ /**
973
+ * @param options Server query options
974
+ * @param context A context to use. If not set, it looks for the context of the passed model
975
+ * @returns List of servers for method, if defined, or endpoint, if defined, or root level
976
+ */
977
+ _getServers(options: ServersQueryOptions = {}, context?: Record<string, string>): Server[] | undefined {
978
+ const { endpointId, methodId } = options;
979
+ const { amf } = this;
980
+ if (!amf) {
981
+ return undefined;
982
+ }
983
+ let api = this._computeApi(amf, context);
984
+ if (Array.isArray(api)) {
985
+ [api] = api;
986
+ }
987
+ if (!api) {
988
+ if (this._isValidServerPartial(amf, context)) {
989
+ api = amf;
990
+ } else {
991
+ return undefined;
992
+ }
993
+ }
994
+
995
+ const serverKey = this._getAmfKey(ns.aml.vocabularies.apiContract.server, context);
996
+
997
+ const getRootServers = (): Server[] | undefined => (this[getArrayItems](api, serverKey, context) as Server[]);
998
+ const getEndpointServers = (): Server[] | undefined => {
999
+ const endpoint = this._computeEndpointModel(api, endpointId, context);
1000
+ const servers = (this[getArrayItems](endpoint, serverKey, context) as Server[]);
1001
+ if (servers) {
1002
+ return servers;
1003
+ }
1004
+ return getRootServers();
1005
+ };
1006
+ const getMethodServers = (): Server[] | undefined => {
1007
+ const method = this._computeMethodModel(api, methodId, context);
1008
+ const servers = (this[getArrayItems](method, serverKey, context)) as Server[];
1009
+ if (servers) {
1010
+ return servers;
1011
+ }
1012
+ return getEndpointServers();
1013
+ };
1014
+
1015
+ if (methodId) {
1016
+ return getMethodServers();
1017
+ } if (endpointId) {
1018
+ return getEndpointServers();
1019
+ }
1020
+ return getRootServers();
1021
+ }
1022
+
1023
+ /**
1024
+ * Computes value for the `expects` property.
1025
+ *
1026
+ * @param method AMF `supportedOperation` model
1027
+ * @param context A context to use. If not set, it looks for the context of the passed model
1028
+ */
1029
+ _computeExpects(method?: Operation, context?: Record<string, string>): Request | undefined {
1030
+ const operationKey = ns.aml.vocabularies.apiContract.Operation;
1031
+ const expectsKey = ns.aml.vocabularies.apiContract.expects;
1032
+ if (this._hasType(method, operationKey, context)) {
1033
+ const key = this._getAmfKey(expectsKey, context)!;
1034
+ const expects = this._ensureArray((method as any)[key]);
1035
+ if (expects) {
1036
+ return Array.isArray(expects) ? expects[0] : expects;
1037
+ }
1038
+ }
1039
+ return undefined;
1040
+ }
1041
+
1042
+ /**
1043
+ * Computes list of endpoints from a WebApi model.
1044
+ * @param webApi
1045
+ * @param context A context to use. If not set, it looks for the context of the passed model
1046
+ * @returns An array of endpoints.
1047
+ */
1048
+ _computeEndpoints(webApi?: WebApi, context?: Record<string, string>): EndPoint[] | undefined {
1049
+ if (!webApi) {
1050
+ return [];
1051
+ }
1052
+ const endpointKey = ns.aml.vocabularies.apiContract.endpoint;
1053
+ const key = this._getAmfKey(endpointKey, context)!;
1054
+ return this._ensureArray((webApi as any)[key]) as EndPoint[];
1055
+ }
1056
+
1057
+ /**
1058
+ * Computes model for an endpoint documentation.
1059
+ *
1060
+ * @param webApi Current value of `webApi` property
1061
+ * @param id Selected shape ID
1062
+ * @param context A context to use. If not set, it looks for the context of the passed model
1063
+ * @returns An endpoint definition
1064
+ */
1065
+ _computeEndpointModel(webApi?: WebApi, id?: string, context?: Record<string, string>): EndPoint | undefined {
1066
+ if (this._hasType(webApi, ns.aml.vocabularies.apiContract.EndPoint, context)) {
1067
+ return webApi;
1068
+ }
1069
+ const endpoints = this._computeEndpoints(webApi, context);
1070
+ if (!endpoints) {
1071
+ return undefined;
1072
+ }
1073
+ return endpoints.find((item) => item['@id'] === id);
1074
+ }
1075
+
1076
+ /**
1077
+ * Computes method for the method documentation.
1078
+ *
1079
+ * @param webApi Current value of `webApi` property
1080
+ * @param selected Selected shape
1081
+ * @param context A context to use. If not set, it looks for the context of the passed model
1082
+ * @returns A method definition
1083
+ */
1084
+ _computeMethodModel(webApi?: WebApi, selected?: string, context?: Record<string, string>): Operation | undefined {
1085
+ const methods = this.__computeMethodsListForMethod(webApi, selected, context);
1086
+ if (!methods) {
1087
+ return undefined;
1088
+ }
1089
+ return methods.find((item) => item['@id'] === selected);
1090
+ }
1091
+
1092
+ /**
1093
+ * Computes an endpoint for a method.
1094
+ * @param webApi The WebApi AMF model
1095
+ * @param methodId Method id
1096
+ * @param context A context to use. If not set, it looks for the context of the passed model
1097
+ * @returns An endpoint model of undefined.
1098
+ */
1099
+ _computeMethodEndpoint(webApi?: WebApi, methodId?: string, context?: Record<string, string>): EndPoint|undefined {
1100
+ if (!webApi || !methodId) {
1101
+ return undefined;
1102
+ }
1103
+ if (this._hasType(webApi, ns.aml.vocabularies.apiContract.EndPoint, context)) {
1104
+ return webApi;
1105
+ }
1106
+ const endpoints = this._computeEndpoints(webApi, context);
1107
+ if (!endpoints) {
1108
+ return undefined;
1109
+ }
1110
+ const opKey = this._getAmfKey(ns.aml.vocabularies.apiContract.supportedOperation, context)!;
1111
+ for (let i = 0, len = endpoints.length; i < len; i++) {
1112
+ const endpoint = endpoints[i];
1113
+ let methods = (endpoint as any)[opKey] as Operation[];
1114
+ if (!methods) {
1115
+ continue;
1116
+ }
1117
+ if (!Array.isArray(methods)) {
1118
+ methods = [methods];
1119
+ }
1120
+ for (let j = 0, jLen = methods.length; j < jLen; j++) {
1121
+ if (methods[j]['@id'] === methodId) {
1122
+ return endpoint;
1123
+ }
1124
+ }
1125
+ }
1126
+ return undefined;
1127
+ }
1128
+
1129
+ /**
1130
+ * Computes a list of methods for an endpoint that contains a method with
1131
+ * given id.
1132
+ *
1133
+ * @param webApi WebApi model
1134
+ * @param methodId Method id.
1135
+ * @param context A context to use. If not set, it looks for the context of the passed model
1136
+ * @returns A list of sibling methods or undefined.
1137
+ */
1138
+ __computeMethodsListForMethod(webApi?: WebApi, methodId?: string, context?: Record<string, string>): Operation[] | undefined {
1139
+ const endpoint = this._computeMethodEndpoint(webApi, methodId, context);
1140
+ if (!endpoint) {
1141
+ return undefined;
1142
+ }
1143
+ const opKey = this._getAmfKey(ns.aml.vocabularies.apiContract.supportedOperation, context)!;
1144
+ return this._ensureArray((endpoint as any)[opKey]) as Operation[] | undefined;
1145
+ }
1146
+
1147
+ /**
1148
+ * Computes a type documentation model.
1149
+ *
1150
+ * @param declares Current value of `declares` property
1151
+ * @param references Current value of `references` property
1152
+ * @param selected Selected shape
1153
+ * @param context A context to use. If not set, it looks for the context of the passed model
1154
+ * @returns A type definition
1155
+ */
1156
+ _computeType(declares?: DomainElement[], references?: DomainElement[], selected?: string, context?: Record<string, string>): Shape | undefined {
1157
+ if ((!declares && !references) || !selected) {
1158
+ return undefined;
1159
+ }
1160
+ // In compact model some IDs are presented in long version (in source maps for examples)
1161
+ // This must test for this case as well.
1162
+ const compactId = selected.replace('amf://id', '');
1163
+ let type = declares && declares.find((item) => item['@id'] === selected || item['@id'] === compactId);
1164
+ if (!type && references && references.length) {
1165
+ for (let i = 0, len = references.length; i < len; i++) {
1166
+ if (!this._hasType(references[i], ns.aml.vocabularies.document.Module)) {
1167
+ continue;
1168
+ }
1169
+ type = this._computeReferenceType(references[i], selected, context);
1170
+ if (type) {
1171
+ break;
1172
+ }
1173
+ }
1174
+ }
1175
+ return type;
1176
+ }
1177
+
1178
+ /**
1179
+ * Finds a type in the model declares and references.
1180
+ * @param domainId The domain id of the type (AMF's shape).
1181
+ * @param context A context to use. If not set, it looks for the context of the passed model
1182
+ * @returns The AMF shape or undefined when not found.
1183
+ */
1184
+ [findAmfType](domainId?: string, context?: Record<string, string>): Shape|undefined {
1185
+ let { amf } = this;
1186
+ if (!amf || !domainId) {
1187
+ return undefined;
1188
+ }
1189
+ if (Array.isArray(amf)) {
1190
+ [amf] = amf;
1191
+ }
1192
+ const declares = this._computeDeclares(amf, context);
1193
+ const compactId = domainId.replace('amf://id', '');
1194
+ if (Array.isArray(declares)) {
1195
+ const result = declares.find((item) => item['@id'] === domainId || item['@id'] === compactId);
1196
+ if (result) {
1197
+ return result;
1198
+ }
1199
+ }
1200
+ return this[findReferenceObject](domainId);
1201
+ }
1202
+
1203
+ /**
1204
+ * Searches for an object in model's references list.
1205
+ * It does not resolve the object (useful for handling links correctly).
1206
+ *
1207
+ * @param domainId The domain of the object to find in the references.
1208
+ * @param context A context to use. If not set, it looks for the context of the passed model
1209
+ * @returns The domain object or undefined.
1210
+ */
1211
+ [findReferenceObject](domainId: string, context?: Record<string, string>): DomainElement | undefined {
1212
+ let { amf } = this;
1213
+ if (Array.isArray(amf)) {
1214
+ [amf] = amf;
1215
+ }
1216
+ if (!amf) {
1217
+ return undefined;
1218
+ }
1219
+ const references = this._computeReferences(amf, context);
1220
+ if (!Array.isArray(references) || !references.length) {
1221
+ return undefined;
1222
+ }
1223
+ const compactId = domainId.replace('amf://id', '');
1224
+ for (let i = 0, len = references.length; i < len; i++) {
1225
+ const ref = /** @type AmfDocument */ (references[i]);
1226
+ const declares = this._computeDeclares(ref, context);
1227
+ if (!Array.isArray(declares)) {
1228
+ continue;
1229
+ }
1230
+ for (let j = 0, lenDecl = declares.length; j < lenDecl; j++) {
1231
+ let declared = declares[j];
1232
+ if (Array.isArray(declared)) {
1233
+ [declared] = declared;
1234
+ }
1235
+ if (declared['@id'] === domainId || declared['@id'] === compactId) {
1236
+ return declared;
1237
+ }
1238
+ }
1239
+ }
1240
+ return undefined;
1241
+ }
1242
+
1243
+ /**
1244
+ * Computes a type model from a reference (library for example).
1245
+ * @param reference AMF model for a reference to extract the data from
1246
+ * @param selected Node ID to look for
1247
+ * @param context A context to use. If not set, it looks for the context of the passed model
1248
+ * @returns Type definition or undefined if not found.
1249
+ */
1250
+ _computeReferenceType(reference?: DomainElement, selected?: string, context?: Record<string, string>): Shape|undefined {
1251
+ const declare = this._computeDeclares(reference, context);
1252
+ if (!declare || !selected) {
1253
+ return undefined;
1254
+ }
1255
+ // In compact model some IDs are presented in long version (in source maps for examples)
1256
+ // This must test for this case as well.
1257
+ const compactId = selected.replace('amf://id', '');
1258
+ let result = declare.find((item) => {
1259
+ if (Array.isArray(item)) {
1260
+ /* eslint-disable-next-line no-param-reassign */
1261
+ [item] = item;
1262
+ }
1263
+ return item['@id'] === selected || item['@id'] === compactId;
1264
+ });
1265
+ if (Array.isArray(result)) {
1266
+ [result] = result;
1267
+ }
1268
+ return this._resolve(result);
1269
+ }
1270
+
1271
+ /**
1272
+ * Computes a documentation model.
1273
+ *
1274
+ * @param webApi Current value of `webApi` property
1275
+ * @param selected Selected shape
1276
+ * @param context A context to use. If not set, it looks for the context of the passed model
1277
+ */
1278
+ _computeDocument(webApi?: DomainElement, selected?: string, context?: Record<string, string>): DomainElement|undefined {
1279
+ if (!webApi || !selected) {
1280
+ return undefined;
1281
+ }
1282
+ const key = this._getAmfKey(ns.aml.vocabularies.core.documentation, context)!;
1283
+ const docs = this._ensureArray((webApi as any)[key]) as DomainElement[];
1284
+ return docs && docs.find((item) => (item as any)['@id'] as string === selected);
1285
+ }
1286
+
1287
+ /**
1288
+ * Resolves a reference to an external fragment.
1289
+ *
1290
+ * @param shape A shape to resolve
1291
+ * @param context A context to use. If not set, it looks for the context of the passed model
1292
+ * @returns Resolved shape.
1293
+ */
1294
+ _resolve(shape: any, context?: Record<string, string>): any {
1295
+ const { amf } = this;
1296
+ if (typeof shape !== 'object' || Array.isArray(shape) || !amf || shape.__apicResolved) {
1297
+ return shape;
1298
+ }
1299
+ let refKey = this._getAmfKey(ns.aml.vocabularies.document.linkTarget, context)!;
1300
+ let refValue = this._ensureArray(shape[refKey]) as DomainElement[];
1301
+ let refData;
1302
+ if (refValue) {
1303
+ const rk = refValue[0]['@id'];
1304
+ if (rk === shape['@id']) {
1305
+ // recursive shape.
1306
+ shape.__apicResolved = true;
1307
+ return shape;
1308
+ }
1309
+ refData = this._getLinkTarget(amf, rk, context);
1310
+ } else {
1311
+ refKey = this._getAmfKey(ns.aml.vocabularies.document.referenceId, context)!;
1312
+ refValue = this._ensureArray(shape[refKey]) as DomainElement[];
1313
+ if (refValue) {
1314
+ const rk = refValue[0]['@id'];
1315
+ if (rk === shape['@id']) {
1316
+ // recursive shape.
1317
+ shape.__apicResolved = true;
1318
+ return shape;
1319
+ }
1320
+ refData = this._getReferenceId(amf, rk, context);
1321
+ }
1322
+ }
1323
+ if (!refData) {
1324
+ this._resolveRecursive(shape);
1325
+ shape.__apicResolved = true;
1326
+ return shape;
1327
+ }
1328
+ const copy = { ...refData } as any;
1329
+ delete copy['@id'];
1330
+ const types = copy['@type'];
1331
+ if (types) {
1332
+ if (shape['@type']) {
1333
+ shape['@type'] = shape['@type'].concat(types);
1334
+ } else {
1335
+ shape['@type'] = types;
1336
+ }
1337
+ delete copy['@type'];
1338
+ }
1339
+ this._mergeShapes(shape, copy, context);
1340
+ shape.__apicResolved = true;
1341
+ this._resolveRecursive(shape);
1342
+ return shape;
1343
+ }
1344
+
1345
+ /**
1346
+ * @param amf References object to search in
1347
+ * @param id Id of the shape to resolve
1348
+ * @param context A context to use. If not set, it looks for the context of the passed model
1349
+ * @returns Resolved shape for given reference, undefined otherwise
1350
+ */
1351
+ _getLinkTarget(amf?: AmfDocument, id?: string , context?: Record<string, string>): DomainElement | undefined {
1352
+ if (!amf || !id) {
1353
+ return undefined;
1354
+ }
1355
+ let target;
1356
+ const declares = this._computeDeclares(amf, context);
1357
+ if (declares) {
1358
+ target = this._findById(declares, id);
1359
+ }
1360
+ if (!target) {
1361
+ const references = this._computeReferences(amf, context);
1362
+ target = this._obtainShapeFromReferences(references, id, context);
1363
+ }
1364
+ if (!target) {
1365
+ return undefined;
1366
+ }
1367
+ // Declaration may contain references
1368
+ target = this._resolve(target);
1369
+ return target;
1370
+ }
1371
+
1372
+ /**
1373
+ * Resolves the shape of a given reference.
1374
+ *
1375
+ * @param references References object to search in
1376
+ * @param id Id of the shape to resolve
1377
+ * @param context A context to use. If not set, it looks for the context of the passed model
1378
+ * @returns Resolved shape for given reference, undefined otherwise
1379
+ */
1380
+ _obtainShapeFromReferences(references?: DomainElement[], id?: string, context?: Record<string, string>): DomainElement | undefined {
1381
+ if (!Array.isArray(references) || !references.length) {
1382
+ return undefined;
1383
+ }
1384
+ let target;
1385
+ for (let i = 0; i < references.length; i++) {
1386
+ const _ref = references[i];
1387
+ // case of fragment that encodes the shape
1388
+ const encoded = this._computeEncodes(_ref, context);
1389
+ if (encoded && encoded['@id'] === id) {
1390
+ target = encoded;
1391
+ break;
1392
+ }
1393
+ // case of a library which declares types
1394
+ if (!encoded) {
1395
+ target = this._findById(this._computeDeclares(_ref, context), id);
1396
+ if (target) break;
1397
+ }
1398
+ }
1399
+ return target;
1400
+ }
1401
+
1402
+ /**
1403
+ * Searches a node with a given ID in an array
1404
+ *
1405
+ * @param array Array to search for a given ID
1406
+ * @param id Id to search for
1407
+ * @returns Node with the given ID when found, undefined otherwise
1408
+ */
1409
+ _findById(array?: DomainElement[], id?: string): DomainElement | undefined {
1410
+ if (!array) return undefined;
1411
+ let target;
1412
+ for (let i = 0; i < array.length; i++) {
1413
+ const _current = array[i];
1414
+ if (_current && _current['@id'] === id) {
1415
+ target = _current;
1416
+ break;
1417
+ }
1418
+ }
1419
+ return target;
1420
+ }
1421
+
1422
+ _getReferenceId(amf?: AmfDocument, id?: string, context?: Record<string, string>): DomainElement | undefined {
1423
+ if (!amf || !id) {
1424
+ return undefined;
1425
+ }
1426
+ const refs = this._computeReferences(amf, context);
1427
+ if (!refs) {
1428
+ return undefined;
1429
+ }
1430
+ for (let i = 0; i < refs.length; i++) {
1431
+ const _ref = refs[i];
1432
+ const enc = this._computeEncodes(_ref, context);
1433
+ if (enc) {
1434
+ if (enc['@id'] === id) {
1435
+ return enc;
1436
+ }
1437
+ }
1438
+ }
1439
+ return undefined;
1440
+ }
1441
+
1442
+ _resolveRecursive(shape: any, context?: Record<string, string>): void {
1443
+ Object.keys(shape).forEach((key) => {
1444
+ const currentShape = shape[key];
1445
+ if (Array.isArray(currentShape)) {
1446
+ for (let i = 0, len = currentShape.length; i < len; i++) {
1447
+ currentShape[i] = this._resolve(currentShape[i]);
1448
+ }
1449
+ } else if (typeof currentShape === 'object') {
1450
+ /* eslint-disable-next-line no-param-reassign */
1451
+ shape[key] = this._resolve(currentShape, context);
1452
+ }
1453
+ });
1454
+ }
1455
+
1456
+ /**
1457
+ * Merge two shapes together. If the resulting shape has one of the "special merge" keys,
1458
+ * then the special merge function for that key will be used to match that property
1459
+ * @param shapeA AMF node
1460
+ * @param shapeB AMF node
1461
+ * @param context A context to use. If not set, it looks for the context of the passed model
1462
+ * @returns Merged AMF node
1463
+ */
1464
+ _mergeShapes(shapeA: any, shapeB: any, context?: Record<string, string>): any {
1465
+ const merged = { ...shapeA, ...shapeB };
1466
+ const specialMerges = [
1467
+ {
1468
+ key: this._getAmfKey(ns.aml.vocabularies.docSourceMaps.sources, context)!,
1469
+ merger: this._mergeSourceMapsSources.bind(this)
1470
+ },
1471
+ ];
1472
+ specialMerges.forEach(({ key, merger }) => {
1473
+ if (this._hasProperty(merged, key, context)) {
1474
+ merged[key] = merger(shapeA, shapeB, context);
1475
+ }
1476
+ });
1477
+ return Object.assign(shapeA, merged);
1478
+ }
1479
+
1480
+ /**
1481
+ * Obtains source map sources value from two shapes and returns the merged result
1482
+ * If neither shape has a sources node, then an empty object will be returned.
1483
+ * Result is wrapped in an array as per AMF model standard
1484
+ * @param shapeA AMF node
1485
+ * @param shapeB AMF node
1486
+ * @param context A context to use. If not set, it looks for the context of the passed model
1487
+ * @returns Empty object or resulting merge, wrapped in an array
1488
+ * @private
1489
+ */
1490
+ _mergeSourceMapsSources(shapeA: any, shapeB: any, context?: Record<string, string>): (any | {})[] {
1491
+ const sourcesKey = this._getAmfKey(ns.aml.vocabularies.docSourceMaps.sources, context)!;
1492
+ let aSources = shapeA[sourcesKey] || {};
1493
+ if (Array.isArray(aSources)) {
1494
+ aSources = aSources[0];
1495
+ }
1496
+ let bSources = shapeB[sourcesKey] || {};
1497
+ if (Array.isArray(bSources)) {
1498
+ bSources = bSources[0];
1499
+ }
1500
+ return [Object.assign(aSources, bSources)];
1501
+ }
1502
+
1503
+ /**
1504
+ * Expands the key property from compacted mode to full mode.
1505
+ * @param value The value to process
1506
+ * @returns The expanded value.
1507
+ */
1508
+ [expandKey](value: string, context?: Record<string, string>): string {
1509
+ let { amf } = this;
1510
+ if (!value || typeof value !== 'string' || (!amf && !context)) {
1511
+ return value;
1512
+ }
1513
+ if (Array.isArray(amf)) {
1514
+ [amf] = amf;
1515
+ }
1516
+ const ctx = context || amf && amf['@context'];
1517
+ if (!ctx) {
1518
+ return value;
1519
+ }
1520
+ const [root, key] = value.split(':');
1521
+ if (!root || !key) {
1522
+ return value;
1523
+ }
1524
+ const prefix = ctx[root];
1525
+ if (!prefix) {
1526
+ return value;
1527
+ }
1528
+ return `${prefix}${key}`;
1529
+ }
1530
+
1531
+ /**
1532
+ * Computes a security model from a reference (library for example).
1533
+ * @param domainId Domain id of the security requirement to find.
1534
+ * @param context A context to use. If not set, it looks for the context of the passed model
1535
+ * @returns Type definition or undefined if not found.
1536
+ */
1537
+ findSecurityScheme(domainId: string, context?: Record<string, string>): SecurityScheme | undefined {
1538
+ const { amf } = this;
1539
+ const declares = this._computeDeclares(amf, context);
1540
+ let result;
1541
+ if (declares) {
1542
+ result = declares.find((item) => item['@id'] === domainId);
1543
+ }
1544
+ if (result) {
1545
+ result = this._resolve(result);
1546
+ return result;
1547
+ }
1548
+ const references = this._computeReferences(amf, context);
1549
+ if (Array.isArray(references) && references.length) {
1550
+ for (const ref of references) {
1551
+ if (this._hasType(ref, ns.aml.vocabularies.document.Module, context)) {
1552
+ result = this[computeReferenceSecurity](ref, domainId, context);
1553
+ if (result) {
1554
+ result = this._resolve(result);
1555
+ return result;
1556
+ }
1557
+ }
1558
+ }
1559
+ }
1560
+ return undefined;
1561
+ }
1562
+
1563
+ /**
1564
+ * Computes a security model from a reference (library for example).
1565
+ * @param reference AMF model for a reference to extract the data from
1566
+ * @param selected Node ID to look for
1567
+ * @param context A context to use. If not set, it looks for the context of the passed model
1568
+ * @returns Type definition or undefined if not found.
1569
+ */
1570
+ [computeReferenceSecurity](reference: DomainElement, selected: string, context?: Record<string, string>): SecurityScheme | undefined {
1571
+ const declare = this._computeDeclares(reference, context);
1572
+ if (!declare) {
1573
+ return undefined;
1574
+ }
1575
+ let result = declare.find((item) => {
1576
+ let declared = item;
1577
+ if (Array.isArray(declared)) {
1578
+ [declared] = declared;
1579
+ }
1580
+ return declared['@id'] === selected;
1581
+ });
1582
+ if (Array.isArray(result)) {
1583
+ [result] = result;
1584
+ }
1585
+ return this._resolve(result);
1586
+ }
1587
+
1588
+ /**
1589
+ * Collects domain objects by a domain type.
1590
+ * @param source The element to search for declare/encoded objects.
1591
+ * @param type The domain type
1592
+ * @param context A context to use. If not set, it looks for the context of the passed model
1593
+ */
1594
+ getByType(source: DomainElement, type: string, context?: Record<string, string>): DomainElement[] {
1595
+ if (!source) {
1596
+ return [];
1597
+ }
1598
+ let result: DomainElement[] = [];
1599
+ const declares = this._computeDeclares(source);
1600
+ const key = this._getAmfKey(type, context);
1601
+ if (declares && declares.length) {
1602
+ declares.forEach((declared) => {
1603
+ if (this._hasType(declared, key)) {
1604
+ result.push(declared as DomainElement);
1605
+ }
1606
+ });
1607
+ }
1608
+ const references = this._computeReferences(source);
1609
+ if (Array.isArray(references) && references.length) {
1610
+ for (const ref of references) {
1611
+ if (this._hasType(ref, ns.aml.vocabularies.document.Module)) {
1612
+ const items = this.getByType(ref as DomainElement, type, context);
1613
+ if (items.length) {
1614
+ result = result.concat(items);
1615
+ }
1616
+ }
1617
+ }
1618
+ }
1619
+ return result;
1620
+ }
1621
+ }
1622
+ return AmfMixin as Constructor<AmfMixinInterface> & T;
1623
+ }