@dineug/erd-editor 3.9.0 → 3.9.1

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