@yrest/cli 0.10.0 → 0.11.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/dist/index.mjs CHANGED
@@ -33,37 +33,100 @@ function parseRelations(raw) {
33
33
  }
34
34
  function normaliseRelationDef(key, value) {
35
35
  if (typeof value === "string") {
36
- return { type: "many2one", target: value };
36
+ return value.includes(":") ? parseDslString(value) : { type: "many2one", target: value };
37
37
  }
38
38
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
39
39
  const v = value;
40
- const type = v["type"];
41
- const nested = v["nested"] === true ? true : void 0;
40
+ const type = v["_type"];
41
+ const nested = v["_nested"] === true ? true : void 0;
42
+ const carDirect = typeof v["_car-direct"] === "string" ? v["_car-direct"] : void 0;
43
+ const carInverse = typeof v["_car-inverse"] === "string" ? v["_car-inverse"] : void 0;
42
44
  if (type === "many2one" || type === void 0) {
43
- const target = v["target"];
45
+ const target = v["_target"];
44
46
  if (typeof target !== "string") return null;
45
- return nested ? { type: "many2one", target, nested } : { type: "many2one", target };
47
+ const foreignKey = typeof v["_foreignKey"] === "string" ? v["_foreignKey"] : void 0;
48
+ return compact({ type: "many2one", target, foreignKey, nested, carDirect, carInverse });
46
49
  }
47
50
  if (type === "one2one") {
48
- const target = v["target"];
51
+ const target = v["_target"];
49
52
  if (typeof target !== "string") return null;
50
- return nested ? { type: "one2one", target, nested } : { type: "one2one", target };
53
+ const foreignKey = typeof v["_foreignKey"] === "string" ? v["_foreignKey"] : void 0;
54
+ return compact({ type: "one2one", target, foreignKey, nested, carDirect, carInverse });
51
55
  }
52
56
  if (type === "many2many") {
53
- const target = typeof v["target"] === "string" ? v["target"] : key;
54
- const through = v["through"];
55
- const foreignKey = v["foreignKey"];
56
- const otherKey = v["otherKey"];
57
+ const target = typeof v["_target"] === "string" ? v["_target"] : key;
58
+ const through = v["_through"];
59
+ const foreignKey = v["_foreignKey"];
60
+ const otherKey = v["_otherKey"];
57
61
  if (typeof through !== "string" || typeof foreignKey !== "string" || typeof otherKey !== "string")
58
62
  return null;
59
- return nested ? { type: "many2many", target, through, foreignKey, otherKey, nested } : { type: "many2many", target, through, foreignKey, otherKey };
63
+ return compact({
64
+ type: "many2many",
65
+ target,
66
+ through,
67
+ foreignKey,
68
+ otherKey,
69
+ nested,
70
+ carDirect,
71
+ carInverse
72
+ });
60
73
  }
61
74
  return null;
62
75
  }
76
+ function parseDslString(raw) {
77
+ const nested = raw.endsWith("+nested") ? true : void 0;
78
+ let s = nested ? raw.slice(0, -7) : raw;
79
+ let carDirect;
80
+ let carInverse;
81
+ const carMatch = s.match(/\[([^[\]]+)->([^[\]]+)\]$/);
82
+ if (carMatch) {
83
+ carDirect = carMatch[1];
84
+ carInverse = carMatch[2];
85
+ s = s.slice(0, s.length - carMatch[0].length);
86
+ }
87
+ const colonIdx = s.indexOf(":");
88
+ if (colonIdx === -1) return null;
89
+ const typeAlias = s.slice(0, colonIdx);
90
+ const body = s.slice(colonIdx + 1);
91
+ const type = TYPE_ALIASES[typeAlias];
92
+ if (!type) return null;
93
+ if (type === "many2many") {
94
+ const m = body.match(/^([^@()[\]]+)@([^@()[\]]+)\(([^,)]+),\s*([^,)]+)\)$/);
95
+ if (!m) return null;
96
+ const [, target2, through, foreignKey2, otherKey] = m;
97
+ return compact({
98
+ type: "many2many",
99
+ target: target2,
100
+ through,
101
+ foreignKey: foreignKey2,
102
+ otherKey,
103
+ nested,
104
+ carDirect,
105
+ carInverse
106
+ });
107
+ }
108
+ const atIdx = body.indexOf("@");
109
+ const target = atIdx === -1 ? body : body.slice(0, atIdx);
110
+ const foreignKey = atIdx === -1 ? void 0 : body.slice(atIdx + 1);
111
+ if (!target) return null;
112
+ return compact({ type, target, foreignKey, nested, carDirect, carInverse });
113
+ }
114
+ function compact(obj) {
115
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
116
+ }
117
+ var TYPE_ALIASES;
63
118
  var init_parseRelations = __esm({
64
119
  "src/storage/parseRelations.ts"() {
65
120
  "use strict";
66
121
  init_esm_shims();
122
+ TYPE_ALIASES = {
123
+ many2one: "many2one",
124
+ m2o: "many2one",
125
+ one2one: "one2one",
126
+ o2o: "one2one",
127
+ many2many: "many2many",
128
+ m2m: "many2many"
129
+ };
67
130
  }
68
131
  });
69
132
 
@@ -87,13 +150,13 @@ function normaliseFieldDef(value) {
87
150
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
88
151
  const v = value;
89
152
  const def = {};
90
- if (v["required"] === true || v["required"] === false) def.required = v["required"];
91
- if (typeof v["type"] === "string" && ["string", "integer", "number", "boolean", "object", "array"].includes(v["type"]))
92
- def.type = v["type"];
93
- if (typeof v["format"] === "string") def.format = v["format"];
94
- if (Array.isArray(v["enum"])) def.enum = v["enum"];
95
- if (typeof v["description"] === "string") def.description = v["description"];
96
- if (v["default"] !== void 0) def.default = v["default"];
153
+ if (v["_required"] === true || v["_required"] === false) def.required = v["_required"];
154
+ if (typeof v["_type"] === "string" && ["string", "integer", "number", "boolean", "object", "array"].includes(v["_type"]))
155
+ def.type = v["_type"];
156
+ if (typeof v["_format"] === "string") def.format = v["_format"];
157
+ if (Array.isArray(v["_enum"])) def.enum = v["_enum"];
158
+ if (typeof v["_description"] === "string") def.description = v["_description"];
159
+ if (v["_default"] !== void 0) def.default = v["_default"];
97
160
  return def;
98
161
  }
99
162
  var init_parseSchema = __esm({
@@ -116,6 +179,60 @@ var init_deepCopy = __esm({
116
179
  }
117
180
  });
118
181
 
182
+ // src/storage/parseRoutes.ts
183
+ function parseRoutes(raw) {
184
+ if (!Array.isArray(raw)) return [];
185
+ return raw.map(normaliseRoute).filter((r) => r !== null);
186
+ }
187
+ function normaliseRoute(raw) {
188
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
189
+ const v = raw;
190
+ const method = v["_method"];
191
+ const path2 = v["_path"];
192
+ if (typeof method !== "string" || typeof path2 !== "string") return null;
193
+ const route = { method, path: path2 };
194
+ if (typeof v["_handler"] === "string") route.handler = v["_handler"];
195
+ if (typeof v["_delay"] === "number") route.delay = v["_delay"];
196
+ if (typeof v["_error"] === "number") route.error = v["_error"];
197
+ if (v["_errorBody"] !== void 0) route.errorBody = v["_errorBody"];
198
+ const response = normaliseResponse(v["_response"]);
199
+ if (response) route.response = response;
200
+ const otherwise = normaliseResponse(v["_otherwise"]);
201
+ if (otherwise) route.otherwise = otherwise;
202
+ const scenarios = normaliseScenarios(v["_scenarios"]);
203
+ if (scenarios.length > 0) route.scenarios = scenarios;
204
+ return route;
205
+ }
206
+ function normaliseResponse(raw) {
207
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
208
+ const v = raw;
209
+ const response = {};
210
+ if (typeof v["_status"] === "number") response.status = v["_status"];
211
+ if (v["_body"] !== void 0) response.body = v["_body"];
212
+ if (v["_headers"] && typeof v["_headers"] === "object" && !Array.isArray(v["_headers"]))
213
+ response.headers = v["_headers"];
214
+ return Object.keys(response).length > 0 ? response : void 0;
215
+ }
216
+ function normaliseScenarios(raw) {
217
+ if (!Array.isArray(raw)) return [];
218
+ return raw.map(normaliseScenario).filter((s) => s !== null);
219
+ }
220
+ function normaliseScenario(raw) {
221
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
222
+ const v = raw;
223
+ const when = v["_when"];
224
+ if (!when || typeof when !== "object") return null;
225
+ const response = normaliseResponse(v["_response"]);
226
+ if (!response) return null;
227
+ return { when, response };
228
+ }
229
+ var init_parseRoutes = __esm({
230
+ "src/storage/parseRoutes.ts"() {
231
+ "use strict";
232
+ init_esm_shims();
233
+ }
234
+ });
235
+
119
236
  // src/storage/yrestStorage.ts
120
237
  var yrestStorage_exports = {};
121
238
  __export(yrestStorage_exports, {
@@ -125,12 +242,66 @@ import { readFileSync as readFileSync2, writeFileSync, renameSync } from "fs";
125
242
  import { resolve, dirname as dirname2 } from "path";
126
243
  import { randomUUID as randomUUID2 } from "crypto";
127
244
  import { parse as parse2, stringify as stringify2 } from "yaml";
245
+ function serializeRelations(relations) {
246
+ const out = {};
247
+ for (const [col, fields] of Object.entries(relations)) {
248
+ out[col] = {};
249
+ for (const [key, def] of Object.entries(fields)) {
250
+ out[col][key] = serializeRelationDef(def);
251
+ }
252
+ }
253
+ return out;
254
+ }
255
+ function serializeRelationDef(def) {
256
+ if (def.type === "many2many") {
257
+ const entry2 = {
258
+ _type: def.type,
259
+ _target: def.target,
260
+ _through: def.through,
261
+ _foreignKey: def.foreignKey,
262
+ _otherKey: def.otherKey
263
+ };
264
+ if (def.nested) entry2._nested = true;
265
+ if (def.carDirect) entry2["_car-direct"] = def.carDirect;
266
+ if (def.carInverse) entry2["_car-inverse"] = def.carInverse;
267
+ return entry2;
268
+ }
269
+ const entry = { _type: def.type, _target: def.target };
270
+ if (def.foreignKey) entry._foreignKey = def.foreignKey;
271
+ if (def.nested) entry._nested = true;
272
+ if (def.carDirect) entry["_car-direct"] = def.carDirect;
273
+ if (def.carInverse) entry["_car-inverse"] = def.carInverse;
274
+ return entry;
275
+ }
276
+ function serializeRoutes(routes) {
277
+ return routes.map((r) => {
278
+ const entry = { _method: r.method, _path: r.path };
279
+ if (r.handler) entry._handler = r.handler;
280
+ if (r.delay !== void 0) entry._delay = r.delay;
281
+ if (r.error !== void 0) entry._error = r.error;
282
+ if (r.errorBody !== void 0) entry._errorBody = r.errorBody;
283
+ if (r.response) entry._response = serializeResponse(r.response);
284
+ if (r.otherwise) entry._otherwise = serializeResponse(r.otherwise);
285
+ if (r.scenarios?.length) entry._scenarios = r.scenarios.map(serializeScenario);
286
+ return entry;
287
+ });
288
+ }
289
+ function serializeResponse(res) {
290
+ const out = {};
291
+ if (res.status !== void 0) out._status = res.status;
292
+ if (res.body !== void 0) out._body = res.body;
293
+ if (res.headers) out._headers = res.headers;
294
+ return out;
295
+ }
296
+ function serializeScenario(s) {
297
+ return { _when: s.when, _response: serializeResponse(s.response) };
298
+ }
128
299
  function createYrestStorage(filePath) {
129
300
  const absPath = resolve(filePath);
130
301
  const raw = parse2(readFileSync2(absPath, "utf8")) ?? {};
131
302
  const RESERVED = /* @__PURE__ */ new Set(["_rel", "_routes", "_schema"]);
132
303
  const relations = parseRelations(raw["_rel"]);
133
- const routes = Array.isArray(raw["_routes"]) ? raw["_routes"] : [];
304
+ const routes = parseRoutes(raw["_routes"]);
134
305
  const schema = parseSchema(raw["_schema"]);
135
306
  const data = Object.fromEntries(
136
307
  Object.entries(raw).filter(([key]) => !RESERVED.has(key))
@@ -161,8 +332,8 @@ function createYrestStorage(filePath) {
161
332
  },
162
333
  persist() {
163
334
  const payload = {};
164
- if (Object.keys(relations).length > 0) payload._rel = relations;
165
- if (routes.length > 0) payload._routes = routes;
335
+ if (Object.keys(relations).length > 0) payload._rel = serializeRelations(relations);
336
+ if (routes.length > 0) payload._routes = serializeRoutes(routes);
166
337
  Object.assign(payload, data);
167
338
  const tmp = resolve(dirname2(absPath), `.yrest-${randomUUID2()}.tmp`);
168
339
  writeFileSync(tmp, stringify2(payload), "utf8");
@@ -204,6 +375,7 @@ var init_yrestStorage = __esm({
204
375
  "use strict";
205
376
  init_esm_shims();
206
377
  init_parseRelations();
378
+ init_parseRoutes();
207
379
  init_parseSchema();
208
380
  init_deepCopy();
209
381
  }
@@ -646,12 +818,584 @@ curl ${curlFlag}${fullPath}`);
646
818
  return `<pre>${highlighted}</pre>`;
647
819
  }
648
820
 
821
+ // src/router/templates/about.diagram.ts
822
+ init_esm_shims();
823
+ function inferType(value) {
824
+ if (value === null || value === void 0) return "string";
825
+ if (typeof value === "boolean") return "boolean";
826
+ if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
827
+ if (Array.isArray(value)) return "array";
828
+ if (typeof value === "object") return "object";
829
+ return "string";
830
+ }
831
+ function generateERData(storage) {
832
+ const data = storage.getData();
833
+ const relations = storage.getRelations();
834
+ const schema = storage.getSchema();
835
+ const pivotTables = /* @__PURE__ */ new Set();
836
+ const pivotFKs = /* @__PURE__ */ new Map();
837
+ for (const fields of Object.values(relations)) {
838
+ for (const def of Object.values(fields)) {
839
+ if (def.type === "many2many") {
840
+ pivotTables.add(def.through);
841
+ if (!pivotFKs.has(def.through)) pivotFKs.set(def.through, /* @__PURE__ */ new Set());
842
+ pivotFKs.get(def.through).add(def.foreignKey);
843
+ pivotFKs.get(def.through).add(def.otherKey);
844
+ }
845
+ }
846
+ }
847
+ const fkFields = /* @__PURE__ */ new Map();
848
+ for (const [source, fields] of Object.entries(relations)) {
849
+ for (const [key, def] of Object.entries(fields)) {
850
+ if (def.type !== "many2many") {
851
+ if (!fkFields.has(source)) fkFields.set(source, /* @__PURE__ */ new Set());
852
+ fkFields.get(source).add(key);
853
+ }
854
+ }
855
+ }
856
+ const entities = Object.entries(data).map(([name, items]) => {
857
+ const sample = items[0] ?? {};
858
+ const schemaFields = schema[name] ?? {};
859
+ const allFields = /* @__PURE__ */ new Set([...Object.keys(sample), ...Object.keys(schemaFields)]);
860
+ const fields = [...allFields].map((fieldName) => ({
861
+ name: fieldName,
862
+ type: schemaFields[fieldName]?.type ?? inferType(sample[fieldName]),
863
+ pk: fieldName === "id",
864
+ fk: fkFields.get(name)?.has(fieldName) ?? false,
865
+ required: schemaFields[fieldName]?.required ?? false
866
+ }));
867
+ fields.sort((a, b) => {
868
+ if (a.pk) return -1;
869
+ if (b.pk) return 1;
870
+ if (a.fk && !b.fk) return 1;
871
+ if (!a.fk && b.fk) return -1;
872
+ return 0;
873
+ });
874
+ return { name, fields, isPivot: pivotTables.has(name) };
875
+ });
876
+ const erRelations = [];
877
+ for (const [source, fields] of Object.entries(relations)) {
878
+ for (const [key, def] of Object.entries(fields)) {
879
+ if (def.type === "many2many") {
880
+ const throughRels = relations[def.through] ?? {};
881
+ const fkRel = throughRels[def.foreignKey];
882
+ const otherRel = throughRels[def.otherKey];
883
+ erRelations.push({
884
+ source,
885
+ target: def.target,
886
+ type: "many2many",
887
+ label: def.through,
888
+ through: def.through,
889
+ foreignKey: def.foreignKey,
890
+ otherKey: def.otherKey,
891
+ fkCarDirect: fkRel?.carDirect,
892
+ fkCarInverse: fkRel?.carInverse,
893
+ otherCarDirect: otherRel?.carDirect,
894
+ otherCarInverse: otherRel?.carInverse
895
+ });
896
+ } else {
897
+ if (pivotFKs.get(source)?.has(key)) continue;
898
+ erRelations.push({
899
+ source,
900
+ target: def.target,
901
+ type: def.type,
902
+ label: key,
903
+ carDirect: def.carDirect,
904
+ carInverse: def.carInverse
905
+ });
906
+ }
907
+ }
908
+ }
909
+ return { entities, relations: erRelations };
910
+ }
911
+
912
+ // src/router/templates/about.diagram.canvas.ts
913
+ init_esm_shims();
914
+ function erDiagramSection(data) {
915
+ if (!data.entities.length) return "";
916
+ const json = JSON.stringify(data);
917
+ return (
918
+ /*html*/
919
+ `
920
+ <h2>Data Model</h2>
921
+
922
+ <div class="card" style="padding:0;overflow:hidden;position:relative;">
923
+ <canvas id="er-canvas" style="width:100%;display:block;cursor:grab;"></canvas>
924
+ <div style="position:absolute;top:10px;right:14px;display:flex;gap:6px;align-items:center;">
925
+ <select id="er-scale" title="Download quality" style="background:#161b22;border:1px solid #30363d;color:#7d8590;padding:3px 6px;border-radius:6px;font-size:11px;cursor:pointer;">
926
+ <option value="1">1\xD7</option>
927
+ <option value="2">2\xD7</option>
928
+ <option value="3" selected>3\xD7</option>
929
+ <option value="4">4\xD7</option>
930
+ </select>
931
+ <button id="er-dl" title="Download PNG" style="background:#161b22;border:1px solid #30363d;color:#7d8590;padding:4px 10px;border-radius:6px;font-size:11px;cursor:pointer;line-height:1.4;">\u2193 PNG</button>
932
+ </div>
933
+ </div>
934
+
935
+ <script>${/*js*/
936
+ `
937
+ (function(){
938
+
939
+ var D=${json};
940
+
941
+ // \u2500\u2500 Constants \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
942
+ var NW=178,HH=34,FH=22,FP=10,ROW_GAP=44,COL_GAP=100,BR=12,BO=16,LGH=84,MIN_GAP=10;
943
+
944
+ var C={bg:'#0d1117',nb:'#161b22',nh:'#1c2128',pb:'#0d1117',ph:'#161b22',
945
+ bo:'#30363d',bs:'#58a6ff',tx:'#e6edf3',mu:'#7d8590',
946
+ pk:'#e3b341',fk:'#79c0ff',m2o:'#58a6ff',o2o:'#34d399',m2m:'#818cf8'};
947
+
948
+ // \u2500\u2500 Canvas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
949
+ var cv = document.getElementById('er-canvas');
950
+ var dpr = window.devicePixelRatio||1;
951
+ var ctx = cv.getContext('2d');
952
+
953
+ function resize(h){
954
+ if(h)cv.style.height = h + 'px';
955
+ var r = cv.getBoundingClientRect();
956
+ cv.width = Math.round(r.width*dpr);
957
+ cv.height = Math.round(r.height*dpr);
958
+ }
959
+
960
+ // \u2500\u2500 Nodes & adjacency \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
961
+ var nodes = D.entities.map(function(e){
962
+ return{e:e,x:0,y:0,w:NW,h:HH+e.fields.length*FH+6};
963
+ });
964
+
965
+ var nIdx={};D.entities.forEach(function(e,i){nIdx[e.name]=i;});
966
+
967
+ var adj=nodes.map(function(){return[];}); // forward
968
+ var radj=nodes.map(function(){return[];}); // reverse
969
+
970
+ D.relations.forEach(function(r){
971
+ if(r.type==='many2many'&&r.through&&nIdx[r.through]!=null){
972
+ var s=nIdx[r.source],p=nIdx[r.through],t=nIdx[r.target];
973
+ if(s!=null&&p!=null&&s!==p){adj[s].push(p);radj[p].push(s);}
974
+ if(t!=null&&p!=null&&t!==p){adj[t].push(p);radj[p].push(t);}
975
+ }else{
976
+ var s=nIdx[r.source],t=nIdx[r.target];
977
+ if(s==null||t==null||s===t)return;
978
+ adj[s].push(t);radj[t].push(s);
979
+ }
980
+ });
981
+
982
+ // \u2500\u2500 Dynamic node width \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
983
+ function computeNodeWidths(){
984
+ nodes.forEach(function(n){
985
+ var e=n.e;
986
+ ctx.font='600 12px -apple-system,BlinkMacSystemFont,sans-serif';
987
+ var hdrW=FP+ctx.measureText(e.name).width+FP;
988
+ if(e.isPivot){
989
+ ctx.font='9px monospace';
990
+ hdrW+=ctx.measureText('pivot').width+FP;
991
+ }
992
+ var maxRow=hdrW;
993
+ e.fields.forEach(function(f){
994
+ var leftPad=FP+(f.pk||f.fk?16:0);
995
+ var rightPad=(f.required&&!f.pk?14:0)+FP;
996
+ ctx.font=(f.required&&!f.pk?'600 ':'')+'11px monospace';
997
+ var nw=ctx.measureText(f.name).width;
998
+ ctx.font='10px monospace';
999
+ var tw=ctx.measureText(f.type).width;
1000
+ maxRow=Math.max(maxRow,leftPad+nw+MIN_GAP+tw+rightPad);
1001
+ });
1002
+ n.w=Math.max(NW,Math.ceil(maxRow));
1003
+ });
1004
+ }
1005
+
1006
+ // \u2500\u2500 Layered layout (simplified Sugiyama) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1007
+ var groups=[];
1008
+
1009
+ function median(arr){
1010
+ if(!arr.length)return 0;
1011
+ var s=[].concat(arr).sort(function(a,b){return a-b;});
1012
+ return s[Math.floor(s.length/2)];
1013
+ }
1014
+
1015
+ function computeLayout(W,H){
1016
+ var layer=nodes.map(function(){return 0;});
1017
+ var inDeg=nodes.map(function(){return 0;});
1018
+ adj.forEach(function(ts){ts.forEach(function(t){inDeg[t]++;});});
1019
+ var q=[],qi=0;
1020
+ for(var i=0;i<nodes.length;i++)if(inDeg[i]===0)q.push(i);
1021
+ if(!q.length)for(var i=0;i<nodes.length;i++)q.push(i);
1022
+ while(qi<q.length){
1023
+ var u=q[qi++];
1024
+ adj[u].forEach(function(v){if(layer[v]<=layer[u]){layer[v]=layer[u]+1;q.push(v);}});
1025
+ }
1026
+ var maxL=layer.reduce(function(m,l){return Math.max(m,l);},0);
1027
+ groups=[];
1028
+ for(var l=0;l<=maxL;l++)groups.push([]);
1029
+ for(var i=0;i<nodes.length;i++)groups[layer[i]].push(i);
1030
+ for(var l=1;l<=maxL;l++){
1031
+ var pp={};groups[l-1].forEach(function(i,p){pp[i]=p;});
1032
+ groups[l].sort(function(a,b){
1033
+ return median(radj[a].map(function(x){return pp[x]!=null?pp[x]:0;}))-
1034
+ median(radj[b].map(function(x){return pp[x]!=null?pp[x]:0;}));
1035
+ });
1036
+ }
1037
+ for(var l=maxL-1;l>=0;l--){
1038
+ var np={};groups[l+1].forEach(function(i,p){np[i]=p;});
1039
+ groups[l].sort(function(a,b){
1040
+ return median(adj[a].map(function(x){return np[x]!=null?np[x]:0;}))-
1041
+ median(adj[b].map(function(x){return np[x]!=null?np[x]:0;}));
1042
+ });
1043
+ }
1044
+ var maxNW=nodes.reduce(function(m,n){return Math.max(m,n.w);},NW);
1045
+ var colW=maxNW+COL_GAP;
1046
+ var totalW=(maxL+1)*colW-COL_GAP;
1047
+ var startX=Math.max(20,(W-totalW)/2);
1048
+ for(var l=0;l<=maxL;l++){
1049
+ var g=groups[l];
1050
+ var totalH=g.reduce(function(s,i){return s+nodes[i].h;},0)+(g.length-1)*ROW_GAP;
1051
+ var y=Math.max(20,(H-totalH)/2);
1052
+ g.forEach(function(i){nodes[i].x=startX+l*colW;nodes[i].y=y;y+=nodes[i].h+ROW_GAP;});
1053
+ }
1054
+ }
1055
+
1056
+ function requiredH(){
1057
+ return Math.max(340,Math.min(720,groups.reduce(function(m,g){
1058
+ return Math.max(m,g.reduce(function(s,i){return s+nodes[i].h;},0)+(g.length-1)*ROW_GAP+LGH+70);
1059
+ },300)));
1060
+ }
1061
+
1062
+ // \u2500\u2500 View \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1063
+ var pan={x:0,y:0},zm=1;
1064
+ var origPos=[];
1065
+
1066
+ function savePos(){origPos=nodes.map(function(n){return{x:n.x,y:n.y};});}
1067
+
1068
+ function fitView(W,H){
1069
+ var x0=1e9,y0=1e9,x1=-1e9,y1=-1e9;
1070
+ nodes.forEach(function(n){x0=Math.min(x0,n.x);y0=Math.min(y0,n.y);x1=Math.max(x1,n.x+n.w);y1=Math.max(y1,n.y+n.h);});
1071
+ var pad=28,gW=x1-x0+pad*2,gH=y1-y0+pad*2;
1072
+ zm=Math.min(W/gW,(H-LGH)/gH,1);
1073
+ pan.x=(W-gW*zm)/2+pad*zm-x0*zm;
1074
+ pan.y=((H-LGH)-gH*zm)/2+pad*zm-y0*zm;
1075
+ }
1076
+
1077
+ // \u2500\u2500 Rendering \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1078
+ function rr(x,y,w,h,r){
1079
+ if(ctx.roundRect){ctx.beginPath();ctx.roundRect(x,y,w,h,r);return;}
1080
+ ctx.beginPath();ctx.moveTo(x+r,y);ctx.arcTo(x+w,y,x+w,y+h,r);
1081
+ ctx.arcTo(x+w,y+h,x,y+h,r);ctx.arcTo(x,y+h,x,y,r);ctx.arcTo(x,y,x+w,y,r);ctx.closePath();
1082
+ }
1083
+
1084
+ function edgePt(n,tx,ty){
1085
+ var cx=n.x+n.w/2,cy=n.y+n.h/2,dx=tx-cx,dy=ty-cy;
1086
+ if(!dx&&!dy)return{x:cx,y:cy};
1087
+ var s=Math.min((n.w/2)/Math.abs(dx||.001),(n.h/2)/Math.abs(dy||.001));
1088
+ return{x:cx+dx*s,y:cy+dy*s};
1089
+ }
1090
+
1091
+ var badges=[];
1092
+
1093
+ // \u2500\u2500 SVG cardinality badges via Path2D \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1094
+ // SVG orientation: LEFT side touches the node, RIGHT side connects to the line.
1095
+ // Rotation = Math.atan2(uy,ux) aligns local +x with the outward (away-from-node) direction.
1096
+ var P2D={
1097
+ '1..1':new Path2D('M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM41 26C41 24.3431 39.6569 23 38 23C36.3431 23 35 24.3431 35 26V37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57C24.6569 57 26 55.6569 26 54V43H35V54C35 55.6569 36.3431 57 38 57C39.6569 57 41 55.6569 41 54V43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H41V26Z'),
1098
+ '1..n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM44.9862 42.9025L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H46V26C46 24.3431 47.3431 23 49 23C50.6569 23 52 24.3431 52 26V36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H52V53C52 54.6569 50.6569 56 49 56C47.3431 56 46 54.6569 46 53V42.9025H44.9862Z'),
1099
+ '0..1':new Path2D('M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM23 57C24.6569 57 26 55.6569 26 54V43H33.3781C34.7102 48.1757 39.4085 52 45 52C50.5915 52 55.2898 48.1757 56.6219 43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H56.6219C55.2898 31.8243 50.5915 28 45 28C39.4085 28 34.7102 31.8243 33.3781 37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57ZM51 40C51 41.0929 50.7078 42.1175 50.1973 43C49.1599 44.7934 47.2208 46 45 46C42.7792 46 40.8401 44.7934 39.8027 43C39.2922 42.1175 39 41.0929 39 40C39 38.9071 39.2922 37.8825 39.8027 37C40.8401 35.2066 42.7792 34 45 34C47.2208 34 49.1599 35.2066 50.1973 37C50.7078 37.8825 51 38.9071 51 40Z'),
1100
+ '0..n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 42.9025C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L45.4091 36.8818L45.4036 36.9025H45.445L45.4091 36.8818C46.7819 31.7662 51.4511 28 57 28C62.579 28 67.2687 31.8072 68.6129 36.9652C69.9758 37.2481 71 38.4557 71 39.9025C71 41.331 70.0017 42.5262 68.6647 42.8286C67.3931 48.091 62.6531 52 57 52C51.3734 52 46.6513 48.1276 45.3534 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17ZM62.1397 36.9025C61.0891 35.163 59.1804 34 57 34C54.8196 34 52.9109 35.163 51.8603 36.9025C51.3142 37.8067 51 38.8667 51 40C51 41.0529 51.2712 42.0424 51.7475 42.9025C52.7704 44.7496 54.7392 46 57 46C59.2608 46 61.2296 44.7496 62.2525 42.9025C62.7288 42.0424 63 41.0529 63 40C63 38.8667 62.6858 37.8067 62.1397 36.9025Z'),
1101
+ 'n':new Path2D('M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 36.9025H33.0677L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025Z')
1102
+ };
1103
+
1104
+ function pushBadge(x,y,ux,uy,car,col){
1105
+ badges.push({x:x,y:y,ux:ux,uy:uy,car:car,col:col});
1106
+ }
1107
+
1108
+ function drawBadge(b){
1109
+ var p=P2D[b.car]||P2D['n'],sc=BR/40;
1110
+ ctx.save();
1111
+ ctx.translate(b.x+b.ux*BO,b.y+b.uy*BO);
1112
+ ctx.rotate(Math.atan2(b.uy,b.ux));
1113
+ ctx.scale(sc,sc);
1114
+ ctx.translate(-40,-40);
1115
+ ctx.fillStyle=b.col;
1116
+ ctx.fill(p,'evenodd');
1117
+ ctx.restore();
1118
+ }
1119
+
1120
+ function ecol(t){return t==='one2one'?C.o2o:t==='many2many'?C.m2m:C.m2o;}
1121
+
1122
+ // offset: pixels to shift perpendicular to the edge direction (for parallel edges)
1123
+ function drawEdgeLine(a,b,col,dashed,label,carA,carB,off){
1124
+ var p1=edgePt(a,b.x+b.w/2,b.y+b.h/2);
1125
+ var p2=edgePt(b,a.x+a.w/2,a.y+a.h/2);
1126
+ var dx=p2.x-p1.x,dy=p2.y-p1.y,d=Math.sqrt(dx*dx+dy*dy)||1;
1127
+ var ux=dx/d,uy=dy/d;
1128
+ var px=-uy*off,py=ux*off; // perpendicular shift
1129
+ var q1x=p1.x+px,q1y=p1.y+py,q2x=p2.x+px,q2y=p2.y+py;
1130
+ ctx.strokeStyle=col+'55';ctx.lineWidth=1.5;
1131
+ ctx.setLineDash(dashed?[5,4]:[]);
1132
+ ctx.beginPath();ctx.moveTo(q1x,q1y);ctx.lineTo(q2x,q2y);ctx.stroke();
1133
+ ctx.setLineDash([]);
1134
+ pushBadge(q1x,q1y,ux,uy,carA,col);
1135
+ pushBadge(q2x,q2y,-ux,-uy,carB,col);
1136
+ if(label){
1137
+ var mx=(q1x+q2x)/2,my=(q1y+q2y)/2;
1138
+ var la=Math.atan2(uy,ux);
1139
+ if(la>Math.PI/2||la<-Math.PI/2)la+=Math.PI; // keep text readable
1140
+ var ls=off>0?11:-11; // alternate above/below for parallel edges
1141
+ ctx.save();
1142
+ ctx.translate(mx,my);
1143
+ ctx.rotate(la);
1144
+ ctx.fillStyle=C.mu;ctx.font='10px monospace';ctx.textAlign='center';ctx.textBaseline='middle';
1145
+ ctx.fillText(label,0,ls);
1146
+ ctx.restore();
1147
+ }
1148
+ }
1149
+
1150
+ // canonical key for a node pair regardless of direction
1151
+ function pairKey(a,b){
1152
+ var ai=nodes.indexOf(a),bi=nodes.indexOf(b);
1153
+ return ai<bi?ai+'-'+bi:bi+'-'+ai;
1154
+ }
1155
+
1156
+ function collectEdges(){
1157
+ var edges=[];
1158
+ D.relations.forEach(function(r){
1159
+ var col=ecol(r.type);
1160
+ if(r.type==='many2many'&&r.through&&nIdx[r.through]!=null){
1161
+ var sn=nodes[nIdx[r.source]],pn=nodes[nIdx[r.through]],tn=nodes[nIdx[r.target]];
1162
+ if(sn&&pn)edges.push({a:sn,b:pn,col:col,dashed:true,label:r.foreignKey||'',carA:r.fkCarDirect||'1..1',carB:r.fkCarInverse||'0..n',off:0});
1163
+ if(tn&&pn)edges.push({a:tn,b:pn,col:col,dashed:true,label:r.otherKey||'',carA:r.otherCarDirect||'1..1',carB:r.otherCarInverse||'0..n',off:0});
1164
+ }else{
1165
+ var sn=nodes[nIdx[r.source]],tn=nodes[nIdx[r.target]];
1166
+ if(sn&&tn&&sn!==tn){
1167
+ var carA=r.carInverse||(r.type!=='one2one'?'1..n':'1..1');
1168
+ var carB=r.carDirect||(r.type==='many2many'?'1..n':'1..1');
1169
+ edges.push({a:sn,b:tn,col:col,dashed:false,label:r.label,carA:carA,carB:carB,off:0});
1170
+ }
1171
+ }
1172
+ });
1173
+ // assign perpendicular offsets to parallel edges (same node pair)
1174
+ var cnt={},idx={};
1175
+ edges.forEach(function(e){var k=pairKey(e.a,e.b);cnt[k]=(cnt[k]||0)+1;});
1176
+ edges.forEach(function(e){
1177
+ var k=pairKey(e.a,e.b),n=cnt[k];
1178
+ var i=idx[k]=(idx[k]||0);
1179
+ e.off=n>1?(i-(n-1)/2)*16:0;
1180
+ idx[k]++;
1181
+ });
1182
+ return edges;
1183
+ }
1184
+
1185
+ function drawNode(n){
1186
+ var x=n.x,y=n.y,w=n.w,h=n.h,e=n.e;
1187
+ var bg=e.isPivot?C.pb:C.nb,hd=e.isPivot?C.ph:C.nh;
1188
+ ctx.save();ctx.shadowColor='rgba(0,0,0,0.45)';ctx.shadowBlur=14;ctx.shadowOffsetY=4;
1189
+ ctx.fillStyle=bg;rr(x,y,w,h,7);ctx.fill();ctx.restore();
1190
+ ctx.fillStyle=bg;rr(x,y,w,h,7);ctx.fill();
1191
+ ctx.strokeStyle=n===drag?C.bs:C.bo;ctx.lineWidth=1.2;rr(x,y,w,h,7);ctx.stroke();
1192
+ ctx.fillStyle=hd;rr(x,y,w,HH,7);ctx.fill();ctx.fillRect(x,y+HH-7,w,7);
1193
+ ctx.strokeStyle=C.bo;ctx.lineWidth=1;
1194
+ ctx.beginPath();ctx.moveTo(x,y+HH);ctx.lineTo(x+w,y+HH);ctx.stroke();
1195
+ ctx.fillStyle=e.isPivot?C.mu:C.tx;
1196
+ ctx.font='600 12px -apple-system,BlinkMacSystemFont,sans-serif';
1197
+ ctx.textAlign='left';ctx.textBaseline='middle';
1198
+ ctx.fillText(e.name,x+FP,y+HH/2);
1199
+ if(e.isPivot){
1200
+ ctx.fillStyle='#3d444d';ctx.font='9px monospace';ctx.textAlign='right';
1201
+ ctx.fillText('pivot',x+w-FP,y+HH/2);
1202
+ }
1203
+ e.fields.forEach(function(f,fi){
1204
+ var fy=y+HH+fi*FH+FH/2+3;
1205
+ ctx.fillStyle=C.mu;ctx.font='10px monospace';ctx.textAlign='right';ctx.textBaseline='middle';
1206
+ ctx.fillText(f.type,x+w-FP-(f.required&&!f.pk?14:0),fy);
1207
+ if(f.pk||f.fk){
1208
+ var tag=f.pk?'PK':'FK',tc=f.pk?C.pk:C.fk;
1209
+ ctx.fillStyle=tc+'22';ctx.strokeStyle=tc+'66';ctx.lineWidth=1;
1210
+ rr(x+FP,fy-6,12,12,2);ctx.fill();ctx.stroke();
1211
+ ctx.fillStyle=tc;ctx.font='7px monospace';ctx.textAlign='center';
1212
+ ctx.fillText(tag,x+FP+6,fy+0.5);
1213
+ }
1214
+ ctx.fillStyle=f.pk?C.pk:f.fk?C.fk:C.tx;
1215
+ ctx.font=(f.required&&!f.pk?'600 ':'')+'11px monospace';
1216
+ ctx.textAlign='left';ctx.textBaseline='middle';
1217
+ ctx.fillText(f.name,x+FP+(f.pk||f.fk?16:0),fy);
1218
+ if(f.required&&!f.pk){
1219
+ ctx.fillStyle='#f85149';ctx.beginPath();
1220
+ ctx.arc(x+w-FP-6,fy,2.5,0,Math.PI*2);ctx.fill();
1221
+ }
1222
+ });
1223
+ ctx.textBaseline='alphabetic';
1224
+ }
1225
+
1226
+ function drawLegend(){
1227
+ var cvW=cv.width/dpr,cvH=cv.height/dpr;
1228
+ var yL=cvH-LGH,y1=yL+13,y2=yL+35,y3=yL+62;
1229
+
1230
+ ctx.fillStyle='#161b22';
1231
+ ctx.fillRect(0,yL,cvW,LGH);
1232
+ ctx.strokeStyle='#30363d';ctx.lineWidth=1;
1233
+ ctx.beginPath();ctx.moveTo(0,yL);ctx.lineTo(cvW,yL);ctx.stroke();
1234
+
1235
+ function legendBadge(cx,cy,car,col,angle){
1236
+ var p=P2D[car]||P2D['n'],sc=8/40;
1237
+ ctx.save();
1238
+ ctx.translate(cx,cy);
1239
+ ctx.rotate(angle);
1240
+ ctx.scale(sc,sc);
1241
+ ctx.translate(-40,-40);
1242
+ ctx.fillStyle=col;
1243
+ ctx.fill(p,'evenodd');
1244
+ ctx.restore();
1245
+ }
1246
+
1247
+ // Row 1: relation line types
1248
+ var types=[
1249
+ {c:C.m2o,l:'many2one',d:false},
1250
+ {c:C.o2o,l:'one2one',d:false},
1251
+ {c:C.m2m,l:'many2many',d:true}
1252
+ ];
1253
+ ctx.textAlign='left';ctx.textBaseline='middle';ctx.font='10px monospace';
1254
+ var x=14;
1255
+ types.forEach(function(it){
1256
+ ctx.strokeStyle=it.c;ctx.lineWidth=1.5;ctx.setLineDash(it.d?[4,3]:[]);
1257
+ ctx.beginPath();ctx.moveTo(x,y1);ctx.lineTo(x+14,y1);ctx.stroke();
1258
+ ctx.setLineDash([]);
1259
+ ctx.fillStyle=C.mu;
1260
+ ctx.fillText(it.l,x+18,y1);
1261
+ x+=18+ctx.measureText(it.l).width+22;
1262
+ });
1263
+
1264
+ // Row 2: relation type examples (pair of badges + line)
1265
+ x=14;
1266
+ var pairs=[
1267
+ {carA:'1..n',carB:'1..1',col:C.m2o,l:'many2one (N:1)'},
1268
+ {carA:'1..1',carB:'1..1',col:C.o2o,l:'one2one (1:1)'},
1269
+ {carA:'1..1',carB:'0..n',col:C.m2m,l:'pivot edge (1:0..N)'}
1270
+ ];
1271
+ pairs.forEach(function(p){
1272
+ ctx.strokeStyle=p.col+'55';ctx.lineWidth=1.2;ctx.setLineDash(p.col===C.m2m?[4,3]:[]);
1273
+ ctx.beginPath();ctx.moveTo(x+8,y2);ctx.lineTo(x+56,y2);ctx.stroke();
1274
+ ctx.setLineDash([]);
1275
+ legendBadge(x+8,y2,p.carA,p.col,0);
1276
+ legendBadge(x+56,y2,p.carB,p.col,Math.PI);
1277
+ ctx.fillStyle=C.mu;ctx.font='10px monospace';ctx.textAlign='left';ctx.textBaseline='middle';
1278
+ ctx.fillText(p.l,x+66,y2);
1279
+ x+=66+ctx.measureText(p.l).width+24;
1280
+ });
1281
+
1282
+ // Row 3: individual symbol meanings
1283
+ var symbols=[
1284
+ {car:'1..1',l:'exactly one'},
1285
+ {car:'0..1',l:'zero or one'},
1286
+ {car:'1..n',l:'one or more'},
1287
+ {car:'0..n',l:'zero or more'},
1288
+ {car:'n', l:'many (pivot)'}
1289
+ ];
1290
+ x=14;
1291
+ ctx.font='10px monospace';ctx.textAlign='left';ctx.textBaseline='middle';
1292
+ symbols.forEach(function(s){
1293
+ legendBadge(x+8,y3,s.car,C.mu,0);
1294
+ ctx.fillStyle=C.mu;
1295
+ ctx.fillText(s.l,x+20,y3);
1296
+ x+=20+ctx.measureText(s.l).width+18;
1297
+ });
1298
+
1299
+ ctx.fillStyle='#3d444d';ctx.font='10px monospace';ctx.textAlign='right';ctx.textBaseline='middle';
1300
+ ctx.fillText('drag \xB7 scroll to zoom \xB7 dbl-click to reset',cvW-14,y1);
1301
+ ctx.textBaseline='alphabetic';
1302
+ }
1303
+
1304
+ function draw(){
1305
+ var W=cv.width/dpr,H=cv.height/dpr;
1306
+ ctx.setTransform(dpr,0,0,dpr,0,0);
1307
+ ctx.clearRect(0,0,W,H);
1308
+ ctx.fillStyle=C.bg;ctx.fillRect(0,0,W,H);
1309
+ ctx.save();ctx.translate(pan.x,pan.y);ctx.scale(zm,zm);
1310
+ badges=[];
1311
+ var edges=collectEdges();
1312
+ edges.forEach(function(e){drawEdgeLine(e.a,e.b,e.col,e.dashed,e.label,e.carA,e.carB,e.off);});
1313
+ nodes.forEach(function(n){drawNode(n);});
1314
+ badges.forEach(function(b){drawBadge(b);});
1315
+ ctx.restore();
1316
+ drawLegend();
1317
+ }
1318
+
1319
+ // \u2500\u2500 Interaction \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1320
+ var drag=null,dox=0,doy=0,isPan=false,ps={x:0,y:0};
1321
+
1322
+ function toW(mx,my){return{x:(mx-pan.x)/zm,y:(my-pan.y)/zm};}
1323
+ function hitTest(wx,wy){
1324
+ for(var i=nodes.length-1;i>=0;i--){var n=nodes[i];if(wx>=n.x&&wx<=n.x+n.w&&wy>=n.y&&wy<=n.y+n.h)return n;}
1325
+ return null;
1326
+ }
1327
+
1328
+ cv.addEventListener('mousedown',function(ev){
1329
+ var r=cv.getBoundingClientRect(),mx=ev.clientX-r.left,my=ev.clientY-r.top;
1330
+ var w=toW(mx,my),h=hitTest(w.x,w.y);
1331
+ if(h){drag=h;dox=w.x-h.x;doy=w.y-h.y;}else{isPan=true;ps={x:mx-pan.x,y:my-pan.y};}
1332
+ cv.style.cursor='grabbing';
1333
+ });
1334
+ window.addEventListener('mousemove',function(ev){
1335
+ if(!drag&&!isPan)return;
1336
+ var r=cv.getBoundingClientRect(),mx=ev.clientX-r.left,my=ev.clientY-r.top;
1337
+ if(drag){var w=toW(mx,my);drag.x=w.x-dox;drag.y=w.y-doy;}
1338
+ else{pan.x=mx-ps.x;pan.y=my-ps.y;}
1339
+ draw();
1340
+ });
1341
+ window.addEventListener('mouseup',function(){drag=null;isPan=false;cv.style.cursor='grab';});
1342
+ cv.addEventListener('wheel',function(ev){
1343
+ ev.preventDefault();
1344
+ var r=cv.getBoundingClientRect(),mx=ev.clientX-r.left,my=ev.clientY-r.top;
1345
+ var d=ev.deltaY<0?1.1:0.91,nz=Math.max(0.25,Math.min(3,zm*d));
1346
+ pan.x=mx-(mx-pan.x)*(nz/zm);pan.y=my-(my-pan.y)*(nz/zm);zm=nz;draw();
1347
+ },{passive:false});
1348
+ cv.addEventListener('dblclick',function(){
1349
+ nodes.forEach(function(n,i){n.x=origPos[i].x;n.y=origPos[i].y;});
1350
+ var r=cv.getBoundingClientRect();fitView(r.width,r.height);draw();
1351
+ });
1352
+ window.addEventListener('resize',function(){
1353
+ resize();var r=cv.getBoundingClientRect();
1354
+ computeLayout(r.width,r.height);savePos();fitView(r.width,r.height);draw();
1355
+ });
1356
+
1357
+ document.getElementById('er-dl').addEventListener('click',function(){
1358
+ var SCALE=parseInt(document.getElementById('er-scale').value,10)||3;
1359
+ var pad=36;
1360
+ var bx0=1e9,by0=1e9,bx1=-1e9,by1=-1e9;
1361
+ nodes.forEach(function(n){
1362
+ bx0=Math.min(bx0,n.x);by0=Math.min(by0,n.y);
1363
+ bx1=Math.max(bx1,n.x+n.w);by1=Math.max(by1,n.y+n.h);
1364
+ });
1365
+ var cw=bx1-bx0+pad*2,ch=by1-by0+pad*2+LGH;
1366
+ var oc=document.createElement('canvas');
1367
+ oc.width=Math.round(cw*SCALE);oc.height=Math.round(ch*SCALE);
1368
+ var sav={cv:cv,ctx:ctx,dpr:dpr,px:pan.x,py:pan.y,zm:zm};
1369
+ cv=oc;ctx=oc.getContext('2d');dpr=SCALE;
1370
+ pan.x=pad-bx0;pan.y=pad-by0;zm=1;
1371
+ draw();
1372
+ cv=sav.cv;ctx=sav.ctx;dpr=sav.dpr;pan.x=sav.px;pan.y=sav.py;zm=sav.zm;
1373
+ var a=document.createElement('a');
1374
+ a.download='er-diagram.png';a.href=oc.toDataURL('image/png');a.click();
1375
+ });
1376
+
1377
+ // \u2500\u2500 Init \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
1378
+ requestAnimationFrame(function(){
1379
+ resize();
1380
+ computeNodeWidths();
1381
+ var r=cv.getBoundingClientRect();
1382
+ computeLayout(r.width,r.height);
1383
+ var h=requiredH();
1384
+ resize(h);r=cv.getBoundingClientRect();
1385
+ computeLayout(r.width,r.height);
1386
+ savePos();fitView(r.width,r.height);draw();
1387
+ });
1388
+ })();
1389
+ `}</script>`
1390
+ );
1391
+ }
1392
+
649
1393
  // src/router/templates/about.template.ts
650
1394
  var _dir = dirname(fileURLToPath2(import.meta.url));
651
1395
  var LOGO_SRC = (() => {
652
1396
  try {
653
- const buf = readFileSync(join(_dir, "../../assets/logo-color.png"));
654
- return `data:image/png;base64,${buf.toString("base64")}`;
1397
+ const buf = readFileSync(join(_dir, "../../assets/yrest-lockup.svg"));
1398
+ return `data:image/svg+xml;base64,${buf.toString("base64")}`;
655
1399
  } catch {
656
1400
  return "";
657
1401
  }
@@ -662,6 +1406,7 @@ function generateAboutHtml(storage, options, handlers = /* @__PURE__ */ new Map(
662
1406
  const customRoutes = storage.getRoutes();
663
1407
  const base = options.base;
664
1408
  const host = `http://${options.host}:${options.port}`;
1409
+ const swaggerUrl = `https://petstore.swagger.io/?url=${encodeURIComponent(`${host}/_openapi.json`)}`;
665
1410
  const modes = [];
666
1411
  if (options.watch) modes.push(badge("watch", "#38bdf8", "#38bdf818"));
667
1412
  if (options.readonly) modes.push(badge("readonly", "#94a3b8", "#94a3b818"));
@@ -672,9 +1417,12 @@ function generateAboutHtml(storage, options, handlers = /* @__PURE__ */ new Map(
672
1417
  if (handlers.size > 0) modes.push(badge(`handlers \xB7 ${handlers.size}`, "#f0883e", "#f0883e18"));
673
1418
  if (options.idStrategy !== "increment")
674
1419
  modes.push(badge(`id \xB7 ${options.idStrategy}`, "#a371f7", "#a371f718"));
1420
+ const erDiagram = erDiagramSection(generateERData(storage));
675
1421
  const accordions = collections.map((col, i) => resourceAccordion(col, base, i === 0)).join("");
676
1422
  const paginationDesc = options.pageable.enabled ? `Pageable mode active \u2014 default limit <code>${options.pageable.limit}</code>. Response wrapped in <code>{ data, pagination }</code>.` : `Returns the requested slice. <code>X-Total-Count</code> header reflects the total before pagination.`;
677
- return `<!DOCTYPE html>
1423
+ return (
1424
+ /*html*/
1425
+ `<!DOCTYPE html>
678
1426
  <html lang="en">
679
1427
  <head>
680
1428
  <meta charset="UTF-8">
@@ -701,20 +1449,30 @@ function generateAboutHtml(storage, options, handlers = /* @__PURE__ */ new Map(
701
1449
  width: 100%;
702
1450
  background: linear-gradient(135deg, #0d1117 0%, #161b22 40%, #1a2332 100%);
703
1451
  border-bottom: 1px solid var(--border);
704
- padding: 48px 32px 40px;
1452
+ padding: 20px 32px 16px;
705
1453
  }
706
- .banner-inner { max-width: 1100px; margin: 0 auto; }
707
- .banner h1 { font-size: clamp(36px, 6vw, 60px); font-weight: 800; letter-spacing: -2px; line-height: 1; }
1454
+ .banner-inner { margin: 0 auto; display:flex; align-items:center; justify-content:space-between; gap:16px; flex-wrap:wrap; }
1455
+ .banner-left { flex:1; min-width:0; }
1456
+ .banner h1 { font-size: clamp(24px, 4vw, 40px); font-weight: 800; letter-spacing: -1.5px; line-height: 1; }
708
1457
  .banner h1 .y { color: var(--text); }
709
1458
  .banner h1 .rest { color: var(--accent); }
710
- .banner p { color: var(--text-muted); margin-top: 10px; font-size: 15px; }
711
- .banner-meta { display: flex; gap: 24px; margin-top: 20px; flex-wrap: wrap; }
712
- .banner-meta span { color: var(--text-muted); font-size: 13px; }
1459
+ .banner p { color: var(--text-muted); margin-top: 6px; font-size: 14px; }
1460
+ .banner-meta { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
1461
+ .banner-meta span { color: var(--text-muted); font-size: 12px; }
713
1462
  .banner-meta span strong { color: var(--text); font-family: monospace; }
1463
+ .api-links { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
1464
+ .btn-api { display:inline-block; padding:5px 12px; border-radius:6px; border:1px solid var(--border); color:var(--text-muted); text-decoration:none; font-size:12px; font-weight:500; background:var(--bg-card); white-space:nowrap; transition:border-color .15s,color .15s; }
1465
+ .btn-api:hover { border-color:var(--border-hi); color:var(--text); }
1466
+ .btn-swagger { border-color:var(--accent); color:var(--accent); }
1467
+ .btn-swagger:hover { background:#58a6ff18; }
714
1468
 
715
1469
  /* \u2500\u2500 Layout \u2500\u2500 */
716
- .wrap { max-width: 1100px; margin: 0 auto; padding: 32px 24px 48px; }
1470
+ .wrap { padding: 24px 32px 48px; }
717
1471
  h2 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin: 32px 0 12px; }
1472
+ .about-grid { display:grid; grid-template-columns:5fr 7fr; gap:28px; align-items:start; }
1473
+ @media(max-width:960px) { .about-grid { grid-template-columns:1fr; } }
1474
+ .col-left, .col-right { min-width:0; }
1475
+ .col-left > h2:first-child, .col-right > h2:first-child { margin-top:0; }
718
1476
 
719
1477
  /* \u2500\u2500 Cards \u2500\u2500 */
720
1478
  .card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
@@ -730,10 +1488,8 @@ function generateAboutHtml(storage, options, handlers = /* @__PURE__ */ new Map(
730
1488
  .modes { display: flex; gap: 8px; flex-wrap: wrap; min-height: 28px; align-items: center; }
731
1489
  .badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
732
1490
 
733
- /* \u2500\u2500 Endpoints grid (2 cols on wide, 1 col on narrow) \u2500\u2500 */
734
- .endpoints-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
735
- @media (max-width: 860px) { .endpoints-grid { grid-template-columns: 1fr; } }
736
- .nested-card { grid-column: 1 / -1; }
1491
+ /* \u2500\u2500 Endpoints list \u2500\u2500 */
1492
+ .endpoints-grid { display: flex; flex-direction: column; gap: 10px; }
737
1493
 
738
1494
  /* \u2500\u2500 Accordion (details/summary) \u2500\u2500 */
739
1495
  .resource-card {
@@ -798,64 +1554,80 @@ function generateAboutHtml(storage, options, handlers = /* @__PURE__ */ new Map(
798
1554
 
799
1555
  <div class="banner">
800
1556
  <div class="banner-inner">
801
- ${LOGO_SRC ? `<img src="${LOGO_SRC}" alt="yRest" height="68" style="display:block;margin-bottom:0px" />` : `<h1><span class="y">y</span><span class="rest">Rest</span></h1>`}
802
- <p>Zero-config REST API mock server</p>
803
- <div class="banner-meta">
804
- <span>URL <strong>${host}</strong></span>
805
- <span>Base <strong>${base || "/"}</strong></span>
806
- <span>File <strong>${options.file}</strong></span>
807
- <span>Collections <strong>${collections.length}</strong></span>
1557
+ <div class="banner-left">
1558
+ ${LOGO_SRC ? `<img src="${LOGO_SRC}" alt="yRest" height="36" style="display:block;margin-bottom:4px" />` : `<h1><span class="y">y</span><span class="rest">Rest</span></h1>`}
1559
+ <p>Zero-config REST API mock server</p>
1560
+ <div class="banner-meta">
1561
+ <span>URL <strong>${host}</strong></span>
1562
+ <span>Base <strong>${base || "/"}</strong></span>
1563
+ <span>File <strong>${options.file}</strong></span>
1564
+ <span>Collections <strong>${collections.length}</strong></span>
1565
+ </div>
1566
+ </div>
1567
+ <div class="api-links">
1568
+ <a href="/_openapi" target="_blank" class="btn-api">OpenAPI YAML</a>
1569
+ <a href="/_openapi.json" target="_blank" class="btn-api">OpenAPI JSON</a>
1570
+ <a href="${swaggerUrl}" target="_blank" class="btn-api btn-swagger">Swagger UI \u2197</a>
808
1571
  </div>
809
1572
  </div>
810
1573
  </div>
811
1574
 
812
1575
  <div class="wrap">
1576
+ <div class="about-grid">
1577
+
1578
+ <div class="col-left">
1579
+ <h2>Active Modes</h2>
1580
+ <div class="card">
1581
+ <div class="modes">${modes.length ? modes.join(" ") : `<span style="color:var(--text-muted);font-size:13px">none</span>`}</div>
1582
+ ${options.watch ? `<div class="warn">\u26A0 <strong>Watch mode:</strong> data changes in existing collections reload automatically. Adding or removing entire collections requires a server restart.</div>` : ""}
1583
+ </div>
1584
+
1585
+ <h2>Endpoints</h2>
1586
+ <div class="endpoints-grid">
1587
+ ${accordions}
1588
+ ${nestedRoutesAccordion(relations, base)}
1589
+ ${options.snapshot ? snapshotAccordion() : ""}
1590
+ ${customRoutesAccordion(customRoutes, base, handlers)}
1591
+ ${handlersAccordion(handlers, customRoutes, base)}
1592
+ </div>
1593
+
1594
+ <h2>Query Parameters</h2>
1595
+ <div class="card">
1596
+ <table class="param-table">
1597
+ <thead><tr><th>Param</th><th>Example</th><th>Description</th></tr></thead>
1598
+ <tbody>
1599
+ <tr><td><code>?field=value</code></td><td><code>?name=Ana&amp;role=admin</code></td><td>Filter by any field. Multiple params are ANDed.</td></tr>
1600
+ <tr><td><code>?field_gte / _lte</code></td><td><code>?price_gte=10&amp;price_lte=50</code></td><td>Numeric or lexicographic range. Works with any comparable field.</td></tr>
1601
+ <tr><td><code>?field_ne</code></td><td><code>?status_ne=inactive</code></td><td>Exclude items where the field equals the value.</td></tr>
1602
+ <tr><td><code>?field_like</code></td><td><code>?name_like=ana</code></td><td>Case-insensitive substring match.</td></tr>
1603
+ <tr><td><code>?field_start</code></td><td><code>?name_start=A</code></td><td>Case-insensitive prefix match.</td></tr>
1604
+ <tr><td><code>?field_regex</code></td><td><code>?email_regex=gmail</code></td><td>Case-insensitive regular expression match.</td></tr>
1605
+ <tr><td><code>?_q</code></td><td><code>?_q=ana</code></td><td>Full-text search across all scalar fields (case-insensitive substring).</td></tr>
1606
+ <tr><td><code>?_sort &amp; ?_order</code></td><td><code>?_sort=name&amp;_order=desc</code></td><td>Sort by field. <code>_order</code>: <code>asc</code> (default) or <code>desc</code>.</td></tr>
1607
+ <tr><td><code>?_page &amp; ?_limit</code></td><td><code>?_page=2&amp;_limit=10</code></td><td>${paginationDesc}</td></tr>
1608
+ <tr><td><code>?_expand</code></td><td><code>?_expand=user</code></td><td>Embed a related parent object inline. Requires <code>_rel</code> in the YAML file.</td></tr>
1609
+ <tr><td><code>?_embed</code></td><td><code>?_embed=posts</code></td><td>Embed child collections into each parent item. Requires <code>_rel</code> in the YAML file.</td></tr>
1610
+ <tr><td><code>?_fields</code></td><td><code>?_fields=id,name</code></td><td>Return only the specified fields. Applied last \u2014 can include embedded/expanded keys.</td></tr>
1611
+ </tbody>
1612
+ </table>
1613
+ </div>
1614
+ </div>
813
1615
 
814
- <h2>Active Modes</h2>
815
- <div class="card">
816
- <div class="modes">${modes.length ? modes.join(" ") : `<span style="color:var(--text-muted);font-size:13px">none</span>`}</div>
817
- ${options.watch ? `<div class="warn">\u26A0 <strong>Watch mode:</strong> data changes in existing collections reload automatically. Adding or removing entire collections requires a server restart.</div>` : ""}
818
- </div>
819
-
820
- <h2>Endpoints</h2>
821
- <div class="endpoints-grid">
822
- ${accordions}
823
- ${nestedRoutesAccordion(relations, base)}
824
- ${options.snapshot ? snapshotAccordion() : ""}
825
- ${customRoutesAccordion(customRoutes, base, handlers)}
826
- ${handlersAccordion(handlers, customRoutes, base)}
827
- </div>
1616
+ <div class="col-right">
1617
+ ${erDiagram}
1618
+ ${collections.length ? `<h2>Examples</h2><div class="card">${examplesBlock(collections, relations, base, host, options, customRoutes[0])}</div>` : ""}
1619
+ </div>
828
1620
 
829
- <h2>Query Parameters</h2>
830
- <div class="card">
831
- <table class="param-table">
832
- <thead><tr><th>Param</th><th>Example</th><th>Description</th></tr></thead>
833
- <tbody>
834
- <tr><td><code>?field=value</code></td><td><code>?name=Ana&amp;role=admin</code></td><td>Filter by any field. Multiple params are ANDed.</td></tr>
835
- <tr><td><code>?field_gte / _lte</code></td><td><code>?price_gte=10&amp;price_lte=50</code></td><td>Numeric or lexicographic range. Works with any comparable field.</td></tr>
836
- <tr><td><code>?field_ne</code></td><td><code>?status_ne=inactive</code></td><td>Exclude items where the field equals the value.</td></tr>
837
- <tr><td><code>?field_like</code></td><td><code>?name_like=ana</code></td><td>Case-insensitive substring match.</td></tr>
838
- <tr><td><code>?field_start</code></td><td><code>?name_start=A</code></td><td>Case-insensitive prefix match.</td></tr>
839
- <tr><td><code>?field_regex</code></td><td><code>?email_regex=gmail</code></td><td>Case-insensitive regular expression match.</td></tr>
840
- <tr><td><code>?_q</code></td><td><code>?_q=ana</code></td><td>Full-text search across all scalar fields (case-insensitive substring).</td></tr>
841
- <tr><td><code>?_sort &amp; ?_order</code></td><td><code>?_sort=name&amp;_order=desc</code></td><td>Sort by field. <code>_order</code>: <code>asc</code> (default) or <code>desc</code>.</td></tr>
842
- <tr><td><code>?_page &amp; ?_limit</code></td><td><code>?_page=2&amp;_limit=10</code></td><td>${paginationDesc}</td></tr>
843
- <tr><td><code>?_expand</code></td><td><code>?_expand=user</code></td><td>Embed a related parent object inline. Requires <code>_rel</code> in the YAML file.</td></tr>
844
- <tr><td><code>?_embed</code></td><td><code>?_embed=posts</code></td><td>Embed child collections into each parent item. Requires <code>_rel</code> in the YAML file.</td></tr>
845
- <tr><td><code>?_fields</code></td><td><code>?_fields=id,name</code></td><td>Return only the specified fields. Applied last \u2014 can include embedded/expanded keys.</td></tr>
846
- </tbody>
847
- </table>
848
1621
  </div>
849
1622
 
850
- ${collections.length ? `<h2>Examples</h2><div class="card">${examplesBlock(collections, relations, base, host, options, customRoutes[0])}</div>` : ""}
851
-
852
1623
  <footer>
853
1624
  Powered by <a href="https://github.com/aggiovato/yRest" target="_blank">@yrest/cli</a> &nbsp;\xB7&nbsp; <a href="/_about">/_about</a>
854
1625
  </footer>
855
1626
 
856
1627
  </div>
857
1628
  </body>
858
- </html>`;
1629
+ </html>`
1630
+ );
859
1631
  }
860
1632
 
861
1633
  // src/router/routes/about.routes.ts
@@ -1456,12 +2228,23 @@ var NestedRouteCommand = class {
1456
2228
  relations;
1457
2229
  base;
1458
2230
  register(server) {
2231
+ const registered = /* @__PURE__ */ new Set();
1459
2232
  for (const [source, fields] of Object.entries(this.relations)) {
1460
2233
  for (const [key, def] of Object.entries(fields)) {
1461
2234
  if (def.type === "many2many") {
1462
- this.registerMany2Many(server, source, key, def);
2235
+ const fwd = `${this.base}/${source}/:id/${key}`;
2236
+ const inv = `${this.base}/${def.target}/:id/${source}`;
2237
+ if (!registered.has(fwd) && !registered.has(inv)) {
2238
+ registered.add(fwd);
2239
+ registered.add(inv);
2240
+ this.registerMany2Many(server, source, key, def);
2241
+ }
1463
2242
  } else {
1464
- this.registerFkRelation(server, source, key, def.target, def.type);
2243
+ const collPath = `${this.base}/${def.target}/:id/${source}`;
2244
+ if (!registered.has(collPath)) {
2245
+ registered.add(collPath);
2246
+ this.registerFkRelation(server, source, key, def.target, def.type);
2247
+ }
1465
2248
  }
1466
2249
  }
1467
2250
  }