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 8b24f4f commit 015be46
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
43 changes: 24 additions & 19 deletions src/airtableDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
pMap,
_by,
_omit,
AnyObjectWithId,
ObjectWithId,
_mapValues,
AnyObject,
PartialObjectWithId,
AnyPartialObjectWithId,
Saved,
ObjectWithId,
} from '@naturalcycles/js-lib'
import { _inspect, ReadableTyped } from '@naturalcycles/nodejs-lib'
import {
Expand Down Expand Up @@ -71,7 +73,7 @@ export interface AirtableDBOptions extends CommonDBOptions {
idField?: string
}
export type AirtableDBStreamOptions = CommonDBStreamOptions
export interface AirtableDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjectWithId>
export interface AirtableDBSaveOptions<ROW extends PartialObjectWithId = AnyPartialObjectWithId>
extends AirtableDBOptions,
CommonDBSaveOptions<ROW> {}

Expand Down Expand Up @@ -112,11 +114,11 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
// impossible to implement without having a baseId and a known Table name there
}

override async getByIds<ROW extends ObjectWithId>(
override async getByIds<ROW extends PartialObjectWithId>(
table: string,
ids: string[],
opt: AirtableDBOptions = {},
): Promise<ROW[]> {
): Promise<Saved<ROW>[]> {
if (!ids.length) return []

const { idField = 'id' } = opt
Expand Down Expand Up @@ -175,7 +177,7 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
/**
* Does "upsert" always
*/
override async saveBatch<ROW extends Partial<ObjectWithId>>(
override async saveBatch<ROW extends PartialObjectWithId>(
table: string,
rows: ROW[],
opt?: AirtableDBSaveOptions<ROW>,
Expand Down Expand Up @@ -205,10 +207,10 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
)
}

override async runQuery<ROW extends ObjectWithId>(
override async runQuery<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt: AirtableDBOptions = {},
): Promise<RunQueryResult<ROW>> {
): Promise<RunQueryResult<Saved<ROW>>> {
const selectOpts = dbQueryToAirtableSelectOptions<ROW>(q, opt)
// console.log({selectOpts})

Expand All @@ -225,20 +227,20 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
}
}

override async runQueryCount<ROW extends ObjectWithId>(
override async runQueryCount<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt?: AirtableDBOptions,
): Promise<number> {
return (await this.runQuery(q.select([]), opt)).rows.length
}

override async deleteByQuery<ROW extends ObjectWithId>(
override async deleteByQuery<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt?: AirtableDBOptions,
): Promise<number> {
const { rows } = await this.runQuery<ROW & AirtableRecord>(q.select([]), opt)

const tableApi = this.tableApi<ObjectWithId>(q.table)
const tableApi = this.tableApi<PartialObjectWithId>(q.table)

await pMap(
rows.map(r => r.airtableId),
Expand All @@ -256,10 +258,10 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
/**
* Streaming is emulated by just returning the results of the query as a stream.
*/
override streamQuery<ROW extends ObjectWithId>(
override streamQuery<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt?: AirtableDBStreamOptions,
): ReadableTyped<ROW> {
): ReadableTyped<Saved<ROW>> {
const readable = new Readable({
objectMode: true,
read() {},
Expand All @@ -273,7 +275,7 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
return readable
}

private tableApi<ROW extends ObjectWithId>(table: string): AirtableApiTable<ROW> {
private tableApi<ROW extends PartialObjectWithId>(table: string): AirtableApiTable<ROW> {
let { baseId } = this.cfg

if (!baseId) {
Expand All @@ -289,13 +291,13 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
return this.api.base(baseId)<ROW>(table)
}

private async queryAirtableRecords<ROW extends ObjectWithId>(
private async queryAirtableRecords<ROW extends PartialObjectWithId>(
table: string,
selectOpts: AirtableApiSelectOpts<ROW>,
opt: AirtableDBOptions,
q?: DBQuery<ROW>,
): Promise<ROW[]> {
const records = await this.tableApi<ROW>(table)
): Promise<Saved<ROW>[]> {
const records = await this.tableApi<Saved<ROW>>(table)
.select({
// defaults
pageSize: 100,
Expand Down Expand Up @@ -332,7 +334,10 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
return rows
}

async createRecord<ROW extends ObjectWithId>(table: string, record: Partial<ROW>): Promise<ROW> {
async createRecord<ROW extends PartialObjectWithId>(
table: string,
record: Partial<ROW>,
): Promise<ROW> {
// pre-save validation is skipped, cause we'll need to "omit" the `airtableId` from schema
const raw = await this.tableApi<ROW>(table)
.create(_omit(record, ['airtableId'] as any))
Expand All @@ -341,7 +346,7 @@ export class AirtableDB extends BaseCommonDB implements CommonDB {
return this.mapToAirtableRecord(raw)
}

private async updateRecord<ROW extends ObjectWithId>(
private async updateRecord<ROW extends PartialObjectWithId>(
table: string,
airtableId: string,
patch: Partial<ROW>,
Expand Down
4 changes: 2 additions & 2 deletions src/query.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
import { _uniq, ObjectWithId } from '@naturalcycles/js-lib'
import { _uniq, PartialObjectWithId } from '@naturalcycles/js-lib'
import { AirtableApiSelectOpts } from './airtable.api'
import { AirtableDBOptions } from './airtableDB'

Expand All @@ -10,7 +10,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
/**
* https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference
*/
export function dbQueryToAirtableSelectOptions<ROW extends ObjectWithId>(
export function dbQueryToAirtableSelectOptions<ROW extends PartialObjectWithId>(
q: DBQuery<ROW>,
opt: AirtableDBOptions,
): AirtableApiSelectOpts<ROW> {
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,9 @@
typescript "^5.0.2"

"@naturalcycles/db-lib@^9.1.0":
version "9.1.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.1.0.tgz#4c2d206301caeb67381713566d1945df91435a1f"
integrity sha512-qAJai7bRWY37+Wo/p8KyxaJ+d1UE2XIgIZoc8dcdYtB3XyEUjz3ZNNA4GeurgtxOBqeD5U0UxcOHbijJaHyzCg==
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 @@ -842,9 +842,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 @@ -1658,9 +1658,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001565:
version "1.0.30001578"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001578.tgz#11741580434ce60aae4b4a9abee9f9f8d7bf5be5"
integrity sha512-J/jkFgsQ3NEl4w2lCoM9ZPxrD+FoBNJ7uJUpGVjIg/j0OwJosWM36EPDv+Yyi0V4twBk9pPmlFS+PLykgEvUmg==
version "1.0.30001579"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz#45c065216110f46d6274311a4b3fcf6278e0852a"
integrity sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA==

[email protected]:
version "5.3.0"
Expand Down Expand Up @@ -2008,9 +2008,9 @@ [email protected]:
safe-buffer "^5.0.1"

electron-to-chromium@^1.4.601:
version "1.4.636"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.636.tgz#302cf4c3016d9d714ba246243a7c97b528e22fe7"
integrity sha512-NLE0GIy1OL9wRiKL20h9TkctBEYZuc99tquSS9MVdTahnuHputoETHeqDzgqGqyOY9NUH0g9wjfEuw5OD+wRcQ==
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 Expand Up @@ -3431,9 +3431,9 @@ jiti@^1.19.1:
integrity sha512-gFqAIbuKyyso/3G2qhiO2OM6shY6EPP/R0+mkDbyspxKazh8BXDC5FiFsUjlczgdNz/vfra0da2y+aHrusLG/Q==

joi@^17.9.2:
version "17.11.1"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.11.1.tgz#f42951137d25c27f61807502b0af71f7abb885ba"
integrity sha512-671acnrx+w96PCcQOzvm0VYQVwNL2PVgZmDRaFuSsx8sIUmGzYElPw5lU8F3Cr0jOuPs1oM56p7W2a1cdDOwcw==
version "17.12.0"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.12.0.tgz#a3fb5715f198beb0471cd551dd26792089c308d5"
integrity sha512-HSLsmSmXz+PV9PYoi3p7cgIbj06WnEBNT28n+bbBNcPZXZFqCzzvGqpTBPujx/Z0nh1+KNQPDrNgdmQ8dq0qYw==
dependencies:
"@hapi/hoek" "^9.3.0"
"@hapi/topo" "^5.1.0"
Expand Down

0 comments on commit 015be46

Please sign in to comment.