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.
- package/LICENSE +21 -0
- package/README.md +589 -2
- package/bin/run.js +4 -0
- package/docs/artifact-format.md +527 -0
- package/docs/capabilities.md +1208 -0
- package/docs/git-workflow.md +160 -0
- package/docs/handover.md +10446 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +7 -0
- package/lib/artifacts/code-fields.d.ts +49 -0
- package/lib/artifacts/code-fields.js +142 -0
- package/lib/artifacts/data-graph-document.d.ts +29 -0
- package/lib/artifacts/data-graph-document.js +52 -0
- package/lib/artifacts/data-space-field.d.ts +65 -0
- package/lib/artifacts/data-space-field.js +98 -0
- package/lib/artifacts/data-stream-document.d.ts +264 -0
- package/lib/artifacts/data-stream-document.js +680 -0
- package/lib/artifacts/data-transform-document.d.ts +152 -0
- package/lib/artifacts/data-transform-document.js +560 -0
- package/lib/artifacts/dependency-selection.d.ts +51 -0
- package/lib/artifacts/dependency-selection.js +154 -0
- package/lib/artifacts/dlo-document.d.ts +93 -0
- package/lib/artifacts/dlo-document.js +253 -0
- package/lib/artifacts/enum-case.d.ts +39 -0
- package/lib/artifacts/enum-case.js +67 -0
- package/lib/artifacts/git-deploy-selection.d.ts +68 -0
- package/lib/artifacts/git-deploy-selection.js +474 -0
- package/lib/artifacts/identity-resolution-document.d.ts +133 -0
- package/lib/artifacts/identity-resolution-document.js +625 -0
- package/lib/artifacts/mapping-document.d.ts +1 -0
- package/lib/artifacts/mapping-document.js +1 -0
- package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
- package/lib/artifacts/native-calculated-insight-document.js +321 -0
- package/lib/artifacts/native-data-graph-document.d.ts +124 -0
- package/lib/artifacts/native-data-graph-document.js +780 -0
- package/lib/artifacts/native-dmo-document.d.ts +151 -0
- package/lib/artifacts/native-dmo-document.js +313 -0
- package/lib/artifacts/native-mapping-document.d.ts +67 -0
- package/lib/artifacts/native-mapping-document.js +187 -0
- package/lib/artifacts/native-relationship-document.d.ts +76 -0
- package/lib/artifacts/native-relationship-document.js +232 -0
- package/lib/artifacts/path-selector.d.ts +55 -0
- package/lib/artifacts/path-selector.js +167 -0
- package/lib/artifacts/read-deploy-input.d.ts +239 -0
- package/lib/artifacts/read-deploy-input.js +1359 -0
- package/lib/artifacts/segment-document.d.ts +183 -0
- package/lib/artifacts/segment-document.js +570 -0
- package/lib/artifacts/verbatim-document.d.ts +203 -0
- package/lib/artifacts/verbatim-document.js +339 -0
- package/lib/artifacts/write-data-graph.d.ts +17 -0
- package/lib/artifacts/write-data-graph.js +162 -0
- package/lib/artifacts/write-data-stream.d.ts +11 -0
- package/lib/artifacts/write-data-stream.js +175 -0
- package/lib/artifacts/write-data-transform.d.ts +11 -0
- package/lib/artifacts/write-data-transform.js +180 -0
- package/lib/artifacts/write-dlo.d.ts +11 -0
- package/lib/artifacts/write-dlo.js +158 -0
- package/lib/artifacts/write-identity-resolution.d.ts +18 -0
- package/lib/artifacts/write-identity-resolution.js +165 -0
- package/lib/artifacts/write-mapping-definition.d.ts +17 -0
- package/lib/artifacts/write-mapping-definition.js +127 -0
- package/lib/artifacts/write-member-export.d.ts +88 -0
- package/lib/artifacts/write-member-export.js +199 -0
- package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
- package/lib/artifacts/write-native-calculated-insight.js +176 -0
- package/lib/artifacts/write-native-dmo.d.ts +11 -0
- package/lib/artifacts/write-native-dmo.js +158 -0
- package/lib/artifacts/write-native-mapping.d.ts +11 -0
- package/lib/artifacts/write-native-mapping.js +157 -0
- package/lib/artifacts/write-native-relationship.d.ts +11 -0
- package/lib/artifacts/write-native-relationship.js +157 -0
- package/lib/artifacts/write-segment.d.ts +26 -0
- package/lib/artifacts/write-segment.js +212 -0
- package/lib/commands/data360/delete.d.ts +280 -0
- package/lib/commands/data360/delete.js +2297 -0
- package/lib/commands/data360/deploy.d.ts +303 -0
- package/lib/commands/data360/deploy.js +2400 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +322 -0
- package/lib/commands/data360/retrieve.js +1963 -0
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +318 -0
- package/lib/errors/codes/calculated-insight.d.ts +2 -0
- package/lib/errors/codes/calculated-insight.js +25 -0
- package/lib/errors/codes/data-graph.d.ts +2 -0
- package/lib/errors/codes/data-graph.js +22 -0
- package/lib/errors/codes/data-stream.d.ts +2 -0
- package/lib/errors/codes/data-stream.js +70 -0
- package/lib/errors/codes/data-transform.d.ts +2 -0
- package/lib/errors/codes/data-transform.js +35 -0
- package/lib/errors/codes/dependency.d.ts +2 -0
- package/lib/errors/codes/dependency.js +11 -0
- package/lib/errors/codes/dlo.d.ts +2 -0
- package/lib/errors/codes/dlo.js +31 -0
- package/lib/errors/codes/dmo.d.ts +2 -0
- package/lib/errors/codes/dmo.js +28 -0
- package/lib/errors/codes/general.d.ts +2 -0
- package/lib/errors/codes/general.js +57 -0
- package/lib/errors/codes/identity-resolution.d.ts +2 -0
- package/lib/errors/codes/identity-resolution.js +24 -0
- package/lib/errors/codes/mapping.d.ts +2 -0
- package/lib/errors/codes/mapping.js +42 -0
- package/lib/errors/codes/relationship.d.ts +2 -0
- package/lib/errors/codes/relationship.js +21 -0
- package/lib/errors/codes/segment.d.ts +2 -0
- package/lib/errors/codes/segment.js +49 -0
- package/lib/errors/registry.d.ts +60 -0
- package/lib/errors/registry.js +123 -0
- package/lib/plugin.d.ts +5 -0
- package/lib/plugin.js +5 -0
- package/lib/services/acquire-retrieve-selection.d.ts +43 -0
- package/lib/services/acquire-retrieve-selection.js +145 -0
- package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
- package/lib/services/bind-identity-resolution-dependencies.js +238 -0
- package/lib/services/bind-segment-dependencies.d.ts +49 -0
- package/lib/services/bind-segment-dependencies.js +115 -0
- package/lib/services/bounded-reads.d.ts +17 -0
- package/lib/services/bounded-reads.js +42 -0
- package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
- package/lib/services/calculated-insight-sql-checks.js +193 -0
- package/lib/services/command-dlo.d.ts +48 -0
- package/lib/services/command-dlo.js +103 -0
- package/lib/services/command-native-data-graph.d.ts +54 -0
- package/lib/services/command-native-data-graph.js +485 -0
- package/lib/services/command-native-data-stream.d.ts +104 -0
- package/lib/services/command-native-data-stream.js +257 -0
- package/lib/services/command-native-dmo.d.ts +124 -0
- package/lib/services/command-native-dmo.js +338 -0
- package/lib/services/command-native-mapping.d.ts +65 -0
- package/lib/services/command-native-mapping.js +129 -0
- package/lib/services/command-native-relationship.d.ts +46 -0
- package/lib/services/command-native-relationship.js +103 -0
- package/lib/services/cross-dataspace-deploy.d.ts +111 -0
- package/lib/services/cross-dataspace-deploy.js +493 -0
- package/lib/services/cross-dataspace-rename.d.ts +74 -0
- package/lib/services/cross-dataspace-rename.js +1314 -0
- package/lib/services/cross-dataspace-sql.d.ts +109 -0
- package/lib/services/cross-dataspace-sql.js +1301 -0
- package/lib/services/cross-space-context.d.ts +23 -0
- package/lib/services/cross-space-context.js +36 -0
- package/lib/services/crud-plan.d.ts +137 -0
- package/lib/services/crud-plan.js +408 -0
- package/lib/services/data-space-check.d.ts +89 -0
- package/lib/services/data-space-check.js +162 -0
- package/lib/services/data-space-prefix.d.ts +77 -0
- package/lib/services/data-space-prefix.js +127 -0
- package/lib/services/data-transform-space.d.ts +31 -0
- package/lib/services/data-transform-space.js +79 -0
- package/lib/services/delete-calculated-insight.d.ts +44 -0
- package/lib/services/delete-calculated-insight.js +101 -0
- package/lib/services/delete-data-transform.d.ts +52 -0
- package/lib/services/delete-data-transform.js +222 -0
- package/lib/services/delete-dmo-field.d.ts +211 -0
- package/lib/services/delete-dmo-field.js +472 -0
- package/lib/services/delete-identity-resolution.d.ts +43 -0
- package/lib/services/delete-identity-resolution.js +295 -0
- package/lib/services/delete-segment.d.ts +42 -0
- package/lib/services/delete-segment.js +248 -0
- package/lib/services/deploy-result.d.ts +54 -0
- package/lib/services/deploy-result.js +60 -0
- package/lib/services/escaped-copy.d.ts +23 -0
- package/lib/services/escaped-copy.js +88 -0
- package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
- package/lib/services/execute-calculated-insight-deploy.js +96 -0
- package/lib/services/execute-data-transform-deploy.d.ts +56 -0
- package/lib/services/execute-data-transform-deploy.js +168 -0
- package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
- package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
- package/lib/services/execute-segment-deploy.d.ts +45 -0
- package/lib/services/execute-segment-deploy.js +393 -0
- package/lib/services/local-file-removal.d.ts +36 -0
- package/lib/services/local-file-removal.js +103 -0
- package/lib/services/native-calculated-insight.d.ts +87 -0
- package/lib/services/native-calculated-insight.js +164 -0
- package/lib/services/native-crm-data-stream.d.ts +91 -0
- package/lib/services/native-crm-data-stream.js +272 -0
- package/lib/services/native-data-graph-context.d.ts +12 -0
- package/lib/services/native-data-graph-context.js +139 -0
- package/lib/services/native-data-graph-crd.d.ts +261 -0
- package/lib/services/native-data-graph-crd.js +866 -0
- package/lib/services/native-data-stream.d.ts +329 -0
- package/lib/services/native-data-stream.js +1830 -0
- package/lib/services/native-dlo.d.ts +163 -0
- package/lib/services/native-dlo.js +402 -0
- package/lib/services/native-dmo.d.ts +191 -0
- package/lib/services/native-dmo.js +614 -0
- package/lib/services/native-mapping.d.ts +255 -0
- package/lib/services/native-mapping.js +1226 -0
- package/lib/services/native-relationship.d.ts +132 -0
- package/lib/services/native-relationship.js +512 -0
- package/lib/services/operation-diagnostic.d.ts +83 -0
- package/lib/services/operation-diagnostic.js +272 -0
- package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
- package/lib/services/preflight-calculated-insight-deploy.js +95 -0
- package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
- package/lib/services/preflight-data-transform-deploy.js +104 -0
- package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
- package/lib/services/preflight-identity-resolution-deploy.js +281 -0
- package/lib/services/preflight-segment-deploy.d.ts +31 -0
- package/lib/services/preflight-segment-deploy.js +109 -0
- package/lib/services/publish-calculated-insight.d.ts +40 -0
- package/lib/services/publish-calculated-insight.js +95 -0
- package/lib/services/publish-segment.d.ts +65 -0
- package/lib/services/publish-segment.js +194 -0
- package/lib/services/readback-pace.d.ts +16 -0
- package/lib/services/readback-pace.js +23 -0
- package/lib/services/retrieve-data-transform.d.ts +26 -0
- package/lib/services/retrieve-data-transform.js +65 -0
- package/lib/services/retrieve-identity-resolution.d.ts +40 -0
- package/lib/services/retrieve-identity-resolution.js +87 -0
- package/lib/services/retrieve-inventory.d.ts +32 -0
- package/lib/services/retrieve-inventory.js +151 -0
- package/lib/services/retrieve-segment.d.ts +120 -0
- package/lib/services/retrieve-segment.js +502 -0
- package/lib/services/segment-lookup.d.ts +46 -0
- package/lib/services/segment-lookup.js +108 -0
- package/lib/services/segment-members.d.ts +144 -0
- package/lib/services/segment-members.js +402 -0
- package/lib/services/select-native-retrieve.d.ts +60 -0
- package/lib/services/select-native-retrieve.js +226 -0
- package/lib/services/settle-calculated-insight.d.ts +22 -0
- package/lib/services/settle-calculated-insight.js +53 -0
- package/lib/services/sql-tokens.d.ts +58 -0
- package/lib/services/sql-tokens.js +147 -0
- package/lib/transport/api-version.d.ts +36 -0
- package/lib/transport/api-version.js +89 -0
- package/lib/transport/bound-ssot.d.ts +27 -0
- package/lib/transport/bound-ssot.js +116 -0
- package/lib/transport/calculated-insight-rest.d.ts +28 -0
- package/lib/transport/calculated-insight-rest.js +62 -0
- package/lib/transport/connect-client.d.ts +129 -0
- package/lib/transport/connect-client.js +446 -0
- package/lib/transport/connect-diagnostic.d.ts +89 -0
- package/lib/transport/connect-diagnostic.js +331 -0
- package/lib/transport/data-graph-rest.d.ts +27 -0
- package/lib/transport/data-graph-rest.js +76 -0
- package/lib/transport/data-stream-rest.d.ts +62 -0
- package/lib/transport/data-stream-rest.js +348 -0
- package/lib/transport/data-transform-rest.d.ts +25 -0
- package/lib/transport/data-transform-rest.js +100 -0
- package/lib/transport/dlo-native-rest.d.ts +22 -0
- package/lib/transport/dlo-native-rest.js +89 -0
- package/lib/transport/dlo-rest.d.ts +23 -0
- package/lib/transport/dlo-rest.js +135 -0
- package/lib/transport/dmo-native-rest.d.ts +18 -0
- package/lib/transport/dmo-native-rest.js +55 -0
- package/lib/transport/dmo-rest.d.ts +30 -0
- package/lib/transport/dmo-rest.js +163 -0
- package/lib/transport/mapping-rest.d.ts +63 -0
- package/lib/transport/mapping-rest.js +341 -0
- package/lib/transport/project-metadata.d.ts +36 -0
- package/lib/transport/project-metadata.js +118 -0
- package/lib/transport/relationship-rest.d.ts +43 -0
- package/lib/transport/relationship-rest.js +201 -0
- package/package.json +96 -4
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { crossSpaceSentence, explainInput, printableKey, } from '../services/operation-diagnostic.js';
|
|
4
|
+
import { dataSpaceKey, isDataSpaceName, readSingleDataSpace } from './data-space-field.js';
|
|
5
|
+
import { DataGraphError, dataGraphName, graphCanonicalObject, graphRecord, graphRequire, graphText, } from './data-graph-document.js';
|
|
6
|
+
/**
|
|
7
|
+
* Settings a Real-Time Data Graph carries (UI page "Real-Time Consumption Limits"; read on a
|
|
8
|
+
* UI-created real-time graph at API68, 2026-11-15). Authored configuration, sent as written.
|
|
9
|
+
*/
|
|
10
|
+
const realTimeKeys = [
|
|
11
|
+
'isRealTimeToggleEnabled',
|
|
12
|
+
'isRecordCachingDisabled',
|
|
13
|
+
'processIngestionApi',
|
|
14
|
+
'processSalesforceCrm',
|
|
15
|
+
'sessionEnd',
|
|
16
|
+
'sessionEndTimeUnit',
|
|
17
|
+
'cacheDurationInDays',
|
|
18
|
+
'maxRecordsCached',
|
|
19
|
+
];
|
|
20
|
+
const topKeys = [
|
|
21
|
+
'name',
|
|
22
|
+
'label',
|
|
23
|
+
'description',
|
|
24
|
+
'dataspaceName',
|
|
25
|
+
'primaryObjectName',
|
|
26
|
+
'type',
|
|
27
|
+
'sourceObject',
|
|
28
|
+
'idDmoName',
|
|
29
|
+
'valuesDmoName',
|
|
30
|
+
'dayZeroMappingDevName',
|
|
31
|
+
'dayZeroTransformDevName',
|
|
32
|
+
'incrementalMappingDevName',
|
|
33
|
+
'incrementalTransformDevName',
|
|
34
|
+
'fullRefreshConfig',
|
|
35
|
+
'incrementalRefreshConfig',
|
|
36
|
+
...realTimeKeys,
|
|
37
|
+
];
|
|
38
|
+
const nodeKeys = [
|
|
39
|
+
'name',
|
|
40
|
+
'devName',
|
|
41
|
+
'label',
|
|
42
|
+
'jsonPath',
|
|
43
|
+
'path',
|
|
44
|
+
'type',
|
|
45
|
+
'fragmentDMOName',
|
|
46
|
+
'referenceDeveloperName',
|
|
47
|
+
'projectedName',
|
|
48
|
+
'recencyCriteria',
|
|
49
|
+
'filterCriteria',
|
|
50
|
+
'topKFilterCriteria',
|
|
51
|
+
'fields',
|
|
52
|
+
'relatedObjects',
|
|
53
|
+
];
|
|
54
|
+
const fieldKeys = [
|
|
55
|
+
'devName',
|
|
56
|
+
'sourceFieldName',
|
|
57
|
+
'dataType',
|
|
58
|
+
'isKeyColumn',
|
|
59
|
+
'isProjected',
|
|
60
|
+
'usageTag',
|
|
61
|
+
'keyQualifierName',
|
|
62
|
+
'isDGRootKeyField',
|
|
63
|
+
'fieldRoles',
|
|
64
|
+
];
|
|
65
|
+
const pathKeys = ['devName', 'fieldName', 'parentFieldName'];
|
|
66
|
+
// Keys a GET carries that are server facts, never authored configuration; retrieve leaves them out.
|
|
67
|
+
const serverTopKeys = [
|
|
68
|
+
'id',
|
|
69
|
+
'createdDate',
|
|
70
|
+
'createdBy',
|
|
71
|
+
'modifiedDate',
|
|
72
|
+
'lastRefreshedDate',
|
|
73
|
+
'kind',
|
|
74
|
+
'status',
|
|
75
|
+
'lastRunStatus',
|
|
76
|
+
'version',
|
|
77
|
+
'extendedProperties',
|
|
78
|
+
'idDmoLabel',
|
|
79
|
+
'valuesDmoLabel',
|
|
80
|
+
'primaryObjectLabel',
|
|
81
|
+
];
|
|
82
|
+
// Request spellings of the schedule granularity (Data 360 input schema, API68); GET reads them
|
|
83
|
+
// in lowercase (`day`, `hour`).
|
|
84
|
+
const timeGranularities = ['Minute', 'Hour', 'Day', 'Month', 'Year', 'Streaming', 'OnDemand'];
|
|
85
|
+
const serverNodeKeys = [
|
|
86
|
+
'id',
|
|
87
|
+
'categoryDevName',
|
|
88
|
+
'dependency',
|
|
89
|
+
'relatedSegments',
|
|
90
|
+
'fragmentDMOLabel',
|
|
91
|
+
];
|
|
92
|
+
const serverFieldKeys = ['id', 'name', 'dependency', 'sourceFieldLabel'];
|
|
93
|
+
const serverPathKeys = ['fieldLabel', 'parentFieldLabel'];
|
|
94
|
+
const generatedKeys = topKeys.slice(7, 13);
|
|
95
|
+
/**
|
|
96
|
+
* Refuse a data graph setting the plugin cannot send, naming its key path.
|
|
97
|
+
* @param {string} keyPath Printable key path.
|
|
98
|
+
* @param {string} problem What is wrong with it.
|
|
99
|
+
* @returns {DataGraphError} Refusal with an explanation.
|
|
100
|
+
*/
|
|
101
|
+
function refuse(keyPath, problem) {
|
|
102
|
+
return explainInput(new DataGraphError(), `The data graph cannot be deployed: ${keyPath} ${problem}. Correct the file, or retrieve the graph again once the plugin supports it.`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Require a deploy invariant, naming the key path when it does not hold.
|
|
106
|
+
* @param {unknown} condition Invariant.
|
|
107
|
+
* @param {string} keyPath Printable key path.
|
|
108
|
+
* @param {string} problem What is wrong otherwise.
|
|
109
|
+
*/
|
|
110
|
+
function need(condition, keyPath, problem) {
|
|
111
|
+
if (!condition)
|
|
112
|
+
throw refuse(keyPath, problem);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Reject executable, cyclic, sparse or accessor-bearing inputs before any reads.
|
|
116
|
+
* @param {unknown} value Candidate JSON.
|
|
117
|
+
* @param {Set<object>} ancestors Active ancestors.
|
|
118
|
+
* @param {number} depth Nesting limit (retrieve mode passes none).
|
|
119
|
+
*/
|
|
120
|
+
function inert(value, ancestors = new Set(), depth = 24) {
|
|
121
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string')
|
|
122
|
+
return;
|
|
123
|
+
if (typeof value === 'number') {
|
|
124
|
+
graphRequire(Number.isFinite(value));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
graphRequire(value && typeof value === 'object' && !ancestors.has(value) && ancestors.size < depth);
|
|
128
|
+
graphRequire(Object.getPrototypeOf(value) === (Array.isArray(value) ? Array.prototype : Object.prototype));
|
|
129
|
+
ancestors.add(value);
|
|
130
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
131
|
+
if (Array.isArray(value) && key === 'length')
|
|
132
|
+
continue;
|
|
133
|
+
const d = Object.getOwnPropertyDescriptor(value, key);
|
|
134
|
+
graphRequire(typeof key === 'string' && key !== 'toJSON' && d?.enumerable && 'value' in d);
|
|
135
|
+
inert(d.value, ancestors, depth);
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value))
|
|
138
|
+
graphRequire(Object.keys(value).length === value.length);
|
|
139
|
+
ancestors.delete(value);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check a closed property inventory without discarding unsupported configuration. Retrieve mode
|
|
143
|
+
* keeps unknown keys; deploy refuses them, naming the first one.
|
|
144
|
+
* @param {unknown} value Record.
|
|
145
|
+
* @param {string[]} keys Allowed keys.
|
|
146
|
+
* @param {DocumentMode} mode Strictness.
|
|
147
|
+
* @param {string} keyPath Printable key path of the record.
|
|
148
|
+
* @returns {Record<string, unknown>} Checked record.
|
|
149
|
+
*/
|
|
150
|
+
function closed(value, keys, mode = 'deploy', keyPath = 'definition') {
|
|
151
|
+
const result = graphRecord(value);
|
|
152
|
+
if (mode === 'deploy')
|
|
153
|
+
for (const key of Object.keys(result))
|
|
154
|
+
need(keys.includes(key), `${keyPath}.${printableKey(key)}`, 'is not a setting the plugin can send');
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Require an array.
|
|
159
|
+
* @param {unknown} value Candidate array.
|
|
160
|
+
* @returns {unknown[]} Checked array.
|
|
161
|
+
*/
|
|
162
|
+
function array(value) {
|
|
163
|
+
graphRequire(Array.isArray(value));
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Keep a GET record as authored configuration: the known keys in their order, then every other
|
|
168
|
+
* key in the order read, without the server facts.
|
|
169
|
+
* @param {Record<string, unknown>} value GET record.
|
|
170
|
+
* @param {string[]} keys Known request keys.
|
|
171
|
+
* @param {string[]} server Server-only keys left out.
|
|
172
|
+
* @returns {Record<string, unknown>} Detached kept properties.
|
|
173
|
+
*/
|
|
174
|
+
function keep(value, keys, server) {
|
|
175
|
+
const result = pick(value, keys);
|
|
176
|
+
for (const key of Object.keys(value))
|
|
177
|
+
if (!keys.includes(key) && !server.includes(key))
|
|
178
|
+
result[key] = structuredClone(value[key]);
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Select known request properties after closed observation admission.
|
|
183
|
+
* @param {Record<string, unknown>} value Record.
|
|
184
|
+
* @param {string[]} keys Request inventory.
|
|
185
|
+
* @returns {Record<string, unknown>} Detached selected properties.
|
|
186
|
+
*/
|
|
187
|
+
function pick(value, keys) {
|
|
188
|
+
return Object.fromEntries(keys
|
|
189
|
+
.filter((key) => Object.hasOwn(value, key))
|
|
190
|
+
.map((key) => [key, structuredClone(value[key])]));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Upper-case text; any other value as is.
|
|
194
|
+
* @param {unknown} value Candidate.
|
|
195
|
+
* @returns {unknown} Upper-cased text or the value.
|
|
196
|
+
*/
|
|
197
|
+
function upper(value) {
|
|
198
|
+
return typeof value === 'string' ? value.toUpperCase() : value;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether a value stands for an unset generated name or extended properties.
|
|
202
|
+
* @param {unknown} value Candidate.
|
|
203
|
+
* @returns {boolean} Empty text or null.
|
|
204
|
+
*/
|
|
205
|
+
function unset(value) {
|
|
206
|
+
return value === '' || value === null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Write the API's lowercase enum spellings in their request form so a retrieved file and a
|
|
210
|
+
* fresh GET compare equal, whichever case the author used (GET reads `none`, `key_qualifier`,
|
|
211
|
+
* `desc`, `day`; requests send `NONE`, `KEY_QUALIFIER`, `DESC`, `Day`).
|
|
212
|
+
* @param {Record<string, unknown>} node Admitted node, changed in place.
|
|
213
|
+
*/
|
|
214
|
+
function normaliseNode(node) {
|
|
215
|
+
// Retrieve mode admits other values (null, absent); they are kept as read.
|
|
216
|
+
for (const field of node.fields)
|
|
217
|
+
if (Object.hasOwn(field, 'usageTag'))
|
|
218
|
+
field.usageTag = upper(field.usageTag);
|
|
219
|
+
const top = node.topKFilterCriteria;
|
|
220
|
+
if (top && Array.isArray(top.orderCriteria))
|
|
221
|
+
for (const order of top.orderCriteria)
|
|
222
|
+
if (Object.hasOwn(order, 'sortOrder'))
|
|
223
|
+
order.sortOrder = upper(order.sortOrder);
|
|
224
|
+
for (const child of node.relatedObjects)
|
|
225
|
+
normaliseNode(child);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Whether a value is nonblank text.
|
|
229
|
+
* @param {unknown} value Candidate.
|
|
230
|
+
* @returns {boolean} Nonblank string.
|
|
231
|
+
*/
|
|
232
|
+
function isText(value) {
|
|
233
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Admit the structure of a node tree: shapes, names, unique paths and parent-linked joins.
|
|
237
|
+
* Object names, node types, field data types, usage tags, key columns and criteria are not
|
|
238
|
+
* restricted locally; the API decides. Retrieve mode checks only what holds the tree together
|
|
239
|
+
* (node name and path, field source names, the array shapes) and keeps every other value as read.
|
|
240
|
+
* @param {unknown} value Node input.
|
|
241
|
+
* @param {DocumentMode} mode Strictness.
|
|
242
|
+
* @param {string} keyPath Printable key path of the node.
|
|
243
|
+
* @param {Record<string, unknown>} [parent] Parent input.
|
|
244
|
+
* @param {Set<string>} paths Unique node paths.
|
|
245
|
+
* @returns {Record<string, unknown>} Checked node.
|
|
246
|
+
*/
|
|
247
|
+
function admitNode(value, mode, keyPath, parent, paths = new Set()) {
|
|
248
|
+
const strict = mode === 'deploy';
|
|
249
|
+
const n = closed(value, nodeKeys, mode, keyPath);
|
|
250
|
+
graphText(n.name);
|
|
251
|
+
graphText(n.jsonPath);
|
|
252
|
+
if (strict)
|
|
253
|
+
need(isText(n.label), `${keyPath}.label`, 'must be text');
|
|
254
|
+
// The node type is assigned by Salesforce: a create may leave it out (a live API 68 create
|
|
255
|
+
// without node types answered 201, 2026-11-18); a stated one must be text.
|
|
256
|
+
if (strict && Object.hasOwn(n, 'type'))
|
|
257
|
+
need(isText(n.type), `${keyPath}.type`, 'must be text');
|
|
258
|
+
graphRequire(!paths.has(n.jsonPath));
|
|
259
|
+
paths.add(n.jsonPath);
|
|
260
|
+
if (strict)
|
|
261
|
+
for (const key of ['devName', 'fragmentDMOName', 'referenceDeveloperName', 'projectedName'])
|
|
262
|
+
if (Object.hasOwn(n, key))
|
|
263
|
+
need(isText(n[key]), `${keyPath}.${key}`, 'must be text');
|
|
264
|
+
const fields = array(n.fields).map((f, index) => closed(f, fieldKeys, mode, `${keyPath}.fields[${index}]`));
|
|
265
|
+
if (strict)
|
|
266
|
+
need(fields.length > 0, `${keyPath}.fields`, 'must not be empty');
|
|
267
|
+
const sources = new Set();
|
|
268
|
+
const devs = new Set();
|
|
269
|
+
for (const [index, f] of fields.entries()) {
|
|
270
|
+
const at = `${keyPath}.fields[${index}]`;
|
|
271
|
+
graphText(f.sourceFieldName);
|
|
272
|
+
graphRequire(!sources.has(f.sourceFieldName));
|
|
273
|
+
sources.add(f.sourceFieldName);
|
|
274
|
+
if (!strict)
|
|
275
|
+
continue;
|
|
276
|
+
for (const key of ['dataType', 'usageTag'])
|
|
277
|
+
need(isText(f[key]), `${at}.${key}`, 'must be text');
|
|
278
|
+
for (const key of ['isKeyColumn', 'isProjected'])
|
|
279
|
+
need(typeof f[key] === 'boolean', `${at}.${key}`, 'must be true or false');
|
|
280
|
+
if (Object.hasOwn(f, 'devName')) {
|
|
281
|
+
need(typeof f.devName === 'string' && dataGraphName.test(f.devName) && !devs.has(f.devName), `${at}.devName`, 'must be a unique API name');
|
|
282
|
+
devs.add(f.devName);
|
|
283
|
+
}
|
|
284
|
+
if (Object.hasOwn(f, 'keyQualifierName'))
|
|
285
|
+
need(isText(f.keyQualifierName), `${at}.keyQualifierName`, 'must be text');
|
|
286
|
+
if (Object.hasOwn(f, 'isDGRootKeyField'))
|
|
287
|
+
need(typeof f.isDGRootKeyField === 'boolean', `${at}.isDGRootKeyField`, 'must be true or false');
|
|
288
|
+
if (Object.hasOwn(f, 'fieldRoles'))
|
|
289
|
+
need(Array.isArray(f.fieldRoles), `${at}.fieldRoles`, 'must be a list');
|
|
290
|
+
}
|
|
291
|
+
const joins = array(n.path).map((p, index) => closed(p, pathKeys, mode, `${keyPath}.path[${index}]`));
|
|
292
|
+
if (strict)
|
|
293
|
+
for (const [index, p] of joins.entries())
|
|
294
|
+
for (const key of pathKeys)
|
|
295
|
+
if (key !== 'devName' || Object.hasOwn(p, key))
|
|
296
|
+
need(isText(p[key]), `${keyPath}.path[${index}].${key}`, 'must be text');
|
|
297
|
+
// The tree shape is structural: a related object hangs below its parent through a join. A
|
|
298
|
+
// retrieved jsonPath of another form cannot be represented (the catch-all keeps it verbatim).
|
|
299
|
+
if (parent) {
|
|
300
|
+
graphRequire(n.jsonPath === `${parent.jsonPath}.${n.name}`);
|
|
301
|
+
if (strict)
|
|
302
|
+
need(joins.length > 0, `${keyPath}.path`, 'must name the join to its parent');
|
|
303
|
+
}
|
|
304
|
+
else
|
|
305
|
+
graphRequire(n.jsonPath === '$' && joins.length === 0);
|
|
306
|
+
if (strict)
|
|
307
|
+
for (const key of ['recencyCriteria', 'filterCriteria'])
|
|
308
|
+
if (Object.hasOwn(n, key))
|
|
309
|
+
need(Array.isArray(n[key]), `${keyPath}.${key}`, 'must be a list');
|
|
310
|
+
if (Object.hasOwn(n, 'topKFilterCriteria') && (strict || n.topKFilterCriteria !== null)) {
|
|
311
|
+
const at = `${keyPath}.topKFilterCriteria`;
|
|
312
|
+
const top = closed(n.topKFilterCriteria, ['limit', 'orderCriteria'], mode, at);
|
|
313
|
+
if (strict)
|
|
314
|
+
need(Number.isSafeInteger(top.limit) && top.limit > 0, `${at}.limit`, 'must be a positive whole number');
|
|
315
|
+
if (strict || Array.isArray(top.orderCriteria))
|
|
316
|
+
for (const [index, entry] of array(top.orderCriteria).entries()) {
|
|
317
|
+
const order = closed(entry, ['fieldApiName', 'sortOrder'], mode, `${at}.orderCriteria[${index}]`);
|
|
318
|
+
if (strict)
|
|
319
|
+
for (const key of ['fieldApiName', 'sortOrder'])
|
|
320
|
+
need(isText(order[key]), `${at}.orderCriteria[${index}].${key}`, 'must be text');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
for (const [index, child] of array(n.relatedObjects).entries())
|
|
324
|
+
admitNode(child, mode, `${keyPath}.relatedObjects[${index}]`, n, paths);
|
|
325
|
+
return n;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Admit saved native68 definitions by structure; the API decides what it accepts. Retrieve mode
|
|
329
|
+
* keeps unknown keys and unset (`null`) values, and checks only the name, data space, root
|
|
330
|
+
* object, schedule shape and node tree; a deploy of such a file refuses and names the key.
|
|
331
|
+
* `c__dataSpace` names the data space; `definition.dataspaceName`, when present, must equal it,
|
|
332
|
+
* and the returned definition always names it.
|
|
333
|
+
* @param {unknown} value Native document.
|
|
334
|
+
* @param {DocumentMode} mode Strictness (deploy by default).
|
|
335
|
+
* @returns {NativeDataGraphDocument} Detached admitted input with normalised enum spellings.
|
|
336
|
+
*/
|
|
337
|
+
export function validateNativeDataGraphDocument(value, mode = 'deploy') {
|
|
338
|
+
const strict = mode === 'deploy';
|
|
339
|
+
// Retrieve mode takes any nesting depth the org returns.
|
|
340
|
+
inert(value, new Set(), strict ? 24 : Number.POSITIVE_INFINITY);
|
|
341
|
+
const dataSpace = readSingleDataSpace(graphRecord(value), refuseFile);
|
|
342
|
+
const raw = graphRecord(structuredClone(value), [
|
|
343
|
+
'schemaVersion',
|
|
344
|
+
'kind',
|
|
345
|
+
'apiVersion',
|
|
346
|
+
dataSpaceKey,
|
|
347
|
+
'definition',
|
|
348
|
+
]);
|
|
349
|
+
graphRequire(raw.schemaVersion === 1 && raw.kind === 'native-data-graph' && raw.apiVersion === '68.0');
|
|
350
|
+
const d = closed(raw.definition, topKeys, mode);
|
|
351
|
+
graphRequire(typeof d.name === 'string' && dataGraphName.test(d.name));
|
|
352
|
+
// Salesforce's own key, when the definition names it, must agree with c__dataSpace; without
|
|
353
|
+
// it the definition takes c__dataSpace (the create body sends dataspaceName).
|
|
354
|
+
if (Object.hasOwn(d, 'dataspaceName') && d.dataspaceName !== dataSpace)
|
|
355
|
+
throw refuseFile('INVALID_DATASPACE_FIELD', dataSpaceKey, 'must name the data space of definition.dataspaceName');
|
|
356
|
+
d.dataspaceName = dataSpace;
|
|
357
|
+
graphText(d.primaryObjectName);
|
|
358
|
+
if (strict) {
|
|
359
|
+
need(isText(d.label), 'definition.label', 'must be text');
|
|
360
|
+
if (Object.hasOwn(d, 'description'))
|
|
361
|
+
need(typeof d.description === 'string', 'definition.description', 'must be text');
|
|
362
|
+
need(isText(d.type), 'definition.type', 'must be text');
|
|
363
|
+
for (const key of generatedKeys)
|
|
364
|
+
if (Object.hasOwn(d, key))
|
|
365
|
+
need(isText(d[key]), `definition.${key}`, 'must be text');
|
|
366
|
+
}
|
|
367
|
+
if (Object.hasOwn(d, 'fullRefreshConfig')) {
|
|
368
|
+
// Only {schedule: {frequency, timeGranularity}} is represented, in either mode; a retrieved
|
|
369
|
+
// schedule of another shape is kept verbatim by the retrieve catch-all.
|
|
370
|
+
const schedule = closed(closed(d.fullRefreshConfig, ['schedule'], 'deploy', 'definition.fullRefreshConfig').schedule, ['frequency', 'timeGranularity'], 'deploy', 'definition.fullRefreshConfig.schedule');
|
|
371
|
+
graphRequire(Number.isSafeInteger(schedule.frequency) && schedule.frequency > 0);
|
|
372
|
+
graphText(schedule.timeGranularity);
|
|
373
|
+
const spelling = schedule.timeGranularity.toLowerCase();
|
|
374
|
+
// A known value takes its request spelling; any other value is kept as written.
|
|
375
|
+
schedule.timeGranularity =
|
|
376
|
+
timeGranularities.find((value) => value.toLowerCase() === spelling) ??
|
|
377
|
+
schedule.timeGranularity;
|
|
378
|
+
}
|
|
379
|
+
if (Object.hasOwn(d, 'incrementalRefreshConfig')) {
|
|
380
|
+
if (strict)
|
|
381
|
+
need(isRecord(d.incrementalRefreshConfig), 'definition.incrementalRefreshConfig', 'must be an object');
|
|
382
|
+
else if (d.incrementalRefreshConfig !== null)
|
|
383
|
+
graphRecord(d.incrementalRefreshConfig);
|
|
384
|
+
}
|
|
385
|
+
const root = admitNode(d.sourceObject, mode, 'definition.sourceObject');
|
|
386
|
+
// The root node is the primary object; root binding reads exactly this object.
|
|
387
|
+
graphRequire(root.name === d.primaryObjectName);
|
|
388
|
+
if (typeof d.type === 'string')
|
|
389
|
+
d.type = d.type.toUpperCase();
|
|
390
|
+
normaliseNode(root);
|
|
391
|
+
// Keys in file order: the definition keeps the order it was read or written in.
|
|
392
|
+
return {
|
|
393
|
+
schemaVersion: 1,
|
|
394
|
+
kind: 'native-data-graph',
|
|
395
|
+
apiVersion: '68.0',
|
|
396
|
+
c__dataSpace: dataSpace,
|
|
397
|
+
definition: d,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Refuse a data graph file problem, naming the key.
|
|
402
|
+
* @param {string} code Refusal code.
|
|
403
|
+
* @param {string} keyPath Key path.
|
|
404
|
+
* @param {string} problem What is wrong with it.
|
|
405
|
+
* @returns {DataGraphError} Refusal with an explanation.
|
|
406
|
+
*/
|
|
407
|
+
function refuseFile(code, keyPath, problem) {
|
|
408
|
+
return explainInput(new DataGraphError(code), `The data graph file cannot be deployed: ${keyPath} ${problem}. Correct the file, or retrieve the graph again.`);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* The data graph document of a definition that names its data space (`dataspaceName`).
|
|
412
|
+
* @param {Record<string, unknown>} definition Graph definition (checked by the validator).
|
|
413
|
+
* @returns {unknown} Document candidate for validateNativeDataGraphDocument.
|
|
414
|
+
*/
|
|
415
|
+
export function nativeDataGraphDocumentOf(definition) {
|
|
416
|
+
return {
|
|
417
|
+
schemaVersion: 1,
|
|
418
|
+
kind: 'native-data-graph',
|
|
419
|
+
apiVersion: '68.0',
|
|
420
|
+
[dataSpaceKey]: definition.dataspaceName,
|
|
421
|
+
definition,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* The data space a graph GET names (`dataspaceName`): the graph's real data space, read before
|
|
426
|
+
* anything is projected. A GET without a usable one is DATA_GRAPH_DATASPACE_UNREADABLE.
|
|
427
|
+
* @param {unknown} value Graph GET body.
|
|
428
|
+
* @returns {string} Data space.
|
|
429
|
+
*/
|
|
430
|
+
export function nativeDataGraphSpace(value) {
|
|
431
|
+
const found = value && typeof value === 'object' && !Array.isArray(value)
|
|
432
|
+
? value.dataspaceName
|
|
433
|
+
: undefined;
|
|
434
|
+
if (!isDataSpaceName(found))
|
|
435
|
+
throw new DataGraphError('DATA_GRAPH_DATASPACE_UNREADABLE');
|
|
436
|
+
return found;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The refusal of a data graph whose file, or whose graph in the org, is in another data space
|
|
440
|
+
* than the run's.
|
|
441
|
+
* @param {string} name Graph name.
|
|
442
|
+
* @param {string} found The data space of the file or the org graph.
|
|
443
|
+
* @param {string} dataSpace The run's data space.
|
|
444
|
+
* @param {'file' | 'org'} where Whether the file or the org graph names `found`.
|
|
445
|
+
* @param {boolean} [crossSpace] A deploy --allow-cross-dataspace can translate: say so.
|
|
446
|
+
* @returns {DataGraphError} DATA_GRAPH_DATASPACE_MISMATCH with an explanation.
|
|
447
|
+
*/
|
|
448
|
+
export function nativeDataGraphSpaceMismatch(name, found, dataSpace, where, crossSpace = false) {
|
|
449
|
+
return explainInput(new DataGraphError('DATA_GRAPH_DATASPACE_MISMATCH'), `${where === 'file' ? `The file of data graph ${name} names the data space ${printableKey(found)} in ${dataSpaceKey}` : `Data graph ${name} is in the data space ${printableKey(found)} in the org`}, but the run's data space is ${printableKey(dataSpace)} (--dataspace, default "default"). Graph names are unique in the org, so run the command with --dataspace ${printableKey(found)}${where === 'file' ? ', or correct the file' : ''}. Nothing was written.${crossSpace ? crossSpaceSentence(dataSpace) : ''}`);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Whether a value is a plain object.
|
|
453
|
+
* @param {unknown} value Candidate.
|
|
454
|
+
* @returns {boolean} Object and not an array.
|
|
455
|
+
*/
|
|
456
|
+
function isRecord(value) {
|
|
457
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Whether no node or field of a native GET reports dependencies or related segments.
|
|
461
|
+
* Delete requires this; retrieve and update do not.
|
|
462
|
+
* @param {unknown} value Native GET response (or its observed target).
|
|
463
|
+
* @returns {boolean} True when every dependency and related-segment array is empty.
|
|
464
|
+
*/
|
|
465
|
+
export function nativeDataGraphUnreferenced(value) {
|
|
466
|
+
const node = graphRecord(value);
|
|
467
|
+
return (isDeepStrictEqual(node.dependency, []) &&
|
|
468
|
+
isDeepStrictEqual(node.relatedSegments, []) &&
|
|
469
|
+
array(node.fields).every((f) => isDeepStrictEqual(graphRecord(f).dependency, [])) &&
|
|
470
|
+
array(node.relatedObjects).every((child) => nativeDataGraphUnreferenced(child)));
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Hash detached JSON with stable object keys while retaining every array order.
|
|
474
|
+
* @param {unknown} value JSON evidence.
|
|
475
|
+
* @returns {string} SHA256 evidence digest.
|
|
476
|
+
*/
|
|
477
|
+
export function nativeGraphFingerprint(value) {
|
|
478
|
+
return createHash('sha256')
|
|
479
|
+
.update(JSON.stringify(graphCanonicalObject(value)))
|
|
480
|
+
.digest('hex');
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Convert an admitted GET node to the exact qualified PUT inventory. Retrieve mode keeps unknown
|
|
484
|
+
* node, field and join keys and does not check record IDs or generated names.
|
|
485
|
+
* @param {unknown} value GET node.
|
|
486
|
+
* @param {DocumentMode} mode Strictness.
|
|
487
|
+
* @param {Set<string>} identities Already observed record identities.
|
|
488
|
+
* @returns {Record<string, unknown>} Request node.
|
|
489
|
+
*/
|
|
490
|
+
function observedNode(value, mode, identities = new Set()) {
|
|
491
|
+
const strict = mode === 'deploy';
|
|
492
|
+
const n = closed(value, [...nodeKeys, ...serverNodeKeys], mode, 'sourceObject');
|
|
493
|
+
if (strict) {
|
|
494
|
+
graphText(n.id);
|
|
495
|
+
graphRequire(!identities.has(n.id));
|
|
496
|
+
identities.add(n.id);
|
|
497
|
+
graphText(n.devName);
|
|
498
|
+
// Dependencies and related segments are server facts, not authored configuration; delete
|
|
499
|
+
// checks them separately (nativeDataGraphUnreferenced).
|
|
500
|
+
for (const key of ['dependency', 'relatedSegments'])
|
|
501
|
+
array(n[key]);
|
|
502
|
+
graphText(n.categoryDevName);
|
|
503
|
+
}
|
|
504
|
+
const result = strict ? pick(n, nodeKeys) : keep(n, nodeKeys, serverNodeKeys);
|
|
505
|
+
result.fields = array(n.fields).map((value) => {
|
|
506
|
+
const f = closed(value, [...fieldKeys, ...serverFieldKeys], mode, 'sourceObject.fields');
|
|
507
|
+
if (!strict)
|
|
508
|
+
return keep(f, fieldKeys, serverFieldKeys);
|
|
509
|
+
graphText(f.id);
|
|
510
|
+
graphRequire(!identities.has(f.id));
|
|
511
|
+
identities.add(f.id);
|
|
512
|
+
graphText(f.devName);
|
|
513
|
+
graphRequire(f.name === f.devName);
|
|
514
|
+
array(f.dependency);
|
|
515
|
+
return pick(f, fieldKeys);
|
|
516
|
+
});
|
|
517
|
+
result.path = array(n.path).map((value) => {
|
|
518
|
+
const p = closed(value, [...pathKeys, ...serverPathKeys], mode, 'sourceObject.path');
|
|
519
|
+
if (!strict)
|
|
520
|
+
return keep(p, pathKeys, serverPathKeys);
|
|
521
|
+
graphText(p.devName);
|
|
522
|
+
return pick(p, pathKeys);
|
|
523
|
+
});
|
|
524
|
+
result.relatedObjects = array(n.relatedObjects).map((child) => observedNode(child, mode, identities));
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Roundtrip qualified native GET data without treating record IDs as portable authority.
|
|
529
|
+
* Retrieve mode takes a graph in any status, keeps unknown keys (and a nonempty
|
|
530
|
+
* `extendedProperties`) and drops empty or `null` generated names.
|
|
531
|
+
* @param {unknown} value Native GET response.
|
|
532
|
+
* @param {DocumentMode} mode Strictness (deploy by default).
|
|
533
|
+
* @returns {NativeDataGraphDocument} Complete authored request representation.
|
|
534
|
+
*/
|
|
535
|
+
export function nativeDataGraphDocumentFromResponse(value, mode = 'deploy') {
|
|
536
|
+
const strict = mode === 'deploy';
|
|
537
|
+
inert(value, new Set(), strict ? 24 : Number.POSITIVE_INFINITY);
|
|
538
|
+
const raw = closed(value, [...topKeys, ...serverTopKeys], mode, 'graph');
|
|
539
|
+
if (strict)
|
|
540
|
+
graphRequire(raw.kind === 'CdpDataGraphOutputRepresentation' &&
|
|
541
|
+
raw.extendedProperties === '' &&
|
|
542
|
+
typeof raw.version === 'string' &&
|
|
543
|
+
/^\d+$/u.test(raw.version));
|
|
544
|
+
const definition = strict
|
|
545
|
+
? pick(raw, topKeys)
|
|
546
|
+
: keep(raw, topKeys, serverTopKeys.filter((key) => key !== 'extendedProperties' || unset(raw.extendedProperties)));
|
|
547
|
+
// A graph that is still being created carries empty generated names (`valuesDmoName: ""`
|
|
548
|
+
// in the API68 create echo, recorded live 2026-11-12); they are not authored values.
|
|
549
|
+
// Retrieve drops empty or null ones whatever the status.
|
|
550
|
+
if (!strict || raw.status !== 'ready')
|
|
551
|
+
for (const key of generatedKeys)
|
|
552
|
+
if (strict ? definition[key] === '' : unset(definition[key]))
|
|
553
|
+
delete definition[key];
|
|
554
|
+
definition.sourceObject = observedNode(raw.sourceObject, mode);
|
|
555
|
+
// The graph's own data space becomes c__dataSpace; a GET without one cannot be placed.
|
|
556
|
+
nativeDataGraphSpace(raw);
|
|
557
|
+
// Lowercase enum spellings (type, usageTag, sortOrder, timeGranularity) are normalised there.
|
|
558
|
+
return validateNativeDataGraphDocument(nativeDataGraphDocumentOf(definition), mode);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Remove server-generated names from a node tree: node fragment DMOs, join and field developer
|
|
562
|
+
* names. They belong to one graph instance and are never authored configuration.
|
|
563
|
+
* @param {Record<string, unknown>} n Node, changed in place.
|
|
564
|
+
*/
|
|
565
|
+
function unbind(n) {
|
|
566
|
+
delete n.fragmentDMOName;
|
|
567
|
+
for (const p of n.path)
|
|
568
|
+
delete p.devName;
|
|
569
|
+
for (const f of n.fields)
|
|
570
|
+
delete f.devName;
|
|
571
|
+
for (const c of n.relatedObjects)
|
|
572
|
+
unbind(c);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Project an authored native document into its API68 create body: the authored definition as
|
|
576
|
+
* written (any root, related objects with their joins, field settings, schedules), without the
|
|
577
|
+
* graph-level generated DMO/mapping/transform names, fragment DMOs and join/field developer names.
|
|
578
|
+
* The node `devName` is kept: both recorded API68 creates sent one and the server replaced it.
|
|
579
|
+
* @param {unknown} value Native document.
|
|
580
|
+
* @returns {Record<string, unknown>} Detached create body.
|
|
581
|
+
*/
|
|
582
|
+
export function nativeDataGraphCreateDefinition(value) {
|
|
583
|
+
const definition = validateNativeDataGraphDocument(value).definition;
|
|
584
|
+
for (const key of topKeys.slice(7, 13))
|
|
585
|
+
delete definition[key];
|
|
586
|
+
unbind(graphRecord(definition.sourceObject));
|
|
587
|
+
return definition;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Refuse a join change of a retained related object before any write. Salesforce answers 200 to
|
|
591
|
+
* a PUT that changes the join, rebuilds the graph and keeps the old join (live, API 68,
|
|
592
|
+
* 2026-11-18), so sending it would report a change that never happened.
|
|
593
|
+
* @param {string} jsonPath Node whose join differs.
|
|
594
|
+
* @returns {DataGraphError} Named refusal.
|
|
595
|
+
*/
|
|
596
|
+
function joinChange(jsonPath) {
|
|
597
|
+
return explainInput(new DataGraphError('DATA_GRAPH_JOIN_CHANGE'), `The join of the related object ${jsonPath} differs from the graph in the org. Salesforce accepts a join change but keeps the old join, so the plugin does not send it. Keep the join of the org in the file, or delete the graph and create it again with the new join.`);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Build the PUT body from the authored definition: the file is the desired state. Fields and
|
|
601
|
+
* related objects are sent as the file lists them, so a field or related object the file leaves
|
|
602
|
+
* out is not sent and Salesforce answers (at API 68 it refuses removals with 400); a root change
|
|
603
|
+
* and another related object are sent too. Retained nodes and fields keep the generated names of
|
|
604
|
+
* the fresh target; a node whose object differs (a new root, another related object) and all
|
|
605
|
+
* nodes below it are sent without generated names. Key-qualifier fields Salesforce added (named
|
|
606
|
+
* by another field's keyQualifierName) are kept when the file leaves them out: a PUT without them
|
|
607
|
+
* keeps them (live, API 68). Omitted settings of the graph, a retained node or a retained field
|
|
608
|
+
* keep the target's values. Entries keep the target's order; new ones follow in authored order.
|
|
609
|
+
* A retained node keeps the target's label: Salesforce sets node labels itself, from the object's
|
|
610
|
+
* label, and keeps them when a POST or PUT sends another one (live, API 68, 2026-11-22/23).
|
|
611
|
+
* Refused: a different name or data space (they identify the target graph), a join change of a
|
|
612
|
+
* retained related object (DATA_GRAPH_JOIN_CHANGE; Salesforce ignores it), and a different type,
|
|
613
|
+
* reference or projected name of a retained node (assigned by the API: a recorded API68 create
|
|
614
|
+
* sent `standard` for a unified root and read `derived` back, 2026-11-12).
|
|
615
|
+
* @param {unknown} baseline Fresh independently bound native GET.
|
|
616
|
+
* @param {NativeDataGraphDocument} desired Authored intent, not target authority.
|
|
617
|
+
* @param {DocumentMode} mode Strictness of both documents (retrieve keeps unknown keys).
|
|
618
|
+
* @param {boolean} [superset] Readback only: keep every target field the authored node does not
|
|
619
|
+
* name (Salesforce adds fields, such as key qualifiers or data source fields on bridge nodes).
|
|
620
|
+
* @returns {Record<string, unknown>} Complete target-bound PUT payload.
|
|
621
|
+
*/
|
|
622
|
+
export function buildNativeDataGraphUpdateRequest(baseline, desired, mode = 'deploy', superset = false) {
|
|
623
|
+
const target = nativeDataGraphDocumentFromResponse(baseline, mode).definition;
|
|
624
|
+
const wanted = validateNativeDataGraphDocument(desired, mode).definition;
|
|
625
|
+
for (const key of ['name', 'dataspaceName'])
|
|
626
|
+
graphRequire(target[key] === wanted[key]);
|
|
627
|
+
target.primaryObjectName = wanted.primaryObjectName;
|
|
628
|
+
// Generated DMO, mapping and transform names stay the target's; authored ones are ignored.
|
|
629
|
+
for (const key of [
|
|
630
|
+
'label',
|
|
631
|
+
'type',
|
|
632
|
+
'fullRefreshConfig',
|
|
633
|
+
'incrementalRefreshConfig',
|
|
634
|
+
...realTimeKeys,
|
|
635
|
+
])
|
|
636
|
+
if (Object.hasOwn(wanted, key))
|
|
637
|
+
target[key] = wanted[key];
|
|
638
|
+
// An omitted description keeps the target's, like any other omitted property.
|
|
639
|
+
if (Object.hasOwn(wanted, 'description'))
|
|
640
|
+
target.description = wanted.description;
|
|
641
|
+
const settings = fieldKeys.filter((key) => key !== 'devName');
|
|
642
|
+
/**
|
|
643
|
+
* A node the target does not hold, sent without generated names, including authored hints
|
|
644
|
+
* from another graph.
|
|
645
|
+
* @param {Record<string, unknown>} next Authored node.
|
|
646
|
+
* @returns {Record<string, unknown>} Detached new node.
|
|
647
|
+
*/
|
|
648
|
+
function added(next) {
|
|
649
|
+
const node = structuredClone(next);
|
|
650
|
+
/**
|
|
651
|
+
* Drop node developer names throughout the new subtree.
|
|
652
|
+
* @param {Record<string, unknown>} n New node.
|
|
653
|
+
*/
|
|
654
|
+
const anonymous = (n) => {
|
|
655
|
+
delete n.devName;
|
|
656
|
+
for (const c of n.relatedObjects)
|
|
657
|
+
anonymous(c);
|
|
658
|
+
};
|
|
659
|
+
anonymous(node);
|
|
660
|
+
unbind(node);
|
|
661
|
+
return node;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Apply one authored node to its retained target node, keeping generated bindings.
|
|
665
|
+
* @param {Record<string, unknown>} current Target node (same object and jsonPath).
|
|
666
|
+
* @param {Record<string, unknown>} next Authored node.
|
|
667
|
+
* @returns {Record<string, unknown>} Node to send.
|
|
668
|
+
*/
|
|
669
|
+
function merge(current, next) {
|
|
670
|
+
for (const key of ['type', 'referenceDeveloperName', 'projectedName'])
|
|
671
|
+
if (Object.hasOwn(next, key))
|
|
672
|
+
graphRequire(isDeepStrictEqual(current[key], next[key]));
|
|
673
|
+
for (const key of ['recencyCriteria', 'filterCriteria', 'topKFilterCriteria'])
|
|
674
|
+
if (Object.hasOwn(next, key))
|
|
675
|
+
current[key] = next[key];
|
|
676
|
+
const joins = (path) => path.map((p) => pick(p, ['fieldName', 'parentFieldName']));
|
|
677
|
+
if (!isDeepStrictEqual(joins(current.path), joins(next.path)))
|
|
678
|
+
throw joinChange(next.jsonPath);
|
|
679
|
+
const authored = next.fields;
|
|
680
|
+
const existing = current.fields;
|
|
681
|
+
const qualifiers = new Set(existing.map((f) => f.keyQualifierName).filter(Boolean));
|
|
682
|
+
const fields = [];
|
|
683
|
+
for (const f of existing) {
|
|
684
|
+
const match = authored.find((entry) => entry.sourceFieldName === f.sourceFieldName);
|
|
685
|
+
if (match)
|
|
686
|
+
fields.push(Object.assign(f, pick(match, settings)));
|
|
687
|
+
else if (superset || qualifiers.has(f.sourceFieldName))
|
|
688
|
+
fields.push(f);
|
|
689
|
+
}
|
|
690
|
+
for (const f of authored)
|
|
691
|
+
if (!existing.some((entry) => entry.sourceFieldName === f.sourceFieldName))
|
|
692
|
+
fields.push(pick(f, settings));
|
|
693
|
+
current.fields = fields;
|
|
694
|
+
current.relatedObjects = nodes(current.relatedObjects, next.relatedObjects);
|
|
695
|
+
return current;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* The authored related objects: retained ones (same jsonPath) in target order, then new ones.
|
|
699
|
+
* @param {Record<string, unknown>[]} existing Target nodes.
|
|
700
|
+
* @param {Record<string, unknown>[]} authored Authored nodes.
|
|
701
|
+
* @returns {Record<string, unknown>[]} Nodes to send.
|
|
702
|
+
*/
|
|
703
|
+
function nodes(existing, authored) {
|
|
704
|
+
const result = [];
|
|
705
|
+
for (const current of existing) {
|
|
706
|
+
const match = authored.find((entry) => entry.jsonPath === current.jsonPath);
|
|
707
|
+
if (match)
|
|
708
|
+
result.push(merge(current, match));
|
|
709
|
+
}
|
|
710
|
+
for (const next of authored)
|
|
711
|
+
if (!existing.some((entry) => entry.jsonPath === next.jsonPath))
|
|
712
|
+
result.push(added(next));
|
|
713
|
+
return result;
|
|
714
|
+
}
|
|
715
|
+
const root = graphRecord(target.sourceObject);
|
|
716
|
+
const wantedRoot = graphRecord(wanted.sourceObject);
|
|
717
|
+
// A root change sends the whole authored tree without the old root's generated names.
|
|
718
|
+
target.sourceObject = root.name === wantedRoot.name ? merge(root, wantedRoot) : added(wantedRoot);
|
|
719
|
+
return validateNativeDataGraphDocument(nativeDataGraphDocumentOf(target), mode).definition;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Bind independently read projection and generated identities; readiness is not computation proof.
|
|
723
|
+
* Retrieve mode takes any status, ID and creation date as read and does not require the generated
|
|
724
|
+
* names of a ready graph; the authored settings must still hold.
|
|
725
|
+
* @param {unknown} value Native GET response.
|
|
726
|
+
* @param {NativeDataGraphDocument} expected Authored intent.
|
|
727
|
+
* @param {DocumentMode} mode Strictness (deploy by default).
|
|
728
|
+
* @returns {NativeDataGraphObservation} Detached nonvolatile evidence.
|
|
729
|
+
*/
|
|
730
|
+
export function observeNativeDataGraph(value, expected, mode = 'deploy') {
|
|
731
|
+
const strict = mode === 'deploy';
|
|
732
|
+
const document = validateNativeDataGraphDocument(expected, mode);
|
|
733
|
+
const actual = nativeDataGraphDocumentFromResponse(value, mode);
|
|
734
|
+
const raw = graphRecord(structuredClone(value));
|
|
735
|
+
const created = Date.parse(raw.createdDate);
|
|
736
|
+
if (strict) {
|
|
737
|
+
graphText(raw.id);
|
|
738
|
+
graphText(raw.createdDate);
|
|
739
|
+
graphRequire(Number.isFinite(created));
|
|
740
|
+
}
|
|
741
|
+
graphRequire(!strict ||
|
|
742
|
+
[
|
|
743
|
+
'creating',
|
|
744
|
+
// Read for about 9 s between creating and ready during a live API68 create (2026-11-12).
|
|
745
|
+
'processing',
|
|
746
|
+
'ready',
|
|
747
|
+
'deleting',
|
|
748
|
+
'editing',
|
|
749
|
+
'editing_no_version_update',
|
|
750
|
+
'editing_post_sync',
|
|
751
|
+
].includes(raw.status));
|
|
752
|
+
// Every authored setting must already hold. Field order is the server's: it reordered the
|
|
753
|
+
// fields of a related object added by PUT (recorded live at API68, 2026-11-12). Fields the
|
|
754
|
+
// server added beyond the authored ones are accepted here (never dropped in a PUT body).
|
|
755
|
+
const request = buildNativeDataGraphUpdateRequest(raw, document, mode, true);
|
|
756
|
+
graphRequire(isDeepStrictEqual(request, actual.definition));
|
|
757
|
+
if (strict && raw.status === 'ready') {
|
|
758
|
+
for (const key of [
|
|
759
|
+
'idDmoName',
|
|
760
|
+
'valuesDmoName',
|
|
761
|
+
'dayZeroMappingDevName',
|
|
762
|
+
'dayZeroTransformDevName',
|
|
763
|
+
])
|
|
764
|
+
graphText(raw[key]);
|
|
765
|
+
graphText(graphRecord(raw.sourceObject).fragmentDMOName);
|
|
766
|
+
}
|
|
767
|
+
const target = { ...raw };
|
|
768
|
+
for (const key of ['status', 'modifiedDate', 'lastRefreshedDate'])
|
|
769
|
+
delete target[key];
|
|
770
|
+
return {
|
|
771
|
+
id: raw.id,
|
|
772
|
+
createdDate: Number.isFinite(created)
|
|
773
|
+
? new Date(created).toISOString()
|
|
774
|
+
: raw.createdDate,
|
|
775
|
+
status: raw.status,
|
|
776
|
+
definitionFingerprint: nativeGraphFingerprint(target),
|
|
777
|
+
document,
|
|
778
|
+
target,
|
|
779
|
+
};
|
|
780
|
+
}
|