mokup 2.3.0 → 2.3.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/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 +85 -24
- 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 };
|