@brickkit/cli 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dashboard-dist/{api-reference-B-bZRtNV.js → api-reference-mT9VNcPb.js} +69 -69
  2. package/dashboard-dist/app.css +1 -1
  3. package/dashboard-dist/app.js +12 -13
  4. package/dashboard-dist/{client-BJJtVSVr.js → client-CwATkLJa.js} +1 -1
  5. package/dashboard-dist/{core-Z7NJFk0K.js → core-BEUWp6B5.js} +1 -1
  6. package/dashboard-dist/docs-BRrtyxDB.js +4 -0
  7. package/dashboard-dist/kit.js +1 -1
  8. package/dashboard-dist/popover-Bj9x-88h.js +1 -0
  9. package/dist/bin.js +154 -217
  10. package/dist/bin.js.map +1 -1
  11. package/dist/build.js +463 -0
  12. package/dist/build.js.map +1 -0
  13. package/dist/client-contract-file.js +356 -1
  14. package/dist/client-contract-file.js.map +1 -0
  15. package/dist/compiler.d.ts +12 -2
  16. package/dist/compiler2.js +12 -5
  17. package/dist/compiler2.js.map +1 -1
  18. package/dist/config.d.ts +3 -0
  19. package/dist/config.js +1 -250
  20. package/dist/config2.d.ts +122 -0
  21. package/dist/config2.js +207 -0
  22. package/dist/config2.js.map +1 -0
  23. package/dist/dashboard-extension.d.ts +3 -0
  24. package/dist/{dev-telemetry-store.js → dashboard-host.js} +1533 -1574
  25. package/dist/dashboard-host.js.map +1 -0
  26. package/dist/dashboard-protocol.js +189 -0
  27. package/dist/dashboard-protocol.js.map +1 -0
  28. package/dist/dashboard.d.ts +4 -1
  29. package/dist/definitions.js +33 -0
  30. package/dist/definitions.js.map +1 -0
  31. package/dist/dev-application.js +34 -0
  32. package/dist/dev-application.js.map +1 -0
  33. package/dist/dev-protocol.js +21 -0
  34. package/dist/dev-protocol.js.map +1 -0
  35. package/dist/dev-reporter.js +2 -1
  36. package/dist/dev-reporter.js.map +1 -1
  37. package/dist/dev-telemetry.js +5 -20
  38. package/dist/dev-telemetry.js.map +1 -1
  39. package/dist/dev-worker.js +79 -19
  40. package/dist/dev-worker.js.map +1 -1
  41. package/dist/index.d.ts +15 -74
  42. package/dist/index.js +12 -5
  43. package/dist/index.js.map +1 -0
  44. package/dist/lint/oxlint.js +5 -3
  45. package/dist/lint/oxlint.js.map +1 -1
  46. package/dist/own-module.js +7 -0
  47. package/dist/own-module.js.map +1 -0
  48. package/dist/plugin.d.ts +6 -5
  49. package/dist/plugin.js +5 -39
  50. package/dist/plugin.js.map +1 -1
  51. package/dist/production-dashboard.d.ts +2 -0
  52. package/dist/production-dashboard.js +51 -0
  53. package/dist/production-dashboard.js.map +1 -0
  54. package/dist/production-dashboard2.d.ts +34 -0
  55. package/dist/{presets.js → project.js} +104 -106
  56. package/dist/project.js.map +1 -0
  57. package/dist/serve.d.ts +24 -0
  58. package/dist/serve.js +1 -0
  59. package/dist/serve2.js +49 -0
  60. package/dist/serve2.js.map +1 -0
  61. package/dist/vite.js +26 -47
  62. package/dist/vite.js.map +1 -1
  63. package/dist/workflows.d.ts +2 -2
  64. package/dist/workflows2.js +59 -37
  65. package/dist/workflows2.js.map +1 -1
  66. package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
  67. package/inspector-dist/client/assets/{highlighted-body-B3W2YXNL-DYVdwGy2.js → highlighted-body-B3W2YXNL-CfRnuITN.js} +1 -1
  68. package/inspector-dist/client/assets/{home-CyjkvtII.js → home-hwPlkNhv.js} +1529 -378
  69. package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
  70. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
  71. package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
  72. package/inspector-dist/client/assets/{root-DX9wtogx.js → root-SLeEf-sT.js} +17 -29
  73. package/inspector-dist/client/assets/{run-detail-C69EJGql.js → run-detail-DYbVkIFH.js} +398 -76
  74. package/inspector-dist/client/assets/{tabs-B6B88IjT.js → tabs-CaJisoyb.js} +189 -2130
  75. package/inspector-dist/client/assets/{zstd-browser-decoder-ByUgcY9H.js → zstd-browser-decoder-D94wmfAU.js} +1 -1
  76. package/inspector-dist/server/assets/{app-WoDoT62X.js → app-DGlfWVUI.js} +69783 -70608
  77. package/inspector-dist/server/assets/{chunk-RLXIAIE6-CbvDIAEa.js → chunk-RLXIAIE6-F0SJZlei.js} +4 -6
  78. package/inspector-dist/server/assets/{dist-qR-969AD.js → dist-BCbwm6jl.js} +2 -4
  79. package/inspector-dist/server/assets/{dist-CQnQcIJg.js → dist-CG2aVufI.js} +0 -2
  80. package/inspector-dist/server/assets/{dist-BRxZSWUN.js → dist-Ce0I2PUv.js} +2 -5
  81. package/inspector-dist/server/assets/{dist-DqRd9pyS.js → dist-DY0UlahA.js} +0 -2
  82. package/inspector-dist/server/assets/{encryption-_PuklZNX.js → encryption-DdQgC8Rk.js} +2 -4
  83. package/inspector-dist/server/assets/{event-metadata-BVakQJ_y.js → event-metadata-n7E4zEmT.js} +0 -2
  84. package/inspector-dist/server/assets/{functions-CImcpqNl.js → functions-CNVQtbgg.js} +2 -4
  85. package/inspector-dist/server/assets/{global-singleton-CPirHxFh.js → global-singleton-D8sIN5du.js} +0 -2
  86. package/inspector-dist/server/assets/{highlighted-body-B3W2YXNL-fPMB_t7F.js → highlighted-body-B3W2YXNL-CWRzMxYD.js} +2 -4
  87. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
  88. package/inspector-dist/server/assets/{parse-D9Vvgzt9.js → parse-Begau9cA.js} +0 -2
  89. package/inspector-dist/server/assets/{rolldown-runtime-CLg409Sh.js → rolldown-runtime-C1I3wEg2.js} +1 -2
  90. package/inspector-dist/server/assets/{serialization-format-DDtsVTU1.js → serialization-format-BbuGfHog.js} +6 -8
  91. package/inspector-dist/server/assets/{token-BW4GdQZh.js → token-BgMmJNP5.js} +2 -4
  92. package/inspector-dist/server/assets/{token-D6FXdkJT.js → token-BrUX0bxz.js} +2 -4
  93. package/inspector-dist/server/assets/{token-util-BoNmi-wE.js → token-util-DZN32qmT.js} +1 -3
  94. package/inspector-dist/server/assets/{wrapper-wiqsGXcE.js → wrapper-CIC3w0oC.js} +1 -3
  95. package/inspector-dist/server/assets/{ws-transport-DV7oG4mL.js → ws-transport-CxTYB11n.js} +24094 -24096
  96. package/inspector-dist/server/assets/{zstd-browser-decoder-Cswf0KO6.js → zstd-browser-decoder-D7bCXbGg.js} +2 -4
  97. package/inspector-dist/server/index.js +1 -3
  98. package/package.json +12 -2
  99. package/dashboard-dist/docs-Dpfc0wJb.js +0 -4
  100. package/dashboard-dist/popover-BzejBolB.js +0 -1
  101. package/dist/app-entry.js +0 -1
  102. package/dist/app-entry2.js +0 -18
  103. package/dist/app-entry2.js.map +0 -1
  104. package/dist/client-contract-file2.js +0 -33
  105. package/dist/client-contract-file2.js.map +0 -1
  106. package/dist/client-contract.js +0 -1
  107. package/dist/client-contract2.js +0 -296
  108. package/dist/client-contract2.js.map +0 -1
  109. package/dist/config.js.map +0 -1
  110. package/dist/dev-telemetry-store.js.map +0 -1
  111. package/dist/emit.d.ts +0 -5
  112. package/dist/presets.js.map +0 -1
  113. package/dist/runner.js +0 -519
  114. package/dist/runner.js.map +0 -1
  115. package/inspector-dist/client/assets/app-CCzpuUz_.css +0 -2
  116. package/inspector-dist/client/assets/manifest-ba30b52d.js +0 -1
  117. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +0 -1
  118. package/inspector-dist/client/assets/root-8BMab1lL.css +0 -2
  119. package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +0 -30
  120. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +0 -3
@@ -1,296 +0,0 @@
1
- import { getActionRoute, getPluginActionRoute, serializeSocketSchema } from "@brickkit/core";
2
- import { createHash } from "node:crypto";
3
- // src/client-contract.ts
4
- /** Generate browser metadata and transport types from the app's selected services. */
5
- function generateClientContract(app) {
6
- const { services, prefix } = app.definition;
7
- const contract = Object.create(null);
8
- const types = Object.create(null);
9
- const schemas = new SchemaTypes();
10
- for (const service of services) {
11
- addServiceActions(service, prefix, contract, types, schemas);
12
- for (const socket of service.listSockets()) {
13
- const route = app.definition.sockets.find((route) => route.service === service.name && route.name === socket.schema.name);
14
- if (!route) throw new Error(`Brick client: missing socket route '${service.name}.${socket.schema.name}'`);
15
- try {
16
- const metadata = {
17
- kind: "socket",
18
- name: socket.schema.name,
19
- serviceName: service.name,
20
- config: { path: route.path },
21
- output: Object.fromEntries(Object.entries(socket.output).map(([key, schema]) => [key, serializeSocketSchema(schema)]))
22
- };
23
- const payloads = (map) => `{ ${Object.entries(map).map(([key, schema]) => `${JSON.stringify(key)}: ${schemas.generate(schema)}`).join("; ")} }`;
24
- insertAction(contract[service.name], types[service.name], metadata, `BrickClientSocket<${payloads(socket.input)}, ${payloads(socket.output)}, ${errorsType(socket.errors)}>`);
25
- } catch (error) {
26
- throw new Error(`Brick client: cannot generate socket '${service.name}.${socket.schema.name}': ${String(error)}`);
27
- }
28
- }
29
- }
30
- return `// Generated by the Brick Vite plugin. Do not edit.
31
- import type { BrickClientAction${app.definition.sockets.length ? ", BrickClientSocket" : ""} } from "@brickkit/core/client";
32
-
33
- ${schemas.renderContract(namespaceType(types))}
34
-
35
- export const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});
36
-
37
- // Types useService(service) on the server from this contract.
38
- declare module "@brickkit/core/client" {
39
- interface BrickServices extends AppContract {}
40
- }
41
- `;
42
- }
43
- function addServiceActions(service, prefix, contract, types, schemas) {
44
- const namespace = contract[service.name] ?? Object.create(null);
45
- const namespaceTypes = types[service.name] ?? Object.create(null);
46
- contract[service.name] = namespace;
47
- types[service.name] = namespaceTypes;
48
- for (const action of service.listActions()) {
49
- const route = getActionRoute(action, prefix);
50
- if (route === false) continue;
51
- const pluginRoute = getPluginActionRoute(action, prefix) || void 0;
52
- const { input, output, errors } = action.config;
53
- let inputType;
54
- let outputType;
55
- try {
56
- inputType = input ? schemas.generate(input) : "unknown";
57
- outputType = output ? schemas.generate(output) : "unknown";
58
- } catch (error) {
59
- throw new Error(`Brick client: cannot generate '${service.name}.${action.name}': ${error.message}`);
60
- }
61
- const metadata = {
62
- kind: "action",
63
- name: action.name,
64
- serviceName: service.name,
65
- ...action.plugin ? { plugin: action.plugin } : pluginRoute?.plugin ? { plugin: pluginRoute.plugin } : {},
66
- ...action.resource ? { resource: action.resource } : pluginRoute?.resource ? { resource: pluginRoute.resource } : {},
67
- config: {
68
- path: route.path,
69
- method: route.method
70
- }
71
- };
72
- insertAction(pluginRoute?.clientPath ? contract : namespace, pluginRoute?.clientPath ? types : namespaceTypes, metadata, actionType(inputType, outputType, errors), pluginRoute?.clientPath);
73
- }
74
- }
75
- function insertAction(node, typeNode, metadata, type, clientPath) {
76
- const segments = clientPath ?? metadata.name.split(".");
77
- for (const segment of segments.slice(0, -1)) {
78
- if (Object.hasOwn(typeNode, segment) && typeof typeNode[segment] === "string") throw new Error(`Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`);
79
- node[segment] ??= Object.create(null);
80
- typeNode[segment] ??= Object.create(null);
81
- node = node[segment];
82
- typeNode = typeNode[segment];
83
- }
84
- const leaf = segments.at(-1);
85
- if (Object.hasOwn(node, leaf)) throw new Error(`Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`);
86
- node[leaf] = metadata;
87
- typeNode[leaf] = type;
88
- }
89
- function actionType(input, output, errors) {
90
- return `BrickClientAction<${input}, ${output}, ${errorsType(errors)}>`;
91
- }
92
- function errorsType(errors) {
93
- const codes = Object.keys(errors ?? {});
94
- return codes.length ? `Record<${codes.map((code) => JSON.stringify(code)).join(" | ")}, { message: string; status?: number }>` : "{}";
95
- }
96
- function namespaceType(node) {
97
- return `{\n${Object.entries(node).map(([key, value]) => ` ${JSON.stringify(key)}: ${typeof value === "string" ? value : namespaceType(value)};`).join("\n")}\n}`;
98
- }
99
- var SchemaTypes = class {
100
- aliases = /* @__PURE__ */ new Map();
101
- names = /* @__PURE__ */ new Set([
102
- "AppContract",
103
- "BrickClientAction",
104
- "BrickClientSocket",
105
- "contract"
106
- ]);
107
- fragments = [];
108
- fragmentIds = /* @__PURE__ */ new Map();
109
- fragment(body) {
110
- let id = this.fragmentIds.get(body);
111
- if (id === void 0) {
112
- id = this.fragments.length;
113
- const size = body.replace(/\0(\d+)\0/g, "").length + [...body.matchAll(/\0(\d+)\0/g)].reduce((total, match) => total + this.fragments[Number(match[1])].size, 0);
114
- const shape = body.replace(/\0(\d+)\0/g, (_, child) => this.fragments[Number(child)].hash);
115
- const hash = createHash("sha256").update(shape).digest("hex");
116
- this.fragments.push({
117
- body,
118
- size,
119
- hash
120
- });
121
- this.fragmentIds.set(body, id);
122
- }
123
- return `\0${id}\0`;
124
- }
125
- renderContract(contract) {
126
- const uses = this.fragments.map(() => 0);
127
- const count = (body, multiplier) => {
128
- for (const match of body.matchAll(/\0(\d+)\0/g)) uses[Number(match[1])] += multiplier;
129
- };
130
- count(contract, 1);
131
- for (const body of this.aliases.values()) count(body, 1);
132
- const shared = /* @__PURE__ */ new Map();
133
- for (let id = this.fragments.length - 1; id >= 0; id--) {
134
- const { body, size, hash } = this.fragments[id];
135
- const nameBase = `BrickSchema_${hash.slice(0, 12)}`;
136
- let name = nameBase;
137
- let suffix = 2;
138
- while (this.names.has(name)) name = `${nameBase}_${suffix++}`;
139
- const declarationCost = `export type ${name} = ;\n\n`.length;
140
- if (uses[id] > 1 && (uses[id] - 1) * size > uses[id] * name.length + declarationCost) {
141
- this.names.add(name);
142
- shared.set(id, name);
143
- }
144
- count(body, shared.has(id) ? 1 : uses[id]);
145
- }
146
- const rendered = [];
147
- const declarations = [];
148
- for (let id = 0; id < this.fragments.length; id++) {
149
- const body = this.fragments[id].body.replace(/\0(\d+)\0/g, (_, child) => rendered[Number(child)]);
150
- const name = shared.get(id);
151
- if (name && (uses[id] - 1) * body.length > uses[id] * name.length + `export type ${name} = ;\n\n`.length) {
152
- declarations.push(`export type ${name} = ${body};\n\n`);
153
- rendered.push(name);
154
- } else rendered.push(body);
155
- }
156
- const render = (body) => body.replace(/\0(\d+)\0/g, (_, id) => rendered[Number(id)]);
157
- return declarations.join("") + [...this.aliases].map(([name, type]) => `export type ${name} = ${render(type)};\n\n`).join("") + `export type AppContract = ${render(contract)};`;
158
- }
159
- generate(root) {
160
- const ids = /* @__PURE__ */ new Map();
161
- const references = [];
162
- const resources = /* @__PURE__ */ new Map();
163
- const active = /* @__PURE__ */ new Set();
164
- const visit = (schema, base) => {
165
- if (!schema || typeof schema !== "object" || active.has(schema)) return;
166
- const currentBase = typeof schema.$id === "string" && schema.$id ? schema : base;
167
- if (!resources.has(schema)) resources.set(schema, currentBase);
168
- if (typeof schema.$ref === "string") references.push({
169
- ref: schema.$ref,
170
- base: currentBase
171
- });
172
- active.add(schema);
173
- try {
174
- if (typeof schema.$id === "string" && schema.$id) ids.set(schema.$id, schema);
175
- for (const key of [
176
- "properties",
177
- "patternProperties",
178
- "$defs",
179
- "definitions"
180
- ]) for (const child of Object.values(schema[key] ?? {})) visit(child, currentBase);
181
- for (const key of [
182
- "anyOf",
183
- "oneOf",
184
- "allOf",
185
- "prefixItems"
186
- ]) for (const child of schema[key] ?? []) visit(child, currentBase);
187
- for (const key of [
188
- "items",
189
- "additionalProperties",
190
- "not"
191
- ]) if (Array.isArray(schema[key])) schema[key].forEach((child) => visit(child, currentBase));
192
- else visit(schema[key], currentBase);
193
- } finally {
194
- active.delete(schema);
195
- }
196
- };
197
- visit(root, root);
198
- const resolve = (reference, base) => {
199
- const hashIndex = reference.indexOf("#");
200
- const id = hashIndex === -1 ? reference : reference.slice(0, hashIndex);
201
- const fragment = hashIndex === -1 ? void 0 : reference.slice(hashIndex + 1);
202
- let target = id ? ids.get(id) : base;
203
- if (fragment) {
204
- if (!fragment.startsWith("/")) return void 0;
205
- try {
206
- for (const part of decodeURIComponent(fragment).slice(1).split("/")) {
207
- const key = part.replaceAll("~1", "/").replaceAll("~0", "~");
208
- if (!target || !Object.hasOwn(target, key)) return void 0;
209
- target = target[key];
210
- }
211
- } catch {
212
- return;
213
- }
214
- }
215
- return typeof target === "boolean" || target && typeof target === "object" ? target : void 0;
216
- };
217
- const targets = new Set(references.map(({ ref, base }) => resolve(ref, base)).filter((value) => value !== void 0));
218
- const names = /* @__PURE__ */ new Map();
219
- const emit = (schema, inline = false, base = root) => {
220
- const body = emitInline(schema, inline, base);
221
- if (schema && !schema.$ref && !Object.hasOwn(schema, "const") && (schema.anyOf || schema.oneOf || schema.allOf || schema.enum?.length > 1 || schema.type === "array" || schema.type === "object")) return this.fragment(body);
222
- return body;
223
- };
224
- const emitInline = (schema, inline, base) => {
225
- if (schema === void 0 || schema === true) return "unknown";
226
- if (schema === false || schema.not && !Object.keys(schema.not).length) return "never";
227
- const currentBase = schema && typeof schema === "object" && typeof schema.$id === "string" && schema.$id ? schema : base;
228
- if (!inline && targets.has(schema)) {
229
- const existing = names.get(schema);
230
- if (existing) return existing;
231
- const hint = schema.title ?? schema.$id ?? "Schema";
232
- let nameBase = String(hint).replace(/[^a-zA-Z0-9_$]/g, "_");
233
- if (!/^[a-zA-Z_$]/.test(nameBase)) nameBase = `Schema_${nameBase}`;
234
- nameBase = `Brick${nameBase}`;
235
- let name = nameBase;
236
- let suffix = 2;
237
- while (this.names.has(name)) {
238
- name = `${nameBase}_${suffix}`;
239
- suffix += 1;
240
- }
241
- this.names.add(name);
242
- names.set(schema, name);
243
- this.aliases.set(name, emit(schema, true, currentBase));
244
- return name;
245
- }
246
- if (schema.$ref) {
247
- const target = resolve(schema.$ref, currentBase);
248
- if (target === void 0) throw new Error(`unresolved schema reference '${schema.$ref}'`);
249
- const targetBase = target && typeof target === "object" ? resources.get(target) ?? root : currentBase;
250
- return emit(target, false, targetBase);
251
- }
252
- if (Object.hasOwn(schema, "const")) return JSON.stringify(schema.const);
253
- if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
254
- if (schema.anyOf || schema.oneOf) return `(${(schema.anyOf ?? schema.oneOf).map((child) => emit(child, false, currentBase)).join(" | ")})`;
255
- if (schema.allOf) return `(${schema.allOf.map((child) => emit(child, false, currentBase)).join(" & ")})`;
256
- switch (schema.type) {
257
- case "string": return "string";
258
- case "number":
259
- case "integer": return "number";
260
- case "boolean": return "boolean";
261
- case "null": return "null";
262
- case "undefined":
263
- case "void": return "undefined";
264
- case "array":
265
- if (Array.isArray(schema.items)) return `[${schema.items.map((child) => emit(child, false, currentBase)).join(", ")}]`;
266
- return `Array<${emit(schema.items, false, currentBase)}>`;
267
- case "object": {
268
- const entries = Object.entries(schema.properties ?? {});
269
- const properties = entries.map(([key, value]) => `${JSON.stringify(key)}${schema.required?.includes(key) ? "" : "?"}: ${emit(value, false, currentBase)};`);
270
- const indexParts = Object.values(schema.patternProperties ?? {}).map((child) => emit(child, false, currentBase));
271
- if (schema.additionalProperties) indexParts.push(emit(schema.additionalProperties, false, currentBase));
272
- let indexType;
273
- if (indexParts.length) {
274
- for (const [, value] of entries) {
275
- const propType = emit(value, false, currentBase);
276
- if (!indexParts.includes(propType)) indexParts.push(propType);
277
- }
278
- indexType = indexParts.join(" | ");
279
- }
280
- const object = `{ ${properties.join(" ")} }`;
281
- if (indexType) {
282
- const index = `{ [key: string]: ${indexType} }`;
283
- return properties.length ? `${object} & ${index}` : index;
284
- }
285
- return object;
286
- }
287
- case void 0: return "unknown";
288
- default: throw new Error(`unsupported transport schema type '${schema.type}'`);
289
- }
290
- };
291
- return emit(root);
292
- }
293
- };
294
- export { generateClientContract as t };
295
-
296
- //# sourceMappingURL=client-contract2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-contract2.js","names":[],"sources":["../src/client-contract.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport {\n getActionRoute,\n getPluginActionRoute,\n serializeSocketSchema,\n type Service,\n} from \"@brickkit/core\";\nimport type {\n BrickClientAction,\n BrickClientSocket,\n} from \"@brickkit/core/client\";\nimport type { BrickApp } from \"@brickkit/core\";\n\n/** Generate browser metadata and transport types from the app's selected services. */\nexport function generateClientContract(app: BrickApp): string {\n const { services, prefix } = app.definition;\n const contract: Record<string, any> = Object.create(null);\n const types: Record<string, any> = Object.create(null);\n const schemas = new SchemaTypes();\n for (const service of services) {\n addServiceActions(service, prefix, contract, types, schemas);\n for (const socket of service.listSockets()) {\n const route = app.definition.sockets.find(\n (route) =>\n route.service === service.name && route.name === socket.schema.name,\n );\n if (!route)\n throw new Error(\n `Brick client: missing socket route '${service.name}.${socket.schema.name}'`,\n );\n try {\n const metadata: BrickClientSocket = {\n kind: \"socket\",\n name: socket.schema.name,\n serviceName: service.name,\n config: { path: route.path },\n output: Object.fromEntries(\n Object.entries(socket.output).map(([key, schema]) => [\n key,\n serializeSocketSchema(schema),\n ]),\n ),\n };\n const payloads = (map: typeof socket.input) =>\n `{ ${Object.entries(map)\n .map(\n ([key, schema]) =>\n `${JSON.stringify(key)}: ${schemas.generate(schema)}`,\n )\n .join(\"; \")} }`;\n insertAction(\n contract[service.name],\n types[service.name],\n metadata,\n `BrickClientSocket<${payloads(socket.input)}, ${payloads(socket.output)}, ${errorsType(socket.errors)}>`,\n );\n } catch (error) {\n throw new Error(\n `Brick client: cannot generate socket '${service.name}.${socket.schema.name}': ${String(error)}`,\n );\n }\n }\n }\n return `// Generated by the Brick Vite plugin. Do not edit.\nimport type { BrickClientAction${app.definition.sockets.length ? \", BrickClientSocket\" : \"\"} } from \"@brickkit/core/client\";\n\n${schemas.renderContract(namespaceType(types))}\n\nexport const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});\n\n// Types useService(service) on the server from this contract.\ndeclare module \"@brickkit/core/client\" {\n interface BrickServices extends AppContract {}\n}\n`;\n}\n\nfunction addServiceActions(\n service: Service<any, any>,\n prefix: string,\n contract: Record<string, any>,\n types: Record<string, any>,\n schemas: SchemaTypes,\n) {\n const namespace: Record<string, any> =\n contract[service.name] ?? Object.create(null);\n const namespaceTypes: Record<string, any> =\n types[service.name] ?? Object.create(null);\n contract[service.name] = namespace;\n types[service.name] = namespaceTypes;\n for (const action of service.listActions()) {\n const route = getActionRoute(action, prefix);\n if (route === false) continue;\n const pluginRoute = getPluginActionRoute(action, prefix) || undefined;\n const { input, output, errors } = action.config;\n let inputType: string;\n let outputType: string;\n try {\n inputType = input ? schemas.generate(input) : \"unknown\";\n outputType = output ? schemas.generate(output) : \"unknown\";\n } catch (error) {\n throw new Error(\n `Brick client: cannot generate '${service.name}.${action.name}': ${(error as Error).message}`,\n );\n }\n const metadata: BrickClientAction = {\n kind: \"action\",\n name: action.name,\n serviceName: service.name,\n ...((action as { plugin?: string }).plugin\n ? { plugin: (action as { plugin?: string }).plugin }\n : pluginRoute?.plugin\n ? { plugin: pluginRoute.plugin }\n : {}),\n ...((action as { resource?: string }).resource\n ? { resource: (action as { resource?: string }).resource }\n : pluginRoute?.resource\n ? { resource: pluginRoute.resource }\n : {}),\n config: { path: route.path, method: route.method },\n };\n insertAction(\n pluginRoute?.clientPath ? contract : namespace,\n pluginRoute?.clientPath ? types : namespaceTypes,\n metadata,\n actionType(inputType, outputType, errors),\n pluginRoute?.clientPath,\n );\n }\n}\n\nfunction insertAction(\n node: Record<string, any>,\n typeNode: Record<string, any>,\n metadata: BrickClientAction | BrickClientSocket,\n type: string,\n clientPath?: readonly string[],\n) {\n const segments = clientPath ?? metadata.name.split(\".\");\n for (const segment of segments.slice(0, -1)) {\n if (\n Object.hasOwn(typeNode, segment) &&\n typeof typeNode[segment] === \"string\"\n ) {\n throw new Error(\n `Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`,\n );\n }\n node[segment] ??= Object.create(null);\n typeNode[segment] ??= Object.create(null);\n node = node[segment];\n typeNode = typeNode[segment];\n }\n const leaf = segments.at(-1)!;\n if (Object.hasOwn(node, leaf))\n throw new Error(\n `Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`,\n );\n node[leaf] = metadata;\n typeNode[leaf] = type;\n}\n\nfunction actionType(\n input: string,\n output: string,\n errors: Record<string, unknown> | undefined,\n): string {\n return `BrickClientAction<${input}, ${output}, ${errorsType(errors)}>`;\n}\n\nfunction errorsType(errors: Record<string, unknown> | undefined): string {\n const codes = Object.keys(errors ?? {});\n return codes.length\n ? `Record<${codes.map((code) => JSON.stringify(code)).join(\" | \")}, { message: string; status?: number }>`\n : \"{}\";\n}\n\nfunction namespaceType(node: Record<string, any>): string {\n return `{\\n${Object.entries(node)\n .map(\n ([key, value]) =>\n ` ${JSON.stringify(key)}: ${typeof value === \"string\" ? value : namespaceType(value)};`,\n )\n .join(\"\\n\")}\\n}`;\n}\n\n// Emit transport types from schemas, rather than importing backend callbacks or databases.\nclass SchemaTypes {\n private readonly aliases = new Map<string, string>();\n private readonly names = new Set([\n \"AppContract\",\n \"BrickClientAction\",\n \"BrickClientSocket\",\n \"contract\",\n ]);\n\n // Internal tokens cannot occur in JSON-escaped property names or literals.\n private readonly fragments: { body: string; size: number; hash: string }[] =\n [];\n private readonly fragmentIds = new Map<string, number>();\n\n private fragment(body: string): string {\n let id = this.fragmentIds.get(body);\n if (id === undefined) {\n id = this.fragments.length;\n const size =\n body.replace(/\\0(\\d+)\\0/g, \"\").length +\n [...body.matchAll(/\\0(\\d+)\\0/g)].reduce(\n (total, match) => total + this.fragments[Number(match[1])]!.size,\n 0,\n );\n const shape = body.replace(\n /\\0(\\d+)\\0/g,\n (_, child) => this.fragments[Number(child)]!.hash,\n );\n const hash = createHash(\"sha256\").update(shape).digest(\"hex\");\n this.fragments.push({ body, size, hash });\n this.fragmentIds.set(body, id);\n }\n return `\\0${id}\\0`;\n }\n\n renderContract(contract: string): string {\n const uses = this.fragments.map(() => 0);\n const count = (body: string, multiplier: number) => {\n for (const match of body.matchAll(/\\0(\\d+)\\0/g))\n uses[Number(match[1])]! += multiplier;\n };\n count(contract, 1);\n for (const body of this.aliases.values()) count(body, 1);\n const shared = new Map<number, string>();\n // Parents are interned after their children. Once a parent is shared, its\n // children occur only once in its declaration, avoiding overlapping savings.\n for (let id = this.fragments.length - 1; id >= 0; id--) {\n const { body, size, hash } = this.fragments[id]!;\n const nameBase = `BrickSchema_${hash.slice(0, 12)}`;\n let name = nameBase;\n let suffix = 2;\n while (this.names.has(name)) name = `${nameBase}_${suffix++}`;\n const declarationCost = `export type ${name} = ;\\n\\n`.length;\n if (\n uses[id]! > 1 &&\n (uses[id]! - 1) * size > uses[id]! * name.length + declarationCost\n ) {\n this.names.add(name);\n shared.set(id, name);\n }\n count(body, shared.has(id) ? 1 : uses[id]!);\n }\n const rendered: string[] = [];\n const declarations: string[] = [];\n for (let id = 0; id < this.fragments.length; id++) {\n const body = this.fragments[id]!.body.replace(\n /\\0(\\d+)\\0/g,\n (_, child) => rendered[Number(child)]!,\n );\n const name = shared.get(id);\n // Child aliases can make a parent too small to justify sharing it.\n if (\n name &&\n (uses[id]! - 1) * body.length >\n uses[id]! * name.length + `export type ${name} = ;\\n\\n`.length\n ) {\n declarations.push(`export type ${name} = ${body};\\n\\n`);\n rendered.push(name);\n } else rendered.push(body);\n }\n const render = (body: string) =>\n body.replace(/\\0(\\d+)\\0/g, (_, id) => rendered[Number(id)]!);\n return (\n declarations.join(\"\") +\n [...this.aliases]\n .map(([name, type]) => `export type ${name} = ${render(type)};\\n\\n`)\n .join(\"\") +\n `export type AppContract = ${render(contract)};`\n );\n }\n\n generate(root: any): string {\n // IDs belong to this schema document. Separate actions may reuse the same ID.\n const ids = new Map<string, any>();\n const references: { ref: string; base: any }[] = [];\n const resources = new Map<unknown, any>();\n const active = new Set<unknown>();\n const visit = (schema: any, base: any) => {\n if (!schema || typeof schema !== \"object\" || active.has(schema)) return;\n const currentBase =\n typeof schema.$id === \"string\" && schema.$id ? schema : base;\n if (!resources.has(schema)) resources.set(schema, currentBase);\n if (typeof schema.$ref === \"string\")\n references.push({ ref: schema.$ref, base: currentBase });\n active.add(schema);\n try {\n if (typeof schema.$id === \"string\" && schema.$id)\n ids.set(schema.$id, schema);\n for (const key of [\n \"properties\",\n \"patternProperties\",\n \"$defs\",\n \"definitions\",\n ]) {\n for (const child of Object.values(schema[key] ?? {}))\n visit(child, currentBase);\n }\n for (const key of [\"anyOf\", \"oneOf\", \"allOf\", \"prefixItems\"]) {\n for (const child of schema[key] ?? []) visit(child, currentBase);\n }\n for (const key of [\"items\", \"additionalProperties\", \"not\"]) {\n if (Array.isArray(schema[key]))\n schema[key].forEach((child: any) => visit(child, currentBase));\n else visit(schema[key], currentBase);\n }\n } finally {\n active.delete(schema);\n }\n };\n visit(root, root);\n\n const resolve = (reference: string, base: any): any => {\n const hashIndex = reference.indexOf(\"#\");\n const id = hashIndex === -1 ? reference : reference.slice(0, hashIndex);\n const fragment =\n hashIndex === -1 ? undefined : reference.slice(hashIndex + 1);\n let target = id ? ids.get(id) : base;\n if (fragment) {\n if (!fragment.startsWith(\"/\")) return undefined;\n try {\n for (const part of decodeURIComponent(fragment).slice(1).split(\"/\")) {\n const key = part.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n if (!target || !Object.hasOwn(target, key)) return undefined;\n target = target[key];\n }\n } catch {\n return undefined;\n }\n }\n return typeof target === \"boolean\" ||\n (target && typeof target === \"object\")\n ? target\n : undefined;\n };\n const targets = new Set(\n references\n .map(({ ref, base }) => resolve(ref, base))\n .filter((value) => value !== undefined),\n );\n const names = new Map<any, string>();\n const emit = (schema: any, inline = false, base: any = root): string => {\n const body = emitInline(schema, inline, base);\n // References already have document-scoped aliases; scalars stay inline.\n if (\n schema &&\n !schema.$ref &&\n !Object.hasOwn(schema, \"const\") &&\n (schema.anyOf ||\n schema.oneOf ||\n schema.allOf ||\n schema.enum?.length > 1 ||\n schema.type === \"array\" ||\n schema.type === \"object\")\n )\n return this.fragment(body);\n return body;\n };\n const emitInline = (schema: any, inline: boolean, base: any): string => {\n if (schema === undefined || schema === true) return \"unknown\";\n if (schema === false || (schema.not && !Object.keys(schema.not).length))\n return \"never\";\n const currentBase =\n schema &&\n typeof schema === \"object\" &&\n typeof schema.$id === \"string\" &&\n schema.$id\n ? schema\n : base;\n if (!inline && targets.has(schema)) {\n const existing = names.get(schema);\n if (existing) return existing;\n // Titles provide readable names; generated TypeBox IDs remain usable fallbacks.\n const hint = schema.title ?? schema.$id ?? \"Schema\";\n let nameBase = String(hint).replace(/[^a-zA-Z0-9_$]/g, \"_\");\n if (!/^[a-zA-Z_$]/.test(nameBase)) nameBase = `Schema_${nameBase}`;\n nameBase = `Brick${nameBase}`;\n let name = nameBase;\n let suffix = 2;\n while (this.names.has(name)) {\n name = `${nameBase}_${suffix}`;\n suffix += 1;\n }\n this.names.add(name);\n names.set(schema, name);\n // names is reserved before the body is rendered, so recursive refs terminate.\n this.aliases.set(name, emit(schema, true, currentBase));\n return name;\n }\n if (schema.$ref) {\n const target = resolve(schema.$ref, currentBase);\n if (target === undefined)\n throw new Error(`unresolved schema reference '${schema.$ref}'`);\n const targetBase =\n target && typeof target === \"object\"\n ? (resources.get(target) ?? root)\n : currentBase;\n return emit(target, false, targetBase);\n }\n if (Object.hasOwn(schema, \"const\")) return JSON.stringify(schema.const);\n if (schema.enum)\n return (\n schema.enum\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \") || \"never\"\n );\n if (schema.anyOf || schema.oneOf)\n return `(${(schema.anyOf ?? schema.oneOf).map((child: any) => emit(child, false, currentBase)).join(\" | \")})`;\n if (schema.allOf)\n return `(${schema.allOf.map((child: any) => emit(child, false, currentBase)).join(\" & \")})`;\n switch (schema.type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"undefined\":\n case \"void\":\n return \"undefined\";\n case \"array\":\n if (Array.isArray(schema.items))\n return `[${schema.items.map((child: any) => emit(child, false, currentBase)).join(\", \")}]`;\n return `Array<${emit(schema.items, false, currentBase)}>`;\n case \"object\": {\n const entries = Object.entries(schema.properties ?? {});\n const properties = entries.map(\n ([key, value]) =>\n `${JSON.stringify(key)}${schema.required?.includes(key) ? \"\" : \"?\"}: ${emit(value, false, currentBase)};`,\n );\n // additionalProperties applies to keys matched by neither properties\n // nor patternProperties, so union it instead of discarding it.\n const indexParts = Object.values(schema.patternProperties ?? {}).map(\n (child) => emit(child, false, currentBase),\n );\n if (schema.additionalProperties) {\n indexParts.push(\n emit(schema.additionalProperties, false, currentBase),\n );\n }\n let indexType: string | undefined;\n if (indexParts.length) {\n // TS index signatures must also cover declared keys, so widen\n // with their types; otherwise the intersection below rejects\n // valid values. Over-approximating is safe: the server validates.\n for (const [, value] of entries) {\n const propType = emit(value, false, currentBase);\n if (!indexParts.includes(propType)) indexParts.push(propType);\n }\n indexType = indexParts.join(\" | \");\n }\n const object = `{ ${properties.join(\" \")} }`;\n if (indexType) {\n const index = `{ [key: string]: ${indexType} }`;\n return properties.length ? `${object} & ${index}` : index;\n }\n return object;\n }\n case undefined:\n return \"unknown\";\n default:\n throw new Error(`unsupported transport schema type '${schema.type}'`);\n }\n };\n return emit(root);\n }\n}\n"],"mappings":";;;;AAcA,SAAgB,uBAAuB,KAAuB;CAC5D,MAAM,EAAE,UAAU,WAAW,IAAI;CACjC,MAAM,WAAgC,OAAO,OAAO,IAAI;CACxD,MAAM,QAA6B,OAAO,OAAO,IAAI;CACrD,MAAM,UAAU,IAAI,YAAY;CAChC,KAAK,MAAM,WAAW,UAAU;EAC9B,kBAAkB,SAAS,QAAQ,UAAU,OAAO,OAAO;EAC3D,KAAK,MAAM,UAAU,QAAQ,YAAY,GAAG;GAC1C,MAAM,QAAQ,IAAI,WAAW,QAAQ,MAClC,UACC,MAAM,YAAY,QAAQ,QAAQ,MAAM,SAAS,OAAO,OAAO,IACnE;GACA,IAAI,CAAC,OACH,MAAM,IAAI,MACR,uCAAuC,QAAQ,KAAK,GAAG,OAAO,OAAO,KAAK,EAC5E;GACF,IAAI;IACF,MAAM,WAA8B;KAClC,MAAM;KACN,MAAM,OAAO,OAAO;KACpB,aAAa,QAAQ;KACrB,QAAQ,EAAE,MAAM,MAAM,KAAK;KAC3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AW,KAAK,OAAO,OAAO,WAAW;OAC/C,IAAI,CAAC,WAAW,SAAS,QAAQ,GAAG,WAAW,KAAK,QAAQ;MAC9D;MACA,YAAY,WAAW,KAAK,KAAK;KACnC;KACA,MAAM,SAAS,KAAK,WAAW,KAAK,GAAG,EAAE;KACzC,IAAI,WAAW;MACb,MAAM,QAAQ,oBAAoB,UAAU;MAC5C,OAAO,WAAW,SAAS,GAAG,OAAO,KAAK,UAAU;KACtD;KACA,OAAO;IACT;IACA,KAAK,KAAA,GACH,OAAO;IACT,SACE,MAAM,IAAI,MAAM,sCAAsC,OAAO,KAAK,EAAE;GACxE;EACF;EACA,OAAO,KAAK,IAAI;CAClB;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","names":[],"sources":["../src/compiler/aot.ts","../src/build.ts","../src/config.ts"],"sourcesContent":["import { aot } from \"elysia/plugin/aot/bun\";\nimport type { BunPlugin } from \"bun\";\n\n/** Keep the pinned Elysia beta's incomplete stripping from breaking builds. */\nexport function brickAot(entry: string, hasSockets: boolean): BunPlugin {\n // WS routes still need cookie setup during reconstruction in beta.29.\n // Retain those modules while continuing to precompile HTTP handlers.\n if (hasSockets) return aot(entry, { target: \"bun\", strip: false });\n return {\n name: \"brick-elysia-aot\",\n async setup(build) {\n await aot(entry, { target: \"bun\", strip: true }).setup({\n ...build,\n onLoad(options, callback) {\n return build.onLoad(options, async (args) => {\n const result = await callback(args);\n if (\n !result ||\n !(\"contents\" in result) ||\n typeof result.contents !== \"string\"\n )\n return result;\n let contents = result.contents;\n if (\n /[/\\\\]elysia[/\\\\]dist[/\\\\]ws[/\\\\]route\\.m?js$/.test(args.path) &&\n contents.includes(\n \"[elysia-aot] WebSocket route builder was stripped\",\n )\n ) {\n for (const name of [\"resolveWSOptions\", \"accumulateWSOptions\"]) {\n if (!contents.includes(`export function ${name}`))\n contents += `\\nexport function ${name}() { throw new Error(\"WebSocket support was stripped\"); }\\n`;\n }\n }\n return contents === result.contents\n ? result\n : { ...result, contents };\n });\n },\n });\n },\n };\n}\n","import { mkdtemp, mkdir, rename, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { compileBrickApplication } from \"@brickkit/core\";\nimport { emitCompiledApplication } from \"./compiler\";\nimport { brickAot } from \"./compiler/aot\";\nimport { loadBrickApp } from \"./app-entry\";\nimport { buildAppWorkflows, workflowTransformPlugin } from \"./workflows\";\nimport {\n themeCss,\n writeDashboardExtension,\n type DashboardExtensionOptions,\n} from \"./dashboard-extension\";\n\nexport interface BuildApplicationOptions {\n /** A module whose default export is a BrickApp, without starting a server. */\n entry: string;\n outdir?: string;\n port?: number;\n /** Precompile Elysia's HTTP handlers at build time (default true). */\n aot?: boolean;\n /**\n * The dashboard's extension, built into `<outdir>/dashboard` with those of\n * the app's plugins for the production dashboard to serve; its theme is\n * checked here too.\n */\n dashboard?: DashboardExtensionOptions;\n}\n\n/** Bundle an exported BrickApp with generated handlers and its original configuration. */\nexport async function buildApplication(options: BuildApplicationOptions) {\n const entry = resolve(options.entry);\n if (!(await Bun.file(entry).exists()))\n throw new Error(`Brick compiler: entry not found: ${entry}`);\n const outdir = resolve(options.outdir ?? \"dist/brick\");\n if (\n entry === join(outdir, \"server.js\") ||\n entry === join(outdir, \"routes.js\")\n )\n throw new Error(\n \"Brick compiler: output would overwrite the application entry\",\n );\n const port = options.port ?? 4000;\n if (!Number.isInteger(port) || port < 1 || port > 65535)\n throw new Error(\n \"Brick compiler: port must be an integer between 1 and 65535\",\n );\n themeCss(options.dashboard?.theme);\n const extension = options.dashboard?.extension\n ? resolve(options.dashboard.extension)\n : undefined;\n if (extension && !(await Bun.file(extension).exists()))\n throw new Error(\n `Brick compiler: dashboard extension not found: ${extension}`,\n );\n const app = await loadBrickApp(entry);\n // The bundle stays in the project, where the server finds it from the working\n // directory, as `brick start` does.\n await buildAppWorkflows(app);\n const services = [...app.definition.services];\n const compilation = compileBrickApplication({\n services,\n prefix: app.definition.prefix,\n });\n await mkdir(dirname(outdir), { recursive: true });\n const staging = await mkdtemp(join(dirname(outdir), \".brick-build-\"));\n try {\n await Bun.write(\n join(staging, \"routes.js\"),\n emitCompiledApplication(compilation.ir),\n );\n const source = `import { loadCompiledBrickApp } from \"@brickkit/core\";\nimport { ir, bind } from \"./routes.js\";\nexport const app = await loadCompiledBrickApp(() => import(${JSON.stringify(entry)}), ir, bind);\nif (import.meta.main) {\n const port = Number(process.env.PORT ?? ${port});\n if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error(\"Invalid PORT: must be between 1 and 65535\");\n await app.start?.();\n app.listen(port);\n app.events?.start();\n console.log(\"Brick compiled server listening on http://localhost:\" + app.server.port);\n let stopping = false;\n const stop = async (signal: string) => {\n // A second signal exits at once, for a delivery that never finishes.\n if (stopping) process.exit(signal === \"SIGINT\" ? 130 : 143);\n stopping = true;\n await app.events?.stop();\n await app.stop();\n process.exit(0);\n };\n // on, not once: the workflow runtime bundles signal-exit, which re-raises a signal when no listener is left.\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n}\n`;\n await Bun.write(join(staging, \"entry.ts\"), source);\n const workflows = app.events?.workflows\n ? await workflowTransformPlugin(app.events.workflows.root)\n : undefined;\n const result = await Bun.build({\n entrypoints: [join(staging, \"entry.ts\")],\n target: \"bun\",\n format: \"esm\",\n outdir: staging,\n naming: \"server.js\",\n sourcemap: \"external\",\n // AOT first: the workflow plugin loads every project file it sees, so after\n // it the AOT plugin would never get to transform the entry.\n plugins: [\n ...(options.aot === false\n ? []\n : [\n brickAot(\n join(staging, \"entry.ts\"),\n app.definition.sockets.length > 0,\n ),\n ]),\n ...(workflows ? [workflows] : []),\n ],\n });\n if (!result.success)\n throw new AggregateError(result.logs, \"Brick compiler: bundling failed\");\n await Bun.write(\n join(staging, \"brick-ir.json\"),\n JSON.stringify(compilation.ir, null, 2) + \"\\n\",\n );\n const dashboard = (await writeDashboardExtension(\n extension,\n app.definition.plugins ?? [],\n join(staging, \"dashboard\"),\n ))\n ? join(outdir, \"dashboard\")\n : undefined;\n await mkdir(outdir, { recursive: true });\n for (const name of [\n \"routes.js\",\n \"brick-ir.json\",\n \"server.js.map\",\n \"server.js\",\n ])\n await rename(join(staging, name), join(outdir, name));\n if (dashboard) {\n await rm(dashboard, { recursive: true, force: true });\n await rename(join(staging, \"dashboard\"), dashboard);\n }\n return {\n outdir,\n entry: join(outdir, \"server.js\"),\n ir: compilation.ir,\n /** The built dashboard extension's folder, when there is one. */\n dashboard,\n };\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n}\n","import { existsSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nimport type {\n DashboardExtensionOptions,\n DashboardTheme,\n} from \"./dashboard-extension\";\n\nexport type { DashboardExtensionOptions, DashboardTheme };\n\nexport type LintSeverity = \"error\" | \"warn\" | \"off\";\nexport type LintPreset = \"recommended\" | \"layout\" | \"strict\" | \"plugin\";\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 */\nexport interface BrickConfig {\n /** App entry whose default export is the BrickApp (default `src/app.ts`). */\n entry?: string;\n /** Folder scanned for definition files (default `src/services`). */\n services?: string;\n /** Folder for `services.gen.ts` and the default contract (default `_brick`). */\n generated?: string;\n client?: { output?: string };\n openapi?: { output?: string };\n dev?: {\n port?: number;\n /** Frontend command, started once the client contract exists. Needs `client.output`. */\n frontend?: string;\n dashboard?: { port?: number; historyDays?: number } | false;\n };\n build?: { outdir?: string; aot?: boolean; requestLogging?: boolean };\n dashboard?: DashboardExtensionOptions;\n lint?: {\n presets?: LintPreset[];\n rules?: Record<string, LintSeverity>;\n ignore?: string[];\n };\n}\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\nexport const CONFIG_FILE = \"brick.config.ts\";\n\n/** A missing or invalid config file; the message names the file and key. */\nexport class ConfigError extends Error {}\n\nexport interface LoadedConfig {\n /** Absolute path of the config file. */\n file: string;\n /** Folder the config's paths are relative to. */\n root: string;\n config: BrickConfig;\n /** Absolute paths with defaults applied. */\n entry: string;\n services: string;\n generated: 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 * 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 file = explicit ? resolve(cwd, explicit) : findConfigFile(cwd);\n if (!file) return undefined;\n if (!existsSync(file))\n throw new ConfigError(`Brick: config file not found: ${file}`);\n const module = await import(pathToFileURL(file).href);\n const config = module.default as BrickConfig;\n validateConfig(config, file.endsWith(CONFIG_FILE) ? CONFIG_FILE : file);\n const root = dirname(file);\n return {\n file,\n root,\n config,\n entry: resolve(root, config.entry ?? \"src/app.ts\"),\n services: resolve(root, config.services ?? \"src/services\"),\n generated: resolve(root, config.generated ?? \"_brick\"),\n };\n}\n\ntype Check = (value: unknown) => boolean;\ntype Shape = { [key: string]: [Check, string] | Shape };\n\nconst isString: Check = (v) => typeof v === \"string\" && v.length > 0;\nconst isBoolean: Check = (v) => typeof v === \"boolean\";\nconst isPort: Check = (v) =>\n Number.isInteger(v) && (v as number) >= 1 && (v as number) <= 65535;\nconst isRecordOf =\n (check: Check): Check =>\n (v) =>\n isPlainObject(v) && Object.values(v).every(check);\nconst isArrayOf =\n (check: Check): Check =>\n (v) =>\n Array.isArray(v) && v.every(check);\nconst PRESETS = [\"recommended\", \"layout\", \"strict\", \"plugin\"];\nconst SEVERITIES = [\"error\", \"warn\", \"off\"];\n\nconst SCHEMA: Shape = {\n entry: [isString, \"must be a file path\"],\n services: [isString, \"must be a folder path\"],\n generated: [isString, \"must be a folder path\"],\n client: { output: [isString, \"must be a file path\"] },\n openapi: { output: [isString, \"must be a file path\"] },\n dev: {\n port: [isPort, \"must be a port number\"],\n frontend: [isString, \"must be a command\"],\n // `false`, or the shape below, checked in validateConfig.\n dashboard: {\n port: [isPort, \"must be a port number\"],\n historyDays: [\n (v) => Number.isSafeInteger(v) && (v as number) >= 0,\n \"must be a whole number of days, or 0 for none\",\n ],\n },\n },\n build: {\n outdir: [isString, \"must be a folder path\"],\n aot: [isBoolean, \"must be true or false\"],\n requestLogging: [isBoolean, \"must be true or false\"],\n },\n dashboard: {\n extension: [isString, \"must be a file path\"],\n theme: {\n light: [isRecordOf(isString), \"must map token names to values\"],\n dark: [isRecordOf(isString), \"must map token names to values\"],\n radius: [isString, \"must be a CSS length\"],\n fonts: {\n sans: [isString, \"must be a font-family value\"],\n mono: [isString, \"must be a font-family value\"],\n },\n },\n },\n lint: {\n presets: [\n isArrayOf((v) => PRESETS.includes(v as string)),\n `must list presets from ${PRESETS.join(\", \")}`,\n ],\n rules: [\n isRecordOf((v) => SEVERITIES.includes(v as string)),\n 'must map rule names to \"error\", \"warn\" or \"off\"',\n ],\n ignore: [isArrayOf(isString), \"must be a list of glob patterns\"],\n },\n};\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\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 if (!isPlainObject(config)) fail(\"must default-export defineConfig({ ... })\");\n const walk = (value: Record<string, unknown>, shape: Shape, path: string) => {\n for (const [key, child] of Object.entries(value)) {\n const keyPath = path + key;\n const rule = shape[key];\n if (!rule) fail(`unknown key ${keyPath}`);\n if (child === undefined) continue;\n if (keyPath === \"dev.dashboard\" && child === false) continue;\n if (Array.isArray(rule)) {\n if (!rule[0](child)) fail(`${keyPath} ${rule[1]}`);\n } else if (!isPlainObject(child)) {\n fail(\n `${keyPath} must be an object${keyPath === \"dev.dashboard\" ? \" or false\" : \"\"}`,\n );\n } else walk(child, rule as Shape, `${keyPath}.`);\n }\n };\n walk(config as Record<string, unknown>, SCHEMA, \"\");\n const typed = config as BrickConfig;\n if (typed.dev?.frontend && !typed.client?.output)\n fail(\"dev.frontend requires client.output\");\n}\n"],"mappings":";;;;;;;;;;;;AAIA,SAAgB,SAAS,OAAe,YAAgC;CAGtE,IAAI,YAAY,OAAO,IAAI,OAAO;EAAE,QAAQ;EAAO,OAAO;CAAM,CAAC;CACjE,OAAO;EACL,MAAM;EACN,MAAM,MAAM,OAAO;GACjB,MAAM,IAAI,OAAO;IAAE,QAAQ;IAAO,OAAO;GAAK,CAAC,CAAC,CAAC,MAAM;IACrD,GAAG;IACH,OAAO,SAAS,UAAU;KACxB,OAAO,MAAM,OAAO,SAAS,OAAO,SAAS;MAC3C,MAAM,SAAS,MAAM,SAAS,IAAI;MAClC,IACE,CAAC,UACD,EAAE,cAAc,WAChB,OAAO,OAAO,aAAa,UAE3B,OAAO;MACT,IAAI,WAAW,OAAO;MACtB,IACE,+CAA+C,KAAK,KAAK,IAAI,KAC7D,SAAS,SACP,mDACF,GAEK;YAAA,MAAM,QAAQ,CAAC,oBAAoB,qBAAqB,GAC3D,IAAI,CAAC,SAAS,SAAS,mBAAmB,MAAM,GAC9C,YAAY,qBAAqB,KAAK;MAAA;MAG5C,OAAO,aAAa,OAAO,WACvB,SACA;OAAE,GAAG;OAAQ;MAAS;KAC5B,CAAC;IACH;GACF,CAAC;EACH;CACF;AACF;;;ACbA,eAAsB,iBAAiB,SAAkC;CACvE,MAAM,QAAQ,QAAQ,QAAQ,KAAK;CACnC,IAAI,CAAE,MAAM,IAAI,KAAK,KAAK,CAAC,CAAC,OAAO,GACjC,MAA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