@marko/run 0.6.6 → 0.7.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/README.md +70 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapter/index.cjs +15 -17
- package/dist/adapter/index.js +15 -17
- package/dist/cli/index.mjs +453 -410
- package/dist/runtime/internal.cjs +55 -28
- package/dist/runtime/internal.d.ts +2 -3
- package/dist/runtime/internal.js +55 -27
- package/dist/runtime/types.d.ts +8 -3
- package/dist/vite/codegen/index.d.ts +5 -6
- package/dist/vite/index.cjs +444 -416
- package/dist/vite/index.js +426 -395
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite/routes/builder.d.ts +3 -4
- package/dist/vite/routes/vdir.d.ts +0 -1
- package/dist/vite/routes/walk.d.ts +1 -1
- package/dist/vite/types.d.ts +26 -9
- package/dist/vite/utils/fs.d.ts +1 -0
- package/dist/vite/utils/route.d.ts +1 -0
- package/package.json +3 -2
|
@@ -29,7 +29,6 @@ __export(internal_exports, {
|
|
|
29
29
|
normalize: () => normalize,
|
|
30
30
|
notHandled: () => notHandled,
|
|
31
31
|
notMatched: () => notMatched,
|
|
32
|
-
pageResponse: () => pageResponse,
|
|
33
32
|
passthrough: () => passthrough,
|
|
34
33
|
stripResponseBody: () => stripResponseBody,
|
|
35
34
|
stripResponseBodySync: () => stripResponseBodySync
|
|
@@ -47,6 +46,7 @@ var NotHandled = Symbol(
|
|
|
47
46
|
var NotMatched = Symbol(
|
|
48
47
|
"marko-run not matched"
|
|
49
48
|
);
|
|
49
|
+
var parentContextLookup = /* @__PURE__ */ new WeakMap();
|
|
50
50
|
var serializedGlobals = { params: true, url: true };
|
|
51
51
|
var pageResponseInit = {
|
|
52
52
|
status: 200,
|
|
@@ -86,37 +86,65 @@ var toReadable = (rendered) => {
|
|
|
86
86
|
};
|
|
87
87
|
return toReadable(rendered);
|
|
88
88
|
};
|
|
89
|
-
function pageResponse(template, input, init = pageResponseInit) {
|
|
90
|
-
return new Response(toReadable(template.render(input)), init);
|
|
91
|
-
}
|
|
92
89
|
function createContext(route, request, platform, url = new URL(request.url)) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
meta
|
|
98
|
-
params
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
let meta;
|
|
91
|
+
let params;
|
|
92
|
+
let path;
|
|
93
|
+
if (route) {
|
|
94
|
+
meta = route.meta;
|
|
95
|
+
params = route.params;
|
|
96
|
+
path = route.path;
|
|
97
|
+
} else {
|
|
98
|
+
meta = {};
|
|
99
|
+
params = {};
|
|
100
|
+
path = "";
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
102
103
|
request,
|
|
103
104
|
url,
|
|
104
105
|
platform,
|
|
105
|
-
meta
|
|
106
|
-
params
|
|
107
|
-
route:
|
|
108
|
-
serializedGlobals
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
106
|
+
meta,
|
|
107
|
+
params,
|
|
108
|
+
route: path,
|
|
109
|
+
serializedGlobals,
|
|
110
|
+
parent: parentContextLookup.get(request),
|
|
111
|
+
async fetch(resource, init) {
|
|
112
|
+
let request2;
|
|
113
|
+
let url2;
|
|
114
|
+
if (resource instanceof Request) {
|
|
115
|
+
request2 = new Request(resource, init);
|
|
116
|
+
url2 = new URL(request2.url);
|
|
117
|
+
} else {
|
|
118
|
+
url2 = typeof resource === "string" ? new URL(resource, this.url) : resource;
|
|
119
|
+
request2 = new Request(url2, init);
|
|
120
|
+
}
|
|
121
|
+
parentContextLookup.set(request2, this);
|
|
122
|
+
return await globalThis.__marko_run__.fetch(request2, this.platform) || new Response(null, { status: 404 });
|
|
123
|
+
},
|
|
124
|
+
render(template, input, init = pageResponseInit) {
|
|
125
|
+
return new Response(
|
|
126
|
+
toReadable(
|
|
127
|
+
template.render({
|
|
128
|
+
...input,
|
|
129
|
+
$global: this
|
|
130
|
+
})
|
|
131
|
+
),
|
|
132
|
+
init
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
redirect(to, status) {
|
|
136
|
+
return Response.redirect(
|
|
137
|
+
typeof to === "string" ? new URL(to, this.url) : to,
|
|
138
|
+
status
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
back(fallback = "/", status) {
|
|
142
|
+
return this.redirect(
|
|
143
|
+
this.request.headers.get("referer") || fallback,
|
|
144
|
+
status
|
|
145
|
+
);
|
|
118
146
|
}
|
|
119
|
-
|
|
147
|
+
};
|
|
120
148
|
}
|
|
121
149
|
async function call(handler, next, context) {
|
|
122
150
|
let response;
|
|
@@ -223,7 +251,6 @@ function notMatched() {
|
|
|
223
251
|
normalize,
|
|
224
252
|
notHandled,
|
|
225
253
|
notMatched,
|
|
226
|
-
pageResponse,
|
|
227
254
|
passthrough,
|
|
228
255
|
stripResponseBody,
|
|
229
256
|
stripResponseBodySync
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { AnyRoute, Awaitable, Context,
|
|
1
|
+
import type { AnyRoute, Awaitable, Context, MultiRouteContext, NextFunction, Platform, RouteHandler } from "./types";
|
|
2
2
|
export declare const NotHandled: typeof MarkoRun.NotHandled;
|
|
3
3
|
export declare const NotMatched: typeof MarkoRun.NotMatched;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function createContext<TRoute extends AnyRoute>(route: TRoute | undefined, request: Request, platform: Platform, url?: URL): [Context<TRoute>, (data?: InputObject) => InputObject];
|
|
4
|
+
export declare function createContext<TRoute extends AnyRoute>(route: TRoute | null, request: Request, platform: Platform, url?: URL): Context<TRoute>;
|
|
6
5
|
export declare function call<TRoute extends AnyRoute>(handler: RouteHandler<TRoute>, next: NextFunction, context: MultiRouteContext<TRoute>): Promise<Response>;
|
|
7
6
|
export declare function compose(handlers: RouteHandler[]): RouteHandler;
|
|
8
7
|
export declare function normalize(obj: RouteHandler | RouteHandler[] | Promise<RouteHandler | RouteHandler[]>): RouteHandler;
|
package/dist/runtime/internal.js
CHANGED
|
@@ -5,6 +5,7 @@ var NotHandled = Symbol(
|
|
|
5
5
|
var NotMatched = Symbol(
|
|
6
6
|
"marko-run not matched"
|
|
7
7
|
);
|
|
8
|
+
var parentContextLookup = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
var serializedGlobals = { params: true, url: true };
|
|
9
10
|
var pageResponseInit = {
|
|
10
11
|
status: 200,
|
|
@@ -44,37 +45,65 @@ var toReadable = (rendered) => {
|
|
|
44
45
|
};
|
|
45
46
|
return toReadable(rendered);
|
|
46
47
|
};
|
|
47
|
-
function pageResponse(template, input, init = pageResponseInit) {
|
|
48
|
-
return new Response(toReadable(template.render(input)), init);
|
|
49
|
-
}
|
|
50
48
|
function createContext(route, request, platform, url = new URL(request.url)) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
meta
|
|
56
|
-
params
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
let meta;
|
|
50
|
+
let params;
|
|
51
|
+
let path;
|
|
52
|
+
if (route) {
|
|
53
|
+
meta = route.meta;
|
|
54
|
+
params = route.params;
|
|
55
|
+
path = route.path;
|
|
56
|
+
} else {
|
|
57
|
+
meta = {};
|
|
58
|
+
params = {};
|
|
59
|
+
path = "";
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
60
62
|
request,
|
|
61
63
|
url,
|
|
62
64
|
platform,
|
|
63
|
-
meta
|
|
64
|
-
params
|
|
65
|
-
route:
|
|
66
|
-
serializedGlobals
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
65
|
+
meta,
|
|
66
|
+
params,
|
|
67
|
+
route: path,
|
|
68
|
+
serializedGlobals,
|
|
69
|
+
parent: parentContextLookup.get(request),
|
|
70
|
+
async fetch(resource, init) {
|
|
71
|
+
let request2;
|
|
72
|
+
let url2;
|
|
73
|
+
if (resource instanceof Request) {
|
|
74
|
+
request2 = new Request(resource, init);
|
|
75
|
+
url2 = new URL(request2.url);
|
|
76
|
+
} else {
|
|
77
|
+
url2 = typeof resource === "string" ? new URL(resource, this.url) : resource;
|
|
78
|
+
request2 = new Request(url2, init);
|
|
79
|
+
}
|
|
80
|
+
parentContextLookup.set(request2, this);
|
|
81
|
+
return await globalThis.__marko_run__.fetch(request2, this.platform) || new Response(null, { status: 404 });
|
|
82
|
+
},
|
|
83
|
+
render(template, input, init = pageResponseInit) {
|
|
84
|
+
return new Response(
|
|
85
|
+
toReadable(
|
|
86
|
+
template.render({
|
|
87
|
+
...input,
|
|
88
|
+
$global: this
|
|
89
|
+
})
|
|
90
|
+
),
|
|
91
|
+
init
|
|
92
|
+
);
|
|
93
|
+
},
|
|
94
|
+
redirect(to, status) {
|
|
95
|
+
return Response.redirect(
|
|
96
|
+
typeof to === "string" ? new URL(to, this.url) : to,
|
|
97
|
+
status
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
back(fallback = "/", status) {
|
|
101
|
+
return this.redirect(
|
|
102
|
+
this.request.headers.get("referer") || fallback,
|
|
103
|
+
status
|
|
104
|
+
);
|
|
76
105
|
}
|
|
77
|
-
|
|
106
|
+
};
|
|
78
107
|
}
|
|
79
108
|
async function call(handler, next, context) {
|
|
80
109
|
let response;
|
|
@@ -180,7 +209,6 @@ export {
|
|
|
180
209
|
normalize,
|
|
181
210
|
notHandled,
|
|
182
211
|
notMatched,
|
|
183
|
-
pageResponse,
|
|
184
212
|
passthrough,
|
|
185
213
|
stripResponseBody,
|
|
186
214
|
stripResponseBodySync
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface Context<TRoute extends Route = AnyRoute> {
|
|
|
21
21
|
readonly meta: TRoute["meta"];
|
|
22
22
|
readonly platform: Platform;
|
|
23
23
|
readonly serializedGlobals: Record<string, boolean>;
|
|
24
|
+
readonly parent: Context | undefined;
|
|
25
|
+
render<T>(template: Marko.Template<T>, input: T, init?: ResponseInit): Response;
|
|
26
|
+
fetch(resource: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
27
|
+
redirect(to: string | URL, status?: number): Response;
|
|
28
|
+
back(fallback?: string | URL, status?: number): Response;
|
|
24
29
|
}
|
|
25
30
|
export type MultiRouteContext<TRoute extends Route, _Preserved extends TRoute = TRoute> = TRoute extends any ? Context<Simplify<SuperSets<TRoute, _Preserved, "params">>> : never;
|
|
26
31
|
export type ParamsObject = Record<string, string>;
|
|
@@ -46,7 +51,7 @@ type DefinePaths<T extends Record<string, {
|
|
|
46
51
|
}>, Verb extends "get" | "post"> = {
|
|
47
52
|
[K in keyof T]: K extends string ? T[K] extends {
|
|
48
53
|
verb: infer V;
|
|
49
|
-
} ? V extends Verb ?
|
|
54
|
+
} ? V extends Verb ? K : never : never : never;
|
|
50
55
|
}[keyof T];
|
|
51
56
|
export type DefineApp<T extends {
|
|
52
57
|
routes: Record<string, {
|
|
@@ -70,7 +75,8 @@ export interface RuntimeModule {
|
|
|
70
75
|
invoke<TPlatform extends Platform = Platform>(...args: Parameters<Invoke<TPlatform>>): ReturnType<Invoke<TPlatform>>;
|
|
71
76
|
}
|
|
72
77
|
type Member<T, U> = T extends T ? (U extends T ? T : never) : never;
|
|
73
|
-
type PathParamKeys<Path extends string> = Path extends `${infer _}
|
|
78
|
+
type PathParamKeys<Path extends string> = Path extends `${infer _}$${infer Param}/${infer Rest}` ? [Unescape<Param>, ...PathParamKeys<Rest>] : Path extends `${infer _}$$${infer Param}` ? [Unescape<Param>] : Path extends `${infer _}$${infer Param}` ? [Unescape<Param>] : [];
|
|
79
|
+
type Unescape<Escaped extends string> = Escaped extends `\`${infer Value}\`` ? Value : Escaped;
|
|
74
80
|
type PathParams<Path extends string, Keys extends string[] = PathParamKeys<Path>> = 0 extends Keys["length"] ? NoParams : {
|
|
75
81
|
[K in Keys[number]]: string;
|
|
76
82
|
};
|
|
@@ -78,7 +84,6 @@ type Segments<T extends string, Acc extends string[] = []> = T extends "" ? Acc
|
|
|
78
84
|
type GTE<A extends any[], B extends any[]> = A["length"] extends B["length"] ? 1 : A extends [infer _Ha, ...infer Ta] ? B extends [infer _Hb, ...infer Tb] ? GTE<Ta, Tb> : 1 : 0;
|
|
79
85
|
type MatchSegments<A extends string, B extends string> = A extends `${infer P}/${string}*` ? 1 extends GTE<Segments<B>, Segments<P>> ? `${P}/${string}` : never : Segments<B>["length"] extends Segments<A>["length"] ? A : never;
|
|
80
86
|
type PathPattern<T extends string> = T extends `${infer Left}/\${${string}}/${infer Rest}` ? PathPattern<`${Left}/${string}/${Rest}`> : T extends `${infer Left}/\${...${string}}` ? PathPattern<`${Left}/${string}*`> : T extends `${infer Left}/\${${string}}` ? PathPattern<`${Left}/${string}`> : T;
|
|
81
|
-
export type ConvertPath<Path extends string> = Path extends `${infer Left}/:${infer Param}/${infer Rest}` ? ConvertPath<`${Left}/\${${Param}}/${Rest}`> : Path extends `${infer Left}/:${infer Param}*` ? `${Left}/\${${Param}...}` : Path extends `${infer Left}/:${infer Param}` ? `${Left}/\${${Param}}` : Path;
|
|
82
87
|
type ValidatePath<Paths extends string, Path extends string> = Paths | (Path extends `/${string}` ? MatchSegments<Member<PathPattern<Paths>, Path>, Path> : Path);
|
|
83
88
|
type ValidateHref<Paths extends string, Href extends string> = Href extends `${infer P}#${infer H}?${infer Q}` ? `${ValidatePath<Paths, P>}#${H}?${Q}` : Href extends `${infer P}?${infer Q}` ? `${ValidatePath<Paths, P>}?${Q}` : Href extends `${infer P}#${infer H}` ? `${ValidatePath<Paths, P>}#${H}` : ValidatePath<Paths, Href>;
|
|
84
89
|
export interface AppData {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Adapter, BuiltRoutes, RoutableFile, Route, RouterOptions } from "../types";
|
|
2
|
-
export declare function renderRouteTemplate(route: Route,
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function renderRouteTypeInfo(routes: BuiltRoutes, pathPrefix?: string, adapter?: Adapter | null): Promise<string>;
|
|
2
|
+
export declare function renderRouteTemplate(route: Route, rootDir: string): string;
|
|
3
|
+
export declare function renderRouteEntry(route: Route, rootDir: string): string;
|
|
4
|
+
export declare function renderRouter(routes: BuiltRoutes, rootDir: string, options?: RouterOptions): string;
|
|
5
|
+
export declare function renderMiddleware(middleware: RoutableFile[], rootDir: string): string;
|
|
6
|
+
export declare function renderRouteTypeInfo(routes: BuiltRoutes, outDir: string, adapter?: Adapter | null): Promise<string>;
|