@keetanetwork/keetanet-client 0.10.2

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 (71) hide show
  1. package/._version.d.ts +0 -0
  2. package/LICENSE +35 -0
  3. package/api/index.d.ts +181 -0
  4. package/api/node.d.ts +216 -0
  5. package/api/vote.d.ts +25 -0
  6. package/client/builder.d.ts +129 -0
  7. package/client/client_common_tests.d.ts +72 -0
  8. package/client/index-browser.d.ts +243 -0
  9. package/client/index-browser.js +141899 -0
  10. package/client/index.d.ts +243 -0
  11. package/client/index.js +89118 -0
  12. package/config/index.d.ts +62 -0
  13. package/lib/account.d.ts +544 -0
  14. package/lib/block/index.d.ts +181 -0
  15. package/lib/block/operations.d.ts +407 -0
  16. package/lib/bootstrap.d.ts +27 -0
  17. package/lib/error/account.d.ts +9 -0
  18. package/lib/error/block.d.ts +9 -0
  19. package/lib/error/client.d.ts +9 -0
  20. package/lib/error/index.d.ts +20 -0
  21. package/lib/error/kv.d.ts +9 -0
  22. package/lib/error/ledger.d.ts +12 -0
  23. package/lib/error/permissions.d.ts +9 -0
  24. package/lib/error/vote.d.ts +9 -0
  25. package/lib/index.d.ts +39 -0
  26. package/lib/kv/index.d.ts +22 -0
  27. package/lib/kv/index.test.data.d.ts +9 -0
  28. package/lib/kv/kv_dynamodb.d.ts +20 -0
  29. package/lib/kv/kv_memory.d.ts +17 -0
  30. package/lib/kv/kv_redis.d.ts +22 -0
  31. package/lib/kv/providers.d.ts +9 -0
  32. package/lib/ledger/cache.d.ts +14 -0
  33. package/lib/ledger/common.d.ts +115 -0
  34. package/lib/ledger/db_dynamodb.d.ts +129 -0
  35. package/lib/ledger/db_memory.d.ts +6 -0
  36. package/lib/ledger/db_postgres.d.ts +70 -0
  37. package/lib/ledger/db_spanner.d.ts +116 -0
  38. package/lib/ledger/db_spanner_helper.d.ts +487 -0
  39. package/lib/ledger/db_sqlite.d.ts +64 -0
  40. package/lib/ledger/drivers.d.ts +7 -0
  41. package/lib/ledger/effects.d.ts +78 -0
  42. package/lib/ledger/index.d.ts +312 -0
  43. package/lib/ledger/types.d.ts +49 -0
  44. package/lib/node/index.d.ts +114 -0
  45. package/lib/node/local.d.ts +30 -0
  46. package/lib/node/timing.d.ts +12 -0
  47. package/lib/node/utils.d.ts +4 -0
  48. package/lib/p2p.d.ts +300 -0
  49. package/lib/permissions.d.ts +121 -0
  50. package/lib/pubsub/index.d.ts +7 -0
  51. package/lib/pubsub/providers.d.ts +7 -0
  52. package/lib/pubsub/ps_memory.d.ts +9 -0
  53. package/lib/pubsub/ps_redis.d.ts +10 -0
  54. package/lib/stats.d.ts +51 -0
  55. package/lib/utils/asn1.d.ts +205 -0
  56. package/lib/utils/bitfield.d.ts +13 -0
  57. package/lib/utils/bloom.d.ts +6 -0
  58. package/lib/utils/buffer.d.ts +27 -0
  59. package/lib/utils/certificate.d.ts +340 -0
  60. package/lib/utils/conversion.d.ts +46 -0
  61. package/lib/utils/dynamodb.d.ts +17 -0
  62. package/lib/utils/ed2curve.d.ts +7 -0
  63. package/lib/utils/hash.d.ts +17 -0
  64. package/lib/utils/helper.d.ts +67 -0
  65. package/lib/utils/helper_testing.d.ts +37 -0
  66. package/lib/utils/initial.d.ts +32 -0
  67. package/lib/utils/never.d.ts +7 -0
  68. package/lib/utils/redis.d.ts +11 -0
  69. package/lib/vote.d.ts +273 -0
  70. package/package.json +35 -0
  71. package/version.d.ts +2 -0
@@ -0,0 +1,487 @@
1
+ import type { LedgerStorage } from '.';
2
+ import type { GenericAccount, TokenAddress } from '../account';
3
+ import Account, { AccountKeyAlgorithm } from '../account';
4
+ import Block, { BlockHash } from '../block';
5
+ import Vote, { PossiblyExpiredVote, VoteBlockHash } from '../vote';
6
+ import type { BaseSet, ExternalSet } from '../permissions';
7
+ import type { SpannerTransaction } from './db_spanner';
8
+ declare const ColumnTypes: {
9
+ readonly LEDGER: {
10
+ readonly dbType: "STRING";
11
+ readonly dbSize: 4;
12
+ readonly fromSpanner: (value: string) => LedgerStorage;
13
+ readonly toSpanner: (ledger: LedgerStorage) => LedgerStorage;
14
+ readonly toComparable: (name: string) => string;
15
+ };
16
+ readonly ACCOUNT: {
17
+ readonly fromSpanner: (pubKey: string) => Account<AccountKeyAlgorithm.ECDSA_SECP256K1 | AccountKeyAlgorithm.ED25519 | AccountKeyAlgorithm.ECDSA_SECP256R1>;
18
+ readonly toSpanner: (account: Account) => import("../account").Secp256K1PublicKeyString | import("../account").ED25519PublicKeyString | import("../account").Secp256R1PublicKeyString;
19
+ readonly dbType: string;
20
+ readonly dbSize: number;
21
+ readonly toComparable: (account: string | Account) => string;
22
+ };
23
+ readonly TOKEN_ACCOUNT: {
24
+ readonly fromSpanner: (pubKey: string) => Account<AccountKeyAlgorithm.TOKEN>;
25
+ readonly toSpanner: (account: TokenAddress) => import("../account").TokenPublicKeyString;
26
+ readonly dbType: string;
27
+ readonly dbSize: number;
28
+ readonly toComparable: (account: string | Account) => string;
29
+ };
30
+ readonly INFO_NAME: {
31
+ readonly dbSize: 50;
32
+ readonly dbType: string;
33
+ readonly fromSpanner: (str: string) => string;
34
+ readonly toSpanner: (str: string) => string;
35
+ readonly toComparable: (str: string) => string;
36
+ };
37
+ readonly INFO_DESCRIPTION: {
38
+ readonly dbSize: 250;
39
+ readonly dbType: string;
40
+ readonly fromSpanner: (str: string) => string;
41
+ readonly toSpanner: (str: string) => string;
42
+ readonly toComparable: (str: string) => string;
43
+ };
44
+ readonly INFO_METADATA: {
45
+ readonly dbSize: 750;
46
+ readonly dbType: string;
47
+ readonly fromSpanner: (str: string) => string;
48
+ readonly toSpanner: (str: string) => string;
49
+ readonly toComparable: (str: string) => string;
50
+ };
51
+ readonly BLOCK: {
52
+ readonly fromSpanner: (value: Buffer) => Block;
53
+ readonly toSpanner: (block: Block) => Buffer;
54
+ readonly toComparable: (vote: Block | Buffer | ArrayBuffer) => string;
55
+ readonly dbType: string;
56
+ readonly dbSize: string;
57
+ };
58
+ readonly VOTE: {
59
+ readonly fromSpanner: (value: Buffer, transaction: SpannerTransaction) => PossiblyExpiredVote | Vote | null;
60
+ readonly toSpanner: (vote: Vote | null) => Buffer | null;
61
+ readonly toComparable: (vote: PossiblyExpiredVote | Buffer | ArrayBuffer | null) => string | null;
62
+ readonly dbType: string;
63
+ readonly dbSize: string;
64
+ };
65
+ readonly SUPPLY: {
66
+ readonly fromSpanner: (value: any) => bigint;
67
+ readonly dbType: string;
68
+ readonly dbSize: number;
69
+ readonly toSpanner: (value: string | bigint) => string;
70
+ readonly toComparable: (value: bigint | string) => bigint;
71
+ };
72
+ readonly BASE_PERMISSION: {
73
+ readonly fromSpanner: (value: string) => BaseSet;
74
+ readonly toSpanner: (baseSet: BaseSet) => string;
75
+ readonly toComparable: (value: bigint | BaseSet) => bigint;
76
+ readonly dbType: string;
77
+ readonly dbSize: undefined;
78
+ };
79
+ readonly EXTERNAL_PERMISSION: {
80
+ readonly fromSpanner: (value: string) => ExternalSet;
81
+ readonly toSpanner: (externalSet: ExternalSet) => string;
82
+ readonly toComparable: (value: bigint | ExternalSet) => bigint;
83
+ readonly dbType: string;
84
+ readonly dbSize: undefined;
85
+ };
86
+ readonly BLOCKHASH: {
87
+ readonly fromSpanner: (hash: string) => BlockHash;
88
+ readonly toSpanner: (blockHash: BlockHash) => string;
89
+ readonly toComparable: (blockHash: BlockHash | string) => string;
90
+ readonly dbType: string;
91
+ readonly dbSize: number;
92
+ };
93
+ readonly VOTEBLOCKHASH: {
94
+ readonly fromSpanner: (hash: string) => VoteBlockHash;
95
+ readonly toSpanner: (blockHash: VoteBlockHash) => string;
96
+ readonly toComparable: (blockHash: VoteBlockHash | string) => string;
97
+ readonly dbType: string;
98
+ readonly dbSize: number;
99
+ };
100
+ readonly VOTE_UID: {
101
+ readonly dbSize: 150;
102
+ readonly dbType: string;
103
+ readonly fromSpanner: (str: string) => string;
104
+ readonly toSpanner: (str: string) => string;
105
+ readonly toComparable: (str: string) => string;
106
+ };
107
+ readonly BUFFER: {
108
+ dbType: string;
109
+ dbSize: string;
110
+ toSpanner: (buf: Buffer | Uint8Array | string) => Buffer;
111
+ fromSpanner: (value: Buffer | Uint8Array | string) => Buffer;
112
+ toComparable: (val: Buffer | string) => string;
113
+ };
114
+ readonly HASH: {
115
+ dbType: string;
116
+ dbSize: number;
117
+ fromSpanner: (hash: string) => string;
118
+ toSpanner: (hash: string) => string;
119
+ toComparable: (value: string) => string;
120
+ };
121
+ readonly BIGINT: {
122
+ dbType: string;
123
+ dbSize: undefined;
124
+ fromSpanner: (value: number | string) => bigint;
125
+ toSpanner: (value: string | bigint) => string;
126
+ toComparable: (value: bigint | string) => bigint;
127
+ };
128
+ readonly INT_AS_STRING: {
129
+ dbType: string;
130
+ dbSize: number;
131
+ fromSpanner: (value: string | bigint) => bigint;
132
+ toSpanner: (value: string | bigint) => string;
133
+ toComparable: (value: bigint | string) => bigint;
134
+ };
135
+ readonly STRING: {
136
+ dbType: string;
137
+ dbSize: number;
138
+ fromSpanner: (str: string) => string;
139
+ toSpanner: (str: string) => string;
140
+ toComparable: (str: string) => string;
141
+ };
142
+ readonly TIMESTAMP: {
143
+ dbType: string;
144
+ dbSize: undefined;
145
+ fromSpanner: (date: Date) => Date;
146
+ toSpanner: (date: Date) => Date;
147
+ toComparable: (date: Date) => number;
148
+ };
149
+ readonly BOOLEAN: {
150
+ dbType: string;
151
+ dbSize: undefined;
152
+ fromSpanner: (bool: boolean) => boolean;
153
+ toSpanner: (bool: boolean) => boolean;
154
+ toComparable: (bool: boolean) => boolean;
155
+ };
156
+ readonly GENERIC_ACCOUNT: {
157
+ dbType: string;
158
+ dbSize: number;
159
+ toComparable: (account: string | Account) => string;
160
+ fromSpanner: (pubKey: string) => GenericAccount;
161
+ toSpanner: (account: GenericAccount) => import("../account").Secp256K1PublicKeyString | import("../account").ED25519PublicKeyString | import("../account").NetworkPublicKeyString | import("../account").TokenPublicKeyString | import("../account").StoragePublicKeyString | import("../account").Secp256R1PublicKeyString;
162
+ };
163
+ readonly BUFFER_BIGINT: {
164
+ dbType: string;
165
+ dbSize: string;
166
+ toSpanner: (buf: bigint) => Buffer;
167
+ fromSpanner: (value: Buffer) => bigint;
168
+ toComparable: (val: Buffer | bigint | string) => bigint;
169
+ };
170
+ };
171
+ type ColumnTypeName = keyof typeof ColumnTypes;
172
+ type ColumnOutputTypeArg<T extends ColumnTypeName> = Parameters<typeof ColumnTypes[T]['fromSpanner']>[0];
173
+ type ColumnOutputTypeReturn<T extends ColumnTypeName> = ReturnType<typeof ColumnTypes[T]['fromSpanner']>;
174
+ type ColumnOutputTypeInfer<X> = X extends ColumnInterface<infer TR> ? ColumnOutputTypeReturn<TR> : never;
175
+ type ColumnInputTypeArg<T extends ColumnTypeName> = Parameters<typeof ColumnTypes[T]['toSpanner']>[0];
176
+ type ColumnInputTypeReturn<T extends ColumnTypeName> = ReturnType<typeof ColumnTypes[T]['toSpanner']>;
177
+ interface ColumnInterface<T extends ColumnTypeName> {
178
+ nullable: (nullable: boolean) => ColumnInterface<T>;
179
+ fromSpanner: (value: ColumnOutputTypeArg<T>, transaction: SpannerTransaction) => ColumnOutputTypeReturn<T>;
180
+ toSpanner: (value: ColumnInputTypeArg<T>, transaction: SpannerTransaction) => ColumnInputTypeReturn<T>;
181
+ toComparable: (value: any, transaction: SpannerTransaction) => any;
182
+ }
183
+ type KeyOrderBy = 'NONE' | 'ASC' | 'DESC';
184
+ declare class Key {
185
+ #private;
186
+ constructor(columnName: string, orderBy?: KeyOrderBy);
187
+ get ddl(): string;
188
+ get name(): string;
189
+ }
190
+ type SchemaType = 'TABLE' | 'INDEX';
191
+ type InterleaveAction = 'CASCADE' | 'NOTHING';
192
+ declare class Interleave {
193
+ #private;
194
+ constructor(type: SchemaType, table: string);
195
+ action(action: InterleaveAction): this;
196
+ get ddl(): string;
197
+ static FromTable(table: string, action?: InterleaveAction): Interleave;
198
+ static FromIndex(table: string): Interleave;
199
+ }
200
+ declare const schema: {
201
+ readonly accountInfo: {
202
+ readonly type: "TABLE";
203
+ readonly columns: {
204
+ readonly account: ColumnInterface<"GENERIC_ACCOUNT">;
205
+ readonly name: ColumnInterface<"INFO_NAME">;
206
+ readonly description: ColumnInterface<"INFO_DESCRIPTION">;
207
+ readonly metadata: ColumnInterface<"INFO_METADATA">;
208
+ readonly supply: ColumnInterface<"SUPPLY">;
209
+ readonly defaultBasePermission: ColumnInterface<"BASE_PERMISSION">;
210
+ readonly defaultExternalPermission: ColumnInterface<"EXTERNAL_PERMISSION">;
211
+ };
212
+ readonly key: readonly [Key];
213
+ };
214
+ readonly permissions: {
215
+ readonly type: "TABLE";
216
+ readonly columns: {
217
+ readonly account: ColumnInterface<"GENERIC_ACCOUNT">;
218
+ readonly entity: ColumnInterface<"GENERIC_ACCOUNT">;
219
+ readonly target: ColumnInterface<"GENERIC_ACCOUNT">;
220
+ readonly basePermission: ColumnInterface<"BASE_PERMISSION">;
221
+ readonly externalPermission: ColumnInterface<"EXTERNAL_PERMISSION">;
222
+ };
223
+ readonly key: readonly [Key, Key, Key];
224
+ readonly interleave: Interleave;
225
+ };
226
+ readonly ledger: {
227
+ readonly type: "TABLE";
228
+ readonly columns: {
229
+ readonly account: ColumnInterface<"GENERIC_ACCOUNT">;
230
+ readonly token: ColumnInterface<"TOKEN_ACCOUNT">;
231
+ readonly onLedger: ColumnInterface<"LEDGER">;
232
+ readonly balance: ColumnInterface<"INT_AS_STRING">;
233
+ };
234
+ readonly key: readonly [Key, Key, Key];
235
+ readonly interleave: Interleave;
236
+ };
237
+ readonly chain: {
238
+ readonly type: "TABLE";
239
+ readonly columns: {
240
+ readonly account: ColumnInterface<"GENERIC_ACCOUNT">;
241
+ readonly blockHeight: ColumnInterface<"BIGINT">;
242
+ readonly blockHash: ColumnInterface<"BLOCKHASH">;
243
+ };
244
+ readonly key: readonly [Key, Key];
245
+ readonly interleave: Interleave;
246
+ };
247
+ readonly history: {
248
+ readonly type: "TABLE";
249
+ readonly columns: {
250
+ readonly account: ColumnInterface<"GENERIC_ACCOUNT">;
251
+ readonly voteBlockHash: ColumnInterface<"VOTEBLOCKHASH">;
252
+ readonly orderIndex: ColumnInterface<"BUFFER_BIGINT">;
253
+ };
254
+ readonly key: readonly [Key, Key];
255
+ readonly interleave: Interleave;
256
+ };
257
+ readonly delegation: {
258
+ readonly type: "TABLE";
259
+ readonly columns: {
260
+ readonly account: ColumnInterface<"ACCOUNT">;
261
+ readonly delegatedToRep: ColumnInterface<"ACCOUNT">;
262
+ };
263
+ readonly key: readonly [Key];
264
+ readonly interleave: Interleave;
265
+ };
266
+ readonly votes: {
267
+ readonly type: "TABLE";
268
+ readonly columns: {
269
+ readonly voteUID: ColumnInterface<"VOTE_UID">;
270
+ readonly onLedger: ColumnInterface<"LEDGER">;
271
+ readonly vote: ColumnInterface<"VOTE">;
272
+ readonly timestamp: ColumnInterface<"TIMESTAMP">;
273
+ readonly expires: ColumnInterface<"TIMESTAMP">;
274
+ readonly issuer: ColumnInterface<"ACCOUNT">;
275
+ readonly voteBlockHash: ColumnInterface<"VOTEBLOCKHASH">;
276
+ };
277
+ readonly key: readonly [Key, Key];
278
+ };
279
+ readonly blocks: {
280
+ readonly type: "TABLE";
281
+ readonly columns: {
282
+ readonly blockHash: ColumnInterface<"BLOCKHASH">;
283
+ readonly onLedger: ColumnInterface<"LEDGER">;
284
+ readonly block: ColumnInterface<"BLOCK">;
285
+ readonly prevBlockHash: ColumnInterface<"BLOCKHASH">;
286
+ };
287
+ readonly key: readonly [Key];
288
+ };
289
+ readonly voteBlocks: {
290
+ readonly type: "TABLE";
291
+ readonly columns: {
292
+ readonly blockHash: ColumnInterface<"BLOCKHASH">;
293
+ readonly voteUID: ColumnInterface<"VOTE_UID">;
294
+ };
295
+ readonly key: readonly [Key, Key];
296
+ readonly interleave: Interleave;
297
+ };
298
+ readonly weight: {
299
+ readonly type: "TABLE";
300
+ readonly columns: {
301
+ readonly repAccount: ColumnInterface<"ACCOUNT">;
302
+ readonly weight: ColumnInterface<"INT_AS_STRING">;
303
+ };
304
+ readonly key: readonly [Key];
305
+ };
306
+ readonly heapBlocks: {
307
+ readonly type: "TABLE";
308
+ readonly columns: {
309
+ readonly prevBlockHash: ColumnInterface<"BLOCKHASH">;
310
+ readonly storageHash: ColumnInterface<"HASH">;
311
+ };
312
+ readonly key: readonly [Key];
313
+ };
314
+ readonly heapStorage: {
315
+ readonly type: "TABLE";
316
+ readonly columns: {
317
+ readonly storageHash: ColumnInterface<"HASH">;
318
+ readonly data: ColumnInterface<"BUFFER">;
319
+ };
320
+ readonly key: readonly [Key];
321
+ };
322
+ readonly permissionsAccount: {
323
+ readonly type: "INDEX";
324
+ readonly table: "permissions";
325
+ readonly key: readonly [Key];
326
+ readonly storing: readonly [Key, Key];
327
+ };
328
+ readonly permissionsPrincipalEntity: {
329
+ readonly type: "INDEX";
330
+ readonly table: "permissions";
331
+ readonly key: readonly [Key, Key];
332
+ readonly storing: readonly [Key, Key];
333
+ };
334
+ readonly permissionsEntity: {
335
+ readonly type: "INDEX";
336
+ readonly table: "permissions";
337
+ readonly key: readonly [Key];
338
+ readonly storing: readonly [Key, Key];
339
+ };
340
+ readonly permissionsEntityBasePerm: {
341
+ readonly type: "INDEX";
342
+ readonly table: "permissions";
343
+ readonly key: readonly [Key, Key];
344
+ };
345
+ readonly historyAccount: {
346
+ readonly type: "INDEX";
347
+ readonly table: "history";
348
+ readonly key: readonly [Key];
349
+ readonly storing: readonly [Key];
350
+ };
351
+ readonly historyVoteBlockHash: {
352
+ readonly type: "INDEX";
353
+ readonly table: "history";
354
+ readonly key: readonly [Key, Key];
355
+ };
356
+ readonly historyAccountOrderIndex: {
357
+ readonly type: "INDEX";
358
+ readonly table: "history";
359
+ readonly key: readonly [Key, Key];
360
+ readonly storing: readonly [Key];
361
+ };
362
+ readonly chainAccount: {
363
+ readonly type: "INDEX";
364
+ readonly table: "chain";
365
+ readonly key: readonly [Key];
366
+ readonly interleave: Interleave;
367
+ readonly storing: readonly [Key];
368
+ };
369
+ readonly chainAccountHash: {
370
+ readonly type: "INDEX";
371
+ readonly table: "chain";
372
+ readonly unique: true;
373
+ readonly key: readonly [Key, Key];
374
+ readonly interleave: Interleave;
375
+ };
376
+ readonly blocksPrevBlockHash: {
377
+ readonly type: "INDEX";
378
+ readonly table: "blocks";
379
+ readonly key: readonly [Key];
380
+ readonly unique: true;
381
+ readonly storing: readonly [Key, Key];
382
+ };
383
+ readonly voteBlocksBlockhash: {
384
+ readonly type: "INDEX";
385
+ readonly table: "voteBlocks";
386
+ readonly key: readonly [Key];
387
+ readonly interleave: Interleave;
388
+ };
389
+ readonly votesTimestamp: {
390
+ readonly type: "INDEX";
391
+ readonly table: "votes";
392
+ readonly key: readonly [Key, Key];
393
+ readonly storing: readonly [Key];
394
+ };
395
+ readonly votesOnLedgerExpired: {
396
+ readonly type: "INDEX";
397
+ readonly table: "votes";
398
+ readonly key: readonly [Key, Key];
399
+ readonly storing: readonly [Key];
400
+ };
401
+ readonly votesUidIssuer: {
402
+ readonly type: "INDEX";
403
+ readonly table: "votes";
404
+ readonly key: readonly [Key, Key];
405
+ readonly storing: readonly [Key];
406
+ };
407
+ readonly votesUid: {
408
+ readonly type: "INDEX";
409
+ readonly table: "votes";
410
+ readonly key: readonly [Key];
411
+ readonly storing: readonly [Key];
412
+ };
413
+ readonly votesBlockHash: {
414
+ readonly type: "INDEX";
415
+ readonly table: "votes";
416
+ readonly key: readonly [Key];
417
+ readonly storing: readonly [Key];
418
+ };
419
+ readonly ledgerBalanceByAccount: {
420
+ readonly type: "INDEX";
421
+ readonly table: "ledger";
422
+ readonly key: readonly [Key];
423
+ readonly storing: readonly [Key];
424
+ readonly interleave: Interleave;
425
+ };
426
+ };
427
+ type SchemaEntriesFilter<T extends SchemaType> = keyof {
428
+ [K in (keyof typeof schema) as typeof schema[K]['type'] extends T ? K : never]: true;
429
+ };
430
+ export type TableName = SchemaEntriesFilter<'TABLE'>;
431
+ export type IndexName = SchemaEntriesFilter<'INDEX'>;
432
+ export type TableIndexName = IndexName | TableName;
433
+ type IndexToTableName<I extends IndexName> = typeof schema[I]['table'];
434
+ type RootTableNameUndef<TI extends TableIndexName> = (TI extends IndexName ? IndexToTableName<TI> : TI);
435
+ export type RootTableName<T extends TableIndexName> = RootTableNameUndef<T> extends TableName ? RootTableNameUndef<T> : never;
436
+ export type TableColumn<T extends TableName> = keyof NonNullable<((typeof schema[T])['columns'])>;
437
+ type TableColumnType<T extends TableName, K extends TableColumn<T>> = K extends keyof typeof schema[T]['columns'] ? typeof schema[T]['columns'][K] : never;
438
+ export type TableRow<T extends TableName> = {
439
+ -readonly [key in TableColumn<T>]?: ColumnOutputTypeInfer<TableColumnType<T, key>>;
440
+ };
441
+ interface QueryValueMin<T extends TableName, K extends TableColumn<T>> {
442
+ min: ColumnOutputTypeInfer<TableColumnType<T, K>>;
443
+ }
444
+ interface QueryValueMax<T extends TableName, K extends TableColumn<T>> {
445
+ max: ColumnOutputTypeInfer<TableColumnType<T, K>>;
446
+ }
447
+ type QueryValueMinMax<T extends TableName, K extends TableColumn<T>> = QueryValueMin<T, K> | QueryValueMax<T, K> | (QueryValueMin<T, K> & QueryValueMax<T, K>);
448
+ export type QueryRow<T extends TableName> = {
449
+ [key in TableColumn<T>]?: ColumnOutputTypeInfer<TableColumnType<T, key>> | QueryValueMinMax<T, key>;
450
+ };
451
+ export type TableRows<T extends TableName> = TableRow<T>[];
452
+ export type QueryRows<T extends TableName> = QueryRow<T>[];
453
+ export type FilteredResponseRow<T extends TableName, C> = TableRow<T> & {
454
+ [K in keyof C as C[K] extends TableColumn<T> ? C[K] : never]: C[K] extends TableColumn<T> ? ColumnOutputTypeInfer<TableColumnType<T, C[K]>> : never;
455
+ };
456
+ export declare class Helper {
457
+ #private;
458
+ constructor();
459
+ static getPrimaryKeyNames<X extends TableIndexName>(table: X): string[];
460
+ static getNameFromType(filterType: 'INDEX'): IndexName[];
461
+ static getNameFromType(filterType: 'TABLE'): TableName[];
462
+ static getAllTables(): ("permissions" | "blocks" | "votes" | "ledger" | "history" | "weight" | "chain" | "accountInfo" | "heapBlocks" | "heapStorage" | "delegation" | "voteBlocks")[];
463
+ static IsTable(name: TableIndexName): name is TableName;
464
+ static IsIndex(name: TableIndexName): name is IndexName;
465
+ static getIndexParent(index: IndexName): TableName;
466
+ static getCompoundKeys<T extends TableName, R extends TableRow<T>[]>(table: TableName, rows: R, index?: IndexName): any[][];
467
+ static getCompoundRangeKeys<T extends TableName, R extends QueryRows<T>>(table: TableName, rows: R, index?: IndexName): {
468
+ startClosed: any[];
469
+ endClosed: any[];
470
+ }[];
471
+ static getDDL(addSemis?: boolean): string[];
472
+ }
473
+ export declare class RowBuilder {
474
+ #private;
475
+ constructor(transaction: SpannerTransaction, table: TableName, rawRows?: any);
476
+ ensureKeys(index?: IndexName): this;
477
+ mapRows(perRow?: (row: any) => any, perKey?: (key: string, value: any) => any): any[];
478
+ unwrapRows(): this;
479
+ toSpanner(): this;
480
+ fromSpanner(): this;
481
+ toComparable(): this;
482
+ merge(toMerge: any[]): this;
483
+ filter(columns: TableColumn<any>[]): this;
484
+ get rows(): any[];
485
+ get compoundKeys(): any[][];
486
+ }
487
+ export {};
@@ -0,0 +1,64 @@
1
+ import { VoteStaple, Vote, VoteBlockHash } from '../vote';
2
+ import type { VoteBlockHashMap } from '../vote';
3
+ import type { BlockHash } from '../block';
4
+ import { Block } from '../block';
5
+ import type { GenericAccount, IdentifierAddress, TokenAddress } from '../account';
6
+ import Account, { AccountKeyAlgorithm } from '../account';
7
+ import type { Ledger, LedgerConfig, LedgerStorageAPI, LedgerSelector, PaginatedVotes, GetVotesAfterOptions } from '../ledger';
8
+ import type { AccountInfo, ACLRow, GetAllBalancesResponse, LedgerStatistics } from './types';
9
+ import { LedgerStorageBase } from './common';
10
+ import * as sqlite from 'sqlite';
11
+ import type { ComputedEffectOfBlocks } from './effects';
12
+ interface DBSqliteTransaction {
13
+ sql: Awaited<ReturnType<typeof sqlite['open']>>;
14
+ moment: Date;
15
+ release: null | ((value: null | number) => void);
16
+ lock: null | Promise<null | number>;
17
+ }
18
+ export interface DBSqliteConfig {
19
+ filename: string;
20
+ retryCount?: number;
21
+ }
22
+ export declare class DBSqlite extends LedgerStorageBase implements LedgerStorageAPI {
23
+ #private;
24
+ constructor();
25
+ init(config: LedgerConfig, ledger: Ledger): void;
26
+ destroy(): Promise<void>;
27
+ beginTransaction(): Promise<DBSqliteTransaction>;
28
+ commitTransaction(transaction: DBSqliteTransaction): Promise<void>;
29
+ abortTransaction(transaction: DBSqliteTransaction): Promise<void>;
30
+ evaluateError(error: any): Promise<any>;
31
+ delegatedWeight(transaction: DBSqliteTransaction, rep?: Account): Promise<bigint>;
32
+ getBalance(transaction: DBSqliteTransaction, account: GenericAccount, token: TokenAddress): Promise<bigint>;
33
+ getAllBalances(transaction: DBSqliteTransaction, account: GenericAccount): Promise<GetAllBalancesResponse>;
34
+ addPendingVote(transaction: DBSqliteTransaction, votesAndBlocks: VoteStaple): Promise<void>;
35
+ getAccountRep(transaction: DBSqliteTransaction, userAccount: Account | string): Promise<Account | null>;
36
+ /**
37
+ * If an adjustment cannot be made right now, defer it for follow-up
38
+ */
39
+ protected adjustDefer(transaction: DBSqliteTransaction, input: VoteStaple): Promise<void>;
40
+ listOwners(transaction: DBSqliteTransaction, entity: IdentifierAddress): Promise<Account<AccountKeyAlgorithm.TOKEN>[]>;
41
+ listACLsByEntity(transaction: DBSqliteTransaction, entity: GenericAccount): Promise<ACLRow[]>;
42
+ listACLsByPrincipal(transaction: DBSqliteTransaction, principal: GenericAccount, entityList?: GenericAccount[]): Promise<ACLRow[]>;
43
+ getAccountInfo(transaction: DBSqliteTransaction, account: GenericAccount | string): Promise<AccountInfo>;
44
+ adjust(transaction: DBSqliteTransaction, input: VoteStaple, changes: ComputedEffectOfBlocks, mayDefer?: boolean): Promise<BlockHash[]>;
45
+ getBlock(transaction: DBSqliteTransaction, block: BlockHash, from: LedgerSelector): Promise<Block | null>;
46
+ getBlockHeight(transaction: DBSqliteTransaction, blockHash: BlockHash, account: GenericAccount): Promise<{
47
+ blockHeight: string | null;
48
+ } | null>;
49
+ getVotes(transaction: DBSqliteTransaction, block: BlockHash, from: LedgerSelector): Promise<Vote[] | null>;
50
+ getVoteStaples(transaction: DBSqliteTransaction, voteBlockHashes: VoteBlockHash[], from?: LedgerSelector): Promise<VoteBlockHashMap<VoteStaple | null>>;
51
+ getHistory(transaction: DBSqliteTransaction, account: GenericAccount, start: VoteBlockHash | null, limit?: number): Promise<VoteBlockHash[]>;
52
+ getBlockFromPrevious(transaction: DBSqliteTransaction, prevBlock: BlockHash, from: LedgerSelector): Promise<Block | null>;
53
+ getVotesFromMultiplePrevious(transaction: DBSqliteTransaction, prevBlocks: BlockHash[], from: LedgerSelector, issuer?: GenericAccount): Promise<{
54
+ [hash: string]: Vote[] | null;
55
+ }>;
56
+ getHeadBlocks(transaction: DBSqliteTransaction, accounts: GenericAccount[], from: LedgerSelector): Promise<{
57
+ [publicKey: string]: Block | null;
58
+ }>;
59
+ getVotesAfter(transaction: DBSqliteTransaction, moment: Date, startKey?: string, options?: GetVotesAfterOptions): Promise<PaginatedVotes>;
60
+ gc(transaction: DBSqliteTransaction): Promise<true>;
61
+ getNextSerialNumber(transaction: DBSqliteTransaction): Promise<bigint>;
62
+ stats(): Promise<LedgerStatistics>;
63
+ }
64
+ export default DBSqlite;
@@ -0,0 +1,7 @@
1
+ import type { LedgerStorageAPI } from './';
2
+ export declare const Drivers: {
3
+ [name: string]: {
4
+ new (): LedgerStorageAPI;
5
+ };
6
+ };
7
+ export default Drivers;
@@ -0,0 +1,78 @@
1
+ import type { GenericAccount, IdentifierAddress, NetworkAddress, TokenAddress } from '../account';
2
+ import Account from '../account';
3
+ import type { BlockHash } from '../block';
4
+ import { Block } from '../block';
5
+ import type { AccountInfo, ACLEntry, ACLUpdate } from '../ledger/types';
6
+ import type { InstanceSet } from '../utils/helper';
7
+ interface NumericValueEntry {
8
+ value: bigint;
9
+ }
10
+ interface TokenNumericEntry extends NumericValueEntry {
11
+ otherAccount: GenericAccount;
12
+ isReceive: boolean;
13
+ }
14
+ interface RequestTokenReceiveEntry extends TokenNumericEntry {
15
+ isReceive: true;
16
+ otherAccount: GenericAccount;
17
+ exact: boolean;
18
+ }
19
+ interface ModifyTokenBalanceEntry extends TokenNumericEntry {
20
+ isReceive: false;
21
+ set: boolean;
22
+ receivable: boolean;
23
+ }
24
+ type TokenEntry = ModifyTokenBalanceEntry | RequestTokenReceiveEntry;
25
+ interface ComputedBlocksEffectTokenChangesField {
26
+ [tokenPubKey: string]: TokenEntry[];
27
+ }
28
+ /**
29
+ * Which fields may be affected by blocks
30
+ */
31
+ type CreateIdentifierRequest = {
32
+ previousBlockHash: BlockHash;
33
+ requestedIdentifier: IdentifierAddress;
34
+ operationIndex: number;
35
+ account: GenericAccount;
36
+ };
37
+ type DelegationUpdate = {
38
+ delegateTo: Account;
39
+ };
40
+ interface ComputedBlocksEffectFields {
41
+ balance?: ComputedBlocksEffectTokenChangesField;
42
+ supply?: NumericValueEntry[];
43
+ info?: AccountInfo;
44
+ permissions?: ACLUpdate[];
45
+ permissionRequirements?: ACLEntry[];
46
+ createRequests?: CreateIdentifierRequest[];
47
+ delegation?: DelegationUpdate;
48
+ }
49
+ /**
50
+ * Which accounts and fields are affected by a set of block
51
+ */
52
+ interface ComputedBlockEffect {
53
+ account: GenericAccount;
54
+ fields: ComputedBlocksEffectFields;
55
+ }
56
+ /**
57
+ * A breakdown of computed effects by account public key
58
+ */
59
+ export type ComputedEffectOfBlocksByAccount = {
60
+ [accountPubKey: string]: ComputedBlockEffect;
61
+ };
62
+ export type ComputedEffectOfBlocks = {
63
+ accounts: ComputedEffectOfBlocksByAccount;
64
+ touched: InstanceSet<GenericAccount>;
65
+ metadata: {
66
+ operationCount: number;
67
+ blockCount: number;
68
+ };
69
+ };
70
+ type LedgerOptions = {
71
+ initialTrustedAccount?: Account;
72
+ baseToken: TokenAddress;
73
+ networkAddress: NetworkAddress;
74
+ };
75
+ type OnlyTouchedEffects = Pick<ComputedEffectOfBlocks, 'touched'>;
76
+ export declare function computeEffectOfBlocks(blocks: Block[], ledger?: undefined): OnlyTouchedEffects;
77
+ export declare function computeEffectOfBlocks(blocks: Block[], ledger: LedgerOptions): ComputedEffectOfBlocks;
78
+ export {};