From 22d2293834071b3512b973b9ad689cbdd3166ab2 Mon Sep 17 00:00:00 2001 From: Ryan Turnquist Date: Tue, 10 Feb 2026 12:02:36 -0800 Subject: [PATCH] feat: support verb overrides for json and object meta data --- .changeset/wide-moose-sit.md | 5 + packages/run/README.md | 59 +++++++- .../all-http-verbs/.marko-run/routes.d.ts | 14 ++ .../fixtures/basic-404/.marko-run/routes.d.ts | 14 ++ .../fixtures/basic-500/.marko-run/routes.d.ts | 28 ++++ .../basic-assets/.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 21 +++ .../basic-cookies/.marko-run/routes.d.ts | 14 ++ .../basic-handler/.marko-run/routes.d.ts | 14 ++ .../basic-layout/.marko-run/routes.d.ts | 14 ++ .../basic-middleware/.marko-run/routes.d.ts | 14 ++ .../basic-nested-page/.marko-run/routes.d.ts | 21 +++ .../basic-page/.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 14 ++ .../basic-redirect/.marko-run/routes.d.ts | 14 ++ .../config-override/.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../dynamic-nested/.marko-run/routes.d.ts | 7 + .../dynamic-rest/.marko-run/routes.d.ts | 7 + .../fixtures/dynamic/.marko-run/routes.d.ts | 7 + .../force-class-api/.marko-run/routes.d.ts | 14 ++ .../force-tags-api/.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 42 ++++++ .../.marko-run/routes.d.ts | 7 + .../inject-plugin/.marko-run/routes.d.ts | 7 + .../layout-404/.marko-run/routes.d.ts | 21 +++ .../micro-frame-fetch/.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../node-adapter-page/.marko-run/routes.d.ts | 7 + .../not-handled/.marko-run/routes.d.ts | 14 ++ .../not-matched/.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 14 ++ .../render-custom-page/.marko-run/routes.d.ts | 7 + .../runtime-include/.marko-run/routes.d.ts | 7 + .../ssr-emit-assets/.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 14 ++ .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 21 +++ .../.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 14 ++ .../uri-encoded/.marko-run/routes.d.ts | 7 + .../.marko-run/routes.d.ts | 34 +++++ .../__snapshots__/dev.expected.md | 20 +++ .../__snapshots__/preview.expected.md | 20 +++ .../src/routes/+meta.js | 15 ++ .../src/routes/+page.marko | 12 ++ .../test.config.ts | 1 + .../tsconfig.json | 4 + .../.marko-run/routes.d.ts | 34 +++++ .../__snapshots__/dev.expected.md | 12 ++ .../__snapshots__/preview.expected.md | 12 ++ .../src/routes/+meta.js | 11 ++ .../src/routes/+page.marko | 12 ++ .../test.config.ts | 1 + .../tsconfig.json | 4 + .../.marko-run/routes.d.ts | 34 +++++ .../__snapshots__/dev.expected.md | 12 ++ .../__snapshots__/preview.expected.md | 12 ++ .../src/routes/+meta.js | 15 ++ .../src/routes/+page.marko | 12 ++ .../test.config.ts | 1 + .../tsconfig.json | 4 + .../.marko-run/routes.d.ts | 34 +++++ .../__snapshots__/dev.expected.md | 12 ++ .../__snapshots__/preview.expected.md | 12 ++ .../src/routes/+meta.json | 10 ++ .../src/routes/+page.marko | 12 ++ .../test.config.ts | 1 + .../tsconfig.json | 4 + .../.marko-run/routes.d.ts | 52 +++++++ .../__snapshots__/dev.expected.md | 13 ++ .../__snapshots__/preview.expected.md | 13 ++ .../src/routes/+handler.ts | 9 ++ .../src/routes/+meta.json | 15 ++ .../src/routes/+page.marko | 12 ++ .../verb-specific-json-meta/test.config.ts | 1 + .../verb-specific-json-meta/tsconfig.json | 4 + packages/run/src/runtime/index.ts | 23 ++- packages/run/src/runtime/internal.ts | 7 +- packages/run/src/runtime/namespace.ts | 1 + packages/run/src/runtime/types.ts | 103 ++++++++----- .../basic-500.expected.routetypes.d.ts | 21 +++ .../basic.expected.routetypes.d.ts | 14 ++ .../build-routes.expected.router.js | 16 +- .../build-routes.expected.routes.md | 52 ++++--- .../build-routes.expected.routetypes.d.ts | 126 ++++++++++++++++ .../escape-path.expected.routetypes.d.ts | 14 ++ .../flat-routes.expected.routes.md | 34 ++--- .../flat-routes.expected.routetypes.d.ts | 21 +++ .../force-class-api.expected.routetypes.d.ts | 14 ++ .../force-tags-api.expected.routetypes.d.ts | 14 ++ .../meta-files-with-verbs.expected.router.js | 141 ++++++++++++++++++ .../meta-files-with-verbs.expected.routes.md | 64 ++++++++ ...-files-with-verbs.expected.routetypes.d.ts | 71 +++++++++ .../fixtures/meta-files-with-verbs/routes.txt | 8 + .../multiple-sources.expected.routetypes.d.ts | 14 ++ .../nested-dynamic.expected.routetypes.d.ts | 7 + .../optional-dynamic.expected.routetypes.d.ts | 7 + .../optional-static.expected.routetypes.d.ts | 7 + .../optional-types.expected.routes.md | 20 +-- .../optional-types.expected.routetypes.d.ts | 28 ++++ ...ram-optional-rest.expected.routetypes.d.ts | 7 + .../uri-encoded.expected.routetypes.d.ts | 7 + packages/run/src/vite/codegen/index.ts | 56 +++++-- packages/run/src/vite/index.ts | 3 +- packages/run/src/vite/utils/meta-data.ts | 43 ++++++ 117 files changed, 1973 insertions(+), 122 deletions(-) create mode 100644 .changeset/wide-moose-sit.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/.marko-run/routes.d.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/dev.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/preview.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+meta.js create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+page.marko create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/test.config.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/tsconfig.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/.marko-run/routes.d.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/dev.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/preview.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+meta.js create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+page.marko create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/test.config.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/tsconfig.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/.marko-run/routes.d.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/dev.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/preview.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+meta.js create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+page.marko create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/test.config.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/tsconfig.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/.marko-run/routes.d.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/dev.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/preview.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+meta.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+page.marko create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/test.config.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/tsconfig.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/.marko-run/routes.d.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/dev.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/preview.expected.md create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+handler.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+meta.json create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+page.marko create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/test.config.ts create mode 100644 packages/run/src/__tests__/fixtures/verb-specific-json-meta/tsconfig.json create mode 100644 packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.router.js create mode 100644 packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routes.md create mode 100644 packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routetypes.d.ts create mode 100644 packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/routes.txt create mode 100644 packages/run/src/vite/utils/meta-data.ts diff --git a/.changeset/wide-moose-sit.md b/.changeset/wide-moose-sit.md new file mode 100644 index 00000000..8bd2f0ab --- /dev/null +++ b/.changeset/wide-moose-sit.md @@ -0,0 +1,5 @@ +--- +"@marko/run": patch +--- + +Support verb-specific overrides for JSON and object meta data diff --git a/packages/run/README.md b/packages/run/README.md index 03b278b8..10395e94 100644 --- a/packages/run/README.md +++ b/packages/run/README.md @@ -133,7 +133,7 @@ Typically, these will be `.js` or `.ts` files depending on your project. Like pa
More Info - - Valid exports are functions named `GET`, `POST`, `PUT`, or `DELETE`. + - Valid exports are functions named `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `PATCH`, `OPTIONS`. - Exports can be one of the following - Handler function (see below) - Array of handler functions - will be composed by calling them in order @@ -207,7 +207,48 @@ These files are like layouts, but for handlers. Middleware files are called befo #### `+meta.*` -These files represent static metadata to attach to the route. This metadata will be automatically provided on the route `context` when invoking a route. +These files represent static metadata to attach to the route. This metadata will be automatically provided on the route `context` when invoking a route. When the file is a non-JSON file, the default export will be used. + +Meta data supports verb-specific overrides when it is an object (eg. a JSON file or `export default { ... }`). Top-level keys that match one of `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `PATCH` or `OPTIONS` will be merged in shallowly to the base object and override any existing values for routes of the method. These keys will also be exlcuded from the base object and ignored if not an object. For example given a `+meta.json` file: + +```json +{ + "name": "Default Name", + "POST": { + "name": "Post Name", + "postOnlyData": "foo" + }, + "GET": { + "name": "Get Name" + }, + "PUT": "Ignored" +} +``` + +when making a POST request the value of `context.meta` will be + +```js +{ + name: "Post Name", + portOnlyData: "foo" +} +``` + +and the value for a GET request will be + +```js +{ + name: "Get Name"; +} +``` + +all other methods, including PUT, will be the base object + +```js +{ + name: "Default Name"; +} +``` ### Special Files @@ -651,6 +692,20 @@ express() **`MarkoRun.Handler`** - Type that represents a handler function to be exported by a +handler or +middleware file +**`MarkoRun.GET`** - Handler type narrowed to GET requests + +**`MarkoRun.HEAD`** - Handler type narrowed to HEAD requests + +**`MarkoRun.POST`** - Handler type narrowed to POST requests + +**`MarkoRun.PUT`** - Handler type narrowed to PUT requests + +**`MarkoRun.DELETE`** - Handler type narrowed to DELETE requests + +**`MarkoRun.PATCH`** - Handler type narrowed to PATCH requests + +**`MarkoRun.OPTIONS`** - Handler type narrowed to OPTIONS requests + **`MarkoRun.Route`** - Type of the route's params and metadata **`MarkoRun.Context`** - Type of the request context object in a handler and `$global` in your Marko files. This type can be extended using TypeScript's module and interface merging by declaring a `Context` interface on the `@marko/run` module within your applcation code diff --git a/packages/run/src/__tests__/fixtures/all-http-verbs/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/all-http-verbs/.marko-run/routes.d.ts index 9318777d..11411577 100644 --- a/packages/run/src/__tests__/fixtures/all-http-verbs/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/all-http-verbs/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-404/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-404/.marko-run/routes.d.ts index beae10d3..8b5c8177 100644 --- a/packages/run/src/__tests__/fixtures/basic-404/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-404/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-500/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-500/.marko-run/routes.d.ts index 4e8756e1..eca69fcd 100644 --- a/packages/run/src/__tests__/fixtures/basic-500/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-500/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -44,6 +58,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -58,6 +79,13 @@ declare module "../src/routes/+500.marko" { export type Route = globalThis.MarkoRun.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-assets/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-assets/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/basic-assets/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-assets/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-client-component/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-client-component/.marko-run/routes.d.ts index 00c1c69e..919510f4 100644 --- a/packages/run/src/__tests__/fixtures/basic-client-component/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-client-component/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/foo/$id/+page.marko" { export type Route = Run.Routes["/foo/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -45,6 +59,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/" | "/foo/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-cookies/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-cookies/.marko-run/routes.d.ts index e1963ffc..08df99a3 100644 --- a/packages/run/src/__tests__/fixtures/basic-cookies/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-cookies/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+middleware" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-handler/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-handler/.marko-run/routes.d.ts index 93ed2004..a0f05b15 100644 --- a/packages/run/src/__tests__/fixtures/basic-handler/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-handler/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-layout/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-layout/.marko-run/routes.d.ts index 52ce23c8..0de10630 100644 --- a/packages/run/src/__tests__/fixtures/basic-layout/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-layout/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-middleware/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-middleware/.marko-run/routes.d.ts index e1963ffc..08df99a3 100644 --- a/packages/run/src/__tests__/fixtures/basic-middleware/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-middleware/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+middleware" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-nested-page/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-nested-page/.marko-run/routes.d.ts index 667a3b7b..3649359a 100644 --- a/packages/run/src/__tests__/fixtures/basic-nested-page/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-nested-page/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/foo/+page.marko" { export type Route = Run.Routes["/foo"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/foo/bar+page.marko" { export type Route = Run.Routes["/foo/bar"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -45,6 +59,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/foo" | "/foo/bar"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-page/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-page/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/basic-page/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-page/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-redirect-back-fallback/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-redirect-back-fallback/.marko-run/routes.d.ts index 6f60c56e..d4aee061 100644 --- a/packages/run/src/__tests__/fixtures/basic-redirect-back-fallback/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-redirect-back-fallback/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/other+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-redirect-back/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-redirect-back/.marko-run/routes.d.ts index 6f60c56e..d4aee061 100644 --- a/packages/run/src/__tests__/fixtures/basic-redirect-back/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-redirect-back/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/other+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/basic-redirect/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/basic-redirect/.marko-run/routes.d.ts index 6f60c56e..d4aee061 100644 --- a/packages/run/src/__tests__/fixtures/basic-redirect/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/basic-redirect/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/other+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/config-override/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/config-override/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/config-override/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/config-override/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/config-port-override/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/config-port-override/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/config-port-override/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/config-port-override/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/default-get-as-head/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/default-get-as-head/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/default-get-as-head/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/default-get-as-head/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/dynamic-nested/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/dynamic-nested/.marko-run/routes.d.ts index d3aef392..ae766262 100644 --- a/packages/run/src/__tests__/fixtures/dynamic-nested/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/dynamic-nested/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/foo/$fooId/bar/$barId/+page.marko" { export type Route = Run.Routes["/foo/$fooId/bar/$barId"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/dynamic-rest/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/dynamic-rest/.marko-run/routes.d.ts index 828666f6..9d927fd7 100644 --- a/packages/run/src/__tests__/fixtures/dynamic-rest/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/dynamic-rest/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/$$rest/+page.marko" { export type Route = Run.Routes["/$$rest"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/dynamic/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/dynamic/.marko-run/routes.d.ts index 91c4dfc1..afa41da2 100644 --- a/packages/run/src/__tests__/fixtures/dynamic/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/dynamic/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/$id/+page.marko" { export type Route = Run.Routes["/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/force-class-api/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/force-class-api/.marko-run/routes.d.ts index 52ce23c8..0de10630 100644 --- a/packages/run/src/__tests__/fixtures/force-class-api/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/force-class-api/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/force-tags-api/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/force-tags-api/.marko-run/routes.d.ts index 52ce23c8..0de10630 100644 --- a/packages/run/src/__tests__/fixtures/force-tags-api/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/force-tags-api/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/generated-route-files/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/generated-route-files/.marko-run/routes.d.ts index c9fe0149..bccd43aa 100644 --- a/packages/run/src/__tests__/fixtures/generated-route-files/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/generated-route-files/.marko-run/routes.d.ts @@ -26,6 +26,13 @@ declare module "../src/routes/_index/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -37,6 +44,13 @@ declare module "../src/routes/_index/component/+page.marko" { export type Route = Run.Routes["/component"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -48,6 +62,13 @@ declare module "../src/routes/a.(,b,c),d.e/+page.marko" { export type Route = Run.Routes["/a" | "/a/b" | "/a/c" | "/d/e"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -60,6 +81,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/" | "/component" | "/a" | "/a/b" | "/a/c" | "/d/e"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -71,6 +99,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -85,6 +120,13 @@ declare module "../src/routes/+500.marko" { export type Route = globalThis.MarkoRun.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/inject-plugin-custom-entry/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/inject-plugin-custom-entry/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/inject-plugin-custom-entry/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/inject-plugin-custom-entry/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/inject-plugin/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/inject-plugin/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/inject-plugin/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/inject-plugin/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/layout-404/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/layout-404/.marko-run/routes.d.ts index 87f85125..c59701fc 100644 --- a/packages/run/src/__tests__/fixtures/layout-404/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/layout-404/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -44,6 +58,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/micro-frame-fetch/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/micro-frame-fetch/.marko-run/routes.d.ts index 5313b11a..0ff992ed 100644 --- a/packages/run/src/__tests__/fixtures/micro-frame-fetch/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/micro-frame-fetch/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/other+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/netlify-adapter-edge/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/netlify-adapter-edge/.marko-run/routes.d.ts index 6544c128..bcb7cffe 100644 --- a/packages/run/src/__tests__/fixtures/netlify-adapter-edge/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/netlify-adapter-edge/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/netlify-adapter-not-edge/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/netlify-adapter-not-edge/.marko-run/routes.d.ts index 152ee502..95f43708 100644 --- a/packages/run/src/__tests__/fixtures/netlify-adapter-not-edge/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/netlify-adapter-not-edge/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-express-bodyParser/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-express-bodyParser/.marko-run/routes.d.ts index 0c3a332c..be410fb6 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-express-bodyParser/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-express-bodyParser/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -34,6 +41,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-express-formData/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-express-formData/.marko-run/routes.d.ts index 0c3a332c..be410fb6 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-express-formData/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-express-formData/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -34,6 +41,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-express-import/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-express-import/.marko-run/routes.d.ts index dca3b743..b9782034 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-express-import/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-express-import/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-express-match/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-express-match/.marko-run/routes.d.ts index dca3b743..b9782034 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-express-match/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-express-match/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-express/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-express/.marko-run/routes.d.ts index dca3b743..b9782034 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-express/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-express/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/node-adapter-page/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/node-adapter-page/.marko-run/routes.d.ts index dca3b743..b9782034 100644 --- a/packages/run/src/__tests__/fixtures/node-adapter-page/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/node-adapter-page/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/not-handled/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/not-handled/.marko-run/routes.d.ts index 93ed2004..a0f05b15 100644 --- a/packages/run/src/__tests__/fixtures/not-handled/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/not-handled/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/not-matched/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/not-matched/.marko-run/routes.d.ts index 0875f22a..7267ae5d 100644 --- a/packages/run/src/__tests__/fixtures/not-matched/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/not-matched/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/post-get-single-flight/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/post-get-single-flight/.marko-run/routes.d.ts index 94ba4db3..9c87e2ac 100644 --- a/packages/run/src/__tests__/fixtures/post-get-single-flight/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/post-get-single-flight/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/$id+handler" { export type Route = Run.Routes["/$id"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/$id+page.marko" { export type Route = Run.Routes["/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/render-custom-page/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/render-custom-page/.marko-run/routes.d.ts index 0a369485..319ae2cf 100644 --- a/packages/run/src/__tests__/fixtures/render-custom-page/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/render-custom-page/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/runtime-include/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/runtime-include/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/runtime-include/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/runtime-include/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/ssr-emit-assets/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/ssr-emit-assets/.marko-run/routes.d.ts index b6b93448..f8d65cd8 100644 --- a/packages/run/src/__tests__/fixtures/ssr-emit-assets/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/ssr-emit-assets/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+middleware.js" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-file-html/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-file-html/.marko-run/routes.d.ts index 969315e0..5013aaff 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-file-html/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-file-html/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/`html.md`+handler.marko" { export type Route = Run.Routes["/html.md"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-file-plain/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-file-plain/.marko-run/routes.d.ts index 66fdc585..5a9cfea4 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-file-plain/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-file-plain/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/`plain.md`+handler.marko" { export type Route = Run.Routes["/plain.md"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-invalid-url/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-invalid-url/.marko-run/routes.d.ts index beae10d3..8b5c8177 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-invalid-url/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-invalid-url/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -32,6 +39,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-page/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-page/.marko-run/routes.d.ts index 5c2f00fd..4c22b843 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-page/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-page/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-path-param/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-path-param/.marko-run/routes.d.ts index e670a6a2..749457b6 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-path-param/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-path-param/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/users.$id+page.marko" { export type Route = Run.Routes["/users/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-redirect/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-redirect/.marko-run/routes.d.ts index c0b534fc..cb73b042 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-redirect/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-redirect/.marko-run/routes.d.ts @@ -23,6 +23,13 @@ declare module "../src/routes/+handler" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -34,6 +41,13 @@ declare module "../src/routes/foo+page.marko" { export type Route = Run.Routes["/foo"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -45,6 +59,13 @@ declare module "../src/routes/other/+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-rest-param/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-rest-param/.marko-run/routes.d.ts index c5d4af84..0d21532a 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-rest-param/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-rest-param/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/$$rest+page.marko" { export type Route = Run.Routes["/$$rest"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/static-adapter-trailing-slash/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/static-adapter-trailing-slash/.marko-run/routes.d.ts index 5313b11a..0ff992ed 100644 --- a/packages/run/src/__tests__/fixtures/static-adapter-trailing-slash/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/static-adapter-trailing-slash/.marko-run/routes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/other+page.marko" { export type Route = Run.Routes["/other"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/uri-encoded/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/uri-encoded/.marko-run/routes.d.ts index 0ad30e2d..7823dd5d 100644 --- a/packages/run/src/__tests__/fixtures/uri-encoded/.marko-run/routes.d.ts +++ b/packages/run/src/__tests__/fixtures/uri-encoded/.marko-run/routes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/a%2fb%2fc/$%24id/+page.marko" { export type Route = Run.Routes["/a%2fb%2fc/$`$id`"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/.marko-run/routes.d.ts new file mode 100644 index 00000000..1f9b69a4 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/.marko-run/routes.d.ts @@ -0,0 +1,34 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/": { verb: "get"; meta: typeof import("../src/routes/+meta.js")["default"]; }; + } + }> {} +} + +declare module "../src/routes/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/dev.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/dev.expected.md new file mode 100644 index 00000000..9f186689 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/dev.expected.md @@ -0,0 +1,20 @@ +# Loading + +```html +() => ({ + pageTitle: "base-title", + otherProp: "other", + get: { + prop: "value" + }, + GET: { + pageTitle: "get-title", + otherProp: "other", + }, + POST: { + pageTitle: "post-title", + otherProp: "other", + } +}) +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/preview.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/preview.expected.md new file mode 100644 index 00000000..9f186689 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/__snapshots__/preview.expected.md @@ -0,0 +1,20 @@ +# Loading + +```html +() => ({ + pageTitle: "base-title", + otherProp: "other", + get: { + prop: "value" + }, + GET: { + pageTitle: "get-title", + otherProp: "other", + }, + POST: { + pageTitle: "post-title", + otherProp: "other", + } +}) +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+meta.js b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+meta.js new file mode 100644 index 00000000..173f82d9 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+meta.js @@ -0,0 +1,15 @@ +export default () => ({ + pageTitle: "base-title", + otherProp: "other", + get: { + prop: "value" + }, + GET: { + pageTitle: "get-title", + otherProp: "other", + }, + POST: { + pageTitle: "post-title", + otherProp: "other", + } +}) diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+page.marko b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+page.marko new file mode 100644 index 00000000..b0309a2d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/src/routes/+page.marko @@ -0,0 +1,12 @@ + + + + + @marko/run Test Fixture + + + + ${$global.meta.toString()} + + + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/test.config.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/test.config.ts new file mode 100644 index 00000000..69d2286d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/test.config.ts @@ -0,0 +1 @@ +export const steps = []; diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/tsconfig.json b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/tsconfig.json new file mode 100644 index 00000000..03ff88a5 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-non-object-meta/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig-base.json", + "include": ["src/**/*", ".marko-run/*"], +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/.marko-run/routes.d.ts new file mode 100644 index 00000000..1f9b69a4 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/.marko-run/routes.d.ts @@ -0,0 +1,34 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/": { verb: "get"; meta: typeof import("../src/routes/+meta.js")["default"]; }; + } + }> {} +} + +declare module "../src/routes/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/dev.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/dev.expected.md new file mode 100644 index 00000000..2f2a84f8 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/dev.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/preview.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/preview.expected.md new file mode 100644 index 00000000..2f2a84f8 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/__snapshots__/preview.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+meta.js b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+meta.js new file mode 100644 index 00000000..fcd513d0 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+meta.js @@ -0,0 +1,11 @@ +export default { + pageTitle: "base-title", + otherProp: "other", + get: { + prop: "value" + }, + POST: { + pageTitle: "post-title", + otherProp: "other", + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+page.marko b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+page.marko new file mode 100644 index 00000000..46593d24 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/src/routes/+page.marko @@ -0,0 +1,12 @@ + + + + + @marko/run Test Fixture + + + + ${JSON.stringify($global.meta, null, 2)} + + + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/test.config.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/test.config.ts new file mode 100644 index 00000000..69d2286d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/test.config.ts @@ -0,0 +1 @@ +export const steps = []; diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/tsconfig.json b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/tsconfig.json new file mode 100644 index 00000000..03ff88a5 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta-fallback/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig-base.json", + "include": ["src/**/*", ".marko-run/*"], +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/.marko-run/routes.d.ts new file mode 100644 index 00000000..1f9b69a4 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/.marko-run/routes.d.ts @@ -0,0 +1,34 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/": { verb: "get"; meta: typeof import("../src/routes/+meta.js")["default"]; }; + } + }> {} +} + +declare module "../src/routes/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/dev.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/dev.expected.md new file mode 100644 index 00000000..0cc07fdf --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/dev.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "get-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/preview.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/preview.expected.md new file mode 100644 index 00000000..0cc07fdf --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/__snapshots__/preview.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "get-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+meta.js b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+meta.js new file mode 100644 index 00000000..1b44e2ce --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+meta.js @@ -0,0 +1,15 @@ +export default { + pageTitle: "base-title", + otherProp: "other", + get: { + prop: "value" + }, + GET: { + pageTitle: "get-title", + otherProp: "other", + }, + POST: { + pageTitle: "post-title", + otherProp: "other", + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+page.marko b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+page.marko new file mode 100644 index 00000000..46593d24 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/src/routes/+page.marko @@ -0,0 +1,12 @@ + + + + + @marko/run Test Fixture + + + + ${JSON.stringify($global.meta, null, 2)} + + + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/test.config.ts b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/test.config.ts new file mode 100644 index 00000000..69d2286d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/test.config.ts @@ -0,0 +1 @@ +export const steps = []; diff --git a/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/tsconfig.json b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/tsconfig.json new file mode 100644 index 00000000..03ff88a5 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-js-object-meta/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig-base.json", + "include": ["src/**/*", ".marko-run/*"], +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/.marko-run/routes.d.ts new file mode 100644 index 00000000..5a68d0e5 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/.marko-run/routes.d.ts @@ -0,0 +1,34 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/": { verb: "get"; meta: typeof import("../src/routes/+meta.json"); }; + } + }> {} +} + +declare module "../src/routes/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/dev.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/dev.expected.md new file mode 100644 index 00000000..2f2a84f8 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/dev.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/preview.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/preview.expected.md new file mode 100644 index 00000000..2f2a84f8 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/__snapshots__/preview.expected.md @@ -0,0 +1,12 @@ +# Loading + +```html +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+meta.json b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+meta.json new file mode 100644 index 00000000..d3b35306 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+meta.json @@ -0,0 +1,10 @@ +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + }, + "POST": { + "pageTitle": "post-title" + } +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+page.marko b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+page.marko new file mode 100644 index 00000000..46593d24 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/src/routes/+page.marko @@ -0,0 +1,12 @@ + + + + + @marko/run Test Fixture + + + + ${JSON.stringify($global.meta, null, 2)} + + + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/test.config.ts b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/test.config.ts new file mode 100644 index 00000000..69d2286d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/test.config.ts @@ -0,0 +1 @@ +export const steps = []; diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/tsconfig.json b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/tsconfig.json new file mode 100644 index 00000000..03ff88a5 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta-fallback/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig-base.json", + "include": ["src/**/*", ".marko-run/*"], +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/.marko-run/routes.d.ts b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/.marko-run/routes.d.ts new file mode 100644 index 00000000..a83d993b --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/.marko-run/routes.d.ts @@ -0,0 +1,52 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/": { verb: "get" | "post"; meta: typeof import("../src/routes/+meta.json"); }; + } + }> {} +} + +declare module "../src/routes/+handler" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} + +declare module "../src/routes/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/dev.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/dev.expected.md new file mode 100644 index 00000000..cf942f66 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/dev.expected.md @@ -0,0 +1,13 @@ +# Loading + +```html +{ + "pageTitle": "get-title", + "getOnly": true, + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/preview.expected.md b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/preview.expected.md new file mode 100644 index 00000000..cf942f66 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/__snapshots__/preview.expected.md @@ -0,0 +1,13 @@ +# Loading + +```html +{ + "pageTitle": "get-title", + "getOnly": true, + "otherProp": "other", + "get": { + "prop": "value" + } +} +``` + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+handler.ts b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+handler.ts new file mode 100644 index 00000000..bf08bb71 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+handler.ts @@ -0,0 +1,9 @@ +export const GET: MarkoRun.GET = (ctx) => { +} + +export const POST: MarkoRun.POST = (ctx) => { +} + +export const PUT: MarkoRun.PUT = (ctx) => { +} + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+meta.json b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+meta.json new file mode 100644 index 00000000..eee3d4ce --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+meta.json @@ -0,0 +1,15 @@ +{ + "pageTitle": "base-title", + "otherProp": "other", + "get": { + "prop": "value" + }, + "GET": { + "pageTitle": "get-title", + "getOnly": true + }, + "POST": { + "pageTitle": "post-title", + "postOnly": true + } +} \ No newline at end of file diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+page.marko b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+page.marko new file mode 100644 index 00000000..46593d24 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/src/routes/+page.marko @@ -0,0 +1,12 @@ + + + + + @marko/run Test Fixture + + + + ${JSON.stringify($global.meta, null, 2)} + + + diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/test.config.ts b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/test.config.ts new file mode 100644 index 00000000..69d2286d --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/test.config.ts @@ -0,0 +1 @@ +export const steps = []; diff --git a/packages/run/src/__tests__/fixtures/verb-specific-json-meta/tsconfig.json b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/tsconfig.json new file mode 100644 index 00000000..9f5d4932 --- /dev/null +++ b/packages/run/src/__tests__/fixtures/verb-specific-json-meta/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig-base.json", + "include": ["src/**/*", ".marko-run/*", "src/routes/+handler.d.ts"], +} \ No newline at end of file diff --git a/packages/run/src/runtime/index.ts b/packages/run/src/runtime/index.ts index 9500632d..af0c31bd 100644 --- a/packages/run/src/runtime/index.ts +++ b/packages/run/src/runtime/index.ts @@ -2,13 +2,13 @@ import { InlineConfig } from "vite"; import { NotHandled, NotMatched } from "./namespace"; import type { - AnyContext, - AnyHandler, AnyRoute, GetableHref, GetablePath, GetPaths, + HandlerLike, HandlerTypeFn, + MultiRouteContext, Platform, PostableHref, PostablePath, @@ -18,26 +18,32 @@ import type { declare global { var __marko_run__: RuntimeModule; - var __marko_run_vite_config__: InlineConfig | undefined; namespace MarkoRun { - /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ - export const route: HandlerTypeFn; export { - AnyContext as Context, GetableHref, GetablePath, GetPaths, - AnyHandler as Handler, NotHandled, NotMatched, Platform, PostableHref, PostablePath, PostPaths, - AnyRoute as Route, }; + export type Route = AnyRoute; + export type Context = MultiRouteContext; + export type Handler = HandlerLike; + export type GET = HandlerLike; + export type HEAD = HandlerLike; + export type POST = HandlerLike; + export type PUT = HandlerLike; + export type DELETE = HandlerLike; + export type PATCH = HandlerLike; + export type OPTIONS = HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: HandlerTypeFn; } } @@ -61,4 +67,5 @@ export type { Routes, RouteWithHandler, RuntimeModule, + Verb, } from "./types"; diff --git a/packages/run/src/runtime/internal.ts b/packages/run/src/runtime/internal.ts index 7e622f5a..1f204147 100644 --- a/packages/run/src/runtime/internal.ts +++ b/packages/run/src/runtime/internal.ts @@ -9,7 +9,9 @@ import type { Platform, RouteHandler, RouteHandlerResult, + Verb, } from "./types"; +export { getMetaDataLookup as normalizeMeta } from "../vite/utils/meta-data"; export const NotHandled: typeof MarkoRun.NotHandled = Symbol( "marko-run not handled", @@ -87,6 +89,7 @@ export function createContext( } return { request, + method: request.method as Verb, url, platform, meta, @@ -106,7 +109,7 @@ export function createContext( request = new Request(url, init); } - parentContextLookup.set(request, this); + parentContextLookup.set(request, this as any); return ( (await globalThis.__marko_run__.fetch(request, this.platform)) || new Response(null, { status: 404 }) @@ -219,7 +222,7 @@ export function compose(handlers: RouteHandler[]): RouteHandler { }; } -export function normalize( +export function normalizeHandler( obj: RouteHandler | RouteHandler[] | Promise, ): RouteHandler { if (typeof obj === "function") { diff --git a/packages/run/src/runtime/namespace.ts b/packages/run/src/runtime/namespace.ts index f96036d5..a5aca77f 100644 --- a/packages/run/src/runtime/namespace.ts +++ b/packages/run/src/runtime/namespace.ts @@ -8,4 +8,5 @@ export type { PostableHref, PostablePath, PostPaths, + Verb, } from "./types"; diff --git a/packages/run/src/runtime/types.ts b/packages/run/src/runtime/types.ts index b72922af..5e439d98 100644 --- a/packages/run/src/runtime/types.ts +++ b/packages/run/src/runtime/types.ts @@ -1,10 +1,18 @@ /// -export type Awaitable = Promise | T; +import type { HttpVerb } from "../vite"; + type OneOrMany = T | T[]; type NoParams = {}; type AllKeys = T extends T ? keyof T : never; type Simplify = T extends unknown ? { [K in keyof T]: T[K] } : never; +type IsObject = T extends object + ? T extends any[] + ? 0 + : T extends (...args: any[]) => any + ? 0 + : 1 + : 0; type SuperSet = T & { [K in AllKeys as K extends keyof T ? never : K]?: never; }; @@ -12,14 +20,22 @@ type SuperSets = Omit & { [P in K]: Simplify>; }; +export type Awaitable = Promise | T; + +export type Verb = Uppercase; + export interface Platform {} -export interface Context { +export interface Context< + TRoute extends Route = AnyRoute, + TVerb extends Verb = Verb, +> { readonly url: URL; readonly request: Request; + readonly method: TVerb; readonly route: TRoute["path"]; readonly params: TRoute["params"]; - readonly meta: TRoute["meta"]; + readonly meta: NormalizedMeta; readonly platform: Platform; readonly serializedGlobals: Record; readonly parent: Context | undefined; @@ -38,18 +54,22 @@ export interface Context { export type MultiRouteContext< TRoute extends Route, + TVerb extends Verb = Verb, _Preserved extends TRoute = TRoute, > = TRoute extends any - ? Context>> + ? TVerb extends any + ? Context>, TVerb> + : never : never; export type ParamsObject = Record; export type InputObject = Record; export type NextFunction = () => Awaitable; -export type HandlerLike = Awaitable< - OneOrMany> ->; +export type HandlerLike< + TRoute extends Route = AnyRoute, + TVerb extends Verb = Verb, +> = Awaitable>>; export type RouteHandlerResult = | Response @@ -58,14 +78,17 @@ export type RouteHandlerResult = | null | void; -export type RouteHandler = ( - context: MultiRouteContext, +export type RouteHandler< + TRoute extends Route = AnyRoute, + TVerb extends Verb = Verb, +> = ( + context: MultiRouteContext, next: NextFunction, ) => Awaitable; export interface Route< Params extends ParamsObject = ParamsObject, - Meta = unknown, + Meta = any, Path extends string = string, > { path: Path; @@ -77,17 +100,17 @@ type DefineRoutes> = { [K in keyof T]: K extends string ? T[K] extends { meta: infer Meta } ? Route, Meta, K> - : Route, unknown, K> + : Route, any, K> : never; }; type DefinePaths< T extends Record, - Verb extends "get" | "post", + TVerb extends "get" | "post", > = { [K in keyof T]: K extends string ? T[K] extends { verb: infer V } - ? V extends Verb + ? V extends TVerb ? K : never : never @@ -209,11 +232,23 @@ type ValidateHref< ? `${ValidatePath}#${H}` : ValidatePath; -export interface AppData {} +type NormalizedMetaObject = + IsObject extends 1 + ? TVerb extends keyof T + ? Simplify & T[TVerb]> + : Simplify> + : never; + +export type NormalizedMeta = + IsObject extends 1 + ? { [K in TVerb]: NormalizedMetaObject }[TVerb] + : T; -type HasAppData = AppData extends { routes: any } ? 1 : 0; -type AnyParams = 0 extends HasAppData ? ParamsObject : never; -type AnyMeta = 0 extends HasAppData ? unknown : never; +export type NormalizedMetaLookup = { + [K in Verb]: IsObject extends 1 ? NormalizedMetaObject : T; +}; + +export interface AppData {} export type Routes = AppData extends { routes: infer T } ? T @@ -221,27 +256,19 @@ export type Routes = AppData extends { routes: infer T } export type AnyRoute = Routes[keyof Routes]; -export type AnyContext = MultiRouteContext; - -export type AnyHandler< - Params extends AnyParams = AnyParams, - Meta extends AnyMeta = AnyMeta, -> = 0 extends HasAppData - ? HandlerLike> - : HandlerLike; - -export type HandlerTypeFn = - 0 extends HasAppData - ? < - Params extends ParamsObject = ParamsObject, - Meta = unknown, - T extends HandlerLike> = HandlerLike< - Route - >, - >( - handler: T, - ) => T - : >(handler: T) => T; +export type HandlerTypeFn = AppData extends { + routes: any; +} + ? < + Params extends ParamsObject = ParamsObject, + Meta = any, + T extends HandlerLike> = HandlerLike< + Route + >, + >( + handler: T, + ) => T + : >(handler: T) => T; type DefaultAPI = keyof Exclude< Marko.Renderable, diff --git a/packages/run/src/vite/__tests__/fixtures/basic-500/__snapshots__/basic-500.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/basic-500/__snapshots__/basic-500.expected.routetypes.d.ts index e178d858..37be312a 100644 --- a/packages/run/src/vite/__tests__/fixtures/basic-500/__snapshots__/basic-500.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/basic-500/__snapshots__/basic-500.expected.routetypes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -47,6 +61,13 @@ declare module "../src/routes/+500.marko" { export type Route = globalThis.MarkoRun.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/basic/__snapshots__/basic.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/basic/__snapshots__/basic.expected.routetypes.d.ts index a09be2d9..c46f7945 100644 --- a/packages/run/src/vite/__tests__/fixtures/basic/__snapshots__/basic.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/basic/__snapshots__/basic.expected.routetypes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/fOoBaR/+page.marko" { export type Route = Run.Routes["/fOoBaR"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.router.js b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.router.js index bc539f7f..c33d6899 100644 --- a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.router.js +++ b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.router.js @@ -1,8 +1,8 @@ import { NotHandled, NotMatched, createContext } from "virtual:marko-run/runtime/internal"; import { get3, head3 } from "virtual:marko-run/__marko-run__index.js"; -import { get4, head4, post4, meta4 } from "virtual:marko-run/__marko-run__new.js"; +import { get4, get4_meta, head4, head4_meta, post4, post4_meta } from "virtual:marko-run/__marko-run__new.js"; import { get5, head5, post5, put5, delete5 } from "virtual:marko-run/__marko-run__notes.$.js"; -import { post6, put6, delete6, meta6 } from "virtual:marko-run/__marko-run__notes.$.comments.js"; +import { post6, post6_meta, put6, put6_meta, delete6, delete6_meta } from "virtual:marko-run/__marko-run__notes.$.comments.js"; import { get7, head7 } from "virtual:marko-run/__marko-run__callback.oauth2.js"; import { get8, head8 } from "virtual:marko-run/__marko-run__my.js"; import { get9, head9 } from "virtual:marko-run/__marko-run__$$.js"; @@ -35,7 +35,7 @@ function match_internal(method, pathname) { const i1 = pathname.indexOf('/', 1) + 1; if (!i1 || i1 === len) { switch (pathname.slice(1, i1 ? -1 : len)) { - case 'new': return { handler: get4, params: {}, meta: meta4, path: '/new' }; + case 'new': return { handler: get4, params: {}, meta: get4_meta, path: '/new' }; case 'my': return { handler: get8, params: {}, meta: {}, path: '/my' }; } } else { @@ -63,7 +63,7 @@ function match_internal(method, pathname) { const i1 = pathname.indexOf('/', 1) + 1; if (!i1 || i1 === len) { switch (pathname.slice(1, i1 ? -1 : len)) { - case 'new': return { handler: head4, params: {}, meta: meta4, path: '/new' }; + case 'new': return { handler: head4, params: {}, meta: head4_meta, path: '/new' }; case 'my': return { handler: head8, params: {}, meta: {}, path: '/my' }; } } else { @@ -90,7 +90,7 @@ function match_internal(method, pathname) { if (len > 1) { const i1 = pathname.indexOf('/', 1) + 1; if (!i1 || i1 === len) { - if (pathname.slice(1, i1 ? -1 : len) === 'new') return { handler: post4, params: {}, meta: meta4, path: '/new' }; + if (pathname.slice(1, i1 ? -1 : len) === 'new') return { handler: post4, params: {}, meta: post4_meta, path: '/new' }; } else { if (pathname.slice(1, i1 - 1) === 'notes') { const i2 = pathname.indexOf('/', 7) + 1; @@ -102,7 +102,7 @@ function match_internal(method, pathname) { if (s2) { const i3 = pathname.indexOf('/', i2) + 1; if (!i3 || i3 === len) { - if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: post6, params: { id: s2 }, meta: meta6, path: '/notes/$id/comments' }; + if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: post6, params: { id: s2 }, meta: post6_meta, path: '/notes/$id/comments' }; } } } @@ -126,7 +126,7 @@ function match_internal(method, pathname) { if (s2) { const i3 = pathname.indexOf('/', i2) + 1; if (!i3 || i3 === len) { - if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: put6, params: { id: s2 }, meta: meta6, path: '/notes/$id/comments' }; + if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: put6, params: { id: s2 }, meta: put6_meta, path: '/notes/$id/comments' }; } } } @@ -150,7 +150,7 @@ function match_internal(method, pathname) { if (s2) { const i3 = pathname.indexOf('/', i2) + 1; if (!i3 || i3 === len) { - if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: delete6, params: { id: s2 }, meta: meta6, path: '/notes/$id/comments' }; + if (pathname.slice(i2, i3 ? -1 : len) === 'comments') return { handler: delete6, params: { id: s2 }, meta: delete6_meta, path: '/notes/$id/comments' }; } } } diff --git a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routes.md b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routes.md index bac5403f..fd41903a 100644 --- a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routes.md +++ b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routes.md @@ -2,16 +2,16 @@ ## Middleware ```js -import { normalize } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler } from "virtual:marko-run/runtime/internal"; import middleware4 from "./src/routes/+middleware.ts"; import middleware5 from "./src/routes/_protected/+middleware.ts"; import middleware7 from "./src/routes/_protected/_home/+middleware.ts"; import middleware13 from "./src/routes/_protected/_home/notes/$id/+middleware.ts"; -export const mware4 = normalize(middleware4); -export const mware5 = normalize(middleware5); -export const mware7 = normalize(middleware7); -export const mware13 = normalize(middleware13); +export const mware4 = normalizeHandler(middleware4); +export const mware5 = normalizeHandler(middleware5); +export const mware7 = normalizeHandler(middleware7); +export const mware13 = normalizeHandler(middleware13); ``` --- @@ -63,13 +63,15 @@ import Page from "../../src/routes/_protected/_home/new/+page.marko"; ``` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, normalizeMeta, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware4, mware5, mware7 } from "virtual:marko-run/__marko-run__middleware.js"; import { POST } from "./src/routes/_protected/_home/new/+handler.ts"; import page from "./dist/.marko-run/new.marko"; -export { default as meta4 } from "./src/routes/_protected/_home/new/+meta.json"; +import meta4 from "./src/routes/_protected/_home/new/+meta.json"; -const postHandler = normalize(POST); +const postHandler = normalizeHandler(POST); + +export const { GET: get4_meta, GET: head4_meta, POST: post4_meta } = normalizeMeta(meta4); export function get4(context) { const __page = () => context.render(page, {}); @@ -106,14 +108,14 @@ import Page from "../../src/routes/_protected/_home/notes/$id/+page.marko"; ``` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware4, mware5, mware7, mware13 } from "virtual:marko-run/__marko-run__middleware.js"; import { PUT, POST, DELETE } from "./src/routes/_protected/_home/notes/$id/+handler.ts"; import page from "./dist/.marko-run/notes.$.marko"; -const putHandler = normalize(PUT); -const postHandler = normalize(POST); -const deleteHandler = normalize(DELETE); +const putHandler = normalizeHandler(PUT); +const postHandler = normalizeHandler(POST); +const deleteHandler = normalizeHandler(DELETE); export function get5(context) { const __page = () => context.render(page, {}); @@ -156,14 +158,16 @@ export function delete5(context) { ### Path: ``/notes/$id/comments`` ### Handler ```js -import { normalize, call, noContent } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, normalizeMeta, call, noContent } from "virtual:marko-run/runtime/internal"; import { mware4, mware5, mware7, mware13 } from "virtual:marko-run/__marko-run__middleware.js"; import { PUT, POST, DELETE } from "./src/routes/_protected/_home/notes/$id/comments/+handler.ts"; -export { default as meta6 } from "./src/routes/_protected/_home/notes/$id/comments/+meta.ts"; +import meta6 from "./src/routes/_protected/_home/notes/$id/comments/+meta.ts"; + +const putHandler = normalizeHandler(PUT); +const postHandler = normalizeHandler(POST); +const deleteHandler = normalizeHandler(DELETE); -const putHandler = normalize(PUT); -const postHandler = normalize(POST); -const deleteHandler = normalize(DELETE); +export const { POST: post6_meta, PUT: put6_meta, DELETE: delete6_meta } = normalizeMeta(meta6); export function post6(context) { const __postHandler = () => call(postHandler, noContent, context); @@ -194,11 +198,11 @@ export function delete6(context) { ### Path: ``/callback/oauth2`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware4 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/callback/oauth2/+handler.ts"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get7(context) { const __getHandler = () => call(getHandler, noContent, context); @@ -223,13 +227,13 @@ import Page from "../../src/routes/my/+page.marko"; ``` ### Handler ```js -import { normalize, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware4 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET, HEAD } from "./src/routes/my/+handler.ts"; import page from "./dist/.marko-run/my.marko"; -const getHandler = normalize(GET); -const headHandler = normalize(HEAD); +const getHandler = normalizeHandler(GET); +const headHandler = normalizeHandler(HEAD); export function get8(context) { const __page = () => context.render(page, {}); @@ -248,11 +252,11 @@ export function head8(context) { ### Path: ``/$$match`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware4 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/$$match/+handler.ts"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get9(context) { const __getHandler = () => call(getHandler, noContent, context); diff --git a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routetypes.d.ts index 9fd1394e..6cd3fbce 100644 --- a/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/build-routes/__snapshots__/build-routes.expected.routetypes.d.ts @@ -27,6 +27,13 @@ declare module "../src/routes/_protected/_home/new/+handler" { export type Route = Run.Routes["/new"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -38,6 +45,13 @@ declare module "../src/routes/_protected/_home/notes/$id/+handler" { export type Route = Run.Routes["/notes/$id"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -49,6 +63,13 @@ declare module "../src/routes/_protected/_home/notes/$id/comments/+handler" { export type Route = Run.Routes["/notes/$id/comments"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -60,6 +81,13 @@ declare module "../src/routes/callback/oauth2/+handler" { export type Route = Run.Routes["/callback/oauth2"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -71,6 +99,13 @@ declare module "../src/routes/my/+handler" { export type Route = Run.Routes["/my"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -82,6 +117,13 @@ declare module "../src/routes/$$match/+handler" { export type Route = Run.Routes["/$$match"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -93,6 +135,13 @@ declare module "../src/routes/+middleware" { export type Route = Run.Routes["/" | "/new" | "/notes/$id" | "/notes/$id/comments" | "/callback/oauth2" | "/my" | "/$$match"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -104,6 +153,13 @@ declare module "../src/routes/_protected/+middleware" { export type Route = Run.Routes["/" | "/new" | "/notes/$id" | "/notes/$id/comments"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -115,6 +171,13 @@ declare module "../src/routes/_protected/_home/+middleware" { export type Route = Run.Routes["/" | "/new" | "/notes/$id" | "/notes/$id/comments"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -126,6 +189,13 @@ declare module "../src/routes/_protected/_home/notes/$id/+middleware" { export type Route = Run.Routes["/notes/$id" | "/notes/$id/comments"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -137,6 +207,13 @@ declare module "../src/routes/_protected/_home/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -148,6 +225,13 @@ declare module "../src/routes/_protected/_home/new/+page.marko" { export type Route = Run.Routes["/new"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -159,6 +243,13 @@ declare module "../src/routes/_protected/_home/notes/$id/+page.marko" { export type Route = Run.Routes["/notes/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -170,6 +261,13 @@ declare module "../src/routes/my/+page.marko" { export type Route = Run.Routes["/my"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -182,6 +280,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/" | "/new" | "/notes/$id" | "/my"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -194,6 +299,13 @@ declare module "../src/routes/_protected/_home/+layout.marko" { export type Route = Run.Routes["/" | "/new" | "/notes/$id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -205,6 +317,13 @@ declare module "../src/routes/+404.marko" { export type Route = Run.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -219,6 +338,13 @@ declare module "../src/routes/+500.marko" { export type Route = globalThis.MarkoRun.Route; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/escape-path/__snapshots__/escape-path.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/escape-path/__snapshots__/escape-path.expected.routetypes.d.ts index 863c1c5d..428ee685 100644 --- a/packages/run/src/vite/__tests__/fixtures/escape-path/__snapshots__/escape-path.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/escape-path/__snapshots__/escape-path.expected.routetypes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/`a?b`/$`$id`/$foo/+page.marko" { export type Route = Run.Routes["/a%3fb/$`$id`/$foo"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/`a?b`/baz/+page.marko" { export type Route = Run.Routes["/a%3fb/baz"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routes.md b/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routes.md index 7220951f..0f5a4cbf 100644 --- a/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routes.md +++ b/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routes.md @@ -2,10 +2,10 @@ ## Middleware ```js -import { normalize } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler } from "virtual:marko-run/runtime/internal"; import middleware3 from "./src/routes/$id,a.d+middleware.marko"; -export const mware3 = normalize(middleware3); +export const mware3 = normalizeHandler(middleware3); ``` --- @@ -29,12 +29,12 @@ export function head1(context) { ### Path: ``/foo`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { GET, POST } from "./src/routes/foo,(a,b).(c,d)+handler.marko"; import page from "./src/routes/foo,$id,$$rest,+page.marko"; -const getHandler = normalize(GET); -const postHandler = normalize(POST); +const getHandler = normalizeHandler(GET); +const postHandler = normalizeHandler(POST); export function get2(context) { const __page = () => context.render(page, {}); @@ -88,11 +88,11 @@ export function head4(context) { ### Path: ``/a/c`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { GET, POST } from "./src/routes/foo,(a,b).(c,d)+handler.marko"; -const getHandler = normalize(GET); -const postHandler = normalize(POST); +const getHandler = normalizeHandler(GET); +const postHandler = normalizeHandler(POST); export function get5(context) { return call(getHandler, noContent, context); @@ -111,12 +111,12 @@ export function post5(context) { ### Path: ``/a/d`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware3 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET, POST } from "./src/routes/foo,(a,b).(c,d)+handler.marko"; -const getHandler = normalize(GET); -const postHandler = normalize(POST); +const getHandler = normalizeHandler(GET); +const postHandler = normalizeHandler(POST); export function get6(context) { const __getHandler = () => call(getHandler, noContent, context); @@ -137,11 +137,11 @@ export function post6(context) { ### Path: ``/b/c`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { GET, POST } from "./src/routes/foo,(a,b).(c,d)+handler.marko"; -const getHandler = normalize(GET); -const postHandler = normalize(POST); +const getHandler = normalizeHandler(GET); +const postHandler = normalizeHandler(POST); export function get7(context) { return call(getHandler, noContent, context); @@ -160,11 +160,11 @@ export function post7(context) { ### Path: ``/b/d`` ### Handler ```js -import { normalize, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { GET, POST } from "./src/routes/foo,(a,b).(c,d)+handler.marko"; -const getHandler = normalize(GET); -const postHandler = normalize(POST); +const getHandler = normalizeHandler(GET); +const postHandler = normalizeHandler(POST); export function get8(context) { return call(getHandler, noContent, context); diff --git a/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routetypes.d.ts index 5fdabcfb..0d5c443b 100644 --- a/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/flat-routes/__snapshots__/flat-routes.expected.routetypes.d.ts @@ -28,6 +28,13 @@ declare module "../src/routes/foo,(a,b).(c,d)+handler.marko" { export type Route = Run.Routes["/foo" | "/a/c" | "/a/d" | "/b/c" | "/b/d"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -39,6 +46,13 @@ declare module "../src/routes/$id,a.d+middleware.marko" { export type Route = Run.Routes["/$id" | "/a/d"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -50,6 +64,13 @@ declare module "../src/routes/foo,$id,$$rest,+page.marko" { export type Route = Run.Routes["/" | "/foo" | "/$id" | "/$$rest"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/force-class-api/__snapshots__/force-class-api.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/force-class-api/__snapshots__/force-class-api.expected.routetypes.d.ts index 52ce23c8..0de10630 100644 --- a/packages/run/src/vite/__tests__/fixtures/force-class-api/__snapshots__/force-class-api.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/force-class-api/__snapshots__/force-class-api.expected.routetypes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/force-tags-api/__snapshots__/force-tags-api.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/force-tags-api/__snapshots__/force-tags-api.expected.routetypes.d.ts index 52ce23c8..0de10630 100644 --- a/packages/run/src/vite/__tests__/fixtures/force-tags-api/__snapshots__/force-tags-api.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/force-tags-api/__snapshots__/force-tags-api.expected.routetypes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.router.js b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.router.js new file mode 100644 index 00000000..c912d4e3 --- /dev/null +++ b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.router.js @@ -0,0 +1,141 @@ +import { NotHandled, NotMatched, createContext } from "virtual:marko-run/runtime/internal"; +import { post1, post1_meta, put1, put1_meta, delete1, delete1_meta } from "virtual:marko-run/__marko-run__foo.bar.js"; +import { get2, get2_meta, head2, head2_meta, post2, post2_meta, put2, put2_meta, delete2, delete2_meta } from "virtual:marko-run/__marko-run__foo.baz.js"; + +globalThis.__marko_run__ = { match, fetch, invoke }; + +export function match(method, pathname) { + const last = pathname.length - 1; + return match_internal(method, last && pathname.charAt(last) === '/' ? pathname.slice(0, last) : pathname) +}; + +function match_internal(method, pathname) { + const len = pathname.length; + switch (method) { + case 'GET': + case 'get': { + if (len > 1) { + const i1 = pathname.indexOf('/', 1) + 1; + if (i1 && i1 !== len) { + if (pathname.slice(1, i1 - 1) === 'foo') { + const i2 = pathname.indexOf('/', 5) + 1; + if (!i2 || i2 === len) { + if (pathname.slice(5, i2 ? -1 : len) === 'baz') return { handler: get2, params: {}, meta: get2_meta, path: '/foo/baz' }; + } + } + } + } + return null; + } + case 'HEAD': + case 'head': { + if (len > 1) { + const i1 = pathname.indexOf('/', 1) + 1; + if (i1 && i1 !== len) { + if (pathname.slice(1, i1 - 1) === 'foo') { + const i2 = pathname.indexOf('/', 5) + 1; + if (!i2 || i2 === len) { + if (pathname.slice(5, i2 ? -1 : len) === 'baz') return { handler: head2, params: {}, meta: head2_meta, path: '/foo/baz' }; + } + } + } + } + return null; + } + case 'POST': + case 'post': { + if (len > 1) { + const i1 = pathname.indexOf('/', 1) + 1; + if (i1 && i1 !== len) { + if (pathname.slice(1, i1 - 1) === 'foo') { + const i2 = pathname.indexOf('/', 5) + 1; + if (!i2 || i2 === len) { + switch (pathname.slice(5, i2 ? -1 : len)) { + case 'bar': return { handler: post1, params: {}, meta: post1_meta, path: '/foo/bar' }; + case 'baz': return { handler: post2, params: {}, meta: post2_meta, path: '/foo/baz' }; + } + } + } + } + } + return null; + } + case 'PUT': + case 'put': { + if (len > 1) { + const i1 = pathname.indexOf('/', 1) + 1; + if (i1 && i1 !== len) { + if (pathname.slice(1, i1 - 1) === 'foo') { + const i2 = pathname.indexOf('/', 5) + 1; + if (!i2 || i2 === len) { + switch (pathname.slice(5, i2 ? -1 : len)) { + case 'bar': return { handler: put1, params: {}, meta: put1_meta, path: '/foo/bar' }; + case 'baz': return { handler: put2, params: {}, meta: put2_meta, path: '/foo/baz' }; + } + } + } + } + } + return null; + } + case 'DELETE': + case 'delete': { + if (len > 1) { + const i1 = pathname.indexOf('/', 1) + 1; + if (i1 && i1 !== len) { + if (pathname.slice(1, i1 - 1) === 'foo') { + const i2 = pathname.indexOf('/', 5) + 1; + if (!i2 || i2 === len) { + switch (pathname.slice(5, i2 ? -1 : len)) { + case 'bar': return { handler: delete1, params: {}, meta: delete1_meta, path: '/foo/bar' }; + case 'baz': return { handler: delete2, params: {}, meta: delete2_meta, path: '/foo/baz' }; + } + } + } + } + } + return null; + } + } + return null; +} + +export async function invoke(route, request, platform, url) { + const context = createContext(route, request, platform, url); + if (route) { + try { + const response = await route.handler(context); + if (response) return response; + } catch (error) { + if (error === NotHandled) return; + if (error !== NotMatched) throw error; + } + } + + return new Response(null, { + status: 404, + }); +} + +export async function fetch(request, platform) { + try { + const url = new URL(request.url); + const { pathname } = url; + const last = pathname.length - 1; + const hasTrailingSlash = last && pathname.charAt(last) === '/'; + const normalizedPathname = hasTrailingSlash ? pathname.slice(0, last) : pathname; + const route = match_internal(request.method, normalizedPathname); + if (route && hasTrailingSlash) { + url.pathname = normalizedPathname + return Response.redirect(url); + } + return await invoke(route, request, platform, url); + } catch (error) { + if (import.meta.env.DEV) { + throw error; + } + return new Response(null, { + status: 500 + }); + } +} \ No newline at end of file diff --git a/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routes.md b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routes.md new file mode 100644 index 00000000..eebb901d --- /dev/null +++ b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routes.md @@ -0,0 +1,64 @@ +# Routes + +## Route ``foo.bar`` +### Path: ``/foo/bar`` +### Handler +```js +import { normalizeHandler, normalizeMeta, call, noContent } from "virtual:marko-run/runtime/internal"; +import { PUT, POST, DELETE } from "./src/routes/foo/bar/+handler.ts"; +import meta1 from "./src/routes/foo/bar/+meta.ts"; + +const putHandler = normalizeHandler(PUT); +const postHandler = normalizeHandler(POST); +const deleteHandler = normalizeHandler(DELETE); + +export const { POST: post1_meta, PUT: put1_meta, DELETE: delete1_meta } = normalizeMeta(meta1); + +export function post1(context) { + return call(postHandler, noContent, context); +} + +export function put1(context) { + return call(putHandler, noContent, context); +} + +export function delete1(context) { + return call(deleteHandler, noContent, context); +} +``` +--- +## Route ``foo.baz`` +### Path: ``/foo/baz`` +### Handler +```js +import { normalizeHandler, normalizeMeta, call, noContent, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { PUT, POST, DELETE } from "./src/routes/foo/baz/+handler.ts"; +import page from "./src/routes/foo/baz/+page.marko"; +import meta2 from "./src/routes/foo/baz/+meta.json"; + +const putHandler = normalizeHandler(PUT); +const postHandler = normalizeHandler(POST); +const deleteHandler = normalizeHandler(DELETE); + +export const { GET: get2_meta, GET: head2_meta, POST: post2_meta, PUT: put2_meta, DELETE: delete2_meta } = normalizeMeta(meta2); + +export function get2(context) { + return context.render(page, {}); +} + +export function head2(context) { + return stripResponseBody(get2(context)); +} + +export function post2(context) { + return call(postHandler, noContent, context); +} + +export function put2(context) { + return call(putHandler, noContent, context); +} + +export function delete2(context) { + return call(deleteHandler, noContent, context); +} +``` diff --git a/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routetypes.d.ts new file mode 100644 index 00000000..7a563d5a --- /dev/null +++ b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/__snapshots__/meta-files-with-verbs.expected.routetypes.d.ts @@ -0,0 +1,71 @@ +/* + WARNING: This file is automatically generated and any changes made to it will be overwritten without warning. + Do NOT manually edit this file or your changes will be lost. +*/ + +import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace"; +import type * as Run from "@marko/run"; + + +declare module "@marko/run" { + interface AppData extends Run.DefineApp<{ + routes: { + "/foo/bar": { verb: "post"; meta: typeof import("../src/routes/foo/bar/+meta")["default"]; }; + "/foo/baz": { verb: "get" | "post"; meta: typeof import("../src/routes/foo/baz/+meta.json"); }; + } + }> {} +} + +declare module "../src/routes/foo/bar/+handler" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/foo/bar"]; + export type Context = Run.MultiRouteContext; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} + +declare module "../src/routes/foo/baz/+handler" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/foo/baz"]; + export type Context = Run.MultiRouteContext; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} + +declare module "../src/routes/foo/baz/+page.marko" { + namespace MarkoRun { + export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform }; + export type Route = Run.Routes["/foo/baz"]; + export type Context = Run.MultiRouteContext & Marko.Global; + export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; + /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ + export const route: Run.HandlerTypeFn; + } +} diff --git a/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/routes.txt b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/routes.txt new file mode 100644 index 00000000..a4e91ef0 --- /dev/null +++ b/packages/run/src/vite/__tests__/fixtures/meta-files-with-verbs/routes.txt @@ -0,0 +1,8 @@ +/foo + /bar + +handler.ts { "verbs": ["put", "post", "delete"] } + +meta.ts + /baz + +handler.ts { "verbs": ["put", "post", "delete"] } + +page.marko + +meta.json \ No newline at end of file diff --git a/packages/run/src/vite/__tests__/fixtures/multiple-sources/__snapshots__/multiple-sources.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/multiple-sources/__snapshots__/multiple-sources.expected.routetypes.d.ts index 30e72d9c..7e59ae70 100644 --- a/packages/run/src/vite/__tests__/fixtures/multiple-sources/__snapshots__/multiple-sources.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/multiple-sources/__snapshots__/multiple-sources.expected.routetypes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -33,6 +40,13 @@ declare module "../src/routes/+page.marko" { export type Route = Run.Routes["/+routes"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/nested-dynamic/__snapshots__/nested-dynamic.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/nested-dynamic/__snapshots__/nested-dynamic.expected.routetypes.d.ts index 25bdae9c..e5cd2ebc 100644 --- a/packages/run/src/vite/__tests__/fixtures/nested-dynamic/__snapshots__/nested-dynamic.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/nested-dynamic/__snapshots__/nested-dynamic.expected.routetypes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/foo/$fooId/bar/$bar_Id/baz/$1bazId/$qux-Id/+page.m export type Route = Run.Routes["/foo/$fooId/bar/$bar_Id/baz/$1bazId/$qux-Id"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/optional-dynamic/__snapshots__/optional-dynamic.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/optional-dynamic/__snapshots__/optional-dynamic.expected.routetypes.d.ts index 094b48cd..badb9847 100644 --- a/packages/run/src/vite/__tests__/fixtures/optional-dynamic/__snapshots__/optional-dynamic.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/optional-dynamic/__snapshots__/optional-dynamic.expected.routetypes.d.ts @@ -24,6 +24,13 @@ declare module "../src/routes/$foo,/$bar,$$rest/+page.marko" { export type Route = Run.Routes["/$foo/$bar" | "/$foo/$$rest" | "/$bar" | "/$$rest"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/optional-static/__snapshots__/optional-static.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/optional-static/__snapshots__/optional-static.expected.routetypes.d.ts index 16d63300..874a221e 100644 --- a/packages/run/src/vite/__tests__/fixtures/optional-static/__snapshots__/optional-static.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/optional-static/__snapshots__/optional-static.expected.routetypes.d.ts @@ -28,6 +28,13 @@ declare module "../src/routes/foo,/bar,/,baz/+page.marko" { export type Route = Run.Routes["/" | "/foo" | "/foo/bar" | "/foo/bar/baz" | "/foo/baz" | "/bar" | "/bar/baz" | "/baz"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routes.md b/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routes.md index e602c2b8..2a93f7f2 100644 --- a/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routes.md +++ b/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routes.md @@ -2,10 +2,10 @@ ## Middleware ```js -import { normalize } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler } from "virtual:marko-run/runtime/internal"; import middleware2 from "./src/routes/+middleware.ts"; -export const mware2 = normalize(middleware2); +export const mware2 = normalizeHandler(middleware2); ``` --- @@ -22,12 +22,12 @@ import Page from "../../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+page.marko" ``` ### Handler ```js -import { normalize, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware2 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+handler.ts"; import page from "./dist/.marko-run/aaa.$.marko"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get1(context) { const __page = () => context.render(page, {}); @@ -53,12 +53,12 @@ import Page from "../../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+page.marko" ``` ### Handler ```js -import { normalize, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware2 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+handler.ts"; import page from "./dist/.marko-run/aaa.$.bbb.$.marko"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get2(context) { const __page = () => context.render(page, {}); @@ -84,12 +84,12 @@ import Page from "../../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+page.marko" ``` ### Handler ```js -import { normalize, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware2 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+handler.ts"; import page from "./dist/.marko-run/aaa.$.bbb.$.ccc.$.marko"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get3(context) { const __page = () => context.render(page, {}); @@ -115,12 +115,12 @@ import Page from "../../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+page.marko" ``` ### Handler ```js -import { normalize, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; +import { normalizeHandler, call, stripResponseBody } from "virtual:marko-run/runtime/internal"; import { mware2 } from "virtual:marko-run/__marko-run__middleware.js"; import { GET } from "./src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+handler.ts"; import page from "./dist/.marko-run/aaa.$.ccc.$.marko"; -const getHandler = normalize(GET); +const getHandler = normalizeHandler(GET); export function get4(context) { const __page = () => context.render(page, {}); diff --git a/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routetypes.d.ts index c505645e..5e93b27b 100644 --- a/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/optional-types/__snapshots__/optional-types.expected.routetypes.d.ts @@ -24,6 +24,13 @@ declare module "../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+handler" { export type Route = Run.Routes["/aaa/$aId" | "/aaa/$aId/bbb/$bId" | "/aaa/$aId/bbb/$bId/ccc/$cId" | "/aaa/$aId/ccc/$cId"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -35,6 +42,13 @@ declare module "../src/routes/+middleware" { export type Route = Run.Routes["/aaa/$aId" | "/aaa/$aId/bbb/$bId" | "/aaa/$aId/bbb/$bId/ccc/$cId" | "/aaa/$aId/ccc/$cId"]; export type Context = Run.MultiRouteContext; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -46,6 +60,13 @@ declare module "../src/routes/aaa.$aId.(,bbb.$bId).(,ccc.$cId)/+page.marko" { export type Route = Run.Routes["/aaa/$aId" | "/aaa/$aId/bbb/$bId" | "/aaa/$aId/bbb/$bId/ccc/$cId" | "/aaa/$aId/ccc/$cId"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } @@ -58,6 +79,13 @@ declare module "../src/routes/+layout.marko" { export type Route = Run.Routes["/aaa/$aId" | "/aaa/$aId/bbb/$bId" | "/aaa/$aId/bbb/$bId/ccc/$cId" | "/aaa/$aId/ccc/$cId"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/param-optional-rest/__snapshots__/param-optional-rest.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/param-optional-rest/__snapshots__/param-optional-rest.expected.routetypes.d.ts index a540e075..ac876204 100644 --- a/packages/run/src/vite/__tests__/fixtures/param-optional-rest/__snapshots__/param-optional-rest.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/param-optional-rest/__snapshots__/param-optional-rest.expected.routetypes.d.ts @@ -22,6 +22,13 @@ declare module "../src/routes/$campaignId/$$rest,/+page.marko" { export type Route = Run.Routes["/$campaignId" | "/$campaignId/$$rest"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/__tests__/fixtures/uri-encoded/__snapshots__/uri-encoded.expected.routetypes.d.ts b/packages/run/src/vite/__tests__/fixtures/uri-encoded/__snapshots__/uri-encoded.expected.routetypes.d.ts index 5b00af27..de62e88f 100644 --- a/packages/run/src/vite/__tests__/fixtures/uri-encoded/__snapshots__/uri-encoded.expected.routetypes.d.ts +++ b/packages/run/src/vite/__tests__/fixtures/uri-encoded/__snapshots__/uri-encoded.expected.routetypes.d.ts @@ -21,6 +21,13 @@ declare module "../src/routes/a%2Fb?c#d+e:f%26g/$%24id/+page.marko" { export type Route = Run.Routes["/a%2fb%3fc%23d+e:f&g/$`$id`"]; export type Context = Run.MultiRouteContext & Marko.Global; export type Handler = Run.HandlerLike; + export type GET = Run.HandlerLike; + export type HEAD = Run.HandlerLike; + export type POST = Run.HandlerLike; + export type PUT = Run.HandlerLike; + export type DELETE = Run.HandlerLike; + export type PATCH = Run.HandlerLike; + export type OPTIONS = Run.HandlerLike; /** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */ export const route: Run.HandlerTypeFn; } diff --git a/packages/run/src/vite/codegen/index.ts b/packages/run/src/vite/codegen/index.ts index 93b6aca6..8d1929a3 100644 --- a/packages/run/src/vite/codegen/index.ts +++ b/packages/run/src/vite/codegen/index.ts @@ -99,10 +99,13 @@ export function renderRouteEntry(route: Route, rootDir: string): string { const writer = createStringWriter(); const imports = writer.branch("imports"); - const runtimeImports = []; + const runtimeImports: string[] = []; if (handler) { - runtimeImports.push("normalize"); + runtimeImports.push("normalizeHandler"); + } + if (meta) { + runtimeImports.push("normalizeMeta"); } if (handler || middleware.length) { runtimeImports.push("call"); @@ -138,7 +141,9 @@ export function renderRouteEntry(route: Route, rootDir: string): string { for (const verb of handler.verbs) { const importName = verb.toUpperCase(); names.push(importName); - writer.writeLines(`const ${verb}Handler = normalize(${importName});`); + writer.writeLines( + `const ${verb}Handler = normalizeHandler(${importName});`, + ); } imports.writeLines( `import { ${names.join(", ")} } from "${normalizedRelativePath(rootDir, handler.filePath)}";`, @@ -151,8 +156,23 @@ export function renderRouteEntry(route: Route, rootDir: string): string { ); } if (meta) { + const metaName = `meta${index}`; + const metaVerbsExports = verbs + .map((verb) => { + const name = + verb === "head" && !handler?.verbs?.includes(verb) + ? "GET" + : verb.toUpperCase(); + return `${name}: ${verb}${index}_meta`; + }) + .join(", "); + + writer.writeLines(""); imports.writeLines( - `export { default as meta${index} } from "${normalizedRelativePath(rootDir, meta.filePath)}";`, + `import ${metaName} from "${normalizedRelativePath(rootDir, meta.filePath)}";`, + ); + writer.writeLines( + `export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`, ); } @@ -299,11 +319,16 @@ export function renderRouter( for (const route of routes.list) { const verbs = getVerbs(route); - const names = verbs.map((verb) => `${verb}${route.index}`); - route.meta && names.push(`meta${route.index}`); - + const routeImports: string[] = []; + for (const verb of verbs) { + const verbName = `${verb}${route.index}`; + routeImports.push(verbName); + if (route.meta) { + routeImports.push(`${verbName}_meta`); + } + } imports.writeLines( - `import { ${names.join(", ")} } from "${virtualFilePrefix}/${getRouteVirtualFileName(route)}";`, + `import { ${routeImports.join(", ")} } from "${virtualFilePrefix}/${getRouteVirtualFileName(route)}";`, ); } for (const route of Object.values(routes.special) as Route[]) { @@ -680,7 +705,7 @@ function renderMatch( ) { const handler = `${verb}${route.index}`; const params = path.params ? renderParams(path.params, pathIndex) : "{}"; - const meta = route.meta ? `meta${route.index}` : "{}"; + const meta = route.meta ? `${verb}${route.index}_meta` : "{}"; return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path.path}' }`; } @@ -691,7 +716,7 @@ export function renderMiddleware( const writer = createStringWriter(); const imports = writer.branch("imports"); imports.writeLines( - `import { normalize } from "${virtualFilePrefix}/runtime/internal";`, + `import { normalizeHandler } from "${virtualFilePrefix}/runtime/internal";`, ); writer.writeLines(""); @@ -701,7 +726,9 @@ export function renderMiddleware( imports.writeLines( `import ${importName} from "${normalizedRelativePath(rootDir, filePath)}";`, ); - writer.writeLines(`export const mware${id} = normalize(${importName});`); + writer.writeLines( + `export const mware${id} = normalizeHandler(${importName});`, + ); } imports.join(); @@ -900,7 +927,12 @@ function writeModuleDeclaration( export type Context = Run.MultiRouteContext${ isMarko ? " & Marko.Global" : "" }; - export type Handler = Run.HandlerLike; + export type Handler = Run.HandlerLike;`); + for (const verb of httpVerbs) { + writer.write(` + export type ${verb.toUpperCase()} = Run.HandlerLike;`); + } + writer.write(` /** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */ export const route: Run.HandlerTypeFn; }`); diff --git a/packages/run/src/vite/index.ts b/packages/run/src/vite/index.ts index ea086358..843a2379 100644 --- a/packages/run/src/vite/index.ts +++ b/packages/run/src/vite/index.ts @@ -14,12 +14,13 @@ export type { Route, RouteGenerationData, } from "./types"; -export type { SpawnedServer } from "./utils/server"; +export { getMetaDataForVerb } from "./utils/meta-data"; export { getAvailablePort, isPortInUse, loadEnv, parseEnv, + type SpawnedServer, spawnServer, spawnServerWorker, } from "./utils/server"; diff --git a/packages/run/src/vite/utils/meta-data.ts b/packages/run/src/vite/utils/meta-data.ts new file mode 100644 index 00000000..0833ecee --- /dev/null +++ b/packages/run/src/vite/utils/meta-data.ts @@ -0,0 +1,43 @@ +import { + NormalizedMeta, + NormalizedMetaLookup, + Verb, +} from "../../runtime/types"; +import { httpVerbs } from "../constants"; + +const verbKeys = new Set(httpVerbs.map((v) => v.toUpperCase() as Verb)); + +function isObject(obj: any): obj is Record { + return obj && typeof obj === "object" && !Array.isArray(obj); +} + +export function getMetaDataForVerb( + data: T, + verb: TVerb, +): NormalizedMeta { + if (!httpVerbs.includes(verb.toLowerCase() as any)) { + throw new Error( + `Invalid argument 'verb': expected one of ${[...verbKeys].join(", ")} but received ${verb}`, + ); + } + if (isObject(data)) { + return Object.keys(data).reduce( + (result, key) => { + if (!(key in result || verbKeys.has(key as Verb))) { + result[key] = data[key]; + } + return result; + }, + isObject(data[verb]) ? { ...data[verb] } : ({} as any), + ); + } + return data as any; +} + +export function getMetaDataLookup(data: T): NormalizedMetaLookup { + const lookup = {} as any; + for (const verb of verbKeys) { + lookup[verb] = getMetaDataForVerb(data, verb); + } + return lookup; +}