@delta-comic/db 0.0.7 → 0.0.8

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,4 +1,4 @@
1
- import { Pn as e, Wr as t, c as n, lr as r, n as i, r as a, s as o, sn as s, t as c, u as l, y as u } from "./esm-Di_XcAT-.js";
1
+ import { Pn as e, Wr as t, c as n, lr as r, n as i, r as a, s as o, sn as s, t as c, u as l, y as u } from "./esm-YHRn16YB.js";
2
2
  import { useGlobalVar as d } from "@delta-comic/utils";
3
3
  import { computed as f, customRef as p, getCurrentInstance as m, nextTick as h, onMounted as g, readonly as _, ref as v, shallowRef as y, toRef as b, toValue as x, triggerRef as S, unref as C, watch as w } from "vue";
4
4
  import { SourcedValue as T, Struct as E, uni as D } from "@delta-comic/model";
@@ -73,103 +73,19 @@ var ae = {
73
73
  up: re,
74
74
  down: ie
75
75
  };
76
- /**
77
- * Sends a message to the backend.
78
- * @example
79
- * ```typescript
80
- * import { invoke } from '@tauri-apps/api/core';
81
- * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
82
- * ```
83
- *
84
- * @param cmd The command name.
85
- * @param args The optional arguments to pass to the command.
86
- * @param options The request options.
87
- * @return A promise resolving or rejecting to the backend response.
88
- *
89
- * @since 1.0.0
90
- */
91
76
  async function N(e, t = {}, n) {
92
77
  return window.__TAURI_INTERNALS__.invoke(e, t, n);
93
78
  }
94
- /**
95
- * **Database**
96
- *
97
- * The `Database` class serves as the primary interface for
98
- * communicating with the rust side of the sql plugin.
99
- */
100
79
  var oe = class e {
101
80
  constructor(e) {
102
81
  this.path = e;
103
82
  }
104
- /**
105
- * **load**
106
- *
107
- * A static initializer which connects to the underlying database and
108
- * returns a `Database` instance once a connection to the database is established.
109
- *
110
- * # Sqlite
111
- *
112
- * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
113
- *
114
- * @example
115
- * ```ts
116
- * const db = await Database.load("sqlite:test.db");
117
- * ```
118
- */
119
83
  static async load(t) {
120
84
  return new e(await N("plugin:sql|load", { db: t }));
121
85
  }
122
- /**
123
- * **get**
124
- *
125
- * A static initializer which synchronously returns an instance of
126
- * the Database class while deferring the actual database connection
127
- * until the first invocation or selection on the database.
128
- *
129
- * # Sqlite
130
- *
131
- * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
132
- *
133
- * @example
134
- * ```ts
135
- * const db = Database.get("sqlite:test.db");
136
- * ```
137
- */
138
86
  static get(t) {
139
87
  return new e(t);
140
88
  }
141
- /**
142
- * **execute**
143
- *
144
- * Passes a SQL expression to the database for execution.
145
- *
146
- * @example
147
- * ```ts
148
- * // for sqlite & postgres
149
- * // INSERT example
150
- * const result = await db.execute(
151
- * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
152
- * [ todos.id, todos.title, todos.status ]
153
- * );
154
- * // UPDATE example
155
- * const result = await db.execute(
156
- * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3",
157
- * [ todos.title, todos.status, todos.id ]
158
- * );
159
- *
160
- * // for mysql
161
- * // INSERT example
162
- * const result = await db.execute(
163
- * "INSERT into todos (id, title, status) VALUES (?, ?, ?)",
164
- * [ todos.id, todos.title, todos.status ]
165
- * );
166
- * // UPDATE example
167
- * const result = await db.execute(
168
- * "UPDATE todos SET title = ?, completed = ? WHERE id = ?",
169
- * [ todos.title, todos.status, todos.id ]
170
- * );
171
- * ```
172
- */
173
89
  async execute(e, t) {
174
90
  let [n, r] = await N("plugin:sql|execute", {
175
91
  db: this.path,
@@ -181,24 +97,6 @@ var oe = class e {
181
97
  rowsAffected: n
182
98
  };
183
99
  }
184
- /**
185
- * **select**
186
- *
187
- * Passes in a SELECT query to the database for execution.
188
- *
189
- * @example
190
- * ```ts
191
- * // for sqlite & postgres
192
- * const result = await db.select(
193
- * "SELECT * from todos WHERE id = $1", [ id ]
194
- * );
195
- *
196
- * // for mysql
197
- * const result = await db.select(
198
- * "SELECT * from todos WHERE id = ?", [ id ]
199
- * );
200
- * ```
201
- */
202
100
  async select(e, t) {
203
101
  return await N("plugin:sql|select", {
204
102
  db: this.path,
@@ -206,17 +104,6 @@ var oe = class e {
206
104
  values: t ?? []
207
105
  });
208
106
  }
209
- /**
210
- * **close**
211
- *
212
- * Closes the database connection pool.
213
- *
214
- * @example
215
- * ```ts
216
- * const success = await db.close()
217
- * ```
218
- * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
219
- */
220
107
  async close(e) {
221
108
  return await N("plugin:sql|close", { db: e });
222
109
  }
@@ -245,10 +132,6 @@ function P(e, t, { signal: n, edges: r } = {}) {
245
132
  return h.schedule = d, h.cancel = p, h.flush = m, n?.addEventListener("abort", p, { once: !0 }), h;
246
133
  }
247
134
  var se = class {
248
- /**
249
- * Base class that implements {@link Dialect}
250
- * @param create function that create {@link Driver}
251
- */
252
135
  constructor(e) {
253
136
  this.createDriver = e;
254
137
  }
@@ -286,13 +169,8 @@ var le = class {
286
169
  releaseSavepoint;
287
170
  rollbackToSavepoint;
288
171
  init;
289
- /**
290
- * Base abstract class that implements {@link Driver}
291
- *
292
- * You **MUST** assign `this.conn` in `init` and implement `destroy` method
293
- */
294
172
  constructor(e) {
295
- this.init = () => import("./esm-CzppQRXP.js").then(({ createQueryId: e }) => {
173
+ this.init = () => import("./esm-BGcGAQ5-.js").then(({ createQueryId: e }) => {
296
174
  e && (this.savepoint = F.bind(null, "savepoint", e), this.releaseSavepoint = F.bind(null, "release", e), this.rollbackToSavepoint = F.bind(null, "rollback to", e));
297
175
  }).then(e);
298
176
  }
@@ -347,19 +225,10 @@ var de = class extends le {
347
225
  return await this.db.query(e.is(n), r, t);
348
226
  }
349
227
  }, pe = class extends se {
350
- /**
351
- * Dialect for generic SQLite that run SQLs in current thread
352
- *
353
- * @param executor function to create {@link IGenericSqlite}
354
- * @param onCreateConnection optional callback after connection created
355
- */
356
228
  constructor(e, t) {
357
229
  super(() => new de(e, t));
358
230
  }
359
231
  }, L = class extends pe {
360
- /**
361
- * SQLite dialect for Tauri, using [official sql plugin](https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql)
362
- */
363
232
  constructor(e) {
364
233
  let { database: t, onCreateConnection: n } = e;
365
234
  super(async () => {
@@ -441,11 +310,8 @@ var ye = class {
441
310
  deserializer;
442
311
  skipNodeSet;
443
312
  ctx;
444
- /**
445
- * Base class for {@link SerializePlugin}, without default options
446
- */
447
313
  constructor(e, t, n) {
448
- this.transformer = new me(e), this.deserializer = t, n.length && (this.skipNodeSet = new Set(n), this.ctx = /* @__PURE__ */ new WeakSet());
314
+ this.transformer = new me(e), this.deserializer = t, n.length && (this.skipNodeSet = new Set(n), this.ctx = new WeakSet());
449
315
  }
450
316
  transformQuery({ node: e, queryId: t }) {
451
317
  return this.skipNodeSet?.has(e.kind) ? (this.ctx?.add(t), e) : this.transformer.transformNode(e);
@@ -467,67 +333,6 @@ var ye = class {
467
333
  return t;
468
334
  }
469
335
  }, z = class extends ye {
470
- /**
471
- * _**THIS PLUGIN SHOULD BE PLACED AT THE END OF PLUGINS ARRAY !!!**_
472
- *
473
- * reference from https://github.com/koskimas/kysely/pull/138
474
- *
475
- * The following example will return an error when using sqlite dialects, unless using this plugin:
476
- * ```ts
477
- * interface TestTable {
478
- * id: Generated<number>
479
- * person: { name: string; age: number; time: Date } | null
480
- * gender: boolean
481
- * blob: Uint8Array | null
482
- * date: Date
483
- * }
484
- *
485
- * interface Database {
486
- * test: TestTable
487
- * }
488
- *
489
- * const db = new Kysely<Database>({
490
- * dialect: new SqliteDialect({
491
- * database: new Database(':memory:'),
492
- * }),
493
- * plugins: [
494
- * new SerializePlugin(),
495
- * ],
496
- * })
497
- *
498
- * await db.insertInto('test').values({
499
- * gender: true,
500
- * person: { name: 'test', age: 2, time: new Date() },
501
- * blob: Uint8Array.from([1, 2, 3]),
502
- * date: new Date(),
503
- * }).execute()
504
- * ```
505
- *
506
- * You can also provide a custom serializer function:
507
- *
508
- * ```ts
509
- * const db = new Kysely<Database>({
510
- * dialect: new SqliteDialect({
511
- * database: new Database(":memory:"),
512
- * }),
513
- * plugins: [
514
- * new SerializePlugin({
515
- * serializer: (value) => {
516
- * if (value instanceof Date) {
517
- * return formatDatetime(value)
518
- * }
519
- *
520
- * if (value !== null && typeof value === 'object') {
521
- * return JSON.stringify(value)
522
- * }
523
- *
524
- * return value
525
- * }
526
- * }),
527
- * ],
528
- * })
529
- * ```
530
- */
531
336
  constructor(e = {}) {
532
337
  let { deserializer: t = _e, serializer: n = he, skipNodeKind: r = [] } = e;
533
338
  super(n, t, r);
@@ -535,7 +340,7 @@ var ye = class {
535
340
  };
536
341
  function B(e) {
537
342
  return {
538
- all: e ||= /* @__PURE__ */ new Map(),
343
+ all: e ||= new Map(),
539
344
  on: function(t, n) {
540
345
  var r = e.get(t);
541
346
  r ? r.push(n) : e.set(t, [n]);
@@ -554,7 +359,7 @@ function B(e) {
554
359
  }
555
360
  };
556
361
  }
557
- var be = /* @__PURE__ */ k({
362
+ var be = k({
558
363
  get: () => Se,
559
364
  getByEnabled: () => xe,
560
365
  toggleEnable: () => Ce
@@ -571,7 +376,7 @@ async function Ce(e) {
571
376
  let { db: t } = await import("./index.js"), n = await t.value.selectFrom("plugin").where("pluginName", "=", e).select("enable").executeTakeFirstOrThrow();
572
377
  return t.value.updateTable("plugin").where("pluginName", "=", e).set({ enable: !n.enable }).execute();
573
378
  }
574
- var we = /* @__PURE__ */ k({
379
+ var we = k({
575
380
  key: () => V,
576
381
  upsert: () => H
577
382
  });
@@ -583,7 +388,7 @@ async function H(e) {
583
388
  key: n
584
389
  }).execute(), n;
585
390
  }
586
- var Te = /* @__PURE__ */ k({
391
+ var Te = k({
587
392
  moveItem: () => De,
588
393
  upsertItem: () => Ee
589
394
  });
@@ -604,7 +409,7 @@ async function De(e, t, ...n) {
604
409
  belongTo: t
605
410
  }).execute();
606
411
  }
607
- var Oe = /* @__PURE__ */ k({ upsert: () => ke });
412
+ var Oe = k({ upsert: () => ke });
608
413
  async function ke(e) {
609
414
  let { db: t } = await import("./index.js"), n = await H(e);
610
415
  await t.value.replaceInto("history").values({
@@ -613,7 +418,7 @@ async function ke(e) {
613
418
  ep: E.toRaw(e)
614
419
  }).execute();
615
420
  }
616
- var Ae = /* @__PURE__ */ k({
421
+ var Ae = k({
617
422
  getAll: () => Me,
618
423
  key: () => je,
619
424
  upsert: () => Ne
@@ -633,7 +438,7 @@ async function Ne(e) {
633
438
  author: JSON.stringify(e.author)
634
439
  }).execute();
635
440
  }
636
- var Pe = /* @__PURE__ */ k({ upsert: () => Fe });
441
+ var Pe = k({ upsert: () => Fe });
637
442
  async function Fe(e) {
638
443
  let { db: t } = await import("./index.js"), n = await H(e);
639
444
  await t.value.replaceInto("recentView").values({
@@ -662,9 +467,6 @@ function He(...e) {
662
467
  set: Ve
663
468
  }))) : v(t);
664
469
  }
665
- /**
666
- * @internal
667
- */
668
470
  function Ue(e, t) {
669
471
  function n(...n) {
670
472
  return new Promise((r, i) => {
@@ -678,12 +480,6 @@ function Ue(e, t) {
678
480
  return n;
679
481
  }
680
482
  var W = (e) => e();
681
- /**
682
- * EventFilter that gives extra controls to pause and resume the filter
683
- *
684
- * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
685
- * @param options Options to configure the filter
686
- */
687
483
  function We(e = W, t = {}) {
688
484
  let { initialState: n = "active" } = t, r = He(n === "active");
689
485
  function i() {
@@ -711,7 +507,6 @@ function Ke(e, t, n = {}) {
711
507
  let { eventFilter: r = W, ...i } = n;
712
508
  return w(e, Ue(r, t), i);
713
509
  }
714
- /** @deprecated Use Vue's built-in `watch` instead. This function will be removed in future version. */
715
510
  function qe(e, t, n = {}) {
716
511
  let { eventFilter: r, initialState: i = "active", ...a } = n, { eventFilter: o, pause: s, resume: c, isActive: l } = We(r, { initialState: i });
717
512
  return {
@@ -724,21 +519,9 @@ function qe(e, t, n = {}) {
724
519
  isActive: l
725
520
  };
726
521
  }
727
- /**
728
- * Call onMounted() if it's inside a component lifecycle, if not, just call the function
729
- *
730
- * @param fn
731
- * @param sync if set to false, it will run in the nextTick() of Vue
732
- * @param target
733
- */
734
522
  function Je(e, t = !0, n) {
735
523
  Ge(n) ? g(e, n) : t ? e() : h(e);
736
524
  }
737
- /**
738
- * Shorthand for watching value with {immediate: true}
739
- *
740
- * @see https://vueuse.org/watchImmediate
741
- */
742
525
  function Ye(e, t, n) {
743
526
  return w(e, t, {
744
527
  ...n,
@@ -747,11 +530,6 @@ function Ye(e, t, n) {
747
530
  }
748
531
  var K = U ? window : void 0;
749
532
  U && window.document, U && window.navigator, U && window.location;
750
- /**
751
- * Get the dom element of a ref of element or Vue component instance
752
- *
753
- * @param elRef
754
- */
755
533
  function Xe(e) {
756
534
  let t = x(e);
757
535
  return t?.$el ?? t;
@@ -774,7 +552,7 @@ function q(...e) {
774
552
  });
775
553
  }, { flush: "post" });
776
554
  }
777
- var J = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Y = "__vueuse_ssr_handlers__", Ze = /* @__PURE__ */ Qe();
555
+ var J = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Y = "__vueuse_ssr_handlers__", Ze = Qe();
778
556
  function Qe() {
779
557
  return Y in J || (J[Y] = J[Y] || {}), J[Y];
780
558
  }
@@ -818,11 +596,6 @@ var tt = {
818
596
  write: (e) => e.toISOString()
819
597
  }
820
598
  }, X = "vueuse-storage";
821
- /**
822
- * Reactive LocalStorage/SessionStorage.
823
- *
824
- * @see https://vueuse.org/useStorage
825
- */
826
599
  function nt(e, t, n, r = {}) {
827
600
  let { flush: i = "pre", deep: a = !0, listenToStorageChanges: o = !0, writeDefaults: s = !0, mergeDefaults: c = !1, shallow: l, window: u = K, eventFilter: d, onError: p = (e) => {
828
601
  console.error(e);
@@ -906,19 +679,11 @@ function nt(e, t, n, r = {}) {
906
679
  }
907
680
  return g;
908
681
  }
909
- /**
910
- * Reactive LocalStorage.
911
- *
912
- * @see https://vueuse.org/useLocalStorage
913
- * @param key
914
- * @param initialValue
915
- * @param options
916
- */
917
682
  function rt(e, t, n = {}) {
918
683
  let { window: r = K } = n;
919
684
  return nt(e, t, r?.localStorage, n);
920
685
  }
921
- var it = /* @__PURE__ */ Object.assign({ "./migrations/1_initial.ts": Re }), Z = d(await oe.load("sqlite:native_store.db"), "core/store/raw"), at = B(), ot = /\b(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER)\b/i, st = P(() => {
686
+ var it = Object.assign({ "./migrations/1_initial.ts": Re }), Z = d(await oe.load("sqlite:native_store.db"), "core/store/raw"), at = B(), ot = /\b(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER)\b/i, st = P(() => {
922
687
  console.debug("[db sync] db changed"), at.emit("onChange"), S(ct);
923
688
  }, 300), ct = d(await (async () => {
924
689
  let e = y(new u({
@@ -948,7 +713,7 @@ var it = /* @__PURE__ */ Object.assign({ "./migrations/1_initial.ts": Re }), Z =
948
713
  }).migrateToLatest(), e;
949
714
  })(), "core/store/ins"), lt = new T();
950
715
  const ut = (e, t, n) => rt(lt.toString([e, x(t)]), n);
951
- var dt = /* @__PURE__ */ Object.assign({
716
+ var dt = Object.assign({
952
717
  "./migrations/1_initial.ts": M,
953
718
  "./migrations/2_fix-display_name.ts": ne,
954
719
  "./migrations/3_fix_fvi_foreign_key.ts": ae