@mokup/shared 1.1.4 → 2.0.0
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 +58 -0
- package/dist/chokidar.d.mts +3 -8
- package/dist/chokidar.d.ts +3 -9
- package/dist/chokidar.mjs +2 -1
- package/dist/chunk-_iGcCiPk.mjs +28 -0
- package/dist/{config-core.d.cts → config-core-dqVMz7on.d.mts} +3 -2
- package/dist/config-core-dqVMz7on.d.ts +5 -0
- package/dist/config-core.d.mts +2 -4
- package/dist/config-core.d.ts +2 -4
- package/dist/config-core.mjs +3 -2
- package/dist/config-utils-DFu0_9tl.d.mts +59 -0
- package/dist/config-utils-DFu0_9tl.d.ts +59 -0
- package/dist/config-utils.d.mts +3 -62
- package/dist/config-utils.d.ts +3 -62
- package/dist/config-utils.mjs +143 -159
- package/dist/define-config-CzB1-X1m.d.mts +20 -0
- package/dist/define-config-CzB1-X1m.d.ts +20 -0
- package/dist/define-config.d.mts +2 -20
- package/dist/define-config.d.ts +2 -20
- package/dist/define-config.mjs +146 -162
- package/dist/diagnostic-types-DqAzUbgn.d.mts +39 -0
- package/dist/diagnostic-types-DqAzUbgn.d.ts +39 -0
- package/dist/diagnostic-types.d.mts +2 -0
- package/dist/diagnostic-types.d.ts +2 -0
- package/dist/diagnostic-types.mjs +29 -0
- package/dist/diagnostics-C3QaEtqE.d.mts +101 -0
- package/dist/diagnostics-C3QaEtqE.d.ts +101 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.mjs +129 -0
- package/dist/hono.d.mts +4 -3
- package/dist/hono.d.ts +4 -3
- package/dist/hono.mjs +4 -3
- package/dist/index-5prVUGOX.d.mts +113 -0
- package/dist/index-5prVUGOX.d.ts +113 -0
- package/dist/index.d.mts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.mjs +13 -18
- package/dist/jsonc-parser.d.mts +1 -1
- package/dist/jsonc-parser.d.ts +1 -1
- package/dist/jsonc-parser.mjs +8 -1
- package/dist/jsonc-utils-_Hs6a39T.d.mts +7 -0
- package/dist/jsonc-utils-_Hs6a39T.d.ts +7 -0
- package/dist/jsonc-utils.d.mts +2 -7
- package/dist/jsonc-utils.d.ts +2 -7
- package/dist/jsonc-utils.mjs +20 -20
- package/dist/load-rules-D_kCpu9I.d.mts +14 -0
- package/dist/load-rules-D_kCpu9I.d.ts +14 -0
- package/dist/load-rules.d.mts +2 -14
- package/dist/load-rules.d.ts +2 -14
- package/dist/load-rules.mjs +16 -34
- package/dist/logger-types-BbqYCr6j.d.mts +50 -0
- package/dist/logger-types-BbqYCr6j.d.ts +50 -0
- package/dist/logger.browser.d.mts +4 -3
- package/dist/logger.browser.d.ts +4 -3
- package/dist/logger.browser.mjs +49 -48
- package/dist/logger.d.mts +4 -3
- package/dist/logger.d.ts +4 -3
- package/dist/logger.mjs +49 -48
- package/dist/{mock-files.d.cts → mock-files-DfGigWmY.d.mts} +5 -5
- package/dist/mock-files-DfGigWmY.d.ts +10 -0
- package/dist/mock-files.d.mts +2 -10
- package/dist/mock-files.d.ts +2 -10
- package/dist/mock-files.mjs +38 -50
- package/dist/{module-loader.d.cts → module-loader-nAQlwo3D.d.mts} +7 -6
- package/dist/module-loader-nAQlwo3D.d.ts +14 -0
- package/dist/module-loader.d.mts +2 -13
- package/dist/module-loader.d.ts +2 -13
- package/dist/module-loader.mjs +60 -69
- package/dist/path-utils.d.mts +3 -2
- package/dist/path-utils.d.ts +3 -2
- package/dist/path-utils.mjs +25 -35
- package/dist/pathe.d.mts +1 -1
- package/dist/pathe.d.ts +1 -1
- package/dist/pathe.mjs +8 -1
- package/dist/playground-grouping.d.mts +6 -6
- package/dist/playground-grouping.d.ts +6 -6
- package/dist/playground-grouping.mjs +57 -77
- package/dist/rolldown.d.mts +37 -0
- package/dist/rolldown.d.ts +37 -0
- package/dist/rolldown.mjs +81 -0
- package/dist/{route-constants.d.cts → route-constants-BUi36iYR.d.mts} +3 -2
- package/dist/route-constants-BUi36iYR.d.ts +8 -0
- package/dist/route-constants.d.mts +2 -7
- package/dist/route-constants.d.ts +2 -7
- package/dist/route-constants.mjs +25 -21
- package/dist/route-utils-BiWFUqo-.d.mts +42 -0
- package/dist/route-utils-BiWFUqo-.d.ts +42 -0
- package/dist/route-utils.d.mts +2 -42
- package/dist/route-utils.d.ts +2 -42
- package/dist/route-utils.mjs +94 -121
- package/dist/scan-utils.d.mts +2 -114
- package/dist/scan-utils.d.ts +2 -114
- package/dist/scan-utils.mjs +14 -25
- package/dist/timing.d.mts +3 -2
- package/dist/timing.d.ts +3 -2
- package/dist/timing.mjs +11 -12
- package/package.json +88 -128
- package/dist/chokidar.cjs +0 -11
- package/dist/chokidar.d.cts +0 -9
- package/dist/config-core.cjs +0 -9
- package/dist/config-utils.cjs +0 -179
- package/dist/config-utils.d.cts +0 -62
- package/dist/define-config.cjs +0 -169
- package/dist/define-config.d.cts +0 -20
- package/dist/esbuild.cjs +0 -16
- package/dist/esbuild.d.cts +0 -1
- package/dist/esbuild.d.mts +0 -1
- package/dist/esbuild.d.ts +0 -1
- package/dist/esbuild.mjs +0 -1
- package/dist/hono.cjs +0 -20
- package/dist/hono.d.cts +0 -3
- package/dist/index.cjs +0 -50
- package/dist/index.d.cts +0 -10
- package/dist/jsonc-parser.cjs +0 -16
- package/dist/jsonc-parser.d.cts +0 -1
- package/dist/jsonc-utils.cjs +0 -25
- package/dist/jsonc-utils.d.cts +0 -7
- package/dist/load-rules.cjs +0 -39
- package/dist/load-rules.d.cts +0 -14
- package/dist/logger.browser.cjs +0 -55
- package/dist/logger.browser.d.cts +0 -21
- package/dist/logger.cjs +0 -55
- package/dist/logger.d.cts +0 -21
- package/dist/mock-files.cjs +0 -65
- package/dist/module-loader.cjs +0 -93
- package/dist/path-utils.cjs +0 -57
- package/dist/path-utils.d.cts +0 -7
- package/dist/pathe.cjs +0 -16
- package/dist/pathe.d.cts +0 -1
- package/dist/playground-grouping.cjs +0 -95
- package/dist/playground-grouping.d.cts +0 -12
- package/dist/route-constants.cjs +0 -30
- package/dist/route-utils.cjs +0 -126
- package/dist/route-utils.d.cts +0 -42
- package/dist/scan-utils.cjs +0 -39
- package/dist/scan-utils.d.cts +0 -114
- package/dist/shared/shared.DazgCdsk.d.cts +0 -49
- package/dist/shared/shared.DazgCdsk.d.mts +0 -49
- package/dist/shared/shared.DazgCdsk.d.ts +0 -49
- package/dist/timing.cjs +0 -20
- package/dist/timing.d.cts +0 -4
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare const supportedExtensions: Set<string>;
|
|
4
|
-
declare const configExtensions: readonly [".ts", ".js", ".mjs", ".cjs"];
|
|
5
|
-
declare const jsonExtensions: Set<string>;
|
|
6
|
-
|
|
7
|
-
export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };
|
|
1
|
+
import { a as supportedExtensions, i as methodSuffixSet, n as jsonExtensions, r as methodSet, t as configExtensions } from "./route-constants-BUi36iYR.mjs";
|
|
2
|
+
export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };
|
package/dist/route-constants.mjs
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/route-constants.ts
|
|
2
|
+
const methodSet = new Set([
|
|
3
|
+
"GET",
|
|
4
|
+
"POST",
|
|
5
|
+
"PUT",
|
|
6
|
+
"PATCH",
|
|
7
|
+
"DELETE",
|
|
8
|
+
"OPTIONS",
|
|
9
|
+
"HEAD"
|
|
9
10
|
]);
|
|
10
|
-
const methodSuffixSet = new Set(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
".mjs",
|
|
19
|
-
".cjs"
|
|
11
|
+
const methodSuffixSet = new Set(Array.from(methodSet, (method) => method.toLowerCase()));
|
|
12
|
+
const supportedExtensions = new Set([
|
|
13
|
+
".json",
|
|
14
|
+
".jsonc",
|
|
15
|
+
".ts",
|
|
16
|
+
".js",
|
|
17
|
+
".mjs",
|
|
18
|
+
".cjs"
|
|
20
19
|
]);
|
|
21
|
-
const configExtensions = [
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const configExtensions = [
|
|
21
|
+
".ts",
|
|
22
|
+
".js",
|
|
23
|
+
".mjs",
|
|
24
|
+
".cjs"
|
|
25
|
+
];
|
|
26
|
+
const jsonExtensions = new Set([".json", ".jsonc"]);
|
|
27
|
+
//#endregion
|
|
24
28
|
export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/route-utils.d.ts
|
|
2
|
+
interface RouteParserResult<TToken = unknown> {
|
|
3
|
+
template: string;
|
|
4
|
+
tokens: TToken[];
|
|
5
|
+
score: number[];
|
|
6
|
+
errors: string[];
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}
|
|
9
|
+
type RouteParser<TToken = unknown> = (template: string) => RouteParserResult<TToken>;
|
|
10
|
+
type RouteScoreComparator = (a: number[], b: number[]) => number;
|
|
11
|
+
interface DerivedRoute<TToken = unknown, TMethod extends string = string> {
|
|
12
|
+
template: string;
|
|
13
|
+
method: TMethod;
|
|
14
|
+
tokens: TToken[];
|
|
15
|
+
score: number[];
|
|
16
|
+
}
|
|
17
|
+
declare function createRouteUtils<TToken = unknown, TRule extends {
|
|
18
|
+
handler: unknown;
|
|
19
|
+
} = {
|
|
20
|
+
handler: unknown;
|
|
21
|
+
}, TMethod extends string = string>(params: {
|
|
22
|
+
parseRouteTemplate: RouteParser<TToken>;
|
|
23
|
+
compareRouteScore: RouteScoreComparator;
|
|
24
|
+
}): {
|
|
25
|
+
deriveRouteFromFile: (file: string, rootDir: string, warn?: (message: string) => void) => DerivedRoute<TToken, TMethod> | null;
|
|
26
|
+
resolveRule: <TOutput = DerivedRoute<TToken, TMethod>>(input: {
|
|
27
|
+
rule: TRule;
|
|
28
|
+
derivedTemplate: string;
|
|
29
|
+
derivedMethod?: TMethod | undefined;
|
|
30
|
+
prefix: string;
|
|
31
|
+
file: string;
|
|
32
|
+
warn?: (message: string) => void;
|
|
33
|
+
build?: (base: DerivedRoute<TToken, TMethod>, rule: TRule) => TOutput;
|
|
34
|
+
}) => TOutput | null;
|
|
35
|
+
sortRoutes: <TRoute extends {
|
|
36
|
+
method: string;
|
|
37
|
+
score: number[];
|
|
38
|
+
template: string;
|
|
39
|
+
}>(routes: TRoute[]) => TRoute[];
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createRouteUtils as a, RouteScoreComparator as i, RouteParser as n, RouteParserResult as r, DerivedRoute as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/route-utils.d.ts
|
|
2
|
+
interface RouteParserResult<TToken = unknown> {
|
|
3
|
+
template: string;
|
|
4
|
+
tokens: TToken[];
|
|
5
|
+
score: number[];
|
|
6
|
+
errors: string[];
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}
|
|
9
|
+
type RouteParser<TToken = unknown> = (template: string) => RouteParserResult<TToken>;
|
|
10
|
+
type RouteScoreComparator = (a: number[], b: number[]) => number;
|
|
11
|
+
interface DerivedRoute<TToken = unknown, TMethod extends string = string> {
|
|
12
|
+
template: string;
|
|
13
|
+
method: TMethod;
|
|
14
|
+
tokens: TToken[];
|
|
15
|
+
score: number[];
|
|
16
|
+
}
|
|
17
|
+
declare function createRouteUtils<TToken = unknown, TRule extends {
|
|
18
|
+
handler: unknown;
|
|
19
|
+
} = {
|
|
20
|
+
handler: unknown;
|
|
21
|
+
}, TMethod extends string = string>(params: {
|
|
22
|
+
parseRouteTemplate: RouteParser<TToken>;
|
|
23
|
+
compareRouteScore: RouteScoreComparator;
|
|
24
|
+
}): {
|
|
25
|
+
deriveRouteFromFile: (file: string, rootDir: string, warn?: (message: string) => void) => DerivedRoute<TToken, TMethod> | null;
|
|
26
|
+
resolveRule: <TOutput = DerivedRoute<TToken, TMethod>>(input: {
|
|
27
|
+
rule: TRule;
|
|
28
|
+
derivedTemplate: string;
|
|
29
|
+
derivedMethod?: TMethod | undefined;
|
|
30
|
+
prefix: string;
|
|
31
|
+
file: string;
|
|
32
|
+
warn?: (message: string) => void;
|
|
33
|
+
build?: (base: DerivedRoute<TToken, TMethod>, rule: TRule) => TOutput;
|
|
34
|
+
}) => TOutput | null;
|
|
35
|
+
sortRoutes: <TRoute extends {
|
|
36
|
+
method: string;
|
|
37
|
+
score: number[];
|
|
38
|
+
template: string;
|
|
39
|
+
}>(routes: TRoute[]) => TRoute[];
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createRouteUtils as a, RouteScoreComparator as i, RouteParser as n, RouteParserResult as r, DerivedRoute as t };
|
package/dist/route-utils.d.mts
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
tokens: TToken[];
|
|
4
|
-
score: number[];
|
|
5
|
-
errors: string[];
|
|
6
|
-
warnings: string[];
|
|
7
|
-
}
|
|
8
|
-
type RouteParser<TToken = unknown> = (template: string) => RouteParserResult<TToken>;
|
|
9
|
-
type RouteScoreComparator = (a: number[], b: number[]) => number;
|
|
10
|
-
interface DerivedRoute<TToken = unknown, TMethod extends string = string> {
|
|
11
|
-
template: string;
|
|
12
|
-
method: TMethod;
|
|
13
|
-
tokens: TToken[];
|
|
14
|
-
score: number[];
|
|
15
|
-
}
|
|
16
|
-
declare function createRouteUtils<TToken = unknown, TRule extends {
|
|
17
|
-
handler: unknown;
|
|
18
|
-
} = {
|
|
19
|
-
handler: unknown;
|
|
20
|
-
}, TMethod extends string = string>(params: {
|
|
21
|
-
parseRouteTemplate: RouteParser<TToken>;
|
|
22
|
-
compareRouteScore: RouteScoreComparator;
|
|
23
|
-
}): {
|
|
24
|
-
deriveRouteFromFile: (file: string, rootDir: string, warn?: (message: string) => void) => DerivedRoute<TToken, TMethod> | null;
|
|
25
|
-
resolveRule: <TOutput = DerivedRoute<TToken, TMethod>>(input: {
|
|
26
|
-
rule: TRule;
|
|
27
|
-
derivedTemplate: string;
|
|
28
|
-
derivedMethod?: TMethod | undefined;
|
|
29
|
-
prefix: string;
|
|
30
|
-
file: string;
|
|
31
|
-
warn?: (message: string) => void;
|
|
32
|
-
build?: (base: DerivedRoute<TToken, TMethod>, rule: TRule) => TOutput;
|
|
33
|
-
}) => TOutput | null;
|
|
34
|
-
sortRoutes: <TRoute extends {
|
|
35
|
-
method: string;
|
|
36
|
-
score: number[];
|
|
37
|
-
template: string;
|
|
38
|
-
}>(routes: TRoute[]) => TRoute[];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { createRouteUtils };
|
|
42
|
-
export type { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator };
|
|
1
|
+
import { a as createRouteUtils, i as RouteScoreComparator, n as RouteParser, r as RouteParserResult, t as DerivedRoute } from "./route-utils-BiWFUqo-.mjs";
|
|
2
|
+
export { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator, createRouteUtils };
|
package/dist/route-utils.d.ts
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
tokens: TToken[];
|
|
4
|
-
score: number[];
|
|
5
|
-
errors: string[];
|
|
6
|
-
warnings: string[];
|
|
7
|
-
}
|
|
8
|
-
type RouteParser<TToken = unknown> = (template: string) => RouteParserResult<TToken>;
|
|
9
|
-
type RouteScoreComparator = (a: number[], b: number[]) => number;
|
|
10
|
-
interface DerivedRoute<TToken = unknown, TMethod extends string = string> {
|
|
11
|
-
template: string;
|
|
12
|
-
method: TMethod;
|
|
13
|
-
tokens: TToken[];
|
|
14
|
-
score: number[];
|
|
15
|
-
}
|
|
16
|
-
declare function createRouteUtils<TToken = unknown, TRule extends {
|
|
17
|
-
handler: unknown;
|
|
18
|
-
} = {
|
|
19
|
-
handler: unknown;
|
|
20
|
-
}, TMethod extends string = string>(params: {
|
|
21
|
-
parseRouteTemplate: RouteParser<TToken>;
|
|
22
|
-
compareRouteScore: RouteScoreComparator;
|
|
23
|
-
}): {
|
|
24
|
-
deriveRouteFromFile: (file: string, rootDir: string, warn?: (message: string) => void) => DerivedRoute<TToken, TMethod> | null;
|
|
25
|
-
resolveRule: <TOutput = DerivedRoute<TToken, TMethod>>(input: {
|
|
26
|
-
rule: TRule;
|
|
27
|
-
derivedTemplate: string;
|
|
28
|
-
derivedMethod?: TMethod | undefined;
|
|
29
|
-
prefix: string;
|
|
30
|
-
file: string;
|
|
31
|
-
warn?: (message: string) => void;
|
|
32
|
-
build?: (base: DerivedRoute<TToken, TMethod>, rule: TRule) => TOutput;
|
|
33
|
-
}) => TOutput | null;
|
|
34
|
-
sortRoutes: <TRoute extends {
|
|
35
|
-
method: string;
|
|
36
|
-
score: number[];
|
|
37
|
-
template: string;
|
|
38
|
-
}>(routes: TRoute[]) => TRoute[];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { createRouteUtils };
|
|
42
|
-
export type { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator };
|
|
1
|
+
import { a as createRouteUtils, i as RouteScoreComparator, n as RouteParser, r as RouteParserResult, t as DerivedRoute } from "./route-utils-BiWFUqo-.mjs";
|
|
2
|
+
export { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator, createRouteUtils };
|
package/dist/route-utils.mjs
CHANGED
|
@@ -1,124 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { normalizePrefix } from
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { t as pathe_exports } from "./pathe.mjs";
|
|
2
|
+
import { jsonExtensions, methodSuffixSet } from "./route-constants.mjs";
|
|
3
|
+
import { toPosix } from "./path-utils.mjs";
|
|
4
|
+
import { normalizePrefix } from "./scan-utils.mjs";
|
|
5
|
+
//#region src/route-utils.ts
|
|
7
6
|
function createRouteUtils(params) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
const base = {
|
|
98
|
-
template: parsed.template,
|
|
99
|
-
method,
|
|
100
|
-
tokens: parsed.tokens,
|
|
101
|
-
score: parsed.score
|
|
102
|
-
};
|
|
103
|
-
return input.build ? input.build(base, input.rule) : base;
|
|
104
|
-
}
|
|
105
|
-
function sortRoutes(routes) {
|
|
106
|
-
return routes.sort((a, b) => {
|
|
107
|
-
if (a.method !== b.method) {
|
|
108
|
-
return a.method.localeCompare(b.method);
|
|
109
|
-
}
|
|
110
|
-
const scoreCompare = compareRouteScore(a.score, b.score);
|
|
111
|
-
if (scoreCompare !== 0) {
|
|
112
|
-
return scoreCompare;
|
|
113
|
-
}
|
|
114
|
-
return a.template.localeCompare(b.template);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
deriveRouteFromFile,
|
|
119
|
-
resolveRule,
|
|
120
|
-
sortRoutes
|
|
121
|
-
};
|
|
7
|
+
const { parseRouteTemplate, compareRouteScore } = params;
|
|
8
|
+
function resolveTemplate(template, prefix) {
|
|
9
|
+
const normalized = template.startsWith("/") ? template : `/${template}`;
|
|
10
|
+
if (!prefix) return normalized;
|
|
11
|
+
const normalizedPrefix = normalizePrefix(prefix);
|
|
12
|
+
if (!normalizedPrefix) return normalized;
|
|
13
|
+
if (normalized === normalizedPrefix || normalized.startsWith(`${normalizedPrefix}/`)) return normalized;
|
|
14
|
+
if (normalized === "/") return `${normalizedPrefix}/`;
|
|
15
|
+
return `${normalizedPrefix}${normalized}`;
|
|
16
|
+
}
|
|
17
|
+
function stripMethodSuffix(base) {
|
|
18
|
+
const segments = base.split(".");
|
|
19
|
+
const last = segments.at(-1);
|
|
20
|
+
if (last && methodSuffixSet.has(last.toLowerCase())) {
|
|
21
|
+
segments.pop();
|
|
22
|
+
return {
|
|
23
|
+
name: segments.join("."),
|
|
24
|
+
method: last.toUpperCase()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
name: base,
|
|
29
|
+
method: void 0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function deriveRouteFromFile(file, rootDir, warn) {
|
|
33
|
+
const rel = toPosix((0, pathe_exports.relative)(rootDir, file));
|
|
34
|
+
const ext = (0, pathe_exports.extname)(rel);
|
|
35
|
+
const withoutExt = rel.slice(0, rel.length - ext.length);
|
|
36
|
+
const dir = (0, pathe_exports.dirname)(withoutExt);
|
|
37
|
+
const { name, method } = stripMethodSuffix((0, pathe_exports.basename)(withoutExt));
|
|
38
|
+
const resolvedMethod = method ?? (jsonExtensions.has(ext) ? "GET" : void 0);
|
|
39
|
+
if (!resolvedMethod) {
|
|
40
|
+
warn?.(`Skip mock without method suffix: ${file}`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!name) {
|
|
44
|
+
warn?.(`Skip mock with empty route name: ${file}`);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const segments = toPosix(dir === "." ? name : (0, pathe_exports.join)(dir, name)).split("/");
|
|
48
|
+
if (segments.at(-1) === "index") segments.pop();
|
|
49
|
+
const parsed = parseRouteTemplate(segments.length === 0 ? "/" : `/${segments.join("/")}`);
|
|
50
|
+
if (parsed.errors.length > 0) {
|
|
51
|
+
for (const error of parsed.errors) warn?.(`${error} in ${file}`);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
for (const warning of parsed.warnings) warn?.(`${warning} in ${file}`);
|
|
55
|
+
return {
|
|
56
|
+
template: parsed.template,
|
|
57
|
+
method: resolvedMethod,
|
|
58
|
+
tokens: parsed.tokens,
|
|
59
|
+
score: parsed.score
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function resolveRule(input) {
|
|
63
|
+
const method = input.derivedMethod;
|
|
64
|
+
if (!method) {
|
|
65
|
+
input.warn?.(`Skip mock without method suffix: ${input.file}`);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const parsed = parseRouteTemplate(resolveTemplate(input.derivedTemplate, input.prefix));
|
|
69
|
+
if (parsed.errors.length > 0) {
|
|
70
|
+
for (const error of parsed.errors) input.warn?.(`${error} in ${input.file}`);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
for (const warning of parsed.warnings) input.warn?.(`${warning} in ${input.file}`);
|
|
74
|
+
const base = {
|
|
75
|
+
template: parsed.template,
|
|
76
|
+
method,
|
|
77
|
+
tokens: parsed.tokens,
|
|
78
|
+
score: parsed.score
|
|
79
|
+
};
|
|
80
|
+
return input.build ? input.build(base, input.rule) : base;
|
|
81
|
+
}
|
|
82
|
+
function sortRoutes(routes) {
|
|
83
|
+
return routes.sort((a, b) => {
|
|
84
|
+
if (a.method !== b.method) return a.method.localeCompare(b.method);
|
|
85
|
+
const scoreCompare = compareRouteScore(a.score, b.score);
|
|
86
|
+
if (scoreCompare !== 0) return scoreCompare;
|
|
87
|
+
return a.template.localeCompare(b.template);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
deriveRouteFromFile,
|
|
92
|
+
resolveRule,
|
|
93
|
+
sortRoutes
|
|
94
|
+
};
|
|
122
95
|
}
|
|
123
|
-
|
|
96
|
+
//#endregion
|
|
124
97
|
export { createRouteUtils };
|
package/dist/scan-utils.d.mts
CHANGED
|
@@ -1,114 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import './define-config.mjs';
|
|
4
|
-
import './jsonc-utils.mjs';
|
|
5
|
-
import './load-rules.mjs';
|
|
6
|
-
import './mock-files.mjs';
|
|
7
|
-
import './module-loader.mjs';
|
|
8
|
-
import './route-constants.mjs';
|
|
9
|
-
import './route-utils.mjs';
|
|
10
|
-
|
|
11
|
-
declare function normalizeMethod(method?: string | null): string | undefined;
|
|
12
|
-
declare function normalizePrefix(prefix: string): string;
|
|
13
|
-
declare function resolveDirs(dir: DirInput, root: string): string[];
|
|
14
|
-
declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Directory input for mock scanning.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* import type { DirInput } from '@mokup/shared'
|
|
21
|
-
*
|
|
22
|
-
* const dir: DirInput = ['mock', 'fixtures']
|
|
23
|
-
*/
|
|
24
|
-
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Shared entry options for mokup scanners and plugins.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* import type { MockEntryOptions } from '@mokup/shared'
|
|
30
|
-
*
|
|
31
|
-
* const entry: MockEntryOptions = {
|
|
32
|
-
* dir: 'mock',
|
|
33
|
-
* prefix: '/api',
|
|
34
|
-
* watch: true,
|
|
35
|
-
* }
|
|
36
|
-
*/
|
|
37
|
-
interface MockEntryOptions {
|
|
38
|
-
/**
|
|
39
|
-
* Directory (or directories) to scan for mock routes.
|
|
40
|
-
*
|
|
41
|
-
* @default "mock" (resolved by Vite/webpack plugins)
|
|
42
|
-
*/
|
|
43
|
-
dir?: DirInput;
|
|
44
|
-
/**
|
|
45
|
-
* Request path prefix to mount mock routes under.
|
|
46
|
-
*
|
|
47
|
-
* @default ""
|
|
48
|
-
*/
|
|
49
|
-
prefix?: string;
|
|
50
|
-
/**
|
|
51
|
-
* Include filter for files to scan.
|
|
52
|
-
*
|
|
53
|
-
* @default undefined
|
|
54
|
-
*/
|
|
55
|
-
include?: RegExp | RegExp[];
|
|
56
|
-
/**
|
|
57
|
-
* Exclude filter for files to scan.
|
|
58
|
-
*
|
|
59
|
-
* @default undefined
|
|
60
|
-
*/
|
|
61
|
-
exclude?: RegExp | RegExp[];
|
|
62
|
-
/**
|
|
63
|
-
* Ignore file or folder prefixes when scanning.
|
|
64
|
-
*
|
|
65
|
-
* @default ["."]
|
|
66
|
-
*/
|
|
67
|
-
ignorePrefix?: string | string[];
|
|
68
|
-
/**
|
|
69
|
-
* Enable file watching for live route updates.
|
|
70
|
-
*
|
|
71
|
-
* @default true
|
|
72
|
-
*/
|
|
73
|
-
watch?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Enable mokup logging.
|
|
76
|
-
*
|
|
77
|
-
* @default true
|
|
78
|
-
*/
|
|
79
|
-
log?: boolean;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Playground configuration input.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* import type { PlaygroundOptionsInput } from '@mokup/shared'
|
|
86
|
-
*
|
|
87
|
-
* const playground: PlaygroundOptionsInput = {
|
|
88
|
-
* path: '/__mokup',
|
|
89
|
-
* enabled: true,
|
|
90
|
-
* }
|
|
91
|
-
*/
|
|
92
|
-
type PlaygroundOptionsInput = boolean | {
|
|
93
|
-
/**
|
|
94
|
-
* Base path for the playground UI.
|
|
95
|
-
*
|
|
96
|
-
* @default "/__mokup"
|
|
97
|
-
*/
|
|
98
|
-
path?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Emit playground assets during production builds.
|
|
101
|
-
*
|
|
102
|
-
* @default false
|
|
103
|
-
*/
|
|
104
|
-
build?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Enable or disable the playground routes.
|
|
107
|
-
*
|
|
108
|
-
* @default true
|
|
109
|
-
*/
|
|
110
|
-
enabled?: boolean;
|
|
111
|
-
} | undefined;
|
|
112
|
-
|
|
113
|
-
export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
|
|
114
|
-
export type { DirInput as D, MockEntryOptions as M, PlaygroundOptionsInput as P };
|
|
1
|
+
import { a as normalizeMethod, i as normalizeIgnorePrefix, o as normalizePrefix, s as resolveDirs } from "./index-5prVUGOX.mjs";
|
|
2
|
+
export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
|