import { r as r2 } from "./chunk-M27YFD2U.js"; import { i as i2 } from "./chunk-LX2NI53X.js"; import "./chunk-IZUZZJS7.js"; import { o } from "./chunk-DPJTSE3G.js"; import { a, c, f, i } from "./chunk-CL4WJLNQ.js"; import { Ze } from "./chunk-X3LGAQTK.js"; import "./chunk-2HHPZ6SS.js"; import "./chunk-6SHVYOIM.js"; import "./chunk-EFTIWDMB.js"; import "./chunk-U4FO32II.js"; import "./chunk-VIUIPJ2T.js"; import "./chunk-B2PL3HFN.js"; import "./chunk-XHABCR3B.js"; import "./chunk-XWNMXN2S.js"; import "./chunk-A5Z32OF2.js"; import "./chunk-YVKMCAJV.js"; import "./chunk-FB243F4I.js"; import "./chunk-DKAJ6NC2.js"; import "./chunk-6334AFGG.js"; import "./chunk-XPAZUTSW.js"; import "./chunk-IFWO6QLG.js"; import "./chunk-7ZZ4CSFO.js"; import "./chunk-Z3NKZOMZ.js"; import "./chunk-KAB3V7FU.js"; import "./chunk-SOSOZIX6.js"; import "./chunk-3BH3STDH.js"; import "./chunk-2RHPWGZL.js"; import "./chunk-TQGFAPAE.js"; import "./chunk-VICJMAP2.js"; import "./chunk-ESLFDGN5.js"; import "./chunk-TU7WVKU4.js"; import "./chunk-DUH52ME3.js"; import "./chunk-BFKFNCQC.js"; import "./chunk-3C3WGWKN.js"; import "./chunk-5AJSBAUF.js"; import "./chunk-GVQH5RUG.js"; import "./chunk-OJUMXZ6B.js"; import "./chunk-WAMWXYF4.js"; import "./chunk-KIHNYIAS.js"; import "./chunk-3FIDMJGU.js"; import "./chunk-645IVR72.js"; import "./chunk-2BWPQRLB.js"; import "./chunk-HPD2S4QL.js"; import "./chunk-BSICH3MG.js"; import "./chunk-3HCJD762.js"; import "./chunk-N7XY3JXE.js"; import "./chunk-6FOIAIYJ.js"; import "./chunk-PRIMQXBG.js"; import "./chunk-PK4W65H4.js"; import "./chunk-WBBQZMZY.js"; import "./chunk-C3KK62DP.js"; import "./chunk-LC4GXK7D.js"; import "./chunk-3MLCBRBA.js"; import "./chunk-JAWNLPXH.js"; import "./chunk-4PNYPUDB.js"; import "./chunk-ZSW35JPD.js"; import "./chunk-K6QDYFZU.js"; import "./chunk-EY2WJSAJ.js"; import "./chunk-YMULPZCD.js"; import { m } from "./chunk-SZFMKPVM.js"; import "./chunk-RDMCXRET.js"; import "./chunk-BQHWPTT7.js"; import "./chunk-CBJSVH3K.js"; import "./chunk-73AMYZFU.js"; import "./chunk-NKMX5M3L.js"; import "./chunk-MGUVQY3Q.js"; import "./chunk-QEWF7QPH.js"; import "./chunk-PJNBFKPF.js"; import "./chunk-C7742RNZ.js"; import "./chunk-SQ2SY4BX.js"; import "./chunk-VLG7MMVR.js"; import "./chunk-TV3CFJQR.js"; import "./chunk-BWATQC2Y.js"; import "./chunk-KHIO7AP6.js"; import "./chunk-SOMCS6KY.js"; import "./chunk-UZPANPRD.js"; import "./chunk-JYRZQPQI.js"; import "./chunk-KLAIF65O.js"; import "./chunk-AR2YN3E2.js"; import "./chunk-U3LEOWJX.js"; import "./chunk-4ONPMX2F.js"; import "./chunk-RO66DUFA.js"; import "./chunk-ISA3OUNM.js"; import "./chunk-UMJCSYX5.js"; import "./chunk-UA6W42KP.js"; import "./chunk-3OSQ6GXO.js"; import "./chunk-3WQOA5CB.js"; import "./chunk-2L5METUC.js"; import "./chunk-FZQZIM7U.js"; import "./chunk-CZBRZ6SU.js"; import "./chunk-VGWC3IKZ.js"; import "./chunk-SWMSD4RP.js"; import "./chunk-UKEN2UNL.js"; import "./chunk-UVVU4UUO.js"; import { l, o as o2 } from "./chunk-ICWTATWH.js"; import "./chunk-HWSWTWZD.js"; import "./chunk-O6VYMEIX.js"; import "./chunk-X4SA4ELJ.js"; import "./chunk-XJCUT65M.js"; import "./chunk-PE24J2I5.js"; import "./chunk-P3XKUGLS.js"; import "./chunk-PIFOHNWC.js"; import { x as x2 } from "./chunk-HW2HR4MJ.js"; import { j } from "./chunk-WRBH7HN2.js"; import "./chunk-UO6QARKZ.js"; import "./chunk-ZLNEXZAN.js"; import "./chunk-5UVJ64RB.js"; import "./chunk-PSEI52P3.js"; import "./chunk-OFMCRJIU.js"; import "./chunk-AUOH2VSO.js"; import "./chunk-ZYRIJWLX.js"; import "./chunk-RYY6632W.js"; import "./chunk-DW42UVIT.js"; import "./chunk-YAEIHDJH.js"; import "./chunk-TJNOJH33.js"; import "./chunk-OSHI574D.js"; import "./chunk-44GMIOGP.js"; import "./chunk-75U5LM2V.js"; import "./chunk-ZHRAUKVQ.js"; import "./chunk-RZK6A2GY.js"; import "./chunk-4NQ74ZR6.js"; import "./chunk-X4LLOW7U.js"; import "./chunk-BDA6VH2A.js"; import "./chunk-Z4JTBD7M.js"; import "./chunk-MSBIHK67.js"; import "./chunk-SOR4EVYE.js"; import "./chunk-LFXFUJ2J.js"; import "./chunk-VEGAOVMY.js"; import "./chunk-HZRKBTHJ.js"; import "./chunk-CXCDYJ5R.js"; import "./chunk-GAOW3WRZ.js"; import "./chunk-QCKFNSN2.js"; import "./chunk-6SOHRC7T.js"; import "./chunk-U2XHEJM7.js"; import "./chunk-SQOPWYIT.js"; import "./chunk-6KZ2LTDA.js"; import { E, x } from "./chunk-V6P2MAQQ.js"; import { s2, s3 } from "./chunk-E5O6P5I2.js"; import "./chunk-SPWQ3AWG.js"; import { s } from "./chunk-2TIUKVZN.js"; import { r, t } from "./chunk-YXWMMD76.js"; import "./chunk-S5KM4IGW.js"; // node_modules/@arcgis/core/layers/save/featureLayerUtils.js var I = s2.getLogger("esri.layers.FeatureLayer"); var S = "Feature Service"; function g(e, t2) { return `Layer (title: ${e.title}, id: ${e.id}) of type '${e.declaredClass}' ${t2}`; } function j2(e, r3) { if (r3.type !== S) throw new s3("feature-layer:portal-item-wrong-type", g(e, `should have portal item of type "${S}"`)); } async function L(e) { if (await e.load(), l(e)) throw new s3("feature-layer:save", g(e, "using an in-memory source cannot be saved to a portal item")); } function P(e, r3) { var _a; let a2 = ((_a = e.messages) != null ? _a : []).filter(({ type: e2 }) => "error" === e2).map(({ name: e2, message: r4, details: a3 }) => new s3(e2, r4, a3)); if ((r3 == null ? void 0 : r3.ignoreUnsupported) && (a2 = a2.filter(({ name: e2 }) => "layer:unsupported" !== e2 && "symbol:unsupported" !== e2 && "symbol-layer:unsupported" !== e2 && "property:unsupported" !== e2 && "url:unsupported" !== e2)), a2.length > 0) throw new s3("feature-layer:save", "Failed to save feature layer due to unsupported or invalid content. See 'details.errors' for more detailed information", { errors: a2 }); } async function J(e, t2, r3) { "beforeSave" in e && "function" == typeof e.beforeSave && await e.beforeSave(); const a2 = e.write({}, t2); return P(t2, r3), a2; } function N(e) { const { layer: t2, layerJSON: r3 } = e; return t2.isTable ? { layers: [], tables: [r3] } : { layers: [r3], tables: [] }; } function O(e) { i(e, f.JSAPI), e.typeKeywords && (e.typeKeywords = e.typeKeywords.filter((e2, t2, r3) => r3.indexOf(e2) === t2)); } function E2(e) { const r3 = e.portalItem; if (!r3) throw I.error("save: requires the portalItem property to be set"), new s3("feature-layer:portal-item-not-set", g(e, "requires the portalItem property to be set")); if (!r3.loaded) throw new s3("feature-layer:portal-item-not-loaded", g(e, "cannot be saved to a portal item that does not exist or is inaccessible")); j2(e, r3); } async function T(e, t2) { var _a; return /\/\d+\/?$/.test((_a = e.url) != null ? _a : "") ? N(t2[0]) : $(e, t2); } async function $(e, t2) { const { layer: { url: r3, customParameters: a2, apiKey: o3 } } = t2[0]; let s4 = await e.fetchData("json"); s4 && null != s4.layers && null != s4.tables || (s4 = await x3(s4, { url: r3 != null ? r3 : "", customParameters: a2, apiKey: o3 }, t2.map((e2) => e2.layer.layerId))); for (const l2 of t2) K(l2.layer, l2.layerJSON, s4); return s4; } async function x3(e, t2, r3) { var a2, o3; e || (e = {}), (a2 = e).layers || (a2.layers = []), (o3 = e).tables || (o3.tables = []); const { url: s4, customParameters: l2, apiKey: i3 } = t2, { serviceJSON: n, layersJSON: u } = await r2(s4, { customParameters: l2, apiKey: i3 }), c2 = A(e.layers, n.layers, r3), y = A(e.tables, n.tables, r3); e.layers = c2.itemResources, e.tables = y.itemResources; const d = [...c2.added, ...y.added], m2 = u ? [...u.layers, ...u.tables] : []; return await U(e, d, s4, m2), e; } function A(t2, r3, a2) { const o3 = s(t2, r3, (e, t3) => e.id === t3.id); t2 = t2.filter((e) => !o3.removed.some((t3) => t3.id === e.id)); const s4 = o3.added.map(({ id: e }) => ({ id: e })); return s4.forEach(({ id: e }) => { t2.push({ id: e }); }), { itemResources: t2, added: s4.filter(({ id: e }) => !a2.includes(e)) }; } async function U(e, t2, r3, o3) { const s4 = t2.map(({ id: e2 }) => new Ze({ url: r3, layerId: e2, sourceJSON: o3.find(({ id: t3 }) => t3 === e2) })); await E(s4.map((e2) => e2.load())), s4.forEach((t3) => { const { layerId: r4, loaded: o4, defaultPopupTemplate: s5 } = t3; if (!o4 || t(s5)) return; K(t3, { id: r4, popupInfo: s5.toJSON() }, e); }); } function K(e, t2, r3) { e.isTable ? F(r3.tables, t2) : F(r3.layers, t2); } function F(e, t2) { if (!e) return; const r3 = e.findIndex(({ id: e2 }) => e2 === t2.id); -1 === r3 ? e.push(t2) : e[r3] = t2; } function R(e) { const { portalItem: t2 } = e; return o2(e) && !e.dynamicDataSource && !!(t2 == null ? void 0 : t2.loaded) && t2.type === S; } async function D(e) { if (!(e == null ? void 0 : e.length)) throw new s3("feature-layer-utils-saveall:missing-parameters", "'layers' array should contain at least one feature layer"); await Promise.all(e.map((e2) => e2.load())); for (const o3 of e) if (!R(o3)) throw new s3("feature-layer-utils-saveall:invalid-parameters", `'layers' array should only contain layers or tables in a feature service loaded from 'Feature Service' item. ${g(o3, "does not conform")}`, { layer: o3 }); const r3 = e.map((e2) => e2.portalItem.id); if (new Set(r3).size > 1) throw new s3("feature-layer-utils-saveall:invalid-parameters", "All layers in the 'layers' array should be loaded from the same portal item"); const a2 = e.map((e2) => e2.layerId); if (new Set(a2).size !== a2.length) throw new s3("feature-layer-utils-saveall:invalid-parameters", "'layers' array should contain only one instance each of layer or table in a feature service"); } function _(e, t2) { var _a, _b; var r3, a2; let o3 = x2.from(t2); return o3.id && (o3 = o3.clone(), o3.id = null), (_a = (r3 = o3).type) != null ? _a : r3.type = S, (_b = (a2 = o3).portal) != null ? _b : a2.portal = j.getDefault(), j2(e, o3), o3; } async function q(e, t2) { const { url: r3, layerId: a2, title: s4, fullExtent: l2, isTable: i3 } = e, n = m(r3), p = r(n) && "FeatureServer" === n.serverType; t2.url = p ? r3 : `${r3}/${a2}`, t2.title || (t2.title = s4), t2.extent = null, !i3 && r(l2) && (t2.extent = await a(l2)), c(t2, f.METADATA), c(t2, f.MULTI_LAYER), i(t2, f.SINGLE_LAYER), i3 && i(t2, f.TABLE), O(t2); } async function z(e, t2, r3) { var _a; const a2 = e.portal; await (a2 == null ? void 0 : a2._signIn()), await ((_a = a2 == null ? void 0 : a2.user) == null ? void 0 : _a.addItem({ item: e, data: t2, folder: r3 == null ? void 0 : r3.folder })); } var C = x(M); async function M(e, t2) { await L(e), E2(e); const r3 = e.portalItem, a2 = o(r3), o3 = await J(e, a2, t2), s4 = await T(r3, [{ layer: e, layerJSON: o3 }]); return O(r3), await r3.update({ data: s4 }), i2(a2), r3; } var Y = x(async (e, t2) => { await D(e); const r3 = e[0].portalItem, a2 = o(r3), o3 = await Promise.all(e.map((e2) => J(e2, a2, t2))), s4 = await T(r3, e.map((e2, t3) => ({ layer: e2, layerJSON: o3[t3] }))); return O(r3), await r3.update({ data: s4 }), await Promise.all(e.slice(1).map((e2) => e2.portalItem.reload())), i2(a2), r3.clone(); }); var B = x(G); async function G(e, t2, r3) { await L(e); const a2 = _(e, t2), o3 = o(a2), s4 = N({ layer: e, layerJSON: await J(e, o3, r3) }); return await q(e, a2), await z(a2, s4, r3), e.portalItem = a2, i2(o3), a2; } export { C as save, Y as saveAll, B as saveAs }; //# sourceMappingURL=featureLayerUtils-PBVOZIFQ.js.map