@lovrabet/dataset-mcp-server 1.3.1-beta.1 → 1.3.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/analyzer/dataset-analyzer.js +1 -1
- package/dist/api/cache.js +1 -1
- package/dist/api/dev-api-client.js +1 -1
- package/dist/auth/constants.js +1 -1
- package/dist/auth/cookie-manager.js +1 -1
- package/dist/auth/session-validator.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server.js +1 -1
- package/dist/tools/execute-custom-sql.js +1 -1
- package/dist/tools/generate-sdk-code.js +1 -1
- package/dist/tools/generate-sql-code.js +1 -1
- package/dist/tools/get-dataset-detail.js +1 -1
- package/dist/tools/get-operation-detail.js +1 -1
- package/dist/tools/get-operations.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/list-datasets.js +1 -1
- package/dist/tools/list-sql-queries.js +1 -1
- package/dist/tools/login.js +1 -1
- package/dist/tools/save-custom-sql.js +1 -1
- package/dist/tools/save-or-update-custom-sql.js +1 -1
- package/dist/tools/search-datasets.js +1 -1
- package/dist/tools/validate-sql-content.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/mcp-types.js +1 -1
- package/dist/utils/sql-parser.js +1 -1
- package/package.json +1 -1
package/dist/utils/sql-parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(_0x4e476e,_0x4e8297){const _0x45a414=a24_0x1d10,_0x1c44de=_0x4e476e();while(!![]){try{const _0x25b8c6=-parseInt(_0x45a414(0x1ac))/0x1+parseInt(_0x45a414(0x1c2))/0x2*(parseInt(_0x45a414(0x185))/0x3)+-parseInt(_0x45a414(0x1be))/0x4+parseInt(_0x45a414(0x1b3))/0x5*(parseInt(_0x45a414(0x18b))/0x6)+-parseInt(_0x45a414(0x1ad))/0x7*(parseInt(_0x45a414(0x1af))/0x8)+parseInt(_0x45a414(0x1a0))/0x9*(-parseInt(_0x45a414(0x1ca))/0xa)+-parseInt(_0x45a414(0x18c))/0xb*(-parseInt(_0x45a414(0x17d))/0xc);if(_0x25b8c6===_0x4e8297)break;else _0x1c44de['push'](_0x1c44de['shift']());}catch(_0x39ebc0){_0x1c44de['push'](_0x1c44de['shift']());}}}(a24_0x177e,0xe9b68));export function parseSqlStructure(_0x4810b8){const _0x3d9ad6=a24_0x1d10,_0x2f97b2={'tables':[],'columns':[],'parameters':[],'joins':[]};if(!_0x4810b8||typeof _0x4810b8!=='string')return _0x2f97b2;const _0xf1b182=_0x4810b8['replace'](/#\{[^}]*\}/g,'?')[_0x3d9ad6(0x1b1)](/\$\{[^}]*\}/g,'?')['replace'](/'[^']*'/g,'\x27\x27')['replace'](/--.*$/gm,'')[_0x3d9ad6(0x1b1)](/\/\*[\s\S]*?\*\//g,''),_0x4a1276=_0xf1b182[_0x3d9ad6(0x1c5)](/FROM\s+([^\s,)(]+)/i);if(_0x4a1276){const _0x3d29a9=_0x4a1276[0x1]['replace'](/[`"]/g,'');_0x2f97b2['tables'][_0x3d9ad6(0x17e)](_0x3d29a9);}const _0x3efa70=_0xf1b182['matchAll'](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi);for(const _0x43459c of _0x3efa70){const _0x20132b=_0x43459c[0x1][_0x3d9ad6(0x1b1)](/[`"]/g,'');_0x20132b&&!_0x2f97b2['tables'][_0x3d9ad6(0x187)](_0x20132b)&&_0x2f97b2[_0x3d9ad6(0x1a8)][_0x3d9ad6(0x17e)](_0x20132b);}const _0x41018f=_0xf1b182[_0x3d9ad6(0x1c5)](/SELECT\s+([\s\S]+?)\s+FROM/i);if(_0x41018f){const _0x1c9f9e=_0x41018f[0x1][_0x3d9ad6(0x1bc)]();if(_0x1c9f9e!=='*'){const _0x233e1a=splitSqlColumns(_0x1c9f9e);for(const _0x38f103 of _0x233e1a){const _0x1bf4f1=_0x38f103[_0x3d9ad6(0x1bc)]();if(_0x1bf4f1&&!_0x1bf4f1[_0x3d9ad6(0x1c5)](/^\d+$/)){const _0x462591=_0x1bf4f1['split'](/\s+AS\s+/i),_0x2511ab=_0x462591[0x0][_0x3d9ad6(0x1bc)](),_0x1c26cc=_0x462591[0x1]?.[_0x3d9ad6(0x1bc)]();if(_0x2511ab['includes']('.')){const [_0x46e59e,_0x4f7c43]=_0x2511ab[_0x3d9ad6(0x1b9)]('.');_0x2f97b2[_0x3d9ad6(0x17f)]['push']({'table':_0x46e59e[_0x3d9ad6(0x1bc)](),'column':_0x4f7c43[_0x3d9ad6(0x1b1)](/[`"]/g,'')['trim'](),'alias':_0x1c26cc});}else!_0x2511ab['includes']('(')&&_0x2f97b2[_0x3d9ad6(0x17f)][_0x3d9ad6(0x17e)]({'table':'','column':_0x2511ab[_0x3d9ad6(0x1b1)](/[`"]/g,''),'alias':_0x1c26cc});}}}}const _0x1069f5=_0xf1b182[_0x3d9ad6(0x180)](/JOIN\s+(\w+)\s+(?:AS\s+)?(\w+)?\s+ON\s+([\w.]+)\s*=\s*([\w.]+)/gi);for(const _0x451cc1 of _0x1069f5){const [,,,_0x5b50c9,_0x44f581]=_0x451cc1;if(_0x5b50c9&&_0x44f581){const [_0x2063a7,_0x4a1561]=_0x5b50c9['includes']('.')?_0x5b50c9[_0x3d9ad6(0x1b9)]('.'):['',_0x5b50c9],[_0x141276,_0x296aba]=_0x44f581[_0x3d9ad6(0x187)]('.')?_0x44f581['split']('.'):['',_0x44f581];_0x2f97b2['joins']?.['push']({'leftTable':_0x2063a7,'leftColumn':_0x4a1561,'rightTable':_0x141276,'rightColumn':_0x296aba});}}const _0x1aa31c=_0x4810b8[_0x3d9ad6(0x180)](/[#\$]\{(\w+)\}/g),_0x452089=new Set();for(const _0x5a241e of _0x1aa31c){const _0xa9fe08=_0x5a241e[0x1];!_0x452089[_0x3d9ad6(0x1a6)](_0xa9fe08)&&(_0x452089[_0x3d9ad6(0x1a4)](_0xa9fe08),_0x2f97b2['parameters'][_0x3d9ad6(0x17e)]({'name':_0xa9fe08,'type':inferParamType(_0xa9fe08),'example':getExampleValue(_0xa9fe08)}));}return _0x2f97b2;}function splitSqlColumns(_0x41db9a){const _0x5ef93d=a24_0x1d10,_0x423a00=[];let _0x2ccd22='',_0x41d214=0x0;for(let _0x280b8a=0x0;_0x280b8a<_0x41db9a[_0x5ef93d(0x1a3)];_0x280b8a++){const _0x288b4a=_0x41db9a[_0x280b8a];if(_0x288b4a==='(')_0x41d214++,_0x2ccd22+=_0x288b4a;else{if(_0x288b4a===')')_0x41d214--,_0x2ccd22+=_0x288b4a;else _0x288b4a===','&&_0x41d214===0x0?(_0x423a00[_0x5ef93d(0x17e)](_0x2ccd22),_0x2ccd22=''):_0x2ccd22+=_0x288b4a;}}return _0x2ccd22&&_0x423a00[_0x5ef93d(0x17e)](_0x2ccd22),_0x423a00;}function inferParamType(_0x12cfff){const _0x51812e=a24_0x1d10,_0x3565ee=_0x12cfff[_0x51812e(0x1c0)]();if(_0x3565ee[_0x51812e(0x187)]('id')||_0x3565ee[_0x51812e(0x187)]('count')||_0x3565ee[_0x51812e(0x187)]('limit')||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1ae))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1ab))||_0x3565ee['includes'](_0x51812e(0x195))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x1a1))||_0x3565ee[_0x51812e(0x187)](_0x51812e(0x193)))return _0x51812e(0x19c);return _0x51812e(0x196);}function getExampleValue(_0x46132e){const _0x3c7912=a24_0x1d10,_0x59a2cd=_0x46132e[_0x3c7912(0x1c0)](),_0x45f161=inferParamType(_0x59a2cd);if(_0x45f161===_0x3c7912(0x19c)){if(_0x59a2cd[_0x3c7912(0x187)]('limit')||_0x59a2cd[_0x3c7912(0x187)]('count')||_0x59a2cd[_0x3c7912(0x187)]('size'))return 0xa;if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1ab)))return 0x1;return 0x7b;}if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1b5))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x182)))return _0x3c7912(0x1bf);if(_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x18a)))return'1';if(_0x59a2cd['includes'](_0x3c7912(0x18e))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x1b2))||_0x59a2cd[_0x3c7912(0x187)](_0x3c7912(0x188)))return _0x3c7912(0x1ba);return _0x3c7912(0x1c6);}export function validateIsSelectOnly(_0x30b560){const _0x424e4b=a24_0x1d10;if(!_0x30b560||typeof _0x30b560!==_0x424e4b(0x196))return{'valid':![],'reason':_0x424e4b(0x192)};const _0x241801=_0x30b560[_0x424e4b(0x1b1)](/#\{[^}]*\}/g,'?')[_0x424e4b(0x1b1)](/\$\{[^}]*\}/g,'?')['replace'](/@[^(\s]+(\([^)]*\))?/g,''),_0x3577f5=_0x241801[_0x424e4b(0x1bc)](),_0x27d7ea=_0x3577f5['split']('\x0a');let _0x4056c4='';for(const _0x357252 of _0x27d7ea){const _0x2bb2b1=_0x357252['trim']();if(!_0x2bb2b1||_0x2bb2b1[_0x424e4b(0x191)]('--')||_0x2bb2b1['startsWith']('/*'))continue;_0x4056c4=_0x2bb2b1;break;}if(!_0x4056c4[_0x424e4b(0x189)]()[_0x424e4b(0x191)]('SELECT'))return{'valid':![],'reason':'Only\x20SELECT\x20queries\x20are\x20allowed.\x20The\x20SQL\x20must\x20start\x20with\x20SELECT\x20(after\x20any\x20comments).'};const _0x31d524=['INSERT\x5cs+INTO','UPDATE\x5cs+\x5cw+\x5cs+SET',_0x424e4b(0x1b7),_0x424e4b(0x1c9),_0x424e4b(0x1a2),_0x424e4b(0x186),'TRUNCATE',_0x424e4b(0x1a9),_0x424e4b(0x194),'EXEC',_0x424e4b(0x1a5)],_0x44e7aa=_0x3577f5[_0x424e4b(0x189)]();for(const _0x201be6 of _0x31d524){const _0x1e843d=new RegExp(_0x201be6,'i');if(_0x1e843d[_0x424e4b(0x19b)](_0x44e7aa))return{'valid':![],'reason':'Forbidden\x20keyword\x20detected:\x20'+_0x201be6[_0x424e4b(0x1b1)](_0x424e4b(0x1b8),'\x20')+_0x424e4b(0x1aa)};}return{'valid':!![]};}export function extractTableNames(_0x1f6c4e){const _0x214b2e=a24_0x1d10,_0x27a20f=parseSqlStructure(_0x1f6c4e);return _0x27a20f[_0x214b2e(0x1a8)];}export function extractColumnNames(_0x3ad3cf){const _0x4e2fc4=a24_0x1d10,_0x4a8c9e=parseSqlStructure(_0x3ad3cf);return _0x4a8c9e['columns'][_0x4e2fc4(0x1c3)](_0x2e5262=>({'table':_0x2e5262['table'],'column':_0x2e5262[_0x4e2fc4(0x190)]}));}export function extractParameters(_0x3505ad){const _0x4aba92=a24_0x1d10,_0x1593a4=parseSqlStructure(_0x3505ad);return _0x1593a4[_0x4aba92(0x184)];}function a24_0x1d10(_0x1932fb,_0x48bfff){_0x1932fb=_0x1932fb-0x17d;const _0x177e57=a24_0x177e();let _0x1d108f=_0x177e57[_0x1932fb];return _0x1d108f;}export function validateSqlContent(_0x3641d0,_0x4cd170){const _0x64a2d4=a24_0x1d10,_0x135e62=validateIsSelectOnly(_0x3641d0);if(!_0x135e62[_0x64a2d4(0x1a7)])return{'valid':![],'isSelectOnly':![],'errors':[{'type':_0x64a2d4(0x1bd),'location':'SQL_START','message':_0x135e62[_0x64a2d4(0x1c4)]||_0x64a2d4(0x197),'suggestion':_0x64a2d4(0x1b4)}]};const _0x4cb3aa=parseSqlStructure(_0x3641d0),_0x406620=[];if(_0x4cd170){const _0x4cd441=new Map(_0x4cd170[_0x64a2d4(0x1a8)][_0x64a2d4(0x1c3)](_0x1ea0d9=>[_0x1ea0d9[_0x64a2d4(0x1c7)][_0x64a2d4(0x1c0)](),_0x1ea0d9[_0x64a2d4(0x17f)][_0x64a2d4(0x1c3)](_0xe16045=>_0xe16045[_0x64a2d4(0x1c0)]())]));for(const _0x5dd1b4 of _0x4cb3aa[_0x64a2d4(0x1a8)]){const _0x134cbc=_0x5dd1b4[_0x64a2d4(0x1c0)]();!_0x4cd441[_0x64a2d4(0x1a6)](_0x134cbc)&&_0x406620[_0x64a2d4(0x17e)]({'type':_0x64a2d4(0x19a),'location':_0x5dd1b4,'message':_0x64a2d4(0x1c8)+_0x5dd1b4+_0x64a2d4(0x198),'suggestion':'Use\x20list_datasets\x20to\x20find\x20available\x20tables','suggestions':Array[_0x64a2d4(0x19d)](_0x4cd441['keys']())});}for(const _0x111e6a of _0x4cb3aa[_0x64a2d4(0x17f)]){if(_0x111e6a[_0x64a2d4(0x181)]){const _0x7a7014=_0x111e6a[_0x64a2d4(0x181)][_0x64a2d4(0x1c0)](),_0x5b46c5=_0x4cd441[_0x64a2d4(0x18d)](_0x7a7014);if(_0x5b46c5){const _0x3d5186=_0x111e6a[_0x64a2d4(0x190)]['toLowerCase']();!_0x5b46c5[_0x64a2d4(0x187)](_0x3d5186)&&!_0x111e6a[_0x64a2d4(0x190)][_0x64a2d4(0x187)]('*')&&_0x406620[_0x64a2d4(0x17e)]({'type':_0x64a2d4(0x1b6),'location':_0x111e6a['table']+'.'+_0x111e6a[_0x64a2d4(0x190)],'message':_0x64a2d4(0x183)+_0x111e6a[_0x64a2d4(0x190)]+'\x22\x20not\x20found\x20in\x20table\x20\x22'+_0x111e6a['table']+'\x22','suggestion':_0x64a2d4(0x19f),'suggestions':_0x5b46c5[_0x64a2d4(0x1b0)](_0x5a546a=>_0x5a546a[_0x64a2d4(0x187)](_0x111e6a['column'][_0x64a2d4(0x1c0)]())||_0x111e6a[_0x64a2d4(0x190)][_0x64a2d4(0x1c0)]()['includes'](_0x5a546a))});}}}}return{'valid':_0x406620[_0x64a2d4(0x1a3)]===0x0,'isSelectOnly':!![],'parsedStructure':_0x4cb3aa,'errors':_0x406620[_0x64a2d4(0x1a3)]>0x0?_0x406620:undefined};}function a24_0x177e(){const _0x3f44f7=['Invalid\x20SQL','\x22\x20not\x20found\x20in\x20database\x20schema','joins','TABLE_NOT_FOUND','test','number','from','join','Use\x20get_dataset_detail\x20to\x20see\x20available\x20columns','27RcQhes','amount','ALTER\x5cs+(TABLE|DATABASE)','length','add','EXECUTE','has','valid','tables','GRANT','.\x20Only\x20SELECT\x20queries\x20are\x20allowed.','page','786973kNwqXs','2624594cxUdZI','size','8iDAsBv','filter','replace','search','3245530ghOmgz','SQL\x20must\x20be\x20a\x20SELECT\x20statement','date','COLUMN_NOT_FOUND','DELETE\x5cs+FROM','\x5c\x5cs+','split','example','SELECT\x20query','trim','SYNTAX_ERROR','3978080qIvNsL','2024-01-01','toLowerCase','Joins:\x20','300676zgTESO','map','reason','match','value','tableName','Table\x20\x22','DROP\x5cs+(TABLE|INDEX|DATABASE)','2670950JWMARg','9444GPOXBx','push','columns','matchAll','table','time','Column\x20\x22','parameters','3xNFmxb','CREATE\x5cs+(TABLE|INDEX|DATABASE|VIEW)','includes','name','toUpperCase','status','12vGoPNf','34474zifsqR','get','keyword','\x20|\x20','column','startsWith','SQL\x20content\x20cannot\x20be\x20empty','price','REVOKE','num','string'];a24_0x177e=function(){return _0x3f44f7;};return a24_0x177e();}export function generateSqlSummary(_0x48f6f3){const _0xe564d2=a24_0x1d10,_0x2ee958=parseSqlStructure(_0x48f6f3),_0x246d84=[];return _0x2ee958['tables'][_0xe564d2(0x1a3)]>0x0&&_0x246d84['push']('Tables:\x20'+_0x2ee958[_0xe564d2(0x1a8)]['join'](',\x20')),_0x2ee958[_0xe564d2(0x184)]['length']>0x0&&_0x246d84[_0xe564d2(0x17e)]('Params:\x20'+_0x2ee958[_0xe564d2(0x184)]['map'](_0x711fb=>_0x711fb[_0xe564d2(0x188)])['join'](',\x20')),_0x2ee958[_0xe564d2(0x199)]&&_0x2ee958[_0xe564d2(0x199)]['length']>0x0&&_0x246d84['push'](_0xe564d2(0x1c1)+_0x2ee958[_0xe564d2(0x199)][_0xe564d2(0x1a3)]),_0x246d84[_0xe564d2(0x1a3)]>0x0?_0x246d84[_0xe564d2(0x19e)](_0xe564d2(0x18f)):_0xe564d2(0x1bb);}
|
|
1
|
+
(function(_0x8e19c2,_0x28a7b9){const _0x19f686=a24_0x23f7,_0x403ae0=_0x8e19c2();while(!![]){try{const _0x2d8112=-parseInt(_0x19f686(0x9c))/0x1+-parseInt(_0x19f686(0xc0))/0x2*(parseInt(_0x19f686(0xab))/0x3)+-parseInt(_0x19f686(0xe2))/0x4*(parseInt(_0x19f686(0xe7))/0x5)+-parseInt(_0x19f686(0xb4))/0x6*(-parseInt(_0x19f686(0xce))/0x7)+parseInt(_0x19f686(0xa4))/0x8+parseInt(_0x19f686(0xac))/0x9+-parseInt(_0x19f686(0xbd))/0xa*(-parseInt(_0x19f686(0xc5))/0xb);if(_0x2d8112===_0x28a7b9)break;else _0x403ae0['push'](_0x403ae0['shift']());}catch(_0x8b2b13){_0x403ae0['push'](_0x403ae0['shift']());}}}(a24_0x5f35,0x75293));import{createStructuredSqlError}from'../types/mcp-types.js';export function parseSqlStructure(_0x87987b){const _0x434a63=a24_0x23f7,_0x36f2d6={'tables':[],'columns':[],'parameters':[],'joins':[]};if(!_0x87987b||typeof _0x87987b!==_0x434a63(0xdd))return _0x36f2d6;const _0x4359d2=_0x87987b[_0x434a63(0xdb)](/#\{[^}]*\}/g,'?')[_0x434a63(0xdb)](/\$\{[^}]*\}/g,'?')[_0x434a63(0xdb)](/'[^']*'/g,'\x27\x27')[_0x434a63(0xdb)](/--.*$/gm,'')[_0x434a63(0xdb)](/\/\*[\s\S]*?\*\//g,''),_0x330fdd=_0x4359d2['match'](/FROM\s+([^\s,)(]+)/i);if(_0x330fdd){const _0x325cdd=_0x330fdd[0x1]['replace'](/[`"]/g,'');_0x36f2d6['tables']['push'](_0x325cdd);}const _0x27f5ff=_0x4359d2[_0x434a63(0xb1)](/(?:INNER|LEFT|RIGHT|FULL|CROSS)?\s*JOIN\s+([^\s,)(]+)/gi);for(const _0x593faf of _0x27f5ff){const _0x324629=_0x593faf[0x1][_0x434a63(0xdb)](/[`"]/g,'');_0x324629&&!_0x36f2d6[_0x434a63(0xb6)][_0x434a63(0xd4)](_0x324629)&&_0x36f2d6[_0x434a63(0xb6)]['push'](_0x324629);}const _0x317645=_0x4359d2[_0x434a63(0xea)](/SELECT\s+([\s\S]+?)\s+FROM/i);if(_0x317645){const _0x40efe7=_0x317645[0x1][_0x434a63(0xb7)]();if(_0x40efe7!=='*'){const _0x463d88=splitSqlColumns(_0x40efe7);for(const _0x55e029 of _0x463d88){const _0x42c94c=_0x55e029[_0x434a63(0xb7)]();if(_0x42c94c&&!_0x42c94c[_0x434a63(0xea)](/^\d+$/)){const _0x103fd6=_0x42c94c['split'](/\s+AS\s+/i),_0xd9557f=_0x103fd6[0x0][_0x434a63(0xb7)](),_0x2d08df=_0x103fd6[0x1]?.['trim']();if(_0xd9557f[_0x434a63(0xd4)]('.')){const [_0x3ea617,_0x284b15]=_0xd9557f[_0x434a63(0xa8)]('.');_0x36f2d6[_0x434a63(0xe5)][_0x434a63(0xcd)]({'table':_0x3ea617['trim'](),'column':_0x284b15['replace'](/[`"]/g,'')[_0x434a63(0xb7)](),'alias':_0x2d08df});}else!_0xd9557f[_0x434a63(0xd4)]('(')&&_0x36f2d6[_0x434a63(0xe5)][_0x434a63(0xcd)]({'table':'','column':_0xd9557f[_0x434a63(0xdb)](/[`"]/g,''),'alias':_0x2d08df});}}}}const _0xde08b0=_0x4359d2['matchAll'](/JOIN\s+(\w+)\s+(?:AS\s+)?(\w+)?\s+ON\s+([\w.]+)\s*=\s*([\w.]+)/gi);for(const _0x27b3d5 of _0xde08b0){const [,,,_0x52cf7e,_0x416288]=_0x27b3d5;if(_0x52cf7e&&_0x416288){const [_0x434bc7,_0x28b646]=_0x52cf7e[_0x434a63(0xd4)]('.')?_0x52cf7e['split']('.'):['',_0x52cf7e],[_0xbb0eb5,_0x298559]=_0x416288['includes']('.')?_0x416288[_0x434a63(0xa8)]('.'):['',_0x416288];_0x36f2d6[_0x434a63(0xa0)]?.[_0x434a63(0xcd)]({'leftTable':_0x434bc7,'leftColumn':_0x28b646,'rightTable':_0xbb0eb5,'rightColumn':_0x298559});}}const _0x2ac0ff=_0x87987b[_0x434a63(0xb1)](/[#\$]\{(\w+)\}/g),_0x5d7600=new Set();for(const _0x157f0f of _0x2ac0ff){const _0xb1446d=_0x157f0f[0x1];!_0x5d7600[_0x434a63(0xd6)](_0xb1446d)&&(_0x5d7600['add'](_0xb1446d),_0x36f2d6[_0x434a63(0xa2)]['push']({'name':_0xb1446d,'type':inferParamType(_0xb1446d),'example':getExampleValue(_0xb1446d)}));}return _0x36f2d6;}function splitSqlColumns(_0x57148c){const _0x382546=a24_0x23f7,_0x1724b7=[];let _0xdbaab0='',_0x1051c2=0x0;for(let _0x543785=0x0;_0x543785<_0x57148c[_0x382546(0xdc)];_0x543785++){const _0x37ca86=_0x57148c[_0x543785];if(_0x37ca86==='(')_0x1051c2++,_0xdbaab0+=_0x37ca86;else{if(_0x37ca86===')')_0x1051c2--,_0xdbaab0+=_0x37ca86;else _0x37ca86===','&&_0x1051c2===0x0?(_0x1724b7[_0x382546(0xcd)](_0xdbaab0),_0xdbaab0=''):_0xdbaab0+=_0x37ca86;}}return _0xdbaab0&&_0x1724b7['push'](_0xdbaab0),_0x1724b7;}function inferParamType(_0x1e4e42){const _0x1e1100=a24_0x23f7,_0x4e1da7=_0x1e4e42['toLowerCase']();if(_0x4e1da7[_0x1e1100(0xd4)]('id')||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xe9))||_0x4e1da7['includes'](_0x1e1100(0xbe))||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xa1))||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xc2))||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xc3))||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xd7))||_0x4e1da7[_0x1e1100(0xd4)](_0x1e1100(0xcf)))return _0x1e1100(0xa3);return'string';}function getExampleValue(_0x2336ea){const _0x3e12f1=a24_0x23f7,_0x3ccd38=_0x2336ea[_0x3e12f1(0xaa)](),_0x4a4290=inferParamType(_0x3ccd38);if(_0x4a4290===_0x3e12f1(0xa3)){if(_0x3ccd38[_0x3e12f1(0xd4)]('limit')||_0x3ccd38['includes'](_0x3e12f1(0xe9))||_0x3ccd38[_0x3e12f1(0xd4)](_0x3e12f1(0xa1)))return 0xa;if(_0x3ccd38[_0x3e12f1(0xd4)](_0x3e12f1(0xc2)))return 0x1;return 0x7b;}if(_0x3ccd38[_0x3e12f1(0xd4)](_0x3e12f1(0xcb))||_0x3ccd38['includes'](_0x3e12f1(0xb9)))return _0x3e12f1(0xcc);if(_0x3ccd38[_0x3e12f1(0xd4)]('status'))return'1';if(_0x3ccd38[_0x3e12f1(0xd4)](_0x3e12f1(0xd1))||_0x3ccd38[_0x3e12f1(0xd4)](_0x3e12f1(0xa5))||_0x3ccd38[_0x3e12f1(0xd4)]('name'))return _0x3e12f1(0xa9);return'value';}export function validateIsSelectOnly(_0x5dc7d7){const _0x2b6e2a=a24_0x23f7;if(!_0x5dc7d7||typeof _0x5dc7d7!==_0x2b6e2a(0xdd))return{'valid':![],'reason':_0x2b6e2a(0xdf)};const _0x1c059f=_0x5dc7d7[_0x2b6e2a(0xdb)](/#\{[^}]*\}/g,'?')[_0x2b6e2a(0xdb)](/\$\{[^}]*\}/g,'?')[_0x2b6e2a(0xdb)](/@[^(\s]+(\([^)]*\))?/g,''),_0x491ed3=_0x1c059f[_0x2b6e2a(0xb7)](),_0x430d42=_0x491ed3[_0x2b6e2a(0xa8)]('\x0a');let _0x22f53e='';for(const _0x38b22e of _0x430d42){const _0x306787=_0x38b22e['trim']();if(!_0x306787||_0x306787['startsWith']('--')||_0x306787['startsWith']('/*'))continue;_0x22f53e=_0x306787;break;}if(!_0x22f53e[_0x2b6e2a(0xeb)]()[_0x2b6e2a(0xd9)](_0x2b6e2a(0xb3)))return{'valid':![],'reason':_0x2b6e2a(0xd2)};const _0x27e764=[_0x2b6e2a(0xc4),_0x2b6e2a(0xba),_0x2b6e2a(0xd8),_0x2b6e2a(0xb8),_0x2b6e2a(0x9e),_0x2b6e2a(0xa7),_0x2b6e2a(0xae),_0x2b6e2a(0xbc),_0x2b6e2a(0xb5),_0x2b6e2a(0xd5),'EXECUTE'],_0x2c40c5=_0x491ed3['toUpperCase']();for(const _0x26f23c of _0x27e764){const _0x2232e9=new RegExp(_0x26f23c,'i');if(_0x2232e9[_0x2b6e2a(0xe8)](_0x2c40c5))return{'valid':![],'reason':_0x2b6e2a(0x9d)+_0x26f23c[_0x2b6e2a(0xdb)]('\x5c\x5cs+','\x20')+_0x2b6e2a(0x9f)};}return{'valid':!![]};}export function extractTableNames(_0x238400){const _0x3cfa15=a24_0x23f7,_0x5231f2=parseSqlStructure(_0x238400);return _0x5231f2[_0x3cfa15(0xb6)];}export function extractColumnNames(_0x3420b2){const _0x33bbae=a24_0x23f7,_0x184538=parseSqlStructure(_0x3420b2);return _0x184538[_0x33bbae(0xe5)][_0x33bbae(0xca)](_0x205b00=>({'table':_0x205b00[_0x33bbae(0xb2)],'column':_0x205b00['column']}));}export function extractParameters(_0x5ae4dc){const _0x365d85=a24_0x23f7,_0x1407d9=parseSqlStructure(_0x5ae4dc);return _0x1407d9[_0x365d85(0xa2)];}function a24_0x5f35(){const _0x3789e9=['GRANT','60SqKGPp','limit','表\x20\x22','1462094IeSFXh','column','page','num','INSERT\x5cs+INTO','3173027BzDtYj','get','join','slice','\x20|\x20','map','date','2024-01-01','push','49oOoITx','price','valid','keyword','Only\x20SELECT\x20queries\x20are\x20allowed.\x20The\x20SQL\x20must\x20start\x20with\x20SELECT\x20(after\x20any\x20comments).','from','includes','EXEC','has','amount','DELETE\x5cs+FROM','startsWith','\x22\x20中不存在','replace','length','string','reason','SQL\x20content\x20cannot\x20be\x20empty','字段\x20\x22','Tables:\x20','66180Dvytye','SELECT\x20query','Params:\x20','columns','filter','220uXIXWo','test','count','match','toUpperCase','确保\x20SQL\x20语句以\x20SELECT\x20关键字开头','473048qczQrT','Forbidden\x20keyword\x20detected:\x20','ALTER\x5cs+(TABLE|DATABASE)','.\x20Only\x20SELECT\x20queries\x20are\x20allowed.','joins','size','parameters','number','2830024jwodDR','search','tableName','CREATE\x5cs+(TABLE|INDEX|DATABASE|VIEW)','split','example','toLowerCase','3zeLlTF','1951272hUluML','\x22\x20在表\x20\x22','TRUNCATE','SYNTAX_ERROR','keys','matchAll','table','SELECT','94854wArqMx','REVOKE','tables','trim','DROP\x5cs+(TABLE|INDEX|DATABASE)','time','UPDATE\x5cs+\x5cw+\x5cs+SET','error'];a24_0x5f35=function(){return _0x3789e9;};return a24_0x5f35();}export function validateSqlContent(_0x36a843,_0x59b8cf){const _0x3df6f1=a24_0x23f7,_0x526816=validateIsSelectOnly(_0x36a843);if(!_0x526816[_0x3df6f1(0xd0)])return{'valid':![],'isSelectOnly':![],'errors':[createStructuredSqlError({'type':_0x3df6f1(0xaf),'location':'SQL_START','message':_0x526816[_0x3df6f1(0xde)]||'SQL\x20必须以\x20SELECT\x20开头','severity':_0x3df6f1(0xbb),'fixSteps':[{'description':_0x3df6f1(0xec),'example':'SELECT\x20id,\x20name\x20FROM\x20customer\x20WHERE\x20status\x20=\x201'}]})]};const _0x5a44bc=parseSqlStructure(_0x36a843),_0x239913=[];if(_0x59b8cf){const _0x108799=new Map(_0x59b8cf[_0x3df6f1(0xb6)]['map'](_0x298923=>[_0x298923[_0x3df6f1(0xa6)][_0x3df6f1(0xaa)](),_0x298923[_0x3df6f1(0xe5)][_0x3df6f1(0xca)](_0x3d7776=>_0x3d7776[_0x3df6f1(0xaa)]())]));for(const _0x45ab35 of _0x5a44bc[_0x3df6f1(0xb6)]){const _0x5eb4d5=_0x45ab35[_0x3df6f1(0xaa)]();if(!_0x108799['has'](_0x5eb4d5)){const _0x3bdec2=Array['from'](_0x108799[_0x3df6f1(0xb0)]())[_0x3df6f1(0xe6)](_0x3e83bc=>_0x3e83bc[_0x3df6f1(0xd4)](_0x5eb4d5)||_0x5eb4d5[_0x3df6f1(0xd4)](_0x3e83bc));_0x239913[_0x3df6f1(0xcd)](createStructuredSqlError({'type':'TABLE_NOT_FOUND','location':_0x45ab35,'message':_0x3df6f1(0xbf)+_0x45ab35+'\x22\x20在数据库\x20schema\x20中不存在','severity':_0x3df6f1(0xbb),'suggestions':_0x3bdec2[_0x3df6f1(0xdc)]>0x0?_0x3bdec2:Array[_0x3df6f1(0xd3)](_0x108799[_0x3df6f1(0xb0)]())}));}}for(const _0x3822c4 of _0x5a44bc[_0x3df6f1(0xe5)]){if(_0x3822c4[_0x3df6f1(0xb2)]){const _0x1d8cd3=_0x3822c4[_0x3df6f1(0xb2)]['toLowerCase'](),_0x3110d1=_0x108799[_0x3df6f1(0xc6)](_0x1d8cd3);if(_0x3110d1){const _0x20903=_0x3822c4['column'][_0x3df6f1(0xaa)]();if(!_0x3110d1[_0x3df6f1(0xd4)](_0x20903)&&!_0x3822c4[_0x3df6f1(0xc1)][_0x3df6f1(0xd4)]('*')){const _0x524873=_0x3110d1[_0x3df6f1(0xe6)](_0xd98b79=>_0xd98b79[_0x3df6f1(0xd4)](_0x20903)||_0x20903[_0x3df6f1(0xd4)](_0xd98b79));_0x239913[_0x3df6f1(0xcd)](createStructuredSqlError({'type':'COLUMN_NOT_FOUND','location':_0x3822c4[_0x3df6f1(0xb2)]+'.'+_0x3822c4[_0x3df6f1(0xc1)],'message':_0x3df6f1(0xe0)+_0x3822c4[_0x3df6f1(0xc1)]+_0x3df6f1(0xad)+_0x3822c4[_0x3df6f1(0xb2)]+_0x3df6f1(0xda),'severity':_0x3df6f1(0xbb),'suggestions':_0x524873[_0x3df6f1(0xdc)]>0x0?_0x524873:_0x3110d1[_0x3df6f1(0xc8)](0x0,0xa)}));}}}}}return{'valid':_0x239913['length']===0x0,'isSelectOnly':!![],'parsedStructure':_0x5a44bc,'errors':_0x239913['length']>0x0?_0x239913:undefined};}function a24_0x23f7(_0x22d88d,_0xa7ec14){_0x22d88d=_0x22d88d-0x9c;const _0x5f35df=a24_0x5f35();let _0x23f739=_0x5f35df[_0x22d88d];return _0x23f739;}export function generateSqlSummary(_0x5cc5ac){const _0x5046f4=a24_0x23f7,_0x5e1945=parseSqlStructure(_0x5cc5ac),_0x2823e2=[];return _0x5e1945[_0x5046f4(0xb6)][_0x5046f4(0xdc)]>0x0&&_0x2823e2[_0x5046f4(0xcd)](_0x5046f4(0xe1)+_0x5e1945[_0x5046f4(0xb6)][_0x5046f4(0xc7)](',\x20')),_0x5e1945[_0x5046f4(0xa2)]['length']>0x0&&_0x2823e2['push'](_0x5046f4(0xe4)+_0x5e1945[_0x5046f4(0xa2)][_0x5046f4(0xca)](_0x13a3de=>_0x13a3de['name'])['join'](',\x20')),_0x5e1945[_0x5046f4(0xa0)]&&_0x5e1945[_0x5046f4(0xa0)][_0x5046f4(0xdc)]>0x0&&_0x2823e2[_0x5046f4(0xcd)]('Joins:\x20'+_0x5e1945['joins'][_0x5046f4(0xdc)]),_0x2823e2['length']>0x0?_0x2823e2[_0x5046f4(0xc7)](_0x5046f4(0xc9)):_0x5046f4(0xe3);}
|