@lukoweb/apitogo 0.1.1 → 0.1.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/dist/cli/cli.js +17 -6
- package/dist/declarations/lib/ui/Command.d.ts +1 -1
- package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
- package/package.json +1 -1
- package/src/app/main.tsx +150 -150
- package/src/config/loader.ts +245 -245
- package/src/index.ts +33 -33
- package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
- package/src/lib/authentication/components/SignIn.tsx +46 -46
- package/src/lib/authentication/components/SignUp.tsx +48 -48
- package/src/lib/authentication/providers/clerk.tsx +224 -224
- package/src/lib/authentication/ui/AuthCard.tsx +7 -7
- package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
- package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
- package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
- package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
- package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
- package/src/lib/components/Autocomplete.tsx +123 -123
- package/src/lib/components/DeveloperHint.tsx +39 -35
- package/src/lib/components/Header.tsx +260 -260
- package/src/lib/components/Layout.tsx +53 -53
- package/src/lib/components/Main.tsx +51 -51
- package/src/lib/components/Mermaid.tsx +74 -70
- package/src/lib/components/MobileTopNavigation.tsx +276 -276
- package/src/lib/components/MultiSelect.tsx +86 -82
- package/src/lib/components/TopNavigation.tsx +103 -103
- package/src/lib/components/index.ts +26 -26
- package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
- package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
- package/src/lib/components/navigation/NavigationItem.tsx +181 -177
- package/src/lib/core/RouteGuard.tsx +193 -193
- package/src/lib/errors/ErrorMessage.tsx +50 -46
- package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
- package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
- package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
- package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
- package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
- package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
- package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
- package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
- package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
- package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
- package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
- package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
- package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
- package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
- package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
- package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
- package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
- package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
- package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
- package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
- package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
- package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
- package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
- package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
- package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
- package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
- package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
- package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
- package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
- package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
- package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
- package/src/lib/ui/ActionButton.tsx +21 -21
- package/src/lib/ui/Command.tsx +191 -191
- package/src/lib/util/MdxComponents.tsx +150 -150
- package/src/vite/config.ts +234 -231
- package/src/vite/dev-server.ts +291 -291
- package/src/vite/plugin-api-keys.ts +50 -50
- package/src/vite/plugin-api.ts +320 -318
- package/src/vite/plugin-auth.ts +38 -38
- package/src/vite/plugin-component.ts +45 -39
- package/src/vite/plugin-config.ts +75 -75
- package/src/vite/plugin-custom-pages.ts +36 -36
- package/src/vite/plugin-docs.ts +202 -202
- package/src/vite/plugin-markdown-export.ts +214 -214
- package/src/vite/plugin-mdx.ts +149 -149
- package/src/vite/plugin-navigation.ts +106 -106
- package/src/vite/plugin-search.ts +47 -47
- package/src/vite/plugin.ts +42 -42
- package/src/vite/prerender/prerender.ts +233 -233
package/src/vite/plugin-api.ts
CHANGED
|
@@ -1,318 +1,320 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { deepEqual } from "fast-equals";
|
|
4
|
-
import { type Plugin, runnerImport } from "vite";
|
|
5
|
-
import { ZuploEnv } from "../app/env.js";
|
|
6
|
-
import { getZudokuRootDir } from "../cli/common/package-json.js";
|
|
7
|
-
import { getCurrentConfig } from "../config/loader.js";
|
|
8
|
-
import {
|
|
9
|
-
getBuildConfig,
|
|
10
|
-
type Processor,
|
|
11
|
-
} from "../config/validators/BuildSchema.js";
|
|
12
|
-
import { getAllTags } from "../lib/oas/graphql/index.js";
|
|
13
|
-
import type {
|
|
14
|
-
ApiCatalogItem,
|
|
15
|
-
ApiCatalogPluginOptions,
|
|
16
|
-
} from "../lib/plugins/api-catalog/index.js";
|
|
17
|
-
import type { VersionedInput } from "../lib/plugins/openapi/interfaces.js";
|
|
18
|
-
import { ensureArray } from "../lib/util/ensureArray.js";
|
|
19
|
-
import { SchemaManager } from "./api/SchemaManager.js";
|
|
20
|
-
import { reload } from "./plugin-config-reload.js";
|
|
21
|
-
import { invalidate as invalidateNavigation } from "./plugin-navigation.js";
|
|
22
|
-
|
|
23
|
-
const viteApiPlugin = async (): Promise<Plugin> => {
|
|
24
|
-
const virtualModuleId = "virtual:zudoku-api-plugins";
|
|
25
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
26
|
-
|
|
27
|
-
const initialConfig = getCurrentConfig();
|
|
28
|
-
|
|
29
|
-
// Load Zuplo-specific processors if in Zuplo environment
|
|
30
|
-
const zuploProcessors = ZuploEnv.isZuplo
|
|
31
|
-
? await runnerImport<{ default: (rootDir: string) => Processor[] }>(
|
|
32
|
-
path.resolve(getZudokuRootDir(), "src/zuplo/with-zuplo-processors.ts"),
|
|
33
|
-
).then((m) => m.module.default(initialConfig.__meta.rootDir))
|
|
34
|
-
: [];
|
|
35
|
-
|
|
36
|
-
const buildConfig = await getBuildConfig();
|
|
37
|
-
const buildProcessors = buildConfig?.processors ?? [];
|
|
38
|
-
|
|
39
|
-
const tmpStoreDir = path.posix.join(
|
|
40
|
-
initialConfig.__meta.rootDir,
|
|
41
|
-
"node_modules/.apitogo/processed",
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const processors = [...buildProcessors, ...zuploProcessors];
|
|
45
|
-
const schemaManager = new SchemaManager({
|
|
46
|
-
storeDir: tmpStoreDir,
|
|
47
|
-
config: initialConfig,
|
|
48
|
-
processors,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
name: "zudoku-api-plugins",
|
|
53
|
-
async buildStart() {
|
|
54
|
-
await fs.rm(tmpStoreDir, { recursive: true, force: true });
|
|
55
|
-
await fs.mkdir(tmpStoreDir, { recursive: true });
|
|
56
|
-
|
|
57
|
-
await schemaManager.processAllSchemas();
|
|
58
|
-
|
|
59
|
-
schemaManager
|
|
60
|
-
.getAllTrackedFiles()
|
|
61
|
-
.forEach((file) => this.addWatchFile(file));
|
|
62
|
-
},
|
|
63
|
-
configureServer(server) {
|
|
64
|
-
// Serve original OpenAPI schema files
|
|
65
|
-
server.middlewares.use(async (req, res, next) => {
|
|
66
|
-
if (req.method !== "GET" || !req.url) return next();
|
|
67
|
-
if (
|
|
68
|
-
!req.url.toLowerCase().endsWith(".json") &&
|
|
69
|
-
!req.url.toLowerCase().endsWith(".yaml")
|
|
70
|
-
) {
|
|
71
|
-
return next();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const pathMap = schemaManager.getUrlToFilePathMap();
|
|
75
|
-
|
|
76
|
-
const inputPath = pathMap.get(req.url);
|
|
77
|
-
if (!inputPath) return next();
|
|
78
|
-
|
|
79
|
-
const content = await fs.readFile(inputPath, "utf-8");
|
|
80
|
-
const mimeType =
|
|
81
|
-
path.extname(inputPath).toLowerCase() === ".json"
|
|
82
|
-
? "application/json"
|
|
83
|
-
: "application/x-yaml";
|
|
84
|
-
|
|
85
|
-
res.setHeader("Content-Type", `${mimeType}; charset=utf-8`);
|
|
86
|
-
return res.end(content);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
server.watcher.on("change", async (id) => {
|
|
90
|
-
const mainFiles = schemaManager.getFilesToReprocess(id);
|
|
91
|
-
if (mainFiles.length === 0) return;
|
|
92
|
-
|
|
93
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
94
|
-
console.log(`Re-processing schema ${id}`);
|
|
95
|
-
|
|
96
|
-
for (const inputConfig of mainFiles) {
|
|
97
|
-
await schemaManager.processSchema(inputConfig);
|
|
98
|
-
}
|
|
99
|
-
schemaManager
|
|
100
|
-
.getAllTrackedFiles()
|
|
101
|
-
.forEach((file) => server.watcher.add(file));
|
|
102
|
-
|
|
103
|
-
invalidateNavigation(server);
|
|
104
|
-
reload(server);
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
resolveId(id) {
|
|
108
|
-
if (id === virtualModuleId) {
|
|
109
|
-
return resolvedVirtualModuleId;
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
async load(id) {
|
|
113
|
-
if (id !== resolvedVirtualModuleId) return;
|
|
114
|
-
|
|
115
|
-
const config = getCurrentConfig();
|
|
116
|
-
|
|
117
|
-
if (!deepEqual(schemaManager.config.apis, config.apis)) {
|
|
118
|
-
schemaManager.config = config;
|
|
119
|
-
await schemaManager.processAllSchemas();
|
|
120
|
-
schemaManager
|
|
121
|
-
.getAllTrackedFiles()
|
|
122
|
-
.forEach((file) => this.addWatchFile(file));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (config.__meta.mode === "standalone") {
|
|
126
|
-
return [
|
|
127
|
-
"export const configuredApiPlugins = [];",
|
|
128
|
-
"export const configuredApiCatalogPlugins = [];",
|
|
129
|
-
].join("\n");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const code = [
|
|
133
|
-
`import config from "virtual:zudoku-config";`,
|
|
134
|
-
`const configuredApiPlugins = [];`,
|
|
135
|
-
`const configuredApiCatalogPlugins = [];`,
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
if (config.apis) {
|
|
139
|
-
code.push(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
`
|
|
200
|
-
`
|
|
201
|
-
`
|
|
202
|
-
`
|
|
203
|
-
`
|
|
204
|
-
`
|
|
205
|
-
`
|
|
206
|
-
`
|
|
207
|
-
`
|
|
208
|
-
`
|
|
209
|
-
`
|
|
210
|
-
`
|
|
211
|
-
`
|
|
212
|
-
`
|
|
213
|
-
`
|
|
214
|
-
`
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
"
|
|
227
|
-
`
|
|
228
|
-
|
|
229
|
-
`
|
|
230
|
-
`
|
|
231
|
-
`
|
|
232
|
-
`
|
|
233
|
-
`
|
|
234
|
-
`
|
|
235
|
-
`
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
`
|
|
285
|
-
`
|
|
286
|
-
`
|
|
287
|
-
`}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { deepEqual } from "fast-equals";
|
|
4
|
+
import { type Plugin, runnerImport } from "vite";
|
|
5
|
+
import { ZuploEnv } from "../app/env.js";
|
|
6
|
+
import { getZudokuRootDir } from "../cli/common/package-json.js";
|
|
7
|
+
import { getCurrentConfig } from "../config/loader.js";
|
|
8
|
+
import {
|
|
9
|
+
getBuildConfig,
|
|
10
|
+
type Processor,
|
|
11
|
+
} from "../config/validators/BuildSchema.js";
|
|
12
|
+
import { getAllTags } from "../lib/oas/graphql/index.js";
|
|
13
|
+
import type {
|
|
14
|
+
ApiCatalogItem,
|
|
15
|
+
ApiCatalogPluginOptions,
|
|
16
|
+
} from "../lib/plugins/api-catalog/index.js";
|
|
17
|
+
import type { VersionedInput } from "../lib/plugins/openapi/interfaces.js";
|
|
18
|
+
import { ensureArray } from "../lib/util/ensureArray.js";
|
|
19
|
+
import { SchemaManager } from "./api/SchemaManager.js";
|
|
20
|
+
import { reload } from "./plugin-config-reload.js";
|
|
21
|
+
import { invalidate as invalidateNavigation } from "./plugin-navigation.js";
|
|
22
|
+
|
|
23
|
+
const viteApiPlugin = async (): Promise<Plugin> => {
|
|
24
|
+
const virtualModuleId = "virtual:zudoku-api-plugins";
|
|
25
|
+
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
26
|
+
|
|
27
|
+
const initialConfig = getCurrentConfig();
|
|
28
|
+
|
|
29
|
+
// Load Zuplo-specific processors if in Zuplo environment
|
|
30
|
+
const zuploProcessors = ZuploEnv.isZuplo
|
|
31
|
+
? await runnerImport<{ default: (rootDir: string) => Processor[] }>(
|
|
32
|
+
path.resolve(getZudokuRootDir(), "src/zuplo/with-zuplo-processors.ts"),
|
|
33
|
+
).then((m) => m.module.default(initialConfig.__meta.rootDir))
|
|
34
|
+
: [];
|
|
35
|
+
|
|
36
|
+
const buildConfig = await getBuildConfig();
|
|
37
|
+
const buildProcessors = buildConfig?.processors ?? [];
|
|
38
|
+
|
|
39
|
+
const tmpStoreDir = path.posix.join(
|
|
40
|
+
initialConfig.__meta.rootDir,
|
|
41
|
+
"node_modules/.apitogo/processed",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const processors = [...buildProcessors, ...zuploProcessors];
|
|
45
|
+
const schemaManager = new SchemaManager({
|
|
46
|
+
storeDir: tmpStoreDir,
|
|
47
|
+
config: initialConfig,
|
|
48
|
+
processors,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: "zudoku-api-plugins",
|
|
53
|
+
async buildStart() {
|
|
54
|
+
await fs.rm(tmpStoreDir, { recursive: true, force: true });
|
|
55
|
+
await fs.mkdir(tmpStoreDir, { recursive: true });
|
|
56
|
+
|
|
57
|
+
await schemaManager.processAllSchemas();
|
|
58
|
+
|
|
59
|
+
schemaManager
|
|
60
|
+
.getAllTrackedFiles()
|
|
61
|
+
.forEach((file) => this.addWatchFile(file));
|
|
62
|
+
},
|
|
63
|
+
configureServer(server) {
|
|
64
|
+
// Serve original OpenAPI schema files
|
|
65
|
+
server.middlewares.use(async (req, res, next) => {
|
|
66
|
+
if (req.method !== "GET" || !req.url) return next();
|
|
67
|
+
if (
|
|
68
|
+
!req.url.toLowerCase().endsWith(".json") &&
|
|
69
|
+
!req.url.toLowerCase().endsWith(".yaml")
|
|
70
|
+
) {
|
|
71
|
+
return next();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const pathMap = schemaManager.getUrlToFilePathMap();
|
|
75
|
+
|
|
76
|
+
const inputPath = pathMap.get(req.url);
|
|
77
|
+
if (!inputPath) return next();
|
|
78
|
+
|
|
79
|
+
const content = await fs.readFile(inputPath, "utf-8");
|
|
80
|
+
const mimeType =
|
|
81
|
+
path.extname(inputPath).toLowerCase() === ".json"
|
|
82
|
+
? "application/json"
|
|
83
|
+
: "application/x-yaml";
|
|
84
|
+
|
|
85
|
+
res.setHeader("Content-Type", `${mimeType}; charset=utf-8`);
|
|
86
|
+
return res.end(content);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
server.watcher.on("change", async (id) => {
|
|
90
|
+
const mainFiles = schemaManager.getFilesToReprocess(id);
|
|
91
|
+
if (mainFiles.length === 0) return;
|
|
92
|
+
|
|
93
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
94
|
+
console.log(`Re-processing schema ${id}`);
|
|
95
|
+
|
|
96
|
+
for (const inputConfig of mainFiles) {
|
|
97
|
+
await schemaManager.processSchema(inputConfig);
|
|
98
|
+
}
|
|
99
|
+
schemaManager
|
|
100
|
+
.getAllTrackedFiles()
|
|
101
|
+
.forEach((file) => server.watcher.add(file));
|
|
102
|
+
|
|
103
|
+
invalidateNavigation(server);
|
|
104
|
+
reload(server);
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
resolveId(id) {
|
|
108
|
+
if (id === virtualModuleId) {
|
|
109
|
+
return resolvedVirtualModuleId;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async load(id) {
|
|
113
|
+
if (id !== resolvedVirtualModuleId) return;
|
|
114
|
+
|
|
115
|
+
const config = getCurrentConfig();
|
|
116
|
+
|
|
117
|
+
if (!deepEqual(schemaManager.config.apis, config.apis)) {
|
|
118
|
+
schemaManager.config = config;
|
|
119
|
+
await schemaManager.processAllSchemas();
|
|
120
|
+
schemaManager
|
|
121
|
+
.getAllTrackedFiles()
|
|
122
|
+
.forEach((file) => this.addWatchFile(file));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (config.__meta.mode === "standalone") {
|
|
126
|
+
return [
|
|
127
|
+
"export const configuredApiPlugins = [];",
|
|
128
|
+
"export const configuredApiCatalogPlugins = [];",
|
|
129
|
+
].join("\n");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const code = [
|
|
133
|
+
`import config from "virtual:zudoku-config";`,
|
|
134
|
+
`const configuredApiPlugins = [];`,
|
|
135
|
+
`const configuredApiCatalogPlugins = [];`,
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
if (config.apis) {
|
|
139
|
+
code.push(
|
|
140
|
+
'import { openApiPlugin } from "@lukoweb/apitogo/plugins/openapi";',
|
|
141
|
+
);
|
|
142
|
+
code.push(
|
|
143
|
+
`const apis = Array.isArray(config.apis) ? config.apis : [config.apis]`,
|
|
144
|
+
);
|
|
145
|
+
const apis = ensureArray(config.apis);
|
|
146
|
+
const apiMetadata: ApiCatalogItem[] = [];
|
|
147
|
+
|
|
148
|
+
for (const apiConfig of apis) {
|
|
149
|
+
if (apiConfig.type === "file" && apiConfig.path) {
|
|
150
|
+
const latestSchema = schemaManager.getLatestSchema(apiConfig.path);
|
|
151
|
+
if (!latestSchema?.schema.info) continue;
|
|
152
|
+
|
|
153
|
+
apiMetadata.push({
|
|
154
|
+
path: apiConfig.path,
|
|
155
|
+
label: latestSchema.schema.info.title,
|
|
156
|
+
description: latestSchema.schema.info.description ?? "",
|
|
157
|
+
categories: apiConfig.categories ?? [],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Generate API plugin code
|
|
163
|
+
let apiIndex = -1;
|
|
164
|
+
for (const apiConfig of apis) {
|
|
165
|
+
apiIndex++;
|
|
166
|
+
if (apiConfig.type === "file") {
|
|
167
|
+
if (!apiConfig.path) continue;
|
|
168
|
+
|
|
169
|
+
const schemas = schemaManager.getSchemasForPath(apiConfig.path);
|
|
170
|
+
|
|
171
|
+
if (!schemas?.length) continue;
|
|
172
|
+
|
|
173
|
+
const allSlugs = new Set<string>();
|
|
174
|
+
const versionedInput = schemas.map<VersionedInput>((s) => {
|
|
175
|
+
const versionTags = getAllTags(s.schema);
|
|
176
|
+
versionTags.forEach(({ slug }) => {
|
|
177
|
+
if (slug) allSlugs.add(slug);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
path: s.path,
|
|
182
|
+
version: s.version,
|
|
183
|
+
downloadUrl: s.downloadUrl,
|
|
184
|
+
label: s.label ?? s.schema.info?.version,
|
|
185
|
+
input: s.importKey,
|
|
186
|
+
hasUntaggedOperations: versionTags.some(
|
|
187
|
+
(tag) => tag.name === undefined,
|
|
188
|
+
),
|
|
189
|
+
tagPages: versionTags.flatMap((t) => t.slug ?? []),
|
|
190
|
+
};
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const tags = Array.from(allSlugs);
|
|
194
|
+
|
|
195
|
+
const schemaImports = schemaManager.getSchemaImports();
|
|
196
|
+
|
|
197
|
+
code.push(
|
|
198
|
+
"configuredApiPlugins.push(openApiPlugin({",
|
|
199
|
+
` type: "file",`,
|
|
200
|
+
` input: ${JSON.stringify(versionedInput)},`,
|
|
201
|
+
` path: ${JSON.stringify(apiConfig.path)},`,
|
|
202
|
+
` tagPages: ${JSON.stringify(tags)},`,
|
|
203
|
+
` options: {`,
|
|
204
|
+
` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
|
|
205
|
+
` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
|
|
206
|
+
` disablePlayground: config.defaults?.apis?.disablePlayground,`,
|
|
207
|
+
` disableSidecar: config.defaults?.apis?.disableSidecar,`,
|
|
208
|
+
` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
|
|
209
|
+
` expandAllTags: config.defaults?.apis?.expandAllTags ?? true,`,
|
|
210
|
+
` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
|
|
211
|
+
` schemaDownload: config.defaults?.apis?.schemaDownload,`,
|
|
212
|
+
` transformExamples: config.defaults?.apis?.transformExamples,`,
|
|
213
|
+
` generateCodeSnippet: config.defaults?.apis?.generateCodeSnippet,`,
|
|
214
|
+
` ...(apis[${apiIndex}].options ?? {}),`,
|
|
215
|
+
` },`,
|
|
216
|
+
` schemaImports: {`,
|
|
217
|
+
...schemaImports.map(
|
|
218
|
+
(s) =>
|
|
219
|
+
` "${s.importKey.replaceAll("\\", "\\\\")}": () => import("${s.importKey.replaceAll("\\", "/")}?d=${s.processedTime}"),`,
|
|
220
|
+
),
|
|
221
|
+
` },`,
|
|
222
|
+
"}));",
|
|
223
|
+
);
|
|
224
|
+
} else {
|
|
225
|
+
code.push(
|
|
226
|
+
"configuredApiPlugins.push(openApiPlugin({",
|
|
227
|
+
` ...${JSON.stringify(apiConfig)},`,
|
|
228
|
+
" options: {",
|
|
229
|
+
` examplesLanguage: config.defaults?.apis?.examplesLanguage ?? config.defaults?.examplesLanguage,`,
|
|
230
|
+
` supportedLanguages: config.defaults?.apis?.supportedLanguages,`,
|
|
231
|
+
` disablePlayground: config.defaults?.apis?.disablePlayground,`,
|
|
232
|
+
` disableSidecar: config.defaults?.apis?.disableSidecar,`,
|
|
233
|
+
` showVersionSelect: config.defaults?.apis?.showVersionSelect ?? "if-available",`,
|
|
234
|
+
` expandAllTags: config.defaults?.apis?.expandAllTags ?? false,`,
|
|
235
|
+
` showInfoPage: config.defaults?.apis?.showInfoPage ?? true,`,
|
|
236
|
+
` schemaDownload: config.defaults?.apis?.schemaDownload,`,
|
|
237
|
+
` ...${JSON.stringify(apiConfig.options ?? {})},`,
|
|
238
|
+
" },",
|
|
239
|
+
"}));",
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (config.catalogs) {
|
|
245
|
+
code.push(
|
|
246
|
+
'import { apiCatalogPlugin } from "@lukoweb/apitogo/plugins/api-catalog";',
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const catalogs = ensureArray(config.catalogs);
|
|
250
|
+
|
|
251
|
+
const categories = apis
|
|
252
|
+
.flatMap((api) => api.categories ?? [])
|
|
253
|
+
.reduce((acc, catalog) => {
|
|
254
|
+
if (!acc.has(catalog.label)) {
|
|
255
|
+
acc.set(catalog.label ?? "", new Set(catalog.tags));
|
|
256
|
+
}
|
|
257
|
+
for (const tag of catalog.tags) {
|
|
258
|
+
acc.get(catalog.label ?? "")?.add(tag);
|
|
259
|
+
}
|
|
260
|
+
return acc;
|
|
261
|
+
}, new Map<string, Set<string>>());
|
|
262
|
+
|
|
263
|
+
const categoryList = Array.from(categories.entries()).map(
|
|
264
|
+
([label, tags]) => ({
|
|
265
|
+
label,
|
|
266
|
+
tags: Array.from(tags),
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
for (let i = 0; i < catalogs.length; i++) {
|
|
271
|
+
const catalog = catalogs[i];
|
|
272
|
+
if (!catalog) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const apiCatalogConfig: ApiCatalogPluginOptions = {
|
|
276
|
+
...catalog,
|
|
277
|
+
items: apiMetadata,
|
|
278
|
+
label: catalog.label,
|
|
279
|
+
categories: categoryList,
|
|
280
|
+
filterCatalogItems: catalog.filterItems,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
code.push(
|
|
284
|
+
`configuredApiCatalogPlugins.push(apiCatalogPlugin({`,
|
|
285
|
+
` ...${JSON.stringify(apiCatalogConfig, null, 2)},`,
|
|
286
|
+
` filterCatalogItems: Array.isArray(config.catalogs)`,
|
|
287
|
+
` ? config.catalogs[${i}].filterItems`,
|
|
288
|
+
` : config.catalogs.filterItems,`,
|
|
289
|
+
`}));`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
code.push(
|
|
296
|
+
`export { configuredApiPlugins, configuredApiCatalogPlugins };`,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
return code.join("\n");
|
|
300
|
+
},
|
|
301
|
+
async closeBundle() {
|
|
302
|
+
if (this.environment.name === "ssr") return;
|
|
303
|
+
|
|
304
|
+
const config = getCurrentConfig();
|
|
305
|
+
const pathMap = schemaManager.getUrlToFilePathMap();
|
|
306
|
+
|
|
307
|
+
if (process.env.NODE_ENV !== "production") return;
|
|
308
|
+
|
|
309
|
+
for (const [urlPath, inputPath] of pathMap) {
|
|
310
|
+
const content = await fs.readFile(inputPath, "utf-8");
|
|
311
|
+
const outputPath = path.join(config.__meta.rootDir, "dist", urlPath);
|
|
312
|
+
|
|
313
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
314
|
+
await fs.writeFile(outputPath, content, "utf-8");
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export default viteApiPlugin;
|