@brickkit/cli 0.12.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.
- package/dashboard-dist/{api-reference-B-bZRtNV.js → api-reference-mT9VNcPb.js} +69 -69
- package/dashboard-dist/app.js +12 -13
- package/dashboard-dist/{client-BJJtVSVr.js → client-CwATkLJa.js} +1 -1
- package/dashboard-dist/{core-Z7NJFk0K.js → core-BEUWp6B5.js} +1 -1
- package/dashboard-dist/docs-BRrtyxDB.js +4 -0
- package/dashboard-dist/kit.js +1 -1
- package/dashboard-dist/popover-Bj9x-88h.js +1 -0
- package/dist/bin.js +154 -217
- package/dist/bin.js.map +1 -1
- package/dist/build.js +463 -0
- package/dist/build.js.map +1 -0
- package/dist/client-contract-file.js +356 -1
- package/dist/client-contract-file.js.map +1 -0
- package/dist/compiler.d.ts +12 -2
- package/dist/compiler2.js +12 -5
- package/dist/compiler2.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +1 -250
- package/dist/config2.d.ts +122 -0
- package/dist/config2.js +207 -0
- package/dist/config2.js.map +1 -0
- package/dist/dashboard-extension.d.ts +3 -0
- package/dist/{dev-telemetry-store.js → dashboard-host.js} +1533 -1574
- package/dist/dashboard-host.js.map +1 -0
- package/dist/dashboard-protocol.js +189 -0
- package/dist/dashboard-protocol.js.map +1 -0
- package/dist/dashboard.d.ts +4 -1
- package/dist/definitions.js +33 -0
- package/dist/definitions.js.map +1 -0
- package/dist/dev-application.js +34 -0
- package/dist/dev-application.js.map +1 -0
- package/dist/dev-protocol.js +21 -0
- package/dist/dev-protocol.js.map +1 -0
- package/dist/dev-reporter.js +2 -1
- package/dist/dev-reporter.js.map +1 -1
- package/dist/dev-telemetry.js +5 -20
- package/dist/dev-telemetry.js.map +1 -1
- package/dist/dev-worker.js +79 -19
- package/dist/dev-worker.js.map +1 -1
- package/dist/index.d.ts +15 -74
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -0
- package/dist/lint/oxlint.js +5 -3
- package/dist/lint/oxlint.js.map +1 -1
- package/dist/own-module.js +7 -0
- package/dist/own-module.js.map +1 -0
- package/dist/plugin.d.ts +6 -5
- package/dist/plugin.js +5 -39
- package/dist/plugin.js.map +1 -1
- package/dist/production-dashboard.d.ts +2 -0
- package/dist/production-dashboard.js +51 -0
- package/dist/production-dashboard.js.map +1 -0
- package/dist/production-dashboard2.d.ts +34 -0
- package/dist/{presets.js → project.js} +104 -106
- package/dist/project.js.map +1 -0
- package/dist/serve.d.ts +24 -0
- package/dist/serve.js +1 -0
- package/dist/serve2.js +49 -0
- package/dist/serve2.js.map +1 -0
- package/dist/vite.js +26 -47
- package/dist/vite.js.map +1 -1
- package/dist/workflows.d.ts +2 -2
- package/dist/workflows2.js +59 -37
- package/dist/workflows2.js.map +1 -1
- package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
- package/inspector-dist/client/assets/{highlighted-body-B3W2YXNL-DYVdwGy2.js → highlighted-body-B3W2YXNL-CfRnuITN.js} +1 -1
- package/inspector-dist/client/assets/{home-CyjkvtII.js → home-hwPlkNhv.js} +1529 -378
- package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
- package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
- package/inspector-dist/client/assets/{root-DX9wtogx.js → root-SLeEf-sT.js} +17 -29
- package/inspector-dist/client/assets/{run-detail-C69EJGql.js → run-detail-DYbVkIFH.js} +398 -76
- package/inspector-dist/client/assets/{tabs-B6B88IjT.js → tabs-CaJisoyb.js} +189 -2130
- package/inspector-dist/client/assets/{zstd-browser-decoder-ByUgcY9H.js → zstd-browser-decoder-D94wmfAU.js} +1 -1
- package/inspector-dist/server/assets/{app-WoDoT62X.js → app-DGlfWVUI.js} +69783 -70608
- package/inspector-dist/server/assets/{chunk-RLXIAIE6-CbvDIAEa.js → chunk-RLXIAIE6-F0SJZlei.js} +4 -6
- package/inspector-dist/server/assets/{dist-qR-969AD.js → dist-BCbwm6jl.js} +2 -4
- package/inspector-dist/server/assets/{dist-CQnQcIJg.js → dist-CG2aVufI.js} +0 -2
- package/inspector-dist/server/assets/{dist-BRxZSWUN.js → dist-Ce0I2PUv.js} +2 -5
- package/inspector-dist/server/assets/{dist-DqRd9pyS.js → dist-DY0UlahA.js} +0 -2
- package/inspector-dist/server/assets/{encryption-_PuklZNX.js → encryption-DdQgC8Rk.js} +2 -4
- package/inspector-dist/server/assets/{event-metadata-BVakQJ_y.js → event-metadata-n7E4zEmT.js} +0 -2
- package/inspector-dist/server/assets/{functions-CImcpqNl.js → functions-CNVQtbgg.js} +2 -4
- package/inspector-dist/server/assets/{global-singleton-CPirHxFh.js → global-singleton-D8sIN5du.js} +0 -2
- package/inspector-dist/server/assets/{highlighted-body-B3W2YXNL-fPMB_t7F.js → highlighted-body-B3W2YXNL-CWRzMxYD.js} +2 -4
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
- package/inspector-dist/server/assets/{parse-D9Vvgzt9.js → parse-Begau9cA.js} +0 -2
- package/inspector-dist/server/assets/{rolldown-runtime-CLg409Sh.js → rolldown-runtime-C1I3wEg2.js} +1 -2
- package/inspector-dist/server/assets/{serialization-format-DDtsVTU1.js → serialization-format-BbuGfHog.js} +6 -8
- package/inspector-dist/server/assets/{token-BW4GdQZh.js → token-BgMmJNP5.js} +2 -4
- package/inspector-dist/server/assets/{token-D6FXdkJT.js → token-BrUX0bxz.js} +2 -4
- package/inspector-dist/server/assets/{token-util-BoNmi-wE.js → token-util-DZN32qmT.js} +1 -3
- package/inspector-dist/server/assets/{wrapper-wiqsGXcE.js → wrapper-CIC3w0oC.js} +1 -3
- package/inspector-dist/server/assets/{ws-transport-DV7oG4mL.js → ws-transport-CxTYB11n.js} +24094 -24096
- package/inspector-dist/server/assets/{zstd-browser-decoder-Cswf0KO6.js → zstd-browser-decoder-D7bCXbGg.js} +2 -4
- package/inspector-dist/server/index.js +1 -3
- package/package.json +12 -2
- package/dashboard-dist/docs-Dpfc0wJb.js +0 -4
- package/dashboard-dist/popover-BzejBolB.js +0 -1
- package/dist/app-entry.js +0 -1
- package/dist/app-entry2.js +0 -18
- package/dist/app-entry2.js.map +0 -1
- package/dist/client-contract-file2.js +0 -33
- package/dist/client-contract-file2.js.map +0 -1
- package/dist/client-contract.js +0 -1
- package/dist/client-contract2.js +0 -296
- package/dist/client-contract2.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/dev-telemetry-store.js.map +0 -1
- package/dist/emit.d.ts +0 -5
- package/dist/presets.js.map +0 -1
- package/dist/runner.js +0 -519
- package/dist/runner.js.map +0 -1
- package/inspector-dist/client/assets/app-CCzpuUz_.css +0 -2
- package/inspector-dist/client/assets/manifest-ba30b52d.js +0 -1
- package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +0 -1
- package/inspector-dist/client/assets/root-8BMab1lL.css +0 -2
- package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +0 -30
- package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +0 -3
|
@@ -1 +1,356 @@
|
|
|
1
|
-
|
|
1
|
+
import { n as ConfigError } from "./config2.js";
|
|
2
|
+
import { r as registerWorkflowTransform } from "./workflows2.js";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { actionOwners, getActionRoute, getPluginActionRoute, requireBrickApp, serializeSocketSchema } from "@brickkit/core";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
8
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
+
// src/app-entry.ts
|
|
10
|
+
/**
|
|
11
|
+
* Import an app entry and return its default export. `run`: the app will run
|
|
12
|
+
* in this process, so workflow files are transformed as they load.
|
|
13
|
+
*
|
|
14
|
+
* @throws When the file does not exist.
|
|
15
|
+
*/
|
|
16
|
+
async function importEntry(entry, options = {}) {
|
|
17
|
+
const file = resolve(entry);
|
|
18
|
+
if (!existsSync(file)) throw new ConfigError(`[Brick-TS] Error: Entry file not found: ${file}`);
|
|
19
|
+
if (options.run) await registerWorkflowTransform();
|
|
20
|
+
return (await import(pathToFileURL(file).href)).default;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Import an app entry to inspect it: to build it, or to read its routes. The app
|
|
24
|
+
* is not run, so what creating it opened is released here: a workflow world
|
|
25
|
+
* holds Redis connections that would keep the command from exiting.
|
|
26
|
+
*/
|
|
27
|
+
async function loadBrickApp(entry) {
|
|
28
|
+
const app = requireBrickApp(await importEntry(entry));
|
|
29
|
+
await app.events?.stop();
|
|
30
|
+
return app;
|
|
31
|
+
}
|
|
32
|
+
// src/client-contract.ts
|
|
33
|
+
/** Generate browser metadata and transport types from the app's selected services. */
|
|
34
|
+
function generateClientContract(app) {
|
|
35
|
+
const { services, prefix } = app.definition;
|
|
36
|
+
const contract = Object.create(null);
|
|
37
|
+
const types = Object.create(null);
|
|
38
|
+
const schemas = new SchemaTypes();
|
|
39
|
+
for (const service of services) {
|
|
40
|
+
addServiceActions(service, prefix, contract, types, schemas);
|
|
41
|
+
for (const socket of service.listSockets()) {
|
|
42
|
+
const route = app.definition.sockets.find((route) => route.service === service.name && route.name === socket.schema.name);
|
|
43
|
+
if (!route) throw new Error(`Brick client: missing socket route '${service.name}.${socket.schema.name}'`);
|
|
44
|
+
try {
|
|
45
|
+
const metadata = {
|
|
46
|
+
kind: "socket",
|
|
47
|
+
name: socket.schema.name,
|
|
48
|
+
serviceName: service.name,
|
|
49
|
+
config: { path: route.path },
|
|
50
|
+
output: Object.fromEntries(Object.entries(socket.output).map(([key, schema]) => [key, serializeSocketSchema(schema)]))
|
|
51
|
+
};
|
|
52
|
+
const payloads = (map) => `{ ${Object.entries(map).map(([key, schema]) => `${JSON.stringify(key)}: ${schemas.generate(schema)}`).join("; ")} }`;
|
|
53
|
+
insertAction(contract[service.name], types[service.name], metadata, `BrickClientSocket<${payloads(socket.input)}, ${payloads(socket.output)}, ${errorsType(socket.errors)}>`);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(`Brick client: cannot generate socket '${service.name}.${socket.schema.name}': ${String(error)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return `// Generated by Brick. Do not edit.
|
|
60
|
+
import type { BrickClientAction${app.definition.sockets.length ? ", BrickClientSocket" : ""} } from "@brickkit/core/client";
|
|
61
|
+
|
|
62
|
+
${schemas.renderContract(namespaceType(types))}
|
|
63
|
+
|
|
64
|
+
export const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});
|
|
65
|
+
|
|
66
|
+
// Types useService(service) on the server from this contract.
|
|
67
|
+
declare module "@brickkit/core/client" {
|
|
68
|
+
interface BrickServices extends AppContract {}
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
function addServiceActions(service, prefix, contract, types, schemas) {
|
|
73
|
+
const namespace = contract[service.name] ?? Object.create(null);
|
|
74
|
+
const namespaceTypes = types[service.name] ?? Object.create(null);
|
|
75
|
+
contract[service.name] = namespace;
|
|
76
|
+
types[service.name] = namespaceTypes;
|
|
77
|
+
for (const action of service.listActions()) {
|
|
78
|
+
const route = getActionRoute(action, prefix);
|
|
79
|
+
if (route === false) continue;
|
|
80
|
+
const pluginRoute = getPluginActionRoute(action, prefix) || void 0;
|
|
81
|
+
const { input, output, errors } = action.config;
|
|
82
|
+
let inputType;
|
|
83
|
+
let outputType;
|
|
84
|
+
try {
|
|
85
|
+
inputType = input ? schemas.generate(input) : "unknown";
|
|
86
|
+
outputType = output ? schemas.generate(output) : "unknown";
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw new Error(`Brick client: cannot generate '${service.name}.${action.name}': ${error.message}`);
|
|
89
|
+
}
|
|
90
|
+
const metadata = {
|
|
91
|
+
kind: "action",
|
|
92
|
+
name: action.name,
|
|
93
|
+
serviceName: service.name,
|
|
94
|
+
...actionOwners(action),
|
|
95
|
+
config: {
|
|
96
|
+
path: route.path,
|
|
97
|
+
method: route.method
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
insertAction(pluginRoute?.clientPath ? contract : namespace, pluginRoute?.clientPath ? types : namespaceTypes, metadata, actionType(inputType, outputType, errors), pluginRoute?.clientPath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function insertAction(node, typeNode, metadata, type, clientPath) {
|
|
104
|
+
const segments = clientPath ?? metadata.name.split(".");
|
|
105
|
+
for (const segment of segments.slice(0, -1)) {
|
|
106
|
+
if (Object.hasOwn(typeNode, segment) && typeof typeNode[segment] === "string") throw new Error(`Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`);
|
|
107
|
+
node[segment] ??= Object.create(null);
|
|
108
|
+
typeNode[segment] ??= Object.create(null);
|
|
109
|
+
node = node[segment];
|
|
110
|
+
typeNode = typeNode[segment];
|
|
111
|
+
}
|
|
112
|
+
const leaf = segments.at(-1);
|
|
113
|
+
if (Object.hasOwn(node, leaf)) throw new Error(`Brick client: action namespace collision at '${metadata.serviceName}.${metadata.name}'`);
|
|
114
|
+
node[leaf] = metadata;
|
|
115
|
+
typeNode[leaf] = type;
|
|
116
|
+
}
|
|
117
|
+
function actionType(input, output, errors) {
|
|
118
|
+
return `BrickClientAction<${input}, ${output}, ${errorsType(errors)}>`;
|
|
119
|
+
}
|
|
120
|
+
function errorsType(errors) {
|
|
121
|
+
const codes = Object.keys(errors ?? {});
|
|
122
|
+
return codes.length ? `Record<${codes.map((code) => JSON.stringify(code)).join(" | ")}, { message: string; status?: number }>` : "{}";
|
|
123
|
+
}
|
|
124
|
+
function namespaceType(node) {
|
|
125
|
+
return `{\n${Object.entries(node).map(([key, value]) => ` ${JSON.stringify(key)}: ${typeof value === "string" ? value : namespaceType(value)};`).join("\n")}\n}`;
|
|
126
|
+
}
|
|
127
|
+
var SchemaTypes = class {
|
|
128
|
+
aliases = /* @__PURE__ */ new Map();
|
|
129
|
+
names = /* @__PURE__ */ new Set([
|
|
130
|
+
"AppContract",
|
|
131
|
+
"BrickClientAction",
|
|
132
|
+
"BrickClientSocket",
|
|
133
|
+
"contract"
|
|
134
|
+
]);
|
|
135
|
+
fragments = [];
|
|
136
|
+
fragmentIds = /* @__PURE__ */ new Map();
|
|
137
|
+
fragment(body) {
|
|
138
|
+
let id = this.fragmentIds.get(body);
|
|
139
|
+
if (id === void 0) {
|
|
140
|
+
id = this.fragments.length;
|
|
141
|
+
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);
|
|
142
|
+
const shape = body.replace(/\0(\d+)\0/g, (_, child) => this.fragments[Number(child)].hash);
|
|
143
|
+
const hash = createHash("sha256").update(shape).digest("hex");
|
|
144
|
+
this.fragments.push({
|
|
145
|
+
body,
|
|
146
|
+
size,
|
|
147
|
+
hash
|
|
148
|
+
});
|
|
149
|
+
this.fragmentIds.set(body, id);
|
|
150
|
+
}
|
|
151
|
+
return `\0${id}\0`;
|
|
152
|
+
}
|
|
153
|
+
renderContract(contract) {
|
|
154
|
+
const uses = this.fragments.map(() => 0);
|
|
155
|
+
const count = (body, multiplier) => {
|
|
156
|
+
for (const match of body.matchAll(/\0(\d+)\0/g)) uses[Number(match[1])] += multiplier;
|
|
157
|
+
};
|
|
158
|
+
count(contract, 1);
|
|
159
|
+
for (const body of this.aliases.values()) count(body, 1);
|
|
160
|
+
const worthSharing = (id, size, name) => uses[id] > 1 && (uses[id] - 1) * size > uses[id] * name.length + `export type ${name} = ;\n\n`.length;
|
|
161
|
+
const shared = /* @__PURE__ */ new Map();
|
|
162
|
+
for (let id = this.fragments.length - 1; id >= 0; id--) {
|
|
163
|
+
const { body, size, hash } = this.fragments[id];
|
|
164
|
+
const nameBase = `BrickSchema_${hash.slice(0, 12)}`;
|
|
165
|
+
let name = nameBase;
|
|
166
|
+
let suffix = 2;
|
|
167
|
+
while (this.names.has(name)) name = `${nameBase}_${suffix++}`;
|
|
168
|
+
if (worthSharing(id, size, name)) {
|
|
169
|
+
this.names.add(name);
|
|
170
|
+
shared.set(id, name);
|
|
171
|
+
}
|
|
172
|
+
count(body, shared.has(id) ? 1 : uses[id]);
|
|
173
|
+
}
|
|
174
|
+
const rendered = [];
|
|
175
|
+
const declarations = [];
|
|
176
|
+
for (let id = 0; id < this.fragments.length; id++) {
|
|
177
|
+
const body = this.fragments[id].body.replace(/\0(\d+)\0/g, (_, child) => rendered[Number(child)]);
|
|
178
|
+
const name = shared.get(id);
|
|
179
|
+
if (name && worthSharing(id, body.length, name)) {
|
|
180
|
+
declarations.push(`export type ${name} = ${body};\n\n`);
|
|
181
|
+
rendered.push(name);
|
|
182
|
+
} else rendered.push(body);
|
|
183
|
+
}
|
|
184
|
+
const render = (body) => body.replace(/\0(\d+)\0/g, (_, id) => rendered[Number(id)]);
|
|
185
|
+
return declarations.join("") + [...this.aliases].map(([name, type]) => `export type ${name} = ${render(type)};\n\n`).join("") + `export type AppContract = ${render(contract)};`;
|
|
186
|
+
}
|
|
187
|
+
generate(root) {
|
|
188
|
+
const ids = /* @__PURE__ */ new Map();
|
|
189
|
+
const references = [];
|
|
190
|
+
const resources = /* @__PURE__ */ new Map();
|
|
191
|
+
const active = /* @__PURE__ */ new Set();
|
|
192
|
+
const visit = (schema, base) => {
|
|
193
|
+
if (!schema || typeof schema !== "object" || active.has(schema)) return;
|
|
194
|
+
const currentBase = typeof schema.$id === "string" && schema.$id ? schema : base;
|
|
195
|
+
if (!resources.has(schema)) resources.set(schema, currentBase);
|
|
196
|
+
if (typeof schema.$ref === "string") references.push({
|
|
197
|
+
ref: schema.$ref,
|
|
198
|
+
base: currentBase
|
|
199
|
+
});
|
|
200
|
+
active.add(schema);
|
|
201
|
+
try {
|
|
202
|
+
if (typeof schema.$id === "string" && schema.$id) ids.set(schema.$id, schema);
|
|
203
|
+
for (const key of [
|
|
204
|
+
"properties",
|
|
205
|
+
"patternProperties",
|
|
206
|
+
"$defs",
|
|
207
|
+
"definitions"
|
|
208
|
+
]) for (const child of Object.values(schema[key] ?? {})) visit(child, currentBase);
|
|
209
|
+
for (const key of [
|
|
210
|
+
"anyOf",
|
|
211
|
+
"oneOf",
|
|
212
|
+
"allOf",
|
|
213
|
+
"prefixItems"
|
|
214
|
+
]) for (const child of schema[key] ?? []) visit(child, currentBase);
|
|
215
|
+
for (const key of [
|
|
216
|
+
"items",
|
|
217
|
+
"additionalProperties",
|
|
218
|
+
"not"
|
|
219
|
+
]) if (Array.isArray(schema[key])) schema[key].forEach((child) => visit(child, currentBase));
|
|
220
|
+
else visit(schema[key], currentBase);
|
|
221
|
+
} finally {
|
|
222
|
+
active.delete(schema);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
visit(root, root);
|
|
226
|
+
const resolve = (reference, base) => {
|
|
227
|
+
const hashIndex = reference.indexOf("#");
|
|
228
|
+
const id = hashIndex === -1 ? reference : reference.slice(0, hashIndex);
|
|
229
|
+
const fragment = hashIndex === -1 ? void 0 : reference.slice(hashIndex + 1);
|
|
230
|
+
let target = id ? ids.get(id) : base;
|
|
231
|
+
if (fragment) {
|
|
232
|
+
if (!fragment.startsWith("/")) return void 0;
|
|
233
|
+
try {
|
|
234
|
+
for (const part of decodeURIComponent(fragment).slice(1).split("/")) {
|
|
235
|
+
const key = part.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
236
|
+
if (!target || !Object.hasOwn(target, key)) return void 0;
|
|
237
|
+
target = target[key];
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return typeof target === "boolean" || target && typeof target === "object" ? target : void 0;
|
|
244
|
+
};
|
|
245
|
+
const targets = new Set(references.map(({ ref, base }) => resolve(ref, base)).filter((value) => value !== void 0));
|
|
246
|
+
const names = /* @__PURE__ */ new Map();
|
|
247
|
+
const emit = (schema, inline = false, base = root) => {
|
|
248
|
+
const body = emitInline(schema, inline, base);
|
|
249
|
+
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);
|
|
250
|
+
return body;
|
|
251
|
+
};
|
|
252
|
+
const emitInline = (schema, inline, base) => {
|
|
253
|
+
if (schema === void 0 || schema === true) return "unknown";
|
|
254
|
+
if (schema === false || schema.not && !Object.keys(schema.not).length) return "never";
|
|
255
|
+
const currentBase = schema && typeof schema === "object" && typeof schema.$id === "string" && schema.$id ? schema : base;
|
|
256
|
+
if (!inline && targets.has(schema)) {
|
|
257
|
+
const existing = names.get(schema);
|
|
258
|
+
if (existing) return existing;
|
|
259
|
+
const hint = schema.title ?? schema.$id ?? "Schema";
|
|
260
|
+
let nameBase = String(hint).replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
261
|
+
if (!/^[a-zA-Z_$]/.test(nameBase)) nameBase = `Schema_${nameBase}`;
|
|
262
|
+
nameBase = `Brick${nameBase}`;
|
|
263
|
+
let name = nameBase;
|
|
264
|
+
let suffix = 2;
|
|
265
|
+
while (this.names.has(name)) {
|
|
266
|
+
name = `${nameBase}_${suffix}`;
|
|
267
|
+
suffix += 1;
|
|
268
|
+
}
|
|
269
|
+
this.names.add(name);
|
|
270
|
+
names.set(schema, name);
|
|
271
|
+
this.aliases.set(name, emit(schema, true, currentBase));
|
|
272
|
+
return name;
|
|
273
|
+
}
|
|
274
|
+
if (schema.$ref) {
|
|
275
|
+
const target = resolve(schema.$ref, currentBase);
|
|
276
|
+
if (target === void 0) throw new Error(`unresolved schema reference '${schema.$ref}'`);
|
|
277
|
+
const targetBase = target && typeof target === "object" ? resources.get(target) ?? root : currentBase;
|
|
278
|
+
return emit(target, false, targetBase);
|
|
279
|
+
}
|
|
280
|
+
if (Object.hasOwn(schema, "const")) return JSON.stringify(schema.const);
|
|
281
|
+
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
282
|
+
if (schema.anyOf || schema.oneOf) return `(${(schema.anyOf ?? schema.oneOf).map((child) => emit(child, false, currentBase)).join(" | ")})`;
|
|
283
|
+
if (schema.allOf) return `(${schema.allOf.map((child) => emit(child, false, currentBase)).join(" & ")})`;
|
|
284
|
+
switch (schema.type) {
|
|
285
|
+
case "string": return "string";
|
|
286
|
+
case "number":
|
|
287
|
+
case "integer": return "number";
|
|
288
|
+
case "boolean": return "boolean";
|
|
289
|
+
case "null": return "null";
|
|
290
|
+
case "undefined":
|
|
291
|
+
case "void": return "undefined";
|
|
292
|
+
case "array":
|
|
293
|
+
if (Array.isArray(schema.items)) return `[${schema.items.map((child) => emit(child, false, currentBase)).join(", ")}]`;
|
|
294
|
+
return `Array<${emit(schema.items, false, currentBase)}>`;
|
|
295
|
+
case "object": {
|
|
296
|
+
const entries = Object.entries(schema.properties ?? {});
|
|
297
|
+
const properties = entries.map(([key, value]) => `${JSON.stringify(key)}${schema.required?.includes(key) ? "" : "?"}: ${emit(value, false, currentBase)};`);
|
|
298
|
+
const indexParts = Object.values(schema.patternProperties ?? {}).map((child) => emit(child, false, currentBase));
|
|
299
|
+
if (schema.additionalProperties) indexParts.push(emit(schema.additionalProperties, false, currentBase));
|
|
300
|
+
let indexType;
|
|
301
|
+
if (indexParts.length) {
|
|
302
|
+
for (const [, value] of entries) {
|
|
303
|
+
const propType = emit(value, false, currentBase);
|
|
304
|
+
if (!indexParts.includes(propType)) indexParts.push(propType);
|
|
305
|
+
}
|
|
306
|
+
indexType = indexParts.join(" | ");
|
|
307
|
+
}
|
|
308
|
+
const object = `{ ${properties.join(" ")} }`;
|
|
309
|
+
if (indexType) {
|
|
310
|
+
const index = `{ [key: string]: ${indexType} }`;
|
|
311
|
+
return properties.length ? `${object} & ${index}` : index;
|
|
312
|
+
}
|
|
313
|
+
return object;
|
|
314
|
+
}
|
|
315
|
+
case void 0: return "unknown";
|
|
316
|
+
default: throw new Error(`unsupported transport schema type '${schema.type}'`);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
return emit(root);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
// src/client-contract-file.ts
|
|
323
|
+
/** Generate a client contract without loading Vite or starting a server. */
|
|
324
|
+
async function writeClientContract(entry, output) {
|
|
325
|
+
checkContractOutput(entry, output);
|
|
326
|
+
await writeAppContract(await loadBrickApp(entry), entry, output);
|
|
327
|
+
return resolve(output);
|
|
328
|
+
}
|
|
329
|
+
function checkContractOutput(entry, output) {
|
|
330
|
+
if (resolve(output) === resolve(entry)) throw new Error("Brick: contract output must not overwrite the app entry.");
|
|
331
|
+
}
|
|
332
|
+
/** Write the browser contract of the entry's `app` to `output`. */
|
|
333
|
+
async function writeAppContract(app, entry, output) {
|
|
334
|
+
checkContractOutput(entry, output);
|
|
335
|
+
await writeFileIfChanged(resolve(output), generateClientContract(requireBrickApp(app)));
|
|
336
|
+
}
|
|
337
|
+
/** Begins the name of the temporary file `writeFileIfChanged` renames into place; watchers skip it. */
|
|
338
|
+
const TEMPORARY_FILE_PREFIX = ".brick-write-";
|
|
339
|
+
/** Atomically replace a generated file whose text changed, leaving it (and its timestamp) alone otherwise. */
|
|
340
|
+
async function writeFileIfChanged(output, source) {
|
|
341
|
+
if (await readFile(output, "utf8").catch((error) => {
|
|
342
|
+
if (error.code !== "ENOENT") throw error;
|
|
343
|
+
}) !== source) {
|
|
344
|
+
await mkdir(dirname(output), { recursive: true });
|
|
345
|
+
const temporary = join(dirname(output), `${TEMPORARY_FILE_PREFIX}${randomUUID()}.tmp`);
|
|
346
|
+
try {
|
|
347
|
+
await writeFile(temporary, source, { flag: "wx" });
|
|
348
|
+
await rename(temporary, output);
|
|
349
|
+
} finally {
|
|
350
|
+
await rm(temporary, { force: true });
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
export { generateClientContract as a, writeFileIfChanged as i, writeAppContract as n, importEntry as o, writeClientContract as r, loadBrickApp as s, TEMPORARY_FILE_PREFIX as t };
|
|
355
|
+
|
|
356
|
+
//# sourceMappingURL=client-contract-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-contract-file.js","names":[],"sources":["../src/app-entry.ts","../src/client-contract.ts","../src/client-contract-file.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { requireBrickApp, type BrickApp } from \"@brickkit/core\";\nimport { ConfigError } from \"./config\";\nimport { registerWorkflowTransform } from \"./workflows\";\n\n/**\n * Import an app entry and return its default export. `run`: the app will run\n * in this process, so workflow files are transformed as they load.\n *\n * @throws When the file does not exist.\n */\nexport async function importEntry(\n entry: string,\n options: { run?: boolean } = {},\n): Promise<unknown> {\n const file = resolve(entry);\n if (!existsSync(file))\n throw new ConfigError(`[Brick-TS] Error: Entry file not found: ${file}`);\n if (options.run) await registerWorkflowTransform();\n return (await import(pathToFileURL(file).href)).default;\n}\n\n/**\n * Import an app entry to inspect it: to build it, or to read its routes. The app\n * is not run, so what creating it opened is released here: a workflow world\n * holds Redis connections that would keep the command from exiting.\n */\nexport async function loadBrickApp(entry: string): Promise<BrickApp> {\n const app = requireBrickApp(await importEntry(entry));\n await app.events?.stop();\n return app;\n}\n","import { createHash } from \"node:crypto\";\nimport {\n actionOwners,\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 Brick. 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 ...actionOwners(action),\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 // Whether naming a type saves more text than its declaration costs.\n const worthSharing = (id: number, size: number, name: string) =>\n uses[id]! > 1 &&\n (uses[id]! - 1) * size >\n uses[id]! * name.length + `export type ${name} = ;\\n\\n`.length;\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 if (worthSharing(id, size, name)) {\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 (name && worthSharing(id, body.length, name)) {\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","import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { generateClientContract } from \"./client-contract\";\nimport { requireBrickApp } from \"@brickkit/core\";\nimport { loadBrickApp } from \"./app-entry\";\n\n/** Generate a client contract without loading Vite or starting a server. */\nexport async function writeClientContract(entry: string, output: string) {\n checkContractOutput(entry, output);\n await writeAppContract(await loadBrickApp(entry), entry, output);\n return resolve(output);\n}\n\nfunction checkContractOutput(entry: string, output: string) {\n if (resolve(output) === resolve(entry))\n throw new Error(\"Brick: contract output must not overwrite the app entry.\");\n}\n\n/** Write the browser contract of the entry's `app` to `output`. */\nexport async function writeAppContract(\n app: unknown,\n entry: string,\n output: string,\n) {\n checkContractOutput(entry, output);\n await writeFileIfChanged(\n resolve(output),\n generateClientContract(requireBrickApp(app)),\n );\n}\n\n/** Begins the name of the temporary file `writeFileIfChanged` renames into place; watchers skip it. */\nexport const TEMPORARY_FILE_PREFIX = \".brick-write-\";\n\n/** Atomically replace a generated file whose text changed, leaving it (and its timestamp) alone otherwise. */\nexport async function writeFileIfChanged(output: string, source: string) {\n const previous = await readFile(output, \"utf8\").catch((error) => {\n if (error.code !== \"ENOENT\") throw error;\n return undefined;\n });\n if (previous !== source) {\n await mkdir(dirname(output), { recursive: true });\n const temporary = join(\n dirname(output),\n `${TEMPORARY_FILE_PREFIX}${randomUUID()}.tmp`,\n );\n try {\n await writeFile(temporary, source, { flag: \"wx\" });\n await rename(temporary, output);\n } finally {\n await rm(temporary, { force: true });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA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AK,IAAI;CAClB;AACF;;;ACxcA,eAAsB,oBAAoB,OAAe,QAAgB;CACvE,oBAAoB,OAAO,MAAM;CACjC,MAAM,iBAAiB,MAAM,aAAa,KAAK,GAAG,OAAO,MAAM;CAC/D,OAAO,QAAQ,MAAM;AACvB;AAEA,SAAS,oBAAoB,OAAe,QAAgB;CAC1D,IAAI,QAAQ,MAAM,MAAM,QAAQ,KAAK,GACnC,MAAM,IAAI,MAAM,0DAA0D;AAC9E;;AAGA,eAAsB,iBACpB,KACA,OACA,QACA;CACA,oBAAoB,OAAO,MAAM;CACjC,MAAM,mBACJ,QAAQ,MAAM,GACd,uBAAuB,gBAAgB,GAAG,CAAC,CAC7C;AACF;;AAGA,MAAa,wBAAwB;;AAGrC,eAAsB,mBAAmB,QAAgB,QAAgB;CAKvE,IAAI,MAJmB,SAAS,QAAQ,MAAM,CAAC,CAAC,OAAO,UAAU;EAC/D,IAAI,MAAM,SAAS,UAAU,MAAM;CAErC,CAAC,MACgB,QAAQ;EACvB,MAAM,MAAM,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;EAChD,MAAM,YAAY,KAChB,QAAQ,MAAM,GACd,GAAG,wBAAwB,WAAW,EAAE,KAC1C;EACA,IAAI;GACF,MAAM,UAAU,WAAW,QAAQ,EAAE,MAAM,KAAK,CAAC;GACjD,MAAM,OAAO,WAAW,MAAM;EAChC,UAAU;GACR,MAAM,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC;EACrC;CACF;AACF"}
|
package/dist/compiler.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BrickIR, RouteIR } from "@brickkit/core";
|
|
2
|
+
/**
|
|
3
|
+
* A route's handler factory for `brick build`: it binds the runtime pipeline, so no framework logic is emitted.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated `brick build` no longer emits handler factories; built servers bind routes at startup.
|
|
6
|
+
*/
|
|
7
|
+
export declare function emitHandlerFactory(_route: RouteIR): string;
|
|
8
|
+
/** The `routes.js` module of a build: the compiled IR the built server checks its app against. */
|
|
9
|
+
export declare function emitCompiledApplication(ir: BrickIR,
|
|
10
|
+
/** @deprecated Unused: the module no longer imports the runtime. */
|
|
11
|
+
_runtimeImport?: string): string;
|
|
12
|
+
//# sourceMappingURL=compiler.d.ts.map
|
package/dist/compiler2.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/compiler.ts
|
|
2
|
+
/**
|
|
3
|
+
* A route's handler factory for `brick build`: it binds the runtime pipeline, so no framework logic is emitted.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated `brick build` no longer emits handler factories; built servers bind routes at startup.
|
|
6
|
+
*/
|
|
7
|
+
function emitHandlerFactory(_route) {
|
|
8
|
+
return "function bindAction(binding, runtime) { return runtime.bindRoute(binding); }";
|
|
9
|
+
}
|
|
10
|
+
/** The `routes.js` module of a build: the compiled IR the built server checks its app against. */
|
|
11
|
+
function emitCompiledApplication(ir, _runtimeImport) {
|
|
12
|
+
return `// Generated by Brick compiler v1. Rebuild after changing application definitions.\nexport const ir = JSON.parse(${JSON.stringify(JSON.stringify(ir))});\n`;
|
|
6
13
|
}
|
|
7
14
|
export { emitHandlerFactory as n, emitCompiledApplication as t };
|
|
8
15
|
|
package/dist/compiler2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler2.js","names":[],"sources":["../src/compiler
|
|
1
|
+
{"version":3,"file":"compiler2.js","names":[],"sources":["../src/compiler.ts"],"sourcesContent":["import type { BrickIR, RouteIR } from \"@brickkit/core\";\n\n/**\n * A route's handler factory for `brick build`: it binds the runtime pipeline, so no framework logic is emitted.\n *\n * @deprecated `brick build` no longer emits handler factories; built servers bind routes at startup.\n */\nexport function emitHandlerFactory(_route: RouteIR): string {\n return \"function bindAction(binding, runtime) { return runtime.bindRoute(binding); }\";\n}\n\n/** The `routes.js` module of a build: the compiled IR the built server checks its app against. */\nexport function emitCompiledApplication(\n ir: BrickIR,\n /** @deprecated Unused: the module no longer imports the runtime. */\n _runtimeImport?: string,\n): string {\n return `// Generated by Brick compiler v1. Rebuild after changing application definitions.\\nexport const ir = JSON.parse(${JSON.stringify(JSON.stringify(ir))});\\n`;\n}\n"],"mappings":";;;;;;AAOA,SAAgB,mBAAmB,QAAyB;CAC1D,OAAO;AACT;;AAGA,SAAgB,wBACd,IAEA,gBACQ;CACR,OAAO,oHAAoH,KAAK,UAAU,KAAK,UAAU,EAAE,CAAC,EAAE;AAChK"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as DashboardTheme, t as DashboardExtensionOptions } from "./dashboard-extension.js";
|
|
2
|
+
import { _ as resolvePort, a as DEFAULT_HISTORY_DAYS, c as DevDashboardFlags, d as LoadedConfig, f as PROJECT_DEFAULTS, g as resolveDevDashboard, h as loadConfig, i as DEFAULT_DASHBOARD_PORT, l as LintPreset, m as findConfigFile, n as CONTRACT_FILE, o as DEFAULT_OUTDIR, p as defineConfig, r as ConfigError, s as DEFAULT_PORT, t as BrickConfig, u as LintSeverity, v as resolveProject, y as validateConfig } from "./config2.js";
|
|
3
|
+
export { BrickConfig, CONTRACT_FILE, ConfigError, DEFAULT_DASHBOARD_PORT, DEFAULT_HISTORY_DAYS, DEFAULT_OUTDIR, DEFAULT_PORT, type DashboardExtensionOptions, type DashboardTheme, DevDashboardFlags, LintPreset, LintSeverity, LoadedConfig, PROJECT_DEFAULTS, defineConfig, findConfigFile, loadConfig, resolveDevDashboard, resolvePort, resolveProject, validateConfig };
|