@mintlify/common 1.0.313 → 1.0.315
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asyncapi/getAsyncApiDocumentFromUrl.d.ts +2 -2
- package/dist/asyncapi/getAsyncApiDocumentFromUrl.js +20 -14
- package/dist/asyncapi/validateAsyncApi.d.ts +7 -0
- package/dist/asyncapi/{asyncApiCheck.js → validateAsyncApi.js} +19 -8
- package/dist/asyncapi.d.ts +1 -2
- package/dist/asyncapi.js +1 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/asyncapi.d.ts +14 -4
- package/package.json +3 -3
- package/dist/asyncapi/asyncApiCheck.d.ts +0 -2
- package/dist/asyncapi/validate.d.ts +0 -7
- package/dist/asyncapi/validate.js +0 -20
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getAsyncApiDocumentFromUrl: (url: string) => Promise<
|
|
1
|
+
import { AsyncAPIDocumentInterface } from '../types/asyncapi.js';
|
|
2
|
+
export declare const getAsyncApiDocumentFromUrl: (url: string) => Promise<AsyncAPIDocumentInterface>;
|
|
@@ -7,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import yaml from 'js-yaml';
|
|
10
|
+
import { validateAsyncApi } from './validateAsyncApi.js';
|
|
12
11
|
export const getAsyncApiDocumentFromUrl = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
12
|
try {
|
|
14
13
|
new URL(url);
|
|
@@ -16,19 +15,26 @@ export const getAsyncApiDocumentFromUrl = (url) => __awaiter(void 0, void 0, voi
|
|
|
16
15
|
catch (error) {
|
|
17
16
|
throw new Error(`Invalid URL: ${url}`);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
const parser = new Parser();
|
|
26
|
-
const diagnostic = yield parser.validate(asyncApiDocument);
|
|
27
|
-
if (diagnostic.length > 0) {
|
|
28
|
-
const firstDiagnosis = diagnostic[0];
|
|
29
|
-
if (firstDiagnosis) {
|
|
30
|
-
throw new Error(`This AsyncAPI document is invalid, ${firstDiagnosis.path}, ${firstDiagnosis.code}`);
|
|
18
|
+
let response;
|
|
19
|
+
try {
|
|
20
|
+
response = yield fetch(url);
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
31
23
|
}
|
|
32
24
|
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`Failed to fetch AsyncAPI document from ${url}`);
|
|
27
|
+
}
|
|
28
|
+
let data;
|
|
29
|
+
try {
|
|
30
|
+
data = yield response.text();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error(`Failed to read response from ${url}`);
|
|
34
|
+
}
|
|
35
|
+
const { document: asyncApiDocument, errorMessage } = yield validateAsyncApi(data);
|
|
36
|
+
if (!asyncApiDocument) {
|
|
37
|
+
throw new Error(`Could not load AsyncAPI document from ${url}:\n ${errorMessage}`);
|
|
38
|
+
}
|
|
33
39
|
return asyncApiDocument;
|
|
34
40
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AsyncAPIDocumentInterface, AsyncAPIParserInput } from '../types/asyncapi.js';
|
|
2
|
+
export type ValidateAsyncApiResult = {
|
|
3
|
+
valid: boolean;
|
|
4
|
+
errorMessage?: string;
|
|
5
|
+
document?: AsyncAPIDocumentInterface;
|
|
6
|
+
};
|
|
7
|
+
export declare function validateAsyncApi(str: AsyncAPIParserInput): Promise<ValidateAsyncApiResult>;
|
|
@@ -8,20 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Parser } from '@asyncapi/parser';
|
|
11
|
-
export function
|
|
11
|
+
export function validateAsyncApi(str) {
|
|
12
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
var _a;
|
|
14
13
|
try {
|
|
15
|
-
const objectAsInput = typeof obj === 'string' ? obj : JSON.stringify(obj);
|
|
16
14
|
const parser = new Parser();
|
|
17
|
-
const { document
|
|
15
|
+
const { document, diagnostics } = yield parser.parse(str);
|
|
18
16
|
if (diagnostics.length > 0) {
|
|
19
|
-
|
|
17
|
+
const errorMessages = diagnostics.map((diagnostic) => diagnostic.message).join('\n');
|
|
18
|
+
return {
|
|
19
|
+
valid: false,
|
|
20
|
+
errorMessage: errorMessages,
|
|
21
|
+
document: undefined,
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
valid: true,
|
|
26
|
+
errorMessage: undefined,
|
|
27
|
+
document,
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
|
-
catch (
|
|
24
|
-
return
|
|
30
|
+
catch (error) {
|
|
31
|
+
return {
|
|
32
|
+
valid: false,
|
|
33
|
+
errorMessage: `Error validating AsyncAPI document, ${error}`,
|
|
34
|
+
document: undefined,
|
|
35
|
+
};
|
|
25
36
|
}
|
|
26
37
|
});
|
|
27
38
|
}
|
package/dist/asyncapi.d.ts
CHANGED
package/dist/asyncapi.js
CHANGED