bimdown-cli 0.3.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/chunk-4SKM4RHY.js +142 -0
- package/dist/chunk-4SKM4RHY.js.map +1 -0
- package/dist/chunk-4YHVOWS4.js +255 -0
- package/dist/chunk-4YHVOWS4.js.map +1 -0
- package/dist/chunk-AYAXRYGP.js +2129 -0
- package/dist/chunk-AYAXRYGP.js.map +1 -0
- package/dist/chunk-EC5MR5ZH.js +648 -0
- package/dist/chunk-EC5MR5ZH.js.map +1 -0
- package/dist/chunk-HS3PO2LB.js +487 -0
- package/dist/chunk-HS3PO2LB.js.map +1 -0
- package/dist/chunk-IQJA3EFO.js +179 -0
- package/dist/chunk-IQJA3EFO.js.map +1 -0
- package/dist/chunk-JY6KWRDB.js +80 -0
- package/dist/chunk-JY6KWRDB.js.map +1 -0
- package/dist/chunk-KWSGJUMZ.js +2501 -0
- package/dist/chunk-KWSGJUMZ.js.map +1 -0
- package/dist/chunk-LWYIPR64.js +35 -0
- package/dist/chunk-LWYIPR64.js.map +1 -0
- package/dist/chunk-OBY3UYCO.js +44 -0
- package/dist/chunk-OBY3UYCO.js.map +1 -0
- package/dist/chunk-XC6WHJRL.js +29 -0
- package/dist/chunk-XC6WHJRL.js.map +1 -0
- package/dist/chunk-XQU52JKB.js +187 -0
- package/dist/chunk-XQU52JKB.js.map +1 -0
- package/dist/clash-load-D3LNQR6G.js +941 -0
- package/dist/clash-load-D3LNQR6G.js.map +1 -0
- package/dist/cli.js +431 -0
- package/dist/cli.js.map +1 -0
- package/dist/dehydrate-ZHAGOI7Q.js +90 -0
- package/dist/dehydrate-ZHAGOI7Q.js.map +1 -0
- package/dist/diff-T2KOK2WR.js +89 -0
- package/dist/diff-T2KOK2WR.js.map +1 -0
- package/dist/engine-2TPWJVEQ.js +12 -0
- package/dist/engine-2TPWJVEQ.js.map +1 -0
- package/dist/hydrate-V24H7IF3.js +673 -0
- package/dist/hydrate-V24H7IF3.js.map +1 -0
- package/dist/import-ifc-RCZSXDA6.js +5324 -0
- package/dist/import-ifc-RCZSXDA6.js.map +1 -0
- package/dist/info-QC7YXWNX.js +92 -0
- package/dist/info-QC7YXWNX.js.map +1 -0
- package/dist/init-VWDML3UC.js +112 -0
- package/dist/init-VWDML3UC.js.map +1 -0
- package/dist/lib.d.ts +492 -0
- package/dist/lib.js +6528 -0
- package/dist/lib.js.map +1 -0
- package/dist/mep-W4HJI363.js +25 -0
- package/dist/mep-W4HJI363.js.map +1 -0
- package/dist/merge-ESOPDSA5.js +413 -0
- package/dist/merge-ESOPDSA5.js.map +1 -0
- package/dist/publish-3TAXQCUV.js +80 -0
- package/dist/publish-3TAXQCUV.js.map +1 -0
- package/dist/render-UEWYHPN6.js +1807 -0
- package/dist/render-UEWYHPN6.js.map +1 -0
- package/dist/resolve-topology-AQ2RO3W3.js +338 -0
- package/dist/resolve-topology-AQ2RO3W3.js.map +1 -0
- package/dist/spec/csv-schema/annotation/dimension.yaml +77 -0
- package/dist/spec/csv-schema/annotation/tag.yaml +44 -0
- package/dist/spec/csv-schema/annotation/text_note.yaml +52 -0
- package/dist/spec/csv-schema/architecture/ceiling.yaml +8 -1
- package/dist/spec/csv-schema/architecture/column.yaml +5 -1
- package/dist/spec/csv-schema/architecture/curtain_wall.yaml +45 -5
- package/dist/spec/csv-schema/architecture/door.yaml +5 -0
- package/dist/spec/csv-schema/architecture/furniture.yaml +28 -0
- package/dist/spec/csv-schema/architecture/opening.yaml +27 -6
- package/dist/spec/csv-schema/architecture/railing.yaml +35 -0
- package/dist/spec/csv-schema/architecture/roof.yaml +34 -1
- package/dist/spec/csv-schema/architecture/slab.yaml +19 -0
- package/dist/spec/csv-schema/architecture/space.yaml +11 -1
- package/dist/spec/csv-schema/architecture/stair.yaml +49 -0
- package/dist/spec/csv-schema/architecture/stair_landing.yaml +36 -0
- package/dist/spec/csv-schema/architecture/stair_run.yaml +31 -0
- package/dist/spec/csv-schema/architecture/wall.yaml +14 -1
- package/dist/spec/csv-schema/architecture/window.yaml +19 -0
- package/dist/spec/csv-schema/base/element.yaml +20 -11
- package/dist/spec/csv-schema/base/furniture_params.yaml +60 -0
- package/dist/spec/csv-schema/base/hosted_element.yaml +10 -2
- package/dist/spec/csv-schema/base/mep_connectable.yaml +23 -0
- package/dist/spec/csv-schema/base/mep_design.yaml +24 -0
- package/dist/spec/csv-schema/base/mep_insulated.yaml +9 -0
- package/dist/spec/csv-schema/base/mep_system_tag.yaml +12 -0
- package/dist/spec/csv-schema/base/point_element.yaml +1 -0
- package/dist/spec/csv-schema/base/section_profile.yaml +5 -0
- package/dist/spec/csv-schema/base/spatial_line_element.yaml +4 -2
- package/dist/spec/csv-schema/base/structural_section_profile.yaml +50 -0
- package/dist/spec/csv-schema/base/vertical_span.yaml +9 -3
- package/dist/spec/csv-schema/base/wall_bounded.yaml +21 -0
- package/dist/spec/csv-schema/grid.yaml +5 -0
- package/dist/spec/csv-schema/mep/cable_tray.yaml +10 -3
- package/dist/spec/csv-schema/mep/circuit.yaml +70 -0
- package/dist/spec/csv-schema/mep/conduit.yaml +2 -2
- package/dist/spec/csv-schema/mep/connector.yaml +112 -0
- package/dist/spec/csv-schema/mep/duct.yaml +10 -3
- package/dist/spec/csv-schema/mep/equipment.yaml +18 -1
- package/dist/spec/csv-schema/mep/mep_node.yaml +91 -2
- package/dist/spec/csv-schema/mep/mep_system.yaml +21 -0
- package/dist/spec/csv-schema/mep/pipe.yaml +27 -3
- package/dist/spec/csv-schema/mep/terminal.yaml +22 -1
- package/dist/spec/csv-schema/model_group.yaml +40 -0
- package/dist/spec/csv-schema/sheet/sheet.yaml +50 -0
- package/dist/spec/csv-schema/sheet/sheet_viewport.yaml +86 -0
- package/dist/spec/csv-schema/structure/beam.yaml +29 -1
- package/dist/spec/csv-schema/structure/beam_system.yaml +29 -0
- package/dist/spec/csv-schema/structure/brace.yaml +24 -1
- package/dist/spec/csv-schema/structure/foundation.yaml +40 -7
- package/dist/spec/csv-schema/structure/structure_column.yaml +19 -1
- package/dist/spec/csv-schema/structure/structure_slab.yaml +32 -0
- package/dist/spec/csv-schema/structure/structure_wall.yaml +22 -0
- package/dist/spec/csv-schema/types/beam_type.yaml +11 -0
- package/dist/spec/csv-schema/types/ceiling_type.yaml +6 -0
- package/dist/spec/csv-schema/types/column_type.yaml +12 -0
- package/dist/spec/csv-schema/types/curtain_wall_type.yaml +32 -0
- package/dist/spec/csv-schema/types/door_type.yaml +27 -0
- package/dist/spec/csv-schema/types/element_type.yaml +21 -0
- package/dist/spec/csv-schema/types/fenestration.yaml +16 -0
- package/dist/spec/csv-schema/types/foundation_type.yaml +36 -0
- package/dist/spec/csv-schema/types/furniture_type.yaml +11 -0
- package/dist/spec/csv-schema/types/layered_type.yaml +13 -0
- package/dist/spec/csv-schema/types/railing_type.yaml +40 -0
- package/dist/spec/csv-schema/types/roof_type.yaml +7 -0
- package/dist/spec/csv-schema/types/slab_type.yaml +9 -0
- package/dist/spec/csv-schema/types/type_layer.yaml +47 -0
- package/dist/spec/csv-schema/types/wall_type.yaml +6 -0
- package/dist/spec/csv-schema/types/window_type.yaml +31 -0
- package/dist/spec/csv-schema/underlay.yaml +73 -0
- package/dist/spec/csv-schema/view.yaml +36 -0
- package/dist/spec/duckdb-strategy.md +4 -3
- package/dist/spec/geojson-schema/readme.md +380 -0
- package/dist/spec/mep-port-conventions.md +190 -0
- package/dist/spec/migration-guide.md +1 -1
- package/dist/spec/project_metadata.schema.yaml +52 -4
- package/dist/spec/readme.md +356 -97
- package/dist/spec/starter-types/global/beam_type.csv +5 -0
- package/dist/spec/starter-types/global/ceiling_type.csv +3 -0
- package/dist/spec/starter-types/global/column_type.csv +5 -0
- package/dist/spec/starter-types/global/curtain_wall_type.csv +2 -0
- package/dist/spec/starter-types/global/door_type.csv +6 -0
- package/dist/spec/starter-types/global/foundation_type.csv +7 -0
- package/dist/spec/starter-types/global/furniture_type.csv +11 -0
- package/dist/spec/starter-types/global/railing_type.csv +5 -0
- package/dist/spec/starter-types/global/roof_type.csv +3 -0
- package/dist/spec/starter-types/global/slab_type.csv +4 -0
- package/dist/spec/starter-types/global/type_layer.csv +40 -0
- package/dist/spec/starter-types/global/wall_type.csv +8 -0
- package/dist/spec/starter-types/global/window_type.csv +6 -0
- package/dist/spec/svg-schema/readme.md +47 -1
- package/package.json +17 -5
- package/dist/index.js +0 -3366
- package/dist/index.js.map +0 -1
- package/dist/spec/csv-schema/base/mep_connected_segment.yaml +0 -17
- package/dist/spec/csv-schema/base/mep_system.yaml +0 -7
package/dist/cli.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
build,
|
|
4
|
+
validateOnly
|
|
5
|
+
} from "./chunk-KWSGJUMZ.js";
|
|
6
|
+
import {
|
|
7
|
+
CATEGORY_LABELS,
|
|
8
|
+
CATEGORY_ORDER,
|
|
9
|
+
furnitureFamilies
|
|
10
|
+
} from "./chunk-AYAXRYGP.js";
|
|
11
|
+
import "./chunk-LWYIPR64.js";
|
|
12
|
+
import {
|
|
13
|
+
typeParamFields
|
|
14
|
+
} from "./chunk-XQU52JKB.js";
|
|
15
|
+
import "./chunk-EC5MR5ZH.js";
|
|
16
|
+
import "./chunk-IQJA3EFO.js";
|
|
17
|
+
import "./chunk-4SKM4RHY.js";
|
|
18
|
+
import {
|
|
19
|
+
buildRegistry,
|
|
20
|
+
getSpecDir
|
|
21
|
+
} from "./chunk-4YHVOWS4.js";
|
|
22
|
+
import "./chunk-JY6KWRDB.js";
|
|
23
|
+
import {
|
|
24
|
+
discoverLayout
|
|
25
|
+
} from "./chunk-OBY3UYCO.js";
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
import { Command } from "commander";
|
|
29
|
+
import { resolve } from "path";
|
|
30
|
+
|
|
31
|
+
// src/furniture/catalog-text.ts
|
|
32
|
+
var size = (s) => s.map((v) => +v.toFixed(3)).join("\xD7");
|
|
33
|
+
function furnitureCatalogLines() {
|
|
34
|
+
const lines = [" Families (default size_x\xD7size_y\xD7height m; variants with their own default size):"];
|
|
35
|
+
for (const cat of CATEGORY_ORDER) {
|
|
36
|
+
const fams = furnitureFamilies().filter((f) => f.category === cat);
|
|
37
|
+
if (fams.length === 0) continue;
|
|
38
|
+
lines.push(` ${CATEGORY_LABELS[cat].en}:`);
|
|
39
|
+
for (const f of fams) {
|
|
40
|
+
const tags = [];
|
|
41
|
+
if (f.wallBacked) tags.push("back to wall");
|
|
42
|
+
if (f.baseOffset) tags.push(`base_offset ${f.baseOffset}`);
|
|
43
|
+
const variants = (f.variants ?? []).map((v, i) => `${v.id}${v.size ? ` ${size(v.size)}` : ""}${i === 0 ? " (default)" : ""}`);
|
|
44
|
+
lines.push(` ${f.id} ${size(f.size)}${tags.length ? ` [${tags.join(", ")}]` : ""}${variants.length ? ` variants: ${variants.join(", ")}` : ""}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/schema/schema-text.ts
|
|
51
|
+
var INDEX = [
|
|
52
|
+
["Project (global/)", [
|
|
53
|
+
["level", "storey: number, elevation (absolute)"],
|
|
54
|
+
["grid", "axis line: number, start/end x y"],
|
|
55
|
+
["view", "section / elevation / 3D view: view_type, cut line"],
|
|
56
|
+
["underlay", "tracing image / PDF under a level: level_id, file"],
|
|
57
|
+
["mesh", "imported GLB: category, mesh_file"],
|
|
58
|
+
["sheet", "drawing sheet: number, paper"],
|
|
59
|
+
["sheet_viewport", "view placed on a sheet: sheet_id, view_type, x y"]
|
|
60
|
+
]],
|
|
61
|
+
["Architecture", [
|
|
62
|
+
["wall", "line: thickness, type_id, base_offset/top_level_id/top_offset"],
|
|
63
|
+
["curtain_wall", "line: u/v grids, panels, mullions"],
|
|
64
|
+
["column", "point: shape, size_x/size_y"],
|
|
65
|
+
["slab", "polygon floor, top = level + base_offset: thickness"],
|
|
66
|
+
["roof", "polygon: roof_type (flat/gable/hip...), slope"],
|
|
67
|
+
["ceiling", "polygon: height_offset"],
|
|
68
|
+
["space", "room seed point: x y, name; boundary computed"],
|
|
69
|
+
["room_separator", "line splitting rooms without a wall"],
|
|
70
|
+
["door", "hosted on a wall: host_id, position, width, height"],
|
|
71
|
+
["window", "hosted on a wall: host_id, position, width, height, base_offset (sill)"],
|
|
72
|
+
["opening", "void in a wall / slab / roof"],
|
|
73
|
+
["stair", "stair container (3D); parts below"],
|
|
74
|
+
["stair_run", "flight of steps: host_id (stair)"],
|
|
75
|
+
["stair_landing", "landing: host_id (stair)"],
|
|
76
|
+
["ramp", "3D line (start_z/end_z): width"],
|
|
77
|
+
["railing", "3D path or hosted on stair / slab edge"],
|
|
78
|
+
["furniture", "library component (point): family, variant, rotation"]
|
|
79
|
+
]],
|
|
80
|
+
["Structure", [
|
|
81
|
+
["structure_wall", "line: thickness"],
|
|
82
|
+
["structure_column", "point: shape, size_x/size_y or designation"],
|
|
83
|
+
["structure_slab", "polygon, top = level + base_offset: thickness"],
|
|
84
|
+
["beam", "3D line (absolute z = top): shape, size_x, size_y"],
|
|
85
|
+
["beam_system", "parallel infill beams in a bay: spacing"],
|
|
86
|
+
["brace", "3D line: shape"],
|
|
87
|
+
["foundation", "pad / pile / strip / raft / pile cap: kind, thickness"]
|
|
88
|
+
]],
|
|
89
|
+
["MEP", [
|
|
90
|
+
["duct", "3D line: shape, size_x/size_y, system_type, from/to"],
|
|
91
|
+
["pipe", "3D line: shape, size_x (diameter), system_type"],
|
|
92
|
+
["cable_tray", "3D line: size_x/size_y, system_type"],
|
|
93
|
+
["conduit", "3D line: size_x (diameter)"],
|
|
94
|
+
["equipment", "point: equipment_type (AHU, pump, panel...); ports in connector"],
|
|
95
|
+
["terminal", "point: terminal_type (diffuser, sink, WC, light...)"],
|
|
96
|
+
["mep_node", "elbow / tee / fitting joining runs: kind"],
|
|
97
|
+
["connector", "port on equipment / terminal / mep_node: host_id, name"],
|
|
98
|
+
["mep_system", "system lookup: system_type"],
|
|
99
|
+
["circuit", "electrical circuit from a panel: host_id"]
|
|
100
|
+
]],
|
|
101
|
+
["Types (global/; instances use type_id)", [
|
|
102
|
+
["wall_type", "layers in type_layer"],
|
|
103
|
+
["slab_type", "layered"],
|
|
104
|
+
["roof_type", "layered"],
|
|
105
|
+
["ceiling_type", "layered"],
|
|
106
|
+
["type_layer", "one layer: type_id, seq, function, thickness"],
|
|
107
|
+
["door_type", "width, height, operation"],
|
|
108
|
+
["window_type", "width, height, operation, u_value"],
|
|
109
|
+
["curtain_wall_type", "u/v spacing, mullions"],
|
|
110
|
+
["column_type", "shape, sizes"],
|
|
111
|
+
["beam_type", "shape, sizes"],
|
|
112
|
+
["foundation_type", "kind, sizes"],
|
|
113
|
+
["furniture_type", "family, variant, sizes"],
|
|
114
|
+
["railing_type", "height, rails, infill"]
|
|
115
|
+
]],
|
|
116
|
+
["Annotation (level dirs)", [
|
|
117
|
+
["dimension", "linear dimension: start/end x y"],
|
|
118
|
+
["text_note", "text at x y"],
|
|
119
|
+
["tag", "label of an element: host_id"],
|
|
120
|
+
["model_group", "group instance: name, x y"]
|
|
121
|
+
]]
|
|
122
|
+
];
|
|
123
|
+
function schemaIndexLines(registry) {
|
|
124
|
+
const lines = ["Tables. Run `schema <table>` for exact columns, types, enums, references."];
|
|
125
|
+
const seen = /* @__PURE__ */ new Set();
|
|
126
|
+
for (const [group, tables] of INDEX) {
|
|
127
|
+
const present = tables.filter(([t]) => registry.has(t));
|
|
128
|
+
if (present.length === 0) continue;
|
|
129
|
+
lines.push(`${group}:`);
|
|
130
|
+
for (const [t, purpose] of present) {
|
|
131
|
+
seen.add(t);
|
|
132
|
+
lines.push(` ${t}: ${purpose}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const other = [...registry.keys()].filter((t) => !seen.has(t)).sort();
|
|
136
|
+
if (other.length > 0) lines.push(`Other: ${other.join(", ")}`);
|
|
137
|
+
return lines;
|
|
138
|
+
}
|
|
139
|
+
function schemaTableLines(resolved) {
|
|
140
|
+
const t = resolved.name;
|
|
141
|
+
const lines = [`\u2500\u2500 ${t} (prefix: ${resolved.prefix}) \u2500\u2500`];
|
|
142
|
+
if (resolved.hostType) lines.push(` host_type: ${resolved.hostType}`);
|
|
143
|
+
if (resolved.typeOf) {
|
|
144
|
+
lines.push(` type of: ${resolved.typeOf.join(", ")} (global/ only; instances inherit shared fields they leave empty)`);
|
|
145
|
+
}
|
|
146
|
+
if (resolved.typeTable) lines.push(` type_id \u2192 ${resolved.typeTable}: empty shared fields inherit the type's values`);
|
|
147
|
+
const typeParams = new Set(resolved.typeTable ? typeParamFields(t) : []);
|
|
148
|
+
lines.push(" CSV fields:");
|
|
149
|
+
for (const f of resolved.csvFields) {
|
|
150
|
+
const tags = [];
|
|
151
|
+
if (f.required) tags.push(typeParams.has(f.name) ? "required unless type_id gives it" : "required");
|
|
152
|
+
if (f.type === "reference") tags.push(`ref:${f.reference}`);
|
|
153
|
+
if (f.type === "enum") tags.push(`enum:[${f.values?.join("|")}]`);
|
|
154
|
+
lines.push(` ${f.name}: ${f.type}${tags.length > 0 ? ` (${tags.join(", ")})` : ""}`);
|
|
155
|
+
}
|
|
156
|
+
if (resolved.computedFields.length > 0) {
|
|
157
|
+
lines.push(" Computed fields (derived from geometry; queryable, never written to CSV):");
|
|
158
|
+
for (const f of resolved.computedFields) lines.push(` ${f.name}: ${f.type}`);
|
|
159
|
+
}
|
|
160
|
+
if (t === "furniture") lines.push(...furnitureCatalogLines());
|
|
161
|
+
return lines;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/index.ts
|
|
165
|
+
import { existsSync, writeFileSync } from "fs";
|
|
166
|
+
var program = new Command();
|
|
167
|
+
program.name("bimdown").description("BimDown CLI \u2014 build, query, and manage BimDown projects").version(true ? "0.5.1" : "0.0.0");
|
|
168
|
+
var WARN_LIST_LIMIT = 20;
|
|
169
|
+
function runBuild(dir, opts = {}, readOnly = false) {
|
|
170
|
+
const absDir = resolve(dir);
|
|
171
|
+
const result = readOnly ? validateOnly(absDir) : build(absDir);
|
|
172
|
+
if (result.issues.length > 0) {
|
|
173
|
+
for (const issue of result.issues) {
|
|
174
|
+
console.log(issue);
|
|
175
|
+
}
|
|
176
|
+
console.log(`
|
|
177
|
+
${result.issues.length} issue(s) found.`);
|
|
178
|
+
process.exitCode = 1;
|
|
179
|
+
}
|
|
180
|
+
if (result.warnings.length > 0) {
|
|
181
|
+
const shown = opts.verbose ? result.warnings : result.warnings.slice(0, WARN_LIST_LIMIT);
|
|
182
|
+
for (const w of shown) {
|
|
183
|
+
console.log(w);
|
|
184
|
+
}
|
|
185
|
+
if (shown.length < result.warnings.length) {
|
|
186
|
+
console.log(`... ${result.warnings.length - shown.length} more (use --verbose to list all)`);
|
|
187
|
+
}
|
|
188
|
+
console.log(`
|
|
189
|
+
${result.warnings.length} warning(s). Warnings are advisory; issues are errors.`);
|
|
190
|
+
}
|
|
191
|
+
if (result.roomIssues.length > 0) {
|
|
192
|
+
const label = { shared: "share one enclosed area", contains: "encloses", unbounded: "has no enclosing boundary" };
|
|
193
|
+
console.log(`
|
|
194
|
+
Room problems (${result.roomIssues.length}): derived room areas are wrong until fixed`);
|
|
195
|
+
const shown = opts.verbose ? result.roomIssues : result.roomIssues.slice(0, WARN_LIST_LIMIT);
|
|
196
|
+
for (const r of shown) {
|
|
197
|
+
const text = r.kind === "contains" ? `${r.spaceIds.join(", ")} ${label.contains} ${(r.inside ?? []).join(", ")}` : `${r.spaceIds.join(", ")} ${label[r.kind]}`;
|
|
198
|
+
console.log(` ${r.level}: ${text}`);
|
|
199
|
+
}
|
|
200
|
+
if (shown.length < result.roomIssues.length) {
|
|
201
|
+
console.log(` ... ${result.roomIssues.length - shown.length} more (use --verbose to list all)`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (result.snaps.length > 0) {
|
|
205
|
+
console.log(readOnly ? `${result.snaps.length} endpoint(s) closer than 5 cm (build snaps them):` : `Snapped ${result.snaps.length} endpoint(s) closer than 5 cm:`);
|
|
206
|
+
const shown = opts.verbose ? result.snaps : result.snaps.slice(0, WARN_LIST_LIMIT);
|
|
207
|
+
for (const s of shown) {
|
|
208
|
+
console.log(` ${s.level}/${s.table} ${s.elementId} ${s.side} (${s.from.x.toFixed(3)}, ${s.from.y.toFixed(3)}) -> (${s.to.x.toFixed(3)}, ${s.to.y.toFixed(3)})`);
|
|
209
|
+
}
|
|
210
|
+
if (shown.length < result.snaps.length) console.log(` ... ${result.snaps.length - shown.length} more`);
|
|
211
|
+
}
|
|
212
|
+
if (result.hints.length > 0) {
|
|
213
|
+
console.log();
|
|
214
|
+
for (const h of result.hints) console.log(h);
|
|
215
|
+
}
|
|
216
|
+
if (result.artifacts.length > 0 && !readOnly) {
|
|
217
|
+
console.log(`
|
|
218
|
+
Generated: ${result.artifacts.join(", ")}`);
|
|
219
|
+
}
|
|
220
|
+
if (result.issues.length === 0 && result.warnings.length === 0) {
|
|
221
|
+
console.log("Build successful. No issues found.");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
program.command("build").argument("<dir>", "BimDown project directory").option("--verbose", "List every warning and snapped endpoint").description("Build a BimDown project (validate + compute space boundaries)").action((dir, opts) => runBuild(dir, opts));
|
|
225
|
+
program.command("validate").argument("<dir>", "BimDown project directory").option("--verbose", "List every warning and snapped endpoint").description("Check a BimDown project like build, without writing anything").action((dir, opts) => runBuild(dir, opts, true));
|
|
226
|
+
program.command("query").argument("<dir>", "BimDown project directory").argument("<sql>", "SQL query to execute").option("--json", "Output results as JSON").description("Hydrate into DuckDB and execute a SQL query").action(async (dir, sql, opts) => {
|
|
227
|
+
const absDir = resolve(dir);
|
|
228
|
+
const { getConnection, runQuery, closeConnection } = await import("./engine-2TPWJVEQ.js");
|
|
229
|
+
const { hydrate } = await import("./hydrate-V24H7IF3.js");
|
|
230
|
+
const conn = await getConnection();
|
|
231
|
+
try {
|
|
232
|
+
await hydrate(conn, absDir);
|
|
233
|
+
const result = await runQuery(conn, sql);
|
|
234
|
+
if (opts.json) {
|
|
235
|
+
console.log(JSON.stringify(result.rows, jsonReplacer, 2));
|
|
236
|
+
} else {
|
|
237
|
+
printTable(result.columns, result.rows);
|
|
238
|
+
}
|
|
239
|
+
} finally {
|
|
240
|
+
await closeConnection();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
program.command("sync").argument("<dir>", "BimDown project directory").description("Hydrate, then dehydrate back (sync DuckDB changes to files)").action(async (dir) => {
|
|
244
|
+
const absDir = resolve(dir);
|
|
245
|
+
const { getConnection, closeConnection } = await import("./engine-2TPWJVEQ.js");
|
|
246
|
+
const { hydrate } = await import("./hydrate-V24H7IF3.js");
|
|
247
|
+
const { dehydrate } = await import("./dehydrate-ZHAGOI7Q.js");
|
|
248
|
+
const conn = await getConnection();
|
|
249
|
+
try {
|
|
250
|
+
const tables = await hydrate(conn, absDir);
|
|
251
|
+
console.log(`Hydrated ${tables.length} tables: ${tables.join(", ")}`);
|
|
252
|
+
await dehydrate(conn, absDir);
|
|
253
|
+
console.log("Sync complete \u2014 files updated.");
|
|
254
|
+
} finally {
|
|
255
|
+
await closeConnection();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
program.command("render").argument("<dir>", "BimDown project directory").option("-l, --level <id>", "Level to render (defaults to lv-1)", "lv-1").option("-o, --output <file>", "Output file path (defaults to render.png)", "render.png").option("-w, --width <px>", "Image width in pixels", "2048").description("Renders the BimDown project into a visual blueprint (PNG). Color legend: walls=dark navy, structural walls=slate, columns=dark filled, slabs=light grey translucent (sloped floors with their slope arrow, tail dot \u2192 head), spaces=blue translucent, stairs=orange runs with treads (dashed beyond the 1.2 m plan cut), landings and an UP walking line (multi-storey stairs also on the storeys they repeat on), railings=slate lines (stair railings follow the derived path), beams/braces=thin purple dashed centerlines (overhead, drawn under walls), columns at their real section size, foundations=brown dashed outlines (pads width\xD7length, piles as circles, strips at their width, rafts/pile caps), grids=red dash-dot axes with numbered bubbles, roofs=brown outline with ridges and hips (valleys dashed) and down-slope arrows labelled with the slope, slab holes and slab openings (white with a cross; shafts also on every level they cross), wall openings=orange lines, curtain walls=light blue strips with a tick per vertical grid line (door panels open, with red swings). DOORS render as BOLD RED (#e63946) lines and WINDOWS as BOLD TEAL (#2a9d8f) lines cutting across their host walls. MEP: runs at their real width in system colours (SA blue, RA light blue, CHWS cyan, SAN brown, FP red, \u2026) with elbow / tee / reducer bodies, system + size tags, rise / drop boxes, slope arrows; terminals, equipment and valves as plan symbols. Furniture and library components draw their grey plan symbols (back edge = local +Y). Annotations (dimension/text_note/tag tables) in dark blue: dimension lines with values in mm (ft-in for imperial), text, boxed door/window tags, room tags with name/number/area.").action(async (dir, opts) => {
|
|
259
|
+
const absDir = resolve(dir);
|
|
260
|
+
const { renderLevel } = await import("./render-UEWYHPN6.js");
|
|
261
|
+
try {
|
|
262
|
+
const svg = renderLevel(absDir, opts.level);
|
|
263
|
+
if (opts.output.endsWith(".svg")) {
|
|
264
|
+
writeFileSync(opts.output, svg);
|
|
265
|
+
} else {
|
|
266
|
+
const sharp = (await import("sharp")).default;
|
|
267
|
+
const width = parseInt(opts.width, 10) || 2048;
|
|
268
|
+
await sharp(Buffer.from(svg)).resize({ width }).png().toFile(opts.output);
|
|
269
|
+
}
|
|
270
|
+
console.log(`Rendered ${opts.level} to ${opts.output}`);
|
|
271
|
+
} catch (err) {
|
|
272
|
+
console.error(`Render failed: ${err.message}`);
|
|
273
|
+
process.exitCode = 1;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
program.command("info").argument("<dir>", "BimDown project directory").description("Print project summary: units, levels, element counts, element types").action(async (dir) => {
|
|
277
|
+
const { projectInfoLines } = await import("./info-QC7YXWNX.js");
|
|
278
|
+
for (const l of projectInfoLines(resolve(dir))) console.log(l);
|
|
279
|
+
});
|
|
280
|
+
program.command("resolve-topology").argument("<dir>", "BimDown project directory").description("Auto-resolve MEP topology: detect coincident endpoints, generate mep_nodes, fill connectivity").action(async (dir) => {
|
|
281
|
+
const absDir = resolve(dir);
|
|
282
|
+
const { resolveTopology } = await import("./resolve-topology-AQ2RO3W3.js");
|
|
283
|
+
resolveTopology(absDir);
|
|
284
|
+
});
|
|
285
|
+
program.command("mep-check").argument("<dir>", "BimDown project directory").option("--json", "Print the report as JSON").option("--all", "Also list info-level findings (unused equipment ports, devices without a circuit)").description("MEP connectivity check: systems (curves, length, devices) and problems \u2014 open ends, port refs that do not resolve or whose curve end is not on the port, system / domain mismatches, disconnected devices, orphan fittings, overloaded circuits. Exit code 1 when there are warnings.").action(async (dir, opts) => {
|
|
286
|
+
const { mepReport, formatProblem } = await import("./mep-W4HJI363.js");
|
|
287
|
+
const report = mepReport(resolve(dir));
|
|
288
|
+
const shown = opts.all ? report.problems : report.problems.filter((p) => p.severity === "warning");
|
|
289
|
+
if (opts.json) {
|
|
290
|
+
console.log(JSON.stringify({ systems: report.systems, problems: shown }, null, 2));
|
|
291
|
+
} else {
|
|
292
|
+
console.log("Systems:");
|
|
293
|
+
if (report.systems.length === 0) console.log(" (no MEP curves)");
|
|
294
|
+
for (const s of report.systems) {
|
|
295
|
+
console.log(` ${s.system.padEnd(8)} ${String(s.curves).padStart(4)} curve(s) ${s.length.toFixed(1).padStart(7)} long ${s.devices} device(s) [${s.tables.join(", ")}]`);
|
|
296
|
+
}
|
|
297
|
+
console.log();
|
|
298
|
+
for (const p of shown) console.log(`${p.severity === "info" ? "info " : ""}${formatProblem(p)}`);
|
|
299
|
+
const warnings = report.problems.filter((p) => p.severity === "warning").length;
|
|
300
|
+
console.log(warnings === 0 ? "MEP connectivity: no problems." : `
|
|
301
|
+
${warnings} connectivity problem(s).`);
|
|
302
|
+
}
|
|
303
|
+
if (report.problems.some((p) => p.severity === "warning")) process.exitCode = 1;
|
|
304
|
+
});
|
|
305
|
+
function parseLengthM(s, bareM) {
|
|
306
|
+
const m = /^\s*([0-9]*\.?[0-9]+(?:e[-+]?\d+)?)\s*(mm|cm|m)?\s*$/i.exec(s);
|
|
307
|
+
if (!m) return null;
|
|
308
|
+
const v = Number(m[1]) * (m[2] ? { mm: 1e-3, cm: 0.01, m: 1 }[m[2].toLowerCase()] : bareM);
|
|
309
|
+
return Number.isFinite(v) && v >= 0 ? v : null;
|
|
310
|
+
}
|
|
311
|
+
program.command("clash").argument("<dir>", "BimDown project directory").option("--tolerance <m>", "Overlaps no deeper than this are within tolerance, not clashes: metres, or with a unit (50mm, 5cm); 0 = every overlap", "0.05").option("--clearance <mm>", "Also report MEP closer than this to MEP / structure without touching: mm, or with a unit (0 = off)", "0").option("--minor", "Also list the overlaps within tolerance").option("--level <id>", "Only MEP on this level (obstacles from every level)").option("--json", "Print the report as JSON").option("--mep-only", "Only MEP vs MEP").description("MEP clash detection: ducts / pipes / conduits / cable trays and devices against structure (high), against other MEP they do not connect to (medium), through slabs / roofs / non-structural walls with no opening (low penetration), and closer than --clearance (low). Overlaps up to --tolerance (5 cm) are modelling slack, not clashes. Exit code 0 unless the project cannot be read.").action(async (dir, opts) => {
|
|
312
|
+
const absDir = resolve(dir);
|
|
313
|
+
const tolerance = parseLengthM(opts.tolerance, 1), clearance = parseLengthM(opts.clearance, 1e-3);
|
|
314
|
+
if (!existsSync(absDir)) {
|
|
315
|
+
console.error(`No such directory: ${dir}`);
|
|
316
|
+
process.exitCode = 1;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (tolerance === null || clearance === null) {
|
|
320
|
+
console.error("--tolerance takes a length in metres, --clearance in mm (>= 0; or with a unit: 50mm, 5cm, 0.05m)");
|
|
321
|
+
process.exitCode = 1;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (tolerance > 1 && !/[a-z]$/i.test(opts.tolerance.trim())) {
|
|
325
|
+
console.error(`--tolerance is in metres (0.05 = 5 cm); for millimetres write ${opts.tolerance}mm`);
|
|
326
|
+
process.exitCode = 1;
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (opts.level && !discoverLayout(absDir).levelDirs.some((d) => d.name === opts.level) && opts.level !== "global") {
|
|
330
|
+
console.error(`No level directory ${opts.level} in ${dir}`);
|
|
331
|
+
process.exitCode = 1;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const { clashReport, formatClashReport } = await import("./clash-load-D3LNQR6G.js");
|
|
335
|
+
const report = clashReport(absDir, { toleranceM: tolerance, clearanceMm: clearance * 1e3, level: opts.level, mepOnly: opts.mepOnly, minor: opts.minor });
|
|
336
|
+
if (opts.json) console.log(JSON.stringify(report, null, 2));
|
|
337
|
+
else for (const line of formatClashReport(report)) console.log(line);
|
|
338
|
+
});
|
|
339
|
+
program.command("merge").argument("<dirs...>", "Two or more BimDown project directories to merge").requiredOption("-o, --output <dir>", "Output directory for merged project").description("Merge multiple BimDown project directories into one, resolving ID conflicts").action(async (dirs, opts) => {
|
|
340
|
+
if (dirs.length < 2) {
|
|
341
|
+
console.error("At least 2 source directories are required.");
|
|
342
|
+
process.exitCode = 1;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const absDirs = dirs.map((d) => resolve(d));
|
|
346
|
+
const absOut = resolve(opts.output);
|
|
347
|
+
const { merge } = await import("./merge-ESOPDSA5.js");
|
|
348
|
+
await merge(absDirs, absOut);
|
|
349
|
+
});
|
|
350
|
+
program.command("schema").argument("[table]", "Table name (omit for a compact index of all tables)").option("--all", "Print the full schema of every table (long)").description("Print the full schema of a table, or an index of all tables").action((table, opts) => {
|
|
351
|
+
const registry = buildRegistry(getSpecDir());
|
|
352
|
+
if (!table && !opts.all) {
|
|
353
|
+
for (const l of schemaIndexLines(registry)) console.log(l);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const tables = table ? [table] : [...registry.keys()].sort();
|
|
357
|
+
for (const t of tables) {
|
|
358
|
+
const resolved = registry.get(t);
|
|
359
|
+
if (!resolved) {
|
|
360
|
+
console.error(`Unknown table: ${t}. Run \`bimdown schema\` for the list of tables.`);
|
|
361
|
+
process.exitCode = 1;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
for (const l of schemaTableLines(resolved)) console.log(l);
|
|
365
|
+
console.log();
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
program.command("init").argument("<dir>", "BimDown project directory").option("--units <units>", "Project units: m, mm, ft or in (starter types are scaled to them)", "m").description("Initialize a new BimDown project structure").action(async (dir, opts) => {
|
|
369
|
+
const absDir = resolve(dir);
|
|
370
|
+
const { initProject, PROJECT_UNITS } = await import("./init-VWDML3UC.js");
|
|
371
|
+
if (!PROJECT_UNITS.includes(opts.units)) {
|
|
372
|
+
console.error(`Unknown units "${opts.units}" (use ${PROJECT_UNITS.join(", ")})`);
|
|
373
|
+
process.exitCode = 1;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
initProject(absDir, { units: opts.units });
|
|
377
|
+
});
|
|
378
|
+
program.command("diff").argument("<dirA>", "First BimDown project directory").argument("<dirB>", "Second BimDown project directory").description("Show differences between two BimDown projects").action(async (dirA, dirB) => {
|
|
379
|
+
const absA = resolve(dirA);
|
|
380
|
+
const absB = resolve(dirB);
|
|
381
|
+
const { diffProjects } = await import("./diff-T2KOK2WR.js");
|
|
382
|
+
diffProjects(absA, absB);
|
|
383
|
+
});
|
|
384
|
+
program.command("import-ifc").argument("<file>", "IFC file (IFC2x3 / IFC4 / IFC4x3, .ifc)").argument("<outdir>", "Directory for the new BimDown project").option("--force", "Write into a non-empty directory").option("--json <path>", "Also write the import report as JSON").description("Convert an IFC model into a BimDown project, then build it and report room problems").action(async (file, outdir, opts) => {
|
|
385
|
+
const { runImportIfc, printImportResult } = await import("./import-ifc-RCZSXDA6.js");
|
|
386
|
+
try {
|
|
387
|
+
const r = await runImportIfc(file, outdir, opts);
|
|
388
|
+
printImportResult(r, outdir);
|
|
389
|
+
if (r.build.issues.length > 0) process.exitCode = 1;
|
|
390
|
+
} catch (e) {
|
|
391
|
+
console.error(`import-ifc: ${e.message}`);
|
|
392
|
+
process.exitCode = 1;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
program.command("publish").argument("<dir>", "BimDown project directory").option("--expires <duration>", "Expiration time (e.g. 7d, 24h, 30m)", "7d").option("--api <url>", "API base URL (default https://bim.jouledown.com, or $BIMDOWN_API)").option("--name <name>", "Project name").description("Publish a BimDown project to bim.jouledown.com and get a share link").action(async (dir, opts) => {
|
|
396
|
+
const { publish } = await import("./publish-3TAXQCUV.js");
|
|
397
|
+
await publish(dir, opts);
|
|
398
|
+
});
|
|
399
|
+
program.parse();
|
|
400
|
+
function printTable(columns, rows) {
|
|
401
|
+
if (rows.length === 0) {
|
|
402
|
+
console.log("(empty result)");
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const widths = columns.map((c) => c.length);
|
|
406
|
+
for (const row of rows) {
|
|
407
|
+
for (let i = 0; i < columns.length; i++) {
|
|
408
|
+
const val = formatValue(row[columns[i]]);
|
|
409
|
+
widths[i] = Math.max(widths[i], val.length);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const header = columns.map((c, i) => c.padEnd(widths[i])).join(" | ");
|
|
413
|
+
console.log(header);
|
|
414
|
+
console.log(widths.map((w) => "-".repeat(w)).join("-+-"));
|
|
415
|
+
for (const row of rows) {
|
|
416
|
+
const line = columns.map((c, i) => formatValue(row[c]).padEnd(widths[i])).join(" | ");
|
|
417
|
+
console.log(line);
|
|
418
|
+
}
|
|
419
|
+
console.log(`
|
|
420
|
+
(${rows.length} row(s))`);
|
|
421
|
+
}
|
|
422
|
+
function formatValue(val) {
|
|
423
|
+
if (val == null) return "";
|
|
424
|
+
if (typeof val === "bigint") return val.toString();
|
|
425
|
+
return String(val);
|
|
426
|
+
}
|
|
427
|
+
function jsonReplacer(_key, value) {
|
|
428
|
+
if (typeof value === "bigint") return Number(value);
|
|
429
|
+
return value;
|
|
430
|
+
}
|
|
431
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/furniture/catalog-text.ts","../src/schema/schema-text.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { resolve } from 'node:path';\nimport { build, validateOnly } from './build/index.js';\nimport { buildRegistry, getSpecDir } from './schema/registry.js';\nimport { schemaIndexLines, schemaTableLines } from './schema/schema-text.js';\nimport { discoverLayout } from './utils/fs.js';\nimport { existsSync, writeFileSync } from 'node:fs';\n\ndeclare const CLI_VERSION: string;\n\nconst program = new Command();\n\nprogram\n .name('bimdown')\n .description('BimDown CLI — build, query, and manage BimDown projects')\n .version(typeof CLI_VERSION !== 'undefined' ? CLI_VERSION : '0.0.0');\n\n// ─── build ──────────────────────────────────────────────\nconst WARN_LIST_LIMIT = 20;\n\nfunction runBuild(dir: string, opts: { verbose?: boolean } = {}, readOnly = false) {\n const absDir = resolve(dir);\n const result = readOnly ? validateOnly(absDir) : build(absDir);\n\n if (result.issues.length > 0) {\n for (const issue of result.issues) {\n console.log(issue);\n }\n console.log(`\\n${result.issues.length} issue(s) found.`);\n process.exitCode = 1;\n }\n\n if (result.warnings.length > 0) {\n const shown = opts.verbose ? result.warnings : result.warnings.slice(0, WARN_LIST_LIMIT);\n for (const w of shown) {\n console.log(w);\n }\n if (shown.length < result.warnings.length) {\n console.log(`... ${result.warnings.length - shown.length} more (use --verbose to list all)`);\n }\n console.log(`\\n${result.warnings.length} warning(s). Warnings are advisory; issues are errors.`);\n }\n\n if (result.roomIssues.length > 0) {\n const label = { shared: 'share one enclosed area', contains: 'encloses', unbounded: 'has no enclosing boundary' } as const;\n console.log(`\\nRoom problems (${result.roomIssues.length}): derived room areas are wrong until fixed`);\n const shown = opts.verbose ? result.roomIssues : result.roomIssues.slice(0, WARN_LIST_LIMIT);\n for (const r of shown) {\n const text = r.kind === 'contains'\n ? `${r.spaceIds.join(', ')} ${label.contains} ${(r.inside ?? []).join(', ')}`\n : `${r.spaceIds.join(', ')} ${label[r.kind]}`;\n console.log(` ${r.level}: ${text}`);\n }\n if (shown.length < result.roomIssues.length) {\n console.log(` ... ${result.roomIssues.length - shown.length} more (use --verbose to list all)`);\n }\n }\n\n if (result.snaps.length > 0) {\n console.log(readOnly\n ? `${result.snaps.length} endpoint(s) closer than 5 cm (build snaps them):`\n : `Snapped ${result.snaps.length} endpoint(s) closer than 5 cm:`);\n const shown = opts.verbose ? result.snaps : result.snaps.slice(0, WARN_LIST_LIMIT);\n for (const s of shown) {\n console.log(` ${s.level}/${s.table} ${s.elementId} ${s.side} (${s.from.x.toFixed(3)}, ${s.from.y.toFixed(3)}) -> (${s.to.x.toFixed(3)}, ${s.to.y.toFixed(3)})`);\n }\n if (shown.length < result.snaps.length) console.log(` ... ${result.snaps.length - shown.length} more`);\n }\n\n if (result.hints.length > 0) {\n console.log();\n for (const h of result.hints) console.log(h);\n }\n\n if (result.artifacts.length > 0 && !readOnly) {\n console.log(`\\nGenerated: ${result.artifacts.join(', ')}`);\n }\n\n if (result.issues.length === 0 && result.warnings.length === 0) {\n console.log('Build successful. No issues found.');\n }\n}\n\nprogram\n .command('build')\n .argument('<dir>', 'BimDown project directory')\n .option('--verbose', 'List every warning and snapped endpoint')\n .description('Build a BimDown project (validate + compute space boundaries)')\n .action((dir: string, opts: { verbose?: boolean }) => runBuild(dir, opts));\n\nprogram\n .command('validate')\n .argument('<dir>', 'BimDown project directory')\n .option('--verbose', 'List every warning and snapped endpoint')\n .description('Check a BimDown project like build, without writing anything')\n .action((dir: string, opts: { verbose?: boolean }) => runBuild(dir, opts, true));\n\n// ─── query ──────────────────────────────────────────────\nprogram\n .command('query')\n .argument('<dir>', 'BimDown project directory')\n .argument('<sql>', 'SQL query to execute')\n .option('--json', 'Output results as JSON')\n .description('Hydrate into DuckDB and execute a SQL query')\n .action(async (dir: string, sql: string, opts: { json?: boolean }) => {\n const absDir = resolve(dir);\n const { getConnection, runQuery, closeConnection } = await import('./duckdb/engine.js');\n const { hydrate } = await import('./duckdb/hydrate.js');\n\n const conn = await getConnection();\n try {\n await hydrate(conn, absDir);\n const result = await runQuery(conn, sql);\n\n if (opts.json) {\n console.log(JSON.stringify(result.rows, jsonReplacer, 2));\n } else {\n printTable(result.columns, result.rows);\n }\n } finally {\n await closeConnection();\n }\n });\n\n// ─── sync ───────────────────────────────────────────────\nprogram\n .command('sync')\n .argument('<dir>', 'BimDown project directory')\n .description('Hydrate, then dehydrate back (sync DuckDB changes to files)')\n .action(async (dir: string) => {\n const absDir = resolve(dir);\n const { getConnection, closeConnection } = await import('./duckdb/engine.js');\n const { hydrate } = await import('./duckdb/hydrate.js');\n const { dehydrate } = await import('./duckdb/dehydrate.js');\n\n const conn = await getConnection();\n try {\n const tables = await hydrate(conn, absDir);\n console.log(`Hydrated ${tables.length} tables: ${tables.join(', ')}`);\n await dehydrate(conn, absDir);\n console.log('Sync complete — files updated.');\n } finally {\n await closeConnection();\n }\n });\n\n// ─── render ─────────────────────────────────────────────\nprogram\n .command('render')\n .argument('<dir>', 'BimDown project directory')\n .option('-l, --level <id>', 'Level to render (defaults to lv-1)', 'lv-1')\n .option('-o, --output <file>', 'Output file path (defaults to render.png)', 'render.png')\n .option('-w, --width <px>', 'Image width in pixels', '2048')\n .description('Renders the BimDown project into a visual blueprint (PNG). Color legend: walls=dark navy, structural walls=slate, columns=dark filled, slabs=light grey translucent (sloped floors with their slope arrow, tail dot → head), spaces=blue translucent, stairs=orange runs with treads (dashed beyond the 1.2 m plan cut), landings and an UP walking line (multi-storey stairs also on the storeys they repeat on), railings=slate lines (stair railings follow the derived path), beams/braces=thin purple dashed centerlines (overhead, drawn under walls), columns at their real section size, foundations=brown dashed outlines (pads width×length, piles as circles, strips at their width, rafts/pile caps), grids=red dash-dot axes with numbered bubbles, roofs=brown outline with ridges and hips (valleys dashed) and down-slope arrows labelled with the slope, slab holes and slab openings (white with a cross; shafts also on every level they cross), wall openings=orange lines, curtain walls=light blue strips with a tick per vertical grid line (door panels open, with red swings). DOORS render as BOLD RED (#e63946) lines and WINDOWS as BOLD TEAL (#2a9d8f) lines cutting across their host walls. MEP: runs at their real width in system colours (SA blue, RA light blue, CHWS cyan, SAN brown, FP red, …) with elbow / tee / reducer bodies, system + size tags, rise / drop boxes, slope arrows; terminals, equipment and valves as plan symbols. Furniture and library components draw their grey plan symbols (back edge = local +Y). Annotations (dimension/text_note/tag tables) in dark blue: dimension lines with values in mm (ft-in for imperial), text, boxed door/window tags, room tags with name/number/area.')\n .action(async (dir: string, opts: { level: string; output: string; width: string }) => {\n const absDir = resolve(dir);\n const { renderLevel } = await import('./render.js');\n try {\n const svg = renderLevel(absDir, opts.level);\n if (opts.output.endsWith('.svg')) {\n writeFileSync(opts.output, svg);\n } else {\n const sharp = (await import('sharp')).default;\n const width = parseInt(opts.width, 10) || 2048;\n await sharp(Buffer.from(svg)).resize({ width }).png().toFile(opts.output);\n }\n console.log(`Rendered ${opts.level} to ${opts.output}`);\n } catch (err: any) {\n console.error(`Render failed: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\n// ─── info ───────────────────────────────────────────────\nprogram\n .command('info')\n .argument('<dir>', 'BimDown project directory')\n .description('Print project summary: units, levels, element counts, element types')\n .action(async (dir: string) => {\n const { projectInfoLines } = await import('./commands/info.js');\n for (const l of projectInfoLines(resolve(dir))) console.log(l);\n });\n\n// ─── resolve-topology ──────────────────────────────────────\nprogram\n .command('resolve-topology')\n .argument('<dir>', 'BimDown project directory')\n .description('Auto-resolve MEP topology: detect coincident endpoints, generate mep_nodes, fill connectivity')\n .action(async (dir: string) => {\n const absDir = resolve(dir);\n const { resolveTopology } = await import('./commands/resolve-topology.js');\n resolveTopology(absDir);\n });\n\n// ─── mep-check ────────────────────────────────────────────\nprogram\n .command('mep-check')\n .argument('<dir>', 'BimDown project directory')\n .option('--json', 'Print the report as JSON')\n .option('--all', 'Also list info-level findings (unused equipment ports, devices without a circuit)')\n .description('MEP connectivity check: systems (curves, length, devices) and problems — open ends, port refs that do not resolve or whose curve end is not on the port, system / domain mismatches, disconnected devices, orphan fittings, overloaded circuits. Exit code 1 when there are warnings.')\n .action(async (dir: string, opts: { json?: boolean; all?: boolean }) => {\n const { mepReport, formatProblem } = await import('./mep/index.js');\n const report = mepReport(resolve(dir));\n const shown = opts.all ? report.problems : report.problems.filter(p => p.severity === 'warning');\n if (opts.json) {\n console.log(JSON.stringify({ systems: report.systems, problems: shown }, null, 2));\n } else {\n console.log('Systems:');\n if (report.systems.length === 0) console.log(' (no MEP curves)');\n for (const s of report.systems) {\n console.log(` ${s.system.padEnd(8)} ${String(s.curves).padStart(4)} curve(s) ${s.length.toFixed(1).padStart(7)} long ${s.devices} device(s) [${s.tables.join(', ')}]`);\n }\n console.log();\n for (const p of shown) console.log(`${p.severity === 'info' ? 'info ' : ''}${formatProblem(p)}`);\n const warnings = report.problems.filter(p => p.severity === 'warning').length;\n console.log(warnings === 0 ? 'MEP connectivity: no problems.' : `\\n${warnings} connectivity problem(s).`);\n }\n if (report.problems.some(p => p.severity === 'warning')) process.exitCode = 1;\n });\n\n// ─── clash ────────────────────────────────────────────────\n/** A length argument in metres: a bare number in `bareM` metres, or with a unit (mm, cm, m). Null when invalid or negative. */\nfunction parseLengthM(s: string, bareM: number): number | null {\n const m = /^\\s*([0-9]*\\.?[0-9]+(?:e[-+]?\\d+)?)\\s*(mm|cm|m)?\\s*$/i.exec(s);\n if (!m) return null;\n const v = Number(m[1]) * (m[2] ? { mm: 0.001, cm: 0.01, m: 1 }[m[2].toLowerCase() as 'mm' | 'cm' | 'm'] : bareM);\n return Number.isFinite(v) && v >= 0 ? v : null;\n}\n\nprogram\n .command('clash')\n .argument('<dir>', 'BimDown project directory')\n .option('--tolerance <m>', 'Overlaps no deeper than this are within tolerance, not clashes: metres, or with a unit (50mm, 5cm); 0 = every overlap', '0.05')\n .option('--clearance <mm>', 'Also report MEP closer than this to MEP / structure without touching: mm, or with a unit (0 = off)', '0')\n .option('--minor', 'Also list the overlaps within tolerance')\n .option('--level <id>', 'Only MEP on this level (obstacles from every level)')\n .option('--json', 'Print the report as JSON')\n .option('--mep-only', 'Only MEP vs MEP')\n .description('MEP clash detection: ducts / pipes / conduits / cable trays and devices against structure (high), against other MEP they do not connect to (medium), through slabs / roofs / non-structural walls with no opening (low penetration), and closer than --clearance (low). Overlaps up to --tolerance (5 cm) are modelling slack, not clashes. Exit code 0 unless the project cannot be read.')\n .action(async (dir: string, opts: { tolerance: string; clearance: string; minor?: boolean; level?: string; json?: boolean; mepOnly?: boolean }) => {\n const absDir = resolve(dir);\n const tolerance = parseLengthM(opts.tolerance, 1), clearance = parseLengthM(opts.clearance, 0.001);\n if (!existsSync(absDir)) { console.error(`No such directory: ${dir}`); process.exitCode = 1; return; }\n if (tolerance === null || clearance === null) {\n console.error('--tolerance takes a length in metres, --clearance in mm (>= 0; or with a unit: 50mm, 5cm, 0.05m)'); process.exitCode = 1; return;\n }\n if (tolerance > 1 && !/[a-z]$/i.test(opts.tolerance.trim())) {\n console.error(`--tolerance is in metres (0.05 = 5 cm); for millimetres write ${opts.tolerance}mm`); process.exitCode = 1; return;\n }\n if (opts.level && !discoverLayout(absDir).levelDirs.some(d => d.name === opts.level) && opts.level !== 'global') {\n console.error(`No level directory ${opts.level} in ${dir}`); process.exitCode = 1; return;\n }\n const { clashReport, formatClashReport } = await import('./mep/clash-load.js');\n const report = clashReport(absDir, { toleranceM: tolerance, clearanceMm: clearance * 1000, level: opts.level, mepOnly: opts.mepOnly, minor: opts.minor });\n if (opts.json) console.log(JSON.stringify(report, null, 2));\n else for (const line of formatClashReport(report)) console.log(line);\n });\n\n// ─── merge ───────────────────────────────────────────────\nprogram\n .command('merge')\n .argument('<dirs...>', 'Two or more BimDown project directories to merge')\n .requiredOption('-o, --output <dir>', 'Output directory for merged project')\n .description('Merge multiple BimDown project directories into one, resolving ID conflicts')\n .action(async (dirs: string[], opts: { output: string }) => {\n if (dirs.length < 2) {\n console.error('At least 2 source directories are required.');\n process.exitCode = 1;\n return;\n }\n const absDirs = dirs.map((d) => resolve(d));\n const absOut = resolve(opts.output);\n const { merge } = await import('./commands/merge.js');\n await merge(absDirs, absOut);\n });\n\n// ─── schema ─────────────────────────────────────────────\nprogram\n .command('schema')\n .argument('[table]', 'Table name (omit for a compact index of all tables)')\n .option('--all', 'Print the full schema of every table (long)')\n .description('Print the full schema of a table, or an index of all tables')\n .action((table: string | undefined, opts: { all?: boolean }) => {\n const registry = buildRegistry(getSpecDir());\n if (!table && !opts.all) {\n for (const l of schemaIndexLines(registry)) console.log(l);\n return;\n }\n\n const tables = table ? [table] : [...registry.keys()].sort();\n for (const t of tables) {\n const resolved = registry.get(t);\n if (!resolved) {\n console.error(`Unknown table: ${t}. Run \\`bimdown schema\\` for the list of tables.`);\n process.exitCode = 1;\n return;\n }\n for (const l of schemaTableLines(resolved)) console.log(l);\n console.log();\n }\n });\n\n// ─── init ───────────────────────────────────────────────\nprogram\n .command('init')\n .argument('<dir>', 'BimDown project directory')\n .option('--units <units>', 'Project units: m, mm, ft or in (starter types are scaled to them)', 'm')\n .description('Initialize a new BimDown project structure')\n .action(async (dir: string, opts: { units: string }) => {\n const absDir = resolve(dir);\n const { initProject, PROJECT_UNITS } = await import('./commands/init.js');\n if (!(PROJECT_UNITS as string[]).includes(opts.units)) {\n console.error(`Unknown units \"${opts.units}\" (use ${PROJECT_UNITS.join(', ')})`);\n process.exitCode = 1;\n return;\n }\n initProject(absDir, { units: opts.units as any });\n });\n\n// ─── diff ───────────────────────────────────────────────\nprogram\n .command('diff')\n .argument('<dirA>', 'First BimDown project directory')\n .argument('<dirB>', 'Second BimDown project directory')\n .description('Show differences between two BimDown projects')\n .action(async (dirA: string, dirB: string) => {\n const absA = resolve(dirA);\n const absB = resolve(dirB);\n const { diffProjects } = await import('./commands/diff.js');\n diffProjects(absA, absB);\n });\n\n// ─── import-ifc ────────────────────────────────────────\nprogram\n .command('import-ifc')\n .argument('<file>', 'IFC file (IFC2x3 / IFC4 / IFC4x3, .ifc)')\n .argument('<outdir>', 'Directory for the new BimDown project')\n .option('--force', 'Write into a non-empty directory')\n .option('--json <path>', 'Also write the import report as JSON')\n .description('Convert an IFC model into a BimDown project, then build it and report room problems')\n .action(async (file: string, outdir: string, opts: { force?: boolean; json?: string }) => {\n const { runImportIfc, printImportResult } = await import('./commands/import-ifc.js');\n try {\n const r = await runImportIfc(file, outdir, opts);\n printImportResult(r, outdir);\n if (r.build.issues.length > 0) process.exitCode = 1;\n } catch (e) {\n console.error(`import-ifc: ${(e as Error).message}`);\n process.exitCode = 1;\n }\n });\n\n// ─── publish ───────────────────────────────────────────\nprogram\n .command('publish')\n .argument('<dir>', 'BimDown project directory')\n .option('--expires <duration>', 'Expiration time (e.g. 7d, 24h, 30m)', '7d')\n .option('--api <url>', 'API base URL (default https://bim.jouledown.com, or $BIMDOWN_API)')\n .option('--name <name>', 'Project name')\n .description('Publish a BimDown project to bim.jouledown.com and get a share link')\n .action(async (dir: string, opts: { expires?: string; api?: string; name?: string }) => {\n const { publish } = await import('./commands/publish.js');\n await publish(dir, opts);\n });\n\nprogram.parse();\n\n// ─── helpers ────────────────────────────────────────────\n\nfunction printTable(columns: string[], rows: Record<string, unknown>[]) {\n if (rows.length === 0) {\n console.log('(empty result)');\n return;\n }\n\n // Calculate column widths\n const widths = columns.map((c) => c.length);\n for (const row of rows) {\n for (let i = 0; i < columns.length; i++) {\n const val = formatValue(row[columns[i]]);\n widths[i] = Math.max(widths[i], val.length);\n }\n }\n\n // Header\n const header = columns.map((c, i) => c.padEnd(widths[i])).join(' | ');\n console.log(header);\n console.log(widths.map((w) => '-'.repeat(w)).join('-+-'));\n\n // Rows\n for (const row of rows) {\n const line = columns\n .map((c, i) => formatValue(row[c]).padEnd(widths[i]))\n .join(' | ');\n console.log(line);\n }\n\n console.log(`\\n(${rows.length} row(s))`);\n}\n\nfunction formatValue(val: unknown): string {\n if (val == null) return '';\n if (typeof val === 'bigint') return val.toString();\n return String(val);\n}\n\nfunction jsonReplacer(_key: string, value: unknown): unknown {\n if (typeof value === 'bigint') return Number(value);\n return value;\n}\n","/** Text listing of the furniture library, appended to `bimdown schema furniture`. */\nimport { CATEGORY_LABELS, CATEGORY_ORDER, furnitureFamilies } from './library.js';\n\nconst size = (s: [number, number, number]) => s.map(v => +v.toFixed(3)).join('×');\n\nexport function furnitureCatalogLines(): string[] {\n const lines = [' Families (default size_x×size_y×height m; variants with their own default size):'];\n for (const cat of CATEGORY_ORDER) {\n const fams = furnitureFamilies().filter(f => f.category === cat);\n if (fams.length === 0) continue;\n lines.push(` ${CATEGORY_LABELS[cat].en}:`);\n for (const f of fams) {\n const tags: string[] = [];\n if (f.wallBacked) tags.push('back to wall');\n if (f.baseOffset) tags.push(`base_offset ${f.baseOffset}`);\n const variants = (f.variants ?? []).map((v, i) => `${v.id}${v.size ? ` ${size(v.size)}` : ''}${i === 0 ? ' (default)' : ''}`);\n lines.push(` ${f.id} ${size(f.size)}${tags.length ? ` [${tags.join(', ')}]` : ''}${variants.length ? ` variants: ${variants.join(', ')}` : ''}`);\n }\n }\n return lines;\n}\n","/**\n * Text for `bimdown schema` (and the agent's model_schema tool).\n * No table: a compact index (one line per table, a few key fields) — the full\n * dump of every table is ~40k characters. With a table: its full columns.\n */\nimport type { ResolvedTable } from './types.js';\nimport { typeParamFields } from '../catalog/index.js';\nimport { furnitureCatalogLines } from '../furniture/catalog-text.js';\n\n/** Table → one-line purpose with its key fields, grouped as printed. */\nconst INDEX: [group: string, tables: [string, string][]][] = [\n ['Project (global/)', [\n ['level', 'storey: number, elevation (absolute)'],\n ['grid', 'axis line: number, start/end x y'],\n ['view', 'section / elevation / 3D view: view_type, cut line'],\n ['underlay', 'tracing image / PDF under a level: level_id, file'],\n ['mesh', 'imported GLB: category, mesh_file'],\n ['sheet', 'drawing sheet: number, paper'],\n ['sheet_viewport', 'view placed on a sheet: sheet_id, view_type, x y'],\n ]],\n ['Architecture', [\n ['wall', 'line: thickness, type_id, base_offset/top_level_id/top_offset'],\n ['curtain_wall', 'line: u/v grids, panels, mullions'],\n ['column', 'point: shape, size_x/size_y'],\n ['slab', 'polygon floor, top = level + base_offset: thickness'],\n ['roof', 'polygon: roof_type (flat/gable/hip...), slope'],\n ['ceiling', 'polygon: height_offset'],\n ['space', 'room seed point: x y, name; boundary computed'],\n ['room_separator', 'line splitting rooms without a wall'],\n ['door', 'hosted on a wall: host_id, position, width, height'],\n ['window', 'hosted on a wall: host_id, position, width, height, base_offset (sill)'],\n ['opening', 'void in a wall / slab / roof'],\n ['stair', 'stair container (3D); parts below'],\n ['stair_run', 'flight of steps: host_id (stair)'],\n ['stair_landing', 'landing: host_id (stair)'],\n ['ramp', '3D line (start_z/end_z): width'],\n ['railing', '3D path or hosted on stair / slab edge'],\n ['furniture', 'library component (point): family, variant, rotation'],\n ]],\n ['Structure', [\n ['structure_wall', 'line: thickness'],\n ['structure_column', 'point: shape, size_x/size_y or designation'],\n ['structure_slab', 'polygon, top = level + base_offset: thickness'],\n ['beam', '3D line (absolute z = top): shape, size_x, size_y'],\n ['beam_system', 'parallel infill beams in a bay: spacing'],\n ['brace', '3D line: shape'],\n ['foundation', 'pad / pile / strip / raft / pile cap: kind, thickness'],\n ]],\n ['MEP', [\n ['duct', '3D line: shape, size_x/size_y, system_type, from/to'],\n ['pipe', '3D line: shape, size_x (diameter), system_type'],\n ['cable_tray', '3D line: size_x/size_y, system_type'],\n ['conduit', '3D line: size_x (diameter)'],\n ['equipment', 'point: equipment_type (AHU, pump, panel...); ports in connector'],\n ['terminal', 'point: terminal_type (diffuser, sink, WC, light...)'],\n ['mep_node', 'elbow / tee / fitting joining runs: kind'],\n ['connector', 'port on equipment / terminal / mep_node: host_id, name'],\n ['mep_system', 'system lookup: system_type'],\n ['circuit', 'electrical circuit from a panel: host_id'],\n ]],\n ['Types (global/; instances use type_id)', [\n ['wall_type', 'layers in type_layer'],\n ['slab_type', 'layered'],\n ['roof_type', 'layered'],\n ['ceiling_type', 'layered'],\n ['type_layer', 'one layer: type_id, seq, function, thickness'],\n ['door_type', 'width, height, operation'],\n ['window_type', 'width, height, operation, u_value'],\n ['curtain_wall_type', 'u/v spacing, mullions'],\n ['column_type', 'shape, sizes'],\n ['beam_type', 'shape, sizes'],\n ['foundation_type', 'kind, sizes'],\n ['furniture_type', 'family, variant, sizes'],\n ['railing_type', 'height, rails, infill'],\n ]],\n ['Annotation (level dirs)', [\n ['dimension', 'linear dimension: start/end x y'],\n ['text_note', 'text at x y'],\n ['tag', 'label of an element: host_id'],\n ['model_group', 'group instance: name, x y'],\n ]],\n];\n\n/** Compact index of every table (under 3k chars). */\nexport function schemaIndexLines(registry: Map<string, ResolvedTable>): string[] {\n const lines = ['Tables. Run `schema <table>` for exact columns, types, enums, references.'];\n const seen = new Set<string>();\n for (const [group, tables] of INDEX) {\n const present = tables.filter(([t]) => registry.has(t));\n if (present.length === 0) continue;\n lines.push(`${group}:`);\n for (const [t, purpose] of present) {\n seen.add(t);\n lines.push(` ${t}: ${purpose}`);\n }\n }\n const other = [...registry.keys()].filter((t) => !seen.has(t)).sort();\n if (other.length > 0) lines.push(`Other: ${other.join(', ')}`);\n return lines;\n}\n\n/** Full schema of one table. */\nexport function schemaTableLines(resolved: ResolvedTable): string[] {\n const t = resolved.name;\n const lines = [`── ${t} (prefix: ${resolved.prefix}) ──`];\n if (resolved.hostType) lines.push(` host_type: ${resolved.hostType}`);\n if (resolved.typeOf) {\n lines.push(` type of: ${resolved.typeOf.join(', ')} (global/ only; instances inherit shared fields they leave empty)`);\n }\n if (resolved.typeTable) lines.push(` type_id → ${resolved.typeTable}: empty shared fields inherit the type's values`);\n const typeParams = new Set(resolved.typeTable ? typeParamFields(t) : []);\n lines.push(' CSV fields:');\n for (const f of resolved.csvFields) {\n const tags: string[] = [];\n if (f.required) tags.push(typeParams.has(f.name) ? 'required unless type_id gives it' : 'required');\n if (f.type === 'reference') tags.push(`ref:${f.reference}`);\n if (f.type === 'enum') tags.push(`enum:[${f.values?.join('|')}]`);\n lines.push(` ${f.name}: ${f.type}${tags.length > 0 ? ` (${tags.join(', ')})` : ''}`);\n }\n if (resolved.computedFields.length > 0) {\n lines.push(' Computed fields (derived from geometry; queryable, never written to CSV):');\n for (const f of resolved.computedFields) lines.push(` ${f.name}: ${f.type}`);\n }\n if (t === 'furniture') lines.push(...furnitureCatalogLines());\n return lines;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,eAAe;;;ACExB,IAAM,OAAO,CAAC,MAAgC,EAAE,IAAI,OAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,KAAK,MAAG;AAEzE,SAAS,wBAAkC;AAChD,QAAM,QAAQ,CAAC,0FAAoF;AACnG,aAAW,OAAO,gBAAgB;AAChC,UAAM,OAAO,kBAAkB,EAAE,OAAO,OAAK,EAAE,aAAa,GAAG;AAC/D,QAAI,KAAK,WAAW,EAAG;AACvB,UAAM,KAAK,MAAM,gBAAgB,GAAG,EAAE,EAAE,GAAG;AAC3C,eAAW,KAAK,MAAM;AACpB,YAAM,OAAiB,CAAC;AACxB,UAAI,EAAE,WAAY,MAAK,KAAK,cAAc;AAC1C,UAAI,EAAE,WAAY,MAAK,KAAK,eAAe,EAAE,UAAU,EAAE;AACzD,YAAM,YAAY,EAAE,YAAY,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,IAAI,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,IAAI,eAAe,EAAE,EAAE;AAC5H,YAAM,KAAK,OAAO,EAAE,EAAE,KAAK,KAAK,EAAE,IAAI,CAAC,GAAG,KAAK,SAAS,MAAM,KAAK,KAAK,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,KAAK,EAAE,EAAE;AAAA,IACvJ;AAAA,EACF;AACA,SAAO;AACT;;;ACVA,IAAM,QAAuD;AAAA,EAC3D,CAAC,qBAAqB;AAAA,IACpB,CAAC,SAAS,sCAAsC;AAAA,IAChD,CAAC,QAAQ,kCAAkC;AAAA,IAC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,QAAQ,KAAK;AACvC,YAAM,MAAM,YAAY,IAAI,QAAQ,CAAC,CAAC,CAAC;AACvC,aAAO,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,IAAI,MAAM;AAAA,IAC5C;AAAA,EACF;AAGA,QAAM,SAAS,QAAQ,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK;AACpE,UAAQ,IAAI,MAAM;AAClB,UAAQ,IAAI,OAAO,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC;AAGxD,aAAW,OAAO,MAAM;AACtB,UAAM,OAAO,QACV,IAAI,CAAC,GAAG,MAAM,YAAY,IAAI,CAAC,CAAC,EAAE,OAAO,OAAO,CAAC,CAAC,CAAC,EACnD,KAAK,KAAK;AACb,YAAQ,IAAI,IAAI;AAAA,EAClB;AAEA,UAAQ,IAAI;AAAA,GAAM,KAAK,MAAM,UAAU;AACzC;AAEA,SAAS,YAAY,KAAsB;AACzC,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,OAAO,QAAQ,SAAU,QAAO,IAAI,SAAS;AACjD,SAAO,OAAO,GAAG;AACnB;AAEA,SAAS,aAAa,MAAc,OAAyB;AAC3D,MAAI,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK;AAClD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
runQuery
|
|
4
|
+
} from "./chunk-XC6WHJRL.js";
|
|
5
|
+
import {
|
|
6
|
+
typeParamFields
|
|
7
|
+
} from "./chunk-XQU52JKB.js";
|
|
8
|
+
import {
|
|
9
|
+
buildRegistry,
|
|
10
|
+
getSpecDir
|
|
11
|
+
} from "./chunk-4YHVOWS4.js";
|
|
12
|
+
import {
|
|
13
|
+
writeCsv
|
|
14
|
+
} from "./chunk-JY6KWRDB.js";
|
|
15
|
+
import "./chunk-OBY3UYCO.js";
|
|
16
|
+
|
|
17
|
+
// src/duckdb/dehydrate.ts
|
|
18
|
+
import { existsSync, mkdirSync } from "fs";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
async function dehydrate(conn, dir) {
|
|
21
|
+
const registry = buildRegistry(getSpecDir());
|
|
22
|
+
await stripTypeDefaults(conn, registry);
|
|
23
|
+
for (const [tableName, table] of registry) {
|
|
24
|
+
const check = await runQuery(
|
|
25
|
+
conn,
|
|
26
|
+
`SELECT count(*) as cnt FROM information_schema.tables WHERE table_name = '${tableName}'`
|
|
27
|
+
);
|
|
28
|
+
if (!check.rows.length || check.rows[0].cnt === 0n) continue;
|
|
29
|
+
const colsResult = await runQuery(
|
|
30
|
+
conn,
|
|
31
|
+
`SELECT column_name FROM information_schema.columns WHERE table_name = '${tableName}'`
|
|
32
|
+
);
|
|
33
|
+
const existingCols = new Set(colsResult.rows.map((r) => String(r.column_name)));
|
|
34
|
+
const csvHeaders = table.csvFields.map((f) => f.name).filter((h) => existingCols.has(h));
|
|
35
|
+
if (csvHeaders.length === 0) continue;
|
|
36
|
+
const partResult = await runQuery(
|
|
37
|
+
conn,
|
|
38
|
+
`SELECT DISTINCT _partition FROM "${tableName}"`
|
|
39
|
+
);
|
|
40
|
+
for (const partRow of partResult.rows) {
|
|
41
|
+
const partition = String(partRow._partition);
|
|
42
|
+
const outDir = join(dir, partition);
|
|
43
|
+
if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true });
|
|
44
|
+
const selectCols = csvHeaders.map((h) => `"${h}"`).join(", ");
|
|
45
|
+
const dataResult = await runQuery(
|
|
46
|
+
conn,
|
|
47
|
+
`SELECT ${selectCols} FROM "${tableName}" WHERE _partition = '${partition}'`
|
|
48
|
+
);
|
|
49
|
+
const data = {
|
|
50
|
+
headers: csvHeaders,
|
|
51
|
+
rows: dataResult.rows.map((r) => {
|
|
52
|
+
const row = {};
|
|
53
|
+
for (const h of csvHeaders) {
|
|
54
|
+
const val = r[h];
|
|
55
|
+
row[h] = val == null ? "" : String(val);
|
|
56
|
+
}
|
|
57
|
+
return row;
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
writeCsv(join(outDir, `${tableName}.csv`), data);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function columnsOf(conn, name) {
|
|
65
|
+
const r = await runQuery(conn, `SELECT column_name FROM information_schema.columns WHERE table_name = '${name}'`);
|
|
66
|
+
return new Set(r.rows.map((row) => String(row.column_name)));
|
|
67
|
+
}
|
|
68
|
+
async function stripTypeDefaults(conn, registry) {
|
|
69
|
+
for (const [name, table] of registry) {
|
|
70
|
+
const typeTable = table.typeTable;
|
|
71
|
+
if (!typeTable) continue;
|
|
72
|
+
const instCols = await columnsOf(conn, name);
|
|
73
|
+
const typeCols = await columnsOf(conn, typeTable);
|
|
74
|
+
if (!instCols.has("type_id") || typeCols.size === 0) continue;
|
|
75
|
+
for (const f of typeParamFields(name)) {
|
|
76
|
+
if (!instCols.has(f) || !typeCols.has(f)) continue;
|
|
77
|
+
await runQuery(
|
|
78
|
+
conn,
|
|
79
|
+
`UPDATE "${name}" AS i SET "${f}" = '' FROM "${typeTable}" AS t
|
|
80
|
+
WHERE i.type_id = t.id AND i."${f}" <> '' AND (
|
|
81
|
+
CAST(i."${f}" AS VARCHAR) = CAST(t."${f}" AS VARCHAR)
|
|
82
|
+
OR abs(TRY_CAST(i."${f}" AS DOUBLE) - TRY_CAST(t."${f}" AS DOUBLE)) < 1e-6)`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
dehydrate
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=dehydrate-ZHAGOI7Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/duckdb/dehydrate.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport type { DuckDBConnection } from '@duckdb/node-api';\nimport { buildRegistry, getSpecDir } from '../schema/registry.js';\nimport type { ResolvedTable } from '../schema/types.js';\nimport { typeParamFields } from '../catalog/index.js';\nimport { writeCsv, type CsvData } from '../utils/csv.js';\nimport { runQuery } from './engine.js';\n\nexport async function dehydrate(conn: DuckDBConnection, dir: string): Promise<void> {\n const registry = buildRegistry(getSpecDir());\n await stripTypeDefaults(conn, registry);\n\n for (const [tableName, table] of registry) {\n // Check if table exists\n const check = await runQuery(\n conn,\n `SELECT count(*) as cnt FROM information_schema.tables WHERE table_name = '${tableName}'`,\n );\n if (!check.rows.length || check.rows[0].cnt === 0n) continue;\n\n // Only select CSV fields that actually exist as columns in DuckDB\n // (mixin fields like host_x/host_y are valid AI inputs but absent in dehydrated data).\n const colsResult = await runQuery(\n conn,\n `SELECT column_name FROM information_schema.columns WHERE table_name = '${tableName}'`,\n );\n const existingCols = new Set(colsResult.rows.map((r) => String(r.column_name)));\n const csvHeaders = table.csvFields.map((f) => f.name).filter((h) => existingCols.has(h));\n if (csvHeaders.length === 0) continue;\n\n const partResult = await runQuery(\n conn,\n `SELECT DISTINCT _partition FROM \"${tableName}\"`,\n );\n\n for (const partRow of partResult.rows) {\n const partition = String(partRow._partition);\n const outDir = join(dir, partition);\n if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true });\n\n const selectCols = csvHeaders.map((h) => `\"${h}\"`).join(', ');\n const dataResult = await runQuery(\n conn,\n `SELECT ${selectCols} FROM \"${tableName}\" WHERE _partition = '${partition}'`,\n );\n\n const data: CsvData = {\n headers: csvHeaders,\n rows: dataResult.rows.map((r) => {\n const row: Record<string, string> = {};\n for (const h of csvHeaders) {\n const val = r[h];\n row[h] = val == null ? '' : String(val);\n }\n return row;\n }),\n };\n\n writeCsv(join(outDir, `${tableName}.csv`), data);\n }\n }\n}\n\nasync function columnsOf(conn: DuckDBConnection, name: string): Promise<Set<string>> {\n const r = await runQuery(conn, `SELECT column_name FROM information_schema.columns WHERE table_name = '${name}'`);\n return new Set(r.rows.map((row) => String(row.column_name)));\n}\n\n/**\n * Inverse of hydrate's type defaults: a typed row's parameter equal to its\n * type's value is written back empty, so later type edits reach the instance.\n */\nasync function stripTypeDefaults(conn: DuckDBConnection, registry: Map<string, ResolvedTable>): Promise<void> {\n for (const [name, table] of registry) {\n const typeTable = table.typeTable;\n if (!typeTable) continue;\n const instCols = await columnsOf(conn, name);\n const typeCols = await columnsOf(conn, typeTable);\n if (!instCols.has('type_id') || typeCols.size === 0) continue;\n for (const f of typeParamFields(name)) {\n if (!instCols.has(f) || !typeCols.has(f)) continue;\n await runQuery(\n conn,\n `UPDATE \"${name}\" AS i SET \"${f}\" = '' FROM \"${typeTable}\" AS t\n WHERE i.type_id = t.id AND i.\"${f}\" <> '' AND (\n CAST(i.\"${f}\" AS VARCHAR) = CAST(t.\"${f}\" AS VARCHAR)\n OR abs(TRY_CAST(i.\"${f}\" AS DOUBLE) - TRY_CAST(t.\"${f}\" AS DOUBLE)) < 1e-6)`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAS,YAAY;AAQrB,eAAsB,UAAU,MAAwB,KAA4B;AAClF,QAAM,WAAW,cAAc,WAAW,CAAC;AAC3C,QAAM,kBAAkB,MAAM,QAAQ;AAEtC,aAAW,CAAC,WAAW,KAAK,KAAK,UAAU;AAEzC,UAAM,QAAQ,MAAM;AAAA,MAClB;AAAA,MACA,6EAA6E,SAAS;AAAA,IACxF;AACA,QAAI,CAAC,MAAM,KAAK,UAAU,MAAM,KAAK,CAAC,EAAE,QAAQ,GAAI;AAIpD,UAAM,aAAa,MAAM;AAAA,MACvB;AAAA,MACA,0EAA0E,SAAS;AAAA,IACrF;AACA,UAAM,eAAe,IAAI,IAAI,WAAW,KAAK,IAAI,CAAC,MAAM,OAAO,EAAE,WAAW,CAAC,CAAC;AAC9E,UAAM,aAAa,MAAM,UAAU,IAAI,CAAC,MAAM,EAAE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