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,17 @@
1
+ /** The outcome of one read: its value, or what it threw. */
2
+ export type SettledRead<T> = {
3
+ value: T;
4
+ } | {
5
+ error: unknown;
6
+ };
7
+ /**
8
+ * Start a read per item with at most `limit` running at once, in item order. Each returned
9
+ * promise settles with its own read's outcome and never rejects, so the caller can consume the
10
+ * results strictly in item order while later reads are still running.
11
+ * @template I, T
12
+ * @param {I[]} items Items to read.
13
+ * @param {number} limit Maximum concurrent reads (at least 1).
14
+ * @param {(item: I) => Promise<T>} read One read.
15
+ * @returns {Array<Promise<SettledRead<T>>>} One outcome per item, in item order.
16
+ */
17
+ export declare function readInOrder<I, T>(items: I[], limit: number, read: (item: I) => Promise<T>): Array<Promise<SettledRead<T>>>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Start a read per item with at most `limit` running at once, in item order. Each returned
3
+ * promise settles with its own read's outcome and never rejects, so the caller can consume the
4
+ * results strictly in item order while later reads are still running.
5
+ * @template I, T
6
+ * @param {I[]} items Items to read.
7
+ * @param {number} limit Maximum concurrent reads (at least 1).
8
+ * @param {(item: I) => Promise<T>} read One read.
9
+ * @returns {Array<Promise<SettledRead<T>>>} One outcome per item, in item order.
10
+ */
11
+ export function readInOrder(items, limit, read) {
12
+ const waiting = [];
13
+ let running = 0;
14
+ const slot = async () => {
15
+ if (running < Math.max(1, limit)) {
16
+ running++;
17
+ return;
18
+ }
19
+ await new Promise((resolve) => {
20
+ waiting.push(resolve);
21
+ });
22
+ };
23
+ const release = () => {
24
+ const next = waiting.shift();
25
+ if (next)
26
+ next();
27
+ else
28
+ running--;
29
+ };
30
+ return items.map(async (item) => {
31
+ await slot();
32
+ try {
33
+ return { value: await read(item) };
34
+ }
35
+ catch (error) {
36
+ return { error };
37
+ }
38
+ finally {
39
+ release();
40
+ }
41
+ });
42
+ }
@@ -0,0 +1,33 @@
1
+ /** The warning code of SQL that Salesforce accepts on create and publish but cannot run. */
2
+ export declare const ciSqlFailsSilentlyCode = "CI_SQL_FAILS_SILENTLY";
3
+ /** One construct of an insight's SQL that makes the insight fail after publish. */
4
+ export type CalculatedInsightSqlFinding = {
5
+ line: number;
6
+ column: number;
7
+ /** What was found, for example `a -- comment`. */
8
+ construct: string;
9
+ /** How to write it instead. */
10
+ fix: string;
11
+ };
12
+ /**
13
+ * Find the constructs of a calculated insight's SQL that Salesforce accepts on create and publish
14
+ * but then fails a few minutes later (ERROR, CREATE_FAILED, no message; live API 68):
15
+ * - classic (`ANSI_SQL`): a table alias of an object in FROM or JOIN (with or without AS), a quoted
16
+ * column alias (double quotes or backticks), a text literal as a column, a `--` comment;
17
+ * - SQL Insights Builder (`DC_SQL`): a column alias in backticks.
18
+ * Texts and comments are never read as code. SQL the tokenizer cannot read, and a missing or
19
+ * unknown dialect, give no findings.
20
+ * @param {string} sql The insight's SQL.
21
+ * @param {unknown} queryDialect The file's `queryDialect`.
22
+ * @returns {CalculatedInsightSqlFinding[]} Findings in text order.
23
+ */
24
+ export declare function findSilentSqlFailures(sql: string, queryDialect: unknown): CalculatedInsightSqlFinding[];
25
+ /**
26
+ * The deploy warnings of one calculated insight: one per finding, naming its SQL file, line and
27
+ * column, the construct and the fix. The deploy goes ahead; Salesforce decides.
28
+ * @param {string} sql The insight's SQL.
29
+ * @param {unknown} queryDialect The file's `queryDialect`.
30
+ * @param {string} file The SQL file as shown to the user.
31
+ * @returns {string[]} Warnings.
32
+ */
33
+ export declare function silentSqlFailureWarnings(sql: string, queryDialect: unknown, file: string): string[];
@@ -0,0 +1,193 @@
1
+ import { operatorWords, reservedWords } from './cross-dataspace-sql.js';
2
+ import { isSqlTokenProblem, tokenizeSql } from './sql-tokens.js';
3
+ /** The warning code of SQL that Salesforce accepts on create and publish but cannot run. */
4
+ export const ciSqlFailsSilentlyCode = 'CI_SQL_FAILS_SILENTLY';
5
+ // Words that end a select list or a FROM clause in the same query block.
6
+ const clauseEnd = new Set([
7
+ 'FROM',
8
+ 'WHERE',
9
+ 'GROUP',
10
+ 'HAVING',
11
+ 'QUALIFY',
12
+ 'WINDOW',
13
+ 'ORDER',
14
+ 'LIMIT',
15
+ 'OFFSET',
16
+ 'FETCH',
17
+ 'UNION',
18
+ 'INTERSECT',
19
+ 'EXCEPT',
20
+ 'MINUS',
21
+ ]);
22
+ const objectLike = /__(?:dlm|cio|dll)$/iu;
23
+ /**
24
+ * The dialect of a `queryDialect` value, in either spelling (`ANSI_SQL` or `AnsiSql`).
25
+ * @param {unknown} value `queryDialect` of the file.
26
+ * @returns {Dialect | undefined} Dialect, or undefined when missing or unknown.
27
+ */
28
+ function dialectOf(value) {
29
+ if (typeof value !== 'string')
30
+ return undefined;
31
+ const plain = value.replaceAll('_', '').toLowerCase();
32
+ if (plain === 'ansisql')
33
+ return 'classic';
34
+ if (plain === 'dcsql')
35
+ return 'dc-sql';
36
+ return undefined;
37
+ }
38
+ /**
39
+ * Find the constructs of a calculated insight's SQL that Salesforce accepts on create and publish
40
+ * but then fails a few minutes later (ERROR, CREATE_FAILED, no message; live API 68):
41
+ * - classic (`ANSI_SQL`): a table alias of an object in FROM or JOIN (with or without AS), a quoted
42
+ * column alias (double quotes or backticks), a text literal as a column, a `--` comment;
43
+ * - SQL Insights Builder (`DC_SQL`): a column alias in backticks.
44
+ * Texts and comments are never read as code. SQL the tokenizer cannot read, and a missing or
45
+ * unknown dialect, give no findings.
46
+ * @param {string} sql The insight's SQL.
47
+ * @param {unknown} queryDialect The file's `queryDialect`.
48
+ * @returns {CalculatedInsightSqlFinding[]} Findings in text order.
49
+ */
50
+ export function findSilentSqlFailures(sql, queryDialect) {
51
+ const dialect = dialectOf(queryDialect);
52
+ if (dialect === undefined)
53
+ return [];
54
+ const tokens = tokenizeSql(sql);
55
+ if (isSqlTokenProblem(tokens))
56
+ return [];
57
+ const findings = [];
58
+ const add = (token, construct, fix) => {
59
+ findings.push({ line: token.line, column: token.column, construct, fix });
60
+ };
61
+ if (dialect === 'classic')
62
+ for (const token of tokens)
63
+ if (token.kind === 'comment' && token.text.startsWith('--'))
64
+ add(token, 'a -- comment', 'remove the comment');
65
+ const sig = tokens.filter((token) => token.kind !== 'space' && token.kind !== 'comment');
66
+ const match = new Map();
67
+ const open = [];
68
+ for (const [p, token] of sig.entries())
69
+ if (token.kind === 'punct' && token.text === '(')
70
+ open.push(p);
71
+ else if (token.kind === 'punct' && token.text === ')') {
72
+ const start = open.pop();
73
+ if (start === undefined)
74
+ return sortFindings(findings);
75
+ match.set(start, p);
76
+ }
77
+ if (open.length > 0)
78
+ return sortFindings(findings);
79
+ const upper = (p, end) => p < end && sig[p].kind === 'word' ? sig[p].text.toUpperCase() : '';
80
+ const isPunct = (p, text, end) => p < end && sig[p].kind === 'punct' && sig[p].text === text;
81
+ const isName = (p, end) => p < end && (sig[p].kind === 'word' || sig[p].kind === 'quoted');
82
+ const skip = (p) => (isPunct(p, '(', sig.length) ? match.get(p) + 1 : p + 1);
83
+ const isClauseEnd = (p, end) => clauseEnd.has(upper(p, end)) || isPunct(p, ';', end);
84
+ const selectItem = (begin, end) => {
85
+ const last = end - 1;
86
+ const before = last - 1;
87
+ const hasAs = before >= begin && upper(before, end) === 'AS';
88
+ const operand = before >= begin &&
89
+ (isPunct(before, ')', end) ||
90
+ ['number', 'string', 'quoted'].includes(sig[before].kind) ||
91
+ (sig[before].kind === 'word' && !operatorWords.has(upper(before, end))));
92
+ const aliased = last > begin &&
93
+ isName(last, end) &&
94
+ !isPunct(before, '.', end) &&
95
+ (hasAs || (!reservedWords.has(upper(last, end)) && operand));
96
+ const alias = aliased ? sig[last] : undefined;
97
+ if (alias?.kind === 'quoted') {
98
+ const unquoted = `write the alias without quotes (${alias.value ?? ''})`;
99
+ if (dialect === 'classic')
100
+ add(alias, `a quoted column alias ${alias.text}`, unquoted);
101
+ else if (alias.quote === '`')
102
+ add(alias, `a column alias in backticks ${alias.text}`, unquoted);
103
+ }
104
+ // A text literal alone as a column, with or without an alias.
105
+ if (dialect === 'classic' &&
106
+ sig[begin].kind === 'string' &&
107
+ (end === begin + 1 || (aliased && (hasAs ? before === begin + 1 : last === begin + 1))))
108
+ add(sig[begin], `a text literal ${sig[begin].text} as a column`, 'remove it, or build the insight in the SQL Insights Builder (DC_SQL)');
109
+ };
110
+ const selectList = (from, to) => {
111
+ let p = from;
112
+ while (['DISTINCT', 'ALL'].includes(upper(p, to)))
113
+ p++;
114
+ let start = p;
115
+ for (; p < to; p = skip(p))
116
+ if (isPunct(p, ',', to)) {
117
+ if (p > start)
118
+ selectItem(start, p);
119
+ start = p + 1;
120
+ }
121
+ if (start < to)
122
+ selectItem(start, to);
123
+ };
124
+ const fromClause = (from, to) => {
125
+ let tableStart = true;
126
+ for (let p = from; p < to; p = skip(p)) {
127
+ if (isPunct(p, ',', to) || upper(p, to) === 'JOIN') {
128
+ tableStart = true;
129
+ continue;
130
+ }
131
+ if (!tableStart)
132
+ continue;
133
+ tableStart = false;
134
+ if (!isName(p, to) ||
135
+ !objectLike.test(sig[p].kind === 'quoted' ? (sig[p].value ?? '') : sig[p].text) ||
136
+ isPunct(p + 1, '(', to) ||
137
+ isPunct(p + 1, '.', to))
138
+ continue;
139
+ let aliasAt = p + 1;
140
+ if (upper(aliasAt, to) === 'AS')
141
+ aliasAt++;
142
+ if (isName(aliasAt, to) &&
143
+ !reservedWords.has(upper(aliasAt, to)) &&
144
+ !['ON', 'USING', 'TABLESAMPLE'].includes(upper(aliasAt, to))) {
145
+ const table = sig[p].kind === 'quoted' ? (sig[p].value ?? '') : sig[p].text;
146
+ add(sig[aliasAt], `the table alias ${sig[aliasAt].text} of ${table}`, `write the full object name in front of each field (${table}.Field__c) and drop the alias`);
147
+ }
148
+ }
149
+ };
150
+ // Every query block, at every depth: its select list and, in classic SQL, its FROM clause.
151
+ const scan = (from, to) => {
152
+ for (let p = from; p < to; p = skip(p)) {
153
+ if (isPunct(p, '(', to))
154
+ scan(p + 1, match.get(p));
155
+ if (upper(p, to) !== 'SELECT')
156
+ continue;
157
+ let end = p + 1;
158
+ while (end < to && !isClauseEnd(end, to))
159
+ end = skip(end);
160
+ selectList(p + 1, end);
161
+ if (dialect !== 'classic' || upper(end, to) !== 'FROM')
162
+ continue;
163
+ let fromEnd = end + 1;
164
+ while (fromEnd < to && !isClauseEnd(fromEnd, to))
165
+ fromEnd = skip(fromEnd);
166
+ fromClause(end + 1, fromEnd);
167
+ }
168
+ };
169
+ scan(0, sig.length);
170
+ return sortFindings(findings);
171
+ }
172
+ /**
173
+ * Findings in text order.
174
+ * @param {CalculatedInsightSqlFinding[]} findings Findings.
175
+ * @returns {CalculatedInsightSqlFinding[]} The same, sorted by line and column.
176
+ */
177
+ function sortFindings(findings) {
178
+ // eslint-disable-next-line unicorn/no-array-sort -- Sorting the array built here.
179
+ return findings.sort((left, right) => left.line - right.line || left.column - right.column);
180
+ }
181
+ /**
182
+ * The deploy warnings of one calculated insight: one per finding, naming its SQL file, line and
183
+ * column, the construct and the fix. The deploy goes ahead; Salesforce decides.
184
+ * @param {string} sql The insight's SQL.
185
+ * @param {unknown} queryDialect The file's `queryDialect`.
186
+ * @param {string} file The SQL file as shown to the user.
187
+ * @returns {string[]} Warnings.
188
+ */
189
+ export function silentSqlFailureWarnings(sql, queryDialect, file) {
190
+ const dialect = dialectOf(queryDialect);
191
+ const kind = dialect === 'classic' ? 'a classic (ANSI_SQL) insight' : 'a DC_SQL insight';
192
+ return findSilentSqlFailures(sql, queryDialect).map((finding) => `${ciSqlFailsSilentlyCode}: ${file} line ${finding.line}:${finding.column}: ${finding.construct} in ${kind}. Salesforce accepts it on deploy and publish, but the insight then ends in ERROR (CREATE_FAILED) without a message; ${finding.fix}.`);
193
+ }
@@ -0,0 +1,48 @@
1
+ import type { DloDeployOptions, DloMembershipChange } from './native-dlo.js';
2
+ import type { DloClient } from '../transport/dlo-rest.js';
3
+ export type DloPreview = {
4
+ family: 'dlo';
5
+ outcome: 'create' | 'update' | 'unchanged' | 'blocked';
6
+ target: 'absent' | 'existing' | 'unknown';
7
+ absenceProof: 'confirmed-404' | 'none';
8
+ /** Every data space of the file, sorted. */
9
+ dataSpaces?: string[];
10
+ /** Data spaces the deploy adds the DLO to or removes it from; absent when none change. */
11
+ dataSpaceChanges?: DloMembershipChange;
12
+ diagnostics: Array<{
13
+ code: string;
14
+ message: string;
15
+ }>;
16
+ };
17
+ export type DloExecution = {
18
+ family: 'dlo';
19
+ outcome: 'created' | 'updated' | 'unchanged' | 'failed' | 'blocked';
20
+ mutation: 'confirmed-created' | 'confirmed-updated' | 'unknown' | 'not-attempted' | 'rejected';
21
+ serverProcessing?: true;
22
+ /** The data spaces the DLO belongs to after the deploy, sorted. */
23
+ dataSpaces?: string[];
24
+ /** Data spaces the deploy added the DLO to or removed it from; absent when none changed. */
25
+ dataSpaceChanges?: DloMembershipChange;
26
+ diagnostics: Array<{
27
+ code: string;
28
+ message: string;
29
+ }>;
30
+ };
31
+ /**
32
+ * Compare a portable definition without mutation.
33
+ * @param {unknown} value Portable definition.
34
+ * @param {DloClient} client Target API client.
35
+ * @param {string} dataSpace The run's data space.
36
+ * @param {DloDeployOptions} [options] Data space removal permission.
37
+ * @returns {Promise<DloPreview>} Payload-free comparison.
38
+ */
39
+ export declare function preflightDloDeploy(value: unknown, client: DloClient, dataSpace: string, options?: DloDeployOptions): Promise<DloPreview>;
40
+ /**
41
+ * Deploy through freshly resolved target identity.
42
+ * @param {unknown} value Portable definition.
43
+ * @param {DloClient} client Target client.
44
+ * @param {string} dataSpace The run's data space.
45
+ * @param {DloDeployOptions} [options] Data space removal permission.
46
+ * @returns {Promise<DloExecution>} Accepted write or conservative unknown outcome.
47
+ */
48
+ export declare function executeDloDeploy(value: unknown, client: DloClient, dataSpace: string, options?: DloDeployOptions): Promise<DloExecution>;
@@ -0,0 +1,103 @@
1
+ import { operationDiagnostic } from './operation-diagnostic.js';
2
+ import { DloError } from '../artifacts/dlo-document.js';
3
+ import { preflightNativeDlo, deployNativeDlo } from './native-dlo.js';
4
+ import { WriteLedger, rejectedNextAction } from './deploy-result.js';
5
+ /** Data space refusals a preview reports on the item instead of failing. */
6
+ const blockingSpaceCodes = new Set(['DLO_DATASPACE_REMOVAL_NOT_ALLOWED']);
7
+ /**
8
+ * Compare a portable definition without mutation.
9
+ * @param {unknown} value Portable definition.
10
+ * @param {DloClient} client Target API client.
11
+ * @param {string} dataSpace The run's data space.
12
+ * @param {DloDeployOptions} [options] Data space removal permission.
13
+ * @returns {Promise<DloPreview>} Payload-free comparison.
14
+ */
15
+ export async function preflightDloDeploy(value, client, dataSpace, options = {}) {
16
+ let plan;
17
+ try {
18
+ plan = await preflightNativeDlo(value, client, dataSpace, options);
19
+ }
20
+ catch (error) {
21
+ // A data space change the deploy would refuse is the item's own block, with its code.
22
+ if (!(error instanceof DloError) || !blockingSpaceCodes.has(error.code))
23
+ throw error;
24
+ return {
25
+ family: 'dlo',
26
+ outcome: 'blocked',
27
+ target: 'existing',
28
+ absenceProof: 'none',
29
+ diagnostics: [
30
+ {
31
+ code: error.code,
32
+ message: operationDiagnostic(error, 'Preview only; nothing was written.'),
33
+ },
34
+ ],
35
+ };
36
+ }
37
+ return {
38
+ family: 'dlo',
39
+ outcome: plan.operation,
40
+ target: plan.operation === 'create' ? 'absent' : 'existing',
41
+ absenceProof: plan.operation === 'create' ? 'confirmed-404' : 'none',
42
+ dataSpaces: plan.dataSpaces,
43
+ ...(plan.membership.add.length > 0 || plan.membership.remove.length > 0
44
+ ? { dataSpaceChanges: plan.membership }
45
+ : {}),
46
+ diagnostics: [],
47
+ };
48
+ }
49
+ /**
50
+ * Deploy through freshly resolved target identity.
51
+ * @param {unknown} value Portable definition.
52
+ * @param {DloClient} client Target client.
53
+ * @param {string} dataSpace The run's data space.
54
+ * @param {DloDeployOptions} [options] Data space removal permission.
55
+ * @returns {Promise<DloExecution>} Accepted write or conservative unknown outcome.
56
+ */
57
+ export async function executeDloDeploy(value, client, dataSpace, options = {}) {
58
+ const ledger = new WriteLedger();
59
+ const guarded = {
60
+ ...client,
61
+ create: async (body) => ledger.run(async () => client.create(body)),
62
+ update: async (id, body) => ledger.run(async () => client.update(id, body)),
63
+ putMembers: async (space, names) => ledger.run(async () => client.putMembers(space, names)),
64
+ removeMember: async (space, name) => ledger.run(async () => client.removeMember(space, name)),
65
+ };
66
+ try {
67
+ const result = await deployNativeDlo(value, guarded, dataSpace, options);
68
+ if (result.operation === 'unchanged')
69
+ return {
70
+ family: 'dlo',
71
+ outcome: 'unchanged',
72
+ mutation: 'not-attempted',
73
+ dataSpaces: result.document.c__dataSpace,
74
+ diagnostics: [],
75
+ };
76
+ return {
77
+ family: 'dlo',
78
+ outcome: result.operation === 'create' ? 'created' : 'updated',
79
+ mutation: result.operation === 'create' ? 'confirmed-created' : 'confirmed-updated',
80
+ ...(result.serverProcessing ? { serverProcessing: true } : {}),
81
+ dataSpaces: result.document.c__dataSpace,
82
+ ...(result.dataSpaceChanges ? { dataSpaceChanges: result.dataSpaceChanges } : {}),
83
+ diagnostics: [],
84
+ };
85
+ }
86
+ catch (error) {
87
+ const failure = ledger.failure(error);
88
+ return {
89
+ family: 'dlo',
90
+ ...failure,
91
+ diagnostics: [
92
+ {
93
+ code: error instanceof DloError ? error.code : 'DLO_REQUEST_UNCONFIRMED',
94
+ message: operationDiagnostic(error, failure.mutation === 'rejected'
95
+ ? rejectedNextAction
96
+ : failure.mutation === 'unknown'
97
+ ? 'Write outcome is unknown; inspect target before another attempt.'
98
+ : 'Target lookup or definition admission failed; no write attempted.'),
99
+ },
100
+ ],
101
+ };
102
+ }
103
+ }
@@ -0,0 +1,54 @@
1
+ import { settleNativeDataGraph } from './native-data-graph-crd.js';
2
+ import type { NativeGraphContext, NativeGraphCreateCheck } from './native-data-graph-crd.js';
3
+ import type { DataGraphClient } from '../transport/data-graph-rest.js';
4
+ /**
5
+ * Project independently read native runtime configuration into a distinct authored artifact.
6
+ * Retrieve takes the graph in any status and keeps settings the plugin does not model (deploy
7
+ * of such a file refuses and names the key); the root DMO is not read. The graph is read twice
8
+ * and both reads must agree. A shape the file cannot hold (an unknown schedule form, a jsonPath
9
+ * other than `$` or `parent.name`) throws, so the retrieve catch-all keeps the GET verbatim.
10
+ * @param {string} name Exact selected graph.
11
+ * @param {NativeGraphContext} context Scoped independent readers.
12
+ * @returns {Promise<import('../artifacts/native-data-graph-document.js').NativeDataGraphDocument>} Portable intent without generated identities.
13
+ */
14
+ export declare function retrieveNativeDataGraph(name: string, context: NativeGraphContext): Promise<import('../artifacts/native-data-graph-document.js').NativeDataGraphDocument>;
15
+ export declare const nativeGraphLimitations = "Native dependency and related-segment arrays block delete only: delete is refused while any node or field reports one, while deploy and retrieve proceed regardless. Exhaustive external-consumer exclusion is unverified. Definition absence does not establish generated DMO, mapping or transform cleanup, computation success, storage reclamation or credit savings.";
16
+ export type NativeGraphOperationResult = {
17
+ outcome: 'create' | 'update' | 'delete' | 'created' | 'updated' | 'deleted' | 'unchanged' | 'blocked' | 'failed';
18
+ mutation: 'not-attempted' | 'confirmed-created' | 'confirmed-updated' | 'confirmed-deleted' | 'rejected' | 'unknown';
19
+ /** After an attempted create: the step that could not confirm it. */
20
+ failedCheck?: NativeGraphCreateCheck;
21
+ /** Root/owner findings of a preview, or why a deploy was blocked before any write. */
22
+ diagnostics?: Array<{
23
+ code: string;
24
+ message: string;
25
+ }>;
26
+ /** A block found after the graph was read: whether it exists in the target. */
27
+ target?: 'present';
28
+ };
29
+ /**
30
+ * Bind one invocation to fresh target identity and root; never import creation ownership.
31
+ * @param {unknown} value Exact local native intent.
32
+ * @param {NativeGraphContext} context Independently org-bound readers.
33
+ * @param {DataGraphClient} client Single-attempt writer.
34
+ * @param {object} options Explicit operation intent and immutable source verifier.
35
+ * @param {'deploy' | 'delete'} options.operation Requested product operation.
36
+ * @param {boolean} options.preview Zero-write comparison.
37
+ * @param {boolean} options.confirmed Explicit processing/deletion acknowledgement.
38
+ * @param {Function} options.verifyInput Re-admit exact local bytes and flags.
39
+ * @param {Function} [options.pause] Read-only polling seam.
40
+ * @param {Function} [options.now] Injectable monotonic clock.
41
+ * @param {number} [options.waitTimeoutSeconds] Deploy invocation budget in seconds.
42
+ * @param {Function} [options.progress] Stderr-only progress sink.
43
+ * @returns {Promise<NativeGraphOperationResult>} Truthful mutation evidence.
44
+ */
45
+ export declare function operateNativeDataGraph(value: unknown, context: NativeGraphContext, client: DataGraphClient, options: {
46
+ operation: 'deploy' | 'delete';
47
+ preview: boolean;
48
+ confirmed: boolean;
49
+ verifyInput: () => Promise<void>;
50
+ pause?: Parameters<typeof settleNativeDataGraph>[3];
51
+ now?: () => number;
52
+ waitTimeoutSeconds?: number;
53
+ progress?: (message: string) => void;
54
+ }): Promise<NativeGraphOperationResult>;