@scalar/cli 2.1.0 → 2.5.2
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/README.md +28 -24
- package/chunks/action-42D2C47G.js +18 -0
- package/chunks/{action-DFKHSDFV.js → action-6FAJNP6C.js} +7 -3
- package/chunks/{action-5R5FDF6S.js → action-6MZZHPVQ.js} +120 -22
- package/chunks/{action-BYZUBXVB.js → action-7H3XARJP.js} +8 -4
- package/chunks/{action-H5OHT2GV.js → action-AMNYOA4B.js} +7 -3
- package/chunks/{action-ANU5HGC4.js → action-DCINFQ57.js} +17 -14
- package/chunks/{action-GB6DM53B.js → action-DGD6Q6Y5.js} +21 -10
- package/chunks/{action-TPBKPHNS.js → action-EPNE5XCM.js} +22 -22
- package/chunks/{action-C5VB4ITT.js → action-FF2OMGAS.js} +36 -18
- package/chunks/{action-Q5UJ32D6.js → action-H3RTILLM.js} +1 -1
- package/chunks/action-HIL5ZFNB.js +84 -0
- package/chunks/{action-MENXFJH3.js → action-HXHBU7XC.js} +9 -9
- package/chunks/{action-F4Y6Q2VB.js → action-LFL3ZZKN.js} +21 -21
- package/chunks/action-LUVBQEIQ.js +250 -0
- package/chunks/{action-TZ5KGAQT.js → action-OILGZAMK.js} +17 -14
- package/chunks/{action-HD2T6BFJ.js → action-OK55BFGM.js} +10 -10
- package/chunks/{action-HNKM3Q65.js → action-P7RFXIC7.js} +17 -14
- package/chunks/action-PAA4NWUJ.js +374 -0
- package/chunks/action-PHLOE27S.js +522 -0
- package/chunks/{action-CYP4VDK3.js → action-RBVPKCRI.js} +12 -35
- package/chunks/action-SJYAMXYI.js +244 -0
- package/chunks/{action-45OGQB2M.js → action-TWHLZW4V.js} +17 -8
- package/chunks/{action-GEBRPNRT.js → action-V5KYG7XD.js} +15 -16
- package/chunks/{action-BNEGJBUH.js → action-W62AIEBN.js} +8 -9
- package/chunks/{action-PVDDRIM6.js → action-X7TZA3RE.js} +65 -26
- package/chunks/{action-CLSD7O2R.js → action-XUQ7TKKJ.js} +10 -10
- package/chunks/{action-BMFXENMX.js → action-Y6CEKYEK.js} +39 -34
- package/chunks/{action-STIEAXOE.js → action-YRWHX2AE.js} +16 -5
- package/chunks/{action-W5BATF4Q.js → action-ZLTUMRO2.js} +24 -24
- package/chunks/{action-UDZUUJSI.js → action-ZWQLQENM.js} +18 -7
- package/chunks/{agent-XGLOHXNA.js → agent-JAXLLDPE.js} +25 -5
- package/chunks/asyncapi-P6Y3L7RG.js +105 -0
- package/chunks/{build.action-LKOILPA6.js → build.action-AZ5ECU4B.js} +22 -22
- package/chunks/chunk-3BWGTPPT.js +27022 -0
- package/chunks/{chunk-ZTVWAKNJ.js → chunk-3DJ2GKEG.js} +1 -1
- package/chunks/chunk-3ZJYGGAA.js +30 -0
- package/chunks/{chunk-IX7LJ3AD.js → chunk-4ORL4MST.js} +2 -3
- package/chunks/{chunk-ASMHW5AY.js → chunk-6ZMT63IV.js} +1 -1
- package/chunks/{chunk-B6QZJWCQ.js → chunk-B2MHTD3R.js} +4 -6
- package/chunks/{chunk-P646T2WH.js → chunk-CIFOFSZ3.js} +131 -13
- package/chunks/chunk-CX7ZRMTC.js +404 -0
- package/chunks/{chunk-HQKBZOYU.js → chunk-FOKFF4EP.js} +3 -3
- package/chunks/{chunk-UPUTMFD4.js → chunk-FQVVKQPU.js} +185 -13
- package/chunks/{chunk-P2VH7DOC.js → chunk-HUCR333E.js} +6 -6
- package/chunks/{chunk-KWOL7A6J.js → chunk-HXIDUCSZ.js} +2 -2
- package/chunks/{chunk-H2WRMLYY.js → chunk-IKT5F47M.js} +3571 -7
- package/chunks/{chunk-OAXFCOJV.js → chunk-JV7TUEXQ.js} +2 -1
- package/chunks/{chunk-2BSG2QHO.js → chunk-KEOCJ3NJ.js} +133 -20
- package/chunks/{chunk-AHWWJ3MD.js → chunk-LCPFHE4Z.js} +1 -1
- package/chunks/{chunk-TLFMATXR.js → chunk-LQN4S62O.js} +33 -25
- package/chunks/chunk-M622VXRQ.js +14 -0
- package/chunks/chunk-M6Q3ARBV.js +210 -0
- package/chunks/{chunk-4QS7SJTG.js → chunk-MNLXYOVF.js} +51 -36
- package/chunks/{chunk-5BISXQX4.js → chunk-NIXG4KDE.js} +11 -13
- package/chunks/{chunk-47Y4L5IT.js → chunk-NNMSZVAB.js} +1031 -481
- package/chunks/chunk-OQKDBLOZ.js +741 -0
- package/chunks/{chunk-NUXPNUSS.js → chunk-RAO7VUGM.js} +1 -1
- package/chunks/{chunk-SHSHFGA7.js → chunk-RPVHJMQT.js} +4 -6
- package/chunks/{chunk-23I5PKZZ.js → chunk-SWWWYWHC.js} +32 -5
- package/chunks/{chunk-X4QLDBB5.js → chunk-T5HJUAWB.js} +24 -3
- package/chunks/chunk-TYLWJ2UL.js +25 -0
- package/chunks/{chunk-SXYALPYK.js → chunk-UB3XGOUW.js} +498 -60
- package/chunks/{chunk-TQ5XC2E3.js → chunk-UMPODUJO.js} +77 -11
- package/chunks/{chunk-4DGQIAJX.js → chunk-VNYE4R7N.js} +154 -14
- package/chunks/{create.action-FFQLBSJH.js → create.action-34OTO2SB.js} +22 -22
- package/chunks/{delete.action-QNN3LC2F.js → delete.action-6LRT4M3S.js} +22 -22
- package/chunks/{delete.action-STHQHP4F.js → delete.action-ZYXFMIOW.js} +22 -22
- package/chunks/{get.action-OTKYOP3Z.js → get.action-XP36SA2J.js} +15 -16
- package/chunks/{list.action-KDM5RHEH.js → list.action-6LF6KSD5.js} +19 -19
- package/chunks/{list.action-6I5EZAVB.js → list.action-WVRVLX5E.js} +22 -22
- package/chunks/{publish.action-PODTVRXS.js → publish.action-AHFUBT5C.js} +44 -36
- package/chunks/{update.action-KMD4ZM75.js → update.action-YQTVUDYE.js} +22 -22
- package/chunks/{update.action-4F6STTEQ.js → update.action-ZREAFJVG.js} +22 -22
- package/docs.html +107 -104
- package/index.js +84 -68
- package/package.json +19 -15
- package/chunks/action-CCW66QJN.js +0 -72
- package/chunks/action-CQ56FVES.js +0 -65
- package/chunks/action-JOSVV6YA.js +0 -71
- package/chunks/action-P7LN6FGY.js +0 -13
- package/chunks/action-R6ZZO26F.js +0 -299
- package/chunks/action-TWFJNQ2R.js +0 -95
- package/chunks/chunk-5BPPGTUU.js +0 -463
- package/chunks/chunk-DOVIWNKQ.js +0 -108
- package/chunks/chunk-ISGLWBXZ.js +0 -4265
- package/chunks/chunk-T7MDADON.js +0 -17
- package/chunks/chunk-VTYTPSXO.js +0 -161
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
measureTime
|
|
4
|
+
} from "./chunk-KHDYYVYF.js";
|
|
5
|
+
import {
|
|
6
|
+
isAsyncApiDocument,
|
|
7
|
+
isDocument
|
|
8
|
+
} from "./chunk-SWWWYWHC.js";
|
|
9
|
+
import "./chunk-MNLXYOVF.js";
|
|
10
|
+
import "./chunk-CX7ZRMTC.js";
|
|
11
|
+
import {
|
|
12
|
+
isUrl
|
|
13
|
+
} from "./chunk-4ORL4MST.js";
|
|
14
|
+
import {
|
|
15
|
+
output
|
|
16
|
+
} from "./chunk-T5HJUAWB.js";
|
|
17
|
+
import "./chunk-LQN4S62O.js";
|
|
18
|
+
import "./chunk-IKT5F47M.js";
|
|
19
|
+
import "./chunk-3MZYUBJ6.js";
|
|
20
|
+
|
|
21
|
+
// src/domains/document/split/action.ts
|
|
22
|
+
import fs2 from "node:fs/promises";
|
|
23
|
+
import path2 from "node:path";
|
|
24
|
+
import { text } from "@clack/prompts";
|
|
25
|
+
import as from "ansis";
|
|
26
|
+
import { bundle } from "@scalar/json-magic/bundle";
|
|
27
|
+
import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
|
|
28
|
+
import {
|
|
29
|
+
createServerWorkspaceStore,
|
|
30
|
+
WORKSPACE_FILE_NAME
|
|
31
|
+
} from "@scalar/workspace-store/server";
|
|
32
|
+
|
|
33
|
+
// src/domains/document/split/split-asyncapi.ts
|
|
34
|
+
import { createHash } from "node:crypto";
|
|
35
|
+
import fs from "node:fs/promises";
|
|
36
|
+
import path from "node:path";
|
|
37
|
+
import { extensions } from "@scalar/json-magic/bundle";
|
|
38
|
+
import { escapeJsonPointer } from "@scalar/json-magic/helpers/escape-json-pointer";
|
|
39
|
+
async function splitAsyncApi(document, outputPath) {
|
|
40
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
41
|
+
const root = structuredClone(document);
|
|
42
|
+
const segmentNames = /* @__PURE__ */ new Map();
|
|
43
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
44
|
+
const shorten = (name) => name.length <= 240 ? name : `${name.slice(0, 170)}~5${createHash("sha256").update(name).digest("hex")}`;
|
|
45
|
+
const getFilePath = (segments) => {
|
|
46
|
+
const names = [];
|
|
47
|
+
for (const segment of segments) {
|
|
48
|
+
const directory = names.join("/");
|
|
49
|
+
const key = JSON.stringify([directory, segment]);
|
|
50
|
+
const existing = segmentNames.get(key);
|
|
51
|
+
if (existing !== void 0) {
|
|
52
|
+
names.push(existing);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const escaped = shorten(
|
|
56
|
+
encodeURIComponent(escapeJsonPointer(segment)).replaceAll("%", "~2").replaceAll(".", "~3").replaceAll("*", "~6") || "~7"
|
|
57
|
+
);
|
|
58
|
+
const name = shorten(
|
|
59
|
+
usedNames.has(`${directory}/${escaped}`.toLowerCase()) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(escaped) ? escaped.replace(
|
|
60
|
+
/[a-z]/gi,
|
|
61
|
+
(letter) => `~4${letter.charCodeAt(0).toString(16)}`
|
|
62
|
+
) : escaped
|
|
63
|
+
);
|
|
64
|
+
segmentNames.set(key, name);
|
|
65
|
+
usedNames.add(`${directory}/${name}`.toLowerCase());
|
|
66
|
+
names.push(name);
|
|
67
|
+
}
|
|
68
|
+
return `chunks/default/${names.join("/")}.json`;
|
|
69
|
+
};
|
|
70
|
+
const extract = (parent, key, segments) => {
|
|
71
|
+
const pointer = `#/${segments.map(escapeJsonPointer).join("/")}`;
|
|
72
|
+
const file = getFilePath(segments);
|
|
73
|
+
chunks.set(pointer, { file, value: parent[key] });
|
|
74
|
+
parent[key] = {
|
|
75
|
+
$ref: `#/${segments.map((segment) => encodeURIComponent(escapeJsonPointer(segment))).join("/")}`
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const extractMap = (value, segments) => {
|
|
79
|
+
if (!isDocument(value)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const key of Object.keys(value)) {
|
|
83
|
+
extract(value, key, [...segments, key]);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const resolveChannel = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
87
|
+
if (!isDocument(value) || typeof value.$ref !== "string" || !value.$ref.startsWith("#/") || seen.has(value.$ref)) {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
seen.add(value.$ref);
|
|
91
|
+
const segments = decodeURIComponent(value.$ref.slice(2)).split("/").map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
92
|
+
const target = segments.reduce(
|
|
93
|
+
(node, segment) => isDocument(node) && Object.hasOwn(node, segment) ? node[segment] : void 0,
|
|
94
|
+
root
|
|
95
|
+
);
|
|
96
|
+
const resolved = resolveChannel(target, seen);
|
|
97
|
+
if (!isDocument(resolved)) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
const { $ref: _ref, ...siblings } = value;
|
|
101
|
+
return { ...resolved, ...siblings };
|
|
102
|
+
};
|
|
103
|
+
if (isDocument(root.channels)) {
|
|
104
|
+
for (const [name, value] of Object.entries(root.channels)) {
|
|
105
|
+
const channel = structuredClone(resolveChannel(value));
|
|
106
|
+
if (!isDocument(channel)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
root.channels[name] = channel;
|
|
110
|
+
extractMap(channel.messages, ["channels", name, "messages"]);
|
|
111
|
+
for (const method of ["publish", "subscribe"]) {
|
|
112
|
+
if (isDocument(channel[method])) {
|
|
113
|
+
if (isDocument(channel[method].message)) {
|
|
114
|
+
extract(channel[method], "message", [
|
|
115
|
+
"channels",
|
|
116
|
+
name,
|
|
117
|
+
method,
|
|
118
|
+
"message"
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
extract(channel, method, ["channels", name, method]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
extractMap(root.channels, ["channels"]);
|
|
127
|
+
extractMap(root.operations, ["operations"]);
|
|
128
|
+
if (isDocument(root.components)) {
|
|
129
|
+
for (const [type, entries] of Object.entries(root.components)) {
|
|
130
|
+
if (!type.startsWith("x-")) {
|
|
131
|
+
extractMap(entries, ["components", type]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (isDocument(root[extensions.externalDocuments])) {
|
|
136
|
+
extractMap(root[extensions.externalDocuments], [
|
|
137
|
+
extensions.externalDocuments
|
|
138
|
+
]);
|
|
139
|
+
extract(root, extensions.externalDocuments, [extensions.externalDocuments]);
|
|
140
|
+
delete root[extensions.externalDocuments];
|
|
141
|
+
delete root[extensions.externalDocumentsMappings];
|
|
142
|
+
}
|
|
143
|
+
const pointers = [...chunks.keys()].sort((a, b) => b.length - a.length);
|
|
144
|
+
const rebase = (value, sourceFile) => {
|
|
145
|
+
if (Array.isArray(value)) {
|
|
146
|
+
return value.map((entry) => rebase(entry, sourceFile));
|
|
147
|
+
}
|
|
148
|
+
if (!isDocument(value)) {
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
return Object.fromEntries(
|
|
152
|
+
Object.entries(value).map(([key, entry]) => {
|
|
153
|
+
if (key !== "$ref" || typeof entry !== "string" || !entry.startsWith("#")) {
|
|
154
|
+
return [key, rebase(entry, sourceFile)];
|
|
155
|
+
}
|
|
156
|
+
const pointer = decodeURIComponent(entry);
|
|
157
|
+
const target = pointers.find(
|
|
158
|
+
(candidate) => pointer === candidate || pointer.startsWith(`${candidate}/`)
|
|
159
|
+
);
|
|
160
|
+
const targetFile = target && chunks.get(target)?.file || "out.json";
|
|
161
|
+
const fragment = target ? `#${pointer.slice(target.length)}` : pointer;
|
|
162
|
+
const relativeFile = path.posix.relative(
|
|
163
|
+
path.posix.dirname(sourceFile),
|
|
164
|
+
targetFile
|
|
165
|
+
);
|
|
166
|
+
return [
|
|
167
|
+
key,
|
|
168
|
+
`${relativeFile.split("/").map(encodeURIComponent).join("/")}#${fragment.slice(1).split("/").map(encodeURIComponent).join("/")}`
|
|
169
|
+
];
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
for (const { file, value } of [
|
|
174
|
+
...chunks.values(),
|
|
175
|
+
{ file: "out.json", value: root }
|
|
176
|
+
]) {
|
|
177
|
+
const destination = path.join(outputPath, file);
|
|
178
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
179
|
+
await fs.writeFile(destination, JSON.stringify(rebase(value, file)));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/domains/document/split/action.ts
|
|
184
|
+
async function splitAction(input, { output: __outputPath }) {
|
|
185
|
+
if (!input) {
|
|
186
|
+
return output.error().title("Missing input").message("Please provide a file path or URL to split").exit("error");
|
|
187
|
+
}
|
|
188
|
+
const getOutputPath = async () => {
|
|
189
|
+
if (__outputPath !== void 0 && typeof __outputPath === "string") {
|
|
190
|
+
return __outputPath;
|
|
191
|
+
}
|
|
192
|
+
const outputPath2 = await text({
|
|
193
|
+
message: "Where should the chunks be written?",
|
|
194
|
+
defaultValue: "./assets",
|
|
195
|
+
placeholder: "./assets"
|
|
196
|
+
});
|
|
197
|
+
if (typeof outputPath2 !== "string") {
|
|
198
|
+
return output.error().message("Operation cancelled by user").exit("error");
|
|
199
|
+
}
|
|
200
|
+
return outputPath2;
|
|
201
|
+
};
|
|
202
|
+
const outputPath = await getOutputPath();
|
|
203
|
+
const document = await bundle(isUrl(input) ? input : path2.resolve(input), {
|
|
204
|
+
plugins: [readFiles(), fetchUrls()],
|
|
205
|
+
treeShake: false,
|
|
206
|
+
hooks: {
|
|
207
|
+
onResolveError: ({ $ref }) => {
|
|
208
|
+
throw new Error(`Could not resolve reference: ${$ref}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}).catch(() => null);
|
|
212
|
+
if (!isDocument(document)) {
|
|
213
|
+
return output.error().title("Invalid input").message(
|
|
214
|
+
"Could not read an OpenAPI or AsyncAPI document from the input. Please provide a valid JSON or YAML file."
|
|
215
|
+
).exit("error");
|
|
216
|
+
}
|
|
217
|
+
const { executionTimeMs } = await measureTime(async () => {
|
|
218
|
+
if (isAsyncApiDocument(document)) {
|
|
219
|
+
await splitAsyncApi(document, outputPath);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const documentName = "default";
|
|
223
|
+
const store = await createServerWorkspaceStore({
|
|
224
|
+
mode: "static",
|
|
225
|
+
documents: [{ name: documentName, document }],
|
|
226
|
+
// The workspace writer prefixes its directory with cwd, including absolute paths.
|
|
227
|
+
directory: path2.relative(process.cwd(), path2.resolve(outputPath)) || "."
|
|
228
|
+
});
|
|
229
|
+
await store.generateWorkspaceChunks();
|
|
230
|
+
const workspaceFilePath = path2.join(outputPath, WORKSPACE_FILE_NAME);
|
|
231
|
+
const sparseDocument = JSON.parse(
|
|
232
|
+
await fs2.readFile(workspaceFilePath, { encoding: "utf-8" })
|
|
233
|
+
);
|
|
234
|
+
await fs2.writeFile(
|
|
235
|
+
path2.join(outputPath, "out.json"),
|
|
236
|
+
JSON.stringify(sparseDocument.documents[documentName])
|
|
237
|
+
);
|
|
238
|
+
await fs2.rm(workspaceFilePath);
|
|
239
|
+
});
|
|
240
|
+
output.info().line().title(as.green("Document Split Successfully! \u{1F389}")).line().message(`\u2728 Chunks have been generated at: ${as.blue(outputPath)}`).line(`\u23F1\uFE0F Split completed in ${as.yellow(executionTimeMs.toFixed(2))}ms`).line("").print();
|
|
241
|
+
}
|
|
242
|
+
export {
|
|
243
|
+
splitAction
|
|
244
|
+
};
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
+
getFileOrUrl,
|
|
4
|
+
isAsyncApiContent,
|
|
3
5
|
loadOpenApiFile,
|
|
4
6
|
printSpecificationBanner
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SWWWYWHC.js";
|
|
6
8
|
import {
|
|
7
9
|
watchFile
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-NIXG4KDE.js";
|
|
11
|
+
import "./chunk-JV7TUEXQ.js";
|
|
12
|
+
import "./chunk-VNYE4R7N.js";
|
|
13
|
+
import "./chunk-OQKDBLOZ.js";
|
|
14
|
+
import "./chunk-MNLXYOVF.js";
|
|
15
|
+
import "./chunk-CX7ZRMTC.js";
|
|
16
|
+
import "./chunk-4ORL4MST.js";
|
|
14
17
|
import {
|
|
15
18
|
output
|
|
16
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-T5HJUAWB.js";
|
|
20
|
+
import "./chunk-LQN4S62O.js";
|
|
21
|
+
import "./chunk-IKT5F47M.js";
|
|
17
22
|
import "./chunk-3MZYUBJ6.js";
|
|
18
23
|
|
|
19
24
|
// src/domains/document/mock/action.ts
|
|
@@ -87,6 +92,10 @@ function getMethodColor(method) {
|
|
|
87
92
|
|
|
88
93
|
// src/domains/document/mock/action.ts
|
|
89
94
|
async function mockAction(fileArgument, { watch, once, port }) {
|
|
95
|
+
if (isAsyncApiContent(await getFileOrUrl(fileArgument))) {
|
|
96
|
+
const { mockAsyncApi } = await import("./asyncapi-P6Y3L7RG.js");
|
|
97
|
+
return mockAsyncApi(fileArgument, { watch, once, port });
|
|
98
|
+
}
|
|
90
99
|
let server;
|
|
91
100
|
const result = await loadOpenApiFile(fileArgument);
|
|
92
101
|
if (!result.valid) {
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
fetchFromRegistry
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-RAO7VUGM.js";
|
|
5
|
+
import "./chunk-TYLWJ2UL.js";
|
|
6
6
|
import {
|
|
7
7
|
registry
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-4QS7SJTG.js";
|
|
10
|
-
import "./chunk-VTYTPSXO.js";
|
|
8
|
+
} from "./chunk-M6Q3ARBV.js";
|
|
11
9
|
import {
|
|
12
10
|
getAuthData
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-NIXG4KDE.js";
|
|
12
|
+
import "./chunk-JV7TUEXQ.js";
|
|
13
|
+
import "./chunk-VNYE4R7N.js";
|
|
14
|
+
import "./chunk-OQKDBLOZ.js";
|
|
15
|
+
import "./chunk-MNLXYOVF.js";
|
|
16
|
+
import "./chunk-CX7ZRMTC.js";
|
|
17
|
+
import "./chunk-4ORL4MST.js";
|
|
17
18
|
import {
|
|
18
|
-
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
output
|
|
20
|
+
} from "./chunk-T5HJUAWB.js";
|
|
21
|
+
import "./chunk-LQN4S62O.js";
|
|
20
22
|
import {
|
|
23
|
+
docVersionSchema,
|
|
21
24
|
external_exports
|
|
22
|
-
} from "./chunk-
|
|
23
|
-
import "./chunk-IX7LJ3AD.js";
|
|
24
|
-
import {
|
|
25
|
-
output
|
|
26
|
-
} from "./chunk-X4QLDBB5.js";
|
|
25
|
+
} from "./chunk-IKT5F47M.js";
|
|
27
26
|
import "./chunk-3MZYUBJ6.js";
|
|
28
27
|
|
|
29
28
|
// src/domains/registry/get/action.ts
|
|
@@ -2,18 +2,17 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
|
|
|
2
2
|
import {
|
|
3
3
|
readAndParseConfig,
|
|
4
4
|
renderConfigError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-4QS7SJTG.js";
|
|
9
|
-
import "./chunk-VTYTPSXO.js";
|
|
10
|
-
import "./chunk-TLFMATXR.js";
|
|
11
|
-
import "./chunk-ISGLWBXZ.js";
|
|
12
|
-
import "./chunk-H2WRMLYY.js";
|
|
5
|
+
} from "./chunk-HUCR333E.js";
|
|
6
|
+
import "./chunk-NNMSZVAB.js";
|
|
7
|
+
import "./chunk-OQKDBLOZ.js";
|
|
13
8
|
import "./chunk-K74E42RV.js";
|
|
9
|
+
import "./chunk-MNLXYOVF.js";
|
|
10
|
+
import "./chunk-CX7ZRMTC.js";
|
|
14
11
|
import {
|
|
15
12
|
output
|
|
16
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-T5HJUAWB.js";
|
|
14
|
+
import "./chunk-LQN4S62O.js";
|
|
15
|
+
import "./chunk-IKT5F47M.js";
|
|
17
16
|
import "./chunk-3MZYUBJ6.js";
|
|
18
17
|
|
|
19
18
|
// src/domains/project/check-config/action.ts
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
getFileOrUrl,
|
|
4
|
+
isAsyncApiDocument,
|
|
5
|
+
isDocument,
|
|
6
|
+
loadOpenApiDocument,
|
|
7
|
+
printSpecificationBanner,
|
|
8
|
+
safeNormalize
|
|
9
|
+
} from "./chunk-SWWWYWHC.js";
|
|
6
10
|
import {
|
|
7
11
|
watchFile
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-NIXG4KDE.js";
|
|
13
|
+
import "./chunk-JV7TUEXQ.js";
|
|
14
|
+
import "./chunk-VNYE4R7N.js";
|
|
15
|
+
import "./chunk-OQKDBLOZ.js";
|
|
16
|
+
import "./chunk-MNLXYOVF.js";
|
|
17
|
+
import "./chunk-CX7ZRMTC.js";
|
|
18
|
+
import "./chunk-4ORL4MST.js";
|
|
14
19
|
import {
|
|
15
20
|
output
|
|
16
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-T5HJUAWB.js";
|
|
22
|
+
import "./chunk-LQN4S62O.js";
|
|
23
|
+
import "./chunk-IKT5F47M.js";
|
|
17
24
|
import "./chunk-3MZYUBJ6.js";
|
|
18
25
|
|
|
19
26
|
// src/domains/document/serve/action.ts
|
|
@@ -21,25 +28,47 @@ import { serve } from "@hono/node-server";
|
|
|
21
28
|
import as from "ansis";
|
|
22
29
|
import { Hono } from "hono";
|
|
23
30
|
import { stream } from "hono/streaming";
|
|
31
|
+
|
|
32
|
+
// src/domains/document/serve/load-document.ts
|
|
33
|
+
import { validate } from "@scalar/asyncapi-validator";
|
|
34
|
+
var loadServeDocument = async (input) => {
|
|
35
|
+
const content = await getFileOrUrl(input);
|
|
36
|
+
const document = safeNormalize(content);
|
|
37
|
+
if (!isDocument(document) || !isAsyncApiDocument(document)) {
|
|
38
|
+
return loadOpenApiDocument(content);
|
|
39
|
+
}
|
|
40
|
+
const result = validate(document);
|
|
41
|
+
if (!result.valid) {
|
|
42
|
+
output.warn().title("File does not match the AsyncAPI specification.").print();
|
|
43
|
+
for (const error of result.errors ?? []) {
|
|
44
|
+
output.warn().title(error.message ?? "Invalid AsyncAPI document").print();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
valid: result.valid,
|
|
49
|
+
version: result.version,
|
|
50
|
+
specification: document,
|
|
51
|
+
schema: void 0
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/domains/document/serve/action.ts
|
|
24
56
|
async function serveAction(inputArgument, { watch, once, port }) {
|
|
25
57
|
if (!inputArgument) {
|
|
26
58
|
return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
|
|
27
59
|
}
|
|
28
|
-
const result = await
|
|
29
|
-
if (
|
|
60
|
+
const result = await loadServeDocument(inputArgument);
|
|
61
|
+
if (result.specification === void 0) {
|
|
30
62
|
return;
|
|
31
63
|
}
|
|
32
64
|
let { specification } = result;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
schema: result.schema
|
|
36
|
-
});
|
|
37
|
-
if (specification?.paths === void 0 || Object.keys(specification?.paths).length === 0) {
|
|
65
|
+
printServeBanner(result);
|
|
66
|
+
if (!isAsyncApiDocument(specification) && Object.keys(specification.paths ?? {}).length === 0) {
|
|
38
67
|
output.warn().title("Could not find any paths in the OpenAPI file.").print();
|
|
39
68
|
}
|
|
40
69
|
const app = new Hono();
|
|
41
70
|
app.get("/", (c) => {
|
|
42
|
-
return c.html(getHtmlDocument(specification
|
|
71
|
+
return c.html(getHtmlDocument(specification, watch));
|
|
43
72
|
});
|
|
44
73
|
app.use("/__watcher", async (c, next) => {
|
|
45
74
|
c.header("Content-Type", "text/event-stream");
|
|
@@ -51,14 +80,14 @@ async function serveAction(inputArgument, { watch, once, port }) {
|
|
|
51
80
|
return stream(c, async (s) => {
|
|
52
81
|
if (watch) {
|
|
53
82
|
const subscription = await watchFile(inputArgument, async () => {
|
|
54
|
-
const newResult = await
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
83
|
+
const newResult = await loadServeDocument(inputArgument);
|
|
84
|
+
if (newResult.specification && JSON.stringify(specification) !== JSON.stringify(newResult.specification)) {
|
|
85
|
+
output.info().title(
|
|
86
|
+
as.grey(
|
|
87
|
+
`${isAsyncApiDocument(newResult.specification) ? "AsyncAPI" : "OpenAPI"} file modified`
|
|
88
|
+
)
|
|
89
|
+
).print();
|
|
90
|
+
printServeBanner(newResult);
|
|
62
91
|
specification = newResult.specification;
|
|
63
92
|
s.write("data: file modified\n\n");
|
|
64
93
|
}
|
|
@@ -124,6 +153,16 @@ var getHtmlDocument = (specification, watch = false) => {
|
|
|
124
153
|
</body>
|
|
125
154
|
</html>`;
|
|
126
155
|
};
|
|
156
|
+
var printServeBanner = (result) => {
|
|
157
|
+
if (isAsyncApiDocument(result.specification)) {
|
|
158
|
+
output.info().title(`AsyncAPI${result.version ? ` v${result.version}` : ""}`).print();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
printSpecificationBanner({
|
|
162
|
+
version: result.version,
|
|
163
|
+
schema: result.valid ? result.schema : void 0
|
|
164
|
+
});
|
|
165
|
+
};
|
|
127
166
|
export {
|
|
128
167
|
getHtmlDocument,
|
|
129
168
|
serveAction
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getUserTeams
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6ZMT63IV.js";
|
|
5
5
|
import {
|
|
6
6
|
getDatabaseClient
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-RPVHJMQT.js";
|
|
8
|
+
import "./chunk-B2MHTD3R.js";
|
|
9
9
|
import {
|
|
10
10
|
getAuthData,
|
|
11
11
|
refreshToken
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-IX7LJ3AD.js";
|
|
12
|
+
} from "./chunk-NIXG4KDE.js";
|
|
13
|
+
import "./chunk-JV7TUEXQ.js";
|
|
14
|
+
import "./chunk-VNYE4R7N.js";
|
|
15
|
+
import "./chunk-OQKDBLOZ.js";
|
|
16
|
+
import "./chunk-4ORL4MST.js";
|
|
18
17
|
import {
|
|
19
18
|
output
|
|
20
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-T5HJUAWB.js";
|
|
20
|
+
import "./chunk-IKT5F47M.js";
|
|
21
21
|
import "./chunk-3MZYUBJ6.js";
|
|
22
22
|
|
|
23
23
|
// src/domains/team/set/action.ts
|
|
@@ -2,55 +2,59 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
|
|
|
2
2
|
import {
|
|
3
3
|
dashboardUrl,
|
|
4
4
|
registryUrl
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TYLWJ2UL.js";
|
|
6
6
|
import {
|
|
7
7
|
registry
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-M6Q3ARBV.js";
|
|
9
9
|
import {
|
|
10
|
-
getFileOrUrl
|
|
11
|
-
|
|
10
|
+
getFileOrUrl,
|
|
11
|
+
isDocument,
|
|
12
|
+
safeNormalize
|
|
13
|
+
} from "./chunk-SWWWYWHC.js";
|
|
12
14
|
import {
|
|
13
15
|
DEFAULT_FETCH_CONCURRENCY
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LCPFHE4Z.js";
|
|
15
17
|
import {
|
|
16
18
|
apiService
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-UB3XGOUW.js";
|
|
18
20
|
import {
|
|
19
21
|
BaseCollections
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-KEOCJ3NJ.js";
|
|
21
23
|
import {
|
|
22
24
|
getDatabaseClient
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import
|
|
29
|
-
RegistryAsset
|
|
30
|
-
} from "./chunk-4QS7SJTG.js";
|
|
31
|
-
import "./chunk-VTYTPSXO.js";
|
|
25
|
+
} from "./chunk-RPVHJMQT.js";
|
|
26
|
+
import "./chunk-FQVVKQPU.js";
|
|
27
|
+
import "./chunk-B2MHTD3R.js";
|
|
28
|
+
import "./chunk-3BWGTPPT.js";
|
|
29
|
+
import "./chunk-M622VXRQ.js";
|
|
30
|
+
import "./chunk-CIFOFSZ3.js";
|
|
32
31
|
import {
|
|
33
32
|
getAuthData
|
|
34
|
-
} from "./chunk-
|
|
35
|
-
import "./chunk-
|
|
36
|
-
import "./chunk-TLFMATXR.js";
|
|
33
|
+
} from "./chunk-NIXG4KDE.js";
|
|
34
|
+
import "./chunk-JV7TUEXQ.js";
|
|
37
35
|
import {
|
|
38
36
|
teamSchema
|
|
39
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-VNYE4R7N.js";
|
|
38
|
+
import "./chunk-OQKDBLOZ.js";
|
|
39
|
+
import "./chunk-K74E42RV.js";
|
|
40
|
+
import {
|
|
41
|
+
RegistryAsset
|
|
42
|
+
} from "./chunk-MNLXYOVF.js";
|
|
43
|
+
import "./chunk-CX7ZRMTC.js";
|
|
44
|
+
import {
|
|
45
|
+
isUrl
|
|
46
|
+
} from "./chunk-4ORL4MST.js";
|
|
47
|
+
import {
|
|
48
|
+
output
|
|
49
|
+
} from "./chunk-T5HJUAWB.js";
|
|
50
|
+
import "./chunk-LQN4S62O.js";
|
|
40
51
|
import {
|
|
41
52
|
docVersionSchema,
|
|
53
|
+
external_exports,
|
|
42
54
|
namespaceSchema,
|
|
43
55
|
slugSchema,
|
|
44
56
|
toAsciiSlug
|
|
45
|
-
} from "./chunk-
|
|
46
|
-
import {
|
|
47
|
-
external_exports
|
|
48
|
-
} from "./chunk-H2WRMLYY.js";
|
|
49
|
-
import "./chunk-K74E42RV.js";
|
|
50
|
-
import "./chunk-IX7LJ3AD.js";
|
|
51
|
-
import {
|
|
52
|
-
output
|
|
53
|
-
} from "./chunk-X4QLDBB5.js";
|
|
57
|
+
} from "./chunk-IKT5F47M.js";
|
|
54
58
|
import "./chunk-3MZYUBJ6.js";
|
|
55
59
|
|
|
56
60
|
// src/domains/registry/publish/action.ts
|
|
@@ -58,7 +62,6 @@ import { text } from "@clack/prompts";
|
|
|
58
62
|
import as from "ansis";
|
|
59
63
|
import { bundle } from "@scalar/json-magic/bundle";
|
|
60
64
|
import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
|
|
61
|
-
import { parseJsonOrYaml } from "@scalar/oas-utils/helpers";
|
|
62
65
|
async function publishAction(file, args) {
|
|
63
66
|
const { error, data } = external_exports.object({
|
|
64
67
|
slug: slugSchema.optional(),
|
|
@@ -112,10 +115,12 @@ async function publishAction(file, args) {
|
|
|
112
115
|
if (value.length === 0) return "File path or URL is required!";
|
|
113
116
|
}
|
|
114
117
|
})).toString();
|
|
115
|
-
const
|
|
116
|
-
const parsed =
|
|
117
|
-
if (!
|
|
118
|
-
return output.error().title("Invalid file").message(
|
|
118
|
+
const content = await getFileOrUrl(apiFile);
|
|
119
|
+
const parsed = safeNormalize(content);
|
|
120
|
+
if (!isDocument(parsed)) {
|
|
121
|
+
return output.error().title("Invalid file").message(
|
|
122
|
+
isUrl(apiFile) ? "Could not fetch or parse the document from the URL." : "Could not read or parse the document file."
|
|
123
|
+
).exit("error");
|
|
119
124
|
}
|
|
120
125
|
const bundlingPlugins = [readFiles()];
|
|
121
126
|
if (data.bundle) {
|