kmore-types
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [2.0.0](https://github.com/waitingsong/kmore/compare/v1.1.1...v2.0.0) (2020-07-13) | ||
### Features | ||
* **kmore-types:** refactor types ([314c956](https://github.com/waitingsong/kmore/commit/314c956c014fcea88bcc3726e8e9908ad213aebb)) | ||
# [1.1.0](https://github.com/waitingsong/kmore/compare/v0.21.0...v1.1.0) (2020-07-12) | ||
@@ -8,0 +19,0 @@ |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 0.21.0 | ||
* @version 1.1.0 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
@@ -1,2 +0,2 @@ | ||
import { DbCols, DbModel, DbAliasCols } from './model'; | ||
import { DbAliasCols, DbCols, DbModel } from './model'; | ||
export declare function genAliasColumns<D extends DbModel>(scopedColumns: DbCols<D>): DbAliasCols<D>; |
@@ -1,4 +0,4 @@ | ||
import { UnionToIntersection, DbModel, TableModel } from '@waiting/shared-types'; | ||
import { AliasColumn, DbModel, TableAliasCols, TableModel } from '@waiting/shared-types'; | ||
import type { CallExpression, JSDocTagInfo, SourceFile, TypeChecker } from 'typescript'; | ||
export { DbModel, TableModel, }; | ||
export { AliasColumn, DbModel, TableAliasCols, TableModel, }; | ||
export declare enum KmorePropKeys { | ||
@@ -268,27 +268,2 @@ 'dbh' = "dbh", | ||
}; | ||
/** | ||
* ``` | ||
* @returns if TAC valid | ||
* ```ts | ||
* interface { | ||
* uid: { | ||
* tbUserUid: "tb_user.uid" | ||
* }, | ||
* name: { | ||
* tbUserName: "tb_user.name" | ||
* } | ||
* } | ||
* if TAC void | ||
* ```ts | ||
* interface { | ||
* uid: Record<string, string> | ||
* name: Record<string, string> | ||
* } | ||
* ``` | ||
*/ | ||
export declare type TableAliasCols<TModel extends TableModel = TableModel, TAC = void> = { | ||
[fld in keyof TModel]: TAC extends void ? KnexColumnsParma : fld extends keyof TAC ? { | ||
[out in keyof TAC[fld]]: TAC[fld][out]; | ||
} : KnexColumnsParma; | ||
}; | ||
export declare type TableAlias = string; | ||
@@ -349,114 +324,2 @@ export declare type TableColAlias = string; | ||
} | ||
/** | ||
* output field: inupt field | ||
* { | ||
* uid: 'tb_user_detail.uid', | ||
* tbUserDetailUid: 'tb_user_detail.uid', | ||
* tbUserDetailAge: 'tb_user_detail.age', | ||
* } | ||
*/ | ||
export interface KnexColumnsParma { | ||
[out: string]: string; | ||
} | ||
/** | ||
* Generate TableAlias type from TableModel and typeof AliasConst | ||
* | ||
* @example ```ts | ||
* TableModelFromAlias<User, typeof acUser> | ||
* ``` | ||
* @param T - table model ```ts | ||
* interface User { | ||
* uid: number | ||
* name: string | ||
* ctime: Date | string | ||
* } | ||
* ``` | ||
* @param TAliasConst - type from a variable/const, not a interface/type directly ```ts | ||
* const acUser = { | ||
* uid: { tbUserUid: 'tb_user.uid' }, | ||
* name: { tbUserName: 'tb_user.name' }, | ||
* ctime: { tbUserCtime: 'tb_user.ctime' }, | ||
* } as const | ||
* typeof acUser | ||
* ``` | ||
* @returns ```ts | ||
* type { | ||
* tbUserUid: number | ||
* tbUserName: string | ||
* tbUserCtime: Date | string | ||
* 'tb_user.uid': number | ||
* 'tb_user.name': string | ||
* 'tb_user.ctime': Date | string | ||
* } | ||
* ``` | ||
*/ | ||
export declare type TableModelFromAlias<T extends TableModel, TAliasConst extends TableAliasCols<T>> = Readonly<TypeFromJointTable<JointTableFromAliasConst<T, TAliasConst>>>; | ||
/** | ||
* | ||
* @example ```ts | ||
* interface UserAlias { | ||
* uid: { | ||
* tbUserUid: number | ||
* 'tb_user.uid': number | ||
* } | ||
* name: { | ||
* tbUserName: string | ||
* 'tb_user.name': string | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
interface AliasTableModel { | ||
[fld: string]: TableModel; | ||
} | ||
declare type TypeFromJointTable<T extends AliasTableModel> = OverwriteNeverToUnknown<UnionToIntersection<FlateJointTable<T>>>; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { tbUserUid: number } | ||
* name: { tbUserName: string } | ||
* ... | ||
* } & { | ||
* uid: { 'tb_user.uid': number } | ||
* name: { 'tb_user.name': string } | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromAliasConst<TModel extends TableModel, TAliasConst extends TableAliasCols<TModel>> = JointTableFromAliasConstKey<TModel, TAliasConst> & JointTableFromAliasConstValue<TModel, TAliasConst>; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { tbUserUid: number } | ||
* name: { tbUserName: string } | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromAliasConstKey<TModel extends TableModel, TAliasConst extends TableAliasCols<TModel>> = { | ||
[fld in keyof TModel]: { | ||
[output in keyof TAliasConst[fld]]: TModel[fld]; | ||
}; | ||
}; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { 'tb_user.uid': number } | ||
* name: { 'tb_user.name': string } | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromAliasConstValue<TModel extends TableModel, TAliasConst extends TableAliasCols<TModel>> = { | ||
[fld in keyof TModel]: { | ||
[output in TAliasConst[fld][keyof TAliasConst[fld]]]: TModel[fld]; | ||
}; | ||
}; | ||
declare type OverwriteNeverToUnknown<T extends any> = T extends TableModel ? { | ||
[fld in keyof T]: T[fld] extends never ? unknown : T[fld]; | ||
} : never; | ||
declare type FlateJointTable<T extends AliasTableModel> = T extends { | ||
[fld: string]: infer F; | ||
} ? F extends TableModel ? { | ||
[output in keyof F]: F[output]; | ||
} : never : never; | ||
export declare type CreateColumnNameFn = (options: CreateColumnNameOpts) => string; | ||
@@ -463,0 +326,0 @@ export interface CreateColumnNameOpts { |
{ | ||
"name": "kmore-types", | ||
"author": "waiting", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Retrieve types info from ts file", | ||
@@ -88,3 +88,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "de9a962e725764f8dcaed607d7a5a2ab4320aed5" | ||
"gitHead": "6b7a32135b8b1c50eb7c96da2eb78b3f1392bb5b" | ||
} |
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
1
250403
13
3761