@marko/run 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapter/dev-server.d.ts +1 -1
- package/dist/adapter/index.cjs +10 -9
- package/dist/adapter/index.js +16 -15
- package/dist/cli/index.mjs +61 -23
- package/dist/runtime/index.d.ts +13 -3
- package/dist/runtime/internal.cjs +49 -3
- package/dist/runtime/internal.d.ts +2 -1
- package/dist/runtime/internal.js +47 -2
- package/dist/runtime/namespace.d.ts +1 -1
- package/dist/runtime/types.d.ts +24 -18
- package/dist/vite/index.cjs +85 -20
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +85 -21
- package/dist/vite/utils/meta-data.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/marko-js/run/raw/main/assets/marko-run-
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/marko-js/run/raw/main/assets/marko-run-dark.png">
|
|
4
4
|
<source media="(prefers-color-scheme: light)" srcset="https://github.com/marko-js/run/raw/main/assets/marko-run.png">
|
|
5
5
|
<img alt="Marko Run Logo" src="https://github.com/marko-js/run/raw/main/assets/marko-run.png" width="400">
|
|
6
6
|
</picture>
|
|
@@ -102,7 +102,7 @@ export default defineConfig({
|
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
###
|
|
105
|
+
### Routable Files
|
|
106
106
|
|
|
107
107
|
The router only recognizes certain filenames which are all prefixed with `+` ([Why?](#What-about-markoserve)). The following filenames will be discovered in any directory inside your application’s [routes directory](#routes-directory).
|
|
108
108
|
|
|
@@ -133,7 +133,7 @@ Typically, these will be `.js` or `.ts` files depending on your project. Like pa
|
|
|
133
133
|
<details>
|
|
134
134
|
<summary>More Info</summary>
|
|
135
135
|
|
|
136
|
-
- Valid exports are functions named `GET`, `POST`, `PUT`,
|
|
136
|
+
- Valid exports are functions named `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `PATCH`, `OPTIONS`.
|
|
137
137
|
- Exports can be one of the following
|
|
138
138
|
- Handler function (see below)
|
|
139
139
|
- 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
|
|
|
207
207
|
|
|
208
208
|
#### `+meta.*`
|
|
209
209
|
|
|
210
|
-
These files represent static metadata to attach to the route. This metadata will be automatically provided on the route `context` when invoking a route.
|
|
210
|
+
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.
|
|
211
|
+
|
|
212
|
+
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 excluded from the base object and ignored if not an object. For example given a `+meta.json` file:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"name": "Default Name",
|
|
217
|
+
"POST": {
|
|
218
|
+
"name": "Post Name",
|
|
219
|
+
"postOnlyData": "foo"
|
|
220
|
+
},
|
|
221
|
+
"GET": {
|
|
222
|
+
"name": "Get Name"
|
|
223
|
+
},
|
|
224
|
+
"PUT": "Ignored"
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
when making a POST request the value of `context.meta` will be
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
{
|
|
232
|
+
name: "Post Name",
|
|
233
|
+
portOnlyData: "foo"
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
and the value for a GET request will be
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
{
|
|
241
|
+
name: "Get Name";
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
all other methods, including PUT, will be the base object
|
|
246
|
+
|
|
247
|
+
```js
|
|
248
|
+
{
|
|
249
|
+
name: "Default Name";
|
|
250
|
+
}
|
|
251
|
+
```
|
|
211
252
|
|
|
212
253
|
### Special Files
|
|
213
254
|
|
|
@@ -322,9 +363,9 @@ Within the [routes directory](#routes-directory), the directory structure determ
|
|
|
322
363
|
|
|
323
364
|
### Flat Routes
|
|
324
365
|
|
|
325
|
-
Flat routes let you define paths without needing additional folders. Instead the folder structure can be defined either in the file or folder name. This allows you to decouple your routes from your folder structure or co-locate them as needed. To define a flat route, use periods (`.`) to
|
|
366
|
+
Flat routes let you define paths without needing additional folders. Instead the folder structure can be defined either in the file or folder name. This allows you to decouple your routes from your folder structure or co-locate them as needed. To define a flat route, use periods (`.`) to delineate each path segment. This behaves exactly like creating a new folder and each segment will be parsed using the rules described above for static, dynamic and pathless routes.
|
|
326
367
|
|
|
327
|
-
Flat routes syntax can be used for both directories and routable files (eg. pages, handlers, middleware, etc.). For these files, anything
|
|
368
|
+
Flat routes syntax can be used for both directories and routable files (eg. pages, handlers, middleware, etc.). For these files, anything preceding the plus (`+`) will be treated as the flat route.
|
|
328
369
|
|
|
329
370
|
For example to define a page at `/projects/$projectId/members` with a root layout and a project layout:
|
|
330
371
|
|
|
@@ -371,7 +412,7 @@ routes/
|
|
|
371
412
|
|
|
372
413
|
### Multiple Paths, Groups and Optional Segments
|
|
373
414
|
|
|
374
|
-
Along with
|
|
415
|
+
Along with describing multiple segments, flat route syntax supports defining routes that match more than one path and segments that are optional. To describe a route that matches multiple paths, use a comma (`,`) and define each route.
|
|
375
416
|
|
|
376
417
|
For example the following page matches `/projects/$projectId/members` and `/projects/$projectId/people`
|
|
377
418
|
|
|
@@ -397,7 +438,7 @@ routes/
|
|
|
397
438
|
|
|
398
439
|
This is a simple example of grouping but you can nest groups and make them as complicated as you want.
|
|
399
440
|
|
|
400
|
-
The last concept is **
|
|
441
|
+
The last concept is **optionality**. By introducing an empty segment or pathless segment along with another value you can make that segment optional. For example, If we want a page that matches `/projects` and `/projects/home`, you can create a flat route that optionally matches `home`
|
|
401
442
|
|
|
402
443
|
```
|
|
403
444
|
routes/
|
|
@@ -411,7 +452,7 @@ routes/
|
|
|
411
452
|
projects.(home,_pathless)+page.marko
|
|
412
453
|
```
|
|
413
454
|
|
|
414
|
-
While both of these create a route which matches the paths, they have slightly different semantics. Using a pathless segment is the same as creating a pathless folder which allows you to isolate middleware and
|
|
455
|
+
While both of these create a route which matches the paths, they have slightly different semantics. Using a pathless segment is the same as creating a pathless folder which allows you to isolate middleware and layouts. Using an empty segment is the same as defining a file at the current location.
|
|
415
456
|
|
|
416
457
|
### Escaping Control Characters
|
|
417
458
|
|
|
@@ -496,7 +537,7 @@ import * as Run from '@marko/run/router`;
|
|
|
496
537
|
|
|
497
538
|
### Context
|
|
498
539
|
|
|
499
|
-
Context is passed to `middleware` and `handler` functions as the first
|
|
540
|
+
Context is passed to `middleware` and `handler` functions as the first parameter and is available in Marko templates as `$global`. The context object contains information about the current request with the following properties
|
|
500
541
|
|
|
501
542
|
- `route` - A string identifying the current route
|
|
502
543
|
- `request` - Current WHATWG Request instance
|
|
@@ -538,7 +579,7 @@ back(fallback?: string | URL, status?: number): Response;
|
|
|
538
579
|
|
|
539
580
|
Creates a redirect response that uses the current request referer or an optional fallback.
|
|
540
581
|
|
|
541
|
-
###
|
|
582
|
+
### Embedding in Existing Server
|
|
542
583
|
|
|
543
584
|
### `Run.fetch`
|
|
544
585
|
|
|
@@ -651,14 +692,28 @@ express()
|
|
|
651
692
|
|
|
652
693
|
**`MarkoRun.Handler`** - Type that represents a handler function to be exported by a +handler or +middleware file
|
|
653
694
|
|
|
695
|
+
**`MarkoRun.GET`** - Handler type narrowed to GET requests
|
|
696
|
+
|
|
697
|
+
**`MarkoRun.HEAD`** - Handler type narrowed to HEAD requests
|
|
698
|
+
|
|
699
|
+
**`MarkoRun.POST`** - Handler type narrowed to POST requests
|
|
700
|
+
|
|
701
|
+
**`MarkoRun.PUT`** - Handler type narrowed to PUT requests
|
|
702
|
+
|
|
703
|
+
**`MarkoRun.DELETE`** - Handler type narrowed to DELETE requests
|
|
704
|
+
|
|
705
|
+
**`MarkoRun.PATCH`** - Handler type narrowed to PATCH requests
|
|
706
|
+
|
|
707
|
+
**`MarkoRun.OPTIONS`** - Handler type narrowed to OPTIONS requests
|
|
708
|
+
|
|
654
709
|
**`MarkoRun.Route`** - Type of the route's params and metadata
|
|
655
710
|
|
|
656
|
-
**`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
|
|
711
|
+
**`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 application code
|
|
657
712
|
|
|
658
713
|
```ts
|
|
659
714
|
declare module "@marko/run" {
|
|
660
715
|
interface Context {
|
|
661
|
-
|
|
716
|
+
customProperty: MyCustomThing; // will be globally defined on MarkoRun.Context
|
|
662
717
|
}
|
|
663
718
|
}
|
|
664
719
|
```
|
|
@@ -668,7 +723,7 @@ declare module "@marko/run" {
|
|
|
668
723
|
```ts
|
|
669
724
|
declare module "@marko/run" {
|
|
670
725
|
interface Platform {
|
|
671
|
-
|
|
726
|
+
customProperty: MyCustomThing; // will be globally defined on MarkoRun.Platform
|
|
672
727
|
}
|
|
673
728
|
}
|
|
674
729
|
```
|