Skip to content

Commit

Permalink
feat!: do not automatically unwrap numbers for users, though allow th…
Browse files Browse the repository at this point in the history
…em to specify it
  • Loading branch information
crwilcox committed Dec 11, 2020
1 parent aa86a2f commit 1d80aea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export namespace entity {
*
* @private
* @param {object} valueProto The protobuf Value message to convert.
* @param {boolean | IntegerTypeCastOptions} [wrapNumbers=false] Wrap values of integerValue type in
* @param {boolean | IntegerTypeCastOptions} [wrapNumbers=true] Wrap values of integerValue type in
* {@link Datastore#Int} objects.
* If a `boolean`, this will wrap values in {@link Datastore#Int} objects.
* If an `object`, this will return a value returned by
Expand Down Expand Up @@ -523,10 +523,21 @@ export namespace entity {
}

case 'doubleValue': {
if (wrapNumbers === undefined) {
wrapNumbers = true;
}

if (wrapNumbers) {
return new entity.Double(value);
}
return Number(value);
}

case 'integerValue': {
if (wrapNumbers === undefined) {
wrapNumbers = true;
}

return wrapNumbers
? typeof wrapNumbers === 'object'
? new entity.Int(valueProto, wrapNumbers).valueOf()
Expand Down
2 changes: 1 addition & 1 deletion src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class Query {
* [here](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore).
* @param {object} [options.gaxOptions] Request configuration options, outlined
* here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
* @param {boolean | IntegerTypeCastOptions} [options.wrapNumbers=false]
* @param {boolean | IntegerTypeCastOptions} [options.wrapNumbers=True]
* Wrap values of integerValue type in {@link Datastore#Int} objects.
* If a `boolean`, this will wrap values in {@link Datastore#Int} objects.
* If an `object`, this will return a value returned by
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class DatastoreRequest {
* [here](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore).
* @param {object} [options.gaxOptions] Request configuration options, outlined
* here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
* @param {boolean | IntegerTypeCastOptions} [options.wrapNumbers=false]
* @param {boolean | IntegerTypeCastOptions} [options.wrapNumbers=true]
* Wrap values of integerValue type in {@link Datastore#Int} objects.
* If a `boolean`, this will wrap values in {@link Datastore#Int} objects.
* If an `object`, this will return a value returned by
Expand Down

0 comments on commit 1d80aea

Please sign in to comment.