@salesforcedevs/docs-components 0.17.0 → 0.17.12-search-alpha

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 (114) hide show
  1. package/lwc.config.json +18 -3
  2. package/package.json +18 -7
  3. package/src/modules/README.md +41 -0
  4. package/src/modules/doc/amfModelParser/amfModelParser.ts +674 -0
  5. package/src/modules/doc/amfReference/amfReference.css +25 -0
  6. package/src/modules/doc/amfReference/amfReference.html +55 -0
  7. package/src/modules/doc/amfReference/amfReference.ts +1467 -0
  8. package/src/modules/doc/amfReference/constants.ts +76 -0
  9. package/src/modules/doc/amfReference/types.ts +125 -0
  10. package/src/modules/doc/amfTopic/amfTopic.css +21 -0
  11. package/src/modules/doc/amfTopic/amfTopic.html +3 -0
  12. package/src/modules/doc/amfTopic/amfTopic.ts +111 -0
  13. package/src/modules/doc/amfTopic/types.ts +56 -0
  14. package/src/modules/doc/amfTopic/utils.ts +136 -0
  15. package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +51 -0
  16. package/src/modules/doc/breadcrumbItem/breadcrumbItem.html +5 -0
  17. package/src/modules/doc/breadcrumbItem/breadcrumbItem.ts +71 -0
  18. package/src/modules/doc/breadcrumbs/breadcrumbs.css +27 -0
  19. package/src/modules/doc/breadcrumbs/breadcrumbs.html +58 -0
  20. package/src/modules/doc/breadcrumbs/breadcrumbs.ts +183 -0
  21. package/src/modules/doc/componentPlayground/componentPlayground.css +22 -0
  22. package/src/modules/doc/componentPlayground/componentPlayground.html +20 -0
  23. package/src/modules/doc/componentPlayground/componentPlayground.ts +42 -0
  24. package/src/modules/doc/content/content.css +89 -70
  25. package/src/modules/doc/content/content.html +1 -0
  26. package/src/modules/doc/content/content.ts +188 -195
  27. package/src/modules/doc/contentCallout/contentCallout.css +17 -23
  28. package/src/modules/doc/contentCallout/contentCallout.html +13 -4
  29. package/src/modules/doc/contentCallout/contentCallout.ts +16 -3
  30. package/src/modules/doc/contentLayout/contentLayout.css +1 -0
  31. package/src/modules/doc/contentLayout/contentLayout.html +46 -0
  32. package/src/modules/doc/contentLayout/contentLayout.ts +524 -0
  33. package/src/modules/doc/doDont/doDont.css +47 -0
  34. package/src/modules/doc/doDont/doDont.html +27 -0
  35. package/src/modules/doc/doDont/doDont.ts +17 -0
  36. package/src/modules/doc/header/header.css +70 -37
  37. package/src/modules/doc/header/header.html +41 -138
  38. package/src/modules/doc/header/header.ts +56 -78
  39. package/src/modules/doc/heading/heading.css +33 -0
  40. package/src/modules/doc/heading/heading.html +14 -0
  41. package/src/modules/doc/heading/heading.ts +67 -0
  42. package/src/modules/doc/headingAnchor/headingAnchor.css +3 -3
  43. package/src/modules/doc/headingAnchor/headingAnchor.ts +2 -2
  44. package/src/modules/doc/headingContent/headingContent.css +53 -0
  45. package/src/modules/doc/headingContent/headingContent.html +13 -0
  46. package/src/modules/doc/headingContent/headingContent.ts +30 -0
  47. package/src/modules/doc/lwcContentLayout/lwcContentLayout.css +1 -0
  48. package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +45 -0
  49. package/src/modules/doc/lwcContentLayout/lwcContentLayout.ts +256 -0
  50. package/src/modules/doc/overview/overview.css +40 -0
  51. package/src/modules/doc/overview/overview.html +34 -0
  52. package/src/modules/doc/overview/overview.ts +12 -0
  53. package/src/modules/doc/phase/phase.css +70 -0
  54. package/src/modules/doc/phase/phase.html +38 -0
  55. package/src/modules/doc/phase/phase.ts +93 -0
  56. package/src/modules/doc/specificationContent/specificationContent.css +36 -0
  57. package/src/modules/doc/specificationContent/specificationContent.html +167 -0
  58. package/src/modules/doc/specificationContent/specificationContent.ts +127 -0
  59. package/src/modules/doc/sprigSurvey/sprigSurvey.html +20 -0
  60. package/src/modules/doc/sprigSurvey/sprigSurvey.scoped.css +16 -0
  61. package/src/modules/doc/sprigSurvey/sprigSurvey.ts +16 -0
  62. package/src/modules/doc/toc/toc.ts +1 -1
  63. package/src/modules/doc/versionPicker/versionPicker.css +64 -0
  64. package/src/modules/doc/versionPicker/versionPicker.html +38 -0
  65. package/src/modules/doc/versionPicker/versionPicker.ts +65 -0
  66. package/src/modules/doc/xmlContent/types.ts +120 -0
  67. package/src/modules/doc/xmlContent/utils.ts +163 -0
  68. package/src/modules/doc/xmlContent/xmlContent.css +54 -0
  69. package/src/modules/doc/xmlContent/xmlContent.html +54 -0
  70. package/src/modules/doc/xmlContent/xmlContent.ts +763 -0
  71. package/src/modules/docHelpers/amfStyle/amfStyle.css +355 -0
  72. package/src/modules/docHelpers/contentLayoutStyle/contentLayoutStyle.css +131 -0
  73. package/src/modules/docHelpers/imgStyle/imgStyle.css +59 -0
  74. package/src/modules/docHelpers/status/status.css +22 -0
  75. package/src/modules/docUtils/searchSyncer/searchSyncer.ts +86 -0
  76. package/src/modules/docUtils/utils/__mocks__/coveo.analytics.ts +16 -0
  77. package/src/modules/docUtils/utils/coveo.analytics.d.ts +10 -0
  78. package/src/modules/docUtils/utils/utils.ts +32 -0
  79. package/LICENSE +0 -12
  80. package/src/modules/doc/content/__tests__/content.test.ts +0 -312
  81. package/src/modules/doc/content/__tests__/mockDocContent.ts +0 -348
  82. package/src/modules/doc/content/__tests__/mockPageReference.ts +0 -8
  83. package/src/modules/doc/content/__tests__/mockSidebar.ts +0 -81
  84. package/src/modules/doc/content/content.stories.ts +0 -148
  85. package/src/modules/doc/contentCallout/__tests__/contentCallout.test.ts +0 -80
  86. package/src/modules/doc/contentCallout/__tests__/mockProps.ts +0 -14
  87. package/src/modules/doc/contentCallout/contentCallout.stories.ts +0 -29
  88. package/src/modules/doc/contentMedia/__tests__/contentMedia.test.ts +0 -97
  89. package/src/modules/doc/contentMedia/contentMedia.stories.ts +0 -113
  90. package/src/modules/doc/header/__tests__/coveoConfig.ts +0 -12
  91. package/src/modules/doc/header/__tests__/header.test.ts +0 -445
  92. package/src/modules/doc/header/__tests__/mockNavDevelopers.ts +0 -427
  93. package/src/modules/doc/header/__tests__/mockNavs.ts +0 -115
  94. package/src/modules/doc/header/__tests__/mockProps.ts +0 -152
  95. package/src/modules/doc/header/header.stories.ts +0 -190
  96. package/src/modules/doc/headingAnchor/__tests__/headingAnchor.test.ts +0 -111
  97. package/src/modules/doc/headingAnchor/headingAnchor.stories.ts +0 -33
  98. package/src/modules/doc/nav/__tests__/mockAvailableLanguages.ts +0 -8
  99. package/src/modules/doc/nav/__tests__/mockAvailableVersions.ts +0 -122
  100. package/src/modules/doc/nav/__tests__/mockPageReference.ts +0 -8
  101. package/src/modules/doc/nav/__tests__/mockPdfUrl.ts +0 -1
  102. package/src/modules/doc/nav/__tests__/mockSelectedLanguage.ts +0 -8
  103. package/src/modules/doc/nav/__tests__/mockSelectedVersion.ts +0 -8
  104. package/src/modules/doc/nav/__tests__/mockToc.ts +0 -146
  105. package/src/modules/doc/nav/__tests__/nav.test.ts +0 -58
  106. package/src/modules/doc/toc/__tests__/mockPageReference.ts +0 -8
  107. package/src/modules/doc/toc/__tests__/mockToc.ts +0 -146
  108. package/src/modules/doc/toc/__tests__/toc.test.ts +0 -29
  109. package/src/modules/doc/toolbar/__tests__/mockAvailableLanguages.ts +0 -8
  110. package/src/modules/doc/toolbar/__tests__/mockAvailableVersions.ts +0 -122
  111. package/src/modules/doc/toolbar/__tests__/mockPdfUrl.ts +0 -1
  112. package/src/modules/doc/toolbar/__tests__/mockSelectedLanguage.ts +0 -8
  113. package/src/modules/doc/toolbar/__tests__/mockSelectedVersion.ts +0 -8
  114. package/src/modules/doc/toolbar/__tests__/toolbar.test.ts +0 -44
@@ -0,0 +1,674 @@
1
+ // @ts-nocheck not going to check this file because it deals almost entirely with the AmfHelperMixin, which is terrible and not worth messing with. We should just upgrade our LWC version instead.
2
+ import {
3
+ AmfHelperMixin,
4
+ EndPoint,
5
+ Operation
6
+ } from "@api-components/amf-helper-mixin";
7
+ import { normalizeDomId } from "dxUtils/normalizers";
8
+
9
+ const ID_PROPERTY = "@id";
10
+ const TYPE_PROPERTY = "@type";
11
+
12
+ export class AmfModelParser extends AmfHelperMixin(Object) {
13
+ _parsedModel = null;
14
+
15
+ constructor(api: any) {
16
+ super();
17
+ if (api) {
18
+ this.amf = Array.isArray(api) ? api[0] : api;
19
+ }
20
+ }
21
+
22
+ parse() {
23
+ let model = this.amf;
24
+ let data = {};
25
+ let isFragment = true;
26
+ const moduleKey = this._getAmfKey(
27
+ this.ns.aml.vocabularies.document.Module
28
+ );
29
+ if (this._hasType(model, this.ns.aml.vocabularies.document.Document)) {
30
+ isFragment = false;
31
+ model = this._ensureAmfModel(model);
32
+ data = this._collectData(model);
33
+ } else if (
34
+ this._hasType(
35
+ model,
36
+ this.ns.aml.vocabularies.security.SecuritySchemeFragment
37
+ )
38
+ ) {
39
+ data = this._collectSecurityData(model);
40
+ } else if (
41
+ this._hasType(
42
+ model,
43
+ this.ns.aml.vocabularies.apiContract.UserDocumentationFragment
44
+ )
45
+ ) {
46
+ data = this._collectDocumentationData(model);
47
+ } else if (
48
+ this._hasType(
49
+ model,
50
+ this.ns.aml.vocabularies.shapes.DataTypeFragment
51
+ )
52
+ ) {
53
+ data = this._collectTypeData(model);
54
+ } else if (
55
+ model[TYPE_PROPERTY] &&
56
+ moduleKey === model[TYPE_PROPERTY][0]
57
+ ) {
58
+ data = this._collectData(model);
59
+ }
60
+
61
+ this._collectName(model, data);
62
+
63
+ const summaryId = data.title + "Summary";
64
+
65
+ return {
66
+ title: data.title,
67
+ summary: {
68
+ id: summaryId,
69
+ label: "Summary",
70
+ domId: normalizeDomId(summaryId)
71
+ },
72
+ types: data.types,
73
+ security: data.securitySchemes,
74
+ endpoints: data.endpoints,
75
+ docs: data.documentation,
76
+ isFragment
77
+ };
78
+ }
79
+
80
+ get parsedModel() {
81
+ if (!this._parsedModel) {
82
+ this._parsedModel = this.parse();
83
+ }
84
+
85
+ return this._parsedModel;
86
+ }
87
+
88
+ /**
89
+ * Collects the information about the API and creates data model
90
+ * for the navigation element
91
+ *
92
+ * @param {object} model
93
+ * @return {Object} Data model for the API navigation
94
+ */
95
+ _collectData(model) {
96
+ const result = {
97
+ documentation: [],
98
+ types: [],
99
+ securitySchemes: [],
100
+ endpoints: []
101
+ };
102
+ if (!model) {
103
+ return result;
104
+ }
105
+ result._typeIds = [];
106
+ result._basePaths = [];
107
+ this._traverseDeclarations(model, result);
108
+ this._traverseReferences(model, result);
109
+ this._traverseEncodes(model, result);
110
+ delete result._typeIds;
111
+ delete result._basePaths;
112
+ return result;
113
+ }
114
+
115
+ /**
116
+ * Collects the data from the security fragment
117
+ * @param {object} model Security fragment model
118
+ * @return {Object|undefined}
119
+ */
120
+ _collectSecurityData(model) {
121
+ const result = {
122
+ securitySchemes: []
123
+ };
124
+ const encodes = this._computeEncodes(model);
125
+ if (!encodes) {
126
+ return undefined;
127
+ }
128
+ this._appendSecurityItem(encodes, result);
129
+ return result;
130
+ }
131
+
132
+ /**
133
+ * Collects the data from the documentation fragment
134
+ * @param {object} model Documentation fragment model
135
+ * @return {Object|undefined}
136
+ */
137
+ _collectDocumentationData(model) {
138
+ const result = {
139
+ documentation: []
140
+ };
141
+ const encodes = this._computeEncodes(model);
142
+ if (!encodes) {
143
+ return undefined;
144
+ }
145
+ this._appendDocumentationItem(encodes, result);
146
+ return result;
147
+ }
148
+
149
+ /**
150
+ * Collects the data from the type fragment
151
+ * @param {object} model Type fragment model
152
+ * @return {Object|undefined}
153
+ */
154
+ _collectTypeData(model) {
155
+ const result = {
156
+ types: [],
157
+ _typeIds: []
158
+ };
159
+ const encodes = this._computeEncodes(model);
160
+ if (!encodes) {
161
+ return undefined;
162
+ }
163
+ this._appendTypeItem(encodes, result);
164
+ delete result._typeIds;
165
+ return result;
166
+ }
167
+
168
+ /**
169
+ * Traverses the `http://raml.org/vocabularies/document#declares`
170
+ * node to find types and security schemes.
171
+ *
172
+ * @param {object} model AMF model
173
+ * @param {TargetModel} target Target object where to put data.
174
+ */
175
+ _traverseDeclarations(model, target) {
176
+ const declares = this._computeDeclares(model);
177
+ if (!declares) {
178
+ return;
179
+ }
180
+ declares.forEach((item) => this._appendModelItem(item, target));
181
+ }
182
+
183
+ /**
184
+ * Traverses the `http://raml.org/vocabularies/document#references`
185
+ *
186
+ * @param {object} model AMF model
187
+ * @param {TargetModel} target Target object where to put data.
188
+ */
189
+ _traverseReferences(model, target) {
190
+ const refs = this._computeReferences(model);
191
+ if (!refs) {
192
+ return;
193
+ }
194
+ refs.forEach((item) => {
195
+ if (
196
+ !this._hasType(item, this.ns.aml.vocabularies.document.Module)
197
+ ) {
198
+ return;
199
+ }
200
+ this._traverseDeclarations(item, target);
201
+ });
202
+ }
203
+
204
+ /**
205
+ * Traverses the `http://raml.org/vocabularies/document#encodes`
206
+ * node to find documentation and endpoints.
207
+ *
208
+ * @param {object} model AMF model
209
+ * @param {TargetModel} target Target object where to put data.
210
+ */
211
+ _traverseEncodes(model, target) {
212
+ const webApi = this._computeWebApi(model);
213
+ const endpoints = this._computeEndpoints(webApi);
214
+
215
+ if (endpoints) {
216
+ endpoints.forEach((item) => this._appendModelItem(item, target));
217
+ }
218
+ const dkey = this._getAmfKey(
219
+ this.ns.aml.vocabularies.core.documentation
220
+ );
221
+ const documentation = this._ensureArray(webApi[dkey]);
222
+ if (documentation) {
223
+ documentation.forEach((item) =>
224
+ this._appendModelItem(item, target)
225
+ );
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Extract API title from `http://raml.org/vocabularies/document#encodes`
231
+ *
232
+ * @param {object} model AMF model
233
+ * @param {TargetModel} target Target object where to put data.
234
+ */
235
+ _collectName(model, target) {
236
+ const encodes = this._computeEncodes(model);
237
+ if (!encodes) {
238
+ return;
239
+ }
240
+
241
+ target.title = this._getValue(
242
+ encodes,
243
+ this._getAmfKey(this.ns.aml.vocabularies.core.name)
244
+ );
245
+ }
246
+
247
+ /**
248
+ * Appends declaration of navigation data model to the target if
249
+ * it matches documentation or security types.
250
+ *
251
+ * @param {Object} item AMF model item to check for data.
252
+ * @param {TargetModel} target The target to which append values.
253
+ * @return {void}
254
+ */
255
+ _appendModelItem(item, target) {
256
+ if (this._hasType(item, this.ns.w3.shacl.Shape)) {
257
+ this._appendTypeItem(item, target);
258
+ } else if (
259
+ this._hasType(
260
+ item,
261
+ this.ns.aml.vocabularies.security.SecurityScheme
262
+ )
263
+ ) {
264
+ this._appendSecurityItem(item, target);
265
+ } else if (
266
+ this._hasType(item, this.ns.aml.vocabularies.core.CreativeWork)
267
+ ) {
268
+ this._appendDocumentationItem(item, target);
269
+ } else if (
270
+ this._hasType(item, this.ns.aml.vocabularies.apiContract.EndPoint)
271
+ ) {
272
+ this._appendEndpointItem(item, target);
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Appends "type" item to the results.
278
+ *
279
+ * @param {Object} item Type item declaration
280
+ * @param {TargetModel} target
281
+ * @return {void}
282
+ */
283
+ _appendTypeItem(item, target) {
284
+ const w3name = this._getValue(item, this.ns.w3.shacl.name);
285
+ if (w3name && w3name.indexOf("amf_inline_type") === 0) {
286
+ // https://www.mulesoft.org/jira/browse/APIMF-972
287
+ return;
288
+ }
289
+ let name = this._getValue(item, this.ns.aml.vocabularies.core.name);
290
+ if (!name && w3name) {
291
+ name = w3name;
292
+ } else if (!name) {
293
+ return;
294
+ }
295
+ const id = item[ID_PROPERTY];
296
+ if (!id) {
297
+ return;
298
+ }
299
+ const rfIdKey = this._getAmfKey(
300
+ this.ns.aml.vocabularies.document.referenceId
301
+ );
302
+ const compareId = id;
303
+ const refNode = this._ensureArray(item[rfIdKey]);
304
+ const refId = refNode ? refNode[0][ID_PROPERTY] : undefined;
305
+ const idIndex = target._typeIds.indexOf(compareId);
306
+ const refIndex = refId ? target._typeIds.indexOf(refId) : -1;
307
+ if (idIndex === -1 && refIndex === -1) {
308
+ target._typeIds[target._typeIds.length] = id;
309
+ if (refId) {
310
+ target._typeIds[target._typeIds.length] = refId;
311
+ }
312
+ target.types.push({
313
+ label: name,
314
+ id,
315
+ domId: normalizeDomId(id)
316
+ });
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Appends "security" item to the results.
322
+ *
323
+ * @param {Object} item Type item declaration
324
+ * @param {TargetModel} target
325
+ * @return {void}
326
+ */
327
+ _appendSecurityItem(item, target) {
328
+ const voc = this.ns.aml.vocabularies;
329
+ let name = this._getValue(item, voc.core.displayName);
330
+ if (!name) {
331
+ name = this._getValue(item, voc.security.name);
332
+ }
333
+ if (!name) {
334
+ const apiName = this._getValue(item, voc.core.name);
335
+ const secType = this._getValue(item, voc.security.type);
336
+ let result = "";
337
+ if (apiName) {
338
+ result = `${apiName} - `;
339
+ }
340
+ name = result + this._mapAuthName(secType);
341
+ }
342
+ const id = item[ID_PROPERTY];
343
+ target.securitySchemes.push({
344
+ label: String(name),
345
+ id,
346
+ domId: normalizeDomId(id)
347
+ });
348
+ }
349
+
350
+ /**
351
+ * Maps authorization scheme name to a label
352
+ * @param {string} name
353
+ * @return {string}
354
+ */
355
+ _mapAuthName(name) {
356
+ switch (name) {
357
+ case "http":
358
+ return "HTTP";
359
+ case "openIdConnect":
360
+ return "OpenID Connect";
361
+ default:
362
+ return name;
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Checks if url is valid and return it, otherwise returns 'about:blank'.
368
+ * @param {string} url
369
+ * @return {string}
370
+ */
371
+ _validUrl(url) {
372
+ return url.startsWith("http://") || url.startsWith("https://")
373
+ ? url
374
+ : "about:blank";
375
+ }
376
+
377
+ /**
378
+ * Appends "documentation" item to the results.
379
+ *
380
+ * @param {Object} item Type item declaration
381
+ * @param {TargetModel} target
382
+ * @return {void}
383
+ */
384
+ _appendDocumentationItem(item, target) {
385
+ const { core } = this.ns.aml.vocabularies;
386
+ const id = item[ID_PROPERTY];
387
+ const urlNode = item[this._getAmfKey(core.url)];
388
+ const title = this._getValue(item, core.title);
389
+ const description = this._getValue(item, core.description);
390
+ const label = title ? String(title) : String(description);
391
+ let isExternal = false;
392
+ let url = urlNode ? (urlNode[0] || urlNode)[ID_PROPERTY] : undefined;
393
+ if (url) {
394
+ url = this._validUrl(url);
395
+ isExternal = true;
396
+ }
397
+ const result = {
398
+ id,
399
+ label,
400
+ isExternal,
401
+ url,
402
+ domId: normalizeDomId(id)
403
+ };
404
+ target.documentation.push(result);
405
+ }
406
+
407
+ /**
408
+ * Appends "endpoint" item to the results.
409
+ * This also iterates over methods to extract method data.
410
+ *
411
+ * @param {Object} item Endpoint item declaration
412
+ * @param {TargetModel} target
413
+ * @return {void}
414
+ */
415
+ _appendEndpointItem(item, target) {
416
+ const result = {};
417
+
418
+ let name = this._getValue(item, this.ns.aml.vocabularies.core.name);
419
+ const path = this._getValue(
420
+ item,
421
+ this.ns.raml.vocabularies.apiContract.path
422
+ );
423
+ result.path = path;
424
+
425
+ let tmpPath = path;
426
+ if (tmpPath[0] === "/") {
427
+ tmpPath = tmpPath.substr(1);
428
+ }
429
+ const parts = tmpPath.split("/");
430
+ let indent = 0;
431
+ target._basePaths[target._basePaths.length] = path;
432
+ if (parts.length > 1) {
433
+ const lowerParts = parts.slice(0, parts.length - 1);
434
+ if (lowerParts.length) {
435
+ for (let i = lowerParts.length - 1; i >= 0; i--) {
436
+ const currentPath = `/${lowerParts
437
+ .slice(0, i + 1)
438
+ .join("/")}`;
439
+ if (target._basePaths.indexOf(currentPath) !== -1) {
440
+ indent++;
441
+ }
442
+ }
443
+ }
444
+ }
445
+ if (!name) {
446
+ result.renderPath = false;
447
+ if (indent > 0) {
448
+ try {
449
+ name = this._computePathName(
450
+ path,
451
+ parts,
452
+ indent,
453
+ target._basePaths
454
+ );
455
+ } catch (_) {
456
+ name = path;
457
+ }
458
+ } else {
459
+ name = path;
460
+ }
461
+ } else {
462
+ result.renderPath = true;
463
+ }
464
+ const id = item[ID_PROPERTY];
465
+ const key = this._getAmfKey(this.ns.w3.hydra.supportedOperation);
466
+ const operations = this._ensureArray(item[key]) || [];
467
+ const methods = operations.map((op) => this._createOperationModel(op));
468
+ result.label = String(name);
469
+ result.id = id;
470
+ result.indent = indent;
471
+ result.methods = methods;
472
+ result.domId = normalizeDomId(id);
473
+ target.endpoints.push(result);
474
+ }
475
+
476
+ /**
477
+ * Computes label for an endpoint when name is missing and the endpoint
478
+ * is indented, hence name should be truncated.
479
+ * @param {string} currentPath Endpoint's path
480
+ * @param {string[]} parts Path parts
481
+ * @param {number} indent Endpoint indentation
482
+ * @param {string[]} basePaths List of base paths already used.
483
+ * @return {string} Name of the path to render.
484
+ */
485
+ _computePathName(currentPath, parts, indent, basePaths) {
486
+ let path = "";
487
+ for (let i = 0, len = parts.length; i < len; i++) {
488
+ path += `/${parts[i]}`;
489
+ if (basePaths.indexOf(path) !== -1) {
490
+ indent--;
491
+ }
492
+ if (indent === 0) {
493
+ break;
494
+ }
495
+ }
496
+ return currentPath.replace(path, "");
497
+ }
498
+
499
+ /**
500
+ * Creates the view model for an opration.
501
+ *
502
+ * @param {Object} item Operation AMF model
503
+ * @return {Object} Method view model
504
+ */
505
+ _createOperationModel(item) {
506
+ const label = this._getValue(item, this.ns.aml.vocabularies.core.name);
507
+ const methodKey = this.ns.aml.vocabularies.apiContract.method;
508
+ const id = item[ID_PROPERTY];
509
+ const method = this._getValue(item, methodKey);
510
+ return {
511
+ label,
512
+ id,
513
+ method,
514
+ domId: normalizeDomId(id)
515
+ };
516
+ }
517
+
518
+ /**
519
+ * Computes Endpoint definition model from web API and current selection.
520
+ *
521
+ * @param {any} model WebApi AMF model. Do not use an array here.
522
+ * @param {string} selected Currently selected `@id`.
523
+ * @return {any|undefined} Model definition for an endpoint fragment.
524
+ */
525
+ computeEndpointApiModel(model, selectedId): EndPoint {
526
+ const webApi = this._computeApi(model);
527
+ return this._computeEndpointModel(webApi, selectedId);
528
+ }
529
+
530
+ /**
531
+ * Computes Method definition model from web API and current selection.
532
+ *
533
+ * @param {any} model WebApi AMF model. Do not use an array here.
534
+ * @param {string} selected Currently selected `@id`.
535
+ * @return {any|undefined} Model definition for an endpoint fragment.
536
+ */
537
+ computeMethodApiModel(model, selected): Operation | undefined {
538
+ const webApi = this._computeApi(model);
539
+ return this._computeMethodModel(webApi, selected);
540
+ }
541
+
542
+ /**
543
+ * Computes Endpoint definition model for a method from web API and current selection.
544
+ *
545
+ * @param {any} model WebApi AMF model. Do not use an array here.
546
+ * @param {string} selected Currently selected `@id`.
547
+ * @return {any|undefined} Model definition for an endpoint fragment.
548
+ */
549
+ computeEndpointApiMethodModel(model, selected): EndPoint | undefined {
550
+ const webApi = this._computeApi(model);
551
+ return this._computeMethodEndpoint(webApi, selected);
552
+ }
553
+
554
+ /**
555
+ * Computes security scheme definition model from web API and current selection.
556
+ * It looks for the definition in both `declares` and `references` properties.
557
+ * Returned value is already resolved AMF model (references are resolved).
558
+ *
559
+ * @param {any} model WebApi AMF model. Do not use an array here.
560
+ * @param {string} selected Currently selected `@id`.
561
+ * @return {any|undefined} Model definition for the security scheme.
562
+ */
563
+ computeSecurityApiModel(model, selected) {
564
+ const declares = this._computeDeclares(model);
565
+ let result;
566
+ if (declares) {
567
+ result = declares.find((item) => item["@id"] === selected);
568
+ }
569
+ if (!result) {
570
+ const references = this._computeReferences(model);
571
+ if (references && references.length) {
572
+ for (let i = 0, len = references.length; i < len; i++) {
573
+ if (
574
+ !this._hasType(
575
+ references[i],
576
+ this.ns.aml.vocabularies.document.Module
577
+ )
578
+ ) {
579
+ continue;
580
+ }
581
+ result = this._computeReferenceSecurity(
582
+ references[i],
583
+ selected
584
+ );
585
+ if (result) {
586
+ break;
587
+ }
588
+ }
589
+ }
590
+ } else {
591
+ result = this._resolve(result);
592
+ }
593
+ return result;
594
+ }
595
+
596
+ /**
597
+ * Computes documentation definition model from web API and current selection.
598
+ *
599
+ * @param {any} model WebApi AMF model. Do not use an array here.
600
+ * @param {string} selected Currently selected `@id`.
601
+ * @return {any|undefined} Model definition for a documentation fragment.
602
+ */
603
+ computeDocsApiModel(model, selected) {
604
+ const webApi = this._computeApi(model);
605
+ return this._computeDocument(webApi, selected);
606
+ }
607
+
608
+ /**
609
+ * Computes type definition model from web API and current selection.
610
+ * It looks for the definition in both `declares` and `references` properties.
611
+ * Returned value is already resolved AMF model (references are resolved).
612
+ *
613
+ * @param {any} model WebApi AMF model. Do not use an array here.
614
+ * @param {string} selected Currently selected `@id`.
615
+ * @return {any|undefined} Model definition for a type.
616
+ */
617
+ computeTypeApiModel(model, selected) {
618
+ const declares = this._computeDeclares(model);
619
+ const references = this._computeReferences(model);
620
+ return this._computeType(declares, references, selected);
621
+ }
622
+
623
+ /**
624
+ * Computes a security model from a reference (library for example).
625
+ * @param {any|any[]} reference AMF model for a reference to extract the data from
626
+ * @param {string} selected Node ID to look for
627
+ * @return {any|undefined} Type definition or undefined if not found.
628
+ */
629
+ _computeReferenceSecurity(reference, selected) {
630
+ const declare = this._computeDeclares(reference);
631
+ if (!declare) {
632
+ return undefined;
633
+ }
634
+ let result = declare.find((item) => {
635
+ if (Array.isArray(item)) {
636
+ [item] = item;
637
+ }
638
+ return item["@id"] === selected;
639
+ });
640
+ if (Array.isArray(result)) {
641
+ [result] = result;
642
+ }
643
+ return this._resolve(result);
644
+ }
645
+
646
+ /**
647
+ * Computes API's media types when requesting type documentation view.
648
+ * This is passed to the type documentation to render examples in the type
649
+ * according to API's defined media type.
650
+ *
651
+ * @param {any} model API model.
652
+ * @return {string[]|undefined} List of supported media types or undefined.
653
+ */
654
+ computeApiMediaTypes(model) {
655
+ if (Array.isArray(model)) {
656
+ [model] = model;
657
+ }
658
+ let webApi = this._computeWebApi(model);
659
+ if (!webApi) {
660
+ return undefined;
661
+ }
662
+ if (Array.isArray(webApi)) {
663
+ [webApi] = webApi;
664
+ }
665
+ const key = this._getAmfKey(
666
+ this.ns.aml.vocabularies.apiContract.accepts
667
+ );
668
+ const value = this._ensureArray(webApi[key]);
669
+ if (value) {
670
+ return value.map((item) => item["@value"]);
671
+ }
672
+ return undefined;
673
+ }
674
+ }
@@ -0,0 +1,25 @@
1
+ doc-phase {
2
+ --doc-c-phase-top: calc(
3
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
4
+ var(--dx-g-spacing-xl)
5
+ );
6
+ }
7
+
8
+ /* We need to apply some borders when there are two doc phases */
9
+ doc-phase:not(:only-of-type)::part(container) {
10
+ border-top: 1px solid var(--dx-g-yellow-vibrant-90);
11
+ }
12
+
13
+ doc-phase:nth-child(2)::part(container) {
14
+ border-top: 1px solid var(--dx-g-yellow-vibrant-90);
15
+ border-bottom: 1px solid var(--dx-g-yellow-vibrant-90);
16
+ }
17
+
18
+ /* We don't want second component to sticky as we need to handle different cases like position */
19
+ doc-phase:nth-child(2) {
20
+ position: static;
21
+ }
22
+
23
+ .api-documentation {
24
+ margin-top: 48px;
25
+ }