@esri/arcgis-rest-feature-service
Version:
Feature layer query and edit helpers for @esri/arcgis-rest-js
31 lines (30 loc) • 32.3 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)
*/
import{cleanUrl as e,appendCustomParams as t,request as r,ArcGISRequestError as s,ArcGISAuthError as n}from"@esri/arcgis-rest-request";import{determineOwner as i,getPortalUrl as a}from"@esri/arcgis-rest-portal";function o(s){const n=`${e(s.url)}/addFeatures`,i=t(s,["features","gdbVersion","returnEditMoment","rollbackOnFailure"],{params:Object.assign({},s.params)});return r(n,i)}function l(t){const s=Object.assign({params:{}},t);return s.params.attachment=t.attachment,r(`${e(s.url)}/${s.featureId}/addAttachment`,s)}function u(t,s){const n=`${e(t).replace("/rest/services","/rest/admin/services")}/addToDefinition`;return s.params=Object.assign({addToDefinition:{}},s.params),s.layers&&s.layers.length>0&&(s.params.addToDefinition.layers=s.layers),s.tables&&s.tables.length>0&&(s.params.addToDefinition.tables=s.tables),r(n,s)}function d(s){const n=`${e(s.url)}/applyEdits`,i=t(s,["adds","updates","deletes","useGlobalIds","attachments","gdbVersion","returnEditMoment","rollbackOnFailure","trueCurveClient"],{params:Object.assign({},s.params)});return r(n,i)}function c(e){return i(e).then(t=>{const s=Object.assign(Object.assign({},e),{rawResponse:!1}),n=`${`${a(e)}/content/users/${t}`}${s.folderId&&"/"!==s.folderId?"/"+s.folderId:""}/createService`;return s.params=Object.assign({createParameters:s.item,outputType:"featureService"},s.params),r(n,s)})}function p(t){return r(e(t.url),t)}function h(e){let t;return t=e.fields?Promise.resolve(e.fields):p({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 n=e.attributes[s],i=r[s];t[s]=null!==n&&i?f(n,i):n}return Object.assign(Object.assign({},e),{attributes:t})});return Object.assign(Object.assign({},e.queryResponse),{features:s})})}function f(e,t){const r=t.codedValues.find(t=>e===t.code);return r?r.name:e}function g(s){const n=`${e(s.url)}/deleteFeatures`,i=t(s,["where","objectIds","gdbVersion","returnEditMoment","rollbackOnFailure"],{params:Object.assign({},s.params)});return r(n,i)}function y(t){const s=Object.assign({params:{}},t);return s.params.attachmentIds=t.attachmentIds,r(`${e(s.url)}/${s.featureId}/deleteAttachments`,s)}const m=new RegExp(/.+(?:map|feature|image)server/i);function b(t){const r=t.match(m);return r?r[0]:function(t){const r=t.split("?")[0];return e(r)}(t)}function w(e){const{url:t}=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=`${b(t)}/layers`;return r(n,s)}function F(t){const s=Object.assign({httpMethod:"GET"},t);return r(`${e(s.url)}/${s.featureId}/attachments`,s)}function v(t){return r(e(t.url),t)}function V(e,t){const s=e.replace("/rest/services","/rest/admin/services");return r(s,{authentication:t,params:{f:"json"}})}function T(e,t){return r(`${e}/sources`,{authentication:t})}
/* istanbul ignore file --@preserve */function S(e,t){return e.readFields(x,{version:"",queryResult:void 0},t)}function x(e,t,r){1===e?t.version=r.readString():2===e&&(t.queryResult=function(e,t){return e.readFields(ee,{featureResult:void 0,Results:void 0,countResult:void 0,idsResult:void 0,extentCountResult:void 0},t)}(r,r.readVarint()+r.pos))}const O={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},j={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 R(e,t){return e.readFields(q,{wkid:0,latestWkid:0,vcsWkid:0,latestVcsWkid:0,wkt:"",wkt2:""},t)}function q(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 P(e,t){return e.readFields(k,{name:"",fieldType:0,alias:"",sqlType:0,domain:"",defaultValue:""},t)}function k(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 I(e,t,r){1===e?t.field=P(r,r.readVarint()+r.pos):2===e&&(t.geometryType=r.readVarint())}function M(e,t){return e.readFields(_,{XMin:0,YMin:0,XMax:0,YMax:0,SpatialReference:void 0},t)}function _(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=R(r,r.readVarint()+r.pos))}function D(e,t){return e.readFields(E,{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 E(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 G(e,t){return e.readFields(B,{geometryType:0,lengths:[],coords:[],ids:[]},t)}function B(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 C(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($,{type:0,count:0,parameters:[]},t)}(r,r.readVarint()+r.pos)):4===e&&r.readPackedSVarint(t.coords)}function $(e,t,r){1===e?t.type=r.readVarint():2===e?t.count=r.readVarint():3===e&&r.readPackedDouble(t.parameters)}function N(e,t,r){1===e&&(t.bytes=r.readBytes())}function L(e,t,r){1===e?t.attributes.push(D(r,r.readVarint()+r.pos)):2===e?(t.geometry=G(r,r.readVarint()+r.pos),t.compressed_geometry="geometry"):3===e?(t.shapeBuffer=function(e,t){return e.readFields(N,{bytes:void 0},t)}(r,r.readVarint()+r.pos),t.compressed_geometry="shapeBuffer"):7===e?(t.curveGeometry=function(e,t){return e.readFields(C,{geometryType:0,parts:[],segmentSets:[],coords:[]},t)}(r,r.readVarint()+r.pos),t.compressed_geometry="curveGeometry"):4===e?t.centroid=G(r,r.readVarint()+r.pos):5===e?t.aggregateGeometries.push(G(r,r.readVarint()+r.pos)):6===e&&(t.envelope=M(r,r.readVarint()+r.pos))}function z(e,t,r){1===e?t.name=r.readString():2===e&&(t.isSystemMaintained=r.readBoolean())}function A(e,t,r){1===e?t.shapeAreaFieldName=r.readString():2===e?t.shapeLengthFieldName=r.readString():3===e&&(t.units=r.readString())}function U(e,t){return e.readFields(W,{minServerGen:0,serverGen:0},t)}function W(e,t,r){1===e?t.minServerGen=r.readVarint():2===e&&(t.serverGen=r.readVarint())}function X(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 Y(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 Z(e,t,r){1===e?t.quantizeOriginPostion=r.readVarint():2===e?t.scale=function(e,t){return e.readFields(X,{xScale:0,yScale:0,mScale:0,zScale:0},t)}(r,r.readVarint()+r.pos):3===e&&(t.translate=function(e,t){return e.readFields(Y,{xTranslate:0,yTranslate:0,mTranslate:0,zTranslate:0},t)}(r,r.readVarint()+r.pos))}function J(e,t,r){1===e?t.objectIdFieldName=r.readString():2===e?t.uniqueIdField=function(e,t){return e.readFields(z,{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(A,{shapeAreaFieldName:"",shapeLengthFieldName:"",units:""},t)}(r,r.readVarint()+r.pos):6===e?t.serverGens=U(r,r.readVarint()+r.pos):7===e?t.geometryType=r.readVarint():8===e?t.spatialReference=R(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(Z,{quantizeOriginPostion:0,scale:void 0,translate:void 0},t)}(r,r.readVarint()+r.pos):13===e?t.fields.push(P(r,r.readVarint()+r.pos)):14===e?t.values.push(D(r,r.readVarint()+r.pos)):15===e?t.features.push(function(e,t){return e.readFields(L,{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(I,{field:void 0,geometryType:0},t)}(r,r.readVarint()+r.pos))}function H(e,t,r){1===e&&(t.count=r.readVarint())}function K(e,t,r){1===e?t.objectIdFieldName=r.readString():2===e?t.serverGens=U(r,r.readVarint()+r.pos):3===e&&r.readPackedVarint(t.objectIds)}function Q(e,t,r){1===e?t.extent=M(r,r.readVarint()+r.pos):2===e&&(t.count=r.readVarint())}function ee(e,t,r){1===e?(t.featureResult=function(e,t){return e.readFields(J,{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(H,{count:0},t)}(r,r.readVarint()+r.pos),t.Results="countResult"):3===e?(t.idsResult=function(e,t){return e.readFields(K,{objectIdFieldName:"",serverGens:void 0,objectIds:[]},t)}(r,r.readVarint()+r.pos),t.Results="idsResult"):4===e&&(t.extentCountResult=function(e,t){return e.readFields(Q,{extent:void 0,count:0},t)}(r,r.readVarint()+r.pos),t.Results="extentCountResult")}const te=4294967296,re=1/te,se="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");class ne{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)*te;return this.pos+=8,e}readSFixed64(){const e=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*te;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 ie(e,n,t);if(i=s[r.pos++],n|=(127&i)<<3,i<128)return ie(e,n,t);if(i=s[r.pos++],n|=(127&i)<<10,i<128)return ie(e,n,t);if(i=s[r.pos++],n|=(127&i)<<17,i<128)return ie(e,n,t);if(i=s[r.pos++],n|=(127&i)<<24,i<128)return ie(e,n,t);if(i=s[r.pos++],n|=(1&i)<<31,i<128)return ie(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&&se?se.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,l=null,u=t>239?4:t>223?3:t>191?2:1;if(n+u>r)break;1===u?t<128&&(l=t):2===u?(i=e[n+1],128==(192&i)&&(l=(31&t)<<6|63&i,l<=127&&(l=null))):3===u?(i=e[n+1],a=e[n+2],128==(192&i)&&128==(192&a)&&(l=(15&t)<<12|(63&i)<<6|63&a,(l<=2047||l>=55296&&l<=57343)&&(l=null))):4===u&&(i=e[n+1],a=e[n+2],o=e[n+3],128==(192&i)&&128==(192&a)&&128==(192&o)&&(l=(15&t)<<18|(63&i)<<12|(63&a)<<6|63&o,(l<=65535||l>=1114112)&&(l=null))),null===l?(l=65533,u=1):l>65535&&(l-=65536,s+=String.fromCharCode(l>>>10&1023|55296),l=56320|1023&l),s+=String.fromCharCode(l),n+=u}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*re),!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*re),!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&&ae(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&&ae(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,oe,t)}writePackedSVarint(e,t){t.length&&this.writeMessage(e,le,t)}writePackedBoolean(e,t){t.length&&this.writeMessage(e,ce,t)}writePackedFloat(e,t){t.length&&this.writeMessage(e,ue,t)}writePackedDouble(e,t){t.length&&this.writeMessage(e,de,t)}writePackedFixed32(e,t){t.length&&this.writeMessage(e,pe,t)}writePackedSFixed32(e,t){t.length&&this.writeMessage(e,he,t)}writePackedFixed64(e,t){t.length&&this.writeMessage(e,fe,t)}writePackedSFixed64(e,t){t.length&&this.writeMessage(e,ge,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 ie(e,t,r){return r?4294967296*t+(e>>>0):4294967296*(t>>>0)+(e>>>0)}function ae(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 oe(e,t){for(let r=0;r<e.length;r++)t.writeVarint(e[r])}function le(e,t){for(let r=0;r<e.length;r++)t.writeSVarint(e[r])}function ue(e,t){for(let r=0;r<e.length;r++)t.writeFloat(e[r])}function de(e,t){for(let r=0;r<e.length;r++)t.writeDouble(e[r])}function ce(e,t){for(let r=0;r<e.length;r++)t.writeBoolean(e[r])}function pe(e,t){for(let r=0;r<e.length;r++)t.writeFixed32(e[r])}function he(e,t){for(let r=0;r<e.length;r++)t.writeSFixed32(e[r])}function fe(e,t){for(let r=0;r<e.length;r++)t.writeFixed64(e[r])}function ge(e,t){for(let r=0;r<e.length;r++)t.writeSFixed64(e[r])}function ye(e){return function(e){let t;try{t=S(new ne(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.");const r=t.queryResult.featureResult,n=r.transform,i=r.geometryType,a=r.objectIdFieldName,o={type:"FeatureCollection",features:[]};o.properties={exceededTransferLimit:r.exceededTransferLimit};const l=function(e){switch(e){case 3:
/* istanbul ignore next --@preserve */
default:return we;case 2:return be;case 0:return me}}(i),u=r.fields;if(u.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)}),u.every(e=>e.name!==a))throw new s(`objectIdField '${a}' was not found.`,400);const d=r.features.length;for(let e=0;e<d;e++){const t=r.features[e];o.features.push({type:"Feature",properties:Ve(u,t.attributes),geometry:t.geometry&&l(t,n)||null})}return o.features.forEach((e,t)=>{e.id=e.properties[a]}),o}(e)}function me(e,t){return{type:"Point",coordinates:Te(e.geometry.coords,t)}}function be(e,t){let r=null;const s=e.geometry.lengths.length;
/* istanbul ignore else if --@preserve */if(1===s)r={type:"LineString",coordinates:ve(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=ve(e.geometry.coords,t,n,s);r.coordinates.push(a),n=s}}return r}function we(e,t){const r=e.geometry.lengths.length,s={type:"Polygon",coordinates:[]};if(1===r)s.coordinates.push(ve(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=ve(e.geometry.coords,t,n,r);
/* istanbul ignore else if --@preserve */
Fe(a)?s.coordinates.push([a]):s.coordinates.length>0&&s.coordinates[s.coordinates.length-1].push(a),n=r}}return s}function Fe(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 ve(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(Te([i,a],t));let o=i,l=a;for(let i=r+2;i<s;i+=2){const r=Se(o,e[i]),s=Se(l,e[i+1]),a=Te([r,s],t);n.push(a),o=r,l=s}return n}function Ve(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 Te(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 Se(e,t){return e+t}function xe(e){const t=function(e){let t;try{t=S(new ne(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),r=t.queryResult.featureResult,n=t.queryResult.featureResult.transform,i=t.queryResult.featureResult.geometryType,a=Object.assign(Object.assign({},r),{geometryType:qe(i)});var o;if(a.spatialReference&&(a.spatialReference=(o=a.spatialReference,Object.fromEntries(Object.entries(o).filter(([,e])=>0!==e&&""!==e)))),a.fields=function(e){const t=Oe(O),r=Oe(j);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))}(r.fields),a.fields.every(e=>e.name!==r.objectIdFieldName))throw new s(`objectIdField '${r.objectIdFieldName}' was not found.`,400);const l=r.fields.map(e=>Object.assign(Object.assign({},e),{keyName:je(e)})),u=function(e){switch(e){case 3:
/* istanbul ignore next --@preserve */
default:return Ie;case 2:return ke;case 0:return Pe}}(i);a.features=r.features.map(e=>({attributes:Re(l,e.attributes),geometry:e.geometry&&u(e,n)||null}));const d=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 d}function Oe(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function je(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 Re(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 qe(e){switch(e){case 0:return"esriGeometryPoint";case 2:return"esriGeometryPolyline";case 3:return"esriGeometryPolygon";default:throw new s("Geometry type not supported.",501)}}function Pe(e,t){const r={coordinates:De(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 ke(e,t){let r=null;const s=e.geometry.lengths.length;
/* istanbul ignore else if --@preserve */if(1===s)return r={type:"LineString",coordinates:_e(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=_e(e.geometry.coords,t,n,s);r.coordinates.push(a),n=s}return{paths:r.coordinates}}}function Ie(e,t){const r=e.geometry.lengths.length,s={type:"Polygon",coordinates:[]};if(1===r)s.coordinates.push(_e(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=_e(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 _e(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(De([i,a],t));let o=i,l=a;for(let i=r+2;i<s;i+=2){const r=Ee(o,e[i]),s=Ee(l,e[i+1]),a=De([r,s],t);n.push(a),o=r,l=s}return n}
/* istanbul ignore next --@preserve */function De(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 Ee(e,t){return e+t}function Ge(t,i){if("pbf-as-geojson"===i.params.f&&i.params.outSR&&"4326"!==i.params.outSR)throw new s("Unsupported outSR for GeoJSON requests.",422,null,t,i);const a="pbf-as-geojson"===i.params.f?{outSR:"4326"}:{},o=Object.assign(Object.assign({},i),{params:Object.assign(Object.assign(Object.assign({},i.params),a),{f:"pbf"}),rawResponse:!0});return r(`${e(t)}/query`,o).then(async e=>{var r;if(null===(r=e.headers.get("content-type"))||void 0===r?void 0:r.includes("application/json")){const r=(await e.json()).error;if(498===(null==r?void 0:r.code)||499===(null==r?void 0:r.code))throw new n(r.message,r.code,e,t,o);throw new s(r.message,r.code,e,t,o)}try{const t=await e.arrayBuffer();
/* istanbul ignore else --@preserve */if("pbf-as-arcgis"===i.params.f)return xe(t);
/* istanbul ignore else --@preserve */if("pbf-as-geojson"===i.params.f)return ye(t)}catch(r){throw r instanceof s?(r.response=e,r.url=t,r.options=o,r):new s("Unable to decode pbf response.",500,e,t,o)}})}function Be(t){const s=`${e(t.url)}/${t.id}`,n=Object.assign({httpMethod:"GET"},t);return r(s,n).then(e=>n.rawResponse?e:e.feature)}function Ce(s){var n,i;const a=t(s,["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:"*"},s.params)});return"pbf-as-geojson"===(null===(n=a.params)||void 0===n?void 0:n.f)||"pbf-as-arcgis"===(null===(i=a.params)||void 0===i?void 0:i.f)?Ge(s.url,a):r(`${e(s.url)}/query`,a)}async function $e(n){var i,a,o,l;let u=!0,d=0,c=!0,p=null;const h=n.resultRecordCount||(null===(i=n.params)||void 0===i?void 0:i.resultRecordCount);if(h&&h>=1e5)throw new s("resultRecordCount must be less than 100,000.",400,null,n.url,n);let f;if(h)f=h;else{f=(await r(n.url,{httpMethod:"GET",authentication:n.authentication})).maxRecordCount||2e3}for(;c;){const s=Object.assign(Object.assign({},n),{params:Object.assign(Object.assign({where:"1=1",outFields:"*"},n.params||{}),{resultOffset:d,resultRecordCount:f})}),i=t(s,["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},s.params)});let h;h="pbf-as-geojson"===(null===(a=i.params)||void 0===a?void 0:a.f)||"pbf-as-arcgis"===(null===(o=i.params)||void 0===o?void 0:o.f)?await Ge(n.url,i):await r(`${e(n.url)}/query`,i),p?p.features=p.features.concat(h.features):p=Object.assign({},h);const g=h.features.length;u&&(u=!1,g>0&&g<f&&(f=g));const y=h.exceededTransferLimit||(null===(l=h.properties)||void 0===l?void 0:l.exceededTransferLimit);g<f||!y?c=!1:d+=f}return p}function Ne(s){const n=t(s,["objectIds","relationshipId","definitionExpression","outFields"],{httpMethod:"GET",params:Object.assign({definitionExpression:"1=1",outFields:"*",relationshipId:0},s.params)});return r(`${e(s.url)}/queryRelatedRecords`,n)}function Le(s){const n=`${e(s.url)}/updateFeatures`,i=t(s,["features","gdbVersion","returnEditMoment","rollbackOnFailure","trueCurveClient"],{params:Object.assign({},s.params)});return r(n,i)}function ze(t){const s=Object.assign({params:{}},t);return s.params.attachment=t.attachment,s.params.attachmentId=t.attachmentId,r(`${e(s.url)}/${s.featureId}/updateAttachment`,s)}function Ae(t,s){const n=`${e(t).replace("/rest/services","/rest/admin/services")}/updateDefinition`;return s.params=Object.assign({updateDefinition:{}},s.params),s.updateDefinition&&(s.params.updateDefinition=s.updateDefinition),r(n,s)}export{l as addAttachment,o as addFeatures,u as addToServiceDefinition,d as applyEdits,c as createFeatureService,h as decodeValues,y as deleteAttachments,g as deleteFeatures,w as getAllLayersAndTables,F as getAttachments,Be as getFeature,p as getLayer,v as getService,V as getServiceAdminInfo,T as getViewSources,b as parseServiceUrl,$e as queryAllFeatures,Ce as queryFeatures,Ge as queryPbfAsGeoJSONOrArcGIS,Ne as queryRelated,ze as updateAttachment,Le as updateFeatures,Ae as updateServiceDefinition};
//# sourceMappingURL=feature-service.esm.min.js.map