Comparing version 0.3.0 to 0.4.0
@@ -5,2 +5,4 @@ # Changelog | ||
## [0.4.0](https://github.com/waitingsong/kmore/compare/v0.3.0...v0.4.0) (2019-08-11) | ||
## [0.3.0](https://github.com/waitingsong/kmore/compare/v0.2.0...v0.3.0) (2019-08-10) | ||
@@ -7,0 +9,0 @@ |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @author waiting | ||
@@ -34,3 +34,3 @@ * @license MIT | ||
}; | ||
const initBuildSrcOpts = Object.assign({}, initOptions, { baseDir: [], concurrent: 5 }); | ||
const initBuildSrcOpts = Object.assign({}, initOptions, { baseDirFile: [], concurrent: 5 }); | ||
const initGenTbListFromTypeOpts = { | ||
@@ -234,3 +234,3 @@ callerFuncNames: initOptions.callerFuncNames, | ||
const opts = Object.assign({}, initBuildSrcOpts, options); | ||
const { baseDir } = opts; | ||
const { baseDirFile: baseDir } = opts; | ||
const maxDepth = 99; | ||
@@ -237,0 +237,0 @@ const concurrent = opts.concurrent && opts.concurrent > 0 |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @author waiting | ||
@@ -30,3 +30,3 @@ * @license MIT | ||
}; | ||
const initBuildSrcOpts = Object.assign({}, initOptions, { baseDir: [], concurrent: 5 }); | ||
const initBuildSrcOpts = Object.assign({}, initOptions, { baseDirFile: [], concurrent: 5 }); | ||
const initGenTbListFromTypeOpts = { | ||
@@ -230,3 +230,3 @@ callerFuncNames: initOptions.callerFuncNames, | ||
const opts = Object.assign({}, initBuildSrcOpts, options); | ||
const { baseDir } = opts; | ||
const { baseDirFile: baseDir } = opts; | ||
const maxDepth = 99; | ||
@@ -233,0 +233,0 @@ const concurrent = opts.concurrent && opts.concurrent > 0 |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 0.3.0 | ||
* @version 0.4.0 | ||
* @author waiting | ||
@@ -12,3 +12,3 @@ * @license MIT | ||
import*as e from"knex";import{install as r}from"source-map-support";import{walk as t}from"rxwalker";import{iif as n,of as o,from as c,defer as a}from"rxjs";import{mergeMap as i,filter as s,map as l,mapTo as u,catchError as f}from"rxjs/operators";import{readFileAsync as p,pathResolve as h,writeFileAsync as m}from"@waiting/shared-core";import{accessSync as y,constants as b}from"fs";import{createProgram as d,ScriptTarget as g,ModuleKind as w,forEachChild as T,isCallExpression as E}from"typescript";const M={callerFuncNames:["genTbListFromType","kmore"],exportVarPrefix:"tbs",forceLoadTbListJs:!1,forceLoadTbListJsPathReplaceRules:null,outputBanner:"/* eslint-disable */",outputFileNameSuffix:"__built-tables",refTablesPrefix:"reftb_"},F=Object.assign({},M,{baseDir:[],concurrent:5}),k={callerFuncNames:M.callerFuncNames,includePathKeyWords:[],stackDepth:1},O=["constructor","__proto__"];var j;!function(e){e.dbh="dbh",e.tables="tables",e.refTables="rb"}(j||(j={}));const $={configurable:!1,enumerable:!0,writable:!1},v={tbListMap:new Map,callerIdToLocalTypeIdMap:new Map,localTypeMap:new Map};function x(e){if(null===e)throw new TypeError("Parameter tables of DbFacrory() invalid. Values is null.");if("symbol"==typeof e)throw new TypeError("Parameter tables of DbFacrory() invalid. Values is symbol.");if(Array.isArray(e))throw new TypeError("Parameter tables of DbFacrory() invalid, value is Array.");if("object"!=typeof e)throw new TypeError("Parameter tables of DbFacrory() invalid.");e&&Object.keys(e).length&&Object.entries(e).forEach(e=>{const[r,t]=e;if(L(r),L(t),"string"!=typeof r)throw new TypeError("TableModel name in parameter of DbFacrory() invalid."+e.toString());if(!r.trim())throw new RangeError("Value of Parameter alias/tbl of DbFacrory() invalid.")})}function L(e){if("string"!=typeof e)throw new TypeError("TableName in parameter of DbFacrory() empty.");const r=e.trim();if(!r)throw new RangeError("Value of Parameter alias/tbl of DbFacrory() invalid.");if(O.includes(r))throw new TypeError(`tableName "${r}" of param tables is in reservedTbListKeys`)}function N(e=1){const t=Error.prepareStackTrace;if(!t&&(r(),!Error.prepareStackTrace))throw new Error("Error.prepareStackTrace not defined");const n=Error.prepareStackTrace;Error.prepareStackTrace=function(r,t){const o=t[e+1];return n(r,[o])};const o=Error.stackTraceLimit;Error.stackTraceLimit=e+2;const c=new Error,{stack:a}=c;if(Error.prepareStackTrace=t,Error.stackTraceLimit=o,!a)throw new Error("stack EMPTY!");const i=a.split("\n"),s=i.pop();if(!s)throw new Error("Retrieve stack of caller failed, line empty.");const l=s.slice(s.indexOf("(")+1,-1);if(!l)throw new Error("Retrieve stack of caller failed");const u=l.match(/^(.+):(\d+):(\d+)$/u);if(!u||4!==u.length)throw new Error("Retrieve stack of caller failed. "+(u?JSON.stringify(u):""));const f={path:u[1].replace(/\\/gu,"/"),line:+u[2],column:+u[3]};return f}function P(e){return!(!e||!e.endsWith(".ts"))}function S(e){const r=A();if(!e||!e.size)throw new TypeError("Value of tagMap invalid.");return e.forEach((e,t)=>{Object.defineProperty(r,t,Object.assign({},$,{value:t}))}),r}function D(e,r){return!!e&&("string"==typeof r&&r===e||!(!Array.isArray(r)||!r.includes(e)))}function A(){return Object.create(null)}function C(e,r){const t=e.slice(0,-3)+`.${r}.ts`;return t.replace(/\\/gu,"/")}function _(e,r,t){const n=`${e}_${r}_${t}`;return n}function R(e,r){let t=e;return r&&r.length&&r.forEach(([e,r])=>{t=t.replace(e,r)}),t}function z(e,r,t){const n=_(t.exportVarPrefix,r.line,r.column),o=I(e);if(o&&"object"==typeof o[n])return o[n];throw new TypeError(`Load tables failed, path: "${e}"`)}function I(e){const r=require(e);return r}function V(e){const r=Object.assign({},F,e),{baseDir:a}=r,u=99,f=r.concurrent&&r.concurrent>0?r.concurrent:5,p=n(()=>{if("string"==typeof a)return!0;if(Array.isArray(a))return!1;throw new TypeError("Value of baseDir invalid, should be String or Array.")},o(a),c(a)),h=p.pipe(i(e=>t(e,{maxDepth:99}),f),s(e=>"file"===e.type&&e.path.endsWith(".ts")&&!e.path.endsWith(".d.ts")),l(e=>e.path),i(e=>{const t=J(e,r.callerFuncNames);return t.pipe(l(r=>r?e:""))},f),s(e=>e.length>0));return h}function J(e,r){const t=a(()=>p(e)),n=t.pipe(l(e=>{const r=e.length>1024?e.slice(0,1024):e;return r}),s(e=>{const t=e.toString();return W(t,r)}),u(!0),f(()=>o(!1)));return n}function W(e,r){if(e){if("string"==typeof r)return e.includes(r);for(const t of r)if(e.includes(t))return!0;return!1}return!1}function K(e){const r=e.match(/^(.+):(\d+):(\d+):typeid-(\d+)$/u);if(r&&5===r.length){const e={path:r[1],line:+r[2],column:+r[3],typeId:+r[4]};return e}throw new TypeError("CallerTypeId value invalid")}function B(e,r,t,n){const o=new Map;return e.forEach(e=>{const c=q({node:e,checker:r,sourceFile:t,retMap:o,path:n});c&&o.set(c.id,c.tagMap)}),o}function q(e){const{node:r,checker:t,sourceFile:n,retMap:o,path:c}=e;if(r){const e=G(r);if(e&&e.getText()){const a=t.getTypeAtLocation(e);if(a&&a.symbol){const e="number"==typeof a.id?a.id:Math.random(),{line:t,character:i}=n.getLineAndCharacterOfPosition(r.getStart()),s=`${c}:${t+1}:${i+1}:typeid-${e}`;if(o.has(s))return;{const e=Y(a.symbol);if(e.size)return{id:s,tagMap:e}}}}}}function Y(e){const{members:r}=e,t=new Map;return r&&r.forEach(e=>{const r=e.getName(),n=e.getJsDocTags();t.set(r,n)}),t}function G(e){if(!e.typeArguments||1!==e.typeArguments.length)return;const[r]=e.typeArguments;return r.typeName}function H(e,r){return(!r||!r.includes("node_modules"))&&(!e||!e.length||!!Q(e,r))}function Q(e,r){if("string"==typeof e)return r.includes(e);if(Array.isArray(e))for(const t of e)if(r.includes(t))return!0;return!1}function U(e){const r=h(e).replace(/\\/gu,"/"),t=d([r],{noEmitOnError:!0,noImplicitAny:!0,target:g.ESNext,inlineSourceMap:!1,module:w.CommonJS}),n={checker:t.getTypeChecker(),sourceFile:null};for(const e of t.getSourceFiles())if(H("",e.path)&&!e.isDeclarationFile){const t=e.path?e.path:"";t.toLowerCase()===r.toLowerCase()&&(n.sourceFile=e)}return n}function X(e){const r=(t,n)=>{const{line:o,character:c}=n.sourceFile.getLineAndCharacterOfPosition(t.getStart());if(o+1===n.matchLine&&c+1===n.matchColumn&&E(t)){const r=t.expression;if(r){const n=D(r.getText(),e.matchFuncName);if(n)return t}}else if(t.getChildCount())return T(t,e=>r(e,n))},t=T(e.sourceFile,t=>r(t,e));return t}function Z(e){const r=new Set,t=(n,o)=>{if(E(n)){const t=n.expression;if(t&&D(t.getText(),e.matchFuncName))return void r.add(n)}n.getChildCount()&&T(n,e=>t(e))};return T(e.sourceFile,e=>t(e)),r}function ee(e){const r=e?Object.assign({},k,e):Object.assign({},k),t="number"==typeof r.stackDepth&&r.stackDepth>0?r.stackDepth:1,n=N(t);if(P(n.path))return re(n,r);throw TypeError("Not .ts file")}function re(e,r){const t=Object.assign({callerFuncNames:M.callerFuncNames},r||{},{caller:e,cacheMap:v}),n=`${e.path}:${e.line}:${e.column}`,o=t.cacheMap.callerIdToLocalTypeIdMap.get(n);let c={};if(o){const e=t.cacheMap.localTypeMap.get(o);if(!e)throw new Error(`cacheMap.localTypeMap not contains key: "${o}".`);if(!e.size)throw new Error(`cacheMap.localTypeMap key: "${o}" value empty.`);c=S(e)}else{const e=te(t);e.forEach((e,r)=>{if(t.cacheMap.callerIdToLocalTypeIdMap.set(n,r),e.size)t.cacheMap.localTypeMap.set(r,e),c=S(e);else{const e=t.cacheMap.localTypeMap.get(r);if(!e)throw new Error(`cacheMap.localTypeMap not contains key: "${r}" or value empty.`);if(!e.size)throw new Error(`cacheMap.localTypeMap key: "${r}" value empty.`);c=S(e)}})}return c}function te(e){const{checker:r,sourceFile:t}=U(e.caller.path);if(t){const n=ne(Object.assign({},e,{sourceFile:t,checker:r}));if(n.size)return n}return new Map}function ne(e){const r=new Map,{cacheMap:t,sourceFile:n,checker:o,caller:c,callerFuncNames:a}=e,i=X({sourceFile:n,matchLine:c.line,matchColumn:c.column,matchFuncName:a});if(i){const e=G(i);if(e&&e.getText()){const n=o.getTypeAtLocation(e);if(n&&n.symbol){const e="number"==typeof n.id?n.id:Math.random(),o=`${c.path}:typeid-${e}`;if(r.has(o))return r;if(t.localTypeMap.has(o))r.set(o,new Map);else{const e=Y(n.symbol);e.size&&r.set(o,e)}}}}return r}function oe(e){const r=N(2);return!e.forceLoadTbListJs&&P(r.path)?ce(e.callerFuncNames):ae(e,r)}function ce(e){const r=ee({callerFuncNames:e,stackDepth:4});return r}function ae(e,r){const{outputFileNameSuffix:t,forceLoadTbListJsPathReplaceRules:n}=e;let o=r.path.slice(0,-3)+`.${t}.js`;o=R(o,n),y(o,b.R_OK);const c=z(o,r,e);return c}const ie=e;function se(e,r){const t=r?Object.assign({},M,r):Object.assign({},M),n=oe(t);let o=A();return o=le($,o,e),o=ue($,o,n),o=fe(t,$,o),Object.freeze(o)}function le(e,r,t){return Object.defineProperty(r,j.dbh,Object.assign({},e,{value:ie(t)})),r}function ue(e,r,t){return x(t),Object.defineProperty(r,j.tables,Object.assign({},e,{value:t})),r}function fe(e,r,t){const n=A();return Object.defineProperty(t,j.refTables,Object.assign({},r,{value:n})),t.tables&&Object.keys(t.tables).forEach(o=>{Object.defineProperty(n,o,Object.assign({},r,{value:()=>t.dbh(o)})),Object.defineProperty(n[o],"name",Object.assign({},r,{value:`${e.refTablesPrefix}${o}`}))}),t}function pe(e){const r=Object.assign({},F,e),t=V(r),n=t.pipe(i(e=>a(()=>he(e,r)),r.concurrent));return n}async function he(e,r){const t=Object.assign({},F,r),n=me(e);if(n&&n.size){const e=await be(n,t);return e.replace(/\\/gu,"/")}return""}function me(e){const r=h(e).replace(/\\/gu,"/"),{checker:t,sourceFile:n}=U(r),o=new Map;if(n){const e=Z({sourceFile:n,matchFuncName:M.callerFuncNames}),c=B(e,t,n,r);c.forEach((e,r)=>{const t=S(e);o.set(r,t)})}return o}function ye(e,r){const{exportVarPrefix:t,outputFileNameSuffix:n}=r;let o="";const c=[];return e.forEach((e,r)=>{const{path:a,line:i,column:s}=K(r);o||(o=C(a,n));const l=_(t,i,s);c.push(`export const ${l} = ${JSON.stringify(e,null,2)} as const`)}),[o,c.join("\n\n")]}async function be(e,r){const{outputBanner:t}=r,[n,o]=ye(e,r),c=t?`${t}\n\n${o}\n\n`:`${o}\n\n`;return await m(n,c),n.replace(/\\/gu,"/")}export{pe as buildSource,se as kmore}; | ||
import*as e from"knex";import{install as r}from"source-map-support";import{walk as t}from"rxwalker";import{iif as n,of as o,from as c,defer as a}from"rxjs";import{mergeMap as i,filter as s,map as l,mapTo as u,catchError as f}from"rxjs/operators";import{readFileAsync as p,pathResolve as h,writeFileAsync as m}from"@waiting/shared-core";import{accessSync as y,constants as b}from"fs";import{createProgram as d,ScriptTarget as g,ModuleKind as w,forEachChild as T,isCallExpression as E}from"typescript";const F={callerFuncNames:["genTbListFromType","kmore"],exportVarPrefix:"tbs",forceLoadTbListJs:!1,forceLoadTbListJsPathReplaceRules:null,outputBanner:"/* eslint-disable */",outputFileNameSuffix:"__built-tables",refTablesPrefix:"reftb_"},M=Object.assign({},F,{baseDirFile:[],concurrent:5}),k={callerFuncNames:F.callerFuncNames,includePathKeyWords:[],stackDepth:1},O=["constructor","__proto__"];var j;!function(e){e.dbh="dbh",e.tables="tables",e.refTables="rb"}(j||(j={}));const $={configurable:!1,enumerable:!0,writable:!1},v={tbListMap:new Map,callerIdToLocalTypeIdMap:new Map,localTypeMap:new Map};function x(e){if(null===e)throw new TypeError("Parameter tables of DbFacrory() invalid. Values is null.");if("symbol"==typeof e)throw new TypeError("Parameter tables of DbFacrory() invalid. Values is symbol.");if(Array.isArray(e))throw new TypeError("Parameter tables of DbFacrory() invalid, value is Array.");if("object"!=typeof e)throw new TypeError("Parameter tables of DbFacrory() invalid.");e&&Object.keys(e).length&&Object.entries(e).forEach(e=>{const[r,t]=e;if(L(r),L(t),"string"!=typeof r)throw new TypeError("TableModel name in parameter of DbFacrory() invalid."+e.toString());if(!r.trim())throw new RangeError("Value of Parameter alias/tbl of DbFacrory() invalid.")})}function L(e){if("string"!=typeof e)throw new TypeError("TableName in parameter of DbFacrory() empty.");const r=e.trim();if(!r)throw new RangeError("Value of Parameter alias/tbl of DbFacrory() invalid.");if(O.includes(r))throw new TypeError(`tableName "${r}" of param tables is in reservedTbListKeys`)}function N(e=1){const t=Error.prepareStackTrace;if(!t&&(r(),!Error.prepareStackTrace))throw new Error("Error.prepareStackTrace not defined");const n=Error.prepareStackTrace;Error.prepareStackTrace=function(r,t){const o=t[e+1];return n(r,[o])};const o=Error.stackTraceLimit;Error.stackTraceLimit=e+2;const c=new Error,{stack:a}=c;if(Error.prepareStackTrace=t,Error.stackTraceLimit=o,!a)throw new Error("stack EMPTY!");const i=a.split("\n"),s=i.pop();if(!s)throw new Error("Retrieve stack of caller failed, line empty.");const l=s.slice(s.indexOf("(")+1,-1);if(!l)throw new Error("Retrieve stack of caller failed");const u=l.match(/^(.+):(\d+):(\d+)$/u);if(!u||4!==u.length)throw new Error("Retrieve stack of caller failed. "+(u?JSON.stringify(u):""));const f={path:u[1].replace(/\\/gu,"/"),line:+u[2],column:+u[3]};return f}function P(e){return!(!e||!e.endsWith(".ts"))}function S(e){const r=A();if(!e||!e.size)throw new TypeError("Value of tagMap invalid.");return e.forEach((e,t)=>{Object.defineProperty(r,t,Object.assign({},$,{value:t}))}),r}function D(e,r){return!!e&&("string"==typeof r&&r===e||!(!Array.isArray(r)||!r.includes(e)))}function A(){return Object.create(null)}function C(e,r){const t=e.slice(0,-3)+`.${r}.ts`;return t.replace(/\\/gu,"/")}function _(e,r,t){const n=`${e}_${r}_${t}`;return n}function R(e,r){let t=e;return r&&r.length&&r.forEach(([e,r])=>{t=t.replace(e,r)}),t}function z(e,r,t){const n=_(t.exportVarPrefix,r.line,r.column),o=I(e);if(o&&"object"==typeof o[n])return o[n];throw new TypeError(`Load tables failed, path: "${e}"`)}function I(e){const r=require(e);return r}function V(e){const r=Object.assign({},M,e),{baseDirFile:a}=r,u=99,f=r.concurrent&&r.concurrent>0?r.concurrent:5,p=n(()=>{if("string"==typeof a)return!0;if(Array.isArray(a))return!1;throw new TypeError("Value of baseDir invalid, should be String or Array.")},o(a),c(a)),h=p.pipe(i(e=>t(e,{maxDepth:99}),f),s(e=>"file"===e.type&&e.path.endsWith(".ts")&&!e.path.endsWith(".d.ts")),l(e=>e.path),i(e=>{const t=J(e,r.callerFuncNames);return t.pipe(l(r=>r?e:""))},f),s(e=>e.length>0));return h}function J(e,r){const t=a(()=>p(e)),n=t.pipe(l(e=>{const r=e.length>1024?e.slice(0,1024):e;return r}),s(e=>{const t=e.toString();return W(t,r)}),u(!0),f(()=>o(!1)));return n}function W(e,r){if(e){if("string"==typeof r)return e.includes(r);for(const t of r)if(e.includes(t))return!0;return!1}return!1}function K(e){const r=e.match(/^(.+):(\d+):(\d+):typeid-(\d+)$/u);if(r&&5===r.length){const e={path:r[1],line:+r[2],column:+r[3],typeId:+r[4]};return e}throw new TypeError("CallerTypeId value invalid")}function B(e,r,t,n){const o=new Map;return e.forEach(e=>{const c=q({node:e,checker:r,sourceFile:t,retMap:o,path:n});c&&o.set(c.id,c.tagMap)}),o}function q(e){const{node:r,checker:t,sourceFile:n,retMap:o,path:c}=e;if(r){const e=G(r);if(e&&e.getText()){const a=t.getTypeAtLocation(e);if(a&&a.symbol){const e="number"==typeof a.id?a.id:Math.random(),{line:t,character:i}=n.getLineAndCharacterOfPosition(r.getStart()),s=`${c}:${t+1}:${i+1}:typeid-${e}`;if(o.has(s))return;{const e=Y(a.symbol);if(e.size)return{id:s,tagMap:e}}}}}}function Y(e){const{members:r}=e,t=new Map;return r&&r.forEach(e=>{const r=e.getName(),n=e.getJsDocTags();t.set(r,n)}),t}function G(e){if(!e.typeArguments||1!==e.typeArguments.length)return;const[r]=e.typeArguments;return r.typeName}function H(e,r){return(!r||!r.includes("node_modules"))&&(!e||!e.length||!!Q(e,r))}function Q(e,r){if("string"==typeof e)return r.includes(e);if(Array.isArray(e))for(const t of e)if(r.includes(t))return!0;return!1}function U(e){const r=h(e).replace(/\\/gu,"/"),t=d([r],{noEmitOnError:!0,noImplicitAny:!0,target:g.ESNext,inlineSourceMap:!1,module:w.CommonJS}),n={checker:t.getTypeChecker(),sourceFile:null};for(const e of t.getSourceFiles())if(H("",e.path)&&!e.isDeclarationFile){const t=e.path?e.path:"";t.toLowerCase()===r.toLowerCase()&&(n.sourceFile=e)}return n}function X(e){const r=(t,n)=>{const{line:o,character:c}=n.sourceFile.getLineAndCharacterOfPosition(t.getStart());if(o+1===n.matchLine&&c+1===n.matchColumn&&E(t)){const r=t.expression;if(r){const n=D(r.getText(),e.matchFuncName);if(n)return t}}else if(t.getChildCount())return T(t,e=>r(e,n))},t=T(e.sourceFile,t=>r(t,e));return t}function Z(e){const r=new Set,t=(n,o)=>{if(E(n)){const t=n.expression;if(t&&D(t.getText(),e.matchFuncName))return void r.add(n)}n.getChildCount()&&T(n,e=>t(e))};return T(e.sourceFile,e=>t(e)),r}function ee(e){const r=e?Object.assign({},k,e):Object.assign({},k),t="number"==typeof r.stackDepth&&r.stackDepth>0?r.stackDepth:1,n=N(t);if(P(n.path))return re(n,r);throw TypeError("Not .ts file")}function re(e,r){const t=Object.assign({callerFuncNames:F.callerFuncNames},r||{},{caller:e,cacheMap:v}),n=`${e.path}:${e.line}:${e.column}`,o=t.cacheMap.callerIdToLocalTypeIdMap.get(n);let c={};if(o){const e=t.cacheMap.localTypeMap.get(o);if(!e)throw new Error(`cacheMap.localTypeMap not contains key: "${o}".`);if(!e.size)throw new Error(`cacheMap.localTypeMap key: "${o}" value empty.`);c=S(e)}else{const e=te(t);e.forEach((e,r)=>{if(t.cacheMap.callerIdToLocalTypeIdMap.set(n,r),e.size)t.cacheMap.localTypeMap.set(r,e),c=S(e);else{const e=t.cacheMap.localTypeMap.get(r);if(!e)throw new Error(`cacheMap.localTypeMap not contains key: "${r}" or value empty.`);if(!e.size)throw new Error(`cacheMap.localTypeMap key: "${r}" value empty.`);c=S(e)}})}return c}function te(e){const{checker:r,sourceFile:t}=U(e.caller.path);if(t){const n=ne(Object.assign({},e,{sourceFile:t,checker:r}));if(n.size)return n}return new Map}function ne(e){const r=new Map,{cacheMap:t,sourceFile:n,checker:o,caller:c,callerFuncNames:a}=e,i=X({sourceFile:n,matchLine:c.line,matchColumn:c.column,matchFuncName:a});if(i){const e=G(i);if(e&&e.getText()){const n=o.getTypeAtLocation(e);if(n&&n.symbol){const e="number"==typeof n.id?n.id:Math.random(),o=`${c.path}:typeid-${e}`;if(r.has(o))return r;if(t.localTypeMap.has(o))r.set(o,new Map);else{const e=Y(n.symbol);e.size&&r.set(o,e)}}}}return r}function oe(e){const r=N(2);return!e.forceLoadTbListJs&&P(r.path)?ce(e.callerFuncNames):ae(e,r)}function ce(e){const r=ee({callerFuncNames:e,stackDepth:4});return r}function ae(e,r){const{outputFileNameSuffix:t,forceLoadTbListJsPathReplaceRules:n}=e;let o=r.path.slice(0,-3)+`.${t}.js`;o=R(o,n),y(o,b.R_OK);const c=z(o,r,e);return c}const ie=e;function se(e,r){const t=r?Object.assign({},F,r):Object.assign({},F),n=oe(t);let o=A();return o=le($,o,e),o=ue($,o,n),o=fe(t,$,o),Object.freeze(o)}function le(e,r,t){return Object.defineProperty(r,j.dbh,Object.assign({},e,{value:ie(t)})),r}function ue(e,r,t){return x(t),Object.defineProperty(r,j.tables,Object.assign({},e,{value:t})),r}function fe(e,r,t){const n=A();return Object.defineProperty(t,j.refTables,Object.assign({},r,{value:n})),t.tables&&Object.keys(t.tables).forEach(o=>{Object.defineProperty(n,o,Object.assign({},r,{value:()=>t.dbh(o)})),Object.defineProperty(n[o],"name",Object.assign({},r,{value:`${e.refTablesPrefix}${o}`}))}),t}function pe(e){const r=Object.assign({},M,e),t=V(r),n=t.pipe(i(e=>a(()=>he(e,r)),r.concurrent));return n}async function he(e,r){const t=Object.assign({},M,r),n=me(e);if(n&&n.size){const e=await be(n,t);return e.replace(/\\/gu,"/")}return""}function me(e){const r=h(e).replace(/\\/gu,"/"),{checker:t,sourceFile:n}=U(r),o=new Map;if(n){const e=Z({sourceFile:n,matchFuncName:F.callerFuncNames}),c=B(e,t,n,r);c.forEach((e,r)=>{const t=S(e);o.set(r,t)})}return o}function ye(e,r){const{exportVarPrefix:t,outputFileNameSuffix:n}=r;let o="";const c=[];return e.forEach((e,r)=>{const{path:a,line:i,column:s}=K(r);o||(o=C(a,n));const l=_(t,i,s);c.push(`export const ${l} = ${JSON.stringify(e,null,2)} as const`)}),[o,c.join("\n\n")]}async function be(e,r){const{outputBanner:t}=r,[n,o]=ye(e,r),c=t?`${t}\n\n${o}\n\n`:`${o}\n\n`;return await m(n,c),n.replace(/\\/gu,"/")}export{pe as buildSource,se as kmore}; | ||
//# sourceMappingURL=index.esm.min.js.map |
@@ -10,3 +10,3 @@ export const initOptions = { | ||
}; | ||
export const initBuildSrcOpts = Object.assign({}, initOptions, { baseDir: [], concurrent: 5 }); | ||
export const initBuildSrcOpts = Object.assign({}, initOptions, { baseDirFile: [], concurrent: 5 }); | ||
export const initGenTbListFromTypeOpts = { | ||
@@ -13,0 +13,0 @@ callerFuncNames: initOptions.callerFuncNames, |
@@ -24,3 +24,4 @@ import * as Knex from 'knex'; | ||
export interface BuildSrcOpts extends Partial<Options> { | ||
baseDir: string | string[]; | ||
/** Base dir or file in both relative and absolute style to scan */ | ||
baseDirFile: string | string[]; | ||
/** Default: 5 */ | ||
@@ -27,0 +28,0 @@ concurrent?: number; |
@@ -225,3 +225,3 @@ import * as sourceMapSupport from 'source-map-support'; | ||
const opts = Object.assign({}, initBuildSrcOpts, options); | ||
const { baseDir } = opts; | ||
const { baseDirFile: baseDir } = opts; | ||
const maxDepth = 99; | ||
@@ -228,0 +228,0 @@ const concurrent = opts.concurrent && opts.concurrent > 0 |
{ | ||
"name": "kmore", | ||
"author": "waiting", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A Knex little more factory of SQL query builder, with auto-generated type-safe tables accessor for Node.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
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
262679
2523