@aiao/rxdb-adapter-pglite 0.0.5 → 0.0.7

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.
Files changed (62) hide show
  1. package/dist/PGliteClient.d.ts +10 -4
  2. package/dist/PGliteClient.d.ts.map +1 -1
  3. package/dist/RxDBAdapterPGlite.d.ts +174 -19
  4. package/dist/RxDBAdapterPGlite.d.ts.map +1 -1
  5. package/dist/entity/delete_sql.d.ts +13 -0
  6. package/dist/entity/delete_sql.d.ts.map +1 -0
  7. package/dist/entity/deletes_sql.d.ts +11 -0
  8. package/dist/entity/deletes_sql.d.ts.map +1 -0
  9. package/dist/entity/insert_sql.d.ts +14 -0
  10. package/dist/entity/insert_sql.d.ts.map +1 -0
  11. package/dist/entity/inserts_sql.d.ts +12 -0
  12. package/dist/entity/inserts_sql.d.ts.map +1 -0
  13. package/dist/entity/update_sql.d.ts +15 -0
  14. package/dist/entity/update_sql.d.ts.map +1 -0
  15. package/dist/execute_helper.d.ts +70 -0
  16. package/dist/execute_helper.d.ts.map +1 -0
  17. package/dist/handle_rxdb_change.d.ts +26 -0
  18. package/dist/handle_rxdb_change.d.ts.map +1 -0
  19. package/dist/index.d.ts +8 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3116 -128
  22. package/dist/pglite.interface.d.ts +171 -2
  23. package/dist/pglite.interface.d.ts.map +1 -1
  24. package/dist/pglite.utils.d.ts +67 -5
  25. package/dist/pglite.utils.d.ts.map +1 -1
  26. package/dist/query/find_by_row_ids_sql.d.ts +15 -0
  27. package/dist/query/find_by_row_ids_sql.d.ts.map +1 -0
  28. package/dist/query/join_sql.d.ts +51 -0
  29. package/dist/query/join_sql.d.ts.map +1 -0
  30. package/dist/query/query_sql.d.ts +19 -0
  31. package/dist/query/query_sql.d.ts.map +1 -0
  32. package/dist/query/query_tree_sql.d.ts +36 -0
  33. package/dist/query/query_tree_sql.d.ts.map +1 -0
  34. package/dist/repository/PGliteRepository.d.ts +13 -0
  35. package/dist/repository/PGliteRepository.d.ts.map +1 -0
  36. package/dist/repository/PGliteRepositoryBase.d.ts +18 -0
  37. package/dist/repository/PGliteRepositoryBase.d.ts.map +1 -0
  38. package/dist/repository/PGliteTreeRepository.d.ts +13 -0
  39. package/dist/repository/PGliteTreeRepository.d.ts.map +1 -0
  40. package/dist/rxdb_adapter_mutations.d.ts +72 -0
  41. package/dist/rxdb_adapter_mutations.d.ts.map +1 -0
  42. package/dist/sql_dialect.d.ts +77 -0
  43. package/dist/sql_dialect.d.ts.map +1 -0
  44. package/dist/table/create_table_sql.d.ts +5 -0
  45. package/dist/table/create_table_sql.d.ts.map +1 -0
  46. package/dist/table/create_tables_sql.d.ts +31 -0
  47. package/dist/table/create_tables_sql.d.ts.map +1 -0
  48. package/dist/table/notify_function_sql.d.ts +46 -0
  49. package/dist/table/notify_function_sql.d.ts.map +1 -0
  50. package/dist/table/remove_trigger_sql.d.ts +41 -0
  51. package/dist/table/remove_trigger_sql.d.ts.map +1 -0
  52. package/dist/table/trigger_sql.d.ts +37 -0
  53. package/dist/table/trigger_sql.d.ts.map +1 -0
  54. package/dist/transaction_pglite_result.d.ts +102 -0
  55. package/dist/transaction_pglite_result.d.ts.map +1 -0
  56. package/dist/version/create_branch.d.ts +24 -0
  57. package/dist/version/create_branch.d.ts.map +1 -0
  58. package/dist/version/switch_transaction_id.d.ts +18 -0
  59. package/dist/version/switch_transaction_id.d.ts.map +1 -0
  60. package/package.json +7 -5
  61. package/dist/generate_table_create_sql.d.ts +0 -5
  62. package/dist/generate_table_create_sql.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,188 +1,3176 @@
1
- import { PropertyType as i, RxDBAdapterLocalBase as _, getEntityMetadata as T } from "@aiao/rxdb";
2
- import { Observable as y, shareReplay as w, switchMap as m, from as f, map as h, firstValueFrom as p } from "rxjs";
3
- import { isFunction as b, isString as x } from "@aiao/utils";
4
- import { PGlite as $ } from "@electric-sql/pglite";
5
- class a extends Error {
6
- constructor(e) {
7
- super(e), this.name = "RxDBError", Object.setPrototypeOf(this, a.prototype);
1
+ import { PropertyType as k, RxDBChange as ht, EntityLocalCreatedEvent as et, EntityLocalRemovedEvent as Xt, EntityLocalUpdatedEvent as Kt, RelationKind as _e, getEntityMetadata as re, RepositoryBase as or, getEntityStatus as be, RxDBBranch as zt, RxDBAdapterLocalBase as cr } from "@aiao/rxdb";
2
+ import { pickBy as Zt, EventDispatcher as lr, traverseObjectKeys as ur, isFunction as en, isString as fr, AsyncQueueExecutor as hr } from "@aiao/utils";
3
+ import { PGlite as dr } from "@electric-sql/pglite";
4
+ import { ReplaySubject as pr } from "rxjs";
5
+ const yr = "pglite";
6
+ var Ee = /* @__PURE__ */ ((e) => (e.INSERT = "INSERT", e.UPDATE = "UPDATE", e.DELETE = "DELETE", e))(Ee || {});
7
+ class ce extends Error {
8
+ /**
9
+ * 错误代码(例如:DUPLICATE_ENTITY, INVALID_SQL)
10
+ */
11
+ code;
12
+ /**
13
+ * 原始错误对象(如果是从其他错误转换而来)
14
+ */
15
+ originalError;
16
+ constructor(t, n, s) {
17
+ super(t), this.name = "RxdbAdapterPGliteError", this.code = n, this.originalError = s, Object.setPrototypeOf(this, ce.prototype);
8
18
  }
9
19
  }
10
- const g = (s) => {
11
- switch (s.type) {
12
- case i.uuid:
20
+ const tn = (e, t = "public") => `"${t}"."${e}"`, oe = (e) => tn(e.name, e.namespace), nn = (e) => {
21
+ switch (e.type) {
22
+ case k.uuid:
13
23
  return "uuid";
14
- case i.string:
24
+ case k.string:
15
25
  return "varchar";
16
- case i.json:
26
+ case k.json:
17
27
  return "jsonb";
18
- case i.number:
28
+ case k.number:
19
29
  return "numeric";
20
- case i.integer:
30
+ case k.integer:
21
31
  return "integer";
22
- case i.boolean:
32
+ case k.boolean:
23
33
  return "boolean";
24
- case i.date:
34
+ case k.date:
25
35
  return "timestamptz";
26
36
  }
27
- throw new Error("rxDBColumnTypeToPGliteType: type '" + s.type + "' not support");
28
- }, R = (s) => {
29
- switch (s.type) {
30
- case i.uuid:
37
+ throw new ce("rxDBColumnTypeToPGliteType: type '" + e.type + "' not support");
38
+ }, gr = (e) => {
39
+ switch (e.type) {
40
+ case k.uuid:
31
41
  return "uuid_ops";
32
- case i.string:
42
+ case k.string:
33
43
  return "bpchar_ops";
34
- case i.json:
44
+ case k.json:
35
45
  return "jsonb_ops";
36
- case i.number:
46
+ case k.number:
37
47
  return "numeric_ops";
38
- case i.integer:
48
+ case k.integer:
39
49
  return "int4_ops";
40
50
  default:
41
- throw new a(`rxDBColumnTypeToPGliteTypeIndexName: type '${s.type}' not support`);
42
- }
43
- }, q = (s, e) => `idx_${s.namespace}_${s.name}_${e.name}`, M = (s, e) => {
44
- let t = `CREATE TABLE ${e.namespace}."${e.name}" (`;
45
- const n = [], c = [], l = [];
46
- e.propertyMap.forEach((r) => {
47
- let o = "";
48
- o += `"${r.name}"`;
49
- const E = g(r);
50
- if (r.primary ? r.type === i.integer ? o += " serial PRIMARY KEY" : o += ` ${E} PRIMARY KEY` : o += ` ${E}`, !r.nullable) o += " NOT NULL";
51
- else if (Reflect.get(r, "default") !== void 0) {
52
- let u = r.default;
53
- b(r.default) && (u = r.default()), x(u) ? ["CURRENT_TIMESTAMP", "now()"].includes(u) ? o += " DEFAULT now()" : o += ` DEFAULT '${u}'` : o += ` DEFAULT ${String(u)}`;
54
- }
55
- r.unique && n.push(
56
- `CREATE UNIQUE INDEX "${q(e, r)}" on ${e.namespace}."${e.name}" ("${r.name}" ${R(r)});`
57
- ), l.push(o);
58
- });
59
- const d = [...l, ...c];
60
- if (d.length)
61
- t += d.map((r) => `
62
- ${r}`).join(","), t += `
63
- );`;
64
- else
65
- throw new a("columns is empty!");
66
- return n.length && (t += `
67
- ` + n.join(`
68
- `)), t;
69
- }, v = (s, e) => "", A = (s, e) => {
70
- let t = "";
71
- return t += M(s, e), t += v(), t;
72
- }, C = "pglite";
73
- class D {
51
+ throw new ce(`rxDBColumnTypeToPGliteTypeIndexName: type '${e.type}' not support`);
52
+ }
53
+ }, rn = (e, t) => `idx_${e.namespace}_${e.name}_${t.name}`, Er = (e, t) => {
54
+ if (e == null)
55
+ return null;
56
+ switch (t.type) {
57
+ case k.json:
58
+ case k.keyValue:
59
+ case k.stringArray:
60
+ case k.numberArray:
61
+ return JSON.stringify(e);
62
+ case k.date:
63
+ return e instanceof Date ? e.toISOString() : e;
64
+ case k.boolean:
65
+ return !!e;
66
+ case k.number:
67
+ case k.integer:
68
+ return Number(e);
69
+ case k.string:
70
+ case k.uuid:
71
+ default:
72
+ return String(e);
73
+ }
74
+ }, dt = (e, t) => {
75
+ const n = {}, s = Object.keys(t);
76
+ for (let r = 0; r < s.length; r++) {
77
+ const a = s[r];
78
+ if (a.endsWith("Id")) {
79
+ n[a] = t[a];
80
+ continue;
81
+ }
82
+ const f = e.propertyMap.get(a);
83
+ f && (n[a] = Er(t[a], f));
84
+ }
85
+ return n;
86
+ }, sn = (e, t) => Zt(t, (n, s) => e.propertyMap.has(s) || e.foreignKeyNames.includes(s)), mr = (e, t) => Zt(t, (n, s) => e.propertyMap.get(s)?.readonly !== !0), _r = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, pt = (e) => {
87
+ if (typeof e == "string") {
88
+ const t = e.replaceAll("'", "''");
89
+ return _r.test(e) ? `'${t}'::uuid` : `'${t}'`;
90
+ }
91
+ return e == null ? "NULL" : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e instanceof Date ? `'${e.toISOString()}'` : Array.isArray(e) ? `ARRAY[${e.map((n) => pt(n)).join(", ")}]` : typeof e == "object" ? `'${JSON.stringify(e).replaceAll("'", "''")}'::jsonb` : String(e);
92
+ }, Ji = (e, t = []) => !t || t.length === 0 ? e : e.replace(/\$(\d+)/g, (n, s) => {
93
+ const r = parseInt(s, 10) - 1;
94
+ if (r < 0 || r >= t.length)
95
+ throw new ce(`Parameter index ${s} out of range (have ${t.length} params)`);
96
+ return pt(t[r]);
97
+ }), Ne = (e, t) => {
98
+ const n = {};
99
+ return Object.keys(t).forEach((s) => {
100
+ const r = t[s];
101
+ if (e.isForeignKey(s))
102
+ n[s] = r;
103
+ else {
104
+ const a = e.propertyMap.get(s);
105
+ a ? a.type === k.number && typeof r == "string" ? n[s] = parseFloat(r) : a.type === k.integer && typeof r == "string" ? n[s] = parseInt(r, 10) : n[s] = r : n[s] = r;
106
+ }
107
+ }), n;
108
+ }, wr = (e, t) => {
109
+ if (e == null) return e;
110
+ switch (t.type) {
111
+ case k.date:
112
+ return e instanceof Date ? e : new Date(e);
113
+ case k.json:
114
+ case k.keyValue:
115
+ case k.stringArray:
116
+ case k.numberArray:
117
+ return e;
118
+ case k.boolean:
119
+ return !!e;
120
+ default:
121
+ return e;
122
+ }
123
+ }, $t = (e, t) => (Object.keys(t).forEach((n) => {
124
+ const s = t[n], r = e.propertyMap.get(n);
125
+ r && (t[n] = wr(s, r));
126
+ }), t);
127
+ var br = Object.defineProperty, an = (e) => {
128
+ throw TypeError(e);
129
+ }, Tr = (e, t) => () => (e && (t = e(e = 0)), t), Fe = (e, t) => {
130
+ for (var n in t) br(e, n, { get: t[n], enumerable: !0 });
131
+ }, yt = (e, t, n) => t.has(e) || an("Cannot " + n), T = (e, t, n) => (yt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), ae = (e, t, n) => t.has(e) ? an("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), Y = (e, t, n, s) => (yt(e, t, "write to private field"), t.set(e, n), n), G = (e, t, n) => (yt(e, t, "access private method"), n), on = (e, t, n, s) => ({ set _(r) {
132
+ Y(e, t, r);
133
+ }, get _() {
134
+ return T(e, t, s);
135
+ } }), pe = Tr(() => {
136
+ }), Ar = {};
137
+ Fe(Ar, { ABSTIME: () => qr, ACLITEM: () => Yr, BIT: () => Qr, BOOL: () => tt, BPCHAR: () => dn, BYTEA: () => nt, CHAR: () => Sr, CID: () => Lr, CIDR: () => Br, CIRCLE: () => Pr, DATE: () => yn, FLOAT4: () => fn, FLOAT8: () => hn, GTSVECTOR: () => fs, INET: () => Gr, INT2: () => cn, INT4: () => ln, INT8: () => rt, INTERVAL: () => Hr, JSON: () => st, JSONB: () => En, MACADDR: () => Wr, MACADDR8: () => Fr, MONEY: () => kr, NUMERIC: () => Kr, OID: () => un, PATH: () => Mr, PG_DEPENDENCIES: () => cs, PG_LSN: () => as, PG_NDISTINCT: () => os, PG_NODE_TREE: () => Dr, POLYGON: () => Ur, REFCURSOR: () => zr, REGCLASS: () => ns, REGCONFIG: () => hs, REGDICTIONARY: () => ds, REGNAMESPACE: () => ps, REGOPER: () => es, REGOPERATOR: () => ts, REGPROC: () => Nr, REGPROCEDURE: () => Zr, REGROLE: () => ys, REGTYPE: () => rs, RELTIME: () => jr, SMGR: () => Cr, TEXT: () => Ce, TID: () => Rr, TIME: () => Vr, TIMESTAMP: () => gn, TIMESTAMPTZ: () => it, TIMETZ: () => Jr, TINTERVAL: () => xr, TSQUERY: () => us, TSVECTOR: () => ls, TXID_SNAPSHOT: () => is, UUID: () => ss, VARBIT: () => Xr, VARCHAR: () => pn, XID: () => vr, XML: () => Or, arrayParser: () => Ts, arraySerializer: () => _n, parseType: () => at, parsers: () => gs, serializers: () => Es, types: () => mn });
138
+ pe();
139
+ var Ir = globalThis.JSON.parse, $r = globalThis.JSON.stringify, tt = 16, nt = 17, Sr = 18, rt = 20, cn = 21, ln = 23, Nr = 24, Ce = 25, un = 26, Rr = 27, vr = 28, Lr = 29, st = 114, Or = 142, Dr = 194, Cr = 210, Mr = 602, Ur = 604, Br = 650, fn = 700, hn = 701, qr = 702, jr = 703, xr = 704, Pr = 718, Fr = 774, kr = 790, Wr = 829, Gr = 869, Yr = 1033, dn = 1042, pn = 1043, yn = 1082, Vr = 1083, gn = 1114, it = 1184, Hr = 1186, Jr = 1266, Qr = 1560, Xr = 1562, Kr = 1700, zr = 1790, Zr = 2202, es = 2203, ts = 2204, ns = 2205, rs = 2206, ss = 2950, is = 2970, as = 3220, os = 3361, cs = 3402, ls = 3614, us = 3615, fs = 3642, hs = 3734, ds = 3769, En = 3802, ps = 4089, ys = 4096, mn = { string: { to: Ce, from: [Ce, pn, dn], serialize: (e) => {
140
+ if (typeof e == "string") return e;
141
+ if (typeof e == "number") return e.toString();
142
+ throw new Error("Invalid input for string type");
143
+ }, parse: (e) => e }, number: { to: 0, from: [cn, ln, un, fn, hn], serialize: (e) => e.toString(), parse: (e) => +e }, bigint: { to: rt, from: [rt], serialize: (e) => e.toString(), parse: (e) => {
144
+ let t = BigInt(e);
145
+ return t < Number.MIN_SAFE_INTEGER || t > Number.MAX_SAFE_INTEGER ? t : Number(t);
146
+ } }, json: { to: st, from: [st, En], serialize: (e) => typeof e == "string" ? e : $r(e), parse: (e) => Ir(e) }, boolean: { to: tt, from: [tt], serialize: (e) => {
147
+ if (typeof e != "boolean") throw new Error("Invalid input for boolean type");
148
+ return e ? "t" : "f";
149
+ }, parse: (e) => e === "t" }, date: { to: it, from: [yn, gn, it], serialize: (e) => {
150
+ if (typeof e == "string") return e;
151
+ if (typeof e == "number") return new Date(e).toISOString();
152
+ if (e instanceof Date) return e.toISOString();
153
+ throw new Error("Invalid input for date type");
154
+ }, parse: (e) => new Date(e) }, bytea: { to: nt, from: [nt], serialize: (e) => {
155
+ if (!(e instanceof Uint8Array)) throw new Error("Invalid input for bytea type");
156
+ return "\\x" + Array.from(e).map((t) => t.toString(16).padStart(2, "0")).join("");
157
+ }, parse: (e) => {
158
+ let t = e.slice(2);
159
+ return Uint8Array.from({ length: t.length / 2 }, (n, s) => parseInt(t.substring(s * 2, (s + 1) * 2), 16));
160
+ } } }, gt = ms(mn), gs = gt.parsers, Es = gt.serializers;
161
+ function at(e, t, n) {
162
+ if (e === null) return null;
163
+ let s = n?.[t] ?? gt.parsers[t];
164
+ return s ? s(e, t) : e;
165
+ }
166
+ function ms(e) {
167
+ return Object.keys(e).reduce(({ parsers: t, serializers: n }, s) => {
168
+ let { to: r, from: a, serialize: f, parse: d } = e[s];
169
+ return n[r] = f, n[s] = f, t[s] = d, Array.isArray(a) ? a.forEach((h) => {
170
+ t[h] = d, n[h] = f;
171
+ }) : (t[a] = d, n[a] = f), { parsers: t, serializers: n };
172
+ }, { parsers: {}, serializers: {} });
173
+ }
174
+ var _s = /\\/g, ws = /"/g;
175
+ function bs(e) {
176
+ return e.replace(_s, "\\\\").replace(ws, '\\"');
177
+ }
178
+ function _n(e, t, n) {
179
+ if (Array.isArray(e) === !1) return e;
180
+ if (!e.length) return "{}";
181
+ let s = e[0], r = n === 1020 ? ";" : ",";
182
+ return Array.isArray(s) ? `{${e.map((a) => _n(a, t, n)).join(r)}}` : `{${e.map((a) => (a === void 0 && (a = null), a === null ? "null" : '"' + bs(t ? t(a) : a.toString()) + '"')).join(r)}}`;
183
+ }
184
+ var Qe = { i: 0, char: null, str: "", quoted: !1, last: 0, p: null };
185
+ function Ts(e, t, n) {
186
+ return Qe.i = Qe.last = 0, wn(Qe, e, t, n)[0];
187
+ }
188
+ function wn(e, t, n, s) {
189
+ let r = [], a = s === 1020 ? ";" : ",";
190
+ for (; e.i < t.length; e.i++) {
191
+ if (e.char = t[e.i], e.quoted) e.char === "\\" ? e.str += t[++e.i] : e.char === '"' ? (r.push(n ? n(e.str) : e.str), e.str = "", e.quoted = t[e.i + 1] === '"', e.last = e.i + 2) : e.str += e.char;
192
+ else if (e.char === '"') e.quoted = !0;
193
+ else if (e.char === "{") e.last = ++e.i, r.push(wn(e, t, n, s));
194
+ else if (e.char === "}") {
195
+ e.quoted = !1, e.last < e.i && r.push(n ? n(t.slice(e.last, e.i)) : t.slice(e.last, e.i)), e.last = e.i + 1;
196
+ break;
197
+ } else e.char === a && e.p !== "}" && e.p !== '"' && (r.push(n ? n(t.slice(e.last, e.i)) : t.slice(e.last, e.i)), e.last = e.i + 1);
198
+ e.p = e.char;
199
+ }
200
+ return e.last < e.i && r.push(n ? n(t.slice(e.last, e.i + 1)) : t.slice(e.last, e.i + 1)), r;
201
+ }
202
+ var As = {};
203
+ Fe(As, { parseDescribeStatementResults: () => bn, parseResults: () => Is });
204
+ pe();
205
+ function Is(e, t, n, s) {
206
+ let r = [], a = { rows: [], fields: [] }, f = 0, d = { ...t, ...n?.parsers };
207
+ return e.forEach((h) => {
208
+ switch (h.name) {
209
+ case "rowDescription": {
210
+ let E = h;
211
+ a.fields = E.fields.map(($) => ({ name: $.name, dataTypeID: $.dataTypeID }));
212
+ break;
213
+ }
214
+ case "dataRow": {
215
+ if (!a) break;
216
+ let E = h;
217
+ n?.rowMode === "array" ? a.rows.push(E.fields.map(($, N) => at($, a.fields[N].dataTypeID, d))) : a.rows.push(Object.fromEntries(E.fields.map(($, N) => [a.fields[N].name, at($, a.fields[N].dataTypeID, d)])));
218
+ break;
219
+ }
220
+ case "commandComplete": {
221
+ f += $s(h), r.push({ ...a, affectedRows: f, ...s ? { blob: s } : {} }), a = { rows: [], fields: [] };
222
+ break;
223
+ }
224
+ }
225
+ }), r.length === 0 && r.push({ affectedRows: 0, rows: [], fields: [] }), r;
226
+ }
227
+ function $s(e) {
228
+ let t = e.text.split(" ");
229
+ switch (t[0]) {
230
+ case "INSERT":
231
+ return parseInt(t[2], 10);
232
+ case "UPDATE":
233
+ case "DELETE":
234
+ case "COPY":
235
+ case "MERGE":
236
+ return parseInt(t[1], 10);
237
+ default:
238
+ return 0;
239
+ }
240
+ }
241
+ function bn(e) {
242
+ let t = e.find((n) => n.name === "parameterDescription");
243
+ return t ? t.dataTypeIDs : [];
244
+ }
245
+ var Tn = {};
246
+ Fe(Tn, { AuthenticationCleartextPassword: () => Dn, AuthenticationMD5Password: () => Cn, AuthenticationOk: () => On, AuthenticationSASL: () => Mn, AuthenticationSASLContinue: () => Un, AuthenticationSASLFinal: () => Bn, BackendKeyDataMessage: () => Wn, CommandCompleteMessage: () => Vn, CopyDataMessage: () => qn, CopyResponse: () => jn, DataRowMessage: () => Hn, DatabaseError: () => ot, Field: () => xn, NoticeMessage: () => Jn, NotificationResponseMessage: () => Gn, ParameterDescriptionMessage: () => Fn, ParameterStatusMessage: () => kn, ReadyForQueryMessage: () => Yn, RowDescriptionMessage: () => Pn, bindComplete: () => In, closeComplete: () => $n, copyDone: () => Ln, emptyQuery: () => vn, noData: () => Sn, parseComplete: () => An, portalSuspended: () => Nn, replicationStart: () => Rn });
247
+ pe();
248
+ var An = { name: "parseComplete", length: 5 }, In = { name: "bindComplete", length: 5 }, $n = { name: "closeComplete", length: 5 }, Sn = { name: "noData", length: 5 }, Nn = { name: "portalSuspended", length: 5 }, Rn = { name: "replicationStart", length: 4 }, vn = { name: "emptyQuery", length: 4 }, Ln = { name: "copyDone", length: 4 }, On = class {
249
+ constructor(t) {
250
+ this.length = t, this.name = "authenticationOk";
251
+ }
252
+ }, Dn = class {
253
+ constructor(e) {
254
+ this.length = e, this.name = "authenticationCleartextPassword";
255
+ }
256
+ }, Cn = class {
257
+ constructor(e, t) {
258
+ this.length = e, this.salt = t, this.name = "authenticationMD5Password";
259
+ }
260
+ }, Mn = class {
261
+ constructor(t, n) {
262
+ this.length = t, this.mechanisms = n, this.name = "authenticationSASL";
263
+ }
264
+ }, Un = class {
265
+ constructor(e, t) {
266
+ this.length = e, this.data = t, this.name = "authenticationSASLContinue";
267
+ }
268
+ }, Bn = class {
269
+ constructor(e, t) {
270
+ this.length = e, this.data = t, this.name = "authenticationSASLFinal";
271
+ }
272
+ }, ot = class extends Error {
273
+ constructor(e, t, n) {
274
+ super(e), this.length = t, this.name = n;
275
+ }
276
+ }, qn = class {
277
+ constructor(e, t) {
278
+ this.length = e, this.chunk = t, this.name = "copyData";
279
+ }
280
+ }, jn = class {
281
+ constructor(e, t, n, s) {
282
+ this.length = e, this.name = t, this.binary = n, this.columnTypes = new Array(s);
283
+ }
284
+ }, xn = class {
285
+ constructor(e, t, n, s, r, a, f) {
286
+ this.name = e, this.tableID = t, this.columnID = n, this.dataTypeID = s, this.dataTypeSize = r, this.dataTypeModifier = a, this.format = f;
287
+ }
288
+ }, Pn = class {
289
+ constructor(t, n) {
290
+ this.length = t, this.fieldCount = n, this.name = "rowDescription", this.fields = new Array(this.fieldCount);
291
+ }
292
+ }, Fn = class {
293
+ constructor(e, t) {
294
+ this.length = e, this.parameterCount = t, this.name = "parameterDescription", this.dataTypeIDs = new Array(this.parameterCount);
295
+ }
296
+ }, kn = class {
297
+ constructor(e, t, n) {
298
+ this.length = e, this.parameterName = t, this.parameterValue = n, this.name = "parameterStatus";
299
+ }
300
+ }, Wn = class {
301
+ constructor(e, t, n) {
302
+ this.length = e, this.processID = t, this.secretKey = n, this.name = "backendKeyData";
303
+ }
304
+ }, Gn = class {
305
+ constructor(e, t, n, s) {
306
+ this.length = e, this.processId = t, this.channel = n, this.payload = s, this.name = "notification";
307
+ }
308
+ }, Yn = class {
309
+ constructor(e, t) {
310
+ this.length = e, this.status = t, this.name = "readyForQuery";
311
+ }
312
+ }, Vn = class {
313
+ constructor(e, t) {
314
+ this.length = e, this.text = t, this.name = "commandComplete";
315
+ }
316
+ }, Hn = class {
317
+ constructor(e, t) {
318
+ this.length = e, this.fields = t, this.name = "dataRow", this.fieldCount = t.length;
319
+ }
320
+ }, Jn = class {
321
+ constructor(e, t) {
322
+ this.length = e, this.message = t, this.name = "notice";
323
+ }
324
+ }, Ss = {};
325
+ Fe(Ss, { Parser: () => Zs, messages: () => Tn, serialize: () => Oe });
326
+ pe();
327
+ pe();
328
+ pe();
329
+ pe();
330
+ function ke(e) {
331
+ let t = e.length;
332
+ for (let n = e.length - 1; n >= 0; n--) {
333
+ let s = e.charCodeAt(n);
334
+ s > 127 && s <= 2047 ? t++ : s > 2047 && s <= 65535 && (t += 2), s >= 56320 && s <= 57343 && n--;
335
+ }
336
+ return t;
337
+ }
338
+ var ie, Z, Se, ct, $e, ge, Me, Ae, Qn, We = class {
339
+ constructor(e = 256) {
340
+ this.size = e, ae(this, ge), ae(this, ie), ae(this, Z, 5), ae(this, Se, !1), ae(this, ct, new TextEncoder()), ae(this, $e, 0), Y(this, ie, G(this, ge, Me).call(this, e));
341
+ }
342
+ addInt32(e) {
343
+ return G(this, ge, Ae).call(this, 4), T(this, ie).setInt32(T(this, Z), e, T(this, Se)), Y(this, Z, T(this, Z) + 4), this;
344
+ }
345
+ addInt16(e) {
346
+ return G(this, ge, Ae).call(this, 2), T(this, ie).setInt16(T(this, Z), e, T(this, Se)), Y(this, Z, T(this, Z) + 2), this;
347
+ }
348
+ addCString(e) {
349
+ return e && this.addString(e), G(this, ge, Ae).call(this, 1), T(this, ie).setUint8(T(this, Z), 0), on(this, Z)._++, this;
350
+ }
351
+ addString(e = "") {
352
+ let t = ke(e);
353
+ return G(this, ge, Ae).call(this, t), T(this, ct).encodeInto(e, new Uint8Array(T(this, ie).buffer, T(this, Z))), Y(this, Z, T(this, Z) + t), this;
354
+ }
355
+ add(e) {
356
+ return G(this, ge, Ae).call(this, e.byteLength), new Uint8Array(T(this, ie).buffer).set(new Uint8Array(e), T(this, Z)), Y(this, Z, T(this, Z) + e.byteLength), this;
357
+ }
358
+ flush(e) {
359
+ let t = G(this, ge, Qn).call(this, e);
360
+ return Y(this, Z, 5), Y(this, ie, G(this, ge, Me).call(this, this.size)), new Uint8Array(t);
361
+ }
362
+ };
363
+ ie = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), Se = /* @__PURE__ */ new WeakMap(), ct = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakSet(), Me = function(e) {
364
+ return new DataView(new ArrayBuffer(e));
365
+ }, Ae = function(e) {
366
+ if (T(this, ie).byteLength - T(this, Z) < e) {
367
+ let t = T(this, ie).buffer, n = t.byteLength + (t.byteLength >> 1) + e;
368
+ Y(this, ie, G(this, ge, Me).call(this, n)), new Uint8Array(T(this, ie).buffer).set(new Uint8Array(t));
369
+ }
370
+ }, Qn = function(e) {
371
+ if (e) {
372
+ T(this, ie).setUint8(T(this, $e), e);
373
+ let t = T(this, Z) - (T(this, $e) + 1);
374
+ T(this, ie).setInt32(T(this, $e) + 1, t, T(this, Se));
375
+ }
376
+ return T(this, ie).buffer.slice(e ? 0 : 5, T(this, Z));
377
+ };
378
+ var J = new We(), Ns = (e) => {
379
+ J.addInt16(3).addInt16(0);
380
+ for (let s of Object.keys(e)) J.addCString(s).addCString(e[s]);
381
+ J.addCString("client_encoding").addCString("UTF8");
382
+ let t = J.addCString("").flush(), n = t.byteLength + 4;
383
+ return new We().addInt32(n).add(t).flush();
384
+ }, Rs = () => {
385
+ let e = new DataView(new ArrayBuffer(8));
386
+ return e.setInt32(0, 8, !1), e.setInt32(4, 80877103, !1), new Uint8Array(e.buffer);
387
+ }, vs = (e) => J.addCString(e).flush(112), Ls = (e, t) => (J.addCString(e).addInt32(ke(t)).addString(t), J.flush(112)), Os = (e) => J.addString(e).flush(112), Ds = (e) => J.addCString(e).flush(81), Cs = [], Ms = (e) => {
388
+ let t = e.name ?? "";
389
+ 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"));
390
+ let n = J.addCString(t).addCString(e.text).addInt16(e.types?.length ?? 0);
391
+ return e.types?.forEach((s) => n.addInt32(s)), J.flush(80);
392
+ }, Ie = new We(), Us = (e, t) => {
393
+ for (let n = 0; n < e.length; n++) {
394
+ let s = t ? t(e[n], n) : e[n];
395
+ if (s === null) J.addInt16(0), Ie.addInt32(-1);
396
+ else if (s instanceof ArrayBuffer || ArrayBuffer.isView(s)) {
397
+ let r = ArrayBuffer.isView(s) ? s.buffer.slice(s.byteOffset, s.byteOffset + s.byteLength) : s;
398
+ J.addInt16(1), Ie.addInt32(r.byteLength), Ie.add(r);
399
+ } else J.addInt16(0), Ie.addInt32(ke(s)), Ie.addString(s);
400
+ }
401
+ }, Bs = (e = {}) => {
402
+ let t = e.portal ?? "", n = e.statement ?? "", s = e.binary ?? !1, r = e.values ?? Cs, a = r.length;
403
+ return J.addCString(t).addCString(n), J.addInt16(a), Us(r, e.valueMapper), J.addInt16(a), J.add(Ie.flush()), J.addInt16(s ? 1 : 0), J.flush(66);
404
+ }, qs = new Uint8Array([69, 0, 0, 0, 9, 0, 0, 0, 0, 0]), js = (e) => {
405
+ if (!e || !e.portal && !e.rows) return qs;
406
+ let t = e.portal ?? "", n = e.rows ?? 0, s = ke(t), r = 4 + s + 1 + 4, a = new DataView(new ArrayBuffer(1 + r));
407
+ return a.setUint8(0, 69), a.setInt32(1, r, !1), new TextEncoder().encodeInto(t, new Uint8Array(a.buffer, 5)), a.setUint8(s + 5, 0), a.setUint32(a.byteLength - 4, n, !1), new Uint8Array(a.buffer);
408
+ }, xs = (e, t) => {
409
+ let n = new DataView(new ArrayBuffer(16));
410
+ 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);
411
+ }, Et = (e, t) => {
412
+ let n = new We();
413
+ return n.addCString(t), n.flush(e);
414
+ }, Ps = J.addCString("P").flush(68), Fs = J.addCString("S").flush(68), ks = (e) => e.name ? Et(68, `${e.type}${e.name ?? ""}`) : e.type === "P" ? Ps : Fs, Ws = (e) => {
415
+ let t = `${e.type}${e.name ?? ""}`;
416
+ return Et(67, t);
417
+ }, Gs = (e) => J.add(e).flush(100), Ys = (e) => Et(102, e), Ge = (e) => new Uint8Array([e, 0, 0, 0, 4]), Vs = Ge(72), Hs = Ge(83), Js = Ge(88), Qs = Ge(99), Oe = { startup: Ns, password: vs, requestSsl: Rs, sendSASLInitialResponseMessage: Ls, sendSCRAMClientFinalMessage: Os, query: Ds, parse: Ms, bind: Bs, execute: js, describe: ks, close: Ws, flush: () => Vs, sync: () => Hs, end: () => Js, copyData: Gs, copyDone: () => Qs, copyFail: Ys, cancel: xs };
418
+ pe();
419
+ pe();
420
+ var St = { text: 0, binary: 1 };
421
+ pe();
422
+ var Xs = new ArrayBuffer(0), we, ne, lt, ut, De, Ks = class {
423
+ constructor(e = 0) {
424
+ ae(this, we, new DataView(Xs)), ae(this, ne), ae(this, lt, "utf-8"), ae(this, ut, new TextDecoder(T(this, lt))), ae(this, De, !1), Y(this, ne, e);
425
+ }
426
+ setBuffer(e, t) {
427
+ Y(this, ne, e), Y(this, we, new DataView(t));
428
+ }
429
+ int16() {
430
+ let e = T(this, we).getInt16(T(this, ne), T(this, De));
431
+ return Y(this, ne, T(this, ne) + 2), e;
432
+ }
433
+ byte() {
434
+ let e = T(this, we).getUint8(T(this, ne));
435
+ return on(this, ne)._++, e;
436
+ }
437
+ int32() {
438
+ let e = T(this, we).getInt32(T(this, ne), T(this, De));
439
+ return Y(this, ne, T(this, ne) + 4), e;
440
+ }
441
+ string(e) {
442
+ return T(this, ut).decode(this.bytes(e));
443
+ }
444
+ cstring() {
445
+ let e = T(this, ne), t = e;
446
+ for (; T(this, we).getUint8(t++) !== 0; ) ;
447
+ let n = this.string(t - e - 1);
448
+ return Y(this, ne, t), n;
449
+ }
450
+ bytes(e) {
451
+ let t = T(this, we).buffer.slice(T(this, ne), T(this, ne) + e);
452
+ return Y(this, ne, T(this, ne) + e), new Uint8Array(t);
453
+ }
454
+ };
455
+ we = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new WeakMap(), lt = /* @__PURE__ */ new WeakMap(), ut = /* @__PURE__ */ new WeakMap(), De = /* @__PURE__ */ new WeakMap();
456
+ var ft = 1, zs = 4, Nt = ft + zs, Rt = new ArrayBuffer(0), fe, he, de, x, K, Xn, Kn, vt, Lt, Ot, Dt, Ct, Xe, Mt, Ut, Bt, qt, jt, xt, Pt, Ft, Ke, Zs = class {
457
+ constructor() {
458
+ ae(this, K), ae(this, fe, new DataView(Rt)), ae(this, he, 0), ae(this, de, 0), ae(this, x, new Ks());
459
+ }
460
+ parse(e, t) {
461
+ G(this, K, Xn).call(this, ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : e);
462
+ let n = T(this, de) + T(this, he), s = T(this, de);
463
+ for (; s + Nt <= n; ) {
464
+ let r = T(this, fe).getUint8(s), a = T(this, fe).getUint32(s + ft, !1), f = ft + a;
465
+ if (f + s <= n && a > 0) {
466
+ let d = G(this, K, Kn).call(this, s + Nt, r, a, T(this, fe).buffer);
467
+ t(d), s += f;
468
+ } else break;
469
+ }
470
+ s === n ? (Y(this, fe, new DataView(Rt)), Y(this, he, 0), Y(this, de, 0)) : (Y(this, he, n - s), Y(this, de, s));
471
+ }
472
+ };
473
+ fe = /* @__PURE__ */ new WeakMap(), he = /* @__PURE__ */ new WeakMap(), de = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakSet(), Xn = function(e) {
474
+ if (T(this, he) > 0) {
475
+ let t = T(this, he) + e.byteLength;
476
+ if (t + T(this, de) > T(this, fe).byteLength) {
477
+ let n;
478
+ if (t <= T(this, fe).byteLength && T(this, de) >= T(this, he)) n = T(this, fe).buffer;
479
+ else {
480
+ let s = T(this, fe).byteLength * 2;
481
+ for (; t >= s; ) s *= 2;
482
+ n = new ArrayBuffer(s);
483
+ }
484
+ new Uint8Array(n).set(new Uint8Array(T(this, fe).buffer, T(this, de), T(this, he))), Y(this, fe, new DataView(n)), Y(this, de, 0);
485
+ }
486
+ new Uint8Array(T(this, fe).buffer).set(new Uint8Array(e), T(this, de) + T(this, he)), Y(this, he, t);
487
+ } else Y(this, fe, new DataView(e)), Y(this, de, 0), Y(this, he, e.byteLength);
488
+ }, Kn = function(e, t, n, s) {
489
+ switch (t) {
490
+ case 50:
491
+ return In;
492
+ case 49:
493
+ return An;
494
+ case 51:
495
+ return $n;
496
+ case 110:
497
+ return Sn;
498
+ case 115:
499
+ return Nn;
500
+ case 99:
501
+ return Ln;
502
+ case 87:
503
+ return Rn;
504
+ case 73:
505
+ return vn;
506
+ case 68:
507
+ return G(this, K, jt).call(this, e, n, s);
508
+ case 67:
509
+ return G(this, K, Lt).call(this, e, n, s);
510
+ case 90:
511
+ return G(this, K, vt).call(this, e, n, s);
512
+ case 65:
513
+ return G(this, K, Mt).call(this, e, n, s);
514
+ case 82:
515
+ return G(this, K, Ft).call(this, e, n, s);
516
+ case 83:
517
+ return G(this, K, xt).call(this, e, n, s);
518
+ case 75:
519
+ return G(this, K, Pt).call(this, e, n, s);
520
+ case 69:
521
+ return G(this, K, Ke).call(this, e, n, s, "error");
522
+ case 78:
523
+ return G(this, K, Ke).call(this, e, n, s, "notice");
524
+ case 84:
525
+ return G(this, K, Ut).call(this, e, n, s);
526
+ case 116:
527
+ return G(this, K, qt).call(this, e, n, s);
528
+ case 71:
529
+ return G(this, K, Dt).call(this, e, n, s);
530
+ case 72:
531
+ return G(this, K, Ct).call(this, e, n, s);
532
+ case 100:
533
+ return G(this, K, Ot).call(this, e, n, s);
534
+ default:
535
+ return new ot("received invalid response: " + t.toString(16), n, "error");
536
+ }
537
+ }, vt = function(e, t, n) {
538
+ T(this, x).setBuffer(e, n);
539
+ let s = T(this, x).string(1);
540
+ return new Yn(t, s);
541
+ }, Lt = function(e, t, n) {
542
+ T(this, x).setBuffer(e, n);
543
+ let s = T(this, x).cstring();
544
+ return new Vn(t, s);
545
+ }, Ot = function(e, t, n) {
546
+ let s = n.slice(e, e + (t - 4));
547
+ return new qn(t, new Uint8Array(s));
548
+ }, Dt = function(e, t, n) {
549
+ return G(this, K, Xe).call(this, e, t, n, "copyInResponse");
550
+ }, Ct = function(e, t, n) {
551
+ return G(this, K, Xe).call(this, e, t, n, "copyOutResponse");
552
+ }, Xe = function(e, t, n, s) {
553
+ T(this, x).setBuffer(e, n);
554
+ let r = T(this, x).byte() !== 0, a = T(this, x).int16(), f = new jn(t, s, r, a);
555
+ for (let d = 0; d < a; d++) f.columnTypes[d] = T(this, x).int16();
556
+ return f;
557
+ }, Mt = function(e, t, n) {
558
+ T(this, x).setBuffer(e, n);
559
+ let s = T(this, x).int32(), r = T(this, x).cstring(), a = T(this, x).cstring();
560
+ return new Gn(t, s, r, a);
561
+ }, Ut = function(e, t, n) {
562
+ T(this, x).setBuffer(e, n);
563
+ let s = T(this, x).int16(), r = new Pn(t, s);
564
+ for (let a = 0; a < s; a++) r.fields[a] = G(this, K, Bt).call(this);
565
+ return r;
566
+ }, Bt = function() {
567
+ let e = T(this, x).cstring(), t = T(this, x).int32(), n = T(this, x).int16(), s = T(this, x).int32(), r = T(this, x).int16(), a = T(this, x).int32(), f = T(this, x).int16() === 0 ? St.text : St.binary;
568
+ return new xn(e, t, n, s, r, a, f);
569
+ }, qt = function(e, t, n) {
570
+ T(this, x).setBuffer(e, n);
571
+ let s = T(this, x).int16(), r = new Fn(t, s);
572
+ for (let a = 0; a < s; a++) r.dataTypeIDs[a] = T(this, x).int32();
573
+ return r;
574
+ }, jt = function(e, t, n) {
575
+ T(this, x).setBuffer(e, n);
576
+ let s = T(this, x).int16(), r = new Array(s);
577
+ for (let a = 0; a < s; a++) {
578
+ let f = T(this, x).int32();
579
+ r[a] = f === -1 ? null : T(this, x).string(f);
580
+ }
581
+ return new Hn(t, r);
582
+ }, xt = function(e, t, n) {
583
+ T(this, x).setBuffer(e, n);
584
+ let s = T(this, x).cstring(), r = T(this, x).cstring();
585
+ return new kn(t, s, r);
586
+ }, Pt = function(e, t, n) {
587
+ T(this, x).setBuffer(e, n);
588
+ let s = T(this, x).int32(), r = T(this, x).int32();
589
+ return new Wn(t, s, r);
590
+ }, Ft = function(e, t, n) {
591
+ T(this, x).setBuffer(e, n);
592
+ let s = T(this, x).int32();
593
+ switch (s) {
594
+ case 0:
595
+ return new On(t);
596
+ case 3:
597
+ return new Dn(t);
598
+ case 5:
599
+ return new Cn(t, T(this, x).bytes(4));
600
+ case 10: {
601
+ let r = [];
602
+ for (; ; ) {
603
+ let a = T(this, x).cstring();
604
+ if (a.length === 0) return new Mn(t, r);
605
+ r.push(a);
606
+ }
607
+ }
608
+ case 11:
609
+ return new Un(t, T(this, x).string(t - 8));
610
+ case 12:
611
+ return new Bn(t, T(this, x).string(t - 8));
612
+ default:
613
+ throw new Error("Unknown authenticationOk message type " + s);
614
+ }
615
+ }, Ke = function(e, t, n, s) {
616
+ T(this, x).setBuffer(e, n);
617
+ let r = {}, a = T(this, x).string(1);
618
+ for (; a !== "\0"; ) r[a] = T(this, x).cstring(), a = T(this, x).string(1);
619
+ let f = r.M, d = s === "notice" ? new Jn(t, f) : new ot(f, t, s);
620
+ return d.severity = r.S, d.code = r.C, d.detail = r.D, d.hint = r.H, d.position = r.P, d.internalPosition = r.p, d.internalQuery = r.q, d.where = r.W, d.schema = r.s, d.table = r.t, d.column = r.c, d.dataType = r.d, d.constraint = r.n, d.file = r.F, d.line = r.L, d.routine = r.R, d;
621
+ };
622
+ pe();
623
+ typeof process == "object" && typeof process.versions == "object" && process.versions.node;
624
+ var kt = () => {
625
+ if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
626
+ let e = new Uint8Array(16);
627
+ if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(e);
628
+ else for (let n = 0; n < e.length; n++) e[n] = Math.floor(Math.random() * 256);
629
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
630
+ let t = [];
631
+ return e.forEach((n) => {
632
+ t.push(n.toString(16).padStart(2, "0"));
633
+ }), t.slice(0, 4).join("") + "-" + t.slice(4, 6).join("") + "-" + t.slice(6, 8).join("") + "-" + t.slice(8, 10).join("") + "-" + t.slice(10).join("");
634
+ };
635
+ async function Wt(e, t, n, s) {
636
+ if (!n || n.length === 0) return t;
637
+ s = s ?? e;
638
+ let r = [];
639
+ try {
640
+ await e.execProtocol(Oe.parse({ text: t }), { syncToFs: !1 }), r.push(...(await e.execProtocol(Oe.describe({ type: "S" }), { syncToFs: !1 })).messages);
641
+ } finally {
642
+ r.push(...(await e.execProtocol(Oe.sync(), { syncToFs: !1 })).messages);
643
+ }
644
+ let a = bn(r), f = t.replace(/\$([0-9]+)/g, (d, h) => "%" + h + "L");
645
+ return (await s.query(`SELECT format($1, ${n.map((d, h) => `$${h + 2}`).join(", ")}) as query`, [f, ...n], { paramTypes: [Ce, ...a] })).rows[0].query;
646
+ }
647
+ function Gt(e) {
648
+ let t, n = !1, s = async () => {
649
+ if (!t) {
650
+ n = !1;
651
+ return;
652
+ }
653
+ n = !0;
654
+ let { args: r, resolve: a, reject: f } = t;
655
+ t = void 0;
656
+ try {
657
+ let d = await e(...r);
658
+ a(d);
659
+ } catch (d) {
660
+ f(d);
661
+ } finally {
662
+ s();
663
+ }
664
+ };
665
+ return async (...r) => {
666
+ t && t.resolve(void 0);
667
+ let a = new Promise((f, d) => {
668
+ t = { args: r, resolve: f, reject: d };
669
+ });
670
+ return n || s(), a;
671
+ };
672
+ }
673
+ pe();
674
+ var ei = 5, ti = async (e, t) => {
675
+ let n = /* @__PURE__ */ new Set(), s = { async query(r, a, f) {
676
+ let d, h, E;
677
+ if (typeof r != "string" && (d = r.signal, a = r.params, f = r.callback, h = r.offset, E = r.limit, r = r.query), h === void 0 != (E === void 0)) throw new Error("offset and limit must be provided together");
678
+ let $ = h !== void 0 && E !== void 0, N;
679
+ if ($ && (typeof h != "number" || isNaN(h) || typeof E != "number" || isNaN(E))) throw new Error("offset and limit must be numbers");
680
+ let D = f ? [f] : [], M = kt().replace(/-/g, ""), S = !1, C, _, R = async () => {
681
+ await e.transaction(async (I) => {
682
+ let p = a && a.length > 0 ? await Wt(e, r, a, I) : r;
683
+ await I.exec(`CREATE OR REPLACE TEMP VIEW live_query_${M}_view AS ${p}`);
684
+ let m = await Yt(I, `live_query_${M}_view`);
685
+ await Vt(I, m, n), $ ? (await I.exec(`
686
+ PREPARE live_query_${M}_get(int, int) AS
687
+ SELECT * FROM live_query_${M}_view
688
+ LIMIT $1 OFFSET $2;
689
+ `), await I.exec(`
690
+ PREPARE live_query_${M}_get_total_count AS
691
+ SELECT COUNT(*) FROM live_query_${M}_view;
692
+ `), N = (await I.query(`EXECUTE live_query_${M}_get_total_count;`)).rows[0].count, C = { ...await I.query(`EXECUTE live_query_${M}_get(${E}, ${h});`), offset: h, limit: E, totalCount: N }) : (await I.exec(`
693
+ PREPARE live_query_${M}_get AS
694
+ SELECT * FROM live_query_${M}_view;
695
+ `), C = await I.query(`EXECUTE live_query_${M}_get;`)), _ = await Promise.all(m.map((c) => I.listen(`"table_change__${c.schema_oid}__${c.table_oid}"`, async () => {
696
+ O();
697
+ })));
698
+ });
699
+ };
700
+ await R();
701
+ let O = Gt(async ({ offset: I, limit: p } = {}) => {
702
+ if (!$ && (I !== void 0 || p !== void 0)) throw new Error("offset and limit cannot be provided for non-windowed queries");
703
+ if (I && (typeof I != "number" || isNaN(I)) || p && (typeof p != "number" || isNaN(p))) throw new Error("offset and limit must be numbers");
704
+ h = I ?? h, E = p ?? E;
705
+ let m = async (c = 0) => {
706
+ if (D.length !== 0) {
707
+ try {
708
+ $ ? C = { ...await e.query(`EXECUTE live_query_${M}_get(${E}, ${h});`), offset: h, limit: E, totalCount: N } : C = await e.query(`EXECUTE live_query_${M}_get;`);
709
+ } catch (l) {
710
+ let o = l.message;
711
+ if (o.startsWith(`prepared statement "live_query_${M}`) && o.endsWith("does not exist")) {
712
+ if (c > ei) throw l;
713
+ await R(), m(c + 1);
714
+ } else throw l;
715
+ }
716
+ if (ve(D, C), $) {
717
+ let l = (await e.query(`EXECUTE live_query_${M}_get_total_count;`)).rows[0].count;
718
+ l !== N && (N = l, O());
719
+ }
720
+ }
721
+ };
722
+ await m();
723
+ }), A = (I) => {
724
+ if (S) throw new Error("Live query is no longer active and cannot be subscribed to");
725
+ D.push(I);
726
+ }, b = async (I) => {
727
+ I ? D = D.filter((p) => p !== p) : D = [], D.length === 0 && !S && (S = !0, await e.transaction(async (p) => {
728
+ await Promise.all(_.map((m) => m(p))), await p.exec(`
729
+ DROP VIEW IF EXISTS live_query_${M}_view;
730
+ DEALLOCATE live_query_${M}_get;
731
+ `);
732
+ }));
733
+ };
734
+ return d?.aborted ? await b() : d?.addEventListener("abort", () => {
735
+ b();
736
+ }, { once: !0 }), ve(D, C), { initialResults: C, subscribe: A, unsubscribe: b, refresh: O };
737
+ }, async changes(r, a, f, d) {
738
+ let h;
739
+ if (typeof r != "string" && (h = r.signal, a = r.params, f = r.key, d = r.callback, r = r.query), !f) throw new Error("key is required for changes queries");
740
+ let E = d ? [d] : [], $ = kt().replace(/-/g, ""), N = !1, D = 1, M, S, C = async () => {
741
+ await e.transaction(async (A) => {
742
+ let b = await Wt(e, r, a, A);
743
+ await A.query(`CREATE OR REPLACE TEMP VIEW live_query_${$}_view AS ${b}`);
744
+ let I = await Yt(A, `live_query_${$}_view`);
745
+ await Vt(A, I, n);
746
+ let p = [...(await A.query(`
747
+ SELECT column_name, data_type, udt_name
748
+ FROM information_schema.columns
749
+ WHERE table_name = 'live_query_${$}_view'
750
+ `)).rows, { column_name: "__after__", data_type: "integer" }];
751
+ await A.exec(`
752
+ CREATE TEMP TABLE live_query_${$}_state1 (LIKE live_query_${$}_view INCLUDING ALL);
753
+ CREATE TEMP TABLE live_query_${$}_state2 (LIKE live_query_${$}_view INCLUDING ALL);
754
+ `);
755
+ for (let m of [1, 2]) {
756
+ let c = m === 1 ? 2 : 1;
757
+ await A.exec(`
758
+ PREPARE live_query_${$}_diff${m} AS
759
+ WITH
760
+ prev AS (SELECT LAG("${f}") OVER () as __after__, * FROM live_query_${$}_state${c}),
761
+ curr AS (SELECT LAG("${f}") OVER () as __after__, * FROM live_query_${$}_state${m}),
762
+ data_diff AS (
763
+ -- INSERT operations: Include all columns
764
+ SELECT
765
+ 'INSERT' AS __op__,
766
+ ${p.map(({ column_name: l }) => `curr."${l}" AS "${l}"`).join(`,
767
+ `)},
768
+ ARRAY[]::text[] AS __changed_columns__
769
+ FROM curr
770
+ LEFT JOIN prev ON curr.${f} = prev.${f}
771
+ WHERE prev.${f} IS NULL
772
+ UNION ALL
773
+ -- DELETE operations: Include only the primary key
774
+ SELECT
775
+ 'DELETE' AS __op__,
776
+ ${p.map(({ column_name: l, data_type: o, udt_name: g }) => l === f ? `prev."${l}" AS "${l}"` : `NULL${o === "USER-DEFINED" ? `::${g}` : ""} AS "${l}"`).join(`,
777
+ `)},
778
+ ARRAY[]::text[] AS __changed_columns__
779
+ FROM prev
780
+ LEFT JOIN curr ON prev.${f} = curr.${f}
781
+ WHERE curr.${f} IS NULL
782
+ UNION ALL
783
+ -- UPDATE operations: Include only changed columns
784
+ SELECT
785
+ 'UPDATE' AS __op__,
786
+ ${p.map(({ column_name: l, data_type: o, udt_name: g }) => l === f ? `curr."${l}" AS "${l}"` : `CASE
787
+ WHEN curr."${l}" IS DISTINCT FROM prev."${l}"
788
+ THEN curr."${l}"
789
+ ELSE NULL${o === "USER-DEFINED" ? `::${g}` : ""}
790
+ END AS "${l}"`).join(`,
791
+ `)},
792
+ ARRAY(SELECT unnest FROM unnest(ARRAY[${p.filter(({ column_name: l }) => l !== f).map(({ column_name: l }) => `CASE
793
+ WHEN curr."${l}" IS DISTINCT FROM prev."${l}"
794
+ THEN '${l}'
795
+ ELSE NULL
796
+ END`).join(", ")}]) WHERE unnest IS NOT NULL) AS __changed_columns__
797
+ FROM curr
798
+ INNER JOIN prev ON curr.${f} = prev.${f}
799
+ WHERE NOT (curr IS NOT DISTINCT FROM prev)
800
+ )
801
+ SELECT * FROM data_diff;
802
+ `);
803
+ }
804
+ S = await Promise.all(I.map((m) => A.listen(`"table_change__${m.schema_oid}__${m.table_oid}"`, async () => {
805
+ _();
806
+ })));
807
+ });
808
+ };
809
+ await C();
810
+ let _ = Gt(async () => {
811
+ if (E.length === 0 && M) return;
812
+ let A = !1;
813
+ for (let b = 0; b < 5; b++) try {
814
+ await e.transaction(async (I) => {
815
+ await I.exec(`
816
+ INSERT INTO live_query_${$}_state${D}
817
+ SELECT * FROM live_query_${$}_view;
818
+ `), M = await I.query(`EXECUTE live_query_${$}_diff${D};`), D = D === 1 ? 2 : 1, await I.exec(`
819
+ TRUNCATE live_query_${$}_state${D};
820
+ `);
821
+ });
822
+ break;
823
+ } catch (I) {
824
+ if (I.message === `relation "live_query_${$}_state${D}" does not exist`) {
825
+ A = !0, await C();
826
+ continue;
827
+ } else throw I;
828
+ }
829
+ ri(E, [...A ? [{ __op__: "RESET" }] : [], ...M.rows]);
830
+ }), R = (A) => {
831
+ if (N) throw new Error("Live query is no longer active and cannot be subscribed to");
832
+ E.push(A);
833
+ }, O = async (A) => {
834
+ A ? E = E.filter((b) => b !== b) : E = [], E.length === 0 && !N && (N = !0, await e.transaction(async (b) => {
835
+ await Promise.all(S.map((I) => I(b))), await b.exec(`
836
+ DROP VIEW IF EXISTS live_query_${$}_view;
837
+ DROP TABLE IF EXISTS live_query_${$}_state1;
838
+ DROP TABLE IF EXISTS live_query_${$}_state2;
839
+ DEALLOCATE live_query_${$}_diff1;
840
+ DEALLOCATE live_query_${$}_diff2;
841
+ `);
842
+ }));
843
+ };
844
+ return h?.aborted ? await O() : h?.addEventListener("abort", () => {
845
+ O();
846
+ }, { once: !0 }), await _(), { fields: M.fields.filter((A) => !["__after__", "__op__", "__changed_columns__"].includes(A.name)), initialChanges: M.rows, subscribe: R, unsubscribe: O, refresh: _ };
847
+ }, async incrementalQuery(r, a, f, d) {
848
+ let h;
849
+ if (typeof r != "string" && (h = r.signal, a = r.params, f = r.key, d = r.callback, r = r.query), !f) throw new Error("key is required for incremental queries");
850
+ let E = d ? [d] : [], $ = /* @__PURE__ */ new Map(), N = /* @__PURE__ */ new Map(), D = [], M = !0, { fields: S, unsubscribe: C, refresh: _ } = await s.changes(r, a, f, (A) => {
851
+ for (let p of A) {
852
+ let { __op__: m, __changed_columns__: c, ...l } = p;
853
+ switch (m) {
854
+ case "RESET":
855
+ $.clear(), N.clear();
856
+ break;
857
+ case "INSERT":
858
+ $.set(l[f], l), N.set(l.__after__, l[f]);
859
+ break;
860
+ case "DELETE": {
861
+ let o = $.get(l[f]);
862
+ $.delete(l[f]), o.__after__ !== null && N.delete(o.__after__);
863
+ break;
864
+ }
865
+ case "UPDATE": {
866
+ let o = { ...$.get(l[f]) ?? {} };
867
+ for (let g of c) o[g] = l[g], g === "__after__" && N.set(l.__after__, l[f]);
868
+ $.set(l[f], o);
869
+ break;
870
+ }
871
+ }
872
+ }
873
+ let b = [], I = null;
874
+ for (let p = 0; p < $.size; p++) {
875
+ let m = N.get(I), c = $.get(m);
876
+ if (!c) break;
877
+ let l = { ...c };
878
+ delete l.__after__, b.push(l), I = m;
879
+ }
880
+ D = b, M || ve(E, { rows: b, fields: S });
881
+ });
882
+ M = !1, ve(E, { rows: D, fields: S });
883
+ let R = (A) => {
884
+ E.push(A);
885
+ }, O = async (A) => {
886
+ A ? E = E.filter((b) => b !== b) : E = [], E.length === 0 && await C();
887
+ };
888
+ return h?.aborted ? await O() : h?.addEventListener("abort", () => {
889
+ O();
890
+ }, { once: !0 }), { initialResults: { rows: D, fields: S }, subscribe: R, unsubscribe: O, refresh: _ };
891
+ } };
892
+ return { namespaceObj: s };
893
+ }, ni = { name: "Live Queries", setup: ti };
894
+ async function Yt(e, t) {
895
+ return (await e.query(`
896
+ WITH RECURSIVE view_dependencies AS (
897
+ -- Base case: Get the initial view's dependencies
898
+ SELECT DISTINCT
899
+ cl.relname AS dependent_name,
900
+ n.nspname AS schema_name,
901
+ cl.oid AS dependent_oid,
902
+ n.oid AS schema_oid,
903
+ cl.relkind = 'v' AS is_view
904
+ FROM pg_rewrite r
905
+ JOIN pg_depend d ON r.oid = d.objid
906
+ JOIN pg_class cl ON d.refobjid = cl.oid
907
+ JOIN pg_namespace n ON cl.relnamespace = n.oid
908
+ WHERE
909
+ r.ev_class = (
910
+ SELECT oid FROM pg_class WHERE relname = $1 AND relkind = 'v'
911
+ )
912
+ AND d.deptype = 'n'
913
+
914
+ UNION ALL
915
+
916
+ -- Recursive case: Traverse dependencies for views
917
+ SELECT DISTINCT
918
+ cl.relname AS dependent_name,
919
+ n.nspname AS schema_name,
920
+ cl.oid AS dependent_oid,
921
+ n.oid AS schema_oid,
922
+ cl.relkind = 'v' AS is_view
923
+ FROM view_dependencies vd
924
+ JOIN pg_rewrite r ON vd.dependent_name = (
925
+ SELECT relname FROM pg_class WHERE oid = r.ev_class AND relkind = 'v'
926
+ )
927
+ JOIN pg_depend d ON r.oid = d.objid
928
+ JOIN pg_class cl ON d.refobjid = cl.oid
929
+ JOIN pg_namespace n ON cl.relnamespace = n.oid
930
+ WHERE d.deptype = 'n'
931
+ )
932
+ SELECT DISTINCT
933
+ dependent_name AS table_name,
934
+ schema_name,
935
+ dependent_oid AS table_oid,
936
+ schema_oid
937
+ FROM view_dependencies
938
+ WHERE NOT is_view; -- Exclude intermediate views
939
+ `, [t])).rows.map((n) => ({ table_name: n.table_name, schema_name: n.schema_name, table_oid: n.table_oid, schema_oid: n.schema_oid }));
940
+ }
941
+ async function Vt(e, t, n) {
942
+ let s = t.filter((r) => !n.has(`${r.schema_oid}_${r.table_oid}`)).map((r) => `
943
+ CREATE OR REPLACE FUNCTION "_notify_${r.schema_oid}_${r.table_oid}"() RETURNS TRIGGER AS $$
944
+ BEGIN
945
+ PERFORM pg_notify('table_change__${r.schema_oid}__${r.table_oid}', '');
946
+ RETURN NULL;
947
+ END;
948
+ $$ LANGUAGE plpgsql;
949
+ CREATE OR REPLACE TRIGGER "_notify_trigger_${r.schema_oid}_${r.table_oid}"
950
+ AFTER INSERT OR UPDATE OR DELETE ON "${r.schema_name}"."${r.table_name}"
951
+ FOR EACH STATEMENT EXECUTE FUNCTION "_notify_${r.schema_oid}_${r.table_oid}"();
952
+ `).join(`
953
+ `);
954
+ s.trim() !== "" && await e.exec(s), t.map((r) => n.add(`${r.schema_oid}_${r.table_oid}`));
955
+ }
956
+ var ve = (e, t) => {
957
+ for (let n of e) n(t);
958
+ }, ri = (e, t) => {
959
+ for (let n of e) n(t);
960
+ };
961
+ class Ht extends lr {
74
962
  #e;
75
- async init(e, t) {
76
- return this.#e = new $({
77
- dataDir: t.store === "memory" ? void 0 : `idb://${e}`,
78
- database: e
79
- }), this.#e.waitReady;
963
+ #n;
964
+ #a = 16;
965
+ // 批量发送间隔 (ms)
966
+ #t = [];
967
+ #r;
968
+ async init(t, n) {
969
+ this.#n = t, this.#e = new dr({
970
+ ...n,
971
+ dataDir: n.store === "memory" ? void 0 : `idb://${t}`,
972
+ database: t,
973
+ extensions: {
974
+ live: ni
975
+ }
976
+ }), await this.#e.waitReady;
977
+ const s = ["public$RxDBChange", "public$RxDBBranch", "public$RxDBMigration"];
978
+ for (const r of s)
979
+ await this.#e.exec(`LISTEN "${r}_notify"`);
980
+ this.#e.onNotification((r, a) => {
981
+ this.#o(r, a);
982
+ });
80
983
  }
81
- sql(e, ...t) {
82
- return this.#e.sql(e, ...t);
984
+ sql(t, ...n) {
985
+ return this.#e.sql(t, ...n);
83
986
  }
84
- exec(e, t) {
85
- return this.#e.exec(e, t);
987
+ exec(t, n) {
988
+ return this.#e.exec(t, n);
86
989
  }
87
- query(e, t, n) {
88
- return this.#e.query(e, t, n);
990
+ query(t, n, s) {
991
+ return this.#e.query(t, n, s);
89
992
  }
90
- describeQuery(e, t) {
91
- return this.#e.describeQuery(e, t);
993
+ describeQuery(t, n) {
994
+ return this.#e.describeQuery(t, n);
92
995
  }
93
- transaction(e) {
94
- return this.#e.transaction(e);
996
+ transaction(t) {
997
+ return this.#e.transaction(t);
95
998
  }
96
- runExclusive(e) {
97
- return this.#e.runExclusive(e);
999
+ runExclusive(t) {
1000
+ return this.#e.runExclusive(t);
98
1001
  }
99
- disconnect() {
100
- throw new a("Method not implemented.");
1002
+ async disconnect() {
1003
+ await this.#e.close();
101
1004
  }
102
1005
  async version() {
103
1006
  return (await this.#e.query("SELECT version()")).rows[0].version;
104
1007
  }
1008
+ /**
1009
+ * 处理 NOTIFY 通知
1010
+ * @param channel - 通知频道名称
1011
+ * @param payload - JSON 格式的 payload
1012
+ */
1013
+ #o(t, n) {
1014
+ try {
1015
+ const s = JSON.parse(n), r = t.replace("_notify", "");
1016
+ for (const a of s.ids)
1017
+ this.#t.push({
1018
+ type: s.operation,
1019
+ tableName: r,
1020
+ id: a
1021
+ });
1022
+ this.#r && clearTimeout(this.#r), this.#r = setTimeout(() => {
1023
+ this.#s(), this.#r = void 0;
1024
+ }, this.#a);
1025
+ } catch (s) {
1026
+ console.error("Failed to parse NOTIFY payload:", s);
1027
+ }
1028
+ }
1029
+ /**
1030
+ * 批量发送聚合后的事件
1031
+ */
1032
+ #s() {
1033
+ const t = Object.groupBy(this.#t, (n) => `${n.type}_${n.tableName}`);
1034
+ for (const [, n] of Object.entries(t)) {
1035
+ if (!n || n.length === 0) continue;
1036
+ const s = n[0], r = n.map((f) => f.id), a = {
1037
+ type: s.type,
1038
+ dbName: this.#n,
1039
+ tableName: s.tableName,
1040
+ rowIds: r,
1041
+ recordAt: /* @__PURE__ */ new Date()
1042
+ };
1043
+ this.dispatchEvent(s.type, a);
1044
+ }
1045
+ this.#t.length = 0;
1046
+ }
105
1047
  }
106
- class B extends _ {
107
- constructor(e, t) {
108
- super(e), this.options = t;
1048
+ function si(e) {
1049
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
1050
+ }
1051
+ function Le(e) {
1052
+ throw new Error('Could not dynamically require "' + e + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
1053
+ }
1054
+ var ze = { exports: {} }, Jt;
1055
+ function ii() {
1056
+ return Jt || (Jt = 1, (function(e, t) {
1057
+ (function(n) {
1058
+ e.exports = n();
1059
+ })(function() {
1060
+ return (function n(s, r, a) {
1061
+ function f(E, $) {
1062
+ if (!r[E]) {
1063
+ if (!s[E]) {
1064
+ var N = typeof Le == "function" && Le;
1065
+ if (!$ && N) return N(E, !0);
1066
+ if (d) return d(E, !0);
1067
+ throw new Error("Cannot find module '" + E + "'");
1068
+ }
1069
+ $ = r[E] = { exports: {} }, s[E][0].call($.exports, function(D) {
1070
+ var M = s[E][1][D];
1071
+ return f(M || D);
1072
+ }, $, $.exports, n, s, r, a);
1073
+ }
1074
+ return r[E].exports;
1075
+ }
1076
+ for (var d = typeof Le == "function" && Le, h = 0; h < a.length; h++) f(a[h]);
1077
+ return f;
1078
+ })({ 1: [function(n, s, r) {
1079
+ (function(a, f, d, h, E, $, N, D, M) {
1080
+ var S = n("crypto");
1081
+ function C(p, m) {
1082
+ m = O(p, m);
1083
+ var c;
1084
+ return (c = m.algorithm !== "passthrough" ? S.createHash(m.algorithm) : new I()).write === void 0 && (c.write = c.update, c.end = c.update), b(m, c).dispatch(p), c.update || c.end(""), c.digest ? c.digest(m.encoding === "buffer" ? void 0 : m.encoding) : (p = c.read(), m.encoding !== "buffer" ? p.toString(m.encoding) : p);
1085
+ }
1086
+ (r = s.exports = C).sha1 = function(p) {
1087
+ return C(p);
1088
+ }, r.keys = function(p) {
1089
+ return C(p, { excludeValues: !0, algorithm: "sha1", encoding: "hex" });
1090
+ }, r.MD5 = function(p) {
1091
+ return C(p, { algorithm: "md5", encoding: "hex" });
1092
+ }, r.keysMD5 = function(p) {
1093
+ return C(p, { algorithm: "md5", encoding: "hex", excludeValues: !0 });
1094
+ };
1095
+ var _ = S.getHashes ? S.getHashes().slice() : ["sha1", "md5"], R = (_.push("passthrough"), ["buffer", "hex", "binary", "base64"]);
1096
+ function O(p, m) {
1097
+ var c = {};
1098
+ if (c.algorithm = (m = m || {}).algorithm || "sha1", c.encoding = m.encoding || "hex", c.excludeValues = !!m.excludeValues, c.algorithm = c.algorithm.toLowerCase(), c.encoding = c.encoding.toLowerCase(), c.ignoreUnknown = m.ignoreUnknown === !0, c.respectType = m.respectType !== !1, c.respectFunctionNames = m.respectFunctionNames !== !1, c.respectFunctionProperties = m.respectFunctionProperties !== !1, c.unorderedArrays = m.unorderedArrays === !0, c.unorderedSets = m.unorderedSets !== !1, c.unorderedObjects = m.unorderedObjects !== !1, c.replacer = m.replacer || void 0, c.excludeKeys = m.excludeKeys || void 0, p === void 0) throw new Error("Object argument required.");
1099
+ for (var l = 0; l < _.length; ++l) _[l].toLowerCase() === c.algorithm.toLowerCase() && (c.algorithm = _[l]);
1100
+ if (_.indexOf(c.algorithm) === -1) throw new Error('Algorithm "' + c.algorithm + '" not supported. supported values: ' + _.join(", "));
1101
+ if (R.indexOf(c.encoding) === -1 && c.algorithm !== "passthrough") throw new Error('Encoding "' + c.encoding + '" not supported. supported values: ' + R.join(", "));
1102
+ return c;
1103
+ }
1104
+ function A(p) {
1105
+ if (typeof p == "function") return /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(p)) != null;
1106
+ }
1107
+ function b(p, m, c) {
1108
+ c = c || [];
1109
+ function l(o) {
1110
+ return m.update ? m.update(o, "utf8") : m.write(o, "utf8");
1111
+ }
1112
+ return { dispatch: function(o) {
1113
+ return this["_" + ((o = p.replacer ? p.replacer(o) : o) === null ? "null" : typeof o)](o);
1114
+ }, _object: function(o) {
1115
+ var g, w = Object.prototype.toString.call(o), P = /\[object (.*)\]/i.exec(w);
1116
+ if (P = (P = P ? P[1] : "unknown:[" + w + "]").toLowerCase(), 0 <= (w = c.indexOf(o))) return this.dispatch("[CIRCULAR:" + w + "]");
1117
+ if (c.push(o), d !== void 0 && d.isBuffer && d.isBuffer(o)) return l("buffer:"), l(o);
1118
+ if (P === "object" || P === "function" || P === "asyncfunction") return w = Object.keys(o), p.unorderedObjects && (w = w.sort()), p.respectType === !1 || A(o) || w.splice(0, 0, "prototype", "__proto__", "constructor"), p.excludeKeys && (w = w.filter(function(j) {
1119
+ return !p.excludeKeys(j);
1120
+ })), l("object:" + w.length + ":"), g = this, w.forEach(function(j) {
1121
+ g.dispatch(j), l(":"), p.excludeValues || g.dispatch(o[j]), l(",");
1122
+ });
1123
+ if (!this["_" + P]) {
1124
+ if (p.ignoreUnknown) return l("[" + P + "]");
1125
+ throw new Error('Unknown object type "' + P + '"');
1126
+ }
1127
+ this["_" + P](o);
1128
+ }, _array: function(o, j) {
1129
+ j = j !== void 0 ? j : p.unorderedArrays !== !1;
1130
+ var w = this;
1131
+ if (l("array:" + o.length + ":"), !j || o.length <= 1) return o.forEach(function(F) {
1132
+ return w.dispatch(F);
1133
+ });
1134
+ var P = [], j = o.map(function(F) {
1135
+ var q = new I(), H = c.slice();
1136
+ return b(p, q, H).dispatch(F), P = P.concat(H.slice(c.length)), q.read().toString();
1137
+ });
1138
+ return c = c.concat(P), j.sort(), this._array(j, !1);
1139
+ }, _date: function(o) {
1140
+ return l("date:" + o.toJSON());
1141
+ }, _symbol: function(o) {
1142
+ return l("symbol:" + o.toString());
1143
+ }, _error: function(o) {
1144
+ return l("error:" + o.toString());
1145
+ }, _boolean: function(o) {
1146
+ return l("bool:" + o.toString());
1147
+ }, _string: function(o) {
1148
+ l("string:" + o.length + ":"), l(o.toString());
1149
+ }, _function: function(o) {
1150
+ l("fn:"), A(o) ? this.dispatch("[native]") : this.dispatch(o.toString()), p.respectFunctionNames !== !1 && this.dispatch("function-name:" + String(o.name)), p.respectFunctionProperties && this._object(o);
1151
+ }, _number: function(o) {
1152
+ return l("number:" + o.toString());
1153
+ }, _xml: function(o) {
1154
+ return l("xml:" + o.toString());
1155
+ }, _null: function() {
1156
+ return l("Null");
1157
+ }, _undefined: function() {
1158
+ return l("Undefined");
1159
+ }, _regexp: function(o) {
1160
+ return l("regex:" + o.toString());
1161
+ }, _uint8array: function(o) {
1162
+ return l("uint8array:"), this.dispatch(Array.prototype.slice.call(o));
1163
+ }, _uint8clampedarray: function(o) {
1164
+ return l("uint8clampedarray:"), this.dispatch(Array.prototype.slice.call(o));
1165
+ }, _int8array: function(o) {
1166
+ return l("int8array:"), this.dispatch(Array.prototype.slice.call(o));
1167
+ }, _uint16array: function(o) {
1168
+ return l("uint16array:"), this.dispatch(Array.prototype.slice.call(o));
1169
+ }, _int16array: function(o) {
1170
+ return l("int16array:"), this.dispatch(Array.prototype.slice.call(o));
1171
+ }, _uint32array: function(o) {
1172
+ return l("uint32array:"), this.dispatch(Array.prototype.slice.call(o));
1173
+ }, _int32array: function(o) {
1174
+ return l("int32array:"), this.dispatch(Array.prototype.slice.call(o));
1175
+ }, _float32array: function(o) {
1176
+ return l("float32array:"), this.dispatch(Array.prototype.slice.call(o));
1177
+ }, _float64array: function(o) {
1178
+ return l("float64array:"), this.dispatch(Array.prototype.slice.call(o));
1179
+ }, _arraybuffer: function(o) {
1180
+ return l("arraybuffer:"), this.dispatch(new Uint8Array(o));
1181
+ }, _url: function(o) {
1182
+ return l("url:" + o.toString());
1183
+ }, _map: function(o) {
1184
+ return l("map:"), o = Array.from(o), this._array(o, p.unorderedSets !== !1);
1185
+ }, _set: function(o) {
1186
+ return l("set:"), o = Array.from(o), this._array(o, p.unorderedSets !== !1);
1187
+ }, _file: function(o) {
1188
+ return l("file:"), this.dispatch([o.name, o.size, o.type, o.lastModfied]);
1189
+ }, _blob: function() {
1190
+ if (p.ignoreUnknown) return l("[blob]");
1191
+ throw Error(`Hashing Blob objects is currently not supported
1192
+ (see https://github.com/puleos/object-hash/issues/26)
1193
+ Use "options.replacer" or "options.ignoreUnknown"
1194
+ `);
1195
+ }, _domwindow: function() {
1196
+ return l("domwindow");
1197
+ }, _bigint: function(o) {
1198
+ return l("bigint:" + o.toString());
1199
+ }, _process: function() {
1200
+ return l("process");
1201
+ }, _timer: function() {
1202
+ return l("timer");
1203
+ }, _pipe: function() {
1204
+ return l("pipe");
1205
+ }, _tcp: function() {
1206
+ return l("tcp");
1207
+ }, _udp: function() {
1208
+ return l("udp");
1209
+ }, _tty: function() {
1210
+ return l("tty");
1211
+ }, _statwatcher: function() {
1212
+ return l("statwatcher");
1213
+ }, _securecontext: function() {
1214
+ return l("securecontext");
1215
+ }, _connection: function() {
1216
+ return l("connection");
1217
+ }, _zlib: function() {
1218
+ return l("zlib");
1219
+ }, _context: function() {
1220
+ return l("context");
1221
+ }, _nodescript: function() {
1222
+ return l("nodescript");
1223
+ }, _httpparser: function() {
1224
+ return l("httpparser");
1225
+ }, _dataview: function() {
1226
+ return l("dataview");
1227
+ }, _signal: function() {
1228
+ return l("signal");
1229
+ }, _fsevent: function() {
1230
+ return l("fsevent");
1231
+ }, _tlswrap: function() {
1232
+ return l("tlswrap");
1233
+ } };
1234
+ }
1235
+ function I() {
1236
+ return { buf: "", write: function(p) {
1237
+ this.buf += p;
1238
+ }, end: function(p) {
1239
+ this.buf += p;
1240
+ }, read: function() {
1241
+ return this.buf;
1242
+ } };
1243
+ }
1244
+ r.writeToStream = function(p, m, c) {
1245
+ return c === void 0 && (c = m, m = {}), b(m = O(p, m), c).dispatch(p);
1246
+ };
1247
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/fake_9a5aa49d.js", "/");
1248
+ }, { buffer: 3, crypto: 5, lYpoI2: 11 }], 2: [function(n, s, r) {
1249
+ (function(a, f, d, h, E, $, N, D, M) {
1250
+ (function(S) {
1251
+ var C = typeof Uint8Array < "u" ? Uint8Array : Array, _ = 43, R = 47, O = 48, A = 97, b = 65, I = 45, p = 95;
1252
+ function m(c) {
1253
+ return c = c.charCodeAt(0), c === _ || c === I ? 62 : c === R || c === p ? 63 : c < O ? -1 : c < O + 10 ? c - O + 26 + 26 : c < b + 26 ? c - b : c < A + 26 ? c - A + 26 : void 0;
1254
+ }
1255
+ S.toByteArray = function(c) {
1256
+ var l, o;
1257
+ if (0 < c.length % 4) throw new Error("Invalid string. Length must be a multiple of 4");
1258
+ var g = c.length, g = c.charAt(g - 2) === "=" ? 2 : c.charAt(g - 1) === "=" ? 1 : 0, w = new C(3 * c.length / 4 - g), P = 0 < g ? c.length - 4 : c.length, j = 0;
1259
+ function F(q) {
1260
+ w[j++] = q;
1261
+ }
1262
+ for (l = 0; l < P; l += 4, 0) F((16711680 & (o = m(c.charAt(l)) << 18 | m(c.charAt(l + 1)) << 12 | m(c.charAt(l + 2)) << 6 | m(c.charAt(l + 3)))) >> 16), F((65280 & o) >> 8), F(255 & o);
1263
+ return g == 2 ? F(255 & (o = m(c.charAt(l)) << 2 | m(c.charAt(l + 1)) >> 4)) : g == 1 && (F((o = m(c.charAt(l)) << 10 | m(c.charAt(l + 1)) << 4 | m(c.charAt(l + 2)) >> 2) >> 8 & 255), F(255 & o)), w;
1264
+ }, S.fromByteArray = function(c) {
1265
+ var l, o, g, w, P = c.length % 3, j = "";
1266
+ function F(q) {
1267
+ return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(q);
1268
+ }
1269
+ for (l = 0, g = c.length - P; l < g; l += 3) o = (c[l] << 16) + (c[l + 1] << 8) + c[l + 2], j += F((w = o) >> 18 & 63) + F(w >> 12 & 63) + F(w >> 6 & 63) + F(63 & w);
1270
+ switch (P) {
1271
+ case 1:
1272
+ j = (j += F((o = c[c.length - 1]) >> 2)) + F(o << 4 & 63) + "==";
1273
+ break;
1274
+ case 2:
1275
+ j = (j = (j += F((o = (c[c.length - 2] << 8) + c[c.length - 1]) >> 10)) + F(o >> 4 & 63)) + F(o << 2 & 63) + "=";
1276
+ }
1277
+ return j;
1278
+ };
1279
+ })(r === void 0 ? this.base64js = {} : r);
1280
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js", "/node_modules/gulp-browserify/node_modules/base64-js/lib");
1281
+ }, { buffer: 3, lYpoI2: 11 }], 3: [function(n, s, r) {
1282
+ (function(a, f, _, h, E, $, N, D, M) {
1283
+ var S = n("base64-js"), C = n("ieee754");
1284
+ function _(i, u, y) {
1285
+ if (!(this instanceof _)) return new _(i, u, y);
1286
+ var L, v, B, W, X = typeof i;
1287
+ if (u === "base64" && X == "string") for (i = (W = i).trim ? W.trim() : W.replace(/^\s+|\s+$/g, ""); i.length % 4 != 0; ) i += "=";
1288
+ if (X == "number") L = se(i);
1289
+ else if (X == "string") L = _.byteLength(i, u);
1290
+ else {
1291
+ if (X != "object") throw new Error("First argument needs to be a number, array or string.");
1292
+ L = se(i.length);
1293
+ }
1294
+ if (_._useTypedArrays ? v = _._augment(new Uint8Array(L)) : ((v = this).length = L, v._isBuffer = !0), _._useTypedArrays && typeof i.byteLength == "number") v._set(i);
1295
+ else if (Q(W = i) || _.isBuffer(W) || W && typeof W == "object" && typeof W.length == "number") for (B = 0; B < L; B++) _.isBuffer(i) ? v[B] = i.readUInt8(B) : v[B] = i[B];
1296
+ else if (X == "string") v.write(i, 0, u);
1297
+ else if (X == "number" && !_._useTypedArrays && !y) for (B = 0; B < L; B++) v[B] = 0;
1298
+ return v;
1299
+ }
1300
+ function R(i, u, y, L) {
1301
+ return _._charsWritten = Re((function(v) {
1302
+ for (var B = [], W = 0; W < v.length; W++) B.push(255 & v.charCodeAt(W));
1303
+ return B;
1304
+ })(u), i, y, L);
1305
+ }
1306
+ function O(i, u, y, L) {
1307
+ return _._charsWritten = Re((function(v) {
1308
+ for (var B, W, X = [], ee = 0; ee < v.length; ee++) W = v.charCodeAt(ee), B = W >> 8, W = W % 256, X.push(W), X.push(B);
1309
+ return X;
1310
+ })(u), i, y, L);
1311
+ }
1312
+ function A(i, u, y) {
1313
+ var L = "";
1314
+ y = Math.min(i.length, y);
1315
+ for (var v = u; v < y; v++) L += String.fromCharCode(i[v]);
1316
+ return L;
1317
+ }
1318
+ function b(i, u, y, B) {
1319
+ B || (U(typeof y == "boolean", "missing or invalid endian"), U(u != null, "missing offset"), U(u + 1 < i.length, "Trying to read beyond buffer length"));
1320
+ var v, B = i.length;
1321
+ if (!(B <= u)) return y ? (v = i[u], u + 1 < B && (v |= i[u + 1] << 8)) : (v = i[u] << 8, u + 1 < B && (v |= i[u + 1])), v;
1322
+ }
1323
+ function I(i, u, y, B) {
1324
+ B || (U(typeof y == "boolean", "missing or invalid endian"), U(u != null, "missing offset"), U(u + 3 < i.length, "Trying to read beyond buffer length"));
1325
+ var v, B = i.length;
1326
+ if (!(B <= u)) return y ? (u + 2 < B && (v = i[u + 2] << 16), u + 1 < B && (v |= i[u + 1] << 8), v |= i[u], u + 3 < B && (v += i[u + 3] << 24 >>> 0)) : (u + 1 < B && (v = i[u + 1] << 16), u + 2 < B && (v |= i[u + 2] << 8), u + 3 < B && (v |= i[u + 3]), v += i[u] << 24 >>> 0), v;
1327
+ }
1328
+ function p(i, u, y, L) {
1329
+ if (L || (U(typeof y == "boolean", "missing or invalid endian"), U(u != null, "missing offset"), U(u + 1 < i.length, "Trying to read beyond buffer length")), !(i.length <= u)) return L = b(i, u, y, !0), 32768 & L ? -1 * (65535 - L + 1) : L;
1330
+ }
1331
+ function m(i, u, y, L) {
1332
+ if (L || (U(typeof y == "boolean", "missing or invalid endian"), U(u != null, "missing offset"), U(u + 3 < i.length, "Trying to read beyond buffer length")), !(i.length <= u)) return L = I(i, u, y, !0), 2147483648 & L ? -1 * (4294967295 - L + 1) : L;
1333
+ }
1334
+ function c(i, u, y, L) {
1335
+ return L || (U(typeof y == "boolean", "missing or invalid endian"), U(u + 3 < i.length, "Trying to read beyond buffer length")), C.read(i, u, y, 23, 4);
1336
+ }
1337
+ function l(i, u, y, L) {
1338
+ return L || (U(typeof y == "boolean", "missing or invalid endian"), U(u + 7 < i.length, "Trying to read beyond buffer length")), C.read(i, u, y, 52, 8);
1339
+ }
1340
+ function o(i, u, y, L, v) {
1341
+ if (v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 1 < i.length, "trying to write beyond buffer length"), He(u, 65535)), v = i.length, !(v <= y)) for (var B = 0, W = Math.min(v - y, 2); B < W; B++) i[y + B] = (u & 255 << 8 * (L ? B : 1 - B)) >>> 8 * (L ? B : 1 - B);
1342
+ }
1343
+ function g(i, u, y, L, v) {
1344
+ if (v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 3 < i.length, "trying to write beyond buffer length"), He(u, 4294967295)), v = i.length, !(v <= y)) for (var B = 0, W = Math.min(v - y, 4); B < W; B++) i[y + B] = u >>> 8 * (L ? B : 3 - B) & 255;
1345
+ }
1346
+ function w(i, u, y, L, v) {
1347
+ v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 1 < i.length, "Trying to write beyond buffer length"), Je(u, 32767, -32768)), i.length <= y || o(i, 0 <= u ? u : 65535 + u + 1, y, L, v);
1348
+ }
1349
+ function P(i, u, y, L, v) {
1350
+ v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 3 < i.length, "Trying to write beyond buffer length"), Je(u, 2147483647, -2147483648)), i.length <= y || g(i, 0 <= u ? u : 4294967295 + u + 1, y, L, v);
1351
+ }
1352
+ function j(i, u, y, L, v) {
1353
+ v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 3 < i.length, "Trying to write beyond buffer length"), At(u, 34028234663852886e22, -34028234663852886e22)), i.length <= y || C.write(i, u, y, L, 23, 4);
1354
+ }
1355
+ function F(i, u, y, L, v) {
1356
+ v || (U(u != null, "missing value"), U(typeof L == "boolean", "missing or invalid endian"), U(y != null, "missing offset"), U(y + 7 < i.length, "Trying to write beyond buffer length"), At(u, 17976931348623157e292, -17976931348623157e292)), i.length <= y || C.write(i, u, y, L, 52, 8);
1357
+ }
1358
+ r.Buffer = _, r.SlowBuffer = _, r.INSPECT_MAX_BYTES = 50, _.poolSize = 8192, _._useTypedArrays = (function() {
1359
+ try {
1360
+ var i = new ArrayBuffer(0), u = new Uint8Array(i);
1361
+ return u.foo = function() {
1362
+ return 42;
1363
+ }, u.foo() === 42 && typeof u.subarray == "function";
1364
+ } catch {
1365
+ return !1;
1366
+ }
1367
+ })(), _.isEncoding = function(i) {
1368
+ switch (String(i).toLowerCase()) {
1369
+ case "hex":
1370
+ case "utf8":
1371
+ case "utf-8":
1372
+ case "ascii":
1373
+ case "binary":
1374
+ case "base64":
1375
+ case "raw":
1376
+ case "ucs2":
1377
+ case "ucs-2":
1378
+ case "utf16le":
1379
+ case "utf-16le":
1380
+ return !0;
1381
+ default:
1382
+ return !1;
1383
+ }
1384
+ }, _.isBuffer = function(i) {
1385
+ return !(i == null || !i._isBuffer);
1386
+ }, _.byteLength = function(i, u) {
1387
+ var y;
1388
+ switch (i += "", u || "utf8") {
1389
+ case "hex":
1390
+ y = i.length / 2;
1391
+ break;
1392
+ case "utf8":
1393
+ case "utf-8":
1394
+ y = me(i).length;
1395
+ break;
1396
+ case "ascii":
1397
+ case "binary":
1398
+ case "raw":
1399
+ y = i.length;
1400
+ break;
1401
+ case "base64":
1402
+ y = bt(i).length;
1403
+ break;
1404
+ case "ucs2":
1405
+ case "ucs-2":
1406
+ case "utf16le":
1407
+ case "utf-16le":
1408
+ y = 2 * i.length;
1409
+ break;
1410
+ default:
1411
+ throw new Error("Unknown encoding");
1412
+ }
1413
+ return y;
1414
+ }, _.concat = function(i, u) {
1415
+ if (U(Q(i), `Usage: Buffer.concat(list, [totalLength])
1416
+ list should be an Array.`), i.length === 0) return new _(0);
1417
+ if (i.length === 1) return i[0];
1418
+ if (typeof u != "number") for (v = u = 0; v < i.length; v++) u += i[v].length;
1419
+ for (var y = new _(u), L = 0, v = 0; v < i.length; v++) {
1420
+ var B = i[v];
1421
+ B.copy(y, L), L += B.length;
1422
+ }
1423
+ return y;
1424
+ }, _.prototype.write = function(i, u, y, L) {
1425
+ isFinite(u) ? isFinite(y) || (L = y, y = void 0) : (ee = L, L = u, u = y, y = ee), u = Number(u) || 0;
1426
+ var v, B, W, X, ee = this.length - u;
1427
+ switch ((!y || ee < (y = Number(y))) && (y = ee), L = String(L || "utf8").toLowerCase()) {
1428
+ case "hex":
1429
+ v = (function(ye, le, ue, te) {
1430
+ ue = Number(ue) || 0;
1431
+ var z = ye.length - ue;
1432
+ (!te || z < (te = Number(te))) && (te = z), U((z = le.length) % 2 == 0, "Invalid hex string"), z / 2 < te && (te = z / 2);
1433
+ for (var Te = 0; Te < te; Te++) {
1434
+ var It = parseInt(le.substr(2 * Te, 2), 16);
1435
+ U(!isNaN(It), "Invalid hex string"), ye[ue + Te] = It;
1436
+ }
1437
+ return _._charsWritten = 2 * Te, Te;
1438
+ })(this, i, u, y);
1439
+ break;
1440
+ case "utf8":
1441
+ case "utf-8":
1442
+ B = this, W = u, X = y, v = _._charsWritten = Re(me(i), B, W, X);
1443
+ break;
1444
+ case "ascii":
1445
+ case "binary":
1446
+ v = R(this, i, u, y);
1447
+ break;
1448
+ case "base64":
1449
+ B = this, W = u, X = y, v = _._charsWritten = Re(bt(i), B, W, X);
1450
+ break;
1451
+ case "ucs2":
1452
+ case "ucs-2":
1453
+ case "utf16le":
1454
+ case "utf-16le":
1455
+ v = O(this, i, u, y);
1456
+ break;
1457
+ default:
1458
+ throw new Error("Unknown encoding");
1459
+ }
1460
+ return v;
1461
+ }, _.prototype.toString = function(i, u, y) {
1462
+ var L, v, B, W, X = this;
1463
+ if (i = String(i || "utf8").toLowerCase(), u = Number(u) || 0, (y = y !== void 0 ? Number(y) : X.length) === u) return "";
1464
+ switch (i) {
1465
+ case "hex":
1466
+ L = (function(ee, ye, le) {
1467
+ var ue = ee.length;
1468
+ (!ye || ye < 0) && (ye = 0), (!le || le < 0 || ue < le) && (le = ue);
1469
+ for (var te = "", z = ye; z < le; z++) te += V(ee[z]);
1470
+ return te;
1471
+ })(X, u, y);
1472
+ break;
1473
+ case "utf8":
1474
+ case "utf-8":
1475
+ L = (function(ee, ye, le) {
1476
+ var ue = "", te = "";
1477
+ le = Math.min(ee.length, le);
1478
+ for (var z = ye; z < le; z++) ee[z] <= 127 ? (ue += Tt(te) + String.fromCharCode(ee[z]), te = "") : te += "%" + ee[z].toString(16);
1479
+ return ue + Tt(te);
1480
+ })(X, u, y);
1481
+ break;
1482
+ case "ascii":
1483
+ case "binary":
1484
+ L = A(X, u, y);
1485
+ break;
1486
+ case "base64":
1487
+ v = X, W = y, L = (B = u) === 0 && W === v.length ? S.fromByteArray(v) : S.fromByteArray(v.slice(B, W));
1488
+ break;
1489
+ case "ucs2":
1490
+ case "ucs-2":
1491
+ case "utf16le":
1492
+ case "utf-16le":
1493
+ L = (function(ee, ye, le) {
1494
+ for (var ue = ee.slice(ye, le), te = "", z = 0; z < ue.length; z += 2) te += String.fromCharCode(ue[z] + 256 * ue[z + 1]);
1495
+ return te;
1496
+ })(X, u, y);
1497
+ break;
1498
+ default:
1499
+ throw new Error("Unknown encoding");
1500
+ }
1501
+ return L;
1502
+ }, _.prototype.toJSON = function() {
1503
+ return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
1504
+ }, _.prototype.copy = function(i, u, y, L) {
1505
+ if (u = u || 0, (L = L || L === 0 ? L : this.length) !== (y = y || 0) && i.length !== 0 && this.length !== 0) {
1506
+ U(y <= L, "sourceEnd < sourceStart"), U(0 <= u && u < i.length, "targetStart out of bounds"), U(0 <= y && y < this.length, "sourceStart out of bounds"), U(0 <= L && L <= this.length, "sourceEnd out of bounds"), L > this.length && (L = this.length);
1507
+ var v = (L = i.length - u < L - y ? i.length - u + y : L) - y;
1508
+ if (v < 100 || !_._useTypedArrays) for (var B = 0; B < v; B++) i[B + u] = this[B + y];
1509
+ else i._set(this.subarray(y, y + v), u);
1510
+ }
1511
+ }, _.prototype.slice = function(i, u) {
1512
+ var y = this.length;
1513
+ if (i = H(i, y, 0), u = H(u, y, y), _._useTypedArrays) return _._augment(this.subarray(i, u));
1514
+ for (var L = u - i, v = new _(L, void 0, !0), B = 0; B < L; B++) v[B] = this[B + i];
1515
+ return v;
1516
+ }, _.prototype.get = function(i) {
1517
+ return console.log(".get() is deprecated. Access using array indexes instead."), this.readUInt8(i);
1518
+ }, _.prototype.set = function(i, u) {
1519
+ return console.log(".set() is deprecated. Access using array indexes instead."), this.writeUInt8(i, u);
1520
+ }, _.prototype.readUInt8 = function(i, u) {
1521
+ if (u || (U(i != null, "missing offset"), U(i < this.length, "Trying to read beyond buffer length")), !(i >= this.length)) return this[i];
1522
+ }, _.prototype.readUInt16LE = function(i, u) {
1523
+ return b(this, i, !0, u);
1524
+ }, _.prototype.readUInt16BE = function(i, u) {
1525
+ return b(this, i, !1, u);
1526
+ }, _.prototype.readUInt32LE = function(i, u) {
1527
+ return I(this, i, !0, u);
1528
+ }, _.prototype.readUInt32BE = function(i, u) {
1529
+ return I(this, i, !1, u);
1530
+ }, _.prototype.readInt8 = function(i, u) {
1531
+ if (u || (U(i != null, "missing offset"), U(i < this.length, "Trying to read beyond buffer length")), !(i >= this.length)) return 128 & this[i] ? -1 * (255 - this[i] + 1) : this[i];
1532
+ }, _.prototype.readInt16LE = function(i, u) {
1533
+ return p(this, i, !0, u);
1534
+ }, _.prototype.readInt16BE = function(i, u) {
1535
+ return p(this, i, !1, u);
1536
+ }, _.prototype.readInt32LE = function(i, u) {
1537
+ return m(this, i, !0, u);
1538
+ }, _.prototype.readInt32BE = function(i, u) {
1539
+ return m(this, i, !1, u);
1540
+ }, _.prototype.readFloatLE = function(i, u) {
1541
+ return c(this, i, !0, u);
1542
+ }, _.prototype.readFloatBE = function(i, u) {
1543
+ return c(this, i, !1, u);
1544
+ }, _.prototype.readDoubleLE = function(i, u) {
1545
+ return l(this, i, !0, u);
1546
+ }, _.prototype.readDoubleBE = function(i, u) {
1547
+ return l(this, i, !1, u);
1548
+ }, _.prototype.writeUInt8 = function(i, u, y) {
1549
+ y || (U(i != null, "missing value"), U(u != null, "missing offset"), U(u < this.length, "trying to write beyond buffer length"), He(i, 255)), u >= this.length || (this[u] = i);
1550
+ }, _.prototype.writeUInt16LE = function(i, u, y) {
1551
+ o(this, i, u, !0, y);
1552
+ }, _.prototype.writeUInt16BE = function(i, u, y) {
1553
+ o(this, i, u, !1, y);
1554
+ }, _.prototype.writeUInt32LE = function(i, u, y) {
1555
+ g(this, i, u, !0, y);
1556
+ }, _.prototype.writeUInt32BE = function(i, u, y) {
1557
+ g(this, i, u, !1, y);
1558
+ }, _.prototype.writeInt8 = function(i, u, y) {
1559
+ y || (U(i != null, "missing value"), U(u != null, "missing offset"), U(u < this.length, "Trying to write beyond buffer length"), Je(i, 127, -128)), u >= this.length || (0 <= i ? this.writeUInt8(i, u, y) : this.writeUInt8(255 + i + 1, u, y));
1560
+ }, _.prototype.writeInt16LE = function(i, u, y) {
1561
+ w(this, i, u, !0, y);
1562
+ }, _.prototype.writeInt16BE = function(i, u, y) {
1563
+ w(this, i, u, !1, y);
1564
+ }, _.prototype.writeInt32LE = function(i, u, y) {
1565
+ P(this, i, u, !0, y);
1566
+ }, _.prototype.writeInt32BE = function(i, u, y) {
1567
+ P(this, i, u, !1, y);
1568
+ }, _.prototype.writeFloatLE = function(i, u, y) {
1569
+ j(this, i, u, !0, y);
1570
+ }, _.prototype.writeFloatBE = function(i, u, y) {
1571
+ j(this, i, u, !1, y);
1572
+ }, _.prototype.writeDoubleLE = function(i, u, y) {
1573
+ F(this, i, u, !0, y);
1574
+ }, _.prototype.writeDoubleBE = function(i, u, y) {
1575
+ F(this, i, u, !1, y);
1576
+ }, _.prototype.fill = function(i, u, y) {
1577
+ if (u = u || 0, y = y || this.length, U(typeof (i = typeof (i = i || 0) == "string" ? i.charCodeAt(0) : i) == "number" && !isNaN(i), "value is not a number"), U(u <= y, "end < start"), y !== u && this.length !== 0) {
1578
+ U(0 <= u && u < this.length, "start out of bounds"), U(0 <= y && y <= this.length, "end out of bounds");
1579
+ for (var L = u; L < y; L++) this[L] = i;
1580
+ }
1581
+ }, _.prototype.inspect = function() {
1582
+ for (var i = [], u = this.length, y = 0; y < u; y++) if (i[y] = V(this[y]), y === r.INSPECT_MAX_BYTES) {
1583
+ i[y + 1] = "...";
1584
+ break;
1585
+ }
1586
+ return "<Buffer " + i.join(" ") + ">";
1587
+ }, _.prototype.toArrayBuffer = function() {
1588
+ if (typeof Uint8Array > "u") throw new Error("Buffer.toArrayBuffer not supported in this browser");
1589
+ if (_._useTypedArrays) return new _(this).buffer;
1590
+ for (var i = new Uint8Array(this.length), u = 0, y = i.length; u < y; u += 1) i[u] = this[u];
1591
+ return i.buffer;
1592
+ };
1593
+ var q = _.prototype;
1594
+ function H(i, u, y) {
1595
+ return typeof i != "number" ? y : u <= (i = ~~i) ? u : 0 <= i || 0 <= (i += u) ? i : 0;
1596
+ }
1597
+ function se(i) {
1598
+ return (i = ~~Math.ceil(+i)) < 0 ? 0 : i;
1599
+ }
1600
+ function Q(i) {
1601
+ return (Array.isArray || function(u) {
1602
+ return Object.prototype.toString.call(u) === "[object Array]";
1603
+ })(i);
1604
+ }
1605
+ function V(i) {
1606
+ return i < 16 ? "0" + i.toString(16) : i.toString(16);
1607
+ }
1608
+ function me(i) {
1609
+ for (var u = [], y = 0; y < i.length; y++) {
1610
+ var L = i.charCodeAt(y);
1611
+ if (L <= 127) u.push(i.charCodeAt(y));
1612
+ else for (var v = y, B = (55296 <= L && L <= 57343 && y++, encodeURIComponent(i.slice(v, y + 1)).substr(1).split("%")), W = 0; W < B.length; W++) u.push(parseInt(B[W], 16));
1613
+ }
1614
+ return u;
1615
+ }
1616
+ function bt(i) {
1617
+ return S.toByteArray(i);
1618
+ }
1619
+ function Re(i, u, y, L) {
1620
+ for (var v = 0; v < L && !(v + y >= u.length || v >= i.length); v++) u[v + y] = i[v];
1621
+ return v;
1622
+ }
1623
+ function Tt(i) {
1624
+ try {
1625
+ return decodeURIComponent(i);
1626
+ } catch {
1627
+ return "�";
1628
+ }
1629
+ }
1630
+ function He(i, u) {
1631
+ U(typeof i == "number", "cannot write a non-number as a number"), U(0 <= i, "specified a negative value for writing an unsigned value"), U(i <= u, "value is larger than maximum value for type"), U(Math.floor(i) === i, "value has a fractional component");
1632
+ }
1633
+ function Je(i, u, y) {
1634
+ U(typeof i == "number", "cannot write a non-number as a number"), U(i <= u, "value larger than maximum allowed value"), U(y <= i, "value smaller than minimum allowed value"), U(Math.floor(i) === i, "value has a fractional component");
1635
+ }
1636
+ function At(i, u, y) {
1637
+ U(typeof i == "number", "cannot write a non-number as a number"), U(i <= u, "value larger than maximum allowed value"), U(y <= i, "value smaller than minimum allowed value");
1638
+ }
1639
+ function U(i, u) {
1640
+ if (!i) throw new Error(u || "Failed assertion");
1641
+ }
1642
+ _._augment = function(i) {
1643
+ return i._isBuffer = !0, i._get = i.get, i._set = i.set, i.get = q.get, i.set = q.set, i.write = q.write, i.toString = q.toString, i.toLocaleString = q.toString, i.toJSON = q.toJSON, i.copy = q.copy, i.slice = q.slice, i.readUInt8 = q.readUInt8, i.readUInt16LE = q.readUInt16LE, i.readUInt16BE = q.readUInt16BE, i.readUInt32LE = q.readUInt32LE, i.readUInt32BE = q.readUInt32BE, i.readInt8 = q.readInt8, i.readInt16LE = q.readInt16LE, i.readInt16BE = q.readInt16BE, i.readInt32LE = q.readInt32LE, i.readInt32BE = q.readInt32BE, i.readFloatLE = q.readFloatLE, i.readFloatBE = q.readFloatBE, i.readDoubleLE = q.readDoubleLE, i.readDoubleBE = q.readDoubleBE, i.writeUInt8 = q.writeUInt8, i.writeUInt16LE = q.writeUInt16LE, i.writeUInt16BE = q.writeUInt16BE, i.writeUInt32LE = q.writeUInt32LE, i.writeUInt32BE = q.writeUInt32BE, i.writeInt8 = q.writeInt8, i.writeInt16LE = q.writeInt16LE, i.writeInt16BE = q.writeInt16BE, i.writeInt32LE = q.writeInt32LE, i.writeInt32BE = q.writeInt32BE, i.writeFloatLE = q.writeFloatLE, i.writeFloatBE = q.writeFloatBE, i.writeDoubleLE = q.writeDoubleLE, i.writeDoubleBE = q.writeDoubleBE, i.fill = q.fill, i.inspect = q.inspect, i.toArrayBuffer = q.toArrayBuffer, i;
1644
+ };
1645
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/buffer/index.js", "/node_modules/gulp-browserify/node_modules/buffer");
1646
+ }, { "base64-js": 2, buffer: 3, ieee754: 10, lYpoI2: 11 }], 4: [function(n, s, r) {
1647
+ (function(a, f, S, h, E, $, N, D, M) {
1648
+ var S = n("buffer").Buffer, C = 4, _ = new S(C);
1649
+ _.fill(0), s.exports = { hash: function(R, O, A, b) {
1650
+ for (var I = O((function(o, g) {
1651
+ o.length % C != 0 && (w = o.length + (C - o.length % C), o = S.concat([o, _], w));
1652
+ for (var w, P = [], j = g ? o.readInt32BE : o.readInt32LE, F = 0; F < o.length; F += C) P.push(j.call(o, F));
1653
+ return P;
1654
+ })(R = S.isBuffer(R) ? R : new S(R), b), 8 * R.length), O = b, p = new S(A), m = O ? p.writeInt32BE : p.writeInt32LE, c = 0; c < I.length; c++) m.call(p, I[c], 4 * c, !0);
1655
+ return p;
1656
+ } };
1657
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1658
+ }, { buffer: 3, lYpoI2: 11 }], 5: [function(n, s, r) {
1659
+ (function(a, f, S, h, E, $, N, D, M) {
1660
+ var S = n("buffer").Buffer, C = n("./sha"), _ = n("./sha256"), R = n("./rng"), O = { sha1: C, sha256: _, md5: n("./md5") }, A = 64, b = new S(A);
1661
+ function I(o, g) {
1662
+ var w = O[o = o || "sha1"], P = [];
1663
+ return w || p("algorithm:", o, "is not yet supported"), { update: function(j) {
1664
+ return S.isBuffer(j) || (j = new S(j)), P.push(j), j.length, this;
1665
+ }, digest: function(j) {
1666
+ var F = S.concat(P), F = g ? (function(q, H, se) {
1667
+ S.isBuffer(H) || (H = new S(H)), S.isBuffer(se) || (se = new S(se)), H.length > A ? H = q(H) : H.length < A && (H = S.concat([H, b], A));
1668
+ for (var Q = new S(A), V = new S(A), me = 0; me < A; me++) Q[me] = 54 ^ H[me], V[me] = 92 ^ H[me];
1669
+ return se = q(S.concat([Q, se])), q(S.concat([V, se]));
1670
+ })(w, g, F) : w(F);
1671
+ return P = null, j ? F.toString(j) : F;
1672
+ } };
1673
+ }
1674
+ function p() {
1675
+ var o = [].slice.call(arguments).join(" ");
1676
+ throw new Error([o, "we accept pull requests", "http://github.com/dominictarr/crypto-browserify"].join(`
1677
+ `));
1678
+ }
1679
+ b.fill(0), r.createHash = function(o) {
1680
+ return I(o);
1681
+ }, r.createHmac = I, r.randomBytes = function(o, g) {
1682
+ if (!g || !g.call) return new S(R(o));
1683
+ try {
1684
+ g.call(this, void 0, new S(R(o)));
1685
+ } catch (w) {
1686
+ g(w);
1687
+ }
1688
+ };
1689
+ var m, c = ["createCredentials", "createCipher", "createCipheriv", "createDecipher", "createDecipheriv", "createSign", "createVerify", "createDiffieHellman", "pbkdf2"], l = function(o) {
1690
+ r[o] = function() {
1691
+ p("sorry,", o, "is not implemented yet");
1692
+ };
1693
+ };
1694
+ for (m in c) l(c[m]);
1695
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1696
+ }, { "./md5": 6, "./rng": 7, "./sha": 8, "./sha256": 9, buffer: 3, lYpoI2: 11 }], 6: [function(n, s, r) {
1697
+ (function(a, f, d, h, E, $, N, D, M) {
1698
+ var S = n("./helpers");
1699
+ function C(p, m) {
1700
+ p[m >> 5] |= 128 << m % 32, p[14 + (m + 64 >>> 9 << 4)] = m;
1701
+ for (var c = 1732584193, l = -271733879, o = -1732584194, g = 271733878, w = 0; w < p.length; w += 16) {
1702
+ var P = c, j = l, F = o, q = g, c = R(c, l, o, g, p[w + 0], 7, -680876936), g = R(g, c, l, o, p[w + 1], 12, -389564586), o = R(o, g, c, l, p[w + 2], 17, 606105819), l = R(l, o, g, c, p[w + 3], 22, -1044525330);
1703
+ c = R(c, l, o, g, p[w + 4], 7, -176418897), g = R(g, c, l, o, p[w + 5], 12, 1200080426), o = R(o, g, c, l, p[w + 6], 17, -1473231341), l = R(l, o, g, c, p[w + 7], 22, -45705983), c = R(c, l, o, g, p[w + 8], 7, 1770035416), g = R(g, c, l, o, p[w + 9], 12, -1958414417), o = R(o, g, c, l, p[w + 10], 17, -42063), l = R(l, o, g, c, p[w + 11], 22, -1990404162), c = R(c, l, o, g, p[w + 12], 7, 1804603682), g = R(g, c, l, o, p[w + 13], 12, -40341101), o = R(o, g, c, l, p[w + 14], 17, -1502002290), c = O(c, l = R(l, o, g, c, p[w + 15], 22, 1236535329), o, g, p[w + 1], 5, -165796510), g = O(g, c, l, o, p[w + 6], 9, -1069501632), o = O(o, g, c, l, p[w + 11], 14, 643717713), l = O(l, o, g, c, p[w + 0], 20, -373897302), c = O(c, l, o, g, p[w + 5], 5, -701558691), g = O(g, c, l, o, p[w + 10], 9, 38016083), o = O(o, g, c, l, p[w + 15], 14, -660478335), l = O(l, o, g, c, p[w + 4], 20, -405537848), c = O(c, l, o, g, p[w + 9], 5, 568446438), g = O(g, c, l, o, p[w + 14], 9, -1019803690), o = O(o, g, c, l, p[w + 3], 14, -187363961), l = O(l, o, g, c, p[w + 8], 20, 1163531501), c = O(c, l, o, g, p[w + 13], 5, -1444681467), g = O(g, c, l, o, p[w + 2], 9, -51403784), o = O(o, g, c, l, p[w + 7], 14, 1735328473), c = A(c, l = O(l, o, g, c, p[w + 12], 20, -1926607734), o, g, p[w + 5], 4, -378558), g = A(g, c, l, o, p[w + 8], 11, -2022574463), o = A(o, g, c, l, p[w + 11], 16, 1839030562), l = A(l, o, g, c, p[w + 14], 23, -35309556), c = A(c, l, o, g, p[w + 1], 4, -1530992060), g = A(g, c, l, o, p[w + 4], 11, 1272893353), o = A(o, g, c, l, p[w + 7], 16, -155497632), l = A(l, o, g, c, p[w + 10], 23, -1094730640), c = A(c, l, o, g, p[w + 13], 4, 681279174), g = A(g, c, l, o, p[w + 0], 11, -358537222), o = A(o, g, c, l, p[w + 3], 16, -722521979), l = A(l, o, g, c, p[w + 6], 23, 76029189), c = A(c, l, o, g, p[w + 9], 4, -640364487), g = A(g, c, l, o, p[w + 12], 11, -421815835), o = A(o, g, c, l, p[w + 15], 16, 530742520), c = b(c, l = A(l, o, g, c, p[w + 2], 23, -995338651), o, g, p[w + 0], 6, -198630844), g = b(g, c, l, o, p[w + 7], 10, 1126891415), o = b(o, g, c, l, p[w + 14], 15, -1416354905), l = b(l, o, g, c, p[w + 5], 21, -57434055), c = b(c, l, o, g, p[w + 12], 6, 1700485571), g = b(g, c, l, o, p[w + 3], 10, -1894986606), o = b(o, g, c, l, p[w + 10], 15, -1051523), l = b(l, o, g, c, p[w + 1], 21, -2054922799), c = b(c, l, o, g, p[w + 8], 6, 1873313359), g = b(g, c, l, o, p[w + 15], 10, -30611744), o = b(o, g, c, l, p[w + 6], 15, -1560198380), l = b(l, o, g, c, p[w + 13], 21, 1309151649), c = b(c, l, o, g, p[w + 4], 6, -145523070), g = b(g, c, l, o, p[w + 11], 10, -1120210379), o = b(o, g, c, l, p[w + 2], 15, 718787259), l = b(l, o, g, c, p[w + 9], 21, -343485551), c = I(c, P), l = I(l, j), o = I(o, F), g = I(g, q);
1704
+ }
1705
+ return Array(c, l, o, g);
1706
+ }
1707
+ function _(p, m, c, l, o, g) {
1708
+ return I((m = I(I(m, p), I(l, g))) << o | m >>> 32 - o, c);
1709
+ }
1710
+ function R(p, m, c, l, o, g, w) {
1711
+ return _(m & c | ~m & l, p, m, o, g, w);
1712
+ }
1713
+ function O(p, m, c, l, o, g, w) {
1714
+ return _(m & l | c & ~l, p, m, o, g, w);
1715
+ }
1716
+ function A(p, m, c, l, o, g, w) {
1717
+ return _(m ^ c ^ l, p, m, o, g, w);
1718
+ }
1719
+ function b(p, m, c, l, o, g, w) {
1720
+ return _(c ^ (m | ~l), p, m, o, g, w);
1721
+ }
1722
+ function I(p, m) {
1723
+ var c = (65535 & p) + (65535 & m);
1724
+ return (p >> 16) + (m >> 16) + (c >> 16) << 16 | 65535 & c;
1725
+ }
1726
+ s.exports = function(p) {
1727
+ return S.hash(p, C, 16);
1728
+ };
1729
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1730
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 7: [function(n, s, r) {
1731
+ (function(a, f, d, h, E, $, N, D, M) {
1732
+ s.exports = function(S) {
1733
+ for (var C, _ = new Array(S), R = 0; R < S; R++) (3 & R) == 0 && (C = 4294967296 * Math.random()), _[R] = C >>> ((3 & R) << 3) & 255;
1734
+ return _;
1735
+ };
1736
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1737
+ }, { buffer: 3, lYpoI2: 11 }], 8: [function(n, s, r) {
1738
+ (function(a, f, d, h, E, $, N, D, M) {
1739
+ var S = n("./helpers");
1740
+ function C(O, A) {
1741
+ O[A >> 5] |= 128 << 24 - A % 32, O[15 + (A + 64 >> 9 << 4)] = A;
1742
+ for (var b, I, p, m = Array(80), c = 1732584193, l = -271733879, o = -1732584194, g = 271733878, w = -1009589776, P = 0; P < O.length; P += 16) {
1743
+ for (var j = c, F = l, q = o, H = g, se = w, Q = 0; Q < 80; Q++) {
1744
+ m[Q] = Q < 16 ? O[P + Q] : R(m[Q - 3] ^ m[Q - 8] ^ m[Q - 14] ^ m[Q - 16], 1);
1745
+ var V = _(_(R(c, 5), (V = l, I = o, p = g, (b = Q) < 20 ? V & I | ~V & p : !(b < 40) && b < 60 ? V & I | V & p | I & p : V ^ I ^ p)), _(_(w, m[Q]), (b = Q) < 20 ? 1518500249 : b < 40 ? 1859775393 : b < 60 ? -1894007588 : -899497514)), w = g, g = o, o = R(l, 30), l = c, c = V;
1746
+ }
1747
+ c = _(c, j), l = _(l, F), o = _(o, q), g = _(g, H), w = _(w, se);
1748
+ }
1749
+ return Array(c, l, o, g, w);
1750
+ }
1751
+ function _(O, A) {
1752
+ var b = (65535 & O) + (65535 & A);
1753
+ return (O >> 16) + (A >> 16) + (b >> 16) << 16 | 65535 & b;
1754
+ }
1755
+ function R(O, A) {
1756
+ return O << A | O >>> 32 - A;
1757
+ }
1758
+ s.exports = function(O) {
1759
+ return S.hash(O, C, 20, !0);
1760
+ };
1761
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1762
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 9: [function(n, s, r) {
1763
+ (function(a, f, d, h, E, $, N, D, M) {
1764
+ function S(A, b) {
1765
+ var I = (65535 & A) + (65535 & b);
1766
+ return (A >> 16) + (b >> 16) + (I >> 16) << 16 | 65535 & I;
1767
+ }
1768
+ function C(A, b) {
1769
+ var I, p = new Array(1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298), m = new Array(1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225), c = new Array(64);
1770
+ A[b >> 5] |= 128 << 24 - b % 32, A[15 + (b + 64 >> 9 << 4)] = b;
1771
+ for (var l, o, g = 0; g < A.length; g += 16) {
1772
+ for (var w = m[0], P = m[1], j = m[2], F = m[3], q = m[4], H = m[5], se = m[6], Q = m[7], V = 0; V < 64; V++) c[V] = V < 16 ? A[V + g] : S(S(S((o = c[V - 2], R(o, 17) ^ R(o, 19) ^ O(o, 10)), c[V - 7]), (o = c[V - 15], R(o, 7) ^ R(o, 18) ^ O(o, 3))), c[V - 16]), I = S(S(S(S(Q, R(o = q, 6) ^ R(o, 11) ^ R(o, 25)), q & H ^ ~q & se), p[V]), c[V]), l = S(R(l = w, 2) ^ R(l, 13) ^ R(l, 22), w & P ^ w & j ^ P & j), Q = se, se = H, H = q, q = S(F, I), F = j, j = P, P = w, w = S(I, l);
1773
+ m[0] = S(w, m[0]), m[1] = S(P, m[1]), m[2] = S(j, m[2]), m[3] = S(F, m[3]), m[4] = S(q, m[4]), m[5] = S(H, m[5]), m[6] = S(se, m[6]), m[7] = S(Q, m[7]);
1774
+ }
1775
+ return m;
1776
+ }
1777
+ var _ = n("./helpers"), R = function(A, b) {
1778
+ return A >>> b | A << 32 - b;
1779
+ }, O = function(A, b) {
1780
+ return A >>> b;
1781
+ };
1782
+ s.exports = function(A) {
1783
+ return _.hash(A, C, 32, !0);
1784
+ };
1785
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js", "/node_modules/gulp-browserify/node_modules/crypto-browserify");
1786
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 10: [function(n, s, r) {
1787
+ (function(a, f, d, h, E, $, N, D, M) {
1788
+ r.read = function(S, C, _, R, g) {
1789
+ var A, b, I = 8 * g - R - 1, p = (1 << I) - 1, m = p >> 1, c = -7, l = _ ? g - 1 : 0, o = _ ? -1 : 1, g = S[C + l];
1790
+ for (l += o, A = g & (1 << -c) - 1, g >>= -c, c += I; 0 < c; A = 256 * A + S[C + l], l += o, c -= 8) ;
1791
+ for (b = A & (1 << -c) - 1, A >>= -c, c += R; 0 < c; b = 256 * b + S[C + l], l += o, c -= 8) ;
1792
+ if (A === 0) A = 1 - m;
1793
+ else {
1794
+ if (A === p) return b ? NaN : 1 / 0 * (g ? -1 : 1);
1795
+ b += Math.pow(2, R), A -= m;
1796
+ }
1797
+ return (g ? -1 : 1) * b * Math.pow(2, A - R);
1798
+ }, r.write = function(S, C, _, R, O, w) {
1799
+ var b, I, p = 8 * w - O - 1, m = (1 << p) - 1, c = m >> 1, l = O === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, o = R ? 0 : w - 1, g = R ? 1 : -1, w = C < 0 || C === 0 && 1 / C < 0 ? 1 : 0;
1800
+ for (C = Math.abs(C), isNaN(C) || C === 1 / 0 ? (I = isNaN(C) ? 1 : 0, b = m) : (b = Math.floor(Math.log(C) / Math.LN2), C * (R = Math.pow(2, -b)) < 1 && (b--, R *= 2), 2 <= (C += 1 <= b + c ? l / R : l * Math.pow(2, 1 - c)) * R && (b++, R /= 2), m <= b + c ? (I = 0, b = m) : 1 <= b + c ? (I = (C * R - 1) * Math.pow(2, O), b += c) : (I = C * Math.pow(2, c - 1) * Math.pow(2, O), b = 0)); 8 <= O; S[_ + o] = 255 & I, o += g, I /= 256, O -= 8) ;
1801
+ for (b = b << O | I, p += O; 0 < p; S[_ + o] = 255 & b, o += g, b /= 256, p -= 8) ;
1802
+ S[_ + o - g] |= 128 * w;
1803
+ };
1804
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/ieee754/index.js", "/node_modules/gulp-browserify/node_modules/ieee754");
1805
+ }, { buffer: 3, lYpoI2: 11 }], 11: [function(n, s, r) {
1806
+ (function(a, f, d, h, E, $, N, D, M) {
1807
+ var S, C, _;
1808
+ function R() {
1809
+ }
1810
+ (a = s.exports = {}).nextTick = (C = typeof window < "u" && window.setImmediate, _ = typeof window < "u" && window.postMessage && window.addEventListener, C ? function(O) {
1811
+ return window.setImmediate(O);
1812
+ } : _ ? (S = [], window.addEventListener("message", function(O) {
1813
+ var A = O.source;
1814
+ A !== window && A !== null || O.data !== "process-tick" || (O.stopPropagation(), 0 < S.length && S.shift()());
1815
+ }, !0), function(O) {
1816
+ S.push(O), window.postMessage("process-tick", "*");
1817
+ }) : function(O) {
1818
+ setTimeout(O, 0);
1819
+ }), a.title = "browser", a.browser = !0, a.env = {}, a.argv = [], a.on = R, a.addListener = R, a.once = R, a.off = R, a.removeListener = R, a.removeAllListeners = R, a.emit = R, a.binding = function(O) {
1820
+ throw new Error("process.binding is not supported");
1821
+ }, a.cwd = function() {
1822
+ return "/";
1823
+ }, a.chdir = function(O) {
1824
+ throw new Error("process.chdir is not supported");
1825
+ };
1826
+ }).call(this, n("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, n("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/node_modules/gulp-browserify/node_modules/process/browser.js", "/node_modules/gulp-browserify/node_modules/process");
1827
+ }, { buffer: 3, lYpoI2: 11 }] }, {}, [1])(1);
1828
+ });
1829
+ })(ze)), ze.exports;
1830
+ }
1831
+ var ai = ii();
1832
+ const zn = /* @__PURE__ */ si(ai), Zn = (e, t) => {
1833
+ const n = oe(e), s = t.map((r) => `'${r.id}'`).join(",");
1834
+ return `DELETE FROM ${n} WHERE id IN (${s});`;
1835
+ }, Ue = (e, t, n) => {
1836
+ const s = oe(e), r = n?.userId && e.propertyMap.has("createdBy"), a = n?.userId && e.propertyMap.has("updatedBy"), f = [...e.propertyMap.keys(), ...e.foreignKeyNames], d = [];
1837
+ t.forEach((E) => {
1838
+ const $ = sn(e, E);
1839
+ r && ($.createdBy = n.userId), a && ($.updatedBy = n.userId);
1840
+ const N = dt(e, $), D = [];
1841
+ f.forEach((M) => {
1842
+ const S = N[M];
1843
+ D.push(pt(S));
1844
+ }), d.push(`(${D.join(",")})`);
1845
+ });
1846
+ const h = f.map((E) => `"${E}"`).join(",");
1847
+ return `INSERT INTO ${s} (${h}) VALUES ${d.join(",")};`;
1848
+ }, oi = (e) => {
1849
+ const t = e.indexOf("$");
1850
+ return t === -1 ? ["", e] : [e.substring(0, t), e.substring(t + 1)];
1851
+ }, ci = (e) => {
1852
+ switch (e) {
1853
+ case Ee.INSERT:
1854
+ return "INSERT";
1855
+ case Ee.UPDATE:
1856
+ return "UPDATE";
1857
+ case Ee.DELETE:
1858
+ return "DELETE";
1859
+ }
1860
+ }, li = (e, t) => {
1861
+ t.forEach((r) => {
1862
+ const a = e.rxdb.schemaManager.getEntityMetadata(r.entity, r.namespace);
1863
+ a ? (r.inversePatch && $t(a, r.inversePatch), r.patch && $t(a, r.patch)) : console.warn(`Entity metadata not found for ${r.namespace}.${r.entity}`);
1864
+ });
1865
+ const n = Object.groupBy(t, (r) => r.type), s = Object.entries(n);
1866
+ for (let r = 0; r < s.length; r++) {
1867
+ const [a, f] = s[r];
1868
+ if (!f || f.length === 0) continue;
1869
+ const d = f.map(
1870
+ (h) => ({
1871
+ namespace: h.namespace,
1872
+ entity: h.entity,
1873
+ type: h.type,
1874
+ id: h.entityId,
1875
+ patch: h.patch,
1876
+ inversePatch: h.inversePatch,
1877
+ recordAt: h.createdAt
1878
+ })
1879
+ );
1880
+ switch (a) {
1881
+ case "INSERT":
1882
+ e.rxdb.dispatchEvent(new et(d));
1883
+ break;
1884
+ case "UPDATE":
1885
+ e.rxdb.dispatchEvent(new Kt(d));
1886
+ break;
1887
+ case "DELETE":
1888
+ e.rxdb.dispatchEvent(new Xt(d));
1889
+ break;
1890
+ }
1891
+ }
1892
+ }, Ze = (e, t) => {
1893
+ const { tableName: n } = t, [s, r] = oi(n), a = e.rxdb.schemaManager.getEntityType(r, s);
1894
+ if (!a) return;
1895
+ const f = e.getRepository(a), d = e.rxdb.schemaManager.getEntityMetadata(r, s);
1896
+ if (!d) {
1897
+ console.warn(`Metadata not found for entity ${s}.${r}`);
1898
+ return;
1899
+ }
1900
+ f.findByRowIds(t.rowIds).then((h) => {
1901
+ const E = h;
1902
+ if (!(!E || E.length === 0))
1903
+ if (a === ht) {
1904
+ if (li(e, h), t.type === Ee.INSERT) {
1905
+ const $ = h.map((N) => ({
1906
+ namespace: d.namespace,
1907
+ entity: d.name,
1908
+ type: N.type,
1909
+ id: N.id,
1910
+ patch: { ...N },
1911
+ inversePatch: null,
1912
+ recordAt: N.createdAt || /* @__PURE__ */ new Date()
1913
+ }));
1914
+ e.rxdb.dispatchEvent(new et($));
1915
+ }
1916
+ } else {
1917
+ const $ = ci(t.type), N = E.map((D) => {
1918
+ const M = {
1919
+ namespace: d.namespace,
1920
+ entity: d.name,
1921
+ type: $,
1922
+ id: D.id,
1923
+ patch: null,
1924
+ inversePatch: null,
1925
+ recordAt: D.createdAt || /* @__PURE__ */ new Date()
1926
+ };
1927
+ switch (t.type) {
1928
+ case Ee.INSERT:
1929
+ return {
1930
+ ...M,
1931
+ patch: { ...D }
1932
+ };
1933
+ case Ee.DELETE:
1934
+ return {
1935
+ ...M,
1936
+ inversePatch: { ...D }
1937
+ };
1938
+ case Ee.UPDATE:
1939
+ return {
1940
+ ...M,
1941
+ // 注意:这里无法获取变更前的数据,只能把整个 entity 作为 patch
1942
+ // 这是 UPDATE hook 的限制,完整的 patch/inversePatch 应该从 RxDBChange 表获取
1943
+ inversePatch: null,
1944
+ patch: { ...D }
1945
+ };
1946
+ }
1947
+ });
1948
+ switch ($) {
1949
+ case "UPDATE":
1950
+ e.rxdb.dispatchEvent(
1951
+ new Kt(N)
1952
+ );
1953
+ break;
1954
+ case "DELETE":
1955
+ e.rxdb.dispatchEvent(
1956
+ new Xt(N)
1957
+ );
1958
+ break;
1959
+ case "INSERT":
1960
+ e.rxdb.dispatchEvent(
1961
+ new et(N)
1962
+ );
1963
+ break;
1964
+ }
1965
+ }
1966
+ }).catch((h) => {
1967
+ console.error("Failed to handle RxDBChange event", h);
1968
+ });
1969
+ }, ui = (e, t) => {
1970
+ const n = oe(e), s = [t.id];
1971
+ return {
1972
+ sql: `DELETE FROM ${n} WHERE id = $1;`,
1973
+ params: s
1974
+ };
1975
+ }, fi = (e, t, n) => {
1976
+ const s = oe(e), r = sn(e, t);
1977
+ n?.userId && (e.propertyMap.has("createdBy") && (r.createdBy = n.userId), e.propertyMap.has("updatedBy") && (r.updatedBy = n.userId));
1978
+ const a = {};
1979
+ Object.keys(r).forEach((D) => {
1980
+ const M = r[D];
1981
+ M != null && (a[D] = M);
1982
+ });
1983
+ const f = Object.keys(a), d = dt(e, a), h = [], E = f.map((D, M) => (h.push(d[D]), `$${M + 1}`)), $ = f.map((D) => `"${D}"`).join(",");
1984
+ let N = `INSERT INTO ${s} (${$}) VALUES (${E.join(",")})`;
1985
+ return n?.returning !== !1 ? N += " RETURNING *;" : N += ";", { sql: N, params: h };
1986
+ }, er = (e, t, n, s) => {
1987
+ const r = mr(e, n);
1988
+ e.propertyMap.has("updatedAt") && (r.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && e.propertyMap.has("updatedBy") && (r.updatedBy = s.userId);
1989
+ const a = dt(e, r), d = Object.keys(r).map((D, M) => `"${D}" = $${M + 1}`).join(","), h = [...Object.values(a)], E = oe(e), $ = Array.isArray(t) ? t : [t];
1990
+ let N = `UPDATE ${E} SET ${d} WHERE id `;
1991
+ if (Array.isArray(t)) {
1992
+ const D = h.length + 1;
1993
+ N += `= ANY($${D})`, h.push($.map((M) => M.id));
1994
+ } else {
1995
+ const D = h.length + 1;
1996
+ N += `= $${D}`, h.push(t.id);
1997
+ }
1998
+ return s?.returning !== !1 ? N += " RETURNING *;" : N += ";", {
1999
+ sql: N,
2000
+ params: h
2001
+ };
2002
+ }, mt = "_", tr = (e) => e.replaceAll(".", "_"), Be = (e, t) => {
2003
+ if (e.relationAliasMap.has(t)) return e.relationAliasMap.get(t);
2004
+ const n = t.includes("_") ? t : t.split("_")[0], s = rr(e, tr(n));
2005
+ return e.relationAliasMap.set(t, s), s;
2006
+ }, hi = (e, t, n, s) => {
2007
+ const r = n.slice(0, s);
2008
+ let a = t;
2009
+ const f = [];
2010
+ for (const d of r) {
2011
+ if (!a?.relationMap.has(d)) return { relPairs: [] };
2012
+ const h = a.relationMap.get(d);
2013
+ f.push({ metadata: a, relation: h }), a = e.rxdb.schemaManager.getEntityMetadata(h.mappedEntity, h.mappedNamespace);
2014
+ }
2015
+ return { metaWalker: a, relPairs: f };
2016
+ }, di = (e, t, n, s, r) => {
2017
+ for (let a = r.length - 1; a > 0; a--) {
2018
+ const f = r.slice(a);
2019
+ if (f.length === 0) continue;
2020
+ const { metaWalker: d, relPairs: h } = hi(e, n, r, a);
2021
+ if (!d || h.length === 0) continue;
2022
+ const E = f[0], $ = f.slice(1).join("."), N = d.propertyMap.get(E);
2023
+ if (N && N.type === k.keyValue) {
2024
+ const D = r.slice(0, a).join(".");
2025
+ nr(e, t, h, D);
2026
+ const M = h[h.length - 1].relation, S = je(h, D, M), C = Be(t, S), _ = $ ? `$.${$}` : "$";
2027
+ return t.fieldAliasMap.set(s, `"${C}"."${E}" ->> '${_.replace("$.", "")}'`), !0;
2028
+ }
2029
+ }
2030
+ return !1;
2031
+ }, nr = (e, t, n, s) => {
2032
+ n.forEach(({ metadata: r, relation: a }, f) => {
2033
+ const d = e.rxdb.schemaManager.findMappedRelation(r, a);
2034
+ if (!d) throw new ce("mappedRelation not found");
2035
+ const h = je(n, s, a), E = Be(t, h);
2036
+ let $ = mt;
2037
+ if (f > 0) {
2038
+ const N = n[f - 1], D = je(n, s, N.relation);
2039
+ $ = Be(t, D);
2040
+ }
2041
+ switch (a.kind) {
2042
+ case _e.ONE_TO_MANY:
2043
+ pi(t, d, E, $);
2044
+ break;
2045
+ case _e.ONE_TO_ONE:
2046
+ case _e.MANY_TO_ONE:
2047
+ yi(t, d, E, $, a);
2048
+ break;
2049
+ case _e.MANY_TO_MANY:
2050
+ gi(e, t, d, E, $, a);
2051
+ break;
2052
+ }
2053
+ });
2054
+ }, pi = (e, t, n, s) => {
2055
+ const r = qe(e, t.metadata), a = `${t.relation.name}Id`;
2056
+ r.push({
2057
+ joinTableName: n,
2058
+ on: `"${n}"."${a}" = ${_t(s)}."id"`
2059
+ });
2060
+ }, yi = (e, t, n, s, r) => {
2061
+ qe(e, t.metadata).push({
2062
+ joinTableName: n,
2063
+ on: `"${n}"."id" = ${_t(s)}."${r.name}Id"`
2064
+ });
2065
+ }, gi = (e, t, n, s, r, a) => {
2066
+ const f = re(a.junctionEntityType), d = qe(t, f), h = rr(t, tr(`${a.name}_m_n`));
2067
+ d.push({
2068
+ joinTableName: h,
2069
+ on: `"${h}"."${n.relation.name}Id" = ${_t(r)}."id"`
2070
+ }), qe(t, n.metadata).push({
2071
+ joinTableName: s,
2072
+ on: `"${s}"."id" = "${h}"."${a.name}Id"`
2073
+ });
2074
+ }, qe = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), rr = (e, t) => {
2075
+ let n = t, s = 1;
2076
+ for (; e.usedAliases.has(n); )
2077
+ n = `${t}_${s++}`;
2078
+ return e.usedAliases.add(n), n;
2079
+ }, je = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, _t = (e) => e === mt ? e : `"${e}"`, sr = (e, t, n) => {
2080
+ const s = {
2081
+ joinMap: /* @__PURE__ */ new Map(),
2082
+ usedAliases: /* @__PURE__ */ new Set(),
2083
+ fieldAliasMap: /* @__PURE__ */ new Map(),
2084
+ relationAliasMap: /* @__PURE__ */ new Map()
2085
+ };
2086
+ ur(n, (a, f, d) => {
2087
+ const h = f;
2088
+ a !== "field" || !h.includes(".") || Ei(e, s, t, h, d);
2089
+ });
2090
+ const r = [];
2091
+ for (const [a, f] of s.joinMap.entries()) {
2092
+ const d = oe(a);
2093
+ for (const h of f)
2094
+ r.push(` LEFT JOIN ${d} "${h.joinTableName}" ON ${h.on}`);
2095
+ }
2096
+ return { joinSQL: r.join(""), fieldAliasMap: s.fieldAliasMap };
2097
+ }, Ei = (e, t, n, s, r) => {
2098
+ const a = s.split(".");
2099
+ try {
2100
+ const E = e.rxdb.schemaManager.getFieldRelations(n, s);
2101
+ if (E.isForeignKey) {
2102
+ r.field = E.propertyName;
2103
+ return;
2104
+ }
2105
+ const $ = s.replace(`.${E.propertyName}`, "");
2106
+ nr(e, t, E.relations, $);
2107
+ const N = E.relations[E.relations.length - 1], D = je(E.relations, $, N.relation), M = Be(t, D);
2108
+ t.fieldAliasMap.set(s, `"${M}"."${E.propertyName}"`);
2109
+ return;
2110
+ } catch {
2111
+ }
2112
+ const [f, ...d] = a, h = n.propertyMap.get(f);
2113
+ if (h && h.type === k.keyValue && d.length > 0) {
2114
+ const E = d.join(".");
2115
+ t.fieldAliasMap.set(s, `"${mt}"."${f}" ->> '${E}'`);
2116
+ return;
2117
+ }
2118
+ di(e, t, n, s, a);
2119
+ }, xe = "_", mi = {
2120
+ "=": "=",
2121
+ "!=": "!=",
2122
+ ">": ">",
2123
+ ">=": ">=",
2124
+ "<": "<",
2125
+ "<=": "<=",
2126
+ in: "IN",
2127
+ notIn: "NOT IN",
2128
+ between: "BETWEEN",
2129
+ notBetween: "NOT BETWEEN",
2130
+ contains: "LIKE",
2131
+ notContains: "NOT LIKE",
2132
+ startsWith: "LIKE",
2133
+ notStartsWith: "NOT LIKE",
2134
+ endsWith: "LIKE",
2135
+ notEndsWith: "NOT LIKE"
2136
+ }, _i = (e) => {
2137
+ if (e?.length)
2138
+ return e.map((t) => `${xe}."${t.field}" ${t.sort.toUpperCase()}`).join(", ");
2139
+ }, wi = (e) => mi[e] || e, bi = (e) => e && typeof e == "object" && "rules" in e && Array.isArray(e.rules), Ti = (e, t, n) => {
2140
+ if (t) return t;
2141
+ if (!e.includes("."))
2142
+ return e.toLowerCase() !== e ? `"${e}"` : e;
2143
+ const s = e.split("."), r = s[0], a = n?.propertyMap.get(r);
2144
+ if (a && (a.type === k.json || a.type === k.keyValue) && s.length === 2)
2145
+ return `"${r}" ->> '${s[1]}'`;
2146
+ const f = e.lastIndexOf(".");
2147
+ return `"${e.slice(0, f)}".${e.slice(f + 1)}`;
2148
+ }, Ai = (e, t, n = /* @__PURE__ */ new Map(), s) => {
2149
+ const r = String(e.field), a = n.get(r), f = Ti(r, a, s), d = e.value, h = e.operator;
2150
+ if (d === null)
2151
+ return h === "=" ? `${f} IS NULL` : h === "!=" ? `${f} IS NOT NULL` : "";
2152
+ let E = r;
2153
+ a && r.includes(".") && (E = r.split(".").pop() || r);
2154
+ const $ = s?.propertyMap.get(E.split(".")[0]);
2155
+ if ($ && ($.type === k.json || $.type === k.keyValue)) {
2156
+ if (h === "contains" && typeof d == "object" && !Array.isArray(d))
2157
+ return t.push(JSON.stringify(d)), `${f} @> $${t.length}::jsonb`;
2158
+ if (h === "notContains" && typeof d == "object" && !Array.isArray(d))
2159
+ return t.push(JSON.stringify(d)), `NOT (${f} @> $${t.length}::jsonb)`;
109
2160
  }
110
- #e = new y((e) => {
111
- const t = new D();
112
- t.init(this.rxdb.options.dbName, this.options).then(() => e.next(t));
113
- }).pipe(w(1));
2161
+ if ($ && ($.type === k.stringArray || $.type === k.numberArray) && (h === "in" || h === "notIn")) {
2162
+ if (!Array.isArray(d)) return "";
2163
+ t.push(JSON.stringify(d));
2164
+ const D = `${f} @> $${t.length}::jsonb`;
2165
+ return h === "notIn" ? `NOT ${D}` : D;
2166
+ }
2167
+ if (h === "in" || h === "notIn")
2168
+ return Array.isArray(d) ? d.length === 0 ? h === "in" ? "1=0" : "1=1" : (t.push(d), `${f} ${h === "in" ? "= ANY" : "!= ALL"}($${t.length})`) : "";
2169
+ if (h === "between" || h === "notBetween")
2170
+ return !Array.isArray(d) || d.length !== 2 ? "" : (t.push(d[0], d[1]), `${f} ${h === "between" ? "BETWEEN" : "NOT BETWEEN"} $${t.length - 1} AND $${t.length}`);
2171
+ if (["contains", "notContains", "startsWith", "notStartsWith", "endsWith", "notEndsWith"].includes(h)) {
2172
+ let D = "";
2173
+ h === "contains" || h === "notContains" ? D = `%${d}%` : h === "startsWith" || h === "notStartsWith" ? D = `${d}%` : (h === "endsWith" || h === "notEndsWith") && (D = `%${d}`), t.push(D);
2174
+ const M = h.startsWith("not") ? "NOT LIKE" : "LIKE";
2175
+ return `${f} ${M} $${t.length}`;
2176
+ }
2177
+ const N = wi(h);
2178
+ return t.push(d), $ && $.type === k.uuid ? `${f}::uuid ${N} $${t.length}::uuid` : `${f} ${N} $${t.length}`;
2179
+ }, Ye = (e, t, n = /* @__PURE__ */ new Map(), s) => {
2180
+ const r = e.rules.map(
2181
+ (f) => bi(f) ? Ye(f, t, n, s) : Ai(f, t, n, s)
2182
+ ).filter(Boolean);
2183
+ if (!r.length) return "";
2184
+ if (r.length === 1) return r[0];
2185
+ const a = e.combinator.toUpperCase();
2186
+ return `(${r.join(` ${a} `)})`;
2187
+ }, Ii = (e, t) => {
2188
+ let n = `SELECT ${xe}.* FROM ${e.tableName} AS ${xe}`;
2189
+ return e.join && (n += ` ${e.join}`), e.where && (n += ` WHERE ${e.where}`), e.orderBy && (n += ` ORDER BY ${e.orderBy}`), e.limit !== void 0 && (t.push(e.limit), n += ` LIMIT $${t.length}`), e.offset !== void 0 && e.offset > 0 && (t.push(e.offset), n += ` OFFSET $${t.length}`), n;
2190
+ }, $i = (e) => {
2191
+ let t = `SELECT COUNT(*) as count FROM ${e.tableName} AS ${xe}`;
2192
+ return e.join && (t += ` ${e.join}`), e.where && (t += ` WHERE ${e.where}`), t;
2193
+ }, Pe = (e, t, n) => {
2194
+ const s = oe(t), r = [], { joinSQL: a, fieldAliasMap: f } = n.where ? sr(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, d = n.where ? Ye(n.where, r, f, t) : void 0, h = _i(n.orderBy), E = "limit" in n ? n.limit : void 0, $ = "offset" in n ? n.offset : void 0;
2195
+ return { sql: Ii(
2196
+ {
2197
+ tableName: s,
2198
+ where: d,
2199
+ join: a,
2200
+ orderBy: h,
2201
+ limit: E,
2202
+ offset: $
2203
+ },
2204
+ r
2205
+ ), params: r };
2206
+ }, Si = (e, t, n) => {
2207
+ if (n.groupBy)
2208
+ throw new ce("groupBy not supported in count queries");
2209
+ const s = oe(t), r = [], { joinSQL: a, fieldAliasMap: f } = n.where ? sr(e, t, n.where) : { joinSQL: "", fieldAliasMap: /* @__PURE__ */ new Map() }, d = n.where ? Ye(n.where, r, f, t) : void 0;
2210
+ return { sql: $i({
2211
+ tableName: s,
2212
+ where: d,
2213
+ join: a
2214
+ }), params: r };
2215
+ }, Ni = (e, t) => {
2216
+ const n = oe(e), s = t.map((a, f) => `$${f + 1}`).join(", ");
2217
+ return {
2218
+ sql: `SELECT * FROM ${n} WHERE id IN (${s})`,
2219
+ params: t
2220
+ };
2221
+ };
2222
+ class Ri extends or {
2223
+ constructor(t, n) {
2224
+ super(t.rxdb, n), this.adapter = t, this.metadata = re(n);
2225
+ }
2226
+ metadata;
114
2227
  /**
115
- * 数据库版本
2228
+ * 通过行 ID 列表查询实体
2229
+ * 用于 handle_rxdb_change 中根据 NOTIFY 事件的 rowIds 查询实体
2230
+ *
2231
+ * @param rowIds - 行 ID 数组(string | number)
2232
+ * @returns 实体数组
116
2233
  */
117
- version$ = this.#e.pipe(
118
- m((e) => f(e.version())),
119
- w(1)
2234
+ async findByRowIds(t) {
2235
+ if (t.length === 0) return [];
2236
+ const { sql: n, params: s } = Ni(this.metadata, t), r = await this.adapter.query(n, s);
2237
+ return this.addQueryCache(r);
2238
+ }
2239
+ addQueryCache(t, n = !1) {
2240
+ return t.rows.map((s) => {
2241
+ const r = Ne(this.metadata, s), a = r.id;
2242
+ let f;
2243
+ super.hasEntityRef(a) ? (f = super.getEntityRef(a), n && super.updateEntity(f, r)) : f = this.createEntityRef(r);
2244
+ const d = be(f);
2245
+ return d.local = !0, d.modified = !1, f;
2246
+ });
2247
+ }
2248
+ }
2249
+ class ir extends Ri {
2250
+ async get(t) {
2251
+ const n = {
2252
+ where: {
2253
+ combinator: "and",
2254
+ rules: [{ field: "id", operator: "=", value: t }]
2255
+ }
2256
+ }, s = await this.findOne(n);
2257
+ if (!s) throw new ce(`Entity (${t}) not found`);
2258
+ return s;
2259
+ }
2260
+ async findOne(t) {
2261
+ return (await this.find({ ...t, limit: 1, offset: 0 }))[0];
2262
+ }
2263
+ async find(t) {
2264
+ const { sql: n, params: s } = Pe(this.adapter, this.metadata, t), r = await this.adapter.query(n, s);
2265
+ return this.addQueryCache(r);
2266
+ }
2267
+ async findAll(t) {
2268
+ const { sql: n, params: s } = Pe(this.adapter, this.metadata, t), r = await this.adapter.query(n, s);
2269
+ return this.addQueryCache(r);
2270
+ }
2271
+ async count(t) {
2272
+ const { sql: n, params: s } = Si(this.adapter, this.metadata, t), r = await this.adapter.query(n, s);
2273
+ return parseInt(r.rows[0].count);
2274
+ }
2275
+ async create(t) {
2276
+ const { sql: n, params: s } = fi(this.metadata, t, this.rxdb.context), r = await this.adapter.query(n, s);
2277
+ return this.addQueryCache(r, !0), t;
2278
+ }
2279
+ async update(t, n) {
2280
+ Object.assign(t, n);
2281
+ const { sql: s, params: r } = er(this.metadata, t, n, this.rxdb.context);
2282
+ return await this.adapter.query(s, r), t;
2283
+ }
2284
+ async remove(t) {
2285
+ const { sql: n, params: s } = ui(this.metadata, t);
2286
+ return await this.adapter.query(n, s), t;
2287
+ }
2288
+ }
2289
+ const Ve = (e, t, n) => {
2290
+ const { isCount: s, isFindDescendants: r, entityId: a, where: f } = n, d = !a, h = oe(t);
2291
+ let E = "";
2292
+ const N = [`c.level < ${n.level || 0}`], D = [];
2293
+ if (d || D.push(a), f) {
2294
+ const R = /* @__PURE__ */ new Map(), O = (b) => {
2295
+ if ("rules" in b)
2296
+ return { ...b, rules: b.rules.map(O) };
2297
+ if (b.field && typeof b.field == "string" && b.field.startsWith("children.")) {
2298
+ const I = b.field.substring(9);
2299
+ R.set(b.field, `children."${I}"`);
2300
+ }
2301
+ return b;
2302
+ };
2303
+ O(f);
2304
+ const A = Ye(f, D, R, t);
2305
+ A && N.push(A);
2306
+ }
2307
+ const M = N.filter(Boolean).join(" AND ");
2308
+ M && (E = `WHERE ${M}`);
2309
+ let S = "*";
2310
+ return s && (d ? S = "count(*) AS count" : S = "(count(*) - 1) AS count"), {
2311
+ sql: `WITH RECURSIVE __children AS (
2312
+ SELECT *, 0 AS level
2313
+ FROM ${h}
2314
+ WHERE ${d ? '"parentId" IS NULL' : "id = $1"}
2315
+ UNION ALL
2316
+ SELECT children.*, c.level + 1 AS level
2317
+ FROM ${h} children
2318
+ JOIN __children c ON ${r ? 'children."parentId"::uuid = c.id::uuid' : 'children.id::uuid = c."parentId"::uuid'}
2319
+ ${E}
2320
+ )
2321
+
2322
+ SELECT ${S} FROM __children${s ? "" : " ORDER BY level, id"};`,
2323
+ params: D
2324
+ };
2325
+ }, vi = (e, t, n) => Ve(e, t, { ...n, isFindDescendants: !0 }), Li = (e, t, n) => Ve(e, t, { ...n, isFindDescendants: !0, isCount: !0 }), Oi = (e, t, n) => Ve(e, t, { ...n, isFindDescendants: !1 }), Di = (e, t, n) => Ve(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
2326
+ class Ci extends ir {
2327
+ async findDescendants(t) {
2328
+ const { sql: n, params: s } = vi(this.adapter, this.metadata, t), r = await this.adapter.query(n, s);
2329
+ return !r.rows || r.rows.length === 0 ? [] : r.rows.map((f) => {
2330
+ const d = Ne(this.metadata, f);
2331
+ return this.createEntityRef(d);
2332
+ });
2333
+ }
2334
+ async countDescendants(t) {
2335
+ const { sql: n, params: s } = Li(this.adapter, this.metadata, t), a = (await this.adapter.query(n, s)).rows[0], f = a.count || a["?column?"];
2336
+ return parseInt(String(f), 10) || 0;
2337
+ }
2338
+ async findAncestors(t) {
2339
+ const { sql: n, params: s } = Oi(this.adapter, this.metadata, t), r = await this.adapter.query(n, s);
2340
+ return !r.rows || r.rows.length === 0 ? [] : r.rows.map((f) => {
2341
+ const d = Ne(this.metadata, f);
2342
+ return this.createEntityRef(d);
2343
+ });
2344
+ }
2345
+ async countAncestors(t) {
2346
+ const { sql: n, params: s } = Di(this.adapter, this.metadata, t), a = (await this.adapter.query(n, s)).rows[0], f = a.count || a["?column?"];
2347
+ return parseInt(String(f), 10) || 0;
2348
+ }
2349
+ }
2350
+ const Mi = async (e, t, n) => {
2351
+ const s = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Date();
2352
+ for (const [a, f] of t.create.entries()) {
2353
+ const d = Array.from(f);
2354
+ d.forEach((C) => s.add(C));
2355
+ const h = re(a), E = Ue(h, d, e.rxdb.context);
2356
+ await e.query(E);
2357
+ const $ = d.map((C) => C.id), { sql: N, params: D } = Pe(e, h, {
2358
+ where: { combinator: "and", rules: [{ field: "id", operator: "in", value: $ }] }
2359
+ }), M = await e.query(N, D), S = e.getRepository(a);
2360
+ for (const C of M.rows) {
2361
+ const _ = Ne(h, C), R = _.id;
2362
+ if (S.hasEntityRef(R)) {
2363
+ const O = S.getEntityRef(R);
2364
+ S.updateEntity(O, _);
2365
+ const A = be(O);
2366
+ A.local = !0, A.modified = !1;
2367
+ }
2368
+ }
2369
+ }
2370
+ for (const [a, f] of t.update.entries()) {
2371
+ const d = Array.from(f);
2372
+ d.forEach((N) => s.add(N));
2373
+ const h = re(a), E = Object.groupBy(d, (N) => {
2374
+ const D = be(N);
2375
+ return zn(Object.keys(D.patch || {}).sort());
2376
+ }), $ = e.getRepository(a);
2377
+ for (const N of Object.values(E)) {
2378
+ if (!N || N.length === 0) continue;
2379
+ const D = N[0], M = be(D), { sql: S, params: C } = er(h, N, M.patch || {}, {
2380
+ ...e.rxdb.context,
2381
+ returning: !1,
2382
+ // 后续用 SELECT 获取
2383
+ updatedAt: r
2384
+ });
2385
+ await e.query(S, C);
2386
+ const _ = N.map((A) => A.id), R = Pe(e, h, {
2387
+ where: { combinator: "and", rules: [{ field: "id", operator: "in", value: _ }] }
2388
+ }), O = await e.query(R.sql, R.params);
2389
+ for (const A of O.rows) {
2390
+ const b = Ne(h, A), I = b.id;
2391
+ if ($.hasEntityRef(I)) {
2392
+ const p = $.getEntityRef(I);
2393
+ $.updateEntity(p, b);
2394
+ const m = be(p);
2395
+ m.local = !0, m.modified = !1;
2396
+ }
2397
+ }
2398
+ }
2399
+ }
2400
+ for (const [, a] of t.remove.entries()) {
2401
+ const f = Array.from(a), d = re(f[0]?.constructor);
2402
+ if (f.length > 0) {
2403
+ const h = Zn(d, f);
2404
+ await e.query(h);
2405
+ }
2406
+ for (const h of f) {
2407
+ s.add(h);
2408
+ const E = be(h);
2409
+ E.origin = structuredClone({ ...h }), E.modified = !1, E.removed = !0, E.local = !1;
2410
+ }
2411
+ }
2412
+ return Array.from(s);
2413
+ }, Ui = (e, t) => {
2414
+ const n = oe(t);
2415
+ let s = `CREATE TABLE ${n} (`;
2416
+ const r = [], a = [], f = [];
2417
+ t.propertyMap.forEach((h) => {
2418
+ let E = "";
2419
+ E += `"${h.name}"`;
2420
+ const $ = nn(h);
2421
+ if (h.primary ? h.type === k.integer ? E += " serial PRIMARY KEY" : E += ` ${$} PRIMARY KEY` : E += ` ${$}`, Reflect.get(h, "default") !== void 0) {
2422
+ let N = h.default;
2423
+ en(h.default) && (N = h.default()), fr(N) ? ["CURRENT_TIMESTAMP", "now()"].includes(N) ? E += " DEFAULT now()" : E += ` DEFAULT '${N}'` : N instanceof Date ? E += ` DEFAULT '${N.toISOString()}'` : typeof N == "boolean" || typeof N == "number" ? E += ` DEFAULT ${String(N)}` : E += ` DEFAULT '${String(N)}'`;
2424
+ }
2425
+ h.nullable || (E += " NOT NULL"), h.unique && r.push(
2426
+ `CREATE UNIQUE INDEX "${rn(t, h)}" on ${n} ("${h.name}" ${gr(h)});`
2427
+ ), f.push(E);
2428
+ });
2429
+ const d = [...f, ...a];
2430
+ if (d.length)
2431
+ s += d.map((h) => `
2432
+ ${h}`).join(","), s += `
2433
+ );`;
2434
+ else
2435
+ throw new ce("columns is empty!");
2436
+ return r.length && (s += `
2437
+ ` + r.join(`
2438
+ `)), s;
2439
+ }, Bi = (e, t) => {
2440
+ let n = "";
2441
+ const s = oe(t);
2442
+ return t.indexes && t.indexes.length > 0 && t.indexes.forEach((r) => {
2443
+ const a = `idx_${t.name}_${r.name}`, f = r.properties?.map((h) => `"${h}"`).join(", ") || `"${r.name}"`, d = r.unique ? "UNIQUE " : "";
2444
+ n += `
2445
+ CREATE ${d}INDEX "${a}" ON ${s}(${f});`;
2446
+ }), n;
2447
+ }, qi = (e, t) => {
2448
+ let n = "";
2449
+ const s = oe(t);
2450
+ return Array.from(t.relationMap.values()).forEach((r) => {
2451
+ switch (r.kind) {
2452
+ case _e.ONE_TO_ONE:
2453
+ case _e.MANY_TO_ONE:
2454
+ {
2455
+ const a = `${r.name}Id`;
2456
+ let f = "uuid";
2457
+ if (r.mappedEntity)
2458
+ try {
2459
+ const h = e.rxdb.schemaManager.getEntityMetadata(
2460
+ r.mappedEntity,
2461
+ r.mappedNamespace
2462
+ );
2463
+ if (h) {
2464
+ const E = Array.from(h.propertyMap.values()).find(
2465
+ ($) => $.primary
2466
+ );
2467
+ E && (f = nn(E));
2468
+ }
2469
+ } catch {
2470
+ }
2471
+ if (n += `
2472
+ ALTER TABLE ${s} ADD COLUMN "${a}" ${f}`, r.nullable || (n += " NOT NULL"), r.kind === _e.MANY_TO_ONE && Reflect.get(r, "default") !== void 0) {
2473
+ const h = r;
2474
+ let E = h.default;
2475
+ en(h.default) && (E = h.default()), n += ` DEFAULT '${E}'`;
2476
+ }
2477
+ n += ";";
2478
+ const d = r.mappedEntity === t.name;
2479
+ if (r.mappedEntity && !d) {
2480
+ const h = tn(r.mappedEntity, r.mappedNamespace || t.namespace), E = `${s}_${a}_fk`.replace(/"/g, "");
2481
+ n += `
2482
+ ALTER TABLE ${s} ADD CONSTRAINT "${E}" FOREIGN KEY ("${a}") REFERENCES ${h}(id)`, r.onDelete ? n += ` ON DELETE ${r.onDelete}` : r.kind === _e.MANY_TO_ONE && (r.nullable ? n += " ON DELETE SET NULL" : n += " ON DELETE CASCADE"), n += " DEFERRABLE INITIALLY DEFERRED", n += ";";
2483
+ }
2484
+ (r.unique || r.kind === _e.ONE_TO_ONE) && (n += `
2485
+ CREATE UNIQUE INDEX "${rn(t, r)}" ON ${s}("${a}");`);
2486
+ }
2487
+ break;
2488
+ }
2489
+ }), n;
2490
+ }, ar = (e, t) => {
2491
+ let n = "";
2492
+ return n += Ui(e, t), n += qi(e, t), n += Bi(e, t), n;
2493
+ };
2494
+ function ji() {
2495
+ return `
2496
+ -- 创建触发器函数(如果不存在)
2497
+ CREATE OR REPLACE FUNCTION notify_change()
2498
+ RETURNS TRIGGER AS $$
2499
+ DECLARE
2500
+ payload JSON;
2501
+ notification_channel TEXT;
2502
+ row_id TEXT;
2503
+ BEGIN
2504
+ -- 确定通知频道名称:表名_notify
2505
+ notification_channel := TG_TABLE_NAME || '_notify';
2506
+
2507
+ -- 获取受影响行的 ID
2508
+ IF TG_OP = 'DELETE' THEN
2509
+ row_id := OLD.id;
2510
+ ELSE
2511
+ row_id := NEW.id;
2512
+ END IF;
2513
+
2514
+ -- 构建 JSON payload
2515
+ payload := json_build_object(
2516
+ 'operation', TG_OP,
2517
+ 'table', TG_TABLE_NAME,
2518
+ 'ids', json_build_array(row_id)
120
2519
  );
121
- name = C;
122
- saveMany(e) {
123
- throw new Error("Method not implemented.");
2520
+
2521
+ -- 发送 NOTIFY
2522
+ PERFORM pg_notify(notification_channel, payload::text);
2523
+
2524
+ -- 触发器必须返回行
2525
+ IF TG_OP = 'DELETE' THEN
2526
+ RETURN OLD;
2527
+ ELSE
2528
+ RETURN NEW;
2529
+ END IF;
2530
+ END;
2531
+ $$ LANGUAGE plpgsql;
2532
+ `.trim();
2533
+ }
2534
+ function xi(e) {
2535
+ const t = `${e}_notify_trigger`;
2536
+ return `
2537
+ -- 只在表存在时创建触发器
2538
+ DO $$
2539
+ BEGIN
2540
+ IF EXISTS (
2541
+ SELECT FROM pg_tables
2542
+ WHERE schemaname = 'public'
2543
+ AND tablename = '${e}'
2544
+ ) THEN
2545
+ -- 删除旧触发器(如果存在)
2546
+ DROP TRIGGER IF EXISTS "${t}" ON "${e}";
2547
+
2548
+ -- 创建触发器
2549
+ CREATE TRIGGER "${t}"
2550
+ AFTER INSERT OR UPDATE OR DELETE
2551
+ ON "${e}"
2552
+ FOR EACH ROW
2553
+ EXECUTE FUNCTION notify_change();
2554
+ END IF;
2555
+ END $$;
2556
+ `.trim();
2557
+ }
2558
+ function zi(e) {
2559
+ return `DROP TRIGGER IF EXISTS "${`${e}_notify_trigger`}" ON "${e}";`;
2560
+ }
2561
+ function Pi(e = ["public$RxDBChange", "public$RxDBBranch", "public$RxDBMigration"]) {
2562
+ const t = [];
2563
+ t.push(ji());
2564
+ for (const n of e)
2565
+ t.push(xi(n));
2566
+ return t.join(`
2567
+
2568
+ `);
2569
+ }
2570
+ function wt(e, t = {}) {
2571
+ const n = oe(e), s = re(ht), r = oe(s), { propertyMap: a, name: f, foreignKeyNames: d, namespace: h } = e, { branchId: E, transactionId: $ } = t, N = `"${f}_change_trigger"`, D = [...a.keys(), ...d].filter((I) => I !== "id"), M = 'type, namespace, entity, "branchId", "transactionId", "entityId", "inversePatch", patch', S = $ ? `'${$}'` : "NULL", C = E || "main", _ = `"${h}"."${f}_change_trigger_fn"`, R = `'${h}','${f}','${C}',${S}`, O = `
2572
+ -- 创建或替换触发器函数
2573
+ CREATE OR REPLACE FUNCTION ${_}()
2574
+ RETURNS TRIGGER AS $$
2575
+ DECLARE
2576
+ old_values JSONB;
2577
+ new_values JSONB;
2578
+ BEGIN
2579
+ -- INSERT 操作
2580
+ IF (TG_OP = 'INSERT') THEN
2581
+ INSERT INTO ${r} (${M})
2582
+ VALUES (
2583
+ 'INSERT',
2584
+ ${R},
2585
+ NEW.id,
2586
+ NULL,
2587
+ jsonb_build_object(${D.map((I) => `'${I}', NEW."${I}"`).join(", ")})
2588
+ );
2589
+ RETURN NEW;
2590
+
2591
+ -- UPDATE 操作
2592
+ ELSIF (TG_OP = 'UPDATE') THEN
2593
+ -- 只在字段真正变更时记录
2594
+ IF (${D.map((I) => `OLD."${I}" IS DISTINCT FROM NEW."${I}"`).join(" OR ")}) THEN
2595
+ -- 构建变更前的值 (inversePatch - 只包含变更的字段)
2596
+ old_values := jsonb_build_object(${D.map((I) => `'${I}', CASE WHEN OLD."${I}" IS DISTINCT FROM NEW."${I}" THEN to_jsonb(OLD."${I}") ELSE NULL END`).join(", ")});
2597
+ old_values := jsonb_strip_nulls(old_values);
2598
+
2599
+ -- 构建变更后的值 (patch - 只包含变更的字段)
2600
+ new_values := jsonb_build_object(${D.map((I) => `'${I}', CASE WHEN OLD."${I}" IS DISTINCT FROM NEW."${I}" THEN to_jsonb(NEW."${I}") ELSE NULL END`).join(", ")});
2601
+ new_values := jsonb_strip_nulls(new_values);
2602
+
2603
+ INSERT INTO ${r} (${M})
2604
+ VALUES (
2605
+ 'UPDATE',
2606
+ ${R},
2607
+ NEW.id,
2608
+ old_values,
2609
+ new_values
2610
+ );
2611
+ END IF;
2612
+ RETURN NEW;
2613
+
2614
+ -- DELETE 操作
2615
+ ELSIF (TG_OP = 'DELETE') THEN
2616
+ INSERT INTO ${r} (${M})
2617
+ VALUES (
2618
+ 'DELETE',
2619
+ ${R},
2620
+ OLD.id,
2621
+ jsonb_build_object(${D.map((I) => `'${I}', OLD."${I}"`).join(", ")}),
2622
+ NULL
2623
+ );
2624
+ RETURN OLD;
2625
+ END IF;
2626
+
2627
+ RETURN NULL;
2628
+ END;
2629
+ $$ LANGUAGE plpgsql;`, A = `
2630
+ -- 删除已存在的触发器
2631
+ DROP TRIGGER IF EXISTS ${N} ON ${n}`, b = `
2632
+ -- 创建触发器 (监听 INSERT, UPDATE, DELETE)
2633
+ CREATE TRIGGER ${N}
2634
+ AFTER INSERT OR UPDATE OR DELETE ON ${n}
2635
+ FOR EACH ROW
2636
+ EXECUTE FUNCTION ${_}()`;
2637
+ return [O, A, b].join(`
2638
+ ---STATEMENT_SEPARATOR---
2639
+ `);
2640
+ }
2641
+ const Fi = async (e, t, n) => {
2642
+ const s = e.localRxDBBranch(), r = e.localRxDBChange();
2643
+ if ((await s.find({
2644
+ where: {
2645
+ combinator: "and",
2646
+ rules: [{ field: "id", operator: "=", value: t }]
2647
+ },
2648
+ limit: 1
2649
+ })).length > 0)
2650
+ throw new ce(`Branch ID (${t}) already exists`);
2651
+ let f;
2652
+ if (n) {
2653
+ const h = await r.get(n);
2654
+ if (!h)
2655
+ throw new ce(`Change ID (${n}) not found`);
2656
+ if (!h.branchId)
2657
+ throw new ce(`Change record (${n}) has no branchId`);
2658
+ f = await s.get(h.branchId);
2659
+ } else
2660
+ f = (await s.find({
2661
+ where: {
2662
+ combinator: "and",
2663
+ rules: [{ field: "activated", operator: "=", value: !0 }]
2664
+ },
2665
+ limit: 1
2666
+ }))[0];
2667
+ if (!f)
2668
+ throw new ce("Source branch not found");
2669
+ n || (n = (await r.find({
2670
+ where: {
2671
+ combinator: "and",
2672
+ rules: [
2673
+ { field: "branchId", operator: "=", value: f.id },
2674
+ { field: "revertChangeId", operator: "=", value: null }
2675
+ ]
2676
+ },
2677
+ orderBy: [{ field: "id", sort: "desc" }],
2678
+ limit: 1
2679
+ }))[0]?.id ?? null);
2680
+ const d = new zt();
2681
+ return d.id = t, d.activated = !1, d.local = !0, d.remote = !1, d.fromChangeId = n ?? null, d.parentId = f.id, await s.create(d);
2682
+ };
2683
+ function Qt(e, t, n) {
2684
+ const s = [];
2685
+ return e.rxdb.config.entities.forEach((r) => {
2686
+ const a = re(r);
2687
+ if (a.log !== !1) {
2688
+ const d = wt(a, { branchId: t, transactionId: n }).split("---STATEMENT_SEPARATOR---").map((h) => h.trim()).filter((h) => h.length > 0);
2689
+ s.push(...d);
2690
+ }
2691
+ }), s;
2692
+ }
2693
+ class Zi extends cr {
2694
+ /**
2695
+ * 构造函数
2696
+ *
2697
+ * @param rxdb - RxDB 实例
2698
+ * @param options - PGlite 客户端配置选项
2699
+ */
2700
+ constructor(t, n) {
2701
+ super(t), this.options = n;
124
2702
  }
125
- connect() {
126
- return this.#e.pipe(h(() => this));
2703
+ /** 销毁信号主题,用于清理资源 */
2704
+ #e = new pr();
2705
+ /** 仓库实例缓存,避免重复创建 */
2706
+ #n = /* @__PURE__ */ new Map();
2707
+ /** PGlite 客户端缓存 */
2708
+ #a;
2709
+ /** 事务锁标志,防止事务嵌套 */
2710
+ #t = !1;
2711
+ /** 查询任务队列执行器,确保查询按顺序执行 */
2712
+ #r = new hr(1);
2713
+ /** 客户端初始化 Promise,确保单例 */
2714
+ #o;
2715
+ /** 当前活跃的事务对象 */
2716
+ #s;
2717
+ /** 适配器名称 */
2718
+ name = yr;
2719
+ async mutations(t) {
2720
+ const n = async () => await Mi(this, t, this.rxdb.context);
2721
+ return this.#t ? await n() : await this.transaction(() => n());
127
2722
  }
128
- disconnect() {
129
- throw new a("Method disconnect not implemented.");
2723
+ mergeChanges(t, n, s) {
2724
+ throw new Error("Method not implemented.");
130
2725
  }
131
- createBranch(e, t) {
2726
+ getRxDBChangeSequence() {
132
2727
  throw new Error("Method not implemented.");
133
2728
  }
134
- switchBranch(e) {
2729
+ setRxDBChangeSequence(t) {
135
2730
  throw new Error("Method not implemented.");
136
2731
  }
137
- restoreEntity(e, t) {
2732
+ /**
2733
+ * 批量删除实体
2734
+ *
2735
+ * @param entities - 要删除的实体数组
2736
+ * @returns 已删除的实体数组
2737
+ */
2738
+ async removeMany(t) {
2739
+ if (!t || t.length === 0) return Promise.resolve([]);
2740
+ const n = re(t[0].constructor), s = Zn(n, t);
2741
+ return await this.query(s), t;
2742
+ }
2743
+ /**
2744
+ * 批量保存实体
2745
+ *
2746
+ * 将实体持久化到数据库:
2747
+ * 1. 按实体类型分组(避免混合不同表的数据)
2748
+ * 2. 为每个类型生成批量插入 SQL(使用 UPSERT)
2749
+ * 3. 在事务中执行(如果尚未在事务中)
2750
+ * 4. 更新实体状态标记
2751
+ *
2752
+ * @param entities - 要保存的实体数组
2753
+ * @returns 已保存的实体数组
2754
+ */
2755
+ async saveMany(t) {
2756
+ if (!t || t.length === 0) return Promise.resolve([]);
2757
+ const n = /* @__PURE__ */ new Map();
2758
+ for (const r of t) {
2759
+ const a = r.constructor;
2760
+ n.has(a) || n.set(a, []), n.get(a).push(r);
2761
+ }
2762
+ const s = async () => {
2763
+ for (const [r, a] of n.entries()) {
2764
+ const f = re(r), d = Ue(f, a, this.rxdb.context);
2765
+ await this.query(d);
2766
+ for (const h of a) {
2767
+ const E = be(h);
2768
+ E.local = !0, E.modified = !1;
2769
+ }
2770
+ }
2771
+ };
2772
+ return await (this.#t ? s() : this.transaction(s)), t;
2773
+ }
2774
+ /**
2775
+ * 连接到数据库
2776
+ *
2777
+ * @returns 适配器实例
2778
+ */
2779
+ async connect() {
2780
+ const t = await this.#i(), n = Pi();
2781
+ return await t.exec(n), t instanceof Ht && (t.addEventListener(Ee.INSERT, (s) => Ze(this, s)), t.addEventListener(Ee.UPDATE, (s) => Ze(this, s)), t.addEventListener(Ee.DELETE, (s) => Ze(this, s))), this;
2782
+ }
2783
+ /**
2784
+ * 断开数据库连接
2785
+ *
2786
+ * 清理资源并发送销毁信号
2787
+ */
2788
+ async disconnect() {
2789
+ this.#a && (await this.#a.disconnect(), this.#e.next(), this.#e.complete());
2790
+ }
2791
+ /**
2792
+ * 创建分支
2793
+ *
2794
+ * 分支用于管理数据的不同版本,类似 Git 分支:
2795
+ * 1. 验证分支 ID 不存在
2796
+ * 2. 确定源分支(从当前活跃分支或指定变更点)
2797
+ * 3. 创建新分支记录
2798
+ *
2799
+ * @param branchId - 新分支 ID
2800
+ * @param fromChangeId - 从指定变更 ID 创建分支(可选,默认从当前分支的最新状态)
2801
+ * @throws {RxdbAdapterPGliteError} 分支 ID 已存在或源分支未找到
2802
+ */
2803
+ async createBranch(t, n) {
2804
+ return Fi(this, t, n);
2805
+ }
2806
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2807
+ switchBranch(t) {
138
2808
  throw new Error("Method not implemented.");
139
2809
  }
140
2810
  /**
141
- * 获取版本
2811
+ * 恢复实体到指定状态
2812
+ *
2813
+ * 从变更历史中恢复实体到指定的版本
2814
+ *
2815
+ * @param _entity - 要恢复的实体
2816
+ * @param _options - 恢复选项
2817
+ * @returns 恢复后的实体
2818
+ * @throws {RxdbAdapterPGliteError} 此功能尚未实现
142
2819
  */
143
- version() {
144
- return p(this.version$);
2820
+ restoreEntity(t, n) {
2821
+ throw new ce("restoreEntity is not yet implemented. ");
145
2822
  }
146
- getRepository(e) {
147
- throw new a("Method getRepository not implemented.");
2823
+ /**
2824
+ * 获取 PostgreSQL 版本
2825
+ *
2826
+ * @returns PostgreSQL 版本字符串
2827
+ */
2828
+ async version() {
2829
+ return await (await this.#i()).version();
148
2830
  }
149
- createTables(e) {
150
- let t = "";
151
- for (let n = 0; n < e.length; n++) {
152
- const c = e[n], l = T(c);
153
- t += `
154
- ` + A(this, l), l.log;
2831
+ /**
2832
+ * 获取实体类型的仓库实例
2833
+ *
2834
+ * 根据实体元数据中的仓库类型创建相应的仓库实例:
2835
+ * - Repository: 通用仓库
2836
+ * - TreeRepository: 树形仓库(用于层级数据)
2837
+ *
2838
+ * 仓库实例会被缓存,避免重复创建
2839
+ *
2840
+ * @param entity - 实体类型
2841
+ * @returns 仓库实例
2842
+ * @throws {RxdbAdapterPGliteError} 不支持的仓库类型
2843
+ */
2844
+ getRepository(t) {
2845
+ if (!this.#n.has(t)) {
2846
+ const n = re(t);
2847
+ let s;
2848
+ switch (n.repository) {
2849
+ case "Repository":
2850
+ s = new ir(this, t);
2851
+ break;
2852
+ case "TreeRepository":
2853
+ s = new Ci(this, t);
2854
+ break;
2855
+ default:
2856
+ throw new ce("Unsupported repository type: " + n.repository);
2857
+ }
2858
+ return this.#n.set(t, s), s;
155
2859
  }
156
- return p(this.#n(t).pipe(h(() => !0)));
2860
+ return this.#n.get(t);
157
2861
  }
158
- async isTableExisted(e) {
159
- return p(this.isTableExisted$(e));
2862
+ /**
2863
+ * 创建数据库表
2864
+ *
2865
+ * 分三阶段创建表结构:
2866
+ * 1. 创建表和列(不含外键约束)
2867
+ * 2. 添加外键约束
2868
+ * 3. 创建触发器(用于变更追踪)
2869
+ *
2870
+ * 这样可以避免因表创建顺序导致的外键约束失败
2871
+ *
2872
+ * @param EntityTypes - 实体类型数组
2873
+ * @param entities - 初始化数据(可选)
2874
+ * @returns 是否成功创建
2875
+ */
2876
+ async createTables(t, n) {
2877
+ const s = [], r = [];
2878
+ for (const a of t) {
2879
+ const f = re(a), h = ar(this, f).split(/;\s*\n/).map((E) => E.trim()).filter((E) => E.length > 0 && !E.startsWith("--"));
2880
+ for (const E of h)
2881
+ E && (E.includes("ADD CONSTRAINT") && E.includes("FOREIGN KEY") ? s.push(E) : r.push(E));
2882
+ }
2883
+ if (r.length > 0) {
2884
+ const a = r.join(`;
2885
+ `) + ";";
2886
+ await this.#c(a);
2887
+ }
2888
+ if (s.length > 0) {
2889
+ const a = s.join(`;
2890
+ `) + ";";
2891
+ try {
2892
+ await this.#c(a);
2893
+ } catch (f) {
2894
+ console.warn("Failed to add foreign key constraints:", f);
2895
+ }
2896
+ }
2897
+ for (const a of t) {
2898
+ const f = re(a);
2899
+ if (f.log !== !1) {
2900
+ const d = wt(f);
2901
+ await this.#c(d.replace(/---STATEMENT_SEPARATOR---/g, ";"));
2902
+ }
2903
+ }
2904
+ if (n && n.length > 0) {
2905
+ const a = /* @__PURE__ */ new Map();
2906
+ for (const f of n) {
2907
+ const d = f.constructor;
2908
+ a.has(d) || a.set(d, []), a.get(d).push(f);
2909
+ }
2910
+ for (const [f, d] of a) {
2911
+ const h = re(f), E = Ue(h, d, this.rxdb.context);
2912
+ await this.#c(E);
2913
+ }
2914
+ }
2915
+ return !0;
160
2916
  }
161
2917
  /**
162
2918
  * 判断表是否存在
163
- * @param EntityType
2919
+ *
2920
+ * @param EntityType - 实体类型
2921
+ * @returns 表是否存在
164
2922
  */
165
- isTableExisted$(e) {
166
- const t = T(e);
167
- return this.#t(
2923
+ async isTableExisted(t) {
2924
+ const n = re(t);
2925
+ return (await this.#l(
168
2926
  `SELECT EXISTS (
169
- SELECT 1
170
- FROM information_schema.tables
171
- WHERE table_schema = '${t.namespace}'
172
- AND table_name = '${t.name}');`
173
- ).pipe(h((n) => n.rows[0]?.exists));
2927
+ SELECT 1 FROM information_schema.tables
2928
+ WHERE
2929
+ table_schema = '${n.namespace}' AND
2930
+ table_name = '${n.name}');`
2931
+ )).rows[0]?.exists;
2932
+ }
2933
+ /**
2934
+ * 获取表的列信息
2935
+ *
2936
+ * @param EntityType - 实体类型
2937
+ * @returns 列信息数组
2938
+ */
2939
+ async getTableColumns(t) {
2940
+ const n = re(t);
2941
+ return (await this.#l(
2942
+ `SELECT * FROM information_schema.columns
2943
+ WHERE table_schema = '${n.namespace}'
2944
+ AND table_name = '${n.name}'
2945
+ ORDER BY ordinal_position;`
2946
+ )).rows;
2947
+ }
2948
+ /**
2949
+ * 获取本地分支仓库
2950
+ *
2951
+ * @returns 分支仓库实例
2952
+ */
2953
+ localRxDBBranch() {
2954
+ return this.getRepository(zt);
174
2955
  }
175
- transaction(e) {
176
- throw new a("Method transaction not implemented.");
2956
+ /**
2957
+ * 获取本地变更仓库
2958
+ *
2959
+ * @returns 变更仓库实例
2960
+ */
2961
+ localRxDBChange() {
2962
+ return this.getRepository(ht);
177
2963
  }
178
- #t(e, t, n) {
179
- return this.#e.pipe(m((c) => c.query(e, t, n)));
2964
+ /**
2965
+ * 执行事务
2966
+ *
2967
+ * 事务管理策略:
2968
+ * - 使用手动 BEGIN/COMMIT/ROLLBACK 控制事务边界
2969
+ * - 使用 SET CONSTRAINTS ALL DEFERRED 延迟外键约束检查到提交时
2970
+ * - 动态重建触发器以注入 transactionId(与 SQLite 方案一致)
2971
+ * - PostgreSQL 不允许在有 pending trigger events 时修改表结构,
2972
+ * 因此无法使用列默认值方案,必须重建触发器
2973
+ *
2974
+ * @param transactionFun - 事务函数
2975
+ * @param transactionLog - 是否启用事务日志(默认 true)
2976
+ * @returns 事务函数的返回值
2977
+ * @throws {RxdbAdapterPGliteError} 事务执行失败
2978
+ */
2979
+ async transaction(t, n = !0) {
2980
+ await this.rxdb.connect(this.name);
2981
+ const s = await this.#i(), r = n ? crypto.randomUUID() : void 0;
2982
+ return await s.transaction(async (f) => {
2983
+ if (this.#t = !0, this.#s = f, await f.query("SET CONSTRAINTS ALL DEFERRED"), n && r) {
2984
+ const h = Qt(this, "main", r);
2985
+ for (const E of h)
2986
+ await f.query(E);
2987
+ }
2988
+ const d = await t();
2989
+ if (n && r) {
2990
+ const h = Qt(this, "main");
2991
+ for (const E of h)
2992
+ await f.query(E);
2993
+ }
2994
+ return this.#s = void 0, this.#t = !1, d;
2995
+ });
180
2996
  }
181
- #n(e, t) {
182
- return this.#e.pipe(m((n) => n.exec(e, t)));
2997
+ /**
2998
+ * 执行 SQL 查询
2999
+ *
3000
+ * 查询执行策略:
3001
+ * - 在事务中:直接在事务上下文中执行
3002
+ * - 非事务中:加入队列按顺序执行,避免并发冲突
3003
+ *
3004
+ * @param sql - SQL 语句
3005
+ * @param bindings - 参数绑定
3006
+ * @returns 查询结果
3007
+ */
3008
+ query(t, n) {
3009
+ return this.#t && this.#s ? this.#s.query(t, n) : this.#r.addTask(
3010
+ async () => (await this.rxdb.connect(this.name), (await this.#i()).query(t, n)),
3011
+ zn([t, n])
3012
+ );
183
3013
  }
3014
+ /**
3015
+ * 内部查询方法 (Public Alias)
3016
+ * 供核心同步逻辑使用,绕过队列直接查询
3017
+ */
3018
+ internalQuery(t, n) {
3019
+ return this.#l(t, n);
3020
+ }
3021
+ /**
3022
+ * 内部查询方法
3023
+ *
3024
+ * 直接在客户端上执行查询,不经过队列
3025
+ *
3026
+ * @param query - SQL 查询
3027
+ * @param params - 查询参数
3028
+ * @param options - 查询选项
3029
+ * @returns 查询结果
3030
+ */
3031
+ async #l(t, n, s) {
3032
+ return (await this.#i()).query(t, n, s);
3033
+ }
3034
+ /**
3035
+ * 内部执行方法
3036
+ *
3037
+ * 执行 SQL 语句(可能包含多个语句)
3038
+ *
3039
+ * @param query - SQL 语句
3040
+ * @param options - 执行选项
3041
+ * @returns 执行结果数组
3042
+ */
3043
+ async #c(t, n) {
3044
+ return (await this.#i()).exec(t, n);
3045
+ }
3046
+ /**
3047
+ * 获取 PGlite 客户端实例
3048
+ *
3049
+ * 使用单例模式,确保只创建一个客户端实例
3050
+ *
3051
+ * @returns PGlite 客户端 Promise
3052
+ */
3053
+ #i() {
3054
+ if (!this.#o) {
3055
+ const t = new Ht();
3056
+ this.#o = t.init(this.rxdb.config.dbName, this.options).then(() => (this.#a = t, t));
3057
+ }
3058
+ return this.#o;
3059
+ }
3060
+ }
3061
+ class ki {
3062
+ getReturningClause() {
3063
+ return "RETURNING *";
3064
+ }
3065
+ getParameterPlaceholder(t) {
3066
+ return `$${t}`;
3067
+ }
3068
+ escapeIdentifier(t) {
3069
+ return `"${t.replace(/"/g, '""')}"`;
3070
+ }
3071
+ getJsonExtractOperator() {
3072
+ return "->>";
3073
+ }
3074
+ getConcatOperator() {
3075
+ return "||";
3076
+ }
3077
+ /**
3078
+ * 生成批量插入 SQL(带 RETURNING)
3079
+ * @param tableName - 表名
3080
+ * @param columns - 列名数组
3081
+ * @param rowCount - 行数
3082
+ * @returns SQL 语句
3083
+ */
3084
+ generateBatchInsert(t, n, s) {
3085
+ const r = this.escapeIdentifier(t), a = n.map((h) => this.escapeIdentifier(h)).join(", "), f = [];
3086
+ let d = 1;
3087
+ for (let h = 0; h < s; h++) {
3088
+ const E = n.map(() => this.getParameterPlaceholder(d++)).join(", ");
3089
+ f.push(`(${E})`);
3090
+ }
3091
+ return `INSERT INTO ${r} (${a}) VALUES ${f.join(", ")} ${this.getReturningClause()}`;
3092
+ }
3093
+ /**
3094
+ * 生成批量更新 SQL(使用 UPDATE ... FROM 模式)
3095
+ * @param tableName - 表名
3096
+ * @param pkColumn - 主键列名
3097
+ * @param updateColumns - 更新列名数组
3098
+ * @returns SQL 模板
3099
+ */
3100
+ generateBatchUpdate(t, n, s) {
3101
+ const r = this.escapeIdentifier(t), a = this.escapeIdentifier(n), f = s.map((d) => `${this.escapeIdentifier(d)} = temp.${this.escapeIdentifier(d)}`).join(", ");
3102
+ return `UPDATE ${r} SET ${f} FROM (VALUES ($1)) AS temp(${a}, ${s.join(", ")}) WHERE ${r}.${a} = temp.${a} ${this.getReturningClause()}`;
3103
+ }
3104
+ }
3105
+ const ea = new ki();
3106
+ function ta(e, t, n) {
3107
+ let s = "";
3108
+ for (let r = 0; r < t.length; r++) {
3109
+ const a = t[r], f = re(a), d = ar(e, f);
3110
+ if (s += `
3111
+ ` + d, f.log !== !1) {
3112
+ const h = wt(f);
3113
+ s += `
3114
+ ` + h;
3115
+ }
3116
+ }
3117
+ if (n && n.length > 0) {
3118
+ const r = /* @__PURE__ */ new Map();
3119
+ n.forEach((a) => {
3120
+ const f = re(a);
3121
+ r.has(f) || r.set(f, /* @__PURE__ */ new Set()), r.get(f).add(a);
3122
+ });
3123
+ for (const [a, f] of r.entries()) {
3124
+ const d = Ue(a, Array.from(f), e.rxdb.context);
3125
+ s += `
3126
+ ` + d;
3127
+ }
3128
+ }
3129
+ return s;
3130
+ }
3131
+ function Wi(e) {
3132
+ const t = oe(e), { name: n, namespace: s } = e, r = `"${n}_change_trigger"`, a = `"${s}"."${n}_change_trigger_fn"`, f = `DROP TRIGGER IF EXISTS ${r} ON ${t}`, d = `DROP FUNCTION IF EXISTS ${a}() CASCADE`;
3133
+ return [f, d].join(`
3134
+ ---STATEMENT_SEPARATOR---
3135
+ `);
3136
+ }
3137
+ function na(e) {
3138
+ const t = [];
3139
+ return e.rxdb.config.entities.forEach((n) => {
3140
+ const s = re(n);
3141
+ s.log !== !1 && t.push(Wi(s));
3142
+ }), t.join(`
3143
+ ---STATEMENT_SEPARATOR---
3144
+ `);
184
3145
  }
185
3146
  export {
186
- B as RxDBAdapterPGlite,
187
- a as RxdbAdapterPGliteError
3147
+ yr as ADAPTER_NAME,
3148
+ Ee as PGliteChangeType,
3149
+ Ht as PGliteClient,
3150
+ ki as PostgreSQLDialect,
3151
+ Zi as RxDBAdapterPGlite,
3152
+ ce as RxdbAdapterPGliteError,
3153
+ ta as create_tables_sql,
3154
+ ji as generateNotifyFunctionSQL,
3155
+ Pi as generateNotifyInfrastructureSQL,
3156
+ xi as generateNotifyTriggerSQL,
3157
+ wt as generate_trigger_sql,
3158
+ Ne as getEntityObjectFromResult,
3159
+ pt as getSqlValue,
3160
+ Ji as getSqlWithParams,
3161
+ rn as getTableColumnIndexName,
3162
+ tn as getTableName,
3163
+ oe as getTableNameByMetadata,
3164
+ sn as normalizeCreateEntity,
3165
+ mr as normalizeEntity,
3166
+ ea as pgDialect,
3167
+ zi as removeNotifyTriggerSQL,
3168
+ na as remove_all_triggers_sql,
3169
+ Wi as remove_trigger_sql,
3170
+ nn as rxDBColumnTypeToPGliteType,
3171
+ gr as rxDBColumnTypeToPGliteTypeIndexName,
3172
+ $t as transformEntityValuePGliteToJs,
3173
+ dt as transformEntityValueToSql,
3174
+ Er as transformValueJsToPGlite,
3175
+ wr as transformValuePGliteToJs
188
3176
  };