@aiao/rxdb-adapter-sqlite 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,168 +1,168 @@
1
- import { getEntityMetadata as T, PropertyType as E, RelationKind as b, isRuleGroup as fe, getEntityStatus as D, RepositoryBase as Be, RxDBChange as B, EntityLocalCreatedEvent as K, EntityLocalRemovedEvent as ce, EntityLocalUpdatedEvent as Y, parseRxDBChangeKey as ee, RxDBBranch as H, getEntityType as te, TransactionBeginEvent as Ue, TransactionRollbackEvent as We, TransactionCommitEvent as Ke, RxDBAdapterLocalBase as He, getEntityMutations as he, uuid as Ve } from "@aiao/rxdb";
2
- import { isString as Qe, isNil as Ge, traverseObjectKeys as Je, EventDispatcher as Xe, AsyncQueueExecutor as we, get as Ye, isFunction as me } from "@aiao/utils";
3
- import { wrap as Ee, proxy as ze } from "comlink";
4
- import { defer as ne, of as se, from as re, map as Ze } from "rxjs";
5
- import { Factory as et, SQLITE_ROW as tt, SQLITE_UTF8 as Ae, SQLITE_DETERMINISTIC as Se } from "wa-sqlite";
6
- const nt = (e) => ({
1
+ import { getEntityMetadata as V, PropertyType as D, RelationKind as z, isRuleGroup as Ye, getEntityStatus as ae, RepositoryBase as Nt, RxDBChange as pe, EntityLocalCreatedEvent as Ee, EntityLocalRemovedEvent as qe, EntityLocalUpdatedEvent as Te, parseRxDBChangeKey as Re, RxDBBranch as _e, getEntityType as Ce, TransactionBeginEvent as At, TransactionRollbackEvent as It, TransactionCommitEvent as Tt, RxDBAdapterLocalBase as $t, getEntityMutations as Qe, uuid as St } from "@aiao/rxdb";
2
+ import { isString as vt, isNil as Rt, traverseObjectKeys as Ct, EventDispatcher as Lt, AsyncQueueExecutor as st, get as Mt, isFunction as Je } from "@aiao/utils";
3
+ import { wrap as Ge, proxy as Ot } from "comlink";
4
+ import { defer as Le, of as Me, from as Oe, map as xt } from "rxjs";
5
+ import { Factory as jt, SQLITE_ROW as Bt, SQLITE_UTF8 as ot, SQLITE_DETERMINISTIC as it } from "wa-sqlite";
6
+ const Dt = (t) => ({
7
7
  sql: "SELECT * FROM sqlite_master WHERE type='table' AND name=? LIMIT 1;",
8
- params: [e]
9
- }), st = (e) => !!e.sql && (e.results.length === 0 || e.results[0].rows.length === 0), q = "__rowid", rt = (e) => {
10
- switch (e.type) {
11
- case E.uuid:
12
- case E.string:
13
- case E.enum:
14
- case E.json:
15
- case E.keyValue:
16
- case E.stringArray:
17
- case E.numberArray:
8
+ params: [t]
9
+ }), qt = (t) => !!t.sql && (t.results.length === 0 || t.results[0].rows.length === 0), ie = "__rowid", kt = (t) => {
10
+ switch (t.type) {
11
+ case D.uuid:
12
+ case D.string:
13
+ case D.enum:
14
+ case D.json:
15
+ case D.keyValue:
16
+ case D.stringArray:
17
+ case D.numberArray:
18
18
  return "TEXT";
19
- case E.number:
19
+ case D.number:
20
20
  return "REAL";
21
- case E.integer:
22
- case E.boolean:
21
+ case D.integer:
22
+ case D.boolean:
23
23
  return "INTEGER";
24
24
  default:
25
25
  return "TEXT";
26
26
  }
27
- }, V = (e, n) => {
28
- if (e === null && n.nullable) return null;
29
- if (e !== void 0)
27
+ }, we = (t, n) => {
28
+ if (t === null && n.nullable) return null;
29
+ if (t !== void 0)
30
30
  switch (n.type) {
31
- case E.boolean:
32
- return e ? 1 : 0;
33
- case E.date:
34
- return e instanceof Date ? e.toISOString() : e;
35
- case E.keyValue: {
36
- if (!e) return null;
37
- if (n.properties && typeof e == "object" && !Array.isArray(e)) {
38
- const t = { ...e };
31
+ case D.boolean:
32
+ return t ? 1 : 0;
33
+ case D.date:
34
+ return t instanceof Date ? t.toISOString() : t;
35
+ case D.keyValue: {
36
+ if (!t) return null;
37
+ if (n.properties && typeof t == "object" && !Array.isArray(t)) {
38
+ const e = { ...t };
39
39
  return n.properties.forEach((s) => {
40
- s.name in t && (t[s.name] = V(t[s.name], s));
41
- }), JSON.stringify(t);
40
+ s.name in e && (e[s.name] = we(e[s.name], s));
41
+ }), JSON.stringify(e);
42
42
  }
43
- return JSON.stringify(e);
43
+ return JSON.stringify(t);
44
44
  }
45
- case E.stringArray:
46
- case E.numberArray:
47
- case E.json:
48
- return JSON.stringify(e);
45
+ case D.stringArray:
46
+ case D.numberArray:
47
+ case D.json:
48
+ return JSON.stringify(t);
49
49
  default:
50
- return e;
50
+ return t;
51
51
  }
52
- }, P = (e, n) => {
53
- if (e === null && n.nullable) return null;
54
- if (e !== void 0)
52
+ }, ue = (t, n) => {
53
+ if (t === null && n.nullable) return null;
54
+ if (t !== void 0)
55
55
  switch (n.type) {
56
- case E.boolean:
57
- return !!e;
58
- case E.date:
59
- return e instanceof Date ? e : typeof e == "string" ? new Date(e) : e;
60
- case E.keyValue: {
61
- if (!e) return null;
62
- const t = typeof e == "object" ? e : JSON.parse(e);
63
- return n.properties && t && typeof t == "object" && n.properties.forEach((s) => {
64
- s.name in t && (t[s.name] = P(t[s.name], s));
65
- }), t;
56
+ case D.boolean:
57
+ return !!t;
58
+ case D.date:
59
+ return t instanceof Date ? t : typeof t == "string" ? new Date(t) : t;
60
+ case D.keyValue: {
61
+ if (!t) return null;
62
+ const e = typeof t == "object" ? t : JSON.parse(t);
63
+ return n.properties && e && typeof e == "object" && n.properties.forEach((s) => {
64
+ s.name in e && (e[s.name] = ue(e[s.name], s));
65
+ }), e;
66
66
  }
67
- case E.stringArray:
68
- case E.numberArray:
69
- return Array.isArray(e) ? e : e ? JSON.parse(e) : null;
70
- case E.json:
71
- return e !== null && typeof e == "object" ? e : e ? JSON.parse(e) : null;
67
+ case D.stringArray:
68
+ case D.numberArray:
69
+ return Array.isArray(t) ? t : t ? JSON.parse(t) : null;
70
+ case D.json:
71
+ return t !== null && typeof t == "object" ? t : t ? JSON.parse(t) : null;
72
72
  default:
73
- return e;
73
+ return t;
74
74
  }
75
- }, k = (e, n) => `${n}$${e}`, ot = (e) => {
76
- const n = e.indexOf("$");
77
- return n === -1 ? ["", e] : [e.substring(0, n), e.substring(n + 1)];
78
- }, A = (e) => k(e.tableName, e.namespace), ye = (e) => A(T(e)), _e = (e, n) => `idx_${e.name}_${n.name}`;
79
- class R extends Error {
80
- constructor(n, t) {
81
- super(n, t), this.name = "RxDBAdapterSqliteError", Object.setPrototypeOf(this, R.prototype);
75
+ }, le = (t, n) => `${n}$${t}`, Ut = (t) => {
76
+ const n = t.indexOf("$");
77
+ return n === -1 ? ["", t] : [t.substring(0, n), t.substring(n + 1)];
78
+ }, X = (t) => le(t.tableName, t.namespace), Xe = (t) => X(V(t)), ze = (t, n) => `idx_${t.name}_${n.name}`;
79
+ class ee extends Error {
80
+ constructor(n, e) {
81
+ super(n, e), this.name = "RxDBAdapterSqliteError", Object.setPrototypeOf(this, ee.prototype);
82
82
  }
83
83
  }
84
- const le = (e, n) => {
85
- const t = {}, s = Object.keys(n), r = e.foreignKeyNames || [], o = e.foreignKeyColumnNames || r;
86
- for (let i = 0; i < s.length; i++) {
87
- const c = s[i], a = r.indexOf(c);
88
- if (a !== -1) {
89
- t[o[a]] = n[c];
84
+ const ke = (t, n) => {
85
+ const e = {}, s = Object.keys(n), o = t.foreignKeyNames || [], a = t.foreignKeyColumnNames || o;
86
+ for (let d = 0; d < s.length; d++) {
87
+ const p = s[d], f = o.indexOf(p);
88
+ if (f !== -1) {
89
+ e[a[f]] = n[p];
90
90
  continue;
91
91
  }
92
- if (o.indexOf(c) !== -1) {
93
- t[c] = n[c];
92
+ if (a.indexOf(p) !== -1) {
93
+ e[p] = n[p];
94
94
  continue;
95
95
  }
96
- if (r.length === 0 && c.endsWith("Id")) {
97
- t[c] = n[c];
96
+ if (o.length === 0 && p.endsWith("Id")) {
97
+ e[p] = n[p];
98
98
  continue;
99
99
  }
100
- const d = e.propertyMap.get(c);
101
- if (d) {
102
- t[d.columnName] = V(n[c], d);
100
+ const A = t.propertyMap.get(p);
101
+ if (A) {
102
+ e[A.columnName] = we(n[p], A);
103
103
  continue;
104
104
  }
105
- const u = e.columnNameToPropertyName?.get(c);
106
- if (u) {
107
- const h = e.propertyMap.get(u);
108
- h && (t[c] = V(n[c], h));
105
+ const I = t.columnNameToPropertyName?.get(p);
106
+ if (I) {
107
+ const M = t.propertyMap.get(I);
108
+ M && (e[p] = we(n[p], M));
109
109
  }
110
110
  }
111
- return t;
112
- }, be = (e, n) => {
113
- const t = {};
114
- for (const [o, i] of e.propertyMap)
115
- o in n && (t[i.columnName] = n[o]);
116
- const s = e.foreignKeyNames || [], r = e.foreignKeyColumnNames || s;
117
- for (let o = 0; o < s.length; o++) {
118
- const i = s[o];
119
- i in n && (t[r[o]] = n[i]);
111
+ return e;
112
+ }, at = (t, n) => {
113
+ const e = {};
114
+ for (const [a, d] of t.propertyMap)
115
+ a in n && (e[d.columnName] = n[a]);
116
+ const s = t.foreignKeyNames || [], o = t.foreignKeyColumnNames || s;
117
+ for (let a = 0; a < s.length; a++) {
118
+ const d = s[a];
119
+ d in n && (e[o[a]] = n[d]);
120
120
  }
121
- return t;
122
- }, at = (e, n) => {
123
- const t = {};
124
- for (const [o, i] of e.propertyMap)
125
- o in n && i.readonly !== !0 && (t[i.columnName] = n[o]);
126
- const s = e.foreignKeyNames || [], r = e.foreignKeyColumnNames || s;
127
- for (let o = 0; o < s.length; o++) {
128
- const i = s[o];
129
- if (i in n) {
130
- const c = e.foreignKeyRelationMap.get(i);
131
- c && c.readonly !== !0 && (t[r[o]] = n[i]);
121
+ return e;
122
+ }, Pt = (t, n) => {
123
+ const e = {};
124
+ for (const [a, d] of t.propertyMap)
125
+ a in n && d.readonly !== !0 && (e[d.columnName] = n[a]);
126
+ const s = t.foreignKeyNames || [], o = t.foreignKeyColumnNames || s;
127
+ for (let a = 0; a < s.length; a++) {
128
+ const d = s[a];
129
+ if (d in n) {
130
+ const p = t.foreignKeyRelationMap.get(d);
131
+ p && p.readonly !== !0 && (e[o[a]] = n[d]);
132
132
  }
133
133
  }
134
- return t;
135
- }, I = (e) => Qe(e) ? `'${e.replaceAll("\0", "").replaceAll("'", "''")}'` : Ge(e) ? "NULL" : e, F = (e, n = []) => e.replace(/\?/g, () => String(I(n.shift()))), oe = (e, n, t) => {
134
+ return e;
135
+ }, te = (t) => vt(t) ? `'${t.replaceAll("\0", "").replaceAll("'", "''")}'` : Rt(t) ? "NULL" : t, fe = (t, n = []) => t.replace(/\?/g, () => String(te(n.shift()))), je = (t, n, e) => {
136
136
  const s = {};
137
- return t.forEach((r, o) => {
138
- const i = n[o];
139
- if (i.startsWith("__")) return;
140
- const c = e.foreignKeyNames || [], l = (e.foreignKeyColumnNames || c).indexOf(i);
141
- if (l !== -1) {
142
- s[c[l]] = r;
137
+ return e.forEach((o, a) => {
138
+ const d = n[a];
139
+ if (d.startsWith("__")) return;
140
+ const p = t.foreignKeyNames || [], b = (t.foreignKeyColumnNames || p).indexOf(d);
141
+ if (b !== -1) {
142
+ s[p[b]] = o;
143
143
  return;
144
144
  }
145
- const d = e.columnNameToPropertyName, p = d?.get(i);
146
- if (p) {
147
- const h = e.propertyMap.get(p);
148
- h ? s[p] = P(r, h) : console.warn(`Property ${p} not found in metadata ${e.name}`);
145
+ const A = t.columnNameToPropertyName, T = A?.get(d);
146
+ if (T) {
147
+ const M = t.propertyMap.get(T);
148
+ M ? s[T] = ue(o, M) : console.warn(`Property ${T} not found in metadata ${t.name}`);
149
149
  return;
150
150
  }
151
- const u = e.computedPropertyMap?.get(i);
152
- if (u) {
153
- s[i] = P(r, u);
151
+ const I = t.computedPropertyMap?.get(d);
152
+ if (I) {
153
+ s[d] = ue(o, I);
154
154
  return;
155
155
  }
156
- if (!d) {
157
- const h = e.propertyMap.get(i);
158
- if (h) {
159
- s[i] = P(r, h);
156
+ if (!A) {
157
+ const M = t.propertyMap.get(d);
158
+ if (M) {
159
+ s[d] = ue(o, M);
160
160
  return;
161
161
  }
162
162
  }
163
- console.warn(`Column ${i}=${r} not found in metadata ${e.name}`);
163
+ console.warn(`Column ${d}=${o} not found in metadata ${t.name}`);
164
164
  }), s;
165
- }, w = "_", it = {
165
+ }, Q = "_", Ft = {
166
166
  "=": "=",
167
167
  "!=": "!=",
168
168
  ">": ">",
@@ -179,514 +179,514 @@ const le = (e, n) => {
179
179
  notStartsWith: "NOT LIKE",
180
180
  endsWith: "LIKE",
181
181
  notEndsWith: "NOT LIKE"
182
- }, ae = (e, n) => {
183
- if (n && e.includes(".")) {
184
- const t = e.split("."), s = n.propertyMap.get(t[0]);
185
- if (!s) return e;
186
- if (s.type === E.keyValue)
182
+ }, Be = (t, n) => {
183
+ if (n && t.includes(".")) {
184
+ const e = t.split("."), s = n.propertyMap.get(e[0]);
185
+ if (!s) return t;
186
+ if (s.type === D.keyValue)
187
187
  return s.columnName;
188
- for (let o = 0; o < t.length - 1; o++) {
189
- const i = n.propertyMap.get(t[o]);
190
- if (!i) return e;
191
- if (i.type === E.keyValue)
192
- return i.columnName;
188
+ for (let a = 0; a < e.length - 1; a++) {
189
+ const d = n.propertyMap.get(e[a]);
190
+ if (!d) return t;
191
+ if (d.type === D.keyValue)
192
+ return d.columnName;
193
193
  }
194
- const r = n.propertyMap.get(t[t.length - 1]);
195
- return r ? r.columnName : e;
194
+ const o = n.propertyMap.get(e[e.length - 1]);
195
+ return o ? o.columnName : t;
196
196
  }
197
197
  if (n) {
198
- const t = n.propertyMap.get(e);
199
- if (t)
200
- return t.columnName;
201
- const s = n.foreignKeyNames || [], r = n.foreignKeyColumnNames || s, o = s.indexOf(e);
202
- if (o !== -1)
203
- return r[o];
198
+ const e = n.propertyMap.get(t);
199
+ if (e)
200
+ return e.columnName;
201
+ const s = n.foreignKeyNames || [], o = n.foreignKeyColumnNames || s, a = s.indexOf(t);
202
+ if (a !== -1)
203
+ return o[a];
204
204
  }
205
- return e;
206
- }, ge = (e, n, t) => {
205
+ return t;
206
+ }, Ze = (t, n, e) => {
207
207
  if (n) return n;
208
- if (!e.includes(".")) {
209
- const c = ae(e, t);
210
- return `${w}."${c}"`;
211
- }
212
- const s = e.lastIndexOf("."), r = e.slice(0, s), o = e.slice(s + 1), i = ae(o, t);
213
- return `"${r}"."${i}"`;
214
- }, Re = (e) => {
215
- const { operator: n, value: t } = e;
208
+ if (!t.includes(".")) {
209
+ const p = Be(t, e);
210
+ return `${Q}."${p}"`;
211
+ }
212
+ const s = t.lastIndexOf("."), o = t.slice(0, s), a = t.slice(s + 1), d = Be(a, e);
213
+ return `"${o}"."${d}"`;
214
+ }, ct = (t) => {
215
+ const { operator: n, value: e } = t;
216
216
  switch (n) {
217
217
  case "in":
218
218
  case "notIn":
219
- return lt(t);
219
+ return Kt(e);
220
220
  case "between":
221
221
  case "notBetween":
222
- return ut(t);
222
+ return Ht(e);
223
223
  case "contains":
224
224
  case "notContains":
225
- return I(`%${t}%`);
225
+ return te(`%${e}%`);
226
226
  case "startsWith":
227
227
  case "notStartsWith":
228
- return I(`${t}%`);
228
+ return te(`${e}%`);
229
229
  case "endsWith":
230
230
  case "notEndsWith":
231
- return I(`%${t}`);
231
+ return te(`%${e}`);
232
232
  default:
233
- return dt(t);
234
- }
235
- }, ct = (e) => it[e] || e, Q = (e, n, t) => e.length === 1 ? t.name : `${n}_${t.name}`, lt = (e) => !Array.isArray(e) || !e.length ? "(NULL)" : `(${e.map(I).join(", ")})`, ut = (e) => {
236
- if (!Array.isArray(e) || e.length < 2) return "";
237
- const [n, t] = e;
238
- if (n == null || t == null) return "";
239
- const s = n instanceof Date ? n.toISOString() : n, r = t instanceof Date ? t.toISOString() : t;
240
- return `${I(s)} and ${I(r)}`;
241
- }, dt = (e) => typeof e == "boolean" ? e ? "1" : "0" : typeof e == "string" ? I(e) : typeof e == "number" ? e.toString() : e instanceof Date ? I(e.toISOString()) : I(e), pt = (e, n, t) => {
242
- const s = e.propertyMap.get(n);
243
- if (!s || s.type !== E.keyValue || typeof t.value != "object" || Array.isArray(t.value)) return null;
244
- const r = Object.entries(t.value).filter(([, a]) => a != null);
245
- if (!r.length) return "";
246
- const o = t.operator === "notContains" ? "NOT LIKE" : "LIKE", i = t.operator === "contains" ? " OR " : " AND ";
247
- return `(${r.map(([a, l]) => {
248
- const d = l instanceof Date ? l.toISOString() : typeof l == "string" ? l : String(l), p = a.replace(/'/g, "''");
249
- return `json_extract(${w}."${s.columnName}", '$.${p}') ${o} ${I(`%${d}%`)}`;
250
- }).join(i)})`;
251
- }, ft = (e, n, t) => {
252
- const s = e.propertyMap.get(n);
253
- if (!s || s.type !== E.stringArray && s.type !== E.numberArray) return null;
254
- const r = Re(t), o = `EXISTS (SELECT 1 FROM json_each(${w}."${s.columnName}") WHERE json_each.value IN ${r})`;
255
- return t.operator === "notIn" ? `NOT ${o}` : o;
256
- }, ht = (e, n, t, s, r) => {
257
- if (t && s && r && (e.operator === "exists" || e.operator === "notExists")) {
258
- const u = gt(e, t, s, (h, f) => {
259
- const y = /* @__PURE__ */ new Map();
260
- return f.propertyMap.forEach((m, _) => {
261
- y.set(_, `"child"."${m.columnName}"`);
262
- }), r(h, y, f, s);
233
+ return Vt(e);
234
+ }
235
+ }, Wt = (t) => Ft[t] || t, be = (t, n, e) => t.length === 1 ? e.name : `${n}_${e.name}`, Kt = (t) => !Array.isArray(t) || !t.length ? "(NULL)" : `(${t.map(te).join(", ")})`, Ht = (t) => {
236
+ if (!Array.isArray(t) || t.length < 2) return "";
237
+ const [n, e] = t;
238
+ if (n == null || e == null) return "";
239
+ const s = n instanceof Date ? n.toISOString() : n, o = e instanceof Date ? e.toISOString() : e;
240
+ return `${te(s)} and ${te(o)}`;
241
+ }, Vt = (t) => typeof t == "boolean" ? t ? "1" : "0" : typeof t == "string" ? te(t) : typeof t == "number" ? t.toString() : t instanceof Date ? te(t.toISOString()) : te(t), Yt = (t, n, e) => {
242
+ const s = t.propertyMap.get(n);
243
+ if (!s || s.type !== D.keyValue || typeof e.value != "object" || Array.isArray(e.value)) return null;
244
+ const o = Object.entries(e.value).filter(([, f]) => f != null);
245
+ if (!o.length) return "";
246
+ const a = e.operator === "notContains" ? "NOT LIKE" : "LIKE", d = e.operator === "contains" ? " OR " : " AND ";
247
+ return `(${o.map(([f, b]) => {
248
+ const A = b instanceof Date ? b.toISOString() : typeof b == "string" ? b : String(b), T = f.replace(/'/g, "''");
249
+ return `json_extract(${Q}."${s.columnName}", '$.${T}') ${a} ${te(`%${A}%`)}`;
250
+ }).join(d)})`;
251
+ }, Qt = (t, n, e) => {
252
+ const s = t.propertyMap.get(n);
253
+ if (!s || s.type !== D.stringArray && s.type !== D.numberArray) return null;
254
+ const o = ct(e), a = `EXISTS (SELECT 1 FROM json_each(${Q}."${s.columnName}") WHERE json_each.value IN ${o})`;
255
+ return e.operator === "notIn" ? `NOT ${a}` : a;
256
+ }, Jt = (t, n, e, s, o) => {
257
+ if (e && s && o && (t.operator === "exists" || t.operator === "notExists")) {
258
+ const I = en(t, e, s, (M, E) => {
259
+ const v = /* @__PURE__ */ new Map();
260
+ return E.propertyMap.forEach((m, N) => {
261
+ v.set(N, `"child"."${m.columnName}"`);
262
+ }), o(M, v, E, s);
263
263
  });
264
- if (u !== null) return u;
265
- }
266
- if (e.operator === "null" || e.operator === "notNull") {
267
- const p = String(e.field), u = n.get(p), h = ge(p, u, t);
268
- return e.operator === "null" ? `${h} IS NULL` : `${h} IS NOT NULL`;
269
- }
270
- const o = e.value === null, i = o ? "" : ct(e.operator).toLowerCase(), c = o ? e.operator === "=" ? "IS NULL" : e.operator === "!=" ? "IS NOT NULL" : "" : Re(e);
271
- if (!c && ["in", "notIn", "between", "notBetween"].includes(e.operator)) return "";
272
- const a = String(e.field), l = n.get(a);
273
- if (t && !a.includes(".") && (e.operator === "contains" || e.operator === "notContains")) {
274
- const p = pt(t, a, e);
275
- if (p !== null) return p;
276
- }
277
- if (t && !a.includes(".") && (e.operator === "in" || e.operator === "notIn")) {
278
- const p = ft(t, a, e);
279
- if (p !== null) return p;
280
- }
281
- return `${ge(a, l, t)} ${i} ${c}`.replace(/\s+/g, " ").trim();
282
- }, ue = (e) => e === w ? e : `"${e}"`, mt = (e, n, t) => {
283
- if (e.kind !== b.ONE_TO_MANY)
264
+ if (I !== null) return I;
265
+ }
266
+ if (t.operator === "null" || t.operator === "notNull") {
267
+ const T = String(t.field), I = n.get(T), M = Ze(T, I, e);
268
+ return t.operator === "null" ? `${M} IS NULL` : `${M} IS NOT NULL`;
269
+ }
270
+ const a = t.value === null, d = a ? "" : Wt(t.operator).toLowerCase(), p = a ? t.operator === "=" ? "IS NULL" : t.operator === "!=" ? "IS NOT NULL" : "" : ct(t);
271
+ if (!p && ["in", "notIn", "between", "notBetween"].includes(t.operator)) return "";
272
+ const f = String(t.field), b = n.get(f);
273
+ if (e && !f.includes(".") && (t.operator === "contains" || t.operator === "notContains")) {
274
+ const T = Yt(e, f, t);
275
+ if (T !== null) return T;
276
+ }
277
+ if (e && !f.includes(".") && (t.operator === "in" || t.operator === "notIn")) {
278
+ const T = Qt(e, f, t);
279
+ if (T !== null) return T;
280
+ }
281
+ return `${Ze(f, b, e)} ${d} ${p}`.replace(/\s+/g, " ").trim();
282
+ }, Ue = (t) => t === Q ? t : `"${t}"`, Gt = (t, n, e) => {
283
+ if (t.kind !== z.ONE_TO_MANY)
284
284
  throw new Error("_build_one_to_many_exists requires ONE_TO_MANY relation");
285
- const s = k(n.tableName, n.namespace), r = "child", o = n.relations.find((a) => a.name === e.mappedProperty);
286
- if (!o)
285
+ const s = le(n.tableName, n.namespace), o = "child", a = n.relations.find((f) => f.name === t.mappedProperty);
286
+ if (!a)
287
287
  throw new Error(
288
- `Cannot find mappedProperty relation "${e.mappedProperty}" in entity "${n.name}"`
288
+ `Cannot find mappedProperty relation "${t.mappedProperty}" in entity "${n.name}"`
289
289
  );
290
- const i = o.columnName;
291
- let c = `EXISTS (SELECT 1 FROM "${s}" "${r}"`;
292
- return c += ` WHERE "${r}"."${i}" = ${w}."id"`, t && (c += ` AND ${t}`), c += ")", c;
293
- }, Et = (e, n, t) => {
294
- const s = e.columnName;
295
- if (!t)
296
- return `${w}."${s}" IS NOT NULL`;
297
- const r = k(n.tableName, n.namespace), o = "child";
298
- let i = `EXISTS (SELECT 1 FROM "${r}" "${o}"`;
299
- return i += ` WHERE ${w}."${s}" = "${o}"."id"`, i += ` AND ${t}`, i += ")", i;
300
- }, yt = (e, n, t, s, r) => {
301
- const o = s.rxdb.schemaManager.findMappedRelation(e, n);
302
- if (o?.relation) {
303
- const i = k(t.tableName, t.namespace), c = "child", a = o.relation.columnName;
304
- let l = `EXISTS (SELECT 1 FROM "${i}" "${c}"`;
305
- return l += ` WHERE "${c}"."${a}" = ${w}."id"`, r && (l += ` AND ${r}`), l += ")", l;
290
+ const d = a.columnName;
291
+ let p = `EXISTS (SELECT 1 FROM "${s}" "${o}"`;
292
+ return p += ` WHERE "${o}"."${d}" = ${Q}."id"`, e && (p += ` AND ${e}`), p += ")", p;
293
+ }, Xt = (t, n, e) => {
294
+ const s = t.columnName;
295
+ if (!e)
296
+ return `${Q}."${s}" IS NOT NULL`;
297
+ const o = le(n.tableName, n.namespace), a = "child";
298
+ let d = `EXISTS (SELECT 1 FROM "${o}" "${a}"`;
299
+ return d += ` WHERE ${Q}."${s}" = "${a}"."id"`, d += ` AND ${e}`, d += ")", d;
300
+ }, zt = (t, n, e, s, o) => {
301
+ const a = s.rxdb.schemaManager.findMappedRelation(t, n);
302
+ if (a?.relation) {
303
+ const d = le(e.tableName, e.namespace), p = "child", f = a.relation.columnName;
304
+ let b = `EXISTS (SELECT 1 FROM "${d}" "${p}"`;
305
+ return b += ` WHERE "${p}"."${f}" = ${Q}."id"`, o && (b += ` AND ${o}`), b += ")", b;
306
306
  } else {
307
- const i = n.columnName;
308
- if (!r)
309
- return `${w}."${i}" IS NOT NULL`;
310
- const c = k(t.tableName, t.namespace), a = "child";
311
- let l = `EXISTS (SELECT 1 FROM "${c}" "${a}"`;
312
- return l += ` WHERE ${w}."${i}" = "${a}"."id"`, l += ` AND ${r}`, l += ")", l;
313
- }
314
- }, _t = (e, n, t, s) => {
315
- const r = k(t.tableName, t.namespace), o = "child", i = n.junctionEntityType;
316
- if (!i)
307
+ const d = n.columnName;
308
+ if (!o)
309
+ return `${Q}."${d}" IS NOT NULL`;
310
+ const p = le(e.tableName, e.namespace), f = "child";
311
+ let b = `EXISTS (SELECT 1 FROM "${p}" "${f}"`;
312
+ return b += ` WHERE ${Q}."${d}" = "${f}"."id"`, b += ` AND ${o}`, b += ")", b;
313
+ }
314
+ }, Zt = (t, n, e, s) => {
315
+ const o = le(e.tableName, e.namespace), a = "child", d = n.junctionEntityType;
316
+ if (!d)
317
317
  throw new Error(`MANY_TO_MANY relation "${n.name}" missing junctionEntityType`);
318
- const c = T(i);
319
- if (!c)
318
+ const p = V(d);
319
+ if (!p)
320
320
  throw new Error("Cannot find metadata for junction entity");
321
- const a = k(c.tableName, c.namespace), l = "junction", d = c.relations.find(
322
- (y) => y.mappedEntity === e.name && y.mappedNamespace === e.namespace
321
+ const f = le(p.tableName, p.namespace), b = "junction", A = p.relations.find(
322
+ (v) => v.mappedEntity === t.name && v.mappedNamespace === t.namespace
323
323
  );
324
- if (!d)
324
+ if (!A)
325
325
  throw new Error(
326
- `Cannot find relation in junction entity ${c.name} pointing to ${e.name}`
326
+ `Cannot find relation in junction entity ${p.name} pointing to ${t.name}`
327
327
  );
328
- const p = c.relations.find(
329
- (y) => y.mappedEntity === t.name && y.mappedNamespace === t.namespace
328
+ const T = p.relations.find(
329
+ (v) => v.mappedEntity === e.name && v.mappedNamespace === e.namespace
330
330
  );
331
- if (!p)
331
+ if (!T)
332
332
  throw new Error(
333
- `Cannot find relation in junction entity ${c.name} pointing to ${t.name}`
333
+ `Cannot find relation in junction entity ${p.name} pointing to ${e.name}`
334
334
  );
335
- const u = d.columnName, h = p.columnName;
336
- let f = `EXISTS (SELECT 1 FROM "${r}" "${o}"`;
337
- return f += ` INNER JOIN "${a}" "${l}"`, f += ` ON "${l}"."${h}" = "${o}"."id"`, f += ` WHERE "${l}"."${u}" = ${w}."id"`, s && (f += ` AND ${s}`), f += ")", f;
338
- }, gt = (e, n, t, s) => {
339
- if (e.operator !== "exists" && e.operator !== "notExists")
335
+ const I = A.columnName, M = T.columnName;
336
+ let E = `EXISTS (SELECT 1 FROM "${o}" "${a}"`;
337
+ return E += ` INNER JOIN "${f}" "${b}"`, E += ` ON "${b}"."${M}" = "${a}"."id"`, E += ` WHERE "${b}"."${I}" = ${Q}."id"`, s && (E += ` AND ${s}`), E += ")", E;
338
+ }, en = (t, n, e, s) => {
339
+ if (t.operator !== "exists" && t.operator !== "notExists")
340
340
  return null;
341
- const r = n.relationMap.get(e.field);
342
- if (!r) return null;
343
- const o = t.rxdb.schemaManager.getEntityMetadata(
344
- r.mappedEntity,
345
- r.mappedNamespace
341
+ const o = n.relationMap.get(t.field);
342
+ if (!o) return null;
343
+ const a = e.rxdb.schemaManager.getEntityMetadata(
344
+ o.mappedEntity,
345
+ o.mappedNamespace
346
346
  );
347
- if (!o)
348
- throw new Error(`Cannot find metadata for entity: ${r.mappedNamespace}.${r.mappedEntity}`);
349
- let i;
350
- e.where && s && (i = s(e.where, o));
351
- let c;
352
- switch (r.kind) {
353
- case b.ONE_TO_MANY:
354
- c = mt(r, o, i);
347
+ if (!a)
348
+ throw new Error(`Cannot find metadata for entity: ${o.mappedNamespace}.${o.mappedEntity}`);
349
+ let d;
350
+ t.where && s && (d = s(t.where, a));
351
+ let p;
352
+ switch (o.kind) {
353
+ case z.ONE_TO_MANY:
354
+ p = Gt(o, a, d);
355
355
  break;
356
- case b.MANY_TO_ONE:
357
- c = Et(r, o, i);
356
+ case z.MANY_TO_ONE:
357
+ p = Xt(o, a, d);
358
358
  break;
359
- case b.ONE_TO_ONE:
360
- c = yt(n, r, o, t, i);
359
+ case z.ONE_TO_ONE:
360
+ p = zt(n, o, a, e, d);
361
361
  break;
362
- case b.MANY_TO_MANY:
363
- c = _t(n, r, o, i);
362
+ case z.MANY_TO_MANY:
363
+ p = Zt(n, o, a, d);
364
364
  break;
365
365
  }
366
- return e.operator === "notExists" ? `NOT ${c}` : c;
367
- }, G = (e, n) => {
368
- if (e.relationAliasMap.has(n))
369
- return e.relationAliasMap.get(n);
370
- const t = n.includes("_") ? n : n.split("_")[0], s = Oe(e, t);
371
- return e.relationAliasMap.set(n, s), s;
372
- }, Nt = (e, n, t, s) => {
373
- const r = t.slice(0, s);
374
- let o = n;
375
- const i = [];
376
- for (const c of r) {
377
- if (!o?.relationMap.has(c))
366
+ return t.operator === "notExists" ? `NOT ${p}` : p;
367
+ }, Ne = (t, n) => {
368
+ if (t.relationAliasMap.has(n))
369
+ return t.relationAliasMap.get(n);
370
+ const e = n.includes("_") ? n : n.split("_")[0], s = lt(t, e);
371
+ return t.relationAliasMap.set(n, s), s;
372
+ }, tn = (t, n, e, s) => {
373
+ const o = e.slice(0, s);
374
+ let a = n;
375
+ const d = [];
376
+ for (const p of o) {
377
+ if (!a?.relationMap.has(p))
378
378
  return { relPairs: [] };
379
- const a = o.relationMap.get(c);
380
- i.push({ metadata: o, relation: a }), o = e.rxdb.schemaManager.getEntityMetadata(a.mappedEntity, a.mappedNamespace);
381
- }
382
- return { metaWalker: o, relPairs: i };
383
- }, $t = (e, n, t, s, r) => {
384
- for (let o = r.length - 1; o > 0; o--) {
385
- const i = r.slice(o);
386
- if (i.length === 0) continue;
387
- const { metaWalker: c, relPairs: a } = Nt(e, t, r, o);
388
- if (!c || a.length === 0) continue;
389
- const l = i[0], d = i.slice(1).join("."), p = c.propertyMap.get(l);
390
- if (p && p.type === E.keyValue) {
391
- const u = r.slice(0, o).join(".");
392
- Ie(e, n, a, u);
393
- const h = a[a.length - 1].relation, f = Q(a, u, h), y = G(n, f), m = d ? `$.${d}` : "$";
394
- return n.fieldAliasMap.set(s, `json_extract("${y}"."${p.columnName}", '${m}')`), !0;
379
+ const f = a.relationMap.get(p);
380
+ d.push({ metadata: a, relation: f }), a = t.rxdb.schemaManager.getEntityMetadata(f.mappedEntity, f.mappedNamespace);
381
+ }
382
+ return { metaWalker: a, relPairs: d };
383
+ }, nn = (t, n, e, s, o) => {
384
+ for (let a = o.length - 1; a > 0; a--) {
385
+ const d = o.slice(a);
386
+ if (d.length === 0) continue;
387
+ const { metaWalker: p, relPairs: f } = tn(t, e, o, a);
388
+ if (!p || f.length === 0) continue;
389
+ const b = d[0], A = d.slice(1).join("."), T = p.propertyMap.get(b);
390
+ if (T && T.type === D.keyValue) {
391
+ const I = o.slice(0, a).join(".");
392
+ ut(t, n, f, I);
393
+ const M = f[f.length - 1].relation, E = be(f, I, M), v = Ne(n, E), m = A ? `$.${A}` : "$";
394
+ return n.fieldAliasMap.set(s, `json_extract("${v}"."${T.columnName}", '${m}')`), !0;
395
395
  }
396
396
  }
397
397
  return !1;
398
- }, Ie = (e, n, t, s) => {
399
- t.forEach(({ metadata: r, relation: o }, i) => {
400
- let c = e.rxdb.schemaManager.findMappedRelation(r, o);
401
- if (!c)
402
- if (o.kind === b.ONE_TO_MANY || o.kind === b.MANY_TO_MANY) {
403
- const p = r.relationMap.get(o.mappedProperty);
404
- p && (c = { metadata: r, relation: p });
405
- } else (o.kind === b.MANY_TO_ONE || o.kind === b.ONE_TO_ONE) && (c = { metadata: r, relation: o });
406
- if (!c) throw new R("mappedRelation not found");
407
- const a = Q(t, s, o), l = G(n, a);
408
- let d = w;
409
- if (i > 0) {
410
- const p = t[i - 1], u = Q(t, s, p.relation);
411
- d = G(n, u);
398
+ }, ut = (t, n, e, s) => {
399
+ e.forEach(({ metadata: o, relation: a }, d) => {
400
+ let p = t.rxdb.schemaManager.findMappedRelation(o, a);
401
+ if (!p)
402
+ if (a.kind === z.ONE_TO_MANY || a.kind === z.MANY_TO_MANY) {
403
+ const T = o.relationMap.get(a.mappedProperty);
404
+ T && (p = { metadata: o, relation: T });
405
+ } else (a.kind === z.MANY_TO_ONE || a.kind === z.ONE_TO_ONE) && (p = { metadata: o, relation: a });
406
+ if (!p) throw new ee("mappedRelation not found");
407
+ const f = be(e, s, a), b = Ne(n, f);
408
+ let A = Q;
409
+ if (d > 0) {
410
+ const T = e[d - 1], I = be(e, s, T.relation);
411
+ A = Ne(n, I);
412
412
  }
413
- switch (o.kind) {
414
- case b.ONE_TO_MANY:
415
- Tt(
413
+ switch (a.kind) {
414
+ case z.ONE_TO_MANY:
415
+ rn(
416
416
  n,
417
- c,
418
- l,
419
- d
417
+ p,
418
+ b,
419
+ A
420
420
  );
421
421
  break;
422
- case b.ONE_TO_ONE:
423
- case b.MANY_TO_ONE:
424
- wt(
422
+ case z.ONE_TO_ONE:
423
+ case z.MANY_TO_ONE:
424
+ sn(
425
425
  n,
426
- c,
427
- l,
428
- d,
429
- o
426
+ p,
427
+ b,
428
+ A,
429
+ a
430
430
  );
431
431
  break;
432
- case b.MANY_TO_MANY:
433
- At(
434
- e,
432
+ case z.MANY_TO_MANY:
433
+ on(
434
+ t,
435
435
  n,
436
- c,
437
- l,
438
- d,
439
- o
436
+ p,
437
+ b,
438
+ A,
439
+ a
440
440
  );
441
441
  break;
442
442
  }
443
443
  });
444
- }, Tt = (e, n, t, s) => {
445
- const r = J(e, n.metadata), o = `"${t}".${n.relation.columnName} = ${ue(s)}.id`;
446
- r.find((c) => c.joinTableName === t && c.on === o) || r.push({
447
- joinTableName: t,
448
- on: o
444
+ }, rn = (t, n, e, s) => {
445
+ const o = Ae(t, n.metadata), a = `"${e}".${n.relation.columnName} = ${Ue(s)}.id`;
446
+ o.find((p) => p.joinTableName === e && p.on === a) || o.push({
447
+ joinTableName: e,
448
+ on: a
449
449
  });
450
- }, wt = (e, n, t, s, r) => {
451
- const o = J(e, n.metadata), i = `"${t}".id = ${ue(s)}.${r.columnName}`;
452
- o.find((a) => a.joinTableName === t && a.on === i) || o.push({
453
- joinTableName: t,
454
- on: i
450
+ }, sn = (t, n, e, s, o) => {
451
+ const a = Ae(t, n.metadata), d = `"${e}".id = ${Ue(s)}.${o.columnName}`;
452
+ a.find((f) => f.joinTableName === e && f.on === d) || a.push({
453
+ joinTableName: e,
454
+ on: d
455
455
  });
456
- }, At = (e, n, t, s, r, o) => {
457
- const i = T(o.junctionEntityType), c = J(n, i), a = Oe(n, `${o.name}_m_n`), l = `"${a}".${t.relation.columnName} = ${ue(r)}.id`;
458
- c.find(
459
- (f) => f.joinTableName === a && f.on === l
460
- ) || c.push({
461
- joinTableName: a,
462
- on: l
456
+ }, on = (t, n, e, s, o, a) => {
457
+ const d = V(a.junctionEntityType), p = Ae(n, d), f = lt(n, `${a.name}_m_n`), b = `"${f}".${e.relation.columnName} = ${Ue(o)}.id`;
458
+ p.find(
459
+ (E) => E.joinTableName === f && E.on === b
460
+ ) || p.push({
461
+ joinTableName: f,
462
+ on: b
463
463
  });
464
- const p = J(n, t.metadata), u = `"${s}".id = "${a}".${o.columnName}`;
465
- p.find((f) => f.joinTableName === s && f.on === u) || p.push({
464
+ const T = Ae(n, e.metadata), I = `"${s}".id = "${f}".${a.columnName}`;
465
+ T.find((E) => E.joinTableName === s && E.on === I) || T.push({
466
466
  joinTableName: s,
467
- on: u
467
+ on: I
468
468
  });
469
- }, J = (e, n) => (e.joinMap.has(n) || e.joinMap.set(n, []), e.joinMap.get(n)), Oe = (e, n) => {
470
- let t = n, s = 1;
471
- for (; e.usedAliases.has(t); )
472
- t = `${n}_${s}`, s++;
473
- return e.usedAliases.add(t), t;
474
- }, St = (e, n) => {
475
- if (e?.length)
476
- return e.map((t) => {
477
- const s = ae(t.field, n);
478
- return `${w}."${s}" ${t.sort}`;
469
+ }, Ae = (t, n) => (t.joinMap.has(n) || t.joinMap.set(n, []), t.joinMap.get(n)), lt = (t, n) => {
470
+ let e = n, s = 1;
471
+ for (; t.usedAliases.has(e); )
472
+ e = `${n}_${s}`, s++;
473
+ return t.usedAliases.add(e), e;
474
+ }, an = (t, n) => {
475
+ if (t?.length)
476
+ return t.map((e) => {
477
+ const s = Be(e.field, n);
478
+ return `${Q}."${s}" ${e.sort}`;
479
479
  }).join(", ");
480
- }, U = (e, n = /* @__PURE__ */ new Map(), t, s) => {
481
- if (!e?.rules) return "";
482
- const r = e.rules.map(
483
- (o) => fe(o) ? U(o, n, t, s) : ht(o, n, t, s, U)
480
+ }, he = (t, n = /* @__PURE__ */ new Map(), e, s) => {
481
+ if (!t?.rules) return "";
482
+ const o = t.rules.map(
483
+ (a) => Ye(a) ? he(a, n, e, s) : Jt(a, n, e, s, he)
484
484
  ).filter(Boolean);
485
- return r.length ? r.length === 1 ? r[0] : `(${r.join(fe(e) ? ` ${e.combinator} ` : " ")})` : "";
486
- }, Me = (e) => {
487
- const { tableName: n, where: t, limit: s, offset: r, orderBy: o, join: i, hasJoin: c, metadata: a } = e;
488
- let l = `${w}.rowid as ${q}, ${w}.*`;
489
- if (a.features?.tree?.hasChildren && a.features?.tree?.type === "adjacency-list") {
490
- const u = a.relationMap.get("parent").columnName;
491
- l += `, EXISTS(SELECT 1 FROM "${n}" __sub WHERE __sub."${u}" = ${w}."id") AS "hasChildren"`;
492
- }
493
- const d = [`SELECT ${c ? "DISTINCT " : ""}${l} FROM "${n}" ${w}`];
494
- return i && d.push(i), t && d.push(` WHERE ${t}`), o && d.push(` ORDER BY ${o}`), s && d.push(` LIMIT ${s}`), r && d.push(` OFFSET ${r}`), d.join("") + ";";
495
- }, Ce = (e, n, t) => {
485
+ return o.length ? o.length === 1 ? o[0] : `(${o.join(Ye(t) ? ` ${t.combinator} ` : " ")})` : "";
486
+ }, ft = (t) => {
487
+ const { tableName: n, where: e, limit: s, offset: o, orderBy: a, join: d, hasJoin: p, metadata: f } = t;
488
+ let b = `${Q}.rowid as ${ie}, ${Q}.*`;
489
+ if (f.features?.tree?.hasChildren && f.features?.tree?.type === "adjacency-list") {
490
+ const I = f.relationMap.get("parent").columnName;
491
+ b += `, EXISTS(SELECT 1 FROM "${n}" __sub WHERE __sub."${I}" = ${Q}."id") AS "hasChildren"`;
492
+ }
493
+ const A = [`SELECT ${p ? "DISTINCT " : ""}${b} FROM "${n}" ${Q}`];
494
+ return d && A.push(d), e && A.push(` WHERE ${e}`), a && A.push(` ORDER BY ${a}`), s && A.push(` LIMIT ${s}`), o && A.push(` OFFSET ${o}`), A.join("") + ";";
495
+ }, dt = (t, n, e) => {
496
496
  const s = {
497
497
  joinMap: /* @__PURE__ */ new Map(),
498
498
  usedAliases: /* @__PURE__ */ new Set(),
499
499
  fieldAliasMap: /* @__PURE__ */ new Map(),
500
500
  relationAliasMap: /* @__PURE__ */ new Map()
501
501
  };
502
- Je(t, (o, i, c) => {
503
- const a = i;
504
- o !== "field" || !a.includes(".") || Rt(e, s, n, a, c);
502
+ Ct(e, (a, d, p) => {
503
+ const f = d;
504
+ a !== "field" || !f.includes(".") || un(t, s, n, f, p);
505
505
  });
506
- const r = [];
507
- for (const [o, i] of s.joinMap.entries()) {
508
- const c = A(o);
509
- for (const a of i)
510
- r.push(` LEFT JOIN "${c}" "${a.joinTableName}" ON ${a.on}`);
511
- }
512
- return { joinSQL: r.join(""), fieldAliasMap: s.fieldAliasMap };
513
- }, bt = (e, n, t, s) => {
506
+ const o = [];
507
+ for (const [a, d] of s.joinMap.entries()) {
508
+ const p = X(a);
509
+ for (const f of d)
510
+ o.push(` LEFT JOIN "${p}" "${f.joinTableName}" ON ${f.on}`);
511
+ }
512
+ return { joinSQL: o.join(""), fieldAliasMap: s.fieldAliasMap };
513
+ }, cn = (t, n, e, s) => {
514
514
  if (s.length <= 1) return !1;
515
- const [r, ...o] = s, i = n.propertyMap.get(r);
516
- if (i && i.type === E.keyValue && o.length > 0) {
517
- const c = o.join(".");
518
- return e.fieldAliasMap.set(t, `json_extract(${w}."${i.columnName}", '$.${c}')`), !0;
515
+ const [o, ...a] = s, d = n.propertyMap.get(o);
516
+ if (d && d.type === D.keyValue && a.length > 0) {
517
+ const p = a.join(".");
518
+ return t.fieldAliasMap.set(e, `json_extract(${Q}."${d.columnName}", '$.${p}')`), !0;
519
519
  }
520
520
  return !1;
521
- }, Rt = (e, n, t, s, r) => {
522
- const o = s.split(".");
521
+ }, un = (t, n, e, s, o) => {
522
+ const a = s.split(".");
523
523
  try {
524
- const i = e.rxdb.schemaManager.getFieldRelations(t, s);
525
- if (i.isForeignKey) {
526
- r.field = i.propertyName;
524
+ const d = t.rxdb.schemaManager.getFieldRelations(e, s);
525
+ if (d.isForeignKey) {
526
+ o.field = d.propertyName;
527
527
  return;
528
528
  }
529
- const c = s.replace(`.${i.propertyName}`, "");
530
- Ie(e, n, i.relations, c);
531
- const a = i.relations[i.relations.length - 1], l = Q(i.relations, c, a.relation), d = G(n, l);
532
- n.fieldAliasMap.set(s, `"${d}"."${i.property.columnName}"`);
529
+ const p = s.replace(`.${d.propertyName}`, "");
530
+ ut(t, n, d.relations, p);
531
+ const f = d.relations[d.relations.length - 1], b = be(d.relations, p, f.relation), A = Ne(n, b);
532
+ n.fieldAliasMap.set(s, `"${A}"."${d.property.columnName}"`);
533
533
  return;
534
534
  } catch {
535
535
  }
536
- bt(n, t, s, o) || $t(e, n, t, s, o);
537
- }, It = (e, n) => {
538
- const t = A(e), s = [n.id];
536
+ cn(n, e, s, a) || nn(t, n, e, s, a);
537
+ }, ln = (t, n) => {
538
+ const e = X(t), s = [n.id];
539
539
  return {
540
- sql: `DELETE FROM "${t}" WHERE id = ?;`,
540
+ sql: `DELETE FROM "${e}" WHERE id = ?;`,
541
541
  params: s
542
542
  };
543
- }, Le = (e, n, t) => {
544
- const s = A(e), r = be(e, n);
545
- t?.userId && (e.propertyMap.has("createdBy") && (r.createdBy = t.userId), e.propertyMap.has("updatedBy") && (r.updatedBy = t.userId));
546
- const o = /* @__PURE__ */ new Date();
547
- e.propertyMap.has("createdAt") && r.createdAt === void 0 && (r.createdAt = t?.createdAt ?? o), e.propertyMap.has("updatedAt") && r.updatedAt === void 0 && (r.updatedAt = t?.updatedAt ?? o);
548
- const i = le(e, r), c = Object.keys(i), a = Array(c.length).fill("?").join(","), l = Object.values(i);
549
- let p = `${t?.useReplace ? "INSERT OR REPLACE" : "INSERT"} INTO "${s}" (${c.join(",")}) VALUES (${a})`;
550
- return t?.returning !== !1 ? p += ` RETURNING rowid as ${q}, *;` : p += ";", {
551
- sql: p,
552
- params: l
543
+ }, pt = (t, n, e) => {
544
+ const s = X(t), o = at(t, n);
545
+ e?.userId && (t.propertyMap.has("createdBy") && (o.createdBy = e.userId), t.propertyMap.has("updatedBy") && (o.updatedBy = e.userId));
546
+ const a = /* @__PURE__ */ new Date();
547
+ t.propertyMap.has("createdAt") && o.createdAt === void 0 && (o.createdAt = e?.createdAt ?? a), t.propertyMap.has("updatedAt") && o.updatedAt === void 0 && (o.updatedAt = e?.updatedAt ?? a);
548
+ const d = ke(t, o), p = Object.keys(d), f = Array(p.length).fill("?").join(","), b = Object.values(d);
549
+ let T = `${e?.useReplace ? "INSERT OR REPLACE" : "INSERT"} INTO "${s}" (${p.join(",")}) VALUES (${f})`;
550
+ return e?.returning !== !1 ? T += ` RETURNING rowid as ${ie}, *;` : T += ";", {
551
+ sql: T,
552
+ params: b
553
553
  };
554
- }, de = (e, n, t, s) => {
555
- const r = at(e, t);
556
- e.propertyMap.has("updatedAt") && (r.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && e.propertyMap.has("updatedBy") && (r.updatedBy = s.userId);
557
- const o = le(e, r), i = Object.keys(o).map((u) => `${u} = ?`).join(","), c = [...Object.values(o)], a = A(e), l = Array.isArray(n), d = l ? n : [n];
558
- let p = `UPDATE "${a}" SET ${i} WHERE id `;
559
- return l ? p += `in (${d.map((u) => I(u.id)).join(",")})` : (c.push(n.id), p += "= ?"), s?.returning !== !1 ? p += ` RETURNING rowid as ${q}, *;` : p += ";", {
560
- sql: p,
561
- params: c
554
+ }, Pe = (t, n, e, s) => {
555
+ const o = Pt(t, e);
556
+ t.propertyMap.has("updatedAt") && (o.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && t.propertyMap.has("updatedBy") && (o.updatedBy = s.userId);
557
+ const a = ke(t, o), d = Object.keys(a).map((I) => `${I} = ?`).join(","), p = [...Object.values(a)], f = X(t), b = Array.isArray(n), A = b ? n : [n];
558
+ let T = `UPDATE "${f}" SET ${d} WHERE id `;
559
+ return b ? T += `in (${A.map((I) => te(I.id)).join(",")})` : (p.push(n.id), T += "= ?"), s?.returning !== !1 ? T += ` RETURNING rowid as ${ie}, *;` : T += ";", {
560
+ sql: T,
561
+ params: p
562
562
  };
563
- }, Ot = (e, n, t) => {
564
- if (t.groupBy)
565
- throw new R("groupBy not supported yet");
566
- const { joinSQL: s, fieldAliasMap: r } = Ce(e, n, t.where), o = A(n), i = U(t.where, r, n, e), c = [`SELECT COUNT(${w}.rowid) AS count FROM "${o}" ${w}`];
567
- return s && c.push(s), i && c.push(` WHERE ${i}`), { sql: c.join("") };
568
- }, ie = (e, n, t) => {
569
- const { joinSQL: s, fieldAliasMap: r } = Ce(e, n, t.where);
570
- return { sql: Me({
571
- tableName: A(n),
572
- where: U(t.where, r, n, e),
573
- orderBy: St(t.orderBy, n),
563
+ }, fn = (t, n, e) => {
564
+ if (e.groupBy)
565
+ throw new ee("groupBy not supported yet");
566
+ const { joinSQL: s, fieldAliasMap: o } = dt(t, n, e.where), a = X(n), d = he(e.where, o, n, t), p = [`SELECT COUNT(${Q}.rowid) AS count FROM "${a}" ${Q}`];
567
+ return s && p.push(s), d && p.push(` WHERE ${d}`), { sql: p.join("") };
568
+ }, De = (t, n, e) => {
569
+ const { joinSQL: s, fieldAliasMap: o } = dt(t, n, e.where);
570
+ return { sql: ft({
571
+ tableName: X(n),
572
+ where: he(e.where, o, n, t),
573
+ orderBy: an(e.orderBy, n),
574
574
  join: s,
575
575
  hasJoin: !!s,
576
576
  metadata: n,
577
- limit: t.limit,
578
- offset: t.offset
577
+ limit: e.limit,
578
+ offset: e.offset
579
579
  }) };
580
- }, Mt = (e, n) => {
581
- const t = n.map(() => "?").join(",");
582
- return { sql: Me({
583
- tableName: A(e),
584
- where: `${q} IN (${t})`,
585
- metadata: e
580
+ }, dn = (t, n) => {
581
+ const e = n.map(() => "?").join(",");
582
+ return { sql: ft({
583
+ tableName: X(t),
584
+ where: `${ie} IN (${e})`,
585
+ metadata: t
586
586
  }), params: n };
587
- }, X = (e, n, t, s = !1, r = !1) => {
588
- const o = [], i = T(n), c = e.rxdb.entityManager;
589
- return t.results.forEach(({ columns: a, rows: l }) => {
590
- const d = a.findIndex((u) => u === "id"), p = a.findIndex((u) => u === q);
591
- l.forEach((u) => {
592
- const h = u[d];
593
- let f;
594
- if (e.rxdb.entityManager.hasEntityRef(n, h)) {
595
- f = c.getEntityRef(n, h);
596
- const _ = oe(i, a, u);
597
- if (i.computedPropertyMap.forEach((N, $) => {
598
- $ in _ && (f[$] = _[$]);
587
+ }, Ie = (t, n, e, s = !1, o = !1) => {
588
+ const a = [], d = V(n), p = t.rxdb.entityManager;
589
+ return e.results.forEach(({ columns: f, rows: b }) => {
590
+ const A = f.findIndex((I) => I === "id"), T = f.findIndex((I) => I === ie);
591
+ b.forEach((I) => {
592
+ const M = I[A];
593
+ let E;
594
+ if (t.rxdb.entityManager.hasEntityRef(n, M)) {
595
+ E = p.getEntityRef(n, M);
596
+ const N = je(d, f, I);
597
+ if (d.computedPropertyMap.forEach((S, $) => {
598
+ $ in N && (E[$] = N[$]);
599
599
  }), s) {
600
- const N = D(f);
601
- N.origin = { ..._ }, Object.assign(f, _);
600
+ const S = ae(E);
601
+ S.origin = { ...N }, Object.assign(E, N);
602
602
  }
603
603
  } else {
604
- if (r)
604
+ if (o)
605
605
  return;
606
606
  {
607
- const _ = oe(i, a, u);
608
- f = c.createEntityRef(n, _);
607
+ const N = je(d, f, I);
608
+ E = p.createEntityRef(n, N);
609
609
  }
610
610
  }
611
- o.push(f);
612
- const m = D(f);
613
- if (m.local = !0, m.modified = !1, p !== -1) {
614
- const _ = BigInt(u[p]);
615
- e.cacheRowIdEntity(_, f);
611
+ a.push(E);
612
+ const m = ae(E);
613
+ if (m.local = !0, m.modified = !1, T !== -1) {
614
+ const N = BigInt(I[T]);
615
+ t.cacheRowIdEntity(N, E);
616
616
  }
617
617
  });
618
- }), o;
619
- }, Ct = (e, n, t) => {
620
- t.forEach((s) => {
621
- if (e.rxdb.entityManager.hasEntityRef(n, s)) {
622
- const r = e.rxdb.entityManager.getEntityRef(n, s), o = D(r);
623
- o.local = !1, o.removed = !0, o.modified = !1;
618
+ }), a;
619
+ }, pn = (t, n, e) => {
620
+ e.forEach((s) => {
621
+ if (t.rxdb.entityManager.hasEntityRef(n, s)) {
622
+ const o = t.rxdb.entityManager.getEntityRef(n, s), a = ae(o);
623
+ a.local = !1, a.removed = !0, a.modified = !1;
624
624
  }
625
625
  });
626
626
  };
627
- class Lt extends Be {
628
- constructor(n, t) {
629
- super(n.rxdb, t), this.adapter = n, this.metadata = T(t);
627
+ class hn extends Nt {
628
+ constructor(n, e) {
629
+ super(n.rxdb, e), this.adapter = n, this.metadata = V(e);
630
630
  }
631
631
  metadata;
632
632
  async findByRowIds(n) {
633
- const { sql: t, params: s } = Mt(this.metadata, n), r = await this.adapter.query(t, s);
634
- return this.addQueryCache(r);
633
+ const { sql: e, params: s } = dn(this.metadata, n), o = await this.adapter.query(e, s);
634
+ return this.addQueryCache(o);
635
635
  }
636
636
  /**
637
637
  * 添加缓存
638
638
  * @param sqliteSuccessResult
639
639
  * @param forcedUpdate 强制刷新,在数据有的情况下也会更新数据,在修改数据的情况下需要
640
640
  */
641
- addQueryCache(n, t = !1) {
642
- return X(this.adapter, this.EntityType, n, t);
641
+ addQueryCache(n, e = !1) {
642
+ return Ie(this.adapter, this.EntityType, n, e);
643
643
  }
644
644
  }
645
- class je extends Lt {
645
+ class ht extends hn {
646
646
  async get(n) {
647
- const t = {
647
+ const e = {
648
648
  where: {
649
649
  combinator: "and",
650
650
  rules: [{ field: "id", operator: "=", value: n }]
651
651
  }
652
- }, s = await this.findOne(t);
653
- if (!s) throw new R(`Entity (${n}) not found`);
652
+ }, s = await this.findOne(e);
653
+ if (!s) throw new ee(`Entity (${n}) not found`);
654
654
  return s;
655
655
  }
656
656
  async findOne(n) {
657
657
  return (await this.find({ ...n, limit: 1, offset: 0 }))[0];
658
658
  }
659
659
  async find(n) {
660
- const { sql: t, params: s } = ie(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
661
- return this.addQueryCache(r);
660
+ const { sql: e, params: s } = De(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
661
+ return this.addQueryCache(o);
662
662
  }
663
663
  async count(n) {
664
- const { sql: t, params: s } = Ot(this.adapter, this.metadata, n);
665
- return (await this.adapter.query(t, s)).results[0].rows[0][0];
664
+ const { sql: e, params: s } = fn(this.adapter, this.metadata, n);
665
+ return (await this.adapter.query(e, s)).results[0].rows[0][0];
666
666
  }
667
667
  async create(n) {
668
- const { sql: t, params: s } = Le(this.metadata, n, this.rxdb.context), r = await this.adapter.query(t, s);
669
- return this.addQueryCache(r, !0), n;
670
- }
671
- async update(n, t) {
672
- const { sql: s, params: r } = de(this.metadata, n, t, this.rxdb.context), o = await this.adapter.query(s, r);
668
+ const { sql: e, params: s } = pt(this.metadata, n, this.rxdb.context), o = await this.adapter.query(e, s);
673
669
  return this.addQueryCache(o, !0), n;
674
670
  }
671
+ async update(n, e) {
672
+ const { sql: s, params: o } = Pe(this.metadata, n, e, this.rxdb.context), a = await this.adapter.query(s, o);
673
+ return this.addQueryCache(a, !0), n;
674
+ }
675
675
  async remove(n) {
676
- const t = D(n), s = () => {
677
- t.origin = structuredClone({ ...n }), t.modified = !1, t.removed = !0;
676
+ const e = ae(n), s = () => {
677
+ e.origin = structuredClone({ ...n }), e.modified = !1, e.removed = !0;
678
678
  };
679
- if (t.local === !0) {
680
- const { sql: o, params: i } = It(this.metadata, n);
681
- return await this.adapter.query(o, i), s(), n;
679
+ if (e.local === !0) {
680
+ const { sql: a, params: d } = ln(this.metadata, n);
681
+ return await this.adapter.query(a, d), s(), n;
682
682
  }
683
- const r = T(n);
684
- throw new R(`Remove Error${r.name}(${n.id}) not saved local.`);
683
+ const o = V(n);
684
+ throw new ee(`Remove Error${o.name}(${n.id}) not saved local.`);
685
685
  }
686
686
  }
687
- var v = /* @__PURE__ */ ((e) => (e[e.SQLITE_DELETE = 9] = "SQLITE_DELETE", e[e.SQLITE_INSERT = 18] = "SQLITE_INSERT", e[e.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", e))(v || {});
688
- const jt = (e) => {
689
- switch (e) {
687
+ var ce = /* @__PURE__ */ ((t) => (t[t.SQLITE_DELETE = 9] = "SQLITE_DELETE", t[t.SQLITE_INSERT = 18] = "SQLITE_INSERT", t[t.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", t))(ce || {});
688
+ const mn = (t) => {
689
+ switch (t) {
690
690
  case 18:
691
691
  return "INSERT";
692
692
  case 9:
@@ -694,10 +694,10 @@ const jt = (e) => {
694
694
  case 23:
695
695
  return "UPDATE";
696
696
  }
697
- }, xt = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").then((e) => e.default), Dt = () => import("wa-sqlite/dist/wa-sqlite.mjs").then((e) => e.default), vt = [
697
+ }, yn = "sqlite", gn = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").then((t) => t.default), En = () => import("wa-sqlite/dist/wa-sqlite.mjs").then((t) => t.default), _n = [
698
698
  {
699
699
  name: "MemoryVFS",
700
- vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((e) => e.MemoryVFS),
700
+ vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((t) => t.MemoryVFS),
701
701
  sync: !0,
702
702
  async: !0,
703
703
  worker: !0,
@@ -707,7 +707,7 @@ const jt = (e) => {
707
707
  },
708
708
  {
709
709
  name: "MemoryAsyncVFS",
710
- vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((e) => e.MemoryAsyncVFS),
710
+ vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((t) => t.MemoryAsyncVFS),
711
711
  sync: !1,
712
712
  async: !0,
713
713
  worker: !0,
@@ -717,7 +717,7 @@ const jt = (e) => {
717
717
  },
718
718
  {
719
719
  name: "IDBBatchAtomicVFS",
720
- vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((e) => e.IDBBatchAtomicVFS),
720
+ vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((t) => t.IDBBatchAtomicVFS),
721
721
  vfsOptions: { lockPolicy: "shared+hint" },
722
722
  sync: !1,
723
723
  async: !0,
@@ -728,7 +728,7 @@ const jt = (e) => {
728
728
  },
729
729
  {
730
730
  name: "OPFSAdaptiveVFS",
731
- vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((e) => e.OPFSAdaptiveVFS),
731
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((t) => t.OPFSAdaptiveVFS),
732
732
  vfsOptions: { lockPolicy: "shared+hint" },
733
733
  sync: !1,
734
734
  async: !0,
@@ -739,7 +739,7 @@ const jt = (e) => {
739
739
  },
740
740
  {
741
741
  name: "AccessHandlePoolVFS",
742
- vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((e) => e.AccessHandlePoolVFS),
742
+ vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((t) => t.AccessHandlePoolVFS),
743
743
  sync: !0,
744
744
  async: !0,
745
745
  worker: !0,
@@ -749,7 +749,7 @@ const jt = (e) => {
749
749
  },
750
750
  {
751
751
  name: "OPFSAnyContextVFS",
752
- vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((e) => e.OPFSAnyContextVFS),
752
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((t) => t.OPFSAnyContextVFS),
753
753
  vfsOptions: { lockPolicy: "shared+hint" },
754
754
  sync: !1,
755
755
  async: !0,
@@ -760,7 +760,7 @@ const jt = (e) => {
760
760
  },
761
761
  {
762
762
  name: "OPFSCoopSyncVFS",
763
- vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((e) => e.OPFSCoopSyncVFS),
763
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((t) => t.OPFSCoopSyncVFS),
764
764
  sync: !0,
765
765
  async: !0,
766
766
  worker: !0,
@@ -770,7 +770,7 @@ const jt = (e) => {
770
770
  },
771
771
  {
772
772
  name: "OPFSPermutedVFS",
773
- vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((e) => e.OPFSPermutedVFS),
773
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((t) => t.OPFSPermutedVFS),
774
774
  sync: !1,
775
775
  async: !0,
776
776
  worker: !0,
@@ -778,80 +778,80 @@ const jt = (e) => {
778
778
  jsContext: !1,
779
779
  multipleConnections: !0
780
780
  }
781
- ], xe = (e) => {
782
- const n = vt.find((o) => o.name === e.vfs), { vfs: t, async: s, worker: r } = e;
783
- if (!n) throw new R(`vfs ${t} not found`);
781
+ ], mt = (t) => {
782
+ const n = _n.find((a) => a.name === t.vfs), { vfs: e, async: s, worker: o } = t;
783
+ if (!n) throw new ee(`vfs ${e} not found`);
784
784
  if (s !== void 0) {
785
785
  if (s && !n.async)
786
- throw new R(`vfs ${t} not support async: true`);
786
+ throw new ee(`vfs ${e} not support async: true`);
787
787
  if (!s && !n.sync)
788
- throw new R(`vfs ${t} not support async: false`);
788
+ throw new ee(`vfs ${e} not support async: false`);
789
789
  }
790
- if (r && !n.worker) throw new R(`vfs ${t} not support worker`);
791
- if (!r && !n.jsContext) throw new R(`vfs ${t} only support worker`);
790
+ if (o && !n.worker) throw new ee(`vfs ${e} not support worker`);
791
+ if (!o && !n.jsContext) throw new ee(`vfs ${e} only support worker`);
792
792
  return n;
793
- }, Pt = async (e) => {
794
- const n = xe(e), t = e.async ?? !0;
793
+ }, wn = async (t) => {
794
+ const n = mt(t), e = t.async ?? !0;
795
795
  let s;
796
- t ? s = qt : s = Dt;
797
- const [r, o] = await Promise.all([s(), n.vfsModule()]), i = {};
798
- e.locateFile ? i.locateFile = e.locateFile : e.wasmPath && (i.locateFile = () => e.wasmPath);
799
- const c = await r(i), a = et(c), l = await o.create(e.vfs, c, n.vfsOptions);
800
- return a.vfs_register(l, !0), a;
796
+ e ? s = gn : s = En;
797
+ const [o, a] = await Promise.all([s(), n.vfsModule()]), d = {};
798
+ t.locateFile ? d.locateFile = t.locateFile : t.wasmPath && (d.locateFile = () => t.wasmPath);
799
+ const p = await o(d), f = jt(p), b = await a.create(t.vfs, p, n.vfsOptions);
800
+ return f.vfs_register(b, !0), f;
801
801
  };
802
- async function kt(e, n, t, s) {
803
- const r = performance.now(), o = [];
804
- let i = 0, c = s;
805
- const a = {
806
- sql: t,
807
- results: o
802
+ async function bn(t, n, e, s) {
803
+ const o = performance.now(), a = [];
804
+ let d = 0, p = s;
805
+ const f = {
806
+ sql: e,
807
+ results: a
808
808
  };
809
- for await (const l of e.statements(n, t)) {
810
- c && (e.reset(l), e.bind_collection(l, c), c = void 0);
811
- const d = [];
812
- for (; await e.step(l) === tt; ) {
813
- const u = e.row(l);
814
- d.push(u);
809
+ for await (const b of t.statements(n, e)) {
810
+ p && (t.reset(b), t.bind_collection(b, p), p = void 0);
811
+ const A = [];
812
+ for (; await t.step(b) === Bt; ) {
813
+ const I = t.row(b);
814
+ A.push(I);
815
815
  }
816
- const p = e.column_names(l);
817
- p.length && o.push({ columns: p, rows: d }), i += e.changes(n);
816
+ const T = t.column_names(b);
817
+ T.length && a.push({ columns: T, rows: A }), d += t.changes(n);
818
818
  }
819
819
  return {
820
- ...a,
821
- rowsAffected: i,
822
- elapsed: performance.now() - r
820
+ ...f,
821
+ rowsAffected: d,
822
+ elapsed: performance.now() - o
823
823
  };
824
824
  }
825
- const Ft = {
825
+ const Nn = {
826
826
  BALANCED: 16
827
- }, Ne = Ft.BALANCED, Bt = 50 * 1024, Ut = /* @__PURE__ */ new Set(["public$rxdb_change", "public$rxdb_branch", "public$rxdb_migration"]);
828
- class Wt extends Xe {
827
+ }, et = Nn.BALANCED, An = 50 * 1024, In = /* @__PURE__ */ new Set(["public$rxdb_change", "public$rxdb_branch", "public$rxdb_migration"]);
828
+ class Tn extends Lt {
829
829
  #n;
830
830
  #e;
831
- #a = !1;
831
+ #i = !1;
832
832
  #o = !1;
833
833
  #c;
834
- #s = [];
834
+ #r = [];
835
835
  #t;
836
- #r = Ne;
836
+ #s = et;
837
837
  /**
838
838
  * 初始化数据库
839
839
  *
840
840
  * @param dbName - 数据库名称(不含 .sqlite 扩展名)
841
841
  * @param options - 加载选项
842
842
  */
843
- async init(n, t) {
844
- if (this.#a) return;
845
- this.#a = !0, this.#c = new we(1);
846
- const s = await Pt(t), r = `${n}.sqlite`;
847
- this.#e = await s.open_v2(r), this.#n = s, this.#u(s, this.#e), this.#r = t?.batchTimeout ?? Ne;
848
- const o = t?.cacheSizeKb ?? Bt;
843
+ async init(n, e) {
844
+ if (this.#i) return;
845
+ this.#i = !0, this.#c = new st(1);
846
+ const s = await wn(e), o = `${n}.sqlite`;
847
+ this.#e = await s.open_v2(o), this.#n = s, this.#l(s, this.#e), this.#s = e?.batchTimeout ?? et;
848
+ const a = e?.cacheSizeKb ?? An;
849
849
  await this.execute(`
850
850
  PRAGMA temp_store = memory;
851
851
  PRAGMA foreign_keys = ON;
852
- PRAGMA cache_size = -${o};
853
- `), this.#n.update_hook(this.#e, (i, c, a, l) => {
854
- !c || !a || !Ut.has(a) || (this.#s.push({ type: i, dbName: c, tableName: a, rowId: l }), this.#i());
852
+ PRAGMA cache_size = -${a};
853
+ `), this.#n.update_hook(this.#e, (d, p, f, b) => {
854
+ !p || !f || !In.has(f) || (this.#r.push({ type: d, dbName: p, tableName: f, rowId: b }), this.#a());
855
855
  });
856
856
  }
857
857
  /**
@@ -861,7 +861,7 @@ class Wt extends Xe {
861
861
  */
862
862
  async version() {
863
863
  const n = await this.execute("SELECT sqlite_version()");
864
- return Ye(n, "results[0].rows[0][0]");
864
+ return Mt(n, "results[0].rows[0][0]");
865
865
  }
866
866
  /**
867
867
  * 断开数据库连接
@@ -869,7 +869,7 @@ class Wt extends Xe {
869
869
  * 等待所有待执行任务完成后关闭数据库连接
870
870
  */
871
871
  async disconnect() {
872
- this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#s.length = 0, this.#n.update_hook(this.#e, () => {
872
+ this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#r.length = 0, this.#n.update_hook(this.#e, () => {
873
873
  }), await this.#c.waitForAll(), await this.#n.close(this.#e);
874
874
  }
875
875
  /**
@@ -890,38 +890,38 @@ class Wt extends Xe {
890
890
  * );
891
891
  * ```
892
892
  */
893
- async execute(n, t) {
893
+ async execute(n, e) {
894
894
  if (this.#o)
895
895
  throw new Error("SqliteClient has been disconnected");
896
- return this.#c.addTask(() => kt(this.#n, this.#e, n, t));
896
+ return this.#c.addTask(() => bn(this.#n, this.#e, n, e));
897
897
  }
898
898
  /**
899
899
  * 调度批量发送
900
900
  * 使用防抖机制合并连续的变更事件
901
901
  */
902
- #i() {
902
+ #a() {
903
903
  this.#t && clearTimeout(this.#t), this.#t = setTimeout(() => {
904
- this.#l(), this.#t = void 0;
905
- }, this.#r);
904
+ this.#u(), this.#t = void 0;
905
+ }, this.#s);
906
906
  }
907
907
  /**
908
908
  * 刷新待发送事件
909
909
  * 将同类型、同表的事件合并后分发
910
910
  */
911
- #l() {
912
- const n = Object.groupBy(this.#s, (t) => `${t.type}_${t.dbName}_${t.tableName}`);
913
- for (const t of Object.values(n)) {
914
- if (!t || t.length === 0) continue;
915
- const s = t[0];
911
+ #u() {
912
+ const n = Object.groupBy(this.#r, (e) => `${e.type}_${e.dbName}_${e.tableName}`);
913
+ for (const e of Object.values(n)) {
914
+ if (!e || e.length === 0) continue;
915
+ const s = e[0];
916
916
  this.dispatchEvent(s.type, {
917
917
  type: s.type,
918
918
  dbName: s.dbName,
919
919
  tableName: s.tableName,
920
- rowIds: t.map((r) => r.rowId),
920
+ rowIds: e.map((o) => o.rowId),
921
921
  recordAt: /* @__PURE__ */ new Date()
922
922
  });
923
923
  }
924
- this.#s.length = 0;
924
+ this.#r.length = 0;
925
925
  }
926
926
  /**
927
927
  * 注册自定义 SQL 函数
@@ -930,751 +930,1535 @@ class Wt extends Xe {
930
930
  * - `regexp(pattern, text)` - 正则匹配
931
931
  * - `regexp_replace(pattern, text, replacement[, flags])` - 正则替换
932
932
  */
933
- #u(n, t) {
934
- Ht(n, t), Vt(n, t);
933
+ #l(n, e) {
934
+ Sn(n, e), vn(n, e);
935
935
  }
936
936
  }
937
- const W = /* @__PURE__ */ new Map(), Kt = 128;
938
- function qe(e, n = "") {
939
- const t = `${e}\0${n}`;
940
- let s = W.get(t);
937
+ const ye = /* @__PURE__ */ new Map(), $n = 128;
938
+ function yt(t, n = "") {
939
+ const e = `${t}\0${n}`;
940
+ let s = ye.get(e);
941
941
  if (!s) {
942
- if (e.length > 1e3) throw new Error("regexp pattern too long");
943
- s = new RegExp(e, n), W.size >= Kt && W.clear(), W.set(t, s);
942
+ if (t.length > 1e3) throw new Error("regexp pattern too long");
943
+ s = new RegExp(t, n), ye.size >= $n && ye.clear(), ye.set(e, s);
944
944
  }
945
945
  return s;
946
946
  }
947
- function Ht(e, n) {
948
- e.create_function(n, "regexp", 2, Ae | Se, 0, (t, s) => {
947
+ function Sn(t, n) {
948
+ t.create_function(n, "regexp", 2, ot | it, 0, (e, s) => {
949
949
  try {
950
- const r = qe(e.value_text(s[0])), o = e.value_text(s[1]);
951
- e.result(t, r.test(o) ? 1 : 0);
950
+ const o = yt(t.value_text(s[0])), a = t.value_text(s[1]);
951
+ t.result(e, o.test(a) ? 1 : 0);
952
952
  } catch {
953
- e.result(t, 0);
953
+ t.result(e, 0);
954
954
  }
955
955
  });
956
956
  }
957
- function Vt(e, n) {
958
- e.create_function(n, "regexp_replace", -1, Ae | Se, 0, (t, s) => {
957
+ function vn(t, n) {
958
+ t.create_function(n, "regexp_replace", -1, ot | it, 0, (e, s) => {
959
959
  if (s.length < 3) {
960
- e.result(t, "");
960
+ t.result(e, "");
961
961
  return;
962
962
  }
963
963
  try {
964
- const r = e.value_text(s[0]), o = e.value_text(s[1]), i = e.value_text(s[2]), c = s.length > 3 ? e.value_text(s[3]) : "";
965
- e.result(t, o.replace(qe(r, c), i));
964
+ const o = t.value_text(s[0]), a = t.value_text(s[1]), d = t.value_text(s[2]), p = s.length > 3 ? t.value_text(s[3]) : "";
965
+ t.result(e, a.replace(yt(o, p), d));
966
966
  } catch {
967
- e.result(t, e.value_text(s[1]));
967
+ t.result(e, t.value_text(s[1]));
968
968
  }
969
969
  });
970
970
  }
971
- async function Qt(e, n) {
972
- const { vfs: t, async: s, worker: r, wasmPath: o, locateFile: i, workerInstance: c, sharedWorkerInstance: a, sharedWorker: l } = n, d = {
973
- vfs: t,
971
+ async function Rn(t, n) {
972
+ const { vfs: e, async: s, worker: o, wasmPath: a, locateFile: d, workerInstance: p, sharedWorkerInstance: f, sharedWorker: b } = n, A = {
973
+ vfs: e,
974
974
  async: s,
975
- worker: r,
976
- wasmPath: o,
977
- locateFile: i
975
+ worker: o,
976
+ wasmPath: a,
977
+ locateFile: d
978
978
  };
979
- xe(d);
980
- let p;
981
- return r && c ? p = Ee(c) : l && a ? p = Ee(a.port) : p = new Wt(), await p.init(e, d), p;
979
+ mt(A);
980
+ let T;
981
+ return o && p ? T = Ge(p) : b && f ? T = Ge(f.port) : T = new Tn(), await T.init(t, A), T;
982
982
  }
983
- const Gt = (e, n) => n.map((t) => {
984
- const s = e.rxdb.schemaManager.getEntityMetadata(t.entity, t.namespace);
985
- return s ? (t.inversePatch && Object.keys(t.inversePatch).forEach((r) => {
986
- const o = s.propertyMap.get(r);
987
- o && (t.inversePatch[r] = P(
988
- t.inversePatch[r],
989
- o
983
+ const Cn = (t, n) => n.map((e) => {
984
+ const s = t.rxdb.schemaManager.getEntityMetadata(e.entity, e.namespace);
985
+ return s ? (e.inversePatch && Object.keys(e.inversePatch).forEach((o) => {
986
+ const a = s.propertyMap.get(o);
987
+ a && (e.inversePatch[o] = ue(
988
+ e.inversePatch[o],
989
+ a
990
990
  ));
991
- }), t.patch && Object.keys(t.patch).forEach((r) => {
992
- const o = s.propertyMap.get(r);
993
- o && (t.patch[r] = P(
994
- t.patch[r],
995
- o
991
+ }), e.patch && Object.keys(e.patch).forEach((o) => {
992
+ const a = s.propertyMap.get(o);
993
+ a && (e.patch[o] = ue(
994
+ e.patch[o],
995
+ a
996
996
  ));
997
- })) : console.warn(`Entity metadata not found for ${t.namespace}.${t.entity}`), t;
998
- }), Jt = (e, n) => {
999
- const t = Object.groupBy(n, (s) => s.type);
1000
- if (t.INSERT?.length) {
1001
- const s = t.INSERT.map(
1002
- (r) => ({
1003
- namespace: r.namespace,
1004
- entity: r.entity,
1005
- type: r.type,
1006
- id: r.entityId,
1007
- patch: r.patch,
997
+ })) : console.warn(`Entity metadata not found for ${e.namespace}.${e.entity}`), e;
998
+ }), Ln = (t, n) => {
999
+ const e = Object.groupBy(n, (s) => s.type);
1000
+ if (e.INSERT?.length) {
1001
+ const s = e.INSERT.map(
1002
+ (o) => ({
1003
+ namespace: o.namespace,
1004
+ entity: o.entity,
1005
+ type: o.type,
1006
+ id: o.entityId,
1007
+ patch: o.patch,
1008
1008
  inversePatch: null,
1009
- recordAt: r.createdAt
1009
+ recordAt: o.createdAt
1010
1010
  })
1011
1011
  );
1012
- e.rxdb.dispatchEvent(new K(s));
1013
- }
1014
- if (t.UPDATE?.length) {
1015
- const s = t.UPDATE.map(
1016
- (r) => ({
1017
- namespace: r.namespace,
1018
- entity: r.entity,
1019
- type: r.type,
1020
- id: r.entityId,
1021
- patch: r.patch,
1022
- inversePatch: r.inversePatch,
1023
- recordAt: r.createdAt
1012
+ t.rxdb.dispatchEvent(new Ee(s));
1013
+ }
1014
+ if (e.UPDATE?.length) {
1015
+ const s = e.UPDATE.map(
1016
+ (o) => ({
1017
+ namespace: o.namespace,
1018
+ entity: o.entity,
1019
+ type: o.type,
1020
+ id: o.entityId,
1021
+ patch: o.patch,
1022
+ inversePatch: o.inversePatch,
1023
+ recordAt: o.createdAt
1024
1024
  })
1025
1025
  );
1026
- e.rxdb.dispatchEvent(new Y(s));
1027
- }
1028
- if (t.DELETE?.length) {
1029
- const s = t.DELETE.map(
1030
- (r) => ({
1031
- namespace: r.namespace,
1032
- entity: r.entity,
1033
- type: r.type,
1034
- id: r.entityId,
1026
+ t.rxdb.dispatchEvent(new Te(s));
1027
+ }
1028
+ if (e.DELETE?.length) {
1029
+ const s = e.DELETE.map(
1030
+ (o) => ({
1031
+ namespace: o.namespace,
1032
+ entity: o.entity,
1033
+ type: o.type,
1034
+ id: o.entityId,
1035
1035
  patch: null,
1036
- inversePatch: r.inversePatch,
1037
- recordAt: r.createdAt
1036
+ inversePatch: o.inversePatch,
1037
+ recordAt: o.createdAt
1038
1038
  })
1039
1039
  );
1040
- e.rxdb.dispatchEvent(new ce(s));
1040
+ t.rxdb.dispatchEvent(new qe(s));
1041
1041
  }
1042
- }, Xt = (e, n) => {
1043
- const { tableName: t } = n, [s, r] = ot(t), o = e.rxdb.schemaManager.getEntityTypeByTableName(r, s);
1044
- if (!o) return;
1045
- const i = e.getRepository(o), c = T(o), a = T(B);
1046
- i.findByRowIds(n.rowIds).then((l) => {
1042
+ }, Mn = (t, n) => {
1043
+ const { tableName: e } = n, [s, o] = Ut(e), a = t.rxdb.schemaManager.getEntityTypeByTableName(o, s);
1044
+ if (!a) return;
1045
+ const d = t.getRepository(a), p = V(a), f = V(pe);
1046
+ d.findByRowIds(n.rowIds).then((b) => {
1047
1047
  try {
1048
- let d = l;
1049
- if (c === a) {
1050
- if (d = Gt(e, l), n.type === v.SQLITE_INSERT) {
1051
- Jt(e, d);
1052
- const p = d.map((u) => ({
1053
- namespace: c.namespace,
1054
- entity: c.name,
1055
- type: u.type,
1056
- id: u.id,
1057
- patch: { ...u },
1048
+ let A = b;
1049
+ if (p === f) {
1050
+ if (A = Cn(t, b), n.type === ce.SQLITE_INSERT) {
1051
+ Ln(t, A);
1052
+ const T = A.map((I) => ({
1053
+ namespace: p.namespace,
1054
+ entity: p.name,
1055
+ type: I.type,
1056
+ id: I.id,
1057
+ patch: { ...I },
1058
1058
  inversePatch: null,
1059
- recordAt: u.createdAt
1059
+ recordAt: I.createdAt
1060
1060
  }));
1061
- e.rxdb.dispatchEvent(new K(p));
1061
+ t.rxdb.dispatchEvent(new Ee(T));
1062
1062
  }
1063
1063
  } else {
1064
- const p = jt(n.type), u = d.map((h) => {
1065
- const f = {
1066
- namespace: c.namespace,
1067
- entity: c.name,
1068
- type: p,
1069
- id: h.id,
1070
- recordAt: h.createdAt || /* @__PURE__ */ new Date()
1064
+ const T = mn(n.type), I = A.map((M) => {
1065
+ const E = {
1066
+ namespace: p.namespace,
1067
+ entity: p.name,
1068
+ type: T,
1069
+ id: M.id,
1070
+ recordAt: M.createdAt || /* @__PURE__ */ new Date()
1071
1071
  };
1072
1072
  switch (n.type) {
1073
- case v.SQLITE_INSERT:
1073
+ case ce.SQLITE_INSERT:
1074
1074
  return {
1075
- ...f,
1076
- patch: { ...h },
1075
+ ...E,
1076
+ patch: { ...M },
1077
1077
  inversePatch: null
1078
1078
  };
1079
- case v.SQLITE_DELETE:
1079
+ case ce.SQLITE_DELETE:
1080
1080
  return {
1081
- ...f,
1081
+ ...E,
1082
1082
  patch: null,
1083
- inversePatch: { ...h }
1083
+ inversePatch: { ...M }
1084
1084
  };
1085
- case v.SQLITE_UPDATE:
1085
+ case ce.SQLITE_UPDATE:
1086
1086
  return {
1087
- ...f,
1087
+ ...E,
1088
1088
  inversePatch: null,
1089
- patch: { ...h }
1089
+ patch: { ...M }
1090
1090
  };
1091
1091
  }
1092
1092
  });
1093
- switch (p) {
1093
+ switch (T) {
1094
1094
  case "UPDATE":
1095
- e.rxdb.dispatchEvent(
1096
- new Y(u)
1095
+ t.rxdb.dispatchEvent(
1096
+ new Te(I)
1097
1097
  );
1098
1098
  break;
1099
1099
  case "DELETE":
1100
- e.rxdb.dispatchEvent(
1101
- new ce(u)
1100
+ t.rxdb.dispatchEvent(
1101
+ new qe(I)
1102
1102
  );
1103
1103
  break;
1104
1104
  case "INSERT":
1105
- e.rxdb.dispatchEvent(
1106
- new K(u)
1105
+ t.rxdb.dispatchEvent(
1106
+ new Ee(I)
1107
1107
  );
1108
1108
  break;
1109
1109
  }
1110
1110
  }
1111
- } catch (d) {
1112
- console.error(`[rxdb-adapter-sqlite] Error processing ${t} change event:`, d);
1111
+ } catch (A) {
1112
+ console.error(`[rxdb-adapter-sqlite] Error processing ${e} change event:`, A);
1113
1113
  }
1114
- }).catch((l) => {
1115
- console.error(`[rxdb-adapter-sqlite] Failed to query ${t} change (rowIds: ${n.rowIds}):`, l);
1114
+ }).catch((b) => {
1115
+ console.error(`[rxdb-adapter-sqlite] Failed to query ${e} change (rowIds: ${n.rowIds}):`, b);
1116
1116
  });
1117
- }, z = (e, n, t) => {
1118
- const { isCount: s, isFindDescendants: r, entityId: o, where: i } = t, c = !o, a = A(n), d = n.relationMap.get("parent").columnName;
1119
- let p = "";
1120
- const h = [`c.__level < ${t.level || 0}`, i && U(i, /* @__PURE__ */ new Map(), n, e)].filter(Boolean).join(" AND ");
1121
- h && (p = `WHERE ${h}`);
1122
- let f = "__children.*";
1123
- s ? c ? f = "count(*)" : f = "count(*)-1" : t.hasChildren && (f += `, EXISTS(SELECT 1 FROM "${a}" __sub WHERE __sub."${d}" = __children.id) AS hasChildren`);
1124
- const y = [];
1117
+ }, $e = (t, n, e) => {
1118
+ const { isCount: s, isFindDescendants: o, entityId: a, where: d } = e, p = !a, f = X(n), A = n.relationMap.get("parent").columnName;
1119
+ let T = "";
1120
+ const M = [`c.__level < ${e.level || 0}`, d && he(d, /* @__PURE__ */ new Map(), n, t)].filter(Boolean).join(" AND ");
1121
+ M && (T = `WHERE ${M}`);
1122
+ let E = "__children.*";
1123
+ s ? p ? E = "count(*)" : E = "count(*)-1" : e.hasChildren && (E += `, EXISTS(SELECT 1 FROM "${f}" __sub WHERE __sub."${A}" = __children.id) AS hasChildren`);
1124
+ const v = [];
1125
1125
  let m;
1126
- return c ? m = `"${d}" is null` : (m = "id = ?", y.push(o)), { sql: `WITH RECURSIVE __children AS (
1127
- SELECT *,rowid as ${q}, 0 AS __level
1128
- FROM "${a}"
1126
+ return p ? m = `"${A}" is null` : (m = "id = ?", v.push(a)), { sql: `WITH RECURSIVE __children AS (
1127
+ SELECT *,rowid as ${ie}, 0 AS __level
1128
+ FROM "${f}"
1129
1129
  WHERE ${m}
1130
1130
  UNION ALL
1131
- SELECT children.*,children.rowid as ${q}, c.__level + 1 AS __level
1132
- FROM "${a}" children
1133
- JOIN __children c ON ${r ? `children."${d}" = c.id` : `children.id = c."${d}"`}
1134
- ${p}
1131
+ SELECT children.*,children.rowid as ${ie}, c.__level + 1 AS __level
1132
+ FROM "${f}" children
1133
+ JOIN __children c ON ${o ? `children."${A}" = c.id` : `children.id = c."${A}"`}
1134
+ ${T}
1135
1135
  )
1136
1136
 
1137
- SELECT ${f} FROM __children ORDER BY __level, id;`, params: y };
1138
- }, Yt = (e, n, t) => z(e, n, {
1139
- ...t,
1137
+ SELECT ${E} FROM __children ORDER BY __level, id;`, params: v };
1138
+ }, On = (t, n, e) => $e(t, n, {
1139
+ ...e,
1140
1140
  isFindDescendants: !0,
1141
1141
  hasChildren: n.features?.tree?.hasChildren
1142
- }), zt = (e, n, t) => z(e, n, { ...t, isFindDescendants: !0, isCount: !0 }), Zt = (e, n, t) => z(e, n, {
1143
- ...t,
1142
+ }), xn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !0, isCount: !0 }), jn = (t, n, e) => $e(t, n, {
1143
+ ...e,
1144
1144
  isFindDescendants: !1,
1145
1145
  hasChildren: n.features?.tree?.hasChildren
1146
- }), en = (e, n, t) => z(e, n, { ...t, isFindDescendants: !1, isCount: !0 });
1147
- class tn extends je {
1146
+ }), Bn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !1, isCount: !0 });
1147
+ class Dn extends ht {
1148
1148
  async findDescendants(n) {
1149
- const { sql: t, params: s } = Yt(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
1150
- return this.addQueryCache(r, !0);
1149
+ const { sql: e, params: s } = On(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
1150
+ return this.addQueryCache(o, !0);
1151
1151
  }
1152
1152
  async countDescendants(n) {
1153
- const { sql: t, params: s } = zt(this.adapter, this.metadata, n);
1154
- return (await this.adapter.query(t, s)).results[0].rows[0][0];
1153
+ const { sql: e, params: s } = xn(this.adapter, this.metadata, n);
1154
+ return (await this.adapter.query(e, s)).results[0].rows[0][0];
1155
1155
  }
1156
1156
  async findAncestors(n) {
1157
- const { sql: t, params: s } = Zt(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
1158
- return this.addQueryCache(r);
1157
+ const { sql: e, params: s } = jn(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
1158
+ return this.addQueryCache(o);
1159
1159
  }
1160
1160
  async countAncestors(n) {
1161
- const { sql: t, params: s } = en(this.adapter, this.metadata, n);
1162
- return (await this.adapter.query(t, s)).results[0].rows[0][0];
1161
+ const { sql: e, params: s } = Bn(this.adapter, this.metadata, n);
1162
+ return (await this.adapter.query(e, s)).results[0].rows[0][0];
1163
1163
  }
1164
1164
  }
1165
- const nn = (e, n) => {
1166
- const t = A(e), s = n.map((r) => I(r.id)).join(",");
1167
- return `DELETE FROM "${t}" WHERE id in (${s});`;
1168
- }, De = (e, n, t) => {
1169
- const s = A(e), r = t?.userId && e.propertyMap.has("createdBy"), o = t?.userId && e.propertyMap.has("updatedBy"), i = e.propertyMap.has("createdAt"), c = e.propertyMap.has("updatedAt"), a = /* @__PURE__ */ new Date(), l = [
1170
- ...Array.from(e.propertyMap.values()).map((h) => h.columnName),
1171
- ...e.foreignKeyColumnNames || e.foreignKeyNames
1172
- ], d = [], p = [];
1173
- return n.forEach((h) => {
1174
- const f = be(e, h);
1175
- r && (f.createdBy = t.userId), o && (f.updatedBy = t.userId), i && f.createdAt === void 0 && (f.createdAt = a), c && f.updatedAt === void 0 && (f.updatedAt = a);
1176
- const y = le(e, f), m = [];
1177
- l.forEach((_) => {
1178
- m.push("?"), d.push(y[_] ?? null);
1179
- }), p.push(`(${m.join(",")})`);
1180
- }), { sql: `INSERT INTO "${s}" (${l.join(",")}) VALUES ${p.join(",")};`, params: d };
1181
- }, $e = async (e, n) => {
1182
- const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Date();
1183
- let r = "";
1184
- const o = /* @__PURE__ */ new Set();
1185
- return n.create.forEach((i, c) => {
1186
- const a = Array.from(i);
1187
- a.forEach((m) => o.add(m));
1188
- const l = T(c), d = De(l, a, e.rxdb.context), p = F(d.sql, d.params), u = a.map((m) => m.id);
1189
- u.forEach((m) => t.set(m, c));
1190
- const { sql: h, params: f } = ie(e, l, {
1165
+ function qn(t) {
1166
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
1167
+ }
1168
+ function ge(t) {
1169
+ throw new Error('Could not dynamically require "' + t + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
1170
+ }
1171
+ var xe = { exports: {} }, tt;
1172
+ function kn() {
1173
+ return tt || (tt = 1, (function(t, n) {
1174
+ (function(e) {
1175
+ t.exports = e();
1176
+ })(function() {
1177
+ return (function e(s, o, a) {
1178
+ function d(b, A) {
1179
+ if (!o[b]) {
1180
+ if (!s[b]) {
1181
+ var T = typeof ge == "function" && ge;
1182
+ if (!A && T) return T(b, !0);
1183
+ if (p) return p(b, !0);
1184
+ throw new Error("Cannot find module '" + b + "'");
1185
+ }
1186
+ A = o[b] = { exports: {} }, s[b][0].call(A.exports, function(I) {
1187
+ var M = s[b][1][I];
1188
+ return d(M || I);
1189
+ }, A, A.exports, e, s, o, a);
1190
+ }
1191
+ return o[b].exports;
1192
+ }
1193
+ for (var p = typeof ge == "function" && ge, f = 0; f < a.length; f++) d(a[f]);
1194
+ return d;
1195
+ })({ 1: [function(e, s, o) {
1196
+ (function(a, d, p, f, b, A, T, I, M) {
1197
+ var E = e("crypto");
1198
+ function v(y, w) {
1199
+ w = S(y, w);
1200
+ var c;
1201
+ return (c = w.algorithm !== "passthrough" ? E.createHash(w.algorithm) : new B()).write === void 0 && (c.write = c.update, c.end = c.update), R(w, c).dispatch(y), c.update || c.end(""), c.digest ? c.digest(w.encoding === "buffer" ? void 0 : w.encoding) : (y = c.read(), w.encoding !== "buffer" ? y.toString(w.encoding) : y);
1202
+ }
1203
+ (o = s.exports = v).sha1 = function(y) {
1204
+ return v(y);
1205
+ }, o.keys = function(y) {
1206
+ return v(y, { excludeValues: !0, algorithm: "sha1", encoding: "hex" });
1207
+ }, o.MD5 = function(y) {
1208
+ return v(y, { algorithm: "md5", encoding: "hex" });
1209
+ }, o.keysMD5 = function(y) {
1210
+ return v(y, { algorithm: "md5", encoding: "hex", excludeValues: !0 });
1211
+ };
1212
+ var m = E.getHashes ? E.getHashes().slice() : ["sha1", "md5"], N = (m.push("passthrough"), ["buffer", "hex", "binary", "base64"]);
1213
+ function S(y, w) {
1214
+ var c = {};
1215
+ if (c.algorithm = (w = w || {}).algorithm || "sha1", c.encoding = w.encoding || "hex", c.excludeValues = !!w.excludeValues, c.algorithm = c.algorithm.toLowerCase(), c.encoding = c.encoding.toLowerCase(), c.ignoreUnknown = w.ignoreUnknown === !0, c.respectType = w.respectType !== !1, c.respectFunctionNames = w.respectFunctionNames !== !1, c.respectFunctionProperties = w.respectFunctionProperties !== !1, c.unorderedArrays = w.unorderedArrays === !0, c.unorderedSets = w.unorderedSets !== !1, c.unorderedObjects = w.unorderedObjects !== !1, c.replacer = w.replacer || void 0, c.excludeKeys = w.excludeKeys || void 0, y === void 0) throw new Error("Object argument required.");
1216
+ for (var u = 0; u < m.length; ++u) m[u].toLowerCase() === c.algorithm.toLowerCase() && (c.algorithm = m[u]);
1217
+ if (m.indexOf(c.algorithm) === -1) throw new Error('Algorithm "' + c.algorithm + '" not supported. supported values: ' + m.join(", "));
1218
+ if (N.indexOf(c.encoding) === -1 && c.algorithm !== "passthrough") throw new Error('Encoding "' + c.encoding + '" not supported. supported values: ' + N.join(", "));
1219
+ return c;
1220
+ }
1221
+ function $(y) {
1222
+ if (typeof y == "function") return /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(y)) != null;
1223
+ }
1224
+ function R(y, w, c) {
1225
+ c = c || [];
1226
+ function u(i) {
1227
+ return w.update ? w.update(i, "utf8") : w.write(i, "utf8");
1228
+ }
1229
+ return { dispatch: function(i) {
1230
+ return this["_" + ((i = y.replacer ? y.replacer(i) : i) === null ? "null" : typeof i)](i);
1231
+ }, _object: function(i) {
1232
+ var g, _ = Object.prototype.toString.call(i), k = /\[object (.*)\]/i.exec(_);
1233
+ if (k = (k = k ? k[1] : "unknown:[" + _ + "]").toLowerCase(), 0 <= (_ = c.indexOf(i))) return this.dispatch("[CIRCULAR:" + _ + "]");
1234
+ if (c.push(i), p !== void 0 && p.isBuffer && p.isBuffer(i)) return u("buffer:"), u(i);
1235
+ if (k === "object" || k === "function" || k === "asyncfunction") return _ = Object.keys(i), y.unorderedObjects && (_ = _.sort()), y.respectType === !1 || $(i) || _.splice(0, 0, "prototype", "__proto__", "constructor"), y.excludeKeys && (_ = _.filter(function(q) {
1236
+ return !y.excludeKeys(q);
1237
+ })), u("object:" + _.length + ":"), g = this, _.forEach(function(q) {
1238
+ g.dispatch(q), u(":"), y.excludeValues || g.dispatch(i[q]), u(",");
1239
+ });
1240
+ if (!this["_" + k]) {
1241
+ if (y.ignoreUnknown) return u("[" + k + "]");
1242
+ throw new Error('Unknown object type "' + k + '"');
1243
+ }
1244
+ this["_" + k](i);
1245
+ }, _array: function(i, q) {
1246
+ q = q !== void 0 ? q : y.unorderedArrays !== !1;
1247
+ var _ = this;
1248
+ if (u("array:" + i.length + ":"), !q || i.length <= 1) return i.forEach(function(U) {
1249
+ return _.dispatch(U);
1250
+ });
1251
+ var k = [], q = i.map(function(U) {
1252
+ var j = new B(), W = c.slice();
1253
+ return R(y, j, W).dispatch(U), k = k.concat(W.slice(c.length)), j.read().toString();
1254
+ });
1255
+ return c = c.concat(k), q.sort(), this._array(q, !1);
1256
+ }, _date: function(i) {
1257
+ return u("date:" + i.toJSON());
1258
+ }, _symbol: function(i) {
1259
+ return u("symbol:" + i.toString());
1260
+ }, _error: function(i) {
1261
+ return u("error:" + i.toString());
1262
+ }, _boolean: function(i) {
1263
+ return u("bool:" + i.toString());
1264
+ }, _string: function(i) {
1265
+ u("string:" + i.length + ":"), u(i.toString());
1266
+ }, _function: function(i) {
1267
+ u("fn:"), $(i) ? this.dispatch("[native]") : this.dispatch(i.toString()), y.respectFunctionNames !== !1 && this.dispatch("function-name:" + String(i.name)), y.respectFunctionProperties && this._object(i);
1268
+ }, _number: function(i) {
1269
+ return u("number:" + i.toString());
1270
+ }, _xml: function(i) {
1271
+ return u("xml:" + i.toString());
1272
+ }, _null: function() {
1273
+ return u("Null");
1274
+ }, _undefined: function() {
1275
+ return u("Undefined");
1276
+ }, _regexp: function(i) {
1277
+ return u("regex:" + i.toString());
1278
+ }, _uint8array: function(i) {
1279
+ return u("uint8array:"), this.dispatch(Array.prototype.slice.call(i));
1280
+ }, _uint8clampedarray: function(i) {
1281
+ return u("uint8clampedarray:"), this.dispatch(Array.prototype.slice.call(i));
1282
+ }, _int8array: function(i) {
1283
+ return u("int8array:"), this.dispatch(Array.prototype.slice.call(i));
1284
+ }, _uint16array: function(i) {
1285
+ return u("uint16array:"), this.dispatch(Array.prototype.slice.call(i));
1286
+ }, _int16array: function(i) {
1287
+ return u("int16array:"), this.dispatch(Array.prototype.slice.call(i));
1288
+ }, _uint32array: function(i) {
1289
+ return u("uint32array:"), this.dispatch(Array.prototype.slice.call(i));
1290
+ }, _int32array: function(i) {
1291
+ return u("int32array:"), this.dispatch(Array.prototype.slice.call(i));
1292
+ }, _float32array: function(i) {
1293
+ return u("float32array:"), this.dispatch(Array.prototype.slice.call(i));
1294
+ }, _float64array: function(i) {
1295
+ return u("float64array:"), this.dispatch(Array.prototype.slice.call(i));
1296
+ }, _arraybuffer: function(i) {
1297
+ return u("arraybuffer:"), this.dispatch(new Uint8Array(i));
1298
+ }, _url: function(i) {
1299
+ return u("url:" + i.toString());
1300
+ }, _map: function(i) {
1301
+ return u("map:"), i = Array.from(i), this._array(i, y.unorderedSets !== !1);
1302
+ }, _set: function(i) {
1303
+ return u("set:"), i = Array.from(i), this._array(i, y.unorderedSets !== !1);
1304
+ }, _file: function(i) {
1305
+ return u("file:"), this.dispatch([i.name, i.size, i.type, i.lastModfied]);
1306
+ }, _blob: function() {
1307
+ if (y.ignoreUnknown) return u("[blob]");
1308
+ throw Error(`Hashing Blob objects is currently not supported
1309
+ (see https://github.com/puleos/object-hash/issues/26)
1310
+ Use "options.replacer" or "options.ignoreUnknown"
1311
+ `);
1312
+ }, _domwindow: function() {
1313
+ return u("domwindow");
1314
+ }, _bigint: function(i) {
1315
+ return u("bigint:" + i.toString());
1316
+ }, _process: function() {
1317
+ return u("process");
1318
+ }, _timer: function() {
1319
+ return u("timer");
1320
+ }, _pipe: function() {
1321
+ return u("pipe");
1322
+ }, _tcp: function() {
1323
+ return u("tcp");
1324
+ }, _udp: function() {
1325
+ return u("udp");
1326
+ }, _tty: function() {
1327
+ return u("tty");
1328
+ }, _statwatcher: function() {
1329
+ return u("statwatcher");
1330
+ }, _securecontext: function() {
1331
+ return u("securecontext");
1332
+ }, _connection: function() {
1333
+ return u("connection");
1334
+ }, _zlib: function() {
1335
+ return u("zlib");
1336
+ }, _context: function() {
1337
+ return u("context");
1338
+ }, _nodescript: function() {
1339
+ return u("nodescript");
1340
+ }, _httpparser: function() {
1341
+ return u("httpparser");
1342
+ }, _dataview: function() {
1343
+ return u("dataview");
1344
+ }, _signal: function() {
1345
+ return u("signal");
1346
+ }, _fsevent: function() {
1347
+ return u("fsevent");
1348
+ }, _tlswrap: function() {
1349
+ return u("tlswrap");
1350
+ } };
1351
+ }
1352
+ function B() {
1353
+ return { buf: "", write: function(y) {
1354
+ this.buf += y;
1355
+ }, end: function(y) {
1356
+ this.buf += y;
1357
+ }, read: function() {
1358
+ return this.buf;
1359
+ } };
1360
+ }
1361
+ o.writeToStream = function(y, w, c) {
1362
+ return c === void 0 && (c = w, w = {}), R(w = S(y, w), c).dispatch(y);
1363
+ };
1364
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("buffer").Buffer, arguments[3], arguments[4], arguments[5], arguments[6], "/fake_9a5aa49d.js", "/");
1365
+ }, { buffer: 3, crypto: 5, lYpoI2: 11 }], 2: [function(e, s, o) {
1366
+ (function(a, d, p, f, b, A, T, I, M) {
1367
+ (function(E) {
1368
+ var v = typeof Uint8Array < "u" ? Uint8Array : Array, m = 43, N = 47, S = 48, $ = 97, R = 65, B = 45, y = 95;
1369
+ function w(c) {
1370
+ return c = c.charCodeAt(0), c === m || c === B ? 62 : c === N || c === y ? 63 : c < S ? -1 : c < S + 10 ? c - S + 26 + 26 : c < R + 26 ? c - R : c < $ + 26 ? c - $ + 26 : void 0;
1371
+ }
1372
+ E.toByteArray = function(c) {
1373
+ var u, i;
1374
+ if (0 < c.length % 4) throw new Error("Invalid string. Length must be a multiple of 4");
1375
+ var g = c.length, g = c.charAt(g - 2) === "=" ? 2 : c.charAt(g - 1) === "=" ? 1 : 0, _ = new v(3 * c.length / 4 - g), k = 0 < g ? c.length - 4 : c.length, q = 0;
1376
+ function U(j) {
1377
+ _[q++] = j;
1378
+ }
1379
+ for (u = 0; u < k; u += 4, 0) U((16711680 & (i = w(c.charAt(u)) << 18 | w(c.charAt(u + 1)) << 12 | w(c.charAt(u + 2)) << 6 | w(c.charAt(u + 3)))) >> 16), U((65280 & i) >> 8), U(255 & i);
1380
+ return g == 2 ? U(255 & (i = w(c.charAt(u)) << 2 | w(c.charAt(u + 1)) >> 4)) : g == 1 && (U((i = w(c.charAt(u)) << 10 | w(c.charAt(u + 1)) << 4 | w(c.charAt(u + 2)) >> 2) >> 8 & 255), U(255 & i)), _;
1381
+ }, E.fromByteArray = function(c) {
1382
+ var u, i, g, _, k = c.length % 3, q = "";
1383
+ function U(j) {
1384
+ return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(j);
1385
+ }
1386
+ for (u = 0, g = c.length - k; u < g; u += 3) i = (c[u] << 16) + (c[u + 1] << 8) + c[u + 2], q += U((_ = i) >> 18 & 63) + U(_ >> 12 & 63) + U(_ >> 6 & 63) + U(63 & _);
1387
+ switch (k) {
1388
+ case 1:
1389
+ q = (q += U((i = c[c.length - 1]) >> 2)) + U(i << 4 & 63) + "==";
1390
+ break;
1391
+ case 2:
1392
+ q = (q = (q += U((i = (c[c.length - 2] << 8) + c[c.length - 1]) >> 10)) + U(i >> 4 & 63)) + U(i << 2 & 63) + "=";
1393
+ }
1394
+ return q;
1395
+ };
1396
+ })(o === void 0 ? this.base64js = {} : o);
1397
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1398
+ }, { buffer: 3, lYpoI2: 11 }], 3: [function(e, s, o) {
1399
+ (function(a, d, m, f, b, A, T, I, M) {
1400
+ var E = e("base64-js"), v = e("ieee754");
1401
+ function m(r, l, h) {
1402
+ if (!(this instanceof m)) return new m(r, l, h);
1403
+ var L, C, x, P, H = typeof r;
1404
+ if (l === "base64" && H == "string") for (r = (P = r).trim ? P.trim() : P.replace(/^\s+|\s+$/g, ""); r.length % 4 != 0; ) r += "=";
1405
+ if (H == "number") L = Z(r);
1406
+ else if (H == "string") L = m.byteLength(r, l);
1407
+ else {
1408
+ if (H != "object") throw new Error("First argument needs to be a number, array or string.");
1409
+ L = Z(r.length);
1410
+ }
1411
+ if (m._useTypedArrays ? C = m._augment(new Uint8Array(L)) : ((C = this).length = L, C._isBuffer = !0), m._useTypedArrays && typeof r.byteLength == "number") C._set(r);
1412
+ else if (K(P = r) || m.isBuffer(P) || P && typeof P == "object" && typeof P.length == "number") for (x = 0; x < L; x++) m.isBuffer(r) ? C[x] = r.readUInt8(x) : C[x] = r[x];
1413
+ else if (H == "string") C.write(r, 0, l);
1414
+ else if (H == "number" && !m._useTypedArrays && !h) for (x = 0; x < L; x++) C[x] = 0;
1415
+ return C;
1416
+ }
1417
+ function N(r, l, h, L) {
1418
+ return m._charsWritten = me((function(C) {
1419
+ for (var x = [], P = 0; P < C.length; P++) x.push(255 & C.charCodeAt(P));
1420
+ return x;
1421
+ })(l), r, h, L);
1422
+ }
1423
+ function S(r, l, h, L) {
1424
+ return m._charsWritten = me((function(C) {
1425
+ for (var x, P, H = [], J = 0; J < C.length; J++) P = C.charCodeAt(J), x = P >> 8, P = P % 256, H.push(P), H.push(x);
1426
+ return H;
1427
+ })(l), r, h, L);
1428
+ }
1429
+ function $(r, l, h) {
1430
+ var L = "";
1431
+ h = Math.min(r.length, h);
1432
+ for (var C = l; C < h; C++) L += String.fromCharCode(r[C]);
1433
+ return L;
1434
+ }
1435
+ function R(r, l, h, x) {
1436
+ x || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 1 < r.length, "Trying to read beyond buffer length"));
1437
+ var C, x = r.length;
1438
+ if (!(x <= l)) return h ? (C = r[l], l + 1 < x && (C |= r[l + 1] << 8)) : (C = r[l] << 8, l + 1 < x && (C |= r[l + 1])), C;
1439
+ }
1440
+ function B(r, l, h, x) {
1441
+ x || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 3 < r.length, "Trying to read beyond buffer length"));
1442
+ var C, x = r.length;
1443
+ if (!(x <= l)) return h ? (l + 2 < x && (C = r[l + 2] << 16), l + 1 < x && (C |= r[l + 1] << 8), C |= r[l], l + 3 < x && (C += r[l + 3] << 24 >>> 0)) : (l + 1 < x && (C = r[l + 1] << 16), l + 2 < x && (C |= r[l + 2] << 8), l + 3 < x && (C |= r[l + 3]), C += r[l] << 24 >>> 0), C;
1444
+ }
1445
+ function y(r, l, h, L) {
1446
+ if (L || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 1 < r.length, "Trying to read beyond buffer length")), !(r.length <= l)) return L = R(r, l, h, !0), 32768 & L ? -1 * (65535 - L + 1) : L;
1447
+ }
1448
+ function w(r, l, h, L) {
1449
+ if (L || (O(typeof h == "boolean", "missing or invalid endian"), O(l != null, "missing offset"), O(l + 3 < r.length, "Trying to read beyond buffer length")), !(r.length <= l)) return L = B(r, l, h, !0), 2147483648 & L ? -1 * (4294967295 - L + 1) : L;
1450
+ }
1451
+ function c(r, l, h, L) {
1452
+ return L || (O(typeof h == "boolean", "missing or invalid endian"), O(l + 3 < r.length, "Trying to read beyond buffer length")), v.read(r, l, h, 23, 4);
1453
+ }
1454
+ function u(r, l, h, L) {
1455
+ return L || (O(typeof h == "boolean", "missing or invalid endian"), O(l + 7 < r.length, "Trying to read beyond buffer length")), v.read(r, l, h, 52, 8);
1456
+ }
1457
+ function i(r, l, h, L, C) {
1458
+ if (C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 1 < r.length, "trying to write beyond buffer length"), Se(l, 65535)), C = r.length, !(C <= h)) for (var x = 0, P = Math.min(C - h, 2); x < P; x++) r[h + x] = (l & 255 << 8 * (L ? x : 1 - x)) >>> 8 * (L ? x : 1 - x);
1459
+ }
1460
+ function g(r, l, h, L, C) {
1461
+ if (C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "trying to write beyond buffer length"), Se(l, 4294967295)), C = r.length, !(C <= h)) for (var x = 0, P = Math.min(C - h, 4); x < P; x++) r[h + x] = l >>> 8 * (L ? x : 3 - x) & 255;
1462
+ }
1463
+ function _(r, l, h, L, C) {
1464
+ C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 1 < r.length, "Trying to write beyond buffer length"), ve(l, 32767, -32768)), r.length <= h || i(r, 0 <= l ? l : 65535 + l + 1, h, L, C);
1465
+ }
1466
+ function k(r, l, h, L, C) {
1467
+ C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "Trying to write beyond buffer length"), ve(l, 2147483647, -2147483648)), r.length <= h || g(r, 0 <= l ? l : 4294967295 + l + 1, h, L, C);
1468
+ }
1469
+ function q(r, l, h, L, C) {
1470
+ C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 3 < r.length, "Trying to write beyond buffer length"), He(l, 34028234663852886e22, -34028234663852886e22)), r.length <= h || v.write(r, l, h, L, 23, 4);
1471
+ }
1472
+ function U(r, l, h, L, C) {
1473
+ C || (O(l != null, "missing value"), O(typeof L == "boolean", "missing or invalid endian"), O(h != null, "missing offset"), O(h + 7 < r.length, "Trying to write beyond buffer length"), He(l, 17976931348623157e292, -17976931348623157e292)), r.length <= h || v.write(r, l, h, L, 52, 8);
1474
+ }
1475
+ o.Buffer = m, o.SlowBuffer = m, o.INSPECT_MAX_BYTES = 50, m.poolSize = 8192, m._useTypedArrays = (function() {
1476
+ try {
1477
+ var r = new ArrayBuffer(0), l = new Uint8Array(r);
1478
+ return l.foo = function() {
1479
+ return 42;
1480
+ }, l.foo() === 42 && typeof l.subarray == "function";
1481
+ } catch {
1482
+ return !1;
1483
+ }
1484
+ })(), m.isEncoding = function(r) {
1485
+ switch (String(r).toLowerCase()) {
1486
+ case "hex":
1487
+ case "utf8":
1488
+ case "utf-8":
1489
+ case "ascii":
1490
+ case "binary":
1491
+ case "base64":
1492
+ case "raw":
1493
+ case "ucs2":
1494
+ case "ucs-2":
1495
+ case "utf16le":
1496
+ case "utf-16le":
1497
+ return !0;
1498
+ default:
1499
+ return !1;
1500
+ }
1501
+ }, m.isBuffer = function(r) {
1502
+ return !(r == null || !r._isBuffer);
1503
+ }, m.byteLength = function(r, l) {
1504
+ var h;
1505
+ switch (r += "", l || "utf8") {
1506
+ case "hex":
1507
+ h = r.length / 2;
1508
+ break;
1509
+ case "utf8":
1510
+ case "utf-8":
1511
+ h = oe(r).length;
1512
+ break;
1513
+ case "ascii":
1514
+ case "binary":
1515
+ case "raw":
1516
+ h = r.length;
1517
+ break;
1518
+ case "base64":
1519
+ h = We(r).length;
1520
+ break;
1521
+ case "ucs2":
1522
+ case "ucs-2":
1523
+ case "utf16le":
1524
+ case "utf-16le":
1525
+ h = 2 * r.length;
1526
+ break;
1527
+ default:
1528
+ throw new Error("Unknown encoding");
1529
+ }
1530
+ return h;
1531
+ }, m.concat = function(r, l) {
1532
+ if (O(K(r), `Usage: Buffer.concat(list, [totalLength])
1533
+ list should be an Array.`), r.length === 0) return new m(0);
1534
+ if (r.length === 1) return r[0];
1535
+ if (typeof l != "number") for (C = l = 0; C < r.length; C++) l += r[C].length;
1536
+ for (var h = new m(l), L = 0, C = 0; C < r.length; C++) {
1537
+ var x = r[C];
1538
+ x.copy(h, L), L += x.length;
1539
+ }
1540
+ return h;
1541
+ }, m.prototype.write = function(r, l, h, L) {
1542
+ isFinite(l) ? isFinite(h) || (L = h, h = void 0) : (J = L, L = l, l = h, h = J), l = Number(l) || 0;
1543
+ var C, x, P, H, J = this.length - l;
1544
+ switch ((!h || J < (h = Number(h))) && (h = J), L = String(L || "utf8").toLowerCase()) {
1545
+ case "hex":
1546
+ C = (function(se, ne, re, G) {
1547
+ re = Number(re) || 0;
1548
+ var Y = se.length - re;
1549
+ (!G || Y < (G = Number(G))) && (G = Y), O((Y = ne.length) % 2 == 0, "Invalid hex string"), Y / 2 < G && (G = Y / 2);
1550
+ for (var de = 0; de < G; de++) {
1551
+ var Ve = parseInt(ne.substr(2 * de, 2), 16);
1552
+ O(!isNaN(Ve), "Invalid hex string"), se[re + de] = Ve;
1553
+ }
1554
+ return m._charsWritten = 2 * de, de;
1555
+ })(this, r, l, h);
1556
+ break;
1557
+ case "utf8":
1558
+ case "utf-8":
1559
+ x = this, P = l, H = h, C = m._charsWritten = me(oe(r), x, P, H);
1560
+ break;
1561
+ case "ascii":
1562
+ case "binary":
1563
+ C = N(this, r, l, h);
1564
+ break;
1565
+ case "base64":
1566
+ x = this, P = l, H = h, C = m._charsWritten = me(We(r), x, P, H);
1567
+ break;
1568
+ case "ucs2":
1569
+ case "ucs-2":
1570
+ case "utf16le":
1571
+ case "utf-16le":
1572
+ C = S(this, r, l, h);
1573
+ break;
1574
+ default:
1575
+ throw new Error("Unknown encoding");
1576
+ }
1577
+ return C;
1578
+ }, m.prototype.toString = function(r, l, h) {
1579
+ var L, C, x, P, H = this;
1580
+ if (r = String(r || "utf8").toLowerCase(), l = Number(l) || 0, (h = h !== void 0 ? Number(h) : H.length) === l) return "";
1581
+ switch (r) {
1582
+ case "hex":
1583
+ L = (function(J, se, ne) {
1584
+ var re = J.length;
1585
+ (!se || se < 0) && (se = 0), (!ne || ne < 0 || re < ne) && (ne = re);
1586
+ for (var G = "", Y = se; Y < ne; Y++) G += F(J[Y]);
1587
+ return G;
1588
+ })(H, l, h);
1589
+ break;
1590
+ case "utf8":
1591
+ case "utf-8":
1592
+ L = (function(J, se, ne) {
1593
+ var re = "", G = "";
1594
+ ne = Math.min(J.length, ne);
1595
+ for (var Y = se; Y < ne; Y++) J[Y] <= 127 ? (re += Ke(G) + String.fromCharCode(J[Y]), G = "") : G += "%" + J[Y].toString(16);
1596
+ return re + Ke(G);
1597
+ })(H, l, h);
1598
+ break;
1599
+ case "ascii":
1600
+ case "binary":
1601
+ L = $(H, l, h);
1602
+ break;
1603
+ case "base64":
1604
+ C = H, P = h, L = (x = l) === 0 && P === C.length ? E.fromByteArray(C) : E.fromByteArray(C.slice(x, P));
1605
+ break;
1606
+ case "ucs2":
1607
+ case "ucs-2":
1608
+ case "utf16le":
1609
+ case "utf-16le":
1610
+ L = (function(J, se, ne) {
1611
+ for (var re = J.slice(se, ne), G = "", Y = 0; Y < re.length; Y += 2) G += String.fromCharCode(re[Y] + 256 * re[Y + 1]);
1612
+ return G;
1613
+ })(H, l, h);
1614
+ break;
1615
+ default:
1616
+ throw new Error("Unknown encoding");
1617
+ }
1618
+ return L;
1619
+ }, m.prototype.toJSON = function() {
1620
+ return { type: "Buffer", data: Array.prototype.slice.call(this._arr || this, 0) };
1621
+ }, m.prototype.copy = function(r, l, h, L) {
1622
+ if (l = l || 0, (L = L || L === 0 ? L : this.length) !== (h = h || 0) && r.length !== 0 && this.length !== 0) {
1623
+ O(h <= L, "sourceEnd < sourceStart"), O(0 <= l && l < r.length, "targetStart out of bounds"), O(0 <= h && h < this.length, "sourceStart out of bounds"), O(0 <= L && L <= this.length, "sourceEnd out of bounds"), L > this.length && (L = this.length);
1624
+ var C = (L = r.length - l < L - h ? r.length - l + h : L) - h;
1625
+ if (C < 100 || !m._useTypedArrays) for (var x = 0; x < C; x++) r[x + l] = this[x + h];
1626
+ else r._set(this.subarray(h, h + C), l);
1627
+ }
1628
+ }, m.prototype.slice = function(r, l) {
1629
+ var h = this.length;
1630
+ if (r = W(r, h, 0), l = W(l, h, h), m._useTypedArrays) return m._augment(this.subarray(r, l));
1631
+ for (var L = l - r, C = new m(L, void 0, !0), x = 0; x < L; x++) C[x] = this[x + r];
1632
+ return C;
1633
+ }, m.prototype.get = function(r) {
1634
+ return console.log(".get() is deprecated. Access using array indexes instead."), this.readUInt8(r);
1635
+ }, m.prototype.set = function(r, l) {
1636
+ return console.log(".set() is deprecated. Access using array indexes instead."), this.writeUInt8(r, l);
1637
+ }, m.prototype.readUInt8 = function(r, l) {
1638
+ if (l || (O(r != null, "missing offset"), O(r < this.length, "Trying to read beyond buffer length")), !(r >= this.length)) return this[r];
1639
+ }, m.prototype.readUInt16LE = function(r, l) {
1640
+ return R(this, r, !0, l);
1641
+ }, m.prototype.readUInt16BE = function(r, l) {
1642
+ return R(this, r, !1, l);
1643
+ }, m.prototype.readUInt32LE = function(r, l) {
1644
+ return B(this, r, !0, l);
1645
+ }, m.prototype.readUInt32BE = function(r, l) {
1646
+ return B(this, r, !1, l);
1647
+ }, m.prototype.readInt8 = function(r, l) {
1648
+ if (l || (O(r != null, "missing offset"), O(r < this.length, "Trying to read beyond buffer length")), !(r >= this.length)) return 128 & this[r] ? -1 * (255 - this[r] + 1) : this[r];
1649
+ }, m.prototype.readInt16LE = function(r, l) {
1650
+ return y(this, r, !0, l);
1651
+ }, m.prototype.readInt16BE = function(r, l) {
1652
+ return y(this, r, !1, l);
1653
+ }, m.prototype.readInt32LE = function(r, l) {
1654
+ return w(this, r, !0, l);
1655
+ }, m.prototype.readInt32BE = function(r, l) {
1656
+ return w(this, r, !1, l);
1657
+ }, m.prototype.readFloatLE = function(r, l) {
1658
+ return c(this, r, !0, l);
1659
+ }, m.prototype.readFloatBE = function(r, l) {
1660
+ return c(this, r, !1, l);
1661
+ }, m.prototype.readDoubleLE = function(r, l) {
1662
+ return u(this, r, !0, l);
1663
+ }, m.prototype.readDoubleBE = function(r, l) {
1664
+ return u(this, r, !1, l);
1665
+ }, m.prototype.writeUInt8 = function(r, l, h) {
1666
+ h || (O(r != null, "missing value"), O(l != null, "missing offset"), O(l < this.length, "trying to write beyond buffer length"), Se(r, 255)), l >= this.length || (this[l] = r);
1667
+ }, m.prototype.writeUInt16LE = function(r, l, h) {
1668
+ i(this, r, l, !0, h);
1669
+ }, m.prototype.writeUInt16BE = function(r, l, h) {
1670
+ i(this, r, l, !1, h);
1671
+ }, m.prototype.writeUInt32LE = function(r, l, h) {
1672
+ g(this, r, l, !0, h);
1673
+ }, m.prototype.writeUInt32BE = function(r, l, h) {
1674
+ g(this, r, l, !1, h);
1675
+ }, m.prototype.writeInt8 = function(r, l, h) {
1676
+ h || (O(r != null, "missing value"), O(l != null, "missing offset"), O(l < this.length, "Trying to write beyond buffer length"), ve(r, 127, -128)), l >= this.length || (0 <= r ? this.writeUInt8(r, l, h) : this.writeUInt8(255 + r + 1, l, h));
1677
+ }, m.prototype.writeInt16LE = function(r, l, h) {
1678
+ _(this, r, l, !0, h);
1679
+ }, m.prototype.writeInt16BE = function(r, l, h) {
1680
+ _(this, r, l, !1, h);
1681
+ }, m.prototype.writeInt32LE = function(r, l, h) {
1682
+ k(this, r, l, !0, h);
1683
+ }, m.prototype.writeInt32BE = function(r, l, h) {
1684
+ k(this, r, l, !1, h);
1685
+ }, m.prototype.writeFloatLE = function(r, l, h) {
1686
+ q(this, r, l, !0, h);
1687
+ }, m.prototype.writeFloatBE = function(r, l, h) {
1688
+ q(this, r, l, !1, h);
1689
+ }, m.prototype.writeDoubleLE = function(r, l, h) {
1690
+ U(this, r, l, !0, h);
1691
+ }, m.prototype.writeDoubleBE = function(r, l, h) {
1692
+ U(this, r, l, !1, h);
1693
+ }, m.prototype.fill = function(r, l, h) {
1694
+ if (l = l || 0, h = h || this.length, O(typeof (r = typeof (r = r || 0) == "string" ? r.charCodeAt(0) : r) == "number" && !isNaN(r), "value is not a number"), O(l <= h, "end < start"), h !== l && this.length !== 0) {
1695
+ O(0 <= l && l < this.length, "start out of bounds"), O(0 <= h && h <= this.length, "end out of bounds");
1696
+ for (var L = l; L < h; L++) this[L] = r;
1697
+ }
1698
+ }, m.prototype.inspect = function() {
1699
+ for (var r = [], l = this.length, h = 0; h < l; h++) if (r[h] = F(this[h]), h === o.INSPECT_MAX_BYTES) {
1700
+ r[h + 1] = "...";
1701
+ break;
1702
+ }
1703
+ return "<Buffer " + r.join(" ") + ">";
1704
+ }, m.prototype.toArrayBuffer = function() {
1705
+ if (typeof Uint8Array > "u") throw new Error("Buffer.toArrayBuffer not supported in this browser");
1706
+ if (m._useTypedArrays) return new m(this).buffer;
1707
+ for (var r = new Uint8Array(this.length), l = 0, h = r.length; l < h; l += 1) r[l] = this[l];
1708
+ return r.buffer;
1709
+ };
1710
+ var j = m.prototype;
1711
+ function W(r, l, h) {
1712
+ return typeof r != "number" ? h : l <= (r = ~~r) ? l : 0 <= r || 0 <= (r += l) ? r : 0;
1713
+ }
1714
+ function Z(r) {
1715
+ return (r = ~~Math.ceil(+r)) < 0 ? 0 : r;
1716
+ }
1717
+ function K(r) {
1718
+ return (Array.isArray || function(l) {
1719
+ return Object.prototype.toString.call(l) === "[object Array]";
1720
+ })(r);
1721
+ }
1722
+ function F(r) {
1723
+ return r < 16 ? "0" + r.toString(16) : r.toString(16);
1724
+ }
1725
+ function oe(r) {
1726
+ for (var l = [], h = 0; h < r.length; h++) {
1727
+ var L = r.charCodeAt(h);
1728
+ if (L <= 127) l.push(r.charCodeAt(h));
1729
+ else for (var C = h, x = (55296 <= L && L <= 57343 && h++, encodeURIComponent(r.slice(C, h + 1)).substr(1).split("%")), P = 0; P < x.length; P++) l.push(parseInt(x[P], 16));
1730
+ }
1731
+ return l;
1732
+ }
1733
+ function We(r) {
1734
+ return E.toByteArray(r);
1735
+ }
1736
+ function me(r, l, h, L) {
1737
+ for (var C = 0; C < L && !(C + h >= l.length || C >= r.length); C++) l[C + h] = r[C];
1738
+ return C;
1739
+ }
1740
+ function Ke(r) {
1741
+ try {
1742
+ return decodeURIComponent(r);
1743
+ } catch {
1744
+ return "�";
1745
+ }
1746
+ }
1747
+ function Se(r, l) {
1748
+ O(typeof r == "number", "cannot write a non-number as a number"), O(0 <= r, "specified a negative value for writing an unsigned value"), O(r <= l, "value is larger than maximum value for type"), O(Math.floor(r) === r, "value has a fractional component");
1749
+ }
1750
+ function ve(r, l, h) {
1751
+ O(typeof r == "number", "cannot write a non-number as a number"), O(r <= l, "value larger than maximum allowed value"), O(h <= r, "value smaller than minimum allowed value"), O(Math.floor(r) === r, "value has a fractional component");
1752
+ }
1753
+ function He(r, l, h) {
1754
+ O(typeof r == "number", "cannot write a non-number as a number"), O(r <= l, "value larger than maximum allowed value"), O(h <= r, "value smaller than minimum allowed value");
1755
+ }
1756
+ function O(r, l) {
1757
+ if (!r) throw new Error(l || "Failed assertion");
1758
+ }
1759
+ m._augment = function(r) {
1760
+ return r._isBuffer = !0, r._get = r.get, r._set = r.set, r.get = j.get, r.set = j.set, r.write = j.write, r.toString = j.toString, r.toLocaleString = j.toString, r.toJSON = j.toJSON, r.copy = j.copy, r.slice = j.slice, r.readUInt8 = j.readUInt8, r.readUInt16LE = j.readUInt16LE, r.readUInt16BE = j.readUInt16BE, r.readUInt32LE = j.readUInt32LE, r.readUInt32BE = j.readUInt32BE, r.readInt8 = j.readInt8, r.readInt16LE = j.readInt16LE, r.readInt16BE = j.readInt16BE, r.readInt32LE = j.readInt32LE, r.readInt32BE = j.readInt32BE, r.readFloatLE = j.readFloatLE, r.readFloatBE = j.readFloatBE, r.readDoubleLE = j.readDoubleLE, r.readDoubleBE = j.readDoubleBE, r.writeUInt8 = j.writeUInt8, r.writeUInt16LE = j.writeUInt16LE, r.writeUInt16BE = j.writeUInt16BE, r.writeUInt32LE = j.writeUInt32LE, r.writeUInt32BE = j.writeUInt32BE, r.writeInt8 = j.writeInt8, r.writeInt16LE = j.writeInt16LE, r.writeInt16BE = j.writeInt16BE, r.writeInt32LE = j.writeInt32LE, r.writeInt32BE = j.writeInt32BE, r.writeFloatLE = j.writeFloatLE, r.writeFloatBE = j.writeFloatBE, r.writeDoubleLE = j.writeDoubleLE, r.writeDoubleBE = j.writeDoubleBE, r.fill = j.fill, r.inspect = j.inspect, r.toArrayBuffer = j.toArrayBuffer, r;
1761
+ };
1762
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1763
+ }, { "base64-js": 2, buffer: 3, ieee754: 10, lYpoI2: 11 }], 4: [function(e, s, o) {
1764
+ (function(a, d, E, f, b, A, T, I, M) {
1765
+ var E = e("buffer").Buffer, v = 4, m = new E(v);
1766
+ m.fill(0), s.exports = { hash: function(N, S, $, R) {
1767
+ for (var B = S((function(i, g) {
1768
+ i.length % v != 0 && (_ = i.length + (v - i.length % v), i = E.concat([i, m], _));
1769
+ for (var _, k = [], q = g ? i.readInt32BE : i.readInt32LE, U = 0; U < i.length; U += v) k.push(q.call(i, U));
1770
+ return k;
1771
+ })(N = E.isBuffer(N) ? N : new E(N), R), 8 * N.length), S = R, y = new E($), w = S ? y.writeInt32BE : y.writeInt32LE, c = 0; c < B.length; c++) w.call(y, B[c], 4 * c, !0);
1772
+ return y;
1773
+ } };
1774
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1775
+ }, { buffer: 3, lYpoI2: 11 }], 5: [function(e, s, o) {
1776
+ (function(a, d, E, f, b, A, T, I, M) {
1777
+ var E = e("buffer").Buffer, v = e("./sha"), m = e("./sha256"), N = e("./rng"), S = { sha1: v, sha256: m, md5: e("./md5") }, $ = 64, R = new E($);
1778
+ function B(i, g) {
1779
+ var _ = S[i = i || "sha1"], k = [];
1780
+ return _ || y("algorithm:", i, "is not yet supported"), { update: function(q) {
1781
+ return E.isBuffer(q) || (q = new E(q)), k.push(q), q.length, this;
1782
+ }, digest: function(q) {
1783
+ var U = E.concat(k), U = g ? (function(j, W, Z) {
1784
+ E.isBuffer(W) || (W = new E(W)), E.isBuffer(Z) || (Z = new E(Z)), W.length > $ ? W = j(W) : W.length < $ && (W = E.concat([W, R], $));
1785
+ for (var K = new E($), F = new E($), oe = 0; oe < $; oe++) K[oe] = 54 ^ W[oe], F[oe] = 92 ^ W[oe];
1786
+ return Z = j(E.concat([K, Z])), j(E.concat([F, Z]));
1787
+ })(_, g, U) : _(U);
1788
+ return k = null, q ? U.toString(q) : U;
1789
+ } };
1790
+ }
1791
+ function y() {
1792
+ var i = [].slice.call(arguments).join(" ");
1793
+ throw new Error([i, "we accept pull requests", "http://github.com/dominictarr/crypto-browserify"].join(`
1794
+ `));
1795
+ }
1796
+ R.fill(0), o.createHash = function(i) {
1797
+ return B(i);
1798
+ }, o.createHmac = B, o.randomBytes = function(i, g) {
1799
+ if (!g || !g.call) return new E(N(i));
1800
+ try {
1801
+ g.call(this, void 0, new E(N(i)));
1802
+ } catch (_) {
1803
+ g(_);
1804
+ }
1805
+ };
1806
+ var w, c = ["createCredentials", "createCipher", "createCipheriv", "createDecipher", "createDecipheriv", "createSign", "createVerify", "createDiffieHellman", "pbkdf2"], u = function(i) {
1807
+ o[i] = function() {
1808
+ y("sorry,", i, "is not implemented yet");
1809
+ };
1810
+ };
1811
+ for (w in c) u(c[w]);
1812
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1813
+ }, { "./md5": 6, "./rng": 7, "./sha": 8, "./sha256": 9, buffer: 3, lYpoI2: 11 }], 6: [function(e, s, o) {
1814
+ (function(a, d, p, f, b, A, T, I, M) {
1815
+ var E = e("./helpers");
1816
+ function v(y, w) {
1817
+ y[w >> 5] |= 128 << w % 32, y[14 + (w + 64 >>> 9 << 4)] = w;
1818
+ for (var c = 1732584193, u = -271733879, i = -1732584194, g = 271733878, _ = 0; _ < y.length; _ += 16) {
1819
+ var k = c, q = u, U = i, j = g, c = N(c, u, i, g, y[_ + 0], 7, -680876936), g = N(g, c, u, i, y[_ + 1], 12, -389564586), i = N(i, g, c, u, y[_ + 2], 17, 606105819), u = N(u, i, g, c, y[_ + 3], 22, -1044525330);
1820
+ c = N(c, u, i, g, y[_ + 4], 7, -176418897), g = N(g, c, u, i, y[_ + 5], 12, 1200080426), i = N(i, g, c, u, y[_ + 6], 17, -1473231341), u = N(u, i, g, c, y[_ + 7], 22, -45705983), c = N(c, u, i, g, y[_ + 8], 7, 1770035416), g = N(g, c, u, i, y[_ + 9], 12, -1958414417), i = N(i, g, c, u, y[_ + 10], 17, -42063), u = N(u, i, g, c, y[_ + 11], 22, -1990404162), c = N(c, u, i, g, y[_ + 12], 7, 1804603682), g = N(g, c, u, i, y[_ + 13], 12, -40341101), i = N(i, g, c, u, y[_ + 14], 17, -1502002290), c = S(c, u = N(u, i, g, c, y[_ + 15], 22, 1236535329), i, g, y[_ + 1], 5, -165796510), g = S(g, c, u, i, y[_ + 6], 9, -1069501632), i = S(i, g, c, u, y[_ + 11], 14, 643717713), u = S(u, i, g, c, y[_ + 0], 20, -373897302), c = S(c, u, i, g, y[_ + 5], 5, -701558691), g = S(g, c, u, i, y[_ + 10], 9, 38016083), i = S(i, g, c, u, y[_ + 15], 14, -660478335), u = S(u, i, g, c, y[_ + 4], 20, -405537848), c = S(c, u, i, g, y[_ + 9], 5, 568446438), g = S(g, c, u, i, y[_ + 14], 9, -1019803690), i = S(i, g, c, u, y[_ + 3], 14, -187363961), u = S(u, i, g, c, y[_ + 8], 20, 1163531501), c = S(c, u, i, g, y[_ + 13], 5, -1444681467), g = S(g, c, u, i, y[_ + 2], 9, -51403784), i = S(i, g, c, u, y[_ + 7], 14, 1735328473), c = $(c, u = S(u, i, g, c, y[_ + 12], 20, -1926607734), i, g, y[_ + 5], 4, -378558), g = $(g, c, u, i, y[_ + 8], 11, -2022574463), i = $(i, g, c, u, y[_ + 11], 16, 1839030562), u = $(u, i, g, c, y[_ + 14], 23, -35309556), c = $(c, u, i, g, y[_ + 1], 4, -1530992060), g = $(g, c, u, i, y[_ + 4], 11, 1272893353), i = $(i, g, c, u, y[_ + 7], 16, -155497632), u = $(u, i, g, c, y[_ + 10], 23, -1094730640), c = $(c, u, i, g, y[_ + 13], 4, 681279174), g = $(g, c, u, i, y[_ + 0], 11, -358537222), i = $(i, g, c, u, y[_ + 3], 16, -722521979), u = $(u, i, g, c, y[_ + 6], 23, 76029189), c = $(c, u, i, g, y[_ + 9], 4, -640364487), g = $(g, c, u, i, y[_ + 12], 11, -421815835), i = $(i, g, c, u, y[_ + 15], 16, 530742520), c = R(c, u = $(u, i, g, c, y[_ + 2], 23, -995338651), i, g, y[_ + 0], 6, -198630844), g = R(g, c, u, i, y[_ + 7], 10, 1126891415), i = R(i, g, c, u, y[_ + 14], 15, -1416354905), u = R(u, i, g, c, y[_ + 5], 21, -57434055), c = R(c, u, i, g, y[_ + 12], 6, 1700485571), g = R(g, c, u, i, y[_ + 3], 10, -1894986606), i = R(i, g, c, u, y[_ + 10], 15, -1051523), u = R(u, i, g, c, y[_ + 1], 21, -2054922799), c = R(c, u, i, g, y[_ + 8], 6, 1873313359), g = R(g, c, u, i, y[_ + 15], 10, -30611744), i = R(i, g, c, u, y[_ + 6], 15, -1560198380), u = R(u, i, g, c, y[_ + 13], 21, 1309151649), c = R(c, u, i, g, y[_ + 4], 6, -145523070), g = R(g, c, u, i, y[_ + 11], 10, -1120210379), i = R(i, g, c, u, y[_ + 2], 15, 718787259), u = R(u, i, g, c, y[_ + 9], 21, -343485551), c = B(c, k), u = B(u, q), i = B(i, U), g = B(g, j);
1821
+ }
1822
+ return Array(c, u, i, g);
1823
+ }
1824
+ function m(y, w, c, u, i, g) {
1825
+ return B((w = B(B(w, y), B(u, g))) << i | w >>> 32 - i, c);
1826
+ }
1827
+ function N(y, w, c, u, i, g, _) {
1828
+ return m(w & c | ~w & u, y, w, i, g, _);
1829
+ }
1830
+ function S(y, w, c, u, i, g, _) {
1831
+ return m(w & u | c & ~u, y, w, i, g, _);
1832
+ }
1833
+ function $(y, w, c, u, i, g, _) {
1834
+ return m(w ^ c ^ u, y, w, i, g, _);
1835
+ }
1836
+ function R(y, w, c, u, i, g, _) {
1837
+ return m(c ^ (w | ~u), y, w, i, g, _);
1838
+ }
1839
+ function B(y, w) {
1840
+ var c = (65535 & y) + (65535 & w);
1841
+ return (y >> 16) + (w >> 16) + (c >> 16) << 16 | 65535 & c;
1842
+ }
1843
+ s.exports = function(y) {
1844
+ return E.hash(y, v, 16);
1845
+ };
1846
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1847
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 7: [function(e, s, o) {
1848
+ (function(a, d, p, f, b, A, T, I, M) {
1849
+ s.exports = function(E) {
1850
+ for (var v, m = new Array(E), N = 0; N < E; N++) (3 & N) == 0 && (v = 4294967296 * Math.random()), m[N] = v >>> ((3 & N) << 3) & 255;
1851
+ return m;
1852
+ };
1853
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1854
+ }, { buffer: 3, lYpoI2: 11 }], 8: [function(e, s, o) {
1855
+ (function(a, d, p, f, b, A, T, I, M) {
1856
+ var E = e("./helpers");
1857
+ function v(S, $) {
1858
+ S[$ >> 5] |= 128 << 24 - $ % 32, S[15 + ($ + 64 >> 9 << 4)] = $;
1859
+ for (var R, B, y, w = Array(80), c = 1732584193, u = -271733879, i = -1732584194, g = 271733878, _ = -1009589776, k = 0; k < S.length; k += 16) {
1860
+ for (var q = c, U = u, j = i, W = g, Z = _, K = 0; K < 80; K++) {
1861
+ w[K] = K < 16 ? S[k + K] : N(w[K - 3] ^ w[K - 8] ^ w[K - 14] ^ w[K - 16], 1);
1862
+ var F = m(m(N(c, 5), (F = u, B = i, y = g, (R = K) < 20 ? F & B | ~F & y : !(R < 40) && R < 60 ? F & B | F & y | B & y : F ^ B ^ y)), m(m(_, w[K]), (R = K) < 20 ? 1518500249 : R < 40 ? 1859775393 : R < 60 ? -1894007588 : -899497514)), _ = g, g = i, i = N(u, 30), u = c, c = F;
1863
+ }
1864
+ c = m(c, q), u = m(u, U), i = m(i, j), g = m(g, W), _ = m(_, Z);
1865
+ }
1866
+ return Array(c, u, i, g, _);
1867
+ }
1868
+ function m(S, $) {
1869
+ var R = (65535 & S) + (65535 & $);
1870
+ return (S >> 16) + ($ >> 16) + (R >> 16) << 16 | 65535 & R;
1871
+ }
1872
+ function N(S, $) {
1873
+ return S << $ | S >>> 32 - $;
1874
+ }
1875
+ s.exports = function(S) {
1876
+ return E.hash(S, v, 20, !0);
1877
+ };
1878
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1879
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 9: [function(e, s, o) {
1880
+ (function(a, d, p, f, b, A, T, I, M) {
1881
+ function E($, R) {
1882
+ var B = (65535 & $) + (65535 & R);
1883
+ return ($ >> 16) + (R >> 16) + (B >> 16) << 16 | 65535 & B;
1884
+ }
1885
+ function v($, R) {
1886
+ var B, y = 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), w = new Array(1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225), c = new Array(64);
1887
+ $[R >> 5] |= 128 << 24 - R % 32, $[15 + (R + 64 >> 9 << 4)] = R;
1888
+ for (var u, i, g = 0; g < $.length; g += 16) {
1889
+ for (var _ = w[0], k = w[1], q = w[2], U = w[3], j = w[4], W = w[5], Z = w[6], K = w[7], F = 0; F < 64; F++) c[F] = F < 16 ? $[F + g] : E(E(E((i = c[F - 2], N(i, 17) ^ N(i, 19) ^ S(i, 10)), c[F - 7]), (i = c[F - 15], N(i, 7) ^ N(i, 18) ^ S(i, 3))), c[F - 16]), B = E(E(E(E(K, N(i = j, 6) ^ N(i, 11) ^ N(i, 25)), j & W ^ ~j & Z), y[F]), c[F]), u = E(N(u = _, 2) ^ N(u, 13) ^ N(u, 22), _ & k ^ _ & q ^ k & q), K = Z, Z = W, W = j, j = E(U, B), U = q, q = k, k = _, _ = E(B, u);
1890
+ w[0] = E(_, w[0]), w[1] = E(k, w[1]), w[2] = E(q, w[2]), w[3] = E(U, w[3]), w[4] = E(j, w[4]), w[5] = E(W, w[5]), w[6] = E(Z, w[6]), w[7] = E(K, w[7]);
1891
+ }
1892
+ return w;
1893
+ }
1894
+ var m = e("./helpers"), N = function($, R) {
1895
+ return $ >>> R | $ << 32 - R;
1896
+ }, S = function($, R) {
1897
+ return $ >>> R;
1898
+ };
1899
+ s.exports = function($) {
1900
+ return m.hash($, v, 32, !0);
1901
+ };
1902
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1903
+ }, { "./helpers": 4, buffer: 3, lYpoI2: 11 }], 10: [function(e, s, o) {
1904
+ (function(a, d, p, f, b, A, T, I, M) {
1905
+ o.read = function(E, v, m, N, g) {
1906
+ var $, R, B = 8 * g - N - 1, y = (1 << B) - 1, w = y >> 1, c = -7, u = m ? g - 1 : 0, i = m ? -1 : 1, g = E[v + u];
1907
+ for (u += i, $ = g & (1 << -c) - 1, g >>= -c, c += B; 0 < c; $ = 256 * $ + E[v + u], u += i, c -= 8) ;
1908
+ for (R = $ & (1 << -c) - 1, $ >>= -c, c += N; 0 < c; R = 256 * R + E[v + u], u += i, c -= 8) ;
1909
+ if ($ === 0) $ = 1 - w;
1910
+ else {
1911
+ if ($ === y) return R ? NaN : 1 / 0 * (g ? -1 : 1);
1912
+ R += Math.pow(2, N), $ -= w;
1913
+ }
1914
+ return (g ? -1 : 1) * R * Math.pow(2, $ - N);
1915
+ }, o.write = function(E, v, m, N, S, _) {
1916
+ var R, B, y = 8 * _ - S - 1, w = (1 << y) - 1, c = w >> 1, u = S === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, i = N ? 0 : _ - 1, g = N ? 1 : -1, _ = v < 0 || v === 0 && 1 / v < 0 ? 1 : 0;
1917
+ for (v = Math.abs(v), isNaN(v) || v === 1 / 0 ? (B = isNaN(v) ? 1 : 0, R = w) : (R = Math.floor(Math.log(v) / Math.LN2), v * (N = Math.pow(2, -R)) < 1 && (R--, N *= 2), 2 <= (v += 1 <= R + c ? u / N : u * Math.pow(2, 1 - c)) * N && (R++, N /= 2), w <= R + c ? (B = 0, R = w) : 1 <= R + c ? (B = (v * N - 1) * Math.pow(2, S), R += c) : (B = v * Math.pow(2, c - 1) * Math.pow(2, S), R = 0)); 8 <= S; E[m + i] = 255 & B, i += g, B /= 256, S -= 8) ;
1918
+ for (R = R << S | B, y += S; 0 < y; E[m + i] = 255 & R, i += g, R /= 256, y -= 8) ;
1919
+ E[m + i - g] |= 128 * _;
1920
+ };
1921
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1922
+ }, { buffer: 3, lYpoI2: 11 }], 11: [function(e, s, o) {
1923
+ (function(a, d, p, f, b, A, T, I, M) {
1924
+ var E, v, m;
1925
+ function N() {
1926
+ }
1927
+ (a = s.exports = {}).nextTick = (v = typeof window < "u" && window.setImmediate, m = typeof window < "u" && window.postMessage && window.addEventListener, v ? function(S) {
1928
+ return window.setImmediate(S);
1929
+ } : m ? (E = [], window.addEventListener("message", function(S) {
1930
+ var $ = S.source;
1931
+ $ !== window && $ !== null || S.data !== "process-tick" || (S.stopPropagation(), 0 < E.length && E.shift()());
1932
+ }, !0), function(S) {
1933
+ E.push(S), window.postMessage("process-tick", "*");
1934
+ }) : function(S) {
1935
+ setTimeout(S, 0);
1936
+ }), a.title = "browser", a.browser = !0, a.env = {}, a.argv = [], a.on = N, a.addListener = N, a.once = N, a.off = N, a.removeListener = N, a.removeAllListeners = N, a.emit = N, a.binding = function(S) {
1937
+ throw new Error("process.binding is not supported");
1938
+ }, a.cwd = function() {
1939
+ return "/";
1940
+ }, a.chdir = function(S) {
1941
+ throw new Error("process.chdir is not supported");
1942
+ };
1943
+ }).call(this, e("lYpoI2"), typeof self < "u" ? self : typeof window < "u" ? window : {}, e("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");
1944
+ }, { buffer: 3, lYpoI2: 11 }] }, {}, [1])(1);
1945
+ });
1946
+ })(xe)), xe.exports;
1947
+ }
1948
+ var Un = kn();
1949
+ const Pn = /* @__PURE__ */ qn(Un), Fn = (t, n) => {
1950
+ const e = X(t), s = n.map((o) => te(o.id)).join(",");
1951
+ return `DELETE FROM "${e}" WHERE id in (${s});`;
1952
+ }, gt = (t, n, e) => {
1953
+ const s = X(t), o = e?.userId && t.propertyMap.has("createdBy"), a = e?.userId && t.propertyMap.has("updatedBy"), d = t.propertyMap.has("createdAt"), p = t.propertyMap.has("updatedAt"), f = /* @__PURE__ */ new Date(), b = [
1954
+ ...Array.from(t.propertyMap.values()).map((M) => M.columnName),
1955
+ ...t.foreignKeyColumnNames || t.foreignKeyNames
1956
+ ], A = [], T = [];
1957
+ return n.forEach((M) => {
1958
+ const E = at(t, M);
1959
+ o && (E.createdBy = e.userId), a && (E.updatedBy = e.userId), d && E.createdAt === void 0 && (E.createdAt = f), p && E.updatedAt === void 0 && (E.updatedAt = f);
1960
+ const v = ke(t, E), m = [];
1961
+ b.forEach((N) => {
1962
+ m.push("?"), A.push(v[N] ?? null);
1963
+ }), T.push(`(${m.join(",")})`);
1964
+ }), { sql: `INSERT INTO "${s}" (${b.join(",")}) VALUES ${T.join(",")};`, params: A };
1965
+ }, nt = async (t, n) => {
1966
+ const e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Date();
1967
+ let o = "";
1968
+ const a = /* @__PURE__ */ new Set();
1969
+ return n.create.forEach((d, p) => {
1970
+ const f = Array.from(d);
1971
+ f.forEach((m) => a.add(m));
1972
+ const b = V(p), A = gt(b, f, t.rxdb.context), T = fe(A.sql, A.params), I = f.map((m) => m.id);
1973
+ I.forEach((m) => e.set(m, p));
1974
+ const { sql: M, params: E } = De(t, b, {
1191
1975
  where: {
1192
1976
  combinator: "and",
1193
- rules: [{ field: "id", operator: "in", value: u }]
1977
+ rules: [{ field: "id", operator: "in", value: I }]
1194
1978
  }
1195
- }), y = F(h, f);
1196
- r += p + y;
1197
- }), n.update.forEach((i, c) => {
1198
- const a = Array.from(i);
1199
- a.forEach((p) => o.add(p));
1200
- const l = T(c), d = Object.groupBy(a, (p) => {
1201
- const u = D(p);
1202
- return Object.keys(u.patch).sort().join(",");
1979
+ }), v = fe(M, E);
1980
+ o += T + v;
1981
+ }), n.update.forEach((d, p) => {
1982
+ const f = Array.from(d);
1983
+ f.forEach((T) => a.add(T));
1984
+ const b = V(p), A = Object.groupBy(f, (T) => {
1985
+ const I = ae(T);
1986
+ return Pn(I.patch);
1203
1987
  });
1204
- Object.values(d).forEach((p) => {
1205
- const u = p[0], h = D(u), f = de(l, p, h.patch, {
1206
- ...e.rxdb.context,
1988
+ Object.values(A).forEach((T) => {
1989
+ const I = T[0], M = ae(I), E = Pe(b, T, M.patch, {
1990
+ ...t.rxdb.context,
1207
1991
  returning: !1,
1208
1992
  updatedAt: s
1209
- }), y = F(f.sql, f.params);
1210
- r += y;
1211
- const m = p.map(($) => $.id);
1212
- m.forEach(($) => t.set($, c));
1213
- const _ = ie(e, l, {
1993
+ }), v = fe(E.sql, E.params);
1994
+ o += v;
1995
+ const m = T.map(($) => $.id);
1996
+ m.forEach(($) => e.set($, p));
1997
+ const N = De(t, b, {
1214
1998
  where: {
1215
1999
  combinator: "and",
1216
2000
  rules: [{ field: "id", operator: "in", value: m }]
1217
2001
  }
1218
- }), N = F(_.sql, _.params);
1219
- r += N;
2002
+ }), S = fe(N.sql, N.params);
2003
+ o += S;
1220
2004
  });
1221
- }), n.remove.forEach((i, c) => {
1222
- const a = Array.from(i), l = T(c), d = nn(l, a);
1223
- r += d;
1224
- }), r && (await e.query(r)).results.forEach(({ columns: c, rows: a }) => {
1225
- const l = c.findIndex((u) => u === "id"), d = c.findIndex((u) => u === q), p = e.rxdb.entityManager;
1226
- a.forEach((u) => {
1227
- const h = u[l], f = t.get(h), y = T(f);
1228
- if (p.hasEntityRef(f, h)) {
1229
- const m = p.getEntityRef(f, h), _ = oe(y, c, u);
1230
- e.getRepository(f).updateEntity(m, _);
1231
- const N = D(m);
1232
- if (N.local = !0, d !== -1) {
1233
- const $ = BigInt(u[d]);
1234
- e.cacheRowIdEntity($, m);
2005
+ }), n.remove.forEach((d, p) => {
2006
+ const f = Array.from(d), b = V(p), A = Fn(b, f);
2007
+ o += A;
2008
+ }), o && (await t.query(o)).results.forEach(({ columns: p, rows: f }) => {
2009
+ const b = p.findIndex((I) => I === "id"), A = p.findIndex((I) => I === ie), T = t.rxdb.entityManager;
2010
+ f.forEach((I) => {
2011
+ const M = I[b], E = e.get(M), v = V(E);
2012
+ if (T.hasEntityRef(E, M)) {
2013
+ const m = T.getEntityRef(E, M), N = je(v, p, I);
2014
+ t.getRepository(E).updateEntity(m, N);
2015
+ const S = ae(m);
2016
+ if (S.local = !0, A !== -1) {
2017
+ const $ = BigInt(I[A]);
2018
+ t.cacheRowIdEntity($, m);
1235
2019
  }
1236
- N.modified = !1;
2020
+ S.modified = !1;
1237
2021
  }
1238
2022
  });
1239
2023
  }), n.remove.forEach(
1240
- (i) => i.forEach((c) => {
1241
- o.add(c);
1242
- const a = D(c);
1243
- a.origin = structuredClone({ ...c }), a.modified = !1, a.removed = !0, a.local = !1;
2024
+ (d) => d.forEach((p) => {
2025
+ a.add(p);
2026
+ const f = ae(p);
2027
+ f.origin = structuredClone({ ...p }), f.modified = !1, f.removed = !0, f.local = !1;
1244
2028
  })
1245
- ), Array.from(o);
1246
- }, sn = (e, n) => {
1247
- const t = A(n);
1248
- let s = `CREATE TABLE "${t}" (`;
1249
- const r = [], o = [], i = [];
1250
- n.propertyMap.forEach((a) => {
1251
- const l = a.columnName;
1252
- let d = `"${l}" ${rt(a)}`;
1253
- if (a.type === E.integer && a.primary ? d += " PRIMARY KEY AUTOINCREMENT" : (a.type === E.uuid || a.type === E.string) && a.primary && (d += " PRIMARY KEY", a.type === E.uuid && (d += " DEFAULT (lower(hex(randomblob(16))))")), !(a.type === E.uuid && a.primary) && a.default !== void 0) {
1254
- let u = a.default;
1255
- me(a.default) && (u = a.default()), u === "CURRENT_TIMESTAMP" ? d += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : (u = V(u, a), a.type === E.boolean || a.type === E.integer || a.type === E.number ? d += ` DEFAULT ${u}` : d += ` DEFAULT '${u}'`);
2029
+ ), Array.from(a);
2030
+ }, Wn = (t, n) => {
2031
+ const e = X(n);
2032
+ let s = `CREATE TABLE "${e}" (`;
2033
+ const o = [], a = [], d = [];
2034
+ n.propertyMap.forEach((f) => {
2035
+ const b = f.columnName;
2036
+ let A = `"${b}" ${kt(f)}`;
2037
+ if (f.type === D.integer && f.primary ? A += " PRIMARY KEY AUTOINCREMENT" : (f.type === D.uuid || f.type === D.string) && f.primary && (A += " PRIMARY KEY", f.type === D.uuid && (A += " DEFAULT (lower(hex(randomblob(16))))")), !(f.type === D.uuid && f.primary) && f.default !== void 0) {
2038
+ let I = f.default;
2039
+ Je(f.default) && (I = f.default()), I === "CURRENT_TIMESTAMP" ? A += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : (I = we(I, f), f.type === D.boolean || f.type === D.integer || f.type === D.number ? A += ` DEFAULT ${I}` : A += ` DEFAULT '${I}'`);
1256
2040
  }
1257
- switch (a.nullable || (d += " NOT NULL"), a.type) {
1258
- case E.json:
1259
- case E.keyValue:
1260
- case E.stringArray:
1261
- case E.numberArray:
1262
- o.push(`CHECK ( JSON_VALID(${l})=1 )`);
2041
+ switch (f.nullable || (A += " NOT NULL"), f.type) {
2042
+ case D.json:
2043
+ case D.keyValue:
2044
+ case D.stringArray:
2045
+ case D.numberArray:
2046
+ a.push(`CHECK ( JSON_VALID(${b})=1 )`);
1263
2047
  break;
1264
- case E.boolean:
1265
- o.push(`CHECK (${l} in(0,1))`);
2048
+ case D.boolean:
2049
+ a.push(`CHECK (${b} in(0,1))`);
1266
2050
  break;
1267
- case E.enum:
1268
- if ("enum" in a && a.enum && a.enum.length > 0) {
1269
- const u = a.enum.map((h) => `'${String(h).replace(/'/g, "''")}'`).join(",");
1270
- o.push(`CHECK (${l} in(${u}))`);
2051
+ case D.enum:
2052
+ if ("enum" in f && f.enum && f.enum.length > 0) {
2053
+ const I = f.enum.map((M) => `'${String(M).replace(/'/g, "''")}'`).join(",");
2054
+ a.push(`CHECK (${b} in(${I}))`);
1271
2055
  }
1272
2056
  break;
1273
2057
  }
1274
- a.unique && r.push(
1275
- `CREATE UNIQUE INDEX ${_e(n, a)} on "${t}"(${l});`
1276
- ), i.push(d);
1277
- }), n.relationMap.forEach((a) => {
1278
- if (a.kind === b.ONE_TO_ONE || a.kind === b.MANY_TO_ONE) {
1279
- const l = a.columnName, d = e.rxdb.schemaManager.getEntityMetadata(
1280
- a.mappedEntity,
1281
- a.mappedNamespace
2058
+ f.unique && o.push(
2059
+ `CREATE UNIQUE INDEX ${ze(n, f)} on "${e}"(${b});`
2060
+ ), d.push(A);
2061
+ }), n.relationMap.forEach((f) => {
2062
+ if (f.kind === z.ONE_TO_ONE || f.kind === z.MANY_TO_ONE) {
2063
+ const b = f.columnName, A = t.rxdb.schemaManager.getEntityMetadata(
2064
+ f.mappedEntity,
2065
+ f.mappedNamespace
1282
2066
  );
1283
- let p = "TEXT";
1284
- const u = d.propertyMap.get("id");
1285
- u.type === E.integer ? p = "INTEGER" : (u.type === E.uuid || u.type === E.string) && (p = "TEXT");
1286
- const h = a.onDelete === "SET NULL" || a.onUpdate === "SET NULL";
1287
- let f = `"${l}" ${p}`;
1288
- if (!a.nullable && !h && (f += " NOT NULL"), a.kind === b.MANY_TO_ONE && a.default !== void 0) {
1289
- const y = a;
1290
- let m = y.default;
1291
- me(y.default) && (m = y.default()), f += ` DEFAULT ${m}`;
2067
+ let T = "TEXT";
2068
+ const I = A.propertyMap.get("id");
2069
+ I.type === D.integer ? T = "INTEGER" : (I.type === D.uuid || I.type === D.string) && (T = "TEXT");
2070
+ const M = f.onDelete === "SET NULL" || f.onUpdate === "SET NULL";
2071
+ let E = `"${b}" ${T}`;
2072
+ if (!f.nullable && !M && (E += " NOT NULL"), f.kind === z.MANY_TO_ONE && f.default !== void 0) {
2073
+ const v = f;
2074
+ let m = v.default;
2075
+ Je(v.default) && (m = v.default()), E += ` DEFAULT ${m}`;
1292
2076
  }
1293
- if (a.mappedEntity) {
1294
- const y = e.rxdb.schemaManager.getEntityMetadata(
1295
- a.mappedEntity,
1296
- a.mappedNamespace
1297
- ), m = k(
1298
- y?.tableName ?? a.mappedEntity,
1299
- a.mappedNamespace
2077
+ if (f.mappedEntity) {
2078
+ const v = t.rxdb.schemaManager.getEntityMetadata(
2079
+ f.mappedEntity,
2080
+ f.mappedNamespace
2081
+ ), m = le(
2082
+ v?.tableName ?? f.mappedEntity,
2083
+ f.mappedNamespace
1300
2084
  );
1301
- f += ` REFERENCES ${m}(id)`, a.onDelete && (f += ` ON DELETE ${a.onDelete}`), a.onUpdate && (f += ` ON UPDATE ${a.onUpdate}`);
2085
+ E += ` REFERENCES ${m}(id)`, f.onDelete && (E += ` ON DELETE ${f.onDelete}`), f.onUpdate && (E += ` ON UPDATE ${f.onUpdate}`);
1302
2086
  }
1303
- i.push(f), (a.unique || a.kind === b.ONE_TO_ONE) && r.push(
1304
- `CREATE UNIQUE INDEX ${_e(n, a)} on "${t}"(${l});`
2087
+ d.push(E), (f.unique || f.kind === z.ONE_TO_ONE) && o.push(
2088
+ `CREATE UNIQUE INDEX ${ze(n, f)} on "${e}"(${b});`
1305
2089
  );
1306
2090
  }
1307
2091
  });
1308
- const c = [...i, ...o];
1309
- if (c.length)
1310
- s += c.map((a) => `
1311
- ${a}`).join(","), s += `
2092
+ const p = [...d, ...a];
2093
+ if (p.length)
2094
+ s += p.map((f) => `
2095
+ ${f}`).join(","), s += `
1312
2096
  );`;
1313
2097
  else
1314
- throw new R("columns is empty!");
1315
- return r.length && (s += `
1316
- ` + r.join(`
1317
- `)), n.indexes && n.indexes.length > 0 && n.indexes.forEach((a) => {
1318
- const l = `idx_${n.name}_${a.name}`, d = a.properties?.map((u) => {
1319
- const h = n.propertyMap.get(u);
1320
- if (h) return `"${h.columnName}"`;
1321
- const f = n.foreignKeyNames, y = n.foreignKeyColumnNames;
1322
- if (f && y) {
1323
- const m = f.indexOf(u);
1324
- if (m >= 0) return `"${y[m]}"`;
2098
+ throw new ee("columns is empty!");
2099
+ return o.length && (s += `
2100
+ ` + o.join(`
2101
+ `)), n.indexes && n.indexes.length > 0 && n.indexes.forEach((f) => {
2102
+ const b = `idx_${n.name}_${f.name}`, A = f.properties?.map((I) => {
2103
+ const M = n.propertyMap.get(I);
2104
+ if (M) return `"${M.columnName}"`;
2105
+ const E = n.foreignKeyNames, v = n.foreignKeyColumnNames;
2106
+ if (E && v) {
2107
+ const m = E.indexOf(I);
2108
+ if (m >= 0) return `"${v[m]}"`;
1325
2109
  }
1326
- return `"${u}"`;
1327
- }).join(", ") || `"${a.name}"`, p = a.unique ? "UNIQUE " : "";
2110
+ return `"${I}"`;
2111
+ }).join(", ") || `"${f.name}"`, T = f.unique ? "UNIQUE " : "";
1328
2112
  s += `
1329
- CREATE ${p}INDEX "${l}" ON "${t}"(${d});`;
2113
+ CREATE ${T}INDEX "${b}" ON "${e}"(${A});`;
1330
2114
  }), s;
1331
- }, rn = (e, n) => sn(e, n), pe = (e, n = {}) => {
1332
- const t = A(e), s = T(B), r = A(s), { propertyMap: o, name: i, foreignKeyNames: c, foreignKeyColumnNames: a, namespace: l } = e, d = [];
1333
- for (const [g, C] of o)
1334
- g !== "id" && d.push({ jsName: g, dbColumn: C.columnName });
1335
- const p = a || c;
1336
- for (let g = 0; g < c.length; g++)
1337
- c[g] !== "id" && d.push({ jsName: c[g], dbColumn: p[g] });
1338
- const u = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: h, branchId: f } = n, y = I(h), m = I(f || "main"), _ = `'${l}','${i}',${m},${y}`, N = (g) => g === E.stringArray || g === E.numberArray || g === E.json || g === E.keyValue, $ = (g, C, x) => {
1339
- const Z = o.get(C);
1340
- return Z?.type === E.boolean ? `CASE WHEN ${x}.${g} = 1 THEN 1 ELSE 0 END` : N(Z?.type) ? `CASE WHEN ${x}.${g} IS NOT NULL THEN json(${x}.${g}) ELSE NULL END` : `${x}.${g}`;
1341
- }, S = (g, C, x) => o.get(C)?.type === E.boolean ? `CASE WHEN ${x}.${g} = 1 THEN 1 ELSE 0 END` : `${x}.${g}`, L = `
1342
- DROP TRIGGER IF EXISTS ${t}_insert;
1343
- CREATE TRIGGER ${t}_insert AFTER INSERT ON "${t}"
2115
+ }, Kn = (t, n) => Wn(t, n), Fe = (t, n = {}) => {
2116
+ const e = X(t), s = V(pe), o = X(s), { propertyMap: a, name: d, foreignKeyNames: p, foreignKeyColumnNames: f, namespace: b } = t, A = [];
2117
+ for (const [u, i] of a)
2118
+ u !== "id" && A.push({ jsName: u, dbColumn: i.columnName });
2119
+ const T = f || p;
2120
+ for (let u = 0; u < p.length; u++)
2121
+ p[u] !== "id" && A.push({ jsName: p[u], dbColumn: T[u] });
2122
+ const I = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: M, branchId: E } = n, v = te(M), m = te(E || "main"), N = `'${b}','${d}',${m},${v}`, S = (u) => u === D.stringArray || u === D.numberArray || u === D.json || u === D.keyValue, $ = (u, i, g) => {
2123
+ const _ = a.get(i);
2124
+ return _?.type === D.boolean ? `CASE WHEN ${g}.${u} = 1 THEN 1 ELSE 0 END` : S(_?.type) ? `CASE WHEN ${g}.${u} IS NOT NULL THEN json(${g}.${u}) ELSE NULL END` : `${g}.${u}`;
2125
+ }, R = (u, i, g) => a.get(i)?.type === D.boolean ? `CASE WHEN ${g}.${u} = 1 THEN 1 ELSE 0 END` : `${g}.${u}`, B = `
2126
+ DROP TRIGGER IF EXISTS ${e}_insert;
2127
+ CREATE TRIGGER ${e}_insert AFTER INSERT ON "${e}"
1344
2128
  BEGIN
1345
- INSERT INTO ${r} (${u}) VALUES (
1346
- 'INSERT',${_}, NEW.id, NULL,
1347
- json_object(${d.map((g) => `'${g.jsName}', ${$(g.dbColumn, g.jsName, "NEW")}`).join(`,
2129
+ INSERT INTO ${o} (${I}) VALUES (
2130
+ 'INSERT',${N}, NEW.id, NULL,
2131
+ json_object(${A.map((u) => `'${u.jsName}', ${$(u.dbColumn, u.jsName, "NEW")}`).join(`,
1348
2132
  `)})
1349
2133
  );
1350
- END;`, O = (g) => d.map((C) => {
1351
- const x = N(o.get(C.jsName)?.type) ? 1 : 0;
1352
- return `SELECT '${C.jsName}' AS key, ${S(C.dbColumn, C.jsName, g)} AS value, ${x} AS is_json WHERE OLD.${C.dbColumn} IS NOT NEW.${C.dbColumn}`;
2134
+ END;`, y = (u) => A.map((i) => {
2135
+ const g = S(a.get(i.jsName)?.type) ? 1 : 0;
2136
+ return `SELECT '${i.jsName}' AS key, ${R(i.dbColumn, i.jsName, u)} AS value, ${g} AS is_json WHERE OLD.${i.dbColumn} IS NOT NEW.${i.dbColumn}`;
1353
2137
  }).join(`
1354
- UNION `), M = `
1355
- DROP TRIGGER IF EXISTS ${t}_update;
1356
- CREATE TRIGGER ${t}_update AFTER UPDATE ON "${t}"
1357
- WHEN ( ${d.map((g) => `OLD.${g.dbColumn} IS NOT NEW.${g.dbColumn}`).join(` OR
2138
+ UNION `), w = `
2139
+ DROP TRIGGER IF EXISTS ${e}_update;
2140
+ CREATE TRIGGER ${e}_update AFTER UPDATE ON "${e}"
2141
+ WHEN ( ${A.map((u) => `OLD.${u.dbColumn} IS NOT NEW.${u.dbColumn}`).join(` OR
1358
2142
  `)} )
1359
2143
  BEGIN
1360
- INSERT INTO ${r} (${u}) VALUES (
1361
- 'UPDATE',${_}, NEW.id,
2144
+ INSERT INTO ${o} (${I}) VALUES (
2145
+ 'UPDATE',${N}, NEW.id,
1362
2146
  (
1363
2147
  SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
1364
- ${O("OLD")}
2148
+ ${y("OLD")}
1365
2149
  )
1366
2150
  ),
1367
2151
  (
1368
2152
  SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
1369
- ${O("NEW")}
2153
+ ${y("NEW")}
1370
2154
  )
1371
2155
  )
1372
2156
  );
1373
- END;`, j = `
1374
- DROP TRIGGER IF EXISTS ${t}_delete;
1375
- CREATE TRIGGER ${t}_delete AFTER DELETE ON "${t}"
2157
+ END;`, c = `
2158
+ DROP TRIGGER IF EXISTS ${e}_delete;
2159
+ CREATE TRIGGER ${e}_delete AFTER DELETE ON "${e}"
1376
2160
  BEGIN
1377
- INSERT INTO ${r} (${u}) VALUES (
1378
- 'DELETE',${_}, OLD.id,
1379
- json_object(${d.map((g) => `'${g.jsName}', ${$(g.dbColumn, g.jsName, "OLD")}`).join(`,
2161
+ INSERT INTO ${o} (${I}) VALUES (
2162
+ 'DELETE',${N}, OLD.id,
2163
+ json_object(${A.map((u) => `'${u.jsName}', ${$(u.dbColumn, u.jsName, "OLD")}`).join(`,
1380
2164
  `)}), NULL
1381
2165
  );
1382
2166
  END;`;
1383
- return L + `
1384
- ` + M + `
1385
- ` + j;
1386
- }, on = (e, n, t) => {
2167
+ return B + `
2168
+ ` + w + `
2169
+ ` + c;
2170
+ }, Hn = (t, n, e) => {
1387
2171
  let s = "";
1388
- for (let r = 0; r < n.length; r++) {
1389
- const o = n[r], i = T(o);
2172
+ for (let o = 0; o < n.length; o++) {
2173
+ const a = n[o], d = V(a);
1390
2174
  if (s += `
1391
- ` + rn(e, i), i.log !== !1) {
1392
- const c = pe(i);
2175
+ ` + Kn(t, d), d.log !== !1) {
2176
+ const p = Fe(d);
1393
2177
  s += `
1394
- ` + c;
2178
+ ` + p;
1395
2179
  }
1396
2180
  }
1397
- if (t) {
1398
- const r = /* @__PURE__ */ new Map();
1399
- t.forEach((o) => {
1400
- const i = T(o);
1401
- r.has(i) === !1 && r.set(i, /* @__PURE__ */ new Set()), r.get(i).add(o);
2181
+ if (e) {
2182
+ const o = /* @__PURE__ */ new Map();
2183
+ e.forEach((a) => {
2184
+ const d = V(a);
2185
+ o.has(d) === !1 && o.set(d, /* @__PURE__ */ new Set()), o.get(d).add(a);
1402
2186
  });
1403
- for (const o of r.keys()) {
1404
- const i = De(
1405
- o,
1406
- Array.from(r.get(o)),
1407
- e.rxdb.context
2187
+ for (const a of o.keys()) {
2188
+ const d = gt(
2189
+ a,
2190
+ Array.from(o.get(a)),
2191
+ t.rxdb.context
1408
2192
  );
1409
2193
  s += `
1410
- ` + F(i.sql, i.params);
2194
+ ` + fe(d.sql, d.params);
1411
2195
  }
1412
2196
  }
1413
2197
  return s;
1414
- }, an = (e) => {
1415
- const n = A(e);
2198
+ }, Vn = (t) => {
2199
+ const n = X(t);
1416
2200
  return `DROP TRIGGER IF EXISTS ${n}_insert;
1417
2201
  DROP TRIGGER IF EXISTS ${n}_update;
1418
2202
  DROP TRIGGER IF EXISTS ${n}_delete;`;
1419
- }, ve = (e) => {
2203
+ }, Et = (t) => {
1420
2204
  let n = "";
1421
- return e.rxdb.config.entities.forEach((t) => {
1422
- const s = T(t);
1423
- s.log !== !1 && (n += an(s));
2205
+ return t.rxdb.config.entities.forEach((e) => {
2206
+ const s = V(e);
2207
+ s.log !== !1 && (n += Vn(s));
1424
2208
  }), n;
1425
- }, Pe = (e, n) => {
1426
- const { deletes: t, inserts: s, updates: r } = n, o = { deletes: [], inserts: [], updates: [] }, i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
1427
- for (const [u, h] of t.entries()) {
1428
- const [f, y, m] = ee(u), _ = `${f}:${y}`, N = i.get(_);
1429
- N ? N.add(m) : i.set(_, /* @__PURE__ */ new Set([m]));
1430
- let $ = c.get(_);
1431
- $ || ($ = /* @__PURE__ */ new Map(), c.set(_, $)), $.set(m, {
1432
- patch: h.patch,
1433
- inversePatch: h.inversePatch
2209
+ }, _t = (t, n) => {
2210
+ const { deletes: e, inserts: s, updates: o } = n, a = { deletes: [], inserts: [], updates: [] }, d = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
2211
+ for (const [I, M] of e.entries()) {
2212
+ const [E, v, m] = Re(I), N = `${E}:${v}`, S = d.get(N);
2213
+ S ? S.add(m) : d.set(N, /* @__PURE__ */ new Set([m]));
2214
+ let $ = p.get(N);
2215
+ $ || ($ = /* @__PURE__ */ new Map(), p.set(N, $)), $.set(m, {
2216
+ patch: M.patch,
2217
+ inversePatch: M.inversePatch
1434
2218
  });
1435
2219
  }
1436
- for (const [u, h] of i) {
1437
- const [f, y] = u.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(y, f), _ = A(m), N = m.propertyMap.get("id").type === "integer";
2220
+ for (const [I, M] of d) {
2221
+ const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E), N = X(m), S = m.propertyMap.get("id").type === "integer";
1438
2222
  let $ = "";
1439
- N ? $ = Array.from(h).join(",") : $ = Array.from(h).map((L) => I(L)).join(",");
1440
- const S = `DELETE FROM "${_}" WHERE id in (${$});`;
1441
- o.deletes.push({
2223
+ S ? $ = Array.from(M).join(",") : $ = Array.from(M).map((B) => te(B)).join(",");
2224
+ const R = `DELETE FROM "${N}" WHERE id in (${$});`;
2225
+ a.deletes.push({
1442
2226
  metadata: m,
1443
- ids: h,
1444
- sql: S,
1445
- changes: c.get(u)
2227
+ ids: M,
2228
+ sql: R,
2229
+ changes: p.get(I)
1446
2230
  });
1447
2231
  }
1448
- const a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
1449
- for (const [u, h] of s.entries()) {
1450
- const [f, y, m] = ee(u), _ = `${f}:${y}`, N = a.get(_), $ = { ...h.patch, id: m };
1451
- N ? N.push($) : a.set(_, [$]);
1452
- let S = l.get(_);
1453
- S || (S = /* @__PURE__ */ new Map(), l.set(_, S)), S.set(m, {
1454
- patch: h.patch,
1455
- inversePatch: h.inversePatch
2232
+ const f = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map();
2233
+ for (const [I, M] of s.entries()) {
2234
+ const [E, v, m] = Re(I), N = `${E}:${v}`, S = f.get(N), $ = { ...M.patch, id: m };
2235
+ S ? S.push($) : f.set(N, [$]);
2236
+ let R = b.get(N);
2237
+ R || (R = /* @__PURE__ */ new Map(), b.set(N, R)), R.set(m, {
2238
+ patch: M.patch,
2239
+ inversePatch: M.inversePatch
1456
2240
  });
1457
2241
  }
1458
- for (const [u, h] of a) {
1459
- const [f, y] = u.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(y, f);
1460
- let _ = "";
1461
- h.forEach((N) => {
1462
- for (const [O, M] of m.propertyMap)
1463
- N[O] === void 0 && M.default !== void 0 && (typeof M.default == "function" ? N[O] = M.default() : N[O] = M.default);
1464
- const { sql: $, params: S } = Le(m, N, {
2242
+ for (const [I, M] of f) {
2243
+ const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E);
2244
+ let N = "";
2245
+ M.forEach((S) => {
2246
+ for (const [y, w] of m.propertyMap)
2247
+ S[y] === void 0 && w.default !== void 0 && (typeof w.default == "function" ? S[y] = w.default() : S[y] = w.default);
2248
+ const { sql: $, params: R } = pt(m, S, {
1465
2249
  useReplace: !0
1466
- }), L = F($, S);
1467
- _ += L;
1468
- }), o.inserts.push({
2250
+ }), B = fe($, R);
2251
+ N += B;
2252
+ }), a.inserts.push({
1469
2253
  metadata: m,
1470
- ids: new Set(h.filter((N) => N != null).map((N) => N.id)),
1471
- sql: _,
1472
- changes: l.get(u)
2254
+ ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
2255
+ sql: N,
2256
+ changes: b.get(I)
1473
2257
  });
1474
2258
  }
1475
- const d = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
1476
- for (const [u, h] of r.entries()) {
1477
- const [f, y, m] = ee(u), _ = `${f}:${y}`, N = d.get(_), $ = { ...h.patch, id: m };
1478
- N ? N.push($) : d.set(_, [$]);
1479
- let S = p.get(_);
1480
- S || (S = /* @__PURE__ */ new Map(), p.set(_, S));
1481
- const L = e.rxdb.schemaManager.getEntityMetadata(y, f), O = h.patch ? { ...h.patch } : null, M = h.inversePatch ? { ...h.inversePatch } : null;
1482
- L && (O && Object.keys(O).forEach((j) => {
1483
- const g = L.propertyMap.get(j);
1484
- g && (O[j] = P(O[j], g));
1485
- }), M && Object.keys(M).forEach((j) => {
1486
- const g = L.propertyMap.get(j);
1487
- g && (M[j] = P(M[j], g));
1488
- })), S.set(m, {
1489
- patch: O,
1490
- inversePatch: M
2259
+ const A = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
2260
+ for (const [I, M] of o.entries()) {
2261
+ const [E, v, m] = Re(I), N = `${E}:${v}`, S = A.get(N), $ = { ...M.patch, id: m };
2262
+ S ? S.push($) : A.set(N, [$]);
2263
+ let R = T.get(N);
2264
+ R || (R = /* @__PURE__ */ new Map(), T.set(N, R));
2265
+ const B = t.rxdb.schemaManager.getEntityMetadata(v, E), y = M.patch ? { ...M.patch } : null, w = M.inversePatch ? { ...M.inversePatch } : null;
2266
+ B && (y && Object.keys(y).forEach((c) => {
2267
+ const u = B.propertyMap.get(c);
2268
+ u && (y[c] = ue(y[c], u));
2269
+ }), w && Object.keys(w).forEach((c) => {
2270
+ const u = B.propertyMap.get(c);
2271
+ u && (w[c] = ue(w[c], u));
2272
+ })), R.set(m, {
2273
+ patch: y,
2274
+ inversePatch: w
1491
2275
  });
1492
2276
  }
1493
- for (const [u, h] of d) {
1494
- const [f, y] = u.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(y, f);
1495
- let _ = "";
1496
- h.forEach((N) => {
2277
+ for (const [I, M] of A) {
2278
+ const [E, v] = I.split(":"), m = t.rxdb.schemaManager.getEntityMetadata(v, E);
2279
+ let N = "";
2280
+ M.forEach((S) => {
1497
2281
  let $;
1498
- m.propertyMap.has("updatedAt") && ($ = N.updatedAt);
1499
- const { id: S, ...L } = N, { sql: O, params: M } = de(m, { id: S }, L, {
2282
+ m.propertyMap.has("updatedAt") && ($ = S.updatedAt);
2283
+ const { id: R, ...B } = S, { sql: y, params: w } = Pe(m, { id: R }, B, {
1500
2284
  updatedAt: $
1501
2285
  });
1502
- _ += F(O, M);
1503
- }), o.updates.push({
2286
+ N += fe(y, w);
2287
+ }), a.updates.push({
1504
2288
  metadata: m,
1505
- ids: new Set(h.filter((N) => N != null).map((N) => N.id)),
1506
- sql: _,
1507
- changes: p.get(u)
2289
+ ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
2290
+ sql: N,
2291
+ changes: T.get(I)
1508
2292
  });
1509
2293
  }
1510
- return o;
1511
- }, ke = (e, n) => {
1512
- let t = "";
1513
- e.rxdb.config.entities.forEach((i) => {
1514
- const c = T(i);
1515
- if (c.log !== !1)
2294
+ return a;
2295
+ }, wt = (t, n) => {
2296
+ let e = "";
2297
+ t.rxdb.config.entities.forEach((d) => {
2298
+ const p = V(d);
2299
+ if (p.log !== !1)
1516
2300
  try {
1517
- const a = pe(c, {
2301
+ const f = Fe(p, {
1518
2302
  branchId: n
1519
2303
  });
1520
- a.trim() && (t += a);
1521
- } catch (a) {
1522
- console.warn(`Failed to generate trigger SQL for entity ${c.name}:`, a);
2304
+ f.trim() && (e += f);
2305
+ } catch (f) {
2306
+ console.warn(`Failed to generate trigger SQL for entity ${p.name}:`, f);
1523
2307
  }
1524
2308
  });
1525
- const s = T(H), r = A(s), o = n.replace(/'/g, "''");
1526
- return t += `
1527
- UPDATE "${r}"
2309
+ const s = V(_e), o = X(s), a = n.replace(/'/g, "''");
2310
+ return e += `
2311
+ UPDATE "${o}"
1528
2312
  SET
1529
2313
  activated = CASE
1530
- WHEN id = '${o}' THEN 1
2314
+ WHEN id = '${a}' THEN 1
1531
2315
  ELSE 0
1532
2316
  END,
1533
2317
  updatedAt = CASE
1534
- WHEN (id = '${o}' AND activated = 0) OR (id != '${o}' AND activated = 1) THEN CURRENT_TIMESTAMP
2318
+ WHEN (id = '${a}' AND activated = 0) OR (id != '${a}' AND activated = 1) THEN CURRENT_TIMESTAMP
1535
2319
  ELSE updatedAt
1536
2320
  END
1537
- WHERE id = '${o}' OR activated = 1
1538
- RETURNING rowid as ${q},*;
1539
- `, t;
1540
- }, cn = async (e, n) => {
1541
- const { branchId: t, actions: s } = n, r = s && Pe(e, s);
1542
- let o;
2321
+ WHERE id = '${a}' OR activated = 1
2322
+ RETURNING rowid as ${ie},*;
2323
+ `, e;
2324
+ }, Yn = async (t, n) => {
2325
+ const { branchId: e, actions: s } = n, o = s && _t(t, s);
2326
+ let a;
1543
2327
  try {
1544
- await e.transaction(async (a) => {
1545
- const l = ve(e);
1546
- if (l && await a.execute(l), r) {
1547
- if (r.deletes.length)
1548
- for (const d of r.deletes)
1549
- await a.execute(d.sql);
1550
- if (r.inserts.length)
1551
- for (const d of r.inserts)
1552
- d.successResults = await a.execute(d.sql);
1553
- if (r.updates.length)
1554
- for (const d of r.updates)
1555
- d.successResults = await a.execute(d.sql);
2328
+ await t.transaction(async (f) => {
2329
+ const b = Et(t);
2330
+ if (b && await f.execute(b), o) {
2331
+ if (o.deletes.length)
2332
+ for (const A of o.deletes)
2333
+ await f.execute(A.sql);
2334
+ if (o.inserts.length)
2335
+ for (const A of o.inserts)
2336
+ A.successResults = await f.execute(A.sql);
2337
+ if (o.updates.length)
2338
+ for (const A of o.updates)
2339
+ A.successResults = await f.execute(A.sql);
1556
2340
  }
1557
- s?.updateRxDBChangeSequence !== void 0 && await e.setRxDBChangeSequence(s.updateRxDBChangeSequence);
2341
+ s?.updateRxDBChangeSequence !== void 0 && await t.setRxDBChangeSequence(s.updateRxDBChangeSequence);
1558
2342
  }, !1);
1559
- const i = ke(e, t);
1560
- o = await e.internalQuery(i);
1561
- const c = (a, l) => {
1562
- if (l.length === 0) return;
1563
- const d = l.map((p) => {
1564
- const u = { ...p };
2343
+ const d = wt(t, e);
2344
+ a = await t.internalQuery(d);
2345
+ const p = (f, b) => {
2346
+ if (b.length === 0) return;
2347
+ const A = b.map((T) => {
2348
+ const I = { ...T };
1565
2349
  return {
1566
- namespace: a.namespace,
1567
- entity: a.name,
2350
+ namespace: f.namespace,
2351
+ entity: f.name,
1568
2352
  type: "UPDATE",
1569
- id: p.id,
1570
- patch: u,
1571
- inversePatch: u,
1572
- recordAt: p.createdAt
2353
+ id: T.id,
2354
+ patch: I,
2355
+ inversePatch: I,
2356
+ recordAt: T.createdAt
1573
2357
  };
1574
2358
  });
1575
- e.rxdb.dispatchEvent(new Y(d));
2359
+ t.rxdb.dispatchEvent(new Te(A));
1576
2360
  };
1577
- if (o) {
1578
- const a = X(e, H, o, !0), l = T(H);
1579
- c(l, a);
2361
+ if (a) {
2362
+ const f = Ie(t, _e, a, !0), b = V(_e);
2363
+ p(b, f);
1580
2364
  }
1581
- r && Fe(e, r);
1582
- } catch (i) {
1583
- throw new R(`switch branch ${t} failed`, { cause: i });
2365
+ o && bt(t, o);
2366
+ } catch (d) {
2367
+ throw new ee(`switch branch ${e} failed`, { cause: d });
1584
2368
  }
1585
2369
  };
1586
- async function ln(e, n, t = !1) {
1587
- if (await e.transaction(async (s) => {
1588
- if (t) {
1589
- const r = ve(e);
1590
- r && await s.execute(r);
2370
+ async function Qn(t, n, e = !1) {
2371
+ if (await t.transaction(async (s) => {
2372
+ if (e) {
2373
+ const o = Et(t);
2374
+ o && await s.execute(o);
1591
2375
  }
1592
- for (const r of n.deletes)
1593
- await s.execute(r.sql);
1594
- for (const r of n.inserts)
1595
- r.successResults = await s.execute(r.sql);
1596
- for (const r of n.updates)
1597
- r.successResults = await s.execute(r.sql);
1598
- }, !1), t) {
1599
- const s = await e.rxdb.versionManager.getCurrentBranch(), r = ke(e, s.id);
1600
- await e.internalQuery(r);
1601
- }
1602
- Fe(e, n);
2376
+ for (const o of n.deletes)
2377
+ await s.execute(o.sql);
2378
+ for (const o of n.inserts)
2379
+ o.successResults = await s.execute(o.sql);
2380
+ for (const o of n.updates)
2381
+ o.successResults = await s.execute(o.sql);
2382
+ }, !1), e) {
2383
+ const s = await t.rxdb.versionManager.getCurrentBranch(), o = wt(t, s.id);
2384
+ await t.internalQuery(o);
2385
+ }
2386
+ bt(t, n);
1603
2387
  }
1604
- function Fe(e, n) {
1605
- for (const t of n.deletes) {
1606
- const s = te(t.metadata);
1607
- Ct(e, s, Array.from(t.ids));
1608
- const r = t.metadata, o = Array.from(t.ids).map((i) => {
1609
- const c = t.changes.get(String(i));
2388
+ function bt(t, n) {
2389
+ for (const e of n.deletes) {
2390
+ const s = Ce(e.metadata);
2391
+ pn(t, s, Array.from(e.ids));
2392
+ const o = e.metadata, a = Array.from(e.ids).map((d) => {
2393
+ const p = e.changes.get(String(d));
1610
2394
  return {
1611
- namespace: r.namespace,
1612
- entity: r.name,
2395
+ namespace: o.namespace,
2396
+ entity: o.name,
1613
2397
  type: "DELETE",
1614
- id: i,
2398
+ id: d,
1615
2399
  patch: null,
1616
- inversePatch: c?.inversePatch ?? null,
2400
+ inversePatch: p?.inversePatch ?? null,
1617
2401
  recordAt: /* @__PURE__ */ new Date()
1618
2402
  };
1619
2403
  });
1620
- e.rxdb.dispatchEvent(new ce(o));
2404
+ t.rxdb.dispatchEvent(new qe(a));
1621
2405
  }
1622
- for (const t of n.inserts) {
1623
- const s = te(t.metadata), r = X(e, s, t.successResults), o = t.metadata, i = r.map((c) => {
1624
- const a = t.changes.get(String(c.id));
2406
+ for (const e of n.inserts) {
2407
+ const s = Ce(e.metadata), o = Ie(t, s, e.successResults), a = e.metadata, d = o.map((p) => {
2408
+ const f = e.changes.get(String(p.id));
1625
2409
  return {
1626
- namespace: o.namespace,
1627
- entity: o.name,
2410
+ namespace: a.namespace,
2411
+ entity: a.name,
1628
2412
  type: "INSERT",
1629
- id: c.id,
1630
- patch: a?.patch ?? { ...c },
1631
- inversePatch: a?.inversePatch ?? null,
1632
- recordAt: c.createdAt
2413
+ id: p.id,
2414
+ patch: f?.patch ?? { ...p },
2415
+ inversePatch: f?.inversePatch ?? null,
2416
+ recordAt: p.createdAt
1633
2417
  };
1634
2418
  });
1635
- e.rxdb.dispatchEvent(new K(i));
2419
+ t.rxdb.dispatchEvent(new Ee(d));
1636
2420
  }
1637
- for (const t of n.updates) {
1638
- const s = te(t.metadata), r = X(e, s, t.successResults, !0), o = t.metadata, i = r.map((c) => {
1639
- const a = t.changes.get(String(c.id));
2421
+ for (const e of n.updates) {
2422
+ const s = Ce(e.metadata), o = Ie(t, s, e.successResults, !0), a = e.metadata, d = o.map((p) => {
2423
+ const f = e.changes.get(String(p.id));
1640
2424
  return {
1641
- namespace: o.namespace,
1642
- entity: o.name,
2425
+ namespace: a.namespace,
2426
+ entity: a.name,
1643
2427
  type: "UPDATE",
1644
- id: c.id,
1645
- patch: a?.patch ?? { ...c },
1646
- inversePatch: a?.inversePatch ?? null,
1647
- recordAt: c.updatedAt || c.createdAt || /* @__PURE__ */ new Date()
2428
+ id: p.id,
2429
+ patch: f?.patch ?? { ...p },
2430
+ inversePatch: f?.inversePatch ?? null,
2431
+ recordAt: p.updatedAt || p.createdAt || /* @__PURE__ */ new Date()
1648
2432
  };
1649
2433
  });
1650
- e.rxdb.dispatchEvent(new Y(i));
2434
+ t.rxdb.dispatchEvent(new Te(d));
1651
2435
  }
1652
2436
  }
1653
- const Te = (e, n, t) => {
2437
+ const rt = (t, n, e) => {
1654
2438
  let s = "";
1655
- return e.rxdb.config.entities.forEach((r) => {
1656
- const o = T(r);
1657
- if (o.log !== !1) {
1658
- const i = pe(o, {
2439
+ return t.rxdb.config.entities.forEach((o) => {
2440
+ const a = V(o);
2441
+ if (a.log !== !1) {
2442
+ const d = Fe(a, {
1659
2443
  branchId: n,
1660
- transactionId: t
2444
+ transactionId: e
1661
2445
  });
1662
2446
  s += `
1663
- ` + i;
2447
+ ` + d;
1664
2448
  }
1665
2449
  }), s;
1666
2450
  };
1667
- class _n extends He {
1668
- constructor(n, t) {
1669
- super(n), this.options = t, t.repositories && Object.keys(t.repositories).forEach((r) => {
1670
- this.repository(r, t.repositories[r]);
2451
+ class rr extends $t {
2452
+ constructor(n, e) {
2453
+ super(n), this.options = e, e.repositories && Object.keys(e.repositories).forEach((o) => {
2454
+ this.repository(o, e.repositories[o]);
1671
2455
  });
1672
- const s = ze((r) => {
1673
- this.#t || Xt(this, r);
2456
+ const s = Ot((o) => {
2457
+ this.#t || Mn(this, o);
1674
2458
  });
1675
- this.#r().then((r) => {
1676
- r.addEventListener(v.SQLITE_INSERT, s), r.addEventListener(v.SQLITE_UPDATE, s), r.addEventListener(v.SQLITE_DELETE, s);
1677
- }).catch((r) => console.error("[RxDBAdapterSqlite] Failed to register event listeners", r)), this.repository("Repository", je), this.repository("TreeRepository", tn);
2459
+ this.#s().then((o) => {
2460
+ o.addEventListener(ce.SQLITE_INSERT, s), o.addEventListener(ce.SQLITE_UPDATE, s), o.addEventListener(ce.SQLITE_DELETE, s);
2461
+ }).catch((o) => console.error("[RxDBAdapterSqlite] Failed to register event listeners", o)), this.repository("Repository", ht), this.repository("TreeRepository", Dn);
1678
2462
  }
1679
2463
  // SQLite 客户端缓存
1680
2464
  #n;
@@ -1685,29 +2469,29 @@ class _n extends He {
1685
2469
  * 存储数据库行ID到实体UUID的映射关系
1686
2470
  * 用于在数据库操作中快速查找实体
1687
2471
  */
1688
- #a = /* @__PURE__ */ new Map();
2472
+ #i = /* @__PURE__ */ new Map();
1689
2473
  #o = /* @__PURE__ */ new WeakMap();
1690
2474
  // 查询任务队列执行器
1691
- #c = new we(1);
2475
+ #c = new st(1);
1692
2476
  // sqlite 客户端
1693
- #s;
2477
+ #r;
1694
2478
  // 是否已断开连接
1695
2479
  #t = !1;
1696
2480
  /**
1697
2481
  * 适配器名称
1698
2482
  */
1699
- name = xt;
2483
+ name = yn;
1700
2484
  /**
1701
2485
  * 获取实体仓库
1702
2486
  * @param EntityType 实体类
1703
2487
  */
1704
2488
  getRepository(n) {
1705
2489
  if (!this.repository_cache.has(n)) {
1706
- const t = T(n), s = this.repository_map.get(t.repository);
2490
+ const e = V(n), s = this.repository_map.get(e.repository);
1707
2491
  if (!s)
1708
- throw new R(`Repository '${t.repository}' not found`);
1709
- const r = new s(this, n);
1710
- return this.repository_cache.set(n, r), r;
2492
+ throw new ee(`Repository '${e.repository}' not found`);
2493
+ const o = new s(this, n);
2494
+ return this.repository_cache.set(n, o), o;
1711
2495
  }
1712
2496
  return this.repository_cache.get(n);
1713
2497
  }
@@ -1715,7 +2499,7 @@ class _n extends He {
1715
2499
  * 连接 wab sqlite
1716
2500
  */
1717
2501
  async connect() {
1718
- return await this.#r(), this;
2502
+ return await this.#s(), this;
1719
2503
  }
1720
2504
  /**
1721
2505
  * 断开连接
@@ -1727,18 +2511,18 @@ class _n extends He {
1727
2511
  * 获取版本
1728
2512
  */
1729
2513
  async version() {
1730
- return await (await this.#r()).version();
2514
+ return await (await this.#s()).version();
1731
2515
  }
1732
2516
  /**
1733
2517
  * 保存多个实体
1734
2518
  * @param entities
1735
2519
  */
1736
2520
  async saveMany(n) {
1737
- const t = he({
2521
+ const e = Qe({
1738
2522
  need_save_entities: n,
1739
2523
  need_remove_entities: []
1740
2524
  });
1741
- return this.mutations(t);
2525
+ return this.mutations(e);
1742
2526
  }
1743
2527
  /**
1744
2528
  * 删除多个实例
@@ -1746,26 +2530,26 @@ class _n extends He {
1746
2530
  * @returns
1747
2531
  */
1748
2532
  async removeMany(n) {
1749
- const t = he({
2533
+ const e = Qe({
1750
2534
  need_save_entities: [],
1751
2535
  need_remove_entities: n
1752
2536
  });
1753
- return this.mutations(t);
2537
+ return this.mutations(e);
1754
2538
  }
1755
2539
  /**
1756
2540
  * 批量修改实体(创建/更新/删除)
1757
2541
  * @param options
1758
2542
  */
1759
2543
  async mutations(n) {
1760
- return this.#e ? await $e(this, n) : await this.transaction(() => $e(this, n));
2544
+ return this.#e ? await nt(this, n) : await this.transaction(() => nt(this, n));
1761
2545
  }
1762
2546
  /**
1763
2547
  * 判断表是否存在
1764
2548
  * @param EntityType
1765
2549
  */
1766
2550
  async isTableExisted(n) {
1767
- const t = T(n), s = A(t), { sql: r, params: o } = nt(s), i = await this.#i(r, o);
1768
- return st(i) === !1;
2551
+ const e = V(n), s = X(e), { sql: o, params: a } = Dt(s), d = await this.#a(o, a);
2552
+ return qt(d) === !1;
1769
2553
  }
1770
2554
  /**
1771
2555
  * 创建表和初始化数据
@@ -1773,9 +2557,9 @@ class _n extends He {
1773
2557
  * @param entities 视图数据
1774
2558
  * @returns
1775
2559
  */
1776
- async createTables(n, t) {
1777
- const s = on(this, n, t);
1778
- return await this.#i(s), !0;
2560
+ async createTables(n, e) {
2561
+ const s = Hn(this, n, e);
2562
+ return await this.#a(s), !0;
1779
2563
  }
1780
2564
  /**
1781
2565
  * 切换分支
@@ -1783,7 +2567,7 @@ class _n extends He {
1783
2567
  * @returns
1784
2568
  */
1785
2569
  async switchBranch(n) {
1786
- return cn(this, n);
2570
+ return Yn(this, n);
1787
2571
  }
1788
2572
  /**
1789
2573
  * 应用压缩后的变更到本地实体表
@@ -1794,33 +2578,33 @@ class _n extends He {
1794
2578
  * @param _localChanges - (已废弃)不再使用
1795
2579
  * @param disableTriggers - 是否禁用触发器(用于 pull 等操作,避免创建 RxDBChange)
1796
2580
  */
1797
- async mergeChanges(n, t, s = !1) {
1798
- const r = Pe(this, n);
1799
- await ln(this, r, s);
2581
+ async mergeChanges(n, e, s = !1) {
2582
+ const o = _t(this, n);
2583
+ await Qn(this, o, s);
1800
2584
  }
1801
2585
  /**
1802
2586
  * 缓存 RowId 与实体映射
1803
2587
  * @param rowId
1804
2588
  * @param entity
1805
2589
  */
1806
- cacheRowIdEntity(n, t) {
1807
- this.#l(t.constructor).set(n, t), this.#o.set(t, n);
2590
+ cacheRowIdEntity(n, e) {
2591
+ this.#u(e.constructor).set(n, e), this.#o.set(e, n);
1808
2592
  }
1809
2593
  /**
1810
2594
  * 移除缓存实体映射
1811
2595
  * @param entity
1812
2596
  */
1813
2597
  removeCacheEntity(n) {
1814
- const t = this.#o.get(n);
1815
- t !== void 0 && (this.#l(n.constructor).delete(t), this.#o.delete(n));
2598
+ const e = this.#o.get(n);
2599
+ e !== void 0 && (this.#u(n.constructor).delete(e), this.#o.delete(n));
1816
2600
  }
1817
2601
  /**
1818
2602
  * 根据 RowId 获取实体
1819
2603
  * @param rowId
1820
2604
  * @returns
1821
2605
  */
1822
- getEntityByRowId(n, t) {
1823
- return this.#l(t).get(n);
2606
+ getEntityByRowId(n, e) {
2607
+ return this.#u(e).get(n);
1824
2608
  }
1825
2609
  /**
1826
2610
  * 根据实体获取 RowId
@@ -1834,13 +2618,13 @@ class _n extends He {
1834
2618
  * 清空所有缓存
1835
2619
  */
1836
2620
  cleanAllCache() {
1837
- this.#a.clear(), this.#o = /* @__PURE__ */ new WeakMap();
2621
+ this.#i.clear(), this.#o = /* @__PURE__ */ new WeakMap();
1838
2622
  }
1839
2623
  /**
1840
2624
  * 执行 SQL 语句
1841
2625
  */
1842
- query(n, t) {
1843
- return this.#t ? Promise.reject(new R("Adapter is disconnected")) : this.#c.addTask(async () => (await this.rxdb.connect(this.name), (await this.#r()).execute(n, t)));
2626
+ query(n, e) {
2627
+ return this.#t ? Promise.reject(new ee("Adapter is disconnected")) : this.#c.addTask(async () => (await this.rxdb.connect(this.name), (await this.#s()).execute(n, e)));
1844
2628
  }
1845
2629
  /**
1846
2630
  * 执行事务
@@ -1848,41 +2632,41 @@ class _n extends He {
1848
2632
  * @param transactionLog 是否生成事务日志
1849
2633
  * @returns
1850
2634
  */
1851
- async transaction(n, t = !0) {
2635
+ async transaction(n, e = !0) {
1852
2636
  await this.rxdb.connect(this.name);
1853
- const s = await this.#r();
1854
- this.#e = !0, this.rxdb.dispatchEvent(un);
1855
- let r = "", o = "";
1856
- if (t) {
1857
- const i = Ve(), c = await this.rxdb.versionManager.getCurrentBranch();
1858
- if (!c)
2637
+ const s = await this.#s();
2638
+ this.#e = !0, this.rxdb.dispatchEvent(Jn);
2639
+ let o = "", a = "";
2640
+ if (e) {
2641
+ const d = St(), p = await this.rxdb.versionManager.getCurrentBranch();
2642
+ if (!p)
1859
2643
  throw new Error("currentBranch is undefined! Cannot start transaction with logging.");
1860
- r = Te(this, c.id, i), o = Te(this, c.id);
2644
+ o = rt(this, p.id, d), a = rt(this, p.id);
1861
2645
  }
1862
2646
  await s.execute(`
1863
2647
  BEGIN;
1864
2648
  PRAGMA defer_foreign_keys = ON;
1865
- ${r}
2649
+ ${o}
1866
2650
  `);
1867
2651
  try {
1868
- const i = await n(s);
1869
- return await s.execute(`${o}
1870
- COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1871
- } catch (i) {
2652
+ const d = await n(s);
2653
+ return await s.execute(`${a}
2654
+ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2655
+ } catch (d) {
1872
2656
  try {
1873
2657
  await s.execute("ROLLBACK");
1874
2658
  } finally {
1875
- this.#e = !1, this.rxdb.dispatchEvent(dn);
2659
+ this.#e = !1, this.rxdb.dispatchEvent(Gn);
1876
2660
  }
1877
- const c = i?.message || "Transaction Error";
1878
- throw new R(c, { cause: i });
2661
+ const p = d?.message || "Transaction Error";
2662
+ throw new ee(p, { cause: d });
1879
2663
  }
1880
2664
  }
1881
2665
  /**
1882
2666
  * 本地分支仓库
1883
2667
  */
1884
2668
  localRxDBBranch() {
1885
- return this.getRepository(H);
2669
+ return this.getRepository(_e);
1886
2670
  }
1887
2671
  /**
1888
2672
  * 内部查询
@@ -1890,30 +2674,30 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1890
2674
  * @param sql
1891
2675
  * @returns
1892
2676
  */
1893
- internalQuery(n, t) {
1894
- return this.#i(n, t);
2677
+ internalQuery(n, e) {
2678
+ return this.#a(n, e);
1895
2679
  }
1896
2680
  /**
1897
2681
  * 本地变更仓库
1898
2682
  */
1899
2683
  localRxDBChange() {
1900
- return this.getRepository(B);
2684
+ return this.getRepository(pe);
1901
2685
  }
1902
2686
  /**
1903
2687
  * 获取 RxDBChange 表的当前序列值
1904
2688
  * @returns
1905
2689
  */
1906
2690
  async getRxDBChangeSequence() {
1907
- const n = ye(B);
1908
- return (await this.#i("SELECT seq FROM sqlite_sequence WHERE name = ?", [n])).results[0]?.rows?.[0]?.[0] ?? 0;
2691
+ const n = Xe(pe);
2692
+ return (await this.#a("SELECT seq FROM sqlite_sequence WHERE name = ?", [n])).results[0]?.rows?.[0]?.[0] ?? 0;
1909
2693
  }
1910
2694
  /**
1911
2695
  * 设置 RxDBChange 表的序列值
1912
2696
  * @param sequence 序列值
1913
2697
  */
1914
2698
  async setRxDBChangeSequence(n) {
1915
- const t = ye(B);
1916
- await this.#i("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [n, t]);
2699
+ const e = Xe(pe);
2700
+ await this.#a("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [n, e]);
1917
2701
  }
1918
2702
  // ============================================
1919
2703
  // QueryCache 方法
@@ -1933,18 +2717,18 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1933
2717
  * .subscribe(map => console.log(map.get('id1')));
1934
2718
  * ```
1935
2719
  */
1936
- getMetadataByIds(n, t) {
1937
- return ne(() => {
1938
- if (t.length === 0)
1939
- return se(/* @__PURE__ */ new Map());
1940
- const s = t.map(() => "?").join(", "), r = `SELECT id, updatedAt FROM "${n}" WHERE id IN (${s})`;
1941
- return re(this.internalQuery(r, t)).pipe(
1942
- Ze((o) => {
1943
- const i = /* @__PURE__ */ new Map();
1944
- if (o.results?.[0]?.rows)
1945
- for (const c of o.results[0].rows)
1946
- i.set(c[0], c[1]);
1947
- return i;
2720
+ getMetadataByIds(n, e) {
2721
+ return Le(() => {
2722
+ if (e.length === 0)
2723
+ return Me(/* @__PURE__ */ new Map());
2724
+ const s = e.map(() => "?").join(", "), o = `SELECT id, updatedAt FROM "${n}" WHERE id IN (${s})`;
2725
+ return Oe(this.internalQuery(o, e)).pipe(
2726
+ xt((a) => {
2727
+ const d = /* @__PURE__ */ new Map();
2728
+ if (a.results?.[0]?.rows)
2729
+ for (const p of a.results[0].rows)
2730
+ d.set(p[0], p[1]);
2731
+ return d;
1948
2732
  })
1949
2733
  );
1950
2734
  });
@@ -1964,11 +2748,11 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1964
2748
  * .subscribe(() => console.log('upserted'));
1965
2749
  * ```
1966
2750
  */
1967
- upsertMany(n, t) {
1968
- return ne(() => t.length === 0 ? se(void 0) : re(
2751
+ upsertMany(n, e) {
2752
+ return Le(() => e.length === 0 ? Me(void 0) : Oe(
1969
2753
  (async () => {
1970
- const s = Object.keys(t[0]), r = `(${s.map(() => "?").join(", ")})`, o = t.map(() => r).join(", "), i = `INSERT OR REPLACE INTO "${n}" (${s.join(", ")}) VALUES ${o}`, c = t.flatMap((a) => s.map((l) => a[l]));
1971
- await this.internalQuery(i, c);
2754
+ const s = Object.keys(e[0]), o = `(${s.map(() => "?").join(", ")})`, a = e.map(() => o).join(", "), d = `INSERT OR REPLACE INTO "${n}" (${s.join(", ")}) VALUES ${a}`, p = e.flatMap((f) => s.map((b) => f[b]));
2755
+ await this.internalQuery(d, p);
1972
2756
  })()
1973
2757
  ));
1974
2758
  }
@@ -1985,12 +2769,12 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1985
2769
  * .subscribe(() => console.log('deleted'));
1986
2770
  * ```
1987
2771
  */
1988
- deleteByIds(n, t) {
1989
- return ne(() => {
1990
- if (t.length === 0)
1991
- return se(void 0);
1992
- const s = t.map(() => "?").join(", "), r = `DELETE FROM "${n}" WHERE id IN (${s})`;
1993
- return re(this.internalQuery(r, t).then(() => {
2772
+ deleteByIds(n, e) {
2773
+ return Le(() => {
2774
+ if (e.length === 0)
2775
+ return Me(void 0);
2776
+ const s = e.map(() => "?").join(", "), o = `DELETE FROM "${n}" WHERE id IN (${s})`;
2777
+ return Oe(this.internalQuery(o, e).then(() => {
1994
2778
  }));
1995
2779
  });
1996
2780
  }
@@ -2000,13 +2784,13 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
2000
2784
  /**
2001
2785
  * 获取 SQLite 客户端
2002
2786
  */
2003
- #r() {
2004
- return this.#s || (this.#s = Qt(this.rxdb.config.dbName, this.options).then(
2787
+ #s() {
2788
+ return this.#r || (this.#r = Rn(this.rxdb.config.dbName, this.options).then(
2005
2789
  (n) => (this.#n = n, n),
2006
2790
  (n) => {
2007
- throw this.#s = void 0, n;
2791
+ throw this.#r = void 0, n;
2008
2792
  }
2009
- )), this.#s;
2793
+ )), this.#r;
2010
2794
  }
2011
2795
  /**
2012
2796
  * 内部执行 sql
@@ -2014,23 +2798,23 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
2014
2798
  * @param sql
2015
2799
  * @param bindings
2016
2800
  */
2017
- async #i(n, t) {
2018
- return await (await this.#r()).execute(n, t);
2801
+ async #a(n, e) {
2802
+ return await (await this.#s()).execute(n, e);
2019
2803
  }
2020
- #l(n) {
2021
- return this.#a.has(n) === !1 && this.#a.set(n, /* @__PURE__ */ new Map()), this.#a.get(n);
2804
+ #u(n) {
2805
+ return this.#i.has(n) === !1 && this.#i.set(n, /* @__PURE__ */ new Map()), this.#i.get(n);
2022
2806
  }
2023
2807
  }
2024
- const un = new Ue(), dn = new We(), pn = new Ke();
2808
+ const Jn = new At(), Gn = new It(), Xn = new Tt();
2025
2809
  export {
2026
- q as ROWID,
2027
- _n as RxDBAdapterSqlite,
2028
- R as RxDBAdapterSqliteError,
2029
- Wt as SqliteClient,
2030
- je as SqliteRepository,
2031
- vt as WA_SQLITE_VFS_LIST,
2032
- U as buildRuleGroup,
2033
- k as sqliteGetTableName,
2034
- A as sqliteGetTableNameByMetadata,
2035
- Pt as sqliteLoad
2810
+ ie as ROWID,
2811
+ rr as RxDBAdapterSqlite,
2812
+ ee as RxDBAdapterSqliteError,
2813
+ Tn as SqliteClient,
2814
+ ht as SqliteRepository,
2815
+ _n as WA_SQLITE_VFS_LIST,
2816
+ he as buildRuleGroup,
2817
+ le as sqliteGetTableName,
2818
+ X as sqliteGetTableNameByMetadata,
2819
+ wn as sqliteLoad
2036
2820
  };