@alipay/faas-web-sdk 1.1.3 → 1.1.4-alpha.1

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Aggregate=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils");class Aggregate{#e;#s;#t;constructor(t,e){this.#s=t,this.#e=e,this.#t=new faas_db_builder_1.AggregateBuilder(t)}match(t){return this.#t.match(t),this}group(t){return this.#t.group(t),this}sample(t){return this.#t.sample(t),this}lookup(t){return this.#t.lookup(t),this}async end(){const{options:t}=this.#t.end(),e="POST",s=`${this.#r()}?aggregate`,r=await this.#e.httpclient.request({method:e,path:s,data:t,headers:{}});return utils_1.ResponseUtil.handleResponse(r)}#r(){return`/${this.#e.databaseName||"faas"}/${this.#s}`}}exports.Aggregate=Aggregate;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Aggregate=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils");class Aggregate{#e;#s;#t;constructor(t,e){this.#s=t,this.#e=e,this.#t=new faas_db_builder_1.AggregateBuilder(t)}match(t){return this.#t.match(t),this}group(t){return this.#t.group(t),this}sample(t){return this.#t.sample(t),this}lookup(t){return this.#t.lookup(t),this}async end(){const{options:t}=this.#t.end(),e="POST",s=`${this.#r()}?aggregate`,r=await this.#e.httpclient.request({method:e,path:s,data:t});return utils_1.ResponseUtil.handleResponse(r)}#r(){return`/${this.#e.databaseName||"faas"}/${this.#s}`}}exports.Aggregate=Aggregate;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Collection=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils"),Aggregate_1=require("./Aggregate"),Document_1=require("./Document"),Query_1=require("./Query");class Collection{#e;#t;builder;constructor(e,t){this.#t=e,this.#e=t,this.builder=new faas_db_builder_1.CollectionBuilder(e)}async add(e){const{options:t}=this.builder.add(e),r="POST",i=this.#r(e.data._id),s=await this.#e.httpclient.request({method:r,path:i,data:t,headers:{}});return utils_1.ResponseUtil.handleResponse(s)}doc(e){return new Document_1.Document(this.#t,e,this.#e)}limit(e){return new Query_1.Query(this.#t,this.#e).limit(e)}skip(e){return new Query_1.Query(this.#t,this.#e).skip(e)}where(e){return new Query_1.Query(this.#t,this.#e).where(e)}projection(e){return new Query_1.Query(this.#t,this.#e).projection(e)}field(e){return new Query_1.Query(this.#t,this.#e).field(e)}orderBy(e,t){return new Query_1.Query(this.#t,this.#e).orderBy(e,t)}aggregate(){return new Aggregate_1.Aggregate(this.#t,this.#e)}async get(){return await new Query_1.Query(this.#t,this.#e).get()}async count(){return await new Query_1.Query(this.#t,this.#e).count()}#r(e){return`/${this.#e.databaseName||"faas"}/${this.#t}?_id=${e||""}`}}exports.Collection=Collection;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Collection=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils"),Aggregate_1=require("./Aggregate"),Document_1=require("./Document"),Query_1=require("./Query");class Collection{#e;#t;builder;constructor(e,t){this.#t=e,this.#e=t,this.builder=new faas_db_builder_1.CollectionBuilder(e)}async add(e){const{options:t}=this.builder.add(e),r="POST",i=this.#r(e.data._id),s=await this.#e.httpclient.request({method:r,path:i,data:t});return utils_1.ResponseUtil.handleResponse(s)}doc(e){return new Document_1.Document(this.#t,e,this.#e)}limit(e){return new Query_1.Query(this.#t,this.#e).limit(e)}skip(e){return new Query_1.Query(this.#t,this.#e).skip(e)}where(e){return new Query_1.Query(this.#t,this.#e).where(e)}projection(e){return new Query_1.Query(this.#t,this.#e).projection(e)}field(e){return new Query_1.Query(this.#t,this.#e).field(e)}orderBy(e,t){return new Query_1.Query(this.#t,this.#e).orderBy(e,t)}aggregate(){return new Aggregate_1.Aggregate(this.#t,this.#e)}async get(){return await new Query_1.Query(this.#t,this.#e).get()}async count(){return await new Query_1.Query(this.#t,this.#e).count()}#r(e){return`/${this.#e.databaseName||"faas"}/${this.#t}?_id=${e||""}`}}exports.Collection=Collection;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Query=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils");class Query{#e;#n;#t;constructor(t,e){this.#n=t,this.#e=e,this.#t=new faas_db_builder_1.QueryBuilder(t)}limit(t){return this.#t.limit(t),this}skip(t){return this.#t.skip(t),this}where(t){return this.#t.where(t),this}projection(t){return this.#t.projection(t),this}field(t){return this.#t.projection(t),this}orderBy(t,e){return this.#t.orderBy(t,e),this}async update(t){const e="POST",s=`${this.#s()}?update`,{options:n}=this.#t.update(t),i=await this.#e.httpclient.request({method:e,path:s,data:n,headers:{}});return utils_1.ResponseUtil.handleResponse(i)}async set(t){const e="POST",s=`${this.#s()}?replace`,{options:n}=this.#t.set(t),i=await this.#e.httpclient.request({method:e,path:s,data:n,headers:{}});return utils_1.ResponseUtil.handleResponse(i)}async remove(){const t="POST",e=`${this.#s()}?delete`,{options:s}=this.#t.remove(),n=await this.#e.httpclient.request({method:t,path:e,data:s,headers:{}});return utils_1.ResponseUtil.handleResponse(n)}async get(){const t="POST",e=`${this.#s()}?query`,{options:s}=this.#t.get(),n=await this.#e.httpclient.request({method:t,path:e,data:s,headers:{}});return utils_1.ResponseUtil.handleResponse(n)}async count(){const t="POST",e=`${this.#s()}?count`,{options:s}=this.#t.count(),n=await this.#e.httpclient.request({method:t,path:e,data:s,headers:{}});return{total:utils_1.ResponseUtil.handleResponse(n).count}}#s(){return`/${this.#e.databaseName||"faas"}/${this.#n}`}}exports.Query=Query;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Query=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),utils_1=require("../utils");class Query{#e;#n;#t;constructor(t,e){this.#n=t,this.#e=e,this.#t=new faas_db_builder_1.QueryBuilder(t)}limit(t){return this.#t.limit(t),this}skip(t){return this.#t.skip(t),this}where(t){return this.#t.where(t),this}projection(t){return this.#t.projection(t),this}field(t){return this.#t.projection(t),this}orderBy(t,e){return this.#t.orderBy(t,e),this}async update(t){const e="POST",s=`${this.#s()}?update`,{options:n}=this.#t.update(t),i=await this.#e.httpclient.request({method:e,path:s,data:n});return utils_1.ResponseUtil.handleResponse(i)}async set(t){const e="POST",s=`${this.#s()}?replace`,{options:n}=this.#t.set(t),i=await this.#e.httpclient.request({method:e,path:s,data:n});return utils_1.ResponseUtil.handleResponse(i)}async remove(){const t="POST",e=`${this.#s()}?delete`,{options:s}=this.#t.remove(),n=await this.#e.httpclient.request({method:t,path:e,data:s});return utils_1.ResponseUtil.handleResponse(n)}async get(){const t="POST",e=`${this.#s()}?query`,{options:s}=this.#t.get(),n=await this.#e.httpclient.request({method:t,path:e,data:s});return utils_1.ResponseUtil.handleResponse(n)}async count(){const t="POST",e=`${this.#s()}?count`,{options:s}=this.#t.count(),n=await this.#e.httpclient.request({method:t,path:e,data:s});return{total:utils_1.ResponseUtil.handleResponse(n).count}}#s(){return`/${this.#e.databaseName||"faas"}/${this.#n}`}}exports.Query=Query;
package/lib/Storage.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Storage=void 0;const error_1=require("./error"),utils_1=require("./utils");class Storage{#t;constructor(t){this.#t=t}#i(t){return`/${t}?upload_url`}#a(t){return`/${t}?download_url&expire=3600`}#n(){return"/?delete"}#l(){return"/?download_url"}#h(t){if(typeof t!="string")return"\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32";if(t=t.trim(),!t)return"\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32";if(t.startsWith("/"))return"\u4E0D\u80FD\u4EE5 / \u5F00\u5934";if(t.includes("//"))return"\u4E0D\u80FD\u5305\u542B\u8FDE\u7EED\u7684 /";if(t.length>850)return"\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7 850 \u5B57\u8282"}#s(t){if(typeof t!="string")return"\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32";if(t=t.trim(),!t)return"\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32"}#r(t){return`cloud://${this.#t.toEnvId}/${t.replace(/^\/+/,"")}`}#o(t){const s=t.trim().replace(/^cloud:\/\//,""),r=s.indexOf("/");if(r<=0)throw error_1.FaasError.INVALID_PARAM_ERR("fileID","\u4E0D\u5408\u6CD5");const o=s.substring(0,r),i=s.substring(r+1);return o!==this.#t.toEnvId&&console.warn(`file ${t} does not belong to env ${this.#t.toEnvId}`),i}async uploadFile(t){const s=this.#h(t.cloudPath);if(s)throw error_1.FaasError.INVALID_PARAM_ERR("cloudPath",s);const r=this.#i(t.cloudPath.trim()),o=await this.#e({method:"GET",path:r,data:{},headers:{}}),i=utils_1.ResponseUtil.handleResponse(o),a=this.#r(i.file_id),e=await this.#t.fileUploader.upload({fileID:a,uploadURL:i.upload_url,fileContent:t.fileContent});if(e.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",o.requestID);return{fileID:a,statusCode:e.statusCode}}async downloadFile(t){const s=this.#s(t.fileID);if(s)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",s);const r=this.#o(t.fileID),o=this.#a(r),i=await this.#e({method:"GET",path:o,data:{},headers:{}}),a=utils_1.ResponseUtil.handleResponse(i),e=await this.#t.fileUploader.download({fileID:t.fileID,downloadURL:a.download_url});if(e.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",i.requestID);return e}async deleteFile(t){const s=Array.isArray(t)?t:t.fileList;if(!Array.isArray(s)||s.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");const r=[];for(const e of s){const n=this.#s(e);if(n)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",n);const l=this.#o(e);r.push(l)}const o=this.#n(),i=await this.#e({method:"POST",path:o,data:{file_list:r},headers:{}});return{fileList:utils_1.ResponseUtil.handleResponse(i).file_list.map(e=>({fileID:this.#r(e.file_id),status:e.status?0:-1,errMsg:e.status?"ok":e.result_message}))}}async getTempFileURL(t){const s=Array.isArray(t)?t:t.fileList;if(!Array.isArray(s)||s.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");if(s.length>50)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u6700\u5927\u957F\u5EA6 50");const r=[];for(const e of s){const n=this.#s(e);if(n)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",n);const l=this.#o(e);r.push({file_id:l,expire:600})}const o=this.#l(),i=await this.#e({method:"POST",path:o,data:{file_list:r},headers:{}});return{fileList:utils_1.ResponseUtil.handleResponse(i).file_list.map(e=>({fileID:this.#r(e.file_id),tempFileURL:e.download_url,status:e.status?0:-1,errMsg:e.status?"ok":e.result_message}))}}async#e({method:t,path:s,data:r,headers:o}){return await this.#t.httpclient.request({method:t,path:s,data:r,headers:{"x-alipay-cloud-mode":"oss","x-data-api-type":"oss","x-expire-timestamp":`${Date.now()+6e4}`,...o}})}}exports.Storage=Storage;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Storage=void 0;const error_1=require("./error"),utils_1=require("./utils");class Storage{#t;constructor(t){this.#t=t}#i(t){return`/${t}?upload_url`}#n(t){return`/${t}?download_url&expire=3600`}#a(){return"/?delete"}#l(){return"/?download_url"}#h(t){if(typeof t!="string")return"\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32";if(t=t.trim(),!t)return"\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32";if(t.startsWith("/"))return"\u4E0D\u80FD\u4EE5 / \u5F00\u5934";if(t.includes("//"))return"\u4E0D\u80FD\u5305\u542B\u8FDE\u7EED\u7684 /";if(t.length>850)return"\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7 850 \u5B57\u8282"}#s(t){if(typeof t!="string")return"\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32";if(t=t.trim(),!t)return"\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32"}#r(t){return`cloud://${this.#t.toEnvId}/${t.replace(/^\/+/,"")}`}#o(t){const s=t.trim().replace(/^cloud:\/\//,""),r=s.indexOf("/");if(r<=0)throw error_1.FaasError.INVALID_PARAM_ERR("fileID","\u4E0D\u5408\u6CD5");const o=s.substring(0,r),i=s.substring(r+1);return o!==this.#t.toEnvId&&console.warn(`file ${t} does not belong to env ${this.#t.toEnvId}`),i}async uploadFile(t){const s=this.#h(t.cloudPath);if(s)throw error_1.FaasError.INVALID_PARAM_ERR("cloudPath",s);const r=this.#i(t.cloudPath.trim()),o=await this.#e({method:"GET",path:r}),i=utils_1.ResponseUtil.handleResponse(o),n=this.#r(i.file_id),e=await this.#t.fileUploader.upload({fileID:n,uploadURL:i.upload_url,fileContent:t.fileContent});if(e.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",o.requestID);return{fileID:n,statusCode:e.statusCode}}async downloadFile(t){const s=this.#s(t.fileID);if(s)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",s);const r=this.#o(t.fileID),o=this.#n(r),i=await this.#e({method:"GET",path:o}),n=utils_1.ResponseUtil.handleResponse(i),e=await this.#t.fileUploader.download({fileID:t.fileID,downloadURL:n.download_url});if(e.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",i.requestID);return e}async deleteFile(t){const s=Array.isArray(t)?t:t.fileList;if(!Array.isArray(s)||s.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");const r=[];for(const e of s){const a=this.#s(e);if(a)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",a);const l=this.#o(e);r.push(l)}const o=this.#a(),i=await this.#e({method:"POST",path:o,data:{file_list:r}});return{fileList:utils_1.ResponseUtil.handleResponse(i).file_list.map(e=>({fileID:this.#r(e.file_id),status:e.status?0:-1,errMsg:e.status?"ok":e.result_message}))}}async getTempFileURL(t){const s=Array.isArray(t)?t:t.fileList;if(!Array.isArray(s)||s.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");if(s.length>50)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u6700\u5927\u957F\u5EA6 50");const r=[];for(const e of s){const a=this.#s(e);if(a)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",a);const l=this.#o(e);r.push({file_id:l,expire:600})}const o=this.#l(),i=await this.#e({method:"POST",path:o,data:{file_list:r}});return{fileList:utils_1.ResponseUtil.handleResponse(i).file_list.map(e=>({fileID:this.#r(e.file_id),tempFileURL:e.download_url,status:e.status?0:-1,errMsg:e.status?"ok":e.result_message}))}}async#e({method:t,path:s,data:r,headers:o}){return await this.#t.httpclient.request({method:t,path:s,data:r,headers:{"x-alipay-cloud-mode":"oss","x-data-api-type":"oss","x-expire-timestamp":`${Date.now()+6e4}`,...o}})}}exports.Storage=Storage;
package/lib/types.d.ts CHANGED
@@ -22,8 +22,8 @@ export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT'
22
22
  export interface HttpRequestOptions {
23
23
  method: HttpMethod;
24
24
  path: string;
25
- data: any;
26
- headers: Record<string, string | string[]>;
25
+ data?: any;
26
+ headers?: Record<string, string | string[]>;
27
27
  }
28
28
  export interface HttpResponse<T> {
29
29
  status: number;
@@ -48,7 +48,7 @@ export interface CallFunctionResult<T = any> {
48
48
  }
49
49
  export interface CallFunctionParam {
50
50
  name: string;
51
- data: object | string | number | boolean;
51
+ data?: object | string | number | boolean;
52
52
  }
53
53
  export type CallFunction<T> = FunctionCall<CallFunctionParam, CallFunctionResult<T>>;
54
54
  export interface CallContainerResult<T> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/faas-web-sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.4-alpha.1",
4
4
  "description": "云函数服务 SDK",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "typescript": "^5.0.4"
26
26
  },
27
27
  "dependencies": {
28
- "@alipay/faas-db-builder": "^1.1.3"
28
+ "@alipay/faas-db-builder": "^1.1.4-alpha.1"
29
29
  },
30
30
  "engines": {
31
31
  "node": ">= 16.0.0"