Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 19, 2024
1 parent 00b821c commit 63e478b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
38 changes: 21 additions & 17 deletions src/datastore.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
CommonDBTransactionOptions,
} from '@naturalcycles/db-lib'
import {
ObjectWithId,
JsonSchemaAny,
JsonSchemaBoolean,
JsonSchemaNull,
Expand All @@ -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'
Expand Down Expand Up @@ -133,11 +135,11 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
await this.getAllStats()
}

override async getByIds<ROW extends ObjectWithId>(
override async getByIds<ROW extends PartialObjectWithId>(
table: string,
ids: string[],
opt: DatastoreDBOptions = {},
): Promise<ROW[]> {
): Promise<Saved<ROW>[]> {
if (!ids.length) return []
const keys = ids.map(id => this.key(table, id))
let rows: any[]
Expand Down Expand Up @@ -187,7 +189,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {

return (
rows
.map(r => this.mapId<ROW>(r))
.map(r => this.mapId<Saved<ROW>>(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))
Expand All @@ -199,10 +201,10 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
// return q.kinds[0]!
// }

override async runQuery<ROW extends ObjectWithId>(
override async runQuery<ROW extends PartialObjectWithId>(
dbQuery: DBQuery<ROW>,
_opt?: DatastoreDBOptions,
): Promise<RunQueryResult<ROW>> {
): Promise<RunQueryResult<Saved<ROW>>> {
const idFilter = dbQuery._filters.find(f => f.name === 'id')
if (idFilter) {
const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val
Expand All @@ -223,7 +225,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
return qr
}

override async runQueryCount<ROW extends ObjectWithId>(
override async runQueryCount<ROW extends PartialObjectWithId>(
dbQuery: DBQuery<ROW>,
_opt?: DatastoreDBOptions,
): Promise<number> {
Expand All @@ -232,18 +234,20 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
return entities.length
}

async runDatastoreQuery<ROW extends ObjectWithId>(q: Query): Promise<RunQueryResult<ROW>> {
async runDatastoreQuery<ROW extends PartialObjectWithId>(
q: Query,
): Promise<RunQueryResult<Saved<ROW>>> {
const [entities, queryResult] = await this.ds().runQuery(q)

const rows = entities.map(e => this.mapId<ROW>(e))
const rows = entities.map(e => this.mapId<Saved<ROW>>(e))

return {
...queryResult,
rows,
}
}

private runQueryStream<ROW extends ObjectWithId>(
private runQueryStream<ROW extends PartialObjectWithId>(
q: Query,
_opt?: DatastoreDBStreamOptions,
): ReadableTyped<ROW> {
Expand Down Expand Up @@ -274,7 +278,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
return stream
}

override streamQuery<ROW extends ObjectWithId>(
override streamQuery<ROW extends PartialObjectWithId>(
dbQuery: DBQuery<ROW>,
opt?: DatastoreDBStreamOptions,
): ReadableTyped<ROW> {
Expand All @@ -287,7 +291,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
/**
* Returns saved entities with generated id/updated/created (non-mutating!)
*/
override async saveBatch<ROW extends Partial<ObjectWithId>>(
override async saveBatch<ROW extends PartialObjectWithId>(
table: string,
rows: ROW[],
opt: DatastoreDBSaveOptions<ROW> = {},
Expand Down Expand Up @@ -324,7 +328,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
}
}

override async deleteByQuery<ROW extends ObjectWithId>(
override async deleteByQuery<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt?: DatastoreDBOptions,
): Promise<number> {
Expand Down Expand Up @@ -458,7 +462,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
return id?.toString()
}

override async createTable<ROW extends ObjectWithId>(
override async createTable<ROW extends PartialObjectWithId>(
_table: string,
_schema: JsonSchemaObject<ROW>,
): Promise<void> {}
Expand All @@ -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<ROW extends ObjectWithId>(
override async getTableSchema<ROW extends PartialObjectWithId>(
table: string,
): Promise<JsonSchemaRootObject<ROW>> {
const stats = await this.getTableProperties(table)
Expand Down Expand Up @@ -572,15 +576,15 @@ export class DatastoreDBTransaction implements DBTransaction {
}
}

async getByIds<ROW extends ObjectWithId>(
async getByIds<ROW extends PartialObjectWithId>(
table: string,
ids: string[],
opt?: CommonDBOptions | undefined,
): Promise<ROW[]> {
return await this.db.getByIds(table, ids, { ...opt, tx: this })
}

async saveBatch<ROW extends Partial<ObjectWithId>>(
async saveBatch<ROW extends PartialObjectWithId>(
table: string,
rows: ROW[],
opt?: CommonDBSaveOptions<ROW> | undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/query.util.ts
Original file line number Diff line number Diff line change
@@ -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__',
Expand All @@ -12,7 +12,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
'not-in': 'NOT_IN',
}

export function dbQueryToDatastoreQuery<ROW extends ObjectWithId>(
export function dbQueryToDatastoreQuery<ROW extends PartialObjectWithId>(
dbQuery: Readonly<DBQuery<ROW>>,
emptyQuery: Query,
): Query {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -2173,9 +2173,9 @@ [email protected], 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"
Expand Down

0 comments on commit 63e478b

Please sign in to comment.