sf-plugin-data 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +618 -240
  3. package/docs/artifact-format.md +528 -633
  4. package/docs/capabilities.md +1160 -168
  5. package/docs/git-workflow.md +135 -12
  6. package/docs/handover.md +7826 -12
  7. package/lib/api.d.ts +13 -0
  8. package/lib/api.js +10 -0
  9. package/lib/artifacts/code-fields.d.ts +49 -0
  10. package/lib/artifacts/code-fields.js +142 -0
  11. package/lib/artifacts/data-graph-document.d.ts +29 -0
  12. package/lib/artifacts/data-graph-document.js +52 -0
  13. package/lib/artifacts/data-space-field.d.ts +65 -0
  14. package/lib/artifacts/data-space-field.js +98 -0
  15. package/lib/artifacts/data-stream-document.d.ts +264 -0
  16. package/lib/artifacts/data-stream-document.js +680 -0
  17. package/lib/artifacts/data-transform-document.d.ts +152 -0
  18. package/lib/artifacts/data-transform-document.js +560 -0
  19. package/lib/artifacts/dependency-selection.d.ts +51 -0
  20. package/lib/artifacts/dependency-selection.js +154 -0
  21. package/lib/artifacts/dlo-document.d.ts +93 -0
  22. package/lib/artifacts/dlo-document.js +253 -0
  23. package/lib/artifacts/enum-case.d.ts +39 -0
  24. package/lib/artifacts/enum-case.js +67 -0
  25. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  26. package/lib/artifacts/git-deploy-selection.js +474 -0
  27. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  28. package/lib/artifacts/identity-resolution-document.js +625 -0
  29. package/lib/artifacts/mapping-document.d.ts +1 -0
  30. package/lib/artifacts/mapping-document.js +1 -0
  31. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  32. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  33. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  34. package/lib/artifacts/native-data-graph-document.js +780 -0
  35. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  36. package/lib/artifacts/native-dmo-document.js +313 -0
  37. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  38. package/lib/artifacts/native-mapping-document.js +187 -0
  39. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  40. package/lib/artifacts/native-relationship-document.js +232 -0
  41. package/lib/artifacts/path-selector.d.ts +55 -0
  42. package/lib/artifacts/path-selector.js +167 -0
  43. package/lib/artifacts/read-deploy-input.d.ts +222 -6
  44. package/lib/artifacts/read-deploy-input.js +1213 -53
  45. package/lib/artifacts/segment-document.d.ts +183 -0
  46. package/lib/artifacts/segment-document.js +570 -0
  47. package/lib/artifacts/verbatim-document.d.ts +203 -0
  48. package/lib/artifacts/verbatim-document.js +339 -0
  49. package/lib/artifacts/write-data-graph.d.ts +17 -0
  50. package/lib/artifacts/write-data-graph.js +162 -0
  51. package/lib/artifacts/write-data-stream.d.ts +11 -0
  52. package/lib/artifacts/write-data-stream.js +175 -0
  53. package/lib/artifacts/write-data-transform.d.ts +11 -0
  54. package/lib/artifacts/write-data-transform.js +180 -0
  55. package/lib/artifacts/write-dlo.d.ts +11 -0
  56. package/lib/artifacts/write-dlo.js +158 -0
  57. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  58. package/lib/artifacts/write-identity-resolution.js +165 -0
  59. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  60. package/lib/artifacts/write-mapping-definition.js +127 -0
  61. package/lib/artifacts/write-member-export.d.ts +88 -0
  62. package/lib/artifacts/write-member-export.js +199 -0
  63. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  64. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  65. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  66. package/lib/artifacts/write-native-dmo.js +158 -0
  67. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  68. package/lib/artifacts/write-native-mapping.js +157 -0
  69. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  70. package/lib/artifacts/write-native-relationship.js +157 -0
  71. package/lib/artifacts/write-segment.d.ts +26 -0
  72. package/lib/artifacts/write-segment.js +212 -0
  73. package/lib/commands/data360/delete.d.ts +280 -0
  74. package/lib/commands/data360/delete.js +2347 -0
  75. package/lib/commands/data360/deploy.d.ts +235 -16
  76. package/lib/commands/data360/deploy.js +2339 -102
  77. package/lib/commands/data360/list/dataspace.d.ts +53 -0
  78. package/lib/commands/data360/list/dataspace.js +109 -0
  79. package/lib/commands/data360/publish.d.ts +93 -0
  80. package/lib/commands/data360/publish.js +298 -0
  81. package/lib/commands/data360/retrieve.d.ts +283 -14
  82. package/lib/commands/data360/retrieve.js +1945 -95
  83. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  84. package/lib/commands/data360/segment/members/export.js +320 -0
  85. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  86. package/lib/errors/codes/calculated-insight.js +25 -0
  87. package/lib/errors/codes/data-graph.d.ts +2 -0
  88. package/lib/errors/codes/data-graph.js +22 -0
  89. package/lib/errors/codes/data-stream.d.ts +2 -0
  90. package/lib/errors/codes/data-stream.js +70 -0
  91. package/lib/errors/codes/data-transform.d.ts +2 -0
  92. package/lib/errors/codes/data-transform.js +35 -0
  93. package/lib/errors/codes/dependency.d.ts +2 -0
  94. package/lib/errors/codes/dependency.js +11 -0
  95. package/lib/errors/codes/dlo.d.ts +2 -0
  96. package/lib/errors/codes/dlo.js +31 -0
  97. package/lib/errors/codes/dmo.d.ts +2 -0
  98. package/lib/errors/codes/dmo.js +28 -0
  99. package/lib/errors/codes/general.d.ts +2 -0
  100. package/lib/errors/codes/general.js +58 -0
  101. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  102. package/lib/errors/codes/identity-resolution.js +24 -0
  103. package/lib/errors/codes/mapping.d.ts +2 -0
  104. package/lib/errors/codes/mapping.js +42 -0
  105. package/lib/errors/codes/relationship.d.ts +2 -0
  106. package/lib/errors/codes/relationship.js +21 -0
  107. package/lib/errors/codes/segment.d.ts +2 -0
  108. package/lib/errors/codes/segment.js +49 -0
  109. package/lib/errors/registry.d.ts +60 -0
  110. package/lib/errors/registry.js +123 -0
  111. package/lib/exit-code.d.ts +10 -0
  112. package/lib/exit-code.js +24 -0
  113. package/lib/plugin.d.ts +1 -0
  114. package/lib/plugin.js +3 -1
  115. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  116. package/lib/services/acquire-retrieve-selection.js +145 -0
  117. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  118. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  119. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  120. package/lib/services/bind-segment-dependencies.js +115 -0
  121. package/lib/services/bounded-reads.d.ts +17 -0
  122. package/lib/services/bounded-reads.js +42 -0
  123. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  124. package/lib/services/calculated-insight-sql-checks.js +193 -0
  125. package/lib/services/command-dlo.d.ts +48 -0
  126. package/lib/services/command-dlo.js +103 -0
  127. package/lib/services/command-native-data-graph.d.ts +54 -0
  128. package/lib/services/command-native-data-graph.js +485 -0
  129. package/lib/services/command-native-data-stream.d.ts +104 -0
  130. package/lib/services/command-native-data-stream.js +257 -0
  131. package/lib/services/command-native-dmo.d.ts +124 -0
  132. package/lib/services/command-native-dmo.js +338 -0
  133. package/lib/services/command-native-mapping.d.ts +65 -0
  134. package/lib/services/command-native-mapping.js +129 -0
  135. package/lib/services/command-native-relationship.d.ts +46 -0
  136. package/lib/services/command-native-relationship.js +103 -0
  137. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  138. package/lib/services/cross-dataspace-deploy.js +493 -0
  139. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  140. package/lib/services/cross-dataspace-rename.js +1314 -0
  141. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  142. package/lib/services/cross-dataspace-sql.js +1301 -0
  143. package/lib/services/cross-space-context.d.ts +23 -0
  144. package/lib/services/cross-space-context.js +38 -0
  145. package/lib/services/crud-plan.d.ts +137 -0
  146. package/lib/services/crud-plan.js +408 -0
  147. package/lib/services/data-space-check.d.ts +92 -0
  148. package/lib/services/data-space-check.js +169 -0
  149. package/lib/services/data-space-prefix.d.ts +77 -0
  150. package/lib/services/data-space-prefix.js +127 -0
  151. package/lib/services/data-transform-space.d.ts +31 -0
  152. package/lib/services/data-transform-space.js +79 -0
  153. package/lib/services/delete-calculated-insight.d.ts +44 -0
  154. package/lib/services/delete-calculated-insight.js +101 -0
  155. package/lib/services/delete-data-transform.d.ts +52 -0
  156. package/lib/services/delete-data-transform.js +222 -0
  157. package/lib/services/delete-dmo-field.d.ts +211 -0
  158. package/lib/services/delete-dmo-field.js +472 -0
  159. package/lib/services/delete-identity-resolution.d.ts +43 -0
  160. package/lib/services/delete-identity-resolution.js +295 -0
  161. package/lib/services/delete-segment.d.ts +42 -0
  162. package/lib/services/delete-segment.js +248 -0
  163. package/lib/services/deploy-result.d.ts +54 -0
  164. package/lib/services/deploy-result.js +60 -0
  165. package/lib/services/escaped-copy.d.ts +23 -0
  166. package/lib/services/escaped-copy.js +88 -0
  167. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  168. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  169. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  170. package/lib/services/execute-data-transform-deploy.js +168 -0
  171. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  172. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  173. package/lib/services/execute-segment-deploy.d.ts +45 -0
  174. package/lib/services/execute-segment-deploy.js +393 -0
  175. package/lib/services/list-data-spaces.d.ts +17 -0
  176. package/lib/services/list-data-spaces.js +24 -0
  177. package/lib/services/local-file-removal.d.ts +36 -0
  178. package/lib/services/local-file-removal.js +103 -0
  179. package/lib/services/native-calculated-insight.d.ts +87 -0
  180. package/lib/services/native-calculated-insight.js +164 -0
  181. package/lib/services/native-crm-data-stream.d.ts +91 -0
  182. package/lib/services/native-crm-data-stream.js +272 -0
  183. package/lib/services/native-data-graph-context.d.ts +12 -0
  184. package/lib/services/native-data-graph-context.js +139 -0
  185. package/lib/services/native-data-graph-crd.d.ts +261 -0
  186. package/lib/services/native-data-graph-crd.js +866 -0
  187. package/lib/services/native-data-stream.d.ts +329 -0
  188. package/lib/services/native-data-stream.js +1830 -0
  189. package/lib/services/native-dlo.d.ts +163 -0
  190. package/lib/services/native-dlo.js +402 -0
  191. package/lib/services/native-dmo.d.ts +191 -0
  192. package/lib/services/native-dmo.js +614 -0
  193. package/lib/services/native-mapping.d.ts +255 -0
  194. package/lib/services/native-mapping.js +1226 -0
  195. package/lib/services/native-relationship.d.ts +132 -0
  196. package/lib/services/native-relationship.js +512 -0
  197. package/lib/services/operation-diagnostic.d.ts +83 -0
  198. package/lib/services/operation-diagnostic.js +272 -0
  199. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  200. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  201. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  202. package/lib/services/preflight-data-transform-deploy.js +104 -0
  203. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  204. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  205. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  206. package/lib/services/preflight-segment-deploy.js +109 -0
  207. package/lib/services/publish-calculated-insight.d.ts +40 -0
  208. package/lib/services/publish-calculated-insight.js +95 -0
  209. package/lib/services/publish-segment.d.ts +65 -0
  210. package/lib/services/publish-segment.js +194 -0
  211. package/lib/services/readback-pace.d.ts +16 -0
  212. package/lib/services/readback-pace.js +23 -0
  213. package/lib/services/retrieve-data-transform.d.ts +26 -0
  214. package/lib/services/retrieve-data-transform.js +65 -0
  215. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  216. package/lib/services/retrieve-identity-resolution.js +87 -0
  217. package/lib/services/retrieve-inventory.d.ts +32 -0
  218. package/lib/services/retrieve-inventory.js +151 -0
  219. package/lib/services/retrieve-segment.d.ts +120 -0
  220. package/lib/services/retrieve-segment.js +502 -0
  221. package/lib/services/run-retrieve.d.ts +24 -0
  222. package/lib/services/run-retrieve.js +51 -0
  223. package/lib/services/segment-lookup.d.ts +46 -0
  224. package/lib/services/segment-lookup.js +108 -0
  225. package/lib/services/segment-members.d.ts +144 -0
  226. package/lib/services/segment-members.js +402 -0
  227. package/lib/services/select-native-retrieve.d.ts +60 -0
  228. package/lib/services/select-native-retrieve.js +226 -0
  229. package/lib/services/settle-calculated-insight.d.ts +22 -0
  230. package/lib/services/settle-calculated-insight.js +53 -0
  231. package/lib/services/sql-tokens.d.ts +58 -0
  232. package/lib/services/sql-tokens.js +147 -0
  233. package/lib/transport/api-version.d.ts +36 -0
  234. package/lib/transport/api-version.js +89 -0
  235. package/lib/transport/bound-ssot.d.ts +27 -0
  236. package/lib/transport/bound-ssot.js +116 -0
  237. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  238. package/lib/transport/calculated-insight-rest.js +62 -0
  239. package/lib/transport/connect-client.d.ts +94 -32
  240. package/lib/transport/connect-client.js +318 -178
  241. package/lib/transport/connect-diagnostic.d.ts +89 -0
  242. package/lib/transport/connect-diagnostic.js +331 -0
  243. package/lib/transport/data-graph-rest.d.ts +27 -0
  244. package/lib/transport/data-graph-rest.js +76 -0
  245. package/lib/transport/data-stream-rest.d.ts +62 -0
  246. package/lib/transport/data-stream-rest.js +348 -0
  247. package/lib/transport/data-transform-rest.d.ts +25 -0
  248. package/lib/transport/data-transform-rest.js +100 -0
  249. package/lib/transport/dlo-native-rest.d.ts +22 -0
  250. package/lib/transport/dlo-native-rest.js +89 -0
  251. package/lib/transport/dlo-rest.d.ts +23 -0
  252. package/lib/transport/dlo-rest.js +135 -0
  253. package/lib/transport/dmo-native-rest.d.ts +18 -0
  254. package/lib/transport/dmo-native-rest.js +55 -0
  255. package/lib/transport/dmo-rest.d.ts +30 -0
  256. package/lib/transport/dmo-rest.js +163 -0
  257. package/lib/transport/mapping-rest.d.ts +63 -0
  258. package/lib/transport/mapping-rest.js +341 -0
  259. package/lib/transport/project-metadata.d.ts +36 -0
  260. package/lib/transport/project-metadata.js +118 -0
  261. package/lib/transport/relationship-rest.d.ts +43 -0
  262. package/lib/transport/relationship-rest.js +201 -0
  263. package/package.json +29 -6
  264. package/lib/artifacts/dmo-document.d.ts +0 -181
  265. package/lib/artifacts/dmo-document.js +0 -848
  266. package/lib/artifacts/dmo-update-delta.d.ts +0 -28
  267. package/lib/artifacts/dmo-update-delta.js +0 -86
  268. package/lib/artifacts/write-other-dmo.d.ts +0 -17
  269. package/lib/artifacts/write-other-dmo.js +0 -140
  270. package/lib/services/execute-dmo-create.d.ts +0 -24
  271. package/lib/services/execute-dmo-create.js +0 -118
  272. package/lib/services/execute-dmo-deploy.d.ts +0 -33
  273. package/lib/services/execute-dmo-deploy.js +0 -197
  274. package/lib/services/preflight-dmo-deploy.d.ts +0 -69
  275. package/lib/services/preflight-dmo-deploy.js +0 -161
  276. package/lib/services/retrieve-other-dmo.d.ts +0 -46
  277. package/lib/services/retrieve-other-dmo.js +0 -140
@@ -0,0 +1,163 @@
1
+ import type { DloDocument } from '../artifacts/dlo-document.js';
2
+ import type { DloClient } from '../transport/dlo-rest.js';
3
+ import type { DocumentMode } from '../artifacts/verbatim-document.js';
4
+ /** Data spaces a deploy adds the DLO to and removes it from (both sorted). */
5
+ export type DloMembershipChange = {
6
+ add: string[];
7
+ remove: string[];
8
+ };
9
+ export type DloDeployPlan = {
10
+ /** `update` also when only the data spaces change. */
11
+ operation: 'create' | 'update' | 'unchanged';
12
+ apiName: string;
13
+ targetId?: string;
14
+ /** POST or PATCH body of the definition; absent when the definition itself is unchanged. */
15
+ body?: Record<string, unknown>;
16
+ /** The org definition, when the definition is unchanged. */
17
+ document?: DloDocument;
18
+ /** Every data space of the file, sorted. */
19
+ dataSpaces: string[];
20
+ membership: DloMembershipChange;
21
+ };
22
+ /** What a DLO deploy may do besides the definition. */
23
+ export type DloDeployOptions = {
24
+ /** Remove the DLO from org data spaces the file no longer lists (--allow-dataspace-removal). */
25
+ allowDataspaceRemoval?: boolean;
26
+ };
27
+ /**
28
+ * Resolve exactly the requested API name in the target, retaining only its current target ID.
29
+ * @param {string} apiName Requested full API name.
30
+ * @param {DloClient} client Target client.
31
+ * @param {string} dataSpace The run's data space; the DLO must belong to it.
32
+ * @param {DocumentMode} [mode] `retrieve` keeps what the plugin cannot deploy and admits a
33
+ * 15-character ID.
34
+ * @returns {Promise<{document: DloDocument, targetId: string}>} Definition and target identity.
35
+ */
36
+ export declare function resolveNativeDloTarget(apiName: string, client: Pick<DloClient, 'get'>, dataSpace: string, mode?: DocumentMode): Promise<{
37
+ document: DloDocument;
38
+ targetId: string;
39
+ runtime: Record<string, unknown>;
40
+ }>;
41
+ /**
42
+ * Retrieve a portable definition by its full API name, never saving the source ID. The file lists
43
+ * every data space of the DLO; the DLO must belong to the run's data space.
44
+ * @param {string} apiName Exact name ending in __dll.
45
+ * @param {Pick<DloClient, 'get'>} client Authenticated target client.
46
+ * @param {string} dataSpace The run's data space.
47
+ * @param {DocumentMode} [mode] `retrieve` for the retrieve command; other callers stay strict.
48
+ * @returns {Promise<DloDocument>} Portable definition.
49
+ */
50
+ export declare function retrieveNativeDlo(apiName: string, client: Pick<DloClient, 'get'>, dataSpace: string, mode?: DocumentMode): Promise<DloDocument>;
51
+ /**
52
+ * Preflight one native deploy: only authoritative absence selects create.
53
+ * Updates permit label, record-modified field and ordinary field additions, refusing any
54
+ * removed/changed field or key. The file's data space list (`c__dataSpace`) must hold the run's
55
+ * data space; the DLO is added to listed spaces it is not in yet, and removed from org spaces the
56
+ * file no longer lists only with `allowDataspaceRemoval`.
57
+ * @param {unknown} value Saved document.
58
+ * @param {DloClient} client Authenticated target client.
59
+ * @param {string} dataSpace The run's data space.
60
+ * @param {DloDeployOptions} [options] Data space removal permission.
61
+ * @returns {Promise<DloDeployPlan>} Target-bound write plan with no source IDs.
62
+ */
63
+ export declare function preflightNativeDlo(value: unknown, client: DloClient, dataSpace: string, options?: DloDeployOptions): Promise<DloDeployPlan>;
64
+ /**
65
+ * Resolve and preflight immediately before one write; no retries or cached-plan replay.
66
+ * @param {unknown} value Portable document.
67
+ * @param {DloClient} client Target client.
68
+ * @param {string} dataSpace The run's data space.
69
+ * @param {DloDeployOptions} [options] Data space removal permission.
70
+ * @returns {Promise<{operation: 'create' | 'update' | 'unchanged', document: DloDocument}>} Accepted or unchanged definition, not terminal activation proof.
71
+ */
72
+ export declare function deployNativeDlo(value: unknown, client: DloClient, dataSpace: string, options?: DloDeployOptions): Promise<{
73
+ operation: 'create' | 'update' | 'unchanged';
74
+ document: DloDocument;
75
+ serverProcessing?: true;
76
+ /** The data spaces the DLO was added to or removed from; absent when none changed. */
77
+ dataSpaceChanges?: DloMembershipChange;
78
+ }>;
79
+ /**
80
+ * Identity a delete needs from a DLO GET, without projecting the rest: the same name, membership
81
+ * in the run's data space and an 18-character record ID. A DELETE removes the DLO from every data
82
+ * space, so a DLO that also belongs to other spaces refuses (DLO_DELETE_OTHER_DATASPACES); deploy
83
+ * a shorter c__dataSpace list with --allow-dataspace-removal instead. Fields, labels and keys the
84
+ * plugin does not model never block a delete.
85
+ * @param {string} apiName Requested full API name.
86
+ * @param {Pick<DloClient, 'get'>} client Target client.
87
+ * @param {string} dataSpace The run's data space.
88
+ * @returns {Promise<{identity: {apiName: string; dataSpace: string}; targetId: string}>} Target.
89
+ */
90
+ export declare function resolveDloDeleteTarget(apiName: string, client: Pick<DloClient, 'get'>, dataSpace: string): Promise<{
91
+ identity: {
92
+ apiName: string;
93
+ dataSpace: string;
94
+ };
95
+ targetId: string;
96
+ }>;
97
+ /**
98
+ * Read-only delete preview: the identity a delete would remove, from the same checks.
99
+ * @param {string} apiName Requested full API name.
100
+ * @param {Pick<DloClient, 'get'>} client Target client.
101
+ * @param {string} dataSpace The run's data space.
102
+ * @returns {Promise<{identity: {apiName: string; dataSpace: string}}>} Identity to delete.
103
+ */
104
+ export declare function previewDeleteNativeDlo(apiName: string, client: Pick<DloClient, 'get'>, dataSpace: string): Promise<{
105
+ identity: {
106
+ apiName: string;
107
+ dataSpace: string;
108
+ };
109
+ }>;
110
+ /**
111
+ * Delete only a freshly resolved exact target ID, without cascade or retry.
112
+ * The command executes by default; its preview path never invokes this operation.
113
+ * One name read after the DELETE settles the result: 404 confirms deletion; the same target
114
+ * in a DELETING state is acknowledged-processing; anything else (still readable, or the read
115
+ * failed) is acknowledged but unconfirmed (DLO_DELETE_NOT_CONFIRMED). Nothing is replayed.
116
+ * @param {string} apiName Confirmed full API name.
117
+ * @param {Pick<DloClient, 'get' | 'delete'>} client Authenticated target client.
118
+ * @param {string} dataSpace The run's data space.
119
+ * @returns {Promise<{apiName: string, targetId: string, dataSpace: string, processing?: true}>} Exact deleted target identity.
120
+ */
121
+ export declare function deleteNativeDlo(apiName: string, client: Pick<DloClient, 'get' | 'delete'>, dataSpace: string): Promise<{
122
+ apiName: string;
123
+ targetId: string;
124
+ dataSpace: string;
125
+ processing?: true;
126
+ }>;
127
+ /** One entry of a DLO's dependency list, as Salesforce reports it. */
128
+ export type DloDependent = {
129
+ componentType: string;
130
+ name: string;
131
+ };
132
+ /**
133
+ * Read the dependency list of a DLO; anything but the documented shape confirms nothing.
134
+ * @param {unknown} response Native dependencies response.
135
+ * @returns {DloDependent[]} Dependents by type and name.
136
+ */
137
+ export declare function dloDependents(response: unknown): DloDependent[];
138
+ /**
139
+ * Salesforce refuses to delete a DLO that something depends on (HTTP 412 DEPENDENCY_EXISTS), so
140
+ * the plugin reads the dependency list once, before the command's first write: a dependent the
141
+ * same command does not delete refuses with DLO_DEPENDENCY_EXISTS naming each one.
142
+ * @param {string} apiName Exact DLO name.
143
+ * @param {object} client Dependency reader.
144
+ * @param {Function} client.dependencies Reads the dependency list of a DLO by name.
145
+ * @param {Function} covered Whether the same command deletes a dependent.
146
+ * @returns {Promise<DloDependent[]>} The dependents the command deletes.
147
+ */
148
+ export declare function admitDloDependents(apiName: string, client: {
149
+ dependencies: (apiName: string) => Promise<unknown>;
150
+ }, covered: (dependent: DloDependent) => Promise<boolean>): Promise<DloDependent[]>;
151
+ /**
152
+ * Wait (bounded) until the dependents the command deleted are no longer listed. A dependent
153
+ * that was not admitted before the first write refuses; one still listed after the last read
154
+ * gives DLO_DEPENDENCY_PENDING. No DELETE is sent here.
155
+ * @param {string} apiName Exact DLO name.
156
+ * @param {object} client Dependency reader.
157
+ * @param {Function} client.dependencies Reads the dependency list of a DLO by name.
158
+ * @param {DloDependent[]} admitted Dependents admitted before the command's first write.
159
+ * @returns {Promise<void>} Resolves when the list is empty.
160
+ */
161
+ export declare function waitForDloDependents(apiName: string, client: {
162
+ dependencies: (apiName: string) => Promise<unknown>;
163
+ }, admitted: DloDependent[]): Promise<void>;
@@ -0,0 +1,402 @@
1
+ import { sameEnum, sameRecord } from '../artifacts/enum-case.js';
2
+ import { refuseEscapedCopy } from './escaped-copy.js';
3
+ import { crossSpaceSentence, explainInput, explainMismatch, printableKey, } from './operation-diagnostic.js';
4
+ import { DloError, dloDataSpaces, dloSystemFields, isGeneratedDloField, normalizeDlo, projectDlo, unwrapDlo, validateDloDocument, } from '../artifacts/dlo-document.js';
5
+ import { sortedDataSpaces } from '../artifacts/data-space-field.js';
6
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
7
+ import { replaceExplanation } from './operation-diagnostic.js';
8
+ import { paceReadback, readbackPace } from './readback-pace.js';
9
+ /** Field keys Salesforce stores in its own letter case (`text` reads `Text`, live API 68). */
10
+ const dloFieldEnums = new Set(['dataType']);
11
+ /**
12
+ * Identify qualified generated qualifier/system fields, never generic Id-bearing fields.
13
+ * @param {DloField} field Portable definition.
14
+ * @returns {boolean} Whether native create generates this field.
15
+ */
16
+ function generated(field) {
17
+ return dloSystemFields.has(field.name) || field.name.startsWith('KQ_');
18
+ }
19
+ /**
20
+ * Convert the saved API field name to native input without losing definitions.
21
+ * @param {DloField} field Saved field.
22
+ * @returns {Record<string, unknown>} Native field input.
23
+ */
24
+ function fieldInput(field) {
25
+ return { ...field, name: field.name.slice(0, -3) };
26
+ }
27
+ /**
28
+ * Data space names as they may appear in a message.
29
+ * @param {string[]} spaces Names.
30
+ * @returns {string} Comma-separated printable names.
31
+ */
32
+ function spaceList(spaces) {
33
+ return spaces.map((space) => printableKey(space)).join(', ');
34
+ }
35
+ /**
36
+ * Resolve exactly the requested API name in the target, retaining only its current target ID.
37
+ * @param {string} apiName Requested full API name.
38
+ * @param {DloClient} client Target client.
39
+ * @param {string} dataSpace The run's data space; the DLO must belong to it.
40
+ * @param {DocumentMode} [mode] `retrieve` keeps what the plugin cannot deploy and admits a
41
+ * 15-character ID.
42
+ * @returns {Promise<{document: DloDocument, targetId: string}>} Definition and target identity.
43
+ */
44
+ export async function resolveNativeDloTarget(apiName, client, dataSpace, mode = 'deploy') {
45
+ const raw = unwrapDlo(await client.get(apiName));
46
+ const document = normalizeDlo(raw, dataSpace, mode);
47
+ if (document.identity.apiName !== apiName)
48
+ throw new DloError('DLO_TARGET_IDENTITY_MISMATCH');
49
+ // A missing or unusual ID is a shape the plugin does not model, not another DLO.
50
+ if (typeof raw.id !== 'string' ||
51
+ !(mode === 'retrieve' ? /^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/u : /^[A-Za-z0-9]{18}$/u).test(raw.id))
52
+ throw new DloError('INVALID_DLO_TARGET_ID');
53
+ return { document, targetId: raw.id, runtime: structuredClone(raw) };
54
+ }
55
+ /**
56
+ * Retrieve a portable definition by its full API name, never saving the source ID. The file lists
57
+ * every data space of the DLO; the DLO must belong to the run's data space.
58
+ * @param {string} apiName Exact name ending in __dll.
59
+ * @param {Pick<DloClient, 'get'>} client Authenticated target client.
60
+ * @param {string} dataSpace The run's data space.
61
+ * @param {DocumentMode} [mode] `retrieve` for the retrieve command; other callers stay strict.
62
+ * @returns {Promise<DloDocument>} Portable definition.
63
+ */
64
+ export async function retrieveNativeDlo(apiName, client, dataSpace, mode = 'deploy') {
65
+ const target = await resolveNativeDloTarget(apiName, client, dataSpace, mode);
66
+ return target.document;
67
+ }
68
+ /**
69
+ * Preflight one native deploy: only authoritative absence selects create.
70
+ * Updates permit label, record-modified field and ordinary field additions, refusing any
71
+ * removed/changed field or key. The file's data space list (`c__dataSpace`) must hold the run's
72
+ * data space; the DLO is added to listed spaces it is not in yet, and removed from org spaces the
73
+ * file no longer lists only with `allowDataspaceRemoval`.
74
+ * @param {unknown} value Saved document.
75
+ * @param {DloClient} client Authenticated target client.
76
+ * @param {string} dataSpace The run's data space.
77
+ * @param {DloDeployOptions} [options] Data space removal permission.
78
+ * @returns {Promise<DloDeployPlan>} Target-bound write plan with no source IDs.
79
+ */
80
+ export async function preflightNativeDlo(value, client, dataSpace, options = {}) {
81
+ const desired = validateDloDocument(value);
82
+ const apiName = desired.identity.apiName;
83
+ const dataSpaces = sortedDataSpaces(desired.c__dataSpace);
84
+ if (!dataSpaces.includes(dataSpace))
85
+ throw explainInput(new DloError('DLO_DATASPACE_MISMATCH'), `The file lists the data spaces ${spaceList(dataSpaces)} in c__dataSpace, not the run's data space ${printableKey(dataSpace)} (--dataspace, default "default").${crossSpaceSentence(dataSpace)}`);
86
+ let raw;
87
+ try {
88
+ raw = unwrapDlo(await client.get(apiName));
89
+ }
90
+ catch (error) {
91
+ if (!(error instanceof DloError) || error.code !== 'DLO_HTTP_ERROR' || error.status !== 404)
92
+ throw error;
93
+ const fields = desired.spec.fields.filter((field) => !generated(field));
94
+ if (fields.filter((field) => field.isPrimaryKey).length !== 1)
95
+ throw new DloError('INVALID_DLO_PRIMARY_KEY');
96
+ const add = dataSpaces.filter((space) => space !== dataSpace);
97
+ return {
98
+ operation: 'create',
99
+ apiName,
100
+ // Create sends the run's space; whether a create takes several is not proven, so the
101
+ // other listed spaces are added afterwards through the members route.
102
+ body: {
103
+ name: apiName.slice(0, -5),
104
+ label: desired.spec.label,
105
+ category: desired.spec.category,
106
+ ...(desired.spec.eventDateTimeFieldName === undefined
107
+ ? {}
108
+ : { eventDateTimeFieldName: desired.spec.eventDateTimeFieldName.slice(0, -3) }),
109
+ ...(desired.spec.recordModifiedFieldName === undefined
110
+ ? {}
111
+ : { recordModifiedFieldName: desired.spec.recordModifiedFieldName.slice(0, -3) }),
112
+ dataspaceInfo: [{ name: dataSpace }],
113
+ dataLakeFieldInputRepresentations: fields.map((field) => fieldInput(field)),
114
+ },
115
+ dataSpaces,
116
+ membership: { add, remove: [] },
117
+ };
118
+ }
119
+ const target = projectDlo(raw);
120
+ if (target.identity.apiName !== apiName)
121
+ throw new DloError('DLO_TARGET_IDENTITY_MISMATCH');
122
+ if (typeof raw.id !== 'string' || !/^[A-Za-z0-9]{18}$/u.test(raw.id))
123
+ throw new DloError('INVALID_DLO_TARGET_ID');
124
+ const targetId = raw.id;
125
+ refuseEscapedCopy(desired, target, (code) => new DloError(code));
126
+ const membership = {
127
+ add: dataSpaces.filter((space) => !target.c__dataSpace.includes(space)),
128
+ remove: target.c__dataSpace.filter((space) => !dataSpaces.includes(space)),
129
+ };
130
+ if (membership.remove.length > 0 && options.allowDataspaceRemoval !== true)
131
+ throw explainInput(new DloError('DLO_DATASPACE_REMOVAL_NOT_ALLOWED'), `${apiName} belongs to the data spaces ${spaceList(membership.remove)} in the org, which c__dataSpace does not list. Removing a DLO from a data space needs --allow-dataspace-removal; otherwise add them to c__dataSpace.`);
132
+ // Neither can change after create: a PATCH naming them is rejected (HTTP 400, live API 68).
133
+ // Salesforce stores the category and field types in its own letter case (`other` reads `Other`).
134
+ if (!sameEnum(desired.spec.category, target.spec.category))
135
+ throw new DloError('UNSUPPORTED_DLO_CATEGORY_CHANGE');
136
+ if (desired.spec.eventDateTimeFieldName !== undefined &&
137
+ desired.spec.eventDateTimeFieldName !== target.spec.eventDateTimeFieldName)
138
+ throw explainMismatch(new DloError('UNSUPPORTED_DLO_EVENT_FIELD_CHANGE'), 'event field preservation', apiName, target.spec.eventDateTimeFieldName, desired.spec.eventDateTimeFieldName, 'spec.eventDateTimeFieldName', 'The event field of a data lake object is set on create and cannot be changed.');
139
+ const existing = new Map(target.spec.fields.map((field) => [field.name, field]));
140
+ const incoming = new Map(desired.spec.fields.map((field) => [field.name, field]));
141
+ for (const [name, field] of existing) {
142
+ // Fields Salesforce generated (system fields and the key qualifier of another field) stay
143
+ // as they are when the file does not list them; retrieve leaves out exactly these.
144
+ if (!incoming.has(name) && isGeneratedDloField(field, target.spec.fields))
145
+ continue;
146
+ const listed = incoming.get(name);
147
+ // A listed field is compared on the keys the file states; keys only the org adds are kept.
148
+ const observed = listed
149
+ ? Object.fromEntries(Object.entries(field).filter(([key]) => key in listed))
150
+ : field;
151
+ if (!listed || !sameRecord(observed, listed, dloFieldEnums))
152
+ throw explainMismatch(new DloError('UNSUPPORTED_DLO_FIELD_CHANGE'), 'update field preservation', apiName, field, incoming.get(name), `fields.${name}`, 'Salesforce only adds fields to an existing data lake object: a changed field is rejected (HTTP 400), and removing one is refused by the Metadata API ("setup object in use"); only external data lake objects have a field delete route.');
153
+ }
154
+ const added = desired.spec.fields.filter((field) => !existing.has(field.name));
155
+ if (added.some((field) => generated(field) || field.isPrimaryKey))
156
+ throw new DloError('UNSUPPORTED_DLO_FIELD_ADDITION');
157
+ // Salesforce sets the record-modified field once: a PATCH naming one while the DLO has one is
158
+ // answered with HTTP 400 "Record modified field already present" (live API 68), and that answer
159
+ // is reported. A file without the key leaves the org's value as it is.
160
+ const recordModified = desired.spec.recordModifiedFieldName !== undefined &&
161
+ desired.spec.recordModifiedFieldName !== target.spec.recordModifiedFieldName
162
+ ? { recordModifiedFieldName: desired.spec.recordModifiedFieldName.slice(0, -3) }
163
+ : {};
164
+ const definitionUnchanged = added.length === 0 &&
165
+ desired.spec.label === target.spec.label &&
166
+ Object.keys(recordModified).length === 0;
167
+ const membershipUnchanged = membership.add.length === 0 && membership.remove.length === 0;
168
+ if (definitionUnchanged)
169
+ return {
170
+ operation: membershipUnchanged ? 'unchanged' : 'update',
171
+ apiName,
172
+ targetId,
173
+ document: target,
174
+ dataSpaces,
175
+ membership,
176
+ };
177
+ return {
178
+ operation: 'update',
179
+ apiName,
180
+ targetId,
181
+ body: {
182
+ label: desired.spec.label,
183
+ ...recordModified,
184
+ ...(added.length > 0
185
+ ? { dataLakeFieldInputRepresentations: added.map((field) => fieldInput(field)) }
186
+ : {}),
187
+ },
188
+ dataSpaces,
189
+ membership,
190
+ };
191
+ }
192
+ /**
193
+ * Change the data spaces of a DLO as planned, then read it until it lists exactly the planned
194
+ * spaces (a membership change answers PROCESSING and settles within seconds, live API 68).
195
+ * Adding sends one PUT naming only this DLO: the PUT adds the members it names and keeps every
196
+ * other member (live API 68, DB entry data360:dataspace-members-put-semantics-api68); removing
197
+ * sends one DELETE of that member. Nothing is resent.
198
+ * @param {DloDeployPlan} plan Preflighted plan.
199
+ * @param {DloClient} client Target client.
200
+ * @param {string} dataSpace The run's data space.
201
+ * @returns {Promise<DloDocument>} The DLO as read once it lists the planned spaces.
202
+ */
203
+ async function changeDataSpaces(plan, client, dataSpace) {
204
+ for (const space of plan.membership.add)
205
+ await client.putMembers(space, [plan.apiName]);
206
+ for (const space of plan.membership.remove)
207
+ await client.removeMember(space, plan.apiName);
208
+ let observed = [];
209
+ for (let attempt = 0; attempt < readbackPace.attempts; attempt++) {
210
+ await paceReadback(attempt);
211
+ const readback = unwrapDlo(await client.get(plan.apiName));
212
+ observed = dloDataSpaces(readback);
213
+ if (observed.join('\n') === plan.dataSpaces.join('\n'))
214
+ return normalizeDlo(readback, dataSpace);
215
+ }
216
+ throw explainInput(new DloError('DLO_DATASPACE_NOT_SETTLED'), `${plan.apiName} still lists the data spaces ${spaceList(observed)} instead of ${spaceList(plan.dataSpaces)}. Read the DLO in the org before deploying again.`);
217
+ }
218
+ /**
219
+ * Resolve and preflight immediately before one write; no retries or cached-plan replay.
220
+ * @param {unknown} value Portable document.
221
+ * @param {DloClient} client Target client.
222
+ * @param {string} dataSpace The run's data space.
223
+ * @param {DloDeployOptions} [options] Data space removal permission.
224
+ * @returns {Promise<{operation: 'create' | 'update' | 'unchanged', document: DloDocument}>} Accepted or unchanged definition, not terminal activation proof.
225
+ */
226
+ export async function deployNativeDlo(value, client, dataSpace, options = {}) {
227
+ const desired = validateDloDocument(value);
228
+ const plan = await preflightNativeDlo(desired, client, dataSpace, options);
229
+ if (plan.operation === 'unchanged')
230
+ return { operation: 'unchanged', document: plan.document };
231
+ let document = plan.document;
232
+ let serverProcessing = false;
233
+ if (plan.body !== undefined) {
234
+ const response = plan.operation === 'create'
235
+ ? await client.create(plan.body)
236
+ : await client.update(plan.targetId, plan.body);
237
+ document = projectDlo(response);
238
+ if (document.identity.apiName !== plan.apiName)
239
+ throw new DloError('DLO_TARGET_IDENTITY_MISMATCH');
240
+ // A create lands in the run's space only; an update keeps the spaces the DLO had.
241
+ if (!document.c__dataSpace.includes(dataSpace) && plan.membership.add.length === 0)
242
+ throw explainInput(new DloError('DLO_DATASPACE_MISMATCH'), `Salesforce answered ${plan.apiName} in the data spaces ${spaceList(sortedDataSpaces(document.c__dataSpace))}, not in the run's data space ${printableKey(dataSpace)}. Retrieve the DLO to see its data spaces before another attempt.`);
243
+ serverProcessing = unwrapDlo(response).status === 'PROCESSING';
244
+ }
245
+ const changed = plan.membership.add.length > 0 || plan.membership.remove.length > 0;
246
+ if (changed)
247
+ document = await changeDataSpaces(plan, client, dataSpace);
248
+ return {
249
+ operation: plan.operation,
250
+ document: document,
251
+ ...(serverProcessing ? { serverProcessing: true } : {}),
252
+ ...(changed ? { dataSpaceChanges: structuredClone(plan.membership) } : {}),
253
+ };
254
+ }
255
+ /**
256
+ * Identity a delete needs from a DLO GET, without projecting the rest: the same name, membership
257
+ * in the run's data space and an 18-character record ID. A DELETE removes the DLO from every data
258
+ * space, so a DLO that also belongs to other spaces refuses (DLO_DELETE_OTHER_DATASPACES); deploy
259
+ * a shorter c__dataSpace list with --allow-dataspace-removal instead. Fields, labels and keys the
260
+ * plugin does not model never block a delete.
261
+ * @param {string} apiName Requested full API name.
262
+ * @param {Pick<DloClient, 'get'>} client Target client.
263
+ * @param {string} dataSpace The run's data space.
264
+ * @returns {Promise<{identity: {apiName: string; dataSpace: string}; targetId: string}>} Target.
265
+ */
266
+ export async function resolveDloDeleteTarget(apiName, client, dataSpace) {
267
+ const raw = unwrapDlo(await client.get(apiName));
268
+ if (raw.name !== apiName)
269
+ throw new DloError('DLO_TARGET_IDENTITY_MISMATCH');
270
+ const memberships = dloDataSpaces(raw);
271
+ if (!memberships.includes(dataSpace))
272
+ throw new DloError('UNSUPPORTED_DLO_DATASPACE');
273
+ const others = memberships.filter((space) => space !== dataSpace);
274
+ if (others.length > 0)
275
+ throw explainInput(new DloError('DLO_DELETE_OTHER_DATASPACES'), `${apiName} also belongs to the data ${others.length === 1 ? 'space' : 'spaces'} ${spaceList(others)}, and a delete would remove it from all of them. To take it out of one data space only, deploy its file with a shorter c__dataSpace list and --allow-dataspace-removal.`);
276
+ if (typeof raw.id !== 'string' || !/^[A-Za-z0-9]{18}$/u.test(raw.id))
277
+ throw new DloError('INVALID_DLO_TARGET_ID');
278
+ return { identity: { apiName, dataSpace }, targetId: raw.id };
279
+ }
280
+ /**
281
+ * Read-only delete preview: the identity a delete would remove, from the same checks.
282
+ * @param {string} apiName Requested full API name.
283
+ * @param {Pick<DloClient, 'get'>} client Target client.
284
+ * @param {string} dataSpace The run's data space.
285
+ * @returns {Promise<{identity: {apiName: string; dataSpace: string}}>} Identity to delete.
286
+ */
287
+ export async function previewDeleteNativeDlo(apiName, client, dataSpace) {
288
+ const { identity } = await resolveDloDeleteTarget(apiName, client, dataSpace);
289
+ return { identity };
290
+ }
291
+ /**
292
+ * Delete only a freshly resolved exact target ID, without cascade or retry.
293
+ * The command executes by default; its preview path never invokes this operation.
294
+ * One name read after the DELETE settles the result: 404 confirms deletion; the same target
295
+ * in a DELETING state is acknowledged-processing; anything else (still readable, or the read
296
+ * failed) is acknowledged but unconfirmed (DLO_DELETE_NOT_CONFIRMED). Nothing is replayed.
297
+ * @param {string} apiName Confirmed full API name.
298
+ * @param {Pick<DloClient, 'get' | 'delete'>} client Authenticated target client.
299
+ * @param {string} dataSpace The run's data space.
300
+ * @returns {Promise<{apiName: string, targetId: string, dataSpace: string, processing?: true}>} Exact deleted target identity.
301
+ */
302
+ export async function deleteNativeDlo(apiName, client, dataSpace) {
303
+ const { targetId, identity } = await resolveDloDeleteTarget(apiName, client, dataSpace);
304
+ await client.delete(targetId);
305
+ const deleted = { apiName, targetId, dataSpace: identity.dataSpace };
306
+ let readback;
307
+ try {
308
+ readback = await client.get(apiName);
309
+ }
310
+ catch (error) {
311
+ if (error instanceof DloError && error.code === 'DLO_HTTP_ERROR' && error.status === 404)
312
+ return deleted;
313
+ // Keep the read failure's API detail (status, Retry-After) for the printed diagnostic.
314
+ throw retainConnectDiagnostic(new DloError('DLO_DELETE_NOT_CONFIRMED'), getConnectDiagnostic(error));
315
+ }
316
+ let observed;
317
+ try {
318
+ observed = unwrapDlo(readback);
319
+ }
320
+ catch {
321
+ observed = undefined;
322
+ }
323
+ if (observed?.id === targetId &&
324
+ typeof observed.status === 'string' &&
325
+ observed.status.startsWith('DELETING'))
326
+ return { ...deleted, processing: true };
327
+ throw new DloError('DLO_DELETE_NOT_CONFIRMED', 200);
328
+ }
329
+ /**
330
+ * Read the dependency list of a DLO; anything but the documented shape confirms nothing.
331
+ * @param {unknown} response Native dependencies response.
332
+ * @returns {DloDependent[]} Dependents by type and name.
333
+ */
334
+ export function dloDependents(response) {
335
+ const list = response?.dependencies;
336
+ if (!Array.isArray(list))
337
+ throw new DloError('DLO_DEPENDENCIES_UNCONFIRMED');
338
+ return list.map((entry) => {
339
+ const value = entry;
340
+ if (typeof value?.componentType !== 'string' || typeof value.name !== 'string')
341
+ throw new DloError('DLO_DEPENDENCIES_UNCONFIRMED');
342
+ return { componentType: value.componentType, name: value.name };
343
+ });
344
+ }
345
+ /**
346
+ * Name the dependents a command does not delete.
347
+ * @param {string} apiName Exact DLO name.
348
+ * @param {DloDependent[]} open Uncovered dependents.
349
+ * @returns {DloError} DLO_DEPENDENCY_EXISTS refusal.
350
+ */
351
+ function dependencyRefusal(apiName, open) {
352
+ const error = new DloError('DLO_DEPENDENCY_EXISTS');
353
+ replaceExplanation(error, `${apiName} cannot be deleted while Salesforce lists dependents: ${open
354
+ .map((dependent) => `${dependent.componentType} ${dependent.name}`)
355
+ .join(', ')}. Delete them first, or select them in the same command (a data model object as dmo:<Name>, or every mapping between this data lake object and it as mapping:<Name>).`);
356
+ return error;
357
+ }
358
+ const sameDependent = (a, b) => a.componentType === b.componentType && a.name === b.name;
359
+ /**
360
+ * Salesforce refuses to delete a DLO that something depends on (HTTP 412 DEPENDENCY_EXISTS), so
361
+ * the plugin reads the dependency list once, before the command's first write: a dependent the
362
+ * same command does not delete refuses with DLO_DEPENDENCY_EXISTS naming each one.
363
+ * @param {string} apiName Exact DLO name.
364
+ * @param {object} client Dependency reader.
365
+ * @param {Function} client.dependencies Reads the dependency list of a DLO by name.
366
+ * @param {Function} covered Whether the same command deletes a dependent.
367
+ * @returns {Promise<DloDependent[]>} The dependents the command deletes.
368
+ */
369
+ export async function admitDloDependents(apiName, client, covered) {
370
+ const dependents = dloDependents(await client.dependencies(apiName));
371
+ const open = [];
372
+ for (const dependent of dependents)
373
+ if (!(await covered(dependent)))
374
+ open.push(dependent);
375
+ if (open.length > 0)
376
+ throw dependencyRefusal(apiName, open);
377
+ return dependents;
378
+ }
379
+ /**
380
+ * Wait (bounded) until the dependents the command deleted are no longer listed. A dependent
381
+ * that was not admitted before the first write refuses; one still listed after the last read
382
+ * gives DLO_DEPENDENCY_PENDING. No DELETE is sent here.
383
+ * @param {string} apiName Exact DLO name.
384
+ * @param {object} client Dependency reader.
385
+ * @param {Function} client.dependencies Reads the dependency list of a DLO by name.
386
+ * @param {DloDependent[]} admitted Dependents admitted before the command's first write.
387
+ * @returns {Promise<void>} Resolves when the list is empty.
388
+ */
389
+ export async function waitForDloDependents(apiName, client, admitted) {
390
+ for (let attempt = 0; attempt < readbackPace.attempts; attempt++) {
391
+ await paceReadback(attempt);
392
+ const dependents = dloDependents(await client.dependencies(apiName));
393
+ if (dependents.length === 0)
394
+ return;
395
+ const open = dependents.filter((dependent) => !admitted.some((known) => sameDependent(known, dependent)));
396
+ if (open.length > 0)
397
+ throw dependencyRefusal(apiName, open);
398
+ }
399
+ const error = new DloError('DLO_DEPENDENCY_PENDING');
400
+ replaceExplanation(error, `${apiName} was not deleted: the dependents deleted by this command are still listed by Salesforce. Read the data lake object's dependencies and delete it again once the list is empty.`);
401
+ throw error;
402
+ }