@esri/arcgis-rest-feature-service
Version:
Feature layer query and edit helpers for @esri/arcgis-rest-js
32 lines (31 loc) • 33 kB
JavaScript
/* @preserve
* @esri/arcgis-rest-feature-service - v4.10.2 - Apache-2.0
* Copyright (c) 2017-2026 Esri, Inc.
* Tue Apr 07 2026 14:52:39 GMT+0000 (Coordinated Universal Time)
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request"),require("@esri/arcgis-rest-portal")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request","@esri/arcgis-rest-portal"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest,e.arcgisRest)}(this,function(e,t,r){"use strict";function s(e){return t.request(t.cleanUrl(e.url),e)}function n(e,t){const r=t.codedValues.find(t=>e===t.code);return r?r.name:e}const i=new RegExp(/.+(?:map|feature|image)server/i);function a(e){const r=e.match(i);return r?r[0]:function(e){const r=e.split("?")[0];return t.cleanUrl(r)}(e)}
/* istanbul ignore file --@preserve */
function o(e,t){return e.readFields(u,{version:"",queryResult:void 0},t)}function u(e,t,r){1===e?t.version=r.readString():2===e&&(t.queryResult=function(e,t){return e.readFields(G,{featureResult:void 0,Results:void 0,countResult:void 0,idsResult:void 0,extentCountResult:void 0},t)}(r,r.readVarint()+r.pos))}const l={esriFieldTypeSmallInteger:0,esriFieldTypeInteger:1,esriFieldTypeSingle:2,esriFieldTypeDouble:3,esriFieldTypeString:4,esriFieldTypeDate:5,esriFieldTypeOID:6,esriFieldTypeGeometry:7,esriFieldTypeBlob:8,esriFieldTypeRaster:9,esriFieldTypeGUID:10,esriFieldTypeGlobalID:11,esriFieldTypeXML:12,esriFieldTypeBigInteger:13,esriFieldTypeDateOnly:14,esriFieldTypeTimeOnly:15,esriFieldTypeTimestampOffset:16},d={sqlTypeBigInt:0,sqlTypeBinary:1,sqlTypeBit:2,sqlTypeChar:3,sqlTypeDate:4,sqlTypeDecimal:5,sqlTypeDouble:6,sqlTypeFloat:7,sqlTypeGeometry:8,sqlTypeGUID:9,sqlTypeInteger:10,sqlTypeLongNVarchar:11,sqlTypeLongVarbinary:12,sqlTypeLongVarchar:13,sqlTypeNChar:14,sqlTypeNVarchar:15,sqlTypeOther:16,sqlTypeReal:17,sqlTypeSmallInt:18,sqlTypeSqlXml:19,sqlTypeTime:20,sqlTypeTimestamp:21,sqlTypeTimestamp2:22,sqlTypeTinyInt:23,sqlTypeVarbinary:24,sqlTypeVarchar:25,sqlTypeTimestampWithTimezone:26};function c(e,t){return e.readFields(p,{wkid:0,latestWkid:0,vcsWkid:0,latestVcsWkid:0,wkt:"",wkt2:""},t)}function p(e,t,r){1===e?t.wkid=r.readVarint():2===e?t.latestWkid=r.readVarint():3===e?t.vcsWkid=r.readVarint():4===e?t.latestVcsWkid=r.readVarint():5===e?t.wkt=r.readString():6===e&&(t.wkt2=r.readString())}function f(e,t){return e.readFields(h,{name:"",fieldType:0,alias:"",sqlType:0,domain:"",defaultValue:""},t)}function h(e,t,r){1===e?t.name=r.readString():2===e?t.fieldType=r.readVarint():3===e?t.alias=r.readString():4===e?t.sqlType=r.readVarint():5===e?t.domain=r.readString():6===e&&(t.defaultValue=r.readString())}function g(e,t,r){1===e?t.field=f(r,r.readVarint()+r.pos):2===e&&(t.geometryType=r.readVarint())}function m(e,t){return e.readFields(y,{XMin:0,YMin:0,XMax:0,YMax:0,SpatialReference:void 0},t)}function y(e,t,r){1===e?t.XMin=r.readDouble():2===e?t.YMin=r.readDouble():3===e?t.XMax=r.readDouble():4===e?t.YMax=r.readDouble():5===e&&(t.SpatialReference=c(r,r.readVarint()+r.pos))}function b(e,t){return e.readFields(w,{string_value:"",value_type:void 0,float_value:0,double_value:0,sint_value:0,uint_value:0,int64_value:0,uint64_value:0,sint64_value:0,bool_value:!1,null_value:!1,index:0},t)}function w(e,t,r){1===e?(t.string_value=r.readString(),t.value_type="string_value"):2===e?(t.float_value=r.readFloat(),t.value_type="float_value"):3===e?(t.double_value=r.readDouble(),t.value_type="double_value"):4===e?(t.sint_value=r.readSVarint(),t.value_type="sint_value"):5===e?(t.uint_value=r.readVarint(),t.value_type="uint_value"):6===e?(t.int64_value=r.readVarint(!0),t.value_type="int64_value"):7===e?(t.uint64_value=r.readVarint(),t.value_type="uint64_value"):8===e?(t.sint64_value=r.readSVarint(),t.value_type="sint64_value"):9===e?(t.bool_value=r.readBoolean(),t.value_type="bool_value"):10===e?(t.null_value=r.readBoolean(),t.value_type="null_value"):11===e&&(t.index=r.readVarint())}function F(e,t){return e.readFields(v,{geometryType:0,lengths:[],coords:[],ids:[]},t)}function v(e,t,r){1===e?t.geometryType=r.readVarint():2===e?r.readPackedVarint(t.lengths):3===e?r.readPackedSVarint(t.coords):4===e&&r.readPackedSVarint(t.ids)}function V(e,t,r){1===e?t.geometryType=r.readVarint():2===e?r.readPackedVarint(t.parts):3===e?t.segmentSets.push(function(e,t){return e.readFields(T,{type:0,count:0,parameters:[]},t)}(r,r.readVarint()+r.pos)):4===e&&r.readPackedSVarint(t.coords)}function T(e,t,r){1===e?t.type=r.readVarint():2===e?t.count=r.readVarint():3===e&&r.readPackedDouble(t.parameters)}function S(e,t,r){1===e&&(t.bytes=r.readBytes())}function q(e,t,r){1===e?t.attributes.push(b(r,r.readVarint()+r.pos)):2===e?(t.geometry=F(r,r.readVarint()+r.pos),t.compressed_geometry="geometry"):3===e?(t.shapeBuffer=function(e,t){return e.readFields(S,{bytes:void 0},t)}(r,r.readVarint()+r.pos),t.compressed_geometry="shapeBuffer"):7===e?(t.curveGeometry=function(e,t){return e.readFields(V,{geometryType:0,parts:[],segmentSets:[],coords:[]},t)}(r,r.readVarint()+r.pos),t.compressed_geometry="curveGeometry"):4===e?t.centroid=F(r,r.readVarint()+r.pos):5===e?t.aggregateGeometries.push(F(r,r.readVarint()+r.pos)):6===e&&(t.envelope=m(r,r.readVarint()+r.pos))}function R(e,t,r){1===e?t.name=r.readString():2===e&&(t.isSystemMaintained=r.readBoolean())}function x(e,t,r){1===e?t.shapeAreaFieldName=r.readString():2===e?t.shapeLengthFieldName=r.readString():3===e&&(t.units=r.readString())}function O(e,t){return e.readFields(j,{minServerGen:0,serverGen:0},t)}function j(e,t,r){1===e?t.minServerGen=r.readVarint():2===e&&(t.serverGen=r.readVarint())}function P(e,t,r){1===e?t.xScale=r.readDouble():2===e?t.yScale=r.readDouble():3===e?t.mScale=r.readDouble():4===e&&(t.zScale=r.readDouble())}function I(e,t,r){1===e?t.xTranslate=r.readDouble():2===e?t.yTranslate=r.readDouble():3===e?t.mTranslate=r.readDouble():4===e&&(t.zTranslate=r.readDouble())}function k(e,t,r){1===e?t.quantizeOriginPostion=r.readVarint():2===e?t.scale=function(e,t){return e.readFields(P,{xScale:0,yScale:0,mScale:0,zScale:0},t)}(r,r.readVarint()+r.pos):3===e&&(t.translate=function(e,t){return e.readFields(I,{xTranslate:0,yTranslate:0,mTranslate:0,zTranslate:0},t)}(r,r.readVarint()+r.pos))}function M(e,t,r){1===e?t.objectIdFieldName=r.readString():2===e?t.uniqueIdField=function(e,t){return e.readFields(R,{name:"",isSystemMaintained:!1},t)}(r,r.readVarint()+r.pos):3===e?t.globalIdFieldName=r.readString():4===e?t.geohashFieldName=r.readString():5===e?t.geometryProperties=function(e,t){return e.readFields(x,{shapeAreaFieldName:"",shapeLengthFieldName:"",units:""},t)}(r,r.readVarint()+r.pos):6===e?t.serverGens=O(r,r.readVarint()+r.pos):7===e?t.geometryType=r.readVarint():8===e?t.spatialReference=c(r,r.readVarint()+r.pos):9===e?t.exceededTransferLimit=r.readBoolean():10===e?t.hasZ=r.readBoolean():11===e?t.hasM=r.readBoolean():12===e?t.transform=function(e,t){return e.readFields(k,{quantizeOriginPostion:0,scale:void 0,translate:void 0},t)}(r,r.readVarint()+r.pos):13===e?t.fields.push(f(r,r.readVarint()+r.pos)):14===e?t.values.push(b(r,r.readVarint()+r.pos)):15===e?t.features.push(function(e,t){return e.readFields(q,{attributes:[],geometry:void 0,compressed_geometry:void 0,shapeBuffer:void 0,curveGeometry:void 0,centroid:void 0,aggregateGeometries:[],envelope:void 0},t)}(r,r.readVarint()+r.pos)):16===e&&t.geometryFields.push(function(e,t){return e.readFields(g,{field:void 0,geometryType:0},t)}(r,r.readVarint()+r.pos))}function E(e,t,r){1===e&&(t.count=r.readVarint())}function _(e,t,r){1===e?t.objectIdFieldName=r.readString():2===e?t.serverGens=O(r,r.readVarint()+r.pos):3===e&&r.readPackedVarint(t.objectIds)}function D(e,t,r){1===e?t.extent=m(r,r.readVarint()+r.pos):2===e&&(t.count=r.readVarint())}function G(e,t,r){1===e?(t.featureResult=function(e,t){return e.readFields(M,{objectIdFieldName:"",uniqueIdField:void 0,globalIdFieldName:"",geohashFieldName:"",geometryProperties:void 0,serverGens:void 0,geometryType:0,spatialReference:void 0,exceededTransferLimit:!1,hasZ:!1,hasM:!1,transform:void 0,fields:[],values:[],features:[],geometryFields:[]},t)}(r,r.readVarint()+r.pos),t.Results="featureResult"):2===e?(t.countResult=function(e,t){return e.readFields(E,{count:0},t)}(r,r.readVarint()+r.pos),t.Results="countResult"):3===e?(t.idsResult=function(e,t){return e.readFields(_,{objectIdFieldName:"",serverGens:void 0,objectIds:[]},t)}(r,r.readVarint()+r.pos),t.Results="idsResult"):4===e&&(t.extentCountResult=function(e,t){return e.readFields(D,{extent:void 0,count:0},t)}(r,r.readVarint()+r.pos),t.Results="extentCountResult")}const C=4294967296,B=1/C,A="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");class U{constructor(e=new Uint8Array(16)){this.buf=ArrayBuffer.isView(e)?e:new Uint8Array(e),this.dataView=new DataView(this.buf.buffer),this.pos=0,this.type=0,this.length=this.buf.length}readFields(e,t,r=this.length){for(;this.pos<r;){const r=this.readVarint(),s=r>>3,n=this.pos;this.type=7&r,e(s,t,this),this.pos===n&&this.skip(r)}return t}readMessage(e,t){return this.readFields(e,t,this.readVarint()+this.pos)}readFixed32(){const e=this.dataView.getUint32(this.pos,!0);return this.pos+=4,e}readSFixed32(){const e=this.dataView.getInt32(this.pos,!0);return this.pos+=4,e}readFixed64(){const e=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*C;return this.pos+=8,e}readSFixed64(){const e=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*C;return this.pos+=8,e}readFloat(){const e=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,e}readDouble(){const e=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,e}readVarint(e){const t=this.buf;let r,s;return s=t[this.pos++],r=127&s,s<128?r:(s=t[this.pos++],r|=(127&s)<<7,s<128?r:(s=t[this.pos++],r|=(127&s)<<14,s<128?r:(s=t[this.pos++],r|=(127&s)<<21,s<128?r:(s=t[this.pos],r|=(15&s)<<28,function(e,t,r){const s=r.buf;let n,i;if(i=s[r.pos++],n=(112&i)>>4,i<128)return $(e,n,t);if(i=s[r.pos++],n|=(127&i)<<3,i<128)return $(e,n,t);if(i=s[r.pos++],n|=(127&i)<<10,i<128)return $(e,n,t);if(i=s[r.pos++],n|=(127&i)<<17,i<128)return $(e,n,t);if(i=s[r.pos++],n|=(127&i)<<24,i<128)return $(e,n,t);if(i=s[r.pos++],n|=(1&i)<<31,i<128)return $(e,n,t);throw new Error("Expected varint not more than 10 bytes")}(r,e,this)))))}readVarint64(){return this.readVarint(!0)}readSVarint(){const e=this.readVarint();return e%2==1?(e+1)/-2:e/2}readBoolean(){return Boolean(this.readVarint())}readString(){const e=this.readVarint()+this.pos,t=this.pos;return this.pos=e,e-t>=12&&A?A.decode(this.buf.subarray(t,e)):function(e,t,r){let s="",n=t;for(;n<r;){const t=e[n];let i,a,o,u=null,l=t>239?4:t>223?3:t>191?2:1;if(n+l>r)break;1===l?t<128&&(u=t):2===l?(i=e[n+1],128==(192&i)&&(u=(31&t)<<6|63&i,u<=127&&(u=null))):3===l?(i=e[n+1],a=e[n+2],128==(192&i)&&128==(192&a)&&(u=(15&t)<<12|(63&i)<<6|63&a,(u<=2047||u>=55296&&u<=57343)&&(u=null))):4===l&&(i=e[n+1],a=e[n+2],o=e[n+3],128==(192&i)&&128==(192&a)&&128==(192&o)&&(u=(15&t)<<18|(63&i)<<12|(63&a)<<6|63&o,(u<=65535||u>=1114112)&&(u=null))),null===u?(u=65533,l=1):u>65535&&(u-=65536,s+=String.fromCharCode(u>>>10&1023|55296),u=56320|1023&u),s+=String.fromCharCode(u),n+=l}return s}(this.buf,t,e)}readBytes(){const e=this.readVarint()+this.pos,t=this.buf.subarray(this.pos,e);return this.pos=e,t}readPackedVarint(e=[],t){const r=this.readPackedEnd();for(;this.pos<r;)e.push(this.readVarint(t));return e}readPackedSVarint(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readSVarint());return e}readPackedBoolean(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readBoolean());return e}readPackedFloat(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readFloat());return e}readPackedDouble(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readDouble());return e}readPackedFixed32(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readFixed32());return e}readPackedSFixed32(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readSFixed32());return e}readPackedFixed64(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readFixed64());return e}readPackedSFixed64(e=[]){const t=this.readPackedEnd();for(;this.pos<t;)e.push(this.readSFixed64());return e}readPackedEnd(){return 2===this.type?this.readVarint()+this.pos:this.pos+1}skip(e){const t=7&e;if(0===t)for(;this.buf[this.pos++]>127;);else if(2===t)this.pos=this.readVarint()+this.pos;else if(5===t)this.pos+=4;else{if(1!==t)throw new Error(`Unimplemented type: ${t}`);this.pos+=8}}writeTag(e,t){this.writeVarint(e<<3|t)}realloc(e){let t=this.length||16;for(;t<this.pos+e;)t*=2;if(t!==this.length){const e=new Uint8Array(t);e.set(this.buf),this.buf=e,this.dataView=new DataView(e.buffer),this.length=t}}finish(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)}writeFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeSFixed32(e){this.realloc(4),this.dataView.setInt32(this.pos,e,!0),this.pos+=4}writeFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,-1&e,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*B),!0),this.pos+=8}writeSFixed64(e){this.realloc(8),this.dataView.setInt32(this.pos,-1&e,!0),this.dataView.setInt32(this.pos+4,Math.floor(e*B),!0),this.pos+=8}writeVarint(e){(e=+e||0)>268435455||e<0?function(e,t){let r,s;e>=0?(r=e%4294967296|0,s=e/4294967296|0):(r=~(-e%4294967296),s=~(-e/4294967296),4294967295^r?r=r+1|0:(r=0,s=s+1|0));if(e>=0x10000000000000000||e<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");t.realloc(10),function(e,t,r){r.buf[r.pos++]=127&e|128,e>>>=7,r.buf[r.pos++]=127&e|128,e>>>=7,r.buf[r.pos++]=127&e|128,e>>>=7,r.buf[r.pos++]=127&e|128,e>>>=7,r.buf[r.pos]=127&e}(r,0,t),function(e,t){const r=(7&e)<<4;if(t.buf[t.pos++]|=r|((e>>>=3)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;t.buf[t.pos++]=127&e}(s,t)}(e,this):(this.realloc(4),this.buf[this.pos++]=127&e|(e>127?128:0),e<=127||(this.buf[this.pos++]=127&(e>>>=7)|(e>127?128:0),e<=127||(this.buf[this.pos++]=127&(e>>>=7)|(e>127?128:0),e<=127||(this.buf[this.pos++]=e>>>7&127))))}writeSVarint(e){this.writeVarint(e<0?2*-e-1:2*e)}writeBoolean(e){this.writeVarint(+e)}writeString(e){e=String(e),this.realloc(4*e.length),this.pos++;const t=this.pos;this.pos=function(e,t,r){for(let s,n,i=0;i<t.length;i++){if(s=t.charCodeAt(i),s>55295&&s<57344){if(!n){s>56319||i+1===t.length?(e[r++]=239,e[r++]=191,e[r++]=189):n=s;continue}if(s<56320){e[r++]=239,e[r++]=191,e[r++]=189,n=s;continue}s=n-55296<<10|s-56320|65536,n=null}else n&&(e[r++]=239,e[r++]=191,e[r++]=189,n=null);s<128?e[r++]=s:(s<2048?e[r++]=s>>6|192:(s<65536?e[r++]=s>>12|224:(e[r++]=s>>18|240,e[r++]=s>>12&63|128),e[r++]=s>>6&63|128),e[r++]=63&s|128)}return r}(this.buf,e,this.pos);const r=this.pos-t;r>=128&&N(t,r,this),this.pos=t-1,this.writeVarint(r),this.pos+=r}writeFloat(e){this.realloc(4),this.dataView.setFloat32(this.pos,e,!0),this.pos+=4}writeDouble(e){this.realloc(8),this.dataView.setFloat64(this.pos,e,!0),this.pos+=8}writeBytes(e){const t=e.length;this.writeVarint(t),this.realloc(t);for(let r=0;r<t;r++)this.buf[this.pos++]=e[r]}writeRawMessage(e,t){this.pos++;const r=this.pos;e(t,this);const s=this.pos-r;s>=128&&N(r,s,this),this.pos=r-1,this.writeVarint(s),this.pos+=s}writeMessage(e,t,r){this.writeTag(e,2),this.writeRawMessage(t,r)}writePackedVarint(e,t){t.length&&this.writeMessage(e,L,t)}writePackedSVarint(e,t){t.length&&this.writeMessage(e,z,t)}writePackedBoolean(e,t){t.length&&this.writeMessage(e,Y,t)}writePackedFloat(e,t){t.length&&this.writeMessage(e,W,t)}writePackedDouble(e,t){t.length&&this.writeMessage(e,X,t)}writePackedFixed32(e,t){t.length&&this.writeMessage(e,Z,t)}writePackedSFixed32(e,t){t.length&&this.writeMessage(e,J,t)}writePackedFixed64(e,t){t.length&&this.writeMessage(e,H,t)}writePackedSFixed64(e,t){t.length&&this.writeMessage(e,K,t)}writeBytesField(e,t){this.writeTag(e,2),this.writeBytes(t)}writeFixed32Field(e,t){this.writeTag(e,5),this.writeFixed32(t)}writeSFixed32Field(e,t){this.writeTag(e,5),this.writeSFixed32(t)}writeFixed64Field(e,t){this.writeTag(e,1),this.writeFixed64(t)}writeSFixed64Field(e,t){this.writeTag(e,1),this.writeSFixed64(t)}writeVarintField(e,t){this.writeTag(e,0),this.writeVarint(t)}writeSVarintField(e,t){this.writeTag(e,0),this.writeSVarint(t)}writeStringField(e,t){this.writeTag(e,2),this.writeString(t)}writeFloatField(e,t){this.writeTag(e,5),this.writeFloat(t)}writeDoubleField(e,t){this.writeTag(e,1),this.writeDouble(t)}writeBooleanField(e,t){this.writeVarintField(e,+t)}}function $(e,t,r){return r?4294967296*t+(e>>>0):4294967296*(t>>>0)+(e>>>0)}function N(e,t,r){const s=t<=16383?1:t<=2097151?2:t<=268435455?3:Math.floor(Math.log(t)/(7*Math.LN2));r.realloc(s);for(let t=r.pos-1;t>=e;t--)r.buf[t+s]=r.buf[t]}function L(e,t){for(let r=0;r<e.length;r++)t.writeVarint(e[r])}function z(e,t){for(let r=0;r<e.length;r++)t.writeSVarint(e[r])}function W(e,t){for(let r=0;r<e.length;r++)t.writeFloat(e[r])}function X(e,t){for(let r=0;r<e.length;r++)t.writeDouble(e[r])}function Y(e,t){for(let r=0;r<e.length;r++)t.writeBoolean(e[r])}function Z(e,t){for(let r=0;r<e.length;r++)t.writeFixed32(e[r])}function J(e,t){for(let r=0;r<e.length;r++)t.writeSFixed32(e[r])}function H(e,t){for(let r=0;r<e.length;r++)t.writeFixed64(e[r])}function K(e,t){for(let r=0;r<e.length;r++)t.writeSFixed64(e[r])}function Q(e){return function(e){let r;try{r=o(new U(e))}catch(e){
/* istanbul ignore next --@preserve */
throw new Error(`Could not parse arcgis-pbf buffer: ${e}`)}if(!r.queryResult)throw new Error("Could not parse arcgis-pbf buffer: Missing queryResult.");const s=r.queryResult.featureResult,n=s.transform,i=s.geometryType,a=s.objectIdFieldName,u={type:"FeatureCollection",features:[]};u.properties={exceededTransferLimit:s.exceededTransferLimit};const l=function(e){switch(e){case 3:
/* istanbul ignore next --@preserve */
default:return re;case 2:return te;case 0:return ee}}(i),d=s.fields;if(d.forEach(e=>{e.keyName=function(e){switch(e.fieldType){case 1:return"sintValue";case 2:return"floatValue";case 3:return"doubleValue";case 4:return"stringValue";
/* istanbul ignore next --@preserve */case 5:return"sint64Value";case 6:return"uintValue";default:return null}}
/* istanbul ignore next --@preserve */(e)}),d.every(e=>e.name!==a))throw new t.ArcGISRequestError(`objectIdField '${a}' was not found.`,400);const c=s.features.length;for(let e=0;e<c;e++){const t=s.features[e];u.features.push({type:"Feature",properties:ie(d,t.attributes),geometry:t.geometry&&l(t,n)||null})}return u.features.forEach((e,t)=>{e.id=e.properties[a]}),u}(e)}function ee(e,t){return{type:"Point",coordinates:ae(e.geometry.coords,t)}}function te(e,t){let r=null;const s=e.geometry.lengths.length;
/* istanbul ignore else if --@preserve */if(1===s)r={type:"LineString",coordinates:ne(e.geometry.coords,t,0,2*e.geometry.lengths[0])};else if(s>1){r={type:"MultiLineString",coordinates:[]};let n=0;for(let i=0;i<s;i++){const s=n+2*e.geometry.lengths[i],a=ne(e.geometry.coords,t,n,s);r.coordinates.push(a),n=s}}return r}function re(e,t){const r=e.geometry.lengths.length,s={type:"Polygon",coordinates:[]};if(1===r)s.coordinates.push(ne(e.geometry.coords,t,0,2*e.geometry.lengths[0]));else{s.type="MultiPolygon";let n=0;for(let i=0;i<r;i++){const r=n+2*e.geometry.lengths[i],a=ne(e.geometry.coords,t,n,r);
/* istanbul ignore else if --@preserve */
se(a)?s.coordinates.push([a]):s.coordinates.length>0&&s.coordinates[s.coordinates.length-1].push(a),n=r}}return s}function se(e){let t=0,r=0;const s=e.length;let n,i=e[r];for(;r<s-1;r++)n=e[r+1],t+=(n[0]-i[0])*(n[1]+i[1]),i=n;return t>=0}function ne(e,t,r,s){const n=[];
/* istanbul ignore if --@preserve */if(0===e.length)return n;const i=e[r],a=e[r+1];n.push(ae([i,a],t));let o=i,u=a;for(let i=r+2;i<s;i+=2){const r=oe(o,e[i]),s=oe(u,e[i+1]),a=ae([r,s],t);n.push(a),o=r,u=s}return n}function ie(e,t){const r={};for(let s=0;s<e.length;s++){const n=e[s];void 0!==t[s][t[s].value_type]?r[n.name]=t[s][t[s].value_type]:r[n.name]=null}return r}function ae(e,t){let r=e[0],s=e[1],n=e[2]?e[2]:void 0;t.scale&&(r*=t.scale.xScale,s*=-t.scale.yScale,void 0!==n&&(n*=t.scale.zScale)),t.translate&&(r+=t.translate.xTranslate,s+=t.translate.yTranslate,void 0!==n&&(n+=t.translate.zTranslate));const i=[r,s];return void 0!==n&&i.push(n),i}function oe(e,t){return e+t}function ue(e){const r=function(e){let t;try{t=o(new U(e))}catch(e){
/* istanbul ignore next --@preserve */
throw new Error(`Could not parse arcgis-pbf buffer: ${e}`)}if(!t.queryResult)throw new Error("Could not parse arcgis-pbf buffer: Missing queryResult.");return t}(e),s=r.queryResult.featureResult,n=r.queryResult.featureResult.transform,i=r.queryResult.featureResult.geometryType,a=Object.assign(Object.assign({},s),{geometryType:pe(i)});var u;if(a.spatialReference&&(a.spatialReference=(u=a.spatialReference,Object.fromEntries(Object.entries(u).filter(([,e])=>0!==e&&""!==e)))),a.fields=function(e){const t=le(l),r=le(d);return e.map(e=>function(e,t,r){const s=[["alias",e=>e.alias],["sqlType",e=>r[e.sqlType]],["domain",e=>""===e.domain?null:JSON.parse(e.domain)],["length",e=>0===e.length?void 0:e.length],["editable",e=>e.editable],["exactMatch",e=>e.exactMatch],["nullable",e=>e.nullable],["defaultValue",e=>""===e.defaultValue?null:e.defaultValue]],n={name:e.name,type:t[e.fieldType]};for(const[t,r]of s)if(void 0!==e[t]){const s=r(e);void 0!==s&&(n[t]=s)}return n}(e,t,r))}(s.fields),a.fields.every(e=>e.name!==s.objectIdFieldName))throw new t.ArcGISRequestError(`objectIdField '${s.objectIdFieldName}' was not found.`,400);const c=s.fields.map(e=>Object.assign(Object.assign({},e),{keyName:de(e)})),p=function(e){switch(e){case 3:
/* istanbul ignore next --@preserve */
default:return ge;case 2:return he;case 0:return fe}}(i);a.features=s.features.map(e=>({attributes:ce(c,e.attributes),geometry:e.geometry&&p(e,n)||null}));const f=function(e){const t=["serverGens","geohashFieldName","transform","values"],r={};return Object.keys(e).forEach(s=>{t.includes(s)||void 0===e[s]||(r[s]=e[s])}),r}(a);return f}function le(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function de(e){switch(e.fieldType){case 1:return"sintValue";case 2:return"floatValue";case 3:return"doubleValue";case 4:return"stringValue";
/* istanbul ignore next --@preserve */case 5:return"sint64Value";case 6:return"uintValue";default:return null}}function ce(e,t){const r={};for(let s=0;s<e.length;s++){const n=e[s];void 0!==t[s][t[s].value_type]?r[n.name]=t[s][t[s].value_type]:r[n.name]=null}return r}function pe(e){switch(e){case 0:return"esriGeometryPoint";case 2:return"esriGeometryPolyline";case 3:return"esriGeometryPolygon";default:throw new t.ArcGISRequestError("Geometry type not supported.",501)}}function fe(e,t){const r={coordinates:be(e.geometry.coords,t)},s={x:r.coordinates[0],y:r.coordinates[1]};return r.coordinates.length>2?Object.assign(Object.assign({},s),{z:r.coordinates[2]}):s}function he(e,t){let r=null;const s=e.geometry.lengths.length;
/* istanbul ignore else if --@preserve */if(1===s)return r={type:"LineString",coordinates:ye(e.geometry.coords,t,0,2*e.geometry.lengths[0])},{paths:[r.coordinates]};if(s>1){r={type:"MultiLineString",coordinates:[]};let n=0;for(let i=0;i<s;i++){const s=n+2*e.geometry.lengths[i],a=ye(e.geometry.coords,t,n,s);r.coordinates.push(a),n=s}return{paths:r.coordinates}}}function ge(e,t){const r=e.geometry.lengths.length,s={type:"Polygon",coordinates:[]};if(1===r)s.coordinates.push(ye(e.geometry.coords,t,0,2*e.geometry.lengths[0]));else{s.type="MultiPolygon";let n=0;for(let i=0;i<r;i++){const r=n+2*e.geometry.lengths[i],a=ye(e.geometry.coords,t,n,r);
/* istanbul ignore else if --@preserve */
me(a)?s.coordinates.push([a]):s.coordinates.length>0&&s.coordinates[s.coordinates.length-1].push(a),n=r}}return{rings:s.coordinates}}function me(e){let t=0,r=0;const s=e.length;let n,i=e[r];for(;r<s-1;r++)n=e[r+1],t+=(n[0]-i[0])*(n[1]+i[1]),i=n;return t>=0}function ye(e,t,r,s){const n=[];
/* istanbul ignore if --@preserve */if(0===e.length)return n;const i=e[r],a=e[r+1];n.push(be([i,a],t));let o=i,u=a;for(let i=r+2;i<s;i+=2){const r=we(o,e[i]),s=we(u,e[i+1]),a=be([r,s],t);n.push(a),o=r,u=s}return n}
/* istanbul ignore next --@preserve */function be(e,t){let r=e[0],s=e[1],n=e[2]?e[2]:void 0;t.scale&&(r*=t.scale.xScale,s*=-t.scale.yScale,void 0!==n&&(n*=t.scale.zScale)),t.translate&&(r+=t.translate.xTranslate,s+=t.translate.yTranslate,void 0!==n&&(n+=t.translate.zTranslate));const i=[r,s];return void 0!==n&&i.push(n),i}function we(e,t){return e+t}function Fe(e,r){if("pbf-as-geojson"===r.params.f&&r.params.outSR&&"4326"!==r.params.outSR)throw new t.ArcGISRequestError("Unsupported outSR for GeoJSON requests.",422,null,e,r);const s="pbf-as-geojson"===r.params.f?{outSR:"4326"}:{},n=Object.assign(Object.assign({},r),{params:Object.assign(Object.assign(Object.assign({},r.params),s),{f:"pbf"}),rawResponse:!0});return t.request(`${t.cleanUrl(e)}/query`,n).then(async s=>{var i;if(null===(i=s.headers.get("content-type"))||void 0===i?void 0:i.includes("application/json")){const r=(await s.json()).error;if(498===(null==r?void 0:r.code)||499===(null==r?void 0:r.code))throw new t.ArcGISAuthError(r.message,r.code,s,e,n);throw new t.ArcGISRequestError(r.message,r.code,s,e,n)}try{const e=await s.arrayBuffer();
/* istanbul ignore else --@preserve */if("pbf-as-arcgis"===r.params.f)return ue(e);
/* istanbul ignore else --@preserve */if("pbf-as-geojson"===r.params.f)return Q(e)}catch(r){throw r instanceof t.ArcGISRequestError?(r.response=s,r.url=e,r.options=n,r):new t.ArcGISRequestError("Unable to decode pbf response.",500,s,e,n)}})}e.addAttachment=function(e){const r=Object.assign({params:{}},e);return r.params.attachment=e.attachment,t.request(`${t.cleanUrl(r.url)}/${r.featureId}/addAttachment`,r)},e.addFeatures=function(e){const r=`${t.cleanUrl(e.url)}/addFeatures`,s=t.appendCustomParams(e,["features","gdbVersion","returnEditMoment","rollbackOnFailure"],{params:Object.assign({},e.params)});return t.request(r,s)},e.addToServiceDefinition=function(e,r){const s=`${t.cleanUrl(e).replace("/rest/services","/rest/admin/services")}/addToDefinition`;return r.params=Object.assign({addToDefinition:{}},r.params),r.layers&&r.layers.length>0&&(r.params.addToDefinition.layers=r.layers),r.tables&&r.tables.length>0&&(r.params.addToDefinition.tables=r.tables),t.request(s,r)},e.applyEdits=function(e){const r=`${t.cleanUrl(e.url)}/applyEdits`,s=t.appendCustomParams(e,["adds","updates","deletes","useGlobalIds","attachments","gdbVersion","returnEditMoment","rollbackOnFailure","trueCurveClient"],{params:Object.assign({},e.params)});return t.request(r,s)},e.createFeatureService=function(e){return r.determineOwner(e).then(s=>{const n=Object.assign(Object.assign({},e),{rawResponse:!1}),i=`${`${r.getPortalUrl(e)}/content/users/${s}`}${n.folderId&&"/"!==n.folderId?"/"+n.folderId:""}/createService`;return n.params=Object.assign({createParameters:n.item,outputType:"featureService"},n.params),t.request(i,n)})},e.decodeValues=function(e){let t;return t=e.fields?Promise.resolve(e.fields):s({url:e.url}).then(e=>e.fields),t.then(t=>{const r=function(e){return e.reduce((e,t)=>{const r=t.domain;return r&&"codedValue"===r.type&&(e[t.name]=r),e},{})}(t);if(Object.keys(r).length<1)return e.queryResponse;const s=e.queryResponse.features.map(e=>{const t={};for(const s in e.attributes){if(!Object.prototype.hasOwnProperty.call(e.attributes,s))continue;const i=e.attributes[s],a=r[s];t[s]=null!==i&&a?n(i,a):i}return Object.assign(Object.assign({},e),{attributes:t})});return Object.assign(Object.assign({},e.queryResponse),{features:s})})},e.deleteAttachments=function(e){const r=Object.assign({params:{}},e);return r.params.attachmentIds=e.attachmentIds,t.request(`${t.cleanUrl(r.url)}/${r.featureId}/deleteAttachments`,r)},e.deleteFeatures=function(e){const r=`${t.cleanUrl(e.url)}/deleteFeatures`,s=t.appendCustomParams(e,["where","objectIds","gdbVersion","returnEditMoment","rollbackOnFailure"],{params:Object.assign({},e.params)});return t.request(r,s)},e.getAllLayersAndTables=function(e){const{url:r}=e,s=function(e,t){var r={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(r[s[n]]=e[s[n]])}return r}(e,["url"]),n=`${a(r)}/layers`;return t.request(n,s)},e.getAttachments=function(e){const r=Object.assign({httpMethod:"GET"},e);return t.request(`${t.cleanUrl(r.url)}/${r.featureId}/attachments`,r)},e.getFeature=function(e){const r=`${t.cleanUrl(e.url)}/${e.id}`,s=Object.assign({httpMethod:"GET"},e);return t.request(r,s).then(e=>s.rawResponse?e:e.feature)},e.getLayer=s,e.getService=function(e){return t.request(t.cleanUrl(e.url),e)},e.getServiceAdminInfo=function(e,r){const s=e.replace("/rest/services","/rest/admin/services");return t.request(s,{authentication:r,params:{f:"json"}})},e.getViewSources=function(e,r){return t.request(`${e}/sources`,{authentication:r})},e.parseServiceUrl=a,e.queryAllFeatures=async function(e){var r,s,n,i;let a=!0,o=0,u=!0,l=null;const d=e.resultRecordCount||(null===(r=e.params)||void 0===r?void 0:r.resultRecordCount);if(d&&d>=1e5)throw new t.ArcGISRequestError("resultRecordCount must be less than 100,000.",400,null,e.url,e);let c;if(d)c=d;else{c=(await t.request(e.url,{httpMethod:"GET",authentication:e.authentication})).maxRecordCount||2e3}for(;u;){const r=Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({where:"1=1",outFields:"*"},e.params||{}),{resultOffset:o,resultRecordCount:c})}),d=t.appendCustomParams(r,["where","objectIds","relationParam","time","distance","units","outFields","geometry","geometryType","spatialRel","returnGeometry","maxAllowableOffset","geometryPrecision","inSR","outSR","gdbVersion","orderByFields","groupByFieldsForStatistics","outStatistics","returnZ","returnM","multipatchOption","resultOffset","resultRecordCount","maxRecordCountFactor","quantizationParameters","resultType","historicMoment","returnTrueCurves","sqlFormat","f"],{httpMethod:"GET",params:Object.assign({where:"1=1",outFields:"*",returnExceededLimitFeatures:!0},r.params)});let p;p="pbf-as-geojson"===(null===(s=d.params)||void 0===s?void 0:s.f)||"pbf-as-arcgis"===(null===(n=d.params)||void 0===n?void 0:n.f)?await Fe(e.url,d):await t.request(`${t.cleanUrl(e.url)}/query`,d),l?l.features=l.features.concat(p.features):l=Object.assign({},p);const f=p.features.length;a&&(a=!1,f>0&&f<c&&(c=f));const h=p.exceededTransferLimit||(null===(i=p.properties)||void 0===i?void 0:i.exceededTransferLimit);f<c||!h?u=!1:o+=c}return l},e.queryFeatures=function(e){var r,s;const n=t.appendCustomParams(e,["where","objectIds","relationParam","time","distance","units","outFields","geometry","geometryType","spatialRel","returnGeometry","maxAllowableOffset","geometryPrecision","inSR","outSR","gdbVersion","returnDistinctValues","returnIdsOnly","returnCountOnly","returnExtentOnly","orderByFields","groupByFieldsForStatistics","outStatistics","returnZ","returnM","multipatchOption","resultOffset","resultRecordCount","quantizationParameters","returnCentroid","resultType","historicMoment","returnTrueCurves","sqlFormat","returnExceededLimitFeatures","f"],{httpMethod:"GET",params:Object.assign({where:"1=1",outFields:"*"},e.params)});return"pbf-as-geojson"===(null===(r=n.params)||void 0===r?void 0:r.f)||"pbf-as-arcgis"===(null===(s=n.params)||void 0===s?void 0:s.f)?Fe(e.url,n):t.request(`${t.cleanUrl(e.url)}/query`,n)},e.queryPbfAsGeoJSONOrArcGIS=Fe,e.queryRelated=function(e){const r=t.appendCustomParams(e,["objectIds","relationshipId","definitionExpression","outFields"],{httpMethod:"GET",params:Object.assign({definitionExpression:"1=1",outFields:"*",relationshipId:0},e.params)});return t.request(`${t.cleanUrl(e.url)}/queryRelatedRecords`,r)},e.updateAttachment=function(e){const r=Object.assign({params:{}},e);return r.params.attachment=e.attachment,r.params.attachmentId=e.attachmentId,t.request(`${t.cleanUrl(r.url)}/${r.featureId}/updateAttachment`,r)},e.updateFeatures=function(e){const r=`${t.cleanUrl(e.url)}/updateFeatures`,s=t.appendCustomParams(e,["features","gdbVersion","returnEditMoment","rollbackOnFailure","trueCurveClient"],{params:Object.assign({},e.params)});return t.request(r,s)},e.updateServiceDefinition=function(e,r){const s=`${t.cleanUrl(e).replace("/rest/services","/rest/admin/services")}/updateDefinition`;return r.params=Object.assign({updateDefinition:{}},r.params),r.updateDefinition&&(r.params.updateDefinition=r.updateDefinition),t.request(s,r)}});
//# sourceMappingURL=feature-service.umd.min.js.map