sf-plugin-data 0.0.0-stage → 0.2.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 (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +589 -2
  3. package/bin/run.js +4 -0
  4. package/docs/artifact-format.md +527 -0
  5. package/docs/capabilities.md +1208 -0
  6. package/docs/git-workflow.md +160 -0
  7. package/docs/handover.md +10446 -0
  8. package/lib/api.d.ts +7 -0
  9. package/lib/api.js +7 -0
  10. package/lib/artifacts/code-fields.d.ts +49 -0
  11. package/lib/artifacts/code-fields.js +142 -0
  12. package/lib/artifacts/data-graph-document.d.ts +29 -0
  13. package/lib/artifacts/data-graph-document.js +52 -0
  14. package/lib/artifacts/data-space-field.d.ts +65 -0
  15. package/lib/artifacts/data-space-field.js +98 -0
  16. package/lib/artifacts/data-stream-document.d.ts +264 -0
  17. package/lib/artifacts/data-stream-document.js +680 -0
  18. package/lib/artifacts/data-transform-document.d.ts +152 -0
  19. package/lib/artifacts/data-transform-document.js +560 -0
  20. package/lib/artifacts/dependency-selection.d.ts +51 -0
  21. package/lib/artifacts/dependency-selection.js +154 -0
  22. package/lib/artifacts/dlo-document.d.ts +93 -0
  23. package/lib/artifacts/dlo-document.js +253 -0
  24. package/lib/artifacts/enum-case.d.ts +39 -0
  25. package/lib/artifacts/enum-case.js +67 -0
  26. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  27. package/lib/artifacts/git-deploy-selection.js +474 -0
  28. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  29. package/lib/artifacts/identity-resolution-document.js +625 -0
  30. package/lib/artifacts/mapping-document.d.ts +1 -0
  31. package/lib/artifacts/mapping-document.js +1 -0
  32. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  33. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  34. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  35. package/lib/artifacts/native-data-graph-document.js +780 -0
  36. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  37. package/lib/artifacts/native-dmo-document.js +313 -0
  38. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  39. package/lib/artifacts/native-mapping-document.js +187 -0
  40. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  41. package/lib/artifacts/native-relationship-document.js +232 -0
  42. package/lib/artifacts/path-selector.d.ts +55 -0
  43. package/lib/artifacts/path-selector.js +167 -0
  44. package/lib/artifacts/read-deploy-input.d.ts +239 -0
  45. package/lib/artifacts/read-deploy-input.js +1359 -0
  46. package/lib/artifacts/segment-document.d.ts +183 -0
  47. package/lib/artifacts/segment-document.js +570 -0
  48. package/lib/artifacts/verbatim-document.d.ts +203 -0
  49. package/lib/artifacts/verbatim-document.js +339 -0
  50. package/lib/artifacts/write-data-graph.d.ts +17 -0
  51. package/lib/artifacts/write-data-graph.js +162 -0
  52. package/lib/artifacts/write-data-stream.d.ts +11 -0
  53. package/lib/artifacts/write-data-stream.js +175 -0
  54. package/lib/artifacts/write-data-transform.d.ts +11 -0
  55. package/lib/artifacts/write-data-transform.js +180 -0
  56. package/lib/artifacts/write-dlo.d.ts +11 -0
  57. package/lib/artifacts/write-dlo.js +158 -0
  58. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  59. package/lib/artifacts/write-identity-resolution.js +165 -0
  60. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  61. package/lib/artifacts/write-mapping-definition.js +127 -0
  62. package/lib/artifacts/write-member-export.d.ts +88 -0
  63. package/lib/artifacts/write-member-export.js +199 -0
  64. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  65. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  66. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  67. package/lib/artifacts/write-native-dmo.js +158 -0
  68. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  69. package/lib/artifacts/write-native-mapping.js +157 -0
  70. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  71. package/lib/artifacts/write-native-relationship.js +157 -0
  72. package/lib/artifacts/write-segment.d.ts +26 -0
  73. package/lib/artifacts/write-segment.js +212 -0
  74. package/lib/commands/data360/delete.d.ts +280 -0
  75. package/lib/commands/data360/delete.js +2297 -0
  76. package/lib/commands/data360/deploy.d.ts +303 -0
  77. package/lib/commands/data360/deploy.js +2400 -0
  78. package/lib/commands/data360/publish.d.ts +93 -0
  79. package/lib/commands/data360/publish.js +292 -0
  80. package/lib/commands/data360/retrieve.d.ts +322 -0
  81. package/lib/commands/data360/retrieve.js +1963 -0
  82. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  83. package/lib/commands/data360/segment/members/export.js +318 -0
  84. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  85. package/lib/errors/codes/calculated-insight.js +25 -0
  86. package/lib/errors/codes/data-graph.d.ts +2 -0
  87. package/lib/errors/codes/data-graph.js +22 -0
  88. package/lib/errors/codes/data-stream.d.ts +2 -0
  89. package/lib/errors/codes/data-stream.js +70 -0
  90. package/lib/errors/codes/data-transform.d.ts +2 -0
  91. package/lib/errors/codes/data-transform.js +35 -0
  92. package/lib/errors/codes/dependency.d.ts +2 -0
  93. package/lib/errors/codes/dependency.js +11 -0
  94. package/lib/errors/codes/dlo.d.ts +2 -0
  95. package/lib/errors/codes/dlo.js +31 -0
  96. package/lib/errors/codes/dmo.d.ts +2 -0
  97. package/lib/errors/codes/dmo.js +28 -0
  98. package/lib/errors/codes/general.d.ts +2 -0
  99. package/lib/errors/codes/general.js +57 -0
  100. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  101. package/lib/errors/codes/identity-resolution.js +24 -0
  102. package/lib/errors/codes/mapping.d.ts +2 -0
  103. package/lib/errors/codes/mapping.js +42 -0
  104. package/lib/errors/codes/relationship.d.ts +2 -0
  105. package/lib/errors/codes/relationship.js +21 -0
  106. package/lib/errors/codes/segment.d.ts +2 -0
  107. package/lib/errors/codes/segment.js +49 -0
  108. package/lib/errors/registry.d.ts +60 -0
  109. package/lib/errors/registry.js +123 -0
  110. package/lib/plugin.d.ts +5 -0
  111. package/lib/plugin.js +5 -0
  112. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  113. package/lib/services/acquire-retrieve-selection.js +145 -0
  114. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  115. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  116. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  117. package/lib/services/bind-segment-dependencies.js +115 -0
  118. package/lib/services/bounded-reads.d.ts +17 -0
  119. package/lib/services/bounded-reads.js +42 -0
  120. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  121. package/lib/services/calculated-insight-sql-checks.js +193 -0
  122. package/lib/services/command-dlo.d.ts +48 -0
  123. package/lib/services/command-dlo.js +103 -0
  124. package/lib/services/command-native-data-graph.d.ts +54 -0
  125. package/lib/services/command-native-data-graph.js +485 -0
  126. package/lib/services/command-native-data-stream.d.ts +104 -0
  127. package/lib/services/command-native-data-stream.js +257 -0
  128. package/lib/services/command-native-dmo.d.ts +124 -0
  129. package/lib/services/command-native-dmo.js +338 -0
  130. package/lib/services/command-native-mapping.d.ts +65 -0
  131. package/lib/services/command-native-mapping.js +129 -0
  132. package/lib/services/command-native-relationship.d.ts +46 -0
  133. package/lib/services/command-native-relationship.js +103 -0
  134. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  135. package/lib/services/cross-dataspace-deploy.js +493 -0
  136. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  137. package/lib/services/cross-dataspace-rename.js +1314 -0
  138. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  139. package/lib/services/cross-dataspace-sql.js +1301 -0
  140. package/lib/services/cross-space-context.d.ts +23 -0
  141. package/lib/services/cross-space-context.js +36 -0
  142. package/lib/services/crud-plan.d.ts +137 -0
  143. package/lib/services/crud-plan.js +408 -0
  144. package/lib/services/data-space-check.d.ts +89 -0
  145. package/lib/services/data-space-check.js +162 -0
  146. package/lib/services/data-space-prefix.d.ts +77 -0
  147. package/lib/services/data-space-prefix.js +127 -0
  148. package/lib/services/data-transform-space.d.ts +31 -0
  149. package/lib/services/data-transform-space.js +79 -0
  150. package/lib/services/delete-calculated-insight.d.ts +44 -0
  151. package/lib/services/delete-calculated-insight.js +101 -0
  152. package/lib/services/delete-data-transform.d.ts +52 -0
  153. package/lib/services/delete-data-transform.js +222 -0
  154. package/lib/services/delete-dmo-field.d.ts +211 -0
  155. package/lib/services/delete-dmo-field.js +472 -0
  156. package/lib/services/delete-identity-resolution.d.ts +43 -0
  157. package/lib/services/delete-identity-resolution.js +295 -0
  158. package/lib/services/delete-segment.d.ts +42 -0
  159. package/lib/services/delete-segment.js +248 -0
  160. package/lib/services/deploy-result.d.ts +54 -0
  161. package/lib/services/deploy-result.js +60 -0
  162. package/lib/services/escaped-copy.d.ts +23 -0
  163. package/lib/services/escaped-copy.js +88 -0
  164. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  165. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  166. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  167. package/lib/services/execute-data-transform-deploy.js +168 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  169. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  170. package/lib/services/execute-segment-deploy.d.ts +45 -0
  171. package/lib/services/execute-segment-deploy.js +393 -0
  172. package/lib/services/local-file-removal.d.ts +36 -0
  173. package/lib/services/local-file-removal.js +103 -0
  174. package/lib/services/native-calculated-insight.d.ts +87 -0
  175. package/lib/services/native-calculated-insight.js +164 -0
  176. package/lib/services/native-crm-data-stream.d.ts +91 -0
  177. package/lib/services/native-crm-data-stream.js +272 -0
  178. package/lib/services/native-data-graph-context.d.ts +12 -0
  179. package/lib/services/native-data-graph-context.js +139 -0
  180. package/lib/services/native-data-graph-crd.d.ts +261 -0
  181. package/lib/services/native-data-graph-crd.js +866 -0
  182. package/lib/services/native-data-stream.d.ts +329 -0
  183. package/lib/services/native-data-stream.js +1830 -0
  184. package/lib/services/native-dlo.d.ts +163 -0
  185. package/lib/services/native-dlo.js +402 -0
  186. package/lib/services/native-dmo.d.ts +191 -0
  187. package/lib/services/native-dmo.js +614 -0
  188. package/lib/services/native-mapping.d.ts +255 -0
  189. package/lib/services/native-mapping.js +1226 -0
  190. package/lib/services/native-relationship.d.ts +132 -0
  191. package/lib/services/native-relationship.js +512 -0
  192. package/lib/services/operation-diagnostic.d.ts +83 -0
  193. package/lib/services/operation-diagnostic.js +272 -0
  194. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  195. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  196. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  197. package/lib/services/preflight-data-transform-deploy.js +104 -0
  198. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  199. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  200. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  201. package/lib/services/preflight-segment-deploy.js +109 -0
  202. package/lib/services/publish-calculated-insight.d.ts +40 -0
  203. package/lib/services/publish-calculated-insight.js +95 -0
  204. package/lib/services/publish-segment.d.ts +65 -0
  205. package/lib/services/publish-segment.js +194 -0
  206. package/lib/services/readback-pace.d.ts +16 -0
  207. package/lib/services/readback-pace.js +23 -0
  208. package/lib/services/retrieve-data-transform.d.ts +26 -0
  209. package/lib/services/retrieve-data-transform.js +65 -0
  210. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  211. package/lib/services/retrieve-identity-resolution.js +87 -0
  212. package/lib/services/retrieve-inventory.d.ts +32 -0
  213. package/lib/services/retrieve-inventory.js +151 -0
  214. package/lib/services/retrieve-segment.d.ts +120 -0
  215. package/lib/services/retrieve-segment.js +502 -0
  216. package/lib/services/segment-lookup.d.ts +46 -0
  217. package/lib/services/segment-lookup.js +108 -0
  218. package/lib/services/segment-members.d.ts +144 -0
  219. package/lib/services/segment-members.js +402 -0
  220. package/lib/services/select-native-retrieve.d.ts +60 -0
  221. package/lib/services/select-native-retrieve.js +226 -0
  222. package/lib/services/settle-calculated-insight.d.ts +22 -0
  223. package/lib/services/settle-calculated-insight.js +53 -0
  224. package/lib/services/sql-tokens.d.ts +58 -0
  225. package/lib/services/sql-tokens.js +147 -0
  226. package/lib/transport/api-version.d.ts +36 -0
  227. package/lib/transport/api-version.js +89 -0
  228. package/lib/transport/bound-ssot.d.ts +27 -0
  229. package/lib/transport/bound-ssot.js +116 -0
  230. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  231. package/lib/transport/calculated-insight-rest.js +62 -0
  232. package/lib/transport/connect-client.d.ts +129 -0
  233. package/lib/transport/connect-client.js +446 -0
  234. package/lib/transport/connect-diagnostic.d.ts +89 -0
  235. package/lib/transport/connect-diagnostic.js +331 -0
  236. package/lib/transport/data-graph-rest.d.ts +27 -0
  237. package/lib/transport/data-graph-rest.js +76 -0
  238. package/lib/transport/data-stream-rest.d.ts +62 -0
  239. package/lib/transport/data-stream-rest.js +348 -0
  240. package/lib/transport/data-transform-rest.d.ts +25 -0
  241. package/lib/transport/data-transform-rest.js +100 -0
  242. package/lib/transport/dlo-native-rest.d.ts +22 -0
  243. package/lib/transport/dlo-native-rest.js +89 -0
  244. package/lib/transport/dlo-rest.d.ts +23 -0
  245. package/lib/transport/dlo-rest.js +135 -0
  246. package/lib/transport/dmo-native-rest.d.ts +18 -0
  247. package/lib/transport/dmo-native-rest.js +55 -0
  248. package/lib/transport/dmo-rest.d.ts +30 -0
  249. package/lib/transport/dmo-rest.js +163 -0
  250. package/lib/transport/mapping-rest.d.ts +63 -0
  251. package/lib/transport/mapping-rest.js +341 -0
  252. package/lib/transport/project-metadata.d.ts +36 -0
  253. package/lib/transport/project-metadata.js +118 -0
  254. package/lib/transport/relationship-rest.d.ts +43 -0
  255. package/lib/transport/relationship-rest.js +201 -0
  256. package/package.json +96 -4
@@ -0,0 +1,89 @@
1
+ import type { BoundSsot } from '../transport/bound-ssot.js';
2
+ /** Opens the command's shared bound sender (resolving the target org) on first use. */
3
+ export type DataSpaceSender = () => Promise<Pick<BoundSsot, 'request'>>;
4
+ /** Payload-free refusal of the data space check. */
5
+ export declare class DataSpaceError extends Error {
6
+ readonly code: string;
7
+ readonly status?: number | undefined;
8
+ constructor(code: string, status?: number | undefined);
9
+ }
10
+ /**
11
+ * One data space of the org: its name and, for every space but `default`, the prefix Salesforce
12
+ * gives the copies of standard DMOs in it (`ds2` for `ds2_Individual__dlm`). Only this route
13
+ * names the prefix (live API 68, DB entry data360:dataspace-name-spelling-api68).
14
+ */
15
+ export type OrgDataSpace = {
16
+ name: string;
17
+ prefix?: string;
18
+ };
19
+ /**
20
+ * Read the names of every data space of the org with `GET /ssot/data-spaces`, page by page
21
+ * (`batchSize` and `offset`) until `totalSize` names are read. Anything else is not a complete
22
+ * list: DATASPACE_READ_FAILED. A failure to open the sender (no target org) is thrown as it is.
23
+ * @param {DataSpaceSender} open Opens the command's shared bound sender.
24
+ * @returns {Promise<string[]>} Data space names.
25
+ */
26
+ export declare function readOrgDataSpaces(open: DataSpaceSender): Promise<string[]>;
27
+ /**
28
+ * Read every data space of the org as readOrgDataSpaces does, keeping each one's prefix when it
29
+ * names a usable one (letters and digits).
30
+ * @param {DataSpaceSender} open Opens the command's shared bound sender.
31
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
32
+ */
33
+ export declare function readOrgDataSpaceEntries(open: DataSpaceSender): Promise<OrgDataSpace[]>;
34
+ /**
35
+ * Reads the org's data spaces; tests replace `read` with an offline fake, which may answer plain
36
+ * names (no prefixes).
37
+ */
38
+ export declare const dataSpaceDirectory: {
39
+ read: (open: DataSpaceSender) => Promise<Array<string | OrgDataSpace>>;
40
+ };
41
+ /**
42
+ * The code a command reports when its data space check stops it: the check's own code, otherwise
43
+ * the code the failure carries (an expired session, for example), otherwise the fallback.
44
+ * @param {unknown} error Failure of the check.
45
+ * @param {string} fallback Code for a failure without one.
46
+ * @returns {string} Diagnostic code.
47
+ */
48
+ export declare function dataSpaceCheckCode(error: unknown, fallback: string): string;
49
+ /**
50
+ * The data space check of one command run, created on first use.
51
+ * @param {object} run The running command.
52
+ * @param {DataSpaceSender} sender Opens the command's shared bound sender on first use.
53
+ * @returns {DataSpaceCheck} The run's check.
54
+ */
55
+ export declare function dataSpaceCheckOf(run: object, sender: DataSpaceSender): DataSpaceCheck;
56
+ /**
57
+ * The live data space check of one command run: the org's list is read once, on first use, and
58
+ * reused for every item and type the command carries.
59
+ */
60
+ export declare class DataSpaceCheck {
61
+ private readonly sender;
62
+ private known?;
63
+ /**
64
+ * @param {DataSpaceSender} sender Opens the command's shared bound sender on first use.
65
+ */
66
+ constructor(sender: DataSpaceSender);
67
+ /**
68
+ * Refuse with UNKNOWN_DATASPACE when a named data space is not in the org.
69
+ * @param {Iterable<string>} spaces The run's data space and every space a selected file names.
70
+ * @returns {Promise<void>} Resolves when every one exists.
71
+ */
72
+ require(spaces: Iterable<string>): Promise<void>;
73
+ /**
74
+ * The prefix of a data space as the org's list names it (the same single read).
75
+ * @param {string} space Data space name.
76
+ * @returns {Promise<string | undefined>} Its prefix, or undefined when the list names none.
77
+ */
78
+ prefixOf(space: string): Promise<string | undefined>;
79
+ /**
80
+ * Every data space of the org with its prefix (the same single read).
81
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
82
+ */
83
+ entries(): Promise<OrgDataSpace[]>;
84
+ /**
85
+ * The org's data spaces, read once.
86
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
87
+ */
88
+ private spaces;
89
+ }
@@ -0,0 +1,162 @@
1
+ import { ConnectError } from '../transport/connect-client.js';
2
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
3
+ import { isDataSpaceName, sortedDataSpaces } from '../artifacts/data-space-field.js';
4
+ import { explainInput, printableKey } from './operation-diagnostic.js';
5
+ /** Payload-free refusal of the data space check. */
6
+ export class DataSpaceError extends Error {
7
+ code;
8
+ status;
9
+ constructor(code, status) {
10
+ super(`Data space check refused: ${code}.`);
11
+ this.code = code;
12
+ this.status = status;
13
+ this.name = 'DataSpaceError';
14
+ }
15
+ }
16
+ /** The route of the org's data space list (proven live on API 68, DB entry data360:dataspace-*). */
17
+ const dataSpacesRoute = '/services/data/v68.0/ssot/data-spaces';
18
+ const pageSize = 50;
19
+ // More pages than any org has data spaces; a server that keeps answering stops the read.
20
+ const pageLimit = 40;
21
+ /**
22
+ * Read the names of every data space of the org with `GET /ssot/data-spaces`, page by page
23
+ * (`batchSize` and `offset`) until `totalSize` names are read. Anything else is not a complete
24
+ * list: DATASPACE_READ_FAILED. A failure to open the sender (no target org) is thrown as it is.
25
+ * @param {DataSpaceSender} open Opens the command's shared bound sender.
26
+ * @returns {Promise<string[]>} Data space names.
27
+ */
28
+ export async function readOrgDataSpaces(open) {
29
+ const entries = await readOrgDataSpaceEntries(open);
30
+ return entries.map((entry) => entry.name);
31
+ }
32
+ /**
33
+ * Read every data space of the org as readOrgDataSpaces does, keeping each one's prefix when it
34
+ * names a usable one (letters and digits).
35
+ * @param {DataSpaceSender} open Opens the command's shared bound sender.
36
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
37
+ */
38
+ export async function readOrgDataSpaceEntries(open) {
39
+ const sender = await open();
40
+ const names = [];
41
+ for (let page = 0; page < pageLimit; page++) {
42
+ let response;
43
+ try {
44
+ response = await sender.request('GET', `${dataSpacesRoute}?batchSize=${pageSize}&offset=${names.length}`);
45
+ }
46
+ catch (error) {
47
+ // An expired or refused session keeps its own code; it is not a list problem.
48
+ if (error instanceof ConnectError && error.code === 'AUTHENTICATION_FAILED')
49
+ throw error;
50
+ const status = error instanceof ConnectError ? error.statusCode : undefined;
51
+ throw retainConnectDiagnostic(new DataSpaceError('DATASPACE_READ_FAILED', status), getConnectDiagnostic(error));
52
+ }
53
+ const body = response;
54
+ const entries = body?.dataSpaces;
55
+ const total = body?.totalSize;
56
+ if (!Array.isArray(entries) ||
57
+ typeof total !== 'number' ||
58
+ !Number.isSafeInteger(total) ||
59
+ total < names.length + entries.length)
60
+ throw new DataSpaceError('DATASPACE_READ_FAILED');
61
+ for (const entry of entries) {
62
+ const { name, prefix } = (entry ?? {});
63
+ if (!isDataSpaceName(name))
64
+ throw new DataSpaceError('DATASPACE_READ_FAILED');
65
+ names.push(typeof prefix === 'string' && /^[A-Za-z][A-Za-z0-9]{0,39}$/u.test(prefix)
66
+ ? { name, prefix }
67
+ : { name });
68
+ }
69
+ if (names.length === total)
70
+ return names;
71
+ if (entries.length === 0)
72
+ break;
73
+ }
74
+ throw new DataSpaceError('DATASPACE_READ_FAILED');
75
+ }
76
+ /**
77
+ * Reads the org's data spaces; tests replace `read` with an offline fake, which may answer plain
78
+ * names (no prefixes).
79
+ */
80
+ export const dataSpaceDirectory = { read: readOrgDataSpaceEntries };
81
+ /**
82
+ * The code a command reports when its data space check stops it: the check's own code, otherwise
83
+ * the code the failure carries (an expired session, for example), otherwise the fallback.
84
+ * @param {unknown} error Failure of the check.
85
+ * @param {string} fallback Code for a failure without one.
86
+ * @returns {string} Diagnostic code.
87
+ */
88
+ export function dataSpaceCheckCode(error, fallback) {
89
+ const code = error?.code;
90
+ return typeof code === 'string' && /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/u.test(code)
91
+ ? code
92
+ : fallback;
93
+ }
94
+ const commandChecks = new WeakMap();
95
+ /**
96
+ * The data space check of one command run, created on first use.
97
+ * @param {object} run The running command.
98
+ * @param {DataSpaceSender} sender Opens the command's shared bound sender on first use.
99
+ * @returns {DataSpaceCheck} The run's check.
100
+ */
101
+ export function dataSpaceCheckOf(run, sender) {
102
+ let check = commandChecks.get(run);
103
+ if (!check) {
104
+ check = new DataSpaceCheck(sender);
105
+ commandChecks.set(run, check);
106
+ }
107
+ return check;
108
+ }
109
+ /**
110
+ * The live data space check of one command run: the org's list is read once, on first use, and
111
+ * reused for every item and type the command carries.
112
+ */
113
+ export class DataSpaceCheck {
114
+ sender;
115
+ known;
116
+ /**
117
+ * @param {DataSpaceSender} sender Opens the command's shared bound sender on first use.
118
+ */
119
+ constructor(sender) {
120
+ this.sender = sender;
121
+ }
122
+ /**
123
+ * Refuse with UNKNOWN_DATASPACE when a named data space is not in the org.
124
+ * @param {Iterable<string>} spaces The run's data space and every space a selected file names.
125
+ * @returns {Promise<void>} Resolves when every one exists.
126
+ */
127
+ async require(spaces) {
128
+ const entries = await this.spaces();
129
+ const known = entries.map((entry) => entry.name);
130
+ const unknown = sortedDataSpaces([...spaces].filter((space) => !known.includes(space)));
131
+ if (unknown.length > 0)
132
+ throw explainInput(new DataSpaceError('UNKNOWN_DATASPACE'), `The org has no data space named ${unknown.map((space) => printableKey(space)).join(', ')}; its data spaces are ${sortedDataSpaces(known)
133
+ .map((space) => printableKey(space))
134
+ .join(', ')}.`);
135
+ }
136
+ /**
137
+ * The prefix of a data space as the org's list names it (the same single read).
138
+ * @param {string} space Data space name.
139
+ * @returns {Promise<string | undefined>} Its prefix, or undefined when the list names none.
140
+ */
141
+ async prefixOf(space) {
142
+ const entries = await this.spaces();
143
+ return entries.find((entry) => entry.name === space)?.prefix;
144
+ }
145
+ /**
146
+ * Every data space of the org with its prefix (the same single read).
147
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
148
+ */
149
+ async entries() {
150
+ return this.spaces();
151
+ }
152
+ /**
153
+ * The org's data spaces, read once.
154
+ * @returns {Promise<OrgDataSpace[]>} Data spaces.
155
+ */
156
+ async spaces() {
157
+ this.known ??= dataSpaceDirectory
158
+ .read(this.sender)
159
+ .then((entries) => entries.map((entry) => (typeof entry === 'string' ? { name: entry } : entry)));
160
+ return this.known;
161
+ }
162
+ }
@@ -0,0 +1,77 @@
1
+ import type { OrgDataSpace } from './data-space-check.js';
2
+ /**
3
+ * The four kinds of component whose names are unique in the whole org, whatever their data
4
+ * space: custom DMOs, calculated insights, data transforms and data graphs.
5
+ */
6
+ export type PrefixType = 'dmo' | 'calculated-insight' | 'data-transform' | 'data-graph';
7
+ /** The code of a prefix mismatch, per type: an error on create, a warning on retrieve and update. */
8
+ export declare const prefixMismatchCodes: Readonly<Record<PrefixType, string>>;
9
+ /** A name that does not carry the prefix its data space asks for. */
10
+ export type PrefixMismatch = {
11
+ code: string;
12
+ type: PrefixType;
13
+ name: string;
14
+ space: string;
15
+ /** The prefix the name must start with (`missing`) or must not start with (`foreign`). */
16
+ prefix: string;
17
+ /** `missing`: a non-default space's name without its prefix; `foreign`: a name in default with another space's prefix. */
18
+ reason: 'missing' | 'foreign';
19
+ /** The data space whose prefix a `foreign` name carries. */
20
+ owner?: string;
21
+ /** The name that follows the rule. */
22
+ suggestion: string;
23
+ };
24
+ /**
25
+ * Check a name against the prefix rule of its data space. In a non-default data space the name
26
+ * must start with that space's own prefix and an underscore (`ds2_Order__dlm`); in `default` it
27
+ * must not start with the prefix of any other data space. Spaces without a prefix in the org's
28
+ * list are never checked, so an org with only `default` never has a mismatch.
29
+ * @param {string} name The component's name (a DMO or insight with its suffix).
30
+ * @param {PrefixType} type Kind of component.
31
+ * @param {string} space Its data space.
32
+ * @param {readonly OrgDataSpace[]} spaces The org's data spaces, as the one space list read names them.
33
+ * @returns {PrefixMismatch | undefined} The mismatch, or undefined when the name follows the rule.
34
+ */
35
+ export declare function prefixMismatch(name: string, type: PrefixType, space: string, spaces: readonly OrgDataSpace[]): PrefixMismatch | undefined;
36
+ /**
37
+ * Whether the prefix rule covers a name before any read: every graph, insight and transform, and
38
+ * every DMO but a namespaced or standard one (`ns__X__dlm`, `ssot__X__dlm`).
39
+ * @param {PrefixType} type Kind of component.
40
+ * @param {string} name The component's name.
41
+ * @returns {boolean} Whether its name is checked.
42
+ */
43
+ export declare function prefixRuleCoversName(type: PrefixType, name: string): boolean;
44
+ /**
45
+ * Whether the prefix rule covers a component as the org read it: only what users make
46
+ * themselves. A DMO with creationType Custom and no namespace; an insight or transform with
47
+ * creationType Custom (any letter case); every graph. Standard DMOs and their copies, generated
48
+ * objects (`Dg_` transforms, Adg and other generated DMOs) and packaged ones are left out.
49
+ * @param {PrefixType} type Kind of component.
50
+ * @param {unknown} native The raw read.
51
+ * @returns {boolean} Whether the read component is checked.
52
+ */
53
+ export declare function prefixRuleCoversRead(type: PrefixType, native: unknown): boolean;
54
+ /**
55
+ * The sentence that explains a mismatch.
56
+ * @param {PrefixMismatch} mismatch The mismatch.
57
+ * @param {'create' | 'existing'} stage A new component (refused) or one that exists (warned).
58
+ * @returns {string} Explanation.
59
+ */
60
+ export declare function prefixMismatchMessage(mismatch: PrefixMismatch, stage: 'create' | 'existing'): string;
61
+ /** Refusal of a new component whose name breaks the prefix rule. */
62
+ export declare class DataSpacePrefixError extends Error {
63
+ readonly code: string;
64
+ constructor(code: string);
65
+ }
66
+ /**
67
+ * The refusal of a new component whose name breaks the prefix rule.
68
+ * @param {PrefixMismatch} mismatch The mismatch.
69
+ * @returns {DataSpacePrefixError} Refusal with its explanation.
70
+ */
71
+ export declare function prefixMismatchError(mismatch: PrefixMismatch): DataSpacePrefixError;
72
+ /**
73
+ * The warning for a component that exists (retrieve, deploy update) and breaks the prefix rule.
74
+ * @param {PrefixMismatch} mismatch The mismatch.
75
+ * @returns {string} Warning text, starting with its code.
76
+ */
77
+ export declare function prefixMismatchWarning(mismatch: PrefixMismatch): string;
@@ -0,0 +1,127 @@
1
+ import { nativeDmoWriteScope, unwrapNativeDmo } from '../artifacts/native-dmo-document.js';
2
+ import { explainInput } from './operation-diagnostic.js';
3
+ /** The code of a prefix mismatch, per type: an error on create, a warning on retrieve and update. */
4
+ export const prefixMismatchCodes = {
5
+ dmo: 'DMO_PREFIX_MISMATCH',
6
+ 'calculated-insight': 'CI_PREFIX_MISMATCH',
7
+ 'data-transform': 'TRANSFORM_PREFIX_MISMATCH',
8
+ 'data-graph': 'DATA_GRAPH_PREFIX_MISMATCH',
9
+ };
10
+ const labels = {
11
+ dmo: 'DMO',
12
+ 'calculated-insight': 'Calculated insight',
13
+ 'data-transform': 'Data transform',
14
+ 'data-graph': 'Data graph',
15
+ };
16
+ /**
17
+ * Check a name against the prefix rule of its data space. In a non-default data space the name
18
+ * must start with that space's own prefix and an underscore (`ds2_Order__dlm`); in `default` it
19
+ * must not start with the prefix of any other data space. Spaces without a prefix in the org's
20
+ * list are never checked, so an org with only `default` never has a mismatch.
21
+ * @param {string} name The component's name (a DMO or insight with its suffix).
22
+ * @param {PrefixType} type Kind of component.
23
+ * @param {string} space Its data space.
24
+ * @param {readonly OrgDataSpace[]} spaces The org's data spaces, as the one space list read names them.
25
+ * @returns {PrefixMismatch | undefined} The mismatch, or undefined when the name follows the rule.
26
+ */
27
+ export function prefixMismatch(name, type, space, spaces) {
28
+ const others = spaces.filter((entry) => entry.name !== space && entry.name !== 'default' && entry.prefix !== undefined);
29
+ const carried = others.find((entry) => name.startsWith(`${entry.prefix}_`));
30
+ const base = { code: prefixMismatchCodes[type], type, name, space };
31
+ if (space === 'default') {
32
+ if (!carried)
33
+ return undefined;
34
+ return {
35
+ ...base,
36
+ prefix: carried.prefix,
37
+ reason: 'foreign',
38
+ owner: carried.name,
39
+ suggestion: name.slice(carried.prefix.length + 1),
40
+ };
41
+ }
42
+ const own = spaces.find((entry) => entry.name === space)?.prefix;
43
+ if (own === undefined || name.startsWith(`${own}_`))
44
+ return undefined;
45
+ return {
46
+ ...base,
47
+ prefix: own,
48
+ reason: 'missing',
49
+ suggestion: `${own}_${carried ? name.slice(carried.prefix.length + 1) : name}`,
50
+ };
51
+ }
52
+ /**
53
+ * Whether the prefix rule covers a name before any read: every graph, insight and transform, and
54
+ * every DMO but a namespaced or standard one (`ns__X__dlm`, `ssot__X__dlm`).
55
+ * @param {PrefixType} type Kind of component.
56
+ * @param {string} name The component's name.
57
+ * @returns {boolean} Whether its name is checked.
58
+ */
59
+ export function prefixRuleCoversName(type, name) {
60
+ return type !== 'dmo' || !name.slice(0, -'__dlm'.length).includes('__');
61
+ }
62
+ /**
63
+ * Whether the prefix rule covers a component as the org read it: only what users make
64
+ * themselves. A DMO with creationType Custom and no namespace; an insight or transform with
65
+ * creationType Custom (any letter case); every graph. Standard DMOs and their copies, generated
66
+ * objects (`Dg_` transforms, Adg and other generated DMOs) and packaged ones are left out.
67
+ * @param {PrefixType} type Kind of component.
68
+ * @param {unknown} native The raw read.
69
+ * @returns {boolean} Whether the read component is checked.
70
+ */
71
+ export function prefixRuleCoversRead(type, native) {
72
+ if (type === 'data-graph')
73
+ return true;
74
+ if (!native || typeof native !== 'object' || Array.isArray(native))
75
+ return false;
76
+ if (type === 'dmo') {
77
+ try {
78
+ return nativeDmoWriteScope(unwrapNativeDmo(native)) === 'custom';
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ const { creationType } = native;
85
+ return typeof creationType === 'string' && creationType.toLowerCase() === 'custom';
86
+ }
87
+ /**
88
+ * The sentence that explains a mismatch.
89
+ * @param {PrefixMismatch} mismatch The mismatch.
90
+ * @param {'create' | 'existing'} stage A new component (refused) or one that exists (warned).
91
+ * @returns {string} Explanation.
92
+ */
93
+ export function prefixMismatchMessage(mismatch, stage) {
94
+ const { type, name, space, prefix, owner, suggestion } = mismatch;
95
+ const subject = `${labels[type]} ${name} ${stage === 'create' ? 'is new in' : 'is in'} the data space ${space}`;
96
+ const problem = mismatch.reason === 'missing'
97
+ ? `its name does not start with ${prefix}_, the prefix of that data space`
98
+ : `its name starts with ${prefix}_, the prefix of the data space ${owner}`;
99
+ return stage === 'create'
100
+ ? `${subject}, but ${problem}. Name it ${suggestion} in the file and its file name, then rerun.`
101
+ : `${subject}, but ${problem}. Names of this kind are unique in the org; ${suggestion} would follow the rule. The plugin does not rename it.`;
102
+ }
103
+ /** Refusal of a new component whose name breaks the prefix rule. */
104
+ export class DataSpacePrefixError extends Error {
105
+ code;
106
+ constructor(code) {
107
+ super(`Data space prefix check refused: ${code}.`);
108
+ this.code = code;
109
+ this.name = 'DataSpacePrefixError';
110
+ }
111
+ }
112
+ /**
113
+ * The refusal of a new component whose name breaks the prefix rule.
114
+ * @param {PrefixMismatch} mismatch The mismatch.
115
+ * @returns {DataSpacePrefixError} Refusal with its explanation.
116
+ */
117
+ export function prefixMismatchError(mismatch) {
118
+ return explainInput(new DataSpacePrefixError(mismatch.code), prefixMismatchMessage(mismatch, 'create'));
119
+ }
120
+ /**
121
+ * The warning for a component that exists (retrieve, deploy update) and breaks the prefix rule.
122
+ * @param {PrefixMismatch} mismatch The mismatch.
123
+ * @returns {string} Warning text, starting with its code.
124
+ */
125
+ export function prefixMismatchWarning(mismatch) {
126
+ return `${mismatch.code}: ${prefixMismatchMessage(mismatch, 'existing')}`;
127
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The data space of every data transform of the org, read with one SOQL query over the command's
3
+ * own connection: `SELECT Id, DataSpace.Name FROM MktDataTransform`. Live at API 68 (DB entry
4
+ * data360:dataspace-access-membership-20261118-api68): `Id` is the transform's `1dt` record ID
5
+ * (the `id` of its GET and list entry) and `DataSpaceId` points at its data space; the system
6
+ * transform `StaticCurrencyRatesTransform_Home` has none (null). `Name` is the label, not the API
7
+ * name, and the object has no developer name, so the map is keyed by ID only (18 characters and
8
+ * the 15-character prefix). Anything but one complete page of records with a usable ID is
9
+ * TRANSFORM_DATASPACE_UNREADABLE.
10
+ * @param {(query: string) => Promise<unknown>} soql Runs one SOQL query.
11
+ * @returns {Promise<ReadonlyMap<string, string | null>>} Record ID to data space (null: none).
12
+ */
13
+ export declare function readDataTransformSpaces(soql: (query: string) => Promise<unknown>): Promise<ReadonlyMap<string, string | null>>;
14
+ /**
15
+ * The data space of one transform as the plugin handles it: the `dataSpaceName` of its GET when
16
+ * it names one, otherwise the data space its MktDataTransform record names, found by the GET's
17
+ * record `id` only (never by a name or label). A transform without any data space (a system
18
+ * transform) is handled in `default` only; a missing `id`, or one the records lack, is
19
+ * TRANSFORM_DATASPACE_UNREADABLE.
20
+ * @param {Record<string, unknown>} raw The transform GET.
21
+ * @param {() => Promise<ReadonlyMap<string, string | null>>} spaces The org's transform spaces.
22
+ * @returns {Promise<string>} Data space.
23
+ */
24
+ export declare function resolveDataTransformSpace(raw: Record<string, unknown>, spaces: () => Promise<ReadonlyMap<string, string | null>>): Promise<string>;
25
+ /**
26
+ * The data space of a transform record ID in the org's records (`default` for none).
27
+ * @param {unknown} id Record ID.
28
+ * @param {ReadonlyMap<string, string | null>} known The org's transform spaces.
29
+ * @returns {string} Data space.
30
+ */
31
+ export declare function dataTransformSpaceById(id: unknown, known: ReadonlyMap<string, string | null>): string;
@@ -0,0 +1,79 @@
1
+ import { DataTransformError } from '../artifacts/data-transform-document.js';
2
+ import { isDataSpaceName } from '../artifacts/data-space-field.js';
3
+ // A transform record ID: `1dt`, 15 or 18 characters.
4
+ const recordId = /^1dt[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/u;
5
+ /**
6
+ * The refusal of an unreadable data space of a transform.
7
+ * @returns {DataTransformError} TRANSFORM_DATASPACE_UNREADABLE.
8
+ */
9
+ function unreadable() {
10
+ return new DataTransformError('TRANSFORM_DATASPACE_UNREADABLE');
11
+ }
12
+ /**
13
+ * The data space of every data transform of the org, read with one SOQL query over the command's
14
+ * own connection: `SELECT Id, DataSpace.Name FROM MktDataTransform`. Live at API 68 (DB entry
15
+ * data360:dataspace-access-membership-20261118-api68): `Id` is the transform's `1dt` record ID
16
+ * (the `id` of its GET and list entry) and `DataSpaceId` points at its data space; the system
17
+ * transform `StaticCurrencyRatesTransform_Home` has none (null). `Name` is the label, not the API
18
+ * name, and the object has no developer name, so the map is keyed by ID only (18 characters and
19
+ * the 15-character prefix). Anything but one complete page of records with a usable ID is
20
+ * TRANSFORM_DATASPACE_UNREADABLE.
21
+ * @param {(query: string) => Promise<unknown>} soql Runs one SOQL query.
22
+ * @returns {Promise<ReadonlyMap<string, string | null>>} Record ID to data space (null: none).
23
+ */
24
+ export async function readDataTransformSpaces(soql) {
25
+ let response;
26
+ try {
27
+ response = await soql('SELECT Id, DataSpace.Name FROM MktDataTransform');
28
+ }
29
+ catch {
30
+ throw unreadable();
31
+ }
32
+ const body = response;
33
+ if (!body ||
34
+ body.done !== true ||
35
+ !Array.isArray(body.records) ||
36
+ body.records.length !== body.totalSize)
37
+ throw unreadable();
38
+ const spaces = new Map();
39
+ for (const entry of body.records) {
40
+ const record = (entry ?? {});
41
+ const space = record.DataSpace?.Name;
42
+ if (typeof record.Id !== 'string' ||
43
+ !recordId.test(record.Id) ||
44
+ (space !== undefined && space !== null && !isDataSpaceName(space)))
45
+ throw unreadable();
46
+ // eslint-disable-next-line unicorn/no-null -- null marks a transform without any data space.
47
+ const value = isDataSpaceName(space) ? space : null;
48
+ spaces.set(record.Id, value);
49
+ // A 15-character ID matches the 18-character one of the GET too.
50
+ spaces.set(record.Id.slice(0, 15), value);
51
+ }
52
+ return spaces;
53
+ }
54
+ /**
55
+ * The data space of one transform as the plugin handles it: the `dataSpaceName` of its GET when
56
+ * it names one, otherwise the data space its MktDataTransform record names, found by the GET's
57
+ * record `id` only (never by a name or label). A transform without any data space (a system
58
+ * transform) is handled in `default` only; a missing `id`, or one the records lack, is
59
+ * TRANSFORM_DATASPACE_UNREADABLE.
60
+ * @param {Record<string, unknown>} raw The transform GET.
61
+ * @param {() => Promise<ReadonlyMap<string, string | null>>} spaces The org's transform spaces.
62
+ * @returns {Promise<string>} Data space.
63
+ */
64
+ export async function resolveDataTransformSpace(raw, spaces) {
65
+ if (isDataSpaceName(raw.dataSpaceName))
66
+ return raw.dataSpaceName;
67
+ return dataTransformSpaceById(raw.id, await spaces());
68
+ }
69
+ /**
70
+ * The data space of a transform record ID in the org's records (`default` for none).
71
+ * @param {unknown} id Record ID.
72
+ * @param {ReadonlyMap<string, string | null>} known The org's transform spaces.
73
+ * @returns {string} Data space.
74
+ */
75
+ export function dataTransformSpaceById(id, known) {
76
+ if (typeof id !== 'string' || !recordId.test(id) || !known.has(id))
77
+ throw unreadable();
78
+ return known.get(id) ?? 'default';
79
+ }
@@ -0,0 +1,44 @@
1
+ import type { ApiVersionSelection } from '../transport/api-version.js';
2
+ import type { CalculatedInsightClient } from '../transport/calculated-insight-rest.js';
3
+ import type { CalculatedInsightConnection, CalculatedInsightReadContext } from './native-calculated-insight.js';
4
+ import type { CalculatedInsightTiming } from './settle-calculated-insight.js';
5
+ export type CalculatedInsightDeleteOptions = CalculatedInsightTiming & {
6
+ preview?: boolean;
7
+ confirmDelete: boolean;
8
+ verifyInput: () => Promise<void>;
9
+ context?: CalculatedInsightReadContext;
10
+ nativeClient?: Pick<CalculatedInsightClient, 'delete'>;
11
+ };
12
+ export type CalculatedInsightDeleteResult = {
13
+ family: 'calculated-insight';
14
+ route: {
15
+ apiVersion: '68.0';
16
+ method: 'DELETE';
17
+ resource: 'calculated-insights';
18
+ };
19
+ outcome: 'delete' | 'deleted' | 'unchanged' | 'blocked' | 'failed';
20
+ mutation: 'not-attempted' | 'confirmed-deleted' | 'unknown' | 'rejected';
21
+ requiredEffects: Array<'destructive'>;
22
+ diagnostics: Array<{
23
+ code: string;
24
+ message: string;
25
+ }>;
26
+ };
27
+ /**
28
+ * Delete one insight by name: absent is unchanged; otherwise one DELETE, then reads until it
29
+ * answers 404. The read before the DELETE must answer with the selected name and data space
30
+ * (the name and data space check of `calculatedInsightPresence`). Any status and content is deletable;
31
+ * Salesforce decides. No cascade, replay or rollback.
32
+ * @param {object} value Identity of the insight (a document from the org or the base file).
33
+ * @param {string} value.apiName Exact name ending in __cio.
34
+ * @param {string} value.dataSpace Its data space.
35
+ * @param {CalculatedInsightConnection} connection API 68 connection.
36
+ * @param {ApiVersionSelection} selection Route selection (68.0).
37
+ * @param {string} dataSpace Selected data space.
38
+ * @param {CalculatedInsightDeleteOptions} options Confirmation, verifier, preview and test seams.
39
+ * @returns {Promise<CalculatedInsightDeleteResult>} Payload-free outcome.
40
+ */
41
+ export declare function deleteCalculatedInsight(value: {
42
+ apiName: string;
43
+ dataSpace: string;
44
+ }, connection: CalculatedInsightConnection, selection: ApiVersionSelection, dataSpace: string, options: CalculatedInsightDeleteOptions): Promise<CalculatedInsightDeleteResult>;