@aiao/rxdb-adapter-sqlite 0.0.9 → 0.0.10

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 { getEntityMetadata as w, PropertyType as y, RelationKind as S, isRuleGroup as ce, getEntityStatus as C, RepositoryBase as De, RxDBChange as P, EntityLocalCreatedEvent as k, EntityLocalRemovedEvent as ne, EntityLocalUpdatedEvent as K, parseRxDBChangeKey as J, RxDBBranch as W, getEntityType as Y, TransactionBeginEvent as je, TransactionRollbackEvent as Pe, TransactionCommitEvent as Fe, RxDBAdapterLocalBase as Be, getEntityMutations as le, uuid as ke } from "@aiao/rxdb";
2
- import { pickBy as me, isString as We, isNil as Ue, traverseObjectKeys as Ve, EventDispatcher as He, AsyncQueueExecutor as ye, get as Qe, isFunction as de } from "@aiao/utils";
3
- import { wrap as ue, proxy as Ke } from "comlink";
4
- import ge from "object-hash";
5
- import { defer as X, of as z, from as Z, map as Ge } from "rxjs";
6
- import { Factory as Je, SQLITE_ROW as Ye, SQLITE_UTF8 as $e, SQLITE_DETERMINISTIC as Te } from "wa-sqlite";
7
- const Xe = (e) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${e}' limit 1;`, ze = (e) => !!e.sql && (e.results.length === 0 || e.results[0].rows.length === 0), L = "__rowid", Ze = (e) => {
1
+ import { getEntityMetadata as w, PropertyType as y, RelationKind as A, isRuleGroup as ce, getEntityStatus as C, RepositoryBase as je, RxDBChange as F, EntityLocalCreatedEvent as k, EntityLocalRemovedEvent as ne, EntityLocalUpdatedEvent as K, parseRxDBChangeKey as J, RxDBBranch as W, getEntityType as Y, TransactionBeginEvent as Fe, TransactionRollbackEvent as Pe, TransactionCommitEvent as Be, RxDBAdapterLocalBase as ke, getEntityMutations as le, uuid as We } from "@aiao/rxdb";
2
+ import { pickBy as ye, isString as Ue, isNil as Ve, traverseObjectKeys as He, EventDispatcher as Qe, AsyncQueueExecutor as ge, get as Ke, isFunction as de } from "@aiao/utils";
3
+ import { wrap as ue, proxy as Ge } from "comlink";
4
+ import $e from "object-hash";
5
+ import { defer as X, of as z, from as Z, map as Je } from "rxjs";
6
+ import { Factory as Ye, SQLITE_ROW as Xe, SQLITE_UTF8 as Te, SQLITE_DETERMINISTIC as we } from "wa-sqlite";
7
+ const ze = (e) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${e}' limit 1;`, Ze = (e) => !!e.sql && (e.results.length === 0 || e.results[0].rows.length === 0), L = "__rowid", et = (e) => {
8
8
  switch (e.type) {
9
9
  case y.uuid:
10
10
  case y.string:
@@ -68,10 +68,10 @@ const Xe = (e) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${e}
68
68
  default:
69
69
  return e;
70
70
  }
71
- }, q = (e, t) => `${t}$${e}`, et = (e) => {
71
+ }, q = (e, t) => `${t}$${e}`, tt = (e) => {
72
72
  const t = e.indexOf("$");
73
73
  return t === -1 ? ["", e] : [e.substring(0, t), e.substring(t + 1)];
74
- }, A = (e) => q(e.name, e.namespace), he = (e) => A(w(e)), pe = (e, t) => `idx_${e.name}_${t.name}`;
74
+ }, S = (e) => q(e.name, e.namespace), he = (e) => S(w(e)), pe = (e, t) => `idx_${e.name}_${t.name}`;
75
75
  class b extends Error {
76
76
  constructor(t) {
77
77
  super(t), this.name = "RxDBAdapterSqliteError", Object.setPrototypeOf(this, b.prototype);
@@ -89,13 +89,13 @@ const re = (e, t) => {
89
89
  i && (n[a] = se(t[a], i));
90
90
  }
91
91
  return n;
92
- }, we = (e, t) => me(t, (n, s) => e.propertyMap.has(s) || e.foreignKeyNames.includes(s)), tt = (e, t) => me(t, (n, s) => {
92
+ }, Ne = (e, t) => ye(t, (n, s) => e.propertyMap.has(s) || e.foreignKeyNames.includes(s)), nt = (e, t) => ye(t, (n, s) => {
93
93
  const r = e.propertyMap.get(s);
94
94
  if (r)
95
95
  return r.readonly !== !0;
96
96
  const a = e.foreignKeyRelationMap.get(s);
97
97
  return a ? a.readonly !== !0 : e.computedPropertyMap.has(s) === !1;
98
- }), R = (e) => We(e) ? `'${e.replaceAll("'", "''")}'` : Ue(e) ? "NULL" : e, F = (e, t = []) => e.replace(/\?/g, () => R(t.shift())), ee = (e, t, n) => {
98
+ }), R = (e) => Ue(e) ? `'${e.replaceAll("'", "''")}'` : Ve(e) ? "NULL" : e, P = (e, t = []) => e.replace(/\?/g, () => R(t.shift())), ee = (e, t, n) => {
99
99
  const s = {};
100
100
  return n.forEach((r, a) => {
101
101
  const i = t[a];
@@ -107,7 +107,7 @@ const re = (e, t) => {
107
107
  c ? s[i] = D(r, c) : console.log(`Property ${i}=${r} not found in metadata ${e.name}`);
108
108
  }
109
109
  }), s;
110
- }, N = "_", nt = {
110
+ }, N = "_", st = {
111
111
  "=": "=",
112
112
  "!=": "!=",
113
113
  ">": ">",
@@ -124,12 +124,12 @@ const re = (e, t) => {
124
124
  notStartsWith: "NOT LIKE",
125
125
  endsWith: "LIKE",
126
126
  notEndsWith: "NOT LIKE"
127
- }, st = (e, t) => {
127
+ }, fe = (e, t) => {
128
128
  if (t) return t;
129
129
  if (!e.includes(".")) return `${N}."${e}"`;
130
130
  const n = e.lastIndexOf("."), s = e.slice(0, n), r = e.slice(n + 1);
131
131
  return `"${s}"."${r}"`;
132
- }, Ne = (e) => {
132
+ }, Se = (e) => {
133
133
  const { operator: t, value: n } = e;
134
134
  switch (t) {
135
135
  case "in":
@@ -150,7 +150,7 @@ const re = (e, t) => {
150
150
  default:
151
151
  return it(n);
152
152
  }
153
- }, rt = (e) => nt[e] || e, U = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, at = (e) => !Array.isArray(e) || !e.length ? "(NULL)" : `(${e.map(R).join(", ")})`, ot = (e) => {
153
+ }, rt = (e) => st[e] || e, U = (e, t, n) => e.length === 1 ? n.name : `${t}_${n.name}`, at = (e) => !Array.isArray(e) || !e.length ? "(NULL)" : `(${e.map(R).join(", ")})`, ot = (e) => {
154
154
  if (!Array.isArray(e) || e.length < 2) return "";
155
155
  const [t, n] = e;
156
156
  if (t == null || n == null) return "";
@@ -169,7 +169,7 @@ const re = (e, t) => {
169
169
  }, lt = (e, t, n) => {
170
170
  const s = e.propertyMap.get(t);
171
171
  if (!s || s.type !== y.stringArray && s.type !== y.numberArray) return null;
172
- const r = Ne(n), a = `EXISTS (SELECT 1 FROM json_each(${N}."${t}") WHERE json_each.value IN ${r})`;
172
+ const r = Se(n), a = `EXISTS (SELECT 1 FROM json_each(${N}."${t}") WHERE json_each.value IN ${r})`;
173
173
  return n.operator === "notIn" ? `NOT ${a}` : a;
174
174
  }, dt = (e, t, n, s, r) => {
175
175
  if (n && s && r && (e.operator === "exists" || e.operator === "notExists")) {
@@ -181,7 +181,11 @@ const re = (e, t) => {
181
181
  });
182
182
  if (u !== null) return u;
183
183
  }
184
- const a = e.value === null, i = a ? "" : rt(e.operator).toLowerCase(), c = a ? e.operator === "=" ? "IS NULL" : e.operator === "!=" ? "IS NOT NULL" : "" : Ne(e);
184
+ if (e.operator === "null" || e.operator === "notNull") {
185
+ const d = String(e.field), u = t.get(d), p = fe(d, u);
186
+ return e.operator === "null" ? `${p} IS NULL` : `${p} IS NOT NULL`;
187
+ }
188
+ const a = e.value === null, i = a ? "" : rt(e.operator).toLowerCase(), c = a ? e.operator === "=" ? "IS NULL" : e.operator === "!=" ? "IS NOT NULL" : "" : Se(e);
185
189
  if (!c && ["in", "notIn", "between", "notBetween"].includes(e.operator)) return "";
186
190
  const o = String(e.field), l = t.get(o);
187
191
  if (n && !o.includes(".") && (e.operator === "contains" || e.operator === "notContains")) {
@@ -192,9 +196,9 @@ const re = (e, t) => {
192
196
  const d = lt(n, o, e);
193
197
  if (d !== null) return d;
194
198
  }
195
- return `${st(o, l)} ${i} ${c}`.replace(/\s+/g, " ").trim();
199
+ return `${fe(o, l)} ${i} ${c}`.replace(/\s+/g, " ").trim();
196
200
  }, ae = (e) => e === N ? e : `"${e}"`, ut = (e, t, n) => {
197
- if (e.kind !== S.ONE_TO_MANY)
201
+ if (e.kind !== A.ONE_TO_MANY)
198
202
  throw new Error("_build_one_to_many_exists requires ONE_TO_MANY relation");
199
203
  const s = q(t.name, t.namespace), r = "child", a = `${e.mappedProperty}Id`;
200
204
  let i = `EXISTS (SELECT 1 FROM "${s}" "${r}"`;
@@ -259,16 +263,16 @@ const re = (e, t) => {
259
263
  e.where && s && (i = s(e.where, a));
260
264
  let c;
261
265
  switch (r.kind) {
262
- case S.ONE_TO_MANY:
266
+ case A.ONE_TO_MANY:
263
267
  c = ut(r, a, i);
264
268
  break;
265
- case S.MANY_TO_ONE:
269
+ case A.MANY_TO_ONE:
266
270
  c = ht(r, a, i);
267
271
  break;
268
- case S.ONE_TO_ONE:
272
+ case A.ONE_TO_ONE:
269
273
  c = pt(t, r, a, n, i);
270
274
  break;
271
- case S.MANY_TO_MANY:
275
+ case A.MANY_TO_MANY:
272
276
  c = ft(t, r, a, i);
273
277
  break;
274
278
  }
@@ -276,7 +280,7 @@ const re = (e, t) => {
276
280
  }, V = (e, t) => {
277
281
  if (e.relationAliasMap.has(t))
278
282
  return e.relationAliasMap.get(t);
279
- const n = t.includes("_") ? t : t.split("_")[0], s = Se(e, n);
283
+ const n = t.includes("_") ? t : t.split("_")[0], s = be(e, n);
280
284
  return e.relationAliasMap.set(t, s), s;
281
285
  }, _t = (e, t, n, s) => {
282
286
  const r = n.slice(0, s);
@@ -308,10 +312,10 @@ const re = (e, t) => {
308
312
  n.forEach(({ metadata: r, relation: a }, i) => {
309
313
  let c = e.rxdb.schemaManager.findMappedRelation(r, a);
310
314
  if (!c)
311
- if ((a.kind === S.ONE_TO_MANY || a.kind === S.MANY_TO_MANY) && "mappedProperty" in a) {
315
+ if ((a.kind === A.ONE_TO_MANY || a.kind === A.MANY_TO_MANY) && "mappedProperty" in a) {
312
316
  const d = r.relationMap.get(a.mappedProperty);
313
317
  d && (c = { metadata: r, relation: d });
314
- } else (a.kind === S.MANY_TO_ONE || a.kind === S.ONE_TO_ONE) && (c = { metadata: r, relation: a });
318
+ } else (a.kind === A.MANY_TO_ONE || a.kind === A.ONE_TO_ONE) && (c = { metadata: r, relation: a });
315
319
  if (!c) throw new b("mappedRelation not found");
316
320
  const o = U(n, s, a), l = V(t, o);
317
321
  let h = N;
@@ -320,14 +324,14 @@ const re = (e, t) => {
320
324
  h = V(t, u);
321
325
  }
322
326
  switch (a.kind) {
323
- case S.ONE_TO_MANY:
327
+ case A.ONE_TO_MANY:
324
328
  yt(t, c, l, h);
325
329
  break;
326
- case S.ONE_TO_ONE:
327
- case S.MANY_TO_ONE:
330
+ case A.ONE_TO_ONE:
331
+ case A.MANY_TO_ONE:
328
332
  gt(t, c, l, h, a);
329
333
  break;
330
- case S.MANY_TO_MANY:
334
+ case A.MANY_TO_MANY:
331
335
  $t(e, t, c, l, h, a);
332
336
  break;
333
337
  }
@@ -345,7 +349,7 @@ const re = (e, t) => {
345
349
  on: i
346
350
  });
347
351
  }, $t = (e, t, n, s, r, a) => {
348
- const i = w(a.junctionEntityType), c = H(t, i), o = Se(t, `${a.name}_m_n`), l = `"${o}".${n.relation.name}Id = ${ae(r)}.id`;
352
+ const i = w(a.junctionEntityType), c = H(t, i), o = be(t, `${a.name}_m_n`), l = `"${o}".${n.relation.name}Id = ${ae(r)}.id`;
349
353
  c.find(
350
354
  (f) => f.joinTableName === o && f.on === l
351
355
  ) || c.push({
@@ -357,7 +361,7 @@ const re = (e, t) => {
357
361
  joinTableName: s,
358
362
  on: u
359
363
  });
360
- }, H = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), Se = (e, t) => {
364
+ }, H = (e, t) => (e.joinMap.has(t) || e.joinMap.set(t, []), e.joinMap.get(t)), be = (e, t) => {
361
365
  let n = t, s = 1;
362
366
  for (; e.usedAliases.has(n); )
363
367
  n = `${t}_${s}`, s++;
@@ -371,26 +375,26 @@ const re = (e, t) => {
371
375
  (a) => ce(a) ? B(a, t, n, s) : dt(a, t, n, s, B)
372
376
  ).filter(Boolean);
373
377
  return r.length ? r.length === 1 ? r[0] : `(${r.join(ce(e) ? ` ${e.combinator} ` : " ")})` : "";
374
- }, be = (e) => {
378
+ }, Re = (e) => {
375
379
  const { tableName: t, where: n, limit: s, offset: r, orderBy: a, join: i, hasJoin: c, metadata: o } = e;
376
380
  let l = `${N}.rowid as ${L}, ${N}.*`;
377
381
  o.features?.tree?.hasChildren && o.features?.tree?.type === "adjacency-list" && (l += `, EXISTS(SELECT 1 FROM "${t}" __sub WHERE __sub."parentId" = ${N}."id") AS "hasChildren"`);
378
382
  const h = [`SELECT ${c ? "DISTINCT " : ""}${l} FROM "${t}" ${N}`];
379
383
  return i && h.push(i), n && h.push(` WHERE ${n}`), a && h.push(` ORDER BY ${a}`), s && h.push(` LIMIT ${s}`), r && h.push(` OFFSET ${r}`), h.join("") + ";";
380
- }, Re = (e, t, n) => {
384
+ }, Ie = (e, t, n) => {
381
385
  const s = {
382
386
  joinMap: /* @__PURE__ */ new Map(),
383
387
  usedAliases: /* @__PURE__ */ new Set(),
384
388
  fieldAliasMap: /* @__PURE__ */ new Map(),
385
389
  relationAliasMap: /* @__PURE__ */ new Map()
386
390
  };
387
- Ve(n, (a, i, c) => {
391
+ He(n, (a, i, c) => {
388
392
  const o = i;
389
393
  a !== "field" || !o.includes(".") || Nt(e, s, t, o, c);
390
394
  });
391
395
  const r = [];
392
396
  for (const [a, i] of s.joinMap.entries()) {
393
- const c = A(a);
397
+ const c = S(a);
394
398
  for (const o of i)
395
399
  r.push(` LEFT JOIN "${c}" "${o.joinTableName}" ON ${o.on}`);
396
400
  }
@@ -425,14 +429,14 @@ const re = (e, t) => {
425
429
  } catch {
426
430
  }
427
431
  wt(t, n, s, a) || mt(e, t, n, s, a);
428
- }, At = (e, t) => {
429
- const n = A(e), s = [t.id];
432
+ }, St = (e, t) => {
433
+ const n = S(e), s = [t.id];
430
434
  return {
431
435
  sql: `DELETE FROM "${n}" WHERE id = ?;`,
432
436
  params: s
433
437
  };
434
- }, Ie = (e, t, n) => {
435
- const s = A(e), r = we(e, t);
438
+ }, Oe = (e, t, n) => {
439
+ const s = S(e), r = Ne(e, t);
436
440
  n?.userId && (e.propertyMap.has("createdBy") && (r.createdBy = n.userId), e.propertyMap.has("updatedBy") && (r.updatedBy = n.userId));
437
441
  const a = /* @__PURE__ */ new Date();
438
442
  e.propertyMap.has("createdAt") && r.createdAt === void 0 && (r.createdAt = n?.createdAt ?? a), e.propertyMap.has("updatedAt") && r.updatedAt === void 0 && (r.updatedAt = n?.updatedAt ?? a);
@@ -443,23 +447,23 @@ const re = (e, t) => {
443
447
  params: l
444
448
  };
445
449
  }, oe = (e, t, n, s) => {
446
- const r = tt(e, n);
450
+ const r = nt(e, n);
447
451
  e.propertyMap.has("updatedAt") && (r.updatedAt = s?.updatedAt ?? /* @__PURE__ */ new Date()), s?.userId && e.propertyMap.has("updatedBy") && (r.updatedBy = s.userId);
448
- const a = re(e, r), i = Object.keys(r).map((u) => `${u} = ?`).join(","), c = [...Object.values(a)], o = A(e), l = Array.isArray(t), h = l ? t : [t];
452
+ const a = re(e, r), i = Object.keys(r).map((u) => `${u} = ?`).join(","), c = [...Object.values(a)], o = S(e), l = Array.isArray(t), h = l ? t : [t];
449
453
  let d = `UPDATE "${o}" SET ${i} WHERE id `;
450
454
  return l ? d += `in (${h.map((u) => R(u.id)).join(",")})` : (c.push(t.id), d += "= ?"), s?.returning !== !1 ? d += ` RETURNING rowid as ${L}, *;` : d += ";", {
451
455
  sql: d,
452
456
  params: c
453
457
  };
454
- }, St = (e, t, n) => {
458
+ }, At = (e, t, n) => {
455
459
  if (n.groupBy)
456
460
  throw new b("groupBy not supported yet");
457
- const { joinSQL: s, fieldAliasMap: r } = Re(e, t, n.where), a = A(t), i = B(n.where, r, t, e), c = [`SELECT COUNT(${N}.rowid) AS count FROM "${a}" ${N}`];
461
+ const { joinSQL: s, fieldAliasMap: r } = Ie(e, t, n.where), a = S(t), i = B(n.where, r, t, e), c = [`SELECT COUNT(${N}.rowid) AS count FROM "${a}" ${N}`];
458
462
  return s && c.push(s), i && c.push(` WHERE ${i}`), { sql: c.join("") };
459
463
  }, te = (e, t, n) => {
460
- const { joinSQL: s, fieldAliasMap: r } = Re(e, t, n.where);
461
- return { sql: be({
462
- tableName: A(t),
464
+ const { joinSQL: s, fieldAliasMap: r } = Ie(e, t, n.where);
465
+ return { sql: Re({
466
+ tableName: S(t),
463
467
  where: B(n.where, r, t, e),
464
468
  orderBy: Tt(n.orderBy),
465
469
  join: s,
@@ -468,8 +472,8 @@ const re = (e, t) => {
468
472
  limit: n.limit,
469
473
  offset: n.offset
470
474
  }) };
471
- }, bt = (e, t) => ({ sql: be({
472
- tableName: A(e),
475
+ }, bt = (e, t) => ({ sql: Re({
476
+ tableName: S(e),
473
477
  where: `${L} IN (${t.join(",")})`,
474
478
  metadata: e
475
479
  }) }), Q = (e, t, n, s = !1) => {
@@ -508,7 +512,7 @@ const re = (e, t) => {
508
512
  }
509
513
  });
510
514
  };
511
- class It extends De {
515
+ class It extends je {
512
516
  constructor(t, n) {
513
517
  super(t.rxdb, n), this.adapter = t, this.metadata = w(n);
514
518
  }
@@ -526,7 +530,7 @@ class It extends De {
526
530
  return Q(this.adapter, this.EntityType, t, n);
527
531
  }
528
532
  }
529
- class Oe extends It {
533
+ class Me extends It {
530
534
  async get(t) {
531
535
  const n = {
532
536
  where: {
@@ -545,11 +549,11 @@ class Oe extends It {
545
549
  return this.addQueryCache(r);
546
550
  }
547
551
  async count(t) {
548
- const { sql: n, params: s } = St(this.adapter, this.metadata, t);
552
+ const { sql: n, params: s } = At(this.adapter, this.metadata, t);
549
553
  return (await this.adapter.query(n, s)).results[0].rows[0][0];
550
554
  }
551
555
  async create(t) {
552
- const { sql: n, params: s } = Ie(this.metadata, t, this.rxdb.context), r = await this.adapter.query(n, s);
556
+ const { sql: n, params: s } = Oe(this.metadata, t, this.rxdb.context), r = await this.adapter.query(n, s);
553
557
  return this.addQueryCache(r, !0), t;
554
558
  }
555
559
  async update(t, n) {
@@ -561,7 +565,7 @@ class Oe extends It {
561
565
  n.origin = structuredClone({ ...t }), n.modified = !1, n.removed = !0;
562
566
  };
563
567
  if (n.local === !0) {
564
- const { sql: a, params: i } = At(this.metadata, t);
568
+ const { sql: a, params: i } = St(this.metadata, t);
565
569
  return await this.adapter.query(a, i), s(), t;
566
570
  }
567
571
  const r = w(t);
@@ -662,7 +666,7 @@ const Ot = (e) => {
662
666
  jsContext: !1,
663
667
  multipleConnections: !0
664
668
  }
665
- ], Me = (e) => {
669
+ ], Le = (e) => {
666
670
  const t = vt.find((a) => a.name === e.vfs), { vfs: n, async: s, worker: r } = e;
667
671
  if (!t) throw new b(`vfs ${n} not found`);
668
672
  if (s !== void 0) {
@@ -675,12 +679,12 @@ const Ot = (e) => {
675
679
  if (!r && !t.jsContext) throw new b(`vfs ${n} only support worker`);
676
680
  return t;
677
681
  }, qt = async (e) => {
678
- const t = Me(e), n = e.async ?? !0;
682
+ const t = Le(e), n = e.async ?? !0;
679
683
  let s;
680
684
  n ? s = Lt : s = Ct;
681
685
  const [r, a] = await Promise.all([s(), t.vfsModule()]), i = {};
682
686
  e.locateFile ? i.locateFile = e.locateFile : e.wasmPath && (i.locateFile = () => e.wasmPath);
683
- const c = await r(i), o = Je(c), l = await a.create(e.vfs, c, t.vfsOptions);
687
+ const c = await r(i), o = Ye(c), l = await a.create(e.vfs, c, t.vfsOptions);
684
688
  return o.vfs_register(l, !0), o;
685
689
  }, xt = async (e, t, n, s) => {
686
690
  const r = performance.now(), a = s ? [s] : [[]], i = [];
@@ -694,7 +698,7 @@ const Ot = (e) => {
694
698
  for (const u of a)
695
699
  e.reset(l), e.bind_collection(l, u);
696
700
  const h = [];
697
- for (; await e.step(l) === Ye; ) {
701
+ for (; await e.step(l) === Xe; ) {
698
702
  const u = e.row(l);
699
703
  h.push(u);
700
704
  }
@@ -708,8 +712,8 @@ const Ot = (e) => {
708
712
  };
709
713
  }, Dt = {
710
714
  BALANCED: 16
711
- }, fe = Dt.BALANCED, jt = 50 * 1024, Pt = /* @__PURE__ */ new Set(["public$RxDBChange", "public$RxDBBranch", "public$RxDBMigration"]);
712
- class Ft extends He {
715
+ }, Ee = Dt.BALANCED, jt = 50 * 1024, Ft = /* @__PURE__ */ new Set(["public$RxDBChange", "public$RxDBBranch", "public$RxDBMigration"]);
716
+ class Pt extends Qe {
713
717
  #n;
714
718
  #e;
715
719
  #r = !1;
@@ -717,7 +721,7 @@ class Ft extends He {
717
721
  #c;
718
722
  #a = [];
719
723
  #o;
720
- #t = fe;
724
+ #t = Ee;
721
725
  /**
722
726
  * 初始化数据库
723
727
  *
@@ -726,16 +730,16 @@ class Ft extends He {
726
730
  */
727
731
  async init(t, n) {
728
732
  if (this.#r) return;
729
- this.#r = !0, this.#c = new ye(1);
733
+ this.#r = !0, this.#c = new ge(1);
730
734
  const s = await qt(n), r = `${t}.sqlite`;
731
- this.#e = await s.open_v2(r), this.#n = s, this.#d(s, this.#e), this.#t = n?.batchTimeout ?? fe;
735
+ this.#e = await s.open_v2(r), this.#n = s, this.#d(s, this.#e), this.#t = n?.batchTimeout ?? Ee;
732
736
  const a = n?.cacheSizeKb ?? jt;
733
737
  await this.execute(`
734
738
  PRAGMA temp_store = memory;
735
739
  PRAGMA foreign_keys = ON;
736
740
  PRAGMA cache_size = -${a};
737
741
  `), this.#n.update_hook(this.#e, (i, c, o, l) => {
738
- !c || !o || !Pt.has(o) || (this.#a.push({ type: i, dbName: c, tableName: o, rowId: l }), this.#i());
742
+ !c || !o || !Ft.has(o) || (this.#a.push({ type: i, dbName: c, tableName: o, rowId: l }), this.#i());
739
743
  });
740
744
  }
741
745
  /**
@@ -745,7 +749,7 @@ class Ft extends He {
745
749
  */
746
750
  async version() {
747
751
  const t = await this.execute("SELECT sqlite_version()");
748
- return Qe(t, "results[0].rows[0][0]");
752
+ return Ke(t, "results[0].rows[0][0]");
749
753
  }
750
754
  /**
751
755
  * 断开数据库连接
@@ -818,13 +822,13 @@ class Ft extends He {
818
822
  }
819
823
  }
820
824
  function Bt(e, t) {
821
- e.create_function(t, "regexp", 2, $e | Te, 0, (n, s) => {
825
+ e.create_function(t, "regexp", 2, Te | we, 0, (n, s) => {
822
826
  const r = new RegExp(e.value_text(s[0])), a = e.value_text(s[1]);
823
827
  e.result(n, r.test(a) ? 1 : 0);
824
828
  });
825
829
  }
826
830
  function kt(e, t) {
827
- e.create_function(t, "regexp_replace", -1, $e | Te, 0, (n, s) => {
831
+ e.create_function(t, "regexp_replace", -1, Te | we, 0, (n, s) => {
828
832
  if (s.length < 3) {
829
833
  e.result(n, "");
830
834
  return;
@@ -841,9 +845,9 @@ const Wt = async (e, t) => {
841
845
  wasmPath: a,
842
846
  locateFile: i
843
847
  };
844
- Me(h);
848
+ Le(h);
845
849
  let d;
846
- return r && c ? d = ue(c) : l && o ? d = ue(o.port) : d = new Ft(), await d.init(e, h), d;
850
+ return r && c ? d = ue(c) : l && o ? d = ue(o.port) : d = new Pt(), await d.init(e, h), d;
847
851
  }, Ut = (e, t) => t.map((n) => {
848
852
  const s = e.rxdb.schemaManager.getEntityMetadata(n.entity, n.namespace);
849
853
  return s ? (n.inversePatch && Object.keys(n.inversePatch).forEach((r) => {
@@ -886,9 +890,9 @@ const Wt = async (e, t) => {
886
890
  }
887
891
  }
888
892
  }, Ht = (e, t) => {
889
- const { tableName: n } = t, [s, r] = et(n), a = e.rxdb.schemaManager.getEntityType(r, s);
893
+ const { tableName: n } = t, [s, r] = tt(n), a = e.rxdb.schemaManager.getEntityType(r, s);
890
894
  if (!a) return;
891
- const i = e.getRepository(a), c = w(a), o = w(P);
895
+ const i = e.getRepository(a), c = w(a), o = w(F);
892
896
  i.findByRowIds(t.rowIds).then((l) => {
893
897
  let h = l;
894
898
  if (c === o) {
@@ -958,7 +962,7 @@ const Wt = async (e, t) => {
958
962
  console.error("Failed to handle RxDBChange insert event", l);
959
963
  });
960
964
  }, G = (e, t, n) => {
961
- const { isCount: s, isFindDescendants: r, entityId: a, where: i } = n, c = !a, o = A(t);
965
+ const { isCount: s, isFindDescendants: r, entityId: a, where: i } = n, c = !a, o = S(t);
962
966
  let l = "";
963
967
  const d = [`c.__level < ${n.level || 0}`, i && B(i, /* @__PURE__ */ new Map(), t, e)].filter(Boolean).join(" AND ");
964
968
  d && (l = `WHERE ${d}`);
@@ -988,7 +992,7 @@ SELECT ${u} FROM __children ORDER BY __level, id;`
988
992
  isFindDescendants: !1,
989
993
  hasChildren: t.features?.tree?.hasChildren
990
994
  }), Jt = (e, t, n) => G(e, t, { ...n, isFindDescendants: !1, isCount: !0 });
991
- class Yt extends Oe {
995
+ class Yt extends Me {
992
996
  async findDescendants(t) {
993
997
  const { sql: n } = Qt(this.adapter, this.metadata, t), s = await this.adapter.query(n);
994
998
  return this.addQueryCache(s, !0);
@@ -1007,12 +1011,12 @@ class Yt extends Oe {
1007
1011
  }
1008
1012
  }
1009
1013
  const Xt = (e, t) => {
1010
- const n = A(e), s = t.map((r) => `'${r.id}'`).join(",");
1014
+ const n = S(e), s = t.map((r) => `'${r.id}'`).join(",");
1011
1015
  return `DELETE FROM "${n}" WHERE id in (${s});`;
1012
- }, Le = (e, t, n) => {
1013
- const s = A(e), r = n?.userId && e.propertyMap.has("createdBy"), a = n?.userId && e.propertyMap.has("updatedBy"), i = [...e.propertyMap.keys(), ...e.foreignKeyNames], c = [];
1016
+ }, Ce = (e, t, n) => {
1017
+ const s = S(e), r = n?.userId && e.propertyMap.has("createdBy"), a = n?.userId && e.propertyMap.has("updatedBy"), i = [...e.propertyMap.keys(), ...e.foreignKeyNames], c = [];
1014
1018
  t.forEach((l) => {
1015
- const h = we(e, l);
1019
+ const h = Ne(e, l);
1016
1020
  r && (h.createdBy = n.userId), a && (h.updatedBy = n.userId);
1017
1021
  const d = re(e, h), u = [];
1018
1022
  i.forEach((p) => {
@@ -1022,35 +1026,35 @@ const Xt = (e, t) => {
1022
1026
  });
1023
1027
  const o = c.map((l) => `(${l.join(",")})`).join(",");
1024
1028
  return `INSERT INTO "${s}" (${i.join(",")}) VALUES ${o};`;
1025
- }, Ee = async (e, t, n) => {
1029
+ }, _e = async (e, t, n) => {
1026
1030
  const s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Date();
1027
1031
  let a = "";
1028
1032
  const i = /* @__PURE__ */ new Set();
1029
1033
  return t.create.forEach((c, o) => {
1030
1034
  const l = Array.from(c);
1031
1035
  l.forEach((E) => i.add(E));
1032
- const h = w(o), d = Le(h, l, e.rxdb.context), u = l.map((E) => E.id);
1036
+ const h = w(o), d = Ce(h, l, e.rxdb.context), u = l.map((E) => E.id);
1033
1037
  u.forEach((E) => s.set(E, o));
1034
1038
  const { sql: p, params: f } = te(e, h, {
1035
1039
  where: {
1036
1040
  combinator: "and",
1037
1041
  rules: [{ field: "id", operator: "in", value: u }]
1038
1042
  }
1039
- }), _ = F(p, f);
1043
+ }), _ = P(p, f);
1040
1044
  a += d + _;
1041
1045
  }), t.update.forEach((c, o) => {
1042
1046
  const l = Array.from(c);
1043
1047
  l.forEach((u) => i.add(u));
1044
1048
  const h = w(o), d = Object.groupBy(l, (u) => {
1045
1049
  const p = C(u);
1046
- return ge(Object.keys(p.patch).sort());
1050
+ return $e(Object.keys(p.patch).sort());
1047
1051
  });
1048
1052
  Object.values(d).forEach((u) => {
1049
1053
  const p = u[0], f = C(p), _ = oe(h, u, f.patch, {
1050
1054
  ...e.rxdb.context,
1051
1055
  returning: !1,
1052
1056
  updatedAt: r
1053
- }), E = F(_.sql, _.params);
1057
+ }), E = P(_.sql, _.params);
1054
1058
  a += E;
1055
1059
  const g = u.map((m) => m.id);
1056
1060
  g.forEach((m) => s.set(m, o));
@@ -1059,7 +1063,7 @@ const Xt = (e, t) => {
1059
1063
  combinator: "and",
1060
1064
  rules: [{ field: "id", operator: "in", value: g }]
1061
1065
  }
1062
- }), T = F($.sql, $.params);
1066
+ }), T = P($.sql, $.params);
1063
1067
  a += T;
1064
1068
  });
1065
1069
  }), t.remove.forEach((c, o) => {
@@ -1088,11 +1092,11 @@ const Xt = (e, t) => {
1088
1092
  })
1089
1093
  ), Array.from(i);
1090
1094
  }, zt = (e, t) => {
1091
- const n = A(t);
1095
+ const n = S(t);
1092
1096
  let s = `CREATE TABLE "${n}" (`;
1093
1097
  const r = [], a = [], i = [];
1094
1098
  t.propertyMap.forEach((o) => {
1095
- let l = `"${o.name}" ${Ze(o)}`;
1099
+ let l = `"${o.name}" ${et(o)}`;
1096
1100
  if (o.type === y.integer && o.primary ? l += " PRIMARY KEY AUTOINCREMENT" : (o.type === y.uuid || o.type === y.string) && o.primary && (l += " PRIMARY KEY", o.type === y.uuid && (l += " DEFAULT (lower(hex(randomblob(16))))")), !(o.type === y.uuid && o.primary) && Reflect.get(o, "default") !== void 0) {
1097
1101
  let d = o.default;
1098
1102
  de(o.default) && (d = o.default()), d === "CURRENT_TIMESTAMP" ? l += " DEFAULT(strftime('%FT%H:%M:%fZ'))" : (d = se(d, o), o.type === y.boolean || o.type === y.integer || o.type === y.number ? l += ` DEFAULT ${d}` : l += ` DEFAULT '${d}'`);
@@ -1112,7 +1116,7 @@ const Xt = (e, t) => {
1112
1116
  `CREATE UNIQUE INDEX ${pe(t, o)} on "${n}"(${o.name});`
1113
1117
  ), i.push(l);
1114
1118
  }), t.relationMap.forEach((o) => {
1115
- if (o.kind === S.ONE_TO_ONE || o.kind === S.MANY_TO_ONE) {
1119
+ if (o.kind === A.ONE_TO_ONE || o.kind === A.MANY_TO_ONE) {
1116
1120
  const l = `${o.name}Id`, h = e.rxdb.schemaManager.getEntityMetadata(
1117
1121
  o.mappedEntity,
1118
1122
  o.mappedNamespace
@@ -1122,7 +1126,7 @@ const Xt = (e, t) => {
1122
1126
  u.type === y.integer ? d = "INTEGER" : (u.type === y.uuid || u.type === y.string) && (d = "TEXT");
1123
1127
  const p = o.onDelete === "SET NULL" || o.onUpdate === "SET NULL";
1124
1128
  let f = `"${l}" ${d}`;
1125
- if (!o.nullable && !p && (f += " NOT NULL"), o.kind === S.MANY_TO_ONE && Reflect.get(o, "default") !== void 0) {
1129
+ if (!o.nullable && !p && (f += " NOT NULL"), o.kind === A.MANY_TO_ONE && Reflect.get(o, "default") !== void 0) {
1126
1130
  const _ = o;
1127
1131
  let E = _.default;
1128
1132
  de(_.default) && (E = _.default()), f += ` DEFAULT ${E}`;
@@ -1131,7 +1135,7 @@ const Xt = (e, t) => {
1131
1135
  const _ = q(o.mappedEntity, o.mappedNamespace);
1132
1136
  f += ` REFERENCES ${_}(id)`, o.onDelete && (f += ` ON DELETE ${o.onDelete}`), o.onUpdate && (f += ` ON UPDATE ${o.onUpdate}`);
1133
1137
  }
1134
- i.push(f), (o.unique || o.kind === S.ONE_TO_ONE) && r.push(
1138
+ i.push(f), (o.unique || o.kind === A.ONE_TO_ONE) && r.push(
1135
1139
  `CREATE UNIQUE INDEX ${pe(t, o)} on "${n}"(${l});`
1136
1140
  );
1137
1141
  }
@@ -1151,7 +1155,7 @@ ${o}`).join(","), s += `
1151
1155
  CREATE ${d}INDEX "${l}" ON "${n}"(${h});`;
1152
1156
  }), s;
1153
1157
  }, Zt = (e, t) => zt(e, t), ie = (e, t = {}) => {
1154
- const n = A(e), s = w(P), r = A(s), { propertyMap: a, name: i, foreignKeyNames: c, namespace: o } = e, l = [...a.keys(), ...c].filter((m) => ["id"].includes(m) === !1), h = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: d, branchId: u } = t, p = R(d), f = R(u || "main"), _ = `'${o}','${i}',${f},${p}`, E = (m, I) => a.get(m)?.type === y.boolean ? `CASE WHEN ${I}.${m} = 1 THEN 1 ELSE 0 END` : `${I}.${m}`, g = `
1158
+ const n = S(e), s = w(F), r = S(s), { propertyMap: a, name: i, foreignKeyNames: c, namespace: o } = e, l = [...a.keys(), ...c].filter((m) => ["id"].includes(m) === !1), h = " type, namespace, entity, branchId, transactionId, entityId, inversePatch, patch", { transactionId: d, branchId: u } = t, p = R(d), f = R(u || "main"), _ = `'${o}','${i}',${f},${p}`, E = (m, I) => a.get(m)?.type === y.boolean ? `CASE WHEN ${I}.${m} = 1 THEN 1 ELSE 0 END` : `${I}.${m}`, g = `
1155
1159
  DROP TRIGGER IF EXISTS ${n}_insert;
1156
1160
  CREATE TRIGGER ${n}_insert AFTER INSERT ON "${n}"
1157
1161
  BEGIN
@@ -1212,24 +1216,24 @@ CREATE ${d}INDEX "${l}" ON "${n}"(${h});`;
1212
1216
  r.has(i) === !1 && r.set(i, /* @__PURE__ */ new Set()), r.get(i).add(a);
1213
1217
  });
1214
1218
  for (const a of r.keys()) {
1215
- const i = Le(a, Array.from(r.get(a)), e.rxdb.context);
1219
+ const i = Ce(a, Array.from(r.get(a)), e.rxdb.context);
1216
1220
  s += `
1217
1221
  ` + i;
1218
1222
  }
1219
1223
  }
1220
1224
  return s;
1221
1225
  }, tn = (e) => {
1222
- const t = A(e);
1226
+ const t = S(e);
1223
1227
  return `DROP TRIGGER IF EXISTS ${t}_insert;
1224
1228
  DROP TRIGGER IF EXISTS ${t}_update;
1225
1229
  DROP TRIGGER IF EXISTS ${t}_delete;`;
1226
- }, Ce = (e) => {
1230
+ }, ve = (e) => {
1227
1231
  let t = "";
1228
1232
  return e.rxdb.config.entities.forEach((n) => {
1229
1233
  const s = w(n);
1230
1234
  s.log !== !1 && (t += tn(s));
1231
1235
  }), t;
1232
- }, ve = (e, t) => {
1236
+ }, qe = (e, t) => {
1233
1237
  const { deletes: n, inserts: s, updates: r } = t, a = { deletes: [], inserts: [], updates: [] }, i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
1234
1238
  for (const [u, p] of n.entries()) {
1235
1239
  const [f, _, E] = J(u), g = `${f}:${_}`, $ = i.get(g);
@@ -1241,7 +1245,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1241
1245
  });
1242
1246
  }
1243
1247
  for (const [u, p] of i) {
1244
- const [f, _] = u.split(":"), E = e.rxdb.schemaManager.getEntityMetadata(_, f), g = A(E), $ = E.propertyMap.get("id").type === "integer";
1248
+ const [f, _] = u.split(":"), E = e.rxdb.schemaManager.getEntityMetadata(_, f), g = S(E), $ = E.propertyMap.get("id").type === "integer";
1245
1249
  let T = "";
1246
1250
  $ ? T = Array.from(p).join(",") : T = Array.from(p).map((I) => `'${I}'`).join(",");
1247
1251
  const m = `DELETE FROM "${g}" WHERE id in (${T});`;
@@ -1268,7 +1272,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1268
1272
  p.forEach(($) => {
1269
1273
  for (const [O, M] of E.propertyMap)
1270
1274
  $[O] === void 0 && M.default !== void 0 && (typeof M.default == "function" ? $[O] = M.default() : $[O] = M.default);
1271
- const { sql: T, params: m } = Ie(E, $, { useReplace: !0 }), I = F(T, m);
1275
+ const { sql: T, params: m } = Oe(E, $, { useReplace: !0 }), I = P(T, m);
1272
1276
  g += I;
1273
1277
  }), a.inserts.push({
1274
1278
  metadata: E,
@@ -1304,7 +1308,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1304
1308
  const { id: m, ...I } = $, { sql: O, params: M } = oe(E, { id: m }, I, {
1305
1309
  updatedAt: T
1306
1310
  });
1307
- g += F(O, M);
1311
+ g += P(O, M);
1308
1312
  }), a.updates.push({
1309
1313
  metadata: E,
1310
1314
  ids: new Set(p.filter(($) => $ != null).map(($) => $.id)),
@@ -1313,7 +1317,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1313
1317
  });
1314
1318
  }
1315
1319
  return a;
1316
- }, qe = (e, t) => {
1320
+ }, xe = (e, t) => {
1317
1321
  let n = "";
1318
1322
  e.rxdb.config.entities.forEach((i) => {
1319
1323
  const c = w(i);
@@ -1327,7 +1331,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1327
1331
  console.warn(`Failed to generate trigger SQL for entity ${c.name}:`, o);
1328
1332
  }
1329
1333
  });
1330
- const s = w(W), r = A(s), a = t.replace(/'/g, "''");
1334
+ const s = w(W), r = S(s), a = t.replace(/'/g, "''");
1331
1335
  return n += `
1332
1336
  UPDATE "${r}"
1333
1337
  SET
@@ -1343,11 +1347,11 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1343
1347
  RETURNING rowid as ${L},*;
1344
1348
  `, n;
1345
1349
  }, nn = async (e, t) => {
1346
- const { branchId: n, actions: s } = t, r = s && ve(e, s);
1350
+ const { branchId: n, actions: s } = t, r = s && qe(e, s);
1347
1351
  let a;
1348
1352
  try {
1349
1353
  await e.transaction(async (o) => {
1350
- const l = Ce(e);
1354
+ const l = ve(e);
1351
1355
  if (l && await o.execute(l), r) {
1352
1356
  if (r.deletes.length)
1353
1357
  for (const h of r.deletes)
@@ -1361,7 +1365,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1361
1365
  }
1362
1366
  s?.updateRxDBChangeSequence !== void 0 && await e.setRxDBChangeSequence(s.updateRxDBChangeSequence);
1363
1367
  }, !1);
1364
- const i = qe(e, n);
1368
+ const i = xe(e, n);
1365
1369
  a = await e.internalQuery(i);
1366
1370
  const c = (o, l) => {
1367
1371
  if (l.length === 0) return;
@@ -1383,7 +1387,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1383
1387
  const o = Q(e, W, a, !0), l = w(W);
1384
1388
  c(l, o);
1385
1389
  }
1386
- r && xe(e, r);
1390
+ r && De(e, r);
1387
1391
  } catch (i) {
1388
1392
  throw new b(`switch branch ${n} failed: ` + i);
1389
1393
  }
@@ -1391,7 +1395,7 @@ DROP TRIGGER IF EXISTS ${t}_delete;`;
1391
1395
  async function sn(e, t, n, s = !1) {
1392
1396
  if (await e.transaction(async (r) => {
1393
1397
  if (s) {
1394
- const a = Ce(e);
1398
+ const a = ve(e);
1395
1399
  a && await r.execute(a);
1396
1400
  }
1397
1401
  for (const a of t.deletes)
@@ -1401,12 +1405,12 @@ async function sn(e, t, n, s = !1) {
1401
1405
  for (const a of t.updates)
1402
1406
  a.successResults = await r.execute(a.sql);
1403
1407
  }, !1), s) {
1404
- const r = await e.rxdb.versionManager.getCurrentBranch(), a = qe(e, r.id);
1408
+ const r = await e.rxdb.versionManager.getCurrentBranch(), a = xe(e, r.id);
1405
1409
  await e.internalQuery(a);
1406
1410
  }
1407
- xe(e, t);
1411
+ De(e, t);
1408
1412
  }
1409
- function xe(e, t) {
1413
+ function De(e, t) {
1410
1414
  for (const n of t.deletes) {
1411
1415
  const s = Y(n.metadata);
1412
1416
  Rt(e, s, Array.from(n.ids));
@@ -1455,7 +1459,7 @@ function xe(e, t) {
1455
1459
  e.rxdb.dispatchEvent(new K(i));
1456
1460
  }
1457
1461
  }
1458
- const _e = (e, t, n) => {
1462
+ const me = (e, t, n) => {
1459
1463
  let s = "";
1460
1464
  return e.rxdb.config.entities.forEach((r) => {
1461
1465
  const a = w(r);
@@ -1469,17 +1473,17 @@ const _e = (e, t, n) => {
1469
1473
  }
1470
1474
  }), s;
1471
1475
  };
1472
- class fn extends Be {
1476
+ class fn extends ke {
1473
1477
  constructor(t, n) {
1474
1478
  super(t), this.options = n, n.repositories && Object.keys(n.repositories).forEach((r) => {
1475
1479
  this.repository(r, n.repositories[r]);
1476
1480
  });
1477
- const s = Ke((r) => {
1481
+ const s = Ge((r) => {
1478
1482
  this.#o || Ht(this, r);
1479
1483
  });
1480
1484
  this.#t().then((r) => {
1481
1485
  r.addEventListener(v.SQLITE_INSERT, s), r.addEventListener(v.SQLITE_UPDATE, s), r.addEventListener(v.SQLITE_DELETE, s);
1482
- }), this.repository("Repository", Oe), this.repository("TreeRepository", Yt);
1486
+ }), this.repository("Repository", Me), this.repository("TreeRepository", Yt);
1483
1487
  }
1484
1488
  // SQLite 客户端缓存
1485
1489
  #n;
@@ -1493,7 +1497,7 @@ class fn extends Be {
1493
1497
  #r = /* @__PURE__ */ new Map();
1494
1498
  #s = /* @__PURE__ */ new WeakMap();
1495
1499
  // 查询任务队列执行器
1496
- #c = new ye(1);
1500
+ #c = new ge(1);
1497
1501
  // sqlite 客户端
1498
1502
  #a;
1499
1503
  // 是否已断开连接
@@ -1563,15 +1567,15 @@ class fn extends Be {
1563
1567
  * @param options
1564
1568
  */
1565
1569
  async mutations(t) {
1566
- return this.#e ? await Ee(this, t) : await this.transaction(() => Ee(this, t));
1570
+ return this.#e ? await _e(this, t) : await this.transaction(() => _e(this, t));
1567
1571
  }
1568
1572
  /**
1569
1573
  * 判断表是否存在
1570
1574
  * @param EntityType
1571
1575
  */
1572
1576
  async isTableExisted(t) {
1573
- const n = w(t), s = A(n), r = await this.#i(Xe(s));
1574
- return ze(r) === !1;
1577
+ const n = w(t), s = S(n), r = await this.#i(ze(s));
1578
+ return Ze(r) === !1;
1575
1579
  }
1576
1580
  /**
1577
1581
  * 创建表和初始化数据
@@ -1602,7 +1606,7 @@ class fn extends Be {
1602
1606
  * @deprecated localChanges 参数已废弃,将在未来版本中移除
1603
1607
  */
1604
1608
  async mergeChanges(t, n, s = !1) {
1605
- const r = ve(this, t);
1609
+ const r = qe(this, t);
1606
1610
  await sn(this, r, n, s);
1607
1611
  }
1608
1612
  /**
@@ -1649,7 +1653,7 @@ class fn extends Be {
1649
1653
  query(t, n) {
1650
1654
  return this.#c.addTask(
1651
1655
  async () => (await this.rxdb.connect(this.name), (await this.#t()).execute(t, n)),
1652
- ge([t, n])
1656
+ $e([t, n])
1653
1657
  );
1654
1658
  }
1655
1659
  /**
@@ -1664,10 +1668,10 @@ class fn extends Be {
1664
1668
  this.#e = !0, this.rxdb.dispatchEvent(rn);
1665
1669
  let r = "", a = "";
1666
1670
  if (n) {
1667
- const i = ke(), c = await this.rxdb.versionManager.getCurrentBranch();
1671
+ const i = We(), c = await this.rxdb.versionManager.getCurrentBranch();
1668
1672
  if (!c)
1669
1673
  throw new Error("currentBranch is undefined! Cannot start transaction with logging.");
1670
- r = _e(this, c.id, i), a = _e(this, c.id);
1674
+ r = me(this, c.id, i), a = me(this, c.id);
1671
1675
  }
1672
1676
  await s.execute(`
1673
1677
  BEGIN;
@@ -1703,14 +1707,14 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(on), i;
1703
1707
  * 本地变更仓库
1704
1708
  */
1705
1709
  localRxDBChange() {
1706
- return this.getRepository(P);
1710
+ return this.getRepository(F);
1707
1711
  }
1708
1712
  /**
1709
1713
  * 获取 RxDBChange 表的当前序列值
1710
1714
  * @returns
1711
1715
  */
1712
1716
  async getRxDBChangeSequence() {
1713
- const t = he(P);
1717
+ const t = he(F);
1714
1718
  return (await this.#i(`SELECT seq FROM sqlite_sequence WHERE name='${t}'`)).results[0].rows[0][0];
1715
1719
  }
1716
1720
  /**
@@ -1718,7 +1722,7 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(on), i;
1718
1722
  * @param sequence 序列值
1719
1723
  */
1720
1724
  async setRxDBChangeSequence(t) {
1721
- const n = he(P);
1725
+ const n = he(F);
1722
1726
  await this.#i("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", [t, n]);
1723
1727
  }
1724
1728
  // ============================================
@@ -1745,7 +1749,7 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(on), i;
1745
1749
  return z(/* @__PURE__ */ new Map());
1746
1750
  const s = n.map(() => "?").join(", "), r = `SELECT id, updatedAt FROM ${t} WHERE id IN (${s})`;
1747
1751
  return Z(this.internalQuery(r, n)).pipe(
1748
- Ge((a) => {
1752
+ Je((a) => {
1749
1753
  const i = /* @__PURE__ */ new Map();
1750
1754
  if (a.results?.[0]?.rows)
1751
1755
  for (const c of a.results[0].rows)
@@ -1824,16 +1828,16 @@ COMMIT;`), this.#e = !1, this.rxdb.dispatchEvent(on), i;
1824
1828
  return this.#r.has(t) === !1 && this.#r.set(t, /* @__PURE__ */ new Map()), this.#r.get(t);
1825
1829
  }
1826
1830
  }
1827
- const rn = new je(), an = new Pe(), on = new Fe();
1831
+ const rn = new Fe(), an = new Pe(), on = new Be();
1828
1832
  export {
1829
1833
  L as ROWID,
1830
1834
  fn as RxDBAdapterSqlite,
1831
1835
  b as RxDBAdapterSqliteError,
1832
- Ft as SqliteClient,
1833
- Oe as SqliteRepository,
1836
+ Pt as SqliteClient,
1837
+ Me as SqliteRepository,
1834
1838
  vt as WA_SQLITE_VFS_LIST,
1835
1839
  B as buildRuleGroup,
1836
1840
  q as sqliteGetTableName,
1837
- A as sqliteGetTableNameByMetadata,
1841
+ S as sqliteGetTableNameByMetadata,
1838
1842
  qt as sqliteLoad
1839
1843
  };
@@ -1 +1 @@
1
- {"version":3,"file":"query_sql.utils.d.ts","sourceRoot":"","sources":["../../src/query/query_sql.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,sBAAsB,EAItB,SAAS,EACV,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAG,GAAY,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAwBD;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,eAAe,MAAM,EAAE,aAAa,MAAM,KAAG,MAQ1E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,GAAG,KAAG,MA2B1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,KAAG,MAA4C,CAAC;AAEjG;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,YAAY,EAAE,EACzB,eAAe,MAAM,EACrB,UAAU,sBAAsB,KAC/B,MAAwF,CAAC;AAkC5F;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,gBAAgB,cAAc,EAC9B,eAAe,MAAM,EACrB,MAAM,GAAG,KACR,MAAM,GAAG,IAoBX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,gBAAgB,cAAc,EAAE,eAAe,MAAM,EAAE,MAAM,GAAG,KAAG,MAAM,GAAG,IAQ3G,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,GAAG,EACT,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,iBAAiB,cAAc,EAC/B,UAAU,GAAG,EACb,mBAAmB,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,KACpG,MAiDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAA6D,CAAC;AA2PjH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,GAAG,EACT,gBAAgB,cAAc,EAC9B,SAAS,GAAG,EACZ,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,KAAK,MAAM,KAC9E,MAAM,GAAG,IAiDX,CAAC"}
1
+ {"version":3,"file":"query_sql.utils.d.ts","sourceRoot":"","sources":["../../src/query/query_sql.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,sBAAsB,EAItB,SAAS,EACV,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAG,GAAY,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAwBD;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,eAAe,MAAM,EAAE,aAAa,MAAM,KAAG,MAQ1E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,GAAG,KAAG,MA2B1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,KAAG,MAA4C,CAAC;AAEjG;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,YAAY,EAAE,EACzB,eAAe,MAAM,EACrB,UAAU,sBAAsB,KAC/B,MAAwF,CAAC;AAkC5F;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,gBAAgB,cAAc,EAC9B,eAAe,MAAM,EACrB,MAAM,GAAG,KACR,MAAM,GAAG,IAoBX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,gBAAgB,cAAc,EAAE,eAAe,MAAM,EAAE,MAAM,GAAG,KAAG,MAAM,GAAG,IAQ3G,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,GAAG,EACT,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,iBAAiB,cAAc,EAC/B,UAAU,GAAG,EACb,mBAAmB,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,KACpG,MAyDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAA6D,CAAC;AA2PjH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,GAAG,EACT,gBAAgB,cAAc,EAC9B,SAAS,GAAG,EACZ,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,KAAK,MAAM,KAC9E,MAAM,GAAG,IAiDX,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-sqlite",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -32,11 +32,11 @@
32
32
  "object-hash": "^3.0.0",
33
33
  "rxjs": "^7.8.2",
34
34
  "wa-sqlite": "https://codeload.github.com/rhashimoto/wa-sqlite/tar.gz/refs/tags/v1.0.9",
35
- "@aiao/rxdb": "0.0.9",
36
- "@aiao/utils": "0.0.9"
35
+ "@aiao/rxdb": "0.0.10",
36
+ "@aiao/utils": "0.0.10"
37
37
  },
38
38
  "devDependencies": {
39
39
  "ms": "^2.1.3",
40
- "@aiao/rxdb-test": "0.0.9"
40
+ "@aiao/rxdb-test": "0.0.10"
41
41
  }
42
42
  }