editingSupport-KL4E3VVF.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import {
  2. L
  3. } from "./chunk-P4UZNLD5.js";
  4. import {
  5. g
  6. } from "./chunk-RZFGRBD7.js";
  7. import "./chunk-PUSPZYFZ.js";
  8. import "./chunk-EN7YGJWG.js";
  9. import "./chunk-VBNMTM7L.js";
  10. import "./chunk-3D3QEPRE.js";
  11. import "./chunk-JFNNSBWL.js";
  12. import "./chunk-WNCU6BFU.js";
  13. import "./chunk-PIGRDDRG.js";
  14. import "./chunk-C43UE3Z5.js";
  15. import "./chunk-7XXXCK2A.js";
  16. import "./chunk-7ZIDBK7B.js";
  17. import "./chunk-65BYCSII.js";
  18. import "./chunk-WZQZRKNH.js";
  19. import "./chunk-LRDX4TO7.js";
  20. import "./chunk-6A4U74YA.js";
  21. import "./chunk-N2663GRX.js";
  22. import "./chunk-WEMIK25H.js";
  23. import "./chunk-7N4X6GF3.js";
  24. import "./chunk-JXW4QTJA.js";
  25. import "./chunk-UXF37FQ4.js";
  26. import "./chunk-ZOEK6QHJ.js";
  27. import "./chunk-XNLG7T2T.js";
  28. import "./chunk-IR4PV7VK.js";
  29. import "./chunk-2Z6LERTI.js";
  30. import "./chunk-OWVBLVP3.js";
  31. import "./chunk-AFZ7XSEW.js";
  32. import "./chunk-4NKD334K.js";
  33. import "./chunk-65K7LC56.js";
  34. import "./chunk-ATPLLI5W.js";
  35. import "./chunk-XH7RUGVZ.js";
  36. import "./chunk-TBBTRX4O.js";
  37. import "./chunk-YBSUITLL.js";
  38. import {
  39. j
  40. } from "./chunk-ALDCDSPV.js";
  41. import "./chunk-DT6EAZQ5.js";
  42. import "./chunk-HNOZUNJ4.js";
  43. import "./chunk-VNFRAYHO.js";
  44. import "./chunk-R5IG2D6H.js";
  45. import {
  46. nt
  47. } from "./chunk-VBRY5KJM.js";
  48. import "./chunk-PDKDCAAD.js";
  49. import "./chunk-ECW2QABR.js";
  50. import "./chunk-GCDJLKH4.js";
  51. import "./chunk-MRJEICT6.js";
  52. import "./chunk-Y3WMVFTW.js";
  53. import "./chunk-SAS7RONY.js";
  54. import "./chunk-WSRBH7BF.js";
  55. import "./chunk-IHXECKQQ.js";
  56. import "./chunk-ULGDPLM2.js";
  57. import {
  58. s3 as s
  59. } from "./chunk-EMJ4ZSM2.js";
  60. import {
  61. m
  62. } from "./chunk-IKP3YN53.js";
  63. import {
  64. r
  65. } from "./chunk-GZT4BVFP.js";
  66. import "./chunk-A5ICIBVI.js";
  67. // node_modules/@arcgis/core/layers/graphics/editingSupport.js
  68. function n(e) {
  69. return e && e.applyEdits != null;
  70. }
  71. async function l(e, t, a, i = {}) {
  72. let s2, d;
  73. const n2 = { edits: a, result: new Promise((e2, t2) => {
  74. s2 = e2, d = t2;
  75. }) };
  76. e.emit("apply-edits", n2);
  77. try {
  78. const { results: d2, edits: n3 } = await o(e, t, a, i), l2 = (e2) => e2.filter((e3) => !e3.error).map(m), u2 = { edits: n3, addedFeatures: l2(d2.addFeatureResults), updatedFeatures: l2(d2.updateFeatureResults), deletedFeatures: l2(d2.deleteFeatureResults), addedAttachments: l2(d2.addAttachmentResults), updatedAttachments: l2(d2.updateAttachmentResults), deletedAttachments: l2(d2.deleteAttachmentResults) };
  79. return d2.editedFeatureResults?.length && (u2.editedFeatures = d2.editedFeatureResults), (u2.addedFeatures.length || u2.updatedFeatures.length || u2.deletedFeatures.length || u2.addedAttachments.length || u2.updatedAttachments.length || u2.deletedAttachments.length) && e.emit("edits", u2), s2(u2), d2;
  80. } catch (l2) {
  81. throw d(l2), l2;
  82. }
  83. }
  84. async function o(e, t, r2, i) {
  85. if (await e.load(), !n(t))
  86. throw new s(`${e.type}-layer:no-editing-support`, "Layer source does not support applyEdits capability", { layer: e });
  87. if (!e.editingEnabled)
  88. throw new s(`${e.type}-layer:editing-disabled`, "Editing is disabled for layer", { layer: e });
  89. const { edits: s2, options: d } = await u(e, r2, i);
  90. return s2.addFeatures.length || s2.updateFeatures.length || s2.deleteFeatures.length || s2.addAttachments.length || s2.updateAttachments.length || s2.deleteAttachments.length ? { edits: s2, results: await t.applyEdits(s2, d) } : { edits: s2, results: { addFeatureResults: [], updateFeatureResults: [], deleteFeatureResults: [], addAttachmentResults: [], updateAttachmentResults: [], deleteAttachmentResults: [] } };
  91. }
  92. async function u(e, r2, i) {
  93. const s2 = r2 && (r2.addFeatures || r2.updateFeatures || r2.deleteFeatures), d = r2 && (r2.addAttachments || r2.updateAttachments || r2.deleteAttachments);
  94. if (!r2 || !s2 && !d)
  95. throw new s(`${e.type}-layer:missing-parameters`, "'addFeatures', 'updateFeatures', 'deleteFeatures', 'addAttachments', 'updateAttachments' or 'deleteAttachments' parameter is required");
  96. if (!e.capabilities.data.isVersioned && i && i.gdbVersion)
  97. throw new s(`${e.type}-layer:invalid-parameter`, "'gdbVersion' is applicable only if the layer supports versioned data. See: 'capabilities.data.isVersioned'");
  98. if (!e.capabilities.editing.supportsRollbackOnFailure && i && i.rollbackOnFailureEnabled)
  99. throw new s(`${e.type}-layer:invalid-parameter`, "This layer does not support 'rollbackOnFailureEnabled' parameter. See: 'capabilities.editing.supportsRollbackOnFailure'");
  100. if (!e.capabilities.editing.supportsGlobalId && i && i.globalIdUsed)
  101. throw new s(`${e.type}-layer:invalid-parameter`, "This layer does not support 'globalIdUsed' parameter. See: 'capabilities.editing.supportsGlobalId'");
  102. if (!e.capabilities.editing.supportsGlobalId && d)
  103. throw new s(`${e.type}-layer:invalid-parameter`, "'addAttachments', 'updateAttachments' and 'deleteAttachments' are applicable only if the layer supports global ids. See: 'capabilities.editing.supportsGlobalId'");
  104. if ((!i || !i.globalIdUsed) && d)
  105. throw new s(`${e.type}-layer:invalid-parameter`, "When 'addAttachments', 'updateAttachments' or 'deleteAttachments' is specified, globalIdUsed should be set to true");
  106. const n2 = { ...i };
  107. if (n2.rollbackOnFailureEnabled != null || e.capabilities.editing.supportsRollbackOnFailure || (n2.rollbackOnFailureEnabled = true), n2.rollbackOnFailureEnabled === false && n2.returnServiceEditsOption === "original-and-current-features")
  108. throw new s(`${e.type}-layer:invalid-parameter`, "'original-and-current-features' is valid for 'returnServiceEditsOption' only when 'rollBackOnFailure' is true.");
  109. if (!e.capabilities.editing.supportsReturnServiceEditsInSourceSpatialReference && n2.returnServiceEditsInSourceSR)
  110. throw new s(`${e.type}-layer:invalid-parameter`, "This layer does not support 'returnServiceEditsInSourceSR' parameter. See: 'capabilities.editing.supportsReturnServiceEditsInSourceSpatialReference'");
  111. if (n2.returnServiceEditsInSourceSR && n2.returnServiceEditsOption !== "original-and-current-features")
  112. throw new s(`${e.type}-layer:invalid-parameter`, "'returnServiceEditsOption' is valid only when 'returnServiceEditsOption' is set to 'original-and-current-features'");
  113. const l2 = { ...r2 };
  114. if (l2.addFeatures = r2 && j.isCollection(r2.addFeatures) ? r2.addFeatures.toArray() : l2.addFeatures || [], l2.updateFeatures = r2 && j.isCollection(r2.updateFeatures) ? r2.updateFeatures.toArray() : l2.updateFeatures || [], l2.deleteFeatures = r2 && j.isCollection(r2.deleteFeatures) ? r2.deleteFeatures.toArray() : l2.deleteFeatures || [], l2.addFeatures.length && !e.capabilities.operations.supportsAdd)
  115. throw new s(`${e.type}-layer:unsupported-operation`, "Layer does not support adding features.");
  116. if (l2.updateFeatures.length && !e.capabilities.operations.supportsUpdate)
  117. throw new s(`${e.type}-layer:unsupported-operation`, "Layer does not support updating features.");
  118. if (l2.deleteFeatures.length && !e.capabilities.operations.supportsDelete)
  119. throw new s(`${e.type}-layer:unsupported-operation`, "Layer does not support deleting features.");
  120. l2.addAttachments = l2.addAttachments || [], l2.updateAttachments = l2.updateAttachments || [], l2.deleteAttachments = l2.deleteAttachments || [], l2.addFeatures = l2.addFeatures.map(g2), l2.updateFeatures = l2.updateFeatures.map(g2);
  121. const o2 = i && i.globalIdUsed;
  122. l2.addFeatures.forEach((t) => c(t, e, o2)), l2.updateFeatures.forEach((t) => m2(t, e, o2)), l2.deleteFeatures.forEach((t) => h(t, e, o2)), l2.addAttachments.forEach((t) => y(t, e)), l2.updateAttachments.forEach((t) => y(t, e));
  123. return { edits: await f(l2), options: n2 };
  124. }
  125. function p(e, t, r2) {
  126. if (r2) {
  127. if ("attributes" in e && !e.attributes[t.globalIdField])
  128. throw new s(`${t.type}-layer:invalid-parameter`, "Feature should have 'globalId' when 'globalIdUsed' is true");
  129. if (!("attributes" in e) && !e.globalId)
  130. throw new s(`${t.type}-layer:invalid-parameter`, "'globalId' of the feature should be passed when 'globalIdUsed' is true");
  131. }
  132. if ("geometry" in e && r(e.geometry)) {
  133. if (e.geometry.hasZ && t.capabilities.data.supportsZ === false)
  134. throw new s(`${t.type}-layer:z-unsupported`, "Layer does not support z values while feature has z values.");
  135. if (e.geometry.hasM && t.capabilities.data.supportsM === false)
  136. throw new s(`${t.type}-layer:m-unsupported`, "Layer does not support m values while feature has m values.");
  137. }
  138. }
  139. function c(e, t, a) {
  140. p(e, t, a);
  141. }
  142. function h(e, t, a) {
  143. p(e, t, a);
  144. }
  145. function m2(e, t, r2) {
  146. if (p(e, t, r2), "geometry" in e && r(e.geometry) && !t.capabilities.editing.supportsGeometryUpdate)
  147. throw new s(`${t.type}-layer:unsupported-operation`, "Layer does not support geometry updates.");
  148. }
  149. function y(e, t) {
  150. const { feature: r2, attachment: i } = e;
  151. if (!r2 || "attributes" in r2 && !r2.attributes[t.globalIdField])
  152. throw new s(`${t.type}-layer:invalid-parameter`, "Attachment should have reference to a feature with 'globalId'");
  153. if (!("attributes" in r2) && !r2.globalId)
  154. throw new s(`${t.type}-layer:invalid-parameter`, "Attachment should have reference to 'globalId' of the parent feature");
  155. if (!i.globalId)
  156. throw new s(`${t.type}-layer:invalid-parameter`, "Attachment should have 'globalId'");
  157. if (!i.data && !i.uploadId)
  158. throw new s(`${t.type}-layer:invalid-parameter`, "Attachment should have 'data' or 'uploadId'");
  159. if (!(i.data instanceof File && !!i.data.name) && !i.name)
  160. throw new s(`${t.type}-layer:invalid-parameter`, "'name' is required when attachment is specified as Base64 encoded string using 'data'");
  161. if (!t.capabilities.editing.supportsUploadWithItemId && i.uploadId)
  162. throw new s(`${t.type}-layer:invalid-parameter`, "This layer does not support 'uploadId' parameter. See: 'capabilities.editing.supportsUploadWithItemId'");
  163. if (typeof i.data == "string") {
  164. const e2 = nt(i.data);
  165. if (e2 && !e2.isBase64)
  166. throw new s(`${t.type}-layer:invalid-parameter`, "Attachment 'data' should be a Blob, File or Base64 encoded string");
  167. }
  168. }
  169. async function f(e) {
  170. const t = e.addFeatures, a = e.updateFeatures, r2 = t.concat(a).map((e2) => e2.geometry), i = await L(r2), s2 = t.length, n2 = a.length;
  171. return i.slice(0, s2).forEach((t2, a2) => e.addFeatures[a2].geometry = t2), i.slice(s2, s2 + n2).forEach((t2, a2) => e.updateFeatures[a2].geometry = t2), e;
  172. }
  173. function g2(t) {
  174. const a = new g();
  175. return t.attributes || (t.attributes = {}), a.geometry = t.geometry, a.attributes = t.attributes, a;
  176. }
  177. export {
  178. l as applyEdits
  179. };
  180. //# sourceMappingURL=editingSupport-KL4E3VVF.js.map