@mintlify/previewing 3.1.55 → 3.1.57

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 (34) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +17 -17
  3. package/dist/constants.d.ts +9 -9
  4. package/dist/constants.js +31 -31
  5. package/dist/downloadImage.d.ts +4 -4
  6. package/dist/downloadImage.js +139 -139
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +3 -3
  9. package/dist/local-preview/helper-commands/installDepsCommand.d.ts +2 -2
  10. package/dist/local-preview/helper-commands/installDepsCommand.js +51 -51
  11. package/dist/local-preview/index.d.ts +3 -3
  12. package/dist/local-preview/index.js +212 -212
  13. package/dist/local-preview/listener/categorize.d.ts +8 -8
  14. package/dist/local-preview/listener/categorize.js +193 -193
  15. package/dist/local-preview/listener/generate.d.ts +1 -1
  16. package/dist/local-preview/listener/generate.js +137 -137
  17. package/dist/local-preview/listener/index.d.ts +2 -2
  18. package/dist/local-preview/listener/index.js +317 -317
  19. package/dist/local-preview/listener/update.d.ts +2 -2
  20. package/dist/local-preview/listener/update.js +79 -79
  21. package/dist/local-preview/listener/utils/createPage.d.ts +10 -10
  22. package/dist/local-preview/listener/utils/createPage.js +210 -210
  23. package/dist/local-preview/listener/utils/getOpenApiContext.d.ts +21 -21
  24. package/dist/local-preview/listener/utils/getOpenApiContext.js +55 -55
  25. package/dist/local-preview/listener/utils/mintConfigFile.d.ts +2 -2
  26. package/dist/local-preview/listener/utils/mintConfigFile.js +74 -74
  27. package/dist/local-preview/listener/utils/types.d.ts +2 -2
  28. package/dist/local-preview/listener/utils/types.js +1 -1
  29. package/dist/local-preview/listener/utils.d.ts +13 -13
  30. package/dist/local-preview/listener/utils.js +112 -112
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/util.d.ts +4 -4
  33. package/dist/util.js +20 -20
  34. package/package.json +88 -87
@@ -1,55 +1,55 @@
1
- export var extractMethodAndEndpoint = function (api) {
2
- var methodRegex = /(get|post|put|delete|patch)\s/i;
3
- var trimmed = api.trim();
4
- var foundMethod = trimmed.match(methodRegex);
5
- var startIndexOfMethod = foundMethod ? api.indexOf(foundMethod[0]) : 0;
6
- var endIndexOfMethod = foundMethod ? startIndexOfMethod + foundMethod[0].length - 1 : 0;
7
- var filename = api.substring(0, startIndexOfMethod).trim();
8
- return {
9
- method: foundMethod ? foundMethod[0].slice(0, -1).toUpperCase() : undefined,
10
- endpoint: api.substring(endIndexOfMethod).trim(),
11
- filename: filename ? filename : undefined,
12
- };
13
- };
14
- export var getOpenApiOperationMethodAndEndpoint = function (openApi, openApiMetaField) {
15
- var _a;
16
- var _b = extractMethodAndEndpoint(openApiMetaField), endpoint = _b.endpoint, method = _b.method, filename = _b.filename;
17
- var path;
18
- (_a = openApi.files) === null || _a === void 0 ? void 0 : _a.forEach(function (file) {
19
- var openApiFile = file.openapi;
20
- var openApiPath = openApiFile.paths && openApiFile.paths[endpoint];
21
- var isFilenameOrNone = !filename || filename === file.name;
22
- if (openApiPath && isFilenameOrNone) {
23
- path = openApiPath;
24
- }
25
- });
26
- if (path == null) {
27
- return {};
28
- }
29
- var operation;
30
- if (method) {
31
- operation = path[method.toLowerCase()];
32
- }
33
- else {
34
- var firstOperationKey = Object.keys(path)[0];
35
- operation = path[firstOperationKey];
36
- }
37
- return {
38
- operation: operation,
39
- method: method,
40
- endpoint: endpoint,
41
- };
42
- };
43
- export var getOpenApiTitleAndDescription = function (openApi, openApiMetaField) {
44
- if (openApi == null || !openApiMetaField || openApiMetaField == null) {
45
- return {};
46
- }
47
- var operation = getOpenApiOperationMethodAndEndpoint(openApi, openApiMetaField).operation;
48
- if (operation == null) {
49
- return {};
50
- }
51
- return {
52
- title: operation.summary,
53
- description: operation.description,
54
- };
55
- };
1
+ export var extractMethodAndEndpoint = function (api) {
2
+ var methodRegex = /(get|post|put|delete|patch)\s/i;
3
+ var trimmed = api.trim();
4
+ var foundMethod = trimmed.match(methodRegex);
5
+ var startIndexOfMethod = foundMethod ? api.indexOf(foundMethod[0]) : 0;
6
+ var endIndexOfMethod = foundMethod ? startIndexOfMethod + foundMethod[0].length - 1 : 0;
7
+ var filename = api.substring(0, startIndexOfMethod).trim();
8
+ return {
9
+ method: foundMethod ? foundMethod[0].slice(0, -1).toUpperCase() : undefined,
10
+ endpoint: api.substring(endIndexOfMethod).trim(),
11
+ filename: filename ? filename : undefined,
12
+ };
13
+ };
14
+ export var getOpenApiOperationMethodAndEndpoint = function (openApi, openApiMetaField) {
15
+ var _a;
16
+ var _b = extractMethodAndEndpoint(openApiMetaField), endpoint = _b.endpoint, method = _b.method, filename = _b.filename;
17
+ var path;
18
+ (_a = openApi.files) === null || _a === void 0 ? void 0 : _a.forEach(function (file) {
19
+ var openApiFile = file.openapi;
20
+ var openApiPath = openApiFile.paths && openApiFile.paths[endpoint];
21
+ var isFilenameOrNone = !filename || filename === file.name;
22
+ if (openApiPath && isFilenameOrNone) {
23
+ path = openApiPath;
24
+ }
25
+ });
26
+ if (path == null) {
27
+ return {};
28
+ }
29
+ var operation;
30
+ if (method) {
31
+ operation = path[method.toLowerCase()];
32
+ }
33
+ else {
34
+ var firstOperationKey = Object.keys(path)[0];
35
+ operation = path[firstOperationKey];
36
+ }
37
+ return {
38
+ operation: operation,
39
+ method: method,
40
+ endpoint: endpoint,
41
+ };
42
+ };
43
+ export var getOpenApiTitleAndDescription = function (openApi, openApiMetaField) {
44
+ if (openApi == null || !openApiMetaField || openApiMetaField == null) {
45
+ return {};
46
+ }
47
+ var operation = getOpenApiOperationMethodAndEndpoint(openApi, openApiMetaField).operation;
48
+ if (operation == null) {
49
+ return {};
50
+ }
51
+ return {
52
+ title: operation.summary,
53
+ description: operation.description,
54
+ };
55
+ };
@@ -1,2 +1,2 @@
1
- export declare const getConfigPath: (contentDirectoryPath: string) => Promise<string | null>;
2
- export declare const getConfigObj: (contentDirectoryPath: string) => Promise<any>;
1
+ export declare const getConfigPath: (contentDirectoryPath: string) => Promise<string | null>;
2
+ export declare const getConfigObj: (contentDirectoryPath: string) => Promise<any>;
@@ -1,74 +1,74 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { promises as _promises } from 'fs';
38
- import { pathExists } from 'fs-extra';
39
- import pathUtil from 'path';
40
- var readFile = _promises.readFile;
41
- // TODO: Put in prebuild package
42
- export var getConfigPath = function (contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0: return [4 /*yield*/, pathExists(pathUtil.join(contentDirectoryPath, 'mint.json'))];
46
- case 1:
47
- if (_a.sent()) {
48
- return [2 /*return*/, pathUtil.join(contentDirectoryPath, 'mint.json')];
49
- }
50
- return [2 /*return*/, null];
51
- }
52
- });
53
- }); };
54
- // TODO: Put in prebuild package
55
- export var getConfigObj = function (contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
56
- var configPath, configObj, configContents;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0: return [4 /*yield*/, getConfigPath(contentDirectoryPath)];
60
- case 1:
61
- configPath = _a.sent();
62
- configObj = null;
63
- if (!configPath) return [3 /*break*/, 4];
64
- return [4 /*yield*/, readFile(configPath)];
65
- case 2:
66
- configContents = _a.sent();
67
- return [4 /*yield*/, JSON.parse(configContents.toString())];
68
- case 3:
69
- configObj = _a.sent();
70
- _a.label = 4;
71
- case 4: return [2 /*return*/, configObj];
72
- }
73
- });
74
- }); };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { promises as _promises } from 'fs';
38
+ import { pathExists } from 'fs-extra';
39
+ import pathUtil from 'path';
40
+ var readFile = _promises.readFile;
41
+ // TODO: Put in prebuild package
42
+ export var getConfigPath = function (contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0: return [4 /*yield*/, pathExists(pathUtil.join(contentDirectoryPath, 'mint.json'))];
46
+ case 1:
47
+ if (_a.sent()) {
48
+ return [2 /*return*/, pathUtil.join(contentDirectoryPath, 'mint.json')];
49
+ }
50
+ return [2 /*return*/, null];
51
+ }
52
+ });
53
+ }); };
54
+ // TODO: Put in prebuild package
55
+ export var getConfigObj = function (contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
56
+ var configPath, configObj, configContents;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0: return [4 /*yield*/, getConfigPath(contentDirectoryPath)];
60
+ case 1:
61
+ configPath = _a.sent();
62
+ configObj = null;
63
+ if (!configPath) return [3 /*break*/, 4];
64
+ return [4 /*yield*/, readFile(configPath)];
65
+ case 2:
66
+ configContents = _a.sent();
67
+ return [4 /*yield*/, JSON.parse(configContents.toString())];
68
+ case 3:
69
+ configObj = _a.sent();
70
+ _a.label = 4;
71
+ case 4: return [2 /*return*/, configObj];
72
+ }
73
+ });
74
+ }); };
@@ -1,2 +1,2 @@
1
- export type PotentialFileCategory = 'page' | 'snippet' | 'mintConfig' | 'potentialYamlOpenApiSpec' | 'potentialJsonOpenApiSpec' | 'staticFile';
2
- export type FileCategory = 'page' | 'snippet' | 'mintConfig' | 'openApi' | 'staticFile';
1
+ export type PotentialFileCategory = 'page' | 'snippet' | 'mintConfig' | 'potentialYamlOpenApiSpec' | 'potentialJsonOpenApiSpec' | 'staticFile';
2
+ export type FileCategory = 'page' | 'snippet' | 'mintConfig' | 'openApi' | 'staticFile';
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,13 +1,13 @@
1
- export declare const getFileExtension: (filename: string) => string;
2
- export type OpenApiCheckResult = {
3
- spec: any;
4
- isOpenApi: boolean;
5
- };
6
- export declare const openApiCheck: (path: string) => Promise<OpenApiCheckResult>;
7
- export declare const filterOutNullInGroup: (group: MintNavigation) => {
8
- pages: MintNavigationEntry[];
9
- group: string;
10
- version?: string | undefined;
11
- };
12
- export declare const isFileSizeValid: (path: string, maxFileSizeInMb: number) => Promise<boolean>;
13
- export declare function isError(obj: unknown): boolean;
1
+ export declare const getFileExtension: (filename: string) => string;
2
+ export type OpenApiCheckResult = {
3
+ spec: any;
4
+ isOpenApi: boolean;
5
+ };
6
+ export declare const openApiCheck: (path: string) => Promise<OpenApiCheckResult>;
7
+ export declare const filterOutNullInGroup: (group: MintNavigation) => {
8
+ pages: MintNavigationEntry[];
9
+ group: string;
10
+ version?: string | undefined;
11
+ };
12
+ export declare const isFileSizeValid: (path: string, maxFileSizeInMb: number) => Promise<boolean>;
13
+ export declare function isError(obj: unknown): boolean;
@@ -1,112 +1,112 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import SwaggerParser from '@apidevtools/swagger-parser';
49
- import { promises as _promises } from 'fs';
50
- var readdir = _promises.readdir, stat = _promises.stat;
51
- export var getFileExtension = function (filename) {
52
- return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
53
- };
54
- export var openApiCheck = function (path) { return __awaiter(void 0, void 0, void 0, function () {
55
- var spec, isOpenApi, _a;
56
- return __generator(this, function (_b) {
57
- switch (_b.label) {
58
- case 0:
59
- isOpenApi = false;
60
- _b.label = 1;
61
- case 1:
62
- _b.trys.push([1, 3, , 4]);
63
- return [4 /*yield*/, SwaggerParser.validate(path)];
64
- case 2:
65
- spec = _b.sent();
66
- isOpenApi = true;
67
- return [3 /*break*/, 4];
68
- case 3:
69
- _a = _b.sent();
70
- return [3 /*break*/, 4];
71
- case 4: return [2 /*return*/, { spec: spec, isOpenApi: isOpenApi }];
72
- }
73
- });
74
- }); };
75
- export var filterOutNullInGroup = function (group) {
76
- var newPages = filterOutNullInPages(group.pages);
77
- var newGroup = __assign(__assign({}, group), { pages: newPages });
78
- return newGroup;
79
- };
80
- var filterOutNullInPages = function (pages) {
81
- var newPages = [];
82
- pages.forEach(function (page) {
83
- if (page == null) {
84
- return;
85
- }
86
- if (page.hasOwnProperty('pages')) {
87
- var group = page;
88
- var newGroup = filterOutNullInGroup(group);
89
- newPages.push(newGroup);
90
- }
91
- else {
92
- newPages.push(page);
93
- }
94
- });
95
- return newPages;
96
- };
97
- export var isFileSizeValid = function (path, maxFileSizeInMb) { return __awaiter(void 0, void 0, void 0, function () {
98
- var maxFileSizeBytes, stats;
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0:
102
- maxFileSizeBytes = maxFileSizeInMb * 1000000;
103
- return [4 /*yield*/, stat(path)];
104
- case 1:
105
- stats = _a.sent();
106
- return [2 /*return*/, stats.size <= maxFileSizeBytes];
107
- }
108
- });
109
- }); };
110
- export function isError(obj) {
111
- return Object.prototype.toString.call(obj) === '[object Error]';
112
- }
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import SwaggerParser from '@apidevtools/swagger-parser';
49
+ import { promises as _promises } from 'fs';
50
+ var readdir = _promises.readdir, stat = _promises.stat;
51
+ export var getFileExtension = function (filename) {
52
+ return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
53
+ };
54
+ export var openApiCheck = function (path) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var spec, isOpenApi, _a;
56
+ return __generator(this, function (_b) {
57
+ switch (_b.label) {
58
+ case 0:
59
+ isOpenApi = false;
60
+ _b.label = 1;
61
+ case 1:
62
+ _b.trys.push([1, 3, , 4]);
63
+ return [4 /*yield*/, SwaggerParser.validate(path)];
64
+ case 2:
65
+ spec = _b.sent();
66
+ isOpenApi = true;
67
+ return [3 /*break*/, 4];
68
+ case 3:
69
+ _a = _b.sent();
70
+ return [3 /*break*/, 4];
71
+ case 4: return [2 /*return*/, { spec: spec, isOpenApi: isOpenApi }];
72
+ }
73
+ });
74
+ }); };
75
+ export var filterOutNullInGroup = function (group) {
76
+ var newPages = filterOutNullInPages(group.pages);
77
+ var newGroup = __assign(__assign({}, group), { pages: newPages });
78
+ return newGroup;
79
+ };
80
+ var filterOutNullInPages = function (pages) {
81
+ var newPages = [];
82
+ pages.forEach(function (page) {
83
+ if (page == null) {
84
+ return;
85
+ }
86
+ if (page.hasOwnProperty('pages')) {
87
+ var group = page;
88
+ var newGroup = filterOutNullInGroup(group);
89
+ newPages.push(newGroup);
90
+ }
91
+ else {
92
+ newPages.push(page);
93
+ }
94
+ });
95
+ return newPages;
96
+ };
97
+ export var isFileSizeValid = function (path, maxFileSizeInMb) { return __awaiter(void 0, void 0, void 0, function () {
98
+ var maxFileSizeBytes, stats;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ maxFileSizeBytes = maxFileSizeInMb * 1000000;
103
+ return [4 /*yield*/, stat(path)];
104
+ case 1:
105
+ stats = _a.sent();
106
+ return [2 /*return*/, stats.size <= maxFileSizeBytes];
107
+ }
108
+ });
109
+ }); };
110
+ export function isError(obj) {
111
+ return Object.prototype.toString.call(obj) === '[object Error]';
112
+ }