primate 0.29.1 → 0.29.2
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/package.json +1 -1
- package/src/errors.json +3 -3
- package/src/handlers.js +6 -5
- package/src/loaders/routes/routes.js +2 -0
- package/types/index.d.ts +29 -68
package/package.json
CHANGED
package/src/errors.json
CHANGED
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
"fix": "add configuration options or remove file",
|
|
92
92
|
"level": "Warn"
|
|
93
93
|
},
|
|
94
|
-
"
|
|
95
|
-
"message": "no handler for {0}
|
|
96
|
-
"fix": "add handler module for
|
|
94
|
+
"NoHandlerForComponent": {
|
|
95
|
+
"message": "no handler for {0}",
|
|
96
|
+
"fix": "add handler module for this component or remove {0}",
|
|
97
97
|
"level": "Error"
|
|
98
98
|
},
|
|
99
99
|
"NoRouteToPath": {
|
package/src/handlers.js
CHANGED
|
@@ -67,11 +67,12 @@ const html = (name, options) => async app => {
|
|
|
67
67
|
};
|
|
68
68
|
// }}}
|
|
69
69
|
// {{{ view
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const extensions = ["fullExtension", "extension"];
|
|
71
|
+
const view = (name, props, options) => (app, ...rest) => extensions
|
|
72
|
+
.map(extension => app.extensions[new File(name)[extension]])
|
|
73
|
+
.find(extension => extension?.handle)
|
|
74
|
+
?.handle(name, props, options)(app, ...rest)
|
|
75
|
+
?? errors.NoHandlerForComponent.throw(name);
|
|
75
76
|
// }}}
|
|
76
77
|
|
|
77
78
|
export { text, json, stream, redirect, error, html, view, ws, sse };
|
|
@@ -3,6 +3,8 @@ import errors from "../../errors.js";
|
|
|
3
3
|
|
|
4
4
|
const normalize = route => {
|
|
5
5
|
let i = 0;
|
|
6
|
+
// user/ -> user
|
|
7
|
+
// user/{id=number}/{id2=number} -> user/{0}/{1}
|
|
6
8
|
return (route.endsWith("/") ? route.slice(0, -1) : route)
|
|
7
9
|
.replaceAll(/\{(?:\w*)(?:=\w+)?\}?/gu, _ => `{${i++}}`);
|
|
8
10
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -1,69 +1,30 @@
|
|
|
1
|
-
declare module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type ResponseFn = (app: App, ...rest: any) => Response;
|
|
31
|
-
type ResponseFacade =
|
|
32
|
-
string
|
|
33
|
-
| object
|
|
34
|
-
| URL
|
|
35
|
-
| Blob
|
|
36
|
-
| ReadableStream
|
|
37
|
-
| Response
|
|
38
|
-
| ResponseFn;
|
|
39
|
-
|
|
40
|
-
type RouteFunction = (request?: RequestFacade) => ResponseFacade;
|
|
41
|
-
|
|
42
|
-
type Streamable = ReadableStream | Blob;
|
|
43
|
-
|
|
44
|
-
export type Route = {
|
|
45
|
-
get?: RouteFunction,
|
|
46
|
-
post?: RouteFunction,
|
|
47
|
-
put?: RouteFunction,
|
|
48
|
-
delete?: RouteFunction,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export function text(body: string, options?: MinOptions): ResponseFn;
|
|
52
|
-
|
|
53
|
-
export function json(body: {}, options?: MinOptions): ResponseFn;
|
|
54
|
-
|
|
55
|
-
export function stream(body: Streamable, options?: MinOptions): ResponseFn;
|
|
56
|
-
|
|
57
|
-
export function redirect(location: string, options?: MinOptions): ResponseFn;
|
|
58
|
-
|
|
59
|
-
export function html(name: string, options?: MinOptions): ResponseFn;
|
|
60
|
-
|
|
61
|
-
export function view(name: string, props: {}, options?: Options): ResponseFn;
|
|
62
|
-
|
|
63
|
-
export function error(body: string, options?: ErrorOptions): ResponseFn;
|
|
64
|
-
|
|
65
|
-
export function sse(implementation: {
|
|
66
|
-
open?: () => void,
|
|
67
|
-
close?: () => void,
|
|
68
|
-
}, options?: MinOptions): ResponseFn;
|
|
1
|
+
declare module 'primate' {
|
|
2
|
+
function _default(command: any): Promise<any>;
|
|
3
|
+
export default _default;
|
|
4
|
+
export function text(body: any, options: any): (app: any) => any;
|
|
5
|
+
export function json(body: any, options: any): (app: any) => any;
|
|
6
|
+
export function stream(body: any, options: any): (app: any) => any;
|
|
7
|
+
export function redirect(Location: any, { status }?: {
|
|
8
|
+
status?: any;
|
|
9
|
+
}): (app: any) => any;
|
|
10
|
+
export function error(body?: string, { status, page }?: {
|
|
11
|
+
status?: any;
|
|
12
|
+
page: any;
|
|
13
|
+
}): (app: any) => any;
|
|
14
|
+
export function html(name: any, options: any): (app: any) => Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Render a component using handler for the given filename extension.
|
|
17
|
+
* @param name component filename
|
|
18
|
+
* @param props props passed to component
|
|
19
|
+
* @param options rendering options
|
|
20
|
+
*/
|
|
21
|
+
export function view(name: string, props: object, options: object): (app: any, ...rest: any[]) => Promise<any>;
|
|
22
|
+
export function ws(implementation: any): ({ server }: {
|
|
23
|
+
server: any;
|
|
24
|
+
}, _: any, { original }: {
|
|
25
|
+
original: any;
|
|
26
|
+
}) => any;
|
|
27
|
+
export function sse(body: any, options: any): (app: any) => any;
|
|
69
28
|
}
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|