@alipay/faas-common-sdk 1.1.9 → 1.1.10-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.
- package/lib/Database/Aggregate.d.ts +0 -1
- package/lib/Database/Aggregate.js +1 -1
- package/lib/Database/Collection.d.ts +0 -1
- package/lib/Database/Collection.js +1 -1
- package/lib/Database/Document.d.ts +0 -1
- package/lib/Database/Document.js +1 -1
- package/lib/Database/Query.d.ts +0 -1
- package/lib/Database/Query.js +1 -1
- package/lib/Database/index.d.ts +0 -1
- package/lib/Database/index.js +1 -1
- package/lib/Storage.d.ts +0 -1
- package/lib/Storage.js +1 -1
- package/lib/callContainer.js +1 -1
- package/lib/callFunction.js +1 -1
- package/lib/error.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +6 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LookupAggregateParam, QueryChainCommand, SampleAggregateParam } from '@alipay/faas-db-builder';
|
|
2
2
|
import { CreateDatabaseOptions } from '../types';
|
|
3
3
|
export declare class Aggregate {
|
|
4
|
-
#private;
|
|
5
4
|
constructor(collectionName: string, options: CreateDatabaseOptions);
|
|
6
5
|
match(match: QueryChainCommand): Aggregate;
|
|
7
6
|
group(group: object): Aggregate;
|
|
@@ -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{
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(a,t,e,i){function r(n){return n instanceof e?n:new e(function(o){o(n)})}return new(e||(e=Promise))(function(n,o){function l(s){try{h(i.next(s))}catch(c){o(c)}}function u(s){try{h(i.throw(s))}catch(c){o(c)}}function h(s){s.done?n(s.value):r(s.value).then(l,u)}h((i=i.apply(a,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(a,t,e,i,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!r:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(a,e):r?r.value=e:t.set(a,e),e},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(a,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?a!==t||!i:!t.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(a):i?i.value:t.get(a)},_Aggregate_instances,_Aggregate_options,_Aggregate_collectionName,_Aggregate_builder,_Aggregate_getCollectionPath;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{constructor(t,e){_Aggregate_instances.add(this),_Aggregate_options.set(this,void 0),_Aggregate_collectionName.set(this,void 0),_Aggregate_builder.set(this,void 0),__classPrivateFieldSet(this,_Aggregate_collectionName,t,"f"),__classPrivateFieldSet(this,_Aggregate_options,e,"f"),__classPrivateFieldSet(this,_Aggregate_builder,new faas_db_builder_1.AggregateBuilder(t),"f")}match(t){return __classPrivateFieldGet(this,_Aggregate_builder,"f").match(t),this}group(t){return __classPrivateFieldGet(this,_Aggregate_builder,"f").group(t),this}sample(t){return __classPrivateFieldGet(this,_Aggregate_builder,"f").sample(t),this}lookup(t){return __classPrivateFieldGet(this,_Aggregate_builder,"f").lookup(t),this}end(){return __awaiter(this,void 0,void 0,function*(){const{options:t}=__classPrivateFieldGet(this,_Aggregate_builder,"f").end(),e="POST",i=`${__classPrivateFieldGet(this,_Aggregate_instances,"m",_Aggregate_getCollectionPath).call(this)}?aggregate`,r=yield __classPrivateFieldGet(this,_Aggregate_options,"f").httpclient.request({method:e,path:i,data:t});return utils_1.ResponseUtil.handleResponse(r)})}}exports.Aggregate=Aggregate,_Aggregate_options=new WeakMap,_Aggregate_collectionName=new WeakMap,_Aggregate_builder=new WeakMap,_Aggregate_instances=new WeakSet,_Aggregate_getCollectionPath=function(){return`/${__classPrivateFieldGet(this,_Aggregate_options,"f").databaseName||"faas"}/${__classPrivateFieldGet(this,_Aggregate_collectionName,"f")}`};
|
|
@@ -4,7 +4,6 @@ import { Aggregate } from './Aggregate';
|
|
|
4
4
|
import { Document } from './Document';
|
|
5
5
|
import { Query } from './Query';
|
|
6
6
|
export declare class Collection {
|
|
7
|
-
#private;
|
|
8
7
|
private readonly builder;
|
|
9
8
|
constructor(collectionName: string, options: CreateDatabaseOptions);
|
|
10
9
|
add(param: AddDocumentParam): Promise<AddDocumentResult>;
|
|
@@ -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{
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(n,t,e,i){function r(o){return o instanceof e?o:new e(function(a){a(o)})}return new(e||(e=Promise))(function(o,a){function h(s){try{u(i.next(s))}catch(c){a(c)}}function l(s){try{u(i.throw(s))}catch(c){a(c)}}function u(s){s.done?o(s.value):r(s.value).then(h,l)}u((i=i.apply(n,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(n,t,e,i,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?n!==t||!r:!t.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(n,e):r?r.value=e:t.set(n,e),e},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(n,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?n!==t||!i:!t.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(n):i?i.value:t.get(n)},_Collection_instances,_Collection_options,_Collection_collectionName,_Collection_getDocumentPath;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{constructor(t,e){_Collection_instances.add(this),_Collection_options.set(this,void 0),_Collection_collectionName.set(this,void 0),__classPrivateFieldSet(this,_Collection_collectionName,t,"f"),__classPrivateFieldSet(this,_Collection_options,e,"f"),this.builder=new faas_db_builder_1.CollectionBuilder(t)}add(t){return __awaiter(this,void 0,void 0,function*(){const{options:e}=this.builder.add(t),i="POST",r=__classPrivateFieldGet(this,_Collection_instances,"m",_Collection_getDocumentPath).call(this,t.data._id),o=yield __classPrivateFieldGet(this,_Collection_options,"f").httpclient.request({method:i,path:r,data:e});return utils_1.ResponseUtil.handleResponse(o)})}doc(t){return new Document_1.Document(__classPrivateFieldGet(this,_Collection_collectionName,"f"),t,__classPrivateFieldGet(this,_Collection_options,"f"))}limit(t){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).limit(t)}skip(t){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).skip(t)}where(t){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).where(t)}projection(t){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).projection(t)}field(t){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).field(t)}orderBy(t,e){return new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).orderBy(t,e)}aggregate(){return new Aggregate_1.Aggregate(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f"))}get(){return __awaiter(this,void 0,void 0,function*(){return yield new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).get()})}count(){return __awaiter(this,void 0,void 0,function*(){return yield new Query_1.Query(__classPrivateFieldGet(this,_Collection_collectionName,"f"),__classPrivateFieldGet(this,_Collection_options,"f")).count()})}}exports.Collection=Collection,_Collection_options=new WeakMap,_Collection_collectionName=new WeakMap,_Collection_instances=new WeakSet,_Collection_getDocumentPath=function(t){return`/${__classPrivateFieldGet(this,_Collection_options,"f").databaseName||"faas"}/${__classPrivateFieldGet(this,_Collection_collectionName,"f")}?_id=${t||""}`};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { UpdateData } from '@alipay/faas-db-builder';
|
|
2
2
|
import { CreateDatabaseOptions, DeleteDocumentResult, UpdateDocumentResult } from '../types';
|
|
3
3
|
export declare class Document {
|
|
4
|
-
#private;
|
|
5
4
|
constructor(collectionName: string, id: string, options: CreateDatabaseOptions);
|
|
6
5
|
update(data: UpdateData): Promise<UpdateDocumentResult>;
|
|
7
6
|
set(data: UpdateData): Promise<UpdateDocumentResult>;
|
package/lib/Database/Document.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Document=void 0;const error_1=require("../error"),Query_1=require("./Query");class Document{
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(o,t,e,i){function r(s){return s instanceof e?s:new e(function(a){a(s)})}return new(e||(e=Promise))(function(s,a){function d(n){try{c(i.next(n))}catch(u){a(u)}}function h(n){try{c(i.throw(n))}catch(u){a(u)}}function c(n){n.done?s(n.value):r(n.value).then(d,h)}c((i=i.apply(o,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(o,t,e,i,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?o!==t||!r:!t.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(o,e):r?r.value=e:t.set(o,e),e},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(o,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?o!==t||!i:!t.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(o):i?i.value:t.get(o)},_Document_instances,_Document_options,_Document_collectionName,_Document_id,_Document_query_get;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Document=void 0;const error_1=require("../error"),Query_1=require("./Query");class Document{constructor(t,e,i){_Document_instances.add(this),_Document_options.set(this,void 0),_Document_collectionName.set(this,void 0),_Document_id.set(this,void 0),__classPrivateFieldSet(this,_Document_collectionName,t,"f"),__classPrivateFieldSet(this,_Document_id,e,"f"),__classPrivateFieldSet(this,_Document_options,i,"f")}update(t){return __awaiter(this,void 0,void 0,function*(){return yield __classPrivateFieldGet(this,_Document_instances,"a",_Document_query_get).update(t)})}set(t){return __awaiter(this,void 0,void 0,function*(){return yield __classPrivateFieldGet(this,_Document_instances,"a",_Document_query_get).set(t)})}remove(){return __awaiter(this,void 0,void 0,function*(){return yield __classPrivateFieldGet(this,_Document_instances,"a",_Document_query_get).remove()})}get(){return __awaiter(this,void 0,void 0,function*(){const e=(yield __classPrivateFieldGet(this,_Document_instances,"a",_Document_query_get).get())[0];if(!e){if(__classPrivateFieldGet(this,_Document_options,"f").throwOnNotFound)throw error_1.FaasError.NOT_FOUND_ERR(`\u4E0D\u5B58\u5728_id \u4E3A ${__classPrivateFieldGet(this,_Document_id,"f")} \u7684\u6587\u6863`);return null}return e})}}exports.Document=Document,_Document_options=new WeakMap,_Document_collectionName=new WeakMap,_Document_id=new WeakMap,_Document_instances=new WeakSet,_Document_query_get=function(){return new Query_1.Query(__classPrivateFieldGet(this,_Document_collectionName,"f"),__classPrivateFieldGet(this,_Document_options,"f")).where({_id:String(__classPrivateFieldGet(this,_Document_id,"f"))}).limit(1)};
|
package/lib/Database/Query.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { QueryChainCommand, Sort, UpdateData } from '@alipay/faas-db-builder';
|
|
2
2
|
import { CountDocumentResult, CreateDatabaseOptions, DeleteDocumentResult, UpdateDocumentResult } from '../types';
|
|
3
3
|
export declare class Query {
|
|
4
|
-
#private;
|
|
5
4
|
constructor(collectionName: string, options: CreateDatabaseOptions);
|
|
6
5
|
limit(limit: number): Query;
|
|
7
6
|
skip(skip: number): Query;
|
package/lib/Database/Query.js
CHANGED
|
@@ -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{
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(n,t,e,s){function i(o){return o instanceof e?o:new e(function(a){a(o)})}return new(e||(e=Promise))(function(o,a){function u(r){try{h(s.next(r))}catch(c){a(c)}}function d(r){try{h(s.throw(r))}catch(c){a(c)}}function h(r){r.done?o(r.value):i(r.value).then(u,d)}h((s=s.apply(n,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(n,t,e,s,i){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?n!==t||!i:!t.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?i.call(n,e):i?i.value=e:t.set(n,e),e},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(n,t,e,s){if(e==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?n!==t||!s:!t.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?s:e==="a"?s.call(n):s?s.value:t.get(n)},_Query_instances,_Query_options,_Query_collectionName,_Query_builder,_Query_getCollectionPath;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{constructor(t,e){_Query_instances.add(this),_Query_options.set(this,void 0),_Query_collectionName.set(this,void 0),_Query_builder.set(this,void 0),__classPrivateFieldSet(this,_Query_collectionName,t,"f"),__classPrivateFieldSet(this,_Query_options,e,"f"),__classPrivateFieldSet(this,_Query_builder,new faas_db_builder_1.QueryBuilder(t),"f")}limit(t){return __classPrivateFieldGet(this,_Query_builder,"f").limit(t),this}skip(t){return __classPrivateFieldGet(this,_Query_builder,"f").skip(t),this}where(t){return __classPrivateFieldGet(this,_Query_builder,"f").where(t),this}projection(t){return __classPrivateFieldGet(this,_Query_builder,"f").projection(t),this}field(t){return __classPrivateFieldGet(this,_Query_builder,"f").projection(t),this}orderBy(t,e){return __classPrivateFieldGet(this,_Query_builder,"f").orderBy(t,e),this}update(t){return __awaiter(this,void 0,void 0,function*(){const e="POST",s=`${__classPrivateFieldGet(this,_Query_instances,"m",_Query_getCollectionPath).call(this)}?update`,{options:i}=__classPrivateFieldGet(this,_Query_builder,"f").update(t),o=yield __classPrivateFieldGet(this,_Query_options,"f").httpclient.request({method:e,path:s,data:i});return utils_1.ResponseUtil.handleResponse(o)})}set(t){return __awaiter(this,void 0,void 0,function*(){const e="POST",s=`${__classPrivateFieldGet(this,_Query_instances,"m",_Query_getCollectionPath).call(this)}?replace`,{options:i}=__classPrivateFieldGet(this,_Query_builder,"f").set(t),o=yield __classPrivateFieldGet(this,_Query_options,"f").httpclient.request({method:e,path:s,data:i});return utils_1.ResponseUtil.handleResponse(o)})}remove(){return __awaiter(this,void 0,void 0,function*(){const t="POST",e=`${__classPrivateFieldGet(this,_Query_instances,"m",_Query_getCollectionPath).call(this)}?delete`,{options:s}=__classPrivateFieldGet(this,_Query_builder,"f").remove(),i=yield __classPrivateFieldGet(this,_Query_options,"f").httpclient.request({method:t,path:e,data:s});return utils_1.ResponseUtil.handleResponse(i)})}get(){return __awaiter(this,void 0,void 0,function*(){const t="POST",e=`${__classPrivateFieldGet(this,_Query_instances,"m",_Query_getCollectionPath).call(this)}?query`,{options:s}=__classPrivateFieldGet(this,_Query_builder,"f").get(),i=yield __classPrivateFieldGet(this,_Query_options,"f").httpclient.request({method:t,path:e,data:s});return utils_1.ResponseUtil.handleResponse(i)})}count(){return __awaiter(this,void 0,void 0,function*(){const t="POST",e=`${__classPrivateFieldGet(this,_Query_instances,"m",_Query_getCollectionPath).call(this)}?count`,{options:s}=__classPrivateFieldGet(this,_Query_builder,"f").count(),i=yield __classPrivateFieldGet(this,_Query_options,"f").httpclient.request({method:t,path:e,data:s});return{total:utils_1.ResponseUtil.handleResponse(i).count}})}}exports.Query=Query,_Query_options=new WeakMap,_Query_collectionName=new WeakMap,_Query_builder=new WeakMap,_Query_instances=new WeakSet,_Query_getCollectionPath=function(){return`/${__classPrivateFieldGet(this,_Query_options,"f").databaseName||"faas"}/${__classPrivateFieldGet(this,_Query_collectionName,"f")}`};
|
package/lib/Database/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Command } from '@alipay/faas-db-builder';
|
|
|
2
2
|
import { CreateDatabaseOptions } from '../types';
|
|
3
3
|
import { Collection } from './Collection';
|
|
4
4
|
export declare class Database {
|
|
5
|
-
#private;
|
|
6
5
|
readonly command: Command;
|
|
7
6
|
constructor(options: CreateDatabaseOptions);
|
|
8
7
|
collection(collectionName: string): Collection;
|
package/lib/Database/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Database=void 0;const Collection_1=require("./Collection");class DatabaseHttpclient{
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(i,t,a,e){function o(s){return s instanceof a?s:new a(function(r){r(s)})}return new(a||(a=Promise))(function(s,r){function h(n){try{c(e.next(n))}catch(l){r(l)}}function p(n){try{c(e.throw(n))}catch(l){r(l)}}function c(n){n.done?s(n.value):o(n.value).then(h,p)}c((e=e.apply(i,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(i,t,a,e,o){if(e==="m")throw new TypeError("Private method is not writable");if(e==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?i!==t||!o:!t.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e==="a"?o.call(i,a):o?o.value=a:t.set(i,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(i,t,a,e){if(a==="a"&&!e)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?i!==t||!e:!t.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return a==="m"?e:a==="a"?e.call(i):e?e.value:t.get(i)},_DatabaseHttpclient_httpclient,_Database_options;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Database=void 0;const Collection_1=require("./Collection");class DatabaseHttpclient{constructor(t){_DatabaseHttpclient_httpclient.set(this,void 0),__classPrivateFieldSet(this,_DatabaseHttpclient_httpclient,t,"f")}request({method:t,path:a,data:e,headers:o}){return __awaiter(this,void 0,void 0,function*(){return yield __classPrivateFieldGet(this,_DatabaseHttpclient_httpclient,"f").request({method:t,path:a,data:e,headers:Object.assign({"x-alipay-cloud-mode":"mongo","x-data-api-type":"mongo","x-expire-timestamp":`${Date.now()+6e4}`},o)})})}}_DatabaseHttpclient_httpclient=new WeakMap;class Database{constructor(t){_Database_options.set(this,void 0),__classPrivateFieldSet(this,_Database_options,Object.assign(Object.assign({},t),{httpclient:new DatabaseHttpclient(t.httpclient)}),"f")}collection(t){return new Collection_1.Collection(t,__classPrivateFieldGet(this,_Database_options,"f"))}}exports.Database=Database,_Database_options=new WeakMap;
|
package/lib/Storage.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export interface DeleteFileRawResult {
|
|
|
16
16
|
}>;
|
|
17
17
|
}
|
|
18
18
|
export declare class Storage<FileContent, DownloadFileResult extends FileUploaderResult> {
|
|
19
|
-
#private;
|
|
20
19
|
constructor(options: CreateStorageOptions<FileContent, DownloadFileResult>);
|
|
21
20
|
uploadFile(param: UploadFileParam<FileContent>): Promise<UploadFileResult>;
|
|
22
21
|
downloadFile(param: DownloadFileParam): Promise<DownloadFileResult>;
|
package/lib/Storage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(i,t,e,s){function r(n){return n instanceof e?n:new e(function(a){a(n)})}return new(e||(e=Promise))(function(n,a){function o(c){try{h(s.next(c))}catch(d){a(d)}}function l(c){try{h(s.throw(c))}catch(d){a(d)}}function h(c){c.done?n(c.value):r(c.value).then(o,l)}h((s=s.apply(i,t||[])).next())})},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(i,t,e,s,r){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?i!==t||!r:!t.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?r.call(i,e):r?r.value=e:t.set(i,e),e},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(i,t,e,s){if(e==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?i!==t||!s:!t.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?s:e==="a"?s.call(i):s?s.value:t.get(i)},_Storage_instances,_Storage_options,_Storage_getUploadPath,_Storage_getDownloadPath,_Storage_getBatchDeletePath,_Storage_getBatchDownloadPath,_Storage_checkCloudPath,_Storage_checkFileID,_Storage_formatFileID,_Storage_getCloudPathFromFileID,_Storage_request;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Storage=void 0;const error_1=require("./error"),utils_1=require("./utils");class Storage{constructor(t){_Storage_instances.add(this),_Storage_options.set(this,void 0),__classPrivateFieldSet(this,_Storage_options,t,"f")}uploadFile(t){return __awaiter(this,void 0,void 0,function*(){const e=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_checkCloudPath).call(this,t.cloudPath);if(e)throw error_1.FaasError.INVALID_PARAM_ERR("cloudPath",e);const s=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getUploadPath).call(this,t.cloudPath.trim()),r=yield __classPrivateFieldGet(this,_Storage_instances,"m",_Storage_request).call(this,{method:"GET",path:s}),n=utils_1.ResponseUtil.handleResponse(r),a=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_formatFileID).call(this,n.file_id),o=yield __classPrivateFieldGet(this,_Storage_options,"f").fileUploader.upload({fileID:a,uploadURL:n.upload_url,fileContent:t.fileContent});if(o.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",r.requestID);return{fileID:a,statusCode:o.statusCode}})}downloadFile(t){return __awaiter(this,void 0,void 0,function*(){const e=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_checkFileID).call(this,t.fileID);if(e)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",e);const s=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getCloudPathFromFileID).call(this,t.fileID),r=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getDownloadPath).call(this,s),n=yield __classPrivateFieldGet(this,_Storage_instances,"m",_Storage_request).call(this,{method:"GET",path:r}),a=utils_1.ResponseUtil.handleResponse(n),o=yield __classPrivateFieldGet(this,_Storage_options,"f").fileUploader.download({fileID:t.fileID,downloadURL:a.download_url});if(o.statusCode!==200)throw error_1.FaasError.STORAGE_ERR(-1,"\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25",n.requestID);return o})}deleteFile(t){return __awaiter(this,void 0,void 0,function*(){const e=Array.isArray(t)?t:t.fileList;if(!Array.isArray(e)||e.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");const s=[];for(const o of e){const l=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_checkFileID).call(this,o);if(l)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",l);const h=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getCloudPathFromFileID).call(this,o);s.push(h)}const r=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getBatchDeletePath).call(this),n=yield __classPrivateFieldGet(this,_Storage_instances,"m",_Storage_request).call(this,{method:"POST",path:r,data:{file_list:s}});return{fileList:utils_1.ResponseUtil.handleResponse(n).file_list.map(o=>({fileID:__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_formatFileID).call(this,o.file_id),status:o.status?0:-1,errMsg:o.status?"ok":o.result_message}))}})}getTempFileURL(t){return __awaiter(this,void 0,void 0,function*(){const e=Array.isArray(t)?t:t.fileList;if(!Array.isArray(e)||e.length===0)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4");if(e.length>50)throw error_1.FaasError.INVALID_PARAM_ERR("fileList","\u6700\u5927\u957F\u5EA6 50");const s=[];for(const o of e){const l=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_checkFileID).call(this,o);if(l)throw error_1.FaasError.INVALID_PARAM_ERR("fileID",l);const h=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getCloudPathFromFileID).call(this,o);s.push({file_id:h,expire:600})}const r=__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_getBatchDownloadPath).call(this),n=yield __classPrivateFieldGet(this,_Storage_instances,"m",_Storage_request).call(this,{method:"POST",path:r,data:{file_list:s}});return{fileList:utils_1.ResponseUtil.handleResponse(n).file_list.map(o=>({fileID:__classPrivateFieldGet(this,_Storage_instances,"m",_Storage_formatFileID).call(this,o.file_id),tempFileURL:o.download_url,status:o.status?0:-1,errMsg:o.status?"ok":o.result_message}))}})}}exports.Storage=Storage,_Storage_options=new WeakMap,_Storage_instances=new WeakSet,_Storage_getUploadPath=function(t){return`/${t}?upload_url`},_Storage_getDownloadPath=function(t){return`/${t}?download_url&expire=3600`},_Storage_getBatchDeletePath=function(){return"/?delete"},_Storage_getBatchDownloadPath=function(){return"/?download_url"},_Storage_checkCloudPath=function(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"},_Storage_checkFileID=function(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"},_Storage_formatFileID=function(t){return`cloud://${__classPrivateFieldGet(this,_Storage_options,"f").toEnvId}/${t.replace(/^\/+/,"")}`},_Storage_getCloudPathFromFileID=function(t){const e=t.trim().replace(/^cloud:\/\//,""),s=e.indexOf("/");if(s<=0)throw error_1.FaasError.INVALID_PARAM_ERR("fileID","\u4E0D\u5408\u6CD5");const r=e.substring(0,s),n=e.substring(s+1);return r!==__classPrivateFieldGet(this,_Storage_options,"f").toEnvId&&console.warn(`file ${t} does not belong to env ${__classPrivateFieldGet(this,_Storage_options,"f").toEnvId}`),n},_Storage_request=function({method:t,path:e,data:s,headers:r}){return __awaiter(this,void 0,void 0,function*(){return yield __classPrivateFieldGet(this,_Storage_options,"f").httpclient.request({method:t,path:e,data:s,headers:Object.assign({"x-alipay-cloud-mode":"oss","x-data-api-type":"oss","x-expire-timestamp":`${Date.now()+6e4}`},r)})})};
|
package/lib/callContainer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCallContainer=void 0;const utils_1=require("./utils"),createCallContainer=
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(r,c,n,i){function u(e){return e instanceof n?e:new n(function(o){o(e)})}return new(n||(n=Promise))(function(e,o){function s(t){try{a(i.next(t))}catch(l){o(l)}}function f(t){try{a(i.throw(t))}catch(l){o(l)}}function a(t){t.done?e(t.value):u(t.value).then(s,f)}a((i=i.apply(r,c||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCallContainer=void 0;const utils_1=require("./utils"),createCallContainer=r=>{const c=n=>__awaiter(void 0,void 0,void 0,function*(){throw new Error("not implemented in "+r.type+" with "+n)});return(0,utils_1.wrapCallback)(c)};exports.createCallContainer=createCallContainer;
|
package/lib/callFunction.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCallFunction=void 0;const error_1=require("./error"),utils_1=require("./utils"),createCallFunction=
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(s,u,i,e){function l(o){return o instanceof i?o:new i(function(a){a(o)})}return new(i||(i=Promise))(function(o,a){function n(t){try{r(e.next(t))}catch(d){a(d)}}function c(t){try{r(e.throw(t))}catch(d){a(d)}}function r(t){t.done?o(t.value):l(t.value).then(n,c)}r((e=e.apply(s,u||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createCallFunction=void 0;const error_1=require("./error"),utils_1=require("./utils"),createCallFunction=s=>{const{httpclient:u}=s,i=e=>__awaiter(void 0,void 0,void 0,function*(){if(!e.name)throw error_1.FaasError.INVALID_PARAM_ERR("name","\u7F3A\u5931");const l={"x-to-function-name":e.name,"x-alipay-cloud-mode":"function"},o="POST",a="/functions/invokeFunction",n=yield u.request({method:o,path:a,data:e.data,headers:l});if(n.status!==200){let c=-1,r="";const t=n.data;throw t&&({errCode:c,errMsg:r}=t,t.errDetail&&(r+=`\uFF0C\u8BE6\u60C5\uFF1A${t.errDetail}`)),error_1.FaasError.SERVER_ERR(c,r,n.requestID,n.status)}return{requestID:n.requestID,result:n.data}});return(0,utils_1.wrapCallback)(i)};exports.createCallFunction=createCallFunction;
|
package/lib/error.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FaasError=void 0;class FaasError extends Error{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FaasError=void 0;class FaasError extends Error{get errCode(){return this.error}get errMsg(){return this.message}constructor(e,t){super(t),this.error=e,this.errorMessage=t}static INVALID_PARAM_ERR(e,t){return new FaasError(60001,`\u65E0\u6548\u5165\u53C2\uFF0C\u53C2\u6570 ${e} ${t}`)}static NOT_FOUND_ERR(e){return new FaasError(70001,e)}static SERVER_ERR(e,t,r,s){const n=new FaasError(e,t);return n.requestID=r,n.httpStatus=s,n}static STORAGE_ERR(e,t,r){const s=new FaasError(e,t);return s.requestID=r,s}static NETWORK_ERR(e,t){const r=new FaasError(-1,e.toString());return r.requestID=t,r}}exports.FaasError=FaasError;
|
package/lib/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResponseUtil=exports.wrapCallback=void 0;const error_1=require("./error"),wrapCallback=
|
|
1
|
+
"use strict";var __rest=this&&this.__rest||function(o,e){var l={};for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&e.indexOf(t)<0&&(l[t]=o[t]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(o);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(o,t[r])&&(l[t[r]]=o[t[r]]);return l};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResponseUtil=exports.wrapCallback=void 0;const error_1=require("./error"),wrapCallback=o=>function(e){if(e?.complete||e?.success||e?.fail){const{complete:l,success:t,fail:r}=e,s=__rest(e,["complete","success","fail"]);o(s).then(n=>(t?.(n),n),n=>(r?.(n),n)).then(n=>{l?.(n)});return}return o(e)};exports.wrapCallback=wrapCallback;class ResponseUtil{static handleResponse(e){if(e.status!==200){const{code:l,message:t}=e.data||{code:-1,message:"\u672A\u77E5\u5F02\u5E38"};throw error_1.FaasError.SERVER_ERR(l,t,e.requestID,e.status)}return e.data.data}}exports.ResponseUtil=ResponseUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alipay/faas-common-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10-alpha.1",
|
|
4
4
|
"description": "云函数服务通用 SDK",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
10
|
"lint": "eslint src test --cache --fix --ext ts",
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "tspc -p ./tsconfig.json && minimize-js lib",
|
|
12
|
+
"dev": "tspc -p ./tsconfig.json",
|
|
12
13
|
"clean": "tsc --build --clean",
|
|
13
14
|
"test": "egg-bin test",
|
|
14
15
|
"cov": "egg-bin cov",
|
|
@@ -22,13 +23,14 @@
|
|
|
22
23
|
"eslint-config-egg": "^12.1.0",
|
|
23
24
|
"minimize-js": "^1.3.1",
|
|
24
25
|
"mm": "^3.2.1",
|
|
26
|
+
"ts-patch": "^3.0.1",
|
|
25
27
|
"typescript": "^5.0.4"
|
|
26
28
|
},
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@alipay/faas-db-builder": "^1.1.
|
|
30
|
+
"@alipay/faas-db-builder": "^1.1.10-alpha.1"
|
|
29
31
|
},
|
|
30
32
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
33
|
+
"node": ">= 14.0.0"
|
|
32
34
|
},
|
|
33
35
|
"publishConfig": {
|
|
34
36
|
"access": "public"
|