Comparing version 28.1.0 to 28.2.0
@@ -5,6 +5,13 @@ import { RecordCamelKeys, RecordSnakeKeys } from '@waiting/shared-types'; | ||
export declare function getCurrentTime(dbh: Knex, clientType: KnexConfig['client']): Promise<string>; | ||
export declare type PostProcessPlain = number | string | undefined | null | boolean; | ||
export declare type PostProcessRecord = Record<string, PostProcessPlain> | object; | ||
export declare type PostProcessArray = PostProcessPlain[]; | ||
export declare type PostProcessInput = PostProcessPlain | PostProcessRecord | PostProcessArray; | ||
export declare type PostProcessRespRet<T extends PostProcessInput> = T extends PostProcessPlain ? T : T extends PostProcessArray ? PostProcessArray : T extends PostProcessRecord ? RecordCamelKeys<T> : never; | ||
/** | ||
* Convert keys of result to camelcase | ||
* Convert keys of result to camelcase, if input is object | ||
*/ | ||
export declare function postProcessResponseToCamel<T = unknown>(result: T, _queryContext: unknown): RecordCamelKeys<T, '_'>[] | RecordCamelKeys<T, '_'>; | ||
export declare function postProcessResponseToCamel<T extends PostProcessInput = PostProcessInput>(result: T, _queryContext?: unknown): PostProcessRespRet<T>; | ||
export declare function genCamelKeysFrom<From extends PostProcessRecord>(input: From): RecordCamelKeys<From, '_'>; | ||
export declare function genSnakeKeysFrom<From>(input: From): RecordSnakeKeys<From, '_'>; | ||
/** | ||
@@ -14,4 +21,2 @@ * Convert identifier (field) to snakecase | ||
export declare function wrapIdentifier(value: string, origImpl: (input: string) => string, _queryContext: unknown): string; | ||
export declare function genCamelKeysFrom<From>(input: From): RecordCamelKeys<From, '_'>; | ||
export declare function genSnakeKeysFrom<From>(input: From): RecordSnakeKeys<From, '_'>; | ||
/** | ||
@@ -18,0 +23,0 @@ * @description only one level |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mergeDoWithInitData = exports.genSnakeKeysFrom = exports.genCamelKeysFrom = exports.wrapIdentifier = exports.postProcessResponseToCamel = exports.getCurrentTime = void 0; | ||
exports.mergeDoWithInitData = exports.wrapIdentifier = exports.genSnakeKeysFrom = exports.genCamelKeysFrom = exports.postProcessResponseToCamel = exports.getCurrentTime = void 0; | ||
const shared_core_1 = require("@waiting/shared-core"); | ||
@@ -37,22 +37,17 @@ // import keysDto2DoSnake from 'snakecase-keys' | ||
/** | ||
* Convert keys of result to camelcase | ||
* Convert keys of result to camelcase, if input is object | ||
*/ | ||
function postProcessResponseToCamel(result, _queryContext) { | ||
if (Array.isArray(result)) { | ||
return result.map(row => genCamelKeysFrom(row)); | ||
const ret = result.map(row => postProcessResponseToCamel(row)); | ||
return ret; | ||
} | ||
else { | ||
return genCamelKeysFrom(result); | ||
else if (typeof result === 'object' && result) { | ||
const ret = genCamelKeysFrom(result); | ||
return ret; | ||
} | ||
return result; | ||
} | ||
exports.postProcessResponseToCamel = postProcessResponseToCamel; | ||
/** | ||
* Convert identifier (field) to snakecase | ||
*/ | ||
function wrapIdentifier(value, origImpl, _queryContext) { | ||
return origImpl((0, shared_core_1.camelToSnake)(value)); | ||
} | ||
exports.wrapIdentifier = wrapIdentifier; | ||
function genCamelKeysFrom(input) { | ||
// return keysDoToDtoCamel(input) | ||
return (0, shared_core_1.camelKeys)(input); | ||
@@ -67,2 +62,9 @@ } | ||
/** | ||
* Convert identifier (field) to snakecase | ||
*/ | ||
function wrapIdentifier(value, origImpl, _queryContext) { | ||
return origImpl((0, shared_core_1.camelToSnake)(value)); | ||
} | ||
exports.wrapIdentifier = wrapIdentifier; | ||
/** | ||
* @description only one level | ||
@@ -69,0 +71,0 @@ */ |
{ | ||
"name": "kmore", | ||
"author": "waiting", | ||
"version": "28.1.0", | ||
"version": "28.2.0", | ||
"description": "A SQL query builder based on knex with powerful TypeScript type support", | ||
@@ -70,3 +70,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a556058d48e9ac633c2f421d68ba2791b03f5b01" | ||
"gitHead": "378630afcee9524efd51161fc6a1a1eb986d155b" | ||
} |
@@ -62,35 +62,38 @@ import { | ||
export type PostProcessPlain = number | string | undefined | null | boolean | ||
export type PostProcessRecord = Record<string, PostProcessPlain> | object | ||
export type PostProcessArray = PostProcessPlain[] | ||
export type PostProcessInput = PostProcessPlain | PostProcessRecord | PostProcessArray | ||
export type PostProcessRespRet<T extends PostProcessInput> = T extends PostProcessPlain | ||
? T | ||
: T extends PostProcessArray // before PostProcessRecord | ||
? PostProcessArray | ||
: T extends PostProcessRecord | ||
? RecordCamelKeys<T> | ||
: never | ||
/** | ||
* Convert keys of result to camelcase | ||
* Convert keys of result to camelcase, if input is object | ||
*/ | ||
export function postProcessResponseToCamel<T = unknown>( | ||
export function postProcessResponseToCamel<T extends PostProcessInput = PostProcessInput>( | ||
result: T, | ||
_queryContext: unknown, | ||
): RecordCamelKeys<T, '_'>[] | RecordCamelKeys<T, '_'> { | ||
_queryContext?: unknown, | ||
): PostProcessRespRet<T> { | ||
if (Array.isArray(result)) { | ||
return result.map(row => genCamelKeysFrom(row)) | ||
const ret = result.map(row => postProcessResponseToCamel(row)) | ||
return ret as PostProcessRespRet<T> | ||
} | ||
else { | ||
return genCamelKeysFrom(result) | ||
else if (typeof result === 'object' && result) { | ||
const ret = genCamelKeysFrom(result) | ||
return ret as PostProcessRespRet<T> | ||
} | ||
} | ||
/** | ||
* Convert identifier (field) to snakecase | ||
*/ | ||
export function wrapIdentifier( | ||
value: string, | ||
origImpl: (input: string) => string, | ||
_queryContext: unknown, | ||
): string { | ||
return origImpl(camelToSnake(value)) | ||
return result as PostProcessRespRet<T> | ||
} | ||
export function genCamelKeysFrom<From>( | ||
export function genCamelKeysFrom<From extends PostProcessRecord>( | ||
input: From, | ||
): RecordCamelKeys<From, '_'> { | ||
// return keysDoToDtoCamel(input) | ||
return camelKeys(input) | ||
@@ -107,3 +110,14 @@ } | ||
/** | ||
* Convert identifier (field) to snakecase | ||
*/ | ||
export function wrapIdentifier( | ||
value: string, | ||
origImpl: (input: string) => string, | ||
_queryContext: unknown, | ||
): string { | ||
return origImpl(camelToSnake(value)) | ||
} | ||
/** | ||
@@ -110,0 +124,0 @@ * @description only one level |
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
76619
1232