bonescript-compiler 0.5.1 → 0.5.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/dist/commands/diff.js +3 -5
- package/dist/commands/diff.js.map +1 -1
- package/dist/emit_capability.js +6 -8
- package/dist/emit_capability.js.map +1 -1
- package/dist/emit_database.js +2 -4
- package/dist/emit_database.js.map +1 -1
- package/dist/emit_deploy.js +6 -8
- package/dist/emit_deploy.js.map +1 -1
- package/dist/emit_events.js +2 -19
- package/dist/emit_events.js.map +1 -1
- package/dist/emit_extras.js +3 -5
- package/dist/emit_extras.js.map +1 -1
- package/dist/emit_full.js +9 -11
- package/dist/emit_full.js.map +1 -1
- package/dist/emit_openapi.js +2 -4
- package/dist/emit_openapi.js.map +1 -1
- package/dist/emit_package.js +2 -4
- package/dist/emit_package.js.map +1 -1
- package/dist/emit_router.js +3 -4
- package/dist/emit_router.js.map +1 -1
- package/dist/emit_tests.js +16 -18
- package/dist/emit_tests.js.map +1 -1
- package/dist/emit_websocket.js +0 -3
- package/dist/emit_websocket.js.map +1 -1
- package/dist/emitter.js +27 -48
- package/dist/emitter.js.map +1 -1
- package/dist/extension_manager.js +3 -17
- package/dist/extension_manager.js.map +1 -1
- package/dist/lowering.js +19 -0
- package/dist/lowering.js.map +1 -1
- package/dist/optimizer.js +6 -3
- package/dist/optimizer.js.map +1 -1
- package/dist/solver.js +1 -1
- package/dist/solver.js.map +1 -1
- package/dist/typechecker.d.ts +2 -0
- package/dist/typechecker.js +35 -3
- package/dist/typechecker.js.map +1 -1
- package/dist/verifier.js +2 -3
- package/dist/verifier.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/compile.ts +191 -191
- package/src/commands/diff.ts +1 -4
- package/src/emit_capability.ts +1 -5
- package/src/emit_database.ts +1 -4
- package/src/emit_deploy.ts +1 -4
- package/src/emit_events.ts +1 -16
- package/src/emit_extras.ts +1 -4
- package/src/emit_full.ts +1 -4
- package/src/emit_openapi.ts +1 -4
- package/src/emit_package.ts +1 -4
- package/src/emit_router.ts +1 -2
- package/src/emit_tests.ts +1 -4
- package/src/emit_websocket.ts +1 -4
- package/src/emitter.ts +12 -28
- package/src/extension_manager.ts +1 -13
- package/src/lowering.ts +27 -1
- package/src/optimizer.ts +6 -3
- package/src/solver.ts +1 -1
- package/src/typechecker.ts +47 -4
- package/src/verifier.ts +4 -5
package/src/commands/compile.ts
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bonec compile <file>
|
|
3
|
-
* Full 7-stage compilation pipeline → runnable project.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as fs from "fs";
|
|
7
|
-
import * as path from "path";
|
|
8
|
-
import { createHash } from "crypto";
|
|
9
|
-
import { Lexer } from "../lexer";
|
|
10
|
-
import { TypeChecker } from "../typechecker";
|
|
11
|
-
import { Lowering } from "../lowering";
|
|
12
|
-
import { ConstraintSolver } from "../solver";
|
|
13
|
-
import { FullEmitter } from "../emit_full";
|
|
14
|
-
import { Verifier } from "../verifier";
|
|
15
|
-
import { ModuleLoader } from "../module_loader";
|
|
16
|
-
import { mergeWithExisting } from "../extension_manager";
|
|
17
|
-
import { optimize } from "../optimizer";
|
|
18
|
-
|
|
19
|
-
export async function runCompile(source: string, resolved: string): Promise<void> {
|
|
20
|
-
try {
|
|
21
|
-
const tokens = new Lexer(source).tokenize();
|
|
22
|
-
console.log(` [1/7] Lexed: ${tokens.length} tokens`);
|
|
23
|
-
|
|
24
|
-
const loader = new ModuleLoader();
|
|
25
|
-
const loadResult = await loader.load(resolved);
|
|
26
|
-
|
|
27
|
-
if (loadResult.errors.length > 0) {
|
|
28
|
-
console.log(` [2/7] Parse: ${loadResult.errors.length} error(s)`);
|
|
29
|
-
for (const e of loadResult.errors.slice(0, 10)) {
|
|
30
|
-
console.log(` ${path.basename(e.file)}: ${e.error.message}`);
|
|
31
|
-
}
|
|
32
|
-
if (!loadResult.ast) process.exit(1);
|
|
33
|
-
} else {
|
|
34
|
-
const sysCount = loadResult.ast?.systems.length || 0;
|
|
35
|
-
console.log(` [2/7] Parsed: ${sysCount} system(s) from ${loadResult.loadedFiles.length} file(s)`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const ast = loadResult.ast!;
|
|
39
|
-
|
|
40
|
-
for (const sys of ast.systems) {
|
|
41
|
-
console.log(` System '${sys.name}':`);
|
|
42
|
-
const counts: Record<string, number> = {};
|
|
43
|
-
for (const d of sys.declarations) counts[d.kind] = (counts[d.kind] || 0) + 1;
|
|
44
|
-
for (const [kind, count] of Object.entries(counts)) {
|
|
45
|
-
console.log(` ${kind}: ${count}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Stage 3: Type Check
|
|
50
|
-
const typeErrors = new TypeChecker().check(ast);
|
|
51
|
-
if (typeErrors.length > 0) {
|
|
52
|
-
console.log(` [3/7] Type check: ${typeErrors.length} error(s)`);
|
|
53
|
-
for (const err of typeErrors) {
|
|
54
|
-
console.log(` ${err.code} at ${err.loc.line}:${err.loc.column}: ${err.message}`);
|
|
55
|
-
}
|
|
56
|
-
process.exit(1);
|
|
57
|
-
} else {
|
|
58
|
-
console.log(` [3/7] Type check: v (0 errors)`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Stage 4: Lower to IR
|
|
62
|
-
const sourceHash = createHash("sha256").update(source).digest("hex").slice(0, 16);
|
|
63
|
-
const irSystems = new Lowering().lower(ast, sourceHash);
|
|
64
|
-
const totalModules = irSystems.reduce((sum, s) => sum + s.modules.length, 0);
|
|
65
|
-
const totalEvents = irSystems.reduce((sum, s) => sum + s.events.length, 0);
|
|
66
|
-
const totalFlows = irSystems.reduce((sum, s) => sum + s.flows.length, 0);
|
|
67
|
-
console.log(` [4/7] Lower to IR: ${totalModules} modules, ${totalEvents} events, ${totalFlows} flows`);
|
|
68
|
-
for (const sys of irSystems) {
|
|
69
|
-
for (const mod of sys.modules) {
|
|
70
|
-
const methodCount = mod.interfaces.reduce((s, i) => s + i.methods.length, 0);
|
|
71
|
-
console.log(` ${mod.kind.padEnd(16)} ${mod.name.padEnd(24)} (${methodCount} methods, ${mod.models.length} models)`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Stage 4.5: IR Optimization
|
|
76
|
-
for (let i = 0; i < irSystems.length; i++) {
|
|
77
|
-
const result = optimize(irSystems[i]);
|
|
78
|
-
irSystems[i] = result.system;
|
|
79
|
-
if (result.log.length > 0) {
|
|
80
|
-
console.log(` [4.5] IR optimize: ${result.modulesRemoved} modules removed, ${result.eventsDeduped} events deduped, ${result.depsRemoved} deps minimized`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Stage 5: Constraint Solve
|
|
85
|
-
const solver = new ConstraintSolver();
|
|
86
|
-
let totalResolved = 0;
|
|
87
|
-
let solverFailed = false;
|
|
88
|
-
for (const sys of irSystems) {
|
|
89
|
-
const result = solver.solve(sys);
|
|
90
|
-
sys.resolution = result.resolution;
|
|
91
|
-
totalResolved += Object.keys(result.resolution).length;
|
|
92
|
-
if (result.errors.length > 0) {
|
|
93
|
-
solverFailed = true;
|
|
94
|
-
console.log(` [5/7] Constraint solve: ${result.errors.length} error(s)`);
|
|
95
|
-
for (const err of result.errors) console.log(` x ${err}`);
|
|
96
|
-
} else {
|
|
97
|
-
console.log(` [5/7] Constraint solve: v (${totalResolved} resolved, ${result.assumptions.length} assumptions)`);
|
|
98
|
-
for (const a of result.assumptions.slice(0, 5)) console.log(` ${a}`);
|
|
99
|
-
if (result.assumptions.length > 5) console.log(` ... and ${result.assumptions.length - 5} more`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Back-propagate resolved values into module configs so emitters pick them up.
|
|
103
|
-
// The solver resolves keys like "APIGateway.rate_limit" → write back to mod.config.
|
|
104
|
-
for (const mod of sys.modules) {
|
|
105
|
-
for (const [key, value] of Object.entries(result.resolution)) {
|
|
106
|
-
const prefix = `${mod.name}.`;
|
|
107
|
-
if (key.startsWith(prefix)) {
|
|
108
|
-
const prop = key.slice(prefix.length);
|
|
109
|
-
// Only overwrite if the module config doesn't already have an explicit value
|
|
110
|
-
if (mod.config[prop] === undefined || mod.config[prop] === null) {
|
|
111
|
-
const numVal = Number(value);
|
|
112
|
-
mod.config[prop] = isNaN(numVal) ? value : numVal;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (solverFailed) process.exit(1);
|
|
119
|
-
|
|
120
|
-
// Stage 6: Code Emit
|
|
121
|
-
const emitter = new FullEmitter();
|
|
122
|
-
const allFiles: ReturnType<typeof emitter.emit> = [];
|
|
123
|
-
for (const sys of irSystems) allFiles.push(...emitter.emit(sys));
|
|
124
|
-
console.log(` [6/7] Code emit: ${allFiles.length} files generated`);
|
|
125
|
-
const byLang: Record<string, number> = {};
|
|
126
|
-
for (const f of allFiles) byLang[f.language] = (byLang[f.language] || 0) + 1;
|
|
127
|
-
for (const [lang, count] of Object.entries(byLang)) {
|
|
128
|
-
console.log(` ${lang}: ${count} file(s)`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Stage 7: Verify — check ALL systems, not just the first
|
|
132
|
-
let verifyFailed = false;
|
|
133
|
-
let totalVerifyErrors = 0;
|
|
134
|
-
let totalVerifyWarnings = 0;
|
|
135
|
-
for (const sys of irSystems) {
|
|
136
|
-
const verifyResult = new Verifier().verify(sys, allFiles);
|
|
137
|
-
const errCount = verifyResult.issues.filter(i => i.severity === "error").length;
|
|
138
|
-
const warnCount = verifyResult.issues.filter(i => i.severity === "warning").length;
|
|
139
|
-
totalVerifyErrors += errCount;
|
|
140
|
-
totalVerifyWarnings += warnCount;
|
|
141
|
-
if (!verifyResult.passed) verifyFailed = true;
|
|
142
|
-
for (const issue of verifyResult.issues.slice(0, 10)) {
|
|
143
|
-
console.log(` ${issue.severity === "error" ? "x" : "!"} ${issue.code}: ${issue.message}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (verifyFailed) {
|
|
147
|
-
console.log(` [7/7] Verify: FAILED (${totalVerifyErrors} errors, ${totalVerifyWarnings} warnings)`);
|
|
148
|
-
} else {
|
|
149
|
-
console.log(` [7/7] Verify: v (${allFiles.length} files, ${totalVerifyWarnings} warnings)`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Abort before writing output if verification failed
|
|
153
|
-
if (verifyFailed) process.exit(1);
|
|
154
|
-
|
|
155
|
-
// Write output — all writes in parallel per directory
|
|
156
|
-
const outputDir = path.resolve(path.dirname(resolved), "output");
|
|
157
|
-
const allExtensions = irSystems.flatMap(s => s.extension_points || []);
|
|
158
|
-
const extensionErrors: string[] = [];
|
|
159
|
-
|
|
160
|
-
// Collect unique directories and create them all first
|
|
161
|
-
const dirs = new Set(allFiles.map(f => path.dirname(path.join(outputDir, f.path))));
|
|
162
|
-
await Promise.all([...dirs].map(dir => fs.promises.mkdir(dir, { recursive: true })));
|
|
163
|
-
|
|
164
|
-
// Write all files (extensions.ts merged, rest written directly)
|
|
165
|
-
await Promise.all(allFiles.map(async f => {
|
|
166
|
-
const outPath = path.join(outputDir, f.path);
|
|
167
|
-
|
|
168
|
-
if (f.path === "src/extensions.ts" && allExtensions.length > 0) {
|
|
169
|
-
const astExtensions = ast.systems.flatMap(s =>
|
|
170
|
-
s.declarations.filter((d): d is any => d.kind === "ExtensionPointDecl")
|
|
171
|
-
);
|
|
172
|
-
const { content, validationErrors } = await mergeWithExisting(f.content, outPath, astExtensions);
|
|
173
|
-
for (const e of validationErrors) extensionErrors.push(e.message);
|
|
174
|
-
await fs.promises.writeFile(outPath, content, "utf-8");
|
|
175
|
-
} else {
|
|
176
|
-
await fs.promises.writeFile(outPath, f.content, "utf-8");
|
|
177
|
-
}
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
if (extensionErrors.length > 0) {
|
|
181
|
-
console.log(`\n Extension point errors:`);
|
|
182
|
-
for (const e of extensionErrors) console.log(` x ${e}`);
|
|
183
|
-
process.exit(1);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
console.log(`\nv Compilation complete. ${allFiles.length} files written to output/`);
|
|
187
|
-
} catch (e: any) {
|
|
188
|
-
console.error(`x ${e.message}`);
|
|
189
|
-
process.exit(1);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* bonec compile <file>
|
|
3
|
+
* Full 7-stage compilation pipeline → runnable project.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { createHash } from "crypto";
|
|
9
|
+
import { Lexer } from "../lexer";
|
|
10
|
+
import { TypeChecker } from "../typechecker";
|
|
11
|
+
import { Lowering } from "../lowering";
|
|
12
|
+
import { ConstraintSolver } from "../solver";
|
|
13
|
+
import { FullEmitter } from "../emit_full";
|
|
14
|
+
import { Verifier } from "../verifier";
|
|
15
|
+
import { ModuleLoader } from "../module_loader";
|
|
16
|
+
import { mergeWithExisting } from "../extension_manager";
|
|
17
|
+
import { optimize } from "../optimizer";
|
|
18
|
+
|
|
19
|
+
export async function runCompile(source: string, resolved: string): Promise<void> {
|
|
20
|
+
try {
|
|
21
|
+
const tokens = new Lexer(source).tokenize();
|
|
22
|
+
console.log(` [1/7] Lexed: ${tokens.length} tokens`);
|
|
23
|
+
|
|
24
|
+
const loader = new ModuleLoader();
|
|
25
|
+
const loadResult = await loader.load(resolved);
|
|
26
|
+
|
|
27
|
+
if (loadResult.errors.length > 0) {
|
|
28
|
+
console.log(` [2/7] Parse: ${loadResult.errors.length} error(s)`);
|
|
29
|
+
for (const e of loadResult.errors.slice(0, 10)) {
|
|
30
|
+
console.log(` ${path.basename(e.file)}: ${e.error.message}`);
|
|
31
|
+
}
|
|
32
|
+
if (!loadResult.ast) process.exit(1);
|
|
33
|
+
} else {
|
|
34
|
+
const sysCount = loadResult.ast?.systems.length || 0;
|
|
35
|
+
console.log(` [2/7] Parsed: ${sysCount} system(s) from ${loadResult.loadedFiles.length} file(s)`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ast = loadResult.ast!;
|
|
39
|
+
|
|
40
|
+
for (const sys of ast.systems) {
|
|
41
|
+
console.log(` System '${sys.name}':`);
|
|
42
|
+
const counts: Record<string, number> = {};
|
|
43
|
+
for (const d of sys.declarations) counts[d.kind] = (counts[d.kind] || 0) + 1;
|
|
44
|
+
for (const [kind, count] of Object.entries(counts)) {
|
|
45
|
+
console.log(` ${kind}: ${count}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Stage 3: Type Check
|
|
50
|
+
const typeErrors = new TypeChecker().check(ast);
|
|
51
|
+
if (typeErrors.length > 0) {
|
|
52
|
+
console.log(` [3/7] Type check: ${typeErrors.length} error(s)`);
|
|
53
|
+
for (const err of typeErrors) {
|
|
54
|
+
console.log(` ${err.code} at ${err.loc.line}:${err.loc.column}: ${err.message}`);
|
|
55
|
+
}
|
|
56
|
+
process.exit(1);
|
|
57
|
+
} else {
|
|
58
|
+
console.log(` [3/7] Type check: v (0 errors)`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Stage 4: Lower to IR
|
|
62
|
+
const sourceHash = createHash("sha256").update(source).digest("hex").slice(0, 16);
|
|
63
|
+
const irSystems = new Lowering().lower(ast, sourceHash);
|
|
64
|
+
const totalModules = irSystems.reduce((sum, s) => sum + s.modules.length, 0);
|
|
65
|
+
const totalEvents = irSystems.reduce((sum, s) => sum + s.events.length, 0);
|
|
66
|
+
const totalFlows = irSystems.reduce((sum, s) => sum + s.flows.length, 0);
|
|
67
|
+
console.log(` [4/7] Lower to IR: ${totalModules} modules, ${totalEvents} events, ${totalFlows} flows`);
|
|
68
|
+
for (const sys of irSystems) {
|
|
69
|
+
for (const mod of sys.modules) {
|
|
70
|
+
const methodCount = mod.interfaces.reduce((s, i) => s + i.methods.length, 0);
|
|
71
|
+
console.log(` ${mod.kind.padEnd(16)} ${mod.name.padEnd(24)} (${methodCount} methods, ${mod.models.length} models)`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Stage 4.5: IR Optimization
|
|
76
|
+
for (let i = 0; i < irSystems.length; i++) {
|
|
77
|
+
const result = optimize(irSystems[i]);
|
|
78
|
+
irSystems[i] = result.system;
|
|
79
|
+
if (result.log.length > 0) {
|
|
80
|
+
console.log(` [4.5] IR optimize: ${result.modulesRemoved} modules removed, ${result.eventsDeduped} events deduped, ${result.depsRemoved} deps minimized`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Stage 5: Constraint Solve
|
|
85
|
+
const solver = new ConstraintSolver();
|
|
86
|
+
let totalResolved = 0;
|
|
87
|
+
let solverFailed = false;
|
|
88
|
+
for (const sys of irSystems) {
|
|
89
|
+
const result = solver.solve(sys);
|
|
90
|
+
sys.resolution = result.resolution;
|
|
91
|
+
totalResolved += Object.keys(result.resolution).length;
|
|
92
|
+
if (result.errors.length > 0) {
|
|
93
|
+
solverFailed = true;
|
|
94
|
+
console.log(` [5/7] Constraint solve: ${result.errors.length} error(s)`);
|
|
95
|
+
for (const err of result.errors) console.log(` x ${err}`);
|
|
96
|
+
} else {
|
|
97
|
+
console.log(` [5/7] Constraint solve: v (${totalResolved} resolved, ${result.assumptions.length} assumptions)`);
|
|
98
|
+
for (const a of result.assumptions.slice(0, 5)) console.log(` ${a}`);
|
|
99
|
+
if (result.assumptions.length > 5) console.log(` ... and ${result.assumptions.length - 5} more`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Back-propagate resolved values into module configs so emitters pick them up.
|
|
103
|
+
// The solver resolves keys like "APIGateway.rate_limit" → write back to mod.config.
|
|
104
|
+
for (const mod of sys.modules) {
|
|
105
|
+
for (const [key, value] of Object.entries(result.resolution)) {
|
|
106
|
+
const prefix = `${mod.name}.`;
|
|
107
|
+
if (key.startsWith(prefix)) {
|
|
108
|
+
const prop = key.slice(prefix.length);
|
|
109
|
+
// Only overwrite if the module config doesn't already have an explicit value
|
|
110
|
+
if (mod.config[prop] === undefined || mod.config[prop] === null) {
|
|
111
|
+
const numVal = Number(value);
|
|
112
|
+
mod.config[prop] = isNaN(numVal) ? value : numVal;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (solverFailed) process.exit(1);
|
|
119
|
+
|
|
120
|
+
// Stage 6: Code Emit
|
|
121
|
+
const emitter = new FullEmitter();
|
|
122
|
+
const allFiles: ReturnType<typeof emitter.emit> = [];
|
|
123
|
+
for (const sys of irSystems) allFiles.push(...emitter.emit(sys));
|
|
124
|
+
console.log(` [6/7] Code emit: ${allFiles.length} files generated`);
|
|
125
|
+
const byLang: Record<string, number> = {};
|
|
126
|
+
for (const f of allFiles) byLang[f.language] = (byLang[f.language] || 0) + 1;
|
|
127
|
+
for (const [lang, count] of Object.entries(byLang)) {
|
|
128
|
+
console.log(` ${lang}: ${count} file(s)`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Stage 7: Verify — check ALL systems, not just the first
|
|
132
|
+
let verifyFailed = false;
|
|
133
|
+
let totalVerifyErrors = 0;
|
|
134
|
+
let totalVerifyWarnings = 0;
|
|
135
|
+
for (const sys of irSystems) {
|
|
136
|
+
const verifyResult = new Verifier().verify(sys, allFiles);
|
|
137
|
+
const errCount = verifyResult.issues.filter(i => i.severity === "error").length;
|
|
138
|
+
const warnCount = verifyResult.issues.filter(i => i.severity === "warning").length;
|
|
139
|
+
totalVerifyErrors += errCount;
|
|
140
|
+
totalVerifyWarnings += warnCount;
|
|
141
|
+
if (!verifyResult.passed) verifyFailed = true;
|
|
142
|
+
for (const issue of verifyResult.issues.slice(0, 10)) {
|
|
143
|
+
console.log(` ${issue.severity === "error" ? "x" : "!"} ${issue.code}: ${issue.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (verifyFailed) {
|
|
147
|
+
console.log(` [7/7] Verify: FAILED (${totalVerifyErrors} errors, ${totalVerifyWarnings} warnings)`);
|
|
148
|
+
} else {
|
|
149
|
+
console.log(` [7/7] Verify: v (${allFiles.length} files, ${totalVerifyWarnings} warnings)`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Abort before writing output if verification failed
|
|
153
|
+
if (verifyFailed) process.exit(1);
|
|
154
|
+
|
|
155
|
+
// Write output — all writes in parallel per directory
|
|
156
|
+
const outputDir = path.resolve(path.dirname(resolved), "output");
|
|
157
|
+
const allExtensions = irSystems.flatMap(s => s.extension_points || []);
|
|
158
|
+
const extensionErrors: string[] = [];
|
|
159
|
+
|
|
160
|
+
// Collect unique directories and create them all first
|
|
161
|
+
const dirs = new Set(allFiles.map(f => path.dirname(path.join(outputDir, f.path))));
|
|
162
|
+
await Promise.all([...dirs].map(dir => fs.promises.mkdir(dir, { recursive: true })));
|
|
163
|
+
|
|
164
|
+
// Write all files (extensions.ts merged, rest written directly)
|
|
165
|
+
await Promise.all(allFiles.map(async f => {
|
|
166
|
+
const outPath = path.join(outputDir, f.path);
|
|
167
|
+
|
|
168
|
+
if (f.path === "src/extensions.ts" && allExtensions.length > 0) {
|
|
169
|
+
const astExtensions = ast.systems.flatMap(s =>
|
|
170
|
+
s.declarations.filter((d): d is any => d.kind === "ExtensionPointDecl")
|
|
171
|
+
);
|
|
172
|
+
const { content, validationErrors } = await mergeWithExisting(f.content, outPath, astExtensions);
|
|
173
|
+
for (const e of validationErrors) extensionErrors.push(e.message);
|
|
174
|
+
await fs.promises.writeFile(outPath, content, "utf-8");
|
|
175
|
+
} else {
|
|
176
|
+
await fs.promises.writeFile(outPath, f.content, "utf-8");
|
|
177
|
+
}
|
|
178
|
+
}));
|
|
179
|
+
|
|
180
|
+
if (extensionErrors.length > 0) {
|
|
181
|
+
console.log(`\n Extension point errors:`);
|
|
182
|
+
for (const e of extensionErrors) console.log(` x ${e}`);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(`\nv Compilation complete. ${allFiles.length} files written to output/`);
|
|
187
|
+
} catch (e: any) {
|
|
188
|
+
console.error(`x ${e.message}`);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
}
|
package/src/commands/diff.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { createHash } from "crypto";
|
|
|
9
9
|
import { Lexer } from "../lexer";
|
|
10
10
|
import { Parser } from "../parser";
|
|
11
11
|
import { Lowering } from "../lowering";
|
|
12
|
+
import { toSnakeCase } from "../lowering_helpers";
|
|
12
13
|
import type * as IR from "../ir";
|
|
13
14
|
|
|
14
15
|
const SQL_TYPE_MAP: Record<string, string> = {
|
|
@@ -16,10 +17,6 @@ const SQL_TYPE_MAP: Record<string, string> = {
|
|
|
16
17
|
bool: "BOOLEAN", timestamp: "TIMESTAMPTZ", uuid: "UUID", bytes: "BYTEA", json: "JSONB",
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
function toSnakeCase(s: string): string {
|
|
20
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
20
|
async function compileToIR(filePath: string): Promise<IR.IRSystem[]> {
|
|
24
21
|
const resolved = path.resolve(filePath);
|
|
25
22
|
try {
|
package/src/emit_capability.ts
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import * as IR from "./ir";
|
|
21
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
21
22
|
|
|
22
|
-
// ─── Expression Parser ────────────────────────────────────────────────────────
|
|
23
23
|
|
|
24
24
|
type ExprKind =
|
|
25
25
|
| { kind: "literal"; value: string; raw: string }
|
|
@@ -88,10 +88,6 @@ interface EntityFetch {
|
|
|
88
88
|
idField: string;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
function toSnakeCase(s: string): string {
|
|
92
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
91
|
function getEntityFetches(method: IR.IRMethod, mod: IR.IRModule, system: IR.IRSystem): EntityFetch[] {
|
|
96
92
|
const fetches: EntityFetch[] = [];
|
|
97
93
|
const seen = new Set<string>();
|
package/src/emit_database.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as IR from "./ir";
|
|
7
|
-
|
|
8
|
-
function toSnakeCase(s: string): string {
|
|
9
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
10
|
-
}
|
|
7
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
11
8
|
|
|
12
9
|
export function emitDbClient(system: IR.IRSystem): string {
|
|
13
10
|
const name = toSnakeCase(system.name);
|
package/src/emit_deploy.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as IR from "./ir";
|
|
7
|
-
|
|
8
|
-
function toSnakeCase(s: string): string {
|
|
9
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
10
|
-
}
|
|
7
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
11
8
|
|
|
12
9
|
export function emitDockerfile(system: IR.IRSystem): string {
|
|
13
10
|
return `# Generated by BoneScript compiler.
|
package/src/emit_events.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import * as IR from "./ir";
|
|
14
|
+
import { toTsType } from "./emit_router";
|
|
14
15
|
|
|
15
16
|
// ─── Outbox SQL Schema ────────────────────────────────────────────────────────
|
|
16
17
|
|
|
@@ -311,22 +312,6 @@ export const eventBus = {
|
|
|
311
312
|
// spec/09_CODEGEN.md §5.4. These wrap eventBus.publish with a typed payload
|
|
312
313
|
// interface so callers get compile-time safety instead of raw Record<string,unknown>.
|
|
313
314
|
|
|
314
|
-
const TS_TYPE_MAP: Record<string, string> = {
|
|
315
|
-
string: "string", uint: "number", int: "number", float: "number",
|
|
316
|
-
bool: "boolean", timestamp: "Date", uuid: "string", bytes: "Buffer", json: "unknown",
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
function toTsType(irType: string): string {
|
|
320
|
-
if (TS_TYPE_MAP[irType]) return TS_TYPE_MAP[irType];
|
|
321
|
-
const listMatch = irType.match(/^list<(.+)>$/);
|
|
322
|
-
if (listMatch) return `${toTsType(listMatch[1])}[]`;
|
|
323
|
-
const setMatch = irType.match(/^set<(.+)>$/);
|
|
324
|
-
if (setMatch) return `${toTsType(setMatch[1])}[]`;
|
|
325
|
-
const optMatch = irType.match(/^optional<(.+)>$/);
|
|
326
|
-
if (optMatch) return `${toTsType(optMatch[1])} | null`;
|
|
327
|
-
return irType;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
315
|
export function emitTypedEventPublishers(system: IR.IRSystem): string {
|
|
331
316
|
if (system.events.length === 0) return "";
|
|
332
317
|
|
package/src/emit_extras.ts
CHANGED
|
@@ -8,10 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import * as IR from "./ir";
|
|
10
10
|
import * as AST from "./ast";
|
|
11
|
-
|
|
12
|
-
function toSnakeCase(s: string): string {
|
|
13
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
14
|
-
}
|
|
11
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
15
12
|
|
|
16
13
|
// ─── Derived Field Emission ──────────────────────────────────────────────────
|
|
17
14
|
// Derived fields become PostgreSQL generated columns (when expression supports it)
|
package/src/emit_full.ts
CHANGED
|
@@ -34,10 +34,7 @@ import { emitTestSuite } from "./emit_tests";
|
|
|
34
34
|
import { emitDockerfile, emitDockerignore, emitK8sDeployment, emitGithubActions } from "./emit_deploy";
|
|
35
35
|
import { emitModelFile, emitModelsIndex } from "./emit_models";
|
|
36
36
|
import { emitOpenApiSchema } from "./emit_openapi";
|
|
37
|
-
|
|
38
|
-
function toSnakeCase(s: string): string {
|
|
39
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
40
|
-
}
|
|
37
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
41
38
|
|
|
42
39
|
/** Resolve the auth method for the system from the resolution map or module configs. */
|
|
43
40
|
function resolveSystemAuthMethod(system: IR.IRSystem): "jwt" | "oauth2" | "apikey" {
|
package/src/emit_openapi.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as IR from "./ir";
|
|
10
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
10
11
|
|
|
11
12
|
// ─── Type mapping ─────────────────────────────────────────────────────────────
|
|
12
13
|
|
|
@@ -53,10 +54,6 @@ function modelToSchema(model: IR.IRModel): Record<string, unknown> {
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
function toSnakeCase(s: string): string {
|
|
57
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
57
|
// ─── Main emitter ─────────────────────────────────────────────────────────────
|
|
61
58
|
|
|
62
59
|
export function emitOpenApiSchema(system: IR.IRSystem): string {
|
package/src/emit_package.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as IR from "./ir";
|
|
7
|
-
|
|
8
|
-
function toSnakeCase(s: string): string {
|
|
9
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
10
|
-
}
|
|
7
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
11
8
|
|
|
12
9
|
export function emitPackageJson(system: IR.IRSystem): string {
|
|
13
10
|
const pkg = {
|
package/src/emit_router.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as IR from "./ir";
|
|
8
8
|
import { emitCapabilityBody } from "./emit_capability";
|
|
9
|
+
import { emitPipelineBody, emitAlgorithmBody } from "./emit_composition";
|
|
9
10
|
|
|
10
11
|
// ─── Shared helpers ───────────────────────────────────────────────────────────
|
|
11
12
|
|
|
@@ -361,10 +362,8 @@ export function emitCapabilityEndpoint(
|
|
|
361
362
|
}
|
|
362
363
|
|
|
363
364
|
if (method.pipeline) {
|
|
364
|
-
const { emitPipelineBody } = require("./emit_composition");
|
|
365
365
|
lines.push(emitPipelineBody(method, " "));
|
|
366
366
|
} else if (method.algorithm) {
|
|
367
|
-
const { emitAlgorithmBody } = require("./emit_composition");
|
|
368
367
|
lines.push(emitAlgorithmBody(method, " "));
|
|
369
368
|
} else {
|
|
370
369
|
lines.push(emitCapabilityBody(method, mod, system, " "));
|
package/src/emit_tests.ts
CHANGED
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import * as IR from "./ir";
|
|
16
|
-
|
|
17
|
-
function toSnakeCase(s: string): string {
|
|
18
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
19
|
-
}
|
|
16
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
20
17
|
|
|
21
18
|
export function emitTestSuite(system: IR.IRSystem): string {
|
|
22
19
|
const lines: string[] = [];
|
package/src/emit_websocket.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as IR from "./ir";
|
|
7
|
-
|
|
8
|
-
function toSnakeCase(s: string): string {
|
|
9
|
-
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
10
|
-
}
|
|
7
|
+
import { toSnakeCase } from "./lowering_helpers";
|
|
11
8
|
|
|
12
9
|
function toCamelCase(s: string): string {
|
|
13
10
|
return s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|