@aiao/rxdb-adapter-sqlite 0.0.1 → 0.0.3

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 +199 -211
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,57 +1,57 @@
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 y, 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
- case m.uuid:
9
- case m.string:
10
- case m.json:
8
+ case y.uuid:
9
+ case y.string:
10
+ case y.json:
11
11
  return "TEXT";
12
- case m.number:
12
+ case y.number:
13
13
  return "REAL";
14
- case m.integer:
15
- case m.boolean:
14
+ case y.integer:
15
+ case y.boolean:
16
16
  return "INTEGER";
17
- case m.date:
17
+ default:
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) {
24
- case m.boolean:
24
+ case y.boolean:
25
25
  return r ? 1 : 0;
26
- case m.date:
26
+ case y.date:
27
27
  return r instanceof Date ? r.toISOString() : 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) {
35
- case m.boolean:
35
+ case y.boolean:
36
36
  return !!r;
37
- case m.date:
37
+ case y.date:
38
38
  return r;
39
- case m.json:
39
+ case y.json:
40
40
  return r ? JSON.parse(r) : null;
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}`, E = (r) => ce(r.name, r.namespace), le = (r, e) => `idx_${r.name}_${e.name}`;
45
+ class m 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,55 +59,50 @@ 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
67
  const s = E(e);
73
- return Array.from(e.relationMap.values())?.toSorted((n, a) => ne[n.kind] - ne[a.kind]).forEach((n) => {
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) => {
85
+ }, Ye = (r, e) => {
91
86
  const t = E(e);
92
87
  let s = `CREATE TABLE ${t} (`;
93
88
  const n = [], a = [], o = [];
94
89
  e.propertyMap.forEach((i) => {
95
90
  let l = "";
96
- 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";
91
+ if (l += `"${i.name}"`, i.primary ? i.type === y.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
- case m.json:
97
+ case y.json:
103
98
  a.push(`CHECK ( JSON_VALID(${i.name})=1 )`);
104
99
  break;
105
- case m.boolean:
100
+ case y.boolean:
106
101
  a.push(`CHECK (${i.name} in(0,1))`);
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 m("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 = E(e), s = q(Ee), 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}
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 m(`vfs ${t} not found`);
249
+ if (s !== s) throw new m(`vfs ${t} not support async: ${s}`);
250
+ if (n && !e.worker) throw new m(`vfs ${t} not support worker`);
251
+ if (!n && !e.jsContext) throw new m(`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,20 +284,19 @@ 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) => {
305
- if (!l) return;
306
300
  const h = {
307
301
  type: c,
308
302
  dbName: i,
@@ -317,51 +311,51 @@ class rt {
317
311
  }
318
312
  async version() {
319
313
  const e = await this.execute("SELECT sqlite_version()");
320
- return Be(e, "results[0].rows[0][0]");
314
+ return De(e, "results[0].rows[0][0]");
321
315
  }
322
316
  async disconnect() {
323
317
  await this.#e.close(this.#t);
324
318
  }
325
319
  async execute(e, t) {
326
- return nt(this.#e, this.#t, e, t);
320
+ return st(this.#e, this.#t, e, t);
327
321
  }
328
322
  }
329
- const at = (r, e, t) => {
323
+ const rt = (r, e, t) => {
330
324
  const s = E(r), n = [e.id];
331
325
  return {
332
326
  sql: `DELETE FROM ${s} WHERE id = ?;`,
333
327
  params: n
334
328
  };
335
- }, it = (r, e, t) => {
336
- const s = E(r), n = Ye(r, e);
329
+ }, at = (r, e, t) => {
330
+ const s = E(r), n = Ke(r, e);
337
331
  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);
332
+ const a = Object.keys(n), o = H(r, n), c = Array(a.length).fill("?").join(","), i = Object.values(o);
339
333
  return {
340
- sql: `INSERT INTO ${s} (${a.join(",")}) VALUES (${c}) RETURNING rowid as ${R},*;`,
334
+ sql: `INSERT INTO ${s} (${a.join(",")}) VALUES (${c}) RETURNING rowid as ${S},*;`,
341
335
  params: i
342
336
  };
343
- }, ot = (r, e, t) => {
337
+ }, it = (r, e, t) => {
344
338
  const s = {};
345
339
  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];
340
+ const n = E(r), o = Object.keys(s).map((l) => `${l} = ?`).join(","), c = H(r, s), i = [...Object.values(c), e.id];
347
341
  return {
348
- sql: `UPDATE ${n} SET ${o} WHERE id = ? and removedAt is null and removedBy is null RETURNING rowid as ${R},*;`,
342
+ sql: `UPDATE ${n} SET ${o} WHERE id = ? and removedAt is null and removedBy is null RETURNING rowid as ${S},*;`,
349
343
  params: i
350
344
  };
351
- }, ct = (r, e, t, s) => {
345
+ }, ot = (r, e, t, s) => {
352
346
  const n = He(r, t);
353
347
  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];
348
+ const a = Object.keys(n), o = H(r, n), c = a.map((h) => `${h} = ?`).join(","), i = [...Object.values(o), e.id];
355
349
  return {
356
- sql: `UPDATE ${E(r)} SET ${c} WHERE id = ? RETURNING rowid as ${R},*;`,
350
+ sql: `UPDATE ${E(r)} SET ${c} WHERE id = ? RETURNING rowid as ${S},*;`,
357
351
  params: i
358
352
  };
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) => {
353
+ }, J = (r) => r?.map((e) => `${e.field} ${e.order}`).join(", "), v = (r, e = /* @__PURE__ */ new Map()) => {
354
+ const t = r.rules.map((s) => ne(s) ? v(s, e) : ct(s, e)).filter(Boolean);
355
+ return t.length === 0 ? "" : t.length === 1 ? t[0] : `(${t.join(ne(r) ? ` ${r.combinator} ` : " ")})`;
356
+ }, ct = (r, e) => {
363
357
  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 "";
358
+ 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
359
  let n = String(r.field);
366
360
  if (e.has(n))
367
361
  n = e.get(n);
@@ -370,7 +364,7 @@ const at = (r, e, t) => {
370
364
  n = `'${o}'.${c}`;
371
365
  }
372
366
  return `${n} ${t} ${s}`.replaceAll(/ +/g, " ").trim();
373
- }, re = (r) => "rules" in r && "combinator" in r, ut = {
367
+ }, ne = (r) => "rules" in r && "combinator" in r, lt = {
374
368
  "=": "=",
375
369
  "!=": "!=",
376
370
  ">": ">",
@@ -387,7 +381,7 @@ const at = (r, e, t) => {
387
381
  notBeginWith: "NOT LIKE",
388
382
  endWith: "LIKE",
389
383
  notEndWith: "NOT LIKE"
390
- }, dt = (r) => ut[r] || r, ht = (r) => {
384
+ }, ut = (r) => lt[r] || r, dt = (r) => {
391
385
  switch (r.operator) {
392
386
  case "in":
393
387
  case "notIn":
@@ -420,61 +414,61 @@ const at = (r, e, t) => {
420
414
  const h = u.includes("_") ? u : u.split("_")[0], _ = c(h);
421
415
  return o.set(u, _), _;
422
416
  };
423
- Fe(t, (u, h, _) => {
417
+ Be(t, (u, h, _) => {
424
418
  const p = h;
425
419
  if (u !== "field" || p.includes(".") === !1) return;
426
- const { relations: d, isForeignKey: x, propertyName: B } = r.rxdb.schema.getFieldRelations(e, h);
427
- if (x) {
420
+ const { relations: d, isForeignKey: C, propertyName: B } = r.rxdb.schema.getFieldRelations(e, h);
421
+ if (C) {
428
422
  _.field = B;
429
423
  return;
430
424
  }
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");
425
+ 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));
426
+ d.forEach(({ metadata: b, relation: T }, z) => {
427
+ const k = r.rxdb.schema.findMappedRelation(b, T);
428
+ if (!k) throw new m("mappedRelation not found");
435
429
  const P = () => {
436
- const O = G(C.metadata), b = F(g), k = i(b);
430
+ const g = G(k.metadata), $ = F(T), x = i($);
437
431
  return {
438
- joinArray: O,
439
- uniqueAlias: k
432
+ joinArray: g,
433
+ uniqueAlias: x
440
434
  };
441
435
  };
442
- let T = "_";
436
+ let N = "_";
443
437
  if (z > 0) {
444
- const O = d[z - 1], b = F(O.relation);
445
- T = i(b);
438
+ const g = d[z - 1], $ = F(g.relation);
439
+ N = i($);
446
440
  }
447
- switch (g.kind) {
448
- case y.ONE_TO_ONE:
449
- case y.ONE_TO_MANY:
441
+ switch (T.kind) {
442
+ case I.ONE_TO_ONE:
443
+ case I.ONE_TO_MANY:
450
444
  {
451
- const { joinArray: O, uniqueAlias: b } = P();
452
- O.push({
453
- joinTableName: b,
454
- on: `'${b}'.${C.relation.name}Id = ${T === "_" ? T : `'${T}'`}.id`
445
+ const { joinArray: g, uniqueAlias: $ } = P();
446
+ g.push({
447
+ joinTableName: $,
448
+ on: `'${$}'.${k.relation.name}Id = ${N === "_" ? N : `'${N}'`}.id`
455
449
  });
456
450
  }
457
451
  break;
458
- case y.MANY_TO_ONE:
452
+ case I.MANY_TO_ONE:
459
453
  {
460
- const { joinArray: O, uniqueAlias: b } = P();
461
- O.push({
462
- joinTableName: b,
463
- on: `'${b}'.id = ${T === "_" ? T : `'${T}'`}.${g.name}Id`
454
+ const { joinArray: g, uniqueAlias: $ } = P();
455
+ g.push({
456
+ joinTableName: $,
457
+ on: `'${$}'.id = ${N === "_" ? N : `'${N}'`}.${T.name}Id`
464
458
  });
465
459
  }
466
460
  break;
467
- case y.MANY_TO_MANY:
461
+ case I.MANY_TO_MANY:
468
462
  {
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`
463
+ const g = q(T.junctionEntityType), $ = G(g), x = c(`${T.name}_m_n`);
464
+ $.push({
465
+ joinTableName: x,
466
+ on: `'${x}'.${k.relation.name}Id = ${N === "_" ? N : `'${N}'`}.id`
473
467
  });
474
- const { joinArray: me, uniqueAlias: X } = P();
475
- me.push({
468
+ const { joinArray: pe, uniqueAlias: X } = P();
469
+ pe.push({
476
470
  joinTableName: X,
477
- on: `'${X}'.id = '${k}'.${g.name}Id`
471
+ on: `'${X}'.id = '${x}'.${T.name}Id`
478
472
  });
479
473
  }
480
474
  break;
@@ -482,8 +476,8 @@ const at = (r, e, t) => {
482
476
  });
483
477
  const W = d[d.length - 1];
484
478
  if (r.rxdb.schema.findMappedRelation(W.metadata, W.relation)) {
485
- const N = F(W.relation), g = i(N);
486
- a.set(p, `'${g}'.${B}`);
479
+ const b = F(W.relation), T = i(b);
480
+ a.set(p, `'${T}'.${B}`);
487
481
  }
488
482
  });
489
483
  let l = "";
@@ -493,25 +487,25 @@ const at = (r, e, t) => {
493
487
  l += ` LEFT JOIN ${_} '${p.joinTableName}' ON ${p.on}`;
494
488
  }
495
489
  return { joinSQL: l, fieldAliasMap: a };
496
- }, J = (r) => {
490
+ }, Y = (r) => {
497
491
  const { tableName: e, where: t, limit: s, orderBy: n, join: a } = r;
498
- let o = `SELECT _.rowid as ${R}, _.* FROM ${e} _`;
492
+ let o = `SELECT _.rowid as ${S}, _.* FROM ${e} _`;
499
493
  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) => {
494
+ }, ht = (r, e, t, s) => {
501
495
  t = structuredClone(t);
502
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
496
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = J(s?.orderBy);
503
497
  return {
504
- sql: J({ tableName: o, where: c, orderBy: i, join: n }),
498
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n }),
505
499
  params: []
506
500
  };
507
- }, ft = (r, e, t, s) => {
501
+ }, _t = (r, e, t, s) => {
508
502
  t = structuredClone(t);
509
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
503
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = J(s?.orderBy);
510
504
  return {
511
- sql: J({ tableName: o, where: c, orderBy: i, join: n }),
505
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n }),
512
506
  params: []
513
507
  };
514
- }, pt = (r, e, t, s) => {
508
+ }, ft = (r, e, t, s) => {
515
509
  t = structuredClone(t);
516
510
  const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a);
517
511
  let i = `SELECT count(_.rowid) as count FROM ${o} _`;
@@ -521,24 +515,24 @@ const at = (r, e, t) => {
521
515
  };
522
516
  }, V = (r, e, t, s) => {
523
517
  t = structuredClone(t);
524
- const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = H(s?.orderBy);
518
+ const { joinSQL: n, fieldAliasMap: a } = j(r, e, t), o = E(e), c = v(t, a), i = J(s?.orderBy);
525
519
  return {
526
- sql: J({ tableName: o, where: c, orderBy: i, join: n, limit: 1 }),
520
+ sql: Y({ tableName: o, where: c, orderBy: i, join: n, limit: 1 }),
527
521
  params: []
528
522
  };
529
523
  };
530
- class mt extends $e {
524
+ class pt extends ye {
531
525
  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, () => {
526
+ 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
527
  this.transaction_pending = !0;
534
- }), this.rxdb.addEventListener(Ne, () => {
528
+ }), this.rxdb.addEventListener(be, () => {
535
529
  this.transaction_pending = !1, this.transaction_entities.forEach((n) => this.merge_cache(n.type, n.entities)), this.transaction_entities = [];
536
- }), this.rxdb.addEventListener(Te, () => {
530
+ }), this.rxdb.addEventListener(Ne, () => {
537
531
  this.transaction_pending = !1, this.transaction_entities = [];
538
532
  });
539
533
  }
540
534
  metadata;
541
- need_run_task = new ke();
535
+ need_run_task = new ve();
542
536
  run_task$ = this.need_run_task.asObservable().pipe(xe(16));
543
537
  cache_query_task_map = /* @__PURE__ */ new Map();
544
538
  cache_query_tasks = [];
@@ -561,7 +555,7 @@ class mt extends $e {
561
555
  add_query_cache(e, t = !1) {
562
556
  const s = [];
563
557
  return e.results.forEach(({ columns: n, rows: a }) => {
564
- const o = n.findIndex((i) => i === "id"), c = n.findIndex((i) => i === R);
558
+ const o = n.findIndex((i) => i === "id"), c = n.findIndex((i) => i === S);
565
559
  a.forEach((i) => {
566
560
  const l = i[o];
567
561
  let u;
@@ -574,7 +568,7 @@ class mt extends $e {
574
568
  const _ = se(this.metadata, n, i);
575
569
  u = this.createEntityRef(_), s.push(u);
576
570
  }
577
- const h = ae(u);
571
+ const h = re(u);
578
572
  h.local = !0, c !== -1 && (h.rowId = BigInt(i[c])), h.modified = !1;
579
573
  });
580
574
  }), s;
@@ -586,13 +580,13 @@ class mt extends $e {
586
580
  const { sql: t, params: s } = e, n = t + s.join(",");
587
581
  let a;
588
582
  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) => {
583
+ const o = new U(), c = o.asObservable(), i = new ae(0), l = i.asObservable(), u = new ie((p) => {
590
584
  const d = this.cache_query_task_map.get(n);
591
585
  return d.observerCount++, a = p, _(), () => {
592
586
  if (d.observerCount--, d.observerCount <= 0) {
593
587
  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);
588
+ const C = this.cache_query_tasks.indexOf(d);
589
+ C >= 0 && this.cache_query_tasks.splice(C, 1);
596
590
  }
597
591
  };
598
592
  }).pipe(L(1)), h = {
@@ -630,7 +624,7 @@ class mt extends $e {
630
624
  });
631
625
  }
632
626
  }
633
- class fe extends mt {
627
+ class _e extends pt {
634
628
  #e = /* @__PURE__ */ new Map();
635
629
  get(e, t) {
636
630
  const s = {
@@ -646,7 +640,7 @@ class fe extends mt {
646
640
  return this.#s("get", a, s, t), a.result$.pipe(
647
641
  f((o) => this.#t(a, o)),
648
642
  f((o) => {
649
- if (o.length === 0) throw new $("not found");
643
+ if (o.length === 0) throw new m("not found");
650
644
  return o[0];
651
645
  })
652
646
  );
@@ -664,54 +658,54 @@ class fe extends mt {
664
658
  f((a) => this.#t(n, a)),
665
659
  f((a) => {
666
660
  if (a.length === 0)
667
- throw new $("not found");
661
+ throw new m("not found");
668
662
  return a[0];
669
663
  })
670
664
  );
671
665
  }
672
666
  find(e, t) {
673
- const s = _t(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
667
+ const s = ht(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
674
668
  return this.#s("find", n, e, t), n.result$.pipe(f((a) => this.#t(n, a)));
675
669
  }
676
670
  findAll(e, t) {
677
- const s = ft(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
671
+ const s = _t(this.adapter, this.metadata, e, t), n = this.create_query_task(s);
678
672
  return this.#s("findAll", n, e, t), n.result$.pipe(f((a) => this.#t(n, a)));
679
673
  }
680
674
  findByCursor(e, t) {
681
- throw new Error("Method not implemented.");
675
+ throw new m("Method not implemented.");
682
676
  }
683
677
  count(e, t) {
684
- const s = pt(this.adapter, this.metadata, e), n = this.create_query_task(s);
678
+ const s = ft(this.adapter, this.metadata, e), n = this.create_query_task(s);
685
679
  return this.#s("count", n, e, t), n.result$.pipe(f((a) => a.results[0].rows[0][0]));
686
680
  }
687
681
  create(e) {
688
- return I(this.#r(e));
682
+ return O(this.#r(e));
689
683
  }
690
684
  update(e, t) {
691
- return I(this.#i(e, t));
685
+ return O(this.#i(e, t));
692
686
  }
693
687
  remove(e) {
694
- const t = ae(e), s = () => {
688
+ const t = re(e), s = () => {
695
689
  t.origin = structuredClone({ ...e }), t.modified = !1, t.removed = !0;
696
690
  };
697
691
  if (t.local === !0) {
698
- const { sql: a, params: o } = at(this.metadata, e, this.rxdb.context), c = this.client$.pipe(
692
+ const { sql: a, params: o } = rt(this.metadata, e, this.rxdb.context), c = this.client$.pipe(
699
693
  Q(1),
700
694
  w(() => this.adapter.execute(a, o)),
701
695
  f(() => (e.removedAt = /* @__PURE__ */ new Date(), this.rxdb.context?.userId && (e.removedBy = this.rxdb.context.userId), s(), e)),
702
696
  A(() => s()),
703
697
  A((i) => this.merge_cache("remove", [i]))
704
698
  );
705
- return I(c);
699
+ return O(c);
706
700
  } 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(
701
+ const { sql: a, params: o } = it(this.metadata, e, this.rxdb.context), c = this.#n("remove", a, o).pipe(
708
702
  A(() => s()),
709
703
  f((i) => i[0])
710
704
  );
711
- return I(c);
705
+ return O(c);
712
706
  }
713
707
  const n = q(e);
714
- throw new $(`Remove Error${n.name}(${e.id}) not saved local.`);
708
+ throw new m(`Remove Error${n.name}(${e.id}) not saved local.`);
715
709
  }
716
710
  /**
717
711
  * 根据 type 计算主动更新缓存策略
@@ -733,7 +727,7 @@ class fe extends mt {
733
727
  this.#l(n, s, t);
734
728
  break;
735
729
  default:
736
- throw new Error("unknown type");
730
+ throw new m("unknown type");
737
731
  }
738
732
  }
739
733
  }
@@ -742,11 +736,11 @@ class fe extends mt {
742
736
  return e.resultEntities = s, e.resultEntityIds = s.map((n) => n.id), s;
743
737
  }
744
738
  #r(e) {
745
- const { sql: t, params: s } = it(this.metadata, e, this.rxdb.context);
739
+ const { sql: t, params: s } = at(this.metadata, e, this.rxdb.context);
746
740
  return this.#n("create", t, s).pipe(f((n) => n[0]));
747
741
  }
748
742
  #i(e, t) {
749
- const { sql: s, params: n } = ct(this.metadata, e, t, this.rxdb.context);
743
+ const { sql: s, params: n } = ot(this.metadata, e, t, this.rxdb.context);
750
744
  return this.#n("update", s, n).pipe(f((a) => a[0]));
751
745
  }
752
746
  #s(e, t, s, n) {
@@ -776,12 +770,12 @@ class fe extends mt {
776
770
  case "findByCursor":
777
771
  case "count":
778
772
  case "findAll":
779
- s.some((c) => S(c, a)) && t.refresh();
773
+ s.some((c) => R(c, a)) && t.refresh();
780
774
  break;
781
775
  }
782
776
  }
783
777
  #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));
778
+ 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
779
  switch (o) {
786
780
  case "count":
787
781
  l !== a && t.refresh();
@@ -806,7 +800,7 @@ class fe extends mt {
806
800
  case "findByCursor":
807
801
  case "count":
808
802
  case "findAll":
809
- (a || s.some((i) => S(i, c))) && t.refresh();
803
+ (a || s.some((i) => R(i, c))) && t.refresh();
810
804
  break;
811
805
  }
812
806
  }
@@ -817,11 +811,11 @@ const D = (r, e, t, s) => {
817
811
  const i = [o, v(t)].filter(Boolean).join(" AND ");
818
812
  return i && (c = `WHERE ${i}`), {
819
813
  sql: `WITH RECURSIVE __children AS (
820
- SELECT *,rowid as ${R}, 0 AS level
814
+ SELECT *,rowid as ${S}, 0 AS level
821
815
  FROM ${a}
822
816
  WHERE id = ?
823
817
  UNION ALL
824
- SELECT children.*,children.rowid as ${R}, c.level + 1
818
+ SELECT children.*,children.rowid as ${S}, c.level + 1
825
819
  FROM ${a} children
826
820
  JOIN __children c ON ${s.descendants ? "children.parentId = c.id" : "children.id = c.parentId"}
827
821
  ${c}
@@ -830,23 +824,23 @@ SELECT ${s.count ? "count(*)-1 as count" : "*"} FROM __children
830
824
  ORDER BY level, id;`,
831
825
  params: [e]
832
826
  };
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 {
827
+ }, 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 });
828
+ class bt extends _e {
835
829
  #e = /* @__PURE__ */ new Map();
836
830
  findDescendants(e, t, s) {
837
- const n = Et(this.metadata, e.id, t, s), a = this.create_query_task(n);
831
+ const n = mt(this.metadata, e.id, t, s), a = this.create_query_task(n);
838
832
  return this.#r("findDescendants", a, e.id, t, s), a.result$.pipe(f((o) => this.#t(a, o)));
839
833
  }
840
834
  countDescendants(e, t, s) {
841
- const n = $t(this.metadata, e.id, t, s), a = this.create_query_task(n);
835
+ const n = yt(this.metadata, e.id, t, s), a = this.create_query_task(n);
842
836
  return this.#r("countDescendants", a, e.id, t, s), a.result$.pipe(f((o) => o.results[0].rows[0][0]));
843
837
  }
844
838
  findAncestors(e, t, s) {
845
- const n = yt(this.metadata, e.id, t, s), a = this.create_query_task(n);
839
+ const n = Et(this.metadata, e.id, t, s), a = this.create_query_task(n);
846
840
  return this.#r("findAncestors", a, e.id, t, s), a.result$.pipe(f((o) => this.#t(a, o)));
847
841
  }
848
842
  countAncestors(e, t, s) {
849
- const n = bt(this.metadata, e.id, t, s), a = this.create_query_task(n);
843
+ const n = $t(this.metadata, e.id, t, s), a = this.create_query_task(n);
850
844
  return this.#r("countAncestors", a, e.id, t, s), a.result$.pipe(f((o) => o.results[0].rows[0][0]));
851
845
  }
852
846
  /**
@@ -869,7 +863,7 @@ class Nt extends fe {
869
863
  this.#n(n, s, t);
870
864
  break;
871
865
  default:
872
- throw new Error("unknown type");
866
+ throw new m("unknown type");
873
867
  }
874
868
  }
875
869
  }
@@ -888,7 +882,7 @@ class Nt extends fe {
888
882
  #i(e, t, s) {
889
883
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
890
884
  let i = !0;
891
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
885
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
892
886
  case "findDescendants":
893
887
  case "countDescendants":
894
888
  c && i && t.refresh();
@@ -898,7 +892,7 @@ class Nt extends fe {
898
892
  #s(e, t, s) {
899
893
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
900
894
  let i = !0;
901
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
895
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
902
896
  case "findDescendants":
903
897
  case "countDescendants":
904
898
  case "findAncestors":
@@ -910,7 +904,7 @@ class Nt extends fe {
910
904
  #n(e, t, s) {
911
905
  const { type: n, where: a } = e, o = s.map((l) => l.parentId), c = t.resultEntityIds.some((l) => o.includes(l));
912
906
  let i = !0;
913
- switch (a.rules.length > 0 && (i = s.some((l) => S(l, a))), n) {
907
+ switch (a.rules.length > 0 && (i = s.some((l) => R(l, a))), n) {
914
908
  case "findDescendants":
915
909
  case "countDescendants":
916
910
  case "findAncestors":
@@ -920,10 +914,10 @@ class Nt extends fe {
920
914
  }
921
915
  }
922
916
  }
923
- class vt extends Ae {
917
+ class Rt extends Oe {
924
918
  constructor(e, t) {
925
919
  super(e), this.options = t;
926
- const s = _e(e.options.dbName, "changes");
920
+ const s = he(e.options.dbName, "changes");
927
921
  this.#r = new BroadcastChannel(s), this.#i = Ce(this.#r, "message"), this.#i.pipe(K(this.#e)).subscribe((n) => {
928
922
  const a = n.data, { dbName: o, tableName: c, rowid: i, recordAt: l, timeStamp: u } = a;
929
923
  if (!o || !c || !i) return;
@@ -939,10 +933,10 @@ class vt extends Ae {
939
933
  this.rxdb.dispatchEvent(new Se(p, d));
940
934
  break;
941
935
  case M.SQLITE_INSERT:
942
- this.rxdb.dispatchEvent(new Re(p, d));
936
+ this.rxdb.dispatchEvent(new qe(p, d));
943
937
  break;
944
938
  case M.SQLITE_UPDATE:
945
- this.rxdb.dispatchEvent(new qe(p, d));
939
+ this.rxdb.dispatchEvent(new Ae(p, d));
946
940
  break;
947
941
  }
948
942
  }), this.#_.pipe(K(this.#e)).subscribe();
@@ -956,22 +950,22 @@ class vt extends Ae {
956
950
  #s = [];
957
951
  #n = /* @__PURE__ */ new Map();
958
952
  #o = !1;
959
- #c = new ie(0);
953
+ #c = new ae(0);
960
954
  #l = this.#c.asObservable();
961
955
  // sqlite 客户端
962
- #a = new oe((e) => {
956
+ #a = new ie((e) => {
963
957
  const { vfs: t, async: s, worker: n, wasmPath: a, workerInstance: o } = this.options, c = {
964
958
  vfs: t,
965
959
  async: s,
966
960
  worker: n,
967
961
  wasmPath: a
968
962
  };
969
- he(c);
963
+ de(c);
970
964
  let i;
971
- n && o ? i = ve(o) : i = new rt(), i.init(this.rxdb.options.dbName, c).then(() => e.next(i));
965
+ n && o ? i = Re(o) : i = new nt(), i.init(this.rxdb.options.dbName, c).then(() => e.next(i));
972
966
  }).pipe(L(1));
973
967
  // 已连接
974
- #h = Le(() => this.rxdb.connect(this.name)).pipe(L(1));
968
+ #h = ke(() => this.rxdb.connect(this.name)).pipe(L(1));
975
969
  // 队列
976
970
  #_ = this.#l.pipe(
977
971
  Z(() => this.#o === !1),
@@ -985,15 +979,9 @@ class vt extends Ae {
985
979
  w((s) => s.execute(e.sql, e.bindings)),
986
980
  A((s) => t.next(s)),
987
981
  A(() => setTimeout(() => this.#n.delete(e.key), 0)),
988
- Me((s) => {
982
+ Le((s) => {
989
983
  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 });
984
+ return t.error(new m(`${n} ${e.sql} ${JSON.stringify(e.bindings)}`)), Me({ error: s });
997
985
  })
998
986
  );
999
987
  }),
@@ -1001,7 +989,7 @@ class vt extends Ae {
1001
989
  this.#o = !1, this.#u();
1002
990
  })
1003
991
  );
1004
- name = de;
992
+ name = ue;
1005
993
  /**
1006
994
  * 数据库版本
1007
995
  */
@@ -1025,7 +1013,7 @@ class vt extends Ae {
1025
1013
  * 获取版本
1026
1014
  */
1027
1015
  version() {
1028
- return I(this.version$);
1016
+ return O(this.version$);
1029
1017
  }
1030
1018
  /**
1031
1019
  * 获取实体仓库
@@ -1037,13 +1025,13 @@ class vt extends Ae {
1037
1025
  let s;
1038
1026
  switch (t.repository) {
1039
1027
  case "Repository":
1040
- s = new fe(this, this.#a, e);
1028
+ s = new _e(this, this.#a, e);
1041
1029
  break;
1042
1030
  case "TreeRepository":
1043
- s = new Nt(this, this.#a, e);
1031
+ s = new bt(this, this.#a, e);
1044
1032
  break;
1045
1033
  default:
1046
- throw new $("Unsupported repository type: " + t.repository);
1034
+ throw new m("Unsupported repository type: " + t.repository);
1047
1035
  }
1048
1036
  return this.#t.set(e, s), s;
1049
1037
  }
@@ -1054,7 +1042,7 @@ class vt extends Ae {
1054
1042
  * @param EntityType
1055
1043
  */
1056
1044
  isTableExisted(e) {
1057
- return I(this.isTableExisted$(e));
1045
+ return O(this.isTableExisted$(e));
1058
1046
  }
1059
1047
  /**
1060
1048
  * 判断表是否存在
@@ -1062,7 +1050,7 @@ class vt extends Ae {
1062
1050
  */
1063
1051
  isTableExisted$(e) {
1064
1052
  const t = q(e), s = E(t);
1065
- return this.#d(Ve(s)).pipe(f((n) => Ue(n) === !1));
1053
+ return this.#d(Pe(s)).pipe(f((n) => Ve(n) === !1));
1066
1054
  }
1067
1055
  /**
1068
1056
  * 创建 table
@@ -1070,13 +1058,13 @@ class vt extends Ae {
1070
1058
  */
1071
1059
  createTable(e) {
1072
1060
  const t = q(e);
1073
- let s = ze(this, t);
1061
+ let s = Ge(this, t);
1074
1062
  if (t.log !== !1) {
1075
- const n = Xe(this, t);
1063
+ const n = ze(this, t);
1076
1064
  s += `
1077
1065
  ` + n;
1078
1066
  }
1079
- return I(this.#d(s).pipe(f(() => !0)));
1067
+ return O(this.#d(s).pipe(f(() => !0)));
1080
1068
  }
1081
1069
  /**
1082
1070
  * 执行 sql
@@ -1096,19 +1084,19 @@ class vt extends Ae {
1096
1084
  * @param callback
1097
1085
  */
1098
1086
  transaction(e) {
1099
- return I(this.transaction$(e));
1087
+ return O(this.transaction$(e));
1100
1088
  }
1101
1089
  transaction$(e) {
1102
1090
  return this.#a.pipe(
1103
1091
  w(async (t) => {
1104
- this.rxdb.dispatchEvent(Tt), await t.execute("BEGIN; PRAGMA defer_foreign_keys = ON;");
1092
+ this.rxdb.dispatchEvent(Nt), await t.execute("BEGIN; PRAGMA defer_foreign_keys = ON;");
1105
1093
  try {
1106
1094
  const s = await e();
1107
1095
  return await t.execute("COMMIT"), this.rxdb.dispatchEvent(wt), s;
1108
1096
  } catch (s) {
1109
- await t.execute("ROLLBACK"), this.rxdb.dispatchEvent(gt);
1097
+ await t.execute("ROLLBACK"), this.rxdb.dispatchEvent(Tt);
1110
1098
  const n = s?.message || "Transaction Error";
1111
- throw new $(n);
1099
+ throw new m(n);
1112
1100
  }
1113
1101
  })
1114
1102
  );
@@ -1126,11 +1114,11 @@ class vt extends Ae {
1126
1114
  return this.#a.pipe(w((s) => ee(s.execute(e, t))));
1127
1115
  }
1128
1116
  }
1129
- const Tt = new ge(), wt = new Oe(), gt = new Ie();
1117
+ const Nt = new Te(), wt = new ge(), Tt = new Ie();
1130
1118
  export {
1131
- vt as RxDBAdapterSqlite,
1132
- $ as RxdbAdapterSqliteError,
1133
- rt as SqliteClient,
1134
- tt as WA_SQLITE_VFS_LIST,
1135
- st as sqliteLoad
1119
+ Rt as RxDBAdapterSqlite,
1120
+ m as RxdbAdapterSqliteError,
1121
+ nt as SqliteClient,
1122
+ et as WA_SQLITE_VFS_LIST,
1123
+ tt as sqliteLoad
1136
1124
  };
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.3",
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.3",
8
+ "@aiao/utils": "0.0.3",
9
9
  "rxjs": "~7.8.0",
10
10
  "@journeyapps/wa-sqlite": "^1.2.4",
11
11
  "comlink": "^4.4.2"