@constructive-io/schema-builder 0.2.0 → 0.2.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/CHANGELOG.md +11 -0
- package/dist/card-widths-CmIxkRfh.cjs +28 -0
- package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
- package/dist/card-widths-pI4Kw4Xz.js +22 -0
- package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
- package/dist/core-WwCS0CKu.cjs +66 -0
- package/dist/core-WwCS0CKu.cjs.map +1 -0
- package/dist/core-kx6KjxE5.js +49 -0
- package/dist/core-kx6KjxE5.js.map +1 -0
- package/dist/core.cjs +14 -212
- package/dist/core.d.cts +3 -54
- package/dist/core.d.ts +3 -54
- package/dist/core.js +3 -200
- package/dist/create-table-card-BzNKfpXO.cjs +7726 -0
- package/dist/create-table-card-BzNKfpXO.cjs.map +1 -0
- package/dist/create-table-card-pZ0Aq6rr.js +7685 -0
- package/dist/create-table-card-pZ0Aq6rr.js.map +1 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
- package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
- package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
- package/dist/empty-state-card-DMn8ADRq.cjs +62 -0
- package/dist/empty-state-card-DMn8ADRq.cjs.map +1 -0
- package/dist/empty-state-card-Dnn36JVH.js +57 -0
- package/dist/empty-state-card-Dnn36JVH.js.map +1 -0
- package/dist/fields.cjs +8 -7763
- package/dist/fields.d.cts +39 -39
- package/dist/fields.d.ts +39 -39
- package/dist/fields.js +2 -7735
- package/dist/generated-types-DZMUyNBH.d.cts +27 -0
- package/dist/generated-types-DZMUyNBH.d.ts +27 -0
- package/dist/index-9h0EROdb.d.cts +56 -0
- package/dist/index-CwQ9QpxA.d.ts +7 -0
- package/dist/index-DOWB1UBK.d.cts +56 -0
- package/dist/index-DOWB1UBK.d.ts +56 -0
- package/dist/index-Dgb_e3AP.d.cts +7 -0
- package/dist/index-p_NegPQ5.d.ts +56 -0
- package/dist/index.cjs +736 -13712
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +725 -13680
- package/dist/index.js.map +1 -1
- package/dist/indexes-view-CJ1WQKdp.js +736 -0
- package/dist/indexes-view-CJ1WQKdp.js.map +1 -0
- package/dist/indexes-view-peIv6QUZ.cjs +759 -0
- package/dist/indexes-view-peIv6QUZ.cjs.map +1 -0
- package/dist/indexes.cjs +6 -1041
- package/dist/indexes.d.cts +27 -27
- package/dist/indexes.d.ts +27 -27
- package/dist/indexes.js +2 -1016
- package/dist/invalidate-database-entities-9DsT5NlP.cjs +2862 -0
- package/dist/invalidate-database-entities-9DsT5NlP.cjs.map +1 -0
- package/dist/invalidate-database-entities-CmmOT3S0.js +2559 -0
- package/dist/invalidate-database-entities-CmmOT3S0.js.map +1 -0
- package/dist/keyboard-activation-BQiV0scm.js +13 -0
- package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
- package/dist/policies-view-BRbpbyB6.js +1018 -0
- package/dist/policies-view-BRbpbyB6.js.map +1 -0
- package/dist/policies-view-H1HTjpmv.cjs +1023 -0
- package/dist/policies-view-H1HTjpmv.cjs.map +1 -0
- package/dist/policies.cjs +10 -5939
- package/dist/policies.d.cts +55 -50
- package/dist/policies.d.ts +55 -50
- package/dist/policies.js +4 -5911
- package/dist/policy-config-form-BwyK7DGV.js +2502 -0
- package/dist/policy-config-form-BwyK7DGV.js.map +1 -0
- package/dist/policy-config-form-CefFo6Fw.cjs +2629 -0
- package/dist/policy-config-form-CefFo6Fw.cjs.map +1 -0
- package/dist/policy-types-D_sYWb-b.d.cts +81 -0
- package/dist/policy-types-D_sYWb-b.d.ts +81 -0
- package/dist/query-BmN_qO0W.js +171 -0
- package/dist/query-BmN_qO0W.js.map +1 -0
- package/dist/query-DU-KZleN.cjs +212 -0
- package/dist/query-DU-KZleN.cjs.map +1 -0
- package/dist/relationships-view-B5TAcPHU.cjs +2452 -0
- package/dist/relationships-view-B5TAcPHU.cjs.map +1 -0
- package/dist/relationships-view-DbwFh5r-.js +2417 -0
- package/dist/relationships-view-DbwFh5r-.js.map +1 -0
- package/dist/relationships.cjs +9 -4328
- package/dist/relationships.d.cts +93 -92
- package/dist/relationships.d.ts +93 -92
- package/dist/relationships.js +2 -4300
- package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
- package/dist/schema-builder-sidebar-Ctu621Vw.cjs +604 -0
- package/dist/schema-builder-sidebar-Ctu621Vw.cjs.map +1 -0
- package/dist/schema-builder-sidebar-VR-Ctidc.js +593 -0
- package/dist/schema-builder-sidebar-VR-Ctidc.js.map +1 -0
- package/dist/table-editor-C-hHz3DJ.cjs +1935 -0
- package/dist/table-editor-C-hHz3DJ.cjs.map +1 -0
- package/dist/table-editor-IVp3B4nG.js +1906 -0
- package/dist/table-editor-IVp3B4nG.js.map +1 -0
- package/dist/tables.cjs +6 -5643
- package/dist/tables.d.cts +22 -21
- package/dist/tables.d.ts +22 -21
- package/dist/tables.js +3 -5618
- package/dist/testing.cjs +63 -62
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +62 -61
- package/dist/testing.js.map +1 -1
- package/dist/types-GUrH1Qny.d.cts +200 -0
- package/dist/types-GUrH1Qny.d.ts +200 -0
- package/dist/use-update-table-C7v3gRyG.cjs +291 -0
- package/dist/use-update-table-C7v3gRyG.cjs.map +1 -0
- package/dist/use-update-table-Dz6knGoH.js +244 -0
- package/dist/use-update-table-Dz6knGoH.js.map +1 -0
- package/package.json +6 -6
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/fields.cjs.map +0 -1
- package/dist/fields.js.map +0 -1
- package/dist/generated-types-CnAlqHU_.d.cts +0 -25
- package/dist/generated-types-CnAlqHU_.d.ts +0 -25
- package/dist/indexes.cjs.map +0 -1
- package/dist/indexes.js.map +0 -1
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.js.map +0 -1
- package/dist/policy-types-CEYAR5TN.d.cts +0 -79
- package/dist/policy-types-CEYAR5TN.d.ts +0 -79
- package/dist/relationships.cjs.map +0 -1
- package/dist/relationships.js.map +0 -1
- package/dist/tables.cjs.map +0 -1
- package/dist/tables.js.map +0 -1
- package/dist/types-Du86atZ8.d.cts +0 -199
- package/dist/types-Du86atZ8.d.ts +0 -199
- package/dist/types-bX2dCrdl.d.cts +0 -52
- package/dist/types-bX2dCrdl.d.ts +0 -52
|
@@ -0,0 +1,2452 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
const require_query = require('./query-DU-KZleN.cjs');
|
|
3
|
+
const require_invalidate_database_entities = require('./invalidate-database-entities-9DsT5NlP.cjs');
|
|
4
|
+
const require_policy_config_form = require('./policy-config-form-CefFo6Fw.cjs');
|
|
5
|
+
const require_keyboard_activation = require('./keyboard-activation-D-L0IU6Y.cjs');
|
|
6
|
+
const require_empty_state_card = require('./empty-state-card-DMn8ADRq.cjs');
|
|
7
|
+
const require_delete_confirm_dialog = require('./delete-confirm-dialog-Ch4tWj6B.cjs');
|
|
8
|
+
let _constructive_io_ui_stack = require("@constructive-io/ui/stack");
|
|
9
|
+
let react = require("react");
|
|
10
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
+
let lucide_react = require("lucide-react");
|
|
12
|
+
let _tanstack_react_query = require("@tanstack/react-query");
|
|
13
|
+
let _constructive_io_ui_button = require("@constructive-io/ui/button");
|
|
14
|
+
let _constructive_io_ui_toast = require("@constructive-io/ui/toast");
|
|
15
|
+
let _constructive_io_ui_combobox = require("@constructive-io/ui/combobox");
|
|
16
|
+
let _constructive_io_ui_input = require("@constructive-io/ui/input");
|
|
17
|
+
let _constructive_io_ui_label = require("@constructive-io/ui/label");
|
|
18
|
+
let _constructive_io_ui_scroll_area = require("@constructive-io/ui/scroll-area");
|
|
19
|
+
let _constructive_io_ui_responsive_diagram = require("@constructive-io/ui/responsive-diagram");
|
|
20
|
+
let node_type_registry = require("node-type-registry");
|
|
21
|
+
let _constructive_io_ui_select = require("@constructive-io/ui/select");
|
|
22
|
+
let _constructive_io_ui_switch = require("@constructive-io/ui/switch");
|
|
23
|
+
|
|
24
|
+
//#region src/schema/schema-builder-core/components/policies/policy-diagram/svg-icons.ts
|
|
25
|
+
const DATABASE_ICON = { elements: [
|
|
26
|
+
{
|
|
27
|
+
tag: "ellipse",
|
|
28
|
+
attrs: {
|
|
29
|
+
cx: 12,
|
|
30
|
+
cy: 5,
|
|
31
|
+
rx: 9,
|
|
32
|
+
ry: 3
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
tag: "path",
|
|
37
|
+
attrs: { d: "M3 5V19A9 3 0 0 0 21 19V5" }
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
tag: "path",
|
|
41
|
+
attrs: { d: "M3 12A9 3 0 0 0 21 12" }
|
|
42
|
+
}
|
|
43
|
+
] };
|
|
44
|
+
const TABLE2_ICON = { elements: [{
|
|
45
|
+
tag: "path",
|
|
46
|
+
attrs: { d: "M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18" }
|
|
47
|
+
}] };
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/schema/schema-builder-core/components/policies/policy-diagram/svg-primitives.tsx
|
|
51
|
+
const MD_RADIUS = 28;
|
|
52
|
+
const SM_RADIUS = 24;
|
|
53
|
+
const MD_ICON_SIZE = 24;
|
|
54
|
+
const SM_ICON_SIZE = 20;
|
|
55
|
+
const FONT_FAMILY = "'Inter', system-ui, sans-serif";
|
|
56
|
+
const LABEL_FONT_SIZE = 12;
|
|
57
|
+
const TOP_LABEL_FONT_SIZE = 10;
|
|
58
|
+
const NODE_TOTAL_HEIGHT = 76;
|
|
59
|
+
const CENTER_Y = 28;
|
|
60
|
+
const LABEL_Y = 76 - 6;
|
|
61
|
+
const DiagramModeCtx = (0, react.createContext)("light");
|
|
62
|
+
const DiagramModeProvider = DiagramModeCtx.Provider;
|
|
63
|
+
function SvgIcon({ x, y, size, color, icon }) {
|
|
64
|
+
const scale = size / 24;
|
|
65
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {
|
|
66
|
+
transform: `translate(${x - size / 2},${y - size / 2}) scale(${scale})`,
|
|
67
|
+
fill: "none",
|
|
68
|
+
stroke: color,
|
|
69
|
+
strokeWidth: "2",
|
|
70
|
+
strokeLinecap: "round",
|
|
71
|
+
strokeLinejoin: "round",
|
|
72
|
+
children: icon.elements.map((el, i) => {
|
|
73
|
+
if (el.tag === "path") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: el.attrs.d }, i);
|
|
74
|
+
if (el.tag === "circle") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
75
|
+
cx: el.attrs.cx,
|
|
76
|
+
cy: el.attrs.cy,
|
|
77
|
+
r: el.attrs.r
|
|
78
|
+
}, i);
|
|
79
|
+
if (el.tag === "ellipse") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ellipse", {
|
|
80
|
+
cx: el.attrs.cx,
|
|
81
|
+
cy: el.attrs.cy,
|
|
82
|
+
rx: el.attrs.rx,
|
|
83
|
+
ry: el.attrs.ry
|
|
84
|
+
}, i);
|
|
85
|
+
return null;
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function SvgDiagramNode({ x, icon, label, theme, size = "md", stacked, outlined }) {
|
|
90
|
+
const r = size === "sm" ? 24 : 28;
|
|
91
|
+
const iconSize = size === "sm" ? SM_ICON_SIZE : MD_ICON_SIZE;
|
|
92
|
+
const cy = 28;
|
|
93
|
+
const bg = outlined ? theme.bg : theme.fill;
|
|
94
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [
|
|
95
|
+
stacked && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
96
|
+
cx: x - 8,
|
|
97
|
+
cy: cy - 6,
|
|
98
|
+
r,
|
|
99
|
+
fill: theme.bg,
|
|
100
|
+
stroke: theme.border,
|
|
101
|
+
strokeWidth: "2"
|
|
102
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
103
|
+
cx: x - 4,
|
|
104
|
+
cy: cy - 3,
|
|
105
|
+
r,
|
|
106
|
+
fill: theme.bg,
|
|
107
|
+
stroke: theme.border,
|
|
108
|
+
strokeWidth: "2"
|
|
109
|
+
})] }),
|
|
110
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
111
|
+
cx: x,
|
|
112
|
+
cy,
|
|
113
|
+
r,
|
|
114
|
+
fill: bg,
|
|
115
|
+
stroke: theme.border,
|
|
116
|
+
strokeWidth: "2"
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgIcon, {
|
|
119
|
+
x,
|
|
120
|
+
y: cy,
|
|
121
|
+
size: iconSize,
|
|
122
|
+
color: theme.primary,
|
|
123
|
+
icon
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
126
|
+
x,
|
|
127
|
+
y: 70,
|
|
128
|
+
textAnchor: "middle",
|
|
129
|
+
fontSize: LABEL_FONT_SIZE,
|
|
130
|
+
fill: theme.text,
|
|
131
|
+
style: { fontFamily: FONT_FAMILY },
|
|
132
|
+
children: label
|
|
133
|
+
})
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
/** Width of a diagram node (including stacked offset) */
|
|
137
|
+
function nodeWidth(size = "md", stacked) {
|
|
138
|
+
const diameter = (size === "sm" ? 24 : 28) * 2;
|
|
139
|
+
return stacked ? diameter + 8 : diameter;
|
|
140
|
+
}
|
|
141
|
+
function SvgConnector({ x, width, theme, topLabel, topLabelFilled, dashed }) {
|
|
142
|
+
const cy = 28;
|
|
143
|
+
const dotR = 4;
|
|
144
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [
|
|
145
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
146
|
+
cx: x + 6,
|
|
147
|
+
cy,
|
|
148
|
+
r: dotR,
|
|
149
|
+
fill: theme.connector
|
|
150
|
+
}),
|
|
151
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
152
|
+
x1: x + 10,
|
|
153
|
+
y1: cy,
|
|
154
|
+
x2: x + width - 10,
|
|
155
|
+
y2: cy,
|
|
156
|
+
stroke: theme.connectorLight,
|
|
157
|
+
strokeWidth: "2.5",
|
|
158
|
+
strokeLinecap: "round",
|
|
159
|
+
...dashed ? { strokeDasharray: "4 3" } : {}
|
|
160
|
+
}),
|
|
161
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
162
|
+
cx: x + width - 6,
|
|
163
|
+
cy,
|
|
164
|
+
r: dotR,
|
|
165
|
+
fill: theme.connector
|
|
166
|
+
}),
|
|
167
|
+
topLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgTopLabel, {
|
|
168
|
+
cx: x + width / 2,
|
|
169
|
+
y: 4,
|
|
170
|
+
label: topLabel,
|
|
171
|
+
filled: topLabelFilled,
|
|
172
|
+
theme
|
|
173
|
+
})
|
|
174
|
+
] });
|
|
175
|
+
}
|
|
176
|
+
function SvgFanConnector({ x, theme, topLabel, topLabelFilled }) {
|
|
177
|
+
const flatWidth = topLabel ? Math.max(24, topLabelBoxWidth(topLabel) + 4) : 24;
|
|
178
|
+
const fanMidX = x + flatWidth + 4 + 3;
|
|
179
|
+
const fanTipX = x + (flatWidth + 36) - 6;
|
|
180
|
+
const cy = 28;
|
|
181
|
+
const fanSpread = 14;
|
|
182
|
+
const startDotCx = x + 6;
|
|
183
|
+
const endDots = [
|
|
184
|
+
{
|
|
185
|
+
cx: fanTipX,
|
|
186
|
+
cy: cy - fanSpread
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
cx: fanTipX,
|
|
190
|
+
cy
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
cx: fanTipX,
|
|
194
|
+
cy: 42
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [
|
|
198
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
199
|
+
x1: startDotCx,
|
|
200
|
+
y1: cy,
|
|
201
|
+
x2: fanMidX,
|
|
202
|
+
y2: cy,
|
|
203
|
+
stroke: theme.connectorLight,
|
|
204
|
+
strokeWidth: "2.5",
|
|
205
|
+
strokeLinecap: "round"
|
|
206
|
+
}),
|
|
207
|
+
endDots.map((dot, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
208
|
+
x1: fanMidX,
|
|
209
|
+
y1: cy,
|
|
210
|
+
x2: dot.cx,
|
|
211
|
+
y2: dot.cy,
|
|
212
|
+
stroke: theme.connector,
|
|
213
|
+
strokeWidth: "2",
|
|
214
|
+
strokeLinecap: "round"
|
|
215
|
+
}, i)),
|
|
216
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
217
|
+
cx: startDotCx,
|
|
218
|
+
cy,
|
|
219
|
+
r: 4,
|
|
220
|
+
fill: theme.connector
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
223
|
+
cx: fanMidX,
|
|
224
|
+
cy,
|
|
225
|
+
r: 3,
|
|
226
|
+
fill: theme.connector
|
|
227
|
+
}),
|
|
228
|
+
endDots.map((dot, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
229
|
+
cx: dot.cx,
|
|
230
|
+
cy: dot.cy,
|
|
231
|
+
r: 3,
|
|
232
|
+
fill: theme.connector
|
|
233
|
+
}, i)),
|
|
234
|
+
topLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgTopLabel, {
|
|
235
|
+
cx: x + (flatWidth + 6) / 2,
|
|
236
|
+
y: 4,
|
|
237
|
+
label: topLabel,
|
|
238
|
+
filled: topLabelFilled,
|
|
239
|
+
theme
|
|
240
|
+
})
|
|
241
|
+
] });
|
|
242
|
+
}
|
|
243
|
+
/** Width of a fan connector */
|
|
244
|
+
function fanConnectorWidth(topLabel) {
|
|
245
|
+
return (topLabel ? Math.max(24, topLabelBoxWidth(topLabel) + 4) : 24) + 36;
|
|
246
|
+
}
|
|
247
|
+
/** Compute connector width that fits the top label with padding from dots */
|
|
248
|
+
function connectorWidthForLabel(label, minWidth = 40) {
|
|
249
|
+
if (!label) return minWidth;
|
|
250
|
+
const boxW = topLabelBoxWidth(label);
|
|
251
|
+
return Math.max(minWidth, boxW + 16);
|
|
252
|
+
}
|
|
253
|
+
const TOP_LABEL_MAX_CHARS = 12;
|
|
254
|
+
const TOP_LABEL_CHAR_WIDTH = 5.5;
|
|
255
|
+
const TOP_LABEL_PAD_X = 6;
|
|
256
|
+
/** Truncate a label string for display, adding ellipsis if needed */
|
|
257
|
+
function truncateLabel(label, maxChars = TOP_LABEL_MAX_CHARS) {
|
|
258
|
+
return label.length > maxChars ? label.slice(0, maxChars - 1) + "…" : label;
|
|
259
|
+
}
|
|
260
|
+
/** Compute the rendered width of a top-label box (accounts for truncation) */
|
|
261
|
+
function topLabelBoxWidth(label) {
|
|
262
|
+
return truncateLabel(label).length * TOP_LABEL_CHAR_WIDTH + TOP_LABEL_PAD_X * 2;
|
|
263
|
+
}
|
|
264
|
+
function SvgTopLabel({ cx, y, label, filled, theme }) {
|
|
265
|
+
const display = truncateLabel(label);
|
|
266
|
+
const rectW = display.length * TOP_LABEL_CHAR_WIDTH + TOP_LABEL_PAD_X * 2;
|
|
267
|
+
const rectH = 16;
|
|
268
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
269
|
+
x: cx - rectW / 2,
|
|
270
|
+
y,
|
|
271
|
+
width: rectW,
|
|
272
|
+
height: rectH,
|
|
273
|
+
rx: 3,
|
|
274
|
+
fill: filled ? theme.fill : theme.bg,
|
|
275
|
+
stroke: filled ? theme.primary : theme.border,
|
|
276
|
+
strokeWidth: "1",
|
|
277
|
+
...!filled ? { strokeDasharray: "3 2" } : {}
|
|
278
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
279
|
+
x: cx,
|
|
280
|
+
y: y + rectH / 2 + 10 * .35,
|
|
281
|
+
textAnchor: "middle",
|
|
282
|
+
fontSize: 10,
|
|
283
|
+
fontWeight: "500",
|
|
284
|
+
fill: theme.primary,
|
|
285
|
+
style: { fontFamily: FONT_FAMILY },
|
|
286
|
+
children: display
|
|
287
|
+
})] });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/schema/schema-builder-relationships/lib/gql/hooks/schema-builder/use-relation-provision.ts
|
|
292
|
+
/**
|
|
293
|
+
* Hook for atomic relationship creation via relation_provision
|
|
294
|
+
* Tier 4 wrapper: single mutation replaces multi-step FK/M2M creation
|
|
295
|
+
*/
|
|
296
|
+
const RELATION_TYPE_MAP = {
|
|
297
|
+
"one-to-one": node_type_registry.RelationHasOne.name,
|
|
298
|
+
"belongs-to": node_type_registry.RelationBelongsTo.name,
|
|
299
|
+
"one-to-many": node_type_registry.RelationHasMany.name,
|
|
300
|
+
"many-to-many": node_type_registry.RelationManyToMany.name
|
|
301
|
+
};
|
|
302
|
+
function useRelationProvision(options) {
|
|
303
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
304
|
+
const { selectTable, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
305
|
+
const createProvisionMutation = require_invalidate_database_entities.useCreateRelationProvisionMutation({ selection: { fields: {
|
|
306
|
+
id: true,
|
|
307
|
+
outFieldId: true,
|
|
308
|
+
outJunctionTableId: true,
|
|
309
|
+
outSourceFieldId: true,
|
|
310
|
+
outTargetFieldId: true
|
|
311
|
+
} } });
|
|
312
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
313
|
+
mutationFn: async (input) => {
|
|
314
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId;
|
|
315
|
+
if (!databaseId) throw new Error("Database ID not found");
|
|
316
|
+
const relationType = RELATION_TYPE_MAP[input.relationshipType];
|
|
317
|
+
if (!relationType) throw new Error(`Unsupported relationship type: ${input.relationshipType}`);
|
|
318
|
+
const isManyToMany = input.relationshipType === "many-to-many";
|
|
319
|
+
let derivedNodes;
|
|
320
|
+
let resolvedPolicyData = input.policyData ?? {};
|
|
321
|
+
if (isManyToMany) {
|
|
322
|
+
const dataNode = require_policy_config_form.getDataNodeForPolicy(input.policyType || "AuthzAllowAll");
|
|
323
|
+
if (input.policyTypeObj) {
|
|
324
|
+
resolvedPolicyData = {
|
|
325
|
+
...require_policy_config_form.getDefaultFormValues(input.policyTypeObj),
|
|
326
|
+
...resolvedPolicyData
|
|
327
|
+
};
|
|
328
|
+
resolvedPolicyData = require_policy_config_form.sanitizePolicyData(resolvedPolicyData);
|
|
329
|
+
}
|
|
330
|
+
const nodes = [];
|
|
331
|
+
if (!input.useCompositeKey) nodes.push({ $type: "DataId" });
|
|
332
|
+
if (dataNode) {
|
|
333
|
+
const baseNodeData = input.policyTypeObj ? require_policy_config_form.buildNodeData(resolvedPolicyData, input.policyTypeObj) : {};
|
|
334
|
+
nodes.push({
|
|
335
|
+
$type: dataNode,
|
|
336
|
+
...Object.keys(baseNodeData).length > 0 ? { data: baseNodeData } : {}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (nodes.length > 0) derivedNodes = nodes;
|
|
340
|
+
}
|
|
341
|
+
const provision = (await createProvisionMutation.mutateAsync({
|
|
342
|
+
databaseId,
|
|
343
|
+
relationType,
|
|
344
|
+
sourceTableId: input.sourceTableId,
|
|
345
|
+
targetTableId: input.targetTableId,
|
|
346
|
+
...input.deleteAction && { deleteAction: input.deleteAction },
|
|
347
|
+
...input.fieldName && { fieldName: input.fieldName },
|
|
348
|
+
...input.isRequired !== void 0 && { isRequired: input.isRequired },
|
|
349
|
+
...input.junctionTableName && { junctionTableName: input.junctionTableName },
|
|
350
|
+
...input.useCompositeKey !== void 0 && { useCompositeKey: input.useCompositeKey },
|
|
351
|
+
...input.sourceFieldName && { sourceFieldName: input.sourceFieldName },
|
|
352
|
+
...input.targetFieldName && { targetFieldName: input.targetFieldName },
|
|
353
|
+
...derivedNodes && { nodes: derivedNodes },
|
|
354
|
+
...input.exposeInApi !== void 0 && { exposeInApi: input.exposeInApi },
|
|
355
|
+
...isManyToMany && {
|
|
356
|
+
grants: require_policy_config_form.buildGrants(),
|
|
357
|
+
policies: [require_policy_config_form.buildPolicyEntry(input.policyType || "AuthzAllowAll", {
|
|
358
|
+
permissive: true,
|
|
359
|
+
...Object.keys(resolvedPolicyData).length > 0 && { data: resolvedPolicyData }
|
|
360
|
+
})]
|
|
361
|
+
}
|
|
362
|
+
})).createRelationProvision?.relationProvision;
|
|
363
|
+
if (!provision) throw new Error("Failed to create relation provision");
|
|
364
|
+
return {
|
|
365
|
+
outFieldId: provision.outFieldId ?? null,
|
|
366
|
+
outJunctionTableId: provision.outJunctionTableId ?? null,
|
|
367
|
+
outSourceFieldId: provision.outSourceFieldId ?? null,
|
|
368
|
+
outTargetFieldId: provision.outTargetFieldId ?? null
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
onSuccess: async (_result, input) => {
|
|
372
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
373
|
+
if (!options?.skipTableSelect) selectTable(input.sourceTableId);
|
|
374
|
+
},
|
|
375
|
+
onError: (error) => {
|
|
376
|
+
console.error("Failed to provision relation:", error);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/schema/schema-builder-relationships/lib/gql/hooks/schema-builder/use-relationship-mutations.ts
|
|
383
|
+
/**
|
|
384
|
+
* Hook for managing foreign key relationships
|
|
385
|
+
* Tier 4 wrapper: orchestrates FK + M2M relationship creation
|
|
386
|
+
*/
|
|
387
|
+
function useCreateForeignKey() {
|
|
388
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
389
|
+
const { selectTable, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
390
|
+
const createFkMutation = require_invalidate_database_entities.useCreateForeignKeyConstraintMutation({ selection: { fields: {
|
|
391
|
+
id: true,
|
|
392
|
+
name: true
|
|
393
|
+
} } });
|
|
394
|
+
const createUniqueMutation = require_invalidate_database_entities.useCreateUniqueConstraintMutation({ selection: { fields: { id: true } } });
|
|
395
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
396
|
+
mutationFn: async (input) => {
|
|
397
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId;
|
|
398
|
+
if (!databaseId) throw new Error("Database ID not found");
|
|
399
|
+
const refUniqueConstraintName = `${input.refTableId}_${input.refFieldIds.join("_")}_ref_unique`.slice(0, 63);
|
|
400
|
+
try {
|
|
401
|
+
await createUniqueMutation.mutateAsync({
|
|
402
|
+
tableId: input.refTableId,
|
|
403
|
+
databaseId,
|
|
404
|
+
fieldIds: require_invalidate_database_entities.asFieldIds(input.refFieldIds),
|
|
405
|
+
name: refUniqueConstraintName,
|
|
406
|
+
type: "u"
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const errorMessage = error instanceof Error ? error.message : "";
|
|
410
|
+
if (!errorMessage.includes("already exists") && !errorMessage.includes("duplicate")) throw error;
|
|
411
|
+
}
|
|
412
|
+
const createdFk = (await createFkMutation.mutateAsync({
|
|
413
|
+
databaseId,
|
|
414
|
+
tableId: input.tableId,
|
|
415
|
+
fieldIds: require_invalidate_database_entities.asFieldIds(input.fieldIds),
|
|
416
|
+
refTableId: input.refTableId,
|
|
417
|
+
refFieldIds: require_invalidate_database_entities.asFieldIds(input.refFieldIds),
|
|
418
|
+
name: input.name ?? void 0,
|
|
419
|
+
deleteAction: input.deleteAction ?? "a",
|
|
420
|
+
updateAction: input.updateAction ?? "a",
|
|
421
|
+
type: "f",
|
|
422
|
+
smartTags: input.relationshipType ? { relationshipType: input.relationshipType } : void 0
|
|
423
|
+
})).createForeignKeyConstraint?.foreignKeyConstraint;
|
|
424
|
+
if (!createdFk?.id) throw new Error("Failed to create foreign key constraint");
|
|
425
|
+
if (input.relationshipType === require_invalidate_database_entities.RelationshipTypes.ONE_TO_ONE) {
|
|
426
|
+
const uniqueName = (input.name || createdFk.name || "fk").replace(/_fkey\d*$/, "_unique");
|
|
427
|
+
await createUniqueMutation.mutateAsync({
|
|
428
|
+
tableId: input.tableId,
|
|
429
|
+
databaseId,
|
|
430
|
+
fieldIds: require_invalidate_database_entities.asFieldIds(input.fieldIds),
|
|
431
|
+
name: uniqueName,
|
|
432
|
+
type: "u"
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
id: createdFk.id,
|
|
437
|
+
name: createdFk.name ?? ""
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
onSuccess: async (_createdForeignKey, variables) => {
|
|
441
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
442
|
+
selectTable(variables.tableId);
|
|
443
|
+
},
|
|
444
|
+
onError: (error) => {
|
|
445
|
+
console.error("Failed to create foreign key constraint:", error);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
function useUpdateForeignKey() {
|
|
450
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
451
|
+
const { selectTable, selectedTableId, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
452
|
+
const updateFkMutation = require_invalidate_database_entities.useUpdateForeignKeyConstraintMutation({ selection: { fields: {
|
|
453
|
+
id: true,
|
|
454
|
+
name: true
|
|
455
|
+
} } });
|
|
456
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
457
|
+
mutationFn: async (input) => {
|
|
458
|
+
const patch = {};
|
|
459
|
+
if (input.name !== void 0) patch.name = input.name;
|
|
460
|
+
if (input.fieldIds !== void 0) patch.fieldIds = input.fieldIds;
|
|
461
|
+
if (input.refTableId !== void 0) patch.refTableId = input.refTableId;
|
|
462
|
+
if (input.refFieldIds !== void 0) patch.refFieldIds = input.refFieldIds;
|
|
463
|
+
if (input.deleteAction !== void 0) patch.deleteAction = input.deleteAction;
|
|
464
|
+
if (input.updateAction !== void 0) patch.updateAction = input.updateAction;
|
|
465
|
+
const updatedFk = (await updateFkMutation.mutateAsync({
|
|
466
|
+
id: input.id,
|
|
467
|
+
foreignKeyConstraintPatch: patch
|
|
468
|
+
})).updateForeignKeyConstraint?.foreignKeyConstraint;
|
|
469
|
+
if (!updatedFk?.id) throw new Error("Failed to update foreign key constraint");
|
|
470
|
+
return {
|
|
471
|
+
id: updatedFk.id,
|
|
472
|
+
name: updatedFk.name ?? ""
|
|
473
|
+
};
|
|
474
|
+
},
|
|
475
|
+
onSuccess: async () => {
|
|
476
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
477
|
+
if (selectedTableId) selectTable(selectedTableId);
|
|
478
|
+
},
|
|
479
|
+
onError: (error) => {
|
|
480
|
+
console.error("Failed to update foreign key constraint:", error);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function useDeleteForeignKey() {
|
|
485
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
486
|
+
const { selectTable, selectedTableId, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
487
|
+
const deleteFkMutation = require_invalidate_database_entities.useDeleteForeignKeyConstraintMutation({ selection: { fields: { id: true } } });
|
|
488
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
489
|
+
mutationFn: async (input) => {
|
|
490
|
+
await deleteFkMutation.mutateAsync({ id: input.id });
|
|
491
|
+
return { id: input.id };
|
|
492
|
+
},
|
|
493
|
+
onSuccess: async () => {
|
|
494
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
495
|
+
if (selectedTableId) selectTable(selectedTableId);
|
|
496
|
+
},
|
|
497
|
+
onError: (error) => {
|
|
498
|
+
console.error("Failed to delete foreign key constraint:", error);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Creates a many-to-many relationship by:
|
|
504
|
+
* 1. Creating a junction table
|
|
505
|
+
* 2. Creating an id field with primary key
|
|
506
|
+
* 3. Creating two FK fields pointing to both related tables
|
|
507
|
+
* 4. Creating two FK constraints
|
|
508
|
+
* 5. Creating a composite unique constraint on (a_id, b_id) to prevent duplicates
|
|
509
|
+
*/
|
|
510
|
+
function useCreateManyToMany() {
|
|
511
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
512
|
+
const { selectTable, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
513
|
+
const { mutateAsync: createGrant } = require_policy_config_form.useCreateTableGrant();
|
|
514
|
+
const createTableMutation = require_invalidate_database_entities.useCreateTableMutation({ selection: { fields: {
|
|
515
|
+
id: true,
|
|
516
|
+
name: true
|
|
517
|
+
} } });
|
|
518
|
+
const createFieldMutation = require_invalidate_database_entities.useCreateFieldMutation({ selection: { fields: { id: true } } });
|
|
519
|
+
const createPkMutation = require_invalidate_database_entities.useCreatePrimaryKeyConstraintMutation({ selection: { fields: { id: true } } });
|
|
520
|
+
const createFkMutation = require_invalidate_database_entities.useCreateForeignKeyConstraintMutation({ selection: { fields: { id: true } } });
|
|
521
|
+
const createUniqueMutation = require_invalidate_database_entities.useCreateUniqueConstraintMutation({ selection: { fields: { id: true } } });
|
|
522
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
523
|
+
mutationFn: async (input) => {
|
|
524
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId;
|
|
525
|
+
const schemaId = currentDatabase?.schemaId ?? currentSchema?.metadata?.schemaId;
|
|
526
|
+
if (!databaseId || !schemaId) throw new Error("Database ID or Schema ID not found");
|
|
527
|
+
const deleteAction = input.deleteAction ?? require_invalidate_database_entities.ForeignKeyActions.CASCADE;
|
|
528
|
+
const updateAction = input.updateAction ?? require_invalidate_database_entities.ForeignKeyActions.NO_ACTION;
|
|
529
|
+
const junctionTable = (await createTableMutation.mutateAsync({
|
|
530
|
+
name: input.junctionTableName,
|
|
531
|
+
databaseId,
|
|
532
|
+
schemaId
|
|
533
|
+
})).createTable?.table;
|
|
534
|
+
if (!junctionTable?.id || !junctionTable?.name) throw new Error("Failed to create junction table");
|
|
535
|
+
const junctionTableId = junctionTable.id;
|
|
536
|
+
const junctionTableName = junctionTable.name;
|
|
537
|
+
const idField = (await createFieldMutation.mutateAsync({
|
|
538
|
+
name: "id",
|
|
539
|
+
type: require_invalidate_database_entities.toFieldType("uuid"),
|
|
540
|
+
tableId: junctionTableId,
|
|
541
|
+
databaseId,
|
|
542
|
+
isRequired: true,
|
|
543
|
+
defaultValue: require_invalidate_database_entities.toFieldDefault("uuidv7()")
|
|
544
|
+
})).createField?.field;
|
|
545
|
+
if (!idField?.id) throw new Error("Failed to create id field");
|
|
546
|
+
const idFieldId = idField.id;
|
|
547
|
+
await createPkMutation.mutateAsync({
|
|
548
|
+
tableId: junctionTableId,
|
|
549
|
+
databaseId,
|
|
550
|
+
fieldIds: require_invalidate_database_entities.asFieldIds([idFieldId]),
|
|
551
|
+
name: `${input.junctionTableName}_pkey`,
|
|
552
|
+
type: "p"
|
|
553
|
+
});
|
|
554
|
+
const fieldAName = `${input.tableAName}_id`;
|
|
555
|
+
const fieldBName = `${input.tableBName}_id`;
|
|
556
|
+
const fieldA = (await createFieldMutation.mutateAsync({
|
|
557
|
+
name: fieldAName,
|
|
558
|
+
type: require_invalidate_database_entities.toFieldType("uuid"),
|
|
559
|
+
tableId: junctionTableId,
|
|
560
|
+
databaseId,
|
|
561
|
+
isRequired: true
|
|
562
|
+
})).createField?.field;
|
|
563
|
+
if (!fieldA?.id) throw new Error("Failed to create FK field for table A");
|
|
564
|
+
const fieldAId = fieldA.id;
|
|
565
|
+
const fieldB = (await createFieldMutation.mutateAsync({
|
|
566
|
+
name: fieldBName,
|
|
567
|
+
type: require_invalidate_database_entities.toFieldType("uuid"),
|
|
568
|
+
tableId: junctionTableId,
|
|
569
|
+
databaseId,
|
|
570
|
+
isRequired: true
|
|
571
|
+
})).createField?.field;
|
|
572
|
+
if (!fieldB?.id) throw new Error("Failed to create FK field for table B");
|
|
573
|
+
const fieldBId = fieldB.id;
|
|
574
|
+
await createFkMutation.mutateAsync({
|
|
575
|
+
databaseId,
|
|
576
|
+
tableId: junctionTableId,
|
|
577
|
+
fieldIds: require_invalidate_database_entities.asFieldIds([fieldAId]),
|
|
578
|
+
refTableId: input.tableAId,
|
|
579
|
+
refFieldIds: require_invalidate_database_entities.asFieldIds([input.tableAPrimaryKeyFieldId]),
|
|
580
|
+
name: `${input.junctionTableName}_${input.tableAName}_fkey`,
|
|
581
|
+
deleteAction,
|
|
582
|
+
updateAction,
|
|
583
|
+
type: "f"
|
|
584
|
+
});
|
|
585
|
+
await createFkMutation.mutateAsync({
|
|
586
|
+
databaseId,
|
|
587
|
+
tableId: junctionTableId,
|
|
588
|
+
fieldIds: require_invalidate_database_entities.asFieldIds([fieldBId]),
|
|
589
|
+
refTableId: input.tableBId,
|
|
590
|
+
refFieldIds: require_invalidate_database_entities.asFieldIds([input.tableBPrimaryKeyFieldId]),
|
|
591
|
+
name: `${input.junctionTableName}_${input.tableBName}_fkey`,
|
|
592
|
+
deleteAction,
|
|
593
|
+
updateAction,
|
|
594
|
+
type: "f"
|
|
595
|
+
});
|
|
596
|
+
await createUniqueMutation.mutateAsync({
|
|
597
|
+
tableId: junctionTableId,
|
|
598
|
+
databaseId,
|
|
599
|
+
fieldIds: require_invalidate_database_entities.asFieldIds([fieldAId, fieldBId]),
|
|
600
|
+
name: `${input.junctionTableName}_pair_unique`,
|
|
601
|
+
type: "u"
|
|
602
|
+
});
|
|
603
|
+
await createGrant({
|
|
604
|
+
databaseId,
|
|
605
|
+
tableName: junctionTableName,
|
|
606
|
+
privileges: [
|
|
607
|
+
"select",
|
|
608
|
+
"insert",
|
|
609
|
+
"update",
|
|
610
|
+
"delete"
|
|
611
|
+
],
|
|
612
|
+
roleName: "authenticated"
|
|
613
|
+
}).catch((error) => {
|
|
614
|
+
console.warn(`Failed to grant permissions for junction table: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
615
|
+
});
|
|
616
|
+
return {
|
|
617
|
+
junctionTableId,
|
|
618
|
+
junctionTableName
|
|
619
|
+
};
|
|
620
|
+
},
|
|
621
|
+
onSuccess: async (result) => {
|
|
622
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
623
|
+
if (result?.junctionTableId && result?.junctionTableName) selectTable(result.junctionTableId, result.junctionTableName);
|
|
624
|
+
},
|
|
625
|
+
onError: (error) => {
|
|
626
|
+
console.error("Failed to create many-to-many relationship:", error);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-diagram-themes.ts
|
|
633
|
+
const AMBIENT_LIGHT = {
|
|
634
|
+
bg: "#ffffff",
|
|
635
|
+
text: "#4B5563",
|
|
636
|
+
muted: "#9CA3AF"
|
|
637
|
+
};
|
|
638
|
+
const AMBIENT_DARK = {
|
|
639
|
+
bg: "#1e293b",
|
|
640
|
+
text: "#D1D5DB",
|
|
641
|
+
muted: "#6B7280"
|
|
642
|
+
};
|
|
643
|
+
const RELATIONSHIP_THEMES = {
|
|
644
|
+
"one-to-one": {
|
|
645
|
+
light: {
|
|
646
|
+
primary: "#A855F7",
|
|
647
|
+
fill: "#F3E8FF",
|
|
648
|
+
border: "#D8B4FE",
|
|
649
|
+
connector: "#A855F7",
|
|
650
|
+
connectorLight: "#E9D5FF",
|
|
651
|
+
...AMBIENT_LIGHT
|
|
652
|
+
},
|
|
653
|
+
dark: {
|
|
654
|
+
primary: "#C084FC",
|
|
655
|
+
fill: "#3B0764",
|
|
656
|
+
border: "#7E22CE",
|
|
657
|
+
connector: "#C084FC",
|
|
658
|
+
connectorLight: "#9333EA",
|
|
659
|
+
...AMBIENT_DARK
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
"belongs-to": {
|
|
663
|
+
light: {
|
|
664
|
+
primary: "#22C55E",
|
|
665
|
+
fill: "#F0FDF4",
|
|
666
|
+
border: "#86EFAC",
|
|
667
|
+
connector: "#22C55E",
|
|
668
|
+
connectorLight: "#BBF7D0",
|
|
669
|
+
...AMBIENT_LIGHT
|
|
670
|
+
},
|
|
671
|
+
dark: {
|
|
672
|
+
primary: "#4ADE80",
|
|
673
|
+
fill: "#052E16",
|
|
674
|
+
border: "#166534",
|
|
675
|
+
connector: "#4ADE80",
|
|
676
|
+
connectorLight: "#15803D",
|
|
677
|
+
...AMBIENT_DARK
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
"one-to-many": {
|
|
681
|
+
light: {
|
|
682
|
+
primary: "#3B82F6",
|
|
683
|
+
fill: "#DBEAFE",
|
|
684
|
+
border: "#93C5FD",
|
|
685
|
+
connector: "#3B82F6",
|
|
686
|
+
connectorLight: "#BFDBFE",
|
|
687
|
+
...AMBIENT_LIGHT
|
|
688
|
+
},
|
|
689
|
+
dark: {
|
|
690
|
+
primary: "#60A5FA",
|
|
691
|
+
fill: "#172554",
|
|
692
|
+
border: "#1E40AF",
|
|
693
|
+
connector: "#60A5FA",
|
|
694
|
+
connectorLight: "#2563EB",
|
|
695
|
+
...AMBIENT_DARK
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
"many-to-many": {
|
|
699
|
+
light: {
|
|
700
|
+
primary: "#F59E0B",
|
|
701
|
+
fill: "#FEF3C7",
|
|
702
|
+
border: "#FCD34D",
|
|
703
|
+
connector: "#F59E0B",
|
|
704
|
+
connectorLight: "#FDE68A",
|
|
705
|
+
...AMBIENT_LIGHT
|
|
706
|
+
},
|
|
707
|
+
dark: {
|
|
708
|
+
primary: "#FBBF24",
|
|
709
|
+
fill: "#451A03",
|
|
710
|
+
border: "#92400E",
|
|
711
|
+
connector: "#FBBF24",
|
|
712
|
+
connectorLight: "#B45309",
|
|
713
|
+
...AMBIENT_DARK
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
function getRelationshipTheme(type, mode = "light") {
|
|
718
|
+
return RELATIONSHIP_THEMES[type][mode];
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
//#endregion
|
|
722
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-diagrams.tsx
|
|
723
|
+
const GAP = 8;
|
|
724
|
+
const FAN_MARGIN_RIGHT = 4;
|
|
725
|
+
const PAD = 12;
|
|
726
|
+
function layoutHorizontal(widths) {
|
|
727
|
+
let x = 0;
|
|
728
|
+
const centers = [];
|
|
729
|
+
for (let i = 0; i < widths.length; i++) {
|
|
730
|
+
if (i > 0) x += GAP;
|
|
731
|
+
centers.push(x + widths[i] / 2);
|
|
732
|
+
x += widths[i];
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
totalWidth: x,
|
|
736
|
+
centers
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function svgProps(w, h = 76) {
|
|
740
|
+
return {
|
|
741
|
+
width: w + PAD * 2,
|
|
742
|
+
height: h + PAD * 2,
|
|
743
|
+
viewBox: `-12 -12 ${w + PAD * 2} ${h + PAD * 2}`,
|
|
744
|
+
fill: "none"
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function fanLeftX(center, topLabel) {
|
|
748
|
+
return center - fanConnectorWidth(topLabel) / 2;
|
|
749
|
+
}
|
|
750
|
+
function useMode() {
|
|
751
|
+
const { colorMode: resolvedTheme } = require_invalidate_database_entities.useSchemaBuilderRuntime();
|
|
752
|
+
return resolvedTheme === "dark" ? "dark" : "light";
|
|
753
|
+
}
|
|
754
|
+
function OneToOneDiagram({ sourceTable, targetTable, fieldName }) {
|
|
755
|
+
const theme = getRelationshipTheme("one-to-one", useMode());
|
|
756
|
+
const connW = connectorWidthForLabel(fieldName, 60);
|
|
757
|
+
const { totalWidth, centers } = layoutHorizontal([
|
|
758
|
+
nodeWidth("md"),
|
|
759
|
+
connW,
|
|
760
|
+
nodeWidth("md")
|
|
761
|
+
]);
|
|
762
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
763
|
+
...svgProps(totalWidth),
|
|
764
|
+
children: [
|
|
765
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
766
|
+
x: centers[0],
|
|
767
|
+
icon: TABLE2_ICON,
|
|
768
|
+
label: sourceTable,
|
|
769
|
+
theme
|
|
770
|
+
}),
|
|
771
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgConnector, {
|
|
772
|
+
x: centers[1] - connW / 2,
|
|
773
|
+
width: connW,
|
|
774
|
+
theme,
|
|
775
|
+
topLabel: fieldName,
|
|
776
|
+
topLabelFilled: fieldName !== "fk"
|
|
777
|
+
}),
|
|
778
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
779
|
+
x: centers[2],
|
|
780
|
+
icon: TABLE2_ICON,
|
|
781
|
+
label: targetTable,
|
|
782
|
+
theme
|
|
783
|
+
})
|
|
784
|
+
]
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
function SvgFanConnectorReversed({ x, theme, topLabel, topLabelFilled }) {
|
|
788
|
+
const flatWidth = topLabel ? Math.max(24, topLabelBoxWidth(topLabel) + 4) : 24;
|
|
789
|
+
const totalWidth = flatWidth + 36;
|
|
790
|
+
const cy = 28;
|
|
791
|
+
const fanSpread = 14;
|
|
792
|
+
const fanTipX = x + 6;
|
|
793
|
+
const fanMidX = x + totalWidth - flatWidth - 7;
|
|
794
|
+
const endDotCx = x + totalWidth - 6;
|
|
795
|
+
const startDots = [
|
|
796
|
+
{
|
|
797
|
+
cx: fanTipX,
|
|
798
|
+
cy: cy - fanSpread
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
cx: fanTipX,
|
|
802
|
+
cy
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
cx: fanTipX,
|
|
806
|
+
cy: cy + fanSpread
|
|
807
|
+
}
|
|
808
|
+
];
|
|
809
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", { children: [
|
|
810
|
+
startDots.map((dot, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
811
|
+
x1: dot.cx,
|
|
812
|
+
y1: dot.cy,
|
|
813
|
+
x2: fanMidX,
|
|
814
|
+
y2: cy,
|
|
815
|
+
stroke: theme.connector,
|
|
816
|
+
strokeWidth: "2",
|
|
817
|
+
strokeLinecap: "round"
|
|
818
|
+
}, i)),
|
|
819
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
820
|
+
x1: fanMidX,
|
|
821
|
+
y1: cy,
|
|
822
|
+
x2: endDotCx,
|
|
823
|
+
y2: cy,
|
|
824
|
+
stroke: theme.connectorLight,
|
|
825
|
+
strokeWidth: "2.5",
|
|
826
|
+
strokeLinecap: "round"
|
|
827
|
+
}),
|
|
828
|
+
startDots.map((dot, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
829
|
+
cx: dot.cx,
|
|
830
|
+
cy: dot.cy,
|
|
831
|
+
r: 3,
|
|
832
|
+
fill: theme.connector
|
|
833
|
+
}, i)),
|
|
834
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
835
|
+
cx: fanMidX,
|
|
836
|
+
cy,
|
|
837
|
+
r: 3,
|
|
838
|
+
fill: theme.connector
|
|
839
|
+
}),
|
|
840
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
841
|
+
cx: endDotCx,
|
|
842
|
+
cy,
|
|
843
|
+
r: 4,
|
|
844
|
+
fill: theme.connector
|
|
845
|
+
}),
|
|
846
|
+
topLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgTopLabel, {
|
|
847
|
+
cx: fanMidX + (endDotCx - fanMidX) / 2,
|
|
848
|
+
y: 4,
|
|
849
|
+
label: topLabel,
|
|
850
|
+
filled: topLabelFilled,
|
|
851
|
+
theme
|
|
852
|
+
})
|
|
853
|
+
] });
|
|
854
|
+
}
|
|
855
|
+
function BelongsToDiagram({ sourceTable, targetTable, fieldName }) {
|
|
856
|
+
const theme = getRelationshipTheme("belongs-to", useMode());
|
|
857
|
+
const fanW = fanConnectorWidth(fieldName);
|
|
858
|
+
const { totalWidth, centers } = layoutHorizontal([
|
|
859
|
+
nodeWidth("md", true),
|
|
860
|
+
FAN_MARGIN_RIGHT + fanW,
|
|
861
|
+
nodeWidth("md")
|
|
862
|
+
]);
|
|
863
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
864
|
+
...svgProps(totalWidth),
|
|
865
|
+
children: [
|
|
866
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
867
|
+
x: centers[0],
|
|
868
|
+
icon: DATABASE_ICON,
|
|
869
|
+
label: sourceTable,
|
|
870
|
+
theme,
|
|
871
|
+
stacked: true,
|
|
872
|
+
outlined: true
|
|
873
|
+
}),
|
|
874
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgFanConnectorReversed, {
|
|
875
|
+
x: fanLeftX(centers[1], fieldName),
|
|
876
|
+
theme,
|
|
877
|
+
topLabel: fieldName,
|
|
878
|
+
topLabelFilled: fieldName !== "fk"
|
|
879
|
+
}),
|
|
880
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
881
|
+
x: centers[2],
|
|
882
|
+
icon: TABLE2_ICON,
|
|
883
|
+
label: targetTable,
|
|
884
|
+
theme
|
|
885
|
+
})
|
|
886
|
+
]
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
function OneToManyDiagram({ sourceTable, targetTable, fieldName }) {
|
|
890
|
+
const theme = getRelationshipTheme("one-to-many", useMode());
|
|
891
|
+
const fanW = fanConnectorWidth(fieldName);
|
|
892
|
+
const { totalWidth, centers } = layoutHorizontal([
|
|
893
|
+
nodeWidth("md"),
|
|
894
|
+
fanW + FAN_MARGIN_RIGHT,
|
|
895
|
+
nodeWidth("md", true)
|
|
896
|
+
]);
|
|
897
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
898
|
+
...svgProps(totalWidth),
|
|
899
|
+
children: [
|
|
900
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
901
|
+
x: centers[0],
|
|
902
|
+
icon: TABLE2_ICON,
|
|
903
|
+
label: sourceTable,
|
|
904
|
+
theme
|
|
905
|
+
}),
|
|
906
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgFanConnector, {
|
|
907
|
+
x: fanLeftX(centers[1], fieldName),
|
|
908
|
+
theme,
|
|
909
|
+
topLabel: fieldName,
|
|
910
|
+
topLabelFilled: fieldName !== "fk"
|
|
911
|
+
}),
|
|
912
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
913
|
+
x: centers[2],
|
|
914
|
+
icon: DATABASE_ICON,
|
|
915
|
+
label: targetTable,
|
|
916
|
+
theme,
|
|
917
|
+
stacked: true,
|
|
918
|
+
outlined: true
|
|
919
|
+
})
|
|
920
|
+
]
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
function ManyToManyDiagram({ sourceTable, targetTable, junctionTable, sourceFkName, targetFkName }) {
|
|
924
|
+
const theme = getRelationshipTheme("many-to-many", useMode());
|
|
925
|
+
const srcFk = sourceFkName || `${sourceTable}_id`;
|
|
926
|
+
const tgtFk = targetFkName || `${targetTable}_id`;
|
|
927
|
+
const srcFanW = fanConnectorWidth(srcFk);
|
|
928
|
+
const tgtFanW = fanConnectorWidth(tgtFk);
|
|
929
|
+
const { totalWidth, centers } = layoutHorizontal([
|
|
930
|
+
nodeWidth("sm"),
|
|
931
|
+
srcFanW + FAN_MARGIN_RIGHT,
|
|
932
|
+
nodeWidth("sm"),
|
|
933
|
+
FAN_MARGIN_RIGHT + tgtFanW,
|
|
934
|
+
nodeWidth("sm")
|
|
935
|
+
]);
|
|
936
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
937
|
+
...svgProps(totalWidth),
|
|
938
|
+
children: [
|
|
939
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
940
|
+
x: centers[0],
|
|
941
|
+
icon: TABLE2_ICON,
|
|
942
|
+
label: sourceTable,
|
|
943
|
+
theme,
|
|
944
|
+
size: "sm"
|
|
945
|
+
}),
|
|
946
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgFanConnectorReversed, {
|
|
947
|
+
x: fanLeftX(centers[1], srcFk),
|
|
948
|
+
theme,
|
|
949
|
+
topLabel: srcFk,
|
|
950
|
+
topLabelFilled: true
|
|
951
|
+
}),
|
|
952
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
953
|
+
x: centers[2],
|
|
954
|
+
icon: DATABASE_ICON,
|
|
955
|
+
label: junctionTable,
|
|
956
|
+
theme,
|
|
957
|
+
size: "sm"
|
|
958
|
+
}),
|
|
959
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgFanConnector, {
|
|
960
|
+
x: fanLeftX(centers[3], tgtFk),
|
|
961
|
+
theme,
|
|
962
|
+
topLabel: tgtFk,
|
|
963
|
+
topLabelFilled: true
|
|
964
|
+
}),
|
|
965
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgDiagramNode, {
|
|
966
|
+
x: centers[4],
|
|
967
|
+
icon: TABLE2_ICON,
|
|
968
|
+
label: targetTable,
|
|
969
|
+
theme,
|
|
970
|
+
size: "sm"
|
|
971
|
+
})
|
|
972
|
+
]
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
function RelationshipDiagram({ type, sourceTable, targetTable, fieldName = "fk", junctionTable = "junction", sourceFkName, targetFkName, className }) {
|
|
976
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_responsive_diagram.ResponsiveDiagram, {
|
|
977
|
+
className,
|
|
978
|
+
children: [
|
|
979
|
+
type === "one-to-one" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OneToOneDiagram, {
|
|
980
|
+
sourceTable,
|
|
981
|
+
targetTable,
|
|
982
|
+
fieldName
|
|
983
|
+
}),
|
|
984
|
+
type === "belongs-to" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BelongsToDiagram, {
|
|
985
|
+
sourceTable,
|
|
986
|
+
targetTable,
|
|
987
|
+
fieldName
|
|
988
|
+
}),
|
|
989
|
+
type === "one-to-many" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OneToManyDiagram, {
|
|
990
|
+
sourceTable,
|
|
991
|
+
targetTable,
|
|
992
|
+
fieldName
|
|
993
|
+
}),
|
|
994
|
+
type === "many-to-many" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ManyToManyDiagram, {
|
|
995
|
+
sourceTable,
|
|
996
|
+
targetTable,
|
|
997
|
+
junctionTable,
|
|
998
|
+
sourceFkName,
|
|
999
|
+
targetFkName
|
|
1000
|
+
})
|
|
1001
|
+
]
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
//#endregion
|
|
1006
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-type-selector.tsx
|
|
1007
|
+
const TYPE_OPTIONS = [
|
|
1008
|
+
{
|
|
1009
|
+
type: "one-to-one",
|
|
1010
|
+
icon: lucide_react.Link2,
|
|
1011
|
+
title: "One-to-One",
|
|
1012
|
+
subtitle: "Exactly one each",
|
|
1013
|
+
colors: {
|
|
1014
|
+
iconBg: "bg-purple-500/10",
|
|
1015
|
+
iconText: "text-purple-600 dark:text-purple-400",
|
|
1016
|
+
selectedBorder: "border-purple-500",
|
|
1017
|
+
selectedBg: "bg-purple-500/5",
|
|
1018
|
+
checkBg: "bg-purple-500"
|
|
1019
|
+
}
|
|
1020
|
+
},
|
|
1021
|
+
{
|
|
1022
|
+
type: "belongs-to",
|
|
1023
|
+
icon: lucide_react.Share2,
|
|
1024
|
+
iconClassName: "rotate-180",
|
|
1025
|
+
title: "Belongs To",
|
|
1026
|
+
subtitle: "Many belong to one",
|
|
1027
|
+
colors: {
|
|
1028
|
+
iconBg: "bg-green-500/10",
|
|
1029
|
+
iconText: "text-green-600 dark:text-green-400",
|
|
1030
|
+
selectedBorder: "border-green-500",
|
|
1031
|
+
selectedBg: "bg-green-500/5",
|
|
1032
|
+
checkBg: "bg-green-500"
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
type: "one-to-many",
|
|
1037
|
+
icon: lucide_react.Share2,
|
|
1038
|
+
title: "One-to-Many",
|
|
1039
|
+
subtitle: "One has many",
|
|
1040
|
+
colors: {
|
|
1041
|
+
iconBg: "bg-blue-500/10",
|
|
1042
|
+
iconText: "text-blue-600 dark:text-blue-400",
|
|
1043
|
+
selectedBorder: "border-blue-500",
|
|
1044
|
+
selectedBg: "bg-blue-500/5",
|
|
1045
|
+
checkBg: "bg-blue-500"
|
|
1046
|
+
}
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
type: "many-to-many",
|
|
1050
|
+
icon: lucide_react.Waypoints,
|
|
1051
|
+
title: "Many-to-Many",
|
|
1052
|
+
subtitle: "Linked via join table",
|
|
1053
|
+
colors: {
|
|
1054
|
+
iconBg: "bg-amber-500/10",
|
|
1055
|
+
iconText: "text-amber-600 dark:text-amber-400",
|
|
1056
|
+
selectedBorder: "border-amber-500",
|
|
1057
|
+
selectedBg: "bg-amber-500/5",
|
|
1058
|
+
checkBg: "bg-amber-500"
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
];
|
|
1062
|
+
function RelationshipTypeSelector({ value, onChange, disabled }) {
|
|
1063
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1064
|
+
className: "space-y-3",
|
|
1065
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1066
|
+
className: "text-muted-foreground text-xs font-semibold tracking-wide uppercase",
|
|
1067
|
+
children: "Select type"
|
|
1068
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1069
|
+
className: "grid grid-cols-2 gap-2",
|
|
1070
|
+
children: TYPE_OPTIONS.map((option) => {
|
|
1071
|
+
const Icon = option.icon;
|
|
1072
|
+
const isSelected = value === option.type;
|
|
1073
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1074
|
+
type: "button",
|
|
1075
|
+
onClick: () => onChange(option.type),
|
|
1076
|
+
disabled,
|
|
1077
|
+
className: require_invalidate_database_entities.cn(`border-border relative flex min-h-10 items-center gap-2 rounded-lg border px-3 py-2.5 text-left
|
|
1078
|
+
transition-[background-color,border-color,box-shadow,scale] duration-150 ease-out motion-safe:active:scale-[0.96]`, !isSelected && "disabled:pointer-events-none disabled:opacity-70", isSelected && "disabled:pointer-events-none", isSelected ? [option.colors.selectedBorder, option.colors.selectedBg] : "hover:border-border/80 hover:bg-muted/30"),
|
|
1079
|
+
children: [
|
|
1080
|
+
isSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1081
|
+
className: "absolute top-2 right-2",
|
|
1082
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1083
|
+
className: require_invalidate_database_entities.cn("flex h-4 w-4 items-center justify-center rounded-full", option.colors.checkBg),
|
|
1084
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Check, {
|
|
1085
|
+
className: "h-2.5 w-2.5 text-white",
|
|
1086
|
+
strokeWidth: 3
|
|
1087
|
+
})
|
|
1088
|
+
})
|
|
1089
|
+
}),
|
|
1090
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1091
|
+
className: require_invalidate_database_entities.cn("flex h-7 w-7 shrink-0 items-center justify-center rounded-md", option.colors.iconBg),
|
|
1092
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: require_invalidate_database_entities.cn("h-4 w-4", option.colors.iconText, option.iconClassName) })
|
|
1093
|
+
}),
|
|
1094
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1095
|
+
className: "min-w-0 flex-1 pr-4",
|
|
1096
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1097
|
+
className: "text-balance text-xs leading-tight font-semibold",
|
|
1098
|
+
children: option.title
|
|
1099
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1100
|
+
className: require_invalidate_database_entities.cn("text-muted-foreground text-[10px]", isSelected && option.colors.iconText),
|
|
1101
|
+
children: option.subtitle
|
|
1102
|
+
})]
|
|
1103
|
+
})
|
|
1104
|
+
]
|
|
1105
|
+
}, option.type);
|
|
1106
|
+
})
|
|
1107
|
+
})]
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-card.tsx
|
|
1113
|
+
function TableCombobox({ tables, value, onChange, placeholder = "Select table", disabled }) {
|
|
1114
|
+
const options = tables.map((t) => ({
|
|
1115
|
+
value: t.id,
|
|
1116
|
+
label: t.name,
|
|
1117
|
+
table: t
|
|
1118
|
+
}));
|
|
1119
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.Combobox, {
|
|
1120
|
+
items: options,
|
|
1121
|
+
value: options.find((o) => o.value === value) ?? null,
|
|
1122
|
+
onValueChange: (next) => next && onChange(next.value),
|
|
1123
|
+
filter: (item, q) => item.label.toLowerCase().includes(q.toLowerCase()),
|
|
1124
|
+
disabled,
|
|
1125
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxInput, {
|
|
1126
|
+
placeholder,
|
|
1127
|
+
showClear: false
|
|
1128
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.ComboboxPopup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxEmpty, { children: "No tables found" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxList, { children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxItem, {
|
|
1129
|
+
value: option,
|
|
1130
|
+
children: option.label
|
|
1131
|
+
}, option.value) })] })]
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
function FieldCombobox({ fields, value, onChange, placeholder = "Select field", disabled }) {
|
|
1135
|
+
const selectedField = fields.find((f) => f.id === value);
|
|
1136
|
+
const options = fields.map((f) => ({
|
|
1137
|
+
value: f.id,
|
|
1138
|
+
label: selectedField?.id === f.id ? `${f.name} ` : f.name,
|
|
1139
|
+
field: f
|
|
1140
|
+
}));
|
|
1141
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1142
|
+
className: "relative",
|
|
1143
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.Combobox, {
|
|
1144
|
+
items: options,
|
|
1145
|
+
value: options.find((o) => o.value === value) ?? null,
|
|
1146
|
+
onValueChange: (next) => next && onChange(next.value),
|
|
1147
|
+
filter: (item, q) => {
|
|
1148
|
+
const lower = q.toLowerCase();
|
|
1149
|
+
return item.field.name.toLowerCase().includes(lower) || item.field.type.toLowerCase().includes(lower);
|
|
1150
|
+
},
|
|
1151
|
+
disabled,
|
|
1152
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxInput, {
|
|
1153
|
+
placeholder,
|
|
1154
|
+
showClear: false
|
|
1155
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_combobox.ComboboxPopup, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxEmpty, { children: "No fields found" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxList, { children: (option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_combobox.ComboboxItem, {
|
|
1156
|
+
value: option,
|
|
1157
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1158
|
+
className: "flex w-full items-center justify-between gap-2",
|
|
1159
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: option.field.name }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1160
|
+
className: "bg-muted text-muted-foreground rounded px-1.5 py-0.5 font-mono text-[10px]",
|
|
1161
|
+
children: option.field.type
|
|
1162
|
+
})]
|
|
1163
|
+
})
|
|
1164
|
+
}, option.value) })] })]
|
|
1165
|
+
}), selectedField && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1166
|
+
className: "bg-muted text-muted-foreground pointer-events-none absolute top-1/2 right-9 -translate-y-1/2\n rounded px-1.5 py-0.5 font-mono text-[10px]",
|
|
1167
|
+
children: selectedField.type
|
|
1168
|
+
})]
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
const isSystemTable = (category) => category === "CORE" || category === "MODULE";
|
|
1172
|
+
const RelationshipCard = ({ editingRelationship, sourceTable: directSourceTable, prefilledSourceTableId, prefilledTargetTableId, card }) => {
|
|
1173
|
+
const editingConstraint = editingRelationship?.constraint ?? null;
|
|
1174
|
+
const { currentSchema, currentTable: selectedTable, currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
1175
|
+
const relationProvisionMutation = useRelationProvision();
|
|
1176
|
+
const updateForeignKeyMutation = useUpdateForeignKey();
|
|
1177
|
+
const { policyTypes } = require_policy_config_form.usePolicyTypes();
|
|
1178
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId ?? "";
|
|
1179
|
+
const { data: tablesWithPolicies = [] } = require_invalidate_database_entities.useDatabasePolicies(databaseId, { enabled: !!databaseId });
|
|
1180
|
+
const tables = currentSchema?.tables || [];
|
|
1181
|
+
const defaultSourceTableId = (0, react.useMemo)(() => {
|
|
1182
|
+
if (directSourceTable) return directSourceTable.id;
|
|
1183
|
+
if (prefilledSourceTableId) return prefilledSourceTableId;
|
|
1184
|
+
return selectedTable?.id || "";
|
|
1185
|
+
}, [
|
|
1186
|
+
directSourceTable,
|
|
1187
|
+
prefilledSourceTableId,
|
|
1188
|
+
selectedTable?.id
|
|
1189
|
+
]);
|
|
1190
|
+
const [relationshipType, setRelationshipType] = (0, react.useState)(require_invalidate_database_entities.RelationshipTypes.ONE_TO_ONE);
|
|
1191
|
+
const [sourceTableId, setSourceTableId] = (0, react.useState)(defaultSourceTableId);
|
|
1192
|
+
const [sourceFieldId, setSourceFieldId] = (0, react.useState)("");
|
|
1193
|
+
const [targetTableId, setTargetTableId] = (0, react.useState)(prefilledTargetTableId || "");
|
|
1194
|
+
const [targetFieldId, setTargetFieldId] = (0, react.useState)("");
|
|
1195
|
+
const [onDelete, setOnDelete] = (0, react.useState)(require_invalidate_database_entities.ForeignKeyActions.NO_ACTION);
|
|
1196
|
+
const [junctionTableName, setJunctionTableName] = (0, react.useState)("");
|
|
1197
|
+
const [showAdvanced, setShowAdvanced] = (0, react.useState)(false);
|
|
1198
|
+
const [fieldNameOverride, setFieldNameOverride] = (0, react.useState)("");
|
|
1199
|
+
const [isRequired, setIsRequired] = (0, react.useState)(true);
|
|
1200
|
+
const [useCompositeKey, setUseCompositeKey] = (0, react.useState)(true);
|
|
1201
|
+
const [sourceFieldName, setSourceFieldName] = (0, react.useState)("");
|
|
1202
|
+
const [targetFieldName, setTargetFieldName] = (0, react.useState)("");
|
|
1203
|
+
const [exposeInApi, setExposeInApi] = (0, react.useState)(true);
|
|
1204
|
+
const [selectedPolicyTypeName, setSelectedPolicyTypeName] = (0, react.useState)("AuthzAllowAll");
|
|
1205
|
+
const [policyData, setPolicyData] = (0, react.useState)({});
|
|
1206
|
+
const isEditMode = editingConstraint !== null;
|
|
1207
|
+
const isManyToMany = relationshipType === require_invalidate_database_entities.RelationshipTypes.MANY_TO_MANY;
|
|
1208
|
+
const isFkType = !isManyToMany;
|
|
1209
|
+
const isM2MEdit = isEditMode && isManyToMany;
|
|
1210
|
+
const sourceTable = (0, react.useMemo)(() => tables.find((t) => t.id === sourceTableId), [tables, sourceTableId]);
|
|
1211
|
+
const targetTable = (0, react.useMemo)(() => tables.find((t) => t.id === targetTableId), [tables, targetTableId]);
|
|
1212
|
+
const availableSourceTables = (0, react.useMemo)(() => tables.filter((t) => !isSystemTable(t.category)), [tables]);
|
|
1213
|
+
const availableTargetTables = (0, react.useMemo)(() => tables.filter((t) => (isEditMode || t.id !== sourceTableId) && !isSystemTable(t.category)), [
|
|
1214
|
+
tables,
|
|
1215
|
+
sourceTableId,
|
|
1216
|
+
isEditMode
|
|
1217
|
+
]);
|
|
1218
|
+
const sourceFields = sourceTable?.fields || [];
|
|
1219
|
+
const targetFields = targetTable?.fields || [];
|
|
1220
|
+
const existingTableNames = (0, react.useMemo)(() => new Set(tables.map((t) => t.name.toLowerCase())), [tables]);
|
|
1221
|
+
const isJunctionNameTaken = (0, react.useMemo)(() => junctionTableName.trim() && existingTableNames.has(junctionTableName.trim().toLowerCase()), [junctionTableName, existingTableNames]);
|
|
1222
|
+
const inferredPolicyTypeName = (0, react.useMemo)(() => {
|
|
1223
|
+
const tableData = tablesWithPolicies.find((t) => t.id === sourceTableId);
|
|
1224
|
+
if (!tableData?.policies?.length) return "AuthzAllowAll";
|
|
1225
|
+
const resolved = tableData.policies.find((p) => p.privilege === "SELECT" && p.policyType)?.policyType ?? tableData.policies.find((p) => p.policyType)?.policyType ?? "AuthzAllowAll";
|
|
1226
|
+
return resolved === "AuthzComposite" ? "AuthzDirectOwner" : resolved;
|
|
1227
|
+
}, [tablesWithPolicies, sourceTableId]);
|
|
1228
|
+
const selectedPolicyType = (0, react.useMemo)(() => policyTypes.find((pt) => pt.name === selectedPolicyTypeName) ?? null, [policyTypes, selectedPolicyTypeName]);
|
|
1229
|
+
(0, react.useEffect)(() => {
|
|
1230
|
+
if (editingRelationship) {
|
|
1231
|
+
const { constraint, sourceTable: relSource, targetTable: relTarget, relationshipType: relType } = editingRelationship;
|
|
1232
|
+
setOnDelete(constraint.onDelete || require_invalidate_database_entities.ForeignKeyActions.NO_ACTION);
|
|
1233
|
+
setRelationshipType(relType);
|
|
1234
|
+
setJunctionTableName("");
|
|
1235
|
+
if (relType === "many-to-many") {
|
|
1236
|
+
const actualTarget = tables.find((t) => t.name === editingRelationship.withTableName);
|
|
1237
|
+
setTargetTableId(actualTarget?.id || "");
|
|
1238
|
+
} else {
|
|
1239
|
+
setTargetTableId(relTarget?.id || "");
|
|
1240
|
+
const srcField = relSource?.fields.find((f) => f.name === editingRelationship.sourceFieldName);
|
|
1241
|
+
const tgtField = relTarget?.fields.find((f) => f.name === editingRelationship.targetFieldName);
|
|
1242
|
+
setSourceFieldId(srcField?.id || "");
|
|
1243
|
+
setTargetFieldId(tgtField?.id || "");
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}, [editingRelationship, tables]);
|
|
1247
|
+
const m2mEditInfo = (0, react.useMemo)(() => {
|
|
1248
|
+
if (!isM2MEdit || !editingRelationship) return null;
|
|
1249
|
+
const junction = editingRelationship.targetTable;
|
|
1250
|
+
if (!junction) return null;
|
|
1251
|
+
const actualTarget = tables.find((t) => t.name === editingRelationship.withTableName);
|
|
1252
|
+
const srcFkName = editingRelationship.targetFieldName;
|
|
1253
|
+
const targetFk = (junction.constraints || []).filter((c) => c.type === "foreign_key").find((c) => c.referencedTable === actualTarget?.id);
|
|
1254
|
+
const tgtFkName = targetFk ? junction.fields.find((f) => f.id === targetFk.fields[0])?.name || "" : "";
|
|
1255
|
+
const pk = (junction.constraints || []).find((c) => c.type === "primary_key");
|
|
1256
|
+
const hasCompositePk = pk ? pk.fields.length > 1 : false;
|
|
1257
|
+
return {
|
|
1258
|
+
junctionName: junction.name,
|
|
1259
|
+
srcFkName,
|
|
1260
|
+
tgtFkName,
|
|
1261
|
+
hasCompositePk
|
|
1262
|
+
};
|
|
1263
|
+
}, [
|
|
1264
|
+
isM2MEdit,
|
|
1265
|
+
editingRelationship,
|
|
1266
|
+
tables
|
|
1267
|
+
]);
|
|
1268
|
+
(0, react.useEffect)(() => {
|
|
1269
|
+
if (!isManyToMany) {
|
|
1270
|
+
setJunctionTableName("");
|
|
1271
|
+
setSourceFieldName("");
|
|
1272
|
+
setTargetFieldName("");
|
|
1273
|
+
}
|
|
1274
|
+
setSelectedPolicyTypeName(inferredPolicyTypeName);
|
|
1275
|
+
setPolicyData({});
|
|
1276
|
+
}, [isManyToMany, inferredPolicyTypeName]);
|
|
1277
|
+
(0, react.useEffect)(() => {
|
|
1278
|
+
if (selectedPolicyType) setPolicyData(require_policy_config_form.getDefaultFormValues(selectedPolicyType));
|
|
1279
|
+
}, [selectedPolicyTypeName]);
|
|
1280
|
+
const handleSourceTableChange = (0, react.useCallback)((tableId) => {
|
|
1281
|
+
setSourceTableId(tableId);
|
|
1282
|
+
setTargetTableId((prev) => prev === tableId ? "" : prev);
|
|
1283
|
+
}, []);
|
|
1284
|
+
const handleTargetTableChange = (0, react.useCallback)((tableId) => {
|
|
1285
|
+
setTargetTableId(tableId);
|
|
1286
|
+
setTargetFieldId("");
|
|
1287
|
+
}, []);
|
|
1288
|
+
const handleSave = (0, react.useCallback)(async () => {
|
|
1289
|
+
if (!sourceTable) {
|
|
1290
|
+
_constructive_io_ui_toast.toast.error({ message: "No source table selected" });
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
if (!targetTableId) {
|
|
1294
|
+
_constructive_io_ui_toast.toast.error({ message: "Please select a target table" });
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
if (isManyToMany) {
|
|
1298
|
+
try {
|
|
1299
|
+
await relationProvisionMutation.mutateAsync({
|
|
1300
|
+
relationshipType,
|
|
1301
|
+
sourceTableId: sourceTable.id,
|
|
1302
|
+
targetTableId,
|
|
1303
|
+
...junctionTableName.trim() && { junctionTableName: junctionTableName.trim() },
|
|
1304
|
+
useCompositeKey,
|
|
1305
|
+
exposeInApi,
|
|
1306
|
+
...sourceFieldName.trim() && { sourceFieldName: sourceFieldName.trim() },
|
|
1307
|
+
...targetFieldName.trim() && { targetFieldName: targetFieldName.trim() },
|
|
1308
|
+
policyType: selectedPolicyTypeName,
|
|
1309
|
+
policyData,
|
|
1310
|
+
policyTypeObj: selectedPolicyType ?? void 0
|
|
1311
|
+
});
|
|
1312
|
+
_constructive_io_ui_toast.toast.success({
|
|
1313
|
+
message: "Many-to-many relationship created",
|
|
1314
|
+
description: junctionTableName.trim() ? `Junction table "${junctionTableName}" created.` : "Junction table created."
|
|
1315
|
+
});
|
|
1316
|
+
card.close();
|
|
1317
|
+
} catch (error) {
|
|
1318
|
+
_constructive_io_ui_toast.toast.error({
|
|
1319
|
+
message: "Failed to create relationship",
|
|
1320
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
if (isEditMode && editingConstraint) {
|
|
1326
|
+
try {
|
|
1327
|
+
await updateForeignKeyMutation.mutateAsync({
|
|
1328
|
+
id: editingConstraint.id,
|
|
1329
|
+
deleteAction: onDelete
|
|
1330
|
+
});
|
|
1331
|
+
_constructive_io_ui_toast.toast.success({ message: "Relationship updated" });
|
|
1332
|
+
card.close();
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
_constructive_io_ui_toast.toast.error({
|
|
1335
|
+
message: "Failed to update relationship",
|
|
1336
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
try {
|
|
1342
|
+
await relationProvisionMutation.mutateAsync({
|
|
1343
|
+
relationshipType,
|
|
1344
|
+
sourceTableId: sourceTable.id,
|
|
1345
|
+
targetTableId,
|
|
1346
|
+
deleteAction: onDelete,
|
|
1347
|
+
...fieldNameOverride.trim() && { fieldName: fieldNameOverride.trim() },
|
|
1348
|
+
...isRequired !== void 0 && { isRequired }
|
|
1349
|
+
});
|
|
1350
|
+
_constructive_io_ui_toast.toast.success({ message: "Relationship created" });
|
|
1351
|
+
card.close();
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
_constructive_io_ui_toast.toast.error({
|
|
1354
|
+
message: "Failed to create relationship",
|
|
1355
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
}, [
|
|
1359
|
+
sourceTable,
|
|
1360
|
+
targetTableId,
|
|
1361
|
+
isManyToMany,
|
|
1362
|
+
junctionTableName,
|
|
1363
|
+
relationshipType,
|
|
1364
|
+
onDelete,
|
|
1365
|
+
isEditMode,
|
|
1366
|
+
editingConstraint,
|
|
1367
|
+
fieldNameOverride,
|
|
1368
|
+
isRequired,
|
|
1369
|
+
useCompositeKey,
|
|
1370
|
+
exposeInApi,
|
|
1371
|
+
sourceFieldName,
|
|
1372
|
+
targetFieldName,
|
|
1373
|
+
selectedPolicyTypeName,
|
|
1374
|
+
selectedPolicyType,
|
|
1375
|
+
policyData,
|
|
1376
|
+
relationProvisionMutation,
|
|
1377
|
+
updateForeignKeyMutation,
|
|
1378
|
+
card
|
|
1379
|
+
]);
|
|
1380
|
+
const isPending = relationProvisionMutation.isPending || updateForeignKeyMutation.isPending;
|
|
1381
|
+
const canSaveM2M = isManyToMany && sourceTableId && targetTableId;
|
|
1382
|
+
const initialOnDelete = editingRelationship?.constraint.onDelete || require_invalidate_database_entities.ForeignKeyActions.NO_ACTION;
|
|
1383
|
+
const canSave = canSaveM2M || isEditMode && isFkType && onDelete !== initialOnDelete || !isEditMode && isFkType && sourceTableId && targetTableId;
|
|
1384
|
+
const sourceTableName = sourceTable?.name || "source";
|
|
1385
|
+
const targetTableName = targetTable?.name || "target";
|
|
1386
|
+
const fkDerivedTable = relationshipType === require_invalidate_database_entities.RelationshipTypes.ONE_TO_MANY ? sourceTable : targetTable;
|
|
1387
|
+
const diagramFieldName = fieldNameOverride.trim() || (fkDerivedTable ? `${fkDerivedTable.name}_id` : "fk");
|
|
1388
|
+
const diagramJunctionName = m2mEditInfo?.junctionName || junctionTableName.trim() || (sourceTable && targetTable ? [sourceTable.name, targetTable.name].sort().join("_") : "junction");
|
|
1389
|
+
const sourceFkPlaceholder = sourceTable ? `${sourceTable.name}_id (auto)` : "Auto-derived";
|
|
1390
|
+
const targetFkPlaceholder = targetTable ? `${targetTable.name}_id (auto)` : "Auto-derived";
|
|
1391
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1392
|
+
"data-chat-component": "relationship-card",
|
|
1393
|
+
"data-chat-relationship-type": relationshipType,
|
|
1394
|
+
"data-chat-source-table": sourceTable?.name ?? "",
|
|
1395
|
+
"data-chat-target-table": targetTable?.name ?? "",
|
|
1396
|
+
className: "flex h-full flex-col",
|
|
1397
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_scroll_area.ScrollArea, {
|
|
1398
|
+
className: "min-h-0 flex-1",
|
|
1399
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1400
|
+
className: "space-y-6 p-6",
|
|
1401
|
+
children: [
|
|
1402
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RelationshipTypeSelector, {
|
|
1403
|
+
value: relationshipType,
|
|
1404
|
+
onChange: setRelationshipType,
|
|
1405
|
+
disabled: isEditMode
|
|
1406
|
+
}),
|
|
1407
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1408
|
+
className: "space-y-4",
|
|
1409
|
+
children: [
|
|
1410
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1411
|
+
className: "text-muted-foreground text-xs font-semibold tracking-wide uppercase",
|
|
1412
|
+
children: "Connect tables"
|
|
1413
|
+
}),
|
|
1414
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RelationshipDiagram, {
|
|
1415
|
+
type: relationshipType,
|
|
1416
|
+
sourceTable: sourceTableName,
|
|
1417
|
+
targetTable: targetTableName,
|
|
1418
|
+
fieldName: isManyToMany ? void 0 : diagramFieldName,
|
|
1419
|
+
junctionTable: isManyToMany ? diagramJunctionName : void 0,
|
|
1420
|
+
sourceFkName: isManyToMany ? m2mEditInfo?.srcFkName || sourceFieldName.trim() || void 0 : void 0,
|
|
1421
|
+
targetFkName: isManyToMany ? m2mEditInfo?.tgtFkName || targetFieldName.trim() || void 0 : void 0
|
|
1422
|
+
}),
|
|
1423
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1424
|
+
className: "space-y-1.5",
|
|
1425
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Source table" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableCombobox, {
|
|
1426
|
+
tables: availableSourceTables,
|
|
1427
|
+
value: sourceTableId,
|
|
1428
|
+
onChange: handleSourceTableChange,
|
|
1429
|
+
placeholder: "Select source table",
|
|
1430
|
+
disabled: isEditMode
|
|
1431
|
+
})]
|
|
1432
|
+
}),
|
|
1433
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1434
|
+
className: "space-y-1.5",
|
|
1435
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Target table" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableCombobox, {
|
|
1436
|
+
tables: availableTargetTables,
|
|
1437
|
+
value: targetTableId,
|
|
1438
|
+
onChange: handleTargetTableChange,
|
|
1439
|
+
placeholder: "Select target table",
|
|
1440
|
+
disabled: isEditMode
|
|
1441
|
+
})]
|
|
1442
|
+
}),
|
|
1443
|
+
isManyToMany && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1444
|
+
className: "space-y-3",
|
|
1445
|
+
children: [
|
|
1446
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1447
|
+
className: "flex items-center justify-between gap-3",
|
|
1448
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1449
|
+
className: "space-y-0.5",
|
|
1450
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Use composite primary key" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1451
|
+
className: "text-muted-foreground text-xs",
|
|
1452
|
+
children: (isM2MEdit ? m2mEditInfo?.hasCompositePk : useCompositeKey) ? "Each source–target pair can only appear once." : "Rows get a UUID id — pairs are not enforced as unique."
|
|
1453
|
+
})]
|
|
1454
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
|
|
1455
|
+
checked: isM2MEdit ? m2mEditInfo?.hasCompositePk ?? true : useCompositeKey,
|
|
1456
|
+
onCheckedChange: setUseCompositeKey,
|
|
1457
|
+
disabled: isM2MEdit
|
|
1458
|
+
})]
|
|
1459
|
+
}),
|
|
1460
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1461
|
+
className: "bg-muted/50 rounded-md px-3 py-2 font-mono text-xs",
|
|
1462
|
+
children: (isM2MEdit ? m2mEditInfo?.hasCompositePk : useCompositeKey) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1463
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1464
|
+
className: "text-muted-foreground",
|
|
1465
|
+
children: "PK"
|
|
1466
|
+
}),
|
|
1467
|
+
" (",
|
|
1468
|
+
sourceTable?.name || "source",
|
|
1469
|
+
"_id,",
|
|
1470
|
+
" ",
|
|
1471
|
+
targetTable?.name || "target",
|
|
1472
|
+
"_id)"
|
|
1473
|
+
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1474
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1475
|
+
className: "text-muted-foreground",
|
|
1476
|
+
children: "PK"
|
|
1477
|
+
}),
|
|
1478
|
+
" id",
|
|
1479
|
+
" ",
|
|
1480
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1481
|
+
className: "text-muted-foreground",
|
|
1482
|
+
children: "uuid"
|
|
1483
|
+
})
|
|
1484
|
+
] })
|
|
1485
|
+
}),
|
|
1486
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1487
|
+
className: "flex items-center justify-between gap-3",
|
|
1488
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1489
|
+
className: "space-y-0.5",
|
|
1490
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Expose in GraphQL API" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1491
|
+
className: "text-muted-foreground text-xs",
|
|
1492
|
+
children: "Makes this many-to-many relation directly queryable in the GraphQL API."
|
|
1493
|
+
})]
|
|
1494
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
|
|
1495
|
+
checked: isM2MEdit ? editingRelationship?.provision?.exposeInApi ?? true : exposeInApi,
|
|
1496
|
+
onCheckedChange: setExposeInApi,
|
|
1497
|
+
disabled: isM2MEdit
|
|
1498
|
+
})]
|
|
1499
|
+
})
|
|
1500
|
+
]
|
|
1501
|
+
}),
|
|
1502
|
+
isM2MEdit && m2mEditInfo && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1503
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1504
|
+
className: "space-y-1.5",
|
|
1505
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Junction table name" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1506
|
+
value: m2mEditInfo.junctionName,
|
|
1507
|
+
disabled: true
|
|
1508
|
+
})]
|
|
1509
|
+
}),
|
|
1510
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1511
|
+
className: "space-y-1.5",
|
|
1512
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Source FK name" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1513
|
+
value: m2mEditInfo.srcFkName,
|
|
1514
|
+
disabled: true
|
|
1515
|
+
})]
|
|
1516
|
+
}),
|
|
1517
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1518
|
+
className: "space-y-1.5",
|
|
1519
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Target FK name" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1520
|
+
value: m2mEditInfo.tgtFkName,
|
|
1521
|
+
disabled: true
|
|
1522
|
+
})]
|
|
1523
|
+
})
|
|
1524
|
+
] }),
|
|
1525
|
+
isEditMode && isFkType && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1526
|
+
className: "space-y-1.5",
|
|
1527
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Source field" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldCombobox, {
|
|
1528
|
+
fields: sourceFields,
|
|
1529
|
+
value: sourceFieldId,
|
|
1530
|
+
onChange: setSourceFieldId,
|
|
1531
|
+
placeholder: "Select field",
|
|
1532
|
+
disabled: true
|
|
1533
|
+
})]
|
|
1534
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1535
|
+
className: "space-y-1.5",
|
|
1536
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Target field" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldCombobox, {
|
|
1537
|
+
fields: targetFields,
|
|
1538
|
+
value: targetFieldId,
|
|
1539
|
+
onChange: setTargetFieldId,
|
|
1540
|
+
placeholder: "Select field",
|
|
1541
|
+
disabled: true
|
|
1542
|
+
})]
|
|
1543
|
+
})] }),
|
|
1544
|
+
isFkType && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1545
|
+
className: "space-y-1.5",
|
|
1546
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "On delete" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
|
|
1547
|
+
value: onDelete,
|
|
1548
|
+
onValueChange: (v) => setOnDelete(v),
|
|
1549
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: require_invalidate_database_entities.ForeignKeyActionLabels[onDelete] }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: Object.entries(require_invalidate_database_entities.ForeignKeyActions).map(([key, value]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectItem, {
|
|
1550
|
+
value,
|
|
1551
|
+
children: require_invalidate_database_entities.ForeignKeyActionLabels[value]
|
|
1552
|
+
}, key)) })]
|
|
1553
|
+
})]
|
|
1554
|
+
})
|
|
1555
|
+
]
|
|
1556
|
+
}),
|
|
1557
|
+
!isEditMode && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1558
|
+
className: "border-border/60 rounded-lg border",
|
|
1559
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1560
|
+
type: "button",
|
|
1561
|
+
onClick: () => setShowAdvanced(!showAdvanced),
|
|
1562
|
+
className: "flex min-h-10 w-full items-center gap-2 rounded-lg px-4 py-3 text-left text-sm font-medium\n transition-[background-color,scale] duration-150 ease-out hover:bg-muted/40 motion-safe:active:scale-[0.96]",
|
|
1563
|
+
"aria-expanded": showAdvanced,
|
|
1564
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: require_invalidate_database_entities.cn("text-muted-foreground h-4 w-4 transition-transform", showAdvanced && "rotate-90") }), "Advanced"]
|
|
1565
|
+
}), showAdvanced && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1566
|
+
className: "space-y-4 border-t px-4 pt-3 pb-4",
|
|
1567
|
+
children: [isFkType && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1568
|
+
className: "space-y-1.5",
|
|
1569
|
+
children: [
|
|
1570
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Foreign key field name" }),
|
|
1571
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1572
|
+
value: fieldNameOverride,
|
|
1573
|
+
onChange: (e) => setFieldNameOverride(e.target.value),
|
|
1574
|
+
placeholder: targetTable ? `${targetTable.name}_id (auto)` : "Auto-derived"
|
|
1575
|
+
}),
|
|
1576
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1577
|
+
className: "text-muted-foreground text-xs",
|
|
1578
|
+
children: "Leave empty to auto-derive from the target table name."
|
|
1579
|
+
})
|
|
1580
|
+
]
|
|
1581
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1582
|
+
className: "flex items-center justify-between gap-3",
|
|
1583
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1584
|
+
className: "space-y-0.5",
|
|
1585
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Foreign key field required" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1586
|
+
className: "text-muted-foreground text-xs",
|
|
1587
|
+
children: "Whether the foreign key field is NOT NULL."
|
|
1588
|
+
})]
|
|
1589
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
|
|
1590
|
+
checked: isRequired,
|
|
1591
|
+
onCheckedChange: setIsRequired
|
|
1592
|
+
})]
|
|
1593
|
+
})] }), isManyToMany && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1594
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1595
|
+
className: "space-y-1.5",
|
|
1596
|
+
children: [
|
|
1597
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Junction table name" }),
|
|
1598
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1599
|
+
value: junctionTableName,
|
|
1600
|
+
onChange: (e) => setJunctionTableName(e.target.value),
|
|
1601
|
+
placeholder: sourceTable && targetTable ? `${[sourceTable.name, targetTable.name].sort().join("_")} (auto)` : "Auto-derived",
|
|
1602
|
+
className: isJunctionNameTaken ? "border-destructive" : ""
|
|
1603
|
+
}),
|
|
1604
|
+
isJunctionNameTaken ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1605
|
+
className: "text-destructive text-xs",
|
|
1606
|
+
children: "Table name already exists"
|
|
1607
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1608
|
+
className: "text-muted-foreground text-xs",
|
|
1609
|
+
children: "Leave empty to auto-derive from table names."
|
|
1610
|
+
})
|
|
1611
|
+
]
|
|
1612
|
+
}),
|
|
1613
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1614
|
+
className: "space-y-1.5",
|
|
1615
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Source FK name" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1616
|
+
value: sourceFieldName,
|
|
1617
|
+
onChange: (e) => setSourceFieldName(e.target.value),
|
|
1618
|
+
placeholder: sourceFkPlaceholder
|
|
1619
|
+
})]
|
|
1620
|
+
}),
|
|
1621
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1622
|
+
className: "space-y-1.5",
|
|
1623
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Target FK name" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
1624
|
+
value: targetFieldName,
|
|
1625
|
+
onChange: (e) => setTargetFieldName(e.target.value),
|
|
1626
|
+
placeholder: targetFkPlaceholder
|
|
1627
|
+
})]
|
|
1628
|
+
}),
|
|
1629
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1630
|
+
className: "space-y-1.5",
|
|
1631
|
+
children: [
|
|
1632
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, { children: "Junction table policy" }),
|
|
1633
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
|
|
1634
|
+
value: selectedPolicyTypeName,
|
|
1635
|
+
onValueChange: setSelectedPolicyTypeName,
|
|
1636
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1637
|
+
className: "flex items-center gap-2",
|
|
1638
|
+
children: [selectedPolicyType && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(selectedPolicyType.icon, { className: "text-muted-foreground h-4 w-4 shrink-0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: selectedPolicyType?.title || selectedPolicyTypeName })]
|
|
1639
|
+
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: policyTypes.filter((pt) => pt.name !== "AuthzComposite").map((pt) => {
|
|
1640
|
+
const Icon = pt.icon;
|
|
1641
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectItem, {
|
|
1642
|
+
value: pt.name,
|
|
1643
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1644
|
+
className: "flex items-center gap-2",
|
|
1645
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "text-muted-foreground h-4 w-4 shrink-0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: pt.title })]
|
|
1646
|
+
})
|
|
1647
|
+
}, pt.name);
|
|
1648
|
+
}) })]
|
|
1649
|
+
}),
|
|
1650
|
+
selectedPolicyType && selectedPolicyTypeName === inferredPolicyTypeName && inferredPolicyTypeName !== "AuthzAllowAll" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1651
|
+
className: "text-muted-foreground flex items-start gap-2 text-xs",
|
|
1652
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Info, { className: "mt-0.5 h-3 w-3 shrink-0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Inherited from source table’s policy." })]
|
|
1653
|
+
}),
|
|
1654
|
+
selectedPolicyType && (selectedPolicyTypeName !== inferredPolicyTypeName || inferredPolicyTypeName === "AuthzAllowAll") && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1655
|
+
className: "text-muted-foreground text-xs",
|
|
1656
|
+
children: selectedPolicyType.description
|
|
1657
|
+
})
|
|
1658
|
+
]
|
|
1659
|
+
}),
|
|
1660
|
+
selectedPolicyType && selectedPolicyTypeName !== "AuthzAllowAll" && (selectedPolicyType.fieldOverrides && Object.keys(selectedPolicyType.fieldOverrides).length > 0 || selectedPolicyType.generatedFields.length > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1661
|
+
className: "space-y-3",
|
|
1662
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1663
|
+
className: "text-muted-foreground text-xs font-semibold tracking-wide uppercase",
|
|
1664
|
+
children: "Policy config"
|
|
1665
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_policy_config_form.PolicyConfigForm, {
|
|
1666
|
+
policyType: selectedPolicyType,
|
|
1667
|
+
value: policyData,
|
|
1668
|
+
onChange: setPolicyData
|
|
1669
|
+
})]
|
|
1670
|
+
})
|
|
1671
|
+
] })]
|
|
1672
|
+
})]
|
|
1673
|
+
})
|
|
1674
|
+
]
|
|
1675
|
+
})
|
|
1676
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1677
|
+
className: "flex justify-end gap-2 border-t px-4 py-3",
|
|
1678
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
1679
|
+
variant: "outline",
|
|
1680
|
+
onClick: () => card.close(),
|
|
1681
|
+
disabled: isPending,
|
|
1682
|
+
children: isM2MEdit ? "Close" : "Cancel"
|
|
1683
|
+
}), !isM2MEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
1684
|
+
onClick: handleSave,
|
|
1685
|
+
disabled: !canSave || isPending,
|
|
1686
|
+
children: [isPending && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), isEditMode ? "Update Relationship" : "Create Relationship"]
|
|
1687
|
+
})]
|
|
1688
|
+
})]
|
|
1689
|
+
});
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
//#endregion
|
|
1693
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-empty-state.tsx
|
|
1694
|
+
function RelationshipEmptyState({ onCreateClick, tableName }) {
|
|
1695
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_empty_state_card.EmptyStateCard, {
|
|
1696
|
+
icon: lucide_react.Link2,
|
|
1697
|
+
title: tableName ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: ["No relationships for ", tableName] }) : "Create your first relationship",
|
|
1698
|
+
description: tableName ? `Add a relationship to connect ${tableName} to other tables. This helps organize your data and maintain consistency.` : "Connect your tables to establish relationships. This helps organize your data and maintain consistency.",
|
|
1699
|
+
actionLabel: "Create Relationship",
|
|
1700
|
+
actionIcon: lucide_react.Link2,
|
|
1701
|
+
onAction: onCreateClick,
|
|
1702
|
+
features: [
|
|
1703
|
+
{
|
|
1704
|
+
icon: lucide_react.Shield,
|
|
1705
|
+
title: "Data Integrity",
|
|
1706
|
+
description: "Maintain consistency across tables"
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
icon: lucide_react.Target,
|
|
1710
|
+
title: "Referential Actions",
|
|
1711
|
+
description: "Control cascade & deletion behavior"
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
icon: lucide_react.Zap,
|
|
1715
|
+
title: "Query Optimization",
|
|
1716
|
+
description: "Efficient joins & data retrieval"
|
|
1717
|
+
}
|
|
1718
|
+
]
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
//#endregion
|
|
1723
|
+
//#region src/compat/relation-provisions.ts
|
|
1724
|
+
function useRelationProvisionsQuery(variables) {
|
|
1725
|
+
const { adapter, scope } = require_query.useSchemaBuilder();
|
|
1726
|
+
const { enabled = true, ...operationVariables } = variables;
|
|
1727
|
+
return (0, _tanstack_react_query.useQuery)({
|
|
1728
|
+
queryKey: [
|
|
1729
|
+
"schema-builder",
|
|
1730
|
+
scope,
|
|
1731
|
+
"relationProvisions",
|
|
1732
|
+
operationVariables
|
|
1733
|
+
],
|
|
1734
|
+
queryFn: ({ signal }) => adapter.relationships.relationProvisions(operationVariables, {
|
|
1735
|
+
scope,
|
|
1736
|
+
signal
|
|
1737
|
+
}),
|
|
1738
|
+
enabled
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
//#endregion
|
|
1743
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationship-utils.ts
|
|
1744
|
+
/** Map backend relation type names to UI RelationshipType */
|
|
1745
|
+
const PROVISION_TYPE_MAP = {
|
|
1746
|
+
[node_type_registry.RelationHasOne.name]: "one-to-one",
|
|
1747
|
+
[node_type_registry.RelationBelongsTo.name]: "belongs-to",
|
|
1748
|
+
[node_type_registry.RelationHasMany.name]: "one-to-many",
|
|
1749
|
+
[node_type_registry.RelationManyToMany.name]: "many-to-many"
|
|
1750
|
+
};
|
|
1751
|
+
function isForeignKeyConstraint(constraint) {
|
|
1752
|
+
return typeof constraint === "object" && constraint != null && "type" in constraint && constraint.type === "foreign_key";
|
|
1753
|
+
}
|
|
1754
|
+
function resolveFieldName(table, fieldId) {
|
|
1755
|
+
if (!fieldId) return "";
|
|
1756
|
+
return table?.fields.find((field) => field.id === fieldId)?.name || fieldId;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Find matching provision for an FK constraint.
|
|
1760
|
+
* Match by outFieldId (the FK field created by the provision) first,
|
|
1761
|
+
* then fall back to sourceTableId + targetTableId match.
|
|
1762
|
+
*/
|
|
1763
|
+
function findProvision(constraint, sourceTableId, provisions) {
|
|
1764
|
+
const fkFieldId = constraint.fields[0];
|
|
1765
|
+
if (fkFieldId) {
|
|
1766
|
+
const byField = provisions.find((p) => p.outFieldId === fkFieldId);
|
|
1767
|
+
if (byField) return byField;
|
|
1768
|
+
}
|
|
1769
|
+
const targetTableId = constraint.referencedTable;
|
|
1770
|
+
return provisions.find((p) => p.sourceTableId === sourceTableId && p.targetTableId === targetTableId);
|
|
1771
|
+
}
|
|
1772
|
+
function resolveRelationshipType(constraint, provision) {
|
|
1773
|
+
if (provision?.relationType) {
|
|
1774
|
+
const mapped = PROVISION_TYPE_MAP[provision.relationType];
|
|
1775
|
+
if (mapped) return mapped;
|
|
1776
|
+
}
|
|
1777
|
+
return constraint.smartTags?.relationshipType || "one-to-many";
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Get all relationships involving the current table.
|
|
1781
|
+
* Source/target are oriented from the current table's perspective:
|
|
1782
|
+
* - belongs-to: currentTable (has FK) → referenced table
|
|
1783
|
+
* - one-to-one: currentTable (has FK) → referenced table
|
|
1784
|
+
* - one-to-many: currentTable (the "one" side) → other table (has FK)
|
|
1785
|
+
* - For FK on other table referencing current: other table → currentTable
|
|
1786
|
+
*/
|
|
1787
|
+
function getTableRelationships(currentTable, tables, provisions = []) {
|
|
1788
|
+
if (!currentTable) return [];
|
|
1789
|
+
const relationships = [];
|
|
1790
|
+
const seenConstraintIds = /* @__PURE__ */ new Set();
|
|
1791
|
+
const ownForeignKeys = (currentTable.constraints || []).filter(isForeignKeyConstraint);
|
|
1792
|
+
for (const constraint of ownForeignKeys) {
|
|
1793
|
+
seenConstraintIds.add(constraint.id);
|
|
1794
|
+
const targetTable = tables.find((table) => table.id === constraint.referencedTable);
|
|
1795
|
+
const provision = findProvision(constraint, currentTable.id, provisions);
|
|
1796
|
+
relationships.push({
|
|
1797
|
+
constraint,
|
|
1798
|
+
sourceTable: currentTable,
|
|
1799
|
+
targetTable,
|
|
1800
|
+
sourceFieldName: resolveFieldName(currentTable, constraint.fields[0]),
|
|
1801
|
+
targetFieldName: resolveFieldName(targetTable, constraint.referencedFields?.[0]),
|
|
1802
|
+
relationshipType: resolveRelationshipType(constraint, provision),
|
|
1803
|
+
provision
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
for (const otherTable of tables) {
|
|
1807
|
+
if (otherTable.id === currentTable.id) continue;
|
|
1808
|
+
const referencesCurrent = (otherTable.constraints || []).filter(isForeignKeyConstraint).filter((c) => c.referencedTable === currentTable.id);
|
|
1809
|
+
for (const constraint of referencesCurrent) {
|
|
1810
|
+
if (seenConstraintIds.has(constraint.id)) continue;
|
|
1811
|
+
seenConstraintIds.add(constraint.id);
|
|
1812
|
+
const provision = findProvision(constraint, otherTable.id, provisions);
|
|
1813
|
+
let relationshipType = resolveRelationshipType(constraint, provision);
|
|
1814
|
+
let withTableName;
|
|
1815
|
+
const m2mProvision = provisions.find((p) => p.relationType === node_type_registry.RelationManyToMany.name && p.outJunctionTableId === otherTable.id && (p.sourceTableId === currentTable.id || p.targetTableId === currentTable.id));
|
|
1816
|
+
if (m2mProvision) {
|
|
1817
|
+
relationshipType = "many-to-many";
|
|
1818
|
+
const actualTargetId = m2mProvision.sourceTableId === currentTable.id ? m2mProvision.targetTableId : m2mProvision.sourceTableId;
|
|
1819
|
+
withTableName = tables.find((t) => t.id === actualTargetId)?.name;
|
|
1820
|
+
}
|
|
1821
|
+
if (relationshipType === "one-to-many" || relationshipType === "one-to-one" || relationshipType === "many-to-many") relationships.push({
|
|
1822
|
+
constraint,
|
|
1823
|
+
sourceTable: currentTable,
|
|
1824
|
+
targetTable: otherTable,
|
|
1825
|
+
sourceFieldName: resolveFieldName(currentTable, constraint.referencedFields?.[0]),
|
|
1826
|
+
targetFieldName: resolveFieldName(otherTable, constraint.fields[0]),
|
|
1827
|
+
relationshipType,
|
|
1828
|
+
provision: m2mProvision ?? provision,
|
|
1829
|
+
withTableName
|
|
1830
|
+
});
|
|
1831
|
+
else relationships.push({
|
|
1832
|
+
constraint,
|
|
1833
|
+
sourceTable: otherTable,
|
|
1834
|
+
targetTable: currentTable,
|
|
1835
|
+
sourceFieldName: resolveFieldName(otherTable, constraint.fields[0]),
|
|
1836
|
+
targetFieldName: resolveFieldName(currentTable, constraint.referencedFields?.[0]),
|
|
1837
|
+
relationshipType,
|
|
1838
|
+
provision
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
relationships.sort((a, b) => {
|
|
1843
|
+
const aTime = a.constraint.createdAt || "";
|
|
1844
|
+
return (b.constraint.createdAt || "").localeCompare(aTime);
|
|
1845
|
+
});
|
|
1846
|
+
return relationships;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
//#endregion
|
|
1850
|
+
//#region src/schema/schema-builder-relationships/components/table-editor/relationships/relationships-view.tsx
|
|
1851
|
+
const RELATIONSHIP_STYLES = {
|
|
1852
|
+
"one-to-one": {
|
|
1853
|
+
bg: "bg-purple-500/10",
|
|
1854
|
+
border: "border-purple-500/30",
|
|
1855
|
+
text: "text-purple-600 dark:text-purple-400",
|
|
1856
|
+
label: "One to One",
|
|
1857
|
+
shortLabel: "1:1"
|
|
1858
|
+
},
|
|
1859
|
+
"belongs-to": {
|
|
1860
|
+
bg: "bg-green-500/10",
|
|
1861
|
+
border: "border-green-500/30",
|
|
1862
|
+
text: "text-green-600 dark:text-green-400",
|
|
1863
|
+
label: "Belongs To",
|
|
1864
|
+
shortLabel: "BT"
|
|
1865
|
+
},
|
|
1866
|
+
"one-to-many": {
|
|
1867
|
+
bg: "bg-blue-500/10",
|
|
1868
|
+
border: "border-blue-500/30",
|
|
1869
|
+
text: "text-blue-600 dark:text-blue-400",
|
|
1870
|
+
label: "One to Many",
|
|
1871
|
+
shortLabel: "1:N"
|
|
1872
|
+
},
|
|
1873
|
+
"many-to-many": {
|
|
1874
|
+
bg: "bg-amber-500/10",
|
|
1875
|
+
border: "border-amber-500/30",
|
|
1876
|
+
text: "text-amber-600 dark:text-amber-400",
|
|
1877
|
+
label: "Many to Many",
|
|
1878
|
+
shortLabel: "N:M"
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
function MiniConnector({ type }) {
|
|
1882
|
+
if (type === "one-to-one") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1883
|
+
width: "32",
|
|
1884
|
+
height: "16",
|
|
1885
|
+
viewBox: "0 0 32 16",
|
|
1886
|
+
fill: "none",
|
|
1887
|
+
className: "shrink-0",
|
|
1888
|
+
children: [
|
|
1889
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1890
|
+
cx: "4",
|
|
1891
|
+
cy: "8",
|
|
1892
|
+
r: "3",
|
|
1893
|
+
fill: "currentColor",
|
|
1894
|
+
fillOpacity: "0.3",
|
|
1895
|
+
stroke: "currentColor",
|
|
1896
|
+
strokeWidth: "1.5"
|
|
1897
|
+
}),
|
|
1898
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
1899
|
+
x1: "8",
|
|
1900
|
+
y1: "8",
|
|
1901
|
+
x2: "24",
|
|
1902
|
+
y2: "8",
|
|
1903
|
+
stroke: "currentColor",
|
|
1904
|
+
strokeWidth: "1.5",
|
|
1905
|
+
strokeDasharray: "2 2"
|
|
1906
|
+
}),
|
|
1907
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1908
|
+
cx: "28",
|
|
1909
|
+
cy: "8",
|
|
1910
|
+
r: "3",
|
|
1911
|
+
fill: "currentColor",
|
|
1912
|
+
fillOpacity: "0.3",
|
|
1913
|
+
stroke: "currentColor",
|
|
1914
|
+
strokeWidth: "1.5"
|
|
1915
|
+
})
|
|
1916
|
+
]
|
|
1917
|
+
});
|
|
1918
|
+
if (type === "belongs-to") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1919
|
+
width: "32",
|
|
1920
|
+
height: "16",
|
|
1921
|
+
viewBox: "0 0 32 16",
|
|
1922
|
+
fill: "none",
|
|
1923
|
+
className: "shrink-0",
|
|
1924
|
+
children: [
|
|
1925
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1926
|
+
cx: "6",
|
|
1927
|
+
cy: "3",
|
|
1928
|
+
r: "2",
|
|
1929
|
+
fill: "currentColor"
|
|
1930
|
+
}),
|
|
1931
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1932
|
+
cx: "4",
|
|
1933
|
+
cy: "8",
|
|
1934
|
+
r: "2",
|
|
1935
|
+
fill: "currentColor"
|
|
1936
|
+
}),
|
|
1937
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1938
|
+
cx: "6",
|
|
1939
|
+
cy: "13",
|
|
1940
|
+
r: "2",
|
|
1941
|
+
fill: "currentColor"
|
|
1942
|
+
}),
|
|
1943
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
1944
|
+
x1: "10",
|
|
1945
|
+
y1: "8",
|
|
1946
|
+
x2: "20",
|
|
1947
|
+
y2: "8",
|
|
1948
|
+
stroke: "currentColor",
|
|
1949
|
+
strokeWidth: "1.5"
|
|
1950
|
+
}),
|
|
1951
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
1952
|
+
d: "M18 5L22 8L18 11",
|
|
1953
|
+
stroke: "currentColor",
|
|
1954
|
+
strokeWidth: "1.5",
|
|
1955
|
+
fill: "none",
|
|
1956
|
+
strokeLinecap: "round"
|
|
1957
|
+
}),
|
|
1958
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1959
|
+
cx: "28",
|
|
1960
|
+
cy: "8",
|
|
1961
|
+
r: "3",
|
|
1962
|
+
fill: "currentColor",
|
|
1963
|
+
fillOpacity: "0.3",
|
|
1964
|
+
stroke: "currentColor",
|
|
1965
|
+
strokeWidth: "1.5"
|
|
1966
|
+
})
|
|
1967
|
+
]
|
|
1968
|
+
});
|
|
1969
|
+
if (type === "one-to-many") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1970
|
+
width: "32",
|
|
1971
|
+
height: "16",
|
|
1972
|
+
viewBox: "0 0 32 16",
|
|
1973
|
+
fill: "none",
|
|
1974
|
+
className: "shrink-0",
|
|
1975
|
+
children: [
|
|
1976
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
1977
|
+
cx: "4",
|
|
1978
|
+
cy: "8",
|
|
1979
|
+
r: "3",
|
|
1980
|
+
fill: "currentColor",
|
|
1981
|
+
fillOpacity: "0.3",
|
|
1982
|
+
stroke: "currentColor",
|
|
1983
|
+
strokeWidth: "1.5"
|
|
1984
|
+
}),
|
|
1985
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
1986
|
+
x1: "8",
|
|
1987
|
+
y1: "8",
|
|
1988
|
+
x2: "20",
|
|
1989
|
+
y2: "8",
|
|
1990
|
+
stroke: "currentColor",
|
|
1991
|
+
strokeWidth: "1.5"
|
|
1992
|
+
}),
|
|
1993
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
1994
|
+
d: "M18 5L22 8L18 11",
|
|
1995
|
+
stroke: "currentColor",
|
|
1996
|
+
strokeWidth: "1.5",
|
|
1997
|
+
fill: "none",
|
|
1998
|
+
strokeLinecap: "round"
|
|
1999
|
+
}),
|
|
2000
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2001
|
+
cx: "26",
|
|
2002
|
+
cy: "3",
|
|
2003
|
+
r: "2",
|
|
2004
|
+
fill: "currentColor"
|
|
2005
|
+
}),
|
|
2006
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2007
|
+
cx: "28",
|
|
2008
|
+
cy: "8",
|
|
2009
|
+
r: "2",
|
|
2010
|
+
fill: "currentColor"
|
|
2011
|
+
}),
|
|
2012
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2013
|
+
cx: "26",
|
|
2014
|
+
cy: "13",
|
|
2015
|
+
r: "2",
|
|
2016
|
+
fill: "currentColor"
|
|
2017
|
+
})
|
|
2018
|
+
]
|
|
2019
|
+
});
|
|
2020
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
2021
|
+
width: "32",
|
|
2022
|
+
height: "16",
|
|
2023
|
+
viewBox: "0 0 32 16",
|
|
2024
|
+
fill: "none",
|
|
2025
|
+
className: "shrink-0",
|
|
2026
|
+
children: [
|
|
2027
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2028
|
+
cx: "4",
|
|
2029
|
+
cy: "3",
|
|
2030
|
+
r: "2",
|
|
2031
|
+
fill: "currentColor"
|
|
2032
|
+
}),
|
|
2033
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2034
|
+
cx: "2",
|
|
2035
|
+
cy: "8",
|
|
2036
|
+
r: "2",
|
|
2037
|
+
fill: "currentColor"
|
|
2038
|
+
}),
|
|
2039
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2040
|
+
cx: "4",
|
|
2041
|
+
cy: "13",
|
|
2042
|
+
r: "2",
|
|
2043
|
+
fill: "currentColor"
|
|
2044
|
+
}),
|
|
2045
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
2046
|
+
x1: "8",
|
|
2047
|
+
y1: "8",
|
|
2048
|
+
x2: "24",
|
|
2049
|
+
y2: "8",
|
|
2050
|
+
stroke: "currentColor",
|
|
2051
|
+
strokeWidth: "1.5"
|
|
2052
|
+
}),
|
|
2053
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2054
|
+
cx: "28",
|
|
2055
|
+
cy: "3",
|
|
2056
|
+
r: "2",
|
|
2057
|
+
fill: "currentColor"
|
|
2058
|
+
}),
|
|
2059
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2060
|
+
cx: "30",
|
|
2061
|
+
cy: "8",
|
|
2062
|
+
r: "2",
|
|
2063
|
+
fill: "currentColor"
|
|
2064
|
+
}),
|
|
2065
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
2066
|
+
cx: "28",
|
|
2067
|
+
cy: "13",
|
|
2068
|
+
r: "2",
|
|
2069
|
+
fill: "currentColor"
|
|
2070
|
+
})
|
|
2071
|
+
]
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
function NoTableSelectedState() {
|
|
2075
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2076
|
+
className: "flex min-h-0 flex-1 flex-col items-center justify-center p-6",
|
|
2077
|
+
children: [
|
|
2078
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2079
|
+
className: "bg-muted/50 mb-4 flex h-16 w-16 items-center justify-center rounded-full",
|
|
2080
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Table2, { className: "text-muted-foreground h-8 w-8" })
|
|
2081
|
+
}),
|
|
2082
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
2083
|
+
className: "mb-1 text-balance text-lg font-semibold",
|
|
2084
|
+
children: "No table selected"
|
|
2085
|
+
}),
|
|
2086
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2087
|
+
className: "text-muted-foreground max-w-sm text-center text-sm",
|
|
2088
|
+
children: "Select a table from the sidebar to view and manage its relationships."
|
|
2089
|
+
})
|
|
2090
|
+
]
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
function RelationshipsView() {
|
|
2094
|
+
const [deleteTarget, setDeleteTarget] = (0, react.useState)(null);
|
|
2095
|
+
const [isDeleting, setIsDeleting] = (0, react.useState)(false);
|
|
2096
|
+
const stack = (0, _constructive_io_ui_stack.useCardStack)();
|
|
2097
|
+
const { currentTable, currentSchema, currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
2098
|
+
const deleteForeignKeyMutation = useDeleteForeignKey();
|
|
2099
|
+
const tables = currentSchema?.tables || [];
|
|
2100
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId ?? "";
|
|
2101
|
+
const { data: provisionsData } = useRelationProvisionsQuery({
|
|
2102
|
+
selection: {
|
|
2103
|
+
fields: {
|
|
2104
|
+
id: true,
|
|
2105
|
+
relationType: true,
|
|
2106
|
+
sourceTableId: true,
|
|
2107
|
+
targetTableId: true,
|
|
2108
|
+
outFieldId: true,
|
|
2109
|
+
outJunctionTableId: true,
|
|
2110
|
+
exposeInApi: true
|
|
2111
|
+
},
|
|
2112
|
+
where: databaseId ? { databaseId: { equalTo: databaseId } } : void 0
|
|
2113
|
+
},
|
|
2114
|
+
enabled: !!databaseId
|
|
2115
|
+
});
|
|
2116
|
+
const provisions = (0, react.useMemo)(() => {
|
|
2117
|
+
const nodes = provisionsData?.relationProvisions?.nodes;
|
|
2118
|
+
if (!nodes) return [];
|
|
2119
|
+
return nodes.map((n) => ({
|
|
2120
|
+
id: n.id,
|
|
2121
|
+
relationType: n.relationType ?? null,
|
|
2122
|
+
sourceTableId: n.sourceTableId ?? null,
|
|
2123
|
+
targetTableId: n.targetTableId ?? null,
|
|
2124
|
+
outFieldId: n.outFieldId ?? null,
|
|
2125
|
+
outJunctionTableId: n.outJunctionTableId ?? null,
|
|
2126
|
+
exposeInApi: n.exposeInApi ?? null
|
|
2127
|
+
}));
|
|
2128
|
+
}, [provisionsData]);
|
|
2129
|
+
const relationships = (0, react.useMemo)(() => getTableRelationships(currentTable, tables, provisions), [
|
|
2130
|
+
currentTable,
|
|
2131
|
+
tables,
|
|
2132
|
+
provisions
|
|
2133
|
+
]);
|
|
2134
|
+
const handleOpenCreate = () => {
|
|
2135
|
+
if (!currentTable) return;
|
|
2136
|
+
stack.push({
|
|
2137
|
+
id: "relationship-new",
|
|
2138
|
+
title: "Create Relationship",
|
|
2139
|
+
Component: RelationshipCard,
|
|
2140
|
+
props: {
|
|
2141
|
+
editingRelationship: null,
|
|
2142
|
+
sourceTable: currentTable
|
|
2143
|
+
},
|
|
2144
|
+
width: 540
|
|
2145
|
+
});
|
|
2146
|
+
};
|
|
2147
|
+
const handleOpenEdit = (rel) => {
|
|
2148
|
+
const sourceTable = rel.sourceTable ?? currentTable;
|
|
2149
|
+
if (!sourceTable) return;
|
|
2150
|
+
stack.push({
|
|
2151
|
+
id: `relationship-edit-${rel.constraint.id}`,
|
|
2152
|
+
title: "Edit Relationship",
|
|
2153
|
+
Component: RelationshipCard,
|
|
2154
|
+
props: {
|
|
2155
|
+
editingRelationship: rel,
|
|
2156
|
+
sourceTable
|
|
2157
|
+
},
|
|
2158
|
+
width: 540
|
|
2159
|
+
});
|
|
2160
|
+
};
|
|
2161
|
+
const handleDeleteRequest = (constraintId, constraintName) => {
|
|
2162
|
+
setDeleteTarget({
|
|
2163
|
+
id: constraintId,
|
|
2164
|
+
name: constraintName
|
|
2165
|
+
});
|
|
2166
|
+
};
|
|
2167
|
+
const handleDeleteConfirm = async () => {
|
|
2168
|
+
if (!deleteTarget) return;
|
|
2169
|
+
setIsDeleting(true);
|
|
2170
|
+
try {
|
|
2171
|
+
await deleteForeignKeyMutation.mutateAsync({ id: deleteTarget.id });
|
|
2172
|
+
_constructive_io_ui_toast.toast.success({ message: "Relationship deleted" });
|
|
2173
|
+
setDeleteTarget(null);
|
|
2174
|
+
} catch (error) {
|
|
2175
|
+
_constructive_io_ui_toast.toast.error({
|
|
2176
|
+
message: "Failed to delete relationship",
|
|
2177
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
2178
|
+
});
|
|
2179
|
+
} finally {
|
|
2180
|
+
setIsDeleting(false);
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
if (!currentTable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NoTableSelectedState, {});
|
|
2184
|
+
const hasRelationships = relationships.length > 0;
|
|
2185
|
+
function renderRelationshipCard(rel) {
|
|
2186
|
+
const style = RELATIONSHIP_STYLES[rel.relationshipType];
|
|
2187
|
+
const isM2M = !!rel.withTableName;
|
|
2188
|
+
let junctionTargetFieldName;
|
|
2189
|
+
let targetPkFieldName;
|
|
2190
|
+
if (isM2M && rel.targetTable) {
|
|
2191
|
+
const junction = rel.targetTable;
|
|
2192
|
+
const actualTarget = tables.find((t) => t.name === rel.withTableName);
|
|
2193
|
+
if (actualTarget) {
|
|
2194
|
+
const junctionFk = (junction.constraints || []).find((c) => c.type === "foreign_key" && c.referencedTable === actualTarget.id);
|
|
2195
|
+
if (junctionFk) {
|
|
2196
|
+
junctionTargetFieldName = junction.fields.find((f) => f.id === junctionFk.fields[0])?.name;
|
|
2197
|
+
targetPkFieldName = actualTarget.fields.find((f) => f.id === junctionFk.referencedFields?.[0])?.name;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2202
|
+
role: "button",
|
|
2203
|
+
tabIndex: 0,
|
|
2204
|
+
"data-testid": "relationship-row",
|
|
2205
|
+
onClick: () => handleOpenEdit(rel),
|
|
2206
|
+
onKeyDown: (event) => {
|
|
2207
|
+
require_keyboard_activation.handleActivationKeyDown(event, () => handleOpenEdit(rel));
|
|
2208
|
+
},
|
|
2209
|
+
className: require_invalidate_database_entities.cn(`group relative cursor-pointer rounded-xl border p-4 transition-[background-color,border-color,box-shadow,scale]
|
|
2210
|
+
duration-150 ease-out motion-safe:active:scale-[0.96]`, "border-border/60 hover:border-border/80 hover:bg-muted/30"),
|
|
2211
|
+
children: [
|
|
2212
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2213
|
+
className: "flex items-center justify-between gap-2",
|
|
2214
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2215
|
+
className: "flex min-w-0 flex-wrap items-center gap-2",
|
|
2216
|
+
children: [
|
|
2217
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Link2, { className: "text-muted-foreground h-4 w-4 shrink-0" }),
|
|
2218
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2219
|
+
className: "truncate text-sm font-semibold",
|
|
2220
|
+
children: rel.constraint.name
|
|
2221
|
+
}),
|
|
2222
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2223
|
+
className: require_invalidate_database_entities.cn("shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold tracking-wide uppercase", style.bg, style.text, "border", style.border),
|
|
2224
|
+
children: style.label
|
|
2225
|
+
})
|
|
2226
|
+
]
|
|
2227
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
2228
|
+
variant: "ghost",
|
|
2229
|
+
size: "sm",
|
|
2230
|
+
"aria-label": "Delete relationship",
|
|
2231
|
+
className: "text-muted-foreground hover:text-destructive hover:bg-destructive/10 h-8 w-8 shrink-0 p-0",
|
|
2232
|
+
onClick: (e) => {
|
|
2233
|
+
e.stopPropagation();
|
|
2234
|
+
handleDeleteRequest(rel.constraint.id, rel.constraint.name || "this relationship");
|
|
2235
|
+
},
|
|
2236
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "h-4 w-4" })
|
|
2237
|
+
})]
|
|
2238
|
+
}),
|
|
2239
|
+
isM2M ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2240
|
+
className: "mt-3 space-y-2",
|
|
2241
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2242
|
+
className: "flex items-center gap-2",
|
|
2243
|
+
children: [
|
|
2244
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2245
|
+
className: "bg-background truncate rounded-md border px-3 py-1.5 font-mono text-sm",
|
|
2246
|
+
children: [
|
|
2247
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2248
|
+
className: "text-foreground",
|
|
2249
|
+
children: rel.sourceTable?.name || "?"
|
|
2250
|
+
}),
|
|
2251
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2252
|
+
className: "text-muted-foreground",
|
|
2253
|
+
children: "."
|
|
2254
|
+
}),
|
|
2255
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2256
|
+
className: style.text,
|
|
2257
|
+
children: rel.sourceFieldName || "?"
|
|
2258
|
+
})
|
|
2259
|
+
]
|
|
2260
|
+
}),
|
|
2261
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2262
|
+
className: style.text,
|
|
2263
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MiniConnector, { type: "many-to-many" })
|
|
2264
|
+
}),
|
|
2265
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2266
|
+
className: "bg-muted/50 truncate rounded-md border border-dashed px-3 py-1.5 font-mono text-sm",
|
|
2267
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2268
|
+
className: "text-muted-foreground",
|
|
2269
|
+
children: rel.targetTable?.name || "?"
|
|
2270
|
+
})
|
|
2271
|
+
}),
|
|
2272
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2273
|
+
className: style.text,
|
|
2274
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MiniConnector, { type: "many-to-many" })
|
|
2275
|
+
}),
|
|
2276
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2277
|
+
className: "bg-background truncate rounded-md border px-3 py-1.5 font-mono text-sm",
|
|
2278
|
+
children: [
|
|
2279
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2280
|
+
className: "text-foreground",
|
|
2281
|
+
children: rel.withTableName
|
|
2282
|
+
}),
|
|
2283
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2284
|
+
className: "text-muted-foreground",
|
|
2285
|
+
children: "."
|
|
2286
|
+
}),
|
|
2287
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2288
|
+
className: style.text,
|
|
2289
|
+
children: targetPkFieldName || "id"
|
|
2290
|
+
})
|
|
2291
|
+
]
|
|
2292
|
+
})
|
|
2293
|
+
]
|
|
2294
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2295
|
+
className: "text-muted-foreground flex items-center gap-1.5 pl-1 font-mono text-[10px]",
|
|
2296
|
+
children: [
|
|
2297
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "via" }),
|
|
2298
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2299
|
+
className: "bg-muted rounded px-1.5 py-0.5",
|
|
2300
|
+
children: rel.targetFieldName || "?"
|
|
2301
|
+
}),
|
|
2302
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "&" }),
|
|
2303
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2304
|
+
className: "bg-muted rounded px-1.5 py-0.5",
|
|
2305
|
+
children: junctionTargetFieldName || "?"
|
|
2306
|
+
})
|
|
2307
|
+
]
|
|
2308
|
+
})]
|
|
2309
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2310
|
+
className: "mt-3 flex items-center gap-3",
|
|
2311
|
+
children: [
|
|
2312
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2313
|
+
className: "bg-background truncate rounded-md border px-3 py-1.5 font-mono text-sm",
|
|
2314
|
+
children: [
|
|
2315
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2316
|
+
className: "text-foreground",
|
|
2317
|
+
children: rel.sourceTable?.name || "?"
|
|
2318
|
+
}),
|
|
2319
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2320
|
+
className: "text-muted-foreground",
|
|
2321
|
+
children: "."
|
|
2322
|
+
}),
|
|
2323
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2324
|
+
className: style.text,
|
|
2325
|
+
children: rel.sourceFieldName || "?"
|
|
2326
|
+
})
|
|
2327
|
+
]
|
|
2328
|
+
}),
|
|
2329
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2330
|
+
className: style.text,
|
|
2331
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MiniConnector, { type: rel.relationshipType })
|
|
2332
|
+
}),
|
|
2333
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2334
|
+
className: "bg-background truncate rounded-md border px-3 py-1.5 font-mono text-sm",
|
|
2335
|
+
children: [
|
|
2336
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2337
|
+
className: "text-foreground",
|
|
2338
|
+
children: rel.targetTable?.name || "?"
|
|
2339
|
+
}),
|
|
2340
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2341
|
+
className: "text-muted-foreground",
|
|
2342
|
+
children: "."
|
|
2343
|
+
}),
|
|
2344
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2345
|
+
className: style.text,
|
|
2346
|
+
children: rel.targetFieldName || "?"
|
|
2347
|
+
})
|
|
2348
|
+
]
|
|
2349
|
+
})
|
|
2350
|
+
]
|
|
2351
|
+
}),
|
|
2352
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2353
|
+
className: "mt-3 flex items-center justify-between gap-4 border-t pt-3",
|
|
2354
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2355
|
+
className: "text-muted-foreground flex items-center gap-1.5 text-xs",
|
|
2356
|
+
children: [
|
|
2357
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CornerDownRight, { className: "h-3 w-3" }),
|
|
2358
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "On Delete:" }),
|
|
2359
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2360
|
+
className: "text-foreground/70 font-medium",
|
|
2361
|
+
children: require_invalidate_database_entities.ForeignKeyActionLabels[rel.constraint.onDelete ?? require_invalidate_database_entities.ForeignKeyActions.NO_ACTION]
|
|
2362
|
+
})
|
|
2363
|
+
]
|
|
2364
|
+
})
|
|
2365
|
+
})
|
|
2366
|
+
]
|
|
2367
|
+
}, rel.constraint.id);
|
|
2368
|
+
}
|
|
2369
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2370
|
+
"data-chat-component": "relationships-view",
|
|
2371
|
+
"data-chat-relationship-count": String(relationships.length),
|
|
2372
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto p-6",
|
|
2373
|
+
children: !hasRelationships ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RelationshipEmptyState, {
|
|
2374
|
+
onCreateClick: handleOpenCreate,
|
|
2375
|
+
tableName: currentTable.name
|
|
2376
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2377
|
+
className: "mx-auto w-full min-w-80 max-w-4xl space-y-6",
|
|
2378
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2379
|
+
className: "flex items-center justify-between gap-4",
|
|
2380
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
2381
|
+
className: "text-balance text-xl font-semibold tracking-tight",
|
|
2382
|
+
children: "Relationships"
|
|
2383
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
2384
|
+
className: "text-muted-foreground mt-1 text-sm",
|
|
2385
|
+
children: [
|
|
2386
|
+
relationships.length,
|
|
2387
|
+
" connection",
|
|
2388
|
+
relationships.length !== 1 ? "s" : "",
|
|
2389
|
+
" for",
|
|
2390
|
+
" ",
|
|
2391
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
2392
|
+
className: "bg-muted rounded px-1.5 py-0.5 font-mono text-xs",
|
|
2393
|
+
children: currentTable.name
|
|
2394
|
+
})
|
|
2395
|
+
]
|
|
2396
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
2397
|
+
onClick: handleOpenCreate,
|
|
2398
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Link2, { className: "mr-2 h-4 w-4" }), "Add Relationship"]
|
|
2399
|
+
})]
|
|
2400
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2401
|
+
className: "space-y-3",
|
|
2402
|
+
children: relationships.map(renderRelationshipCard)
|
|
2403
|
+
})]
|
|
2404
|
+
})
|
|
2405
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_delete_confirm_dialog.DeleteConfirmDialog, {
|
|
2406
|
+
entityType: "Relationship",
|
|
2407
|
+
entityName: deleteTarget?.name ?? null,
|
|
2408
|
+
open: !!deleteTarget,
|
|
2409
|
+
onOpenChange: () => setDeleteTarget(null),
|
|
2410
|
+
onConfirm: handleDeleteConfirm,
|
|
2411
|
+
isPending: isDeleting
|
|
2412
|
+
})] });
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
//#endregion
|
|
2416
|
+
Object.defineProperty(exports, 'RelationshipsView', {
|
|
2417
|
+
enumerable: true,
|
|
2418
|
+
get: function () {
|
|
2419
|
+
return RelationshipsView;
|
|
2420
|
+
}
|
|
2421
|
+
});
|
|
2422
|
+
Object.defineProperty(exports, 'useCreateForeignKey', {
|
|
2423
|
+
enumerable: true,
|
|
2424
|
+
get: function () {
|
|
2425
|
+
return useCreateForeignKey;
|
|
2426
|
+
}
|
|
2427
|
+
});
|
|
2428
|
+
Object.defineProperty(exports, 'useCreateManyToMany', {
|
|
2429
|
+
enumerable: true,
|
|
2430
|
+
get: function () {
|
|
2431
|
+
return useCreateManyToMany;
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
Object.defineProperty(exports, 'useDeleteForeignKey', {
|
|
2435
|
+
enumerable: true,
|
|
2436
|
+
get: function () {
|
|
2437
|
+
return useDeleteForeignKey;
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
Object.defineProperty(exports, 'useRelationProvision', {
|
|
2441
|
+
enumerable: true,
|
|
2442
|
+
get: function () {
|
|
2443
|
+
return useRelationProvision;
|
|
2444
|
+
}
|
|
2445
|
+
});
|
|
2446
|
+
Object.defineProperty(exports, 'useUpdateForeignKey', {
|
|
2447
|
+
enumerable: true,
|
|
2448
|
+
get: function () {
|
|
2449
|
+
return useUpdateForeignKey;
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
//# sourceMappingURL=relationships-view-B5TAcPHU.cjs.map
|