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.
- package/LICENSE +21 -21
- package/README.md +572 -240
- package/docs/artifact-format.md +527 -633
- package/docs/capabilities.md +1159 -168
- package/docs/git-workflow.md +135 -12
- package/docs/handover.md +7826 -12
- 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 +222 -6
- package/lib/artifacts/read-deploy-input.js +1213 -53
- 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 +234 -15
- package/lib/commands/data360/deploy.js +2292 -100
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +260 -13
- package/lib/commands/data360/retrieve.js +1880 -85
- 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 +1 -0
- package/lib/plugin.js +3 -1
- 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 +94 -32
- package/lib/transport/connect-client.js +318 -178
- 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 +29 -6
- package/lib/artifacts/dmo-document.d.ts +0 -181
- package/lib/artifacts/dmo-document.js +0 -848
- package/lib/artifacts/dmo-update-delta.d.ts +0 -28
- package/lib/artifacts/dmo-update-delta.js +0 -86
- package/lib/artifacts/write-other-dmo.d.ts +0 -17
- package/lib/artifacts/write-other-dmo.js +0 -140
- package/lib/services/execute-dmo-create.d.ts +0 -24
- package/lib/services/execute-dmo-create.js +0 -118
- package/lib/services/execute-dmo-deploy.d.ts +0 -33
- package/lib/services/execute-dmo-deploy.js +0 -197
- package/lib/services/preflight-dmo-deploy.d.ts +0 -69
- package/lib/services/preflight-dmo-deploy.js +0 -161
- package/lib/services/retrieve-other-dmo.d.ts +0 -46
- package/lib/services/retrieve-other-dmo.js +0 -140
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { isDataSpaceName } from './data-space-field.js';
|
|
2
|
+
import { validateDloDocument } from './dlo-document.js';
|
|
3
|
+
import { calculatedInsightName } from './native-calculated-insight-document.js';
|
|
4
|
+
import { validateIdentityResolutionDocument } from './identity-resolution-document.js';
|
|
5
|
+
import { validateNativeDmoDocument } from './native-dmo-document.js';
|
|
6
|
+
import { unnamedChildSegment, validateSegmentDocument } from './segment-document.js';
|
|
7
|
+
export const dependencyLimits = Object.freeze({
|
|
8
|
+
nodes: 256,
|
|
9
|
+
edges: 512,
|
|
10
|
+
});
|
|
11
|
+
/** Payload-free selection refusal. */
|
|
12
|
+
export class DependencySelectionError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
constructor(code) {
|
|
15
|
+
super('Dependency selection is incomplete or unsupported; no deployment was executed.');
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.name = 'DependencySelectionError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Key exact typed identities in any data space; API names are mandatory, never label fallbacks.
|
|
22
|
+
* @param {DependencyIdentity} identity Logical identity.
|
|
23
|
+
* @returns {string} Unambiguous typed key.
|
|
24
|
+
*/
|
|
25
|
+
export function dependencyKey(identity) {
|
|
26
|
+
if (!['dmo', 'segment', 'identity-resolution', 'calculated-insight', 'dlo'].includes(identity.kind) ||
|
|
27
|
+
!isDataSpaceName(identity.dataSpace) ||
|
|
28
|
+
!/^[A-Za-z][A-Za-z0-9_]{0,199}$/u.test(identity.apiName))
|
|
29
|
+
throw new DependencySelectionError('DEPENDENCY_IDENTITY_UNSUPPORTED');
|
|
30
|
+
return `${identity.kind}:${identity.dataSpace}:${identity.apiName}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Extract only admitted family structures; unknown closure must not become an empty leaf.
|
|
34
|
+
* @param {NativeDmoDocument | SegmentDocument | IdentityResolutionDocument} value Authored component.
|
|
35
|
+
* @param {DocumentMode} [mode] `retrieve` checks a DLO or DMO only for its identity.
|
|
36
|
+
* @param {string} [dataSpace] The run's data space: a DLO (which lists every data space it
|
|
37
|
+
* belongs to) is keyed in it when it lists it.
|
|
38
|
+
* @returns {DependencyNode} Exact component and dependencies.
|
|
39
|
+
*/
|
|
40
|
+
export function documentDependencyNode(value, mode = 'deploy', dataSpace = 'default') {
|
|
41
|
+
if (value.kind === 'dlo') {
|
|
42
|
+
const document = validateDloDocument(value, mode);
|
|
43
|
+
// Source ownership is freshly admitted by its family service, never provisioned. A DLO is
|
|
44
|
+
// keyed in the run's data space when it lists it.
|
|
45
|
+
const keyed = document.c__dataSpace.includes(dataSpace) ? dataSpace : document.c__dataSpace[0];
|
|
46
|
+
return {
|
|
47
|
+
identity: { kind: 'dlo', dataSpace: keyed, apiName: document.identity.apiName },
|
|
48
|
+
dependencies: [],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (value.kind === 'calculated-insight') {
|
|
52
|
+
// The DMOs and insights its SQL names (calculatedInsightReference): ordering edges only.
|
|
53
|
+
if (!calculatedInsightName.test(value.identity.apiName))
|
|
54
|
+
throw new DependencySelectionError('DEPENDENCY_IDENTITY_UNSUPPORTED');
|
|
55
|
+
return {
|
|
56
|
+
identity: { kind: 'calculated-insight', ...value.identity },
|
|
57
|
+
dependencies: value.spec.dependencies.map(({ kind, dataSpace, apiName }) => ({
|
|
58
|
+
kind,
|
|
59
|
+
dataSpace,
|
|
60
|
+
apiName,
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (value.kind === 'identity-resolution') {
|
|
65
|
+
const document = validateIdentityResolutionDocument(value, mode);
|
|
66
|
+
// Every entity DMO is in the ruleset's own data space.
|
|
67
|
+
const space = document.c__dataSpace;
|
|
68
|
+
return {
|
|
69
|
+
identity: {
|
|
70
|
+
kind: 'identity-resolution',
|
|
71
|
+
dataSpace: space,
|
|
72
|
+
apiName: document.identity.apiName,
|
|
73
|
+
},
|
|
74
|
+
dependencies: document.spec.reconciliationRules.map(({ entity }) => ({
|
|
75
|
+
kind: entity.kind,
|
|
76
|
+
dataSpace: space,
|
|
77
|
+
apiName: entity.apiName,
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (value.kind === 'segment') {
|
|
82
|
+
const document = validateSegmentDocument(value, mode);
|
|
83
|
+
// The segmentOn DMO and every Waterfall child are in the segment's own data space.
|
|
84
|
+
const space = document.c__dataSpace;
|
|
85
|
+
const { kind, apiName } = document.spec.segmentOn;
|
|
86
|
+
// A Waterfall runs after the child segments it names (a stand-in for an unnamed child is none).
|
|
87
|
+
const children = (document.spec.childSegments ?? [])
|
|
88
|
+
.filter((child) => child !== unnamedChildSegment)
|
|
89
|
+
.map((child) => ({ kind: 'segment', dataSpace: space, apiName: child }));
|
|
90
|
+
return {
|
|
91
|
+
identity: { kind: 'segment', dataSpace: space, apiName: document.identity.apiName },
|
|
92
|
+
dependencies: [{ kind, dataSpace: space, apiName }, ...children],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (value.kind !== 'dmo')
|
|
96
|
+
throw new DependencySelectionError('DEPENDENCY_CLOSURE_UNSUPPORTED');
|
|
97
|
+
let document;
|
|
98
|
+
try {
|
|
99
|
+
document = validateNativeDmoDocument(value, mode);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new DependencySelectionError('DEPENDENCY_CLOSURE_UNSUPPORTED');
|
|
103
|
+
}
|
|
104
|
+
// A native DMO definition names no other component; it is always a leaf.
|
|
105
|
+
return {
|
|
106
|
+
identity: { kind: 'dmo', dataSpace: document.c__dataSpace, apiName: document.identity.apiName },
|
|
107
|
+
dependencies: [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Order selected nodes dependency-first, retaining isolated roots and external prerequisites.
|
|
112
|
+
* Family/space/name is a tie-break only among ready nodes. External nodes need target binding.
|
|
113
|
+
* @param {DependencyNode[]} nodes Complete selected graph.
|
|
114
|
+
* @param {{nodes: number, edges: number}} [limits] Node and edge caps; deploy keeps the default,
|
|
115
|
+
* retrieve passes unbounded caps (it writes files and provisions nothing).
|
|
116
|
+
* @returns {string[]} Ordered typed keys.
|
|
117
|
+
*/
|
|
118
|
+
export function orderDependencyNodes(nodes, limits = dependencyLimits) {
|
|
119
|
+
if (nodes.length > limits.nodes)
|
|
120
|
+
throw new DependencySelectionError('DEPENDENCY_LIMIT_EXCEEDED');
|
|
121
|
+
const remaining = new Map();
|
|
122
|
+
let edges = 0;
|
|
123
|
+
for (const node of nodes) {
|
|
124
|
+
const key = dependencyKey(node.identity);
|
|
125
|
+
if (remaining.has(key))
|
|
126
|
+
throw new DependencySelectionError('DEPENDENCY_DUPLICATE_IDENTITY');
|
|
127
|
+
// A component may name only components of its own data space.
|
|
128
|
+
if (node.dependencies.some((identity) => identity.dataSpace !== node.identity.dataSpace))
|
|
129
|
+
throw new DependencySelectionError('DEPENDENCY_IDENTITY_UNSUPPORTED');
|
|
130
|
+
const dependencies = new Set(node.dependencies.map((identity) => dependencyKey(identity)));
|
|
131
|
+
edges += dependencies.size;
|
|
132
|
+
if (edges > limits.edges)
|
|
133
|
+
throw new DependencySelectionError('DEPENDENCY_LIMIT_EXCEEDED');
|
|
134
|
+
remaining.set(key, dependencies);
|
|
135
|
+
}
|
|
136
|
+
const selected = new Set(remaining.keys());
|
|
137
|
+
const ordered = [];
|
|
138
|
+
const done = new Set();
|
|
139
|
+
while (remaining.size > 0) {
|
|
140
|
+
const ready = [...remaining]
|
|
141
|
+
.filter(([, dependencies]) => [...dependencies].every((key) => !selected.has(key) || done.has(key)))
|
|
142
|
+
.map(([key]) => key)
|
|
143
|
+
// eslint-disable-next-line unicorn/no-array-sort -- Sort a fresh ready-node list within the existing TypeScript library target.
|
|
144
|
+
.sort();
|
|
145
|
+
if (ready.length === 0)
|
|
146
|
+
throw new DependencySelectionError('DEPENDENCY_CYCLE');
|
|
147
|
+
// Recompute readiness after each node so newly-ready nodes take part in the tie-break.
|
|
148
|
+
const key = ready[0];
|
|
149
|
+
ordered.push(key);
|
|
150
|
+
done.add(key);
|
|
151
|
+
remaining.delete(key);
|
|
152
|
+
}
|
|
153
|
+
return ordered;
|
|
154
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DocumentMode } from './verbatim-document.js';
|
|
2
|
+
export type DloField = {
|
|
3
|
+
name: string;
|
|
4
|
+
label: string;
|
|
5
|
+
dataType: string;
|
|
6
|
+
isPrimaryKey: boolean;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type DloDocument = {
|
|
10
|
+
schemaVersion: 1;
|
|
11
|
+
kind: 'dlo';
|
|
12
|
+
/** Every data space the DLO belongs to (file key `c__dataSpace`). */
|
|
13
|
+
c__dataSpace: string[];
|
|
14
|
+
identity: {
|
|
15
|
+
apiName: string;
|
|
16
|
+
};
|
|
17
|
+
spec: {
|
|
18
|
+
label: string;
|
|
19
|
+
category: string;
|
|
20
|
+
/** Engagement DLOs: the DateTime field that dates each record; fixed after create. */
|
|
21
|
+
eventDateTimeFieldName?: string;
|
|
22
|
+
/** The field whose value tells which version of a record is newest; set once, then fixed. */
|
|
23
|
+
recordModifiedFieldName?: string;
|
|
24
|
+
fields: DloField[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Payload-free native DLO refusal, with an authoritative HTTP status when available. */
|
|
28
|
+
export declare class DloError extends Error {
|
|
29
|
+
readonly code: string;
|
|
30
|
+
readonly status?: number | undefined;
|
|
31
|
+
constructor(code: string, status?: number | undefined);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate a native DLO document without losing additional field definitions. Deploy mode (the
|
|
35
|
+
* default) admits only what a deploy can send and names the first offending key path; retrieve
|
|
36
|
+
* mode keeps what the org returned and checks only what names and places the file.
|
|
37
|
+
* @param {unknown} value Untrusted saved document.
|
|
38
|
+
* @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (lenient).
|
|
39
|
+
* @returns {DloDocument} Checked document.
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateDloDocument(value: unknown, mode?: DocumentMode): DloDocument;
|
|
42
|
+
/** Fields Salesforce adds to a data lake object itself. */
|
|
43
|
+
export declare const dloSystemFields: ReadonlySet<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Whether a field of an existing DLO is one Salesforce generated: a system field or a key
|
|
46
|
+
* qualifier `KQ_<Name>__c` of another field of the same DLO (Salesforce adds one for the primary
|
|
47
|
+
* key on create, and one for a field that a relationship uses as its source, live API 68), never a
|
|
48
|
+
* primary key or a custom field. A deploy keeps such a field when the file leaves it out, and a
|
|
49
|
+
* retrieve leaves it out; both use this one predicate.
|
|
50
|
+
* @param {DloField} field Field of the DLO.
|
|
51
|
+
* @param {DloField[]} fields Every field of the same DLO.
|
|
52
|
+
* @returns {boolean} Whether the field is generated, not authored.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isGeneratedDloField(field: DloField, fields: readonly DloField[]): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Keep the authored content of a DLO definition: generated fields are left out, except a field
|
|
57
|
+
* the event field or the record-modified field names, which the document has to list.
|
|
58
|
+
* @param {DloDocument} document Complete definition as read.
|
|
59
|
+
* @returns {DloDocument} Independent copy without generated fields.
|
|
60
|
+
*/
|
|
61
|
+
export declare function leanDloDocument(document: DloDocument): DloDocument;
|
|
62
|
+
/**
|
|
63
|
+
* Unwrap exactly one native GET object or a POST/PATCH single-object response.
|
|
64
|
+
* @param {unknown} value Native response.
|
|
65
|
+
* @returns {Record<string, unknown>} Single native object with target runtime identity retained.
|
|
66
|
+
*/
|
|
67
|
+
export declare function unwrapDlo(value: unknown): Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* The data spaces a native DLO object lists in `dataSpaceInfo[].name`, sorted; a missing, empty
|
|
70
|
+
* or unusable list is UNSUPPORTED_DLO_DATASPACE.
|
|
71
|
+
* @param {Record<string, unknown>} object Native DLO object.
|
|
72
|
+
* @returns {string[]} Its data spaces.
|
|
73
|
+
*/
|
|
74
|
+
export declare function dloDataSpaces(object: Record<string, unknown>): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Save definition fields, including generated fields, without runtime/wrapper duplication.
|
|
77
|
+
* The file lists every data space of the DLO (sorted by name); the DLO must belong to the run's
|
|
78
|
+
* data space, otherwise UNSUPPORTED_DLO_DATASPACE.
|
|
79
|
+
* @param {unknown} value Native API GET or write response.
|
|
80
|
+
* @param {string} dataSpace The run's data space.
|
|
81
|
+
* @param {DocumentMode} [mode] `retrieve` keeps values the plugin cannot deploy as returned.
|
|
82
|
+
* @returns {DloDocument} Portable document with observed membership.
|
|
83
|
+
*/
|
|
84
|
+
export declare function normalizeDlo(value: unknown, dataSpace: string, mode?: DocumentMode): DloDocument;
|
|
85
|
+
/**
|
|
86
|
+
* The portable document of a native DLO object with every data space it lists, whichever they
|
|
87
|
+
* are; normalizeDlo also requires the run's data space.
|
|
88
|
+
* @param {unknown} value Native API GET or write response.
|
|
89
|
+
* @param {DocumentMode} [mode] `retrieve` keeps values the plugin cannot deploy as returned.
|
|
90
|
+
* @returns {DloDocument} Portable document with observed membership.
|
|
91
|
+
*/
|
|
92
|
+
export declare function projectDlo(value: unknown, mode?: DocumentMode): DloDocument;
|
|
93
|
+
export { dloName } from './path-selector.js';
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { dloName } from './path-selector.js';
|
|
2
|
+
import { explainInput, printableKey } from '../services/operation-diagnostic.js';
|
|
3
|
+
import { dataSpaceKey, isDataSpaceName, readDataSpaceList, refuseLegacyDataSpace, sortedDataSpaces, } from './data-space-field.js';
|
|
4
|
+
/** Payload-free native DLO refusal, with an authoritative HTTP status when available. */
|
|
5
|
+
export class DloError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
status;
|
|
8
|
+
constructor(code, status) {
|
|
9
|
+
super(`Native DLO operation refused: ${code}.`);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.name = 'DloError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const fieldName = /^[A-Za-z][A-Za-z0-9_]{0,239}__c$/u;
|
|
16
|
+
const runtimeFieldKeys = new Set(['id', 'recordId', 'recordID', 'createdDate', 'lastModifiedDate']);
|
|
17
|
+
/**
|
|
18
|
+
* Require a plain JSON object.
|
|
19
|
+
* @param {unknown} value Untrusted input.
|
|
20
|
+
* @returns {Record<string, unknown>} Object content.
|
|
21
|
+
*/
|
|
22
|
+
function record(value) {
|
|
23
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
24
|
+
throw new DloError('INVALID_DLO_DOCUMENT');
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Refuse an authored DLO file, naming the key path that cannot be deployed.
|
|
29
|
+
* @param {string} code Refusal code.
|
|
30
|
+
* @param {string} keyPath Printable key path.
|
|
31
|
+
* @param {string} problem What is wrong with it.
|
|
32
|
+
* @returns {DloError} Refusal with an explanation.
|
|
33
|
+
*/
|
|
34
|
+
function refuse(code, keyPath, problem) {
|
|
35
|
+
return explainInput(new DloError(code), `The DLO file cannot be deployed: ${keyPath} ${problem}. Correct the file, or retrieve the DLO again once the plugin supports it.`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Require a plain JSON object at a key path of the file.
|
|
39
|
+
* @param {unknown} value Untrusted input.
|
|
40
|
+
* @param {string} keyPath Printable key path.
|
|
41
|
+
* @returns {Record<string, unknown>} Object content.
|
|
42
|
+
*/
|
|
43
|
+
function objectAt(value, keyPath) {
|
|
44
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
45
|
+
throw refuse('INVALID_DLO_DOCUMENT', keyPath, 'must be an object');
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Refuse a key outside the given set and a missing required key.
|
|
50
|
+
* @param {Record<string, unknown>} value Object of the file.
|
|
51
|
+
* @param {string} prefix Key path of the object, with a trailing dot (empty at the top).
|
|
52
|
+
* @param {string[]} required Keys it must hold.
|
|
53
|
+
* @param {string[]} [optional] Keys it may hold.
|
|
54
|
+
* @param {string} [code] Refusal code.
|
|
55
|
+
*/
|
|
56
|
+
function closedKeys(value, prefix, required, optional = [], code = 'INVALID_DLO_DOCUMENT') {
|
|
57
|
+
for (const key of Object.keys(value))
|
|
58
|
+
if (!required.includes(key) && !optional.includes(key))
|
|
59
|
+
throw refuse(code, `${prefix}${printableKey(key)}`, 'is not a key a DLO file can hold');
|
|
60
|
+
for (const key of required)
|
|
61
|
+
if (!Object.hasOwn(value, key))
|
|
62
|
+
throw refuse(code, `${prefix}${key}`, 'is missing');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validate a native DLO document without losing additional field definitions. Deploy mode (the
|
|
66
|
+
* default) admits only what a deploy can send and names the first offending key path; retrieve
|
|
67
|
+
* mode keeps what the org returned and checks only what names and places the file.
|
|
68
|
+
* @param {unknown} value Untrusted saved document.
|
|
69
|
+
* @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (lenient).
|
|
70
|
+
* @returns {DloDocument} Checked document.
|
|
71
|
+
*/
|
|
72
|
+
export function validateDloDocument(value, mode = 'deploy') {
|
|
73
|
+
const document = objectAt(value, 'the document');
|
|
74
|
+
const identity = objectAt(document.identity, 'identity');
|
|
75
|
+
const spec = objectAt(document.spec, 'spec');
|
|
76
|
+
if (document.schemaVersion !== 1)
|
|
77
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'schemaVersion', 'must be 1');
|
|
78
|
+
if (document.kind !== 'dlo')
|
|
79
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'kind', 'must be "dlo"');
|
|
80
|
+
if (typeof identity.apiName !== 'string' || !dloName.test(identity.apiName))
|
|
81
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'identity.apiName', 'must be a DLO API name ending in __dll');
|
|
82
|
+
refuseLegacyDataSpace(identity, refuse);
|
|
83
|
+
readDataSpaceList(document, refuse);
|
|
84
|
+
if (!Array.isArray(spec.fields))
|
|
85
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'spec.fields', 'must be a list of fields');
|
|
86
|
+
const fields = spec.fields.map((field, index) => objectAt(field, `spec.fields[${index}]`));
|
|
87
|
+
if (mode === 'retrieve')
|
|
88
|
+
return structuredClone(value);
|
|
89
|
+
closedKeys(document, '', [dataSpaceKey, 'identity', 'kind', 'schemaVersion', 'spec']);
|
|
90
|
+
closedKeys(identity, 'identity.', ['apiName']);
|
|
91
|
+
closedKeys(spec, 'spec.', ['category', 'fields', 'label'], ['eventDateTimeFieldName', 'recordModifiedFieldName']);
|
|
92
|
+
for (const key of ['eventDateTimeFieldName', 'recordModifiedFieldName']) {
|
|
93
|
+
const named = spec[key];
|
|
94
|
+
if (Object.hasOwn(spec, key) && (typeof named !== 'string' || !fieldName.test(named)))
|
|
95
|
+
throw refuse('INVALID_DLO_DOCUMENT', `spec.${key}`, 'must be a field API name ending in __c');
|
|
96
|
+
}
|
|
97
|
+
if (typeof spec.label !== 'string' || !spec.label.trim() || spec.label.length > 40)
|
|
98
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'spec.label', 'must be a text of 1 to 40 characters');
|
|
99
|
+
if (typeof spec.category !== 'string' || !spec.category)
|
|
100
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'spec.category', 'must be a category name');
|
|
101
|
+
if (fields.length === 0)
|
|
102
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'spec.fields', 'must list at least one field');
|
|
103
|
+
const names = new Set();
|
|
104
|
+
for (const [index, field] of fields.entries()) {
|
|
105
|
+
const at = `spec.fields[${index}]`;
|
|
106
|
+
const runtime = Object.keys(field).find((key) => runtimeFieldKeys.has(key));
|
|
107
|
+
if (runtime !== undefined)
|
|
108
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.${runtime}`, 'is not a key a DLO file can hold');
|
|
109
|
+
if (typeof field.name !== 'string' || !fieldName.test(field.name))
|
|
110
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.name`, 'must be a field API name ending in __c');
|
|
111
|
+
if (names.has(field.name.toLowerCase()))
|
|
112
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.name`, 'repeats the name of another field');
|
|
113
|
+
if (typeof field.label !== 'string' || !field.label)
|
|
114
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.label`, 'must be a non-empty text');
|
|
115
|
+
if (typeof field.dataType !== 'string' || !field.dataType)
|
|
116
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.dataType`, 'must be a data type name');
|
|
117
|
+
if (typeof field.isPrimaryKey !== 'boolean')
|
|
118
|
+
throw refuse('INVALID_DLO_FIELD', `${at}.isPrimaryKey`, 'must be true or false');
|
|
119
|
+
names.add(field.name.toLowerCase());
|
|
120
|
+
}
|
|
121
|
+
const keys = fields.filter((field) => field.isPrimaryKey === true).length;
|
|
122
|
+
if (keys !== 1)
|
|
123
|
+
throw refuse('INVALID_DLO_PRIMARY_KEY', 'spec.fields', `marks ${keys} fields as isPrimaryKey; a DLO deploy needs exactly one`);
|
|
124
|
+
// The event field has to name one of the listed fields exactly.
|
|
125
|
+
if (spec.eventDateTimeFieldName !== undefined &&
|
|
126
|
+
!fields.some((field) => field.name === spec.eventDateTimeFieldName))
|
|
127
|
+
throw refuse('INVALID_DLO_DOCUMENT', 'spec.eventDateTimeFieldName', 'must name a listed field');
|
|
128
|
+
return structuredClone(value);
|
|
129
|
+
}
|
|
130
|
+
/** Fields Salesforce adds to a data lake object itself. */
|
|
131
|
+
export const dloSystemFields = new Set([
|
|
132
|
+
'cdp_sys_SourceVersion__c',
|
|
133
|
+
// Engagement DLOs: Salesforce adds it with the event field.
|
|
134
|
+
'cdp_sys_PartitionDate__c',
|
|
135
|
+
'DataSource__c',
|
|
136
|
+
'DataSourceObject__c',
|
|
137
|
+
'InternalOrganization__c',
|
|
138
|
+
]);
|
|
139
|
+
/**
|
|
140
|
+
* Whether a field of an existing DLO is one Salesforce generated: a system field or a key
|
|
141
|
+
* qualifier `KQ_<Name>__c` of another field of the same DLO (Salesforce adds one for the primary
|
|
142
|
+
* key on create, and one for a field that a relationship uses as its source, live API 68), never a
|
|
143
|
+
* primary key or a custom field. A deploy keeps such a field when the file leaves it out, and a
|
|
144
|
+
* retrieve leaves it out; both use this one predicate.
|
|
145
|
+
* @param {DloField} field Field of the DLO.
|
|
146
|
+
* @param {DloField[]} fields Every field of the same DLO.
|
|
147
|
+
* @returns {boolean} Whether the field is generated, not authored.
|
|
148
|
+
*/
|
|
149
|
+
export function isGeneratedDloField(field, fields) {
|
|
150
|
+
if (field.isPrimaryKey || field.creationType === 'Custom')
|
|
151
|
+
return false;
|
|
152
|
+
return (dloSystemFields.has(field.name) ||
|
|
153
|
+
fields.some((other) => other !== field && field.name === `KQ_${other.name}`));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Keep the authored content of a DLO definition: generated fields are left out, except a field
|
|
157
|
+
* the event field or the record-modified field names, which the document has to list.
|
|
158
|
+
* @param {DloDocument} document Complete definition as read.
|
|
159
|
+
* @returns {DloDocument} Independent copy without generated fields.
|
|
160
|
+
*/
|
|
161
|
+
export function leanDloDocument(document) {
|
|
162
|
+
const lean = structuredClone(document);
|
|
163
|
+
lean.spec.fields = document.spec.fields.filter((field) => field.name === document.spec.eventDateTimeFieldName ||
|
|
164
|
+
field.name === document.spec.recordModifiedFieldName ||
|
|
165
|
+
!isGeneratedDloField(field, document.spec.fields));
|
|
166
|
+
return lean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Unwrap exactly one native GET object or a POST/PATCH single-object response.
|
|
170
|
+
* @param {unknown} value Native response.
|
|
171
|
+
* @returns {Record<string, unknown>} Single native object with target runtime identity retained.
|
|
172
|
+
*/
|
|
173
|
+
export function unwrapDlo(value) {
|
|
174
|
+
const response = record(value);
|
|
175
|
+
if (!Object.hasOwn(response, 'dataLakeObjects'))
|
|
176
|
+
return response;
|
|
177
|
+
if (!Array.isArray(response.dataLakeObjects) || response.dataLakeObjects.length !== 1)
|
|
178
|
+
throw new DloError('AMBIGUOUS_DLO_RESPONSE');
|
|
179
|
+
return record(response.dataLakeObjects[0]);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The data spaces a native DLO object lists in `dataSpaceInfo[].name`, sorted; a missing, empty
|
|
183
|
+
* or unusable list is UNSUPPORTED_DLO_DATASPACE.
|
|
184
|
+
* @param {Record<string, unknown>} object Native DLO object.
|
|
185
|
+
* @returns {string[]} Its data spaces.
|
|
186
|
+
*/
|
|
187
|
+
export function dloDataSpaces(object) {
|
|
188
|
+
if (!Array.isArray(object.dataSpaceInfo) || object.dataSpaceInfo.length === 0)
|
|
189
|
+
throw new DloError('UNSUPPORTED_DLO_DATASPACE');
|
|
190
|
+
// A membership with more than its name and label (a record filter, for example) is a shape the
|
|
191
|
+
// plugin does not model; it is never dropped silently (retrieve writes the DLO as-is).
|
|
192
|
+
if (object.dataSpaceInfo.some((entry) => entry &&
|
|
193
|
+
typeof entry === 'object' &&
|
|
194
|
+
Object.keys(entry).some((key) => key !== 'name' && key !== 'label')))
|
|
195
|
+
throw new DloError('UNSUPPORTED_DLO_MEMBERSHIP');
|
|
196
|
+
const memberships = object.dataSpaceInfo.map((entry) => entry && typeof entry === 'object' ? entry.name : undefined);
|
|
197
|
+
if (!memberships.every((name) => isDataSpaceName(name)))
|
|
198
|
+
throw new DloError('UNSUPPORTED_DLO_DATASPACE');
|
|
199
|
+
return sortedDataSpaces(memberships);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Save definition fields, including generated fields, without runtime/wrapper duplication.
|
|
203
|
+
* The file lists every data space of the DLO (sorted by name); the DLO must belong to the run's
|
|
204
|
+
* data space, otherwise UNSUPPORTED_DLO_DATASPACE.
|
|
205
|
+
* @param {unknown} value Native API GET or write response.
|
|
206
|
+
* @param {string} dataSpace The run's data space.
|
|
207
|
+
* @param {DocumentMode} [mode] `retrieve` keeps values the plugin cannot deploy as returned.
|
|
208
|
+
* @returns {DloDocument} Portable document with observed membership.
|
|
209
|
+
*/
|
|
210
|
+
export function normalizeDlo(value, dataSpace, mode = 'deploy') {
|
|
211
|
+
const document = projectDlo(value, mode);
|
|
212
|
+
if (!document.c__dataSpace.includes(dataSpace))
|
|
213
|
+
throw new DloError('UNSUPPORTED_DLO_DATASPACE');
|
|
214
|
+
return document;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The portable document of a native DLO object with every data space it lists, whichever they
|
|
218
|
+
* are; normalizeDlo also requires the run's data space.
|
|
219
|
+
* @param {unknown} value Native API GET or write response.
|
|
220
|
+
* @param {DocumentMode} [mode] `retrieve` keeps values the plugin cannot deploy as returned.
|
|
221
|
+
* @returns {DloDocument} Portable document with observed membership.
|
|
222
|
+
*/
|
|
223
|
+
export function projectDlo(value, mode = 'deploy') {
|
|
224
|
+
const object = unwrapDlo(value);
|
|
225
|
+
const memberships = dloDataSpaces(object);
|
|
226
|
+
const fields = object.dataLakeFieldInfoRepresentation ?? object.fields;
|
|
227
|
+
if (!Array.isArray(fields))
|
|
228
|
+
throw new DloError('INVALID_DLO_RESPONSE');
|
|
229
|
+
return validateDloDocument({
|
|
230
|
+
schemaVersion: 1,
|
|
231
|
+
kind: 'dlo',
|
|
232
|
+
[dataSpaceKey]: memberships,
|
|
233
|
+
identity: { apiName: object.name },
|
|
234
|
+
spec: {
|
|
235
|
+
label: object.label,
|
|
236
|
+
category: object.category,
|
|
237
|
+
...(typeof object.eventDateTimeFieldName === 'string' ||
|
|
238
|
+
(mode === 'retrieve' &&
|
|
239
|
+
object.eventDateTimeFieldName !== undefined &&
|
|
240
|
+
object.eventDateTimeFieldName !== null)
|
|
241
|
+
? { eventDateTimeFieldName: object.eventDateTimeFieldName }
|
|
242
|
+
: {}),
|
|
243
|
+
...(typeof object.recordModifiedFieldName === 'string' ||
|
|
244
|
+
(mode === 'retrieve' &&
|
|
245
|
+
object.recordModifiedFieldName !== undefined &&
|
|
246
|
+
object.recordModifiedFieldName !== null)
|
|
247
|
+
? { recordModifiedFieldName: object.recordModifiedFieldName }
|
|
248
|
+
: {}),
|
|
249
|
+
fields: fields.map((field) => Object.fromEntries(Object.entries(record(field)).filter(([key]) => !runtimeFieldKeys.has(key)))),
|
|
250
|
+
},
|
|
251
|
+
}, mode);
|
|
252
|
+
}
|
|
253
|
+
export { dloName } from './path-selector.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether two values name the same enum value: text ignoring letter case, anything else exactly.
|
|
3
|
+
* @param {unknown} left One value.
|
|
4
|
+
* @param {unknown} right The other value.
|
|
5
|
+
* @returns {boolean} Whether both are the same value.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sameEnum(left: unknown, right: unknown): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The comparison form of an enum value: text in upper case, anything else unchanged.
|
|
10
|
+
* @param {unknown} value Enum value.
|
|
11
|
+
* @returns {unknown} Value for comparison only, never sent.
|
|
12
|
+
*/
|
|
13
|
+
export declare function enumKey(value: unknown): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Whether one property holds the same value on both sides; the keys in `enumKeys` ignore case.
|
|
16
|
+
* @param {string} key Property name.
|
|
17
|
+
* @param {unknown} left One value.
|
|
18
|
+
* @param {unknown} right The other value.
|
|
19
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
20
|
+
* @returns {boolean} Whether the property is unchanged.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sameProperty(key: string, left: unknown, right: unknown, enumKeys: ReadonlySet<string>): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether two flat records hold the same values: the union of their keys compared with
|
|
25
|
+
* {@link sameProperty}.
|
|
26
|
+
* @param {Record<string, unknown>} left One record.
|
|
27
|
+
* @param {Record<string, unknown>} right The other record.
|
|
28
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
29
|
+
* @returns {boolean} Whether both records are the same.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sameRecord(left: Record<string, unknown>, right: Record<string, unknown>, enumKeys: ReadonlySet<string>): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* A deep copy for comparison only, in which every text value under a key in `enumKeys` (at any
|
|
34
|
+
* depth) is in upper case. Other values, and keys outside `enumKeys`, stay as they are.
|
|
35
|
+
* @param {unknown} value JSON value.
|
|
36
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
37
|
+
* @returns {unknown} Comparison copy, never sent.
|
|
38
|
+
*/
|
|
39
|
+
export declare function foldEnums(value: unknown, enumKeys: ReadonlySet<string>): unknown;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
/*
|
|
3
|
+
* Salesforce stores several enum values in its own letter case (a DLO category `other` reads
|
|
4
|
+
* `Other`, a field type `text` reads `Text`, a transform `fullRunFrequency` `Daily` reads `DAILY`;
|
|
5
|
+
* live API 68). Deploy sends the value as authored, and the unchanged comparison treats values
|
|
6
|
+
* that differ only in letter case as equal, so a hand-written file deploys unchanged the second
|
|
7
|
+
* time. Retrieve keeps Salesforce's spelling. Names, labels, SQL, formulas and free text are
|
|
8
|
+
* never compared this way.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Whether two values name the same enum value: text ignoring letter case, anything else exactly.
|
|
12
|
+
* @param {unknown} left One value.
|
|
13
|
+
* @param {unknown} right The other value.
|
|
14
|
+
* @returns {boolean} Whether both are the same value.
|
|
15
|
+
*/
|
|
16
|
+
export function sameEnum(left, right) {
|
|
17
|
+
return typeof left === 'string' && typeof right === 'string'
|
|
18
|
+
? left.toUpperCase() === right.toUpperCase()
|
|
19
|
+
: isDeepStrictEqual(left, right);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The comparison form of an enum value: text in upper case, anything else unchanged.
|
|
23
|
+
* @param {unknown} value Enum value.
|
|
24
|
+
* @returns {unknown} Value for comparison only, never sent.
|
|
25
|
+
*/
|
|
26
|
+
export function enumKey(value) {
|
|
27
|
+
return typeof value === 'string' ? value.toUpperCase() : value;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether one property holds the same value on both sides; the keys in `enumKeys` ignore case.
|
|
31
|
+
* @param {string} key Property name.
|
|
32
|
+
* @param {unknown} left One value.
|
|
33
|
+
* @param {unknown} right The other value.
|
|
34
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
35
|
+
* @returns {boolean} Whether the property is unchanged.
|
|
36
|
+
*/
|
|
37
|
+
export function sameProperty(key, left, right, enumKeys) {
|
|
38
|
+
return enumKeys.has(key) ? sameEnum(left, right) : isDeepStrictEqual(left, right);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether two flat records hold the same values: the union of their keys compared with
|
|
42
|
+
* {@link sameProperty}.
|
|
43
|
+
* @param {Record<string, unknown>} left One record.
|
|
44
|
+
* @param {Record<string, unknown>} right The other record.
|
|
45
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
46
|
+
* @returns {boolean} Whether both records are the same.
|
|
47
|
+
*/
|
|
48
|
+
export function sameRecord(left, right, enumKeys) {
|
|
49
|
+
return [...new Set([...Object.keys(left), ...Object.keys(right)])].every((key) => sameProperty(key, left[key], right[key], enumKeys));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A deep copy for comparison only, in which every text value under a key in `enumKeys` (at any
|
|
53
|
+
* depth) is in upper case. Other values, and keys outside `enumKeys`, stay as they are.
|
|
54
|
+
* @param {unknown} value JSON value.
|
|
55
|
+
* @param {ReadonlySet<string>} enumKeys Properties that hold enum values.
|
|
56
|
+
* @returns {unknown} Comparison copy, never sent.
|
|
57
|
+
*/
|
|
58
|
+
export function foldEnums(value, enumKeys) {
|
|
59
|
+
if (Array.isArray(value))
|
|
60
|
+
return value.map((entry) => foldEnums(entry, enumKeys));
|
|
61
|
+
if (!value || typeof value !== 'object')
|
|
62
|
+
return value;
|
|
63
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
64
|
+
key,
|
|
65
|
+
enumKeys.has(key) && typeof entry === 'string' ? enumKey(entry) : foldEnums(entry, enumKeys),
|
|
66
|
+
]));
|
|
67
|
+
}
|