@weft-framework/server 0.0.0-stage → 0.0.3

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/account.d.ts +124 -0
  4. package/dist/account.js +344 -0
  5. package/dist/action.d.ts +43 -0
  6. package/dist/action.js +135 -0
  7. package/dist/admin.d.ts +99 -0
  8. package/dist/admin.js +431 -0
  9. package/dist/api.d.ts +21 -0
  10. package/dist/api.js +72 -0
  11. package/dist/app.d.ts +202 -0
  12. package/dist/app.js +3692 -0
  13. package/dist/assets.d.ts +4 -0
  14. package/dist/assets.js +91 -0
  15. package/dist/auth.d.ts +150 -0
  16. package/dist/auth.js +215 -0
  17. package/dist/backup.d.ts +46 -0
  18. package/dist/backup.js +345 -0
  19. package/dist/build.d.ts +33 -0
  20. package/dist/build.js +274 -0
  21. package/dist/bun.d.ts +30 -0
  22. package/dist/bun.js +53 -0
  23. package/dist/calendar.d.ts +161 -0
  24. package/dist/calendar.js +690 -0
  25. package/dist/compiler.d.ts +13 -0
  26. package/dist/compiler.js +58 -0
  27. package/dist/compress.d.ts +6 -0
  28. package/dist/compress.js +78 -0
  29. package/dist/config.d.ts +26 -0
  30. package/dist/config.js +317 -0
  31. package/dist/context.d.ts +9 -0
  32. package/dist/context.js +1 -0
  33. package/dist/contract.d.ts +18 -0
  34. package/dist/contract.js +171 -0
  35. package/dist/datamap.d.ts +24 -0
  36. package/dist/datamap.js +365 -0
  37. package/dist/db-backup.d.ts +27 -0
  38. package/dist/db-backup.js +115 -0
  39. package/dist/dev-events.d.ts +14 -0
  40. package/dist/dev-events.js +135 -0
  41. package/dist/dev.d.ts +1 -0
  42. package/dist/dev.js +240 -0
  43. package/dist/devtools-client.d.ts +1 -0
  44. package/dist/devtools-client.js +362 -0
  45. package/dist/devtools.d.ts +87 -0
  46. package/dist/devtools.js +68 -0
  47. package/dist/edge.d.ts +3 -0
  48. package/dist/edge.js +7 -0
  49. package/dist/email-signin.d.ts +92 -0
  50. package/dist/email-signin.js +259 -0
  51. package/dist/env.d.ts +1 -0
  52. package/dist/env.js +15 -0
  53. package/dist/explain.d.ts +12 -0
  54. package/dist/explain.js +217 -0
  55. package/dist/files.d.ts +6 -0
  56. package/dist/files.js +170 -0
  57. package/dist/grants.d.ts +69 -0
  58. package/dist/grants.js +206 -0
  59. package/dist/image/bitmap.d.ts +11 -0
  60. package/dist/image/bitmap.js +172 -0
  61. package/dist/image/jpeg.d.ts +10 -0
  62. package/dist/image/jpeg.js +697 -0
  63. package/dist/image/png.d.ts +8 -0
  64. package/dist/image/png.js +282 -0
  65. package/dist/image/transform.d.ts +20 -0
  66. package/dist/image/transform.js +52 -0
  67. package/dist/image/worker.d.ts +1 -0
  68. package/dist/image/worker.js +11 -0
  69. package/dist/images.d.ts +39 -0
  70. package/dist/images.js +283 -0
  71. package/dist/index.d.ts +64 -0
  72. package/dist/index.js +31 -0
  73. package/dist/inspect-hub.d.ts +42 -0
  74. package/dist/inspect-hub.js +14 -0
  75. package/dist/inspector.d.ts +51 -0
  76. package/dist/inspector.js +193 -0
  77. package/dist/job-admin.d.ts +55 -0
  78. package/dist/job-admin.js +89 -0
  79. package/dist/jobs.d.ts +222 -0
  80. package/dist/jobs.js +789 -0
  81. package/dist/live.d.ts +72 -0
  82. package/dist/live.js +481 -0
  83. package/dist/load-config.d.ts +2 -0
  84. package/dist/load-config.js +41 -0
  85. package/dist/log.d.ts +20 -0
  86. package/dist/log.js +143 -0
  87. package/dist/mail.d.ts +189 -0
  88. package/dist/mail.js +999 -0
  89. package/dist/media.d.ts +129 -0
  90. package/dist/media.js +470 -0
  91. package/dist/meta.d.ts +54 -0
  92. package/dist/meta.js +146 -0
  93. package/dist/middleware.d.ts +20 -0
  94. package/dist/middleware.js +101 -0
  95. package/dist/migrate.d.ts +12 -0
  96. package/dist/migrate.js +88 -0
  97. package/dist/node.d.ts +26 -0
  98. package/dist/node.js +96 -0
  99. package/dist/notice.d.ts +21 -0
  100. package/dist/notice.js +48 -0
  101. package/dist/npm.d.ts +16 -0
  102. package/dist/npm.js +347 -0
  103. package/dist/oauth.d.ts +76 -0
  104. package/dist/oauth.js +408 -0
  105. package/dist/otel.d.ts +57 -0
  106. package/dist/otel.js +293 -0
  107. package/dist/passkey.d.ts +99 -0
  108. package/dist/passkey.js +572 -0
  109. package/dist/password.d.ts +8 -0
  110. package/dist/password.js +65 -0
  111. package/dist/pdf.d.ts +46 -0
  112. package/dist/pdf.js +332 -0
  113. package/dist/personal-data.d.ts +22 -0
  114. package/dist/personal-data.js +148 -0
  115. package/dist/pointers.d.ts +9 -0
  116. package/dist/pointers.js +148 -0
  117. package/dist/postcss.d.ts +3 -0
  118. package/dist/postcss.js +89 -0
  119. package/dist/presence.d.ts +27 -0
  120. package/dist/presence.js +161 -0
  121. package/dist/preview.d.ts +25 -0
  122. package/dist/preview.js +353 -0
  123. package/dist/production.d.ts +16 -0
  124. package/dist/production.js +119 -0
  125. package/dist/project.d.ts +23 -0
  126. package/dist/project.js +536 -0
  127. package/dist/regions.d.ts +47 -0
  128. package/dist/regions.js +511 -0
  129. package/dist/replay.d.ts +44 -0
  130. package/dist/replay.js +259 -0
  131. package/dist/router.d.ts +29 -0
  132. package/dist/router.js +146 -0
  133. package/dist/rules-diff.d.ts +18 -0
  134. package/dist/rules-diff.js +165 -0
  135. package/dist/rules-test.d.ts +17 -0
  136. package/dist/rules-test.js +108 -0
  137. package/dist/saml.d.ts +160 -0
  138. package/dist/saml.js +959 -0
  139. package/dist/seal.d.ts +35 -0
  140. package/dist/seal.js +107 -0
  141. package/dist/secret.d.ts +14 -0
  142. package/dist/secret.js +110 -0
  143. package/dist/security.d.ts +53 -0
  144. package/dist/security.js +250 -0
  145. package/dist/seed.d.ts +16 -0
  146. package/dist/seed.js +94 -0
  147. package/dist/seo.d.ts +42 -0
  148. package/dist/seo.js +175 -0
  149. package/dist/settings.d.ts +79 -0
  150. package/dist/settings.js +212 -0
  151. package/dist/shared.d.ts +15 -0
  152. package/dist/shared.js +283 -0
  153. package/dist/shell.d.ts +12 -0
  154. package/dist/shell.js +118 -0
  155. package/dist/storage.d.ts +13 -0
  156. package/dist/storage.js +55 -0
  157. package/dist/support.d.ts +83 -0
  158. package/dist/support.js +236 -0
  159. package/dist/sync.d.ts +35 -0
  160. package/dist/sync.js +167 -0
  161. package/dist/tailwind.d.ts +14 -0
  162. package/dist/tailwind.js +117 -0
  163. package/dist/two-factor.d.ts +103 -0
  164. package/dist/two-factor.js +435 -0
  165. package/dist/uploads.d.ts +185 -0
  166. package/dist/uploads.js +991 -0
  167. package/dist/webhooks.d.ts +169 -0
  168. package/dist/webhooks.js +758 -0
  169. package/dist/webpush.d.ts +97 -0
  170. package/dist/webpush.js +372 -0
  171. package/dist/wizard.d.ts +141 -0
  172. package/dist/wizard.js +410 -0
  173. package/dist/workflows.d.ts +134 -0
  174. package/dist/workflows.js +511 -0
  175. package/package.json +186 -4
@@ -0,0 +1,115 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { randomUUID } from "node:crypto";
10
+ import { existsSync, realpathSync, rmSync } from "node:fs";
11
+ import { join, resolve } from "node:path";
12
+ import { fileURLToPath, pathToFileURL } from "node:url";
13
+ import { parseArgs } from "node:util";
14
+ import { defineBackups } from "./backup.js";
15
+ import { CompileError, findCompiler } from "./compiler.js";
16
+ import { ConfigError } from "./config.js";
17
+ import { ProjectError, loadProject } from "./project.js";
18
+ export class BackupCommandError extends Error {
19
+ }
20
+ export async function backupProject(root, compiler, cmd) {
21
+ root = resolve(root);
22
+ const outDir = join(root, ".weft", "backup", randomUUID());
23
+ try {
24
+ const project = await loadProject(root, { compiler, outDir, browserAssets: false, cacheKey: outDir });
25
+ const database = project.database;
26
+ if (database === undefined || database === ":memory:") {
27
+ throw new BackupCommandError("no `database` file in weft.config.ts; there is nothing to back up");
28
+ }
29
+ const file = ["backup.ts", "backup.js"].map((name) => join(outDir, name)).find((f) => existsSync(f));
30
+ if (!file) {
31
+ throw new BackupCommandError("no src/backup.ts; export `target` from it (dirBackups(...) or s3Backups(...))");
32
+ }
33
+ const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
34
+ if (!mod.target || typeof mod.target.put !== "function") {
35
+ throw new BackupCommandError("src/backup: export `target`, a dirBackups(...) or s3Backups(...)");
36
+ }
37
+ const backups = defineBackups({ database, target: mod.target, ...(mod.keep !== undefined ? { keep: mod.keep } : {}) });
38
+ switch (cmd.command) {
39
+ case "backup":
40
+ return { command: "backup", database, file: await backups.run() };
41
+ case "list":
42
+ return { command: "list", database, files: await backups.list() };
43
+ case "restore": {
44
+ if ((cmd.env ?? process.env).NODE_ENV === "production") {
45
+ throw new BackupCommandError("refusing to restore with NODE_ENV=production; stop the server and unset it to confirm");
46
+ }
47
+ return { command: "restore", database, ...(await backups.restore(cmd.name)) };
48
+ }
49
+ }
50
+ }
51
+ finally {
52
+ rmSync(outDir, { recursive: true, force: true });
53
+ }
54
+ }
55
+ async function main() {
56
+ const { values, positionals } = parseArgs({
57
+ allowPositionals: true,
58
+ options: { command: { type: "string" }, name: { type: "string" }, yes: { type: "boolean" } },
59
+ });
60
+ const root = resolve(positionals[0] ?? ".");
61
+ try {
62
+ const command = values.command;
63
+ let cmd;
64
+ if (command === "backup" || command === "list") {
65
+ cmd = { command };
66
+ }
67
+ else if (command === "restore") {
68
+ if (!values.name)
69
+ throw new BackupCommandError("`weft db restore` needs --name <file> (see `weft db backups`)");
70
+ if (values.yes !== true)
71
+ throw new BackupCommandError("`weft db restore` replaces the database; stop the server and run it again with --yes");
72
+ cmd = { command, name: values.name };
73
+ }
74
+ else {
75
+ throw new BackupCommandError("expected backup, backups or restore");
76
+ }
77
+ const r = await backupProject(root, findCompiler(root), cmd);
78
+ if (r.command === "backup") {
79
+ console.log(`[weft] backed up ${r.database} as ${r.file.name} (${r.file.size} bytes)`);
80
+ }
81
+ else if (r.command === "list") {
82
+ console.log(`[weft] backups of ${r.database}:`);
83
+ if (r.files.length === 0)
84
+ console.log(" none");
85
+ for (const f of r.files)
86
+ console.log(` ${f.name} ${f.size} bytes ${new Date(f.time).toISOString()}`);
87
+ }
88
+ else {
89
+ console.log(`[weft] restored ${r.database}${r.previous ? `; the previous database is at ${r.previous}` : ""}`);
90
+ }
91
+ }
92
+ catch (err) {
93
+ if (err instanceof CompileError) {
94
+ console.error(err.diagnostics);
95
+ }
96
+ else if (err instanceof BackupCommandError || err instanceof ProjectError || err instanceof ConfigError) {
97
+ console.error(`[weft] ${err.message}`);
98
+ }
99
+ else {
100
+ console.error("[weft] db:", err instanceof Error ? err.message : err);
101
+ }
102
+ process.exit(1);
103
+ }
104
+ }
105
+ function isEntry() {
106
+ try {
107
+ return !!process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
108
+ }
109
+ catch {
110
+ return false;
111
+ }
112
+ }
113
+ if (isEntry()) {
114
+ await main();
115
+ }
@@ -0,0 +1,14 @@
1
+ export declare function overlayText(text: string): string;
2
+ export declare class DevEvents {
3
+ private streams;
4
+ private error;
5
+ private builds;
6
+ reload(): void;
7
+ fail(text: string): void;
8
+ get current(): string | null;
9
+ response(): Response;
10
+ close(): void;
11
+ private errorMessage;
12
+ private send;
13
+ }
14
+ export declare const DEV_CLIENT_JS: string;
@@ -0,0 +1,135 @@
1
+ import { DEV_PANEL_JS } from "./devtools-client.js";
2
+ const enc = new TextEncoder();
3
+ export function overlayText(text) {
4
+ const plain = text.replace(/\x1b\[[0-9;]*[A-Za-z]/g, "");
5
+ return plain.length > 20_000 ? plain.slice(0, 20_000) + "\n..." : plain;
6
+ }
7
+ export class DevEvents {
8
+ streams = new Set();
9
+ error = null;
10
+ builds = 0;
11
+ reload() {
12
+ this.error = null;
13
+ this.builds += 1;
14
+ this.send("data: reload\n\n");
15
+ }
16
+ fail(text) {
17
+ this.error = overlayText(text);
18
+ this.send(this.errorMessage());
19
+ }
20
+ get current() {
21
+ return this.error;
22
+ }
23
+ response() {
24
+ let ctl = null;
25
+ const body = new ReadableStream({
26
+ start: (c) => {
27
+ ctl = c;
28
+ this.streams.add(c);
29
+ c.enqueue(enc.encode(`: dev\n\nevent: weft-build\ndata: ${this.builds}\n\n`));
30
+ if (this.error !== null) {
31
+ c.enqueue(enc.encode(this.errorMessage()));
32
+ }
33
+ },
34
+ cancel: () => {
35
+ if (ctl) {
36
+ this.streams.delete(ctl);
37
+ }
38
+ },
39
+ });
40
+ return new Response(body, {
41
+ headers: { "content-type": "text/event-stream", "cache-control": "no-store", "x-content-type-options": "nosniff" },
42
+ });
43
+ }
44
+ close() {
45
+ for (const c of this.streams) {
46
+ try {
47
+ c.close();
48
+ }
49
+ catch {
50
+ }
51
+ }
52
+ this.streams.clear();
53
+ }
54
+ errorMessage() {
55
+ return `event: weft-error\ndata: ${JSON.stringify(this.error)}\n\n`;
56
+ }
57
+ send(message) {
58
+ const bytes = enc.encode(message);
59
+ for (const c of this.streams) {
60
+ try {
61
+ c.enqueue(bytes);
62
+ }
63
+ catch {
64
+ this.streams.delete(c);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ const BUILD_OVERLAY_JS = `const ID = "weft-dev-overlay";
70
+ let es = null;
71
+ let build = null;
72
+ function listen() {
73
+ es = new EventSource("/_weft/dev/events");
74
+ es.onmessage = () => location.reload();
75
+ es.addEventListener("weft-build", (e) => {
76
+ if (build !== null && build !== e.data) location.reload();
77
+ build = e.data;
78
+ });
79
+ es.addEventListener("weft-error", (e) => {
80
+ let text = "";
81
+ try { text = String(JSON.parse(e.data)); } catch { text = "Build failed"; }
82
+ show(text);
83
+ });
84
+ }
85
+ listen();
86
+ let hidden = null;
87
+ document.addEventListener?.("visibilitychange", () => {
88
+ clearTimeout(hidden);
89
+ hidden = null;
90
+ if (document.visibilityState === "hidden") {
91
+ hidden = setTimeout(() => { es?.close(); es = null; }, 10000);
92
+ } else if (!es) {
93
+ listen();
94
+ }
95
+ });
96
+
97
+ function css(el, props) {
98
+ for (const [k, v] of Object.entries(props)) el.style.setProperty(k, v);
99
+ return el;
100
+ }
101
+
102
+ function show(text) {
103
+ document.getElementById(ID)?.remove();
104
+ const root = css(document.createElement("div"), {
105
+ position: "fixed", inset: "0", "z-index": "2147483647", overflow: "auto",
106
+ background: "rgba(255,255,255,0.97)", color: "#1a1a1a",
107
+ font: "13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
108
+ padding: "24px",
109
+ });
110
+ root.id = ID;
111
+ root.setAttribute("role", "alertdialog");
112
+ root.setAttribute("aria-label", "Build failed");
113
+ const head = css(document.createElement("div"), {
114
+ display: "flex", "justify-content": "space-between", "align-items": "baseline",
115
+ "border-bottom": "1px solid #d0d0d0", "padding-bottom": "8px", "margin-bottom": "16px",
116
+ });
117
+ const title = css(document.createElement("strong"), { color: "#b00020", "font-size": "14px" });
118
+ title.textContent = "Build failed - the last good build is still being served";
119
+ const close = css(document.createElement("button"), {
120
+ font: "inherit", background: "none", border: "1px solid #b0b0b0", padding: "2px 10px", cursor: "pointer",
121
+ });
122
+ close.type = "button";
123
+ close.textContent = "Dismiss";
124
+ close.addEventListener("click", () => root.remove());
125
+ head.append(title, close);
126
+ const pre = css(document.createElement("pre"), { margin: "0", "white-space": "pre-wrap", "word-break": "break-word" });
127
+ pre.textContent = text;
128
+ const foot = css(document.createElement("p"), { color: "#666", "margin-top": "16px" });
129
+ foot.textContent = "Fix the error and save: the page reloads when the build succeeds.";
130
+ root.append(head, pre, foot);
131
+ document.body.append(root);
132
+ close.focus();
133
+ }
134
+ `;
135
+ export const DEV_CLIENT_JS = BUILD_OVERLAY_JS + DEV_PANEL_JS;
package/dist/dev.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/dev.js ADDED
@@ -0,0 +1,240 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { mkdirSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
10
+ import { basename, dirname, join, resolve, sep } from "node:path";
11
+ import { pathToFileURL } from "node:url";
12
+ import { parseArgs } from "node:util";
13
+ import { createApp } from "./app.js";
14
+ import { islandAssets } from "./assets.js";
15
+ import { loadEnvFile } from "./env.js";
16
+ import { CompileError, compileClient, compileFile, findCompiler } from "./compiler.js";
17
+ import { runtimeAssets, serveNode } from "./node.js";
18
+ import { ConfigError, resolveSecret } from "./config.js";
19
+ import { loadConfig } from "./load-config.js";
20
+ import { mailPreview } from "./mail.js";
21
+ import { ProjectError, loadProject } from "./project.js";
22
+ import { randomId, securityHeaders } from "./security.js";
23
+ import { ModelStorage } from "./storage.js";
24
+ import { DEV_CLIENT_JS, DevEvents } from "./dev-events.js";
25
+ function pick(mod, name, file) {
26
+ const comps = Object.entries(mod).filter(([, v]) => typeof v === "function" && "def" in v);
27
+ const wanted = name ?? basename(file, ".wx");
28
+ const match = comps.find(([k]) => k === wanted)?.[1];
29
+ if (match || name) {
30
+ return match ?? null;
31
+ }
32
+ return comps.length === 1 ? comps[0][1] : null;
33
+ }
34
+ function noBuildYet(path) {
35
+ if (path === "/_weft/dev.js") {
36
+ return new Response(DEV_CLIENT_JS, {
37
+ headers: { "content-type": "text/javascript; charset=utf-8", "cache-control": "no-store" },
38
+ });
39
+ }
40
+ const nonce = randomId(16);
41
+ const html = `<!doctype html>\n<html lang="en"><head><meta charset="utf-8"><title>Build failed</title></head>` +
42
+ `<body><p>The project does not build yet; the error is shown above once loaded.</p>` +
43
+ `<script type="module" nonce="${nonce}" src="/_weft/dev.js"></script></body></html>\n`;
44
+ return new Response(html, {
45
+ status: 503,
46
+ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", ...securityHeaders({ nonce, secure: false }) },
47
+ });
48
+ }
49
+ async function main() {
50
+ const { values, positionals } = parseArgs({
51
+ allowPositionals: true,
52
+ options: {
53
+ port: { type: "string" },
54
+ host: { type: "string" },
55
+ component: { type: "string" },
56
+ route: { type: "string", default: "/" },
57
+ },
58
+ });
59
+ const target = resolve(positionals[0] ?? ".");
60
+ const isFile = target.endsWith(".wx");
61
+ if (!isFile && !statSync(target, { throwIfNoEntry: false })?.isDirectory()) {
62
+ console.error("usage: dev.ts [project-dir | file.wx] [--port N] [--host H]");
63
+ process.exit(2);
64
+ }
65
+ const root = isFile ? dirname(target) : target;
66
+ const compiler = findCompiler(root);
67
+ const devDir = join(root, ".weft", "dev");
68
+ rmSync(devDir, { recursive: true, force: true });
69
+ let version = 0;
70
+ let templates = {};
71
+ const buildProject = async () => {
72
+ const outDir = join(devDir, String(version));
73
+ return loadProject(root, {
74
+ compiler,
75
+ outDir,
76
+ publicFiles: { cacheControl: "no-cache" },
77
+ cacheKey: String(version),
78
+ onWarn: (m) => console.warn(`weft: ${m}`),
79
+ });
80
+ };
81
+ const buildFile = async () => {
82
+ const outDir = join(devDir, String(version));
83
+ mkdirSync(outDir, { recursive: true });
84
+ const out = join(outDir, `${basename(target, ".wx")}.ts`);
85
+ writeFileSync(out, compileFile(compiler, target));
86
+ const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(out).href)));
87
+ const component = pick(mod, values.component, target);
88
+ if (!component) {
89
+ throw new ProjectError(`no component ${values.component ?? basename(target, ".wx")}; choose one with --component`);
90
+ }
91
+ const client = compileClient(compiler, target);
92
+ return {
93
+ routes: { [values.route]: { component: component, title: component.def.name } },
94
+ assets: islandAssets(client ? { [`${basename(target, ".wx")}.client.ts`]: client } : {}, {
95
+ root: dirname(target),
96
+ onWarn: (m) => console.warn(`weft: ${m}`),
97
+ }),
98
+ };
99
+ };
100
+ let configPort;
101
+ let configHost;
102
+ let secret = randomId(32);
103
+ if (!isFile) {
104
+ try {
105
+ loadEnvFile(join(root, ".env"));
106
+ const config = await loadConfig(root);
107
+ configPort = config.port;
108
+ configHost = config.host;
109
+ secret = resolveSecret(config, process.env, process.env.NODE_ENV === "production") ?? secret;
110
+ }
111
+ catch (err) {
112
+ if (err instanceof ConfigError) {
113
+ console.error(`[weft] ${err.message}`);
114
+ process.exit(1);
115
+ }
116
+ throw err;
117
+ }
118
+ }
119
+ const port = Number(values.port ?? configPort ?? 3000);
120
+ const host = values.host ?? configHost ?? "127.0.0.1";
121
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
122
+ console.error("[weft] port must be an integer from 0 to 65535");
123
+ process.exit(2);
124
+ }
125
+ const runtime = runtimeAssets();
126
+ const devAssets = {
127
+ "/_weft/client.js": `${runtime["/_weft/client.js"]}import "./dev.js";\n`,
128
+ "/_weft/dev.js": DEV_CLIENT_JS,
129
+ };
130
+ let app = null;
131
+ const storage = new ModelStorage();
132
+ const events = new DevEvents();
133
+ const rebuild = async () => {
134
+ version += 1;
135
+ const started = performance.now();
136
+ try {
137
+ const { models, database, emails, ...build } = await (isFile ? buildFile() : buildProject());
138
+ templates = emails ?? {};
139
+ await storage.attach(Object.values(models ?? {}), {
140
+ database,
141
+ onWarning: (m) => console.warn(`[weft] database: ${m}`),
142
+ });
143
+ const next = createApp({
144
+ ...build,
145
+ secret,
146
+ assets: { ...runtime, ...build.assets, ...devAssets },
147
+ transports: ["sse"],
148
+ devtools: true,
149
+ });
150
+ app?.close();
151
+ app = next;
152
+ const ms = Math.round(performance.now() - started);
153
+ const pages = Object.keys(build.routes).sort().join(" ");
154
+ console.log(`[weft] build ${version} ready in ${ms} ms: ${pages}`);
155
+ rmSync(join(devDir, String(version - 2)), { recursive: true, force: true });
156
+ return true;
157
+ }
158
+ catch (err) {
159
+ let text;
160
+ if (err instanceof CompileError) {
161
+ text = err.diagnostics;
162
+ }
163
+ else if (err instanceof ProjectError || err instanceof ConfigError) {
164
+ text = err.message;
165
+ }
166
+ else {
167
+ text = err instanceof Error ? (err.stack ?? err.message) : String(err);
168
+ }
169
+ console.error(err instanceof CompileError ? text : `[weft] ${text}`);
170
+ events.fail(text.split(root + sep).join(""));
171
+ return false;
172
+ }
173
+ };
174
+ await rebuild();
175
+ const reload = () => events.reload();
176
+ const devApp = {
177
+ drain: async (o) => (app ? app.drain(o) : true),
178
+ close: () => {
179
+ app?.close();
180
+ storage.close();
181
+ events.close();
182
+ },
183
+ websocket: {
184
+ open: (ws) => (app ? app.websocket.open(ws) : ws.close(1013, "no build")),
185
+ message: async (ws, data) => app?.websocket.message(ws, data),
186
+ close: (ws) => app?.websocket.close(ws),
187
+ },
188
+ async fetch(req, server) {
189
+ const path = new URL(req.url).pathname;
190
+ if (path === "/_weft/dev/events") {
191
+ return events.response();
192
+ }
193
+ const preview = mailPreview(req, templates);
194
+ if (preview) {
195
+ return preview;
196
+ }
197
+ if (app) {
198
+ return app.fetch(req, server);
199
+ }
200
+ return noBuildYet(path);
201
+ },
202
+ };
203
+ const server = await serveNode(devApp, { port, host });
204
+ console.log(`[weft] serving ${isFile ? basename(target) : root} at ${server.url}${isFile ? values.route : "/"}`);
205
+ let timer = null;
206
+ let pending = "reload";
207
+ const schedule = (what) => {
208
+ if (what === "build") {
209
+ pending = "build";
210
+ }
211
+ if (timer) {
212
+ clearTimeout(timer);
213
+ }
214
+ timer = setTimeout(async () => {
215
+ timer = null;
216
+ const kind = pending;
217
+ pending = "reload";
218
+ if (kind === "reload" || (await rebuild())) {
219
+ reload();
220
+ }
221
+ }, 80);
222
+ };
223
+ if (isFile) {
224
+ watch(target, () => schedule("build"));
225
+ }
226
+ else {
227
+ watch(join(root, "src"), { recursive: true }, () => schedule("build"));
228
+ const pub = join(root, "public");
229
+ if (statSync(pub, { throwIfNoEntry: false })?.isDirectory()) {
230
+ watch(pub, { recursive: true }, () => schedule("reload"));
231
+ }
232
+ for (const name of ["weft.config.ts", "weft.config.js", "postcss.config.js", "postcss.config.mjs", "postcss.config.cjs"]) {
233
+ const file = join(root, name);
234
+ if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
235
+ watch(file, () => schedule("build"));
236
+ }
237
+ }
238
+ }
239
+ }
240
+ await main();
@@ -0,0 +1 @@
1
+ export declare const DEV_PANEL_JS = "\nconst PANEL = \"weft-dev-panel\";\nconst INK = \"#1a1a1a\", MUTED = \"#6b6b6b\", RULE = \"#d4d4d4\", BG = \"#fbfbf9\", WARN = \"#b00020\", OK = \"#1d6b3a\";\nlet panel = null, view = \"tree\", timer = null, last = null, viewForm = null, viewNote = \"\";\n// Time travel: the step shown in place of the page (null: live).\nlet shown = null, shownBox = null, shownRoot = null, shownLid = \"\", shownNote = \"\";\n\nfunction el(tag, props, text) {\n const n = css(document.createElement(tag), props || {});\n if (text !== undefined) n.textContent = text;\n return n;\n}\nfunction lid() {\n return document.querySelector('meta[name=\"weft-live\"]')?.getAttribute(\"content\") || \"\";\n}\n\nlet toggle = null;\nif (typeof document.querySelector === \"function\" && document.body) installPanel();\nfunction installPanel() {\ntoggle = el(\"button\", {\n position: \"fixed\", right: \"8px\", bottom: \"8px\", \"z-index\": \"2147483646\",\n font: \"11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace\",\n background: BG, color: MUTED, border: \"1px solid \" + RULE, padding: \"4px 6px\", cursor: \"pointer\", opacity: \"0.8\",\n}, \"weft\");\ntoggle.type = \"button\";\ntoggle.title = \"Weft dev overlay (Alt+Shift+D)\";\ntoggle.setAttribute(\"aria-expanded\", \"false\");\ntoggle.addEventListener(\"click\", () => (panel ? closePanel() : openPanel()));\ndocument.body.append(toggle);\ndocument.addEventListener(\"keydown\", (e) => {\n if (e.altKey && e.shiftKey && (e.key === \"D\" || e.key === \"d\" || e.code === \"KeyD\")) {\n e.preventDefault();\n panel ? closePanel() : openPanel();\n }\n});\ndocument.addEventListener(\"visibilitychange\", () => {\n if (!panel) return;\n if (document.visibilityState === \"hidden\") stop(); else poll();\n});\n}\n\nfunction openPanel() {\n panel = el(\"section\", {\n position: \"fixed\", left: \"0\", right: \"0\", bottom: \"0\", height: \"38vh\", \"z-index\": \"2147483646\",\n display: \"flex\", \"flex-direction\": \"column\", background: BG, color: INK, \"border-top\": \"1px solid \" + RULE,\n font: \"12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace\",\n });\n panel.id = PANEL;\n panel.setAttribute(\"aria-label\", \"Weft dev overlay\");\n const bar = el(\"div\", { display: \"flex\", gap: \"16px\", \"align-items\": \"baseline\", padding: \"6px 12px\", \"border-bottom\": \"1px solid \" + RULE });\n bar.append(el(\"strong\", {}, \"weft dev\"));\n for (const [key, label] of [[\"tree\", \"Tree\"], [\"messages\", \"Messages\"], [\"data\", \"Data\"], [\"access\", \"Access\"], [\"time\", \"Time\"], [\"viewas\", \"View as\"]]) {\n const b = el(\"button\", { font: \"inherit\", background: \"none\", border: \"0\", padding: \"0\", cursor: \"pointer\", color: MUTED }, label);\n b.type = \"button\";\n b.dataset.view = key;\n b.addEventListener(\"click\", () => { view = key; draw(); });\n bar.append(b);\n }\n const status = el(\"span\", { \"margin-left\": \"auto\", color: MUTED });\n status.dataset.role = \"status\";\n const close = el(\"button\", { font: \"inherit\", background: \"none\", border: \"1px solid \" + RULE, padding: \"0 8px\", cursor: \"pointer\" }, \"Close\");\n close.type = \"button\";\n close.addEventListener(\"click\", closePanel);\n bar.append(status, close);\n const body = el(\"div\", { flex: \"1\", overflow: \"auto\", padding: \"8px 12px\" });\n body.dataset.role = \"body\";\n panel.append(bar, body);\n document.body.append(panel);\n toggle.setAttribute(\"aria-expanded\", \"true\");\n toggle.style.setProperty(\"display\", \"none\");\n poll();\n}\n\nfunction closePanel() {\n stop();\n live();\n panel?.remove();\n panel = null;\n toggle.setAttribute(\"aria-expanded\", \"false\");\n toggle.style.removeProperty(\"display\");\n toggle.focus();\n}\n\nfunction stop() {\n clearTimeout(timer);\n timer = null;\n}\n\nasync function poll() {\n stop();\n if (!panel) return;\n const id = lid();\n // Another page now (client navigation): its own states, from live.\n if (shown !== null && (id !== shownLid || !document.contains(shownRoot))) live();\n if (!id) {\n last = null;\n draw(\"This page is inert: it sends no live page, so there is nothing to inspect.\");\n return;\n }\n try {\n const res = await fetch(\"/_weft/dev/inspect?lid=\" + encodeURIComponent(id), { credentials: \"same-origin\", cache: \"no-store\" });\n if (res.ok) { last = await res.json(); draw(); }\n else { last = null; draw(res.status === 404 ? \"The live page expired or belongs to another session.\" : \"Inspect failed: HTTP \" + res.status); }\n } catch {\n last = null;\n draw(\"The dev server is not answering.\");\n }\n if (panel) timer = setTimeout(poll, 1000);\n}\n\nfunction table(head, rows) {\n const t = el(\"table\", { \"border-collapse\": \"collapse\", width: \"100%\" });\n const tr = el(\"tr\", {});\n for (const h of head) tr.append(el(\"th\", { \"text-align\": \"left\", color: MUTED, \"font-weight\": \"normal\", \"border-bottom\": \"1px solid \" + RULE, padding: \"2px 12px 2px 0\" }, h));\n t.append(tr);\n for (const row of rows) {\n const r = el(\"tr\", {});\n for (const cell of row) {\n const td = el(\"td\", { padding: \"2px 12px 2px 0\", \"vertical-align\": \"top\", \"border-bottom\": \"1px solid #ececea\" });\n if (cell && typeof cell === \"object\") { td.textContent = cell.text; css(td, { color: cell.color }); }\n else td.textContent = String(cell);\n r.append(td);\n }\n t.append(r);\n }\n return t;\n}\nfunction empty(text) {\n return el(\"p\", { color: MUTED, margin: \"0\" }, text);\n}\nfunction clock(ms) {\n const d = new Date(ms);\n return d.toLocaleTimeString(undefined, { hour12: false }) + \".\" + String(d.getMilliseconds()).padStart(3, \"0\");\n}\n\n// The \"View as\" form, built once so a refresh keeps what is typed in it.\nfunction viewAsForm() {\n if (viewForm) return viewForm;\n viewForm = el(\"form\", { display: \"flex\", \"flex-wrap\": \"wrap\", gap: \"8px\", \"align-items\": \"baseline\", margin: \"0 0 8px\" });\n const field = (label, name) => {\n const l = el(\"label\", { display: \"flex\", gap: \"4px\", \"align-items\": \"baseline\" }, label);\n const i = el(\"input\", { font: \"inherit\", border: \"1px solid \" + RULE, padding: \"1px 4px\", background: \"#fff\", color: INK });\n i.name = name;\n i.autocomplete = \"off\";\n i.spellcheck = false;\n l.append(i);\n return l;\n };\n const go = el(\"button\", { font: \"inherit\", border: \"1px solid \" + RULE, background: \"#fff\", padding: \"0 8px\", cursor: \"pointer\" }, \"View as\");\n go.type = \"submit\";\n const back = el(\"button\", { font: \"inherit\", border: \"1px solid \" + RULE, background: \"#fff\", padding: \"0 8px\", cursor: \"pointer\" }, \"Back to me\");\n back.type = \"button\";\n back.dataset.role = \"stop\";\n const said = el(\"p\", { margin: \"0\", width: \"100%\", color: MUTED });\n said.dataset.role = \"viewing\";\n viewForm.append(field(\"User id\", \"user\"), field(\"Tenant (optional)\", \"tenant\"), go, back, said);\n viewForm.addEventListener(\"submit\", (e) => {\n e.preventDefault();\n const user = viewForm.elements.user.value.trim();\n const tenant = viewForm.elements.tenant.value.trim();\n sendViewAs(tenant ? { user, tenant } : { user });\n });\n back.addEventListener(\"click\", () => sendViewAs({ user: null }));\n return viewForm;\n}\nasync function sendViewAs(body) {\n viewNote = \"...\";\n draw();\n try {\n const res = await fetch(\"/_weft/dev/view-as\", {\n method: \"POST\", credentials: \"same-origin\", cache: \"no-store\",\n headers: { \"content-type\": \"application/json\" }, body: JSON.stringify(body),\n });\n const out = await res.json().catch(() => ({}));\n viewNote = out.ok ? (out.viewing ? \"Now viewing as \" + out.viewing.user + \".\" : \"Back to your own view.\")\n : (out.reason || \"View as failed: HTTP \" + res.status);\n } catch {\n viewNote = \"The dev server is not answering.\";\n }\n poll();\n}\nfunction drawViewAs(body) {\n const form = viewAsForm();\n if (!body.contains(form)) {\n body.append(form, empty(\"Pages load and render as that user, read-only: every write rule refuses, and the reads are \"\n + \"audited as that user via you. It lasts an hour or until Back to me. Sign in first.\"));\n }\n const v = last && last.viewing;\n form.querySelector('[data-role=\"viewing\"]').textContent = (viewNote ? viewNote + \" \" : \"\")\n + (v ? \"This session sees the app as id \" + v.user + (v.tenant ? \" in \" + v.tenant : \"\") + \" until \" + clock(v.until) + \".\"\n : \"This session sees the app as you.\");\n form.querySelector('[data-role=\"stop\"]').disabled = !v;\n}\n\n// The live page's root instance (the body's first data-weft-c).\nfunction liveRoot() {\n return document.querySelector(\"body [data-weft-c]\");\n}\n// Show step n in place of the page: its HTML with every runtime hook\n// (data-weft-* attributes, scripts, inline handlers) taken out, inert, after the live\n// root, which is hidden and keeps receiving its patches.\nasync function showStep(n) {\n const id = lid();\n try {\n const res = await fetch(\"/_weft/dev/frame?lid=\" + encodeURIComponent(id) + \"&n=\" + n, { credentials: \"same-origin\", cache: \"no-store\" });\n if (!res.ok) { shownNote = res.status === 404 ? \"That step is no longer kept.\" : \"HTTP \" + res.status; draw(); return; }\n const f = await res.json();\n const doc = new DOMParser().parseFromString(\"<body>\" + f.html + \"</body>\", \"text/html\");\n for (const s of doc.querySelectorAll(\"script\")) s.remove();\n for (const node of doc.body.querySelectorAll(\"*\")) {\n for (const a of [...node.attributes]) {\n if (a.name.startsWith(\"data-weft-\") || a.name.startsWith(\"on\")) node.removeAttribute(a.name);\n }\n }\n const rootEl = liveRoot();\n if (!rootEl) return;\n if (!shownBox) {\n shownBox = document.createElement(\"div\");\n shownBox.id = \"weft-dev-step\";\n shownBox.inert = true;\n shownBox.setAttribute(\"aria-label\", \"An earlier state of this page (read-only)\");\n rootEl.after(shownBox);\n }\n shownBox.replaceChildren(...doc.body.childNodes);\n rootEl.style.setProperty(\"display\", \"none\", \"important\");\n shownRoot = rootEl;\n shownLid = id;\n shown = f.n;\n shownNote = \"\";\n } catch {\n shownNote = \"The dev server is not answering.\";\n }\n draw();\n}\n// Save the page's events (values redacted) as a file for weft replay.\nasync function download() {\n try {\n const res = await fetch(\"/_weft/dev/recording?lid=\" + encodeURIComponent(lid()), { credentials: \"same-origin\", cache: \"no-store\" });\n if (!res.ok) { shownNote = \"Recording failed: HTTP \" + res.status; draw(); return; }\n const url = URL.createObjectURL(await res.blob());\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = (location.pathname.replace(/[^A-Za-z0-9]+/g, \"-\").replace(/^-|-$/g, \"\") || \"index\") + \".weft-recording.json\";\n document.body.append(a);\n a.click();\n a.remove();\n setTimeout(() => URL.revokeObjectURL(url), 1000);\n shownNote = \"Saved. Replay it with: weft replay \" + a.download;\n } catch {\n shownNote = \"The dev server is not answering.\";\n }\n draw();\n}\n// Back to the live page.\nfunction live() {\n shownBox?.remove();\n shownRoot?.style.removeProperty(\"display\");\n shownBox = null;\n shownRoot = null;\n shown = null;\n}\nfunction button(label, onClick, disabled) {\n const b = el(\"button\", { font: \"inherit\", border: \"1px solid \" + RULE, background: \"#fff\", padding: \"0 8px\", cursor: disabled ? \"default\" : \"pointer\" }, label);\n b.type = \"button\";\n b.disabled = !!disabled;\n b.addEventListener(\"click\", onClick);\n return b;\n}\nfunction drawTime(body) {\n const frames = last.frames || [];\n if (frames.length === 0) { body.append(empty(\"No states kept yet.\")); return; }\n const at = shown === null ? frames.length - 1 : frames.findIndex((f) => f.n === shown);\n const bar = el(\"div\", { display: \"flex\", gap: \"8px\", \"align-items\": \"baseline\", margin: \"0 0 8px\" });\n bar.dataset.role = \"time\";\n bar.append(\n button(\"Back\", () => showStep(frames[Math.max(0, at - 1)].n), at <= 0),\n button(\"Forward\", () => (at + 1 >= frames.length - 1 && shown !== null ? (live(), draw()) : showStep(frames[at + 1].n)), shown === null),\n button(\"Live\", () => { live(); draw(); }, shown === null),\n button(\"Download recording\", download),\n el(\"span\", { color: shown === null ? MUTED : WARN },\n shown === null ? \"Showing the live page.\" : \"Showing step \" + shown + \", read-only: the live page goes on behind it.\"),\n );\n body.append(bar);\n if (shownNote) body.append(empty(shownNote));\n body.append(table([\"Step\", \"Time\", \"After\", \"Size\"], frames.slice().reverse().map((f) => [\n { text: (f.n === shown || (shown === null && f === frames[frames.length - 1]) ? \"> \" : \" \") + f.n, color: f.n === shown ? WARN : INK },\n clock(f.at), f.what, (f.bytes / 1024).toFixed(1) + \" KB\",\n ])));\n for (const [i, row] of [...body.querySelectorAll(\"tr\")].slice(1).entries()) {\n const f = frames[frames.length - 1 - i];\n css(row, { cursor: \"pointer\" });\n row.addEventListener(\"click\", () => (f === frames[frames.length - 1] ? (live(), draw()) : showStep(f.n)));\n }\n body.append(empty(\"The page's HTML after each event and refresh (the last \" + frames.length + \" kept). Island and client-drawn state is not part of it.\"));\n}\n\nfunction draw(notice) {\n if (!panel) return;\n for (const b of panel.querySelectorAll(\"button[data-view]\")) {\n const on = b.dataset.view === view;\n css(b, { color: on ? INK : MUTED, \"text-decoration\": on ? \"underline\" : \"none\" });\n b.setAttribute(\"aria-pressed\", String(on));\n }\n if (view === \"viewas\") {\n const status = panel.querySelector('[data-role=\"status\"]');\n const body = panel.querySelector('[data-role=\"body\"]');\n status.textContent = last ? last.path + \" page \" + last.lid.slice(0, 8) : \"\";\n if (!body.contains(viewForm)) body.replaceChildren();\n drawViewAs(body);\n return;\n }\n const status = panel.querySelector('[data-role=\"status\"]');\n const body = panel.querySelector('[data-role=\"body\"]');\n const top = body.scrollTop;\n body.replaceChildren();\n if (!last) {\n status.textContent = \"\";\n body.append(empty(notice || \"Loading...\"));\n return;\n }\n status.textContent = last.path + \" page \" + last.lid.slice(0, 8);\n if (view === \"tree\") {\n const rows = [];\n const walk = (n, depth) => {\n rows.push([\" \".repeat(depth) + n.name + (n.island ? \" (island)\" : \"\"), n.id, n.renders, n.ms.toFixed(2) + \" ms\"]);\n for (const c of n.children) walk(c, depth + 1);\n };\n walk(last.tree, 0);\n body.append(table([\"Component\", \"Instance\", \"Renders\", \"Last render\"], rows));\n body.append(empty(\"Inert components are drawn inline into their parent and do not appear as instances.\"));\n } else if (view === \"messages\") {\n if (last.messages.length === 0) body.append(empty(\"No live messages yet. Interact with the page.\"));\n else body.append(table([\"Time\", \"\", \"Message\", \"Handled in\", \"Sent\"], last.messages.slice().reverse().map((m) => [\n clock(m.at), m.dir === \"in\" ? \"event\" : m.dir === \"warn\" ? \"warning\" : \"push\", m.what, m.ms === undefined ? \"\" : m.ms.toFixed(1) + \" ms\", m.out.join(\", \") || \"nothing\",\n ])));\n } else if (view === \"data\") {\n const rows = [];\n for (const [pass, list] of [[\"load\", last.reads.load], [\"render\", last.reads.render]]) {\n for (const r of list) rows.push([pass, r.model, r.scope.join(\", \")]);\n }\n if (rows.length === 0) body.append(empty(\"The last load and render read no models.\"));\n else body.append(table([\"Pass\", \"Model\", \"Read as\"], rows));\n body.append(empty(\"Built-in sync refreshes this page when a change to one of these models is visible to one of these actors.\"\n + (last.stores ? \" Its load also read \" + last.stores + \" store(s).\" : \"\")));\n const k = last.cost;\n body.append(empty(\"Since it opened, this page handled \" + k.events + \" event(s) and \" + k.refreshes + \" refresh(es) in \"\n + k.ms.toFixed(1) + \" ms of server time, and was sent \" + (k.bytes / 1024).toFixed(1) + \" KB.\"));\n const cap = last.capacity;\n body.append(empty(\"It holds about \" + (k.heldBytes / 1024).toFixed(1) + \" KB (estimate: its HTML and load data).\"\n + (cap ? \" At \" + (cap.perPage / 1024).toFixed(1) + \" KB a page, about \" + cap.pages + \" more pages of \" + cap.route\n + \" fit in the \" + ((cap.heapLimit - cap.heapUsed) / 1048576).toFixed(0) + \" MB of heap left (estimate).\" : \"\")));\n } else if (view === \"time\") {\n drawTime(body);\n } else {\n if (last.decisions.length === 0) body.append(empty(\"No data-rule decisions recorded for this session yet.\"));\n else body.append(table([\"Time\", \"Model\", \"Action\", \"Outcome\", \"Rows\", \"Actor\", \"Reason\"], last.decisions.slice().reverse().map((d) => [\n clock(d.at), d.model, d.action, { text: d.outcome, color: d.outcome === \"denied\" ? WARN : OK }, d.count, d.actor, d.reason || \"\",\n ])));\n }\n body.scrollTop = top;\n}\n";