@marko/run 0.0.1-beta6 → 0.0.1-beta8
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 +227 -72
- package/dist/adapter/default-entry.mjs +8 -5
- package/dist/adapter/index.cjs +50 -46
- package/dist/adapter/index.js +50 -46
- package/dist/adapter/middleware.cjs +34 -40
- package/dist/adapter/middleware.d.ts +4 -2
- package/dist/adapter/middleware.js +33 -40
- package/dist/cli/index.mjs +2 -2
- package/dist/runtime/index.d.ts +7 -3
- package/dist/runtime/internal.cjs +16 -13
- package/dist/runtime/internal.d.ts +2 -2
- package/dist/runtime/internal.js +14 -11
- package/dist/runtime/router.cjs +9 -9
- package/dist/runtime/router.d.ts +3 -4
- package/dist/runtime/router.js +6 -6
- package/dist/runtime/types.d.ts +11 -9
- package/dist/vite/codegen/index.d.ts +1 -1
- package/dist/vite/index.cjs +83 -58
- package/dist/vite/index.js +83 -58
- package/package.json +3 -2
package/dist/adapter/index.js
CHANGED
|
@@ -62,8 +62,8 @@ function getOrigin(req, protocol, host, trustProxy) {
|
|
|
62
62
|
}
|
|
63
63
|
return `${protocol}://${host}`;
|
|
64
64
|
}
|
|
65
|
-
function createMiddleware(
|
|
66
|
-
const { trustProxy = process.env.TRUST_PROXY === "1" } = options;
|
|
65
|
+
function createMiddleware(fetch2, options = {}) {
|
|
66
|
+
const { trustProxy = process.env.TRUST_PROXY === "1", devServer } = options;
|
|
67
67
|
let { origin = process.env.ORIGIN } = options;
|
|
68
68
|
let protocol;
|
|
69
69
|
let host;
|
|
@@ -75,45 +75,28 @@ function createMiddleware(router, options = {}) {
|
|
|
75
75
|
origin ?? (origin = getOrigin(req, protocol, host, trustProxy));
|
|
76
76
|
const url = new URL(req.url, origin);
|
|
77
77
|
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
78
|
-
const
|
|
78
|
+
const headers = req.headers;
|
|
79
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
80
|
+
start(controller) {
|
|
81
|
+
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
82
|
+
req.on("end", () => controller.close());
|
|
83
|
+
req.on("error", (err) => controller.error(err));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const request = new Request(url, {
|
|
79
87
|
method: req.method,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
headers,
|
|
89
|
+
body,
|
|
90
|
+
duplex: "half"
|
|
91
|
+
});
|
|
92
|
+
const response = await fetch2(request, {
|
|
93
|
+
ip,
|
|
94
|
+
request: req,
|
|
95
|
+
response: res,
|
|
96
|
+
setCookie(cookie) {
|
|
97
|
+
res.appendHeader("set-cookie", cookie);
|
|
88
98
|
}
|
|
89
|
-
};
|
|
90
|
-
Object.defineProperty(requestContext, "request", {
|
|
91
|
-
get() {
|
|
92
|
-
const headers = req.headers;
|
|
93
|
-
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
94
|
-
start(controller) {
|
|
95
|
-
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
96
|
-
req.on("end", () => controller.close());
|
|
97
|
-
req.on("error", (err) => controller.error(err));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
const request = new Request(url, {
|
|
101
|
-
method: req.method,
|
|
102
|
-
headers,
|
|
103
|
-
body,
|
|
104
|
-
duplex: "half"
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "request", {
|
|
107
|
-
value: request,
|
|
108
|
-
enumerable: true,
|
|
109
|
-
configurable: true
|
|
110
|
-
});
|
|
111
|
-
return request;
|
|
112
|
-
},
|
|
113
|
-
enumerable: true,
|
|
114
|
-
configurable: true
|
|
115
99
|
});
|
|
116
|
-
const response = await router(requestContext);
|
|
117
100
|
if (!response) {
|
|
118
101
|
if (next) {
|
|
119
102
|
next();
|
|
@@ -164,7 +147,17 @@ function createMiddleware(router, options = {}) {
|
|
|
164
147
|
res.off("error", cancel);
|
|
165
148
|
reader.cancel(error).catch(() => {
|
|
166
149
|
});
|
|
167
|
-
|
|
150
|
+
if (error) {
|
|
151
|
+
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
152
|
+
res.end();
|
|
153
|
+
devServer.ws.send({
|
|
154
|
+
type: "error",
|
|
155
|
+
err: { message: error.message, stack: error.stack || "" }
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
res.destroy(error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
168
161
|
}
|
|
169
162
|
async function write() {
|
|
170
163
|
try {
|
|
@@ -191,6 +184,7 @@ function createMiddleware(router, options = {}) {
|
|
|
191
184
|
}
|
|
192
185
|
|
|
193
186
|
// src/adapter/dev-server.ts
|
|
187
|
+
var fixedErrors = /* @__PURE__ */ new WeakSet();
|
|
194
188
|
function createViteDevMiddleware(devServer, load, factory) {
|
|
195
189
|
let value;
|
|
196
190
|
let middleware;
|
|
@@ -203,10 +197,16 @@ function createViteDevMiddleware(devServer, load, factory) {
|
|
|
203
197
|
}
|
|
204
198
|
await middleware(req, res, next);
|
|
205
199
|
} catch (err) {
|
|
200
|
+
res.statusCode = 500;
|
|
206
201
|
if (err instanceof Error) {
|
|
207
|
-
|
|
202
|
+
if (!fixedErrors.has(err)) {
|
|
203
|
+
fixedErrors.add(err);
|
|
204
|
+
devServer.ssrFixStacktrace(err);
|
|
205
|
+
}
|
|
206
|
+
res.end(err.stack);
|
|
207
|
+
} else {
|
|
208
|
+
res.end();
|
|
208
209
|
}
|
|
209
|
-
return next == null ? void 0 : next();
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
212
|
}
|
|
@@ -214,12 +214,16 @@ async function createDevServer(configFile) {
|
|
|
214
214
|
const devServer = await createServer({
|
|
215
215
|
configFile,
|
|
216
216
|
appType: "custom",
|
|
217
|
-
server: { middlewareMode: true }
|
|
217
|
+
server: { middlewareMode: true },
|
|
218
|
+
resolve: {
|
|
219
|
+
dedupe: ["marko"],
|
|
220
|
+
conditions: ["worker"]
|
|
221
|
+
}
|
|
218
222
|
});
|
|
219
223
|
const middleware = createViteDevMiddleware(
|
|
220
224
|
devServer,
|
|
221
|
-
async () =>
|
|
222
|
-
createMiddleware
|
|
225
|
+
async () => await devServer.ssrLoadModule("@marko/run/router"),
|
|
226
|
+
(module) => createMiddleware(module.fetch, { devServer })
|
|
223
227
|
);
|
|
224
228
|
return devServer.middlewares.use(middleware);
|
|
225
229
|
}
|
|
@@ -314,8 +318,8 @@ function adapter() {
|
|
|
314
318
|
});
|
|
315
319
|
});
|
|
316
320
|
},
|
|
317
|
-
async startPreview(
|
|
318
|
-
const server = await spawnServer(`node ${entry}`, port, envFile
|
|
321
|
+
async startPreview(_dir, entry, port, envFile) {
|
|
322
|
+
const server = await spawnServer(`node ${entry}`, port, envFile);
|
|
319
323
|
console.log(`Preview server started: http://localhost:${server.port}`);
|
|
320
324
|
}
|
|
321
325
|
};
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/adapter/middleware.ts
|
|
21
21
|
var middleware_exports = {};
|
|
22
22
|
__export(middleware_exports, {
|
|
23
|
-
|
|
23
|
+
createMiddleware: () => createMiddleware,
|
|
24
24
|
getOrigin: () => getOrigin
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(middleware_exports);
|
|
@@ -82,8 +82,8 @@ function getOrigin(req, protocol, host, trustProxy) {
|
|
|
82
82
|
}
|
|
83
83
|
return `${protocol}://${host}`;
|
|
84
84
|
}
|
|
85
|
-
function createMiddleware(
|
|
86
|
-
const { trustProxy = process.env.TRUST_PROXY === "1" } = options;
|
|
85
|
+
function createMiddleware(fetch2, options = {}) {
|
|
86
|
+
const { trustProxy = process.env.TRUST_PROXY === "1", devServer } = options;
|
|
87
87
|
let { origin = process.env.ORIGIN } = options;
|
|
88
88
|
let protocol;
|
|
89
89
|
let host;
|
|
@@ -95,45 +95,28 @@ function createMiddleware(router, options = {}) {
|
|
|
95
95
|
origin ?? (origin = getOrigin(req, protocol, host, trustProxy));
|
|
96
96
|
const url = new URL(req.url, origin);
|
|
97
97
|
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
98
|
-
const
|
|
98
|
+
const headers = req.headers;
|
|
99
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
100
|
+
start(controller) {
|
|
101
|
+
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
102
|
+
req.on("end", () => controller.close());
|
|
103
|
+
req.on("error", (err) => controller.error(err));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const request = new Request(url, {
|
|
99
107
|
method: req.method,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
headers,
|
|
109
|
+
body,
|
|
110
|
+
duplex: "half"
|
|
111
|
+
});
|
|
112
|
+
const response = await fetch2(request, {
|
|
113
|
+
ip,
|
|
114
|
+
request: req,
|
|
115
|
+
response: res,
|
|
116
|
+
setCookie(cookie) {
|
|
117
|
+
res.appendHeader("set-cookie", cookie);
|
|
108
118
|
}
|
|
109
|
-
};
|
|
110
|
-
Object.defineProperty(requestContext, "request", {
|
|
111
|
-
get() {
|
|
112
|
-
const headers = req.headers;
|
|
113
|
-
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
114
|
-
start(controller) {
|
|
115
|
-
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
116
|
-
req.on("end", () => controller.close());
|
|
117
|
-
req.on("error", (err) => controller.error(err));
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
const request = new Request(url, {
|
|
121
|
-
method: req.method,
|
|
122
|
-
headers,
|
|
123
|
-
body,
|
|
124
|
-
duplex: "half"
|
|
125
|
-
});
|
|
126
|
-
Object.defineProperty(this, "request", {
|
|
127
|
-
value: request,
|
|
128
|
-
enumerable: true,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
return request;
|
|
132
|
-
},
|
|
133
|
-
enumerable: true,
|
|
134
|
-
configurable: true
|
|
135
119
|
});
|
|
136
|
-
const response = await router(requestContext);
|
|
137
120
|
if (!response) {
|
|
138
121
|
if (next) {
|
|
139
122
|
next();
|
|
@@ -184,7 +167,17 @@ function createMiddleware(router, options = {}) {
|
|
|
184
167
|
res.off("error", cancel);
|
|
185
168
|
reader.cancel(error).catch(() => {
|
|
186
169
|
});
|
|
187
|
-
|
|
170
|
+
if (error) {
|
|
171
|
+
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
172
|
+
res.end();
|
|
173
|
+
devServer.ws.send({
|
|
174
|
+
type: "error",
|
|
175
|
+
err: { message: error.message, stack: error.stack || "" }
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
res.destroy(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
188
181
|
}
|
|
189
182
|
async function write() {
|
|
190
183
|
try {
|
|
@@ -211,5 +204,6 @@ function createMiddleware(router, options = {}) {
|
|
|
211
204
|
}
|
|
212
205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
213
206
|
0 && (module.exports = {
|
|
207
|
+
createMiddleware,
|
|
214
208
|
getOrigin
|
|
215
209
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Fetch } from "../runtime";
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from "http";
|
|
3
|
+
import type { ViteDevServer } from "vite";
|
|
3
4
|
declare module "net" {
|
|
4
5
|
interface Socket {
|
|
5
6
|
encrypted?: boolean;
|
|
@@ -46,10 +47,11 @@ export interface NodeAdapterOptions {
|
|
|
46
47
|
* is set to `1`, otherwise false.
|
|
47
48
|
*/
|
|
48
49
|
trustProxy?: boolean;
|
|
50
|
+
devServer?: ViteDevServer;
|
|
49
51
|
}
|
|
50
52
|
export declare function getOrigin(req: IncomingMessage, protocol?: string, host?: string, trustProxy?: boolean): string;
|
|
51
53
|
/**
|
|
52
54
|
* Creates a request handler to be passed to http.createServer() or used as a
|
|
53
55
|
* middleware in Connect-style frameworks like Express.
|
|
54
56
|
*/
|
|
55
|
-
export
|
|
57
|
+
export declare function createMiddleware(fetch: Fetch<NodePlatformInfo>, options?: NodeAdapterOptions): NodeMiddleware;
|
|
@@ -55,8 +55,8 @@ function getOrigin(req, protocol, host, trustProxy) {
|
|
|
55
55
|
}
|
|
56
56
|
return `${protocol}://${host}`;
|
|
57
57
|
}
|
|
58
|
-
function createMiddleware(
|
|
59
|
-
const { trustProxy = process.env.TRUST_PROXY === "1" } = options;
|
|
58
|
+
function createMiddleware(fetch2, options = {}) {
|
|
59
|
+
const { trustProxy = process.env.TRUST_PROXY === "1", devServer } = options;
|
|
60
60
|
let { origin = process.env.ORIGIN } = options;
|
|
61
61
|
let protocol;
|
|
62
62
|
let host;
|
|
@@ -68,45 +68,28 @@ function createMiddleware(router, options = {}) {
|
|
|
68
68
|
origin ?? (origin = getOrigin(req, protocol, host, trustProxy));
|
|
69
69
|
const url = new URL(req.url, origin);
|
|
70
70
|
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
71
|
-
const
|
|
71
|
+
const headers = req.headers;
|
|
72
|
+
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
73
|
+
start(controller) {
|
|
74
|
+
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
75
|
+
req.on("end", () => controller.close());
|
|
76
|
+
req.on("error", (err) => controller.error(err));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const request = new Request(url, {
|
|
72
80
|
method: req.method,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
headers,
|
|
82
|
+
body,
|
|
83
|
+
duplex: "half"
|
|
84
|
+
});
|
|
85
|
+
const response = await fetch2(request, {
|
|
86
|
+
ip,
|
|
87
|
+
request: req,
|
|
88
|
+
response: res,
|
|
89
|
+
setCookie(cookie) {
|
|
90
|
+
res.appendHeader("set-cookie", cookie);
|
|
81
91
|
}
|
|
82
|
-
};
|
|
83
|
-
Object.defineProperty(requestContext, "request", {
|
|
84
|
-
get() {
|
|
85
|
-
const headers = req.headers;
|
|
86
|
-
const body = req.method === "GET" || req.method === "HEAD" ? void 0 : req.socket ? req : new ReadableStream({
|
|
87
|
-
start(controller) {
|
|
88
|
-
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
89
|
-
req.on("end", () => controller.close());
|
|
90
|
-
req.on("error", (err) => controller.error(err));
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
const request = new Request(url, {
|
|
94
|
-
method: req.method,
|
|
95
|
-
headers,
|
|
96
|
-
body,
|
|
97
|
-
duplex: "half"
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, "request", {
|
|
100
|
-
value: request,
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true
|
|
103
|
-
});
|
|
104
|
-
return request;
|
|
105
|
-
},
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true
|
|
108
92
|
});
|
|
109
|
-
const response = await router(requestContext);
|
|
110
93
|
if (!response) {
|
|
111
94
|
if (next) {
|
|
112
95
|
next();
|
|
@@ -157,7 +140,17 @@ function createMiddleware(router, options = {}) {
|
|
|
157
140
|
res.off("error", cancel);
|
|
158
141
|
reader.cancel(error).catch(() => {
|
|
159
142
|
});
|
|
160
|
-
|
|
143
|
+
if (error) {
|
|
144
|
+
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
145
|
+
res.end();
|
|
146
|
+
devServer.ws.send({
|
|
147
|
+
type: "error",
|
|
148
|
+
err: { message: error.message, stack: error.stack || "" }
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
res.destroy(error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
161
154
|
}
|
|
162
155
|
async function write() {
|
|
163
156
|
try {
|
|
@@ -183,6 +176,6 @@ function createMiddleware(router, options = {}) {
|
|
|
183
176
|
};
|
|
184
177
|
}
|
|
185
178
|
export {
|
|
186
|
-
createMiddleware
|
|
179
|
+
createMiddleware,
|
|
187
180
|
getOrigin
|
|
188
181
|
};
|
package/dist/cli/index.mjs
CHANGED
|
@@ -98,12 +98,12 @@ var defaultPort = +process.env.PORT || 3e3;
|
|
|
98
98
|
var defaultConfigFileBases = ["serve.config", "vite.config"];
|
|
99
99
|
var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
|
|
100
100
|
var prog = sade("marko-run").version("0.0.1").option("-c, --config", `Provide path to a Vite config file (by default looks for a file starting with ${defaultConfigFileBases.join(" or ")} with one of these extensions: ${defaultConfigFileExts.join(", ")})`).option("-e, --env", "Provide path to a dotenv file");
|
|
101
|
-
prog.command("serve [entry]"
|
|
101
|
+
prog.command("serve [entry]").describe("Start a production-like server for already-built app files").option("-o, --output", "Directory to serve files from, and write asset files to if `--build` (default: )").option("-p, --port", "Port the server should listen on (defaults: `$PORT` env variable or 3000)").option("-f, --file", "Output file to start").action(async (entry, opts) => {
|
|
102
102
|
const config2 = await getViteConfig(cwd, opts.config);
|
|
103
103
|
await build(entry, config2, opts.output, false, opts.env);
|
|
104
104
|
await preview(opts.entry, config2, opts.port, opts.output, opts.env);
|
|
105
105
|
});
|
|
106
|
-
prog.command("dev [entry]").describe("Start development server in watch mode").option("-p, --port", "Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)").example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
106
|
+
prog.command("dev [entry]", "", { default: true }).describe("Start development server in watch mode").option("-p, --port", "Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)").example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
107
107
|
const cmd = opts._.length ? `${entry} ${opts._.join(" ")}` : entry ? `node ${entry}` : void 0;
|
|
108
108
|
const config2 = await getViteConfig(cwd, opts.config);
|
|
109
109
|
await dev(cmd, config2, opts.port, opts.env);
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { HandlerLike, ParamsObject, Route, RouteContext } from "./types";
|
|
2
2
|
declare global {
|
|
3
3
|
namespace Marko {
|
|
4
|
-
interface Global {
|
|
5
|
-
|
|
4
|
+
interface Global extends MarkoRun.CurrentContext {
|
|
5
|
+
}
|
|
6
|
+
interface Out {
|
|
7
|
+
global: Global;
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
10
|
namespace MarkoRun {
|
|
11
|
+
const NotHandled: symbol;
|
|
12
|
+
const NotMatched: symbol;
|
|
9
13
|
interface CurrentRoute extends Route {
|
|
10
14
|
}
|
|
11
15
|
interface CurrentContext extends RouteContext<CurrentRoute> {
|
|
@@ -14,4 +18,4 @@ declare global {
|
|
|
14
18
|
function route<Params extends ParamsObject = {}, Meta = unknown>(handler: Handler<Params, Meta>): typeof handler;
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
|
-
export type { HandlerLike, InputObject,
|
|
21
|
+
export type { Fetch, HandlerLike, InputObject, Invoke, Match, NextFunction, PathTemplate, Route, RouteContext, RouteContextExtensions, RouteHandler, RouteWithHandler, RuntimeModule, ValidateHref, ValidatePath, } from "./types";
|
|
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/runtime/internal.ts
|
|
21
21
|
var internal_exports = {};
|
|
22
22
|
__export(internal_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
NotHandled: () => NotHandled,
|
|
24
|
+
NotMatched: () => NotMatched,
|
|
25
25
|
call: () => call,
|
|
26
26
|
compose: () => compose,
|
|
27
27
|
createInput: () => createInput,
|
|
@@ -31,17 +31,20 @@ __export(internal_exports, {
|
|
|
31
31
|
notMatched: () => notMatched
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(internal_exports);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
var NotHandled = Symbol();
|
|
35
|
+
var NotMatched = Symbol();
|
|
36
|
+
globalThis.MarkoRun ?? (globalThis.MarkoRun = {
|
|
37
|
+
NotHandled,
|
|
38
|
+
NotMatched,
|
|
39
|
+
route(handler) {
|
|
40
|
+
return handler;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
38
43
|
function createInput(context) {
|
|
39
44
|
let existing;
|
|
40
45
|
return (data) => {
|
|
41
46
|
existing ?? (existing = {
|
|
42
|
-
$global:
|
|
43
|
-
context
|
|
44
|
-
}
|
|
47
|
+
$global: context
|
|
45
48
|
});
|
|
46
49
|
return data ? Object.assign(existing, data) : existing;
|
|
47
50
|
};
|
|
@@ -78,7 +81,7 @@ async function call(handler, next, context) {
|
|
|
78
81
|
response = await handler(context, next);
|
|
79
82
|
} catch (error) {
|
|
80
83
|
if (error == null) {
|
|
81
|
-
throw
|
|
84
|
+
throw NotHandled;
|
|
82
85
|
} else if (error instanceof Response) {
|
|
83
86
|
return error;
|
|
84
87
|
}
|
|
@@ -86,7 +89,7 @@ async function call(handler, next, context) {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
if (response === null) {
|
|
89
|
-
throw
|
|
92
|
+
throw NotMatched;
|
|
90
93
|
}
|
|
91
94
|
return response || next();
|
|
92
95
|
}
|
|
@@ -136,8 +139,8 @@ function notMatched() {
|
|
|
136
139
|
}
|
|
137
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
138
141
|
0 && (module.exports = {
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
NotHandled,
|
|
143
|
+
NotMatched,
|
|
141
144
|
call,
|
|
142
145
|
compose,
|
|
143
146
|
createInput,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InputObject, NextFunction, Route, RouteContext, RouteHandler } from "./types";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const NotHandled: unique symbol;
|
|
3
|
+
export declare const NotMatched: unique symbol;
|
|
4
4
|
export declare function createInput(context: RouteContext): (data: InputObject) => InputObject;
|
|
5
5
|
export declare function call(handler: RouteHandler<Route>, next: NextFunction, context: RouteContext): Promise<Response>;
|
|
6
6
|
export declare function compose(handlers: RouteHandler[]): RouteHandler;
|
package/dist/runtime/internal.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// src/runtime/internal.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var NotHandled = Symbol();
|
|
3
|
+
var NotMatched = Symbol();
|
|
4
|
+
globalThis.MarkoRun ?? (globalThis.MarkoRun = {
|
|
5
|
+
NotHandled,
|
|
6
|
+
NotMatched,
|
|
7
|
+
route(handler) {
|
|
8
|
+
return handler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
6
11
|
function createInput(context) {
|
|
7
12
|
let existing;
|
|
8
13
|
return (data) => {
|
|
9
14
|
existing ?? (existing = {
|
|
10
|
-
$global:
|
|
11
|
-
context
|
|
12
|
-
}
|
|
15
|
+
$global: context
|
|
13
16
|
});
|
|
14
17
|
return data ? Object.assign(existing, data) : existing;
|
|
15
18
|
};
|
|
@@ -46,7 +49,7 @@ async function call(handler, next, context) {
|
|
|
46
49
|
response = await handler(context, next);
|
|
47
50
|
} catch (error) {
|
|
48
51
|
if (error == null) {
|
|
49
|
-
throw
|
|
52
|
+
throw NotHandled;
|
|
50
53
|
} else if (error instanceof Response) {
|
|
51
54
|
return error;
|
|
52
55
|
}
|
|
@@ -54,7 +57,7 @@ async function call(handler, next, context) {
|
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
if (response === null) {
|
|
57
|
-
throw
|
|
60
|
+
throw NotMatched;
|
|
58
61
|
}
|
|
59
62
|
return response || next();
|
|
60
63
|
}
|
|
@@ -103,8 +106,8 @@ function notMatched() {
|
|
|
103
106
|
return null;
|
|
104
107
|
}
|
|
105
108
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
NotHandled,
|
|
110
|
+
NotMatched,
|
|
108
111
|
call,
|
|
109
112
|
compose,
|
|
110
113
|
createInput,
|
package/dist/runtime/router.cjs
CHANGED
|
@@ -20,9 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/runtime/router.ts
|
|
21
21
|
var router_exports = {};
|
|
22
22
|
__export(router_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
fetch: () => fetch,
|
|
24
|
+
invoke: () => invoke,
|
|
25
|
+
match: () => match
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(router_exports);
|
|
28
28
|
function notImplemented() {
|
|
@@ -30,12 +30,12 @@ function notImplemented() {
|
|
|
30
30
|
"This should have been replaced by the @marko/run plugin at build/dev time"
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
33
|
+
var fetch = notImplemented;
|
|
34
|
+
var match = notImplemented;
|
|
35
|
+
var invoke = notImplemented;
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
fetch,
|
|
39
|
+
invoke,
|
|
40
|
+
match
|
|
41
41
|
});
|
package/dist/runtime/router.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const invokeRoute: <T>(route: Route | null, context: RequestContext<T>) => Promise<Response | void>;
|
|
1
|
+
export declare const fetch: <Platform = unknown>(request: Request, platform: Platform) => Promise<void | Response>;
|
|
2
|
+
export declare const match: (method: string, pathname: string) => import("./types").RouteWithHandler<{}, unknown, string> | null;
|
|
3
|
+
export declare const invoke: <Platform = unknown>(route: import("./types").RouteWithHandler<{}, unknown, string> | null, request: Request, platform: Platform) => Promise<void | Response>;
|
package/dist/runtime/router.js
CHANGED
|
@@ -4,11 +4,11 @@ function notImplemented() {
|
|
|
4
4
|
"This should have been replaced by the @marko/run plugin at build/dev time"
|
|
5
5
|
);
|
|
6
6
|
}
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
7
|
+
var fetch = notImplemented;
|
|
8
|
+
var match = notImplemented;
|
|
9
|
+
var invoke = notImplemented;
|
|
10
10
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
fetch,
|
|
12
|
+
invoke,
|
|
13
|
+
match
|
|
14
14
|
};
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -7,20 +7,17 @@ export interface RouteContextExtensions {
|
|
|
7
7
|
}
|
|
8
8
|
export declare type ParamsObject = Record<string, string>;
|
|
9
9
|
export declare type InputObject = Record<PropertyKey, any>;
|
|
10
|
-
export
|
|
10
|
+
export declare type RouteContext<Platform = unknown, TRoute extends Route = Route> = TRoute extends any ? Combine<RouteContextExtensions & Readonly<{
|
|
11
11
|
url: URL;
|
|
12
|
-
method: string;
|
|
13
12
|
request: Request;
|
|
14
|
-
platform: T;
|
|
15
|
-
}
|
|
16
|
-
export declare type RouteContext<TRoute extends Route = Route> = TRoute extends any ? Combine<RouteContextExtensions & Readonly<RequestContext & {
|
|
17
13
|
route: TRoute["path"];
|
|
18
14
|
params: TRoute["params"];
|
|
19
15
|
meta: TRoute["meta"];
|
|
16
|
+
platform: Platform;
|
|
20
17
|
}>> : never;
|
|
21
18
|
export declare type NextFunction = () => Awaitable<Response>;
|
|
22
19
|
export declare type HandlerLike<TRoute extends Route = Route> = Awaitable<OneOrMany<RouteHandler<TRoute>>>;
|
|
23
|
-
export declare type RouteHandler<TRoute extends Route = Route> = (context: RouteContext<TRoute>, next: NextFunction) => Awaitable<Response | null | void>;
|
|
20
|
+
export declare type RouteHandler<TRoute extends Route = Route> = (context: RouteContext<unknown, TRoute>, next: NextFunction) => Awaitable<Response | null | void>;
|
|
24
21
|
export interface Route<Params extends ParamsObject = {}, Meta = unknown, Path extends string = string> {
|
|
25
22
|
path: Path;
|
|
26
23
|
params: Params;
|
|
@@ -29,9 +26,14 @@ export interface Route<Params extends ParamsObject = {}, Meta = unknown, Path ex
|
|
|
29
26
|
export interface RouteWithHandler<Params extends ParamsObject = {}, Meta = unknown, Path extends string = string> extends Route<Params, Meta, Path> {
|
|
30
27
|
handler: RouteHandler<this>;
|
|
31
28
|
}
|
|
32
|
-
export declare type
|
|
33
|
-
export declare type
|
|
34
|
-
export declare type
|
|
29
|
+
export declare type Fetch<Platform = unknown> = (request: Request, platform: Platform) => Promise<Response | void>;
|
|
30
|
+
export declare type Match = (method: string, pathname: string) => RouteWithHandler | null;
|
|
31
|
+
export declare type Invoke = <Platform = unknown>(route: RouteWithHandler | null, request: Request, platform: Platform) => Promise<Response | void>;
|
|
32
|
+
export interface RuntimeModule {
|
|
33
|
+
fetch: <Platform = unknown>(request: Request, platform: Platform) => Promise<Response | void>;
|
|
34
|
+
match: (method: string, pathname: string) => RouteWithHandler | null;
|
|
35
|
+
invoke: <Platform = unknown>(route: RouteWithHandler | null, request: Request, platform: Platform) => Promise<Response | void>;
|
|
36
|
+
}
|
|
35
37
|
declare type Member<T, U> = T extends T ? (U extends T ? T : never) : never;
|
|
36
38
|
declare type Segments<T extends string, Acc extends string[] = []> = T extends "" ? Acc : T extends `${infer Left}/${infer Rest}` ? Segments<Rest, [...Acc, Left]> : [...Acc, T];
|
|
37
39
|
declare 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;
|
|
@@ -3,4 +3,4 @@ export declare function renderRouteTemplate(route: Route): string;
|
|
|
3
3
|
export declare function renderRouteEntry(route: Route): string;
|
|
4
4
|
export declare function renderRouter(routes: BuiltRoutes, options?: RouterOptions): string;
|
|
5
5
|
export declare function renderMiddleware(middleware: RoutableFile[]): string;
|
|
6
|
-
export declare function renderRouteTypeInfo(routes: BuiltRoutes, pathPrefix?: string): string;
|
|
6
|
+
export declare function renderRouteTypeInfo(routes: BuiltRoutes, pathPrefix?: string, adapterTypes?: string): string;
|