-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Independent Table Elements #34
Conversation
* | ||
* @returns A new cursor with updated parameters. | ||
*/ | ||
query(query: Query) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I guess one side effect of decoupling table and table cursor is that this now feels out of place 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if we want it back - it's going to need to be a function that translates a TableCursor
back into a Table
call, and that kinda re-adds that dependency this was seeking to remove.
I'm thinking maybe we add this feature into whatever a future QueryBuilder
might be, and leave it off for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
|
||
if (this.next_key) { | ||
lower_bound = this.next_key | ||
} | ||
|
||
let indexPosition = this.tableParams.index_position || 'primary' | ||
|
||
if (this.indexPositionField) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit that I do love the fact that this is no longer needed 😁
src/contract/table-cursor.ts
Outdated
|
||
const rows = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable assignment does a lot and is a bit difficult to follow so I would probably break it up into different steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a shot, and added some comments.
contract/src/contract/table-cursor.ts
Lines 85 to 100 in ede31bf
// Determine if we need to decode the rows, based on if: | |
// - json parameter is false, meaning hex data will be returned | |
// - type parameter is not set, meaning the APIClient will not automatically decode | |
const requiresDecoding = | |
this.params.json === false && !(query as API.v1.GetTableRowsParamsTyped).type | |
// Retrieve the rows from the result, decoding if needed | |
const rows: RowType[] = requiresDecoding | |
? result.rows.map((data) => | |
Serializer.decode({ | |
data, | |
abi: this.abi, | |
type: this.type, | |
}) | |
) | |
: result.rows |
I'm not sure how much more I think we should split it out, unless we wanted to get rid of the ternary operator, and instead do...
let rows = thing
if (decode) {
rows = otherThing
}
private rowsCount = 0 | ||
private maxRows: number = Number.MAX_SAFE_INTEGER | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that these were far from perfect, but we will still want to have some JSDoc statements here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah absolutely. I just kept seeing so many things changing - that I wanted to redo them all if this was the direction we wanted to go 👍
Co-authored-by: Daniel Fugere <[email protected]>
|
||
const mockClient = makeClient('https://eos.greymass.com') | ||
|
||
suite('Cursor', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
test/tests/table.ts
Outdated
) | ||
}) | ||
// TODO: Discuss and remove? No longer works since query is a Table method | ||
// test('should allow you to chain index query statements', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess we can just remove this. I personally kind of liked the fact that you could chain query statements like this, but given that the cursor and table classes are now built to be used independently, it no longer really makes sense to have a query method on the cursor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed for now, and left a link to this discussion in the commit.
test/utils/decentium.ts
Outdated
@@ -0,0 +1,382 @@ | |||
// generated by @greymass/abi2core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to commit this? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the unit tests are using it to test with Struct
instances from abi2core.
test/utils/eosio.ts
Outdated
@@ -0,0 +1,799 @@ | |||
// generated by @greymass/abi2core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I think about it, the more I realize that this is probably a good change to make! I left you some comments about some minor stuff, but overall the PR looks good! Thanks for working on this!
Same logic as before, just different syntax.
Resulting logic is the same, just simplified the Math.min() call
This PR breaks the dependencies between Contract, Table, and TableCursor - which allows developers the opportunity to use each element individually if they choose to do so.