Skip to content

Commit

Permalink
debug: trying to get generics to work
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jul 22, 2023
1 parent 4a9d062 commit 49500df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/contract/table-cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {API, Serializer} from '@greymass/eosio'
import {ABISerializableConstructor, API, Serializer} from '@greymass/eosio'
import {wrapIndexValue} from '../utils'
import {Query, Table} from './table'

Expand All @@ -16,7 +16,7 @@ interface TableCursorParams {
*
* @typeparam TableRow The type of rows in the table.
*/
export class TableCursor<TableRow> {
export class TableCursor<TableRow extends ABISerializableConstructor> {
private table: Table
private next_key: API.v1.TableIndexType | string | undefined
private tableParams: API.v1.GetTableRowsParams
Expand Down Expand Up @@ -75,7 +75,7 @@ export class TableCursor<TableRow> {
*
* @returns The new rows.
*/
async next(rowsPerAPIRequest?: number): Promise<TableRow[]> {
async next<Key extends keyof API.v1.TableIndexTypes = 'name'>(rowsPerAPIRequest?: number): Promise<TableRow[]> {
if (this.endReached) {
return []
}
Expand All @@ -99,7 +99,7 @@ export class TableCursor<TableRow> {
indexPosition = fieldToIndexMapping[this.indexPositionField].index_position
}

const result = await this.table.contract.client!.v1.chain.get_table_rows({
const result = await this.table.contract.client!.v1.chain.get_table_rows<TableRow, Key>({
...this.tableParams,
limit: Math.min(
this.maxRows - this.rowsCount,
Expand Down
4 changes: 2 additions & 2 deletions test/tests/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ suite('Table', () => {
@Struct.field(Int64) high_bid!: Int64
@Struct.field(TimePoint) last_bid_time!: TimePoint
}
const table = new Table({
const table = new Table<NameBid>({
contract: eosio,
name: 'namebids',
rowType: NameBid,
})
assert.instanceOf(table, Table)
const rows = await table.first(1).next()
const rows: NameBid[] = await table.first(1).next()
assert.instanceOf(rows[0], NameBid)
// assert.instanceOf(rows[0].newname, Name)
console.log(JSON.stringify(rows[0].newname))
Expand Down

0 comments on commit 49500df

Please sign in to comment.