diff --git a/src/datastore.db.ts b/src/datastore.db.ts index 1fad91d..6b34056 100644 --- a/src/datastore.db.ts +++ b/src/datastore.db.ts @@ -16,7 +16,6 @@ import { CommonDBTransactionOptions, } from '@naturalcycles/db-lib' import { - ObjectWithId, JsonSchemaAny, JsonSchemaBoolean, JsonSchemaNull, @@ -34,6 +33,9 @@ import { pRetryFn, pRetry, PRetryOptions, + PartialObjectWithId, + Saved, + ObjectWithId, } from '@naturalcycles/js-lib' import { ReadableTyped, boldWhite } from '@naturalcycles/nodejs-lib' import { DatastoreStreamReadable } from './DatastoreStreamReadable' @@ -133,11 +135,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { await this.getAllStats() } - override async getByIds( + override async getByIds( table: string, ids: string[], opt: DatastoreDBOptions = {}, - ): Promise { + ): Promise[]> { if (!ids.length) return [] const keys = ids.map(id => this.key(table, id)) let rows: any[] @@ -187,7 +189,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return ( rows - .map(r => this.mapId(r)) + .map(r => this.mapId>(r)) // Seems like datastore .get() method doesn't return items properly sorted by input ids, so we gonna sort them here // same ids are not expected here .sort((a, b) => (a.id > b.id ? 1 : -1)) @@ -199,10 +201,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { // return q.kinds[0]! // } - override async runQuery( + override async runQuery( dbQuery: DBQuery, _opt?: DatastoreDBOptions, - ): Promise> { + ): Promise>> { const idFilter = dbQuery._filters.find(f => f.name === 'id') if (idFilter) { const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val @@ -223,7 +225,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return qr } - override async runQueryCount( + override async runQueryCount( dbQuery: DBQuery, _opt?: DatastoreDBOptions, ): Promise { @@ -232,10 +234,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return entities.length } - async runDatastoreQuery(q: Query): Promise> { + async runDatastoreQuery( + q: Query, + ): Promise>> { const [entities, queryResult] = await this.ds().runQuery(q) - const rows = entities.map(e => this.mapId(e)) + const rows = entities.map(e => this.mapId>(e)) return { ...queryResult, @@ -243,7 +247,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { } } - private runQueryStream( + private runQueryStream( q: Query, _opt?: DatastoreDBStreamOptions, ): ReadableTyped { @@ -274,7 +278,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return stream } - override streamQuery( + override streamQuery( dbQuery: DBQuery, opt?: DatastoreDBStreamOptions, ): ReadableTyped { @@ -287,7 +291,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { /** * Returns saved entities with generated id/updated/created (non-mutating!) */ - override async saveBatch>( + override async saveBatch( table: string, rows: ROW[], opt: DatastoreDBSaveOptions = {}, @@ -324,7 +328,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { } } - override async deleteByQuery( + override async deleteByQuery( q: DBQuery, opt?: DatastoreDBOptions, ): Promise { @@ -458,7 +462,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return id?.toString() } - override async createTable( + override async createTable( _table: string, _schema: JsonSchemaObject, ): Promise {} @@ -469,7 +473,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { return statsArray.map(stats => stats.kind_name).filter(table => table && !table.startsWith('_')) } - override async getTableSchema( + override async getTableSchema( table: string, ): Promise> { const stats = await this.getTableProperties(table) @@ -572,7 +576,7 @@ export class DatastoreDBTransaction implements DBTransaction { } } - async getByIds( + async getByIds( table: string, ids: string[], opt?: CommonDBOptions | undefined, @@ -580,7 +584,7 @@ export class DatastoreDBTransaction implements DBTransaction { return await this.db.getByIds(table, ids, { ...opt, tx: this }) } - async saveBatch>( + async saveBatch( table: string, rows: ROW[], opt?: CommonDBSaveOptions | undefined, diff --git a/src/query.util.ts b/src/query.util.ts index 2acab3f..483aed2 100644 --- a/src/query.util.ts +++ b/src/query.util.ts @@ -1,6 +1,6 @@ import { PropertyFilter, Query } from '@google-cloud/datastore' import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib' -import { ObjectWithId, StringMap } from '@naturalcycles/js-lib' +import { PartialObjectWithId, StringMap } from '@naturalcycles/js-lib' const FNAME_MAP: StringMap = { id: '__key__', @@ -12,7 +12,7 @@ const OP_MAP: Partial> = { 'not-in': 'NOT_IN', } -export function dbQueryToDatastoreQuery( +export function dbQueryToDatastoreQuery( dbQuery: Readonly>, emptyQuery: Query, ): Query { diff --git a/yarn.lock b/yarn.lock index c048da2..1465899 100644 --- a/yarn.lock +++ b/yarn.lock @@ -836,9 +836,9 @@ typescript "^5.0.2" "@naturalcycles/db-lib@^9.0.0": - version "9.2.0" - resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.2.0.tgz#48bbaec6ca19004569b017d68f9ce5b7bb0bd3c4" - integrity sha512-/XGmq9qN+LVX+a0BIeAb+BeqzdisZj0x5SYWrbIfhcqb7h671vv7yeexMDw9V5jehMXIcrUpXRFiUszjJ0Uqng== + version "9.3.0" + resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.3.0.tgz#d6727ff62b4150f26e83e3b68e5ca975229f154d" + integrity sha512-wcPFWmQ+jXtdXrSqPuXHnkzw4UjwvJUhtIIWFxLdsaoEFnA8peSsdpH+E5QIU7EDjXfQmYQ6nhcacmWQ6NvM+Q== dependencies: "@naturalcycles/js-lib" "^14.116.0" "@naturalcycles/nodejs-lib" "^13.1.1" @@ -879,9 +879,9 @@ yargs "^17.0.0" "@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.116.0": - version "14.201.1" - resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.201.1.tgz#67d7b74be557385736b489c4ab6f318cf8d093cf" - integrity sha512-NAxPDWxNiFs8Eidj4vt0jcRyvLJ2MuHmPuryIETvKRLfdQ3j14XfZbvCtNMfmX1Yfl0an0xE5fKN2yzKKJk0LQ== + version "14.204.1" + resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.204.1.tgz#d81838e4a8cd889b734637c2b26a750d5758ef10" + integrity sha512-+2E30+MKFdlxnkbsBHBcbi8aTTPl3AZRe+NUzgimJoJw+7wJS0k6v2DVbrmQ1MCcEyQ4gV5jhOQT8iHEtDDSDw== dependencies: tslib "^2.0.0" zod "^3.20.2" @@ -2173,9 +2173,9 @@ ecdsa-sig-formatter@1.0.11, ecdsa-sig-formatter@^1.0.11: safe-buffer "^5.0.1" electron-to-chromium@^1.4.601: - version "1.4.637" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.637.tgz#ed8775cf5e0c380c3e8452e9818a0e4b7a671ac4" - integrity sha512-G7j3UCOukFtxVO1vWrPQUoDk3kL70mtvjc/DC/k2o7lE0wAdq+Vwp1ipagOow+BH0uVztFysLWbkM/RTIrbK3w== + version "1.4.639" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.639.tgz#c6f9cc685f9efb2980d2cfc95a27f8142c9adf28" + integrity sha512-CkKf3ZUVZchr+zDpAlNLEEy2NJJ9T64ULWaDgy3THXXlPVPkLu3VOs9Bac44nebVtdwl2geSj6AxTtGDOxoXhg== emittery@^0.13.1: version "0.13.1"