@concavejs/docstore-better-sqlite3 0.0.1-alpha.6 → 0.0.1-alpha.7

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.
@@ -5,12 +5,13 @@
5
5
  * which works in Electron without --experimental-sqlite flags.
6
6
  */
7
7
  import type Database from "better-sqlite3";
8
- import type { SqliteAdapter, PreparedStatement, SqlParam, TransactionFn } from "@concavejs/docstore-sqlite-base";
8
+ import { type SqliteAdapter, type PreparedStatement, type SqlParam, type TransactionFn } from "@concavejs/docstore-sqlite-base";
9
9
  /**
10
10
  * better-sqlite3 adapter for SqliteAdapter interface
11
11
  */
12
12
  export declare class BetterSqlite3Adapter implements SqliteAdapter {
13
13
  private db;
14
+ private readonly runSerializedTransaction;
14
15
  constructor(db: Database.Database);
15
16
  exec(sql: string): void;
16
17
  prepare(sql: string): PreparedStatement;
package/dist/index.js CHANGED
@@ -5588,6 +5588,8 @@ function decodeJwtClaimsToken(token) {
5588
5588
  return null;
5589
5589
  }
5590
5590
  }
5591
+ var DEFAULT_JWKS_CACHE_TTL_MS = 5 * 60 * 1000;
5592
+ var MAX_JWKS_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
5591
5593
  var JWKS_CACHE = new Map;
5592
5594
  function decodeJwtUnsafe(token) {
5593
5595
  if (!token)
@@ -6424,6 +6426,30 @@ class BaseSqliteDocStore {
6424
6426
  return scored.slice(0, limit);
6425
6427
  }
6426
6428
  }
6429
+ function createSerializedTransactionRunner(hooks) {
6430
+ let queue = Promise.resolve();
6431
+ return async function runInTransaction(fn) {
6432
+ const run = queue.then(async () => {
6433
+ await hooks.begin();
6434
+ try {
6435
+ const result = await fn();
6436
+ await hooks.commit();
6437
+ return result;
6438
+ } catch (error) {
6439
+ try {
6440
+ await hooks.rollback();
6441
+ } catch {}
6442
+ throw error;
6443
+ }
6444
+ });
6445
+ queue = run.then(() => {
6446
+ return;
6447
+ }, () => {
6448
+ return;
6449
+ });
6450
+ return run;
6451
+ };
6452
+ }
6427
6453
  // ../core/dist/utils/long.js
6428
6454
  class Long2 {
6429
6455
  low;
@@ -6582,8 +6608,20 @@ class BetterSqlite3PreparedStatement {
6582
6608
 
6583
6609
  class BetterSqlite3Adapter {
6584
6610
  db;
6611
+ runSerializedTransaction;
6585
6612
  constructor(db) {
6586
6613
  this.db = db;
6614
+ this.runSerializedTransaction = createSerializedTransactionRunner({
6615
+ begin: () => {
6616
+ this.db.exec("BEGIN TRANSACTION");
6617
+ },
6618
+ commit: () => {
6619
+ this.db.exec("COMMIT");
6620
+ },
6621
+ rollback: () => {
6622
+ this.db.exec("ROLLBACK");
6623
+ }
6624
+ });
6587
6625
  }
6588
6626
  exec(sql) {
6589
6627
  this.db.exec(sql);
@@ -6592,15 +6630,7 @@ class BetterSqlite3Adapter {
6592
6630
  return new BetterSqlite3PreparedStatement(this.db.prepare(sql));
6593
6631
  }
6594
6632
  async transaction(fn) {
6595
- try {
6596
- this.db.exec("BEGIN TRANSACTION");
6597
- const result = await fn();
6598
- this.db.exec("COMMIT");
6599
- return result;
6600
- } catch (error) {
6601
- this.db.exec("ROLLBACK");
6602
- throw error;
6603
- }
6633
+ return this.runSerializedTransaction(fn);
6604
6634
  }
6605
6635
  hexToBuffer(hex) {
6606
6636
  return Buffer.from(hexToArrayBuffer3(hex));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concavejs/docstore-better-sqlite3",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-alpha.7",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"