@naturalcycles/db-lib
Advanced tools
Comparing version 9.4.1 to 9.4.2
/// <reference types="node" /> | ||
import { Transform } from 'node:stream'; | ||
import { AnyObject, AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, Saved, UnixTimestampMillisNumber, UnsavedId, ZodSchema } from '@naturalcycles/js-lib'; | ||
import { AnyObject, AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, UnixTimestampMillisNumber, Unsaved, ZodSchema } from '@naturalcycles/js-lib'; | ||
import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib'; | ||
@@ -18,15 +18,15 @@ import { CommonDBTransactionOptions, DBModelType, DBPatch, DBTransaction, RunQueryResult } from '../db.model'; | ||
constructor(cfg: CommonDaoCfg<BM, DBM, TM>); | ||
create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>; | ||
create(part?: Partial<BM>, opt?: CommonDaoOptions): BM; | ||
getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>; | ||
getById(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>; | ||
getByIdOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<BM>>; | ||
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<DBM>>; | ||
getById(id?: string | null, opt?: CommonDaoOptions): Promise<BM | null>; | ||
getByIdOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<BM>; | ||
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM>; | ||
getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>; | ||
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<DBM> | null>; | ||
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<DBM | null>; | ||
getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>; | ||
getByIdAsTM(id?: string | null, opt?: CommonDaoOptions): Promise<TM | null>; | ||
getByIds(ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<Saved<DBM>[]>; | ||
requireById(id: string, opt?: CommonDaoOptions): Promise<Saved<BM>>; | ||
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<Saved<DBM>>; | ||
getByIds(ids: string[], opt?: CommonDaoOptions): Promise<BM[]>; | ||
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<DBM[]>; | ||
requireById(id: string, opt?: CommonDaoOptions): Promise<BM>; | ||
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<DBM>; | ||
private throwRequiredError; | ||
@@ -42,5 +42,5 @@ /** | ||
private ensureUniqueId; | ||
getBy(by: keyof DBM, value: any, limit?: number, opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<Saved<BM> | null>; | ||
getAll(opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
getBy(by: keyof DBM, value: any, limit?: number, opt?: CommonDaoOptions): Promise<BM[]>; | ||
getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<BM | null>; | ||
getAll(opt?: CommonDaoOptions): Promise<BM[]>; | ||
/** | ||
@@ -50,3 +50,3 @@ * Pass `table` to override table | ||
query(table?: string): RunnableDBQuery<BM, DBM, TM>; | ||
runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<BM[]>; | ||
runQuerySingleColumn<T = any>(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<T[]>; | ||
@@ -58,15 +58,15 @@ /** | ||
*/ | ||
runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
runQueryExtended(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>>; | ||
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<Saved<DBM>[]>; | ||
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<DBM>>>; | ||
runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<BM[]>; | ||
runQueryExtended(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<BM>>; | ||
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<DBM[]>; | ||
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>>; | ||
runQueryAsTM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<TM[]>; | ||
runQueryExtendedAsTM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<TM>>; | ||
runQueryCount(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<number>; | ||
streamQueryForEach(q: DBQuery<DBM>, mapper: AsyncMapper<Saved<BM>, void>, opt?: CommonDaoStreamForEachOptions<Saved<BM>>): Promise<void>; | ||
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper: AsyncMapper<Saved<DBM>, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>; | ||
streamQueryForEach(q: DBQuery<DBM>, mapper: AsyncMapper<BM, void>, opt?: CommonDaoStreamForEachOptions<BM>): Promise<void>; | ||
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper: AsyncMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>; | ||
/** | ||
* Stream as Readable, to be able to .pipe() it further with support of backpressure. | ||
*/ | ||
streamQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<Saved<DBM>>; | ||
streamQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM>; | ||
/** | ||
@@ -81,3 +81,3 @@ * Stream as Readable, to be able to .pipe() it further with support of backpressure. | ||
*/ | ||
streamQuery(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<Saved<BM>>): ReadableTyped<Saved<BM>>; | ||
streamQuery(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>; | ||
queryIds(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<string[]>; | ||
@@ -94,3 +94,3 @@ streamQueryIds(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<string>): ReadableTyped<string>; | ||
*/ | ||
save(bm: UnsavedId<BM>, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<Saved<BM>>; | ||
save(bm: Unsaved<BM>, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<BM>; | ||
/** | ||
@@ -104,3 +104,3 @@ * 1. Applies the patch | ||
*/ | ||
savePatch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
savePatch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
/** | ||
@@ -115,7 +115,7 @@ * Convenience method to replace 3 operations (loading+patching+saving) with one: | ||
*/ | ||
patchById(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
patchById(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
/** | ||
* Like patchById, but runs all operations within a Transaction. | ||
*/ | ||
patchByIdInTransaction(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
patchByIdInTransaction(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
/** | ||
@@ -127,10 +127,10 @@ * Same as patchById, but takes the whole object as input. | ||
*/ | ||
patch(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
patch(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
/** | ||
* Like patch, but runs all operations within a Transaction. | ||
*/ | ||
patchInTransaction(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
saveAsDBM(dbm: UnsavedId<DBM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>>; | ||
saveBatch(bms: UnsavedId<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>; | ||
saveBatchAsDBM(dbms: UnsavedId<DBM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>[]>; | ||
patchInTransaction(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
saveAsDBM(dbm: Unsaved<DBM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<DBM>; | ||
saveBatch(bms: Unsaved<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM[]>; | ||
saveBatchAsDBM(dbms: Unsaved<DBM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<DBM[]>; | ||
/** | ||
@@ -159,4 +159,4 @@ * "Streaming" is implemented by buffering incoming rows into **batches** | ||
dbmToBM(_dbm: undefined, opt?: CommonDaoOptions): Promise<undefined>; | ||
dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<Saved<BM>>; | ||
dbmsToBM(dbms: DBM[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<BM>; | ||
dbmsToBM(dbms: DBM[], opt?: CommonDaoOptions): Promise<BM[]>; | ||
/** | ||
@@ -167,7 +167,7 @@ * Mutates object with properties: id, created, updated. | ||
bmToDBM(bm: undefined, opt?: CommonDaoOptions): Promise<undefined>; | ||
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<Saved<DBM>>; | ||
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<Saved<DBM>[]>; | ||
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<DBM>; | ||
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<DBM[]>; | ||
anyToDBM(dbm: undefined, opt?: CommonDaoOptions): undefined; | ||
anyToDBM(dbm?: any, opt?: CommonDaoOptions): Saved<DBM>; | ||
anyToDBMs(entities: DBM[], opt?: CommonDaoOptions): Saved<DBM>[]; | ||
anyToDBM(dbm?: any, opt?: CommonDaoOptions): DBM; | ||
anyToDBMs(entities: DBM[], opt?: CommonDaoOptions): DBM[]; | ||
bmToTM(bm: undefined, opt?: CommonDaoOptions): TM | undefined; | ||
@@ -213,8 +213,8 @@ bmToTM(bm?: BM, opt?: CommonDaoOptions): TM; | ||
rollback(): Promise<void>; | ||
getById<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>; | ||
getByIds<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
save<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bm: UnsavedId<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>; | ||
saveBatch<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bms: UnsavedId<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>; | ||
getById<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<BM | null>; | ||
getByIds<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<BM[]>; | ||
save<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bm: Unsaved<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>; | ||
saveBatch<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bms: Unsaved<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM[]>; | ||
deleteById(dao: CommonDao<any>, id?: string | null, opt?: CommonDaoOptions): Promise<number>; | ||
deleteByIds(dao: CommonDao<any>, ids: string[], opt?: CommonDaoOptions): Promise<number>; | ||
} |
@@ -422,3 +422,3 @@ "use strict"; | ||
// .pipe(transformMap<any, DBM>(dbm => this.anyToDBM(dbm, opt), safeOpt)) | ||
// .pipe(transformMap<DBM, Saved<BM>>(dbm => this.dbmToBM(dbm, opt), safeOpt)) | ||
// .pipe(transformMap<DBM, BM>(dbm => this.dbmToBM(dbm, opt), safeOpt)) | ||
.on('error', err => stream.emit('error', err)) | ||
@@ -1121,3 +1121,3 @@ .pipe((0, nodejs_lib_1.transformMap)(async (dbm) => { | ||
// opt?: CommonDaoOptions, | ||
// ): Promise<Saved<BM>[]> { | ||
// ): Promise<BM[]> { | ||
// try { | ||
@@ -1124,0 +1124,0 @@ // return await dao.runQuery(q, { ...opt, tx: this.tx }) |
@@ -1,2 +0,2 @@ | ||
import { AnyObject, BaseDBEntity, CommonLogger, ErrorMode, Promisable, Saved, ZodError, ZodSchema } from '@naturalcycles/js-lib'; | ||
import { AnyObject, BaseDBEntity, CommonLogger, ErrorMode, Promisable, ZodError, ZodSchema } from '@naturalcycles/js-lib'; | ||
import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib'; | ||
@@ -56,3 +56,3 @@ import { CommonDB } from '../common.db'; | ||
*/ | ||
afterLoad?: (dbm: Saved<DBM>) => Promisable<Saved<DBM> | null>; | ||
afterLoad?: (dbm: DBM) => Promisable<DBM | null>; | ||
/** | ||
@@ -71,3 +71,3 @@ * Allows to access the DBM just before it's supposed to be saved to the DB. | ||
*/ | ||
beforeSave?: (dbm: Saved<DBM>) => Promisable<Saved<DBM> | null>; | ||
beforeSave?: (dbm: DBM) => Promisable<DBM | null>; | ||
/** | ||
@@ -74,0 +74,0 @@ * Called in: |
@@ -1,2 +0,2 @@ | ||
import { AsyncMapper, Saved, AnyObject, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib'; | ||
import { AsyncMapper, AnyObject, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib'; | ||
import { ReadableTyped } from '@naturalcycles/nodejs-lib'; | ||
@@ -93,15 +93,15 @@ import { CommonDaoOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, DBPatch } from '..'; | ||
constructor(dao: CommonDao<BM, DBM, TM>, table?: string); | ||
runQuery(opt?: CommonDaoOptions): Promise<Saved<BM>[]>; | ||
runQuery(opt?: CommonDaoOptions): Promise<BM[]>; | ||
runQuerySingleColumn<T = any>(opt?: CommonDaoOptions): Promise<T[]>; | ||
runQueryAsDBM(opt?: CommonDaoOptions): Promise<Saved<DBM>[]>; | ||
runQueryAsDBM(opt?: CommonDaoOptions): Promise<DBM[]>; | ||
runQueryAsTM(opt?: CommonDaoOptions): Promise<TM[]>; | ||
runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>>; | ||
runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<DBM>>>; | ||
runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<BM>>; | ||
runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>>; | ||
runQueryExtendedAsTM(opt?: CommonDaoOptions): Promise<RunQueryResult<TM>>; | ||
runQueryCount(opt?: CommonDaoOptions): Promise<number>; | ||
updateByQuery(patch: DBPatch<DBM>, opt?: CommonDaoOptions): Promise<number>; | ||
streamQueryForEach(mapper: AsyncMapper<Saved<BM>, void>, opt?: CommonDaoStreamForEachOptions<Saved<BM>>): Promise<void>; | ||
streamQueryAsDBMForEach(mapper: AsyncMapper<Saved<DBM>, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>; | ||
streamQuery(opt?: CommonDaoStreamOptions<Saved<BM>>): ReadableTyped<Saved<BM>>; | ||
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<Saved<DBM>>; | ||
streamQueryForEach(mapper: AsyncMapper<BM, void>, opt?: CommonDaoStreamForEachOptions<BM>): Promise<void>; | ||
streamQueryAsDBMForEach(mapper: AsyncMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>; | ||
streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>; | ||
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM>; | ||
queryIds(opt?: CommonDaoOptions): Promise<string[]>; | ||
@@ -108,0 +108,0 @@ streamQueryIds(opt?: CommonDaoStreamOptions<string>): ReadableTyped<string>; |
/// <reference types="node" /> | ||
import { BaseDBEntity, Saved, JsonSchemaObject } from '@naturalcycles/js-lib'; | ||
import { BaseDBEntity, JsonSchemaObject } from '@naturalcycles/js-lib'; | ||
export declare const TEST_TABLE = "TEST_TABLE"; | ||
@@ -22,5 +22,5 @@ export interface TestItemBM extends BaseDBEntity { | ||
export declare const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM>; | ||
export declare function createTestItemDBM(num?: number): Saved<TestItemDBM>; | ||
export declare function createTestItemBM(num?: number): Saved<TestItemBM>; | ||
export declare function createTestItemsDBM(count?: number): Saved<TestItemDBM>[]; | ||
export declare function createTestItemsBM(count?: number): Saved<TestItemBM>[]; | ||
export declare function createTestItemDBM(num?: number): TestItemDBM; | ||
export declare function createTestItemBM(num?: number): TestItemBM; | ||
export declare function createTestItemsDBM(count?: number): TestItemDBM[]; | ||
export declare function createTestItemsBM(count?: number): TestItemBM[]; |
@@ -28,3 +28,6 @@ "use strict"; | ||
.rootObject({ | ||
// todo: figure out how to not copy-paste these 3 fields | ||
id: js_lib_1.jsonSchema.string(), // todo: not strictly needed here | ||
created: js_lib_1.jsonSchema.unixTimestamp(), | ||
updated: js_lib_1.jsonSchema.unixTimestamp(), | ||
k1: js_lib_1.jsonSchema.string(), | ||
@@ -31,0 +34,0 @@ k2: js_lib_1.jsonSchema.oneOf([js_lib_1.jsonSchema.string(), js_lib_1.jsonSchema.null()]).optional(), |
@@ -43,3 +43,3 @@ { | ||
}, | ||
"version": "9.4.1", | ||
"version": "9.4.2", | ||
"description": "Lowest Common Denominator API to supported Databases", | ||
@@ -46,0 +46,0 @@ "keywords": [ |
@@ -7,3 +7,2 @@ import { | ||
Promisable, | ||
Saved, | ||
ZodError, | ||
@@ -80,3 +79,3 @@ ZodSchema, | ||
*/ | ||
afterLoad?: (dbm: Saved<DBM>) => Promisable<Saved<DBM> | null> | ||
afterLoad?: (dbm: DBM) => Promisable<DBM | null> | ||
@@ -96,3 +95,3 @@ /** | ||
*/ | ||
beforeSave?: (dbm: Saved<DBM>) => Promisable<Saved<DBM> | null> | ||
beforeSave?: (dbm: DBM) => Promisable<DBM | null> | ||
@@ -99,0 +98,0 @@ /** |
@@ -24,6 +24,5 @@ import { Transform } from 'node:stream' | ||
pMap, | ||
Saved, | ||
SKIP, | ||
UnixTimestampMillisNumber, | ||
UnsavedId, | ||
Unsaved, | ||
ZodSchema, | ||
@@ -119,3 +118,3 @@ ZodValidationError, | ||
// CREATE | ||
create(part: Partial<BM> = {}, opt: CommonDaoOptions = {}): Saved<BM> { | ||
create(part: Partial<BM> = {}, opt: CommonDaoOptions = {}): BM { | ||
const bm = this.cfg.hooks!.beforeCreate!(part) | ||
@@ -129,4 +128,4 @@ // First assignIdCreatedUpdated, then validate! | ||
async getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null> | ||
async getById(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null> | ||
async getById(id?: string | null, opt: CommonDaoOptions = {}): Promise<Saved<BM> | null> { | ||
async getById(id?: string | null, opt?: CommonDaoOptions): Promise<BM | null> | ||
async getById(id?: string | null, opt: CommonDaoOptions = {}): Promise<BM | null> { | ||
if (!id) return null | ||
@@ -137,3 +136,3 @@ const op = `getById(${id})` | ||
let dbm = (await (opt.tx || this.cfg.db).getByIds<Saved<DBM>>(table, [id]))[0] | ||
let dbm = (await (opt.tx || this.cfg.db).getByIds<DBM>(table, [id]))[0] | ||
if (dbm && !opt.raw && this.cfg.hooks!.afterLoad) { | ||
@@ -148,7 +147,3 @@ dbm = (await this.cfg.hooks!.afterLoad(dbm)) || undefined | ||
async getByIdOrEmpty( | ||
id: string, | ||
part: Partial<BM> = {}, | ||
opt?: CommonDaoOptions, | ||
): Promise<Saved<BM>> { | ||
async getByIdOrEmpty(id: string, part: Partial<BM> = {}, opt?: CommonDaoOptions): Promise<BM> { | ||
const bm = await this.getById(id, opt) | ||
@@ -164,3 +159,3 @@ if (bm) return bm | ||
opt?: CommonDaoOptions, | ||
): Promise<Saved<DBM>> { | ||
): Promise<DBM> { | ||
const dbm = await this.getByIdAsDBM(id, opt) | ||
@@ -174,4 +169,4 @@ if (dbm) return dbm | ||
async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null> | ||
async getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<DBM> | null> | ||
async getByIdAsDBM(id?: string | null, opt: CommonDaoOptions = {}): Promise<Saved<DBM> | null> { | ||
async getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<DBM | null> | ||
async getByIdAsDBM(id?: string | null, opt: CommonDaoOptions = {}): Promise<DBM | null> { | ||
if (!id) return null | ||
@@ -181,3 +176,3 @@ const op = `getByIdAsDBM(${id})` | ||
const started = this.logStarted(op, table) | ||
let [dbm] = await (opt.tx || this.cfg.db).getByIds<Saved<DBM>>(table, [id]) | ||
let [dbm] = await (opt.tx || this.cfg.db).getByIds<DBM>(table, [id]) | ||
if (dbm && !opt.raw && this.cfg.hooks!.afterLoad) { | ||
@@ -201,3 +196,3 @@ dbm = (await this.cfg.hooks!.afterLoad(dbm)) || undefined | ||
const started = this.logStarted(op, table) | ||
let [dbm] = await (opt.tx || this.cfg.db).getByIds<Saved<DBM>>(table, [id]) | ||
let [dbm] = await (opt.tx || this.cfg.db).getByIds<DBM>(table, [id]) | ||
if (dbm && !opt.raw && this.cfg.hooks!.afterLoad) { | ||
@@ -217,3 +212,3 @@ dbm = (await this.cfg.hooks!.afterLoad(dbm)) || undefined | ||
async getByIds(ids: string[], opt: CommonDaoOptions = {}): Promise<Saved<BM>[]> { | ||
async getByIds(ids: string[], opt: CommonDaoOptions = {}): Promise<BM[]> { | ||
if (!ids.length) return [] | ||
@@ -223,3 +218,3 @@ const op = `getByIds ${ids.length} id(s) (${_truncate(ids.slice(0, 10).join(', '), 50)})` | ||
const started = this.logStarted(op, table) | ||
let dbms = await (opt.tx || this.cfg.db).getByIds<Saved<DBM>>(table, ids) | ||
let dbms = await (opt.tx || this.cfg.db).getByIds<DBM>(table, ids) | ||
if (!opt.raw && this.cfg.hooks!.afterLoad && dbms.length) { | ||
@@ -236,3 +231,3 @@ dbms = (await pMap(dbms, async dbm => await this.cfg.hooks!.afterLoad!(dbm))).filter( | ||
async getByIdsAsDBM(ids: string[], opt: CommonDaoOptions = {}): Promise<Saved<DBM>[]> { | ||
async getByIdsAsDBM(ids: string[], opt: CommonDaoOptions = {}): Promise<DBM[]> { | ||
if (!ids.length) return [] | ||
@@ -242,3 +237,3 @@ const op = `getByIdsAsDBM ${ids.length} id(s) (${_truncate(ids.slice(0, 10).join(', '), 50)})` | ||
const started = this.logStarted(op, table) | ||
let dbms = await (opt.tx || this.cfg.db).getByIds<Saved<DBM>>(table, ids) | ||
let dbms = await (opt.tx || this.cfg.db).getByIds<DBM>(table, ids) | ||
if (!opt.raw && this.cfg.hooks!.afterLoad && dbms.length) { | ||
@@ -254,3 +249,3 @@ dbms = (await pMap(dbms, async dbm => await this.cfg.hooks!.afterLoad!(dbm))).filter( | ||
async requireById(id: string, opt: CommonDaoOptions = {}): Promise<Saved<BM>> { | ||
async requireById(id: string, opt: CommonDaoOptions = {}): Promise<BM> { | ||
const r = await this.getById(id, opt) | ||
@@ -263,3 +258,3 @@ if (!r) { | ||
async requireByIdAsDBM(id: string, opt: CommonDaoOptions = {}): Promise<Saved<DBM>> { | ||
async requireByIdAsDBM(id: string, opt: CommonDaoOptions = {}): Promise<DBM> { | ||
const r = await this.getByIdAsDBM(id, opt) | ||
@@ -313,7 +308,7 @@ if (!r) { | ||
async getBy(by: keyof DBM, value: any, limit = 0, opt?: CommonDaoOptions): Promise<Saved<BM>[]> { | ||
async getBy(by: keyof DBM, value: any, limit = 0, opt?: CommonDaoOptions): Promise<BM[]> { | ||
return await this.query().filterEq(by, value).limit(limit).runQuery(opt) | ||
} | ||
async getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<Saved<BM> | null> { | ||
async getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<BM | null> { | ||
const [bm] = await this.query().filterEq(by, value).limit(1).runQuery(opt) | ||
@@ -323,3 +318,3 @@ return bm || null | ||
async getAll(opt?: CommonDaoOptions): Promise<Saved<BM>[]> { | ||
async getAll(opt?: CommonDaoOptions): Promise<BM[]> { | ||
return await this.query().runQuery(opt) | ||
@@ -336,3 +331,3 @@ } | ||
async runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<Saved<BM>[]> { | ||
async runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<BM[]> { | ||
const { rows } = await this.runQueryExtended(q, opt) | ||
@@ -359,3 +354,3 @@ return rows | ||
*/ | ||
async runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<Saved<BM>[]> { | ||
async runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<BM[]> { | ||
const results = ( | ||
@@ -367,10 +362,7 @@ await pMap(queries, async q => (await this.runQueryExtended(q, opt)).rows) | ||
async runQueryExtended( | ||
q: DBQuery<DBM>, | ||
opt: CommonDaoOptions = {}, | ||
): Promise<RunQueryResult<Saved<BM>>> { | ||
async runQueryExtended(q: DBQuery<DBM>, opt: CommonDaoOptions = {}): Promise<RunQueryResult<BM>> { | ||
q.table = opt.table || q.table | ||
const op = `runQuery(${q.pretty()})` | ||
const started = this.logStarted(op, q.table) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<Saved<DBM>>(q, opt) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<DBM>(q, opt) | ||
const partialQuery = !!q._selectedFieldNames | ||
@@ -391,3 +383,3 @@ if (!opt.raw && this.cfg.hooks!.afterLoad && rows.length) { | ||
async runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<Saved<DBM>[]> { | ||
async runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<DBM[]> { | ||
const { rows } = await this.runQueryExtendedAsDBM(q, opt) | ||
@@ -400,7 +392,7 @@ return rows | ||
opt: CommonDaoOptions = {}, | ||
): Promise<RunQueryResult<Saved<DBM>>> { | ||
): Promise<RunQueryResult<DBM>> { | ||
q.table = opt.table || q.table | ||
const op = `runQueryAsDBM(${q.pretty()})` | ||
const started = this.logStarted(op, q.table) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<Saved<DBM>>(q, opt) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<DBM>(q, opt) | ||
if (!opt.raw && this.cfg.hooks!.afterLoad && rows.length) { | ||
@@ -430,3 +422,3 @@ rows = (await pMap(rows, async dbm => await this.cfg.hooks!.afterLoad!(dbm))).filter( | ||
const started = this.logStarted(op, q.table) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<Saved<DBM>>(q, opt) | ||
let { rows, ...queryResult } = await this.cfg.db.runQuery<DBM>(q, opt) | ||
if (!opt.raw && this.cfg.hooks!.afterLoad && rows.length) { | ||
@@ -461,4 +453,4 @@ rows = (await pMap(rows, async dbm => await this.cfg.hooks!.afterLoad!(dbm))).filter( | ||
q: DBQuery<DBM>, | ||
mapper: AsyncMapper<Saved<BM>, void>, | ||
opt: CommonDaoStreamForEachOptions<Saved<BM>> = {}, | ||
mapper: AsyncMapper<BM, void>, | ||
opt: CommonDaoStreamForEachOptions<BM> = {}, | ||
): Promise<void> { | ||
@@ -477,3 +469,3 @@ q.table = opt.table || q.table | ||
this.cfg.db.streamQuery<DBM>(q, opt), | ||
transformMap<Saved<DBM>, Saved<BM>>( | ||
transformMap<DBM, BM>( | ||
async dbm => { | ||
@@ -494,3 +486,3 @@ count++ | ||
), | ||
transformMap<Saved<BM>, void>(mapper, { | ||
transformMap<BM, void>(mapper, { | ||
...opt, | ||
@@ -514,3 +506,3 @@ predicate: _passthroughPredicate, // to be able to logProgress | ||
q: DBQuery<DBM>, | ||
mapper: AsyncMapper<Saved<DBM>, void>, | ||
mapper: AsyncMapper<DBM, void>, | ||
opt: CommonDaoStreamForEachOptions<DBM> = {}, | ||
@@ -546,3 +538,3 @@ ): Promise<void> { | ||
), | ||
transformMap<Saved<DBM>, void>(mapper, { | ||
transformMap<DBM, void>(mapper, { | ||
...opt, | ||
@@ -567,6 +559,3 @@ predicate: _passthroughPredicate, // to be able to logProgress | ||
*/ | ||
streamQueryAsDBM( | ||
q: DBQuery<DBM>, | ||
opt: CommonDaoStreamOptions<DBM> = {}, | ||
): ReadableTyped<Saved<DBM>> { | ||
streamQueryAsDBM(q: DBQuery<DBM>, opt: CommonDaoStreamOptions<DBM> = {}): ReadableTyped<DBM> { | ||
q.table = opt.table || q.table | ||
@@ -585,3 +574,3 @@ opt.skipValidation = opt.skipValidation !== false // default true | ||
.pipe( | ||
transformMap<any, Saved<DBM>>( | ||
transformMap<any, DBM>( | ||
async dbm => { | ||
@@ -611,6 +600,3 @@ if (this.cfg.hooks!.afterLoad) { | ||
*/ | ||
streamQuery( | ||
q: DBQuery<DBM>, | ||
opt: CommonDaoStreamOptions<Saved<BM>> = {}, | ||
): ReadableTyped<Saved<BM>> { | ||
streamQuery(q: DBQuery<DBM>, opt: CommonDaoStreamOptions<BM> = {}): ReadableTyped<BM> { | ||
q.table = opt.table || q.table | ||
@@ -629,6 +615,6 @@ opt.skipValidation = opt.skipValidation !== false // default true | ||
// .pipe(transformMap<any, DBM>(dbm => this.anyToDBM(dbm, opt), safeOpt)) | ||
// .pipe(transformMap<DBM, Saved<BM>>(dbm => this.dbmToBM(dbm, opt), safeOpt)) | ||
// .pipe(transformMap<DBM, BM>(dbm => this.dbmToBM(dbm, opt), safeOpt)) | ||
.on('error', err => stream.emit('error', err)) | ||
.pipe( | ||
transformMap<Saved<DBM>, Saved<BM>>( | ||
transformMap<DBM, BM>( | ||
async dbm => { | ||
@@ -667,3 +653,3 @@ if (this.cfg.hooks!.afterLoad) { | ||
.pipe( | ||
transformMapSimple<Saved<DBM>, string>(r => r.id, { | ||
transformMapSimple<DBM, string>(r => r.id, { | ||
errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors | ||
@@ -690,3 +676,3 @@ }), | ||
this.cfg.db.streamQuery<DBM>(q.select(['id']), opt), | ||
transformMapSimple<Saved<DBM>, string>(r => { | ||
transformMapSimple<DBM, string>(r => { | ||
count++ | ||
@@ -738,3 +724,3 @@ return r.id | ||
*/ | ||
async save(bm: UnsavedId<BM>, opt: CommonDaoSaveOptions<BM, DBM> = {}): Promise<Saved<BM>> { | ||
async save(bm: Unsaved<BM>, opt: CommonDaoSaveOptions<BM, DBM> = {}): Promise<BM> { | ||
this.requireWriteAccess() | ||
@@ -744,3 +730,3 @@ | ||
// Skipping the save operation | ||
return bm as Saved<BM> | ||
return bm as BM | ||
} | ||
@@ -750,3 +736,3 @@ | ||
this.assignIdCreatedUpdated(bm, opt) // mutates | ||
_typeCast<Saved<BM>>(bm) | ||
_typeCast<BM>(bm) | ||
let dbm = await this.bmToDBM(bm, opt) | ||
@@ -791,7 +777,3 @@ | ||
*/ | ||
async savePatch( | ||
bm: BM, | ||
patch: Partial<BM>, | ||
opt: CommonDaoSaveBatchOptions<DBM>, | ||
): Promise<Saved<BM>> { | ||
async savePatch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<BM> { | ||
const patched: BM = { | ||
@@ -804,3 +786,3 @@ ...bm, | ||
// Skipping the save operation, as data is the same | ||
return bm as Saved<BM> | ||
return bm | ||
} | ||
@@ -827,3 +809,3 @@ | ||
opt: CommonDaoSaveBatchOptions<DBM> = {}, | ||
): Promise<Saved<BM>> { | ||
): Promise<BM> { | ||
if (this.cfg.patchInTransaction && !opt.tx) { | ||
@@ -836,3 +818,3 @@ // patchInTransaction means that we should run this op in Transaction | ||
let patched: Saved<BM> | ||
let patched: BM | ||
const loaded = await this.getById(id, opt) | ||
@@ -861,3 +843,3 @@ | ||
opt?: CommonDaoSaveBatchOptions<DBM>, | ||
): Promise<Saved<BM>> { | ||
): Promise<BM> { | ||
return await this.runInTransaction(async daoTx => { | ||
@@ -874,7 +856,3 @@ return await this.patchById(id, patch, { ...opt, tx: daoTx.tx }) | ||
*/ | ||
async patch( | ||
bm: BM, | ||
patch: Partial<BM>, | ||
opt: CommonDaoSaveBatchOptions<DBM> = {}, | ||
): Promise<Saved<BM>> { | ||
async patch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM> = {}): Promise<BM> { | ||
if (this.cfg.patchInTransaction && !opt.tx) { | ||
@@ -894,3 +872,3 @@ // patchInTransaction means that we should run this op in Transaction | ||
// Skipping the save operation, as data is the same | ||
return bm as Saved<BM> | ||
return bm | ||
} | ||
@@ -914,3 +892,3 @@ | ||
opt?: CommonDaoSaveBatchOptions<DBM>, | ||
): Promise<Saved<BM>> { | ||
): Promise<BM> { | ||
return await this.runInTransaction(async daoTx => { | ||
@@ -921,6 +899,3 @@ return await this.patch(bm, patch, { ...opt, tx: daoTx.tx }) | ||
async saveAsDBM( | ||
dbm: UnsavedId<DBM>, | ||
opt: CommonDaoSaveBatchOptions<DBM> = {}, | ||
): Promise<Saved<DBM>> { | ||
async saveAsDBM(dbm: Unsaved<DBM>, opt: CommonDaoSaveBatchOptions<DBM> = {}): Promise<DBM> { | ||
this.requireWriteAccess() | ||
@@ -931,3 +906,3 @@ const table = opt.table || this.cfg.table | ||
// will override/set `updated` field, unless opts.preserveUpdated is set | ||
let row = dbm as Saved<DBM> | ||
let row = dbm as DBM | ||
if (!opt.raw) { | ||
@@ -949,3 +924,3 @@ const idWasGenerated = !dbm.id && this.cfg.generateId | ||
row = (await this.cfg.hooks!.beforeSave(row))! | ||
if (row === null) return dbm as Saved<DBM> | ||
if (row === null) return dbm as DBM | ||
} | ||
@@ -967,6 +942,3 @@ | ||
async saveBatch( | ||
bms: UnsavedId<BM>[], | ||
opt: CommonDaoSaveBatchOptions<DBM> = {}, | ||
): Promise<Saved<BM>[]> { | ||
async saveBatch(bms: Unsaved<BM>[], opt: CommonDaoSaveBatchOptions<DBM> = {}): Promise<BM[]> { | ||
if (!bms.length) return [] | ||
@@ -1012,16 +984,16 @@ this.requireWriteAccess() | ||
return bms as Saved<BM>[] | ||
return bms as BM[] | ||
} | ||
async saveBatchAsDBM( | ||
dbms: UnsavedId<DBM>[], | ||
dbms: Unsaved<DBM>[], | ||
opt: CommonDaoSaveBatchOptions<DBM> = {}, | ||
): Promise<Saved<DBM>[]> { | ||
): Promise<DBM[]> { | ||
if (!dbms.length) return [] | ||
this.requireWriteAccess() | ||
const table = opt.table || this.cfg.table | ||
let rows = dbms as Saved<DBM>[] | ||
let rows = dbms as DBM[] | ||
if (!opt.raw) { | ||
dbms.forEach(dbm => this.assignIdCreatedUpdated(dbm, opt)) // mutates | ||
rows = this.anyToDBMs(dbms as Saved<DBM>[], opt) | ||
rows = this.anyToDBMs(dbms as DBM[], opt) | ||
if (opt.ensureUniqueId) throw new AppError('ensureUniqueId is not supported in saveBatch') | ||
@@ -1087,3 +1059,3 @@ } | ||
return [ | ||
transformMap<BM, Saved<DBM>>( | ||
transformMap<BM, DBM>( | ||
async bm => { | ||
@@ -1245,4 +1217,4 @@ this.assignIdCreatedUpdated(bm, opt) // mutates | ||
async dbmToBM(_dbm: undefined, opt?: CommonDaoOptions): Promise<undefined> | ||
async dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<Saved<BM>> | ||
async dbmToBM(_dbm?: DBM, opt: CommonDaoOptions = {}): Promise<Saved<BM> | undefined> { | ||
async dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<BM> | ||
async dbmToBM(_dbm?: DBM, opt: CommonDaoOptions = {}): Promise<BM | undefined> { | ||
if (!_dbm) return | ||
@@ -1266,3 +1238,3 @@ | ||
async dbmsToBM(dbms: DBM[], opt: CommonDaoOptions = {}): Promise<Saved<BM>[]> { | ||
async dbmsToBM(dbms: DBM[], opt: CommonDaoOptions = {}): Promise<BM[]> { | ||
return await pMap(dbms, async dbm => await this.dbmToBM(dbm, opt)) | ||
@@ -1276,4 +1248,4 @@ } | ||
async bmToDBM(bm: undefined, opt?: CommonDaoOptions): Promise<undefined> | ||
async bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<Saved<DBM>> | ||
async bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<Saved<DBM> | undefined> { | ||
async bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<DBM> | ||
async bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<DBM | undefined> { | ||
if (bm === undefined) return | ||
@@ -1297,3 +1269,3 @@ | ||
async bmsToDBM(bms: BM[], opt: CommonDaoOptions = {}): Promise<Saved<DBM>[]> { | ||
async bmsToDBM(bms: BM[], opt: CommonDaoOptions = {}): Promise<DBM[]> { | ||
// try/catch? | ||
@@ -1304,4 +1276,4 @@ return await pMap(bms, async bm => await this.bmToDBM(bm, opt)) | ||
anyToDBM(dbm: undefined, opt?: CommonDaoOptions): undefined | ||
anyToDBM(dbm?: any, opt?: CommonDaoOptions): Saved<DBM> | ||
anyToDBM(dbm?: DBM, opt: CommonDaoOptions = {}): Saved<DBM> | undefined { | ||
anyToDBM(dbm?: any, opt?: CommonDaoOptions): DBM | ||
anyToDBM(dbm?: DBM, opt: CommonDaoOptions = {}): DBM | undefined { | ||
if (!dbm) return | ||
@@ -1322,3 +1294,3 @@ | ||
anyToDBMs(entities: DBM[], opt: CommonDaoOptions = {}): Saved<DBM>[] { | ||
anyToDBMs(entities: DBM[], opt: CommonDaoOptions = {}): DBM[] { | ||
return entities.map(entity => this.anyToDBM(entity, opt)) | ||
@@ -1551,3 +1523,3 @@ } | ||
opt?: CommonDaoOptions, | ||
): Promise<Saved<BM> | null> { | ||
): Promise<BM | null> { | ||
return await dao.getById(id, { ...opt, tx: this.tx }) | ||
@@ -1560,3 +1532,3 @@ } | ||
opt?: CommonDaoOptions, | ||
): Promise<Saved<BM>[]> { | ||
): Promise<BM[]> { | ||
return await dao.getByIds(ids, { ...opt, tx: this.tx }) | ||
@@ -1570,3 +1542,3 @@ } | ||
// opt?: CommonDaoOptions, | ||
// ): Promise<Saved<BM>[]> { | ||
// ): Promise<BM[]> { | ||
// try { | ||
@@ -1582,5 +1554,5 @@ // return await dao.runQuery(q, { ...opt, tx: this.tx }) | ||
dao: CommonDao<BM, DBM, any>, | ||
bm: UnsavedId<BM>, | ||
bm: Unsaved<BM>, | ||
opt?: CommonDaoSaveBatchOptions<DBM>, | ||
): Promise<Saved<BM>> { | ||
): Promise<BM> { | ||
return (await this.saveBatch(dao, [bm], opt))[0]! | ||
@@ -1591,5 +1563,5 @@ } | ||
dao: CommonDao<BM, DBM, any>, | ||
bms: UnsavedId<BM>[], | ||
bms: Unsaved<BM>[], | ||
opt?: CommonDaoSaveBatchOptions<DBM>, | ||
): Promise<Saved<BM>[]> { | ||
): Promise<BM[]> { | ||
return await dao.saveBatch(bms, { ...opt, tx: this.tx }) | ||
@@ -1596,0 +1568,0 @@ } |
@@ -13,3 +13,2 @@ import fs from 'node:fs' | ||
BaseDBEntity, | ||
Saved, | ||
} from '@naturalcycles/js-lib' | ||
@@ -221,3 +220,3 @@ import { | ||
...(sinceUpdated | ||
? [transformFilterSync<Saved<BaseDBEntity>>(r => r.updated >= sinceUpdated)] | ||
? [transformFilterSync<BaseDBEntity>(r => r.updated >= sinceUpdated)] | ||
: []), | ||
@@ -224,0 +223,0 @@ transformMap(mapperPerTable[table] || _passthroughMapper, { |
import { | ||
AsyncMapper, | ||
_truncate, | ||
Saved, | ||
AnyObject, | ||
@@ -254,3 +253,3 @@ _objectAssign, | ||
async runQuery(opt?: CommonDaoOptions): Promise<Saved<BM>[]> { | ||
async runQuery(opt?: CommonDaoOptions): Promise<BM[]> { | ||
return await this.dao.runQuery(this, opt) | ||
@@ -263,3 +262,3 @@ } | ||
async runQueryAsDBM(opt?: CommonDaoOptions): Promise<Saved<DBM>[]> { | ||
async runQueryAsDBM(opt?: CommonDaoOptions): Promise<DBM[]> { | ||
return await this.dao.runQueryAsDBM(this, opt) | ||
@@ -272,7 +271,7 @@ } | ||
async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>> { | ||
async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<BM>> { | ||
return await this.dao.runQueryExtended(this, opt) | ||
} | ||
async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<DBM>>> { | ||
async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>> { | ||
return await this.dao.runQueryExtendedAsDBM(this, opt) | ||
@@ -294,4 +293,4 @@ } | ||
async streamQueryForEach( | ||
mapper: AsyncMapper<Saved<BM>, void>, | ||
opt?: CommonDaoStreamForEachOptions<Saved<BM>>, | ||
mapper: AsyncMapper<BM, void>, | ||
opt?: CommonDaoStreamForEachOptions<BM>, | ||
): Promise<void> { | ||
@@ -302,3 +301,3 @@ await this.dao.streamQueryForEach(this, mapper, opt) | ||
async streamQueryAsDBMForEach( | ||
mapper: AsyncMapper<Saved<DBM>, void>, | ||
mapper: AsyncMapper<DBM, void>, | ||
opt?: CommonDaoStreamForEachOptions<DBM>, | ||
@@ -309,7 +308,7 @@ ): Promise<void> { | ||
streamQuery(opt?: CommonDaoStreamOptions<Saved<BM>>): ReadableTyped<Saved<BM>> { | ||
streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM> { | ||
return this.dao.streamQuery(this, opt) | ||
} | ||
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<Saved<DBM>> { | ||
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM> { | ||
return this.dao.streamQueryAsDBM(this, opt) | ||
@@ -316,0 +315,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { jsonSchema, _range, BaseDBEntity, Saved, JsonSchemaObject } from '@naturalcycles/js-lib' | ||
import { jsonSchema, _range, BaseDBEntity, JsonSchemaObject } from '@naturalcycles/js-lib' | ||
import { | ||
@@ -53,3 +53,6 @@ baseDBEntitySchema, | ||
.rootObject<TestItemBM>({ | ||
// todo: figure out how to not copy-paste these 3 fields | ||
id: jsonSchema.string(), // todo: not strictly needed here | ||
created: jsonSchema.unixTimestamp(), | ||
updated: jsonSchema.unixTimestamp(), | ||
k1: jsonSchema.string(), | ||
@@ -78,3 +81,3 @@ k2: jsonSchema.oneOf<string | null>([jsonSchema.string(), jsonSchema.null()]).optional(), | ||
export function createTestItemDBM(num = 1): Saved<TestItemDBM> { | ||
export function createTestItemDBM(num = 1): TestItemDBM { | ||
return { | ||
@@ -91,12 +94,12 @@ id: `id${num}`, | ||
export function createTestItemBM(num = 1): Saved<TestItemBM> { | ||
export function createTestItemBM(num = 1): TestItemBM { | ||
return createTestItemDBM(num) | ||
} | ||
export function createTestItemsDBM(count = 1): Saved<TestItemDBM>[] { | ||
export function createTestItemsDBM(count = 1): TestItemDBM[] { | ||
return _range(1, count + 1).map(num => createTestItemDBM(num)) | ||
} | ||
export function createTestItemsBM(count = 1): Saved<TestItemBM>[] { | ||
export function createTestItemsBM(count = 1): TestItemBM[] { | ||
return _range(1, count + 1).map(num => createTestItemBM(num)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
430740
11303