"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Transaction=void 0;const faas_common_sdk_1=require("@alipay/faas-common-sdk"),Collection_1=require("./Collection");class TransactionHttpclient{#t;#s;constructor(t,s){this.#t=t,this.#s=s}request(t){return this.#t.request({method:t.method,path:t.path,data:t.data,headers:{...t.headers,"x-transaction-id":this.#s}})}}class Transaction{static COMMIT_FLAG=1;static ROLLBACK_FLAG=2;#t;#s;#e=0;reason;constructor(t,s){this.#s=t,this.#t=s}async#a(){const t="POST",s="/?startTransaction",e=await this.#t.request({method:t,path:s}),a=faas_common_sdk_1.ResponseUtil.handleResponse(e);this.#t=new TransactionHttpclient(this.#t,a.transaction_id)}#n(t){this.#e=_a.ROLLBACK_FLAG,this.reason=t}#i(){this.#e=_a.COMMIT_FLAG}async commit(){const t="POST",s="/?commitTransaction",e=await this.#t.request({method:t,path:s});faas_common_sdk_1.ResponseUtil.handleResponse(e),this.#i()}async rollback(t){const s="POST",e="/?rollbackTransaction",a=await this.#t.request({method:s,path:e});faas_common_sdk_1.ResponseUtil.handleResponse(a),this.#n(t)}collection(t){return new Collection_1.Collection(this.#s,t,this.#t)}isProcessing(){return!this.#e}isRollback(){return this.#e===_a.ROLLBACK_FLAG}isCommitted(){return this.#e===_a.COMMIT_FLAG}static async create(t,s){const e=new _a(t,s);return await e.#a(),e}}exports.Transaction=Transaction,_a=Transaction;