@ocap/indexdb-sqlite 1.29.5
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/README.md +84 -0
- package/esm/_virtual/rolldown_runtime.mjs +21 -0
- package/esm/db/base.d.mts +76 -0
- package/esm/db/base.mjs +666 -0
- package/esm/db/index.d.mts +80 -0
- package/esm/db/index.mjs +551 -0
- package/esm/index.d.mts +3 -0
- package/esm/index.mjs +8 -0
- package/esm/interfaces.d.mts +328 -0
- package/esm/interfaces.mjs +1 -0
- package/esm/kysely.d.mts +43 -0
- package/esm/kysely.mjs +62 -0
- package/esm/migrations/001-genesis.d.mts +14 -0
- package/esm/migrations/001-genesis.mjs +107 -0
- package/esm/migrations/index.d.mts +16 -0
- package/esm/migrations/index.mjs +44 -0
- package/esm/package.mjs +70 -0
- package/esm/table/base.d.mts +107 -0
- package/esm/table/base.mjs +262 -0
- package/esm/table/transaction.d.mts +18 -0
- package/esm/table/transaction.mjs +22 -0
- package/lib/_virtual/rolldown_runtime.cjs +43 -0
- package/lib/db/base.cjs +670 -0
- package/lib/db/base.d.cts +76 -0
- package/lib/db/index.cjs +552 -0
- package/lib/db/index.d.cts +80 -0
- package/lib/index.cjs +10 -0
- package/lib/index.d.cts +3 -0
- package/lib/interfaces.cjs +0 -0
- package/lib/interfaces.d.cts +328 -0
- package/lib/kysely.cjs +63 -0
- package/lib/kysely.d.cts +43 -0
- package/lib/migrations/001-genesis.cjs +114 -0
- package/lib/migrations/001-genesis.d.cts +14 -0
- package/lib/migrations/index.cjs +46 -0
- package/lib/migrations/index.d.cts +16 -0
- package/lib/package.cjs +76 -0
- package/lib/table/base.cjs +265 -0
- package/lib/table/base.d.cts +107 -0
- package/lib/table/transaction.cjs +24 -0
- package/lib/table/transaction.d.cts +18 -0
- package/package.json +75 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Database } from "../interfaces.mjs";
|
|
2
|
+
import SqliteBaseIndexDB from "./base.mjs";
|
|
3
|
+
import { SqliteConfig } from "../kysely.mjs";
|
|
4
|
+
import { Kysely, Transaction } from "kysely";
|
|
5
|
+
import { IIndexDB, IIndexTable, IndexTableTypeMap } from "@ocap/types";
|
|
6
|
+
|
|
7
|
+
//#region src/db/index.d.ts
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SQLite IndexDB Implementation
|
|
11
|
+
* Uses SQLite via Kysely as the storage backend for indexed blockchain data
|
|
12
|
+
*/
|
|
13
|
+
declare class SqliteIndexDB extends SqliteBaseIndexDB implements IIndexDB {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
protected db: Kysely<Database>;
|
|
17
|
+
private config;
|
|
18
|
+
private initialized;
|
|
19
|
+
tx: IIndexTable<IndexTableTypeMap['tx']>;
|
|
20
|
+
account: IIndexTable<IndexTableTypeMap['account']>;
|
|
21
|
+
asset: IIndexTable<IndexTableTypeMap['asset']>;
|
|
22
|
+
token: IIndexTable<IndexTableTypeMap['token']>;
|
|
23
|
+
factory: IIndexTable<IndexTableTypeMap['factory']>;
|
|
24
|
+
stake: IIndexTable<IndexTableTypeMap['stake']>;
|
|
25
|
+
delegation: IIndexTable<IndexTableTypeMap['delegation']>;
|
|
26
|
+
rollup: IIndexTable<IndexTableTypeMap['rollup']>;
|
|
27
|
+
rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
|
|
28
|
+
rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
|
|
29
|
+
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
30
|
+
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
31
|
+
balance: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of SqliteIndexDB
|
|
34
|
+
*
|
|
35
|
+
* @param config - SQLite configuration (defaults to in-memory)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // In-memory database for testing
|
|
40
|
+
* const db = new SqliteIndexDB();
|
|
41
|
+
* await db.initialize();
|
|
42
|
+
*
|
|
43
|
+
* // File-based database for production
|
|
44
|
+
* const db = new SqliteIndexDB({ filename: './data/index.sqlite' });
|
|
45
|
+
* await db.initialize();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
constructor(config?: SqliteConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Synchronous initialization
|
|
51
|
+
* Called from constructor for immediate table availability
|
|
52
|
+
*/
|
|
53
|
+
private initSync;
|
|
54
|
+
/**
|
|
55
|
+
* Async initialization - runs migrations
|
|
56
|
+
* Call this after constructor to ensure database schema is ready
|
|
57
|
+
*/
|
|
58
|
+
initialize(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute multiple operations within a database transaction
|
|
61
|
+
*
|
|
62
|
+
* @param fn - Function receiving Kysely transaction object
|
|
63
|
+
* @returns Result of the transaction function
|
|
64
|
+
*/
|
|
65
|
+
runAsLambda<T>(fn: (txn: Transaction<Database>) => T | Promise<T>): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Reset all tables (for testing)
|
|
68
|
+
*/
|
|
69
|
+
reset(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Close database connection
|
|
72
|
+
*/
|
|
73
|
+
close(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the underlying Kysely instance (for advanced operations)
|
|
76
|
+
*/
|
|
77
|
+
getKysely(): Kysely<Database>;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { SqliteIndexDB as default };
|
package/esm/db/index.mjs
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { createKysely } from "../kysely.mjs";
|
|
2
|
+
import { runMigrations } from "../migrations/index.mjs";
|
|
3
|
+
import base_default from "../table/base.mjs";
|
|
4
|
+
import transaction_default from "../table/transaction.mjs";
|
|
5
|
+
import base_default$1 from "./base.mjs";
|
|
6
|
+
import package_default from "../package.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/db/index.ts
|
|
9
|
+
const { name, version } = package_default;
|
|
10
|
+
/**
|
|
11
|
+
* SQLite IndexDB Implementation
|
|
12
|
+
* Uses SQLite via Kysely as the storage backend for indexed blockchain data
|
|
13
|
+
*/
|
|
14
|
+
var SqliteIndexDB = class extends base_default$1 {
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of SqliteIndexDB
|
|
17
|
+
*
|
|
18
|
+
* @param config - SQLite configuration (defaults to in-memory)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // In-memory database for testing
|
|
23
|
+
* const db = new SqliteIndexDB();
|
|
24
|
+
* await db.initialize();
|
|
25
|
+
*
|
|
26
|
+
* // File-based database for production
|
|
27
|
+
* const db = new SqliteIndexDB({ filename: './data/index.sqlite' });
|
|
28
|
+
* await db.initialize();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
constructor(config = { filename: ":memory:" }) {
|
|
32
|
+
super();
|
|
33
|
+
this.initialized = false;
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.version = version;
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.initSync();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Synchronous initialization
|
|
41
|
+
* Called from constructor for immediate table availability
|
|
42
|
+
*/
|
|
43
|
+
initSync() {
|
|
44
|
+
this.db = createKysely(this.config);
|
|
45
|
+
this.tx = new transaction_default({
|
|
46
|
+
name: "tx",
|
|
47
|
+
uniqIndex: "hash",
|
|
48
|
+
db: this.db,
|
|
49
|
+
schema: {
|
|
50
|
+
jsonFields: [
|
|
51
|
+
"receipts",
|
|
52
|
+
"tx",
|
|
53
|
+
"accounts",
|
|
54
|
+
"assets",
|
|
55
|
+
"tokens",
|
|
56
|
+
"tokenSymbols",
|
|
57
|
+
"factories",
|
|
58
|
+
"rollups",
|
|
59
|
+
"stakes",
|
|
60
|
+
"delegations",
|
|
61
|
+
"tokenFactories",
|
|
62
|
+
"data"
|
|
63
|
+
],
|
|
64
|
+
booleanFields: [
|
|
65
|
+
"receiptsVerified",
|
|
66
|
+
"finalized",
|
|
67
|
+
"valid"
|
|
68
|
+
],
|
|
69
|
+
columnMapping: { index: "index_" },
|
|
70
|
+
knownColumns: [
|
|
71
|
+
"hash",
|
|
72
|
+
"code",
|
|
73
|
+
"height",
|
|
74
|
+
"index",
|
|
75
|
+
"receipts",
|
|
76
|
+
"receiptsVerified",
|
|
77
|
+
"receiver",
|
|
78
|
+
"sender",
|
|
79
|
+
"time",
|
|
80
|
+
"tx",
|
|
81
|
+
"type",
|
|
82
|
+
"finalized",
|
|
83
|
+
"valid",
|
|
84
|
+
"accounts",
|
|
85
|
+
"assets",
|
|
86
|
+
"tokens",
|
|
87
|
+
"tokenSymbols",
|
|
88
|
+
"factories",
|
|
89
|
+
"rollups",
|
|
90
|
+
"stakes",
|
|
91
|
+
"delegations",
|
|
92
|
+
"tokenFactories",
|
|
93
|
+
"genesisTime",
|
|
94
|
+
"renaissanceTime",
|
|
95
|
+
"data"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
this.account = new base_default({
|
|
100
|
+
name: "account",
|
|
101
|
+
uniqIndex: "address",
|
|
102
|
+
db: this.db,
|
|
103
|
+
schema: {
|
|
104
|
+
jsonFields: [
|
|
105
|
+
"stake",
|
|
106
|
+
"tokens",
|
|
107
|
+
"data"
|
|
108
|
+
],
|
|
109
|
+
numericFields: { balance: "balanceNum" },
|
|
110
|
+
knownColumns: [
|
|
111
|
+
"address",
|
|
112
|
+
"balance",
|
|
113
|
+
"gasBalance",
|
|
114
|
+
"moniker",
|
|
115
|
+
"pk",
|
|
116
|
+
"nonce",
|
|
117
|
+
"numTxs",
|
|
118
|
+
"numAssets",
|
|
119
|
+
"issuer",
|
|
120
|
+
"migratedTo",
|
|
121
|
+
"migratedFrom",
|
|
122
|
+
"stake",
|
|
123
|
+
"tokens",
|
|
124
|
+
"data",
|
|
125
|
+
"genesisTime",
|
|
126
|
+
"renaissanceTime"
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.asset = new base_default({
|
|
131
|
+
name: "asset",
|
|
132
|
+
uniqIndex: "address",
|
|
133
|
+
db: this.db,
|
|
134
|
+
schema: {
|
|
135
|
+
jsonFields: [
|
|
136
|
+
"display",
|
|
137
|
+
"tags",
|
|
138
|
+
"stake",
|
|
139
|
+
"data"
|
|
140
|
+
],
|
|
141
|
+
booleanFields: ["readonly", "transferrable"],
|
|
142
|
+
knownColumns: [
|
|
143
|
+
"address",
|
|
144
|
+
"owner",
|
|
145
|
+
"moniker",
|
|
146
|
+
"readonly",
|
|
147
|
+
"transferrable",
|
|
148
|
+
"issuer",
|
|
149
|
+
"parent",
|
|
150
|
+
"ttl",
|
|
151
|
+
"consumedTime",
|
|
152
|
+
"endpoint",
|
|
153
|
+
"display",
|
|
154
|
+
"tags",
|
|
155
|
+
"stake",
|
|
156
|
+
"data",
|
|
157
|
+
"genesisTime",
|
|
158
|
+
"renaissanceTime"
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
this.token = new base_default({
|
|
163
|
+
name: "token",
|
|
164
|
+
uniqIndex: "address",
|
|
165
|
+
db: this.db,
|
|
166
|
+
schema: {
|
|
167
|
+
jsonFields: [
|
|
168
|
+
"foreignToken",
|
|
169
|
+
"metadata",
|
|
170
|
+
"spenders",
|
|
171
|
+
"minters",
|
|
172
|
+
"data"
|
|
173
|
+
],
|
|
174
|
+
numericFields: { totalSupply: "totalSupplyNum" },
|
|
175
|
+
knownColumns: [
|
|
176
|
+
"address",
|
|
177
|
+
"symbol",
|
|
178
|
+
"name",
|
|
179
|
+
"decimal",
|
|
180
|
+
"unit",
|
|
181
|
+
"description",
|
|
182
|
+
"icon",
|
|
183
|
+
"totalSupply",
|
|
184
|
+
"initialSupply",
|
|
185
|
+
"maxTotalSupply",
|
|
186
|
+
"foreignToken",
|
|
187
|
+
"issuer",
|
|
188
|
+
"website",
|
|
189
|
+
"metadata",
|
|
190
|
+
"tokenFactoryAddress",
|
|
191
|
+
"spenders",
|
|
192
|
+
"minters",
|
|
193
|
+
"type",
|
|
194
|
+
"data",
|
|
195
|
+
"genesisTime",
|
|
196
|
+
"renaissanceTime"
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
this.factory = new base_default({
|
|
201
|
+
name: "factory",
|
|
202
|
+
uniqIndex: "address",
|
|
203
|
+
db: this.db,
|
|
204
|
+
schema: {
|
|
205
|
+
jsonFields: [
|
|
206
|
+
"trustedIssuers",
|
|
207
|
+
"tokens",
|
|
208
|
+
"input",
|
|
209
|
+
"output",
|
|
210
|
+
"display",
|
|
211
|
+
"hooks",
|
|
212
|
+
"data"
|
|
213
|
+
],
|
|
214
|
+
columnMapping: { limit: "limit_" },
|
|
215
|
+
knownColumns: [
|
|
216
|
+
"address",
|
|
217
|
+
"owner",
|
|
218
|
+
"name",
|
|
219
|
+
"description",
|
|
220
|
+
"settlement",
|
|
221
|
+
"limit",
|
|
222
|
+
"trustedIssuers",
|
|
223
|
+
"tokens",
|
|
224
|
+
"numMinted",
|
|
225
|
+
"lastSettlement",
|
|
226
|
+
"input",
|
|
227
|
+
"output",
|
|
228
|
+
"display",
|
|
229
|
+
"hooks",
|
|
230
|
+
"data",
|
|
231
|
+
"genesisTime",
|
|
232
|
+
"renaissanceTime"
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
this.tokenFactory = new base_default({
|
|
237
|
+
name: "tokenFactory",
|
|
238
|
+
uniqIndex: "address",
|
|
239
|
+
db: this.db,
|
|
240
|
+
schema: {
|
|
241
|
+
jsonFields: [
|
|
242
|
+
"curve",
|
|
243
|
+
"token",
|
|
244
|
+
"reserveToken",
|
|
245
|
+
"input",
|
|
246
|
+
"output",
|
|
247
|
+
"data"
|
|
248
|
+
],
|
|
249
|
+
numericFields: {
|
|
250
|
+
reserveBalance: "reserveBalanceNum",
|
|
251
|
+
currentSupply: "currentSupplyNum"
|
|
252
|
+
},
|
|
253
|
+
knownColumns: [
|
|
254
|
+
"address",
|
|
255
|
+
"owner",
|
|
256
|
+
"name",
|
|
257
|
+
"description",
|
|
258
|
+
"moniker",
|
|
259
|
+
"status",
|
|
260
|
+
"curve",
|
|
261
|
+
"tokenAddress",
|
|
262
|
+
"reserveAddress",
|
|
263
|
+
"reserveBalance",
|
|
264
|
+
"currentSupply",
|
|
265
|
+
"feeRate",
|
|
266
|
+
"token",
|
|
267
|
+
"reserveToken",
|
|
268
|
+
"input",
|
|
269
|
+
"output",
|
|
270
|
+
"data",
|
|
271
|
+
"genesisTime",
|
|
272
|
+
"renaissanceTime"
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
this.stake = new base_default({
|
|
277
|
+
name: "stake",
|
|
278
|
+
uniqIndex: "address",
|
|
279
|
+
db: this.db,
|
|
280
|
+
schema: {
|
|
281
|
+
jsonFields: [
|
|
282
|
+
"tokens",
|
|
283
|
+
"revokedTokens",
|
|
284
|
+
"assets",
|
|
285
|
+
"revokedAssets",
|
|
286
|
+
"slashers",
|
|
287
|
+
"data"
|
|
288
|
+
],
|
|
289
|
+
booleanFields: ["revocable"],
|
|
290
|
+
knownColumns: [
|
|
291
|
+
"address",
|
|
292
|
+
"sender",
|
|
293
|
+
"receiver",
|
|
294
|
+
"revocable",
|
|
295
|
+
"tokens",
|
|
296
|
+
"revokedTokens",
|
|
297
|
+
"assets",
|
|
298
|
+
"revokedAssets",
|
|
299
|
+
"slashers",
|
|
300
|
+
"nonce",
|
|
301
|
+
"revokeWaitingPeriod",
|
|
302
|
+
"message",
|
|
303
|
+
"data",
|
|
304
|
+
"genesisTime",
|
|
305
|
+
"renaissanceTime"
|
|
306
|
+
]
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
this.delegation = new base_default({
|
|
310
|
+
name: "delegation",
|
|
311
|
+
uniqIndex: "address",
|
|
312
|
+
db: this.db,
|
|
313
|
+
schema: {
|
|
314
|
+
jsonFields: [
|
|
315
|
+
"ops",
|
|
316
|
+
"context",
|
|
317
|
+
"data"
|
|
318
|
+
],
|
|
319
|
+
columnMapping: {
|
|
320
|
+
from: "from_",
|
|
321
|
+
to: "to_"
|
|
322
|
+
},
|
|
323
|
+
knownColumns: [
|
|
324
|
+
"address",
|
|
325
|
+
"from",
|
|
326
|
+
"to",
|
|
327
|
+
"ops",
|
|
328
|
+
"context",
|
|
329
|
+
"data",
|
|
330
|
+
"genesisTime",
|
|
331
|
+
"renaissanceTime"
|
|
332
|
+
]
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
this.rollup = new base_default({
|
|
336
|
+
name: "rollup",
|
|
337
|
+
uniqIndex: "address",
|
|
338
|
+
db: this.db,
|
|
339
|
+
schema: {
|
|
340
|
+
jsonFields: [
|
|
341
|
+
"seedValidators",
|
|
342
|
+
"validators",
|
|
343
|
+
"foreignToken",
|
|
344
|
+
"tokenInfo",
|
|
345
|
+
"migrateHistory",
|
|
346
|
+
"vaultHistory",
|
|
347
|
+
"data"
|
|
348
|
+
],
|
|
349
|
+
booleanFields: ["paused", "closed"],
|
|
350
|
+
knownColumns: [
|
|
351
|
+
"address",
|
|
352
|
+
"tokenAddress",
|
|
353
|
+
"vaultAddress",
|
|
354
|
+
"contractAddress",
|
|
355
|
+
"paused",
|
|
356
|
+
"closed",
|
|
357
|
+
"seedValidators",
|
|
358
|
+
"validators",
|
|
359
|
+
"blockHash",
|
|
360
|
+
"issuer",
|
|
361
|
+
"foreignToken",
|
|
362
|
+
"minStakeAmount",
|
|
363
|
+
"maxStakeAmount",
|
|
364
|
+
"minSignerCount",
|
|
365
|
+
"maxSignerCount",
|
|
366
|
+
"minBlockSize",
|
|
367
|
+
"maxBlockSize",
|
|
368
|
+
"minBlockInterval",
|
|
369
|
+
"leaveWaitingPeriod",
|
|
370
|
+
"publishWaitingPeriod",
|
|
371
|
+
"publishSlashRate",
|
|
372
|
+
"tokenInfo",
|
|
373
|
+
"depositFeeRate",
|
|
374
|
+
"withdrawFeeRate",
|
|
375
|
+
"proposerFeeShare",
|
|
376
|
+
"publisherFeeShare",
|
|
377
|
+
"minDepositAmount",
|
|
378
|
+
"minWithdrawAmount",
|
|
379
|
+
"totalDepositAmount",
|
|
380
|
+
"totalWithdrawAmount",
|
|
381
|
+
"migrateHistory",
|
|
382
|
+
"vaultHistory",
|
|
383
|
+
"data",
|
|
384
|
+
"genesisTime",
|
|
385
|
+
"renaissanceTime"
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
this.rollupBlock = new base_default({
|
|
390
|
+
name: "rollupBlock",
|
|
391
|
+
uniqIndex: "hash",
|
|
392
|
+
db: this.db,
|
|
393
|
+
schema: {
|
|
394
|
+
jsonFields: [
|
|
395
|
+
"signatures",
|
|
396
|
+
"txs",
|
|
397
|
+
"validators",
|
|
398
|
+
"tokenInfo",
|
|
399
|
+
"data"
|
|
400
|
+
],
|
|
401
|
+
booleanFields: ["governance"],
|
|
402
|
+
knownColumns: [
|
|
403
|
+
"hash",
|
|
404
|
+
"rollup",
|
|
405
|
+
"height",
|
|
406
|
+
"merkleRoot",
|
|
407
|
+
"previousHash",
|
|
408
|
+
"txsHash",
|
|
409
|
+
"txs",
|
|
410
|
+
"proposer",
|
|
411
|
+
"signatures",
|
|
412
|
+
"rewardAmount",
|
|
413
|
+
"mintedAmount",
|
|
414
|
+
"burnedAmount",
|
|
415
|
+
"minReward",
|
|
416
|
+
"validators",
|
|
417
|
+
"tokenInfo",
|
|
418
|
+
"governance",
|
|
419
|
+
"data",
|
|
420
|
+
"genesisTime",
|
|
421
|
+
"renaissanceTime"
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
this.rollupValidator = new base_default({
|
|
426
|
+
name: "rollupValidator",
|
|
427
|
+
uniqIndex: "address",
|
|
428
|
+
db: this.db,
|
|
429
|
+
schema: {
|
|
430
|
+
jsonFields: ["data"],
|
|
431
|
+
knownColumns: [
|
|
432
|
+
"address",
|
|
433
|
+
"rollup",
|
|
434
|
+
"pk",
|
|
435
|
+
"moniker",
|
|
436
|
+
"endpoint",
|
|
437
|
+
"joinTime",
|
|
438
|
+
"leaveTime",
|
|
439
|
+
"genesisTime",
|
|
440
|
+
"renaissanceTime",
|
|
441
|
+
"totalStake",
|
|
442
|
+
"availableStake",
|
|
443
|
+
"revokedStake",
|
|
444
|
+
"totalGain",
|
|
445
|
+
"proposedBlockCount",
|
|
446
|
+
"verifiedBlockCount",
|
|
447
|
+
"latestBlockHeight",
|
|
448
|
+
"latestBlockHash",
|
|
449
|
+
"data"
|
|
450
|
+
]
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
this.tokenDistribution = new base_default({
|
|
454
|
+
name: "tokenDistribution",
|
|
455
|
+
uniqIndex: "tokenAddress",
|
|
456
|
+
db: this.db,
|
|
457
|
+
schema: {
|
|
458
|
+
jsonFields: ["distribution", "data"],
|
|
459
|
+
knownColumns: [
|
|
460
|
+
"tokenAddress",
|
|
461
|
+
"holders",
|
|
462
|
+
"distribution",
|
|
463
|
+
"stake",
|
|
464
|
+
"gasStake",
|
|
465
|
+
"revokedStake",
|
|
466
|
+
"gas",
|
|
467
|
+
"fee",
|
|
468
|
+
"slashedVault",
|
|
469
|
+
"account",
|
|
470
|
+
"txTime",
|
|
471
|
+
"genesisTime",
|
|
472
|
+
"renaissanceTime",
|
|
473
|
+
"data"
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
this.balance = new base_default({
|
|
478
|
+
name: "balance",
|
|
479
|
+
uniqIndex: ["address", "tokenAddress"],
|
|
480
|
+
db: this.db,
|
|
481
|
+
schema: {
|
|
482
|
+
jsonFields: ["data"],
|
|
483
|
+
numericFields: { balance: "balanceNum" },
|
|
484
|
+
knownColumns: [
|
|
485
|
+
"address",
|
|
486
|
+
"tokenAddress",
|
|
487
|
+
"balance",
|
|
488
|
+
"data"
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
this.attachReadyListeners();
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Async initialization - runs migrations
|
|
496
|
+
* Call this after constructor to ensure database schema is ready
|
|
497
|
+
*/
|
|
498
|
+
async initialize() {
|
|
499
|
+
if (this.initialized) return;
|
|
500
|
+
await runMigrations(this.db);
|
|
501
|
+
this.initialized = true;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Execute multiple operations within a database transaction
|
|
505
|
+
*
|
|
506
|
+
* @param fn - Function receiving Kysely transaction object
|
|
507
|
+
* @returns Result of the transaction function
|
|
508
|
+
*/
|
|
509
|
+
async runAsLambda(fn) {
|
|
510
|
+
return this.db.transaction().execute(fn);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Reset all tables (for testing)
|
|
514
|
+
*/
|
|
515
|
+
async reset() {
|
|
516
|
+
for (const table of [
|
|
517
|
+
"tx",
|
|
518
|
+
"account",
|
|
519
|
+
"asset",
|
|
520
|
+
"token",
|
|
521
|
+
"factory",
|
|
522
|
+
"tokenFactory",
|
|
523
|
+
"stake",
|
|
524
|
+
"delegation",
|
|
525
|
+
"rollup",
|
|
526
|
+
"rollupBlock",
|
|
527
|
+
"rollupValidator",
|
|
528
|
+
"tokenDistribution",
|
|
529
|
+
"balance"
|
|
530
|
+
]) {
|
|
531
|
+
const tableInstance = this[table];
|
|
532
|
+
if (tableInstance?.reset) await tableInstance.reset();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Close database connection
|
|
537
|
+
*/
|
|
538
|
+
async close() {
|
|
539
|
+
await this.db.destroy();
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Get the underlying Kysely instance (for advanced operations)
|
|
543
|
+
*/
|
|
544
|
+
getKysely() {
|
|
545
|
+
return this.db;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
var db_default = SqliteIndexDB;
|
|
549
|
+
|
|
550
|
+
//#endregion
|
|
551
|
+
export { db_default as default };
|
package/esm/index.d.mts
ADDED