primate 0.32.3 → 0.32.5
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 +4 -4
- package/src/public/loader.js +10 -6
- package/types/index.d.ts +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.5",
|
|
4
4
|
"description": "Polymorphic development platform",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"@rcompat/args": "^0.3.0",
|
|
21
21
|
"@rcompat/async": "^0.3.0",
|
|
22
22
|
"@rcompat/cli": "^0.5.1",
|
|
23
|
-
"@rcompat/fs": "^0.
|
|
24
|
-
"@rcompat/package": "^0.
|
|
25
|
-
"@primate/core": "^0.1.
|
|
23
|
+
"@rcompat/fs": "^0.7.0",
|
|
24
|
+
"@rcompat/package": "^0.8.0",
|
|
25
|
+
"@primate/core": "^0.1.9"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=18"
|
package/src/public/loader.js
CHANGED
|
@@ -5,6 +5,7 @@ export default ({
|
|
|
5
5
|
pages_app,
|
|
6
6
|
pages,
|
|
7
7
|
rootfile,
|
|
8
|
+
static_root,
|
|
8
9
|
}) => {
|
|
9
10
|
const buildroot = file(rootfile).join("..");
|
|
10
11
|
|
|
@@ -13,13 +14,16 @@ export default ({
|
|
|
13
14
|
return pages[name] ?? pages[pages_app];
|
|
14
15
|
},
|
|
15
16
|
async asset(pathname) {
|
|
16
|
-
const
|
|
17
|
-
if (await
|
|
18
|
-
return serve_asset(
|
|
17
|
+
const client_file = buildroot.join(`client/${pathname}`);
|
|
18
|
+
if (await client_file.isFile()) {
|
|
19
|
+
return serve_asset(client_file);
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (pathname.startsWith(static_root)) {
|
|
22
|
+
const assetname = pathname.slice(static_root.length);
|
|
23
|
+
const static_file = buildroot.join(`server/static/${assetname}`);
|
|
24
|
+
if (await static_file.isFile()) {
|
|
25
|
+
return serve_asset(static_file);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
type RouteFunction = (request?: RequestFacade) => ResponseFacade;
|
|
2
|
+
|
|
3
|
+
type App = any;
|
|
4
|
+
|
|
5
|
+
interface MinOptions {
|
|
6
|
+
status: number,
|
|
7
|
+
headers: Headers | {},
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ErrorOptions extends MinOptions {
|
|
11
|
+
page: string,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Options extends ErrorOptions {
|
|
15
|
+
placeholders: {},
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Dispatcher = {
|
|
19
|
+
get(property: string): string,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type RequestFacade = {
|
|
23
|
+
body: {}
|
|
24
|
+
path: Dispatcher,
|
|
25
|
+
query: Dispatcher,
|
|
26
|
+
cookies: Dispatcher,
|
|
27
|
+
headers: Dispatcher,
|
|
28
|
+
original: Request,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ResponseFn = (app: App, ...rest: any) => Response;
|
|
32
|
+
type ResponseFacade =
|
|
33
|
+
string
|
|
34
|
+
| object
|
|
35
|
+
| URL
|
|
36
|
+
| Blob
|
|
37
|
+
| ReadableStream
|
|
38
|
+
| Response
|
|
39
|
+
| ResponseFn;
|
|
40
|
+
|
|
41
|
+
type Streamable = ReadableStream | Blob;
|
|
42
|
+
|
|
43
|
+
declare module "primate" {
|
|
44
|
+
export type Route = {
|
|
45
|
+
get?: RouteFunction,
|
|
46
|
+
post?: RouteFunction,
|
|
47
|
+
put?: RouteFunction,
|
|
48
|
+
delete?: RouteFunction,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare module "primate/handler/error" {
|
|
53
|
+
export default function(body: string, options?: ErrorOptions): ResponseFn;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module "primate/handler/json" {
|
|
57
|
+
export default function(body: {}, options?: MinOptions): ResponseFn;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare module "primate/handler/redirect" {
|
|
61
|
+
export default function(location: string, options?: MinOptions): ResponseFn;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare module "primate/handler/sse" {
|
|
65
|
+
export default function(implementation: {
|
|
66
|
+
open?: () => void,
|
|
67
|
+
close?: () => void,
|
|
68
|
+
}, options?: MinOptions): ResponseFn;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare module "primate/handler/stream" {
|
|
72
|
+
export default function(body: Streamable, options?: MinOptions): ResponseFn;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare module "primate/handler/text" {
|
|
76
|
+
export default function(body: string, options?: MinOptions): ResponseFn;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare module "primate/handler/view" {
|
|
80
|
+
export default function(name: string, props: {}, options?: Options): ResponseFn;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare module "primate/handler/ws" {
|
|
84
|
+
export default function(implementation: {
|
|
85
|
+
open?: () => void,
|
|
86
|
+
close?: () => void,
|
|
87
|
+
message?: (Event: unknown) => void,
|
|
88
|
+
});
|
|
89
|
+
}
|