@ocap/indexdb-sqlite 1.30.10 → 1.30.12

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/esm/db/base.mjs CHANGED
@@ -307,13 +307,14 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
307
307
  const { paging, tokenAddress } = params;
308
308
  const pagination = formatPagination({
309
309
  paging,
310
- defaultSortField: "balance",
310
+ defaultSortField: tokenAddress ? "balance" : "renaissanceTime",
311
311
  supportedSortFields: [
312
312
  "genesisTime",
313
313
  "renaissanceTime",
314
314
  "balance"
315
315
  ]
316
316
  });
317
+ if (pagination.order.field === "balance" && !tokenAddress) throw new Error("tokenAddress is required when order.field is balance");
317
318
  debug("listTopAccounts", {
318
319
  tokenAddress,
319
320
  paging,
package/esm/kysely.d.mts CHANGED
@@ -17,6 +17,18 @@ interface SqliteConfig {
17
17
  walMode?: boolean;
18
18
  /** Busy timeout in ms (default: SQLITE_BUSY_TIMEOUT env or 5000) */
19
19
  busyTimeout?: number;
20
+ /**
21
+ * `PRAGMA wal_autocheckpoint` value (in 4KB pages) when WAL is enabled.
22
+ * SQLite default is 1000 pages (~4MB) which forces a synchronous WAL→main
23
+ * DB checkpoint inside writer transactions every ~30s at 100 TPS, causing
24
+ * latency spikes. Bumping it spreads I/O over a larger window. Set to 0
25
+ * to disable auto-checkpoint entirely (caller must run periodic
26
+ * `wal_checkpoint(PASSIVE)` from a background worker).
27
+ *
28
+ * Falls back to `SQLITE_WAL_AUTOCHECKPOINT` env (process-global) when not
29
+ * provided. If neither is set, SQLite's default (1000) is left untouched.
30
+ */
31
+ walAutoCheckpoint?: number;
20
32
  }
21
33
  /**
22
34
  * Create a Kysely instance with SQLite dialect
package/esm/kysely.mjs CHANGED
@@ -3,6 +3,15 @@ import { Kysely, SqliteDialect } from "kysely";
3
3
 
4
4
  //#region src/kysely.ts
5
5
  const DEFAULT_BUSY_TIMEOUT = Number(process.env.SQLITE_BUSY_TIMEOUT) || 5e3;
6
+ /**
7
+ * Env is read at call time (not module load) so test harnesses and lazy
8
+ * config flows work uniformly.
9
+ */
10
+ function resolveWalAutoCheckpoint(config) {
11
+ const fromEnv = process.env.SQLITE_WAL_AUTOCHECKPOINT ? Number(process.env.SQLITE_WAL_AUTOCHECKPOINT) : void 0;
12
+ const v = config.walAutoCheckpoint ?? fromEnv;
13
+ return Number.isFinite(v) ? v : void 0;
14
+ }
6
15
  function isBunRuntime() {
7
16
  return typeof globalThis.Bun !== "undefined";
8
17
  }
@@ -33,6 +42,8 @@ function createKysely(config) {
33
42
  if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
34
43
  sqlite$1.exec("PRAGMA journal_mode = WAL");
35
44
  sqlite$1.exec("PRAGMA synchronous = NORMAL");
45
+ const walCp = resolveWalAutoCheckpoint(config);
46
+ if (walCp !== void 0) sqlite$1.exec(`PRAGMA wal_autocheckpoint = ${walCp}`);
36
47
  }
37
48
  sqlite$1.exec("PRAGMA foreign_keys = ON");
38
49
  sqlite$1.exec(`PRAGMA busy_timeout = ${config.busyTimeout ?? DEFAULT_BUSY_TIMEOUT}`);
@@ -45,6 +56,8 @@ function createKysely(config) {
45
56
  if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
46
57
  sqlite.pragma("journal_mode = WAL");
47
58
  sqlite.pragma("synchronous = NORMAL");
59
+ const walCp = resolveWalAutoCheckpoint(config);
60
+ if (walCp !== void 0) sqlite.pragma(`wal_autocheckpoint = ${walCp}`);
48
61
  }
49
62
  sqlite.pragma("foreign_keys = ON");
50
63
  sqlite.pragma(`busy_timeout = ${config.busyTimeout ?? DEFAULT_BUSY_TIMEOUT}`);
package/lib/db/base.cjs CHANGED
@@ -311,13 +311,14 @@ var SqliteBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
311
311
  const { paging, tokenAddress } = params;
312
312
  const pagination = (0, _ocap_indexdb.formatPagination)({
313
313
  paging,
314
- defaultSortField: "balance",
314
+ defaultSortField: tokenAddress ? "balance" : "renaissanceTime",
315
315
  supportedSortFields: [
316
316
  "genesisTime",
317
317
  "renaissanceTime",
318
318
  "balance"
319
319
  ]
320
320
  });
321
+ if (pagination.order.field === "balance" && !tokenAddress) throw new Error("tokenAddress is required when order.field is balance");
321
322
  debug$1("listTopAccounts", {
322
323
  tokenAddress,
323
324
  paging,
package/lib/kysely.cjs CHANGED
@@ -3,6 +3,15 @@ let kysely = require("kysely");
3
3
 
4
4
  //#region src/kysely.ts
5
5
  const DEFAULT_BUSY_TIMEOUT = Number(process.env.SQLITE_BUSY_TIMEOUT) || 5e3;
6
+ /**
7
+ * Env is read at call time (not module load) so test harnesses and lazy
8
+ * config flows work uniformly.
9
+ */
10
+ function resolveWalAutoCheckpoint(config) {
11
+ const fromEnv = process.env.SQLITE_WAL_AUTOCHECKPOINT ? Number(process.env.SQLITE_WAL_AUTOCHECKPOINT) : void 0;
12
+ const v = config.walAutoCheckpoint ?? fromEnv;
13
+ return Number.isFinite(v) ? v : void 0;
14
+ }
6
15
  function isBunRuntime() {
7
16
  return typeof globalThis.Bun !== "undefined";
8
17
  }
@@ -33,6 +42,8 @@ function createKysely(config) {
33
42
  if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
34
43
  sqlite$1.exec("PRAGMA journal_mode = WAL");
35
44
  sqlite$1.exec("PRAGMA synchronous = NORMAL");
45
+ const walCp = resolveWalAutoCheckpoint(config);
46
+ if (walCp !== void 0) sqlite$1.exec(`PRAGMA wal_autocheckpoint = ${walCp}`);
36
47
  }
37
48
  sqlite$1.exec("PRAGMA foreign_keys = ON");
38
49
  sqlite$1.exec(`PRAGMA busy_timeout = ${config.busyTimeout ?? DEFAULT_BUSY_TIMEOUT}`);
@@ -45,6 +56,8 @@ function createKysely(config) {
45
56
  if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
46
57
  sqlite.pragma("journal_mode = WAL");
47
58
  sqlite.pragma("synchronous = NORMAL");
59
+ const walCp = resolveWalAutoCheckpoint(config);
60
+ if (walCp !== void 0) sqlite.pragma(`wal_autocheckpoint = ${walCp}`);
48
61
  }
49
62
  sqlite.pragma("foreign_keys = ON");
50
63
  sqlite.pragma(`busy_timeout = ${config.busyTimeout ?? DEFAULT_BUSY_TIMEOUT}`);
package/lib/kysely.d.cts CHANGED
@@ -17,6 +17,18 @@ interface SqliteConfig {
17
17
  walMode?: boolean;
18
18
  /** Busy timeout in ms (default: SQLITE_BUSY_TIMEOUT env or 5000) */
19
19
  busyTimeout?: number;
20
+ /**
21
+ * `PRAGMA wal_autocheckpoint` value (in 4KB pages) when WAL is enabled.
22
+ * SQLite default is 1000 pages (~4MB) which forces a synchronous WAL→main
23
+ * DB checkpoint inside writer transactions every ~30s at 100 TPS, causing
24
+ * latency spikes. Bumping it spreads I/O over a larger window. Set to 0
25
+ * to disable auto-checkpoint entirely (caller must run periodic
26
+ * `wal_checkpoint(PASSIVE)` from a background worker).
27
+ *
28
+ * Falls back to `SQLITE_WAL_AUTOCHECKPOINT` env (process-global) when not
29
+ * provided. If neither is set, SQLite's default (1000) is left untouched.
30
+ */
31
+ walAutoCheckpoint?: number;
20
32
  }
21
33
  /**
22
34
  * Create a Kysely instance with SQLite dialect
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocap/indexdb-sqlite",
3
3
  "description": "OCAP indexdb adapter that uses SQLite as backend",
4
- "version": "1.30.10",
4
+ "version": "1.30.12",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ArcBlock/blockchain/issues",
@@ -61,10 +61,10 @@
61
61
  "clean": "rm -rf lib esm"
62
62
  },
63
63
  "dependencies": {
64
- "@arcblock/did": "1.30.10",
65
- "@ocap/indexdb": "1.30.10",
66
- "@ocap/types": "1.30.10",
67
- "@ocap/util": "1.30.10",
64
+ "@arcblock/did": "1.30.12",
65
+ "@ocap/indexdb": "1.30.12",
66
+ "@ocap/types": "1.30.12",
67
+ "@ocap/util": "1.30.12",
68
68
  "debug": "^4.4.3",
69
69
  "better-sqlite3": "^11.8.1",
70
70
  "kysely": "^0.28.14",