@brickkit/cli 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 (177) hide show
  1. package/dashboard-dist/CollapsiblePanel-CbUysOp5.js +2 -0
  2. package/dashboard-dist/CompositeRoot-D4sRkYq3.js +1 -0
  3. package/dashboard-dist/Geist-Variable.woff2 +0 -0
  4. package/dashboard-dist/GeistMono-Variable.woff2 +0 -0
  5. package/dashboard-dist/PopoverPopup-CiI2avT_.js +1 -0
  6. package/dashboard-dist/api-reference-mT9VNcPb.js +265 -0
  7. package/dashboard-dist/app.css +2 -2
  8. package/dashboard-dist/app.js +12 -13
  9. package/dashboard-dist/ccount-CcG1m-Yh.js +1 -0
  10. package/dashboard-dist/client-CwATkLJa.js +1 -0
  11. package/dashboard-dist/core-BEUWp6B5.js +1 -0
  12. package/dashboard-dist/docs-BRrtyxDB.js +4 -0
  13. package/dashboard-dist/docs.css +1 -1
  14. package/dashboard-dist/kit.js +1 -1
  15. package/dashboard-dist/popover-Bj9x-88h.js +1 -0
  16. package/dist/bin.d.ts +0 -2
  17. package/dist/bin.js +309 -211
  18. package/dist/bin.js.map +1 -1
  19. package/dist/build.js +463 -0
  20. package/dist/build.js.map +1 -0
  21. package/dist/client-contract-file.js +356 -1
  22. package/dist/client-contract-file.js.map +1 -0
  23. package/dist/compiler.d.ts +12 -3
  24. package/dist/compiler.js +1 -1
  25. package/dist/compiler2.js +13 -7
  26. package/dist/compiler2.js.map +1 -1
  27. package/dist/config.d.ts +3 -0
  28. package/dist/config.js +1 -252
  29. package/dist/config2.d.ts +122 -0
  30. package/dist/config2.js +207 -0
  31. package/dist/config2.js.map +1 -0
  32. package/dist/dashboard-extension.d.ts +3 -2
  33. package/dist/{dev-telemetry-store.js → dashboard-host.js} +1381 -1432
  34. package/dist/dashboard-host.js.map +1 -0
  35. package/dist/dashboard-protocol.js +189 -0
  36. package/dist/dashboard-protocol.js.map +1 -0
  37. package/dist/dashboard.d.ts +8 -135
  38. package/dist/definitions.js +33 -0
  39. package/dist/definitions.js.map +1 -0
  40. package/dist/dev-application.js +34 -0
  41. package/dist/dev-application.js.map +1 -0
  42. package/dist/dev-protocol.js +21 -0
  43. package/dist/dev-protocol.js.map +1 -0
  44. package/dist/dev-reporter.d.ts +0 -2
  45. package/dist/dev-reporter.js +3 -3
  46. package/dist/dev-reporter.js.map +1 -1
  47. package/dist/dev-telemetry.js +8 -24
  48. package/dist/dev-telemetry.js.map +1 -1
  49. package/dist/dev-worker.js +80 -21
  50. package/dist/dev-worker.js.map +1 -1
  51. package/dist/index.d.ts +18 -87
  52. package/dist/index.js +12 -6
  53. package/dist/index.js.map +1 -0
  54. package/dist/lint/oxlint.d.ts +0 -2
  55. package/dist/lint/oxlint.js +6 -5
  56. package/dist/lint/oxlint.js.map +1 -1
  57. package/dist/own-module.js +7 -0
  58. package/dist/own-module.js.map +1 -0
  59. package/dist/plugin.d.ts +6 -11
  60. package/dist/plugin.js +6 -42
  61. package/dist/plugin.js.map +1 -1
  62. package/dist/production-dashboard.d.ts +2 -0
  63. package/dist/production-dashboard.js +51 -0
  64. package/dist/production-dashboard.js.map +1 -0
  65. package/dist/production-dashboard2.d.ts +34 -0
  66. package/dist/{presets.js → project.js} +107 -113
  67. package/dist/project.js.map +1 -0
  68. package/dist/serve.d.ts +24 -0
  69. package/dist/serve.js +1 -0
  70. package/dist/serve2.js +49 -0
  71. package/dist/serve2.js.map +1 -0
  72. package/dist/vite.d.ts +0 -2
  73. package/dist/vite.js +28 -51
  74. package/dist/vite.js.map +1 -1
  75. package/dist/workflows.d.ts +2 -4
  76. package/dist/workflows2.js +60 -39
  77. package/dist/workflows2.js.map +1 -1
  78. package/inspector-dist/client/assets/api.rpc-BvRk9kiK.js +0 -0
  79. package/inspector-dist/client/assets/api.stream._streamId-BvRk9kiK.js +0 -0
  80. package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
  81. package/inspector-dist/client/assets/dist-BK8w6xOr.js +3930 -0
  82. package/inspector-dist/client/assets/dist-CG2aVufI.js +197 -0
  83. package/inspector-dist/client/assets/entry.client-D9jbgmTR.js +9391 -0
  84. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-CfRnuITN.js +34 -0
  85. package/inspector-dist/client/assets/home-hwPlkNhv.js +4034 -0
  86. package/inspector-dist/client/assets/jsx-runtime-CPEah4WQ.js +7084 -0
  87. package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
  88. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
  89. package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
  90. package/inspector-dist/client/assets/root-SLeEf-sT.js +320 -0
  91. package/inspector-dist/client/assets/run-detail-DYbVkIFH.js +1871 -0
  92. package/inspector-dist/client/assets/tabs-CaJisoyb.js +73751 -0
  93. package/inspector-dist/client/assets/tabs-L5XKzOpP.css +1 -0
  94. package/inspector-dist/client/assets/zstd-browser-decoder-D94wmfAU.js +41 -0
  95. package/inspector-dist/server/assets/app-DGlfWVUI.js +99330 -0
  96. package/inspector-dist/server/assets/chunk-RLXIAIE6-F0SJZlei.js +42975 -0
  97. package/inspector-dist/server/assets/dist-BCbwm6jl.js +10325 -0
  98. package/inspector-dist/server/assets/dist-CG2aVufI.js +197 -0
  99. package/inspector-dist/server/assets/dist-Ce0I2PUv.js +1137 -0
  100. package/inspector-dist/server/assets/dist-DY0UlahA.js +1642 -0
  101. package/inspector-dist/server/assets/encryption-DdQgC8Rk.js +886 -0
  102. package/inspector-dist/server/assets/event-metadata-n7E4zEmT.js +145 -0
  103. package/inspector-dist/server/assets/functions-CNVQtbgg.js +1170 -0
  104. package/inspector-dist/server/assets/global-singleton-D8sIN5du.js +80 -0
  105. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-CWRzMxYD.js +34 -0
  106. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
  107. package/inspector-dist/server/assets/parse-Begau9cA.js +469 -0
  108. package/inspector-dist/server/assets/rolldown-runtime-C1I3wEg2.js +43 -0
  109. package/inspector-dist/server/assets/serialization-format-BbuGfHog.js +476 -0
  110. package/inspector-dist/server/assets/token-BgMmJNP5.js +60 -0
  111. package/inspector-dist/server/assets/token-BrUX0bxz.js +55 -0
  112. package/inspector-dist/server/assets/token-util-DZN32qmT.js +455 -0
  113. package/inspector-dist/server/assets/wrapper-CIC3w0oC.js +3624 -0
  114. package/inspector-dist/server/assets/ws-transport-CxTYB11n.js +29476 -0
  115. package/inspector-dist/server/assets/zstd-browser-decoder-D7bCXbGg.js +38 -0
  116. package/inspector-dist/server/index.js +1 -58
  117. package/package.json +39 -28
  118. package/vite-client.d.ts +1 -1
  119. package/dashboard-dist/CollapsiblePanel-BX79_W-b.js +0 -2
  120. package/dashboard-dist/CompositeRoot-xzybXjnx.js +0 -1
  121. package/dashboard-dist/PopoverPopup-CvlmC7EL.js +0 -1
  122. package/dashboard-dist/api-reference-BcAYVYwJ.js +0 -260
  123. package/dashboard-dist/core-BGO9JZ1r.js +0 -1
  124. package/dashboard-dist/docs-DHikPD2v.js +0 -4
  125. package/dashboard-dist/popover-DG498XHH.js +0 -1
  126. package/dist/app-entry.js +0 -1
  127. package/dist/app-entry2.js +0 -19
  128. package/dist/app-entry2.js.map +0 -1
  129. package/dist/bin.d.ts.map +0 -1
  130. package/dist/client-contract-file2.js +0 -34
  131. package/dist/client-contract-file2.js.map +0 -1
  132. package/dist/client-contract.js +0 -1
  133. package/dist/client-contract2.js +0 -294
  134. package/dist/client-contract2.js.map +0 -1
  135. package/dist/config.js.map +0 -1
  136. package/dist/dashboard-extension.d.ts.map +0 -1
  137. package/dist/dev-reporter.d.ts.map +0 -1
  138. package/dist/dev-telemetry-store.js.map +0 -1
  139. package/dist/emit.d.ts +0 -7
  140. package/dist/emit.d.ts.map +0 -1
  141. package/dist/index.d.ts.map +0 -1
  142. package/dist/lint/oxlint.d.ts.map +0 -1
  143. package/dist/plugin.d.ts.map +0 -1
  144. package/dist/presets.js.map +0 -1
  145. package/dist/runner.js +0 -523
  146. package/dist/runner.js.map +0 -1
  147. package/dist/vite.d.ts.map +0 -1
  148. package/dist/workflows.d.ts.map +0 -1
  149. package/inspector-dist/client/assets/api.rpc-l0sNRNKZ.js +0 -1
  150. package/inspector-dist/client/assets/api.stream._streamId-l0sNRNKZ.js +0 -1
  151. package/inspector-dist/client/assets/app-CvoGgWcV.css +0 -1
  152. package/inspector-dist/client/assets/entry.client-BJ6G3n5t.js +0 -11697
  153. package/inspector-dist/client/assets/highlighted-body-B3W2YXNL-C-3wZnxf.js +0 -19
  154. package/inspector-dist/client/assets/home-CSKAS4P2.js +0 -4979
  155. package/inspector-dist/client/assets/index-DECCyMR0.js +0 -4482
  156. package/inspector-dist/client/assets/index-Dot7CgrA.js +0 -9837
  157. package/inspector-dist/client/assets/index-HqNj_XIX.js +0 -200
  158. package/inspector-dist/client/assets/manifest-139c9319.js +0 -1
  159. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-DC0K8uTy.js +0 -58626
  160. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-F88p7PFX.css +0 -1
  161. package/inspector-dist/client/assets/root-BMHd_XHz.css +0 -1
  162. package/inspector-dist/client/assets/root-cbi6iYwg.js +0 -305
  163. package/inspector-dist/client/assets/run-detail-CWoGxu_0.css +0 -1
  164. package/inspector-dist/client/assets/run-detail-Cc7tSGNq.js +0 -6237
  165. package/inspector-dist/client/assets/world-config-context-BAD1QCrR.js +0 -26
  166. package/inspector-dist/client/assets/zstd-browser-decoder-BQoRpP7L.js +0 -28
  167. package/inspector-dist/server/assets/app-DUP5RybL.js +0 -174880
  168. package/inspector-dist/server/assets/highlighted-body-B3W2YXNL-D2g4hL2-.js +0 -71
  169. package/inspector-dist/server/assets/index-BfLBLRRi.js +0 -204
  170. package/inspector-dist/server/assets/index-BzrGWk7J.js +0 -1164
  171. package/inspector-dist/server/assets/index-D71yP6AL.js +0 -191
  172. package/inspector-dist/server/assets/index-wGSWRns3.js +0 -1296
  173. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-DsvuKoEV.js +0 -58
  174. package/inspector-dist/server/assets/token-ClUZZwXl.js +0 -95
  175. package/inspector-dist/server/assets/token-util-DSxMZ6nI.js +0 -33
  176. package/inspector-dist/server/assets/wrapper-B3vstpCO.js +0 -67
  177. package/inspector-dist/server/assets/zstd-browser-decoder-Dn82m2BU.js +0 -77
package/dist/config.js CHANGED
@@ -1,252 +1 @@
1
- import { a as writeDashboardExtension, i as themeCss } from "./dev-telemetry-store.js";
2
- import { t as loadBrickApp } from "./app-entry2.js";
3
- import { i as workflowTransformPlugin, t as buildAppWorkflows } from "./workflows2.js";
4
- import { i as emitCompiledApplication, n as compileBrickApplication } from "./compiler2.js";
5
- import { pathToFileURL } from "node:url";
6
- import { mkdir, mkdtemp, rename, rm } from "node:fs/promises";
7
- import { dirname, join, resolve } from "node:path";
8
- import { existsSync } from "node:fs";
9
- import { aot } from "elysia/plugin/aot/bun";
10
- //#region src/compiler/aot.ts
11
- /** Keep the pinned Elysia beta's incomplete stripping from breaking builds. */
12
- function brickAot(entry, hasSockets) {
13
- if (hasSockets) return aot(entry, {
14
- target: "bun",
15
- strip: false
16
- });
17
- return {
18
- name: "brick-elysia-aot",
19
- async setup(build) {
20
- await aot(entry, {
21
- target: "bun",
22
- strip: true
23
- }).setup({
24
- ...build,
25
- onLoad(options, callback) {
26
- return build.onLoad(options, async (args) => {
27
- const result = await callback(args);
28
- if (!result || !("contents" in result) || typeof result.contents !== "string") return result;
29
- let contents = result.contents;
30
- if (/[/\\]elysia[/\\]dist[/\\]ws[/\\]route\.m?js$/.test(args.path) && contents.includes("[elysia-aot] WebSocket route builder was stripped")) {
31
- for (const name of ["resolveWSOptions", "accumulateWSOptions"]) if (!contents.includes(`export function ${name}`)) contents += `\nexport function ${name}() { throw new Error("WebSocket support was stripped"); }\n`;
32
- }
33
- return contents === result.contents ? result : {
34
- ...result,
35
- contents
36
- };
37
- });
38
- }
39
- });
40
- }
41
- };
42
- }
43
- //#endregion
44
- //#region src/build.ts
45
- /** Bundle an exported BrickApp with generated handlers and its original configuration. */
46
- async function buildApplication(options) {
47
- const entry = resolve(options.entry);
48
- if (!await Bun.file(entry).exists()) throw new Error(`Brick compiler: entry not found: ${entry}`);
49
- const outdir = resolve(options.outdir ?? "dist/brick");
50
- if (entry === join(outdir, "server.js") || entry === join(outdir, "routes.js")) throw new Error("Brick compiler: output would overwrite the application entry");
51
- const port = options.port ?? 4e3;
52
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Brick compiler: port must be an integer between 1 and 65535");
53
- themeCss(options.dashboard?.theme);
54
- const extension = options.dashboard?.extension ? resolve(options.dashboard.extension) : void 0;
55
- if (extension && !await Bun.file(extension).exists()) throw new Error(`Brick compiler: dashboard extension not found: ${extension}`);
56
- const app = await loadBrickApp(entry);
57
- await buildAppWorkflows(app);
58
- const services = [...app.definition.services];
59
- const compilation = compileBrickApplication({
60
- services,
61
- prefix: app.definition.prefix
62
- });
63
- await mkdir(dirname(outdir), { recursive: true });
64
- const staging = await mkdtemp(join(dirname(outdir), ".brick-build-"));
65
- try {
66
- await Bun.write(join(staging, "routes.js"), emitCompiledApplication(compilation.ir));
67
- const source = `import { loadCompiledBrickApp } from "@brickkit/core";
68
- import { ir, bind } from "./routes.js";
69
- export const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir, bind);
70
- if (import.meta.main) {
71
- const port = Number(process.env.PORT ?? ${port});
72
- if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Invalid PORT: must be between 1 and 65535");
73
- await app.start?.();
74
- app.listen(port);
75
- app.events?.start();
76
- console.log("Brick compiled server listening on http://localhost:" + app.server.port);
77
- let stopping = false;
78
- const stop = async (signal: string) => {
79
- // A second signal exits at once, for a delivery that never finishes.
80
- if (stopping) process.exit(signal === "SIGINT" ? 130 : 143);
81
- stopping = true;
82
- await app.events?.stop();
83
- await app.stop();
84
- process.exit(0);
85
- };
86
- // on, not once: the workflow runtime bundles signal-exit, which re-raises a signal when no listener is left.
87
- process.on("SIGINT", stop);
88
- process.on("SIGTERM", stop);
89
- }
90
- `;
91
- await Bun.write(join(staging, "entry.ts"), source);
92
- const workflows = app.events?.workflows ? await workflowTransformPlugin(app.events.workflows.root) : void 0;
93
- const result = await Bun.build({
94
- entrypoints: [join(staging, "entry.ts")],
95
- target: "bun",
96
- format: "esm",
97
- outdir: staging,
98
- naming: "server.js",
99
- sourcemap: "external",
100
- plugins: [...options.aot === false ? [] : [brickAot(join(staging, "entry.ts"), app.definition.sockets.length > 0)], ...workflows ? [workflows] : []]
101
- });
102
- if (!result.success) throw new AggregateError(result.logs, "Brick compiler: bundling failed");
103
- await Bun.write(join(staging, "brick-ir.json"), JSON.stringify(compilation.ir, null, 2) + "\n");
104
- const dashboard = await writeDashboardExtension(extension, app.definition.plugins ?? [], join(staging, "dashboard")) ? join(outdir, "dashboard") : void 0;
105
- await mkdir(outdir, { recursive: true });
106
- for (const name of [
107
- "routes.js",
108
- "brick-ir.json",
109
- "server.js.map",
110
- "server.js"
111
- ]) await rename(join(staging, name), join(outdir, name));
112
- if (dashboard) {
113
- await rm(dashboard, {
114
- recursive: true,
115
- force: true
116
- });
117
- await rename(join(staging, "dashboard"), dashboard);
118
- }
119
- return {
120
- outdir,
121
- entry: join(outdir, "server.js"),
122
- ir: compilation.ir,
123
- /** The built dashboard extension's folder, when there is one. */
124
- dashboard
125
- };
126
- } finally {
127
- await rm(staging, {
128
- recursive: true,
129
- force: true
130
- });
131
- }
132
- }
133
- //#endregion
134
- //#region src/config.ts
135
- /** Types the config file in the editor; the CLI validates it at load. */
136
- function defineConfig(config) {
137
- return config;
138
- }
139
- const CONFIG_FILE = "brick.config.ts";
140
- /** A missing or invalid config file; the message names the file and key. */
141
- var ConfigError = class extends Error {};
142
- /** The nearest `brick.config.ts` in `cwd` or its parents. */
143
- function findConfigFile(cwd = process.cwd()) {
144
- for (let dir = resolve(cwd);; dir = dirname(dir)) {
145
- const file = join(dir, CONFIG_FILE);
146
- if (existsSync(file)) return file;
147
- if (dirname(dir) === dir) return void 0;
148
- }
149
- }
150
- /**
151
- * Load and validate the project's config: `explicit` (`--config`) when given,
152
- * else the nearest `brick.config.ts`. Returns undefined when there is none.
153
- */
154
- async function loadConfig(explicit, cwd = process.cwd()) {
155
- const file = explicit ? resolve(cwd, explicit) : findConfigFile(cwd);
156
- if (!file) return void 0;
157
- if (!existsSync(file)) throw new ConfigError(`Brick: config file not found: ${file}`);
158
- const config = (await import(pathToFileURL(file).href)).default;
159
- validateConfig(config, file.endsWith("brick.config.ts") ? CONFIG_FILE : file);
160
- const root = dirname(file);
161
- return {
162
- file,
163
- root,
164
- config,
165
- entry: resolve(root, config.entry ?? "src/app.ts"),
166
- services: resolve(root, config.services ?? "src/services"),
167
- generated: resolve(root, config.generated ?? "_brick")
168
- };
169
- }
170
- const isString = (v) => typeof v === "string" && v.length > 0;
171
- const isBoolean = (v) => typeof v === "boolean";
172
- const isPort = (v) => Number.isInteger(v) && v >= 1 && v <= 65535;
173
- const isRecordOf = (check) => (v) => isPlainObject(v) && Object.values(v).every(check);
174
- const isArrayOf = (check) => (v) => Array.isArray(v) && v.every(check);
175
- const PRESETS = [
176
- "recommended",
177
- "layout",
178
- "strict",
179
- "plugin"
180
- ];
181
- const SEVERITIES = [
182
- "error",
183
- "warn",
184
- "off"
185
- ];
186
- const SCHEMA = {
187
- entry: [isString, "must be a file path"],
188
- services: [isString, "must be a folder path"],
189
- generated: [isString, "must be a folder path"],
190
- client: { output: [isString, "must be a file path"] },
191
- openapi: { output: [isString, "must be a file path"] },
192
- dev: {
193
- port: [isPort, "must be a port number"],
194
- frontend: [isString, "must be a command"],
195
- dashboard: {
196
- port: [isPort, "must be a port number"],
197
- historyDays: [(v) => Number.isSafeInteger(v) && v >= 0, "must be a whole number of days, or 0 for none"]
198
- }
199
- },
200
- build: {
201
- outdir: [isString, "must be a folder path"],
202
- aot: [isBoolean, "must be true or false"],
203
- requestLogging: [isBoolean, "must be true or false"]
204
- },
205
- dashboard: {
206
- extension: [isString, "must be a file path"],
207
- theme: {
208
- light: [isRecordOf(isString), "must map token names to values"],
209
- dark: [isRecordOf(isString), "must map token names to values"],
210
- radius: [isString, "must be a CSS length"],
211
- fonts: {
212
- sans: [isString, "must be a font-family value"],
213
- mono: [isString, "must be a font-family value"]
214
- }
215
- }
216
- },
217
- lint: {
218
- presets: [isArrayOf((v) => PRESETS.includes(v)), `must list presets from ${PRESETS.join(", ")}`],
219
- rules: [isRecordOf((v) => SEVERITIES.includes(v)), "must map rule names to \"error\", \"warn\" or \"off\""],
220
- ignore: [isArrayOf(isString), "must be a list of glob patterns"]
221
- }
222
- };
223
- function isPlainObject(value) {
224
- return typeof value === "object" && value !== null && !Array.isArray(value);
225
- }
226
- /** Throws on an unknown key, a bad type, or `dev.frontend` without `client.output`. */
227
- function validateConfig(config, label = CONFIG_FILE) {
228
- const fail = (message) => {
229
- throw new ConfigError(`${label}: ${message}`);
230
- };
231
- if (!isPlainObject(config)) fail("must default-export defineConfig({ ... })");
232
- const walk = (value, shape, path) => {
233
- for (const [key, child] of Object.entries(value)) {
234
- const keyPath = path + key;
235
- const rule = shape[key];
236
- if (!rule) fail(`unknown key ${keyPath}`);
237
- if (child === void 0) continue;
238
- if (keyPath === "dev.dashboard" && child === false) continue;
239
- if (Array.isArray(rule)) {
240
- if (!rule[0](child)) fail(`${keyPath} ${rule[1]}`);
241
- } else if (!isPlainObject(child)) fail(`${keyPath} must be an object${keyPath === "dev.dashboard" ? " or false" : ""}`);
242
- else walk(child, rule, `${keyPath}.`);
243
- }
244
- };
245
- walk(config, SCHEMA, "");
246
- const typed = config;
247
- if (typed.dev?.frontend && !typed.client?.output) fail("dev.frontend requires client.output");
248
- }
249
- //#endregion
250
- export { buildApplication as i, defineConfig as n, loadConfig as r, ConfigError as t };
251
-
252
- //# sourceMappingURL=config.js.map
1
+ export { t as CONTRACT_FILE, n as ConfigError, r as DEFAULT_DASHBOARD_PORT, i as DEFAULT_HISTORY_DAYS, a as DEFAULT_OUTDIR, o as DEFAULT_PORT, s as PROJECT_DEFAULTS, c as defineConfig, l as findConfigFile, u as loadConfig, d as resolveDevDashboard, f as resolvePort, p as resolveProject, m as validateConfig } from "./config2.js";
@@ -0,0 +1,122 @@
1
+ import "./dashboard-extension.js";
2
+ import { Static, TOptional } from "@sinclair/typebox";
3
+ declare const PRESET_NAMES: readonly ["recommended", "layout", "strict", "plugin"];
4
+ declare const SEVERITIES: readonly ["error", "warn", "off"];
5
+ type LintPreset = (typeof PRESET_NAMES)[number];
6
+ type LintSeverity = (typeof SEVERITIES)[number];
7
+ declare const DEFAULT_PORT = 4000;
8
+ declare const DEFAULT_DASHBOARD_PORT = 9400;
9
+ declare const DEFAULT_HISTORY_DAYS = 90;
10
+ declare const DEFAULT_OUTDIR = "dist/brick";
11
+ /** Project paths a config leaves out, relative to its folder. */
12
+ declare const PROJECT_DEFAULTS: {
13
+ readonly entry: "src/app.ts";
14
+ readonly services: "src/services";
15
+ readonly generated: "_brick";
16
+ };
17
+ /** The client contract's name in the generated folder, when `client.output` names none. */
18
+ declare const CONTRACT_FILE = "contract.ts";
19
+ /**
20
+ * Project and tooling settings read by the `brick` CLI and its lint rules.
21
+ * Paths are relative to the folder that holds `brick.config.ts`. Runtime
22
+ * behaviour (prefix, docs, telemetry, events, sockets) stays in `brick()`.
23
+ */
24
+ declare const BrickConfigSchema: import("@sinclair/typebox").TObject<{
25
+ entry: TOptional<import("@sinclair/typebox").TString>;
26
+ services: TOptional<import("@sinclair/typebox").TString>;
27
+ generated: TOptional<import("@sinclair/typebox").TString>;
28
+ client: TOptional<TOptional<import("@sinclair/typebox").TObject<{
29
+ output: TOptional<import("@sinclair/typebox").TString>;
30
+ }>>>;
31
+ openapi: TOptional<TOptional<import("@sinclair/typebox").TObject<{
32
+ output: TOptional<import("@sinclair/typebox").TString>;
33
+ }>>>;
34
+ dev: TOptional<TOptional<import("@sinclair/typebox").TObject<{
35
+ port: TOptional<import("@sinclair/typebox").TInteger>;
36
+ frontend: TOptional<import("@sinclair/typebox").TString>;
37
+ dashboard: TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<false>, import("@sinclair/typebox").TObject<{
38
+ port: TOptional<import("@sinclair/typebox").TInteger>;
39
+ historyDays: TOptional<import("@sinclair/typebox").TInteger>;
40
+ }>]>>;
41
+ }>>>;
42
+ build: TOptional<TOptional<import("@sinclair/typebox").TObject<{
43
+ outdir: TOptional<import("@sinclair/typebox").TString>;
44
+ aot: TOptional<import("@sinclair/typebox").TBoolean>;
45
+ requestLogging: TOptional<import("@sinclair/typebox").TBoolean>;
46
+ }>>>;
47
+ dashboard: TOptional<TOptional<import("@sinclair/typebox").TObject<{
48
+ extension: TOptional<import("@sinclair/typebox").TString>;
49
+ theme: TOptional<TOptional<import("@sinclair/typebox").TObject<{
50
+ light: TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
51
+ dark: TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
52
+ radius: TOptional<import("@sinclair/typebox").TString>;
53
+ fonts: TOptional<TOptional<import("@sinclair/typebox").TObject<{
54
+ sans: TOptional<import("@sinclair/typebox").TString>;
55
+ mono: TOptional<import("@sinclair/typebox").TString>;
56
+ }>>>;
57
+ }>>>;
58
+ }>>>;
59
+ lint: TOptional<TOptional<import("@sinclair/typebox").TObject<{
60
+ presets: TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"layout" | "plugin" | "recommended" | "strict">[]>>>;
61
+ rules: TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"error" | "off" | "warn">[]>>>;
62
+ ignore: TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
63
+ }>>>;
64
+ }>;
65
+ type BrickConfig = Static<typeof BrickConfigSchema>;
66
+ /** Types the config file in the editor; the CLI validates it at load. */
67
+ declare function defineConfig(config: BrickConfig): BrickConfig;
68
+ /** A user's mistake: a missing file, an invalid config, or flags that conflict. `brick` prints the message alone. */
69
+ declare class ConfigError extends Error {}
70
+ /** The project: its config file, if any, and every path with defaults applied. */
71
+ interface LoadedConfig {
72
+ /** Absolute path of the config file; absent when the project has none. */
73
+ file?: string;
74
+ /** Folder the config's paths are relative to (the working folder without a file). */
75
+ root: string;
76
+ config: BrickConfig;
77
+ /** Absolute paths with defaults applied. */
78
+ entry: string;
79
+ services: string;
80
+ generated: string;
81
+ /** Where the client contract goes: `client.output`, else `<generated>/contract.ts`. */
82
+ contract: string;
83
+ /** Where `brick build` writes: `build.outdir`, else `dist/brick`. */
84
+ outdir: string;
85
+ }
86
+ /** The nearest `brick.config.ts` in `cwd` or its parents. */
87
+ declare function findConfigFile(cwd?: string): string | undefined;
88
+ /**
89
+ * The project, from `explicit` (`--config`) when given, else the nearest
90
+ * `brick.config.ts`, validated. Without a file, the defaults from `cwd`.
91
+ */
92
+ declare function resolveProject(explicit?: string, cwd?: string): Promise<LoadedConfig>;
93
+ /**
94
+ * Load and validate the project's config: `explicit` (`--config`) when given,
95
+ * else the nearest `brick.config.ts`. Returns undefined when there is none.
96
+ */
97
+ declare function loadConfig(explicit?: string, cwd?: string): Promise<LoadedConfig | undefined>;
98
+ /** The dashboard flags of `brick dev`. */
99
+ interface DevDashboardFlags {
100
+ /** `false` with `--no-dashboard`. */
101
+ dashboard?: boolean;
102
+ dashboardPort?: number;
103
+ historyDays?: number;
104
+ dashboardExtension?: string;
105
+ }
106
+ /**
107
+ * Whether `brick dev` serves its dashboard, and its port and history, from the
108
+ * config's `dev.dashboard` and the flags. The config can turn it off; a port or
109
+ * history flag turns it back on.
110
+ *
111
+ * @throws ConfigError When a dashboard flag is combined with turning it off.
112
+ */
113
+ declare function resolveDevDashboard(configured: NonNullable<BrickConfig["dev"]>["dashboard"], flags: DevDashboardFlags): {
114
+ port?: number;
115
+ historyDays?: number;
116
+ } | false;
117
+ /** A port from a flag, else `PORT`, else the config, else 4000; throws outside 1-65535. */
118
+ declare function resolvePort(flag?: number | string, configured?: number, env?: string | undefined): number;
119
+ /** Throws on an unknown key, a bad type, or `dev.frontend` without `client.output`. */
120
+ declare function validateConfig(config: unknown, label?: string): asserts config is BrickConfig;
121
+ export { resolvePort as _, DEFAULT_HISTORY_DAYS as a, DevDashboardFlags as c, LoadedConfig as d, PROJECT_DEFAULTS as f, resolveDevDashboard as g, loadConfig as h, DEFAULT_DASHBOARD_PORT as i, LintPreset as l, findConfigFile as m, CONTRACT_FILE as n, DEFAULT_OUTDIR as o, defineConfig as p, ConfigError as r, DEFAULT_PORT as s, BrickConfig as t, LintSeverity as u, resolveProject as v, validateConfig as y };
122
+ //# sourceMappingURL=config2.d.ts.map
@@ -0,0 +1,207 @@
1
+ import { existsSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { Type } from "@sinclair/typebox";
5
+ import { Value, ValueErrorType } from "@sinclair/typebox/value";
6
+ // src/config.ts
7
+ const PRESET_NAMES = [
8
+ "recommended",
9
+ "layout",
10
+ "strict",
11
+ "plugin"
12
+ ];
13
+ const SEVERITIES = [
14
+ "error",
15
+ "warn",
16
+ "off"
17
+ ];
18
+ const DEFAULT_PORT = 4e3;
19
+ const DEFAULT_DASHBOARD_PORT = 9400;
20
+ const DEFAULT_HISTORY_DAYS = 90;
21
+ const DEFAULT_OUTDIR = "dist/brick";
22
+ /** Project paths a config leaves out, relative to its folder. */
23
+ const PROJECT_DEFAULTS = {
24
+ entry: "src/app.ts",
25
+ services: "src/services",
26
+ generated: "_brick"
27
+ };
28
+ /** The client contract's name in the generated folder, when `client.output` names none. */
29
+ const CONTRACT_FILE = "contract.ts";
30
+ const CONFIG_FILE = "brick.config.ts";
31
+ const path = (message) => Type.String({
32
+ minLength: 1,
33
+ message
34
+ });
35
+ const port = Type.Integer({
36
+ minimum: 1,
37
+ maximum: 65535,
38
+ message: "must be a port number"
39
+ });
40
+ const flag = Type.Boolean({ message: "must be true or false" });
41
+ const shape = (properties) => Type.Optional(Type.Object(properties, { additionalProperties: false }));
42
+ const optional = (properties) => Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, Type.Optional(value)]));
43
+ const tokens = Type.Record(Type.String(), Type.String(), { message: "must map token names to values" });
44
+ /**
45
+ * Project and tooling settings read by the `brick` CLI and its lint rules.
46
+ * Paths are relative to the folder that holds `brick.config.ts`. Runtime
47
+ * behaviour (prefix, docs, telemetry, events, sockets) stays in `brick()`.
48
+ */
49
+ const BrickConfigSchema = Type.Object(optional({
50
+ /** App entry whose default export is the BrickApp (default `src/app.ts`). */
51
+ entry: path("must be a file path"),
52
+ /** Folder scanned for definition files (default `src/services`). */
53
+ services: path("must be a folder path"),
54
+ /** Folder for `services.gen.ts` and the default contract (default `_brick`). */
55
+ generated: path("must be a folder path"),
56
+ client: shape(optional({ output: path("must be a file path") })),
57
+ openapi: shape(optional({ output: path("must be a file path") })),
58
+ dev: shape(optional({
59
+ port,
60
+ /** Frontend command, started once the client contract exists. Needs `client.output`. */
61
+ frontend: path("must be a command"),
62
+ dashboard: Type.Union([Type.Literal(false), Type.Object(optional({
63
+ port,
64
+ historyDays: Type.Integer({
65
+ minimum: 0,
66
+ maximum: Number.MAX_SAFE_INTEGER,
67
+ message: "must be a whole number of days, or 0 for none"
68
+ })
69
+ }), { additionalProperties: false })], { message: "must be an object or false" })
70
+ })),
71
+ build: shape(optional({
72
+ outdir: path("must be a folder path"),
73
+ aot: flag,
74
+ requestLogging: flag
75
+ })),
76
+ dashboard: shape(optional({
77
+ extension: path("must be a file path"),
78
+ theme: shape(optional({
79
+ light: tokens,
80
+ dark: tokens,
81
+ radius: path("must be a CSS length"),
82
+ fonts: shape(optional({
83
+ sans: path("must be a font-family value"),
84
+ mono: path("must be a font-family value")
85
+ }))
86
+ }))
87
+ })),
88
+ lint: shape(optional({
89
+ presets: Type.Array(Type.Union(PRESET_NAMES.map((name) => Type.Literal(name))), { message: `must list presets from ${PRESET_NAMES.join(", ")}` }),
90
+ rules: Type.Record(Type.String(), Type.Union(SEVERITIES.map((severity) => Type.Literal(severity))), { message: "must map rule names to \"error\", \"warn\" or \"off\"" }),
91
+ ignore: Type.Array(Type.String({ minLength: 1 }), { message: "must be a list of glob patterns" })
92
+ }))
93
+ }), {
94
+ additionalProperties: false,
95
+ message: "must default-export defineConfig({ ... })"
96
+ });
97
+ /** Types the config file in the editor; the CLI validates it at load. */
98
+ function defineConfig(config) {
99
+ return config;
100
+ }
101
+ /** A user's mistake: a missing file, an invalid config, or flags that conflict. `brick` prints the message alone. */
102
+ var ConfigError = class extends Error {};
103
+ /** The nearest `brick.config.ts` in `cwd` or its parents. */
104
+ function findConfigFile(cwd = process.cwd()) {
105
+ for (let dir = resolve(cwd);; dir = dirname(dir)) {
106
+ const file = join(dir, CONFIG_FILE);
107
+ if (existsSync(file)) return file;
108
+ if (dirname(dir) === dir) return void 0;
109
+ }
110
+ }
111
+ /**
112
+ * The project, from `explicit` (`--config`) when given, else the nearest
113
+ * `brick.config.ts`, validated. Without a file, the defaults from `cwd`.
114
+ */
115
+ async function resolveProject(explicit, cwd = process.cwd()) {
116
+ const file = explicit ? resolve(cwd, explicit) : findConfigFile(cwd);
117
+ if (file && !existsSync(file)) throw new ConfigError(`Brick: config file not found: ${file}`);
118
+ const config = file ? (await import(pathToFileURL(file).href)).default : {};
119
+ if (file) validateConfig(config, file.endsWith(CONFIG_FILE) ? CONFIG_FILE : file);
120
+ const root = file ? dirname(file) : resolve(cwd);
121
+ const generated = resolve(root, config.generated ?? PROJECT_DEFAULTS.generated);
122
+ return {
123
+ file,
124
+ root,
125
+ config,
126
+ entry: resolve(root, config.entry ?? PROJECT_DEFAULTS.entry),
127
+ services: resolve(root, config.services ?? PROJECT_DEFAULTS.services),
128
+ generated,
129
+ contract: config.client?.output ? resolve(root, config.client.output) : join(generated, CONTRACT_FILE),
130
+ outdir: resolve(root, config.build?.outdir ?? "dist/brick")
131
+ };
132
+ }
133
+ /**
134
+ * Load and validate the project's config: `explicit` (`--config`) when given,
135
+ * else the nearest `brick.config.ts`. Returns undefined when there is none.
136
+ */
137
+ async function loadConfig(explicit, cwd = process.cwd()) {
138
+ const project = await resolveProject(explicit, cwd);
139
+ return project.file ? project : void 0;
140
+ }
141
+ /**
142
+ * Whether `brick dev` serves its dashboard, and its port and history, from the
143
+ * config's `dev.dashboard` and the flags. The config can turn it off; a port or
144
+ * history flag turns it back on.
145
+ *
146
+ * @throws ConfigError When a dashboard flag is combined with turning it off.
147
+ */
148
+ function resolveDevDashboard(configured, flags) {
149
+ if (flags.dashboard === false) {
150
+ if (flags.dashboardPort !== void 0) throw new ConfigError("Brick: --dashboard-port cannot be combined with --no-dashboard.");
151
+ if (flags.historyDays !== void 0) throw new ConfigError("Brick: --history-days cannot be combined with --no-dashboard.");
152
+ }
153
+ const off = flags.dashboard === false || configured === false && flags.dashboardPort === void 0 && flags.historyDays === void 0;
154
+ if (off && flags.dashboardExtension) throw new ConfigError(flags.dashboard === false ? "Brick: --dashboard-extension cannot be combined with --no-dashboard." : "Brick: --dashboard-extension needs the dashboard, which dev.dashboard: false in the config turns off.");
155
+ if (off) return false;
156
+ const settings = configured || void 0;
157
+ return {
158
+ port: flags.dashboardPort ?? settings?.port,
159
+ historyDays: flags.historyDays ?? settings?.historyDays
160
+ };
161
+ }
162
+ /** A port from a flag, else `PORT`, else the config, else 4000; throws outside 1-65535. */
163
+ function resolvePort(flag, configured, env = process.env.PORT) {
164
+ const port = Number(flag ?? (env || void 0) ?? configured ?? 4e3);
165
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(`Invalid port: ${port}. Port must be an integer between 1 and 65535`);
166
+ return port;
167
+ }
168
+ function isPlainObject(value) {
169
+ return typeof value === "object" && value !== null && !Array.isArray(value);
170
+ }
171
+ /** The schema of `key` inside `schema`, looking into the object of a union. */
172
+ function child(schema, key) {
173
+ const object = schema.anyOf?.find((s) => s.type === "object") ?? schema;
174
+ return object.properties?.[key] ?? (object.patternProperties && Object.values(object.patternProperties)[0]) ?? object.items;
175
+ }
176
+ /** Throws on an unknown key, a bad type, or `dev.frontend` without `client.output`. */
177
+ function validateConfig(config, label = CONFIG_FILE) {
178
+ const fail = (message) => {
179
+ throw new ConfigError(`${label}: ${message}`);
180
+ };
181
+ let error = Value.Errors(BrickConfigSchema, config).First();
182
+ const keys = [];
183
+ while (error?.schema.anyOf && isPlainObject(error.value)) {
184
+ const object = error.schema.anyOf.find((s) => s.type === "object");
185
+ if (!object) break;
186
+ keys.push(...error.path.split("/").slice(1));
187
+ error = Value.Errors(object, error.value).First();
188
+ }
189
+ if (error) {
190
+ keys.push(...error.path.split("/").slice(1));
191
+ if (error.type === ValueErrorType.ObjectAdditionalProperties) fail(`unknown key ${keys.join(".")}`);
192
+ let schema = BrickConfigSchema;
193
+ let message = schema.message;
194
+ let at = 0;
195
+ keys.forEach((key, index) => {
196
+ schema = schema && child(schema, key);
197
+ if (schema?.message) [message, at] = [schema.message, index + 1];
198
+ else if (schema?.type === "object" && index === keys.length - 1) [message, at] = ["must be an object", index + 1];
199
+ });
200
+ fail(at ? `${keys.slice(0, at).join(".")} ${message}` : message);
201
+ }
202
+ const typed = config;
203
+ if (typed.dev?.frontend && !typed.client?.output) fail("dev.frontend requires client.output");
204
+ }
205
+ export { DEFAULT_OUTDIR as a, defineConfig as c, resolveDevDashboard as d, resolvePort as f, DEFAULT_HISTORY_DAYS as i, findConfigFile as l, validateConfig as m, ConfigError as n, DEFAULT_PORT as o, resolveProject as p, DEFAULT_DASHBOARD_PORT as r, PROJECT_DEFAULTS as s, CONTRACT_FILE as t, loadConfig as u };
206
+
207
+ //# sourceMappingURL=config2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config2.js","names":["t"],"sources":["../src/config.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport {\n Type as t,\n type Static,\n type TOptional,\n type TSchema,\n} from \"@sinclair/typebox\";\nimport { Value, ValueErrorType } from \"@sinclair/typebox/value\";\n\nimport type {\n DashboardExtensionOptions,\n DashboardTheme,\n} from \"./dashboard-extension\";\n\nexport type { DashboardExtensionOptions, DashboardTheme };\n\nconst PRESET_NAMES = [\"recommended\", \"layout\", \"strict\", \"plugin\"] as const;\nconst SEVERITIES = [\"error\", \"warn\", \"off\"] as const;\nexport type LintPreset = (typeof PRESET_NAMES)[number];\nexport type LintSeverity = (typeof SEVERITIES)[number];\n\nexport const DEFAULT_PORT = 4000;\nexport const DEFAULT_DASHBOARD_PORT = 9400;\nexport const DEFAULT_HISTORY_DAYS = 90;\nexport const DEFAULT_OUTDIR = \"dist/brick\";\n/** Project paths a config leaves out, relative to its folder. */\nexport const PROJECT_DEFAULTS = {\n entry: \"src/app.ts\",\n services: \"src/services\",\n generated: \"_brick\",\n} as const;\n/** The client contract's name in the generated folder, when `client.output` names none. */\nexport const CONTRACT_FILE = \"contract.ts\";\nconst CONFIG_FILE = \"brick.config.ts\";\n\nconst path = (message: string) => t.String({ minLength: 1, message });\nconst port = t.Integer({\n minimum: 1,\n maximum: 65535,\n message: \"must be a port number\",\n});\nconst flag = t.Boolean({ message: \"must be true or false\" });\nconst shape = <T extends Record<string, TSchema>>(properties: T) =>\n t.Optional(t.Object(properties, { additionalProperties: false }));\nconst optional = <T extends Record<string, TSchema>>(properties: T) =>\n Object.fromEntries(\n Object.entries(properties).map(([key, value]) => [key, t.Optional(value)]),\n ) as { [K in keyof T]: TOptional<T[K]> };\nconst tokens = t.Record(t.String(), t.String(), {\n message: \"must map token names to values\",\n});\n\n/**\n * Project and tooling settings read by the `brick` CLI and its lint rules.\n * Paths are relative to the folder that holds `brick.config.ts`. Runtime\n * behaviour (prefix, docs, telemetry, events, sockets) stays in `brick()`.\n */\nconst BrickConfigSchema = t.Object(\n optional({\n /** App entry whose default export is the BrickApp (default `src/app.ts`). */\n entry: path(\"must be a file path\"),\n /** Folder scanned for definition files (default `src/services`). */\n services: path(\"must be a folder path\"),\n /** Folder for `services.gen.ts` and the default contract (default `_brick`). */\n generated: path(\"must be a folder path\"),\n client: shape(optional({ output: path(\"must be a file path\") })),\n openapi: shape(optional({ output: path(\"must be a file path\") })),\n dev: shape(\n optional({\n port,\n /** Frontend command, started once the client contract exists. Needs `client.output`. */\n frontend: path(\"must be a command\"),\n dashboard: t.Union(\n [\n t.Literal(false),\n t.Object(\n optional({\n port,\n historyDays: t.Integer({\n minimum: 0,\n maximum: Number.MAX_SAFE_INTEGER,\n message: \"must be a whole number of days, or 0 for none\",\n }),\n }),\n { additionalProperties: false },\n ),\n ],\n { message: \"must be an object or false\" },\n ),\n }),\n ),\n build: shape(\n optional({\n outdir: path(\"must be a folder path\"),\n aot: flag,\n requestLogging: flag,\n }),\n ),\n dashboard: shape(\n optional({\n extension: path(\"must be a file path\"),\n theme: shape(\n optional({\n light: tokens,\n dark: tokens,\n radius: path(\"must be a CSS length\"),\n fonts: shape(\n optional({\n sans: path(\"must be a font-family value\"),\n mono: path(\"must be a font-family value\"),\n }),\n ),\n }),\n ),\n }),\n ),\n lint: shape(\n optional({\n presets: t.Array(t.Union(PRESET_NAMES.map((name) => t.Literal(name))), {\n message: `must list presets from ${PRESET_NAMES.join(\", \")}`,\n }),\n rules: t.Record(\n t.String(),\n t.Union(SEVERITIES.map((severity) => t.Literal(severity))),\n { message: 'must map rule names to \"error\", \"warn\" or \"off\"' },\n ),\n ignore: t.Array(t.String({ minLength: 1 }), {\n message: \"must be a list of glob patterns\",\n }),\n }),\n ),\n }),\n {\n additionalProperties: false,\n message: \"must default-export defineConfig({ ... })\",\n },\n);\n\nexport type BrickConfig = Static<typeof BrickConfigSchema>;\n\n/** Types the config file in the editor; the CLI validates it at load. */\nexport function defineConfig(config: BrickConfig): BrickConfig {\n return config;\n}\n\n/** A user's mistake: a missing file, an invalid config, or flags that conflict. `brick` prints the message alone. */\nexport class ConfigError extends Error {}\n\n/** The project: its config file, if any, and every path with defaults applied. */\nexport interface LoadedConfig {\n /** Absolute path of the config file; absent when the project has none. */\n file?: string;\n /** Folder the config's paths are relative to (the working folder without a file). */\n root: string;\n config: BrickConfig;\n /** Absolute paths with defaults applied. */\n entry: string;\n services: string;\n generated: string;\n /** Where the client contract goes: `client.output`, else `<generated>/contract.ts`. */\n contract: string;\n /** Where `brick build` writes: `build.outdir`, else `dist/brick`. */\n outdir: string;\n}\n\n/** The nearest `brick.config.ts` in `cwd` or its parents. */\nexport function findConfigFile(cwd = process.cwd()): string | undefined {\n for (let dir = resolve(cwd); ; dir = dirname(dir)) {\n const file = join(dir, CONFIG_FILE);\n if (existsSync(file)) return file;\n if (dirname(dir) === dir) return undefined;\n }\n}\n\n/**\n * The project, from `explicit` (`--config`) when given, else the nearest\n * `brick.config.ts`, validated. Without a file, the defaults from `cwd`.\n */\nexport async function resolveProject(\n explicit?: string,\n cwd = process.cwd(),\n): Promise<LoadedConfig> {\n const file = explicit ? resolve(cwd, explicit) : findConfigFile(cwd);\n if (file && !existsSync(file))\n throw new ConfigError(`Brick: config file not found: ${file}`);\n const config: BrickConfig = file\n ? (await import(pathToFileURL(file).href)).default\n : {};\n if (file)\n validateConfig(config, file.endsWith(CONFIG_FILE) ? CONFIG_FILE : file);\n const root = file ? dirname(file) : resolve(cwd);\n const generated = resolve(\n root,\n config.generated ?? PROJECT_DEFAULTS.generated,\n );\n return {\n file,\n root,\n config,\n entry: resolve(root, config.entry ?? PROJECT_DEFAULTS.entry),\n services: resolve(root, config.services ?? PROJECT_DEFAULTS.services),\n generated,\n contract: config.client?.output\n ? resolve(root, config.client.output)\n : join(generated, CONTRACT_FILE),\n outdir: resolve(root, config.build?.outdir ?? DEFAULT_OUTDIR),\n };\n}\n\n/**\n * Load and validate the project's config: `explicit` (`--config`) when given,\n * else the nearest `brick.config.ts`. Returns undefined when there is none.\n */\nexport async function loadConfig(\n explicit?: string,\n cwd = process.cwd(),\n): Promise<LoadedConfig | undefined> {\n const project = await resolveProject(explicit, cwd);\n return project.file ? project : undefined;\n}\n\n/** The dashboard flags of `brick dev`. */\nexport interface DevDashboardFlags {\n /** `false` with `--no-dashboard`. */\n dashboard?: boolean;\n dashboardPort?: number;\n historyDays?: number;\n dashboardExtension?: string;\n}\n\n/**\n * Whether `brick dev` serves its dashboard, and its port and history, from the\n * config's `dev.dashboard` and the flags. The config can turn it off; a port or\n * history flag turns it back on.\n *\n * @throws ConfigError When a dashboard flag is combined with turning it off.\n */\nexport function resolveDevDashboard(\n configured: NonNullable<BrickConfig[\"dev\"]>[\"dashboard\"],\n flags: DevDashboardFlags,\n): { port?: number; historyDays?: number } | false {\n if (flags.dashboard === false) {\n if (flags.dashboardPort !== undefined)\n throw new ConfigError(\n \"Brick: --dashboard-port cannot be combined with --no-dashboard.\",\n );\n if (flags.historyDays !== undefined)\n throw new ConfigError(\n \"Brick: --history-days cannot be combined with --no-dashboard.\",\n );\n }\n const off =\n flags.dashboard === false ||\n (configured === false &&\n flags.dashboardPort === undefined &&\n flags.historyDays === undefined);\n if (off && flags.dashboardExtension)\n throw new ConfigError(\n flags.dashboard === false\n ? \"Brick: --dashboard-extension cannot be combined with --no-dashboard.\"\n : \"Brick: --dashboard-extension needs the dashboard, which dev.dashboard: false in the config turns off.\",\n );\n if (off) return false;\n const settings = configured || undefined;\n return {\n port: flags.dashboardPort ?? settings?.port,\n historyDays: flags.historyDays ?? settings?.historyDays,\n };\n}\n\n/** A port from a flag, else `PORT`, else the config, else 4000; throws outside 1-65535. */\nexport function resolvePort(\n flag?: number | string,\n configured?: number,\n env = process.env.PORT,\n): number {\n const port = Number(flag ?? (env || undefined) ?? configured ?? DEFAULT_PORT);\n if (!Number.isInteger(port) || port < 1 || port > 65535)\n throw new Error(\n `Invalid port: ${port}. Port must be an integer between 1 and 65535`,\n );\n return port;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The schema of `key` inside `schema`, looking into the object of a union. */\nfunction child(schema: TSchema, key: string): TSchema | undefined {\n const object: TSchema =\n schema.anyOf?.find((s: TSchema) => s.type === \"object\") ?? schema;\n return (\n object.properties?.[key] ??\n (object.patternProperties &&\n (Object.values(object.patternProperties)[0] as TSchema)) ??\n object.items\n );\n}\n\n/** Throws on an unknown key, a bad type, or `dev.frontend` without `client.output`. */\nexport function validateConfig(\n config: unknown,\n label = CONFIG_FILE,\n): asserts config is BrickConfig {\n const fail = (message: string): never => {\n throw new ConfigError(`${label}: ${message}`);\n };\n let error = Value.Errors(BrickConfigSchema, config).First();\n const keys: string[] = [];\n // `false` or an object: given an object, report what is wrong inside it.\n while (error?.schema.anyOf && isPlainObject(error.value)) {\n const object = error.schema.anyOf.find((s: TSchema) => s.type === \"object\");\n if (!object) break;\n keys.push(...error.path.split(\"/\").slice(1));\n error = Value.Errors(object, error.value).First();\n }\n if (error) {\n keys.push(...error.path.split(\"/\").slice(1));\n if (error.type === ValueErrorType.ObjectAdditionalProperties)\n fail(`unknown key ${keys.join(\".\")}`);\n // The message of the deepest schema that has one, at that schema's path.\n let schema: TSchema | undefined = BrickConfigSchema;\n let message: string = schema.message;\n let at = 0;\n keys.forEach((key, index) => {\n schema = schema && child(schema, key);\n if (schema?.message) [message, at] = [schema.message, index + 1];\n else if (schema?.type === \"object\" && index === keys.length - 1)\n [message, at] = [\"must be an object\", index + 1];\n });\n fail(at ? `${keys.slice(0, at).join(\".\")} ${message}` : message);\n }\n const typed = config as BrickConfig;\n if (typed.dev?.frontend && !typed.client?.output)\n fail(\"dev.frontend requires client.output\");\n}\n"],"mappings":";;;;;;AAkBA,MAAM,eAAe;CAAC;CAAe;CAAU;CAAU;AAAQ;AACjE,MAAM,aAAa;CAAC;CAAS;CAAQ;AAAK;AAI1C,MAAa,eAAe;AAC5B,MAAa,yBAAyB;AACtC,MAAa,uBAAuB;AACpC,MAAa,i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e,KAAK,KAAK,GAAG,GAAG;EAEtC,IAAI,SAA8B;EAClC,IAAI,UAAkB,OAAO;EAC7B,IAAI,KAAK;EACT,KAAK,SAAS,KAAK,UAAU;GAC3B,SAAS,UAAU,MAAM,QAAQ,GAAG;GACpC,IAAI,QAAQ,SAAS,CAAC,SAAS,MAAM,CAAC,OAAO,SAAS,QAAQ,CAAC;QAC1D,IAAI,QAAQ,SAAS,YAAY,UAAU,KAAK,SAAS,GAC5D,CAAC,SAAS,MAAM,CAAC,qBAAqB,QAAQ,CAAC;EACnD,CAAC;EACD,KAAK,KAAK,GAAG,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,YAAY,OAAO;CACjE;CACA,MAAM,QAAQ;CACd,IAAI,MAAM,KAAK,YAAY,CAAC,MAAM,QAAQ,QACxC,KAAK,qCAAqC;AAC9C"}
@@ -1,4 +1,6 @@
1
- //#region src/dashboard-extension.d.ts
1
+ import "@brickkit/core";
2
+ import "@brickkit/core/client";
3
+ import "@opentelemetry/api";
2
4
  /** Token values for the dashboard's light and dark themes, its radius and fonts. */
3
5
  interface DashboardTheme {
4
6
  /** Colour tokens in light mode, by name: `{ primary: "oklch(0.55 0.2 260)" }`. */
@@ -22,6 +24,5 @@ interface DashboardExtensionOptions {
22
24
  extension?: string;
23
25
  theme?: DashboardTheme;
24
26
  }
25
- //#endregion
26
27
  export { DashboardTheme as n, DashboardExtensionOptions as t };
27
28
  //# sourceMappingURL=dashboard-extension.d.ts.map