-
Notifications
You must be signed in to change notification settings - Fork 592
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
Provide helper methods on entity.Key for Kind, parent, name, and ID #574
Comments
Yeah this seems nice. I like this. Would this functionality mimic existing similar functionality from another gcloud library (python? ruby?) that we could take a look at? Or can we just run with this idea on our own? |
I think the Python methods are modeled after |
I'll put this in queue for after #897 merges. |
Here's what I've got. Look okay @jgeewax? Your examplenew Key({ path: ['Person', 'mom', 'Person', 'jim'] })
// returns:
Key {
namespace: undefined,
path: [ 'Person', 'mom', 'Person', 'jim' ],
name: 'jim',
kind: 'Person',
parent:
Key {
namespace: undefined,
path: [ 'Person', 'mom' ],
name: 'mom',
kind: 'Person' } } Example with extra level of hierarchy and numeric IDnew Key({ path: ['Person', 'mom', 'Person', 'jim', 'SmallPerson', 1] })
// returns:
Key {
namespace: undefined,
path: [ 'Person', 'mom', 'Person', 'jim', 'SmallPerson', 1 ],
id: 1,
kind: 'SmallPerson',
parent:
Key {
namespace: undefined,
path: [ 'Person', 'mom', 'Person', 'jim' ],
name: 'jim',
kind: 'Person',
parent:
Key {
namespace: undefined,
path: [Object],
name: 'mom',
kind: 'Person' } } } |
I don't spot anything crazy, but just to be sure -- this is a method that derives the results at eval time, right? Or is it duplicate information being stored? |
At the time of instantiation, the parts of a key are split apart to create named properties for the given path array. So all of these things are stored in memory with the object. This is how all of our custom type constructors work. The duplicate information, do you mean the path? I kept that around since I thought it would be unfair for the user to lose a reference to their original input. |
Ah, sorry, to be clear I'm basically saying... If I change one piece of
information on this object, do the other pieces (that should be the same)
change too ? Or is there only one way to change the information, and
therefore they're always in sync ?
|
Gotcha. What types of changes should we support? We can prevent a parent from being overwritten for example, or just a kind, an ID, etc. Or, we allow everything. We would have to compute the path when it's asked for or update it when one of its parts changes... probably easier to compute the path on request. Here's a working constructor that allows anything to be changed and function Key(options) {
this.namespace = options.namespace;
if (options.path.length % 2 === 0) {
var identifier = options.path.pop();
if (is.number(identifier)) {
this.id = identifier;
} else if (is.string(identifier)) {
this.name = identifier;
}
}
this.kind = options.path.pop();
if (options.path.length > 0) {
this.parent = new Key(options);
}
// `path` is computed on demand to consider any changes that may have been
// made to the key.
Object.defineProperty(this, 'path', {
enumerable: true,
get: function () {
return arrify(this.parent && this.parent.path)
.concat([this.kind, this.name || this.id]);
}
});
}
var key = new Key({ path: ['Person', 'mom', 'Person', 'jim'] });
console.log(key.path);
// [ 'Person', 'mom', 'Person', 'jim' ]
key.parent.name = 'sam';
console.log(key.path);
// [ 'Person', 'sam', 'Person', 'jim' ]
console.log(key.parent.path);
// [ 'Person', 'sam' ] The one case I can think of that isn't covered is if a user had an ID but now assigns a name. But then I'm back to how mutable we should allow a Key path to be? |
Yep - the on-demand eval SGTM. Basically anything that is derived would ideally be on-demand evaluated... right? which would include ID / name, ie: var key = new Key({ path: ['Person', 'mom', 'Person', 'jim'] });
console.log(key.path);
// [ 'Person', 'mom', 'Person', 'jim' ]
key.parent.name = null;
key.parent.id = 1
console.log(key.path);
// [ 'Person', 1, 'Person', 'jim' ]
console.log(key.parent.path);
// [ 'Person', 1 ] |
Yeah that works fine. PR incoming! |
* feat: OSConfig: add OS policy assignment rpcs Committer: @adjackura PiperOrigin-RevId: 407422484 Source-Link: googleapis/googleapis@c11bc3e Source-Link: googleapis/googleapis-gen@d2df80a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDJkZjgwYTVhNjEyOTllZDJkZmYxMmJmYWYyODg2NjE5MTE3ZTljZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
🤖 I have created a release \*beep\* \*boop\* --- ## [3.21.0](https://www.github.com/googleapis/nodejs-asset/compare/v3.20.0...v3.21.0) (2021-11-09) ### Features * OSConfig: add OS policy assignment rpcs ([#574](https://www.github.com/googleapis/nodejs-asset/issues/574)) ([ff9491d](https://www.github.com/googleapis/nodejs-asset/commit/ff9491d55bd527c451914b487ce08fed3068dbd8)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
* feat: OSConfig: add OS policy assignment rpcs Committer: @adjackura PiperOrigin-RevId: 407422484 Source-Link: googleapis/googleapis@c11bc3e Source-Link: googleapis/googleapis-gen@d2df80a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDJkZjgwYTVhNjEyOTllZDJkZmYxMmJmYWYyODg2NjE5MTE3ZTljZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
🤖 I have created a release \*beep\* \*boop\* --- ## [3.21.0](https://www.github.com/googleapis/nodejs-asset/compare/v3.20.0...v3.21.0) (2021-11-09) ### Features * OSConfig: add OS policy assignment rpcs ([#574](https://www.github.com/googleapis/nodejs-asset/issues/574)) ([ff9491d](https://www.github.com/googleapis/nodejs-asset/commit/ff9491d55bd527c451914b487ce08fed3068dbd8)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
* feat: OSConfig: add OS policy assignment rpcs Committer: @adjackura PiperOrigin-RevId: 407422484 Source-Link: googleapis/googleapis@c11bc3e Source-Link: googleapis/googleapis-gen@d2df80a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDJkZjgwYTVhNjEyOTllZDJkZmYxMmJmYWYyODg2NjE5MTE3ZTljZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
🤖 I have created a release \*beep\* \*boop\* --- ## [3.21.0](https://www.github.com/googleapis/nodejs-asset/compare/v3.20.0...v3.21.0) (2021-11-09) ### Features * OSConfig: add OS policy assignment rpcs ([#574](https://www.github.com/googleapis/nodejs-asset/issues/574)) ([ff9491d](https://www.github.com/googleapis/nodejs-asset/commit/ff9491d55bd527c451914b487ce08fed3068dbd8)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release \*beep\* \*boop\* --- ### [3.3.5](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.3.4...v3.3.5) (2021-06-30) ### Bug Fixes * **deps:** google-gax v2.17.0 with mTLS ([#573](https://www.github.com/googleapis/nodejs-video-intelligence/issues/573)) ([afb19b5](https://www.github.com/googleapis/nodejs-video-intelligence/commit/afb19b5d54518d672e761881110c69e78276f80c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release \*beep\* \*boop\* --- ### [3.3.5](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v3.3.4...v3.3.5) (2021-06-30) ### Bug Fixes * **deps:** google-gax v2.17.0 with mTLS ([#573](https://www.github.com/googleapis/nodejs-video-intelligence/issues/573)) ([afb19b5](https://www.github.com/googleapis/nodejs-video-intelligence/commit/afb19b5d54518d672e761881110c69e78276f80c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
* chore(deps): update dependency gts to v3 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
* test: use fully qualified request type name in tests PiperOrigin-RevId: 475685359 Source-Link: googleapis/googleapis@7a12973 Source-Link: googleapis/googleapis-gen@370c729 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzcwYzcyOWUyYmEwNjJhMTY3NDQ5YzI3ODgyYmE1ZjM3OWM1YzM0ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
🤖 I have created a release \*beep\* \*boop\* --- ### [2.3.5](https://www.github.com/googleapis/nodejs-monitoring/compare/v2.3.4...v2.3.5) (2021-09-08) ### Bug Fixes * **build:** update branch to main ([#574](https://www.github.com/googleapis/nodejs-monitoring/issues/574)) ([955622f](https://www.github.com/googleapis/nodejs-monitoring/commit/955622f40583247a78301340fc172c9d42fa1354)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration.
* feat: OSConfig: add OS policy assignment rpcs Committer: @adjackura PiperOrigin-RevId: 407422484 Source-Link: googleapis/googleapis@c11bc3e Source-Link: googleapis/googleapis-gen@d2df80a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDJkZjgwYTVhNjEyOTllZDJkZmYxMmJmYWYyODg2NjE5MTE3ZTljZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
🤖 I have created a release \*beep\* \*boop\* --- ## [3.21.0](https://www.github.com/googleapis/nodejs-asset/compare/v3.20.0...v3.21.0) (2021-11-09) ### Features * OSConfig: add OS policy assignment rpcs ([#574](https://www.github.com/googleapis/nodejs-asset/issues/574)) ([ff9491d](https://www.github.com/googleapis/nodejs-asset/commit/ff9491d55bd527c451914b487ce08fed3068dbd8)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/c6d83c4f-acdd-445f-bc9f-2d95e3e6c923/targets - [ ] To automatically regenerate this PR, check this box. PiperOrigin-RevId: 361273630 Source-Link: googleapis/googleapis@5477122
(In reference to https://github.com/GoogleCloudPlatform/gcloud-node/blob/412598cad200198caaac5dbe83700fd1665b2102/lib/datastore/entity.js#L54)
It'd be really nice if we had some helper methods on the Key class, so that you could do the following...
Auto-generated ID example:
Specific name and parent example
Is this a reasonable request?
The text was updated successfully, but these errors were encountered: