From a02efbabe6f12b78a09cab61899eefff9a7d9350 Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Mon, 25 Mar 2024 07:36:57 +0100 Subject: [PATCH] feat: unify skipValidation and skipConversion skipValidation now works as skipConversion. skipConversion is no longer supported (it's skipValidation or nothing). This is for the sake of simplicity. --- scripts/cannon.ts | 6 ------ src/commondao/common.dao.model.ts | 20 +++----------------- src/commondao/common.dao.ts | 9 ++------- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/scripts/cannon.ts b/scripts/cannon.ts index 5c33ece..40f1306 100644 --- a/scripts/cannon.ts +++ b/scripts/cannon.ts @@ -52,12 +52,6 @@ async function register2(): Promise { } async function register3(): Promise { - let item = createTestItemsBM(1).map(r => _omit(r, ['id']))[0]! - item = await dao.save(item, { skipConversion: true }) - return { item } -} - -async function register4(): Promise { let item = createTestItemsBM(1).map(r => _omit(r, ['id']))[0]! item = await dao.save(item, { skipValidation: true }) return { item } diff --git a/src/commondao/common.dao.model.ts b/src/commondao/common.dao.model.ts index 082fc17..9a221cc 100644 --- a/src/commondao/common.dao.model.ts +++ b/src/commondao/common.dao.model.ts @@ -215,22 +215,13 @@ export interface CommonDaoCfg */ skipValidation?: boolean - /** - * @default true (for streams) - */ - skipConversion?: boolean - /** * @default ErrorMode.SUPPRESS for returning ReadableStream, because .pipe() has no concept of "error propagation" * @default ErrorMode.SUPPRESS for .forEach() streams as well, but overridable diff --git a/src/commondao/common.dao.ts b/src/commondao/common.dao.ts index f9ccde7..96deec2 100644 --- a/src/commondao/common.dao.ts +++ b/src/commondao/common.dao.ts @@ -355,7 +355,6 @@ export class CommonDao { ): Promise { q.table = opt.table || q.table opt.skipValidation = opt.skipValidation !== false // default true - opt.skipConversion = opt.skipConversion !== false // default true opt.errorMode ||= ErrorMode.SUPPRESS const partialQuery = !!q._selectedFieldNames @@ -405,7 +404,6 @@ export class CommonDao { ): Promise { q.table = opt.table || q.table opt.skipValidation = opt.skipValidation !== false // default true - opt.skipConversion = opt.skipConversion !== false // default true opt.errorMode ||= ErrorMode.SUPPRESS const partialQuery = !!q._selectedFieldNames @@ -454,7 +452,6 @@ export class CommonDao { streamQueryAsDBM(q: DBQuery, opt: CommonDaoStreamOptions = {}): ReadableTyped { q.table = opt.table || q.table opt.skipValidation = opt.skipValidation !== false // default true - opt.skipConversion = opt.skipConversion !== false // default true opt.errorMode ||= ErrorMode.SUPPRESS const partialQuery = !!q._selectedFieldNames @@ -493,7 +490,6 @@ export class CommonDao { streamQuery(q: DBQuery, opt: CommonDaoStreamOptions = {}): ReadableTyped { q.table = opt.table || q.table opt.skipValidation = opt.skipValidation !== false // default true - opt.skipConversion = opt.skipConversion !== false // default true opt.errorMode ||= ErrorMode.SUPPRESS const stream = this.cfg.db.streamQuery(q, opt) @@ -902,7 +898,6 @@ export class CommonDao { const table = opt.table || this.cfg.table opt.skipValidation ??= true - opt.skipConversion ??= true opt.errorMode ||= ErrorMode.SUPPRESS if (this.cfg.immutable && !opt.allowMutability && !opt.saveMethod) { @@ -1157,7 +1152,7 @@ export class CommonDao { // Return as is if no schema is passed or if `skipConversion` is set if ( !schema || - opt.skipConversion || + opt.skipValidation || (op === 'load' && !this.cfg.validateOnLoad) || (op === 'save' && !this.cfg.validateOnSave) ) { @@ -1191,7 +1186,7 @@ export class CommonDao { } // If we care about validation and there's an error - if (error && !opt.skipValidation) { + if (error) { const processedError = this.cfg.hooks!.onValidationError!(error) if (processedError) throw processedError