primate 0.31.13 → 0.32.1
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/LICENSE +19 -0
- package/package.json +13 -6
- package/src/bin.js +3 -3
- package/src/commands/build.js +4 -0
- package/src/commands/dev.js +7 -2
- package/src/commands/exports.js +2 -1
- package/src/commands/serve.js +7 -2
- package/src/handlers/error.js +1 -0
- package/src/handlers/json.js +1 -0
- package/src/handlers/redirect.js +1 -0
- package/src/handlers/sse.js +1 -0
- package/src/handlers/stream.js +1 -0
- package/src/handlers/text.js +1 -0
- package/src/handlers/view.js +1 -0
- package/src/handlers/ws.js +1 -0
- package/src/init.js +12 -0
- package/README.md +0 -14
- package/src/Logger.js +0 -111
- package/src/app.js +0 -220
- package/src/defaults/app.html +0 -9
- package/src/defaults/error.html +0 -14
- package/src/defaults/primate.config.js +0 -55
- package/src/dispatch.js +0 -28
- package/src/errors.js +0 -8
- package/src/errors.json +0 -130
- package/src/exports.js +0 -9
- package/src/handlers.js +0 -93
- package/src/hooks/copy_includes.js +0 -20
- package/src/hooks/exports.js +0 -7
- package/src/hooks/handle.js +0 -113
- package/src/hooks/init.js +0 -3
- package/src/hooks/parse.js +0 -17
- package/src/hooks/publish.js +0 -3
- package/src/hooks/register.js +0 -60
- package/src/hooks/respond.js +0 -29
- package/src/hooks/route.js +0 -49
- package/src/hooks/stage.js +0 -64
- package/src/loaders/common.js +0 -32
- package/src/loaders/exports.js +0 -2
- package/src/loaders/modules.js +0 -33
- package/src/loaders/types.js +0 -29
- package/src/run.js +0 -42
- package/src/start.js +0 -66
- package/src/to_sorted.js +0 -1
- package/src/validate.js +0 -10
- package/types/index.d.ts +0 -69
package/src/loaders/types.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import FS from "rcompat/fs";
|
|
2
|
-
import { is } from "rcompat/invariant";
|
|
3
|
-
import { tryreturn } from "rcompat/sync";
|
|
4
|
-
import errors from "../errors.js";
|
|
5
|
-
import fs from "./common.js";
|
|
6
|
-
|
|
7
|
-
const filter = path => /^[a-z]/u.test(path.name);
|
|
8
|
-
|
|
9
|
-
export default async (log, directory, load = fs) => {
|
|
10
|
-
const types = (await load({ log, directory, name: "types", filter }))
|
|
11
|
-
.map(([name, type]) => [name, type.default]);
|
|
12
|
-
|
|
13
|
-
const resolve = name => FS.File.join(directory, name);
|
|
14
|
-
types.every(([name, type]) => tryreturn(_ => {
|
|
15
|
-
is(type).object();
|
|
16
|
-
is(type.base).string();
|
|
17
|
-
is(type.validate).function();
|
|
18
|
-
return true;
|
|
19
|
-
}).orelse(_ => errors.InvalidTypeExport.throw(resolve(`${name}.js`))),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
types.every(([name]) =>
|
|
23
|
-
/^(?:[a-z][^\W_]*)$/u.test(name) || errors.InvalidTypeName.throw(name));
|
|
24
|
-
|
|
25
|
-
types.some(([name]) => ["get", "raw"].includes(name) &&
|
|
26
|
-
errors.ReservedTypeName.throw(name));
|
|
27
|
-
|
|
28
|
-
return Object.fromEntries(types);
|
|
29
|
-
};
|
package/src/run.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { tryreturn } from "rcompat/async";
|
|
2
|
-
import FS from "rcompat/fs";
|
|
3
|
-
import o from "rcompat/object";
|
|
4
|
-
import { runtime } from "rcompat/meta";
|
|
5
|
-
import app from "./app.js";
|
|
6
|
-
import { default as Logger, bye } from "./Logger.js";
|
|
7
|
-
import errors from "./errors.js";
|
|
8
|
-
import command from "./commands/exports.js";
|
|
9
|
-
import defaults from "./defaults/primate.config.js";
|
|
10
|
-
|
|
11
|
-
let logger = new Logger({ level: Logger.Warn });
|
|
12
|
-
|
|
13
|
-
const get_config = async root => {
|
|
14
|
-
const name = "primate.config.js";
|
|
15
|
-
const config = root.join(name);
|
|
16
|
-
return await config.exists()
|
|
17
|
-
? tryreturn(async _ => {
|
|
18
|
-
const imported = await config.import("default");
|
|
19
|
-
|
|
20
|
-
(imported === undefined || Object.keys(imported).length === 0) &&
|
|
21
|
-
errors.EmptyConfigFile.warn(logger, config);
|
|
22
|
-
|
|
23
|
-
return o.extend(defaults, imported);
|
|
24
|
-
}).orelse(({ message }) =>
|
|
25
|
-
errors.ErrorInConfigFile.throw(message, `${runtime} ${config}`))
|
|
26
|
-
: defaults;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default async name => tryreturn(async _ => {
|
|
30
|
-
// use module root if possible, fall back to current directory
|
|
31
|
-
const root = await tryreturn(_ => FS.File.root())
|
|
32
|
-
.orelse(_ => FS.File.resolve());
|
|
33
|
-
const config = await get_config(root);
|
|
34
|
-
logger = new Logger(config.logger);
|
|
35
|
-
await command(name)(await app(logger, root, config));
|
|
36
|
-
}).orelse(error => {
|
|
37
|
-
if (error.level === Logger.Error) {
|
|
38
|
-
logger.auto(error);
|
|
39
|
-
return bye();
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
});
|
package/src/start.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { serve, Response, Status } from "rcompat/http";
|
|
2
|
-
import { tryreturn } from "rcompat/async";
|
|
3
|
-
import { bold, blue, dim } from "rcompat/colors";
|
|
4
|
-
import { resolve } from "rcompat/package";
|
|
5
|
-
import o from "rcompat/object";
|
|
6
|
-
import Build from "rcompat/build";
|
|
7
|
-
import FS from "rcompat/fs";
|
|
8
|
-
import * as hooks from "./hooks/exports.js";
|
|
9
|
-
import { print } from "./Logger.js";
|
|
10
|
-
|
|
11
|
-
const base_hooks = ["init", "stage", "register", "publish"];
|
|
12
|
-
|
|
13
|
-
const publish = async app => {
|
|
14
|
-
const http = app.get("http");
|
|
15
|
-
const client = app.runpath(app.get("location.client"));
|
|
16
|
-
|
|
17
|
-
const re = new RegExp("app..*(?:js|css)$", "u");
|
|
18
|
-
for (const path of await client.collect(re, { recursive: false })) {
|
|
19
|
-
const src = path.name;
|
|
20
|
-
const type = path.extension === ".css" ? "style" : "module";
|
|
21
|
-
await app.publish({ src, type });
|
|
22
|
-
if (path.extension === ".js") {
|
|
23
|
-
const imports = { app: FS.File.join(http.static.root, src).webpath() };
|
|
24
|
-
await app.publish({
|
|
25
|
-
inline: true,
|
|
26
|
-
code: JSON.stringify({ imports }, null, 2),
|
|
27
|
-
type: "importmap",
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default async ($app, mode = "development") => {
|
|
34
|
-
let app = $app;
|
|
35
|
-
|
|
36
|
-
app.mode = mode;
|
|
37
|
-
app.build = new Build({
|
|
38
|
-
...o.exclude(app.get("build"), ["includes", "index", "transform"]),
|
|
39
|
-
outdir: app.runpath(app.get("location.client")).path,
|
|
40
|
-
resolveDir: app.path.build.path,
|
|
41
|
-
}, mode);
|
|
42
|
-
|
|
43
|
-
const primate = await resolve(import.meta.url);
|
|
44
|
-
print(blue(bold(primate.name)), blue(primate.version), "in startup\n");
|
|
45
|
-
|
|
46
|
-
for (const hook of base_hooks) {
|
|
47
|
-
app.log.info(`running ${dim(hook)} hooks`, { module: "primate" });
|
|
48
|
-
app = await hooks[hook](app);
|
|
49
|
-
}
|
|
50
|
-
// start the build
|
|
51
|
-
await app.build.start();
|
|
52
|
-
await publish(app);
|
|
53
|
-
app.route = hooks.route(app);
|
|
54
|
-
app.parse = hooks.parse(app);
|
|
55
|
-
const handle = await hooks.handle(app);
|
|
56
|
-
app.server = await serve(async request =>
|
|
57
|
-
tryreturn(async _ => handle(await app.parse(request)))
|
|
58
|
-
.orelse(error => {
|
|
59
|
-
app.log.auto(error);
|
|
60
|
-
return new Response(null, { status: Status.INTERNAL_SERVER_ERROR });
|
|
61
|
-
}), app.get("http"));
|
|
62
|
-
|
|
63
|
-
const { host, port } = app.get("http");
|
|
64
|
-
const address = `http${app.secure ? "s" : ""}://${host}:${port}`;
|
|
65
|
-
print(`${blue("++")} started ${dim("->")} ${dim(address)}\n`);
|
|
66
|
-
};
|
package/src/to_sorted.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default (array, compareFn) => [...array].sort(compareFn);
|
package/src/validate.js
DELETED
package/types/index.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
declare module "primate" {
|
|
2
|
-
type App = any;
|
|
3
|
-
|
|
4
|
-
interface MinOptions {
|
|
5
|
-
status: number,
|
|
6
|
-
headers: Headers | {},
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ErrorOptions extends MinOptions {
|
|
10
|
-
page: string,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface Options extends ErrorOptions {
|
|
14
|
-
placeholders: {},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type Dispatcher = {
|
|
18
|
-
get(property: string): string,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type RequestFacade = {
|
|
22
|
-
body: {}
|
|
23
|
-
path: Dispatcher,
|
|
24
|
-
query: Dispatcher,
|
|
25
|
-
cookies: Dispatcher,
|
|
26
|
-
headers: Dispatcher,
|
|
27
|
-
original: Request,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type ResponseFn = (app: App, ...rest: any) => Response;
|
|
31
|
-
type ResponseFacade =
|
|
32
|
-
string
|
|
33
|
-
| object
|
|
34
|
-
| URL
|
|
35
|
-
| Blob
|
|
36
|
-
| ReadableStream
|
|
37
|
-
| Response
|
|
38
|
-
| ResponseFn;
|
|
39
|
-
|
|
40
|
-
type RouteFunction = (request?: RequestFacade) => ResponseFacade;
|
|
41
|
-
|
|
42
|
-
type Streamable = ReadableStream | Blob;
|
|
43
|
-
|
|
44
|
-
export type Route = {
|
|
45
|
-
get?: RouteFunction,
|
|
46
|
-
post?: RouteFunction,
|
|
47
|
-
put?: RouteFunction,
|
|
48
|
-
delete?: RouteFunction,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export function text(body: string, options?: MinOptions): ResponseFn;
|
|
52
|
-
|
|
53
|
-
export function json(body: {}, options?: MinOptions): ResponseFn;
|
|
54
|
-
|
|
55
|
-
export function stream(body: Streamable, options?: MinOptions): ResponseFn;
|
|
56
|
-
|
|
57
|
-
export function redirect(location: string, options?: MinOptions): ResponseFn;
|
|
58
|
-
|
|
59
|
-
export function html(name: string, options?: MinOptions): ResponseFn;
|
|
60
|
-
|
|
61
|
-
export function view(name: string, props: {}, options?: Options): ResponseFn;
|
|
62
|
-
|
|
63
|
-
export function error(body: string, options?: ErrorOptions): ResponseFn;
|
|
64
|
-
|
|
65
|
-
export function sse(implementation: {
|
|
66
|
-
open?: () => void,
|
|
67
|
-
close?: () => void,
|
|
68
|
-
}, options?: MinOptions): ResponseFn;
|
|
69
|
-
}
|