@aiao/rxdb-adapter-pglite 0.0.12 → 0.0.14

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,10 +1,10 @@
1
- import { PropertyType as A, RxDBChange as ie, getEntityMetadata as D, EntityLocalCreatedEvent as oe, EntityLocalRemovedEvent as Ve, EntityLocalUpdatedEvent as me, RelationKind as Q, RepositoryBase as Fn, getEntityStatus as K, RxDBBranch as ne, parseRxDBChangeKey as $e, getEntityType as Re, RxDBAdapterLocalBase as kn } from "@aiao/rxdb";
1
+ import { PropertyType as N, RxDBChange as ie, getEntityMetadata as D, EntityLocalCreatedEvent as oe, EntityLocalRemovedEvent as Ve, EntityLocalUpdatedEvent as me, RelationKind as F, RepositoryBase as Fn, getEntityStatus as J, RxDBBranch as ne, parseRxDBChangeKey as Ae, getEntityType as Re, RxDBAdapterLocalBase as kn } from "@aiao/rxdb";
2
2
  import { EventDispatcher as Wn, traverseObjectKeys as Gn, isFunction as It, isString as Hn, AsyncQueueExecutor as Vn } from "@aiao/utils";
3
3
  import { PGlite as Kn } from "@electric-sql/pglite";
4
4
  import Ot from "object-hash";
5
- import { ReplaySubject as Qn, defer as be, of as Se, from as Ie, map as Yn } from "rxjs";
6
- const Xn = "pglite";
7
- var V = /* @__PURE__ */ ((e) => (e.INSERT = "INSERT", e.UPDATE = "UPDATE", e.DELETE = "DELETE", e))(V || {});
5
+ import { ReplaySubject as Jn, defer as be, of as Se, from as Ie, map as Yn } from "rxjs";
6
+ const Qn = "pglite";
7
+ var K = /* @__PURE__ */ ((e) => (e.INSERT = "INSERT", e.UPDATE = "UPDATE", e.DELETE = "DELETE", e))(K || {});
8
8
  class x extends Error {
9
9
  /**
10
10
  * 错误代码(例如:DUPLICATE_ENTITY, INVALID_SQL)
@@ -20,55 +20,58 @@ class x extends Error {
20
20
  }
21
21
  const vt = (e, t = "public") => `"${t}"."${e}"`, P = (e) => vt(e.tableName, e.namespace), Dt = (e) => {
22
22
  switch (e.type) {
23
- case A.uuid:
23
+ case N.uuid:
24
24
  return "uuid";
25
- case A.string:
25
+ case N.string:
26
+ case N.enum:
26
27
  return "varchar";
27
- case A.json:
28
+ case N.json:
28
29
  return "jsonb";
29
- case A.number:
30
+ case N.number:
30
31
  return "numeric";
31
- case A.integer:
32
+ case N.integer:
32
33
  return "integer";
33
- case A.boolean:
34
+ case N.boolean:
34
35
  return "boolean";
35
- case A.date:
36
+ case N.date:
36
37
  return "timestamptz";
37
38
  }
38
39
  throw new x("rxDBColumnTypeToPGliteType: type '" + e.type + "' not support");
39
- }, Jn = (e) => {
40
+ }, Xn = (e) => {
40
41
  switch (e.type) {
41
- case A.uuid:
42
+ case N.uuid:
42
43
  return "uuid_ops";
43
- case A.string:
44
+ case N.string:
45
+ case N.enum:
44
46
  return "bpchar_ops";
45
- case A.json:
47
+ case N.json:
46
48
  return "jsonb_ops";
47
- case A.number:
49
+ case N.number:
48
50
  return "numeric_ops";
49
- case A.integer:
51
+ case N.integer:
50
52
  return "int4_ops";
51
53
  default:
52
54
  throw new x(`rxDBColumnTypeToPGliteTypeIndexName: type '${e.type}' not support`);
53
55
  }
54
- }, Lt = (e, t) => `idx_${e.namespace}_${e.tableName}_${t.name}`, tt = (e, t) => {
56
+ }, Ct = (e, t) => `idx_${e.namespace}_${e.tableName}_${t.name}`, tt = (e, t) => {
55
57
  if (e == null)
56
58
  return null;
57
59
  switch (t.type) {
58
- case A.json:
59
- case A.keyValue:
60
- case A.stringArray:
61
- case A.numberArray:
60
+ case N.json:
61
+ case N.keyValue:
62
+ case N.stringArray:
63
+ case N.numberArray:
62
64
  return JSON.stringify(e);
63
- case A.date:
65
+ case N.date:
64
66
  return e instanceof Date ? e.toISOString() : e;
65
- case A.boolean:
67
+ case N.boolean:
66
68
  return !!e;
67
- case A.number:
68
- case A.integer:
69
+ case N.number:
70
+ case N.integer:
69
71
  return Number(e);
70
- case A.string:
71
- case A.uuid:
72
+ case N.enum:
73
+ case N.string:
74
+ case N.uuid:
72
75
  default:
73
76
  return String(e);
74
77
  }
@@ -89,14 +92,14 @@ const vt = (e, t = "public") => `"${t}"."${e}"`, P = (e) => vt(e.tableName, e.na
89
92
  n[l.columnName] = tt(t[o], l);
90
93
  continue;
91
94
  }
92
- const p = e.columnNameToPropertyName?.get(o);
93
- if (p) {
94
- const f = e.propertyMap.get(p);
95
+ const d = e.columnNameToPropertyName?.get(o);
96
+ if (d) {
97
+ const f = e.propertyMap.get(d);
95
98
  f && (n[o] = tt(t[o], f));
96
99
  }
97
100
  }
98
101
  return n;
99
- }, Ct = (e, t) => {
102
+ }, Lt = (e, t) => {
100
103
  const n = {};
101
104
  for (const [a, i] of e.propertyMap)
102
105
  a in t && (n[i.columnName] = t[a]);
@@ -116,17 +119,17 @@ const vt = (e, t = "public") => `"${t}"."${e}"`, P = (e) => vt(e.tableName, e.na
116
119
  i in t && (n[s[a]] = t[i]);
117
120
  }
118
121
  return n;
119
- }, Zn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Qe = (e) => {
122
+ }, Zn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, Je = (e) => {
120
123
  if (typeof e == "string") {
121
124
  const t = e.replaceAll("'", "''");
122
125
  return Zn.test(e) ? `'${t}'::uuid` : `'${t}'`;
123
126
  }
124
- return e == null ? "NULL" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : Array.isArray(e) ? `ARRAY[${e.map((n) => Qe(n)).join(", ")}]` : typeof e == "object" ? `'${JSON.stringify(e).replaceAll("'", "''")}'::jsonb` : String(e);
127
+ 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);
125
128
  }, nt = (e, t = []) => !t || t.length === 0 ? e : e.replace(/\$(\d+)/g, (n, r) => {
126
129
  const s = parseInt(r, 10) - 1;
127
130
  if (s < 0 || s >= t.length)
128
131
  throw new x(`Parameter index ${r} out of range (have ${t.length} params)`);
129
- return Qe(t[s]);
132
+ return Je(t[s]);
130
133
  }), Z = (e, t) => {
131
134
  const n = {}, r = e.foreignKeyNames || [], s = e.foreignKeyColumnNames || r, a = e.columnNameToPropertyName;
132
135
  return Object.keys(t).forEach((i) => {
@@ -138,57 +141,57 @@ const vt = (e, t = "public") => `"${t}"."${e}"`, P = (e) => vt(e.tableName, e.na
138
141
  const u = a?.get(i);
139
142
  if (u) {
140
143
  const l = e.propertyMap.get(u);
141
- l && (l.type === A.number && typeof o == "string" ? n[u] = parseFloat(o) : l.type === A.integer && typeof o == "string" ? n[u] = parseInt(o, 10) : n[u] = o);
144
+ 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);
142
145
  return;
143
146
  }
144
147
  if (!a) {
145
148
  const l = e.propertyMap.get(i);
146
149
  if (l) {
147
- l.type === A.number && typeof o == "string" ? n[i] = parseFloat(o) : l.type === A.integer && typeof o == "string" ? n[i] = parseInt(o, 10) : n[i] = o;
150
+ 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;
148
151
  return;
149
152
  }
150
153
  }
151
154
  e.isForeignKey(i), n[i] = o;
152
155
  }), n;
153
- }, Ce = (e, t) => {
156
+ }, Le = (e, t) => {
154
157
  if (e == null) return e;
155
158
  switch (t.type) {
156
- case A.date:
159
+ case N.date:
157
160
  return e instanceof Date ? e : new Date(e);
158
- case A.json:
159
- case A.keyValue:
160
- case A.stringArray:
161
- case A.numberArray:
161
+ case N.json:
162
+ case N.keyValue:
163
+ case N.stringArray:
164
+ case N.numberArray:
162
165
  return e;
163
- case A.boolean:
166
+ case N.boolean:
164
167
  return !!e;
165
168
  default:
166
169
  return e;
167
170
  }
168
171
  }, st = (e, t) => (Object.keys(t).forEach((n) => {
169
172
  const r = t[n], s = e.propertyMap.get(n);
170
- s && (t[n] = Ce(r, s));
173
+ s && (t[n] = Le(r, s));
171
174
  }), t);
172
- var es = Object.defineProperty, qt = (e) => {
175
+ var es = Object.defineProperty, Mt = (e) => {
173
176
  throw TypeError(e);
174
177
  }, ts = (e, t) => () => (e && (t = e(e = 0)), t), ye = (e, t) => {
175
178
  for (var n in t) es(e, n, { get: t[n], enumerable: !0 });
176
- }, Ye = (e, t, n) => t.has(e) || qt("Cannot " + n), h = (e, t, n) => (Ye(e, t, "read from private field"), n ? n.call(e) : t.get(e)), j = (e, t, n) => t.has(e) ? qt("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
+ }, Ye = (e, t, n) => t.has(e) || Mt("Cannot " + n), h = (e, t, n) => (Ye(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), 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), qt = (e, t, n, r) => ({ set _(s) {
177
180
  v(e, t, s);
178
181
  }, get _() {
179
182
  return h(e, t, r);
180
- } }), G = ts(() => {
183
+ } }), H = ts(() => {
181
184
  }), ns = {};
182
- ye(ns, { ABSTIME: () => ms, ACLITEM: () => $s, BIT: () => Is, BOOL: () => qe, BPCHAR: () => Ft, BYTEA: () => Me, CHAR: () => as, CID: () => ls, CIDR: () => Es, CIRCLE: () => gs, DATE: () => Wt, FLOAT4: () => xt, FLOAT8: () => Bt, GTSVECTOR: () => Gs, INET: () => As, INT2: () => Pt, INT4: () => Ut, INT8: () => Pe, INTERVAL: () => bs, JSON: () => Ue, JSONB: () => Ht, MACADDR: () => Ns, MACADDR8: () => Ts, MONEY: () => ws, NUMERIC: () => vs, OID: () => jt, PATH: () => ds, PG_DEPENDENCIES: () => Fs, PG_LSN: () => xs, PG_NDISTINCT: () => Bs, PG_NODE_TREE: () => hs, POLYGON: () => ps, REFCURSOR: () => Ds, REGCLASS: () => Ms, REGCONFIG: () => Hs, REGDICTIONARY: () => Vs, REGNAMESPACE: () => Ks, REGOPER: () => Cs, REGOPERATOR: () => qs, REGPROC: () => is, REGPROCEDURE: () => Ls, REGROLE: () => Qs, REGTYPE: () => Ps, RELTIME: () => ys, SMGR: () => fs, TEXT: () => ce, TID: () => os, TIME: () => Rs, TIMESTAMP: () => Gt, TIMESTAMPTZ: () => je, TIMETZ: () => Ss, TINTERVAL: () => _s, TSQUERY: () => Ws, TSVECTOR: () => ks, TXID_SNAPSHOT: () => js, UUID: () => Us, VARBIT: () => Os, VARCHAR: () => kt, XID: () => cs, XML: () => us, arrayParser: () => tr, arraySerializer: () => Kt, parseType: () => xe, parsers: () => Ys, serializers: () => Xs, types: () => Vt });
183
- G();
184
- var ss = globalThis.JSON.parse, rs = globalThis.JSON.stringify, qe = 16, Me = 17, as = 18, Pe = 20, Pt = 21, Ut = 23, is = 24, ce = 25, jt = 26, os = 27, cs = 28, ls = 29, Ue = 114, us = 142, hs = 194, fs = 210, ds = 602, ps = 604, Es = 650, xt = 700, Bt = 701, ms = 702, ys = 703, _s = 704, gs = 718, Ts = 774, ws = 790, Ns = 829, As = 869, $s = 1033, Ft = 1042, kt = 1043, Wt = 1082, Rs = 1083, Gt = 1114, je = 1184, bs = 1186, Ss = 1266, Is = 1560, Os = 1562, vs = 1700, Ds = 1790, Ls = 2202, Cs = 2203, qs = 2204, Ms = 2205, Ps = 2206, Us = 2950, js = 2970, xs = 3220, Bs = 3361, Fs = 3402, ks = 3614, Ws = 3615, Gs = 3642, Hs = 3734, Vs = 3769, Ht = 3802, Ks = 4089, Qs = 4096, Vt = { string: { to: ce, from: [ce, kt, Ft], serialize: (e) => {
185
+ ye(ns, { ABSTIME: () => ms, ACLITEM: () => As, BIT: () => Is, BOOL: () => Me, BPCHAR: () => Ft, BYTEA: () => qe, CHAR: () => as, CID: () => ls, CIDR: () => Es, CIRCLE: () => _s, DATE: () => Wt, FLOAT4: () => xt, FLOAT8: () => Bt, GTSVECTOR: () => Gs, INET: () => $s, INT2: () => Pt, INT4: () => Ut, INT8: () => Pe, INTERVAL: () => bs, JSON: () => Ue, JSONB: () => Ht, MACADDR: () => Ns, MACADDR8: () => Ts, MONEY: () => ws, NUMERIC: () => vs, OID: () => jt, PATH: () => ds, PG_DEPENDENCIES: () => Fs, PG_LSN: () => xs, PG_NDISTINCT: () => Bs, PG_NODE_TREE: () => hs, POLYGON: () => ps, REFCURSOR: () => Ds, REGCLASS: () => qs, REGCONFIG: () => Hs, REGDICTIONARY: () => Vs, REGNAMESPACE: () => Ks, REGOPER: () => Ls, REGOPERATOR: () => Ms, REGPROC: () => is, REGPROCEDURE: () => Cs, REGROLE: () => Js, REGTYPE: () => Ps, RELTIME: () => ys, SMGR: () => fs, TEXT: () => ce, TID: () => os, TIME: () => Rs, TIMESTAMP: () => Gt, TIMESTAMPTZ: () => je, 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: () => xe, parsers: () => Ys, serializers: () => Qs, types: () => Vt });
186
+ H();
187
+ var ss = globalThis.JSON.parse, rs = globalThis.JSON.stringify, Me = 16, qe = 17, as = 18, Pe = 20, Pt = 21, Ut = 23, is = 24, ce = 25, jt = 26, os = 27, cs = 28, ls = 29, Ue = 114, us = 142, hs = 194, fs = 210, ds = 602, ps = 604, Es = 650, xt = 700, Bt = 701, ms = 702, ys = 703, gs = 704, _s = 718, Ts = 774, ws = 790, Ns = 829, $s = 869, As = 1033, Ft = 1042, kt = 1043, Wt = 1082, Rs = 1083, Gt = 1114, je = 1184, bs = 1186, Ss = 1266, Is = 1560, Os = 1562, vs = 1700, Ds = 1790, Cs = 2202, Ls = 2203, Ms = 2204, qs = 2205, Ps = 2206, Us = 2950, js = 2970, xs = 3220, Bs = 3361, Fs = 3402, ks = 3614, Ws = 3615, Gs = 3642, Hs = 3734, Vs = 3769, Ht = 3802, Ks = 4089, Js = 4096, Vt = { string: { to: ce, from: [ce, kt, Ft], serialize: (e) => {
185
188
  if (typeof e == "string") return e;
186
189
  if (typeof e == "number") return e.toString();
187
190
  throw new Error("Invalid input for string type");
188
191
  }, parse: (e) => e }, number: { to: 0, from: [Pt, Ut, jt, xt, Bt], serialize: (e) => e.toString(), parse: (e) => +e }, bigint: { to: Pe, from: [Pe], serialize: (e) => e.toString(), parse: (e) => {
189
192
  let t = BigInt(e);
190
193
  return t < Number.MIN_SAFE_INTEGER || t > Number.MAX_SAFE_INTEGER ? t : Number(t);
191
- } }, json: { to: Ue, from: [Ue, Ht], serialize: (e) => typeof e == "string" ? e : rs(e), parse: (e) => ss(e) }, boolean: { to: qe, from: [qe], serialize: (e) => {
194
+ } }, json: { to: Ue, from: [Ue, Ht], serialize: (e) => typeof e == "string" ? e : rs(e), parse: (e) => ss(e) }, boolean: { to: Me, from: [Me], serialize: (e) => {
192
195
  if (typeof e != "boolean") throw new Error("Invalid input for boolean type");
193
196
  return e ? "t" : "f";
194
197
  }, parse: (e) => e === "t" }, date: { to: je, from: [Wt, Gt, je], serialize: (e) => {
@@ -196,19 +199,19 @@ var ss = globalThis.JSON.parse, rs = globalThis.JSON.stringify, qe = 16, Me = 17
196
199
  if (typeof e == "number") return new Date(e).toISOString();
197
200
  if (e instanceof Date) return e.toISOString();
198
201
  throw new Error("Invalid input for date type");
199
- }, parse: (e) => new Date(e) }, bytea: { to: Me, from: [Me], serialize: (e) => {
202
+ }, parse: (e) => new Date(e) }, bytea: { to: qe, from: [qe], serialize: (e) => {
200
203
  if (!(e instanceof Uint8Array)) throw new Error("Invalid input for bytea type");
201
204
  return "\\x" + Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
202
205
  }, parse: (e) => {
203
206
  let t = e.slice(2);
204
207
  return Uint8Array.from({ length: t.length / 2 }, (n, r) => parseInt(t.substring(r * 2, (r + 1) * 2), 16));
205
- } } }, Xe = Js(Vt), Ys = Xe.parsers, Xs = Xe.serializers;
208
+ } } }, Qe = Xs(Vt), Ys = Qe.parsers, Qs = Qe.serializers;
206
209
  function xe(e, t, n) {
207
210
  if (e === null) return null;
208
- let r = n?.[t] ?? Xe.parsers[t];
211
+ let r = n?.[t] ?? Qe.parsers[t];
209
212
  return r ? r(e, t) : e;
210
213
  }
211
- function Js(e) {
214
+ function Xs(e) {
212
215
  return Object.keys(e).reduce(({ parsers: t, serializers: n }, r) => {
213
216
  let { to: s, from: a, serialize: i, parse: o } = e[r];
214
217
  return n[s] = i, n[r] = i, t[r] = o, Array.isArray(a) ? a.forEach((c) => {
@@ -228,14 +231,14 @@ function Kt(e, t, n) {
228
231
  }
229
232
  var Oe = { i: 0, char: null, str: "", quoted: !1, last: 0, p: null };
230
233
  function tr(e, t, n) {
231
- return Oe.i = Oe.last = 0, Qt(Oe, e, t, n)[0];
234
+ return Oe.i = Oe.last = 0, Jt(Oe, e, t, n)[0];
232
235
  }
233
- function Qt(e, t, n, r) {
236
+ function Jt(e, t, n, r) {
234
237
  let s = [], a = r === 1020 ? ";" : ",";
235
238
  for (; e.i < t.length; e.i++) {
236
239
  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;
237
240
  else if (e.char === '"') e.quoted = !0;
238
- else if (e.char === "{") e.last = ++e.i, s.push(Qt(e, t, n, r));
241
+ else if (e.char === "{") e.last = ++e.i, s.push(Jt(e, t, n, r));
239
242
  else if (e.char === "}") {
240
243
  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;
241
244
  break;
@@ -246,7 +249,7 @@ function Qt(e, t, n, r) {
246
249
  }
247
250
  var nr = {};
248
251
  ye(nr, { parseDescribeStatementResults: () => Yt, parseResults: () => sr });
249
- G();
252
+ H();
250
253
  function sr(e, t, n, r) {
251
254
  let s = [], a = { rows: [], fields: [] }, i = 0, o = { ...t, ...n?.parsers };
252
255
  return e.forEach((c) => {
@@ -259,7 +262,7 @@ function sr(e, t, n, r) {
259
262
  case "dataRow": {
260
263
  if (!a) break;
261
264
  let u = c;
262
- 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)])));
265
+ n?.rowMode === "array" ? a.rows.push(u.fields.map((l, d) => xe(l, a.fields[d].dataTypeID, o))) : a.rows.push(Object.fromEntries(u.fields.map((l, d) => [a.fields[d].name, xe(l, a.fields[d].dataTypeID, o)])));
263
266
  break;
264
267
  }
265
268
  case "commandComplete": {
@@ -287,10 +290,10 @@ function Yt(e) {
287
290
  let t = e.find((n) => n.name === "parameterDescription");
288
291
  return t ? t.dataTypeIDs : [];
289
292
  }
290
- var Xt = {};
291
- ye(Xt, { AuthenticationCleartextPassword: () => on, AuthenticationMD5Password: () => cn, AuthenticationOk: () => an, AuthenticationSASL: () => ln, AuthenticationSASLContinue: () => un, AuthenticationSASLFinal: () => hn, BackendKeyDataMessage: () => _n, CommandCompleteMessage: () => wn, CopyDataMessage: () => fn, CopyResponse: () => dn, DataRowMessage: () => Nn, DatabaseError: () => Be, Field: () => pn, NoticeMessage: () => An, NotificationResponseMessage: () => gn, ParameterDescriptionMessage: () => mn, ParameterStatusMessage: () => yn, ReadyForQueryMessage: () => Tn, RowDescriptionMessage: () => En, bindComplete: () => zt, closeComplete: () => Zt, copyDone: () => rn, emptyQuery: () => sn, noData: () => en, parseComplete: () => Jt, portalSuspended: () => tn, replicationStart: () => nn });
292
- G();
293
- var Jt = { 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 {
293
+ var Qt = {};
294
+ ye(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: () => $n, 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 });
295
+ H();
296
+ 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 {
294
297
  constructor(t) {
295
298
  this.length = t, this.name = "authenticationOk";
296
299
  }
@@ -342,11 +345,11 @@ var Jt = { name: "parseComplete", length: 5 }, zt = { name: "bindComplete", leng
342
345
  constructor(e, t, n) {
343
346
  this.length = e, this.parameterName = t, this.parameterValue = n, this.name = "parameterStatus";
344
347
  }
345
- }, _n = class {
348
+ }, gn = class {
346
349
  constructor(e, t, n) {
347
350
  this.length = e, this.processID = t, this.secretKey = n, this.name = "backendKeyData";
348
351
  }
349
- }, gn = class {
352
+ }, _n = class {
350
353
  constructor(e, t, n, r) {
351
354
  this.length = e, this.processId = t, this.channel = n, this.payload = r, this.name = "notification";
352
355
  }
@@ -362,17 +365,17 @@ var Jt = { name: "parseComplete", length: 5 }, zt = { name: "bindComplete", leng
362
365
  constructor(e, t) {
363
366
  this.length = e, this.fields = t, this.name = "dataRow", this.fieldCount = t.length;
364
367
  }
365
- }, An = class {
368
+ }, $n = class {
366
369
  constructor(e, t) {
367
370
  this.length = e, this.message = t, this.name = "notice";
368
371
  }
369
372
  }, ar = {};
370
- ye(ar, { Parser: () => Lr, messages: () => Xt, serialize: () => re });
371
- G();
372
- G();
373
- G();
374
- G();
375
- function _e(e) {
373
+ ye(ar, { Parser: () => Cr, messages: () => Qt, serialize: () => re });
374
+ H();
375
+ H();
376
+ H();
377
+ H();
378
+ function ge(e) {
376
379
  let t = e.length;
377
380
  for (let n = e.length - 1; n >= 0; n--) {
378
381
  let r = e.charCodeAt(n);
@@ -380,162 +383,162 @@ function _e(e) {
380
383
  }
381
384
  return t;
382
385
  }
383
- var U, q, te, Fe, ee, H, le, J, $n, ge = class {
386
+ var U, M, te, Fe, ee, V, le, X, An, _e = class {
384
387
  constructor(e = 256) {
385
- this.size = e, j(this, H), j(this, U), j(this, q, 5), j(this, te, !1), j(this, Fe, new TextEncoder()), j(this, ee, 0), v(this, U, O(this, H, le).call(this, e));
388
+ this.size = e, j(this, V), j(this, U), j(this, M, 5), j(this, te, !1), j(this, Fe, new TextEncoder()), j(this, ee, 0), v(this, U, O(this, V, le).call(this, e));
386
389
  }
387
390
  addInt32(e) {
388
- return O(this, H, J).call(this, 4), h(this, U).setInt32(h(this, q), e, h(this, te)), v(this, q, h(this, q) + 4), this;
391
+ return O(this, V, X).call(this, 4), h(this, U).setInt32(h(this, M), e, h(this, te)), v(this, M, h(this, M) + 4), this;
389
392
  }
390
393
  addInt16(e) {
391
- return O(this, H, J).call(this, 2), h(this, U).setInt16(h(this, q), e, h(this, te)), v(this, q, h(this, q) + 2), this;
394
+ return O(this, V, X).call(this, 2), h(this, U).setInt16(h(this, M), e, h(this, te)), v(this, M, h(this, M) + 2), this;
392
395
  }
393
396
  addCString(e) {
394
- return e && this.addString(e), O(this, H, J).call(this, 1), h(this, U).setUint8(h(this, q), 0), Mt(this, q)._++, this;
397
+ return e && this.addString(e), O(this, V, X).call(this, 1), h(this, U).setUint8(h(this, M), 0), qt(this, M)._++, this;
395
398
  }
396
399
  addString(e = "") {
397
- let t = _e(e);
398
- return O(this, H, J).call(this, t), h(this, Fe).encodeInto(e, new Uint8Array(h(this, U).buffer, h(this, q))), v(this, q, h(this, q) + t), this;
400
+ let t = ge(e);
401
+ return O(this, V, X).call(this, t), h(this, Fe).encodeInto(e, new Uint8Array(h(this, U).buffer, h(this, M))), v(this, M, h(this, M) + t), this;
399
402
  }
400
403
  add(e) {
401
- return O(this, H, J).call(this, e.byteLength), new Uint8Array(h(this, U).buffer).set(new Uint8Array(e), h(this, q)), v(this, q, h(this, q) + e.byteLength), this;
404
+ return O(this, V, X).call(this, e.byteLength), new Uint8Array(h(this, U).buffer).set(new Uint8Array(e), h(this, M)), v(this, M, h(this, M) + e.byteLength), this;
402
405
  }
403
406
  flush(e) {
404
- let t = O(this, H, $n).call(this, e);
405
- return v(this, q, 5), v(this, U, O(this, H, le).call(this, this.size)), new Uint8Array(t);
407
+ let t = O(this, V, An).call(this, e);
408
+ return v(this, M, 5), v(this, U, O(this, V, le).call(this, this.size)), new Uint8Array(t);
406
409
  }
407
410
  };
408
- U = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), Fe = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakSet(), le = function(e) {
411
+ U = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), Fe = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakSet(), le = function(e) {
409
412
  return new DataView(new ArrayBuffer(e));
410
- }, J = function(e) {
411
- if (h(this, U).byteLength - h(this, q) < e) {
413
+ }, X = function(e) {
414
+ if (h(this, U).byteLength - h(this, M) < e) {
412
415
  let t = h(this, U).buffer, n = t.byteLength + (t.byteLength >> 1) + e;
413
- v(this, U, O(this, H, le).call(this, n)), new Uint8Array(h(this, U).buffer).set(new Uint8Array(t));
416
+ v(this, U, O(this, V, le).call(this, n)), new Uint8Array(h(this, U).buffer).set(new Uint8Array(t));
414
417
  }
415
- }, $n = function(e) {
418
+ }, An = function(e) {
416
419
  if (e) {
417
420
  h(this, U).setUint8(h(this, ee), e);
418
- let t = h(this, q) - (h(this, ee) + 1);
421
+ let t = h(this, M) - (h(this, ee) + 1);
419
422
  h(this, U).setInt32(h(this, ee) + 1, t, h(this, te));
420
423
  }
421
- return h(this, U).buffer.slice(e ? 0 : 5, h(this, q));
424
+ return h(this, U).buffer.slice(e ? 0 : 5, h(this, M));
422
425
  };
423
- var L = new ge(), ir = (e) => {
424
- L.addInt16(3).addInt16(0);
425
- for (let r of Object.keys(e)) L.addCString(r).addCString(e[r]);
426
- L.addCString("client_encoding").addCString("UTF8");
427
- let t = L.addCString("").flush(), n = t.byteLength + 4;
428
- return new ge().addInt32(n).add(t).flush();
426
+ var C = new _e(), ir = (e) => {
427
+ C.addInt16(3).addInt16(0);
428
+ for (let r of Object.keys(e)) C.addCString(r).addCString(e[r]);
429
+ C.addCString("client_encoding").addCString("UTF8");
430
+ let t = C.addCString("").flush(), n = t.byteLength + 4;
431
+ return new _e().addInt32(n).add(t).flush();
429
432
  }, or = () => {
430
433
  let e = new DataView(new ArrayBuffer(8));
431
434
  return e.setInt32(0, 8, !1), e.setInt32(4, 80877103, !1), new Uint8Array(e.buffer);
432
- }, cr = (e) => L.addCString(e).flush(112), lr = (e, t) => (L.addCString(e).addInt32(_e(t)).addString(t), L.flush(112)), ur = (e) => L.addString(e).flush(112), hr = (e) => L.addCString(e).flush(81), fr = [], dr = (e) => {
435
+ }, cr = (e) => C.addCString(e).flush(112), lr = (e, t) => (C.addCString(e).addInt32(ge(t)).addString(t), C.flush(112)), ur = (e) => C.addString(e).flush(112), hr = (e) => C.addCString(e).flush(81), fr = [], dr = (e) => {
433
436
  let t = e.name ?? "";
434
437
  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"));
435
- let n = L.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
436
- return e.types?.forEach((r) => n.addInt32(r)), L.flush(80);
437
- }, z = new ge(), pr = (e, t) => {
438
+ let n = C.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
439
+ return e.types?.forEach((r) => n.addInt32(r)), C.flush(80);
440
+ }, z = new _e(), pr = (e, t) => {
438
441
  for (let n = 0; n < e.length; n++) {
439
442
  let r = t ? t(e[n], n) : e[n];
440
- if (r === null) L.addInt16(0), z.addInt32(-1);
443
+ if (r === null) C.addInt16(0), z.addInt32(-1);
441
444
  else if (r instanceof ArrayBuffer || ArrayBuffer.isView(r)) {
442
445
  let s = ArrayBuffer.isView(r) ? r.buffer.slice(r.byteOffset, r.byteOffset + r.byteLength) : r;
443
- L.addInt16(1), z.addInt32(s.byteLength), z.add(s);
444
- } else L.addInt16(0), z.addInt32(_e(r)), z.addString(r);
446
+ C.addInt16(1), z.addInt32(s.byteLength), z.add(s);
447
+ } else C.addInt16(0), z.addInt32(ge(r)), z.addString(r);
445
448
  }
446
449
  }, Er = (e = {}) => {
447
450
  let t = e.portal ?? "", n = e.statement ?? "", r = e.binary ?? !1, s = e.values ?? fr, a = s.length;
448
- 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);
451
+ return C.addCString(t).addCString(n), C.addInt16(a), pr(s, e.valueMapper), C.addInt16(a), C.add(z.flush()), C.addInt16(r ? 1 : 0), C.flush(66);
449
452
  }, mr = new Uint8Array([69, 0, 0, 0, 9, 0, 0, 0, 0, 0]), yr = (e) => {
450
453
  if (!e || !e.portal && !e.rows) return mr;
451
- let t = e.portal ?? "", n = e.rows ?? 0, r = _e(t), s = 4 + r + 1 + 4, a = new DataView(new ArrayBuffer(1 + s));
454
+ let t = e.portal ?? "", n = e.rows ?? 0, r = ge(t), s = 4 + r + 1 + 4, a = new DataView(new ArrayBuffer(1 + s));
452
455
  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);
453
- }, _r = (e, t) => {
456
+ }, gr = (e, t) => {
454
457
  let n = new DataView(new ArrayBuffer(16));
455
458
  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);
456
- }, Je = (e, t) => {
457
- let n = new ge();
459
+ }, Xe = (e, t) => {
460
+ let n = new _e();
458
461
  return n.addCString(t), n.flush(e);
459
- }, gr = L.addCString("P").flush(68), Tr = L.addCString("S").flush(68), wr = (e) => e.name ? Je(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? gr : Tr, Nr = (e) => {
462
+ }, _r = C.addCString("P").flush(68), Tr = C.addCString("S").flush(68), wr = (e) => e.name ? Xe(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? _r : Tr, Nr = (e) => {
460
463
  let t = `${e.type}${e.name ?? ""}`;
461
- return Je(67, t);
462
- }, Ar = (e) => L.add(e).flush(100), $r = (e) => Je(102, e), Te = (e) => new Uint8Array([e, 0, 0, 0, 4]), Rr = Te(72), br = Te(83), Sr = Te(88), Ir = Te(99), re = { startup: ir, password: cr, requestSsl: or, sendSASLInitialResponseMessage: lr, sendSCRAMClientFinalMessage: ur, query: hr, parse: dr, bind: Er, execute: yr, describe: wr, close: Nr, flush: () => Rr, sync: () => br, end: () => Sr, copyData: Ar, copyDone: () => Ir, copyFail: $r, cancel: _r };
463
- G();
464
- G();
464
+ return Xe(67, t);
465
+ }, $r = (e) => C.add(e).flush(100), Ar = (e) => Xe(102, e), Te = (e) => new Uint8Array([e, 0, 0, 0, 4]), Rr = Te(72), br = Te(83), Sr = Te(88), Ir = Te(99), re = { startup: ir, password: cr, requestSsl: or, sendSASLInitialResponseMessage: lr, sendSCRAMClientFinalMessage: ur, query: hr, parse: dr, bind: Er, execute: yr, describe: wr, close: Nr, flush: () => Rr, sync: () => br, end: () => Sr, copyData: $r, copyDone: () => Ir, copyFail: Ar, cancel: gr };
466
+ H();
467
+ H();
465
468
  var rt = { text: 0, binary: 1 };
466
- G();
467
- var Or = new ArrayBuffer(0), Y, M, ke, We, ae, vr = class {
469
+ H();
470
+ var Or = new ArrayBuffer(0), Y, q, ke, We, ae, vr = class {
468
471
  constructor(e = 0) {
469
- j(this, Y, new DataView(Or)), j(this, M), j(this, ke, "utf-8"), j(this, We, new TextDecoder(h(this, ke))), j(this, ae, !1), v(this, M, e);
472
+ j(this, Y, new DataView(Or)), j(this, q), j(this, ke, "utf-8"), j(this, We, new TextDecoder(h(this, ke))), j(this, ae, !1), v(this, q, e);
470
473
  }
471
474
  setBuffer(e, t) {
472
- v(this, M, e), v(this, Y, new DataView(t));
475
+ v(this, q, e), v(this, Y, new DataView(t));
473
476
  }
474
477
  int16() {
475
- let e = h(this, Y).getInt16(h(this, M), h(this, ae));
476
- return v(this, M, h(this, M) + 2), e;
478
+ let e = h(this, Y).getInt16(h(this, q), h(this, ae));
479
+ return v(this, q, h(this, q) + 2), e;
477
480
  }
478
481
  byte() {
479
- let e = h(this, Y).getUint8(h(this, M));
480
- return Mt(this, M)._++, e;
482
+ let e = h(this, Y).getUint8(h(this, q));
483
+ return qt(this, q)._++, e;
481
484
  }
482
485
  int32() {
483
- let e = h(this, Y).getInt32(h(this, M), h(this, ae));
484
- return v(this, M, h(this, M) + 4), e;
486
+ let e = h(this, Y).getInt32(h(this, q), h(this, ae));
487
+ return v(this, q, h(this, q) + 4), e;
485
488
  }
486
489
  string(e) {
487
490
  return h(this, We).decode(this.bytes(e));
488
491
  }
489
492
  cstring() {
490
- let e = h(this, M), t = e;
493
+ let e = h(this, q), t = e;
491
494
  for (; h(this, Y).getUint8(t++) !== 0; ) ;
492
495
  let n = this.string(t - e - 1);
493
- return v(this, M, t), n;
496
+ return v(this, q, t), n;
494
497
  }
495
498
  bytes(e) {
496
- let t = h(this, Y).buffer.slice(h(this, M), h(this, M) + e);
497
- return v(this, M, h(this, M) + e), new Uint8Array(t);
499
+ let t = h(this, Y).buffer.slice(h(this, q), h(this, q) + e);
500
+ return v(this, q, h(this, q) + e), new Uint8Array(t);
498
501
  }
499
502
  };
500
- Y = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), ae = /* @__PURE__ */ new WeakMap();
501
- var Ge = 1, Dr = 4, at = Ge + Dr, it = new ArrayBuffer(0), B, k, W, w, C, Rn, bn, ot, ct, lt, ut, ht, ve, ft, dt, pt, Et, mt, yt, _t, gt, De, Lr = class {
503
+ Y = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), ae = /* @__PURE__ */ new WeakMap();
504
+ var Ge = 1, Dr = 4, at = Ge + Dr, it = new ArrayBuffer(0), B, W, G, w, L, Rn, bn, ot, ct, lt, ut, ht, ve, ft, dt, pt, Et, mt, yt, gt, _t, De, Cr = class {
502
505
  constructor() {
503
- j(this, C), j(this, B, new DataView(it)), j(this, k, 0), j(this, W, 0), j(this, w, new vr());
506
+ j(this, L), j(this, B, new DataView(it)), j(this, W, 0), j(this, G, 0), j(this, w, new vr());
504
507
  }
505
508
  parse(e, t) {
506
- O(this, C, Rn).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
507
- let n = h(this, W) + h(this, k), r = h(this, W);
509
+ O(this, L, Rn).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
510
+ let n = h(this, G) + h(this, W), r = h(this, G);
508
511
  for (; r + at <= n; ) {
509
512
  let s = h(this, B).getUint8(r), a = h(this, B).getUint32(r + Ge, !1), i = Ge + a;
510
513
  if (i + r <= n && a > 0) {
511
- let o = O(this, C, bn).call(this, r + at, s, a, h(this, B).buffer);
514
+ let o = O(this, L, bn).call(this, r + at, s, a, h(this, B).buffer);
512
515
  t(o), r += i;
513
516
  } else break;
514
517
  }
515
- r === n ? (v(this, B, new DataView(it)), v(this, k, 0), v(this, W, 0)) : (v(this, k, n - r), v(this, W, r));
518
+ r === n ? (v(this, B, new DataView(it)), v(this, W, 0), v(this, G, 0)) : (v(this, W, n - r), v(this, G, r));
516
519
  }
517
520
  };
518
- B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakSet(), Rn = function(e) {
519
- if (h(this, k) > 0) {
520
- let t = h(this, k) + e.byteLength;
521
- if (t + h(this, W) > h(this, B).byteLength) {
521
+ B = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakSet(), Rn = function(e) {
522
+ if (h(this, W) > 0) {
523
+ let t = h(this, W) + e.byteLength;
524
+ if (t + h(this, G) > h(this, B).byteLength) {
522
525
  let n;
523
- if (t <= h(this, B).byteLength && h(this, W) >= h(this, k)) n = h(this, B).buffer;
526
+ if (t <= h(this, B).byteLength && h(this, G) >= h(this, W)) n = h(this, B).buffer;
524
527
  else {
525
528
  let r = h(this, B).byteLength * 2;
526
529
  for (; t >= r; ) r *= 2;
527
530
  n = new ArrayBuffer(r);
528
531
  }
529
- new Uint8Array(n).set(new Uint8Array(h(this, B).buffer, h(this, W), h(this, k))), v(this, B, new DataView(n)), v(this, W, 0);
532
+ new Uint8Array(n).set(new Uint8Array(h(this, B).buffer, h(this, G), h(this, W))), v(this, B, new DataView(n)), v(this, G, 0);
530
533
  }
531
- new Uint8Array(h(this, B).buffer).set(new Uint8Array(e), h(this, W) + h(this, k)), v(this, k, t);
532
- } else v(this, B, new DataView(e)), v(this, W, 0), v(this, k, e.byteLength);
534
+ new Uint8Array(h(this, B).buffer).set(new Uint8Array(e), h(this, G) + h(this, W)), v(this, W, t);
535
+ } else v(this, B, new DataView(e)), v(this, G, 0), v(this, W, e.byteLength);
533
536
  }, bn = function(e, t, n, r) {
534
537
  switch (t) {
535
538
  case 50:
536
539
  return zt;
537
540
  case 49:
538
- return Jt;
541
+ return Xt;
539
542
  case 51:
540
543
  return Zt;
541
544
  case 110:
@@ -549,33 +552,33 @@ B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__
549
552
  case 73:
550
553
  return sn;
551
554
  case 68:
552
- return O(this, C, mt).call(this, e, n, r);
555
+ return O(this, L, mt).call(this, e, n, r);
553
556
  case 67:
554
- return O(this, C, ct).call(this, e, n, r);
557
+ return O(this, L, ct).call(this, e, n, r);
555
558
  case 90:
556
- return O(this, C, ot).call(this, e, n, r);
559
+ return O(this, L, ot).call(this, e, n, r);
557
560
  case 65:
558
- return O(this, C, ft).call(this, e, n, r);
561
+ return O(this, L, ft).call(this, e, n, r);
559
562
  case 82:
560
- return O(this, C, gt).call(this, e, n, r);
563
+ return O(this, L, _t).call(this, e, n, r);
561
564
  case 83:
562
- return O(this, C, yt).call(this, e, n, r);
565
+ return O(this, L, yt).call(this, e, n, r);
563
566
  case 75:
564
- return O(this, C, _t).call(this, e, n, r);
567
+ return O(this, L, gt).call(this, e, n, r);
565
568
  case 69:
566
- return O(this, C, De).call(this, e, n, r, "error");
569
+ return O(this, L, De).call(this, e, n, r, "error");
567
570
  case 78:
568
- return O(this, C, De).call(this, e, n, r, "notice");
571
+ return O(this, L, De).call(this, e, n, r, "notice");
569
572
  case 84:
570
- return O(this, C, dt).call(this, e, n, r);
573
+ return O(this, L, dt).call(this, e, n, r);
571
574
  case 116:
572
- return O(this, C, Et).call(this, e, n, r);
575
+ return O(this, L, Et).call(this, e, n, r);
573
576
  case 71:
574
- return O(this, C, ut).call(this, e, n, r);
577
+ return O(this, L, ut).call(this, e, n, r);
575
578
  case 72:
576
- return O(this, C, ht).call(this, e, n, r);
579
+ return O(this, L, ht).call(this, e, n, r);
577
580
  case 100:
578
- return O(this, C, lt).call(this, e, n, r);
581
+ return O(this, L, lt).call(this, e, n, r);
579
582
  default:
580
583
  return new Be("received invalid response: " + t.toString(16), n, "error");
581
584
  }
@@ -591,9 +594,9 @@ B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__
591
594
  let r = n.slice(e, e + (t - 4));
592
595
  return new fn(t, new Uint8Array(r));
593
596
  }, ut = function(e, t, n) {
594
- return O(this, C, ve).call(this, e, t, n, "copyInResponse");
597
+ return O(this, L, ve).call(this, e, t, n, "copyInResponse");
595
598
  }, ht = function(e, t, n) {
596
- return O(this, C, ve).call(this, e, t, n, "copyOutResponse");
599
+ return O(this, L, ve).call(this, e, t, n, "copyOutResponse");
597
600
  }, ve = function(e, t, n, r) {
598
601
  h(this, w).setBuffer(e, n);
599
602
  let s = h(this, w).byte() !== 0, a = h(this, w).int16(), i = new dn(t, r, s, a);
@@ -602,11 +605,11 @@ B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__
602
605
  }, ft = function(e, t, n) {
603
606
  h(this, w).setBuffer(e, n);
604
607
  let r = h(this, w).int32(), s = h(this, w).cstring(), a = h(this, w).cstring();
605
- return new gn(t, r, s, a);
608
+ return new _n(t, r, s, a);
606
609
  }, dt = function(e, t, n) {
607
610
  h(this, w).setBuffer(e, n);
608
611
  let r = h(this, w).int16(), s = new En(t, r);
609
- for (let a = 0; a < r; a++) s.fields[a] = O(this, C, pt).call(this);
612
+ for (let a = 0; a < r; a++) s.fields[a] = O(this, L, pt).call(this);
610
613
  return s;
611
614
  }, pt = function() {
612
615
  let e = h(this, w).cstring(), t = h(this, w).int32(), n = h(this, w).int16(), r = h(this, w).int32(), s = h(this, w).int16(), a = h(this, w).int32(), i = h(this, w).int16() === 0 ? rt.text : rt.binary;
@@ -628,11 +631,11 @@ B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__
628
631
  h(this, w).setBuffer(e, n);
629
632
  let r = h(this, w).cstring(), s = h(this, w).cstring();
630
633
  return new yn(t, r, s);
631
- }, _t = function(e, t, n) {
634
+ }, gt = function(e, t, n) {
632
635
  h(this, w).setBuffer(e, n);
633
636
  let r = h(this, w).int32(), s = h(this, w).int32();
634
- return new _n(t, r, s);
635
- }, gt = function(e, t, n) {
637
+ return new gn(t, r, s);
638
+ }, _t = function(e, t, n) {
636
639
  h(this, w).setBuffer(e, n);
637
640
  let r = h(this, w).int32();
638
641
  switch (r) {
@@ -661,10 +664,10 @@ B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), W = /* @__
661
664
  h(this, w).setBuffer(e, n);
662
665
  let s = {}, a = h(this, w).string(1);
663
666
  for (; a !== "\0"; ) s[a] = h(this, w).cstring(), a = h(this, w).string(1);
664
- let i = s.M, o = r === "notice" ? new An(t, i) : new Be(i, t, r);
667
+ let i = s.M, o = r === "notice" ? new $n(t, i) : new Be(i, t, r);
665
668
  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;
666
669
  };
667
- G();
670
+ H();
668
671
  typeof process == "object" && typeof process.versions == "object" && process.versions.node;
669
672
  var Tt = () => {
670
673
  if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
@@ -715,64 +718,64 @@ function Nt(e) {
715
718
  return n || r(), a;
716
719
  };
717
720
  }
718
- G();
719
- var Cr = 5, qr = async (e, t) => {
721
+ H();
722
+ var Lr = 5, Mr = async (e, t) => {
720
723
  let n = /* @__PURE__ */ new Set(), r = { async query(s, a, i) {
721
724
  let o, c, u;
722
725
  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");
723
- let l = c !== void 0 && u !== void 0, p;
726
+ let l = c !== void 0 && u !== void 0, d;
724
727
  if (l && (typeof c != "number" || isNaN(c) || typeof u != "number" || isNaN(u))) throw new Error("offset and limit must be numbers");
725
- let f = i ? [i] : [], d = Tt().replace(/-/g, ""), g = !1, S, N, $ = async () => {
726
- await e.transaction(async (_) => {
727
- let R = a && a.length > 0 ? await wt(e, s, a, _) : s;
728
- await _.exec(`CREATE OR REPLACE TEMP VIEW live_query_${d}_view AS ${R}`);
729
- let I = await At(_, `live_query_${d}_view`);
730
- await $t(_, I, n), l ? (await _.exec(`
731
- PREPARE live_query_${d}_get(int, int) AS
732
- SELECT * FROM live_query_${d}_view
728
+ let f = i ? [i] : [], p = Tt().replace(/-/g, ""), _ = !1, S, $, A = async () => {
729
+ await e.transaction(async (g) => {
730
+ let R = a && a.length > 0 ? await wt(e, s, a, g) : s;
731
+ await g.exec(`CREATE OR REPLACE TEMP VIEW live_query_${p}_view AS ${R}`);
732
+ let I = await $t(g, `live_query_${p}_view`);
733
+ await At(g, I, n), l ? (await g.exec(`
734
+ PREPARE live_query_${p}_get(int, int) AS
735
+ SELECT * FROM live_query_${p}_view
733
736
  LIMIT $1 OFFSET $2;
734
- `), await _.exec(`
735
- PREPARE live_query_${d}_get_total_count AS
736
- SELECT COUNT(*) FROM live_query_${d}_view;
737
- `), p = (await _.query(`EXECUTE live_query_${d}_get_total_count;`)).rows[0].count, S = { ...await _.query(`EXECUTE live_query_${d}_get(${u}, ${c});`), offset: c, limit: u, totalCount: p }) : (await _.exec(`
738
- PREPARE live_query_${d}_get AS
739
- SELECT * FROM live_query_${d}_view;
740
- `), S = await _.query(`EXECUTE live_query_${d}_get;`)), N = await Promise.all(I.map((y) => _.listen(`"table_change__${y.schema_oid}__${y.table_oid}"`, async () => {
737
+ `), await g.exec(`
738
+ PREPARE live_query_${p}_get_total_count AS
739
+ SELECT COUNT(*) FROM live_query_${p}_view;
740
+ `), d = (await g.query(`EXECUTE live_query_${p}_get_total_count;`)).rows[0].count, S = { ...await g.query(`EXECUTE live_query_${p}_get(${u}, ${c});`), offset: c, limit: u, totalCount: d }) : (await g.exec(`
741
+ PREPARE live_query_${p}_get AS
742
+ SELECT * FROM live_query_${p}_view;
743
+ `), S = await g.query(`EXECUTE live_query_${p}_get;`)), $ = await Promise.all(I.map((y) => g.listen(`"table_change__${y.schema_oid}__${y.table_oid}"`, async () => {
741
744
  b();
742
745
  })));
743
746
  });
744
747
  };
745
- await $();
746
- let b = Nt(async ({ offset: _, limit: R } = {}) => {
747
- if (!l && (_ !== void 0 || R !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
748
- if (_ && (typeof _ != "number" || isNaN(_)) || R && (typeof R != "number" || isNaN(R))) throw new Error("offset and limit must be numbers");
749
- c = _ ?? c, u = R ?? u;
748
+ await A();
749
+ let b = Nt(async ({ offset: g, limit: R } = {}) => {
750
+ if (!l && (g !== void 0 || R !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
751
+ if (g && (typeof g != "number" || isNaN(g)) || R && (typeof R != "number" || isNaN(R))) throw new Error("offset and limit must be numbers");
752
+ c = g ?? c, u = R ?? u;
750
753
  let I = async (y = 0) => {
751
754
  if (f.length !== 0) {
752
755
  try {
753
- l ? S = { ...await e.query(`EXECUTE live_query_${d}_get(${u}, ${c});`), offset: c, limit: u, totalCount: p } : S = await e.query(`EXECUTE live_query_${d}_get;`);
756
+ l ? S = { ...await e.query(`EXECUTE live_query_${p}_get(${u}, ${c});`), offset: c, limit: u, totalCount: d } : S = await e.query(`EXECUTE live_query_${p}_get;`);
754
757
  } catch (T) {
755
- let F = T.message;
756
- if (F.startsWith(`prepared statement "live_query_${d}`) && F.endsWith("does not exist")) {
757
- if (y > Cr) throw T;
758
- await $(), I(y + 1);
758
+ let k = T.message;
759
+ if (k.startsWith(`prepared statement "live_query_${p}`) && k.endsWith("does not exist")) {
760
+ if (y > Lr) throw T;
761
+ await A(), I(y + 1);
759
762
  } else throw T;
760
763
  }
761
764
  if (se(f, S), l) {
762
- let T = (await e.query(`EXECUTE live_query_${d}_get_total_count;`)).rows[0].count;
763
- T !== p && (p = T, b());
765
+ let T = (await e.query(`EXECUTE live_query_${p}_get_total_count;`)).rows[0].count;
766
+ T !== d && (d = T, b());
764
767
  }
765
768
  }
766
769
  };
767
770
  await I();
768
- }), E = (_) => {
769
- if (g) throw new Error("Live query is no longer active and cannot be subscribed to");
770
- f.push(_);
771
- }, m = async (_) => {
772
- _ ? f = f.filter((R) => R !== R) : f = [], f.length === 0 && !g && (g = !0, await e.transaction(async (R) => {
773
- await Promise.all(N.map((I) => I(R))), await R.exec(`
774
- DROP VIEW IF EXISTS live_query_${d}_view;
775
- DEALLOCATE live_query_${d}_get;
771
+ }), E = (g) => {
772
+ if (_) throw new Error("Live query is no longer active and cannot be subscribed to");
773
+ f.push(g);
774
+ }, m = async (g) => {
775
+ g ? f = f.filter((R) => R !== R) : f = [], f.length === 0 && !_ && (_ = !0, await e.transaction(async (R) => {
776
+ await Promise.all($.map((I) => I(R))), await R.exec(`
777
+ DROP VIEW IF EXISTS live_query_${p}_view;
778
+ DEALLOCATE live_query_${p}_get;
776
779
  `);
777
780
  }));
778
781
  };
@@ -782,12 +785,12 @@ var Cr = 5, qr = async (e, t) => {
782
785
  }, async changes(s, a, i, o) {
783
786
  let c;
784
787
  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");
785
- let u = o ? [o] : [], l = Tt().replace(/-/g, ""), p = !1, f = 1, d, g, S = async () => {
788
+ let u = o ? [o] : [], l = Tt().replace(/-/g, ""), d = !1, f = 1, p, _, S = async () => {
786
789
  await e.transaction(async (E) => {
787
790
  let m = await wt(e, s, a, E);
788
791
  await E.query(`CREATE OR REPLACE TEMP VIEW live_query_${l}_view AS ${m}`);
789
- let _ = await At(E, `live_query_${l}_view`);
790
- await $t(E, _, n);
792
+ let g = await $t(E, `live_query_${l}_view`);
793
+ await At(E, g, n);
791
794
  let R = [...(await E.query(`
792
795
  SELECT column_name, data_type, udt_name
793
796
  FROM information_schema.columns
@@ -818,7 +821,7 @@ var Cr = 5, qr = async (e, t) => {
818
821
  -- DELETE operations: Include only the primary key
819
822
  SELECT
820
823
  'DELETE' AS __op__,
821
- ${R.map(({ column_name: T, data_type: F, udt_name: X }) => T === i ? `prev."${T}" AS "${T}"` : `NULL${F === "USER-DEFINED" ? `::${X}` : ""} AS "${T}"`).join(`,
824
+ ${R.map(({ column_name: T, data_type: k, udt_name: Q }) => T === i ? `prev."${T}" AS "${T}"` : `NULL${k === "USER-DEFINED" ? `::${Q}` : ""} AS "${T}"`).join(`,
822
825
  `)},
823
826
  ARRAY[]::text[] AS __changed_columns__
824
827
  FROM prev
@@ -828,10 +831,10 @@ var Cr = 5, qr = async (e, t) => {
828
831
  -- UPDATE operations: Include only changed columns
829
832
  SELECT
830
833
  'UPDATE' AS __op__,
831
- ${R.map(({ column_name: T, data_type: F, udt_name: X }) => T === i ? `curr."${T}" AS "${T}"` : `CASE
834
+ ${R.map(({ column_name: T, data_type: k, udt_name: Q }) => T === i ? `curr."${T}" AS "${T}"` : `CASE
832
835
  WHEN curr."${T}" IS DISTINCT FROM prev."${T}"
833
836
  THEN curr."${T}"
834
- ELSE NULL${F === "USER-DEFINED" ? `::${X}` : ""}
837
+ ELSE NULL${k === "USER-DEFINED" ? `::${Q}` : ""}
835
838
  END AS "${T}"`).join(`,
836
839
  `)},
837
840
  ARRAY(SELECT unnest FROM unnest(ARRAY[${R.filter(({ column_name: T }) => T !== i).map(({ column_name: T }) => `CASE
@@ -846,38 +849,38 @@ var Cr = 5, qr = async (e, t) => {
846
849
  SELECT * FROM data_diff;
847
850
  `);
848
851
  }
849
- g = await Promise.all(_.map((I) => E.listen(`"table_change__${I.schema_oid}__${I.table_oid}"`, async () => {
850
- N();
852
+ _ = await Promise.all(g.map((I) => E.listen(`"table_change__${I.schema_oid}__${I.table_oid}"`, async () => {
853
+ $();
851
854
  })));
852
855
  });
853
856
  };
854
857
  await S();
855
- let N = Nt(async () => {
856
- if (u.length === 0 && d) return;
858
+ let $ = Nt(async () => {
859
+ if (u.length === 0 && p) return;
857
860
  let E = !1;
858
861
  for (let m = 0; m < 5; m++) try {
859
- await e.transaction(async (_) => {
860
- await _.exec(`
862
+ await e.transaction(async (g) => {
863
+ await g.exec(`
861
864
  INSERT INTO live_query_${l}_state${f}
862
865
  SELECT * FROM live_query_${l}_view;
863
- `), d = await _.query(`EXECUTE live_query_${l}_diff${f};`), f = f === 1 ? 2 : 1, await _.exec(`
866
+ `), p = await g.query(`EXECUTE live_query_${l}_diff${f};`), f = f === 1 ? 2 : 1, await g.exec(`
864
867
  TRUNCATE live_query_${l}_state${f};
865
868
  `);
866
869
  });
867
870
  break;
868
- } catch (_) {
869
- if (_.message === `relation "live_query_${l}_state${f}" does not exist`) {
871
+ } catch (g) {
872
+ if (g.message === `relation "live_query_${l}_state${f}" does not exist`) {
870
873
  E = !0, await S();
871
874
  continue;
872
- } else throw _;
875
+ } else throw g;
873
876
  }
874
- Pr(u, [...E ? [{ __op__: "RESET" }] : [], ...d.rows]);
875
- }), $ = (E) => {
876
- if (p) throw new Error("Live query is no longer active and cannot be subscribed to");
877
+ Pr(u, [...E ? [{ __op__: "RESET" }] : [], ...p.rows]);
878
+ }), A = (E) => {
879
+ if (d) throw new Error("Live query is no longer active and cannot be subscribed to");
877
880
  u.push(E);
878
881
  }, b = async (E) => {
879
- E ? u = u.filter((m) => m !== m) : u = [], u.length === 0 && !p && (p = !0, await e.transaction(async (m) => {
880
- await Promise.all(g.map((_) => _(m))), await m.exec(`
882
+ E ? u = u.filter((m) => m !== m) : u = [], u.length === 0 && !d && (d = !0, await e.transaction(async (m) => {
883
+ await Promise.all(_.map((g) => g(m))), await m.exec(`
881
884
  DROP VIEW IF EXISTS live_query_${l}_view;
882
885
  DROP TABLE IF EXISTS live_query_${l}_state1;
883
886
  DROP TABLE IF EXISTS live_query_${l}_state2;
@@ -888,55 +891,55 @@ var Cr = 5, qr = async (e, t) => {
888
891
  };
889
892
  return c?.aborted ? await b() : c?.addEventListener("abort", () => {
890
893
  b();
891
- }, { once: !0 }), await N(), { fields: d.fields.filter((E) => !["__after__", "__op__", "__changed_columns__"].includes(E.name)), initialChanges: d.rows, subscribe: $, unsubscribe: b, refresh: N };
894
+ }, { once: !0 }), await $(), { fields: p.fields.filter((E) => !["__after__", "__op__", "__changed_columns__"].includes(E.name)), initialChanges: p.rows, subscribe: A, unsubscribe: b, refresh: $ };
892
895
  }, async incrementalQuery(s, a, i, o) {
893
896
  let c;
894
897
  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");
895
- let u = o ? [o] : [], l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f = [], d = !0, { fields: g, unsubscribe: S, refresh: N } = await r.changes(s, a, i, (E) => {
898
+ let u = o ? [o] : [], l = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = [], p = !0, { fields: _, unsubscribe: S, refresh: $ } = await r.changes(s, a, i, (E) => {
896
899
  for (let R of E) {
897
900
  let { __op__: I, __changed_columns__: y, ...T } = R;
898
901
  switch (I) {
899
902
  case "RESET":
900
- l.clear(), p.clear();
903
+ l.clear(), d.clear();
901
904
  break;
902
905
  case "INSERT":
903
- l.set(T[i], T), p.set(T.__after__, T[i]);
906
+ l.set(T[i], T), d.set(T.__after__, T[i]);
904
907
  break;
905
908
  case "DELETE": {
906
- let F = l.get(T[i]);
907
- l.delete(T[i]), F.__after__ !== null && p.delete(F.__after__);
909
+ let k = l.get(T[i]);
910
+ l.delete(T[i]), k.__after__ !== null && d.delete(k.__after__);
908
911
  break;
909
912
  }
910
913
  case "UPDATE": {
911
- let F = { ...l.get(T[i]) ?? {} };
912
- for (let X of y) F[X] = T[X], X === "__after__" && p.set(T.__after__, T[i]);
913
- l.set(T[i], F);
914
+ let k = { ...l.get(T[i]) ?? {} };
915
+ for (let Q of y) k[Q] = T[Q], Q === "__after__" && d.set(T.__after__, T[i]);
916
+ l.set(T[i], k);
914
917
  break;
915
918
  }
916
919
  }
917
920
  }
918
- let m = [], _ = null;
921
+ let m = [], g = null;
919
922
  for (let R = 0; R < l.size; R++) {
920
- let I = p.get(_), y = l.get(I);
923
+ let I = d.get(g), y = l.get(I);
921
924
  if (!y) break;
922
925
  let T = { ...y };
923
- delete T.__after__, m.push(T), _ = I;
926
+ delete T.__after__, m.push(T), g = I;
924
927
  }
925
- f = m, d || se(u, { rows: m, fields: g });
928
+ f = m, p || se(u, { rows: m, fields: _ });
926
929
  });
927
- d = !1, se(u, { rows: f, fields: g });
928
- let $ = (E) => {
930
+ p = !1, se(u, { rows: f, fields: _ });
931
+ let A = (E) => {
929
932
  u.push(E);
930
933
  }, b = async (E) => {
931
934
  E ? u = u.filter((m) => m !== m) : u = [], u.length === 0 && await S();
932
935
  };
933
936
  return c?.aborted ? await b() : c?.addEventListener("abort", () => {
934
937
  b();
935
- }, { once: !0 }), { initialResults: { rows: f, fields: g }, subscribe: $, unsubscribe: b, refresh: N };
938
+ }, { once: !0 }), { initialResults: { rows: f, fields: _ }, subscribe: A, unsubscribe: b, refresh: $ };
936
939
  } };
937
940
  return { namespaceObj: r };
938
- }, Mr = { name: "Live Queries", setup: qr };
939
- async function At(e, t) {
941
+ }, qr = { name: "Live Queries", setup: Mr };
942
+ async function $t(e, t) {
940
943
  return (await e.query(`
941
944
  WITH RECURSIVE view_dependencies AS (
942
945
  -- Base case: Get the initial view's dependencies
@@ -983,7 +986,7 @@ async function At(e, t) {
983
986
  WHERE NOT is_view; -- Exclude intermediate views
984
987
  `, [t])).rows.map((n) => ({ table_name: n.table_name, schema_name: n.schema_name, table_oid: n.table_oid, schema_oid: n.schema_oid }));
985
988
  }
986
- async function $t(e, t, n) {
989
+ async function At(e, t, n) {
987
990
  let r = t.filter((s) => !n.has(`${s.schema_oid}_${s.table_oid}`)).map((s) => `
988
991
  CREATE OR REPLACE FUNCTION "_notify_${s.schema_oid}_${s.table_oid}"() RETURNS TRIGGER AS $$
989
992
  BEGIN
@@ -1016,7 +1019,7 @@ class Rt extends Wn {
1016
1019
  dataDir: n.store === "memory" ? void 0 : `idb://${t}`,
1017
1020
  database: t,
1018
1021
  extensions: {
1019
- live: Mr
1022
+ live: qr
1020
1023
  }
1021
1024
  }), await this.#e.waitReady;
1022
1025
  const r = ["rxdb_change", "rxdb_branch", "rxdb_migration"];
@@ -1099,12 +1102,12 @@ const Sn = (e, t) => {
1099
1102
  ...e.foreignKeyColumnNames || e.foreignKeyNames
1100
1103
  ], o = [];
1101
1104
  t.forEach((u) => {
1102
- const l = Ct(e, u);
1105
+ const l = Lt(e, u);
1103
1106
  s && (l.createdBy = n.userId), a && (l.updatedBy = n.userId);
1104
- const p = Ke(e, l), f = [];
1105
- i.forEach((d) => {
1106
- const g = p[d];
1107
- f.push(Qe(g));
1107
+ const d = Ke(e, l), f = [];
1108
+ i.forEach((p) => {
1109
+ const _ = d[p];
1110
+ f.push(Je(_));
1108
1111
  }), o.push(`(${f.join(",")})`);
1109
1112
  });
1110
1113
  const c = i.map((u) => `"${u}"`).join(",");
@@ -1117,11 +1120,11 @@ const Sn = (e, t) => {
1117
1120
  return ["public", e];
1118
1121
  }, jr = (e) => {
1119
1122
  switch (e) {
1120
- case V.INSERT:
1123
+ case K.INSERT:
1121
1124
  return "INSERT";
1122
- case V.UPDATE:
1125
+ case K.UPDATE:
1123
1126
  return "UPDATE";
1124
- case V.DELETE:
1127
+ case K.DELETE:
1125
1128
  return "DELETE";
1126
1129
  }
1127
1130
  }, xr = (e, t) => {
@@ -1161,7 +1164,7 @@ const Sn = (e, t) => {
1161
1164
  break;
1162
1165
  }
1163
1166
  }
1164
- }, Le = (e, t) => {
1167
+ }, Ce = (e, t) => {
1165
1168
  const { tableName: n } = t, [r, s] = Ur(n), a = e.rxdb.schemaManager.getEntityTypeByTableName(s, r);
1166
1169
  if (!a) return;
1167
1170
  const i = e.getRepository(a), o = e.rxdb.schemaManager.getEntityMetadataByTableName(s, r);
@@ -1173,8 +1176,8 @@ const Sn = (e, t) => {
1173
1176
  const u = c;
1174
1177
  if (!(!u || u.length === 0))
1175
1178
  if (a === ie) {
1176
- if (xr(e, c), t.type === V.INSERT) {
1177
- const l = D(ie), p = c.map((f) => ({
1179
+ if (xr(e, c), t.type === K.INSERT) {
1180
+ const l = D(ie), d = c.map((f) => ({
1178
1181
  namespace: l.namespace,
1179
1182
  entity: l.name,
1180
1183
  type: f.type,
@@ -1183,11 +1186,11 @@ const Sn = (e, t) => {
1183
1186
  inversePatch: null,
1184
1187
  recordAt: f.createdAt || /* @__PURE__ */ new Date()
1185
1188
  }));
1186
- e.rxdb.dispatchEvent(new oe(p));
1189
+ e.rxdb.dispatchEvent(new oe(d));
1187
1190
  }
1188
1191
  } else {
1189
- const l = jr(t.type), p = u.map((f) => {
1190
- const d = {
1192
+ const l = jr(t.type), d = u.map((f) => {
1193
+ const p = {
1191
1194
  namespace: o.namespace,
1192
1195
  entity: o.name,
1193
1196
  type: l,
@@ -1197,19 +1200,19 @@ const Sn = (e, t) => {
1197
1200
  recordAt: f.createdAt || /* @__PURE__ */ new Date()
1198
1201
  };
1199
1202
  switch (t.type) {
1200
- case V.INSERT:
1203
+ case K.INSERT:
1201
1204
  return {
1202
- ...d,
1205
+ ...p,
1203
1206
  patch: { ...f }
1204
1207
  };
1205
- case V.DELETE:
1208
+ case K.DELETE:
1206
1209
  return {
1207
- ...d,
1210
+ ...p,
1208
1211
  inversePatch: { ...f }
1209
1212
  };
1210
- case V.UPDATE:
1213
+ case K.UPDATE:
1211
1214
  return {
1212
- ...d,
1215
+ ...p,
1213
1216
  // 注意:这里无法获取变更前的数据,只能把整个 entity 作为 patch
1214
1217
  // 这是 UPDATE hook 的限制,完整的 patch/inversePatch 应该从 RxDBChange 表获取
1215
1218
  inversePatch: null,
@@ -1220,17 +1223,17 @@ const Sn = (e, t) => {
1220
1223
  switch (l) {
1221
1224
  case "UPDATE":
1222
1225
  e.rxdb.dispatchEvent(
1223
- new me(p)
1226
+ new me(d)
1224
1227
  );
1225
1228
  break;
1226
1229
  case "DELETE":
1227
1230
  e.rxdb.dispatchEvent(
1228
- new Ve(p)
1231
+ new Ve(d)
1229
1232
  );
1230
1233
  break;
1231
1234
  case "INSERT":
1232
1235
  e.rxdb.dispatchEvent(
1233
- new oe(p)
1236
+ new oe(d)
1234
1237
  );
1235
1238
  break;
1236
1239
  }
@@ -1245,30 +1248,30 @@ const Sn = (e, t) => {
1245
1248
  params: r
1246
1249
  };
1247
1250
  }, In = (e, t, n) => {
1248
- const r = P(e), s = Ct(e, t);
1251
+ const r = P(e), s = Lt(e, t);
1249
1252
  n?.userId && (e.propertyMap.has("createdBy") && (s.createdBy = n.userId), e.propertyMap.has("updatedBy") && (s.updatedBy = n.userId));
1250
1253
  const a = {};
1251
1254
  Object.keys(s).forEach((f) => {
1252
- const d = s[f];
1253
- d != null && (a[f] = d);
1255
+ const p = s[f];
1256
+ p != null && (a[f] = p);
1254
1257
  });
1255
- const i = Object.keys(a), o = Ke(e, a), c = [], u = i.map((f, d) => (c.push(o[f]), `$${d + 1}`)), l = i.map((f) => `"${f}"`).join(",");
1256
- let p = `INSERT INTO ${r} (${l}) VALUES (${u.join(",")})`;
1257
- return n?.returning !== !1 ? p += " RETURNING *;" : p += ";", { sql: p, params: c };
1258
+ const i = Object.keys(a), o = Ke(e, a), c = [], u = i.map((f, p) => (c.push(o[f]), `$${p + 1}`)), l = i.map((f) => `"${f}"`).join(",");
1259
+ let d = `INSERT INTO ${r} (${l}) VALUES (${u.join(",")})`;
1260
+ return n?.returning !== !1 ? d += " RETURNING *;" : d += ";", { sql: d, params: c };
1258
1261
  }, ze = (e, t, n, r) => {
1259
1262
  const s = zn(e, n);
1260
1263
  e.propertyMap.has("updatedAt") && (s.updatedAt = r?.updatedAt ?? /* @__PURE__ */ new Date()), r?.userId && e.propertyMap.has("updatedBy") && (s.updatedBy = r.userId);
1261
- const a = Ke(e, s), o = Object.keys(s).map((f, d) => `"${f}" = $${d + 1}`).join(","), c = [...Object.values(a)], u = P(e), l = Array.isArray(t) ? t : [t];
1262
- let p = `UPDATE ${u} SET ${o} WHERE id `;
1264
+ const a = Ke(e, s), o = Object.keys(s).map((f, p) => `"${f}" = $${p + 1}`).join(","), c = [...Object.values(a)], u = P(e), l = Array.isArray(t) ? t : [t];
1265
+ let d = `UPDATE ${u} SET ${o} WHERE id `;
1263
1266
  if (Array.isArray(t)) {
1264
1267
  const f = c.length + 1;
1265
- p += `= ANY($${f})`, c.push(l.map((d) => d.id));
1268
+ d += `= ANY($${f})`, c.push(l.map((p) => p.id));
1266
1269
  } else {
1267
1270
  const f = c.length + 1;
1268
- p += `= $${f}`, c.push(t.id);
1271
+ d += `= $${f}`, c.push(t.id);
1269
1272
  }
1270
- return r?.returning !== !1 ? p += " RETURNING *;" : p += ";", {
1271
- sql: p,
1273
+ return r?.returning !== !1 ? d += " RETURNING *;" : d += ";", {
1274
+ sql: d,
1272
1275
  params: c
1273
1276
  };
1274
1277
  }, Ze = "_", On = (e) => e.replaceAll(".", "_"), he = (e, t) => {
@@ -1291,64 +1294,91 @@ const Sn = (e, t) => {
1291
1294
  if (i.length === 0) continue;
1292
1295
  const { metaWalker: o, relPairs: c } = Fr(e, n, s, a);
1293
1296
  if (!o || c.length === 0) continue;
1294
- const u = i[0], l = i.slice(1).join("."), p = o.propertyMap.get(u);
1295
- if (p && p.type === A.keyValue) {
1297
+ const u = i[0], l = i.slice(1).join("."), d = o.propertyMap.get(u);
1298
+ if (d && d.type === N.keyValue) {
1296
1299
  const f = s.slice(0, a).join(".");
1297
1300
  vn(e, t, c, f);
1298
- const d = c[c.length - 1].relation, g = de(c, f, d), S = he(t, g), N = l ? `$.${l}` : "$";
1299
- return t.fieldAliasMap.set(r, `"${S}"."${p.columnName}" ->> '${N.replace("$.", "")}'`), !0;
1301
+ const p = c[c.length - 1].relation, _ = de(c, f, p), S = he(t, _), $ = l ? `$.${l}` : "$";
1302
+ return t.fieldAliasMap.set(r, `"${S}"."${d.columnName}" ->> '${$.replace("$.", "")}'`), !0;
1300
1303
  }
1301
1304
  }
1302
1305
  return !1;
1303
1306
  }, vn = (e, t, n, r) => {
1304
1307
  n.forEach(({ metadata: s, relation: a }, i) => {
1305
- const o = e.rxdb.schemaManager.findMappedRelation(s, a);
1308
+ let o = e.rxdb.schemaManager.findMappedRelation(s, a);
1309
+ if (!o)
1310
+ if (a.kind === F.ONE_TO_MANY || a.kind === F.MANY_TO_MANY) {
1311
+ const d = s.relationMap.get(a.mappedProperty);
1312
+ d && (o = { metadata: s, relation: d });
1313
+ } else (a.kind === F.MANY_TO_ONE || a.kind === F.ONE_TO_ONE) && (o = { metadata: s, relation: a });
1306
1314
  if (!o) throw new x("mappedRelation not found");
1307
1315
  const c = de(n, r, a), u = he(t, c);
1308
1316
  let l = Ze;
1309
1317
  if (i > 0) {
1310
- const p = n[i - 1], f = de(n, r, p.relation);
1318
+ const d = n[i - 1], f = de(n, r, d.relation);
1311
1319
  l = he(t, f);
1312
1320
  }
1313
1321
  switch (a.kind) {
1314
- case Q.ONE_TO_MANY:
1315
- Wr(t, o, u, l);
1322
+ case F.ONE_TO_MANY:
1323
+ Wr(
1324
+ t,
1325
+ o,
1326
+ u,
1327
+ l
1328
+ );
1316
1329
  break;
1317
- case Q.ONE_TO_ONE:
1318
- case Q.MANY_TO_ONE:
1319
- Gr(t, o, u, l, a);
1330
+ case F.ONE_TO_ONE:
1331
+ case F.MANY_TO_ONE:
1332
+ Gr(
1333
+ t,
1334
+ o,
1335
+ u,
1336
+ l,
1337
+ a
1338
+ );
1320
1339
  break;
1321
- case Q.MANY_TO_MANY:
1322
- Hr(e, t, o, u, l, a);
1340
+ case F.MANY_TO_MANY:
1341
+ Hr(
1342
+ t,
1343
+ o,
1344
+ u,
1345
+ l,
1346
+ a
1347
+ );
1323
1348
  break;
1324
1349
  }
1325
1350
  });
1326
1351
  }, Wr = (e, t, n, r) => {
1327
- const s = fe(e, t.metadata), a = t.relation.columnName;
1328
- s.push({
1352
+ const s = fe(e, t.metadata), a = t.relation.columnName, i = `"${n}"."${a}" = ${et(r)}."id"`;
1353
+ s.find((c) => c.joinTableName === n && c.on === i) || s.push({
1329
1354
  joinTableName: n,
1330
- on: `"${n}"."${a}" = ${et(r)}."id"`
1355
+ on: i
1331
1356
  });
1332
1357
  }, Gr = (e, t, n, r, s) => {
1333
- fe(e, t.metadata).push({
1358
+ const a = fe(e, t.metadata), i = `"${n}"."id" = ${et(r)}."${s.columnName}"`;
1359
+ a.find((c) => c.joinTableName === n && c.on === i) || a.push({
1334
1360
  joinTableName: n,
1335
- on: `"${n}"."id" = ${et(r)}."${s.columnName}"`
1361
+ on: i
1336
1362
  });
1337
- }, Hr = (e, t, n, r, s, a) => {
1338
- const i = D(a.junctionEntityType), o = fe(t, i), c = Dn(t, On(`${a.name}_m_n`));
1339
- o.push({
1340
- joinTableName: c,
1341
- on: `"${c}"."${n.relation.columnName}" = ${et(s)}."id"`
1342
- }), fe(t, n.metadata).push({
1343
- joinTableName: r,
1344
- on: `"${r}"."id" = "${c}"."${a.columnName}"`
1363
+ }, Hr = (e, t, n, r, s) => {
1364
+ const a = D(s.junctionEntityType), i = fe(e, a), o = Dn(e, On(`${s.name}_m_n`)), c = `"${o}"."${t.relation.columnName}" = ${et(r)}."id"`;
1365
+ i.find(
1366
+ (p) => p.joinTableName === o && p.on === c
1367
+ ) || i.push({
1368
+ joinTableName: o,
1369
+ on: c
1370
+ });
1371
+ const l = fe(e, t.metadata), d = `"${n}"."id" = "${o}"."${s.columnName}"`;
1372
+ l.find((p) => p.joinTableName === n && p.on === d) || l.push({
1373
+ joinTableName: n,
1374
+ on: d
1345
1375
  });
1346
1376
  }, fe = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), Dn = (e, t) => {
1347
1377
  let n = t, r = 1;
1348
1378
  for (; e.usedAliases.has(n); )
1349
1379
  n = `${t}_${r++}`;
1350
1380
  return e.usedAliases.add(n), n;
1351
- }, de = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, et = (e) => e === Ze ? e : `"${e}"`, Ln = (e, t, n) => {
1381
+ }, de = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, et = (e) => e === Ze ? e : `"${e}"`, Cn = (e, t, n) => {
1352
1382
  const r = {
1353
1383
  joinMap: /* @__PURE__ */ new Map(),
1354
1384
  usedAliases: /* @__PURE__ */ new Set(),
@@ -1376,13 +1406,13 @@ const Sn = (e, t) => {
1376
1406
  }
1377
1407
  const l = r.replace(`.${u.propertyName}`, "");
1378
1408
  vn(e, t, u.relations, l);
1379
- const p = u.relations[u.relations.length - 1], f = de(u.relations, l, p.relation), d = he(t, f);
1380
- t.fieldAliasMap.set(r, `"${d}"."${u.property.columnName}"`);
1409
+ const d = u.relations[u.relations.length - 1], f = de(u.relations, l, d.relation), p = he(t, f);
1410
+ t.fieldAliasMap.set(r, `"${p}"."${u.property.columnName}"`);
1381
1411
  return;
1382
1412
  } catch {
1383
1413
  }
1384
1414
  const [i, ...o] = a, c = n.propertyMap.get(i);
1385
- if (c && c.type === A.keyValue && o.length > 0) {
1415
+ if (c && c.type === N.keyValue && o.length > 0) {
1386
1416
  const u = o.join(".");
1387
1417
  t.fieldAliasMap.set(r, `"${Ze}"."${c.columnName}" ->> '${u}'`);
1388
1418
  return;
@@ -1405,13 +1435,13 @@ const Sn = (e, t) => {
1405
1435
  notStartsWith: "NOT LIKE",
1406
1436
  endsWith: "LIKE",
1407
1437
  notEndsWith: "NOT LIKE"
1408
- }, Qr = (e, t) => {
1438
+ }, Jr = (e, t) => {
1409
1439
  if (e?.length)
1410
1440
  return e.map((n) => {
1411
- const r = Cn(n.field, t);
1441
+ const r = Ln(n.field, t);
1412
1442
  return `${pe}."${r}" ${n.sort.toUpperCase()}`;
1413
1443
  }).join(", ");
1414
- }, Yr = (e) => Kr[e] || e, Xr = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), Cn = (e, t) => {
1444
+ }, Yr = (e) => Kr[e] || e, Qr = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), Ln = (e, t) => {
1415
1445
  if (t && !e.includes(".")) {
1416
1446
  const n = t.propertyMap.get(e);
1417
1447
  if (n)
@@ -1421,19 +1451,19 @@ const Sn = (e, t) => {
1421
1451
  return s[a];
1422
1452
  }
1423
1453
  return e;
1424
- }, Jr = (e, t, n) => {
1454
+ }, Xr = (e, t, n) => {
1425
1455
  if (t) return t;
1426
1456
  if (!e.includes(".")) {
1427
- const o = Cn(e, n);
1457
+ const o = Ln(e, n);
1428
1458
  return o.toLowerCase() !== o ? `"${o}"` : o;
1429
1459
  }
1430
1460
  const r = e.split("."), s = r[0], a = n?.propertyMap.get(s);
1431
- if (a && (a.type === A.json || a.type === A.keyValue) && r.length === 2)
1461
+ if (a && (a.type === N.json || a.type === N.keyValue) && r.length === 2)
1432
1462
  return `"${a.columnName}" ->> '${r[1]}'`;
1433
1463
  const i = e.lastIndexOf(".");
1434
1464
  return `"${e.slice(0, i)}".${e.slice(i + 1)}`;
1435
1465
  }, zr = (e, t, n = /* @__PURE__ */ new Map(), r) => {
1436
- const s = String(e.field), a = n.get(s), i = Jr(s, a, r), o = e.value, c = e.operator;
1466
+ const s = String(e.field), a = n.get(s), i = Xr(s, a, r), o = e.value, c = e.operator;
1437
1467
  if (c === "null" || c === "notNull")
1438
1468
  return c === "null" ? `${i} IS NULL` : `${i} IS NOT NULL`;
1439
1469
  if (o === null)
@@ -1441,13 +1471,13 @@ const Sn = (e, t) => {
1441
1471
  let u = s;
1442
1472
  a && s.includes(".") && (u = s.split(".").pop() || s);
1443
1473
  const l = r?.propertyMap.get(u.split(".")[0]);
1444
- if (l && (l.type === A.json || l.type === A.keyValue)) {
1474
+ if (l && (l.type === N.json || l.type === N.keyValue)) {
1445
1475
  if (c === "contains" && typeof o == "object" && !Array.isArray(o))
1446
1476
  return t.push(JSON.stringify(o)), `${i} @> $${t.length}::jsonb`;
1447
1477
  if (c === "notContains" && typeof o == "object" && !Array.isArray(o))
1448
1478
  return t.push(JSON.stringify(o)), `NOT (${i} @> $${t.length}::jsonb)`;
1449
1479
  }
1450
- if (l && (l.type === A.stringArray || l.type === A.numberArray) && (c === "in" || c === "notIn")) {
1480
+ if (l && (l.type === N.stringArray || l.type === N.numberArray) && (c === "in" || c === "notIn")) {
1451
1481
  if (!Array.isArray(o)) return "";
1452
1482
  t.push(JSON.stringify(o));
1453
1483
  const f = `${i} @> $${t.length}::jsonb`;
@@ -1460,14 +1490,14 @@ const Sn = (e, t) => {
1460
1490
  if (["contains", "notContains", "startsWith", "notStartsWith", "endsWith", "notEndsWith"].includes(c)) {
1461
1491
  let f = "";
1462
1492
  c === "contains" || c === "notContains" ? f = `%${o}%` : c === "startsWith" || c === "notStartsWith" ? f = `${o}%` : (c === "endsWith" || c === "notEndsWith") && (f = `%${o}`), t.push(f);
1463
- const d = c.startsWith("not") ? "NOT LIKE" : "LIKE";
1464
- return `${i} ${d} $${t.length}`;
1493
+ const p = c.startsWith("not") ? "NOT LIKE" : "LIKE";
1494
+ return `${i} ${p} $${t.length}`;
1465
1495
  }
1466
- const p = Yr(c);
1467
- return t.push(o), l && l.type === A.uuid ? `${i}::uuid ${p} $${t.length}::uuid` : `${i} ${p} $${t.length}`;
1496
+ const d = Yr(c);
1497
+ return t.push(o), l && l.type === N.uuid ? `${i}::uuid ${d} $${t.length}::uuid` : `${i} ${d} $${t.length}`;
1468
1498
  }, we = (e, t, n = /* @__PURE__ */ new Map(), r) => {
1469
1499
  const s = e.rules.map(
1470
- (i) => Xr(i) ? we(i, t, n, r) : zr(i, t, n, r)
1500
+ (i) => Qr(i) ? we(i, t, n, r) : zr(i, t, n, r)
1471
1501
  ).filter(Boolean);
1472
1502
  if (!s.length) return "";
1473
1503
  if (s.length === 1) return s[0];
@@ -1480,7 +1510,7 @@ const Sn = (e, t) => {
1480
1510
  let t = `SELECT COUNT(*) as count FROM ${e.tableName} AS ${pe}`;
1481
1511
  return e.join && (t += ` ${e.join}`), e.where && (t += ` WHERE ${e.where}`), t;
1482
1512
  }, Ee = (e, t, n) => {
1483
- const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Ln(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0, c = Qr(n.orderBy, t), u = "limit" in n ? n.limit : void 0, l = "offset" in n ? n.offset : void 0;
1513
+ const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Cn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0, c = Jr(n.orderBy, t), u = "limit" in n ? n.limit : void 0, l = "offset" in n ? n.offset : void 0;
1484
1514
  return { sql: Zr(
1485
1515
  {
1486
1516
  tableName: r,
@@ -1495,7 +1525,7 @@ const Sn = (e, t) => {
1495
1525
  }, ta = (e, t, n) => {
1496
1526
  if (n.groupBy)
1497
1527
  throw new x("groupBy not supported in count queries");
1498
- const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Ln(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0;
1528
+ const r = P(t), s = [], { joinSQL: a, fieldAliasMap: i } = n.where ? Cn(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, o = n.where ? we(n.where, s, i, t) : void 0;
1499
1529
  return { sql: ea({
1500
1530
  tableName: r,
1501
1531
  where: o,
@@ -1530,12 +1560,12 @@ class sa extends Fn {
1530
1560
  const s = Z(this.metadata, r), a = s.id;
1531
1561
  let i;
1532
1562
  super.hasEntityRef(a) ? (i = super.getEntityRef(a), n && super.updateEntity(i, s)) : i = this.createEntityRef(s);
1533
- const o = K(i);
1563
+ const o = J(i);
1534
1564
  return o.local = !0, o.modified = !1, i;
1535
1565
  });
1536
1566
  }
1537
1567
  }
1538
- class qn extends sa {
1568
+ class Mn extends sa {
1539
1569
  async get(t) {
1540
1570
  const n = {
1541
1571
  where: {
@@ -1578,25 +1608,25 @@ class qn extends sa {
1578
1608
  const Ne = (e, t, n) => {
1579
1609
  const { isCount: r, isFindDescendants: s, entityId: a, where: i } = n, o = !a, c = P(t);
1580
1610
  let u = "";
1581
- const p = [`c.level < ${n.level || 0}`], f = [];
1611
+ const d = [`c.level < ${n.level || 0}`], f = [];
1582
1612
  if (o || f.push(a), i) {
1583
- const $ = /* @__PURE__ */ new Map(), b = (m) => {
1613
+ const A = /* @__PURE__ */ new Map(), b = (m) => {
1584
1614
  if ("rules" in m)
1585
1615
  return { ...m, rules: m.rules.map(b) };
1586
1616
  if (m.field && typeof m.field == "string" && m.field.startsWith("children.")) {
1587
- const _ = m.field.substring(9), I = t.propertyMap.get(_)?.columnName ?? _;
1588
- $.set(m.field, `children."${I}"`);
1617
+ const g = m.field.substring(9), I = t.propertyMap.get(g)?.columnName ?? g;
1618
+ A.set(m.field, `children."${I}"`);
1589
1619
  }
1590
1620
  return m;
1591
1621
  };
1592
1622
  b(i);
1593
- const E = we(i, f, $, t);
1594
- E && p.push(E);
1623
+ const E = we(i, f, A, t);
1624
+ E && d.push(E);
1595
1625
  }
1596
- const d = p.filter(Boolean).join(" AND ");
1597
- d && (u = `WHERE ${d}`);
1598
- let g = "*";
1599
- return r && (o ? g = "count(*) AS count" : g = "(count(*) - 1) AS count"), {
1626
+ const p = d.filter(Boolean).join(" AND ");
1627
+ p && (u = `WHERE ${p}`);
1628
+ let _ = "*";
1629
+ return r && (o ? _ = "count(*) AS count" : _ = "(count(*) - 1) AS count"), {
1600
1630
  sql: `WITH RECURSIVE __children AS (
1601
1631
  SELECT *, 0 AS level
1602
1632
  FROM ${c}
@@ -1608,11 +1638,11 @@ const Ne = (e, t, n) => {
1608
1638
  ${u}
1609
1639
  )
1610
1640
 
1611
- SELECT ${g} FROM __children${r ? "" : " ORDER BY level, id"};`,
1641
+ SELECT ${_} FROM __children${r ? "" : " ORDER BY level, id"};`,
1612
1642
  params: f
1613
1643
  };
1614
1644
  }, ra = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !0 }), aa = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !0, isCount: !0 }), ia = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !1 }), oa = (e, t, n) => Ne(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
1615
- class ca extends qn {
1645
+ class ca extends Mn {
1616
1646
  async findDescendants(t) {
1617
1647
  const { sql: n, params: r } = ra(this.adapter, this.metadata, t), s = await this.adapter.query(n, r);
1618
1648
  return !s.rows || s.rows.length === 0 ? [] : s.rows.map((i) => {
@@ -1640,18 +1670,18 @@ const la = async (e, t) => {
1640
1670
  const n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Date();
1641
1671
  for (const [s, a] of t.create.entries()) {
1642
1672
  const i = Array.from(a);
1643
- i.forEach((g) => n.add(g));
1673
+ i.forEach((_) => n.add(_));
1644
1674
  const o = D(s), c = ue(o, i, e.rxdb.context);
1645
1675
  await e.query(c);
1646
- const u = i.map((g) => g.id), { sql: l, params: p } = Ee(e, o, {
1676
+ const u = i.map((_) => _.id), { sql: l, params: d } = Ee(e, o, {
1647
1677
  where: { combinator: "and", rules: [{ field: "id", operator: "in", value: u }] }
1648
- }), f = await e.query(l, p), d = e.getRepository(s);
1649
- for (const g of f.rows) {
1650
- const S = Z(o, g), N = S.id;
1651
- if (d.hasEntityRef(N)) {
1652
- const $ = d.getEntityRef(N);
1653
- d.updateEntity($, S);
1654
- const b = K($);
1678
+ }), f = await e.query(l, d), p = e.getRepository(s);
1679
+ for (const _ of f.rows) {
1680
+ const S = Z(o, _), $ = S.id;
1681
+ if (p.hasEntityRef($)) {
1682
+ const A = p.getEntityRef($);
1683
+ p.updateEntity(A, S);
1684
+ const b = J(A);
1655
1685
  b.local = !0, b.modified = !1;
1656
1686
  }
1657
1687
  }
@@ -1660,27 +1690,27 @@ const la = async (e, t) => {
1660
1690
  const i = Array.from(a);
1661
1691
  i.forEach((l) => n.add(l));
1662
1692
  const o = D(s), c = Object.groupBy(i, (l) => {
1663
- const p = K(l);
1664
- return Ot(Object.keys(p.patch || {}).sort());
1693
+ const d = J(l);
1694
+ return Ot(Object.keys(d.patch || {}).sort());
1665
1695
  }), u = e.getRepository(s);
1666
1696
  for (const l of Object.values(c)) {
1667
1697
  if (!l || l.length === 0) continue;
1668
- const p = l[0], f = K(p), { sql: d, params: g } = ze(o, l, f.patch || {}, {
1698
+ const d = l[0], f = J(d), { sql: p, params: _ } = ze(o, l, f.patch || {}, {
1669
1699
  ...e.rxdb.context,
1670
1700
  returning: !1,
1671
1701
  // 后续用 SELECT 获取
1672
1702
  updatedAt: r
1673
1703
  });
1674
- await e.query(d, g);
1675
- const S = l.map((b) => b.id), N = Ee(e, o, {
1704
+ await e.query(p, _);
1705
+ const S = l.map((b) => b.id), $ = Ee(e, o, {
1676
1706
  where: { combinator: "and", rules: [{ field: "id", operator: "in", value: S }] }
1677
- }), $ = await e.query(N.sql, N.params);
1678
- for (const b of $.rows) {
1707
+ }), A = await e.query($.sql, $.params);
1708
+ for (const b of A.rows) {
1679
1709
  const E = Z(o, b), m = E.id;
1680
1710
  if (u.hasEntityRef(m)) {
1681
- const _ = u.getEntityRef(m);
1682
- u.updateEntity(_, E);
1683
- const R = K(_);
1711
+ const g = u.getEntityRef(m);
1712
+ u.updateEntity(g, E);
1713
+ const R = J(g);
1684
1714
  R.local = !0, R.modified = !1;
1685
1715
  }
1686
1716
  }
@@ -1694,7 +1724,7 @@ const la = async (e, t) => {
1694
1724
  }
1695
1725
  for (const o of a) {
1696
1726
  n.add(o);
1697
- const c = K(o);
1727
+ const c = J(o);
1698
1728
  c.origin = structuredClone({ ...o }), c.modified = !1, c.removed = !0, c.local = !1;
1699
1729
  }
1700
1730
  }
@@ -1707,13 +1737,20 @@ const la = async (e, t) => {
1707
1737
  let u = "";
1708
1738
  u += `"${c.columnName}"`;
1709
1739
  const l = Dt(c);
1710
- if (c.primary ? c.type === A.integer ? u += " serial PRIMARY KEY" : u += ` ${l} PRIMARY KEY` : u += ` ${l}`, Reflect.get(c, "default") !== void 0) {
1711
- let p = c.default;
1712
- It(c.default) && (p = c.default()), Hn(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)}'`;
1740
+ if (c.primary ? c.type === N.integer ? u += " serial PRIMARY KEY" : u += ` ${l} PRIMARY KEY` : u += ` ${l}`, Reflect.get(c, "default") !== void 0) {
1741
+ let d = c.default;
1742
+ It(c.default) && (d = c.default()), Hn(d) ? ["CURRENT_TIMESTAMP", "now()"].includes(d) ? u += " DEFAULT now()" : u += ` DEFAULT '${d}'` : d instanceof Date ? u += ` DEFAULT '${d.toISOString()}'` : typeof d == "boolean" || typeof d == "number" ? u += ` DEFAULT ${String(d)}` : u += ` DEFAULT '${String(d)}'`;
1743
+ }
1744
+ if (c.nullable || (u += " NOT NULL"), c.unique && s.push(
1745
+ `CREATE UNIQUE INDEX "${Ct(t, c)}" on ${n} ("${c.columnName}" ${Xn(c)});`
1746
+ ), c.type === N.enum) {
1747
+ const d = c;
1748
+ if (d.enum && d.enum.length > 0) {
1749
+ const f = d.enum.map((p) => `'${String(p).replace(/'/g, "''")}'`).join(", ");
1750
+ a.push(`CHECK ("${c.columnName}" IN (${f}))`);
1751
+ }
1713
1752
  }
1714
- c.nullable || (u += " NOT NULL"), c.unique && s.push(
1715
- `CREATE UNIQUE INDEX "${Lt(t, c)}" on ${n} ("${c.columnName}" ${Jn(c)});`
1716
- ), i.push(u);
1753
+ i.push(u);
1717
1754
  });
1718
1755
  const o = [...i, ...a];
1719
1756
  if (o.length)
@@ -1738,8 +1775,8 @@ CREATE ${o}INDEX "${a}" ON ${r}(${i});`;
1738
1775
  const r = P(t);
1739
1776
  return Array.from(t.relationMap.values()).forEach((s) => {
1740
1777
  switch (s.kind) {
1741
- case Q.ONE_TO_ONE:
1742
- case Q.MANY_TO_ONE:
1778
+ case F.ONE_TO_ONE:
1779
+ case F.MANY_TO_ONE:
1743
1780
  {
1744
1781
  const a = s.columnName;
1745
1782
  let i = "uuid";
@@ -1758,7 +1795,7 @@ CREATE ${o}INDEX "${a}" ON ${r}(${i});`;
1758
1795
  } catch {
1759
1796
  }
1760
1797
  if (n += `
1761
- ALTER TABLE ${r} ADD COLUMN "${a}" ${i}`, s.nullable || (n += " NOT NULL"), s.kind === Q.MANY_TO_ONE && Reflect.get(s, "default") !== void 0) {
1798
+ ALTER TABLE ${r} ADD COLUMN "${a}" ${i}`, s.nullable || (n += " NOT NULL"), s.kind === F.MANY_TO_ONE && Reflect.get(s, "default") !== void 0) {
1762
1799
  const c = s;
1763
1800
  let u = c.default;
1764
1801
  It(c.default) && (u = c.default()), n += ` DEFAULT '${u}'`;
@@ -1774,15 +1811,15 @@ ALTER TABLE ${r} ADD COLUMN "${a}" ${i}`, s.nullable || (n += " NOT NULL"), s.ki
1774
1811
  s.mappedNamespace || t.namespace
1775
1812
  ), l = `${r}_${a}_fk`.replace(/"/g, "");
1776
1813
  n += `
1777
- ALTER TABLE ${r} ADD CONSTRAINT "${l}" FOREIGN KEY ("${a}") REFERENCES ${u}(id)`, s.onDelete ? n += ` ON DELETE ${s.onDelete}` : s.kind === Q.MANY_TO_ONE && (s.nullable ? n += " ON DELETE SET NULL" : n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
1814
+ ALTER TABLE ${r} ADD CONSTRAINT "${l}" FOREIGN KEY ("${a}") REFERENCES ${u}(id)`, s.onDelete ? n += ` ON DELETE ${s.onDelete}` : s.kind === F.MANY_TO_ONE && (s.nullable ? n += " ON DELETE SET NULL" : n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
1778
1815
  }
1779
- (s.unique || s.kind === Q.ONE_TO_ONE) && (n += `
1780
- CREATE UNIQUE INDEX "${Lt(t, s)}" ON ${r}("${a}");`);
1816
+ (s.unique || s.kind === F.ONE_TO_ONE) && (n += `
1817
+ CREATE UNIQUE INDEX "${Ct(t, s)}" ON ${r}("${a}");`);
1781
1818
  }
1782
1819
  break;
1783
1820
  }
1784
1821
  }), n;
1785
- }, Mn = (e, t) => {
1822
+ }, qn = (e, t) => {
1786
1823
  let n = "";
1787
1824
  return n += ua(e, t), n += fa(e, t), n += ha(e, t), n;
1788
1825
  };
@@ -1862,7 +1899,7 @@ function pa(e = ["RxDBChange", "RxDBBranch", "RxDBMigration"]) {
1862
1899
 
1863
1900
  `);
1864
1901
  }
1865
- function Ae(e, t = {}) {
1902
+ function $e(e, t = {}) {
1866
1903
  const n = P(e), r = D(ie), s = P(r), {
1867
1904
  propertyMap: a,
1868
1905
  name: i,
@@ -1870,13 +1907,13 @@ function Ae(e, t = {}) {
1870
1907
  foreignKeyNames: c,
1871
1908
  foreignKeyColumnNames: u,
1872
1909
  namespace: l
1873
- } = e, { branchId: p, transactionId: f } = t, d = `"${o}_change_trigger"`, g = [];
1910
+ } = e, { branchId: d, transactionId: f } = t, p = `"${o}_change_trigger"`, _ = [];
1874
1911
  for (const [y, T] of a)
1875
- y !== "id" && g.push({ jsName: y, dbColumn: T.columnName });
1912
+ y !== "id" && _.push({ jsName: y, dbColumn: T.columnName });
1876
1913
  const S = u || c;
1877
1914
  for (let y = 0; y < c.length; y++)
1878
- c[y] !== "id" && g.push({ jsName: c[y], dbColumn: S[y] });
1879
- const N = 'type, namespace, entity, "branchId", "transactionId", "entityId", "inversePatch", patch', $ = f ? `'${f}'` : "NULL", b = p || "main", E = `"${l}"."${o}_change_trigger_fn"`, m = `'${l}','${i}','${b}',${$}`, _ = `
1915
+ c[y] !== "id" && _.push({ jsName: c[y], dbColumn: S[y] });
1916
+ const $ = 'type, namespace, entity, "branchId", "transactionId", "entityId", "inversePatch", patch', A = f ? `'${f}'` : "NULL", b = d || "main", E = `"${l}"."${o}_change_trigger_fn"`, m = `'${l}','${i}','${b}',${A}`, g = `
1880
1917
  -- 创建或替换触发器函数
1881
1918
  CREATE OR REPLACE FUNCTION ${E}()
1882
1919
  RETURNS TRIGGER AS $$
@@ -1886,29 +1923,29 @@ DECLARE
1886
1923
  BEGIN
1887
1924
  -- INSERT 操作
1888
1925
  IF (TG_OP = 'INSERT') THEN
1889
- INSERT INTO ${s} (${N})
1926
+ INSERT INTO ${s} (${$})
1890
1927
  VALUES (
1891
1928
  'INSERT',
1892
1929
  ${m},
1893
1930
  NEW.id,
1894
1931
  NULL,
1895
- jsonb_build_object(${g.map((y) => `'${y.jsName}', NEW."${y.dbColumn}"`).join(", ")})
1932
+ jsonb_build_object(${_.map((y) => `'${y.jsName}', NEW."${y.dbColumn}"`).join(", ")})
1896
1933
  );
1897
1934
  RETURN NEW;
1898
1935
 
1899
1936
  -- UPDATE 操作
1900
1937
  ELSIF (TG_OP = 'UPDATE') THEN
1901
1938
  -- 只在字段真正变更时记录
1902
- IF (${g.map((y) => `OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}"`).join(" OR ")}) THEN
1939
+ IF (${_.map((y) => `OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}"`).join(" OR ")}) THEN
1903
1940
  -- 构建变更前的值 (inversePatch - 只包含变更的字段)
1904
- old_values := jsonb_build_object(${g.map((y) => `'${y.jsName}', CASE WHEN OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}" THEN to_jsonb(OLD."${y.dbColumn}") ELSE NULL END`).join(", ")});
1941
+ old_values := jsonb_build_object(${_.map((y) => `'${y.jsName}', CASE WHEN OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}" THEN to_jsonb(OLD."${y.dbColumn}") ELSE NULL END`).join(", ")});
1905
1942
  old_values := jsonb_strip_nulls(old_values);
1906
1943
 
1907
1944
  -- 构建变更后的值 (patch - 只包含变更的字段)
1908
- new_values := jsonb_build_object(${g.map((y) => `'${y.jsName}', CASE WHEN OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}" THEN to_jsonb(NEW."${y.dbColumn}") ELSE NULL END`).join(", ")});
1945
+ new_values := jsonb_build_object(${_.map((y) => `'${y.jsName}', CASE WHEN OLD."${y.dbColumn}" IS DISTINCT FROM NEW."${y.dbColumn}" THEN to_jsonb(NEW."${y.dbColumn}") ELSE NULL END`).join(", ")});
1909
1946
  new_values := jsonb_strip_nulls(new_values);
1910
1947
 
1911
- INSERT INTO ${s} (${N})
1948
+ INSERT INTO ${s} (${$})
1912
1949
  VALUES (
1913
1950
  'UPDATE',
1914
1951
  ${m},
@@ -1921,12 +1958,12 @@ BEGIN
1921
1958
 
1922
1959
  -- DELETE 操作
1923
1960
  ELSIF (TG_OP = 'DELETE') THEN
1924
- INSERT INTO ${s} (${N})
1961
+ INSERT INTO ${s} (${$})
1925
1962
  VALUES (
1926
1963
  'DELETE',
1927
1964
  ${m},
1928
1965
  OLD.id,
1929
- jsonb_build_object(${g.map((y) => `'${y.jsName}', OLD."${y.dbColumn}"`).join(", ")}),
1966
+ jsonb_build_object(${_.map((y) => `'${y.jsName}', OLD."${y.dbColumn}"`).join(", ")}),
1930
1967
  NULL
1931
1968
  );
1932
1969
  RETURN OLD;
@@ -1936,13 +1973,13 @@ BEGIN
1936
1973
  END;
1937
1974
  $$ LANGUAGE plpgsql;`, R = `
1938
1975
  -- 删除已存在的触发器
1939
- DROP TRIGGER IF EXISTS ${d} ON ${n}`, I = `
1976
+ DROP TRIGGER IF EXISTS ${p} ON ${n}`, I = `
1940
1977
  -- 创建触发器 (监听 INSERT, UPDATE, DELETE)
1941
- CREATE TRIGGER ${d}
1978
+ CREATE TRIGGER ${p}
1942
1979
  AFTER INSERT OR UPDATE OR DELETE ON ${n}
1943
1980
  FOR EACH ROW
1944
1981
  EXECUTE FUNCTION ${E}()`;
1945
- return [_, R, I].join(`
1982
+ return [g, R, I].join(`
1946
1983
  ---STATEMENT_SEPARATOR---
1947
1984
  `);
1948
1985
  }
@@ -2011,15 +2048,15 @@ const He = (e, t, n, r = !1) => {
2011
2048
  const c = Z(s, o), u = c.id;
2012
2049
  let l;
2013
2050
  if (i.hasEntityRef(t, u)) {
2014
- if (l = i.getEntityRef(t, u), s.computedPropertyMap.forEach((d, g) => {
2015
- g in c && (l[g] = c[g]);
2051
+ if (l = i.getEntityRef(t, u), s.computedPropertyMap.forEach((p, _) => {
2052
+ _ in c && (l[_] = c[_]);
2016
2053
  }), r) {
2017
- const d = K(l);
2018
- d.origin = { ...c }, Object.assign(l, c), d.local = !0, d.modified = !1;
2054
+ const p = J(l);
2055
+ p.origin = { ...c }, Object.assign(l, c), p.local = !0, p.modified = !1;
2019
2056
  }
2020
2057
  } else
2021
2058
  l = i.createEntityRef(t, c);
2022
- const f = K(l);
2059
+ const f = J(l);
2023
2060
  f.local = !0, f.modified = !1, a.push(l);
2024
2061
  }
2025
2062
  return a;
@@ -2027,101 +2064,101 @@ const He = (e, t, n, r = !1) => {
2027
2064
  for (const r of n) {
2028
2065
  const s = e.rxdb.entityManager.getEntityRef(t, r);
2029
2066
  if (s) {
2030
- const a = K(s);
2067
+ const a = J(s);
2031
2068
  a.local = !1, a.removed = !0, a.modified = !1;
2032
2069
  }
2033
2070
  }
2034
2071
  }, jn = (e, t) => {
2035
2072
  const { deletes: n, inserts: r, updates: s } = t, a = { deletes: [], inserts: [], updates: [] }, i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
2036
- for (const [f, d] of n.entries()) {
2037
- const [g, S, N] = $e(f), $ = `${g}:${S}`, b = i.get($);
2038
- b ? b.add(N) : i.set($, /* @__PURE__ */ new Set([N]));
2039
- let E = o.get($);
2040
- E || (E = /* @__PURE__ */ new Map(), o.set($, E)), E.set(N, {
2041
- patch: d.patch,
2042
- inversePatch: d.inversePatch
2073
+ for (const [f, p] of n.entries()) {
2074
+ const [_, S, $] = Ae(f), A = `${_}:${S}`, b = i.get(A);
2075
+ b ? b.add($) : i.set(A, /* @__PURE__ */ new Set([$]));
2076
+ let E = o.get(A);
2077
+ E || (E = /* @__PURE__ */ new Map(), o.set(A, E)), E.set($, {
2078
+ patch: p.patch,
2079
+ inversePatch: p.inversePatch
2043
2080
  });
2044
2081
  }
2045
- for (const [f, d] of i) {
2046
- const [g, S] = f.split(":"), N = e.rxdb.schemaManager.getEntityMetadata(S, g), $ = P(N), b = N.propertyMap.get("id").type === "integer", E = Array.from(d), m = b ? `DELETE FROM ${$} WHERE id = ANY($1::integer[]);` : `DELETE FROM ${$} WHERE id = ANY($1);`;
2082
+ for (const [f, p] of i) {
2083
+ const [_, S] = f.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(S, _), A = P($), b = $.propertyMap.get("id").type === "integer", E = Array.from(p), m = b ? `DELETE FROM ${A} WHERE id = ANY($1::integer[]);` : `DELETE FROM ${A} WHERE id = ANY($1);`;
2047
2084
  a.deletes.push({
2048
- metadata: N,
2049
- ids: d,
2085
+ metadata: $,
2086
+ ids: p,
2050
2087
  sql: m,
2051
2088
  params: [E],
2052
2089
  changes: o.get(f)
2053
2090
  });
2054
2091
  }
2055
2092
  const c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
2056
- for (const [f, d] of r.entries()) {
2057
- const [g, S, N] = $e(f), $ = `${g}:${S}`, b = c.get($), E = { ...d.patch, id: N };
2058
- b ? b.push(E) : c.set($, [E]);
2059
- let m = u.get($);
2060
- m || (m = /* @__PURE__ */ new Map(), u.set($, m)), m.set(N, {
2061
- patch: d.patch,
2062
- inversePatch: d.inversePatch
2093
+ for (const [f, p] of r.entries()) {
2094
+ const [_, S, $] = Ae(f), A = `${_}:${S}`, b = c.get(A), E = { ...p.patch, id: $ };
2095
+ b ? b.push(E) : c.set(A, [E]);
2096
+ let m = u.get(A);
2097
+ m || (m = /* @__PURE__ */ new Map(), u.set(A, m)), m.set($, {
2098
+ patch: p.patch,
2099
+ inversePatch: p.inversePatch
2063
2100
  });
2064
2101
  }
2065
- for (const [f, d] of c) {
2066
- const [g, S] = f.split(":"), N = e.rxdb.schemaManager.getEntityMetadata(S, g), $ = [];
2067
- d.forEach((E) => {
2068
- for (const [I, y] of N.propertyMap)
2102
+ for (const [f, p] of c) {
2103
+ const [_, S] = f.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(S, _), A = [];
2104
+ p.forEach((E) => {
2105
+ for (const [I, y] of $.propertyMap)
2069
2106
  E[I] === void 0 && y.default !== void 0 && (typeof y.default == "function" ? E[I] = y.default() : E[I] = y.default);
2070
- const { sql: m, params: _ } = In(N, E, { returning: !1 }), R = m.replace(";", _a(N));
2071
- $.push(nt(R, _));
2107
+ const { sql: m, params: g } = In($, E, { returning: !1 }), R = m.replace(";", ga($));
2108
+ A.push(nt(R, g));
2072
2109
  });
2073
- const b = $.join("---STATEMENT_SEPARATOR---");
2110
+ const b = A.join("---STATEMENT_SEPARATOR---");
2074
2111
  a.inserts.push({
2075
- metadata: N,
2076
- ids: new Set(d.filter((E) => E != null).map((E) => E.id)),
2112
+ metadata: $,
2113
+ ids: new Set(p.filter((E) => E != null).map((E) => E.id)),
2077
2114
  sql: b,
2078
2115
  params: [],
2079
2116
  // 已经内联到 SQL 中
2080
2117
  changes: u.get(f)
2081
2118
  });
2082
2119
  }
2083
- const l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
2084
- for (const [f, d] of s.entries()) {
2085
- const [g, S, N] = $e(f), $ = `${g}:${S}`, b = l.get($), E = { ...d.patch, id: N };
2086
- b ? b.push(E) : l.set($, [E]);
2087
- let m = p.get($);
2088
- m || (m = /* @__PURE__ */ new Map(), p.set($, m));
2089
- const _ = e.rxdb.schemaManager.getEntityMetadata(S, g), R = d.patch ? { ...d.patch } : null, I = d.inversePatch ? { ...d.inversePatch } : null;
2090
- _ && (R && Object.keys(R).forEach((y) => {
2091
- const T = _.propertyMap.get(y);
2092
- T && (R[y] = Ce(R[y], T));
2120
+ const l = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
2121
+ for (const [f, p] of s.entries()) {
2122
+ const [_, S, $] = Ae(f), A = `${_}:${S}`, b = l.get(A), E = { ...p.patch, id: $ };
2123
+ b ? b.push(E) : l.set(A, [E]);
2124
+ let m = d.get(A);
2125
+ m || (m = /* @__PURE__ */ new Map(), d.set(A, m));
2126
+ const g = e.rxdb.schemaManager.getEntityMetadata(S, _), R = p.patch ? { ...p.patch } : null, I = p.inversePatch ? { ...p.inversePatch } : null;
2127
+ g && (R && Object.keys(R).forEach((y) => {
2128
+ const T = g.propertyMap.get(y);
2129
+ T && (R[y] = Le(R[y], T));
2093
2130
  }), I && Object.keys(I).forEach((y) => {
2094
- const T = _.propertyMap.get(y);
2095
- T && (I[y] = Ce(I[y], T));
2096
- })), m.set(N, {
2131
+ const T = g.propertyMap.get(y);
2132
+ T && (I[y] = Le(I[y], T));
2133
+ })), m.set($, {
2097
2134
  patch: R,
2098
2135
  inversePatch: I
2099
2136
  });
2100
2137
  }
2101
- for (const [f, d] of l) {
2102
- const [g, S] = f.split(":"), N = e.rxdb.schemaManager.getEntityMetadata(S, g), $ = [];
2103
- d.forEach((E) => {
2138
+ for (const [f, p] of l) {
2139
+ const [_, S] = f.split(":"), $ = e.rxdb.schemaManager.getEntityMetadata(S, _), A = [];
2140
+ p.forEach((E) => {
2104
2141
  let m;
2105
- N.propertyMap.has("updatedAt") && (m = E.updatedAt);
2106
- const { id: _, ...R } = E, { sql: I, params: y } = ze(N, { id: _ }, R, {
2142
+ $.propertyMap.has("updatedAt") && (m = E.updatedAt);
2143
+ const { id: g, ...R } = E, { sql: I, params: y } = ze($, { id: g }, R, {
2107
2144
  updatedAt: m,
2108
2145
  returning: !1
2109
2146
  });
2110
- $.push(nt(I, y));
2147
+ A.push(nt(I, y));
2111
2148
  });
2112
- const b = $.join("---STATEMENT_SEPARATOR---");
2149
+ const b = A.join("---STATEMENT_SEPARATOR---");
2113
2150
  a.updates.push({
2114
- metadata: N,
2115
- ids: new Set(d.filter((E) => E != null).map((E) => E.id)),
2151
+ metadata: $,
2152
+ ids: new Set(p.filter((E) => E != null).map((E) => E.id)),
2116
2153
  sql: b,
2117
2154
  params: [],
2118
2155
  // 已经内联到 SQL 中
2119
- changes: p.get(f)
2156
+ changes: d.get(f)
2120
2157
  });
2121
2158
  }
2122
2159
  return a;
2123
- }, _a = (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(", ")};`;
2124
- function ga(e) {
2160
+ }, 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(", ")};`;
2161
+ function _a(e) {
2125
2162
  return {
2126
2163
  rows: e.rows,
2127
2164
  rowsAffected: e.affectedRows ?? e.rows.length,
@@ -2134,7 +2171,7 @@ const xn = (e, t) => {
2134
2171
  const c = D(o);
2135
2172
  if (c.log !== !1)
2136
2173
  try {
2137
- const u = Ae(c, {
2174
+ const u = $e(c, {
2138
2175
  branchId: t
2139
2176
  });
2140
2177
  u.trim() && n.push(u);
@@ -2165,9 +2202,9 @@ const xn = (e, t) => {
2165
2202
  await e.transaction(async () => {
2166
2203
  const u = Un(e);
2167
2204
  if (u) {
2168
- const l = u.split("---STATEMENT_SEPARATOR---").filter((p) => p.trim());
2169
- for (const p of l)
2170
- await e.query(p.trim());
2205
+ const l = u.split("---STATEMENT_SEPARATOR---").filter((d) => d.trim());
2206
+ for (const d of l)
2207
+ await e.query(d.trim());
2171
2208
  }
2172
2209
  if (s) {
2173
2210
  if (s.deletes.length)
@@ -2189,23 +2226,23 @@ const xn = (e, t) => {
2189
2226
  }
2190
2227
  const c = (u, l) => {
2191
2228
  if (l.length === 0) return;
2192
- const p = l.map((f) => {
2193
- const d = { ...f };
2229
+ const d = l.map((f) => {
2230
+ const p = { ...f };
2194
2231
  return {
2195
2232
  namespace: u.namespace,
2196
2233
  entity: u.name,
2197
2234
  type: "UPDATE",
2198
2235
  id: f.id,
2199
- patch: d,
2200
- inversePatch: d,
2236
+ patch: p,
2237
+ inversePatch: p,
2201
2238
  recordAt: f.createdAt
2202
2239
  };
2203
2240
  });
2204
- e.rxdb.dispatchEvent(new me(p));
2241
+ e.rxdb.dispatchEvent(new me(d));
2205
2242
  };
2206
2243
  if (a) {
2207
- const u = ga(a), l = He(e, ne, u, !0), p = D(ne);
2208
- c(p, l);
2244
+ const u = _a(a), l = He(e, ne, u, !0), d = D(ne);
2245
+ c(d, l);
2209
2246
  }
2210
2247
  s && Bn(e, s);
2211
2248
  } catch (i) {
@@ -2304,12 +2341,12 @@ function St(e, t, n) {
2304
2341
  return e.rxdb.config.entities.forEach((s) => {
2305
2342
  const a = D(s);
2306
2343
  if (a.log !== !1) {
2307
- const o = Ae(a, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((c) => c.trim()).filter((c) => c.length > 0);
2344
+ const o = $e(a, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((c) => c.trim()).filter((c) => c.length > 0);
2308
2345
  r.push(...o);
2309
2346
  }
2310
2347
  }), r;
2311
2348
  }
2312
- class La extends kn {
2349
+ class Ca extends kn {
2313
2350
  /**
2314
2351
  * 构造函数
2315
2352
  *
@@ -2320,7 +2357,7 @@ class La extends kn {
2320
2357
  super(t), this.options = n;
2321
2358
  }
2322
2359
  /** 销毁信号主题,用于清理资源 */
2323
- #e = new Qn();
2360
+ #e = new Jn();
2324
2361
  /** 仓库实例缓存,避免重复创建 */
2325
2362
  #s = /* @__PURE__ */ new Map();
2326
2363
  /** PGlite 客户端缓存 */
@@ -2334,7 +2371,7 @@ class La extends kn {
2334
2371
  /** 当前活跃的事务对象 */
2335
2372
  #a;
2336
2373
  /** 适配器名称 */
2337
- name = Xn;
2374
+ name = Qn;
2338
2375
  /**
2339
2376
  * 批量获取实体元数据(QueryCache 专用)
2340
2377
  *
@@ -2373,8 +2410,8 @@ class La extends kn {
2373
2410
  (async () => {
2374
2411
  const s = this.rxdb.schemaManager.getEntityMetadata(t, "public")?.tableName ?? t, a = Object.keys(n[0]), i = a.map((o) => `"${o}"`).join(", ");
2375
2412
  for (const o of n) {
2376
- const c = a.map((f) => o[f]), u = a.map((f, d) => `$${d + 1}`).join(", "), l = a.filter((f) => f !== "id").map((f) => `"${f}" = EXCLUDED."${f}"`).join(", "), p = `INSERT INTO "public"."${s}" (${i}) VALUES (${u}) ON CONFLICT (id) DO UPDATE SET ${l}`;
2377
- await this.internalQuery(p, c);
2413
+ const c = a.map((f) => o[f]), u = a.map((f, p) => `$${p + 1}`).join(", "), l = a.filter((f) => f !== "id").map((f) => `"${f}" = EXCLUDED."${f}"`).join(", "), d = `INSERT INTO "public"."${s}" (${i}) VALUES (${u}) ON CONFLICT (id) DO UPDATE SET ${l}`;
2414
+ await this.internalQuery(d, c);
2378
2415
  }
2379
2416
  })()
2380
2417
  ));
@@ -2472,7 +2509,7 @@ class La extends kn {
2472
2509
  const i = D(s), o = ue(i, a, this.rxdb.context);
2473
2510
  await this.query(o);
2474
2511
  for (const c of a) {
2475
- const u = K(c);
2512
+ const u = J(c);
2476
2513
  u.local = !0, u.modified = !1;
2477
2514
  }
2478
2515
  }
@@ -2486,7 +2523,7 @@ class La extends kn {
2486
2523
  */
2487
2524
  async connect() {
2488
2525
  const t = await this.#n(), n = pa();
2489
- return await t.exec(n), t instanceof Rt && (t.addEventListener(V.INSERT, (r) => Le(this, r)), t.addEventListener(V.UPDATE, (r) => Le(this, r)), t.addEventListener(V.DELETE, (r) => Le(this, r))), this;
2526
+ 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;
2490
2527
  }
2491
2528
  /**
2492
2529
  * 断开数据库连接
@@ -2562,7 +2599,7 @@ class La extends kn {
2562
2599
  let r;
2563
2600
  switch (n.repository) {
2564
2601
  case "Repository":
2565
- r = new qn(this, t);
2602
+ r = new Mn(this, t);
2566
2603
  break;
2567
2604
  case "TreeRepository":
2568
2605
  r = new ca(this, t);
@@ -2591,7 +2628,7 @@ class La extends kn {
2591
2628
  async createTables(t, n) {
2592
2629
  const r = [], s = [];
2593
2630
  for (const i of t) {
2594
- const o = D(i), u = Mn(this, o).split(/;\s*\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("--"));
2631
+ const o = D(i), u = qn(this, o).split(/;\s*\n/).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("--"));
2595
2632
  for (const l of u)
2596
2633
  l && (l.includes("ADD CONSTRAINT") && l.includes("FOREIGN KEY") ? r.push(l) : s.push(l));
2597
2634
  }
@@ -2612,7 +2649,7 @@ class La extends kn {
2612
2649
  for (const i of t) {
2613
2650
  const o = D(i);
2614
2651
  if (o.log !== !1) {
2615
- const c = Ae(o);
2652
+ const c = $e(o);
2616
2653
  await this.#c(c.replace(/---STATEMENT_SEPARATOR---/g, ";"));
2617
2654
  }
2618
2655
  }
@@ -2822,14 +2859,14 @@ class Na {
2822
2859
  return `UPDATE ${s} SET ${i} FROM (VALUES ($1)) AS temp(${a}, ${r.join(", ")}) WHERE ${s}.${a} = temp.${a} ${this.getReturningClause()}`;
2823
2860
  }
2824
2861
  }
2825
- const Ca = new Na();
2826
- function qa(e, t, n) {
2862
+ const La = new Na();
2863
+ function Ma(e, t, n) {
2827
2864
  let r = "";
2828
2865
  for (let s = 0; s < t.length; s++) {
2829
- const a = t[s], i = D(a), o = Mn(e, i);
2866
+ const a = t[s], i = D(a), o = qn(e, i);
2830
2867
  if (r += `
2831
2868
  ` + o, i.log !== !1) {
2832
- const c = Ae(i);
2869
+ const c = $e(i);
2833
2870
  r += `
2834
2871
  ` + c;
2835
2872
  }
@@ -2849,33 +2886,33 @@ function qa(e, t, n) {
2849
2886
  return r;
2850
2887
  }
2851
2888
  export {
2852
- Xn as ADAPTER_NAME,
2853
- V as PGliteChangeType,
2889
+ Qn as ADAPTER_NAME,
2890
+ K as PGliteChangeType,
2854
2891
  Rt as PGliteClient,
2855
2892
  Na as PostgreSQLDialect,
2856
- La as RxDBAdapterPGlite,
2893
+ Ca as RxDBAdapterPGlite,
2857
2894
  x as RxdbAdapterPGliteError,
2858
- qa as create_tables_sql,
2895
+ Ma as create_tables_sql,
2859
2896
  da as generateNotifyFunctionSQL,
2860
2897
  pa as generateNotifyInfrastructureSQL,
2861
2898
  Pn as generateNotifyTriggerSQL,
2862
- Ae as generate_trigger_sql,
2899
+ $e as generate_trigger_sql,
2863
2900
  Z as getEntityObjectFromResult,
2864
- Qe as getSqlValue,
2901
+ Je as getSqlValue,
2865
2902
  nt as getSqlWithParams,
2866
- Lt as getTableColumnIndexName,
2903
+ Ct as getTableColumnIndexName,
2867
2904
  vt as getTableName,
2868
2905
  P as getTableNameByMetadata,
2869
- Ct as normalizeCreateEntity,
2906
+ Lt as normalizeCreateEntity,
2870
2907
  zn as normalizeEntity,
2871
- Ca as pgDialect,
2908
+ La as pgDialect,
2872
2909
  Da as removeNotifyTriggerSQL,
2873
2910
  Un as remove_all_triggers_sql,
2874
2911
  ma as remove_trigger_sql,
2875
2912
  Dt as rxDBColumnTypeToPGliteType,
2876
- Jn as rxDBColumnTypeToPGliteTypeIndexName,
2913
+ Xn as rxDBColumnTypeToPGliteTypeIndexName,
2877
2914
  st as transformEntityValuePGliteToJs,
2878
2915
  Ke as transformEntityValueToSql,
2879
2916
  tt as transformValueJsToPGlite,
2880
- Ce as transformValuePGliteToJs
2917
+ Le as transformValuePGliteToJs
2881
2918
  };