@dineug/erd-editor 3.9.1 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +46 -9
  2. package/dist/components/erd/Erd.d.ts +1 -0
  3. package/dist/components/erd/canvas/relationship-group/relationship/Relationship.d.ts +2 -0
  4. package/dist/components/erd/canvas/relationship-group/relationship/RelationshipActionLabel.d.ts +32 -0
  5. package/dist/components/erd/canvas/table/cellLayout.d.ts +11 -0
  6. package/dist/components/erd/canvas/table/column/Column.d.ts +7 -0
  7. package/dist/components/erd/canvas/table/goToErd.d.ts +3 -10
  8. package/dist/components/erd/erd-context-menu/menus/relationshipMenus.d.ts +11 -0
  9. package/dist/components/erd/goToErdTarget.d.ts +85 -0
  10. package/dist/components/erd/table-properties/TableProperties.d.ts +2 -0
  11. package/dist/components/erd/table-properties/TableProperties.styles.d.ts +24 -2
  12. package/dist/components/erd/table-properties/table-properties-indexes/TablePropertiesIndexes.d.ts +2 -0
  13. package/dist/components/erd/table-properties/table-properties-indexes/TablePropertiesIndexes.styles.d.ts +32 -0
  14. package/dist/components/erd/table-properties/table-properties-indexes/indexes-checkbox-column/IndexesCheckboxColumn.d.ts +7 -0
  15. package/dist/components/erd/table-properties/table-properties-indexes/indexes-checkbox-column/IndexesCheckboxColumn.styles.d.ts +5 -0
  16. package/dist/components/erd/table-properties/table-properties-indexes/indexes-column/IndexesColumn.d.ts +7 -0
  17. package/dist/components/erd/table-properties/table-properties-indexes/indexes-column/IndexesColumn.styles.d.ts +3 -0
  18. package/dist/components/erd/table-properties/table-properties-indexes/indexes-index/IndexesIndex.d.ts +7 -0
  19. package/dist/components/erd/table-properties/table-properties-indexes/indexes-index/IndexesIndex.styles.d.ts +6 -0
  20. package/dist/components/erd/table-properties/table-properties-indexes/indexes-key/IndexesKey.d.ts +15 -0
  21. package/dist/components/erd/table-properties/table-properties-indexes/indexes-key/IndexesKey.styles.d.ts +13 -0
  22. package/dist/components/erd-editor/ErdEditor.d.ts +1 -1
  23. package/dist/components/find-replace/FindReplace.d.ts +13 -0
  24. package/dist/components/find-replace/FindReplace.styles.d.ts +27 -0
  25. package/dist/components/find-replace/fieldIcon.d.ts +5 -0
  26. package/dist/components/find-replace/matchTarget.d.ts +26 -0
  27. package/dist/components/find-replace/panelLayout.d.ts +17 -0
  28. package/dist/components/primitives/icon/icons.d.ts +10 -1
  29. package/dist/components/quick-search/QuickSearch.styles.d.ts +6 -0
  30. package/dist/components/quick-search/actions.d.ts +23 -0
  31. package/dist/components/quick-search/hangul.d.ts +73 -0
  32. package/dist/components/quick-search/paletteQuery.d.ts +37 -0
  33. package/dist/components/quick-search/scopedActions.d.ts +41 -0
  34. package/dist/components/visualization/table/column/Column.d.ts +4 -0
  35. package/dist/constants/layout.d.ts +13 -0
  36. package/dist/constants/open.d.ts +1 -0
  37. package/dist/constants/schema.d.ts +13 -0
  38. package/dist/engine/index.d.ts +1 -1
  39. package/dist/engine/index.js +20 -14
  40. package/dist/engine/modules/relationship/actions.d.ts +13 -0
  41. package/dist/engine/modules/relationship/atom.actions.d.ts +54 -0
  42. package/dist/engine/modules/relationship/fkColumns.d.ts +20 -3
  43. package/dist/engine/modules/relationship/generator.actions.d.ts +5 -2
  44. package/dist/engine/modules/relationship/history.d.ts +2 -0
  45. package/dist/engine/modules/relationship/hooks.d.ts +11 -0
  46. package/dist/engine/modules/table-column/hooks.d.ts +6 -0
  47. package/dist/engine/replication-store.d.ts +15 -1
  48. package/dist/engine/rx-operators/flushOnNotifier.d.ts +6 -0
  49. package/dist/engine/shared-store.d.ts +2 -2
  50. package/dist/engine/store-hooks.d.ts +8 -0
  51. package/dist/erd-editor.umd.js +1038 -481
  52. package/dist/index.d.ts +1 -0
  53. package/dist/index.js +7151 -5306
  54. package/dist/konva/scene/metrics.d.ts +5 -0
  55. package/dist/{store-hooks-DuNN9ZKu.js → loadValue-Mdc5K4qO.js} +4002 -3426
  56. package/dist/peer/index.d.ts +1 -1
  57. package/dist/peer/index.js +77 -80
  58. package/dist/schemaGCService-CZtGFh2z.js +42 -0
  59. package/dist/services/schema-gc/schemaGCService.d.ts +5 -0
  60. package/dist/shared-store-D82WVL5a.js +1129 -0
  61. package/dist/utils/calcTable.d.ts +9 -1
  62. package/dist/utils/emitter.d.ts +13 -0
  63. package/dist/utils/find-replace/findMatches.d.ts +90 -0
  64. package/dist/utils/find-replace/index.d.ts +5 -0
  65. package/dist/utils/find-replace/matcher.d.ts +53 -0
  66. package/dist/utils/find-replace/present.d.ts +22 -0
  67. package/dist/utils/find-replace/replaceActions.d.ts +20 -0
  68. package/dist/utils/generator-code/utils.d.ts +12 -1
  69. package/dist/utils/keyboard-shortcut/index.d.ts +8 -1
  70. package/dist/utils/loadValue.d.ts +7 -0
  71. package/dist/utils/referentialAction.d.ts +21 -0
  72. package/dist/utils/schema-aml-parser/types.d.ts +6 -0
  73. package/dist/utils/schema-dbml-parser/types.d.ts +3 -0
  74. package/dist/utils/schema-sql/Databricks.d.ts +5 -0
  75. package/dist/utils/schema-sql/MSSQL.d.ts +5 -0
  76. package/dist/utils/schema-sql/MariaDB.d.ts +5 -0
  77. package/dist/utils/schema-sql/MySQL.d.ts +5 -0
  78. package/dist/utils/schema-sql/Oracle.d.ts +5 -0
  79. package/dist/utils/schema-sql/index.d.ts +5 -0
  80. package/dist/utils/schema-sql/utils.d.ts +19 -0
  81. package/dist/utils/schema-sql-parser/index.d.ts +5 -1
  82. package/dist/utils/table-clipboard/payload.d.ts +3 -0
  83. package/dist/utils/tableKeys.d.ts +46 -0
  84. package/dist/workers/elkLayout.shared-worker.js +1 -1
  85. package/dist/workers/exportPng.shared-worker.js +29 -27
  86. package/dist/workers/schemaGC.shared-worker.js +1 -1
  87. package/package.json +9 -8
  88. package/dist/schemaGCService-_8A8Oh9Q.js +0 -38
  89. package/dist/shared-store-CtJL8B4I.js +0 -1072
@@ -0,0 +1,1129 @@
1
+ import { A as e, Ai as t, At as n, Ba as r, Bi as i, C as a, Ct as o, D as s, Dt as c, Et as l, Fn as u, Fr as d, Ft as f, Ha as p, Mt as m, Nt as h, O as g, Oi as _, Ot as v, Pt as y, Qn as b, S as ee, St as x, T as S, Ta as C, Tt as w, Vi as T, Wa as te, _a as E, d as D, f as O, g as k, h as A, j, ji as M, jt as N, k as ne, ka as P, ki as F, kt as I, ln as re, m as ie, n as ae, p as oe, tr as se, u as ce, w as le, wt as L, x as ue } from "./loadValue-Mdc5K4qO.js";
2
+ import { isEmpty as de } from "es-toolkit/compat";
3
+ import { isFunction as fe, isNil as R } from "es-toolkit";
4
+ import { nanoid as z } from "nanoid";
5
+ import { Observable as B, Subject as V, debounceTime as pe, map as H, merge as me, race as he, startWith as ge, switchMap as U, take as W, timer as _e } from "rxjs";
6
+ //#region src/engine/history.ts
7
+ function G({ notify: e, dispatch: t, getNextVersion: n }, r) {
8
+ let i = r?.commands ?? [], a = r?.cursor ?? -1, o = r?.limit ?? 0, s = !0, c = () => a !== -1, l = () => a < i.length - 1, u = (e) => o = e, d = () => ({
9
+ hasRedo: l(),
10
+ hasUndo: c()
11
+ }), f = (e, r) => {
12
+ s = !1, e[r](t, n), s = !0;
13
+ };
14
+ return Object.freeze({
15
+ get cursor() {
16
+ return a;
17
+ },
18
+ get size() {
19
+ return i.length;
20
+ },
21
+ hasUndo: c,
22
+ hasRedo: l,
23
+ push: (t) => {
24
+ s && (i.splice(a + 1, i.length - a), i.push(t), o !== 0 && i.length > o && (i = i.slice(i.length - o, i.length)), a = i.length - 1, e(d()));
25
+ },
26
+ undo: () => {
27
+ if (!c()) return;
28
+ let t = i[a];
29
+ f(t, "undo"), a--, e(d());
30
+ },
31
+ redo: () => {
32
+ if (!l()) return;
33
+ let t = i[a + 1];
34
+ f(t, "redo"), a++, e(d());
35
+ },
36
+ clear: () => {
37
+ let t = i.length;
38
+ i = [], a = -1, t > 0 && e(d());
39
+ },
40
+ setLimit: u,
41
+ clone: (e) => G(e, {
42
+ commands: [...i],
43
+ cursor: a,
44
+ limit: o
45
+ })
46
+ });
47
+ }
48
+ //#endregion
49
+ //#region src/engine/rx-operators/flushOnNotifier.ts
50
+ var K = (e) => (t) => t.pipe(U((t) => e.pipe(W(1), H(() => t)))), ve = (e, t = 200) => (n) => n.pipe(U((n) => he(_e(t), e.pipe(W(1))).pipe(H(() => n)))), q = (e, t = []) => {
51
+ let n = E(a), r = (e) => !R(e.tags) && t.some((t) => _(e.tags, t)) || !n(e.type);
52
+ return (t) => new B((n) => t.subscribe({
53
+ next: (t) => {
54
+ n.next(e() ? t.filter(r) : t);
55
+ },
56
+ error: (e) => n.error(e),
57
+ complete: () => n.complete()
58
+ })).pipe(k);
59
+ }, ye = {
60
+ [d.scrollTo]: r.viewScrollTo,
61
+ [d.streamScrollTo]: r.viewStreamScrollTo,
62
+ [d.changeZoomLevel]: r.viewChangeZoomLevel,
63
+ [d.streamZoomLevel]: r.viewStreamZoomLevel
64
+ }, be = ({ tags: e }) => !R(e) && (_(e, F.shared) || _(e, F.following)), xe = (e) => {
65
+ let t = ye[e.type];
66
+ return t && !be(e) ? {
67
+ ...e,
68
+ type: t
69
+ } : e;
70
+ }, Se = (e) => (t) => new B((n) => t.subscribe({
71
+ next: (t) => {
72
+ n.next(e() ? t.map(xe) : t);
73
+ },
74
+ error: (e) => n.error(e),
75
+ complete: () => n.complete()
76
+ })), J = (e, t = []) => {
77
+ let n = E(j), r = (e) => !R(e.tags) && t.some((t) => _(e.tags, t)) || !n(e.type);
78
+ return (t) => new B((n) => t.subscribe({
79
+ next: (t) => {
80
+ n.next(e() ? t.filter(r) : t);
81
+ },
82
+ error: (e) => n.error(e),
83
+ complete: () => n.complete()
84
+ })).pipe(k);
85
+ }, Y = 2048;
86
+ function Ce(t, { getReadonly: n = () => !1, getHistory: r, manualStreamFlush: a = !1, observable: o = !0 } = {}) {
87
+ let c = /* @__PURE__ */ new Set(), l = ce(t, o), d = ae(l), f = {
88
+ notify: (e) => l.dispatch(u(e)),
89
+ dispatch: l.dispatchSync,
90
+ getNextVersion: () => t.clock.getNextVersion()
91
+ }, p = r?.(f) ?? G(f);
92
+ p.setLimit(Y);
93
+ let m = () => i(l.state), h = new V(), _ = h.pipe(Se(m)), v = new V(), y = new V(), b = new V(), x = y.pipe(ge(void 0), U(() => v.pipe(oe(s, [
94
+ ["@@move", ne],
95
+ ["@@scroll", e],
96
+ ["@@color", g]
97
+ ], a ? K(b) : void 0)))), S = new B((e) => l.subscribe((t) => e.next(t))).pipe(A(ue), q(n, [F.shared]), pe(200)), C = (...e) => {
98
+ let n = t.clock.getNextVersion();
99
+ return te(l.state, l.context, e).map((e) => (R(e.version) && (e.version = n), e));
100
+ }, w = (...e) => {
101
+ let t = C(e);
102
+ h.next(t);
103
+ }, T = (...e) => {
104
+ queueMicrotask(() => w(e));
105
+ }, E = () => {
106
+ Array.from(c).forEach((e) => fe(e) ? e() : e.unsubscribe()), c.clear(), l.destroy(), d.destroy(), p.clear(), h.complete(), b.complete();
107
+ }, D = () => {
108
+ y.next(), p.clear();
109
+ }, k = () => {
110
+ n() || m() || p.undo();
111
+ }, j = () => {
112
+ n() || m() || p.redo();
113
+ }, M = () => {
114
+ a && b.next();
115
+ };
116
+ return c.add(x.subscribe(re(l, p))).add(_.pipe(A(ee), O([F.changeOnly, F.shared]), q(n), J(m)).subscribe(v)).add(_.pipe(q(n, [F.shared]), J(m, [F.shared])).subscribe(l.dispatchSync)).add(l.subscribe((e) => {
117
+ e.forEach((e) => t.clock.merge(e.version));
118
+ })), Object.freeze({
119
+ ...l,
120
+ dispatch: T,
121
+ dispatchSync: w,
122
+ destroy: E,
123
+ undo: k,
124
+ redo: j,
125
+ history: p,
126
+ resetHistory: D,
127
+ change$: S,
128
+ flushStreamBuffers: M
129
+ });
130
+ }
131
+ //#endregion
132
+ //#region src/utils/focus.ts
133
+ function we(e, t, n, r = null) {
134
+ if (!e || n !== e.tableId) return !1;
135
+ switch (t) {
136
+ case "tableName":
137
+ case "tableComment": return t === e.focusType;
138
+ }
139
+ return r === e.columnId && t === e.focusType;
140
+ }
141
+ var Te = (e, t, n) => e?.tableId === t && e.selectColumnIds.includes(n);
142
+ function Ee(e, t, n, r = null) {
143
+ if (e?.tableId !== n) return !1;
144
+ switch (t) {
145
+ case T.tableName:
146
+ case T.tableComment: return t === e.focusType && e.edit;
147
+ }
148
+ return r === e.columnId && t === e.focusType && e.edit;
149
+ }
150
+ function De(e) {
151
+ let t = e.value.length;
152
+ e.selectionStart = t, e.selectionEnd = t, e.focus();
153
+ }
154
+ var Oe = (e) => e ? {
155
+ tableId: e.tableId,
156
+ columnId: e.columnId,
157
+ focusType: e.focusType
158
+ } : null, ke = (e) => e ? JSON.stringify([
159
+ e.tableId,
160
+ e.columnId,
161
+ e.focusType
162
+ ]) : "", X = "`";
163
+ function Z(e) {
164
+ return `'${e.replace(/[\\']/g, "\\$&")}'`;
165
+ }
166
+ var Ae = "NOT ENFORCED RELY", je = N(P.Databricks);
167
+ function Me(e) {
168
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
169
+ return c.forEach((t) => {
170
+ Ne(e, {
171
+ table: t,
172
+ buffer: s
173
+ }), s.push(""), Q(e, {
174
+ table: t,
175
+ buffer: s
176
+ });
177
+ }), l.forEach((t) => {
178
+ Fe(e, {
179
+ relationship: t,
180
+ buffer: s,
181
+ fkNames: a
182
+ }), s.push("");
183
+ }), u.forEach((t) => {
184
+ Ie(e, {
185
+ index: t,
186
+ buffer: s,
187
+ indexNames: o
188
+ }), s.push("");
189
+ }), s.join("\n");
190
+ }
191
+ function Ne(e, { buffer: t, table: r }) {
192
+ let { collections: i } = e, a = p(i).collection("tableColumnEntities").selectByIds(r.columnIds);
193
+ t.push(`CREATE TABLE ${X}${r.name}${X}`), t.push("(");
194
+ let s = I(a), c = w(a);
195
+ if (a.forEach((n, r) => {
196
+ Pe(e, {
197
+ column: n,
198
+ isComma: s || a.length !== r + 1,
199
+ spaceSize: c,
200
+ buffer: t
201
+ });
202
+ }), s) {
203
+ let e = n(a);
204
+ t.push(` CONSTRAINT ${X}PK_${r.name}${X} PRIMARY KEY (${o(e, X)}) ${Ae}`);
205
+ }
206
+ t.push(")"), r.comment.trim() === "" ? t.push("USING DELTA;") : (t.push("USING DELTA"), t.push(`COMMENT ${Z(r.comment)};`));
207
+ }
208
+ function Q({ collections: e }, { buffer: t, table: n }) {
209
+ let r = p(e).collection("tableColumnEntities").selectByIds(n.columnIds);
210
+ f(r).forEach((e) => {
211
+ t.push(`-- Databricks does not support UNIQUE constraints: ${X}${n.name}${X}.${X}${e.name}${X}`), t.push("");
212
+ });
213
+ }
214
+ function Pe(e, { buffer: t, column: n, isComma: r, spaceSize: i }) {
215
+ let a = [];
216
+ a.push(` ${X}${n.name}${X}` + l(i.name - n.name.length)), a.push(`${n.dataType}` + l(i.dataType - n.dataType.length));
217
+ let o = _(n.options, C.notNull) || _(n.options, C.primaryKey);
218
+ a.push(o ? "NOT NULL" : " "), _(n.options, C.autoIncrement) ? a.push("GENERATED ALWAYS AS IDENTITY") : n.default.trim() !== "" && a.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && a.push(`COMMENT ${Z(n.comment)}`), t.push(a.join(" ").trimEnd() + `${r ? "," : ""}`);
219
+ }
220
+ function Fe({ collections: e }, { buffer: t, relationship: n, fkNames: r }) {
221
+ let i = p(e).collection("tableEntities"), a = p(e).collection("tableColumnEntities"), s = i.selectById(n.start.tableId), c = i.selectById(n.end.tableId);
222
+ if (s && c) {
223
+ t.push(`ALTER TABLE ${X}${c.name}${X}`);
224
+ let e = `FK_${s.name}_TO_${c.name}`;
225
+ e = x(r, "", e), r.push({
226
+ id: z(),
227
+ name: e
228
+ }), t.push(` ADD CONSTRAINT ${X}${e}${X}`);
229
+ let i = {
230
+ start: [],
231
+ end: []
232
+ };
233
+ n.end.columnIds.forEach((e) => {
234
+ let t = a.selectById(e);
235
+ t && i.end.push(t);
236
+ }), n.start.columnIds.forEach((e) => {
237
+ let t = a.selectById(e);
238
+ t && i.start.push(t);
239
+ }), t.push(` FOREIGN KEY (${o(i.end, X)})`), t.push([
240
+ ` REFERENCES ${X}${s.name}${X} (${o(i.start, X)})`,
241
+ ...L(n, je),
242
+ `${Ae};`
243
+ ].join(" "));
244
+ }
245
+ }
246
+ function Ie({ collections: e }, { buffer: t, index: n, indexNames: r }) {
247
+ let i = p(e).collection("tableEntities").selectById(n.tableId);
248
+ if (!i) return;
249
+ let a = p(e).collection("indexColumnEntities").selectByIds(n.indexColumnIds).map((t) => {
250
+ let n = p(e).collection("tableColumnEntities").selectById(t.columnId);
251
+ return n ? { name: `${X}${n.name}${X} ${m(t.orderType)}` } : null;
252
+ }).filter((e) => e !== null);
253
+ if (a.length === 0) return;
254
+ let s = n.name;
255
+ n.name.trim() === "" && (s = `IDX_${i.name}`, s = x(r, "", s), r.push({
256
+ id: z(),
257
+ name: s
258
+ })), t.push(`-- Databricks has no secondary indexes. ${X}${s}${X} on ${X}${i.name}${X} (${o(a)})`), t.push(`-- ALTER TABLE ${X}${i.name}${X} CLUSTER BY (${o(p(e).collection("indexColumnEntities").selectByIds(n.indexColumnIds).map((t) => p(e).collection("tableColumnEntities").selectById(t.columnId)).filter((e) => e !== void 0), X)});`);
259
+ }
260
+ //#endregion
261
+ //#region src/utils/schema-sql/MariaDB.ts
262
+ var Le = N(P.MariaDB);
263
+ function Re(e) {
264
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
265
+ return c.forEach((t) => {
266
+ ze(e, {
267
+ table: t,
268
+ buffer: s
269
+ }), s.push(""), Be(e, {
270
+ table: t,
271
+ buffer: s
272
+ });
273
+ }), l.forEach((t) => {
274
+ He(e, {
275
+ relationship: t,
276
+ buffer: s,
277
+ fkNames: a
278
+ }), s.push("");
279
+ }), u.forEach((t) => {
280
+ Ue(e, {
281
+ index: t,
282
+ buffer: s,
283
+ indexNames: o
284
+ }), s.push("");
285
+ }), s.join("\n");
286
+ }
287
+ function ze(e, { buffer: t, table: r }) {
288
+ let { settings: { bracketType: i }, collections: a } = e, s = c(i), l = p(a).collection("tableColumnEntities").selectByIds(r.columnIds);
289
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
290
+ let u = I(l), d = w(l);
291
+ if (l.forEach((n, r) => {
292
+ u ? Ve(e, {
293
+ column: n,
294
+ isComma: !0,
295
+ spaceSize: d,
296
+ buffer: t
297
+ }) : Ve(e, {
298
+ column: n,
299
+ isComma: l.length !== r + 1,
300
+ spaceSize: d,
301
+ buffer: t
302
+ });
303
+ }), u) {
304
+ let e = n(l);
305
+ t.push(` PRIMARY KEY (${o(e, s)})`);
306
+ }
307
+ r.comment.trim() === "" ? t.push(");") : t.push(`) COMMENT ${h(r.comment)};`);
308
+ }
309
+ function Be({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
310
+ let i = c(e), a = p(t).collection("tableColumnEntities").selectByIds(r.columnIds);
311
+ y(a) && f(a).forEach((e) => {
312
+ n.push(`ALTER TABLE ${i}${r.name}${i}`), n.push(` ADD CONSTRAINT ${i}UQ_${r.name}_${e.name}${i} UNIQUE (${i}${e.name}${i});`), n.push("");
313
+ });
314
+ }
315
+ function Ve({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
316
+ let a = c(e), o = [];
317
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), o.push(`${_(n.options, C.notNull) ? "NOT NULL" : "NULL "}`), _(n.options, C.autoIncrement) ? o.push("AUTO_INCREMENT") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && o.push(`COMMENT ${h(n.comment)}`), t.push(o.join(" ") + `${r ? "," : ""}`);
318
+ }
319
+ function He({ settings: { bracketType: e }, collections: t }, { buffer: n, relationship: r, fkNames: i }) {
320
+ let a = c(e), s = p(t).collection("tableEntities"), l = p(t).collection("tableColumnEntities"), u = s.selectById(r.start.tableId), d = s.selectById(r.end.tableId);
321
+ if (u && d) {
322
+ n.push(`ALTER TABLE ${a}${d.name}${a}`);
323
+ let e = `FK_${u.name}_TO_${d.name}`;
324
+ e = x(i, "", e), i.push({
325
+ id: z(),
326
+ name: e
327
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
328
+ let t = {
329
+ start: [],
330
+ end: []
331
+ };
332
+ r.end.columnIds.forEach((e) => {
333
+ let n = l.selectById(e);
334
+ n && t.end.push(n);
335
+ }), r.start.columnIds.forEach((e) => {
336
+ let n = l.selectById(e);
337
+ n && t.start.push(n);
338
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${u.name}${a} (${o(t.start, a)})`, ...L(r, Le).map((e) => ` ${e}`)), n[n.length - 1] += ";";
339
+ }
340
+ }
341
+ function Ue({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
342
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
343
+ if (!s) return;
344
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
345
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
346
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
347
+ }).filter((e) => e !== null);
348
+ if (l.length !== 0) {
349
+ let e = r.name;
350
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
351
+ id: z(),
352
+ name: e
353
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)});`);
354
+ }
355
+ }
356
+ //#endregion
357
+ //#region src/utils/schema-sql/MSSQL.ts
358
+ var We = N(P.MSSQL);
359
+ function Ge(e) {
360
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
361
+ return c.forEach((t) => {
362
+ Ke(e, {
363
+ table: t,
364
+ buffer: s
365
+ }), s.push(""), qe(e, {
366
+ table: t,
367
+ buffer: s
368
+ }), Ye(e, {
369
+ table: t,
370
+ buffer: s
371
+ });
372
+ }), l.forEach((t) => {
373
+ Xe(e, {
374
+ relationship: t,
375
+ buffer: s,
376
+ fkNames: a
377
+ }), s.push("");
378
+ }), u.forEach((t) => {
379
+ Ze(e, {
380
+ index: t,
381
+ buffer: s,
382
+ indexNames: o
383
+ }), s.push("");
384
+ }), s.join("\n");
385
+ }
386
+ function Ke(e, { buffer: t, table: r }) {
387
+ let { settings: { bracketType: i }, collections: a } = e, s = c(i), l = p(a).collection("tableColumnEntities").selectByIds(r.columnIds);
388
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
389
+ let u = I(l), d = w(l);
390
+ if (l.forEach((n, r) => {
391
+ u ? Je(e, {
392
+ column: n,
393
+ isComma: !0,
394
+ spaceSize: d,
395
+ buffer: t
396
+ }) : Je(e, {
397
+ column: n,
398
+ isComma: l.length !== r + 1,
399
+ spaceSize: d,
400
+ buffer: t
401
+ });
402
+ }), u) {
403
+ let e = n(l);
404
+ t.push(` CONSTRAINT ${s}PK_${r.name}${s} PRIMARY KEY (${o(e, s)})`);
405
+ }
406
+ t.push(")\nGO");
407
+ }
408
+ function qe({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
409
+ let i = c(e), a = p(t).collection("tableColumnEntities").selectByIds(r.columnIds);
410
+ y(a) && f(a).forEach((e) => {
411
+ n.push(`ALTER TABLE ${i}${r.name}${i}`), n.push(` ADD CONSTRAINT ${i}UQ_${r.name}_${e.name}${i} UNIQUE (${i}${e.name}${i})\nGO`), n.push("");
412
+ });
413
+ }
414
+ function Je({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
415
+ let a = c(e), o = [];
416
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), _(n.options, C.notNull) && o.push("NOT NULL"), _(n.options, C.autoIncrement) ? o.push("IDENTITY(1,1)") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), t.push(o.join(" ") + `${r ? "," : ""}`);
417
+ }
418
+ function Ye({ collections: e }, { table: t, buffer: n }) {
419
+ let r = h(t.name);
420
+ t.comment.trim() !== "" && (n.push("EXECUTE sys.sp_addextendedproperty 'MS_Description',"), n.push(` ${h(t.comment)}, 'user', dbo, 'table', ${r}\nGO`), n.push("")), p(e).collection("tableColumnEntities").selectByIds(t.columnIds).forEach((e) => {
421
+ e.comment.trim() !== "" && (n.push("EXECUTE sys.sp_addextendedproperty 'MS_Description',"), n.push(` ${h(e.comment)}, 'user', dbo, 'table', ${r}, 'column', ${h(e.name)}\nGO`), n.push(""));
422
+ });
423
+ }
424
+ function Xe({ settings: { bracketType: e }, collections: t }, { buffer: n, relationship: r, fkNames: i }) {
425
+ let a = c(e), s = p(t).collection("tableEntities"), l = p(t).collection("tableColumnEntities"), u = s.selectById(r.start.tableId), d = s.selectById(r.end.tableId);
426
+ if (u && d) {
427
+ n.push(`ALTER TABLE ${a}${d.name}${a}`);
428
+ let e = `FK_${u.name}_TO_${d.name}`;
429
+ e = x(i, "", e), i.push({
430
+ id: z(),
431
+ name: e
432
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
433
+ let t = {
434
+ start: [],
435
+ end: []
436
+ };
437
+ r.end.columnIds.forEach((e) => {
438
+ let n = l.selectById(e);
439
+ n && t.end.push(n);
440
+ }), r.start.columnIds.forEach((e) => {
441
+ let n = l.selectById(e);
442
+ n && t.start.push(n);
443
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${u.name}${a} (${o(t.start, a)})`, ...L(r, We).map((e) => ` ${e}`)), n[n.length - 1] += "\nGO";
444
+ }
445
+ }
446
+ function Ze({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
447
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
448
+ if (!s) return;
449
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
450
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
451
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
452
+ }).filter((e) => e !== null);
453
+ if (l.length !== 0) {
454
+ let e = r.name;
455
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
456
+ id: z(),
457
+ name: e
458
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)})\nGO`);
459
+ }
460
+ }
461
+ //#endregion
462
+ //#region src/utils/schema-sql/MySQL.ts
463
+ var Qe = N(P.MySQL);
464
+ function $e(e) {
465
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
466
+ return c.forEach((t) => {
467
+ et(e, {
468
+ table: t,
469
+ buffer: s
470
+ }), s.push(""), tt(e, {
471
+ table: t,
472
+ buffer: s
473
+ });
474
+ }), l.forEach((t) => {
475
+ rt(e, {
476
+ relationship: t,
477
+ buffer: s,
478
+ fkNames: a
479
+ }), s.push("");
480
+ }), u.forEach((t) => {
481
+ it(e, {
482
+ index: t,
483
+ buffer: s,
484
+ indexNames: o
485
+ }), s.push("");
486
+ }), s.join("\n");
487
+ }
488
+ function et(e, { buffer: t, table: r }) {
489
+ let { settings: { bracketType: i }, collections: a } = e, s = c(i), l = p(a).collection("tableColumnEntities").selectByIds(r.columnIds);
490
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
491
+ let u = I(l), d = w(l);
492
+ if (l.forEach((n, r) => {
493
+ u ? nt(e, {
494
+ column: n,
495
+ isComma: !0,
496
+ spaceSize: d,
497
+ buffer: t
498
+ }) : nt(e, {
499
+ column: n,
500
+ isComma: l.length !== r + 1,
501
+ spaceSize: d,
502
+ buffer: t
503
+ });
504
+ }), u) {
505
+ let e = n(l);
506
+ t.push(` PRIMARY KEY (${o(e, s)})`);
507
+ }
508
+ r.comment.trim() === "" ? t.push(");") : t.push(`) COMMENT ${h(r.comment)};`);
509
+ }
510
+ function tt({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
511
+ let i = c(e), a = p(t).collection("tableColumnEntities").selectByIds(r.columnIds);
512
+ y(a) && f(a).forEach((e) => {
513
+ n.push(`ALTER TABLE ${i}${r.name}${i}`), n.push(` ADD CONSTRAINT ${i}UQ_${r.name}_${e.name}${i} UNIQUE (${i}${e.name}${i});`), n.push("");
514
+ });
515
+ }
516
+ function nt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
517
+ let a = c(e), o = [];
518
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), o.push(`${_(n.options, C.notNull) ? "NOT NULL" : "NULL "}`), _(n.options, C.autoIncrement) ? o.push("AUTO_INCREMENT") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && o.push(`COMMENT ${h(n.comment)}`), t.push(o.join(" ") + `${r ? "," : ""}`);
519
+ }
520
+ function rt({ settings: { bracketType: e }, collections: t }, { buffer: n, relationship: r, fkNames: i }) {
521
+ let a = c(e), s = p(t).collection("tableEntities"), l = p(t).collection("tableColumnEntities"), u = s.selectById(r.start.tableId), d = s.selectById(r.end.tableId);
522
+ if (u && d) {
523
+ n.push(`ALTER TABLE ${a}${d.name}${a}`);
524
+ let e = `FK_${u.name}_TO_${d.name}`;
525
+ e = x(i, "", e), i.push({
526
+ id: z(),
527
+ name: e
528
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
529
+ let t = {
530
+ start: [],
531
+ end: []
532
+ };
533
+ r.end.columnIds.forEach((e) => {
534
+ let n = l.selectById(e);
535
+ n && t.end.push(n);
536
+ }), r.start.columnIds.forEach((e) => {
537
+ let n = l.selectById(e);
538
+ n && t.start.push(n);
539
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${u.name}${a} (${o(t.start, a)})`, ...L(r, Qe).map((e) => ` ${e}`)), n[n.length - 1] += ";";
540
+ }
541
+ }
542
+ function it({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
543
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
544
+ if (!s) return;
545
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
546
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
547
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
548
+ }).filter((e) => e !== null);
549
+ if (l.length !== 0) {
550
+ let e = r.name;
551
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
552
+ id: z(),
553
+ name: e
554
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)});`);
555
+ }
556
+ }
557
+ //#endregion
558
+ //#region src/utils/schema-sql/Oracle.ts
559
+ var at = N(P.Oracle);
560
+ function ot(e) {
561
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [], c = [], l = [""], u = p(i).collection("tableEntities").selectByIds(t).sort(v), d = p(i).collection("relationshipEntities").selectByIds(n), f = p(i).collection("indexEntities").selectByIds(r);
562
+ return u.forEach((t) => {
563
+ st(e, {
564
+ table: t,
565
+ buffer: l
566
+ }), l.push(""), ct(e, {
567
+ table: t,
568
+ buffer: l
569
+ }), p(i).collection("tableColumnEntities").selectByIds(t.columnIds).forEach((e) => {
570
+ if (_(e.options, C.autoIncrement)) {
571
+ let n = `SEQ_${t.name}`;
572
+ n = x(o, "", n), o.push({
573
+ id: z(),
574
+ name: n
575
+ }), l.push(`CREATE SEQUENCE ${n}`), l.push("START WITH 1"), l.push("INCREMENT BY 1;"), l.push("");
576
+ let r = `SEQ_TRG_${t.name}`;
577
+ r = x(o, "", r), s.push({
578
+ id: z(),
579
+ name: r
580
+ }), l.push(`CREATE OR REPLACE TRIGGER ${r}`), l.push(`BEFORE INSERT ON ${t.name}`), l.push("REFERENCING NEW AS NEW FOR EACH ROW"), l.push("BEGIN"), l.push(` SELECT ${n}.NEXTVAL`), l.push(` INTO: NEW.${e.name}`), l.push(" FROM DUAL;"), l.push("END;"), l.push("");
581
+ }
582
+ }), ut(e, {
583
+ table: t,
584
+ buffer: l
585
+ });
586
+ }), d.forEach((t) => {
587
+ dt(e, {
588
+ relationship: t,
589
+ buffer: l,
590
+ fkNames: a
591
+ }), l.push("");
592
+ }), f.forEach((t) => {
593
+ ft(e, {
594
+ index: t,
595
+ buffer: l,
596
+ indexNames: c
597
+ }), l.push("");
598
+ }), l.join("\n");
599
+ }
600
+ function st(e, { buffer: t, table: r }) {
601
+ let { settings: { bracketType: i }, collections: a } = e, s = c(i), l = p(a).collection("tableColumnEntities").selectByIds(r.columnIds);
602
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
603
+ let u = I(l), d = w(l);
604
+ if (l.forEach((n, r) => {
605
+ u ? lt(e, {
606
+ column: n,
607
+ isComma: !0,
608
+ spaceSize: d,
609
+ buffer: t
610
+ }) : lt(e, {
611
+ column: n,
612
+ isComma: l.length !== r + 1,
613
+ spaceSize: d,
614
+ buffer: t
615
+ });
616
+ }), u) {
617
+ let e = n(l);
618
+ t.push(` CONSTRAINT ${s}PK_${r.name}${s} PRIMARY KEY (${o(e, s)})`);
619
+ }
620
+ t.push(");");
621
+ }
622
+ function ct({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
623
+ let i = c(e), a = p(t).collection("tableColumnEntities").selectByIds(r.columnIds);
624
+ y(a) && f(a).forEach((e) => {
625
+ n.push(`ALTER TABLE ${i}${r.name}${i}`), n.push(` ADD CONSTRAINT ${i}UQ_${r.name}_${e.name}${i} UNIQUE (${i}${e.name}${i});`), n.push("");
626
+ });
627
+ }
628
+ function lt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
629
+ let a = c(e), o = [];
630
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), _(n.options, C.notNull) && o.push("NOT NULL"), t.push(o.join(" ") + `${r ? "," : ""}`);
631
+ }
632
+ function ut({ settings: { bracketType: e }, collections: t }, { table: n, buffer: r }) {
633
+ let i = c(e);
634
+ n.comment.trim() !== "" && (r.push(`COMMENT ON TABLE ${i}${n.name}${i} IS ${h(n.comment)};`), r.push("")), p(t).collection("tableColumnEntities").selectByIds(n.columnIds).forEach((e) => {
635
+ e.comment.trim() !== "" && (r.push(`COMMENT ON COLUMN ${i}${n.name}${i}.${i}${e.name}${i} IS ${h(e.comment)};`), r.push(""));
636
+ });
637
+ }
638
+ function dt({ settings: { bracketType: e }, collections: t }, { buffer: n, relationship: r, fkNames: i }) {
639
+ let a = c(e), s = p(t).collection("tableEntities"), l = p(t).collection("tableColumnEntities"), u = s.selectById(r.start.tableId), d = s.selectById(r.end.tableId);
640
+ if (u && d) {
641
+ n.push(`ALTER TABLE ${a}${d.name}${a}`);
642
+ let e = `FK_${u.name}_TO_${d.name}`;
643
+ e = x(i, "", e), i.push({
644
+ id: z(),
645
+ name: e
646
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
647
+ let t = {
648
+ start: [],
649
+ end: []
650
+ };
651
+ r.end.columnIds.forEach((e) => {
652
+ let n = l.selectById(e);
653
+ n && t.end.push(n);
654
+ }), r.start.columnIds.forEach((e) => {
655
+ let n = l.selectById(e);
656
+ n && t.start.push(n);
657
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${u.name}${a} (${o(t.start, a)})`, ...L(r, at).map((e) => ` ${e}`)), n[n.length - 1] += ";";
658
+ }
659
+ }
660
+ function ft({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
661
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
662
+ if (!s) return;
663
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
664
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
665
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
666
+ }).filter((e) => e !== null);
667
+ if (l.length !== 0) {
668
+ let e = r.name;
669
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
670
+ id: z(),
671
+ name: e
672
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)});`);
673
+ }
674
+ }
675
+ //#endregion
676
+ //#region src/utils/schema-sql/PostgreSQL.ts
677
+ var pt = N(P.PostgreSQL);
678
+ function mt(e) {
679
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
680
+ return c.forEach((t) => {
681
+ ht(e, {
682
+ table: t,
683
+ buffer: s
684
+ }), s.push(""), _t(e, {
685
+ table: t,
686
+ buffer: s
687
+ });
688
+ }), l.forEach((t) => {
689
+ vt(e, {
690
+ relationship: t,
691
+ buffer: s,
692
+ fkNames: a
693
+ }), s.push("");
694
+ }), u.forEach((t) => {
695
+ yt(e, {
696
+ index: t,
697
+ buffer: s,
698
+ indexNames: o
699
+ }), s.push("");
700
+ }), s.join("\n");
701
+ }
702
+ function ht(e, { buffer: t, table: r }) {
703
+ let { settings: { bracketType: i }, collections: a } = e, s = c(i), l = p(a).collection("tableColumnEntities").selectByIds(r.columnIds);
704
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
705
+ let u = I(l), d = w(l);
706
+ if (l.forEach((n, r) => {
707
+ u ? gt(e, {
708
+ column: n,
709
+ isComma: !0,
710
+ spaceSize: d,
711
+ buffer: t
712
+ }) : gt(e, {
713
+ column: n,
714
+ isComma: l.length !== r + 1,
715
+ spaceSize: d,
716
+ buffer: t
717
+ });
718
+ }), u) {
719
+ let e = n(l);
720
+ t.push(` PRIMARY KEY (${o(e, s)})`);
721
+ }
722
+ t.push(");");
723
+ }
724
+ function gt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
725
+ let a = c(e), o = [];
726
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), _(n.options, C.notNull) && o.push("NOT NULL"), _(n.options, C.autoIncrement) ? o.push("GENERATED ALWAYS AS IDENTITY") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), _(n.options, C.unique) && o.push("UNIQUE"), t.push(o.join(" ") + `${r ? "," : ""}`);
727
+ }
728
+ function _t({ settings: { bracketType: e }, collections: t }, { buffer: n, table: r }) {
729
+ let i = c(e);
730
+ r.comment.trim() !== "" && (n.push(`COMMENT ON TABLE ${i}${r.name}${i} IS ${h(r.comment)};`), n.push("")), p(t).collection("tableColumnEntities").selectByIds(r.columnIds).forEach((e) => {
731
+ e.comment.trim() !== "" && (n.push(`COMMENT ON COLUMN ${i}${r.name}${i}.${i}${e.name}${i} IS ${h(e.comment)};`), n.push(""));
732
+ });
733
+ }
734
+ function vt({ settings: { bracketType: e }, collections: t }, { buffer: n, relationship: r, fkNames: i }) {
735
+ let a = c(e), s = p(t).collection("tableEntities"), l = p(t).collection("tableColumnEntities"), u = s.selectById(r.start.tableId), d = s.selectById(r.end.tableId);
736
+ if (u && d) {
737
+ n.push(`ALTER TABLE ${a}${d.name}${a}`);
738
+ let e = `FK_${u.name}_TO_${d.name}`;
739
+ e = x(i, "", e), i.push({
740
+ id: z(),
741
+ name: e
742
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
743
+ let t = {
744
+ start: [],
745
+ end: []
746
+ };
747
+ r.end.columnIds.forEach((e) => {
748
+ let n = l.selectById(e);
749
+ n && t.end.push(n);
750
+ }), r.start.columnIds.forEach((e) => {
751
+ let n = l.selectById(e);
752
+ n && t.start.push(n);
753
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${u.name}${a} (${o(t.start, a)})`, ...L(r, pt).map((e) => ` ${e}`)), n[n.length - 1] += ";";
754
+ }
755
+ }
756
+ function yt({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
757
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
758
+ if (!s) return;
759
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
760
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
761
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
762
+ }).filter((e) => e !== null);
763
+ if (l.length !== 0) {
764
+ let e = r.name;
765
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
766
+ id: z(),
767
+ name: e
768
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)});`);
769
+ }
770
+ }
771
+ //#endregion
772
+ //#region src/utils/schema-sql/Snowflake.ts
773
+ var bt = N(P.Snowflake), $ = (e) => c(e) === "" ? "" : "\"";
774
+ function xt(e) {
775
+ let { doc: { tableIds: t, relationshipIds: n, indexIds: r }, collections: i } = e, a = [], o = [], s = [""], c = p(i).collection("tableEntities").selectByIds(t).sort(v), l = p(i).collection("relationshipEntities").selectByIds(n), u = p(i).collection("indexEntities").selectByIds(r);
776
+ return c.forEach((t) => {
777
+ St(e, {
778
+ table: t,
779
+ buffer: s
780
+ }), s.push("");
781
+ }), l.forEach((t) => {
782
+ wt(e, {
783
+ relationship: t,
784
+ buffer: s,
785
+ fkNames: a
786
+ }), s.push("");
787
+ }), u.forEach((t) => {
788
+ Tt(e, {
789
+ index: t,
790
+ buffer: s,
791
+ indexNames: o
792
+ }), s.push("");
793
+ }), s.join("\n");
794
+ }
795
+ function St(e, { buffer: t, table: r }) {
796
+ let { collections: i, settings: { bracketType: a } } = e, s = $(a), c = p(i).collection("tableColumnEntities").selectByIds(r.columnIds);
797
+ t.push(`CREATE TABLE ${s}${r.name}${s}`), t.push("(");
798
+ let l = I(c), u = w(c);
799
+ if (c.forEach((n, r) => {
800
+ Ct(e, {
801
+ column: n,
802
+ isComma: l || c.length !== r + 1,
803
+ spaceSize: u,
804
+ buffer: t
805
+ });
806
+ }), l) {
807
+ let e = n(c);
808
+ t.push(` CONSTRAINT ${s}PK_${r.name}${s} PRIMARY KEY (${o(e, s)})`);
809
+ }
810
+ r.comment.trim() === "" ? t.push(");") : (t.push(")"), t.push(`COMMENT = ${h(r.comment)};`));
811
+ }
812
+ function Ct({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
813
+ let a = $(e), o = [];
814
+ o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), _(n.options, C.unique) && o.push("UNIQUE");
815
+ let s = _(n.options, C.notNull) || _(n.options, C.primaryKey);
816
+ o.push(s ? "NOT NULL" : " "), _(n.options, C.autoIncrement) ? o.push("AUTOINCREMENT") : n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), n.comment.trim() !== "" && o.push(`COMMENT ${h(n.comment)}`), t.push(o.join(" ").trimEnd() + `${r ? "," : ""}`);
817
+ }
818
+ function wt({ collections: e, settings: { bracketType: t } }, { buffer: n, relationship: r, fkNames: i }) {
819
+ let a = $(t), s = p(e).collection("tableEntities"), c = p(e).collection("tableColumnEntities"), l = s.selectById(r.start.tableId), u = s.selectById(r.end.tableId);
820
+ if (l && u) {
821
+ n.push(`ALTER TABLE ${a}${u.name}${a}`);
822
+ let e = `FK_${l.name}_TO_${u.name}`;
823
+ e = x(i, "", e), i.push({
824
+ id: z(),
825
+ name: e
826
+ }), n.push(` ADD CONSTRAINT ${a}${e}${a}`);
827
+ let t = {
828
+ start: [],
829
+ end: []
830
+ };
831
+ r.end.columnIds.forEach((e) => {
832
+ let n = c.selectById(e);
833
+ n && t.end.push(n);
834
+ }), r.start.columnIds.forEach((e) => {
835
+ let n = c.selectById(e);
836
+ n && t.start.push(n);
837
+ }), n.push(` FOREIGN KEY (${o(t.end, a)})`), n.push(` REFERENCES ${a}${l.name}${a} (${o(t.start, a)})`, ...L(r, bt).map((e) => ` ${e}`)), n[n.length - 1] += ";";
838
+ }
839
+ }
840
+ function Tt({ collections: e, settings: { bracketType: t } }, { buffer: n, index: r, indexNames: i }) {
841
+ let a = $(t), s = p(e).collection("tableEntities").selectById(r.tableId);
842
+ if (!s) return;
843
+ let c = p(e).collection("indexColumnEntities").selectByIds(r.indexColumnIds), l = c.map((t) => p(e).collection("tableColumnEntities").selectById(t.columnId)).filter((e) => e !== void 0);
844
+ if (l.length === 0) return;
845
+ let u = r.name;
846
+ if (r.name.trim() === "" && (u = `IDX_${s.name}`, u = x(i, "", u), i.push({
847
+ id: z(),
848
+ name: u
849
+ })), r.unique) {
850
+ n.push(`ALTER TABLE ${a}${s.name}${a}`), n.push(` ADD CONSTRAINT ${a}${u}${a} UNIQUE (${o(l, a)});`);
851
+ return;
852
+ }
853
+ let d = c.map((t) => {
854
+ let n = p(e).collection("tableColumnEntities").selectById(t.columnId);
855
+ return n ? { name: `${a}${n.name}${a} ${m(t.orderType)}` } : null;
856
+ }).filter((e) => e !== null);
857
+ n.push(`-- Snowflake has no secondary indexes. ${a}${u}${a} on ${a}${s.name}${a} (${o(d)})`), n.push(`-- ALTER TABLE ${a}${s.name}${a} CLUSTER BY (${o(l, a)});`);
858
+ }
859
+ //#endregion
860
+ //#region src/utils/schema-sql/SQLite.ts
861
+ var Et = N(P.SQLite);
862
+ function Dt(e) {
863
+ let { doc: { tableIds: t, indexIds: n }, collections: r } = e, i = [], a = [""], o = p(r).collection("tableEntities").selectByIds(t).sort(v), s = p(r).collection("indexEntities").selectByIds(n);
864
+ return o.forEach((t) => {
865
+ Ot(e, {
866
+ table: t,
867
+ buffer: a
868
+ }), a.push("");
869
+ }), s.forEach((t) => {
870
+ At(e, {
871
+ index: t,
872
+ buffer: a,
873
+ indexNames: i
874
+ }), a.push("");
875
+ }), a.join("\n");
876
+ }
877
+ function Ot(e, { buffer: t, table: r }) {
878
+ let { settings: { bracketType: i }, doc: { relationshipIds: a }, collections: s } = e, l = c(i), u = p(s).collection("tableEntities"), d = p(s).collection("tableColumnEntities"), f = d.selectByIds(r.columnIds), m = p(s).collection("relationshipEntities").selectByIds(a).filter(({ end: e }) => e.tableId === r.id);
879
+ r.comment.trim() !== "" && t.push(`-- ${r.comment}`), t.push(`CREATE TABLE ${l}${r.name}${l}`), t.push("(");
880
+ let h = I(f), g = w(f);
881
+ if (f.forEach((n, r) => {
882
+ h ? kt(e, {
883
+ column: n,
884
+ isComma: !0,
885
+ spaceSize: g,
886
+ buffer: t
887
+ }) : kt(e, {
888
+ column: n,
889
+ isComma: f.length !== r + 1,
890
+ spaceSize: g,
891
+ buffer: t
892
+ });
893
+ }), h) {
894
+ let e = n(f);
895
+ if (m.length !== 0) {
896
+ if (e.length === 1) {
897
+ let n = _(e[0].options, C.autoIncrement) ? " AUTOINCREMENT" : "";
898
+ t.push(` PRIMARY KEY (${o(e, l)}${n}),`);
899
+ } else t.push(` PRIMARY KEY (${o(e, l)}),`);
900
+ } else if (e.length === 1) {
901
+ let n = _(e[0].options, C.autoIncrement) ? " AUTOINCREMENT" : "";
902
+ t.push(` PRIMARY KEY (${o(e, l)}${n})`);
903
+ } else t.push(` PRIMARY KEY (${o(e, l)})`);
904
+ }
905
+ m.forEach((e, n) => {
906
+ let r = u.selectById(e.start.tableId), i = u.selectById(e.end.tableId);
907
+ if (r && i) {
908
+ let i = {
909
+ start: [],
910
+ end: []
911
+ };
912
+ e.end.columnIds.forEach((e) => {
913
+ let t = d.selectById(e);
914
+ t && i.end.push(t);
915
+ }), e.start.columnIds.forEach((e) => {
916
+ let t = d.selectById(e);
917
+ t && i.start.push(t);
918
+ });
919
+ let a = L(e, Et).map((e) => ` ${e}`).join("");
920
+ m.length - 1 > n ? t.push(` FOREIGN KEY (${o(i.end, l)}) REFERENCES ${l}${r.name}${l} (${o(i.start, l)})${a},`) : t.push(` FOREIGN KEY (${o(i.end, l)}) REFERENCES ${l}${r.name}${l} (${o(i.start, l)})${a}`);
921
+ }
922
+ }), t.push(");");
923
+ }
924
+ function kt({ settings: { bracketType: e } }, { buffer: t, column: n, isComma: r, spaceSize: i }) {
925
+ let a = c(e), o = [];
926
+ n.comment.trim() !== "" && t.push(` -- ${n.comment}`), o.push(` ${a}${n.name}${a}` + l(i.name - n.name.length)), o.push(`${n.dataType}` + l(i.dataType - n.dataType.length)), o.push(`${_(n.options, C.notNull) ? "NOT NULL" : "NULL "}`), _(n.options, C.unique) && o.push("UNIQUE"), !_(n.options, C.autoIncrement) && n.default.trim() !== "" && o.push(`DEFAULT ${n.default}`), t.push(o.join(" ") + `${r ? "," : ""}`);
927
+ }
928
+ function At({ settings: { bracketType: e }, collections: t }, { buffer: n, index: r, indexNames: i }) {
929
+ let a = c(e), s = p(t).collection("tableEntities").selectById(r.tableId);
930
+ if (!s) return;
931
+ let l = p(t).collection("indexColumnEntities").selectByIds(r.indexColumnIds).map((e) => {
932
+ let n = p(t).collection("tableColumnEntities").selectById(e.columnId);
933
+ return n ? { name: `${a}${n.name}${a} ${m(e.orderType)}` } : null;
934
+ }).filter((e) => e !== null);
935
+ if (l.length !== 0) {
936
+ let e = r.name;
937
+ r.name.trim() === "" && (e = `IDX_${s.name}`, e = x(i, "", e), i.push({
938
+ id: z(),
939
+ name: e
940
+ })), r.unique ? n.push(`CREATE UNIQUE INDEX ${a}${e}${a}`) : n.push(`CREATE INDEX ${a}${e}${a}`), n.push(` ON ${a}${s.name}${a} (${o(l)});`);
941
+ }
942
+ }
943
+ //#endregion
944
+ //#region src/utils/schema-sql/index.ts
945
+ function jt(e, t) {
946
+ switch (t || e.settings.database) {
947
+ case P.Databricks: return Me(e);
948
+ case P.MariaDB: return Re(e);
949
+ case P.MSSQL: return Ge(e);
950
+ case P.MySQL: return $e(e);
951
+ case P.Oracle: return ot(e);
952
+ case P.PostgreSQL: return mt(e);
953
+ case P.Snowflake: return xt(e);
954
+ case P.SQLite: return Dt(e);
955
+ }
956
+ return "";
957
+ }
958
+ function Mt(e, t) {
959
+ let { settings: n, doc: { indexIds: r }, collections: i } = e, a = [""], o = n.database, s = [], c = p(i).collection("indexEntities").selectByIds(r).filter((e) => e.tableId === t.id);
960
+ switch (o) {
961
+ case P.Databricks:
962
+ Ne(e, {
963
+ buffer: a,
964
+ table: t
965
+ }), a.push(""), Q(e, {
966
+ buffer: a,
967
+ table: t
968
+ }), c.forEach((t) => {
969
+ Ie(e, {
970
+ index: t,
971
+ buffer: a,
972
+ indexNames: s
973
+ }), a.push("");
974
+ });
975
+ break;
976
+ case P.MariaDB:
977
+ ze(e, {
978
+ buffer: a,
979
+ table: t
980
+ }), a.push(""), Be(e, {
981
+ buffer: a,
982
+ table: t
983
+ }), c.forEach((t) => {
984
+ Ue(e, {
985
+ index: t,
986
+ buffer: a,
987
+ indexNames: s
988
+ }), a.push("");
989
+ });
990
+ break;
991
+ case P.MSSQL:
992
+ Ke(e, {
993
+ buffer: a,
994
+ table: t
995
+ }), a.push(""), qe(e, {
996
+ buffer: a,
997
+ table: t
998
+ }), c.forEach((t) => {
999
+ Ze(e, {
1000
+ index: t,
1001
+ buffer: a,
1002
+ indexNames: s
1003
+ }), a.push("");
1004
+ });
1005
+ break;
1006
+ case P.MySQL:
1007
+ et(e, {
1008
+ buffer: a,
1009
+ table: t
1010
+ }), a.push(""), tt(e, {
1011
+ buffer: a,
1012
+ table: t
1013
+ }), c.forEach((t) => {
1014
+ it(e, {
1015
+ index: t,
1016
+ buffer: a,
1017
+ indexNames: s
1018
+ }), a.push("");
1019
+ });
1020
+ break;
1021
+ case P.Oracle:
1022
+ st(e, {
1023
+ buffer: a,
1024
+ table: t
1025
+ }), a.push(""), ct(e, {
1026
+ buffer: a,
1027
+ table: t
1028
+ }), c.forEach((t) => {
1029
+ ft(e, {
1030
+ index: t,
1031
+ buffer: a,
1032
+ indexNames: s
1033
+ }), a.push("");
1034
+ });
1035
+ break;
1036
+ case P.PostgreSQL:
1037
+ ht(e, {
1038
+ buffer: a,
1039
+ table: t
1040
+ }), a.push(""), c.forEach((t) => {
1041
+ yt(e, {
1042
+ index: t,
1043
+ buffer: a,
1044
+ indexNames: s
1045
+ }), a.push("");
1046
+ });
1047
+ break;
1048
+ case P.Snowflake:
1049
+ St(e, {
1050
+ buffer: a,
1051
+ table: t
1052
+ }), a.push(""), c.forEach((t) => {
1053
+ Tt(e, {
1054
+ index: t,
1055
+ buffer: a,
1056
+ indexNames: s
1057
+ }), a.push("");
1058
+ });
1059
+ break;
1060
+ case P.SQLite: Ot(e, {
1061
+ buffer: a,
1062
+ table: t
1063
+ }), a.push(""), c.forEach((t) => {
1064
+ At(e, {
1065
+ index: t,
1066
+ buffer: a,
1067
+ indexNames: s
1068
+ }), a.push("");
1069
+ });
1070
+ }
1071
+ return a.join("\n");
1072
+ }
1073
+ //#endregion
1074
+ //#region src/engine/shared-store.ts
1075
+ var Nt = 2, Pt = E(S);
1076
+ function Ft(e, n, r) {
1077
+ let i = r?.manualStreamFlush ?? !1, a = { editorId: e.state.editor.id }, o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = new V(), l = new V(), u = new V(), d = new V(), f = new V(), p = D(i ? K(f) : ve(f)), m = !0, h = !0;
1078
+ o.add(me(new B((t) => e.subscribe((e) => t.next(e))), l).pipe(A(le), O([F.shared]), p, ie(u, d), p, H((e) => M(F.shared, e.map((e) => {
1079
+ let r = {
1080
+ ...e,
1081
+ meta: Object.assign({}, e.meta ?? {}, {
1082
+ ...a,
1083
+ nickname: n?.getNickname?.()
1084
+ })
1085
+ };
1086
+ return Pt(e.type) ? t(F.following, r) : r;
1087
+ })))).subscribe((e) => c.next(e)));
1088
+ let g = () => {
1089
+ let e = 0 < s.size;
1090
+ m && e ? u.next() : d.next();
1091
+ }, _ = (t) => {
1092
+ let n = (Array.isArray(t) ? t : [t]).some((e) => e.type === b.type), r = e.state.lww;
1093
+ n && !de(r) && l.next([{
1094
+ ...se({ lww: r }),
1095
+ version: e.context.clock.getVersion()
1096
+ }]);
1097
+ };
1098
+ return Object.freeze({
1099
+ connection: () => {
1100
+ m = !0, g();
1101
+ },
1102
+ disconnect: () => {
1103
+ m = !1, g();
1104
+ },
1105
+ dispatch: (t) => {
1106
+ e.dispatch(t), _(t);
1107
+ },
1108
+ dispatchSync: (t) => {
1109
+ e.dispatchSync(t), _(t);
1110
+ },
1111
+ subscribe: (t) => {
1112
+ let n = c.subscribe((e) => t(e));
1113
+ return s.add(n), g(), h &&= (l.next([{
1114
+ ...b(),
1115
+ version: e.context.clock.getVersion()
1116
+ }]), !1), () => {
1117
+ n.unsubscribe(), s.delete(n), g();
1118
+ };
1119
+ },
1120
+ flushStreamBuffers: () => {
1121
+ for (let e = 0; e < Nt; e++) f.next();
1122
+ },
1123
+ destroy: () => {
1124
+ Array.from(o).forEach((e) => e.unsubscribe()), Array.from(s).forEach((e) => e.unsubscribe()), o.clear(), s.clear(), c.complete(), u.complete(), d.complete(), f.complete();
1125
+ }
1126
+ });
1127
+ }
1128
+ //#endregion
1129
+ export { we as a, Oe as c, Ce as d, G as f, Ee as i, ke as l, jt as n, Te as o, Mt as r, De as s, Ft as t, Y as u };