@nhost/hasura-storage-js
Advanced tools
Comparing version 2.2.3 to 2.2.4
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("fetch-ponyfill"),F=require("form-data"),d=require("xstate"),{fetch:R}=S(),P=async(t,e,{accessToken:r,name:s,fileId:a,bucketId:o,adminSecret:n,onUploadProgress:l,headers:u={}}={})=>{var y;const p={...u};o&&e.append("bucket-id",o),n&&(p["x-hasura-admin-secret"]=n),r&&(p.Authorization=`Bearer ${r}`);const O=`${t}/files`;if(typeof XMLHttpRequest=="undefined")try{const c=await R(O,{method:"POST",headers:p,body:e}),i=await c.json();return c.ok?{fileMetadata:i,error:null}:{error:{status:c.status,message:((y=i==null?void 0:i.error)==null?void 0:y.message)||c.statusText,error:c.statusText},fileMetadata:null}}catch(c){return{error:{status:0,message:c.message,error:c.message},fileMetadata:null}}return new Promise(c=>{let i=new XMLHttpRequest;i.responseType="json",i.onload=()=>{var g,f,D,U,T;return i.status<200||i.status>=300?c({fileMetadata:null,error:{error:(f=(g=i.response)==null?void 0:g.error)!=null?f:i.response,message:(T=(U=(D=i.response)==null?void 0:D.error)==null?void 0:U.message)!=null?T:i.response,status:i.status}}):c({fileMetadata:i.response,error:null})},i.onerror=()=>c({fileMetadata:null,error:{error:i.statusText,message:i.statusText,status:i.status}}),l&&i.upload.addEventListener("progress",l,!1),i.open("POST",O,!0),Object.entries(p).forEach(([g,f])=>{i.setRequestHeader(g,f)}),i.send(e)})},{fetch:L}=S();class _{constructor({url:e}){this.url=e}async uploadFormData({formData:e,headers:r,bucketId:s}){const{error:a,fileMetadata:o}=await P(this.url,e,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:s,headers:r});return a?{fileMetadata:null,error:a}:o&&!("processedFiles"in o)?{fileMetadata:{processedFiles:[o]},error:null}:{fileMetadata:o,error:null}}async uploadFile({file:e,bucketId:r,id:s,name:a}){const o=new F;o.append("file[]",e),o.append("metadata[]",JSON.stringify({id:s,name:a}));const{error:n,fileMetadata:l}=await P(this.url,o,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:r,fileId:s,name:a});return n?{fileMetadata:null,error:n}:l&&"processedFiles"in l?{fileMetadata:l.processedFiles[0],error:null}:{fileMetadata:l,error:null}}async getPresignedUrl(e){try{const{fileId:r}=e,s=await L(`${this.url}/files/${r}/presignedurl`,{method:"GET",headers:this.generateAuthHeaders()});if(!s.ok)throw new Error(await s.text());return{presignedUrl:await s.json(),error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e,s=await L(`${this.url}/files/${r}`,{method:"DELETE",headers:this.generateAuthHeaders()});if(!s.ok)throw new Error(await s.text());return{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateAuthHeaders(){if(!(!this.adminSecret&&!this.accessToken))return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}function E(t,e){if(!e||Object.keys(e).length===0)return t;const r=new URL(t),s=Object.entries(e).reduce((a,[o,n])=>({...a,[o.charAt(0)]:n}),{});return Object.entries(s).forEach(([a,o])=>{o&&r.searchParams.set(a,o)}),r.toString()}class w{constructor({url:e,adminSecret:r}){this.url=e,this.api=new _({url:e}),this.setAdminSecret(r)}async upload(e){return"file"in e?this.api.uploadFile(e):this.api.uploadFormData(e)}getPublicUrl(e){const{fileId:r,...s}=e;return E(`${this.url}/files/${r}`,s)}async getPresignedUrl(e){const{fileId:r,...s}=e,{presignedUrl:a,error:o}=await this.api.getPresignedUrl(e);if(o)return{presignedUrl:null,error:o};if(!a)return{presignedUrl:null,error:new Error("Invalid file id")};const n=E(a.url,s);return{presignedUrl:{...a,url:n},error:null}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}const m={progress:null,loaded:0,error:null,bucketId:void 0,file:void 0,id:void 0},I=()=>d.createMachine({predictableActionArguments:!0,schema:{context:{},events:{}},tsTypes:{},context:{...m},initial:"idle",on:{DESTROY:{actions:"sendDestroy",target:"stopped"}},states:{idle:{on:{ADD:{actions:"addFile"},UPLOAD:{cond:"hasFile",target:"uploading"}}},uploading:{entry:"resetProgress",on:{UPLOAD_PROGRESS:{actions:["incrementProgress","sendProgress"]},UPLOAD_DONE:"uploaded",UPLOAD_ERROR:"error",CANCEL:"idle"},invoke:{src:"uploadFile"}},uploaded:{entry:["setFileMetadata","sendDone"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},error:{entry:["setError","sendError"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},stopped:{type:"final"}}},{guards:{hasFile:(t,e)=>!!t.file||!!e.file},actions:{incrementProgress:d.assign({loaded:(t,{loaded:e})=>e,progress:(t,{progress:e})=>e}),setFileMetadata:d.assign({id:(t,{id:e})=>e,bucketId:(t,{bucketId:e})=>e,progress:t=>100}),setError:d.assign({error:(t,{error:e})=>e}),sendProgress:()=>{},sendError:()=>{},sendDestroy:()=>{},sendDone:()=>{},resetProgress:d.assign({progress:t=>null,loaded:t=>0}),resetContext:d.assign(t=>m),addFile:d.assign({file:(t,{file:e})=>e,bucketId:(t,{bucketId:e})=>e,id:(t,{id:e})=>e})},services:{uploadFile:(t,e)=>r=>{const s=e.file||t.file,a=new F;a.append("file[]",s);let o=0;return P(e.url,a,{fileId:e.id||t.id,bucketId:e.bucketId||t.bucketId,accessToken:e.accessToken,adminSecret:e.adminSecret,name:e.name||s.name,onUploadProgress:n=>{const l=n.total?Math.round(n.loaded*s.size/n.total):0,u=l-o;o=l,r({type:"UPLOAD_PROGRESS",progress:n.total?Math.round(l*100/n.total):0,loaded:l,additions:u})}}).then(({fileMetadata:n,error:l})=>{if(l&&r({type:"UPLOAD_ERROR",error:l}),n&&!("processedFiles"in n)){const{id:u,bucketId:p}=n;r({type:"UPLOAD_DONE",id:u,bucketId:p})}if(n&&"processedFiles"in n){const{id:u,bucketId:p}=n.processedFiles[0];r({type:"UPLOAD_DONE",id:u,bucketId:p})}}),()=>{}}}}),{pure:A,sendParent:h}=d.actions,M=()=>d.createMachine({id:"files-list",schema:{context:{},events:{}},tsTypes:{},predictableActionArguments:!0,context:{progress:null,files:[],loaded:0,total:0},initial:"idle",on:{UPLOAD:{cond:"hasFileToDownload",actions:"addItem",target:"uploading"},ADD:{actions:"addItem"},REMOVE:{actions:"removeItem"}},states:{idle:{entry:["resetProgress","resetLoaded","resetTotal"],on:{CLEAR:{actions:"clearList",target:"idle"}}},uploading:{entry:["upload","startProgress","resetLoaded","resetTotal"],on:{UPLOAD_PROGRESS:{actions:["incrementProgress"]},UPLOAD_DONE:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],UPLOAD_ERROR:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],CANCEL:{actions:"cancel",target:"idle"}}},uploaded:{entry:"setUploaded",on:{CLEAR:{actions:"clearList",target:"idle"}}},error:{on:{CLEAR:{actions:"clearList",target:"idle"}}}}},{guards:{hasFileToDownload:(t,e)=>t.files.some(r=>r.getSnapshot().matches("idle"))||!!e.files,isAllUploaded:t=>t.files.every(e=>{var r;return(r=e.getSnapshot())==null?void 0:r.matches("uploaded")}),isAllUploadedOrError:t=>t.files.every(e=>{const r=e.getSnapshot();return(r==null?void 0:r.matches("error"))||(r==null?void 0:r.matches("uploaded"))})},actions:{incrementProgress:d.assign((t,e)=>{const r=t.loaded+e.additions,s=Math.round(r*100/t.total);return{...t,loaded:r,progress:s}}),setUploaded:d.assign({progress:t=>100,loaded:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>e.matches("uploaded")).reduce((e,r)=>{var s;return e+((s=r.context.file)==null?void 0:s.size)},0)}),resetTotal:d.assign({total:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>!e.matches("uploaded")).reduce((e,r)=>{var s;return e+((s=r.context.file)==null?void 0:s.size)},0)}),resetLoaded:d.assign({loaded:t=>0}),startProgress:d.assign({progress:t=>0}),resetProgress:d.assign({progress:t=>null}),addItem:d.assign((t,{files:e,bucketId:r})=>{const s=e?Array.isArray(e)?e:"item"in e?Array.from(e):[e]:[],a=t.total+s.reduce((n,l)=>n+l.size,0),o=Math.round(t.loaded*100/a);return{files:[...t.files,...s.map(n=>d.spawn(I().withConfig({actions:{sendProgress:h((l,{additions:u})=>({type:"UPLOAD_PROGRESS",additions:u})),sendDone:h("UPLOAD_DONE"),sendError:h("UPLOAD_ERROR"),sendDestroy:h("REMOVE")}}).withContext({...m,file:n,bucketId:r}),{sync:!0}))],total:a,loaded:t.loaded,progress:o}}),removeItem:d.assign({files:t=>t.files.filter(e=>{var s,a;const r=(s=e.getSnapshot())==null?void 0:s.matches("stopped");return r&&((a=e.stop)==null||a.call(e)),!r})}),clearList:A(t=>t.files.map(e=>d.send({type:"DESTROY"},{to:e.id}))),upload:A((t,e)=>t.files.map(r=>d.send(e,{to:r.id}))),cancel:A(t=>t.files.map(e=>d.send({type:"CANCEL"},{to:e.id})))}}),k=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t}),e.subscribe(s=>{var a;s.matches("error")?r({error:s.context.error,isError:!0,isUploaded:!1}):s.matches("uploaded")&&r({error:null,isError:!1,isUploaded:!0,id:s.context.id,bucketId:s.context.id,name:(a=s.context.file)==null?void 0:a.name})})}),x=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t,files:t.files}),e.onTransition(s=>{s.matches("error")?r({errors:s.context.files.filter(a=>{var o;return(o=a.getSnapshot())==null?void 0:o.context.error}),isError:!0,files:[]}):s.matches("uploaded")&&r({errors:[],isError:!1,files:s.context.files})})});exports.HasuraStorageApi=_;exports.HasuraStorageClient=w;exports.INITIAL_FILE_CONTEXT=m;exports.appendImageTransformationParameters=E;exports.createFileUploadMachine=I;exports.createMultipleFilesUploadMachine=M;exports.uploadFilePromise=k;exports.uploadMultipleFilesPromise=x; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("fetch-ponyfill"),F=require("form-data"),d=require("xstate");let _=globalThis.fetch;typeof EdgeRuntime!="string"&&(_=S().fetch);const P=async(t,e,{accessToken:r,name:s,fileId:a,bucketId:o,adminSecret:i,onUploadProgress:l,headers:u={}}={})=>{var y;const p={...u};o&&e.append("bucket-id",o),i&&(p["x-hasura-admin-secret"]=i),r&&(p.Authorization=`Bearer ${r}`);const O=`${t}/files`;if(typeof XMLHttpRequest=="undefined")try{const c=await _(O,{method:"POST",headers:p,body:e}),n=await c.json();return c.ok?{fileMetadata:n,error:null}:{error:{status:c.status,message:((y=n==null?void 0:n.error)==null?void 0:y.message)||c.statusText,error:c.statusText},fileMetadata:null}}catch(c){return{error:{status:0,message:c.message,error:c.message},fileMetadata:null}}return new Promise(c=>{let n=new XMLHttpRequest;n.responseType="json",n.onload=()=>{var g,f,D,U,T;return n.status<200||n.status>=300?c({fileMetadata:null,error:{error:(f=(g=n.response)==null?void 0:g.error)!=null?f:n.response,message:(T=(U=(D=n.response)==null?void 0:D.error)==null?void 0:U.message)!=null?T:n.response,status:n.status}}):c({fileMetadata:n.response,error:null})},n.onerror=()=>c({fileMetadata:null,error:{error:n.statusText,message:n.statusText,status:n.status}}),l&&n.upload.addEventListener("progress",l,!1),n.open("POST",O,!0),Object.entries(p).forEach(([g,f])=>{n.setRequestHeader(g,f)}),n.send(e)})},{fetch:L}=S();class R{constructor({url:e}){this.url=e}async uploadFormData({formData:e,headers:r,bucketId:s}){const{error:a,fileMetadata:o}=await P(this.url,e,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:s,headers:r});return a?{fileMetadata:null,error:a}:o&&!("processedFiles"in o)?{fileMetadata:{processedFiles:[o]},error:null}:{fileMetadata:o,error:null}}async uploadFile({file:e,bucketId:r,id:s,name:a}){const o=new F;o.append("file[]",e),o.append("metadata[]",JSON.stringify({id:s,name:a}));const{error:i,fileMetadata:l}=await P(this.url,o,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:r,fileId:s,name:a});return i?{fileMetadata:null,error:i}:l&&"processedFiles"in l?{fileMetadata:l.processedFiles[0],error:null}:{fileMetadata:l,error:null}}async getPresignedUrl(e){try{const{fileId:r}=e,s=await L(`${this.url}/files/${r}/presignedurl`,{method:"GET",headers:this.generateAuthHeaders()});if(!s.ok)throw new Error(await s.text());return{presignedUrl:await s.json(),error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e,s=await L(`${this.url}/files/${r}`,{method:"DELETE",headers:this.generateAuthHeaders()});if(!s.ok)throw new Error(await s.text());return{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateAuthHeaders(){if(!(!this.adminSecret&&!this.accessToken))return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}function E(t,e){if(!e||Object.keys(e).length===0)return t;const r=new URL(t),s=Object.entries(e).reduce((a,[o,i])=>({...a,[o.charAt(0)]:i}),{});return Object.entries(s).forEach(([a,o])=>{o&&r.searchParams.set(a,o)}),r.toString()}class w{constructor({url:e,adminSecret:r}){this.url=e,this.api=new R({url:e}),this.setAdminSecret(r)}async upload(e){return"file"in e?this.api.uploadFile(e):this.api.uploadFormData(e)}getPublicUrl(e){const{fileId:r,...s}=e;return E(`${this.url}/files/${r}`,s)}async getPresignedUrl(e){const{fileId:r,...s}=e,{presignedUrl:a,error:o}=await this.api.getPresignedUrl(e);if(o)return{presignedUrl:null,error:o};if(!a)return{presignedUrl:null,error:new Error("Invalid file id")};const i=E(a.url,s);return{presignedUrl:{...a,url:i},error:null}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}const m={progress:null,loaded:0,error:null,bucketId:void 0,file:void 0,id:void 0},I=()=>d.createMachine({predictableActionArguments:!0,schema:{context:{},events:{}},tsTypes:{},context:{...m},initial:"idle",on:{DESTROY:{actions:"sendDestroy",target:"stopped"}},states:{idle:{on:{ADD:{actions:"addFile"},UPLOAD:{cond:"hasFile",target:"uploading"}}},uploading:{entry:"resetProgress",on:{UPLOAD_PROGRESS:{actions:["incrementProgress","sendProgress"]},UPLOAD_DONE:"uploaded",UPLOAD_ERROR:"error",CANCEL:"idle"},invoke:{src:"uploadFile"}},uploaded:{entry:["setFileMetadata","sendDone"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},error:{entry:["setError","sendError"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},stopped:{type:"final"}}},{guards:{hasFile:(t,e)=>!!t.file||!!e.file},actions:{incrementProgress:d.assign({loaded:(t,{loaded:e})=>e,progress:(t,{progress:e})=>e}),setFileMetadata:d.assign({id:(t,{id:e})=>e,bucketId:(t,{bucketId:e})=>e,progress:t=>100}),setError:d.assign({error:(t,{error:e})=>e}),sendProgress:()=>{},sendError:()=>{},sendDestroy:()=>{},sendDone:()=>{},resetProgress:d.assign({progress:t=>null,loaded:t=>0}),resetContext:d.assign(t=>m),addFile:d.assign({file:(t,{file:e})=>e,bucketId:(t,{bucketId:e})=>e,id:(t,{id:e})=>e})},services:{uploadFile:(t,e)=>r=>{const s=e.file||t.file,a=new F;a.append("file[]",s);let o=0;return P(e.url,a,{fileId:e.id||t.id,bucketId:e.bucketId||t.bucketId,accessToken:e.accessToken,adminSecret:e.adminSecret,name:e.name||s.name,onUploadProgress:i=>{const l=i.total?Math.round(i.loaded*s.size/i.total):0,u=l-o;o=l,r({type:"UPLOAD_PROGRESS",progress:i.total?Math.round(l*100/i.total):0,loaded:l,additions:u})}}).then(({fileMetadata:i,error:l})=>{if(l&&r({type:"UPLOAD_ERROR",error:l}),i&&!("processedFiles"in i)){const{id:u,bucketId:p}=i;r({type:"UPLOAD_DONE",id:u,bucketId:p})}if(i&&"processedFiles"in i){const{id:u,bucketId:p}=i.processedFiles[0];r({type:"UPLOAD_DONE",id:u,bucketId:p})}}),()=>{}}}}),{pure:A,sendParent:h}=d.actions,M=()=>d.createMachine({id:"files-list",schema:{context:{},events:{}},tsTypes:{},predictableActionArguments:!0,context:{progress:null,files:[],loaded:0,total:0},initial:"idle",on:{UPLOAD:{cond:"hasFileToDownload",actions:"addItem",target:"uploading"},ADD:{actions:"addItem"},REMOVE:{actions:"removeItem"}},states:{idle:{entry:["resetProgress","resetLoaded","resetTotal"],on:{CLEAR:{actions:"clearList",target:"idle"}}},uploading:{entry:["upload","startProgress","resetLoaded","resetTotal"],on:{UPLOAD_PROGRESS:{actions:["incrementProgress"]},UPLOAD_DONE:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],UPLOAD_ERROR:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],CANCEL:{actions:"cancel",target:"idle"}}},uploaded:{entry:"setUploaded",on:{CLEAR:{actions:"clearList",target:"idle"}}},error:{on:{CLEAR:{actions:"clearList",target:"idle"}}}}},{guards:{hasFileToDownload:(t,e)=>t.files.some(r=>r.getSnapshot().matches("idle"))||!!e.files,isAllUploaded:t=>t.files.every(e=>{var r;return(r=e.getSnapshot())==null?void 0:r.matches("uploaded")}),isAllUploadedOrError:t=>t.files.every(e=>{const r=e.getSnapshot();return(r==null?void 0:r.matches("error"))||(r==null?void 0:r.matches("uploaded"))})},actions:{incrementProgress:d.assign((t,e)=>{const r=t.loaded+e.additions,s=Math.round(r*100/t.total);return{...t,loaded:r,progress:s}}),setUploaded:d.assign({progress:t=>100,loaded:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>e.matches("uploaded")).reduce((e,r)=>{var s;return e+((s=r.context.file)==null?void 0:s.size)},0)}),resetTotal:d.assign({total:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>!e.matches("uploaded")).reduce((e,r)=>{var s;return e+((s=r.context.file)==null?void 0:s.size)},0)}),resetLoaded:d.assign({loaded:t=>0}),startProgress:d.assign({progress:t=>0}),resetProgress:d.assign({progress:t=>null}),addItem:d.assign((t,{files:e,bucketId:r})=>{const s=e?Array.isArray(e)?e:"item"in e?Array.from(e):[e]:[],a=t.total+s.reduce((i,l)=>i+l.size,0),o=Math.round(t.loaded*100/a);return{files:[...t.files,...s.map(i=>d.spawn(I().withConfig({actions:{sendProgress:h((l,{additions:u})=>({type:"UPLOAD_PROGRESS",additions:u})),sendDone:h("UPLOAD_DONE"),sendError:h("UPLOAD_ERROR"),sendDestroy:h("REMOVE")}}).withContext({...m,file:i,bucketId:r}),{sync:!0}))],total:a,loaded:t.loaded,progress:o}}),removeItem:d.assign({files:t=>t.files.filter(e=>{var s,a;const r=(s=e.getSnapshot())==null?void 0:s.matches("stopped");return r&&((a=e.stop)==null||a.call(e)),!r})}),clearList:A(t=>t.files.map(e=>d.send({type:"DESTROY"},{to:e.id}))),upload:A((t,e)=>t.files.map(r=>d.send(e,{to:r.id}))),cancel:A(t=>t.files.map(e=>d.send({type:"CANCEL"},{to:e.id})))}}),k=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t}),e.subscribe(s=>{var a;s.matches("error")?r({error:s.context.error,isError:!0,isUploaded:!1}):s.matches("uploaded")&&r({error:null,isError:!1,isUploaded:!0,id:s.context.id,bucketId:s.context.id,name:(a=s.context.file)==null?void 0:a.name})})}),b=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t,files:t.files}),e.onTransition(s=>{s.matches("error")?r({errors:s.context.files.filter(a=>{var o;return(o=a.getSnapshot())==null?void 0:o.context.error}),isError:!0,files:[]}):s.matches("uploaded")&&r({errors:[],isError:!1,files:s.context.files})})});exports.HasuraStorageApi=R;exports.HasuraStorageClient=w;exports.INITIAL_FILE_CONTEXT=m;exports.appendImageTransformationParameters=E;exports.createFileUploadMachine=I;exports.createMultipleFilesUploadMachine=M;exports.uploadFilePromise=k;exports.uploadMultipleFilesPromise=b; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,5 +0,7 @@ | ||
import _ from "fetch-ponyfill"; | ||
import R from "form-data"; | ||
import { createMachine as w, assign as l, spawn as F, send as m, actions as I } from "xstate"; | ||
const { fetch: M } = _(), P = async (t, e, { | ||
import R from "fetch-ponyfill"; | ||
import _ from "form-data"; | ||
import { createMachine as w, assign as l, spawn as I, send as m, actions as M } from "xstate"; | ||
let F = globalThis.fetch; | ||
typeof EdgeRuntime != "string" && (F = R().fetch); | ||
const P = async (t, e, { | ||
accessToken: r, | ||
@@ -21,3 +23,3 @@ name: s, | ||
try { | ||
const c = await M(O, { | ||
const c = await F(O, { | ||
method: "POST", | ||
@@ -60,3 +62,3 @@ headers: p, | ||
}); | ||
}, { fetch: T } = _(); | ||
}, { fetch: T } = R(); | ||
class k { | ||
@@ -90,3 +92,3 @@ constructor({ url: e }) { | ||
}) { | ||
const a = new R(); | ||
const a = new _(); | ||
a.append("file[]", e), a.append("metadata[]", JSON.stringify({ id: s, name: o })); | ||
@@ -360,3 +362,3 @@ const { error: n, fileMetadata: d } = await P(this.url, a, { | ||
uploadFile: (t, e) => (r) => { | ||
const s = e.file || t.file, o = new R(); | ||
const s = e.file || t.file, o = new _(); | ||
o.append("file[]", s); | ||
@@ -393,3 +395,3 @@ let a = 0; | ||
} | ||
), { pure: A, sendParent: g } = I, j = () => w( | ||
), { pure: A, sendParent: g } = M, j = () => w( | ||
{ | ||
@@ -489,3 +491,3 @@ id: "files-list", | ||
...s.map( | ||
(n) => F( | ||
(n) => I( | ||
x().withConfig({ | ||
@@ -492,0 +494,0 @@ actions: { |
{ | ||
"name": "@nhost/hasura-storage-js", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "Hasura-storage client", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
(function(X,ne){typeof exports=="object"&&typeof module!="undefined"?ne(exports):typeof define=="function"&&define.amd?define(["exports"],ne):(X=typeof globalThis!="undefined"?globalThis:X||self,ne(X["@nhost/hasura-storage-js"]={}))})(this,function(X){"use strict";var ne=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function rt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ce={exports:{}};(function(t,e){(function(r){function n(a){var i=a&&a.Promise||r.Promise,o=a&&a.XMLHttpRequest||r.XMLHttpRequest;return function(){var u=Object.create(r,{fetch:{value:void 0,writable:!0}});return function(f,l){l(e)}(this,function(f){var l=typeof u!="undefined"&&u||typeof self!="undefined"&&self||typeof l!="undefined"&&l,v={searchParams:"URLSearchParams"in l,iterable:"Symbol"in l&&"iterator"in Symbol,blob:"FileReader"in l&&"Blob"in l&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in l,arrayBuffer:"ArrayBuffer"in l};function w(s){return s&&DataView.prototype.isPrototypeOf(s)}if(v.arrayBuffer)var h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],d=ArrayBuffer.isView||function(s){return s&&h.indexOf(Object.prototype.toString.call(s))>-1};function y(s){if(typeof s!="string"&&(s=String(s)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(s)||s==="")throw new TypeError("Invalid character in header field name");return s.toLowerCase()}function m(s){return typeof s!="string"&&(s=String(s)),s}function E(s){var c={next:function(){var A=s.shift();return{done:A===void 0,value:A}}};return v.iterable&&(c[Symbol.iterator]=function(){return c}),c}function S(s){this.map={},s instanceof S?s.forEach(function(c,A){this.append(A,c)},this):Array.isArray(s)?s.forEach(function(c){this.append(c[0],c[1])},this):s&&Object.getOwnPropertyNames(s).forEach(function(c){this.append(c,s[c])},this)}S.prototype.append=function(s,c){s=y(s),c=m(c);var A=this.map[s];this.map[s]=A?A+", "+c:c},S.prototype.delete=function(s){delete this.map[y(s)]},S.prototype.get=function(s){return s=y(s),this.has(s)?this.map[s]:null},S.prototype.has=function(s){return this.map.hasOwnProperty(y(s))},S.prototype.set=function(s,c){this.map[y(s)]=m(c)},S.prototype.forEach=function(s,c){for(var A in this.map)this.map.hasOwnProperty(A)&&s.call(c,this.map[A],A,this)},S.prototype.keys=function(){var s=[];return this.forEach(function(c,A){s.push(A)}),E(s)},S.prototype.values=function(){var s=[];return this.forEach(function(c){s.push(c)}),E(s)},S.prototype.entries=function(){var s=[];return this.forEach(function(c,A){s.push([A,c])}),E(s)},v.iterable&&(S.prototype[Symbol.iterator]=S.prototype.entries);function g(s){if(s.bodyUsed)return i.reject(new TypeError("Already read"));s.bodyUsed=!0}function x(s){return new i(function(c,A){s.onload=function(){c(s.result)},s.onerror=function(){A(s.error)}})}function F(s){var c=new FileReader,A=x(c);return c.readAsArrayBuffer(s),A}function I(s){var c=new FileReader,A=x(c);return c.readAsText(s),A}function $(s){for(var c=new Uint8Array(s),A=new Array(c.length),U=0;U<c.length;U++)A[U]=String.fromCharCode(c[U]);return A.join("")}function k(s){if(s.slice)return s.slice(0);var c=new Uint8Array(s.byteLength);return c.set(new Uint8Array(s)),c.buffer}function B(){return this.bodyUsed=!1,this._initBody=function(s){this.bodyUsed=this.bodyUsed,this._bodyInit=s,s?typeof s=="string"?this._bodyText=s:v.blob&&Blob.prototype.isPrototypeOf(s)?this._bodyBlob=s:v.formData&&FormData.prototype.isPrototypeOf(s)?this._bodyFormData=s:v.searchParams&&URLSearchParams.prototype.isPrototypeOf(s)?this._bodyText=s.toString():v.arrayBuffer&&v.blob&&w(s)?(this._bodyArrayBuffer=k(s.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):v.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(s)||d(s))?this._bodyArrayBuffer=k(s):this._bodyText=s=Object.prototype.toString.call(s):this._bodyText="",this.headers.get("content-type")||(typeof s=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):v.searchParams&&URLSearchParams.prototype.isPrototypeOf(s)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},v.blob&&(this.blob=function(){var s=g(this);if(s)return s;if(this._bodyBlob)return i.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return i.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return i.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var s=g(this);return s||(ArrayBuffer.isView(this._bodyArrayBuffer)?i.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):i.resolve(this._bodyArrayBuffer))}else return this.blob().then(F)}),this.text=function(){var s=g(this);if(s)return s;if(this._bodyBlob)return I(this._bodyBlob);if(this._bodyArrayBuffer)return i.resolve($(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return i.resolve(this._bodyText)},v.formData&&(this.formData=function(){return this.text().then(J)}),this.json=function(){return this.text().then(JSON.parse)},this}var z=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(s){var c=s.toUpperCase();return z.indexOf(c)>-1?c:s}function D(s,c){if(!(this instanceof D))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');c=c||{};var A=c.body;if(s instanceof D){if(s.bodyUsed)throw new TypeError("Already read");this.url=s.url,this.credentials=s.credentials,c.headers||(this.headers=new S(s.headers)),this.method=s.method,this.mode=s.mode,this.signal=s.signal,!A&&s._bodyInit!=null&&(A=s._bodyInit,s.bodyUsed=!0)}else this.url=String(s);if(this.credentials=c.credentials||this.credentials||"same-origin",(c.headers||!this.headers)&&(this.headers=new S(c.headers)),this.method=b(c.method||this.method||"GET"),this.mode=c.mode||this.mode||null,this.signal=c.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&A)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(A),(this.method==="GET"||this.method==="HEAD")&&(c.cache==="no-store"||c.cache==="no-cache")){var U=/([?&])_=[^&]*/;if(U.test(this.url))this.url=this.url.replace(U,"$1_="+new Date().getTime());else{var T=/\?/;this.url+=(T.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}D.prototype.clone=function(){return new D(this,{body:this._bodyInit})};function J(s){var c=new FormData;return s.trim().split("&").forEach(function(A){if(A){var U=A.split("="),T=U.shift().replace(/\+/g," "),j=U.join("=").replace(/\+/g," ");c.append(decodeURIComponent(T),decodeURIComponent(j))}}),c}function Y(s){var c=new S,A=s.replace(/\r?\n[\t ]+/g," ");return A.split("\r").map(function(U){return U.indexOf(` | ||
`)===0?U.substr(1,U.length):U}).forEach(function(U){var T=U.split(":"),j=T.shift().trim();if(j){var ce=T.join(":").trim();c.append(j,ce)}}),c}B.call(D.prototype);function C(s,c){if(!(this instanceof C))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');c||(c={}),this.type="default",this.status=c.status===void 0?200:c.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in c?c.statusText:"",this.headers=new S(c.headers),this.url=c.url||"",this._initBody(s)}B.call(C.prototype),C.prototype.clone=function(){return new C(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new S(this.headers),url:this.url})},C.error=function(){var s=new C(null,{status:0,statusText:""});return s.type="error",s};var re=[301,302,303,307,308];C.redirect=function(s,c){if(re.indexOf(c)===-1)throw new RangeError("Invalid status code");return new C(null,{status:c,headers:{location:s}})},f.DOMException=l.DOMException;try{new f.DOMException}catch{f.DOMException=function(c,A){this.message=c,this.name=A;var U=Error(c);this.stack=U.stack},f.DOMException.prototype=Object.create(Error.prototype),f.DOMException.prototype.constructor=f.DOMException}function Ee(s,c){return new i(function(A,U){var T=new D(s,c);if(T.signal&&T.signal.aborted)return U(new f.DOMException("Aborted","AbortError"));var j=new o;function ce(){j.abort()}j.onload=function(){var H={status:j.status,statusText:j.statusText,headers:Y(j.getAllResponseHeaders()||"")};H.url="responseURL"in j?j.responseURL:H.headers.get("X-Request-URL");var Be="response"in j?j.response:j.responseText;setTimeout(function(){A(new C(Be,H))},0)},j.onerror=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},j.ontimeout=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},j.onabort=function(){setTimeout(function(){U(new f.DOMException("Aborted","AbortError"))},0)};function q(H){try{return H===""&&l.location.href?l.location.href:H}catch{return H}}j.open(T.method,q(T.url),!0),T.credentials==="include"?j.withCredentials=!0:T.credentials==="omit"&&(j.withCredentials=!1),"responseType"in j&&(v.blob?j.responseType="blob":v.arrayBuffer&&T.headers.get("Content-Type")&&T.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(j.responseType="arraybuffer")),c&&typeof c.headers=="object"&&!(c.headers instanceof S)?Object.getOwnPropertyNames(c.headers).forEach(function(H){j.setRequestHeader(H,m(c.headers[H]))}):T.headers.forEach(function(H,Be){j.setRequestHeader(Be,H)}),T.signal&&(T.signal.addEventListener("abort",ce),j.onreadystatechange=function(){j.readyState===4&&T.signal.removeEventListener("abort",ce)}),j.send(typeof T._bodyInit=="undefined"?null:T._bodyInit)})}Ee.polyfill=!0,l.fetch||(l.fetch=Ee,l.Headers=S,l.Request=D,l.Response=C),f.Headers=S,f.Request=D,f.Response=C,f.fetch=Ee,Object.defineProperty(f,"__esModule",{value:!0})}),{fetch:u.fetch,Headers:u.Headers,Request:u.Request,Response:u.Response,DOMException:u.DOMException}}()}t.exports=n})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:ne)})(Ce,Ce.exports);var Yt=Ce.exports;const nt=rt(Yt);var Wt=typeof self=="object"?self.FormData:window.FormData;const it=rt(Wt),{fetch:Kt}=nt(),$e=async(t,e,{accessToken:r,name:n,fileId:a,bucketId:i,adminSecret:o,onUploadProgress:u,headers:f={}}={})=>{var w;const l={...f};i&&e.append("bucket-id",i),o&&(l["x-hasura-admin-secret"]=o),r&&(l.Authorization=`Bearer ${r}`);const v=`${t}/files`;if(typeof XMLHttpRequest=="undefined")try{const h=await Kt(v,{method:"POST",headers:l,body:e}),d=await h.json();return h.ok?{fileMetadata:d,error:null}:{error:{status:h.status,message:((w=d==null?void 0:d.error)==null?void 0:w.message)||h.statusText,error:h.statusText},fileMetadata:null}}catch(h){return{error:{status:0,message:h.message,error:h.message},fileMetadata:null}}return new Promise(h=>{let d=new XMLHttpRequest;d.responseType="json",d.onload=()=>{var y,m,E,S,g;return d.status<200||d.status>=300?h({fileMetadata:null,error:{error:(m=(y=d.response)==null?void 0:y.error)!=null?m:d.response,message:(g=(S=(E=d.response)==null?void 0:E.error)==null?void 0:S.message)!=null?g:d.response,status:d.status}}):h({fileMetadata:d.response,error:null})},d.onerror=()=>h({fileMetadata:null,error:{error:d.statusText,message:d.statusText,status:d.status}}),u&&d.upload.addEventListener("progress",u,!1),d.open("POST",v,!0),Object.entries(l).forEach(([y,m])=>{d.setRequestHeader(y,m)}),d.send(e)})},{fetch:at}=nt();class ot{constructor({url:e}){this.url=e}async uploadFormData({formData:e,headers:r,bucketId:n}){const{error:a,fileMetadata:i}=await $e(this.url,e,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:n,headers:r});return a?{fileMetadata:null,error:a}:i&&!("processedFiles"in i)?{fileMetadata:{processedFiles:[i]},error:null}:{fileMetadata:i,error:null}}async uploadFile({file:e,bucketId:r,id:n,name:a}){const i=new it;i.append("file[]",e),i.append("metadata[]",JSON.stringify({id:n,name:a}));const{error:o,fileMetadata:u}=await $e(this.url,i,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:r,fileId:n,name:a});return o?{fileMetadata:null,error:o}:u&&"processedFiles"in u?{fileMetadata:u.processedFiles[0],error:null}:{fileMetadata:u,error:null}}async getPresignedUrl(e){try{const{fileId:r}=e,n=await at(`${this.url}/files/${r}/presignedurl`,{method:"GET",headers:this.generateAuthHeaders()});if(!n.ok)throw new Error(await n.text());return{presignedUrl:await n.json(),error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e,n=await at(`${this.url}/files/${r}`,{method:"DELETE",headers:this.generateAuthHeaders()});if(!n.ok)throw new Error(await n.text());return{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateAuthHeaders(){if(!(!this.adminSecret&&!this.accessToken))return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}function He(t,e){if(!e||Object.keys(e).length===0)return t;const r=new URL(t),n=Object.entries(e).reduce((a,[i,o])=>({...a,[i.charAt(0)]:o}),{});return Object.entries(n).forEach(([a,i])=>{i&&r.searchParams.set(a,i)}),r.toString()}class Qt{constructor({url:e,adminSecret:r}){this.url=e,this.api=new ot({url:e}),this.setAdminSecret(r)}async upload(e){return"file"in e?this.api.uploadFile(e):this.api.uploadFormData(e)}getPublicUrl(e){const{fileId:r,...n}=e;return He(`${this.url}/files/${r}`,n)}async getPresignedUrl(e){const{fileId:r,...n}=e,{presignedUrl:a,error:i}=await this.api.getPresignedUrl(e);if(i)return{presignedUrl:null,error:i};if(!a)return{presignedUrl:null,error:new Error("Invalid file id")};const o=He(a.url,n);return{presignedUrl:{...a,url:o},error:null}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}/*! ***************************************************************************** | ||
`)===0?U.substr(1,U.length):U}).forEach(function(U){var T=U.split(":"),j=T.shift().trim();if(j){var ce=T.join(":").trim();c.append(j,ce)}}),c}B.call(D.prototype);function C(s,c){if(!(this instanceof C))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');c||(c={}),this.type="default",this.status=c.status===void 0?200:c.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in c?c.statusText:"",this.headers=new S(c.headers),this.url=c.url||"",this._initBody(s)}B.call(C.prototype),C.prototype.clone=function(){return new C(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new S(this.headers),url:this.url})},C.error=function(){var s=new C(null,{status:0,statusText:""});return s.type="error",s};var re=[301,302,303,307,308];C.redirect=function(s,c){if(re.indexOf(c)===-1)throw new RangeError("Invalid status code");return new C(null,{status:c,headers:{location:s}})},f.DOMException=l.DOMException;try{new f.DOMException}catch{f.DOMException=function(c,A){this.message=c,this.name=A;var U=Error(c);this.stack=U.stack},f.DOMException.prototype=Object.create(Error.prototype),f.DOMException.prototype.constructor=f.DOMException}function Ee(s,c){return new i(function(A,U){var T=new D(s,c);if(T.signal&&T.signal.aborted)return U(new f.DOMException("Aborted","AbortError"));var j=new o;function ce(){j.abort()}j.onload=function(){var H={status:j.status,statusText:j.statusText,headers:Y(j.getAllResponseHeaders()||"")};H.url="responseURL"in j?j.responseURL:H.headers.get("X-Request-URL");var Be="response"in j?j.response:j.responseText;setTimeout(function(){A(new C(Be,H))},0)},j.onerror=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},j.ontimeout=function(){setTimeout(function(){U(new TypeError("Network request failed"))},0)},j.onabort=function(){setTimeout(function(){U(new f.DOMException("Aborted","AbortError"))},0)};function q(H){try{return H===""&&l.location.href?l.location.href:H}catch{return H}}j.open(T.method,q(T.url),!0),T.credentials==="include"?j.withCredentials=!0:T.credentials==="omit"&&(j.withCredentials=!1),"responseType"in j&&(v.blob?j.responseType="blob":v.arrayBuffer&&T.headers.get("Content-Type")&&T.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(j.responseType="arraybuffer")),c&&typeof c.headers=="object"&&!(c.headers instanceof S)?Object.getOwnPropertyNames(c.headers).forEach(function(H){j.setRequestHeader(H,m(c.headers[H]))}):T.headers.forEach(function(H,Be){j.setRequestHeader(Be,H)}),T.signal&&(T.signal.addEventListener("abort",ce),j.onreadystatechange=function(){j.readyState===4&&T.signal.removeEventListener("abort",ce)}),j.send(typeof T._bodyInit=="undefined"?null:T._bodyInit)})}Ee.polyfill=!0,l.fetch||(l.fetch=Ee,l.Headers=S,l.Request=D,l.Response=C),f.Headers=S,f.Request=D,f.Response=C,f.fetch=Ee,Object.defineProperty(f,"__esModule",{value:!0})}),{fetch:u.fetch,Headers:u.Headers,Request:u.Request,Response:u.Response,DOMException:u.DOMException}}()}t.exports=n})(typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:ne)})(Ce,Ce.exports);var Wt=Ce.exports;const nt=rt(Wt);var Kt=typeof self=="object"?self.FormData:window.FormData;const it=rt(Kt);let at=globalThis.fetch;typeof EdgeRuntime!="string"&&(at=nt().fetch);const $e=async(t,e,{accessToken:r,name:n,fileId:a,bucketId:i,adminSecret:o,onUploadProgress:u,headers:f={}}={})=>{var w;const l={...f};i&&e.append("bucket-id",i),o&&(l["x-hasura-admin-secret"]=o),r&&(l.Authorization=`Bearer ${r}`);const v=`${t}/files`;if(typeof XMLHttpRequest=="undefined")try{const h=await at(v,{method:"POST",headers:l,body:e}),d=await h.json();return h.ok?{fileMetadata:d,error:null}:{error:{status:h.status,message:((w=d==null?void 0:d.error)==null?void 0:w.message)||h.statusText,error:h.statusText},fileMetadata:null}}catch(h){return{error:{status:0,message:h.message,error:h.message},fileMetadata:null}}return new Promise(h=>{let d=new XMLHttpRequest;d.responseType="json",d.onload=()=>{var y,m,E,S,g;return d.status<200||d.status>=300?h({fileMetadata:null,error:{error:(m=(y=d.response)==null?void 0:y.error)!=null?m:d.response,message:(g=(S=(E=d.response)==null?void 0:E.error)==null?void 0:S.message)!=null?g:d.response,status:d.status}}):h({fileMetadata:d.response,error:null})},d.onerror=()=>h({fileMetadata:null,error:{error:d.statusText,message:d.statusText,status:d.status}}),u&&d.upload.addEventListener("progress",u,!1),d.open("POST",v,!0),Object.entries(l).forEach(([y,m])=>{d.setRequestHeader(y,m)}),d.send(e)})},{fetch:ot}=nt();class st{constructor({url:e}){this.url=e}async uploadFormData({formData:e,headers:r,bucketId:n}){const{error:a,fileMetadata:i}=await $e(this.url,e,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:n,headers:r});return a?{fileMetadata:null,error:a}:i&&!("processedFiles"in i)?{fileMetadata:{processedFiles:[i]},error:null}:{fileMetadata:i,error:null}}async uploadFile({file:e,bucketId:r,id:n,name:a}){const i=new it;i.append("file[]",e),i.append("metadata[]",JSON.stringify({id:n,name:a}));const{error:o,fileMetadata:u}=await $e(this.url,i,{accessToken:this.accessToken,adminSecret:this.adminSecret,bucketId:r,fileId:n,name:a});return o?{fileMetadata:null,error:o}:u&&"processedFiles"in u?{fileMetadata:u.processedFiles[0],error:null}:{fileMetadata:u,error:null}}async getPresignedUrl(e){try{const{fileId:r}=e,n=await ot(`${this.url}/files/${r}/presignedurl`,{method:"GET",headers:this.generateAuthHeaders()});if(!n.ok)throw new Error(await n.text());return{presignedUrl:await n.json(),error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e,n=await ot(`${this.url}/files/${r}`,{method:"DELETE",headers:this.generateAuthHeaders()});if(!n.ok)throw new Error(await n.text());return{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateAuthHeaders(){if(!(!this.adminSecret&&!this.accessToken))return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}function He(t,e){if(!e||Object.keys(e).length===0)return t;const r=new URL(t),n=Object.entries(e).reduce((a,[i,o])=>({...a,[i.charAt(0)]:o}),{});return Object.entries(n).forEach(([a,i])=>{i&&r.searchParams.set(a,i)}),r.toString()}class Qt{constructor({url:e,adminSecret:r}){this.url=e,this.api=new st({url:e}),this.setAdminSecret(r)}async upload(e){return"file"in e?this.api.uploadFile(e):this.api.uploadFormData(e)}getPublicUrl(e){const{fileId:r,...n}=e;return He(`${this.url}/files/${r}`,n)}async getPresignedUrl(e){const{fileId:r,...n}=e,{presignedUrl:a,error:i}=await this.api.getPresignedUrl(e);if(i)return{presignedUrl:null,error:i};if(!a)return{presignedUrl:null,error:new Error("Invalid file id")};const o=He(a.url,n);return{presignedUrl:{...a,url:o},error:null}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
@@ -15,5 +15,5 @@ | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var p=function(){return p=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},p.apply(this,arguments)};function ke(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(r[n[a]]=t[n[a]]);return r}function L(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function O(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),a,i=[],o;try{for(;(e===void 0||e-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(u){o={error:u}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function N(t,e,r){if(r||arguments.length===2)for(var n=0,a=e.length,i;n<a;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}var R;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(R||(R={}));var Q;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Q||(Q={}));var qe=R.Start,Ge=R.Stop,ae=R.Raise,de=R.Send,st=R.Cancel,ut=R.NullEvent,Ae=R.Assign,Zt=R.After,er=R.DoneState,ze=R.Log,ft=R.Init,xe=R.Invoke,tr=R.ErrorExecution,rr=R.ErrorPlatform,lt=R.ErrorCustom,Xe=R.Update,ct=R.Choose,dt=R.Pure;const nr=Object.freeze(Object.defineProperty({__proto__:null,after:Zt,assign:Ae,cancel:st,choose:ct,doneState:er,error:lt,errorExecution:tr,errorPlatform:rr,init:ft,invoke:xe,log:ze,nullEvent:ut,pure:dt,raise:ae,send:de,start:qe,stop:Ge,update:Xe},Symbol.toStringTag,{value:"Module"}));var ht=".",pt={},Ve="xstate.guard",ir="",V=process.env.NODE_ENV==="production",Oe;function Je(t,e,r){r===void 0&&(r=ht);var n=he(t,r),a=he(e,r);return P(a)?P(n)?a===n:!1:P(n)?n in a:Object.keys(n).every(function(i){return i in a?Je(n[i],a[i]):!1})}function vt(t){try{return P(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function Ye(t,e){try{return ve(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function ar(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function he(t,e){if(ar(t))return t.value;if(ve(t))return Te(t);if(typeof t!="string")return t;var r=Ye(t,e);return Te(r)}function Te(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function pe(t,e){for(var r={},n=Object.keys(t),a=0;a<n.length;a++){var i=n[a];r[i]=e(t[i],i,t,a)}return r}function yt(t,e,r){var n,a,i={};try{for(var o=L(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];r(l)&&(i[f]=e(l,f,t))}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}var or=function(t){return function(e){var r,n,a=e;try{for(var i=L(t),o=i.next();!o.done;o=i.next()){var u=o.value;a=a[u]}}catch(f){r={error:f}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}};function sr(t,e){return function(r){var n,a,i=r;try{for(var o=L(t),u=o.next();!u.done;u=o.next()){var f=u.value;i=i[e][f]}}catch(l){n={error:l}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}}function Pe(t){if(!t)return[[]];if(P(t))return[[t]];var e=M(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Pe(t[r]).map(function(a){return[r].concat(a)})}));return e}function M(t){var e;return(e=[]).concat.apply(e,N([],O(t),!1))}function gt(t){return ve(t)?t:[t]}function W(t){return t===void 0?[]:gt(t)}function mt(t,e,r){var n,a;if(_(t))return t(e,r.data);var i={};try{for(var o=L(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];_(l)?i[f]=l(e,r.data):i[f]=l}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}function ur(t){return/^(done|error)\./.test(t)}function fr(t,e){var r,n,a=O([[],[]],2),i=a[0],o=a[1];try{for(var u=L(t),f=u.next();!f.done;f=u.next()){var l=f.value;e(l)?i.push(l):o.push(l)}}catch(v){r={error:v}}finally{try{f&&!f.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return[i,o]}function wt(t,e){return pe(t.states,function(r,n){if(r){var a=(P(e)?void 0:e[n])||(r?r.current:void 0);if(a)return{current:a,states:wt(r,a)}}})}function lr(t,e){return{current:e,states:wt(t,e)}}function St(t,e,r,n){V||K(!!t,"Attempting to update undefined context");var a=t&&r.reduce(function(i,o){var u,f,l=o.assignment,v={state:n,action:o,_event:e},w={};if(_(l))w=l(i,e.data,v);else try{for(var h=L(Object.keys(l)),d=h.next();!d.done;d=h.next()){var y=d.value,m=l[y];w[y]=_(m)?m(i,e.data,v):m}}catch(E){u={error:E}}finally{try{d&&!d.done&&(f=h.return)&&f.call(h)}finally{if(u)throw u.error}}return Object.assign({},i,w)},t);return a}var K=function(){};V||(K=function(t,e){var r=t instanceof Error?t:void 0;if(!(!r&&t)&&console!==void 0){var n=["Warning: ".concat(e)];r&&n.push(r),console.warn.apply(console,n)}});function ve(t){return Array.isArray(t)}function _(t){return typeof t=="function"}function P(t){return typeof t=="string"}function bt(t,e){if(t)return P(t)?{type:Ve,name:t,predicate:e?e[t]:void 0}:_(t)?{type:Ve,name:t.name,predicate:t}:t}var Et=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();Oe={},Oe[Et]=function(){return this},Oe[Symbol.observable]=function(){return this};function ie(t){return!!t&&"__xstatenode"in t}var cr=function(){var t=0;return function(){return t++,t.toString(16)}}();function At(t,e){return P(t)||typeof t=="number"?p({type:t},e):t}function ye(t,e){if(!P(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=At(t);return p({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function oe(t,e){var r=gt(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ie(n)?{target:n,event:t}:p(p({},n),{event:t})});return r}function dr(t){if(!(t===void 0||t===ir))return W(t)}function xt(t,e,r,n,a){var i=t.options.guards,o={state:a,cond:e,_event:n};if(e.type===Ve)return((i==null?void 0:i[e.name])||e.predicate)(r,n.data,o);var u=i==null?void 0:i[e.type];if(!u)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return u(r,n.data,o)}function hr(t){return typeof t=="string"?{type:t}:t}function De(t,e){return"".concat(t,":invocation[").concat(e,"]")}var je=ye({type:ft});function We(t,e){return e&&e[t]||void 0}function se(t,e){var r;if(P(t)||typeof t=="number"){var n=We(t,e);_(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(_(t))r={type:t.name||t.toString(),exec:t};else{var n=We(t.type,e);if(_(n))r=p(p({},t),{exec:n});else if(n){var a=n.type||t.type;r=p(p(p({},n),t),{type:a})}else r=t}return r}var Z=function(t,e){if(!t)return[];var r=ve(t)?t:[t];return r.map(function(n){return se(n,e)})};function Re(t){var e=se(t);return p(p({id:P(t)?t:e.id},e),{type:e.type})}function Ot(t){return P(t)?{type:ae,event:t}:ee(t,{to:Q.Internal})}function Tt(t){return{type:ae,_event:ye(t.event)}}function ee(t,e){return{to:e?e.to:void 0,type:de,event:_(t)?t:At(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:_(t)?t.name:vt(t)}}function Pt(t,e,r,n){var a={_event:r},i=ye(_(t.event)?t.event(e,r.data,a):t.event),o;if(P(t.delay)){var u=n&&n[t.delay];o=_(u)?u(e,r.data,a):u}else o=_(t.delay)?t.delay(e,r.data,a):t.delay;var f=_(t.to)?t.to(e,r.data,a):t.to;return p(p({},t),{to:f,_event:i,event:i.data,delay:o})}function Ke(t,e){return ee(t,p(p({},e),{to:Q.Parent}))}function pr(t,e,r){return ee(e,p(p({},r),{to:t}))}function vr(){return Ke(Xe)}function yr(t,e){return ee(t,p(p({},e),{to:function(r,n,a){var i=a._event;return i.origin}}))}var gr=function(t,e){return{context:t,event:e}};function mr(t,e){return t===void 0&&(t=gr),{type:ze,label:e,expr:t}}var Dt=function(t,e,r){return p(p({},t),{value:P(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},jt=function(t){return{type:st,sendId:t}};function Rt(t){var e=Re(t);return{type:R.Start,activity:e,exec:void 0}}function Ut(t){var e=_(t)?t:Re(t);return{type:R.Stop,activity:e,exec:void 0}}function Nt(t,e,r){var n=_(t.activity)?t.activity(e,r.data):t.activity,a=typeof n=="string"?{id:n}:n,i={type:R.Stop,activity:a};return i}var It=function(t){return{type:Ae,assignment:t}};function wr(t){return typeof t=="object"&&"type"in t}function Lt(t,e){var r=e?"#".concat(e):"";return"".concat(R.After,"(").concat(t,")").concat(r)}function ge(t,e){var r="".concat(R.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ft(t,e){var r="".concat(R.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Mt(t,e){var r="".concat(R.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Sr(t){return{type:R.Pure,get:t}}function br(t,e){if(!V&&(!t||typeof t=="function")){var r=t;t=function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var i=typeof r=="function"?r.apply(void 0,N([],O(n),!1)):r;if(!i)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return i}}return ee(function(n,a){return a},p(p({},e),{to:t}))}function Er(t,e){return Ke(function(r,n,a){return{type:lt,data:_(t)?t(r,n,a):t}},p(p({},e),{to:Q.Parent}))}function Ar(t){return{type:R.Choose,conds:t}}var xr=function(t){var e,r,n=[];try{for(var a=L(t),i=a.next();!i.done;i=a.next())for(var o=i.value,u=0;u<o.length;){if(o[u].type===Ae){n.push(o[u]),o.splice(u,1);continue}u++}}catch(f){e={error:f}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n};function Ue(t,e,r,n,a,i,o){o===void 0&&(o=!1);var u=o?[]:xr(a),f=u.length?St(r,n,u,e):r,l=o?[r]:void 0,v=[];function w(y){var m;switch(y.type){case ae:return Tt(y);case de:var E=Pt(y,f,n,t.options.delays);return V||K(!P(y.delay)||typeof E.delay=="number","No delay reference for delay expression '".concat(y.delay,"' was found on machine '").concat(t.id,"'")),i&&E.to!==Q.Internal&&v.push(E),E;case ze:{var S=Dt(y,f,n);return i==null||i(S,f,n),S}case ct:{var g=y,x=(m=g.conds.find(function(Y){var C=bt(Y.cond,t.options.guards);return!C||xt(t,C,f,n,i?void 0:e)}))===null||m===void 0?void 0:m.actions;if(!x)return[];var F=O(Ue(t,e,f,n,[Z(W(x),t.options.actions)],i,o),2),I=F[0],$=F[1];return f=$,l==null||l.push(f),I}case dt:{var x=y.get(f,n.data);if(!x)return[];var k=O(Ue(t,e,f,n,[Z(W(x),t.options.actions)],i,o),2),B=k[0],z=k[1];return f=z,l==null||l.push(f),B}case Ge:{var S=Nt(y,f,n);return i==null||i(S,r,n),S}case Ae:{f=St(f,n,[y],i?void 0:e),l==null||l.push(f);break}default:var b=se(y,t.options.actions),D=b.exec;if(i)i(b,f,n);else if(D&&l){var J=l.length-1;b=p(p({},b),{exec:function(Y){for(var C=[],re=1;re<arguments.length;re++)C[re-1]=arguments[re];D.apply(void 0,N([l[J]],O(C),!1))}})}return b}}function h(y){var m,E,S=[];try{for(var g=L(y),x=g.next();!x.done;x=g.next()){var F=x.value,I=w(F);I&&(S=S.concat(I))}}catch($){m={error:$}}finally{try{x&&!x.done&&(E=g.return)&&E.call(g)}finally{if(m)throw m.error}}return v.forEach(function($){i($,f,n)}),v.length=0,S}var d=M(a.map(h));return[d,f]}const Or=Object.freeze(Object.defineProperty({__proto__:null,actionTypes:nr,after:Lt,assign:It,cancel:jt,choose:Ar,done:ge,doneInvoke:Ft,error:Mt,escalate:Er,forwardTo:br,getActionFunction:We,initEvent:je,isActionObject:wr,log:mr,pure:Sr,raise:Ot,resolveActions:Ue,resolveLog:Dt,resolveRaise:Tt,resolveSend:Pt,resolveStop:Nt,respond:yr,send:ee,sendParent:Ke,sendTo:pr,sendUpdate:vr,start:Rt,stop:Ut,toActionObject:se,toActionObjects:Z,toActivityDefinition:Re},Symbol.toStringTag,{value:"Module"}));var Ne=[],Tr=function(t,e){Ne.push(t);var r=e(t);return Ne.pop(),r},Pr=function(t){return t(Ne[Ne.length-1])};function _t(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[Et]=function(){return this},e}function Dr(t,e,r,n){var a,i=hr(t.src),o=(a=e==null?void 0:e.options.services)===null||a===void 0?void 0:a[i.type],u=t.data?mt(t.data,r,n):void 0,f=o?Bt(o,t.id,u):_t(t.id);return f.meta=t,f}function Bt(t,e,r){var n=_t(e);if(n.deferred=!0,ie(t)){var a=n.state=Tr(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return a}}return n}var Ie=function(t){return t.type==="atomic"||t.type==="final"};function Ct(t){return Object.keys(t.states).map(function(e){return t.states[e]})}function me(t){return Ct(t).filter(function(e){return e.type!=="history"})}function $t(t){var e=[t];return Ie(t)?e:e.concat(M(me(t).map($t)))}function we(t,e){var r,n,a,i,o,u,f,l,v=new Set(t),w=Qe(v),h=new Set(e);try{for(var d=L(h),y=d.next();!y.done;y=d.next())for(var m=y.value,E=m.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(z){r={error:z}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(r)throw r.error}}var S=Qe(h);try{for(var g=L(h),x=g.next();!x.done;x=g.next()){var m=x.value;if(m.type==="compound"&&(!S.get(m)||!S.get(m).length))w.get(m)?w.get(m).forEach(function(b){return h.add(b)}):m.initialStateNodes.forEach(function(b){return h.add(b)});else if(m.type==="parallel")try{for(var F=(o=void 0,L(me(m))),I=F.next();!I.done;I=F.next()){var $=I.value;h.has($)||(h.add($),w.get($)?w.get($).forEach(function(b){return h.add(b)}):$.initialStateNodes.forEach(function(b){return h.add(b)}))}}catch(b){o={error:b}}finally{try{I&&!I.done&&(u=F.return)&&u.call(F)}finally{if(o)throw o.error}}}}catch(z){a={error:z}}finally{try{x&&!x.done&&(i=g.return)&&i.call(g)}finally{if(a)throw a.error}}try{for(var k=L(h),B=k.next();!B.done;B=k.next())for(var m=B.value,E=m.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(z){f={error:z}}finally{try{B&&!B.done&&(l=k.return)&&l.call(k)}finally{if(f)throw f.error}}return h}function Ht(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(Ie(n))return n.key}else return{}}var a={};return r.forEach(function(i){a[i.key]=Ht(i,e)}),a}function Qe(t){var e,r,n=new Map;try{for(var a=L(t),i=a.next();!i.done;i=a.next()){var o=i.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(u){e={error:u}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n}function jr(t,e){var r=we([t],e);return Ht(t,Qe(r))}function Se(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Rr(t){return N([],O(new Set(M(N([],O(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Le(t,e){return e.type==="compound"?me(e).some(function(r){return r.type==="final"&&Se(t,r)}):e.type==="parallel"?me(e).every(function(r){return Le(t,r)}):!1}function Ur(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function kt(t){return new Set(M(t.map(function(e){return e.tags})))}function qt(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(P(t)||P(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(a){return qt(t[a],e[a])})}var te=function(){function t(e){var r=this,n;this.actions=[],this.activities=pt,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||pt,this.meta=Ur(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Rr(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=je;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=je;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),P(e))return[e];var a=Object.keys(e);return a.concat.apply(a,N([],O(a.map(function(i){return n.toStrings(e[i],r).map(function(o){return i+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=ke(e,["configuration","transitions","tags","machine"]);return p(p({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Je(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;V&&K(!!this.machine,"state.can(...) used outside of a machine-created State object; this will always return false.");var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(a){return a.target!==void 0||a.actions.length})},t}(),Gt={sync:!1,autoForward:!1},zt;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(zt||(zt={}));var Nr=function(t){return P(t)?p(p({},Gt),{name:t}):p(p(p({},Gt),{name:cr()}),t)};function Ir(t,e){var r=Nr(e);return Pr(function(n){if(!V){var a=ie(t)||_(t);K(!!n||a,'Attempted to spawn an Actor (ID: "'.concat(ie(t)?t.id:"undefined",'") outside of a service. This will have no effect.'))}return n?n.spawn(t,r.name,r):Bt(t,r.name)})}function Lr(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function Fe(t){return p(p({type:xe},t),{toJSON:function(){t.onDone,t.onError;var e=ke(t,["onDone","onError"]);return p(p({},e),{type:xe,src:Lr(t.src)})}})}var ue="",Ze="#",be="*",fe={},le=function(t){return t[0]===Ze},Fr=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Mr=function(t,e,r){var n=r.slice(0,-1).some(function(i){return!("cond"in i)&&!("in"in i)&&(P(i.target)||ie(i.target))}),a=e===ue?"the transient event":"event '".concat(e,"'");K(!n,"One or more transitions for ".concat(a," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},_r=function(){function t(e,r,n,a){n===void 0&&(n="context"in e?e.context:void 0);var i=this,o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(Fr(),r),this.parent=a==null?void 0:a.parent,this.key=this.config.key||(a==null?void 0:a.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:ht),this.id=this.config.id||N([this.machine.key],O(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,V||K(!("parallel"in this.config),'The "parallel" property is deprecated and will be removed in version 4.1. '.concat(this.config.parallel?"Replace with `type: 'parallel'`":"Use `type: '".concat(this.type,"'`")," in the config for state node '").concat(this.id,"' instead.")),this.initial=this.config.initial,this.states=this.config.states?pe(this.config.states,function(l,v){var w,h=new t(l,{},void 0,{parent:i,key:v});return Object.assign(i.idMap,p((w={},w[h.id]=h,w),h.idMap)),h}):fe;var u=0;function f(l){var v,w;l.order=u++;try{for(var h=L(Ct(l)),d=h.next();!d.done;d=h.next()){var y=d.value;f(y)}}catch(m){v={error:m}}finally{try{d&&!d.done&&(w=h.return)&&w.call(h)}finally{if(v)throw v.error}}}f(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(l){var v=l.event;return v===ue}):ue in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=W(this.config.entry||this.config.onEntry).map(function(l){return se(l)}),this.onExit=W(this.config.exit||this.config.onExit).map(function(l){return se(l)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=W(this.config.invoke).map(function(l,v){var w,h;if(ie(l)){var d=De(i.id,v);return i.machine.options.services=p((w={},w[d]=l,w),i.machine.options.services),Fe({src:d,id:d})}else if(P(l.src)){var d=l.id||De(i.id,v);return Fe(p(p({},l),{id:d,src:l.src}))}else if(ie(l.src)||_(l.src)){var d=l.id||De(i.id,v);return i.machine.options.services=p((h={},h[d]=l.src,h),i.machine.options.services),Fe(p(p({id:d},l),{src:d}))}else{var y=l.src;return Fe(p(p({id:De(i.id,v)},l),{src:y}))}}),this.activities=W(this.config.activities).concat(this.invoke).map(function(l){return Re(l)}),this.transition=this.transition.bind(this),this.tags=W(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||$t(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,a=n.actions,i=n.activities,o=n.guards,u=n.services,f=n.delays;return new t(this.config,{actions:p(p({},a),e.actions),activities:p(p({},i),e.activities),guards:p(p({},o),e.guards),services:p(p({},u),e.services),delays:p(p({},f),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return _(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:pe(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===ue,n=this.transitions.filter(function(a){var i=a.eventType===e;return r?i:i||a.eventType===be});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(i,o){var u=_(i)?"".concat(e.id,":delay[").concat(o,"]"):i,f=Lt(u,e.id);return e.onEntry.push(ee(f,{delay:i})),e.onExit.push(jt(f)),f},a=ve(r)?r.map(function(i,o){var u=n(i.delay,o);return p(p({},i),{event:u})}):M(Object.keys(r).map(function(i,o){var u=r[i],f=P(u)?{target:u}:u,l=isNaN(+i)?i:+i,v=n(l,o);return W(f).map(function(w){return p(p({},w),{event:v,delay:l})})}));return a.map(function(i){var o=i.delay;return p(p({},e.formatTransition(i)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var a=e instanceof te?e.value:he(e,this.delimiter);if(P(a)){var i=this.getStateNode(a).initial;return i!==void 0?this.getStateNodes((r={},r[a]=i,r)):[this,this.states[a]]}var o=Object.keys(a),u=[this];return u.push.apply(u,N([],O(M(o.map(function(f){return n.getStateNode(f).getStateNodes(a[f])}))),!1)),u},t.prototype.handles=function(e){var r=vt(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof te?e:te.create(e),n=Array.from(we([],this.getStateNodes(r.value)));return new te(p(p({},r),{value:this.resolve(r.value),configuration:n,done:Le(n,this),tags:kt(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var a=this.getStateNode(e),i=a.next(r,n);return!i||!i.transitions.length?this.next(r,n):i},t.prototype.transitionCompoundNode=function(e,r,n){var a=Object.keys(e),i=this.getStateNode(a[0]),o=i._transition(e[a[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var a,i,o={};try{for(var u=L(Object.keys(e)),f=u.next();!f.done;f=u.next()){var l=f.value,v=e[l];if(v){var w=this.getStateNode(l),h=w._transition(v,r,n);h&&(o[l]=h)}}}catch(g){a={error:g}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(a)throw a.error}}var d=Object.keys(o).map(function(g){return o[g]}),y=M(d.map(function(g){return g.transitions})),m=d.some(function(g){return g.transitions.length>0});if(!m)return this.next(r,n);var E=M(d.map(function(g){return g.entrySet})),S=M(Object.keys(o).map(function(g){return o[g].configuration}));return{transitions:y,entrySet:E,exitSet:M(d.map(function(g){return g.exitSet})),configuration:S,source:r,actions:M(Object.keys(o).map(function(g){return o[g].actions}))}},t.prototype._transition=function(e,r,n){return P(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,ye(r))},t.prototype.next=function(e,r){var n,a,i=this,o=r.name,u=[],f=[],l;try{for(var v=L(this.getCandidates(o)),w=v.next();!w.done;w=v.next()){var h=w.value,d=h.cond,y=h.in,m=e.context,E=y?P(y)&&le(y)?e.matches(he(this.getStateNodeById(y).path,this.delimiter)):Je(he(y,this.delimiter),or(this.path.slice(0,-2))(e.value)):!0,S=!1;try{S=!d||xt(this.machine,d,m,r,e)}catch(I){throw new Error("Unable to evaluate guard '".concat(d.name||d.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`': | ||
`).concat(I.message))}if(S&&E){h.target!==void 0&&(f=h.target),u.push.apply(u,N([],O(h.actions),!1)),l=h;break}}}catch(I){n={error:I}}finally{try{w&&!w.done&&(a=v.return)&&a.call(v)}finally{if(n)throw n.error}}if(l){if(!f.length)return{transitions:[l],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:u};var g=M(f.map(function(I){return i.getRelativeStateNodes(I,e.historyValue)})),x=!!l.internal,F=[];return x||f.forEach(function(I){F.push.apply(F,N([],O(i.getExternalReentryNodes(I)),!1))}),{transitions:[l],entrySet:F,exitSet:x?[]:[this],configuration:g,source:e,actions:u}}},t.prototype.getExternalReentryNodes=function(e){for(var r=[],n=O(e.order>this.order?[e,this]:[this,e],2),a=n[0],i=n[1];a&&a!==i;)r.push(a),a=a.parent;return a!==i?[]:(r.push(i),r)},t.prototype.getActions=function(e,r,n,a,i,o,u){var f,l,v,w,h=this,d=we([],o?this.getStateNodes(o.value):[this]);try{for(var y=L(e),m=y.next();!m.done;m=y.next()){var E=m.value;(!Se(d,E)||Se(n.entrySet,E.parent))&&n.entrySet.push(E)}}catch(b){f={error:b}}finally{try{m&&!m.done&&(l=y.return)&&l.call(y)}finally{if(f)throw f.error}}try{for(var S=L(d),g=S.next();!g.done;g=S.next()){var E=g.value;(!Se(e,E)||Se(n.exitSet,E.parent))&&n.exitSet.push(E)}}catch(b){v={error:b}}finally{try{g&&!g.done&&(w=S.return)&&w.call(S)}finally{if(v)throw v.error}}var x=M(n.entrySet.map(function(b){var D=[];if(b.type!=="final")return D;var J=b.parent;if(!J.parent)return D;D.push(ge(b.id,b.doneData),ge(J.id,b.doneData?mt(b.doneData,a,i):void 0));var Y=J.parent;return Y.type==="parallel"&&me(Y).every(function(C){return Le(n.configuration,C)})&&D.push(ge(Y.id)),D}));n.exitSet.sort(function(b,D){return D.order-b.order}),n.entrySet.sort(function(b,D){return b.order-D.order});var F=new Set(n.entrySet),I=new Set(n.exitSet),$=Array.from(F).map(function(b){var D=b.onEntry,J=b.activities.map(function(Y){return Rt(Y)});return Z(u?N(N([],O(D),!1),O(J),!1):N(N([],O(J),!1),O(D),!1),h.machine.options.actions)}).concat([x.map(Ot)]),k=Array.from(I).map(function(b){return Z(N(N([],O(b.onExit),!1),O(b.activities.map(function(D){return Ut(D)})),!1),h.machine.options.actions)}),B=k.concat([Z(n.actions,this.machine.options.actions)]).concat($);if(r){var z=Z(M(N([],O(e),!1).sort(function(b,D){return D.order-b.order}).map(function(b){return b.onExit})),this.machine.options.actions).filter(function(b){return b.type!==ae&&(b.type!==de||!!b.to&&b.to!==Q.Internal)});return B.concat([z])}return B},t.prototype.transition=function(e,r,n,a){e===void 0&&(e=this.initialState);var i=ye(r),o;if(e instanceof te)o=n===void 0?e:this.resolveState(te.from(e,n));else{var u=P(e)?this.resolve(Te(this.getResolvedPath(e))):this.resolve(e),f=n!=null?n:this.machine.context;o=this.resolveState(te.from(u,f))}if(!V&&i.name===be)throw new Error("An event cannot have the wildcard type ('".concat(be,"')"));if(this.strict&&!this.events.includes(i.name)&&!ur(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var l=this._transition(o.value,o,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:o,actions:[]},v=we([],this.getStateNodes(o.value)),w=l.configuration.length?we(v,l.configuration):v;return l.configuration=N([],O(w),!1),this.resolveTransition(l,o,o.context,a,i)},t.prototype.resolveRaisedTransition=function(e,r,n,a){var i,o=e.actions;return e=this.transition(e,r,void 0,a),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,N([],O(o),!1)),e},t.prototype.resolveTransition=function(e,r,n,a,i){var o,u,f,l,v=this;i===void 0&&(i=je);var w=e.configuration,h=!r||e.transitions.length>0,d=h?e.configuration:r?r.configuration:[],y=Le(d,this),m=h?jr(this.machine,w):void 0,E=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,S=this.getActions(new Set(d),y,e,n,i,r,a),g=r?p({},r.activities):{};try{for(var x=L(S),F=x.next();!F.done;F=x.next()){var I=F.value;try{for(var $=(f=void 0,L(I)),k=$.next();!k.done;k=$.next()){var B=k.value;B.type===qe?g[B.activity.id||B.activity.type]=B:B.type===Ge&&(g[B.activity.id||B.activity.type]=!1)}}catch(q){f={error:q}}finally{try{k&&!k.done&&(l=$.return)&&l.call($)}finally{if(f)throw f.error}}}}catch(q){o={error:q}}finally{try{F&&!F.done&&(u=x.return)&&u.call(x)}finally{if(o)throw o.error}}var z=O(Ue(this,r,n,i,S,a,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),b=z[0],D=z[1],J=O(fr(b,function(q){return q.type===ae||q.type===de&&q.to===Q.Internal}),2),Y=J[0],C=J[1],re=b.filter(function(q){var H;return q.type===qe&&((H=q.activity)===null||H===void 0?void 0:H.type)===xe}),Ee=re.reduce(function(q,H){return q[H.activity.id]=Dr(H.activity,v.machine,D,i),q},r?p({},r.children):{}),s=new te({value:m||r.value,context:D,_event:i,_sessionid:r?r._sessionid:null,historyValue:m?E?lr(E,m):void 0:r?r.historyValue:void 0,history:!m||e.source?r:void 0,actions:m?C:[],activities:m?g:r?r.activities:{},events:[],configuration:d,transitions:e.transitions,children:Ee,done:y,tags:kt(d),machine:this}),c=n!==D;s.changed=i.name===Xe||c;var A=s.history;A&&delete A.history;var U=!y&&(this._transient||w.some(function(q){return q._transient}));if(!h&&(!U||i.name===ue))return s;var T=s;if(!y)for(U&&(T=this.resolveRaisedTransition(T,{type:ut},i,a));Y.length;){var j=Y.shift();T=this.resolveRaisedTransition(T,j._event,i,a)}var ce=T.changed||(A?!!T.actions.length||c||typeof A.value!=typeof T.value||!qt(T.value,A.value):void 0);return T.changed=ce,T.history=A,T},t.prototype.getStateNode=function(e){if(le(e))return this.machine.getStateNodeById(e);if(!this.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[e];if(!r)throw new Error("Child state '".concat(e,"' does not exist on '").concat(this.id,"'"));return r},t.prototype.getStateNodeById=function(e){var r=le(e)?e.slice(Ze.length):e;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(e){if(typeof e=="string"&&le(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=Ye(e,this.delimiter).slice(),n=this;r.length;){var a=r.shift();if(!a.length)break;n=n.getStateNode(a)}return n},t.prototype.resolve=function(e){var r,n=this;if(!e)return this.initialStateValue||fe;switch(this.type){case"parallel":return pe(this.initialStateValue,function(i,o){return i?n.getStateNode(o).resolve(e[o]||i):fe});case"compound":if(P(e)){var a=this.getStateNode(e);return a.type==="parallel"||a.type==="compound"?(r={},r[e]=a.initialStateValue,r):e}return Object.keys(e).length?pe(e,function(i,o){return i?n.getStateNode(o).resolve(i):fe}):this.initialStateValue||{};default:return e||fe}},t.prototype.getResolvedPath=function(e){if(le(e)){var r=this.machine.idMap[e.slice(Ze.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return Ye(e,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=yt(this.states,function(n){return n.initialStateValue||fe},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=Ie(this.states[this.initial])?this.initial:(e={},e[this.initial]=this.states[this.initial].initialStateValue,e)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(e,r){this._init();var n=this.getStateNodes(e);return this.resolveTransition({configuration:n,entrySet:N([],O(n),!1),exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r!=null?r:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var e;if(this.type==="history"){var r=this.config;P(r.target)?e=le(r.target)?Te(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:e=r.target}return e},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(e,r,n){return n===void 0&&(n=!0),n?e.type==="history"?e.resolveHistory(r):e.initialStateNodes:[e]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var e=this;if(Ie(this))return[this];if(this.type==="compound"&&!this.initial)return V||K(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Pe(this.initialStateValue);return M(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=O(e),n=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var i=this.getStateNode(n);if(i.type==="history")return i.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(a)},t.prototype.historyValue=function(e){if(Object.keys(this.states).length)return{current:e||this.initialStateValue,states:yt(this.states,function(r,n){if(!e)return r.historyValue();var a=P(e)?void 0:e[n];return r.historyValue(a||r.initialStateValue)},function(r){return!r.history})}},t.prototype.resolveHistory=function(e){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!e){var a=this.target;return a?M(Pe(a).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var i=sr(n.path,"states")(e).current;return P(i)?[n.getStateNode(i)]:M(Pe(i).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=M(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,a;if(this.__cache.events)return this.__cache.events;var i=this.states,o=new Set(this.ownEvents);if(i)try{for(var u=L(Object.keys(i)),f=u.next();!f.done;f=u.next()){var l=f.value,v=i[l];if(v.states)try{for(var w=(n=void 0,L(v.events)),h=w.next();!h.done;h=w.next()){var d=h.value;o.add("".concat(d))}}catch(y){n={error:y}}finally{try{h&&!h.done&&(a=w.return)&&a.call(w)}finally{if(n)throw n.error}}}}catch(y){e={error:y}}finally{try{f&&!f.done&&(r=u.return)&&r.call(u)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!P(n))return n;var a=n[0]===r.delimiter;if(a&&!r.parent)return r.getStateNodeByPath(n.slice(1));var i=a?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(i);return o}catch(u){throw new Error("Invalid transition definition for state node '".concat(r.id,`': | ||
`).concat(u.message))}else return r.getStateNodeByPath(i)})},t.prototype.formatTransition=function(e){var r=this,n=dr(e.target),a="internal"in e?e.internal:n?n.some(function(f){return P(f)&&f[0]===r.delimiter}):!0,i=this.machine.options.guards,o=this.resolveTarget(n),u=p(p({},e),{actions:Z(W(e.actions)),cond:bt(e.cond,i),target:o,source:this,internal:a,eventType:e.event,toJSON:function(){return p(p({},u),{target:u.target?u.target.map(function(f){return"#".concat(f.id)}):void 0,source:"#".concat(r.id)})}});return u},t.prototype.formatTransitions=function(){var e,r,n=this,a;if(!this.config.on)a=[];else if(Array.isArray(this.config.on))a=this.config.on;else{var i=this.config.on,o=be,u=i[o],f=u===void 0?[]:u,l=ke(i,[typeof o=="symbol"?o:o+""]);a=M(Object.keys(l).map(function(g){!V&&g===ue&&K(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var x=oe(g,l[g]);return V||Mr(n,g,x),x}).concat(oe(be,f)))}var v=this.config.always?oe("",this.config.always):[],w=this.config.onDone?oe(String(ge(this.id)),this.config.onDone):[];V||K(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var h=M(this.invoke.map(function(g){var x=[];return g.onDone&&x.push.apply(x,N([],O(oe(String(Ft(g.id)),g.onDone)),!1)),g.onError&&x.push.apply(x,N([],O(oe(String(Mt(g.id)),g.onError)),!1)),x})),d=this.after,y=M(N(N(N(N([],O(w),!1),O(h),!1),O(a),!1),O(v),!1).map(function(g){return W(g).map(function(x){return n.formatTransition(x)})}));try{for(var m=L(d),E=m.next();!E.done;E=m.next()){var S=E.value;y.push(S)}}catch(g){e={error:g}}finally{try{E&&!E.done&&(r=m.return)&&r.call(m)}finally{if(e)throw e.error}}return y},t}(),Xt=!1;function Vt(t,e){return!V&&!t.predictableActionArguments&&!Xt&&(Xt=!0,console.warn("It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html")),new _r(t,e)}var G=It,et=ee;const Me={progress:null,loaded:0,error:null,bucketId:void 0,file:void 0,id:void 0},Jt=()=>Vt({predictableActionArguments:!0,schema:{context:{},events:{}},tsTypes:{},context:{...Me},initial:"idle",on:{DESTROY:{actions:"sendDestroy",target:"stopped"}},states:{idle:{on:{ADD:{actions:"addFile"},UPLOAD:{cond:"hasFile",target:"uploading"}}},uploading:{entry:"resetProgress",on:{UPLOAD_PROGRESS:{actions:["incrementProgress","sendProgress"]},UPLOAD_DONE:"uploaded",UPLOAD_ERROR:"error",CANCEL:"idle"},invoke:{src:"uploadFile"}},uploaded:{entry:["setFileMetadata","sendDone"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},error:{entry:["setError","sendError"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},stopped:{type:"final"}}},{guards:{hasFile:(t,e)=>!!t.file||!!e.file},actions:{incrementProgress:G({loaded:(t,{loaded:e})=>e,progress:(t,{progress:e})=>e}),setFileMetadata:G({id:(t,{id:e})=>e,bucketId:(t,{bucketId:e})=>e,progress:t=>100}),setError:G({error:(t,{error:e})=>e}),sendProgress:()=>{},sendError:()=>{},sendDestroy:()=>{},sendDone:()=>{},resetProgress:G({progress:t=>null,loaded:t=>0}),resetContext:G(t=>Me),addFile:G({file:(t,{file:e})=>e,bucketId:(t,{bucketId:e})=>e,id:(t,{id:e})=>e})},services:{uploadFile:(t,e)=>r=>{const n=e.file||t.file,a=new it;a.append("file[]",n);let i=0;return $e(e.url,a,{fileId:e.id||t.id,bucketId:e.bucketId||t.bucketId,accessToken:e.accessToken,adminSecret:e.adminSecret,name:e.name||n.name,onUploadProgress:o=>{const u=o.total?Math.round(o.loaded*n.size/o.total):0,f=u-i;i=u,r({type:"UPLOAD_PROGRESS",progress:o.total?Math.round(u*100/o.total):0,loaded:u,additions:f})}}).then(({fileMetadata:o,error:u})=>{if(u&&r({type:"UPLOAD_ERROR",error:u}),o&&!("processedFiles"in o)){const{id:f,bucketId:l}=o;r({type:"UPLOAD_DONE",id:f,bucketId:l})}if(o&&"processedFiles"in o){const{id:f,bucketId:l}=o.processedFiles[0];r({type:"UPLOAD_DONE",id:f,bucketId:l})}}),()=>{}}}}),{pure:tt,sendParent:_e}=Or,Br=()=>Vt({id:"files-list",schema:{context:{},events:{}},tsTypes:{},predictableActionArguments:!0,context:{progress:null,files:[],loaded:0,total:0},initial:"idle",on:{UPLOAD:{cond:"hasFileToDownload",actions:"addItem",target:"uploading"},ADD:{actions:"addItem"},REMOVE:{actions:"removeItem"}},states:{idle:{entry:["resetProgress","resetLoaded","resetTotal"],on:{CLEAR:{actions:"clearList",target:"idle"}}},uploading:{entry:["upload","startProgress","resetLoaded","resetTotal"],on:{UPLOAD_PROGRESS:{actions:["incrementProgress"]},UPLOAD_DONE:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],UPLOAD_ERROR:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],CANCEL:{actions:"cancel",target:"idle"}}},uploaded:{entry:"setUploaded",on:{CLEAR:{actions:"clearList",target:"idle"}}},error:{on:{CLEAR:{actions:"clearList",target:"idle"}}}}},{guards:{hasFileToDownload:(t,e)=>t.files.some(r=>r.getSnapshot().matches("idle"))||!!e.files,isAllUploaded:t=>t.files.every(e=>{var r;return(r=e.getSnapshot())==null?void 0:r.matches("uploaded")}),isAllUploadedOrError:t=>t.files.every(e=>{const r=e.getSnapshot();return(r==null?void 0:r.matches("error"))||(r==null?void 0:r.matches("uploaded"))})},actions:{incrementProgress:G((t,e)=>{const r=t.loaded+e.additions,n=Math.round(r*100/t.total);return{...t,loaded:r,progress:n}}),setUploaded:G({progress:t=>100,loaded:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>e.matches("uploaded")).reduce((e,r)=>{var n;return e+((n=r.context.file)==null?void 0:n.size)},0)}),resetTotal:G({total:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>!e.matches("uploaded")).reduce((e,r)=>{var n;return e+((n=r.context.file)==null?void 0:n.size)},0)}),resetLoaded:G({loaded:t=>0}),startProgress:G({progress:t=>0}),resetProgress:G({progress:t=>null}),addItem:G((t,{files:e,bucketId:r})=>{const n=e?Array.isArray(e)?e:"item"in e?Array.from(e):[e]:[],a=t.total+n.reduce((o,u)=>o+u.size,0),i=Math.round(t.loaded*100/a);return{files:[...t.files,...n.map(o=>Ir(Jt().withConfig({actions:{sendProgress:_e((u,{additions:f})=>({type:"UPLOAD_PROGRESS",additions:f})),sendDone:_e("UPLOAD_DONE"),sendError:_e("UPLOAD_ERROR"),sendDestroy:_e("REMOVE")}}).withContext({...Me,file:o,bucketId:r}),{sync:!0}))],total:a,loaded:t.loaded,progress:i}}),removeItem:G({files:t=>t.files.filter(e=>{var n,a;const r=(n=e.getSnapshot())==null?void 0:n.matches("stopped");return r&&((a=e.stop)==null||a.call(e)),!r})}),clearList:tt(t=>t.files.map(e=>et({type:"DESTROY"},{to:e.id}))),upload:tt((t,e)=>t.files.map(r=>et(e,{to:r.id}))),cancel:tt(t=>t.files.map(e=>et({type:"CANCEL"},{to:e.id})))}}),Cr=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t}),e.subscribe(n=>{var a;n.matches("error")?r({error:n.context.error,isError:!0,isUploaded:!1}):n.matches("uploaded")&&r({error:null,isError:!1,isUploaded:!0,id:n.context.id,bucketId:n.context.id,name:(a=n.context.file)==null?void 0:a.name})})}),$r=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t,files:t.files}),e.onTransition(n=>{n.matches("error")?r({errors:n.context.files.filter(a=>{var i;return(i=a.getSnapshot())==null?void 0:i.context.error}),isError:!0,files:[]}):n.matches("uploaded")&&r({errors:[],isError:!1,files:n.context.files})})});X.HasuraStorageApi=ot,X.HasuraStorageClient=Qt,X.INITIAL_FILE_CONTEXT=Me,X.appendImageTransformationParameters=He,X.createFileUploadMachine=Jt,X.createMultipleFilesUploadMachine=Br,X.uploadFilePromise=Cr,X.uploadMultipleFilesPromise=$r,Object.defineProperty(X,Symbol.toStringTag,{value:"Module"})}); | ||
***************************************************************************** */var p=function(){return p=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},p.apply(this,arguments)};function ke(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(r[n[a]]=t[n[a]]);return r}function L(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function O(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),a,i=[],o;try{for(;(e===void 0||e-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(u){o={error:u}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function N(t,e,r){if(r||arguments.length===2)for(var n=0,a=e.length,i;n<a;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}var R;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(R||(R={}));var Q;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Q||(Q={}));var qe=R.Start,Ge=R.Stop,ae=R.Raise,de=R.Send,ut=R.Cancel,ft=R.NullEvent,Ae=R.Assign,Zt=R.After,er=R.DoneState,ze=R.Log,lt=R.Init,xe=R.Invoke,tr=R.ErrorExecution,rr=R.ErrorPlatform,ct=R.ErrorCustom,Xe=R.Update,dt=R.Choose,ht=R.Pure;const nr=Object.freeze(Object.defineProperty({__proto__:null,after:Zt,assign:Ae,cancel:ut,choose:dt,doneState:er,error:ct,errorExecution:tr,errorPlatform:rr,init:lt,invoke:xe,log:ze,nullEvent:ft,pure:ht,raise:ae,send:de,start:qe,stop:Ge,update:Xe},Symbol.toStringTag,{value:"Module"}));var pt=".",vt={},Ve="xstate.guard",ir="",V=process.env.NODE_ENV==="production",Oe;function Je(t,e,r){r===void 0&&(r=pt);var n=he(t,r),a=he(e,r);return P(a)?P(n)?a===n:!1:P(n)?n in a:Object.keys(n).every(function(i){return i in a?Je(n[i],a[i]):!1})}function yt(t){try{return P(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function Ye(t,e){try{return ve(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function ar(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function he(t,e){if(ar(t))return t.value;if(ve(t))return Te(t);if(typeof t!="string")return t;var r=Ye(t,e);return Te(r)}function Te(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function pe(t,e){for(var r={},n=Object.keys(t),a=0;a<n.length;a++){var i=n[a];r[i]=e(t[i],i,t,a)}return r}function gt(t,e,r){var n,a,i={};try{for(var o=L(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];r(l)&&(i[f]=e(l,f,t))}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}var or=function(t){return function(e){var r,n,a=e;try{for(var i=L(t),o=i.next();!o.done;o=i.next()){var u=o.value;a=a[u]}}catch(f){r={error:f}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}};function sr(t,e){return function(r){var n,a,i=r;try{for(var o=L(t),u=o.next();!u.done;u=o.next()){var f=u.value;i=i[e][f]}}catch(l){n={error:l}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}}function Pe(t){if(!t)return[[]];if(P(t))return[[t]];var e=M(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Pe(t[r]).map(function(a){return[r].concat(a)})}));return e}function M(t){var e;return(e=[]).concat.apply(e,N([],O(t),!1))}function mt(t){return ve(t)?t:[t]}function W(t){return t===void 0?[]:mt(t)}function wt(t,e,r){var n,a;if(_(t))return t(e,r.data);var i={};try{for(var o=L(Object.keys(t)),u=o.next();!u.done;u=o.next()){var f=u.value,l=t[f];_(l)?i[f]=l(e,r.data):i[f]=l}}catch(v){n={error:v}}finally{try{u&&!u.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}function ur(t){return/^(done|error)\./.test(t)}function fr(t,e){var r,n,a=O([[],[]],2),i=a[0],o=a[1];try{for(var u=L(t),f=u.next();!f.done;f=u.next()){var l=f.value;e(l)?i.push(l):o.push(l)}}catch(v){r={error:v}}finally{try{f&&!f.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return[i,o]}function St(t,e){return pe(t.states,function(r,n){if(r){var a=(P(e)?void 0:e[n])||(r?r.current:void 0);if(a)return{current:a,states:St(r,a)}}})}function lr(t,e){return{current:e,states:St(t,e)}}function bt(t,e,r,n){V||K(!!t,"Attempting to update undefined context");var a=t&&r.reduce(function(i,o){var u,f,l=o.assignment,v={state:n,action:o,_event:e},w={};if(_(l))w=l(i,e.data,v);else try{for(var h=L(Object.keys(l)),d=h.next();!d.done;d=h.next()){var y=d.value,m=l[y];w[y]=_(m)?m(i,e.data,v):m}}catch(E){u={error:E}}finally{try{d&&!d.done&&(f=h.return)&&f.call(h)}finally{if(u)throw u.error}}return Object.assign({},i,w)},t);return a}var K=function(){};V||(K=function(t,e){var r=t instanceof Error?t:void 0;if(!(!r&&t)&&console!==void 0){var n=["Warning: ".concat(e)];r&&n.push(r),console.warn.apply(console,n)}});function ve(t){return Array.isArray(t)}function _(t){return typeof t=="function"}function P(t){return typeof t=="string"}function Et(t,e){if(t)return P(t)?{type:Ve,name:t,predicate:e?e[t]:void 0}:_(t)?{type:Ve,name:t.name,predicate:t}:t}var At=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();Oe={},Oe[At]=function(){return this},Oe[Symbol.observable]=function(){return this};function ie(t){return!!t&&"__xstatenode"in t}var cr=function(){var t=0;return function(){return t++,t.toString(16)}}();function xt(t,e){return P(t)||typeof t=="number"?p({type:t},e):t}function ye(t,e){if(!P(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=xt(t);return p({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function oe(t,e){var r=mt(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ie(n)?{target:n,event:t}:p(p({},n),{event:t})});return r}function dr(t){if(!(t===void 0||t===ir))return W(t)}function Ot(t,e,r,n,a){var i=t.options.guards,o={state:a,cond:e,_event:n};if(e.type===Ve)return((i==null?void 0:i[e.name])||e.predicate)(r,n.data,o);var u=i==null?void 0:i[e.type];if(!u)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return u(r,n.data,o)}function hr(t){return typeof t=="string"?{type:t}:t}function De(t,e){return"".concat(t,":invocation[").concat(e,"]")}var je=ye({type:lt});function We(t,e){return e&&e[t]||void 0}function se(t,e){var r;if(P(t)||typeof t=="number"){var n=We(t,e);_(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(_(t))r={type:t.name||t.toString(),exec:t};else{var n=We(t.type,e);if(_(n))r=p(p({},t),{exec:n});else if(n){var a=n.type||t.type;r=p(p(p({},n),t),{type:a})}else r=t}return r}var Z=function(t,e){if(!t)return[];var r=ve(t)?t:[t];return r.map(function(n){return se(n,e)})};function Re(t){var e=se(t);return p(p({id:P(t)?t:e.id},e),{type:e.type})}function Tt(t){return P(t)?{type:ae,event:t}:ee(t,{to:Q.Internal})}function Pt(t){return{type:ae,_event:ye(t.event)}}function ee(t,e){return{to:e?e.to:void 0,type:de,event:_(t)?t:xt(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:_(t)?t.name:yt(t)}}function Dt(t,e,r,n){var a={_event:r},i=ye(_(t.event)?t.event(e,r.data,a):t.event),o;if(P(t.delay)){var u=n&&n[t.delay];o=_(u)?u(e,r.data,a):u}else o=_(t.delay)?t.delay(e,r.data,a):t.delay;var f=_(t.to)?t.to(e,r.data,a):t.to;return p(p({},t),{to:f,_event:i,event:i.data,delay:o})}function Ke(t,e){return ee(t,p(p({},e),{to:Q.Parent}))}function pr(t,e,r){return ee(e,p(p({},r),{to:t}))}function vr(){return Ke(Xe)}function yr(t,e){return ee(t,p(p({},e),{to:function(r,n,a){var i=a._event;return i.origin}}))}var gr=function(t,e){return{context:t,event:e}};function mr(t,e){return t===void 0&&(t=gr),{type:ze,label:e,expr:t}}var jt=function(t,e,r){return p(p({},t),{value:P(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},Rt=function(t){return{type:ut,sendId:t}};function Ut(t){var e=Re(t);return{type:R.Start,activity:e,exec:void 0}}function Nt(t){var e=_(t)?t:Re(t);return{type:R.Stop,activity:e,exec:void 0}}function It(t,e,r){var n=_(t.activity)?t.activity(e,r.data):t.activity,a=typeof n=="string"?{id:n}:n,i={type:R.Stop,activity:a};return i}var Lt=function(t){return{type:Ae,assignment:t}};function wr(t){return typeof t=="object"&&"type"in t}function Ft(t,e){var r=e?"#".concat(e):"";return"".concat(R.After,"(").concat(t,")").concat(r)}function ge(t,e){var r="".concat(R.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Mt(t,e){var r="".concat(R.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function _t(t,e){var r="".concat(R.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Sr(t){return{type:R.Pure,get:t}}function br(t,e){if(!V&&(!t||typeof t=="function")){var r=t;t=function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var i=typeof r=="function"?r.apply(void 0,N([],O(n),!1)):r;if(!i)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return i}}return ee(function(n,a){return a},p(p({},e),{to:t}))}function Er(t,e){return Ke(function(r,n,a){return{type:ct,data:_(t)?t(r,n,a):t}},p(p({},e),{to:Q.Parent}))}function Ar(t){return{type:R.Choose,conds:t}}var xr=function(t){var e,r,n=[];try{for(var a=L(t),i=a.next();!i.done;i=a.next())for(var o=i.value,u=0;u<o.length;){if(o[u].type===Ae){n.push(o[u]),o.splice(u,1);continue}u++}}catch(f){e={error:f}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n};function Ue(t,e,r,n,a,i,o){o===void 0&&(o=!1);var u=o?[]:xr(a),f=u.length?bt(r,n,u,e):r,l=o?[r]:void 0,v=[];function w(y){var m;switch(y.type){case ae:return Pt(y);case de:var E=Dt(y,f,n,t.options.delays);return V||K(!P(y.delay)||typeof E.delay=="number","No delay reference for delay expression '".concat(y.delay,"' was found on machine '").concat(t.id,"'")),i&&E.to!==Q.Internal&&v.push(E),E;case ze:{var S=jt(y,f,n);return i==null||i(S,f,n),S}case dt:{var g=y,x=(m=g.conds.find(function(Y){var C=Et(Y.cond,t.options.guards);return!C||Ot(t,C,f,n,i?void 0:e)}))===null||m===void 0?void 0:m.actions;if(!x)return[];var F=O(Ue(t,e,f,n,[Z(W(x),t.options.actions)],i,o),2),I=F[0],$=F[1];return f=$,l==null||l.push(f),I}case ht:{var x=y.get(f,n.data);if(!x)return[];var k=O(Ue(t,e,f,n,[Z(W(x),t.options.actions)],i,o),2),B=k[0],z=k[1];return f=z,l==null||l.push(f),B}case Ge:{var S=It(y,f,n);return i==null||i(S,r,n),S}case Ae:{f=bt(f,n,[y],i?void 0:e),l==null||l.push(f);break}default:var b=se(y,t.options.actions),D=b.exec;if(i)i(b,f,n);else if(D&&l){var J=l.length-1;b=p(p({},b),{exec:function(Y){for(var C=[],re=1;re<arguments.length;re++)C[re-1]=arguments[re];D.apply(void 0,N([l[J]],O(C),!1))}})}return b}}function h(y){var m,E,S=[];try{for(var g=L(y),x=g.next();!x.done;x=g.next()){var F=x.value,I=w(F);I&&(S=S.concat(I))}}catch($){m={error:$}}finally{try{x&&!x.done&&(E=g.return)&&E.call(g)}finally{if(m)throw m.error}}return v.forEach(function($){i($,f,n)}),v.length=0,S}var d=M(a.map(h));return[d,f]}const Or=Object.freeze(Object.defineProperty({__proto__:null,actionTypes:nr,after:Ft,assign:Lt,cancel:Rt,choose:Ar,done:ge,doneInvoke:Mt,error:_t,escalate:Er,forwardTo:br,getActionFunction:We,initEvent:je,isActionObject:wr,log:mr,pure:Sr,raise:Tt,resolveActions:Ue,resolveLog:jt,resolveRaise:Pt,resolveSend:Dt,resolveStop:It,respond:yr,send:ee,sendParent:Ke,sendTo:pr,sendUpdate:vr,start:Ut,stop:Nt,toActionObject:se,toActionObjects:Z,toActivityDefinition:Re},Symbol.toStringTag,{value:"Module"}));var Ne=[],Tr=function(t,e){Ne.push(t);var r=e(t);return Ne.pop(),r},Pr=function(t){return t(Ne[Ne.length-1])};function Bt(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[At]=function(){return this},e}function Dr(t,e,r,n){var a,i=hr(t.src),o=(a=e==null?void 0:e.options.services)===null||a===void 0?void 0:a[i.type],u=t.data?wt(t.data,r,n):void 0,f=o?Ct(o,t.id,u):Bt(t.id);return f.meta=t,f}function Ct(t,e,r){var n=Bt(e);if(n.deferred=!0,ie(t)){var a=n.state=Tr(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return a}}return n}var Ie=function(t){return t.type==="atomic"||t.type==="final"};function $t(t){return Object.keys(t.states).map(function(e){return t.states[e]})}function me(t){return $t(t).filter(function(e){return e.type!=="history"})}function Ht(t){var e=[t];return Ie(t)?e:e.concat(M(me(t).map(Ht)))}function we(t,e){var r,n,a,i,o,u,f,l,v=new Set(t),w=Qe(v),h=new Set(e);try{for(var d=L(h),y=d.next();!y.done;y=d.next())for(var m=y.value,E=m.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(z){r={error:z}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(r)throw r.error}}var S=Qe(h);try{for(var g=L(h),x=g.next();!x.done;x=g.next()){var m=x.value;if(m.type==="compound"&&(!S.get(m)||!S.get(m).length))w.get(m)?w.get(m).forEach(function(b){return h.add(b)}):m.initialStateNodes.forEach(function(b){return h.add(b)});else if(m.type==="parallel")try{for(var F=(o=void 0,L(me(m))),I=F.next();!I.done;I=F.next()){var $=I.value;h.has($)||(h.add($),w.get($)?w.get($).forEach(function(b){return h.add(b)}):$.initialStateNodes.forEach(function(b){return h.add(b)}))}}catch(b){o={error:b}}finally{try{I&&!I.done&&(u=F.return)&&u.call(F)}finally{if(o)throw o.error}}}}catch(z){a={error:z}}finally{try{x&&!x.done&&(i=g.return)&&i.call(g)}finally{if(a)throw a.error}}try{for(var k=L(h),B=k.next();!B.done;B=k.next())for(var m=B.value,E=m.parent;E&&!h.has(E);)h.add(E),E=E.parent}catch(z){f={error:z}}finally{try{B&&!B.done&&(l=k.return)&&l.call(k)}finally{if(f)throw f.error}}return h}function kt(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(Ie(n))return n.key}else return{}}var a={};return r.forEach(function(i){a[i.key]=kt(i,e)}),a}function Qe(t){var e,r,n=new Map;try{for(var a=L(t),i=a.next();!i.done;i=a.next()){var o=i.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(u){e={error:u}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n}function jr(t,e){var r=we([t],e);return kt(t,Qe(r))}function Se(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Rr(t){return N([],O(new Set(M(N([],O(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Le(t,e){return e.type==="compound"?me(e).some(function(r){return r.type==="final"&&Se(t,r)}):e.type==="parallel"?me(e).every(function(r){return Le(t,r)}):!1}function Ur(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function qt(t){return new Set(M(t.map(function(e){return e.tags})))}function Gt(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(P(t)||P(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(a){return Gt(t[a],e[a])})}var te=function(){function t(e){var r=this,n;this.actions=[],this.activities=vt,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||vt,this.meta=Ur(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Rr(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=je;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=je;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),P(e))return[e];var a=Object.keys(e);return a.concat.apply(a,N([],O(a.map(function(i){return n.toStrings(e[i],r).map(function(o){return i+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=ke(e,["configuration","transitions","tags","machine"]);return p(p({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Je(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;V&&K(!!this.machine,"state.can(...) used outside of a machine-created State object; this will always return false.");var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(a){return a.target!==void 0||a.actions.length})},t}(),zt={sync:!1,autoForward:!1},Xt;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(Xt||(Xt={}));var Nr=function(t){return P(t)?p(p({},zt),{name:t}):p(p(p({},zt),{name:cr()}),t)};function Ir(t,e){var r=Nr(e);return Pr(function(n){if(!V){var a=ie(t)||_(t);K(!!n||a,'Attempted to spawn an Actor (ID: "'.concat(ie(t)?t.id:"undefined",'") outside of a service. This will have no effect.'))}return n?n.spawn(t,r.name,r):Ct(t,r.name)})}function Lr(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function Fe(t){return p(p({type:xe},t),{toJSON:function(){t.onDone,t.onError;var e=ke(t,["onDone","onError"]);return p(p({},e),{type:xe,src:Lr(t.src)})}})}var ue="",Ze="#",be="*",fe={},le=function(t){return t[0]===Ze},Fr=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Mr=function(t,e,r){var n=r.slice(0,-1).some(function(i){return!("cond"in i)&&!("in"in i)&&(P(i.target)||ie(i.target))}),a=e===ue?"the transient event":"event '".concat(e,"'");K(!n,"One or more transitions for ".concat(a," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},_r=function(){function t(e,r,n,a){n===void 0&&(n="context"in e?e.context:void 0);var i=this,o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(Fr(),r),this.parent=a==null?void 0:a.parent,this.key=this.config.key||(a==null?void 0:a.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:pt),this.id=this.config.id||N([this.machine.key],O(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,V||K(!("parallel"in this.config),'The "parallel" property is deprecated and will be removed in version 4.1. '.concat(this.config.parallel?"Replace with `type: 'parallel'`":"Use `type: '".concat(this.type,"'`")," in the config for state node '").concat(this.id,"' instead.")),this.initial=this.config.initial,this.states=this.config.states?pe(this.config.states,function(l,v){var w,h=new t(l,{},void 0,{parent:i,key:v});return Object.assign(i.idMap,p((w={},w[h.id]=h,w),h.idMap)),h}):fe;var u=0;function f(l){var v,w;l.order=u++;try{for(var h=L($t(l)),d=h.next();!d.done;d=h.next()){var y=d.value;f(y)}}catch(m){v={error:m}}finally{try{d&&!d.done&&(w=h.return)&&w.call(h)}finally{if(v)throw v.error}}}f(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(l){var v=l.event;return v===ue}):ue in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=W(this.config.entry||this.config.onEntry).map(function(l){return se(l)}),this.onExit=W(this.config.exit||this.config.onExit).map(function(l){return se(l)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=W(this.config.invoke).map(function(l,v){var w,h;if(ie(l)){var d=De(i.id,v);return i.machine.options.services=p((w={},w[d]=l,w),i.machine.options.services),Fe({src:d,id:d})}else if(P(l.src)){var d=l.id||De(i.id,v);return Fe(p(p({},l),{id:d,src:l.src}))}else if(ie(l.src)||_(l.src)){var d=l.id||De(i.id,v);return i.machine.options.services=p((h={},h[d]=l.src,h),i.machine.options.services),Fe(p(p({id:d},l),{src:d}))}else{var y=l.src;return Fe(p(p({id:De(i.id,v)},l),{src:y}))}}),this.activities=W(this.config.activities).concat(this.invoke).map(function(l){return Re(l)}),this.transition=this.transition.bind(this),this.tags=W(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Ht(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,a=n.actions,i=n.activities,o=n.guards,u=n.services,f=n.delays;return new t(this.config,{actions:p(p({},a),e.actions),activities:p(p({},i),e.activities),guards:p(p({},o),e.guards),services:p(p({},u),e.services),delays:p(p({},f),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return _(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:pe(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===ue,n=this.transitions.filter(function(a){var i=a.eventType===e;return r?i:i||a.eventType===be});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(i,o){var u=_(i)?"".concat(e.id,":delay[").concat(o,"]"):i,f=Ft(u,e.id);return e.onEntry.push(ee(f,{delay:i})),e.onExit.push(Rt(f)),f},a=ve(r)?r.map(function(i,o){var u=n(i.delay,o);return p(p({},i),{event:u})}):M(Object.keys(r).map(function(i,o){var u=r[i],f=P(u)?{target:u}:u,l=isNaN(+i)?i:+i,v=n(l,o);return W(f).map(function(w){return p(p({},w),{event:v,delay:l})})}));return a.map(function(i){var o=i.delay;return p(p({},e.formatTransition(i)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var a=e instanceof te?e.value:he(e,this.delimiter);if(P(a)){var i=this.getStateNode(a).initial;return i!==void 0?this.getStateNodes((r={},r[a]=i,r)):[this,this.states[a]]}var o=Object.keys(a),u=[this];return u.push.apply(u,N([],O(M(o.map(function(f){return n.getStateNode(f).getStateNodes(a[f])}))),!1)),u},t.prototype.handles=function(e){var r=yt(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof te?e:te.create(e),n=Array.from(we([],this.getStateNodes(r.value)));return new te(p(p({},r),{value:this.resolve(r.value),configuration:n,done:Le(n,this),tags:qt(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var a=this.getStateNode(e),i=a.next(r,n);return!i||!i.transitions.length?this.next(r,n):i},t.prototype.transitionCompoundNode=function(e,r,n){var a=Object.keys(e),i=this.getStateNode(a[0]),o=i._transition(e[a[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var a,i,o={};try{for(var u=L(Object.keys(e)),f=u.next();!f.done;f=u.next()){var l=f.value,v=e[l];if(v){var w=this.getStateNode(l),h=w._transition(v,r,n);h&&(o[l]=h)}}}catch(g){a={error:g}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(a)throw a.error}}var d=Object.keys(o).map(function(g){return o[g]}),y=M(d.map(function(g){return g.transitions})),m=d.some(function(g){return g.transitions.length>0});if(!m)return this.next(r,n);var E=M(d.map(function(g){return g.entrySet})),S=M(Object.keys(o).map(function(g){return o[g].configuration}));return{transitions:y,entrySet:E,exitSet:M(d.map(function(g){return g.exitSet})),configuration:S,source:r,actions:M(Object.keys(o).map(function(g){return o[g].actions}))}},t.prototype._transition=function(e,r,n){return P(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,ye(r))},t.prototype.next=function(e,r){var n,a,i=this,o=r.name,u=[],f=[],l;try{for(var v=L(this.getCandidates(o)),w=v.next();!w.done;w=v.next()){var h=w.value,d=h.cond,y=h.in,m=e.context,E=y?P(y)&&le(y)?e.matches(he(this.getStateNodeById(y).path,this.delimiter)):Je(he(y,this.delimiter),or(this.path.slice(0,-2))(e.value)):!0,S=!1;try{S=!d||Ot(this.machine,d,m,r,e)}catch(I){throw new Error("Unable to evaluate guard '".concat(d.name||d.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`': | ||
`).concat(I.message))}if(S&&E){h.target!==void 0&&(f=h.target),u.push.apply(u,N([],O(h.actions),!1)),l=h;break}}}catch(I){n={error:I}}finally{try{w&&!w.done&&(a=v.return)&&a.call(v)}finally{if(n)throw n.error}}if(l){if(!f.length)return{transitions:[l],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:u};var g=M(f.map(function(I){return i.getRelativeStateNodes(I,e.historyValue)})),x=!!l.internal,F=[];return x||f.forEach(function(I){F.push.apply(F,N([],O(i.getExternalReentryNodes(I)),!1))}),{transitions:[l],entrySet:F,exitSet:x?[]:[this],configuration:g,source:e,actions:u}}},t.prototype.getExternalReentryNodes=function(e){for(var r=[],n=O(e.order>this.order?[e,this]:[this,e],2),a=n[0],i=n[1];a&&a!==i;)r.push(a),a=a.parent;return a!==i?[]:(r.push(i),r)},t.prototype.getActions=function(e,r,n,a,i,o,u){var f,l,v,w,h=this,d=we([],o?this.getStateNodes(o.value):[this]);try{for(var y=L(e),m=y.next();!m.done;m=y.next()){var E=m.value;(!Se(d,E)||Se(n.entrySet,E.parent))&&n.entrySet.push(E)}}catch(b){f={error:b}}finally{try{m&&!m.done&&(l=y.return)&&l.call(y)}finally{if(f)throw f.error}}try{for(var S=L(d),g=S.next();!g.done;g=S.next()){var E=g.value;(!Se(e,E)||Se(n.exitSet,E.parent))&&n.exitSet.push(E)}}catch(b){v={error:b}}finally{try{g&&!g.done&&(w=S.return)&&w.call(S)}finally{if(v)throw v.error}}var x=M(n.entrySet.map(function(b){var D=[];if(b.type!=="final")return D;var J=b.parent;if(!J.parent)return D;D.push(ge(b.id,b.doneData),ge(J.id,b.doneData?wt(b.doneData,a,i):void 0));var Y=J.parent;return Y.type==="parallel"&&me(Y).every(function(C){return Le(n.configuration,C)})&&D.push(ge(Y.id)),D}));n.exitSet.sort(function(b,D){return D.order-b.order}),n.entrySet.sort(function(b,D){return b.order-D.order});var F=new Set(n.entrySet),I=new Set(n.exitSet),$=Array.from(F).map(function(b){var D=b.onEntry,J=b.activities.map(function(Y){return Ut(Y)});return Z(u?N(N([],O(D),!1),O(J),!1):N(N([],O(J),!1),O(D),!1),h.machine.options.actions)}).concat([x.map(Tt)]),k=Array.from(I).map(function(b){return Z(N(N([],O(b.onExit),!1),O(b.activities.map(function(D){return Nt(D)})),!1),h.machine.options.actions)}),B=k.concat([Z(n.actions,this.machine.options.actions)]).concat($);if(r){var z=Z(M(N([],O(e),!1).sort(function(b,D){return D.order-b.order}).map(function(b){return b.onExit})),this.machine.options.actions).filter(function(b){return b.type!==ae&&(b.type!==de||!!b.to&&b.to!==Q.Internal)});return B.concat([z])}return B},t.prototype.transition=function(e,r,n,a){e===void 0&&(e=this.initialState);var i=ye(r),o;if(e instanceof te)o=n===void 0?e:this.resolveState(te.from(e,n));else{var u=P(e)?this.resolve(Te(this.getResolvedPath(e))):this.resolve(e),f=n!=null?n:this.machine.context;o=this.resolveState(te.from(u,f))}if(!V&&i.name===be)throw new Error("An event cannot have the wildcard type ('".concat(be,"')"));if(this.strict&&!this.events.includes(i.name)&&!ur(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var l=this._transition(o.value,o,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:o,actions:[]},v=we([],this.getStateNodes(o.value)),w=l.configuration.length?we(v,l.configuration):v;return l.configuration=N([],O(w),!1),this.resolveTransition(l,o,o.context,a,i)},t.prototype.resolveRaisedTransition=function(e,r,n,a){var i,o=e.actions;return e=this.transition(e,r,void 0,a),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,N([],O(o),!1)),e},t.prototype.resolveTransition=function(e,r,n,a,i){var o,u,f,l,v=this;i===void 0&&(i=je);var w=e.configuration,h=!r||e.transitions.length>0,d=h?e.configuration:r?r.configuration:[],y=Le(d,this),m=h?jr(this.machine,w):void 0,E=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,S=this.getActions(new Set(d),y,e,n,i,r,a),g=r?p({},r.activities):{};try{for(var x=L(S),F=x.next();!F.done;F=x.next()){var I=F.value;try{for(var $=(f=void 0,L(I)),k=$.next();!k.done;k=$.next()){var B=k.value;B.type===qe?g[B.activity.id||B.activity.type]=B:B.type===Ge&&(g[B.activity.id||B.activity.type]=!1)}}catch(q){f={error:q}}finally{try{k&&!k.done&&(l=$.return)&&l.call($)}finally{if(f)throw f.error}}}}catch(q){o={error:q}}finally{try{F&&!F.done&&(u=x.return)&&u.call(x)}finally{if(o)throw o.error}}var z=O(Ue(this,r,n,i,S,a,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),b=z[0],D=z[1],J=O(fr(b,function(q){return q.type===ae||q.type===de&&q.to===Q.Internal}),2),Y=J[0],C=J[1],re=b.filter(function(q){var H;return q.type===qe&&((H=q.activity)===null||H===void 0?void 0:H.type)===xe}),Ee=re.reduce(function(q,H){return q[H.activity.id]=Dr(H.activity,v.machine,D,i),q},r?p({},r.children):{}),s=new te({value:m||r.value,context:D,_event:i,_sessionid:r?r._sessionid:null,historyValue:m?E?lr(E,m):void 0:r?r.historyValue:void 0,history:!m||e.source?r:void 0,actions:m?C:[],activities:m?g:r?r.activities:{},events:[],configuration:d,transitions:e.transitions,children:Ee,done:y,tags:qt(d),machine:this}),c=n!==D;s.changed=i.name===Xe||c;var A=s.history;A&&delete A.history;var U=!y&&(this._transient||w.some(function(q){return q._transient}));if(!h&&(!U||i.name===ue))return s;var T=s;if(!y)for(U&&(T=this.resolveRaisedTransition(T,{type:ft},i,a));Y.length;){var j=Y.shift();T=this.resolveRaisedTransition(T,j._event,i,a)}var ce=T.changed||(A?!!T.actions.length||c||typeof A.value!=typeof T.value||!Gt(T.value,A.value):void 0);return T.changed=ce,T.history=A,T},t.prototype.getStateNode=function(e){if(le(e))return this.machine.getStateNodeById(e);if(!this.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[e];if(!r)throw new Error("Child state '".concat(e,"' does not exist on '").concat(this.id,"'"));return r},t.prototype.getStateNodeById=function(e){var r=le(e)?e.slice(Ze.length):e;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(e){if(typeof e=="string"&&le(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=Ye(e,this.delimiter).slice(),n=this;r.length;){var a=r.shift();if(!a.length)break;n=n.getStateNode(a)}return n},t.prototype.resolve=function(e){var r,n=this;if(!e)return this.initialStateValue||fe;switch(this.type){case"parallel":return pe(this.initialStateValue,function(i,o){return i?n.getStateNode(o).resolve(e[o]||i):fe});case"compound":if(P(e)){var a=this.getStateNode(e);return a.type==="parallel"||a.type==="compound"?(r={},r[e]=a.initialStateValue,r):e}return Object.keys(e).length?pe(e,function(i,o){return i?n.getStateNode(o).resolve(i):fe}):this.initialStateValue||{};default:return e||fe}},t.prototype.getResolvedPath=function(e){if(le(e)){var r=this.machine.idMap[e.slice(Ze.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return Ye(e,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=gt(this.states,function(n){return n.initialStateValue||fe},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=Ie(this.states[this.initial])?this.initial:(e={},e[this.initial]=this.states[this.initial].initialStateValue,e)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(e,r){this._init();var n=this.getStateNodes(e);return this.resolveTransition({configuration:n,entrySet:N([],O(n),!1),exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r!=null?r:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var e;if(this.type==="history"){var r=this.config;P(r.target)?e=le(r.target)?Te(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:e=r.target}return e},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(e,r,n){return n===void 0&&(n=!0),n?e.type==="history"?e.resolveHistory(r):e.initialStateNodes:[e]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var e=this;if(Ie(this))return[this];if(this.type==="compound"&&!this.initial)return V||K(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Pe(this.initialStateValue);return M(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=O(e),n=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var i=this.getStateNode(n);if(i.type==="history")return i.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(a)},t.prototype.historyValue=function(e){if(Object.keys(this.states).length)return{current:e||this.initialStateValue,states:gt(this.states,function(r,n){if(!e)return r.historyValue();var a=P(e)?void 0:e[n];return r.historyValue(a||r.initialStateValue)},function(r){return!r.history})}},t.prototype.resolveHistory=function(e){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!e){var a=this.target;return a?M(Pe(a).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var i=sr(n.path,"states")(e).current;return P(i)?[n.getStateNode(i)]:M(Pe(i).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=M(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,a;if(this.__cache.events)return this.__cache.events;var i=this.states,o=new Set(this.ownEvents);if(i)try{for(var u=L(Object.keys(i)),f=u.next();!f.done;f=u.next()){var l=f.value,v=i[l];if(v.states)try{for(var w=(n=void 0,L(v.events)),h=w.next();!h.done;h=w.next()){var d=h.value;o.add("".concat(d))}}catch(y){n={error:y}}finally{try{h&&!h.done&&(a=w.return)&&a.call(w)}finally{if(n)throw n.error}}}}catch(y){e={error:y}}finally{try{f&&!f.done&&(r=u.return)&&r.call(u)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!P(n))return n;var a=n[0]===r.delimiter;if(a&&!r.parent)return r.getStateNodeByPath(n.slice(1));var i=a?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(i);return o}catch(u){throw new Error("Invalid transition definition for state node '".concat(r.id,`': | ||
`).concat(u.message))}else return r.getStateNodeByPath(i)})},t.prototype.formatTransition=function(e){var r=this,n=dr(e.target),a="internal"in e?e.internal:n?n.some(function(f){return P(f)&&f[0]===r.delimiter}):!0,i=this.machine.options.guards,o=this.resolveTarget(n),u=p(p({},e),{actions:Z(W(e.actions)),cond:Et(e.cond,i),target:o,source:this,internal:a,eventType:e.event,toJSON:function(){return p(p({},u),{target:u.target?u.target.map(function(f){return"#".concat(f.id)}):void 0,source:"#".concat(r.id)})}});return u},t.prototype.formatTransitions=function(){var e,r,n=this,a;if(!this.config.on)a=[];else if(Array.isArray(this.config.on))a=this.config.on;else{var i=this.config.on,o=be,u=i[o],f=u===void 0?[]:u,l=ke(i,[typeof o=="symbol"?o:o+""]);a=M(Object.keys(l).map(function(g){!V&&g===ue&&K(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var x=oe(g,l[g]);return V||Mr(n,g,x),x}).concat(oe(be,f)))}var v=this.config.always?oe("",this.config.always):[],w=this.config.onDone?oe(String(ge(this.id)),this.config.onDone):[];V||K(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var h=M(this.invoke.map(function(g){var x=[];return g.onDone&&x.push.apply(x,N([],O(oe(String(Mt(g.id)),g.onDone)),!1)),g.onError&&x.push.apply(x,N([],O(oe(String(_t(g.id)),g.onError)),!1)),x})),d=this.after,y=M(N(N(N(N([],O(w),!1),O(h),!1),O(a),!1),O(v),!1).map(function(g){return W(g).map(function(x){return n.formatTransition(x)})}));try{for(var m=L(d),E=m.next();!E.done;E=m.next()){var S=E.value;y.push(S)}}catch(g){e={error:g}}finally{try{E&&!E.done&&(r=m.return)&&r.call(m)}finally{if(e)throw e.error}}return y},t}(),Vt=!1;function Jt(t,e){return!V&&!t.predictableActionArguments&&!Vt&&(Vt=!0,console.warn("It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html")),new _r(t,e)}var G=Lt,et=ee;const Me={progress:null,loaded:0,error:null,bucketId:void 0,file:void 0,id:void 0},Yt=()=>Jt({predictableActionArguments:!0,schema:{context:{},events:{}},tsTypes:{},context:{...Me},initial:"idle",on:{DESTROY:{actions:"sendDestroy",target:"stopped"}},states:{idle:{on:{ADD:{actions:"addFile"},UPLOAD:{cond:"hasFile",target:"uploading"}}},uploading:{entry:"resetProgress",on:{UPLOAD_PROGRESS:{actions:["incrementProgress","sendProgress"]},UPLOAD_DONE:"uploaded",UPLOAD_ERROR:"error",CANCEL:"idle"},invoke:{src:"uploadFile"}},uploaded:{entry:["setFileMetadata","sendDone"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},error:{entry:["setError","sendError"],on:{ADD:{actions:"addFile",target:"idle"},UPLOAD:{actions:"resetContext",target:"uploading"}}},stopped:{type:"final"}}},{guards:{hasFile:(t,e)=>!!t.file||!!e.file},actions:{incrementProgress:G({loaded:(t,{loaded:e})=>e,progress:(t,{progress:e})=>e}),setFileMetadata:G({id:(t,{id:e})=>e,bucketId:(t,{bucketId:e})=>e,progress:t=>100}),setError:G({error:(t,{error:e})=>e}),sendProgress:()=>{},sendError:()=>{},sendDestroy:()=>{},sendDone:()=>{},resetProgress:G({progress:t=>null,loaded:t=>0}),resetContext:G(t=>Me),addFile:G({file:(t,{file:e})=>e,bucketId:(t,{bucketId:e})=>e,id:(t,{id:e})=>e})},services:{uploadFile:(t,e)=>r=>{const n=e.file||t.file,a=new it;a.append("file[]",n);let i=0;return $e(e.url,a,{fileId:e.id||t.id,bucketId:e.bucketId||t.bucketId,accessToken:e.accessToken,adminSecret:e.adminSecret,name:e.name||n.name,onUploadProgress:o=>{const u=o.total?Math.round(o.loaded*n.size/o.total):0,f=u-i;i=u,r({type:"UPLOAD_PROGRESS",progress:o.total?Math.round(u*100/o.total):0,loaded:u,additions:f})}}).then(({fileMetadata:o,error:u})=>{if(u&&r({type:"UPLOAD_ERROR",error:u}),o&&!("processedFiles"in o)){const{id:f,bucketId:l}=o;r({type:"UPLOAD_DONE",id:f,bucketId:l})}if(o&&"processedFiles"in o){const{id:f,bucketId:l}=o.processedFiles[0];r({type:"UPLOAD_DONE",id:f,bucketId:l})}}),()=>{}}}}),{pure:tt,sendParent:_e}=Or,Br=()=>Jt({id:"files-list",schema:{context:{},events:{}},tsTypes:{},predictableActionArguments:!0,context:{progress:null,files:[],loaded:0,total:0},initial:"idle",on:{UPLOAD:{cond:"hasFileToDownload",actions:"addItem",target:"uploading"},ADD:{actions:"addItem"},REMOVE:{actions:"removeItem"}},states:{idle:{entry:["resetProgress","resetLoaded","resetTotal"],on:{CLEAR:{actions:"clearList",target:"idle"}}},uploading:{entry:["upload","startProgress","resetLoaded","resetTotal"],on:{UPLOAD_PROGRESS:{actions:["incrementProgress"]},UPLOAD_DONE:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],UPLOAD_ERROR:[{cond:"isAllUploaded",target:"uploaded"},{cond:"isAllUploadedOrError",target:"error"}],CANCEL:{actions:"cancel",target:"idle"}}},uploaded:{entry:"setUploaded",on:{CLEAR:{actions:"clearList",target:"idle"}}},error:{on:{CLEAR:{actions:"clearList",target:"idle"}}}}},{guards:{hasFileToDownload:(t,e)=>t.files.some(r=>r.getSnapshot().matches("idle"))||!!e.files,isAllUploaded:t=>t.files.every(e=>{var r;return(r=e.getSnapshot())==null?void 0:r.matches("uploaded")}),isAllUploadedOrError:t=>t.files.every(e=>{const r=e.getSnapshot();return(r==null?void 0:r.matches("error"))||(r==null?void 0:r.matches("uploaded"))})},actions:{incrementProgress:G((t,e)=>{const r=t.loaded+e.additions,n=Math.round(r*100/t.total);return{...t,loaded:r,progress:n}}),setUploaded:G({progress:t=>100,loaded:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>e.matches("uploaded")).reduce((e,r)=>{var n;return e+((n=r.context.file)==null?void 0:n.size)},0)}),resetTotal:G({total:({files:t})=>t.map(e=>e.getSnapshot()).filter(e=>!e.matches("uploaded")).reduce((e,r)=>{var n;return e+((n=r.context.file)==null?void 0:n.size)},0)}),resetLoaded:G({loaded:t=>0}),startProgress:G({progress:t=>0}),resetProgress:G({progress:t=>null}),addItem:G((t,{files:e,bucketId:r})=>{const n=e?Array.isArray(e)?e:"item"in e?Array.from(e):[e]:[],a=t.total+n.reduce((o,u)=>o+u.size,0),i=Math.round(t.loaded*100/a);return{files:[...t.files,...n.map(o=>Ir(Yt().withConfig({actions:{sendProgress:_e((u,{additions:f})=>({type:"UPLOAD_PROGRESS",additions:f})),sendDone:_e("UPLOAD_DONE"),sendError:_e("UPLOAD_ERROR"),sendDestroy:_e("REMOVE")}}).withContext({...Me,file:o,bucketId:r}),{sync:!0}))],total:a,loaded:t.loaded,progress:i}}),removeItem:G({files:t=>t.files.filter(e=>{var n,a;const r=(n=e.getSnapshot())==null?void 0:n.matches("stopped");return r&&((a=e.stop)==null||a.call(e)),!r})}),clearList:tt(t=>t.files.map(e=>et({type:"DESTROY"},{to:e.id}))),upload:tt((t,e)=>t.files.map(r=>et(e,{to:r.id}))),cancel:tt(t=>t.files.map(e=>et({type:"CANCEL"},{to:e.id})))}}),Cr=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t}),e.subscribe(n=>{var a;n.matches("error")?r({error:n.context.error,isError:!0,isUploaded:!1}):n.matches("uploaded")&&r({error:null,isError:!1,isUploaded:!0,id:n.context.id,bucketId:n.context.id,name:(a=n.context.file)==null?void 0:a.name})})}),$r=async(t,e)=>new Promise(r=>{e.send({type:"UPLOAD",...t,files:t.files}),e.onTransition(n=>{n.matches("error")?r({errors:n.context.files.filter(a=>{var i;return(i=a.getSnapshot())==null?void 0:i.context.error}),isError:!0,files:[]}):n.matches("uploaded")&&r({errors:[],isError:!1,files:n.context.files})})});X.HasuraStorageApi=st,X.HasuraStorageClient=Qt,X.INITIAL_FILE_CONTEXT=Me,X.appendImageTransformationParameters=He,X.createFileUploadMachine=Yt,X.createMultipleFilesUploadMachine=Br,X.uploadFilePromise=Cr,X.uploadMultipleFilesPromise=$r,Object.defineProperty(X,Symbol.toStringTag,{value:"Module"})}); | ||
//# sourceMappingURL=hasura-storage-js.umd.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
528277
1496