elegance-js 2.1.23 → 2.1.26
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/dist/client/effect.d.ts +27 -0
- package/dist/client/effect.js +37 -0
- package/dist/client/eventListener.d.ts +39 -0
- package/dist/client/eventListener.js +52 -0
- package/dist/client/loadHook.d.ts +34 -0
- package/dist/client/loadHook.js +52 -0
- package/dist/client/observer.d.ts +36 -0
- package/dist/client/observer.js +66 -0
- package/dist/client/runtime.d.ts +105 -0
- package/dist/client/runtime.js +620 -0
- package/dist/client/state.d.ts +40 -0
- package/dist/client/state.js +110 -0
- package/dist/compilation/compiler.d.ts +155 -0
- package/dist/compilation/compiler.js +1153 -0
- package/dist/components/ClientComponent.d.ts +22 -0
- package/dist/components/ClientComponent.js +55 -0
- package/dist/components/Link.d.ts +16 -1
- package/dist/components/Link.js +22 -0
- package/dist/components/Portal.d.ts +2 -0
- package/dist/components/Portal.js +2 -0
- package/dist/elements/element.d.ts +87 -0
- package/dist/elements/element.js +33 -0
- package/dist/elements/element_list.d.ts +7 -0
- package/dist/elements/element_list.js +65 -0
- package/dist/elements/raw.d.ts +14 -0
- package/dist/elements/raw.js +78 -0
- package/dist/elements/specific_props.d.ts +750 -0
- package/dist/global.d.ts +221 -327
- package/dist/index.d.ts +15 -3
- package/dist/index.js +11 -0
- package/dist/server/layout.d.ts +34 -3
- package/dist/server/layout.js +6 -0
- package/dist/server/log.d.ts +12 -0
- package/dist/server/log.js +64 -0
- package/dist/server/page.d.ts +32 -0
- package/dist/server/page.js +6 -0
- package/dist/server/runtime.d.ts +6 -0
- package/dist/server/runtime.js +72 -0
- package/dist/server/server.d.ts +103 -11
- package/dist/server/server.js +709 -0
- package/package.json +13 -13
- package/scripts/bootstrap.js +37 -273
- package/scripts/bootstrap_files/elegance.txt +40 -0
- package/scripts/bootstrap_files/index.txt +3 -0
- package/scripts/bootstrap_files/layout.txt +46 -0
- package/scripts/bootstrap_files/middleware.txt +18 -0
- package/scripts/bootstrap_files/page.txt +123 -0
- package/scripts/bootstrap_files/route.txt +6 -0
- package/scripts/elegance_dev.ts +40 -0
- package/scripts/elegance_prod.ts +40 -0
- package/scripts/elegance_static.ts +24 -0
- package/scripts/prod.js +9 -26
- package/scripts/run.js +13 -0
- package/scripts/static.js +13 -0
- package/dist/build.d.ts +0 -2
- package/dist/build.mjs +0 -202
- package/dist/client/client.d.ts +0 -1
- package/dist/client/client.mjs +0 -574
- package/dist/client/processPageElements.d.ts +0 -1
- package/dist/client/processPageElements.mjs +0 -117
- package/dist/client/render.d.ts +0 -1
- package/dist/client/render.mjs +0 -40
- package/dist/client/watcher.d.ts +0 -1
- package/dist/client/watcher.mjs +0 -26
- package/dist/compilation/compilation.d.ts +0 -139
- package/dist/compilation/compilation.mjs +0 -751
- package/dist/compilation/compiler_process.d.ts +0 -3
- package/dist/compilation/compiler_process.mjs +0 -102
- package/dist/compilation/dynamic_compiler.d.ts +0 -10
- package/dist/compilation/dynamic_compiler.mjs +0 -93
- package/dist/compile_docs.mjs +0 -34
- package/dist/components/Link.mjs +0 -65
- package/dist/global.mjs +0 -0
- package/dist/helpers/ObjectAttributeType.d.ts +0 -7
- package/dist/helpers/ObjectAttributeType.mjs +0 -11
- package/dist/helpers/camelToKebab.d.ts +0 -1
- package/dist/helpers/camelToKebab.mjs +0 -6
- package/dist/index.mjs +0 -3
- package/dist/internal/deprecate.d.ts +0 -1
- package/dist/internal/deprecate.mjs +0 -7
- package/dist/log.d.ts +0 -10
- package/dist/log.mjs +0 -38
- package/dist/server/generateHTMLTemplate.d.ts +0 -12
- package/dist/server/generateHTMLTemplate.mjs +0 -41
- package/dist/server/layout.mjs +0 -19
- package/dist/server/loadHook.d.ts +0 -30
- package/dist/server/loadHook.mjs +0 -50
- package/dist/server/observe.d.ts +0 -19
- package/dist/server/observe.mjs +0 -16
- package/dist/server/render.d.ts +0 -5
- package/dist/server/render.mjs +0 -61
- package/dist/server/server.mjs +0 -429
- package/dist/server/state.d.ts +0 -61
- package/dist/server/state.mjs +0 -146
- package/dist/shared/bindServerElements.mjs +0 -3
- package/dist/shared/serverElements.d.ts +0 -11
- package/dist/shared/serverElements.mjs +0 -164
- package/scripts/dev.js +0 -33
- package/scripts/export.js +0 -20
- package/scripts/ts-arc-dev.js +0 -9
- package/scripts/ts-arc-prod.js +0 -9
- /package/dist/{compile_docs.d.ts → elements/specific_props.js} +0 -0
- /package/dist/{shared/bindServerElements.d.ts → global.js} +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import util from "node:util";
|
|
2
|
+
var LogLevel;
|
|
3
|
+
(function (LogLevel) {
|
|
4
|
+
LogLevel[LogLevel["NONE"] = 0] = "NONE";
|
|
5
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
6
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
7
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
8
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
9
|
+
})(LogLevel || (LogLevel = {}));
|
|
10
|
+
let logLevel = LogLevel.INFO;
|
|
11
|
+
function setLogLevel(level) {
|
|
12
|
+
logLevel = level;
|
|
13
|
+
}
|
|
14
|
+
function formatToLog(level, ...args) {
|
|
15
|
+
if (level === LogLevel.NONE) {
|
|
16
|
+
throw new Error("Can't log with LogLevel none.");
|
|
17
|
+
}
|
|
18
|
+
let tag;
|
|
19
|
+
let tagColor;
|
|
20
|
+
let msgColor;
|
|
21
|
+
switch (level) {
|
|
22
|
+
case LogLevel.ERROR:
|
|
23
|
+
tag = "[ERROR]";
|
|
24
|
+
tagColor = "\x1b[41;30m"; // red bg, black text
|
|
25
|
+
msgColor = "\x1b[31m"; // red text
|
|
26
|
+
break;
|
|
27
|
+
case LogLevel.WARN:
|
|
28
|
+
tag = "[WARN]";
|
|
29
|
+
tagColor = "\x1b[43;30m"; // yellow bg, black text
|
|
30
|
+
msgColor = "\x1b[33m"; // yellow text
|
|
31
|
+
break;
|
|
32
|
+
case LogLevel.INFO:
|
|
33
|
+
tag = "[INFO]";
|
|
34
|
+
tagColor = "\x1b[44;37m"; // blue bg, white text
|
|
35
|
+
msgColor = "\x1b[36m"; // cyan text
|
|
36
|
+
break;
|
|
37
|
+
case LogLevel.DEBUG:
|
|
38
|
+
tag = "[DEBUG]";
|
|
39
|
+
tagColor = "\x1b[45;37m"; // magenta bg, white text
|
|
40
|
+
msgColor = "\x1b[90m"; // gray text
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const ts = new Date().toLocaleTimeString("en-us");
|
|
44
|
+
const formattedArgs = [
|
|
45
|
+
`${ts} Elegance-JS `,
|
|
46
|
+
`${tagColor}${tag}\x1b[0m `,
|
|
47
|
+
msgColor,
|
|
48
|
+
...args,
|
|
49
|
+
"\x1b[0m"
|
|
50
|
+
];
|
|
51
|
+
return formattedArgs.map(arg => {
|
|
52
|
+
if (typeof arg === "string")
|
|
53
|
+
return arg;
|
|
54
|
+
return util.inspect(arg, { colors: false, depth: null });
|
|
55
|
+
}).join('');
|
|
56
|
+
}
|
|
57
|
+
function formattedLog(level, ...args) {
|
|
58
|
+
if (level > logLevel) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const str = formatToLog(level, ...args);
|
|
62
|
+
console.log(str);
|
|
63
|
+
}
|
|
64
|
+
export { formattedLog, setLogLevel, LogLevel, logLevel, formatToLog, };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CompilerOptions } from "../compilation/compiler";
|
|
2
|
+
import { AnyElement } from "../elements/element";
|
|
3
|
+
import { LayoutInformation } from "./layout";
|
|
4
|
+
type PageParams = Record<any, unknown>;
|
|
5
|
+
type PageConstructor = ((params: PageParams) => AnyElement) | ((params: PageParams) => Promise<AnyElement>);
|
|
6
|
+
type PageMetadataConstructor = ((params: PageParams) => AnyElement) | ((params: PageParams) => Promise<AnyElement>);
|
|
7
|
+
/**
|
|
8
|
+
* Described the formatted supported exports of a given page.
|
|
9
|
+
*/
|
|
10
|
+
type PageExports = {
|
|
11
|
+
isDynamic: boolean;
|
|
12
|
+
pageConstructor: PageConstructor;
|
|
13
|
+
pageMetadataConstructor: PageMetadataConstructor;
|
|
14
|
+
enumerateRoutes: (() => string[]) | null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Holds information about a given user-defined page within the project.
|
|
18
|
+
*/
|
|
19
|
+
type PageInformation = {
|
|
20
|
+
/** The absolute path to the .ts file containing the module for this page. */
|
|
21
|
+
modulePath: string;
|
|
22
|
+
/** The pathname of this page relative to pagesDirectory */
|
|
23
|
+
pathname: string;
|
|
24
|
+
exports: PageExports;
|
|
25
|
+
/** This is just the result of pathname.split("/") */
|
|
26
|
+
pathnameParts: string[];
|
|
27
|
+
/** An in-order list of the layouts that apply to this page. */
|
|
28
|
+
applicableLayouts: LayoutInformation[];
|
|
29
|
+
};
|
|
30
|
+
declare function invalidPageError(compilerOptions: CompilerOptions, modulePath: string, reason: string): Error;
|
|
31
|
+
export { invalidPageError, };
|
|
32
|
+
export type { PageInformation, PageExports, PageParams, PageConstructor, PageMetadataConstructor, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { relative } from "path";
|
|
2
|
+
function invalidPageError(compilerOptions, modulePath, reason) {
|
|
3
|
+
const relativePath = relative(compilerOptions.pagesDirectory, modulePath);
|
|
4
|
+
return new Error(`The page at path: "${relativePath}" is invalid.\n${reason}`);
|
|
5
|
+
}
|
|
6
|
+
export { invalidPageError, };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { formattedLog, LogLevel } from "./log.js";
|
|
4
|
+
import { createServer } from "http";
|
|
5
|
+
let child;
|
|
6
|
+
let childPath;
|
|
7
|
+
const clients = new Set();
|
|
8
|
+
let server;
|
|
9
|
+
let serverIsActive = false;
|
|
10
|
+
/**
|
|
11
|
+
* Run the elegance runtime, and if hot-reloading is enabled, will start the hot-reload server.
|
|
12
|
+
* @param file The runtime file to execute.
|
|
13
|
+
*/
|
|
14
|
+
function startEleganceRuntime(file) {
|
|
15
|
+
formattedLog(LogLevel.INFO, "Starting Elegance..");
|
|
16
|
+
childPath = resolve(file);
|
|
17
|
+
server = createServer((req, res) => {
|
|
18
|
+
formattedLog(LogLevel.DEBUG, "Received hot-reload listener.");
|
|
19
|
+
if (req.url === "/elegance-hot-reload") {
|
|
20
|
+
res.writeHead(200, {
|
|
21
|
+
"Content-Type": "text/event-stream",
|
|
22
|
+
"Cache-Control": "no-cache",
|
|
23
|
+
"Connection": "keep-alive",
|
|
24
|
+
"Access-Control-Allow-Origin": "*"
|
|
25
|
+
});
|
|
26
|
+
res.write(":ok\n\n");
|
|
27
|
+
clients.add(res);
|
|
28
|
+
req.on("close", () => {
|
|
29
|
+
clients.delete(res);
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
res.writeHead(404);
|
|
34
|
+
res.end();
|
|
35
|
+
});
|
|
36
|
+
restartEleganceRuntime();
|
|
37
|
+
}
|
|
38
|
+
function restartEleganceRuntime() {
|
|
39
|
+
if (child && child.killed === false) {
|
|
40
|
+
child.kill();
|
|
41
|
+
}
|
|
42
|
+
child = spawn("node", ["--import", "ts-arc/register", childPath], {
|
|
43
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
44
|
+
env: { ...process.env }
|
|
45
|
+
});
|
|
46
|
+
child.on("message", (content) => {
|
|
47
|
+
if (content === "restart-me") {
|
|
48
|
+
formattedLog(LogLevel.INFO, "Rebuilding..");
|
|
49
|
+
restartEleganceRuntime();
|
|
50
|
+
}
|
|
51
|
+
if (content === "hot-reload-finish") {
|
|
52
|
+
if (!serverIsActive) {
|
|
53
|
+
serverIsActive = true;
|
|
54
|
+
server.listen(4000, () => {
|
|
55
|
+
formattedLog(LogLevel.INFO, "Hot-reload server listening on port 4000");
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
for (const client of clients) {
|
|
59
|
+
client.write("data: hot-reload\n\n");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (content === "enable-hot-reload") {
|
|
63
|
+
}
|
|
64
|
+
if (content === "disable-hot-reload") {
|
|
65
|
+
if (!serverIsActive)
|
|
66
|
+
return;
|
|
67
|
+
serverIsActive = false;
|
|
68
|
+
server.close();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export { startEleganceRuntime, };
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,11 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The Elegance.JS server.
|
|
3
|
+
* This server can be used to run your project.
|
|
4
|
+
*
|
|
5
|
+
* It's HTTP only, so if you want HTTPS, use a proxy.
|
|
6
|
+
*/
|
|
7
|
+
import { CompiledLayout, CompiledPage } from "../compilation/compiler";
|
|
8
|
+
import { LayoutInformation } from "./layout";
|
|
9
|
+
import { PageInformation } from "./page";
|
|
10
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
11
|
+
import { URLSearchParams } from "url";
|
|
12
|
+
type ServerOptions = {
|
|
13
|
+
/** If a port is not available, it will increment the port +1 in a loop until it finds a valid one. */
|
|
14
|
+
port: number;
|
|
15
|
+
hostname: string;
|
|
16
|
+
/** Whether or not to use the built-in api handler. */
|
|
17
|
+
serveAPI: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Setting this to true allows dynamic pages to be compiled whenever a user requests them.
|
|
20
|
+
*/
|
|
21
|
+
allowDynamic: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Setting this to true will make statuscode pages like 404.ts be returned in-favor of simple HTTP error codes.
|
|
24
|
+
*/
|
|
25
|
+
allowStatusCodePages: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If basename is /my-website/, and the user makes a request to `/my-website/home`,
|
|
28
|
+
* the page that we will look for will be `/home`.
|
|
29
|
+
*/
|
|
30
|
+
base?: string;
|
|
31
|
+
/** These are gathered by the compiler, you just need to pass them in. */
|
|
32
|
+
allLayouts: Map<string, LayoutInformation>;
|
|
33
|
+
/** These are gathered by the compiler, you just need to pass them in. */
|
|
34
|
+
allPages: Map<string, PageInformation>;
|
|
35
|
+
/** These are gathered by the compiler, you just need to pass them in. */
|
|
36
|
+
allStatusCodePages: Map<string, PageInformation>;
|
|
37
|
+
/** These are gathered by the compiler, you just need to pass them in. */
|
|
38
|
+
builtStaticPages: Map<string, CompiledPage>;
|
|
39
|
+
/** These are gathered by the compiler, you just need to pass them in. */
|
|
40
|
+
builtStaticLayouts: Map<string, CompiledLayout>;
|
|
41
|
+
};
|
|
42
|
+
type ServerStartupResult = {
|
|
43
|
+
/** The port that we ended up actually using (might differ from the one given, if it was not available) */
|
|
44
|
+
port: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Starts the Elegance server and distributes the DIST directory to the public.
|
|
48
|
+
* If hot-reloading is enabled, this also tells the clients to refresh the page.
|
|
49
|
+
*/
|
|
50
|
+
declare function serveProject(startupServerOptions: ServerOptions): Promise<ServerStartupResult>;
|
|
51
|
+
/** Get the current query as `URLSearchParams` */
|
|
52
|
+
declare function getQuery(): URLSearchParams;
|
|
53
|
+
/** Get the current page's request and response. */
|
|
54
|
+
declare function getRequest(): {
|
|
55
|
+
req: IncomingMessage;
|
|
56
|
+
res: ServerResponse;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Get the cookies for the current request.
|
|
60
|
+
* Requires a dynamic page.
|
|
61
|
+
*/
|
|
62
|
+
declare function getCookieStore(): {
|
|
63
|
+
/**
|
|
64
|
+
* Get a cookie value by name
|
|
65
|
+
*/
|
|
66
|
+
get(name: string): string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Check if a cookie exists
|
|
69
|
+
*/
|
|
70
|
+
has(name: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Get all cookies as a plain object
|
|
73
|
+
*/
|
|
74
|
+
getAll(): Record<string, string>;
|
|
75
|
+
/**
|
|
76
|
+
* Set a cookie
|
|
77
|
+
*
|
|
78
|
+
* @param name Cookie name
|
|
79
|
+
* @param value Cookie value
|
|
80
|
+
* @param options Optional cookie attributes
|
|
81
|
+
*/
|
|
82
|
+
set(name: string, value: string, options?: {
|
|
83
|
+
maxAge?: number;
|
|
84
|
+
expires?: Date;
|
|
85
|
+
path?: string;
|
|
86
|
+
domain?: string;
|
|
87
|
+
secure?: boolean;
|
|
88
|
+
httpOnly?: boolean;
|
|
89
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
90
|
+
}): void;
|
|
91
|
+
/**
|
|
92
|
+
* Delete a cookie (sets it to expire immediately)
|
|
93
|
+
*/
|
|
94
|
+
delete(name: string, path?: string, domain?: string): void;
|
|
95
|
+
};
|
|
96
|
+
declare function redirect(location: string, statusCode?: number): void;
|
|
97
|
+
declare const respondWith: {
|
|
98
|
+
notFound(): Promise<void>;
|
|
99
|
+
notAuthorized(): Promise<void>;
|
|
100
|
+
forbidden(): Promise<void>;
|
|
101
|
+
internalError(): Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
export { serveProject, getQuery, getRequest, getCookieStore, redirect, respondWith };
|