@aiao/rxdb-adapter-pglite 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { PropertyType as N, RxDBChange as ie, getEntityMetadata as D, EntityLocalCreatedEvent as oe, EntityLocalRemovedEvent as Ve, EntityLocalUpdatedEvent as me, RelationKind as B, RepositoryBase as Fn, getEntityStatus as J, RxDBBranch as ne, parseRxDBChangeKey as Ae, getEntityType as Re, RxDBAdapterLocalBase as Bn } from "@aiao/rxdb";
2
- import { EventDispatcher as kn, traverseObjectKeys as Wn, isFunction as It, isString as Gn, AsyncQueueExecutor as Hn } from "@aiao/utils";
3
- import { PGlite as Vn } from "@electric-sql/pglite";
4
- import { ReplaySubject as Kn, defer as be, of as Se, from as Ie, map as Jn } from "rxjs";
5
- const Yn = "pglite";
1
+ import { PropertyType as _, RxDBChange as le, getEntityMetadata as C, EntityLocalCreatedEvent as ue, EntityLocalRemovedEvent as Ke, EntityLocalUpdatedEvent as ge, RelationKind as B, RepositoryBase as Bn, getEntityStatus as J, RxDBBranch as re, parseRxDBChangeKey as Re, getEntityType as Se, RxDBAdapterLocalBase as kn } from "@aiao/rxdb";
2
+ import { EventDispatcher as Wn, traverseObjectKeys as Gn, isFunction as Ot, isString as Hn, AsyncQueueExecutor as Vn } from "@aiao/utils";
3
+ import { PGlite as Kn } from "@electric-sql/pglite";
4
+ import { ReplaySubject as Jn, defer as Ie, of as Oe, from as De, map as Yn } from "rxjs";
5
+ const Qn = "pglite";
6
6
  var K = /* @__PURE__ */ ((e) => (e.INSERT = "INSERT", e.UPDATE = "UPDATE", e.DELETE = "DELETE", e))(K || {});
7
7
  class x extends Error {
8
8
  /**
@@ -17,227 +17,244 @@ class x extends Error {
17
17
  super(t), this.name = "RxdbAdapterPGliteError", this.code = n, this.originalError = r, Object.setPrototypeOf(this, x.prototype);
18
18
  }
19
19
  }
20
- const Ot = (e, t = "public") => `"${t}"."${e}"`, P = (e) => Ot(e.tableName, e.namespace), vt = (e) => {
20
+ const Dt = (e, t = "public") => `"${t}"."${e}"`, P = (e) => Dt(e.tableName, e.namespace), Ct = (e) => {
21
21
  switch (e.type) {
22
- case N.uuid:
22
+ case _.uuid:
23
23
  return "uuid";
24
- case N.string:
25
- case N.enum:
24
+ case _.string:
25
+ case _.enum:
26
26
  return "varchar";
27
- case N.json:
27
+ case _.json:
28
+ case _.keyValue:
28
29
  return "jsonb";
29
- case N.number:
30
+ case _.number:
30
31
  return "numeric";
31
- case N.integer:
32
+ case _.integer:
32
33
  return "integer";
33
- case N.boolean:
34
+ case _.boolean:
34
35
  return "boolean";
35
- case N.date:
36
+ case _.date:
36
37
  return "timestamptz";
38
+ case _.stringArray:
39
+ return "text[]";
40
+ case _.numberArray:
41
+ return "numeric[]";
37
42
  }
38
43
  throw new x("rxDBColumnTypeToPGliteType: type '" + e.type + "' not support");
39
- }, Qn = (e) => {
44
+ }, Xn = (e) => {
40
45
  switch (e.type) {
41
- case N.uuid:
46
+ case _.uuid:
42
47
  return "uuid_ops";
43
- case N.string:
44
- case N.enum:
48
+ case _.string:
49
+ case _.enum:
45
50
  return "bpchar_ops";
46
- case N.json:
51
+ case _.json:
47
52
  return "jsonb_ops";
48
- case N.number:
53
+ case _.number:
49
54
  return "numeric_ops";
50
- case N.integer:
55
+ case _.integer:
51
56
  return "int4_ops";
52
57
  default:
53
58
  throw new x(`rxDBColumnTypeToPGliteTypeIndexName: type '${e.type}' not support`);
54
59
  }
55
- }, Dt = (e, t) => `idx_${e.namespace}_${e.tableName}_${t.name}`, tt = (e, t) => {
60
+ }, Lt = (e, t) => `idx_${e.namespace}_${e.tableName}_${t.name}`, nt = (e, t) => {
56
61
  if (e == null)
57
62
  return null;
58
63
  switch (t.type) {
59
- case N.json:
60
- case N.keyValue:
61
- case N.stringArray:
62
- case N.numberArray:
64
+ case _.json:
65
+ case _.keyValue:
63
66
  return JSON.stringify(e);
64
- case N.date:
67
+ case _.stringArray:
68
+ return Array.isArray(e) ? e : JSON.parse(String(e));
69
+ case _.numberArray:
70
+ return (Array.isArray(e) ? e : JSON.parse(String(e))).map(Number);
71
+ case _.date:
65
72
  return e instanceof Date ? e.toISOString() : e;
66
- case N.boolean:
73
+ case _.boolean:
67
74
  return !!e;
68
- case N.number:
69
- case N.integer:
75
+ case _.number:
76
+ case _.integer:
70
77
  return Number(e);
71
- case N.enum:
72
- case N.string:
73
- case N.uuid:
78
+ case _.enum:
79
+ case _.string:
80
+ case _.uuid:
74
81
  default:
75
82
  return String(e);
76
83
  }
77
- }, Ke = (e, t) => {
84
+ }, Je = (e, t) => {
78
85
  const n = {}, r = Object.keys(t), s = e.foreignKeyNames || [], a = e.foreignKeyColumnNames || s;
79
- for (let i = 0; i < r.length; i++) {
80
- const o = r[i], c = s.indexOf(o);
86
+ for (let o = 0; o < r.length; o++) {
87
+ const i = r[o], c = s.indexOf(i);
81
88
  if (c !== -1) {
82
- n[a[c]] = t[o];
89
+ n[a[c]] = t[i];
83
90
  continue;
84
91
  }
85
- if (a.indexOf(o) !== -1) {
86
- n[o] = t[o];
92
+ if (a.indexOf(i) !== -1) {
93
+ n[i] = t[i];
87
94
  continue;
88
95
  }
89
- const l = e.propertyMap.get(o);
90
- if (l) {
91
- n[l.columnName] = tt(t[o], l);
96
+ const u = e.propertyMap.get(i);
97
+ if (u) {
98
+ n[u.columnName] = nt(t[i], u);
92
99
  continue;
93
100
  }
94
- const p = e.columnNameToPropertyName?.get(o);
95
- if (p) {
96
- const h = e.propertyMap.get(p);
97
- h && (n[o] = tt(t[o], h));
101
+ const h = e.columnNameToPropertyName?.get(i);
102
+ if (h) {
103
+ const p = e.propertyMap.get(h);
104
+ p && (n[i] = nt(t[i], p));
98
105
  }
99
106
  }
100
107
  return n;
101
- }, Ct = (e, t) => {
108
+ }, vt = (e, t) => {
102
109
  const n = {};
103
- for (const [a, i] of e.propertyMap)
104
- a in t && (n[i.columnName] = t[a]);
110
+ for (const [a, o] of e.propertyMap)
111
+ a in t && (n[o.columnName] = t[a]);
105
112
  const r = e.foreignKeyNames || [], s = e.foreignKeyColumnNames || r;
106
113
  for (let a = 0; a < r.length; a++) {
107
- const i = r[a];
108
- i in t && (n[s[a]] = t[i]);
114
+ const o = r[a];
115
+ o in t && (n[s[a]] = t[o]);
109
116
  }
110
117
  return n;
111
- }, Xn = (e, t) => {
118
+ }, zn = (e, t) => {
112
119
  const n = {};
113
- for (const [a, i] of e.propertyMap)
114
- a in t && i.readonly !== !0 && (n[i.columnName] = t[a]);
120
+ for (const [a, o] of e.propertyMap)
121
+ a in t && o.readonly !== !0 && (n[o.columnName] = t[a]);
115
122
  const r = e.foreignKeyNames || [], s = e.foreignKeyColumnNames || r;
116
123
  for (let a = 0; a < r.length; a++) {
117
- const i = r[a];
118
- i in t && (n[s[a]] = t[i]);
124
+ const o = r[a];
125
+ o in t && (n[s[a]] = t[o]);
119
126
  }
120
127
  return n;
121
- }, zn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Je = (e) => {
128
+ }, Zn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Ye = (e) => {
122
129
  if (typeof e == "string") {
123
130
  const t = e.replaceAll("'", "''");
124
- return zn.test(e) ? `'${t}'::uuid` : `'${t}'`;
131
+ return Zn.test(e) ? `'${t}'::uuid` : `'${t}'`;
125
132
  }
126
- return e == null ? "NULL" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : Array.isArray(e) ? `ARRAY[${e.map((n) => Je(n)).join(", ")}]` : typeof e == "object" ? `'${JSON.stringify(e).replaceAll("'", "''")}'::jsonb` : String(e);
127
- }, nt = (e, t = []) => !t || t.length === 0 ? e : e.replace(/\$(\d+)/g, (n, r) => {
133
+ return e == null ? "NULL" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : Array.isArray(e) ? `ARRAY[${e.map((n) => Ye(n)).join(", ")}]` : typeof e == "object" ? `'${JSON.stringify(e).replaceAll("'", "''")}'::jsonb` : String(e);
134
+ }, st = (e, t = []) => !t || t.length === 0 ? e : e.replace(/\$(\d+)/g, (n, r) => {
128
135
  const s = parseInt(r, 10) - 1;
129
136
  if (s < 0 || s >= t.length)
130
137
  throw new x(`Parameter index ${r} out of range (have ${t.length} params)`);
131
- return Je(t[s]);
132
- }), Z = (e, t) => {
138
+ return Ye(t[s]);
139
+ }), ee = (e, t) => {
133
140
  const n = {}, r = e.foreignKeyNames || [], s = e.foreignKeyColumnNames || r, a = e.columnNameToPropertyName;
134
- return Object.keys(t).forEach((i) => {
135
- const o = t[i], c = s.indexOf(i);
141
+ return Object.keys(t).forEach((o) => {
142
+ const i = t[o], c = s.indexOf(o);
136
143
  if (c !== -1) {
137
- n[r[c]] = o;
144
+ n[r[c]] = i;
138
145
  return;
139
146
  }
140
- const u = a?.get(i);
141
- if (u) {
142
- const l = e.propertyMap.get(u);
143
- l && (l.type === N.number && typeof o == "string" ? n[u] = parseFloat(o) : l.type === N.integer && typeof o == "string" ? n[u] = parseInt(o, 10) : n[u] = o);
147
+ const l = a?.get(o);
148
+ if (l) {
149
+ const u = e.propertyMap.get(l);
150
+ u && (u.type === _.number && typeof i == "string" ? n[l] = parseFloat(i) : u.type === _.integer && typeof i == "string" ? n[l] = parseInt(i, 10) : u.type === _.numberArray && Array.isArray(i) ? n[l] = i.map((h) => typeof h == "string" ? parseFloat(h) : Number(h)) : u.type === _.keyValue ? n[l] = ae(i, u) : n[l] = i);
144
151
  return;
145
152
  }
146
153
  if (!a) {
147
- const l = e.propertyMap.get(i);
148
- if (l) {
149
- l.type === N.number && typeof o == "string" ? n[i] = parseFloat(o) : l.type === N.integer && typeof o == "string" ? n[i] = parseInt(o, 10) : n[i] = o;
154
+ const u = e.propertyMap.get(o);
155
+ if (u) {
156
+ u.type === _.number && typeof i == "string" ? n[o] = parseFloat(i) : u.type === _.integer && typeof i == "string" ? n[o] = parseInt(i, 10) : u.type === _.numberArray && Array.isArray(i) ? n[o] = i.map((h) => typeof h == "string" ? parseFloat(h) : Number(h)) : u.type === _.keyValue ? n[o] = ae(i, u) : n[o] = i;
150
157
  return;
151
158
  }
152
159
  }
153
- e.isForeignKey(i), n[i] = o;
160
+ e.isForeignKey(o), n[o] = i;
154
161
  }), n;
155
- }, Le = (e, t) => {
162
+ }, ae = (e, t) => {
156
163
  if (e == null) return e;
157
164
  switch (t.type) {
158
- case N.date:
165
+ case _.date:
159
166
  return e instanceof Date ? e : new Date(e);
160
- case N.json:
161
- case N.keyValue:
162
- case N.stringArray:
163
- case N.numberArray:
167
+ case _.keyValue: {
168
+ if (!e || typeof e != "object") return e;
169
+ const n = t.properties;
170
+ if (n && n.length > 0) {
171
+ const r = { ...e };
172
+ for (const s of n)
173
+ s.name in r && (r[s.name] = ae(r[s.name], s));
174
+ return r;
175
+ }
164
176
  return e;
165
- case N.boolean:
177
+ }
178
+ case _.json:
179
+ case _.stringArray:
180
+ case _.numberArray:
181
+ return e;
182
+ case _.boolean:
166
183
  return !!e;
167
184
  default:
168
185
  return e;
169
186
  }
170
- }, st = (e, t) => (Object.keys(t).forEach((n) => {
187
+ }, rt = (e, t) => (Object.keys(t).forEach((n) => {
171
188
  const r = t[n], s = e.propertyMap.get(n);
172
- s && (t[n] = Le(r, s));
189
+ s && (t[n] = ae(r, s));
173
190
  }), t);
174
- var Zn = Object.defineProperty, Lt = (e) => {
191
+ var es = Object.defineProperty, Mt = (e) => {
175
192
  throw TypeError(e);
176
- }, es = (e, t) => () => (e && (t = e(e = 0)), t), ye = (e, t) => {
177
- for (var n in t) Zn(e, n, { get: t[n], enumerable: !0 });
178
- }, Ye = (e, t, n) => t.has(e) || Lt("Cannot " + n), f = (e, t, n) => (Ye(e, t, "read from private field"), n ? n.call(e) : t.get(e)), j = (e, t, n) => t.has(e) ? Lt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), v = (e, t, n, r) => (Ye(e, t, "write to private field"), t.set(e, n), n), O = (e, t, n) => (Ye(e, t, "access private method"), n), Mt = (e, t, n, r) => ({ set _(s) {
179
- v(e, t, s);
193
+ }, ts = (e, t) => () => (e && (t = e(e = 0)), t), _e = (e, t) => {
194
+ for (var n in t) es(e, n, { get: t[n], enumerable: !0 });
195
+ }, Qe = (e, t, n) => t.has(e) || Mt("Cannot " + n), d = (e, t, n) => (Qe(e, t, "read from private field"), n ? n.call(e) : t.get(e)), j = (e, t, n) => t.has(e) ? Mt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), D = (e, t, n, r) => (Qe(e, t, "write to private field"), t.set(e, n), n), O = (e, t, n) => (Qe(e, t, "access private method"), n), qt = (e, t, n, r) => ({ set _(s) {
196
+ D(e, t, s);
180
197
  }, get _() {
181
- return f(e, t, r);
182
- } }), H = es(() => {
183
- }), ts = {};
184
- ye(ts, { ABSTIME: () => Es, ACLITEM: () => $s, BIT: () => Ss, BOOL: () => Me, BPCHAR: () => Ft, BYTEA: () => qe, CHAR: () => rs, CID: () => cs, CIDR: () => ps, CIRCLE: () => _s, DATE: () => kt, FLOAT4: () => jt, FLOAT8: () => xt, GTSVECTOR: () => Ws, INET: () => Ns, INT2: () => qt, INT4: () => Pt, INT8: () => Pe, INTERVAL: () => Rs, JSON: () => Ue, JSONB: () => Gt, MACADDR: () => ws, MACADDR8: () => gs, MONEY: () => Ts, NUMERIC: () => Os, OID: () => Ut, PATH: () => fs, PG_DEPENDENCIES: () => Fs, PG_LSN: () => js, PG_NDISTINCT: () => xs, PG_NODE_TREE: () => us, POLYGON: () => ds, REFCURSOR: () => vs, REGCLASS: () => Ms, REGCONFIG: () => Gs, REGDICTIONARY: () => Hs, REGNAMESPACE: () => Vs, REGOPER: () => Cs, REGOPERATOR: () => Ls, REGPROC: () => as, REGPROCEDURE: () => Ds, REGROLE: () => Ks, REGTYPE: () => qs, RELTIME: () => ms, SMGR: () => hs, TEXT: () => ce, TID: () => is, TIME: () => As, TIMESTAMP: () => Wt, TIMESTAMPTZ: () => je, TIMETZ: () => bs, TINTERVAL: () => ys, TSQUERY: () => ks, TSVECTOR: () => Bs, TXID_SNAPSHOT: () => Us, UUID: () => Ps, VARBIT: () => Is, VARCHAR: () => Bt, XID: () => os, XML: () => ls, arrayParser: () => er, arraySerializer: () => Vt, parseType: () => xe, parsers: () => Js, serializers: () => Ys, types: () => Ht });
198
+ return d(e, t, r);
199
+ } }), H = ts(() => {
200
+ }), ns = {};
201
+ _e(ns, { ABSTIME: () => ms, ACLITEM: () => $s, BIT: () => Is, BOOL: () => qe, BPCHAR: () => Bt, BYTEA: () => Pe, CHAR: () => as, CID: () => ls, CIDR: () => Es, CIRCLE: () => _s, DATE: () => Wt, FLOAT4: () => xt, FLOAT8: () => Ft, GTSVECTOR: () => Gs, INET: () => As, INT2: () => Pt, INT4: () => Ut, INT8: () => Ue, INTERVAL: () => Rs, JSON: () => je, JSONB: () => Ht, MACADDR: () => Ns, MACADDR8: () => Ts, MONEY: () => ws, NUMERIC: () => Ds, OID: () => jt, PATH: () => ds, PG_DEPENDENCIES: () => Bs, PG_LSN: () => xs, PG_NDISTINCT: () => Fs, PG_NODE_TREE: () => hs, POLYGON: () => ps, REFCURSOR: () => Cs, REGCLASS: () => qs, REGCONFIG: () => Hs, REGDICTIONARY: () => Vs, REGNAMESPACE: () => Ks, REGOPER: () => vs, REGOPERATOR: () => Ms, REGPROC: () => is, REGPROCEDURE: () => Ls, REGROLE: () => Js, REGTYPE: () => Ps, RELTIME: () => ys, SMGR: () => fs, TEXT: () => he, TID: () => os, TIME: () => bs, TIMESTAMP: () => Gt, TIMESTAMPTZ: () => xe, TIMETZ: () => Ss, TINTERVAL: () => gs, TSQUERY: () => Ws, TSVECTOR: () => ks, TXID_SNAPSHOT: () => js, UUID: () => Us, VARBIT: () => Os, VARCHAR: () => kt, XID: () => cs, XML: () => us, arrayParser: () => tr, arraySerializer: () => Kt, parseType: () => Fe, parsers: () => Ys, serializers: () => Qs, types: () => Vt });
185
202
  H();
186
- var ns = globalThis.JSON.parse, ss = globalThis.JSON.stringify, Me = 16, qe = 17, rs = 18, Pe = 20, qt = 21, Pt = 23, as = 24, ce = 25, Ut = 26, is = 27, os = 28, cs = 29, Ue = 114, ls = 142, us = 194, hs = 210, fs = 602, ds = 604, ps = 650, jt = 700, xt = 701, Es = 702, ms = 703, ys = 704, _s = 718, gs = 774, Ts = 790, ws = 829, Ns = 869, $s = 1033, Ft = 1042, Bt = 1043, kt = 1082, As = 1083, Wt = 1114, je = 1184, Rs = 1186, bs = 1266, Ss = 1560, Is = 1562, Os = 1700, vs = 1790, Ds = 2202, Cs = 2203, Ls = 2204, Ms = 2205, qs = 2206, Ps = 2950, Us = 2970, js = 3220, xs = 3361, Fs = 3402, Bs = 3614, ks = 3615, Ws = 3642, Gs = 3734, Hs = 3769, Gt = 3802, Vs = 4089, Ks = 4096, Ht = { string: { to: ce, from: [ce, Bt, Ft], serialize: (e) => {
203
+ var ss = globalThis.JSON.parse, rs = globalThis.JSON.stringify, qe = 16, Pe = 17, as = 18, Ue = 20, Pt = 21, Ut = 23, is = 24, he = 25, jt = 26, os = 27, cs = 28, ls = 29, je = 114, us = 142, hs = 194, fs = 210, ds = 602, ps = 604, Es = 650, xt = 700, Ft = 701, ms = 702, ys = 703, gs = 704, _s = 718, Ts = 774, ws = 790, Ns = 829, As = 869, $s = 1033, Bt = 1042, kt = 1043, Wt = 1082, bs = 1083, Gt = 1114, xe = 1184, Rs = 1186, Ss = 1266, Is = 1560, Os = 1562, Ds = 1700, Cs = 1790, Ls = 2202, vs = 2203, Ms = 2204, qs = 2205, Ps = 2206, Us = 2950, js = 2970, xs = 3220, Fs = 3361, Bs = 3402, ks = 3614, Ws = 3615, Gs = 3642, Hs = 3734, Vs = 3769, Ht = 3802, Ks = 4089, Js = 4096, Vt = { string: { to: he, from: [he, kt, Bt], serialize: (e) => {
187
204
  if (typeof e == "string") return e;
188
205
  if (typeof e == "number") return e.toString();
189
206
  throw new Error("Invalid input for string type");
190
- }, parse: (e) => e }, number: { to: 0, from: [qt, Pt, Ut, jt, xt], serialize: (e) => e.toString(), parse: (e) => +e }, bigint: { to: Pe, from: [Pe], serialize: (e) => e.toString(), parse: (e) => {
207
+ }, parse: (e) => e }, number: { to: 0, from: [Pt, Ut, jt, xt, Ft], serialize: (e) => e.toString(), parse: (e) => +e }, bigint: { to: Ue, from: [Ue], serialize: (e) => e.toString(), parse: (e) => {
191
208
  let t = BigInt(e);
192
209
  return t < Number.MIN_SAFE_INTEGER || t > Number.MAX_SAFE_INTEGER ? t : Number(t);
193
- } }, json: { to: Ue, from: [Ue, Gt], serialize: (e) => typeof e == "string" ? e : ss(e), parse: (e) => ns(e) }, boolean: { to: Me, from: [Me], serialize: (e) => {
210
+ } }, json: { to: je, from: [je, Ht], serialize: (e) => typeof e == "string" ? e : rs(e), parse: (e) => ss(e) }, boolean: { to: qe, from: [qe], serialize: (e) => {
194
211
  if (typeof e != "boolean") throw new Error("Invalid input for boolean type");
195
212
  return e ? "t" : "f";
196
- }, parse: (e) => e === "t" }, date: { to: je, from: [kt, Wt, je], serialize: (e) => {
213
+ }, parse: (e) => e === "t" }, date: { to: xe, from: [Wt, Gt, xe], serialize: (e) => {
197
214
  if (typeof e == "string") return e;
198
215
  if (typeof e == "number") return new Date(e).toISOString();
199
216
  if (e instanceof Date) return e.toISOString();
200
217
  throw new Error("Invalid input for date type");
201
- }, parse: (e) => new Date(e) }, bytea: { to: qe, from: [qe], serialize: (e) => {
218
+ }, parse: (e) => new Date(e) }, bytea: { to: Pe, from: [Pe], serialize: (e) => {
202
219
  if (!(e instanceof Uint8Array)) throw new Error("Invalid input for bytea type");
203
220
  return "\\x" + Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
204
221
  }, parse: (e) => {
205
222
  let t = e.slice(2);
206
223
  return Uint8Array.from({ length: t.length / 2 }, (n, r) => parseInt(t.substring(r * 2, (r + 1) * 2), 16));
207
- } } }, Qe = Qs(Ht), Js = Qe.parsers, Ys = Qe.serializers;
208
- function xe(e, t, n) {
224
+ } } }, Xe = Xs(Vt), Ys = Xe.parsers, Qs = Xe.serializers;
225
+ function Fe(e, t, n) {
209
226
  if (e === null) return null;
210
- let r = n?.[t] ?? Qe.parsers[t];
227
+ let r = n?.[t] ?? Xe.parsers[t];
211
228
  return r ? r(e, t) : e;
212
229
  }
213
- function Qs(e) {
230
+ function Xs(e) {
214
231
  return Object.keys(e).reduce(({ parsers: t, serializers: n }, r) => {
215
- let { to: s, from: a, serialize: i, parse: o } = e[r];
216
- return n[s] = i, n[r] = i, t[r] = o, Array.isArray(a) ? a.forEach((c) => {
217
- t[c] = o, n[c] = i;
218
- }) : (t[a] = o, n[a] = i), { parsers: t, serializers: n };
232
+ let { to: s, from: a, serialize: o, parse: i } = e[r];
233
+ return n[s] = o, n[r] = o, t[r] = i, Array.isArray(a) ? a.forEach((c) => {
234
+ t[c] = i, n[c] = o;
235
+ }) : (t[a] = i, n[a] = o), { parsers: t, serializers: n };
219
236
  }, { parsers: {}, serializers: {} });
220
237
  }
221
- var Xs = /\\/g, zs = /"/g;
222
- function Zs(e) {
223
- return e.replace(Xs, "\\\\").replace(zs, '\\"');
238
+ var zs = /\\/g, Zs = /"/g;
239
+ function er(e) {
240
+ return e.replace(zs, "\\\\").replace(Zs, '\\"');
224
241
  }
225
- function Vt(e, t, n) {
242
+ function Kt(e, t, n) {
226
243
  if (Array.isArray(e) === !1) return e;
227
244
  if (!e.length) return "{}";
228
245
  let r = e[0], s = n === 1020 ? ";" : ",";
229
- return Array.isArray(r) ? `{${e.map((a) => Vt(a, t, n)).join(s)}}` : `{${e.map((a) => (a === void 0 && (a = null), a === null ? "null" : '"' + Zs(t ? t(a) : a.toString()) + '"')).join(s)}}`;
246
+ return Array.isArray(r) ? `{${e.map((a) => Kt(a, t, n)).join(s)}}` : `{${e.map((a) => (a === void 0 && (a = null), a === null ? "null" : '"' + er(t ? t(a) : a.toString()) + '"')).join(s)}}`;
230
247
  }
231
- var Oe = { i: 0, char: null, str: "", quoted: !1, last: 0, p: null };
232
- function er(e, t, n) {
233
- return Oe.i = Oe.last = 0, Kt(Oe, e, t, n)[0];
248
+ var Ce = { i: 0, char: null, str: "", quoted: !1, last: 0, p: null };
249
+ function tr(e, t, n) {
250
+ return Ce.i = Ce.last = 0, Jt(Ce, e, t, n)[0];
234
251
  }
235
- function Kt(e, t, n, r) {
252
+ function Jt(e, t, n, r) {
236
253
  let s = [], a = r === 1020 ? ";" : ",";
237
254
  for (; e.i < t.length; e.i++) {
238
255
  if (e.char = t[e.i], e.quoted) e.char === "\\" ? e.str += t[++e.i] : e.char === '"' ? (s.push(n ? n(e.str) : e.str), e.str = "", e.quoted = t[e.i + 1] === '"', e.last = e.i + 2) : e.str += e.char;
239
256
  else if (e.char === '"') e.quoted = !0;
240
- else if (e.char === "{") e.last = ++e.i, s.push(Kt(e, t, n, r));
257
+ else if (e.char === "{") e.last = ++e.i, s.push(Jt(e, t, n, r));
241
258
  else if (e.char === "}") {
242
259
  e.quoted = !1, e.last < e.i && s.push(n ? n(t.slice(e.last, e.i)) : t.slice(e.last, e.i)), e.last = e.i + 1;
243
260
  break;
@@ -246,32 +263,32 @@ function Kt(e, t, n, r) {
246
263
  }
247
264
  return e.last < e.i && s.push(n ? n(t.slice(e.last, e.i + 1)) : t.slice(e.last, e.i + 1)), s;
248
265
  }
249
- var tr = {};
250
- ye(tr, { parseDescribeStatementResults: () => Jt, parseResults: () => nr });
266
+ var nr = {};
267
+ _e(nr, { parseDescribeStatementResults: () => Yt, parseResults: () => sr });
251
268
  H();
252
- function nr(e, t, n, r) {
253
- let s = [], a = { rows: [], fields: [] }, i = 0, o = { ...t, ...n?.parsers };
269
+ function sr(e, t, n, r) {
270
+ let s = [], a = { rows: [], fields: [] }, o = 0, i = { ...t, ...n?.parsers };
254
271
  return e.forEach((c) => {
255
272
  switch (c.name) {
256
273
  case "rowDescription": {
257
- let u = c;
258
- a.fields = u.fields.map((l) => ({ name: l.name, dataTypeID: l.dataTypeID }));
274
+ let l = c;
275
+ a.fields = l.fields.map((u) => ({ name: u.name, dataTypeID: u.dataTypeID }));
259
276
  break;
260
277
  }
261
278
  case "dataRow": {
262
279
  if (!a) break;
263
- let u = c;
264
- n?.rowMode === "array" ? a.rows.push(u.fields.map((l, p) => xe(l, a.fields[p].dataTypeID, o))) : a.rows.push(Object.fromEntries(u.fields.map((l, p) => [a.fields[p].name, xe(l, a.fields[p].dataTypeID, o)])));
280
+ let l = c;
281
+ n?.rowMode === "array" ? a.rows.push(l.fields.map((u, h) => Fe(u, a.fields[h].dataTypeID, i))) : a.rows.push(Object.fromEntries(l.fields.map((u, h) => [a.fields[h].name, Fe(u, a.fields[h].dataTypeID, i)])));
265
282
  break;
266
283
  }
267
284
  case "commandComplete": {
268
- i += sr(c), s.push({ ...a, affectedRows: i, ...r ? { blob: r } : {} }), a = { rows: [], fields: [] };
285
+ o += rr(c), s.push({ ...a, affectedRows: o, ...r ? { blob: r } : {} }), a = { rows: [], fields: [] };
269
286
  break;
270
287
  }
271
288
  }
272
289
  }), s.length === 0 && s.push({ affectedRows: 0, rows: [], fields: [] }), s;
273
290
  }
274
- function sr(e) {
291
+ function rr(e) {
275
292
  let t = e.text.split(" ");
276
293
  switch (t[0]) {
277
294
  case "INSERT":
@@ -285,66 +302,66 @@ function sr(e) {
285
302
  return 0;
286
303
  }
287
304
  }
288
- function Jt(e) {
305
+ function Yt(e) {
289
306
  let t = e.find((n) => n.name === "parameterDescription");
290
307
  return t ? t.dataTypeIDs : [];
291
308
  }
292
- var Yt = {};
293
- ye(Yt, { AuthenticationCleartextPassword: () => an, AuthenticationMD5Password: () => on, AuthenticationOk: () => rn, AuthenticationSASL: () => cn, AuthenticationSASLContinue: () => ln, AuthenticationSASLFinal: () => un, BackendKeyDataMessage: () => yn, CommandCompleteMessage: () => Tn, CopyDataMessage: () => hn, CopyResponse: () => fn, DataRowMessage: () => wn, DatabaseError: () => Fe, Field: () => dn, NoticeMessage: () => Nn, NotificationResponseMessage: () => _n, ParameterDescriptionMessage: () => En, ParameterStatusMessage: () => mn, ReadyForQueryMessage: () => gn, RowDescriptionMessage: () => pn, bindComplete: () => Xt, closeComplete: () => zt, copyDone: () => sn, emptyQuery: () => nn, noData: () => Zt, parseComplete: () => Qt, portalSuspended: () => en, replicationStart: () => tn });
309
+ var Qt = {};
310
+ _e(Qt, { AuthenticationCleartextPassword: () => on, AuthenticationMD5Password: () => cn, AuthenticationOk: () => an, AuthenticationSASL: () => ln, AuthenticationSASLContinue: () => un, AuthenticationSASLFinal: () => hn, BackendKeyDataMessage: () => gn, CommandCompleteMessage: () => wn, CopyDataMessage: () => fn, CopyResponse: () => dn, DataRowMessage: () => Nn, DatabaseError: () => Be, Field: () => pn, NoticeMessage: () => An, NotificationResponseMessage: () => _n, ParameterDescriptionMessage: () => mn, ParameterStatusMessage: () => yn, ReadyForQueryMessage: () => Tn, RowDescriptionMessage: () => En, bindComplete: () => zt, closeComplete: () => Zt, copyDone: () => rn, emptyQuery: () => sn, noData: () => en, parseComplete: () => Xt, portalSuspended: () => tn, replicationStart: () => nn });
294
311
  H();
295
- var Qt = { name: "parseComplete", length: 5 }, Xt = { name: "bindComplete", length: 5 }, zt = { name: "closeComplete", length: 5 }, Zt = { name: "noData", length: 5 }, en = { name: "portalSuspended", length: 5 }, tn = { name: "replicationStart", length: 4 }, nn = { name: "emptyQuery", length: 4 }, sn = { name: "copyDone", length: 4 }, rn = class {
312
+ var Xt = { name: "parseComplete", length: 5 }, zt = { name: "bindComplete", length: 5 }, Zt = { name: "closeComplete", length: 5 }, en = { name: "noData", length: 5 }, tn = { name: "portalSuspended", length: 5 }, nn = { name: "replicationStart", length: 4 }, sn = { name: "emptyQuery", length: 4 }, rn = { name: "copyDone", length: 4 }, an = class {
296
313
  constructor(t) {
297
314
  this.length = t, this.name = "authenticationOk";
298
315
  }
299
- }, an = class {
316
+ }, on = class {
300
317
  constructor(e) {
301
318
  this.length = e, this.name = "authenticationCleartextPassword";
302
319
  }
303
- }, on = class {
320
+ }, cn = class {
304
321
  constructor(e, t) {
305
322
  this.length = e, this.salt = t, this.name = "authenticationMD5Password";
306
323
  }
307
- }, cn = class {
324
+ }, ln = class {
308
325
  constructor(t, n) {
309
326
  this.length = t, this.mechanisms = n, this.name = "authenticationSASL";
310
327
  }
311
- }, ln = class {
328
+ }, un = class {
312
329
  constructor(e, t) {
313
330
  this.length = e, this.data = t, this.name = "authenticationSASLContinue";
314
331
  }
315
- }, un = class {
332
+ }, hn = class {
316
333
  constructor(e, t) {
317
334
  this.length = e, this.data = t, this.name = "authenticationSASLFinal";
318
335
  }
319
- }, Fe = class extends Error {
336
+ }, Be = class extends Error {
320
337
  constructor(e, t, n) {
321
338
  super(e), this.length = t, this.name = n;
322
339
  }
323
- }, hn = class {
340
+ }, fn = class {
324
341
  constructor(e, t) {
325
342
  this.length = e, this.chunk = t, this.name = "copyData";
326
343
  }
327
- }, fn = class {
344
+ }, dn = class {
328
345
  constructor(e, t, n, r) {
329
346
  this.length = e, this.name = t, this.binary = n, this.columnTypes = new Array(r);
330
347
  }
331
- }, dn = class {
332
- constructor(e, t, n, r, s, a, i) {
333
- this.name = e, this.tableID = t, this.columnID = n, this.dataTypeID = r, this.dataTypeSize = s, this.dataTypeModifier = a, this.format = i;
334
- }
335
348
  }, pn = class {
349
+ constructor(e, t, n, r, s, a, o) {
350
+ this.name = e, this.tableID = t, this.columnID = n, this.dataTypeID = r, this.dataTypeSize = s, this.dataTypeModifier = a, this.format = o;
351
+ }
352
+ }, En = class {
336
353
  constructor(t, n) {
337
354
  this.length = t, this.fieldCount = n, this.name = "rowDescription", this.fields = new Array(this.fieldCount);
338
355
  }
339
- }, En = class {
356
+ }, mn = class {
340
357
  constructor(e, t) {
341
358
  this.length = e, this.parameterCount = t, this.name = "parameterDescription", this.dataTypeIDs = new Array(this.parameterCount);
342
359
  }
343
- }, mn = class {
360
+ }, yn = class {
344
361
  constructor(e, t, n) {
345
362
  this.length = e, this.parameterName = t, this.parameterValue = n, this.name = "parameterStatus";
346
363
  }
347
- }, yn = class {
364
+ }, gn = class {
348
365
  constructor(e, t, n) {
349
366
  this.length = e, this.processID = t, this.secretKey = n, this.name = "backendKeyData";
350
367
  }
@@ -352,29 +369,29 @@ var Qt = { name: "parseComplete", length: 5 }, Xt = { name: "bindComplete", leng
352
369
  constructor(e, t, n, r) {
353
370
  this.length = e, this.processId = t, this.channel = n, this.payload = r, this.name = "notification";
354
371
  }
355
- }, gn = class {
372
+ }, Tn = class {
356
373
  constructor(e, t) {
357
374
  this.length = e, this.status = t, this.name = "readyForQuery";
358
375
  }
359
- }, Tn = class {
376
+ }, wn = class {
360
377
  constructor(e, t) {
361
378
  this.length = e, this.text = t, this.name = "commandComplete";
362
379
  }
363
- }, wn = class {
380
+ }, Nn = class {
364
381
  constructor(e, t) {
365
382
  this.length = e, this.fields = t, this.name = "dataRow", this.fieldCount = t.length;
366
383
  }
367
- }, Nn = class {
384
+ }, An = class {
368
385
  constructor(e, t) {
369
386
  this.length = e, this.message = t, this.name = "notice";
370
387
  }
371
- }, rr = {};
372
- ye(rr, { Parser: () => Dr, messages: () => Yt, serialize: () => re });
388
+ }, ar = {};
389
+ _e(ar, { Parser: () => Lr, messages: () => Qt, serialize: () => oe });
373
390
  H();
374
391
  H();
375
392
  H();
376
393
  H();
377
- function _e(e) {
394
+ function Te(e) {
378
395
  let t = e.length;
379
396
  for (let n = e.length - 1; n >= 0; n--) {
380
397
  let r = e.charCodeAt(n);
@@ -382,293 +399,293 @@ function _e(e) {
382
399
  }
383
400
  return t;
384
401
  }
385
- var U, M, te, Be, ee, V, le, X, $n, ge = class {
402
+ var U, M, se, ke, ne, V, fe, z, $n, we = class {
386
403
  constructor(e = 256) {
387
- this.size = e, j(this, V), j(this, U), j(this, M, 5), j(this, te, !1), j(this, Be, new TextEncoder()), j(this, ee, 0), v(this, U, O(this, V, le).call(this, e));
404
+ this.size = e, j(this, V), j(this, U), j(this, M, 5), j(this, se, !1), j(this, ke, new TextEncoder()), j(this, ne, 0), D(this, U, O(this, V, fe).call(this, e));
388
405
  }
389
406
  addInt32(e) {
390
- return O(this, V, X).call(this, 4), f(this, U).setInt32(f(this, M), e, f(this, te)), v(this, M, f(this, M) + 4), this;
407
+ return O(this, V, z).call(this, 4), d(this, U).setInt32(d(this, M), e, d(this, se)), D(this, M, d(this, M) + 4), this;
391
408
  }
392
409
  addInt16(e) {
393
- return O(this, V, X).call(this, 2), f(this, U).setInt16(f(this, M), e, f(this, te)), v(this, M, f(this, M) + 2), this;
410
+ return O(this, V, z).call(this, 2), d(this, U).setInt16(d(this, M), e, d(this, se)), D(this, M, d(this, M) + 2), this;
394
411
  }
395
412
  addCString(e) {
396
- return e && this.addString(e), O(this, V, X).call(this, 1), f(this, U).setUint8(f(this, M), 0), Mt(this, M)._++, this;
413
+ return e && this.addString(e), O(this, V, z).call(this, 1), d(this, U).setUint8(d(this, M), 0), qt(this, M)._++, this;
397
414
  }
398
415
  addString(e = "") {
399
- let t = _e(e);
400
- return O(this, V, X).call(this, t), f(this, Be).encodeInto(e, new Uint8Array(f(this, U).buffer, f(this, M))), v(this, M, f(this, M) + t), this;
416
+ let t = Te(e);
417
+ return O(this, V, z).call(this, t), d(this, ke).encodeInto(e, new Uint8Array(d(this, U).buffer, d(this, M))), D(this, M, d(this, M) + t), this;
401
418
  }
402
419
  add(e) {
403
- return O(this, V, X).call(this, e.byteLength), new Uint8Array(f(this, U).buffer).set(new Uint8Array(e), f(this, M)), v(this, M, f(this, M) + e.byteLength), this;
420
+ return O(this, V, z).call(this, e.byteLength), new Uint8Array(d(this, U).buffer).set(new Uint8Array(e), d(this, M)), D(this, M, d(this, M) + e.byteLength), this;
404
421
  }
405
422
  flush(e) {
406
423
  let t = O(this, V, $n).call(this, e);
407
- return v(this, M, 5), v(this, U, O(this, V, le).call(this, this.size)), new Uint8Array(t);
424
+ return D(this, M, 5), D(this, U, O(this, V, fe).call(this, this.size)), new Uint8Array(t);
408
425
  }
409
426
  };
410
- U = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakSet(), le = function(e) {
427
+ U = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), se = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakSet(), fe = function(e) {
411
428
  return new DataView(new ArrayBuffer(e));
412
- }, X = function(e) {
413
- if (f(this, U).byteLength - f(this, M) < e) {
414
- let t = f(this, U).buffer, n = t.byteLength + (t.byteLength >> 1) + e;
415
- v(this, U, O(this, V, le).call(this, n)), new Uint8Array(f(this, U).buffer).set(new Uint8Array(t));
429
+ }, z = function(e) {
430
+ if (d(this, U).byteLength - d(this, M) < e) {
431
+ let t = d(this, U).buffer, n = t.byteLength + (t.byteLength >> 1) + e;
432
+ D(this, U, O(this, V, fe).call(this, n)), new Uint8Array(d(this, U).buffer).set(new Uint8Array(t));
416
433
  }
417
434
  }, $n = function(e) {
418
435
  if (e) {
419
- f(this, U).setUint8(f(this, ee), e);
420
- let t = f(this, M) - (f(this, ee) + 1);
421
- f(this, U).setInt32(f(this, ee) + 1, t, f(this, te));
436
+ d(this, U).setUint8(d(this, ne), e);
437
+ let t = d(this, M) - (d(this, ne) + 1);
438
+ d(this, U).setInt32(d(this, ne) + 1, t, d(this, se));
422
439
  }
423
- return f(this, U).buffer.slice(e ? 0 : 5, f(this, M));
440
+ return d(this, U).buffer.slice(e ? 0 : 5, d(this, M));
424
441
  };
425
- var C = new ge(), ar = (e) => {
426
- C.addInt16(3).addInt16(0);
427
- for (let r of Object.keys(e)) C.addCString(r).addCString(e[r]);
428
- C.addCString("client_encoding").addCString("UTF8");
429
- let t = C.addCString("").flush(), n = t.byteLength + 4;
430
- return new ge().addInt32(n).add(t).flush();
431
- }, ir = () => {
442
+ var L = new we(), ir = (e) => {
443
+ L.addInt16(3).addInt16(0);
444
+ for (let r of Object.keys(e)) L.addCString(r).addCString(e[r]);
445
+ L.addCString("client_encoding").addCString("UTF8");
446
+ let t = L.addCString("").flush(), n = t.byteLength + 4;
447
+ return new we().addInt32(n).add(t).flush();
448
+ }, or = () => {
432
449
  let e = new DataView(new ArrayBuffer(8));
433
450
  return e.setInt32(0, 8, !1), e.setInt32(4, 80877103, !1), new Uint8Array(e.buffer);
434
- }, or = (e) => C.addCString(e).flush(112), cr = (e, t) => (C.addCString(e).addInt32(_e(t)).addString(t), C.flush(112)), lr = (e) => C.addString(e).flush(112), ur = (e) => C.addCString(e).flush(81), hr = [], fr = (e) => {
451
+ }, cr = (e) => L.addCString(e).flush(112), lr = (e, t) => (L.addCString(e).addInt32(Te(t)).addString(t), L.flush(112)), ur = (e) => L.addString(e).flush(112), hr = (e) => L.addCString(e).flush(81), fr = [], dr = (e) => {
435
452
  let t = e.name ?? "";
436
453
  t.length > 63 && (console.error("Warning! Postgres only supports 63 characters for query names."), console.error("You supplied %s (%s)", t, t.length), console.error("This can cause conflicts and silent errors executing queries"));
437
- let n = C.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
438
- return e.types?.forEach((r) => n.addInt32(r)), C.flush(80);
439
- }, z = new ge(), dr = (e, t) => {
454
+ let n = L.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
455
+ return e.types?.forEach((r) => n.addInt32(r)), L.flush(80);
456
+ }, Z = new we(), pr = (e, t) => {
440
457
  for (let n = 0; n < e.length; n++) {
441
458
  let r = t ? t(e[n], n) : e[n];
442
- if (r === null) C.addInt16(0), z.addInt32(-1);
459
+ if (r === null) L.addInt16(0), Z.addInt32(-1);
443
460
  else if (r instanceof ArrayBuffer || ArrayBuffer.isView(r)) {
444
461
  let s = ArrayBuffer.isView(r) ? r.buffer.slice(r.byteOffset, r.byteOffset + r.byteLength) : r;
445
- C.addInt16(1), z.addInt32(s.byteLength), z.add(s);
446
- } else C.addInt16(0), z.addInt32(_e(r)), z.addString(r);
447
- }
448
- }, pr = (e = {}) => {
449
- let t = e.portal ?? "", n = e.statement ?? "", r = e.binary ?? !1, s = e.values ?? hr, a = s.length;
450
- return C.addCString(t).addCString(n), C.addInt16(a), dr(s, e.valueMapper), C.addInt16(a), C.add(z.flush()), C.addInt16(r ? 1 : 0), C.flush(66);
451
- }, Er = new Uint8Array([69, 0, 0, 0, 9, 0, 0, 0, 0, 0]), mr = (e) => {
452
- if (!e || !e.portal && !e.rows) return Er;
453
- let t = e.portal ?? "", n = e.rows ?? 0, r = _e(t), s = 4 + r + 1 + 4, a = new DataView(new ArrayBuffer(1 + s));
462
+ L.addInt16(1), Z.addInt32(s.byteLength), Z.add(s);
463
+ } else L.addInt16(0), Z.addInt32(Te(r)), Z.addString(r);
464
+ }
465
+ }, Er = (e = {}) => {
466
+ let t = e.portal ?? "", n = e.statement ?? "", r = e.binary ?? !1, s = e.values ?? fr, a = s.length;
467
+ return L.addCString(t).addCString(n), L.addInt16(a), pr(s, e.valueMapper), L.addInt16(a), L.add(Z.flush()), L.addInt16(r ? 1 : 0), L.flush(66);
468
+ }, mr = new Uint8Array([69, 0, 0, 0, 9, 0, 0, 0, 0, 0]), yr = (e) => {
469
+ if (!e || !e.portal && !e.rows) return mr;
470
+ let t = e.portal ?? "", n = e.rows ?? 0, r = Te(t), s = 4 + r + 1 + 4, a = new DataView(new ArrayBuffer(1 + s));
454
471
  return a.setUint8(0, 69), a.setInt32(1, s, !1), new TextEncoder().encodeInto(t, new Uint8Array(a.buffer, 5)), a.setUint8(r + 5, 0), a.setUint32(a.byteLength - 4, n, !1), new Uint8Array(a.buffer);
455
- }, yr = (e, t) => {
472
+ }, gr = (e, t) => {
456
473
  let n = new DataView(new ArrayBuffer(16));
457
474
  return n.setInt32(0, 16, !1), n.setInt16(4, 1234, !1), n.setInt16(6, 5678, !1), n.setInt32(8, e, !1), n.setInt32(12, t, !1), new Uint8Array(n.buffer);
458
- }, Xe = (e, t) => {
459
- let n = new ge();
475
+ }, ze = (e, t) => {
476
+ let n = new we();
460
477
  return n.addCString(t), n.flush(e);
461
- }, _r = C.addCString("P").flush(68), gr = C.addCString("S").flush(68), Tr = (e) => e.name ? Xe(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? _r : gr, wr = (e) => {
478
+ }, _r = L.addCString("P").flush(68), Tr = L.addCString("S").flush(68), wr = (e) => e.name ? ze(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? _r : Tr, Nr = (e) => {
462
479
  let t = `${e.type}${e.name ?? ""}`;
463
- return Xe(67, t);
464
- }, Nr = (e) => C.add(e).flush(100), $r = (e) => Xe(102, e), Te = (e) => new Uint8Array([e, 0, 0, 0, 4]), Ar = Te(72), Rr = Te(83), br = Te(88), Sr = Te(99), re = { startup: ar, password: or, requestSsl: ir, sendSASLInitialResponseMessage: cr, sendSCRAMClientFinalMessage: lr, query: ur, parse: fr, bind: pr, execute: mr, describe: Tr, close: wr, flush: () => Ar, sync: () => Rr, end: () => br, copyData: Nr, copyDone: () => Sr, copyFail: $r, cancel: yr };
480
+ return ze(67, t);
481
+ }, Ar = (e) => L.add(e).flush(100), $r = (e) => ze(102, e), Ne = (e) => new Uint8Array([e, 0, 0, 0, 4]), br = Ne(72), Rr = Ne(83), Sr = Ne(88), Ir = Ne(99), oe = { startup: ir, password: cr, requestSsl: or, sendSASLInitialResponseMessage: lr, sendSCRAMClientFinalMessage: ur, query: hr, parse: dr, bind: Er, execute: yr, describe: wr, close: Nr, flush: () => br, sync: () => Rr, end: () => Sr, copyData: Ar, copyDone: () => Ir, copyFail: $r, cancel: gr };
465
482
  H();
466
483
  H();
467
- var rt = { text: 0, binary: 1 };
484
+ var at = { text: 0, binary: 1 };
468
485
  H();
469
- var Ir = new ArrayBuffer(0), Y, q, ke, We, ae, Or = class {
486
+ var Or = new ArrayBuffer(0), Y, q, We, Ge, ce, Dr = class {
470
487
  constructor(e = 0) {
471
- j(this, Y, new DataView(Ir)), j(this, q), j(this, ke, "utf-8"), j(this, We, new TextDecoder(f(this, ke))), j(this, ae, !1), v(this, q, e);
488
+ j(this, Y, new DataView(Or)), j(this, q), j(this, We, "utf-8"), j(this, Ge, new TextDecoder(d(this, We))), j(this, ce, !1), D(this, q, e);
472
489
  }
473
490
  setBuffer(e, t) {
474
- v(this, q, e), v(this, Y, new DataView(t));
491
+ D(this, q, e), D(this, Y, new DataView(t));
475
492
  }
476
493
  int16() {
477
- let e = f(this, Y).getInt16(f(this, q), f(this, ae));
478
- return v(this, q, f(this, q) + 2), e;
494
+ let e = d(this, Y).getInt16(d(this, q), d(this, ce));
495
+ return D(this, q, d(this, q) + 2), e;
479
496
  }
480
497
  byte() {
481
- let e = f(this, Y).getUint8(f(this, q));
482
- return Mt(this, q)._++, e;
498
+ let e = d(this, Y).getUint8(d(this, q));
499
+ return qt(this, q)._++, e;
483
500
  }
484
501
  int32() {
485
- let e = f(this, Y).getInt32(f(this, q), f(this, ae));
486
- return v(this, q, f(this, q) + 4), e;
502
+ let e = d(this, Y).getInt32(d(this, q), d(this, ce));
503
+ return D(this, q, d(this, q) + 4), e;
487
504
  }
488
505
  string(e) {
489
- return f(this, We).decode(this.bytes(e));
506
+ return d(this, Ge).decode(this.bytes(e));
490
507
  }
491
508
  cstring() {
492
- let e = f(this, q), t = e;
493
- for (; f(this, Y).getUint8(t++) !== 0; ) ;
509
+ let e = d(this, q), t = e;
510
+ for (; d(this, Y).getUint8(t++) !== 0; ) ;
494
511
  let n = this.string(t - e - 1);
495
- return v(this, q, t), n;
512
+ return D(this, q, t), n;
496
513
  }
497
514
  bytes(e) {
498
- let t = f(this, Y).buffer.slice(f(this, q), f(this, q) + e);
499
- return v(this, q, f(this, q) + e), new Uint8Array(t);
515
+ let t = d(this, Y).buffer.slice(d(this, q), d(this, q) + e);
516
+ return D(this, q, d(this, q) + e), new Uint8Array(t);
500
517
  }
501
518
  };
502
- Y = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), ae = /* @__PURE__ */ new WeakMap();
503
- var Ge = 1, vr = 4, at = Ge + vr, it = new ArrayBuffer(0), F, W, G, w, L, An, Rn, ot, ct, lt, ut, ht, ve, ft, dt, pt, Et, mt, yt, _t, gt, De, Dr = class {
519
+ Y = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), Ge = /* @__PURE__ */ new WeakMap(), ce = /* @__PURE__ */ new WeakMap();
520
+ var He = 1, Cr = 4, it = He + Cr, ot = new ArrayBuffer(0), F, W, G, w, v, bn, Rn, ct, lt, ut, ht, ft, Le, dt, pt, Et, mt, yt, gt, _t, Tt, ve, Lr = class {
504
521
  constructor() {
505
- j(this, L), j(this, F, new DataView(it)), j(this, W, 0), j(this, G, 0), j(this, w, new Or());
522
+ j(this, v), j(this, F, new DataView(ot)), j(this, W, 0), j(this, G, 0), j(this, w, new Dr());
506
523
  }
507
524
  parse(e, t) {
508
- O(this, L, An).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
509
- let n = f(this, G) + f(this, W), r = f(this, G);
510
- for (; r + at <= n; ) {
511
- let s = f(this, F).getUint8(r), a = f(this, F).getUint32(r + Ge, !1), i = Ge + a;
512
- if (i + r <= n && a > 0) {
513
- let o = O(this, L, Rn).call(this, r + at, s, a, f(this, F).buffer);
514
- t(o), r += i;
525
+ O(this, v, bn).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
526
+ let n = d(this, G) + d(this, W), r = d(this, G);
527
+ for (; r + it <= n; ) {
528
+ let s = d(this, F).getUint8(r), a = d(this, F).getUint32(r + He, !1), o = He + a;
529
+ if (o + r <= n && a > 0) {
530
+ let i = O(this, v, Rn).call(this, r + it, s, a, d(this, F).buffer);
531
+ t(i), r += o;
515
532
  } else break;
516
533
  }
517
- r === n ? (v(this, F, new DataView(it)), v(this, W, 0), v(this, G, 0)) : (v(this, W, n - r), v(this, G, r));
534
+ r === n ? (D(this, F, new DataView(ot)), D(this, W, 0), D(this, G, 0)) : (D(this, W, n - r), D(this, G, r));
518
535
  }
519
536
  };
520
- F = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakSet(), An = function(e) {
521
- if (f(this, W) > 0) {
522
- let t = f(this, W) + e.byteLength;
523
- if (t + f(this, G) > f(this, F).byteLength) {
537
+ F = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakSet(), bn = function(e) {
538
+ if (d(this, W) > 0) {
539
+ let t = d(this, W) + e.byteLength;
540
+ if (t + d(this, G) > d(this, F).byteLength) {
524
541
  let n;
525
- if (t <= f(this, F).byteLength && f(this, G) >= f(this, W)) n = f(this, F).buffer;
542
+ if (t <= d(this, F).byteLength && d(this, G) >= d(this, W)) n = d(this, F).buffer;
526
543
  else {
527
- let r = f(this, F).byteLength * 2;
544
+ let r = d(this, F).byteLength * 2;
528
545
  for (; t >= r; ) r *= 2;
529
546
  n = new ArrayBuffer(r);
530
547
  }
531
- new Uint8Array(n).set(new Uint8Array(f(this, F).buffer, f(this, G), f(this, W))), v(this, F, new DataView(n)), v(this, G, 0);
548
+ new Uint8Array(n).set(new Uint8Array(d(this, F).buffer, d(this, G), d(this, W))), D(this, F, new DataView(n)), D(this, G, 0);
532
549
  }
533
- new Uint8Array(f(this, F).buffer).set(new Uint8Array(e), f(this, G) + f(this, W)), v(this, W, t);
534
- } else v(this, F, new DataView(e)), v(this, G, 0), v(this, W, e.byteLength);
550
+ new Uint8Array(d(this, F).buffer).set(new Uint8Array(e), d(this, G) + d(this, W)), D(this, W, t);
551
+ } else D(this, F, new DataView(e)), D(this, G, 0), D(this, W, e.byteLength);
535
552
  }, Rn = function(e, t, n, r) {
536
553
  switch (t) {
537
554
  case 50:
538
- return Xt;
555
+ return zt;
539
556
  case 49:
540
- return Qt;
557
+ return Xt;
541
558
  case 51:
542
- return zt;
543
- case 110:
544
559
  return Zt;
545
- case 115:
560
+ case 110:
546
561
  return en;
562
+ case 115:
563
+ return tn;
547
564
  case 99:
548
- return sn;
565
+ return rn;
549
566
  case 87:
550
- return tn;
551
- case 73:
552
567
  return nn;
568
+ case 73:
569
+ return sn;
553
570
  case 68:
554
- return O(this, L, mt).call(this, e, n, r);
571
+ return O(this, v, yt).call(this, e, n, r);
555
572
  case 67:
556
- return O(this, L, ct).call(this, e, n, r);
573
+ return O(this, v, lt).call(this, e, n, r);
557
574
  case 90:
558
- return O(this, L, ot).call(this, e, n, r);
575
+ return O(this, v, ct).call(this, e, n, r);
559
576
  case 65:
560
- return O(this, L, ft).call(this, e, n, r);
577
+ return O(this, v, dt).call(this, e, n, r);
561
578
  case 82:
562
- return O(this, L, gt).call(this, e, n, r);
579
+ return O(this, v, Tt).call(this, e, n, r);
563
580
  case 83:
564
- return O(this, L, yt).call(this, e, n, r);
581
+ return O(this, v, gt).call(this, e, n, r);
565
582
  case 75:
566
- return O(this, L, _t).call(this, e, n, r);
583
+ return O(this, v, _t).call(this, e, n, r);
567
584
  case 69:
568
- return O(this, L, De).call(this, e, n, r, "error");
585
+ return O(this, v, ve).call(this, e, n, r, "error");
569
586
  case 78:
570
- return O(this, L, De).call(this, e, n, r, "notice");
587
+ return O(this, v, ve).call(this, e, n, r, "notice");
571
588
  case 84:
572
- return O(this, L, dt).call(this, e, n, r);
589
+ return O(this, v, pt).call(this, e, n, r);
573
590
  case 116:
574
- return O(this, L, Et).call(this, e, n, r);
591
+ return O(this, v, mt).call(this, e, n, r);
575
592
  case 71:
576
- return O(this, L, ut).call(this, e, n, r);
593
+ return O(this, v, ht).call(this, e, n, r);
577
594
  case 72:
578
- return O(this, L, ht).call(this, e, n, r);
595
+ return O(this, v, ft).call(this, e, n, r);
579
596
  case 100:
580
- return O(this, L, lt).call(this, e, n, r);
597
+ return O(this, v, ut).call(this, e, n, r);
581
598
  default:
582
- return new Fe("received invalid response: " + t.toString(16), n, "error");
599
+ return new Be("received invalid response: " + t.toString(16), n, "error");
583
600
  }
584
- }, ot = function(e, t, n) {
585
- f(this, w).setBuffer(e, n);
586
- let r = f(this, w).string(1);
587
- return new gn(t, r);
588
601
  }, ct = function(e, t, n) {
589
- f(this, w).setBuffer(e, n);
590
- let r = f(this, w).cstring();
602
+ d(this, w).setBuffer(e, n);
603
+ let r = d(this, w).string(1);
591
604
  return new Tn(t, r);
592
605
  }, lt = function(e, t, n) {
593
- let r = n.slice(e, e + (t - 4));
594
- return new hn(t, new Uint8Array(r));
606
+ d(this, w).setBuffer(e, n);
607
+ let r = d(this, w).cstring();
608
+ return new wn(t, r);
595
609
  }, ut = function(e, t, n) {
596
- return O(this, L, ve).call(this, e, t, n, "copyInResponse");
610
+ let r = n.slice(e, e + (t - 4));
611
+ return new fn(t, new Uint8Array(r));
597
612
  }, ht = function(e, t, n) {
598
- return O(this, L, ve).call(this, e, t, n, "copyOutResponse");
599
- }, ve = function(e, t, n, r) {
600
- f(this, w).setBuffer(e, n);
601
- let s = f(this, w).byte() !== 0, a = f(this, w).int16(), i = new fn(t, r, s, a);
602
- for (let o = 0; o < a; o++) i.columnTypes[o] = f(this, w).int16();
603
- return i;
613
+ return O(this, v, Le).call(this, e, t, n, "copyInResponse");
604
614
  }, ft = function(e, t, n) {
605
- f(this, w).setBuffer(e, n);
606
- let r = f(this, w).int32(), s = f(this, w).cstring(), a = f(this, w).cstring();
607
- return new _n(t, r, s, a);
615
+ return O(this, v, Le).call(this, e, t, n, "copyOutResponse");
616
+ }, Le = function(e, t, n, r) {
617
+ d(this, w).setBuffer(e, n);
618
+ let s = d(this, w).byte() !== 0, a = d(this, w).int16(), o = new dn(t, r, s, a);
619
+ for (let i = 0; i < a; i++) o.columnTypes[i] = d(this, w).int16();
620
+ return o;
608
621
  }, dt = function(e, t, n) {
609
- f(this, w).setBuffer(e, n);
610
- let r = f(this, w).int16(), s = new pn(t, r);
611
- for (let a = 0; a < r; a++) s.fields[a] = O(this, L, pt).call(this);
612
- return s;
613
- }, pt = function() {
614
- let e = f(this, w).cstring(), t = f(this, w).int32(), n = f(this, w).int16(), r = f(this, w).int32(), s = f(this, w).int16(), a = f(this, w).int32(), i = f(this, w).int16() === 0 ? rt.text : rt.binary;
615
- return new dn(e, t, n, r, s, a, i);
616
- }, Et = function(e, t, n) {
617
- f(this, w).setBuffer(e, n);
618
- let r = f(this, w).int16(), s = new En(t, r);
619
- for (let a = 0; a < r; a++) s.dataTypeIDs[a] = f(this, w).int32();
622
+ d(this, w).setBuffer(e, n);
623
+ let r = d(this, w).int32(), s = d(this, w).cstring(), a = d(this, w).cstring();
624
+ return new _n(t, r, s, a);
625
+ }, pt = function(e, t, n) {
626
+ d(this, w).setBuffer(e, n);
627
+ let r = d(this, w).int16(), s = new En(t, r);
628
+ for (let a = 0; a < r; a++) s.fields[a] = O(this, v, Et).call(this);
620
629
  return s;
630
+ }, Et = function() {
631
+ let e = d(this, w).cstring(), t = d(this, w).int32(), n = d(this, w).int16(), r = d(this, w).int32(), s = d(this, w).int16(), a = d(this, w).int32(), o = d(this, w).int16() === 0 ? at.text : at.binary;
632
+ return new pn(e, t, n, r, s, a, o);
621
633
  }, mt = function(e, t, n) {
622
- f(this, w).setBuffer(e, n);
623
- let r = f(this, w).int16(), s = new Array(r);
634
+ d(this, w).setBuffer(e, n);
635
+ let r = d(this, w).int16(), s = new mn(t, r);
636
+ for (let a = 0; a < r; a++) s.dataTypeIDs[a] = d(this, w).int32();
637
+ return s;
638
+ }, yt = function(e, t, n) {
639
+ d(this, w).setBuffer(e, n);
640
+ let r = d(this, w).int16(), s = new Array(r);
624
641
  for (let a = 0; a < r; a++) {
625
- let i = f(this, w).int32();
626
- s[a] = i === -1 ? null : f(this, w).string(i);
642
+ let o = d(this, w).int32();
643
+ s[a] = o === -1 ? null : d(this, w).string(o);
627
644
  }
628
- return new wn(t, s);
629
- }, yt = function(e, t, n) {
630
- f(this, w).setBuffer(e, n);
631
- let r = f(this, w).cstring(), s = f(this, w).cstring();
632
- return new mn(t, r, s);
633
- }, _t = function(e, t, n) {
634
- f(this, w).setBuffer(e, n);
635
- let r = f(this, w).int32(), s = f(this, w).int32();
636
- return new yn(t, r, s);
645
+ return new Nn(t, s);
637
646
  }, gt = function(e, t, n) {
638
- f(this, w).setBuffer(e, n);
639
- let r = f(this, w).int32();
647
+ d(this, w).setBuffer(e, n);
648
+ let r = d(this, w).cstring(), s = d(this, w).cstring();
649
+ return new yn(t, r, s);
650
+ }, _t = function(e, t, n) {
651
+ d(this, w).setBuffer(e, n);
652
+ let r = d(this, w).int32(), s = d(this, w).int32();
653
+ return new gn(t, r, s);
654
+ }, Tt = function(e, t, n) {
655
+ d(this, w).setBuffer(e, n);
656
+ let r = d(this, w).int32();
640
657
  switch (r) {
641
658
  case 0:
642
- return new rn(t);
643
- case 3:
644
659
  return new an(t);
660
+ case 3:
661
+ return new on(t);
645
662
  case 5:
646
- return new on(t, f(this, w).bytes(4));
663
+ return new cn(t, d(this, w).bytes(4));
647
664
  case 10: {
648
665
  let s = [];
649
666
  for (; ; ) {
650
- let a = f(this, w).cstring();
651
- if (a.length === 0) return new cn(t, s);
667
+ let a = d(this, w).cstring();
668
+ if (a.length === 0) return new ln(t, s);
652
669
  s.push(a);
653
670
  }
654
671
  }
655
672
  case 11:
656
- return new ln(t, f(this, w).string(t - 8));
673
+ return new un(t, d(this, w).string(t - 8));
657
674
  case 12:
658
- return new un(t, f(this, w).string(t - 8));
675
+ return new hn(t, d(this, w).string(t - 8));
659
676
  default:
660
677
  throw new Error("Unknown authenticationOk message type " + r);
661
678
  }
662
- }, De = function(e, t, n, r) {
663
- f(this, w).setBuffer(e, n);
664
- let s = {}, a = f(this, w).string(1);
665
- for (; a !== "\0"; ) s[a] = f(this, w).cstring(), a = f(this, w).string(1);
666
- let i = s.M, o = r === "notice" ? new Nn(t, i) : new Fe(i, t, r);
667
- return o.severity = s.S, o.code = s.C, o.detail = s.D, o.hint = s.H, o.position = s.P, o.internalPosition = s.p, o.internalQuery = s.q, o.where = s.W, o.schema = s.s, o.table = s.t, o.column = s.c, o.dataType = s.d, o.constraint = s.n, o.file = s.F, o.line = s.L, o.routine = s.R, o;
679
+ }, ve = function(e, t, n, r) {
680
+ d(this, w).setBuffer(e, n);
681
+ let s = {}, a = d(this, w).string(1);
682
+ for (; a !== "\0"; ) s[a] = d(this, w).cstring(), a = d(this, w).string(1);
683
+ let o = s.M, i = r === "notice" ? new An(t, o) : new Be(o, t, r);
684
+ return i.severity = s.S, i.code = s.C, i.detail = s.D, i.hint = s.H, i.position = s.P, i.internalPosition = s.p, i.internalQuery = s.q, i.where = s.W, i.schema = s.s, i.table = s.t, i.column = s.c, i.dataType = s.d, i.constraint = s.n, i.file = s.F, i.line = s.L, i.routine = s.R, i;
668
685
  };
669
686
  H();
670
687
  typeof process == "object" && typeof process.versions == "object" && process.versions.node;
671
- var Tt = () => {
688
+ var wt = () => {
672
689
  if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
673
690
  let e = new Uint8Array(16);
674
691
  if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(e);
@@ -679,265 +696,265 @@ var Tt = () => {
679
696
  t.push(n.toString(16).padStart(2, "0"));
680
697
  }), t.slice(0, 4).join("") + "-" + t.slice(4, 6).join("") + "-" + t.slice(6, 8).join("") + "-" + t.slice(8, 10).join("") + "-" + t.slice(10).join("");
681
698
  };
682
- async function wt(e, t, n, r) {
699
+ async function Nt(e, t, n, r) {
683
700
  if (!n || n.length === 0) return t;
684
701
  r = r ?? e;
685
702
  let s = [];
686
703
  try {
687
- await e.execProtocol(re.parse({ text: t }), { syncToFs: !1 }), s.push(...(await e.execProtocol(re.describe({ type: "S" }), { syncToFs: !1 })).messages);
704
+ await e.execProtocol(oe.parse({ text: t }), { syncToFs: !1 }), s.push(...(await e.execProtocol(oe.describe({ type: "S" }), { syncToFs: !1 })).messages);
688
705
  } finally {
689
- s.push(...(await e.execProtocol(re.sync(), { syncToFs: !1 })).messages);
706
+ s.push(...(await e.execProtocol(oe.sync(), { syncToFs: !1 })).messages);
690
707
  }
691
- let a = Jt(s), i = t.replace(/\$([0-9]+)/g, (o, c) => "%" + c + "L");
692
- return (await r.query(`SELECT format($1, ${n.map((o, c) => `$${c + 2}`).join(", ")}) as query`, [i, ...n], { paramTypes: [ce, ...a] })).rows[0].query;
708
+ let a = Yt(s), o = t.replace(/\$([0-9]+)/g, (i, c) => "%" + c + "L");
709
+ return (await r.query(`SELECT format($1, ${n.map((i, c) => `$${c + 2}`).join(", ")}) as query`, [o, ...n], { paramTypes: [he, ...a] })).rows[0].query;
693
710
  }
694
- function Nt(e) {
711
+ function At(e) {
695
712
  let t, n = !1, r = async () => {
696
713
  if (!t) {
697
714
  n = !1;
698
715
  return;
699
716
  }
700
717
  n = !0;
701
- let { args: s, resolve: a, reject: i } = t;
718
+ let { args: s, resolve: a, reject: o } = t;
702
719
  t = void 0;
703
720
  try {
704
- let o = await e(...s);
705
- a(o);
706
- } catch (o) {
707
- i(o);
721
+ let i = await e(...s);
722
+ a(i);
723
+ } catch (i) {
724
+ o(i);
708
725
  } finally {
709
726
  r();
710
727
  }
711
728
  };
712
729
  return async (...s) => {
713
730
  t && t.resolve(void 0);
714
- let a = new Promise((i, o) => {
715
- t = { args: s, resolve: i, reject: o };
731
+ let a = new Promise((o, i) => {
732
+ t = { args: s, resolve: o, reject: i };
716
733
  });
717
734
  return n || r(), a;
718
735
  };
719
736
  }
720
737
  H();
721
- var Cr = 5, Lr = async (e, t) => {
722
- let n = /* @__PURE__ */ new Set(), r = { async query(s, a, i) {
723
- let o, c, u;
724
- if (typeof s != "string" && (o = s.signal, a = s.params, i = s.callback, c = s.offset, u = s.limit, s = s.query), c === void 0 != (u === void 0)) throw new Error("offset and limit must be provided together");
725
- let l = c !== void 0 && u !== void 0, p;
726
- if (l && (typeof c != "number" || isNaN(c) || typeof u != "number" || isNaN(u))) throw new Error("offset and limit must be numbers");
727
- let h = i ? [i] : [], d = Tt().replace(/-/g, ""), y = !1, A, $, R = async () => {
728
- await e.transaction(async (T) => {
729
- let b = a && a.length > 0 ? await wt(e, s, a, T) : s;
730
- await T.exec(`CREATE OR REPLACE TEMP VIEW live_query_${d}_view AS ${b}`);
731
- let S = await $t(T, `live_query_${d}_view`);
732
- await At(T, S, n), l ? (await T.exec(`
733
- PREPARE live_query_${d}_get(int, int) AS
734
- SELECT * FROM live_query_${d}_view
738
+ var vr = 5, Mr = async (e, t) => {
739
+ let n = /* @__PURE__ */ new Set(), r = { async query(s, a, o) {
740
+ let i, c, l;
741
+ if (typeof s != "string" && (i = s.signal, a = s.params, o = s.callback, c = s.offset, l = s.limit, s = s.query), c === void 0 != (l === void 0)) throw new Error("offset and limit must be provided together");
742
+ let u = c !== void 0 && l !== void 0, h;
743
+ if (u && (typeof c != "number" || isNaN(c) || typeof l != "number" || isNaN(l))) throw new Error("offset and limit must be numbers");
744
+ let p = o ? [o] : [], f = wt().replace(/-/g, ""), E = !1, $, A, b = async () => {
745
+ await e.transaction(async (g) => {
746
+ let S = a && a.length > 0 ? await Nt(e, s, a, g) : s;
747
+ await g.exec(`CREATE OR REPLACE TEMP VIEW live_query_${f}_view AS ${S}`);
748
+ let I = await $t(g, `live_query_${f}_view`);
749
+ await bt(g, I, n), u ? (await g.exec(`
750
+ PREPARE live_query_${f}_get(int, int) AS
751
+ SELECT * FROM live_query_${f}_view
735
752
  LIMIT $1 OFFSET $2;
736
- `), await T.exec(`
737
- PREPARE live_query_${d}_get_total_count AS
738
- SELECT COUNT(*) FROM live_query_${d}_view;
739
- `), p = (await T.query(`EXECUTE live_query_${d}_get_total_count;`)).rows[0].count, A = { ...await T.query(`EXECUTE live_query_${d}_get(${u}, ${c});`), offset: c, limit: u, totalCount: p }) : (await T.exec(`
740
- PREPARE live_query_${d}_get AS
741
- SELECT * FROM live_query_${d}_view;
742
- `), A = await T.query(`EXECUTE live_query_${d}_get;`)), $ = await Promise.all(S.map((m) => T.listen(`"table_change__${m.schema_oid}__${m.table_oid}"`, async () => {
743
- I();
753
+ `), await g.exec(`
754
+ PREPARE live_query_${f}_get_total_count AS
755
+ SELECT COUNT(*) FROM live_query_${f}_view;
756
+ `), h = (await g.query(`EXECUTE live_query_${f}_get_total_count;`)).rows[0].count, $ = { ...await g.query(`EXECUTE live_query_${f}_get(${l}, ${c});`), offset: c, limit: l, totalCount: h }) : (await g.exec(`
757
+ PREPARE live_query_${f}_get AS
758
+ SELECT * FROM live_query_${f}_view;
759
+ `), $ = await g.query(`EXECUTE live_query_${f}_get;`)), A = await Promise.all(I.map((T) => g.listen(`"table_change__${T.schema_oid}__${T.table_oid}"`, async () => {
760
+ R();
744
761
  })));
745
762
  });
746
763
  };
747
- await R();
748
- let I = Nt(async ({ offset: T, limit: b } = {}) => {
749
- if (!l && (T !== void 0 || b !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
750
- if (T && (typeof T != "number" || isNaN(T)) || b && (typeof b != "number" || isNaN(b))) throw new Error("offset and limit must be numbers");
751
- c = T ?? c, u = b ?? u;
752
- let S = async (m = 0) => {
753
- if (h.length !== 0) {
764
+ await b();
765
+ let R = At(async ({ offset: g, limit: S } = {}) => {
766
+ if (!u && (g !== void 0 || S !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
767
+ if (g && (typeof g != "number" || isNaN(g)) || S && (typeof S != "number" || isNaN(S))) throw new Error("offset and limit must be numbers");
768
+ c = g ?? c, l = S ?? l;
769
+ let I = async (T = 0) => {
770
+ if (p.length !== 0) {
754
771
  try {
755
- l ? A = { ...await e.query(`EXECUTE live_query_${d}_get(${u}, ${c});`), offset: c, limit: u, totalCount: p } : A = await e.query(`EXECUTE live_query_${d}_get;`);
756
- } catch (g) {
757
- let k = g.message;
758
- if (k.startsWith(`prepared statement "live_query_${d}`) && k.endsWith("does not exist")) {
759
- if (m > Cr) throw g;
760
- await R(), S(m + 1);
761
- } else throw g;
772
+ u ? $ = { ...await e.query(`EXECUTE live_query_${f}_get(${l}, ${c});`), offset: c, limit: l, totalCount: h } : $ = await e.query(`EXECUTE live_query_${f}_get;`);
773
+ } catch (N) {
774
+ let k = N.message;
775
+ if (k.startsWith(`prepared statement "live_query_${f}`) && k.endsWith("does not exist")) {
776
+ if (T > vr) throw N;
777
+ await b(), I(T + 1);
778
+ } else throw N;
762
779
  }
763
- if (se(h, A), l) {
764
- let g = (await e.query(`EXECUTE live_query_${d}_get_total_count;`)).rows[0].count;
765
- g !== p && (p = g, I());
780
+ if (ie(p, $), u) {
781
+ let N = (await e.query(`EXECUTE live_query_${f}_get_total_count;`)).rows[0].count;
782
+ N !== h && (h = N, R());
766
783
  }
767
784
  }
768
785
  };
769
- await S();
770
- }), E = (T) => {
771
- if (y) throw new Error("Live query is no longer active and cannot be subscribed to");
772
- h.push(T);
773
- }, _ = async (T) => {
774
- T ? h = h.filter((b) => b !== b) : h = [], h.length === 0 && !y && (y = !0, await e.transaction(async (b) => {
775
- await Promise.all($.map((S) => S(b))), await b.exec(`
776
- DROP VIEW IF EXISTS live_query_${d}_view;
777
- DEALLOCATE live_query_${d}_get;
786
+ await I();
787
+ }), m = (g) => {
788
+ if (E) throw new Error("Live query is no longer active and cannot be subscribed to");
789
+ p.push(g);
790
+ }, y = async (g) => {
791
+ g ? p = p.filter((S) => S !== S) : p = [], p.length === 0 && !E && (E = !0, await e.transaction(async (S) => {
792
+ await Promise.all(A.map((I) => I(S))), await S.exec(`
793
+ DROP VIEW IF EXISTS live_query_${f}_view;
794
+ DEALLOCATE live_query_${f}_get;
778
795
  `);
779
796
  }));
780
797
  };
781
- return o?.aborted ? await _() : o?.addEventListener("abort", () => {
782
- _();
783
- }, { once: !0 }), se(h, A), { initialResults: A, subscribe: E, unsubscribe: _, refresh: I };
784
- }, async changes(s, a, i, o) {
798
+ return i?.aborted ? await y() : i?.addEventListener("abort", () => {
799
+ y();
800
+ }, { once: !0 }), ie(p, $), { initialResults: $, subscribe: m, unsubscribe: y, refresh: R };
801
+ }, async changes(s, a, o, i) {
785
802
  let c;
786
- if (typeof s != "string" && (c = s.signal, a = s.params, i = s.key, o = s.callback, s = s.query), !i) throw new Error("key is required for changes queries");
787
- let u = o ? [o] : [], l = Tt().replace(/-/g, ""), p = !1, h = 1, d, y, A = async () => {
788
- await e.transaction(async (E) => {
789
- let _ = await wt(e, s, a, E);
790
- await E.query(`CREATE OR REPLACE TEMP VIEW live_query_${l}_view AS ${_}`);
791
- let T = await $t(E, `live_query_${l}_view`);
792
- await At(E, T, n);
793
- let b = [...(await E.query(`
803
+ if (typeof s != "string" && (c = s.signal, a = s.params, o = s.key, i = s.callback, s = s.query), !o) throw new Error("key is required for changes queries");
804
+ let l = i ? [i] : [], u = wt().replace(/-/g, ""), h = !1, p = 1, f, E, $ = async () => {
805
+ await e.transaction(async (m) => {
806
+ let y = await Nt(e, s, a, m);
807
+ await m.query(`CREATE OR REPLACE TEMP VIEW live_query_${u}_view AS ${y}`);
808
+ let g = await $t(m, `live_query_${u}_view`);
809
+ await bt(m, g, n);
810
+ let S = [...(await m.query(`
794
811
  SELECT column_name, data_type, udt_name
795
812
  FROM information_schema.columns
796
- WHERE table_name = 'live_query_${l}_view'
813
+ WHERE table_name = 'live_query_${u}_view'
797
814
  `)).rows, { column_name: "__after__", data_type: "integer" }];
798
- await E.exec(`
799
- CREATE TEMP TABLE live_query_${l}_state1 (LIKE live_query_${l}_view INCLUDING ALL);
800
- CREATE TEMP TABLE live_query_${l}_state2 (LIKE live_query_${l}_view INCLUDING ALL);
815
+ await m.exec(`
816
+ CREATE TEMP TABLE live_query_${u}_state1 (LIKE live_query_${u}_view INCLUDING ALL);
817
+ CREATE TEMP TABLE live_query_${u}_state2 (LIKE live_query_${u}_view INCLUDING ALL);
801
818
  `);
802
- for (let S of [1, 2]) {
803
- let m = S === 1 ? 2 : 1;
804
- await E.exec(`
805
- PREPARE live_query_${l}_diff${S} AS
819
+ for (let I of [1, 2]) {
820
+ let T = I === 1 ? 2 : 1;
821
+ await m.exec(`
822
+ PREPARE live_query_${u}_diff${I} AS
806
823
  WITH
807
- prev AS (SELECT LAG("${i}") OVER () as __after__, * FROM live_query_${l}_state${m}),
808
- curr AS (SELECT LAG("${i}") OVER () as __after__, * FROM live_query_${l}_state${S}),
824
+ prev AS (SELECT LAG("${o}") OVER () as __after__, * FROM live_query_${u}_state${T}),
825
+ curr AS (SELECT LAG("${o}") OVER () as __after__, * FROM live_query_${u}_state${I}),
809
826
  data_diff AS (
810
827
  -- INSERT operations: Include all columns
811
828
  SELECT
812
829
  'INSERT' AS __op__,
813
- ${b.map(({ column_name: g }) => `curr."${g}" AS "${g}"`).join(`,
830
+ ${S.map(({ column_name: N }) => `curr."${N}" AS "${N}"`).join(`,
814
831
  `)},
815
832
  ARRAY[]::text[] AS __changed_columns__
816
833
  FROM curr
817
- LEFT JOIN prev ON curr.${i} = prev.${i}
818
- WHERE prev.${i} IS NULL
834
+ LEFT JOIN prev ON curr.${o} = prev.${o}
835
+ WHERE prev.${o} IS NULL
819
836
  UNION ALL
820
837
  -- DELETE operations: Include only the primary key
821
838
  SELECT
822
839
  'DELETE' AS __op__,
823
- ${b.map(({ column_name: g, data_type: k, udt_name: Q }) => g === i ? `prev."${g}" AS "${g}"` : `NULL${k === "USER-DEFINED" ? `::${Q}` : ""} AS "${g}"`).join(`,
840
+ ${S.map(({ column_name: N, data_type: k, udt_name: Q }) => N === o ? `prev."${N}" AS "${N}"` : `NULL${k === "USER-DEFINED" ? `::${Q}` : ""} AS "${N}"`).join(`,
824
841
  `)},
825
842
  ARRAY[]::text[] AS __changed_columns__
826
843
  FROM prev
827
- LEFT JOIN curr ON prev.${i} = curr.${i}
828
- WHERE curr.${i} IS NULL
844
+ LEFT JOIN curr ON prev.${o} = curr.${o}
845
+ WHERE curr.${o} IS NULL
829
846
  UNION ALL
830
847
  -- UPDATE operations: Include only changed columns
831
848
  SELECT
832
849
  'UPDATE' AS __op__,
833
- ${b.map(({ column_name: g, data_type: k, udt_name: Q }) => g === i ? `curr."${g}" AS "${g}"` : `CASE
834
- WHEN curr."${g}" IS DISTINCT FROM prev."${g}"
835
- THEN curr."${g}"
850
+ ${S.map(({ column_name: N, data_type: k, udt_name: Q }) => N === o ? `curr."${N}" AS "${N}"` : `CASE
851
+ WHEN curr."${N}" IS DISTINCT FROM prev."${N}"
852
+ THEN curr."${N}"
836
853
  ELSE NULL${k === "USER-DEFINED" ? `::${Q}` : ""}
837
- END AS "${g}"`).join(`,
854
+ END AS "${N}"`).join(`,
838
855
  `)},
839
- ARRAY(SELECT unnest FROM unnest(ARRAY[${b.filter(({ column_name: g }) => g !== i).map(({ column_name: g }) => `CASE
840
- WHEN curr."${g}" IS DISTINCT FROM prev."${g}"
841
- THEN '${g}'
856
+ ARRAY(SELECT unnest FROM unnest(ARRAY[${S.filter(({ column_name: N }) => N !== o).map(({ column_name: N }) => `CASE
857
+ WHEN curr."${N}" IS DISTINCT FROM prev."${N}"
858
+ THEN '${N}'
842
859
  ELSE NULL
843
860
  END`).join(", ")}]) WHERE unnest IS NOT NULL) AS __changed_columns__
844
861
  FROM curr
845
- INNER JOIN prev ON curr.${i} = prev.${i}
862
+ INNER JOIN prev ON curr.${o} = prev.${o}
846
863
  WHERE NOT (curr IS NOT DISTINCT FROM prev)
847
864
  )
848
865
  SELECT * FROM data_diff;
849
866
  `);
850
867
  }
851
- y = await Promise.all(T.map((S) => E.listen(`"table_change__${S.schema_oid}__${S.table_oid}"`, async () => {
852
- $();
868
+ E = await Promise.all(g.map((I) => m.listen(`"table_change__${I.schema_oid}__${I.table_oid}"`, async () => {
869
+ A();
853
870
  })));
854
871
  });
855
872
  };
856
- await A();
857
- let $ = Nt(async () => {
858
- if (u.length === 0 && d) return;
859
- let E = !1;
860
- for (let _ = 0; _ < 5; _++) try {
861
- await e.transaction(async (T) => {
862
- await T.exec(`
863
- INSERT INTO live_query_${l}_state${h}
864
- SELECT * FROM live_query_${l}_view;
865
- `), d = await T.query(`EXECUTE live_query_${l}_diff${h};`), h = h === 1 ? 2 : 1, await T.exec(`
866
- TRUNCATE live_query_${l}_state${h};
873
+ await $();
874
+ let A = At(async () => {
875
+ if (l.length === 0 && f) return;
876
+ let m = !1;
877
+ for (let y = 0; y < 5; y++) try {
878
+ await e.transaction(async (g) => {
879
+ await g.exec(`
880
+ INSERT INTO live_query_${u}_state${p}
881
+ SELECT * FROM live_query_${u}_view;
882
+ `), f = await g.query(`EXECUTE live_query_${u}_diff${p};`), p = p === 1 ? 2 : 1, await g.exec(`
883
+ TRUNCATE live_query_${u}_state${p};
867
884
  `);
868
885
  });
869
886
  break;
870
- } catch (T) {
871
- if (T.message === `relation "live_query_${l}_state${h}" does not exist`) {
872
- E = !0, await A();
887
+ } catch (g) {
888
+ if (g.message === `relation "live_query_${u}_state${p}" does not exist`) {
889
+ m = !0, await $();
873
890
  continue;
874
- } else throw T;
891
+ } else throw g;
875
892
  }
876
- qr(u, [...E ? [{ __op__: "RESET" }] : [], ...d.rows]);
877
- }), R = (E) => {
878
- if (p) throw new Error("Live query is no longer active and cannot be subscribed to");
879
- u.push(E);
880
- }, I = async (E) => {
881
- E ? u = u.filter((_) => _ !== _) : u = [], u.length === 0 && !p && (p = !0, await e.transaction(async (_) => {
882
- await Promise.all(y.map((T) => T(_))), await _.exec(`
883
- DROP VIEW IF EXISTS live_query_${l}_view;
884
- DROP TABLE IF EXISTS live_query_${l}_state1;
885
- DROP TABLE IF EXISTS live_query_${l}_state2;
886
- DEALLOCATE live_query_${l}_diff1;
887
- DEALLOCATE live_query_${l}_diff2;
893
+ Pr(l, [...m ? [{ __op__: "RESET" }] : [], ...f.rows]);
894
+ }), b = (m) => {
895
+ if (h) throw new Error("Live query is no longer active and cannot be subscribed to");
896
+ l.push(m);
897
+ }, R = async (m) => {
898
+ m ? l = l.filter((y) => y !== y) : l = [], l.length === 0 && !h && (h = !0, await e.transaction(async (y) => {
899
+ await Promise.all(E.map((g) => g(y))), await y.exec(`
900
+ DROP VIEW IF EXISTS live_query_${u}_view;
901
+ DROP TABLE IF EXISTS live_query_${u}_state1;
902
+ DROP TABLE IF EXISTS live_query_${u}_state2;
903
+ DEALLOCATE live_query_${u}_diff1;
904
+ DEALLOCATE live_query_${u}_diff2;
888
905
  `);
889
906
  }));
890
907
  };
891
- return c?.aborted ? await I() : c?.addEventListener("abort", () => {
892
- I();
893
- }, { once: !0 }), await $(), { fields: d.fields.filter((E) => !["__after__", "__op__", "__changed_columns__"].includes(E.name)), initialChanges: d.rows, subscribe: R, unsubscribe: I, refresh: $ };
894
- }, async incrementalQuery(s, a, i, o) {
908
+ return c?.aborted ? await R() : c?.addEventListener("abort", () => {
909
+ R();
910
+ }, { once: !0 }), await A(), { fields: f.fields.filter((m) => !["__after__", "__op__", "__changed_columns__"].includes(m.name)), initialChanges: f.rows, subscribe: b, unsubscribe: R, refresh: A };
911
+ }, async incrementalQuery(s, a, o, i) {
895
912
  let c;
896
- if (typeof s != "string" && (c = s.signal, a = s.params, i = s.key, o = s.callback, s = s.query), !i) throw new Error("key is required for incremental queries");
897
- let u = o ? [o] : [], l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), h = [], d = !0, { fields: y, unsubscribe: A, refresh: $ } = await r.changes(s, a, i, (E) => {
898
- for (let b of E) {
899
- let { __op__: S, __changed_columns__: m, ...g } = b;
900
- switch (S) {
913
+ if (typeof s != "string" && (c = s.signal, a = s.params, o = s.key, i = s.callback, s = s.query), !o) throw new Error("key is required for incremental queries");
914
+ let l = i ? [i] : [], u = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), p = [], f = !0, { fields: E, unsubscribe: $, refresh: A } = await r.changes(s, a, o, (m) => {
915
+ for (let S of m) {
916
+ let { __op__: I, __changed_columns__: T, ...N } = S;
917
+ switch (I) {
901
918
  case "RESET":
902
- l.clear(), p.clear();
919
+ u.clear(), h.clear();
903
920
  break;
904
921
  case "INSERT":
905
- l.set(g[i], g), p.set(g.__after__, g[i]);
922
+ u.set(N[o], N), h.set(N.__after__, N[o]);
906
923
  break;
907
924
  case "DELETE": {
908
- let k = l.get(g[i]);
909
- l.delete(g[i]), k.__after__ !== null && p.delete(k.__after__);
925
+ let k = u.get(N[o]);
926
+ u.delete(N[o]), k.__after__ !== null && h.delete(k.__after__);
910
927
  break;
911
928
  }
912
929
  case "UPDATE": {
913
- let k = { ...l.get(g[i]) ?? {} };
914
- for (let Q of m) k[Q] = g[Q], Q === "__after__" && p.set(g.__after__, g[i]);
915
- l.set(g[i], k);
930
+ let k = { ...u.get(N[o]) ?? {} };
931
+ for (let Q of T) k[Q] = N[Q], Q === "__after__" && h.set(N.__after__, N[o]);
932
+ u.set(N[o], k);
916
933
  break;
917
934
  }
918
935
  }
919
936
  }
920
- let _ = [], T = null;
921
- for (let b = 0; b < l.size; b++) {
922
- let S = p.get(T), m = l.get(S);
923
- if (!m) break;
924
- let g = { ...m };
925
- delete g.__after__, _.push(g), T = S;
937
+ let y = [], g = null;
938
+ for (let S = 0; S < u.size; S++) {
939
+ let I = h.get(g), T = u.get(I);
940
+ if (!T) break;
941
+ let N = { ...T };
942
+ delete N.__after__, y.push(N), g = I;
926
943
  }
927
- h = _, d || se(u, { rows: _, fields: y });
944
+ p = y, f || ie(l, { rows: y, fields: E });
928
945
  });
929
- d = !1, se(u, { rows: h, fields: y });
930
- let R = (E) => {
931
- u.push(E);
932
- }, I = async (E) => {
933
- E ? u = u.filter((_) => _ !== _) : u = [], u.length === 0 && await A();
946
+ f = !1, ie(l, { rows: p, fields: E });
947
+ let b = (m) => {
948
+ l.push(m);
949
+ }, R = async (m) => {
950
+ m ? l = l.filter((y) => y !== y) : l = [], l.length === 0 && await $();
934
951
  };
935
- return c?.aborted ? await I() : c?.addEventListener("abort", () => {
936
- I();
937
- }, { once: !0 }), { initialResults: { rows: h, fields: y }, subscribe: R, unsubscribe: I, refresh: $ };
952
+ return c?.aborted ? await R() : c?.addEventListener("abort", () => {
953
+ R();
954
+ }, { once: !0 }), { initialResults: { rows: p, fields: E }, subscribe: b, unsubscribe: R, refresh: A };
938
955
  } };
939
956
  return { namespaceObj: r };
940
- }, Mr = { name: "Live Queries", setup: Lr };
957
+ }, qr = { name: "Live Queries", setup: Mr };
941
958
  async function $t(e, t) {
942
959
  return (await e.query(`
943
960
  WITH RECURSIVE view_dependencies AS (
@@ -985,7 +1002,7 @@ async function $t(e, t) {
985
1002
  WHERE NOT is_view; -- Exclude intermediate views
986
1003
  `, [t])).rows.map((n) => ({ table_name: n.table_name, schema_name: n.schema_name, table_oid: n.table_oid, schema_oid: n.schema_oid }));
987
1004
  }
988
- async function At(e, t, n) {
1005
+ async function bt(e, t, n) {
989
1006
  let r = t.filter((s) => !n.has(`${s.schema_oid}_${s.table_oid}`)).map((s) => `
990
1007
  CREATE OR REPLACE FUNCTION "_notify_${s.schema_oid}_${s.table_oid}"() RETURNS TRIGGER AS $$
991
1008
  BEGIN
@@ -1000,32 +1017,32 @@ async function At(e, t, n) {
1000
1017
  `);
1001
1018
  r.trim() !== "" && await e.exec(r), t.map((s) => n.add(`${s.schema_oid}_${s.table_oid}`));
1002
1019
  }
1003
- var se = (e, t) => {
1020
+ var ie = (e, t) => {
1004
1021
  for (let n of e) n(t);
1005
- }, qr = (e, t) => {
1022
+ }, Pr = (e, t) => {
1006
1023
  for (let n of e) n(t);
1007
1024
  };
1008
- class Rt extends kn {
1025
+ class Rt extends Wn {
1009
1026
  #e;
1010
1027
  #s;
1011
- #i = 16;
1028
+ #o = 16;
1012
1029
  // 批量发送间隔 (ms)
1013
1030
  #t = [];
1014
1031
  #r;
1015
1032
  async init(t, n) {
1016
- this.#s = t, this.#e = new Vn({
1033
+ this.#s = t, this.#e = new Kn({
1017
1034
  ...n,
1018
1035
  dataDir: n.store === "memory" ? void 0 : `idb://${t}`,
1019
1036
  database: t,
1020
1037
  extensions: {
1021
- live: Mr
1038
+ live: qr
1022
1039
  }
1023
1040
  }), await this.#e.waitReady;
1024
1041
  const r = ["rxdb_change", "rxdb_branch", "rxdb_migration"];
1025
1042
  for (const s of r)
1026
1043
  await this.#e.exec(`LISTEN "${s}_notify"`);
1027
1044
  this.#e.onNotification((s, a) => {
1028
- this.#o(s, a);
1045
+ this.#c(s, a);
1029
1046
  });
1030
1047
  }
1031
1048
  sql(t, ...n) {
@@ -1057,7 +1074,7 @@ class Rt extends kn {
1057
1074
  * @param channel - 通知频道名称
1058
1075
  * @param payload - JSON 格式的 payload
1059
1076
  */
1060
- #o(t, n) {
1077
+ #c(t, n) {
1061
1078
  try {
1062
1079
  const r = JSON.parse(n), s = t.replace("_notify", "");
1063
1080
  for (const a of r.ids)
@@ -1068,7 +1085,7 @@ class Rt extends kn {
1068
1085
  });
1069
1086
  this.#r && clearTimeout(this.#r), this.#r = setTimeout(() => {
1070
1087
  this.#a(), this.#r = void 0;
1071
- }, this.#i);
1088
+ }, this.#o);
1072
1089
  } catch (r) {
1073
1090
  console.error("Failed to parse NOTIFY payload:", r);
1074
1091
  }
@@ -1080,7 +1097,7 @@ class Rt extends kn {
1080
1097
  const t = Object.groupBy(this.#t, (n) => `${n.type}_${n.tableName}`);
1081
1098
  for (const [, n] of Object.entries(t)) {
1082
1099
  if (!n || n.length === 0) continue;
1083
- const r = n[0], s = n.map((i) => i.id), a = {
1100
+ const r = n[0], s = n.map((o) => o.id), a = {
1084
1101
  type: r.type,
1085
1102
  dbName: this.#s,
1086
1103
  tableName: r.tableName,
@@ -1092,32 +1109,32 @@ class Rt extends kn {
1092
1109
  this.#t.length = 0;
1093
1110
  }
1094
1111
  }
1095
- const bn = (e, t) => {
1112
+ const Sn = (e, t) => {
1096
1113
  const n = P(e), r = t.map((s) => `'${s.id}'`).join(",");
1097
1114
  return `DELETE FROM ${n} WHERE id IN (${r});`;
1098
- }, ue = (e, t, n) => {
1099
- const r = P(e), s = n?.userId && e.propertyMap.has("createdBy"), a = n?.userId && e.propertyMap.has("updatedBy"), i = [
1100
- ...Array.from(e.propertyMap.values()).map((u) => u.columnName),
1115
+ }, de = (e, t, n) => {
1116
+ const r = P(e), s = n?.userId && e.propertyMap.has("createdBy"), a = n?.userId && e.propertyMap.has("updatedBy"), o = [
1117
+ ...Array.from(e.propertyMap.values()).map((l) => l.columnName),
1101
1118
  ...e.foreignKeyColumnNames || e.foreignKeyNames
1102
- ], o = [];
1103
- t.forEach((u) => {
1104
- const l = Ct(e, u);
1105
- s && (l.createdBy = n.userId), a && (l.updatedBy = n.userId);
1106
- const p = Ke(e, l), h = [];
1107
- i.forEach((d) => {
1108
- const y = p[d];
1109
- h.push(Je(y));
1110
- }), o.push(`(${h.join(",")})`);
1119
+ ], i = [];
1120
+ t.forEach((l) => {
1121
+ const u = vt(e, l);
1122
+ s && (u.createdBy = n.userId), a && (u.updatedBy = n.userId);
1123
+ const h = Je(e, u), p = [];
1124
+ o.forEach((f) => {
1125
+ const E = h[f];
1126
+ p.push(Ye(E));
1127
+ }), i.push(`(${p.join(",")})`);
1111
1128
  });
1112
- const c = i.map((u) => `"${u}"`).join(",");
1113
- return `INSERT INTO ${r} (${c}) VALUES ${o.join(",")};`;
1114
- }, Pr = (e) => {
1129
+ const c = o.map((l) => `"${l}"`).join(",");
1130
+ return `INSERT INTO ${r} (${c}) VALUES ${i.join(",")};`;
1131
+ }, Ur = (e) => {
1115
1132
  if (e.includes("$")) {
1116
1133
  const [t, n] = e.split("$");
1117
1134
  return [t, n];
1118
1135
  }
1119
1136
  return ["public", e];
1120
- }, Ur = (e) => {
1137
+ }, jr = (e) => {
1121
1138
  switch (e) {
1122
1139
  case K.INSERT:
1123
1140
  return "INSERT";
@@ -1126,20 +1143,20 @@ const bn = (e, t) => {
1126
1143
  case K.DELETE:
1127
1144
  return "DELETE";
1128
1145
  }
1129
- }, jr = (e, t) => {
1146
+ }, xr = (e, t) => {
1130
1147
  t.forEach((s) => {
1131
1148
  if (!s.namespace || !s.entity) {
1132
1149
  console.warn(`RxDBChange record missing namespace or entity: id=${s.id}`);
1133
1150
  return;
1134
1151
  }
1135
1152
  const a = e.rxdb.schemaManager.getEntityMetadata(s.entity, s.namespace);
1136
- a ? (s.inversePatch && st(a, s.inversePatch), s.patch && st(a, s.patch)) : console.warn(`Entity metadata not found for ${s.namespace}.${s.entity}`);
1153
+ a ? (s.inversePatch && rt(a, s.inversePatch), s.patch && rt(a, s.patch)) : console.warn(`Entity metadata not found for ${s.namespace}.${s.entity}`);
1137
1154
  });
1138
1155
  const n = Object.groupBy(t, (s) => s.type), r = Object.entries(n);
1139
1156
  for (let s = 0; s < r.length; s++) {
1140
- const [a, i] = r[s];
1141
- if (!i || i.length === 0) continue;
1142
- const o = i.filter((c) => c.namespace && c.entity).map(
1157
+ const [a, o] = r[s];
1158
+ if (!o || o.length === 0) continue;
1159
+ const i = o.filter((c) => c.namespace && c.entity).map(
1143
1160
  (c) => ({
1144
1161
  namespace: c.namespace,
1145
1162
  entity: c.entity,
@@ -1150,89 +1167,89 @@ const bn = (e, t) => {
1150
1167
  recordAt: c.createdAt
1151
1168
  })
1152
1169
  );
1153
- if (o.length !== 0)
1170
+ if (i.length !== 0)
1154
1171
  switch (a) {
1155
1172
  case "INSERT":
1156
- e.rxdb.dispatchEvent(new oe(o));
1173
+ e.rxdb.dispatchEvent(new ue(i));
1157
1174
  break;
1158
1175
  case "UPDATE":
1159
- e.rxdb.dispatchEvent(new me(o));
1176
+ e.rxdb.dispatchEvent(new ge(i));
1160
1177
  break;
1161
1178
  case "DELETE":
1162
- e.rxdb.dispatchEvent(new Ve(o));
1179
+ e.rxdb.dispatchEvent(new Ke(i));
1163
1180
  break;
1164
1181
  }
1165
1182
  }
1166
- }, Ce = (e, t) => {
1167
- const { tableName: n } = t, [r, s] = Pr(n), a = e.rxdb.schemaManager.getEntityTypeByTableName(s, r);
1183
+ }, Me = (e, t) => {
1184
+ const { tableName: n } = t, [r, s] = Ur(n), a = e.rxdb.schemaManager.getEntityTypeByTableName(s, r);
1168
1185
  if (!a) return;
1169
- const i = e.getRepository(a), o = e.rxdb.schemaManager.getEntityMetadataByTableName(s, r);
1170
- if (!o) {
1186
+ const o = e.getRepository(a), i = e.rxdb.schemaManager.getEntityMetadataByTableName(s, r);
1187
+ if (!i) {
1171
1188
  console.warn(`Metadata not found for entity ${r}.${s}`);
1172
1189
  return;
1173
1190
  }
1174
- i.findByRowIds(t.rowIds).then((c) => {
1175
- const u = c;
1176
- if (!(!u || u.length === 0))
1177
- if (a === ie) {
1178
- if (jr(e, c), t.type === K.INSERT) {
1179
- const l = D(ie), p = c.map((h) => ({
1180
- namespace: l.namespace,
1181
- entity: l.name,
1182
- type: h.type,
1183
- id: h.id,
1184
- patch: { ...h },
1191
+ o.findByRowIds(t.rowIds).then((c) => {
1192
+ const l = c;
1193
+ if (!(!l || l.length === 0))
1194
+ if (a === le) {
1195
+ if (xr(e, c), t.type === K.INSERT) {
1196
+ const u = C(le), h = c.map((p) => ({
1197
+ namespace: u.namespace,
1198
+ entity: u.name,
1199
+ type: p.type,
1200
+ id: p.id,
1201
+ patch: { ...p },
1185
1202
  inversePatch: null,
1186
- recordAt: h.createdAt || /* @__PURE__ */ new Date()
1203
+ recordAt: p.createdAt || /* @__PURE__ */ new Date()
1187
1204
  }));
1188
- e.rxdb.dispatchEvent(new oe(p));
1205
+ e.rxdb.dispatchEvent(new ue(h));
1189
1206
  }
1190
1207
  } else {
1191
- const l = Ur(t.type), p = u.map((h) => {
1192
- const d = {
1193
- namespace: o.namespace,
1194
- entity: o.name,
1195
- type: l,
1196
- id: h.id,
1208
+ const u = jr(t.type), h = l.map((p) => {
1209
+ const f = {
1210
+ namespace: i.namespace,
1211
+ entity: i.name,
1212
+ type: u,
1213
+ id: p.id,
1197
1214
  patch: null,
1198
1215
  inversePatch: null,
1199
- recordAt: h.createdAt || /* @__PURE__ */ new Date()
1216
+ recordAt: p.createdAt || /* @__PURE__ */ new Date()
1200
1217
  };
1201
1218
  switch (t.type) {
1202
1219
  case K.INSERT:
1203
1220
  return {
1204
- ...d,
1205
- patch: { ...h }
1221
+ ...f,
1222
+ patch: { ...p }
1206
1223
  };
1207
1224
  case K.DELETE:
1208
1225
  return {
1209
- ...d,
1210
- inversePatch: { ...h }
1226
+ ...f,
1227
+ inversePatch: { ...p }
1211
1228
  };
1212
1229
  case K.UPDATE:
1213
1230
  return {
1214
- ...d,
1231
+ ...f,
1215
1232
  // 注意:这里无法获取变更前的数据,只能把整个 entity 作为 patch
1216
1233
  // 这是 UPDATE hook 的限制,完整的 patch/inversePatch 应该从 RxDBChange 表获取
1217
1234
  inversePatch: null,
1218
- patch: { ...h }
1235
+ patch: { ...p }
1219
1236
  };
1220
1237
  }
1221
1238
  });
1222
- switch (l) {
1239
+ switch (u) {
1223
1240
  case "UPDATE":
1224
1241
  e.rxdb.dispatchEvent(
1225
- new me(p)
1242
+ new ge(h)
1226
1243
  );
1227
1244
  break;
1228
1245
  case "DELETE":
1229
1246
  e.rxdb.dispatchEvent(
1230
- new Ve(p)
1247
+ new Ke(h)
1231
1248
  );
1232
1249
  break;
1233
1250
  case "INSERT":
1234
1251
  e.rxdb.dispatchEvent(
1235
- new oe(p)
1252
+ new ue(h)
1236
1253
  );
1237
1254
  break;
1238
1255
  }
@@ -1240,184 +1257,184 @@ const bn = (e, t) => {
1240
1257
  }).catch((c) => {
1241
1258
  c.message?.includes("closed") || console.error("Failed to handle RxDBChange event", c);
1242
1259
  });
1243
- }, xr = (e, t) => {
1260
+ }, Fr = (e, t) => {
1244
1261
  const n = P(e), r = [t.id];
1245
1262
  return {
1246
1263
  sql: `DELETE FROM ${n} WHERE id = $1;`,
1247
1264
  params: r
1248
1265
  };
1249
- }, Sn = (e, t, n) => {
1250
- const r = P(e), s = Ct(e, t);
1266
+ }, In = (e, t, n) => {
1267
+ const r = P(e), s = vt(e, t);
1251
1268
  n?.userId && (e.propertyMap.has("createdBy") && (s.createdBy = n.userId), e.propertyMap.has("updatedBy") && (s.updatedBy = n.userId));
1252
1269
  const a = {};
1253
- Object.keys(s).forEach((h) => {
1254
- const d = s[h];
1255
- d != null && (a[h] = d);
1270
+ Object.keys(s).forEach((p) => {
1271
+ const f = s[p];
1272
+ f != null && (a[p] = f);
1256
1273
  });
1257
- const i = Object.keys(a), o = Ke(e, a), c = [], u = i.map((h, d) => (c.push(o[h]), `$${d + 1}`)), l = i.map((h) => `"${h}"`).join(",");
1258
- let p = `INSERT INTO ${r} (${l}) VALUES (${u.join(",")})`;
1259
- return n?.returning !== !1 ? p += " RETURNING *;" : p += ";", { sql: p, params: c };
1260
- }, ze = (e, t, n, r) => {
1261
- const s = Xn(e, n);
1274
+ const o = Object.keys(a), i = Je(e, a), c = [], l = o.map((p, f) => (c.push(i[p]), `$${f + 1}`)), u = o.map((p) => `"${p}"`).join(",");
1275
+ let h = `INSERT INTO ${r} (${u}) VALUES (${l.join(",")})`;
1276
+ return n?.returning !== !1 ? h += " RETURNING *;" : h += ";", { sql: h, params: c };
1277
+ }, Ze = (e, t, n, r) => {
1278
+ const s = zn(e, n);
1262
1279
  e.propertyMap.has("updatedAt") && (s.updatedAt = r?.updatedAt ?? /* @__PURE__ */ new Date()), r?.userId && e.propertyMap.has("updatedBy") && (s.updatedBy = r.userId);
1263
- const a = Ke(e, s), o = Object.keys(s).map((h, d) => `"${h}" = $${d + 1}`).join(","), c = [...Object.values(a)], u = P(e), l = Array.isArray(t) ? t : [t];
1264
- let p = `UPDATE ${u} SET ${o} WHERE id `;
1280
+ const a = Je(e, s), i = Object.keys(s).map((p, f) => `"${p}" = $${f + 1}`).join(","), c = [...Object.values(a)], l = P(e), u = Array.isArray(t) ? t : [t];
1281
+ let h = `UPDATE ${l} SET ${i} WHERE id `;
1265
1282
  if (Array.isArray(t)) {
1266
- const h = c.length + 1;
1267
- p += `= ANY($${h})`, c.push(l.map((d) => d.id));
1283
+ const p = c.length + 1;
1284
+ h += `= ANY($${p})`, c.push(u.map((f) => f.id));
1268
1285
  } else {
1269
- const h = c.length + 1;
1270
- p += `= $${h}`, c.push(t.id);
1286
+ const p = c.length + 1;
1287
+ h += `= $${p}`, c.push(t.id);
1271
1288
  }
1272
- return r?.returning !== !1 ? p += " RETURNING *;" : p += ";", {
1273
- sql: p,
1289
+ return r?.returning !== !1 ? h += " RETURNING *;" : h += ";", {
1290
+ sql: h,
1274
1291
  params: c
1275
1292
  };
1276
- }, Ze = "_", In = (e) => e.replaceAll(".", "_"), he = (e, t) => {
1293
+ }, et = "_", On = (e) => e.replaceAll(".", "_"), pe = (e, t) => {
1277
1294
  if (e.relationAliasMap.has(t)) return e.relationAliasMap.get(t);
1278
- const n = t.includes("_") ? t : t.split("_")[0], r = vn(e, In(n));
1295
+ const n = t.includes("_") ? t : t.split("_")[0], r = Cn(e, On(n));
1279
1296
  return e.relationAliasMap.set(t, r), r;
1280
- }, Fr = (e, t, n, r) => {
1297
+ }, Br = (e, t, n, r) => {
1281
1298
  const s = n.slice(0, r);
1282
1299
  let a = t;
1283
- const i = [];
1284
- for (const o of s) {
1285
- if (!a?.relationMap.has(o)) return { relPairs: [] };
1286
- const c = a.relationMap.get(o);
1287
- i.push({ metadata: a, relation: c }), a = e.rxdb.schemaManager.getEntityMetadata(c.mappedEntity, c.mappedNamespace);
1288
- }
1289
- return { metaWalker: a, relPairs: i };
1290
- }, Br = (e, t, n, r, s) => {
1300
+ const o = [];
1301
+ for (const i of s) {
1302
+ if (!a?.relationMap.has(i)) return { relPairs: [] };
1303
+ const c = a.relationMap.get(i);
1304
+ o.push({ metadata: a, relation: c }), a = e.rxdb.schemaManager.getEntityMetadata(c.mappedEntity, c.mappedNamespace);
1305
+ }
1306
+ return { metaWalker: a, relPairs: o };
1307
+ }, kr = (e, t, n, r, s) => {
1291
1308
  for (let a = s.length - 1; a > 0; a--) {
1292
- const i = s.slice(a);
1293
- if (i.length === 0) continue;
1294
- const { metaWalker: o, relPairs: c } = Fr(e, n, s, a);
1295
- if (!o || c.length === 0) continue;
1296
- const u = i[0], l = i.slice(1).join("."), p = o.propertyMap.get(u);
1297
- if (p && p.type === N.keyValue) {
1298
- const h = s.slice(0, a).join(".");
1299
- On(e, t, c, h);
1300
- const d = c[c.length - 1].relation, y = de(c, h, d), A = he(t, y), $ = l ? `$.${l}` : "$";
1301
- return t.fieldAliasMap.set(r, `"${A}"."${p.columnName}" ->> '${$.replace("$.", "")}'`), !0;
1309
+ const o = s.slice(a);
1310
+ if (o.length === 0) continue;
1311
+ const { metaWalker: i, relPairs: c } = Br(e, n, s, a);
1312
+ if (!i || c.length === 0) continue;
1313
+ const l = o[0], u = o.slice(1).join("."), h = i.propertyMap.get(l);
1314
+ if (h && h.type === _.keyValue) {
1315
+ const p = s.slice(0, a).join(".");
1316
+ Dn(e, t, c, p);
1317
+ const f = c[c.length - 1].relation, E = me(c, p, f), $ = pe(t, E), A = u ? `$.${u}` : "$";
1318
+ return t.fieldAliasMap.set(r, `"${$}"."${h.columnName}" ->> '${A.replace("$.", "")}'`), !0;
1302
1319
  }
1303
1320
  }
1304
1321
  return !1;
1305
- }, On = (e, t, n, r) => {
1306
- n.forEach(({ metadata: s, relation: a }, i) => {
1307
- let o = e.rxdb.schemaManager.findMappedRelation(s, a);
1308
- if (!o)
1322
+ }, Dn = (e, t, n, r) => {
1323
+ n.forEach(({ metadata: s, relation: a }, o) => {
1324
+ let i = e.rxdb.schemaManager.findMappedRelation(s, a);
1325
+ if (!i)
1309
1326
  if (a.kind === B.ONE_TO_MANY || a.kind === B.MANY_TO_MANY) {
1310
- const p = s.relationMap.get(a.mappedProperty);
1311
- p && (o = { metadata: s, relation: p });
1312
- } else (a.kind === B.MANY_TO_ONE || a.kind === B.ONE_TO_ONE) && (o = { metadata: s, relation: a });
1313
- if (!o) throw new x("mappedRelation not found");
1314
- const c = de(n, r, a), u = he(t, c);
1315
- let l = Ze;
1316
- if (i > 0) {
1317
- const p = n[i - 1], h = de(n, r, p.relation);
1318
- l = he(t, h);
1327
+ const h = s.relationMap.get(a.mappedProperty);
1328
+ h && (i = { metadata: s, relation: h });
1329
+ } else (a.kind === B.MANY_TO_ONE || a.kind === B.ONE_TO_ONE) && (i = { metadata: s, relation: a });
1330
+ if (!i) throw new x("mappedRelation not found");
1331
+ const c = me(n, r, a), l = pe(t, c);
1332
+ let u = et;
1333
+ if (o > 0) {
1334
+ const h = n[o - 1], p = me(n, r, h.relation);
1335
+ u = pe(t, p);
1319
1336
  }
1320
1337
  switch (a.kind) {
1321
1338
  case B.ONE_TO_MANY:
1322
- kr(
1339
+ Wr(
1323
1340
  t,
1324
- o,
1325
- u,
1326
- l
1341
+ i,
1342
+ l,
1343
+ u
1327
1344
  );
1328
1345
  break;
1329
1346
  case B.ONE_TO_ONE:
1330
1347
  case B.MANY_TO_ONE:
1331
- Wr(
1348
+ Gr(
1332
1349
  t,
1333
- o,
1334
- u,
1350
+ i,
1335
1351
  l,
1352
+ u,
1336
1353
  a
1337
1354
  );
1338
1355
  break;
1339
1356
  case B.MANY_TO_MANY:
1340
- Gr(
1357
+ Hr(
1341
1358
  t,
1342
- o,
1343
- u,
1359
+ i,
1344
1360
  l,
1361
+ u,
1345
1362
  a
1346
1363
  );
1347
1364
  break;
1348
1365
  }
1349
1366
  });
1350
- }, kr = (e, t, n, r) => {
1351
- const s = fe(e, t.metadata), a = t.relation.columnName, i = `"${n}"."${a}" = ${et(r)}."id"`;
1352
- s.find((c) => c.joinTableName === n && c.on === i) || s.push({
1367
+ }, Wr = (e, t, n, r) => {
1368
+ const s = Ee(e, t.metadata), a = t.relation.columnName, o = `"${n}"."${a}" = ${tt(r)}."id"`;
1369
+ s.find((c) => c.joinTableName === n && c.on === o) || s.push({
1353
1370
  joinTableName: n,
1354
- on: i
1371
+ on: o
1355
1372
  });
1356
- }, Wr = (e, t, n, r, s) => {
1357
- const a = fe(e, t.metadata), i = `"${n}"."id" = ${et(r)}."${s.columnName}"`;
1358
- a.find((c) => c.joinTableName === n && c.on === i) || a.push({
1373
+ }, Gr = (e, t, n, r, s) => {
1374
+ const a = Ee(e, t.metadata), o = `"${n}"."id" = ${tt(r)}."${s.columnName}"`;
1375
+ a.find((c) => c.joinTableName === n && c.on === o) || a.push({
1359
1376
  joinTableName: n,
1360
- on: i
1377
+ on: o
1361
1378
  });
1362
- }, Gr = (e, t, n, r, s) => {
1363
- const a = D(s.junctionEntityType), i = fe(e, a), o = vn(e, In(`${s.name}_m_n`)), c = `"${o}"."${t.relation.columnName}" = ${et(r)}."id"`;
1364
- i.find(
1365
- (d) => d.joinTableName === o && d.on === c
1366
- ) || i.push({
1367
- joinTableName: o,
1379
+ }, Hr = (e, t, n, r, s) => {
1380
+ const a = C(s.junctionEntityType), o = Ee(e, a), i = Cn(e, On(`${s.name}_m_n`)), c = `"${i}"."${t.relation.columnName}" = ${tt(r)}."id"`;
1381
+ o.find(
1382
+ (f) => f.joinTableName === i && f.on === c
1383
+ ) || o.push({
1384
+ joinTableName: i,
1368
1385
  on: c
1369
1386
  });
1370
- const l = fe(e, t.metadata), p = `"${n}"."id" = "${o}"."${s.columnName}"`;
1371
- l.find((d) => d.joinTableName === n && d.on === p) || l.push({
1387
+ const u = Ee(e, t.metadata), h = `"${n}"."id" = "${i}"."${s.columnName}"`;
1388
+ u.find((f) => f.joinTableName === n && f.on === h) || u.push({
1372
1389
  joinTableName: n,
1373
- on: p
1390
+ on: h
1374
1391
  });
1375
- }, fe = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), vn = (e, t) => {
1392
+ }, Ee = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), Cn = (e, t) => {
1376
1393
  let n = t, r = 1;
1377
1394
  for (; e.usedAliases.has(n); )
1378
1395
  n = `${t}_${r++}`;
1379
1396
  return e.usedAliases.add(n), n;
1380
- }, de = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, et = (e) => e === Ze ? e : `"${e}"`, Dn = (e, t, n) => {
1397
+ }, me = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, tt = (e) => e === et ? e : `"${e}"`, Ln = (e, t, n) => {
1381
1398
  const r = {
1382
1399
  joinMap: /* @__PURE__ */ new Map(),
1383
1400
  usedAliases: /* @__PURE__ */ new Set(),
1384
1401
  fieldAliasMap: /* @__PURE__ */ new Map(),
1385
1402
  relationAliasMap: /* @__PURE__ */ new Map()
1386
1403
  };
1387
- Wn(n, (a, i, o) => {
1388
- const c = i;
1389
- a !== "field" || !c.includes(".") || Hr(e, r, t, c, o);
1404
+ Gn(n, (a, o, i) => {
1405
+ const c = o;
1406
+ a !== "field" || !c.includes(".") || Vr(e, r, t, c, i);
1390
1407
  });
1391
1408
  const s = [];
1392
- for (const [a, i] of r.joinMap.entries()) {
1393
- const o = P(a);
1394
- for (const c of i)
1395
- s.push(` LEFT JOIN ${o} "${c.joinTableName}" ON ${c.on}`);
1409
+ for (const [a, o] of r.joinMap.entries()) {
1410
+ const i = P(a);
1411
+ for (const c of o)
1412
+ s.push(` LEFT JOIN ${i} "${c.joinTableName}" ON ${c.on}`);
1396
1413
  }
1397
1414
  return { joinSQL: s.join(""), fieldAliasMap: r.fieldAliasMap };
1398
- }, Hr = (e, t, n, r, s) => {
1415
+ }, Vr = (e, t, n, r, s) => {
1399
1416
  const a = r.split(".");
1400
1417
  try {
1401
- const u = e.rxdb.schemaManager.getFieldRelations(n, r);
1402
- if (u.isForeignKey) {
1403
- s.field = u.propertyName;
1418
+ const l = e.rxdb.schemaManager.getFieldRelations(n, r);
1419
+ if (l.isForeignKey) {
1420
+ s.field = l.propertyName;
1404
1421
  return;
1405
1422
  }
1406
- const l = r.replace(`.${u.propertyName}`, "");
1407
- On(e, t, u.relations, l);
1408
- const p = u.relations[u.relations.length - 1], h = de(u.relations, l, p.relation), d = he(t, h);
1409
- t.fieldAliasMap.set(r, `"${d}"."${u.property.columnName}"`);
1423
+ const u = r.replace(`.${l.propertyName}`, "");
1424
+ Dn(e, t, l.relations, u);
1425
+ const h = l.relations[l.relations.length - 1], p = me(l.relations, u, h.relation), f = pe(t, p);
1426
+ t.fieldAliasMap.set(r, `"${f}"."${l.property.columnName}"`);
1410
1427
  return;
1411
1428
  } catch {
1412
1429
  }
1413
- const [i, ...o] = a, c = n.propertyMap.get(i);
1414
- if (c && c.type === N.keyValue && o.length > 0) {
1415
- const u = o.join(".");
1416
- t.fieldAliasMap.set(r, `"${Ze}"."${c.columnName}" ->> '${u}'`);
1430
+ const [o, ...i] = a, c = n.propertyMap.get(o);
1431
+ if (c && c.type === _.keyValue && i.length > 0) {
1432
+ const l = i.join(".");
1433
+ t.fieldAliasMap.set(r, `"${et}"."${c.columnName}" ->> '${l}'`);
1417
1434
  return;
1418
1435
  }
1419
- Br(e, t, n, r, a);
1420
- }, pe = "_", Vr = {
1436
+ kr(e, t, n, r, a);
1437
+ }, te = "_", Kr = {
1421
1438
  "=": "=",
1422
1439
  "!=": "!=",
1423
1440
  ">": ">",
@@ -1434,13 +1451,13 @@ const bn = (e, t) => {
1434
1451
  notStartsWith: "NOT LIKE",
1435
1452
  endsWith: "LIKE",
1436
1453
  notEndsWith: "NOT LIKE"
1437
- }, Kr = (e, t) => {
1454
+ }, Jr = (e, t) => {
1438
1455
  if (e?.length)
1439
1456
  return e.map((n) => {
1440
- const r = Cn(n.field, t);
1441
- return `${pe}."${r}" ${n.sort.toUpperCase()}`;
1457
+ const r = vn(n.field, t);
1458
+ return `${te}."${r}" ${n.sort.toUpperCase()}`;
1442
1459
  }).join(", ");
1443
- }, Jr = (e) => Vr[e] || e, Yr = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), Cn = (e, t) => {
1460
+ }, Yr = (e) => Kr[e] || e, Qr = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), vn = (e, t) => {
1444
1461
  if (t && !e.includes(".")) {
1445
1462
  const n = t.propertyMap.get(e);
1446
1463
  if (n)
@@ -1450,96 +1467,97 @@ const bn = (e, t) => {
1450
1467
  return s[a];
1451
1468
  }
1452
1469
  return e;
1453
- }, Qr = (e, t, n) => {
1470
+ }, Xr = (e, t, n, r) => {
1454
1471
  if (t) return t;
1455
1472
  if (!e.includes(".")) {
1456
- const o = Cn(e, n);
1457
- return o.toLowerCase() !== o ? `"${o}"` : o;
1473
+ const c = vn(e, n), l = r ? `${te}.` : "";
1474
+ return c.toLowerCase() !== c ? `${l}"${c}"` : `${l}${c}`;
1458
1475
  }
1459
- const r = e.split("."), s = r[0], a = n?.propertyMap.get(s);
1460
- if (a && (a.type === N.json || a.type === N.keyValue) && r.length === 2)
1461
- return `"${a.columnName}" ->> '${r[1]}'`;
1476
+ const s = e.split("."), a = s[0], o = n?.propertyMap.get(a);
1477
+ if (o && (o.type === _.json || o.type === _.keyValue) && s.length === 2)
1478
+ return `"${o.columnName}" ->> '${s[1]}'`;
1462
1479
  const i = e.lastIndexOf(".");
1463
1480
  return `"${e.slice(0, i)}".${e.slice(i + 1)}`;
1464
- }, Xr = (e, t, n = /* @__PURE__ */ new Map(), r) => {
1465
- const s = String(e.field), a = n.get(s), i = Qr(s, a, r), o = e.value, c = e.operator;
1466
- if (c === "null" || c === "notNull")
1467
- return c === "null" ? `${i} IS NULL` : `${i} IS NOT NULL`;
1468
- if (o === null)
1469
- return c === "=" ? `${i} IS NULL` : c === "!=" ? `${i} IS NOT NULL` : "";
1470
- let u = s;
1471
- a && s.includes(".") && (u = s.split(".").pop() || s);
1472
- const l = r?.propertyMap.get(u.split(".")[0]);
1473
- if (l && (l.type === N.json || l.type === N.keyValue)) {
1474
- if (c === "contains" && typeof o == "object" && !Array.isArray(o))
1475
- return t.push(JSON.stringify(o)), `${i} @> $${t.length}::jsonb`;
1476
- if (c === "notContains" && typeof o == "object" && !Array.isArray(o))
1477
- return t.push(JSON.stringify(o)), `NOT (${i} @> $${t.length}::jsonb)`;
1478
- }
1479
- if (l && (l.type === N.stringArray || l.type === N.numberArray) && (c === "in" || c === "notIn")) {
1480
- if (!Array.isArray(o)) return "";
1481
- t.push(JSON.stringify(o));
1482
- const h = `${i} @> $${t.length}::jsonb`;
1483
- return c === "notIn" ? `NOT ${h}` : h;
1484
- }
1485
- if (c === "in" || c === "notIn")
1486
- return Array.isArray(o) ? o.length === 0 ? c === "in" ? "1=0" : "1=1" : (t.push(o), `${i} ${c === "in" ? "= ANY" : "!= ALL"}($${t.length})`) : "";
1487
- if (c === "between" || c === "notBetween")
1488
- return !Array.isArray(o) || o.length !== 2 ? "" : (t.push(o[0], o[1]), `${i} ${c === "between" ? "BETWEEN" : "NOT BETWEEN"} $${t.length - 1} AND $${t.length}`);
1489
- if (["contains", "notContains", "startsWith", "notStartsWith", "endsWith", "notEndsWith"].includes(c)) {
1490
- let h = "";
1491
- c === "contains" || c === "notContains" ? h = `%${o}%` : c === "startsWith" || c === "notStartsWith" ? h = `${o}%` : (c === "endsWith" || c === "notEndsWith") && (h = `%${o}`), t.push(h);
1492
- const d = c.startsWith("not") ? "NOT LIKE" : "LIKE";
1493
- return `${i} ${d} $${t.length}`;
1494
- }
1495
- const p = Jr(c);
1496
- return t.push(o), l && l.type === N.uuid ? `${i}::uuid ${p} $${t.length}::uuid` : `${i} ${p} $${t.length}`;
1497
- }, we = (e, t, n = /* @__PURE__ */ new Map(), r) => {
1498
- const s = e.rules.map(
1499
- (i) => Yr(i) ? we(i, t, n, r) : Xr(i, t, n, r)
1481
+ }, zr = (e, t, n = /* @__PURE__ */ new Map(), r, s) => {
1482
+ const a = String(e.field), o = n.get(a), i = Xr(a, o, r, s), c = e.value, l = e.operator;
1483
+ if (l === "null" || l === "notNull")
1484
+ return l === "null" ? `${i} IS NULL` : `${i} IS NOT NULL`;
1485
+ if (c === null)
1486
+ return l === "=" ? `${i} IS NULL` : l === "!=" ? `${i} IS NOT NULL` : "";
1487
+ let u = a;
1488
+ o && a.includes(".") && (u = a.split(".").pop() || a);
1489
+ const h = r?.propertyMap.get(u.split(".")[0]);
1490
+ if (h && (h.type === _.json || h.type === _.keyValue)) {
1491
+ if (l === "contains" && typeof c == "object" && !Array.isArray(c))
1492
+ return t.push(JSON.stringify(c)), `${i} @> $${t.length}::jsonb`;
1493
+ if (l === "notContains" && typeof c == "object" && !Array.isArray(c))
1494
+ return t.push(JSON.stringify(c)), `NOT (${i} @> $${t.length}::jsonb)`;
1495
+ }
1496
+ if (h && (h.type === _.stringArray || h.type === _.numberArray) && (l === "in" || l === "notIn")) {
1497
+ if (!Array.isArray(c)) return "";
1498
+ const f = h.type === _.stringArray ? "text[]" : "numeric[]";
1499
+ t.push(c);
1500
+ const E = `${i} @> $${t.length}::${f}`;
1501
+ return l === "notIn" ? `NOT ${E}` : E;
1502
+ }
1503
+ if (l === "in" || l === "notIn")
1504
+ return Array.isArray(c) ? c.length === 0 ? l === "in" ? "1=0" : "1=1" : (t.push(c), `${i} ${l === "in" ? "= ANY" : "!= ALL"}($${t.length})`) : "";
1505
+ if (l === "between" || l === "notBetween")
1506
+ return !Array.isArray(c) || c.length !== 2 ? "" : (t.push(c[0], c[1]), `${i} ${l === "between" ? "BETWEEN" : "NOT BETWEEN"} $${t.length - 1} AND $${t.length}`);
1507
+ if (["contains", "notContains", "startsWith", "notStartsWith", "endsWith", "notEndsWith"].includes(l)) {
1508
+ let f = "";
1509
+ l === "contains" || l === "notContains" ? f = `%${c}%` : l === "startsWith" || l === "notStartsWith" ? f = `${c}%` : (l === "endsWith" || l === "notEndsWith") && (f = `%${c}`), t.push(f);
1510
+ const E = l.startsWith("not") ? "NOT LIKE" : "LIKE";
1511
+ return `${i} ${E} $${t.length}`;
1512
+ }
1513
+ const p = Yr(l);
1514
+ return t.push(c), h && h.type === _.uuid ? `${i}::uuid ${p} $${t.length}::uuid` : `${i} ${p} $${t.length}`;
1515
+ }, Ae = (e, t, n = /* @__PURE__ */ new Map(), r, s) => {
1516
+ const a = e.rules.map(
1517
+ (i) => Qr(i) ? Ae(i, t, n, r, s) : zr(i, t, n, r, s)
1500
1518
  ).filter(Boolean);
1501
- if (!s.length) return "";
1502
- if (s.length === 1) return s[0];
1503
- const a = e.combinator.toUpperCase();
1504
- return `(${s.join(` ${a} `)})`;
1505
- }, zr = (e, t) => {
1506
- let n = `SELECT ${pe}.* FROM ${e.tableName} AS ${pe}`;
1507
- return e.join && (n += ` ${e.join}`), e.where && (n += ` WHERE ${e.where}`), e.orderBy && (n += ` ORDER BY ${e.orderBy}`), e.limit !== void 0 && (t.push(e.limit), n += ` LIMIT $${t.length}`), e.offset !== void 0 && e.offset > 0 && (t.push(e.offset), n += ` OFFSET $${t.length}`), n;
1508
- }, Zr = (e) => {
1509
- let t = `SELECT COUNT(*) as count FROM ${e.tableName} AS ${pe}`;
1510
- return e.join && (t += ` ${e.join}`), e.where && (t += ` WHERE ${e.where}`), t;
1511
- }, Ee = (e, t, n) => {
1512
- const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Dn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0, c = Kr(n.orderBy, t), u = "limit" in n ? n.limit : void 0, l = "offset" in n ? n.offset : void 0;
1513
- return { sql: zr(
1519
+ if (!a.length) return "";
1520
+ if (a.length === 1) return a[0];
1521
+ const o = e.combinator.toUpperCase();
1522
+ return `(${a.join(` ${o} `)})`;
1523
+ }, Zr = (e, t) => {
1524
+ let r = `SELECT ${e.join ? "DISTINCT " : ""}${te}.* FROM ${e.tableName} AS ${te}`;
1525
+ return e.join && (r += ` ${e.join}`), e.where && (r += ` WHERE ${e.where}`), e.orderBy && (r += ` ORDER BY ${e.orderBy}`), e.limit !== void 0 && (t.push(e.limit), r += ` LIMIT $${t.length}`), e.offset !== void 0 && e.offset > 0 && (t.push(e.offset), r += ` OFFSET $${t.length}`), r;
1526
+ }, ea = (e) => {
1527
+ let n = `SELECT ${e.join ? `COUNT(DISTINCT ${te}.id)` : "COUNT(*)"} as count FROM ${e.tableName} AS ${te}`;
1528
+ return e.join && (n += ` ${e.join}`), e.where && (n += ` WHERE ${e.where}`), n;
1529
+ }, ye = (e, t, n) => {
1530
+ const r = P(t), s = [], { joinSQL: a, fieldAliasMap: o } = n.where ? Ln(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, i = !!a, c = n.where ? Ae(n.where, s, o, t, i) : void 0, l = Jr(n.orderBy, t), u = "limit" in n ? n.limit : void 0, h = "offset" in n ? n.offset : void 0;
1531
+ return { sql: Zr(
1514
1532
  {
1515
1533
  tableName: r,
1516
- where: o,
1534
+ where: c,
1517
1535
  join: a,
1518
- orderBy: c,
1536
+ orderBy: l,
1519
1537
  limit: u,
1520
- offset: l
1538
+ offset: h
1521
1539
  },
1522
1540
  s
1523
1541
  ), params: s };
1524
- }, ea = (e, t, n) => {
1542
+ }, ta = (e, t, n) => {
1525
1543
  if (n.groupBy)
1526
1544
  throw new x("groupBy not supported in count queries");
1527
- const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Dn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0;
1528
- return { sql: Zr({
1545
+ const r = P(t), s = [], { joinSQL: a, fieldAliasMap: o } = n.where ? Ln(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, i = !!a, c = n.where ? Ae(n.where, s, o, t, i) : void 0;
1546
+ return { sql: ea({
1529
1547
  tableName: r,
1530
- where: o,
1548
+ where: c,
1531
1549
  join: a
1532
1550
  }), params: s };
1533
- }, ta = (e, t) => {
1534
- const n = P(e), r = t.map((a, i) => `$${i + 1}`).join(", ");
1551
+ }, na = (e, t) => {
1552
+ const n = P(e), r = t.map((a, o) => `$${o + 1}`).join(", ");
1535
1553
  return {
1536
1554
  sql: `SELECT * FROM ${n} WHERE id IN (${r})`,
1537
1555
  params: t
1538
1556
  };
1539
1557
  };
1540
- class na extends Fn {
1558
+ class sa extends Bn {
1541
1559
  constructor(t, n) {
1542
- super(t.rxdb, n), this.adapter = t, this.metadata = D(n);
1560
+ super(t.rxdb, n), this.adapter = t, this.metadata = C(n);
1543
1561
  }
1544
1562
  metadata;
1545
1563
  /**
@@ -1551,20 +1569,20 @@ class na extends Fn {
1551
1569
  */
1552
1570
  async findByRowIds(t) {
1553
1571
  if (t.length === 0) return [];
1554
- const { sql: n, params: r } = ta(this.metadata, t), s = await this.adapter.query(n, r);
1572
+ const { sql: n, params: r } = na(this.metadata, t), s = await this.adapter.query(n, r);
1555
1573
  return this.addQueryCache(s);
1556
1574
  }
1557
1575
  addQueryCache(t, n = !0) {
1558
1576
  return t.rows.map((r) => {
1559
- const s = Z(this.metadata, r), a = s.id;
1560
- let i;
1561
- super.hasEntityRef(a) ? (i = super.getEntityRef(a), n && super.updateEntity(i, s)) : i = this.createEntityRef(s);
1562
- const o = J(i);
1563
- return o.local = !0, o.modified = !1, i;
1577
+ const s = ee(this.metadata, r), a = s.id;
1578
+ let o;
1579
+ super.hasEntityRef(a) ? (o = super.getEntityRef(a), n && super.updateEntity(o, s)) : o = this.createEntityRef(s);
1580
+ const i = J(o);
1581
+ return i.local = !0, i.modified = !1, o;
1564
1582
  });
1565
1583
  }
1566
1584
  }
1567
- class Ln extends na {
1585
+ class Mn extends sa {
1568
1586
  async get(t) {
1569
1587
  const n = {
1570
1588
  where: {
@@ -1579,176 +1597,176 @@ class Ln extends na {
1579
1597
  return (await this.find({ ...t, limit: 1, offset: 0 }))[0];
1580
1598
  }
1581
1599
  async find(t) {
1582
- const { sql: n, params: r } = Ee(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1600
+ const { sql: n, params: r } = ye(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1583
1601
  return this.addQueryCache(s);
1584
1602
  }
1585
1603
  async findAll(t) {
1586
- const { sql: n, params: r } = Ee(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1604
+ const { sql: n, params: r } = ye(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1587
1605
  return this.addQueryCache(s);
1588
1606
  }
1589
1607
  async count(t) {
1590
- const { sql: n, params: r } = ea(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1608
+ const { sql: n, params: r } = ta(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1591
1609
  return parseInt(s.rows[0].count);
1592
1610
  }
1593
1611
  async create(t) {
1594
- const { sql: n, params: r } = Sn(this.metadata, t, this.rxdb.context), s = await this.adapter.query(n, r);
1612
+ const { sql: n, params: r } = In(this.metadata, t, this.rxdb.context), s = await this.adapter.query(n, r);
1595
1613
  return this.addQueryCache(s, !0), t;
1596
1614
  }
1597
1615
  async update(t, n) {
1598
1616
  Object.assign(t, n);
1599
- const { sql: r, params: s } = ze(this.metadata, t, n, this.rxdb.context);
1600
- return await this.adapter.query(r, s), t;
1617
+ const { sql: r, params: s } = Ze(this.metadata, t, n, this.rxdb.context), a = await this.adapter.query(r, s);
1618
+ return this.addQueryCache(a), t;
1601
1619
  }
1602
1620
  async remove(t) {
1603
- const { sql: n, params: r } = xr(this.metadata, t);
1621
+ const { sql: n, params: r } = Fr(this.metadata, t);
1604
1622
  return await this.adapter.query(n, r), t;
1605
1623
  }
1606
1624
  }
1607
- const Ne = (e, t, n) => {
1608
- const { isCount: r, isFindDescendants: s, entityId: a, where: i } = n, o = !a, c = P(t);
1609
- let u = "";
1610
- const p = [`c.level < ${n.level || 0}`], h = [];
1611
- if (o || h.push(a), i) {
1612
- const R = /* @__PURE__ */ new Map(), I = (_) => {
1613
- if ("rules" in _)
1614
- return { ..._, rules: _.rules.map(I) };
1615
- if (_.field && typeof _.field == "string" && _.field.startsWith("children.")) {
1616
- const T = _.field.substring(9), S = t.propertyMap.get(T)?.columnName ?? T;
1617
- R.set(_.field, `children."${S}"`);
1625
+ const $e = (e, t, n) => {
1626
+ const { isCount: r, isFindDescendants: s, entityId: a, where: o } = n, i = !a, c = P(t);
1627
+ let l = "";
1628
+ const h = [`c.level < ${n.level || 0}`], p = [];
1629
+ if (i || p.push(a), o) {
1630
+ const b = /* @__PURE__ */ new Map(), R = (y) => {
1631
+ if ("rules" in y)
1632
+ return { ...y, rules: y.rules.map(R) };
1633
+ if (y.field && typeof y.field == "string" && y.field.startsWith("children.")) {
1634
+ const g = y.field.substring(9), I = t.propertyMap.get(g)?.columnName ?? g;
1635
+ b.set(y.field, `children."${I}"`);
1618
1636
  }
1619
- return _;
1637
+ return y;
1620
1638
  };
1621
- I(i);
1622
- const E = we(i, h, R, t);
1623
- E && p.push(E);
1624
- }
1625
- const d = p.filter(Boolean).join(" AND ");
1626
- d && (u = `WHERE ${d}`);
1627
- let y = "*";
1628
- return r && (o ? y = "count(*) AS count" : y = "(count(*) - 1) AS count"), {
1639
+ R(o);
1640
+ const m = Ae(o, p, b, t);
1641
+ m && h.push(m);
1642
+ }
1643
+ const f = h.filter(Boolean).join(" AND ");
1644
+ f && (l = `WHERE ${f}`);
1645
+ let E = "*";
1646
+ return r && (i ? E = "count(*) AS count" : E = "(count(*) - 1) AS count"), {
1629
1647
  sql: `WITH RECURSIVE __children AS (
1630
1648
  SELECT *, 0 AS level
1631
1649
  FROM ${c}
1632
- WHERE ${o ? '"parentId" IS NULL' : "id = $1"}
1650
+ WHERE ${i ? '"parentId" IS NULL' : "id = $1"}
1633
1651
  UNION ALL
1634
1652
  SELECT children.*, c.level + 1 AS level
1635
1653
  FROM ${c} children
1636
1654
  JOIN __children c ON ${s ? 'children."parentId"::uuid = c.id::uuid' : 'children.id::uuid = c."parentId"::uuid'}
1637
- ${u}
1655
+ ${l}
1638
1656
  )
1639
1657
 
1640
- SELECT ${y} FROM __children${r ? "" : " ORDER BY level, id"};`,
1641
- params: h
1658
+ SELECT ${E} FROM __children${r ? "" : " ORDER BY level, id"};`,
1659
+ params: p
1642
1660
  };
1643
- }, sa = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !0 }), ra = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !0, isCount: !0 }), aa = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !1 }), ia = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
1644
- class oa extends Ln {
1661
+ }, ra = (e, t, n) => $e(e, t, { ...n, isFindDescendants: !0 }), aa = (e, t, n) => $e(e, t, { ...n, isFindDescendants: !0, isCount: !0 }), ia = (e, t, n) => $e(e, t, { ...n, isFindDescendants: !1 }), oa = (e, t, n) => $e(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
1662
+ class ca extends Mn {
1645
1663
  async findDescendants(t) {
1646
- const { sql: n, params: r } = sa(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1647
- return !s.rows || s.rows.length === 0 ? [] : s.rows.map((i) => {
1648
- const o = Z(this.metadata, i);
1649
- return this.createEntityRef(o);
1664
+ const { sql: n, params: r } = ra(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1665
+ return !s.rows || s.rows.length === 0 ? [] : s.rows.map((o) => {
1666
+ const i = ee(this.metadata, o);
1667
+ return this.createEntityRef(i);
1650
1668
  });
1651
1669
  }
1652
1670
  async countDescendants(t) {
1653
- const { sql: n, params: r } = ra(this.adapter, this.metadata, t), a = (await this.adapter.query(n, r)).rows[0], i = a.count || a["?column?"];
1654
- return parseInt(String(i), 10) || 0;
1671
+ const { sql: n, params: r } = aa(this.adapter, this.metadata, t), a = (await this.adapter.query(n, r)).rows[0], o = a.count || a["?column?"];
1672
+ return parseInt(String(o), 10) || 0;
1655
1673
  }
1656
1674
  async findAncestors(t) {
1657
- const { sql: n, params: r } = aa(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1658
- return !s.rows || s.rows.length === 0 ? [] : s.rows.map((i) => {
1659
- const o = Z(this.metadata, i);
1660
- return this.createEntityRef(o);
1675
+ const { sql: n, params: r } = ia(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1676
+ return !s.rows || s.rows.length === 0 ? [] : s.rows.map((o) => {
1677
+ const i = ee(this.metadata, o);
1678
+ return this.createEntityRef(i);
1661
1679
  });
1662
1680
  }
1663
1681
  async countAncestors(t) {
1664
- const { sql: n, params: r } = ia(this.adapter, this.metadata, t), a = (await this.adapter.query(n, r)).rows[0], i = a.count || a["?column?"];
1665
- return parseInt(String(i), 10) || 0;
1682
+ const { sql: n, params: r } = oa(this.adapter, this.metadata, t), a = (await this.adapter.query(n, r)).rows[0], o = a.count || a["?column?"];
1683
+ return parseInt(String(o), 10) || 0;
1666
1684
  }
1667
1685
  }
1668
- const ca = async (e, t) => {
1686
+ const la = async (e, t) => {
1669
1687
  const n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Date();
1670
1688
  for (const [s, a] of t.create.entries()) {
1671
- const i = Array.from(a);
1672
- i.forEach((y) => n.add(y));
1673
- const o = D(s), c = ue(o, i, e.rxdb.context);
1689
+ const o = Array.from(a);
1690
+ o.forEach((E) => n.add(E));
1691
+ const i = C(s), c = de(i, o, e.rxdb.context);
1674
1692
  await e.query(c);
1675
- const u = i.map((y) => y.id), { sql: l, params: p } = Ee(e, o, {
1676
- where: { combinator: "and", rules: [{ field: "id", operator: "in", value: u }] }
1677
- }), h = await e.query(l, p), d = e.getRepository(s);
1678
- for (const y of h.rows) {
1679
- const A = Z(o, y), $ = A.id;
1680
- if (d.hasEntityRef($)) {
1681
- const R = d.getEntityRef($);
1682
- d.updateEntity(R, A);
1683
- const I = J(R);
1684
- I.local = !0, I.modified = !1;
1693
+ const l = o.map((E) => E.id), { sql: u, params: h } = ye(e, i, {
1694
+ where: { combinator: "and", rules: [{ field: "id", operator: "in", value: l }] }
1695
+ }), p = await e.query(u, h), f = e.getRepository(s);
1696
+ for (const E of p.rows) {
1697
+ const $ = ee(i, E), A = $.id;
1698
+ if (f.hasEntityRef(A)) {
1699
+ const b = f.getEntityRef(A);
1700
+ f.updateEntity(b, $);
1701
+ const R = J(b);
1702
+ R.local = !0, R.modified = !1;
1685
1703
  }
1686
1704
  }
1687
1705
  }
1688
1706
  for (const [s, a] of t.update.entries()) {
1689
- const i = Array.from(a);
1690
- i.forEach((h) => n.add(h));
1691
- const o = D(s), c = e.getRepository(s);
1692
- for (const h of i) {
1693
- const d = J(h), { sql: y, params: A } = ze(o, h, d.patch || {}, {
1707
+ const o = Array.from(a);
1708
+ o.forEach((p) => n.add(p));
1709
+ const i = C(s), c = e.getRepository(s);
1710
+ for (const p of o) {
1711
+ const f = J(p), { sql: E, params: $ } = Ze(i, p, f.patch || {}, {
1694
1712
  ...e.rxdb.context,
1695
1713
  returning: !1,
1696
1714
  updatedAt: r
1697
1715
  });
1698
- await e.query(y, A);
1716
+ await e.query(E, $);
1699
1717
  }
1700
- const u = i.map((h) => h.id), l = Ee(e, o, {
1701
- where: { combinator: "and", rules: [{ field: "id", operator: "in", value: u }] }
1702
- }), p = await e.query(l.sql, l.params);
1703
- for (const h of p.rows) {
1704
- const d = Z(o, h), y = d.id;
1705
- if (c.hasEntityRef(y)) {
1706
- const A = c.getEntityRef(y);
1707
- c.updateEntity(A, d);
1708
- const $ = J(A);
1709
- $.local = !0, $.modified = !1;
1718
+ const l = o.map((p) => p.id), u = ye(e, i, {
1719
+ where: { combinator: "and", rules: [{ field: "id", operator: "in", value: l }] }
1720
+ }), h = await e.query(u.sql, u.params);
1721
+ for (const p of h.rows) {
1722
+ const f = ee(i, p), E = f.id;
1723
+ if (c.hasEntityRef(E)) {
1724
+ const $ = c.getEntityRef(E);
1725
+ c.updateEntity($, f);
1726
+ const A = J($);
1727
+ A.local = !0, A.modified = !1;
1710
1728
  }
1711
1729
  }
1712
1730
  }
1713
1731
  for (const [, s] of t.remove.entries()) {
1714
- const a = Array.from(s), i = D(a[0]?.constructor);
1732
+ const a = Array.from(s), o = C(a[0]?.constructor);
1715
1733
  if (a.length > 0) {
1716
- const o = bn(i, a);
1717
- await e.query(o);
1734
+ const i = Sn(o, a);
1735
+ await e.query(i);
1718
1736
  }
1719
- for (const o of a) {
1720
- n.add(o);
1721
- const c = J(o);
1722
- c.origin = structuredClone({ ...o }), c.modified = !1, c.removed = !0, c.local = !1;
1737
+ for (const i of a) {
1738
+ n.add(i);
1739
+ const c = J(i);
1740
+ c.origin = structuredClone({ ...i }), c.modified = !1, c.removed = !0, c.local = !1;
1723
1741
  }
1724
1742
  }
1725
1743
  return Array.from(n);
1726
- }, la = (e, t) => {
1744
+ }, ua = (e, t) => {
1727
1745
  const n = P(t);
1728
1746
  let r = `CREATE TABLE ${n} (`;
1729
- const s = [], a = [], i = [];
1747
+ const s = [], a = [], o = [];
1730
1748
  t.propertyMap.forEach((c) => {
1731
- let u = "";
1732
- u += `"${c.columnName}"`;
1733
- const l = vt(c);
1734
- if (c.primary ? c.type === N.integer ? u += " serial PRIMARY KEY" : u += ` ${l} PRIMARY KEY` : u += ` ${l}`, Reflect.get(c, "default") !== void 0) {
1735
- let p = c.default;
1736
- It(c.default) && (p = c.default()), Gn(p) ? ["CURRENT_TIMESTAMP", "now()"].includes(p) ? u += " DEFAULT now()" : u += ` DEFAULT '${p}'` : p instanceof Date ? u += ` DEFAULT '${p.toISOString()}'` : typeof p == "boolean" || typeof p == "number" ? u += ` DEFAULT ${String(p)}` : u += ` DEFAULT '${String(p)}'`;
1749
+ let l = "";
1750
+ l += `"${c.columnName}"`;
1751
+ const u = Ct(c);
1752
+ if (c.primary ? c.type === _.integer ? l += " serial PRIMARY KEY" : l += ` ${u} PRIMARY KEY` : l += ` ${u}`, Reflect.get(c, "default") !== void 0) {
1753
+ let h = c.default;
1754
+ Ot(c.default) && (h = c.default()), Hn(h) ? ["CURRENT_TIMESTAMP", "now()"].includes(h) ? l += " DEFAULT now()" : l += ` DEFAULT '${h}'` : h instanceof Date ? l += ` DEFAULT '${h.toISOString()}'` : typeof h == "boolean" || typeof h == "number" ? l += ` DEFAULT ${String(h)}` : l += ` DEFAULT '${String(h)}'`;
1737
1755
  }
1738
- if (c.nullable || (u += " NOT NULL"), c.unique && s.push(
1739
- `CREATE UNIQUE INDEX "${Dt(t, c)}" on ${n} ("${c.columnName}" ${Qn(c)});`
1740
- ), c.type === N.enum) {
1741
- const p = c;
1742
- if (p.enum && p.enum.length > 0) {
1743
- const h = p.enum.map((d) => `'${String(d).replace(/'/g, "''")}'`).join(", ");
1744
- a.push(`CHECK ("${c.columnName}" IN (${h}))`);
1756
+ if (c.nullable || (l += " NOT NULL"), c.unique && s.push(
1757
+ `CREATE UNIQUE INDEX "${Lt(t, c)}" on ${n} ("${c.columnName}" ${Xn(c)});`
1758
+ ), c.type === _.enum) {
1759
+ const h = c;
1760
+ if (h.enum && h.enum.length > 0) {
1761
+ const p = h.enum.map((f) => `'${String(f).replace(/'/g, "''")}'`).join(", ");
1762
+ a.push(`CHECK ("${c.columnName}" IN (${p}))`);
1745
1763
  }
1746
1764
  }
1747
- i.push(u);
1765
+ o.push(l);
1748
1766
  });
1749
- const o = [...i, ...a];
1750
- if (o.length)
1751
- r += o.map((c) => `
1767
+ const i = [...o, ...a];
1768
+ if (i.length)
1769
+ r += i.map((c) => `
1752
1770
  ${c}`).join(","), r += `
1753
1771
  );`;
1754
1772
  else
@@ -1756,15 +1774,15 @@ ${c}`).join(","), r += `
1756
1774
  return s.length && (r += `
1757
1775
  ` + s.join(`
1758
1776
  `)), r;
1759
- }, ua = (e, t) => {
1777
+ }, ha = (e, t) => {
1760
1778
  let n = "";
1761
1779
  const r = P(t);
1762
1780
  return t.indexes && t.indexes.length > 0 && t.indexes.forEach((s) => {
1763
- const a = `idx_${t.tableName}_${s.name}`, i = s.properties?.map((c) => `"${c}"`).join(", ") || `"${s.name}"`, o = s.unique ? "UNIQUE " : "";
1781
+ const a = `idx_${t.tableName}_${s.name}`, o = s.properties?.map((c) => `"${c}"`).join(", ") || `"${s.name}"`, i = s.unique ? "UNIQUE " : "";
1764
1782
  n += `
1765
- CREATE ${o}INDEX "${a}" ON ${r}(${i});`;
1783
+ CREATE ${i}INDEX "${a}" ON ${r}(${o});`;
1766
1784
  }), n;
1767
- }, ha = (e, t) => {
1785
+ }, fa = (e, t) => {
1768
1786
  let n = "";
1769
1787
  const r = P(t);
1770
1788
  return Array.from(t.relationMap.values()).forEach((s) => {
@@ -1773,51 +1791,49 @@ CREATE ${o}INDEX "${a}" ON ${r}(${i});`;
1773
1791
  case B.MANY_TO_ONE:
1774
1792
  {
1775
1793
  const a = s.columnName;
1776
- let i = "uuid";
1794
+ let o = "uuid";
1777
1795
  if (s.mappedEntity)
1778
1796
  try {
1779
- const c = e.rxdb.schemaManager.getEntityMetadata(
1797
+ const i = e.rxdb.schemaManager.getEntityMetadata(
1780
1798
  s.mappedEntity,
1781
1799
  s.mappedNamespace
1782
1800
  );
1783
- if (c) {
1784
- const u = Array.from(c.propertyMap.values()).find(
1801
+ if (i) {
1802
+ const c = Array.from(i.propertyMap.values()).find(
1785
1803
  (l) => l.primary
1786
1804
  );
1787
- u && (i = vt(u));
1805
+ c && (o = Ct(c));
1788
1806
  }
1789
1807
  } catch {
1790
1808
  }
1791
1809
  if (n += `
1792
- ALTER TABLE ${r} ADD COLUMN "${a}" ${i}`, s.nullable || (n += " NOT NULL"), s.kind === B.MANY_TO_ONE && Reflect.get(s, "default") !== void 0) {
1793
- const c = s;
1794
- let u = c.default;
1795
- It(c.default) && (u = c.default()), n += ` DEFAULT '${u}'`;
1810
+ ALTER TABLE ${r} ADD COLUMN "${a}" ${o}`, s.nullable || (n += " NOT NULL"), s.kind === B.MANY_TO_ONE && Reflect.get(s, "default") !== void 0) {
1811
+ const i = s;
1812
+ let c = i.default;
1813
+ Ot(i.default) && (c = i.default()), n += ` DEFAULT '${c}'`;
1796
1814
  }
1797
- n += ";";
1798
- const o = s.mappedEntity === t.name;
1799
- if (s.mappedEntity && !o) {
1800
- const c = e.rxdb.schemaManager.getEntityMetadata(
1815
+ if (n += ";", s.mappedEntity) {
1816
+ const i = e.rxdb.schemaManager.getEntityMetadata(
1801
1817
  s.mappedEntity,
1802
1818
  s.mappedNamespace
1803
- ), u = Ot(
1804
- c?.tableName ?? s.mappedEntity,
1819
+ ), c = Dt(
1820
+ i?.tableName ?? s.mappedEntity,
1805
1821
  s.mappedNamespace || t.namespace
1806
1822
  ), l = `${r}_${a}_fk`.replace(/"/g, "");
1807
1823
  n += `
1808
- ALTER TABLE ${r} ADD CONSTRAINT "${l}" FOREIGN KEY ("${a}") REFERENCES ${u}(id)`, s.onDelete ? n += ` ON DELETE ${s.onDelete}` : s.kind === B.MANY_TO_ONE && (s.nullable ? n += " ON DELETE SET NULL" : n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
1824
+ ALTER TABLE ${r} ADD CONSTRAINT "${l}" FOREIGN KEY ("${a}") REFERENCES ${c}(id)`, s.onDelete ? n += ` ON DELETE ${s.onDelete}` : s.kind === B.MANY_TO_ONE && (s.nullable ? n += " ON DELETE SET NULL" : n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
1809
1825
  }
1810
1826
  (s.unique || s.kind === B.ONE_TO_ONE) && (n += `
1811
- CREATE UNIQUE INDEX "${Dt(t, s)}" ON ${r}("${a}");`);
1827
+ CREATE UNIQUE INDEX "${Lt(t, s)}" ON ${r}("${a}");`);
1812
1828
  }
1813
1829
  break;
1814
1830
  }
1815
1831
  }), n;
1816
- }, Mn = (e, t) => {
1832
+ }, qn = (e, t) => {
1817
1833
  let n = "";
1818
- return n += la(e, t), n += ha(e, t), n += ua(e, t), n;
1834
+ return n += ua(e, t), n += fa(e, t), n += ha(e, t), n;
1819
1835
  };
1820
- function fa() {
1836
+ function da() {
1821
1837
  return `
1822
1838
  -- 创建触发器函数(如果不存在)
1823
1839
  CREATE OR REPLACE FUNCTION notify_change()
@@ -1857,7 +1873,7 @@ END;
1857
1873
  $$ LANGUAGE plpgsql;
1858
1874
  `.trim();
1859
1875
  }
1860
- function qn(e) {
1876
+ function Pn(e) {
1861
1877
  const t = `${e}_notify_trigger`;
1862
1878
  return `
1863
1879
  -- 只在表存在时创建触发器
@@ -1881,35 +1897,35 @@ BEGIN
1881
1897
  END $$;
1882
1898
  `.trim();
1883
1899
  }
1884
- function Oa(e) {
1900
+ function Da(e) {
1885
1901
  return `DROP TRIGGER IF EXISTS "${`${e}_notify_trigger`}" ON "${e}";`;
1886
1902
  }
1887
- function da(e = ["RxDBChange", "RxDBBranch", "RxDBMigration"]) {
1903
+ function pa(e = ["rxdb_change", "rxdb_branch", "rxdb_migration"]) {
1888
1904
  const t = [];
1889
- t.push(fa());
1905
+ t.push(da());
1890
1906
  for (const n of e)
1891
- t.push(qn(n));
1907
+ t.push(Pn(n));
1892
1908
  return t.join(`
1893
1909
 
1894
1910
  `);
1895
1911
  }
1896
- function $e(e, t = {}) {
1897
- const n = P(e), r = D(ie), s = P(r), {
1912
+ function be(e, t = {}) {
1913
+ const n = P(e), r = C(le), s = P(r), {
1898
1914
  propertyMap: a,
1899
- name: i,
1900
- tableName: o,
1915
+ name: o,
1916
+ tableName: i,
1901
1917
  foreignKeyNames: c,
1902
- foreignKeyColumnNames: u,
1903
- namespace: l
1904
- } = e, { branchId: p, transactionId: h } = t, d = `"${o}_change_trigger"`, y = [];
1905
- for (const [m, g] of a)
1906
- m !== "id" && y.push({ jsName: m, dbColumn: g.columnName });
1907
- const A = u || c;
1908
- for (let m = 0; m < c.length; m++)
1909
- c[m] !== "id" && y.push({ jsName: c[m], dbColumn: A[m] });
1910
- const $ = 'type, namespace, entity, "branchId", "transactionId", "entityId", "inversePatch", patch', R = h ? `'${h}'` : "NULL", I = p || "main", E = `"${l}"."${o}_change_trigger_fn"`, _ = `'${l}','${i}','${I}',${R}`, T = `
1918
+ foreignKeyColumnNames: l,
1919
+ namespace: u
1920
+ } = e, { branchId: h, transactionId: p } = t, f = `"${i}_change_trigger"`, E = [];
1921
+ for (const [T, N] of a)
1922
+ T !== "id" && E.push({ jsName: T, dbColumn: N.columnName });
1923
+ const $ = l || c;
1924
+ for (let T = 0; T < c.length; T++)
1925
+ c[T] !== "id" && E.push({ jsName: c[T], dbColumn: $[T] });
1926
+ const A = 'type, namespace, entity, "branchId", "transactionId", "entityId", "inversePatch", patch', b = p ? `'${p}'` : "NULL", R = h || "main", m = `"${u}"."${i}_change_trigger_fn"`, y = `'${u}','${o}','${R}',${b}`, g = `
1911
1927
  -- 创建或替换触发器函数
1912
- CREATE OR REPLACE FUNCTION ${E}()
1928
+ CREATE OR REPLACE FUNCTION ${m}()
1913
1929
  RETURNS TRIGGER AS $$
1914
1930
  DECLARE
1915
1931
  old_values JSONB;
@@ -1917,32 +1933,34 @@ DECLARE
1917
1933
  BEGIN
1918
1934
  -- INSERT 操作
1919
1935
  IF (TG_OP = 'INSERT') THEN
1920
- INSERT INTO ${s} (${$})
1936
+ INSERT INTO ${s} (${A})
1921
1937
  VALUES (
1922
1938
  'INSERT',
1923
- ${_},
1939
+ ${y},
1924
1940
  NEW.id,
1925
1941
  NULL,
1926
- jsonb_build_object(${y.map((m) => `'${m.jsName}', NEW."${m.dbColumn}"`).join(", ")})
1942
+ jsonb_build_object(${E.map((T) => `'${T.jsName}', NEW."${T.dbColumn}"`).join(", ")})
1927
1943
  );
1928
1944
  RETURN NEW;
1929
1945
 
1930
1946
  -- UPDATE 操作
1931
1947
  ELSIF (TG_OP = 'UPDATE') THEN
1932
1948
  -- 只在字段真正变更时记录
1933
- IF (${y.map((m) => `OLD."${m.dbColumn}" IS DISTINCT FROM NEW."${m.dbColumn}"`).join(" OR ")}) THEN
1934
- -- 构建变更前的值 (inversePatch - 只包含变更的字段)
1935
- old_values := jsonb_build_object(${y.map((m) => `'${m.jsName}', CASE WHEN OLD."${m.dbColumn}" IS DISTINCT FROM NEW."${m.dbColumn}" THEN to_jsonb(OLD."${m.dbColumn}") ELSE NULL END`).join(", ")});
1936
- old_values := jsonb_strip_nulls(old_values);
1949
+ IF (${E.map((T) => `OLD."${T.dbColumn}" IS DISTINCT FROM NEW."${T.dbColumn}"`).join(" OR ")}) THEN
1950
+ -- 构建变更前的值 (inversePatch - 只包含变更的字段,保留 NULL 值)
1951
+ old_values := '{}'::jsonb;
1952
+ ${E.map((T) => `IF OLD."${T.dbColumn}" IS DISTINCT FROM NEW."${T.dbColumn}" THEN old_values := old_values || jsonb_build_object('${T.jsName}', to_jsonb(OLD."${T.dbColumn}")); END IF;`).join(`
1953
+ `)}
1937
1954
 
1938
- -- 构建变更后的值 (patch - 只包含变更的字段)
1939
- new_values := jsonb_build_object(${y.map((m) => `'${m.jsName}', CASE WHEN OLD."${m.dbColumn}" IS DISTINCT FROM NEW."${m.dbColumn}" THEN to_jsonb(NEW."${m.dbColumn}") ELSE NULL END`).join(", ")});
1940
- new_values := jsonb_strip_nulls(new_values);
1955
+ -- 构建变更后的值 (patch - 只包含变更的字段,保留 NULL 值)
1956
+ new_values := '{}'::jsonb;
1957
+ ${E.map((T) => `IF OLD."${T.dbColumn}" IS DISTINCT FROM NEW."${T.dbColumn}" THEN new_values := new_values || jsonb_build_object('${T.jsName}', to_jsonb(NEW."${T.dbColumn}")); END IF;`).join(`
1958
+ `)}
1941
1959
 
1942
- INSERT INTO ${s} (${$})
1960
+ INSERT INTO ${s} (${A})
1943
1961
  VALUES (
1944
1962
  'UPDATE',
1945
- ${_},
1963
+ ${y},
1946
1964
  NEW.id,
1947
1965
  old_values,
1948
1966
  new_values
@@ -1952,12 +1970,12 @@ BEGIN
1952
1970
 
1953
1971
  -- DELETE 操作
1954
1972
  ELSIF (TG_OP = 'DELETE') THEN
1955
- INSERT INTO ${s} (${$})
1973
+ INSERT INTO ${s} (${A})
1956
1974
  VALUES (
1957
1975
  'DELETE',
1958
- ${_},
1976
+ ${y},
1959
1977
  OLD.id,
1960
- jsonb_build_object(${y.map((m) => `'${m.jsName}', OLD."${m.dbColumn}"`).join(", ")}),
1978
+ jsonb_build_object(${E.map((T) => `'${T.jsName}', OLD."${T.dbColumn}"`).join(", ")}),
1961
1979
  NULL
1962
1980
  );
1963
1981
  RETURN OLD;
@@ -1965,19 +1983,19 @@ BEGIN
1965
1983
 
1966
1984
  RETURN NULL;
1967
1985
  END;
1968
- $$ LANGUAGE plpgsql;`, b = `
1986
+ $$ LANGUAGE plpgsql;`, S = `
1969
1987
  -- 删除已存在的触发器
1970
- DROP TRIGGER IF EXISTS ${d} ON ${n}`, S = `
1988
+ DROP TRIGGER IF EXISTS ${f} ON ${n}`, I = `
1971
1989
  -- 创建触发器 (监听 INSERT, UPDATE, DELETE)
1972
- CREATE TRIGGER ${d}
1990
+ CREATE TRIGGER ${f}
1973
1991
  AFTER INSERT OR UPDATE OR DELETE ON ${n}
1974
1992
  FOR EACH ROW
1975
- EXECUTE FUNCTION ${E}()`;
1976
- return [T, b, S].join(`
1993
+ EXECUTE FUNCTION ${m}()`;
1994
+ return [g, S, I].join(`
1977
1995
  ---STATEMENT_SEPARATOR---
1978
1996
  `);
1979
1997
  }
1980
- const pa = async (e, t, n) => {
1998
+ const Ea = async (e, t, n) => {
1981
1999
  const r = e.localRxDBBranch(), s = e.localRxDBChange();
1982
2000
  if ((await r.find({
1983
2001
  where: {
@@ -1987,74 +2005,74 @@ const pa = async (e, t, n) => {
1987
2005
  limit: 1
1988
2006
  })).length > 0)
1989
2007
  throw new x(`Branch ID (${t}) already exists`);
1990
- let i;
2008
+ let o;
1991
2009
  if (n) {
1992
2010
  const c = await s.get(n);
1993
2011
  if (!c)
1994
2012
  throw new x(`Change ID (${n}) not found`);
1995
2013
  if (!c.branchId)
1996
2014
  throw new x(`Change record (${n}) has no branchId`);
1997
- i = await r.get(c.branchId);
2015
+ o = await r.get(c.branchId);
1998
2016
  } else
1999
- i = (await r.find({
2017
+ o = (await r.find({
2000
2018
  where: {
2001
2019
  combinator: "and",
2002
2020
  rules: [{ field: "activated", operator: "=", value: !0 }]
2003
2021
  },
2004
2022
  limit: 1
2005
2023
  }))[0];
2006
- if (!i)
2024
+ if (!o)
2007
2025
  throw new x("Source branch not found");
2008
2026
  n || (n = (await s.find({
2009
2027
  where: {
2010
2028
  combinator: "and",
2011
2029
  rules: [
2012
- { field: "branchId", operator: "=", value: i.id },
2030
+ { field: "branchId", operator: "=", value: o.id },
2013
2031
  { field: "revertChangeId", operator: "=", value: null }
2014
2032
  ]
2015
2033
  },
2016
2034
  orderBy: [{ field: "id", sort: "desc" }],
2017
2035
  limit: 1
2018
2036
  }))[0]?.id ?? null);
2019
- const o = new ne();
2020
- return o.id = t, o.activated = !1, o.local = !0, o.remote = !1, o.fromChangeId = n ?? null, o.parentId = i.id, await r.create(o);
2037
+ const i = new re();
2038
+ return i.id = t, i.activated = !1, i.local = !0, i.remote = !1, i.fromChangeId = n ?? null, i.parentId = o.id, await r.create(i);
2021
2039
  };
2022
- function Ea(e) {
2023
- const t = P(e), { tableName: n, namespace: r } = e, s = `"${n}_change_trigger"`, a = `"${r}"."${n}_change_trigger_fn"`, i = `DROP TRIGGER IF EXISTS ${s} ON ${t}`, o = `DROP FUNCTION IF EXISTS ${a}() CASCADE`;
2024
- return [i, o].join(`
2040
+ function ma(e) {
2041
+ const t = P(e), { tableName: n, namespace: r } = e, s = `"${n}_change_trigger"`, a = `"${r}"."${n}_change_trigger_fn"`, o = `DROP TRIGGER IF EXISTS ${s} ON ${t}`, i = `DROP FUNCTION IF EXISTS ${a}() CASCADE`;
2042
+ return [o, i].join(`
2025
2043
  ---STATEMENT_SEPARATOR---
2026
2044
  `);
2027
2045
  }
2028
- function Pn(e) {
2046
+ function Un(e) {
2029
2047
  const t = [];
2030
2048
  return e.rxdb.config.entities.forEach((n) => {
2031
- const r = D(n);
2032
- r.log !== !1 && t.push(Ea(r));
2049
+ const r = C(n);
2050
+ r.log !== !1 && t.push(ma(r));
2033
2051
  }), t.join(`
2034
2052
  ---STATEMENT_SEPARATOR---
2035
2053
  `);
2036
2054
  }
2037
- const He = (e, t, n, r = !1) => {
2055
+ const Ve = (e, t, n, r = !1) => {
2038
2056
  if (!n.rows || n.rows.length === 0)
2039
2057
  return [];
2040
- const s = D(t), a = [], i = e.rxdb.entityManager;
2041
- for (const o of n.rows) {
2042
- const c = Z(s, o), u = c.id;
2043
- let l;
2044
- if (i.hasEntityRef(t, u)) {
2045
- if (l = i.getEntityRef(t, u), s.computedPropertyMap.forEach((d, y) => {
2046
- y in c && (l[y] = c[y]);
2058
+ const s = C(t), a = [], o = e.rxdb.entityManager;
2059
+ for (const i of n.rows) {
2060
+ const c = ee(s, i), l = c.id;
2061
+ let u;
2062
+ if (o.hasEntityRef(t, l)) {
2063
+ if (u = o.getEntityRef(t, l), s.computedPropertyMap.forEach((f, E) => {
2064
+ E in c && (u[E] = c[E]);
2047
2065
  }), r) {
2048
- const d = J(l);
2049
- d.origin = { ...c }, Object.assign(l, c), d.local = !0, d.modified = !1;
2066
+ const f = J(u);
2067
+ f.origin = { ...c }, Object.assign(u, c), f.local = !0, f.modified = !1;
2050
2068
  }
2051
2069
  } else
2052
- l = i.createEntityRef(t, c);
2053
- const h = J(l);
2054
- h.local = !0, h.modified = !1, a.push(l);
2070
+ u = o.createEntityRef(t, c);
2071
+ const p = J(u);
2072
+ p.local = !0, p.modified = !1, a.push(u);
2055
2073
  }
2056
2074
  return a;
2057
- }, ma = (e, t, n) => {
2075
+ }, ya = (e, t, n) => {
2058
2076
  for (const r of n) {
2059
2077
  const s = e.rxdb.entityManager.getEntityRef(t, r);
2060
2078
  if (s) {
@@ -2062,96 +2080,102 @@ const He = (e, t, n, r = !1) => {
2062
2080
  a.local = !1, a.removed = !0, a.modified = !1;
2063
2081
  }
2064
2082
  }
2065
- }, Un = (e, t) => {
2066
- const { deletes: n, inserts: r, updates: s } = t, a = { deletes: [], inserts: [], updates: [] }, i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
2067
- for (const [h, d] of n.entries()) {
2068
- const [y, A, $] = Ae(h), R = `${y}:${A}`, I = i.get(R);
2069
- I ? I.add($) : i.set(R, /* @__PURE__ */ new Set([$]));
2070
- let E = o.get(R);
2071
- E || (E = /* @__PURE__ */ new Map(), o.set(R, E)), E.set($, {
2072
- patch: d.patch,
2073
- inversePatch: d.inversePatch
2083
+ }, X = (e, t) => {
2084
+ if (!e) return null;
2085
+ const n = { ...e };
2086
+ for (const r of Object.keys(n)) {
2087
+ const s = t.propertyMap.get(r);
2088
+ s && (n[r] = ae(n[r], s));
2089
+ }
2090
+ return n;
2091
+ }, jn = (e, t) => {
2092
+ const { deletes: n, inserts: r, updates: s } = t, a = { deletes: [], inserts: [], updates: [] }, o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
2093
+ for (const [p, f] of n.entries()) {
2094
+ const [E, $, A] = Re(p), b = `${E}:${$}`, R = o.get(b);
2095
+ R ? R.add(A) : o.set(b, /* @__PURE__ */ new Set([A]));
2096
+ let m = i.get(b);
2097
+ m || (m = /* @__PURE__ */ new Map(), i.set(b, m));
2098
+ const y = e.rxdb.schemaManager.getEntityMetadata($, E);
2099
+ m.set(A, {
2100
+ patch: y ? X(f.patch, y) : f.patch,
2101
+ inversePatch: y ? X(f.inversePatch, y) : f.inversePatch
2074
2102
  });
2075
2103
  }
2076
- for (const [h, d] of i) {
2077
- const [y, A] = h.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(A, y), R = P($), I = $.propertyMap.get("id").type === "integer", E = Array.from(d), _ = I ? `DELETE FROM ${R} WHERE id = ANY($1::integer[]);` : `DELETE FROM ${R} WHERE id = ANY($1);`;
2104
+ for (const [p, f] of o) {
2105
+ const [E, $] = p.split(":"), A = e.rxdb.schemaManager.getEntityMetadata($, E), b = P(A), R = A.propertyMap.get("id").type === "integer", m = Array.from(f), y = R ? `DELETE FROM ${b} WHERE id = ANY($1::integer[]);` : `DELETE FROM ${b} WHERE id = ANY($1);`;
2078
2106
  a.deletes.push({
2079
- metadata: $,
2080
- ids: d,
2081
- sql: _,
2082
- params: [E],
2083
- changes: o.get(h)
2107
+ metadata: A,
2108
+ ids: f,
2109
+ sql: y,
2110
+ params: [m],
2111
+ changes: i.get(p)
2084
2112
  });
2085
2113
  }
2086
- const c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2087
- for (const [h, d] of r.entries()) {
2088
- const [y, A, $] = Ae(h), R = `${y}:${A}`, I = c.get(R), E = { ...d.patch, id: $ };
2089
- I ? I.push(E) : c.set(R, [E]);
2090
- let _ = u.get(R);
2091
- _ || (_ = /* @__PURE__ */ new Map(), u.set(R, _)), _.set($, {
2092
- patch: d.patch,
2093
- inversePatch: d.inversePatch
2114
+ const c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
2115
+ for (const [p, f] of r.entries()) {
2116
+ const [E, $, A] = Re(p), b = `${E}:${$}`, R = c.get(b), m = { ...f.patch, id: A };
2117
+ R ? R.push(m) : c.set(b, [m]);
2118
+ let y = l.get(b);
2119
+ y || (y = /* @__PURE__ */ new Map(), l.set(b, y));
2120
+ const g = e.rxdb.schemaManager.getEntityMetadata($, E);
2121
+ y.set(A, {
2122
+ patch: g ? X(f.patch, g) : f.patch,
2123
+ inversePatch: g ? X(f.inversePatch, g) : f.inversePatch
2094
2124
  });
2095
2125
  }
2096
- for (const [h, d] of c) {
2097
- const [y, A] = h.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(A, y), R = [];
2098
- d.forEach((E) => {
2099
- for (const [S, m] of $.propertyMap)
2100
- E[S] === void 0 && m.default !== void 0 && (typeof m.default == "function" ? E[S] = m.default() : E[S] = m.default);
2101
- const { sql: _, params: T } = Sn($, E, { returning: !1 }), b = _.replace(";", ya($));
2102
- R.push(nt(b, T));
2126
+ for (const [p, f] of c) {
2127
+ const [E, $] = p.split(":"), A = e.rxdb.schemaManager.getEntityMetadata($, E), b = [];
2128
+ f.forEach((m) => {
2129
+ for (const [I, T] of A.propertyMap)
2130
+ m[I] === void 0 && T.default !== void 0 && (typeof T.default == "function" ? m[I] = T.default() : m[I] = T.default);
2131
+ const { sql: y, params: g } = In(A, m, { returning: !1 }), S = y.replace(";", ga(A));
2132
+ b.push(st(S, g));
2103
2133
  });
2104
- const I = R.join("---STATEMENT_SEPARATOR---");
2134
+ const R = b.join("---STATEMENT_SEPARATOR---");
2105
2135
  a.inserts.push({
2106
- metadata: $,
2107
- ids: new Set(d.filter((E) => E != null).map((E) => E.id)),
2108
- sql: I,
2136
+ metadata: A,
2137
+ ids: new Set(f.filter((m) => m != null).map((m) => m.id)),
2138
+ sql: R,
2109
2139
  params: [],
2110
2140
  // 已经内联到 SQL 中
2111
- changes: u.get(h)
2141
+ changes: l.get(p)
2112
2142
  });
2113
2143
  }
2114
- const l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
2115
- for (const [h, d] of s.entries()) {
2116
- const [y, A, $] = Ae(h), R = `${y}:${A}`, I = l.get(R), E = { ...d.patch, id: $ };
2117
- I ? I.push(E) : l.set(R, [E]);
2118
- let _ = p.get(R);
2119
- _ || (_ = /* @__PURE__ */ new Map(), p.set(R, _));
2120
- const T = e.rxdb.schemaManager.getEntityMetadata(A, y), b = d.patch ? { ...d.patch } : null, S = d.inversePatch ? { ...d.inversePatch } : null;
2121
- T && (b && Object.keys(b).forEach((m) => {
2122
- const g = T.propertyMap.get(m);
2123
- g && (b[m] = Le(b[m], g));
2124
- }), S && Object.keys(S).forEach((m) => {
2125
- const g = T.propertyMap.get(m);
2126
- g && (S[m] = Le(S[m], g));
2127
- })), _.set($, {
2128
- patch: b,
2129
- inversePatch: S
2144
+ const u = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
2145
+ for (const [p, f] of s.entries()) {
2146
+ const [E, $, A] = Re(p), b = `${E}:${$}`, R = u.get(b), m = { ...f.patch, id: A };
2147
+ R ? R.push(m) : u.set(b, [m]);
2148
+ let y = h.get(b);
2149
+ y || (y = /* @__PURE__ */ new Map(), h.set(b, y));
2150
+ const g = e.rxdb.schemaManager.getEntityMetadata($, E);
2151
+ y.set(A, {
2152
+ patch: g ? X(f.patch, g) : f.patch,
2153
+ inversePatch: g ? X(f.inversePatch, g) : f.inversePatch
2130
2154
  });
2131
2155
  }
2132
- for (const [h, d] of l) {
2133
- const [y, A] = h.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(A, y), R = [];
2134
- d.forEach((E) => {
2135
- let _;
2136
- $.propertyMap.has("updatedAt") && (_ = E.updatedAt);
2137
- const { id: T, ...b } = E, { sql: S, params: m } = ze($, { id: T }, b, {
2138
- updatedAt: _,
2156
+ for (const [p, f] of u) {
2157
+ const [E, $] = p.split(":"), A = e.rxdb.schemaManager.getEntityMetadata($, E), b = [];
2158
+ f.forEach((m) => {
2159
+ let y;
2160
+ A.propertyMap.has("updatedAt") && (y = m.updatedAt);
2161
+ const { id: g, ...S } = m, { sql: I, params: T } = Ze(A, { id: g }, S, {
2162
+ updatedAt: y,
2139
2163
  returning: !1
2140
2164
  });
2141
- R.push(nt(S, m));
2165
+ b.push(st(I, T));
2142
2166
  });
2143
- const I = R.join("---STATEMENT_SEPARATOR---");
2167
+ const R = b.join("---STATEMENT_SEPARATOR---");
2144
2168
  a.updates.push({
2145
- metadata: $,
2146
- ids: new Set(d.filter((E) => E != null).map((E) => E.id)),
2147
- sql: I,
2169
+ metadata: A,
2170
+ ids: new Set(f.filter((m) => m != null).map((m) => m.id)),
2171
+ sql: R,
2148
2172
  params: [],
2149
2173
  // 已经内联到 SQL 中
2150
- changes: p.get(h)
2174
+ changes: h.get(p)
2151
2175
  });
2152
2176
  }
2153
2177
  return a;
2154
- }, ya = (e) => ` ON CONFLICT (id) DO UPDATE SET ${Array.from(e.propertyMap.values()).filter((n) => n.name !== "id" && n.name !== "createdAt" && n.name !== "createdBy").map((n) => `"${n.columnName}" = EXCLUDED."${n.columnName}"`).join(", ")};`;
2178
+ }, ga = (e) => ` ON CONFLICT (id) DO UPDATE SET ${Array.from(e.propertyMap.values()).filter((n) => n.name !== "id" && n.name !== "createdAt" && n.name !== "createdBy").map((n) => `"${n.columnName}" = EXCLUDED."${n.columnName}"`).join(", ")};`;
2155
2179
  function _a(e) {
2156
2180
  return {
2157
2181
  rows: e.rows,
@@ -2159,21 +2183,21 @@ function _a(e) {
2159
2183
  elapsed: 0
2160
2184
  };
2161
2185
  }
2162
- const jn = (e, t) => {
2186
+ const xn = (e, t) => {
2163
2187
  const n = [];
2164
- e.rxdb.config.entities.forEach((o) => {
2165
- const c = D(o);
2188
+ e.rxdb.config.entities.forEach((i) => {
2189
+ const c = C(i);
2166
2190
  if (c.log !== !1)
2167
2191
  try {
2168
- const u = $e(c, {
2192
+ const l = be(c, {
2169
2193
  branchId: t
2170
2194
  });
2171
- u.trim() && n.push(u);
2172
- } catch (u) {
2173
- console.warn(`Failed to generate trigger SQL for entity ${c.name}:`, u);
2195
+ l.trim() && n.push(l);
2196
+ } catch (l) {
2197
+ console.warn(`Failed to generate trigger SQL for entity ${c.name}:`, l);
2174
2198
  }
2175
2199
  });
2176
- const r = D(ne), s = P(r), a = t.replace(/'/g, "''"), i = `
2200
+ const r = C(re), s = P(r), a = t.replace(/'/g, "''"), o = `
2177
2201
  UPDATE ${s}
2178
2202
  SET
2179
2203
  activated = CASE
@@ -2186,161 +2210,161 @@ const jn = (e, t) => {
2186
2210
  END
2187
2211
  WHERE id = '${a}' OR activated = TRUE
2188
2212
  RETURNING *`;
2189
- return n.push(i), n.join(`
2213
+ return n.push(o), n.join(`
2190
2214
  ---STATEMENT_SEPARATOR---
2191
2215
  `);
2192
- }, ga = async (e, t) => {
2193
- const { branchId: n, actions: r } = t, s = r && Un(e, r);
2216
+ }, Ta = async (e, t) => {
2217
+ const { branchId: n, actions: r } = t, s = r && jn(e, r);
2194
2218
  let a;
2195
2219
  try {
2196
2220
  await e.transaction(async () => {
2197
- const u = Pn(e);
2198
- if (u) {
2199
- const l = u.split("---STATEMENT_SEPARATOR---").filter((p) => p.trim());
2200
- for (const p of l)
2201
- await e.query(p.trim());
2221
+ const l = Un(e);
2222
+ if (l) {
2223
+ const u = l.split("---STATEMENT_SEPARATOR---").filter((h) => h.trim());
2224
+ for (const h of u)
2225
+ await e.query(h.trim());
2202
2226
  }
2203
2227
  if (s) {
2204
2228
  if (s.deletes.length)
2205
- for (const l of s.deletes)
2206
- l.params.length > 0 ? await e.query(l.sql, l.params) : await e.query(l.sql);
2229
+ for (const u of s.deletes)
2230
+ u.params.length > 0 ? await e.query(u.sql, u.params) : await e.query(u.sql);
2207
2231
  if (s.inserts.length)
2208
- for (const l of s.inserts)
2209
- l.successResults = await e.query(l.sql);
2232
+ for (const u of s.inserts)
2233
+ u.successResults = await e.query(u.sql);
2210
2234
  if (s.updates.length)
2211
- for (const l of s.updates)
2212
- l.successResults = await e.query(l.sql);
2235
+ for (const u of s.updates)
2236
+ u.successResults = await e.query(u.sql);
2213
2237
  }
2214
2238
  r?.updateRxDBChangeSequence !== void 0 && await e.setRxDBChangeSequence(r.updateRxDBChangeSequence);
2215
2239
  }, !1);
2216
- const o = jn(e, n).split("---STATEMENT_SEPARATOR---").filter((u) => u.trim());
2217
- for (const u of o) {
2218
- const l = await e.query(u.trim());
2219
- u.includes("RETURNING") && (a = l);
2240
+ const i = xn(e, n).split("---STATEMENT_SEPARATOR---").filter((l) => l.trim());
2241
+ for (const l of i) {
2242
+ const u = await e.query(l.trim());
2243
+ l.includes("RETURNING") && (a = u);
2220
2244
  }
2221
- const c = (u, l) => {
2222
- if (l.length === 0) return;
2223
- const p = l.map((h) => {
2224
- const d = { ...h };
2245
+ const c = (l, u) => {
2246
+ if (u.length === 0) return;
2247
+ const h = u.map((p) => {
2248
+ const f = { ...p };
2225
2249
  return {
2226
- namespace: u.namespace,
2227
- entity: u.name,
2250
+ namespace: l.namespace,
2251
+ entity: l.name,
2228
2252
  type: "UPDATE",
2229
- id: h.id,
2230
- patch: d,
2231
- inversePatch: d,
2232
- recordAt: h.createdAt
2253
+ id: p.id,
2254
+ patch: f,
2255
+ inversePatch: f,
2256
+ recordAt: p.createdAt
2233
2257
  };
2234
2258
  });
2235
- e.rxdb.dispatchEvent(new me(p));
2259
+ e.rxdb.dispatchEvent(new ge(h));
2236
2260
  };
2237
2261
  if (a) {
2238
- const u = _a(a), l = He(e, ne, u, !0), p = D(ne);
2239
- c(p, l);
2262
+ const l = _a(a), u = Ve(e, re, l, !0), h = C(re);
2263
+ c(h, u);
2240
2264
  }
2241
- s && xn(e, s);
2242
- } catch (i) {
2243
- throw new x(`switch branch ${n} failed: ` + i);
2265
+ s && Fn(e, s);
2266
+ } catch (o) {
2267
+ throw new x(`switch branch ${n} failed: ` + o);
2244
2268
  }
2245
2269
  };
2246
- async function Ta(e, t, n, r = !1) {
2270
+ async function wa(e, t, n, r = !1) {
2247
2271
  if (await e.transaction(async () => {
2248
2272
  if (r) {
2249
- const s = Pn(e);
2273
+ const s = Un(e);
2250
2274
  if (s) {
2251
- const a = s.split("---STATEMENT_SEPARATOR---").filter((i) => i.trim());
2252
- for (const i of a)
2253
- await e.query(i.trim());
2275
+ const a = s.split("---STATEMENT_SEPARATOR---").filter((o) => o.trim());
2276
+ for (const o of a)
2277
+ await e.query(o.trim());
2254
2278
  }
2255
2279
  }
2256
2280
  for (const s of t.deletes)
2257
2281
  s.params.length > 0 ? await e.query(s.sql, s.params) : await e.query(s.sql);
2258
2282
  for (const s of t.inserts) {
2259
- const a = s.sql.split("---STATEMENT_SEPARATOR---").filter((i) => i.trim());
2260
- for (const i of a)
2261
- await e.query(i.trim());
2283
+ const a = s.sql.split("---STATEMENT_SEPARATOR---").filter((o) => o.trim());
2284
+ for (const o of a)
2285
+ await e.query(o.trim());
2262
2286
  s.successResults = { rows: [], affectedRows: a.length, fields: [] };
2263
2287
  }
2264
2288
  for (const s of t.updates) {
2265
- const a = s.sql.split("---STATEMENT_SEPARATOR---").filter((i) => i.trim());
2266
- for (const i of a)
2267
- await e.query(i.trim());
2289
+ const a = s.sql.split("---STATEMENT_SEPARATOR---").filter((o) => o.trim());
2290
+ for (const o of a)
2291
+ await e.query(o.trim());
2268
2292
  s.successResults = { rows: [], affectedRows: a.length, fields: [] };
2269
2293
  }
2270
2294
  }, !1), r) {
2271
- const s = await e.rxdb.versionManager.getCurrentBranch(), i = jn(e, s.id).split("---STATEMENT_SEPARATOR---").filter((o) => o.trim());
2272
- for (const o of i)
2273
- await e.query(o.trim());
2295
+ const s = await e.rxdb.versionManager.getCurrentBranch(), o = xn(e, s.id).split("---STATEMENT_SEPARATOR---").filter((i) => i.trim());
2296
+ for (const i of o)
2297
+ await e.query(i.trim());
2274
2298
  }
2275
- xn(e, t);
2299
+ Fn(e, t);
2276
2300
  }
2277
- function xn(e, t) {
2301
+ function Fn(e, t) {
2278
2302
  for (const n of t.deletes) {
2279
- const r = Re(n.metadata);
2280
- ma(e, r, Array.from(n.ids));
2281
- const s = n.metadata, a = Array.from(n.ids).map((i) => {
2282
- const o = n.changes.get(String(i));
2303
+ const r = Se(n.metadata);
2304
+ ya(e, r, Array.from(n.ids));
2305
+ const s = n.metadata, a = Array.from(n.ids).map((o) => {
2306
+ const i = n.changes.get(String(o));
2283
2307
  return {
2284
2308
  namespace: s.namespace,
2285
2309
  entity: s.name,
2286
2310
  type: "DELETE",
2287
- id: i,
2311
+ id: o,
2288
2312
  patch: null,
2289
- inversePatch: o?.inversePatch ?? null,
2313
+ inversePatch: i?.inversePatch ?? null,
2290
2314
  recordAt: /* @__PURE__ */ new Date()
2291
2315
  };
2292
2316
  });
2293
- e.rxdb.dispatchEvent(new Ve(a));
2317
+ e.rxdb.dispatchEvent(new Ke(a));
2294
2318
  }
2295
2319
  for (const n of t.inserts) {
2296
- const r = Re(n.metadata), s = bt(n.successResults), a = He(e, r, s), i = n.metadata, o = a.map((c) => {
2297
- const u = n.changes.get(String(c.id));
2320
+ const r = Se(n.metadata), s = St(n.successResults), a = Ve(e, r, s), o = n.metadata, i = a.map((c) => {
2321
+ const l = n.changes.get(String(c.id));
2298
2322
  return {
2299
- namespace: i.namespace,
2300
- entity: i.name,
2323
+ namespace: o.namespace,
2324
+ entity: o.name,
2301
2325
  type: "INSERT",
2302
2326
  id: c.id,
2303
- patch: u?.patch ?? { ...c },
2304
- inversePatch: u?.inversePatch ?? null,
2327
+ patch: l?.patch ?? { ...c },
2328
+ inversePatch: l?.inversePatch ?? null,
2305
2329
  recordAt: c.createdAt
2306
2330
  };
2307
2331
  });
2308
- e.rxdb.dispatchEvent(new oe(o));
2332
+ e.rxdb.dispatchEvent(new ue(i));
2309
2333
  }
2310
2334
  for (const n of t.updates) {
2311
- const r = Re(n.metadata), s = bt(n.successResults), a = He(e, r, s, !0), i = n.metadata, o = a.map((c) => {
2312
- const u = n.changes.get(String(c.id));
2335
+ const r = Se(n.metadata), s = St(n.successResults), a = Ve(e, r, s, !0), o = n.metadata, i = a.map((c) => {
2336
+ const l = n.changes.get(String(c.id));
2313
2337
  return {
2314
- namespace: i.namespace,
2315
- entity: i.name,
2338
+ namespace: o.namespace,
2339
+ entity: o.name,
2316
2340
  type: "UPDATE",
2317
2341
  id: c.id,
2318
- patch: u?.patch ?? { ...c },
2319
- inversePatch: u?.inversePatch ?? null,
2342
+ patch: l?.patch ?? { ...c },
2343
+ inversePatch: l?.inversePatch ?? null,
2320
2344
  recordAt: c.updatedAt || c.createdAt || /* @__PURE__ */ new Date()
2321
2345
  };
2322
2346
  });
2323
- e.rxdb.dispatchEvent(new me(o));
2347
+ e.rxdb.dispatchEvent(new ge(i));
2324
2348
  }
2325
2349
  }
2326
- function bt(e) {
2350
+ function St(e) {
2327
2351
  return {
2328
2352
  rows: e.rows,
2329
2353
  rowsAffected: e.affectedRows ?? e.rows.length,
2330
2354
  elapsed: 0
2331
2355
  };
2332
2356
  }
2333
- function St(e, t, n) {
2357
+ function It(e, t, n) {
2334
2358
  const r = [];
2335
2359
  return e.rxdb.config.entities.forEach((s) => {
2336
- const a = D(s);
2360
+ const a = C(s);
2337
2361
  if (a.log !== !1) {
2338
- const o = $e(a, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((c) => c.trim()).filter((c) => c.length > 0);
2339
- r.push(...o);
2362
+ const i = be(a, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((c) => c.trim()).filter((c) => c.length > 0);
2363
+ r.push(...i);
2340
2364
  }
2341
2365
  }), r;
2342
2366
  }
2343
- class va extends Bn {
2367
+ class Ca extends kn {
2344
2368
  /**
2345
2369
  * 构造函数
2346
2370
  *
@@ -2351,21 +2375,21 @@ class va extends Bn {
2351
2375
  super(t), this.options = n;
2352
2376
  }
2353
2377
  /** 销毁信号主题,用于清理资源 */
2354
- #e = new Kn();
2378
+ #e = new Jn();
2355
2379
  /** 仓库实例缓存,避免重复创建 */
2356
2380
  #s = /* @__PURE__ */ new Map();
2357
2381
  /** PGlite 客户端缓存 */
2358
- #i;
2382
+ #o;
2359
2383
  /** 事务锁标志,防止事务嵌套 */
2360
2384
  #t = !1;
2361
2385
  /** 查询任务队列执行器,确保查询按顺序执行 */
2362
- #r = new Hn(1);
2386
+ #r = new Vn(1);
2363
2387
  /** 客户端初始化 Promise,确保单例 */
2364
- #o;
2388
+ #c;
2365
2389
  /** 当前活跃的事务对象 */
2366
2390
  #a;
2367
2391
  /** 适配器名称 */
2368
- name = Yn;
2392
+ name = Qn;
2369
2393
  /**
2370
2394
  * 批量获取实体元数据(QueryCache 专用)
2371
2395
  *
@@ -2376,16 +2400,16 @@ class va extends Bn {
2376
2400
  * @returns Observable<Map<string, string>> - id → updatedAt 映射
2377
2401
  */
2378
2402
  getMetadataByIds(t, n) {
2379
- return be(() => {
2403
+ return Ie(() => {
2380
2404
  if (n.length === 0)
2381
- return Se(/* @__PURE__ */ new Map());
2405
+ return Oe(/* @__PURE__ */ new Map());
2382
2406
  const a = `SELECT id, "updatedAt" FROM "public"."${this.rxdb.schemaManager.getEntityMetadata(t, "public")?.tableName ?? t}" WHERE id = ANY($1)`;
2383
- return Ie(this.internalQuery(a, [n])).pipe(
2384
- Jn((i) => {
2385
- const o = /* @__PURE__ */ new Map();
2386
- for (const c of i.rows)
2387
- o.set(c.id, c.updatedAt);
2388
- return o;
2407
+ return De(this.internalQuery(a, [n])).pipe(
2408
+ Yn((o) => {
2409
+ const i = /* @__PURE__ */ new Map();
2410
+ for (const c of o.rows)
2411
+ i.set(c.id, c.updatedAt);
2412
+ return i;
2389
2413
  })
2390
2414
  );
2391
2415
  });
@@ -2400,12 +2424,12 @@ class va extends Bn {
2400
2424
  * @returns Observable<void>
2401
2425
  */
2402
2426
  upsertMany(t, n) {
2403
- return be(() => n.length === 0 ? Se(void 0) : Ie(
2427
+ return Ie(() => n.length === 0 ? Oe(void 0) : De(
2404
2428
  (async () => {
2405
- const s = this.rxdb.schemaManager.getEntityMetadata(t, "public")?.tableName ?? t, a = Object.keys(n[0]), i = a.map((o) => `"${o}"`).join(", ");
2406
- for (const o of n) {
2407
- const c = a.map((h) => o[h]), u = a.map((h, d) => `$${d + 1}`).join(", "), l = a.filter((h) => h !== "id").map((h) => `"${h}" = EXCLUDED."${h}"`).join(", "), p = `INSERT INTO "public"."${s}" (${i}) VALUES (${u}) ON CONFLICT (id) DO UPDATE SET ${l}`;
2408
- await this.internalQuery(p, c);
2429
+ const s = this.rxdb.schemaManager.getEntityMetadata(t, "public")?.tableName ?? t, a = Object.keys(n[0]), o = a.map((i) => `"${i}"`).join(", ");
2430
+ for (const i of n) {
2431
+ const c = a.map((p) => i[p]), l = a.map((p, f) => `$${f + 1}`).join(", "), u = a.filter((p) => p !== "id").map((p) => `"${p}" = EXCLUDED."${p}"`).join(", "), h = `INSERT INTO "public"."${s}" (${o}) VALUES (${l}) ON CONFLICT (id) DO UPDATE SET ${u}`;
2432
+ await this.internalQuery(h, c);
2409
2433
  }
2410
2434
  })()
2411
2435
  ));
@@ -2418,16 +2442,16 @@ class va extends Bn {
2418
2442
  * @returns Observable<void>
2419
2443
  */
2420
2444
  deleteByIds(t, n) {
2421
- return be(() => {
2445
+ return Ie(() => {
2422
2446
  if (n.length === 0)
2423
- return Se(void 0);
2447
+ return Oe(void 0);
2424
2448
  const a = `DELETE FROM "public"."${this.rxdb.schemaManager.getEntityMetadata(t, "public")?.tableName ?? t}" WHERE id = ANY($1)`;
2425
- return Ie(this.internalQuery(a, [n]).then(() => {
2449
+ return De(this.internalQuery(a, [n]).then(() => {
2426
2450
  }));
2427
2451
  });
2428
2452
  }
2429
2453
  async mutations(t) {
2430
- const n = async () => await ca(this, t);
2454
+ const n = async () => await la(this, t);
2431
2455
  return this.#t ? await n() : await this.transaction(() => n());
2432
2456
  }
2433
2457
  /**
@@ -2441,8 +2465,8 @@ class va extends Bn {
2441
2465
  * @deprecated localChanges 参数已废弃,将在未来版本中移除
2442
2466
  */
2443
2467
  async mergeChanges(t, n, r = !1) {
2444
- const s = Un(this, t);
2445
- await Ta(this, s, n, r);
2468
+ const s = jn(this, t);
2469
+ await wa(this, s, n, r);
2446
2470
  }
2447
2471
  /**
2448
2472
  * 获取 RxDBChange 表当前序列值
@@ -2476,8 +2500,16 @@ class va extends Bn {
2476
2500
  */
2477
2501
  async removeMany(t) {
2478
2502
  if (!t || t.length === 0) return Promise.resolve([]);
2479
- const n = D(t[0].constructor), r = bn(n, t);
2480
- return await this.query(r), t;
2503
+ const n = /* @__PURE__ */ new Map();
2504
+ for (const r of t) {
2505
+ const s = r.constructor;
2506
+ n.has(s) || n.set(s, []), n.get(s).push(r);
2507
+ }
2508
+ for (const [r, s] of n) {
2509
+ const a = C(r), o = Sn(a, s);
2510
+ await this.query(o);
2511
+ }
2512
+ return t;
2481
2513
  }
2482
2514
  /**
2483
2515
  * 批量保存实体
@@ -2500,11 +2532,11 @@ class va extends Bn {
2500
2532
  }
2501
2533
  const r = async () => {
2502
2534
  for (const [s, a] of n.entries()) {
2503
- const i = D(s), o = ue(i, a, this.rxdb.context);
2504
- await this.query(o);
2535
+ const o = C(s), i = de(o, a, this.rxdb.context);
2536
+ await this.query(i);
2505
2537
  for (const c of a) {
2506
- const u = J(c);
2507
- u.local = !0, u.modified = !1;
2538
+ const l = J(c);
2539
+ l.local = !0, l.modified = !1;
2508
2540
  }
2509
2541
  }
2510
2542
  };
@@ -2516,8 +2548,8 @@ class va extends Bn {
2516
2548
  * @returns 适配器实例
2517
2549
  */
2518
2550
  async connect() {
2519
- const t = await this.#n(), n = da();
2520
- return await t.exec(n), t instanceof Rt && (t.addEventListener(K.INSERT, (r) => Ce(this, r)), t.addEventListener(K.UPDATE, (r) => Ce(this, r)), t.addEventListener(K.DELETE, (r) => Ce(this, r))), this;
2551
+ const t = await this.#n(), n = pa();
2552
+ return await t.exec(n), t instanceof Rt && (t.addEventListener(K.INSERT, (r) => Me(this, r)), t.addEventListener(K.UPDATE, (r) => Me(this, r)), t.addEventListener(K.DELETE, (r) => Me(this, r))), this;
2521
2553
  }
2522
2554
  /**
2523
2555
  * 断开数据库连接
@@ -2525,7 +2557,7 @@ class va extends Bn {
2525
2557
  * 清理资源并发送销毁信号
2526
2558
  */
2527
2559
  async disconnect() {
2528
- this.#i && (await this.#i.disconnect(), this.#e.next(), this.#e.complete());
2560
+ this.#o && (await this.#o.disconnect(), this.#e.next(), this.#e.complete());
2529
2561
  }
2530
2562
  /**
2531
2563
  * 创建分支
@@ -2540,7 +2572,7 @@ class va extends Bn {
2540
2572
  * @throws {RxdbAdapterPGliteError} 分支 ID 已存在或源分支未找到
2541
2573
  */
2542
2574
  async createBranch(t, n) {
2543
- return pa(this, t, n);
2575
+ return Ea(this, t, n);
2544
2576
  }
2545
2577
  /**
2546
2578
  * 切换到指定分支
@@ -2551,7 +2583,7 @@ class va extends Bn {
2551
2583
  * @throws {RxdbAdapterPGliteError} 分支切换失败
2552
2584
  */
2553
2585
  async switchBranch(t) {
2554
- return ga(this, t);
2586
+ return Ta(this, t);
2555
2587
  }
2556
2588
  /**
2557
2589
  * 恢复实体到指定状态
@@ -2589,14 +2621,14 @@ class va extends Bn {
2589
2621
  */
2590
2622
  getRepository(t) {
2591
2623
  if (!this.#s.has(t)) {
2592
- const n = D(t);
2624
+ const n = C(t);
2593
2625
  let r;
2594
2626
  switch (n.repository) {
2595
2627
  case "Repository":
2596
- r = new Ln(this, t);
2628
+ r = new Mn(this, t);
2597
2629
  break;
2598
2630
  case "TreeRepository":
2599
- r = new oa(this, t);
2631
+ r = new ca(this, t);
2600
2632
  break;
2601
2633
  default:
2602
2634
  throw new x("Unsupported repository type: " + n.repository);
@@ -2620,48 +2652,57 @@ class va extends Bn {
2620
2652
  * @returns 是否成功创建
2621
2653
  */
2622
2654
  async createTables(t, n) {
2623
- const r = [], s = [];
2655
+ const r = [], s = [], a = /* @__PURE__ */ new Set();
2656
+ for (const i of t) {
2657
+ const c = C(i);
2658
+ c.namespace && c.namespace !== "public" && a.add(c.namespace);
2659
+ }
2660
+ if (a.size > 0) {
2661
+ const i = Array.from(a).map((c) => `CREATE SCHEMA IF NOT EXISTS "${c}"`).join(`;
2662
+ `) + ";";
2663
+ await this.#i(i);
2664
+ }
2624
2665
  for (const i of t) {
2625
- const o = D(i), u = Mn(this, o).split(/;\s*\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("--"));
2626
- for (const l of u)
2627
- l && (l.includes("ADD CONSTRAINT") && l.includes("FOREIGN KEY") ? r.push(l) : s.push(l));
2666
+ const c = C(i), u = qn(this, c).split(/;\s*\n/).map((h) => h.trim()).filter((h) => h.length > 0 && !h.startsWith("--"));
2667
+ for (const h of u)
2668
+ h && (h.includes("ADD CONSTRAINT") && h.includes("FOREIGN KEY") ? r.push(h) : s.push(h));
2628
2669
  }
2629
2670
  if (s.length > 0) {
2630
2671
  const i = s.join(`;
2631
2672
  `) + ";";
2632
- await this.#c(i);
2673
+ await this.#i(i);
2633
2674
  }
2634
2675
  if (r.length > 0) {
2635
2676
  const i = r.join(`;
2636
2677
  `) + ";";
2637
2678
  try {
2638
- await this.#c(i);
2639
- } catch (o) {
2640
- console.warn("Failed to add foreign key constraints:", o);
2679
+ await this.#i(i);
2680
+ } catch (c) {
2681
+ console.warn("Failed to add foreign key constraints:", c);
2641
2682
  }
2642
2683
  }
2643
2684
  for (const i of t) {
2644
- const o = D(i);
2645
- if (o.log !== !1) {
2646
- const c = $e(o);
2647
- await this.#c(c.replace(/---STATEMENT_SEPARATOR---/g, ";"));
2685
+ const c = C(i);
2686
+ if (c.log !== !1) {
2687
+ const l = be(c);
2688
+ await this.#i(l.replace(/---STATEMENT_SEPARATOR---/g, ";"));
2648
2689
  }
2649
2690
  }
2650
2691
  if (n && n.length > 0) {
2651
2692
  const i = /* @__PURE__ */ new Map();
2652
- for (const o of n) {
2653
- const c = o.constructor;
2654
- i.has(c) || i.set(c, []), i.get(c).push(o);
2693
+ for (const c of n) {
2694
+ const l = c.constructor;
2695
+ i.has(l) || i.set(l, []), i.get(l).push(c);
2655
2696
  }
2656
- for (const [o, c] of i) {
2657
- const u = D(o), l = ue(u, c, this.rxdb.context);
2658
- await this.#c(l);
2697
+ for (const [c, l] of i) {
2698
+ const u = C(c), h = de(u, l, this.rxdb.context);
2699
+ await this.#i(h);
2659
2700
  }
2660
2701
  }
2661
- const a = ["rxdb_change", "rxdb_branch", "rxdb_migration"];
2662
- for (const i of a) {
2663
- const o = qn(i);
2664
- await this.#c(o);
2702
+ const o = ["rxdb_change", "rxdb_branch", "rxdb_migration"];
2703
+ for (const i of o) {
2704
+ const c = Pn(i);
2705
+ await this.#i(c);
2665
2706
  }
2666
2707
  return !0;
2667
2708
  }
@@ -2672,7 +2713,7 @@ class va extends Bn {
2672
2713
  * @returns 表是否存在
2673
2714
  */
2674
2715
  async isTableExisted(t) {
2675
- const n = D(t);
2716
+ const n = C(t);
2676
2717
  return (await this.#l(
2677
2718
  `SELECT EXISTS (
2678
2719
  SELECT 1 FROM information_schema.tables
@@ -2688,7 +2729,7 @@ class va extends Bn {
2688
2729
  * @returns 列信息数组
2689
2730
  */
2690
2731
  async getTableColumns(t) {
2691
- const n = D(t);
2732
+ const n = C(t);
2692
2733
  return (await this.#l(
2693
2734
  `SELECT * FROM information_schema.columns
2694
2735
  WHERE table_schema = '${n.namespace}'
@@ -2702,7 +2743,7 @@ class va extends Bn {
2702
2743
  * @returns 分支仓库实例
2703
2744
  */
2704
2745
  localRxDBBranch() {
2705
- return this.getRepository(ne);
2746
+ return this.getRepository(re);
2706
2747
  }
2707
2748
  /**
2708
2749
  * 获取本地变更仓库
@@ -2710,7 +2751,7 @@ class va extends Bn {
2710
2751
  * @returns 变更仓库实例
2711
2752
  */
2712
2753
  localRxDBChange() {
2713
- return this.getRepository(ie);
2754
+ return this.getRepository(le);
2714
2755
  }
2715
2756
  /**
2716
2757
  * 执行事务
@@ -2730,19 +2771,19 @@ class va extends Bn {
2730
2771
  async transaction(t, n = !0) {
2731
2772
  await this.rxdb.connect(this.name);
2732
2773
  const r = await this.#n(), s = n ? crypto.randomUUID() : void 0;
2733
- return await r.transaction(async (i) => {
2734
- if (this.#t = !0, this.#a = i, await i.query("SET CONSTRAINTS ALL DEFERRED"), n && s) {
2735
- const c = St(this, "main", s);
2736
- for (const u of c)
2737
- await i.query(u);
2774
+ return await r.transaction(async (o) => {
2775
+ if (this.#t = !0, this.#a = o, await o.query("SET CONSTRAINTS ALL DEFERRED"), n && s) {
2776
+ const c = It(this, "main", s);
2777
+ for (const l of c)
2778
+ await o.query(l);
2738
2779
  }
2739
- const o = await t();
2780
+ const i = await t();
2740
2781
  if (n && s) {
2741
- const c = St(this, "main");
2742
- for (const u of c)
2743
- await i.query(u);
2782
+ const c = It(this, "main");
2783
+ for (const l of c)
2784
+ await o.query(l);
2744
2785
  }
2745
- return this.#a = void 0, this.#t = !1, o;
2786
+ return this.#a = void 0, this.#t = !1, i;
2746
2787
  });
2747
2788
  }
2748
2789
  /**
@@ -2791,7 +2832,7 @@ class va extends Bn {
2791
2832
  * @param options - 执行选项
2792
2833
  * @returns 执行结果数组
2793
2834
  */
2794
- async #c(t, n) {
2835
+ async #i(t, n) {
2795
2836
  return (await this.#n()).exec(t, n);
2796
2837
  }
2797
2838
  /**
@@ -2802,14 +2843,14 @@ class va extends Bn {
2802
2843
  * @returns PGlite 客户端 Promise
2803
2844
  */
2804
2845
  #n() {
2805
- if (!this.#o) {
2846
+ if (!this.#c) {
2806
2847
  const t = new Rt();
2807
- this.#o = t.init(this.rxdb.config.dbName, this.options).then(() => (this.#i = t, t));
2848
+ this.#c = t.init(this.rxdb.config.dbName, this.options).then(() => (this.#o = t, t));
2808
2849
  }
2809
- return this.#o;
2850
+ return this.#c;
2810
2851
  }
2811
2852
  }
2812
- class wa {
2853
+ class Na {
2813
2854
  getReturningClause() {
2814
2855
  return "RETURNING *";
2815
2856
  }
@@ -2833,13 +2874,13 @@ class wa {
2833
2874
  * @returns SQL 语句
2834
2875
  */
2835
2876
  generateBatchInsert(t, n, r) {
2836
- const s = this.escapeIdentifier(t), a = n.map((c) => this.escapeIdentifier(c)).join(", "), i = [];
2837
- let o = 1;
2877
+ const s = this.escapeIdentifier(t), a = n.map((c) => this.escapeIdentifier(c)).join(", "), o = [];
2878
+ let i = 1;
2838
2879
  for (let c = 0; c < r; c++) {
2839
- const u = n.map(() => this.getParameterPlaceholder(o++)).join(", ");
2840
- i.push(`(${u})`);
2880
+ const l = n.map(() => this.getParameterPlaceholder(i++)).join(", ");
2881
+ o.push(`(${l})`);
2841
2882
  }
2842
- return `INSERT INTO ${s} (${a}) VALUES ${i.join(", ")} ${this.getReturningClause()}`;
2883
+ return `INSERT INTO ${s} (${a}) VALUES ${o.join(", ")} ${this.getReturningClause()}`;
2843
2884
  }
2844
2885
  /**
2845
2886
  * 生成批量更新 SQL(使用 UPDATE ... FROM 模式)
@@ -2849,18 +2890,18 @@ class wa {
2849
2890
  * @returns SQL 模板
2850
2891
  */
2851
2892
  generateBatchUpdate(t, n, r) {
2852
- const s = this.escapeIdentifier(t), a = this.escapeIdentifier(n), i = r.map((o) => `${this.escapeIdentifier(o)} = temp.${this.escapeIdentifier(o)}`).join(", ");
2853
- return `UPDATE ${s} SET ${i} FROM (VALUES ($1)) AS temp(${a}, ${r.join(", ")}) WHERE ${s}.${a} = temp.${a} ${this.getReturningClause()}`;
2893
+ const s = this.escapeIdentifier(t), a = this.escapeIdentifier(n), o = r.map((i) => `${this.escapeIdentifier(i)} = temp.${this.escapeIdentifier(i)}`).join(", ");
2894
+ return `UPDATE ${s} SET ${o} FROM (VALUES ($1)) AS temp(${a}, ${r.join(", ")}) WHERE ${s}.${a} = temp.${a} ${this.getReturningClause()}`;
2854
2895
  }
2855
2896
  }
2856
- const Da = new wa();
2857
- function Ca(e, t, n) {
2897
+ const La = new Na();
2898
+ function va(e, t, n) {
2858
2899
  let r = "";
2859
2900
  for (let s = 0; s < t.length; s++) {
2860
- const a = t[s], i = D(a), o = Mn(e, i);
2901
+ const a = t[s], o = C(a), i = qn(e, o);
2861
2902
  if (r += `
2862
- ` + o, i.log !== !1) {
2863
- const c = $e(i);
2903
+ ` + i, o.log !== !1) {
2904
+ const c = be(o);
2864
2905
  r += `
2865
2906
  ` + c;
2866
2907
  }
@@ -2868,45 +2909,45 @@ function Ca(e, t, n) {
2868
2909
  if (n && n.length > 0) {
2869
2910
  const s = /* @__PURE__ */ new Map();
2870
2911
  n.forEach((a) => {
2871
- const i = D(a);
2872
- s.has(i) || s.set(i, /* @__PURE__ */ new Set()), s.get(i).add(a);
2912
+ const o = C(a);
2913
+ s.has(o) || s.set(o, /* @__PURE__ */ new Set()), s.get(o).add(a);
2873
2914
  });
2874
- for (const [a, i] of s.entries()) {
2875
- const o = ue(a, Array.from(i), e.rxdb.context);
2915
+ for (const [a, o] of s.entries()) {
2916
+ const i = de(a, Array.from(o), e.rxdb.context);
2876
2917
  r += `
2877
- ` + o;
2918
+ ` + i;
2878
2919
  }
2879
2920
  }
2880
2921
  return r;
2881
2922
  }
2882
2923
  export {
2883
- Yn as ADAPTER_NAME,
2924
+ Qn as ADAPTER_NAME,
2884
2925
  K as PGliteChangeType,
2885
2926
  Rt as PGliteClient,
2886
- wa as PostgreSQLDialect,
2887
- va as RxDBAdapterPGlite,
2927
+ Na as PostgreSQLDialect,
2928
+ Ca as RxDBAdapterPGlite,
2888
2929
  x as RxdbAdapterPGliteError,
2889
- Ca as create_tables_sql,
2890
- fa as generateNotifyFunctionSQL,
2891
- da as generateNotifyInfrastructureSQL,
2892
- qn as generateNotifyTriggerSQL,
2893
- $e as generate_trigger_sql,
2894
- Z as getEntityObjectFromResult,
2895
- Je as getSqlValue,
2896
- nt as getSqlWithParams,
2897
- Dt as getTableColumnIndexName,
2898
- Ot as getTableName,
2930
+ va as create_tables_sql,
2931
+ da as generateNotifyFunctionSQL,
2932
+ pa as generateNotifyInfrastructureSQL,
2933
+ Pn as generateNotifyTriggerSQL,
2934
+ be as generate_trigger_sql,
2935
+ ee as getEntityObjectFromResult,
2936
+ Ye as getSqlValue,
2937
+ st as getSqlWithParams,
2938
+ Lt as getTableColumnIndexName,
2939
+ Dt as getTableName,
2899
2940
  P as getTableNameByMetadata,
2900
- Ct as normalizeCreateEntity,
2901
- Xn as normalizeEntity,
2902
- Da as pgDialect,
2903
- Oa as removeNotifyTriggerSQL,
2904
- Pn as remove_all_triggers_sql,
2905
- Ea as remove_trigger_sql,
2906
- vt as rxDBColumnTypeToPGliteType,
2907
- Qn as rxDBColumnTypeToPGliteTypeIndexName,
2908
- st as transformEntityValuePGliteToJs,
2909
- Ke as transformEntityValueToSql,
2910
- tt as transformValueJsToPGlite,
2911
- Le as transformValuePGliteToJs
2941
+ vt as normalizeCreateEntity,
2942
+ zn as normalizeEntity,
2943
+ La as pgDialect,
2944
+ Da as removeNotifyTriggerSQL,
2945
+ Un as remove_all_triggers_sql,
2946
+ ma as remove_trigger_sql,
2947
+ Ct as rxDBColumnTypeToPGliteType,
2948
+ Xn as rxDBColumnTypeToPGliteTypeIndexName,
2949
+ rt as transformEntityValuePGliteToJs,
2950
+ Je as transformEntityValueToSql,
2951
+ nt as transformValueJsToPGlite,
2952
+ ae as transformValuePGliteToJs
2912
2953
  };