ts-prorm-orm 1.2.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +209 -0
- package/README.md +32 -24
- package/dist/compliance/index.d.ts +2 -0
- package/dist/compliance/index.js +13 -1
- package/dist/connection-manager.js +13 -1
- package/dist/core/expressions.d.ts +58 -0
- package/dist/core/expressions.js +83 -0
- package/dist/core/hooks-manager.d.ts +179 -0
- package/dist/core/hooks-manager.js +291 -0
- package/dist/core/types.d.ts +235 -0
- package/dist/core/types.js +9 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +11 -1
- package/dist/diagrams/chen-diagram.d.ts +15 -12
- package/dist/diagrams/chen-diagram.js +76 -85
- package/dist/diagrams/class-diagram.d.ts +9 -8
- package/dist/diagrams/class-diagram.js +60 -82
- package/dist/diagrams/core/index.d.ts +13 -0
- package/dist/diagrams/core/index.js +33 -0
- package/dist/diagrams/core/layout.d.ts +104 -0
- package/dist/diagrams/core/layout.js +223 -0
- package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
- package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
- package/dist/diagrams/core/theme.d.ts +84 -0
- package/dist/diagrams/core/theme.js +62 -0
- package/dist/diagrams/dependency-diagram.d.ts +15 -14
- package/dist/diagrams/dependency-diagram.js +71 -105
- package/dist/diagrams/er-diagram.d.ts +13 -26
- package/dist/diagrams/er-diagram.js +180 -259
- package/dist/diagrams/flow-diagram.d.ts +16 -11
- package/dist/diagrams/flow-diagram.js +96 -91
- package/dist/diagrams/gantt-diagram.d.ts +10 -5
- package/dist/diagrams/gantt-diagram.js +77 -103
- package/dist/diagrams/index-diagram.d.ts +10 -10
- package/dist/diagrams/index-diagram.js +106 -116
- package/dist/diagrams/index.d.ts +6 -9
- package/dist/diagrams/index.js +9 -24
- package/dist/diagrams/migration-diagram.d.ts +8 -4
- package/dist/diagrams/migration-diagram.js +189 -161
- package/dist/diagrams/model-diagram.d.ts +34 -34
- package/dist/diagrams/model-diagram.js +106 -485
- package/dist/diagrams/package-diagram.d.ts +9 -6
- package/dist/diagrams/package-diagram.js +64 -101
- package/dist/diagrams/relational-diagram.d.ts +12 -10
- package/dist/diagrams/relational-diagram.js +87 -114
- package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
- package/dist/diagrams/schemadoc-diagram.js +71 -93
- package/dist/diagrams/sequence-diagram.d.ts +10 -10
- package/dist/diagrams/sequence-diagram.js +64 -89
- package/dist/diagrams/state-diagram.d.ts +10 -9
- package/dist/diagrams/state-diagram.js +69 -92
- package/dist/diagrams/tree-diagram.d.ts +11 -5
- package/dist/diagrams/tree-diagram.js +41 -65
- package/dist/dialects/clickhouse/index.js +15 -0
- package/dist/dialects/cockroachdb/index.d.ts +1 -1
- package/dist/dialects/cockroachdb/index.js +32 -63
- package/dist/dialects/db2/index.js +23 -8
- package/dist/dialects/dialect.d.ts +29 -5
- package/dist/dialects/duckdb/index.js +9 -2
- package/dist/dialects/hana/index.js +22 -5
- package/dist/dialects/lock-clause-helper.d.ts +167 -0
- package/dist/dialects/lock-clause-helper.js +316 -0
- package/dist/dialects/mariadb/index.d.ts +7 -4
- package/dist/dialects/mariadb/index.js +36 -60
- package/dist/dialects/mssql/index.js +34 -3
- package/dist/dialects/mysql/index.d.ts +1 -1
- package/dist/dialects/mysql/index.js +17 -45
- package/dist/dialects/oracle/index.d.ts +14 -3
- package/dist/dialects/oracle/index.js +66 -36
- package/dist/dialects/order-expression-helper.d.ts +72 -0
- package/dist/dialects/order-expression-helper.js +154 -0
- package/dist/dialects/partial-index.d.ts +52 -0
- package/dist/dialects/partial-index.js +251 -0
- package/dist/dialects/postgres/index.d.ts +1 -1
- package/dist/dialects/postgres/index.js +43 -68
- package/dist/dialects/redshift/index.js +9 -2
- package/dist/dialects/snowflake/index.js +17 -0
- package/dist/dialects/spanner/index.js +7 -2
- package/dist/dialects/sqlite/driver.d.ts +55 -0
- package/dist/dialects/sqlite/driver.js +102 -0
- package/dist/dialects/sqlite/index.d.ts +1 -1
- package/dist/dialects/sqlite/index.js +49 -27
- package/dist/graph/base-graph-dialect.d.ts +24 -3
- package/dist/graph/base-graph-dialect.js +43 -2
- package/dist/graph/dgraph/index.js +6 -0
- package/dist/graph/gremlin/index.d.ts +6 -0
- package/dist/graph/gremlin/index.js +12 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/neo4j/index.d.ts +2 -0
- package/dist/graph/neo4j/index.js +6 -1
- package/dist/graph/types.d.ts +12 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.js +54 -7
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.js +23 -0
- package/dist/logging/query-logging.d.ts +82 -0
- package/dist/logging/query-logging.js +102 -0
- package/dist/models/decorators.d.ts +39 -3
- package/dist/models/decorators.js +74 -0
- package/dist/models/eager-load.d.ts +99 -0
- package/dist/models/eager-load.js +348 -5
- package/dist/models/indexes.d.ts +3 -2
- package/dist/models/indexes.js +7 -1
- package/dist/models/model.js +69 -43
- package/dist/prorm.d.ts +175 -409
- package/dist/prorm.js +1142 -557
- package/dist/query-builders/order-limit-builder.js +12 -10
- package/dist/query-builders/sql-compiler.d.ts +10 -3
- package/dist/query-builders/sql-compiler.js +14 -43
- package/dist/query-interface.d.ts +2 -1
- package/dist/sql-constants.d.ts +44 -0
- package/dist/sql-constants.js +138 -1
- package/dist/types/index.d.ts +53 -17
- package/dist/types/index.js +10 -15
- package/dist/types/query-types.d.ts +26 -0
- package/dist/types/query-types.js +30 -0
- package/package.json +32 -5
- package/dist/decorators/belongs-to-many.js +0 -115
- package/dist/decorators/belongs-to.js +0 -115
- package/dist/decorators/has-many.js +0 -127
- package/dist/decorators/has-one.js +0 -116
- package/dist/diagrams/palette.d.ts +0 -138
- package/dist/diagrams/palette.js +0 -194
- package/dist/hooks/hooks-manager.d.ts +0 -189
- package/dist/hooks/hooks-manager.js +0 -350
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -37
- /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
- /package/dist/{logging.js → logging/logger.js} +0 -0
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* DependencyDiagram
|
|
3
|
+
* DependencyDiagram - renders a directed dependency graph of models/tables.
|
|
4
4
|
*
|
|
5
|
-
* Nodes are models/tables; a directed edge `from
|
|
5
|
+
* Nodes are models/tables; a directed edge `from -> to` means "from depends on
|
|
6
6
|
* to" (e.g. table `from` holds a foreign key into table `to`). The generator:
|
|
7
7
|
*
|
|
8
8
|
* - Computes a layered / topological layout: each node's layer is the longest
|
|
9
9
|
* dependency path to a leaf. Nodes with no dependencies sit in layer 0;
|
|
10
10
|
* their dependents fan out into higher layers.
|
|
11
11
|
* - Detects cycles (back edges) with a DFS colouring pass and visually flags
|
|
12
|
-
* the cyclic edges
|
|
13
|
-
* so a cycle can never send it into an infinite loop.
|
|
14
|
-
* - Draws each node as a labelled
|
|
12
|
+
* the cyclic edges with a heavier dashed stroke. The layering pass carries
|
|
13
|
+
* its own visited guard so a cycle can never send it into an infinite loop.
|
|
14
|
+
* - Draws each node as a labelled box sized to its label, with arrows
|
|
15
15
|
* between dependent boxes.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* (`light` | `dark`) drives the canvas + text colours. Both genuinely change
|
|
19
|
-
* real fill/stroke values in the emitted SVG. The viewBox auto-sizes to the
|
|
20
|
-
* computed layout.
|
|
17
|
+
* The viewBox auto-sizes to the computed layout.
|
|
21
18
|
*
|
|
22
19
|
* Usage:
|
|
23
20
|
* const d = new DependencyDiagram({ nodes, edges, title: 'Schema deps' });
|
|
@@ -61,18 +58,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
61
58
|
exports.DependencyDiagram = void 0;
|
|
62
59
|
const fs = __importStar(require("fs"));
|
|
63
60
|
const path = __importStar(require("path"));
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
// Barlow / JetBrains Mono typography, hairline borders and square "blueprint"
|
|
68
|
-
// corners are fixed by the Industry spec; accent + surface colours still route
|
|
69
|
-
// through resolveAccent / resolveTheme so --color / --theme keep working.
|
|
70
|
-
const IND_FONT_HEAD = '"Barlow Condensed", system-ui, sans-serif';
|
|
71
|
-
const IND_FONT_BODY = '"Barlow", system-ui, sans-serif';
|
|
72
|
-
const IND_FONT_MONO = 'ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace';
|
|
73
|
-
const IND_HAIRLINE = 'rgba(29,31,32,0.16)';
|
|
74
|
-
const IND_FONT_IMPORT = "@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;700&family=Barlow+Condensed:wght@400;600&family=JetBrains+Mono&display=swap');";
|
|
75
|
-
// ─── Main class ──────────────────────────────────────────────────────────────
|
|
61
|
+
const svg_1 = require("./core/svg");
|
|
62
|
+
const theme_1 = require("./core/theme");
|
|
63
|
+
const layout_1 = require("./core/layout");
|
|
76
64
|
class DependencyDiagram {
|
|
77
65
|
constructor(options) {
|
|
78
66
|
this.opts = {
|
|
@@ -84,8 +72,8 @@ class DependencyDiagram {
|
|
|
84
72
|
edges: options.edges ?? [],
|
|
85
73
|
};
|
|
86
74
|
}
|
|
87
|
-
//
|
|
88
|
-
/** Adjacency: node
|
|
75
|
+
// -- Graph analysis --------------------------------------------------------
|
|
76
|
+
/** Adjacency: node -> the nodes it depends on (its outgoing edge targets). */
|
|
89
77
|
buildAdjacency(names) {
|
|
90
78
|
const adj = new Map();
|
|
91
79
|
for (const n of names)
|
|
@@ -111,7 +99,7 @@ class DependencyDiagram {
|
|
|
111
99
|
if (layer.has(node))
|
|
112
100
|
return layer.get(node);
|
|
113
101
|
if (onStack.has(node))
|
|
114
|
-
return 0; // cycle guard
|
|
102
|
+
return 0; // cycle guard - break the recursion
|
|
115
103
|
onStack.add(node);
|
|
116
104
|
let best = 0;
|
|
117
105
|
for (const dep of adj.get(node) ?? []) {
|
|
@@ -126,7 +114,7 @@ class DependencyDiagram {
|
|
|
126
114
|
return layer;
|
|
127
115
|
}
|
|
128
116
|
/**
|
|
129
|
-
* Detect cyclic edges via DFS colouring. Returns a set of "from
|
|
117
|
+
* Detect cyclic edges via DFS colouring. Returns a set of "from-to" keys that
|
|
130
118
|
* are back edges (participate in a cycle).
|
|
131
119
|
*/
|
|
132
120
|
detectCyclicEdges(names, adj) {
|
|
@@ -142,7 +130,7 @@ class DependencyDiagram {
|
|
|
142
130
|
for (const dep of adj.get(node) ?? []) {
|
|
143
131
|
const c = color.get(dep);
|
|
144
132
|
if (c === GRAY) {
|
|
145
|
-
cyclic.add(`${node}${dep}`); // back edge
|
|
133
|
+
cyclic.add(`${node}${dep}`); // back edge -> cycle
|
|
146
134
|
}
|
|
147
135
|
else if (c === WHITE) {
|
|
148
136
|
dfs(dep);
|
|
@@ -155,13 +143,13 @@ class DependencyDiagram {
|
|
|
155
143
|
dfs(n);
|
|
156
144
|
return cyclic;
|
|
157
145
|
}
|
|
158
|
-
//
|
|
146
|
+
// -- Geometry helpers -------------------------------------------------------
|
|
159
147
|
nodeWidth(name) {
|
|
160
148
|
return Math.max(DependencyDiagram.MIN_NODE_W, Math.round(name.length * DependencyDiagram.CHAR_W + DependencyDiagram.NODE_PAD_X * 2));
|
|
161
149
|
}
|
|
162
150
|
/**
|
|
163
151
|
* Point on the boundary of a rectangle along the line from the rect centre
|
|
164
|
-
* toward an external point
|
|
152
|
+
* toward an external point - used so arrowheads land on the box edge.
|
|
165
153
|
*/
|
|
166
154
|
edgePoint(node, tx, ty) {
|
|
167
155
|
const cx = node.x + node.w / 2;
|
|
@@ -177,19 +165,14 @@ class DependencyDiagram {
|
|
|
177
165
|
const scale = Math.min(scaleX, scaleY);
|
|
178
166
|
return { x: cx + dx * scale, y: cy + dy * scale };
|
|
179
167
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const { title, theme, color, direction } = this.opts;
|
|
183
|
-
const accent = (0, palette_1.resolveAccent)(color);
|
|
184
|
-
const palettes = (0, palette_1.rotatedPalettes)(color);
|
|
185
|
-
const t = (0, palette_1.resolveTheme)(theme);
|
|
168
|
+
build() {
|
|
169
|
+
const { title, direction } = this.opts;
|
|
186
170
|
const horizontal = direction !== 'vertical';
|
|
187
171
|
const PAD = DependencyDiagram.PAD;
|
|
188
172
|
const TITLE_H = DependencyDiagram.TITLE_H;
|
|
189
173
|
const NODE_H = DependencyDiagram.NODE_H;
|
|
190
174
|
const LAYER_GAP = DependencyDiagram.LAYER_GAP;
|
|
191
175
|
const NODE_GAP = DependencyDiagram.NODE_GAP;
|
|
192
|
-
const R = DependencyDiagram.R;
|
|
193
176
|
// De-duplicate nodes by name, preserving first occurrence.
|
|
194
177
|
const seen = new Set();
|
|
195
178
|
const nodeDefs = [];
|
|
@@ -212,20 +195,10 @@ class DependencyDiagram {
|
|
|
212
195
|
}
|
|
213
196
|
for (let i = 0; i < layersArr.length; i++)
|
|
214
197
|
layersArr[i] ?? (layersArr[i] = []);
|
|
215
|
-
//
|
|
216
|
-
const groupPalette = new Map();
|
|
217
|
-
let gi = 0;
|
|
218
|
-
for (const n of nodeDefs) {
|
|
219
|
-
const g = n.group;
|
|
220
|
-
if (g && !groupPalette.has(g)) {
|
|
221
|
-
groupPalette.set(g, palettes[gi % palettes.length]);
|
|
222
|
-
gi++;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// ── Compute placements ──────────────────────────────────────────────
|
|
198
|
+
// Compute placements.
|
|
226
199
|
const placed = new Map();
|
|
227
200
|
if (horizontal) {
|
|
228
|
-
// Layers = columns (left
|
|
201
|
+
// Layers = columns (left to right). Nodes stacked vertically within a column.
|
|
229
202
|
const layerW = layersArr.map((layer) => layer.reduce((m, n) => Math.max(m, this.nodeWidth(n.name)), DependencyDiagram.MIN_NODE_W));
|
|
230
203
|
const colX = [];
|
|
231
204
|
let cursor = PAD;
|
|
@@ -239,12 +212,12 @@ class DependencyDiagram {
|
|
|
239
212
|
const w = this.nodeWidth(n.name);
|
|
240
213
|
const x = colX[l] + (layerW[l] - w) / 2;
|
|
241
214
|
const y = contentTop + slot * (NODE_H + NODE_GAP);
|
|
242
|
-
this.place(placed, n, l, slot, x, y, w, NODE_H
|
|
215
|
+
this.place(placed, n, l, slot, x, y, w, NODE_H);
|
|
243
216
|
});
|
|
244
217
|
}
|
|
245
218
|
}
|
|
246
219
|
else {
|
|
247
|
-
// Layers = rows (top
|
|
220
|
+
// Layers = rows (top to bottom). Nodes spread horizontally within a row.
|
|
248
221
|
const colW = names.reduce((m, nm) => Math.max(m, this.nodeWidth(nm)), DependencyDiagram.MIN_NODE_W);
|
|
249
222
|
const contentLeft = PAD;
|
|
250
223
|
for (let l = 0; l < layersArr.length; l++) {
|
|
@@ -252,11 +225,11 @@ class DependencyDiagram {
|
|
|
252
225
|
layersArr[l].forEach((n, slot) => {
|
|
253
226
|
const w = this.nodeWidth(n.name);
|
|
254
227
|
const x = contentLeft + slot * (colW + NODE_GAP) + (colW - w) / 2;
|
|
255
|
-
this.place(placed, n, l, slot, x, y, w, NODE_H
|
|
228
|
+
this.place(placed, n, l, slot, x, y, w, NODE_H);
|
|
256
229
|
});
|
|
257
230
|
}
|
|
258
231
|
}
|
|
259
|
-
//
|
|
232
|
+
// Auto-size the canvas.
|
|
260
233
|
let maxX = 0;
|
|
261
234
|
let maxY = 0;
|
|
262
235
|
for (const p of placed.values()) {
|
|
@@ -265,37 +238,33 @@ class DependencyDiagram {
|
|
|
265
238
|
}
|
|
266
239
|
const svgW = Math.round(maxX + PAD);
|
|
267
240
|
const svgH = Math.round(maxY + PAD);
|
|
268
|
-
|
|
269
|
-
const doc = new svg_dom_1.SvgDocument(svgW, svgH);
|
|
241
|
+
const doc = new svg_1.SvgDocument(svgW, svgH);
|
|
270
242
|
const svg = doc.root;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.defineArrow(doc, 'depArrow', accent.mid);
|
|
277
|
-
this.defineArrow(doc, 'depArrowCycle', CYCLE_COLOR);
|
|
278
|
-
// Title
|
|
243
|
+
svg.child('rect', { width: svgW, height: svgH, fill: theme_1.INK.ground });
|
|
244
|
+
// Arrowhead markers: a plain arrow, and a heavier one for cyclic edges.
|
|
245
|
+
this.defineArrow(doc, 'depArrow', theme_1.STROKE.hair);
|
|
246
|
+
this.defineArrow(doc, 'depArrowCycle', theme_1.STROKE.heavy);
|
|
247
|
+
// Title.
|
|
279
248
|
svg
|
|
280
249
|
.child('text', {
|
|
281
250
|
x: PAD,
|
|
282
251
|
y: PAD + 6,
|
|
283
|
-
'font-family':
|
|
284
|
-
'font-size':
|
|
285
|
-
'font-weight':
|
|
286
|
-
fill:
|
|
252
|
+
'font-family': theme_1.FONT.family,
|
|
253
|
+
'font-size': theme_1.FONT.title + 9,
|
|
254
|
+
'font-weight': 'bold',
|
|
255
|
+
fill: theme_1.INK.line,
|
|
287
256
|
})
|
|
288
257
|
.text(title);
|
|
289
258
|
svg
|
|
290
259
|
.child('text', {
|
|
291
260
|
x: PAD,
|
|
292
261
|
y: PAD + 26,
|
|
293
|
-
'font-family':
|
|
294
|
-
'font-size':
|
|
295
|
-
fill:
|
|
262
|
+
'font-family': theme_1.FONT.family,
|
|
263
|
+
'font-size': theme_1.FONT.small + 2,
|
|
264
|
+
fill: theme_1.INK.muted,
|
|
296
265
|
})
|
|
297
|
-
.text(`${placed.size} node${placed.size !== 1 ? 's' : ''}
|
|
298
|
-
//
|
|
266
|
+
.text(`${placed.size} node${placed.size !== 1 ? 's' : ''}, ${this.opts.edges.length} edge${this.opts.edges.length !== 1 ? 's' : ''}${cyclicEdges.size ? `, ${cyclicEdges.size} cyclic` : ''}`);
|
|
267
|
+
// Edges, drawn before nodes so boxes sit on top.
|
|
299
268
|
const edgeLayer = svg.child('g', { 'stroke-linecap': 'round' });
|
|
300
269
|
for (const e of this.opts.edges) {
|
|
301
270
|
const from = placed.get(e.from);
|
|
@@ -304,7 +273,7 @@ class DependencyDiagram {
|
|
|
304
273
|
continue;
|
|
305
274
|
const isCyclic = cyclicEdges.has(`${e.from}${e.to}`);
|
|
306
275
|
const isSelf = e.from === e.to;
|
|
307
|
-
const
|
|
276
|
+
const strokeWidth = isCyclic ? theme_1.STROKE.heavy : theme_1.STROKE.hair;
|
|
308
277
|
const marker = isCyclic ? 'url(#depArrowCycle)' : 'url(#depArrow)';
|
|
309
278
|
if (isSelf) {
|
|
310
279
|
// Self-dependency: small loop above the node.
|
|
@@ -313,8 +282,8 @@ class DependencyDiagram {
|
|
|
313
282
|
edgeLayer.child('path', {
|
|
314
283
|
d: `M ${lx - 10} ${ly} C ${lx - 26} ${ly - 34}, ${lx + 26} ${ly - 34}, ${lx + 10} ${ly}`,
|
|
315
284
|
fill: 'none',
|
|
316
|
-
stroke,
|
|
317
|
-
'stroke-width':
|
|
285
|
+
stroke: theme_1.INK.line,
|
|
286
|
+
'stroke-width': strokeWidth,
|
|
318
287
|
'stroke-dasharray': isCyclic ? '6 4' : undefined,
|
|
319
288
|
'marker-end': marker,
|
|
320
289
|
});
|
|
@@ -331,8 +300,8 @@ class DependencyDiagram {
|
|
|
331
300
|
y1: start.y,
|
|
332
301
|
x2: end.x,
|
|
333
302
|
y2: end.y,
|
|
334
|
-
stroke,
|
|
335
|
-
'stroke-width':
|
|
303
|
+
stroke: theme_1.INK.line,
|
|
304
|
+
'stroke-width': strokeWidth,
|
|
336
305
|
'stroke-dasharray': isCyclic ? '6 4' : undefined,
|
|
337
306
|
'marker-end': marker,
|
|
338
307
|
});
|
|
@@ -341,15 +310,15 @@ class DependencyDiagram {
|
|
|
341
310
|
.child('text', {
|
|
342
311
|
x: (start.x + end.x) / 2,
|
|
343
312
|
y: (start.y + end.y) / 2 - 4,
|
|
344
|
-
'font-family':
|
|
345
|
-
'font-size':
|
|
346
|
-
fill:
|
|
313
|
+
'font-family': theme_1.FONT.mono,
|
|
314
|
+
'font-size': theme_1.FONT.small - 1,
|
|
315
|
+
fill: theme_1.INK.muted,
|
|
347
316
|
'text-anchor': 'middle',
|
|
348
317
|
})
|
|
349
318
|
.text(e.label);
|
|
350
319
|
}
|
|
351
320
|
}
|
|
352
|
-
//
|
|
321
|
+
// Nodes.
|
|
353
322
|
for (const n of nodeDefs) {
|
|
354
323
|
const p = placed.get(n.name);
|
|
355
324
|
if (!p)
|
|
@@ -360,35 +329,36 @@ class DependencyDiagram {
|
|
|
360
329
|
y: p.y,
|
|
361
330
|
width: p.w,
|
|
362
331
|
height: p.h,
|
|
363
|
-
fill:
|
|
364
|
-
stroke:
|
|
365
|
-
'stroke-width':
|
|
332
|
+
fill: theme_1.INK.wash,
|
|
333
|
+
stroke: theme_1.INK.line,
|
|
334
|
+
'stroke-width': theme_1.STROKE.hair,
|
|
366
335
|
});
|
|
367
336
|
g.child('text', {
|
|
368
337
|
x: p.x + p.w / 2,
|
|
369
338
|
y: p.y + p.h / 2 + 5,
|
|
370
|
-
'font-family':
|
|
371
|
-
'font-size':
|
|
372
|
-
'font-weight':
|
|
373
|
-
fill:
|
|
339
|
+
'font-family': theme_1.FONT.mono,
|
|
340
|
+
'font-size': theme_1.FONT.body + 3,
|
|
341
|
+
'font-weight': 'bold',
|
|
342
|
+
fill: theme_1.INK.line,
|
|
374
343
|
'text-anchor': 'middle',
|
|
375
|
-
}).text(n.name);
|
|
344
|
+
}).text((0, layout_1.truncate)(n.name, p.w - 8, theme_1.FONT.body + 3, true));
|
|
376
345
|
// Layer badge on the box shoulder.
|
|
377
346
|
g.child('text', {
|
|
378
347
|
x: p.x + 8,
|
|
379
348
|
y: p.y + 13,
|
|
380
|
-
'font-family':
|
|
381
|
-
'font-size':
|
|
382
|
-
'font-weight':
|
|
383
|
-
fill:
|
|
384
|
-
opacity: 0.55,
|
|
349
|
+
'font-family': theme_1.FONT.family,
|
|
350
|
+
'font-size': theme_1.FONT.small - 1,
|
|
351
|
+
'font-weight': 'bold',
|
|
352
|
+
fill: theme_1.INK.muted,
|
|
385
353
|
}).text(`L${p.layer}`);
|
|
386
354
|
}
|
|
387
|
-
return doc
|
|
355
|
+
return doc;
|
|
356
|
+
}
|
|
357
|
+
generate() {
|
|
358
|
+
return this.build().toString('Generated by ts-prorm-orm DependencyDiagram');
|
|
388
359
|
}
|
|
389
|
-
//
|
|
390
|
-
place(placed, n, layer, slot, x, y, w, h
|
|
391
|
-
const pal = (n.group && groupPalette.get(n.group)) || accent;
|
|
360
|
+
// -- place() records a node's geometry -------------------------------------
|
|
361
|
+
place(placed, n, layer, slot, x, y, w, h) {
|
|
392
362
|
placed.set(n.name, {
|
|
393
363
|
name: n.name,
|
|
394
364
|
group: n.group,
|
|
@@ -398,23 +368,20 @@ class DependencyDiagram {
|
|
|
398
368
|
y,
|
|
399
369
|
w,
|
|
400
370
|
h,
|
|
401
|
-
fill: pal.light,
|
|
402
|
-
stroke: pal.mid,
|
|
403
|
-
text: pal.text,
|
|
404
371
|
});
|
|
405
372
|
}
|
|
406
|
-
//
|
|
407
|
-
defineArrow(doc, id,
|
|
373
|
+
// -- Arrowhead marker in <defs> ---------------------------------------------
|
|
374
|
+
defineArrow(doc, id, strokeWidth) {
|
|
408
375
|
const marker = doc.defs().child('marker', {
|
|
409
376
|
id,
|
|
410
377
|
viewBox: '0 0 10 10',
|
|
411
378
|
refX: 9,
|
|
412
379
|
refY: 5,
|
|
413
|
-
markerWidth: 7,
|
|
414
|
-
markerHeight: 7,
|
|
380
|
+
markerWidth: strokeWidth === theme_1.STROKE.heavy ? 8 : 7,
|
|
381
|
+
markerHeight: strokeWidth === theme_1.STROKE.heavy ? 8 : 7,
|
|
415
382
|
orient: 'auto-start-reverse',
|
|
416
383
|
});
|
|
417
|
-
marker.child('path', { d: 'M 0 0 L 10 5 L 0 10 z', fill:
|
|
384
|
+
marker.child('path', { d: 'M 0 0 L 10 5 L 0 10 z', fill: theme_1.INK.line });
|
|
418
385
|
}
|
|
419
386
|
/**
|
|
420
387
|
* Write the SVG to a file, creating parent directories as needed.
|
|
@@ -438,4 +405,3 @@ DependencyDiagram.NODE_PAD_X = 22;
|
|
|
438
405
|
DependencyDiagram.MIN_NODE_W = 72;
|
|
439
406
|
DependencyDiagram.LAYER_GAP = 90; // gap between layer columns/rows
|
|
440
407
|
DependencyDiagram.NODE_GAP = 26; // gap between nodes in a layer
|
|
441
|
-
DependencyDiagram.R = 9;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ERDiagram
|
|
3
|
-
* a collection of ORM models and their associations
|
|
4
|
-
* blueprint design system.
|
|
2
|
+
* ERDiagram - generates a fully-rendered Entity-Relationship diagram SVG for
|
|
3
|
+
* a collection of ORM models and their associations.
|
|
5
4
|
*
|
|
6
5
|
* Look:
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* accent / accent-2 (two-tone) header bar — no vibrant gradients or shadows
|
|
11
|
-
* - Compact rows: name (mono) + type (mono, neutral) + PK/FK marks
|
|
6
|
+
* - White entity cards on a grid: square corners, 1px hairline borders, a
|
|
7
|
+
* solid header bar - no gradients or shadows
|
|
8
|
+
* - Compact rows: name (mono) + type (mono, muted) + PK/FK marks
|
|
12
9
|
* - Hairline crow's-foot relationship connectors with mono cardinality marks
|
|
13
|
-
* - Legend bottom-right
|
|
14
|
-
* - Fully self-contained SVG (
|
|
10
|
+
* - Legend bottom-right
|
|
11
|
+
* - Fully self-contained SVG (system font stack, no web-font import)
|
|
15
12
|
*
|
|
16
13
|
* Usage:
|
|
17
14
|
* const er = new ERDiagram({
|
|
@@ -35,9 +32,12 @@ export interface ERDiagramOptions {
|
|
|
35
32
|
hGap?: number;
|
|
36
33
|
/** Vertical gap between entity boxes (px) */
|
|
37
34
|
vGap?: number;
|
|
38
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Accepted for backward compatibility and ignored: diagrams render in a
|
|
37
|
+
* single monochrome theme.
|
|
38
|
+
*/
|
|
39
39
|
theme?: 'light' | 'dark';
|
|
40
|
-
/**
|
|
40
|
+
/** Accepted for backward compatibility and ignored. */
|
|
41
41
|
color?: string;
|
|
42
42
|
}
|
|
43
43
|
export declare class ERDiagram {
|
|
@@ -51,15 +51,7 @@ export declare class ERDiagram {
|
|
|
51
51
|
private static readonly LEGEND_W;
|
|
52
52
|
private static readonly LEGEND_PAD;
|
|
53
53
|
private static readonly MARGIN;
|
|
54
|
-
private accentMid;
|
|
55
|
-
private accentText;
|
|
56
|
-
private accentLight;
|
|
57
|
-
private accent2Mid;
|
|
58
|
-
private accent2Text;
|
|
59
|
-
private accent2Light;
|
|
60
54
|
constructor(options: ERDiagramOptions);
|
|
61
|
-
/** Two-tone entity styling — even entities accent, odd accent-2. */
|
|
62
|
-
private entityStyle;
|
|
63
55
|
private boxHeight;
|
|
64
56
|
private computeLayout;
|
|
65
57
|
private renderBox;
|
|
@@ -68,12 +60,7 @@ export declare class ERDiagram {
|
|
|
68
60
|
private singleBar;
|
|
69
61
|
private renderBanner;
|
|
70
62
|
private renderLegend;
|
|
71
|
-
|
|
72
|
-
* Embedded font @import so browsers resolve Barlow / JetBrains Mono. Wrapped
|
|
73
|
-
* in CDATA because the Google-Fonts URL contains raw `&` separators that
|
|
74
|
-
* would otherwise be invalid XML in this string-built document.
|
|
75
|
-
*/
|
|
76
|
-
private fontDefs;
|
|
63
|
+
private build;
|
|
77
64
|
generate(): string;
|
|
78
65
|
/**
|
|
79
66
|
* Write the SVG to a file. Creates parent directories if needed.
|