primate 0.7.0 → 0.7.3
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 +30 -6
- package/exports.js +28 -0
- package/package.json +4 -4
- package/source/App.js +1 -1
- package/source/Bundler.js +6 -15
- package/source/Server.js +3 -3
- package/source/exports.js +0 -28
- package/source/preset/static/index.html +0 -8
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Primate,
|
|
1
|
+
# Primate, a cross-runtime framework
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
repetitive, error-prone tasks and lets you
|
|
5
|
-
expressive code.
|
|
3
|
+
Primate is a full-stack cross-runtime Javascript framework (Node.js and Deno).
|
|
4
|
+
It relieves you of dealing with repetitive, error-prone tasks and lets you
|
|
5
|
+
concentrate on writing effective, expressive code.
|
|
6
6
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
@@ -15,10 +15,12 @@ expressive code.
|
|
|
15
15
|
[MongoDB][primate-mongodb-store]
|
|
16
16
|
* Easy modelling of`1:1`, `1:n` and `n:m` relationships
|
|
17
17
|
* Minimally opinionated with sane, overrideable defaults
|
|
18
|
-
*
|
|
18
|
+
* Supports both Node.js and Deno
|
|
19
19
|
|
|
20
20
|
## Getting started
|
|
21
21
|
|
|
22
|
+
### Prepare
|
|
23
|
+
|
|
22
24
|
Lay out your app
|
|
23
25
|
|
|
24
26
|
```sh
|
|
@@ -56,6 +58,8 @@ import {app} from "primate";
|
|
|
56
58
|
app.run();
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
### Run on Node.js
|
|
62
|
+
|
|
59
63
|
Create a start script and enable ES modules (in `package.json`)
|
|
60
64
|
|
|
61
65
|
```json
|
|
@@ -79,7 +83,27 @@ Run app
|
|
|
79
83
|
$ npm start
|
|
80
84
|
```
|
|
81
85
|
|
|
82
|
-
|
|
86
|
+
### Run on Deno
|
|
87
|
+
|
|
88
|
+
Create an import map file (`import-map.json`)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"imports": {
|
|
93
|
+
"runtime-compat": "https://deno.land/x/runtime_compat/exports.js",
|
|
94
|
+
"primate": "https:/deno.land/x/primate/exports.js"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Run app
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
deno run --import-map=import-map.json app.js
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
You will typically need the `allow-read`, `allow-write` and `allow-net`
|
|
106
|
+
permissions.
|
|
83
107
|
|
|
84
108
|
## Table of Contents
|
|
85
109
|
|
package/exports.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import conf from "./source/conf.js";
|
|
2
|
+
import App from "./source/App.js";
|
|
3
|
+
|
|
4
|
+
export {App};
|
|
5
|
+
export {default as Bundler} from "./source/Bundler.js";
|
|
6
|
+
export {default as EagerPromise, eager} from "./source/EagerPromise.js" ;
|
|
7
|
+
|
|
8
|
+
export {default as Domain} from "./source/domain/Domain.js";
|
|
9
|
+
export {default as Storeable} from "./source/types/Storeable.js";
|
|
10
|
+
|
|
11
|
+
export * from "./source/errors.js";
|
|
12
|
+
export * from "./source/invariants.js";
|
|
13
|
+
|
|
14
|
+
export {default as MemoryStore} from "./source/store/Memory.js";
|
|
15
|
+
export {default as Store} from "./source/store/Store.js";
|
|
16
|
+
|
|
17
|
+
export {default as extend_object} from "./source/extend_object.js";
|
|
18
|
+
export {default as sanitize} from "./source/sanitize.js";
|
|
19
|
+
|
|
20
|
+
export {default as html} from "./source/handlers/html.js";
|
|
21
|
+
export {default as json} from "./source/handlers/json.js";
|
|
22
|
+
export {default as redirect} from "./source/handlers/redirect.js";
|
|
23
|
+
|
|
24
|
+
export {default as router} from "./source/Router.js";
|
|
25
|
+
|
|
26
|
+
const app = new App(conf());
|
|
27
|
+
|
|
28
|
+
export {app};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"author": "Primate core team <core@primatejs.com>",
|
|
5
5
|
"homepage": "https://primatejs.com",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
7
7
|
"repository": "https://github.com/primatejs/primate",
|
|
8
|
-
"description": "
|
|
8
|
+
"description": "Cross-runtime JavaScript framework",
|
|
9
9
|
"license": "BSD-3-Clause",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"copy": "rm -rf output && mkdir output && cp source/* output -a",
|
|
@@ -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.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"debris": "^0.2.2",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"nyc": "^15.1.0"
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
|
-
"exports": "./
|
|
27
|
+
"exports": "./exports.js",
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=17.9.0"
|
|
30
30
|
}
|
package/source/App.js
CHANGED
|
@@ -13,7 +13,7 @@ export default class App {
|
|
|
13
13
|
log.reset("Primate").yellow(package_json.version);
|
|
14
14
|
const routes = await File.list(this.conf.paths.routes);
|
|
15
15
|
for (const route of routes) {
|
|
16
|
-
await import(
|
|
16
|
+
await import(`file://${this.conf.paths.routes}/${route}`);
|
|
17
17
|
}
|
|
18
18
|
await new Bundler(this.conf).bundle();
|
|
19
19
|
|
package/source/Bundler.js
CHANGED
|
@@ -12,25 +12,16 @@ export default class Bundler {
|
|
|
12
12
|
this.scripts = [];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
async copy_with_preset(subdirectory, to) {
|
|
16
|
-
const {paths} = this.conf;
|
|
17
|
-
|
|
18
|
-
// copy files preset files first
|
|
19
|
-
await File.copy(`${preset}/${subdirectory}`, to);
|
|
20
|
-
|
|
21
|
-
// copy any user code over it, not recreating the folder
|
|
22
|
-
try {
|
|
23
|
-
await File.copy(paths[subdirectory], to);
|
|
24
|
-
} catch(error) {
|
|
25
|
-
// directory doesn't exist
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
15
|
async bundle() {
|
|
30
16
|
const {paths} = this.conf;
|
|
31
17
|
|
|
18
|
+
// remove public directory in case exists
|
|
19
|
+
await File.remove(paths.public);
|
|
20
|
+
// create public directory
|
|
21
|
+
await File.create(paths.public);
|
|
22
|
+
|
|
32
23
|
// copy static files to public
|
|
33
|
-
await
|
|
24
|
+
await File.copy(paths.static, paths.public);
|
|
34
25
|
|
|
35
26
|
// read index.html from public, then remove it (we serve it dynamically)
|
|
36
27
|
await File.remove(`${paths.public}/${this.index}`);
|
package/source/Server.js
CHANGED
|
@@ -30,12 +30,12 @@ export default class Server {
|
|
|
30
30
|
response.setHeader("Set-Cookie", `${cookie}; SameSite=${same_site}`);
|
|
31
31
|
}
|
|
32
32
|
response.session = session;
|
|
33
|
-
const
|
|
34
|
-
const payload = Object.fromEntries(decodeURI(
|
|
33
|
+
const text = await request.text();
|
|
34
|
+
const payload = Object.fromEntries(decodeURI(text).replaceAll("+", " ")
|
|
35
35
|
.split("&")
|
|
36
36
|
.map(part => part.split("="))
|
|
37
37
|
.filter(([, value]) => value !== ""));
|
|
38
|
-
const {pathname, search} =
|
|
38
|
+
const {pathname, search} = request.url;
|
|
39
39
|
return this.try(pathname + search, request, response, payload);
|
|
40
40
|
});
|
|
41
41
|
}
|
package/source/exports.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import conf from "./conf.js";
|
|
2
|
-
import App from "./App.js";
|
|
3
|
-
|
|
4
|
-
export {App};
|
|
5
|
-
export {default as Bundler} from "./Bundler.js";
|
|
6
|
-
export {default as EagerPromise, eager} from "./EagerPromise.js" ;
|
|
7
|
-
|
|
8
|
-
export {default as Domain} from "./domain/Domain.js";
|
|
9
|
-
export {default as Storeable} from "./types/Storeable.js";
|
|
10
|
-
|
|
11
|
-
export * from "./errors.js";
|
|
12
|
-
export * from "./invariants.js";
|
|
13
|
-
|
|
14
|
-
export {default as MemoryStore} from "./store/Memory.js";
|
|
15
|
-
export {default as Store} from "./store/Store.js";
|
|
16
|
-
|
|
17
|
-
export {default as extend_object} from "./extend_object.js";
|
|
18
|
-
export {default as sanitize} from "./sanitize.js";
|
|
19
|
-
|
|
20
|
-
export {default as html} from "./handlers/html.js";
|
|
21
|
-
export {default as json} from "./handlers/json.js";
|
|
22
|
-
export {default as redirect} from "./handlers/redirect.js";
|
|
23
|
-
|
|
24
|
-
export {default as router} from "./Router.js";
|
|
25
|
-
|
|
26
|
-
const app = new App(conf());
|
|
27
|
-
|
|
28
|
-
export {app};
|