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