primate 0.11.0 → 0.13.0

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 (60) hide show
  1. package/LICENSE +0 -2
  2. package/README.md +52 -99
  3. package/eslint.config.js +1 -0
  4. package/exports.js +1 -3
  5. package/module.json +10 -5
  6. package/package.json +14 -17
  7. package/readme/extensions/handlers/html/user.js +13 -0
  8. package/readme/extensions/handlers/htmx/user-index.html +4 -0
  9. package/readme/extensions/handlers/htmx/user.js +23 -0
  10. package/readme/extensions/handlers/redirect/user.js +6 -0
  11. package/readme/{domains → extensions/modules/domains}/fields.js +3 -4
  12. package/readme/{domains → extensions/modules/domains}/predicates.js +3 -3
  13. package/readme/{domains → extensions/modules/domains}/short-field-notation.js +3 -3
  14. package/readme/routing/basic.js +1 -1
  15. package/readme/routing/explicit-handlers.js +4 -0
  16. package/readme/routing/sharing-logic-across-requests.js +2 -2
  17. package/readme/serving-content/html.js +10 -11
  18. package/readme/serving-content/json.js +2 -2
  19. package/readme/serving-content/plain-text.js +1 -1
  20. package/readme/serving-content/response.js +6 -0
  21. package/readme/serving-content/streams.js +1 -1
  22. package/readme/template.md +135 -0
  23. package/scripts/docs.sh +7 -0
  24. package/src/bin.js +2 -0
  25. package/src/bundle.js +14 -7
  26. package/src/compile.js +5 -0
  27. package/src/config.js +73 -0
  28. package/src/duck.js +4 -0
  29. package/src/extend.spec.js +19 -27
  30. package/src/handlers/exports.js +5 -0
  31. package/src/handlers/html.js +18 -0
  32. package/src/handlers/http404.js +6 -4
  33. package/src/handlers/json.js +6 -4
  34. package/src/handlers/redirect.js +7 -0
  35. package/src/handlers/stream.js +6 -4
  36. package/src/handlers/text.js +6 -11
  37. package/src/http-statuses.js +5 -0
  38. package/src/index.html +8 -0
  39. package/src/log.js +7 -4
  40. package/src/mimes.js +12 -0
  41. package/src/register.js +5 -0
  42. package/src/respond.js +24 -0
  43. package/src/route.js +15 -28
  44. package/src/run.js +10 -9
  45. package/src/serve.js +25 -12
  46. package/README.template.md +0 -190
  47. package/bin/primate.js +0 -5
  48. package/readme/getting-started/generate-ssl.sh +0 -1
  49. package/readme/getting-started/lay-out-app.sh +0 -1
  50. package/readme/getting-started/site-index.html +0 -1
  51. package/readme/getting-started/site.js +0 -3
  52. package/src/conf.js +0 -30
  53. package/src/http-statuses.json +0 -5
  54. package/src/mimes.json +0 -12
  55. package/src/preset/stores/default.js +0 -2
  56. /package/readme/{serving-content → extensions/handlers/html}/user-index.html +0 -0
  57. /package/readme/{modules → extensions/modules}/configure.js +0 -0
  58. /package/readme/{modules → extensions/modules}/domains/configure.js +0 -0
  59. /package/readme/{getting-started/hello.js → getting-started.js} +0 -0
  60. /package/src/{preset/primate.conf.js → primate.config.js} +0 -0
@@ -1,190 +0,0 @@
1
- # Primate
2
-
3
- An expressive, minimal and extensible framework for JavaScript.
4
-
5
- ## Getting started
6
-
7
- Create a route in `routes/hello.js`
8
-
9
- ```js
10
- // getting-started/hello.js
11
- ```
12
-
13
- Add `{"type": "module"}` to your `package.json` and run `npx primate -y`.
14
-
15
- ## Table of Contents
16
-
17
- - [Serving content](#serving-content)
18
- - [Plain text](#plain-text)
19
- - [JSON](#json)
20
- - [Streams](#streams)
21
- - [HTML](#html)
22
- - [Routing](#routing)
23
- - [Basic](#basic)
24
- - [The request object](#the-request-object)
25
- - [Accessing the request body](#accessing-the-request-body)
26
- - [Regular expressions](#regular-expressions)
27
- - [Named groups](#named-groups)
28
- - [Aliasing](#aliasing)
29
- - [Sharing logic across requests](#sharing-logic-across-requests)
30
- - [Modules](#modules)
31
- - [Data persistance](#data-persistance)
32
- - [Short field notation](#short-field-notation)
33
- - [Predicates](#predicates)
34
-
35
- ## Serving content
36
-
37
- Create a file in `routes` that exports a default function
38
-
39
- ### Plain text
40
-
41
- ```js
42
- // serving-content/plain-text.js
43
- ```
44
-
45
- ### JSON
46
-
47
- ```js
48
- // serving-content/json.js
49
- ```
50
-
51
- ### Streams
52
-
53
- ```js
54
- // serving-content/streams.js
55
- ```
56
-
57
- ### HTML
58
-
59
- Create an HTML component in `components/user-index.html`
60
-
61
- ```html
62
- <!-- serving-content/user-index.html -->
63
- ```
64
-
65
- Serve the component in your route
66
-
67
- ```js
68
- // serving-content/html.js
69
- ```
70
-
71
- ## Routing
72
-
73
- Routes map requests to responses. They are loaded from `routes`.
74
-
75
- ### Basic
76
-
77
- ```js
78
- // routing/basic.js
79
- ```
80
-
81
- ### The request object
82
-
83
- ```js
84
- // routing/the-request-object.js
85
- ```
86
-
87
- ### Accessing the request body
88
-
89
- For requests containing a body, Primate will attempt parsing the body according
90
- to the content type sent along the request. Currently supported are
91
- `application/x-www-form-urlencoded` (typically for form submission) and
92
- `application/json`.
93
-
94
- ```js
95
- // routing/accessing-the-request-body.js
96
- ```
97
-
98
- ### Regular expressions
99
-
100
- ```js
101
- // routing/regular-expressions.js
102
- ```
103
-
104
- ### Named groups
105
-
106
- ```js
107
- // routing/named-groups.js
108
- ```
109
-
110
- ### Aliasing
111
-
112
- ```js
113
- // routing/aliasing.js
114
- ```
115
-
116
- ### Sharing logic across requests
117
-
118
- ```js
119
- // routing/sharing-logic-across-requests.js
120
- ```
121
-
122
- ### Modules
123
-
124
- Primate has optional additional modules published separately that enrich the
125
- core framework with functionality for common use cases.
126
-
127
- To add modules, create a `primate.js` configuration file in your project's
128
- root. This file exports a default export used to extend the framework.
129
-
130
- ```js
131
- // modules/configure.js
132
- ```
133
-
134
- #### Data
135
-
136
- Run `npm i @primate/domains` to install the data domains module, used for
137
- data persistance.
138
-
139
- Import and initialize this module in your configuration file
140
-
141
- ```js
142
- // modules/domains/configure.js
143
- ```
144
-
145
- #### Sessions
146
-
147
- The module `@primate/sessions` is used to maintain user sessions.
148
-
149
-
150
-
151
- #### Databases
152
-
153
- ## Data persistance
154
-
155
- Primate domains (via [`@primate/domains`][primate-domains]) represent a
156
- collection in a store using the class `fields` property.
157
-
158
- ```js
159
- // domains/fields.js
160
- ```
161
-
162
- ### Short field notation
163
-
164
- Value types may be any constructible JavaScript object, including other
165
- domains. When using other domains as types, data integrity (on saving) is
166
- ensured.
167
-
168
- ```js
169
- // domains/short-field-notation.js
170
- ```
171
-
172
- ### Predicates
173
-
174
- Field types may also be specified as an array, to specify additional predicates
175
- aside from the type.
176
-
177
- ```js
178
- // domains/predicates.js
179
- ```
180
-
181
- ## Resources
182
-
183
- * Website: https://primatejs.com
184
- * IRC: Join the `#primate` channel on `irc.libera.chat`.
185
-
186
- ## License
187
-
188
- MIT
189
-
190
- [primate-domains]: https://github.com/primatejs/primate-domains
package/bin/primate.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import conf from "../src/conf.js";
4
- import run from "../src/run.js";
5
- await run(await conf());
@@ -1 +0,0 @@
1
- openssl req -x509 -out ssl/default.crt -keyout ssl/default.key -newkey rsa:2048 -nodes -sha256 -batch
@@ -1 +0,0 @@
1
- mkdir -p app/{routes,components,ssl} && cd app
@@ -1 +0,0 @@
1
- Today's date is ${date}.
@@ -1,3 +0,0 @@
1
- export default router => {
2
- router.get("/", () => "Hello, world!");
3
- };
package/src/conf.js DELETED
@@ -1,30 +0,0 @@
1
- import {Path} from "runtime-compat/filesystem";
2
- import {EagerEither} from "runtime-compat/functional";
3
- import cache from "./cache.js";
4
- import extend from "./extend.js";
5
- import preset from "./preset/primate.conf.js";
6
- import log from "./log.js";
7
- import package_json from "../package.json" assert {type: "json"};
8
-
9
- const qualify = (root, paths) =>
10
- Object.keys(paths).reduce((sofar, key) => {
11
- const value = paths[key];
12
- sofar[key] = typeof value === "string"
13
- ? new Path(root, value)
14
- : qualify(`${root}/${key}`, value);
15
- return sofar;
16
- }, {});
17
-
18
- export default async (filename = "primate.conf.js") => {
19
- const root = Path.resolve();
20
- const conffile = root.join(filename);
21
- const conf = await EagerEither
22
- .try(async () => extend(preset, (await import(conffile)).default))
23
- .match({left: () => preset})
24
- .get();
25
-
26
- const temp = {...conf, ...log, paths: qualify(root, conf.paths), root};
27
- temp.info(`primate \x1b[34m${package_json.version}\x1b[0m`);
28
- const modules = await Promise.all(conf.modules.map(module => module(temp)));
29
- return cache("conf", filename, () => ({...temp, modules}));
30
- };
@@ -1,5 +0,0 @@
1
- {
2
- "OK": 200,
3
- "Found": 302,
4
- "InternalServerError": 500
5
- }
package/src/mimes.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "binary": "application/octet-stream",
3
- "css": "text/css",
4
- "html": "text/html",
5
- "jpg": "image/jpeg",
6
- "js": "text/javascript",
7
- "json": "application/json",
8
- "png": "image/png",
9
- "svg": "image/svg+xml",
10
- "woff2": "font/woff2",
11
- "webp": "image/webp"
12
- }
@@ -1,2 +0,0 @@
1
- import MemoryStore from "../../store/Memory.js";
2
- export default new MemoryStore();