@aiao/rxdb-adapter-sqlite 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { RxDBError as Le, PropertyType as $, RelationKind as B, getEntityMetadata as N, RxDBChange as we, getEntityStatus as M, EntityCreateEvent as je, EntityUpdateEvent as Fe, RxDBBranch as ie, isEntityMatchWhere as Q, isEntityEffectOrderBy as ge, calculateOrderBy as $e, RepositoryBase as Ue, ENTITY_CREATE_EVENT as se, ENTITY_UPDATE_EVENT as ne, ENTITY_REMOVE_EVENT as V, DATABASE_DELETE as We, DATABASE_INSERT as Ve, DATABASE_UPDATE as Pe, TransactionBeginEvent as Ge, TransactionRollbackEvent as Qe, TransactionCommitEvent as Ke, RxDBAdapterLocalBase as He, uuid as Ye, RxDBAdapterUpdateChangeEvent as Je, RxDBAdapterInsertChangeEvent as Xe, RxDBAdapterDeleteChangeEvent as ze } from "@aiao/rxdb";
2
- import { proxy as Ze, wrap as et } from "comlink";
3
- import { firstValueFrom as g, Subject as z, debounceTime as Z, bufferWhen as pe, filter as G, map as w, shareReplay as U, ReplaySubject as re, BehaviorSubject as K, Observable as Re, takeUntil as Te, distinctUntilChanged as tt, tap as D, switchMap as E, take as ae, defer as st, catchError as nt, of as rt, from as me } from "rxjs";
4
- import { pickBy as Ne, isString as at, isFunction as Ae, traverseObjectKeys as ct, get as ot, once as T } from "@aiao/utils";
5
- import it from "object-hash";
6
- import { Factory as lt, SQLITE_ROW as ut, SQLITE_UTF8 as Ie, SQLITE_DETERMINISTIC as ve } from "wa-sqlite";
7
- const ht = (s) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${s}' limit 1;`, dt = (s) => !!s.sql && (s.results.length === 0 || s.results[0].rows.length === 0), v = "_rowid", _t = (s) => {
1
+ import { RxDBError as We, PropertyType as $, RelationKind as B, getEntityMetadata as R, RxDBChange as Te, getEntityStatus as L, EntityRemoveEvent as Ue, EntityCreateEvent as Ve, EntityUpdateEvent as Pe, RxDBBranch as ie, isEntityMatchWhere as G, isEntityEffectOrderBy as Re, calculateOrderBy as Ne, RepositoryBase as Qe, ENTITY_CREATE_EVENT as se, ENTITY_UPDATE_EVENT as ne, ENTITY_REMOVE_EVENT as P, DATABASE_DELETE as Ge, DATABASE_INSERT as Ke, DATABASE_UPDATE as He, TransactionBeginEvent as Ye, TransactionRollbackEvent as Je, TransactionCommitEvent as Xe, RxDBAdapterLocalBase as ze, uuid as Ze, RxDBAdapterUpdateChangeEvent as et, RxDBAdapterInsertChangeEvent as tt, RxDBAdapterDeleteChangeEvent as st } from "@aiao/rxdb";
2
+ import { proxy as X, wrap as Ee } from "comlink";
3
+ import { firstValueFrom as w, Subject as z, debounceTime as Z, bufferWhen as me, filter as Q, map as g, shareReplay as U, ReplaySubject as re, BehaviorSubject as K, Observable as Ae, takeUntil as Ie, distinctUntilChanged as nt, tap as W, switchMap as m, take as ae, defer as rt, catchError as at, of as ct, from as ye } from "rxjs";
4
+ import { pickBy as ve, isString as ot, isFunction as xe, traverseObjectKeys as it, EventDispatcher as lt, AsyncTaskExecutor as ut, get as ht, once as N } from "@aiao/utils";
5
+ import dt from "object-hash";
6
+ import { Factory as _t, SQLITE_ROW as ft, SQLITE_UTF8 as Oe, SQLITE_DETERMINISTIC as Se } from "wa-sqlite";
7
+ const pt = (s) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${s}' limit 1;`, Et = (s) => !!s.sql && (s.results.length === 0 || s.results[0].rows.length === 0), O = "_rowid", mt = (s) => {
8
8
  switch (s.type) {
9
9
  case $.uuid:
10
10
  case $.string:
@@ -18,7 +18,7 @@ const ht = (s) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${s}
18
18
  default:
19
19
  return "TEXT";
20
20
  }
21
- }, ft = (s, e) => {
21
+ }, yt = (s, e) => {
22
22
  if (s === null && e.nullable) return null;
23
23
  if (s !== void 0)
24
24
  switch (e.type) {
@@ -29,7 +29,7 @@ const ht = (s) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${s}
29
29
  default:
30
30
  return s;
31
31
  }
32
- }, pt = (s, e) => {
32
+ }, bt = (s, e) => {
33
33
  if (s === null && e.nullable) return null;
34
34
  if (s !== void 0)
35
35
  switch (e.type) {
@@ -42,22 +42,22 @@ const ht = (s) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${s}
42
42
  default:
43
43
  return s;
44
44
  }
45
- }, Oe = (s, e) => `${e}$${s}`, b = (s) => Oe(s.name, s.namespace), xe = (s, e) => `idx_${s.name}_${e.name}`;
46
- class R extends Error {
45
+ }, qe = (s, e) => `${e}$${s}`, b = (s) => qe(s.name, s.namespace), Be = (s, e) => `idx_${s.name}_${e.name}`;
46
+ class T extends Error {
47
47
  constructor(e) {
48
- super(e), this.name = "RxDBError", Object.setPrototypeOf(this, Le.prototype);
48
+ super(e), this.name = "RxDBError", Object.setPrototypeOf(this, We.prototype);
49
49
  }
50
50
  }
51
- const H = (s, e) => {
51
+ const le = (s, e) => {
52
52
  const n = {};
53
53
  return Object.keys(e).forEach((t) => {
54
54
  t.endsWith("Id") && (n[t] = e[t]);
55
55
  const r = s.propertyMap.get(t);
56
- r && (n[t] = ft(e[t], r));
56
+ r && (n[t] = yt(e[t], r));
57
57
  }), n;
58
- }, Se = (s, e) => Ne(e, (n, t) => s.propertyMap.has(t) || s.foreignKeyNames.includes(t)), mt = (s, e) => Ne(e, (n, t) => s.propertyMap.get(t)?.readonly !== !0), qe = (s) => at(s) ? `'${s}'` : s ?? "NULL", ee = (s, e = []) => {
58
+ }, ke = (s, e) => ve(e, (n, t) => s.propertyMap.has(t) || s.foreignKeyNames.includes(t)), wt = (s, e) => ve(e, (n, t) => s.propertyMap.get(t)?.readonly !== !0), Le = (s) => ot(s) ? `'${s}'` : s ?? "NULL", ee = (s, e = []) => {
59
59
  for (; s.includes("?"); ) {
60
- const n = qe(e.shift());
60
+ const n = Le(e.shift());
61
61
  s = s.replace("?", n);
62
62
  }
63
63
  return s;
@@ -69,34 +69,34 @@ const H = (s, e) => {
69
69
  t[c] = r;
70
70
  else {
71
71
  const o = s.propertyMap.get(c);
72
- o && (t[c] = pt(r, o));
72
+ o && (t[c] = bt(r, o));
73
73
  }
74
74
  }), t;
75
- }, Et = async (s, e, n) => {
75
+ }, gt = async (s, e, n) => {
76
76
  const t = s.localRxDBBranch(), r = s.localRxDBChange();
77
77
  let a = !1;
78
78
  try {
79
- await g(t.get(e)), a = !0;
79
+ await w(t.get(e)), a = !0;
80
80
  } catch {
81
81
  }
82
- if (a) throw new R(`Branch ID (${e}) already exists`);
82
+ if (a) throw new T(`Branch ID (${e}) already exists`);
83
83
  let c;
84
- if (n ? c = await g(
84
+ if (n ? c = await w(
85
85
  t.findOne({
86
86
  where: {
87
87
  combinator: "and",
88
88
  rules: [{ field: "changes.id", operator: "=", value: n }]
89
89
  }
90
90
  })
91
- ) : c = await g(
91
+ ) : c = await w(
92
92
  t.findOne({
93
93
  where: {
94
94
  combinator: "and",
95
95
  rules: [{ field: "activated", operator: "=", value: !0 }]
96
96
  }
97
97
  })
98
- ), !c) throw new R("Source branch not found");
99
- n || (n = (await g(
98
+ ), !c) throw new T("Source branch not found");
99
+ n || (n = (await w(
100
100
  r.findOne({
101
101
  where: {
102
102
  combinator: "and",
@@ -116,20 +116,20 @@ const H = (s, e) => {
116
116
  fromChangeId: n,
117
117
  newBranchId: e
118
118
  });
119
- }, Be = (s, e, n) => {
119
+ }, Me = (s, e, n) => {
120
120
  const t = b(s), r = n?.userId && s.propertyMap.has("createdBy"), a = n?.userId && s.propertyMap.has("updatedBy"), c = [...s.propertyMap.keys(), ...s.foreignKeyNames], o = [];
121
121
  e.forEach((u) => {
122
- const l = Se(s, u);
122
+ const l = ke(s, u);
123
123
  r && (l.createdBy = n.userId), a && (l.updatedBy = n.userId);
124
- const h = H(s, l), _ = [];
124
+ const h = le(s, l), d = [];
125
125
  c.forEach((f) => {
126
- const p = qe(h[f]);
127
- _.push(p);
128
- }), o.push(_);
126
+ const p = Le(h[f]);
127
+ d.push(p);
128
+ }), o.push(d);
129
129
  });
130
130
  const i = o.map((u) => `(${u.join(",")})`).join(",");
131
131
  return `INSERT INTO "${t}" (${c.join(",")}) VALUES ${i};`;
132
- }, yt = (s, e) => {
132
+ }, $t = (s, e) => {
133
133
  let n = "";
134
134
  const t = b(e);
135
135
  return Array.from(e.relationMap.values()).forEach((r) => {
@@ -142,28 +142,28 @@ const H = (s, e) => {
142
142
  ALTER TABLE "${t}" ADD COLUMN "${a}" TEXT`, r.nullable || (n += " NOT NULL"), r.kind === B.MANY_TO_ONE && Reflect.get(r, "default") !== void 0) {
143
143
  const c = r;
144
144
  let o = c.default;
145
- Ae(c.default) && (o = c.default()), n += ` DEFAULT ${o}`;
145
+ xe(c.default) && (o = c.default()), n += ` DEFAULT ${o}`;
146
146
  }
147
147
  if (r.mappedEntity) {
148
- const c = Oe(r.mappedEntity, r.mappedNamespace);
148
+ const c = qe(r.mappedEntity, r.mappedNamespace);
149
149
  n += ` REFERENCES ${c}(id)`;
150
150
  }
151
151
  r.kind === B.MANY_TO_ONE && (n += " ON DELETE CASCADE"), n += ";", (r.unique || r.kind === B.ONE_TO_ONE) && (n += `
152
- CREATE UNIQUE INDEX ${xe(e, r)} on "${t}"(${a});`);
152
+ CREATE UNIQUE INDEX ${Be(e, r)} on "${t}"(${a});`);
153
153
  }
154
154
  break;
155
155
  }
156
156
  }), n;
157
- }, bt = (s, e) => {
157
+ }, Tt = (s, e) => {
158
158
  const n = b(e);
159
159
  let t = `CREATE TABLE "${n}" (`;
160
160
  const r = [], a = [], c = [];
161
161
  e.propertyMap.forEach((i) => {
162
- let u = `"${i.name}" ${_t(i)}`;
162
+ let u = `"${i.name}" ${mt(i)}`;
163
163
  if (i.type === $.integer && i.primary ? u += " PRIMARY KEY AUTOINCREMENT" : (i.type === $.uuid || i.type === $.string) && i.primary && (u += " PRIMARY KEY"), !i.nullable) u += " NOT NULL";
164
164
  else if (Reflect.get(i, "default") !== void 0) {
165
165
  let l = i.default;
166
- Ae(i.default) && (l = i.default()), l === "CURRENT_TIMESTAMP" ? u += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : u += ` DEFAULT ${String(l)}`;
166
+ xe(i.default) && (l = i.default()), l === "CURRENT_TIMESTAMP" ? u += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : u += ` DEFAULT ${String(l)}`;
167
167
  }
168
168
  switch (i.type) {
169
169
  case $.json:
@@ -174,7 +174,7 @@ ALTER TABLE "${t}" ADD COLUMN "${a}" TEXT`, r.nullable || (n += " NOT NULL"), r.
174
174
  break;
175
175
  }
176
176
  i.unique && r.push(
177
- `CREATE UNIQUE INDEX ${xe(e, i)} on "${n}"(${i.name});`
177
+ `CREATE UNIQUE INDEX ${Be(e, i)} on "${n}"(${i.name});`
178
178
  ), c.push(u);
179
179
  });
180
180
  const o = [...c, ...a];
@@ -183,40 +183,40 @@ ALTER TABLE "${t}" ADD COLUMN "${a}" TEXT`, r.nullable || (n += " NOT NULL"), r.
183
183
  ${i}`).join(","), t += `
184
184
  );`;
185
185
  else
186
- throw new R("columns is empty!");
186
+ throw new T("columns is empty!");
187
187
  return r.length && (t += `
188
188
  ` + r.join(`
189
189
  `)), t;
190
- }, wt = (s, e) => {
190
+ }, Rt = (s, e) => {
191
191
  let n = "";
192
- return n += bt(s, e), n += yt(s, e), n;
193
- }, le = (s, e, n = "main", t = null) => {
194
- const r = b(e), a = N(we), c = b(a), { propertyMap: o, name: i, foreignKeyNames: u, namespace: l } = e, h = [...o.keys(), ...u].filter((d) => ["id", "updatedAt"].includes(d) === !1), _ = "namespace, entity, type, branchId, parentId, entityId, inversePatch, patch", f = t !== null && t >= 0 ? t : "NULL", p = `
192
+ return n += Tt(s, e), n += $t(s, e), n;
193
+ }, ue = (s, e, n = "main", t = null) => {
194
+ const r = b(e), a = R(Te), c = b(a), { propertyMap: o, name: i, foreignKeyNames: u, namespace: l } = e, h = [...o.keys(), ...u].filter((_) => ["id", "updatedAt"].includes(_) === !1), d = "namespace, entity, type, branchId, parentId, entityId, inversePatch, patch", f = t !== null && t >= 0 ? t : "NULL", p = `
195
195
  DROP TRIGGER IF EXISTS ${r}_insert;
196
196
  CREATE TRIGGER ${r}_insert AFTER INSERT ON "${r}"
197
197
  BEGIN
198
- INSERT INTO ${c} (${_}) VALUES (
198
+ INSERT INTO ${c} (${d}) VALUES (
199
199
  '${l}', '${i}', 'INSERT', '${n}', ${f}, NEW.id, NULL,
200
- json_object(${h.map((d) => `'${d}', NEW.${d}`).join(`,
200
+ json_object(${h.map((_) => `'${_}', NEW.${_}`).join(`,
201
201
  `)})
202
202
  );
203
- END;`, m = `
203
+ END;`, E = `
204
204
  DROP TRIGGER IF EXISTS ${r}_update;
205
205
  CREATE TRIGGER ${r}_update AFTER UPDATE ON "${r}"
206
- WHEN ( ${h.map((d) => `OLD.${d} IS NOT NEW.${d}`).join(` OR
206
+ WHEN ( ${h.map((_) => `OLD.${_} IS NOT NEW.${_}`).join(` OR
207
207
  `)} )
208
208
  BEGIN
209
- INSERT INTO ${c} (${_}) VALUES (
209
+ INSERT INTO ${c} (${d}) VALUES (
210
210
  '${l}','${i}','UPDATE', '${n}', ${f}, NEW.id,
211
211
  (
212
212
  SELECT json_group_object(key, value) FROM (
213
- ${h.map((d) => `SELECT '${d}' AS key, OLD.${d} AS value WHERE OLD.${d} IS NOT NEW.${d}`).join(`
213
+ ${h.map((_) => `SELECT '${_}' AS key, OLD.${_} AS value WHERE OLD.${_} IS NOT NEW.${_}`).join(`
214
214
  UNION `)}
215
215
  )
216
216
  ),
217
217
  (
218
218
  SELECT json_group_object(key, value) FROM (
219
- ${h.map((d) => `SELECT '${d}' AS key, NEW.${d} AS value WHERE OLD.${d} IS NOT NEW.${d}`).join(`
219
+ ${h.map((_) => `SELECT '${_}' AS key, NEW.${_} AS value WHERE OLD.${_} IS NOT NEW.${_}`).join(`
220
220
  UNION `)}
221
221
  )
222
222
  )
@@ -225,22 +225,22 @@ ${i}`).join(","), t += `
225
225
  DROP TRIGGER IF EXISTS ${r}_delete;
226
226
  CREATE TRIGGER ${r}_delete AFTER DELETE ON "${r}"
227
227
  BEGIN
228
- INSERT INTO ${c} (${_}) VALUES (
228
+ INSERT INTO ${c} (${d}) VALUES (
229
229
  '${l}', '${i}', 'DELETE', '${n}', ${f}, OLD.id,
230
- json_object(${h.map((d) => `'${d}', OLD.${d}`).join(`,
230
+ json_object(${h.map((_) => `'${_}', OLD.${_}`).join(`,
231
231
  `)}), NULL
232
232
  );
233
233
  END;`;
234
234
  return p + `
235
- ` + m + `
235
+ ` + E + `
236
236
  ` + A;
237
- }, gt = (s, e, n) => {
237
+ }, Nt = (s, e, n) => {
238
238
  let t = "";
239
239
  for (let r = 0; r < e.length; r++) {
240
- const a = e[r], c = N(a);
240
+ const a = e[r], c = R(a);
241
241
  if (t += `
242
- ` + wt(s, c), c.log !== !1) {
243
- const o = le(s, c);
242
+ ` + Rt(s, c), c.log !== !1) {
243
+ const o = ue(s, c);
244
244
  t += `
245
245
  ` + o;
246
246
  }
@@ -248,11 +248,11 @@ ${i}`).join(","), t += `
248
248
  if (n) {
249
249
  const r = /* @__PURE__ */ new Map();
250
250
  n.forEach((a) => {
251
- const c = N(a);
251
+ const c = R(a);
252
252
  r.has(c) === !1 && r.set(c, /* @__PURE__ */ new Set()), r.get(c).add(a);
253
253
  });
254
254
  for (const a of r.keys()) {
255
- const c = Be(
255
+ const c = Me(
256
256
  a,
257
257
  Array.from(r.get(a)),
258
258
  s.rxdb.context
@@ -262,21 +262,45 @@ ${i}`).join(","), t += `
262
262
  }
263
263
  }
264
264
  return t;
265
- }, ke = (s, e, n, t) => {
266
- const r = mt(s, n);
265
+ }, At = (s, e) => {
266
+ const n = b(s), t = e.map((r) => `'${r.id}'`).join(",");
267
+ return `DELETE FROM "${n}" WHERE id in (${t});`;
268
+ }, be = async (s, e, n) => {
269
+ const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
270
+ for (let o = 0; o < e.length; o++) {
271
+ const i = e[o];
272
+ if (L(i).local) {
273
+ let l = [];
274
+ t.has(i.constructor) ? l = t.get(i.constructor) : t.set(i.constructor, l), l.push(i);
275
+ }
276
+ }
277
+ let a = "";
278
+ t.forEach((o, i) => {
279
+ const u = R(i), l = At(u, o);
280
+ o.map((d) => d.id).forEach((d) => r.set(d, i)), a += l;
281
+ });
282
+ const c = await w(s.execute(a));
283
+ return console.log(c), t.forEach((o) => {
284
+ s.rxdb.dispatchEvent(new Ue(o));
285
+ }), r.clear(), t.clear(), e.forEach((o) => {
286
+ const i = L(o);
287
+ o.removedAt = /* @__PURE__ */ new Date(), i.origin = structuredClone({ ...o }), i.modified = !1, i.removed = !0;
288
+ }), e;
289
+ }, De = (s, e, n, t) => {
290
+ const r = wt(s, n);
267
291
  s.propertyMap.has("updatedAt") && (r.updatedAt = t?.updatedAt ?? /* @__PURE__ */ new Date()), t?.userId && s.propertyMap.has("updatedBy") && (r.updatedBy = t.userId);
268
- const a = H(s, r), c = Object.keys(r).map((h) => `${h} = ?`).join(","), o = [...Object.values(a)], i = b(s), u = Array.isArray(e) ? e : [e];
292
+ const a = le(s, r), c = Object.keys(r).map((h) => `${h} = ?`).join(","), o = [...Object.values(a)], i = b(s), u = Array.isArray(e) ? e : [e];
269
293
  let l = `UPDATE "${i}" SET ${c} WHERE id `;
270
- return Array.isArray(e) ? l += `in (${u.map((h) => `'${h.id}'`).join(",")})` : (o.push(e.id), l += "= ?"), t?.returning !== !1 ? l += ` RETURNING rowid as ${v}, *;` : l += ";", {
294
+ return Array.isArray(e) ? l += `in (${u.map((h) => `'${h.id}'`).join(",")})` : (o.push(e.id), l += "= ?"), t?.returning !== !1 ? l += ` RETURNING rowid as ${O}, *;` : l += ";", {
271
295
  sql: l,
272
296
  params: o
273
297
  };
274
- }, ue = (s) => s?.map((e) => `_."${e.field}" ${e.sort}`).join(", "), L = (s, e = /* @__PURE__ */ new Map()) => {
275
- const n = s.rules.map((t) => Ee(t) ? L(t, e) : $t(t, e)).filter(Boolean);
276
- return n.length === 0 ? "" : n.length === 1 ? n[0] : `(${n.join(Ee(s) ? ` ${s.combinator} ` : " ")})`;
277
- }, $t = (s, e) => {
298
+ }, he = (s) => s?.map((e) => `_."${e.field}" ${e.sort}`).join(", "), C = (s, e = /* @__PURE__ */ new Map()) => {
299
+ const n = s.rules.map((t) => we(t) ? C(t, e) : It(t, e)).filter(Boolean);
300
+ return n.length === 0 ? "" : n.length === 1 ? n[0] : `(${n.join(we(s) ? ` ${s.combinator} ` : " ")})`;
301
+ }, It = (s, e) => {
278
302
  let n, t;
279
- if (s?.value === null ? s.operator === "=" ? (n = "", t = "is null") : s.operator === "!=" && (n = "", t = "is not null") : (n = Tt(s.operator).toLowerCase(), t = Nt(s)), !t && ["in", "notIn", "between", "notBetween"].includes(s.operator)) return "";
303
+ if (s?.value === null ? s.operator === "=" ? (n = "", t = "is null") : s.operator === "!=" && (n = "", t = "is not null") : (n = xt(s.operator).toLowerCase(), t = Ot(s)), !t && ["in", "notIn", "between", "notBetween"].includes(s.operator)) return "";
280
304
  let r = String(s.field);
281
305
  if (e.has(r))
282
306
  r = e.get(r);
@@ -285,7 +309,7 @@ ${i}`).join(","), t += `
285
309
  r = `'${c}'.${o}`;
286
310
  }
287
311
  return `${r} ${n} ${t}`.replaceAll(/ +/g, " ").trim();
288
- }, Ee = (s) => "rules" in s && "combinator" in s, Rt = {
312
+ }, we = (s) => "rules" in s && "combinator" in s, vt = {
289
313
  "=": "=",
290
314
  "!=": "!=",
291
315
  ">": ">",
@@ -302,7 +326,7 @@ ${i}`).join(","), t += `
302
326
  notBeginWith: "NOT LIKE",
303
327
  endWith: "LIKE",
304
328
  notEndWith: "NOT LIKE"
305
- }, Tt = (s) => Rt[s] || s, Nt = (s) => {
329
+ }, xt = (s) => vt[s] || s, Ot = (s) => {
306
330
  switch (s.operator) {
307
331
  case "in":
308
332
  case "notIn":
@@ -323,59 +347,59 @@ ${i}`).join(","), t += `
323
347
  return `'%${s.value}'`;
324
348
  }
325
349
  return typeof s.value == "boolean" ? s.value ? "1" : "0" : typeof s.value == "string" ? `'${s.value}'` : typeof s.value == "number" ? s.value.toString() : s.value instanceof Date ? `'${s.value.toISOString()}'` : `'${s.value}'`;
326
- }, Y = (s, e, n) => {
350
+ }, H = (s, e, n) => {
327
351
  const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), o = (l) => {
328
- let h = l, _ = 1;
352
+ let h = l, d = 1;
329
353
  for (; r.has(h); )
330
- h = `${l}_${_}`, _++;
354
+ h = `${l}_${d}`, d++;
331
355
  return r.add(h), h;
332
356
  }, i = (l) => {
333
357
  if (c.has(l))
334
358
  return c.get(l);
335
- const h = l.includes("_") ? l : l.split("_")[0], _ = o(h);
336
- return c.set(l, _), _;
359
+ const h = l.includes("_") ? l : l.split("_")[0], d = o(h);
360
+ return c.set(l, d), d;
337
361
  };
338
- ct(n, (l, h, _) => {
362
+ it(n, (l, h, d) => {
339
363
  const f = h;
340
364
  if (l !== "field" || f.includes(".") === !1) return;
341
- const { relations: p, isForeignKey: m, propertyName: A } = s.rxdb.schemaManager.getFieldRelations(
365
+ const { relations: p, isForeignKey: E, propertyName: A } = s.rxdb.schemaManager.getFieldRelations(
342
366
  e,
343
367
  h
344
368
  );
345
- if (m) {
346
- _.field = A;
369
+ if (E) {
370
+ d.field = A;
347
371
  return;
348
372
  }
349
- const d = f.replace(`.${A}`, ""), y = (O) => p.length === 1 ? O.name : `${d}_${O.name}`, k = (O) => (t.has(O) || t.set(O, []), t.get(O));
350
- p.forEach(({ metadata: O, relation: S }, _e) => {
351
- const W = s.rxdb.schemaManager.findMappedRelation(O, S);
352
- if (!W) throw new R("mappedRelation not found");
353
- const X = () => {
354
- const q = k(W.metadata), I = y(S), F = i(I);
373
+ const _ = f.replace(`.${A}`, ""), y = (v) => p.length === 1 ? v.name : `${_}_${v.name}`, k = (v) => (t.has(v) || t.set(v, []), t.get(v));
374
+ p.forEach(({ metadata: v, relation: S }, fe) => {
375
+ const V = s.rxdb.schemaManager.findMappedRelation(v, S);
376
+ if (!V) throw new T("mappedRelation not found");
377
+ const J = () => {
378
+ const q = k(V.metadata), I = y(S), F = i(I);
355
379
  return {
356
380
  joinArray: q,
357
381
  uniqueAlias: F
358
382
  };
359
383
  };
360
384
  let x = "_";
361
- if (_e > 0) {
362
- const q = p[_e - 1], I = y(q.relation);
385
+ if (fe > 0) {
386
+ const q = p[fe - 1], I = y(q.relation);
363
387
  x = i(I);
364
388
  }
365
389
  switch (S.kind) {
366
390
  case B.ONE_TO_ONE:
367
391
  case B.ONE_TO_MANY:
368
392
  {
369
- const { joinArray: q, uniqueAlias: I } = X();
393
+ const { joinArray: q, uniqueAlias: I } = J();
370
394
  q.push({
371
395
  joinTableName: I,
372
- on: `'${I}'.${W.relation.name}Id = ${x === "_" ? x : `'${x}'`}.id`
396
+ on: `'${I}'.${V.relation.name}Id = ${x === "_" ? x : `'${x}'`}.id`
373
397
  });
374
398
  }
375
399
  break;
376
400
  case B.MANY_TO_ONE:
377
401
  {
378
- const { joinArray: q, uniqueAlias: I } = X();
402
+ const { joinArray: q, uniqueAlias: I } = J();
379
403
  q.push({
380
404
  joinTableName: I,
381
405
  on: `'${I}'.id = ${x === "_" ? x : `'${x}'`}.${S.name}Id`
@@ -384,76 +408,76 @@ ${i}`).join(","), t += `
384
408
  break;
385
409
  case B.MANY_TO_MANY:
386
410
  {
387
- const q = N(S.junctionEntityType), I = k(q), F = o(`${S.name}_m_n`);
411
+ const q = R(S.junctionEntityType), I = k(q), F = o(`${S.name}_m_n`);
388
412
  I.push({
389
413
  joinTableName: F,
390
- on: `'${F}'.${W.relation.name}Id = ${x === "_" ? x : `'${x}'`}.id`
414
+ on: `'${F}'.${V.relation.name}Id = ${x === "_" ? x : `'${x}'`}.id`
391
415
  });
392
- const { joinArray: De, uniqueAlias: fe } = X();
393
- De.push({
394
- joinTableName: fe,
395
- on: `'${fe}'.id = '${F}'.${S.name}Id`
416
+ const { joinArray: Fe, uniqueAlias: pe } = J();
417
+ Fe.push({
418
+ joinTableName: pe,
419
+ on: `'${pe}'.id = '${F}'.${S.name}Id`
396
420
  });
397
421
  }
398
422
  break;
399
423
  }
400
424
  });
401
- const C = p[p.length - 1];
425
+ const M = p[p.length - 1];
402
426
  if (s.rxdb.schemaManager.findMappedRelation(
403
- C.metadata,
404
- C.relation
427
+ M.metadata,
428
+ M.relation
405
429
  )) {
406
- const O = y(C.relation), S = i(O);
430
+ const v = y(M.relation), S = i(v);
407
431
  a.set(f, `'${S}'.${A}`);
408
432
  }
409
433
  });
410
434
  let u = "";
411
435
  for (const [l, h] of t.entries()) {
412
- const _ = b(l);
436
+ const d = b(l);
413
437
  for (const f of h)
414
- u += ` LEFT JOIN "${_}" "${f.joinTableName}" ON ${f.on}`;
438
+ u += ` LEFT JOIN "${d}" "${f.joinTableName}" ON ${f.on}`;
415
439
  }
416
440
  return { joinSQL: u, fieldAliasMap: a };
417
- }, J = (s) => {
441
+ }, Y = (s) => {
418
442
  const { tableName: e, where: n, limit: t, offset: r, orderBy: a, join: c } = s;
419
- let o = `SELECT _.rowid as ${v}, _.* FROM '${e}' _`;
443
+ let o = `SELECT _.rowid as ${O}, _.* FROM '${e}' _`;
420
444
  return c && (o += c), n && (o += ` where ${n}`), a && (o += ` order by ${a}`), t && (o += ` limit ${t}`), r && (o += ` offset ${r}`), o += ";", o;
421
- }, At = (s, e, n) => {
422
- const t = n.where, { joinSQL: r, fieldAliasMap: a } = Y(s, e, t), c = b(e), o = L(t, a), i = ue(n?.orderBy), u = n?.limit || 100, l = n?.offset || 0;
445
+ }, St = (s, e, n) => {
446
+ const t = n.where, { joinSQL: r, fieldAliasMap: a } = H(s, e, t), c = b(e), o = C(t, a), i = he(n?.orderBy), u = n?.limit || 100, l = n?.offset || 0;
423
447
  return {
424
- sql: J({ tableName: c, where: o, orderBy: i, join: r, limit: u, offset: l }),
448
+ sql: Y({ tableName: c, where: o, orderBy: i, join: r, limit: u, offset: l }),
425
449
  params: []
426
450
  };
427
451
  }, oe = (s, e, n) => {
428
- const t = n.where, { joinSQL: r, fieldAliasMap: a } = Y(s, e, t), c = b(e), o = L(t, a), i = ue(n?.orderBy);
452
+ const t = n.where, { joinSQL: r, fieldAliasMap: a } = H(s, e, t), c = b(e), o = C(t, a), i = he(n?.orderBy);
429
453
  return {
430
- sql: J({ tableName: c, where: o, orderBy: i, join: r }),
454
+ sql: Y({ tableName: c, where: o, orderBy: i, join: r }),
431
455
  params: []
432
456
  };
433
- }, It = (s, e, n) => {
434
- const t = n.where, { joinSQL: r, fieldAliasMap: a } = Y(s, e, t), c = b(e), o = L(t, a);
457
+ }, qt = (s, e, n) => {
458
+ const t = n.where, { joinSQL: r, fieldAliasMap: a } = H(s, e, t), c = b(e), o = C(t, a);
435
459
  let i = `SELECT count(_.rowid) as count FROM "${c}" _`;
436
460
  return n?.groupBy, r && (i += r), o && (i += ` where ${o}`), {
437
461
  sql: i,
438
462
  params: []
439
463
  };
440
464
  }, te = (s, e, n) => {
441
- const t = n.where, { joinSQL: r, fieldAliasMap: a } = Y(s, e, t), c = b(e), o = L(t, a), i = ue(n?.orderBy);
465
+ const t = n.where, { joinSQL: r, fieldAliasMap: a } = H(s, e, t), c = b(e), o = C(t, a), i = he(n?.orderBy);
442
466
  return {
443
- sql: J({ tableName: c, where: o, orderBy: i, join: r, limit: 1 }),
467
+ sql: Y({ tableName: c, where: o, orderBy: i, join: r, limit: 1 }),
444
468
  params: []
445
469
  };
446
- }, vt = (s, e) => {
447
- const n = `${v} IN (${e.join(",")})`, t = b(s);
470
+ }, Bt = (s, e) => {
471
+ const n = `${O} IN (${e.join(",")})`, t = b(s);
448
472
  return {
449
- sql: J({ tableName: t, where: n }),
473
+ sql: Y({ tableName: t, where: n }),
450
474
  params: []
451
475
  };
452
- }, ye = async (s, e) => {
476
+ }, ge = async (s, e) => {
453
477
  const n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
454
478
  for (let o = 0; o < e.length; o++) {
455
479
  const i = e[o];
456
- if (M(i).local) {
480
+ if (L(i).local) {
457
481
  let l = [];
458
482
  t.has(i.constructor) ? l = t.get(i.constructor) : t.set(i.constructor, l), l.push(i);
459
483
  } else {
@@ -463,9 +487,9 @@ ${i}`).join(","), t += `
463
487
  }
464
488
  let a = "";
465
489
  return n.forEach((o, i) => {
466
- const u = N(i), l = Be(u, o, s.rxdb.context), h = o.map((m) => m.id);
467
- h.forEach((m) => r.set(m, i));
468
- const { sql: _, params: f } = oe(s, u, {
490
+ const u = R(i), l = Me(u, o, s.rxdb.context), h = o.map((E) => E.id);
491
+ h.forEach((E) => r.set(E, i));
492
+ const { sql: d, params: f } = oe(s, u, {
469
493
  where: {
470
494
  combinator: "and",
471
495
  rules: [
@@ -476,22 +500,22 @@ ${i}`).join(","), t += `
476
500
  }
477
501
  ]
478
502
  }
479
- }), p = ee(_, f);
503
+ }), p = ee(d, f);
480
504
  a += l + p;
481
505
  }), t.forEach((o, i) => {
482
- const u = N(i), l = Object.groupBy(o, (h) => {
483
- const _ = M(h);
484
- return it(_.patch);
506
+ const u = R(i), l = Object.groupBy(o, (h) => {
507
+ const d = L(h);
508
+ return dt(d.patch);
485
509
  });
486
510
  Object.values(l).forEach((h) => {
487
- const _ = h[0], f = M(_), p = /* @__PURE__ */ new Date(), m = ke(u, h, f.patch, {
511
+ const d = h[0], f = L(d), p = /* @__PURE__ */ new Date(), E = De(u, h, f.patch, {
488
512
  ...s.rxdb.context,
489
513
  returning: !1,
490
514
  updatedAt: p
491
- }), A = ee(m.sql, m.params);
515
+ }), A = ee(E.sql, E.params);
492
516
  a += A;
493
- const d = h.map((C) => C.id);
494
- d.forEach((C) => r.set(C, i));
517
+ const _ = h.map((M) => M.id);
518
+ _.forEach((M) => r.set(M, i));
495
519
  const y = oe(s, u, {
496
520
  where: {
497
521
  combinator: "and",
@@ -499,51 +523,51 @@ ${i}`).join(","), t += `
499
523
  {
500
524
  field: "id",
501
525
  operator: "in",
502
- value: d
526
+ value: _
503
527
  }
504
528
  ]
505
529
  }
506
530
  }), k = ee(y.sql, y.params);
507
531
  a += k;
508
532
  });
509
- }), (await g(s.execute(a))).results.forEach(({ columns: o, rows: i }) => {
510
- const u = o.findIndex((_) => _ === "id"), l = o.findIndex((_) => _ === v), h = s.rxdb.entityManager;
511
- i.forEach((_) => {
512
- const f = _[u], p = r.get(f), m = N(p);
533
+ }), (await w(s.execute(a))).results.forEach(({ columns: o, rows: i }) => {
534
+ const u = o.findIndex((d) => d === "id"), l = o.findIndex((d) => d === O), h = s.rxdb.entityManager;
535
+ i.forEach((d) => {
536
+ const f = d[u], p = r.get(f), E = R(p);
513
537
  let A;
514
538
  if (h.hasEntityRef(p, f)) {
515
539
  A = h.getEntityRef(p, f);
516
- const d = ce(m, o, _);
517
- s.getRepository(p).updateEntity(A, d);
518
- const y = M(A);
519
- y.local = !0, l !== -1 && (y.rowId = BigInt(_[l])), y.modified = !1;
540
+ const _ = ce(E, o, d);
541
+ s.getRepository(p).updateEntity(A, _);
542
+ const y = L(A);
543
+ y.local = !0, l !== -1 && (y.rowId = BigInt(d[l])), y.modified = !1;
520
544
  }
521
545
  });
522
546
  }), n.forEach((o) => {
523
- s.rxdb.dispatchEvent(new je(o));
547
+ s.rxdb.dispatchEvent(new Ve(o));
524
548
  }), t.forEach((o) => {
525
- s.rxdb.dispatchEvent(new Fe(o));
549
+ s.rxdb.dispatchEvent(new Pe(o));
526
550
  }), r.clear(), n.clear(), t.clear(), e;
527
- }, Ot = (s, e, n) => {
551
+ }, kt = (s, e, n) => {
528
552
  let t = "";
529
553
  if (s.rxdb.options.entities.forEach((r) => {
530
- const a = N(r);
554
+ const a = R(r);
531
555
  if (a.log !== !1) {
532
- const c = le(s, a, e, n);
556
+ const c = ue(s, a, e, n);
533
557
  t += `
534
558
  ` + c;
535
559
  }
536
560
  }), t) {
537
- const r = N(ie), a = b(r);
561
+ const r = R(ie), a = b(r);
538
562
  t = `
539
563
  ${t}
540
- UPDATE "${a}" SET activated = 1 WHERE id = '${e}' and activated != 1 RETURNING rowid as ${v},*;
541
- UPDATE "${a}" SET activated = 0 WHERE id != '${e}' and activated = 1 RETURNING rowid as ${v},*;
564
+ UPDATE "${a}" SET activated = 1 WHERE id = '${e}' and activated != 1 RETURNING rowid as ${O},*;
565
+ UPDATE "${a}" SET activated = 0 WHERE id != '${e}' and activated = 1 RETURNING rowid as ${O},*;
542
566
  `;
543
567
  }
544
568
  return t;
545
- }, xt = async (s, e) => {
546
- const n = s.localRxDBBranch(), t = s.localRxDBChange(), r = await g(
569
+ }, Lt = async (s, e) => {
570
+ const n = s.localRxDBBranch(), t = s.localRxDBChange(), r = await w(
547
571
  n.findOne({
548
572
  where: {
549
573
  combinator: "and",
@@ -551,9 +575,9 @@ ${i}`).join(","), t += `
551
575
  }
552
576
  })
553
577
  );
554
- if (!r) throw new R("Current branch not found");
578
+ if (!r) throw new T("Current branch not found");
555
579
  if (r.id === e) return;
556
- const a = await g(
580
+ const a = await w(
557
581
  t.findOne({
558
582
  where: {
559
583
  combinator: "and",
@@ -570,7 +594,7 @@ ${i}`).join(","), t += `
570
594
  })
571
595
  );
572
596
  a && (a.parentId ? console.log("把当前分支的数据切换记录到:", a.parentId) : console.log("不应该出现这个情况,如果为空,应该还原所有记录"));
573
- const c = await g(
597
+ const c = await w(
574
598
  t.findOne({
575
599
  where: {
576
600
  combinator: "and",
@@ -581,24 +605,24 @@ ${i}`).join(","), t += `
581
605
  );
582
606
  let o = "";
583
607
  if (s.rxdb.options.entities.forEach((i) => {
584
- const u = N(i);
608
+ const u = R(i);
585
609
  if (u.log !== !1) {
586
- const l = le(s, u, e, c?.id);
610
+ const l = ue(s, u, e, c?.id);
587
611
  o += `
588
612
  ` + l;
589
613
  }
590
614
  }), o) {
591
615
  o = `
592
616
  BEGIN;
593
- ${Ot(s, e, c?.id)}
617
+ ${kt(s, e, c?.id)}
594
618
  COMMIT;
595
619
  `;
596
- const u = await g(s.execute(o));
620
+ const u = await w(s.execute(o));
597
621
  s.getRepository(ie).addQueryCache(u, !0);
598
622
  }
599
623
  };
600
- var P = /* @__PURE__ */ ((s) => (s[s.SQLITE_DELETE = 9] = "SQLITE_DELETE", s[s.SQLITE_INSERT = 18] = "SQLITE_INSERT", s[s.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", s))(P || {});
601
- const St = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").then((s) => s.default), Bt = () => import("wa-sqlite/dist/wa-sqlite.mjs").then((s) => s.default), kt = [
624
+ var D = /* @__PURE__ */ ((s) => (s[s.SQLITE_DELETE = 9] = "SQLITE_DELETE", s[s.SQLITE_INSERT = 18] = "SQLITE_INSERT", s[s.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", s))(D || {});
625
+ const Mt = "sqlite", Dt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").then((s) => s.default), Ct = () => import("wa-sqlite/dist/wa-sqlite.mjs").then((s) => s.default), jt = [
602
626
  {
603
627
  name: "MemoryVFS",
604
628
  vfsModule: () => import("wa-sqlite/src/examples/MemoryVFS.js").then((s) => s.MemoryVFS),
@@ -683,21 +707,21 @@ const St = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").the
683
707
  multipleConnections: !0
684
708
  }
685
709
  ], Ce = (s) => {
686
- const e = kt.find((a) => a.name === s.vfs), { vfs: n, async: t, worker: r } = s;
687
- if (!e) throw new R(`vfs ${n} not found`);
688
- if (t !== t) throw new R(`vfs ${n} not support async: ${t}`);
689
- if (r && !e.worker) throw new R(`vfs ${n} not support worker`);
690
- if (!r && !e.jsContext) throw new R(`vfs ${n} only support worker`);
710
+ const e = jt.find((a) => a.name === s.vfs), { vfs: n, async: t, worker: r } = s;
711
+ if (!e) throw new T(`vfs ${n} not found`);
712
+ if (t !== t) throw new T(`vfs ${n} not support async: ${t}`);
713
+ if (r && !e.worker) throw new T(`vfs ${n} not support worker`);
714
+ if (!r && !e.jsContext) throw new T(`vfs ${n} only support worker`);
691
715
  return e;
692
- }, Ct = async (s) => {
716
+ }, Ft = async (s) => {
693
717
  const e = Ce(s), n = s.async ?? !0;
694
718
  let t;
695
- n ? t = qt : t = Bt;
719
+ n ? t = Dt : t = Ct;
696
720
  const [r, a] = await Promise.all([t(), e.vfsModule()]), c = {};
697
721
  s.locateFile ? c.locateFile = s.locateFile : s.wasmPath && (c.locateFile = () => s.wasmPath);
698
- const o = await r(c), i = lt(o), u = await a.create(s.vfs, o, e.vfsOptions);
722
+ const o = await r(c), i = _t(o), u = await a.create(s.vfs, o, e.vfsOptions);
699
723
  return i.vfs_register(u, !0), i;
700
- }, Mt = async (s, e, n, t) => {
724
+ }, Wt = async (s, e, n, t) => {
701
725
  const r = performance.now(), a = t ? [t] : [[]], c = [];
702
726
  let o = 0;
703
727
  const i = {
@@ -706,12 +730,12 @@ const St = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").the
706
730
  };
707
731
  for await (const u of s.statements(e, n)) {
708
732
  if (t)
709
- for (const _ of a)
710
- s.reset(u), t && s.bind_collection(u, _);
733
+ for (const d of a)
734
+ s.reset(u), t && s.bind_collection(u, d);
711
735
  const l = [];
712
- for (; await s.step(u) === ut; ) {
713
- const _ = s.row(u);
714
- l.push(_);
736
+ for (; await s.step(u) === ft; ) {
737
+ const d = s.row(u);
738
+ l.push(d);
715
739
  }
716
740
  const h = s.column_names(u);
717
741
  h.length && c.push({ columns: h, rows: l }), o += s.changes(e);
@@ -721,10 +745,10 @@ const St = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").the
721
745
  rowsAffected: o,
722
746
  elapsed: performance.now() - r
723
747
  };
724
- }, Dt = (s, e) => s.create_function(e, "regexp", 2, Ie | ve, 0, (n, t) => {
748
+ }, Ut = (s, e) => s.create_function(e, "regexp", 2, Oe | Se, 0, (n, t) => {
725
749
  const r = new RegExp(s.value_text(t[0])), a = s.value_text(t[1]);
726
750
  s.result(n, r.test(a) ? 1 : 0);
727
- }), Lt = (s, e) => s.create_function(e, "regexp_replace", -1, Ie | ve, 0, (n, t) => {
751
+ }), Vt = (s, e) => s.create_function(e, "regexp_replace", -1, Oe | Se, 0, (n, t) => {
728
752
  if (t.length < 3) {
729
753
  s.result(n, "");
730
754
  return;
@@ -732,18 +756,18 @@ const St = "sqlite", qt = () => import("wa-sqlite/dist/wa-sqlite-async.mjs").the
732
756
  const r = s.value_text(t[0]), a = s.value_text(t[1]), c = s.value_text(t[2]), o = t.length > 3 ? s.value_text(t[3]) : "";
733
757
  s.result(n, a.replace(new RegExp(r, o), c));
734
758
  });
735
- class jt {
759
+ class Pt extends lt {
736
760
  #e;
737
761
  #t;
738
- #r = [];
762
+ #n = [];
739
763
  #s;
740
- #n;
741
- set onChange(e) {
742
- this.#n = e;
743
- }
764
+ #a;
765
+ #r = !1;
744
766
  async init(e, n) {
745
- const t = await Ct(n), r = e + ".sqlite";
746
- this.#t = await t.open_v2(r), this.#e = t, Dt(t, this.#t), Lt(t, this.#t);
767
+ if (this.#r) return;
768
+ this.#r = !0, this.#a = new ut(1);
769
+ const t = await Ft(n), r = e + ".sqlite";
770
+ this.#t = await t.open_v2(r), this.#e = t, Ut(t, this.#t), Vt(t, this.#t);
747
771
  const a = n?.cacheSizeKb || 50 * 1024;
748
772
  await this.execute(`
749
773
  PRAGMA temp_store = memory;
@@ -753,22 +777,22 @@ class jt {
753
777
  `), this.#e.update_hook(
754
778
  this.#t,
755
779
  (c, o, i, u) => {
756
- if (i !== "public$RxDBChange" || !o || !i || !this.#n) return;
780
+ if (console.log("change"), i !== "public$RxDBChange" || !o || !i) return;
757
781
  const l = {
758
782
  type: c,
759
783
  dbName: o,
760
784
  tableName: i,
761
785
  rowId: u
762
786
  };
763
- this.#r.push(l), this.#s && clearTimeout(this.#s), this.#s = setTimeout(() => {
764
- this.#a(), this.#s = void 0;
787
+ this.#n.push(l), this.#s && clearTimeout(this.#s), this.#s = setTimeout(() => {
788
+ this.#o(), this.#s = void 0;
765
789
  });
766
790
  }
767
791
  );
768
792
  }
769
793
  async version() {
770
794
  const e = await this.execute("SELECT sqlite_version()");
771
- return ot(e, "results[0].rows[0][0]");
795
+ return ht(e, "results[0].rows[0][0]");
772
796
  }
773
797
  async disconnect() {
774
798
  await this.#e.close(this.#t);
@@ -780,80 +804,71 @@ class jt {
780
804
  * @returns
781
805
  */
782
806
  async execute(e, n) {
783
- return Mt(this.#e, this.#t, e, n);
807
+ return this.#a.addTask(() => Wt(this.#e, this.#t, e, n));
784
808
  }
785
- #a() {
786
- const e = Object.groupBy(this.#r, (n) => `${n.type}_${n.dbName}_${n.tableName}`);
809
+ #o() {
810
+ const e = Object.groupBy(this.#n, (n) => `${n.type}_${n.dbName}_${n.tableName}`);
787
811
  Object.values(e).forEach((n) => {
788
- const t = n[0], r = n.map((a) => a.rowId);
789
- this.#n?.({
812
+ const t = n[0], r = n.map((c) => c.rowId), a = {
790
813
  type: t.type,
791
814
  dbName: t.dbName,
792
815
  tableName: t.tableName,
793
816
  rowIds: r,
794
817
  recordAt: /* @__PURE__ */ new Date()
795
- });
796
- }), this.#r.length = 0;
818
+ };
819
+ this.dispatchEvent(a);
820
+ }), this.#n.length = 0;
797
821
  }
798
822
  }
799
- const Ft = (s, e, n) => {
823
+ const Qt = (s, e, n) => {
800
824
  const t = b(s), r = [e.id];
801
825
  return {
802
826
  sql: `DELETE FROM "${t}" WHERE id = ?;`,
803
827
  params: r
804
828
  };
805
- }, Ut = (s, e, n) => {
806
- const t = b(s), r = Se(s, e);
829
+ }, Gt = (s, e, n) => {
830
+ const t = b(s), r = ke(s, e);
807
831
  n?.userId && (s.propertyMap.has("createdBy") && (r.createdBy = n.userId), s.propertyMap.has("updatedBy") && (r.updatedBy = n.userId));
808
- const a = Object.keys(r), c = H(s, r), o = Array(a.length).fill("?").join(","), i = Object.values(c);
832
+ const a = Object.keys(r), c = le(s, r), o = Array(a.length).fill("?").join(","), i = Object.values(c);
809
833
  let u = `INSERT INTO "${t}" (${a.join(",")}) VALUES (${o})`;
810
- return n?.returning !== !1 ? u += ` RETURNING rowid as ${v}, *;` : u += ";", {
811
- sql: u,
812
- params: i
813
- };
814
- }, Wt = (s, e, n) => {
815
- const t = {};
816
- s.propertyMap.has("removedAt") && (t.removedAt = /* @__PURE__ */ new Date()), n?.userId && s.propertyMap.has("removedBy") && (t.removedBy = n.userId);
817
- const r = b(s), c = Object.keys(t).map((l) => `${l} = ?`).join(","), o = H(s, t), i = [...Object.values(o), e.id];
818
- let u = `UPDATE "${r}" SET ${c} WHERE id = ? and removedAt is null and removedBy is null`;
819
- return n?.returning !== !1 ? u += ` RETURNING rowid as ${v}, *;` : u += ";", {
834
+ return n?.returning !== !1 ? u += ` RETURNING rowid as ${O}, *;` : u += ";", {
820
835
  sql: u,
821
836
  params: i
822
837
  };
823
- }, he = (s, e, n, t, r) => {
838
+ }, de = (s, e, n, t, r) => {
824
839
  if (s.length === 0 && e.length === 0) return { refresh: !1, recalculate: !1 };
825
- const { options: a } = n, c = t.resultEntityIds, o = T(() => r.map((d) => d.id)), i = T(() => r.some((d) => Q(d, a.where))), u = T(
840
+ const { options: a } = n, c = t.resultEntityIds, o = N(() => r.map((_) => _.id)), i = N(() => r.some((_) => G(_, a.where))), u = N(
826
841
  () => a.orderBy && r.some(
827
- (d) => ge(d, t.resultEntities || [], a.orderBy)
842
+ (_) => Re(_, t.resultEntities || [], a.orderBy)
828
843
  )
829
- ), l = T(() => u() !== !1), h = T(() => i() === !1), _ = T(
830
- () => c ? c.some((d) => o().includes(d)) : !0
831
- ), f = T(() => _() === !1), p = {
844
+ ), l = N(() => u() !== !1), h = N(() => i() === !1), d = N(
845
+ () => c ? c.some((_) => o().includes(_)) : !0
846
+ ), f = N(() => d() === !1), p = {
832
847
  match_where: i,
833
848
  not_match_where: h,
834
849
  match_order_by: l,
835
- result_contains: _,
850
+ result_contains: d,
836
851
  result_not_contains: f
837
- }, m = e.some(
838
- (d) => d.every((y) => p[y]())
852
+ }, E = e.some(
853
+ (_) => _.every((y) => p[y]())
839
854
  );
840
855
  return {
841
- refresh: m === !1 && s.some(
842
- (d) => d.every((y) => p[y]())
856
+ refresh: E === !1 && s.some(
857
+ (_) => _.every((y) => p[y]())
843
858
  ),
844
- recalculate: m
859
+ recalculate: E
845
860
  };
846
- }, Vt = (s, e, n) => {
861
+ }, Kt = (s, e, n) => {
847
862
  switch (e.type) {
848
863
  case "findAll":
849
864
  {
850
865
  const { options: t } = e;
851
866
  let r = s.resultEntities;
852
- r = r.concat(n), r = r.filter((a) => Q(a, e.options.where)), t.orderBy && t.orderBy.length && (r = $e(r, t.orderBy)), s.updateResult(r), e.refresh();
867
+ r = r.concat(n), r = r.filter((a) => G(a, e.options.where)), t.orderBy && t.orderBy.length && (r = Ne(r, t.orderBy)), s.updateResult(r), e.refresh();
853
868
  }
854
869
  break;
855
870
  }
856
- }, Pt = (s, e, n) => {
871
+ }, Ht = (s, e, n) => {
857
872
  const t = [], r = [];
858
873
  switch (e.type) {
859
874
  case "find":
@@ -868,14 +883,14 @@ const Ft = (s, e, n) => {
868
883
  t.push(["match_where"]);
869
884
  break;
870
885
  }
871
- const a = he(t, r, e, s, n);
872
- a.refresh ? s.refresh() : a.recalculate && Vt(s, e, n);
873
- }, Gt = (s, e, n) => {
886
+ const a = de(t, r, e, s, n);
887
+ a.refresh ? s.refresh() : a.recalculate && Kt(s, e, n);
888
+ }, Yt = (s, e, n) => {
874
889
  if (Array.isArray(s.result)) {
875
890
  const t = s.result.filter((r) => !n.includes(r));
876
891
  s.updateResult(t), e.refresh();
877
892
  }
878
- }, Qt = (s, e, n) => {
893
+ }, Jt = (s, e, n) => {
879
894
  const t = [], r = [];
880
895
  switch (e.type) {
881
896
  case "find":
@@ -890,20 +905,20 @@ const Ft = (s, e, n) => {
890
905
  t.push(["match_where"]);
891
906
  break;
892
907
  }
893
- const a = he(t, r, e, s, n);
894
- a.refresh ? s.refresh() : a.recalculate && Gt(s, e, n);
895
- }, Kt = (s, e) => {
908
+ const a = de(t, r, e, s, n);
909
+ a.refresh ? s.refresh() : a.recalculate && Yt(s, e, n);
910
+ }, Xt = (s, e) => {
896
911
  switch (e.type) {
897
912
  case "findOne":
898
913
  case "findOneOrFail":
899
914
  case "find":
900
915
  case "findAll": {
901
916
  let n = s.resultEntities;
902
- n = n.filter((t) => Q(t, e.options.where)), e.options.orderBy && e.options.orderBy.length && (n = $e(n, e.options.orderBy)), s.updateResult(n), e.refresh();
917
+ n = n.filter((t) => G(t, e.options.where)), e.options.orderBy && e.options.orderBy.length && (n = Ne(n, e.options.orderBy)), s.updateResult(n), e.refresh();
903
918
  return;
904
919
  }
905
920
  }
906
- }, Ht = (s, e, n) => {
921
+ }, zt = (s, e, n) => {
907
922
  const t = [], r = [];
908
923
  switch (e.type) {
909
924
  case "find":
@@ -918,24 +933,24 @@ const Ft = (s, e, n) => {
918
933
  t.push(["match_where"], ["not_match_where", "result_contains"]);
919
934
  break;
920
935
  }
921
- const a = he(t, r, e, s, n);
922
- a.refresh ? s.refresh() : a.recalculate && Kt(s, e);
923
- }, be = (s, e = []) => s + e.join(",");
924
- class Yt extends Ue {
936
+ const a = de(t, r, e, s, n);
937
+ a.refresh ? s.refresh() : a.recalculate && Xt(s, e);
938
+ }, $e = (s, e = []) => s + e.join(",");
939
+ class Zt extends Qe {
925
940
  constructor(e, n, t) {
926
- super(e.rxdb, t), this.adapter = e, this.client$ = n, this.metadata = N(t), this.run_task$.subscribe(() => this.#e());
941
+ super(e.rxdb, t), this.adapter = e, this.client$ = n, this.metadata = R(t), this.run_task$.subscribe(() => this.#e());
927
942
  const r = (c) => {
928
943
  const o = c.entities.filter((i) => i.constructor === t);
929
944
  o.length && this.db_changes_sub.next({ ...c, entities: o });
930
945
  };
931
- this.rxdb.addEventListener(se, (c) => r(c)), this.rxdb.addEventListener(ne, (c) => r(c)), this.rxdb.addEventListener(V, (c) => r(c));
946
+ this.rxdb.addEventListener(se, (c) => r(c)), this.rxdb.addEventListener(ne, (c) => r(c)), this.rxdb.addEventListener(P, (c) => r(c));
932
947
  const a = (c, o) => {
933
948
  if (o.EntityType !== t || this.cache_query_task_map.size === 0) return;
934
949
  const { rowIds: i, recordAt: u } = o.data, l = [], h = [];
935
950
  if (i.forEach((f) => {
936
951
  const p = this.rxdb.entityManager.getEntityByRowId(t, f);
937
952
  p ? l.push(p) : h.push(f);
938
- }), c === V && l.length) {
953
+ }), c === P && l.length) {
939
954
  this.db_changes_sub.next({ type: c, entities: l });
940
955
  return;
941
956
  }
@@ -943,7 +958,7 @@ class Yt extends Ue {
943
958
  (f) => f.updatedAt && f.updatedAt.getTime && u.getTime() - f.updatedAt.getTime() > 500
944
959
  ).length && this.db_checks_sub.next({ type: c, changes: o.data });
945
960
  };
946
- this.rxdb.addEventListener(We, (c) => a(V, c)), this.rxdb.addEventListener(Ve, (c) => a(se, c)), this.rxdb.addEventListener(Pe, (c) => a(ne, c));
961
+ this.rxdb.addEventListener(Ge, (c) => a(P, c)), this.rxdb.addEventListener(Ke, (c) => a(se, c)), this.rxdb.addEventListener(He, (c) => a(ne, c));
947
962
  }
948
963
  metadata;
949
964
  // 任务队列
@@ -957,9 +972,9 @@ class Yt extends Ue {
957
972
  db_changes_sub = new z();
958
973
  db_changes_next$ = this.db_changes_sub.asObservable().pipe(Z(16));
959
974
  db_changes$ = this.db_changes_sub.asObservable().pipe(
960
- pe(() => this.db_changes_next$),
961
- G((e) => e.length > 0),
962
- w((e) => {
975
+ me(() => this.db_changes_next$),
976
+ Q((e) => e.length > 0),
977
+ g((e) => {
963
978
  const n = /* @__PURE__ */ new Map();
964
979
  e.forEach(({ type: r, entities: a }) => {
965
980
  n.has(r) || n.set(r, /* @__PURE__ */ new Set()), a.forEach((c) => n.get(r).add(c));
@@ -976,9 +991,9 @@ class Yt extends Ue {
976
991
  db_checks_sub = new z();
977
992
  db_checks_next$ = this.db_checks_sub.asObservable().pipe(Z(16));
978
993
  db_checks$ = this.db_checks_sub.asObservable().pipe(
979
- pe(() => this.db_checks_next$),
980
- G((e) => e.length > 0),
981
- w((e) => {
994
+ me(() => this.db_checks_next$),
995
+ Q((e) => e.length > 0),
996
+ g((e) => {
982
997
  const n = /* @__PURE__ */ new Map();
983
998
  return e.forEach(({ type: t, changes: r }) => {
984
999
  n.has(t) || n.set(t, /* @__PURE__ */ new Set());
@@ -999,20 +1014,20 @@ class Yt extends Ue {
999
1014
  addQueryCache(e, n = !1) {
1000
1015
  const t = [];
1001
1016
  return e.results.forEach(({ columns: r, rows: a }) => {
1002
- const c = r.findIndex((i) => i === "id"), o = r.findIndex((i) => i === v);
1017
+ const c = r.findIndex((i) => i === "id"), o = r.findIndex((i) => i === O);
1003
1018
  a.forEach((i) => {
1004
1019
  const u = i[c];
1005
1020
  let l;
1006
1021
  if (this.hasEntityRef(u)) {
1007
1022
  if (l = this.getEntityRef(u), t.push(l), n) {
1008
- const _ = ce(this.metadata, r, i);
1009
- this.updateEntity(l, _);
1023
+ const d = ce(this.metadata, r, i);
1024
+ this.updateEntity(l, d);
1010
1025
  }
1011
1026
  } else {
1012
- const _ = ce(this.metadata, r, i);
1013
- l = this.createEntityRef(_), t.push(l);
1027
+ const d = ce(this.metadata, r, i);
1028
+ l = this.createEntityRef(d), t.push(l);
1014
1029
  }
1015
- const h = M(l);
1030
+ const h = L(l);
1016
1031
  h.local = !0, o !== -1 && (h.rowId = BigInt(i[o])), h.modified = !1;
1017
1032
  });
1018
1033
  }), t;
@@ -1021,42 +1036,42 @@ class Yt extends Ue {
1021
1036
  * 创建查询任务
1022
1037
  */
1023
1038
  create_query_task(e) {
1024
- const { sql: n, params: t } = e, r = be(n, t), a = /* @__PURE__ */ new Set();
1039
+ const { sql: n, params: t } = e, r = $e(n, t), a = /* @__PURE__ */ new Set();
1025
1040
  let c = !1;
1026
1041
  const o = new re(), i = o.asObservable(), u = new K(0), l = u.asObservable();
1027
1042
  let h;
1028
1043
  if (this.cache_query_task_map.has(r) === !1) {
1029
- const _ = new Re((p) => (f.observerCount++, h && p.next(h), a.add(p), c || (c = !0, this.queue_tasks.push(f), this.need_run_task.next()), () => {
1044
+ const d = new Ae((p) => (f.observerCount++, h && p.next(h), a.add(p), c || (c = !0, this.queue_tasks.push(f), this.need_run_task.next()), () => {
1030
1045
  if (f.observerCount--, f.observerCount <= 0) {
1031
1046
  o.next(), o.complete(), u.unsubscribe(), o.unsubscribe(), a.delete(p), this.cache_query_task_map.delete(r);
1032
- const m = this.queue_tasks.indexOf(f);
1033
- m >= 0 && this.queue_tasks.splice(m, 1);
1047
+ const E = this.queue_tasks.indexOf(f);
1048
+ E >= 0 && this.queue_tasks.splice(E, 1);
1034
1049
  }
1035
1050
  })), f = {
1036
1051
  sql: n,
1037
1052
  params: t,
1038
1053
  observerCount: 0,
1039
1054
  refreshCount: 0,
1040
- result$: _,
1055
+ result$: d,
1041
1056
  destroy$: i,
1042
1057
  refresh$: l,
1043
1058
  resultEntities: [],
1044
1059
  resultEntityIds: [],
1045
1060
  refresh: () => u.next(f.refreshCount + 1),
1046
1061
  updateResult: (p) => {
1047
- f.result = p, Array.isArray(p) && (f.resultEntities = p, f.resultEntityIds = p.map((m) => m.id));
1062
+ f.result = p, Array.isArray(p) && (f.resultEntities = p, f.resultEntityIds = p.map((E) => E.id));
1048
1063
  },
1049
1064
  next: (p) => {
1050
- h = p, a.forEach((m) => m.next(p));
1065
+ h = p, a.forEach((E) => E.next(p));
1051
1066
  },
1052
- error: (p) => a.forEach((m) => m.error(p))
1067
+ error: (p) => a.forEach((E) => E.error(p))
1053
1068
  };
1054
1069
  return this.cache_query_task_map.set(r, f), f;
1055
1070
  }
1056
1071
  return this.cache_query_task_map.get(r);
1057
1072
  }
1058
1073
  delete_task(e) {
1059
- const n = be(e.sql, e.params);
1074
+ const n = $e(e.sql, e.params);
1060
1075
  this.cache_query_task_map.delete(n);
1061
1076
  }
1062
1077
  /**
@@ -1067,13 +1082,13 @@ class Yt extends Ue {
1067
1082
  if (!e) return;
1068
1083
  const { sql: n, params: t, refresh$: r } = e;
1069
1084
  r.pipe(
1070
- Te(e.destroy$),
1071
- tt(),
1072
- D(() => e.refreshCount++),
1073
- E(
1085
+ Ie(e.destroy$),
1086
+ nt(),
1087
+ W(() => e.refreshCount++),
1088
+ m(
1074
1089
  () => this.client$.pipe(
1075
1090
  ae(1),
1076
- E(() => this.adapter.execute(n, t))
1091
+ m(() => this.adapter.execute(n, t))
1077
1092
  )
1078
1093
  )
1079
1094
  ).subscribe({
@@ -1082,7 +1097,7 @@ class Yt extends Ue {
1082
1097
  });
1083
1098
  }
1084
1099
  }
1085
- class Me extends Yt {
1100
+ class je extends Zt {
1086
1101
  #e = /* @__PURE__ */ new Map();
1087
1102
  constructor(e, n, t) {
1088
1103
  super(e, n, t), this.db_changes$.subscribe((r) => {
@@ -1099,8 +1114,8 @@ class Me extends Yt {
1099
1114
  for (const i of this.cache_query_task_map.values()) {
1100
1115
  if (!i.resultEntityIds || !this.#e.get(i)) return;
1101
1116
  const l = () => setTimeout(() => h.unsubscribe(), 0), h = this.findByRowIds(o, !0).subscribe({
1102
- next: (_) => {
1103
- _.length && this.db_changes_sub.next({ type: c, entities: _ }), l();
1117
+ next: (d) => {
1118
+ d.length && this.db_changes_sub.next({ type: c, entities: d }), l();
1104
1119
  },
1105
1120
  complete: l
1106
1121
  });
@@ -1122,9 +1137,9 @@ class Me extends Yt {
1122
1137
  }
1123
1138
  }, t = te(this.adapter, this.metadata, n), r = this.create_query_task(t), a = this.#s(r, { type: "get", options: n });
1124
1139
  return r.result$.pipe(
1125
- E((c) => a.calculate(c)),
1126
- w((c) => {
1127
- if (c.length === 0) throw new R("not found");
1140
+ m((c) => a.calculate(c)),
1141
+ g((c) => {
1142
+ if (c.length === 0) throw new T("not found");
1128
1143
  return c[0];
1129
1144
  })
1130
1145
  );
@@ -1132,76 +1147,71 @@ class Me extends Yt {
1132
1147
  findOne(e) {
1133
1148
  const n = te(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "findOne", options: e });
1134
1149
  return t.result$.pipe(
1135
- E((a) => r.calculate(a)),
1136
- w((a) => a[0])
1150
+ m((a) => r.calculate(a)),
1151
+ g((a) => a[0])
1137
1152
  );
1138
1153
  }
1139
1154
  findOneOrFail(e) {
1140
1155
  const n = te(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "findOneOrFail", options: e });
1141
1156
  return t.result$.pipe(
1142
- E((a) => r.calculate(a)),
1143
- w((a) => {
1157
+ m((a) => r.calculate(a)),
1158
+ g((a) => {
1144
1159
  if (a.length === 0)
1145
- throw new R("not found");
1160
+ throw new T("not found");
1146
1161
  return a[0];
1147
1162
  })
1148
1163
  );
1149
1164
  }
1150
1165
  find(e) {
1151
- const n = At(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "find", options: e });
1152
- return t.result$.pipe(E((a) => r.calculate(a)));
1166
+ const n = St(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "find", options: e });
1167
+ return t.result$.pipe(m((a) => r.calculate(a)));
1153
1168
  }
1154
1169
  findAll(e) {
1155
1170
  const n = oe(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "findAll", options: e });
1156
- return t.result$.pipe(E((a) => r.calculate(a)));
1171
+ return t.result$.pipe(m((a) => r.calculate(a)));
1157
1172
  }
1158
1173
  findByRowIds(e, n = !1) {
1159
- const t = vt(this.metadata, e), r = this.create_query_task(t);
1160
- return r.result$.pipe(w((a) => this.transform_query_result(r, a, n)));
1174
+ const t = Bt(this.metadata, e), r = this.create_query_task(t);
1175
+ return r.result$.pipe(g((a) => this.transform_query_result(r, a, n)));
1161
1176
  }
1162
1177
  count(e) {
1163
- const n = It(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "count", options: e });
1164
- return t.result$.pipe(E((a) => r.calculate(a)));
1178
+ const n = qt(this.adapter, this.metadata, e), t = this.create_query_task(n), r = this.#s(t, { type: "count", options: e });
1179
+ return t.result$.pipe(m((a) => r.calculate(a)));
1165
1180
  }
1166
1181
  create(e) {
1167
- return g(this.#t(e));
1182
+ return w(this.#t(e));
1168
1183
  }
1169
1184
  update(e, n) {
1170
- return g(this.#r(e, n));
1185
+ return w(this.#n(e, n));
1171
1186
  }
1172
1187
  remove(e) {
1173
- const n = M(e), t = () => {
1188
+ const n = L(e), t = () => {
1174
1189
  this.rxdb.context?.userId && (e.removedBy = this.rxdb.context.userId), n.origin = structuredClone({ ...e }), n.modified = !1, e.removedAt = /* @__PURE__ */ new Date(), n.removed = !0;
1175
1190
  };
1176
1191
  if (n.local === !0) {
1177
- const { sql: a, params: c } = Ft(this.metadata, e, this.rxdb.context), o = this.client$.pipe(
1192
+ const { sql: a, params: c } = Qt(this.metadata, e, this.rxdb.context), o = this.client$.pipe(
1178
1193
  ae(1),
1179
- E(() => this.adapter.execute(a, c)),
1180
- w(() => (t(), e))
1181
- );
1182
- return g(o);
1183
- } else if (n.remote === !0) {
1184
- const { sql: a, params: c } = Wt(this.metadata, e, this.rxdb.context), o = this.#n(a, c).pipe(
1185
- D(() => t()),
1186
- w((i) => i[0])
1194
+ m(() => this.adapter.execute(a, c)),
1195
+ g(() => (t(), e))
1187
1196
  );
1188
- return g(o);
1189
- }
1190
- const r = N(e);
1191
- throw new R(`Remove Error${r.name}(${e.id}) not saved local.`);
1197
+ return w(o);
1198
+ } else
1199
+ t();
1200
+ const r = R(e);
1201
+ throw new T(`Remove Error${r.name}(${e.id}) not saved local.`);
1192
1202
  }
1193
1203
  merge_cache(e, n, t) {
1194
1204
  const r = this.#e.get(n);
1195
1205
  if (r)
1196
1206
  switch (e) {
1197
1207
  case se:
1198
- Pt(n, r, t);
1208
+ Ht(n, r, t);
1199
1209
  break;
1200
1210
  case ne:
1201
- Ht(n, r, t);
1211
+ zt(n, r, t);
1202
1212
  break;
1203
- case V:
1204
- Qt(n, r, t);
1213
+ case P:
1214
+ Jt(n, r, t);
1205
1215
  break;
1206
1216
  }
1207
1217
  }
@@ -1210,12 +1220,12 @@ class Me extends Yt {
1210
1220
  return e.resultEntities = r, e.resultEntityIds = r.map((a) => a.id), r;
1211
1221
  }
1212
1222
  #t(e) {
1213
- const { sql: n, params: t } = Ut(this.metadata, e, this.rxdb.context);
1214
- return this.#n(n, t).pipe(w((r) => r[0]));
1223
+ const { sql: n, params: t } = Gt(this.metadata, e, this.rxdb.context);
1224
+ return this.#a(n, t).pipe(g((r) => r[0]));
1215
1225
  }
1216
- #r(e, n) {
1217
- const { sql: t, params: r } = ke(this.metadata, e, n, this.rxdb.context);
1218
- return this.#n(t, r).pipe(w((a) => a[0]));
1226
+ #n(e, n) {
1227
+ const { sql: t, params: r } = De(this.metadata, e, n, this.rxdb.context);
1228
+ return this.#a(t, r).pipe(g((a) => a[0]));
1219
1229
  }
1220
1230
  #s(e, n) {
1221
1231
  this.#e.set(e, n), e.destroy$.subscribe(() => this.#e.delete(e));
@@ -1236,33 +1246,33 @@ class Me extends Yt {
1236
1246
  e.updateResult(c.results[0].rows[0][0]);
1237
1247
  break;
1238
1248
  }
1239
- return r.pipe(w(() => e.result));
1249
+ return r.pipe(g(() => e.result));
1240
1250
  }, a;
1241
1251
  }
1242
1252
  /**
1243
1253
  * 执行修改语句
1244
1254
  */
1245
- #n(e, n) {
1255
+ #a(e, n) {
1246
1256
  return this.client$.pipe(
1247
1257
  ae(1),
1248
- E(() => this.adapter.execute(e, n)),
1249
- w((t) => this.addQueryCache(t, !0))
1258
+ m(() => this.adapter.execute(e, n)),
1259
+ g((t) => this.addQueryCache(t, !0))
1250
1260
  );
1251
1261
  }
1252
1262
  }
1253
1263
  const j = (s, e) => {
1254
1264
  const n = e.where, t = e.isFindRoot ?? !1, r = e?.level || 0, a = b(s), c = `c.level < ${r}`;
1255
1265
  let o = "";
1256
- const i = [c, n && L(n)].filter(Boolean).join(" AND ");
1266
+ const i = [c, n && C(n)].filter(Boolean).join(" AND ");
1257
1267
  i && (o = `WHERE ${i}`);
1258
1268
  let u = "*";
1259
1269
  return e.count && (e.isFindRoot ? u = "count(*)" : u = "count(*)-1"), {
1260
1270
  sql: `WITH RECURSIVE __children AS (
1261
- SELECT *,rowid as ${v}, 0 AS level
1271
+ SELECT *,rowid as ${O}, 0 AS level
1262
1272
  FROM "${a}"
1263
1273
  WHERE ${t ? "parentId is null" : "id = ?"}
1264
1274
  UNION ALL
1265
- SELECT children.*,children.rowid as ${v}, c.level + 1
1275
+ SELECT children.*,children.rowid as ${O}, c.level + 1
1266
1276
  FROM "${a}" children
1267
1277
  JOIN __children c ON ${e.descendants ? "children.parentId = c.id" : "children.id = c.parentId"}
1268
1278
  ${o}
@@ -1271,34 +1281,34 @@ const j = (s, e) => {
1271
1281
  SELECT ${u} FROM __children ORDER BY level, id;`,
1272
1282
  params: t ? [] : [e.entity && e.entity.id || e.entity]
1273
1283
  };
1274
- }, Jt = (s, e) => j(s, { ...e, isFindRoot: !0, descendants: !0 }), Xt = (s, e) => j(s, { ...e, isFindRoot: !0, descendants: !0, count: !0 }), zt = (s, e) => j(s, { ...e, descendants: !0 }), Zt = (s, e) => j(s, { ...e, descendants: !0, count: !0 }), es = (s, e) => j(s, { ...e, descendants: !1 }), ts = (s, e) => j(s, { ...e, descendants: !1, count: !0 }), de = (s, e, n, t, r) => {
1284
+ }, es = (s, e) => j(s, { ...e, isFindRoot: !0, descendants: !0 }), ts = (s, e) => j(s, { ...e, isFindRoot: !0, descendants: !0, count: !0 }), ss = (s, e) => j(s, { ...e, descendants: !0 }), ns = (s, e) => j(s, { ...e, descendants: !0, count: !0 }), rs = (s, e) => j(s, { ...e, descendants: !1 }), as = (s, e) => j(s, { ...e, descendants: !1, count: !0 }), _e = (s, e, n, t, r) => {
1275
1285
  if (s.length === 0 && e.length === 0) return { refresh: !1, recalculate: !1 };
1276
- const { options: a } = n, c = t.resultEntityIds, o = T(() => r.map((d) => d.id)), i = T(
1277
- () => a?.where ? r.some((d) => Q(d, a.where)) : !0
1278
- ), u = T(
1286
+ const { options: a } = n, c = t.resultEntityIds, o = N(() => r.map((_) => _.id)), i = N(
1287
+ () => a?.where ? r.some((_) => G(_, a.where)) : !0
1288
+ ), u = N(
1279
1289
  () => a.orderBy && r.some(
1280
- (d) => ge(d, t.resultEntities || [], a.orderBy)
1290
+ (_) => Re(_, t.resultEntities || [], a.orderBy)
1281
1291
  )
1282
- ), l = T(() => u() !== !1), h = T(() => i() === !1), _ = T(
1283
- () => c ? c.some((d) => o().includes(d)) : !0
1284
- ), f = T(() => _() === !1), p = {
1292
+ ), l = N(() => u() !== !1), h = N(() => i() === !1), d = N(
1293
+ () => c ? c.some((_) => o().includes(_)) : !0
1294
+ ), f = N(() => d() === !1), p = {
1285
1295
  match_where: i,
1286
1296
  not_match_where: h,
1287
1297
  match_order_by: l,
1288
- result_contains: _,
1298
+ result_contains: d,
1289
1299
  result_not_contains: f
1290
- }, m = e.some(
1291
- (d) => d.every((y) => p[y]())
1300
+ }, E = e.some(
1301
+ (_) => _.every((y) => p[y]())
1292
1302
  );
1293
1303
  return {
1294
- refresh: m === !1 && s.some(
1295
- (d) => d.every((y) => p[y]())
1304
+ refresh: E === !1 && s.some(
1305
+ (_) => _.every((y) => p[y]())
1296
1306
  ),
1297
- recalculate: m
1307
+ recalculate: E
1298
1308
  };
1299
- }, ss = (s, e, n) => {
1309
+ }, cs = (s, e, n) => {
1300
1310
  e.type;
1301
- }, ns = (s, e, n) => {
1311
+ }, os = (s, e, n) => {
1302
1312
  const t = [], r = [];
1303
1313
  switch (e.type) {
1304
1314
  case "countRoot":
@@ -1312,11 +1322,11 @@ SELECT ${u} FROM __children ORDER BY level, id;`,
1312
1322
  t.push(["match_where"]);
1313
1323
  break;
1314
1324
  }
1315
- const a = de(t, r, e, s, n);
1316
- a.refresh ? s.refresh() : a.recalculate && ss(s, e);
1317
- }, rs = (s, e, n) => {
1325
+ const a = _e(t, r, e, s, n);
1326
+ a.refresh ? s.refresh() : a.recalculate && cs(s, e);
1327
+ }, is = (s, e, n) => {
1318
1328
  e.type;
1319
- }, as = (s, e, n) => {
1329
+ }, ls = (s, e, n) => {
1320
1330
  const t = [], r = [];
1321
1331
  switch (e.type) {
1322
1332
  case "countRoot":
@@ -1330,11 +1340,11 @@ SELECT ${u} FROM __children ORDER BY level, id;`,
1330
1340
  t.push(["match_where"]);
1331
1341
  break;
1332
1342
  }
1333
- const a = de(t, r, e, s, n);
1334
- a.refresh ? s.refresh() : a.recalculate && rs(s, e);
1335
- }, cs = (s, e, n) => {
1343
+ const a = _e(t, r, e, s, n);
1344
+ a.refresh ? s.refresh() : a.recalculate && is(s, e);
1345
+ }, us = (s, e, n) => {
1336
1346
  e.type;
1337
- }, os = (s, e, n) => {
1347
+ }, hs = (s, e, n) => {
1338
1348
  const t = [], r = [];
1339
1349
  switch (e.type) {
1340
1350
  case "countRoot":
@@ -1348,34 +1358,34 @@ SELECT ${u} FROM __children ORDER BY level, id;`,
1348
1358
  t.push(["match_where"]);
1349
1359
  break;
1350
1360
  }
1351
- const a = de(t, r, e, s, n);
1352
- a.refresh ? s.refresh() : a.recalculate && cs(s, e);
1361
+ const a = _e(t, r, e, s, n);
1362
+ a.refresh ? s.refresh() : a.recalculate && us(s, e);
1353
1363
  };
1354
- class is extends Me {
1364
+ class ds extends je {
1355
1365
  #e = /* @__PURE__ */ new Map();
1356
1366
  findRoot(e) {
1357
- const n = Jt(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findRoot", options: e });
1358
- return t.result$.pipe(E((a) => r.calculate(a)));
1367
+ const n = es(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findRoot", options: e });
1368
+ return t.result$.pipe(m((a) => r.calculate(a)));
1359
1369
  }
1360
1370
  countRoot(e) {
1361
- const n = Xt(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countRoot", options: e });
1362
- return t.result$.pipe(E((a) => r.calculate(a)));
1371
+ const n = ts(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countRoot", options: e });
1372
+ return t.result$.pipe(m((a) => r.calculate(a)));
1363
1373
  }
1364
1374
  findDescendants(e) {
1365
- const n = zt(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findDescendants", options: e });
1366
- return t.result$.pipe(E((a) => r.calculate(a)));
1375
+ const n = ss(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findDescendants", options: e });
1376
+ return t.result$.pipe(m((a) => r.calculate(a)));
1367
1377
  }
1368
1378
  countDescendants(e) {
1369
- const n = Zt(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countDescendants", options: e });
1370
- return t.result$.pipe(E((a) => r.calculate(a)));
1379
+ const n = ns(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countDescendants", options: e });
1380
+ return t.result$.pipe(m((a) => r.calculate(a)));
1371
1381
  }
1372
1382
  findAncestors(e) {
1373
- const n = es(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findAncestors", options: e });
1374
- return t.result$.pipe(E((a) => r.calculate(a)));
1383
+ const n = rs(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "findAncestors", options: e });
1384
+ return t.result$.pipe(m((a) => r.calculate(a)));
1375
1385
  }
1376
1386
  countAncestors(e) {
1377
- const n = ts(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countAncestors", options: e });
1378
- return t.result$.pipe(E((a) => r.calculate(a)));
1387
+ const n = as(this.metadata, e), t = this.create_query_task(n), r = this.#t(t, { type: "countAncestors", options: e });
1388
+ return t.result$.pipe(m((a) => r.calculate(a)));
1379
1389
  }
1380
1390
  /**
1381
1391
  * 根据 type 计算主动更新缓存策略
@@ -1386,13 +1396,13 @@ class is extends Me {
1386
1396
  if (r)
1387
1397
  switch (e) {
1388
1398
  case "create":
1389
- ns(n, r, t);
1399
+ os(n, r, t);
1390
1400
  break;
1391
1401
  case "update":
1392
- os(n, r, t);
1402
+ hs(n, r, t);
1393
1403
  break;
1394
1404
  case "remove":
1395
- as(n, r, t);
1405
+ ls(n, r, t);
1396
1406
  break;
1397
1407
  }
1398
1408
  }
@@ -1415,113 +1425,110 @@ class is extends Me {
1415
1425
  e.updateResult(c.results[0].rows[0][0]);
1416
1426
  break;
1417
1427
  }
1418
- return r.pipe(w(() => e.result));
1428
+ return r.pipe(g(() => e.result));
1419
1429
  }, a;
1420
1430
  }
1421
1431
  }
1422
- class bs extends He {
1432
+ class Ts extends ze {
1423
1433
  constructor(e, n) {
1424
1434
  super(e), this.options = n;
1425
1435
  const t = (r) => {
1426
1436
  const { tableName: a, rowIds: c, recordAt: o } = r, [i, u] = a.split("$"), l = this.rxdb.schemaManager.getEntityType(u, i);
1427
1437
  if (!l) return;
1428
- const h = {
1429
- rowIds: c,
1430
- recordAt: o
1431
- };
1432
- setTimeout(() => {
1433
- switch (r.type) {
1434
- case P.SQLITE_DELETE:
1435
- this.rxdb.dispatchEvent(new ze(l, h));
1436
- break;
1437
- case P.SQLITE_INSERT:
1438
- this.rxdb.dispatchEvent(new Xe(l, h));
1439
- break;
1440
- case P.SQLITE_UPDATE:
1441
- this.rxdb.dispatchEvent(new Je(l, h));
1442
- break;
1443
- }
1444
- }, 100);
1438
+ const h = { rowIds: c, recordAt: o };
1439
+ switch (r.type) {
1440
+ case D.SQLITE_DELETE:
1441
+ this.rxdb.dispatchEvent(new st(l, h));
1442
+ break;
1443
+ case D.SQLITE_INSERT:
1444
+ this.rxdb.dispatchEvent(new tt(l, h));
1445
+ break;
1446
+ case D.SQLITE_UPDATE:
1447
+ this.rxdb.dispatchEvent(new et(l, h));
1448
+ break;
1449
+ }
1445
1450
  };
1446
- this.#c.subscribe((r) => r.onChange = Ze(t)), this.#_.pipe(Te(this.#e)).subscribe();
1451
+ this.#c.subscribe((r) => {
1452
+ r.addEventListener(D.SQLITE_INSERT, X(t)), r.addEventListener(D.SQLITE_DELETE, X(t)), r.addEventListener(D.SQLITE_UPDATE, X(t));
1453
+ }), this.#_.pipe(Ie(this.#e)).subscribe();
1447
1454
  }
1448
1455
  #e = new re();
1449
1456
  #t = /* @__PURE__ */ new Map();
1450
- #r;
1457
+ #n;
1451
1458
  #s = !1;
1452
1459
  // 查询缓存
1453
- #n = [];
1454
- #a = /* @__PURE__ */ new Map();
1460
+ #a = [];
1461
+ #r = /* @__PURE__ */ new Map();
1455
1462
  #o = !1;
1456
1463
  #i = new K(0);
1457
1464
  #h = this.#i.asObservable();
1458
1465
  // sqlite 客户端
1459
- #c = new Re((e) => {
1460
- const { vfs: n, async: t, worker: r, wasmPath: a, locateFile: c, workerInstance: o } = this.options, i = {
1466
+ #c = new Ae((e) => {
1467
+ const { vfs: n, async: t, worker: r, wasmPath: a, locateFile: c, workerInstance: o, sharedWorkerInstance: i, sharedWorker: u } = this.options, l = {
1461
1468
  vfs: n,
1462
1469
  async: t,
1463
1470
  worker: r,
1464
1471
  wasmPath: a,
1465
1472
  locateFile: c
1466
1473
  };
1467
- Ce(i);
1468
- let u;
1469
- r && o ? u = et(o) : u = new jt(), this.#r = u, u.init(this.rxdb.options.dbName, i).then(() => e.next(u));
1474
+ Ce(l);
1475
+ let h;
1476
+ r && o ? h = Ee(o) : u && i ? h = Ee(i.port) : h = new Pt(), this.#n = h, h.init(this.rxdb.options.dbName, l).then(() => e.next(h));
1470
1477
  }).pipe(U(1));
1471
1478
  // 已连接
1472
- #d = st(() => this.rxdb.connect(this.name)).pipe(U(1));
1479
+ #d = rt(() => this.rxdb.connect(this.name)).pipe(U(1));
1473
1480
  // 队列
1474
1481
  #_ = this.#h.pipe(
1475
- G(() => this.#o === !1),
1476
- w(() => this.#n.shift()),
1477
- G(Boolean),
1478
- D(() => this.#o = !0),
1479
- E((e) => {
1480
- const n = this.#a.get(e.key);
1482
+ Q(() => this.#o === !1),
1483
+ g(() => this.#a.shift()),
1484
+ Q(Boolean),
1485
+ W(() => this.#o = !0),
1486
+ m((e) => {
1487
+ const n = this.#r.get(e.key);
1481
1488
  return this.#d.pipe(
1482
- E(() => this.#c),
1483
- E((t) => t.execute(e.sql, e.bindings)),
1484
- D((t) => n.next(t)),
1485
- D(
1489
+ m(() => this.#c),
1490
+ m((t) => t.execute(e.sql, e.bindings)),
1491
+ W((t) => n.next(t)),
1492
+ W(
1486
1493
  () => setTimeout(() => {
1487
- this.#a.get(e.key)?.unsubscribe(), this.#a.delete(e.key);
1494
+ this.#r.get(e.key)?.unsubscribe(), this.#r.delete(e.key);
1488
1495
  }, 0)
1489
1496
  ),
1490
- nt((t) => {
1497
+ at((t) => {
1491
1498
  const r = t.message || "执行错误";
1492
- return n.error(new R(`${r} ${e.sql} ${JSON.stringify(e.bindings)}`)), rt({ error: t });
1499
+ return n.error(new T(`${r} ${e.sql} ${JSON.stringify(e.bindings)}`)), ct({ error: t });
1493
1500
  })
1494
1501
  );
1495
1502
  }),
1496
- D(() => {
1503
+ W(() => {
1497
1504
  this.#o = !1, this.#l();
1498
1505
  })
1499
1506
  );
1500
- name = St;
1507
+ name = Mt;
1501
1508
  /**
1502
1509
  * 数据库版本
1503
1510
  */
1504
1511
  version$ = this.#c.pipe(
1505
- E((e) => me(e.version())),
1512
+ m((e) => ye(e.version())),
1506
1513
  U(1)
1507
1514
  );
1508
1515
  /**
1509
1516
  * 连接 wab sqlite
1510
1517
  */
1511
1518
  connect() {
1512
- return this.#c.pipe(w(() => this));
1519
+ return this.#c.pipe(g(() => this));
1513
1520
  }
1514
1521
  /**
1515
1522
  * 断开连接
1516
1523
  */
1517
1524
  async disconnect() {
1518
- this.#r && (await this.#r.disconnect(), this.#e.next(), this.#e.complete());
1525
+ this.#n && (await this.#n.disconnect(), this.#e.next(), this.#e.complete());
1519
1526
  }
1520
1527
  /**
1521
1528
  * 获取版本
1522
1529
  */
1523
1530
  version() {
1524
- return g(this.version$);
1531
+ return w(this.version$);
1525
1532
  }
1526
1533
  /**
1527
1534
  * 获取实体仓库
@@ -1529,17 +1536,17 @@ class bs extends He {
1529
1536
  */
1530
1537
  getRepository(e) {
1531
1538
  if (!this.#t.has(e)) {
1532
- const n = N(e);
1539
+ const n = R(e);
1533
1540
  let t;
1534
1541
  switch (n.repository) {
1535
1542
  case "Repository":
1536
- t = new Me(this, this.#c, e);
1543
+ t = new je(this, this.#c, e);
1537
1544
  break;
1538
1545
  case "TreeRepository":
1539
- t = new is(this, this.#c, e);
1546
+ t = new ds(this, this.#c, e);
1540
1547
  break;
1541
1548
  default:
1542
- throw new R("Unsupported repository type: " + n.repository);
1549
+ throw new T("Unsupported repository type: " + n.repository);
1543
1550
  }
1544
1551
  return this.#t.set(e, t), t;
1545
1552
  }
@@ -1551,22 +1558,30 @@ class bs extends He {
1551
1558
  * @param entities
1552
1559
  */
1553
1560
  async saveMany(e) {
1554
- return this.#s ? await ye(this, e) : e.length > 1 ? await this.transaction(() => ye(this, e)) : e.length === 1 && await e[0].save(), e;
1561
+ return this.#s ? await ge(this, e) : e.length > 1 ? await this.transaction(() => ge(this, e)) : e.length === 1 && await e[0].save(), e;
1562
+ }
1563
+ /**
1564
+ * 删除多个实例
1565
+ * @param entities
1566
+ * @returns
1567
+ */
1568
+ async removeMany(e) {
1569
+ return this.#s ? await be(this, e) : e.length > 1 ? await this.transaction(() => be(this, e)) : e.length === 1 && await e[0].save(), e;
1555
1570
  }
1556
1571
  /**
1557
1572
  * 判断表是否存在
1558
1573
  * @param EntityType
1559
1574
  */
1560
1575
  isTableExisted(e) {
1561
- return g(this.isTableExisted$(e));
1576
+ return w(this.isTableExisted$(e));
1562
1577
  }
1563
1578
  /**
1564
1579
  * 判断表是否存在
1565
1580
  * @param EntityType
1566
1581
  */
1567
1582
  isTableExisted$(e) {
1568
- const n = N(e), t = b(n);
1569
- return this.#u(ht(t)).pipe(w((r) => dt(r) === !1));
1583
+ const n = R(e), t = b(n);
1584
+ return this.#u(pt(t)).pipe(g((r) => Et(r) === !1));
1570
1585
  }
1571
1586
  /**
1572
1587
  * 创建表和初始化数据
@@ -1575,8 +1590,8 @@ class bs extends He {
1575
1590
  * @returns
1576
1591
  */
1577
1592
  createTables(e, n) {
1578
- const t = gt(this, e, n);
1579
- return g(this.#u(t).pipe(w(() => !0)));
1593
+ const t = Nt(this, e, n);
1594
+ return w(this.#u(t).pipe(g(() => !0)));
1580
1595
  }
1581
1596
  /**
1582
1597
  * 创建分支
@@ -1584,7 +1599,7 @@ class bs extends He {
1584
1599
  * @param fromChangeId
1585
1600
  */
1586
1601
  async createBranch(e, n) {
1587
- return Et(this, e, n);
1602
+ return gt(this, e, n);
1588
1603
  }
1589
1604
  /**
1590
1605
  * 切换分支
@@ -1592,7 +1607,7 @@ class bs extends He {
1592
1607
  * @returns
1593
1608
  */
1594
1609
  async switchBranch(e) {
1595
- return xt(this, e);
1610
+ return Lt(this, e);
1596
1611
  }
1597
1612
  /**
1598
1613
  * 恢复某个实体
@@ -1609,27 +1624,27 @@ class bs extends He {
1609
1624
  */
1610
1625
  execute(e, n) {
1611
1626
  const t = e + n?.join(",");
1612
- if (!this.#a.has(t)) {
1627
+ if (!this.#r.has(t)) {
1613
1628
  const r = new re(1);
1614
- this.#a.set(t, r), this.#n.push({ key: t, sql: e, bindings: n }), this.#l();
1629
+ this.#r.set(t, r), this.#a.push({ key: t, sql: e, bindings: n }), this.#l();
1615
1630
  }
1616
- return this.#a.get(t).asObservable();
1631
+ return this.#r.get(t).asObservable();
1617
1632
  }
1618
1633
  /**
1619
1634
  * 处理事务
1620
1635
  * @param callback
1621
1636
  */
1622
1637
  transaction(e) {
1623
- return g(this.transaction$(e));
1638
+ return w(this.transaction$(e));
1624
1639
  }
1625
1640
  transaction$(e, n = !0) {
1626
1641
  return this.rxdb.connect(this.name).pipe(
1627
- E(() => this.#c),
1628
- E(async (t) => {
1629
- this.#s = !0, this.rxdb.dispatchEvent(ls);
1642
+ m(() => this.#c),
1643
+ m(async (t) => {
1644
+ this.#s = !0, this.rxdb.dispatchEvent(_s);
1630
1645
  let r = "", a = "";
1631
1646
  if (n) {
1632
- const c = Ye(), o = (i) => `INSERT INTO "public$RxDBChange" (type,branchId,transactionId) VALUES ('${i}','main','${c}');`;
1647
+ const c = Ze(), o = (i) => `INSERT INTO "public$RxDBChange" (type,branchId,transactionId) VALUES ('${i}','main','${c}');`;
1633
1648
  r = o("TRANSACTION_BEGIN"), a = o("TRANSACTION_COMMIT");
1634
1649
  }
1635
1650
  await t.execute(`
@@ -1640,11 +1655,11 @@ class bs extends He {
1640
1655
  try {
1641
1656
  const c = await e();
1642
1657
  return await t.execute(`${a}
1643
- COMMIT;`), this.#s = !1, this.rxdb.dispatchEvent(hs), c;
1658
+ COMMIT;`), this.#s = !1, this.rxdb.dispatchEvent(ps), c;
1644
1659
  } catch (c) {
1645
- await t.execute("ROLLBACK"), this.#s = !1, this.rxdb.dispatchEvent(us);
1660
+ await t.execute("ROLLBACK"), this.#s = !1, this.rxdb.dispatchEvent(fs);
1646
1661
  const o = c?.message || "Transaction Error";
1647
- throw new R(o);
1662
+ throw new T(o);
1648
1663
  }
1649
1664
  })
1650
1665
  );
@@ -1659,7 +1674,7 @@ COMMIT;`), this.#s = !1, this.rxdb.dispatchEvent(hs), c;
1659
1674
  * 本地变更仓库
1660
1675
  */
1661
1676
  localRxDBChange() {
1662
- return this.getRepository(we);
1677
+ return this.getRepository(Te);
1663
1678
  }
1664
1679
  #l() {
1665
1680
  this.#i.next(this.#i.value + 1);
@@ -1670,14 +1685,14 @@ COMMIT;`), this.#s = !1, this.rxdb.dispatchEvent(hs), c;
1670
1685
  * @param bindings
1671
1686
  */
1672
1687
  #u(e, n) {
1673
- return this.#c.pipe(E((t) => me(t.execute(e, n))));
1688
+ return this.#c.pipe(m((t) => ye(t.execute(e, n))));
1674
1689
  }
1675
1690
  }
1676
- const ls = new Ge(), us = new Qe(), hs = new Ke();
1691
+ const _s = new Ye(), fs = new Je(), ps = new Xe();
1677
1692
  export {
1678
- bs as RxDBAdapterSqlite,
1679
- R as RxdbAdapterSqliteError,
1680
- jt as SqliteClient,
1681
- kt as WA_SQLITE_VFS_LIST,
1682
- Ct as sqliteLoad
1693
+ Ts as RxDBAdapterSqlite,
1694
+ T as RxdbAdapterSqliteError,
1695
+ Pt as SqliteClient,
1696
+ jt as WA_SQLITE_VFS_LIST,
1697
+ Ft as sqliteLoad
1683
1698
  };