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,257 @@
1
+ import { operationDiagnostic } from './operation-diagnostic.js';
2
+ import { WriteLedger, rejectedNextAction } from './deploy-result.js';
3
+ import { DataStreamError, isCrmDataStreamDocument, validateDataStreamDocument, } from '../artifacts/data-stream-document.js';
4
+ import { executeCrmDataStream, preflightCrmDataStream } from './native-crm-data-stream.js';
5
+ import { resolveDataStreamBinding, preflightNativeDataStreamCreate, preflightNativeDataStreamUpdate, createNativeDataStream, updateNativeDataStream, preflightNativeDataStreamDelete, deleteNativeDataStream, isStreamNotFound, requireRunSpace, retainStreamFailure, } from './native-data-stream.js';
6
+ /**
7
+ * Watch the first stream read of a delete: an exact HTTP 404 for the selected name means the
8
+ * stream is already gone (a rerun after it was deleted), not a failure.
9
+ * @template T
10
+ * @param {string} apiName Exact selected stream name.
11
+ * @param {T} clients Native clients.
12
+ * @returns {object} Clients with the watched read, and whether that first read answered 404.
13
+ */
14
+ export function watchStreamAbsence(apiName, clients) {
15
+ let reads = 0;
16
+ let absent = false;
17
+ return {
18
+ clients: {
19
+ ...clients,
20
+ streams: {
21
+ ...clients.streams,
22
+ get: async (identity) => {
23
+ const first = reads++ === 0;
24
+ try {
25
+ return await clients.streams.get(identity);
26
+ }
27
+ catch (error) {
28
+ if (first && identity === apiName && isStreamNotFound(error))
29
+ absent = true;
30
+ throw error;
31
+ }
32
+ },
33
+ },
34
+ },
35
+ absent: () => absent,
36
+ };
37
+ }
38
+ /**
39
+ * Preview selected-stream/linked-parent deletion only; unrelated org objects are outside this scope.
40
+ * @param {string} apiName Exact selected stream name.
41
+ * @param {DataStreamDeleteClients} clients Independent native and dependency readers.
42
+ * @param {PublicDeleteOptions} options Explicit cascade acknowledgement and selection guard.
43
+ * @returns {Promise<object>} Payload-free preview, never private target identifiers.
44
+ */
45
+ export async function preflightDeleteDataStream(apiName, clients, options) {
46
+ await options.verifyInput();
47
+ const watched = watchStreamAbsence(apiName, clients);
48
+ let plan;
49
+ try {
50
+ plan = await preflightNativeDataStreamDelete(apiName, watched.clients, {
51
+ deleteDlo: options.deleteDlo,
52
+ survivorDloNames: [],
53
+ ...(options.dataSpace === undefined ? {} : { dataSpace: options.dataSpace }),
54
+ ...(options.covered ? { covered: options.covered } : {}),
55
+ });
56
+ }
57
+ catch (error) {
58
+ if (!watched.absent())
59
+ throw error;
60
+ // Already gone: nothing to delete.
61
+ await options.verifyInput();
62
+ return {
63
+ outcome: 'unchanged',
64
+ mutation: 'not-attempted',
65
+ deleteDlo: options.deleteDlo,
66
+ };
67
+ }
68
+ await options.verifyInput();
69
+ const dloName = plan.dlo?.name;
70
+ return {
71
+ outcome: plan.plannedDependencies ? 'planned-dependencies' : 'delete',
72
+ mutation: 'not-attempted',
73
+ deleteDlo: options.deleteDlo,
74
+ // Names the linked DLO only when it is deleted too, so its local file can be listed.
75
+ ...(options.deleteDlo && typeof dloName === 'string' ? { targetDloName: dloName } : {}),
76
+ ...(plan.plannedDependencies ? { plannedDependencies: plan.plannedDependencies } : {}),
77
+ };
78
+ }
79
+ /**
80
+ * Delete exactly the selected stream with linked-parent checks and actual-dispatch classification.
81
+ * @param {string} apiName Exact selected stream name.
82
+ * @param {DataStreamDeleteClients} clients Single-attempt native mutation and independent readers.
83
+ * @param {PublicDeleteOptions} options Cascade acknowledgement and immutable selection guard.
84
+ * @returns {Promise<object>} Confirmed deletion or payload-free blocked/unknown result.
85
+ */
86
+ export async function executeDeleteDataStream(apiName, clients, options) {
87
+ let dispatched = false;
88
+ const watched = watchStreamAbsence(apiName, clients);
89
+ try {
90
+ const receipt = await deleteNativeDataStream(apiName, {
91
+ ...clients,
92
+ streams: {
93
+ get: (identity) => watched.clients.streams.get(identity),
94
+ list: (connection) => clients.streams.list(connection),
95
+ delete: async (identity, cascade) => {
96
+ dispatched = true;
97
+ await clients.streams.delete(identity, cascade);
98
+ },
99
+ },
100
+ }, { ...options, survivorDloNames: [] });
101
+ return {
102
+ outcome: 'deleted',
103
+ mutation: 'confirmed-deleted',
104
+ targetApiName: receipt.targetApiName,
105
+ targetDloName: receipt.targetDloName,
106
+ diagnostics: [],
107
+ };
108
+ }
109
+ catch (error) {
110
+ // The first read of the stream answered 404: already gone, nothing was sent.
111
+ if (!dispatched && watched.absent())
112
+ return {
113
+ outcome: 'unchanged',
114
+ mutation: 'not-attempted',
115
+ diagnostics: [],
116
+ };
117
+ return {
118
+ outcome: dispatched ? 'failed' : 'blocked',
119
+ mutation: dispatched ? 'unknown' : 'not-attempted',
120
+ diagnostics: [
121
+ {
122
+ code: error instanceof DataStreamError ? error.code : 'DATA_STREAM_DELETE_UNCONFIRMED',
123
+ message: operationDiagnostic(error, dispatched
124
+ ? 'Deletion outcome is unknown; inspect target before another attempt. No automatic retry.'
125
+ : 'No deletion attempted; correct the reported check before another attempt.'),
126
+ retryable: false,
127
+ },
128
+ ],
129
+ };
130
+ }
131
+ }
132
+ /**
133
+ * Select create only from independently confirmed logical absence, never an artifact-name miss.
134
+ * @param {unknown} value Portable stream intent.
135
+ * @param {DataStreamDeployClients} clients Independent target readers.
136
+ * @param {string} dataSpace The run's data space.
137
+ * @returns {Promise<object>} Private selected lifecycle plan.
138
+ */
139
+ async function planDataStream(value, clients, dataSpace) {
140
+ const document = validateDataStreamDocument(value);
141
+ requireRunSpace(document, dataSpace);
142
+ const binding = await resolveDataStreamBinding({
143
+ ...document.identity,
144
+ connectionName: document.spec.connectionName,
145
+ event: document.spec.event,
146
+ primaryKey: document.spec.newDlo.primaryKey.name,
147
+ }, clients);
148
+ return binding.target
149
+ ? preflightNativeDataStreamUpdate(document, clients, dataSpace)
150
+ : preflightNativeDataStreamCreate(document, clients, dataSpace);
151
+ }
152
+ /**
153
+ * Compare qualified stream configuration without exposing private source/schema/record identifiers.
154
+ * @param {unknown} value Portable stream intent.
155
+ * @param {DataStreamDeployClients} clients Independent target readers.
156
+ * @param {string} [dataSpace] The run's data space.
157
+ * @returns {Promise<object>} Public payload-free read-only preview.
158
+ */
159
+ export async function preflightDataStream(value, clients, dataSpace = 'default') {
160
+ if (isCrmDataStreamDocument(value))
161
+ return preflightCrmDataStream(value, clients, dataSpace);
162
+ const plan = await planDataStream(value, clients, dataSpace);
163
+ return {
164
+ family: 'data-stream',
165
+ outcome: plan.operation === 'noop' ? 'unchanged' : plan.operation,
166
+ target: plan.operation === 'create' ? 'absent' : 'existing',
167
+ absenceProof: plan.operation === 'create' ? 'complete-binding-inventory-and-dlo-404' : 'none',
168
+ requiredEffects: plan.operation === 'noop' ? [] : ['processing'],
169
+ ...(plan.operation === 'update' ? { changes: ingestUpdateChanges(plan) } : {}),
170
+ diagnostics: [],
171
+ };
172
+ }
173
+ /**
174
+ * The parts an Ingestion API update sends, for the preview: the label, each added or changed
175
+ * mapping, and each mapping removed from the file.
176
+ * @param {DataStreamUpdatePlan} plan Update plan.
177
+ * @returns {string[]} Changed parts, for example `mappings[Score2]` or `remove mappings[Old]`.
178
+ */
179
+ function ingestUpdateChanges(plan) {
180
+ return [
181
+ ...(plan.labelChange ? ['label'] : []),
182
+ ...[...plan.additions, ...plan.formulaChanges].map((entry) => 'transformationFormula' in entry && entry.transformationFormula === ''
183
+ ? `remove mappings[${entry.targetFieldName}]`
184
+ : `mappings[${entry.targetFieldName}]`),
185
+ ];
186
+ }
187
+ /**
188
+ * Dispatch through completed internal lifecycle helpers and classify failure at the actual write boundary.
189
+ * @param {unknown} value Portable stream intent.
190
+ * @param {DataStreamDeployClients} clients Native target clients.
191
+ * @param {DataStreamDeployOptions} options Exact local input guards and processing acknowledgement.
192
+ * @returns {Promise<object>} Public confirmed/unknown mutation result, without response payloads.
193
+ */
194
+ export async function executeDataStream(value, clients, options) {
195
+ if (isCrmDataStreamDocument(value))
196
+ return executeCrmDataStream(value, clients, options);
197
+ // A 4xx answer to the single write is Salesforce's refusal and is reported as rejected.
198
+ const ledger = new WriteLedger();
199
+ const guarded = {
200
+ ...clients,
201
+ streams: {
202
+ get: (name) => clients.streams.get(name),
203
+ list: (connection) => clients.streams.list(connection),
204
+ create: async (document, sourceFields) => ledger.run(async () => clients.streams.create(document, sourceFields)),
205
+ update: async (name, document) => ledger.run(async () => clients.streams.update(name, document)),
206
+ patch: async (name, body) => ledger.run(async () => clients.streams.patch(name, body)),
207
+ ...(clients.streams.relabel
208
+ ? {
209
+ // Only the update is a write: a failed read before it changed nothing.
210
+ relabel: async (name, label) => clients.streams.relabel(name, label, async (write) => ledger.run(write)),
211
+ }
212
+ : {}),
213
+ },
214
+ };
215
+ try {
216
+ const document = validateDataStreamDocument(value);
217
+ await options.verifyInput();
218
+ const plan = await planDataStream(document, guarded, options.dataSpace ?? 'default');
219
+ const result = plan.operation === 'create'
220
+ ? await createNativeDataStream(document, guarded, options)
221
+ : await updateNativeDataStream(document, guarded, options);
222
+ return {
223
+ family: 'data-stream',
224
+ outcome: result.operation === 'noop'
225
+ ? 'unchanged'
226
+ : result.operation === 'create'
227
+ ? 'created'
228
+ : 'updated',
229
+ mutation: result.operation === 'noop'
230
+ ? 'not-attempted'
231
+ : result.operation === 'create'
232
+ ? 'confirmed-created'
233
+ : 'confirmed-updated',
234
+ targetApiName: result.targetApiName,
235
+ targetDloName: result.targetDloName,
236
+ diagnostics: result.notices,
237
+ };
238
+ }
239
+ catch (error) {
240
+ const { outcome, mutation } = ledger.failure(error);
241
+ return retainStreamFailure({
242
+ family: 'data-stream',
243
+ outcome,
244
+ mutation,
245
+ diagnostics: [
246
+ {
247
+ code: error instanceof DataStreamError ? error.code : 'DATA_STREAM_REQUEST_UNCONFIRMED',
248
+ message: operationDiagnostic(error, mutation === 'rejected'
249
+ ? rejectedNextAction
250
+ : mutation === 'unknown'
251
+ ? 'Write outcome is unknown; inspect target before another attempt. No automatic retry.'
252
+ : 'No write attempted; correct the reported check before another attempt.'),
253
+ },
254
+ ],
255
+ }, error);
256
+ }
257
+ }
@@ -0,0 +1,124 @@
1
+ import type { NativeDmoDeployOptions } from './native-dmo.js';
2
+ import type { DmoClient } from '../transport/dmo-rest.js';
3
+ import type { MappingClient } from '../transport/mapping-rest.js';
4
+ /** A mapped field the file omits and the mappings whose pair targets it; empty when unidentified. */
5
+ export type MappedField = {
6
+ field: string;
7
+ mappings: string[];
8
+ };
9
+ /** What a refused mapped-field removal needs to name the mappings and the exact commands. */
10
+ export type MappedFieldGuide = {
11
+ /** Read-only mapping inventory of the target; built only after a refusal. */
12
+ mappings: () => Pick<MappingClient, 'list'>;
13
+ /** Target org exactly as passed to the command; omitted from the commands when absent. */
14
+ targetOrg?: string;
15
+ /** Data space exactly as passed to the command; omitted from the commands when absent. */
16
+ dataspace?: string;
17
+ };
18
+ export type DmoCommandOptions = NativeDmoDeployOptions & {
19
+ mappedFieldGuide?: MappedFieldGuide;
20
+ };
21
+ /** A selected mapping file, reduced to what decides whether its deployment takes a pair away. */
22
+ export type SelectedMapping = {
23
+ /** Source DLO of the binding the mapping deployment reconciles. */
24
+ source: string;
25
+ /** Target DMO of the binding the mapping deployment reconciles. */
26
+ target: string;
27
+ /** Target fields the file keeps a pair for. */
28
+ targetFields: string[];
29
+ };
30
+ /** Mapped fields the DMO may remove because the selected mapping files drop all their pairs. */
31
+ export type DmoRemovalAdmission = {
32
+ coveredMappedFields: string[];
33
+ };
34
+ export type DmoPreview = {
35
+ family: 'dmo';
36
+ outcome: 'create' | 'update' | 'unchanged';
37
+ target: 'absent' | 'existing';
38
+ absenceProof: 'confirmed-404' | 'none';
39
+ /** Custom target fields a deploy with --allow-field-removal removes. */
40
+ removeFields?: string[];
41
+ diagnostics: Array<{
42
+ code: string;
43
+ message: string;
44
+ }>;
45
+ };
46
+ /**
47
+ * Read the mapped fields and their mappings recorded for a refused field removal.
48
+ * @param {unknown} error Caught error.
49
+ * @returns {MappedField[] | undefined} Recorded fields, or nothing for any other error.
50
+ */
51
+ export declare function mappedFieldMappings(error: unknown): MappedField[] | undefined;
52
+ /**
53
+ * Report a refusal raised before any write as a blocked item.
54
+ * @param {unknown} error Caught refusal.
55
+ * @returns {object} Payload-free blocked outcome with the mapped fields of a removal refusal.
56
+ */
57
+ export declare function refusedDmo(error: unknown): {
58
+ outcome: "blocked";
59
+ mutation: "not-attempted";
60
+ diagnostics: {
61
+ mappedFields?: MappedField[] | undefined;
62
+ hint?: string;
63
+ code: string;
64
+ message: string;
65
+ }[];
66
+ };
67
+ /**
68
+ * Decide, read-only and before any write of the batch, which mapped fields a DMO may remove. A
69
+ * mapped field is covered when every target mapping that holds a pair for it is reconciled by a
70
+ * selected mapping file (same source and target object) that keeps no pair for the field.
71
+ * Salesforce then drops those pairs together with the field. Anything not covered, including a
72
+ * failed lookup, is the DMO_FIELD_REMOVAL_MAPPED refusal.
73
+ * @param {unknown} value Portable definition.
74
+ * @param {DmoClient} client Target client; only read.
75
+ * @param {string} requestScope The run's data space.
76
+ * @param {MappedFieldGuide | undefined} guide Mapping inventory source and command context.
77
+ * @param {SelectedMapping[]} selected Mapping files of the same selection.
78
+ * @returns {Promise<DmoRemovalAdmission>} Covered mapped fields; any other refusal is left to the item's own preflight.
79
+ */
80
+ export declare function admitDmoFieldRemoval(value: unknown, client: DmoClient, requestScope: string, guide: MappedFieldGuide | undefined, selected: SelectedMapping[]): Promise<DmoRemovalAdmission>;
81
+ /**
82
+ * Compare an exact native DMO without mutation.
83
+ * @param {unknown} value Portable definition.
84
+ * @param {DmoClient} client Target client.
85
+ * @param {string} requestScope The run's data space.
86
+ * @param {DmoCommandOptions} [options] Opt-in field removal and its refusal guide.
87
+ * @returns {Promise<DmoPreview>} Payload-free comparison naming any planned field removals.
88
+ */
89
+ export declare function preflightDmo(value: unknown, client: DmoClient, requestScope: string, options?: DmoCommandOptions): Promise<DmoPreview>;
90
+ /**
91
+ * Execute at most one PATCH and one field removal with conservative dispatch evidence and
92
+ * independent readback, reporting the mapping pairs Salesforce dropped with the fields.
93
+ * @param {unknown} value Portable definition.
94
+ * @param {DmoClient} client Target client.
95
+ * @param {string} requestScope The run's data space.
96
+ * @param {DmoCommandOptions} [options] Opt-in field removal and its refusal guide.
97
+ * @returns {Promise<object>} Payload-free outcome.
98
+ */
99
+ export declare function executeDmo(value: unknown, client: DmoClient, requestScope: string, options?: DmoCommandOptions): Promise<{
100
+ outcome: "unchanged";
101
+ mutation: "not-attempted";
102
+ diagnostics: {
103
+ code: string;
104
+ message: string;
105
+ }[];
106
+ } | {
107
+ diagnostics: {
108
+ code: string;
109
+ message: string;
110
+ }[];
111
+ droppedPairs?: import("./native-dmo.js").DroppedPair[] | undefined;
112
+ removedFields?: string[] | undefined;
113
+ outcome: "updated" | "created";
114
+ mutation: "confirmed-created" | "confirmed-updated";
115
+ } | {
116
+ diagnostics: {
117
+ mappedFields?: MappedField[] | undefined;
118
+ hint?: string;
119
+ code: string;
120
+ message: string;
121
+ }[];
122
+ outcome: "failed" | "blocked";
123
+ mutation: "rejected" | "unknown" | "not-attempted";
124
+ }>;