@arcgis/core 4.25.0-next.20220828 → 4.25.0-next.20220829

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 (90) hide show
  1. package/arcade/arcadeAsyncRuntime.js +1 -1
  2. package/arcade/arcadeRuntime.js +1 -1
  3. package/arcade/featureset/actions/Adapted.js +1 -1
  4. package/arcade/featureset/actions/AttributeFilter.js +1 -1
  5. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  6. package/arcade/featureset/support/FeatureSet.js +1 -1
  7. package/arcade/featureset/support/sqlUtils.js +1 -1
  8. package/arcade/featureset/support/stats.js +1 -1
  9. package/arcade/functions/string.js +1 -1
  10. package/arcade/lib/nodes.js +1 -1
  11. package/arcade/treeAnalysis.js +1 -1
  12. package/assets/esri/core/workers/RemoteClient.js +1 -1
  13. package/assets/esri/core/workers/chunks/237217dc252423be80e7.js +1 -0
  14. package/assets/esri/core/workers/chunks/27c1c55a3b8113dc7389.js +1 -0
  15. package/assets/esri/core/workers/chunks/62e7a7bea9c5c36c1af1.js +1 -0
  16. package/assets/esri/core/workers/chunks/{295ecb800d3e4d63d02f.js → 6e9ce019d1b842a1cbc5.js} +1 -1
  17. package/assets/esri/core/workers/chunks/72fe52c83b9575e63de7.js +1 -0
  18. package/assets/esri/core/workers/chunks/93611b7eba525e6fed44.js +1 -0
  19. package/assets/esri/core/workers/chunks/{c912ae9afa1997a6e1bb.js → afb5958d0053f8e354e7.js} +1 -1
  20. package/assets/esri/core/workers/chunks/c62f8edbbf071b9ee483.js +1 -0
  21. package/chunks/languageUtils.js +1 -1
  22. package/chunks/mat4.js +1 -1
  23. package/core/libs/gl-matrix-2/math/mat4.js +1 -1
  24. package/core/sql/WhereClause.js +1 -1
  25. package/geohash/geohashUtils.js +1 -1
  26. package/geometry/support/coordsUtils.js +1 -1
  27. package/geometry/support/jsonUtils.js +1 -1
  28. package/layers/support/SpriteSource.js +1 -1
  29. package/layers/support/layerUtils.js +1 -1
  30. package/layers/support/rasterFunctions/bandIndexUtils.js +1 -1
  31. package/layers/support/rasterFunctions/pixelUtils.js +1 -1
  32. package/package.json +1 -1
  33. package/renderers/support/heatmapUtils.js +1 -1
  34. package/renderers/support/utils.js +1 -1
  35. package/rest/geometryService/densify.js +1 -1
  36. package/rest/geometryService/offset.js +1 -1
  37. package/support/arcadeUtils.js +1 -1
  38. package/support/revision.js +1 -1
  39. package/support/webSceneUtils.js +1 -1
  40. package/symbols/cim/SDFHelper.js +1 -1
  41. package/symbols/support/gfxUtils.js +1 -1
  42. package/symbols/support/styleUtils.js +1 -1
  43. package/views/2d/engine/vectorTiles/decluttering/util.js +1 -1
  44. package/views/2d/engine/webgl/collisions/CollisionGrid.js +1 -1
  45. package/views/2d/engine/webgl/mesh/templates/templateUtils.js +1 -1
  46. package/views/2d/layers/features/tileRenderers/support/visualVariablesUtils.js +1 -1
  47. package/views/2d/viewStateUtils.js +1 -1
  48. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  49. package/views/3d/environment/CloudsComposition.js +1 -1
  50. package/views/3d/environment/CloudsCompositionParameters.js +1 -1
  51. package/views/3d/environment/CloudsData.js +1 -1
  52. package/views/3d/environment/CloudsGenerator.js +1 -1
  53. package/views/3d/interactive/visualElements/support/Segment.js +1 -1
  54. package/views/3d/layers/graphics/constants.js +1 -1
  55. package/views/3d/layers/i3s/I3SUtil.js +1 -1
  56. package/views/3d/state/utils/navigationUtils.js +1 -1
  57. package/views/3d/support/earthUtils.js +1 -1
  58. package/views/3d/terrain/ElevationData.js +1 -1
  59. package/views/3d/terrain/PatchGeometry.js +1 -1
  60. package/views/3d/terrain/PatchGeometryFactory.js +1 -1
  61. package/views/3d/terrain/PatchRenderData.js +1 -1
  62. package/views/3d/terrain/TerrainConst.js +1 -1
  63. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  64. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  65. package/views/3d/webgl-engine/collections/Component/interface.js +0 -1
  66. package/views/3d/webgl-engine/lib/edgeRendering/util.js +1 -1
  67. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  68. package/views/webgl/rasterUtils.js +1 -1
  69. package/widgets/ElevationProfile/css.js +1 -1
  70. package/widgets/FeatureForm/InputField.js +1 -1
  71. package/widgets/FeatureForm/InputFieldGroup.js +1 -1
  72. package/widgets/FeatureTemplates/ItemList.js +1 -1
  73. package/widgets/support/decorators/vmEvent.js +1 -1
  74. package/assets/esri/core/workers/chunks/5c2574365af4a484cd4b.js +0 -1
  75. package/assets/esri/core/workers/chunks/82158f35049d7c9044d1.js +0 -1
  76. package/assets/esri/core/workers/chunks/92f10a6f8eae3ecf5ac2.js +0 -1
  77. package/assets/esri/core/workers/chunks/d929de69309c77fc5b19.js +0 -1
  78. package/assets/esri/core/workers/chunks/e7e88bb1828436899826.js +0 -1
  79. package/assets/esri/core/workers/chunks/ff729a122ddffd95a6b5.js +0 -1
  80. package/geometry/support/cut.js +0 -5
  81. package/views/2d/engine/webgl/effects/post-processing/DRA.js +0 -5
  82. package/views/2d/engine/webgl/effects/post-processing/EdgeDetect.js +0 -5
  83. package/views/2d/engine/webgl/effects/post-processing/EdgeEnhance.js +0 -5
  84. package/views/3d/webgl-engine/core/shaderLibrary/ShaderStageOptions.js +0 -5
  85. package/views/draw/support/createUtilsAsync.js +0 -5
  86. package/views/layers/support/Transition.js +0 -5
  87. package/views/webgl/tests/SimpleDraw.js +0 -5
  88. package/widgets/FeatureForm/support/formTemplateUtils.js +0 -5
  89. package/widgets/FeatureTable/Grid/support/LocalStore.js +0 -5
  90. package/widgets/support/decorators/propUtils.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"./ArcadePortal.js";import t from"./Attachment.js";import r from"./Dictionary.js";import n from"./Feature.js";import o from"./FunctionWrapper.js";import a from"./ImmutablePathArray.js";import i from"./ImmutablePointArray.js";import{p as s,i as c,m as l,N as u,x as f,v as p,w,o as h,b as d,l as m,n as g,s as E,y,a as N,f as v,I,R as T,h as S,q as b,r as R,j as O,z as A,A as U}from"../chunks/languageUtils.js";import{nodeErrorMessage as C,addFunctionDeclaration as F,findFieldLiterals as x,validateScript as M,referencesMember as P,referencesFunction as D,findFunctionCalls as j}from"./treeAnalysis.js";import{A as L}from"../chunks/array.js";import{registerFunctions as k}from"./functions/date.js";import{registerFunctions as _}from"./functions/geomasync.js";import{registerFunctions as V}from"./functions/geometry.js";import{registerFunctions as Y}from"./functions/maths.js";import{registerFunctions as B}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import z from"../geometry/Extent.js";import q from"../geometry/Geometry.js";import H from"../geometry/Multipoint.js";import Z from"../geometry/Point.js";import W from"../geometry/Polygon.js";import K from"../geometry/Polyline.js";import X from"../geometry/SpatialReference.js";function J(e){return e&&"function"==typeof e.then}const Q=100;async function $(e,t){const r=[];for(let n=0;n<t.arguments.length;n++)r.push(await re(e,t.arguments[n]));return r}async function ee(e,t,r){if(!0===t.preparsed)return r(e,null,t.arguments);return r(e,t,await $(e,t))}async function te(e,t,r){if(!0===t.preparsed){const n=r(e,null,t.arguments);return J(n),n}const n=r(e,t,await $(e,t));return J(n),n}async function re(e,t,r){if(t.breakpoint&&!0!==r){const r=t.breakpoint();return await r,re(e,t,!0)}switch(t.type){case"VariableDeclarator":return Re(e,t);case"VariableDeclaration":return be(e,t,0);case"BlockStatement":return ve(e,t);case"FunctionDeclaration":return Se(e,t);case"ReturnStatement":return Te(e,t);case"IfStatement":return Ne(e,t);case"ExpressionStatement":return ye(e,t);case"UpdateExpression":return me(e,t);case"AssignmentExpression":return Ee(e,t);case"ForStatement":return ce(e,t);case"ForInStatement":return de(e,t);case"BreakStatement":return w;case"EmptyStatement":return p;case"ContinueStatement":return f;case"TemplateElement":return je(e,t);case"TemplateLiteral":return Le(e,t);case"Identifier":return Pe(e,t);case"MemberExpression":return Ue(e,t);case"Literal":return t.value;case"CallExpression":return De(e,t);case"UnaryExpression":return Ce(e,t);case"BinaryExpression":return xe(e,t);case"LogicalExpression":return Me(e,t);case"ArrayExpression":return Fe(e,t);case"ObjectExpression":return ne(e,t);case"Property":return oe(e,t);default:throw new Error(C(t,"RUNTIME","UNREOGNISED"))}}async function ne(e,t){const n=[];for(let r=0;r<t.properties.length;r++)n[r]=await re(e,t.properties[r]);const o={};for(let r=0;r<n.length;r++){const e=n[r];if(h(e.value))throw new Error("Illegal Argument");if(!1===d(e.key))throw new Error("Illegal Argument");e.value===p?o[e.key.toString()]=null:o[e.key.toString()]=e.value}const a=new r(o);return a.immutable=!1,a}async function oe(e,t){const r=await re(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:r};return{key:await re(e,t.key),value:r}}async function ae(e,t,r){const n=await re(e,t.body);return r.lastAction=n,r.lastAction===w||r.lastAction instanceof T?(r.testResult=!1,r):null!==t.update?(await re(e,t.update),r):r}async function ie(e,t,r){if(null!==t.test){const n=await re(e,t.test);if(!0===e.abortSignal.aborted)throw new Error("Cancelled");if(r.testResult=n,!1===r.testResult)return r;if(!0!==r.testResult)throw new Error(C(t,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"));return ae(e,t,r)}return ae(e,t,r)}function se(e,t,r,n,o,a){try{ie(e,t,r).then((()=>{try{!0===r.testResult?++a>Q?(a=0,setTimeout((()=>{se(e,t,r,n,o,a)}),0)):se(e,t,r,n,o,a):r.lastAction instanceof T?n(r.lastAction):n(p)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ce(e,t){try{return null!==t.init?re(e,t.init).then((()=>new Promise(((r,n)=>{se(e,t,{testResult:!0,lastAction:p},(e=>{r(e)}),(e=>{n(e)}),0)})))):new Promise(((r,n)=>{se(e,t,{testResult:!0,lastAction:p},(e=>{r(e)}),(e=>{n(e)}),0)}))}catch(r){return Promise.reject(r)}}function le(e,t,r,n,o,a,i,s,c,l){try{if(n<=a)return void s(p);o.value="k"===i?r[a]:a,re(e,t.body).then((u=>{try{u instanceof T?s(u):u===w?s(p):++l>Q?(l=0,setTimeout((()=>{le(e,t,r,n,o,a+1,i,s,c,l)}),0)):le(e,t,r,n,o,a+1,i,s,c,l)}catch(f){c(f)}}),(e=>{c(e)}))}catch(u){c(u)}}function ue(e,t,r,n,o,a,i,s,c){try{if(r.length()<=o)return void i(p);n.value="k"===a?r.get(o):o,re(e,t.body).then((l=>{l instanceof T?i(l):l===w?i(p):++c>Q?(c=0,setTimeout((()=>{ue(e,t,r,n,o+1,a,i,s,c)}),0)):ue(e,t,r,n,o+1,a,i,s,c)}),(e=>{s(e)}))}catch(l){s(l)}}function fe(e,t,r,n,o,a){try{if(void 0===a&&(a="i"),0===r.length)return void n.resolve(p);le(e,t,r,r.length,o,0,a,(e=>{n.resolve(e)}),(e=>{n.reject(e)}),0)}catch(i){n.reject(i)}}function pe(e,t,r,n,o,a){try{if(void 0===a&&(a="i"),0===r.length)return void n.resolve(p);ue(e,t,r,o,0,a,(e=>{n.resolve(e)}),(e=>{n.reject(e)}),0)}catch(i){n.reject(i)}}function we(e,t,r,n,o){try{fe(e,t,r.keys(),n,o,"k")}catch(a){n.reject(a)}}function he(e,t,r,o,a,i,s,c){try{e.next().then((l=>{try{if(null===l)i(p);else{const u=n.createFromGraphicLikeObject(l.geometry,l.attributes,o);u._underlyingGraphic=l,a.value=u;re(t,r.body).then((n=>{try{n===w?i(p):n instanceof T?i(n):++c>Q?(c=0,setTimeout((()=>{he(e,t,r,o,a,i,s,c)}),0)):he(e,t,r,o,a,i,s,c)}catch(l){s(l)}}),(e=>{s(e)}))}}catch(u){s(u)}}),(e=>{s(e)}))}catch(l){s(l)}}async function de(e,t){return new Promise(((n,o)=>{re(e,t.right).then((a=>{try{let i=null;i="VariableDeclaration"===t.left.type?re(e,t.left):Promise.resolve(),i.then((()=>{try{let i="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(i=e.name)}else"Identifier"===t.left.type&&(i=t.left.name);if(!i)throw new Error(C(t,"RUNTIME","INVALIDVARIABLE"));i=i.toLowerCase();let s=null;if(null!==e.localScope&&void 0!==e.localScope[i]&&(s=e.localScope[i]),null===s&&void 0!==e.globalScope[i]&&(s=e.globalScope[i]),null===s)return void o(new Error(C(t,"RUNTIME","VARIABLENOTDECLARED")));m(a)||d(a)?fe(e,t,a,{reject:o,resolve:n},s):g(a)?pe(e,t,a,{reject:o,resolve:n},s):a instanceof r||E(a)?we(e,t,a,{reject:o,resolve:n},s):y(a)?he(a.iterator(e.abortSignal),e,t,a,s,(e=>{n(e)}),(e=>{o(e)}),0):fe(e,t,[],{reject:o,resolve:n},s)}catch(i){o(i)}}),o)}catch(i){o(i)}}),o)}))}async function me(e,t){const n=t.argument;if("MemberExpression"===n.type){const o={t:null},a=await re(e,n.object);let i=null;o.t=a,!0===n.computed?i=await re(e,n.property):"Identifier"===n.property.type&&(i=n.property.name);const s=o.t;let c;if(m(s)){if(!N(i))throw new Error("Invalid Parameter");if(i<0&&(i=s.length+i),i<0||i>=s.length)throw new Error("Assignment outside of array bounds");c=v(s[i]),s[i]="++"===t.operator?c+1:c-1}else if(s instanceof r){if(!1===d(i))throw new Error("Dictionary accessor must be a string");if(!0!==s.hasField(i))throw new Error("Invalid Parameter");c=v(s.field(i)),s.setField(i,"++"===t.operator?c+1:c-1)}else{if(!E(s))throw g(s)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===d(i))throw new Error("Feature accessor must be a string");if(!0!==s.hasField(i))throw new Error("Invalid Parameter");c=v(s.field(i)),s.setField(i,"++"===t.operator?c+1:c-1)}return!1===t.prefix?c:"++"===t.operator?c+1:c-1}const o="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!o)throw new Error("Invalid identifier");let a;if(null!==e.localScope&&void 0!==e.localScope[o])return a=v(e.localScope[o].value),e.localScope[o]={value:"++"===t.operator?a+1:a-1,valueset:!0,node:t},!1===t.prefix?a:"++"===t.operator?a+1:a-1;if(void 0!==e.globalScope[o])return a=v(e.globalScope[o].value),e.globalScope[o]={value:"++"===t.operator?a+1:a-1,valueset:!0,node:t},!1===t.prefix?a:"++"===t.operator?a+1:a-1;throw new Error("Variable not recognised")}function ge(e,t,r,n){switch(t){case"=":return e===p?null:e;case"/=":return v(r)/v(e);case"*=":return v(r)*v(e);case"-=":return v(r)-v(e);case"+=":return d(r)||d(e)?S(r)+S(e):v(r)+v(e);case"%=":return v(r)%v(e);default:throw new Error(C(n,"RUNTIME","OPERATORNOTRECOGNISED"))}}async function Ee(e,t){const n=t.left;if("MemberExpression"===n.type){const o=await re(e,t.right),a=await re(e,n.object);let i=null;if(!0===n.computed)i=await re(e,n.property);else{if("Identifier"!==n.property.type)throw new Error("Expected computed or identifier for assignemnt target");i=n.property.name}if(m(a)){if(!N(i))throw new Error("Invalid Parameter");if(i<0&&(i=a.length+i),i<0||i>a.length)throw new Error("Assignment outside of array bounds");if(i===a.length){if("="!==t.operator)throw new Error("Invalid Parameter");a[i]=ge(o,t.operator,a[i],t)}else a[i]=ge(o,t.operator,a[i],t)}else if(a instanceof r){if(!1===d(i))throw new Error("Dictionary accessor must be a string");if(!0===a.hasField(i))a.setField(i,ge(o,t.operator,a.field(i),t));else{if("="!==t.operator)throw new Error("Invalid Parameter");a.setField(i,ge(o,t.operator,null,t))}}else{if(!E(a))throw g(a)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===d(i))throw new Error("Feature accessor must be a string");if(!0===a.hasField(i))a.setField(i,ge(o,t.operator,a.field(i),t));else{if("="!==t.operator)throw new Error("Invalid Parameter");a.setField(i,ge(o,t.operator,null,t))}}return p}const o=n.name.toLowerCase();if(null!==e.localScope&&void 0!==e.localScope[o]){const r=await re(e,t.right);return e.localScope[o]={value:ge(r,t.operator,e.localScope[o].value,t),valueset:!0,node:t.right},p}if(void 0!==e.globalScope[o]){const r=await re(e,t.right);return e.globalScope[o]={value:ge(r,t.operator,e.globalScope[o].value,t),valueset:!0,node:t.right},p}throw new Error("Cannot assign undeclared variable")}async function ye(e,t){if("AssignmentExpression"===t.expression.type)return re(e,t.expression);if("CallExpression"===t.expression.type){const r=await re(e,t.expression);return r===p?p:new I(r)}const r=await re(e,t.expression);return r===p?p:new I(r)}async function Ne(e,t){if("AssignmentExpression"===t.test.type||"UpdateExpression"===t.test.type)throw new Error(C(t.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const r=await re(e,t.test);if(!0===r)return re(e,t.consequent);if(!1===r)return null!==t.alternate?re(e,t.alternate):p;throw new Error(C(t.test,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}async function ve(e,t){return Ie(e,t,0)}async function Ie(e,t,r){if(r>=t.body.length)return p;const n=await re(e,t.body[r]);return n instanceof T||n===w||n===f||r===t.body.length-1?n:Ie(e,t,r+1)}async function Te(e,t){if(null===t.argument)return new T(p);const r=await re(e,t.argument);return new T(r)}async function Se(e,t){const r=t.id.name.toLowerCase();return e.globalScope[r]={valueset:!0,node:null,value:new o(t,e)},p}async function be(e,t,r){return r>=t.declarations.length?p:(await re(e,t.declarations[r]),r===t.declarations.length-1||await be(e,t,r+1),p)}async function Re(e,t){let r=null;if(r=null===t.init?null:await re(e,t.init),null!==e.localScope){if(r===p&&(r=null),"Identifier"!==t.id.type)throw new Error("Can only assign a regular variable");const n=t.id.name.toLowerCase();return e.localScope[n]={value:r,valueset:!0,node:t.init},p}if("Identifier"!==t.id.type)throw new Error("Can only assign a regular variable");const n=t.id.name.toLowerCase();return r===p&&(r=null),e.globalScope[n]={value:r,valueset:!0,node:t.init},p}let Oe=0;function Ae(e,t,n,o){let s;switch(t=t.toLowerCase()){case"hasz":{const t=e.hasZ;return void 0!==t&&t}case"hasm":{const t=e.hasM;return void 0!==t&&t}case"spatialreference":{let t=e.spatialReference._arcadeCacheId;if(void 0===t){let r=!0;Object.freeze&&Object.isFrozen(e.spatialReference)&&(r=!1),r&&(Oe++,e.spatialReference._arcadeCacheId=Oe,t=Oe)}const n=new r({wkt:e.spatialReference.wkt,wkid:e.spatialReference.wkid});return void 0!==t&&(n._arcadeCacheId="SPREF"+t.toString()),n}}switch(e.type){case"extent":switch(t){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const r=e[t];return void 0!==r?r:null}case"type":return"Extent"}break;case"polygon":switch(t){case"rings":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new a(e.rings,e.spatialReference,!0===e.hasZ,!0===e.hasM,s);case"type":return"Polygon"}break;case"point":switch(t){case"x":case"y":case"z":case"m":return void 0!==e[t]?e[t]:null;case"type":return"Point"}break;case"polyline":switch(t){case"paths":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new a(e.paths,e.spatialReference,!0===e.hasZ,!0===e.hasM,s);case"type":return"Polyline"}break;case"multipoint":switch(t){case"points":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new i(e.points,e.spatialReference,!0===e.hasZ,!0===e.hasM,s,1);case"type":return"Multipoint"}}throw new Error(C(o,"RUNTIME","PROPERTYNOTFOUND"))}async function Ue(e,t){const n=await re(e,t.object);if(null===n)throw new Error(C(t,"RUNTIME","NOTFOUND"));if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof r||E(n))return n.field(t.property.name);if(n instanceof q)return Ae(n,t.property.name,e,t);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}let o=await re(e,t.property);if(n instanceof r||E(n)){if(d(o))return n.field(o);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(n instanceof q){if(d(o))return Ae(n,o,e,t);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(m(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(g(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length()+o),o>=n.length()||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n.get(o)}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(d(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}async function Ce(e,t){const r=await re(e,t.argument);if(c(r)){if("!"===t.operator)return!r;if("-"===t.operator)return-1*v(r);if("+"===t.operator)return 1*v(r);if("~"===t.operator)return~v(r);throw new Error(C(t,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}if("-"===t.operator)return-1*v(r);if("+"===t.operator)return 1*v(r);if("~"===t.operator)return~v(r);throw new Error(C(t,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}async function Fe(e,t){const r=[];for(let n=0;n<t.elements.length;n++)r.push(await re(e,t.elements[n]));for(let n=0;n<r.length;n++){if(h(r[n]))throw new Error(C(t,"RUNTIME","FUNCTIONCONTEXTILLEGAL"));r[n]===p&&(r[n]=null)}return r}async function xe(e,t){const r=[];r[0]=await re(e,t.left),r[1]=await re(e,t.right);const n=r[0],o=r[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return R(v(n),v(o),t.operator);case"==":return l(n,o);case"!=":return!l(n,o);case"<":case">":case"<=":case">=":return b(n,o,t.operator);case"+":return d(n)||d(o)?S(n)+S(o):v(n)+v(o);case"-":return v(n)-v(o);case"*":return v(n)*v(o);case"/":return v(n)/v(o);case"%":return v(n)%v(o);default:throw new Error(C(t,"RUNTIME","OPERATORNOTRECOGNISED"))}}async function Me(e,t){if("AssignmentExpression"===t.left.type||"UpdateExpression"===t.left.type)throw new Error(C(t.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));if("AssignmentExpression"===t.right.type||"UpdateExpression"===t.right.type)throw new Error(C(t.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const r=await re(e,t.left);let n=null;if(!c(r))throw new Error(C(t,"RUNTIME","ONLYBOOLEAN"));switch(t.operator){case"||":if(!0===r)return r;if(n=await re(e,t.right),c(n))return n;throw new Error(C(t,"RUNTIME","ONLYORORAND"));case"&&":if(!1===r)return r;if(n=await re(e,t.right),c(n))return n;throw new Error(C(t,"RUNTIME","ONLYORORAND"));default:throw new Error(C(t,"RUNTIME","ONLYORORAND"))}}async function Pe(e,t){const r=t.name.toLowerCase();if(null!==e.localScope&&void 0!==e.localScope[r]){const t=e.localScope[r];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=re(e,t.node);const n=await t.d;return t.value=n,t.valueset=!0,n}if(void 0!==e.globalScope[r]){const t=e.globalScope[r];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=re(e,t.node);const n=await t.d;return t.value=n,t.valueset=!0,n}throw new Error(C(t,"RUNTIME","VARIABLENOTFOUND"))}async function De(e,t){if("Identifier"!==t.callee.type)throw new Error(C(t,"RUNTIME","ONLYNODESSUPPORTED"));if(null!==e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const r=e.localScope[t.callee.name.toLowerCase()];if(r.value instanceof u)return r.value.fn(e,t);if(r.value instanceof o)return Ze(e,t,r.value.definition);throw new Error(C(t,"RUNTIME","NOTAFUNCTION"))}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const r=e.globalScope[t.callee.name.toLowerCase()];if(r.value instanceof u)return r.value.fn(e,t);if(r.value instanceof o)return Ze(e,t,r.value.definition);throw new Error(C(t,"RUNTIME","NOTAFUNCTION"))}throw new Error(C(t,"RUNTIME","NOTFOUND"))}async function je(e,t){return t.value?t.value.cooked:""}async function Le(e,t){const r=[];for(let a=0;a<t.expressions.length;a++){const n=await re(e,t.expressions[a]);r[a]=S(n)}let n="",o=0;for(const a of t.quasis)if(n+=a.value?a.value.cooked:"",!1===a.tail){n+=r[o]?r[o]:"",o++}return n}const ke={};function _e(n){return null===n?"":m(n)||g(n)?"Array":O(n)?"Date":d(n)?"String":c(n)?"Boolean":N(n)?"Number":n instanceof t?"Attachment":n instanceof e?"Portal":n instanceof r?"Dictionary":E(n)?"Feature":n instanceof Z?"Point":n instanceof W?"Polygon":n instanceof K?"Polyline":n instanceof H?"Multipoint":n instanceof z?"Extent":h(n)?"Function":y(n)?"FeatureSet":A(n)?"FeatureSetCollection":n===p?"":"number"==typeof n&&isNaN(n)?"Number":"Unrecognised Type"}async function Ve(e,t,r,n){const o=await re(e,t.arguments[r]);if(l(o,n))return re(e,t.arguments[r+1]);const a=t.arguments.length-r;return 1===a?re(e,t.arguments[r]):2===a?null:3===a?re(e,t.arguments[r+2]):Ve(e,t,r+2,n)}async function Ye(e,t,r,n){if(!0===n)return re(e,t.arguments[r+1]);if(3===t.arguments.length-r)return re(e,t.arguments[r+2]);const o=await re(e,t.arguments[r+2]);if(!1===c(o))throw new Error("WHEN needs boolean test conditions");return Ye(e,t,r+2,o)}async function Be(e,t){const r=e.length,n=Math.floor(r/2);if(0===r)return[];if(1===r)return[e[0]];const o=[Be(e.slice(0,n),t),Be(e.slice(n,r),t)],a=await Promise.all(o);return Ge(a[0],a[1],t,[])}async function Ge(e,t,r,n){const o=n;if(!(e.length>0||t.length>0))return n;if(e.length>0&&t.length>0){let a=await r(e[0],t[0]);return isNaN(a)&&(a=1),a<=0?(o.push(e[0]),e=e.slice(1)):(o.push(t[0]),t=t.slice(1)),Ge(e,t,r,n)}return e.length>0?(o.push(e[0]),Ge(e=e.slice(1),t,r,n)):t.length>0?(o.push(t[0]),Ge(e,t=t.slice(1),r,n)):void 0}function ze(e,t){const r=e.length,n=Math.floor(r/2);return t||(t=function(e,t){return e<t?-1:e===t?0:1}),0===r?[]:1===r?[e[0]]:qe(ze(e.slice(0,n),t),ze(e.slice(n,r),t),t)}function qe(e,t,r){const n=[];for(;e.length>0||t.length>0;)if(e.length>0&&t.length>0){let o=r(e[0],t[0]);isNaN(o)&&(o=1),o<=0?(n.push(e[0]),e=e.slice(1)):(n.push(t[0]),t=t.slice(1))}else e.length>0?(n.push(e[0]),e=e.slice(1)):t.length>0&&(n.push(t[0]),t=t.slice(1));return n}async function He(e,t,r){const n=e.body;if(r.length!==e.params.length)throw new Error("Invalid Parameter calls to function.");for(let a=0;a<r.length;a++){const n=e.params[a];"Identifier"===n.type&&(t.localScope[n.name.toLowerCase()]={d:null,value:r[a],valueset:!0,node:null})}const o=await re(t,n);if(o instanceof T)return o.value;if(o===w)throw new Error("Cannot Break from a Function");if(o===f)throw new Error("Cannot Continue from a Function");return o instanceof I?o.value:o}function Ze(e,t,r){return te(e,t,((t,n,o)=>{const a={spatialReference:e.spatialReference,services:e.services,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:e.depthCounter+1};if(a.depthCounter>64)throw new Error("Exceeded maximum function depth");return He(r,a,o)}))}function We(e){const t=function(){const t={abortSignal:e.context.abortSignal,spatialReference:e.context.spatialReference,console:e.context.console,lrucache:e.context.lrucache,interceptor:e.context.interceptor,services:e.context.services,localScope:{},globalScope:e.context.globalScope,depthCounter:e.context.depthCounter+1};if(t.depthCounter>64)throw new Error("Exceeded maximum function depth");return He(e.definition,t,arguments)};return t}k(ke,ee),G(ke,ee),Y(ke,ee),V(ke,ee),B(ke,ee),_({functions:ke,compiled:!1,signatures:null,evaluateIdentifier:null,arcadeCustomFunctionHandler:null,mode:"async",standardFunction:ee,standardFunctionAsync:te}),ke.typeof=function(e,t){return ee(e,t,((e,t,r)=>{s(r,1,1);const n=_e(r[0]);if("Unrecognised Type"===n)throw new Error("Unrecognised Type");return n}))},ke.iif=async function(e,t){s(null===t.arguments?[]:t.arguments,3,3);const r=await re(e,t.arguments[0]);if(!1===c(r))throw new Error("IF Function must have a boolean test condition");const n=[];return n[0]=await re(e,t.arguments[1]),n[1]=await re(e,t.arguments[2]),r?n[0]:n[1]},ke.decode=async function(e,t){if(t.arguments.length<2)throw new Error("Missing Parameters");if(2===t.arguments.length)return re(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new Error("Must have a default value result.");return Ve(e,t,1,await re(e,t.arguments[0]))},ke.when=async function(e,t){if(t.arguments.length<3)throw new Error("Missing Parameters");if(t.arguments.length%2==0)throw new Error("Must have a default value result.");const r=await re(e,t.arguments[0]);if(!1===c(r))throw new Error("WHEN needs boolean test conditions");return Ye(e,t,0,r)},ke.sort=function(e,t){return te(e,t,(async(e,t,r)=>{s(r,1,2);let n=r[0];if(g(n)&&(n=n.toArray()),!1===m(n))throw new Error("Illegal Argument");if(r.length>1){if(!1===h(r[1]))throw new Error("Illegal Argument");return Be(n,We(r[1]))}let o=n;if(0===o.length)return[];const a={};for(let s=0;s<o.length;s++){const e=_e(o[s]);""!==e&&(a[e]=!0)}if(!0===a.Array||!0===a.Dictionary||!0===a.Feature||!0===a.Point||!0===a.Polygon||!0===a.Polyline||!0===a.Multipoint||!0===a.Extent||!0===a.Function)return o.slice(0);let i=0,c="";for(const s in a)i++,c=s;return i>1||"String"===c?o=ze(o,((e,t)=>{if(null==e||e===p)return null==t||t===p?0:1;if(null==t||t===p)return-1;const r=S(e),n=S(t);return r<n?-1:r===n?0:1})):"Number"===c?o=ze(o,((e,t)=>e-t)):"Boolean"===c?o=ze(o,((e,t)=>e===t?0:t?-1:1)):"Date"===c&&(o=ze(o,((e,t)=>t-e))),o}))};const Ke={fixSpatialReference:U,parseArguments:$,standardFunction:ee,standardFunctionAsync:te,evaluateIdentifier:Pe,arcadeCustomFunction:We};for(const st in ke)ke[st]={value:new u(ke[st]),valueset:!0,node:null};const Xe=function(){};function Je(e,t){const o=new Xe;null==e&&(e={}),null==t&&(t={});const a=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const r in t)o[r]={value:new u(t[r]),native:!0,valueset:!0,node:null};for(const r in e)e[r]&&"esri.Graphic"===e[r].declaredClass?o[r]={value:n.createFromGraphic(e[r]),valueset:!0,node:null}:o[r]={value:e[r],valueset:!0,node:null};return o}function Qe(e){console.log(e)}Xe.prototype=ke,Xe.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Xe.prototype.pi={value:Math.PI,valueset:!0,node:null};const $e=Ke;function et(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:ee,standardFunctionAsync:te,evaluateIdentifier:Pe,arcadeCustomFunctionHandler:We};for(let r=0;r<e.length;r++)e[r].registerFunctions(t);for(const r in t.functions)ke[r]={value:new u(t.functions[r]),valueset:!0,node:null},Xe.prototype[r]=ke[r];for(let r=0;r<t.signatures.length;r++)F(t.signatures[r],"async")}async function tt(e,t){let r=t.spatialReference;null==r&&(r=new X({wkid:102100}));const n=Je(t.vars,t.customfunctions),a={spatialReference:r,services:t.services,abortSignal:void 0===t.abortSignal||null===t.abortSignal?{aborted:!1}:t.abortSignal,globalScope:n,console:t.console?t.console:Qe,lrucache:t.lrucache,interceptor:t.interceptor,localScope:null,depthCounter:1};let i=await re(a,e.body[0].body);if(i instanceof T&&(i=i.value),i instanceof I&&(i=i.value),i===p&&(i=null),i===w)throw new Error("Cannot return BREAK");if(i===f)throw new Error("Cannot return CONTINUE");if(i instanceof u)throw new Error("Cannot return FUNCTION");if(i instanceof o)throw new Error("Cannot return FUNCTION");return i}function rt(e,t){return x(e)}function nt(e,t){return M(e,t,"full")}function ot(e,t){return P(e,t)}function at(e,t){return D(e,t)}function it(e){return j(e)}et([L]);export{tt as executeScript,et as extend,rt as extractFieldLiterals,it as findFunctionCalls,$e as functionHelper,at as referencesFunction,ot as referencesMember,nt as validateScript};
5
+ import e from"./ArcadePortal.js";import t from"./Attachment.js";import r from"./Dictionary.js";import n from"./Feature.js";import o from"./FunctionWrapper.js";import a from"./ImmutablePathArray.js";import i from"./ImmutablePointArray.js";import{p as s,i as c,m as l,N as u,x as f,v as p,w,o as h,b as d,l as m,n as g,s as E,y,a as N,f as v,I,R as T,h as S,q as b,r as R,j as O,z as A,A as U}from"../chunks/languageUtils.js";import{nodeErrorMessage as C,addFunctionDeclaration as F,findFieldLiterals as x,validateScript as M,referencesMember as P,referencesFunction as D,findFunctionCalls as j}from"./treeAnalysis.js";import{A as L}from"../chunks/array.js";import{registerFunctions as k}from"./functions/date.js";import{registerFunctions as _}from"./functions/geomasync.js";import{registerFunctions as V}from"./functions/geometry.js";import{registerFunctions as Y}from"./functions/maths.js";import{registerFunctions as B}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import z from"../geometry/Extent.js";import q from"../geometry/Geometry.js";import H from"../geometry/Multipoint.js";import Z from"../geometry/Point.js";import W from"../geometry/Polygon.js";import K from"../geometry/Polyline.js";import X from"../geometry/SpatialReference.js";function J(e){return e&&"function"==typeof e.then}const Q=100;async function $(e,t){const r=[];for(let n=0;n<t.arguments.length;n++)r.push(await re(e,t.arguments[n]));return r}async function ee(e,t,r){if(!0===t.preparsed)return r(e,null,t.arguments);return r(e,t,await $(e,t))}async function te(e,t,r){if(!0===t.preparsed){const n=r(e,null,t.arguments);return J(n),n}const n=r(e,t,await $(e,t));return J(n),n}async function re(e,t,r){if(t.breakpoint&&!0!==r){const r=t.breakpoint();return await r,re(e,t,!0)}switch(t.type){case"VariableDeclarator":return Re(e,t);case"VariableDeclaration":return be(e,t,0);case"BlockStatement":return ve(e,t);case"FunctionDeclaration":return Se(e,t);case"ReturnStatement":return Te(e,t);case"IfStatement":return Ne(e,t);case"ExpressionStatement":return ye(e,t);case"UpdateExpression":return me(e,t);case"AssignmentExpression":return Ee(e,t);case"ForStatement":return ce(e,t);case"ForInStatement":return de(e,t);case"BreakStatement":return w;case"EmptyStatement":return p;case"ContinueStatement":return f;case"TemplateElement":return je(e,t);case"TemplateLiteral":return Le(e,t);case"Identifier":return Pe(e,t);case"MemberExpression":return Ue(e,t);case"Literal":return t.value;case"CallExpression":return De(e,t);case"UnaryExpression":return Ce(e,t);case"BinaryExpression":return xe(e,t);case"LogicalExpression":return Me(e,t);case"ArrayExpression":return Fe(e,t);case"ObjectExpression":return ne(e,t);case"Property":return oe(e,t);default:throw new Error(C(t,"RUNTIME","UNREOGNISED"))}}async function ne(e,t){const n=[];for(let r=0;r<t.properties.length;r++)n[r]=await re(e,t.properties[r]);const o={};for(let r=0;r<n.length;r++){const e=n[r];if(h(e.value))throw new Error("Illegal Argument");if(!1===d(e.key))throw new Error("Illegal Argument");e.value===p?o[e.key.toString()]=null:o[e.key.toString()]=e.value}const a=new r(o);return a.immutable=!1,a}async function oe(e,t){const r=await re(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:r};return{key:await re(e,t.key),value:r}}async function ae(e,t,r){const n=await re(e,t.body);return r.lastAction=n,r.lastAction===w||r.lastAction instanceof T?(r.testResult=!1,r):null!==t.update?(await re(e,t.update),r):r}async function ie(e,t,r){if(null!==t.test){const n=await re(e,t.test);if(!0===e.abortSignal?.aborted)throw new Error("Cancelled");if(r.testResult=n,!1===r.testResult)return r;if(!0!==r.testResult)throw new Error(C(t,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"));return ae(e,t,r)}return ae(e,t,r)}function se(e,t,r,n,o,a){try{ie(e,t,r).then((()=>{try{!0===r.testResult?++a>Q?(a=0,setTimeout((()=>{se(e,t,r,n,o,a)}),0)):se(e,t,r,n,o,a):r.lastAction instanceof T?n(r.lastAction):n(p)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ce(e,t){try{return null!==t.init?re(e,t.init).then((()=>new Promise(((r,n)=>{se(e,t,{testResult:!0,lastAction:p},(e=>{r(e)}),(e=>{n(e)}),0)})))):new Promise(((r,n)=>{se(e,t,{testResult:!0,lastAction:p},(e=>{r(e)}),(e=>{n(e)}),0)}))}catch(r){return Promise.reject(r)}}function le(e,t,r,n,o,a,i,s,c,l){try{if(n<=a)return void s(p);o.value="k"===i?r[a]:a,re(e,t.body).then((u=>{try{u instanceof T?s(u):u===w?s(p):++l>Q?(l=0,setTimeout((()=>{le(e,t,r,n,o,a+1,i,s,c,l)}),0)):le(e,t,r,n,o,a+1,i,s,c,l)}catch(f){c(f)}}),(e=>{c(e)}))}catch(u){c(u)}}function ue(e,t,r,n,o,a,i,s,c){try{if(r.length()<=o)return void i(p);n.value="k"===a?r.get(o):o,re(e,t.body).then((l=>{l instanceof T?i(l):l===w?i(p):++c>Q?(c=0,setTimeout((()=>{ue(e,t,r,n,o+1,a,i,s,c)}),0)):ue(e,t,r,n,o+1,a,i,s,c)}),(e=>{s(e)}))}catch(l){s(l)}}function fe(e,t,r,n,o,a){try{if(void 0===a&&(a="i"),0===r.length)return void n.resolve(p);le(e,t,r,r.length,o,0,a,(e=>{n.resolve(e)}),(e=>{n.reject(e)}),0)}catch(i){n.reject(i)}}function pe(e,t,r,n,o,a){try{if(void 0===a&&(a="i"),0===r.length)return void n.resolve(p);ue(e,t,r,o,0,a,(e=>{n.resolve(e)}),(e=>{n.reject(e)}),0)}catch(i){n.reject(i)}}function we(e,t,r,n,o){try{fe(e,t,r.keys(),n,o,"k")}catch(a){n.reject(a)}}function he(e,t,r,o,a,i,s,c){try{e.next().then((l=>{try{if(null===l)i(p);else{const u=n.createFromGraphicLikeObject(l.geometry,l.attributes,o);u._underlyingGraphic=l,a.value=u;re(t,r.body).then((n=>{try{n===w?i(p):n instanceof T?i(n):++c>Q?(c=0,setTimeout((()=>{he(e,t,r,o,a,i,s,c)}),0)):he(e,t,r,o,a,i,s,c)}catch(l){s(l)}}),(e=>{s(e)}))}}catch(u){s(u)}}),(e=>{s(e)}))}catch(l){s(l)}}async function de(e,t){return new Promise(((n,o)=>{re(e,t.right).then((a=>{try{let i=null;i="VariableDeclaration"===t.left.type?re(e,t.left):Promise.resolve(),i.then((()=>{try{let i="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(i=e.name)}else"Identifier"===t.left.type&&(i=t.left.name);if(!i)throw new Error(C(t,"RUNTIME","INVALIDVARIABLE"));i=i.toLowerCase();let s=null;if(null!=e.localScope&&void 0!==e.localScope[i]&&(s=e.localScope[i]),null===s&&void 0!==e.globalScope?.[i]&&(s=e.globalScope[i]),null===s)return void o(new Error(C(t,"RUNTIME","VARIABLENOTDECLARED")));m(a)||d(a)?fe(e,t,a,{reject:o,resolve:n},s):g(a)?pe(e,t,a,{reject:o,resolve:n},s):a instanceof r||E(a)?we(e,t,a,{reject:o,resolve:n},s):y(a)?he(a.iterator(e.abortSignal),e,t,a,s,(e=>{n(e)}),(e=>{o(e)}),0):fe(e,t,[],{reject:o,resolve:n},s)}catch(i){o(i)}}),o)}catch(i){o(i)}}),o)}))}async function me(e,t){const n=t.argument;if("MemberExpression"===n.type){const o={t:null},a=await re(e,n.object);let i=null;o.t=a,!0===n.computed?i=await re(e,n.property):"Identifier"===n.property?.type&&(i=n.property.name);const s=o.t;let c;if(m(s)){if(!N(i))throw new Error("Invalid Parameter");if(i<0&&(i=s.length+i),i<0||i>=s.length)throw new Error("Assignment outside of array bounds");c=v(s[i]),s[i]="++"===t.operator?c+1:c-1}else if(s instanceof r){if(!1===d(i))throw new Error("Dictionary accessor must be a string");if(!0!==s.hasField(i))throw new Error("Invalid Parameter");c=v(s.field(i)),s.setField(i,"++"===t.operator?c+1:c-1)}else{if(!E(s))throw g(s)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===d(i))throw new Error("Feature accessor must be a string");if(!0!==s.hasField(i))throw new Error("Invalid Parameter");c=v(s.field(i)),s.setField(i,"++"===t.operator?c+1:c-1)}return!1===t.prefix?c:"++"===t.operator?c+1:c-1}const o="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!o)throw new Error("Invalid identifier");let a;if(null!=e.localScope&&void 0!==e.localScope[o])return a=v(e.localScope[o].value),e.localScope[o]={value:"++"===t.operator?a+1:a-1,valueset:!0,node:t},!1===t.prefix?a:"++"===t.operator?a+1:a-1;if(void 0!==e.globalScope?.[o])return a=v(e.globalScope[o].value),e.globalScope[o]={value:"++"===t.operator?a+1:a-1,valueset:!0,node:t},!1===t.prefix?a:"++"===t.operator?a+1:a-1;throw new Error("Variable not recognised")}function ge(e,t,r,n){switch(t){case"=":return e===p?null:e;case"/=":return v(r)/v(e);case"*=":return v(r)*v(e);case"-=":return v(r)-v(e);case"+=":return d(r)||d(e)?S(r)+S(e):v(r)+v(e);case"%=":return v(r)%v(e);default:throw new Error(C(n,"RUNTIME","OPERATORNOTRECOGNISED"))}}async function Ee(e,t){const n=t.left;if("MemberExpression"===n?.type){const o=await re(e,t.right),a=await re(e,n.object);let i=null;if(!0===n.computed)i=await re(e,n.property);else{if("Identifier"!==n.property?.type)throw new Error("Expected computed or identifier for assignemnt target");i=n.property.name}if(m(a)){if(!N(i))throw new Error("Invalid Parameter");if(i<0&&(i=a.length+i),i<0||i>a.length)throw new Error("Assignment outside of array bounds");if(i===a.length){if("="!==t.operator)throw new Error("Invalid Parameter");a[i]=ge(o,t.operator,a[i],t)}else a[i]=ge(o,t.operator,a[i],t)}else if(a instanceof r){if(!1===d(i))throw new Error("Dictionary accessor must be a string");if(!0===a.hasField(i))a.setField(i,ge(o,t.operator,a.field(i),t));else{if("="!==t.operator)throw new Error("Invalid Parameter");a.setField(i,ge(o,t.operator,null,t))}}else{if(!E(a))throw g(a)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===d(i))throw new Error("Feature accessor must be a string");if(!0===a.hasField(i))a.setField(i,ge(o,t.operator,a.field(i),t));else{if("="!==t.operator)throw new Error("Invalid Parameter");a.setField(i,ge(o,t.operator,null,t))}}return p}const o=n.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[o]){const r=await re(e,t.right);return e.localScope[o]={value:ge(r,t.operator,e.localScope[o].value,t),valueset:!0,node:t.right},p}if(void 0!==e.globalScope?.[o]){const r=await re(e,t.right);return e.globalScope[o]={value:ge(r,t.operator,e.globalScope[o].value,t),valueset:!0,node:t.right},p}throw new Error("Cannot assign undeclared variable")}async function ye(e,t){if("AssignmentExpression"===t.expression.type)return re(e,t.expression);if("CallExpression"===t.expression.type){const r=await re(e,t.expression);return r===p?p:new I(r)}const r=await re(e,t.expression);return r===p?p:new I(r)}async function Ne(e,t){if("AssignmentExpression"===t.test.type||"UpdateExpression"===t.test.type)throw new Error(C(t.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const r=await re(e,t.test);if(!0===r)return re(e,t.consequent);if(!1===r)return null!==t.alternate?re(e,t.alternate):p;throw new Error(C(t.test,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}async function ve(e,t){return Ie(e,t,0)}async function Ie(e,t,r){if(r>=t.body.length)return p;const n=await re(e,t.body[r]);return n instanceof T||n===w||n===f||r===t.body.length-1?n:Ie(e,t,r+1)}async function Te(e,t){if(null===t.argument)return new T(p);const r=await re(e,t.argument);return new T(r)}async function Se(e,t){const r=t.id.name.toLowerCase();return e.globalScope[r]={valueset:!0,node:null,value:new o(t,e)},p}async function be(e,t,r){return r>=t.declarations.length?p:(await re(e,t.declarations[r]),r===t.declarations.length-1||await be(e,t,r+1),p)}async function Re(e,t){let r=null;if(r=null===t.init?null:await re(e,t.init),null!=e.localScope){if(r===p&&(r=null),"Identifier"!==t.id.type)throw new Error("Can only assign a regular variable");const n=t.id.name.toLowerCase();return e.localScope[n]={value:r,valueset:!0,node:t.init},p}if("Identifier"!==t.id.type)throw new Error("Can only assign a regular variable");const n=t.id.name.toLowerCase();return r===p&&(r=null),e.globalScope[n]={value:r,valueset:!0,node:t.init},p}let Oe=0;function Ae(e,t,n,o){let s;switch(t=t.toLowerCase()){case"hasz":{const t=e.hasZ;return void 0!==t&&t}case"hasm":{const t=e.hasM;return void 0!==t&&t}case"spatialreference":{let t=e.spatialReference._arcadeCacheId;if(void 0===t){let r=!0;Object.freeze&&Object.isFrozen(e.spatialReference)&&(r=!1),r&&(Oe++,e.spatialReference._arcadeCacheId=Oe,t=Oe)}const n=new r({wkt:e.spatialReference.wkt,wkid:e.spatialReference.wkid});return void 0!==t&&(n._arcadeCacheId="SPREF"+t.toString()),n}}switch(e.type){case"extent":switch(t){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const r=e[t];return void 0!==r?r:null}case"type":return"Extent"}break;case"polygon":switch(t){case"rings":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new a(e.rings,e.spatialReference,!0===e.hasZ,!0===e.hasM,s);case"type":return"Polygon"}break;case"point":switch(t){case"x":case"y":case"z":case"m":return void 0!==e[t]?e[t]:null;case"type":return"Point"}break;case"polyline":switch(t){case"paths":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new a(e.paths,e.spatialReference,!0===e.hasZ,!0===e.hasM,s);case"type":return"Polyline"}break;case"multipoint":switch(t){case"points":s=e.cache._arcadeCacheId,void 0===s&&(Oe++,s=Oe,e.cache._arcadeCacheId=s);return new i(e.points,e.spatialReference,!0===e.hasZ,!0===e.hasM,s,1);case"type":return"Multipoint"}}throw new Error(C(o,"RUNTIME","PROPERTYNOTFOUND"))}async function Ue(e,t){const n=await re(e,t.object);if(null===n)throw new Error(C(t,"RUNTIME","NOTFOUND"));if(!1===t.computed){if("Identifier"===t.property?.type){if(n instanceof r||E(n))return n.field(t.property.name);if(n instanceof q)return Ae(n,t.property.name,e,t);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}let o=await re(e,t.property);if(n instanceof r||E(n)){if(d(o))return n.field(o);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(n instanceof q){if(d(o))return Ae(n,o,e,t);throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(m(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(g(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length()+o),o>=n.length()||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n.get(o)}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}if(d(n)){if(N(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(t,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}throw new Error(C(t,"RUNTIME","INVALIDTYPE"))}async function Ce(e,t){const r=await re(e,t.argument);if(c(r)){if("!"===t.operator)return!r;if("-"===t.operator)return-1*v(r);if("+"===t.operator)return 1*v(r);if("~"===t.operator)return~v(r);throw new Error(C(t,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}if("-"===t.operator)return-1*v(r);if("+"===t.operator)return 1*v(r);if("~"===t.operator)return~v(r);throw new Error(C(t,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}async function Fe(e,t){const r=[];for(let n=0;n<t.elements.length;n++)r.push(await re(e,t.elements[n]));for(let n=0;n<r.length;n++){if(h(r[n]))throw new Error(C(t,"RUNTIME","FUNCTIONCONTEXTILLEGAL"));r[n]===p&&(r[n]=null)}return r}async function xe(e,t){const r=[];r[0]=await re(e,t.left),r[1]=await re(e,t.right);const n=r[0],o=r[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return R(v(n),v(o),t.operator);case"==":return l(n,o);case"!=":return!l(n,o);case"<":case">":case"<=":case">=":return b(n,o,t.operator);case"+":return d(n)||d(o)?S(n)+S(o):v(n)+v(o);case"-":return v(n)-v(o);case"*":return v(n)*v(o);case"/":return v(n)/v(o);case"%":return v(n)%v(o);default:throw new Error(C(t,"RUNTIME","OPERATORNOTRECOGNISED"))}}async function Me(e,t){if("AssignmentExpression"===t.left?.type||"UpdateExpression"===t.left?.type)throw new Error(C(t.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));if("AssignmentExpression"===t.right?.type||"UpdateExpression"===t.right?.type)throw new Error(C(t.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const r=await re(e,t.left);let n=null;if(!c(r))throw new Error(C(t,"RUNTIME","ONLYBOOLEAN"));switch(t.operator){case"||":if(!0===r)return r;if(n=await re(e,t.right),c(n))return n;throw new Error(C(t,"RUNTIME","ONLYORORAND"));case"&&":if(!1===r)return r;if(n=await re(e,t.right),c(n))return n;throw new Error(C(t,"RUNTIME","ONLYORORAND"));default:throw new Error(C(t,"RUNTIME","ONLYORORAND"))}}async function Pe(e,t){const r=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[r]){const t=e.localScope[r];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=re(e,t.node);const n=await t.d;return t.value=n,t.valueset=!0,n}if(void 0!==e.globalScope?.[r]){const t=e.globalScope[r];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=re(e,t.node);const n=await t.d;return t.value=n,t.valueset=!0,n}throw new Error(C(t,"RUNTIME","VARIABLENOTFOUND"))}async function De(e,t){if("Identifier"!==t.callee.type)throw new Error(C(t,"RUNTIME","ONLYNODESSUPPORTED"));if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const r=e.localScope[t.callee.name.toLowerCase()];if(r.value instanceof u)return r.value.fn(e,t);if(r.value instanceof o)return Ze(e,t,r.value.definition);throw new Error(C(t,"RUNTIME","NOTAFUNCTION"))}if(void 0!==e.globalScope?.[t.callee.name.toLowerCase()]){const r=e.globalScope[t.callee.name.toLowerCase()];if(r.value instanceof u)return r.value.fn(e,t);if(r.value instanceof o)return Ze(e,t,r.value.definition);throw new Error(C(t,"RUNTIME","NOTAFUNCTION"))}throw new Error(C(t,"RUNTIME","NOTFOUND"))}async function je(e,t){return t.value?t.value.cooked:""}async function Le(e,t){const r=[];for(let a=0;a<t.expressions.length;a++){const n=await re(e,t.expressions[a]);r[a]=S(n)}let n="",o=0;for(const a of t.quasis)if(n+=a.value?a.value.cooked:"",!1===a.tail){n+=r[o]?r[o]:"",o++}return n}const ke={};function _e(n){return null===n?"":m(n)||g(n)?"Array":O(n)?"Date":d(n)?"String":c(n)?"Boolean":N(n)?"Number":n instanceof t?"Attachment":n instanceof e?"Portal":n instanceof r?"Dictionary":E(n)?"Feature":n instanceof Z?"Point":n instanceof W?"Polygon":n instanceof K?"Polyline":n instanceof H?"Multipoint":n instanceof z?"Extent":h(n)?"Function":y(n)?"FeatureSet":A(n)?"FeatureSetCollection":n===p?"":"number"==typeof n&&isNaN(n)?"Number":"Unrecognised Type"}async function Ve(e,t,r,n){const o=await re(e,t.arguments[r]);if(l(o,n))return re(e,t.arguments[r+1]);const a=t.arguments.length-r;return 1===a?re(e,t.arguments[r]):2===a?null:3===a?re(e,t.arguments[r+2]):Ve(e,t,r+2,n)}async function Ye(e,t,r,n){if(!0===n)return re(e,t.arguments[r+1]);if(3===t.arguments.length-r)return re(e,t.arguments[r+2]);const o=await re(e,t.arguments[r+2]);if(!1===c(o))throw new Error("WHEN needs boolean test conditions");return Ye(e,t,r+2,o)}async function Be(e,t){const r=e.length,n=Math.floor(r/2);if(0===r)return[];if(1===r)return[e[0]];const o=[Be(e.slice(0,n),t),Be(e.slice(n,r),t)],a=await Promise.all(o);return Ge(a[0],a[1],t,[])}async function Ge(e,t,r,n){const o=n;if(!(e.length>0||t.length>0))return n;if(e.length>0&&t.length>0){let a=await r(e[0],t[0]);return isNaN(a)&&(a=1),a<=0?(o.push(e[0]),e=e.slice(1)):(o.push(t[0]),t=t.slice(1)),Ge(e,t,r,n)}return e.length>0?(o.push(e[0]),Ge(e=e.slice(1),t,r,n)):t.length>0?(o.push(t[0]),Ge(e,t=t.slice(1),r,n)):void 0}function ze(e,t){const r=e.length,n=Math.floor(r/2);return t||(t=function(e,t){return e<t?-1:e===t?0:1}),0===r?[]:1===r?[e[0]]:qe(ze(e.slice(0,n),t),ze(e.slice(n,r),t),t)}function qe(e,t,r){const n=[];for(;e.length>0||t.length>0;)if(e.length>0&&t.length>0){let o=r(e[0],t[0]);isNaN(o)&&(o=1),o<=0?(n.push(e[0]),e=e.slice(1)):(n.push(t[0]),t=t.slice(1))}else e.length>0?(n.push(e[0]),e=e.slice(1)):t.length>0&&(n.push(t[0]),t=t.slice(1));return n}async function He(e,t,r){const n=e.body;if(r.length!==e.params.length)throw new Error("Invalid Parameter calls to function.");for(let a=0;a<r.length;a++){const n=e.params[a];"Identifier"===n.type&&null!=t.localScope&&(t.localScope[n.name.toLowerCase()]={d:null,value:r[a],valueset:!0,node:null})}const o=await re(t,n);if(o instanceof T)return o.value;if(o===w)throw new Error("Cannot Break from a Function");if(o===f)throw new Error("Cannot Continue from a Function");return o instanceof I?o.value:o}function Ze(e,t,r){return te(e,t,((t,n,o)=>{const a={spatialReference:e.spatialReference,services:e.services,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:e.depthCounter?e.depthCounter+1:1};if(a.depthCounter>64)throw new Error("Exceeded maximum function depth");return He(r,a,o)}))}function We(e){const t=function(){const t={abortSignal:e.context.abortSignal,spatialReference:e.context.spatialReference,console:e.context.console,lrucache:e.context.lrucache,interceptor:e.context.interceptor,services:e.context.services,localScope:{},globalScope:e.context.globalScope,depthCounter:e.context.depthCounter+1};if(t.depthCounter>64)throw new Error("Exceeded maximum function depth");return He(e.definition,t,arguments)};return t}k(ke,ee),G(ke,ee),Y(ke,ee),V(ke,ee),B(ke,ee),_({functions:ke,compiled:!1,signatures:null,evaluateIdentifier:null,arcadeCustomFunctionHandler:null,mode:"async",standardFunction:ee,standardFunctionAsync:te}),ke.typeof=function(e,t){return ee(e,t,((e,t,r)=>{s(r,1,1);const n=_e(r[0]);if("Unrecognised Type"===n)throw new Error("Unrecognised Type");return n}))},ke.iif=async function(e,t){s(null===t.arguments?[]:t.arguments,3,3);const r=await re(e,t.arguments[0]);if(!1===c(r))throw new Error("IF Function must have a boolean test condition");const n=[];return n[0]=await re(e,t.arguments[1]),n[1]=await re(e,t.arguments[2]),r?n[0]:n[1]},ke.decode=async function(e,t){if(t.arguments.length<2)throw new Error("Missing Parameters");if(2===t.arguments.length)return re(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new Error("Must have a default value result.");return Ve(e,t,1,await re(e,t.arguments[0]))},ke.when=async function(e,t){if(t.arguments.length<3)throw new Error("Missing Parameters");if(t.arguments.length%2==0)throw new Error("Must have a default value result.");const r=await re(e,t.arguments[0]);if(!1===c(r))throw new Error("WHEN needs boolean test conditions");return Ye(e,t,0,r)},ke.sort=function(e,t){return te(e,t,(async(e,t,r)=>{s(r,1,2);let n=r[0];if(g(n)&&(n=n.toArray()),!1===m(n))throw new Error("Illegal Argument");if(r.length>1){if(!1===h(r[1]))throw new Error("Illegal Argument");return Be(n,We(r[1]))}let o=n;if(0===o.length)return[];const a={};for(let s=0;s<o.length;s++){const e=_e(o[s]);""!==e&&(a[e]=!0)}if(!0===a.Array||!0===a.Dictionary||!0===a.Feature||!0===a.Point||!0===a.Polygon||!0===a.Polyline||!0===a.Multipoint||!0===a.Extent||!0===a.Function)return o.slice(0);let i=0,c="";for(const s in a)i++,c=s;return i>1||"String"===c?o=ze(o,((e,t)=>{if(null==e||e===p)return null==t||t===p?0:1;if(null==t||t===p)return-1;const r=S(e),n=S(t);return r<n?-1:r===n?0:1})):"Number"===c?o=ze(o,((e,t)=>e-t)):"Boolean"===c?o=ze(o,((e,t)=>e===t?0:t?-1:1)):"Date"===c&&(o=ze(o,((e,t)=>t-e))),o}))};const Ke={fixSpatialReference:U,parseArguments:$,standardFunction:ee,standardFunctionAsync:te,evaluateIdentifier:Pe,arcadeCustomFunction:We};for(const st in ke)ke[st]={value:new u(ke[st]),valueset:!0,node:null};const Xe=function(){};function Je(e,t){const o=new Xe;null==e&&(e={}),null==t&&(t={});const a=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const r in t)o[r]={value:new u(t[r]),native:!0,valueset:!0,node:null};for(const r in e)e[r]&&"esri.Graphic"===e[r].declaredClass?o[r]={value:n.createFromGraphic(e[r]),valueset:!0,node:null}:o[r]={value:e[r],valueset:!0,node:null};return o}function Qe(e){console.log(e)}Xe.prototype=ke,Xe.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Xe.prototype.pi={value:Math.PI,valueset:!0,node:null};const $e=Ke;function et(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:ee,standardFunctionAsync:te,evaluateIdentifier:Pe,arcadeCustomFunctionHandler:We};for(let r=0;r<e.length;r++)e[r].registerFunctions(t);for(const r in t.functions)ke[r]={value:new u(t.functions[r]),valueset:!0,node:null},Xe.prototype[r]=ke[r];for(let r=0;r<t.signatures.length;r++)F(t.signatures[r],"async")}async function tt(e,t){let r=t.spatialReference;null==r&&(r=new X({wkid:102100}));const n=Je(t.vars,t.customfunctions),a={spatialReference:r,services:t.services,abortSignal:void 0===t.abortSignal||null===t.abortSignal?{aborted:!1}:t.abortSignal,globalScope:n,console:t.console?t.console:Qe,lrucache:t.lrucache,interceptor:t.interceptor,localScope:null,depthCounter:1};let i=await re(a,e.body[0].body);if(i instanceof T&&(i=i.value),i instanceof I&&(i=i.value),i===p&&(i=null),i===w)throw new Error("Cannot return BREAK");if(i===f)throw new Error("Cannot return CONTINUE");if(i instanceof u)throw new Error("Cannot return FUNCTION");if(i instanceof o)throw new Error("Cannot return FUNCTION");return i}function rt(e,t){return x(e)}function nt(e,t){return M(e,t,"full")}function ot(e,t){return P(e,t)}function at(e,t){return D(e,t)}function it(e){return j(e)}et([L]);export{tt as executeScript,et as extend,rt as extractFieldLiterals,it as findFunctionCalls,$e as functionHelper,at as referencesFunction,ot as referencesMember,nt as validateScript};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"./ArcadePortal.js";import r from"./Attachment.js";import t from"./Dictionary.js";import n from"./Feature.js";import o from"./FunctionWrapper.js";import a from"./ImmutablePathArray.js";import i from"./ImmutablePointArray.js";import{p as s,i as l,m as c,N as u,x as f,w as p,v as h,o as w,b as m,l as E,R as d,n as g,s as N,a as y,f as I,I as v,h as T,q as R,r as O,j as S,y as b,z as A,A as U}from"../chunks/languageUtils.js";import{nodeErrorMessage as C,addFunctionDeclaration as x,findFieldLiterals as M,findExpectedFieldLiterals as F,validateScript as P,referencesMember as D,referencesFunction as L,findFunctionCalls as j}from"./treeAnalysis.js";import{A as _}from"../chunks/array.js";import{registerFunctions as k}from"./functions/date.js";import{registerFunctions as V}from"./functions/geometry.js";import{registerFunctions as B}from"./functions/geomsync.js";import{registerFunctions as Y}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as z}from"./functions/string.js";import q from"../geometry/Extent.js";import Z from"../geometry/Geometry.js";import H from"../geometry/Multipoint.js";import W from"../geometry/Point.js";import K from"../geometry/Polygon.js";import X from"../geometry/Polyline.js";import J from"../geometry/SpatialReference.js";function Q(e,r){const t=[];for(let n=0;n<r.arguments.length;n++)t.push(ee(e,r.arguments[n]));return t}function $(e,r,t){try{return!0===r.preparsed?t(e,null,r.arguments):t(e,r,Q(e,r))}catch(n){throw n}}function ee(e,r){try{switch(r.type){case"EmptyStatement":return h;case"VariableDeclarator":return me(e,r);case"VariableDeclaration":return we(e,r);case"BlockStatement":return fe(e,r);case"FunctionDeclaration":return he(e,r);case"ReturnStatement":return pe(e,r);case"IfStatement":return ue(e,r);case"ExpressionStatement":return ce(e,r);case"AssignmentExpression":return le(e,r);case"UpdateExpression":return ie(e,r);case"BreakStatement":return p;case"ContinueStatement":return f;case"TemplateElement":return Te(e,r);case"TemplateLiteral":return Re(e,r);case"ForStatement":return oe(e,r);case"ForInStatement":return ne(e,r);case"Identifier":return Oe(e,r);case"MemberExpression":return ge(e,r);case"Literal":return r.value;case"CallExpression":return Se(e,r);case"UnaryExpression":return Ne(e,r);case"BinaryExpression":return Ie(e,r);case"LogicalExpression":return ve(e,r);case"ArrayExpression":return ye(e,r);case"ObjectExpression":return re(e,r);case"Property":return te(e,r);default:throw new Error(C(r,"RUNTIME","UNREOGNISED"))}}catch(t){throw t}}function re(e,r){const n={};for(let t=0;t<r.properties.length;t++){const o=ee(e,r.properties[t]);if(w(o.value))throw new Error("Illegal Argument");if(!1===m(o.key))throw new Error("Illegal Argument");o.value===h?n[o.key.toString()]=null:n[o.key.toString()]=o.value}const o=new t(n);return o.immutable=!1,o}function te(e,r){return{key:"Identifier"===r.key.type?r.key.name:ee(e,r.key),value:ee(e,r.value)}}function ne(e,r){const n=ee(e,r.right);"VariableDeclaration"===r.left.type&&ee(e,r.left);let o=null,a="";if("VariableDeclaration"===r.left.type){const e=r.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===r.left.type&&(a=r.left.name);if(!a)throw new Error(C(r,"RUNTIME","INVALIDVARIABLE"));if(a=a.toLowerCase(),null!==e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new Error(C(r,"RUNTIME","VARIABLENOTDECLARED"));if(E(n)||m(n)){const t=n.length;for(let n=0;n<t;n++){o.value=n;const t=ee(e,r.body);if(t===p)break;if(t instanceof d)return t}return h}if(g(n)){for(let t=0;t<n.length();t++){o.value=t;const n=ee(e,r.body);if(n===p)break;if(n instanceof d)return n}return h}if(!(n instanceof t||N(n)))return h;{const t=n.keys();for(let n=0;n<t.length;n++){o.value=t[n];const a=ee(e,r.body);if(a===p)break;if(a instanceof d)return a}}}function oe(e,r){null!==r.init&&ee(e,r.init);const t={testResult:!0,lastAction:h};do{ae(e,r,t)}while(!0===t.testResult);return t.lastAction instanceof d?t.lastAction:h}function ae(e,r,t){if(null!==r.test){if(t.testResult=ee(e,r.test),!1===t.testResult)return;if(!0!==t.testResult)throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}t.lastAction=ee(e,r.body),t.lastAction!==p?t.lastAction instanceof d?t.testResult=!1:null!==r.update&&ee(e,r.update):t.testResult=!1}function ie(e,r){let n,o=null,a="";if("MemberExpression"===r.argument.type){if(o=ee(e,r.argument.object),!0===r.argument.computed?a=ee(e,r.argument.property):"Identifier"===r.argument.property.type&&(a=r.argument.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error("Assignment outside of array bounds");n=I(o[a]),o[a]="++"===r.operator?n+1:n-1}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}return!1===r.prefix?n:"++"===r.operator?n+1:n-1}if(o="Identifier"===r.argument.type?r.argument.name.toLowerCase():"",!o)throw new Error("Invalid identifier");if(null!==e.localScope&&void 0!==e.localScope[o])return n=I(e.localScope[o].value),e.localScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=I(e.globalScope[o].value),e.globalScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;throw new Error("Variable not recognised")}function se(e,r,t,n){switch(r){case"=":return e===h?null:e;case"/=":return I(t)/I(e);case"*=":return I(t)*I(e);case"-=":return I(t)-I(e);case"+=":return m(t)||m(e)?T(t)+T(e):I(t)+I(e);case"%=":return I(t)%I(e);default:throw new Error(C(n,"RUNTIME","OPERATORNOTRECOGNISED"))}}function le(e,r){const n=ee(e,r.right);let o=null,a="";if("MemberExpression"===r.left.type){if(o=ee(e,r.left.object),!0===r.left.computed?a=ee(e,r.left.property):"Identifier"===r.left.property.type&&(a=r.left.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>o.length)throw new Error("Assignment outside of array bounds");if(a===o.length){if("="!==r.operator)throw new Error("Invalid Parameter");o[a]=se(n,r.operator,o[a],r)}else o[a]=se(n,r.operator,o[a],r)}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}return h}if(o=r.left.name.toLowerCase(),null!==e.localScope&&void 0!==e.localScope[o])return e.localScope[o]={value:se(n,r.operator,e.localScope[o].value,r),valueset:!0,node:r.right},h;if(void 0!==e.globalScope[o])return e.globalScope[o]={value:se(n,r.operator,e.globalScope[o].value,r),valueset:!0,node:r.right},h;throw new Error("Variable not recognised")}function ce(e,r){if("AssignmentExpression"===r.expression.type||"UpdateExpression"===r.expression.type)return ee(e,r.expression);if("CallExpression"===r.expression.type){const t=ee(e,r.expression);return t===h?h:new v(t)}{const t=ee(e,r.expression);return t===h?h:new v(t)}}function ue(e,r){if("AssignmentExpression"===r.test.type||"UpdateExpression"===r.test.type)throw new Error(C(r.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.test);if(!0===t)return ee(e,r.consequent);if(!1===t)return null!==r.alternate?ee(e,r.alternate):h;throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}function fe(e,r){let t=h;for(let n=0;n<r.body.length;n++)if(t=ee(e,r.body[n]),t instanceof d||t===p||t===f)return t;return t}function pe(e,r){if(null===r.argument)return new d(h);const t=ee(e,r.argument);return new d(t)}function he(e,r){const t=r.id.name.toLowerCase();return e.globalScope[t]={valueset:!0,node:null,value:new o(r,e)},h}function we(e,r){for(let t=0;t<r.declarations.length;t++)ee(e,r.declarations[t]);return h}function me(e,r){let t=null===r.init?null:ee(e,r.init);if(t===h&&(t=null),"Identifier"!==r.id.type)throw new Error("Can only assign a regular variable");const n=r.id.name.toLowerCase();return null!==e.localScope?e.localScope[n]={value:t,valueset:!0,node:r.init}:e.globalScope[n]={value:t,valueset:!0,node:r.init},h}let Ee=0;function de(e,r,n){let o;switch(r=r.toLowerCase()){case"hasz":{const r=e.hasZ;return void 0!==r&&r}case"hasm":{const r=e.hasM;return void 0!==r&&r}case"spatialreference":{let r=e.spatialReference._arcadeCacheId;if(void 0===r){let t=!0;Object.freeze&&Object.isFrozen(e.spatialReference)&&(t=!1),t&&(Ee++,e.spatialReference._arcadeCacheId=Ee,r=Ee)}const n=new t({wkt:e.spatialReference.wkt,wkid:e.spatialReference.wkid});return void 0!==r&&(n._arcadeCacheId="SPREF"+r.toString()),n}}switch(e.type){case"extent":switch(r){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const t=e[r];return void 0!==t?t:null}case"type":return"Extent"}break;case"polygon":switch(r){case"rings":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.rings,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polygon"}break;case"point":switch(r){case"x":case"y":case"z":case"m":return void 0!==e[r]?e[r]:null;case"type":return"Point"}break;case"polyline":switch(r){case"paths":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.paths,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polyline"}break;case"multipoint":switch(r){case"points":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new i(e.points,e.spatialReference,!0===e.hasZ,!0===e.hasM,o,1);case"type":return"Multipoint"}}throw new Error(C(n,"RUNTIME","PROPERTYNOTFOUND"))}function ge(e,r){try{const n=ee(e,r.object);if(null===n)throw new Error(C(r,"RUNTIME","NOTFOUND"));if(!1===r.computed){if("Identifier"===r.property.type){if(n instanceof t||N(n))return n.field(r.property.name);if(n instanceof Z)return de(n,r.property.name,r)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}{let o=ee(e,r.property);if(n instanceof t||N(n)){if(m(o))return n.field(o);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(n instanceof Z){if(m(o))return de(n,o,r);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(E(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(m(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(g(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length()+o),o>=n.length()||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n.get(o)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}}catch(n){throw n}}function Ne(e,r){try{const t=ee(e,r.argument);if(l(t)){if("!"===r.operator)return!t;if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);if("~"===r.operator)return~I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}if("~"===r.operator)return~I(t);if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}catch(t){throw t}}function ye(e,r){try{const t=[];for(let n=0;n<r.elements.length;n++){const o=ee(e,r.elements[n]);if(w(o))throw new Error(C(r,"RUNTIME","FUNCTIONCONTEXTILLEGAL"));o===h?t.push(null):t.push(o)}return t}catch(t){throw t}}function Ie(e,r){try{const t=[ee(e,r.left),ee(e,r.right)],n=t[0],o=t[1];switch(r.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return O(I(n),I(o),r.operator);case"==":return c(n,o);case"!=":return!c(n,o);case"<":case">":case"<=":case">=":return R(n,o,r.operator);case"+":return m(n)||m(o)?T(n)+T(o):I(n)+I(o);case"-":return I(n)-I(o);case"*":return I(n)*I(o);case"/":return I(n)/I(o);case"%":return I(n)%I(o);default:throw new Error(C(r,"RUNTIME","OPERATORNOTRECOGNISED"))}}catch(t){throw t}}function ve(e,r){try{if("AssignmentExpression"===r.left.type||"UpdateExpression"===r.left.type)throw new Error(C(r.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));if("AssignmentExpression"===r.right.type||"UpdateExpression"===r.right.type)throw new Error(C(r.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.left);if(l(t))switch(r.operator){case"||":if(!0===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}case"&&":if(!1===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}default:throw new Error(C(r,"RUNTIME","ONLYORORAND"))}throw new Error(C(r,"RUNTIME","ONLYBOOLEAN"))}catch(t){throw t}}function Te(e,r){return r.value?r.value.cooked:""}function Re(e,r){let t="",n=0;for(const o of r.quasis)if(t+=o.value?o.value.cooked:"",!1===o.tail){t+=r.expressions[n]?T(ee(e,r.expressions[n])):"",n++}return t}function Oe(e,r){let t;try{const n=r.name.toLowerCase();if(null!==e.localScope&&void 0!==e.localScope[n])return t=e.localScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;if(void 0!==e.globalScope[n])return t=e.globalScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;throw new Error(C(r,"RUNTIME","VARIABLENOTFOUND"))}catch(n){throw n}}function Se(e,r){try{if("Identifier"!==r.callee.type)throw new Error(C(r,"RUNTIME","ONLYNODESSUPPORTED"));if(null!==e.localScope&&void 0!==e.localScope[r.callee.name.toLowerCase()]){const t=e.localScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}if(void 0!==e.globalScope[r.callee.name.toLowerCase()]){const t=e.globalScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}throw new Error(C(r,"RUNTIME","NOTFOUND"))}catch(t){throw t}}const be={};function Ae(n){return null==n?"":E(n)||g(n)?"Array":S(n)?"Date":m(n)?"String":l(n)?"Boolean":y(n)?"Number":n instanceof r?"Attachment":n instanceof e?"Portal":n instanceof t?"Dictionary":N(n)?"Feature":n instanceof W?"Point":n instanceof K?"Polygon":n instanceof X?"Polyline":n instanceof H?"Multipoint":n instanceof q?"Extent":w(n)?"Function":b(n)?"FeatureSet":A(n)?"FeatureSetCollection":n===h?"":"number"==typeof n&&isNaN(n)?"Number":"Unrecognised Type"}function Ue(e,r,t,n){try{const o=ee(e,r.arguments[t]);if(c(o,n))return ee(e,r.arguments[t+1]);{const o=r.arguments.length-t;return 1===o?ee(e,r.arguments[t]):2===o?null:3===o?ee(e,r.arguments[t+2]):Ue(e,r,t+2,n)}}catch(o){throw o}}function Ce(e,r,t,n){try{if(!0===n)return ee(e,r.arguments[t+1]);if(3===r.arguments.length-t)return ee(e,r.arguments[t+2]);{const n=ee(e,r.arguments[t+2]);if(!1===l(n))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,t+2,n)}}catch(o){throw o}}function xe(e,r){const t=e.length,n=Math.floor(t/2);return 0===t?[]:1===t?[e[0]]:Me(xe(e.slice(0,n),r),xe(e.slice(n,t),r),r)}function Me(e,r,t){const n=[];for(;e.length>0||r.length>0;)if(e.length>0&&r.length>0){let o=t(e[0],r[0]);isNaN(o)&&(o=0),o<=0?(n.push(e[0]),e=e.slice(1)):(n.push(r[0]),r=r.slice(1))}else e.length>0?(n.push(e[0]),e=e.slice(1)):r.length>0&&(n.push(r[0]),r=r.slice(1));return n}function Fe(e,r,t){try{const n=e.body;if(t.length!==e.params.length)throw new Error("Invalid Parameter calls to function.");for(let a=0;a<t.length;a++)r.localScope[e.params[a].name.toLowerCase()]={value:t[a],valueset:!0,node:null};const o=ee(r,n);if(o instanceof d)return o.value;if(o===p)throw new Error("Cannot Break from a Function");if(o===f)throw new Error("Cannot Continue from a Function");return o instanceof v?o.value:o}catch(n){throw n}}function Pe(e,r,t){return $(e,r,((r,n,o)=>{const a={spatialReference:e.spatialReference,globalScope:e.globalScope,depthCounter:e.depthCounter+1,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(t,a,o)}))}function De(e){const r=function(){const r={spatialReference:e.context.spatialReference,console:e.context.console,lrucache:e.context.lrucache,interceptor:e.context.interceptor,localScope:{},depthCounter:e.context.depthCounter+1,globalScope:e.context.globalScope};if(r.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(e.definition,r,arguments)};return r}k(be,$),z(be,$),Y(be,$),V(be,$),G(be,$),B(be,$),be.typeof=function(e,r){return $(e,r,((e,r,t)=>{s(t,1,1);const n=Ae(t[0]);if("Unrecognised Type"===n)throw new Error("Unrecognised Type");return n}))},be.iif=function(e,r){try{s(null===r.arguments?[]:r.arguments,3,3);const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("IF Function must have a boolean test condition");const n=ee(e,r.arguments[1]),o=ee(e,r.arguments[2]);return!0===t?n:o}catch(t){throw t}},be.decode=function(e,r){try{if(r.arguments.length<2)throw new Error("Missing Parameters");if(2===r.arguments.length)return ee(e,r.arguments[1]);{if((r.arguments.length-1)%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);return Ue(e,r,1,t)}}catch(t){throw t}},be.when=function(e,r){try{if(r.arguments.length<3)throw new Error("Missing Parameters");if(r.arguments.length%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,0,t)}catch(t){throw t}},be.top=function(e,r){return $(e,r,((e,r,t)=>{if(s(t,2,2),E(t[0]))return I(t[1])>=t[0].length?t[0].slice(0):t[0].slice(0,I(t[1]));if(g(t[0]))return I(t[1])>=t[0].length()?t[0].slice(0):t[0].slice(0,I(t[1]));throw new Error("Top cannot accept this parameter type")}))},be.first=function(e,r){return $(e,r,((e,r,t)=>(s(t,1,1),E(t[0])?0===t[0].length?null:t[0][0]:g(t[0])?0===t[0].length()?null:t[0].get(0):null)))},be.sort=function(e,r){return $(e,r,((e,r,t)=>{s(t,1,2);let n=t[0];if(g(n)&&(n=n.toArray()),!1===E(n))throw new Error("Illegal Argument");if(t.length>1){if(!1===w(t[1]))throw new Error("Illegal Argument");let e=n;const r=De(t[1]);return e=xe(e,((e,t)=>r(e,t))),e}{let e=n;if(0===e.length)return[];const r={};for(let n=0;n<e.length;n++){const t=Ae(e[n]);""!==t&&(r[t]=!0)}if(!0===r.Array||!0===r.Dictionary||!0===r.Feature||!0===r.Point||!0===r.Polygon||!0===r.Polyline||!0===r.Multipoint||!0===r.Extent||!0===r.Function)return e.slice(0);let t=0,o="";for(const n in r)t++,o=n;return e=t>1||"String"===o?xe(e,((e,r)=>{if(null==e||e===h)return null==r||r===h?0:1;if(null==r||r===h)return-1;const t=T(e),n=T(r);return t<n?-1:t===n?0:1})):"Number"===o?xe(e,((e,r)=>e-r)):"Boolean"===o?xe(e,((e,r)=>e===r?0:r?-1:1)):"Date"===o?xe(e,((e,r)=>r-e)):e.slice(0),e}}))};for(const We in be)be[We]={value:new u(be[We]),valueset:!0,node:null};const Le=function(){};function je(e,r){const o=new Le;e||(e={}),r||(r={});const a=new t({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const t in r)o[t]={value:new u(r[t]),native:!0,valueset:!0,node:null};for(const t in e)e[t]&&"esri.Graphic"===e[t].declaredClass?o[t]={value:n.createFromGraphic(e[t]),valueset:!0,node:null}:o[t]={value:e[t],valueset:!0,node:null};return o}Le.prototype=be,Le.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Le.prototype.pi={value:Math.PI,valueset:!0,node:null};const _e={fixSpatialReference:U,parseArguments:Q,standardFunction:$};function ke(e){console.log(e)}function Ve(e){const r={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:$,evaluateIdentifier:Oe,arcadeCustomFunctionHandler:De};for(let t=0;t<e.length;t++)e[t].registerFunctions(r);for(const t in r.functions)be[t]={value:new u(r.functions[t]),valueset:!0,node:null},Le.prototype[t]=be[t];for(let t=0;t<r.signatures.length;t++)x(r.signatures[t],"async")}function Be(e,r){let t=r.spatialReference;null==t&&(t=new J({wkid:102100}));let n=ee({spatialReference:t,globalScope:je(r.vars,r.customfunctions),localScope:null,console:r.console?r.console:ke,lrucache:r.lrucache,interceptor:r.interceptor,depthCounter:1},e.body[0].body);if(n instanceof d&&(n=n.value),n instanceof v&&(n=n.value),n===h&&(n=null),n===p)throw new Error("Cannot return BREAK");if(n===f)throw new Error("Cannot return CONTINUE");if(n instanceof o)throw new Error("Cannot return FUNCTION");if(n instanceof u)throw new Error("Cannot return FUNCTION");return n}function Ye(e,r){return M(e)}function Ge(e){return F(e)}function ze(e,r){return P(e,r,"simple")}function qe(e,r){return D(e,r)}function Ze(e,r){return L(e,r)}function He(e){return j(e)}Ve([_]);export{Be as executeScript,Ve as extend,Ge as extractExpectedFieldLiterals,Ye as extractFieldLiterals,He as findFunctionCalls,_e as functionHelper,Ze as referencesFunction,qe as referencesMember,ze as validateScript};
5
+ import e from"./ArcadePortal.js";import r from"./Attachment.js";import t from"./Dictionary.js";import n from"./Feature.js";import o from"./FunctionWrapper.js";import a from"./ImmutablePathArray.js";import i from"./ImmutablePointArray.js";import{p as s,i as l,m as c,N as u,x as f,w as p,v as h,o as w,b as m,l as E,R as d,n as g,s as N,a as y,f as I,I as v,h as T,q as R,r as O,j as S,y as b,z as A,A as U}from"../chunks/languageUtils.js";import{nodeErrorMessage as C,addFunctionDeclaration as x,findFieldLiterals as M,findExpectedFieldLiterals as F,validateScript as P,referencesMember as D,referencesFunction as L,findFunctionCalls as j}from"./treeAnalysis.js";import{A as _}from"../chunks/array.js";import{registerFunctions as k}from"./functions/date.js";import{registerFunctions as V}from"./functions/geometry.js";import{registerFunctions as B}from"./functions/geomsync.js";import{registerFunctions as Y}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as z}from"./functions/string.js";import q from"../geometry/Extent.js";import Z from"../geometry/Geometry.js";import H from"../geometry/Multipoint.js";import W from"../geometry/Point.js";import K from"../geometry/Polygon.js";import X from"../geometry/Polyline.js";import J from"../geometry/SpatialReference.js";function Q(e,r){const t=[];for(let n=0;n<r.arguments.length;n++)t.push(ee(e,r.arguments[n]));return t}function $(e,r,t){try{return!0===r.preparsed?t(e,null,r.arguments):t(e,r,Q(e,r))}catch(n){throw n}}function ee(e,r){try{switch(r.type){case"EmptyStatement":return h;case"VariableDeclarator":return me(e,r);case"VariableDeclaration":return we(e,r);case"BlockStatement":return fe(e,r);case"FunctionDeclaration":return he(e,r);case"ReturnStatement":return pe(e,r);case"IfStatement":return ue(e,r);case"ExpressionStatement":return ce(e,r);case"AssignmentExpression":return le(e,r);case"UpdateExpression":return ie(e,r);case"BreakStatement":return p;case"ContinueStatement":return f;case"TemplateElement":return Te(e,r);case"TemplateLiteral":return Re(e,r);case"ForStatement":return oe(e,r);case"ForInStatement":return ne(e,r);case"Identifier":return Oe(e,r);case"MemberExpression":return ge(e,r);case"Literal":return r.value;case"CallExpression":return Se(e,r);case"UnaryExpression":return Ne(e,r);case"BinaryExpression":return Ie(e,r);case"LogicalExpression":return ve(e,r);case"ArrayExpression":return ye(e,r);case"ObjectExpression":return re(e,r);case"Property":return te(e,r);default:throw new Error(C(r,"RUNTIME","UNREOGNISED"))}}catch(t){throw t}}function re(e,r){const n={};for(let t=0;t<r.properties.length;t++){const o=ee(e,r.properties[t]);if(w(o.value))throw new Error("Illegal Argument");if(!1===m(o.key))throw new Error("Illegal Argument");o.value===h?n[o.key.toString()]=null:n[o.key.toString()]=o.value}const o=new t(n);return o.immutable=!1,o}function te(e,r){return{key:"Identifier"===r.key.type?r.key.name:ee(e,r.key),value:ee(e,r.value)}}function ne(e,r){const n=ee(e,r.right);"VariableDeclaration"===r.left.type&&ee(e,r.left);let o=null,a="";if("VariableDeclaration"===r.left.type){const e=r.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===r.left.type&&(a=r.left.name);if(!a)throw new Error(C(r,"RUNTIME","INVALIDVARIABLE"));if(a=a.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new Error(C(r,"RUNTIME","VARIABLENOTDECLARED"));if(E(n)||m(n)){const t=n.length;for(let n=0;n<t;n++){o.value=n;const t=ee(e,r.body);if(t===p)break;if(t instanceof d)return t}return h}if(g(n)){for(let t=0;t<n.length();t++){o.value=t;const n=ee(e,r.body);if(n===p)break;if(n instanceof d)return n}return h}if(!(n instanceof t||N(n)))return h;{const t=n.keys();for(let n=0;n<t.length;n++){o.value=t[n];const a=ee(e,r.body);if(a===p)break;if(a instanceof d)return a}}}function oe(e,r){null!==r.init&&ee(e,r.init);const t={testResult:!0,lastAction:h};do{ae(e,r,t)}while(!0===t.testResult);return t.lastAction instanceof d?t.lastAction:h}function ae(e,r,t){if(null!==r.test){if(t.testResult=ee(e,r.test),!1===t.testResult)return;if(!0!==t.testResult)throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}t.lastAction=ee(e,r.body),t.lastAction!==p?t.lastAction instanceof d?t.testResult=!1:null!==r.update&&ee(e,r.update):t.testResult=!1}function ie(e,r){let n,o=null,a="";if("MemberExpression"===r.argument.type){if(o=ee(e,r.argument.object),!0===r.argument.computed?a=ee(e,r.argument.property):"Identifier"===r.argument.property.type&&(a=r.argument.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error("Assignment outside of array bounds");n=I(o[a]),o[a]="++"===r.operator?n+1:n-1}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}return!1===r.prefix?n:"++"===r.operator?n+1:n-1}if(o="Identifier"===r.argument.type?r.argument.name.toLowerCase():"",!o)throw new Error("Invalid identifier");if(null!=e.localScope&&void 0!==e.localScope[o])return n=I(e.localScope[o].value),e.localScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=I(e.globalScope[o].value),e.globalScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;throw new Error("Variable not recognised")}function se(e,r,t,n){switch(r){case"=":return e===h?null:e;case"/=":return I(t)/I(e);case"*=":return I(t)*I(e);case"-=":return I(t)-I(e);case"+=":return m(t)||m(e)?T(t)+T(e):I(t)+I(e);case"%=":return I(t)%I(e);default:throw new Error(C(n,"RUNTIME","OPERATORNOTRECOGNISED"))}}function le(e,r){const n=ee(e,r.right);let o=null,a="";if("MemberExpression"===r.left?.type){if(o=ee(e,r.left.object),!0===r.left.computed?a=ee(e,r.left.property):"Identifier"===r.left.property.type&&(a=r.left.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>o.length)throw new Error("Assignment outside of array bounds");if(a===o.length){if("="!==r.operator)throw new Error("Invalid Parameter");o[a]=se(n,r.operator,o[a],r)}else o[a]=se(n,r.operator,o[a],r)}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}return h}if(o=r.left.name.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[o])return e.localScope[o]={value:se(n,r.operator,e.localScope[o].value,r),valueset:!0,node:r.right},h;if(void 0!==e.globalScope[o])return e.globalScope[o]={value:se(n,r.operator,e.globalScope[o].value,r),valueset:!0,node:r.right},h;throw new Error("Variable not recognised")}function ce(e,r){if("AssignmentExpression"===r.expression.type||"UpdateExpression"===r.expression.type)return ee(e,r.expression);if("CallExpression"===r.expression.type){const t=ee(e,r.expression);return t===h?h:new v(t)}{const t=ee(e,r.expression);return t===h?h:new v(t)}}function ue(e,r){if("AssignmentExpression"===r.test.type||"UpdateExpression"===r.test.type)throw new Error(C(r.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.test);if(!0===t)return ee(e,r.consequent);if(!1===t)return null!==r.alternate?ee(e,r.alternate):h;throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}function fe(e,r){let t=h;for(let n=0;n<r.body.length;n++)if(t=ee(e,r.body[n]),t instanceof d||t===p||t===f)return t;return t}function pe(e,r){if(null===r.argument)return new d(h);const t=ee(e,r.argument);return new d(t)}function he(e,r){const t=r.id.name.toLowerCase();return e.globalScope[t]={valueset:!0,node:null,value:new o(r,e)},h}function we(e,r){for(let t=0;t<r.declarations.length;t++)ee(e,r.declarations[t]);return h}function me(e,r){let t=null===r.init?null:ee(e,r.init);if(t===h&&(t=null),"Identifier"!==r.id.type)throw new Error("Can only assign a regular variable");const n=r.id.name.toLowerCase();return null!=e.localScope?e.localScope[n]={value:t,valueset:!0,node:r.init}:e.globalScope[n]={value:t,valueset:!0,node:r.init},h}let Ee=0;function de(e,r,n){let o;switch(r=r.toLowerCase()){case"hasz":{const r=e.hasZ;return void 0!==r&&r}case"hasm":{const r=e.hasM;return void 0!==r&&r}case"spatialreference":{let r=e.spatialReference._arcadeCacheId;if(void 0===r){let t=!0;Object.freeze&&Object.isFrozen(e.spatialReference)&&(t=!1),t&&(Ee++,e.spatialReference._arcadeCacheId=Ee,r=Ee)}const n=new t({wkt:e.spatialReference.wkt,wkid:e.spatialReference.wkid});return void 0!==r&&(n._arcadeCacheId="SPREF"+r.toString()),n}}switch(e.type){case"extent":switch(r){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const t=e[r];return void 0!==t?t:null}case"type":return"Extent"}break;case"polygon":switch(r){case"rings":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.rings,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polygon"}break;case"point":switch(r){case"x":case"y":case"z":case"m":return void 0!==e[r]?e[r]:null;case"type":return"Point"}break;case"polyline":switch(r){case"paths":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.paths,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polyline"}break;case"multipoint":switch(r){case"points":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new i(e.points,e.spatialReference,!0===e.hasZ,!0===e.hasM,o,1);case"type":return"Multipoint"}}throw new Error(C(n,"RUNTIME","PROPERTYNOTFOUND"))}function ge(e,r){try{const n=ee(e,r.object);if(null===n)throw new Error(C(r,"RUNTIME","NOTFOUND"));if(!1===r.computed){if("Identifier"===r.property?.type){if(n instanceof t||N(n))return n.field(r.property.name);if(n instanceof Z)return de(n,r.property.name,r)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}{let o=ee(e,r.property);if(n instanceof t||N(n)){if(m(o))return n.field(o);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(n instanceof Z){if(m(o))return de(n,o,r);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(E(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(m(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(g(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length()+o),o>=n.length()||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n.get(o)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}}catch(n){throw n}}function Ne(e,r){try{const t=ee(e,r.argument);if(l(t)){if("!"===r.operator)return!t;if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);if("~"===r.operator)return~I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}if("~"===r.operator)return~I(t);if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}catch(t){throw t}}function ye(e,r){try{const t=[];for(let n=0;n<r.elements.length;n++){const o=ee(e,r.elements[n]);if(w(o))throw new Error(C(r,"RUNTIME","FUNCTIONCONTEXTILLEGAL"));o===h?t.push(null):t.push(o)}return t}catch(t){throw t}}function Ie(e,r){try{const t=[ee(e,r.left),ee(e,r.right)],n=t[0],o=t[1];switch(r.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return O(I(n),I(o),r.operator);case"==":return c(n,o);case"!=":return!c(n,o);case"<":case">":case"<=":case">=":return R(n,o,r.operator);case"+":return m(n)||m(o)?T(n)+T(o):I(n)+I(o);case"-":return I(n)-I(o);case"*":return I(n)*I(o);case"/":return I(n)/I(o);case"%":return I(n)%I(o);default:throw new Error(C(r,"RUNTIME","OPERATORNOTRECOGNISED"))}}catch(t){throw t}}function ve(e,r){try{if("AssignmentExpression"===r.left?.type||"UpdateExpression"===r.left?.type)throw new Error(C(r.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));if("AssignmentExpression"===r.right?.type||"UpdateExpression"===r.right?.type)throw new Error(C(r.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.left);if(l(t))switch(r.operator){case"||":if(!0===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}case"&&":if(!1===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}default:throw new Error(C(r,"RUNTIME","ONLYORORAND"))}throw new Error(C(r,"RUNTIME","ONLYBOOLEAN"))}catch(t){throw t}}function Te(e,r){return r.value?r.value.cooked:""}function Re(e,r){let t="",n=0;for(const o of r.quasis)if(t+=o.value?o.value.cooked:"",!1===o.tail){t+=r.expressions[n]?T(ee(e,r.expressions[n])):"",n++}return t}function Oe(e,r){let t;try{const n=r.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n])return t=e.localScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;if(void 0!==e.globalScope[n])return t=e.globalScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;throw new Error(C(r,"RUNTIME","VARIABLENOTFOUND"))}catch(n){throw n}}function Se(e,r){try{if("Identifier"!==r.callee.type)throw new Error(C(r,"RUNTIME","ONLYNODESSUPPORTED"));if(null!=e.localScope&&void 0!==e.localScope[r.callee.name.toLowerCase()]){const t=e.localScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}if(void 0!==e.globalScope[r.callee.name.toLowerCase()]){const t=e.globalScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}throw new Error(C(r,"RUNTIME","NOTFOUND"))}catch(t){throw t}}const be={};function Ae(n){return null==n?"":E(n)||g(n)?"Array":S(n)?"Date":m(n)?"String":l(n)?"Boolean":y(n)?"Number":n instanceof r?"Attachment":n instanceof e?"Portal":n instanceof t?"Dictionary":N(n)?"Feature":n instanceof W?"Point":n instanceof K?"Polygon":n instanceof X?"Polyline":n instanceof H?"Multipoint":n instanceof q?"Extent":w(n)?"Function":b(n)?"FeatureSet":A(n)?"FeatureSetCollection":n===h?"":"number"==typeof n&&isNaN(n)?"Number":"Unrecognised Type"}function Ue(e,r,t,n){try{const o=ee(e,r.arguments[t]);if(c(o,n))return ee(e,r.arguments[t+1]);{const o=r.arguments.length-t;return 1===o?ee(e,r.arguments[t]):2===o?null:3===o?ee(e,r.arguments[t+2]):Ue(e,r,t+2,n)}}catch(o){throw o}}function Ce(e,r,t,n){try{if(!0===n)return ee(e,r.arguments[t+1]);if(3===r.arguments.length-t)return ee(e,r.arguments[t+2]);{const n=ee(e,r.arguments[t+2]);if(!1===l(n))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,t+2,n)}}catch(o){throw o}}function xe(e,r){const t=e.length,n=Math.floor(t/2);return 0===t?[]:1===t?[e[0]]:Me(xe(e.slice(0,n),r),xe(e.slice(n,t),r),r)}function Me(e,r,t){const n=[];for(;e.length>0||r.length>0;)if(e.length>0&&r.length>0){let o=t(e[0],r[0]);isNaN(o)&&(o=0),o<=0?(n.push(e[0]),e=e.slice(1)):(n.push(r[0]),r=r.slice(1))}else e.length>0?(n.push(e[0]),e=e.slice(1)):r.length>0&&(n.push(r[0]),r=r.slice(1));return n}function Fe(e,r,t){try{const n=e.body;if(t.length!==e.params.length)throw new Error("Invalid Parameter calls to function.");for(let a=0;a<t.length;a++)r.localScope[e.params[a].name.toLowerCase()]={value:t[a],valueset:!0,node:null};const o=ee(r,n);if(o instanceof d)return o.value;if(o===p)throw new Error("Cannot Break from a Function");if(o===f)throw new Error("Cannot Continue from a Function");return o instanceof v?o.value:o}catch(n){throw n}}function Pe(e,r,t){return $(e,r,((r,n,o)=>{const a={spatialReference:e.spatialReference,globalScope:e.globalScope,depthCounter:e.depthCounter+1,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(t,a,o)}))}function De(e){const r=function(){const r={spatialReference:e.context.spatialReference,console:e.context.console,lrucache:e.context.lrucache,interceptor:e.context.interceptor,localScope:{},depthCounter:e.context.depthCounter+1,globalScope:e.context.globalScope};if(r.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(e.definition,r,arguments)};return r}k(be,$),z(be,$),Y(be,$),V(be,$),G(be,$),B(be,$),be.typeof=function(e,r){return $(e,r,((e,r,t)=>{s(t,1,1);const n=Ae(t[0]);if("Unrecognised Type"===n)throw new Error("Unrecognised Type");return n}))},be.iif=function(e,r){try{s(null===r.arguments?[]:r.arguments,3,3);const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("IF Function must have a boolean test condition");const n=ee(e,r.arguments[1]),o=ee(e,r.arguments[2]);return!0===t?n:o}catch(t){throw t}},be.decode=function(e,r){try{if(r.arguments.length<2)throw new Error("Missing Parameters");if(2===r.arguments.length)return ee(e,r.arguments[1]);{if((r.arguments.length-1)%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);return Ue(e,r,1,t)}}catch(t){throw t}},be.when=function(e,r){try{if(r.arguments.length<3)throw new Error("Missing Parameters");if(r.arguments.length%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,0,t)}catch(t){throw t}},be.top=function(e,r){return $(e,r,((e,r,t)=>{if(s(t,2,2),E(t[0]))return I(t[1])>=t[0].length?t[0].slice(0):t[0].slice(0,I(t[1]));if(g(t[0]))return I(t[1])>=t[0].length()?t[0].slice(0):t[0].slice(0,I(t[1]));throw new Error("Top cannot accept this parameter type")}))},be.first=function(e,r){return $(e,r,((e,r,t)=>(s(t,1,1),E(t[0])?0===t[0].length?null:t[0][0]:g(t[0])?0===t[0].length()?null:t[0].get(0):null)))},be.sort=function(e,r){return $(e,r,((e,r,t)=>{s(t,1,2);let n=t[0];if(g(n)&&(n=n.toArray()),!1===E(n))throw new Error("Illegal Argument");if(t.length>1){if(!1===w(t[1]))throw new Error("Illegal Argument");let e=n;const r=De(t[1]);return e=xe(e,((e,t)=>r(e,t))),e}{let e=n;if(0===e.length)return[];const r={};for(let n=0;n<e.length;n++){const t=Ae(e[n]);""!==t&&(r[t]=!0)}if(!0===r.Array||!0===r.Dictionary||!0===r.Feature||!0===r.Point||!0===r.Polygon||!0===r.Polyline||!0===r.Multipoint||!0===r.Extent||!0===r.Function)return e.slice(0);let t=0,o="";for(const n in r)t++,o=n;return e=t>1||"String"===o?xe(e,((e,r)=>{if(null==e||e===h)return null==r||r===h?0:1;if(null==r||r===h)return-1;const t=T(e),n=T(r);return t<n?-1:t===n?0:1})):"Number"===o?xe(e,((e,r)=>e-r)):"Boolean"===o?xe(e,((e,r)=>e===r?0:r?-1:1)):"Date"===o?xe(e,((e,r)=>r-e)):e.slice(0),e}}))};for(const We in be)be[We]={value:new u(be[We]),valueset:!0,node:null};const Le=function(){};function je(e,r){const o=new Le;e||(e={}),r||(r={});const a=new t({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const t in r)o[t]={value:new u(r[t]),native:!0,valueset:!0,node:null};for(const t in e)e[t]&&"esri.Graphic"===e[t].declaredClass?o[t]={value:n.createFromGraphic(e[t]),valueset:!0,node:null}:o[t]={value:e[t],valueset:!0,node:null};return o}Le.prototype=be,Le.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Le.prototype.pi={value:Math.PI,valueset:!0,node:null};const _e={fixSpatialReference:U,parseArguments:Q,standardFunction:$};function ke(e){console.log(e)}function Ve(e){const r={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:$,evaluateIdentifier:Oe,arcadeCustomFunctionHandler:De};for(let t=0;t<e.length;t++)e[t].registerFunctions(r);for(const t in r.functions)be[t]={value:new u(r.functions[t]),valueset:!0,node:null},Le.prototype[t]=be[t];for(let t=0;t<r.signatures.length;t++)x(r.signatures[t],"async")}function Be(e,r){let t=r.spatialReference;null==t&&(t=new J({wkid:102100}));let n=ee({spatialReference:t,globalScope:je(r.vars,r.customfunctions),localScope:null,console:r.console?r.console:ke,lrucache:r.lrucache,interceptor:r.interceptor,depthCounter:1},e.body[0].body);if(n instanceof d&&(n=n.value),n instanceof v&&(n=n.value),n===h&&(n=null),n===p)throw new Error("Cannot return BREAK");if(n===f)throw new Error("Cannot return CONTINUE");if(n instanceof o)throw new Error("Cannot return FUNCTION");if(n instanceof u)throw new Error("Cannot return FUNCTION");return n}function Ye(e,r){return M(e)}function Ge(e){return F(e)}function ze(e,r){return P(e,r,"simple")}function qe(e,r){return D(e,r)}function Ze(e,r){return L(e,r)}function He(e){return j(e)}Ve([_]);export{Be as executeScript,Ve as extend,Ge as extractExpectedFieldLiterals,Ye as extractFieldLiterals,He as findFunctionCalls,_e as functionHelper,Ze as referencesFunction,qe as referencesMember,ze as validateScript};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{cloneField as a,FeatureServiceDatabaseType as i,layerGeometryEsriConstants as l}from"../support/shared.js";import{reformulateWithoutField as n,toWhereClause as o,translateFunctionToDatabaseSpecific as h,makeToday as u,makeDateString as c,convertIntervalToSql as d,combine as p,scanForField as f}from"../support/sqlUtils.js";import{WhereClause as g}from"../../../core/sql/WhereClause.js";import _ from"../../../geometry/SpatialReference.js";class N{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class S extends N{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class w extends N{constructor(e,t,r){super(a(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:n(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class m extends N{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,i.Standardised,this.field.name,this.codefield instanceof g?o(this.codefield,i.Standardised):this.codefield,e.parameters);return r.includes(m.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:g.create(r,t._parent.getFieldsIndex())}}evaluateNodeToWhereClause(e,t,r=null,s=null,a){let i,l,n,o;switch(e.type){case"interval":return d(this.evaluateNodeToWhereClause(e.value,t,r,s,a),e.qualifier,e.op);case"case-expression":{let s=" CASE ";"simple"===e.format&&(s+=this.evaluateNodeToWhereClause(e.operand,t,r,m.BADNESS,a));for(let i=0;i<e.clauses.length;i++)s+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[i].operand,t,r,m.BADNESS,a)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[i].value,t,r,m.BADNESS,a);return null!==e.else&&(s+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,r,m.BADNESS,a)),s+=" END ",s}case"parameter":{const r=a[e.value.toLowerCase()];if("string"==typeof r){return"'"+a[e.value.toLowerCase()].toString().replace(/'/g,"''")+"'"}if(r instanceof Date)return c(r,t);if(r instanceof Array){const e=[];for(let s=0;s<r.length;s++)"string"==typeof r[s]?e.push("'"+r[s].toString().replace(/'/g,"''")+"'"):r[s]instanceof Date?e.push(c(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":l=[];for(const i of e.value)l.push(this.evaluateNodeToWhereClause(i,t,r,s,a));return l;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,r,m.BADNESS,a)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" AND "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" OR "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"IS":if("null"!==e.right.type)throw new Error("Unsupported RHS for IS");return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new Error("Unsupported RHS for IS");return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NOT NULL )";case"IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,t,r,s,a),o instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+o.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+o+")) ";case"NOT IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,t,r,s,a),o instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+o.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+o+")) ";case"BETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"NOTBETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+s+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+s+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replace(/'/g,"''")+"'";case"timestamp":case"date":return c(e.value,t);case"number":return e.value.toString();case"current-time":return u("date"===e.mode,t);case"column-reference":return r&&r.toLowerCase()===e.column.toLowerCase()?"("+s+")":e.column;case"function":{const s=this.evaluateNodeToWhereClause(e.args,t,r,m.BADNESS,a);return h(e.name,s,t)}}throw new Error("Unsupported sql syntax "+e.type)}extractValue(e){return this.codefield instanceof g?this.reverseLkp[this.codefield.calculateValueCompiled(e)]:this.reverseLkp[e.attributes[this.codefield]]}}m.BADNESS="_!!!_BAD_LKP_!!!!";class v extends N{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:n(e,this.field.name,o(this._sql,i.Standardised),t.getFieldsIndex())}}extractValue(e){return this._sql.calculateValueCompiled(e)}}class C extends r{constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=null,this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}_initialiseFeatureSet(){null!==this._parent?(this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.spatialReference=new _({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=l.point,this.typeIdField="",this.types=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await this._parent._getSet(e),this._checkCancelled(e),this._wset=new s(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(r,a,i,l){const n=[];-1!==a&&void 0===this._featureCache[a]&&n.push(a);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,l),this._getFeatures(r,a,i,l);let h=0;for(let e=r._lastFetchedIndex;e<r._known.length&&(h++,h<=i&&(r._lastFetchedIndex+=1),!(void 0===this._featureCache[r._known[e]]&&(r._known[e]!==a&&n.push(r._known[e]),n.length>=o)));e++);if(0===n.length)return"success";r=new s([],n,r._ordered,null);const u=Math.min(n.length,i);await this._parent._getFeatures(r,-1,u,l),this._checkCancelled(l);const c=[];for(let e=0;e<u;e++){const t=this._parent._featureFromCache(n[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:n[e]})}for(const s of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(s);this._featureCache[s.id]=new e({attributes:r,geometry:t(s.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new Error("Fetch and Refine should not be called in this featureset")}async _getFilteredSet(e,t,r,a,i){let l=!1;const n=this._reformulateWithoutAdaptions(r);l=n.cannot,r=n.where;let o=!1;if(null!==a){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof S)&&!0===a.scanForField(t.field.name)){if(!(t instanceof w)){a=null,o=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}a&&e.length>0&&(a=a.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=p(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const h=await this._parent._getFilteredSet(e,t,r,a,i);let u;return this._checkCancelled(i),u=!0===l?new s(h._candidates.slice(0).concat(h._known.slice(0)),[],!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)):new s(h._candidates.slice(0),h._known.slice(0),!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)),u}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===f(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const h=await this._parent._stat(e,t,r,s,a,i,l);return!1===h.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:h}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof S))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,a,i,l){if(null===this._parent)throw new Error("Should never be called");const n=[];for(let h=0;h<t.length;h++){const e=t[h];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new Error("Should never be called");const r=e.clone();r.workingexpr=t.where,n.push(r)}else n.push(e)}const o=this._reformulateWithoutAdaptions(a);if(o.cannot)throw new Error("Should never be called");return null!==(a=o.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,n,r,s,a,i,l)}}export{C as AdaptedFeatureSet,N as AdaptedField,w as FieldRename,S as OriginalField,v as SqlExpressionAdapted,m as StringToCodeAdapted};
5
+ import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{cloneField as a,FeatureServiceDatabaseType as i,layerGeometryEsriConstants as l}from"../support/shared.js";import{reformulateWithoutField as n,toWhereClause as o,translateFunctionToDatabaseSpecific as h,makeToday as u,makeDateString as c,convertIntervalToSql as d,combine as p,scanForField as f}from"../support/sqlUtils.js";import{WhereClause as g}from"../../../core/sql/WhereClause.js";import _ from"../../../geometry/SpatialReference.js";class N{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class S extends N{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return this.field.name?e.attributes[this.field.name]:void 0}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class w extends N{constructor(e,t,r){super(a(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:n(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class m extends N{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,i.Standardised,this.field.name,this.codefield instanceof g?o(this.codefield,i.Standardised):this.codefield,e.parameters);return r.includes(m.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:g.create(r,t._parent.getFieldsIndex())}}evaluateNodeToWhereClause(e,t,r=null,s=null,a){let i,l,n,o;switch(e.type){case"interval":return d(this.evaluateNodeToWhereClause(e.value,t,r,s,a),e.qualifier,e.op);case"case-expression":{let s=" CASE ";"simple"===e.format&&(s+=this.evaluateNodeToWhereClause(e.operand,t,r,m.BADNESS,a));for(let i=0;i<e.clauses.length;i++)s+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[i].operand,t,r,m.BADNESS,a)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[i].value,t,r,m.BADNESS,a);return null!==e.else&&(s+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,r,m.BADNESS,a)),s+=" END ",s}case"parameter":{const r=a[e.value.toLowerCase()];if("string"==typeof r){return"'"+a[e.value.toLowerCase()].toString().replace(/'/g,"''")+"'"}if(r instanceof Date)return c(r,t);if(r instanceof Array){const e=[];for(let s=0;s<r.length;s++)"string"==typeof r[s]?e.push("'"+r[s].toString().replace(/'/g,"''")+"'"):r[s]instanceof Date?e.push(c(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":l=[];for(const i of e.value)l.push(this.evaluateNodeToWhereClause(i,t,r,s,a));return l;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,r,m.BADNESS,a)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" AND "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" OR "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"IS":if("null"!==e.right.type)throw new Error("Unsupported RHS for IS");return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new Error("Unsupported RHS for IS");return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NOT NULL )";case"IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp?.[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,t,r,s,a),o instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+o.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+o+")) ";case"NOT IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,t,r,s,a),o instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+o.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+o+")) ";case"BETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"NOTBETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+s+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+s+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,m.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,m.BADNESS,a)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replace(/'/g,"''")+"'";case"timestamp":case"date":return c(e.value,t);case"number":return e.value.toString();case"current-time":return u("date"===e.mode,t);case"column-reference":return r&&r.toLowerCase()===e.column.toLowerCase()?"("+s+")":e.column;case"function":{const s=this.evaluateNodeToWhereClause(e.args,t,r,m.BADNESS,a);return h(e.name,s,t)}}throw new Error("Unsupported sql syntax "+e.type)}extractValue(e){return this.codefield instanceof g?this.reverseLkp[this.codefield.calculateValueCompiled(e)]:this.reverseLkp[e.attributes[this.codefield]]}}m.BADNESS="_!!!_BAD_LKP_!!!!";class v extends N{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:n(e,this.field.name,o(this._sql,i.Standardised),t.getFieldsIndex())}}extractValue(e){return this._sql.calculateValueCompiled(e)}}class C extends r{constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=null,this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}_initialiseFeatureSet(){null!==this._parent?(this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.spatialReference=new _({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=l.point,this.typeIdField="",this.types=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await this._parent._getSet(e),this._checkCancelled(e),this._wset=new s(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(r,a,i,l){const n=[];-1!==a&&void 0===this._featureCache[a]&&n.push(a);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,l),this._getFeatures(r,a,i,l);let h=0;for(let e=r._lastFetchedIndex;e<r._known.length&&(h++,h<=i&&(r._lastFetchedIndex+=1),!(void 0===this._featureCache[r._known[e]]&&(r._known[e]!==a&&n.push(r._known[e]),n.length>=o)));e++);if(0===n.length)return"success";r=new s([],n,r._ordered,null);const u=Math.min(n.length,i);await this._parent._getFeatures(r,-1,u,l),this._checkCancelled(l);const c=[];for(let e=0;e<u;e++){const t=this._parent._featureFromCache(n[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:n[e]})}for(const s of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(s);this._featureCache[s.id]=new e({attributes:r,geometry:t(s.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new Error("Fetch and Refine should not be called in this featureset")}async _getFilteredSet(e,t,r,a,i){let l=!1;const n=this._reformulateWithoutAdaptions(r);l=n.cannot,r=n.where;let o=!1;if(null!==a){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof S)&&!0===a.scanForField(t.field.name)){if(!(t instanceof w)){a=null,o=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}a&&e.length>0&&(a=a.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=p(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const h=await this._parent._getFilteredSet(e,t,r,a,i);let u;return this._checkCancelled(i),u=!0===l?new s(h._candidates.slice(0).concat(h._known.slice(0)),[],!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)):new s(h._candidates.slice(0),h._known.slice(0),!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)),u}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!=e)for(const r of this.adaptedFields)if(!0===f(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const h=await this._parent._stat(e,t,r,s,a,i,l);return!1===h.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:h}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof S))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,a,i,l){if(null===this._parent)throw new Error("Should never be called");const n=[];for(let h=0;h<t.length;h++){const e=t[h];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new Error("Should never be called");const r=e.clone();r.workingexpr=t.where,n.push(r)}else n.push(e)}const o=this._reformulateWithoutAdaptions(a);if(o.cannot)throw new Error("Should never be called");return null!==(a=o.where)?null!==this._extraFilter&&(a=p(this._extraFilter,a)):a=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,n,r,s,a,i,l)}}export{C as AdaptedFeatureSet,N as AdaptedField,w as FieldRename,S as OriginalField,v as SqlExpressionAdapted,m as StringToCodeAdapted};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"../support/FeatureSet.js";import t from"../support/IdSet.js";import{layerGeometryEsriConstants as s,IdState as i}from"../support/shared.js";import{combine as r}from"../support/sqlUtils.js";import{isPromiseLike as n}from"../../../core/promiseUtils.js";import{WhereClause as a}from"../../../core/sql/WhereClause.js";import l from"../../../geometry/SpatialReference.js";class h extends e{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.actions.AttributeFilter",this._maxProcessing=1e3,this._parent=e.parentfeatureset,e.whereclause instanceof a?(this._whereclause=e.whereclause,this._whereClauseFunction=null):(this._whereClauseFunction=e.whereclause,this._whereclause=null)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.fields=[],this.typeIdField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new l({wkid:4326}),this.geometryType=s.point)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const s=await this._parent._getFilteredSet("",null,this._whereclause,null,e);return this._checkCancelled(e),null!==this._whereClauseFunction?this._wset=new t(s._candidates.slice(0).concat(s._known.slice(0)),[],s._ordered,this._clonePageDefinition(s.pagesDefinition)):this._wset=new t(s._candidates.slice(0),s._known.slice(0),s._ordered,this._clonePageDefinition(s.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent._isInFeatureSet(e);return t===i.NotInFeatureSet?t:(t=this._idstates[e],void 0===t?i.Unknown:t)}_getFeature(e,t,s){return this._parent._getFeature(e,t,s)}_getFeatures(e,t,s,i){return this._parent._getFeatures(e,t,s,i)}_featureFromCache(e){return this._parent._featureFromCache(e)}executeWhereClause(e){return this._whereclause.testFeature(e)}async executeWhereClauseDeferred(e){if(null!==this._whereClauseFunction){const t=this._whereClauseFunction(e);return n(t),t}return this.executeWhereClause(e)}async _fetchAndRefineFeatures(e,s,r){const n=new t([],e,!1,null),a=Math.min(s,e.length);if(await this._parent._getFeatures(n,-1,a,r),this._checkCancelled(r),null==this._whereClauseFunction){for(let t=0;t<a;t++){const s=this._parent._featureFromCache(e[t]);!0===this.executeWhereClause(s)?this._idstates[e[t]]=i.InFeatureSet:this._idstates[e[t]]=i.NotInFeatureSet}return"success"}const l=[];for(let t=0;t<a;t++){const s=this._parent._featureFromCache(e[t]);l.push(await this.executeWhereClauseDeferred(s))}for(let t=0;t<s;t++)!0===l[t]?this._idstates[e[t]]=i.InFeatureSet:this._idstates[e[t]]=i.NotInFeatureSet;return"success"}async _getFilteredSet(e,s,i,n,a){null!==this._whereClauseFunction||(null!==i?null!==this._whereclause&&(i=r(this._whereclause,i)):i=this._whereclause),await this._ensureLoaded();const l=await this._parent._getFilteredSet(e,s,i,n,a);let h;return this._checkCancelled(a),h=null!==this._whereClauseFunction?new t(l._candidates.slice(0).concat(l._known.slice(0)),[],l._ordered,this._clonePageDefinition(l.pagesDefinition)):new t(l._candidates.slice(0),l._known.slice(0),l._ordered,this._clonePageDefinition(l.pagesDefinition)),h}async _stat(e,t,s,i,n,a,l){if(null!==this._whereClauseFunction)return null===n&&""===s&&null===i?this._manualStat(e,t,a,l):{calculated:!1};let h=this._whereclause;null!==n&&null!==this._whereclause&&(h=r(this._whereclause,n));const u=await this._parent._stat(e,t,s,i,h,a,l);return!1===u.calculated?null===n&&""===s&&null===i?this._manualStat(e,t,a,l):{calculated:!1}:u}async _canDoAggregates(e,t,s,i,n){return null===this._whereClauseFunction&&(null!==n?null!==this._whereclause&&(n=r(this._whereclause,n)):n=this._whereclause,null!==this._parent&&this._parent._canDoAggregates(e,t,s,i,n))}async _getAggregatePagesDataSourceDefinition(e,t,s,i,n,a,l){if(null===this._parent)throw new Error("Should never be called");return null!==n?null!==this._whereclause&&(n=r(this._whereclause,n)):n=this._whereclause,this._parent._getAggregatePagesDataSourceDefinition(e,t,s,i,n,a,l)}static registerAction(){e._featuresetFunctions.filter=function(e){if("function"==typeof e)return new h({parentfeatureset:this,whereclause:e});let t=null;return e instanceof a&&(t=e),new h({parentfeatureset:this,whereclause:t})}}}export{h as default};
5
+ import e from"../support/FeatureSet.js";import t from"../support/IdSet.js";import{layerGeometryEsriConstants as s,IdState as i}from"../support/shared.js";import{combine as r}from"../support/sqlUtils.js";import{isPromiseLike as n}from"../../../core/promiseUtils.js";import{WhereClause as a}from"../../../core/sql/WhereClause.js";import l from"../../../geometry/SpatialReference.js";class h extends e{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.actions.AttributeFilter",this._maxProcessing=1e3,this._parent=e.parentfeatureset,e.whereclause instanceof a?(this._whereclause=e.whereclause,this._whereClauseFunction=null):(this._whereClauseFunction=e.whereclause,this._whereclause=null)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.fields=[],this.typeIdField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new l({wkid:4326}),this.geometryType=s.point)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const s=await this._parent._getFilteredSet("",null,this._whereclause,null,e);return this._checkCancelled(e),null!==this._whereClauseFunction?this._wset=new t(s._candidates.slice(0).concat(s._known.slice(0)),[],s._ordered,this._clonePageDefinition(s.pagesDefinition)):this._wset=new t(s._candidates.slice(0),s._known.slice(0),s._ordered,this._clonePageDefinition(s.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent._isInFeatureSet(e);return t===i.NotInFeatureSet?t:(t=this._idstates[e],void 0===t?i.Unknown:t)}_getFeature(e,t,s){return this._parent._getFeature(e,t,s)}_getFeatures(e,t,s,i){return this._parent._getFeatures(e,t,s,i)}_featureFromCache(e){return this._parent._featureFromCache(e)}executeWhereClause(e){return this._whereclause?.testFeature(e)??!1}async executeWhereClauseDeferred(e){if(null!==this._whereClauseFunction){const t=this._whereClauseFunction(e);return n(t),t}return this.executeWhereClause(e)}async _fetchAndRefineFeatures(e,s,r){const n=new t([],e,!1,null),a=Math.min(s,e.length);if(await this._parent._getFeatures(n,-1,a,r),this._checkCancelled(r),null==this._whereClauseFunction){for(let t=0;t<a;t++){const s=this._parent._featureFromCache(e[t]);!0===this.executeWhereClause(s)?this._idstates[e[t]]=i.InFeatureSet:this._idstates[e[t]]=i.NotInFeatureSet}return"success"}const l=[];for(let t=0;t<a;t++){const s=this._parent._featureFromCache(e[t]);l.push(await this.executeWhereClauseDeferred(s))}for(let t=0;t<s;t++)!0===l[t]?this._idstates[e[t]]=i.InFeatureSet:this._idstates[e[t]]=i.NotInFeatureSet;return"success"}async _getFilteredSet(e,s,i,n,a){null!==this._whereClauseFunction||(null!==i?null!==this._whereclause&&(i=r(this._whereclause,i)):i=this._whereclause),await this._ensureLoaded();const l=await this._parent._getFilteredSet(e,s,i,n,a);let h;return this._checkCancelled(a),h=null!==this._whereClauseFunction?new t(l._candidates.slice(0).concat(l._known.slice(0)),[],l._ordered,this._clonePageDefinition(l.pagesDefinition)):new t(l._candidates.slice(0),l._known.slice(0),l._ordered,this._clonePageDefinition(l.pagesDefinition)),h}async _stat(e,t,s,i,n,a,l){if(null!==this._whereClauseFunction)return null===n&&""===s&&null===i?this._manualStat(e,t,a,l):{calculated:!1};let h=this._whereclause;null!==n&&null!==this._whereclause&&(h=r(this._whereclause,n));const u=await this._parent._stat(e,t,s,i,h,a,l);return!1===u.calculated?null===n&&""===s&&null===i?this._manualStat(e,t,a,l):{calculated:!1}:u}async _canDoAggregates(e,t,s,i,n){return null===this._whereClauseFunction&&(null!==n?null!==this._whereclause&&(n=r(this._whereclause,n)):n=this._whereclause,null!==this._parent&&this._parent._canDoAggregates(e,t,s,i,n))}async _getAggregatePagesDataSourceDefinition(e,t,s,i,n,a,l){if(null===this._parent)throw new Error("Should never be called");return null!==n?null!==this._whereclause&&(n=r(this._whereclause,n)):n=this._whereclause,this._parent._getAggregatePagesDataSourceDefinition(e,t,s,i,n,a,l)}static registerAction(){e._featuresetFunctions.filter=function(e){if("function"==typeof e)return new h({parentfeatureset:this,whereclause:e});let t=null;return e instanceof a&&(t=e),new h({parentfeatureset:this,whereclause:t})}}}export{h as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import t from"../../../request.js";import i from"../../Attachment.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,stableStringify as n,FeatureServiceDatabaseType as l,IdState as o,extractServiceUrl as u}from"../support/shared.js";import{toWhereClause as d,isSingleField as h}from"../support/sqlUtils.js";import{decodeStatType as c}from"../support/stats.js";import{createMD5Hash as p,outputTypes as y}from"../../../core/MD5.js";import{id as f}from"../../../kernel.js";import{fromJSON as _}from"../../../geometry/support/jsonUtils.js";import m from"../../../layers/FeatureLayer.js";import{convertToFeatureSet as g}from"../../../layers/graphics/featureConversionUtils.js";import"../../../core/Error.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../layers/support/source/DataLayerSource.js";import{executeQueryJSON as F}from"../../../rest/query/executeQueryJSON.js";import"../../../core/arrayUtils.js";import"../../../core/urlUtils.js";import"../../../core/unitUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import{executeQueryPBF as S}from"../../../rest/query/operations/query.js";import b from"../../../rest/support/FeatureSet.js";import R from"../../../rest/support/Query.js";import"../../../rest/query/support/AttachmentInfo.js";import"../../../rest/support/AttachmentQuery.js";import{executeForCount as w}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import{executeForIds as D}from"../../../rest/query/executeForIds.js";import"../../../rest/support/RelationshipQuery.js";import"../../../geometry/support/normalizeUtils.js";import"../../../rest/support/TopFeaturesQuery.js";import{OptimizedFeatureSetParserContext as x}from"../../../rest/query/operations/pbfOptimizedFeatureSet.js";import I from"../../../rest/support/StatisticDefinition.js";import q from"../../Dictionary.js";class P extends r{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerDynamic",this._removeGeometry=!1,this._overrideFields=null,this.formulaCredential=null,this._pageJustIds=!1,this._requestStandardised=!1,this._useDefinitionExpression=!0,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}convertQueryToLruCacheKey(e){const t=n(e.toJSON());return p(t,y.String)}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._layer.outFields)if(1===this._layer.outFields.length&&"*"===this._layer.outFields[0]);else{const e=[];for(const t of this.fields)if("oid"===t.type)e.push(t);else for(const i of this._layer.outFields)if(i.toLowerCase()===t.name.toLowerCase()){e.push(t);break}this.fields=e}else;if(null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const i of this.fields)if("oid"===i.type)e.push(i),t.push(i.name);else for(const r of this._overrideFields)if(r.toLowerCase()===i.name.toLowerCase()){e.push(i),t.push(i.name);break}this.fields=e,this._overrideFields=t}if(this._layer.source&&this._layer.source.sourceJSON){const e=this._layer.source.sourceJSON.currentVersion;!0===this._layer.source.sourceJSON.useStandardizedQueries?(this._databaseType=l.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=l.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=l.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=l.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this.typeIdField=this._layer.typeIdField,this.types=this._layer.types}_isInFeatureSet(){return o.InFeatureSet}async _refineSetBlock(e){return e}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}async _runDatabaseProbe(e){await this._ensureLoaded();const t=new R;t.where=e.replace("OBJECTID",this._layer.objectIdField);try{return await this._layer.queryObjectIds(t),!0}catch(i){return!1}}_canUsePagination(){return!(!this._layer.capabilities||!this._layer.capabilities.query||!0!==this._layer.capabilities.query.supportsPagination)}_cacheableFeatureSetSourceKey(){return this._layer.url}pbfSupportedForQuery(e){return!e.outStatistics&&this._layer&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsFormatPBF&&!0===this._layer.capabilities.query.supportsQuantizationEditMode}async queryPBF(e){e.quantizationParameters={mode:"edit"};const t=await S(this._layer.parsedUrl,e,new x({}));return b.fromJSON(g(t.data)).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion?this._layer.gdbVersion:"SDE.DEFAULT":""}nativeCapabilities(){return{title:this._layer.title,source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){const i="execute"===t?F:"executeForCount"===t?w:D,r="execute"===t&&this.pbfSupportedForQuery(e);let s=null;if(this.recentlyUsedQueries){const t=this.convertQueryToLruCacheKey(e);s=this.recentlyUsedQueries.getFromCache(t),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(t,s),s=s.catch((e=>{throw this.recentlyUsedQueries.removeFromCache(t),e})))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e)),s}async _getFilteredSet(e,t,i,r,a){const n=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,a);let l="",o=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(l=r.constructClause(),o=!0);const u=new R;u.where=null===i?null===t?"1=1":"":d(i,n),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==l?l.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let h=await this.executeQuery(u,"executeForIds");null===h&&(h=[]),this._checkCancelled(a);return new s([],h,o,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,a){let n="",l=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(n=r.constructClause(),l=!0);const o=await this.databaseType();let u=null===i?null===t?"1=1":"":d(i,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let h=this._maxQueryRate();const c=this._layer.capabilities.query.maxRecordCount;void 0!==c&&c<h&&(h=c);let p=null;if(!0===this._pageJustIds)p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:h,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:!1,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});else{let i=!0;!0===this._removeGeometry&&(i=!1);const r=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._layer.outFields?this._layer.outFields:["*"]);p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:h,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(p,h,0,1,a),p}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,i){const r=e.pagesDefinition.internal.lastRetrieved,s=r,a=e.pagesDefinition.internal.lastPage,n=new R;this._requestStandardised&&(n.sqlFormat="standard"),n.spatialRelationship=e.pagesDefinition.spatialRel,n.relationParameter=e.pagesDefinition.relationParam,n.outFields=e.pagesDefinition.outFields.split(","),n.num=e.pagesDefinition.resultRecordCount,n.start=e.pagesDefinition.internal.lastPage,n.geometry=e.pagesDefinition.geometry,n.where=e.pagesDefinition.where,n.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,n.returnGeometry=e.pagesDefinition.returnGeometry,n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==a)return"done";for(let o=0;o<l.features.length;o++)e.pagesDefinition.internal.set[s+o]=l.features[o].attributes[this._layer.objectIdField];if(!1===this._pageJustIds)for(let o=0;o<l.features.length;o++)this._featureCache[l.features[o].attributes[this._layer.objectIdField]]=l.features[o];return(void 0===l.exceededTransferLimit&&l.features.length!==e.pagesDefinition.resultRecordCount||!1===l.exceededTransferLimit)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=r+l.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,"done"}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const r of t)if(r.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return!1===i&&t.push(this.objectIdField),t}async _getFeatures(e,t,i,r){const s=[];if(-1!==t&&void 0===this._featureCache[t]&&s.push(t),!0===this._checkIfNeedToExpandKnownPage(e,this._maxProcessingRate()))return await this._expandPagedSet(e,this._maxProcessingRate(),0,0,r),this._getFeatures(e,t,i,r);let a=0;for(let o=e._lastFetchedIndex;o<e._known.length;o++){if(e._lastFetchedIndex+=1,a++,void 0===this._featureCache[e._known[o]]){let i=!1;if(null!==this._layer._mode&&void 0!==this._layer._mode){const t=this._layer._mode;if(void 0!==t._featureMap[e._known[o]]){const r=t._featureMap[e._known[o]];null!==r&&(i=!0,this._featureCache[e._known[o]]=r)}}if(!1===i&&(e._known[o]!==t&&s.push(e._known[o]),s.length>=this._maxProcessingRate()-1))break}if(a>=i&&0===s.length)break}if(0===s.length)return"success";const n=new R;this._requestStandardised&&(n.sqlFormat="standard"),n.objectIds=s,n.outFields=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._layer.outFields?this._layer.outFields:["*"]),n.returnGeometry=!0,!0===this._removeGeometry&&(n.returnGeometry=!1),n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(r),void 0!==l.error)throw new Error(l.error);for(let o=0;o<l.features.length;o++)this._featureCache[l.features[o].attributes[this._layer.objectIdField]]=l.features[o];return"success"}async _getDistinctPages(e,t,i,r,s,a,n,l,o){await this._ensureLoaded();const u=await this.databaseType();let h=i.parseTree.column;for(let d=0;d<this._layer.fields.length;d++)if(this._layer.fields[d].name.toLowerCase()===h.toLowerCase()){h=this._layer.fields[d].name;break}const c=new R;this._requestStandardised&&(c.sqlFormat="standard");let p=null===a?null===s?"1=1":"":d(a,u);this._layer.definitionExpression&&this._useDefinitionExpression&&(p=""!==p?"(("+this._layer.definitionExpression+") AND ("+p+"))":this._layer.definitionExpression),c.where=p,c.spatialRelationship=this._makeRelationshipEnum(r),c.relationParameter=this._makeRelationshipParam(r),c.geometry=null===s?null:s,c.returnDistinctValues=!0,c.returnGeometry=!1,c.outFields=[h];const y=await this.executeQuery(c,"execute");if(this._checkCancelled(o),!y.hasOwnProperty("features"))throw new Error("Unnexected Result querying statistics from layer");let f=!1;for(let d=0;d<this._layer.fields.length;d++)if(this._layer.fields[d].name===h){"date"===this._layer.fields[d].type&&(f=!0);break}for(let d=0;d<y.features.length;d++){if(f){const e=y.features[d].attributes[h];null!==e?l.push(new Date(e)):l.push(e)}else l.push(y.features[d].attributes[h]);if(l.length>=n)break}if(0===y.features.length)return l;if(y.features.length===this._layer.capabilities.query.maxRecordCount&&l.length<n){return{calculated:!0,result:await this._getDistinctPages(e+y.features.length,t,i,r,s,a,n,l,o)}}return l}async _distinctStat(e,t,i,r,s,a,n){return{calculated:!0,result:await this._getDistinctPages(0,e,t,i,r,s,a,[],n)}}isTable(){return this._layer.isTable||null===this._layer.geometryType||"table"===this._layer.type||""===this._layer.geometryType}async _countstat(e,t,i,r){const s=await this.databaseType(),a=new R;if(this._requestStandardised&&(a.sqlFormat="standard"),this.isTable()&&i&&null!==t&&""!==t)return{calculated:!0,result:0};let n=null===r?null===i?"1=1":"":d(r,s);this._layer.definitionExpression&&this._useDefinitionExpression&&(n=""!==n?"(("+this._layer.definitionExpression+") AND ("+n+"))":this._layer.definitionExpression),a.where=n,a.where=n,a.spatialRelationship=this._makeRelationshipEnum(t),a.relationParameter=this._makeRelationshipParam(t),a.geometry=null===i?null:i,a.returnGeometry=!1;return{calculated:!0,result:await this.executeQuery(a,"executeForCount")}}async _stats(e,t,i,r,s,a,n){await this._ensureLoaded();const l=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,o=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return u?this._countstat(e,i,r,s):{calculated:!1};if(!1===o||!1===h(t)&&!1===l||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n);if("distinct"===e)return!1===u?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n):this._distinctStat(e,t,i,r,s,a,n);const p=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const y=new R;this._requestStandardised&&(y.sqlFormat="standard");let f=null===s?null===r?"1=1":"":d(s,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(f=""!==f?"(("+this._layer.definitionExpression+") AND ("+f+"))":this._layer.definitionExpression),y.where=f,y.spatialRelationship=this._makeRelationshipEnum(i),y.relationParameter=this._makeRelationshipParam(i),y.geometry=null===r?null:r;const _=new I;_.statisticType=c(e),_.onStatisticField=d(t,p),_.outStatisticFieldName="ARCADE_STAT_RESULT",y.returnGeometry=!1;let m="ARCADE_STAT_RESULT";y.outStatistics=[_];const g=await this.executeQuery(y,"execute");if(!g.hasOwnProperty("features")||0===g.features.length)throw new Error("Unnexected Result querying statistics from layer");let F=!1;for(let d=0;d<g.fields.length;d++)if("ARCADE_STAT_RESULT"===g.fields[d].name.toUpperCase()){m=g.fields[d].name,"date"===g.fields[d].type&&(F=!0);break}if(F){let e=g.features[0].attributes[m];return null!==e&&(e=new Date(g.features[0].attributes[m])),{calculated:!0,result:e}}return{calculated:!0,result:g.features[0].attributes[m]}}_stat(e,t,i,r,s,a,n){return this._stats(e,t,i,r,s,a,n)}async _canDoAggregates(e,t){await this._ensureLoaded();let i=!1;const r=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression;if(void 0!==this._layer.capabilities&&null!==this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics&&!0===this._layer.capabilities.query.supportsOrderBy&&(i=!0),i)for(let s=0;s<t.length-1;s++)null!==t[s].workingexpr&&(!1===t[s].workingexpr.isStandardized||!1===h(t[s].workingexpr)&&!1===r)&&(i=!1);return!1!==i}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _getAggregatePagesDataSourceDefinition(e,t,i,r,a,n,l){await this._ensureLoaded();const o=await this.databaseType();let u="",h=!1,c=!1;null!==n&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=n.constructClause(),c=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(c=!1,h=!0,u=this._layer.objectIdField);const p=[];for(let s=0;s<t.length;s++){const e=new I;e.onStatisticField=null!==t[s].workingexpr?d(t[s].workingexpr,o):"",e.outStatisticFieldName=t[s].field,e.statisticType=t[s].toStatisticsName(),p.push(e)}""===u&&(u=e.join(","));let y=this._maxQueryRate();const f=this._layer.capabilities.query.maxRecordCount;void 0!==f&&f<y&&(y=f);let _=null===a?null===r?"1=1":"":d(a,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(_=""!==_?"(("+this._layer.definitionExpression+") AND ("+_+"))":this._layer.definitionExpression);return new s([],["GETPAGES"],c,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:h,generatedOid:l,resultRecordCount:y,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:p,geometry:null===r?null:r,where:_,orderByFields:u,returnGeometry:!1,returnIdsOnly:!1,internal:{lastMaxId:-1,set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}async _getAgregagtePhysicalPage(t,i,r){let s=t.pagesDefinition.where;!0===t.pagesDefinition.useOIDpagination&&(s=""!==s?"("+s+") AND ("+t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString()+")":t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString());const a=t.pagesDefinition.internal.lastRetrieved,n=a,l=t.pagesDefinition.internal.lastPage,o=new R;if(this._requestStandardised&&(o.sqlFormat="standard"),o.where=s,o.spatialRelationship=t.pagesDefinition.spatialRel,o.relationParameter=t.pagesDefinition.relationParam,o.outFields=t.pagesDefinition.outFields,o.outStatistics=t.pagesDefinition.outStatistics,o.geometry=t.pagesDefinition.geometry,o.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,o.num=t.pagesDefinition.resultRecordCount,o.start=t.pagesDefinition.internal.lastPage,o.returnGeometry=t.pagesDefinition.returnGeometry,o.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&o.geometry&&o.spatialRelationship)return[];const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),!u.hasOwnProperty("features"))throw new Error("Unnexected Result querying aggregates from layer");const d=[];if(t.pagesDefinition.internal.lastPage!==l)return[];for(let e=0;e<u.features.length;e++)t.pagesDefinition.internal.set[n+e]=u.features[e].attributes[t.pagesDefinition.generatedOid];for(let h=0;h<u.features.length;h++)d.push(new e({attributes:u.features[h].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===u.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=u.features[u.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===u.exceededTransferLimit&&u.features.length!==t.pagesDefinition.resultRecordCount||!1===u.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=a+u.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,d}static create(e,t,i,r,s){const a=new m({url:e,outFields:null===t?["*"]:t});return new P({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON&&this._layer.source.sourceJSON.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return u(this._layer.parsedUrl.path)}async queryAttachments(e,t,r,s,a){if(this._layer.capabilities.data.supportsAttachment&&this._layer.capabilities.operations.supportsQueryAttachments){const n={objectIds:[e],returnMetadata:a};(t&&t>0||r&&r>0)&&(n.size=[t&&t>0?t:0,r&&r>0?r:t+1]),s&&s.length>0&&(n.attachmentTypes=s),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:n,method:"attachments"});const l=await this._layer.queryAttachments(n),o=[];return l&&l[e]&&l[e].forEach((t=>{const r=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let s=null;a&&t.exifInfo&&(s=q.convertJsonToArcade(t.exifInfo,!0)),o.push(new i(t.id,t.name,t.contentType,t.size,r,s))})),o}return[]}async queryRelatedFeatures(i){const r={f:"json",relationshipId:i.relationshipId.toString(),definitionExpression:i.where,outFields:i.outFields.join(","),returnGeometry:i.returnGeometry.toString()};void 0!==i.resultOffset&&null!==i.resultOffset&&(r.resultOffset=i.resultOffset.toString()),void 0!==i.resultRecordCount&&null!==i.resultRecordCount&&(r.resultRecordCount=i.resultRecordCount.toString()),i.orderByFields&&(r.orderByFields=i.orderByFields.join(",")),i.objectIds.length>0&&(r.objectIds=i.objectIds.join(",")),i.outSpatialReference&&(r.outSR=JSON.stringify(i.outSpatialReference.toJSON())),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await t(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(i&&i.relatedRecordGroups){const r=i.spatialReference;for(const s of i.relatedRecordGroups){const a=s.objectId,n=[];for(const t of s.relatedRecords){t.geometry&&(t.geometry.spatialReference=r);const i=new e({geometry:t.geometry?_(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new Error("Invalid Request")}async getFeatureByObjectId(e,t){const i=new R;i.outFields=t,i.returnGeometry=!1,i.outSpatialReference=this.spatialReference,i.where=this.objectIdField+"="+e.toString(),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:i,method:"execute"});const r=await F(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=f?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=f?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let i=this._layer.url;const r=i.toLowerCase().indexOf("/rest/services");if(i=r>-1?i.substring(0,r):i,i){i+="/rest/info";try{const e=await t(i,{query:{f:"json"}});let r="";return e.data&&e.data.owningSystemUrl&&(r=e.data.owningSystemUrl),r}catch(s){return""}}return""}getDataSourceFeatureSet(){const e=new P({layer:this._layer,spatialReference:this.spatialReference,outFields:this._overrideFields,includeGeometry:!this._removeGeometry,lrucache:this.recentlyUsedQueries,interceptor:this.featureSetQueryInterceptor});return e._useDefinitionExpression=!1,e}}export{P as default};
5
+ import e from"../../../Graphic.js";import t from"../../../request.js";import i from"../../Attachment.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,stableStringify as n,FeatureServiceDatabaseType as l,IdState as o,extractServiceUrl as u}from"../support/shared.js";import{toWhereClause as d,isSingleField as c}from"../support/sqlUtils.js";import{decodeStatType as h}from"../support/stats.js";import{createMD5Hash as p,outputTypes as y}from"../../../core/MD5.js";import{id as f}from"../../../kernel.js";import{fromJSON as _}from"../../../geometry/support/jsonUtils.js";import m from"../../../layers/FeatureLayer.js";import{convertToFeatureSet as g}from"../../../layers/graphics/featureConversionUtils.js";import"../../../core/Error.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../layers/support/source/DataLayerSource.js";import{executeQueryJSON as F}from"../../../rest/query/executeQueryJSON.js";import"../../../core/arrayUtils.js";import"../../../core/urlUtils.js";import"../../../core/unitUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import{executeQueryPBF as S}from"../../../rest/query/operations/query.js";import R from"../../../rest/support/FeatureSet.js";import b from"../../../rest/support/Query.js";import"../../../rest/query/support/AttachmentInfo.js";import"../../../rest/support/AttachmentQuery.js";import{executeForCount as w}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import{executeForIds as D}from"../../../rest/query/executeForIds.js";import"../../../rest/support/RelationshipQuery.js";import"../../../geometry/support/normalizeUtils.js";import"../../../rest/support/TopFeaturesQuery.js";import{OptimizedFeatureSetParserContext as x}from"../../../rest/query/operations/pbfOptimizedFeatureSet.js";import I from"../../../rest/support/StatisticDefinition.js";import q from"../../Dictionary.js";class P extends r{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerDynamic",this._removeGeometry=!1,this._overrideFields=null,this.formulaCredential=null,this._pageJustIds=!1,this._requestStandardised=!1,this._useDefinitionExpression=!0,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}convertQueryToLruCacheKey(e){const t=n(e.toJSON());return p(t,y.String)}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._layer.outFields)if(1===this._layer.outFields.length&&"*"===this._layer.outFields[0]);else{const e=[];for(const t of this.fields)if("oid"===t.type)e.push(t);else for(const i of this._layer.outFields)if(i.toLowerCase()===t.name.toLowerCase()){e.push(t);break}this.fields=e}else;if(null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const i of this.fields)if("oid"===i.type)e.push(i),t.push(i.name);else for(const r of this._overrideFields)if(r.toLowerCase()===i.name.toLowerCase()){e.push(i),t.push(i.name);break}this.fields=e,this._overrideFields=t}if(this._layer.source&&this._layer.source.sourceJSON){const e=this._layer.source.sourceJSON.currentVersion;!0===this._layer.source.sourceJSON.useStandardizedQueries?(this._databaseType=l.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=l.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=l.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=l.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this.typeIdField=this._layer.typeIdField,this.types=this._layer.types}_isInFeatureSet(){return o.InFeatureSet}async _refineSetBlock(e){return e}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}async _runDatabaseProbe(e){await this._ensureLoaded();const t=new b;t.where=e.replace("OBJECTID",this._layer.objectIdField);try{return await this._layer.queryObjectIds(t),!0}catch(i){return!1}}_canUsePagination(){return!(!this._layer.capabilities||!this._layer.capabilities.query||!0!==this._layer.capabilities.query.supportsPagination)}_cacheableFeatureSetSourceKey(){return this._layer.url}pbfSupportedForQuery(e){const t=this._layer?.capabilities?.query;return!e.outStatistics&&!0===t?.supportsFormatPBF&&!0===t?.supportsQuantizationEditMode}async queryPBF(e){e.quantizationParameters={mode:"edit"};const t=await S(this._layer.parsedUrl,e,new x({}));return R.fromJSON(g(t.data)).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion?this._layer.gdbVersion:"SDE.DEFAULT":""}nativeCapabilities(){return{title:this._layer.title,source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){const i="execute"===t?F:"executeForCount"===t?w:D,r="execute"===t&&this.pbfSupportedForQuery(e);let s=null;if(this.recentlyUsedQueries){const t=this.convertQueryToLruCacheKey(e);s=this.recentlyUsedQueries.getFromCache(t),null==s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(t,s),s=s.catch((e=>{throw this.recentlyUsedQueries.removeFromCache(t),e})))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e)),s}async _getFilteredSet(e,t,i,r,a){const n=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,a);let l="",o=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(l=r.constructClause(),o=!0);const u=new b;u.where=null===i?null===t?"1=1":"":d(i,n),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==l?l.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let c=await this.executeQuery(u,"executeForIds");null===c&&(c=[]),this._checkCancelled(a);return new s([],c,o,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,a){let n="",l=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(n=r.constructClause(),l=!0);const o=await this.databaseType();let u=null===i?null===t?"1=1":"":d(i,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let c=this._maxQueryRate();const h=this._layer.capabilities.query.maxRecordCount;void 0!==h&&h<c&&(c=h);let p=null;if(!0===this._pageJustIds)p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:!1,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});else{let i=!0;!0===this._removeGeometry&&(i=!1);const r=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._layer.outFields?this._layer.outFields:["*"]);p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(p,c,0,1,a),p}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,i){const r=e.pagesDefinition.internal.lastRetrieved,s=r,a=e.pagesDefinition.internal.lastPage,n=new b;this._requestStandardised&&(n.sqlFormat="standard"),n.spatialRelationship=e.pagesDefinition.spatialRel,n.relationParameter=e.pagesDefinition.relationParam,n.outFields=e.pagesDefinition.outFields.split(","),n.num=e.pagesDefinition.resultRecordCount,n.start=e.pagesDefinition.internal.lastPage,n.geometry=e.pagesDefinition.geometry,n.where=e.pagesDefinition.where,n.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,n.returnGeometry=e.pagesDefinition.returnGeometry,n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==a)return"done";for(let o=0;o<l.features.length;o++)e.pagesDefinition.internal.set[s+o]=l.features[o].attributes[this._layer.objectIdField];if(!1===this._pageJustIds)for(let o=0;o<l.features.length;o++)this._featureCache[l.features[o].attributes[this._layer.objectIdField]]=l.features[o];return(void 0===l.exceededTransferLimit&&l.features.length!==e.pagesDefinition.resultRecordCount||!1===l.exceededTransferLimit)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=r+l.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,"done"}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const r of t)if(r.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return!1===i&&t.push(this.objectIdField),t}async _getFeatures(e,t,i,r){const s=[];if(-1!==t&&void 0===this._featureCache[t]&&s.push(t),!0===this._checkIfNeedToExpandKnownPage(e,this._maxProcessingRate()))return await this._expandPagedSet(e,this._maxProcessingRate(),0,0,r),this._getFeatures(e,t,i,r);let a=0;for(let o=e._lastFetchedIndex;o<e._known.length;o++){if(e._lastFetchedIndex+=1,a++,void 0===this._featureCache[e._known[o]]){let i=!1;if(null!==this._layer._mode&&void 0!==this._layer._mode){const t=this._layer._mode;if(void 0!==t._featureMap[e._known[o]]){const r=t._featureMap[e._known[o]];null!==r&&(i=!0,this._featureCache[e._known[o]]=r)}}if(!1===i&&(e._known[o]!==t&&s.push(e._known[o]),s.length>=this._maxProcessingRate()-1))break}if(a>=i&&0===s.length)break}if(0===s.length)return"success";const n=new b;this._requestStandardised&&(n.sqlFormat="standard"),n.objectIds=s,n.outFields=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._layer.outFields?this._layer.outFields:["*"]),n.returnGeometry=!0,!0===this._removeGeometry&&(n.returnGeometry=!1),n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(r),void 0!==l.error)throw new Error(l.error);for(let o=0;o<l.features.length;o++)this._featureCache[l.features[o].attributes[this._layer.objectIdField]]=l.features[o];return"success"}async _getDistinctPages(e,t,i,r,s,a,n,l,o){await this._ensureLoaded();const u=await this.databaseType();let c=i.parseTree.column;const h=this._layer.fields;for(let d=0;d<h.length;d++)if(h[d].name.toLowerCase()===c.toLowerCase()){c=h[d].name;break}const p=new b;this._requestStandardised&&(p.sqlFormat="standard");let y=null===a?null===s?"1=1":"":d(a,u);this._layer.definitionExpression&&this._useDefinitionExpression&&(y=""!==y?"(("+this._layer.definitionExpression+") AND ("+y+"))":this._layer.definitionExpression),p.where=y,p.spatialRelationship=this._makeRelationshipEnum(r),p.relationParameter=this._makeRelationshipParam(r),p.geometry=null===s?null:s,p.returnDistinctValues=!0,p.returnGeometry=!1,p.outFields=[c];const f=await this.executeQuery(p,"execute");if(this._checkCancelled(o),!f.hasOwnProperty("features"))throw new Error("Unnexected Result querying statistics from layer");let _=!1;const m=this._layer.fields;for(let d=0;d<m.length;d++)if(m[d].name===c){"date"===m[d].type&&(_=!0);break}for(let d=0;d<f.features.length;d++){if(_){const e=f.features[d].attributes[c];null!==e?l.push(new Date(e)):l.push(e)}else l.push(f.features[d].attributes[c]);if(l.length>=n)break}if(0===f.features.length)return l;if(f.features.length===this._layer.capabilities.query.maxRecordCount&&l.length<n){return{calculated:!0,result:await this._getDistinctPages(e+f.features.length,t,i,r,s,a,n,l,o)}}return l}async _distinctStat(e,t,i,r,s,a,n){return{calculated:!0,result:await this._getDistinctPages(0,e,t,i,r,s,a,[],n)}}isTable(){return this._layer.isTable||null===this._layer.geometryType||"table"===this._layer.type||""===this._layer.geometryType}async _countstat(e,t,i,r){const s=await this.databaseType(),a=new b;if(this._requestStandardised&&(a.sqlFormat="standard"),this.isTable()&&i&&null!==t&&""!==t)return{calculated:!0,result:0};let n=null===r?null===i?"1=1":"":d(r,s);this._layer.definitionExpression&&this._useDefinitionExpression&&(n=""!==n?"(("+this._layer.definitionExpression+") AND ("+n+"))":this._layer.definitionExpression),a.where=n,a.where=n,a.spatialRelationship=this._makeRelationshipEnum(t),a.relationParameter=this._makeRelationshipParam(t),a.geometry=null===i?null:i,a.returnGeometry=!1;return{calculated:!0,result:await this.executeQuery(a,"executeForCount")}}async _stats(e,t,i,r,s,a,n){await this._ensureLoaded();const l=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,o=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return u?this._countstat(e,i,r,s):{calculated:!1};if(!1===o||!1===c(t)&&!1===l||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n);if("distinct"===e)return!1===u?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n):this._distinctStat(e,t,i,r,s,a,n);const p=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const y=new b;this._requestStandardised&&(y.sqlFormat="standard");let f=null===s?null===r?"1=1":"":d(s,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(f=""!==f?"(("+this._layer.definitionExpression+") AND ("+f+"))":this._layer.definitionExpression),y.where=f,y.spatialRelationship=this._makeRelationshipEnum(i),y.relationParameter=this._makeRelationshipParam(i),y.geometry=null===r?null:r;const _=new I;_.statisticType=h(e),_.onStatisticField=d(t,p),_.outStatisticFieldName="ARCADE_STAT_RESULT",y.returnGeometry=!1;let m="ARCADE_STAT_RESULT";y.outStatistics=[_];const g=await this.executeQuery(y,"execute");if(!g.hasOwnProperty("features")||0===g.features.length||!g.fields)throw new Error("Unnexected Result querying statistics from layer");let F=!1;for(let d=0;d<g.fields.length;d++)if("ARCADE_STAT_RESULT"===g.fields[d].name.toUpperCase()){m=g.fields[d].name,"date"===g.fields[d].type&&(F=!0);break}if(F){let e=g.features[0].attributes[m];return null!==e&&(e=new Date(g.features[0].attributes[m])),{calculated:!0,result:e}}return{calculated:!0,result:g.features[0].attributes[m]}}_stat(e,t,i,r,s,a,n){return this._stats(e,t,i,r,s,a,n)}async _canDoAggregates(e,t){await this._ensureLoaded();let i=!1;const r=this._layer.capabilities,s=r&&r.query&&!0===r.query.supportsSqlExpression;if(null!=r&&null!==r.query&&!0===r.query.supportsStatistics&&!0===r.query.supportsOrderBy&&(i=!0),i)for(let a=0;a<t.length-1;a++)null!==t[a].workingexpr&&(!1===t[a].workingexpr.isStandardized||!1===c(t[a].workingexpr)&&!1===s)&&(i=!1);return!1!==i}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _getAggregatePagesDataSourceDefinition(e,t,i,r,a,n,l){await this._ensureLoaded();const o=await this.databaseType();let u="",c=!1,h=!1;null!==n&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=n.constructClause(),h=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(h=!1,c=!0,u=this._layer.objectIdField);const p=[];for(let s=0;s<t.length;s++){const e=new I;e.onStatisticField=null!==t[s].workingexpr?d(t[s].workingexpr,o):"",e.outStatisticFieldName=t[s].field,e.statisticType=t[s].toStatisticsName(),p.push(e)}""===u&&(u=e.join(","));let y=this._maxQueryRate();const f=this._layer.capabilities.query.maxRecordCount;void 0!==f&&f<y&&(y=f);let _=null===a?null===r?"1=1":"":d(a,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(_=""!==_?"(("+this._layer.definitionExpression+") AND ("+_+"))":this._layer.definitionExpression);return new s([],["GETPAGES"],h,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:c,generatedOid:l,resultRecordCount:y,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:p,geometry:null===r?null:r,where:_,orderByFields:u,returnGeometry:!1,returnIdsOnly:!1,internal:{lastMaxId:-1,set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}async _getAgregagtePhysicalPage(t,i,r){let s=t.pagesDefinition.where;!0===t.pagesDefinition.useOIDpagination&&(s=""!==s?"("+s+") AND ("+t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString()+")":t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString());const a=t.pagesDefinition.internal.lastRetrieved,n=a,l=t.pagesDefinition.internal.lastPage,o=new b;if(this._requestStandardised&&(o.sqlFormat="standard"),o.where=s,o.spatialRelationship=t.pagesDefinition.spatialRel,o.relationParameter=t.pagesDefinition.relationParam,o.outFields=t.pagesDefinition.outFields,o.outStatistics=t.pagesDefinition.outStatistics,o.geometry=t.pagesDefinition.geometry,o.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,o.num=t.pagesDefinition.resultRecordCount,o.start=t.pagesDefinition.internal.lastPage,o.returnGeometry=t.pagesDefinition.returnGeometry,o.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&o.geometry&&o.spatialRelationship)return[];const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),!u.hasOwnProperty("features"))throw new Error("Unnexected Result querying aggregates from layer");const d=[];if(t.pagesDefinition.internal.lastPage!==l)return[];for(let e=0;e<u.features.length;e++)t.pagesDefinition.internal.set[n+e]=u.features[e].attributes[t.pagesDefinition.generatedOid];for(let c=0;c<u.features.length;c++)d.push(new e({attributes:u.features[c].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===u.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=u.features[u.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===u.exceededTransferLimit&&u.features.length!==t.pagesDefinition.resultRecordCount||!1===u.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=a+u.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,d}static create(e,t,i,r,s){const a=new m({url:e,outFields:null===t?["*"]:t});return new P({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON&&this._layer.source.sourceJSON.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return u(this._layer.parsedUrl.path)}async queryAttachments(e,t,r,s,a){const n=this._layer.capabilities;if(n.data.supportsAttachment&&n.operations.supportsQueryAttachments){const n={objectIds:[e],returnMetadata:a};(t&&t>0||r&&r>0)&&(n.size=[t&&t>0?t:0,r&&r>0?r:t+1]),s&&s.length>0&&(n.attachmentTypes=s),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:n,method:"attachments"});const l=await this._layer.queryAttachments(n),o=[];return l&&l[e]&&l[e].forEach((t=>{const r=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let s=null;a&&t.exifInfo&&(s=q.convertJsonToArcade(t.exifInfo,!0)),o.push(new i(t.id,t.name,t.contentType,t.size,r,s))})),o}return[]}async queryRelatedFeatures(i){const r={f:"json",relationshipId:i.relationshipId.toString(),definitionExpression:i.where,outFields:i.outFields.join(","),returnGeometry:i.returnGeometry.toString()};void 0!==i.resultOffset&&null!==i.resultOffset&&(r.resultOffset=i.resultOffset.toString()),void 0!==i.resultRecordCount&&null!==i.resultRecordCount&&(r.resultRecordCount=i.resultRecordCount.toString()),i.orderByFields&&(r.orderByFields=i.orderByFields.join(",")),i.objectIds.length>0&&(r.objectIds=i.objectIds.join(",")),i.outSpatialReference&&(r.outSR=JSON.stringify(i.outSpatialReference.toJSON())),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await t(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(i&&i.relatedRecordGroups){const r=i.spatialReference;for(const s of i.relatedRecordGroups){const a=s.objectId,n=[];for(const t of s.relatedRecords){t.geometry&&(t.geometry.spatialReference=r);const i=new e({geometry:t.geometry?_(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new Error("Invalid Request")}async getFeatureByObjectId(e,t){const i=new b;i.outFields=t,i.returnGeometry=!1,i.outSpatialReference=this.spatialReference,i.where=this.objectIdField+"="+e.toString(),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:i,method:"execute"});const r=await F(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=f?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=f?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let i=this._layer.url;const r=i.toLowerCase().indexOf("/rest/services");if(i=r>-1?i.substring(0,r):i,i){i+="/rest/info";try{const e=await t(i,{query:{f:"json"}});let r="";return e.data&&e.data.owningSystemUrl&&(r=e.data.owningSystemUrl),r}catch(s){return""}}return""}getDataSourceFeatureSet(){const e=new P({layer:this._layer,spatialReference:this.spatialReference,outFields:this._overrideFields,includeGeometry:!this._removeGeometry,lrucache:this.recentlyUsedQueries,interceptor:this.featureSetQueryInterceptor});return e._useDefinitionExpression=!1,e}}export{P as default};