Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wide-moose-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/run": patch
---

Support verb-specific overrides for JSON and object meta data
59 changes: 57 additions & 2 deletions packages/run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Typically, these will be `.js` or `.ts` files depending on your project. Like pa
<details>
<summary>More Info</summary>

- 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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route>;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+404.marko" {
export type Route = Run.Route;
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route>;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -44,6 +58,13 @@ declare module "../src/routes/+layout.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -58,6 +79,13 @@ declare module "../src/routes/+500.marko" {
export type Route = globalThis.MarkoRun.Route;
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -33,6 +40,13 @@ declare module "../src/routes/foo/$id/+page.marko" {
export type Route = Run.Routes["/foo/$id"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -45,6 +59,13 @@ declare module "../src/routes/+layout.marko" {
export type Route = Run.Routes["/" | "/foo/$id"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+middleware" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route>;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+handler" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route>;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -33,6 +40,13 @@ declare module "../src/routes/+layout.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ declare module "../src/routes/+middleware" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route>;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand All @@ -32,6 +39,13 @@ declare module "../src/routes/+page.marko" {
export type Route = Run.Routes["/"];
export type Context = Run.MultiRouteContext<Route> & Marko.Global;
export type Handler = Run.HandlerLike<Route>;
export type GET = Run.HandlerLike<Route, "GET">;
export type HEAD = Run.HandlerLike<Route, "HEAD">;
export type POST = Run.HandlerLike<Route, "POST">;
export type PUT = Run.HandlerLike<Route, "PUT">;
export type DELETE = Run.HandlerLike<Route, "DELETE">;
export type PATCH = Run.HandlerLike<Route, "PATCH">;
export type OPTIONS = Run.HandlerLike<Route, "OPTIONS">;
/** @deprecated use `((context, next) => { ... }) satisfies MarkoRun.Handler` instead */
export const route: Run.HandlerTypeFn<Route>;
}
Expand Down
Loading