import { r as r2 } from "./chunk-KDQ32XYX.js"; import { i as i2 } from "./chunk-LX2NI53X.js"; import "./chunk-IZUZZJS7.js"; import { o } from "./chunk-MYF5A5DJ.js"; import { a, c, f, i } from "./chunk-2HUEYG7P.js"; import { Ze } from "./chunk-WM52QDLS.js"; import "./chunk-MEZ7BUMM.js"; import "./chunk-7B57NUGF.js"; import "./chunk-AOQ55JXI.js"; import "./chunk-X42TFXOU.js"; import "./chunk-JFSMKLAQ.js"; import "./chunk-LXOC7SMQ.js"; import "./chunk-DN6W4TJU.js"; import "./chunk-OUUXJOLT.js"; import "./chunk-PLQUCCQV.js"; import "./chunk-JZAS4TIG.js"; import "./chunk-VBR5BOXI.js"; import "./chunk-NBKUI76A.js"; import "./chunk-6334AFGG.js"; import "./chunk-NLLFSKB2.js"; import "./chunk-LC3GBQ56.js"; import "./chunk-5GYJGY4C.js"; import "./chunk-OXF7W4BJ.js"; import "./chunk-P24XEEHY.js"; import "./chunk-SAJAEMIJ.js"; import "./chunk-S6EFEKAU.js"; import "./chunk-2RHPWGZL.js"; import "./chunk-XEQ4FTFC.js"; import "./chunk-JM5OVQAD.js"; import "./chunk-S3GK7VUF.js"; import "./chunk-TU7WVKU4.js"; import "./chunk-WWXZOC2Y.js"; import "./chunk-ZOKNWEG3.js"; import "./chunk-NQA5XJGK.js"; import "./chunk-EKYSPJO6.js"; import "./chunk-JAUFBT5U.js"; import "./chunk-W6U6FKJ3.js"; import "./chunk-7C2KDOAI.js"; import "./chunk-RHFU6KWO.js"; import "./chunk-3FNKD2EB.js"; import "./chunk-ZOO4I2U4.js"; import "./chunk-JPUFJK2B.js"; import "./chunk-HZ2WKB3G.js"; import "./chunk-3HCJD762.js"; import "./chunk-RVCE264D.js"; import "./chunk-HKJ7X3BD.js"; import "./chunk-Y74D3LKQ.js"; import "./chunk-PK4W65H4.js"; import "./chunk-7C23ILQ4.js"; import "./chunk-P6VVVEX6.js"; import "./chunk-3Z755LKF.js"; import "./chunk-LTZ5XXDV.js"; import "./chunk-IEU3AM37.js"; import "./chunk-SKKBVHTF.js"; import "./chunk-DLMAGHHC.js"; import "./chunk-WD4J43GZ.js"; import "./chunk-JOYXMSKE.js"; import { m } from "./chunk-SZFMKPVM.js"; import "./chunk-YZVAB3DF.js"; import "./chunk-JLYTER4T.js"; import "./chunk-CRHRHOXH.js"; import "./chunk-ZSW35JPD.js"; import "./chunk-JLSNMUQJ.js"; import "./chunk-ECY35CJI.js"; import "./chunk-PT62335L.js"; import "./chunk-JGBXYDGB.js"; import "./chunk-QEWF7QPH.js"; import "./chunk-PJNBFKPF.js"; import "./chunk-C7742RNZ.js"; import "./chunk-FNA5GLRW.js"; import "./chunk-MCWCB5IY.js"; import "./chunk-TV3CFJQR.js"; import "./chunk-TJV6ODRM.js"; import "./chunk-JUWKPBLS.js"; import "./chunk-WLSB4F4I.js"; import "./chunk-GLSWDDR3.js"; import "./chunk-MIQGEDET.js"; import "./chunk-DUEMJ5XS.js"; import "./chunk-VRLXUHP2.js"; import "./chunk-3LVSQLWJ.js"; import "./chunk-4ONPMX2F.js"; import "./chunk-CRGY2SDS.js"; import "./chunk-4T5ZGMEN.js"; import "./chunk-GN35O2ZO.js"; import "./chunk-XTVKPAWY.js"; import "./chunk-3OSQ6GXO.js"; import "./chunk-3WQOA5CB.js"; import "./chunk-PLWDAYK7.js"; import "./chunk-FZQZIM7U.js"; import "./chunk-CZBRZ6SU.js"; import "./chunk-VGWC3IKZ.js"; import "./chunk-2H5MD622.js"; import "./chunk-3RSFVUKZ.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-5N7JLUJJ.js"; import "./chunk-ZAY3CMAZ.js"; import "./chunk-P3XKUGLS.js"; import "./chunk-2ZSOO377.js"; import { x as x2 } from "./chunk-YUA3AHKR.js"; import { j } from "./chunk-LU5IJZB4.js"; import "./chunk-7IBV2TRE.js"; import "./chunk-ZLNEXZAN.js"; import "./chunk-5UVJ64RB.js"; import "./chunk-SFEFRQCL.js"; import "./chunk-DXVOOCG4.js"; import "./chunk-3GZSQU56.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-ETGAZ7LF.js"; import "./chunk-75U5LM2V.js"; import "./chunk-RMDDCMKS.js"; import "./chunk-VCH45Q2I.js"; import "./chunk-LBW34VZ2.js"; import "./chunk-GSSTTHIT.js"; import "./chunk-YFSLJIO4.js"; import "./chunk-IM3LVQXV.js"; import "./chunk-55RWC67C.js"; import "./chunk-HZRKBTHJ.js"; import "./chunk-DVUG3KID.js"; import "./chunk-FWSQEIAR.js"; import "./chunk-VEGAOVMY.js"; import "./chunk-6T6G6LCQ.js"; import "./chunk-YEJL5NEF.js"; import "./chunk-PQFTYGF5.js"; import "./chunk-2Z2TG5CU.js"; import "./chunk-6KZ2LTDA.js"; import "./chunk-U2XHEJM7.js"; import "./chunk-SQOPWYIT.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-4XVGLMTG.js.map