-
Notifications
You must be signed in to change notification settings - Fork 597
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
Dataset.key() docs + proposal for simpler API #209
Conversation
Can you change the named parameter to Here's an example of how we can document our current structure: But, I'm not a big fan of the variable arity, either. It's not something I've seen too often in js-land, since we have the ease of passing around configuration objects. I'm not sure you'll like this any better, but I propose we instead only allow a single argument to // path string
dataset.key('Company');
// path array
dataset.key(['Company', 1]);
// object specifying namespace and path
dataset.key({
namespace: 'MyNS',
path: ['Company', 1]
}); So basically, if provide an object: control all components. Provide an array or string, you're providing the path. I think all it takes is seeing an example, reading about the namespace inheritance, and it's pretty straightforward from there. |
Yeah, I think that'll give us a good compromise. I'll work on making that happen. |
PTAL. This should change |
} | ||
return new entity.Key(keyConfig); | ||
Dataset.prototype.key = function(options) { | ||
var opts = util.is(options, 'object') ? options : { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
If there isn't something that covers this already, could you add a test on dataset.key to see if it handles strings as expected? |
Agh! Good call, I found an issue. Question now though, is: |
} | ||
return new entity.Key(keyConfig); | ||
Dataset.prototype.key = function(options) { | ||
options = util.is(options, 'object') ? options : { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
PTAL |
My dataset.key() example was I guess foreshadowing our desired support for auto-injecting null. Since we don't have that yet, and even after we do, this would be an invalid key currently. After we auto inject null (if we do) it would be a valid, incomplete key. |
Yeah, I just realized that. Although our code doesn't do it anywhere, it would create an invalid key. I will get started on auto-injecting nulls if we think that's a good idea? Let me know. |
I think it's safe to do that. We used to take an array and if it wasn't an even number length, we used the first item as the namespace. Back then, it wasn't possible for us to infer an odd length meant a key didn't have an id or if it didn't have a namespace, so we decided to require nulls for ids. Now that we require explicit specification of a namespace, we can safely use the logic above to pluck off the id from the other end. Ps: I'm not sure the above story is true, but I think it makes sense :) |
That was going to be my approach as well, just if keyPath.length % 2 === 1 ---> inject null |
Backward compatibility fail: |
... In theory we could support it if we check if arguments.length > 1 |
Yeah, as long as we bump the major. But either way, semver grants us free reign to do whatever pre-1.0. |
While we are still pre a major release, I vote to rid it instead of supporting it forever. |
Can you remove that line? While it's informative for us, it's probably not relevant to the doc reader. |
The line above it states that name='Google' so I thought I should clarify. Also in the docs it says:
|
But I'll remove it. |
I actually like it now. I didn't notice the difference in your example explaining name= vs id=. Makes sense to keep it 👍 |
So we support: var key = ds.key('world');
// or
var key = ds.key(['world']);
// or
var key = ds.key({
path: ['world']
}); Should we support: var key = ds.key({
path: 'world'
}); ? |
I think yes unless there's any objections. |
I do see how if we support a string in one place, we should support it in another. However, I think we can get away with requiring an array there, because an object is the explicit specification format. We should expect them to conform to the schema, where a namespace is a string, and a path is an array. I wanted to allow Just my opinion. |
Yeah, we should probably be more explicit with the values we accept. I agree with you. We can document it as: var key = ds.key(kind); // kind is a string e.g. 'Company'
// or
var key = ds.key(path); // path is an array e.g. ['Company'] or ['Company', 123]
// or
var key = ds.key({
namespace: namespace,
path: path
}); |
So, I actually didn't need to do much in order to support this. It seems there was only a check making sure that we didn't pass in less than two values for the path. I just changed it to make sure we were passing in at least 1 value for the path. Updated the docs and tests to reflect this change. |
it('should throw if key contains less than 2 items', function() { | ||
assert.throws(function() { | ||
entity.keyToKeyProto(['Kind']); | ||
it('should not throw if key contains less than 2 items', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [sinon](https://sinonjs.org/) ([source](https://togithub.com/sinonjs/sinon)) | [`^13.0.0` -> `^14.0.0`](https://renovatebot.com/diffs/npm/sinon/13.0.2/14.0.0) | [![age](https://badges.renovateapi.com/packages/npm/sinon/14.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/sinon/14.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/sinon/14.0.0/compatibility-slim/13.0.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/sinon/14.0.0/confidence-slim/13.0.2)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>sinonjs/sinon</summary> ### [`v14.0.0`](https://togithub.com/sinonjs/sinon/blob/HEAD/CHANGES.md#​1400) [Compare Source](https://togithub.com/sinonjs/sinon/compare/v13.0.2...v14.0.0) - [`c2bbd826`](https://togithub.com/sinonjs/sinon/commit/c2bbd82641444eb5b32822489ae40f185afbbf00) Drop node 12 (Morgan Roderick) > And embrace Node 18 > > See https://nodejs.org/en/about/releases/ *Released by Morgan Roderick on 2022-05-07.* </details> --- ### Configuration 📅 **Schedule**: "after 9am and before 3pm" (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-analytics-data).
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/041f5df7-f5d3-4b2a-9ede-0752bf41c185/targets
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 392067151 Source-Link: googleapis/googleapis@06345f7 Source-Link: googleapis/googleapis-gen@95882b3
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jsdoc](https://togithub.com/jsdoc/jsdoc) | [`^3.6.5` -> `^4.0.0`](https://renovatebot.com/diffs/npm/jsdoc/3.6.11/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/compatibility-slim/3.6.11)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jsdoc/4.0.0/confidence-slim/3.6.11)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>jsdoc/jsdoc</summary> ### [`v4.0.0`](https://togithub.com/jsdoc/jsdoc/blob/HEAD/CHANGES.md#​400-November-2022) [Compare Source](https://togithub.com/jsdoc/jsdoc/compare/3.6.11...084218523a7d69fec14a852ce680f374f526af28) - JSDoc releases now use [semantic versioning](https://semver.org/). If JSDoc makes backwards-incompatible changes in the future, the major version will be incremented. - JSDoc no longer uses the [`taffydb`](https://taffydb.com/) package. If your JSDoc template or plugin uses the `taffydb` package, see the [instructions for replacing `taffydb` with `@jsdoc/salty`](https://togithub.com/jsdoc/jsdoc/tree/main/packages/jsdoc-salty#use-salty-in-a-jsdoc-template). - JSDoc now supports Node.js 12.0.0 and later. </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-security-private-ca). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzQuMTcuMSJ9-->
* feat: add BigQuery Storage Write API v1 Committer: @yirutang PiperOrigin-RevId: 397350004 Source-Link: googleapis/googleapis@b4da4fd Source-Link: googleapis/googleapis-gen@67bcfcf Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjdiY2ZjZmEwMGE0MTEzZTk2OGJhYzFhMTBkMGFkMGMxYjdkYzQ1YiJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: fix system tests 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\* --- ## [2.7.0](https://www.github.com/googleapis/nodejs-bigquery-storage/compare/v2.6.2...v2.7.0) (2021-09-27) ### Features * add BigQuery Storage Write API v1 ([#209](https://www.github.com/googleapis/nodejs-bigquery-storage/issues/209)) ([e0401d9](https://www.github.com/googleapis/nodejs-bigquery-storage/commit/e0401d96480cd192a2fad8075884d2a8abd417ca)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jsdoc-region-tag](https://togithub.com/googleapis/jsdoc-region-tag) | [`^1.0.4` -> `^2.0.0`](https://renovatebot.com/diffs/npm/jsdoc-region-tag/1.3.1/2.0.0) | [![age](https://badges.renovateapi.com/packages/npm/jsdoc-region-tag/2.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jsdoc-region-tag/2.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jsdoc-region-tag/2.0.0/compatibility-slim/1.3.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jsdoc-region-tag/2.0.0/confidence-slim/1.3.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/jsdoc-region-tag</summary> ### [`v2.0.0`](https://togithub.com/googleapis/jsdoc-region-tag/blob/HEAD/CHANGELOG.md#​200-httpsgithubcomgoogleapisjsdoc-region-tagcomparev131v200-2022-05-20) [Compare Source](https://togithub.com/googleapis/jsdoc-region-tag/compare/v1.3.1...v2.0.0) ##### ⚠ BREAKING CHANGES - update library to use Node 12 ([#​107](https://togithub.com/googleapis/jsdoc-region-tag/issues/107)) ##### Build System - update library to use Node 12 ([#​107](https://togithub.com/googleapis/jsdoc-region-tag/issues/107)) ([5b51796](https://togithub.com/googleapis/jsdoc-region-tag/commit/5b51796771984cf8b978990025f14faa03c19923)) ##### [1.3.1](https://www.github.com/googleapis/jsdoc-region-tag/compare/v1.3.0...v1.3.1) (2021-08-11) ##### Bug Fixes - **build:** migrate to using main branch ([#​79](https://www.togithub.com/googleapis/jsdoc-region-tag/issues/79)) ([5050615](https://www.github.com/googleapis/jsdoc-region-tag/commit/50506150b7758592df5e389c6a5c3d82b3b20881)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-analytics-admin).
* docs(samples): add LRO code snippets * lint fix * lint fix * lint fix * 🦉 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>
…ncy versions (#209) Source-Author: Megan Potter <57276408+feywind@users.noreply.github.com> Source-Date: Fri Sep 11 18:47:00 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: fdd03c161003ab97657cc0218f25c82c89ddf4b6 Source-Link: googleapis/synthtool@fdd03c1
…ncy versions (#209) This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/28f926df-4479-489a-b60f-ecf7782e1eb7/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@fdd03c1
There were no docs at all for Dataset.key() so I added some here. They are not perfect though because the weird param structure used for the function.
Currently the params are something like either:
object
string
array
or
Issues:
@paramset
: what is suggested here)this.namespace
exists or manually provide it, or I can useFunction.apply
to apply the array to the function as arguments (yikes!)Proposal (not implemented here):
Just accept an object, specifying path. It's not hard to understand, document and requires only 9 characters extra for the developer to surround their old arguments for this new method:
.key({ path: [ <old arguments> ] })
object
false
string
true
(usethis.namespace
if not provided)array
false