primate 0.6.0 → 0.6.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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Primate, A JavaScript Framework
2
2
 
3
- A full-stack Javascript framework with batteries included, Primate relieves you of dealing with repetitive, error-prone tasks and lets you concentrate on writing effective, expressive code.
3
+ A full-stack Javascript framework, Primate relieves you of dealing with
4
+ repetitive, error-prone tasks and lets you concentrate on writing effective,
5
+ expressive code.
4
6
 
5
7
  ## Installing
6
8
 
@@ -14,7 +16,9 @@ npm install primate
14
16
  * Secure by default with HTTPS, hash-verified scripts and a strong CSP
15
17
  * Built-in support for sessions with secure cookies
16
18
  * Input verification using data domains
17
- * Many different data store modules: In-Memory (built-in), [File][primate-store-file], [JSON][primate-store-json], [MongoDB][primate-store-mongodb]
19
+ * Many different data store modules: In-Memory (built-in),
20
+ [File][primate-store-file], [JSON][primate-store-json],
21
+ [MongoDB][primate-store-mongodb]
18
22
  * Easy modelling of`1:1`, `1:n` and `n:m` relationships
19
23
  * Minimally opinionated with sane, overrideable defaults
20
24
  * No dependencies
@@ -23,11 +27,6 @@ npm install primate
23
27
 
24
28
  See the [getting started][getting-started] guide.
25
29
 
26
- ## Resources
27
-
28
- * [Source code][source-code]
29
- * [Issues][issues]
30
-
31
30
  ## License
32
31
 
33
32
  BSD-3-Clause
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.6.0",
3
+ "version": "0.6.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",
package/source/Router.js CHANGED
@@ -14,9 +14,14 @@ export default {
14
14
  "get": (path, callback) => push("get", path, callback),
15
15
  "post": (path, callback) => push("post", path, callback),
16
16
  "alias": (key, value) => aliases.push({key, value}),
17
- "process": async request => {
18
- const {pathname, method} = request;
19
- request.path = pathname.split("/").filter(path => path !== "");
17
+ "process": async original_request => {
18
+ const {method} = original_request;
19
+ const url = new URL(`https://primatejs.com${original_request.pathname}`);
20
+ const {pathname, searchParams} = url;
21
+ const params = Object.fromEntries(searchParams);
22
+ const request = {...original_request, pathname, params,
23
+ "path": pathname.split("/").filter(path => path !== ""),
24
+ };
20
25
  const verb = find(method, pathname, () => http404``);
21
26
  return verb(await find("map", pathname, _ => _)(request));
22
27
  },
package/source/Server.js CHANGED
@@ -46,7 +46,7 @@ export default class Server {
46
46
  }
47
47
 
48
48
  const data = Buffer.concat(buffers).toString();
49
- const payload = Object.fromEntries(data
49
+ const payload = Object.fromEntries(decodeURI(data).replaceAll("+", " ")
50
50
  .split("&")
51
51
  .map(part => part.split("="))
52
52
  .filter(([, value]) => value !== ""));
@@ -89,7 +89,7 @@ export default class Node {
89
89
  }
90
90
  }
91
91
 
92
- as_tag() {
92
+ async render() {
93
93
  let tag = "<" + this.tag_name;
94
94
  for (const [key, value] of Object.entries(this.attributes)) {
95
95
  if (value === undefined) {
@@ -109,20 +109,16 @@ export default class Node {
109
109
  } else {
110
110
  tag += ">";
111
111
  for (const child of this.children) {
112
- tag += child.as_tag();
112
+ tag += await child.render();
113
113
  }
114
114
  if (this.text) {
115
- tag += this.text;
115
+ tag += await this.text;
116
116
  }
117
117
  tag += "</" + this.tag_name + ">";
118
118
  }
119
119
  return tag;
120
120
  }
121
121
 
122
- render() {
123
- return this.as_tag();
124
- }
125
-
126
122
  compose(components) {
127
123
  if (components[this.tag_name]) {
128
124
  return Parser.parse(components[this.tag_name], this.attributes);
@@ -144,11 +140,11 @@ export default class Node {
144
140
  }
145
141
  }
146
142
 
147
- expand() {
143
+ async expand() {
148
144
  if (this.attributes["data-for"] !== undefined) {
149
145
  const key = this.attributes["data-for"];
150
146
  delete this.attributes["data-for"];
151
- const value = this.data[key];
147
+ const value = await this.data[key];
152
148
  const arr = Array.isArray(value) ? value : [value];
153
149
  const newparent = new Node();
154
150
  for (const val of arr) {
@@ -177,7 +173,7 @@ export default class Node {
177
173
  }
178
174
  }
179
175
  for (let i = 0; i < this.children.length; i++) {
180
- this.children[i] = this.children[i].expand();
176
+ this.children[i] = await this.children[i].expand();
181
177
  }
182
178
  return this;
183
179
  }
@@ -15,11 +15,11 @@ if (await File.exists(path)) {
15
15
 
16
16
  export default async (strings, ...keys) => {
17
17
  const awaited_keys = await Promise.all(keys);
18
- const body = Parser.parse(strings
18
+ const body = await (await Parser.parse(strings
19
19
  .slice(0, last)
20
20
  .map((string, i) => `${string}$${i}`)
21
21
  .join("") + strings[strings.length+last], awaited_keys)
22
- .unfold(components)
22
+ .unfold(components))
23
23
  .render();
24
24
  const code = 200;
25
25
  const headers = {"Content-Type": "text/html"};