@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.
Files changed (42) hide show
  1. package/README.md +84 -0
  2. package/esm/_virtual/rolldown_runtime.mjs +21 -0
  3. package/esm/db/base.d.mts +76 -0
  4. package/esm/db/base.mjs +666 -0
  5. package/esm/db/index.d.mts +80 -0
  6. package/esm/db/index.mjs +551 -0
  7. package/esm/index.d.mts +3 -0
  8. package/esm/index.mjs +8 -0
  9. package/esm/interfaces.d.mts +328 -0
  10. package/esm/interfaces.mjs +1 -0
  11. package/esm/kysely.d.mts +43 -0
  12. package/esm/kysely.mjs +62 -0
  13. package/esm/migrations/001-genesis.d.mts +14 -0
  14. package/esm/migrations/001-genesis.mjs +107 -0
  15. package/esm/migrations/index.d.mts +16 -0
  16. package/esm/migrations/index.mjs +44 -0
  17. package/esm/package.mjs +70 -0
  18. package/esm/table/base.d.mts +107 -0
  19. package/esm/table/base.mjs +262 -0
  20. package/esm/table/transaction.d.mts +18 -0
  21. package/esm/table/transaction.mjs +22 -0
  22. package/lib/_virtual/rolldown_runtime.cjs +43 -0
  23. package/lib/db/base.cjs +670 -0
  24. package/lib/db/base.d.cts +76 -0
  25. package/lib/db/index.cjs +552 -0
  26. package/lib/db/index.d.cts +80 -0
  27. package/lib/index.cjs +10 -0
  28. package/lib/index.d.cts +3 -0
  29. package/lib/interfaces.cjs +0 -0
  30. package/lib/interfaces.d.cts +328 -0
  31. package/lib/kysely.cjs +63 -0
  32. package/lib/kysely.d.cts +43 -0
  33. package/lib/migrations/001-genesis.cjs +114 -0
  34. package/lib/migrations/001-genesis.d.cts +14 -0
  35. package/lib/migrations/index.cjs +46 -0
  36. package/lib/migrations/index.d.cts +16 -0
  37. package/lib/package.cjs +76 -0
  38. package/lib/table/base.cjs +265 -0
  39. package/lib/table/base.d.cts +107 -0
  40. package/lib/table/transaction.cjs +24 -0
  41. package/lib/table/transaction.d.cts +18 -0
  42. package/package.json +75 -0
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # [**@ocap/indexdb-sqlite**](https://github.com/arcblock/blockchain)
2
+
3
+ > OCAP indexdb adapter that uses SQLite as backend via [Kysely](https://kysely.dev/)
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @ocap/indexdb-sqlite
9
+ // or
10
+ bun install @ocap/indexdb-sqlite
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### In-Memory Mode
16
+
17
+ For testing or ephemeral data:
18
+
19
+ ```js
20
+ const SqliteIndexDB = require('@ocap/indexdb-sqlite').default;
21
+
22
+ const indexdb = new SqliteIndexDB({ filename: ':memory:' });
23
+ await indexdb.initialize();
24
+
25
+ // Use indexdb...
26
+ await indexdb.tx.insert({ hash: 'abc123', sender: 'z1...' });
27
+
28
+ // Close when done
29
+ await indexdb.close();
30
+ ```
31
+
32
+ ### File Mode
33
+
34
+ For persistent storage:
35
+
36
+ ```js
37
+ const SqliteIndexDB = require('@ocap/indexdb-sqlite').default;
38
+
39
+ const indexdb = new SqliteIndexDB({ filename: '/path/to/indexdb.sqlite' });
40
+ await indexdb.initialize();
41
+
42
+ // Data persists across restarts
43
+ ```
44
+
45
+ ## Features
46
+
47
+ - WAL mode enabled by default for better concurrent read performance
48
+ - Automatic migrations on initialization
49
+ - Generated columns for big number sorting (balances up to 24+ digits)
50
+ - Full-featured list methods with filtering, pagination, and sorting
51
+ - All 12 index tables: tx, account, asset, token, factory, stake, delegation, rollup, etc.
52
+
53
+ ## Big Number Sorting
54
+
55
+ SQLite cannot natively sort numeric strings as numbers. This adapter uses generated columns to handle large balance values (commonly found in blockchain applications):
56
+
57
+ ```sql
58
+ -- Accounts with balances like "99999999999999999999" sort correctly
59
+ SELECT * FROM account ORDER BY balance_sort DESC;
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### Constructor Options
65
+
66
+ ```typescript
67
+ interface SqliteIndexDBOptions {
68
+ filename: string; // ':memory:' or file path
69
+ }
70
+ ```
71
+
72
+ ### Methods
73
+
74
+ - `initialize()` - Run migrations and prepare database
75
+ - `close()` - Close database connection
76
+ - `listTransactions(params)` - Query transactions with filters
77
+ - `listTopAccounts(params)` - Get accounts sorted by balance
78
+ - `listAssets(params)` - Query assets by owner/factory
79
+ - `listTokens(params)` - List all tokens
80
+ - `listFactories(params)` - List asset factories
81
+ - `listStakes(params)` - Query stake records
82
+ - `listDelegations(params)` - Query delegations
83
+ - `listRollups(params)` - List rollup configurations
84
+ - `getRelatedAddresses(address)` - Find related addresses
@@ -0,0 +1,21 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __defProp = Object.defineProperty;
5
+ var __exportAll = (all, symbols) => {
6
+ let target = {};
7
+ for (var name in all) {
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ }
13
+ if (symbols) {
14
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ }
16
+ return target;
17
+ };
18
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
19
+
20
+ //#endregion
21
+ export { __exportAll, __require };
@@ -0,0 +1,76 @@
1
+ import { Database } from "../interfaces.mjs";
2
+ import { Kysely } from "kysely";
3
+ import { BaseIndexDB } from "@ocap/indexdb";
4
+ import { IIndexDB, IIndexTable, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, IndexTableTypeMap, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions } from "@ocap/types";
5
+
6
+ //#region src/db/base.d.ts
7
+
8
+ /**
9
+ * Base SQLite IndexDB implementation
10
+ * Contains all the list methods with SQL-based filtering
11
+ */
12
+ declare class SqliteBaseIndexDB extends BaseIndexDB implements IIndexDB {
13
+ protected db: Kysely<Database>;
14
+ tx: IIndexTable<IndexTableTypeMap['tx']>;
15
+ account: IIndexTable<IndexTableTypeMap['account']>;
16
+ asset: IIndexTable<IndexTableTypeMap['asset']>;
17
+ token: IIndexTable<IndexTableTypeMap['token']>;
18
+ factory: IIndexTable<IndexTableTypeMap['factory']>;
19
+ stake: IIndexTable<IndexTableTypeMap['stake']>;
20
+ delegation: IIndexTable<IndexTableTypeMap['delegation']>;
21
+ rollup: IIndexTable<IndexTableTypeMap['rollup']>;
22
+ rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
23
+ rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
24
+ tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
25
+ tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
26
+ /**
27
+ * List transactions with filtering and pagination
28
+ */
29
+ listTransactions(params?: Partial<TRequestListTransactions>): Promise<IListTransactionsResult>;
30
+ /**
31
+ * Get related addresses for account migration tracking
32
+ */
33
+ getRelatedAddresses(address: string): Promise<string[]>;
34
+ /**
35
+ * List assets with filtering and pagination
36
+ */
37
+ listAssets(params?: Partial<TRequestListAssets>): Promise<IListAssetsResult>;
38
+ /**
39
+ * List top accounts by token balance
40
+ */
41
+ listTopAccounts(params?: Partial<TRequestListTopAccounts>): Promise<IListAccountsResult>;
42
+ /**
43
+ * List tokens with filtering and pagination
44
+ */
45
+ listTokens(params?: Partial<TRequestListTokens>): Promise<IListTokensResult>;
46
+ /**
47
+ * List token factories (bonding curve)
48
+ */
49
+ listTokenFactories(params?: Partial<TRequestListTokenFactories>): Promise<IListTokenFactoriesResult>;
50
+ /**
51
+ * List asset factories
52
+ */
53
+ listFactories(params?: Partial<TRequestListFactories>): Promise<IListFactoriesResult>;
54
+ /**
55
+ * List stakes
56
+ */
57
+ listStakes(params?: Partial<TRequestListStakes>): Promise<IListStakesResult>;
58
+ /**
59
+ * List rollups
60
+ */
61
+ listRollups(params?: Partial<TRequestListRollups>): Promise<IListRollupsResult>;
62
+ /**
63
+ * List rollup blocks
64
+ */
65
+ listRollupBlocks(params?: Partial<TRequestListRollupBlocks>): Promise<IListRollupBlocksResult>;
66
+ /**
67
+ * List rollup validators
68
+ */
69
+ listRollupValidators(params?: Partial<TRequestListRollupValidators>): Promise<IListRollupValidatorsResult>;
70
+ /**
71
+ * List delegations
72
+ */
73
+ listDelegations(params?: Partial<TRequestListDelegations>): Promise<IListDelegationsResult>;
74
+ }
75
+ //#endregion
76
+ export { SqliteBaseIndexDB as default };