GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Dataset.key() docs + proposal for simpler API by ryanseys · Pull Request #209 · googleapis/google-cloud-node

Conversation

@ryanseys

@ryanseys ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

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:

Name Type
options object
options.namespace string
options.path array

or

Name Type
path any type, passed in as arguments list

Issues:

  1. That's really hard to document... I don't even know how to do it here, let alone in valid JSDoc (don't think it's possible, think you need something like a @paramset: what is suggested here)
  2. That's really hard to understand, even if documented.
  3. If I have a path array, only option I have is use the first option and know that this.namespace exists or manually provide it, or I can use Function.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> ] })

Name Type Optional
options object false
options.namespace string true (use this.namespace if not provided)
options.path array false

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ryanseys ryanseys changed the title Entity.key() docs + proposal for simpler API Dataset.key() docs + proposal for simpler API Sep 13, 2014
@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

Can you change the named parameter to options as well? It is still keyConfig.

Here's an example of how we can document our current structure:

screen shot 2014-09-13 at 1 41 18 pm

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 key, but it can be of three types:

// 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

Yeah, I think that'll give us a good compromise. I'll work on making that happen.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

PTAL. This should change .key('kind', id) to .key(['kind', id]).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ryanseys
ryanseys reviewed Sep 13, 2014
View reviewed changes
Comment thread lib/datastore/dataset.js Outdated

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

Agh! Good call, I found an issue. toArray() should be arrayize().

Question now though, is: dataset.key('Company'); an incomplete key equivalent to dataset.key(['Company', null]);? (From your proposal)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ryanseys
ryanseys reviewed Sep 13, 2014
View reviewed changes
Comment thread lib/datastore/dataset.js

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

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 :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

That was going to be my approach as well, just if keyPath.length % 2 === 1 ---> inject null

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

Backward compatibility fail: ds.key('Kind', 123) will now result in an incomplete key. Is this okay?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

... In theory we could support it if we check if arguments.length > 1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

Yeah, as long as we bump the major. But either way, semver grants us free reign to do whatever pre-1.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

While we are still pre a major release, I vote to rid it instead of supporting it forever.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor
  • * // Note: id is used for numeric identifiers and name is used otherwise

Can you remove that line? While it's informative for us, it's probably not relevant to the doc reader.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

The line above it states that name='Google' so I thought I should clarify. Also in the docs it says:

  • An identifier for the individual entity, which can be either
    • a key name string
    • an integer numeric ID
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

But I'll remove it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

I actually like it now. I didn't notice the difference in your example explaining name= vs id=. Makes sense to keep it 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

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'
});

?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

I think yes unless there's any objections.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 13, 2014

Copy link
Copy Markdown
Contributor

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 ds.key('world') as a shorthand, so that we didn't force the user to make an array for a single item as the only argument passed to our function. ds.key(['world']) feels like a quirk of our API that the user shouldn't have to worry about.

Just my opinion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

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
});
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 13, 2014

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ryanseys
ryanseys reviewed Sep 13, 2014
View reviewed changes
Comment thread test/datastore/entity.js Outdated

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

GautamSharda pushed a commit that referenced this pull request Feb 25, 2026
@gcf-owl-bot Takashi Matsuo
feat: add BigQuery Storage Write API v1 (#209)
f670c35
* 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 <[email protected]>
GautamSharda pushed a commit that referenced this pull request Feb 25, 2026
@release-please
chore: release 2.7.0 (#214)
21b3c0e
🤖 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).
@GautamSharda GautamSharda mentioned this pull request Feb 25, 2026
migrate code from googleapis/nodejs-bigquery-storage #7306
Closed
4 tasks
GautamSharda pushed a commit that referenced this pull request Feb 26, 2026
@JustinBeckwith @alexander-fenster
Enable no-var in eslint (#209)
4fb702c
@GautamSharda GautamSharda mentioned this pull request Feb 26, 2026
migrate code from googleapis/nodejs-error-reporting #7308
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Feb 26, 2026
@JustinBeckwith
chore(package): update nyc to version 12.0.2 (#210)
529d37d
Closes #209
This was referenced Feb 26, 2026
migrate code from googleapis/nodejs-firestore #7311
Closed
migrate code from googleapis/nodejs-firestore #7410
Merged
@GautamSharda GautamSharda mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-bigquery-storage #7496
Merged
4 tasks
codyoss pushed a commit that referenced this pull request Mar 5, 2026
@yoshi-automation @sofisl
build: rename _toc to toc (#209)
9c4d5c7
Source-Author: F. Hinkelmann <[email protected]>
Source-Date: Tue Jul 21 10:53:20 2020 -0400
Source-Repo: googleapis/synthtool
Source-Sha: 99c93fe09f8c1dca09dfc0301c8668e3a70dd796
Source-Link: googleapis/synthtool@99c93fe

Co-authored-by: sofisl <[email protected]>
@codyoss codyoss mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-projectify #7511
Merged
GautamSharda pushed a commit that referenced this pull request Mar 5, 2026
@JustinBeckwith
Release v3.0.2 (#209)
8c22280
@GautamSharda GautamSharda mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-logging #7514
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Mar 5, 2026
Renovate Bot @JustinBeckwith
chore(deps): update linters (#209)
1e1b167
sofisl pushed a commit that referenced this pull request Mar 5, 2026
@yoshi-automation
build(node): add KOKORO_BUILD_ARTIFACTS_SUBDIR to env (#209)
6be3b76
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/0d0efc4e-9ccd-472b-a303-4bbf020fc2e0/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@ba9918c
@meltsufin meltsufin mentioned this pull request Mar 10, 2026
chore: migrate code from googleapis/nodejs-logging #7550
Merged
GautamSharda pushed a commit that referenced this pull request Mar 11, 2026
@JustinBeckwith @alexander-fenster
chore: do not use npm ci (#209)
99ad48f
This was referenced Mar 11, 2026
migrate code from googleapis/nodejs-pubsub #7592
Merged
migrate code from googleapis/nodejs-promisify #7595
Closed
GautamSharda pushed a commit that referenced this pull request Mar 12, 2026
@yoshi-automation
build: typeo in nodejs .gitattribute (#209)
b83e56a
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/cc99acfa-05b8-434b-9500-2f6faf2eaa02/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@799d8e6
@GautamSharda GautamSharda mentioned this pull request Mar 12, 2026
migrate code from googleapis/nodejs-promisify #7596
Merged
4 tasks
GautamSharda pushed a commit that referenced this pull request Mar 12, 2026
@yoshi-automation
build: typeo in nodejs .gitattribute (#209)
f46c5dd
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/cc99acfa-05b8-434b-9500-2f6faf2eaa02/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@799d8e6
GautamSharda pushed a commit that referenced this pull request Mar 12, 2026
@JustinBeckwith
chore: remove dead code and packages (#209)
03703a6
@GautamSharda GautamSharda mentioned this pull request Mar 12, 2026
migrate code from googleapis/nodejs-common #7597
Merged
4 tasks
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request Mar 18, 2026
@billyjacobson
Kms sample (googleapis#209)
11c4fc5
* Add KMS to bucket

* Using environment variables to load the KMS key
Adding example for uploading file with KMS kˆey

* Added todo for developer for the defaultKmsKeyName

* Generating README and other scaffolding

* Running prettier

* Fixed typo. Added help text for bucket example.

* Adding a .mailmap file
GautamSharda pushed a commit that referenced this pull request Mar 23, 2026
@vijay-qlogic @sduskis
typo fix for apidoc comment (#209)
91e29ed
@GautamSharda GautamSharda mentioned this pull request Mar 23, 2026
migrate code from googleapis/nodejs-bigtable #7852
Merged
4 tasks
GautamSharda pushed a commit that referenced this pull request Mar 25, 2026
@vijay-qlogic @GautamSharda
typo fix for apidoc comment (#209)
20a6d8c
shivanee-p pushed a commit that referenced this pull request Mar 27, 2026
@vijay-qlogic @shivanee-p
typo fix for apidoc comment (#209)
e9cff2a
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request May 5, 2026
@vijay-qlogic @thiyaguk09
typo fix for apidoc comment (googleapis#209)
f5d2a80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ryanseys @stephenplusplus @silvolu @pcostell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.