Comparing version 59.3.0 to 59.4.0
import type { CtxBuilderPreProcessor, CtxBuilderResultPreProcessor, CtxExceptionHandler, KmoreQueryBuilder, PageRawType, PageWrapType } from './builder.types.js'; | ||
import { CaseType, EventCallbacks, KmoreTransaction, KmoreTransactionConfig, QueryContext, TrxIdQueryMap } from './types.js'; | ||
import { CaseType, EventCallbacks, KmoreTransaction, KmoreTransactionConfig, QueryContext, TrxIdQueryMap, WrapIdentifierIgnoreRule } from './types.js'; | ||
export declare abstract class KmoreBase<Context = any> { | ||
@@ -10,2 +10,6 @@ readonly abstract dict: unknown; | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
*/ | ||
readonly abstract wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule; | ||
/** | ||
* kmoreTrxId => Set(kmoreQueryId) | ||
@@ -12,0 +16,0 @@ */ |
@@ -7,2 +7,3 @@ import assert from 'node:assert'; | ||
wrapIdentifierCaseConvert: kmore.wrapIdentifierCaseConvert, | ||
wrapIdentifierIgnoreRule: kmore.wrapIdentifierIgnoreRule, | ||
postProcessResponseCaseConvert: caseConvert, | ||
@@ -9,0 +10,0 @@ kmoreQueryId, |
import { RecordCamelKeys, RecordPascalKeys, RecordSnakeKeys } from '@waiting/shared-types'; | ||
import type { Knex } from 'knex'; | ||
import { CaseType, KnexConfig, QueryContext } from './types.js'; | ||
import { CaseType, KnexConfig, QueryContext, WrapIdentifierIgnoreRule } from './types.js'; | ||
export declare function getCurrentTime(dbh: Knex, clientType: KnexConfig['client']): Promise<string>; | ||
export declare const defaultWrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule; | ||
/** | ||
* Convert identifier (field) to snakecase | ||
* Convert identifier (field) to snake/camel case | ||
*/ | ||
@@ -8,0 +9,0 @@ export declare function wrapIdentifier(value: string, origImpl: (input: string) => string, queryContext?: QueryContext): string; |
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import assert from 'node:assert'; | ||
import { camelToSnake, camelKeys, snakeKeys, snakeToCamel, } from '@waiting/shared-core'; | ||
import { CaseType, EnumClient } from './types.js'; | ||
import { CaseType, EnumClient, } from './types.js'; | ||
export async function getCurrentTime(dbh, clientType) { | ||
@@ -33,4 +33,14 @@ if (clientType) { | ||
} | ||
export const defaultWrapIdentifierIgnoreRule = [ | ||
'now()', | ||
'CURRENT_DATE', | ||
'CURRENT_TIME', | ||
'CURRENT_TIMESTAMP', | ||
// /\bCURRENT_DATE\b/u, | ||
// /\bCURRENT_TIMESTAMP\b/u, | ||
// /\bDATE_TRUNC(/u, | ||
// /\bINTERVAL\b/u, | ||
]; | ||
/** | ||
* Convert identifier (field) to snakecase | ||
* Convert identifier (field) to snake/camel case | ||
*/ | ||
@@ -44,3 +54,23 @@ export function wrapIdentifier(value, origImpl, queryContext) { | ||
} | ||
if (value === '*') { | ||
return origImpl(value); | ||
} | ||
if (queryContext) { | ||
const { wrapIdentifierIgnoreRule } = queryContext; | ||
if (wrapIdentifierIgnoreRule?.length) { | ||
const flag = wrapIdentifierIgnoreRule.some((rule) => { | ||
if (typeof rule === 'string') { | ||
return rule === value; | ||
} | ||
else if (rule instanceof RegExp) { | ||
return rule.test(value); | ||
} | ||
else { | ||
return false; | ||
} | ||
}); | ||
if (flag) { | ||
return value; | ||
} | ||
} | ||
switch (queryContext.wrapIdentifierCaseConvert) { | ||
@@ -47,0 +77,0 @@ case CaseType.camel: { |
@@ -6,3 +6,3 @@ import type { DbDict } from 'kmore-types'; | ||
import { postProcessResponse } from './helper.js'; | ||
import { CaseType, EventCallbacks, KmoreTransaction, KmoreTransactionConfig, KnexConfig, QueryContext, TrxIdQueryMap } from './types.js'; | ||
import { CaseType, EventCallbacks, KmoreTransaction, KmoreTransactionConfig, KnexConfig, QueryContext, TrxIdQueryMap, WrapIdentifierIgnoreRule } from './types.js'; | ||
export declare class Kmore<D = any, Context = any> extends KmoreBase<Context> { | ||
@@ -26,3 +26,3 @@ /** | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type DbModel = typeof km.DbModel | ||
@@ -38,3 +38,3 @@ * type Uid = DbModel['tb_user']['uid'] // equal to number | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type Dict = typeof kmore['Dict'] | ||
@@ -66,2 +66,7 @@ * type Uid = Dict['columns']['tb_user']['alias']['tbUserUid'] // equal to literal 'tb_user.uid' | ||
readonly wrapIdentifierCaseConvert: CaseType; | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
* @docs https://knexjs.org/guide/#wrapidentifier | ||
*/ | ||
readonly wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule; | ||
constructor(options: KmoreFactoryOpts<D, Context>); | ||
@@ -96,3 +101,3 @@ /** | ||
/** | ||
* Table identifier case convertion, | ||
* Table identifier case conversion, | ||
* If not CaseType.none, will ignore value of `KnexConfig['wrapIdentifier']` | ||
@@ -104,2 +109,7 @@ * @default CaseType.snake | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
* @docs https://knexjs.org/guide/#wrapidentifier | ||
*/ | ||
wrapIdentifierIgnoreRule?: WrapIdentifierIgnoreRule | undefined; | ||
/** | ||
* Atuo trsaction action (rollback|commit|none) on error (Rejection or Exception), | ||
@@ -106,0 +116,0 @@ * @CAUTION **Will always rollback if query error in database even though this value set to 'commit'** |
@@ -10,3 +10,3 @@ /* eslint-disable max-lines-per-function */ | ||
import { initialConfig } from './config.js'; | ||
import { postProcessResponse, wrapIdentifier } from './helper.js'; | ||
import { defaultWrapIdentifierIgnoreRule, postProcessResponse, wrapIdentifier, } from './helper.js'; | ||
import { createTrxProperties } from './proxy.trx.js'; | ||
@@ -34,3 +34,3 @@ import { CaseType, } from './types.js'; | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type DbModel = typeof km.DbModel | ||
@@ -46,3 +46,3 @@ * type Uid = DbModel['tb_user']['uid'] // equal to number | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type Dict = typeof kmore['Dict'] | ||
@@ -74,2 +74,7 @@ * type Uid = Dict['columns']['tb_user']['alias']['tbUserUid'] // equal to literal 'tb_user.uid' | ||
wrapIdentifierCaseConvert; | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
* @docs https://knexjs.org/guide/#wrapidentifier | ||
*/ | ||
wrapIdentifierIgnoreRule; | ||
constructor(options) { | ||
@@ -98,6 +103,7 @@ super(); | ||
/** | ||
* Table identifier case convertion, | ||
* Table identifier case conversion, | ||
* If not CaseType.none, will ignore value of `KnexConfig['wrapIdentifier']` | ||
*/ | ||
this.wrapIdentifierCaseConvert = options.wrapIdentifierCaseConvert ?? CaseType.snake; | ||
this.wrapIdentifierIgnoreRule = options.wrapIdentifierIgnoreRule ?? defaultWrapIdentifierIgnoreRule; | ||
if (!this.config.wrapIdentifier) { | ||
@@ -104,0 +110,0 @@ if (this.wrapIdentifierCaseConvert === CaseType.none) { |
@@ -12,3 +12,3 @@ import type { TraceContext, Span } from '@mwcp/otel'; | ||
/** | ||
* Auto transction action (rollback|commit|none) on builder error (Rejection or Exception), | ||
* Auto transaction action (rollback|commit|none) on builder error (Rejection or Exception), | ||
* declarative transaction always rollback on end | ||
@@ -55,2 +55,3 @@ * | ||
} | ||
export type WrapIdentifierIgnoreRule = (string | RegExp)[]; | ||
export type EventType = 'query' | 'queryError' | 'queryResponse' | 'start' | 'unknown'; | ||
@@ -85,2 +86,6 @@ export interface KmoreEvent<T = unknown> { | ||
wrapIdentifierCaseConvert: CaseType; | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
*/ | ||
wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule | undefined; | ||
postProcessResponseCaseConvert: CaseType; | ||
@@ -87,0 +92,0 @@ kmoreQueryId: symbol; |
{ | ||
"name": "kmore", | ||
"author": "waiting", | ||
"version": "59.3.0", | ||
"version": "59.4.0", | ||
"description": "A SQL query builder based on knex with powerful TypeScript type support", | ||
@@ -86,3 +86,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "d1a6cecac07bfc525b78380e75aa08d22fffef91" | ||
"gitHead": "bb535faf8bb39c475e76d6b616a0b50a8bbc3537" | ||
} |
@@ -17,2 +17,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
TrxIdQueryMap, | ||
WrapIdentifierIgnoreRule, | ||
} from './types.js' | ||
@@ -28,2 +29,6 @@ | ||
readonly abstract wrapIdentifierCaseConvert: CaseType | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
*/ | ||
readonly abstract wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule | ||
@@ -30,0 +35,0 @@ /** |
@@ -35,2 +35,3 @@ import assert from 'node:assert' | ||
wrapIdentifierCaseConvert: kmore.wrapIdentifierCaseConvert, | ||
wrapIdentifierIgnoreRule: kmore.wrapIdentifierIgnoreRule, | ||
postProcessResponseCaseConvert: caseConvert, | ||
@@ -37,0 +38,0 @@ kmoreQueryId, |
@@ -14,3 +14,9 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import { CaseType, EnumClient, KnexConfig, QueryContext } from './types.js' | ||
import { | ||
CaseType, | ||
EnumClient, | ||
KnexConfig, | ||
QueryContext, | ||
WrapIdentifierIgnoreRule, | ||
} from './types.js' | ||
@@ -64,5 +70,16 @@ | ||
export const defaultWrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule = [ | ||
'now()', | ||
'CURRENT_DATE', | ||
'CURRENT_TIME', | ||
'CURRENT_TIMESTAMP', | ||
// /\bCURRENT_DATE\b/u, | ||
// /\bCURRENT_TIMESTAMP\b/u, | ||
// /\bDATE_TRUNC(/u, | ||
// /\bINTERVAL\b/u, | ||
] | ||
/** | ||
* Convert identifier (field) to snakecase | ||
* Convert identifier (field) to snake/camel case | ||
*/ | ||
@@ -83,3 +100,25 @@ export function wrapIdentifier( | ||
if (value === '*') { | ||
return origImpl(value) | ||
} | ||
if (queryContext) { | ||
const { wrapIdentifierIgnoreRule } = queryContext | ||
if (wrapIdentifierIgnoreRule?.length) { | ||
const flag = wrapIdentifierIgnoreRule.some((rule) => { | ||
if (typeof rule === 'string') { | ||
return rule === value | ||
} | ||
else if (rule instanceof RegExp) { | ||
return rule.test(value) | ||
} | ||
else { | ||
return false | ||
} | ||
}) | ||
if (flag) { | ||
return value | ||
} | ||
} | ||
switch (queryContext.wrapIdentifierCaseConvert) { | ||
@@ -86,0 +125,0 @@ case CaseType.camel: { |
@@ -15,3 +15,8 @@ /* eslint-disable max-lines-per-function */ | ||
import { initialConfig } from './config.js' | ||
import { PostProcessInput, postProcessResponse, wrapIdentifier } from './helper.js' | ||
import { | ||
PostProcessInput, | ||
defaultWrapIdentifierIgnoreRule, | ||
postProcessResponse, | ||
wrapIdentifier, | ||
} from './helper.js' | ||
import { createTrxProperties } from './proxy.trx.js' | ||
@@ -26,2 +31,3 @@ import { | ||
TrxIdQueryMap, | ||
WrapIdentifierIgnoreRule, | ||
} from './types.js' | ||
@@ -55,3 +61,3 @@ import { genKmoreTrxId } from './util.js' | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type DbModel = typeof km.DbModel | ||
@@ -68,3 +74,3 @@ * type Uid = DbModel['tb_user']['uid'] // equal to number | ||
* @example ```ts | ||
* const km = kmoreFactore<Db>({}) | ||
* const km = kmoreFactory<Db>({}) | ||
* type Dict = typeof kmore['Dict'] | ||
@@ -98,2 +104,7 @@ * type Uid = Dict['columns']['tb_user']['alias']['tbUserUid'] // equal to literal 'tb_user.uid' | ||
readonly wrapIdentifierCaseConvert: CaseType | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
* @docs https://knexjs.org/guide/#wrapidentifier | ||
*/ | ||
readonly wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule | ||
@@ -127,3 +138,3 @@ constructor(options: KmoreFactoryOpts<D, Context>) { | ||
/** | ||
* Table identifier case convertion, | ||
* Table identifier case conversion, | ||
* If not CaseType.none, will ignore value of `KnexConfig['wrapIdentifier']` | ||
@@ -133,2 +144,4 @@ */ | ||
this.wrapIdentifierIgnoreRule = options.wrapIdentifierIgnoreRule ?? defaultWrapIdentifierIgnoreRule | ||
if (! this.config.wrapIdentifier) { | ||
@@ -311,3 +324,3 @@ if (this.wrapIdentifierCaseConvert === CaseType.none) { | ||
/** | ||
* Table identifier case convertion, | ||
* Table identifier case conversion, | ||
* If not CaseType.none, will ignore value of `KnexConfig['wrapIdentifier']` | ||
@@ -318,3 +331,10 @@ * @default CaseType.snake | ||
wrapIdentifierCaseConvert?: CaseType | undefined | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
* @docs https://knexjs.org/guide/#wrapidentifier | ||
*/ | ||
wrapIdentifierIgnoreRule?: WrapIdentifierIgnoreRule | undefined | ||
/** | ||
* Atuo trsaction action (rollback|commit|none) on error (Rejection or Exception), | ||
@@ -321,0 +341,0 @@ * @CAUTION **Will always rollback if query error in database even though this value set to 'commit'** |
@@ -22,3 +22,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/** | ||
* Auto transction action (rollback|commit|none) on builder error (Rejection or Exception), | ||
* Auto transaction action (rollback|commit|none) on builder error (Rejection or Exception), | ||
* declarative transaction always rollback on end | ||
@@ -72,3 +72,5 @@ * | ||
export type WrapIdentifierIgnoreRule = (string | RegExp)[] | ||
export type EventType = 'query' | 'queryError' | 'queryResponse' | 'start' | 'unknown' | ||
@@ -105,2 +107,6 @@ | ||
wrapIdentifierCaseConvert: CaseType | ||
/** | ||
* Rules ignoring table identifier case conversion, | ||
*/ | ||
wrapIdentifierIgnoreRule: WrapIdentifierIgnoreRule | undefined | ||
postProcessResponseCaseConvert: CaseType | ||
@@ -107,0 +113,0 @@ kmoreQueryId: symbol |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
326811
5777