aws-local-stepfunctions 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-local-stepfunctions",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Execute an AWS Step Function locally",
5
5
  "keywords": [
6
6
  "aws",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "scripts": {
36
36
  "test": "jest",
37
- "build": "bunchee --minify src/main.ts",
37
+ "build": "tsup",
38
38
  "prettier": "prettier --write src/**/*.ts",
39
39
  "lint": "eslint src/**/*.ts",
40
40
  "lint:fix": "eslint src/**/*.ts --fix"
@@ -47,12 +47,12 @@
47
47
  "@types/picomatch": "^2.3.0",
48
48
  "@typescript-eslint/eslint-plugin": "^5.22.0",
49
49
  "@typescript-eslint/parser": "^5.22.0",
50
- "bunchee": "^2.2.0",
51
50
  "eslint": "^8.14.0",
52
51
  "eslint-config-prettier": "^8.5.0",
53
52
  "eslint-plugin-prettier": "^4.0.0",
54
53
  "prettier": "^2.6.2",
55
54
  "ts-jest": "^29.0.3",
55
+ "tsup": "^6.6.3",
56
56
  "typescript": "^4.6.4"
57
57
  },
58
58
  "dependencies": {
package/build/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var clientLambda=require("@aws-sdk/client-lambda"),jsonpathPlus=require("jsonpath-plus"),cloneDeep=require("lodash/cloneDeep.js"),set=require("lodash/set.js"),pLimit=require("p-limit"),wcmatch=require("wildcard-match"),aslValidator=require("asl-validator");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var cloneDeep__default=_interopDefaultLegacy(cloneDeep),set__default=_interopDefaultLegacy(set),pLimit__default=_interopDefaultLegacy(pLimit),wcmatch__default=_interopDefaultLegacy(wcmatch),aslValidator__default=_interopDefaultLegacy(aslValidator);class BaseStateHandler{buildExecutionResult(e){let t={stateResult:e,nextState:"",isEndState:!1};return"Next"in this.stateDefinition&&(t.nextState=this.stateDefinition.Next),"End"in this.stateDefinition&&(t.isEndState=this.stateDefinition.End),t}constructor(e){this.stateDefinition=e}}class CustomError extends Error{constructor(e){super(e)}}class LambdaExecutionError extends CustomError{toString(){return`${this.name}: ${this.message}. The error thrown by the Lambda was:
2
- ${this.wrappedError.stack}`}constructor(e,t){super(`Execution of Lambda function "${t}" failed`),this.name="LambdaExecutionError",this.wrappedError=Error(e.errorMessage),this.wrappedError.stack=e.trace.join("\n")}}function asyncGeneratorStep$8(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$8(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$8(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$8(i,n,a,s,o,"throw",e)}s(void 0)})}}class LambdaClient{invokeFunction(e,t){var r=this;return _asyncToGenerator$8(function*(){let n=Buffer.from(JSON.stringify(t)),a=new clientLambda.InvokeCommand({FunctionName:e,Payload:n}),i=yield r.client.send(a),s=null;if(i.Payload&&(s=JSON.parse(s=Buffer.from(i.Payload).toString())),i.FunctionError)throw new LambdaExecutionError(s,e);return s})()}constructor(e){this.client=new clientLambda.LambdaClient(null!=e?e:{})}}function asyncGeneratorStep$7(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$7(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$7(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$7(i,n,a,s,o,"throw",e)}s(void 0)})}}class TaskStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$7(function*(){let t=n.stateDefinition,a=new LambdaClient;try{if(null==r?void 0:r.overrideFn){let i=yield r.overrideFn(e);return n.buildExecutionResult(i)}let s=yield a.invokeFunction(t.Resource,e);return n.buildExecutionResult(s)}catch(o){throw o instanceof LambdaExecutionError?console.error(o.toString()):console.error(o),o}})()}constructor(e){super(e)}}function jsonPathQuery(e,t,r){return e.startsWith("$$")?jsonpathPlus.JSONPath({path:e.slice(1),json:null!=r?r:null,wrap:!1}):jsonpathPlus.JSONPath({path:e,json:t,wrap:!1})}function isPlainObj(e){return!!e&&Object.getPrototypeOf(e)===Object.prototype}function sleep(e,t){return new Promise(r=>{let n=setTimeout(r,e);null==t||t.addEventListener("abort",()=>{n.unref()})})}function processInputPath(e,t,r){return void 0===e?t:null===e?{}:jsonPathQuery(e,t,r)}function processPayloadTemplate(e,t,r){let n=Object.entries(e).map(([e,n])=>{let a=e,i=n;return isPlainObj(n)&&(i=processPayloadTemplate(n,t)),e.endsWith(".$")&&"string"==typeof n&&(a=e.replace(".$",""),i=jsonPathQuery(n,t,r)),[a,i]});return Object.fromEntries(n)}function processResultPath(e,t,r){if(void 0===e)return r;if(null===e)return t;let n=e.replace("$.","");if(isPlainObj(t)){let a=cloneDeep__default.default(t);return set__default.default(a,n,r)}throw Error("TODO: Change this error message for a more descriptive one")}function processOutputPath(e,t,r){return void 0===e?t:null===e?{}:jsonPathQuery(e,t,r)}function asyncGeneratorStep$6(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$6(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$6(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$6(i,n,a,s,o,"throw",e)}s(void 0)})}}class MapStateHandler extends BaseStateHandler{processItem(e,t,r,n,a){let i;let s=this.stateDefinition;r.Map={Item:{Index:n,Value:e}},s.Parameters&&(i=processPayloadTemplate(s.Parameters,t,r));let o=new StateMachine(s.Iterator,null==a?void 0:a.validationOptions),{result:u}=o.run(null!=i?i:e,null==a?void 0:a.runOptions);return u}executeState(e,t,r){var n=this;return _asyncToGenerator$6(function*(){let a=n.stateDefinition,i=e;if(a.ItemsPath&&(i=jsonPathQuery(a.ItemsPath,e,t)),!Array.isArray(i))return n.buildExecutionResult([]);let s=pLimit__default.default(a.MaxConcurrency||40),o=i.map((a,i)=>s(()=>n.processItem(a,e,t,i,r))),u=yield Promise.all(o);return delete t.Map,n.buildExecutionResult(u)})()}constructor(e){super(e)}}function asyncGeneratorStep$5(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$5(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$5(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$5(i,n,a,s,o,"throw",e)}s(void 0)})}}class PassStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$5(function*(){return n.stateDefinition.Result?n.buildExecutionResult(n.stateDefinition.Result):n.buildExecutionResult(e)})()}constructor(e){super(e)}}function asyncGeneratorStep$4(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$4(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$4(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$4(i,n,a,s,o,"throw",e)}s(void 0)})}}class WaitStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$4(function*(){let a=n.stateDefinition;if((null==r?void 0:r.waitTimeOverrideOption)!==void 0)return yield sleep(r.waitTimeOverrideOption,r.abortSignal),n.buildExecutionResult(e);if(a.Seconds)yield sleep(1e3*a.Seconds,null==r?void 0:r.abortSignal);else if(a.Timestamp){let i=new Date(a.Timestamp),s=Date.now(),o=i.getTime()-s;yield sleep(o,null==r?void 0:r.abortSignal)}else if(a.SecondsPath){let u=jsonPathQuery(a.SecondsPath,e,t);yield sleep(1e3*u,null==r?void 0:r.abortSignal)}else if(a.TimestampPath){let l=jsonPathQuery(a.TimestampPath,e,t),c=new Date(l),h=Date.now(),d=c.getTime()-h;yield sleep(d,null==r?void 0:r.abortSignal)}return n.buildExecutionResult(e)})()}constructor(e){super(e)}}function asyncGeneratorStep$3(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$3(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$3(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$3(i,n,a,s,o,"throw",e)}s(void 0)})}}class ChoiceStateHandler extends BaseStateHandler{testChoiceRule(e,t){if("And"in e)return e.And.every(e=>this.testChoiceRule(e,t));if("Or"in e)return e.Or.some(e=>this.testChoiceRule(e,t));if("Not"in e)return!this.testChoiceRule(e.Not,t);if("StringEquals"in e){let r=jsonPathQuery(e.Variable,t);return r===e.StringEquals}if("StringEqualsPath"in e){let n=jsonPathQuery(e.Variable,t),a=jsonPathQuery(e.StringEqualsPath,t);return n===a}if("StringLessThan"in e){let i=jsonPathQuery(e.Variable,t);return i<e.StringLessThan}if("StringLessThanPath"in e){let s=jsonPathQuery(e.Variable,t),o=jsonPathQuery(e.StringLessThanPath,t);return s<o}if("StringGreaterThan"in e){let u=jsonPathQuery(e.Variable,t);return u>e.StringGreaterThan}if("StringGreaterThanPath"in e){let l=jsonPathQuery(e.Variable,t),c=jsonPathQuery(e.StringGreaterThanPath,t);return l>c}if("StringLessThanEquals"in e){let h=jsonPathQuery(e.Variable,t);return h<=e.StringLessThanEquals}if("StringLessThanEqualsPath"in e){let d=jsonPathQuery(e.Variable,t),f=jsonPathQuery(e.StringLessThanEqualsPath,t);return d<=f}if("StringGreaterThanEquals"in e){let p=jsonPathQuery(e.Variable,t);return p>=e.StringGreaterThanEquals}if("StringGreaterThanEqualsPath"in e){let y=jsonPathQuery(e.Variable,t),P=jsonPathQuery(e.StringGreaterThanEqualsPath,t);return y>=P}if("StringMatches"in e){let m=jsonPathQuery(e.Variable,t),S=wcmatch__default.default(e.StringMatches,{separator:!1});return S(m)}if("NumericEquals"in e){let T=jsonPathQuery(e.Variable,t);return T===e.NumericEquals}if("NumericEqualsPath"in e){let v=jsonPathQuery(e.Variable,t),b=jsonPathQuery(e.NumericEqualsPath,t);return v===b}if("NumericLessThan"in e){let E=jsonPathQuery(e.Variable,t);return E<e.NumericLessThan}if("NumericLessThanPath"in e){let x=jsonPathQuery(e.Variable,t),w=jsonPathQuery(e.NumericLessThanPath,t);return x<w}if("NumericGreaterThan"in e){let j=jsonPathQuery(e.Variable,t);return j>e.NumericGreaterThan}if("NumericGreaterThanPath"in e){let G=jsonPathQuery(e.Variable,t),Q=jsonPathQuery(e.NumericGreaterThanPath,t);return G>Q}if("NumericLessThanEquals"in e){let g=jsonPathQuery(e.Variable,t);return g<=e.NumericLessThanEquals}if("NumericLessThanEqualsPath"in e){let _=jsonPathQuery(e.Variable,t),D=jsonPathQuery(e.NumericLessThanEqualsPath,t);return _<=D}if("NumericGreaterThanEquals"in e){let L=jsonPathQuery(e.Variable,t);return L>=e.NumericGreaterThanEquals}if("NumericGreaterThanEqualsPath"in e){let $=jsonPathQuery(e.Variable,t),q=jsonPathQuery(e.NumericGreaterThanEqualsPath,t);return $>=q}if("BooleanEquals"in e){let V=jsonPathQuery(e.Variable,t);return V===e.BooleanEquals}if("BooleanEqualsPath"in e){let O=jsonPathQuery(e.Variable,t),N=jsonPathQuery(e.BooleanEqualsPath,t);return O===N}if("TimestampEquals"in e){let R=new Date(jsonPathQuery(e.Variable,t)),I=new Date(e.TimestampEquals);return R.getTime()===I.getTime()}if("TimestampEqualsPath"in e){let H=new Date(jsonPathQuery(e.Variable,t)),C=new Date(jsonPathQuery(e.TimestampEqualsPath,t));return H.getTime()===C.getTime()}if("TimestampLessThan"in e){let M=new Date(jsonPathQuery(e.Variable,t)),B=new Date(e.TimestampLessThan);return M<B}if("TimestampLessThanPath"in e){let k=new Date(jsonPathQuery(e.Variable,t)),A=new Date(jsonPathQuery(e.TimestampLessThanPath,t));return k<A}if("TimestampGreaterThan"in e){let F=new Date(jsonPathQuery(e.Variable,t)),W=new Date(e.TimestampGreaterThan);return F>W}if("TimestampGreaterThanPath"in e){let J=new Date(jsonPathQuery(e.Variable,t)),Z=new Date(jsonPathQuery(e.TimestampGreaterThanPath,t));return J>Z}if("TimestampLessThanEquals"in e){let z=new Date(jsonPathQuery(e.Variable,t)),K=new Date(e.TimestampLessThanEquals);return z<=K}if("TimestampLessThanEqualsPath"in e){let U=new Date(jsonPathQuery(e.Variable,t)),X=new Date(jsonPathQuery(e.TimestampLessThanEqualsPath,t));return U<=X}if("TimestampGreaterThanEquals"in e){let Y=new Date(jsonPathQuery(e.Variable,t)),ee=new Date(e.TimestampGreaterThanEquals);return Y>=ee}if("TimestampGreaterThanEqualsPath"in e){let et=new Date(jsonPathQuery(e.Variable,t)),er=new Date(jsonPathQuery(e.TimestampGreaterThanEqualsPath,t));return et>=er}if("IsNull"in e){let en=jsonPathQuery(e.Variable,t),ea=e.IsNull;return ea&&null===en}if("IsPresent"in e){let ei=jsonPathQuery(e.Variable,t),es=e.IsPresent;return es&&void 0!==ei}if("IsNumeric"in e){let eo=jsonPathQuery(e.Variable,t),eu=e.IsNumeric;return eu&&"number"==typeof eo}if("IsString"in e){let el=jsonPathQuery(e.Variable,t),ec=e.IsString;return ec&&"string"==typeof el}if("IsBoolean"in e){let eh=jsonPathQuery(e.Variable,t),ed=e.IsBoolean;return ed&&"boolean"==typeof eh}if("IsTimestamp"in e){let ef=jsonPathQuery(e.Variable,t),ep=e.IsTimestamp;return ep&&/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|(\+|-)\d{2}:\d{2})/.test(ef)}return!1}executeState(e,t,r){var n=this;return _asyncToGenerator$3(function*(){let t=n.stateDefinition;for(let r of t.Choices){let a=n.testChoiceRule(r,e);if(a)return{stateResult:e,nextState:r.Next,isEndState:!1}}if(t.Default)return{stateResult:e,nextState:t.Default,isEndState:!1};throw Error("States.NoChoiceMatched")})()}constructor(e){super(e)}}function asyncGeneratorStep$2(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$2(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$2(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$2(i,n,a,s,o,"throw",e)}s(void 0)})}}class SucceedStateHandler extends BaseStateHandler{executeState(e,t,r){return _asyncToGenerator$2(function*(){return{stateResult:e,nextState:"",isEndState:!0}})()}constructor(e){super(e)}}function asyncGeneratorStep$1(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$1(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$1(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$1(i,n,a,s,o,"throw",e)}s(void 0)})}}class FailStateHandler extends BaseStateHandler{executeState(e,t,r){return _asyncToGenerator$1(function*(){return{stateResult:e,nextState:"",isEndState:!0}})()}constructor(e){super(e)}}class ExecutionAbortedError extends CustomError{toString(){return"Execution aborted"}constructor(){super("Execution aborted"),this.name="ExecutionAbortedError"}}function asyncGeneratorStep(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep(i,n,a,s,o,"throw",e)}s(void 0)})}}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}class StateMachine{run(e,t){let r=new AbortController,n=new Promise((e,n)=>{(null==t?void 0:t.noThrowOnAbort)?r.signal.addEventListener("abort",()=>e(null)):r.signal.addEventListener("abort",()=>n(new ExecutionAbortedError))}),a=this.execute(e,{runOptions:t,abortSignal:r.signal}),i=Promise.race([a,n]);return{abort:()=>r.abort(),result:i}}execute(e,t){var r=this;return _asyncToGenerator(function*(){let n=r.definition.States[r.definition.StartAt],a=r.definition.StartAt,i=cloneDeep__default.default(e),s=cloneDeep__default.default(e),o=null,u="",l=!1,c={};do s=r.processInput(n,s,c),({stateResult:o,nextState:u,isEndState:l}=yield r.stateExecutors[n.Type](n,s,c,a,t)),i=o=r.processResult(n,o,i,c),s=o,n=r.definition.States[u],a=u;while(!l&&!t.abortSignal.aborted);return o})()}processInput(e,t,r){let n=t;return"InputPath"in e&&(n=processInputPath(e.InputPath,n,r)),"Parameters"in e&&"Map"!==e.Type&&(n=processPayloadTemplate(e.Parameters,n,r)),n}processResult(e,t,r,n){let a=t;return"ResultSelector"in e&&(a=processPayloadTemplate(e.ResultSelector,a,n)),"ResultPath"in e&&(a=processResultPath(e.ResultPath,r,a)),"OutputPath"in e&&(a=processOutputPath(e.OutputPath,a,n)),a}executeTaskState(e,t,r,n,a){return _asyncToGenerator(function*(){var i,s,o;let u=null==(i=a.runOptions)?void 0:null==(s=i.overrides)?void 0:null==(o=s.taskResourceLocalHandlers)?void 0:o[n],l=new TaskStateHandler(e),c=yield l.executeState(t,r,{overrideFn:u});return c})()}executeMapState(e,t,r,n,a){var i=this;return _asyncToGenerator(function*(){let n=new MapStateHandler(e),s=yield n.executeState(t,r,{validationOptions:i.validationOptions,runOptions:a.runOptions});return s})()}executePassState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new PassStateHandler(e),a=yield n.executeState(t,r);return a})()}executeWaitState(e,t,r,n,a){return _asyncToGenerator(function*(){var i,s,o;let u=null==(i=a.runOptions)?void 0:null==(s=i.overrides)?void 0:null==(o=s.waitTimeOverrides)?void 0:o[n],l=a.abortSignal,c=new WaitStateHandler(e),h=yield c.executeState(t,r,{waitTimeOverrideOption:u,abortSignal:l});return h})()}executeChoiceState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new ChoiceStateHandler(e),a=yield n.executeState(t,r);return a})()}executeSucceedState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new SucceedStateHandler(e),a=yield n.executeState(t,r);return a})()}executeFailState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new FailStateHandler(e),a=yield n.executeState(t,r);return a})()}constructor(e,t){let{isValid:r,errorsText:n}=aslValidator__default.default(e,_extends({checkArn:!0,checkPaths:!0},t));if(!r)throw Error(`State machine definition is invalid, see error(s) below:
3
- ${n("\n")}`);this.definition=e,this.stateExecutors={Task:this.executeTaskState,Map:this.executeMapState,Pass:this.executePassState,Wait:this.executeWaitState,Choice:this.executeChoiceState,Succeed:this.executeSucceedState,Fail:this.executeFailState},this.validationOptions=t}}exports.ExecutionAbortedError=ExecutionAbortedError,exports.StateMachine=StateMachine;
package/build/main.d.ts DELETED
@@ -1,285 +0,0 @@
1
- declare type StateType = 'Task' | 'Map' | 'Pass' | 'Wait' | 'Choice' | 'Succeed' | 'Fail';
2
-
3
- interface BaseState {
4
- Type: StateType;
5
- Comment?: string;
6
- }
7
-
8
- declare type PayloadTemplate = object;
9
- interface CanHaveInputPath {
10
- InputPath?: string | null;
11
- }
12
- interface CanHaveParameters {
13
- Parameters?: PayloadTemplate;
14
- }
15
- interface CanHaveResultSelector {
16
- ResultSelector?: PayloadTemplate;
17
- }
18
- interface CanHaveResultPath {
19
- ResultPath?: string | null;
20
- }
21
- interface CanHaveOutputPath {
22
- OutputPath?: string | null;
23
- }
24
-
25
- declare type StringOperatorNames = 'StringEquals' | 'StringLessThan' | 'StringGreaterThan' | 'StringLessThanEquals' | 'StringGreaterThanEquals' | 'StringMatches';
26
- declare type StringPathOperatorNames = 'StringEqualsPath' | 'StringLessThanPath' | 'StringGreaterThanPath' | 'StringLessThanEqualsPath' | 'StringGreaterThanEqualsPath';
27
- declare type NumericOperatorNames = 'NumericEquals' | 'NumericLessThan' | 'NumericGreaterThan' | 'NumericLessThanEquals' | 'NumericGreaterThanEquals';
28
- declare type NumericPathOperatorNames = 'NumericEqualsPath' | 'NumericLessThanPath' | 'NumericGreaterThanPath' | 'NumericLessThanEqualsPath' | 'NumericGreaterThanEqualsPath';
29
- declare type BooleanOperatorNames = 'BooleanEquals';
30
- declare type BooleanPathOperatorNames = 'BooleanEqualsPath';
31
- declare type TimestampOperatorNames = 'TimestampEquals' | 'TimestampLessThan' | 'TimestampGreaterThan' | 'TimestampLessThanEquals' | 'TimestampGreaterThanEquals';
32
- declare type TimestampPathOperatorNames = 'TimestampEqualsPath' | 'TimestampLessThanPath' | 'TimestampGreaterThanPath' | 'TimestampLessThanEqualsPath' | 'TimestampGreaterThanEqualsPath';
33
- declare type TypeTestOperatorNames = 'IsNull' | 'IsPresent' | 'IsNumeric' | 'IsString' | 'IsBoolean' | 'IsTimestamp';
34
- declare type StringComparisonOperator = {
35
- [P in StringOperatorNames]?: string;
36
- };
37
- declare type StringPathComparisonOperator = {
38
- [P in StringPathOperatorNames]?: string;
39
- };
40
- declare type NumericComparisonOperator = {
41
- [P in NumericOperatorNames]?: number;
42
- };
43
- declare type NumericPathComparisonOperator = {
44
- [P in NumericPathOperatorNames]?: string;
45
- };
46
- declare type BooleanComparisonOperator = {
47
- [P in BooleanOperatorNames]?: boolean;
48
- };
49
- declare type BooleanPathComparisonOperator = {
50
- [P in BooleanPathOperatorNames]?: string;
51
- };
52
- declare type TimestampComparisonOperator = {
53
- [P in TimestampOperatorNames]?: string;
54
- };
55
- declare type TimestampPathComparisonOperator = {
56
- [P in TimestampPathOperatorNames]?: string;
57
- };
58
- declare type TypeTestComparisonOperator = {
59
- [P in TypeTestOperatorNames]?: true;
60
- };
61
- declare type ComparisonOperator = StringComparisonOperator | StringPathComparisonOperator | NumericComparisonOperator | NumericPathComparisonOperator | BooleanComparisonOperator | BooleanPathComparisonOperator | TimestampComparisonOperator | TimestampPathComparisonOperator | TypeTestComparisonOperator;
62
- declare type BaseDataTestExpression = {
63
- Variable: string;
64
- };
65
- declare type DataTestExpression = BaseDataTestExpression & ComparisonOperator;
66
- declare type BooleanExpression = {
67
- And?: ChoiceRuleWithoutNext[];
68
- Or?: ChoiceRuleWithoutNext[];
69
- Not?: ChoiceRuleWithoutNext;
70
- };
71
- declare type ChoiceRuleWithoutNext = DataTestExpression | BooleanExpression;
72
- declare type ChoiceRule = (DataTestExpression | BooleanExpression) & {
73
- Next: string;
74
- };
75
- interface BaseChoiceState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
76
- Type: 'Choice';
77
- Choices: ChoiceRule[];
78
- Default?: string;
79
- }
80
- declare type ChoiceState = BaseChoiceState;
81
-
82
- interface EndableState extends BaseState {
83
- Type: Exclude<StateType, 'Choice' | 'Succeed' | 'Fail'>;
84
- End: true;
85
- }
86
- interface SucceedOrFailState extends BaseState {
87
- Type: Extract<StateType, 'Succeed' | 'Fail'>;
88
- }
89
- declare type TerminalState = EndableState | SucceedOrFailState;
90
-
91
- interface BaseFailState extends BaseState {
92
- Type: 'Fail';
93
- Cause?: string;
94
- Error?: string;
95
- }
96
- declare type FailState = TerminalState & BaseFailState;
97
-
98
- interface NextableState extends BaseState {
99
- Type: Exclude<StateType, 'Choice' | 'Succeed' | 'Fail'>;
100
- Next: string;
101
- }
102
- declare type IntermediateState = NextableState;
103
-
104
- interface BaseMapState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath {
105
- Type: 'Map';
106
- Iterator: Omit<StateMachineDefinition, 'Version' | 'TimeoutSeconds'>;
107
- ItemsPath?: string;
108
- MaxConcurrency?: number;
109
- }
110
- declare type MapState = (IntermediateState | TerminalState) & BaseMapState;
111
-
112
- declare type JSONValue = null | boolean | number | string | object | JSONValue[];
113
-
114
- interface BasePassState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultPath, CanHaveOutputPath {
115
- Type: 'Pass';
116
- Result?: JSONValue;
117
- }
118
- declare type PassState = (IntermediateState | TerminalState) & BasePassState;
119
-
120
- interface BaseSucceedState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
121
- Type: 'Succeed';
122
- }
123
- declare type SucceedState = TerminalState & BaseSucceedState;
124
-
125
- interface BaseTaskState extends BaseState, CanHaveInputPath, CanHaveParameters, CanHaveResultSelector, CanHaveResultPath, CanHaveOutputPath {
126
- Type: 'Task';
127
- Resource: string;
128
- }
129
- declare type TaskState = (IntermediateState | TerminalState) & BaseTaskState;
130
-
131
- interface BaseWaitState extends BaseState, CanHaveInputPath, CanHaveOutputPath {
132
- Type: 'Wait';
133
- Seconds?: number;
134
- Timestamp?: string;
135
- SecondsPath?: string;
136
- TimestampPath?: string;
137
- }
138
- declare type WaitState = (IntermediateState | TerminalState) & BaseWaitState;
139
-
140
- declare type AllStates = TaskState | MapState | PassState | WaitState | ChoiceState | SucceedState | FailState;
141
-
142
- interface StateMachineDefinition {
143
- States: Record<string, AllStates>;
144
- StartAt: string;
145
- Comment?: string;
146
- Version?: string;
147
- TimeoutSeconds?: number;
148
- }
149
-
150
- declare type TaskStateResourceLocalHandler = {
151
- [taskStateName: string]: (input: JSONValue) => Promise<JSONValue>;
152
- };
153
- declare type WaitStateTimeOverride = {
154
- [waitStateName: string]: number;
155
- };
156
- interface Overrides {
157
- taskResourceLocalHandlers?: TaskStateResourceLocalHandler;
158
- waitTimeOverrides?: WaitStateTimeOverride;
159
- }
160
- interface RunOptions {
161
- overrides?: Overrides;
162
- noThrowOnAbort?: boolean;
163
- }
164
- interface ValidationOptions {
165
- readonly checkPaths?: boolean;
166
- readonly checkArn?: boolean;
167
- }
168
-
169
- declare class StateMachine {
170
- /**
171
- * The structure of the State Machine as represented by the Amazon States Language.
172
- */
173
- private readonly definition;
174
- /**
175
- * A map of functions to execute each type of state.
176
- */
177
- private readonly stateExecutors;
178
- /**
179
- * Options to control whether to apply certain validations to the state machine definition.
180
- */
181
- private readonly validationOptions;
182
- /**
183
- * Constructs a new state machine.
184
- * @param definition The state machine definition defined using the Amazon States Language (https://states-language.net/spec.html).
185
- * @param validationOptions Options to control whether to apply certain validations to the definition.
186
- * These options also apply to state machines defined in the `Iterator` field of `Map` states.
187
- */
188
- constructor(definition: StateMachineDefinition, validationOptions?: ValidationOptions);
189
- /**
190
- * Executes the state machine, running through the states specified in the definition.
191
- *
192
- * By default, if the execution is aborted, the result will throw an `ExecutionAbortedError`. This behavior can be changed by setting
193
- * the `noThrowOnAbort` option to `true`, in which case the result will be `null`.
194
- *
195
- * @param input The input to pass to this state machine execution.
196
- * @param options Miscellaneous options to control certain behaviors of the execution.
197
- */
198
- run(input: JSONValue, options?: RunOptions): {
199
- abort: () => void;
200
- result: Promise<JSONValue>;
201
- };
202
- /**
203
- * Helper method that handles the execution of the machine states and the transitions between them.
204
- */
205
- private execute;
206
- /**
207
- * Process the current input according to the `InputPath` and `Parameters` fields.
208
- */
209
- private processInput;
210
- /**
211
- * Process the current result according to the `ResultSelector`, `ResultPath` and `OutputPath` fields.
212
- */
213
- private processResult;
214
- /**
215
- * Handler for task states.
216
- *
217
- * Invokes the Lambda function specified in the `Resource` field
218
- * and sets the current result of the state machine to the value returned by the Lambda.
219
- */
220
- private executeTaskState;
221
- /**
222
- * Handler for map states.
223
- *
224
- * Iterates over the current input items or the items of an array specified
225
- * by the `ItemsPath` field, and then processes each item by passing it
226
- * as the input to the state machine specified in the `Iterator` field.
227
- */
228
- private executeMapState;
229
- /**
230
- * Handler for pass states.
231
- *
232
- * If the `Result` field is specified, copies `Result` into the current result.
233
- * Else, copies the current input into the current result.
234
- */
235
- private executePassState;
236
- /**
237
- * Handler for wait states.
238
- *
239
- * Pauses the state machine execution for a certain amount of time
240
- * based on one of the `Seconds`, `Timestamp`, `SecondsPath` or `TimestampPath` fields.
241
- */
242
- private executeWaitState;
243
- /**
244
- * Handler for choice states.
245
- *
246
- * Evaluates each choice rule specified in the `Choices` field.
247
- *
248
- * If one of the rules matches, then the state machine transitions to the
249
- * state specified in the `Next` field for that choice rule.
250
- *
251
- * If no rule matches but the `Default` field is specified,
252
- * then the next state will be the state specified in said field.
253
- *
254
- * If no rule matches and the `Default` field is not specified, throws a
255
- * States.NoChoiceMatched error.
256
- */
257
- private executeChoiceState;
258
- /**
259
- * Handler for succeed states.
260
- *
261
- * Ends the state machine execution successfully.
262
- */
263
- private executeSucceedState;
264
- /**
265
- * Handler for fail states.
266
- *
267
- * Ends the state machine execution and marks it as a failure.
268
- */
269
- private executeFailState;
270
- }
271
-
272
- declare abstract class CustomError extends Error {
273
- constructor(message?: string);
274
- abstract toString(): string;
275
- }
276
-
277
- /**
278
- * Represents the abortion of a state machine execution.
279
- */
280
- declare class ExecutionAbortedError extends CustomError {
281
- constructor();
282
- toString(): string;
283
- }
284
-
285
- export { ExecutionAbortedError, StateMachine };
package/build/main.esm.js DELETED
@@ -1,3 +0,0 @@
1
- import{LambdaClient as e,InvokeCommand as t}from"@aws-sdk/client-lambda";import{JSONPath as r}from"jsonpath-plus";import n from"lodash/cloneDeep.js";import a from"lodash/set.js";import i from"p-limit";import s from"wildcard-match";import o from"asl-validator";class BaseStateHandler{buildExecutionResult(e){let t={stateResult:e,nextState:"",isEndState:!1};return"Next"in this.stateDefinition&&(t.nextState=this.stateDefinition.Next),"End"in this.stateDefinition&&(t.isEndState=this.stateDefinition.End),t}constructor(e){this.stateDefinition=e}}class CustomError extends Error{constructor(e){super(e)}}class LambdaExecutionError extends CustomError{toString(){return`${this.name}: ${this.message}. The error thrown by the Lambda was:
2
- ${this.wrappedError.stack}`}constructor(e,t){super(`Execution of Lambda function "${t}" failed`),this.name="LambdaExecutionError",this.wrappedError=Error(e.errorMessage),this.wrappedError.stack=e.trace.join("\n")}}function asyncGeneratorStep$8(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$8(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$8(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$8(i,n,a,s,o,"throw",e)}s(void 0)})}}class LambdaClient{invokeFunction(e,r){var n=this;return _asyncToGenerator$8(function*(){let a=Buffer.from(JSON.stringify(r)),i=new t({FunctionName:e,Payload:a}),s=yield n.client.send(i),o=null;if(s.Payload&&(o=JSON.parse(o=Buffer.from(s.Payload).toString())),s.FunctionError)throw new LambdaExecutionError(o,e);return o})()}constructor(t){this.client=new e(null!=t?t:{})}}function asyncGeneratorStep$7(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$7(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$7(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$7(i,n,a,s,o,"throw",e)}s(void 0)})}}class TaskStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$7(function*(){let t=n.stateDefinition,a=new LambdaClient;try{if(null==r?void 0:r.overrideFn){let i=yield r.overrideFn(e);return n.buildExecutionResult(i)}let s=yield a.invokeFunction(t.Resource,e);return n.buildExecutionResult(s)}catch(o){throw o instanceof LambdaExecutionError?console.error(o.toString()):console.error(o),o}})()}constructor(e){super(e)}}function jsonPathQuery(e,t,n){return e.startsWith("$$")?r({path:e.slice(1),json:null!=n?n:null,wrap:!1}):r({path:e,json:t,wrap:!1})}function isPlainObj(e){return!!e&&Object.getPrototypeOf(e)===Object.prototype}function sleep(e,t){return new Promise(r=>{let n=setTimeout(r,e);null==t||t.addEventListener("abort",()=>{n.unref()})})}function processInputPath(e,t,r){return void 0===e?t:null===e?{}:jsonPathQuery(e,t,r)}function processPayloadTemplate(e,t,r){let n=Object.entries(e).map(([e,n])=>{let a=e,i=n;return isPlainObj(n)&&(i=processPayloadTemplate(n,t)),e.endsWith(".$")&&"string"==typeof n&&(a=e.replace(".$",""),i=jsonPathQuery(n,t,r)),[a,i]});return Object.fromEntries(n)}function processResultPath(e,t,r){if(void 0===e)return r;if(null===e)return t;let i=e.replace("$.","");if(isPlainObj(t)){let s=n(t);return a(s,i,r)}throw Error("TODO: Change this error message for a more descriptive one")}function processOutputPath(e,t,r){return void 0===e?t:null===e?{}:jsonPathQuery(e,t,r)}function asyncGeneratorStep$6(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$6(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$6(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$6(i,n,a,s,o,"throw",e)}s(void 0)})}}class MapStateHandler extends BaseStateHandler{processItem(e,t,r,n,a){let i;let s=this.stateDefinition;r.Map={Item:{Index:n,Value:e}},s.Parameters&&(i=processPayloadTemplate(s.Parameters,t,r));let o=new StateMachine(s.Iterator,null==a?void 0:a.validationOptions),{result:u}=o.run(null!=i?i:e,null==a?void 0:a.runOptions);return u}executeState(e,t,r){var n=this;return _asyncToGenerator$6(function*(){let a=n.stateDefinition,s=e;if(a.ItemsPath&&(s=jsonPathQuery(a.ItemsPath,e,t)),!Array.isArray(s))return n.buildExecutionResult([]);let o=i(a.MaxConcurrency||40),u=s.map((a,i)=>o(()=>n.processItem(a,e,t,i,r))),l=yield Promise.all(u);return delete t.Map,n.buildExecutionResult(l)})()}constructor(e){super(e)}}function asyncGeneratorStep$5(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$5(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$5(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$5(i,n,a,s,o,"throw",e)}s(void 0)})}}class PassStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$5(function*(){return n.stateDefinition.Result?n.buildExecutionResult(n.stateDefinition.Result):n.buildExecutionResult(e)})()}constructor(e){super(e)}}function asyncGeneratorStep$4(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$4(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$4(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$4(i,n,a,s,o,"throw",e)}s(void 0)})}}class WaitStateHandler extends BaseStateHandler{executeState(e,t,r){var n=this;return _asyncToGenerator$4(function*(){let a=n.stateDefinition;if((null==r?void 0:r.waitTimeOverrideOption)!==void 0)return yield sleep(r.waitTimeOverrideOption,r.abortSignal),n.buildExecutionResult(e);if(a.Seconds)yield sleep(1e3*a.Seconds,null==r?void 0:r.abortSignal);else if(a.Timestamp){let i=new Date(a.Timestamp),s=Date.now(),o=i.getTime()-s;yield sleep(o,null==r?void 0:r.abortSignal)}else if(a.SecondsPath){let u=jsonPathQuery(a.SecondsPath,e,t);yield sleep(1e3*u,null==r?void 0:r.abortSignal)}else if(a.TimestampPath){let l=jsonPathQuery(a.TimestampPath,e,t),c=new Date(l),h=Date.now(),d=c.getTime()-h;yield sleep(d,null==r?void 0:r.abortSignal)}return n.buildExecutionResult(e)})()}constructor(e){super(e)}}function asyncGeneratorStep$3(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$3(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$3(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$3(i,n,a,s,o,"throw",e)}s(void 0)})}}class ChoiceStateHandler extends BaseStateHandler{testChoiceRule(e,t){if("And"in e)return e.And.every(e=>this.testChoiceRule(e,t));if("Or"in e)return e.Or.some(e=>this.testChoiceRule(e,t));if("Not"in e)return!this.testChoiceRule(e.Not,t);if("StringEquals"in e){let r=jsonPathQuery(e.Variable,t);return r===e.StringEquals}if("StringEqualsPath"in e){let n=jsonPathQuery(e.Variable,t),a=jsonPathQuery(e.StringEqualsPath,t);return n===a}if("StringLessThan"in e){let i=jsonPathQuery(e.Variable,t);return i<e.StringLessThan}if("StringLessThanPath"in e){let o=jsonPathQuery(e.Variable,t),u=jsonPathQuery(e.StringLessThanPath,t);return o<u}if("StringGreaterThan"in e){let l=jsonPathQuery(e.Variable,t);return l>e.StringGreaterThan}if("StringGreaterThanPath"in e){let c=jsonPathQuery(e.Variable,t),h=jsonPathQuery(e.StringGreaterThanPath,t);return c>h}if("StringLessThanEquals"in e){let d=jsonPathQuery(e.Variable,t);return d<=e.StringLessThanEquals}if("StringLessThanEqualsPath"in e){let f=jsonPathQuery(e.Variable,t),p=jsonPathQuery(e.StringLessThanEqualsPath,t);return f<=p}if("StringGreaterThanEquals"in e){let y=jsonPathQuery(e.Variable,t);return y>=e.StringGreaterThanEquals}if("StringGreaterThanEqualsPath"in e){let m=jsonPathQuery(e.Variable,t),P=jsonPathQuery(e.StringGreaterThanEqualsPath,t);return m>=P}if("StringMatches"in e){let S=jsonPathQuery(e.Variable,t),T=s(e.StringMatches,{separator:!1});return T(S)}if("NumericEquals"in e){let v=jsonPathQuery(e.Variable,t);return v===e.NumericEquals}if("NumericEqualsPath"in e){let E=jsonPathQuery(e.Variable,t),b=jsonPathQuery(e.NumericEqualsPath,t);return E===b}if("NumericLessThan"in e){let x=jsonPathQuery(e.Variable,t);return x<e.NumericLessThan}if("NumericLessThanPath"in e){let w=jsonPathQuery(e.Variable,t),j=jsonPathQuery(e.NumericLessThanPath,t);return w<j}if("NumericGreaterThan"in e){let G=jsonPathQuery(e.Variable,t);return G>e.NumericGreaterThan}if("NumericGreaterThanPath"in e){let Q=jsonPathQuery(e.Variable,t),g=jsonPathQuery(e.NumericGreaterThanPath,t);return Q>g}if("NumericLessThanEquals"in e){let $=jsonPathQuery(e.Variable,t);return $<=e.NumericLessThanEquals}if("NumericLessThanEqualsPath"in e){let q=jsonPathQuery(e.Variable,t),D=jsonPathQuery(e.NumericLessThanEqualsPath,t);return q<=D}if("NumericGreaterThanEquals"in e){let V=jsonPathQuery(e.Variable,t);return V>=e.NumericGreaterThanEquals}if("NumericGreaterThanEqualsPath"in e){let L=jsonPathQuery(e.Variable,t),O=jsonPathQuery(e.NumericGreaterThanEqualsPath,t);return L>=O}if("BooleanEquals"in e){let N=jsonPathQuery(e.Variable,t);return N===e.BooleanEquals}if("BooleanEqualsPath"in e){let R=jsonPathQuery(e.Variable,t),_=jsonPathQuery(e.BooleanEqualsPath,t);return R===_}if("TimestampEquals"in e){let I=new Date(jsonPathQuery(e.Variable,t)),H=new Date(e.TimestampEquals);return I.getTime()===H.getTime()}if("TimestampEqualsPath"in e){let C=new Date(jsonPathQuery(e.Variable,t)),B=new Date(jsonPathQuery(e.TimestampEqualsPath,t));return C.getTime()===B.getTime()}if("TimestampLessThan"in e){let M=new Date(jsonPathQuery(e.Variable,t)),k=new Date(e.TimestampLessThan);return M<k}if("TimestampLessThanPath"in e){let A=new Date(jsonPathQuery(e.Variable,t)),F=new Date(jsonPathQuery(e.TimestampLessThanPath,t));return A<F}if("TimestampGreaterThan"in e){let W=new Date(jsonPathQuery(e.Variable,t)),J=new Date(e.TimestampGreaterThan);return W>J}if("TimestampGreaterThanPath"in e){let Z=new Date(jsonPathQuery(e.Variable,t)),z=new Date(jsonPathQuery(e.TimestampGreaterThanPath,t));return Z>z}if("TimestampLessThanEquals"in e){let K=new Date(jsonPathQuery(e.Variable,t)),U=new Date(e.TimestampLessThanEquals);return K<=U}if("TimestampLessThanEqualsPath"in e){let X=new Date(jsonPathQuery(e.Variable,t)),Y=new Date(jsonPathQuery(e.TimestampLessThanEqualsPath,t));return X<=Y}if("TimestampGreaterThanEquals"in e){let ee=new Date(jsonPathQuery(e.Variable,t)),et=new Date(e.TimestampGreaterThanEquals);return ee>=et}if("TimestampGreaterThanEqualsPath"in e){let er=new Date(jsonPathQuery(e.Variable,t)),en=new Date(jsonPathQuery(e.TimestampGreaterThanEqualsPath,t));return er>=en}if("IsNull"in e){let ea=jsonPathQuery(e.Variable,t),ei=e.IsNull;return ei&&null===ea}if("IsPresent"in e){let es=jsonPathQuery(e.Variable,t),eo=e.IsPresent;return eo&&void 0!==es}if("IsNumeric"in e){let eu=jsonPathQuery(e.Variable,t),el=e.IsNumeric;return el&&"number"==typeof eu}if("IsString"in e){let ec=jsonPathQuery(e.Variable,t),eh=e.IsString;return eh&&"string"==typeof ec}if("IsBoolean"in e){let ed=jsonPathQuery(e.Variable,t),ef=e.IsBoolean;return ef&&"boolean"==typeof ed}if("IsTimestamp"in e){let ep=jsonPathQuery(e.Variable,t),ey=e.IsTimestamp;return ey&&/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|(\+|-)\d{2}:\d{2})/.test(ep)}return!1}executeState(e,t,r){var n=this;return _asyncToGenerator$3(function*(){let t=n.stateDefinition;for(let r of t.Choices){let a=n.testChoiceRule(r,e);if(a)return{stateResult:e,nextState:r.Next,isEndState:!1}}if(t.Default)return{stateResult:e,nextState:t.Default,isEndState:!1};throw Error("States.NoChoiceMatched")})()}constructor(e){super(e)}}function asyncGeneratorStep$2(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$2(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$2(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$2(i,n,a,s,o,"throw",e)}s(void 0)})}}class SucceedStateHandler extends BaseStateHandler{executeState(e,t,r){return _asyncToGenerator$2(function*(){return{stateResult:e,nextState:"",isEndState:!0}})()}constructor(e){super(e)}}function asyncGeneratorStep$1(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator$1(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep$1(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep$1(i,n,a,s,o,"throw",e)}s(void 0)})}}class FailStateHandler extends BaseStateHandler{executeState(e,t,r){return _asyncToGenerator$1(function*(){return{stateResult:e,nextState:"",isEndState:!0}})()}constructor(e){super(e)}}class ExecutionAbortedError extends CustomError{toString(){return"Execution aborted"}constructor(){super("Execution aborted"),this.name="ExecutionAbortedError"}}function asyncGeneratorStep(e,t,r,n,a,i,s){try{var o=e[i](s),u=o.value}catch(l){r(l);return}o.done?t(u):Promise.resolve(u).then(n,a)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function s(e){asyncGeneratorStep(i,n,a,s,o,"next",e)}function o(e){asyncGeneratorStep(i,n,a,s,o,"throw",e)}s(void 0)})}}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}class StateMachine{run(e,t){let r=new AbortController,n=new Promise((e,n)=>{(null==t?void 0:t.noThrowOnAbort)?r.signal.addEventListener("abort",()=>e(null)):r.signal.addEventListener("abort",()=>n(new ExecutionAbortedError))}),a=this.execute(e,{runOptions:t,abortSignal:r.signal}),i=Promise.race([a,n]);return{abort:()=>r.abort(),result:i}}execute(e,t){var r=this;return _asyncToGenerator(function*(){let a=r.definition.States[r.definition.StartAt],i=r.definition.StartAt,s=n(e),o=n(e),u=null,l="",c=!1,h={};do o=r.processInput(a,o,h),({stateResult:u,nextState:l,isEndState:c}=yield r.stateExecutors[a.Type](a,o,h,i,t)),s=u=r.processResult(a,u,s,h),o=u,a=r.definition.States[l],i=l;while(!c&&!t.abortSignal.aborted);return u})()}processInput(e,t,r){let n=t;return"InputPath"in e&&(n=processInputPath(e.InputPath,n,r)),"Parameters"in e&&"Map"!==e.Type&&(n=processPayloadTemplate(e.Parameters,n,r)),n}processResult(e,t,r,n){let a=t;return"ResultSelector"in e&&(a=processPayloadTemplate(e.ResultSelector,a,n)),"ResultPath"in e&&(a=processResultPath(e.ResultPath,r,a)),"OutputPath"in e&&(a=processOutputPath(e.OutputPath,a,n)),a}executeTaskState(e,t,r,n,a){return _asyncToGenerator(function*(){var i,s,o;let u=null==(i=a.runOptions)?void 0:null==(s=i.overrides)?void 0:null==(o=s.taskResourceLocalHandlers)?void 0:o[n],l=new TaskStateHandler(e),c=yield l.executeState(t,r,{overrideFn:u});return c})()}executeMapState(e,t,r,n,a){var i=this;return _asyncToGenerator(function*(){let n=new MapStateHandler(e),s=yield n.executeState(t,r,{validationOptions:i.validationOptions,runOptions:a.runOptions});return s})()}executePassState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new PassStateHandler(e),a=yield n.executeState(t,r);return a})()}executeWaitState(e,t,r,n,a){return _asyncToGenerator(function*(){var i,s,o;let u=null==(i=a.runOptions)?void 0:null==(s=i.overrides)?void 0:null==(o=s.waitTimeOverrides)?void 0:o[n],l=a.abortSignal,c=new WaitStateHandler(e),h=yield c.executeState(t,r,{waitTimeOverrideOption:u,abortSignal:l});return h})()}executeChoiceState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new ChoiceStateHandler(e),a=yield n.executeState(t,r);return a})()}executeSucceedState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new SucceedStateHandler(e),a=yield n.executeState(t,r);return a})()}executeFailState(e,t,r,n,a){return _asyncToGenerator(function*(){let n=new FailStateHandler(e),a=yield n.executeState(t,r);return a})()}constructor(e,t){let{isValid:r,errorsText:n}=o(e,_extends({checkArn:!0,checkPaths:!0},t));if(!r)throw Error(`State machine definition is invalid, see error(s) below:
3
- ${n("\n")}`);this.definition=e,this.stateExecutors={Task:this.executeTaskState,Map:this.executeMapState,Pass:this.executePassState,Wait:this.executeWaitState,Choice:this.executeChoiceState,Succeed:this.executeSucceedState,Fail:this.executeFailState},this.validationOptions=t}}export{ExecutionAbortedError,StateMachine};