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

Dataset.key() docs + proposal for simpler API #209

Merged
merged 1 commit into from
Sep 17, 2014
Merged

Dataset.key() docs + proposal for simpler API #209

merged 1 commit into from
Sep 17, 2014

Conversation

ryanseys
Copy link
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

@ryanseys ryanseys changed the title Entity.key() docs + proposal for simpler API Dataset.key() docs + proposal for simpler API Sep 13, 2014
@stephenplusplus
Copy link
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.

@ryanseys
Copy link
Contributor Author

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

@ryanseys
Copy link
Contributor Author

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

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

@stephenplusplus
Copy link
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?

@ryanseys
Copy link
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)

}
return new entity.Key(keyConfig);
Dataset.prototype.key = function(options) {
options = util.is(options, 'object') ? options : {

This comment was marked as spam.

@ryanseys
Copy link
Contributor Author

PTAL

@stephenplusplus
Copy link
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.

@ryanseys
Copy link
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.

@stephenplusplus
Copy link
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 :)

@ryanseys
Copy link
Contributor Author

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

@ryanseys
Copy link
Contributor Author

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

@ryanseys
Copy link
Contributor Author

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

@stephenplusplus
Copy link
Contributor

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

@stephenplusplus
Copy link
Contributor

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

@stephenplusplus
Copy link
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.

@ryanseys
Copy link
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

@ryanseys
Copy link
Contributor Author

But I'll remove it.

@stephenplusplus
Copy link
Contributor

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

@ryanseys
Copy link
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'
});

?

@ryanseys
Copy link
Contributor Author

I think yes unless there's any objections.

@stephenplusplus
Copy link
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.

@ryanseys
Copy link
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
});

@ryanseys
Copy link
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.

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.

sofisl pushed a commit that referenced this pull request Nov 11, 2022
[![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://github.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://github.com/sinonjs/sinon/blob/HEAD/CHANGES.md#&#8203;1400)

[Compare Source](https://github.com/sinonjs/sinon/compare/v13.0.2...v14.0.0)

-   [`c2bbd826`](https://github.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).
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Nov 11, 2022
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 392067151

Source-Link: googleapis/googleapis@06345f7

Source-Link: googleapis/googleapis-gen@95882b3
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Nov 11, 2022
[![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://github.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://github.com/jsdoc/jsdoc/blob/HEAD/CHANGES.md#&#8203;400-November-2022)

[Compare Source](https://github.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://github.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-->
sofisl pushed a commit that referenced this pull request Nov 11, 2022
* 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>
sofisl pushed a commit that referenced this pull request Nov 11, 2022
[![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://github.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://github.com/googleapis/jsdoc-region-tag/blob/HEAD/CHANGELOG.md#&#8203;200-httpsgithubcomgoogleapisjsdoc-region-tagcomparev131v200-2022-05-20)

[Compare Source](https://github.com/googleapis/jsdoc-region-tag/compare/v1.3.1...v2.0.0)

##### ⚠ BREAKING CHANGES

-   update library to use Node 12 ([#&#8203;107](https://github.com/googleapis/jsdoc-region-tag/issues/107))

##### Build System

-   update library to use Node 12 ([#&#8203;107](https://github.com/googleapis/jsdoc-region-tag/issues/107)) ([5b51796](https://github.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 ([#&#8203;79](https://www.github.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).
sofisl pushed a commit that referenced this pull request Nov 11, 2022
* 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>
sofisl pushed a commit that referenced this pull request Nov 16, 2022
…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
sofisl pushed a commit that referenced this pull request Nov 18, 2022
sofisl pushed a commit that referenced this pull request Nov 30, 2022
…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
sofisl pushed a commit that referenced this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants