@aiao/rxdb-adapter-sqlite 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +191 -202
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { RxDBError as Ee, PropertyType as m, RelationKind as y, getEntityMetadata as q, RxDBChange as ye, RepositoryBase as $e, TRANSACTION_BEGIN as be, TRANSACTION_COMMIT as Ne, TRANSACTION_ROLLBACK as Te, getEntityStatus as ae, isEntityMatchRuleGroup as S, isEntityEffectOrderBy as we, TransactionBeginEvent as ge, TransactionCommitEvent as Oe, TransactionRollbackEvent as Ie, RxDBAdapterLocalBase as Ae, RxDBAdapterUpdateChangeEvent as qe, RxDBAdapterInsertChangeEvent as Re, RxDBAdapterDeleteChangeEvent as Se } from "@aiao/rxdb";
2
- import { wrap as ve } from "comlink";
3
- import { Subject as ke, auditTime as xe, ReplaySubject as U, BehaviorSubject as ie, Observable as oe, shareReplay as L, switchMap as w, take as Q, takeUntil as K, map as f, firstValueFrom as I, tap as A, fromEvent as Ce, defer as Le, filter as Z, catchError as Me, of as je, from as ee } from "rxjs";
4
- import { pickBy as ce, isFunction as De, get as Be, traverseObjectKeys as Fe } from "@aiao/utils";
5
- import { Factory as We, SQLITE_ROW as Pe } from "@journeyapps/wa-sqlite";
6
- const Ve = (r) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${r}' limit 1;`, Ue = (r) => !!r.sql && (r.results.length === 0 || r.results[0].rows.length === 0), R = "_rowid", te = (r) => {
1
+ import { RxDBError as me, PropertyType as m, RelationKind as I, getEntityMetadata as q, RxDBChange as Ee, RepositoryBase as ye, TRANSACTION_BEGIN as $e, TRANSACTION_COMMIT as be, TRANSACTION_ROLLBACK as Ne, getEntityStatus as re, isEntityMatchRuleGroup as R, isEntityEffectOrderBy as we, TransactionBeginEvent as Te, TransactionCommitEvent as ge, TransactionRollbackEvent as Ie, RxDBAdapterLocalBase as Oe, RxDBAdapterUpdateChangeEvent as Ae, RxDBAdapterInsertChangeEvent as qe, RxDBAdapterDeleteChangeEvent as Se } from "@aiao/rxdb";
2
+ import { wrap as Re } from "comlink";
3
+ import { Subject as ve, auditTime as xe, ReplaySubject as U, BehaviorSubject as ae, Observable as ie, shareReplay as L, switchMap as w, take as Q, takeUntil as K, map as f, firstValueFrom as O, tap as A, fromEvent as Ce, defer as ke, filter as Z, catchError as Le, of as Me, from as ee } from "rxjs";
4
+ import { pickBy as oe, isFunction as je, get as De, traverseObjectKeys as Be } from "@aiao/utils";
5
+ import { Factory as Fe, SQLITE_ROW as We } from "@journeyapps/wa-sqlite";
6
+ const Pe = (r) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${r}' limit 1;`, Ve = (r) => !!r.sql && (r.results.length === 0 || r.results[0].rows.length === 0), S = "_rowid", te = (r) => {
7
7
  switch (r.type) {
8
8
  case m.uuid:
9
9
  case m.string:
@@ -17,7 +17,7 @@ const Ve = (r) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${r}
17
17
  case m.date:
18
18
  return "TEXT";
19
19
  }
20
- }, Qe = (r, e) => {
20
+ }, Ue = (r, e) => {
21
21
  if (r === null && e.nullable) return null;
22
22
  if (r !== void 0)
23
23
  switch (e.type) {
@@ -28,7 +28,7 @@ const Ve = (r) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${r}
28
28
  default:
29
29
  return r;
30
30
  }
31
- }, Ke = (r, e) => {
31
+ }, Qe = (r, e) => {
32
32
  if (r === null && e.nullable) return null;
33
33
  if (r !== void 0)
34
34
  switch (e.type) {
@@ -41,17 +41,17 @@ const Ve = (r) => `SELECT * FROM sqlite_master WHERE type='table' AND name='${r}
41
41
  default:
42
42
  return r;
43
43
  }
44
- }, le = (r, e) => `${e}$${r}`, E = (r) => le(r.name, r.namespace), ue = (r, e) => `idx_${r.name}_${e.name}`;
45
- class $ extends Ee {
44
+ }, ce = (r, e) => `${e}$${r}`, y = (r) => ce(r.name, r.namespace), le = (r, e) => `idx_${r.name}_${e.name}`;
45
+ class E extends me {
46
46
  }
47
- const Y = (r, e) => {
47
+ const H = (r, e) => {
48
48
  const t = {};
49
49
  return Object.keys(e).forEach((s) => {
50
50
  s.endsWith("Id") && (t[s] = e[s]);
51
51
  const n = r.propertyMap.get(s);
52
- n && (t[s] = Qe(e[s], n));
52
+ n && (t[s] = Ue(e[s], n));
53
53
  }), t;
54
- }, Ye = (r, e) => ce(e, (t, s) => r.propertyMap.has(s) || r.foreignKeyNames.includes(s)), He = (r, e) => ce(e, (t, s) => r.propertyMap.get(s)?.readonly !== !0), se = (r, e, t) => {
54
+ }, Ke = (r, e) => oe(e, (t, s) => r.propertyMap.has(s) || r.foreignKeyNames.includes(s)), He = (r, e) => oe(e, (t, s) => r.propertyMap.get(s)?.readonly !== !0), se = (r, e, t) => {
55
55
  const s = {};
56
56
  return t.forEach((n, a) => {
57
57
  const o = e[a];
@@ -59,36 +59,31 @@ const Y = (r, e) => {
59
59
  s[o] = n;
60
60
  else {
61
61
  const c = r.propertyMap.get(o);
62
- c && (s[o] = Ke(n, c));
62
+ c && (s[o] = Qe(n, c));
63
63
  }
64
64
  }), s;
65
- }, ne = {
66
- [y.ONE_TO_ONE]: 0,
67
- [y.ONE_TO_MANY]: 1,
68
- [y.MANY_TO_ONE]: 2,
69
- [y.MANY_TO_MANY]: 3
70
65
  }, Je = (r, e) => {
71
66
  let t = "";
72
- const s = E(e);
73
- return Array.from(e.relationMap.values())?.toSorted((n, a) => ne[n.kind] - ne[a.kind]).forEach((n) => {
67
+ const s = y(e);
68
+ return Array.from(e.relationMap.values()).forEach((n) => {
74
69
  switch (n.kind) {
75
- case y.ONE_TO_ONE:
76
- case y.MANY_TO_ONE:
70
+ case I.ONE_TO_ONE:
71
+ case I.MANY_TO_ONE:
77
72
  {
78
73
  const a = `${n.name}Id`;
79
74
  if (t += `
80
75
  ALTER TABLE ${s} ADD COLUMN "${a}" TEXT`, n.nullable || (t += " NOT NULL"), n.mappedEntity) {
81
- const o = le(n.mappedEntity, n.mappedNamespace);
76
+ const o = ce(n.mappedEntity, n.mappedNamespace);
82
77
  t += ` REFERENCES ${o}(id)`;
83
78
  }
84
- n.kind === y.MANY_TO_ONE && (t += " ON DELETE CASCADE"), t += ";", (n.unique || n.kind === y.ONE_TO_ONE) && (t += `
85
- CREATE UNIQUE INDEX ${ue(e, n)} on ${s}(${a});`);
79
+ n.kind === I.MANY_TO_ONE && (t += " ON DELETE CASCADE"), t += ";", (n.unique || n.kind === I.ONE_TO_ONE) && (t += `
80
+ CREATE UNIQUE INDEX ${le(e, n)} on ${s}(${a});`);
86
81
  }
87
82
  break;
88
83
  }
89
84
  }), t;
90
- }, Ge = (r, e) => {
91
- const t = E(e);
85
+ }, Ye = (r, e) => {
86
+ const t = y(e);
92
87
  let s = `CREATE TABLE ${t} (`;
93
88
  const n = [], a = [], o = [];
94
89
  e.propertyMap.forEach((i) => {
@@ -96,7 +91,7 @@ ALTER TABLE ${s} ADD COLUMN "${a}" TEXT`, n.nullable || (t += " NOT NULL"), n.ma
96
91
  if (l += `"${i.name}"`, i.primary ? i.type === m.integer ? l += " INTEGER PRIMARY KEY AUTOINCREMENT" : l += ` ${te(i)} PRIMARY KEY` : l += ` ${te(i)}`, !i.nullable) l += " NOT NULL";
97
92
  else if (Reflect.get(i, "default") !== void 0) {
98
93
  let u = i.default;
99
- De(i.default) && (u = i.default()), l += ` DEFAULT ${String(u)}`;
94
+ je(i.default) && (u = i.default()), l += ` DEFAULT ${String(u)}`;
100
95
  }
101
96
  switch (i.type) {
102
97
  case m.json:
@@ -107,7 +102,7 @@ ALTER TABLE ${s} ADD COLUMN "${a}" TEXT`, n.nullable || (t += " NOT NULL"), n.ma
107
102
  break;
108
103
  }
109
104
  i.unique && n.push(
110
- `CREATE UNIQUE INDEX ${ue(e, i)} on ${t}(${i.name});`
105
+ `CREATE UNIQUE INDEX ${le(e, i)} on ${t}(${i.name});`
111
106
  ), o.push(l);
112
107
  });
113
108
  const c = [...o, ...a];
@@ -116,15 +111,15 @@ ALTER TABLE ${s} ADD COLUMN "${a}" TEXT`, n.nullable || (t += " NOT NULL"), n.ma
116
111
  ${i}`).join(","), s += `
117
112
  );`;
118
113
  else
119
- throw new $("columns is empty!");
114
+ throw new E("columns is empty!");
120
115
  return n.length && (s += `
121
116
  ` + n.join(`
122
117
  `)), s;
123
- }, ze = (r, e) => {
118
+ }, Ge = (r, e) => {
124
119
  let t = "";
125
- return t += Ge(r, e), t += Je(r, e), t;
126
- }, Xe = (r, e) => {
127
- const t = E(e), s = q(ye), n = E(s), { propertyMap: a, name: o, foreignKeyNames: c, namespace: i } = e, l = [...a.keys(), ...c].filter((d) => ["id", "updatedAt"].includes(d) === !1), u = "namespace, entity, type, entityId, inversePatch, patch", h = `CREATE TRIGGER ${t}_insert AFTER INSERT ON ${t}
120
+ return t += Ye(r, e), t += Je(r, e), t;
121
+ }, ze = (r, e) => {
122
+ const t = y(e), s = q(Ee), n = y(s), { propertyMap: a, name: o, foreignKeyNames: c, namespace: i } = e, l = [...a.keys(), ...c].filter((d) => ["id", "updatedAt"].includes(d) === !1), u = "namespace, entity, type, entityId, inversePatch, patch", h = `CREATE TRIGGER ${t}_insert AFTER INSERT ON ${t}
128
123
  BEGIN
129
124
  INSERT INTO ${n} (${u}) VALUES (
130
125
  '${i}', '${o}', 'INSERT', NEW.id, NULL,
@@ -164,7 +159,7 @@ END;`;
164
159
  ` + p;
165
160
  };
166
161
  var M = /* @__PURE__ */ ((r) => (r[r.SQLITE_DELETE = 9] = "SQLITE_DELETE", r[r.SQLITE_INSERT = 18] = "SQLITE_INSERT", r[r.SQLITE_UPDATE = 23] = "SQLITE_UPDATE", r))(M || {});
167
- const de = "sqlite", Ze = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs").then((r) => r.default), et = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite.mjs").then((r) => r.default), tt = [
162
+ const ue = "sqlite", Xe = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs").then((r) => r.default), Ze = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite.mjs").then((r) => r.default), et = [
168
163
  {
169
164
  name: "MemoryVFS",
170
165
  vfsModule: () => import("@journeyapps/wa-sqlite/src/examples/MemoryVFS.js").then((r) => r.MemoryVFS),
@@ -248,22 +243,22 @@ const de = "sqlite", Ze = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite-as
248
243
  jsContext: !1,
249
244
  multipleConnections: !0
250
245
  }
251
- ], he = (r) => {
252
- const e = tt.find((a) => a.name === r.vfs), { vfs: t, async: s, worker: n } = r;
253
- if (!e) throw new $(`vfs ${t} not found`);
254
- if (s !== s) throw new $(`vfs ${t} not support async: ${s}`);
255
- if (n && !e.worker) throw new $(`vfs ${t} not support worker`);
256
- if (!n && !e.jsContext) throw new $(`vfs ${t} only support worker`);
246
+ ], de = (r) => {
247
+ const e = et.find((a) => a.name === r.vfs), { vfs: t, async: s, worker: n } = r;
248
+ if (!e) throw new E(`vfs ${t} not found`);
249
+ if (s !== s) throw new E(`vfs ${t} not support async: ${s}`);
250
+ if (n && !e.worker) throw new E(`vfs ${t} not support worker`);
251
+ if (!n && !e.jsContext) throw new E(`vfs ${t} only support worker`);
257
252
  return e;
258
- }, st = async (r) => {
259
- const e = he(r), t = r.async ?? !0;
253
+ }, tt = async (r) => {
254
+ const e = de(r), t = r.async ?? !0;
260
255
  let s;
261
- t ? s = Ze : s = et;
256
+ t ? s = Xe : s = Ze;
262
257
  const [n, a] = await Promise.all([s(), e.vfsModule()]), o = {};
263
258
  r.wasmPath && (o.locateFile = () => r.wasmPath);
264
- const c = await n(o), i = We(c), l = await a.create(r.vfs, c, e.vfsOptions);
259
+ const c = await n(o), i = Fe(c), l = await a.create(r.vfs, c, e.vfsOptions);
265
260
  return i.vfs_register(l, !0), i;
266
- }, _e = (r, e) => `${de}:${r}:${e}`, nt = async (r, e, t, s) => {
261
+ }, he = (r, e) => `${ue}:${r}:${e}`, st = async (r, e, t, s) => {
267
262
  const n = performance.now(), a = s ? [s] : [[]], o = [];
268
263
  let c = 0;
269
264
  const i = {
@@ -276,7 +271,7 @@ const de = "sqlite", Ze = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite-as
276
271
  for (const _ of a)
277
272
  r.reset(l), s && r.bind_collection(l, _);
278
273
  const u = [];
279
- for (; await r.step(l) === Pe; ) {
274
+ for (; await r.step(l) === We; ) {
280
275
  const _ = r.row(l);
281
276
  u.push(_);
282
277
  }
@@ -289,16 +284,16 @@ const de = "sqlite", Ze = () => import("@journeyapps/wa-sqlite/dist/wa-sqlite-as
289
284
  runEnd: performance.now()
290
285
  };
291
286
  };
292
- class rt {
287
+ class nt {
293
288
  #e;
294
289
  #t;
295
290
  changeChanel;
296
291
  async init(e, t) {
297
- const s = await st(t), n = e + ".sqlite";
292
+ const s = await tt(t), n = e + ".sqlite";
298
293
  this.#t = await s.open_v2(n), this.#e = s, await this.execute("PRAGMA temp_store = memory;"), await this.execute("PRAGMA foreign_keys = ON;");
299
294
  const a = t?.cacheSizeKb || 50 * 1024;
300
295
  await this.execute(`PRAGMA cache_size = -${a};`);
301
- const o = _e(e, "changes");
296
+ const o = he(e, "changes");
302
297
  this.changeChanel = new BroadcastChannel(o), this.#e.update_hook(
303
298
  this.#t,
304
299
  (c, i, l, u) => {
@@ -317,51 +312,51 @@ class rt {
317
312
  }
318
313
  async version() {
319
314
  const e = await this.execute("SELECT sqlite_version()");
320
- return Be(e, "results[0].rows[0][0]");
315
+ return De(e, "results[0].rows[0][0]");
321
316
  }
322
317
  async disconnect() {
323
318
  await this.#e.close(this.#t);
324
319
  }
325
320
  async execute(e, t) {
326
- return nt(this.#e, this.#t, e, t);
321
+ return st(this.#e, this.#t, e, t);
327
322
  }
328
323
  }
329
- const at = (r, e, t) => {
330
- const s = E(r), n = [e.id];
324
+ const rt = (r, e, t) => {
325
+ const s = y(r), n = [e.id];
331
326
  return {
332
327
  sql: `DELETE FROM ${s} WHERE id = ?;`,
333
328
  params: n
334
329
  };
335
- }, it = (r, e, t) => {
336
- const s = E(r), n = Ye(r, e);
330
+ }, at = (r, e, t) => {
331
+ const s = y(r), n = Ke(r, e);
337
332
  t?.userId && (n.createdBy = t.userId, n.updatedBy = t.userId), n.createdAt = /* @__PURE__ */ new Date(), n.updatedAt = n.createdAt;
338
- const a = Object.keys(n), o = Y(r, n), c = Array(a.length).fill("?").join(","), i = Object.values(o);
333
+ const a = Object.keys(n), o = H(r, n), c = Array(a.length).fill("?").join(","), i = Object.values(o);
339
334
  return {
340
- sql: `INSERT INTO ${s} (${a.join(",")}) VALUES (${c}) RETURNING rowid as ${R},*;`,
335
+ sql: `INSERT INTO ${s} (${a.join(",")}) VALUES (${c}) RETURNING rowid as ${S},*;`,
341
336
  params: i
342
337
  };
343
- }, ot = (r, e, t) => {
338
+ }, it = (r, e, t) => {
344
339
  const s = {};
345
340
  s.removedAt = /* @__PURE__ */ new Date(), t?.userId && (s.removedBy = t.userId);
346
- const n = E(r), o = Object.keys(s).map((l) => `${l} = ?`).join(","), c = Y(r, s), i = [...Object.values(c), e.id];
341
+ const n = y(r), o = Object.keys(s).map((l) => `${l} = ?`).join(","), c = H(r, s), i = [...Object.values(c), e.id];
347
342
  return {
348
- sql: `UPDATE ${n} SET ${o} WHERE id = ? and removedAt is null and removedBy is null RETURNING rowid as ${R},*;`,
343
+ sql: `UPDATE ${n} SET ${o} WHERE id = ? and removedAt is null and removedBy is null RETURNING rowid as ${S},*;`,
349
344
  params: i
350
345
  };
351
- }, ct = (r, e, t, s) => {
346
+ }, ot = (r, e, t, s) => {
352
347
  const n = He(r, t);
353
348
  n.updatedAt = /* @__PURE__ */ new Date(), s?.userId && (n.updatedBy = s.userId);
354
- const a = Object.keys(n), o = Y(r, n), c = a.map((h) => `${h} = ?`).join(","), i = [...Object.values(o), e.id];
349
+ const a = Object.keys(n), o = H(r, n), c = a.map((h) => `${h} = ?`).join(","), i = [...Object.values(o), e.id];
355
350
  return {
356
- sql: `UPDATE ${E(r)} SET ${c} WHERE id = ? RETURNING rowid as ${R},*;`,
351
+ sql: `UPDATE ${y(r)} SET ${c} WHERE id = ? RETURNING rowid as ${S},*;`,
357
352
  params: i
358
353
  };
359
- }, H = (r) => r?.map((e) => `${e.field} ${e.order}`).join(", "), v = (r, e = /* @__PURE__ */ new Map()) => {
360
- const t = r.rules.map((s) => re(s) ? v(s, e) : lt(s, e)).filter(Boolean);
361
- return t.length === 0 ? "" : t.length === 1 ? t[0] : `(${t.join(re(r) ? ` ${r.combinator} ` : " ")})`;
362
- }, lt = (r, e) => {
354
+ }, J = (r) => r?.map((e) => `${e.field} ${e.order}`).join(", "), v = (r, e = /* @__PURE__ */ new Map()) => {
355
+ const t = r.rules.map((s) => ne(s) ? v(s, e) : ct(s, e)).filter(Boolean);
356
+ return t.length === 0 ? "" : t.length === 1 ? t[0] : `(${t.join(ne(r) ? ` ${r.combinator} ` : " ")})`;
357
+ }, ct = (r, e) => {
363
358
  let t, s;
364
- if (r?.value === null ? r.operator === "=" ? (t = "", s = "is null") : r.operator === "!=" && (t = "", s = "is not null") : (t = dt(r.operator).toLowerCase(), s = ht(r)), !s && ["in", "notIn", "between", "notBetween"].includes(r.operator)) return "";
359
+ if (r?.value === null ? r.operator === "=" ? (t = "", s = "is null") : r.operator === "!=" && (t = "", s = "is not null") : (t = ut(r.operator).toLowerCase(), s = dt(r)), !s && ["in", "notIn", "between", "notBetween"].includes(r.operator)) return "";
365
360
  let n = String(r.field);
366
361
  if (e.has(n))
367
362
  n = e.get(n);
@@ -370,7 +365,7 @@ const at = (r, e, t) => {
370
365
  n = `'${o}'.${c}`;
371
366
  }
372
367
  return `${n} ${t} ${s}`.replaceAll(/ +/g, " ").trim();
373
- }, re = (r) => "rules" in r && "combinator" in r, ut = {
368
+ }, ne = (r) => "rules" in r && "combinator" in r, lt = {
374
369
  "=": "=",
375
370
  "!=": "!=",
376
371
  ">": ">",
@@ -387,7 +382,7 @@ const at = (r, e, t) => {
387
382
  notBeginWith: "NOT LIKE",
388
383
  endWith: "LIKE",
389
384
  notEndWith: "NOT LIKE"
390
- }, dt = (r) => ut[r] || r, ht = (r) => {
385
+ }, ut = (r) => lt[r] || r, dt = (r) => {
391
386
  switch (r.operator) {
392
387
  case "in":
393
388
  case "notIn":
@@ -420,61 +415,61 @@ const at = (r, e, t) => {
420
415
  const h = u.includes("_") ? u : u.split("_")[0], _ = c(h);
421
416
  return o.set(u, _), _;
422
417
  };
423
- Fe(t, (u, h, _) => {
418
+ Be(t, (u, h, _) => {
424
419
  const p = h;
425
420
  if (u !== "field" || p.includes(".") === !1) return;
426
- const { relations: d, isForeignKey: x, propertyName: B } = r.rxdb.schema.getFieldRelations(e, h);
427
- if (x) {
421
+ const { relations: d, isForeignKey: C, propertyName: B } = r.rxdb.schema.getFieldRelations(e, h);
422
+ if (C) {
428
423
  _.field = B;
429
424
  return;
430
425
  }
431
- const pe = p.replace(`.${B}`, ""), F = (N) => d.length === 1 ? N.name : `${pe}_${N.name}`, G = (N) => (s.has(N) || s.set(N, []), s.get(N));
432
- d.forEach(({ metadata: N, relation: g }, z) => {
433
- const C = r.rxdb.schema.findMappedRelation(N, g);
434
- if (!C) throw new $("mappedRelation not found");
426
+ const fe = p.replace(`.${B}`, ""), F = (b) => d.length === 1 ? b.name : `${fe}_${b.name}`, G = (b) => (s.has(b) || s.set(b, []), s.get(b));
427
+ d.forEach(({ metadata: b, relation: T }, z) => {
428
+ const k = r.rxdb.schema.findMappedRelation(b, T);
429
+ if (!k) throw new E("mappedRelation not found");
435
430
  const P = () => {
436
- const O = G(C.metadata), b = F(g), k = i(b);
431
+ const g = G(k.metadata), $ = F(T), x = i($);
437
432
  return {
438
- joinArray: O,
439
- uniqueAlias: k
433
+ joinArray: g,
434
+ uniqueAlias: x
440
435
  };
441
436
  };
442
- let T = "_";
437
+ let N = "_";
443
438
  if (z > 0) {
444
- const O = d[z - 1], b = F(O.relation);
445
- T = i(b);
439
+ const g = d[z - 1], $ = F(g.relation);
440
+ N = i($);
446
441
  }
447
- switch (g.kind) {
448
- case y.ONE_TO_ONE:
449
- case y.ONE_TO_MANY:
442
+ switch (T.kind) {
443
+ case I.ONE_TO_ONE:
444
+ case I.ONE_TO_MANY:
450
445
  {
451
- const { joinArray: O, uniqueAlias: b } = P();
452
- O.push({
453
- joinTableName: b,
454
- on: `'${b}'.${C.relation.name}Id = ${T === "_" ? T : `'${T}'`}.id`
446
+ const { joinArray: g, uniqueAlias: $ } = P();
447
+ g.push({
448
+ joinTableName: $,
449
+ on: `'${$}'.${k.relation.name}Id = ${N === "_" ? N : `'${N}'`}.id`
455
450
  });
456
451
  }
457
452
  break;
458
- case y.MANY_TO_ONE:
453
+ case I.MANY_TO_ONE:
459
454
  {
460
- const { joinArray: O, uniqueAlias: b } = P();
461
- O.push({
462
- joinTableName: b,
463
- on: `'${b}'.id = ${T === "_" ? T : `'${T}'`}.${g.name}Id`
455
+ const { joinArray: g, uniqueAlias: $ } = P();
456
+ g.push({
457
+ joinTableName: $,
458
+ on: `'${$}'.id = ${N === "_" ? N : `'${N}'`}.${T.name}Id`
464
459
  });
465
460
  }
466
461
  break;
467
- case y.MANY_TO_MANY:
462
+ case I.MANY_TO_MANY:
468
463
  {
469
- const O = q(g.junctionEntityType), b = G(O), k = c(`${g.name}_m_n`);
470
- b.push({
471
- joinTableName: k,
472
- on: `'${k}'.${C.relation.name}Id = ${T === "_" ? T : `'${T}'`}.id`
464
+ const g = q(T.junctionEntityType), $ = G(g), x = c(`${T.name}_m_n`);
465
+ $.push({
466
+ joinTableName: x,
467
+ on: `'${x}'.${k.relation.name}Id = ${N === "_" ? N : `'${N}'`}.id`
473
468
  });
474
- const { joinArray: me, uniqueAlias: X } = P();
475
- me.push({
469
+ const { joinArray: pe, uniqueAlias: X } = P();
470
+ pe.push({
476
471
  joinTableName: X,
477
- on: `'${X}'.id = '${k}'.${g.name}Id`
472
+ on: `'${X}'.id = '${x}'.${T.name}Id`
478
473
  });
479
474
  }
480
475
  break;
@@ -482,38 +477,38 @@ const at = (r, e, t) => {
482
477
  });
483
478
  const W = d[d.length - 1];
484
479
  if (r.rxdb.schema.findMappedRelation(W.metadata, W.relation)) {
485
- const N = F(W.relation), g = i(N);
486
- a.set(p, `'${g}'.${B}`);
480
+ const b = F(W.relation), T = i(b);
481
+ a.set(p, `'${T}'.${B}`);
487
482
  }
488
483
  });
489
484
  let l = "";
490
485
  for (const [u, h] of s.entries()) {
491
- const _ = E(u);
486
+ const _ = y(u);
492
487
  for (const p of h)
493
488
  l += ` LEFT JOIN ${_} '${p.joinTableName}' ON ${p.on}`;
494
489
  }
495
490
  return { joinSQL: l, fieldAliasMap: a };
496
- }, J = (r) => {
491
+ }, Y = (r) => {
497
492
  const { tableName: e, where: t, limit: s, orderBy: n, join: a } = r;
498
- let o = `SELECT _.rowid as ${R}, _.* FROM ${e} _`;
493
+ let o = `SELECT _.rowid as ${S}, _.* FROM ${e} _`;
499
494
  return a && (o += a), t && (o += ` where ${t}`), n && (o += ` order by ${n}`), s && (o += ` limit ${s}`), o += ";", o;
500
- }, _t = (r, e, t, s) => {
495
+ }, ht = (r, e, t, s) => {
501
496
  t = structuredClone(t);
502
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
497
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = y(e), c = v(t, a), i = J(s?.orderBy);
503
498
  return {
504
- sql: J({ tableName: o, where: c, orderBy: i, join: n }),
499
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n }),
505
500
  params: []
506
501
  };
507
- }, ft = (r, e, t, s) => {
502
+ }, _t = (r, e, t, s) => {
508
503
  t = structuredClone(t);
509
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
504
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = y(e), c = v(t, a), i = J(s?.orderBy);
510
505
  return {
511
- sql: J({ tableName: o, where: c, orderBy: i, join: n }),
506
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n }),
512
507
  params: []
513
508
  };
514
- }, pt = (r, e, t, s) => {
509
+ }, ft = (r, e, t, s) => {
515
510
  t = structuredClone(t);
516
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a);
511
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = y(e), c = v(t, a);
517
512
  let i = `SELECT count(_.rowid) as count FROM ${o} _`;
518
513
  return n && (i += n), c && (i += ` where ${c}`), {
519
514
  sql: i,
@@ -521,24 +516,24 @@ const at = (r, e, t) => {
521
516
  };
522
517
  }, V = (r, e, t, s) => {
523
518
  t = structuredClone(t);
524
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
519
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = y(e), c = v(t, a), i = J(s?.orderBy);
525
520
  return {
526
- sql: J({ tableName: o, where: c, orderBy: i, join: n, limit: 1 }),
521
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n, limit: 1 }),
527
522
  params: []
528
523
  };
529
524
  };
530
- class mt extends $e {
525
+ class pt extends ye {
531
526
  constructor(e, t, s) {
532
- super(e.rxdb, s), this.adapter = e, this.client$ = t, this.metadata = q(s), this.run_task$.subscribe(() => this.#e()), this.rxdb.addEventListener(be, () => {
527
+ super(e.rxdb, s), this.adapter = e, this.client$ = t, this.metadata = q(s), this.run_task$.subscribe(() => this.#e()), this.rxdb.addEventListener($e, () => {
533
528
  this.transaction_pending = !0;
534
- }), this.rxdb.addEventListener(Ne, () => {
529
+ }), this.rxdb.addEventListener(be, () => {
535
530
  this.transaction_pending = !1, this.transaction_entities.forEach((n) => this.merge_cache(n.type, n.entities)), this.transaction_entities = [];
536
- }), this.rxdb.addEventListener(Te, () => {
531
+ }), this.rxdb.addEventListener(Ne, () => {
537
532
  this.transaction_pending = !1, this.transaction_entities = [];
538
533
  });
539
534
  }
540
535
  metadata;
541
- need_run_task = new ke();
536
+ need_run_task = new ve();
542
537
  run_task$ = this.need_run_task.asObservable().pipe(xe(16));
543
538
  cache_query_task_map = /* @__PURE__ */ new Map();
544
539
  cache_query_tasks = [];
@@ -561,7 +556,7 @@ class mt extends $e {
561
556
  add_query_cache(e, t = !1) {
562
557
  const s = [];
563
558
  return e.results.forEach(({ columns: n, rows: a }) => {
564
- const o = n.findIndex((i) => i === "id"), c = n.findIndex((i) => i === R);
559
+ const o = n.findIndex((i) => i === "id"), c = n.findIndex((i) => i === S);
565
560
  a.forEach((i) => {
566
561
  const l = i[o];
567
562
  let u;
@@ -574,7 +569,7 @@ class mt extends $e {
574
569
  const _ = se(this.metadata, n, i);
575
570
  u = this.createEntityRef(_), s.push(u);
576
571
  }
577
- const h = ae(u);
572
+ const h = re(u);
578
573
  h.local = !0, c !== -1 && (h.rowId = BigInt(i[c])), h.modified = !1;
579
574
  });
580
575
  }), s;
@@ -586,13 +581,13 @@ class mt extends $e {
586
581
  const { sql: t, params: s } = e, n = t + s.join(",");
587
582
  let a;
588
583
  if (this.cache_query_task_map.has(n) === !1) {
589
- const o = new U(), c = o.asObservable(), i = new ie(0), l = i.asObservable(), u = new oe((p) => {
584
+ const o = new U(), c = o.asObservable(), i = new ae(0), l = i.asObservable(), u = new ie((p) => {
590
585
  const d = this.cache_query_task_map.get(n);
591
586
  return d.observerCount++, a = p, _(), () => {
592
587
  if (d.observerCount--, d.observerCount <= 0) {
593
588
  o.next(), o.complete(), this.cache_query_task_map.delete(n);
594
- const x = this.cache_query_tasks.indexOf(d);
595
- x >= 0 && this.cache_query_tasks.splice(x, 1);
589
+ const C = this.cache_query_tasks.indexOf(d);
590
+ C >= 0 && this.cache_query_tasks.splice(C, 1);
596
591
  }
597
592
  };
598
593
  }).pipe(L(1)), h = {
@@ -630,7 +625,7 @@ class mt extends $e {
630
625
  });
631
626
  }
632
627
  }
633
- class fe extends mt {
628
+ class _e extends pt {
634
629
  #e = /* @__PURE__ */ new Map();
635
630
  get(e, t) {
636
631
  const s = {
@@ -646,7 +641,7 @@ class fe extends mt {
646
641
  return this.#s("get", a, s, t), a.result$.pipe(
647
642
  f((o) => this.#t(a, o)),
648
643
  f((o) => {
649
- if (o.length === 0) throw new $("not found");
644
+ if (o.length === 0) throw new E("not found");
650
645
  return o[0];
651
646
  })
652
647
  );
@@ -664,54 +659,54 @@ class fe extends mt {
664
659
  f((a) => this.#t(n, a)),
665
660
  f((a) => {
666
661
  if (a.length === 0)
667
- throw new $("not found");
662
+ throw new E("not found");
668
663
  return a[0];
669
664
  })
670
665
  );
671
666
  }
672
667
  find(e, t) {
673
- const s = _t(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
668
+ const s = ht(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
674
669
  return this.#s("find", n, e, t), n.result$.pipe(f((a) => this.#t(n, a)));
675
670
  }
676
671
  findAll(e, t) {
677
- const s = ft(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
672
+ const s = _t(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
678
673
  return this.#s("findAll", n, e, t), n.result$.pipe(f((a) => this.#t(n, a)));
679
674
  }
680
675
  findByCursor(e, t) {
681
- throw new Error("Method not implemented.");
676
+ throw new E("Method not implemented.");
682
677
  }
683
678
  count(e, t) {
684
- const s = pt(this.adapter, this.metadata, e), n = this.create_query_task(s);
679
+ const s = ft(this.adapter, this.metadata, e), n = this.create_query_task(s);
685
680
  return this.#s("count", n, e, t), n.result$.pipe(f((a) => a.results[0].rows[0][0]));
686
681
  }
687
682
  create(e) {
688
- return I(this.#r(e));
683
+ return O(this.#r(e));
689
684
  }
690
685
  update(e, t) {
691
- return I(this.#i(e, t));
686
+ return O(this.#i(e, t));
692
687
  }
693
688
  remove(e) {
694
- const t = ae(e), s = () => {
689
+ const t = re(e), s = () => {
695
690
  t.origin = structuredClone({ ...e }), t.modified = !1, t.removed = !0;
696
691
  };
697
692
  if (t.local === !0) {
698
- const { sql: a, params: o } = at(this.metadata, e, this.rxdb.context), c = this.client$.pipe(
693
+ const { sql: a, params: o } = rt(this.metadata, e, this.rxdb.context), c = this.client$.pipe(
699
694
  Q(1),
700
695
  w(() => this.adapter.execute(a, o)),
701
696
  f(() => (e.removedAt = /* @__PURE__ */ new Date(), this.rxdb.context?.userId && (e.removedBy = this.rxdb.context.userId), s(), e)),
702
697
  A(() => s()),
703
698
  A((i) => this.merge_cache("remove", [i]))
704
699
  );
705
- return I(c);
700
+ return O(c);
706
701
  } else if (t.remote === !0) {
707
- const { sql: a, params: o } = ot(this.metadata, e, this.rxdb.context), c = this.#n("remove", a, o).pipe(
702
+ const { sql: a, params: o } = it(this.metadata, e, this.rxdb.context), c = this.#n("remove", a, o).pipe(
708
703
  A(() => s()),
709
704
  f((i) => i[0])
710
705
  );
711
- return I(c);
706
+ return O(c);
712
707
  }
713
708
  const n = q(e);
714
- throw new $(`Remove Error${n.name}(${e.id}) not saved local.`);
709
+ throw new E(`Remove Error${n.name}(${e.id}) not saved local.`);
715
710
  }
716
711
  /**
717
712
  * 根据 type 计算主动更新缓存策略
@@ -733,7 +728,7 @@ class fe extends mt {
733
728
  this.#l(n, s, t);
734
729
  break;
735
730
  default:
736
- throw new Error("unknown type");
731
+ throw new E("unknown type");
737
732
  }
738
733
  }
739
734
  }
@@ -742,11 +737,11 @@ class fe extends mt {
742
737
  return e.resultEntities = s, e.resultEntityIds = s.map((n) => n.id), s;
743
738
  }
744
739
  #r(e) {
745
- const { sql: t, params: s } = it(this.metadata, e, this.rxdb.context);
740
+ const { sql: t, params: s } = at(this.metadata, e, this.rxdb.context);
746
741
  return this.#n("create", t, s).pipe(f((n) => n[0]));
747
742
  }
748
743
  #i(e, t) {
749
- const { sql: s, params: n } = ct(this.metadata, e, t, this.rxdb.context);
744
+ const { sql: s, params: n } = ot(this.metadata, e, t, this.rxdb.context);
750
745
  return this.#n("update", s, n).pipe(f((a) => a[0]));
751
746
  }
752
747
  #s(e, t, s, n) {
@@ -776,12 +771,12 @@ class fe extends mt {
776
771
  case "findByCursor":
777
772
  case "count":
778
773
  case "findAll":
779
- s.some((c) => S(c, a)) && t.refresh();
774
+ s.some((c) => R(c, a)) && t.refresh();
780
775
  break;
781
776
  }
782
777
  }
783
778
  #c(e, t, s) {
784
- const n = s.map((u) => u.id), a = t.resultEntityIds.some((u) => n.includes(u)), { type: o, where: c, options: i } = e, l = s.some((u) => S(u, c));
779
+ const n = s.map((u) => u.id), a = t.resultEntityIds.some((u) => n.includes(u)), { type: o, where: c, options: i } = e, l = s.some((u) => R(u, c));
785
780
  switch (o) {
786
781
  case "count":
787
782
  l !== a && t.refresh();
@@ -806,22 +801,22 @@ class fe extends mt {
806
801
  case "findByCursor":
807
802
  case "count":
808
803
  case "findAll":
809
- (a || s.some((i) => S(i, c))) && t.refresh();
804
+ (a || s.some((i) => R(i, c))) && t.refresh();
810
805
  break;
811
806
  }
812
807
  }
813
808
  }
814
809
  const D = (r, e, t, s) => {
815
- const n = s?.level || 0, a = E(r), o = n > 0 ? `c.level < ${n}` : "";
810
+ const n = s?.level || 0, a = y(r), o = n > 0 ? `c.level < ${n}` : "";
816
811
  let c = "";
817
812
  const i = [o, v(t)].filter(Boolean).join(" AND ");
818
813
  return i && (c = `WHERE ${i}`), {
819
814
  sql: `WITH RECURSIVE __children AS (
820
- SELECT *,rowid as ${R}, 0 AS level
815
+ SELECT *,rowid as ${S}, 0 AS level
821
816
  FROM ${a}
822
817
  WHERE id = ?
823
818
  UNION ALL
824
- SELECT children.*,children.rowid as ${R}, c.level + 1
819
+ SELECT children.*,children.rowid as ${S}, c.level + 1
825
820
  FROM ${a} children
826
821
  JOIN __children c ON ${s.descendants ? "children.parentId = c.id" : "children.id = c.parentId"}
827
822
  ${c}
@@ -830,23 +825,23 @@ SELECT ${s.count ? "count(*)-1 as count" : "*"} FROM __children
830
825
  ORDER BY level, id;`,
831
826
  params: [e]
832
827
  };
833
- }, Et = (r, e, t, s) => D(r, e, t, { ...s, descendants: !0 }), yt = (r, e, t, s) => D(r, e, t, { ...s, descendants: !1 }), $t = (r, e, t, s) => D(r, e, t, { ...s, descendants: !0, count: !0 }), bt = (r, e, t, s) => D(r, e, t, { ...s, descendants: !1, count: !0 });
834
- class Nt extends fe {
828
+ }, mt = (r, e, t, s) => D(r, e, t, { ...s, descendants: !0 }), Et = (r, e, t, s) => D(r, e, t, { ...s, descendants: !1 }), yt = (r, e, t, s) => D(r, e, t, { ...s, descendants: !0, count: !0 }), $t = (r, e, t, s) => D(r, e, t, { ...s, descendants: !1, count: !0 });
829
+ class bt extends _e {
835
830
  #e = /* @__PURE__ */ new Map();
836
831
  findDescendants(e, t, s) {
837
- const n = Et(this.metadata, e.id, t, s), a = this.create_query_task(n);
832
+ const n = mt(this.metadata, e.id, t, s), a = this.create_query_task(n);
838
833
  return this.#r("findDescendants", a, e.id, t, s), a.result$.pipe(f((o) => this.#t(a, o)));
839
834
  }
840
835
  countDescendants(e, t, s) {
841
- const n = $t(this.metadata, e.id, t, s), a = this.create_query_task(n);
836
+ const n = yt(this.metadata, e.id, t, s), a = this.create_query_task(n);
842
837
  return this.#r("countDescendants", a, e.id, t, s), a.result$.pipe(f((o) => o.results[0].rows[0][0]));
843
838
  }
844
839
  findAncestors(e, t, s) {
845
- const n = yt(this.metadata, e.id, t, s), a = this.create_query_task(n);
840
+ const n = Et(this.metadata, e.id, t, s), a = this.create_query_task(n);
846
841
  return this.#r("findAncestors", a, e.id, t, s), a.result$.pipe(f((o) => this.#t(a, o)));
847
842
  }
848
843
  countAncestors(e, t, s) {
849
- const n = bt(this.metadata, e.id, t, s), a = this.create_query_task(n);
844
+ const n = $t(this.metadata, e.id, t, s), a = this.create_query_task(n);
850
845
  return this.#r("countAncestors", a, e.id, t, s), a.result$.pipe(f((o) => o.results[0].rows[0][0]));
851
846
  }
852
847
  /**
@@ -869,7 +864,7 @@ class Nt extends fe {
869
864
  this.#n(n, s, t);
870
865
  break;
871
866
  default:
872
- throw new Error("unknown type");
867
+ throw new E("unknown type");
873
868
  }
874
869
  }
875
870
  }
@@ -888,7 +883,7 @@ class Nt extends fe {
888
883
  #i(e, t, s) {
889
884
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
890
885
  let i = !0;
891
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
886
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
892
887
  case "findDescendants":
893
888
  case "countDescendants":
894
889
  c && i && t.refresh();
@@ -898,7 +893,7 @@ class Nt extends fe {
898
893
  #s(e, t, s) {
899
894
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
900
895
  let i = !0;
901
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
896
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
902
897
  case "findDescendants":
903
898
  case "countDescendants":
904
899
  case "findAncestors":
@@ -910,7 +905,7 @@ class Nt extends fe {
910
905
  #n(e, t, s) {
911
906
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
912
907
  let i = !0;
913
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
908
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
914
909
  case "findDescendants":
915
910
  case "countDescendants":
916
911
  case "findAncestors":
@@ -920,10 +915,10 @@ class Nt extends fe {
920
915
  }
921
916
  }
922
917
  }
923
- class vt extends Ae {
918
+ class Rt extends Oe {
924
919
  constructor(e, t) {
925
920
  super(e), this.options = t;
926
- const s = _e(e.options.dbName, "changes");
921
+ const s = he(e.options.dbName, "changes");
927
922
  this.#r = new BroadcastChannel(s), this.#i = Ce(this.#r, "message"), this.#i.pipe(K(this.#e)).subscribe((n) => {
928
923
  const a = n.data, { dbName: o, tableName: c, rowid: i, recordAt: l, timeStamp: u } = a;
929
924
  if (!o || !c || !i) return;
@@ -939,10 +934,10 @@ class vt extends Ae {
939
934
  this.rxdb.dispatchEvent(new Se(p, d));
940
935
  break;
941
936
  case M.SQLITE_INSERT:
942
- this.rxdb.dispatchEvent(new Re(p, d));
937
+ this.rxdb.dispatchEvent(new qe(p, d));
943
938
  break;
944
939
  case M.SQLITE_UPDATE:
945
- this.rxdb.dispatchEvent(new qe(p, d));
940
+ this.rxdb.dispatchEvent(new Ae(p, d));
946
941
  break;
947
942
  }
948
943
  }), this.#_.pipe(K(this.#e)).subscribe();
@@ -956,22 +951,22 @@ class vt extends Ae {
956
951
  #s = [];
957
952
  #n = /* @__PURE__ */ new Map();
958
953
  #o = !1;
959
- #c = new ie(0);
954
+ #c = new ae(0);
960
955
  #l = this.#c.asObservable();
961
956
  // sqlite 客户端
962
- #a = new oe((e) => {
957
+ #a = new ie((e) => {
963
958
  const { vfs: t, async: s, worker: n, wasmPath: a, workerInstance: o } = this.options, c = {
964
959
  vfs: t,
965
960
  async: s,
966
961
  worker: n,
967
962
  wasmPath: a
968
963
  };
969
- he(c);
964
+ de(c);
970
965
  let i;
971
- n && o ? i = ve(o) : i = new rt(), i.init(this.rxdb.options.dbName, c).then(() => e.next(i));
966
+ n && o ? i = Re(o) : i = new nt(), i.init(this.rxdb.options.dbName, c).then(() => e.next(i));
972
967
  }).pipe(L(1));
973
968
  // 已连接
974
- #h = Le(() => this.rxdb.connect(this.name)).pipe(L(1));
969
+ #h = ke(() => this.rxdb.connect(this.name)).pipe(L(1));
975
970
  // 队列
976
971
  #_ = this.#l.pipe(
977
972
  Z(() => this.#o === !1),
@@ -985,15 +980,9 @@ class vt extends Ae {
985
980
  w((s) => s.execute(e.sql, e.bindings)),
986
981
  A((s) => t.next(s)),
987
982
  A(() => setTimeout(() => this.#n.delete(e.key), 0)),
988
- Me((s) => {
983
+ Le((s) => {
989
984
  const n = s.message || "执行错误";
990
- return t.error(
991
- new $("${msg} ${sql} ${bindings}", {
992
- msg: n,
993
- sql: e.sql,
994
- bindings: JSON.stringify(e.bindings)
995
- })
996
- ), je({ error: s });
985
+ return t.error(new E(`${n} ${e.sql} ${JSON.stringify(e.bindings)}`)), Me({ error: s });
997
986
  })
998
987
  );
999
988
  }),
@@ -1001,7 +990,7 @@ class vt extends Ae {
1001
990
  this.#o = !1, this.#u();
1002
991
  })
1003
992
  );
1004
- name = de;
993
+ name = ue;
1005
994
  /**
1006
995
  * 数据库版本
1007
996
  */
@@ -1025,7 +1014,7 @@ class vt extends Ae {
1025
1014
  * 获取版本
1026
1015
  */
1027
1016
  version() {
1028
- return I(this.version$);
1017
+ return O(this.version$);
1029
1018
  }
1030
1019
  /**
1031
1020
  * 获取实体仓库
@@ -1037,13 +1026,13 @@ class vt extends Ae {
1037
1026
  let s;
1038
1027
  switch (t.repository) {
1039
1028
  case "Repository":
1040
- s = new fe(this, this.#a, e);
1029
+ s = new _e(this, this.#a, e);
1041
1030
  break;
1042
1031
  case "TreeRepository":
1043
- s = new Nt(this, this.#a, e);
1032
+ s = new bt(this, this.#a, e);
1044
1033
  break;
1045
1034
  default:
1046
- throw new $("Unsupported repository type: " + t.repository);
1035
+ throw new E("Unsupported repository type: " + t.repository);
1047
1036
  }
1048
1037
  return this.#t.set(e, s), s;
1049
1038
  }
@@ -1054,15 +1043,15 @@ class vt extends Ae {
1054
1043
  * @param EntityType
1055
1044
  */
1056
1045
  isTableExisted(e) {
1057
- return I(this.isTableExisted$(e));
1046
+ return O(this.isTableExisted$(e));
1058
1047
  }
1059
1048
  /**
1060
1049
  * 判断表是否存在
1061
1050
  * @param EntityType
1062
1051
  */
1063
1052
  isTableExisted$(e) {
1064
- const t = q(e), s = E(t);
1065
- return this.#d(Ve(s)).pipe(f((n) => Ue(n) === !1));
1053
+ const t = q(e), s = y(t);
1054
+ return this.#d(Pe(s)).pipe(f((n) => Ve(n) === !1));
1066
1055
  }
1067
1056
  /**
1068
1057
  * 创建 table
@@ -1070,13 +1059,13 @@ class vt extends Ae {
1070
1059
  */
1071
1060
  createTable(e) {
1072
1061
  const t = q(e);
1073
- let s = ze(this, t);
1062
+ let s = Ge(this, t);
1074
1063
  if (t.log !== !1) {
1075
- const n = Xe(this, t);
1064
+ const n = ze(this, t);
1076
1065
  s += `
1077
1066
  ` + n;
1078
1067
  }
1079
- return I(this.#d(s).pipe(f(() => !0)));
1068
+ return O(this.#d(s).pipe(f(() => !0)));
1080
1069
  }
1081
1070
  /**
1082
1071
  * 执行 sql
@@ -1096,19 +1085,19 @@ class vt extends Ae {
1096
1085
  * @param callback
1097
1086
  */
1098
1087
  transaction(e) {
1099
- return I(this.transaction$(e));
1088
+ return O(this.transaction$(e));
1100
1089
  }
1101
1090
  transaction$(e) {
1102
1091
  return this.#a.pipe(
1103
1092
  w(async (t) => {
1104
- this.rxdb.dispatchEvent(Tt), await t.execute("BEGIN; PRAGMA defer_foreign_keys = ON;");
1093
+ this.rxdb.dispatchEvent(Nt), await t.execute("BEGIN; PRAGMA defer_foreign_keys = ON;");
1105
1094
  try {
1106
1095
  const s = await e();
1107
1096
  return await t.execute("COMMIT"), this.rxdb.dispatchEvent(wt), s;
1108
1097
  } catch (s) {
1109
- await t.execute("ROLLBACK"), this.rxdb.dispatchEvent(gt);
1098
+ await t.execute("ROLLBACK"), this.rxdb.dispatchEvent(Tt);
1110
1099
  const n = s?.message || "Transaction Error";
1111
- throw new $(n);
1100
+ throw new E(n);
1112
1101
  }
1113
1102
  })
1114
1103
  );
@@ -1126,11 +1115,11 @@ class vt extends Ae {
1126
1115
  return this.#a.pipe(w((s) => ee(s.execute(e, t))));
1127
1116
  }
1128
1117
  }
1129
- const Tt = new ge(), wt = new Oe(), gt = new Ie();
1118
+ const Nt = new Te(), wt = new ge(), Tt = new Ie();
1130
1119
  export {
1131
- vt as RxDBAdapterSqlite,
1132
- $ as RxdbAdapterSqliteError,
1133
- rt as SqliteClient,
1134
- tt as WA_SQLITE_VFS_LIST,
1135
- st as sqliteLoad
1120
+ Rt as RxDBAdapterSqlite,
1121
+ E as RxdbAdapterSqliteError,
1122
+ nt as SqliteClient,
1123
+ et as WA_SQLITE_VFS_LIST,
1124
+ tt as sqliteLoad
1136
1125
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-sqlite",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "dependencies": {
7
- "@aiao/rxdb": "*",
8
- "@aiao/utils": "0.0.1",
7
+ "@aiao/rxdb": "0.0.2",
8
+ "@aiao/utils": "0.0.2",
9
9
  "rxjs": "~7.8.0",
10
10
  "@journeyapps/wa-sqlite": "^1.2.4",
11
11
  "comlink": "^4.4.2"