dsql-admin/dsql-app/.local_dist/server/chunks/1251.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

1 line
7.1 KiB
JavaScript

"use strict";exports.id=1251,exports.ids=[1251],exports.modules={96762:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,n){return n in t?t[n]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,n)):"function"==typeof t&&"default"===n?t:void 0}}})},98e3:(e,t,n)=>{n.d(t,{A:()=>d});var r=n(72583),a=n.n(r),o=n(92652),s=n(30802),c=n(48786),i=n(37275),l=n(68829),u=n(7971);async function d({dbContext:e,paradigm:t,dbFullName:n,tableName:r,data:d,tableSchema:p,duplicateColumnName:_,duplicateColumnValue:f,update:g,encryptionKey:h,encryptionSalt:y,useLocal:S}){let E=!!S||!e?.match(/dsql.user/i)&&(!n||!!n.match(/^datasquirel$/)),m=S?u.A:E?c.A:i.A;if(d?.date_created_timestamp&&delete d.date_created_timestamp,d?.date_updated_timestamp&&delete d.date_updated_timestamp,d?.date_updated&&delete d.date_updated,d?.date_updated_code&&delete d.date_updated_code,d?.date_created&&delete d.date_created,d?.date_created_code&&delete d.date_created_code,_&&"string"==typeof _){let a=E?await m(`SELECT * FROM \`${r}\` WHERE \`${_}\`=?`,[f]):await m({paradigm:"Read Only",queryString:`SELECT * FROM \`${n}\`.\`${r}\` WHERE \`${_}\`=?`,queryValues:[f]});if(a?.[0]&&!g)return null;if(a&&a[0]&&g)return await (0,s.A)({dbContext:e,paradigm:t,dbFullName:n,tableName:r,data:d,tableSchema:p,encryptionKey:h,encryptionSalt:y,identifierColumnName:_,identifierValue:f||""})}let A=Object.keys(d),D=[],N=[];for(let e=0;e<A.length;e++)try{let t=A[e],n=d?.[t],r=p?p?.fields?.filter(e=>e.fieldName==t):null,s=r&&r[0]?r[0]:null;if(null==n||void 0==n||s?.dataType?.match(/int$/i)&&"string"==typeof n&&!n?.match(/./))continue;s?.encrypted&&(n=(0,l.A)({data:n,encryptionKey:h,encryptionSalt:y}),console.log("DSQL: Encrypted value =>",n));let c=/<[^>]+>/g;(s?.richText||String(n).match(c))&&(n=a()(n,o.A)),s?.pattern&&!new RegExp(s.pattern,s.patternFlags||"").test(n)&&(console.log("DSQL: Pattern not matched =>",n),n=""),D.push("`"+t+"`"),"object"==typeof n&&(n=JSON.stringify(n)),"number"==typeof n?N.push(String(n)):N.push(n)}catch(e){console.log("DSQL: Error in parsing data keys =>",e.message);continue}d?.date_created||(D.push("`date_created`"),N.push(Date())),d?.date_created_code||(D.push("`date_created_code`"),N.push(Date.now())),d?.date_updated||(D.push("`date_updated`"),N.push(Date())),d?.date_updated_code||(D.push("`date_updated_code`"),N.push(Date.now()));let L=`INSERT INTO \`${n}\`.\`${r}\` (${D.join(",")}) VALUES (${N.map(()=>"?").join(",")})`;return E?await m(L,N):await m({paradigm:t,queryString:L,queryValues:N})}},30802:(e,t,n)=>{n.d(t,{A:()=>u});var r=n(72583),a=n.n(r),o=n(92652),s=n(48786),c=n(37275),i=n(68829),l=n(7971);async function u({dbContext:e,paradigm:t,dbFullName:n,tableName:r,data:u,tableSchema:d,identifierColumnName:p,identifierValue:_,encryptionKey:f,encryptionSalt:g,useLocal:h}){if(!u||!Object.keys(u).length)return null;let y=!!h||!e?.match(/dsql.user/i)&&(!n||!!n.match(/^datasquirel$/)),S=h?l.A:y?s.A:c.A,E=Object.keys(u),m=[],A=[];for(let e=0;e<E.length;e++)try{let t=E[e],n=u[t],r=d?d?.fields?.filter(e=>e.fieldName===t):null,s=r&&r[0]?r[0]:null;if(null==n||void 0==n)continue;let c=/<[^>]+>/g;(s?.richText||String(n).match(c))&&(n=a()(n,o.A)),s?.encrypted&&(n=(0,i.A)({data:n,encryptionKey:f,encryptionSalt:g})),"object"==typeof n&&(n=JSON.stringify(n)),s?.pattern&&!new RegExp(s.pattern,s.patternFlags||"").test(n)&&(console.log("DSQL: Pattern not matched =>",n),n=""),"string"==typeof n&&n.match(/^null$/i)&&(n={toSqlString:function(){return"NULL"}}),"string"!=typeof n||n.match(/./i)||(n={toSqlString:function(){return"NULL"}}),m.push(`\`${t}\`=?`),"number"==typeof n?A.push(String(n)):A.push(n)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}m.push(`date_updated='${Date()}'`),m.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE \`${n}\`.\`${r}\` SET ${m.join(",")} WHERE \`${p}\`=?`;return A.push(_),y?await S(D,A):await S({paradigm:t,queryString:D,queryValues:A})}},92652:(e,t,n)=>{n.d(t,{A:()=>r});let r={allowedTags:["b","i","em","strong","a","p","span","ul","ol","li","h1","h2","h3","h4","h5","h6","img","div","button","pre","code","br"],allowedAttributes:{a:["href"],img:["src","alt","width","height","class","style"],"*":["style","class"]}}},68829:(e,t,n)=>{n.d(t,{A:()=>o});var r=n(55511),a=n(79428);function o({data:e,encryptionKey:t,encryptionSalt:n}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let o=t||process.env.DSQL_ENCRYPTION_PASSWORD,s=n||process.env.DSQL_ENCRYPTION_SALT,c=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!s?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let i=(0,r.scryptSync)(o,s,c),l=a.Buffer.alloc(16,0),u=(0,r.createCipheriv)("aes-192-cbc",i,l);try{let t=u.update(e,"utf8","hex");return t+=u.final("hex")}catch(t){return console.log("Error in encrypting =>",t.message),e}}},48786:(e,t,n)=>{n.d(t,{A:()=>r});async function r(...e){let t=global.DSQL_DB_CONN;try{if(!t)throw Error("No Connection provided to DB_HANDLER function!");let n=await t.query(...e);return JSON.parse(JSON.stringify(n))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await t?.end()}}},37275:(e,t,n)=>{async function r(e,t,n){try{if("string"==typeof t){let r=await e.query(a(t),n);return JSON.parse(JSON.stringify(r))}if("object"!=typeof t)return null;{let n=[];for(let r=0;r<t.length;r++)try{let o=t[r],s=await e.query(a(o.query),o.values);n.push(JSON.parse(JSON.stringify(s)))}catch(e){n.push(null)}return n}}catch(e){return null}finally{e.end()}}function a(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}async function o({paradigm:e,queryString:t,queryValues:n}){try{switch(e){case"Read Only":return await r(global.DSQL_READ_ONLY_DB_CONN,t,n);case"Full Access":case"FA":return await r(global.DSQL_FULL_ACCESS_DB_CONN,t,n);default:return null}}catch(e){return console.log(`DSQL_USER_DB_HANDLER Error: ${e.message}`),null}}n.d(t,{A:()=>o})},7971:(e,t,n)=>{n.d(t,{A:()=>c});var r=n(9973),a=n.n(r),o=n(29021),s=n.n(o);async function c(...e){let t=a()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s().existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s().readFileSync(`${e}/ca-cert.pem`),rejectUnauthorized:!1}}()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let n=await t.query(...e);return await t.end(),JSON.parse(JSON.stringify(n))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}},2706:(e,t)=>{Object.defineProperty(t,"A",{enumerable:!0,get:function(){return n}});var n=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,t,n)=>{e.exports=n(75600)}};