primate 0.8.0 → 0.8.1
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/exports.js +3 -0
- package/package.json +2 -2
- package/source/App.js +2 -1
- package/source/Router.js +1 -1
- package/source/handlers/DOM/Node.js +5 -5
- package/source/handlers/html.js +5 -6
- package/source/handlers/http.js +3 -1
- package/source/handlers/redirect.js +9 -5
package/exports.js
CHANGED
|
@@ -20,6 +20,9 @@ export {default as sanitize} from "./source/sanitize.js";
|
|
|
20
20
|
export {default as html} from "./source/handlers/html.js";
|
|
21
21
|
export {default as json} from "./source/handlers/json.js";
|
|
22
22
|
export {default as redirect} from "./source/handlers/redirect.js";
|
|
23
|
+
export {http404} from "./source/handlers/http.js";
|
|
24
|
+
|
|
25
|
+
export {default as DOMParser} from "./source/handlers/DOM/Parser.js";
|
|
23
26
|
|
|
24
27
|
export {default as router} from "./source/Router.js";
|
|
25
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"author": "Primate core team <core@primatejs.com>",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "npm run copy && npm run debris"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"runtime-compat": "^0.1.
|
|
18
|
+
"runtime-compat": "^0.1.6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"debris": "^0.2.2",
|
package/source/App.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Path, File, log} from "runtime-compat";
|
|
2
|
-
import Bundler from "./Bundler.js";
|
|
2
|
+
import {default as Bundler, index} from "./Bundler.js";
|
|
3
3
|
import Router from "./Router.js";
|
|
4
4
|
import Server from "./Server.js";
|
|
5
5
|
import package_json from "../package.json" assert {"type": "json"};
|
|
@@ -16,6 +16,7 @@ export default class App {
|
|
|
16
16
|
await import(`file://${this.conf.paths.routes}/${route}`);
|
|
17
17
|
}
|
|
18
18
|
await new Bundler(this.conf).bundle();
|
|
19
|
+
this.index = await index(this.conf);
|
|
19
20
|
|
|
20
21
|
const conf = {"router": Router,
|
|
21
22
|
"serve_from": this.conf.paths.public,
|
package/source/Router.js
CHANGED
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
const url = new URL(`https://primatejs.com${original_request.pathname}`);
|
|
20
20
|
const {pathname, searchParams} = url;
|
|
21
21
|
const params = Object.fromEntries(searchParams);
|
|
22
|
-
const verb = find(method, pathname,
|
|
22
|
+
const verb = find(method, pathname, {"handler": http404``});
|
|
23
23
|
const path = pathname.split("/").filter(path => path !== "");
|
|
24
24
|
Object.entries(verb.path.exec(pathname)?.groups ?? [])
|
|
25
25
|
.filter(([key]) => path[key] === undefined)
|
|
@@ -3,19 +3,19 @@ import Parser from "./Parser.js";
|
|
|
3
3
|
const replacement_regex = /^\$([0-9]*)$/;
|
|
4
4
|
const data_regex = /\${([^}]*)}/g;
|
|
5
5
|
const attributes_regex = /([-a-z]*="[^"]+")/g;
|
|
6
|
-
const replace = (attribute, source) => {
|
|
6
|
+
const replace = async (attribute, source) => {
|
|
7
7
|
if (attribute.includes(".")) {
|
|
8
8
|
const index = attribute.indexOf(".");
|
|
9
9
|
const left = attribute.slice(0, index);
|
|
10
10
|
const rest = attribute.slice(index+1);
|
|
11
11
|
if (source[left] !== undefined) {
|
|
12
|
-
return replace(rest, source[left]);
|
|
12
|
+
return await replace(rest, source[left]);
|
|
13
13
|
}
|
|
14
14
|
} else {
|
|
15
15
|
return source[attribute];
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
const fulfill = (attribute, source) => {
|
|
18
|
+
const fulfill = async (attribute, source) => {
|
|
19
19
|
if (source === undefined) {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
@@ -24,7 +24,7 @@ const fulfill = (attribute, source) => {
|
|
|
24
24
|
if (matches.length > 0) {
|
|
25
25
|
for (const match of matches) {
|
|
26
26
|
const [key] = match;
|
|
27
|
-
const new_value = replace(match[1], source);
|
|
27
|
+
const new_value = await replace(match[1], source);
|
|
28
28
|
if (attribute === key) {
|
|
29
29
|
return new_value;
|
|
30
30
|
}
|
|
@@ -153,7 +153,7 @@ export default class Node {
|
|
|
153
153
|
return newparent.expand();
|
|
154
154
|
}
|
|
155
155
|
for (const attribute in this.attributes) {
|
|
156
|
-
const fulfilled = fulfill(this.attributes[attribute], this.data);
|
|
156
|
+
const fulfilled = await fulfill(this.attributes[attribute], this.data);
|
|
157
157
|
switch(attribute) {
|
|
158
158
|
case "value":
|
|
159
159
|
if (this.tag_name === "input") {
|
package/source/handlers/html.js
CHANGED
|
@@ -4,7 +4,6 @@ import {index} from "../Bundler.js";
|
|
|
4
4
|
import _conf from "../conf.js";
|
|
5
5
|
const conf = _conf();
|
|
6
6
|
|
|
7
|
-
const last = -1;
|
|
8
7
|
const {"paths": {"components": path}} = conf;
|
|
9
8
|
const components = {};
|
|
10
9
|
if (await File.exists(path)) {
|
|
@@ -14,16 +13,16 @@ if (await File.exists(path)) {
|
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
|
|
16
|
+
const last = -1;
|
|
17
17
|
export default async (strings, ...keys) => {
|
|
18
|
-
const
|
|
19
|
-
const rendered = await (await (await Parser.parse(strings
|
|
18
|
+
const html = await (await (await Parser.parse(strings
|
|
20
19
|
.slice(0, last)
|
|
21
20
|
.map((string, i) => `${string}$${i}`)
|
|
22
|
-
.join("") + strings[strings.length+last],
|
|
21
|
+
.join("") + strings[strings.length + last], await Promise.all(keys))
|
|
23
22
|
.unfold(components)))
|
|
24
23
|
.render();
|
|
25
|
-
const body = (await index(conf)).replace("<body>", () => `<body>${
|
|
24
|
+
const body = (await index(conf)).replace("<body>", () => `<body>${html}`);
|
|
26
25
|
const code = 200;
|
|
27
26
|
const headers = {"Content-Type": "text/html"};
|
|
28
|
-
return {
|
|
27
|
+
return {body, code, headers};
|
|
29
28
|
};
|
package/source/handlers/http.js
CHANGED
|
@@ -2,9 +2,13 @@ const last = -1;
|
|
|
2
2
|
|
|
3
3
|
export default async (strings, ...keys) => {
|
|
4
4
|
const awaited_keys = await Promise.all(keys);
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const headers = {
|
|
6
|
+
"Location": strings
|
|
7
|
+
.slice(0, last)
|
|
8
|
+
.map((string, i) => string + awaited_keys[i])
|
|
9
|
+
.join("") + strings[strings.length + last],
|
|
10
|
+
};
|
|
11
|
+
const code = 302;
|
|
12
|
+
// no body
|
|
13
|
+
return {code, headers};
|
|
10
14
|
};
|