yaml-flow 6.0.0 → 7.0.0

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.
Files changed (162) hide show
  1. package/board-live-cards-cli.js +4 -4
  2. package/browser/asset-integrity.json +3 -3
  3. package/browser/board-livecards-client.js +2 -0
  4. package/browser/board-livecards-client.js.map +1 -0
  5. package/browser/board-livecards-localstorage.js +10 -0
  6. package/browser/board-livecards-localstorage.js.map +1 -0
  7. package/browser/board-livegraph-engine.js +2 -2
  8. package/browser/board-livegraph-engine.js.map +1 -1
  9. package/browser/card-compute.js +28 -28
  10. package/browser/compute-jsonata.js +5 -0
  11. package/browser/compute-jsonata.js.map +1 -0
  12. package/browser/live-cards.js +261 -150
  13. package/card-store.js +4 -4
  14. package/dist/{board-live-cards-public-CltXYgaY.d.cts → board-live-cards-public-CW5074xr.d.cts} +9 -5
  15. package/dist/{board-live-cards-public-f-E-FAyp.d.ts → board-live-cards-public-hnZo0mAf.d.ts} +9 -5
  16. package/dist/board-livegraph-runtime/index.cjs +2 -2
  17. package/dist/board-livegraph-runtime/index.cjs.map +1 -1
  18. package/dist/board-livegraph-runtime/index.d.cts +11 -9
  19. package/dist/board-livegraph-runtime/index.d.ts +11 -9
  20. package/dist/board-livegraph-runtime/index.js +2 -2
  21. package/dist/board-livegraph-runtime/index.js.map +1 -1
  22. package/dist/board-livegraph-runtime/jsonata-sync.cjs +37 -1
  23. package/dist/card-compute/index.cjs +4 -4
  24. package/dist/card-compute/index.cjs.map +1 -1
  25. package/dist/card-compute/index.d.cts +5 -1
  26. package/dist/card-compute/index.d.ts +5 -1
  27. package/dist/card-compute/index.js +4 -4
  28. package/dist/card-compute/index.js.map +1 -1
  29. package/dist/card-compute/jsonata-sync.cjs +37 -1
  30. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs +2 -1
  31. package/dist/cli/browser-api/board-live-cards-browser-adapter.cjs.map +1 -1
  32. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.cts +27 -14
  33. package/dist/cli/browser-api/board-live-cards-browser-adapter.d.ts +27 -14
  34. package/dist/cli/browser-api/board-live-cards-browser-adapter.js +2 -1
  35. package/dist/cli/browser-api/board-live-cards-browser-adapter.js.map +1 -1
  36. package/dist/cli/browser-api/card-store-browser-api.cjs +1 -1
  37. package/dist/cli/browser-api/card-store-browser-api.cjs.map +1 -1
  38. package/dist/cli/browser-api/card-store-browser-api.js +1 -1
  39. package/dist/cli/browser-api/card-store-browser-api.js.map +1 -1
  40. package/dist/cli/browser-api/jsonata-sync.cjs +37 -1
  41. package/dist/cli/node/artifacts-store-cli.cjs +8 -8
  42. package/dist/cli/node/artifacts-store-cli.cjs.map +1 -1
  43. package/dist/cli/node/artifacts-store-cli.js +8 -8
  44. package/dist/cli/node/artifacts-store-cli.js.map +1 -1
  45. package/dist/cli/node/board-live-cards-cli.cjs +7 -7
  46. package/dist/cli/node/board-live-cards-cli.cjs.map +1 -1
  47. package/dist/cli/node/board-live-cards-cli.js +7 -7
  48. package/dist/cli/node/board-live-cards-cli.js.map +1 -1
  49. package/dist/cli/node/card-store-cli.cjs +5 -5
  50. package/dist/cli/node/card-store-cli.cjs.map +1 -1
  51. package/dist/cli/node/card-store-cli.js +5 -5
  52. package/dist/cli/node/card-store-cli.js.map +1 -1
  53. package/dist/cli/node/execution-adapter.cjs +3 -0
  54. package/dist/cli/node/execution-adapter.cjs.map +1 -0
  55. package/dist/cli/node/execution-adapter.d.cts +174 -0
  56. package/dist/cli/node/execution-adapter.d.ts +174 -0
  57. package/dist/cli/node/execution-adapter.js +3 -0
  58. package/dist/cli/node/execution-adapter.js.map +1 -0
  59. package/dist/cli/node/fs-board-adapter.cjs +7 -7
  60. package/dist/cli/node/fs-board-adapter.cjs.map +1 -1
  61. package/dist/cli/node/fs-board-adapter.d.cts +2 -2
  62. package/dist/cli/node/fs-board-adapter.d.ts +2 -2
  63. package/dist/cli/node/fs-board-adapter.js +7 -7
  64. package/dist/cli/node/fs-board-adapter.js.map +1 -1
  65. package/dist/cli/node/jsonata-sync.cjs +37 -1
  66. package/dist/cli/node/source-cli-task-executor.cjs +4 -4
  67. package/dist/cli/node/source-cli-task-executor.cjs.map +1 -1
  68. package/dist/cli/node/source-cli-task-executor.js +4 -4
  69. package/dist/cli/node/source-cli-task-executor.js.map +1 -1
  70. package/dist/continuous-event-graph/index.cjs +2 -2
  71. package/dist/continuous-event-graph/index.cjs.map +1 -1
  72. package/dist/continuous-event-graph/index.js +2 -2
  73. package/dist/continuous-event-graph/index.js.map +1 -1
  74. package/dist/continuous-event-graph/jsonata-sync.cjs +37 -1
  75. package/dist/execution-refs.cjs +2 -1
  76. package/dist/execution-refs.cjs.map +1 -1
  77. package/dist/execution-refs.d.cts +49 -11
  78. package/dist/execution-refs.d.ts +49 -11
  79. package/dist/execution-refs.js +2 -1
  80. package/dist/execution-refs.js.map +1 -1
  81. package/dist/index.cjs +10 -10
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.js +10 -10
  84. package/dist/index.js.map +1 -1
  85. package/dist/jsonata-sync.cjs +37 -1
  86. package/dist/server-runtime/index.cjs +9 -0
  87. package/dist/server-runtime/index.cjs.map +1 -0
  88. package/dist/server-runtime/index.d.cts +31 -0
  89. package/dist/server-runtime/index.d.ts +31 -0
  90. package/dist/server-runtime/index.js +9 -0
  91. package/dist/server-runtime/index.js.map +1 -0
  92. package/dist/server-runtime/jsonata-sync.cjs +7623 -0
  93. package/dist/step-machine-public/index.cjs +2 -0
  94. package/dist/step-machine-public/index.cjs.map +1 -0
  95. package/dist/step-machine-public/index.d.cts +159 -0
  96. package/dist/step-machine-public/index.d.ts +159 -0
  97. package/dist/step-machine-public/index.js +2 -0
  98. package/dist/step-machine-public/index.js.map +1 -0
  99. package/dist/step-machine-public/jsonata-sync.cjs +7623 -0
  100. package/dist/storage-refs.cjs +2 -2
  101. package/dist/storage-refs.cjs.map +1 -1
  102. package/dist/storage-refs.d.cts +7 -6
  103. package/dist/storage-refs.d.ts +7 -6
  104. package/dist/storage-refs.js +2 -2
  105. package/dist/storage-refs.js.map +1 -1
  106. package/dist/types-B1ZRa4aI.d.ts +147 -0
  107. package/dist/types-BxEFcVK9.d.cts +147 -0
  108. package/examples/browser/boards/portfolio-tracker/portfolio-t4.js +9 -10
  109. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-http-test.js +357 -0
  110. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-public.js +9 -10
  111. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.js +300 -0
  112. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-server.py +617 -0
  113. package/examples/browser/boards/portfolio-tracker/portfolio-tracker-sse-worker.js +48 -0
  114. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.py +11 -10
  115. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +19 -4
  116. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +4 -8
  117. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +6 -10
  118. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/poll-status-cli.js +8 -16
  119. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +2 -6
  120. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +4 -8
  121. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +3 -7
  122. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +4 -8
  123. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +7 -16
  124. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +2 -6
  125. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/_board_pycli.py +13 -3
  126. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/add-cards.py +2 -1
  127. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/init-board.py +2 -1
  128. package/examples/cli/step-machine-cli/portfolio-tracker/handlers-py/poll-status.py +2 -1
  129. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +20 -24
  130. package/examples/cli/step-machine-cli/portfolio-tracker/run-inline-python-demo-pycli.py +0 -3
  131. package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +8 -13
  132. package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +33 -9
  133. package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +3 -1
  134. package/examples/cli/step-machine-demo/step2-double-cli.js +6 -12
  135. package/examples/cli/step-machine-demo/two-step-math.flow.yaml +66 -4
  136. package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +13 -5
  137. package/examples/example-board/cards/_index.json +47 -0
  138. package/examples/example-board/cards/card-market-prices.json +33 -9
  139. package/examples/example-board/cards/card-my-identity.json +30 -6
  140. package/examples/example-board/cards/card-portfolio-action.json +24 -6
  141. package/examples/example-board/cards/card-portfolio-intelligence.json +97 -0
  142. package/examples/example-board/cards/card-portfolio-risks.json +24 -6
  143. package/examples/example-board/cards/card-portfolio-value.json +38 -10
  144. package/examples/example-board/cards/card-portfolio.json +57 -13
  145. package/examples/example-board/cards/card-rebalance-impact.json +22 -6
  146. package/examples/example-board/cards/card-rebalance-sim.json +66 -15
  147. package/examples/example-board/demo-server.js +360 -69
  148. package/examples/example-board/demo-shell-localstorage.html +774 -0
  149. package/examples/example-board/demo-shell-with-server.html +18 -36
  150. package/examples/example-board/demo-shell.html +5 -4
  151. package/examples/example-board/demo-task-executor.js +217 -265
  152. package/package.json +15 -13
  153. package/step-machine-cli.js +43 -310
  154. package/board-livecards-server-runtime.js +0 -1513
  155. package/browser/board-livecards-runtime-client.js +0 -263
  156. package/dist/pycli/quickjs-board-runtime.global.js +0 -9
  157. package/dist/pycli/quickjs-board-runtime.global.js.map +0 -1
  158. package/dist/pycli/quickjs-step-machine-runtime.global.js +0 -5
  159. package/dist/pycli/quickjs-step-machine-runtime.global.js.map +0 -1
  160. package/examples/cli/step-machine-demo/two-step-math-handlers.js +0 -32
  161. package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +0 -24
  162. package/examples/example-board/demo-shell-browser.html +0 -675
@@ -1,5 +0,0 @@
1
- (function(){'use strict';var qt=Object.create;var At=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Bt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Vt=Object.prototype.hasOwnProperty;var Gt=(m,c,y)=>c in m?At(m,c,{enumerable:true,configurable:true,writable:true,value:y}):m[c]=y;var ht=(m=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(m,{get:(c,y)=>(typeof require<"u"?require:c)[y]}):m)(function(m){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+m+'" is not supported')});var Zt=(m,c)=>()=>(c||m((c={exports:{}}).exports,c),c.exports);var Xt=(m,c,y,S)=>{if(c&&typeof c=="object"||typeof c=="function")for(let P of Bt(c))!Vt.call(m,P)&&P!==y&&At(m,P,{get:()=>c[P],enumerable:!(S=Yt(c,P))||S.enumerable});return m};var Qt=(m,c,y)=>(y=m!=null?qt(Jt(m)):{},Xt(At(y,"default",{value:m,enumerable:true}),m));var qe=(m,c,y)=>Gt(m,typeof c!="symbol"?c+"":c,y);var $t=Zt((_t,Ot)=>{(function(m){if(typeof _t=="object"&&typeof Ot<"u")Ot.exports=m();else if(typeof define=="function"&&define.amd)define([],m);else {var c;typeof window<"u"?c=window:typeof global<"u"?c=global:typeof self<"u"?c=self:c=this,c.jsonata=m();}})(function(){return (function(){function S(P,A,B){function d(X,pe){if(!A[X]){if(!P[X]){var F=typeof ht=="function"&&ht;if(!pe&&F)return F(X,true);if(U)return U(X,true);var w=new Error("Cannot find module '"+X+"'");throw w.code="MODULE_NOT_FOUND",w}var k=A[X]={exports:{}};P[X][0].call(k.exports,function(D){var V=P[X][1][D];return d(V||D)},k,k.exports,S,P,A,B);}return A[X].exports}for(var U=typeof ht=="function"&&ht,K=0;K<B.length;K++)d(B[K]);return d}return S})()({1:[function(S,P,A){let B=S("./utils"),d=(function(){let U=B.stringToArray,K=["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"],X=["Zeroth","First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","Fifteenth","Sixteenth","Seventeenth","Eighteenth","Nineteenth"],pe=["Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety","Hundred"],F=["Thousand","Million","Billion","Trillion"];function w(l,v){var p=function(M,C,b){var O="";if(M<=19)O=(C?" and ":"")+(b?X[M]:K[M]);else if(M<100){let ie=Math.floor(M/10),se=M%10;O=(C?" and ":"")+pe[ie-2],se>0?O+="-"+p(se,false,b):b&&(O=O.substring(0,O.length-1)+"ieth");}else if(M<1e3){let ie=Math.floor(M/100),se=M%100;O=(C?", ":"")+K[ie]+" Hundred",se>0?O+=p(se,true,b):b&&(O+="th");}else {var z=Math.floor(Math.log10(M)/3);z>F.length&&(z=F.length);let ie=Math.pow(10,z*3),se=Math.floor(M/ie),L=M-se*ie;O=(C?", ":"")+p(se,false,false)+" "+F[z-1],L>0?O+=p(L,true,b):b&&(O+="th");}return O},E=p(l,false,v);return E}let k={};K.forEach(function(l,v){k[l.toLowerCase()]=v;}),X.forEach(function(l,v){k[l.toLowerCase()]=v;}),pe.forEach(function(l,v){let p=l.toLowerCase();k[p]=(v+2)*10,k[p.substring(0,l.length-1)+"ieth"]=k[p];}),k.hundredth=100,F.forEach(function(l,v){let p=l.toLowerCase(),E=Math.pow(10,(v+1)*3);k[p]=E,k[p+"th"]=E;});function D(l){let p=l.split(/,\s|\sand\s|[\s\\-]/).map(C=>k[C]),E=[0];return p.forEach(C=>{if(C<100){let b=E.pop();b>=1e3&&(E.push(b),b=0),E.push(b+C);}else E.push(E.pop()*C);}),E.reduce((C,b)=>C+b,0)}let V=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]],me={M:1e3,D:500,C:100,L:50,X:10,V:5,I:1};function be(l){for(var v=0;v<V.length;v++){let p=V[v];if(l>=p[0])return p[1]+be(l-p[0])}return ""}function q(l){for(var v=0,p=1,E=l.length-1;E>=0;E--){let M=l[E],C=me[M];C<p?v-=C:(p=C,v+=C);}return v}function x(l,v){for(var p=[],E=v.charCodeAt(0);l>0;)p.unshift(String.fromCharCode((l-1)%26+E)),l=Math.floor((l-1)/26);return p.join("")}function Z(l,v){for(var p=v.charCodeAt(0),E=0,M=0;M<l.length;M++)E+=(l.charCodeAt(l.length-M-1)-p+1)*Math.pow(26,M);return E}function _(l,v){if(typeof l>"u")return;l=Math.floor(l);let p=fe(v);return N(l,p)}let g={DECIMAL:"decimal",LETTERS:"letters",ROMAN:"roman",WORDS:"words",SEQUENCE:"sequence"},R={UPPER:"upper",LOWER:"lower",TITLE:"title"};function N(l,v){let p,E=l<0;switch(l=Math.abs(l),v.primary){case g.LETTERS:p=x(l,v.case===R.UPPER?"A":"a");break;case g.ROMAN:p=be(l),v.case===R.UPPER&&(p=p.toUpperCase());break;case g.WORDS:p=w(l,v.ordinal),v.case===R.UPPER?p=p.toUpperCase():v.case===R.LOWER&&(p=p.toLowerCase());break;case g.DECIMAL:p=""+l;var M=v.mandatoryDigits-p.length;if(M>0){var C=new Array(M+1).join("0");p=C+p;}if(v.zeroCode!==48&&(p=U(p).map(ie=>String.fromCodePoint(ie.codePointAt(0)+v.zeroCode-48)).join("")),v.regular){let ie=Math.floor((p.length-1)/v.groupingSeparators.position);for(let se=ie;se>0;se--){let L=p.length-se*v.groupingSeparators.position;p=p.substr(0,L)+v.groupingSeparators.character+p.substr(L);}}else v.groupingSeparators.reverse().forEach(ie=>{let se=p.length-ie.position;p=p.substr(0,se)+ie.character+p.substr(se);});if(v.ordinal){var b={1:"st",2:"nd",3:"rd"},O=p[p.length-1],z=b[O];(!z||p.length>1&&p[p.length-2]==="1")&&(z="th"),p=p+z;}break;case g.SEQUENCE:throw {code:"D3130",value:v.token}}return E&&(p="-"+p),p}let ne=[48,1632,1776,1984,2406,2534,2662,2790,2918,3046,3174,3302,3430,3558,3664,3792,3872,4160,4240,6112,6160,6470,6608,6784,6800,6992,7088,7232,7248,42528,43216,43264,43472,43504,43600,44016,65296];function fe(l){let v={type:"integer",primary:g.DECIMAL,case:R.LOWER,ordinal:false},p,E,M=l.lastIndexOf(";");switch(M===-1?p=l:(p=l.substring(0,M),E=l.substring(M+1),E[0]==="o"&&(v.ordinal=true)),p){case "A":v.case=R.UPPER;case "a":v.primary=g.LETTERS;break;case "I":v.case=R.UPPER;case "i":v.primary=g.ROMAN;break;case "W":v.case=R.UPPER,v.primary=g.WORDS;break;case "Ww":v.case=R.TITLE,v.primary=g.WORDS;break;case "w":v.primary=g.WORDS;break;default:{let C=null,b=0,O=0,z=[],ie=0;if(U(p).map(L=>L.codePointAt(0)).reverse().forEach(L=>{let Y=false;for(let re=0;re<ne.length;re++){let H=ne[re];if(L>=H&&L<=H+9){if(Y=true,b++,ie++,C===null)C=H;else if(H!==C)throw {code:"D3131"};break}}Y||(L===35?(ie++,O++):z.push({position:ie,character:String.fromCodePoint(L)}));}),b>0){v.primary=g.DECIMAL,v.zeroCode=C,v.mandatoryDigits=b,v.optionalDigits=O;let Y=function(re){if(re.length===0)return 0;let H=re[0].character;for(let Pe=1;Pe<re.length;Pe++)if(re[Pe].character!==H)return 0;let Oe=re.map(Pe=>Pe.position),Je=function(Pe,Ue){return Ue===0?Pe:Je(Ue,Pe%Ue)},je=Oe.reduce(Je);for(let Pe=1;Pe<=Oe.length;Pe++)if(Oe.indexOf(Pe*je)===-1)return 0;return je}(z);Y>0?(v.regular=true,v.groupingSeparators={position:Y,character:z[0].character}):(v.regular=false,v.groupingSeparators=z);}else v.primary=g.SEQUENCE,v.token=p;}}return v}let de={Y:"1",M:"1",D:"1",d:"1",F:"n",W:"1",w:"1",X:"1",x:"1",H:"1",h:"1",P:"n",m:"01",s:"01",f:"1",Z:"01:01",z:"01:01",C:"n",E:"n"};function he(l){var v=[];let p={type:"datetime",parts:v},E=function(Y,re){if(re>Y){let H=l.substring(Y,re);H=H.split("]]").join("]"),v.push({type:"literal",value:H});}};for(var M=0,C=0;C<l.length;){if(l.charAt(C)==="["){if(l.charAt(C+1)==="["){E(M,C),v.push({type:"literal",value:"["}),C+=2,M=C;continue}if(E(M,C),M=C,C=l.indexOf("]",M),C===-1)throw {code:"D3135"};let Y=l.substring(M+1,C);Y=Y.split(/\s+/).join("");var b={type:"marker",component:Y.charAt(0)},O=Y.lastIndexOf(","),z;if(O!==-1){let re=Y.substring(O+1),H=re.indexOf("-"),Oe,Je,je=function(Ue){if(!(typeof Ue>"u"||Ue==="*"))return parseInt(Ue)};H===-1?Oe=re:(Oe=re.substring(0,H),Je=re.substring(H+1));let Pe={min:je(Oe),max:je(Je)};b.width=Pe,z=Y.substring(1,O);}else z=Y.substring(1);if(z.length===1)b.presentation1=z;else if(z.length>1){var ie=z.charAt(z.length-1);"atco".indexOf(ie)!==-1?(b.presentation2=ie,ie==="o"&&(b.ordinal=true),b.presentation1=z.substring(0,z.length-1)):b.presentation1=z;}else b.presentation1=de[b.component];if(typeof b.presentation1>"u")throw {code:"D3132",value:b.component};if(b.presentation1[0]==="n")b.names=R.LOWER;else if(b.presentation1[0]==="N")b.presentation1[1]==="n"?b.names=R.TITLE:b.names=R.UPPER;else if("YMDdFWwXxHhmsf".indexOf(b.component)!==-1){var se=b.presentation1;if(b.presentation2&&(se+=";"+b.presentation2),b.integerFormat=fe(se),b.width&&b.width.min!==void 0&&b.integerFormat.mandatoryDigits<b.width.min&&(b.integerFormat.mandatoryDigits=b.width.min),b.component==="Y")if(b.n=-1,b.width&&b.width.max!==void 0)b.n=b.width.max,b.integerFormat.mandatoryDigits=b.n;else {var L=b.integerFormat.mandatoryDigits+b.integerFormat.optionalDigits;L>=2&&(b.n=L);}let re=v[v.length-1];re&&re.integerFormat&&(re.integerFormat.parseWidth=re.integerFormat.mandatoryDigits);}(b.component==="Z"||b.component==="z")&&(b.integerFormat=fe(b.presentation1)),v.push(b),M=C+1;}C++;}return E(M,C),p}let oe=["","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],Ae=["January","February","March","April","May","June","July","August","September","October","November","December"],He=1e3*60*60*24,ce=function(l){let v=Date.UTC(l.year,l.month);var p=new Date(v).getUTCDay();return p===0&&(p=7),p>4?v+(8-p)*He:v-(p-1)*He},ee=function(l,v){return {year:l,month:v,nextMonth:function(){return v===11?ee(l+1,0):ee(l,v+1)},previousMonth:function(){return v===0?ee(l-1,11):ee(l,v-1)},nextYear:function(){return ee(l+1,v)},previousYear:function(){return ee(l-1,v)}}},Le=function(l,v){return (v-l)/(He*7)+1},G=(l,v)=>{let p;switch(v){case "Y":p=l.getUTCFullYear();break;case "M":p=l.getUTCMonth()+1;break;case "D":p=l.getUTCDate();break;case "d":{let E=Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),l.getUTCDate()),M=Date.UTC(l.getUTCFullYear(),0);p=(E-M)/He+1;break}case "F":p=l.getUTCDay(),p===0&&(p=7);break;case "W":{let E=ee(l.getUTCFullYear(),0),M=ce(E),C=Date.UTC(E.year,l.getUTCMonth(),l.getUTCDate()),b=Le(M,C);if(b>52){let O=ce(E.nextYear());C>=O&&(b=1);}else if(b<1){let O=ce(E.previousYear());b=Le(O,C);}p=Math.floor(b);break}case "w":{let E=ee(l.getUTCFullYear(),l.getUTCMonth()),M=ce(E),C=Date.UTC(E.year,E.month,l.getUTCDate()),b=Le(M,C);if(b>4){let O=ce(E.nextMonth());C>=O&&(b=1);}else if(b<1){let O=ce(E.previousMonth());b=Le(O,C);}p=Math.floor(b);break}case "X":{let E=ee(l.getUTCFullYear(),0),M=ce(E),C=ce(E.nextYear()),b=l.getTime();b<M?p=E.year-1:b>=C?p=E.year+1:p=E.year;break}case "x":{let E=ee(l.getUTCFullYear(),l.getUTCMonth()),M=ce(E),C=E.nextMonth(),b=ce(C),O=l.getTime();O<M?p=E.previousMonth().month+1:O>=b?p=C.month+1:p=E.month+1;break}case "H":p=l.getUTCHours();break;case "h":p=l.getUTCHours(),p=p%12,p===0&&(p=12);break;case "P":p=l.getUTCHours()>=12?"pm":"am";break;case "m":p=l.getUTCMinutes();break;case "s":p=l.getUTCSeconds();break;case "f":p=l.getUTCMilliseconds();break;case "Z":case "z":break;case "C":p="ISO";break;case "E":p="ISO";break}return p},xe=null;function Be(l,v,p){var E=0,M=0;if(typeof p<"u"){let se=parseInt(p);E=Math.floor(se/100),M=se%100;}var C=function(se,L){var Y=G(se,L.component);if("YMDdFWwXxHhms".indexOf(L.component)!==-1)if(L.component==="Y"&&L.n!==-1&&(Y=Y%Math.pow(10,L.n)),L.names){if(L.component==="M"||L.component==="x")Y=Ae[Y-1];else if(L.component==="F")Y=oe[Y];else throw {code:"D3133",value:L.component};L.names===R.UPPER?Y=Y.toUpperCase():L.names===R.LOWER&&(Y=Y.toLowerCase()),L.width&&Y.length>L.width.max&&(Y=Y.substring(0,L.width.max));}else Y=N(Y,L.integerFormat);else if(L.component==="f")Y=N(Y,L.integerFormat);else if(L.component==="Z"||L.component==="z"){let re=E*100+M;if(L.integerFormat.regular)Y=N(re,L.integerFormat);else {let H=L.integerFormat.mandatoryDigits;if(H===1||H===2)Y=N(E,L.integerFormat),M!==0&&(Y+=":"+_(M,"00"));else if(H===3||H===4)Y=N(re,L.integerFormat);else throw {code:"D3134",value:H}}re>=0&&(Y="+"+Y),L.component==="z"&&(Y="GMT"+Y),re===0&&L.presentation2==="t"&&(Y="Z");}else L.component==="P"&&L.names===R.UPPER&&(Y=Y.toUpperCase());return Y};let b;typeof v>"u"?(xe===null&&(xe=he("[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z01:01t]")),b=xe):b=he(v);let O=(60*E+M)*60*1e3,z=new Date(l+O),ie="";return b.parts.forEach(function(se){se.type==="literal"?ie+=se.value:ie+=C(z,se);}),ie}function a(l){var v={};if(l.type==="datetime")v.type="datetime",v.parts=l.parts.map(function(p){var E={};if(p.type==="literal")E.regex=p.value.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if(p.component==="Z"||p.component==="z"){let C;Array.isArray(p.integerFormat.groupingSeparators)||(C=p.integerFormat.groupingSeparators),E.regex="",p.component==="z"&&(E.regex="GMT"),E.regex+="[-+][0-9]+",C&&(E.regex+=C.character+"[0-9]+"),E.parse=function(b){p.component==="z"&&(b=b.substring(3));let O=0,z=0;return C?(O=Number.parseInt(b.substring(0,b.indexOf(C.character))),z=Number.parseInt(b.substring(b.indexOf(C.character)+1))):b.length-1<=2?O=Number.parseInt(b):(O=Number.parseInt(b.substring(0,3)),z=Number.parseInt(b.substring(3))),O*60+z};}else if(p.integerFormat)E=a(p.integerFormat);else {E.regex="[a-zA-Z]+";var M={};if(p.component==="M"||p.component==="x")Ae.forEach(function(C,b){p.width&&p.width.max?M[C.substring(0,p.width.max)]=b+1:M[C]=b+1;});else if(p.component==="F")oe.forEach(function(C,b){b>0&&(p.width&&p.width.max?M[C.substring(0,p.width.max)]=b:M[C]=b);});else if(p.component==="P")M={am:0,AM:0,pm:1,PM:1};else throw {code:"D3133",value:p.component};E.parse=function(C){return M[C]};}return E.component=p.component,E});else {v.type="integer";let p=l.case===R.UPPER;switch(l.primary){case g.LETTERS:v.regex=p?"[A-Z]+":"[a-z]+",v.parse=function(E){return Z(E,p?"A":"a")};break;case g.ROMAN:v.regex=p?"[MDCLXVI]+":"[mdclxvi]+",v.parse=function(E){return q(p?E:E.toUpperCase())};break;case g.WORDS:v.regex="(?:"+Object.keys(k).concat("and","[\\-, ]").join("|")+")+",v.parse=function(E){return D(E.toLowerCase())};break;case g.DECIMAL:v.regex="[0-9]",l.parseWidth?v.regex+=`{${l.parseWidth}}`:v.regex+="+",l.ordinal&&(v.regex+="(?:th|st|nd|rd)"),v.parse=function(E){let M=E;return l.ordinal&&(M=E.substring(0,E.length-2)),l.regular?M=M.split(",").join(""):l.groupingSeparators.forEach(C=>{M=M.split(C.character).join("");}),l.zeroCode!==48&&(M=M.split("").map(C=>String.fromCodePoint(C.codePointAt(0)-l.zeroCode+48)).join("")),parseInt(M)};break;case g.SEQUENCE:throw {code:"D3130",value:l.token}}}return v}function u(l,v){if(typeof l>"u")return;let p=fe(v);return a(p).parse(l)}function $(l,v){let p=he(v),E=a(p),M="^"+E.parts.map(z=>"("+z.regex+")").join("")+"$";var b=new RegExp(M,"i").exec(l);if(b!==null){let H={};for(let ge=1;ge<b.length;ge++){let n=E.parts[ge-1];n.parse&&(H[n.component]=n.parse(b[ge]));}if(Object.getOwnPropertyNames(H).length===0)return;let Oe=0,Je=ge=>{Oe<<=1,Oe+=ge?1:0;},je=ge=>!(~ge&Oe)&&!!(ge&Oe);"YXMxWwdD".split("").forEach(ge=>Je(H[ge]));let Ue=!je(161)&&je(130),Qe=je(84),et=!Qe&&je(72);Oe=0,"PHhmsf".split("").forEach(ge=>Je(H[ge]));let tt=!je(23)&&je(47),ct=(Ue?"YD":Qe?"XxwF":et?"XWF":"YMD")+(tt?"Phmsf":"Hmsf"),Ge=this.environment.timestamp,it=false,Xe=false;if(ct.split("").forEach(ge=>{if(typeof H[ge]>"u")it?(H[ge]="MDd".indexOf(ge)!==-1?1:0,Xe=true):H[ge]=G(Ge,ge);else if(it=true,Xe)throw {code:"D3136"}}),H.M>0?H.M-=1:H.M=0,Ue){let ge=Date.UTC(H.Y,0),n=(H.d-1)*1e3*60*60*24,i=new Date(ge+n);H.M=i.getUTCMonth(),H.D=i.getUTCDate();}if(Qe)throw {code:"D3136"};if(et)throw {code:"D3136"};tt&&(H.H=H.h===12?0:H.h,H.P===1&&(H.H+=12));var O=Date.UTC(H.Y,H.M,H.D,H.H,H.m,H.s,H.f);return (H.Z||H.z)&&(O-=(H.Z||H.z)*60*1e3),O}}var te=new RegExp("^\\d{4}(-[01]\\d)*(-[0-3]\\d)*(T[0-2]\\d:[0-5]\\d:[0-5]\\d)*(\\.\\d+)?([+-][0-2]\\d:?[0-5]\\d|Z)?$");function we(l,v){if(!(typeof l>"u"))if(typeof v>"u"){if(!te.test(l))throw {stack:new Error().stack,code:"D3110",value:l};return Date.parse(l)}else return $.call(this,l,v)}function le(l,v,p){if(!(typeof l>"u"))return Be.call(this,l,v,p)}return {formatInteger:_,parseInteger:u,fromMillis:le,toMillis:we}})();P.exports=d;},{"./utils":6}],2:[function(S,P,A){(function(B){(function(){var d=S("./utils");let U=(()=>{var K=d.isNumeric,X=d.isArrayOfStrings,pe=d.isArrayOfNumbers,F=d.createSequence,w=d.isSequence,k=d.isFunction,D=d.isLambda,V=d.isPromise,me=d.getFunctionArity,be=d.isDeepEqual,q=d.stringToArray;function x(e){if(!(typeof e>"u")){var t=0;return e.forEach(function(r){t+=r;}),t}}function Z(e){return typeof e>"u"?0:e.length}function _(e){if(!(typeof e>"u"||e.length===0))return Math.max.apply(Math,e)}function g(e){if(!(typeof e>"u"||e.length===0))return Math.min.apply(Math,e)}function R(e){if(!(typeof e>"u"||e.length===0)){var t=0;return e.forEach(function(r){t+=r;}),t/e.length}}function N(e,t=false){if(!(typeof e>"u")){var r;if(typeof e=="string")r=e;else if(k(e))r="";else {if(typeof e=="number"&&!isFinite(e))throw {code:"D3001",value:e,stack:new Error().stack};var f=t?2:0;Array.isArray(e)&&e.outerWrapper&&(e=e[0]),r=JSON.stringify(e,function(s,h){return typeof h<"u"&&h!==null&&h.toPrecision&&K(h)?Number(h.toPrecision(15)):h&&k(h)?"":h},f);}return r}}function ne(e,t,r){if(!(typeof e>"u")){var f=q(e),s=f.length;if(s+t<0&&(t=0),typeof r<"u"){if(r<=0)return "";var h=t>=0?t+r:s+t+r;return f.slice(t,h).join("")}return f.slice(t).join("")}}function fe(e,t){if(!(typeof e>"u")){var r=e.indexOf(t);return r>-1?e.substr(0,r):e}}function de(e,t){if(!(typeof e>"u")){var r=e.indexOf(t);return r>-1?e.substr(r+t.length):e}}function he(e){if(!(typeof e>"u"))return e.toLowerCase()}function oe(e){if(!(typeof e>"u"))return e.toUpperCase()}function Ae(e){if(!(typeof e>"u"))return q(e).length}function He(e){if(!(typeof e>"u")){var t=e.replace(/[ \t\n\r]+/gm," ");return t.charAt(0)===" "&&(t=t.substring(1)),t.charAt(t.length-1)===" "&&(t=t.substring(0,t.length-1)),t}}function ce(e,t,r){if(!(typeof e>"u")){(typeof r>"u"||r.length===0)&&(r=" ");var f;t=Math.trunc(t);var s=Math.abs(t)-Ae(e);if(s>0){var h=new Array(s+1).join(r);r.length>1&&(h=ne(h,0,s)),t>0?f=e+h:f=h+e;}else f=e;return f}}async function ee(e,t){var r=e.apply(this,[t]);if(V(r)&&(r=await r),r&&!(typeof r.start=="number"||r.end==="number"||Array.isArray(r.groups)||k(r.next)))throw {code:"T1010",stack:new Error().stack};return r}async function Le(e,t){if(!(typeof e>"u")){var r;if(typeof t=="string")r=e.indexOf(t)!==-1;else {var f=await ee(t,e);r=typeof f<"u";}return r}}async function G(e,t,r){if(!(typeof e>"u")){if(r<0)throw {stack:new Error().stack,value:r,code:"D3040",index:3};var f=F();if(typeof r>"u"||r>0){var s=0,h=await ee(t,e);if(typeof h<"u")for(;typeof h<"u"&&(typeof r>"u"||s<r);)f.push({match:h.match,index:h.start,groups:h.groups}),h=await ee(h.next),s++;}return f}}async function xe(e,t,r,f){if(!(typeof e>"u")){var s=this;if(t==="")throw {code:"D3010",stack:new Error().stack,value:t,index:2};if(f<0)throw {code:"D3011",stack:new Error().stack,value:f,index:4};var h;typeof r=="string"?h=function(ye){for(var Me="",ue=0,De=r.indexOf("$",ue);De!==-1&&ue<r.length;){Me+=r.substring(ue,De),ue=De+1;var Ve=r.charAt(ue);if(Ve==="$")Me+="$",ue++;else if(Ve==="0")Me+=ye.match,ue++;else {var Fe;if(ye.groups.length===0?Fe=1:Fe=Math.floor(Math.log(ye.groups.length)*Math.LOG10E)+1,De=parseInt(r.substring(ue,ue+Fe),10),Fe>1&&De>ye.groups.length&&(De=parseInt(r.substring(ue,ue+Fe-1),10)),isNaN(De))Me+="$";else {if(ye.groups.length>0){var ot=ye.groups[De-1];typeof ot<"u"&&(Me+=ot);}ue+=De.toString().length;}}De=r.indexOf("$",ue);}return Me+=r.substring(ue),Me}:h=r;var T="",I=0;if(typeof f>"u"||f>0){var W=0;if(typeof t=="string"){for(var ve=e.indexOf(t,I);ve!==-1&&(typeof f>"u"||W<f);)T+=e.substring(I,ve),T+=r,I=ve+t.length,W++,ve=e.indexOf(t,I);T+=e.substring(I);}else {var ae=await ee(t,e);if(typeof ae<"u"){for(;typeof ae<"u"&&(typeof f>"u"||W<f);){T+=e.substring(I,ae.start);var ke=h.apply(s,[ae]);if(V(ke)&&(ke=await ke),typeof ke=="string")T+=ke;else throw {code:"D3012",stack:new Error().stack,value:ke};I=ae.start+ae.match.length,W++,ae=await ee(ae.next);}T+=e.substring(I);}else T=e;}}else T=e;return T}}function Be(e){if(!(typeof e>"u")){var t=typeof window<"u"?window.btoa:function(r){return new B.Buffer.from(r,"binary").toString("base64")};return t(e)}}function a(e){if(!(typeof e>"u")){var t=typeof window<"u"?window.atob:function(r){return new B.Buffer.from(r,"base64").toString("binary")};return t(e)}}function u(e){if(!(typeof e>"u")){var t;try{t=encodeURIComponent(e);}catch{throw {code:"D3140",stack:new Error().stack,value:e,functionName:"encodeUrlComponent"}}return t}}function $(e){if(!(typeof e>"u")){var t;try{t=encodeURI(e);}catch{throw {code:"D3140",stack:new Error().stack,value:e,functionName:"encodeUrl"}}return t}}function te(e){if(!(typeof e>"u")){var t;try{t=decodeURIComponent(e);}catch{throw {code:"D3140",stack:new Error().stack,value:e,functionName:"decodeUrlComponent"}}return t}}function we(e){if(!(typeof e>"u")){var t;try{t=decodeURI(e);}catch{throw {code:"D3140",stack:new Error().stack,value:e,functionName:"decodeUrl"}}return t}}async function le(e,t,r){if(!(typeof e>"u")){if(r<0)throw {code:"D3020",stack:new Error().stack,value:r,index:3};var f=[];if(typeof r>"u"||r>0)if(typeof t=="string")f=e.split(t,r);else {var s=0,h=await ee(t,e);if(typeof h<"u"){for(var T=0;typeof h<"u"&&(typeof r>"u"||s<r);)f.push(e.substring(T,h.start)),T=h.end,h=await ee(h.next),s++;(typeof r>"u"||s<r)&&f.push(e.substring(T));}else f.push(e);}return f}}function l(e,t){if(!(typeof e>"u"))return typeof t>"u"&&(t=""),e.join(t)}function v(e,t,r){if(!(typeof e>"u")){var f={"decimal-separator":".","grouping-separator":",","exponent-separator":"e",infinity:"Infinity","minus-sign":"-",NaN:"NaN",percent:"%","per-mille":"\u2030","zero-digit":"0",digit:"#","pattern-separator":";"},s=f;typeof r<"u"&&Object.keys(r).forEach(function(J){s[J]=r[J];});for(var h=[],T=s["zero-digit"].charCodeAt(0),I=T;I<T+10;I++)h.push(String.fromCharCode(I));var W=h.concat([s["decimal-separator"],s["exponent-separator"],s["grouping-separator"],s.digit,s["pattern-separator"]]),ve=t.split(s["pattern-separator"]);if(ve.length>2)throw {code:"D3080",stack:new Error().stack};var ae=function(J){var Ee=(function(){for(var Ce,We=0;We<J.length;We++)if(Ce=J.charAt(We),W.indexOf(Ce)!==-1&&Ce!==s["exponent-separator"])return J.substring(0,We)})(),$e=(function(){for(var Ce,We=J.length-1;We>=0;We--)if(Ce=J.charAt(We),W.indexOf(Ce)!==-1&&Ce!==s["exponent-separator"])return J.substring(We+1)})(),Se=J.substring(Ee.length,J.length-$e.length),Ne,nt,Ie,at,ze=J.indexOf(s["exponent-separator"],Ee.length);ze===-1||ze>J.length-$e.length?(Ne=Se,nt=void 0):(Ne=Se.substring(0,ze),nt=Se.substring(ze+1));var Ze=Ne.indexOf(s["decimal-separator"]);return Ze===-1?(Ie=Ne,at=$e):(Ie=Ne.substring(0,Ze),at=Ne.substring(Ze+1)),{prefix:Ee,suffix:$e,activePart:Se,mantissaPart:Ne,exponentPart:nt,integerPart:Ie,fractionalPart:at,subpicture:J}},ke=function(J){var Ee,$e,Se=J.subpicture,Ne=Se.indexOf(s["decimal-separator"]);Ne!==Se.lastIndexOf(s["decimal-separator"])&&(Ee="D3081"),Se.indexOf(s.percent)!==Se.lastIndexOf(s.percent)&&(Ee="D3082"),Se.indexOf(s["per-mille"])!==Se.lastIndexOf(s["per-mille"])&&(Ee="D3083"),Se.indexOf(s.percent)!==-1&&Se.indexOf(s["per-mille"])!==-1&&(Ee="D3084");var nt=false;for($e=0;$e<J.mantissaPart.length;$e++){var Ie=J.mantissaPart.charAt($e);if(h.indexOf(Ie)!==-1||Ie===s.digit){nt=true;break}}nt||(Ee="D3085");var at=J.activePart.split("").map(function(Ce){return W.indexOf(Ce)===-1?"p":"a"}).join("");at.indexOf("p")!==-1&&(Ee="D3086"),Ne!==-1?(Se.charAt(Ne-1)===s["grouping-separator"]||Se.charAt(Ne+1)===s["grouping-separator"])&&(Ee="D3087"):J.integerPart.charAt(J.integerPart.length-1)===s["grouping-separator"]&&(Ee="D3088"),Se.indexOf(s["grouping-separator"]+s["grouping-separator"])!==-1&&(Ee="D3089");var ze=J.integerPart.indexOf(s.digit);ze!==-1&&J.integerPart.substring(0,ze).split("").filter(function(Ce){return h.indexOf(Ce)>-1}).length>0&&(Ee="D3090"),ze=J.fractionalPart.lastIndexOf(s.digit),ze!==-1&&J.fractionalPart.substring(ze).split("").filter(function(Ce){return h.indexOf(Ce)>-1}).length>0&&(Ee="D3091");var Ze=typeof J.exponentPart=="string";if(Ze&&J.exponentPart.length>0&&(Se.indexOf(s.percent)!==-1||Se.indexOf(s["per-mille"])!==-1)&&(Ee="D3092"),Ze&&(J.exponentPart.length===0||J.exponentPart.split("").filter(function(Ce){return h.indexOf(Ce)===-1}).length>0)&&(Ee="D3093"),Ee)throw {code:Ee,stack:new Error().stack}},ye=function(J){var Ee=function(Re,wt){for(var pt=[],Ke=Re.indexOf(s["grouping-separator"]);Ke!==-1;){var bt=(wt?Re.substring(0,Ke):Re.substring(Ke)).split("").filter(function(ut){return h.indexOf(ut)!==-1||ut===s.digit}).length;pt.push(bt),Ke=J.integerPart.indexOf(s["grouping-separator"],Ke+1);}return pt},$e=Ee(J.integerPart),Se=function(Re){if(Re.length===0)return 0;for(var wt=function(bt,ut){return ut===0?bt:wt(ut,bt%ut)},pt=Re.reduce(wt),Ke=1;Ke<=Re.length;Ke++)if(Re.indexOf(Ke*pt)===-1)return 0;return pt},Ne=Se($e),nt=Ee(J.fractionalPart,true),Ie=J.integerPart.split("").filter(function(Re){return h.indexOf(Re)!==-1}).length,at=Ie,ze=J.fractionalPart.split(""),Ze=ze.filter(function(Re){return h.indexOf(Re)!==-1}).length,Ce=ze.filter(function(Re){return h.indexOf(Re)!==-1||Re===s.digit}).length,We=typeof J.exponentPart=="string";Ie===0&&Ce===0&&(We?(Ze=1,Ce=1):Ie=1),We&&Ie===0&&J.integerPart.indexOf(s.digit)!==-1&&(Ie=1),Ie===0&&Ze===0&&(Ze=1);var Ut=0;return We&&(Ut=J.exponentPart.split("").filter(function(Re){return h.indexOf(Re)!==-1}).length),{integerPartGroupingPositions:$e,regularGrouping:Ne,minimumIntegerPartSize:Ie,scalingFactor:at,prefix:J.prefix,fractionalPartGroupingPositions:nt,minimumFactionalPartSize:Ze,maximumFactionalPartSize:Ce,minimumExponentSize:Ut,suffix:J.suffix,picture:J.subpicture}},Me=ve.map(ae);Me.forEach(ke);var ue=Me.map(ye),De=s["minus-sign"],Ve=s["zero-digit"],Fe=s["decimal-separator"],ot=s["grouping-separator"];ue.length===1&&(ue.push(JSON.parse(JSON.stringify(ue[0]))),ue[1].prefix=De+ue[1].prefix);var Te;e>=0?Te=ue[0]:Te=ue[1];var lt;Te.picture.indexOf(s.percent)!==-1?lt=e*100:Te.picture.indexOf(s["per-mille"])!==-1?lt=e*1e3:lt=e;var rt,st;if(Te.minimumExponentSize===0)rt=lt;else {var Ht=Math.pow(10,Te.scalingFactor),Lt=Math.pow(10,Te.scalingFactor-1);for(rt=lt,st=0;rt<Lt;)rt*=10,st-=1;for(;rt>Ht;)rt/=10,st+=1;}var zt=O(rt,Te.maximumFactionalPartSize),Rt=function(J,Ee){var $e=Math.abs(J).toFixed(Ee);return Ve!=="0"&&($e=$e.split("").map(function(Se){return Se>="0"&&Se<="9"?h[Se.charCodeAt(0)-48]:Se}).join("")),$e},Q=Rt(zt,Te.maximumFactionalPartSize),_e=Q.indexOf(".");for(_e===-1?Q=Q+Fe:Q=Q.replace(".",Fe);Q.charAt(0)===Ve;)Q=Q.substring(1);for(;Q.charAt(Q.length-1)===Ve;)Q=Q.substring(0,Q.length-1);_e=Q.indexOf(Fe);var dt=Te.minimumIntegerPartSize-_e,jt=Te.minimumFactionalPartSize-(Q.length-_e-1);if(Q=(dt>0?new Array(dt+1).join(Ve):"")+Q,Q=Q+(jt>0?new Array(jt+1).join(Ve):""),_e=Q.indexOf(Fe),Te.regularGrouping>0)for(var Wt=Math.floor((_e-1)/Te.regularGrouping),vt=1;vt<=Wt;vt++)Q=[Q.slice(0,_e-vt*Te.regularGrouping),ot,Q.slice(_e-vt*Te.regularGrouping)].join("");else Te.integerPartGroupingPositions.forEach(function(J){Q=[Q.slice(0,_e-J),ot,Q.slice(_e-J)].join(""),_e++;});if(_e=Q.indexOf(Fe),Te.fractionalPartGroupingPositions.forEach(function(J){Q=[Q.slice(0,J+_e+1),ot,Q.slice(J+_e+1)].join("");}),_e=Q.indexOf(Fe),(Te.picture.indexOf(Fe)===-1||_e===Q.length-1)&&(Q=Q.substring(0,Q.length-1)),typeof st<"u"){var mt=Rt(st,0);dt=Te.minimumExponentSize-mt.length,dt>0&&(mt=new Array(dt+1).join(Ve)+mt),Q=Q+s["exponent-separator"]+(st<0?De:"")+mt;}return Q=Te.prefix+Q+Te.suffix,Q}}function p(e,t){if(!(typeof e>"u")){if(e=O(e),typeof t>"u"?t=10:t=O(t),t<2||t>36)throw {code:"D3100",stack:new Error().stack,value:t};var r=e.toString(t);return r}}function E(e){var t;if(!(typeof e>"u")){if(typeof e=="number")t=e;else if(typeof e=="string"&&/^-?[0-9]+(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(e)&&!isNaN(parseFloat(e))&&isFinite(e))t=parseFloat(e);else if(typeof e=="string"&&/^(0[xX][0-9A-Fa-f]+)|(0[oO][0-7]+)|(0[bB][0-1]+)$/.test(e))t=Number(e);else if(e===true)t=1;else if(e===false)t=0;else throw {code:"D3030",value:e,stack:new Error().stack,index:1};return t}}function M(e){var t;if(!(typeof e>"u"))return t=Math.abs(e),t}function C(e){var t;if(!(typeof e>"u"))return t=Math.floor(e),t}function b(e){var t;if(!(typeof e>"u"))return t=Math.ceil(e),t}function O(e,t){var r;if(!(typeof e>"u")){if(t){var f=e.toString().split("e");e=+(f[0]+"e"+(f[1]?+f[1]+t:t));}r=Math.round(e);var s=r-e;return Math.abs(s)===.5&&Math.abs(r%2)===1&&(r=r-1),t&&(f=r.toString().split("e"),r=+(f[0]+"e"+(f[1]?+f[1]-t:-t))),Object.is(r,-0)&&(r=0),r}}function z(e){var t;if(!(typeof e>"u")){if(e<0)throw {stack:new Error().stack,code:"D3060",index:1,value:e};return t=Math.sqrt(e),t}}function ie(e,t){var r;if(!(typeof e>"u")){if(r=Math.pow(e,t),!isFinite(r))throw {stack:new Error().stack,code:"D3061",index:1,value:e,exp:t};return r}}function se(){return Math.random()}function L(e){if(!(typeof e>"u")){var t=false;if(Array.isArray(e)){if(e.length===1)t=L(e[0]);else if(e.length>1){var r=e.filter(function(f){return L(f)});t=r.length>0;}}else typeof e=="string"?e.length>0&&(t=true):K(e)?e!==0&&(t=true):e!==null&&typeof e=="object"&&!k(e)?Object.keys(e).length>0&&(t=true):typeof e=="boolean"&&e===true&&(t=true);return t}}function Y(e){if(!(typeof e>"u"))return !L(e)}function re(e,t,r,f){var s=[t],h=me(e);return h>=2&&s.push(r),h>=3&&s.push(f),s}async function H(e,t){if(!(typeof e>"u")){for(var r=F(),f=0;f<e.length;f++){var s=re(t,e[f],f,e),h=await t.apply(this,s);typeof h<"u"&&r.push(h);}return r}}async function Oe(e,t){if(!(typeof e>"u")){for(var r=F(),f=0;f<e.length;f++){var s=e[f],h=re(t,s,f,e),T=await t.apply(this,h);L(T)&&r.push(s);}return r}}async function Je(e,t){if(!(typeof e>"u")){for(var r=false,f,s=0;s<e.length;s++){var h=e[s],T=true;if(typeof t<"u"){var I=re(t,h,s,e),W=await t.apply(this,I);T=L(W);}if(T)if(!r)f=h,r=true;else throw {stack:new Error().stack,code:"D3138",index:s}}if(!r)throw {stack:new Error().stack,code:"D3139"};return f}}function je(){for(var e=[],t=Array.prototype.slice.call(arguments),r=Math.min.apply(Math,t.map(function(h){return Array.isArray(h)?h.length:0})),f=0;f<r;f++){var s=t.map(h=>h[f]);e.push(s);}return e}async function Pe(e,t,r){if(!(typeof e>"u")){var f,s=me(t);if(s<2)throw {stack:new Error().stack,code:"D3050",index:1};var h;for(typeof r>"u"&&e.length>0?(f=e[0],h=1):(f=r,h=0);h<e.length;){var T=[f,e[h]];s>=3&&T.push(h),s>=4&&T.push(e),f=await t.apply(this,T),h++;}return f}}function Ue(e){var t=F();if(Array.isArray(e)){var r={};e.forEach(function(f){var s=Ue(f);s.forEach(function(h){r[h]=true;});}),t=Ue(r);}else e!==null&&typeof e=="object"&&!k(e)&&Object.keys(e).forEach(f=>t.push(f));return t}function Qe(e,t){var r;if(Array.isArray(e)){r=F();for(var f=0;f<e.length;f++){var s=Qe(e[f],t);typeof s<"u"&&(Array.isArray(s)?s.forEach(h=>r.push(h)):r.push(s));}}else e!==null&&typeof e=="object"&&!k(e)&&(r=e[t]);return r}function et(e,t){return typeof e>"u"?t:typeof t>"u"?e:(Array.isArray(e)||(e=F(e)),Array.isArray(t)||(t=[t]),e.concat(t))}function yt(e){return !(typeof e>"u")}function tt(e){var t=F();if(Array.isArray(e))e.forEach(function(s){t=et(t,tt(s));});else if(e!==null&&typeof e=="object"&&!D(e))for(var r in e){var f={};f[r]=e[r],t.push(f);}else t=e;return t}function j(e){if(!(typeof e>"u")){var t={};return e.forEach(function(r){for(var f in r)t[f]=r[f];}),t}}function gt(e){if(!(typeof e>"u")){if(e.length<=1)return e;for(var t=e.length,r=new Array(t),f=0;f<t;f++)r[t-f-1]=e[f];return r}}async function ct(e,t){var r=F();for(var f in e){var s=re(t,e[f],f,e),h=await t.apply(this,s);typeof h<"u"&&r.push(h);}return r}function Ge(e){throw {code:"D3137",stack:new Error().stack,message:e||"$error() function evaluated"}}function it(e,t){if(!e)throw {code:"D3141",stack:new Error().stack,message:t||"$assert() statement failed"}}function Xe(e){if(e!==void 0)return e===null?"null":K(e)?"number":typeof e=="string"?"string":typeof e=="boolean"?"boolean":Array.isArray(e)?"array":k(e)?"function":"object"}async function ge(e,t){if(!(typeof e>"u")){if(e.length<=1)return e;var r;if(typeof t>"u"){if(!pe(e)&&!X(e))throw {stack:new Error().stack,code:"D3070",index:1};r=async function(T,I){return T>I};}else r=t;var f=async function(T,I){var W=async function(ae,ke,ye){ke.length===0?Array.prototype.push.apply(ae,ye):ye.length===0?Array.prototype.push.apply(ae,ke):await r(ke[0],ye[0])?(ae.push(ye[0]),await W(ae,ke,ye.slice(1))):(ae.push(ke[0]),await W(ae,ke.slice(1),ye));},ve=[];return await W(ve,T,I),ve},s=async function(T){if(!Array.isArray(T)||T.length<=1)return T;var I=Math.floor(T.length/2),W=T.slice(0,I),ve=T.slice(I);return W=await s(W),ve=await s(ve),await f(W,ve)},h=await s(e);return h}}function n(e){if(!(typeof e>"u")){if(e.length<=1)return e;for(var t=new Array(e.length),r=0;r<e.length;r++){var f=Math.floor(Math.random()*(r+1));r!==f&&(t[r]=t[f]),t[f]=e[r];}return t}}function i(e){if(!(typeof e>"u")){if(!Array.isArray(e)||e.length<=1)return e;for(var t=w(e)?F():[],r=0;r<e.length;r++){for(var f=e[r],s=false,h=0;h<t.length;h++)if(be(f,t[h])){s=true;break}s||t.push(f);}return t}}async function o(e,t){var r={};for(var f in e){var s=e[f],h=re(t,s,f,e),T=await t.apply(this,h);L(T)&&(r[f]=s);}return Object.keys(r).length===0&&(r=void 0),r}return {sum:x,count:Z,max:_,min:g,average:R,string:N,substring:ne,substringBefore:fe,substringAfter:de,lowercase:he,uppercase:oe,length:Ae,trim:He,pad:ce,match:G,contains:Le,replace:xe,split:le,join:l,formatNumber:v,formatBase:p,number:E,floor:C,ceil:b,round:O,abs:M,sqrt:z,power:ie,random:se,boolean:L,not:Y,map:H,zip:je,filter:Oe,single:Je,foldLeft:Pe,sift:o,keys:Ue,lookup:Qe,append:et,exists:yt,spread:tt,merge:j,reverse:gt,each:ct,error:Ge,assert:it,type:Xe,sort:ge,shuffle:n,distinct:i,base64encode:Be,base64decode:a,encodeUrlComponent:u,encodeUrl:$,decodeUrlComponent:te,decodeUrl:we}})();P.exports=U;}).call(this);}).call(this,typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{});},{"./utils":6}],3:[function(S,P,A){var B=S("./datetime"),d=S("./functions"),U=S("./utils"),K=S("./parser"),X=S("./signature"),pe=(function(){var F=U.isNumeric,w=U.isArrayOfStrings,k=U.isArrayOfNumbers,D=U.createSequence,V=U.isSequence,me=U.isFunction,be=U.isLambda,q=U.isIterable,x=U.isPromise,Z=U.getFunctionArity,_=U.isDeepEqual,g=Ge(null);async function R(n,i,o){var e,t=o.lookup(Symbol.for("jsonata.__evaluate_entry"));switch(t&&await t(n,i,o),n.type){case "path":e=await N(n,i,o);break;case "binary":e=await Ae(n,i,o);break;case "unary":e=await He(n,i,o);break;case "name":e=ce(n,i);break;case "string":case "number":case "value":e=ee(n);break;case "wildcard":e=Le(n,i);break;case "descendant":e=xe(n,i);break;case "parent":e=o.lookup(n.slot.label);break;case "condition":e=await C(n,i,o);break;case "block":e=await b(n,i,o);break;case "bind":e=await M(n,i,o);break;case "regex":e=O(n);break;case "function":e=await re(n,i,o);break;case "variable":e=z(n,i,o);break;case "lambda":e=Je(n,i,o);break;case "partial":e=await je(n,i,o);break;case "apply":e=await Y(n,i,o);break;case "transform":e=se(n,i,o);break}if(Object.prototype.hasOwnProperty.call(n,"predicate"))for(var r=0;r<n.predicate.length;r++)e=await oe(n.predicate[r].expr,e,o);n.type!=="path"&&Object.prototype.hasOwnProperty.call(n,"group")&&(e=await v(n.group,e,o));var f=o.lookup(Symbol.for("jsonata.__evaluate_exit"));return f&&await f(n,i,o,e),e&&V(e)&&!e.tupleStream&&(n.keepArray&&(e.keepSingleton=true),e.length===0?e=void 0:e.length===1&&(e=e.keepSingleton?e:e[0])),e}async function N(n,i,o){var e;Array.isArray(i)&&n.steps[0].type!=="variable"?e=i:e=D(i);for(var t,r=false,f=void 0,s=0;s<n.steps.length;s++){var h=n.steps[s];if(h.tuple&&(r=true),s===0&&h.consarray?t=await R(h,e,o):r?f=await he(h,e,f,o):t=await fe(h,e,o,s===n.steps.length-1),!r&&(typeof t>"u"||t.length===0))break;typeof h.focus>"u"&&(e=t);}if(r)if(n.tuple)t=f;else for(t=D(),s=0;s<f.length;s++)t.push(f[s]["@"]);return n.keepSingletonArray&&(Array.isArray(t)&&t.cons&&!t.sequence&&(t=D(t)),t.keepSingleton=true),n.hasOwnProperty("group")&&(t=await v(n.group,r?f:t,o)),t}function ne(n,i){var o=Ge(n);for(let e in i)o.bind(e,i[e]);return o}async function fe(n,i,o,e){var t;if(n.type==="sort")return t=await ie(n,i,o),n.stages&&(t=await de(n.stages,t,o)),t;t=D();for(var r=0;r<i.length;r++){var f=await R(n,i[r],o);if(n.stages)for(var s=0;s<n.stages.length;s++)f=await oe(n.stages[s].expr,f,o);typeof f<"u"&&t.push(f);}var h=D();return e&&t.length===1&&Array.isArray(t[0])&&!V(t[0])?h=t[0]:t.forEach(function(T){!Array.isArray(T)||T.cons?h.push(T):T.forEach(I=>h.push(I));}),h}async function de(n,i,o){for(var e=i,t=0;t<n.length;t++){var r=n[t];switch(r.type){case "filter":e=await oe(r.expr,e,o);break;case "index":for(var f=0;f<e.length;f++){var s=e[f];s[r.value]=f;}break}}return e}async function he(n,i,o,e){var t;if(n.type==="sort"){if(o)t=await ie(n,o,e);else {var r=await ie(n,i,e);t=D(),t.tupleStream=true;for(var f=0;f<r.length;f++){var s={"@":r[f]};s[n.index]=f,t.push(s);}}return n.stages&&(t=await de(n.stages,t,e)),t}t=D(),t.tupleStream=true;var h=e;o===void 0&&(o=i.map(ve=>({"@":ve})));for(var T=0;T<o.length;T++){h=ne(e,o[T]);var I=await R(n,o[T]["@"],h);if(typeof I<"u"){Array.isArray(I)||(I=[I]);for(var W=0;W<I.length;W++)s={},Object.assign(s,o[T]),I.tupleStream?Object.assign(s,I[W]):(n.focus?(s[n.focus]=I[W],s["@"]=o[T]["@"]):s["@"]=I[W],n.index&&(s[n.index]=W),n.ancestor&&(s[n.ancestor.label]=o[T]["@"])),t.push(s);}}return n.stages&&(t=await de(n.stages,t,e)),t}async function oe(n,i,o){var e=D();if(i&&i.tupleStream&&(e.tupleStream=true),Array.isArray(i)||(i=D(i)),n.type==="number"){var t=Math.floor(n.value);t<0&&(t=i.length+t);var r=await i[t];typeof r<"u"&&(Array.isArray(r)?e=r:e.push(r));}else for(t=0;t<i.length;t++){var r=i[t],f=r,s=o;i.tupleStream&&(f=r["@"],s=ne(o,r));var h=await R(n,f,s);F(h)&&(h=[h]),k(h)?h.forEach(function(I){var W=Math.floor(I);W<0&&(W=i.length+W),W===t&&e.push(r);}):d.boolean(h)&&e.push(r);}return e}async function Ae(n,i,o){var e,t=await R(n.lhs,i,o),r=n.value,f=async()=>await R(n.rhs,i,o);if(r==="and"||r==="or")try{return await we(t,f,r)}catch(h){throw h.position=n.position,h.token=r,h}var s=await f();try{switch(r){case "+":case "-":case "*":case "/":case "%":e=a(t,s,r);break;case "=":case "!=":e=u(t,s,r);break;case "<":case "<=":case ">":case ">=":e=$(t,s,r);break;case "&":e=l(t,s);break;case "..":e=E(t,s);break;case "in":e=te(t,s);break}}catch(h){throw h.position=n.position,h.token=r,h}return e}async function He(n,i,o){var e;switch(n.value){case "-":if(e=await R(n.expression,i,o),typeof e>"u")e=void 0;else if(F(e))e=-e;else throw {code:"D1002",stack:new Error().stack,position:n.position,token:n.value,value:e};break;case "[":e=[];let f=await Promise.all(n.expressions.map(async(s,h)=>(o.isParallelCall=h>0,[s,await R(s,i,o)])));for(let s of f){var[t,r]=s;typeof r<"u"&&(t.value==="["?e.push(r):e=d.append(e,r));}n.consarray&&Object.defineProperty(e,"cons",{enumerable:false,configurable:false,value:true});break;case "{":e=await v(n,i,o);break}return e}function ce(n,i,o){return d.lookup(i,n.value)}function ee(n){return n.value}function Le(n,i){var o=D();return Array.isArray(i)&&i.outerWrapper&&i.length>0&&(i=i[0]),i!==null&&typeof i=="object"&&Object.keys(i).forEach(function(e){var t=i[e];Array.isArray(t)?(t=G(t),o=d.append(o,t)):o.push(t);}),o}function G(n,i){return typeof i>"u"&&(i=[]),Array.isArray(n)?n.forEach(function(o){G(o,i);}):i.push(n),i}function xe(n,i){var o,e=D();return typeof i<"u"&&(Be(i,e),e.length===1?o=e[0]:o=e),o}function Be(n,i){Array.isArray(n)||i.push(n),Array.isArray(n)?n.forEach(function(o){Be(o,i);}):n!==null&&typeof n=="object"&&Object.keys(n).forEach(function(o){Be(n[o],i);});}function a(n,i,o){var e;if(typeof n<"u"&&!F(n))throw {code:"T2001",stack:new Error().stack,value:n};if(typeof i<"u"&&!F(i))throw {code:"T2002",stack:new Error().stack,value:i};if(typeof n>"u"||typeof i>"u")return e;switch(o){case "+":e=n+i;break;case "-":e=n-i;break;case "*":e=n*i;break;case "/":e=n/i;break;case "%":e=n%i;break}return e}function u(n,i,o){var e,t=typeof n,r=typeof i;if(t==="undefined"||r==="undefined")return false;switch(o){case "=":e=_(n,i);break;case "!=":e=!_(n,i);break}return e}function $(n,i,o){var e,t=typeof n,r=typeof i,f=t==="undefined"||t==="string"||t==="number",s=r==="undefined"||r==="string"||r==="number";if(!f||!s)throw {code:"T2010",stack:new Error().stack,value:t==="string"||t==="number"?i:n};if(!(t==="undefined"||r==="undefined")){if(t!==r)throw {code:"T2009",stack:new Error().stack,value:n,value2:i};switch(o){case "<":e=n<i;break;case "<=":e=n<=i;break;case ">":e=n>i;break;case ">=":e=n>=i;break}return e}}function te(n,i){var o=false;if(typeof n>"u"||typeof i>"u")return false;Array.isArray(i)||(i=[i]);for(var e=0;e<i.length;e++)if(i[e]===n){o=true;break}return o}async function we(n,i,o){var e,t=le(n);switch(o){case "and":e=t&&le(await i());break;case "or":e=t||le(await i());break}return e}function le(n){var i=d.boolean(n);return typeof i>"u"?false:i}function l(n,i){var o,e="",t="";return typeof n<"u"&&(e=d.string(n)),typeof i<"u"&&(t=d.string(i)),o=e.concat(t),o}async function v(n,i,o){var e={},t={},r=!!(i&&i.tupleStream);Array.isArray(i)||(i=D(i)),i.length===0&&i.push(void 0);for(var f=0;f<i.length;f++)for(var s=i[f],h=r?ne(o,s):o,T=0;T<n.lhs.length;T++){var I=n.lhs[T],W=await R(I[0],r?s["@"]:s,h);if(typeof W!="string"&&W!==void 0)throw {code:"T1003",stack:new Error().stack,position:n.position,value:W};if(W!==void 0){var ve={data:s,exprIndex:T};if(t.hasOwnProperty(W)){if(t[W].exprIndex!==T)throw {code:"D1009",stack:new Error().stack,position:n.position,value:W};t[W].data=d.append(t[W].data,s);}else t[W]=ve;}}let ae=await Promise.all(Object.keys(t).map(async(ye,Me)=>{let ue=t[ye];var De=ue.data,Ve=o;if(r){var Fe=p(ue.data);De=Fe["@"],delete Fe["@"],Ve=ne(o,Fe);}return o.isParallelCall=Me>0,[ye,await R(n.lhs[ue.exprIndex][1],De,Ve)]}));for(let ye of ae){var[W,ke]=await ye;typeof ke<"u"&&(e[W]=ke);}return e}function p(n){if(!Array.isArray(n))return n;var i={};Object.assign(i,n[0]);for(var o=1;o<n.length;o++)for(let e in n[o])i[e]=d.append(i[e],n[o][e]);return i}function E(n,i){var o;if(typeof n<"u"&&!Number.isInteger(n))throw {code:"T2003",stack:new Error().stack,value:n};if(typeof i<"u"&&!Number.isInteger(i))throw {code:"T2004",stack:new Error().stack,value:i};if(typeof n>"u"||typeof i>"u"||n>i)return o;var e=i-n+1;if(e>1e7)throw {code:"D2014",stack:new Error().stack,value:e};o=new Array(e);for(var t=n,r=0;t<=i;t++,r++)o[r]=t;return o.sequence=true,o}async function M(n,i,o){var e=await R(n.rhs,i,o);return o.bind(n.lhs.value,e),e}async function C(n,i,o){var e,t=await R(n.condition,i,o);return d.boolean(t)?e=await R(n.then,i,o):typeof n.else<"u"&&(e=await R(n.else,i,o)),e}async function b(n,i,o){for(var e,t=Ge(o),r=0;r<n.expressions.length;r++)e=await R(n.expressions[r],i,t);return e}function O(n){var i=new ge.RegexEngine(n.value),o=function(e,t){var r;i.lastIndex=t||0;var f=i.exec(e);if(f!==null){if(r={match:f[0],start:f.index,end:f.index+f[0].length,groups:[]},f.length>1)for(var s=1;s<f.length;s++)r.groups.push(f[s]);r.next=function(){if(!(i.lastIndex>=e.length)){var h=o(e,i.lastIndex);if(h&&h.match==="")throw {code:"D1004",stack:new Error().stack,position:n.position,value:n.value.source};return h}};}return r};return o}function z(n,i,o){var e;return n.value===""?e=i&&i.outerWrapper?i[0]:i:e=o.lookup(n.value),e}async function ie(n,i,o){var e,t=i,r=!!i.tupleStream,f=async function(h,T){for(var I=0,W=0;I===0&&W<n.terms.length;W++){var ve=n.terms[W],ae=h,ke=o;r&&(ae=h["@"],ke=ne(o,h));var ye=await R(ve.expression,ae,ke);ae=T,ke=o,r&&(ae=T["@"],ke=ne(o,T));var Me=await R(ve.expression,ae,ke),ue=typeof ye,De=typeof Me;if(ue==="undefined"){I=De==="undefined"?0:1;continue}if(De==="undefined"){I=-1;continue}if(!(ue==="string"||ue==="number")||!(De==="string"||De==="number"))throw {code:"T2008",stack:new Error().stack,position:n.position,value:ue==="string"||ue==="number"?Me:ye};if(ue!==De)throw {code:"T2007",stack:new Error().stack,position:n.position,value:ye,value2:Me};ye!==Me&&(ye<Me?I=-1:I=1,ve.descending===true&&(I=-I));}return I===1},s={environment:o,input:i};return e=await d.sort.apply(s,[t,f]),e}function se(n,i,o){var e=async function(t){if(!(typeof t>"u")){var r=o.lookup("clone");if(!me(r))throw {code:"T2013",stack:new Error().stack,position:n.position};var f=await H(r,[t],null,o),s=await R(n.pattern,f,o);if(typeof s<"u"){Array.isArray(s)||(s=[s]);for(var h=0;h<s.length;h++){var T=s[h];if(T&&(T.isPrototypeOf(f)||T instanceof Object.constructor))throw {code:"D1010",stack:new Error().stack,position:n.position};var I=await R(n.update,T,o),W=typeof I;if(W!=="undefined"){if(W!=="object"||I===null||Array.isArray(I))throw {code:"T2011",stack:new Error().stack,position:n.update.position,value:I};for(var ve in I)T[ve]=I[ve];}if(typeof n.delete<"u"){var ae=await R(n.delete,T,o);if(typeof ae<"u"){var ke=ae;if(Array.isArray(ae)||(ae=[ae]),!w(ae))throw {code:"T2012",stack:new Error().stack,position:n.delete.position,value:ke};for(var ye=0;ye<ae.length;ye++)typeof T=="object"&&T!==null&&delete T[ae[ye]];}}}}return f}};return j(e,"<(oa):o>")}var L=K("function($f, $g) { function($x){ $g($f($x)) } }");async function Y(n,i,o){var e,t=await R(n.lhs,i,o);if(n.rhs.type==="function")e=await re(n.rhs,i,o,{context:t});else {var r=await R(n.rhs,i,o);if(!me(r))throw {code:"T2006",stack:new Error().stack,position:n.position,value:r};if(me(t)){var f=await R(L,null,o);e=await H(f,[t,r],null,o);}else e=await H(r,[t],null,o);}return e}async function re(n,i,o,e){var t,r=await R(n.procedure,i,o);if(typeof r>"u"&&n.procedure.type==="path"&&o.lookup(n.procedure.steps[0].value))throw {code:"T1005",stack:new Error().stack,position:n.position,token:n.procedure.steps[0].value};var f=[];typeof e<"u"&&f.push(e.context);for(var s=0;s<n.arguments.length;s++){let T=await R(n.arguments[s],i,o);if(me(T)){let I=async function(...W){return await H(T,W,null,o)};I.arity=Z(T),f.push(I);}else f.push(T);}var h=n.procedure.type==="path"?n.procedure.steps[0].value:n.procedure.value;try{typeof r=="object"&&(r.token=h,r.position=n.position),t=await H(r,f,i,o);}catch(T){throw T.position||(T.position=n.position),T.token||(T.token=h),T}return t}async function H(n,i,o,e){var t;for(t=await Oe(n,i,o,e);be(t)&&t.thunk===true;){var r=await R(t.body.procedure,t.input,t.environment);t.body.procedure.type==="variable"&&(r.token=t.body.procedure.value),r.position=t.body.procedure.position;for(var f=[],s=0;s<t.body.arguments.length;s++)f.push(await R(t.body.arguments[s],t.input,t.environment));t=await Oe(r,f,o,e);}return t}async function Oe(n,i,o,e){var t;try{var r=i;if(n&&(r=Pe(n.signature,i,o)),be(n))t=await Ue(n,r);else if(n&&n._jsonata_function===!0){var f={environment:e,input:o};t=n.implementation.apply(f,r),q(t)&&(t=t.next().value),x(t)&&(t=await t);}else if(typeof n=="function")t=n.apply(o,r),x(t)&&(t=await t);else throw {code:"T1006",stack:new Error().stack}}catch(s){throw n&&(typeof s.token>"u"&&typeof n.token<"u"&&(s.token=n.token),s.position=n.position||s.position),s}return t}function Je(n,i,o){var e={_jsonata_lambda:true,input:i,environment:o,arguments:n.arguments,signature:n.signature,body:n.body};return n.thunk===true&&(e.thunk=true),e.apply=async function(t,r){return await H(e,r,i,t?t.environment:o)},e}async function je(n,i,o){for(var e,t=[],r=0;r<n.arguments.length;r++){var f=n.arguments[r];f.type==="operator"&&f.value==="?"?t.push(f):t.push(await R(f,i,o));}var s=await R(n.procedure,i,o);if(typeof s>"u"&&n.procedure.type==="path"&&o.lookup(n.procedure.steps[0].value))throw {code:"T1007",stack:new Error().stack,position:n.position,token:n.procedure.steps[0].value};if(be(s))e=Qe(s,t);else if(s&&s._jsonata_function===true)e=et(s.implementation,t);else if(typeof s=="function")e=et(s,t);else throw {code:"T1008",stack:new Error().stack,position:n.position,token:n.procedure.type==="path"?n.procedure.steps[0].value:n.procedure.value};return e}function Pe(n,i,o){if(typeof n>"u")return i;var e=n.validate(i,o);return e}async function Ue(n,i){var o,e=Ge(n.environment);return n.arguments.forEach(function(t,r){e.bind(t.value,i[r]);}),typeof n.body=="function"?o=await yt(n.body,e):o=await R(n.body,n.input,e),o}function Qe(n,i){var o=Ge(n.environment),e=[];n.arguments.forEach(function(r,f){var s=i[f];s&&s.type==="operator"&&s.value==="?"?e.push(r):o.bind(r.value,s);});var t={_jsonata_lambda:true,input:n.input,environment:o,arguments:e,body:n.body};return t}function et(n,i){var o=tt(n);o=o.map(function(f){return "$"+f.trim()});var e="function("+o.join(", ")+"){ _ }",t=K(e);t.body=n;var r=Qe(t,i);return r}async function yt(n,i){var o=tt(n),e=o.map(function(f){return i.lookup(f.trim())}),t={environment:i},r=n.apply(t,e);return x(r)&&(r=await r),r}function tt(n){var i=n.toString(),o=/\(([^)]*)\)/.exec(i)[1],e=o.split(",");return e}function j(n,i){var o={_jsonata_function:true,implementation:n};return typeof i<"u"&&(o.signature=X(i)),o}async function gt(n,i){if(!(typeof n>"u")){var o=this.input;typeof i<"u"&&(o=i,Array.isArray(o)&&!V(o)&&(o=D(o),o.outerWrapper=true));try{var e=K(n,!1);}catch(r){throw Xe(r),{stack:new Error().stack,code:"D3120",value:r.message,error:r}}try{var t=await R(e,o,this.environment);}catch(r){throw Xe(r),{stack:new Error().stack,code:"D3121",value:r.message,error:r}}return t}}function ct(n){if(!(typeof n>"u"))return JSON.parse(d.string(n))}function Ge(n){var i={};let o={bind:function(t,r){i[t]=r;},lookup:function(t){var r;return i.hasOwnProperty(t)?r=i[t]:n&&(r=n.lookup(t)),r},timestamp:n?n.timestamp:null,async:n?n.async:false,isParallelCall:n?n.isParallelCall:false,global:n?n.global:{ancestry:[null]}};if(n){var e=n.lookup(Symbol.for("jsonata.__createFrame_push"));e&&e(n,o);}return o}g.bind("sum",j(d.sum,"<a<n>:n>")),g.bind("count",j(d.count,"<a:n>")),g.bind("max",j(d.max,"<a<n>:n>")),g.bind("min",j(d.min,"<a<n>:n>")),g.bind("average",j(d.average,"<a<n>:n>")),g.bind("string",j(d.string,"<x-b?:s>")),g.bind("substring",j(d.substring,"<s-nn?:s>")),g.bind("substringBefore",j(d.substringBefore,"<s-s:s>")),g.bind("substringAfter",j(d.substringAfter,"<s-s:s>")),g.bind("lowercase",j(d.lowercase,"<s-:s>")),g.bind("uppercase",j(d.uppercase,"<s-:s>")),g.bind("length",j(d.length,"<s-:n>")),g.bind("trim",j(d.trim,"<s-:s>")),g.bind("pad",j(d.pad,"<s-ns?:s>")),g.bind("match",j(d.match,"<s-f<s:o>n?:a<o>>")),g.bind("contains",j(d.contains,"<s-(sf):b>")),g.bind("replace",j(d.replace,"<s-(sf)(sf)n?:s>")),g.bind("split",j(d.split,"<s-(sf)n?:a<s>>")),g.bind("join",j(d.join,"<a<s>s?:s>")),g.bind("formatNumber",j(d.formatNumber,"<n-so?:s>")),g.bind("formatBase",j(d.formatBase,"<n-n?:s>")),g.bind("formatInteger",j(B.formatInteger,"<n-s:s>")),g.bind("parseInteger",j(B.parseInteger,"<s-s:n>")),g.bind("number",j(d.number,"<(nsb)-:n>")),g.bind("floor",j(d.floor,"<n-:n>")),g.bind("ceil",j(d.ceil,"<n-:n>")),g.bind("round",j(d.round,"<n-n?:n>")),g.bind("abs",j(d.abs,"<n-:n>")),g.bind("sqrt",j(d.sqrt,"<n-:n>")),g.bind("power",j(d.power,"<n-n:n>")),g.bind("random",j(d.random,"<:n>")),g.bind("boolean",j(d.boolean,"<x-:b>")),g.bind("not",j(d.not,"<x-:b>")),g.bind("map",j(d.map,"<af>")),g.bind("zip",j(d.zip,"<a+>")),g.bind("filter",j(d.filter,"<af>")),g.bind("single",j(d.single,"<af?>")),g.bind("reduce",j(d.foldLeft,"<afj?:j>")),g.bind("sift",j(d.sift,"<o-f?:o>")),g.bind("keys",j(d.keys,"<x-:a<s>>")),g.bind("lookup",j(d.lookup,"<x-s:x>")),g.bind("append",j(d.append,"<xx:a>")),g.bind("exists",j(d.exists,"<x:b>")),g.bind("spread",j(d.spread,"<x-:a<o>>")),g.bind("merge",j(d.merge,"<a<o>:o>")),g.bind("reverse",j(d.reverse,"<a:a>")),g.bind("each",j(d.each,"<o-f:a>")),g.bind("error",j(d.error,"<s?:x>")),g.bind("assert",j(d.assert,"<bs?:x>")),g.bind("type",j(d.type,"<x:s>")),g.bind("sort",j(d.sort,"<af?:a>")),g.bind("shuffle",j(d.shuffle,"<a:a>")),g.bind("distinct",j(d.distinct,"<x:x>")),g.bind("base64encode",j(d.base64encode,"<s-:s>")),g.bind("base64decode",j(d.base64decode,"<s-:s>")),g.bind("encodeUrlComponent",j(d.encodeUrlComponent,"<s-:s>")),g.bind("encodeUrl",j(d.encodeUrl,"<s-:s>")),g.bind("decodeUrlComponent",j(d.decodeUrlComponent,"<s-:s>")),g.bind("decodeUrl",j(d.decodeUrl,"<s-:s>")),g.bind("eval",j(gt,"<sx?:x>")),g.bind("toMillis",j(B.toMillis,"<s-s?:n>")),g.bind("fromMillis",j(B.fromMillis,"<n-s?s?:s>")),g.bind("clone",j(ct,"<(oa)-:o>"));var it={S0101:"String literal must be terminated by a matching quote",S0102:"Number out of range: {{token}}",S0103:"Unsupported escape sequence: \\{{token}}",S0104:"The escape sequence \\u must be followed by 4 hex digits",S0105:"Quoted property name must be terminated with a backquote (`)",S0106:"Comment has no closing tag",S0201:"Syntax error: {{token}}",S0202:"Expected {{value}}, got {{token}}",S0203:"Expected {{value}} before end of expression",S0204:"Unknown operator: {{token}}",S0205:"Unexpected token: {{token}}",S0206:"Unknown expression type: {{token}}",S0207:"Unexpected end of expression",S0208:"Parameter {{value}} of function definition must be a variable name (start with $)",S0209:"A predicate cannot follow a grouping expression in a step",S0210:"Each step can only have one grouping expression",S0211:"The symbol {{token}} cannot be used as a unary operator",S0212:"The left side of := must be a variable name (start with $)",S0213:"The literal value {{value}} cannot be used as a step within a path expression",S0214:"The right side of {{token}} must be a variable name (start with $)",S0215:"A context variable binding must precede any predicates on a step",S0216:"A context variable binding must precede the 'order-by' clause on a step",S0217:"The object representing the 'parent' cannot be derived from this expression",S0301:"Empty regular expressions are not allowed",S0302:"No terminating / in regular expression",S0402:"Choice groups containing parameterized types are not supported",S0401:"Type parameters can only be applied to functions and arrays",S0500:"Attempted to evaluate an expression containing syntax error(s)",T0410:"Argument {{index}} of function {{token}} does not match function signature",T0411:"Context value is not a compatible type with argument {{index}} of function {{token}}",T0412:"Argument {{index}} of function {{token}} must be an array of {{type}}",D1001:"Number out of range: {{value}}",D1002:"Cannot negate a non-numeric value: {{value}}",T1003:"Key in object structure must evaluate to a string; got: {{value}}",D1004:"Regular expression matches zero length string",T1005:"Attempted to invoke a non-function. Did you mean ${{{token}}}?",T1006:"Attempted to invoke a non-function",T1007:"Attempted to partially apply a non-function. Did you mean ${{{token}}}?",T1008:"Attempted to partially apply a non-function",D1009:"Multiple key definitions evaluate to same key: {{value}}",D1010:"Attempted to access the Javascript object prototype",T1010:"The matcher function argument passed to function {{token}} does not return the correct object structure",T2001:"The left side of the {{token}} operator must evaluate to a number",T2002:"The right side of the {{token}} operator must evaluate to a number",T2003:"The left side of the range operator (..) must evaluate to an integer",T2004:"The right side of the range operator (..) must evaluate to an integer",D2005:"The left side of := must be a variable name (start with $)",T2006:"The right side of the function application operator ~> must be a function",T2007:"Type mismatch when comparing values {{value}} and {{value2}} in order-by clause",T2008:"The expressions within an order-by clause must evaluate to numeric or string values",T2009:"The values {{value}} and {{value2}} either side of operator {{token}} must be of the same data type",T2010:"The expressions either side of operator {{token}} must evaluate to numeric or string values",T2011:"The insert/update clause of the transform expression must evaluate to an object: {{value}}",T2012:"The delete clause of the transform expression must evaluate to a string or array of strings: {{value}}",T2013:"The transform expression clones the input object using the $clone() function. This has been overridden in the current scope by a non-function.",D2014:"The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate {{value}}.",D3001:"Attempting to invoke string function on Infinity or NaN",D3010:"Second argument of replace function cannot be an empty string",D3011:"Fourth argument of replace function must evaluate to a positive number",D3012:"Attempted to replace a matched string with a non-string value",D3020:"Third argument of split function must evaluate to a positive number",D3030:"Unable to cast value to a number: {{value}}",D3040:"Third argument of match function must evaluate to a positive number",D3050:"The second argument of reduce function must be a function with at least two arguments",D3060:"The sqrt function cannot be applied to a negative number: {{value}}",D3061:"The power function has resulted in a value that cannot be represented as a JSON number: base={{value}}, exponent={{exp}}",D3070:"The single argument form of the sort function can only be applied to an array of strings or an array of numbers. Use the second argument to specify a comparison function",D3080:"The picture string must only contain a maximum of two sub-pictures",D3081:"The sub-picture must not contain more than one instance of the 'decimal-separator' character",D3082:"The sub-picture must not contain more than one instance of the 'percent' character",D3083:"The sub-picture must not contain more than one instance of the 'per-mille' character",D3084:"The sub-picture must not contain both a 'percent' and a 'per-mille' character",D3085:"The mantissa part of a sub-picture must contain at least one character that is either an 'optional digit character' or a member of the 'decimal digit family'",D3086:"The sub-picture must not contain a passive character that is preceded by an active character and that is followed by another active character",D3087:"The sub-picture must not contain a 'grouping-separator' character that appears adjacent to a 'decimal-separator' character",D3088:"The sub-picture must not contain a 'grouping-separator' at the end of the integer part",D3089:"The sub-picture must not contain two adjacent instances of the 'grouping-separator' character",D3090:"The integer part of the sub-picture must not contain a member of the 'decimal digit family' that is followed by an instance of the 'optional digit character'",D3091:"The fractional part of the sub-picture must not contain an instance of the 'optional digit character' that is followed by a member of the 'decimal digit family'",D3092:"A sub-picture that contains a 'percent' or 'per-mille' character must not contain a character treated as an 'exponent-separator'",D3093:"The exponent part of the sub-picture must comprise only of one or more characters that are members of the 'decimal digit family'",D3100:"The radix of the formatBase function must be between 2 and 36. It was given {{value}}",D3110:"The argument of the toMillis function must be an ISO 8601 formatted timestamp. Given {{value}}",D3120:"Syntax error in expression passed to function eval: {{value}}",D3121:"Dynamic error evaluating the expression passed to function eval: {{value}}",D3130:"Formatting or parsing an integer as a sequence starting with {{value}} is not supported by this implementation",D3131:"In a decimal digit pattern, all digits must be from the same decimal group",D3132:"Unknown component specifier {{value}} in date/time picture string",D3133:"The 'name' modifier can only be applied to months and days in the date/time picture string, not {{value}}",D3134:"The timezone integer format specifier cannot have more than four digits",D3135:"No matching closing bracket ']' in date/time picture string",D3136:"The date/time picture string is missing specifiers required to parse the timestamp",D3137:"{{{message}}}",D3138:"The $single() function expected exactly 1 matching result. Instead it matched more.",D3139:"The $single() function expected exactly 1 matching result. Instead it matched 0.",D3140:"Malformed URL passed to ${{{functionName}}}(): {{value}}",D3141:"{{{message}}}"};function Xe(n){var i=it[n.code];if(typeof i<"u"){var o=i.replace(/\{\{\{([^}]+)}}}/g,function(){return n[arguments[1]]});o=o.replace(/\{\{([^}]+)}}/g,function(){return JSON.stringify(n[arguments[1]])}),n.message=o;}}function ge(n,i){var o,e;try{o=K(n,i&&i.recover),e=o.errors,delete o.errors;}catch(f){throw Xe(f),f}var t=Ge(g),r=new Date;return t.bind("now",j(function(f,s){return B.fromMillis(r.getTime(),f,s)},"<s?s?:s>")),t.bind("millis",j(function(){return r.getTime()},"<:n>")),i&&i.RegexEngine?ge.RegexEngine=i.RegexEngine:ge.RegexEngine=RegExp,{evaluate:async function(f,s,h){if(typeof e<"u"){var T={code:"S0500",position:0};throw Xe(T),T}if(typeof s<"u"){var I;I=Ge(t);for(var W in s)I.bind(W,s[W]);}else I=t;I.bind("$",f),r=new Date,I.timestamp=r,Array.isArray(f)&&!V(f)&&(f=D(f),f.outerWrapper=true);var ve;try{return ve=await R(o,f,I),typeof h=="function"&&h(null,ve),ve}catch(ae){throw Xe(ae),ae}},assign:function(f,s){t.bind(f,s);},registerFunction:function(f,s,h){var T=j(s,h);t.bind(f,T);},ast:function(){return o},errors:function(){return e}}}return ge.parser=K,ge})();P.exports=pe;},{"./datetime":1,"./functions":2,"./parser":4,"./signature":5,"./utils":6}],4:[function(S,P,A){var B=S("./signature");let d=(()=>{var U={".":75,"[":80,"]":0,"{":70,"}":0,"(":80,")":0,",":0,"@":80,"#":80,";":80,":":80,"?":20,"+":50,"-":50,"*":60,"/":60,"%":60,"|":20,"=":40,"<":40,">":40,"^":40,"**":60,"..":20,":=":10,"!=":40,"<=":40,">=":40,"~>":40,"?:":40,"??":40,and:30,or:25,in:40,"&":50,"!":0,"~":0},K={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
- `,r:"\r",t:" "},X=function(F){var w=0,k=F.length,D=function(be,q){var x={type:be,value:q,position:w};return x},V=function(){for(var be=w,q=0,x,Z,_=function(R){if(F.charAt(R)==="/"&&q===0){for(var N=0;F.charAt(R-(N+1))==="\\";)N++;if(N%2===0)return true}return false};w<k;){var g=F.charAt(w);if(_(w)){if(x=F.substring(be,w),x==="")throw {code:"S0301",stack:new Error().stack,position:w};for(w++,g=F.charAt(w),be=w;g==="i"||g==="m";)w++,g=F.charAt(w);return Z=F.substring(be,w)+"g",new RegExp(x,Z)}(g==="("||g==="["||g==="{")&&F.charAt(w-1)!=="\\"&&q++,(g===")"||g==="]"||g==="}")&&F.charAt(w-1)!=="\\"&&q--,w++;}throw {code:"S0302",stack:new Error().stack,position:w}},me=function(be){if(w>=k)return null;for(var q=F.charAt(w);w<k&&`
3
- \r\v`.indexOf(q)>-1;)w++,q=F.charAt(w);if(q==="/"&&F.charAt(w+1)==="*"){var x=w;for(w+=2,q=F.charAt(w);!(q==="*"&&F.charAt(w+1)==="/");)if(q=F.charAt(++w),w>=k)throw {code:"S0106",stack:new Error().stack,position:x};return w+=2,q=F.charAt(w),me(be)}if(be!==true&&q==="/")return w++,D("regex",V());if(q==="."&&F.charAt(w+1)===".")return w+=2,D("operator","..");if(q===":"&&F.charAt(w+1)==="=")return w+=2,D("operator",":=");if(q==="!"&&F.charAt(w+1)==="=")return w+=2,D("operator","!=");if(q===">"&&F.charAt(w+1)==="=")return w+=2,D("operator",">=");if(q==="<"&&F.charAt(w+1)==="=")return w+=2,D("operator","<=");if(q==="*"&&F.charAt(w+1)==="*")return w+=2,D("operator","**");if(q==="~"&&F.charAt(w+1)===">")return w+=2,D("operator","~>");if(q==="?"&&F.charAt(w+1)===":")return w+=2,D("operator","?:");if(q==="?"&&F.charAt(w+1)==="?")return w+=2,D("operator","??");if(Object.prototype.hasOwnProperty.call(U,q))return w++,D("operator",q);if(q==='"'||q==="'"){var Z=q;w++;for(var _="";w<k;){if(q=F.charAt(w),q==="\\")if(w++,q=F.charAt(w),Object.prototype.hasOwnProperty.call(K,q))_+=K[q];else if(q==="u"){var g=F.substr(w+1,4);if(/^[0-9a-fA-F]+$/.test(g)){var R=parseInt(g,16);_+=String.fromCharCode(R),w+=4;}else throw {code:"S0104",stack:new Error().stack,position:w}}else throw {code:"S0103",stack:new Error().stack,position:w,token:q};else {if(q===Z)return w++,D("string",_);_+=q;}w++;}throw {code:"S0101",stack:new Error().stack,position:w}}var N=/^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?/,ne=N.exec(F.substring(w));if(ne!==null){var fe=parseFloat(ne[0]);if(!isNaN(fe)&&isFinite(fe))return w+=ne[0].length,D("number",fe);throw {code:"S0102",stack:new Error().stack,position:w,token:ne[0]}}var de;if(q==="`"){w++;var he=F.indexOf("`",w);if(he!==-1)return de=F.substring(w,he),w=he+1,D("name",de);throw w=k,{code:"S0105",stack:new Error().stack,position:w}}for(var oe=w,Ae;;)if(Ae=F.charAt(oe),oe===k||`
4
- \r\v`.indexOf(Ae)>-1||Object.prototype.hasOwnProperty.call(U,Ae)){if(F.charAt(w)==="$")return de=F.substring(w+1,oe),w=oe,D("variable",de);switch(de=F.substring(w,oe),w=oe,de){case "or":case "in":case "and":return D("operator",de);case "true":return D("value",true);case "false":return D("value",false);case "null":return D("value",null);default:return w===k&&de===""?null:D("name",de)}}else oe++;};return me},pe=function(F,w){var k,D,V={},me=[],be=function(){var a=[];k.id!=="(end)"&&a.push({type:k.type,value:k.value,position:k.position});for(var u=D();u!==null;)a.push(u),u=D();return a},q={nud:function(){var a={code:"S0211",token:this.value,position:this.position};if(w)return a.remaining=be(),a.type="error",me.push(a),a;throw a.stack=new Error().stack,a}},x=function(a,u){var $=V[a];return u=u||0,$?u>=$.lbp&&($.lbp=u):($=Object.create(q),$.id=$.value=a,$.lbp=u,V[a]=$),$},Z=function(a){if(w){a.remaining=be(),me.push(a);var u=V["(error)"];return k=Object.create(u),k.error=a,k.type="(error)",k}else throw a.stack=new Error().stack,a},_=function(a,u){if(a&&k.id!==a){var $;k.id==="(end)"?$="S0203":$="S0202";var te={code:$,position:k.position,token:k.value,value:a};return Z(te)}var we=D(u);if(we===null)return k=V["(end)"],k.position=F.length,k;var le=we.value,l=we.type,v;switch(l){case "name":case "variable":v=V["(name)"];break;case "operator":if(v=V[le],!v)return Z({code:"S0204",stack:new Error().stack,position:we.position,token:le});break;case "string":case "number":case "value":v=V["(literal)"];break;case "regex":l="regex",v=V["(regex)"];break;default:return Z({code:"S0205",stack:new Error().stack,position:we.position,token:le})}return k=Object.create(v),k.value=le,k.type=l,k.position=we.position,k},g=function(a){var u,$=k;for(_(null,true),u=$.nud();a<k.lbp;)$=k,_(),u=$.led(u);return u},R=function(a){var u=x(a,0);u.nud=function(){return this};},N=function(a,u,$){var te=u||U[a],we=x(a,te);return we.led=$||function(le){return this.lhs=le,this.rhs=g(te),this.type="binary",this},we},ne=function(a,u,$){var te=x(a,u);return te.led=$,te},fe=function(a,u){var $=x(a);return $.nud=u||function(){return this.expression=g(70),this.type="unary",this},$};R("(end)"),R("(name)"),R("(literal)"),R("(regex)"),x(":"),x(";"),x(","),x(")"),x("]"),x("}"),x(".."),N("."),N("+"),N("-"),N("*"),N("/"),N("%"),N("="),N("<"),N(">"),N("!="),N("<="),N(">="),N("&"),N("and"),N("or"),N("in"),R("and"),R("or"),R("in"),fe("-"),N("~>"),N("??",U["??"],function(a){return this.type="condition",this.condition={type:"function",value:"(",procedure:{type:"variable",value:"exists"},arguments:[a]},this.then=a,this.else=g(0),this}),ne("(error)",10,function(a){return this.lhs=a,this.error=k.error,this.remaining=be(),this.type="error",this}),fe("*",function(){return this.type="wildcard",this}),fe("**",function(){return this.type="descendant",this}),fe("%",function(){return this.type="parent",this}),N("(",U["("],function(a){if(this.procedure=a,this.type="function",this.arguments=[],k.id!==")")for(;k.type==="operator"&&k.id==="?"?(this.type="partial",this.arguments.push(k),_("?")):this.arguments.push(g(0)),k.id===",";)_(",");if(_(")",true),a.type==="name"&&(a.value==="function"||a.value==="\u03BB")){if(this.arguments.forEach(function(le,l){if(le.type!=="variable")return Z({code:"S0208",stack:new Error().stack,position:le.position,token:le.value,value:l+1})}),this.type="lambda",k.id==="<"){for(var u=k.position,$=1,te="<";$>0&&k.id!=="{"&&k.id!=="(end)";){var we=_();we.id===">"?$--:we.id==="<"&&$++,te+=we.value;}_(">");try{this.signature=B(te);}catch(le){return le.position=u+le.offset,Z(le)}}_("{"),this.body=g(0),_("}");}return this}),fe("(",function(){for(var a=[];k.id!==")"&&(a.push(g(0)),k.id===";");)_(";");return _(")",true),this.type="block",this.expressions=a,this}),fe("[",function(){var a=[];if(k.id!=="]")for(;;){var u=g(0);if(k.id===".."){var $={type:"binary",value:"..",position:k.position,lhs:u};_(".."),$.rhs=g(0),u=$;}if(a.push(u),k.id!==",")break;_(",");}return _("]",true),this.expressions=a,this.type="unary",this}),N("[",U["["],function(a){if(k.id==="]"){for(var u=a;u&&u.type==="binary"&&u.value==="[";)u=u.lhs;return u.keepArray=true,_("]"),a}else return this.lhs=a,this.rhs=g(U["]"]),this.type="binary",_("]",true),this}),N("^",U["^"],function(a){_("(");for(var u=[];;){var $={descending:false};if(k.id==="<"?_("<"):k.id===">"&&($.descending=true,_(">")),$.expression=g(0),u.push($),k.id!==",")break;_(",");}return _(")"),this.lhs=a,this.rhs=u,this.type="binary",this});var de=function(a){var u=[];if(k.id!=="}")for(;;){var $=g(0);_(":");var te=g(0);if(u.push([$,te]),k.id!==",")break;_(",");}return _("}",true),typeof a>"u"?(this.lhs=u,this.type="unary"):(this.lhs=a,this.rhs=u,this.type="binary"),this};fe("{",de),N("{",U["{"],de),ne(":=",U[":="],function(a){return a.type!=="variable"?Z({code:"S0212",stack:new Error().stack,position:a.position,token:a.value}):(this.lhs=a,this.rhs=g(U[":="]-1),this.type="binary",this)}),N("@",U["@"],function(a){return this.lhs=a,this.rhs=g(U["@"]),this.rhs.type!=="variable"?Z({code:"S0214",stack:new Error().stack,position:this.rhs.position,token:"@"}):(this.type="binary",this)}),N("#",U["#"],function(a){return this.lhs=a,this.rhs=g(U["#"]),this.rhs.type!=="variable"?Z({code:"S0214",stack:new Error().stack,position:this.rhs.position,token:"#"}):(this.type="binary",this)}),N("?",U["?"],function(a){return this.type="condition",this.condition=a,this.then=g(0),k.id===":"&&(_(":"),this.else=g(0)),this}),N("?:",U["?:"],function(a){return this.type="condition",this.condition=a,this.then=a,this.else=g(0),this}),fe("|",function(){return this.type="transform",this.pattern=g(0),_("|"),this.update=g(0),k.id===","&&(_(","),this.delete=g(0)),_("|"),this});var he=function(a){var u;if(a.type==="function"&&!a.predicate){var $={type:"lambda",thunk:true,arguments:[],position:a.position};$.body=a,u=$;}else if(a.type==="condition")a.then=he(a.then),typeof a.else<"u"&&(a.else=he(a.else)),u=a;else if(a.type==="block"){var te=a.expressions.length;te>0&&(a.expressions[te-1]=he(a.expressions[te-1])),u=a;}else u=a;return u},oe=0,Ae=0,He=[],ce=function(a,u){switch(a.type){case "name":case "wildcard":u.level--,u.level===0&&(typeof a.ancestor>"u"||(He[u.index].slot.label=a.ancestor.label),a.ancestor=u,a.tuple=true);break;case "parent":u.level++;break;case "block":a.expressions.length>0&&(a.tuple=true,u=ce(a.expressions[a.expressions.length-1],u));break;case "path":a.tuple=true;var $=a.steps.length-1;for(u=ce(a.steps[$--],u);u.level>0&&$>=0;)u=ce(a.steps[$--],u);break;default:throw {code:"S0217",token:a.type,position:a.position}}return u},ee=function(a,u){if(typeof u.seekingParent<"u"||u.type==="parent"){var $=typeof u.seekingParent<"u"?u.seekingParent:[];u.type==="parent"&&$.push(u.slot),typeof a.seekingParent>"u"?a.seekingParent=$:Array.prototype.push.apply(a.seekingParent,$);}},Le=function(a){var u=a.steps.length-1,$=a.steps[u],te=typeof $.seekingParent<"u"?$.seekingParent:[];$.type==="parent"&&te.push($.slot);for(var we=0;we<te.length;we++){var le=te[we];for(u=a.steps.length-2;le.level>0;){if(u<0){typeof a.seekingParent>"u"?a.seekingParent=[le]:a.seekingParent.push(le);break}for(var l=a.steps[u--];u>=0&&l.focus&&a.steps[u].focus;)l=a.steps[u--];le=ce(l,le);}}},G=function(a){var u;switch(a.type){case "binary":switch(a.value){case ".":var $=G(a.lhs);$.type==="path"?u=$:u={type:"path",steps:[$]},$.type==="parent"&&(u.seekingParent=[$.slot]);var te=G(a.rhs);te.type==="function"&&te.procedure.type==="path"&&te.procedure.steps.length===1&&te.procedure.steps[0].type==="name"&&u.steps[u.steps.length-1].type==="function"&&(u.steps[u.steps.length-1].nextFunction=te.procedure.steps[0].value),te.type==="path"?Array.prototype.push.apply(u.steps,te.steps):(typeof te.predicate<"u"&&(te.stages=te.predicate,delete te.predicate),u.steps.push(te)),u.steps.filter(function(O){if(O.type==="number"||O.type==="value")throw {code:"S0213",stack:new Error().stack,position:O.position,value:O.value};return O.type==="string"}).forEach(function(O){O.type="name";}),u.steps.filter(function(O){return O.keepArray===true}).length>0&&(u.keepSingletonArray=true);var we=u.steps[0];we.type==="unary"&&we.value==="["&&(we.consarray=true);var le=u.steps[u.steps.length-1];le.type==="unary"&&le.value==="["&&(le.consarray=true),Le(u);break;case "[":u=G(a.lhs);var l=u,v="predicate";if(u.type==="path"&&(l=u.steps[u.steps.length-1],v="stages"),typeof l.group<"u")throw {code:"S0209",stack:new Error().stack,position:a.position};typeof l[v]>"u"&&(l[v]=[]);var p=G(a.rhs);typeof p.seekingParent<"u"&&(p.seekingParent.forEach(O=>{O.level===1?ce(l,O):O.level--;}),ee(l,p)),l[v].push({type:"filter",expr:p,position:a.position});break;case "{":if(u=G(a.lhs),typeof u.group<"u")throw {code:"S0210",stack:new Error().stack,position:a.position};u.group={lhs:a.rhs.map(function(O){return [G(O[0]),G(O[1])]}),position:a.position};break;case "^":u=G(a.lhs),u.type!=="path"&&(u={type:"path",steps:[u]});var E={type:"sort",position:a.position};E.terms=a.rhs.map(function(O){var z=G(O.expression);return ee(E,z),{descending:O.descending,expression:z}}),u.steps.push(E),Le(u);break;case ":=":u={type:"bind",value:a.value,position:a.position},u.lhs=G(a.lhs),u.rhs=G(a.rhs),ee(u,u.rhs);break;case "@":if(u=G(a.lhs),l=u,u.type==="path"&&(l=u.steps[u.steps.length-1]),typeof l.stages<"u"||typeof l.predicate<"u")throw {code:"S0215",stack:new Error().stack,position:a.position};if(l.type==="sort")throw {code:"S0216",stack:new Error().stack,position:a.position};a.keepArray&&(l.keepArray=true),l.focus=a.rhs.value,l.tuple=true;break;case "#":u=G(a.lhs),l=u,u.type==="path"?l=u.steps[u.steps.length-1]:(u={type:"path",steps:[u]},typeof l.predicate<"u"&&(l.stages=l.predicate,delete l.predicate)),typeof l.stages>"u"?l.index=a.rhs.value:l.stages.push({type:"index",value:a.rhs.value,position:a.position}),l.tuple=true;break;case "~>":u={type:"apply",value:a.value,position:a.position},u.lhs=G(a.lhs),u.rhs=G(a.rhs),u.keepArray=u.lhs.keepArray||u.rhs.keepArray;break;default:u={type:a.type,value:a.value,position:a.position},u.lhs=G(a.lhs),u.rhs=G(a.rhs),ee(u,u.lhs),ee(u,u.rhs);}break;case "unary":u={type:a.type,value:a.value,position:a.position},a.value==="["?u.expressions=a.expressions.map(function(O){var z=G(O);return ee(u,z),z}):a.value==="{"?u.lhs=a.lhs.map(function(O){var z=G(O[0]);ee(u,z);var ie=G(O[1]);return ee(u,ie),[z,ie]}):(u.expression=G(a.expression),a.value==="-"&&u.expression.type==="number"?(u=u.expression,u.value=-u.value):ee(u,u.expression));break;case "function":case "partial":u={type:a.type,name:a.name,value:a.value,position:a.position},u.arguments=a.arguments.map(function(O){var z=G(O);return ee(u,z),z}),u.procedure=G(a.procedure);break;case "lambda":u={type:a.type,arguments:a.arguments,signature:a.signature,position:a.position};var M=G(a.body);u.body=he(M);break;case "condition":u={type:a.type,position:a.position},u.condition=G(a.condition),ee(u,u.condition),u.then=G(a.then),ee(u,u.then),typeof a.else<"u"&&(u.else=G(a.else),ee(u,u.else));break;case "transform":u={type:a.type,position:a.position},u.pattern=G(a.pattern),u.update=G(a.update),typeof a.delete<"u"&&(u.delete=G(a.delete));break;case "block":u={type:a.type,position:a.position},u.expressions=a.expressions.map(function(O){var z=G(O);return ee(u,z),(z.consarray||z.type==="path"&&z.steps[0].consarray)&&(u.consarray=true),z});break;case "name":u={type:"path",steps:[a]},a.keepArray&&(u.keepSingletonArray=true);break;case "parent":u={type:"parent",slot:{label:"!"+oe++,level:1,index:Ae++}},He.push(u);break;case "string":case "number":case "value":case "wildcard":case "descendant":case "variable":case "regex":u=a;break;case "operator":if(a.value==="and"||a.value==="or"||a.value==="in")a.type="name",u=G(a);else if(a.value==="?")u=a;else throw {code:"S0201",stack:new Error().stack,position:a.position,token:a.value};break;case "error":u=a,a.lhs&&(u=G(a.lhs));break;default:var C="S0206";a.id==="(end)"&&(C="S0207");var b={code:C,position:a.position,token:a.value};if(w)return me.push(b),{type:"error",error:b};throw b.stack=new Error().stack,b}return a.keepArray&&(u.keepArray=true),u};D=X(F),_();var xe=g(0);if(k.id!=="(end)"){var Be={code:"S0201",position:k.position,token:k.value};Z(Be);}if(xe=G(xe),xe.type==="parent"||typeof xe.seekingParent<"u")throw {code:"S0217",token:xe.type,position:xe.position};return me.length>0&&(xe.errors=me),xe};return pe})();P.exports=d;},{"./signature":5}],5:[function(S,P,A){var B=S("./utils");let d=(()=>{var U={a:"arrays",b:"booleans",f:"functions",n:"numbers",o:"objects",s:"strings"};function K(X){for(var pe=1,F=[],w={},k=w;pe<X.length;){var D=X.charAt(pe);if(D===":")break;var V=function(){F.push(w),k=w,w={};},me=function(N,ne,fe,de){for(var he=1,oe=ne;oe<N.length;)if(oe++,D=N.charAt(oe),D===de){if(he--,he===0)break}else D===fe&&he++;return oe};switch(D){case "s":case "n":case "b":case "l":case "o":w.regex="["+D+"m]",w.type=D,V();break;case "a":w.regex="[asnblfom]",w.type=D,w.array=true,V();break;case "f":w.regex="f",w.type=D,V();break;case "j":w.regex="[asnblom]",w.type=D,V();break;case "x":w.regex="[asnblfom]",w.type=D,V();break;case "-":k.context=true,k.contextRegex=new RegExp(k.regex),k.regex+="?";break;case "?":case "+":k.regex+=D;break;case "(":var be=me(X,pe,"(",")"),q=X.substring(pe+1,be);if(q.indexOf("<")===-1)w.regex="["+q+"m]";else throw {code:"S0402",stack:new Error().stack,value:q,offset:pe};w.type="("+q+")",pe=be,V();break;case "<":if(k.type==="a"||k.type==="f"){var x=me(X,pe,"<",">");k.subtype=X.substring(pe+1,x),pe=x;}else throw {code:"S0401",stack:new Error().stack,value:k.type,offset:pe};break}pe++;}var Z="^"+F.map(function(N){return "("+N.regex+")"}).join("")+"$",_=new RegExp(Z),g=function(N){var ne;if(B.isFunction(N))ne="f";else {var fe=typeof N;switch(fe){case "string":ne="s";break;case "number":ne="n";break;case "boolean":ne="b";break;case "object":N===null?ne="l":Array.isArray(N)?ne="a":ne="o";break;default:ne="m";}}return ne},R=function(N,ne){for(var fe="^",de=0,he=0;he<F.length;he++){fe+=F[he].regex;var oe=ne.match(fe);if(oe===null)throw {code:"T0410",stack:new Error().stack,value:N[de],index:de+1};de=oe[0].length;}throw {code:"T0410",stack:new Error().stack,value:N[de],index:de+1}};return {definition:X,validate:function(N,ne){var fe="";N.forEach(function(Ae){fe+=g(Ae);});var de=_.exec(fe);if(de){var he=[],oe=0;return F.forEach(function(Ae,He){var ce=N[oe],ee=de[He+1];if(ee==="")if(Ae.context&&Ae.contextRegex){var Le=g(ne);if(Ae.contextRegex.test(Le))he.push(ne);else throw {code:"T0411",stack:new Error().stack,value:ne,index:oe+1}}else he.push(ce),oe++;else ee.split("").forEach(function(G){if(Ae.type==="a"){if(G==="m")ce=void 0;else {ce=N[oe];var xe=true;if(typeof Ae.subtype<"u"){if(G!=="a"&&ee!==Ae.subtype)xe=false;else if(G==="a"&&ce.length>0){var Be=g(ce[0]);if(Be!==Ae.subtype.charAt(0))xe=false;else {var a=ce.filter(function(u){return g(u)!==Be});xe=a.length===0;}}}if(!xe)throw {code:"T0412",stack:new Error().stack,value:ce,index:oe+1,type:U[Ae.subtype]};G!=="a"&&(ce=[ce]);}he.push(ce),oe++;}else he.push(ce),oe++;});}),he}R(N,fe);}}}return K})();P.exports=d;},{"./utils":6}],6:[function(S,P,A){let B=(()=>{function d(x){var Z=false;if(typeof x=="number"&&(Z=!isNaN(x),Z&&!isFinite(x)))throw {code:"D1001",value:x,stack:new Error().stack};return Z}function U(x){var Z=false;return Array.isArray(x)&&(Z=x.filter(function(_){return typeof _!="string"}).length===0),Z}function K(x){var Z=false;return Array.isArray(x)&&(Z=x.filter(function(_){return !d(_)}).length===0),Z}function X(){var x=[];return x.sequence=true,arguments.length===1&&x.push(arguments[0]),x}function pe(x){return x.sequence===true&&Array.isArray(x)}function F(x){return x&&(x._jsonata_function===true||x._jsonata_lambda===true)||typeof x=="function"}function w(x){var Z=typeof x.arity=="number"?x.arity:typeof x.implementation=="function"?x.implementation.length:typeof x.length=="number"?x.length:x.arguments.length;return Z}function k(x){return x&&x._jsonata_lambda===true}var D=(typeof Symbol=="function"?Symbol:{}).iterator||"@@iterator";function V(x){return typeof x=="object"&&x!==null&&D in x&&"next"in x&&typeof x.next=="function"}function me(x,Z){if(x===Z)return true;if(typeof x=="object"&&typeof Z=="object"&&x!==null&&Z!==null){if(Array.isArray(x)&&Array.isArray(Z)){if(x.length!==Z.length)return false;for(var _=0;_<x.length;_++)if(!me(x[_],Z[_]))return false;return true}var g=Object.getOwnPropertyNames(x),R=Object.getOwnPropertyNames(Z);if(g.length!==R.length)return false;for(g=g.sort(),R=R.sort(),_=0;_<g.length;_++)if(g[_]!==R[_])return false;for(_=0;_<g.length;_++){var N=g[_];if(!me(x[N],Z[N]))return false}return true}return false}function be(x){return typeof x=="object"&&x!==null&&"then"in x&&typeof x.then=="function"}function q(x){var Z=[];for(let _ of x)Z.push(_);return Z}return {isNumeric:d,isArrayOfStrings:U,isArrayOfNumbers:K,createSequence:X,isSequence:pe,isFunction:F,isLambda:k,isIterable:V,getFunctionArity:w,isDeepEqual:me,stringToArray:q,isPromise:be}})();P.exports=B;},{}]},{},[3])(3)});});function Et(m,c,y,S){let P=m.steps[y];if(!P)throw new Error(`Step "${y}" not found in flow configuration`);if(S.result==="failure"&&P.retry){let d=c.retryCounts[y]??0;if(d<P.retry.max_attempts)return {newState:{...c,retryCounts:{...c.retryCounts,[y]:d+1},updatedAt:Date.now()},nextStep:y,isTerminal:false,isCircuitBroken:false,shouldRetry:true}}let A=P.failure_transitions?.[S.result]??P.transitions[S.result];if(!A)throw new Error(`No transition defined for result "${S.result}" in step "${y}"`);let B=!!m.terminal_states[A];return {newState:{...c,currentStep:A,stepHistory:[...c.stepHistory,y],retryCounts:{...c.retryCounts,[y]:0},updatedAt:Date.now()},nextStep:A,isTerminal:B,isCircuitBroken:false,shouldRetry:false}}function Dt(m,c,y){let S=m.steps[y];if(!S?.circuit_breaker)return {broken:false,newState:{...c,iterationCounts:{...c.iterationCounts,[y]:(c.iterationCounts[y]??0)+1},updatedAt:Date.now()}};let P=c.iterationCounts[y]??0;return P>=S.circuit_breaker.max_iterations?{broken:true,redirectStep:S.circuit_breaker.on_open,newState:{...c,currentStep:S.circuit_breaker.on_open,updatedAt:Date.now()}}:{broken:false,newState:{...c,iterationCounts:{...c.iterationCounts,[y]:P+1},updatedAt:Date.now()}}}function xt(m,c,y){let S=m.steps[c];if(!S)throw new Error(`Step "${c}" not found`);if(S.expects_data){let P={};for(let A of S.expects_data)P[A]=y[A];return P}return {...y}}function Tt(m,c){if(m===false||m===void 0)return {};if(typeof m=="string")return {[m]:c[m]};if(Array.isArray(m)){let y={};for(let S of m)y[S]=c[S];return y}return {}}function Pt(m,c){let y=Date.now();return {runId:c,flowId:m.id??"unnamed",currentStep:m.settings.start_step,status:"running",stepHistory:[],iterationCounts:{},retryCounts:{},startedAt:y,updatedAt:y}}var ft=class{constructor(){qe(this,"runs",new Map);qe(this,"data",new Map);}async saveRunState(c,y){this.runs.set(c,{...y});}async loadRunState(c){let y=this.runs.get(c);return y?{...y}:null}async deleteRunState(c){this.runs.delete(c),this.data.delete(c);}async setData(c,y,S){this.data.has(c)||this.data.set(c,{});let P=this.data.get(c);P[y]=S;}async getData(c,y){return this.data.get(c)?.[y]}async getAllData(c){return {...this.data.get(c)??{}}}async clearData(c){this.data.delete(c);}async listRuns(){return Array.from(this.runs.keys())}clear(){this.runs.clear(),this.data.clear();}};function Kt(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,m=>{let c=Math.random()*16|0;return (m==="x"?c:c&3|8).toString(16)})}var kt=class{constructor(c,y,S={}){qe(this,"flow");qe(this,"handlers");qe(this,"store");qe(this,"components");qe(this,"options");qe(this,"listeners",new Map);qe(this,"aborted",false);this.flow=c,this.handlers=new Map(Object.entries(y)),this.store=S.store??new ft,this.components=S.components??{},this.options=S,S.signal&&S.signal.addEventListener("abort",()=>{this.aborted=true;}),this.validateFlow();}validateFlow(){let{settings:c,steps:y,terminal_states:S}=this.flow;if(!c?.start_step)throw new Error("Flow must have settings.start_step defined");if(!y||Object.keys(y).length===0)throw new Error("Flow must have at least one step defined");if(!S||Object.keys(S).length===0)throw new Error("Flow must have at least one terminal_state defined");if(!y[c.start_step]&&!S[c.start_step])throw new Error(`Start step "${c.start_step}" not found`);for(let[P,A]of Object.entries(y)){for(let[B,d]of Object.entries(A.transitions))if(!y[d]&&!S[d])throw new Error(`Step "${P}" transition "${B}" points to unknown step "${d}"`);if(A.failure_transitions){for(let[B,d]of Object.entries(A.failure_transitions))if(!y[d]&&!S[d])throw new Error(`Step "${P}" failure_transition "${B}" points to unknown step "${d}"`)}}}on(c,y){this.listeners.has(c)||this.listeners.set(c,new Set),this.listeners.get(c).add(y);}off(c,y){this.listeners.get(c)?.delete(y);}emit(c){let y=this.listeners.get(c.type);if(y)for(let S of y)try{S(c);}catch{}}sleep(c){return new Promise(y=>setTimeout(y,c))}async run(c){let y=Kt(),S=Pt(this.flow,y);if(await this.store.saveRunState(y,S),c)for(let[P,A]of Object.entries(c))await this.store.setData(y,P,A);this.emit({type:"flow:start",runId:y,timestamp:S.startedAt,data:{initialData:c??{}}});try{return await this.executeLoop(y,S)}catch(P){let A=P instanceof Error?P:new Error(String(P));return this.emit({type:"flow:error",runId:y,timestamp:Date.now(),data:{error:A.message}}),this.options.onError?.(A),S={...S,status:"failed",updatedAt:Date.now()},await this.store.saveRunState(y,S),{runId:y,status:"failed",data:await this.store.getAllData(y),finalStep:S.currentStep,stepHistory:S.stepHistory,durationMs:Date.now()-S.startedAt,error:A}}}async resume(c){let y=await this.store.loadRunState(c);if(!y)throw new Error(`No run found with ID: ${c}`);if(y.status==="completed"||y.status==="failed")throw new Error(`Cannot resume a ${y.status} run`);let S={...y,status:"running",pausedAt:void 0,updatedAt:Date.now()};return await this.store.saveRunState(c,S),this.emit({type:"flow:resumed",runId:c,timestamp:Date.now(),data:{currentStep:S.currentStep}}),this.executeLoop(c,S)}async pause(c){let y=await this.store.loadRunState(c);if(!y)throw new Error(`No run found with ID: ${c}`);let S={...y,status:"paused",pausedAt:Date.now(),updatedAt:Date.now()};await this.store.saveRunState(c,S),this.emit({type:"flow:paused",runId:c,timestamp:Date.now(),data:{currentStep:S.currentStep}});}async executeLoop(c,y){let S=this.flow.settings.max_total_steps??100,P=this.flow.settings.timeout_ms,A=y,B=0;for(;B<S;){if(this.aborted)return A={...A,status:"cancelled",updatedAt:Date.now()},await this.store.saveRunState(c,A),{runId:c,status:"cancelled",data:await this.store.getAllData(c),finalStep:A.currentStep,stepHistory:A.stepHistory,durationMs:Date.now()-A.startedAt};if(P&&Date.now()-A.startedAt>P)return A={...A,status:"completed",updatedAt:Date.now()},await this.store.saveRunState(c,A),{runId:c,status:"timeout",intent:"timeout",data:await this.store.getAllData(c),finalStep:A.currentStep,stepHistory:A.stepHistory,durationMs:Date.now()-A.startedAt};let d=A.currentStep,U=this.flow.terminal_states[d];if(U){A={...A,status:"completed",updatedAt:Date.now()},await this.store.saveRunState(c,A);let D=await this.store.getAllData(c),V={runId:c,status:"completed",intent:U.return_intent,data:Tt(U.return_artifacts,D),finalStep:d,stepHistory:A.stepHistory,durationMs:Date.now()-A.startedAt};return this.emit({type:"flow:complete",runId:c,timestamp:Date.now(),data:{...V}}),this.options.onComplete?.(V),V}let K=Dt(this.flow,A,d);if(K.broken){A=K.newState,await this.store.saveRunState(c,A),B++;continue}A=K.newState;let X=await this.store.getAllData(c),pe=xt(this.flow,d,X),F={runId:c,stepName:d,components:this.components,store:this.store,signal:this.options.signal,emit:(D,V)=>{this.emit({type:"step:complete",runId:c,timestamp:Date.now(),data:{event:D,payload:V}});}};this.emit({type:"step:start",runId:c,timestamp:Date.now(),data:{step:d,input:pe}});let w;try{let D=this.handlers.get(d);if(!D)throw new Error(`No handler registered for step "${d}"`);w=await D(pe,F);}catch(D){let V=D instanceof Error?D:new Error(String(D));this.emit({type:"step:error",runId:c,timestamp:Date.now(),data:{step:d,error:V.message}}),w={result:"failure",data:{error:V.message}};}if(w.data)for(let[D,V]of Object.entries(w.data))await this.store.setData(c,D,V);this.emit({type:"step:complete",runId:c,timestamp:Date.now(),data:{step:d,result:w.result}}),this.options.onStep?.(d,w);let k=Et(this.flow,A,d,w);if(A=k.newState,k.shouldRetry){await this.store.saveRunState(c,A);let D=this.flow.steps[d];if(D.retry?.delay_ms){let V=A.retryCounts[d]??0,me=D.retry.backoff_multiplier?D.retry.delay_ms*Math.pow(D.retry.backoff_multiplier,V-1):D.retry.delay_ms;await this.sleep(me);}B++;continue}await this.store.saveRunState(c,A),this.emit({type:"transition",runId:c,timestamp:Date.now(),data:{from:d,to:A.currentStep,result:w.result}}),this.options.onTransition?.(d,A.currentStep),B++;}return A={...A,status:"completed",updatedAt:Date.now()},await this.store.saveRunState(c,A),{runId:c,status:"max_iterations",intent:"max_iterations",data:await this.store.getAllData(c),finalStep:A.currentStep,stepHistory:A.stepHistory,durationMs:Date.now()-A.startedAt}}};function Ct(m,c,y){return new kt(m,c,y)}var Nt=Qt($t());function en(){if(typeof AbortController<"u")return new AbortController;let m=false,c=[];return {signal:{get aborted(){return m},addEventListener(S,P){S==="abort"&&typeof P=="function"&&c.push(P);}},abort(){if(!m){m=true;for(let S of c)S();}}}}function Ye(m){return globalThis.__hostCall(m)}var Ft=class{constructor(c){qe(this,"directory",c);}async saveRunState(c,y){Ye({op:"step.store.saveRunState",directory:this.directory,runId:c,state:y});}async loadRunState(c){return Ye({op:"step.store.loadRunState",directory:this.directory,runId:c})}async deleteRunState(c){Ye({op:"step.store.deleteRunState",directory:this.directory,runId:c});}async setData(c,y,S){Ye({op:"step.store.setData",directory:this.directory,runId:c,key:y,value:S});}async getData(c,y){return Ye({op:"step.store.getData",directory:this.directory,runId:c,key:y})}async getAllData(c){return Ye({op:"step.store.getAllData",directory:this.directory,runId:c})}async clearData(c){Ye({op:"step.store.clearData",directory:this.directory,runId:c});}async listRuns(){return Ye({op:"step.store.listRuns",directory:this.directory})}};function tn(m){return !!m&&typeof m=="object"&&typeof m.cli=="string"&&m.cli.trim().length>0}function nn(m){return !!m&&typeof m=="object"&&typeof m.inline=="string"&&m.inline.trim().length>0}function rn(m){let c=m.trim();if(!c)throw new Error("empty stdout");try{return JSON.parse(c)}catch{let y=c.split(/\r?\n/).filter(Boolean),S=y[y.length-1];return JSON.parse(S)}}function It(m,c){if(!m||typeof m!="object")throw new Error(`[step-machine-pycli] Step "${c}" returned a non-object result.`);let y=m,S=y.result??y.status;if(typeof S!="string"||S.trim().length===0)throw new Error(`[step-machine-pycli] Step "${c}" result must include a non-empty "result" (or "status") string.`);let P=y.data&&typeof y.data=="object"&&!Array.isArray(y.data)?{...y.data}:{},A=typeof y.error=="string"?y.error:void 0;return A&&!("error"in P)&&(P.error=A),{result:S,data:P}}function an(m,c){let y=m??{};if(!c||c.length===0)return y;let S={};for(let P of c)Object.prototype.hasOwnProperty.call(y,P)&&(S[P]=y[P]);return S}async function St(m,c,y,S){if(m==null)return {};if(!m||typeof m!="object"||Array.isArray(m))throw new Error(`[step-machine-pycli] Step "${y}" ${S} must be an object map of key -> JSONata expression.`);let P={};for(let[A,B]of Object.entries(m)){if(typeof B!="string"){P[A]=B;continue}if(B.trim().length===0)throw new Error(`[step-machine-pycli] Step "${y}" ${S}.${A} must be a non-empty string expression.`);if(S==="handler_vars"&&!B.startsWith("=")){P[A]=B;continue}let d=S==="handler_vars"&&B.startsWith("=")?B.slice(1):B;if(Object.prototype.hasOwnProperty.call(c,d)){P[A]=c[d];continue}try{let U=(0,Nt.default)(d);P[A]=await U.evaluate(c);}catch(U){let K=U instanceof Error?U.message:String(U);throw new Error(`[step-machine-pycli] Step "${y}" ${S}.${A} failed: ${K}`)}}return P}function on(m,c,y){if(typeof m!="string"||m.trim().length===0)throw new Error(`[step-machine-pycli] Step "${y}" handler.cli must be a non-empty command string.`);return m.replace(/%%([A-Za-z0-9_-]+)%%/g,(S,P)=>{if(!Object.prototype.hasOwnProperty.call(c,P))throw new Error(`[step-machine-pycli] Step "${y}" command placeholder ${S} has no matching input or input-transform value.`);let A=c[P];if(A==null)throw new Error(`[step-machine-pycli] Step "${y}" command placeholder ${S} resolved to empty value.`);return String(A)})}function Mt(m,c){return async(y,S)=>{let P=await m(y,S),A=It(P,S.stepName);return {result:A.result,data:an(A.data,c)}}}function sn(){return async m=>({result:"success",data:m&&typeof m=="object"&&!Array.isArray(m)?m:{}})}function un(m,c,y,S){return async P=>{let A=P&&typeof P=="object"&&!Array.isArray(P)?P:{},B=await St(S,A,y,"handler_vars"),d=await St(m["input-transforms"],{...A,...B},y,"input-transforms"),U={...A,...B,...d},K=on(m.cli,U,y),X=Ye({op:"step.runCli",command:K,cwd:c,payloadJson:JSON.stringify(U)});if(X.error)return {result:"failure",data:{error:`[step-machine-pycli] step "${y}" failed to start: ${X.error}`}};let pe=X.stdout??"",F=(X.stderr??"").trim(),w=String(m["result-mode"]??"json").toLowerCase();if(X.status!==0)return {result:"failure",data:{error:`[step-machine-pycli] step "${y}" exited with status ${X.status}${F?`: ${F}`:""}`}};if(w==="exit-code")return {result:"success",data:await St(m["output-transforms"],{...U,result:"success",stdout:pe,stderr:F},y,"output-transforms")};try{let k=rn(pe),D=It(k,y),V=await St(m["output-transforms"],{...U,result:D.result,data:D.data},y,"output-transforms");return Object.keys(V).length===0?D:{result:D.result,data:V}}catch(k){let D=k instanceof Error?k.message:String(k);return {result:"failure",data:{error:`[step-machine-pycli] step "${y}" returned invalid JSON on stdout: ${D}`}}}}}function fn(m){return async(c,y)=>Ye({op:"step.invokePythonInline",handlerName:m,stepName:y.stepName,runId:y.runId,input:c})}function cn(m,c,y,S){let P={};for(let[A,B]of Object.entries(m.steps??{})){let d=Array.isArray(B?.produces_data)?B.produces_data:void 0,U=B.handler;if(tn(U)){P[A]=Mt(un(U,c,A,S),d);continue}if(nn(U)){let K=U.inline;if(!y.has(K))throw new Error(`[step-machine-pycli] Inline Python handler "${K}" for step "${A}" was not found in --handlers module.`);P[A]=Mt(fn(K),d);continue}P[A]=Mt(sn(),d);}return P}function ln(m){return m.type==="memory"?new ft:new Ft(m.directory)}async function dn(m){let c=ln(m.store),y=new Set(m.inlineHandlerNames??[]),S=cn(m.flow,m.flowDir,y,m.handlerVars??{});m.pauseFilePath&&Ye({op:"step.pause.clear",pauseFilePath:m.pauseFilePath});let P=en(),A=false,B=Ct(m.flow,S,{store:c,signal:P.signal,onStep:()=>{if(!m.pauseFilePath||A)return;Ye({op:"step.pause.requested",pauseFilePath:m.pauseFilePath})&&(A=true,P.abort());}}),d=m.mode==="resume"?await B.resume(String(m.runId??"")):await B.run(m.initialData);if(A&&d.status==="cancelled"){let U=await c.loadRunState(d.runId);if(U){let X=Date.now();await c.saveRunState(d.runId,{...U,status:"paused",pausedAt:X,updatedAt:X});}m.pauseFilePath&&Ye({op:"step.pause.clear",pauseFilePath:m.pauseFilePath});let K=await c.loadRunState(d.runId);return {status:"paused",runId:d.runId,currentStep:K?.currentStep,pausedAt:K?.pausedAt,stepHistory:d.stepHistory,data:d.data}}if(d.status!=="completed"){let U=d.error?.message??d.intent??d.status;return {status:"failed",runId:d.runId,finalStep:d.finalStep,stepHistory:d.stepHistory,data:d.data,reason:U,error:U}}return {status:"completed",runId:d.runId,intent:d.intent,finalStep:d.finalStep,stepHistory:d.stepHistory,data:d.data}}globalThis.pycliStepMachineInvoke=dn;})();//# sourceMappingURL=quickjs-step-machine-runtime.global.js.map
5
- //# sourceMappingURL=quickjs-step-machine-runtime.global.js.map