sf-plugin-data 0.1.0 → 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 (269) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +572 -240
  3. package/docs/artifact-format.md +527 -633
  4. package/docs/capabilities.md +1159 -168
  5. package/docs/git-workflow.md +135 -12
  6. package/docs/handover.md +7826 -12
  7. package/lib/api.d.ts +7 -0
  8. package/lib/api.js +7 -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 +2297 -0
  75. package/lib/commands/data360/deploy.d.ts +234 -15
  76. package/lib/commands/data360/deploy.js +2292 -100
  77. package/lib/commands/data360/publish.d.ts +93 -0
  78. package/lib/commands/data360/publish.js +292 -0
  79. package/lib/commands/data360/retrieve.d.ts +260 -13
  80. package/lib/commands/data360/retrieve.js +1880 -85
  81. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  82. package/lib/commands/data360/segment/members/export.js +318 -0
  83. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  84. package/lib/errors/codes/calculated-insight.js +25 -0
  85. package/lib/errors/codes/data-graph.d.ts +2 -0
  86. package/lib/errors/codes/data-graph.js +22 -0
  87. package/lib/errors/codes/data-stream.d.ts +2 -0
  88. package/lib/errors/codes/data-stream.js +70 -0
  89. package/lib/errors/codes/data-transform.d.ts +2 -0
  90. package/lib/errors/codes/data-transform.js +35 -0
  91. package/lib/errors/codes/dependency.d.ts +2 -0
  92. package/lib/errors/codes/dependency.js +11 -0
  93. package/lib/errors/codes/dlo.d.ts +2 -0
  94. package/lib/errors/codes/dlo.js +31 -0
  95. package/lib/errors/codes/dmo.d.ts +2 -0
  96. package/lib/errors/codes/dmo.js +28 -0
  97. package/lib/errors/codes/general.d.ts +2 -0
  98. package/lib/errors/codes/general.js +57 -0
  99. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  100. package/lib/errors/codes/identity-resolution.js +24 -0
  101. package/lib/errors/codes/mapping.d.ts +2 -0
  102. package/lib/errors/codes/mapping.js +42 -0
  103. package/lib/errors/codes/relationship.d.ts +2 -0
  104. package/lib/errors/codes/relationship.js +21 -0
  105. package/lib/errors/codes/segment.d.ts +2 -0
  106. package/lib/errors/codes/segment.js +49 -0
  107. package/lib/errors/registry.d.ts +60 -0
  108. package/lib/errors/registry.js +123 -0
  109. package/lib/plugin.d.ts +1 -0
  110. package/lib/plugin.js +3 -1
  111. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  112. package/lib/services/acquire-retrieve-selection.js +145 -0
  113. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  114. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  115. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  116. package/lib/services/bind-segment-dependencies.js +115 -0
  117. package/lib/services/bounded-reads.d.ts +17 -0
  118. package/lib/services/bounded-reads.js +42 -0
  119. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  120. package/lib/services/calculated-insight-sql-checks.js +193 -0
  121. package/lib/services/command-dlo.d.ts +48 -0
  122. package/lib/services/command-dlo.js +103 -0
  123. package/lib/services/command-native-data-graph.d.ts +54 -0
  124. package/lib/services/command-native-data-graph.js +485 -0
  125. package/lib/services/command-native-data-stream.d.ts +104 -0
  126. package/lib/services/command-native-data-stream.js +257 -0
  127. package/lib/services/command-native-dmo.d.ts +124 -0
  128. package/lib/services/command-native-dmo.js +338 -0
  129. package/lib/services/command-native-mapping.d.ts +65 -0
  130. package/lib/services/command-native-mapping.js +129 -0
  131. package/lib/services/command-native-relationship.d.ts +46 -0
  132. package/lib/services/command-native-relationship.js +103 -0
  133. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  134. package/lib/services/cross-dataspace-deploy.js +493 -0
  135. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  136. package/lib/services/cross-dataspace-rename.js +1314 -0
  137. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  138. package/lib/services/cross-dataspace-sql.js +1301 -0
  139. package/lib/services/cross-space-context.d.ts +23 -0
  140. package/lib/services/cross-space-context.js +36 -0
  141. package/lib/services/crud-plan.d.ts +137 -0
  142. package/lib/services/crud-plan.js +408 -0
  143. package/lib/services/data-space-check.d.ts +89 -0
  144. package/lib/services/data-space-check.js +162 -0
  145. package/lib/services/data-space-prefix.d.ts +77 -0
  146. package/lib/services/data-space-prefix.js +127 -0
  147. package/lib/services/data-transform-space.d.ts +31 -0
  148. package/lib/services/data-transform-space.js +79 -0
  149. package/lib/services/delete-calculated-insight.d.ts +44 -0
  150. package/lib/services/delete-calculated-insight.js +101 -0
  151. package/lib/services/delete-data-transform.d.ts +52 -0
  152. package/lib/services/delete-data-transform.js +222 -0
  153. package/lib/services/delete-dmo-field.d.ts +211 -0
  154. package/lib/services/delete-dmo-field.js +472 -0
  155. package/lib/services/delete-identity-resolution.d.ts +43 -0
  156. package/lib/services/delete-identity-resolution.js +295 -0
  157. package/lib/services/delete-segment.d.ts +42 -0
  158. package/lib/services/delete-segment.js +248 -0
  159. package/lib/services/deploy-result.d.ts +54 -0
  160. package/lib/services/deploy-result.js +60 -0
  161. package/lib/services/escaped-copy.d.ts +23 -0
  162. package/lib/services/escaped-copy.js +88 -0
  163. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  164. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  165. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  166. package/lib/services/execute-data-transform-deploy.js +168 -0
  167. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  169. package/lib/services/execute-segment-deploy.d.ts +45 -0
  170. package/lib/services/execute-segment-deploy.js +393 -0
  171. package/lib/services/local-file-removal.d.ts +36 -0
  172. package/lib/services/local-file-removal.js +103 -0
  173. package/lib/services/native-calculated-insight.d.ts +87 -0
  174. package/lib/services/native-calculated-insight.js +164 -0
  175. package/lib/services/native-crm-data-stream.d.ts +91 -0
  176. package/lib/services/native-crm-data-stream.js +272 -0
  177. package/lib/services/native-data-graph-context.d.ts +12 -0
  178. package/lib/services/native-data-graph-context.js +139 -0
  179. package/lib/services/native-data-graph-crd.d.ts +261 -0
  180. package/lib/services/native-data-graph-crd.js +866 -0
  181. package/lib/services/native-data-stream.d.ts +329 -0
  182. package/lib/services/native-data-stream.js +1830 -0
  183. package/lib/services/native-dlo.d.ts +163 -0
  184. package/lib/services/native-dlo.js +402 -0
  185. package/lib/services/native-dmo.d.ts +191 -0
  186. package/lib/services/native-dmo.js +614 -0
  187. package/lib/services/native-mapping.d.ts +255 -0
  188. package/lib/services/native-mapping.js +1226 -0
  189. package/lib/services/native-relationship.d.ts +132 -0
  190. package/lib/services/native-relationship.js +512 -0
  191. package/lib/services/operation-diagnostic.d.ts +83 -0
  192. package/lib/services/operation-diagnostic.js +272 -0
  193. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  194. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  195. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  196. package/lib/services/preflight-data-transform-deploy.js +104 -0
  197. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  198. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  199. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  200. package/lib/services/preflight-segment-deploy.js +109 -0
  201. package/lib/services/publish-calculated-insight.d.ts +40 -0
  202. package/lib/services/publish-calculated-insight.js +95 -0
  203. package/lib/services/publish-segment.d.ts +65 -0
  204. package/lib/services/publish-segment.js +194 -0
  205. package/lib/services/readback-pace.d.ts +16 -0
  206. package/lib/services/readback-pace.js +23 -0
  207. package/lib/services/retrieve-data-transform.d.ts +26 -0
  208. package/lib/services/retrieve-data-transform.js +65 -0
  209. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  210. package/lib/services/retrieve-identity-resolution.js +87 -0
  211. package/lib/services/retrieve-inventory.d.ts +32 -0
  212. package/lib/services/retrieve-inventory.js +151 -0
  213. package/lib/services/retrieve-segment.d.ts +120 -0
  214. package/lib/services/retrieve-segment.js +502 -0
  215. package/lib/services/segment-lookup.d.ts +46 -0
  216. package/lib/services/segment-lookup.js +108 -0
  217. package/lib/services/segment-members.d.ts +144 -0
  218. package/lib/services/segment-members.js +402 -0
  219. package/lib/services/select-native-retrieve.d.ts +60 -0
  220. package/lib/services/select-native-retrieve.js +226 -0
  221. package/lib/services/settle-calculated-insight.d.ts +22 -0
  222. package/lib/services/settle-calculated-insight.js +53 -0
  223. package/lib/services/sql-tokens.d.ts +58 -0
  224. package/lib/services/sql-tokens.js +147 -0
  225. package/lib/transport/api-version.d.ts +36 -0
  226. package/lib/transport/api-version.js +89 -0
  227. package/lib/transport/bound-ssot.d.ts +27 -0
  228. package/lib/transport/bound-ssot.js +116 -0
  229. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  230. package/lib/transport/calculated-insight-rest.js +62 -0
  231. package/lib/transport/connect-client.d.ts +94 -32
  232. package/lib/transport/connect-client.js +318 -178
  233. package/lib/transport/connect-diagnostic.d.ts +89 -0
  234. package/lib/transport/connect-diagnostic.js +331 -0
  235. package/lib/transport/data-graph-rest.d.ts +27 -0
  236. package/lib/transport/data-graph-rest.js +76 -0
  237. package/lib/transport/data-stream-rest.d.ts +62 -0
  238. package/lib/transport/data-stream-rest.js +348 -0
  239. package/lib/transport/data-transform-rest.d.ts +25 -0
  240. package/lib/transport/data-transform-rest.js +100 -0
  241. package/lib/transport/dlo-native-rest.d.ts +22 -0
  242. package/lib/transport/dlo-native-rest.js +89 -0
  243. package/lib/transport/dlo-rest.d.ts +23 -0
  244. package/lib/transport/dlo-rest.js +135 -0
  245. package/lib/transport/dmo-native-rest.d.ts +18 -0
  246. package/lib/transport/dmo-native-rest.js +55 -0
  247. package/lib/transport/dmo-rest.d.ts +30 -0
  248. package/lib/transport/dmo-rest.js +163 -0
  249. package/lib/transport/mapping-rest.d.ts +63 -0
  250. package/lib/transport/mapping-rest.js +341 -0
  251. package/lib/transport/project-metadata.d.ts +36 -0
  252. package/lib/transport/project-metadata.js +118 -0
  253. package/lib/transport/relationship-rest.d.ts +43 -0
  254. package/lib/transport/relationship-rest.js +201 -0
  255. package/package.json +29 -6
  256. package/lib/artifacts/dmo-document.d.ts +0 -181
  257. package/lib/artifacts/dmo-document.js +0 -848
  258. package/lib/artifacts/dmo-update-delta.d.ts +0 -28
  259. package/lib/artifacts/dmo-update-delta.js +0 -86
  260. package/lib/artifacts/write-other-dmo.d.ts +0 -17
  261. package/lib/artifacts/write-other-dmo.js +0 -140
  262. package/lib/services/execute-dmo-create.d.ts +0 -24
  263. package/lib/services/execute-dmo-create.js +0 -118
  264. package/lib/services/execute-dmo-deploy.d.ts +0 -33
  265. package/lib/services/execute-dmo-deploy.js +0 -197
  266. package/lib/services/preflight-dmo-deploy.d.ts +0 -69
  267. package/lib/services/preflight-dmo-deploy.js +0 -161
  268. package/lib/services/retrieve-other-dmo.d.ts +0 -46
  269. package/lib/services/retrieve-other-dmo.js +0 -140
@@ -0,0 +1,139 @@
1
+ import { apiDiagnostic, diagnosticRequestId, getConnectDiagnostic, retainConnectDiagnostic, } from '../transport/connect-diagnostic.js';
2
+ import { ConnectError, plainTextRequest } from '../transport/connect-client.js';
3
+ import { dataGraphName, graphRequire } from '../artifacts/data-graph-document.js';
4
+ import { isDataSpaceName } from '../artifacts/data-space-field.js';
5
+ /**
6
+ * Bind concrete read-only native68 routes to an independently verified authenticated org.
7
+ * Raw wire status/body is retained privately because core otherwise discards Graph error envelopes.
8
+ * No caller-supplied URL, SOQL, org identity, auth refresh or pagination replay is accepted.
9
+ * @param {Connection} connection Existing API68 core connection.
10
+ * @param {string} dataSpace The run's data space: the metadata, inventory, root DMO and DataSpace
11
+ * reads name it (graph item reads are by name, unique in the org).
12
+ * @returns {Promise<NativeGraphContext>} Scope-checked concrete readers, never write authority.
13
+ */
14
+ export async function nativeDataGraphReadContext(connection, dataSpace) {
15
+ graphRequire(isDataSpaceName(dataSpace));
16
+ const space = encodeURIComponent(dataSpace);
17
+ // A SOQL string literal: quotes and backslashes escaped.
18
+ const literal = dataSpace.replaceAll(/['\\]/gu, (character) => `\\${character}`);
19
+ const origin = connection.instanceUrl;
20
+ const parsed = new URL(origin);
21
+ graphRequire(parsed.protocol === 'https:' &&
22
+ !parsed.username &&
23
+ !parsed.password &&
24
+ parsed.pathname === '/' &&
25
+ !parsed.search &&
26
+ !parsed.hash);
27
+ const orgId = connection.getAuthInfoFields().orgId;
28
+ graphRequire(typeof orgId === 'string' && /^00D[A-Za-z0-9]{15}$/u.test(orgId));
29
+ const transport = connection._transport;
30
+ graphRequire(typeof transport?.httpRequest === 'function');
31
+ const requestMethod = connection.request;
32
+ const check = () => {
33
+ graphRequire(connection.getApiVersion() === '68.0' &&
34
+ connection.instanceUrl === origin &&
35
+ connection.getAuthInfoFields().orgId === orgId &&
36
+ connection.request === requestMethod &&
37
+ connection._transport === transport);
38
+ };
39
+ check();
40
+ /**
41
+ * Observe exactly one fixed-route core GET without exposing payloads in thrown diagnostics.
42
+ * @param {string} route Internally constructed API68 path.
43
+ * @returns {Promise<NativeGraphRead>} Detached wire evidence, including exact errors.
44
+ */
45
+ const read = async (route) => {
46
+ check();
47
+ let observed;
48
+ let diagnostic;
49
+ let calls = 0;
50
+ const receiver = Object.create(connection);
51
+ Object.defineProperty(receiver, '_refreshDelegate', { value: undefined });
52
+ const observer = {
53
+ httpRequest: (request, options) => {
54
+ check();
55
+ graphRequire(++calls === 1);
56
+ const pending = transport.httpRequest.call(transport, request, options);
57
+ const captured = pending.then((response) => {
58
+ check();
59
+ diagnostic = apiDiagnostic(response.statusCode, response.body, response.headers, diagnosticRequestId(response.headers));
60
+ graphRequire(Number.isInteger(response.statusCode) &&
61
+ response.statusCode >= 200 &&
62
+ response.statusCode <= 599 &&
63
+ typeof response.body === 'string');
64
+ observed = {
65
+ status: response.statusCode,
66
+ body: JSON.parse(response.body),
67
+ };
68
+ return response;
69
+ });
70
+ return Object.assign(captured, { stream: () => pending.stream() });
71
+ },
72
+ };
73
+ try {
74
+ await receiver.request(plainTextRequest({ method: 'GET', url: `${parsed.origin}${route}` }), {
75
+ transport: observer,
76
+ retry: { maxRetries: 0 },
77
+ followRedirect: () => {
78
+ throw new Error('Native Graph redirect refused');
79
+ },
80
+ });
81
+ }
82
+ catch {
83
+ // A parsed HTTP error is evidence, not absence. Network/redirect/parser failures stay unknown.
84
+ if (observed === undefined && diagnostic)
85
+ throw retainConnectDiagnostic(new ConnectError('REQUEST_FAILED', diagnostic.statusCode), diagnostic);
86
+ graphRequire(observed !== undefined && observed.status >= 400);
87
+ }
88
+ check();
89
+ graphRequire(calls === 1 && observed !== undefined);
90
+ return retainConnectDiagnostic(structuredClone(observed), diagnostic);
91
+ };
92
+ const base = '/services/data/v68.0';
93
+ const graphs = `${base}/ssot/data-graphs`;
94
+ const query = (soql) => read(`${base}/query?q=${encodeURIComponent(soql)}`);
95
+ const identity = await query('SELECT Id FROM Organization');
96
+ const body = identity.body;
97
+ try {
98
+ graphRequire(identity.status === 200 &&
99
+ body?.done === true &&
100
+ body.totalSize === 1 &&
101
+ Array.isArray(body.records) &&
102
+ body.records.length === 1 &&
103
+ body.records[0]?.Id === orgId);
104
+ }
105
+ catch (error) {
106
+ if (error instanceof Error)
107
+ retainConnectDiagnostic(error, getConnectDiagnostic(identity));
108
+ throw error;
109
+ }
110
+ /**
111
+ * Admit a developer name before constructing fixed item, metadata or SOQL requests.
112
+ * @param {string} name Exact Graph developer name.
113
+ * @returns {string} Validated name.
114
+ */
115
+ const name = (name) => {
116
+ check();
117
+ graphRequire(typeof name === 'string' && dataGraphName.test(name));
118
+ return name;
119
+ };
120
+ return {
121
+ orgId,
122
+ space: dataSpace,
123
+ check,
124
+ get: (value) => read(`${graphs}/${name(value)}`),
125
+ metadata: (value) => read(`${graphs}/metadata?dataspace=${space}&dataGraphEntityName=${name(value)}`),
126
+ inventory: () => read(`${graphs}/metadata?dataspace=${space}`),
127
+ dataSpace: () => query(`SELECT Id, DataSpaceApiName, Status, IsDeleted FROM DataSpace WHERE DataSpaceApiName = '${literal}' LIMIT 2`),
128
+ query: (value) => query(`SELECT Id, DataGraphApiName, Status, LastRunStatus, Version, DataSpaceId FROM DataGraph WHERE DataGraphApiName = '${name(value)}'`),
129
+ root: async (value) => {
130
+ const rootName = name(value);
131
+ const detail = await read(`${base}/ssot/data-model-objects/${rootName}?dataspace=${space}`);
132
+ if (detail.status !== 200)
133
+ throw retainConnectDiagnostic(new Error('Native Graph root unavailable'), getConnectDiagnostic(detail));
134
+ check();
135
+ return { detail: detail.body };
136
+ },
137
+ identityResolutions: () => read(`${base}/ssot/identity-resolutions`),
138
+ };
139
+ }
@@ -0,0 +1,261 @@
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
+ import type { NativeDataGraphObservation, NativeDataGraphDocument } from '../artifacts/native-data-graph-document.js';
3
+ import type { DataGraphClient } from '../transport/data-graph-rest.js';
4
+ import type { DocumentMode } from '../artifacts/verbatim-document.js';
5
+ export type NativeGraphRead = {
6
+ status: number;
7
+ body: unknown;
8
+ };
9
+ /** Internal trusted readers must bind every response to the supplied exact name and data space. */
10
+ export type NativeGraphContext = {
11
+ check: () => void;
12
+ orgId: string;
13
+ /** The run's data space: every space-scoped read names it, and every answer must name it. */
14
+ space: string;
15
+ get: (name: string) => Promise<NativeGraphRead>;
16
+ metadata: (name: string) => Promise<NativeGraphRead>;
17
+ inventory: () => Promise<NativeGraphRead>;
18
+ query: (name: string) => Promise<NativeGraphRead>;
19
+ /** Read the named primary object's native API 68 DMO detail. */
20
+ root: (name: string) => Promise<{
21
+ detail: unknown;
22
+ }>;
23
+ dataSpace?: () => Promise<NativeGraphRead>;
24
+ /** Read the identity resolution list (deploy preview owner check only). */
25
+ identityResolutions?: () => Promise<NativeGraphRead>;
26
+ };
27
+ export type NativeGraphAcquisition = {
28
+ state: 'present';
29
+ observation: NativeDataGraphObservation;
30
+ } | {
31
+ state: 'absent';
32
+ proof: 'item+metadata+inventory+soql';
33
+ }
34
+ /** Still being built, or (`deleting`) no longer readable but still listed after a delete. */
35
+ | {
36
+ state: 'pending';
37
+ deleting?: true;
38
+ } | {
39
+ state: 'unknown';
40
+ };
41
+ /**
42
+ * Independently bind the graph's enabled primary object in the run's data space. The root is
43
+ * the document's `primaryObjectName` (standard or unified); its fields are not restricted. A root
44
+ * the read names in another data space is DATA_GRAPH_DEPENDENCY_OTHER_DATASPACE.
45
+ * @param {NativeGraphContext} context Scope-checked readers.
46
+ * @param {string} rootName The document's primary object.
47
+ * @returns {Promise<{id: string; creationType: string; fingerprint: string}>} Detached root binding.
48
+ */
49
+ export declare function bindNativeGraphRoot(context: NativeGraphContext, rootName: string): Promise<{
50
+ id: string;
51
+ creationType: string;
52
+ fingerprint: string;
53
+ }>;
54
+ /**
55
+ * Detect a ready item whose server-generated names are not populated yet.
56
+ * @param {unknown} body Untrusted item body.
57
+ * @returns {boolean} True while generation is visibly incomplete.
58
+ */
59
+ export declare function nativeGraphStillGenerating(body: unknown): boolean;
60
+ /**
61
+ * Prove that no graph of this name exists. HTTP400 alone is never absence evidence: only the
62
+ * item route's exact not-found answer, the metadata route's 404 METADATA_ERROR_ENTITY_NOTFOUND,
63
+ * a complete inventory without the name and an empty SOQL read prove it. Metadata still present
64
+ * (or the name still listed or queried) is pending; anything else is unknown.
65
+ * @param {NativeGraphContext} context Independent exact readers, not mutation responses.
66
+ * @param {string} name Exact graph name.
67
+ * @param {NativeGraphRead} [item] The item read already made for this name; read when omitted.
68
+ * @returns {Promise<object>} Absent with its proof, pending, or unknown with any retained diagnostic.
69
+ */
70
+ export declare function proveNativeDataGraphAbsent(context: NativeGraphContext, name: string, item?: NativeGraphRead): Promise<{
71
+ state: 'absent';
72
+ proof: 'item+metadata+inventory+soql';
73
+ } | {
74
+ state: 'pending';
75
+ deleting: true;
76
+ } | {
77
+ state: 'unknown';
78
+ }>;
79
+ /**
80
+ * Acquire exact native state. HTTP400 alone is never absence evidence; stale metadata is pending.
81
+ * @param {NativeGraphContext} context Independent exact readers, not mutation responses.
82
+ * @param {NativeDataGraphDocument} document Native intent.
83
+ * @param {boolean} [baseline] Acquire target independent of desired equality.
84
+ * @param {DocumentMode} [mode] Retrieve mode takes the graph in any status, as read.
85
+ * @returns {Promise<NativeGraphAcquisition>} Correlated state or conservative uncertainty.
86
+ */
87
+ export declare function acquireNativeDataGraph(context: NativeGraphContext, document: NativeDataGraphDocument, baseline?: boolean, mode?: DocumentMode): Promise<NativeGraphAcquisition>;
88
+ /**
89
+ * Settle using bounded GET-only reads; no write is retried on any outcome.
90
+ * @param {NativeGraphContext} context Readers sharing one operation deadline.
91
+ * @param {NativeDataGraphDocument} document Exact native intent.
92
+ * @param {'ready' | 'absent'} goal Required independent state.
93
+ * @param {Function} pause Injectable read-only polling delay.
94
+ * @returns {Promise<NativeGraphAcquisition>} Settled evidence or unknown.
95
+ */
96
+ export declare function settleNativeDataGraph(context: NativeGraphContext, document: NativeDataGraphDocument, goal: 'ready' | 'absent', pause?: typeof delay): Promise<NativeGraphAcquisition>;
97
+ /**
98
+ * Wait for a created graph to finish building, bounded only by the invocation deadline.
99
+ * While the item reads creating, still lacks its generated names, or its metadata still shows
100
+ * it in progress, the graph is being built: keep reading with the documented pacing (20-second
101
+ * waits, never past the deadline) instead of reporting an unknown result early. GET-only; the
102
+ * create is never replayed.
103
+ * @param {NativeGraphContext} context Deadline-guarded readers.
104
+ * @param {NativeDataGraphDocument} document Exact native intent.
105
+ * @param {object} timing Invocation clock, deadline, delay and progress sink.
106
+ * @param {Function} timing.now Invocation clock.
107
+ * @param {number} timing.started Invocation start time.
108
+ * @param {number} timing.end Invocation deadline (--wait-timeout).
109
+ * @param {Function} timing.pause Read-only delay.
110
+ * @param {Function} timing.progress Stderr-only progress sink.
111
+ * @returns {Promise<NativeGraphAcquisition>} Ready evidence or unknown.
112
+ */
113
+ export declare function settleNativeDataGraphCreation(context: NativeGraphContext, document: NativeDataGraphDocument, timing: {
114
+ now: () => number;
115
+ started: number;
116
+ end: number;
117
+ pause: (milliseconds: number) => Promise<unknown>;
118
+ progress: (message: string) => void;
119
+ }): Promise<NativeGraphAcquisition>;
120
+ /**
121
+ * A Graph write Salesforce refused with HTTP429/503 until the wait budget ran out. The request
122
+ * was not processed; the retained diagnostic is the last refusal.
123
+ */
124
+ export declare class NativeGraphWriteRefused extends Error {
125
+ }
126
+ /**
127
+ * Salesforce answered the update PUT with an API 4xx: the PUT was refused and nothing was
128
+ * written (live, API 68: removals, root and related-object swaps are refused with 400).
129
+ */
130
+ export declare class NativeGraphWriteRejected extends Error {
131
+ }
132
+ /** An update that changes the graph was requested without --allow-processing; nothing was sent. */
133
+ export declare class NativeGraphProcessingRequired extends Error {
134
+ }
135
+ /**
136
+ * Send one Graph write; HTTP429/503 means Salesforce did not process it, so pause (Retry-After
137
+ * delta-seconds, else 20 s) and send the identical request again within the invocation deadline.
138
+ * Any other failure is rethrown unchanged.
139
+ * @template T
140
+ * @param {Function} write Sends the identical request.
141
+ * @param {string} operation Name used in progress messages.
142
+ * @param {object} timing Invocation clock, deadline, delay and stderr progress.
143
+ * @param {Function} timing.now Invocation clock.
144
+ * @param {number} timing.end Invocation deadline.
145
+ * @param {Function} timing.pause Delay seam.
146
+ * @param {Function} timing.progress Stderr-only progress sink.
147
+ * @returns {Promise<T>} The accepted write's response.
148
+ * @throws {NativeGraphWriteRefused} When the next wait would reach the deadline.
149
+ */
150
+ export declare function sendNativeGraphWrite<T>(write: () => Promise<T>, operation: string, timing: {
151
+ now: () => number;
152
+ end: number;
153
+ pause: (milliseconds: number) => Promise<unknown>;
154
+ progress: (message: string) => void;
155
+ }): Promise<T>;
156
+ /**
157
+ * Resolve the authoritative record of the run's data space once per invocation.
158
+ * @param {NativeGraphContext} context Bound target readers.
159
+ * @returns {Promise<string>} Exact active default record identity.
160
+ */
161
+ export declare function bindNativeGraphDataSpace(context: NativeGraphContext): Promise<string>;
162
+ /** Independently correlated readiness; metadata version/tree may legitimately lag. */
163
+ export type NativeGraphReadiness = {
164
+ observation: NativeDataGraphObservation;
165
+ ready: boolean;
166
+ status: string;
167
+ };
168
+ /**
169
+ * Read one fresh item/metadata/SOQL tuple without unrelated reads or write replay.
170
+ * @param {NativeGraphContext} context Bound target readers.
171
+ * @param {NativeDataGraphDocument} document Exact API name.
172
+ * @param {string} dataSpaceId Invocation-resolved data space record identity.
173
+ * @returns {Promise<NativeGraphReadiness>} Detached independent tuple.
174
+ */
175
+ export declare function readNativeGraphReadiness(context: NativeGraphContext, document: NativeDataGraphDocument, dataSpaceId: string): Promise<NativeGraphReadiness>;
176
+ /**
177
+ * Apply one authored change to the bound target (see buildNativeDataGraphUpdateRequest), then
178
+ * reconcile solely with paced GETs. An equal definition is unchanged with zero writes.
179
+ * @param {NativeGraphContext} context Invocation/deadline guarded readers.
180
+ * @param {DataGraphClient} client Single-attempt guarded writer.
181
+ * @param {NativeDataGraphDocument} document Authored delta.
182
+ * @param {NativeDataGraphObservation} baseline Initial independently acquired target.
183
+ * @param {object} options Shared invocation controls.
184
+ * @param {boolean} options.preview Zero-write comparison.
185
+ * @param {boolean} options.confirmed Processing acknowledgement.
186
+ * @param {Function} options.verify Revalidate bytes/flags/root before final tuple.
187
+ * @param {Function} options.now Invocation clock.
188
+ * @param {Function} options.pause Injectable read-only delay.
189
+ * @param {Function} options.progress Stderr-only progress sink.
190
+ * @param {number} options.started Invocation start time.
191
+ * @param {number} options.end Invocation deadline.
192
+ * @returns {Promise<'update'|'updated'|'unchanged'>} Independent result, never response echo.
193
+ * @throws {NativeGraphWriteRefused} When HTTP429/503 refused every PUT until the deadline.
194
+ * @throws {NativeGraphWriteRejected} When Salesforce answered the PUT with an API 4xx.
195
+ * @throws {DataGraphError} DATA_GRAPH_JOIN_CHANGE before any write; DATA_GRAPH_CHANGE_NOT_APPLIED
196
+ * when the settled graph kept a join the PUT changed.
197
+ */
198
+ export declare function updateNativeDataGraph(context: NativeGraphContext, client: DataGraphClient, document: NativeDataGraphDocument, baseline: NativeDataGraphObservation, options: {
199
+ preview: boolean;
200
+ confirmed: boolean;
201
+ verify: () => Promise<void>;
202
+ now: () => number;
203
+ pause: (milliseconds: number) => Promise<unknown>;
204
+ progress: (message: string) => void;
205
+ started: number;
206
+ end: number;
207
+ }): Promise<'update' | 'updated' | 'unchanged'>;
208
+ export type NativeGraphReceipt = {
209
+ orgId: string;
210
+ dataSpace: string;
211
+ apiName: string;
212
+ id: string;
213
+ createdDate: string;
214
+ bodySHA256: string;
215
+ rootId: string;
216
+ definitionFingerprint: string;
217
+ };
218
+ export type NativeGraphResult = {
219
+ outcome: 'created' | 'deleted' | 'blocked' | 'unknown';
220
+ mutation: 'not-attempted' | 'attempted';
221
+ receipt?: NativeGraphReceipt;
222
+ /** After an attempted create: the step that could not confirm it. */
223
+ failedCheck?: NativeGraphCreateCheck;
224
+ };
225
+ /** Steps after the create request that must confirm the created graph. */
226
+ export type NativeGraphCreateCheck = 'request' | 'response' | 'settlement' | 'identity' | 'deadline';
227
+ /**
228
+ * Create one run-local CRD owner; receipts cannot be imported to adopt preexisting graphs.
229
+ * Each operation is single-use, mutually exclusive, deadline-bound and journaled before dispatch.
230
+ * The coordinator supplies trusted scoped readers and an exclusive durable ledger guard.
231
+ * @param {unknown} value Distinct native authored document.
232
+ * @param {NativeGraphContext} context Exact API68/data space/org read context.
233
+ * @param {DataGraphClient} client Single-attempt native transport.
234
+ * @param {object} guards Explicit intent, ledger and independent dependency safety.
235
+ * @param {Function} guards.record Persist predispatch intent/receipt; reject duplicate run ownership.
236
+ * @param {Function} guards.safeToDelete Independently verify no external usage; fail closed.
237
+ * @param {Function} [guards.now] Injectable monotonic wall clock.
238
+ * @param {Function} [guards.pause] Injectable polling delay.
239
+ * @param {object} [guards.creation] Invocation budget; create settlement waits while building.
240
+ * @param {number} guards.creation.started Invocation start time.
241
+ * @param {number} guards.creation.end Invocation deadline (--wait-timeout).
242
+ * @param {Function} guards.creation.pause Paced read-only delay.
243
+ * @param {Function} guards.creation.progress Stderr-only progress sink.
244
+ * @returns {{create: Function; delete: Function}} Internal lifecycle, no UPDATE or name-only delete.
245
+ */
246
+ export declare function nativeDataGraphLifecycle(value: unknown, context: NativeGraphContext, client: DataGraphClient, guards: {
247
+ record: (phase: 'create-attempt' | 'created' | 'delete-attempt', evidence: unknown) => Promise<void>;
248
+ safeToDelete: (receipt: NativeGraphReceipt) => Promise<boolean>;
249
+ now?: () => number;
250
+ pause?: typeof delay;
251
+ /** Invocation deadline; with it, create settlement waits while the graph is still building. */
252
+ creation?: {
253
+ started: number;
254
+ end: number;
255
+ pause: (milliseconds: number) => Promise<unknown>;
256
+ progress: (message: string) => void;
257
+ };
258
+ }): {
259
+ create: (confirmed: boolean) => Promise<NativeGraphResult>;
260
+ delete: (confirmed: boolean) => Promise<NativeGraphResult>;
261
+ };