primate 0.15.1 → 0.15.2

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/eslint.config.js +0 -1
  3. package/module.json +0 -15
  4. package/readme/components/edit-user-for.html +0 -10
  5. package/readme/components/edit-user.html +0 -10
  6. package/readme/components/user-index.html +0 -4
  7. package/readme/components/users.html +0 -4
  8. package/readme/extensions/handlers/html/user-index.html +0 -4
  9. package/readme/extensions/handlers/html/user.js +0 -13
  10. package/readme/extensions/handlers/htmx/user-index.html +0 -4
  11. package/readme/extensions/handlers/htmx/user.js +0 -23
  12. package/readme/extensions/handlers/redirect/user.js +0 -6
  13. package/readme/extensions/modules/configure.js +0 -3
  14. package/readme/extensions/modules/domains/configure.js +0 -5
  15. package/readme/extensions/modules/domains/fields.js +0 -11
  16. package/readme/extensions/modules/domains/predicates.js +0 -14
  17. package/readme/extensions/modules/domains/short-field-notation.js +0 -13
  18. package/readme/getting-started.js +0 -5
  19. package/readme/routing/accessing-the-request-body.js +0 -6
  20. package/readme/routing/basic.js +0 -13
  21. package/readme/routing/explicit-handlers.js +0 -8
  22. package/readme/routing/parameterized-routes.js +0 -7
  23. package/readme/routing/the-request-object.js +0 -7
  24. package/readme/serving-content/html.js +0 -9
  25. package/readme/serving-content/json.js +0 -10
  26. package/readme/serving-content/plain-text.js +0 -7
  27. package/readme/serving-content/response.js +0 -9
  28. package/readme/serving-content/streams.js +0 -9
  29. package/readme/template.md +0 -121
  30. package/scripts/docs.sh +0 -7
  31. package/src/extend.spec.js +0 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Expressive, minimal and extensible framework for JavaScript",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
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,10 +0,0 @@
1
- <form for="${user}" method="post">
2
- <h1>Edit user</h1>
3
- <p>
4
- <input name="name" value="${name}" />
5
- </p>
6
- <p>
7
- <input name="email" value="${email}" />
8
- </p>
9
- <input type="submit" value="Save user" />
10
- </form>
@@ -1,10 +0,0 @@
1
- <form method="post">
2
- <h1>Edit user</h1>
3
- <p>
4
- <input name="name" value="${user.name}"></textarea>
5
- </p>
6
- <p>
7
- <input name="email" value="${user.email}"></textarea>
8
- </p>
9
- <input type="submit" value="Save user" />
10
- </form>
@@ -1,4 +0,0 @@
1
- <div for="${users}">
2
- User ${name}.
3
- Email ${email}.
4
- </div>
@@ -1,4 +0,0 @@
1
- <div for="${users}">
2
- User ${name}.
3
- Email ${email}.
4
- </div>
@@ -1,4 +0,0 @@
1
- <div for="${users}">
2
- User ${name}.
3
- Email ${email}.
4
- </div>
@@ -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,4 +0,0 @@
1
- <div for="${users}" hx-get="/other-users" hx-swap="outerHTML">
2
- User ${name}.
3
- Email ${email}.
4
- </div>
@@ -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,6 +0,0 @@
1
- import redirect from "@primate/html";
2
-
3
- export default router => {
4
- // redirect the request
5
- router.get("/user", () => redirect("/users"));
6
- };
@@ -1,3 +0,0 @@
1
- export default {
2
- modules: [],
3
- };
@@ -1,5 +0,0 @@
1
- import domains from "@primate/domains";
2
-
3
- export default {
4
- modules: [domains()],
5
- };
@@ -1,11 +0,0 @@
1
- import {Domain} from "@primate/domains";
2
-
3
- // A basic domain with two properies
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
- };
11
- }
@@ -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
- }
@@ -1,5 +0,0 @@
1
- export default {
2
- get() {
3
- return "Hello, world!";
4
- },
5
- };
@@ -1,6 +0,0 @@
1
- // routes/site/login.js handles the `/site/login` route
2
- export default {
3
- get(request) {
4
- return `username submitted: ${request.body.username}`;
5
- },
6
- };
@@ -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
- };
@@ -1,8 +0,0 @@
1
- import {redirect} from "primate";
2
-
3
- // routes/source.js handles the `/source` route
4
- export default {
5
- get() {
6
- return redirect("/target");
7
- },
8
- };
@@ -1,7 +0,0 @@
1
- // routes/user/{userId}.js handles all routes of the sort `/user/{userId}`
2
- // where {userId} can be anything
3
- export default {
4
- get(request) {
5
- return `user id: ${request.named.userId}`;
6
- },
7
- };
@@ -1,7 +0,0 @@
1
- // routes/site/login.js handles the `/site/login` route
2
- export default {
3
- get(request) {
4
- // will serve `["site", "login"]` as JSON
5
- return request.path;
6
- },
7
- };
@@ -1,9 +0,0 @@
1
- import {html} from "primate";
2
-
3
- // routes/index.js handles the `/` route
4
- export default {
5
- get() {
6
- // to serve HTML, import and use the html handler
7
- return html("<p>Hello, world!</p>");
8
- },
9
- };
@@ -1,10 +0,0 @@
1
- // routes/index.js handles the `/` route
2
- export default {
3
- get() {
4
- // proper JavaScript objects are served as JSON
5
- return [
6
- {name: "Donald"},
7
- {name: "Ryan"},
8
- ];
9
- },
10
- };
@@ -1,7 +0,0 @@
1
- // routes/index.js handles the `/` route
2
- export default {
3
- get() {
4
- // strings are served as plain text
5
- return "Donald";
6
- },
7
- };
@@ -1,9 +0,0 @@
1
- import {Response} from "runtime-compat/http";
2
-
3
- // routes/index.js handles the `/` route
4
- export default {
5
- get() {
6
- // use a Response object for custom response status
7
- return new Response("created!", {status: 201});
8
- },
9
- };
@@ -1,9 +0,0 @@
1
- import {File} from "runtime-compat/filesystem";
2
-
3
- // routes/index.js handles the `/` route
4
- export default {
5
- get() {
6
- // ReadableStream or Blob objects are streamed to the client
7
- return new File("users.json");
8
- },
9
- };
@@ -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
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env bash
2
- npx -y embedme\
3
- --source-root readme\
4
- --strip-embed-comment\
5
- --stdout readme/template.md\
6
- > README.md
7
-
@@ -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
- };