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
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { DmoDocument, DmoField } from './dmo-document.js';
|
|
2
|
-
export type DmoUpdatePatch = {
|
|
3
|
-
label?: string;
|
|
4
|
-
description?: string;
|
|
5
|
-
fields?: Array<Pick<DmoField, 'name' | 'label' | 'dataType' | 'description' | 'category'>>;
|
|
6
|
-
};
|
|
7
|
-
export type DmoUpdateDelta = {
|
|
8
|
-
status: 'blocked';
|
|
9
|
-
blockers: string[];
|
|
10
|
-
} | {
|
|
11
|
-
status: 'unchanged';
|
|
12
|
-
blockers: [];
|
|
13
|
-
expected: DmoDocument;
|
|
14
|
-
} | {
|
|
15
|
-
status: 'candidate';
|
|
16
|
-
blockers: [];
|
|
17
|
-
patch: DmoUpdatePatch;
|
|
18
|
-
expected: DmoDocument;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Build an offline PATCH contract candidate, never execution authorization.
|
|
22
|
-
* Current must already be qualified by the caller; authored JSON alone is not org evidence.
|
|
23
|
-
* @param {unknown} desired Authored desired document.
|
|
24
|
-
* @param {unknown} current Qualified current authored document.
|
|
25
|
-
* @param {unknown} targetDataSpace Explicit default binding.
|
|
26
|
-
* @returns {DmoUpdateDelta} Atomic candidate/overlay or payload-free blockers only.
|
|
27
|
-
*/
|
|
28
|
-
export declare function buildDmoUpdateDelta(desired: unknown, current: unknown, targetDataSpace: unknown): DmoUpdateDelta;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { validateDmoDocument } from './dmo-document.js';
|
|
2
|
-
/**
|
|
3
|
-
* Build an offline PATCH contract candidate, never execution authorization.
|
|
4
|
-
* Current must already be qualified by the caller; authored JSON alone is not org evidence.
|
|
5
|
-
* @param {unknown} desired Authored desired document.
|
|
6
|
-
* @param {unknown} current Qualified current authored document.
|
|
7
|
-
* @param {unknown} targetDataSpace Explicit default binding.
|
|
8
|
-
* @returns {DmoUpdateDelta} Atomic candidate/overlay or payload-free blockers only.
|
|
9
|
-
*/
|
|
10
|
-
export function buildDmoUpdateDelta(desired, current, targetDataSpace) {
|
|
11
|
-
const source = validateDmoDocument(desired);
|
|
12
|
-
const target = validateDmoDocument(current);
|
|
13
|
-
if (targetDataSpace !== 'default' ||
|
|
14
|
-
source.identity.dataSpace !== 'default' ||
|
|
15
|
-
target.identity.dataSpace !== 'default')
|
|
16
|
-
return { status: 'blocked', blockers: ['INVALID_SCOPE'] };
|
|
17
|
-
if (source.identity.apiName !== target.identity.apiName)
|
|
18
|
-
return { status: 'blocked', blockers: ['OBJECT_IDENTITY_CHANGED'] };
|
|
19
|
-
const blockers = new Set();
|
|
20
|
-
const patch = {};
|
|
21
|
-
const expected = structuredClone(target);
|
|
22
|
-
if (source.spec.category !== target.spec.category)
|
|
23
|
-
blockers.add('CATEGORY_CHANGED');
|
|
24
|
-
for (const key of ['eventDateTimeFieldName', 'recordModifiedFieldName'])
|
|
25
|
-
if (source.spec[key] !== target.spec[key])
|
|
26
|
-
blockers.add('DATE_DESIGNATION_CHANGED');
|
|
27
|
-
if (source.spec.label !== target.spec.label) {
|
|
28
|
-
patch.label = source.spec.label;
|
|
29
|
-
expected.spec.label = source.spec.label;
|
|
30
|
-
}
|
|
31
|
-
if ('description' in source.spec && source.spec.description !== target.spec.description) {
|
|
32
|
-
if (source.spec.description?.trim()) {
|
|
33
|
-
patch.description = source.spec.description;
|
|
34
|
-
expected.spec.description = source.spec.description;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
blockers.add('DESCRIPTION_CLEAR_UNPROVEN');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const existing = new Map(expected.spec.fields.map((field) => [field.name, field]));
|
|
41
|
-
const foldedNames = new Set(target.spec.fields.map((field) => field.name.toLowerCase()));
|
|
42
|
-
const changes = [];
|
|
43
|
-
// Sort a fresh array so candidate order does not depend on the desired field order.
|
|
44
|
-
// eslint-disable-next-line unicorn/no-array-sort -- The configured TypeScript target lacks toSorted.
|
|
45
|
-
const fields = [...source.spec.fields].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
46
|
-
for (const field of fields) {
|
|
47
|
-
const prior = existing.get(field.name);
|
|
48
|
-
if (!prior) {
|
|
49
|
-
if (foldedNames.has(field.name.toLowerCase()))
|
|
50
|
-
blockers.add('FIELD_IDENTITY_CHANGED');
|
|
51
|
-
if (field.isPrimaryKey || field.isDynamicLookup)
|
|
52
|
-
blockers.add('NEW_FIELD_FLAGS_UNSUPPORTED');
|
|
53
|
-
if ('description' in field && !field.description?.trim())
|
|
54
|
-
blockers.add('DESCRIPTION_CLEAR_UNPROVEN');
|
|
55
|
-
const addition = {
|
|
56
|
-
name: field.name,
|
|
57
|
-
label: field.label,
|
|
58
|
-
dataType: field.dataType,
|
|
59
|
-
...('description' in field ? { description: field.description } : {}),
|
|
60
|
-
...('category' in field ? { category: field.category } : {}),
|
|
61
|
-
};
|
|
62
|
-
changes.push(addition);
|
|
63
|
-
expected.spec.fields.push(structuredClone(field));
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (field.dataType !== prior.dataType ||
|
|
67
|
-
field.isPrimaryKey !== prior.isPrimaryKey ||
|
|
68
|
-
field.isDynamicLookup !== prior.isDynamicLookup ||
|
|
69
|
-
field.category !== prior.category ||
|
|
70
|
-
'category' in field !== 'category' in prior ||
|
|
71
|
-
('description' in field && field.description !== prior.description))
|
|
72
|
-
blockers.add('FIELD_CONFIGURATION_UNSUPPORTED');
|
|
73
|
-
if (field.label !== prior.label) {
|
|
74
|
-
// Provisional field-label contract: exact name and unchanged dataType identify the field.
|
|
75
|
-
changes.push({ name: field.name, label: field.label, dataType: field.dataType });
|
|
76
|
-
prior.label = field.label;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (blockers.size > 0)
|
|
80
|
-
return { status: 'blocked', blockers: [...blockers] };
|
|
81
|
-
if (changes.length > 0)
|
|
82
|
-
patch.fields = changes;
|
|
83
|
-
if (Object.keys(patch).length === 0)
|
|
84
|
-
return { status: 'unchanged', blockers: [], expected };
|
|
85
|
-
return { status: 'candidate', blockers: [], patch, expected };
|
|
86
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Payload-free filesystem refusals, including failed atomic publication. */
|
|
2
|
-
export declare class DmoWriteError extends Error {
|
|
3
|
-
readonly code: 'UNSAFE_PATH' | 'OVERWRITE_REQUIRED' | 'OUTPUT_FAILED';
|
|
4
|
-
constructor(code: 'UNSAFE_PATH' | 'OVERWRITE_REQUIRED' | 'OUTPUT_FAILED');
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Publish only independently validated authored DMO/default JSON, with atomic file visibility.
|
|
8
|
-
* Staging is retained in owned OS temp; cross-volume atomic publication fails closed.
|
|
9
|
-
* @param {unknown} value Authored candidate, never the runtime projection.
|
|
10
|
-
* @param {string} projectRoot Output project root (the CLI supplies cwd when omitted).
|
|
11
|
-
* @param {boolean} overwrite Permit replacing differing existing regular-file bytes.
|
|
12
|
-
* @returns {Promise<{ path: string; outcome: 'retrieved' | 'unchanged' }>} Exact path and outcome.
|
|
13
|
-
*/
|
|
14
|
-
export declare function writeDmoDocument(value: unknown, projectRoot: string, overwrite: boolean): Promise<{
|
|
15
|
-
path: string;
|
|
16
|
-
outcome: 'retrieved' | 'unchanged';
|
|
17
|
-
}>;
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { lstat, mkdir, mkdtemp, open, readFile, realpath, rename, link, unlink, } from 'node:fs/promises';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { buildDmoCreateRequestFromDocument, serializeDmoDocument, validateDmoDocument, } from './dmo-document.js';
|
|
6
|
-
/** Payload-free filesystem refusals, including failed atomic publication. */
|
|
7
|
-
export class DmoWriteError extends Error {
|
|
8
|
-
code;
|
|
9
|
-
constructor(code) {
|
|
10
|
-
super('DMO output could not be completed; inspect the selected destination before retrying.');
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.name = 'DmoWriteError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Check every existing ancestor without following links, creating directories one at a time.
|
|
17
|
-
* @param {string} directory Absolute directory to validate or create.
|
|
18
|
-
* @returns {Promise<void>} Resolves only for a real directory chain.
|
|
19
|
-
*/
|
|
20
|
-
async function ensureDirectory(directory) {
|
|
21
|
-
const parent = path.dirname(directory);
|
|
22
|
-
if (parent !== directory)
|
|
23
|
-
await ensureDirectory(parent);
|
|
24
|
-
try {
|
|
25
|
-
await lstat(directory);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
if (error.code !== 'ENOENT')
|
|
29
|
-
throw error;
|
|
30
|
-
try {
|
|
31
|
-
await mkdir(directory);
|
|
32
|
-
}
|
|
33
|
-
catch (creationError) {
|
|
34
|
-
if (creationError.code !== 'EEXIST')
|
|
35
|
-
throw creationError;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const stat = await lstat(directory);
|
|
39
|
-
const actual = path.resolve(await realpath(directory));
|
|
40
|
-
const matches = process.platform === 'win32'
|
|
41
|
-
? actual.toLowerCase() === directory.toLowerCase()
|
|
42
|
-
: actual === directory;
|
|
43
|
-
if (stat.isSymbolicLink() || !stat.isDirectory() || !matches)
|
|
44
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Read only an existing regular file, never a directory or link.
|
|
48
|
-
* @param {string} file Exact destination.
|
|
49
|
-
* @returns {Promise<Buffer | undefined>} Existing bytes or explicit absence.
|
|
50
|
-
*/
|
|
51
|
-
async function existingBytes(file) {
|
|
52
|
-
try {
|
|
53
|
-
const stat = await lstat(file);
|
|
54
|
-
if (stat.isSymbolicLink() || !stat.isFile())
|
|
55
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
56
|
-
return await readFile(file);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (error.code === 'ENOENT')
|
|
60
|
-
return undefined;
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Publish only independently validated authored DMO/default JSON, with atomic file visibility.
|
|
66
|
-
* Staging is retained in owned OS temp; cross-volume atomic publication fails closed.
|
|
67
|
-
* @param {unknown} value Authored candidate, never the runtime projection.
|
|
68
|
-
* @param {string} projectRoot Output project root (the CLI supplies cwd when omitted).
|
|
69
|
-
* @param {boolean} overwrite Permit replacing differing existing regular-file bytes.
|
|
70
|
-
* @returns {Promise<{ path: string; outcome: 'retrieved' | 'unchanged' }>} Exact path and outcome.
|
|
71
|
-
*/
|
|
72
|
-
export async function writeDmoDocument(value, projectRoot, overwrite) {
|
|
73
|
-
// Validate the standalone candidate independently before any filesystem side effect.
|
|
74
|
-
buildDmoCreateRequestFromDocument(value, 'default');
|
|
75
|
-
const document = validateDmoDocument(value);
|
|
76
|
-
const bytes = Buffer.from(serializeDmoDocument(document), 'utf8');
|
|
77
|
-
if (!projectRoot.trim())
|
|
78
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
79
|
-
const root = path.resolve(projectRoot);
|
|
80
|
-
const destination = path.join(root, 'data360', 'default', 'dmo', `${document.identity.apiName}.json`);
|
|
81
|
-
const relative = path.relative(root, destination);
|
|
82
|
-
if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
|
|
83
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
84
|
-
try {
|
|
85
|
-
await ensureDirectory(path.dirname(destination));
|
|
86
|
-
const previous = await existingBytes(destination);
|
|
87
|
-
if (previous?.equals(bytes))
|
|
88
|
-
return { path: destination, outcome: 'unchanged' };
|
|
89
|
-
if (previous && !overwrite)
|
|
90
|
-
throw new DmoWriteError('OVERWRITE_REQUIRED');
|
|
91
|
-
// Stage complete flushed bytes under the verified OS temp directory, never beside user files.
|
|
92
|
-
if (process.platform === 'win32') {
|
|
93
|
-
for (const value of [
|
|
94
|
-
process.env.TEMP,
|
|
95
|
-
os.tmpdir(),
|
|
96
|
-
process.env.TMP,
|
|
97
|
-
process.env.TMPDIR,
|
|
98
|
-
].filter((entry) => entry !== undefined && entry !== '')) {
|
|
99
|
-
if (!path.isAbsolute(value) ||
|
|
100
|
-
path
|
|
101
|
-
.resolve(value)
|
|
102
|
-
.replace(/[\\/]+$/u, '')
|
|
103
|
-
.toLowerCase() !== String.raw `f:\temp`)
|
|
104
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
105
|
-
}
|
|
106
|
-
if (!process.env.TEMP)
|
|
107
|
-
throw new DmoWriteError('UNSAFE_PATH');
|
|
108
|
-
}
|
|
109
|
-
const stagingRoot = await mkdtemp(path.join(os.tmpdir(), 'data360-output-'));
|
|
110
|
-
const staged = await open(path.join(stagingRoot, 'document.json'), 'wx');
|
|
111
|
-
try {
|
|
112
|
-
await staged.writeFile(bytes);
|
|
113
|
-
await staged.sync();
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
await staged.close();
|
|
117
|
-
}
|
|
118
|
-
const marker = await open(path.join(stagingRoot, 'ownership'), 'wx');
|
|
119
|
-
await marker.writeFile(randomUUID());
|
|
120
|
-
await marker.close();
|
|
121
|
-
// Recheck the chain and observed bytes immediately before publication; no snapshot guarantee.
|
|
122
|
-
await ensureDirectory(path.dirname(destination));
|
|
123
|
-
const current = await existingBytes(destination);
|
|
124
|
-
if (previous === undefined ? current !== undefined : !current?.equals(previous))
|
|
125
|
-
throw new DmoWriteError('OUTPUT_FAILED');
|
|
126
|
-
if (previous)
|
|
127
|
-
await rename(path.join(stagingRoot, 'document.json'), destination);
|
|
128
|
-
else {
|
|
129
|
-
await link(path.join(stagingRoot, 'document.json'), destination);
|
|
130
|
-
// Remove only this run-created file entry so retained staging cannot alter published bytes.
|
|
131
|
-
await unlink(path.join(stagingRoot, 'document.json'));
|
|
132
|
-
}
|
|
133
|
-
return { path: destination, outcome: 'retrieved' };
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
if (error instanceof DmoWriteError)
|
|
137
|
-
throw error;
|
|
138
|
-
throw new DmoWriteError('OUTPUT_FAILED');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Connection } from '@salesforce/core';
|
|
2
|
-
import type { DmoDeployPreview } from './preflight-dmo-deploy.js';
|
|
3
|
-
type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'metadata' | 'getApiVersion'>;
|
|
4
|
-
export type DmoCreateExecution = {
|
|
5
|
-
outcome: 'unchanged' | 'blocked' | 'created' | 'failed';
|
|
6
|
-
mutation: 'not-attempted' | 'confirmed-created' | 'unknown';
|
|
7
|
-
preflight?: DmoDeployPreview;
|
|
8
|
-
diagnostics: Array<{
|
|
9
|
-
code: string;
|
|
10
|
-
message: string;
|
|
11
|
-
}>;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Execute one authored create after fresh absence proof; never accepts a saved preview.
|
|
15
|
-
* Snapshot validation happens synchronously before the first await. Only qualified independent
|
|
16
|
-
* readback can establish created status; HTTP failure/ambiguous response never authorizes retry.
|
|
17
|
-
* @param {unknown} document Authored-only document, not a preview or projection.
|
|
18
|
-
* @param {TargetConnection} connection Actual target connection with explicit API version.
|
|
19
|
-
* @param {unknown} apiVersion Explicit API 65.0.
|
|
20
|
-
* @param {unknown} dataSpace Explicit default data space.
|
|
21
|
-
* @returns {Promise<DmoCreateExecution>} Payload-free result retaining possible mutation evidence.
|
|
22
|
-
*/
|
|
23
|
-
export declare function executeDmoCreate(document: unknown, connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoCreateExecution>;
|
|
24
|
-
export {};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { buildDmoCreateRequestFromDocument, validateDmoDocument, } from '../artifacts/dmo-document.js';
|
|
2
|
-
import { ConnectClient } from '../transport/connect-client.js';
|
|
3
|
-
import { compareDmoMeaning, preflightDmoDeploy } from './preflight-dmo-deploy.js';
|
|
4
|
-
import { retrieveDmo } from './retrieve-other-dmo.js';
|
|
5
|
-
/**
|
|
6
|
-
* Execute one authored create after fresh absence proof; never accepts a saved preview.
|
|
7
|
-
* Snapshot validation happens synchronously before the first await. Only qualified independent
|
|
8
|
-
* readback can establish created status; HTTP failure/ambiguous response never authorizes retry.
|
|
9
|
-
* @param {unknown} document Authored-only document, not a preview or projection.
|
|
10
|
-
* @param {TargetConnection} connection Actual target connection with explicit API version.
|
|
11
|
-
* @param {unknown} apiVersion Explicit API 65.0.
|
|
12
|
-
* @param {unknown} dataSpace Explicit default data space.
|
|
13
|
-
* @returns {Promise<DmoCreateExecution>} Payload-free result retaining possible mutation evidence.
|
|
14
|
-
*/
|
|
15
|
-
export async function executeDmoCreate(document, connection, apiVersion, dataSpace) {
|
|
16
|
-
let snapshot;
|
|
17
|
-
let source;
|
|
18
|
-
let client;
|
|
19
|
-
try {
|
|
20
|
-
// Validate before serializing so accessor/toJSON payloads cannot run during snapshotting.
|
|
21
|
-
const { name, dataSpaceName, ...spec } = buildDmoCreateRequestFromDocument(document, 'default');
|
|
22
|
-
snapshot = validateDmoDocument({
|
|
23
|
-
schemaVersion: 1,
|
|
24
|
-
kind: 'dmo',
|
|
25
|
-
identity: { dataSpace: dataSpaceName, apiName: `${name}__dlm` },
|
|
26
|
-
spec,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return {
|
|
31
|
-
outcome: 'blocked',
|
|
32
|
-
mutation: 'not-attempted',
|
|
33
|
-
diagnostics: [
|
|
34
|
-
{
|
|
35
|
-
code: 'INVALID_SOURCE',
|
|
36
|
-
message: 'Supply one valid authored-only default-space DMO document.',
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
if (apiVersion !== '65.0' ||
|
|
43
|
-
dataSpace !== 'default' ||
|
|
44
|
-
connection.getApiVersion() !== apiVersion)
|
|
45
|
-
throw new Error('Invalid scope');
|
|
46
|
-
client = new ConnectClient(connection, apiVersion);
|
|
47
|
-
source = buildDmoCreateRequestFromDocument(snapshot, dataSpace);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return {
|
|
51
|
-
outcome: 'blocked',
|
|
52
|
-
mutation: 'not-attempted',
|
|
53
|
-
diagnostics: [
|
|
54
|
-
{
|
|
55
|
-
code: 'INVALID_SCOPE',
|
|
56
|
-
message: 'Use an explicit API 65.0 connection and default target data space.',
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const preflight = await preflightDmoDeploy(snapshot, connection, apiVersion, dataSpace);
|
|
62
|
-
if (preflight.outcome !== 'create' ||
|
|
63
|
-
preflight.target !== 'absent' ||
|
|
64
|
-
preflight.absenceProof !== 'complete-inventory')
|
|
65
|
-
return {
|
|
66
|
-
outcome: preflight.outcome === 'unchanged' ? 'unchanged' : 'blocked',
|
|
67
|
-
mutation: 'not-attempted',
|
|
68
|
-
preflight,
|
|
69
|
-
diagnostics: preflight.diagnostics,
|
|
70
|
-
};
|
|
71
|
-
try {
|
|
72
|
-
// The response body is deliberately not trusted or used as the readback identity.
|
|
73
|
-
await client.createDataModelObject(snapshot);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return {
|
|
77
|
-
outcome: 'failed',
|
|
78
|
-
mutation: 'unknown',
|
|
79
|
-
preflight,
|
|
80
|
-
diagnostics: [
|
|
81
|
-
{
|
|
82
|
-
code: 'CREATE_UNCONFIRMED',
|
|
83
|
-
message: 'Creation may have occurred. Inspect target state before any further attempt; no automatic retry or rollback was performed.',
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
const acquired = await retrieveDmo(connection, `${source.name}__dlm`, apiVersion, dataSpace);
|
|
90
|
-
const target = buildDmoCreateRequestFromDocument(acquired.candidate, dataSpace);
|
|
91
|
-
if (compareDmoMeaning(source, target).length > 0)
|
|
92
|
-
return {
|
|
93
|
-
outcome: 'failed',
|
|
94
|
-
mutation: 'unknown',
|
|
95
|
-
preflight,
|
|
96
|
-
diagnostics: [
|
|
97
|
-
{
|
|
98
|
-
code: 'READBACK_MISMATCH',
|
|
99
|
-
message: 'Creation may have occurred, but qualified target meaning differs. Inspect target; no retry or rollback was performed.',
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
};
|
|
103
|
-
return { outcome: 'created', mutation: 'confirmed-created', preflight, diagnostics: [] };
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
return {
|
|
107
|
-
outcome: 'failed',
|
|
108
|
-
mutation: 'unknown',
|
|
109
|
-
preflight,
|
|
110
|
-
diagnostics: [
|
|
111
|
-
{
|
|
112
|
-
code: 'READBACK_UNQUALIFIED',
|
|
113
|
-
message: 'Creation may have occurred, but independent target qualification failed. Inspect target; no retry or rollback was performed.',
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Connection } from '@salesforce/core';
|
|
2
|
-
import type { DmoCreateExecution } from './execute-dmo-create.js';
|
|
3
|
-
import type { DmoDeployPreview } from './preflight-dmo-deploy.js';
|
|
4
|
-
type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'metadata' | 'getApiVersion'>;
|
|
5
|
-
export type DmoDeployExecution = {
|
|
6
|
-
outcome: DmoCreateExecution['outcome'] | 'updated' | 'not-attempted';
|
|
7
|
-
mutation: DmoCreateExecution['mutation'] | 'confirmed-updated';
|
|
8
|
-
preflight?: DmoDeployPreview;
|
|
9
|
-
diagnostics: Array<{
|
|
10
|
-
code: string;
|
|
11
|
-
message: string;
|
|
12
|
-
}>;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Execute one internal create/unchanged/label-update operation using fresh target evidence.
|
|
16
|
-
* Public CLI intentionally continues to invoke the create-only executor.
|
|
17
|
-
* @param {unknown} document Authored document, never saved admission evidence.
|
|
18
|
-
* @param {TargetConnection} connection Explicit authenticated API 65 connection.
|
|
19
|
-
* @param {unknown} apiVersion Explicit 65.0.
|
|
20
|
-
* @param {unknown} dataSpace Explicit default space.
|
|
21
|
-
* @returns {Promise<DmoDeployExecution>} Attempt and independently confirmed outcome.
|
|
22
|
-
*/
|
|
23
|
-
export declare function executeDmoDeploy(document: unknown, connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoDeployExecution>;
|
|
24
|
-
/**
|
|
25
|
-
* Admit the complete detached selection before writes, then stop on first ambiguity or block.
|
|
26
|
-
* @param {unknown[]} documents Explicit selected authored inputs; duplicate identities are invalid.
|
|
27
|
-
* @param {TargetConnection} connection Actual target connection.
|
|
28
|
-
* @param {unknown} apiVersion Explicit API 65.0.
|
|
29
|
-
* @param {unknown} dataSpace Explicit default space.
|
|
30
|
-
* @returns {Promise<DmoDeployExecution[]>} Ordered item results, including never-attempted tail.
|
|
31
|
-
*/
|
|
32
|
-
export declare function executeDmoDeploySelection(documents: unknown[], connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoDeployExecution[]>;
|
|
33
|
-
export {};
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
-
import { buildDmoCreateRequestFromDocument, validateDmoDocument, } from '../artifacts/dmo-document.js';
|
|
3
|
-
import { ConnectClient } from '../transport/connect-client.js';
|
|
4
|
-
import { executeDmoCreate } from './execute-dmo-create.js';
|
|
5
|
-
import { buildExecutableDmoDelta, compareDmoMeaning, preflightDmoDeploy, } from './preflight-dmo-deploy.js';
|
|
6
|
-
import { retrieveDmo } from './retrieve-other-dmo.js';
|
|
7
|
-
/**
|
|
8
|
-
* Normalize only independently keyed field collections; preserve every other raw value.
|
|
9
|
-
* @param {DmoCommonProjection['expectations']} raw Full qualified runtime inputs.
|
|
10
|
-
* @returns {DmoCommonProjection['expectations']} Detached normalized runtime.
|
|
11
|
-
*/
|
|
12
|
-
function normalizeRuntime(raw) {
|
|
13
|
-
const result = structuredClone(raw);
|
|
14
|
-
for (const [record, key] of [
|
|
15
|
-
[result.connect, 'name'],
|
|
16
|
-
[result.metadata, 'fullName'],
|
|
17
|
-
]) {
|
|
18
|
-
const fields = record.fields;
|
|
19
|
-
fields.sort((a, b) => String(a[key]).localeCompare(String(b[key])));
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Apply only evidenced label effects to the complete original runtime snapshot.
|
|
25
|
-
* @param {DmoCommonProjection['expectations']} raw Pre-write qualified runtime.
|
|
26
|
-
* @param {DmoUpdatePatch} patch Admitted label-only patch.
|
|
27
|
-
* @returns {DmoCommonProjection['expectations']} Exact preservation expectation.
|
|
28
|
-
*/
|
|
29
|
-
function expectedRuntime(raw, patch) {
|
|
30
|
-
const result = normalizeRuntime(raw);
|
|
31
|
-
if (patch.label !== undefined) {
|
|
32
|
-
result.connect.label = patch.label;
|
|
33
|
-
result.metadata.label = patch.label;
|
|
34
|
-
const attributes = result.metadata.mktDataModelAttributes;
|
|
35
|
-
attributes.labelOverride = patch.label;
|
|
36
|
-
attributes.masterLabel = patch.label;
|
|
37
|
-
}
|
|
38
|
-
for (const field of patch.fields ?? []) {
|
|
39
|
-
const connect = result.connect.fields.find((item) => item.name === field.name);
|
|
40
|
-
const metadata = result.metadata.fields.find((item) => item.fullName === field.name);
|
|
41
|
-
connect.label = field.label;
|
|
42
|
-
metadata.mktDataModelFieldAttributes.labelOverride = field.label;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Validate and detach before any asynchronous target acquisition.
|
|
48
|
-
* @param {unknown} document Authored-only document.
|
|
49
|
-
* @returns {DmoDocument} Independent mapped snapshot.
|
|
50
|
-
*/
|
|
51
|
-
function snapshotDocument(document) {
|
|
52
|
-
const { name, dataSpaceName, ...spec } = buildDmoCreateRequestFromDocument(document, 'default');
|
|
53
|
-
return validateDmoDocument({
|
|
54
|
-
schemaVersion: 1,
|
|
55
|
-
kind: 'dmo',
|
|
56
|
-
identity: { apiName: `${name}__dlm`, dataSpace: dataSpaceName },
|
|
57
|
-
spec,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Construct a payload-free conservative result.
|
|
62
|
-
* @param {string} outcome Result classification.
|
|
63
|
-
* @param {string} mutation Attempt evidence.
|
|
64
|
-
* @param {string} code Stable diagnostic.
|
|
65
|
-
* @returns {DmoDeployExecution} No remote payloads or error details.
|
|
66
|
-
*/
|
|
67
|
-
function result(outcome, mutation, code) {
|
|
68
|
-
return {
|
|
69
|
-
outcome,
|
|
70
|
-
mutation,
|
|
71
|
-
diagnostics: [
|
|
72
|
-
{
|
|
73
|
-
code,
|
|
74
|
-
message: mutation === 'unknown'
|
|
75
|
-
? 'Mutation may have occurred. Inspect target before any further attempt; no retry or rollback was performed.'
|
|
76
|
-
: 'Deployment was not attempted. Resolve input, scope or target qualification before trying again.',
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Execute one internal create/unchanged/label-update operation using fresh target evidence.
|
|
83
|
-
* Public CLI intentionally continues to invoke the create-only executor.
|
|
84
|
-
* @param {unknown} document Authored document, never saved admission evidence.
|
|
85
|
-
* @param {TargetConnection} connection Explicit authenticated API 65 connection.
|
|
86
|
-
* @param {unknown} apiVersion Explicit 65.0.
|
|
87
|
-
* @param {unknown} dataSpace Explicit default space.
|
|
88
|
-
* @returns {Promise<DmoDeployExecution>} Attempt and independently confirmed outcome.
|
|
89
|
-
*/
|
|
90
|
-
export async function executeDmoDeploy(document, connection, apiVersion, dataSpace) {
|
|
91
|
-
let snapshot;
|
|
92
|
-
try {
|
|
93
|
-
snapshot = snapshotDocument(document);
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
return result('blocked', 'not-attempted', 'INVALID_SOURCE');
|
|
97
|
-
}
|
|
98
|
-
const preflight = await preflightDmoDeploy(snapshot, connection, apiVersion, dataSpace, true);
|
|
99
|
-
if (preflight.outcome === 'create')
|
|
100
|
-
return executeDmoCreate(snapshot, connection, apiVersion, dataSpace);
|
|
101
|
-
if (preflight.outcome === 'unchanged')
|
|
102
|
-
return { outcome: 'unchanged', mutation: 'not-attempted', preflight, diagnostics: [] };
|
|
103
|
-
if (preflight.outcome !== 'update')
|
|
104
|
-
return { ...result('blocked', 'not-attempted', 'UPDATE_BLOCKED'), preflight };
|
|
105
|
-
let acquired;
|
|
106
|
-
let delta;
|
|
107
|
-
try {
|
|
108
|
-
// Reacquire immediately before dispatch: admission snapshots never authorize a PATCH.
|
|
109
|
-
acquired = await retrieveDmo(connection, snapshot.identity.apiName, apiVersion, dataSpace);
|
|
110
|
-
delta = buildExecutableDmoDelta(snapshot, acquired.candidate);
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
return { ...result('blocked', 'not-attempted', 'TARGET_UNQUALIFIED'), preflight };
|
|
114
|
-
}
|
|
115
|
-
if (delta.status === 'blocked')
|
|
116
|
-
return { ...result('blocked', 'not-attempted', 'UPDATE_BLOCKED'), preflight };
|
|
117
|
-
if (delta.status === 'unchanged')
|
|
118
|
-
return { outcome: 'unchanged', mutation: 'not-attempted', preflight, diagnostics: [] };
|
|
119
|
-
let runtime;
|
|
120
|
-
try {
|
|
121
|
-
runtime = expectedRuntime(acquired.expectations, delta.patch);
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
return { ...result('blocked', 'not-attempted', 'TARGET_UNQUALIFIED'), preflight };
|
|
125
|
-
}
|
|
126
|
-
// Mark attempted before dispatch and never infer success from the PATCH response body.
|
|
127
|
-
const execution = {
|
|
128
|
-
...result('failed', 'unknown', 'UPDATE_UNCONFIRMED'),
|
|
129
|
-
preflight,
|
|
130
|
-
};
|
|
131
|
-
try {
|
|
132
|
-
await new ConnectClient(connection, '65.0').patchDataModelObject(snapshot.identity.apiName, delta.patch);
|
|
133
|
-
const readback = await retrieveDmo(connection, snapshot.identity.apiName, apiVersion, dataSpace);
|
|
134
|
-
if (compareDmoMeaning(buildDmoCreateRequestFromDocument(delta.expected, dataSpace), buildDmoCreateRequestFromDocument(readback.candidate, dataSpace)).length > 0 ||
|
|
135
|
-
!isDeepStrictEqual(runtime, normalizeRuntime(readback.expectations))) {
|
|
136
|
-
execution.diagnostics = result('failed', 'unknown', 'READBACK_MISMATCH').diagnostics;
|
|
137
|
-
return execution;
|
|
138
|
-
}
|
|
139
|
-
return { outcome: 'updated', mutation: 'confirmed-updated', preflight, diagnostics: [] };
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
return execution;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Admit the complete detached selection before writes, then stop on first ambiguity or block.
|
|
147
|
-
* @param {unknown[]} documents Explicit selected authored inputs; duplicate identities are invalid.
|
|
148
|
-
* @param {TargetConnection} connection Actual target connection.
|
|
149
|
-
* @param {unknown} apiVersion Explicit API 65.0.
|
|
150
|
-
* @param {unknown} dataSpace Explicit default space.
|
|
151
|
-
* @returns {Promise<DmoDeployExecution[]>} Ordered item results, including never-attempted tail.
|
|
152
|
-
*/
|
|
153
|
-
export async function executeDmoDeploySelection(documents, connection, apiVersion, dataSpace) {
|
|
154
|
-
const items = documents.map(() => result('not-attempted', 'not-attempted', 'SELECTION_NOT_ATTEMPTED'));
|
|
155
|
-
let snapshots;
|
|
156
|
-
try {
|
|
157
|
-
snapshots = documents.map((document) => snapshotDocument(document));
|
|
158
|
-
if (snapshots.length === 0 ||
|
|
159
|
-
new Set(snapshots.map((item) => item.identity.apiName)).size !== snapshots.length)
|
|
160
|
-
throw new Error('Invalid selection');
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
return items.map(() => result('blocked', 'not-attempted', 'INVALID_SELECTION'));
|
|
164
|
-
}
|
|
165
|
-
let blocked = false;
|
|
166
|
-
for (const [index, snapshot] of snapshots.entries()) {
|
|
167
|
-
try {
|
|
168
|
-
const preflight = await preflightDmoDeploy(snapshot, connection, apiVersion, dataSpace, true);
|
|
169
|
-
items[index].preflight = preflight;
|
|
170
|
-
if (preflight.outcome === 'blocked' || preflight.outcome === 'blocked-changes') {
|
|
171
|
-
items[index] = { ...result('blocked', 'not-attempted', 'SELECTION_BLOCKED'), preflight };
|
|
172
|
-
blocked = true;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
items[index] = result('blocked', 'not-attempted', 'PREFLIGHT_FAILED');
|
|
177
|
-
blocked = true;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (blocked)
|
|
181
|
-
return items;
|
|
182
|
-
for (const [index, snapshot] of snapshots.entries()) {
|
|
183
|
-
// An unexpected exception after entering execution cannot erase possible mutation evidence.
|
|
184
|
-
items[index] = result('failed', 'unknown', 'EXECUTION_UNCONFIRMED');
|
|
185
|
-
try {
|
|
186
|
-
items[index] = await executeDmoDeploy(snapshot, connection, apiVersion, dataSpace);
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
return items;
|
|
190
|
-
}
|
|
191
|
-
if (items[index].mutation === 'unknown' ||
|
|
192
|
-
items[index].outcome === 'blocked' ||
|
|
193
|
-
items[index].outcome === 'failed')
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
return items;
|
|
197
|
-
}
|