mokup 2.3.0 → 2.3.1
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/bundle.cjs +2 -6
- package/dist/bundle.d.cts +1 -27
- package/dist/bundle.d.mts +1 -27
- package/dist/bundle.d.ts +1 -27
- package/dist/bundle.mjs +1 -5
- package/dist/cli-bin.d.cts +1 -0
- package/dist/cli-bin.d.mts +1 -0
- package/dist/cli-bin.d.ts +1 -0
- package/dist/index.cjs +8 -159
- package/dist/index.d.cts +7 -48
- package/dist/index.d.mts +7 -48
- package/dist/index.d.ts +7 -48
- package/dist/index.mjs +8 -159
- package/dist/shared/mokup.BZpTBIrj.mjs +10 -0
- package/dist/shared/mokup.CO9HhGox.cjs +13 -0
- package/dist/vite.cjs +53 -153
- package/dist/vite.d.cts +2 -7
- package/dist/vite.d.mts +3 -6
- package/dist/vite.d.ts +2 -7
- package/dist/vite.mjs +22 -122
- package/dist/webpack.cjs +29 -38
- package/dist/webpack.d.cts +3 -6
- package/dist/webpack.d.mts +3 -6
- package/dist/webpack.d.ts +3 -6
- package/dist/webpack.mjs +5 -14
- package/package.json +7 -13
- package/dist/shared/mokup.BXPIIxtS.cjs +0 -47
- package/dist/shared/mokup.C-hwskJ_.mjs +0 -1790
- package/dist/shared/mokup.CsBTglhs.mjs +0 -45
- package/dist/shared/mokup.DXCs9518.cjs +0 -1810
- package/dist/shared/mokup.Dkqu10Hk.d.cts +0 -379
- package/dist/shared/mokup.Dkqu10Hk.d.mts +0 -379
- package/dist/shared/mokup.Dkqu10Hk.d.ts +0 -379
- package/dist/shared/mokup.Dy9VDphS.cjs +0 -181
- package/dist/shared/mokup.Iqw32OxC.mjs +0 -174
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import { RouteToken } from '@mokup/runtime';
|
|
2
|
-
import { MockEntryOptions, PlaygroundOptionsInput } from '@mokup/shared';
|
|
3
|
-
import { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Supported HTTP methods for mokup routes.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* import type { HttpMethod } from 'mokup/vite'
|
|
10
|
-
*
|
|
11
|
-
* const method: HttpMethod = 'GET'
|
|
12
|
-
*/
|
|
13
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
14
|
-
/**
|
|
15
|
-
* Static response payloads supported by route rules.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* import type { RouteStaticResponse } from 'mokup/vite'
|
|
19
|
-
*
|
|
20
|
-
* const value: RouteStaticResponse = { ok: true }
|
|
21
|
-
*/
|
|
22
|
-
type RouteStaticResponse = string | number | boolean | bigint | symbol | null | undefined | object;
|
|
23
|
-
/**
|
|
24
|
-
* Allowed return value from a route handler.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* import type { RouteHandlerResult } from 'mokup/vite'
|
|
28
|
-
*
|
|
29
|
-
* const result: RouteHandlerResult = 'ok'
|
|
30
|
-
*/
|
|
31
|
-
type RouteHandlerResult = RouteStaticResponse | Response;
|
|
32
|
-
/**
|
|
33
|
-
* Request handler signature for mokup routes.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* import type { RequestHandler } from 'mokup/vite'
|
|
37
|
-
*
|
|
38
|
-
* const handler: RequestHandler = (c) => c.json({ ok: true })
|
|
39
|
-
*/
|
|
40
|
-
type RequestHandler = (context: Context) => RouteHandlerResult | Promise<RouteHandlerResult>;
|
|
41
|
-
/**
|
|
42
|
-
* Route response as a static value or handler.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* import type { RouteResponse } from 'mokup/vite'
|
|
46
|
-
*
|
|
47
|
-
* const response: RouteResponse = { ok: true }
|
|
48
|
-
*/
|
|
49
|
-
type RouteResponse = RouteStaticResponse | RequestHandler;
|
|
50
|
-
/**
|
|
51
|
-
* Rule metadata for a route handler.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* import type { RouteRule } from 'mokup/vite'
|
|
55
|
-
*
|
|
56
|
-
* const rule: RouteRule = {
|
|
57
|
-
* handler: () => ({ ok: true }),
|
|
58
|
-
* status: 200,
|
|
59
|
-
* }
|
|
60
|
-
*/
|
|
61
|
-
interface RouteRule {
|
|
62
|
-
/** Handler for the route. */
|
|
63
|
-
handler: RouteResponse;
|
|
64
|
-
/**
|
|
65
|
-
* Enable or disable this rule.
|
|
66
|
-
*
|
|
67
|
-
* @default true
|
|
68
|
-
*/
|
|
69
|
-
enabled?: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Override response status code.
|
|
72
|
-
*
|
|
73
|
-
* @default 200
|
|
74
|
-
*/
|
|
75
|
-
status?: number;
|
|
76
|
-
/**
|
|
77
|
-
* Additional response headers.
|
|
78
|
-
*
|
|
79
|
-
* @default {}
|
|
80
|
-
*/
|
|
81
|
-
headers?: Record<string, string>;
|
|
82
|
-
/**
|
|
83
|
-
* Delay in milliseconds before responding.
|
|
84
|
-
*
|
|
85
|
-
* @default 0
|
|
86
|
-
*/
|
|
87
|
-
delay?: number;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Runtime mode for Vite integration.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* import type { RuntimeMode } from 'mokup/vite'
|
|
94
|
-
*
|
|
95
|
-
* const mode: RuntimeMode = 'sw'
|
|
96
|
-
*/
|
|
97
|
-
type RuntimeMode = 'server' | 'sw';
|
|
98
|
-
/**
|
|
99
|
-
* Execution runtime for the Vite plugin.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* import type { ViteRuntime } from 'mokup/vite'
|
|
103
|
-
*
|
|
104
|
-
* const runtime: ViteRuntime = 'vite'
|
|
105
|
-
*/
|
|
106
|
-
type ViteRuntime = 'vite' | 'worker';
|
|
107
|
-
/**
|
|
108
|
-
* Service worker behavior options for mokup.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* import type { ServiceWorkerOptions } from 'mokup/vite'
|
|
112
|
-
*
|
|
113
|
-
* const sw: ServiceWorkerOptions = {
|
|
114
|
-
* path: '/mokup-sw.js',
|
|
115
|
-
* scope: '/',
|
|
116
|
-
* }
|
|
117
|
-
*/
|
|
118
|
-
interface ServiceWorkerOptions {
|
|
119
|
-
/**
|
|
120
|
-
* Service worker script path.
|
|
121
|
-
*
|
|
122
|
-
* @default "/mokup-sw.js"
|
|
123
|
-
*/
|
|
124
|
-
path?: string;
|
|
125
|
-
/**
|
|
126
|
-
* Service worker scope.
|
|
127
|
-
*
|
|
128
|
-
* @default "/"
|
|
129
|
-
*/
|
|
130
|
-
scope?: string;
|
|
131
|
-
/**
|
|
132
|
-
* Auto-register the service worker.
|
|
133
|
-
*
|
|
134
|
-
* @default true
|
|
135
|
-
*/
|
|
136
|
-
register?: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Auto-unregister when no SW entries exist.
|
|
139
|
-
*
|
|
140
|
-
* @default false
|
|
141
|
-
*/
|
|
142
|
-
unregister?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Allow SW fallback to direct network when not matched.
|
|
145
|
-
*
|
|
146
|
-
* @default true
|
|
147
|
-
*/
|
|
148
|
-
fallback?: boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Base paths the service worker should handle.
|
|
151
|
-
*
|
|
152
|
-
* @default []
|
|
153
|
-
*/
|
|
154
|
-
basePath?: string | string[];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Directory-level route configuration loaded from index.config.* files.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* import type { RouteDirectoryConfig } from 'mokup/vite'
|
|
162
|
-
*
|
|
163
|
-
* const config: RouteDirectoryConfig = {
|
|
164
|
-
* headers: { 'x-mokup': 'dir' },
|
|
165
|
-
* }
|
|
166
|
-
*/
|
|
167
|
-
interface RouteDirectoryConfig {
|
|
168
|
-
/**
|
|
169
|
-
* Headers applied to routes under this directory.
|
|
170
|
-
*
|
|
171
|
-
* @default {}
|
|
172
|
-
*/
|
|
173
|
-
headers?: Record<string, string>;
|
|
174
|
-
/**
|
|
175
|
-
* Default status code override.
|
|
176
|
-
*
|
|
177
|
-
* @default 200
|
|
178
|
-
*/
|
|
179
|
-
status?: number;
|
|
180
|
-
/**
|
|
181
|
-
* Delay in milliseconds.
|
|
182
|
-
*
|
|
183
|
-
* @default 0
|
|
184
|
-
*/
|
|
185
|
-
delay?: number;
|
|
186
|
-
/**
|
|
187
|
-
* Enable or disable routes under this directory.
|
|
188
|
-
*
|
|
189
|
-
* @default true
|
|
190
|
-
*/
|
|
191
|
-
enabled?: boolean;
|
|
192
|
-
/**
|
|
193
|
-
* Ignore prefixes within the directory.
|
|
194
|
-
*
|
|
195
|
-
* @default ["."]
|
|
196
|
-
*/
|
|
197
|
-
ignorePrefix?: string | string[];
|
|
198
|
-
/**
|
|
199
|
-
* Include filter for route files.
|
|
200
|
-
*
|
|
201
|
-
* @default undefined
|
|
202
|
-
*/
|
|
203
|
-
include?: RegExp | RegExp[];
|
|
204
|
-
/**
|
|
205
|
-
* Exclude filter for route files.
|
|
206
|
-
*
|
|
207
|
-
* @default undefined
|
|
208
|
-
*/
|
|
209
|
-
exclude?: RegExp | RegExp[];
|
|
210
|
-
/**
|
|
211
|
-
* Middleware for this directory.
|
|
212
|
-
*
|
|
213
|
-
* @default undefined
|
|
214
|
-
*/
|
|
215
|
-
middleware?: MiddlewareHandler | MiddlewareHandler[];
|
|
216
|
-
/**
|
|
217
|
-
* Error handling policy for defineConfig hooks.
|
|
218
|
-
*
|
|
219
|
-
* @default "warn"
|
|
220
|
-
*/
|
|
221
|
-
hookError?: HookErrorPolicy;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Middleware execution position.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* import type { MiddlewarePosition } from 'mokup/vite'
|
|
228
|
-
*
|
|
229
|
-
* const position: MiddlewarePosition = 'pre'
|
|
230
|
-
*/
|
|
231
|
-
type MiddlewarePosition = 'pre' | 'normal' | 'post';
|
|
232
|
-
/**
|
|
233
|
-
* Error handling policy for config hooks.
|
|
234
|
-
*/
|
|
235
|
-
type HookErrorPolicy = 'throw' | 'warn' | 'silent';
|
|
236
|
-
/**
|
|
237
|
-
* Middleware registry used by defineConfig.
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* import type { MiddlewareRegistry } from 'mokup/vite'
|
|
241
|
-
*
|
|
242
|
-
* const registry: MiddlewareRegistry = { use: () => {} }
|
|
243
|
-
*/
|
|
244
|
-
interface MiddlewareRegistry {
|
|
245
|
-
use: (...handlers: MiddlewareHandler[]) => void;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Normalized middleware metadata.
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* import type { ResolvedMiddleware } from 'mokup/vite'
|
|
252
|
-
*
|
|
253
|
-
* const item: ResolvedMiddleware = {
|
|
254
|
-
* handle: () => {},
|
|
255
|
-
* source: 'index.config.ts',
|
|
256
|
-
* index: 0,
|
|
257
|
-
* }
|
|
258
|
-
*/
|
|
259
|
-
interface ResolvedMiddleware {
|
|
260
|
-
handle: MiddlewareHandler;
|
|
261
|
-
source: string;
|
|
262
|
-
index: number;
|
|
263
|
-
/**
|
|
264
|
-
* Position in the middleware chain.
|
|
265
|
-
*
|
|
266
|
-
* @default "normal"
|
|
267
|
-
*/
|
|
268
|
-
position: MiddlewarePosition;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Options for a single Vite entry.
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* import type { VitePluginOptions } from 'mokup/vite'
|
|
275
|
-
*
|
|
276
|
-
* const options: VitePluginOptions = {
|
|
277
|
-
* dir: 'mock',
|
|
278
|
-
* prefix: '/api',
|
|
279
|
-
* }
|
|
280
|
-
*/
|
|
281
|
-
interface VitePluginOptions extends MockEntryOptions {
|
|
282
|
-
/**
|
|
283
|
-
* Runtime mode per entry.
|
|
284
|
-
*
|
|
285
|
-
* @default "server"
|
|
286
|
-
*/
|
|
287
|
-
mode?: RuntimeMode;
|
|
288
|
-
/**
|
|
289
|
-
* Service worker options for this entry.
|
|
290
|
-
*
|
|
291
|
-
* @default undefined
|
|
292
|
-
*/
|
|
293
|
-
sw?: ServiceWorkerOptions;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Top-level plugin options for mokup/vite.
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* import type { MokupPluginOptions } from 'mokup/vite'
|
|
300
|
-
*
|
|
301
|
-
* const options: MokupPluginOptions = {
|
|
302
|
-
* entries: { dir: 'mock' },
|
|
303
|
-
* playground: true,
|
|
304
|
-
* }
|
|
305
|
-
*/
|
|
306
|
-
interface MokupPluginOptions {
|
|
307
|
-
/**
|
|
308
|
-
* One or more entries to scan for mocks.
|
|
309
|
-
*
|
|
310
|
-
* @default [{ }]
|
|
311
|
-
*/
|
|
312
|
-
entries?: VitePluginOptions | VitePluginOptions[];
|
|
313
|
-
/**
|
|
314
|
-
* Playground configuration.
|
|
315
|
-
*
|
|
316
|
-
* @default { enabled: true, path: "/__mokup" }
|
|
317
|
-
*/
|
|
318
|
-
playground?: PlaygroundOptionsInput;
|
|
319
|
-
/**
|
|
320
|
-
* Runtime for the Vite plugin.
|
|
321
|
-
*
|
|
322
|
-
* @default "vite"
|
|
323
|
-
*/
|
|
324
|
-
runtime?: ViteRuntime;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Alias for Vite plugin options.
|
|
328
|
-
*
|
|
329
|
-
* @example
|
|
330
|
-
* import type { VitePluginOptionsInput } from 'mokup/vite'
|
|
331
|
-
*
|
|
332
|
-
* const options: VitePluginOptionsInput = { entries: { dir: 'mock' } }
|
|
333
|
-
*/
|
|
334
|
-
type VitePluginOptionsInput = MokupPluginOptions;
|
|
335
|
-
/**
|
|
336
|
-
* Fully resolved route metadata.
|
|
337
|
-
*
|
|
338
|
-
* @example
|
|
339
|
-
* import type { ResolvedRoute } from 'mokup/vite'
|
|
340
|
-
*
|
|
341
|
-
* const route: ResolvedRoute = {
|
|
342
|
-
* file: '/mock/ping.get.ts',
|
|
343
|
-
* template: '/ping',
|
|
344
|
-
* method: 'GET',
|
|
345
|
-
* tokens: [{ type: 'static', value: 'ping' }],
|
|
346
|
-
* score: [4],
|
|
347
|
-
* handler: () => ({ ok: true }),
|
|
348
|
-
* }
|
|
349
|
-
*/
|
|
350
|
-
interface ResolvedRoute {
|
|
351
|
-
file: string;
|
|
352
|
-
template: string;
|
|
353
|
-
method: HttpMethod;
|
|
354
|
-
tokens: RouteToken[];
|
|
355
|
-
score: number[];
|
|
356
|
-
handler: RouteResponse;
|
|
357
|
-
middlewares?: ResolvedMiddleware[];
|
|
358
|
-
/**
|
|
359
|
-
* Ordered config file chain applied to this route (root to leaf).
|
|
360
|
-
*
|
|
361
|
-
* @default []
|
|
362
|
-
*/
|
|
363
|
-
configChain?: string[];
|
|
364
|
-
status?: number;
|
|
365
|
-
headers?: Record<string, string>;
|
|
366
|
-
delay?: number;
|
|
367
|
-
ruleIndex?: number;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* List of resolved routes.
|
|
371
|
-
*
|
|
372
|
-
* @example
|
|
373
|
-
* import type { RouteTable } from 'mokup/vite'
|
|
374
|
-
*
|
|
375
|
-
* const table: RouteTable = []
|
|
376
|
-
*/
|
|
377
|
-
type RouteTable = ResolvedRoute[];
|
|
378
|
-
|
|
379
|
-
export type { HttpMethod as H, MokupPluginOptions as M, RouteTable as R, ServiceWorkerOptions as S, VitePluginOptions as V, ResolvedRoute as a, MiddlewarePosition as b, MiddlewareRegistry as c, RequestHandler as d, RouteDirectoryConfig as e, RouteResponse as f, RouteRule as g, RuntimeMode as h, VitePluginOptionsInput as i, ViteRuntime as j, HookErrorPolicy as k };
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const pathe = require('@mokup/shared/pathe');
|
|
4
|
-
const pathUtils = require('@mokup/shared/path-utils');
|
|
5
|
-
require('@mokup/shared/timing');
|
|
6
|
-
|
|
7
|
-
const methodSet = /* @__PURE__ */ new Set([
|
|
8
|
-
"GET",
|
|
9
|
-
"POST",
|
|
10
|
-
"PUT",
|
|
11
|
-
"PATCH",
|
|
12
|
-
"DELETE",
|
|
13
|
-
"OPTIONS",
|
|
14
|
-
"HEAD"
|
|
15
|
-
]);
|
|
16
|
-
const methodSuffixSet = new Set(
|
|
17
|
-
Array.from(methodSet, (method) => method.toLowerCase())
|
|
18
|
-
);
|
|
19
|
-
const supportedExtensions = /* @__PURE__ */ new Set([
|
|
20
|
-
".json",
|
|
21
|
-
".jsonc",
|
|
22
|
-
".ts",
|
|
23
|
-
".js",
|
|
24
|
-
".mjs",
|
|
25
|
-
".cjs"
|
|
26
|
-
]);
|
|
27
|
-
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
28
|
-
|
|
29
|
-
function toViteImportPath(file, root) {
|
|
30
|
-
const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
|
|
31
|
-
const rel = pathe.relative(root, absolute);
|
|
32
|
-
if (!rel.startsWith("..") && !pathe.isAbsolute(rel)) {
|
|
33
|
-
return `/${pathUtils.toPosix(rel)}`;
|
|
34
|
-
}
|
|
35
|
-
return `/@fs/${pathUtils.toPosix(absolute)}`;
|
|
36
|
-
}
|
|
37
|
-
function shouldModuleize(handler) {
|
|
38
|
-
if (typeof handler === "function") {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
if (typeof Response !== "undefined" && handler instanceof Response) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
47
|
-
function getNodeBuffer() {
|
|
48
|
-
if (typeof globalThis === "undefined") {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const buffer = globalThis.Buffer;
|
|
52
|
-
return buffer ?? null;
|
|
53
|
-
}
|
|
54
|
-
function getBtoa() {
|
|
55
|
-
if (typeof globalThis === "undefined") {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const btoaFn = globalThis.btoa;
|
|
59
|
-
return typeof btoaFn === "function" ? btoaFn : null;
|
|
60
|
-
}
|
|
61
|
-
function encodeBase64(bytes) {
|
|
62
|
-
const buffer = getNodeBuffer();
|
|
63
|
-
if (buffer) {
|
|
64
|
-
return buffer.from(bytes).toString("base64");
|
|
65
|
-
}
|
|
66
|
-
const btoaFn = getBtoa();
|
|
67
|
-
if (btoaFn) {
|
|
68
|
-
let binary = "";
|
|
69
|
-
const chunkSize = 32768;
|
|
70
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
71
|
-
const chunk = bytes.subarray(i, i + chunkSize);
|
|
72
|
-
binary += String.fromCharCode(...chunk);
|
|
73
|
-
}
|
|
74
|
-
return btoaFn(binary);
|
|
75
|
-
}
|
|
76
|
-
let output = "";
|
|
77
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
78
|
-
const a = bytes[i] ?? 0;
|
|
79
|
-
const b = i + 1 < bytes.length ? bytes[i + 1] ?? 0 : 0;
|
|
80
|
-
const c = i + 2 < bytes.length ? bytes[i + 2] ?? 0 : 0;
|
|
81
|
-
const triple = a << 16 | b << 8 | c;
|
|
82
|
-
output += BASE64_ALPHABET[triple >> 18 & 63];
|
|
83
|
-
output += BASE64_ALPHABET[triple >> 12 & 63];
|
|
84
|
-
output += i + 1 < bytes.length ? BASE64_ALPHABET[triple >> 6 & 63] : "=";
|
|
85
|
-
output += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
|
|
86
|
-
}
|
|
87
|
-
return output;
|
|
88
|
-
}
|
|
89
|
-
function toBinaryBody(handler) {
|
|
90
|
-
if (handler instanceof ArrayBuffer) {
|
|
91
|
-
return encodeBase64(new Uint8Array(handler));
|
|
92
|
-
}
|
|
93
|
-
if (handler instanceof Uint8Array) {
|
|
94
|
-
return encodeBase64(handler);
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
function buildManifestResponse(route, moduleId) {
|
|
99
|
-
if (moduleId) {
|
|
100
|
-
const response = {
|
|
101
|
-
type: "module",
|
|
102
|
-
module: moduleId
|
|
103
|
-
};
|
|
104
|
-
if (typeof route.ruleIndex === "number") {
|
|
105
|
-
response.ruleIndex = route.ruleIndex;
|
|
106
|
-
}
|
|
107
|
-
return response;
|
|
108
|
-
}
|
|
109
|
-
const handler = route.handler;
|
|
110
|
-
if (typeof handler === "string") {
|
|
111
|
-
return {
|
|
112
|
-
type: "text",
|
|
113
|
-
body: handler
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
const binary = toBinaryBody(handler);
|
|
117
|
-
if (binary) {
|
|
118
|
-
return {
|
|
119
|
-
type: "binary",
|
|
120
|
-
body: binary,
|
|
121
|
-
encoding: "base64"
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
type: "json",
|
|
126
|
-
body: handler
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function buildManifestData(params) {
|
|
130
|
-
const { routes, root } = params;
|
|
131
|
-
const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
|
|
132
|
-
const ruleModules = /* @__PURE__ */ new Map();
|
|
133
|
-
const middlewareModules = /* @__PURE__ */ new Map();
|
|
134
|
-
const manifestRoutes = routes.map((route) => {
|
|
135
|
-
const moduleId = shouldModuleize(route.handler) ? resolveModulePath(route.file, root) : null;
|
|
136
|
-
if (moduleId && !ruleModules.has(moduleId)) {
|
|
137
|
-
ruleModules.set(moduleId, { id: moduleId, kind: "rule" });
|
|
138
|
-
}
|
|
139
|
-
const middleware = route.middlewares?.map((entry) => {
|
|
140
|
-
const modulePath = resolveModulePath(entry.source, root);
|
|
141
|
-
if (!middlewareModules.has(modulePath)) {
|
|
142
|
-
middlewareModules.set(modulePath, { id: modulePath, kind: "middleware" });
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
module: modulePath,
|
|
146
|
-
ruleIndex: entry.index
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
const response = buildManifestResponse(route, moduleId);
|
|
150
|
-
const manifestRoute = {
|
|
151
|
-
method: route.method,
|
|
152
|
-
url: route.template,
|
|
153
|
-
...route.tokens ? { tokens: route.tokens } : {},
|
|
154
|
-
...route.score ? { score: route.score } : {},
|
|
155
|
-
...route.status ? { status: route.status } : {},
|
|
156
|
-
...route.headers ? { headers: route.headers } : {},
|
|
157
|
-
...route.delay ? { delay: route.delay } : {},
|
|
158
|
-
...middleware && middleware.length > 0 ? { middleware } : {},
|
|
159
|
-
response
|
|
160
|
-
};
|
|
161
|
-
return manifestRoute;
|
|
162
|
-
});
|
|
163
|
-
const manifest = {
|
|
164
|
-
version: 1,
|
|
165
|
-
routes: manifestRoutes
|
|
166
|
-
};
|
|
167
|
-
return {
|
|
168
|
-
manifest,
|
|
169
|
-
modules: [
|
|
170
|
-
...ruleModules.values(),
|
|
171
|
-
...middlewareModules.values()
|
|
172
|
-
]
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
exports.buildManifestData = buildManifestData;
|
|
177
|
-
exports.configExtensions = configExtensions;
|
|
178
|
-
exports.methodSet = methodSet;
|
|
179
|
-
exports.methodSuffixSet = methodSuffixSet;
|
|
180
|
-
exports.supportedExtensions = supportedExtensions;
|
|
181
|
-
exports.toViteImportPath = toViteImportPath;
|