@ocap/indexdb-sqlite 1.30.9 → 1.30.11
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 +2 -18
- package/esm/kysely.d.mts +12 -0
- package/esm/kysely.mjs +13 -0
- package/lib/db/base.cjs +2 -18
- package/lib/kysely.cjs +13 -0
- package/lib/kysely.d.cts +12 -0
- package/package.json +5 -5
package/esm/db/base.mjs
CHANGED
|
@@ -235,15 +235,6 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
|
|
|
235
235
|
*/
|
|
236
236
|
async listAssets(params = {}) {
|
|
237
237
|
const { ownerAddress, factoryAddress, paging, timeFilter = {} } = params;
|
|
238
|
-
if (!ownerAddress && !factoryAddress) return {
|
|
239
|
-
assets: [],
|
|
240
|
-
account: null,
|
|
241
|
-
paging: {
|
|
242
|
-
cursor: "0",
|
|
243
|
-
next: false,
|
|
244
|
-
total: 0
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
238
|
const pagination = formatPagination({
|
|
248
239
|
paging,
|
|
249
240
|
defaultSortField: "renaissanceTime"
|
|
@@ -316,13 +307,14 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
|
|
|
316
307
|
const { paging, tokenAddress } = params;
|
|
317
308
|
const pagination = formatPagination({
|
|
318
309
|
paging,
|
|
319
|
-
defaultSortField: "balance",
|
|
310
|
+
defaultSortField: tokenAddress ? "balance" : "renaissanceTime",
|
|
320
311
|
supportedSortFields: [
|
|
321
312
|
"genesisTime",
|
|
322
313
|
"renaissanceTime",
|
|
323
314
|
"balance"
|
|
324
315
|
]
|
|
325
316
|
});
|
|
317
|
+
if (pagination.order.field === "balance" && !tokenAddress) throw new Error("tokenAddress is required when order.field is balance");
|
|
326
318
|
debug("listTopAccounts", {
|
|
327
319
|
tokenAddress,
|
|
328
320
|
paging,
|
|
@@ -704,14 +696,6 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
|
|
|
704
696
|
*/
|
|
705
697
|
async listDelegations(params = {}) {
|
|
706
698
|
const { from, to, paging = {}, timeFilter = {} } = params;
|
|
707
|
-
if (!from && !to) return {
|
|
708
|
-
delegations: [],
|
|
709
|
-
paging: {
|
|
710
|
-
cursor: "0",
|
|
711
|
-
next: false,
|
|
712
|
-
total: 0
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
699
|
const pagination = formatPagination({
|
|
716
700
|
paging,
|
|
717
701
|
defaultSortField: "renaissanceTime",
|
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
|
@@ -239,15 +239,6 @@ var SqliteBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
239
239
|
*/
|
|
240
240
|
async listAssets(params = {}) {
|
|
241
241
|
const { ownerAddress, factoryAddress, paging, timeFilter = {} } = params;
|
|
242
|
-
if (!ownerAddress && !factoryAddress) return {
|
|
243
|
-
assets: [],
|
|
244
|
-
account: null,
|
|
245
|
-
paging: {
|
|
246
|
-
cursor: "0",
|
|
247
|
-
next: false,
|
|
248
|
-
total: 0
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
242
|
const pagination = (0, _ocap_indexdb.formatPagination)({
|
|
252
243
|
paging,
|
|
253
244
|
defaultSortField: "renaissanceTime"
|
|
@@ -320,13 +311,14 @@ var SqliteBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
320
311
|
const { paging, tokenAddress } = params;
|
|
321
312
|
const pagination = (0, _ocap_indexdb.formatPagination)({
|
|
322
313
|
paging,
|
|
323
|
-
defaultSortField: "balance",
|
|
314
|
+
defaultSortField: tokenAddress ? "balance" : "renaissanceTime",
|
|
324
315
|
supportedSortFields: [
|
|
325
316
|
"genesisTime",
|
|
326
317
|
"renaissanceTime",
|
|
327
318
|
"balance"
|
|
328
319
|
]
|
|
329
320
|
});
|
|
321
|
+
if (pagination.order.field === "balance" && !tokenAddress) throw new Error("tokenAddress is required when order.field is balance");
|
|
330
322
|
debug$1("listTopAccounts", {
|
|
331
323
|
tokenAddress,
|
|
332
324
|
paging,
|
|
@@ -708,14 +700,6 @@ var SqliteBaseIndexDB = class extends _ocap_indexdb.BaseIndexDB {
|
|
|
708
700
|
*/
|
|
709
701
|
async listDelegations(params = {}) {
|
|
710
702
|
const { from, to, paging = {}, timeFilter = {} } = params;
|
|
711
|
-
if (!from && !to) return {
|
|
712
|
-
delegations: [],
|
|
713
|
-
paging: {
|
|
714
|
-
cursor: "0",
|
|
715
|
-
next: false,
|
|
716
|
-
total: 0
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
703
|
const pagination = (0, _ocap_indexdb.formatPagination)({
|
|
720
704
|
paging,
|
|
721
705
|
defaultSortField: "renaissanceTime",
|
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.
|
|
4
|
+
"version": "1.30.11",
|
|
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.
|
|
65
|
-
"@ocap/indexdb": "1.30.
|
|
66
|
-
"@ocap/types": "1.30.
|
|
67
|
-
"@ocap/util": "1.30.
|
|
64
|
+
"@arcblock/did": "1.30.11",
|
|
65
|
+
"@ocap/indexdb": "1.30.11",
|
|
66
|
+
"@ocap/types": "1.30.11",
|
|
67
|
+
"@ocap/util": "1.30.11",
|
|
68
68
|
"debug": "^4.4.3",
|
|
69
69
|
"better-sqlite3": "^11.8.1",
|
|
70
70
|
"kysely": "^0.28.14",
|