Skip to content

Commit

Permalink
fix(Typings): Allow empty Datastore Entities in `IDstoreEntryWithoutK…
Browse files Browse the repository at this point in the history
…ey`.

BREAKING CHANGE: Cascading Change to typings.
  • Loading branch information
mdornseif committed Dec 15, 2023
1 parent 2789ec1 commit 763cdaa
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lib/dstore-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* dstore.ts - Datastore Compatibility layer
* Try to get a smoother api for transactions and such.
* A little bit inspired by the Python2 ndb interface.
* But without the ORM bits.
*
* In future https://github.com/graphql/dataloader might be used for batching.
*
Expand Down Expand Up @@ -77,27 +78,25 @@ export type DstorePropertyValues =

export interface IDstoreEntryWithoutKey {
/** All User Data stored in the Datastore */
[key: string]: DstorePropertyValues;
[key: string]?: DstorePropertyValues;
}

/** Represents what is actually stored inside the Datastore, called "Entity" by Google
[@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore#readme) adds `[Datastore.KEY]`. Using ES6 Symbols presents all kinds of hurdles, especially when you try to serialize into a cache. So we add the property _keyStr which contains the encoded key. It is automatically used to reconstruct `[Datastore.KEY]`, if you use [[Dstore.readKey]].
*/
export interface IDstoreEntry extends IDstoreEntryWithoutKey {
/* Datastore key provided by [@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore#readme) */
/* Datastore Key provided by [@google-cloud/datastore](https://github.com/googleapis/nodejs-datastore#readme) */
readonly [Datastore.KEY]?: Key;
/** [Datastore.KEY] key */
_keyStr: string;
/** All User Data stored in the Datastore */
[key: string]: DstorePropertyValues;
}

/** Represents the thing you pass to the save method. Also called "Entity" by Google */
export type DstoreSaveEntity = {
key: Key;
data: Omit<IDstoreEntry, '_keyStr' | Datastore['KEY']> &
Partial<{
_keyStr: string;
_keyStr: string|undefined;
[Datastore.KEY]: Key;
}>;
method?: 'insert' | 'update' | 'upsert';
Expand Down

0 comments on commit 763cdaa

Please sign in to comment.