UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.32 kB
import{addTokenParameter as t}from"../../../kernel.js";import o from"../../../request.js";import{addProxy as e}from"../../../core/urlUtils.js";import{mapParameters as n}from"../../operations/urlUtils.js";import r from"../support/AttachmentInfo.js";function s(t){const o=t.toJSON();return o.attachmentTypes&&(o.attachmentTypes=o.attachmentTypes.join(",")),o.keywords&&(o.keywords=o.keywords.join(",")),o.globalIds&&(o.globalIds=o.globalIds.join(",")),o.objectIds&&(o.objectIds=o.objectIds.join(",")),o.size&&(o.size=o.size.join(",")),o}function a(o,n){const s={};for(const a of n){const{parentObjectId:n,parentGlobalId:c,attachmentInfos:m}=a;for(const a of m){const{id:m}=a,p=e(t(`${o.path}/${n}/attachments/${m}`)),i=r.fromJSON(a);i.set({url:p,parentObjectId:n,parentGlobalId:c}),s[n]?s[n].push(i):s[n]=[i]}}return s}function c(t,e,r){let a={query:n({...t.query,f:"json",...s(e)})};return r&&(a={...r,...a,query:{...r.query,...a.query}}),o(t.path+"/queryAttachments",a).then((t=>t.data.attachmentGroups))}async function m(t,e,n){const{objectIds:r}=e,s=[];for(const a of r)s.push(o(t.path+"/"+a+"/attachments",n));return Promise.all(s).then((t=>r.map(((o,e)=>({parentObjectId:o,attachmentInfos:t[e].data.attachmentInfos})))))}export{c as executeAttachmentQuery,m as fetchAttachments,a as processAttachmentQueryResult};