Skip to content
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

RequesterInvokeUpdate.result is inconsistent #23

Open
peterbrock opened this issue May 19, 2020 · 4 comments
Open

RequesterInvokeUpdate.result is inconsistent #23

peterbrock opened this issue May 19, 2020 · 4 comments

Comments

@peterbrock
Copy link

peterbrock commented May 19, 2020

Note: using the web.js version of the SDK, not the node.js version.

I've noticed that as a result of performing an invoke action; the returned RequesterInvokeUpdate has a getter method on, result(). The returned value of this is inconsistent in terms of it's own properties.

Sometimes you access the result using: response.result.result and other times its response.result[0]. From the source code, it looks to be because of here:

        let rows = this.rows;
        if (rows.length) {
          let firstRow = rows[0];
          if (this.rawColumns && this.rawColumns.length >= firstRow.length) {
            let result = {};
            for (let i = 0; i < firstRow.length; ++i) {
              let col = this.rawColumns[i].name;
              result[col] = firstRow[i];
            }
            return result;
          }
          else {
            return firstRow;
          }
        }
        else {
          return null;
        }

Running the following for the first response returns

response.result.hasOwnProperty('result') = true
response.result.hasOwnProperty('0') = false

...and then for subsequent responses/updates to the invoke:

response.result.hasOwnProperty('result') = false
response.result.hasOwnProperty('0') = true

Is it possible to update the SDK so that response.result has a consistent property?

@ilyatsarev
Copy link

Hi @peterbrock, thanks for the report. We're looking into this.

@rinick
Copy link
Member

rinick commented May 23, 2020

RequesterInvokeUpdate.result is a convenient way to convert the first row into Object structure
but since the update rows are sent as Array of Array, in order to convert them to key:value pair, the sdk need to know the column names.

Dslink built with new sdk like new java and ts/js sdk always send column structure in action response
But some older sdks (including the one used in dart broker), will not send that if the $columns is defined on node, so an extra list request is needed to do the conversion.

for now, in order to get consistent result, you can use response.rows[0]

@peterbrock
Copy link
Author

Thanks for getting back to me regarding this.

I'm not 100% sure I understand the reasoning regarding why .result is inconsistent and can't be translated. If I've understood your comment correctly; it's an issue with the SDK that the DSLink is using not sending the columns?
The DSLink we are using to execute the invoke action is the web.js DSLink; which appears to be out of date in the GitHub repo (under the dist directory); but we've rebuilt it ourselves using Browserify and the TS SDK and we still get the same issue - and as far as I'm aware we're using the most up to date version of the TS SDK.

As for the workaround; we found that we had to do:
response.rows[response.rows.length - 1] instead of response.rows[0]; otherwise we missed out on updates. Is this a reliable way of working? Or do we instead need to process rows and updates manually?

@rinick
Copy link
Member

rinick commented Jun 3, 2020

Thanks for getting back to me regarding this.

I'm not 100% sure I understand the reasoning regarding why .result is inconsistent and can't be translated. If I've understood your comment correctly; it's an issue with the SDK that the DSLink is using not sending the columns?
The DSLink we are using to execute the invoke action is the web.js DSLink; which appears to be out of date in the GitHub repo (under the dist directory); but we've rebuilt it ourselves using Browserify and the TS SDK and we still get the same issue - and as far as I'm aware we're using the most up to date version of the TS SDK.

As for the workaround; we found that we had to do:
response.rows[response.rows.length - 1] instead of response.rows[0]; otherwise we missed out on updates. Is this a reliable way of working? Or do we instead need to process rows and updates manually?

are you using latest typescript sdk as responder or requester?

if the responder is also typescript sdk then it's a bug , and we will try our best to fix it.
otherwise you might need to use response.rows[response.rows.length - 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants