@aiao/rxdb-adapter-sqlite 0.0.15 → 0.0.16

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,171 @@
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) => ({
1
+ import { getEntityMetadata as T, PropertyType as E, RelationKind as b, isRuleGroup as fe, getEntityStatus as F, 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) => ({
7
7
  sql: "SELECT * FROM sqlite_master WHERE type='table' AND name=? LIMIT 1;",
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:
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:
18
18
  return "TEXT";
19
- case D.number:
19
+ case E.number:
20
20
  return "REAL";
21
- case D.integer:
22
- case D.boolean:
21
+ case E.integer:
22
+ case E.boolean:
23
23
  return "INTEGER";
24
24
  default:
25
25
  return "TEXT";
26
26
  }
27
- }, we = (t, n) => {
28
- if (t === null && n.nullable) return null;
29
- if (t !== void 0)
27
+ }, V = (e, n) => {
28
+ if (e === null && n.nullable) return null;
29
+ if (e !== void 0)
30
30
  switch (n.type) {
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 };
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 };
39
39
  return n.properties.forEach((s) => {
40
- s.name in e && (e[s.name] = we(e[s.name], s));
41
- }), JSON.stringify(e);
40
+ s.name in t && (t[s.name] = V(t[s.name], s));
41
+ }), JSON.stringify(t);
42
42
  }
43
- return JSON.stringify(t);
43
+ return JSON.stringify(e);
44
44
  }
45
- case D.stringArray:
46
- case D.numberArray:
47
- case D.json:
48
- return JSON.stringify(t);
45
+ case E.stringArray:
46
+ case E.numberArray:
47
+ case E.json:
48
+ return JSON.stringify(e);
49
49
  default:
50
- return t;
50
+ return e;
51
51
  }
52
- }, ue = (t, n) => {
53
- if (t === null && n.nullable) return null;
54
- if (t !== void 0)
52
+ }, v = (e, n) => {
53
+ if (e === null && n.nullable) return null;
54
+ if (e !== void 0)
55
55
  switch (n.type) {
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;
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] = v(t[s.name], s));
65
+ }), t;
66
66
  }
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;
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;
72
72
  default:
73
- return t;
73
+ return e;
74
74
  }
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);
75
+ }, P = (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) => P(e.tableName, e.namespace), _e = (e) => A(T(e)), ye = (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);
82
82
  }
83
83
  }
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];
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];
90
90
  continue;
91
91
  }
92
- if (a.indexOf(p) !== -1) {
93
- e[p] = n[p];
92
+ if (o.indexOf(c) !== -1) {
93
+ t[c] = n[c];
94
94
  continue;
95
95
  }
96
- if (o.length === 0 && p.endsWith("Id")) {
97
- e[p] = n[p];
96
+ if (r.length === 0 && c.endsWith("Id")) {
97
+ t[c] = n[c];
98
98
  continue;
99
99
  }
100
- const A = t.propertyMap.get(p);
101
- if (A) {
102
- e[A.columnName] = we(n[p], A);
100
+ const u = e.propertyMap.get(c);
101
+ if (u) {
102
+ t[u.columnName] = V(n[c], u);
103
103
  continue;
104
104
  }
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));
105
+ const d = e.columnNameToPropertyName?.get(c);
106
+ if (d) {
107
+ const f = e.propertyMap.get(d);
108
+ f && (t[c] = V(n[c], f));
109
109
  }
110
110
  }
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]);
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]);
120
120
  }
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]);
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]);
132
132
  }
133
133
  }
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) => {
134
+ return t;
135
+ }, I = (e) => Qe(e) ? `'${e.replaceAll("\0", "").replaceAll("'", "''")}'` : Ge(e) ? "NULL" : e, k = (e, n = []) => {
136
+ let t = 0;
137
+ return e.replace(/\?/g, () => String(I(n[t++])));
138
+ }, oe = (e, n, t) => {
136
139
  const s = {};
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;
140
+ return t.forEach((r, o) => {
141
+ const i = n[o];
142
+ if (i.startsWith("__")) return;
143
+ const c = e.foreignKeyNames || [], l = (e.foreignKeyColumnNames || c).indexOf(i);
144
+ if (l !== -1) {
145
+ s[c[l]] = r;
143
146
  return;
144
147
  }
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}`);
148
+ const u = e.columnNameToPropertyName, p = u?.get(i);
149
+ if (p) {
150
+ const f = e.propertyMap.get(p);
151
+ f ? s[p] = v(r, f) : console.warn(`Property ${p} not found in metadata ${e.name}`);
149
152
  return;
150
153
  }
151
- const I = t.computedPropertyMap?.get(d);
152
- if (I) {
153
- s[d] = ue(o, I);
154
+ const d = e.computedPropertyMap?.get(i);
155
+ if (d) {
156
+ s[i] = v(r, d);
154
157
  return;
155
158
  }
156
- if (!A) {
157
- const M = t.propertyMap.get(d);
158
- if (M) {
159
- s[d] = ue(o, M);
159
+ if (!u) {
160
+ const f = e.propertyMap.get(i);
161
+ if (f) {
162
+ s[i] = v(r, f);
160
163
  return;
161
164
  }
162
165
  }
163
- console.warn(`Column ${d}=${o} not found in metadata ${t.name}`);
166
+ console.warn(`Column ${i}=${r} not found in metadata ${e.name}`);
164
167
  }), s;
165
- }, Q = "_", Ft = {
168
+ }, w = "_", it = {
166
169
  "=": "=",
167
170
  "!=": "!=",
168
171
  ">": ">",
@@ -179,514 +182,514 @@ const ke = (t, n) => {
179
182
  notStartsWith: "NOT LIKE",
180
183
  endsWith: "LIKE",
181
184
  notEndsWith: "NOT LIKE"
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)
185
+ }, ae = (e, n) => {
186
+ if (n && e.includes(".")) {
187
+ const t = e.split("."), s = n.propertyMap.get(t[0]);
188
+ if (!s) return e;
189
+ if (s.type === E.keyValue)
187
190
  return s.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;
191
+ for (let o = 0; o < t.length - 1; o++) {
192
+ const i = n.propertyMap.get(t[o]);
193
+ if (!i) return e;
194
+ if (i.type === E.keyValue)
195
+ return i.columnName;
193
196
  }
194
- const o = n.propertyMap.get(e[e.length - 1]);
195
- return o ? o.columnName : t;
197
+ const r = n.propertyMap.get(t[t.length - 1]);
198
+ return r ? r.columnName : e;
196
199
  }
197
200
  if (n) {
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];
201
+ const t = n.propertyMap.get(e);
202
+ if (t)
203
+ return t.columnName;
204
+ const s = n.foreignKeyNames || [], r = n.foreignKeyColumnNames || s, o = s.indexOf(e);
205
+ if (o !== -1)
206
+ return r[o];
204
207
  }
205
- return t;
206
- }, Ze = (t, n, e) => {
208
+ return e;
209
+ }, ge = (e, n, t) => {
207
210
  if (n) return n;
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;
211
+ if (!e.includes(".")) {
212
+ const c = ae(e, t);
213
+ return `${w}."${c}"`;
214
+ }
215
+ const s = e.lastIndexOf("."), r = e.slice(0, s), o = e.slice(s + 1), i = ae(o, t);
216
+ return `"${r}"."${i}"`;
217
+ }, Re = (e) => {
218
+ const { operator: n, value: t } = e;
216
219
  switch (n) {
217
220
  case "in":
218
221
  case "notIn":
219
- return Kt(e);
222
+ return lt(t);
220
223
  case "between":
221
224
  case "notBetween":
222
- return Ht(e);
225
+ return ut(t);
223
226
  case "contains":
224
227
  case "notContains":
225
- return te(`%${e}%`);
228
+ return I(`%${t}%`);
226
229
  case "startsWith":
227
230
  case "notStartsWith":
228
- return te(`${e}%`);
231
+ return I(`${t}%`);
229
232
  case "endsWith":
230
233
  case "notEndsWith":
231
- return te(`%${e}`);
234
+ return I(`%${t}`);
232
235
  default:
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);
236
+ return dt(t);
237
+ }
238
+ }, 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) => {
239
+ if (!Array.isArray(e) || e.length < 2) return "";
240
+ const [n, t] = e;
241
+ if (n == null || t == null) return "";
242
+ const s = n instanceof Date ? n.toISOString() : n, r = t instanceof Date ? t.toISOString() : t;
243
+ return `${I(s)} and ${I(r)}`;
244
+ }, 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) => {
245
+ const s = e.propertyMap.get(n);
246
+ if (!s || s.type !== E.keyValue || typeof t.value != "object" || Array.isArray(t.value)) return null;
247
+ const r = Object.entries(t.value).filter(([, a]) => a != null);
248
+ if (!r.length) return "";
249
+ const o = t.operator === "notContains" ? "NOT LIKE" : "LIKE", i = t.operator === "contains" ? " OR " : " AND ";
250
+ return `(${r.map(([a, l]) => {
251
+ const u = l instanceof Date ? l.toISOString() : typeof l == "string" ? l : String(l), p = a.replace(/'/g, "''");
252
+ return `json_extract(${w}."${s.columnName}", '$.${p}') ${o} ${I(`%${u}%`)}`;
253
+ }).join(i)})`;
254
+ }, ft = (e, n, t) => {
255
+ const s = e.propertyMap.get(n);
256
+ if (!s || s.type !== E.stringArray && s.type !== E.numberArray) return null;
257
+ const r = Re(t), o = `EXISTS (SELECT 1 FROM json_each(${w}."${s.columnName}") WHERE json_each.value IN ${r})`;
258
+ return t.operator === "notIn" ? `NOT ${o}` : o;
259
+ }, ht = (e, n, t, s, r) => {
260
+ if (t && s && r && (e.operator === "exists" || e.operator === "notExists")) {
261
+ const d = gt(e, t, s, (f, h) => {
262
+ const _ = /* @__PURE__ */ new Map();
263
+ return h.propertyMap.forEach((m, y) => {
264
+ _.set(y, `"child"."${m.columnName}"`);
265
+ }), r(f, _, h, s);
263
266
  });
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)
267
+ if (d !== null) return d;
268
+ }
269
+ if (e.operator === "null" || e.operator === "notNull") {
270
+ const p = String(e.field), d = n.get(p), f = ge(p, d, t);
271
+ return e.operator === "null" ? `${f} IS NULL` : `${f} IS NOT NULL`;
272
+ }
273
+ const o = e.value === null, i = o ? "" : ct(e.operator).toLowerCase(), c = o ? e.operator === "=" ? "IS NULL" : e.operator === "!=" ? "IS NOT NULL" : "" : Re(e);
274
+ if (!c && ["in", "notIn", "between", "notBetween"].includes(e.operator)) return "";
275
+ const a = String(e.field), l = n.get(a);
276
+ if (t && !a.includes(".") && (e.operator === "contains" || e.operator === "notContains")) {
277
+ const p = pt(t, a, e);
278
+ if (p !== null) return p;
279
+ }
280
+ if (t && !a.includes(".") && (e.operator === "in" || e.operator === "notIn")) {
281
+ const p = ft(t, a, e);
282
+ if (p !== null) return p;
283
+ }
284
+ return `${ge(a, l, t)} ${i} ${c}`.replace(/\s+/g, " ").trim();
285
+ }, ue = (e) => e === w ? e : `"${e}"`, mt = (e, n, t) => {
286
+ if (e.kind !== b.ONE_TO_MANY)
284
287
  throw new Error("_build_one_to_many_exists requires ONE_TO_MANY relation");
285
- const s = le(n.tableName, n.namespace), o = "child", a = n.relations.find((f) => f.name === t.mappedProperty);
286
- if (!a)
288
+ const s = P(n.tableName, n.namespace), r = "child", o = n.relations.find((a) => a.name === e.mappedProperty);
289
+ if (!o)
287
290
  throw new Error(
288
- `Cannot find mappedProperty relation "${t.mappedProperty}" in entity "${n.name}"`
291
+ `Cannot find mappedProperty relation "${e.mappedProperty}" in entity "${n.name}"`
289
292
  );
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;
293
+ const i = o.columnName;
294
+ let c = `EXISTS (SELECT 1 FROM "${s}" "${r}"`;
295
+ return c += ` WHERE "${r}"."${i}" = ${w}."id"`, t && (c += ` AND ${t}`), c += ")", c;
296
+ }, Et = (e, n, t) => {
297
+ const s = e.columnName;
298
+ if (!t)
299
+ return `${w}."${s}" IS NOT NULL`;
300
+ const r = P(n.tableName, n.namespace), o = "child";
301
+ let i = `EXISTS (SELECT 1 FROM "${r}" "${o}"`;
302
+ return i += ` WHERE ${w}."${s}" = "${o}"."id"`, i += ` AND ${t}`, i += ")", i;
303
+ }, _t = (e, n, t, s, r) => {
304
+ const o = s.rxdb.schemaManager.findMappedRelation(e, n);
305
+ if (o?.relation) {
306
+ const i = P(t.tableName, t.namespace), c = "child", a = o.relation.columnName;
307
+ let l = `EXISTS (SELECT 1 FROM "${i}" "${c}"`;
308
+ return l += ` WHERE "${c}"."${a}" = ${w}."id"`, r && (l += ` AND ${r}`), l += ")", l;
306
309
  } else {
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)
310
+ const i = n.columnName;
311
+ if (!r)
312
+ return `${w}."${i}" IS NOT NULL`;
313
+ const c = P(t.tableName, t.namespace), a = "child";
314
+ let l = `EXISTS (SELECT 1 FROM "${c}" "${a}"`;
315
+ return l += ` WHERE ${w}."${i}" = "${a}"."id"`, l += ` AND ${r}`, l += ")", l;
316
+ }
317
+ }, yt = (e, n, t, s) => {
318
+ const r = P(t.tableName, t.namespace), o = "child", i = n.junctionEntityType;
319
+ if (!i)
317
320
  throw new Error(`MANY_TO_MANY relation "${n.name}" missing junctionEntityType`);
318
- const p = V(d);
319
- if (!p)
321
+ const c = T(i);
322
+ if (!c)
320
323
  throw new Error("Cannot find metadata for junction entity");
321
- const f = le(p.tableName, p.namespace), b = "junction", A = p.relations.find(
322
- (v) => v.mappedEntity === t.name && v.mappedNamespace === t.namespace
324
+ const a = P(c.tableName, c.namespace), l = "junction", u = c.relations.find(
325
+ (_) => _.mappedEntity === e.name && _.mappedNamespace === e.namespace
323
326
  );
324
- if (!A)
327
+ if (!u)
325
328
  throw new Error(
326
- `Cannot find relation in junction entity ${p.name} pointing to ${t.name}`
329
+ `Cannot find relation in junction entity ${c.name} pointing to ${e.name}`
327
330
  );
328
- const T = p.relations.find(
329
- (v) => v.mappedEntity === e.name && v.mappedNamespace === e.namespace
331
+ const p = c.relations.find(
332
+ (_) => _.mappedEntity === t.name && _.mappedNamespace === t.namespace
330
333
  );
331
- if (!T)
334
+ if (!p)
332
335
  throw new Error(
333
- `Cannot find relation in junction entity ${p.name} pointing to ${e.name}`
336
+ `Cannot find relation in junction entity ${c.name} pointing to ${t.name}`
334
337
  );
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")
338
+ const d = u.columnName, f = p.columnName;
339
+ let h = `EXISTS (SELECT 1 FROM "${r}" "${o}"`;
340
+ return h += ` INNER JOIN "${a}" "${l}"`, h += ` ON "${l}"."${f}" = "${o}"."id"`, h += ` WHERE "${l}"."${d}" = ${w}."id"`, s && (h += ` AND ${s}`), h += ")", h;
341
+ }, gt = (e, n, t, s) => {
342
+ if (e.operator !== "exists" && e.operator !== "notExists")
340
343
  return null;
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
344
+ const r = n.relationMap.get(e.field);
345
+ if (!r) return null;
346
+ const o = t.rxdb.schemaManager.getEntityMetadata(
347
+ r.mappedEntity,
348
+ r.mappedNamespace
346
349
  );
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);
350
+ if (!o)
351
+ throw new Error(`Cannot find metadata for entity: ${r.mappedNamespace}.${r.mappedEntity}`);
352
+ let i;
353
+ e.where && s && (i = s(e.where, o));
354
+ let c;
355
+ switch (r.kind) {
356
+ case b.ONE_TO_MANY:
357
+ c = mt(r, o, i);
355
358
  break;
356
- case z.MANY_TO_ONE:
357
- p = Xt(o, a, d);
359
+ case b.MANY_TO_ONE:
360
+ c = Et(r, o, i);
358
361
  break;
359
- case z.ONE_TO_ONE:
360
- p = zt(n, o, a, e, d);
362
+ case b.ONE_TO_ONE:
363
+ c = _t(n, r, o, t, i);
361
364
  break;
362
- case z.MANY_TO_MANY:
363
- p = Zt(n, o, a, d);
365
+ case b.MANY_TO_MANY:
366
+ c = yt(n, r, o, i);
364
367
  break;
365
368
  }
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))
369
+ return e.operator === "notExists" ? `NOT ${c}` : c;
370
+ }, G = (e, n) => {
371
+ if (e.relationAliasMap.has(n))
372
+ return e.relationAliasMap.get(n);
373
+ const t = n.includes("_") ? n : n.split("_")[0], s = Oe(e, t);
374
+ return e.relationAliasMap.set(n, s), s;
375
+ }, Nt = (e, n, t, s) => {
376
+ const r = t.slice(0, s);
377
+ let o = n;
378
+ const i = [];
379
+ for (const c of r) {
380
+ if (!o?.relationMap.has(c))
378
381
  return { relPairs: [] };
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;
382
+ const a = o.relationMap.get(c);
383
+ i.push({ metadata: o, relation: a }), o = e.rxdb.schemaManager.getEntityMetadata(a.mappedEntity, a.mappedNamespace);
384
+ }
385
+ return { metaWalker: o, relPairs: i };
386
+ }, $t = (e, n, t, s, r) => {
387
+ for (let o = r.length - 1; o > 0; o--) {
388
+ const i = r.slice(o);
389
+ if (i.length === 0) continue;
390
+ const { metaWalker: c, relPairs: a } = Nt(e, t, r, o);
391
+ if (!c || a.length === 0) continue;
392
+ const l = i[0], u = i.slice(1).join("."), p = c.propertyMap.get(l);
393
+ if (p && p.type === E.keyValue) {
394
+ const d = r.slice(0, o).join(".");
395
+ Ie(e, n, a, d);
396
+ const f = a[a.length - 1].relation, h = Q(a, d, f), _ = G(n, h), m = u ? `$.${u}` : "$";
397
+ return n.fieldAliasMap.set(s, `json_extract("${_}"."${p.columnName}", '${m}')`), !0;
395
398
  }
396
399
  }
397
400
  return !1;
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);
401
+ }, Ie = (e, n, t, s) => {
402
+ t.forEach(({ metadata: r, relation: o }, i) => {
403
+ let c = e.rxdb.schemaManager.findMappedRelation(r, o);
404
+ if (!c)
405
+ if (o.kind === b.ONE_TO_MANY || o.kind === b.MANY_TO_MANY) {
406
+ const p = r.relationMap.get(o.mappedProperty);
407
+ p && (c = { metadata: r, relation: p });
408
+ } else (o.kind === b.MANY_TO_ONE || o.kind === b.ONE_TO_ONE) && (c = { metadata: r, relation: o });
409
+ if (!c) throw new R("mappedRelation not found");
410
+ const a = Q(t, s, o), l = G(n, a);
411
+ let u = w;
412
+ if (i > 0) {
413
+ const p = t[i - 1], d = Q(t, s, p.relation);
414
+ u = G(n, d);
412
415
  }
413
- switch (a.kind) {
414
- case z.ONE_TO_MANY:
415
- rn(
416
+ switch (o.kind) {
417
+ case b.ONE_TO_MANY:
418
+ Tt(
416
419
  n,
417
- p,
418
- b,
419
- A
420
+ c,
421
+ l,
422
+ u
420
423
  );
421
424
  break;
422
- case z.ONE_TO_ONE:
423
- case z.MANY_TO_ONE:
424
- sn(
425
+ case b.ONE_TO_ONE:
426
+ case b.MANY_TO_ONE:
427
+ wt(
425
428
  n,
426
- p,
427
- b,
428
- A,
429
- a
429
+ c,
430
+ l,
431
+ u,
432
+ o
430
433
  );
431
434
  break;
432
- case z.MANY_TO_MANY:
433
- on(
434
- t,
435
+ case b.MANY_TO_MANY:
436
+ At(
437
+ e,
435
438
  n,
436
- p,
437
- b,
438
- A,
439
- a
439
+ c,
440
+ l,
441
+ u,
442
+ o
440
443
  );
441
444
  break;
442
445
  }
443
446
  });
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
447
+ }, Tt = (e, n, t, s) => {
448
+ const r = J(e, n.metadata), o = `"${t}".${n.relation.columnName} = ${ue(s)}.id`;
449
+ r.find((c) => c.joinTableName === t && c.on === o) || r.push({
450
+ joinTableName: t,
451
+ on: o
449
452
  });
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
453
+ }, wt = (e, n, t, s, r) => {
454
+ const o = J(e, n.metadata), i = `"${t}".id = ${ue(s)}.${r.columnName}`;
455
+ o.find((a) => a.joinTableName === t && a.on === i) || o.push({
456
+ joinTableName: t,
457
+ on: i
455
458
  });
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
459
+ }, At = (e, n, t, s, r, o) => {
460
+ const i = T(o.junctionEntityType), c = J(n, i), a = Oe(n, `${o.name}_m_n`), l = `"${a}".${t.relation.columnName} = ${ue(r)}.id`;
461
+ c.find(
462
+ (h) => h.joinTableName === a && h.on === l
463
+ ) || c.push({
464
+ joinTableName: a,
465
+ on: l
463
466
  });
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({
467
+ const p = J(n, t.metadata), d = `"${s}".id = "${a}".${o.columnName}`;
468
+ p.find((h) => h.joinTableName === s && h.on === d) || p.push({
466
469
  joinTableName: s,
467
- on: I
470
+ on: d
468
471
  });
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}`;
472
+ }, J = (e, n) => (e.joinMap.has(n) || e.joinMap.set(n, []), e.joinMap.get(n)), Oe = (e, n) => {
473
+ let t = n, s = 1;
474
+ for (; e.usedAliases.has(t); )
475
+ t = `${n}_${s}`, s++;
476
+ return e.usedAliases.add(t), t;
477
+ }, St = (e, n) => {
478
+ if (e?.length)
479
+ return e.map((t) => {
480
+ const s = ae(t.field, n);
481
+ return `${w}."${s}" ${t.sort}`;
479
482
  }).join(", ");
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)
483
+ }, U = (e, n = /* @__PURE__ */ new Map(), t, s) => {
484
+ if (!e?.rules) return "";
485
+ const r = e.rules.map(
486
+ (o) => fe(o) ? U(o, n, t, s) : ht(o, n, t, s, U)
484
487
  ).filter(Boolean);
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) => {
488
+ return r.length ? r.length === 1 ? r[0] : `(${r.join(fe(e) ? ` ${e.combinator} ` : " ")})` : "";
489
+ }, Me = (e) => {
490
+ const { tableName: n, where: t, limit: s, offset: r, orderBy: o, join: i, hasJoin: c, metadata: a } = e;
491
+ let l = `${w}.rowid as ${q}, ${w}.*`;
492
+ if (a.features?.tree?.hasChildren && a.features?.tree?.type === "adjacency-list") {
493
+ const d = a.relationMap.get("parent").columnName;
494
+ l += `, EXISTS(SELECT 1 FROM "${n}" __sub WHERE __sub."${d}" = ${w}."id") AS "hasChildren"`;
495
+ }
496
+ const u = [`SELECT ${c ? "DISTINCT " : ""}${l} FROM "${n}" ${w}`];
497
+ return i && u.push(i), t && u.push(` WHERE ${t}`), o && u.push(` ORDER BY ${o}`), s && u.push(` LIMIT ${s}`), r && u.push(` OFFSET ${r}`), u.join("") + ";";
498
+ }, Ce = (e, n, t) => {
496
499
  const s = {
497
500
  joinMap: /* @__PURE__ */ new Map(),
498
501
  usedAliases: /* @__PURE__ */ new Set(),
499
502
  fieldAliasMap: /* @__PURE__ */ new Map(),
500
503
  relationAliasMap: /* @__PURE__ */ new Map()
501
504
  };
502
- Ct(e, (a, d, p) => {
503
- const f = d;
504
- a !== "field" || !f.includes(".") || un(t, s, n, f, p);
505
+ Je(t, (o, i, c) => {
506
+ const a = i;
507
+ o !== "field" || !a.includes(".") || Rt(e, s, n, a, c);
505
508
  });
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) => {
509
+ const r = [];
510
+ for (const [o, i] of s.joinMap.entries()) {
511
+ const c = A(o);
512
+ for (const a of i)
513
+ r.push(` LEFT JOIN "${c}" "${a.joinTableName}" ON ${a.on}`);
514
+ }
515
+ return { joinSQL: r.join(""), fieldAliasMap: s.fieldAliasMap };
516
+ }, bt = (e, n, t, s) => {
514
517
  if (s.length <= 1) return !1;
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;
518
+ const [r, ...o] = s, i = n.propertyMap.get(r);
519
+ if (i && i.type === E.keyValue && o.length > 0) {
520
+ const c = o.join(".");
521
+ return e.fieldAliasMap.set(t, `json_extract(${w}."${i.columnName}", '$.${c}')`), !0;
519
522
  }
520
523
  return !1;
521
- }, un = (t, n, e, s, o) => {
522
- const a = s.split(".");
524
+ }, Rt = (e, n, t, s, r) => {
525
+ const o = s.split(".");
523
526
  try {
524
- const d = t.rxdb.schemaManager.getFieldRelations(e, s);
525
- if (d.isForeignKey) {
526
- o.field = d.propertyName;
527
+ const i = e.rxdb.schemaManager.getFieldRelations(t, s);
528
+ if (i.isForeignKey) {
529
+ r.field = i.propertyName;
527
530
  return;
528
531
  }
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}"`);
532
+ const c = s.replace(`.${i.propertyName}`, "");
533
+ Ie(e, n, i.relations, c);
534
+ const a = i.relations[i.relations.length - 1], l = Q(i.relations, c, a.relation), u = G(n, l);
535
+ n.fieldAliasMap.set(s, `"${u}"."${i.property.columnName}"`);
533
536
  return;
534
537
  } catch {
535
538
  }
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
+ bt(n, t, s, o) || $t(e, n, t, s, o);
540
+ }, It = (e, n) => {
541
+ const t = A(e), s = [n.id];
539
542
  return {
540
- sql: `DELETE FROM "${e}" WHERE id = ?;`,
543
+ sql: `DELETE FROM "${t}" WHERE id = ?;`,
541
544
  params: s
542
545
  };
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
546
+ }, Le = (e, n, t) => {
547
+ const s = A(e), r = be(e, n);
548
+ t?.userId && (e.propertyMap.has("createdBy") && (r.createdBy = t.userId), e.propertyMap.has("updatedBy") && (r.updatedBy = t.userId));
549
+ const o = /* @__PURE__ */ new Date();
550
+ 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);
551
+ const i = le(e, r), c = Object.keys(i), a = Array(c.length).fill("?").join(","), l = Object.values(i);
552
+ let p = `${t?.useReplace ? "INSERT OR REPLACE" : "INSERT"} INTO "${s}" (${c.join(",")}) VALUES (${a})`;
553
+ return t?.returning !== !1 ? p += ` RETURNING rowid as ${q}, *;` : p += ";", {
554
+ sql: p,
555
+ params: l
553
556
  };
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
557
+ }, de = (e, n, t, s) => {
558
+ const r = at(e, t);
559
+ e.propertyMap.has("updatedAt") && (r.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && e.propertyMap.has("updatedBy") && (r.updatedBy = s.userId);
560
+ const o = le(e, r), i = Object.keys(o).map((d) => `${d} = ?`).join(","), c = [...Object.values(o)], a = A(e), l = Array.isArray(n), u = l ? n : [n];
561
+ let p = `UPDATE "${a}" SET ${i} WHERE id `;
562
+ return l ? p += `in (${u.map((d) => I(d.id)).join(",")})` : (c.push(n.id), p += "= ?"), s?.returning !== !1 ? p += ` RETURNING rowid as ${q}, *;` : p += ";", {
563
+ sql: p,
564
+ params: c
562
565
  };
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),
566
+ }, Ot = (e, n, t) => {
567
+ if (t.groupBy)
568
+ throw new R("groupBy not supported yet");
569
+ 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}`];
570
+ return s && c.push(s), i && c.push(` WHERE ${i}`), { sql: c.join("") };
571
+ }, ie = (e, n, t) => {
572
+ const { joinSQL: s, fieldAliasMap: r } = Ce(e, n, t.where);
573
+ return { sql: Me({
574
+ tableName: A(n),
575
+ where: U(t.where, r, n, e),
576
+ orderBy: St(t.orderBy, n),
574
577
  join: s,
575
578
  hasJoin: !!s,
576
579
  metadata: n,
577
- limit: e.limit,
578
- offset: e.offset
580
+ limit: t.limit,
581
+ offset: t.offset
579
582
  }) };
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
583
+ }, Mt = (e, n) => {
584
+ const t = n.map(() => "?").join(",");
585
+ return { sql: Me({
586
+ tableName: A(e),
587
+ where: `${q} IN (${t})`,
588
+ metadata: e
586
589
  }), params: n };
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[$]);
590
+ }, X = (e, n, t, s = !1, r = !1) => {
591
+ const o = [], i = T(n), c = e.rxdb.entityManager;
592
+ return t.results.forEach(({ columns: a, rows: l }) => {
593
+ const u = a.findIndex((d) => d === "id"), p = a.findIndex((d) => d === q);
594
+ l.forEach((d) => {
595
+ const f = d[u];
596
+ let h;
597
+ if (e.rxdb.entityManager.hasEntityRef(n, f)) {
598
+ h = c.getEntityRef(n, f);
599
+ const y = oe(i, a, d);
600
+ if (i.computedPropertyMap.forEach((N, $) => {
601
+ $ in y && (h[$] = y[$]);
599
602
  }), s) {
600
- const S = ae(E);
601
- S.origin = { ...N }, Object.assign(E, N);
603
+ const N = F(h);
604
+ N.origin = { ...y }, Object.assign(h, y);
602
605
  }
603
606
  } else {
604
- if (o)
607
+ if (r)
605
608
  return;
606
609
  {
607
- const N = je(d, f, I);
608
- E = p.createEntityRef(n, N);
610
+ const y = oe(i, a, d);
611
+ h = c.createEntityRef(n, y);
609
612
  }
610
613
  }
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);
614
+ o.push(h);
615
+ const m = F(h);
616
+ if (m.local = !0, m.modified = !1, p !== -1) {
617
+ const y = BigInt(d[p]);
618
+ e.cacheRowIdEntity(y, h);
616
619
  }
617
620
  });
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;
621
+ }), o;
622
+ }, Ct = (e, n, t) => {
623
+ t.forEach((s) => {
624
+ if (e.rxdb.entityManager.hasEntityRef(n, s)) {
625
+ const r = e.rxdb.entityManager.getEntityRef(n, s), o = F(r);
626
+ o.local = !1, o.removed = !0, o.modified = !1;
624
627
  }
625
628
  });
626
629
  };
627
- class hn extends Nt {
628
- constructor(n, e) {
629
- super(n.rxdb, e), this.adapter = n, this.metadata = V(e);
630
+ class Lt extends Be {
631
+ constructor(n, t) {
632
+ super(n.rxdb, t), this.adapter = n, this.metadata = T(t);
630
633
  }
631
634
  metadata;
632
635
  async findByRowIds(n) {
633
- const { sql: e, params: s } = dn(this.metadata, n), o = await this.adapter.query(e, s);
634
- return this.addQueryCache(o);
636
+ const { sql: t, params: s } = Mt(this.metadata, n), r = await this.adapter.query(t, s);
637
+ return this.addQueryCache(r);
635
638
  }
636
639
  /**
637
640
  * 添加缓存
638
641
  * @param sqliteSuccessResult
639
642
  * @param forcedUpdate 强制刷新,在数据有的情况下也会更新数据,在修改数据的情况下需要
640
643
  */
641
- addQueryCache(n, e = !1) {
642
- return Ie(this.adapter, this.EntityType, n, e);
644
+ addQueryCache(n, t = !1) {
645
+ return X(this.adapter, this.EntityType, n, t);
643
646
  }
644
647
  }
645
- class ht extends hn {
648
+ class je extends Lt {
646
649
  async get(n) {
647
- const e = {
650
+ const t = {
648
651
  where: {
649
652
  combinator: "and",
650
653
  rules: [{ field: "id", operator: "=", value: n }]
651
654
  }
652
- }, s = await this.findOne(e);
653
- if (!s) throw new ee(`Entity (${n}) not found`);
655
+ }, s = await this.findOne(t);
656
+ if (!s) throw new R(`Entity (${n}) not found`);
654
657
  return s;
655
658
  }
656
659
  async findOne(n) {
657
660
  return (await this.find({ ...n, limit: 1, offset: 0 }))[0];
658
661
  }
659
662
  async find(n) {
660
- const { sql: e, params: s } = De(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
661
- return this.addQueryCache(o);
663
+ const { sql: t, params: s } = ie(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
664
+ return this.addQueryCache(r);
662
665
  }
663
666
  async count(n) {
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];
667
+ const { sql: t, params: s } = Ot(this.adapter, this.metadata, n);
668
+ return (await this.adapter.query(t, s)).results[0].rows[0][0];
666
669
  }
667
670
  async create(n) {
668
- const { sql: e, params: s } = pt(this.metadata, n, this.rxdb.context), o = await this.adapter.query(e, s);
669
- return this.addQueryCache(o, !0), n;
671
+ const { sql: t, params: s } = Le(this.metadata, n, this.rxdb.context), r = await this.adapter.query(t, s);
672
+ return this.addQueryCache(r, !0), n;
670
673
  }
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
+ async update(n, t) {
675
+ const { sql: s, params: r } = de(this.metadata, n, t, this.rxdb.context), o = await this.adapter.query(s, r);
676
+ return this.addQueryCache(o, !0), n;
674
677
  }
675
678
  async remove(n) {
676
- const e = ae(n), s = () => {
677
- e.origin = structuredClone({ ...n }), e.modified = !1, e.removed = !0;
679
+ const t = F(n), s = () => {
680
+ t.origin = structuredClone({ ...n }), t.modified = !1, t.removed = !0;
678
681
  };
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
+ if (t.local === !0) {
683
+ const { sql: o, params: i } = It(this.metadata, n);
684
+ return await this.adapter.query(o, i), s(), n;
682
685
  }
683
- const o = V(n);
684
- throw new ee(`Remove Error${o.name}(${n.id}) not saved local.`);
686
+ const r = T(n);
687
+ throw new R(`Remove Error${r.name}(${n.id}) not saved local.`);
685
688
  }
686
689
  }
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
+ var D = /* @__PURE__ */ ((e) => (e[e.SQLITE_DELETE = 9] = "SQLITE_DELETE", e[e.SQLITE_INSERT = 18] = "SQLITE_INSERT", e[e.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", e))(D || {});
691
+ const jt = (e) => {
692
+ switch (e) {
690
693
  case 18:
691
694
  return "INSERT";
692
695
  case 9:
@@ -694,10 +697,10 @@ const mn = (t) => {
694
697
  case 23:
695
698
  return "UPDATE";
696
699
  }
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 = [
700
+ }, 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 = [
698
701
  {
699
702
  name: "MemoryVFS",
700
- vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((t) => t.MemoryVFS),
703
+ vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((e) => e.MemoryVFS),
701
704
  sync: !0,
702
705
  async: !0,
703
706
  worker: !0,
@@ -707,7 +710,7 @@ const mn = (t) => {
707
710
  },
708
711
  {
709
712
  name: "MemoryAsyncVFS",
710
- vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((t) => t.MemoryAsyncVFS),
713
+ vfsModule: () => import("wa-sqlite/src/examples/MemoryAsyncVFS.js").then((e) => e.MemoryAsyncVFS),
711
714
  sync: !1,
712
715
  async: !0,
713
716
  worker: !0,
@@ -717,7 +720,7 @@ const mn = (t) => {
717
720
  },
718
721
  {
719
722
  name: "IDBBatchAtomicVFS",
720
- vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((t) => t.IDBBatchAtomicVFS),
723
+ vfsModule: () => import("wa-sqlite/src/examples/IDBBatchAtomicVFS.js").then((e) => e.IDBBatchAtomicVFS),
721
724
  vfsOptions: { lockPolicy: "shared+hint" },
722
725
  sync: !1,
723
726
  async: !0,
@@ -728,7 +731,7 @@ const mn = (t) => {
728
731
  },
729
732
  {
730
733
  name: "OPFSAdaptiveVFS",
731
- vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((t) => t.OPFSAdaptiveVFS),
734
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSAdaptiveVFS.js").then((e) => e.OPFSAdaptiveVFS),
732
735
  vfsOptions: { lockPolicy: "shared+hint" },
733
736
  sync: !1,
734
737
  async: !0,
@@ -739,7 +742,7 @@ const mn = (t) => {
739
742
  },
740
743
  {
741
744
  name: "AccessHandlePoolVFS",
742
- vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((t) => t.AccessHandlePoolVFS),
745
+ vfsModule: () => import("wa-sqlite/src/examples/AccessHandlePoolVFS.js").then((e) => e.AccessHandlePoolVFS),
743
746
  sync: !0,
744
747
  async: !0,
745
748
  worker: !0,
@@ -749,7 +752,7 @@ const mn = (t) => {
749
752
  },
750
753
  {
751
754
  name: "OPFSAnyContextVFS",
752
- vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((t) => t.OPFSAnyContextVFS),
755
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSAnyContextVFS.js").then((e) => e.OPFSAnyContextVFS),
753
756
  vfsOptions: { lockPolicy: "shared+hint" },
754
757
  sync: !1,
755
758
  async: !0,
@@ -760,7 +763,7 @@ const mn = (t) => {
760
763
  },
761
764
  {
762
765
  name: "OPFSCoopSyncVFS",
763
- vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((t) => t.OPFSCoopSyncVFS),
766
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSCoopSyncVFS.js").then((e) => e.OPFSCoopSyncVFS),
764
767
  sync: !0,
765
768
  async: !0,
766
769
  worker: !0,
@@ -770,7 +773,7 @@ const mn = (t) => {
770
773
  },
771
774
  {
772
775
  name: "OPFSPermutedVFS",
773
- vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((t) => t.OPFSPermutedVFS),
776
+ vfsModule: () => import("wa-sqlite/src/examples/OPFSPermutedVFS.js").then((e) => e.OPFSPermutedVFS),
774
777
  sync: !1,
775
778
  async: !0,
776
779
  worker: !0,
@@ -778,80 +781,80 @@ const mn = (t) => {
778
781
  jsContext: !1,
779
782
  multipleConnections: !0
780
783
  }
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
+ ], xe = (e) => {
785
+ const n = vt.find((o) => o.name === e.vfs), { vfs: t, async: s, worker: r } = e;
786
+ if (!n) throw new R(`vfs ${t} not found`);
784
787
  if (s !== void 0) {
785
788
  if (s && !n.async)
786
- throw new ee(`vfs ${e} not support async: true`);
789
+ throw new R(`vfs ${t} not support async: true`);
787
790
  if (!s && !n.sync)
788
- throw new ee(`vfs ${e} not support async: false`);
791
+ throw new R(`vfs ${t} not support async: false`);
789
792
  }
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`);
793
+ if (r && !n.worker) throw new R(`vfs ${t} not support worker`);
794
+ if (!r && !n.jsContext) throw new R(`vfs ${t} only support worker`);
792
795
  return n;
793
- }, wn = async (t) => {
794
- const n = mt(t), e = t.async ?? !0;
796
+ }, Pt = async (e) => {
797
+ const n = xe(e), t = e.async ?? !0;
795
798
  let s;
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;
799
+ t ? s = qt : s = Dt;
800
+ const [r, o] = await Promise.all([s(), n.vfsModule()]), i = {};
801
+ e.locateFile ? i.locateFile = e.locateFile : e.wasmPath && (i.locateFile = () => e.wasmPath);
802
+ const c = await r(i), a = et(c), l = await o.create(e.vfs, c, n.vfsOptions);
803
+ return a.vfs_register(l, !0), a;
801
804
  };
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
805
+ async function kt(e, n, t, s) {
806
+ const r = performance.now(), o = [];
807
+ let i = 0, c = s;
808
+ const a = {
809
+ sql: t,
810
+ results: o
808
811
  };
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);
812
+ for await (const l of e.statements(n, t)) {
813
+ c && (e.reset(l), e.bind_collection(l, c), c = void 0);
814
+ const u = [];
815
+ for (; await e.step(l) === tt; ) {
816
+ const d = e.row(l);
817
+ u.push(d);
815
818
  }
816
- const T = t.column_names(b);
817
- T.length && a.push({ columns: T, rows: A }), d += t.changes(n);
819
+ const p = e.column_names(l);
820
+ p.length && o.push({ columns: p, rows: u }), i += e.changes(n);
818
821
  }
819
822
  return {
820
- ...f,
821
- rowsAffected: d,
822
- elapsed: performance.now() - o
823
+ ...a,
824
+ rowsAffected: i,
825
+ elapsed: performance.now() - r
823
826
  };
824
827
  }
825
- const Nn = {
828
+ const Ft = {
826
829
  BALANCED: 16
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 {
830
+ }, Ne = Ft.BALANCED, Bt = 50 * 1024, Ut = /* @__PURE__ */ new Set(["public$rxdb_change", "public$rxdb_branch", "public$rxdb_migration"]);
831
+ class Wt extends Xe {
829
832
  #n;
830
833
  #e;
831
- #i = !1;
834
+ #a = !1;
832
835
  #o = !1;
833
836
  #c;
834
- #r = [];
837
+ #s = [];
835
838
  #t;
836
- #s = et;
839
+ #r = Ne;
837
840
  /**
838
841
  * 初始化数据库
839
842
  *
840
843
  * @param dbName - 数据库名称(不含 .sqlite 扩展名)
841
844
  * @param options - 加载选项
842
845
  */
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;
846
+ async init(n, t) {
847
+ if (this.#a) return;
848
+ this.#a = !0, this.#c = new we(1);
849
+ const s = await Pt(t), r = `${n}.sqlite`;
850
+ this.#e = await s.open_v2(r), this.#n = s, this.#u(s, this.#e), this.#r = t?.batchTimeout ?? Ne;
851
+ const o = t?.cacheSizeKb ?? Bt;
849
852
  await this.execute(`
850
853
  PRAGMA temp_store = memory;
851
854
  PRAGMA foreign_keys = ON;
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
+ PRAGMA cache_size = -${o};
856
+ `), this.#n.update_hook(this.#e, (i, c, a, l) => {
857
+ !c || !a || !Ut.has(a) || (this.#s.push({ type: i, dbName: c, tableName: a, rowId: l }), this.#i());
855
858
  });
856
859
  }
857
860
  /**
@@ -861,7 +864,7 @@ class Tn extends Lt {
861
864
  */
862
865
  async version() {
863
866
  const n = await this.execute("SELECT sqlite_version()");
864
- return Mt(n, "results[0].rows[0][0]");
867
+ return Ye(n, "results[0].rows[0][0]");
865
868
  }
866
869
  /**
867
870
  * 断开数据库连接
@@ -869,7 +872,7 @@ class Tn extends Lt {
869
872
  * 等待所有待执行任务完成后关闭数据库连接
870
873
  */
871
874
  async disconnect() {
872
- this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#r.length = 0, this.#n.update_hook(this.#e, () => {
875
+ this.#o = !0, this.#t && (clearTimeout(this.#t), this.#t = void 0), this.#s.length = 0, this.#n.update_hook(this.#e, () => {
873
876
  }), await this.#c.waitForAll(), await this.#n.close(this.#e);
874
877
  }
875
878
  /**
@@ -890,38 +893,38 @@ class Tn extends Lt {
890
893
  * );
891
894
  * ```
892
895
  */
893
- async execute(n, e) {
896
+ async execute(n, t) {
894
897
  if (this.#o)
895
898
  throw new Error("SqliteClient has been disconnected");
896
- return this.#c.addTask(() => bn(this.#n, this.#e, n, e));
899
+ return this.#c.addTask(() => kt(this.#n, this.#e, n, t));
897
900
  }
898
901
  /**
899
902
  * 调度批量发送
900
903
  * 使用防抖机制合并连续的变更事件
901
904
  */
902
- #a() {
905
+ #i() {
903
906
  this.#t && clearTimeout(this.#t), this.#t = setTimeout(() => {
904
- this.#u(), this.#t = void 0;
905
- }, this.#s);
907
+ this.#l(), this.#t = void 0;
908
+ }, this.#r);
906
909
  }
907
910
  /**
908
911
  * 刷新待发送事件
909
912
  * 将同类型、同表的事件合并后分发
910
913
  */
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];
914
+ #l() {
915
+ const n = Object.groupBy(this.#s, (t) => `${t.type}_${t.dbName}_${t.tableName}`);
916
+ for (const t of Object.values(n)) {
917
+ if (!t || t.length === 0) continue;
918
+ const s = t[0];
916
919
  this.dispatchEvent(s.type, {
917
920
  type: s.type,
918
921
  dbName: s.dbName,
919
922
  tableName: s.tableName,
920
- rowIds: e.map((o) => o.rowId),
923
+ rowIds: t.map((r) => r.rowId),
921
924
  recordAt: /* @__PURE__ */ new Date()
922
925
  });
923
926
  }
924
- this.#r.length = 0;
927
+ this.#s.length = 0;
925
928
  }
926
929
  /**
927
930
  * 注册自定义 SQL 函数
@@ -930,1535 +933,750 @@ class Tn extends Lt {
930
933
  * - `regexp(pattern, text)` - 正则匹配
931
934
  * - `regexp_replace(pattern, text, replacement[, flags])` - 正则替换
932
935
  */
933
- #l(n, e) {
934
- Sn(n, e), vn(n, e);
936
+ #u(n, t) {
937
+ Ht(n, t), Vt(n, t);
935
938
  }
936
939
  }
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);
940
+ const W = /* @__PURE__ */ new Map(), Kt = 128;
941
+ function qe(e, n = "") {
942
+ const t = `${e}\0${n}`;
943
+ let s = W.get(t);
941
944
  if (!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);
945
+ if (e.length > 1e3) throw new Error("regexp pattern too long");
946
+ s = new RegExp(e, n), W.size >= Kt && W.clear(), W.set(t, s);
944
947
  }
945
948
  return s;
946
949
  }
947
- function Sn(t, n) {
948
- t.create_function(n, "regexp", 2, ot | it, 0, (e, s) => {
950
+ function Ht(e, n) {
951
+ e.create_function(n, "regexp", 2, Ae | Se, 0, (t, s) => {
949
952
  try {
950
- const o = yt(t.value_text(s[0])), a = t.value_text(s[1]);
951
- t.result(e, o.test(a) ? 1 : 0);
953
+ const r = qe(e.value_text(s[0])), o = e.value_text(s[1]);
954
+ e.result(t, r.test(o) ? 1 : 0);
952
955
  } catch {
953
- t.result(e, 0);
956
+ e.result(t, 0);
954
957
  }
955
958
  });
956
959
  }
957
- function vn(t, n) {
958
- t.create_function(n, "regexp_replace", -1, ot | it, 0, (e, s) => {
960
+ function Vt(e, n) {
961
+ e.create_function(n, "regexp_replace", -1, Ae | Se, 0, (t, s) => {
959
962
  if (s.length < 3) {
960
- t.result(e, "");
963
+ e.result(t, "");
961
964
  return;
962
965
  }
963
966
  try {
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));
967
+ 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]) : "";
968
+ e.result(t, o.replace(qe(r, c), i));
966
969
  } catch {
967
- t.result(e, t.value_text(s[1]));
970
+ e.result(t, e.value_text(s[1]));
968
971
  }
969
972
  });
970
973
  }
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
+ async function Qt(e, n) {
975
+ const { vfs: t, async: s, worker: r, wasmPath: o, locateFile: i, workerInstance: c, sharedWorkerInstance: a, sharedWorker: l } = n, u = {
976
+ vfs: t,
974
977
  async: s,
975
- worker: o,
976
- wasmPath: a,
977
- locateFile: d
978
+ worker: r,
979
+ wasmPath: o,
980
+ locateFile: i
978
981
  };
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
+ xe(u);
983
+ let p;
984
+ return r && c ? p = Ee(c) : l && a ? p = Ee(a.port) : p = new Wt(), await p.init(e, u), p;
982
985
  }
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
986
+ const Gt = (e, n) => n.map((t) => {
987
+ const s = e.rxdb.schemaManager.getEntityMetadata(t.entity, t.namespace);
988
+ return s ? (t.inversePatch && Object.keys(t.inversePatch).forEach((r) => {
989
+ const o = s.propertyMap.get(r);
990
+ o && (t.inversePatch[r] = v(
991
+ t.inversePatch[r],
992
+ o
990
993
  ));
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
994
+ }), t.patch && Object.keys(t.patch).forEach((r) => {
995
+ const o = s.propertyMap.get(r);
996
+ o && (t.patch[r] = v(
997
+ t.patch[r],
998
+ o
996
999
  ));
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,
1000
+ })) : console.warn(`Entity metadata not found for ${t.namespace}.${t.entity}`), t;
1001
+ }), Jt = (e, n) => {
1002
+ const t = Object.groupBy(n, (s) => s.type);
1003
+ if (t.INSERT?.length) {
1004
+ const s = t.INSERT.map(
1005
+ (r) => ({
1006
+ namespace: r.namespace,
1007
+ entity: r.entity,
1008
+ type: r.type,
1009
+ id: r.entityId,
1010
+ patch: r.patch,
1008
1011
  inversePatch: null,
1009
- recordAt: o.createdAt
1012
+ recordAt: r.createdAt
1010
1013
  })
1011
1014
  );
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
1015
+ e.rxdb.dispatchEvent(new K(s));
1016
+ }
1017
+ if (t.UPDATE?.length) {
1018
+ const s = t.UPDATE.map(
1019
+ (r) => ({
1020
+ namespace: r.namespace,
1021
+ entity: r.entity,
1022
+ type: r.type,
1023
+ id: r.entityId,
1024
+ patch: r.patch,
1025
+ inversePatch: r.inversePatch,
1026
+ recordAt: r.createdAt
1024
1027
  })
1025
1028
  );
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,
1029
+ e.rxdb.dispatchEvent(new Y(s));
1030
+ }
1031
+ if (t.DELETE?.length) {
1032
+ const s = t.DELETE.map(
1033
+ (r) => ({
1034
+ namespace: r.namespace,
1035
+ entity: r.entity,
1036
+ type: r.type,
1037
+ id: r.entityId,
1035
1038
  patch: null,
1036
- inversePatch: o.inversePatch,
1037
- recordAt: o.createdAt
1039
+ inversePatch: r.inversePatch,
1040
+ recordAt: r.createdAt
1038
1041
  })
1039
1042
  );
1040
- t.rxdb.dispatchEvent(new qe(s));
1043
+ e.rxdb.dispatchEvent(new ce(s));
1041
1044
  }
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) => {
1045
+ }, Xt = (e, n) => {
1046
+ const { tableName: t } = n, [s, r] = ot(t), o = e.rxdb.schemaManager.getEntityTypeByTableName(r, s);
1047
+ if (!o) return;
1048
+ const i = e.getRepository(o), c = T(o), a = T(B);
1049
+ i.findByRowIds(n.rowIds).then((l) => {
1047
1050
  try {
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 },
1051
+ let u = l;
1052
+ if (c === a) {
1053
+ if (u = Gt(e, l), n.type === D.SQLITE_INSERT) {
1054
+ Jt(e, u);
1055
+ const p = u.map((d) => ({
1056
+ namespace: c.namespace,
1057
+ entity: c.name,
1058
+ type: d.type,
1059
+ id: d.id,
1060
+ patch: { ...d },
1058
1061
  inversePatch: null,
1059
- recordAt: I.createdAt
1062
+ recordAt: d.createdAt
1060
1063
  }));
1061
- t.rxdb.dispatchEvent(new Ee(T));
1064
+ e.rxdb.dispatchEvent(new K(p));
1062
1065
  }
1063
1066
  } else {
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()
1067
+ const p = jt(n.type), d = u.map((f) => {
1068
+ const h = {
1069
+ namespace: c.namespace,
1070
+ entity: c.name,
1071
+ type: p,
1072
+ id: f.id,
1073
+ recordAt: f.createdAt || /* @__PURE__ */ new Date()
1071
1074
  };
1072
1075
  switch (n.type) {
1073
- case ce.SQLITE_INSERT:
1076
+ case D.SQLITE_INSERT:
1074
1077
  return {
1075
- ...E,
1076
- patch: { ...M },
1078
+ ...h,
1079
+ patch: { ...f },
1077
1080
  inversePatch: null
1078
1081
  };
1079
- case ce.SQLITE_DELETE:
1082
+ case D.SQLITE_DELETE:
1080
1083
  return {
1081
- ...E,
1084
+ ...h,
1082
1085
  patch: null,
1083
- inversePatch: { ...M }
1086
+ inversePatch: { ...f }
1084
1087
  };
1085
- case ce.SQLITE_UPDATE:
1088
+ case D.SQLITE_UPDATE:
1086
1089
  return {
1087
- ...E,
1090
+ ...h,
1088
1091
  inversePatch: null,
1089
- patch: { ...M }
1092
+ patch: { ...f }
1090
1093
  };
1091
1094
  }
1092
1095
  });
1093
- switch (T) {
1096
+ switch (p) {
1094
1097
  case "UPDATE":
1095
- t.rxdb.dispatchEvent(
1096
- new Te(I)
1098
+ e.rxdb.dispatchEvent(
1099
+ new Y(d)
1097
1100
  );
1098
1101
  break;
1099
1102
  case "DELETE":
1100
- t.rxdb.dispatchEvent(
1101
- new qe(I)
1103
+ e.rxdb.dispatchEvent(
1104
+ new ce(d)
1102
1105
  );
1103
1106
  break;
1104
1107
  case "INSERT":
1105
- t.rxdb.dispatchEvent(
1106
- new Ee(I)
1108
+ e.rxdb.dispatchEvent(
1109
+ new K(d)
1107
1110
  );
1108
1111
  break;
1109
1112
  }
1110
1113
  }
1111
- } catch (A) {
1112
- console.error(`[rxdb-adapter-sqlite] Error processing ${e} change event:`, A);
1114
+ } catch (u) {
1115
+ console.error(`[rxdb-adapter-sqlite] Error processing ${t} change event:`, u);
1113
1116
  }
1114
- }).catch((b) => {
1115
- console.error(`[rxdb-adapter-sqlite] Failed to query ${e} change (rowIds: ${n.rowIds}):`, b);
1117
+ }).catch((l) => {
1118
+ console.error(`[rxdb-adapter-sqlite] Failed to query ${t} change (rowIds: ${n.rowIds}):`, l);
1116
1119
  });
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 = [];
1120
+ }, z = (e, n, t) => {
1121
+ const { isCount: s, isFindDescendants: r, entityId: o, where: i } = t, c = !o, a = A(n), u = n.relationMap.get("parent").columnName;
1122
+ let p = "";
1123
+ const f = [`c.__level < ${t.level || 0}`, i && U(i, /* @__PURE__ */ new Map(), n, e)].filter(Boolean).join(" AND ");
1124
+ f && (p = `WHERE ${f}`);
1125
+ let h = "__children.*";
1126
+ s ? c ? h = "count(*)" : h = "count(*)-1" : t.hasChildren && (h += `, EXISTS(SELECT 1 FROM "${a}" __sub WHERE __sub."${u}" = __children.id) AS hasChildren`);
1127
+ const _ = [];
1125
1128
  let m;
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
+ return c ? m = `"${u}" is null` : (m = "id = ?", _.push(o)), { sql: `WITH RECURSIVE __children AS (
1130
+ SELECT *,rowid as ${q}, 0 AS __level
1131
+ FROM "${a}"
1129
1132
  WHERE ${m}
1130
1133
  UNION ALL
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}
1134
+ SELECT children.*,children.rowid as ${q}, c.__level + 1 AS __level
1135
+ FROM "${a}" children
1136
+ JOIN __children c ON ${r ? `children."${u}" = c.id` : `children.id = c."${u}"`}
1137
+ ${p}
1135
1138
  )
1136
1139
 
1137
- SELECT ${E} FROM __children ORDER BY __level, id;`, params: v };
1138
- }, On = (t, n, e) => $e(t, n, {
1139
- ...e,
1140
+ SELECT ${h} FROM __children ORDER BY __level, id;`, params: _ };
1141
+ }, Yt = (e, n, t) => z(e, n, {
1142
+ ...t,
1140
1143
  isFindDescendants: !0,
1141
1144
  hasChildren: n.features?.tree?.hasChildren
1142
- }), xn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !0, isCount: !0 }), jn = (t, n, e) => $e(t, n, {
1143
- ...e,
1145
+ }), zt = (e, n, t) => z(e, n, { ...t, isFindDescendants: !0, isCount: !0 }), Zt = (e, n, t) => z(e, n, {
1146
+ ...t,
1144
1147
  isFindDescendants: !1,
1145
1148
  hasChildren: n.features?.tree?.hasChildren
1146
- }), Bn = (t, n, e) => $e(t, n, { ...e, isFindDescendants: !1, isCount: !0 });
1147
- class Dn extends ht {
1149
+ }), en = (e, n, t) => z(e, n, { ...t, isFindDescendants: !1, isCount: !0 });
1150
+ class tn extends je {
1148
1151
  async findDescendants(n) {
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);
1152
+ const { sql: t, params: s } = Yt(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
1153
+ return this.addQueryCache(r, !0);
1151
1154
  }
1152
1155
  async countDescendants(n) {
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];
1156
+ const { sql: t, params: s } = zt(this.adapter, this.metadata, n);
1157
+ return (await this.adapter.query(t, s)).results[0].rows[0][0];
1155
1158
  }
1156
1159
  async findAncestors(n) {
1157
- const { sql: e, params: s } = jn(this.adapter, this.metadata, n), o = await this.adapter.query(e, s);
1158
- return this.addQueryCache(o);
1160
+ const { sql: t, params: s } = Zt(this.adapter, this.metadata, n), r = await this.adapter.query(t, s);
1161
+ return this.addQueryCache(r);
1159
1162
  }
1160
1163
  async countAncestors(n) {
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];
1164
+ const { sql: t, params: s } = en(this.adapter, this.metadata, n);
1165
+ return (await this.adapter.query(t, s)).results[0].rows[0][0];
1163
1166
  }
1164
1167
  }
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, {
1168
+ const nn = (e, n) => {
1169
+ const t = A(e), s = n.map((r) => I(r.id)).join(",");
1170
+ return `DELETE FROM "${t}" WHERE id in (${s});`;
1171
+ }, De = (e, n, t) => {
1172
+ 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 = [
1173
+ ...Array.from(e.propertyMap.values()).map((f) => f.columnName),
1174
+ ...e.foreignKeyColumnNames || e.foreignKeyNames
1175
+ ], u = [], p = [];
1176
+ return n.forEach((f) => {
1177
+ const h = be(e, f);
1178
+ r && (h.createdBy = t.userId), o && (h.updatedBy = t.userId), i && h.createdAt === void 0 && (h.createdAt = a), c && h.updatedAt === void 0 && (h.updatedAt = a);
1179
+ const _ = le(e, h), m = [];
1180
+ l.forEach((y) => {
1181
+ m.push("?"), u.push(_[y] ?? null);
1182
+ }), p.push(`(${m.join(",")})`);
1183
+ }), { sql: `INSERT INTO "${s}" (${l.join(",")}) VALUES ${p.join(",")};`, params: u };
1184
+ }, $e = async (e, n) => {
1185
+ const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Date();
1186
+ let r = "";
1187
+ const o = /* @__PURE__ */ new Set();
1188
+ return n.create.forEach((i, c) => {
1189
+ const a = Array.from(i);
1190
+ a.forEach((m) => o.add(m));
1191
+ const l = T(c), u = De(l, a, e.rxdb.context), p = k(u.sql, u.params), d = a.map((m) => m.id);
1192
+ d.forEach((m) => t.set(m, c));
1193
+ const { sql: f, params: h } = ie(e, l, {
1975
1194
  where: {
1976
1195
  combinator: "and",
1977
- rules: [{ field: "id", operator: "in", value: I }]
1196
+ rules: [{ field: "id", operator: "in", value: d }]
1978
1197
  }
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);
1987
- });
1988
- Object.values(A).forEach((T) => {
1989
- const I = T[0], M = ae(I), E = Pe(b, T, M.patch, {
1990
- ...t.rxdb.context,
1198
+ }), _ = k(f, h);
1199
+ r += p + _;
1200
+ }), n.update.forEach((i, c) => {
1201
+ const a = Array.from(i);
1202
+ a.forEach((f) => o.add(f));
1203
+ const l = T(c);
1204
+ a.forEach((f) => {
1205
+ const h = F(f), _ = de(l, f, h.patch, {
1206
+ ...e.rxdb.context,
1991
1207
  returning: !1,
1992
1208
  updatedAt: s
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, {
1998
- where: {
1999
- combinator: "and",
2000
- rules: [{ field: "id", operator: "in", value: m }]
2001
- }
2002
- }), S = fe(N.sql, N.params);
2003
- o += S;
1209
+ });
1210
+ t.set(f.id, c);
1211
+ const m = k(_.sql, _.params);
1212
+ r += m;
2004
1213
  });
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);
1214
+ const u = a.map((f) => f.id);
1215
+ u.forEach((f) => t.set(f, c));
1216
+ const p = ie(e, l, {
1217
+ where: {
1218
+ combinator: "and",
1219
+ rules: [{ field: "id", operator: "in", value: u }]
1220
+ }
1221
+ }), d = k(p.sql, p.params);
1222
+ r += d;
1223
+ }), n.remove.forEach((i, c) => {
1224
+ const a = Array.from(i), l = T(c), u = nn(l, a);
1225
+ r += u;
1226
+ }), r && (await e.query(r)).results.forEach(({ columns: c, rows: a }) => {
1227
+ const l = c.findIndex((d) => d === "id"), u = c.findIndex((d) => d === q), p = e.rxdb.entityManager;
1228
+ a.forEach((d) => {
1229
+ const f = d[l], h = t.get(f), _ = T(h);
1230
+ if (p.hasEntityRef(h, f)) {
1231
+ const m = p.getEntityRef(h, f), y = oe(_, c, d);
1232
+ e.getRepository(h).updateEntity(m, y);
1233
+ const N = F(m);
1234
+ if (N.local = !0, u !== -1) {
1235
+ const $ = BigInt(d[u]);
1236
+ e.cacheRowIdEntity($, m);
2019
1237
  }
2020
- S.modified = !1;
1238
+ N.modified = !1;
2021
1239
  }
2022
1240
  });
2023
1241
  }), n.remove.forEach(
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;
1242
+ (i) => i.forEach((c) => {
1243
+ o.add(c);
1244
+ const a = F(c);
1245
+ a.origin = structuredClone({ ...c }), a.modified = !1, a.removed = !0, a.local = !1;
2028
1246
  })
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}'`);
1247
+ ), Array.from(o);
1248
+ }, sn = (e, n) => {
1249
+ const t = A(n);
1250
+ let s = `CREATE TABLE "${t}" (`;
1251
+ const r = [], o = [], i = [];
1252
+ n.propertyMap.forEach((a) => {
1253
+ const l = a.columnName;
1254
+ let u = `"${l}" ${rt(a)}`;
1255
+ if (a.type === E.integer && a.primary ? u += " PRIMARY KEY AUTOINCREMENT" : (a.type === E.uuid || a.type === E.string) && a.primary && (u += " PRIMARY KEY", a.type === E.uuid && (u += " DEFAULT (lower(hex(randomblob(16))))")), !(a.type === E.uuid && a.primary) && a.default !== void 0) {
1256
+ let d = a.default;
1257
+ me(a.default) && (d = a.default()), d === "CURRENT_TIMESTAMP" ? u += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : (d = V(d, a), a.type === E.boolean || a.type === E.integer || a.type === E.number ? u += ` DEFAULT ${d}` : u += ` DEFAULT '${d}'`);
2040
1258
  }
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 )`);
1259
+ switch (a.nullable || (u += " NOT NULL"), a.type) {
1260
+ case E.json:
1261
+ case E.keyValue:
1262
+ case E.stringArray:
1263
+ case E.numberArray:
1264
+ o.push(`CHECK ( JSON_VALID(${l})=1 )`);
2047
1265
  break;
2048
- case D.boolean:
2049
- a.push(`CHECK (${b} in(0,1))`);
1266
+ case E.boolean:
1267
+ o.push(`CHECK (${l} in(0,1))`);
2050
1268
  break;
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}))`);
1269
+ case E.enum:
1270
+ if ("enum" in a && a.enum && a.enum.length > 0) {
1271
+ const d = a.enum.map((f) => `'${String(f).replace(/'/g, "''")}'`).join(",");
1272
+ o.push(`CHECK (${l} in(${d}))`);
2055
1273
  }
2056
1274
  break;
2057
1275
  }
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
1276
+ a.unique && r.push(
1277
+ `CREATE UNIQUE INDEX ${ye(n, a)} on "${t}"(${l});`
1278
+ ), i.push(u);
1279
+ }), n.relationMap.forEach((a) => {
1280
+ if (a.kind === b.ONE_TO_ONE || a.kind === b.MANY_TO_ONE) {
1281
+ const l = a.columnName, u = e.rxdb.schemaManager.getEntityMetadata(
1282
+ a.mappedEntity,
1283
+ a.mappedNamespace
2066
1284
  );
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}`;
1285
+ let p = "TEXT";
1286
+ const d = u.propertyMap.get("id");
1287
+ d.type === E.integer ? p = "INTEGER" : (d.type === E.uuid || d.type === E.string) && (p = "TEXT");
1288
+ const f = a.onDelete === "SET NULL" || a.onUpdate === "SET NULL";
1289
+ let h = `"${l}" ${p}`;
1290
+ if (!a.nullable && !f && (h += " NOT NULL"), a.kind === b.MANY_TO_ONE && a.default !== void 0) {
1291
+ const _ = a;
1292
+ let m = _.default;
1293
+ me(_.default) && (m = _.default()), h += ` DEFAULT ${m}`;
2076
1294
  }
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
1295
+ if (a.mappedEntity) {
1296
+ const _ = e.rxdb.schemaManager.getEntityMetadata(
1297
+ a.mappedEntity,
1298
+ a.mappedNamespace
1299
+ ), m = P(
1300
+ _?.tableName ?? a.mappedEntity,
1301
+ a.mappedNamespace
2084
1302
  );
2085
- E += ` REFERENCES ${m}(id)`, f.onDelete && (E += ` ON DELETE ${f.onDelete}`), f.onUpdate && (E += ` ON UPDATE ${f.onUpdate}`);
1303
+ h += ` REFERENCES ${m}(id)`, a.onDelete && (h += ` ON DELETE ${a.onDelete}`), a.onUpdate && (h += ` ON UPDATE ${a.onUpdate}`);
2086
1304
  }
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
+ i.push(h), (a.unique || a.kind === b.ONE_TO_ONE) && r.push(
1306
+ `CREATE UNIQUE INDEX ${ye(n, a)} on "${t}"(${l});`
2089
1307
  );
2090
1308
  }
2091
1309
  });
2092
- const p = [...d, ...a];
2093
- if (p.length)
2094
- s += p.map((f) => `
2095
- ${f}`).join(","), s += `
1310
+ const c = [...i, ...o];
1311
+ if (c.length)
1312
+ s += c.map((a) => `
1313
+ ${a}`).join(","), s += `
2096
1314
  );`;
2097
1315
  else
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]}"`;
1316
+ throw new R("columns is empty!");
1317
+ return r.length && (s += `
1318
+ ` + r.join(`
1319
+ `)), n.indexes && n.indexes.length > 0 && n.indexes.forEach((a) => {
1320
+ const l = `idx_${n.name}_${a.name}`, u = a.properties?.map((d) => {
1321
+ const f = n.propertyMap.get(d);
1322
+ if (f) return `"${f.columnName}"`;
1323
+ const h = n.foreignKeyNames, _ = n.foreignKeyColumnNames;
1324
+ if (h && _) {
1325
+ const m = h.indexOf(d);
1326
+ if (m >= 0) return `"${_[m]}"`;
2109
1327
  }
2110
- return `"${I}"`;
2111
- }).join(", ") || `"${f.name}"`, T = f.unique ? "UNIQUE " : "";
1328
+ return `"${d}"`;
1329
+ }).join(", ") || `"${a.name}"`, p = a.unique ? "UNIQUE " : "";
2112
1330
  s += `
2113
- CREATE ${T}INDEX "${b}" ON "${e}"(${A});`;
1331
+ CREATE ${p}INDEX "${l}" ON "${t}"(${u});`;
2114
1332
  }), s;
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}"
1333
+ }, rn = (e, n) => sn(e, n), pe = (e, n = {}) => {
1334
+ const t = A(e), s = T(B), r = A(s), { propertyMap: o, name: i, foreignKeyNames: c, foreignKeyColumnNames: a, namespace: l } = e, u = [];
1335
+ for (const [g, C] of o)
1336
+ g !== "id" && u.push({ jsName: g, dbColumn: C.columnName });
1337
+ const p = a || c;
1338
+ for (let g = 0; g < c.length; g++)
1339
+ c[g] !== "id" && u.push({ jsName: c[g], dbColumn: p[g] });
1340
+ const d = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: f, branchId: h } = n, _ = I(f), m = I(h || "main"), y = `'${l}','${i}',${m},${_}`, N = (g) => g === E.stringArray || g === E.numberArray || g === E.json || g === E.keyValue, $ = (g, C, x) => {
1341
+ const Z = o.get(C);
1342
+ 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}`;
1343
+ }, S = (g, C, x) => o.get(C)?.type === E.boolean ? `CASE WHEN ${x}.${g} = 1 THEN 1 ELSE 0 END` : `${x}.${g}`, L = `
1344
+ DROP TRIGGER IF EXISTS ${t}_insert;
1345
+ CREATE TRIGGER ${t}_insert AFTER INSERT ON "${t}"
2128
1346
  BEGIN
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(`,
1347
+ INSERT INTO ${r} (${d}) VALUES (
1348
+ 'INSERT',${y}, NEW.id, NULL,
1349
+ json_object(${u.map((g) => `'${g.jsName}', ${$(g.dbColumn, g.jsName, "NEW")}`).join(`,
2132
1350
  `)})
2133
1351
  );
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}`;
1352
+ END;`, O = (g) => u.map((C) => {
1353
+ const x = N(o.get(C.jsName)?.type) ? 1 : 0;
1354
+ 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}`;
2137
1355
  }).join(`
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
1356
+ UNION `), M = `
1357
+ DROP TRIGGER IF EXISTS ${t}_update;
1358
+ CREATE TRIGGER ${t}_update AFTER UPDATE ON "${t}"
1359
+ WHEN ( ${u.map((g) => `OLD.${g.dbColumn} IS NOT NEW.${g.dbColumn}`).join(` OR
2142
1360
  `)} )
2143
1361
  BEGIN
2144
- INSERT INTO ${o} (${I}) VALUES (
2145
- 'UPDATE',${N}, NEW.id,
1362
+ INSERT INTO ${r} (${d}) VALUES (
1363
+ 'UPDATE',${y}, NEW.id,
2146
1364
  (
2147
1365
  SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
2148
- ${y("OLD")}
1366
+ ${O("OLD")}
2149
1367
  )
2150
1368
  ),
2151
1369
  (
2152
1370
  SELECT json_group_object(key, CASE WHEN is_json AND value IS NOT NULL THEN json(value) ELSE value END) FROM (
2153
- ${y("NEW")}
1371
+ ${O("NEW")}
2154
1372
  )
2155
1373
  )
2156
1374
  );
2157
- END;`, c = `
2158
- DROP TRIGGER IF EXISTS ${e}_delete;
2159
- CREATE TRIGGER ${e}_delete AFTER DELETE ON "${e}"
1375
+ END;`, j = `
1376
+ DROP TRIGGER IF EXISTS ${t}_delete;
1377
+ CREATE TRIGGER ${t}_delete AFTER DELETE ON "${t}"
2160
1378
  BEGIN
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(`,
1379
+ INSERT INTO ${r} (${d}) VALUES (
1380
+ 'DELETE',${y}, OLD.id,
1381
+ json_object(${u.map((g) => `'${g.jsName}', ${$(g.dbColumn, g.jsName, "OLD")}`).join(`,
2164
1382
  `)}), NULL
2165
1383
  );
2166
1384
  END;`;
2167
- return B + `
2168
- ` + w + `
2169
- ` + c;
2170
- }, Hn = (t, n, e) => {
1385
+ return L + `
1386
+ ` + M + `
1387
+ ` + j;
1388
+ }, on = (e, n, t) => {
2171
1389
  let s = "";
2172
- for (let o = 0; o < n.length; o++) {
2173
- const a = n[o], d = V(a);
1390
+ for (let r = 0; r < n.length; r++) {
1391
+ const o = n[r], i = T(o);
2174
1392
  if (s += `
2175
- ` + Kn(t, d), d.log !== !1) {
2176
- const p = Fe(d);
1393
+ ` + rn(e, i), i.log !== !1) {
1394
+ const c = pe(i);
2177
1395
  s += `
2178
- ` + p;
1396
+ ` + c;
2179
1397
  }
2180
1398
  }
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);
1399
+ if (t) {
1400
+ const r = /* @__PURE__ */ new Map();
1401
+ t.forEach((o) => {
1402
+ const i = T(o);
1403
+ r.has(i) === !1 && r.set(i, /* @__PURE__ */ new Set()), r.get(i).add(o);
2186
1404
  });
2187
- for (const a of o.keys()) {
2188
- const d = gt(
2189
- a,
2190
- Array.from(o.get(a)),
2191
- t.rxdb.context
1405
+ for (const o of r.keys()) {
1406
+ const i = De(
1407
+ o,
1408
+ Array.from(r.get(o)),
1409
+ e.rxdb.context
2192
1410
  );
2193
1411
  s += `
2194
- ` + fe(d.sql, d.params);
1412
+ ` + k(i.sql, i.params);
2195
1413
  }
2196
1414
  }
2197
1415
  return s;
2198
- }, Vn = (t) => {
2199
- const n = X(t);
1416
+ }, an = (e) => {
1417
+ const n = A(e);
2200
1418
  return `DROP TRIGGER IF EXISTS ${n}_insert;
2201
1419
  DROP TRIGGER IF EXISTS ${n}_update;
2202
1420
  DROP TRIGGER IF EXISTS ${n}_delete;`;
2203
- }, Et = (t) => {
1421
+ }, ve = (e) => {
2204
1422
  let n = "";
2205
- return t.rxdb.config.entities.forEach((e) => {
2206
- const s = V(e);
2207
- s.log !== !1 && (n += Vn(s));
1423
+ return e.rxdb.config.entities.forEach((t) => {
1424
+ const s = T(t);
1425
+ s.log !== !1 && (n += an(s));
2208
1426
  }), n;
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
1427
+ }, Pe = (e, n) => {
1428
+ const { deletes: t, inserts: s, updates: r } = n, o = { deletes: [], inserts: [], updates: [] }, i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
1429
+ for (const [d, f] of t.entries()) {
1430
+ const [h, _, m] = ee(d), y = `${h}:${_}`, N = i.get(y);
1431
+ N ? N.add(m) : i.set(y, /* @__PURE__ */ new Set([m]));
1432
+ let $ = c.get(y);
1433
+ $ || ($ = /* @__PURE__ */ new Map(), c.set(y, $)), $.set(m, {
1434
+ patch: f.patch,
1435
+ inversePatch: f.inversePatch
2218
1436
  });
2219
1437
  }
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
+ for (const [d, f] of i) {
1439
+ const [h, _] = d.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(_, h), y = A(m), N = m.propertyMap.get("id").type === "integer";
2222
1440
  let $ = "";
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({
1441
+ N ? $ = Array.from(f).join(",") : $ = Array.from(f).map((L) => I(L)).join(",");
1442
+ const S = `DELETE FROM "${y}" WHERE id in (${$});`;
1443
+ o.deletes.push({
2226
1444
  metadata: m,
2227
- ids: M,
2228
- sql: R,
2229
- changes: p.get(I)
1445
+ ids: f,
1446
+ sql: S,
1447
+ changes: c.get(d)
2230
1448
  });
2231
1449
  }
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
1450
+ const a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
1451
+ for (const [d, f] of s.entries()) {
1452
+ const [h, _, m] = ee(d), y = `${h}:${_}`, N = a.get(y), $ = { ...f.patch, id: m };
1453
+ N ? N.push($) : a.set(y, [$]);
1454
+ let S = l.get(y);
1455
+ S || (S = /* @__PURE__ */ new Map(), l.set(y, S)), S.set(m, {
1456
+ patch: f.patch,
1457
+ inversePatch: f.inversePatch
2240
1458
  });
2241
1459
  }
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, {
1460
+ for (const [d, f] of a) {
1461
+ const [h, _] = d.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(_, h);
1462
+ let y = "";
1463
+ f.forEach((N) => {
1464
+ for (const [O, M] of m.propertyMap)
1465
+ N[O] === void 0 && M.default !== void 0 && (typeof M.default == "function" ? N[O] = M.default() : N[O] = M.default);
1466
+ const { sql: $, params: S } = Le(m, N, {
2249
1467
  useReplace: !0
2250
- }), B = fe($, R);
2251
- N += B;
2252
- }), a.inserts.push({
1468
+ }), L = k($, S);
1469
+ y += L;
1470
+ }), o.inserts.push({
2253
1471
  metadata: m,
2254
- ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
2255
- sql: N,
2256
- changes: b.get(I)
1472
+ ids: new Set(f.filter((N) => N != null).map((N) => N.id)),
1473
+ sql: y,
1474
+ changes: l.get(d)
2257
1475
  });
2258
1476
  }
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
1477
+ const u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
1478
+ for (const [d, f] of r.entries()) {
1479
+ const [h, _, m] = ee(d), y = `${h}:${_}`, N = u.get(y), $ = { ...f.patch, id: m };
1480
+ N ? N.push($) : u.set(y, [$]);
1481
+ let S = p.get(y);
1482
+ S || (S = /* @__PURE__ */ new Map(), p.set(y, S));
1483
+ const L = e.rxdb.schemaManager.getEntityMetadata(_, h), O = f.patch ? { ...f.patch } : null, M = f.inversePatch ? { ...f.inversePatch } : null;
1484
+ L && (O && Object.keys(O).forEach((j) => {
1485
+ const g = L.propertyMap.get(j);
1486
+ g && (O[j] = v(O[j], g));
1487
+ }), M && Object.keys(M).forEach((j) => {
1488
+ const g = L.propertyMap.get(j);
1489
+ g && (M[j] = v(M[j], g));
1490
+ })), S.set(m, {
1491
+ patch: O,
1492
+ inversePatch: M
2275
1493
  });
2276
1494
  }
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) => {
1495
+ for (const [d, f] of u) {
1496
+ const [h, _] = d.split(":"), m = e.rxdb.schemaManager.getEntityMetadata(_, h);
1497
+ let y = "";
1498
+ f.forEach((N) => {
2281
1499
  let $;
2282
- m.propertyMap.has("updatedAt") && ($ = S.updatedAt);
2283
- const { id: R, ...B } = S, { sql: y, params: w } = Pe(m, { id: R }, B, {
1500
+ m.propertyMap.has("updatedAt") && ($ = N.updatedAt);
1501
+ const { id: S, ...L } = N, { sql: O, params: M } = de(m, { id: S }, L, {
2284
1502
  updatedAt: $
2285
1503
  });
2286
- N += fe(y, w);
2287
- }), a.updates.push({
1504
+ y += k(O, M);
1505
+ }), o.updates.push({
2288
1506
  metadata: m,
2289
- ids: new Set(M.filter((S) => S != null).map((S) => S.id)),
2290
- sql: N,
2291
- changes: T.get(I)
1507
+ ids: new Set(f.filter((N) => N != null).map((N) => N.id)),
1508
+ sql: y,
1509
+ changes: p.get(d)
2292
1510
  });
2293
1511
  }
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)
1512
+ return o;
1513
+ }, ke = (e, n) => {
1514
+ let t = "";
1515
+ e.rxdb.config.entities.forEach((i) => {
1516
+ const c = T(i);
1517
+ if (c.log !== !1)
2300
1518
  try {
2301
- const f = Fe(p, {
1519
+ const a = pe(c, {
2302
1520
  branchId: n
2303
1521
  });
2304
- f.trim() && (e += f);
2305
- } catch (f) {
2306
- console.warn(`Failed to generate trigger SQL for entity ${p.name}:`, f);
1522
+ a.trim() && (t += a);
1523
+ } catch (a) {
1524
+ console.warn(`Failed to generate trigger SQL for entity ${c.name}:`, a);
2307
1525
  }
2308
1526
  });
2309
- const s = V(_e), o = X(s), a = n.replace(/'/g, "''");
2310
- return e += `
2311
- UPDATE "${o}"
1527
+ const s = T(H), r = A(s), o = n.replace(/'/g, "''");
1528
+ return t += `
1529
+ UPDATE "${r}"
2312
1530
  SET
2313
1531
  activated = CASE
2314
- WHEN id = '${a}' THEN 1
1532
+ WHEN id = '${o}' THEN 1
2315
1533
  ELSE 0
2316
1534
  END,
2317
1535
  updatedAt = CASE
2318
- WHEN (id = '${a}' AND activated = 0) OR (id != '${a}' AND activated = 1) THEN CURRENT_TIMESTAMP
1536
+ WHEN (id = '${o}' AND activated = 0) OR (id != '${o}' AND activated = 1) THEN CURRENT_TIMESTAMP
2319
1537
  ELSE updatedAt
2320
1538
  END
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;
1539
+ WHERE id = '${o}' OR activated = 1
1540
+ RETURNING rowid as ${q},*;
1541
+ `, t;
1542
+ }, cn = async (e, n) => {
1543
+ const { branchId: t, actions: s } = n, r = s && Pe(e, s);
1544
+ let o;
2327
1545
  try {
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);
1546
+ await e.transaction(async (a) => {
1547
+ const l = ve(e);
1548
+ if (l && await a.execute(l), r) {
1549
+ if (r.deletes.length)
1550
+ for (const u of r.deletes)
1551
+ await a.execute(u.sql);
1552
+ if (r.inserts.length)
1553
+ for (const u of r.inserts)
1554
+ u.successResults = await a.execute(u.sql);
1555
+ if (r.updates.length)
1556
+ for (const u of r.updates)
1557
+ u.successResults = await a.execute(u.sql);
2340
1558
  }
2341
- s?.updateRxDBChangeSequence !== void 0 && await t.setRxDBChangeSequence(s.updateRxDBChangeSequence);
1559
+ s?.updateRxDBChangeSequence !== void 0 && await e.setRxDBChangeSequence(s.updateRxDBChangeSequence);
2342
1560
  }, !1);
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 };
1561
+ const i = ke(e, t);
1562
+ o = await e.internalQuery(i);
1563
+ const c = (a, l) => {
1564
+ if (l.length === 0) return;
1565
+ const u = l.map((p) => {
1566
+ const d = { ...p };
2349
1567
  return {
2350
- namespace: f.namespace,
2351
- entity: f.name,
1568
+ namespace: a.namespace,
1569
+ entity: a.name,
2352
1570
  type: "UPDATE",
2353
- id: T.id,
2354
- patch: I,
2355
- inversePatch: I,
2356
- recordAt: T.createdAt
1571
+ id: p.id,
1572
+ patch: d,
1573
+ inversePatch: d,
1574
+ recordAt: p.createdAt
2357
1575
  };
2358
1576
  });
2359
- t.rxdb.dispatchEvent(new Te(A));
1577
+ e.rxdb.dispatchEvent(new Y(u));
2360
1578
  };
2361
- if (a) {
2362
- const f = Ie(t, _e, a, !0), b = V(_e);
2363
- p(b, f);
1579
+ if (o) {
1580
+ const a = X(e, H, o, !0), l = T(H);
1581
+ c(l, a);
2364
1582
  }
2365
- o && bt(t, o);
2366
- } catch (d) {
2367
- throw new ee(`switch branch ${e} failed`, { cause: d });
1583
+ r && Fe(e, r);
1584
+ } catch (i) {
1585
+ throw new R(`switch branch ${t} failed`, { cause: i });
2368
1586
  }
2369
1587
  };
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);
1588
+ async function ln(e, n, t = !1) {
1589
+ if (await e.transaction(async (s) => {
1590
+ if (t) {
1591
+ const r = ve(e);
1592
+ r && await s.execute(r);
2375
1593
  }
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);
1594
+ for (const r of n.deletes)
1595
+ await s.execute(r.sql);
1596
+ for (const r of n.inserts)
1597
+ r.successResults = await s.execute(r.sql);
1598
+ for (const r of n.updates)
1599
+ r.successResults = await s.execute(r.sql);
1600
+ }, !1), t) {
1601
+ const s = await e.rxdb.versionManager.getCurrentBranch(), r = ke(e, s.id);
1602
+ await e.internalQuery(r);
1603
+ }
1604
+ Fe(e, n);
2387
1605
  }
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));
1606
+ function Fe(e, n) {
1607
+ for (const t of n.deletes) {
1608
+ const s = te(t.metadata);
1609
+ Ct(e, s, Array.from(t.ids));
1610
+ const r = t.metadata, o = Array.from(t.ids).map((i) => {
1611
+ const c = t.changes.get(String(i));
2394
1612
  return {
2395
- namespace: o.namespace,
2396
- entity: o.name,
1613
+ namespace: r.namespace,
1614
+ entity: r.name,
2397
1615
  type: "DELETE",
2398
- id: d,
1616
+ id: i,
2399
1617
  patch: null,
2400
- inversePatch: p?.inversePatch ?? null,
1618
+ inversePatch: c?.inversePatch ?? null,
2401
1619
  recordAt: /* @__PURE__ */ new Date()
2402
1620
  };
2403
1621
  });
2404
- t.rxdb.dispatchEvent(new qe(a));
1622
+ e.rxdb.dispatchEvent(new ce(o));
2405
1623
  }
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));
1624
+ for (const t of n.inserts) {
1625
+ const s = te(t.metadata), r = X(e, s, t.successResults), o = t.metadata, i = r.map((c) => {
1626
+ const a = t.changes.get(String(c.id));
2409
1627
  return {
2410
- namespace: a.namespace,
2411
- entity: a.name,
1628
+ namespace: o.namespace,
1629
+ entity: o.name,
2412
1630
  type: "INSERT",
2413
- id: p.id,
2414
- patch: f?.patch ?? { ...p },
2415
- inversePatch: f?.inversePatch ?? null,
2416
- recordAt: p.createdAt
1631
+ id: c.id,
1632
+ patch: a?.patch ?? { ...c },
1633
+ inversePatch: a?.inversePatch ?? null,
1634
+ recordAt: c.createdAt
2417
1635
  };
2418
1636
  });
2419
- t.rxdb.dispatchEvent(new Ee(d));
1637
+ e.rxdb.dispatchEvent(new K(i));
2420
1638
  }
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));
1639
+ for (const t of n.updates) {
1640
+ const s = te(t.metadata), r = X(e, s, t.successResults, !0), o = t.metadata, i = r.map((c) => {
1641
+ const a = t.changes.get(String(c.id));
2424
1642
  return {
2425
- namespace: a.namespace,
2426
- entity: a.name,
1643
+ namespace: o.namespace,
1644
+ entity: o.name,
2427
1645
  type: "UPDATE",
2428
- id: p.id,
2429
- patch: f?.patch ?? { ...p },
2430
- inversePatch: f?.inversePatch ?? null,
2431
- recordAt: p.updatedAt || p.createdAt || /* @__PURE__ */ new Date()
1646
+ id: c.id,
1647
+ patch: a?.patch ?? { ...c },
1648
+ inversePatch: a?.inversePatch ?? null,
1649
+ recordAt: c.updatedAt || c.createdAt || /* @__PURE__ */ new Date()
2432
1650
  };
2433
1651
  });
2434
- t.rxdb.dispatchEvent(new Te(d));
1652
+ e.rxdb.dispatchEvent(new Y(i));
2435
1653
  }
2436
1654
  }
2437
- const rt = (t, n, e) => {
1655
+ const Te = (e, n, t) => {
2438
1656
  let s = "";
2439
- return t.rxdb.config.entities.forEach((o) => {
2440
- const a = V(o);
2441
- if (a.log !== !1) {
2442
- const d = Fe(a, {
1657
+ return e.rxdb.config.entities.forEach((r) => {
1658
+ const o = T(r);
1659
+ if (o.log !== !1) {
1660
+ const i = pe(o, {
2443
1661
  branchId: n,
2444
- transactionId: e
1662
+ transactionId: t
2445
1663
  });
2446
1664
  s += `
2447
- ` + d;
1665
+ ` + i;
2448
1666
  }
2449
1667
  }), s;
2450
1668
  };
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]);
1669
+ class yn extends He {
1670
+ constructor(n, t) {
1671
+ super(n), this.options = t, t.repositories && Object.keys(t.repositories).forEach((r) => {
1672
+ this.repository(r, t.repositories[r]);
2455
1673
  });
2456
- const s = Ot((o) => {
2457
- this.#t || Mn(this, o);
1674
+ const s = ze((r) => {
1675
+ this.#t || Xt(this, r);
2458
1676
  });
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);
1677
+ this.#r().then((r) => {
1678
+ r.addEventListener(D.SQLITE_INSERT, s), r.addEventListener(D.SQLITE_UPDATE, s), r.addEventListener(D.SQLITE_DELETE, s);
1679
+ }).catch((r) => console.error("[RxDBAdapterSqlite] Failed to register event listeners", r)), this.repository("Repository", je), this.repository("TreeRepository", tn);
2462
1680
  }
2463
1681
  // SQLite 客户端缓存
2464
1682
  #n;
@@ -2469,29 +1687,29 @@ class rr extends $t {
2469
1687
  * 存储数据库行ID到实体UUID的映射关系
2470
1688
  * 用于在数据库操作中快速查找实体
2471
1689
  */
2472
- #i = /* @__PURE__ */ new Map();
1690
+ #a = /* @__PURE__ */ new Map();
2473
1691
  #o = /* @__PURE__ */ new WeakMap();
2474
1692
  // 查询任务队列执行器
2475
- #c = new st(1);
1693
+ #c = new we(1);
2476
1694
  // sqlite 客户端
2477
- #r;
1695
+ #s;
2478
1696
  // 是否已断开连接
2479
1697
  #t = !1;
2480
1698
  /**
2481
1699
  * 适配器名称
2482
1700
  */
2483
- name = yn;
1701
+ name = xt;
2484
1702
  /**
2485
1703
  * 获取实体仓库
2486
1704
  * @param EntityType 实体类
2487
1705
  */
2488
1706
  getRepository(n) {
2489
1707
  if (!this.repository_cache.has(n)) {
2490
- const e = V(n), s = this.repository_map.get(e.repository);
1708
+ const t = T(n), s = this.repository_map.get(t.repository);
2491
1709
  if (!s)
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;
1710
+ throw new R(`Repository '${t.repository}' not found`);
1711
+ const r = new s(this, n);
1712
+ return this.repository_cache.set(n, r), r;
2495
1713
  }
2496
1714
  return this.repository_cache.get(n);
2497
1715
  }
@@ -2499,7 +1717,7 @@ class rr extends $t {
2499
1717
  * 连接 wab sqlite
2500
1718
  */
2501
1719
  async connect() {
2502
- return await this.#s(), this;
1720
+ return await this.#r(), this;
2503
1721
  }
2504
1722
  /**
2505
1723
  * 断开连接
@@ -2511,18 +1729,18 @@ class rr extends $t {
2511
1729
  * 获取版本
2512
1730
  */
2513
1731
  async version() {
2514
- return await (await this.#s()).version();
1732
+ return await (await this.#r()).version();
2515
1733
  }
2516
1734
  /**
2517
1735
  * 保存多个实体
2518
1736
  * @param entities
2519
1737
  */
2520
1738
  async saveMany(n) {
2521
- const e = Qe({
1739
+ const t = he({
2522
1740
  need_save_entities: n,
2523
1741
  need_remove_entities: []
2524
1742
  });
2525
- return this.mutations(e);
1743
+ return this.mutations(t);
2526
1744
  }
2527
1745
  /**
2528
1746
  * 删除多个实例
@@ -2530,26 +1748,26 @@ class rr extends $t {
2530
1748
  * @returns
2531
1749
  */
2532
1750
  async removeMany(n) {
2533
- const e = Qe({
1751
+ const t = he({
2534
1752
  need_save_entities: [],
2535
1753
  need_remove_entities: n
2536
1754
  });
2537
- return this.mutations(e);
1755
+ return this.mutations(t);
2538
1756
  }
2539
1757
  /**
2540
1758
  * 批量修改实体(创建/更新/删除)
2541
1759
  * @param options
2542
1760
  */
2543
1761
  async mutations(n) {
2544
- return this.#e ? await nt(this, n) : await this.transaction(() => nt(this, n));
1762
+ return this.#e ? await $e(this, n) : await this.transaction(() => $e(this, n));
2545
1763
  }
2546
1764
  /**
2547
1765
  * 判断表是否存在
2548
1766
  * @param EntityType
2549
1767
  */
2550
1768
  async isTableExisted(n) {
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
+ const t = T(n), s = A(t), { sql: r, params: o } = nt(s), i = await this.#i(r, o);
1770
+ return st(i) === !1;
2553
1771
  }
2554
1772
  /**
2555
1773
  * 创建表和初始化数据
@@ -2557,9 +1775,9 @@ class rr extends $t {
2557
1775
  * @param entities 视图数据
2558
1776
  * @returns
2559
1777
  */
2560
- async createTables(n, e) {
2561
- const s = Hn(this, n, e);
2562
- return await this.#a(s), !0;
1778
+ async createTables(n, t) {
1779
+ const s = on(this, n, t);
1780
+ return await this.#i(s), !0;
2563
1781
  }
2564
1782
  /**
2565
1783
  * 切换分支
@@ -2567,7 +1785,7 @@ class rr extends $t {
2567
1785
  * @returns
2568
1786
  */
2569
1787
  async switchBranch(n) {
2570
- return Yn(this, n);
1788
+ return cn(this, n);
2571
1789
  }
2572
1790
  /**
2573
1791
  * 应用压缩后的变更到本地实体表
@@ -2578,33 +1796,33 @@ class rr extends $t {
2578
1796
  * @param _localChanges - (已废弃)不再使用
2579
1797
  * @param disableTriggers - 是否禁用触发器(用于 pull 等操作,避免创建 RxDBChange)
2580
1798
  */
2581
- async mergeChanges(n, e, s = !1) {
2582
- const o = _t(this, n);
2583
- await Qn(this, o, s);
1799
+ async mergeChanges(n, t, s = !1) {
1800
+ const r = Pe(this, n);
1801
+ await ln(this, r, s);
2584
1802
  }
2585
1803
  /**
2586
1804
  * 缓存 RowId 与实体映射
2587
1805
  * @param rowId
2588
1806
  * @param entity
2589
1807
  */
2590
- cacheRowIdEntity(n, e) {
2591
- this.#u(e.constructor).set(n, e), this.#o.set(e, n);
1808
+ cacheRowIdEntity(n, t) {
1809
+ this.#l(t.constructor).set(n, t), this.#o.set(t, n);
2592
1810
  }
2593
1811
  /**
2594
1812
  * 移除缓存实体映射
2595
1813
  * @param entity
2596
1814
  */
2597
1815
  removeCacheEntity(n) {
2598
- const e = this.#o.get(n);
2599
- e !== void 0 && (this.#u(n.constructor).delete(e), this.#o.delete(n));
1816
+ const t = this.#o.get(n);
1817
+ t !== void 0 && (this.#l(n.constructor).delete(t), this.#o.delete(n));
2600
1818
  }
2601
1819
  /**
2602
1820
  * 根据 RowId 获取实体
2603
1821
  * @param rowId
2604
1822
  * @returns
2605
1823
  */
2606
- getEntityByRowId(n, e) {
2607
- return this.#u(e).get(n);
1824
+ getEntityByRowId(n, t) {
1825
+ return this.#l(t).get(n);
2608
1826
  }
2609
1827
  /**
2610
1828
  * 根据实体获取 RowId
@@ -2618,13 +1836,13 @@ class rr extends $t {
2618
1836
  * 清空所有缓存
2619
1837
  */
2620
1838
  cleanAllCache() {
2621
- this.#i.clear(), this.#o = /* @__PURE__ */ new WeakMap();
1839
+ this.#a.clear(), this.#o = /* @__PURE__ */ new WeakMap();
2622
1840
  }
2623
1841
  /**
2624
1842
  * 执行 SQL 语句
2625
1843
  */
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
+ query(n, t) {
1845
+ 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)));
2628
1846
  }
2629
1847
  /**
2630
1848
  * 执行事务
@@ -2632,41 +1850,41 @@ class rr extends $t {
2632
1850
  * @param transactionLog 是否生成事务日志
2633
1851
  * @returns
2634
1852
  */
2635
- async transaction(n, e = !0) {
1853
+ async transaction(n, t = !0) {
2636
1854
  await this.rxdb.connect(this.name);
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)
1855
+ const s = await this.#r();
1856
+ this.#e = !0, this.rxdb.dispatchEvent(un);
1857
+ let r = "", o = "";
1858
+ if (t) {
1859
+ const i = Ve(), c = await this.rxdb.versionManager.getCurrentBranch();
1860
+ if (!c)
2643
1861
  throw new Error("currentBranch is undefined! Cannot start transaction with logging.");
2644
- o = rt(this, p.id, d), a = rt(this, p.id);
1862
+ r = Te(this, c.id, i), o = Te(this, c.id);
2645
1863
  }
2646
1864
  await s.execute(`
2647
1865
  BEGIN;
2648
1866
  PRAGMA defer_foreign_keys = ON;
2649
- ${o}
1867
+ ${r}
2650
1868
  `);
2651
1869
  try {
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) {
1870
+ const i = await n(s);
1871
+ return await s.execute(`${o}
1872
+ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(pn), i;
1873
+ } catch (i) {
2656
1874
  try {
2657
1875
  await s.execute("ROLLBACK");
2658
1876
  } finally {
2659
- this.#e = !1, this.rxdb.dispatchEvent(Gn);
1877
+ this.#e = !1, this.rxdb.dispatchEvent(dn);
2660
1878
  }
2661
- const p = d?.message || "Transaction Error";
2662
- throw new ee(p, { cause: d });
1879
+ const c = i?.message || "Transaction Error";
1880
+ throw new R(c, { cause: i });
2663
1881
  }
2664
1882
  }
2665
1883
  /**
2666
1884
  * 本地分支仓库
2667
1885
  */
2668
1886
  localRxDBBranch() {
2669
- return this.getRepository(_e);
1887
+ return this.getRepository(H);
2670
1888
  }
2671
1889
  /**
2672
1890
  * 内部查询
@@ -2674,30 +1892,30 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2674
1892
  * @param sql
2675
1893
  * @returns
2676
1894
  */
2677
- internalQuery(n, e) {
2678
- return this.#a(n, e);
1895
+ internalQuery(n, t) {
1896
+ return this.#i(n, t);
2679
1897
  }
2680
1898
  /**
2681
1899
  * 本地变更仓库
2682
1900
  */
2683
1901
  localRxDBChange() {
2684
- return this.getRepository(pe);
1902
+ return this.getRepository(B);
2685
1903
  }
2686
1904
  /**
2687
1905
  * 获取 RxDBChange 表的当前序列值
2688
1906
  * @returns
2689
1907
  */
2690
1908
  async getRxDBChangeSequence() {
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
+ const n = _e(B);
1910
+ return (await this.#i("SELECT seq FROM sqlite_sequence WHERE name = ?", [n])).results[0]?.rows?.[0]?.[0] ?? 0;
2693
1911
  }
2694
1912
  /**
2695
1913
  * 设置 RxDBChange 表的序列值
2696
1914
  * @param sequence 序列值
2697
1915
  */
2698
1916
  async setRxDBChangeSequence(n) {
2699
- const e = Xe(pe);
2700
- await this.#a("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [n, e]);
1917
+ const t = _e(B);
1918
+ await this.#i("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [n, t]);
2701
1919
  }
2702
1920
  // ============================================
2703
1921
  // QueryCache 方法
@@ -2717,18 +1935,18 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2717
1935
  * .subscribe(map => console.log(map.get('id1')));
2718
1936
  * ```
2719
1937
  */
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;
1938
+ getMetadataByIds(n, t) {
1939
+ return ne(() => {
1940
+ if (t.length === 0)
1941
+ return se(/* @__PURE__ */ new Map());
1942
+ const s = t.map(() => "?").join(", "), r = `SELECT id, updatedAt FROM "${n}" WHERE id IN (${s})`;
1943
+ return re(this.internalQuery(r, t)).pipe(
1944
+ Ze((o) => {
1945
+ const i = /* @__PURE__ */ new Map();
1946
+ if (o.results?.[0]?.rows)
1947
+ for (const c of o.results[0].rows)
1948
+ i.set(c[0], c[1]);
1949
+ return i;
2732
1950
  })
2733
1951
  );
2734
1952
  });
@@ -2748,11 +1966,11 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2748
1966
  * .subscribe(() => console.log('upserted'));
2749
1967
  * ```
2750
1968
  */
2751
- upsertMany(n, e) {
2752
- return Le(() => e.length === 0 ? Me(void 0) : Oe(
1969
+ upsertMany(n, t) {
1970
+ return ne(() => t.length === 0 ? se(void 0) : re(
2753
1971
  (async () => {
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
+ 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]));
1973
+ await this.internalQuery(i, c);
2756
1974
  })()
2757
1975
  ));
2758
1976
  }
@@ -2769,12 +1987,12 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2769
1987
  * .subscribe(() => console.log('deleted'));
2770
1988
  * ```
2771
1989
  */
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(() => {
1990
+ deleteByIds(n, t) {
1991
+ return ne(() => {
1992
+ if (t.length === 0)
1993
+ return se(void 0);
1994
+ const s = t.map(() => "?").join(", "), r = `DELETE FROM "${n}" WHERE id IN (${s})`;
1995
+ return re(this.internalQuery(r, t).then(() => {
2778
1996
  }));
2779
1997
  });
2780
1998
  }
@@ -2784,13 +2002,13 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2784
2002
  /**
2785
2003
  * 获取 SQLite 客户端
2786
2004
  */
2787
- #s() {
2788
- return this.#r || (this.#r = Rn(this.rxdb.config.dbName, this.options).then(
2005
+ #r() {
2006
+ return this.#s || (this.#s = Qt(this.rxdb.config.dbName, this.options).then(
2789
2007
  (n) => (this.#n = n, n),
2790
2008
  (n) => {
2791
- throw this.#r = void 0, n;
2009
+ throw this.#s = void 0, n;
2792
2010
  }
2793
- )), this.#r;
2011
+ )), this.#s;
2794
2012
  }
2795
2013
  /**
2796
2014
  * 内部执行 sql
@@ -2798,23 +2016,23 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(Xn), d;
2798
2016
  * @param sql
2799
2017
  * @param bindings
2800
2018
  */
2801
- async #a(n, e) {
2802
- return await (await this.#s()).execute(n, e);
2019
+ async #i(n, t) {
2020
+ return await (await this.#r()).execute(n, t);
2803
2021
  }
2804
- #u(n) {
2805
- return this.#i.has(n) === !1 && this.#i.set(n, /* @__PURE__ */ new Map()), this.#i.get(n);
2022
+ #l(n) {
2023
+ return this.#a.has(n) === !1 && this.#a.set(n, /* @__PURE__ */ new Map()), this.#a.get(n);
2806
2024
  }
2807
2025
  }
2808
- const Jn = new At(), Gn = new It(), Xn = new Tt();
2026
+ const un = new Ue(), dn = new We(), pn = new Ke();
2809
2027
  export {
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
2028
+ q as ROWID,
2029
+ yn as RxDBAdapterSqlite,
2030
+ R as RxDBAdapterSqliteError,
2031
+ Wt as SqliteClient,
2032
+ je as SqliteRepository,
2033
+ vt as WA_SQLITE_VFS_LIST,
2034
+ U as buildRuleGroup,
2035
+ P as sqliteGetTableName,
2036
+ A as sqliteGetTableNameByMetadata,
2037
+ Pt as sqliteLoad
2820
2038
  };