@ocap/indexdb-sqlite 1.30.24 → 1.30.25
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 +14 -2
- package/esm/db/index.d.mts +1 -0
- package/esm/db/index.mjs +21 -1
- package/esm/index.d.mts +2 -1
- package/esm/index.mjs +2 -1
- package/esm/interfaces.d.mts +18 -2
- package/esm/kysely.d.mts +67 -7
- package/esm/kysely.mjs +1526 -16
- package/esm/migrations/001-genesis.mjs +1 -1
- package/esm/migrations/007-token-factory-feerate-integer.d.mts +7 -0
- package/esm/migrations/007-token-factory-feerate-integer.mjs +126 -0
- package/esm/migrations/008-index-failure.d.mts +14 -0
- package/esm/migrations/008-index-failure.mjs +25 -0
- package/esm/migrations/index.mjs +5 -1
- package/esm/package.mjs +1 -1
- package/lib/db/base.cjs +14 -2
- package/lib/db/index.cjs +21 -1
- package/lib/db/index.d.cts +1 -0
- package/lib/index.cjs +4 -1
- package/lib/index.d.cts +2 -1
- package/lib/interfaces.d.cts +18 -2
- package/lib/kysely.cjs +1528 -15
- package/lib/kysely.d.cts +67 -7
- package/lib/migrations/001-genesis.cjs +1 -1
- package/lib/migrations/007-token-factory-feerate-integer.cjs +133 -0
- package/lib/migrations/007-token-factory-feerate-integer.d.cts +7 -0
- package/lib/migrations/008-index-failure.cjs +32 -0
- package/lib/migrations/008-index-failure.d.cts +14 -0
- package/lib/migrations/index.cjs +5 -1
- package/lib/package.cjs +1 -1
- package/package.json +8 -6
package/esm/db/base.mjs
CHANGED
|
@@ -50,7 +50,14 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
|
|
|
50
50
|
const { tokenFactories = [] } = tokenFactoryFilter;
|
|
51
51
|
const pagination = formatPagination({
|
|
52
52
|
paging,
|
|
53
|
-
defaultSortField: "time"
|
|
53
|
+
defaultSortField: "time",
|
|
54
|
+
supportedSortFields: [
|
|
55
|
+
"genesisTime",
|
|
56
|
+
"renaissanceTime",
|
|
57
|
+
"time",
|
|
58
|
+
"sender",
|
|
59
|
+
"receiver"
|
|
60
|
+
]
|
|
54
61
|
});
|
|
55
62
|
debug("listTransactions", {
|
|
56
63
|
sender,
|
|
@@ -237,7 +244,12 @@ var SqliteBaseIndexDB = class extends BaseIndexDB {
|
|
|
237
244
|
const { ownerAddress, factoryAddress, paging, timeFilter = {} } = params;
|
|
238
245
|
const pagination = formatPagination({
|
|
239
246
|
paging,
|
|
240
|
-
defaultSortField: "renaissanceTime"
|
|
247
|
+
defaultSortField: "renaissanceTime",
|
|
248
|
+
supportedSortFields: [
|
|
249
|
+
"genesisTime",
|
|
250
|
+
"renaissanceTime",
|
|
251
|
+
"address"
|
|
252
|
+
]
|
|
241
253
|
});
|
|
242
254
|
let qb = this.db.selectFrom("asset").selectAll();
|
|
243
255
|
if (ownerAddress) {
|
package/esm/db/index.d.mts
CHANGED
|
@@ -29,6 +29,7 @@ declare class SqliteIndexDB extends SqliteBaseIndexDB implements IIndexDB {
|
|
|
29
29
|
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
30
30
|
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
31
31
|
balance: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
32
|
+
indexFailure: IIndexTable<IndexTableTypeMap['indexFailure']>;
|
|
32
33
|
/**
|
|
33
34
|
* Creates an instance of SqliteIndexDB
|
|
34
35
|
*
|
package/esm/db/index.mjs
CHANGED
|
@@ -501,6 +501,25 @@ var SqliteIndexDB = class extends base_default$1 {
|
|
|
501
501
|
]
|
|
502
502
|
}
|
|
503
503
|
});
|
|
504
|
+
this.indexFailure = new base_default({
|
|
505
|
+
name: "indexFailure",
|
|
506
|
+
uniqIndex: "id",
|
|
507
|
+
db: this.db,
|
|
508
|
+
schema: {
|
|
509
|
+
columnMapping: { table: "table_" },
|
|
510
|
+
knownColumns: [
|
|
511
|
+
"id",
|
|
512
|
+
"table",
|
|
513
|
+
"event",
|
|
514
|
+
"entityId",
|
|
515
|
+
"payload",
|
|
516
|
+
"attempts",
|
|
517
|
+
"lastError",
|
|
518
|
+
"createdAt",
|
|
519
|
+
"lastAttemptAt"
|
|
520
|
+
]
|
|
521
|
+
}
|
|
522
|
+
});
|
|
504
523
|
this.attachReadyListeners();
|
|
505
524
|
}
|
|
506
525
|
/**
|
|
@@ -538,7 +557,8 @@ var SqliteIndexDB = class extends base_default$1 {
|
|
|
538
557
|
"rollupBlock",
|
|
539
558
|
"rollupValidator",
|
|
540
559
|
"tokenDistribution",
|
|
541
|
-
"balance"
|
|
560
|
+
"balance",
|
|
561
|
+
"indexFailure"
|
|
542
562
|
]) {
|
|
543
563
|
const tableInstance = this[table];
|
|
544
564
|
if (tableInstance?.reset) await tableInstance.reset();
|
package/esm/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import SqliteBaseIndexDB from "./db/base.mjs";
|
|
2
|
+
import { DurableObjectSqliteDialect, DurableObjectSqliteDialectConfig, IDurableObjectSqlStorage, IDurableObjectSqlStorageCursor, SqliteConfig, getRawDatabase } from "./kysely.mjs";
|
|
2
3
|
import SqliteIndexDB from "./db/index.mjs";
|
|
3
|
-
export { SqliteBaseIndexDB, SqliteIndexDB as default };
|
|
4
|
+
export { DurableObjectSqliteDialect, type DurableObjectSqliteDialectConfig, type IDurableObjectSqlStorage, type IDurableObjectSqlStorageCursor, SqliteBaseIndexDB, type SqliteConfig, SqliteIndexDB as default, getRawDatabase };
|
package/esm/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DurableObjectSqliteDialect, getRawDatabase } from "./kysely.mjs";
|
|
1
2
|
import base_default from "./db/base.mjs";
|
|
2
3
|
import db_default from "./db/index.mjs";
|
|
3
4
|
|
|
@@ -5,4 +6,4 @@ import db_default from "./db/index.mjs";
|
|
|
5
6
|
var src_default = db_default;
|
|
6
7
|
|
|
7
8
|
//#endregion
|
|
8
|
-
export { base_default as SqliteBaseIndexDB, src_default as default };
|
|
9
|
+
export { DurableObjectSqliteDialect, base_default as SqliteBaseIndexDB, src_default as default, getRawDatabase };
|
package/esm/interfaces.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ interface Database {
|
|
|
21
21
|
tokenFactory: TokenFactoryTable;
|
|
22
22
|
balance: BalanceTable;
|
|
23
23
|
tx_ref: TxRefTable;
|
|
24
|
+
indexFailure: IndexFailureTable;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* Transaction table for indexed transactions
|
|
@@ -161,7 +162,7 @@ interface TokenFactoryTable {
|
|
|
161
162
|
reserveBalanceNum: string | null;
|
|
162
163
|
currentSupply: string | null;
|
|
163
164
|
currentSupplyNum: string | null;
|
|
164
|
-
feeRate:
|
|
165
|
+
feeRate: number | null;
|
|
165
166
|
token: string | null;
|
|
166
167
|
reserveToken: string | null;
|
|
167
168
|
input: string | null;
|
|
@@ -331,6 +332,21 @@ interface TxRefTable {
|
|
|
331
332
|
value: string;
|
|
332
333
|
time: string | null;
|
|
333
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* IndexFailure table: durable log of failed indexdb writes from connectIndexDB() (see #67).
|
|
337
|
+
* `table_` avoids colliding with the SQL keyword `table`.
|
|
338
|
+
*/
|
|
339
|
+
interface IndexFailureTable {
|
|
340
|
+
id: string;
|
|
341
|
+
table_: string;
|
|
342
|
+
event: string;
|
|
343
|
+
entityId: string;
|
|
344
|
+
payload: string | null;
|
|
345
|
+
attempts: number;
|
|
346
|
+
lastError: string | null;
|
|
347
|
+
createdAt: string;
|
|
348
|
+
lastAttemptAt: string;
|
|
349
|
+
}
|
|
334
350
|
/**
|
|
335
351
|
* SQLite-specific operation context with optional transaction
|
|
336
352
|
*/
|
|
@@ -338,4 +354,4 @@ interface SqliteOperationContext {
|
|
|
338
354
|
txn?: Transaction<Database>;
|
|
339
355
|
}
|
|
340
356
|
//#endregion
|
|
341
|
-
export { AccountTable, AssetTable, BalanceTable, Database, DelegationTable, FactoryTable, RollupBlockTable, RollupTable, RollupValidatorTable, SqliteOperationContext, StakeTable, TokenDistributionTable, TokenFactoryTable, TokenTable, TxRefTable, TxTable };
|
|
357
|
+
export { AccountTable, AssetTable, BalanceTable, Database, DelegationTable, FactoryTable, IndexFailureTable, RollupBlockTable, RollupTable, RollupValidatorTable, SqliteOperationContext, StakeTable, TokenDistributionTable, TokenFactoryTable, TokenTable, TxRefTable, TxTable };
|
package/esm/kysely.d.mts
CHANGED
|
@@ -1,22 +1,70 @@
|
|
|
1
1
|
import { Database } from "./interfaces.mjs";
|
|
2
|
-
import { Kysely } from "kysely";
|
|
2
|
+
import { DatabaseConnection, Dialect, Driver, Kysely, SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from "kysely";
|
|
3
|
+
import { ITrustedStorage } from "@ocap/types";
|
|
3
4
|
|
|
4
5
|
//#region src/kysely.d.ts
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Minimal Cloudflare Durable Object `SqlStorageCursor` contract (`ctx.storage.sql.exec(...)`).
|
|
9
|
+
*/
|
|
10
|
+
interface IDurableObjectSqlStorageCursor<T = Record<string, unknown>> {
|
|
11
|
+
toArray(): T[];
|
|
12
|
+
one?(): T;
|
|
13
|
+
raw?<U = unknown[]>(): IterableIterator<U> | U[];
|
|
14
|
+
columnNames?: string[];
|
|
15
|
+
rowsRead?: number;
|
|
16
|
+
rowsWritten?: number;
|
|
17
|
+
[Symbol.iterator]?(): IterableIterator<T>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Minimal Cloudflare Durable Object `SqlStorage` contract (`ctx.storage.sql`).
|
|
21
|
+
*/
|
|
22
|
+
interface IDurableObjectSqlStorage {
|
|
23
|
+
exec<T = Record<string, unknown>>(query: string, ...bindings: unknown[]): IDurableObjectSqlStorageCursor<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Optional Durable Object runtime transaction closure (`ctx.storage.transaction.bind(ctx.storage)`).
|
|
26
|
+
* When omitted, `DurableObjectSqliteDialect` still provides full atomic rollback via
|
|
27
|
+
* per-statement SQLite trigger undo logs and crash-recovery metadata without emitting
|
|
28
|
+
* forbidden BEGIN/SAVEPOINT SQL.
|
|
29
|
+
*/
|
|
30
|
+
transaction?<T>(closure: () => Promise<T>): Promise<T>;
|
|
31
|
+
databaseSize?: number;
|
|
32
|
+
}
|
|
33
|
+
interface DurableObjectSqliteDialectConfig {
|
|
34
|
+
storage: IDurableObjectSqlStorage;
|
|
35
|
+
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
declare function getDoStorageWriteEpoch(storage: IDurableObjectSqlStorage): number;
|
|
38
|
+
/**
|
|
39
|
+
* Kysely Dialect for Cloudflare Durable Object SQLite (`ctx.storage.sql`).
|
|
40
|
+
*/
|
|
41
|
+
declare class DurableObjectSqliteDialect implements Dialect {
|
|
42
|
+
private readonly config;
|
|
43
|
+
private readonly createdOrder;
|
|
44
|
+
constructor(config: DurableObjectSqliteDialectConfig);
|
|
45
|
+
createDriver(): Driver;
|
|
46
|
+
createQueryCompiler(): SqliteQueryCompiler;
|
|
47
|
+
createAdapter(): SqliteAdapter;
|
|
48
|
+
createIntrospector(db: Kysely<any>): SqliteIntrospector;
|
|
49
|
+
}
|
|
6
50
|
/**
|
|
7
51
|
* SQLite configuration options
|
|
8
52
|
*/
|
|
9
53
|
interface SqliteConfig {
|
|
10
54
|
/** Database file path. Use ':memory:' for in-memory database */
|
|
11
|
-
filename
|
|
55
|
+
filename?: string;
|
|
56
|
+
/** Cloudflare Durable Object `ctx.storage.sql` instance */
|
|
57
|
+
doStorage?: IDurableObjectSqlStorage;
|
|
58
|
+
/** Custom Kysely Dialect override */
|
|
59
|
+
dialect?: Dialect;
|
|
60
|
+
/** Optional trusted storage instance for state commit hash verification */
|
|
61
|
+
trustedStorage?: ITrustedStorage;
|
|
12
62
|
/** Open database in readonly mode */
|
|
13
63
|
readonly?: boolean;
|
|
14
64
|
/** Throw error if file doesn't exist (default: false, creates new file) */
|
|
15
65
|
create?: boolean;
|
|
16
66
|
/** Enable WAL mode (default: true) */
|
|
17
67
|
walMode?: boolean;
|
|
18
|
-
/** Busy timeout in ms (default: SQLITE_BUSY_TIMEOUT env or 5000) */
|
|
19
|
-
busyTimeout?: number;
|
|
20
68
|
/**
|
|
21
69
|
* `PRAGMA wal_autocheckpoint` value (in 4KB pages) when WAL is enabled.
|
|
22
70
|
* SQLite default is 1000 pages (~4MB) which forces a synchronous WAL→main
|
|
@@ -29,10 +77,22 @@ interface SqliteConfig {
|
|
|
29
77
|
* provided. If neither is set, SQLite's default (1000) is left untouched.
|
|
30
78
|
*/
|
|
31
79
|
walAutoCheckpoint?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Optional interval (in ms) for a background passive WAL checkpoint worker
|
|
82
|
+
* (`PRAGMA wal_checkpoint(PASSIVE)`). When > 0 and WAL mode is enabled, a
|
|
83
|
+
* non-blocking (`unref()`ed) periodic timer checkpoints frames back to the
|
|
84
|
+
* main DB file out-of-band without blocking readers or writers.
|
|
85
|
+
*
|
|
86
|
+
* Falls back to `SQLITE_WAL_CHECKPOINT_INTERVAL_MS` env when not provided.
|
|
87
|
+
* Disabled by default (0 / undefined).
|
|
88
|
+
*/
|
|
89
|
+
walCheckpointIntervalMs?: number;
|
|
32
90
|
}
|
|
91
|
+
declare function resolveWalCheckpointIntervalMs(config: SqliteConfig): number | undefined;
|
|
33
92
|
/**
|
|
34
93
|
* Create a Kysely instance with SQLite dialect
|
|
35
|
-
* Automatically uses
|
|
94
|
+
* Automatically uses DurableObjectSqliteDialect when `config.doStorage` is provided,
|
|
95
|
+
* custom `config.dialect` when provided, kysely-bun-sqlite in Bun, or better-sqlite3 in Node.js
|
|
36
96
|
*
|
|
37
97
|
* @param config - SQLite configuration
|
|
38
98
|
* @returns Kysely instance configured for the database
|
|
@@ -43,7 +103,7 @@ interface SqliteConfig {
|
|
|
43
103
|
* const db = createKysely({ filename: ':memory:' });
|
|
44
104
|
*
|
|
45
105
|
* // File-based database for production
|
|
46
|
-
* const db = createKysely({ filename: './data/
|
|
106
|
+
* const db = createKysely({ filename: './data/state.sqlite' });
|
|
47
107
|
* ```
|
|
48
108
|
*/
|
|
49
109
|
declare function createKysely(config: SqliteConfig): Kysely<Database>;
|
|
@@ -54,4 +114,4 @@ declare function createKysely(config: SqliteConfig): Kysely<Database>;
|
|
|
54
114
|
*/
|
|
55
115
|
declare function getRawDatabase(db: Kysely<Database>): any;
|
|
56
116
|
//#endregion
|
|
57
|
-
export { SqliteConfig, createKysely, getRawDatabase };
|
|
117
|
+
export { DurableObjectSqliteDialect, DurableObjectSqliteDialectConfig, IDurableObjectSqlStorage, IDurableObjectSqlStorageCursor, SqliteConfig, createKysely, getDoStorageWriteEpoch, getRawDatabase, resolveWalCheckpointIntervalMs };
|