@ocap/indexdb 1.28.8 → 1.29.0

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 CHANGED
@@ -15,7 +15,7 @@ bun install @ocap/statedb-memory
15
15
  Then:
16
16
 
17
17
  ```javascript
18
- const MemoryIndexDB = require('@ocap/indexdb-memory');
18
+ const MemoryIndexDB = require('@ocap/indexdb-memory').default;
19
19
 
20
20
  const indexdb = new MemoryIndexDB();
21
21
 
package/esm/db.d.mts ADDED
@@ -0,0 +1,40 @@
1
+ import { Ready } from "@ocap/util/lib/ready";
2
+ import { IIndexDB, IIndexTable, IListAccountsResult, IListAssetsResult, IListDelegationsResult, IListFactoriesResult, IListRollupBlocksResult, IListRollupValidatorsResult, IListRollupsResult, IListStakesResult, IListTokenFactoriesResult, IListTokensResult, IListTransactionsResult, IndexTableTypeMap, Promisable, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions } from "@ocap/types";
3
+
4
+ //#region src/db.d.ts
5
+ declare class BaseIndexDB extends Ready implements IIndexDB {
6
+ readyMarks: Record<string, boolean>;
7
+ readyListenersAttached: boolean;
8
+ name: string;
9
+ version: string;
10
+ tx: IIndexTable<IndexTableTypeMap['tx']>;
11
+ account: IIndexTable<IndexTableTypeMap['account']>;
12
+ asset: IIndexTable<IndexTableTypeMap['asset']>;
13
+ token: IIndexTable<IndexTableTypeMap['token']>;
14
+ factory: IIndexTable<IndexTableTypeMap['factory']>;
15
+ stake: IIndexTable<IndexTableTypeMap['stake']>;
16
+ delegation: IIndexTable<IndexTableTypeMap['delegation']>;
17
+ rollup: IIndexTable<IndexTableTypeMap['rollup']>;
18
+ rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
19
+ rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
20
+ tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
21
+ tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
22
+ [key: string]: unknown;
23
+ constructor();
24
+ attachReadyListeners(): void;
25
+ listTransactions(_params?: Partial<TRequestListTransactions>): Promisable<IListTransactionsResult>;
26
+ listAssets(_params?: Partial<TRequestListAssets>): Promisable<IListAssetsResult>;
27
+ listTopAccounts(_params?: Partial<TRequestListTopAccounts>): Promisable<IListAccountsResult>;
28
+ listTokens(_params?: Partial<TRequestListTokens>): Promisable<IListTokensResult>;
29
+ listFactories(_params?: Partial<TRequestListFactories>): Promisable<IListFactoriesResult>;
30
+ listStakes(_params?: Partial<TRequestListStakes>): Promisable<IListStakesResult>;
31
+ listDelegations(_params?: Partial<TRequestListDelegations>): Promisable<IListDelegationsResult>;
32
+ listRollups(_params?: Partial<TRequestListRollups>): Promisable<IListRollupsResult>;
33
+ listRollupBlocks(_params?: Partial<TRequestListRollupBlocks>): Promisable<IListRollupBlocksResult>;
34
+ listRollupValidators(_params?: Partial<TRequestListRollupValidators>): Promisable<IListRollupValidatorsResult>;
35
+ listTokenFactories(_params?: Partial<TRequestListTokenFactories>): Promisable<IListTokenFactoriesResult>;
36
+ getRelatedAddresses(_address: string): Promisable<string[]>;
37
+ listBlocks(): unknown[];
38
+ }
39
+ //#endregion
40
+ export { BaseIndexDB as default };
package/esm/db.mjs ADDED
@@ -0,0 +1,62 @@
1
+ import { indexes } from "@ocap/state";
2
+ import { Ready } from "@ocap/util/lib/ready";
3
+
4
+ //#region src/db.ts
5
+ var BaseIndexDB = class extends Ready {
6
+ constructor() {
7
+ super();
8
+ this.readyMarks = Object.fromEntries(indexes.map((x) => [x, false]));
9
+ this.readyListenersAttached = false;
10
+ }
11
+ attachReadyListeners() {
12
+ if (this.readyListenersAttached) return;
13
+ for (const index of indexes) {
14
+ if (typeof this[index] === "undefined") throw new Error(`Missing index ${index} in indexdb adapter: ${this.name}`);
15
+ this[index].onReady(() => this.markReady(index));
16
+ }
17
+ this.readyListenersAttached = true;
18
+ }
19
+ listTransactions(_params) {
20
+ throw new Error("listTransactions should be implemented in adapter");
21
+ }
22
+ listAssets(_params) {
23
+ throw new Error("listAssets should be implemented in adapter");
24
+ }
25
+ listTopAccounts(_params) {
26
+ throw new Error("listTopAccounts should be implemented in adapter");
27
+ }
28
+ listTokens(_params) {
29
+ throw new Error("listTokens should be implemented in adapter");
30
+ }
31
+ listFactories(_params) {
32
+ throw new Error("listFactories should be implemented in adapter");
33
+ }
34
+ listStakes(_params) {
35
+ throw new Error("listStakes should be implemented in adapter");
36
+ }
37
+ listDelegations(_params) {
38
+ throw new Error("listDelegations should be implemented in adapter");
39
+ }
40
+ listRollups(_params) {
41
+ throw new Error("listRollups should be implemented in adapter");
42
+ }
43
+ listRollupBlocks(_params) {
44
+ throw new Error("listRollupBlocks should be implemented in adapter");
45
+ }
46
+ listRollupValidators(_params) {
47
+ throw new Error("listRollupValidators should be implemented in adapter");
48
+ }
49
+ listTokenFactories(_params) {
50
+ throw new Error("listTokenFactories should be implemented in adapter");
51
+ }
52
+ getRelatedAddresses(_address) {
53
+ return [];
54
+ }
55
+ listBlocks() {
56
+ return [];
57
+ }
58
+ };
59
+ var db_default = BaseIndexDB;
60
+
61
+ //#endregion
62
+ export { db_default as default };
@@ -0,0 +1,58 @@
1
+ import { Ready } from "@ocap/util/lib/ready";
2
+ import { IIndexTable, IndexTableHookFn, Promisable } from "@ocap/types";
3
+
4
+ //#region src/index.d.ts
5
+ type UniqueIndex = string | string[];
6
+ /**
7
+ * Base class for index tables
8
+ * Provides hook support (pre/post) and common operations
9
+ * Subclasses must implement _insert, _get, _update, _reset, count
10
+ */
11
+ declare class BaseIndex<T = unknown> extends Ready implements IIndexTable<T> {
12
+ readonly name: string;
13
+ readonly primaryKey: string;
14
+ readonly uniqIndex: UniqueIndex;
15
+ ready: boolean;
16
+ readyCallbacks: Array<() => void>;
17
+ pre: (hookName: string, fn: IndexTableHookFn) => void;
18
+ post: (hookName: string, fn: IndexTableHookFn) => void;
19
+ insert: (doc: T | Record<string, unknown>) => Promise<T>;
20
+ get: (key: string | Record<string, unknown>) => Promise<T | null>;
21
+ update: (key: string | Record<string, unknown>, updates: Partial<T>) => Promise<T>;
22
+ reset: () => Promise<void>;
23
+ constructor(name?: string, uniqIndex?: UniqueIndex);
24
+ /**
25
+ * Count documents matching query
26
+ * Must be implemented by subclasses
27
+ */
28
+ count(_query?: unknown): Promisable<number>;
29
+ /**
30
+ * Internal insert implementation
31
+ * Called by the public `insert` method after pre-hooks
32
+ */
33
+ _insert(_doc: T | Record<string, unknown>): Promisable<T>;
34
+ /**
35
+ * Internal get implementation
36
+ * Called by the public `get` method after pre-hooks
37
+ */
38
+ _get(_key: string | Record<string, unknown>): Promisable<T | null>;
39
+ /**
40
+ * Internal update implementation
41
+ * Called by the public `update` method after pre-hooks
42
+ */
43
+ _update(_key: string | Record<string, unknown>, _updates: Partial<T>): Promisable<T>;
44
+ /**
45
+ * Internal reset implementation
46
+ * Called by the public `reset` method after pre-hooks
47
+ */
48
+ _reset(): Promisable<void>;
49
+ /**
50
+ * Generate primary key from document or key object
51
+ * For composite keys, generates MD5 hash of joined values
52
+ * @param doc - String key or document/key object
53
+ * @returns Primary key string
54
+ */
55
+ generatePrimaryKey(doc: string | Record<string, unknown>): string;
56
+ }
57
+ //#endregion
58
+ export { BaseIndex as default };
package/esm/index.mjs ADDED
@@ -0,0 +1,91 @@
1
+ import { Ready } from "@ocap/util/lib/ready";
2
+ import crypto from "node:crypto";
3
+ import Kareem from "kareem";
4
+ import omit from "lodash/omit.js";
5
+
6
+ //#region src/index.ts
7
+ /**
8
+ * Base class for index tables
9
+ * Provides hook support (pre/post) and common operations
10
+ * Subclasses must implement _insert, _get, _update, _reset, count
11
+ */
12
+ var BaseIndex = class extends Ready {
13
+ constructor(name, uniqIndex) {
14
+ super();
15
+ this.name = name || "";
16
+ this.ready = false;
17
+ this.readyCallbacks = [];
18
+ this.uniqIndex = uniqIndex || "id";
19
+ this.primaryKey = typeof uniqIndex === "string" ? uniqIndex : "id";
20
+ const hooks = new Kareem();
21
+ Object.defineProperty(this, "pre", { value: (hookName, fn) => hooks.pre(hookName, fn) });
22
+ Object.defineProperty(this, "post", { value: (hookName, fn) => hooks.post(hookName, fn) });
23
+ [
24
+ "insert",
25
+ "get",
26
+ "update",
27
+ "reset"
28
+ ].forEach((opName) => {
29
+ Object.defineProperty(this, opName, { value: async (...args) => {
30
+ hooks.execPreSync(opName, args);
31
+ const result = await this[`_${opName}`](...args);
32
+ hooks.execPostSync(opName, result);
33
+ if (["insert", "update"].includes(opName)) this.emit(opName, omit(result, "$loki"));
34
+ return result;
35
+ } });
36
+ });
37
+ }
38
+ /**
39
+ * Count documents matching query
40
+ * Must be implemented by subclasses
41
+ */
42
+ count(_query) {
43
+ throw new Error("`count` must be implemented in sub indexdb");
44
+ }
45
+ /**
46
+ * Internal insert implementation
47
+ * Called by the public `insert` method after pre-hooks
48
+ */
49
+ _insert(_doc) {
50
+ throw new Error("`_insert` must be implemented in sub indexdb");
51
+ }
52
+ /**
53
+ * Internal get implementation
54
+ * Called by the public `get` method after pre-hooks
55
+ */
56
+ _get(_key) {
57
+ throw new Error("`_get` must be implemented in sub indexdb");
58
+ }
59
+ /**
60
+ * Internal update implementation
61
+ * Called by the public `update` method after pre-hooks
62
+ */
63
+ _update(_key, _updates) {
64
+ throw new Error("`_update` must be implemented in sub indexdb");
65
+ }
66
+ /**
67
+ * Internal reset implementation
68
+ * Called by the public `reset` method after pre-hooks
69
+ */
70
+ _reset() {
71
+ throw new Error("`_reset` must be implemented in sub indexdb");
72
+ }
73
+ /**
74
+ * Generate primary key from document or key object
75
+ * For composite keys, generates MD5 hash of joined values
76
+ * @param doc - String key or document/key object
77
+ * @returns Primary key string
78
+ */
79
+ generatePrimaryKey(doc) {
80
+ if (typeof doc === "string") return doc;
81
+ if (Array.isArray(this.uniqIndex)) {
82
+ const key = this.uniqIndex.map((id) => doc[id]).map((item) => typeof item === "object" ? JSON.stringify(item) : item).join("-");
83
+ return crypto.createHash("md5").update(key).digest("hex");
84
+ }
85
+ return doc[this.uniqIndex];
86
+ }
87
+ };
88
+ var src_default = BaseIndex;
89
+
90
+ //#endregion
91
+ export { src_default as default };
package/esm/main.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ import BaseIndexDB from "./db.mjs";
2
+ import BaseIndex from "./index.mjs";
3
+ import { DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
4
+ export { BaseIndex, BaseIndexDB, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
package/esm/main.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import db_default from "./db.mjs";
2
+ import src_default from "./index.mjs";
3
+ import { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
4
+
5
+ export { src_default as BaseIndex, db_default as BaseIndexDB, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
package/esm/util.d.mts ADDED
@@ -0,0 +1,374 @@
1
+ import { FinalizedContext, IAccountState, IAssetFactoryState, IAssetState, IDelegateState, IIndexTable, IRollupBlock, IRollupState, IStakeState, ITokenFactoryState, ITokenState, TIndexedAccountState, TIndexedAssetState, TIndexedDelegationState, TIndexedTokenState, TPageInfo, TTokenDistribution, TTokenMeta } from "@ocap/types";
2
+
3
+ //#region src/util.d.ts
4
+
5
+ /**
6
+ * Token state with metadata for formatting
7
+ * Note: foreignToken type from ITokenState (IForeignToken) differs from TForeignToken,
8
+ * we use a flexible type here to accommodate both
9
+ */
10
+ interface TokenStateInfo {
11
+ address: string;
12
+ decimal?: number;
13
+ unit?: string;
14
+ symbol?: string;
15
+ icon?: string;
16
+ /** Foreign token info - may be IForeignToken from state or TForeignToken when indexed */
17
+ foreignToken?: {
18
+ type?: string;
19
+ contractAddress?: string;
20
+ chainType?: string;
21
+ chainName?: string;
22
+ chainId?: number;
23
+ } | null;
24
+ }
25
+ /** Token with address and optional balance */
26
+ interface TokenWithBalance {
27
+ address: string;
28
+ balance?: string;
29
+ value?: string;
30
+ [key: string]: unknown;
31
+ }
32
+ /** Minimal IndexDB interface for indexed transaction creation */
33
+ interface IndexDBForTx {
34
+ delegation?: IIndexTable<{
35
+ to: string;
36
+ address: string;
37
+ }>;
38
+ token?: IIndexTable<TokenStateInfo>;
39
+ }
40
+ /** Inner transaction JSON structure */
41
+ interface ItxJson {
42
+ type_url?: string;
43
+ value?: string | number;
44
+ to?: string;
45
+ token?: string;
46
+ assets?: string[];
47
+ tokens?: Array<{
48
+ address: string;
49
+ value?: string;
50
+ }>;
51
+ inputs?: Array<{
52
+ assets?: string[];
53
+ tokens?: Array<{
54
+ address: string;
55
+ value?: string;
56
+ }>;
57
+ }>;
58
+ outputs?: Array<{
59
+ assets?: string[];
60
+ tokens?: Array<{
61
+ address: string;
62
+ value?: string;
63
+ }>;
64
+ }>;
65
+ sender?: {
66
+ value?: string;
67
+ assets?: string[];
68
+ tokens?: Array<{
69
+ address: string;
70
+ value?: string;
71
+ }>;
72
+ };
73
+ receiver?: {
74
+ value?: string;
75
+ assets?: string[];
76
+ tokens?: Array<{
77
+ address: string;
78
+ value?: string;
79
+ }>;
80
+ };
81
+ address?: string;
82
+ factory?: string;
83
+ data?: {
84
+ type_url: string;
85
+ value: string;
86
+ };
87
+ [key: string]: unknown;
88
+ }
89
+ /** Decoded transaction structure */
90
+ interface DecodedTx {
91
+ from: string;
92
+ itxJson: ItxJson;
93
+ [key: string]: unknown;
94
+ }
95
+ /** Transaction data for indexing */
96
+ interface TxData {
97
+ hash?: string;
98
+ type?: string;
99
+ code?: string;
100
+ sender?: string;
101
+ receiver?: string;
102
+ time?: string;
103
+ valid?: boolean;
104
+ tx: DecodedTx;
105
+ receipts?: Array<{
106
+ changes: Array<{
107
+ target: string;
108
+ value: string;
109
+ }>;
110
+ }>;
111
+ accounts?: string[];
112
+ assets?: string[];
113
+ tokens?: string[];
114
+ factories?: string[];
115
+ stakes?: string[];
116
+ rollups?: string[];
117
+ delegations?: string[];
118
+ tokenFactories?: string[];
119
+ tokenSymbols?: Array<Partial<TTokenMeta>>;
120
+ [key: string]: unknown;
121
+ }
122
+ /** Context for creating indexed delegation */
123
+ interface DelegationContext {
124
+ senderState?: IAccountState;
125
+ receiverState?: IAccountState;
126
+ tx?: {
127
+ from: string;
128
+ };
129
+ itx?: {
130
+ to: string;
131
+ };
132
+ }
133
+ /** Context for creating indexed factory */
134
+ interface FactoryContext {
135
+ factoryTokens?: Array<{
136
+ address: string;
137
+ value: string;
138
+ }>;
139
+ tokenStates?: TokenStateInfo[];
140
+ }
141
+ /** Context for creating indexed token factory */
142
+ interface TokenFactoryContext {
143
+ itx?: {
144
+ token?: TokenStateInfo;
145
+ };
146
+ config?: {
147
+ token?: TokenStateInfo;
148
+ };
149
+ }
150
+ /** Context for creating indexed rollup */
151
+ interface RollupContext {
152
+ tokenStates?: TokenStateInfo[];
153
+ }
154
+ /** Context for creating indexed rollup block */
155
+ interface RollupBlockContext {
156
+ rollupState?: {
157
+ tokenAddress: string;
158
+ };
159
+ tokenStates?: TokenStateInfo[];
160
+ }
161
+ /**
162
+ * Format token with metadata from token states
163
+ * @param token - Token with address
164
+ * @param tokenStates - Array of token states for metadata lookup
165
+ * @param rest - Additional args for debug logging
166
+ */
167
+ declare const formatTokenMeta: (token: TokenWithBalance, tokenStates?: TokenStateInfo[] | null, ...rest: unknown[]) => TokenWithBalance;
168
+ /**
169
+ * Create indexed account from account state
170
+ */
171
+ declare const createIndexedAccount: (x: IAccountState & {
172
+ balance?: string;
173
+ migratedTo?: string[];
174
+ migratedFrom?: string[];
175
+ numAssets?: number;
176
+ numTxs?: number;
177
+ }, getTokenFn: (address: string) => Promise<TokenStateInfo | null>) => Promise<Omit<TIndexedAccountState, "balance" | "totalReceivedStakes" | "totalStakes" | "totalUnstakes" | "nonce" | "numAssets" | "numTxs"> & {
178
+ balance: string;
179
+ nonce: number | string;
180
+ numAssets: number | string;
181
+ numTxs: number | string;
182
+ }>;
183
+ /**
184
+ * Create indexed asset from asset state
185
+ * Note: display/endpoint/data types from IAssetState may differ from TIndexedAssetState,
186
+ * they are passed through without transformation
187
+ */
188
+ declare const createIndexedAsset: (x: IAssetState) => Omit<TIndexedAssetState, "display" | "endpoint" | "data"> & {
189
+ data?: IAssetState["data"];
190
+ display?: IAssetState["display"];
191
+ endpoint?: IAssetState["endpoint"];
192
+ };
193
+ /**
194
+ * Create indexed delegation from delegation state
195
+ */
196
+ declare const createIndexedDelegation: (x: IDelegateState, ctx: DelegationContext) => Partial<TIndexedDelegationState> & {
197
+ ops: unknown[];
198
+ };
199
+ /**
200
+ * Create indexed token from token state
201
+ * Note: foreignToken/metadata/data types from ITokenState may differ from TIndexedTokenState,
202
+ * they are passed through without transformation
203
+ */
204
+ declare const createIndexedToken: (x: ITokenState) => Omit<TIndexedTokenState, "foreignToken" | "metadata" | "data"> & {
205
+ foreignToken?: ITokenState["foreignToken"];
206
+ metadata?: ITokenState["metadata"];
207
+ data?: ITokenState["data"];
208
+ };
209
+ /**
210
+ * Create indexed token factory from token factory state
211
+ * Note: token/reserveToken may not have all TIndexedTokenInput fields filled,
212
+ * they are populated with available metadata from context
213
+ */
214
+ declare const createIndexedTokenFactory: (tokenFactory: ITokenFactoryState & {
215
+ tokenAddress: string;
216
+ reserveAddress: string;
217
+ }, context: TokenFactoryContext) => Record<string, unknown> & {
218
+ token: TokenWithBalance;
219
+ reserveToken: TokenWithBalance;
220
+ };
221
+ /**
222
+ * Create indexed factory from asset factory state
223
+ * Note: tokens array may not have all TTokenMeta fields filled,
224
+ * they are populated with available metadata from context
225
+ */
226
+ declare const createIndexedFactory: (factory: IAssetFactoryState & {
227
+ input?: {
228
+ tokens?: TokenWithBalance[];
229
+ };
230
+ }, context: FactoryContext) => Record<string, unknown> & {
231
+ tokens: TokenWithBalance[];
232
+ };
233
+ /**
234
+ * Create indexed transaction from transaction context
235
+ * These fields are used internally to filter transactions by some entity
236
+ */
237
+ declare const createIndexedTransaction: (tx: TxData, ctx: FinalizedContext, indexdb: IndexDBForTx) => Promise<TxData>;
238
+ /**
239
+ * Create indexed stake from stake state
240
+ * Note: tokens/revokedTokens arrays may not have all TTokenMeta fields filled,
241
+ * they are populated with available metadata from context
242
+ */
243
+ declare const createIndexedStake: (x: IStakeState, ctx: {
244
+ tokenStates?: TokenStateInfo[];
245
+ }, indexdb: {
246
+ token?: IIndexTable<TokenStateInfo>;
247
+ }) => Promise<Record<string, unknown> & {
248
+ tokens: TokenWithBalance[];
249
+ revokedTokens: TokenWithBalance[];
250
+ }>;
251
+ /**
252
+ * Create indexed rollup from rollup state
253
+ * Note: foreignToken from TokenStateInfo is passed through without transformation
254
+ */
255
+ declare const createIndexedRollup: (x: IRollupState & {
256
+ tokenAddress: string;
257
+ }, ctx: RollupContext) => Record<string, unknown> & {
258
+ tokenInfo?: TokenWithBalance;
259
+ foreignToken?: TokenStateInfo["foreignToken"];
260
+ };
261
+ /**
262
+ * Create indexed rollup block from rollup block state
263
+ * Note: tokenInfo may not have all TIndexedTokenInput fields filled,
264
+ * they are populated with available metadata from context
265
+ */
266
+ declare const createIndexedRollupBlock: (x: IRollupBlock & {
267
+ signaturesList?: Array<{
268
+ signer: string;
269
+ }>;
270
+ }, ctx: RollupBlockContext) => Record<string, unknown> & {
271
+ tokenInfo?: TokenWithBalance;
272
+ validators: string[];
273
+ };
274
+ /**
275
+ * Create indexed token distribution
276
+ */
277
+ declare const createIndexedTokenDistribution: (x: {
278
+ tokenAddress: string;
279
+ txTime: string;
280
+ account: {
281
+ toString: () => string;
282
+ };
283
+ gas: {
284
+ toString: () => string;
285
+ };
286
+ fee: {
287
+ toString: () => string;
288
+ };
289
+ slashedVault: {
290
+ toString: () => string;
291
+ };
292
+ stake: {
293
+ toString: () => string;
294
+ };
295
+ revokedStake: {
296
+ toString: () => string;
297
+ };
298
+ gasStake: {
299
+ toString: () => string;
300
+ };
301
+ }) => Partial<TTokenDistribution>;
302
+ /**
303
+ * Format transaction before inserting to index
304
+ */
305
+ declare const formatTxBeforeInsert: (row: TxData) => TxData;
306
+ /**
307
+ * Format transaction after reading from index (remove internal indexing fields)
308
+ */
309
+ declare const formatTxAfterRead: (tx: TxData) => TxData;
310
+ /**
311
+ * Format delegation after reading from index
312
+ */
313
+ declare const formatDelegationAfterRead: (delegation: {
314
+ ops: unknown[] | Record<string, unknown>;
315
+ }) => {
316
+ ops: Array<{
317
+ key: string;
318
+ value: unknown;
319
+ }>;
320
+ };
321
+ /**
322
+ * Parse date time string to ISO format
323
+ */
324
+ declare const parseDateTime: (str: unknown) => string;
325
+ /** Paging input parameters */
326
+ interface PagingInput {
327
+ size?: number | null;
328
+ cursor?: string | number;
329
+ order?: {
330
+ field?: string;
331
+ type?: string;
332
+ } | Array<{
333
+ field?: string;
334
+ type?: string;
335
+ }>;
336
+ }
337
+ /** Parameters for formatPagination */
338
+ interface FormatPaginationParams {
339
+ paging?: PagingInput | null;
340
+ defaultSortField: string;
341
+ supportedSortFields?: string[];
342
+ }
343
+ /** Formatted pagination result */
344
+ interface FormattedPagination {
345
+ size: number;
346
+ cursor: number;
347
+ order: {
348
+ field: string;
349
+ type: string;
350
+ };
351
+ }
352
+ /**
353
+ * Format pagination parameters with defaults
354
+ */
355
+ declare const formatPagination: ({
356
+ paging,
357
+ defaultSortField,
358
+ supportedSortFields
359
+ }: FormatPaginationParams) => FormattedPagination;
360
+ /**
361
+ * Format next pagination info for response
362
+ */
363
+ declare const formatNextPagination: (total: number, pagination: {
364
+ cursor: number;
365
+ size: number;
366
+ }) => TPageInfo;
367
+ /**
368
+ * Check if a transaction changes the default token balance
369
+ */
370
+ declare const isDefaultTokenChanged: (tx: TxData, token: {
371
+ address: string;
372
+ }) => boolean;
373
+ //#endregion
374
+ export { DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };