mokup 2.1.1 → 2.2.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.
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const bundle = require('./shared/mokup.zkaN1ADs.cjs');
4
+ require('./shared/mokup.C7-7PDF7.cjs');
5
+ require('@mokup/shared/pathe');
6
+
7
+
8
+
9
+ exports.buildBundleModule = bundle.buildBundleModule;
@@ -0,0 +1,24 @@
1
+ import { R as RouteTable } from './shared/mokup.DeotZ0g8.cjs';
2
+ export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.cjs';
3
+ import '@mokup/runtime';
4
+ import '@mokup/shared';
5
+ import '@mokup/shared/hono';
6
+
7
+ /**
8
+ * Build the source for a virtual mokup bundle module.
9
+ *
10
+ * @param params - Bundle build parameters.
11
+ * @returns JavaScript source string.
12
+ *
13
+ * @example
14
+ * import { buildBundleModule } from 'mokup/bundle'
15
+ *
16
+ * const source = buildBundleModule({ routes: [], root: '/project' })
17
+ */
18
+ declare function buildBundleModule(params: {
19
+ routes: RouteTable;
20
+ root: string;
21
+ resolveModulePath?: (file: string, root: string) => string;
22
+ }): string;
23
+
24
+ export { RouteTable, buildBundleModule };
@@ -0,0 +1,24 @@
1
+ import { R as RouteTable } from './shared/mokup.DeotZ0g8.mjs';
2
+ export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.mjs';
3
+ import '@mokup/runtime';
4
+ import '@mokup/shared';
5
+ import '@mokup/shared/hono';
6
+
7
+ /**
8
+ * Build the source for a virtual mokup bundle module.
9
+ *
10
+ * @param params - Bundle build parameters.
11
+ * @returns JavaScript source string.
12
+ *
13
+ * @example
14
+ * import { buildBundleModule } from 'mokup/bundle'
15
+ *
16
+ * const source = buildBundleModule({ routes: [], root: '/project' })
17
+ */
18
+ declare function buildBundleModule(params: {
19
+ routes: RouteTable;
20
+ root: string;
21
+ resolveModulePath?: (file: string, root: string) => string;
22
+ }): string;
23
+
24
+ export { RouteTable, buildBundleModule };
@@ -0,0 +1,24 @@
1
+ import { R as RouteTable } from './shared/mokup.DeotZ0g8.js';
2
+ export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.js';
3
+ import '@mokup/runtime';
4
+ import '@mokup/shared';
5
+ import '@mokup/shared/hono';
6
+
7
+ /**
8
+ * Build the source for a virtual mokup bundle module.
9
+ *
10
+ * @param params - Bundle build parameters.
11
+ * @returns JavaScript source string.
12
+ *
13
+ * @example
14
+ * import { buildBundleModule } from 'mokup/bundle'
15
+ *
16
+ * const source = buildBundleModule({ routes: [], root: '/project' })
17
+ */
18
+ declare function buildBundleModule(params: {
19
+ routes: RouteTable;
20
+ root: string;
21
+ resolveModulePath?: (file: string, root: string) => string;
22
+ }): string;
23
+
24
+ export { RouteTable, buildBundleModule };
@@ -0,0 +1,3 @@
1
+ export { b as buildBundleModule } from './shared/mokup.vAap-D_L.mjs';
2
+ import './shared/mokup.JBCzv4xR.mjs';
3
+ import '@mokup/shared/pathe';
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
- import { c as RouteDirectoryConfig, b as MiddlewareRegistry, R as RequestHandler, e as RouteRule } from './shared/mokup.CWQ8woZc.cjs';
2
- export { H as HttpMethod, a as MiddlewarePosition, M as MokupPluginOptions, d as RouteResponse, f as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, g as VitePluginOptionsInput } from './shared/mokup.CWQ8woZc.cjs';
1
+ import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.cjs';
2
+ export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.cjs';
3
3
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
4
4
  export { PlaygroundOptionsInput } from '@mokup/shared';
5
+ import '@mokup/runtime';
5
6
 
6
7
  type DefineConfigFactory = (context: {
7
8
  pre: MiddlewareRegistry;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
- import { c as RouteDirectoryConfig, b as MiddlewareRegistry, R as RequestHandler, e as RouteRule } from './shared/mokup.CWQ8woZc.mjs';
2
- export { H as HttpMethod, a as MiddlewarePosition, M as MokupPluginOptions, d as RouteResponse, f as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, g as VitePluginOptionsInput } from './shared/mokup.CWQ8woZc.mjs';
1
+ import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.mjs';
2
+ export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.mjs';
3
3
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
4
4
  export { PlaygroundOptionsInput } from '@mokup/shared';
5
+ import '@mokup/runtime';
5
6
 
6
7
  type DefineConfigFactory = (context: {
7
8
  pre: MiddlewareRegistry;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /// <reference path="./types/virtual.d.ts" />
2
2
 
3
- import { c as RouteDirectoryConfig, b as MiddlewareRegistry, R as RequestHandler, e as RouteRule } from './shared/mokup.CWQ8woZc.js';
4
- export { H as HttpMethod, a as MiddlewarePosition, M as MokupPluginOptions, d as RouteResponse, f as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, g as VitePluginOptionsInput } from './shared/mokup.CWQ8woZc.js';
3
+ import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.js';
4
+ export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.js';
5
5
  export { Context, MiddlewareHandler } from '@mokup/shared/hono';
6
6
  export { PlaygroundOptionsInput } from '@mokup/shared';
7
+ import '@mokup/runtime';
7
8
 
8
9
  type DefineConfigFactory = (context: {
9
10
  pre: MiddlewareRegistry;
@@ -0,0 +1,252 @@
1
+ 'use strict';
2
+
3
+ const pathe = require('@mokup/shared/pathe');
4
+
5
+ const methodSet = /* @__PURE__ */ new Set([
6
+ "GET",
7
+ "POST",
8
+ "PUT",
9
+ "PATCH",
10
+ "DELETE",
11
+ "OPTIONS",
12
+ "HEAD"
13
+ ]);
14
+ const methodSuffixSet = new Set(
15
+ Array.from(methodSet, (method) => method.toLowerCase())
16
+ );
17
+ const supportedExtensions = /* @__PURE__ */ new Set([
18
+ ".json",
19
+ ".jsonc",
20
+ ".ts",
21
+ ".js",
22
+ ".mjs",
23
+ ".cjs"
24
+ ]);
25
+ const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
26
+
27
+ function normalizeMethod(method) {
28
+ if (!method) {
29
+ return void 0;
30
+ }
31
+ const normalized = method.toUpperCase();
32
+ if (methodSet.has(normalized)) {
33
+ return normalized;
34
+ }
35
+ return void 0;
36
+ }
37
+ function normalizePrefix(prefix) {
38
+ if (!prefix) {
39
+ return "";
40
+ }
41
+ const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
42
+ return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
43
+ }
44
+ function resolveDirs(dir, root) {
45
+ const raw = typeof dir === "function" ? dir(root) : dir;
46
+ const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
47
+ const normalized = resolved.map(
48
+ (entry) => pathe.isAbsolute(entry) ? entry : pathe.resolve(root, entry)
49
+ );
50
+ return Array.from(new Set(normalized));
51
+ }
52
+ function createDebouncer(delayMs, fn) {
53
+ let timer = null;
54
+ return () => {
55
+ if (timer) {
56
+ clearTimeout(timer);
57
+ }
58
+ timer = setTimeout(() => {
59
+ timer = null;
60
+ fn();
61
+ }, delayMs);
62
+ };
63
+ }
64
+ function toPosix(value) {
65
+ return value.replace(/\\/g, "/");
66
+ }
67
+ function isInDirs(file, dirs) {
68
+ const normalized = toPosix(file);
69
+ return dirs.some((dir) => {
70
+ const normalizedDir = toPosix(dir).replace(/\/$/, "");
71
+ return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
72
+ });
73
+ }
74
+ function normalizeIgnorePrefix(value, fallback = ["."]) {
75
+ const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
76
+ return list.filter((entry) => typeof entry === "string" && entry.length > 0);
77
+ }
78
+ function hasIgnoredPrefix(file, rootDir, prefixes) {
79
+ if (prefixes.length === 0) {
80
+ return false;
81
+ }
82
+ const relativePath = toPosix(pathe.relative(rootDir, file));
83
+ const segments = relativePath.split("/");
84
+ return segments.some(
85
+ (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
86
+ );
87
+ }
88
+ function delay(ms) {
89
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
90
+ }
91
+
92
+ function toViteImportPath(file, root) {
93
+ const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
94
+ const rel = pathe.relative(root, absolute);
95
+ if (!rel.startsWith("..") && !pathe.isAbsolute(rel)) {
96
+ return `/${toPosix(rel)}`;
97
+ }
98
+ return `/@fs/${toPosix(absolute)}`;
99
+ }
100
+ function shouldModuleize(handler) {
101
+ if (typeof handler === "function") {
102
+ return true;
103
+ }
104
+ if (typeof Response !== "undefined" && handler instanceof Response) {
105
+ return true;
106
+ }
107
+ return false;
108
+ }
109
+ const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
110
+ function getNodeBuffer() {
111
+ if (typeof globalThis === "undefined") {
112
+ return null;
113
+ }
114
+ const buffer = globalThis.Buffer;
115
+ return buffer ?? null;
116
+ }
117
+ function getBtoa() {
118
+ if (typeof globalThis === "undefined") {
119
+ return null;
120
+ }
121
+ const btoaFn = globalThis.btoa;
122
+ return typeof btoaFn === "function" ? btoaFn : null;
123
+ }
124
+ function encodeBase64(bytes) {
125
+ const buffer = getNodeBuffer();
126
+ if (buffer) {
127
+ return buffer.from(bytes).toString("base64");
128
+ }
129
+ const btoaFn = getBtoa();
130
+ if (btoaFn) {
131
+ let binary = "";
132
+ const chunkSize = 32768;
133
+ for (let i = 0; i < bytes.length; i += chunkSize) {
134
+ const chunk = bytes.subarray(i, i + chunkSize);
135
+ binary += String.fromCharCode(...chunk);
136
+ }
137
+ return btoaFn(binary);
138
+ }
139
+ let output = "";
140
+ for (let i = 0; i < bytes.length; i += 3) {
141
+ const a = bytes[i] ?? 0;
142
+ const b = i + 1 < bytes.length ? bytes[i + 1] ?? 0 : 0;
143
+ const c = i + 2 < bytes.length ? bytes[i + 2] ?? 0 : 0;
144
+ const triple = a << 16 | b << 8 | c;
145
+ output += BASE64_ALPHABET[triple >> 18 & 63];
146
+ output += BASE64_ALPHABET[triple >> 12 & 63];
147
+ output += i + 1 < bytes.length ? BASE64_ALPHABET[triple >> 6 & 63] : "=";
148
+ output += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
149
+ }
150
+ return output;
151
+ }
152
+ function toBinaryBody(handler) {
153
+ if (handler instanceof ArrayBuffer) {
154
+ return encodeBase64(new Uint8Array(handler));
155
+ }
156
+ if (handler instanceof Uint8Array) {
157
+ return encodeBase64(handler);
158
+ }
159
+ return null;
160
+ }
161
+ function buildManifestResponse(route, moduleId) {
162
+ if (moduleId) {
163
+ const response = {
164
+ type: "module",
165
+ module: moduleId
166
+ };
167
+ if (typeof route.ruleIndex === "number") {
168
+ response.ruleIndex = route.ruleIndex;
169
+ }
170
+ return response;
171
+ }
172
+ const handler = route.handler;
173
+ if (typeof handler === "string") {
174
+ return {
175
+ type: "text",
176
+ body: handler
177
+ };
178
+ }
179
+ const binary = toBinaryBody(handler);
180
+ if (binary) {
181
+ return {
182
+ type: "binary",
183
+ body: binary,
184
+ encoding: "base64"
185
+ };
186
+ }
187
+ return {
188
+ type: "json",
189
+ body: handler
190
+ };
191
+ }
192
+ function buildManifestData(params) {
193
+ const { routes, root } = params;
194
+ const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
195
+ const ruleModules = /* @__PURE__ */ new Map();
196
+ const middlewareModules = /* @__PURE__ */ new Map();
197
+ const manifestRoutes = routes.map((route) => {
198
+ const moduleId = shouldModuleize(route.handler) ? resolveModulePath(route.file, root) : null;
199
+ if (moduleId && !ruleModules.has(moduleId)) {
200
+ ruleModules.set(moduleId, { id: moduleId, kind: "rule" });
201
+ }
202
+ const middleware = route.middlewares?.map((entry) => {
203
+ const modulePath = resolveModulePath(entry.source, root);
204
+ if (!middlewareModules.has(modulePath)) {
205
+ middlewareModules.set(modulePath, { id: modulePath, kind: "middleware" });
206
+ }
207
+ return {
208
+ module: modulePath,
209
+ ruleIndex: entry.index
210
+ };
211
+ });
212
+ const response = buildManifestResponse(route, moduleId);
213
+ const manifestRoute = {
214
+ method: route.method,
215
+ url: route.template,
216
+ ...route.tokens ? { tokens: route.tokens } : {},
217
+ ...route.score ? { score: route.score } : {},
218
+ ...route.status ? { status: route.status } : {},
219
+ ...route.headers ? { headers: route.headers } : {},
220
+ ...route.delay ? { delay: route.delay } : {},
221
+ ...middleware && middleware.length > 0 ? { middleware } : {},
222
+ response
223
+ };
224
+ return manifestRoute;
225
+ });
226
+ const manifest = {
227
+ version: 1,
228
+ routes: manifestRoutes
229
+ };
230
+ return {
231
+ manifest,
232
+ modules: [
233
+ ...ruleModules.values(),
234
+ ...middlewareModules.values()
235
+ ]
236
+ };
237
+ }
238
+
239
+ exports.buildManifestData = buildManifestData;
240
+ exports.configExtensions = configExtensions;
241
+ exports.createDebouncer = createDebouncer;
242
+ exports.delay = delay;
243
+ exports.hasIgnoredPrefix = hasIgnoredPrefix;
244
+ exports.isInDirs = isInDirs;
245
+ exports.methodSuffixSet = methodSuffixSet;
246
+ exports.normalizeIgnorePrefix = normalizeIgnorePrefix;
247
+ exports.normalizeMethod = normalizeMethod;
248
+ exports.normalizePrefix = normalizePrefix;
249
+ exports.resolveDirs = resolveDirs;
250
+ exports.supportedExtensions = supportedExtensions;
251
+ exports.toPosix = toPosix;
252
+ exports.toViteImportPath = toViteImportPath;