@naturalcycles/datastore-lib 3.19.1 → 3.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
20
20
  protected KEY: symbol;
21
21
  ds(): Datastore;
22
22
  ping(): Promise<void>;
23
- getByIds<ROW extends ObjectWithId>(table: string, ids: string[], _opt?: DatastoreDBOptions): Promise<ROW[]>;
23
+ getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: DatastoreDBOptions): Promise<ROW[]>;
24
24
  getQueryKind(q: Query): string;
25
25
  runQuery<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<RunQueryResult<ROW>>;
26
26
  runQueryCount<ROW extends ObjectWithId>(dbQuery: DBQuery<ROW>, _opt?: DatastoreDBOptions): Promise<number>;
@@ -36,7 +36,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
36
36
  * Limitation: Datastore's delete returns void, so we always return all ids here as "deleted"
37
37
  * regardless if they were actually deleted or not.
38
38
  */
39
- deleteByIds(table: string, ids: string[], opt?: DatastoreDBOptions): Promise<number>;
39
+ deleteByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: DatastoreDBOptions): Promise<number>;
40
40
  /**
41
41
  * https://cloud.google.com/datastore/docs/concepts/transactions#datastore-datastore-transactional-update-nodejs
42
42
  */
@@ -50,9 +50,9 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
50
50
  getTableProperties(table: string): Promise<DatastorePropertyStats[]>;
51
51
  mapId<T = any>(o: any, preserveKey?: boolean): T;
52
52
  toDatastoreEntity<T = any>(kind: string, o: T & {
53
- id?: string;
53
+ id?: string | number;
54
54
  }, excludeFromIndexes?: string[]): DatastorePayload<T>;
55
- key(kind: string, id: string): Key;
55
+ key(kind: string, id: string | number): Key;
56
56
  getDsKey(o: any): Key | undefined;
57
57
  getKey(key: Key): string | undefined;
58
58
  getTables(): Promise<string[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.19.1",
3
+ "version": "3.19.2",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -111,7 +111,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
111
111
 
112
112
  override async getByIds<ROW extends ObjectWithId>(
113
113
  table: string,
114
- ids: string[],
114
+ ids: ROW['id'][],
115
115
  _opt?: DatastoreDBOptions,
116
116
  ): Promise<ROW[]> {
117
117
  if (!ids.length) return []
@@ -302,9 +302,9 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
302
302
  * Limitation: Datastore's delete returns void, so we always return all ids here as "deleted"
303
303
  * regardless if they were actually deleted or not.
304
304
  */
305
- override async deleteByIds(
305
+ override async deleteByIds<ROW extends ObjectWithId>(
306
306
  table: string,
307
- ids: string[],
307
+ ids: ROW['id'][],
308
308
  opt: DatastoreDBOptions = {},
309
309
  ): Promise<number> {
310
310
  const keys = ids.map(id => this.key(table, id))
@@ -386,7 +386,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
386
386
  // if key field exists on entity, it will be used as key (prevent to duplication of numeric keyed entities)
387
387
  toDatastoreEntity<T = any>(
388
388
  kind: string,
389
- o: T & { id?: string },
389
+ o: T & { id?: string | number },
390
390
  excludeFromIndexes: string[] = [],
391
391
  ): DatastorePayload<T> {
392
392
  const key = this.getDsKey(o) || this.key(kind, o.id!)
@@ -401,7 +401,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
401
401
  }
402
402
  }
403
403
 
404
- key(kind: string, id: string): Key {
404
+ key(kind: string, id: string | number): Key {
405
405
  _assert(id, `Cannot save "${kind}" entity without "id"`)
406
406
  return this.ds().key([kind, String(id)])
407
407
  }
@@ -50,7 +50,7 @@ export class DatastoreKeyValueDB implements CommonKeyValueDB {
50
50
  .limit(limit || 0)
51
51
 
52
52
  return this.db.streamQuery<KVObject>(q).pipe(
53
- transformMapSimple<ObjectWithId, string>(objectWithId => objectWithId.id, {
53
+ transformMapSimple<ObjectWithId<string>, string>(objectWithId => objectWithId.id, {
54
54
  errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
55
55
  }),
56
56
  )