primate 0.20.0 → 0.20.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.
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.20.0",
3
+ "version": "0.20.2",
4
4
  "description": "Expressive, minimal and extensible web framework",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
7
7
  "license": "MIT",
8
8
  "files": [
9
9
  "src/**/*.js",
10
- "src/defaults/index.html",
10
+ "src/errors.json",
11
+ "src/defaults/app.html",
11
12
  "!src/**/*.spec.js"
12
13
  ],
13
14
  "bin": "src/bin.js",
@@ -19,6 +20,9 @@
19
20
  "dependencies": {
20
21
  "runtime-compat": "^0.20.2"
21
22
  },
23
+ "engines": {
24
+ "node": ">=18.16"
25
+ },
22
26
  "type": "module",
23
27
  "exports": "./src/exports.js"
24
28
  }
package/src/app.js CHANGED
@@ -8,6 +8,7 @@ import * as hooks from "./hooks/exports.js";
8
8
  import * as loaders from "./loaders/exports.js";
9
9
  import dispatch from "./dispatch.js";
10
10
  import {print} from "./Logger.js";
11
+ import toSorted from "./toSorted.js";
11
12
 
12
13
  const base = new Path(import.meta.url).up(1);
13
14
  // do not hard-depend on node
@@ -101,8 +102,8 @@ export default async (config, root, log) => {
101
102
  const style = ({inline, code, href, rel = "stylesheet"}) => inline
102
103
  ? tag({name: "style", code})
103
104
  : tag({name: "link", attributes: {rel, href}, close: false});
104
- const heads = app.assets
105
- .toSorted(({type}) => -1 * (type === "importmap"))
105
+ const heads = toSorted(app.assets,
106
+ ({type}) => -1 * (type === "importmap"))
106
107
  .map(({src, code, type, inline, integrity}) =>
107
108
  type === "style"
108
109
  ? style({inline, code, href: src})
@@ -0,0 +1,9 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Primate app</title>
5
+ <meta charset="utf-8" />
6
+ %head%
7
+ </head>
8
+ <body>%body%</body>
9
+ </html>
@@ -0,0 +1,110 @@
1
+ {
2
+ "module": "primate",
3
+ "errors": {
4
+ "CannotParseBody": {
5
+ "message": "cannot parse body {0} as {1}",
6
+ "fix": "use a different content type or fix body",
7
+ "level": "Warn"
8
+ },
9
+ "DoubleModule": {
10
+ "message": "double module {0} in {1}",
11
+ "fix": "load {0} only once",
12
+ "level": "Error"
13
+ },
14
+ "DoublePathParameter": {
15
+ "message": "double path parameter {0} in route {1}",
16
+ "fix": "disambiguate path parameters in route names",
17
+ "level": "Error"
18
+ },
19
+ "DoubleRoute": {
20
+ "message": "double route of the form {0}",
21
+ "fix": "disambiguate routes",
22
+ "level": "Error"
23
+ },
24
+ "EmptyRouteFile": {
25
+ "message": "empty route file at {0}",
26
+ "fix": "add routes or remove file",
27
+ "level": "Warn"
28
+ },
29
+ "EmptyDirectory": {
30
+ "message": "empty {0} directory",
31
+ "fix": "populate {1} or remove it",
32
+ "level": "Warn"
33
+ },
34
+ "ErrorInConfigFile": {
35
+ "message": "error in config file :: {0}",
36
+ "fix": "check errors in config file by running {1}",
37
+ "level": "Error"
38
+ },
39
+ "InvalidDefaultExport": {
40
+ "message": "invalid default export at {0}",
41
+ "fix": "use only functions for the default export",
42
+ "level": "Error"
43
+ },
44
+ "InvalidPathParameter": {
45
+ "message": "invalid path parameter {0} in route {1}",
46
+ "fix": "use only latin letters and decimal digits in path parameters",
47
+ "level": "Error"
48
+ },
49
+ "InvalidRouteName": {
50
+ "message": "invalid route name {0}",
51
+ "fix": "do not use dots in route names",
52
+ "level": "Error"
53
+ },
54
+ "InvalidTypeName": {
55
+ "message": "invalid type name {0}",
56
+ "fix": "use lowercase-first latin letters and decimals in type names",
57
+ "level": "Error"
58
+ },
59
+ "MismatchedPath": {
60
+ "message": "mismatched {0} path :: {1}",
61
+ "fix": "if unintentional, fix the type or the caller",
62
+ "level": "Info"
63
+ },
64
+ "MismatchedType": {
65
+ "message": "mismatched type :: {0}",
66
+ "fix": "if unintentional, fix the type or the caller",
67
+ "level": "Info"
68
+ },
69
+ "ModuleHasNoHooks": {
70
+ "message": "module {0} has no hooks",
71
+ "fix": "ensure every module uses at least one hook or deactivate it",
72
+ "level": "Warn"
73
+ },
74
+ "ModuleHasNoName": {
75
+ "message": "module at index {0} has no name",
76
+ "fix": "update module at index {0} and inform maintainer",
77
+ "level": "Error"
78
+ },
79
+ "ModulesMustBeArray" :{
80
+ "message": "the {0} config property must be an array",
81
+ "fix": "change {0} to an array in the config or remove this property",
82
+ "level": "Error"
83
+ },
84
+ "EmptyConfigFile": {
85
+ "message": "empty config file at {0}",
86
+ "fix": "add configuration options or remove file",
87
+ "level": "Warn"
88
+ },
89
+ "NoFileForPath": {
90
+ "message": "no file for {0}",
91
+ "fix": "if unintentional create a file at {1}{0}",
92
+ "level": "Info"
93
+ },
94
+ "NoHandlerForExtension": {
95
+ "message": "no handler for {0} extension",
96
+ "fix": "add handler module for .{0} files or remove {1}",
97
+ "level": "Error"
98
+ },
99
+ "NoRouteToPath": {
100
+ "message": "no {0} route to {1}",
101
+ "fix": "if unintentional create a route at {2}.js",
102
+ "level": "Info"
103
+ },
104
+ "ReservedTypeName": {
105
+ "message": "reserved type name {0}",
106
+ "fix": "do not use any reserved type names",
107
+ "level": "Error"
108
+ }
109
+ }
110
+ }
@@ -1,13 +1,14 @@
1
1
  import {Path} from "runtime-compat/fs";
2
2
  import errors from "../../errors.js";
3
+ import toSorted from "../../toSorted.js";
3
4
 
4
5
  export default type => async (log, directory, load) => {
5
6
  const filter = path => new RegExp(`^\\+${type}.js$`, "u").test(path.name);
6
7
 
7
8
  const replace = new RegExp(`\\+${type}`, "u");
8
- const objects = (await load({log, directory, filter, warn: false}))
9
- .map(([name, object]) => [name.replace(replace, () => ""), object])
10
- .toSorted(([a], [b]) => a.length - b.length);
9
+ const objects = toSorted((await load({log, directory, filter, warn: false}))
10
+ .map(([name, object]) => [name.replace(replace, () => ""), object]),
11
+ ([a], [b]) => a.length - b.length);
11
12
 
12
13
  const resolve = name => new Path(directory, name, `+${type}.js`);
13
14
  objects.some(([name, value]) => typeof value !== "function"
@@ -0,0 +1 @@
1
+ export default (array, compareFn) => [...array].sort(compareFn);