Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kmore-types

Package Overview
Dependencies
Maintainers
1
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kmore-types - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

18

CHANGELOG.md

@@ -6,2 +6,20 @@ # Change Log

# [0.16.0](https://github.com/waitingsong/kmore/compare/v0.15.0...v0.16.0) (2020-04-14)
### Bug Fixes
* **kmore-types:** loadVarFromFile() ([38f3765](https://github.com/waitingsong/kmore/commit/38f37655b40e5fd48b9f7cdca649aa19bca70961))
### Features
* **kmore-types:** export all funcs of build.ts ([f174de2](https://github.com/waitingsong/kmore/commit/f174de21b24a9beb527dfb9296d4041e07f1d951))
* joint table alias ([7fa9fff](https://github.com/waitingsong/kmore/commit/7fa9fff364be0c7e97f7d54c4fe53ad7cf28577e))
* **kmore-types:** add tyeps BaseMultiTableColumns ([3d4e810](https://github.com/waitingsong/kmore/commit/3d4e8104f44f868368dbd1bd890005f864927488))
# [0.15.0](https://github.com/waitingsong/kmore/compare/v0.14.0...v0.15.0) (2020-03-20)

@@ -8,0 +26,0 @@

196

dist/index.cjs.js

@@ -5,3 +5,3 @@ /**

*
* @version 0.14.0
* @version 0.15.0
* @author waiting

@@ -18,5 +18,5 @@ * @license MIT

var operators = require('rxjs/operators');
var rxjs = require('rxjs');
var sourceMapSupport = require('source-map-support');
var rxwalker = require('rxwalker');
var rxjs = require('rxjs');

@@ -30,3 +30,2 @@ const globalCallerFuncNameSet = new Set(['genTbListFromType', 'kmore']);

exportVarPrefix: 'tbs_',
exportVarColsSuffix: '_cols',
forceLoadTbListJs: false,

@@ -54,2 +53,3 @@ forceLoadTbListJsPathReplaceRules: null,

DbPropKeys["scopedColumns"] = "scopedColumns";
DbPropKeys["aliasColumns"] = "aliasColumns";
DbPropKeys["refTables"] = "rb";

@@ -76,2 +76,3 @@ })(exports.DbPropKeys || (exports.DbPropKeys = {}));

ColumnExtPropKeys["sColsCacheMap"] = "_scopedColsCacheMap";
ColumnExtPropKeys["genFieldsAliasFn"] = "genFieldsAlias";
})(exports.ColumnExtPropKeys || (exports.ColumnExtPropKeys = {}));

@@ -313,3 +314,3 @@

/**
* Load kTables var from a js file
* Load kTablesBase var from a js file
*/

@@ -319,6 +320,7 @@ function loadVarFromFile(loadOpts) {

const tbVarName = genVarName(options.exportVarPrefix, caller.line, caller.column);
const colVarName = `${tbVarName}${options.exportVarColsSuffix}`;
const tableVarName = `${tbVarName}_${exports.DbPropKeys.tables}`;
const colVarName = `${tbVarName}_${exports.DbPropKeys.columns}`;
const mods = loadFile(path);
if (mods && typeof mods[tbVarName] === 'object') {
const tables = mods[tbVarName];
const tables = mods[tableVarName];
const columns = typeof mods[colVarName] === 'object'

@@ -463,31 +465,35 @@ ? mods[colVarName]

const { node, checker, sourceFile, path, } = options;
const typeName = retrieveGenericsIdentifierFromTypeArguments(node);
if (!node.typeArguments || !node.typeArguments[0]) {
return;
}
// const typeName: Identifier | void = retrieveGenericsIdentifierFromTypeArguments(node)
// if (typeName && typeName.getText()) {
// const gType = checker.getTypeAtLocation(typeName)
// }
const gType = checker.getTypeFromTypeNode(node.typeArguments[0]);
// const props = checker.getPropertiesOfType(type2)
/* istanbul ignore else */
if (typeName && typeName.getText()) {
const gType = checker.getTypeAtLocation(typeName);
if (gType && gType.symbol) {
const sym = gType.getSymbol();
if (!sym) {
return;
}
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const inputTypeName = sym.getName();
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:4:1:typeid-TbListModel"
const callerTypeId = `${path}:${line + 1}:${character + 1}:typeid-${inputTypeName}`;
// @ts-ignore
// const gTypeId: number = typeof gType.id === 'number' ? gType.id : Math.random()
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-76"
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-TbListModel"
const localTypeId = `${path}:typeid-${inputTypeName}`;
const { tbTagMap, tbColTagMap } = genTbListTagMapFromSymbol(gType.symbol, checker);
/* istanbul ignore else */
if (gType && gType.symbol) {
const sym = gType.getSymbol();
if (!sym) {
return;
}
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const inputTypeName = sym.getName();
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:4:1:typeid-TbListModel"
const callerTypeId = `${path}:${line + 1}:${character + 1}:typeid-${inputTypeName}`;
// @ts-ignore
// const gTypeId: number = typeof gType.id === 'number' ? gType.id : Math.random()
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-76"
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-TbListModel"
const localTypeId = `${path}:typeid-${inputTypeName}`;
const { tbTagMap, tbColTagMap } = genTbListTagMapFromSymbol(gType.symbol, checker);
/* istanbul ignore else */
if (tbTagMap.size) {
return {
callerTypeId,
localTypeId,
tbTagMap,
tbColTagMap,
};
}
if (tbTagMap.size) {
return {
callerTypeId,
localTypeId,
tbTagMap,
tbColTagMap,
};
}

@@ -552,11 +558,12 @@ }

}
function retrieveGenericsIdentifierFromTypeArguments(node) {
/* istanbul ignore else */
if (!node.typeArguments || node.typeArguments.length !== 1) {
return;
}
const [typeNode] = node.typeArguments;
// @ts-ignore
return typeNode.typeName;
}
// function retrieveGenericsIdentifierFromTypeArguments(node: CallExpression): Identifier | void {
// /* istanbul ignore else */
// if (! node.typeArguments || node.typeArguments.length !== 1) {
// return
// }
// // typeNode TypeReference = 169
// const [typeNode] = node.typeArguments
// // @ts-ignore
// return typeNode.typeName
// }
function matchSourceFileWithFilePath(path) {

@@ -658,3 +665,3 @@ // eslint-disable-next-line import/no-extraneous-dependencies

const build$ = walk$.pipe(operators.mergeMap((path) => {
return rxjs.defer(() => buildSrcTablesFile(path, opts));
return buildSrcTablesFile(path, opts);
}, opts.concurrent));

@@ -673,13 +680,23 @@ return build$;

};
const ret = retrieveTypeFromTsFile(file);
if (ret && ret.size) {
const path = await saveFile(ret, opts);
return path.replace(/\\/gu, '/');
let path = '';
let content = '';
const map = retrieveTypeFromTsFile(file);
if (map && map.size) {
map.forEach((arr, key) => {
const [str, code] = genTsCodeFromTypes(key, arr, opts);
if (!path) {
path = str; // all value are the same one
}
content += code;
});
if (!path) {
throw new Error('path value is empty');
}
await saveFile(path, content, opts.outputBanner);
path = path.replace(/\\/ug, '/');
}
else {
return '';
}
return path;
}
function retrieveTypeFromTsFile(file) {
const path = sharedCore.pathResolve(file).replace(/\\/gu, '/');
const path = sharedCore.pathResolve(file).replace(/\\/ug, '/');
const { checker, sourceFile } = matchSourceFileWithFilePath(path);

@@ -695,4 +712,4 @@ const ret = new Map();

const tbs = buildTbListParam(tbListTagMap);
const tbCols = buildTbColListParam(tbColListTagMap);
ret.set(callerTypeId, [tbs, tbCols]);
const mtCols = buildTbColListParam(tbColListTagMap);
ret.set(callerTypeId, [tbs, mtCols]);
});

@@ -702,23 +719,34 @@ }

}
function genTsCodeFromTypes(inputMap, options) {
const { exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix, } = options;
let targetPath = '';
const sourceArr = [];
inputMap.forEach(([tbs, tbCols], key) => {
const { path, line, column } = pickInfoFromCallerTypeId(key);
if (!targetPath) {
// const relativePath = relative(base, path)
targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
}
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbColVarName = `${tbVarName}${exportVarColsSuffix}`;
sourceArr.push(`export const ${tbVarName} = ${JSON.stringify(tbs, null, 2)} as const`);
sourceArr.push(`export const ${tbColVarName} = ${JSON.stringify(tbCols, null, 2)} as const`);
});
return [targetPath, sourceArr.join('\n\n')];
function genTsCodeFromTypes(callerTypeId, arr, options) {
let path = '';
const codeArr = [];
const [str, code] = genTablesTsCodeFromTypes(callerTypeId, arr[0], options.exportVarPrefix, exports.DbPropKeys.tables, options.outputFileNameSuffix);
if (!path) {
path = str; // all value are the same one
}
codeArr.push(code);
const [, code2] = genColsTsCodeFromTypes(callerTypeId, arr[1], options.exportVarPrefix, exports.DbPropKeys.columns, options.outputFileNameSuffix);
codeArr.push(code2);
return [path, codeArr.join('\n\n')];
}
/** Save tables of one file */
async function saveFile(inputMap, options) {
const { outputBanner: outputPrefix } = options;
const [path, code] = genTsCodeFromTypes(inputMap, options);
function genTablesTsCodeFromTypes(callerTypeId, tables, exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix) {
const { path, line, column } = pickInfoFromCallerTypeId(callerTypeId);
// const relativePath = relative(base, path)
const targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbTableVarName = `${tbVarName}_${exportVarColsSuffix}`;
const code = `export const ${tbTableVarName} = ${JSON.stringify(tables, null, 2)} as const`;
return [targetPath, code];
}
function genColsTsCodeFromTypes(callerTypeId, columns, exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix) {
const { path, line, column } = pickInfoFromCallerTypeId(callerTypeId);
// const relativePath = relative(base, path)
const targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbColVarName = `${tbVarName}_${exportVarColsSuffix}`;
const code = `export const ${tbColVarName} = ${JSON.stringify(columns, null, 2)} as const`;
return [targetPath, code];
}
/** Save (k)tables of one file */
async function saveFile(path, code, outputPrefix) {
const retCode = outputPrefix

@@ -796,2 +824,3 @@ ? `${outputPrefix}\n\n${code}\n\n`

const [tbListTagMap, tbColListTagMap] = tagsMapArr;
// const jointColumns = genJointColListTagMap(tbColListTagMap)
const ret = {

@@ -803,2 +832,17 @@ tables: buildTbListParam(tbListTagMap),

}
// function genJointColListTagMap(tbColListTagMap: TbColListTagMap): TbJointColListTagMap {
// const ret: TbJointColListTagMap = new Map()
// tbColListTagMap.forEach((colListTagMap, tb) => {
// colListTagMap.forEach((tagInfo[], colAlias) => {
// })
// })
// return ret
// }
function snakeToCamel(string) {
return string.replace(/([-_][a-z])/iug, ($1) => {
return $1.toUpperCase()
.replace('-', '')
.replace('_', '');
});
}
function retrieveLocalTypeItemFromType(options) {

@@ -862,6 +906,9 @@ const { caller } = options;

exports.genCallerTypeMapFromNodeSet = genCallerTypeMapFromNodeSet;
exports.genColsTsCodeFromTypes = genColsTsCodeFromTypes;
exports.genInfoFromNode = genInfoFromNode;
exports.genTablesTsCodeFromTypes = genTablesTsCodeFromTypes;
exports.genTbListFromCaller = genTbListFromCaller;
exports.genTbListFromType = genTbListFromType;
exports.genTbListTsFilePath = genTbListTsFilePath;
exports.genTsCodeFromTypes = genTsCodeFromTypes;
exports.genVarName = genVarName;

@@ -887,2 +934,5 @@ exports.getCallerStack = getCallerStack;

exports.retrieveLocalTypeItemFromType = retrieveLocalTypeItemFromType;
exports.retrieveTypeFromTsFile = retrieveTypeFromTsFile;
exports.saveFile = saveFile;
exports.snakeToCamel = snakeToCamel;
exports.validateDuplicateProp = validateDuplicateProp;

@@ -889,0 +939,0 @@ exports.validateParamTables = validateParamTables;

import { Observable } from 'rxjs';
import { TTables, FilePath, BuildSrcOpts } from './model';
import { TTables, FilePath, Tables, CallerTbListMap, BuildSrcOpts, CallerTypeId, MultiTableColsCommon, TablesMapArrCommon } from './model';
/**

@@ -14,1 +14,7 @@ * Generate tables .ts files,

export declare function buildSrcTablesFile<T extends TTables>(file: string, options: BuildSrcOpts): Promise<FilePath>;
export declare function retrieveTypeFromTsFile<T extends TTables>(file: FilePath): CallerTbListMap<T>;
export declare function genTsCodeFromTypes<T extends TTables>(callerTypeId: CallerTypeId, arr: TablesMapArrCommon<T>, options: Required<BuildSrcOpts>): [FilePath, string];
export declare function genTablesTsCodeFromTypes<T extends TTables>(callerTypeId: CallerTypeId, tables: Tables<T>, exportVarPrefix: string, exportVarColsSuffix: string, outputFileNameSuffix: string): [FilePath, string];
export declare function genColsTsCodeFromTypes<T extends TTables>(callerTypeId: CallerTypeId, columns: MultiTableColsCommon<T>, exportVarPrefix: string, exportVarColsSuffix: string, outputFileNameSuffix: string): [FilePath, string];
/** Save (k)tables of one file */
export declare function saveFile(path: string, code: string, outputPrefix: string): Promise<FilePath>;
import { pathResolve, writeFileAsync } from '@waiting/shared-core';
import { mergeMap } from 'rxjs/operators';
import { defer } from 'rxjs';
import { buildTbListParam, genTbListTsFilePath, genVarName, walkDirForCallerFuncTsFiles, buildTbColListParam, } from './util';
import { initBuildSrcOpts, globalCallerFuncNameSet } from './config';
import { initBuildSrcOpts, globalCallerFuncNameSet, DbPropKeys } from './config';
import { pickInfoFromCallerTypeId, genCallerTypeMapFromNodeSet, matchSourceFileWithFilePath, walkNode, } from './ts-util';

@@ -18,3 +17,3 @@ /**

const build$ = walk$.pipe(mergeMap((path) => {
return defer(() => buildSrcTablesFile(path, opts));
return buildSrcTablesFile(path, opts);
}, opts.concurrent));

@@ -33,13 +32,23 @@ return build$;

};
const ret = retrieveTypeFromTsFile(file);
if (ret && ret.size) {
const path = await saveFile(ret, opts);
return path.replace(/\\/gu, '/');
let path = '';
let content = '';
const map = retrieveTypeFromTsFile(file);
if (map && map.size) {
map.forEach((arr, key) => {
const [str, code] = genTsCodeFromTypes(key, arr, opts);
if (!path) {
path = str; // all value are the same one
}
content += code;
});
if (!path) {
throw new Error('path value is empty');
}
await saveFile(path, content, opts.outputBanner);
path = path.replace(/\\/ug, '/');
}
else {
return '';
}
return path;
}
function retrieveTypeFromTsFile(file) {
const path = pathResolve(file).replace(/\\/gu, '/');
export function retrieveTypeFromTsFile(file) {
const path = pathResolve(file).replace(/\\/ug, '/');
const { checker, sourceFile } = matchSourceFileWithFilePath(path);

@@ -55,4 +64,4 @@ const ret = new Map();

const tbs = buildTbListParam(tbListTagMap);
const tbCols = buildTbColListParam(tbColListTagMap);
ret.set(callerTypeId, [tbs, tbCols]);
const mtCols = buildTbColListParam(tbColListTagMap);
ret.set(callerTypeId, [tbs, mtCols]);
});

@@ -62,23 +71,34 @@ }

}
function genTsCodeFromTypes(inputMap, options) {
const { exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix, } = options;
let targetPath = '';
const sourceArr = [];
inputMap.forEach(([tbs, tbCols], key) => {
const { path, line, column } = pickInfoFromCallerTypeId(key);
if (!targetPath) {
// const relativePath = relative(base, path)
targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
}
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbColVarName = `${tbVarName}${exportVarColsSuffix}`;
sourceArr.push(`export const ${tbVarName} = ${JSON.stringify(tbs, null, 2)} as const`);
sourceArr.push(`export const ${tbColVarName} = ${JSON.stringify(tbCols, null, 2)} as const`);
});
return [targetPath, sourceArr.join('\n\n')];
export function genTsCodeFromTypes(callerTypeId, arr, options) {
let path = '';
const codeArr = [];
const [str, code] = genTablesTsCodeFromTypes(callerTypeId, arr[0], options.exportVarPrefix, DbPropKeys.tables, options.outputFileNameSuffix);
if (!path) {
path = str; // all value are the same one
}
codeArr.push(code);
const [, code2] = genColsTsCodeFromTypes(callerTypeId, arr[1], options.exportVarPrefix, DbPropKeys.columns, options.outputFileNameSuffix);
codeArr.push(code2);
return [path, codeArr.join('\n\n')];
}
/** Save tables of one file */
async function saveFile(inputMap, options) {
const { outputBanner: outputPrefix } = options;
const [path, code] = genTsCodeFromTypes(inputMap, options);
export function genTablesTsCodeFromTypes(callerTypeId, tables, exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix) {
const { path, line, column } = pickInfoFromCallerTypeId(callerTypeId);
// const relativePath = relative(base, path)
const targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbTableVarName = `${tbVarName}_${exportVarColsSuffix}`;
const code = `export const ${tbTableVarName} = ${JSON.stringify(tables, null, 2)} as const`;
return [targetPath, code];
}
export function genColsTsCodeFromTypes(callerTypeId, columns, exportVarPrefix, exportVarColsSuffix, outputFileNameSuffix) {
const { path, line, column } = pickInfoFromCallerTypeId(callerTypeId);
// const relativePath = relative(base, path)
const targetPath = genTbListTsFilePath(path, outputFileNameSuffix);
const tbVarName = genVarName(exportVarPrefix, line, column);
const tbColVarName = `${tbVarName}_${exportVarColsSuffix}`;
const code = `export const ${tbColVarName} = ${JSON.stringify(columns, null, 2)} as const`;
return [targetPath, code];
}
/** Save (k)tables of one file */
export async function saveFile(path, code, outputPrefix) {
const retCode = outputPrefix

@@ -85,0 +105,0 @@ ? `${outputPrefix}\n\n${code}\n\n`

@@ -7,2 +7,3 @@ import { RetrieveInfoFromTypeOpts, CallerInfo, GenTbListFromTypeOpts, TTables, KTablesBase, LocalTypeItem } from './model';

export declare function genTbListFromCaller<T extends TTables>(caller: CallerInfo, options: GenTbListFromTypeOpts): KTablesBase<T>;
export declare function snakeToCamel(string: string): string;
export declare function retrieveLocalTypeItemFromType(options: RetrieveInfoFromTypeOpts): LocalTypeItem | void;

@@ -69,2 +69,3 @@ import { buildTbListParam, buildTbColListParam, getCallerStack, isTsFile, } from './util';

const [tbListTagMap, tbColListTagMap] = tagsMapArr;
// const jointColumns = genJointColListTagMap(tbColListTagMap)
const ret = {

@@ -76,2 +77,17 @@ tables: buildTbListParam(tbListTagMap),

}
// function genJointColListTagMap(tbColListTagMap: TbColListTagMap): TbJointColListTagMap {
// const ret: TbJointColListTagMap = new Map()
// tbColListTagMap.forEach((colListTagMap, tb) => {
// colListTagMap.forEach((tagInfo[], colAlias) => {
// })
// })
// return ret
// }
export function snakeToCamel(string) {
return string.replace(/([-_][a-z])/iug, ($1) => {
return $1.toUpperCase()
.replace('-', '')
.replace('_', '');
});
}
export function retrieveLocalTypeItemFromType(options) {

@@ -78,0 +94,0 @@ const { caller } = options;

@@ -12,2 +12,3 @@ import { BuildSrcOpts, CacheMap, CallerFuncNameSet, GenTbListFromTypeOpts, Options } from './model';

'scopedColumns' = "scopedColumns",
'aliasColumns' = "aliasColumns",
'refTables' = "rb"

@@ -14,0 +15,0 @@ }

@@ -8,3 +8,2 @@ export const globalCallerFuncNameSet = new Set(['genTbListFromType', 'kmore']);

exportVarPrefix: 'tbs_',
exportVarColsSuffix: '_cols',
forceLoadTbListJs: false,

@@ -33,2 +32,3 @@ forceLoadTbListJsPathReplaceRules: null,

DbPropKeys["scopedColumns"] = "scopedColumns";
DbPropKeys["aliasColumns"] = "aliasColumns";
DbPropKeys["refTables"] = "rb";

@@ -35,0 +35,0 @@ })(DbPropKeys || (DbPropKeys = {}));

@@ -6,4 +6,2 @@ import { CallExpression, JSDocTagInfo, SourceFile, TypeChecker } from 'typescript';

exportVarPrefix: string;
/** Exported column vaiable name suffix. Default is "_cols", result will be "tbs_m_n_cols" */
exportVarColsSuffix: string;
/**

@@ -55,3 +53,3 @@ * Load js under ts env for debug,

export declare type TbListMap = Map<CallerId, Tables<object>>;
export declare type TbColListMap = Map<CallerId, TableCols<object>>;
export declare type TbColListMap = Map<CallerId, MultiTableCols<object>>;
/** Define what's genericsTypeId at the callexpression position */

@@ -66,7 +64,13 @@ export declare type CallerIdToLocalTypeIdMap = Map<CallerId, LocalTypeId>;

export declare type CallerTbListMap<T extends TTables> = Map<CallerTypeId, TablesMapArr<T>>;
export interface TablesMapArr<T extends TTables> extends Array<Tables<T> | TableCols<T> | TableScopedCols<T>> {
export interface TablesMapArr<T extends TTables> extends Array<Tables<T> | MultiTableCols<T>> {
0: Tables<T>;
1: TableCols<T>;
1: MultiTableCols<T>;
length: 2;
}
export interface TablesMapArrCommon<T extends TTables> extends Array<Tables<T> | MultiTableColsCommon<T>> {
0: Tables<T>;
1: MultiTableColsCommon<T>;
length: 2;
}
export declare type MultiTableColsCommon<T extends TTables> = MultiTableCols<T> | MultiTableScopedCols<T> | MultiTableAliasCols<T>;
/** GenericsTypeId scope in the file */

@@ -78,2 +82,3 @@ export declare type LocalTypeMap = Map<LocalTypeId, TagsMapArr>;

export declare type TbScopedColListTagMap = Map<TableAlias, ColListTagMap>;
export declare type TbJointColListTagMap = Map<TableAlias, ColListTagMap>;
export declare type ColListTagMap = Map<TableColAlias, JSDocTagInfo[]>;

@@ -122,3 +127,3 @@ export interface TbTagsMap {

*/
columns: TableCols<T>;
columns: MultiTableCols<T>;
}

@@ -135,9 +140,10 @@ /**

*/
export declare type TableCols<T extends TTables> = T extends void ? EmptyTbList : T extends never ? EmptyTbList : Columns<T>;
export declare type MultiTableCols<T extends TTables> = T extends void ? EmptyTbList : T extends never ? EmptyTbList : Columns<T>;
export declare enum ColumnExtPropKeys {
tableAlias = "_tableAlias",
tablesRef = "_tablesRef",
sColsCacheMap = "_scopedColsCacheMap"
sColsCacheMap = "_scopedColsCacheMap",
genFieldsAliasFn = "genFieldsAlias"
}
export declare type Columns<T extends TTables> = ScopedColumns<T> & {
export declare type Columns<T extends TTables> = BaseMultiTableColumns<T> & {
readonly [ColumnExtPropKeys.tableAlias]: TableAlias;

@@ -149,10 +155,22 @@ readonly [ColumnExtPropKeys.tablesRef]: KTablesBase<T>['tables'];

* Type of db.tableCols.tb_foo.col_bar,
* value wiht table prefix, eg. `tb_foo.col_name`
* value with table prefix, eg. `tb_foo.col_name`
*/
export declare type TableScopedCols<T extends TTables> = T extends void ? EmptyTbList : T extends never ? EmptyTbList : ScopedColumns<T>;
export declare type ScopedColumns<T extends TTables> = {
readonly [tbAlias in keyof T]: {
readonly [colAlias in keyof T[tbAlias]]: string;
};
export declare type MultiTableScopedCols<T extends TTables> = T extends void ? EmptyTbList : T extends never ? EmptyTbList : ScopedColumns<T>;
/**
* {
* tbAlias1:
* {
* colAlias1: tbName.colName,
* ...
* },
* ...
* }
*/
export declare type ScopedColumns<T extends TTables> = BaseMultiTableColumns<T>;
export declare type BaseMultiTableColumns<T extends TTables> = {
readonly [tbAlias in keyof T]: TableFields<T, tbAlias>;
};
export declare type TableFields<T, TbAlias extends keyof T = any> = {
readonly [colAlias in keyof T[TbAlias]]: string;
};
export declare type TableAlias = string;

@@ -220,1 +238,32 @@ export declare type TableColAlias = string;

export declare type JointTable<L, R, KeyExcludeOptional = void> = Spread<L, R, KeyExcludeOptional>;
export declare type MultiTableAliasCols<T extends TTables> = {
[tbAlias in keyof T]: TableAliasCols<T[tbAlias]>;
};
export declare type TableAliasCols<TAliasCols = any> = AliasTableCols<TAliasCols> & {
[ColumnExtPropKeys.genFieldsAliasFn]<T extends AliasTableCols<TAliasCols> = any>(keyArr: ((keyof T) | '*')[],
/** Default: false */
useColAliasNameAsOutputName?: boolean): KnexColumnsParma;
};
export declare type AliasTableCols<TAliasCols = any> = {
[col in keyof TAliasCols]: ColAliasType<TAliasCols[col]>;
};
/**
* {
* // jointTableColumns.output: jointTableColumns.inupt
* tbUserDetailUid: 'tb_user_detail.uid',
* tbUserDetailAge: 'tb_user_detail.age',
* }
*/
export interface KnexColumnsParma {
[out: string]: string;
}
export interface ColAliasType<TColType> {
/** input column name */
input: string;
/** output column alias name */
output: string;
_typePlaceholder: TColType;
}
export declare type JointRetTable<K extends TableAliasCols> = {
[col in keyof K]: K[col]['_typePlaceholder'];
};

@@ -6,2 +6,3 @@ export var ColumnExtPropKeys;

ColumnExtPropKeys["sColsCacheMap"] = "_scopedColsCacheMap";
ColumnExtPropKeys["genFieldsAliasFn"] = "genFieldsAlias";
})(ColumnExtPropKeys || (ColumnExtPropKeys = {}));

@@ -39,31 +39,35 @@ import { pathResolve } from '@waiting/shared-core';

const { node, checker, sourceFile, path, } = options;
const typeName = retrieveGenericsIdentifierFromTypeArguments(node);
if (!node.typeArguments || !node.typeArguments[0]) {
return;
}
// const typeName: Identifier | void = retrieveGenericsIdentifierFromTypeArguments(node)
// if (typeName && typeName.getText()) {
// const gType = checker.getTypeAtLocation(typeName)
// }
const gType = checker.getTypeFromTypeNode(node.typeArguments[0]);
// const props = checker.getPropertiesOfType(type2)
/* istanbul ignore else */
if (typeName && typeName.getText()) {
const gType = checker.getTypeAtLocation(typeName);
if (gType && gType.symbol) {
const sym = gType.getSymbol();
if (!sym) {
return;
}
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const inputTypeName = sym.getName();
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:4:1:typeid-TbListModel"
const callerTypeId = `${path}:${line + 1}:${character + 1}:typeid-${inputTypeName}`;
// @ts-ignore
// const gTypeId: number = typeof gType.id === 'number' ? gType.id : Math.random()
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-76"
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-TbListModel"
const localTypeId = `${path}:typeid-${inputTypeName}`;
const { tbTagMap, tbColTagMap } = genTbListTagMapFromSymbol(gType.symbol, checker);
/* istanbul ignore else */
if (gType && gType.symbol) {
const sym = gType.getSymbol();
if (!sym) {
return;
}
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const inputTypeName = sym.getName();
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:4:1:typeid-TbListModel"
const callerTypeId = `${path}:${line + 1}:${character + 1}:typeid-${inputTypeName}`;
// @ts-ignore
// const gTypeId: number = typeof gType.id === 'number' ? gType.id : Math.random()
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-76"
// "/kmore-mono/packages/kmore-types/test/config/test.config2.ts:typeid-TbListModel"
const localTypeId = `${path}:typeid-${inputTypeName}`;
const { tbTagMap, tbColTagMap } = genTbListTagMapFromSymbol(gType.symbol, checker);
/* istanbul ignore else */
if (tbTagMap.size) {
return {
callerTypeId,
localTypeId,
tbTagMap,
tbColTagMap,
};
}
if (tbTagMap.size) {
return {
callerTypeId,
localTypeId,
tbTagMap,
tbColTagMap,
};
}

@@ -128,11 +132,12 @@ }

}
function retrieveGenericsIdentifierFromTypeArguments(node) {
/* istanbul ignore else */
if (!node.typeArguments || node.typeArguments.length !== 1) {
return;
}
const [typeNode] = node.typeArguments;
// @ts-ignore
return typeNode.typeName;
}
// function retrieveGenericsIdentifierFromTypeArguments(node: CallExpression): Identifier | void {
// /* istanbul ignore else */
// if (! node.typeArguments || node.typeArguments.length !== 1) {
// return
// }
// // typeNode TypeReference = 169
// const [typeNode] = node.typeArguments
// // @ts-ignore
// return typeNode.typeName
// }
export function matchSourceFileWithFilePath(path) {

@@ -139,0 +144,0 @@ // eslint-disable-next-line import/no-extraneous-dependencies

import { Observable } from 'rxjs';
import { BuildSrcOpts, CallerInfo, CallerFuncName, CallerFuncNameSet, Tables, TableCols, FilePath, KTablesBase, LoadVarFromFileOpts, Options, TbListTagMap, TbColListTagMap, TTables } from './model';
import { BuildSrcOpts, CallerInfo, CallerFuncName, CallerFuncNameSet, Tables, MultiTableCols, FilePath, KTablesBase, LoadVarFromFileOpts, Options, TbListTagMap, TbColListTagMap, TTables } from './model';
/** Allow empty Object */

@@ -16,3 +16,3 @@ export declare function validateParamTables(tbs: unknown): void;

/** Build DbTableCols from TableColListTagMap */
export declare function buildTbColListParam<T extends TTables>(tagMap: TbColListTagMap): TableCols<T>;
export declare function buildTbColListParam<T extends TTables>(tagMap: TbColListTagMap): MultiTableCols<T>;
/** Build DbTableScopedCols from TableColListTagMap */

@@ -25,5 +25,5 @@ export declare function isCallerNameMatched(name: string, matchFuncNameSet: CallerFuncNameSet): boolean;

export declare function loadTableVarFromFile<T extends TTables>(loadOpts: LoadVarFromFileOpts): Tables<T>;
export declare function loadColumnVarFromFile<T extends TTables>(loadOpts: LoadVarFromFileOpts): TableCols<T>;
export declare function loadColumnVarFromFile<T extends TTables>(loadOpts: LoadVarFromFileOpts): MultiTableCols<T>;
/**
* Load kTables var from a js file
* Load kTablesBase var from a js file
*/

@@ -30,0 +30,0 @@ export declare function loadVarFromFile<T extends TTables>(loadOpts: LoadVarFromFileOpts): KTablesBase<T>;

@@ -6,3 +6,3 @@ import * as sourceMapSupport from 'source-map-support';

import { readFileLineRx } from '@waiting/shared-core';
import { defaultPropDescriptor, reservedTbListKeys, initBuildSrcOpts, globalCallerFuncNameSet, } from './config';
import { defaultPropDescriptor, reservedTbListKeys, initBuildSrcOpts, globalCallerFuncNameSet, DbPropKeys, } from './config';
/** Allow empty Object */

@@ -242,3 +242,3 @@ export function validateParamTables(tbs) {

/**
* Load kTables var from a js file
* Load kTablesBase var from a js file
*/

@@ -248,6 +248,7 @@ export function loadVarFromFile(loadOpts) {

const tbVarName = genVarName(options.exportVarPrefix, caller.line, caller.column);
const colVarName = `${tbVarName}${options.exportVarColsSuffix}`;
const tableVarName = `${tbVarName}_${DbPropKeys.tables}`;
const colVarName = `${tbVarName}_${DbPropKeys.columns}`;
const mods = loadFile(path);
if (mods && typeof mods[tbVarName] === 'object') {
const tables = mods[tbVarName];
const tables = mods[tableVarName];
const columns = typeof mods[colVarName] === 'object'

@@ -254,0 +255,0 @@ ? mods[colVarName]

{
"name": "kmore-types",
"author": "waiting",
"version": "0.15.0",
"version": "0.16.0",
"description": "Retrieve types info from ts file",

@@ -87,3 +87,3 @@ "keywords": [

},
"gitHead": "c67e60f8b5d6c1feed58816c2890eb54ed00347a"
"gitHead": "aa43e37f1be046ddf740b635cb1faa4ed313c04d"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc