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

refactor(codec): improve typescript defs #490

Merged
merged 13 commits into from
Jan 8, 2019
Merged

refactor(codec): improve typescript defs #490

merged 13 commits into from
Jan 8, 2019

Conversation

callmehiphop
Copy link
Contributor

@callmehiphop callmehiphop commented Dec 28, 2018

Relates to #223

  • Tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

This PR includes breaking changes!

Because Spanner rows can contain duplicate keys, the default format is an array of objects containing key value pairs.

const row = [
  {
    name: 'myfield',
    value: 'myvalue'
  }
];

Row arrays come equipped with a toJSON() method that transforms said arrays into a plain old JavaScript object while removing any custom wrappers (e.g. Spanner.int becomes number). However this was not applied recursively. The breaking changes do the following:

  1. Unwrap nested values.
  2. Transform Structs into plain old objects.

To elaborate on the second point, Structs behave exactly like rows and they can contain duplicate keys, so we've traditionally returned Arrays. However now they will return pojo's when toJSON() is called.

// before
const row = {
  mystruct: [
    {
      name: 'key',
      value: Spanner.int(10)
    }
  ]
};

// after
const row = {
  mystruct: {
    key: 10
  }
};

Similarly to wrapped numbers, we should allow the raw struct to be returned by passing a wrapStructs option.

row.toJSON({wrapStructs: true});

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 28, 2018
@@ -119,9 +119,7 @@ class BatchTransaction extends Transaction {
}
const reqOpts = codec.encodeQuery(query);
const gaxOpts = query.gaxOptions;
if (gaxOpts) {

This comment was marked as spam.

This comment was marked as spam.

@JustinBeckwith
Copy link
Contributor

I really don't have a good handle on what this code is doing, so it would be great if @stephenplusplus could review this as well :)

@callmehiphop callmehiphop merged commit 79f7855 into googleapis:master Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants