@brickkit/cli 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/bin.js +39 -1
- package/dist/bin.js.map +1 -1
- package/dist/client-contract.js +151 -42
- package/dist/client-contract.js.map +1 -1
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chandraprakash-Darji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ The `brick` binary ships in this package for local dev and inspection:
|
|
|
32
32
|
```sh
|
|
33
33
|
brick dev --port 4000
|
|
34
34
|
brick gen openapi --output openapi.json
|
|
35
|
+
brick gen client src/app.ts
|
|
35
36
|
brick info
|
|
36
37
|
```
|
|
37
38
|
|
|
@@ -130,3 +131,32 @@ schema references and non-JSON transport types fail generation explicitly.
|
|
|
130
131
|
This integration requires Vite 8; the normal server entry point has no Vite
|
|
131
132
|
runtime dependency. `generateClientContract(app)` exposes the source generator
|
|
132
133
|
for non-Vite tooling.
|
|
134
|
+
|
|
135
|
+
## Generate a typed client without Vite
|
|
136
|
+
|
|
137
|
+
Use the standalone Bun CLI with any module whose default export is a `BrickApp`:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
brick gen client src/app.ts
|
|
141
|
+
brick gen client src/app.ts --output frontend/src/contract.ts
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The default output is `_brick/contract.ts`, relative to the working directory.
|
|
145
|
+
The app's selected services and prefix determine its contents, just as with the
|
|
146
|
+
Vite plugin. The command evaluates the entry without calling `.listen()`; keep
|
|
147
|
+
the listener in a separate server bootstrap. Vite is not required or loaded.
|
|
148
|
+
|
|
149
|
+
Run generation before your frontend's development server, build, and type check,
|
|
150
|
+
and rerun after changing backend definitions. You can add a package script:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"scripts": {
|
|
155
|
+
"gen:client": "brick gen client src/app.ts"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Import the generated `contract` with `createBrickClient({ baseUrl, contract })`
|
|
161
|
+
as shown above. The command creates parent directories and leaves an unchanged
|
|
162
|
+
contract file untouched. Add the generated output to `.gitignore`.
|
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { n as startDevServer, t as buildApplication } from "./build.js";
|
|
3
|
+
import { t as generateClientContract } from "./client-contract.js";
|
|
3
4
|
import { generateOpenApiSpec, getGlobalRegistry } from "@brickkit/core";
|
|
5
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
//#region src/client-contract-file.ts
|
|
10
|
+
/** Generate a client contract without loading Vite or starting a server. */
|
|
11
|
+
async function writeClientContract(entryPath, outputPath) {
|
|
12
|
+
const entry = resolve(entryPath);
|
|
13
|
+
const output = resolve(outputPath ?? "_brick/contract.ts");
|
|
14
|
+
if (entry === output) throw new Error("Brick: contract output must not overwrite the app entry.");
|
|
15
|
+
const { default: app } = await import(pathToFileURL(entry).href);
|
|
16
|
+
if (!app || typeof app.endpoint !== "function" || !app.definition) throw new Error("Brick: the entry module must default-export a BrickApp created by brick().");
|
|
17
|
+
const source = generateClientContract(app);
|
|
18
|
+
if (await readFile(output, "utf8").catch((error) => {
|
|
19
|
+
if (error.code !== "ENOENT") throw error;
|
|
20
|
+
}) !== source) {
|
|
21
|
+
await mkdir(dirname(output), { recursive: true });
|
|
22
|
+
const temporary = join(dirname(output), `.brick-contract-${randomUUID()}.tmp`);
|
|
23
|
+
try {
|
|
24
|
+
await writeFile(temporary, source, { flag: "wx" });
|
|
25
|
+
await rename(temporary, output);
|
|
26
|
+
} finally {
|
|
27
|
+
await rm(temporary, { force: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
4
33
|
//#region src/bin.ts
|
|
5
34
|
const args = process.argv.slice(2);
|
|
6
35
|
const command = args[0] || "dev";
|
|
@@ -42,6 +71,14 @@ async function main() {
|
|
|
42
71
|
}
|
|
43
72
|
case "gen": {
|
|
44
73
|
const subCommand = args[1];
|
|
74
|
+
if (subCommand === "client") {
|
|
75
|
+
const entry = args[2];
|
|
76
|
+
if (!entry || entry.startsWith("-")) throw new Error("Usage: brick gen client <entry> [--output <file>]");
|
|
77
|
+
if (args.length > 3 && (args[3] !== "--output" || !args[4] || args[4].startsWith("-") || args.length > 5)) throw new Error("Usage: brick gen client <entry> [--output <file>]");
|
|
78
|
+
const output = await writeClientContract(entry, args[4]);
|
|
79
|
+
console.log(`Client contract written to ${output}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
45
82
|
if (subCommand === "openapi") {
|
|
46
83
|
const outIdx = args.indexOf("--output");
|
|
47
84
|
const outputFile = outIdx !== -1 ? args[outIdx + 1] : void 0;
|
|
@@ -53,7 +90,7 @@ async function main() {
|
|
|
53
90
|
} else console.log(jsonOutput);
|
|
54
91
|
break;
|
|
55
92
|
}
|
|
56
|
-
console.error(`Unknown generator: ${subCommand}. Available: openapi`);
|
|
93
|
+
console.error(`Unknown generator: ${subCommand}. Available: openapi, client`);
|
|
57
94
|
process.exit(1);
|
|
58
95
|
break;
|
|
59
96
|
}
|
|
@@ -72,6 +109,7 @@ Usage:
|
|
|
72
109
|
brick start [entry] Start production server
|
|
73
110
|
brick build <entry> [--outdir <dir>] Compile definitions into a Bun server
|
|
74
111
|
brick gen openapi [--output <file>] Generate OpenAPI 3.1 JSON specification
|
|
112
|
+
brick gen client <entry> [--output <file>] Generate a typed browser client contract
|
|
75
113
|
brick info Export architecture JSON schema
|
|
76
114
|
`);
|
|
77
115
|
process.exit(0);
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env bun\nimport { startDevServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { getGlobalRegistry, generateOpenApiSpec } from \"@brickkit/core\";\n\nconst args = process.argv.slice(2);\nconst command = args[0] || \"dev\";\n\nasync function main() {\n switch (command) {\n case \"dev\":\n case \"start\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n const portArgIdx = args.indexOf(\"--port\");\n const port = portArgIdx !== -1 ? Number(args[portArgIdx + 1]) : 4000;\n\n await startDevServer({ entry, port });\n break;\n }\n\n case \"build\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n if (!entry)\n throw new Error(\n \"Usage: brick build <definitions.ts> [--outdir <directory>] [--prefix <path>] [--port <number>]\",\n );\n const value = (flag: string) => {\n const index = args.indexOf(flag);\n if (index === -1) return undefined;\n if (!args[index + 1] || args[index + 1]!.startsWith(\"--\"))\n throw new Error(`Missing value for ${flag}`);\n return args[index + 1];\n };\n const port = value(\"--port\");\n const result = await buildApplication({\n entry,\n outdir: value(\"--outdir\"),\n prefix: value(\"--prefix\"),\n port: port === undefined ? undefined : Number(port),\n requestLogging: !args.includes(\"--no-request-logging\"),\n });\n for (const warning of result.ir.diagnostics)\n console.warn(`[Brick compiler] ${warning}`);\n console.log(\n `Compiled ${result.ir.services.length} services / ${result.ir.routes.length} routes`,\n );\n console.log(`IR: ${result.outdir}/brick-ir.json`);\n console.log(`Run: bun ${result.entry}`);\n break;\n }\n\n case \"gen\": {\n const subCommand = args[1];\n if (subCommand === \"openapi\") {\n const outIdx = args.indexOf(\"--output\");\n const outputFile = outIdx !== -1 ? args[outIdx + 1] : undefined;\n\n const spec = generateOpenApiSpec();\n const jsonOutput = JSON.stringify(spec, null, 2);\n\n if (outputFile) {\n await Bun.write(outputFile, jsonOutput);\n console.log(`✅ OpenAPI 3.1 specification written to ${outputFile}`);\n } else {\n console.log(jsonOutput);\n }\n break;\n }\n console.error(`Unknown generator: ${subCommand}. Available: openapi
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/client-contract-file.ts","../src/bin.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { generateClientContract } from \"./client-contract\";\nimport type { BrickApp } from \"./endpoints\";\n\n/** Generate a client contract without loading Vite or starting a server. */\nexport async function writeClientContract(\n entryPath: string,\n outputPath?: string,\n) {\n const entry = resolve(entryPath);\n const output = resolve(outputPath ?? \"_brick/contract.ts\");\n if (entry === output)\n throw new Error(\"Brick: contract output must not overwrite the app entry.\");\n const { default: app } = await import(pathToFileURL(entry).href);\n if (!app || typeof app.endpoint !== \"function\" || !app.definition)\n throw new Error(\n \"Brick: the entry module must default-export a BrickApp created by brick().\",\n );\n const source = generateClientContract(app as BrickApp);\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 `.brick-contract-${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 return output;\n}\n","#!/usr/bin/env bun\nimport { startDevServer } from \"./runner\";\nimport { buildApplication } from \"./build\";\nimport { writeClientContract } from \"./client-contract-file\";\nimport { getGlobalRegistry, generateOpenApiSpec } from \"@brickkit/core\";\n\nconst args = process.argv.slice(2);\nconst command = args[0] || \"dev\";\n\nasync function main() {\n switch (command) {\n case \"dev\":\n case \"start\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n const portArgIdx = args.indexOf(\"--port\");\n const port = portArgIdx !== -1 ? Number(args[portArgIdx + 1]) : 4000;\n\n await startDevServer({ entry, port });\n break;\n }\n\n case \"build\": {\n const entry = args[1] && !args[1].startsWith(\"-\") ? args[1] : undefined;\n if (!entry)\n throw new Error(\n \"Usage: brick build <definitions.ts> [--outdir <directory>] [--prefix <path>] [--port <number>]\",\n );\n const value = (flag: string) => {\n const index = args.indexOf(flag);\n if (index === -1) return undefined;\n if (!args[index + 1] || args[index + 1]!.startsWith(\"--\"))\n throw new Error(`Missing value for ${flag}`);\n return args[index + 1];\n };\n const port = value(\"--port\");\n const result = await buildApplication({\n entry,\n outdir: value(\"--outdir\"),\n prefix: value(\"--prefix\"),\n port: port === undefined ? undefined : Number(port),\n requestLogging: !args.includes(\"--no-request-logging\"),\n });\n for (const warning of result.ir.diagnostics)\n console.warn(`[Brick compiler] ${warning}`);\n console.log(\n `Compiled ${result.ir.services.length} services / ${result.ir.routes.length} routes`,\n );\n console.log(`IR: ${result.outdir}/brick-ir.json`);\n console.log(`Run: bun ${result.entry}`);\n break;\n }\n\n case \"gen\": {\n const subCommand = args[1];\n if (subCommand === \"client\") {\n const entry = args[2];\n if (!entry || entry.startsWith(\"-\"))\n throw new Error(\"Usage: brick gen client <entry> [--output <file>]\");\n if (\n args.length > 3 &&\n (args[3] !== \"--output\" ||\n !args[4] ||\n args[4].startsWith(\"-\") ||\n args.length > 5)\n )\n throw new Error(\"Usage: brick gen client <entry> [--output <file>]\");\n const output = await writeClientContract(entry, args[4]);\n console.log(`Client contract written to ${output}`);\n break;\n }\n if (subCommand === \"openapi\") {\n const outIdx = args.indexOf(\"--output\");\n const outputFile = outIdx !== -1 ? args[outIdx + 1] : undefined;\n\n const spec = generateOpenApiSpec();\n const jsonOutput = JSON.stringify(spec, null, 2);\n\n if (outputFile) {\n await Bun.write(outputFile, jsonOutput);\n console.log(`✅ OpenAPI 3.1 specification written to ${outputFile}`);\n } else {\n console.log(jsonOutput);\n }\n break;\n }\n console.error(\n `Unknown generator: ${subCommand}. Available: openapi, client`,\n );\n process.exit(1);\n break;\n }\n\n case \"info\":\n case \"services\": {\n const registry = getGlobalRegistry();\n console.log(JSON.stringify(registry.exportArchitecture(), null, 2));\n break;\n }\n\n default:\n console.log(`\n🧱 Brick-TS CLI\n\nUsage:\n brick dev [entry] [--port <number>] Start development server with live reload\n brick start [entry] Start production server\n brick build <entry> [--outdir <dir>] Compile definitions into a Bun server\n brick gen openapi [--output <file>] Generate OpenAPI 3.1 JSON specification\n brick gen client <entry> [--output <file>] Generate a typed browser client contract\n brick info Export architecture JSON schema\n`);\n process.exit(0);\n }\n}\n\nmain().catch((err) => {\n console.error(\"F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AAI,8BAA8B,QAAQ;IAClD;GACF;GACA,IAAI,eAAe,WAAW;IAC5B,MAAM,SAAS,KAAK,QAAQ,UAAU;IACtC,MAAM,aAAa,WAAW,KAAK,KAAK,SAAS,KAAK,KAAA;IAEtD,MAAM,OAAO,oBAAoB;IACjC,MAAM,aAAa,KAAK,UAAU,MAAM,MAAM,CAAC;IAE/C,IAAI,YAAY;KACd,MAAM,IAAI,MAAM,YAAY,UAAU;KACtC,QAAQ,IAAI,0CAA0C,YAAY;IACpE,OACE,QAAQ,IAAI,UAAU;IAExB;GACF;GACA,QAAQ,MACN,sBAAsB,WAAW,6BACnC;GACA,QAAQ,KAAK,CAAC;GACd;EACF;EAEA,KAAK;EACL,KAAK,YAAY;GACf,MAAM,WAAW,kBAAkB;GACnC,QAAQ,IAAI,KAAK,UAAU,SAAS,mBAAmB,GAAG,MAAM,CAAC,CAAC;GAClE;EACF;EAEA;GACE,QAAQ,IAAI;;;;;;;;;;CAUjB;GACK,QAAQ,KAAK,CAAC;CAClB;AACF;AAEA,KAAK,CAAC,CAAC,OAAO,QAAQ;CACpB,QAAQ,MAAM,gBAAgB,GAAG;CACjC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/client-contract.js
CHANGED
|
@@ -5,17 +5,18 @@ function generateClientContract(app) {
|
|
|
5
5
|
const contract = Object.create(null);
|
|
6
6
|
const types = Object.create(null);
|
|
7
7
|
const resourceActions = /* @__PURE__ */ new Set();
|
|
8
|
-
|
|
9
|
-
for (const service of services)
|
|
8
|
+
const schemas = new SchemaTypes();
|
|
9
|
+
for (const service of services) addResources(service, prefix, contract, types, resourceActions, schemas);
|
|
10
|
+
for (const service of services) addServiceActions(service, prefix, contract, types, resourceActions, schemas);
|
|
10
11
|
return `// Generated by the Brick Vite plugin. Do not edit.
|
|
11
12
|
import type { BrickClientAction } from "@brickkit/core/client";
|
|
12
13
|
|
|
13
|
-
export type AppContract = ${namespaceType(types)};
|
|
14
|
+
${schemas.declarations()}export type AppContract = ${namespaceType(types)};
|
|
14
15
|
|
|
15
16
|
export const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});
|
|
16
17
|
`;
|
|
17
18
|
}
|
|
18
|
-
function addResources(service, prefix, contract, types, resourceActions) {
|
|
19
|
+
function addResources(service, prefix, contract, types, resourceActions, schemas) {
|
|
19
20
|
for (const resource of service.listResources()) {
|
|
20
21
|
if (Object.hasOwn(contract, resource.name)) throw new Error(`Brick client: duplicate namespace '${resource.name}'`);
|
|
21
22
|
const node = Object.create(null);
|
|
@@ -64,7 +65,8 @@ function addResources(service, prefix, contract, types, resourceActions) {
|
|
|
64
65
|
method
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
|
-
|
|
68
|
+
const inputType = schemas.generate(action.config.input);
|
|
69
|
+
const outputSchema = operation === "list" ? {
|
|
68
70
|
...action.config.output,
|
|
69
71
|
required: [.../* @__PURE__ */ new Set([
|
|
70
72
|
...action.config.output?.required ?? [],
|
|
@@ -76,11 +78,12 @@ function addResources(service, prefix, contract, types, resourceActions) {
|
|
|
76
78
|
"hasMore",
|
|
77
79
|
"nextCursor"
|
|
78
80
|
])]
|
|
79
|
-
} : action.config.output
|
|
81
|
+
} : action.config.output;
|
|
82
|
+
typeNode[operation] = actionType(inputType, schemas.generate(outputSchema), action.config.errors);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
function addServiceActions(service, prefix, contract, types, resourceActions) {
|
|
86
|
+
function addServiceActions(service, prefix, contract, types, resourceActions, schemas) {
|
|
84
87
|
const namespace = contract[service.name] ?? Object.create(null);
|
|
85
88
|
const namespaceTypes = types[service.name] ?? Object.create(null);
|
|
86
89
|
contract[service.name] = namespace;
|
|
@@ -91,8 +94,8 @@ function addServiceActions(service, prefix, contract, types, resourceActions) {
|
|
|
91
94
|
let inputType;
|
|
92
95
|
let outputType;
|
|
93
96
|
try {
|
|
94
|
-
inputType = input ?
|
|
95
|
-
outputType = output ?
|
|
97
|
+
inputType = input ? schemas.generate(input) : "unknown";
|
|
98
|
+
outputType = output ? schemas.generate(output) : "unknown";
|
|
96
99
|
} catch (error) {
|
|
97
100
|
throw new Error(`Brick client: cannot generate '${service.name}.${action.name}': ${error.message}`);
|
|
98
101
|
}
|
|
@@ -128,40 +131,146 @@ function actionType(input, output, errors) {
|
|
|
128
131
|
function namespaceType(node) {
|
|
129
132
|
return `{\n${Object.entries(node).map(([key, value]) => ` ${JSON.stringify(key)}: ${typeof value === "string" ? value : namespaceType(value)};`).join("\n")}\n}`;
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
switch (schema.type) {
|
|
141
|
-
case "string": return "string";
|
|
142
|
-
case "number":
|
|
143
|
-
case "integer": return "number";
|
|
144
|
-
case "boolean": return "boolean";
|
|
145
|
-
case "null": return "null";
|
|
146
|
-
case "undefined":
|
|
147
|
-
case "void": return "undefined";
|
|
148
|
-
case "array": return arraySchemaType(schema);
|
|
149
|
-
case "object": return objectSchemaType(schema);
|
|
150
|
-
case void 0: return "unknown";
|
|
151
|
-
default: throw new Error(`unsupported transport schema type '${schema.type}'`);
|
|
134
|
+
var SchemaTypes = class {
|
|
135
|
+
aliases = /* @__PURE__ */ new Map();
|
|
136
|
+
names = /* @__PURE__ */ new Set([
|
|
137
|
+
"AppContract",
|
|
138
|
+
"BrickClientAction",
|
|
139
|
+
"contract"
|
|
140
|
+
]);
|
|
141
|
+
declarations() {
|
|
142
|
+
return [...this.aliases].map(([name, type]) => `export type ${name} = ${type};\n\n`).join("");
|
|
152
143
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
generate(root) {
|
|
145
|
+
const ids = /* @__PURE__ */ new Map();
|
|
146
|
+
const references = [];
|
|
147
|
+
const resources = /* @__PURE__ */ new Map();
|
|
148
|
+
const active = /* @__PURE__ */ new Set();
|
|
149
|
+
const visit = (schema, base) => {
|
|
150
|
+
if (!schema || typeof schema !== "object" || active.has(schema)) return;
|
|
151
|
+
const currentBase = typeof schema.$id === "string" && schema.$id ? schema : base;
|
|
152
|
+
if (!resources.has(schema)) resources.set(schema, currentBase);
|
|
153
|
+
if (typeof schema.$ref === "string") references.push({
|
|
154
|
+
ref: schema.$ref,
|
|
155
|
+
base: currentBase
|
|
156
|
+
});
|
|
157
|
+
active.add(schema);
|
|
158
|
+
try {
|
|
159
|
+
if (typeof schema.$id === "string" && schema.$id) ids.set(schema.$id, schema);
|
|
160
|
+
for (const key of [
|
|
161
|
+
"properties",
|
|
162
|
+
"patternProperties",
|
|
163
|
+
"$defs",
|
|
164
|
+
"definitions"
|
|
165
|
+
]) for (const child of Object.values(schema[key] ?? {})) visit(child, currentBase);
|
|
166
|
+
for (const key of [
|
|
167
|
+
"anyOf",
|
|
168
|
+
"oneOf",
|
|
169
|
+
"allOf",
|
|
170
|
+
"prefixItems"
|
|
171
|
+
]) for (const child of schema[key] ?? []) visit(child, currentBase);
|
|
172
|
+
for (const key of [
|
|
173
|
+
"items",
|
|
174
|
+
"additionalProperties",
|
|
175
|
+
"not"
|
|
176
|
+
]) if (Array.isArray(schema[key])) schema[key].forEach((child) => visit(child, currentBase));
|
|
177
|
+
else visit(schema[key], currentBase);
|
|
178
|
+
} finally {
|
|
179
|
+
active.delete(schema);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
visit(root, root);
|
|
183
|
+
const resolve = (reference, base) => {
|
|
184
|
+
const hashIndex = reference.indexOf("#");
|
|
185
|
+
const id = hashIndex === -1 ? reference : reference.slice(0, hashIndex);
|
|
186
|
+
const fragment = hashIndex === -1 ? void 0 : reference.slice(hashIndex + 1);
|
|
187
|
+
let target = id ? ids.get(id) : base;
|
|
188
|
+
if (fragment) {
|
|
189
|
+
if (!fragment.startsWith("/")) return void 0;
|
|
190
|
+
try {
|
|
191
|
+
for (const part of decodeURIComponent(fragment).slice(1).split("/")) {
|
|
192
|
+
const key = part.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
193
|
+
if (!target || !Object.hasOwn(target, key)) return void 0;
|
|
194
|
+
target = target[key];
|
|
195
|
+
}
|
|
196
|
+
} catch {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return typeof target === "boolean" || target && typeof target === "object" ? target : void 0;
|
|
201
|
+
};
|
|
202
|
+
const targets = new Set(references.map(({ ref, base }) => resolve(ref, base)).filter((value) => value !== void 0));
|
|
203
|
+
const names = /* @__PURE__ */ new Map();
|
|
204
|
+
const emit = (schema, inline = false, base = root) => {
|
|
205
|
+
if (schema === void 0 || schema === true) return "unknown";
|
|
206
|
+
if (schema === false || schema.not && !Object.keys(schema.not).length) return "never";
|
|
207
|
+
const currentBase = schema && typeof schema === "object" && typeof schema.$id === "string" && schema.$id ? schema : base;
|
|
208
|
+
if (!inline && targets.has(schema)) {
|
|
209
|
+
const existing = names.get(schema);
|
|
210
|
+
if (existing) return existing;
|
|
211
|
+
const hint = schema.title ?? schema.$id ?? "Schema";
|
|
212
|
+
let nameBase = String(hint).replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
213
|
+
if (!/^[a-zA-Z_$]/.test(nameBase)) nameBase = `Schema_${nameBase}`;
|
|
214
|
+
nameBase = `Brick${nameBase}`;
|
|
215
|
+
let name = nameBase;
|
|
216
|
+
let suffix = 2;
|
|
217
|
+
while (this.names.has(name)) {
|
|
218
|
+
name = `${nameBase}_${suffix}`;
|
|
219
|
+
suffix += 1;
|
|
220
|
+
}
|
|
221
|
+
this.names.add(name);
|
|
222
|
+
names.set(schema, name);
|
|
223
|
+
this.aliases.set(name, emit(schema, true, currentBase));
|
|
224
|
+
return name;
|
|
225
|
+
}
|
|
226
|
+
if (schema.$ref) {
|
|
227
|
+
const target = resolve(schema.$ref, currentBase);
|
|
228
|
+
if (target === void 0) throw new Error(`unresolved schema reference '${schema.$ref}'`);
|
|
229
|
+
const targetBase = target && typeof target === "object" ? resources.get(target) ?? root : currentBase;
|
|
230
|
+
return emit(target, false, targetBase);
|
|
231
|
+
}
|
|
232
|
+
if (Object.hasOwn(schema, "const")) return JSON.stringify(schema.const);
|
|
233
|
+
if (schema.enum) return schema.enum.map((value) => JSON.stringify(value)).join(" | ") || "never";
|
|
234
|
+
if (schema.anyOf || schema.oneOf) return `(${(schema.anyOf ?? schema.oneOf).map((child) => emit(child, false, currentBase)).join(" | ")})`;
|
|
235
|
+
if (schema.allOf) return `(${schema.allOf.map((child) => emit(child, false, currentBase)).join(" & ")})`;
|
|
236
|
+
switch (schema.type) {
|
|
237
|
+
case "string": return "string";
|
|
238
|
+
case "number":
|
|
239
|
+
case "integer": return "number";
|
|
240
|
+
case "boolean": return "boolean";
|
|
241
|
+
case "null": return "null";
|
|
242
|
+
case "undefined":
|
|
243
|
+
case "void": return "undefined";
|
|
244
|
+
case "array":
|
|
245
|
+
if (Array.isArray(schema.items)) return `[${schema.items.map((child) => emit(child, false, currentBase)).join(", ")}]`;
|
|
246
|
+
return `Array<${emit(schema.items, false, currentBase)}>`;
|
|
247
|
+
case "object": {
|
|
248
|
+
const entries = Object.entries(schema.properties ?? {});
|
|
249
|
+
const properties = entries.map(([key, value]) => `${JSON.stringify(key)}${schema.required?.includes(key) ? "" : "?"}: ${emit(value, false, currentBase)};`);
|
|
250
|
+
const indexParts = Object.values(schema.patternProperties ?? {}).map((child) => emit(child, false, currentBase));
|
|
251
|
+
if (schema.additionalProperties) indexParts.push(emit(schema.additionalProperties, false, currentBase));
|
|
252
|
+
let indexType;
|
|
253
|
+
if (indexParts.length) {
|
|
254
|
+
for (const [, value] of entries) {
|
|
255
|
+
const propType = emit(value, false, currentBase);
|
|
256
|
+
if (!indexParts.includes(propType)) indexParts.push(propType);
|
|
257
|
+
}
|
|
258
|
+
indexType = indexParts.join(" | ");
|
|
259
|
+
}
|
|
260
|
+
const object = `{ ${properties.join(" ")} }`;
|
|
261
|
+
if (indexType) {
|
|
262
|
+
const index = `{ [key: string]: ${indexType} }`;
|
|
263
|
+
return properties.length ? `${object} & ${index}` : index;
|
|
264
|
+
}
|
|
265
|
+
return object;
|
|
266
|
+
}
|
|
267
|
+
case void 0: return "unknown";
|
|
268
|
+
default: throw new Error(`unsupported transport schema type '${schema.type}'`);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
return emit(root);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
165
274
|
//#endregion
|
|
166
275
|
export { generateClientContract as t };
|
|
167
276
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-contract.js","names":[],"sources":["../src/client-contract.ts"],"sourcesContent":["import type { Service } from \"@brickkit/core\";\nimport type { BrickClientAction } from \"@brickkit/core/client\";\nimport type { BrickApp } from \"./endpoints\";\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 resourceActions = new Set<unknown>();\n for (const service of services) {\n addResources(service, prefix, contract, types, resourceActions);\n }\n for (const service of services) {\n addServiceActions(service, prefix, contract, types, resourceActions);\n }\n return `// Generated by the Brick Vite plugin. Do not edit.\nimport type { BrickClientAction } from \"@brickkit/core/client\";\n\nexport type AppContract = ${namespaceType(types)};\n\nexport const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});\n`;\n}\n\nfunction addResources(\n service: Service<any, any>,\n prefix: string,\n contract: Record<string, any>,\n types: Record<string, any>,\n resourceActions: Set<unknown>,\n) {\n for (const resource of service.listResources()) {\n if (Object.hasOwn(contract, resource.name))\n throw new Error(`Brick client: duplicate namespace '${resource.name}'`);\n const node: Record<string, any> = Object.create(null);\n const typeNode: Record<string, any> = Object.create(null);\n contract[resource.name] = node;\n types[resource.name] = typeNode;\n const enabled = new Set(service.listActions());\n for (const [operation, method, item] of [\n [\"list\", \"GET\", false],\n [\"create\", \"POST\", false],\n [\"get\", \"GET\", true],\n [\"update\", \"PATCH\", true],\n [\"delete\", \"DELETE\", true],\n ] as const) {\n const action = resource.actions[operation];\n resourceActions.add(action);\n if (!enabled.has(action)) continue;\n const itemPath = item ? `/:${resource.idField}` : \"\";\n const path = `${prefix}/${resource.name}${itemPath}`;\n node[operation] = {\n kind: \"action\",\n name: action.name,\n serviceName: service.name,\n config: { path, method },\n };\n const inputType = schemaType(action.config.input);\n // The runtime list result always includes these metadata fields.\n const outputSchema =\n operation === \"list\"\n ? {\n ...action.config.output,\n required: [\n ...new Set([\n ...(action.config.output?.required ?? []),\n \"items\",\n \"total\",\n \"limit\",\n \"offset\",\n \"pageCount\",\n \"hasMore\",\n \"nextCursor\",\n ]),\n ],\n }\n : action.config.output;\n typeNode[operation] = actionType(\n inputType,\n schemaType(outputSchema),\n action.config.errors,\n );\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 resourceActions: Set<unknown>,\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 if (resourceActions.has(action)) continue;\n const { input, output, errors, path, method } = action.config;\n let inputType: string;\n let outputType: string;\n try {\n inputType = input ? schemaType(input) : \"unknown\";\n outputType = output ? schemaType(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 config: {\n path: path ?? `${prefix}/${service.name}/${action.name}`,\n method: method ?? \"POST\",\n },\n };\n insertAction(\n namespace,\n namespaceTypes,\n metadata,\n actionType(inputType, outputType, errors),\n );\n }\n}\n\nfunction insertAction(\n node: Record<string, any>,\n typeNode: Record<string, any>,\n metadata: BrickClientAction,\n type: string,\n) {\n const segments = 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 const codes = Object.keys(errors ?? {});\n const errorsType = codes.length\n ? `Record<${codes.map((code) => JSON.stringify(code)).join(\" | \")}, { message: string; status?: number }>`\n : \"{}\";\n return `BrickClientAction<${input}, ${output}, ${errorsType}>`;\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.\nfunction schemaType(schema: any): string {\n if (schema === undefined) return \"unknown\";\n if (schema === true) return \"unknown\";\n if (schema === false || (schema.not && !Object.keys(schema.not).length))\n return \"never\";\n if (schema.$ref)\n throw new Error(`unresolved schema reference '${schema.$ref}'`);\n if (Object.hasOwn(schema, \"const\")) return JSON.stringify(schema.const);\n if (schema.enum)\n return (\n schema.enum.map((value: unknown) => JSON.stringify(value)).join(\" | \") ||\n \"never\"\n );\n if (schema.anyOf || schema.oneOf)\n return `(${(schema.anyOf ?? schema.oneOf).map(schemaType).join(\" | \")})`;\n if (schema.allOf) return `(${schema.allOf.map(schemaType).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 return arraySchemaType(schema);\n case \"object\":\n return objectSchemaType(schema);\n case undefined:\n return \"unknown\";\n default:\n throw new Error(`unsupported transport schema type '${schema.type}'`);\n }\n}\n\nfunction arraySchemaType(schema: any): string {\n if (Array.isArray(schema.items))\n return `[${schema.items.map(schemaType).join(\", \")}]`;\n const itemType = schema.items ? schemaType(schema.items) : \"unknown\";\n return `Array<${itemType}>`;\n}\n\nfunction objectSchemaType(schema: any): string {\n const properties = Object.entries(schema.properties ?? {}).map(\n ([key, value]) =>\n `${JSON.stringify(key)}${schema.required?.includes(key) ? \"\" : \"?\"}: ${schemaType(value)};`,\n );\n const object = `{ ${properties.join(\" \")} }`;\n const patterns = Object.values(schema.patternProperties ?? {});\n if (patterns.length)\n return `${object} & Record<string, ${patterns.map(schemaType).join(\" | \")}>`;\n if (schema.additionalProperties) {\n const valueType =\n schema.additionalProperties === true\n ? \"unknown\"\n : schemaType(schema.additionalProperties);\n return `${object} & Record<string, ${valueType}>`;\n }\n return object;\n}\n"],"mappings":";;AAKA,SAAgB,uBAAuB,KAAuB;CAC5D,MAAM,EAAE,UAAU,WAAW,IAAI;CACjC,MAAM,WAAgC,OAAO,OAAO,IAAI;CACxD,MAAM,QAA6B,OAAO,OAAO,IAAI;CACrD,MAAM,kCAAkB,IAAI,IAAa;CACzC,KAAK,MAAM,WAAW,UACpB,aAAa,SAAS,QAAQ,UAAU,OAAO,eAAe;CAEhE,KAAK,MAAM,WAAW,UACpB,kBAAkB,SAAS,QAAQ,UAAU,OAAO,eAAe;CAErE,OAAO;;;4BAGmB,cAAc,KAAK,EAAE;;kDAEC,KAAK,UAAU,KAAK,UAAU,QAAQ,CAAC,EAAE;;AAE3F;AAEA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AK,QACH,OAAO;EACT,KAAK;EACL,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO,gBAAgB,MAAM;EAC/B,KAAK,UACH,OAAO,iBAAiB,MAAM;EAChC,KAAK,KAAA,GACH,OAAO;EACT,SACE,MAAM,IAAI,MAAM,sCAAsC,OAAO,KAAK,EAAE;CACxE;AACF;AAEA,SAAS,gBAAgB,QAAqB;CAC5C,IAAI,MAAM,QAAQ,OAAO,KAAK,GAC5B,OAAO,IAAI,OAAO,MAAM,IAAI,UAAU,CAAC,CAAC,KAAK,IAAI,EAAE;CAErD,OAAO,SADU,OAAO,QAAQ,WAAW,OAAO,KAAK,IAAI,UAClC;AAC3B;AAEA,SAAS,iBAAiB,QAAqB;CAK7C,MAAM,SAAS,KAJI,OAAO,QAAQ,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,KACxD,CAAC,KAAK,WACL,GAAG,KAAK,UAAU,GAAG,IAAI,OAAO,UAAU,SAAS,GAAG,IAAI,KAAK,IAAI,IAAI,WAAW,KAAK,EAAE,EAEhE,CAAC,CAAC,KAAK,GAAG,EAAE;CACzC,MAAM,WAAW,OAAO,OAAO,OAAO,qBAAqB,CAAC,CAAC;CAC7D,IAAI,SAAS,QACX,OAAO,GAAG,OAAO,oBAAoB,SAAS,IAAI,UAAU,CAAC,CAAC,KAAK,KAAK,EAAE;CAC5E,IAAI,OAAO,sBAKT,OAAO,GAAG,OAAO,oBAHf,OAAO,yBAAyB,OAC5B,YACA,WAAW,OAAO,oBAAoB,EACG;CAEjD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"client-contract.js","names":[],"sources":["../src/client-contract.ts"],"sourcesContent":["import type { Service } from \"@brickkit/core\";\nimport type { BrickClientAction } from \"@brickkit/core/client\";\nimport type { BrickApp } from \"./endpoints\";\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 resourceActions = new Set<unknown>();\n const schemas = new SchemaTypes();\n for (const service of services) {\n addResources(service, prefix, contract, types, resourceActions, schemas);\n }\n for (const service of services) {\n addServiceActions(\n service,\n prefix,\n contract,\n types,\n resourceActions,\n schemas,\n );\n }\n return `// Generated by the Brick Vite plugin. Do not edit.\nimport type { BrickClientAction } from \"@brickkit/core/client\";\n\n${schemas.declarations()}export type AppContract = ${namespaceType(types)};\n\nexport const contract: AppContract = JSON.parse(${JSON.stringify(JSON.stringify(contract))});\n`;\n}\n\nfunction addResources(\n service: Service<any, any>,\n prefix: string,\n contract: Record<string, any>,\n types: Record<string, any>,\n resourceActions: Set<unknown>,\n schemas: SchemaTypes,\n) {\n for (const resource of service.listResources()) {\n if (Object.hasOwn(contract, resource.name))\n throw new Error(`Brick client: duplicate namespace '${resource.name}'`);\n const node: Record<string, any> = Object.create(null);\n const typeNode: Record<string, any> = Object.create(null);\n contract[resource.name] = node;\n types[resource.name] = typeNode;\n const enabled = new Set(service.listActions());\n for (const [operation, method, item] of [\n [\"list\", \"GET\", false],\n [\"create\", \"POST\", false],\n [\"get\", \"GET\", true],\n [\"update\", \"PATCH\", true],\n [\"delete\", \"DELETE\", true],\n ] as const) {\n const action = resource.actions[operation];\n resourceActions.add(action);\n if (!enabled.has(action)) continue;\n const itemPath = item ? `/:${resource.idField}` : \"\";\n const path = `${prefix}/${resource.name}${itemPath}`;\n node[operation] = {\n kind: \"action\",\n name: action.name,\n serviceName: service.name,\n config: { path, method },\n };\n const inputType = schemas.generate(action.config.input);\n // The runtime list result always includes these metadata fields.\n const outputSchema =\n operation === \"list\"\n ? {\n ...action.config.output,\n required: [\n ...new Set([\n ...(action.config.output?.required ?? []),\n \"items\",\n \"total\",\n \"limit\",\n \"offset\",\n \"pageCount\",\n \"hasMore\",\n \"nextCursor\",\n ]),\n ],\n }\n : action.config.output;\n typeNode[operation] = actionType(\n inputType,\n schemas.generate(outputSchema),\n action.config.errors,\n );\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 resourceActions: Set<unknown>,\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 if (resourceActions.has(action)) continue;\n const { input, output, errors, path, method } = 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 config: {\n path: path ?? `${prefix}/${service.name}/${action.name}`,\n method: method ?? \"POST\",\n },\n };\n insertAction(\n namespace,\n namespaceTypes,\n metadata,\n actionType(inputType, outputType, errors),\n );\n }\n}\n\nfunction insertAction(\n node: Record<string, any>,\n typeNode: Record<string, any>,\n metadata: BrickClientAction,\n type: string,\n) {\n const segments = 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 const codes = Object.keys(errors ?? {});\n const errorsType = codes.length\n ? `Record<${codes.map((code) => JSON.stringify(code)).join(\" | \")}, { message: string; status?: number }>`\n : \"{}\";\n return `BrickClientAction<${input}, ${output}, ${errorsType}>`;\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 \"contract\",\n ]);\n\n declarations(): string {\n return [...this.aliases]\n .map(([name, type]) => `export type ${name} = ${type};\\n\\n`)\n .join(\"\");\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 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":";;AAKA,SAAgB,uBAAuB,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"version": "0.2.3",
|
|
4
4
|
"description": "CLI and server engine for Brick-TS",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
8
|
"module": "./dist/index.js",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"format:check": "oxfmt --check ."
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@brickkit/core": "^0.2.
|
|
52
|
+
"@brickkit/core": "^0.2.3",
|
|
52
53
|
"@sinclair/typebox": "^0.34.0",
|
|
53
54
|
"elysia": "^1.2.0"
|
|
54
55
|
},
|