diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 382df1c..e00d3b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - node-version: [12.x, 14.x, 16.x, 17.x, 18.x] + node-version: [12.x, 14.x, 16.x, 18.x, 20.x] steps: - uses: actions/checkout@v2 diff --git a/src/engine/flow-manager.ts b/src/engine/flow-manager.ts index cb5e74d..8583528 100644 --- a/src/engine/flow-manager.ts +++ b/src/engine/flow-manager.ts @@ -100,8 +100,8 @@ export class FlowManager { let error; if (statusCode !== 200) { error = new Error(`Request failed with status code: ${statusCode}`); - } else if (!(/^application\/json/.test(contentType) || /^text\/plain/.test(contentType))) { - error = new Error(`Invalid content-type. Expected application/json or text/plain but received ${contentType}`); + } else if (!(contentType.startsWith('application/json') || contentType.startsWith('text/plain'))) { + error = new Error(`Invalid content-type: Expected 'application/json' or 'text/plain' but received '${contentType}'`); } if (error) { diff --git a/src/engine/flow-state/flow-state.ts b/src/engine/flow-state/flow-state.ts index 9e8b9c9..434cc71 100644 --- a/src/engine/flow-state/flow-state.ts +++ b/src/engine/flow-state/flow-state.ts @@ -345,7 +345,9 @@ export abstract class FlowState implements IFlow { this.runStatus.state.postProcessFinished(error, stopFlowExecutionOnError); } - protected postProcessFinished(_error: Error | boolean, _stopFlowExecutionOnError: boolean): void {} + protected postProcessFinished(_error: Error | boolean, _stopFlowExecutionOnError: boolean): void { + // Default empty implementation to be overridden when applies. + } protected createTransitionError(transition: string): Error { return new Error(`Cannot execute transition ${transition} in current state ${this.getStateCode()}.`); diff --git a/src/engine/task-process.ts b/src/engine/task-process.ts index 7306e8e..79f3bfa 100644 --- a/src/engine/task-process.ts +++ b/src/engine/task-process.ts @@ -38,7 +38,7 @@ export class TaskProcess { let resolverFn = this.taskResolverExecutor as TaskResolverFn; let resolverThis: TaskResolverClass | undefined = undefined; - const isClassResolver = this.taskResolverExecutor.prototype && this.taskResolverExecutor.prototype.exec; + const isClassResolver = this.taskResolverExecutor.prototype?.exec; if (isClassResolver) { // @todo try to remove type casts in this code section const resolverInstance = new (this.taskResolverExecutor as TaskResolverClass)(); @@ -68,7 +68,7 @@ export class TaskProcess { // @sonar end-ignore const resultIsObject = typeof resolverResult === 'object'; - const resultIsPromise = resolverResult && resolverResult.constructor && resolverResult.constructor.name === 'Promise'; + const resultIsPromise = resolverResult?.constructor?.name === 'Promise'; if (!resultIsObject) { throw new Error( diff --git a/src/engine/task.ts b/src/engine/task.ts index 7f33547..ed6b719 100644 --- a/src/engine/task.ts +++ b/src/engine/task.ts @@ -81,26 +81,19 @@ export class Task { for (const [resolverParamName, paramSolvingInfo] of Object.entries(resolverParams)) { // @todo Add test to check the case when a loop round does not set anything and make sure next value (`paramValue`) is undefined by default - // If it is string, it is a task param name if (typeof paramSolvingInfo === 'string') { - const taskParamName = paramSolvingInfo; - paramValue = solvedReqs[taskParamName]; - } - - // If it is an object, expect the format { [value: ], [transform: ] } - else { - // Implicit case: if (typeof paramSolvingInfo === 'object' && paramSolvingInfo !== null) + // If it is string, it is a task param name + paramValue = solvedReqs[paramSolvingInfo]; + } else if (Object.prototype.hasOwnProperty.call(paramSolvingInfo, 'value')) { + // If it is an object, expect the format { value: } or { transform: } + // Implicit condition: typeof paramSolvingInfo === 'object' && paramSolvingInfo !== null // Direct value pre-processor - if (Object.prototype.hasOwnProperty.call(paramSolvingInfo, 'value')) { - paramValue = (paramSolvingInfo as ResolverParamInfoValue).value; - } - + paramValue = (paramSolvingInfo as ResolverParamInfoValue).value; + } else { // Template transform pre-processor - else { - // Implicit case: if (paramSolvingInfo.hasOwnProperty('transform')) - const template = (paramSolvingInfo as ResolverParamInfoTransform).transform; - paramValue = ST.select(solvedReqs).transformWith(template).root(); - } + // Implicit condition: paramSolvingInfo.hasOwnProperty('transform') + const template = (paramSolvingInfo as ResolverParamInfoTransform).transform; + paramValue = ST.select(solvedReqs).transformWith(template).root(); } params[resolverParamName] = paramValue; @@ -120,7 +113,7 @@ export class Task { const results: ValueMap = {}; - let resolverResults = (this.spec.resolver ?? {}).results ?? {}; + let resolverResults = this.spec.resolver?.results ?? {}; if (automap) { const provides = this.spec.provides ?? []; diff --git a/test/load-from-url.ts b/test/load-from-url.ts index 49eaf0e..db98897 100644 --- a/test/load-from-url.ts +++ b/test/load-from-url.ts @@ -83,7 +83,7 @@ describe('can run a flow', function () { throw new Error('An error should have been thrown'); } catch (err) { expect((err as Error).message).to.be.eql( - 'Invalid content-type. Expected application/json or text/plain but received some-unknown/content-format', + "Invalid content-type: Expected 'application/json' or 'text/plain' but received 'some-unknown/content-format'", ); } }); diff --git a/web/flowed.js b/web/flowed.js index 12e7b85..a3fb5ec 100644 --- a/web/flowed.js +++ b/web/flowed.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Flowed=t():e.Flowed=t()}(self,(function(){return e={865:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(227),o={};t.default=e=>{let t=o[e];return void 0===t&&(t=(0,r.default)(`flowed:${e}`),o[e]=t),t}},155:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowManager=void 0;const r=s(673),o=s(883),n=s(316),i=s(167);class a{static run(e,t={},s=[],r={},o={},n={}){return new i.Flow(e).start(t,s,r,o,n)}static runFromString(e,t={},s=[],r={},o={},n={}){return new Promise(((i,u)=>{try{const l=JSON.parse(e);a.run(l,t,s,r,o,n).then(i,u)}catch(e){u(e)}}))}static runFromFile(e,t={},s=[],o={},n={},i={}){return new Promise(((u,l)=>{(0,r.readFile)(e,"utf8",((e,r)=>{e?l(e):a.runFromString(r,t,s,o,n,i).then(u,l)}))}))}static runFromUrl(e,t={},s=[],r={},i={},u={}){let l=null;if(e.startsWith("http://")?l=o:e.startsWith("https://")&&(l=n),null===l){let t=null;const s=e.match(/^([a-zA-Z]+):/);return Array.isArray(s)&&2===s.length?(t=s[1],Promise.reject(new Error(`Protocol not supported: ${t}. Supported protocols are: [http, https]`))):Promise.reject(new Error(`Invalid URL: ${e}`))}return new Promise(((o,n)=>{l.get(e,(e=>{var l;const{statusCode:c}=e,d=null!==(l=e.headers["content-type"])&&void 0!==l?l:"application/json";let p;if(200!==c?p=new Error(`Request failed with status code: ${c}`):/^application\/json/.test(d)||/^text\/plain/.test(d)||(p=new Error(`Invalid content-type. Expected application/json or text/plain but received ${d}`)),p)n(p);else{e.setEncoding("utf8");let l="";e.on("data",(e=>{l+=e})),e.on("end",(()=>{a.runFromString(l,t,s,r,i,u).then(o,n)}))}})).on("error",(e=>{n(e)}))}))}static installPlugin(e){if(e.resolverLibrary)for(const[t,s]of Object.entries(e.resolverLibrary))this.plugins.resolvers[t]=s}static installLogger(e){this.logger=e}static log(e){null!==a.logger&&a.logger.log(e)}}t.FlowManager=a,a.plugins={resolvers:{}},a.logger=null},875:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowRunStatus=void 0;const r=s(985),o=s(871),n=s(851),i=s(413);class a{constructor(e,t,s){this.tasksReady=[],this.tasksByReq={},this.resolvers={},this.expectedResults=[],this.results={},this.context={},this.runOptions={},this.flow=e,this.processManager=new n.ProcessManager,this.id=a.nextId,a.nextId=(a.nextId+1)%Number.MAX_SAFE_INTEGER,this.states={Ready:new o.FlowReady(this),Running:new o.FlowRunning(this),Finished:new o.FlowFinished(this),Pausing:new o.FlowPausing(this),Paused:new o.FlowPaused(this),Stopping:new o.FlowStopping(this),Stopped:new o.FlowStopped(this)},this.state=this.states[r.FlowStateEnum.Ready],this.initRunStatus(t,s)}initRunStatus(e,t){var s,r,o,n,a;this.spec=e,this.tasks={};const u=[];for(const[e,t]of Object.entries(null!==(s=this.spec.tasks)&&void 0!==s?s:{}))u.push(...null!==(r=t.provides)&&void 0!==r?r:[]),this.tasks[e]=new i.Task(e,t);this.taskProvisions=Array.from(new Set(u)),this.options=Object.assign({},null!==(o=this.spec.configs)&&void 0!==o?o:{},null!==(n=this.spec.options)&&void 0!==n?n:{}),Object.prototype.hasOwnProperty.call(this.spec,"configs")&&this.flow.log({m:"DEPRECATED: 'configs' field in flow spec. Use 'options' instead.",l:"w"}),this.tasksByReq={},this.tasksReady=[];for(const e of Object.values(this.tasks)){e.resetRunStatus(),e.isReadyToRun()&&this.tasksReady.push(e);const t=null!==(a=e.spec.requires)&&void 0!==a?a:[];for(const s of t)void 0===this.tasksByReq[s]&&(this.tasksByReq[s]={}),this.tasksByReq[s][e.code]=e}this.results={},t&&this.fromSerializable(t)}fromSerializable(e){this.id=e.id,this.processManager.nextProcessId=e.nextProcessId,this.processManager.processes=[],this.tasksReady=e.tasksReady.map((e=>this.tasks[e])),this.tasksByReq={};for(const[t,s]of Object.entries(e.tasksByReq))this.tasksByReq[t]=s.reduce(((e,t)=>(e[t]=this.tasks[t],e)),{});this.taskProvisions=JSON.parse(JSON.stringify(e.taskProvisions)),this.expectedResults=JSON.parse(JSON.stringify(e.expectedResults)),this.results=JSON.parse(JSON.stringify(e.results)),this.context=JSON.parse(JSON.stringify(e.context)),this.options=JSON.parse(JSON.stringify(e.options));for(const[t,s]of Object.entries(e.taskStatuses))this.tasks[t].setSerializableState(s)}toSerializable(){const e={id:this.id,nextProcessId:this.processManager.nextProcessId,tasksReady:this.tasksReady.map((e=>e.code)),tasksByReq:{},taskProvisions:JSON.parse(JSON.stringify(this.taskProvisions)),expectedResults:JSON.parse(JSON.stringify(this.expectedResults)),results:JSON.parse(JSON.stringify(this.results)),context:{},options:JSON.parse(JSON.stringify(this.options)),taskStatuses:{}},t=Object.assign({},this.context);delete t.$flowed,e.context=JSON.parse(JSON.stringify(t));for(const[t,s]of Object.entries(this.tasksByReq))e.tasksByReq[t]=Object.keys(s);for(const[t,s]of Object.entries(this.tasks))e.taskStatuses[t]=JSON.parse(JSON.stringify(s.getSerializableState()));return e}}t.FlowRunStatus=a,a.nextId=1},389:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowFinished=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Finished}reset(){this.setState(o.FlowStateEnum.Ready),this.runStatus.initRunStatus(this.runStatus.spec)}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowFinished=n},578:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowPaused=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Paused}resume(){return this.setState(o.FlowStateEnum.Running),this.createFinishPromise(),this.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(),this.runStatus.finishPromise}stop(){return this.setState(o.FlowStateEnum.Stopping),Promise.resolve(this.getResults())}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowPaused=n},547:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowPausing=void 0;const r=s(985),o=s(823);class n extends o.FlowState{getStateCode(){return r.FlowStateEnum.Pausing}paused(e){this.setState(r.FlowStateEnum.Paused),e?(this.log({n:this.runStatus.id,m:"Flow paused with error.",e:"FP"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow paused.",e:"FP"}),this.execFinishResolve())}postProcessFinished(e,t){this.runStatus.state.paused(e)}}t.FlowPausing=n},106:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowReady=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Ready}start(e,t,s,r,n={}){return this.setRunOptions(n),this.log({n:this.runStatus.id,m:"Flow started with params: %O",mp:e,e:"FS"}),this.setState(o.FlowStateEnum.Running),this.setExpectedResults([...t]),this.setResolvers(s),this.setContext(r),this.supplyParameters(e),this.createFinishPromise(),this.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(),this.runStatus.finishPromise}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowReady=n},873:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowRunning=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Running}pause(){return this.setState(o.FlowStateEnum.Pausing),this.runStatus.finishPromise}stop(){return this.setState(o.FlowStateEnum.Stopping),this.runStatus.finishPromise}finished(e=!1){this.setState(o.FlowStateEnum.Finished),e?(this.log({n:this.runStatus.id,m:"Flow finished with error. Results: %O",mp:this.getResults(),l:"e",e:"FF"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow finished with results: %O",mp:this.getResults(),e:"FF"}),this.execFinishResolve())}postProcessFinished(e,t){e&&t||this.runStatus.state.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(e)}}t.FlowRunning=n},823:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowState=void 0;const r=s(865),o=s(582),n=s(985),i=s(155);class a{constructor(e){this.runStatus=e}start(e,t,s,r,o={}){throw this.createTransitionError(n.FlowTransitionEnum.Start)}finished(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Finished)}pause(){throw this.createTransitionError(n.FlowTransitionEnum.Pause)}paused(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Paused)}resume(){throw this.createTransitionError(n.FlowTransitionEnum.Resume)}stop(){throw this.createTransitionError(n.FlowTransitionEnum.Stop)}stopped(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Stopped)}reset(){throw this.createTransitionError(n.FlowTransitionEnum.Reset)}execFinishResolve(){this.runStatus.finishResolve(this.runStatus.results)}execFinishReject(e){this.runStatus.finishReject(e)}isRunning(){return this.runStatus.processManager.runningCount()>0}setExpectedResults(e){const t=e.filter((e=>!this.runStatus.taskProvisions.includes(e)));if(t.length>0){const e=`The results [${t.join(", ")}] are not provided by any task`;if(this.runStatus.options.throwErrorOnUnsolvableResult)throw new Error(e);this.log({m:e,l:"w"})}this.runStatus.expectedResults=[...e]}getResults(){return this.runStatus.results}setResolvers(e){this.runStatus.resolvers=e}setContext(e){this.runStatus.context=Object.assign({$flowed:{getResolverByName:this.getResolverByName.bind(this),getResolvers:this.getResolvers.bind(this),processManager:this.runStatus.processManager,flow:this.runStatus.flow}},e)}setRunOptions(e){this.runStatus.runOptions=Object.assign({debugKey:"flow",instanceId:null,logFields:{}},e)}supplyParameters(e){for(const[t,s]of Object.entries(e))this.runStatus.state.supplyResult(t,s)}createFinishPromise(){this.runStatus.finishPromise=new Promise(((e,t)=>{this.runStatus.finishResolve=e,this.runStatus.finishReject=t}))}getResolverForTask(e){const t=e.getResolverName(),s=this.getResolverByName(t);if(null===s)throw new Error(`Task resolver '${t}' for task '${e.code}' has no definition. Defined custom resolvers are: [${Object.keys(this.runStatus.resolvers).join(", ")}].`);return s}getResolverByName(e){const t=this.runStatus.resolvers;return void 0!==t[e]?t[e]:void 0!==i.FlowManager.plugins.resolvers[e]?i.FlowManager.plugins.resolvers[e]:void 0!==a.builtInResolvers[e]?a.builtInResolvers[e]:null}getResolvers(){const e=this.runStatus.resolvers,t=i.FlowManager.plugins.resolvers,s=a.builtInResolvers;return Object.assign(Object.assign(Object.assign({},s),t),e)}supplyResult(e,t){if(void 0!==this.runStatus.tasksByReq[e]){const s=this.runStatus.tasksByReq[e],r=Object.keys(s);for(const o of r){const r=s[o];r.supplyReq(e,t),r.isReadyToRun()&&this.runStatus.tasksReady.push(r)}}this.runStatus.expectedResults.indexOf(e)>-1&&(this.runStatus.results[e]=t)}getStateInstance(e){return this.runStatus.states[e]}startReadyTasks(){const e=this.runStatus.tasksReady;this.runStatus.tasksReady=[];for(const t of e){const e=this.runStatus.state.getResolverForTask(t),s=this.runStatus.processManager.createProcess(t,e,this.runStatus.context,!!this.runStatus.options.resolverAutomapParams,!!this.runStatus.options.resolverAutomapResults,this.runStatus.id,this.debug,this.log.bind(this)),r=e=>{this.processFinished(s,e,!0)};s.run().then((()=>{this.processFinished(s,!1,!0)}),r).catch(r),this.log({n:this.runStatus.id,m:`Task '${t.code}(${t.getResolverName()})' started, params: %O`,mp:s.getParams(),e:"TS",pid:s.pid,task:{code:t.code,type:t.getResolverName()}})}}setState(e){const t=this.runStatus.state.getStateCode();this.runStatus.state=this.getStateInstance(e),this.log({n:this.runStatus.id,m:`Changed flow state from '${t}' to '${e}'`,l:"d",e:"FC"})}getSerializableState(){throw this.createMethodError("getSerializableState")}processFinished(e,t,s){var r;this.runStatus.processManager.removeProcess(e);const o=e.task,n=o.code,i=o.spec,a=null!==(r=i.provides)&&void 0!==r?r:[],u=o.getResults(),l=Object.prototype.hasOwnProperty.call(i,"defaultResult");t?this.log({n:this.runStatus.id,m:`Error in task '${n}', results: %O`,mp:u,l:"e",e:"TF",pid:e.pid,task:{code:o.code,type:o.getResolverName()}}):this.log({n:this.runStatus.id,m:`Finished task '${n}', results: %O`,mp:u,e:"TF",pid:e.pid,task:{code:o.code,type:o.getResolverName()}});for(const e of a)Object.prototype.hasOwnProperty.call(u,e)?this.runStatus.state.supplyResult(e,u[e]):l?this.runStatus.state.supplyResult(e,i.defaultResult):this.log({n:this.runStatus.id,m:`Expected value '${e}' was not provided by task '${n}' with resolver '${o.getResolverName()}'. Consider using the task field 'defaultResult' to provide values by default.`,l:"w"});this.runStatus.state.postProcessFinished(t,s)}postProcessFinished(e,t){}createTransitionError(e){return new Error(`Cannot execute transition ${e} in current state ${this.getStateCode()}.`)}createMethodError(e){return new Error(`Cannot execute method ${e} in current state ${this.getStateCode()}.`)}debug(e,...t){const s=(null==this?void 0:this.runStatus)&&"string"==typeof this.runStatus.runOptions.debugKey?this.runStatus.runOptions.debugKey:"init";(0,r.default)(s)(e,...t)}static formatDebugMessage({n:e,m:t,l:s,e:r}){var o;const n="w"===s?"⚠️ ":"";let i=null!==(o={FS:"▶ ",FF:"✔ ",TS:" ‣ ",TF:" ✓ ",FC:" ⓘ ",FT:"◼ ",FP:"⏸ "}[r||""])&&void 0!==o?o:"";return"TF"===r&&["e","f"].includes(s||"")?i=" ✗":"FF"===r&&["e","f"].includes(s||"")&&(i="✘"),`[${e}] ${n+i}${t}`}static createLogEntry({n:e,m:t,mp:s,l:r,e:o,pid:n,task:i},a){let u={level:(e=>{switch(e=e||"i"){case"e":return"error";case"w":return"warning";case"i":return"info";case"d":return"debug";default:throw new Error(`Not supported error level: "${e}"`)}})(r),eventType:(e=>{switch(e){case"TS":return"Task.Started";case"TF":return"Task.Finished";case"FC":return"Flow.StateChanged";case"FS":return"Flow.Started";case"FF":return"Flow.Finished";case"FT":return"Flow.Stopped";case"FP":return"Flow.Paused";default:return"General"}})(o),message:((e,t)=>{if(t){const s=JSON.stringify(t);return e.replace("%O",s.length>100?s.slice(0,97)+"...":s)}return e})(t,s),timestamp:new Date,extra:{pid:n,task:i,debugId:e,values:JSON.stringify(s)}};return a&&(u.objectId=a.runOptions.instanceId,u=Object.assign(a.runOptions.logFields,u)),u}log({n:e,m:t,mp:s,l:r,e:o,pid:n,task:u}){this.debug(a.formatDebugMessage({n:e,m:t,mp:s,l:r,e:o}),[s]),i.FlowManager.log(a.createLogEntry({n:e,m:t,mp:s,l:r,e:o,pid:n,task:u},this.runStatus))}}t.FlowState=a,a.builtInResolvers={"flowed::Noop":o.NoopResolver,"flowed::Echo":o.EchoResolver,"flowed::ThrowError":o.ThrowErrorResolver,"flowed::Conditional":o.ConditionalResolver,"flowed::Wait":o.WaitResolver,"flowed::SubFlow":o.SubFlowResolver,"flowed::Repeater":o.RepeaterResolver,"flowed::Loop":o.LoopResolver,"flowed::ArrayMap":o.ArrayMapResolver,"flowed::Stop":o.StopResolver,"flowed::Pause":o.PauseResolver}},784:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowStopped=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Stopped}reset(){this.setState(o.FlowStateEnum.Ready),this.runStatus.initRunStatus(this.runStatus.spec)}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowStopped=n},17:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowStopping=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Stopping}stopped(e=!1){this.setState(o.FlowStateEnum.Stopped),e?(this.log({n:this.runStatus.id,m:"Flow stopped with error.",e:"FT"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow stopped.",e:"FT"}),this.execFinishResolve())}postProcessFinished(e,t){this.runStatus.state.stopped(e)}}t.FlowStopping=n},871:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(823),t),o(s(106),t),o(s(389),t),o(s(578),t),o(s(547),t),o(s(873),t),o(s(784),t),o(s(17),t)},167:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Flow=void 0;const r=s(875),o=s(865),n=s(155),i=s(871);t.Flow=class{constructor(e,t){this.runStatus=new r.FlowRunStatus(this,null!=e?e:{},t)}getStateCode(){return this.runStatus.state.getStateCode()}start(e={},t=[],s={},r={},o={}){return this.runStatus.state.start(e,t,s,r,o)}pause(){return this.runStatus.state.pause()}resume(){return this.runStatus.state.resume()}stop(){return this.runStatus.state.stop()}reset(){this.runStatus.state.reset()}getSerializableState(){return this.runStatus.state.getSerializableState()}debug(e,...t){(null==this?void 0:this.runStatus)?this.runStatus.state.debug(e,...t):(0,o.default)("init")(e,...t)}log({n:e,m:t,mp:s,l:r,e:o}){this.debug(i.FlowState.formatDebugMessage({n:e,m:t,mp:s,l:r,e:o}),[s]),n.FlowManager.log(i.FlowState.createLogEntry({n:e,m:t,mp:s,l:r,e:o},this.runStatus))}}},454:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(155),t),o(s(167),t),o(s(580),t),o(s(413),t)},851:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessManager=void 0;const r=s(8);t.ProcessManager=class{constructor(){this.nextProcessId=1,this.processes=[]}createProcess(e,t,s,o,n,i,a,u){this.nextProcessId++;const l=new r.TaskProcess(this,this.nextProcessId,e,t,s,o,n,i,a,u);return this.processes.push(l),l}runningCount(){return this.processes.length}removeProcess(e){const t=this.processes.findIndex((t=>t.id===e.id));this.processes.splice(t,1)}}},580:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TaskSpecMap=void 0,t.TaskSpecMap=class{}},8:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TaskProcess=void 0;class s{constructor(e,t,r,o,n,i,a,u,l,c){this.manager=e,this.id=t,this.task=r,this.taskResolverExecutor=o,this.context=n,this.automapParams=i,this.automapResults=a,this.flowId=u,this.debug=l,this.log=c,this.pid=s.nextPid,s.nextPid=(s.nextPid+1)%Number.MAX_SAFE_INTEGER}getParams(){return this.params}run(){this.params=this.task.mapParamsForResolver(this.task.runStatus.solvedReqs.popAll(),this.automapParams,this.flowId,this.log);let e,t=this.taskResolverExecutor;if(this.taskResolverExecutor.prototype&&this.taskResolverExecutor.prototype.exec){const s=new this.taskResolverExecutor;t=s.exec,e=s}return new Promise(((s,r)=>{const o=e=>{this.task.runStatus.solvedResults=this.task.mapResultsFromResolver(e,this.automapResults,this.flowId,this.log),s(this.task.runStatus.solvedResults)},n=e=>{r(e)};let i;try{i=t.call(e,this.params,this.context,this.task,this.debug,this.log)}catch(e){n(e)}const a="object"==typeof i,u=i&&i.constructor&&"Promise"===i.constructor.name;if(!a)throw new Error(`Expected resolver for task '${this.task.code}' to return an object or Promise that resolves to object. Returned value is of type '${typeof i}'.`);u?i.then(o).catch(n):o(i)}))}}t.TaskProcess=s,s.nextPid=1},413:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Task=void 0;const r=s(405),o=s(829);t.Task=class{constructor(e,t){this.code=e,this.spec=t,this.parseSpec()}getResolverName(){var e;return(null!==(e=this.spec.resolver)&&void 0!==e?e:{name:"flowed::Noop"}).name}getSerializableState(){const e=JSON.parse(JSON.stringify(this.runStatus));return e.solvedReqs=this.runStatus.solvedReqs.toSerializable(),e}setSerializableState(e){this.runStatus=JSON.parse(JSON.stringify(e)),this.runStatus.solvedReqs=r.ValueQueueManager.fromSerializable(e.solvedReqs)}resetRunStatus(){var e;const t=[...null!==(e=this.spec.requires)&&void 0!==e?e:[]];this.runStatus={solvedReqs:new r.ValueQueueManager(t),solvedResults:{}}}isReadyToRun(){return this.runStatus.solvedReqs.allHaveContent()}getResults(){return this.runStatus.solvedResults}supplyReq(e,t){var s;if(-1===(null!==(s=this.spec.requires)&&void 0!==s?s:[]).indexOf(e))throw new Error(`Requirement '${e}' for task '${this.code}' is not valid.`);this.runStatus.solvedReqs.push(e,t)}supplyReqs(e){for(const[t,s]of Object.entries(e))this.supplyReq(t,s)}mapParamsForResolver(e,t,s,r){var n,i,a;const u={};let l,c=null!==(i=null===(n=this.spec.resolver)||void 0===n?void 0:n.params)&&void 0!==i?i:{};if(t){const e=(null!==(a=this.spec.requires)&&void 0!==a?a:[]).map((e=>({[e]:e}))).reduce(((e,t)=>Object.assign(e,t)),{});r({n:s,m:` ⓘ Auto-mapped resolver params in task '${this.code}': %O`,mp:e,l:"d"}),c=Object.assign(e,c)}for(const[t,s]of Object.entries(c)){if("string"==typeof s)l=e[s];else if(Object.prototype.hasOwnProperty.call(s,"value"))l=s.value;else{const t=s.transform;l=o.select(e).transformWith(t).root()}u[t]=l}return u}mapResultsFromResolver(e,t,s,r){var o,n,i;if("object"!=typeof e)throw new Error(`Expected resolver for task '${this.code}' to return an object or Promise that resolves to object. Returned value is of type '${typeof e}'.`);const a={};let u=null!==(n=(null!==(o=this.spec.resolver)&&void 0!==o?o:{}).results)&&void 0!==n?n:{};if(t){const e=(null!==(i=this.spec.provides)&&void 0!==i?i:[]).reduce(((e,t)=>Object.assign(e,{[t]:t})),{});r({n:s,m:` ⓘ Auto-mapped resolver results in task '${this.code}': %O`,mp:e,l:"d"}),u=Object.assign(e,u)}for(const[t,s]of Object.entries(u))Object.prototype.hasOwnProperty.call(e,t)&&(a[s]=e[t]);return a}parseSpec(){this.resetRunStatus()}}},405:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ValueQueueManager=void 0;class s{static fromSerializable(e){const t=Object.keys(e),r=new s(t);return r.queues=e,r.nonEmptyQueues=t.reduce(((e,t)=>(r.queues[t].length>0&&e.add(t),e)),new Set),r}constructor(e){this.nonEmptyQueues=new Set,this.queueNames=[...e],this.queues=e.reduce(((e,t)=>(e[t]=[],e)),{})}push(e,t){if(!this.queueNames.includes(e))throw new Error(`Queue name ${e} does not exist in queue manager. Existing queues are: [${this.queueNames.join(", ")}].`);this.nonEmptyQueues.add(e),this.queues[e].push(t)}getEmptyQueueNames(){return this.queueNames.reduce(((e,t)=>(0===this.queues[t].length&&e.push(t),e)),[])}popAll(){return this.validateAllNonEmpty(),this.queueNames.reduce(((e,t)=>(e[t]=this.queues[t].shift(),0===this.queues[t].length&&this.nonEmptyQueues.delete(t),e)),{})}topAll(){return this.validateAllNonEmpty(),this.queueNames.reduce(((e,t)=>(e[t]=this.queues[t][0],e)),{})}toSerializable(){return JSON.parse(JSON.stringify(this.queues))}validateAllNonEmpty(){if(!this.allHaveContent())throw new Error(`Some of the queues are empty: [${this.getEmptyQueueNames().join(", ")}].`)}allHaveContent(){return this.nonEmptyQueues.size===this.queueNames.length}}t.ValueQueueManager=s},590:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(985),t),o(s(454),t),o(s(582),t)},582:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PauseResolver=t.StopResolver=t.LoopResolver=t.ArrayMapResolver=t.RepeaterResolver=t.SubFlowResolver=t.WaitResolver=t.ConditionalResolver=t.ThrowErrorResolver=t.EchoResolver=t.NoopResolver=void 0;const r=s(454),o=s(8);t.NoopResolver=class{exec(){return{}}},t.EchoResolver=class{exec(e){return{out:e.in}}},t.ThrowErrorResolver=class{exec(e){throw new Error(void 0!==e.message?e.message:"ThrowErrorResolver resolver has thrown an error")}},t.ConditionalResolver=class{exec(e){return e.condition?{onTrue:e.trueResult}:{onFalse:e.falseResult}}},t.WaitResolver=class{exec(e){return new Promise((t=>{setTimeout((()=>{t({result:e.result})}),e.ms)}))}},t.SubFlowResolver=class{async exec(e,t){let s=e.flowResolvers;void 0===s&&(s=t.$flowed.getResolvers());let o=await r.FlowManager.run(e.flowSpec,e.flowParams,e.flowExpectedResults,s,t,t.$flowed.flow.runStatus.runOptions);return"string"==typeof e.uniqueResult&&(o=o[e.uniqueResult]),{flowResult:o}}},t.RepeaterResolver=class{async exec(e,t,s,n,i){const a=t.$flowed.getResolverByName(e.resolver);if(null===a)throw new Error(`Task resolver '${e.resolver}' for inner flowed::Repeater task has no definition.`);const u=new r.Task("task-repeat-model",e.taskSpec),l=[];let c=[];for(let s=0;st[e.outItemName]))),{outCollection:d}}},t.StopResolver=class{exec(e,t){return{promise:t.$flowed.flow.stop()}}},t.PauseResolver=class{exec(e,t){return{promise:t.$flowed.flow.pause()}}}},985:function(e,t){"use strict";var s,r;Object.defineProperty(t,"__esModule",{value:!0}),t.TaskResolverMap=t.TaskResolver=t.FlowTransitionEnum=t.FlowStateEnum=void 0,(r=t.FlowStateEnum||(t.FlowStateEnum={})).Ready="Ready",r.Running="Running",r.Finished="Finished",r.Pausing="Pausing",r.Paused="Paused",r.Stopping="Stopping",r.Stopped="Stopped",(s=t.FlowTransitionEnum||(t.FlowTransitionEnum={})).Start="Start",s.Finished="Finished",s.Reset="Reset",s.Pause="Pause",s.Paused="Paused",s.Resume="Resume",s.Stop="Stop",s.Stopped="Stopped",t.TaskResolver=class{exec(e,t,s,r,o){return{}}},t.TaskResolverMap=class{}},227:function(e,t,s){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const s="color: "+this.color;t.splice(1,0,s,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,s)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=s(447)(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:function(e,t,s){e.exports=function(e){function t(e){let s,o,n,i=null;function a(...e){if(!a.enabled)return;const r=a,o=Number(new Date),n=o-(s||o);r.diff=n,r.prev=s,r.curr=o,s=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((s,o)=>{if("%%"===s)return"%";i++;const n=t.formatters[o];if("function"==typeof n){const t=e[i];s=n.call(r,t),e.splice(i,1),i--}return s})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(o!==t.namespaces&&(o=t.namespaces,n=t.enabled(e)),n),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,s){const r=t(this.namespace+(void 0===s?":":s)+e);return r.log=this.log,r}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(o),...t.skips.map(o).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let s;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(s=0;s{t[s]=e[s]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let s=0;for(let t=0;t0&&e.length-1 in e)},resolve:function(e,t,s){return t&&t.length>0?Function("new_val","with(this) {this"+t+"=new_val; return this;}").bind(e)(s):e=s}},r={run:function(e,t){for(var s=0;s0&&"#"===t[0][0]?{name:t.shift(),expression:t.join(" ")}:null},run:function(e,t){var n,i;if("string"==typeof e)s.is_template(e)?/\{\{([ ]*#include)[ ]*([^ ]*)\}\}/g.test(e)?(i=o.tokenize(e),n=i.expression?o.fillout(t,"{{"+i.expression+"}}",!0):e):n=o.fillout(t,e):n=e;else if(s.is_array(e))if(r.is(e))n=r.run(e,t);else{n=[];for(var a=0;a0&&(i=o.tokenize(c[0]),n=i.expression?o.fillout(e[c[0]],"{{"+i.expression+"}}",!0):e[c[0]]),e)if(s.is_template(d))if(i=o.tokenize(d)){if("#include"===i.name);else if("#let"===i.name){if(s.is_array(e[d])&&2===e[d].length){var p=e[d][0],h=e[d][1],f=o.run(p,t);for(var m in f)o.memory[m]=f[m],t[m]=f[m];n=o.run(h,t)}}else if("#concat"===i.name)s.is_array(e[d])&&(n=[],e[d].forEach((function(e){var s=o.run(e,t);n=n.concat(s)})));else if("#merge"===i.name){if(s.is_array(e[d]))if(n={},e[d].forEach((function(e){var s=o.run(e,t);for(var r in s)n[r]=s[r]})),"object"==typeof t)for(var g in delete n.$index,o.memory)delete n[g];else for(g in delete String.prototype.$index,delete Number.prototype.$index,delete Function.prototype.$index,delete Array.prototype.$index,delete Boolean.prototype.$index,o.memory)delete String.prototype[g],delete Number.prototype[g],delete Function.prototype[g],delete Array.prototype[g],delete Boolean.prototype[g]}else if("#each"===i.name){var v=o.fillout(t,"{{"+i.expression+"}}",!0);if(v&&s.is_array(v)){n=[];for(var y=0;y0&&n.select(n.$injected),n},select:function(e,t,r){var o=e;try{r&&(o=JSON.parse(e))}catch(e){}return t?(n.$selected=[],n.exec(o,"",t)):n.$selected=null,o&&(s.is_array(o)||"object"==typeof o)?(n.$progress||(s.is_array(o)?(n.$val=[],n.$selected_root=[]):(n.$val={},n.$selected_root={})),Object.keys(o).forEach((function(e){n.$val[e]=o[e],n.$selected_root[e]=o[e]}))):(n.$val=o,n.$selected_root=o),n.$progress=!0,n},transformWith:function(e,r){n.$parsed=[],n.$progress=null;var i=e;try{r&&(i=JSON.parse(e))}catch(e){}if(n.$template_root=i,String.prototype.$root=n.$selected_root,Number.prototype.$root=n.$selected_root,Function.prototype.$root=n.$selected_root,Array.prototype.$root=n.$selected_root,Boolean.prototype.$root=n.$selected_root,t=n.$selected_root,n.$selected&&n.$selected.length>0)n.$selected.sort((function(e,t){return t.path.length-e.path.length})).forEach((function(e){var t=o.run(i,e.object);n.$selected_root=s.resolve(n.$selected_root,e.path,t),e.object=t})),n.$selected.sort((function(e,t){return e.index-t.index}));else{var a=o.run(i,n.$selected_root);n.$selected_root=s.resolve(n.$selected_root,"",a)}return delete String.prototype.$root,delete Number.prototype.$root,delete Function.prototype.$root,delete Array.prototype.$root,delete Boolean.prototype.$root,n},transform:function(e,r){n.$parsed=[],n.$progress=null;var i=e;try{r&&(i=JSON.parse(e))}catch(e){}if(n.$template_root=n.$selected_root,String.prototype.$root=i,Number.prototype.$root=i,Function.prototype.$root=i,Array.prototype.$root=i,Boolean.prototype.$root=i,t=i,n.$selected&&n.$selected.length>0)n.$selected.sort((function(e,t){return t.path.length-e.path.length})).forEach((function(e){var t=o.run(e.object,i);n.$template_root=s.resolve(n.$template_root,e.path,t),n.$selected_root=n.$template_root,e.object=t})),n.$selected.sort((function(e,t){return e.index-t.index}));else{var a=o.run(n.$selected_root,i);n.$template_root=s.resolve(n.$template_root,"",a),n.$selected_root=n.$template_root}return delete String.prototype.$root,delete Number.prototype.$root,delete Function.prototype.$root,delete Array.prototype.$root,delete Boolean.prototype.$root,n},objects:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.object})):[n.$selected_root]},keys:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.key})):Array.isArray(n.$selected_root)?Object.keys(n.$selected_root).map((function(e){return parseInt(e)})):Object.keys(n.$selected_root)},paths:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.path})):Array.isArray(n.$selected_root)?Object.keys(n.$selected_root).map((function(e){return"["+e+"]"})):Object.keys(n.$selected_root).map((function(e){return'["'+e+'"]'}))},values:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.value})):Object.values(n.$selected_root)},root:function(){return n.$progress=null,n.$selected_root}},i=JSON.stringify,a=function(e,t,s){return-1!==["number","string","boolean"].indexOf(typeof e)?i(e,t,s):i(e,t||function(e,t){if(!(n.$injected&&n.$injected.length>0&&-1!==n.$injected.indexOf(e)||"$root"===e||"$index"===e||e in o.memory))return"function"==typeof t?"("+t.toString()+")":t},s)};JSON.stringify2=a;var u={TRANSFORM:o,SELECT:n,Conditional:r,Helper:s,inject:n.inject,select:n.select,transform:o.transform};e.exports&&(e.exports=u)}()},824:function(e){var t=1e3,s=60*t,r=60*s,o=24*r;function n(e,t,s,r){var o=t>=1.5*s;return Math.round(e/s)+" "+r+(o?"s":"")}e.exports=function(e,i){i=i||{};var a,u,l=typeof e;if("string"===l&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var n=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(n){var i=parseFloat(n[1]);switch((n[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return 6048e5*i;case"days":case"day":case"d":return i*o;case"hours":case"hour":case"hrs":case"hr":case"h":return i*r;case"minutes":case"minute":case"mins":case"min":case"m":return i*s;case"seconds":case"second":case"secs":case"sec":case"s":return i*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(e);if("number"===l&&isFinite(e))return i.long?(a=e,(u=Math.abs(a))>=o?n(a,u,o,"day"):u>=r?n(a,u,r,"hour"):u>=s?n(a,u,s,"minute"):u>=t?n(a,u,t,"second"):a+" ms"):function(e){var n=Math.abs(e);return n>=o?Math.round(e/o)+"d":n>=r?Math.round(e/r)+"h":n>=s?Math.round(e/s)+"m":n>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},673:function(){},883:function(){},316:function(){}},t={},function s(r){var o=t[r];if(void 0!==o)return o.exports;var n=t[r]={exports:{}};return e[r].call(n.exports,n,n.exports,s),n.exports}(590);var e,t})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Flowed=t():e.Flowed=t()}(self,(function(){return e={865:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(227),o={};t.default=e=>{let t=o[e];return void 0===t&&(t=(0,r.default)(`flowed:${e}`),o[e]=t),t}},155:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowManager=void 0;const r=s(673),o=s(883),n=s(316),i=s(167);class a{static run(e,t={},s=[],r={},o={},n={}){return new i.Flow(e).start(t,s,r,o,n)}static runFromString(e,t={},s=[],r={},o={},n={}){return new Promise(((i,u)=>{try{const l=JSON.parse(e);a.run(l,t,s,r,o,n).then(i,u)}catch(e){u(e)}}))}static runFromFile(e,t={},s=[],o={},n={},i={}){return new Promise(((u,l)=>{(0,r.readFile)(e,"utf8",((e,r)=>{e?l(e):a.runFromString(r,t,s,o,n,i).then(u,l)}))}))}static runFromUrl(e,t={},s=[],r={},i={},u={}){let l=null;if(e.startsWith("http://")?l=o:e.startsWith("https://")&&(l=n),null===l){let t=null;const s=e.match(/^([a-zA-Z]+):/);return Array.isArray(s)&&2===s.length?(t=s[1],Promise.reject(new Error(`Protocol not supported: ${t}. Supported protocols are: [http, https]`))):Promise.reject(new Error(`Invalid URL: ${e}`))}return new Promise(((o,n)=>{l.get(e,(e=>{var l;const{statusCode:c}=e,d=null!==(l=e.headers["content-type"])&&void 0!==l?l:"application/json";let p;if(200!==c?p=new Error(`Request failed with status code: ${c}`):d.startsWith("application/json")||d.startsWith("text/plain")||(p=new Error(`Invalid content-type: Expected 'application/json' or 'text/plain' but received '${d}'`)),p)n(p);else{e.setEncoding("utf8");let l="";e.on("data",(e=>{l+=e})),e.on("end",(()=>{a.runFromString(l,t,s,r,i,u).then(o,n)}))}})).on("error",(e=>{n(e)}))}))}static installPlugin(e){if(e.resolverLibrary)for(const[t,s]of Object.entries(e.resolverLibrary))this.plugins.resolvers[t]=s}static installLogger(e){this.logger=e}static log(e){null!==a.logger&&a.logger.log(e)}}t.FlowManager=a,a.plugins={resolvers:{}},a.logger=null},875:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowRunStatus=void 0;const r=s(985),o=s(871),n=s(851),i=s(413);class a{constructor(e,t,s){this.tasksReady=[],this.tasksByReq={},this.resolvers={},this.expectedResults=[],this.results={},this.context={},this.runOptions={},this.flow=e,this.processManager=new n.ProcessManager,this.id=a.nextId,a.nextId=(a.nextId+1)%Number.MAX_SAFE_INTEGER,this.states={Ready:new o.FlowReady(this),Running:new o.FlowRunning(this),Finished:new o.FlowFinished(this),Pausing:new o.FlowPausing(this),Paused:new o.FlowPaused(this),Stopping:new o.FlowStopping(this),Stopped:new o.FlowStopped(this)},this.state=this.states[r.FlowStateEnum.Ready],this.initRunStatus(t,s)}initRunStatus(e,t){var s,r,o,n,a;this.spec=e,this.tasks={};const u=[];for(const[e,t]of Object.entries(null!==(s=this.spec.tasks)&&void 0!==s?s:{}))u.push(...null!==(r=t.provides)&&void 0!==r?r:[]),this.tasks[e]=new i.Task(e,t);this.taskProvisions=Array.from(new Set(u)),this.options=Object.assign({},null!==(o=this.spec.configs)&&void 0!==o?o:{},null!==(n=this.spec.options)&&void 0!==n?n:{}),Object.prototype.hasOwnProperty.call(this.spec,"configs")&&this.flow.log({m:"DEPRECATED: 'configs' field in flow spec. Use 'options' instead.",l:"w"}),this.tasksByReq={},this.tasksReady=[];for(const e of Object.values(this.tasks)){e.resetRunStatus(),e.isReadyToRun()&&this.tasksReady.push(e);const t=null!==(a=e.spec.requires)&&void 0!==a?a:[];for(const s of t)void 0===this.tasksByReq[s]&&(this.tasksByReq[s]={}),this.tasksByReq[s][e.code]=e}this.results={},t&&this.fromSerializable(t)}fromSerializable(e){this.id=e.id,this.processManager.nextProcessId=e.nextProcessId,this.processManager.processes=[],this.tasksReady=e.tasksReady.map((e=>this.tasks[e])),this.tasksByReq={};for(const[t,s]of Object.entries(e.tasksByReq))this.tasksByReq[t]=s.reduce(((e,t)=>(e[t]=this.tasks[t],e)),{});this.taskProvisions=JSON.parse(JSON.stringify(e.taskProvisions)),this.expectedResults=JSON.parse(JSON.stringify(e.expectedResults)),this.results=JSON.parse(JSON.stringify(e.results)),this.context=JSON.parse(JSON.stringify(e.context)),this.options=JSON.parse(JSON.stringify(e.options));for(const[t,s]of Object.entries(e.taskStatuses))this.tasks[t].setSerializableState(s)}toSerializable(){const e={id:this.id,nextProcessId:this.processManager.nextProcessId,tasksReady:this.tasksReady.map((e=>e.code)),tasksByReq:{},taskProvisions:JSON.parse(JSON.stringify(this.taskProvisions)),expectedResults:JSON.parse(JSON.stringify(this.expectedResults)),results:JSON.parse(JSON.stringify(this.results)),context:{},options:JSON.parse(JSON.stringify(this.options)),taskStatuses:{}},t=Object.assign({},this.context);delete t.$flowed,e.context=JSON.parse(JSON.stringify(t));for(const[t,s]of Object.entries(this.tasksByReq))e.tasksByReq[t]=Object.keys(s);for(const[t,s]of Object.entries(this.tasks))e.taskStatuses[t]=JSON.parse(JSON.stringify(s.getSerializableState()));return e}}t.FlowRunStatus=a,a.nextId=1},389:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowFinished=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Finished}reset(){this.setState(o.FlowStateEnum.Ready),this.runStatus.initRunStatus(this.runStatus.spec)}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowFinished=n},578:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowPaused=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Paused}resume(){return this.setState(o.FlowStateEnum.Running),this.createFinishPromise(),this.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(),this.runStatus.finishPromise}stop(){return this.setState(o.FlowStateEnum.Stopping),Promise.resolve(this.getResults())}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowPaused=n},547:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowPausing=void 0;const r=s(985),o=s(823);class n extends o.FlowState{getStateCode(){return r.FlowStateEnum.Pausing}paused(e){this.setState(r.FlowStateEnum.Paused),e?(this.log({n:this.runStatus.id,m:"Flow paused with error.",e:"FP"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow paused.",e:"FP"}),this.execFinishResolve())}postProcessFinished(e,t){this.runStatus.state.paused(e)}}t.FlowPausing=n},106:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowReady=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Ready}start(e,t,s,r,n={}){return this.setRunOptions(n),this.log({n:this.runStatus.id,m:"Flow started with params: %O",mp:e,e:"FS"}),this.setState(o.FlowStateEnum.Running),this.setExpectedResults([...t]),this.setResolvers(s),this.setContext(r),this.supplyParameters(e),this.createFinishPromise(),this.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(),this.runStatus.finishPromise}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowReady=n},873:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowRunning=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Running}pause(){return this.setState(o.FlowStateEnum.Pausing),this.runStatus.finishPromise}stop(){return this.setState(o.FlowStateEnum.Stopping),this.runStatus.finishPromise}finished(e=!1){this.setState(o.FlowStateEnum.Finished),e?(this.log({n:this.runStatus.id,m:"Flow finished with error. Results: %O",mp:this.getResults(),l:"e",e:"FF"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow finished with results: %O",mp:this.getResults(),e:"FF"}),this.execFinishResolve())}postProcessFinished(e,t){e&&t||this.runStatus.state.startReadyTasks(),this.runStatus.state.isRunning()||this.runStatus.state.finished(e)}}t.FlowRunning=n},823:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowState=void 0;const r=s(865),o=s(582),n=s(985),i=s(155);class a{constructor(e){this.runStatus=e}start(e,t,s,r,o={}){throw this.createTransitionError(n.FlowTransitionEnum.Start)}finished(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Finished)}pause(){throw this.createTransitionError(n.FlowTransitionEnum.Pause)}paused(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Paused)}resume(){throw this.createTransitionError(n.FlowTransitionEnum.Resume)}stop(){throw this.createTransitionError(n.FlowTransitionEnum.Stop)}stopped(e=!1){throw this.createTransitionError(n.FlowTransitionEnum.Stopped)}reset(){throw this.createTransitionError(n.FlowTransitionEnum.Reset)}execFinishResolve(){this.runStatus.finishResolve(this.runStatus.results)}execFinishReject(e){this.runStatus.finishReject(e)}isRunning(){return this.runStatus.processManager.runningCount()>0}setExpectedResults(e){const t=e.filter((e=>!this.runStatus.taskProvisions.includes(e)));if(t.length>0){const e=`The results [${t.join(", ")}] are not provided by any task`;if(this.runStatus.options.throwErrorOnUnsolvableResult)throw new Error(e);this.log({m:e,l:"w"})}this.runStatus.expectedResults=[...e]}getResults(){return this.runStatus.results}setResolvers(e){this.runStatus.resolvers=e}setContext(e){this.runStatus.context=Object.assign({$flowed:{getResolverByName:this.getResolverByName.bind(this),getResolvers:this.getResolvers.bind(this),processManager:this.runStatus.processManager,flow:this.runStatus.flow}},e)}setRunOptions(e){this.runStatus.runOptions=Object.assign({debugKey:"flow",instanceId:null,logFields:{}},e)}supplyParameters(e){for(const[t,s]of Object.entries(e))this.runStatus.state.supplyResult(t,s)}createFinishPromise(){this.runStatus.finishPromise=new Promise(((e,t)=>{this.runStatus.finishResolve=e,this.runStatus.finishReject=t}))}getResolverForTask(e){const t=e.getResolverName(),s=this.getResolverByName(t);if(null===s)throw new Error(`Task resolver '${t}' for task '${e.code}' has no definition. Defined custom resolvers are: [${Object.keys(this.runStatus.resolvers).join(", ")}].`);return s}getResolverByName(e){const t=this.runStatus.resolvers;return void 0!==t[e]?t[e]:void 0!==i.FlowManager.plugins.resolvers[e]?i.FlowManager.plugins.resolvers[e]:void 0!==a.builtInResolvers[e]?a.builtInResolvers[e]:null}getResolvers(){const e=this.runStatus.resolvers,t=i.FlowManager.plugins.resolvers,s=a.builtInResolvers;return Object.assign(Object.assign(Object.assign({},s),t),e)}supplyResult(e,t){if(void 0!==this.runStatus.tasksByReq[e]){const s=this.runStatus.tasksByReq[e],r=Object.keys(s);for(const o of r){const r=s[o];r.supplyReq(e,t),r.isReadyToRun()&&this.runStatus.tasksReady.push(r)}}this.runStatus.expectedResults.indexOf(e)>-1&&(this.runStatus.results[e]=t)}getStateInstance(e){return this.runStatus.states[e]}startReadyTasks(){const e=this.runStatus.tasksReady;this.runStatus.tasksReady=[];for(const t of e){const e=this.runStatus.state.getResolverForTask(t),s=this.runStatus.processManager.createProcess(t,e,this.runStatus.context,!!this.runStatus.options.resolverAutomapParams,!!this.runStatus.options.resolverAutomapResults,this.runStatus.id,this.debug,this.log.bind(this)),r=e=>{this.processFinished(s,e,!0)};s.run().then((()=>{this.processFinished(s,!1,!0)}),r).catch(r),this.log({n:this.runStatus.id,m:`Task '${t.code}(${t.getResolverName()})' started, params: %O`,mp:s.getParams(),e:"TS",pid:s.pid,task:{code:t.code,type:t.getResolverName()}})}}setState(e){const t=this.runStatus.state.getStateCode();this.runStatus.state=this.getStateInstance(e),this.log({n:this.runStatus.id,m:`Changed flow state from '${t}' to '${e}'`,l:"d",e:"FC"})}getSerializableState(){throw this.createMethodError("getSerializableState")}processFinished(e,t,s){var r;this.runStatus.processManager.removeProcess(e);const o=e.task,n=o.code,i=o.spec,a=null!==(r=i.provides)&&void 0!==r?r:[],u=o.getResults(),l=Object.prototype.hasOwnProperty.call(i,"defaultResult");t?this.log({n:this.runStatus.id,m:`Error in task '${n}', results: %O`,mp:u,l:"e",e:"TF",pid:e.pid,task:{code:o.code,type:o.getResolverName()}}):this.log({n:this.runStatus.id,m:`Finished task '${n}', results: %O`,mp:u,e:"TF",pid:e.pid,task:{code:o.code,type:o.getResolverName()}});for(const e of a)Object.prototype.hasOwnProperty.call(u,e)?this.runStatus.state.supplyResult(e,u[e]):l?this.runStatus.state.supplyResult(e,i.defaultResult):this.log({n:this.runStatus.id,m:`Expected value '${e}' was not provided by task '${n}' with resolver '${o.getResolverName()}'. Consider using the task field 'defaultResult' to provide values by default.`,l:"w"});this.runStatus.state.postProcessFinished(t,s)}postProcessFinished(e,t){}createTransitionError(e){return new Error(`Cannot execute transition ${e} in current state ${this.getStateCode()}.`)}createMethodError(e){return new Error(`Cannot execute method ${e} in current state ${this.getStateCode()}.`)}debug(e,...t){const s=(null==this?void 0:this.runStatus)&&"string"==typeof this.runStatus.runOptions.debugKey?this.runStatus.runOptions.debugKey:"init";(0,r.default)(s)(e,...t)}static formatDebugMessage({n:e,m:t,l:s,e:r}){var o;const n="w"===s?"⚠️ ":"";let i=null!==(o={FS:"▶ ",FF:"✔ ",TS:" ‣ ",TF:" ✓ ",FC:" ⓘ ",FT:"◼ ",FP:"⏸ "}[r||""])&&void 0!==o?o:"";return"TF"===r&&["e","f"].includes(s||"")?i=" ✗":"FF"===r&&["e","f"].includes(s||"")&&(i="✘"),`[${e}] ${n+i}${t}`}static createLogEntry({n:e,m:t,mp:s,l:r,e:o,pid:n,task:i},a){let u={level:(e=>{switch(e=e||"i"){case"e":return"error";case"w":return"warning";case"i":return"info";case"d":return"debug";default:throw new Error(`Not supported error level: "${e}"`)}})(r),eventType:(e=>{switch(e){case"TS":return"Task.Started";case"TF":return"Task.Finished";case"FC":return"Flow.StateChanged";case"FS":return"Flow.Started";case"FF":return"Flow.Finished";case"FT":return"Flow.Stopped";case"FP":return"Flow.Paused";default:return"General"}})(o),message:((e,t)=>{if(t){const s=JSON.stringify(t);return e.replace("%O",s.length>100?s.slice(0,97)+"...":s)}return e})(t,s),timestamp:new Date,extra:{pid:n,task:i,debugId:e,values:JSON.stringify(s)}};return a&&(u.objectId=a.runOptions.instanceId,u=Object.assign(a.runOptions.logFields,u)),u}log({n:e,m:t,mp:s,l:r,e:o,pid:n,task:u}){this.debug(a.formatDebugMessage({n:e,m:t,mp:s,l:r,e:o}),[s]),i.FlowManager.log(a.createLogEntry({n:e,m:t,mp:s,l:r,e:o,pid:n,task:u},this.runStatus))}}t.FlowState=a,a.builtInResolvers={"flowed::Noop":o.NoopResolver,"flowed::Echo":o.EchoResolver,"flowed::ThrowError":o.ThrowErrorResolver,"flowed::Conditional":o.ConditionalResolver,"flowed::Wait":o.WaitResolver,"flowed::SubFlow":o.SubFlowResolver,"flowed::Repeater":o.RepeaterResolver,"flowed::Loop":o.LoopResolver,"flowed::ArrayMap":o.ArrayMapResolver,"flowed::Stop":o.StopResolver,"flowed::Pause":o.PauseResolver}},784:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowStopped=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Stopped}reset(){this.setState(o.FlowStateEnum.Ready),this.runStatus.initRunStatus(this.runStatus.spec)}getSerializableState(){return this.runStatus.toSerializable()}}t.FlowStopped=n},17:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FlowStopping=void 0;const r=s(871),o=s(985);class n extends r.FlowState{getStateCode(){return o.FlowStateEnum.Stopping}stopped(e=!1){this.setState(o.FlowStateEnum.Stopped),e?(this.log({n:this.runStatus.id,m:"Flow stopped with error.",e:"FT"}),this.execFinishReject(e)):(this.log({n:this.runStatus.id,m:"Flow stopped.",e:"FT"}),this.execFinishResolve())}postProcessFinished(e,t){this.runStatus.state.stopped(e)}}t.FlowStopping=n},871:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(823),t),o(s(106),t),o(s(389),t),o(s(578),t),o(s(547),t),o(s(873),t),o(s(784),t),o(s(17),t)},167:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Flow=void 0;const r=s(875),o=s(865),n=s(155),i=s(871);t.Flow=class{constructor(e,t){this.runStatus=new r.FlowRunStatus(this,null!=e?e:{},t)}getStateCode(){return this.runStatus.state.getStateCode()}start(e={},t=[],s={},r={},o={}){return this.runStatus.state.start(e,t,s,r,o)}pause(){return this.runStatus.state.pause()}resume(){return this.runStatus.state.resume()}stop(){return this.runStatus.state.stop()}reset(){this.runStatus.state.reset()}getSerializableState(){return this.runStatus.state.getSerializableState()}debug(e,...t){(null==this?void 0:this.runStatus)?this.runStatus.state.debug(e,...t):(0,o.default)("init")(e,...t)}log({n:e,m:t,mp:s,l:r,e:o}){this.debug(i.FlowState.formatDebugMessage({n:e,m:t,mp:s,l:r,e:o}),[s]),n.FlowManager.log(i.FlowState.createLogEntry({n:e,m:t,mp:s,l:r,e:o},this.runStatus))}}},454:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(155),t),o(s(167),t),o(s(580),t),o(s(413),t)},851:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessManager=void 0;const r=s(8);t.ProcessManager=class{constructor(){this.nextProcessId=1,this.processes=[]}createProcess(e,t,s,o,n,i,a,u){this.nextProcessId++;const l=new r.TaskProcess(this,this.nextProcessId,e,t,s,o,n,i,a,u);return this.processes.push(l),l}runningCount(){return this.processes.length}removeProcess(e){const t=this.processes.findIndex((t=>t.id===e.id));this.processes.splice(t,1)}}},580:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TaskSpecMap=void 0,t.TaskSpecMap=class{}},8:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TaskProcess=void 0;class s{constructor(e,t,r,o,n,i,a,u,l,c){this.manager=e,this.id=t,this.task=r,this.taskResolverExecutor=o,this.context=n,this.automapParams=i,this.automapResults=a,this.flowId=u,this.debug=l,this.log=c,this.pid=s.nextPid,s.nextPid=(s.nextPid+1)%Number.MAX_SAFE_INTEGER}getParams(){return this.params}run(){var e;this.params=this.task.mapParamsForResolver(this.task.runStatus.solvedReqs.popAll(),this.automapParams,this.flowId,this.log);let t,s=this.taskResolverExecutor;if(null===(e=this.taskResolverExecutor.prototype)||void 0===e?void 0:e.exec){const e=new this.taskResolverExecutor;s=e.exec,t=e}return new Promise(((e,r)=>{var o;const n=t=>{this.task.runStatus.solvedResults=this.task.mapResultsFromResolver(t,this.automapResults,this.flowId,this.log),e(this.task.runStatus.solvedResults)},i=e=>{r(e)};let a;try{a=s.call(t,this.params,this.context,this.task,this.debug,this.log)}catch(e){i(e)}const u="object"==typeof a,l="Promise"===(null===(o=null==a?void 0:a.constructor)||void 0===o?void 0:o.name);if(!u)throw new Error(`Expected resolver for task '${this.task.code}' to return an object or Promise that resolves to object. Returned value is of type '${typeof a}'.`);l?a.then(n).catch(i):n(a)}))}}t.TaskProcess=s,s.nextPid=1},413:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Task=void 0;const r=s(405),o=s(829);t.Task=class{constructor(e,t){this.code=e,this.spec=t,this.parseSpec()}getResolverName(){var e;return(null!==(e=this.spec.resolver)&&void 0!==e?e:{name:"flowed::Noop"}).name}getSerializableState(){const e=JSON.parse(JSON.stringify(this.runStatus));return e.solvedReqs=this.runStatus.solvedReqs.toSerializable(),e}setSerializableState(e){this.runStatus=JSON.parse(JSON.stringify(e)),this.runStatus.solvedReqs=r.ValueQueueManager.fromSerializable(e.solvedReqs)}resetRunStatus(){var e;const t=[...null!==(e=this.spec.requires)&&void 0!==e?e:[]];this.runStatus={solvedReqs:new r.ValueQueueManager(t),solvedResults:{}}}isReadyToRun(){return this.runStatus.solvedReqs.allHaveContent()}getResults(){return this.runStatus.solvedResults}supplyReq(e,t){var s;if(-1===(null!==(s=this.spec.requires)&&void 0!==s?s:[]).indexOf(e))throw new Error(`Requirement '${e}' for task '${this.code}' is not valid.`);this.runStatus.solvedReqs.push(e,t)}supplyReqs(e){for(const[t,s]of Object.entries(e))this.supplyReq(t,s)}mapParamsForResolver(e,t,s,r){var n,i,a;const u={};let l,c=null!==(i=null===(n=this.spec.resolver)||void 0===n?void 0:n.params)&&void 0!==i?i:{};if(t){const e=(null!==(a=this.spec.requires)&&void 0!==a?a:[]).map((e=>({[e]:e}))).reduce(((e,t)=>Object.assign(e,t)),{});r({n:s,m:` ⓘ Auto-mapped resolver params in task '${this.code}': %O`,mp:e,l:"d"}),c=Object.assign(e,c)}for(const[t,s]of Object.entries(c)){if("string"==typeof s)l=e[s];else if(Object.prototype.hasOwnProperty.call(s,"value"))l=s.value;else{const t=s.transform;l=o.select(e).transformWith(t).root()}u[t]=l}return u}mapResultsFromResolver(e,t,s,r){var o,n,i;if("object"!=typeof e)throw new Error(`Expected resolver for task '${this.code}' to return an object or Promise that resolves to object. Returned value is of type '${typeof e}'.`);const a={};let u=null!==(n=null===(o=this.spec.resolver)||void 0===o?void 0:o.results)&&void 0!==n?n:{};if(t){const e=(null!==(i=this.spec.provides)&&void 0!==i?i:[]).reduce(((e,t)=>Object.assign(e,{[t]:t})),{});r({n:s,m:` ⓘ Auto-mapped resolver results in task '${this.code}': %O`,mp:e,l:"d"}),u=Object.assign(e,u)}for(const[t,s]of Object.entries(u))Object.prototype.hasOwnProperty.call(e,t)&&(a[s]=e[t]);return a}parseSpec(){this.resetRunStatus()}}},405:function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ValueQueueManager=void 0;class s{static fromSerializable(e){const t=Object.keys(e),r=new s(t);return r.queues=e,r.nonEmptyQueues=t.reduce(((e,t)=>(r.queues[t].length>0&&e.add(t),e)),new Set),r}constructor(e){this.nonEmptyQueues=new Set,this.queueNames=[...e],this.queues=e.reduce(((e,t)=>(e[t]=[],e)),{})}push(e,t){if(!this.queueNames.includes(e))throw new Error(`Queue name ${e} does not exist in queue manager. Existing queues are: [${this.queueNames.join(", ")}].`);this.nonEmptyQueues.add(e),this.queues[e].push(t)}getEmptyQueueNames(){return this.queueNames.reduce(((e,t)=>(0===this.queues[t].length&&e.push(t),e)),[])}popAll(){return this.validateAllNonEmpty(),this.queueNames.reduce(((e,t)=>(e[t]=this.queues[t].shift(),0===this.queues[t].length&&this.nonEmptyQueues.delete(t),e)),{})}topAll(){return this.validateAllNonEmpty(),this.queueNames.reduce(((e,t)=>(e[t]=this.queues[t][0],e)),{})}toSerializable(){return JSON.parse(JSON.stringify(this.queues))}validateAllNonEmpty(){if(!this.allHaveContent())throw new Error(`Some of the queues are empty: [${this.getEmptyQueueNames().join(", ")}].`)}allHaveContent(){return this.nonEmptyQueues.size===this.queueNames.length}}t.ValueQueueManager=s},590:function(e,t,s){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,o)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),o=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),o(s(985),t),o(s(454),t),o(s(582),t)},582:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PauseResolver=t.StopResolver=t.LoopResolver=t.ArrayMapResolver=t.RepeaterResolver=t.SubFlowResolver=t.WaitResolver=t.ConditionalResolver=t.ThrowErrorResolver=t.EchoResolver=t.NoopResolver=void 0;const r=s(454),o=s(8);t.NoopResolver=class{exec(){return{}}},t.EchoResolver=class{exec(e){return{out:e.in}}},t.ThrowErrorResolver=class{exec(e){throw new Error(void 0!==e.message?e.message:"ThrowErrorResolver resolver has thrown an error")}},t.ConditionalResolver=class{exec(e){return e.condition?{onTrue:e.trueResult}:{onFalse:e.falseResult}}},t.WaitResolver=class{exec(e){return new Promise((t=>{setTimeout((()=>{t({result:e.result})}),e.ms)}))}},t.SubFlowResolver=class{async exec(e,t){let s=e.flowResolvers;void 0===s&&(s=t.$flowed.getResolvers());let o=await r.FlowManager.run(e.flowSpec,e.flowParams,e.flowExpectedResults,s,t,t.$flowed.flow.runStatus.runOptions);return"string"==typeof e.uniqueResult&&(o=o[e.uniqueResult]),{flowResult:o}}},t.RepeaterResolver=class{async exec(e,t,s,n,i){const a=t.$flowed.getResolverByName(e.resolver);if(null===a)throw new Error(`Task resolver '${e.resolver}' for inner flowed::Repeater task has no definition.`);const u=new r.Task("task-repeat-model",e.taskSpec),l=[];let c=[];for(let s=0;st[e.outItemName]))),{outCollection:d}}},t.StopResolver=class{exec(e,t){return{promise:t.$flowed.flow.stop()}}},t.PauseResolver=class{exec(e,t){return{promise:t.$flowed.flow.pause()}}}},985:function(e,t){"use strict";var s,r;Object.defineProperty(t,"__esModule",{value:!0}),t.TaskResolverMap=t.TaskResolver=t.FlowTransitionEnum=t.FlowStateEnum=void 0,(r=t.FlowStateEnum||(t.FlowStateEnum={})).Ready="Ready",r.Running="Running",r.Finished="Finished",r.Pausing="Pausing",r.Paused="Paused",r.Stopping="Stopping",r.Stopped="Stopped",(s=t.FlowTransitionEnum||(t.FlowTransitionEnum={})).Start="Start",s.Finished="Finished",s.Reset="Reset",s.Pause="Pause",s.Paused="Paused",s.Resume="Resume",s.Stop="Stop",s.Stopped="Stopped",t.TaskResolver=class{exec(e,t,s,r,o){return{}}},t.TaskResolverMap=class{}},227:function(e,t,s){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const s="color: "+this.color;t.splice(1,0,s,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,s)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=s(447)(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:function(e,t,s){e.exports=function(e){function t(e){let s,o,n,i=null;function a(...e){if(!a.enabled)return;const r=a,o=Number(new Date),n=o-(s||o);r.diff=n,r.prev=s,r.curr=o,s=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((s,o)=>{if("%%"===s)return"%";i++;const n=t.formatters[o];if("function"==typeof n){const t=e[i];s=n.call(r,t),e.splice(i,1),i--}return s})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(o!==t.namespaces&&(o=t.namespaces,n=t.enabled(e)),n),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,s){const r=t(this.namespace+(void 0===s?":":s)+e);return r.log=this.log,r}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(o),...t.skips.map(o).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let s;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(s=0;s{t[s]=e[s]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let s=0;for(let t=0;t0&&e.length-1 in e)},resolve:function(e,t,s){return t&&t.length>0?Function("new_val","with(this) {this"+t+"=new_val; return this;}").bind(e)(s):e=s}},r={run:function(e,t){for(var s=0;s0&&"#"===t[0][0]?{name:t.shift(),expression:t.join(" ")}:null},run:function(e,t){var n,i;if("string"==typeof e)s.is_template(e)?/\{\{([ ]*#include)[ ]*([^ ]*)\}\}/g.test(e)?(i=o.tokenize(e),n=i.expression?o.fillout(t,"{{"+i.expression+"}}",!0):e):n=o.fillout(t,e):n=e;else if(s.is_array(e))if(r.is(e))n=r.run(e,t);else{n=[];for(var a=0;a0&&(i=o.tokenize(c[0]),n=i.expression?o.fillout(e[c[0]],"{{"+i.expression+"}}",!0):e[c[0]]),e)if(s.is_template(d))if(i=o.tokenize(d)){if("#include"===i.name);else if("#let"===i.name){if(s.is_array(e[d])&&2===e[d].length){var p=e[d][0],h=e[d][1],f=o.run(p,t);for(var m in f)o.memory[m]=f[m],t[m]=f[m];n=o.run(h,t)}}else if("#concat"===i.name)s.is_array(e[d])&&(n=[],e[d].forEach((function(e){var s=o.run(e,t);n=n.concat(s)})));else if("#merge"===i.name){if(s.is_array(e[d]))if(n={},e[d].forEach((function(e){var s=o.run(e,t);for(var r in s)n[r]=s[r]})),"object"==typeof t)for(var g in delete n.$index,o.memory)delete n[g];else for(g in delete String.prototype.$index,delete Number.prototype.$index,delete Function.prototype.$index,delete Array.prototype.$index,delete Boolean.prototype.$index,o.memory)delete String.prototype[g],delete Number.prototype[g],delete Function.prototype[g],delete Array.prototype[g],delete Boolean.prototype[g]}else if("#each"===i.name){var v=o.fillout(t,"{{"+i.expression+"}}",!0);if(v&&s.is_array(v)){n=[];for(var y=0;y0&&n.select(n.$injected),n},select:function(e,t,r){var o=e;try{r&&(o=JSON.parse(e))}catch(e){}return t?(n.$selected=[],n.exec(o,"",t)):n.$selected=null,o&&(s.is_array(o)||"object"==typeof o)?(n.$progress||(s.is_array(o)?(n.$val=[],n.$selected_root=[]):(n.$val={},n.$selected_root={})),Object.keys(o).forEach((function(e){n.$val[e]=o[e],n.$selected_root[e]=o[e]}))):(n.$val=o,n.$selected_root=o),n.$progress=!0,n},transformWith:function(e,r){n.$parsed=[],n.$progress=null;var i=e;try{r&&(i=JSON.parse(e))}catch(e){}if(n.$template_root=i,String.prototype.$root=n.$selected_root,Number.prototype.$root=n.$selected_root,Function.prototype.$root=n.$selected_root,Array.prototype.$root=n.$selected_root,Boolean.prototype.$root=n.$selected_root,t=n.$selected_root,n.$selected&&n.$selected.length>0)n.$selected.sort((function(e,t){return t.path.length-e.path.length})).forEach((function(e){var t=o.run(i,e.object);n.$selected_root=s.resolve(n.$selected_root,e.path,t),e.object=t})),n.$selected.sort((function(e,t){return e.index-t.index}));else{var a=o.run(i,n.$selected_root);n.$selected_root=s.resolve(n.$selected_root,"",a)}return delete String.prototype.$root,delete Number.prototype.$root,delete Function.prototype.$root,delete Array.prototype.$root,delete Boolean.prototype.$root,n},transform:function(e,r){n.$parsed=[],n.$progress=null;var i=e;try{r&&(i=JSON.parse(e))}catch(e){}if(n.$template_root=n.$selected_root,String.prototype.$root=i,Number.prototype.$root=i,Function.prototype.$root=i,Array.prototype.$root=i,Boolean.prototype.$root=i,t=i,n.$selected&&n.$selected.length>0)n.$selected.sort((function(e,t){return t.path.length-e.path.length})).forEach((function(e){var t=o.run(e.object,i);n.$template_root=s.resolve(n.$template_root,e.path,t),n.$selected_root=n.$template_root,e.object=t})),n.$selected.sort((function(e,t){return e.index-t.index}));else{var a=o.run(n.$selected_root,i);n.$template_root=s.resolve(n.$template_root,"",a),n.$selected_root=n.$template_root}return delete String.prototype.$root,delete Number.prototype.$root,delete Function.prototype.$root,delete Array.prototype.$root,delete Boolean.prototype.$root,n},objects:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.object})):[n.$selected_root]},keys:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.key})):Array.isArray(n.$selected_root)?Object.keys(n.$selected_root).map((function(e){return parseInt(e)})):Object.keys(n.$selected_root)},paths:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.path})):Array.isArray(n.$selected_root)?Object.keys(n.$selected_root).map((function(e){return"["+e+"]"})):Object.keys(n.$selected_root).map((function(e){return'["'+e+'"]'}))},values:function(){return n.$progress=null,n.$selected?n.$selected.map((function(e){return e.value})):Object.values(n.$selected_root)},root:function(){return n.$progress=null,n.$selected_root}},i=JSON.stringify,a=function(e,t,s){return-1!==["number","string","boolean"].indexOf(typeof e)?i(e,t,s):i(e,t||function(e,t){if(!(n.$injected&&n.$injected.length>0&&-1!==n.$injected.indexOf(e)||"$root"===e||"$index"===e||e in o.memory))return"function"==typeof t?"("+t.toString()+")":t},s)};JSON.stringify2=a;var u={TRANSFORM:o,SELECT:n,Conditional:r,Helper:s,inject:n.inject,select:n.select,transform:o.transform};e.exports&&(e.exports=u)}()},824:function(e){var t=1e3,s=60*t,r=60*s,o=24*r;function n(e,t,s,r){var o=t>=1.5*s;return Math.round(e/s)+" "+r+(o?"s":"")}e.exports=function(e,i){i=i||{};var a,u,l=typeof e;if("string"===l&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var n=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(n){var i=parseFloat(n[1]);switch((n[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return 6048e5*i;case"days":case"day":case"d":return i*o;case"hours":case"hour":case"hrs":case"hr":case"h":return i*r;case"minutes":case"minute":case"mins":case"min":case"m":return i*s;case"seconds":case"second":case"secs":case"sec":case"s":return i*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(e);if("number"===l&&isFinite(e))return i.long?(a=e,(u=Math.abs(a))>=o?n(a,u,o,"day"):u>=r?n(a,u,r,"hour"):u>=s?n(a,u,s,"minute"):u>=t?n(a,u,t,"second"):a+" ms"):function(e){var n=Math.abs(e);return n>=o?Math.round(e/o)+"d":n>=r?Math.round(e/r)+"h":n>=s?Math.round(e/s)+"m":n>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},673:function(){},883:function(){},316:function(){}},t={},function s(r){var o=t[r];if(void 0!==o)return o.exports;var n=t[r]={exports:{}};return e[r].call(n.exports,n,n.exports,s),n.exports}(590);var e,t})); \ No newline at end of file