@waiting/shared-types
Advanced tools
Comparing version 4.6.1 to 4.7.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [4.7.0](https://github.com/waitingsong/shared-types/compare/v4.6.1...v4.7.0) (2020-07-13) | ||
### Features | ||
* **types:** add types for database ([5af329e](https://github.com/waitingsong/shared-types/commit/5af329e621576d7016009ed3a8870cbc7093c881)) | ||
## [4.6.1](https://github.com/waitingsong/shared-types/compare/v4.6.0...v4.6.1) (2020-07-11) | ||
@@ -8,0 +19,0 @@ |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 4.6.0 | ||
* @version 4.6.1 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
import { OverwriteNeverToUnknown } from './common'; | ||
import { UnionToIntersection } from './union2tuple'; | ||
/** | ||
@@ -27,2 +28,51 @@ * Database's tables definition (extends DbModel) | ||
/** | ||
* | ||
* @example ```ts | ||
* interface UserAlias { | ||
* uid: { | ||
* tbUserUid: number | ||
* 'tb_user.uid': number | ||
* } | ||
* name: { | ||
* tbUserName: string | ||
* 'tb_user.name': string | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export interface AliasTableModel { | ||
[fld: string]: TableModel; | ||
} | ||
/** | ||
* @example ```ts | ||
* { | ||
* uid: { | ||
* uid: 'tb_user_detail.uid', | ||
* tbUserUid: 'tb_user_detail.uid', | ||
* }, | ||
* name: { | ||
* name: 'tb_user_detail.name', | ||
* tbUserName: 'tb_user.name', | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export declare type TableAliasCols<TModel extends TableModel = TableModel, TAC = void> = { | ||
[fld in keyof TModel]: TAC extends void ? AliasColumn : fld extends keyof TAC ? { | ||
[out in keyof TAC[fld]]: TAC[fld][out]; | ||
} : AliasColumn; | ||
}; | ||
/** | ||
* Column alias mapping | ||
* key for output field, value for inupt field | ||
* @example ```ts | ||
* { | ||
* uid: 'tb_user_detail.uid', | ||
* tbUserDetailUid: 'tb_user_detail.uid', | ||
* tbUserDetailAge: 'tb_user_detail.age', | ||
* } | ||
* ``` | ||
*/ | ||
export declare type AliasColumn = Record<string, string>; | ||
/** | ||
* Join two table, never type will be converted to unknown | ||
@@ -35,1 +85,143 @@ */ | ||
export declare type JoinTableUnique<L extends TableModel, R extends TableModel, KeyExcludeOptional extends keyof L | keyof R | void = void> = JoinTable<L, R, KeyExcludeOptional | (keyof L & keyof R)>; | ||
export declare type PickDuplicateKeys<L extends TableModel, R extends TableModel> = (keyof L & keyof R); | ||
/** | ||
* Generate TableAlias model from TableModel and DictAliasCols, | ||
* keys from input of AcUser. | ||
* | ||
* @example ```ts | ||
* type Foo = TableModelFromAlias<User, AcUser> | ||
* ``` | ||
* @param T - table model ```ts | ||
* interface User { | ||
* uid: number | ||
* name: string | ||
* } | ||
* ``` | ||
* @param TAC - DictType['aliasColumns'][<table>] ```ts | ||
* type AcUser = { | ||
* uid: { tbUserUid: 'tb_user.uid' }, | ||
* name: { tbUserName: 'tb_user.name' }, | ||
* } | ||
* ``` | ||
* @returns ```ts | ||
* type { | ||
* tbUserUid: number | ||
* tbUserName: string | ||
* } | ||
* ``` | ||
*/ | ||
export declare type TableModelFromDictAlias<T extends TableModel, TAC extends TableAliasCols<T>, IncludeKeys extends (keyof T & keyof TAC) | void = void> = Readonly<TypeFromJointTable<JointTableFromDictAliasColsKey<T, TAC, IncludeKeys>>>; | ||
/** | ||
* Generate TableAlias model from TableModel and DictAliasCols, | ||
* keys from output of AcUser. | ||
* | ||
* @example ```ts | ||
* type Foo = TableModelFromAlias<User, AcUser> | ||
* ``` | ||
* @param T - table model ```ts | ||
* interface User { | ||
* uid: number | ||
* name: string | ||
* } | ||
* ``` | ||
* @param TAC - DictType['aliasColumns'][<table>] ```ts | ||
* type AcUser = { | ||
* uid: { tbUserUid: 'tb_user.uid' }, | ||
* name: { tbUserName: 'tb_user.name' }, | ||
* } | ||
* ``` | ||
* @returns ```ts | ||
* type { | ||
* 'tb_user.uid': number | ||
* 'tb_user.name': string | ||
* } | ||
* ``` | ||
*/ | ||
export declare type InverseTableModelFromDictAlias<T extends TableModel, TAC extends TableAliasCols<T>, IncludeKeys extends (keyof T & keyof TAC) | void = void> = Readonly<TypeFromJointTable<JointTableFromDictAliasColsValue<T, TAC, IncludeKeys>>>; | ||
/** | ||
* Generate TableAlias model from TableModel and DictAliasCols, | ||
* keys from both input and output of AcUser. | ||
* | ||
* @example ```ts | ||
* type Foo = TableModelFromAlias<User, AcUser> | ||
* ``` | ||
* @param T - table model ```ts | ||
* interface User { | ||
* uid: number | ||
* name: string | ||
* } | ||
* ``` | ||
* @param TAC - DictType['aliasColumns'][<table>] ```ts | ||
* type acUser = { | ||
* uid: { tbUserUid: 'tb_user.uid' }, | ||
* name: { tbUserName: 'tb_user.name' }, | ||
* } | ||
* ``` | ||
* @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 FullTableModelFromDictAlias<T extends TableModel, TAC extends TableAliasCols<T>, IncludeKeys extends (keyof T & keyof TAC) | void = void> = Readonly<TypeFromJointTable<JointTableFromDictAliasCols<T, TAC, IncludeKeys>>>; | ||
declare type TypeFromJointTable<T extends AliasTableModel> = UnionToIntersection<FlateJointTable<T>>; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { tbUserUid: number } | ||
* name: { tbUserName: string } | ||
* ... | ||
* } & { | ||
* uid: { 'tb_user.uid': number } | ||
* name: { 'tb_user.name': string } | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromDictAliasCols<TModel extends TableModel, TAliasCols extends TableAliasCols<TModel>, IncludeKeys extends (keyof TModel & keyof TAliasCols) | void = void> = JointTableFromDictAliasColsKey<TModel, TAliasCols, IncludeKeys> & JointTableFromDictAliasColsValue<TModel, TAliasCols, IncludeKeys>; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { tbUserUid: number } | ||
* name: { tbUserName: string } | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromDictAliasColsKey<TModel extends TableModel, TAliasCols extends TableAliasCols<TModel>, IncludeKeys extends (keyof TModel & keyof TAliasCols) | void = void> = IncludeKeys extends string | number ? { | ||
[fld in IncludeKeys]: { | ||
[output in keyof TAliasCols[fld]]: TModel[fld]; | ||
}; | ||
} : { | ||
[fld in keyof TModel]: { | ||
[output in keyof TAliasCols[fld]]: TModel[fld]; | ||
}; | ||
}; | ||
/** | ||
* @returns ```ts | ||
* { | ||
* uid: { 'tb_user.uid': number } | ||
* name: { 'tb_user.name': string } | ||
* ... | ||
* } | ||
* ``` | ||
*/ | ||
declare type JointTableFromDictAliasColsValue<TModel extends TableModel, TAliasCols extends TableAliasCols<TModel>, IncludeKeys extends (keyof TModel & keyof TAliasCols) | void = void> = IncludeKeys extends string | number ? { | ||
[fld in IncludeKeys]: { | ||
[output in TAliasCols[fld][keyof TAliasCols[fld]]]: TModel[fld]; | ||
}; | ||
} : { | ||
[fld in keyof TModel]: { | ||
[output in TAliasCols[fld][keyof TAliasCols[fld]]]: TModel[fld]; | ||
}; | ||
}; | ||
declare type FlateJointTable<T extends AliasTableModel> = T extends { | ||
[fld: string]: infer F; | ||
} ? F extends TableModel ? { | ||
[output in keyof F]: F[output]; | ||
} : never : never; | ||
export {}; |
{ | ||
"name": "@waiting/shared-types", | ||
"author": "waiting", | ||
"version": "4.6.1", | ||
"version": "4.7.0", | ||
"description": "shared typescript types", | ||
@@ -74,3 +74,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "9c044dcd942b6748ae97cc159d4069a72660c111" | ||
"gitHead": "084046ce0565b8320d358d4650faf95eb6d9c49f" | ||
} |
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
25815
489