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

feat: support key re-use from serialized path #474

Merged
merged 5 commits into from
Aug 26, 2019

Conversation

stephenplusplus
Copy link
Contributor

Fixes #59

This exposes a serialized property on a Key object. It will correctly differentiate between a key name and id, so that you can re-create a key with it:

const key = datastore.key({
  namespace: 'My-NS',
  path: ['Company', 123]
);
// Later...
const key = datastore.key(key.serialized);

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 16, 2019
@codecov
Copy link

codecov bot commented Aug 16, 2019

Codecov Report

Merging #474 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
+ Coverage   98.24%   98.25%   +0.01%     
==========================================
  Files           5        5              
  Lines         684      689       +5     
  Branches      159      161       +2     
==========================================
+ Hits          672      677       +5     
  Partials       12       12
Impacted Files Coverage Δ
src/entity.ts 98.59% <100%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 928f237...ffdd318. Read the comment docs.

src/entity.ts Outdated
* @name Key#serialized
* @type {array}
*/
Object.defineProperty(this, 'serialized', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use Object.defineProperty as opposed to a regular getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give it a few years-- Object.defineProperty will be in style again, and the kids will be wearing it on their hoodies.

src/entity.ts Outdated Show resolved Hide resolved
src/entity.ts Outdated Show resolved Hide resolved
@JustinBeckwith JustinBeckwith merged commit b36c90f into googleapis:master Aug 26, 2019
@stephenplusplus stephenplusplus deleted the spp--59 branch August 26, 2019 01:31
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.

Key paths are ambiguous, there is no trivial way to serialize a unique entity key!
4 participants