@dineug/erd-editor 3.9.1 → 3.9.2

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