primate 0.15.1 → 0.15.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/package.json +1 -1
- package/src/bin.js +1 -1
- package/src/commands/create.js +2 -0
- package/src/commands/dev.js +16 -0
- package/src/commands/exports.js +2 -1
- package/src/config.js +2 -2
- package/src/exports.js +2 -2
- package/eslint.config.js +0 -1
- package/module.json +0 -15
- package/readme/components/edit-user-for.html +0 -10
- package/readme/components/edit-user.html +0 -10
- package/readme/components/user-index.html +0 -4
- package/readme/components/users.html +0 -4
- package/readme/extensions/handlers/html/user-index.html +0 -4
- package/readme/extensions/handlers/html/user.js +0 -13
- package/readme/extensions/handlers/htmx/user-index.html +0 -4
- package/readme/extensions/handlers/htmx/user.js +0 -23
- package/readme/extensions/handlers/redirect/user.js +0 -6
- package/readme/extensions/modules/configure.js +0 -3
- package/readme/extensions/modules/domains/configure.js +0 -5
- package/readme/extensions/modules/domains/fields.js +0 -11
- package/readme/extensions/modules/domains/predicates.js +0 -14
- package/readme/extensions/modules/domains/short-field-notation.js +0 -13
- package/readme/getting-started.js +0 -5
- package/readme/routing/accessing-the-request-body.js +0 -6
- package/readme/routing/basic.js +0 -13
- package/readme/routing/explicit-handlers.js +0 -8
- package/readme/routing/parameterized-routes.js +0 -7
- package/readme/routing/the-request-object.js +0 -7
- package/readme/serving-content/html.js +0 -9
- package/readme/serving-content/json.js +0 -10
- package/readme/serving-content/plain-text.js +0 -7
- package/readme/serving-content/response.js +0 -9
- package/readme/serving-content/streams.js +0 -9
- package/readme/template.md +0 -121
- package/scripts/docs.sh +0 -7
- package/src/extend.spec.js +0 -103
- /package/src/commands/{start.js → serve.js} +0 -0
package/package.json
CHANGED
package/src/bin.js
CHANGED
package/src/commands/create.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import register from "../register.js";
|
|
2
|
+
import compile from "../compile.js";
|
|
3
|
+
import publish from "../publish.js";
|
|
4
|
+
import route from "../route.js";
|
|
5
|
+
import serve from "../serve.js";
|
|
6
|
+
|
|
7
|
+
export default async env => {
|
|
8
|
+
// register handlers
|
|
9
|
+
await register(env);
|
|
10
|
+
// compile server-side code
|
|
11
|
+
await compile(env);
|
|
12
|
+
// publish client-side code
|
|
13
|
+
await publish(env);
|
|
14
|
+
// serve
|
|
15
|
+
serve({router: await route(env), ...env});
|
|
16
|
+
};
|
package/src/commands/exports.js
CHANGED
package/src/config.js
CHANGED
|
@@ -80,9 +80,9 @@ export default async (filename = "primate.config.js") => {
|
|
|
80
80
|
.replace("%body%", () => body)
|
|
81
81
|
.replace("%head%", () => `${head}${heads}`);
|
|
82
82
|
},
|
|
83
|
-
publish: async ({src, code, type = "", inline = false}) => {
|
|
83
|
+
publish: async ({src, code, type = "", inline = false, main}) => {
|
|
84
84
|
const integrity = await hash(code);
|
|
85
|
-
resources.push({src, code, type, inline, integrity});
|
|
85
|
+
resources.push({src, code, type, inline, integrity, main});
|
|
86
86
|
return integrity;
|
|
87
87
|
},
|
|
88
88
|
};
|
package/src/exports.js
CHANGED
package/eslint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {default} from "maximin";
|
package/module.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "primate",
|
|
3
|
-
"version": "0.15.1",
|
|
4
|
-
"description": "Expressive, minimal and extensible framework for JavaScript",
|
|
5
|
-
"homepage": "https://primatejs.com",
|
|
6
|
-
"bugs": "https://github.com/primatejs/primate/issues",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"bin": "src/bin.js",
|
|
9
|
-
"repository": "https://github.com/primatejs/primate",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"docs": "scripts/docs.sh",
|
|
12
|
-
"test": "npx debris",
|
|
13
|
-
"lint": "npx eslint ."
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import html from "@primate/html";
|
|
2
|
-
|
|
3
|
-
export default router => {
|
|
4
|
-
// the HTML tagged template handler loads a component from the `components`
|
|
5
|
-
// directory and serves it as HTML, passing any given data as attributes
|
|
6
|
-
router.get("/users", () => {
|
|
7
|
-
const users = [
|
|
8
|
-
{name: "Donald", email: "donald@the.duck"},
|
|
9
|
-
{name: "Joe", email: "joe@was.absent"},
|
|
10
|
-
];
|
|
11
|
-
return html("user-index", {users});
|
|
12
|
-
});
|
|
13
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {default as htmx, partial} from "@primate/htmx";
|
|
2
|
-
|
|
3
|
-
export default router => {
|
|
4
|
-
// the HTML tagged template handler loads a component from the `components`
|
|
5
|
-
// directory and serves it as HTML, passing any given data as attributes
|
|
6
|
-
router.get("/users", () => {
|
|
7
|
-
const users = [
|
|
8
|
-
{name: "Donald", email: "donald@the.duck"},
|
|
9
|
-
{name: "Joe", email: "joe@was.absent"},
|
|
10
|
-
];
|
|
11
|
-
return htmx("user-index", {users});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// this is the same as above, with support for partial rendering (without
|
|
15
|
-
// index.html)
|
|
16
|
-
router.get("/other-users", () => {
|
|
17
|
-
const users = [
|
|
18
|
-
{name: "Other Donald", email: "donald@the.goose"},
|
|
19
|
-
{name: "Other Joe", email: "joe@was.around"},
|
|
20
|
-
];
|
|
21
|
-
return partial("user-index", {users});
|
|
22
|
-
});
|
|
23
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {Domain} from "@primate/domains";
|
|
2
|
-
import House from "./House.js";
|
|
3
|
-
|
|
4
|
-
export default class User extends Domain {
|
|
5
|
-
static fields = {
|
|
6
|
-
// a user's name is a string unique across the user collection
|
|
7
|
-
name: [String, "unique"],
|
|
8
|
-
// a user's age is a positive integer
|
|
9
|
-
age: [Number, "integer", "positive"],
|
|
10
|
-
// a user's house has the foreign id of a house record and no two
|
|
11
|
-
// users may have the same house
|
|
12
|
-
house_id: [House, "unique"],
|
|
13
|
-
};
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {Domain} from "@primate/domains";
|
|
2
|
-
import House from "./House.js";
|
|
3
|
-
|
|
4
|
-
export default class User extends Domain {
|
|
5
|
-
static fields = {
|
|
6
|
-
// a user's name is a string
|
|
7
|
-
name: String,
|
|
8
|
-
// a user's age is a number
|
|
9
|
-
age: Number,
|
|
10
|
-
// a user's house has the foreign id of a house record
|
|
11
|
-
house_id: House,
|
|
12
|
-
};
|
|
13
|
-
}
|
package/readme/routing/basic.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {redirect} from "primate";
|
|
2
|
-
|
|
3
|
-
// routes/site/login.js handles the `/site/login` route
|
|
4
|
-
export default {
|
|
5
|
-
get() {
|
|
6
|
-
// strings are served as plain text
|
|
7
|
-
return "Hello, world!";
|
|
8
|
-
},
|
|
9
|
-
// other HTTP verbs are also available
|
|
10
|
-
post() {
|
|
11
|
-
return redirect("/");
|
|
12
|
-
},
|
|
13
|
-
};
|
package/readme/template.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# Primate
|
|
2
|
-
|
|
3
|
-
Expressive, minimal and extensible framework for JavaScript.
|
|
4
|
-
|
|
5
|
-
## Getting started
|
|
6
|
-
|
|
7
|
-
Run `npx -y primate@latest create` to create a project structure.
|
|
8
|
-
|
|
9
|
-
Create a route in `routes/index.js`
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
// getting-started.js
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Run `npm i && npm start` and visit `localhost:6161` in your browser.
|
|
16
|
-
|
|
17
|
-
## Table of Contents
|
|
18
|
-
|
|
19
|
-
- [Serving content](#serving-content)
|
|
20
|
-
- [Plain text](#plain-text)
|
|
21
|
-
- [JSON](#json)
|
|
22
|
-
- [Streams](#streams)
|
|
23
|
-
- [Response](#response)
|
|
24
|
-
- [HTML](#html)
|
|
25
|
-
- [Routing](#routing)
|
|
26
|
-
- [Basic](#basic)
|
|
27
|
-
- [The request object](#the-request-object)
|
|
28
|
-
- [Accessing the request body](#accessing-the-request-body)
|
|
29
|
-
- [Parameterized routes](#parameterized-routes)
|
|
30
|
-
- [Explicit handlers](#explicit-handlers)
|
|
31
|
-
|
|
32
|
-
## Serving content
|
|
33
|
-
|
|
34
|
-
Create a file in `routes/index.js` to handle the special `/` route.
|
|
35
|
-
|
|
36
|
-
### Plain text
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
// serving-content/plain-text.js
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### JSON
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
// serving-content/json.js
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Streams
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
// serving-content/streams.js
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Response
|
|
55
|
-
|
|
56
|
-
```js
|
|
57
|
-
// serving-content/response.js
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### HTML
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
// serving-content/html.js
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Routing
|
|
67
|
-
|
|
68
|
-
Primate uses filesystem-based routes. Every path a client accesses is mapped to
|
|
69
|
-
a route under `routes`.
|
|
70
|
-
|
|
71
|
-
* `index.js` handles the root route (`/`)
|
|
72
|
-
* `post.js` handles the `/post` route
|
|
73
|
-
* `post/{postId}.js` handles a parameterized route where `{postId}` can
|
|
74
|
-
be mapped to anything, such as `/post/1`
|
|
75
|
-
|
|
76
|
-
### Basic
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
// routing/basic.js
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### The request object
|
|
83
|
-
|
|
84
|
-
```js
|
|
85
|
-
// routing/the-request-object.js
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Accessing the request body
|
|
89
|
-
|
|
90
|
-
For requests containing a body, Primate will attempt to parse the body according
|
|
91
|
-
to the content type sent along the request. Currently supported are
|
|
92
|
-
`application/x-www-form-urlencoded` (typically for form submission) and
|
|
93
|
-
`application/json`.
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
// routing/accessing-the-request-body.js
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Parameterized routes
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
// routing/parameterized-routes.js
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Explicit handlers
|
|
106
|
-
|
|
107
|
-
Often we can figure out the content type to respond with based on the return
|
|
108
|
-
type from the handler. For other cases, we need to use an explicit handler.
|
|
109
|
-
|
|
110
|
-
```js
|
|
111
|
-
// routing/explicit-handlers.js
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Resources
|
|
115
|
-
|
|
116
|
-
* Website: https://primatejs.com
|
|
117
|
-
* IRC: Join the `#primate` channel on `irc.libera.chat`.
|
|
118
|
-
|
|
119
|
-
## License
|
|
120
|
-
|
|
121
|
-
MIT
|
package/scripts/docs.sh
DELETED
package/src/extend.spec.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import extend from "./extend.js";
|
|
2
|
-
|
|
3
|
-
export default test => {
|
|
4
|
-
test.case("no params", assert => {
|
|
5
|
-
assert(extend()).equals({});
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test.case("no base", assert => {
|
|
9
|
-
const extension = {key: "value"};
|
|
10
|
-
assert(extend(undefined, extension)).equals(extension);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test.case("no extension", assert => {
|
|
14
|
-
const base = {keys: "values"};
|
|
15
|
-
assert(extend(base)).equals(base);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test.case("base and extension same", assert => {
|
|
19
|
-
const object = {key: "value"};
|
|
20
|
-
assert(extend(object, object)).equals(object);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test.case("one property", assert => {
|
|
24
|
-
const base = {key: "value"};
|
|
25
|
-
const extension = {key: "value2"};
|
|
26
|
-
assert(extend(base, extension)).equals(extension);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test.case("two properties, one replaced", assert => {
|
|
30
|
-
const base = {key: "value", key2: "value2"};
|
|
31
|
-
const extension = {key: "other value"};
|
|
32
|
-
const extended = {key: "other value", key2: "value2"};
|
|
33
|
-
assert(extend(base, extension)).equals(extended);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test.case("arrays overwritten", assert => {
|
|
37
|
-
const base = {key: ["value", "value2"]};
|
|
38
|
-
const extension = {key: ["value3", "value4"]};
|
|
39
|
-
assert(extend(base, extension)).equals(extension);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test.case("one property of a subobject", assert => {
|
|
43
|
-
const base = {key: {subkey: "subvalue"}};
|
|
44
|
-
const extension = {key: {subkey: "subvalue 2"}};
|
|
45
|
-
assert(extend(base, extension)).equals(extension);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test.case("two properties of a subobject, one replaced", assert => {
|
|
49
|
-
const base = {key: {subkey: "subvalue", subkey2: "subvalue2"}};
|
|
50
|
-
const extension = {key: {subkey: "subvalue 2"}};
|
|
51
|
-
const extended = {key: {subkey: "subvalue 2", subkey2: "subvalue2"}};
|
|
52
|
-
assert(extend(base, extension)).equals(extended);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test.case("config enhancement", assert => {
|
|
56
|
-
const base = {
|
|
57
|
-
base: "/",
|
|
58
|
-
debug: false,
|
|
59
|
-
defaults: {
|
|
60
|
-
action: "index",
|
|
61
|
-
context: "guest",
|
|
62
|
-
},
|
|
63
|
-
paths: {
|
|
64
|
-
public: "public",
|
|
65
|
-
static: "static",
|
|
66
|
-
routes: "routes",
|
|
67
|
-
components: "components",
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const additional = {
|
|
72
|
-
debug: true,
|
|
73
|
-
environment: "testing",
|
|
74
|
-
defaults: {
|
|
75
|
-
context: "user",
|
|
76
|
-
mode: "operational",
|
|
77
|
-
},
|
|
78
|
-
paths: {
|
|
79
|
-
client: "client",
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const extended = {
|
|
84
|
-
base: "/",
|
|
85
|
-
debug: true,
|
|
86
|
-
environment: "testing",
|
|
87
|
-
defaults: {
|
|
88
|
-
action: "index",
|
|
89
|
-
context: "user",
|
|
90
|
-
mode: "operational",
|
|
91
|
-
},
|
|
92
|
-
paths: {
|
|
93
|
-
client: "client",
|
|
94
|
-
public: "public",
|
|
95
|
-
static: "static",
|
|
96
|
-
routes: "routes",
|
|
97
|
-
components: "components",
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
assert(extend(base, additional)).equals(extended);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
File without changes
|