-
Notifications
You must be signed in to change notification settings - Fork 107
feat: Add datastore mode data transforms #1369
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
base: main
Are you sure you want to change the base?
Conversation
…into 404540305-datastore-mode-data-transforms
LGTM ! |
export type PropertyTransform = { | ||
property: string; | ||
setToServerValue: boolean; | ||
increment: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these have to be any?
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Entity = any; | ||
// TODO: Call out this interface change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this TODO here for?
import IValue = google.datastore.v1.IValue; | ||
import ServerValue = google.datastore.v1.PropertyTransform.ServerValue; | ||
|
||
export function buildPropertyTransforms(transforms: PropertyTransform[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this would benefit from some comments
@@ -3295,6 +3296,221 @@ async.each( | |||
assert.strictEqual(entity, undefined); | |||
}); | |||
}); | |||
describe('Datastore mode data transforms', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this single test really cover the whole feature? (I dont see anything with setToServerValue: false
for example. And aren't non-int values supported?)
Summary:
This PR adds support for datastore mode data transforms. A new option is provided for the first argument in the
save
method and code is added that will build the entity proto so that the backend receives requests that will do Datastore Mode data transforms.API change
Here is an example of a call that the user can now make with the
save
method. They can now providetransforms
that will do data transforms for acommit
operation:Notes about the API surface:
maximum
,minimum
,increment
,setToServerValue
are encoded togoogle.datastore.v1.IValue
so they can representany
value sincegoogle.datastore.v1.IValue
is an encoded version of any value type. Likewise,appendMissingElements
andremoveAllFromArray
can accept any array ofany
values since they are encoded into thegoogle.datastore.v1.IArrayValue
type.Alternatives:
We could support an API where transforms are indexed by the property:
Pros:
Cons:
Changes:
src/entity.ts
: These are just interface changes. Technically they would affect users that currently supply atransform
property, but I doubt any users currently use atransform
property. We could remove this file and the PR would still be good.src/index.ts
: The save method is modified to attach propertyTransforms to the entity protosrc/utils/entity/buildPropertyTransforms.ts
: This file is added to build the propertyTransforms from the user'stransforms
array.system-test/datastore
: A test is added that performs asave
operation with transforms and ensures the encoded entity proto is correct, the transforms returned are correct and the backend data after the update is correct.Next Steps:
We should add support for users that wish to do transforms with transactions.
Requests for the reviewer:
src/entity.ts
file.