Socket
Socket
Sign inDemoInstall

@alipay/faas-server-sdk

Package Overview
Dependencies
Maintainers
2
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alipay/faas-server-sdk - npm Package Compare versions

Comparing version 1.1.3-alpha.0 to 1.1.3-alpha.1

2

lib/MySQL/index.js

@@ -1,1 +0,1 @@

"use strict";var __importDefault=this&&this.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MySQL=void 0;const node_util_1=require("node:util"),node_diagnostics_channel_1=__importDefault(require("node:diagnostics_channel")),faas_server_utils_1=require("@alipay/faas-server-utils"),ali_rds_1=require("ali-rds"),transaction_1=require("./transaction"),debug=(0,node_util_1.debuglog)("faas-server-sdk:mysql");class MySQL{#e;#n;#s=!0;constructor(t){this.#e=t}async query(t,e){return await this.#t().query(t,e)}async insert(t,e,s){return await this.#t().insert(t,e,s)}async update(t,e,s){return await this.#t().update(t,e,s)}async select(t,e){return await this.#t().select(t,e)}async get(t,e,s){return await this.#t().get(t,e,s)}async delete(t,e){return await this.#t().delete(t,e)}async count(t,e){return await this.#t().count(t,e)}async beginTransaction(){const t=await this.#t().beginTransaction();return new transaction_1.MySQLTransaction(t)}async beginTransactionScope(t){return await this.#t().beginTransactionScope(async e=>{const s=new transaction_1.MySQLTransaction(e);return await t(s)})}#o(t=""){const e=(0,faas_server_utils_1.getAlipayContext)(),s=Date.now(),r={authorization:"","x-from-app-id":e.APPID,"x-from-env-id":this.#e.fromEnvId,"x-to-env-id":this.#e.toEnvId,"x-from-instance-id":this.#e.functionInstanceId,"x-from-function-name":this.#e.functionName,"x-client-timestamp":`${s}`,"x-trace-id":e.TRACEID},u=["x-from-app-id","x-from-env-id","x-from-instance-id","x-from-function-name","x-client-timestamp","x-to-env-id"],l={path:"",query:"",secretId:this.#e.secretId,secretKey:this.#e.secretKey,method:"POST",headers:r,body:t,timestamp:s,signedHeaders:u,isMySql:!0};r.authorization=(0,faas_server_utils_1.sign)(l);const c=[];for(const o in r){if(o==="authorization")continue;const i=r[o];c.push(`${o}:${i}`)}const a=r.authorization.split(" ");c.push(`SecAlgo:${a[0]}`);for(let o=1;o<a.length;o++){let i=a[o];i.endsWith(",")&&(i=i.substring(0,i.length-1)),c.push(i.replace(/=/g,":").replace(/,/g,";"))}return`!cloudbase:${c.join(",")}`}#t(){if(!this.#n){if(process.env.MYSQL_TEST_MODE==="test")this.#s=!1,this.#n=new ali_rds_1.RDSClient({host:process.env.MYSQL_HOST||"127.0.0.1",port:process.env.MYSQL_PORT?parseInt(process.env.MYSQL_PORT):3306,user:process.env.MYSQL_USER||"root",password:process.env.MYSQL_PASSWORD||"",database:process.env.MYSQL_DATABASE||"faas_unittest"});else{const[t,e]=this.#e.functionMysqlEndpoint.split(":");this.#n=new ali_rds_1.RDSClient({getConnectionConfig:()=>({host:t,port:parseInt(e),user:this.#o(),password:"",database:""})})}this.#n.beforeQuery(t=>this.#s?`/*${this.#o(t)}*/${t}`:t)}return this.#n}}exports.MySQL=MySQL;let globalClientId=0,globalConnectionId=0;const kClientId=Symbol("rds client id"),kClientEnqueueCount=Symbol("rds client enqueue counter"),kConnectionId=Symbol("connection id"),kConnectionCount=Symbol("rds client create connection counter"),kConnectionAcquireCount=Symbol("connection acquire counter"),kConnectionReleaseCount=Symbol("connection release counter"),kConnectionQueryStartCount=Symbol("connection query start counter"),kConnectionQueryEndCount=Symbol("connection query end counter");node_diagnostics_channel_1.default.subscribe("ali-rds:connection:new",n=>{const{client:t,connection:e}=n;t[kClientId]||(t[kClientId]=globalClientId++),e[kConnectionId]||(e[kConnectionId]=globalConnectionId++,e[kClientId]=t[kClientId]),t[kConnectionCount]=(t[kConnectionCount]||0)+1,debug("[ali-rds:connection:new] client#%s create a new connection#%s (%s#%s:%s), total created %s, stats: %o",t[kClientId],e[kConnectionId],e.threadId,e.config.host,e.config.port,t[kConnectionCount],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:acquire",n=>{const{client:t,connection:e}=n;e[kConnectionAcquireCount]=(e[kConnectionAcquireCount]||0)+1,debug("[ali-rds:connection:acquire] client#%s acquire connection#%s (%s#%s:%s, acquire/release: %s/%s), stats: %o",t[kClientId],e[kConnectionId],e.threadId,e.config.host,e.config.port,e[kConnectionAcquireCount],e[kConnectionReleaseCount]||0,t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:release",n=>{const{client:t,connection:e}=n;e[kConnectionReleaseCount]=(e[kConnectionReleaseCount]||0)+1,debug("[ali-rds:connection:release] client#%s release connection#%s (%s#%s:%s, acquire/release: %s/%s), stats: %o",t[kClientId],e[kConnectionId],e.threadId,e.config.host,e.config.port,e[kConnectionAcquireCount],e[kConnectionReleaseCount],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:enqueue",n=>{const{client:t}=n;t[kClientEnqueueCount]=(t[kClientEnqueueCount]||0)+1,debug("[ali-rds:connection:enqueue] client#%s enqueue, times: %s, stats: %o",t[kClientId],t[kClientEnqueueCount],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:query:start",n=>{const{sql:t,connection:e}=n;e[kConnectionQueryStartCount]=(e[kConnectionQueryStartCount]||0)+1,debug("[ali-rds:query:start] client#%s connection#%s (%s#%s:%s, query: %s/%s) start query: %j",e[kClientId],e[kConnectionId],e.threadId,e.config.host,e.config.port,e[kConnectionQueryStartCount],e[kConnectionQueryEndCount]||0,t)}),node_diagnostics_channel_1.default.subscribe("ali-rds:query:end",n=>{const{connection:t,duration:e,error:s}=n;t[kConnectionQueryEndCount]=(t[kConnectionQueryEndCount]||0)+1,debug("[ali-rds:query:end] client#%s connection#%s (%s#%s:%s, query: %s/%s) end query, duration: %sms, error: %s",t[kClientId],t[kConnectionId],t.threadId,t.config.host,t.config.port,t[kConnectionQueryStartCount],t[kConnectionQueryEndCount],e,s)});
"use strict";var __importDefault=this&&this.__importDefault||function(l){return l&&l.__esModule?l:{default:l}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MySQL=void 0;const node_util_1=require("node:util"),node_diagnostics_channel_1=__importDefault(require("node:diagnostics_channel")),faas_server_utils_1=require("@alipay/faas-server-utils"),ali_rds_1=require("ali-rds"),transaction_1=require("./transaction");class MySQL{#t;#n;#s=!0;constructor(s){this.#t=s}async query(s,n){return await this.#e().query(s,n)}async insert(s,n,i){return await this.#e().insert(s,n,i)}async update(s,n,i){return await this.#e().update(s,n,i)}async select(s,n){return await this.#e().select(s,n)}async get(s,n,i){return await this.#e().get(s,n,i)}async delete(s,n){return await this.#e().delete(s,n)}async count(s,n){return await this.#e().count(s,n)}async beginTransaction(){const s=await this.#e().beginTransaction();return new transaction_1.MySQLTransaction(s)}async beginTransactionScope(s){return await this.#e().beginTransactionScope(async n=>{const i=new transaction_1.MySQLTransaction(n);return await s(i)})}#o(s=""){const n=(0,faas_server_utils_1.getAlipayContext)(),i=Date.now(),r={authorization:"","x-from-app-id":n.APPID,"x-from-env-id":this.#t.fromEnvId,"x-to-env-id":this.#t.toEnvId,"x-from-instance-id":this.#t.functionInstanceId,"x-from-function-name":this.#t.functionName,"x-client-timestamp":`${i}`,"x-trace-id":n.TRACEID},h=["x-from-app-id","x-from-env-id","x-from-instance-id","x-from-function-name","x-client-timestamp","x-to-env-id"],d={path:"",query:"",secretId:this.#t.secretId,secretKey:this.#t.secretKey,method:"POST",headers:r,body:s,timestamp:i,signedHeaders:h,isMySql:!0};r.authorization=(0,faas_server_utils_1.sign)(d);const a=[];for(const c in r){if(c==="authorization")continue;const o=r[c];a.push(`${c}:${o}`)}const u=r.authorization.split(" ");a.push(`SecAlgo:${u[0]}`);for(let c=1;c<u.length;c++){let o=u[c];o.endsWith(",")&&(o=o.substring(0,o.length-1)),a.push(o.replace(/=/g,":").replace(/,/g,";"))}return`!cloudbase:${a.join(",")}`}#e(){if(!this.#n){if(process.env.MYSQL_TEST_MODE==="test")this.#s=!1,this.#n=new ali_rds_1.RDSClient({host:process.env.MYSQL_HOST||"127.0.0.1",port:process.env.MYSQL_PORT?parseInt(process.env.MYSQL_PORT):3306,user:process.env.MYSQL_USER||"root",password:process.env.MYSQL_PASSWORD||"",database:process.env.MYSQL_DATABASE||"faas_unittest"});else{const[s,n]=this.#t.functionMysqlEndpoint.split(":");this.#n=new ali_rds_1.RDSClient({getConnectionConfig:()=>({host:s,port:parseInt(n),user:this.#o(),password:"",database:""})})}this.#n.beforeQuery(s=>this.#s?`/*${this.#o(s)}*/${s}`:s)}return this.#n}}if(exports.MySQL=MySQL,(0,node_util_1.debuglog)("faas-server-sdk:mysql").enabled){let l=0,s=0;const n=Symbol("rds client id"),i=Symbol("rds client enqueue counter"),r=Symbol("connection id"),h=Symbol("rds client create connection counter"),d=Symbol("connection acquire counter"),a=Symbol("connection release counter"),u=Symbol("connection query start counter"),c=Symbol("connection query end counter");node_diagnostics_channel_1.default.subscribe("ali-rds:connection:new",o=>{const{client:t,connection:e}=o;t[n]||(t[n]=l++),e[r]||(e[r]=s++,e[n]=t[n]),t[h]=(t[h]||0)+1,console.debug("[ali-rds:connection:new] client#%s create a new connection#%s (%s#%s:%s), total created %s, stats: %o",t[n],e[r],e.threadId,e.config.host,e.config.port,t[h],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:acquire",o=>{const{client:t,connection:e}=o;e[d]=(e[d]||0)+1,console.debug("[ali-rds:connection:acquire] client#%s acquire connection#%s (%s#%s:%s, acquire/release: %s/%s), stats: %o",t[n],e[r],e.threadId,e.config.host,e.config.port,e[d],e[a]||0,t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:release",o=>{const{client:t,connection:e}=o;e[a]=(e[a]||0)+1,console.debug("[ali-rds:connection:release] client#%s release connection#%s (%s#%s:%s, acquire/release: %s/%s), stats: %o",t[n],e[r],e.threadId,e.config.host,e.config.port,e[d],e[a],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:connection:enqueue",o=>{const{client:t}=o;t[i]=(t[i]||0)+1,console.debug("[ali-rds:connection:enqueue] client#%s enqueue, times: %s, stats: %o",t[n],t[i],t.stats)}),node_diagnostics_channel_1.default.subscribe("ali-rds:query:start",o=>{const{sql:t,connection:e}=o;e[u]=(e[u]||0)+1,console.debug("[ali-rds:query:start] client#%s connection#%s (%s#%s:%s, query: %s/%s) start query: %j",e[n],e[r],e.threadId,e.config.host,e.config.port,e[u],e[c]||0,t)}),node_diagnostics_channel_1.default.subscribe("ali-rds:query:end",o=>{const{connection:t,duration:e,error:f}=o;t[c]=(t[c]||0)+1,console.debug("[ali-rds:query:end] client#%s connection#%s (%s#%s:%s, query: %s/%s) end query, duration: %sms, error: %s",t[n],t[r],t.threadId,t.config.host,t.config.port,t[u],t[c],e,f)})}

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.callMiddleware=void 0;const node_util_1=require("node:util"),urllib_1=require("urllib"),debug=(0,node_util_1.debuglog)("faas-server-sdk:httpRequest");async function callMiddleware(e,r){await r(),debug("%s %o with headers: %o, content: %o",e.req.requestOptions.method,e.req.url.href,e.req.requestOptions.headers,e.req.requestOptions.content),e.res=await(0,urllib_1.request)(e.req.url,e.req.requestOptions),e.result={status:e.res.status,requestID:e.requestId,headers:e.res.headers,data:e.res.data},debug("%s %o got response status: %o, headers: %o, data: %o",e.req.requestOptions.method,e.req.url.href,e.res.status,e.res.headers,e.res.data)}exports.callMiddleware=callMiddleware;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.callMiddleware=void 0;const node_util_1=require("node:util"),urllib_1=require("urllib"),debugLabel="faas-server-sdk:httpRequest".toLowerCase(),debugEnabled=(0,node_util_1.debuglog)(debugLabel).enabled;async function callMiddleware(e,s){await s(),debugEnabled&&console.debug("[%s] %s %o with headers: %o, content: %o",debugLabel,e.req.requestOptions.method,e.req.url.href,e.req.requestOptions.headers,e.req.requestOptions.content),e.res=await(0,urllib_1.request)(e.req.url,e.req.requestOptions),e.result={status:e.res.status,requestID:e.requestId,headers:e.res.headers,data:e.res.data},debugEnabled&&console.debug("[%s] %s %o got response status: %o, headers: %o, data: %o",debugLabel,e.req.requestOptions.method,e.req.url.href,e.res.status,e.res.headers,e.res.data)}exports.callMiddleware=callMiddleware;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.errorHandlerMiddleware=void 0;const node_util_1=require("node:util"),errors_1=require("../../errors"),debug=(0,node_util_1.debuglog)("faas-server-sdk:httpRequest");async function errorHandlerMiddleware(e,t){try{await t()}catch(r){throw debug("%s %o got failed: %s",e.req.requestOptions.method,e.req.url,r.stack),errors_1.errors.NETWORK_ERR(r,e.requestId)}}exports.errorHandlerMiddleware=errorHandlerMiddleware;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.errorHandlerMiddleware=void 0;const node_util_1=require("node:util"),errors_1=require("../../errors"),debugLabel="faas-server-sdk:httpRequest".toLowerCase(),debugEnabled=(0,node_util_1.debuglog)(debugLabel).enabled;async function errorHandlerMiddleware(e,o){try{await o()}catch(r){throw debugEnabled&&console.debug("[%s] %s %o got failed: %s",debugLabel,e.req.requestOptions.method,e.req.url,r.stack),errors_1.errors.NETWORK_ERR(r,e.requestId)}}exports.errorHandlerMiddleware=errorHandlerMiddleware;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileUploader=void 0;const node_util_1=require("node:util"),urllib_1=require("urllib"),debug=(0,node_util_1.debuglog)("faas-server-sdk:Storage");class FileUploader{static#e;async upload(a){const{uploadURL:t,fileID:s,fileContent:e}=a;let r,n;Buffer.isBuffer(e)?n=e:r=e;const o=await(0,urllib_1.request)(t,{method:"PUT",content:n,stream:r,timeout:6e4});return debug("uploadFile fileID: %o, uploadURL: %o got response status: %o, headers: %o, body: %o",s,t,o.status,o.headers,o.data.toString()),{statusCode:o.status}}async download(a){const{fileID:t,downloadURL:s}=a,e=await(0,urllib_1.request)(s,{timeout:6e4});return debug("downloadFile fileID: %o, downloadURL: %o got response status: %o, headers: %o, body length: %o",t,s,e.status,e.headers,e.data.length),{fileContent:e.data,statusCode:e.status}}static create(){return FileUploader.#e||(FileUploader.#e=new FileUploader),FileUploader.#e}}exports.FileUploader=FileUploader;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileUploader=void 0;const node_util_1=require("node:util"),urllib_1=require("urllib"),debugLabel="faas-server-sdk:Storage".toLowerCase(),debugEnabled=(0,node_util_1.debuglog)(debugLabel).enabled;class FileUploader{static#e;async upload(a){const{uploadURL:t,fileID:o,fileContent:e}=a;let n,r;Buffer.isBuffer(e)?r=e:n=e;const s=await(0,urllib_1.request)(t,{method:"PUT",content:r,stream:n,timeout:6e4});return debugEnabled&&console.debug("[%s] uploadFile fileID: %o, uploadURL: %o got response status: %o, headers: %o, body: %o",debugLabel,o,t,s.status,s.headers,s.data.toString()),{statusCode:s.status}}async download(a){const{fileID:t,downloadURL:o}=a,e=await(0,urllib_1.request)(o,{timeout:6e4});return debugEnabled&&console.debug("[%s] downloadFile fileID: %o, downloadURL: %o got response status: %o, headers: %o, body length: %o",debugLabel,t,o,e.status,e.headers,e.data.length),{fileContent:e.data,statusCode:e.status}}static create(){return FileUploader.#e||(FileUploader.#e=new FileUploader),FileUploader.#e}}exports.FileUploader=FileUploader;
{
"name": "@alipay/faas-server-sdk",
"version": "1.1.3-alpha.0",
"version": "1.1.3-alpha.1",
"description": "云函数服务 SDK",

@@ -36,5 +36,5 @@ "main": "lib/index.js",

"dependencies": {
"@alipay/faas-db-builder": "^1.1.3-alpha.0",
"@alipay/faas-server-utils": "^1.1.3-alpha.0",
"@alipay/faas-web-sdk": "^1.1.3-alpha.0",
"@alipay/faas-db-builder": "^1.1.3-alpha.1",
"@alipay/faas-server-utils": "^1.1.3-alpha.1",
"@alipay/faas-web-sdk": "^1.1.3-alpha.1",
"ali-rds": "^6.2.0",

@@ -41,0 +41,0 @@ "koa-compose": "^4.1.0",

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