sf-plugin-data 0.1.0 → 0.3.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 +618 -240
- package/docs/artifact-format.md +528 -633
- package/docs/capabilities.md +1160 -168
- package/docs/git-workflow.md +135 -12
- package/docs/handover.md +7826 -12
- package/lib/api.d.ts +13 -0
- package/lib/api.js +10 -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 +2347 -0
- package/lib/commands/data360/deploy.d.ts +235 -16
- package/lib/commands/data360/deploy.js +2339 -102
- package/lib/commands/data360/list/dataspace.d.ts +53 -0
- package/lib/commands/data360/list/dataspace.js +109 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +298 -0
- package/lib/commands/data360/retrieve.d.ts +283 -14
- package/lib/commands/data360/retrieve.js +1945 -95
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +320 -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 +58 -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/exit-code.d.ts +10 -0
- package/lib/exit-code.js +24 -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 +38 -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 +92 -0
- package/lib/services/data-space-check.js +169 -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/list-data-spaces.d.ts +17 -0
- package/lib/services/list-data-spaces.js +24 -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/run-retrieve.d.ts +24 -0
- package/lib/services/run-retrieve.js +51 -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,23 @@
|
|
|
1
|
+
import type { CrossSpaceContext } from 'salesforce-data360-rules';
|
|
2
|
+
import type { LookupConnection } from './segment-lookup.js';
|
|
3
|
+
/**
|
|
4
|
+
* The context the rename rules of `salesforce-data360-rules` need to turn names of one data
|
|
5
|
+
* space into those of another (`placeDmo`, `translateSegmentName`, …): the
|
|
6
|
+
* org's data spaces with their prefixes and, when needed, its identity resolution rulesets. The
|
|
7
|
+
* rulesets are read when `names` is left out or one of them is an identity resolution output (the
|
|
8
|
+
* unified DMO of another data space is named by that space's ruleset, not by a spelling rule).
|
|
9
|
+
* @param {LookupConnection} connection Authenticated connection.
|
|
10
|
+
* @param {{from: string, to: string, names?: readonly string[]}} options Source and target data
|
|
11
|
+
* space, and the DMO names the caller will translate.
|
|
12
|
+
* @param {string} options.from Source data space.
|
|
13
|
+
* @param {string} options.to Target data space.
|
|
14
|
+
* @param {readonly string[]} [options.names] DMO names of the source space to be translated.
|
|
15
|
+
* @returns {Promise<CrossSpaceContext>} The context.
|
|
16
|
+
* @throws {DataSpaceError} UNKNOWN_DATASPACE or DATASPACE_READ_FAILED.
|
|
17
|
+
* @throws {CrossSpaceError} CROSS_DATASPACE_RULESETS_READ_FAILED.
|
|
18
|
+
*/
|
|
19
|
+
export declare function crossSpaceContext(connection: LookupConnection, options: {
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
names?: readonly string[];
|
|
23
|
+
}): Promise<CrossSpaceContext>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { pairedByRulesets } from 'salesforce-data360-rules';
|
|
2
|
+
import { sortedDataSpaces } from '../artifacts/data-space-field.js';
|
|
3
|
+
import { openBoundSsot } from '../transport/bound-ssot.js';
|
|
4
|
+
import { readRulesetEntries } from './cross-dataspace-deploy.js';
|
|
5
|
+
import { DataSpaceError, readOrgDataSpaceEntries } from './data-space-check.js';
|
|
6
|
+
import { explainInput, printableKey } from './operation-diagnostic.js';
|
|
7
|
+
/**
|
|
8
|
+
* The context the rename rules of `salesforce-data360-rules` need to turn names of one data
|
|
9
|
+
* space into those of another (`placeDmo`, `translateSegmentName`, …): the
|
|
10
|
+
* org's data spaces with their prefixes and, when needed, its identity resolution rulesets. The
|
|
11
|
+
* rulesets are read when `names` is left out or one of them is an identity resolution output (the
|
|
12
|
+
* unified DMO of another data space is named by that space's ruleset, not by a spelling rule).
|
|
13
|
+
* @param {LookupConnection} connection Authenticated connection.
|
|
14
|
+
* @param {{from: string, to: string, names?: readonly string[]}} options Source and target data
|
|
15
|
+
* space, and the DMO names the caller will translate.
|
|
16
|
+
* @param {string} options.from Source data space.
|
|
17
|
+
* @param {string} options.to Target data space.
|
|
18
|
+
* @param {readonly string[]} [options.names] DMO names of the source space to be translated.
|
|
19
|
+
* @returns {Promise<CrossSpaceContext>} The context.
|
|
20
|
+
* @throws {DataSpaceError} UNKNOWN_DATASPACE or DATASPACE_READ_FAILED.
|
|
21
|
+
* @throws {CrossSpaceError} CROSS_DATASPACE_RULESETS_READ_FAILED.
|
|
22
|
+
*/
|
|
23
|
+
export async function crossSpaceContext(connection, options) {
|
|
24
|
+
const sender = openBoundSsot('', '68.0', async () => connection);
|
|
25
|
+
const open = async () => sender;
|
|
26
|
+
// The context names each space and its prefix only, as the rename rules read them.
|
|
27
|
+
const entries = await readOrgDataSpaceEntries(open);
|
|
28
|
+
const spaces = entries.map(({ name, prefix }) => prefix === undefined ? { name } : { name, prefix });
|
|
29
|
+
const known = spaces.map((space) => space.name);
|
|
30
|
+
const unknown = sortedDataSpaces([options.from, options.to].filter((s) => !known.includes(s)));
|
|
31
|
+
if (unknown.length > 0)
|
|
32
|
+
throw explainInput(new DataSpaceError('UNKNOWN_DATASPACE'), `The org has no data space named ${[...new Set(unknown)].map((space) => printableKey(space)).join(', ')}; its data spaces are ${sortedDataSpaces(known)
|
|
33
|
+
.map((space) => printableKey(space))
|
|
34
|
+
.join(', ')}.`);
|
|
35
|
+
const context = { source: options.from, target: options.to, spaces };
|
|
36
|
+
const needsRulesets = options.names === undefined || options.names.some((name) => pairedByRulesets(context, name));
|
|
37
|
+
return needsRulesets ? { ...context, rulesets: await readRulesetEntries(open) } : context;
|
|
38
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** The input shape the plan needs; deploy passes its admitted inputs. */
|
|
2
|
+
export type PlanInput = {
|
|
3
|
+
path: string;
|
|
4
|
+
document: {
|
|
5
|
+
kind: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
import type { IdentityResolutionDocument } from '../artifacts/identity-resolution-document.js';
|
|
9
|
+
/**
|
|
10
|
+
* Phases in create order. P0: data streams (each creates its landing DLO). P1: native DLO,
|
|
11
|
+
* DMO, mapping, relationship. P2: data transforms. P3: identity resolution, calculated insight,
|
|
12
|
+
* Segment. P4: data graphs. Delete runs them in reverse.
|
|
13
|
+
*/
|
|
14
|
+
export type CrudPhase = 'P0' | 'P1' | 'P2' | 'P3' | 'P4';
|
|
15
|
+
export type CrudStage<T extends PlanInput = PlanInput> = {
|
|
16
|
+
phase: CrudPhase;
|
|
17
|
+
inputs: T[];
|
|
18
|
+
};
|
|
19
|
+
export type CrudStageResult = {
|
|
20
|
+
status: 'success' | 'blocked' | 'failed';
|
|
21
|
+
code?: string;
|
|
22
|
+
error?: unknown;
|
|
23
|
+
/** Preview only: component keys this stage plans to create (or could not compare yet). */
|
|
24
|
+
planned?: string[];
|
|
25
|
+
};
|
|
26
|
+
export type CrudStageHandler<T extends PlanInput = PlanInput> = (stage: CrudStage<T>, planned: ReadonlySet<string>) => Promise<CrudStageResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Case-insensitive component key shared by every phase.
|
|
29
|
+
* @param {string} kind Component family (dlo, dmo, identity-resolution, ...).
|
|
30
|
+
* @param {string} apiName Component API name.
|
|
31
|
+
* @returns {string} Key such as `dmo:person__dlm`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function componentKey(kind: string, apiName: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Phase of one admitted deploy input.
|
|
36
|
+
* @param {PlanInput} input Admitted input.
|
|
37
|
+
* @returns {CrudPhase | undefined} The phase; undefined for an unknown kind.
|
|
38
|
+
*/
|
|
39
|
+
export declare function crudPhase(input: PlanInput): CrudPhase | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Unified and link DMO names an identity resolution ruleset creates, derived from its document.
|
|
42
|
+
* Salesforce names a ruleset `<type>` or `<type>_<rulesetId>` and its outputs
|
|
43
|
+
* `Unified<entity><rulesetId>__dlm` / `UnifiedLink<entity><rulesetId>__dlm`, where `<entity>` is
|
|
44
|
+
* the reconciliation DMO name without `__dlm` and underscores (`ssot__Individual__dlm` with
|
|
45
|
+
* ruleset `Individual_5810` gives `UnifiedssotIndividual5810__dlm`). Outside the default data
|
|
46
|
+
* space the ruleset is `<prefix>_<type>_<rulesetId>` and the prefix replaces the `ssot` infix
|
|
47
|
+
* (`ds2_Individual__dlm` with ruleset `ds2_Individual_cx2a` gives `ds2_UnifiedIndividualCx2a__dlm`,
|
|
48
|
+
* live API 68; names are compared ignoring case). A name that does not follow the type pattern
|
|
49
|
+
* derives nothing. The names only order the deploy; nothing is sent under them.
|
|
50
|
+
* @param {IdentityResolutionDocument} document Authored ruleset.
|
|
51
|
+
* @returns {string[]} Derived output DMO names.
|
|
52
|
+
*/
|
|
53
|
+
export declare function unifiedDmoNames(document: IdentityResolutionDocument): string[];
|
|
54
|
+
/**
|
|
55
|
+
* DLOs a data transform reads and writes: the `load` dataset and the `outputD360` target.
|
|
56
|
+
* @param {PlanInput} input Data transform input.
|
|
57
|
+
* @returns {string[]} DLO names found in the definition; a malformed file yields fewer or none.
|
|
58
|
+
*/
|
|
59
|
+
export declare function transformDloNames(input: PlanInput): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Name of the DLO a data stream creates and owns (`spec.newDlo.name`).
|
|
62
|
+
* @param {PlanInput} input Data stream input.
|
|
63
|
+
* @returns {string | undefined} The landing DLO name.
|
|
64
|
+
*/
|
|
65
|
+
export declare function streamLandingDlo(input: PlanInput): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Selected DLO files that name the landing DLO of a selected data stream. The stream creates and
|
|
68
|
+
* owns that DLO, so deploying both would write one object from two files.
|
|
69
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
70
|
+
* @returns {string[]} Colliding DLO API names, as written in the DLO files.
|
|
71
|
+
*/
|
|
72
|
+
export declare function streamDloCollisions(inputs: PlanInput[]): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Edges from graph, CI and Segment inputs onto the selected identity resolution rulesets whose
|
|
75
|
+
* derived unified/link DMO they reference (root, `segmentOn`, dependencies or graph objects).
|
|
76
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
77
|
+
* @returns {Map<string, string[]>} Dependent input path to the API names of the rulesets it needs.
|
|
78
|
+
*/
|
|
79
|
+
export declare function identityResolutionEdges(inputs: PlanInput[]): Map<string, string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Every component key one input depends on: its authored references plus derived IR edges.
|
|
82
|
+
* @param {PlanInput} input Admitted input.
|
|
83
|
+
* @param {Map<string, string[]>} edges Result of {@link identityResolutionEdges}.
|
|
84
|
+
* @returns {string[]} Component keys.
|
|
85
|
+
*/
|
|
86
|
+
export declare function inputDependencies(input: PlanInput, edges: Map<string, string[]>): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Key of one input as other inputs reference it.
|
|
89
|
+
* @param {PlanInput} input Admitted input.
|
|
90
|
+
* @returns {string} Component key.
|
|
91
|
+
*/
|
|
92
|
+
export declare function inputKey(input: PlanInput): string;
|
|
93
|
+
/**
|
|
94
|
+
* Selected dependents of each input: the inputs whose references (or derived IR edges) name it.
|
|
95
|
+
* @param {PlanInput[]} inputs Whole selection.
|
|
96
|
+
* @returns {Map<PlanInput, string[]>} Input to the component keys of the selected inputs that need it.
|
|
97
|
+
*/
|
|
98
|
+
export declare function selectedDependents<T extends PlanInput>(inputs: T[]): Map<T, string[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Split a delete selection into ordered stages, the reverse of the deploy order: P4 graphs, then
|
|
101
|
+
* the P3 batch with every dependent in an earlier stage than the identity resolution, calculated
|
|
102
|
+
* insight or Segment it needs (unified-DMO edges included), then P2 transforms, P1 native inputs
|
|
103
|
+
* and P0 streams.
|
|
104
|
+
* @param {PlanInput[]} inputs Whole delete selection.
|
|
105
|
+
* @returns {CrudStage[]} Non-empty stages in run order.
|
|
106
|
+
*/
|
|
107
|
+
export declare function planDeleteStages<T extends PlanInput>(inputs: T[]): Array<CrudStage<T>>;
|
|
108
|
+
/**
|
|
109
|
+
* Split an admitted selection into ordered stages: P0 streams, P1 native inputs, P2 transforms,
|
|
110
|
+
* the P3 dependency batch and P4 graphs. With `nativeRoute`, P1 inputs form one stage on the
|
|
111
|
+
* native route; otherwise they stay in the P3 dependency batch. The batch is split further so
|
|
112
|
+
* that an input needing a selected IR's unified DMO (directly or through another selected input)
|
|
113
|
+
* runs in a later stage than that IR, and a Waterfall segment in a later stage than the selected
|
|
114
|
+
* child segments it names (a child must exist before the Waterfall can name it). Graphs come last, so a graph on a selected IR's unified DMO
|
|
115
|
+
* starts only after that IR settled.
|
|
116
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
117
|
+
* @param {object} options Routing choice.
|
|
118
|
+
* @param {boolean} options.nativeRoute Run P1 inputs on the native route as their own stage.
|
|
119
|
+
* @returns {CrudStage[]} Non-empty stages in run order.
|
|
120
|
+
*/
|
|
121
|
+
export declare function planDeployStages<T extends PlanInput>(inputs: T[], options: {
|
|
122
|
+
nativeRoute: boolean;
|
|
123
|
+
}): Array<CrudStage<T>>;
|
|
124
|
+
/**
|
|
125
|
+
* Run stages in order. A stage starts only after the previous one returned success (every
|
|
126
|
+
* item settled); a blocked or failed stage stops the run. With `continueAfterBlocked`
|
|
127
|
+
* (read-only preview) every stage runs and the first non-success result is returned. Preview keys a stage plans to create
|
|
128
|
+
* are handed to later stages, which report their dependents as planned instead of comparing.
|
|
129
|
+
* @param {CrudStage[]} stages Result of {@link planDeployStages}.
|
|
130
|
+
* @param {CrudStageHandler} handler Runs one stage with the family preflight/executors.
|
|
131
|
+
* @param {object} [options] Run options.
|
|
132
|
+
* @param {boolean} [options.continueAfterBlocked] Preview: run later stages anyway.
|
|
133
|
+
* @returns {Promise<CrudStageResult>} First non-success result, or success.
|
|
134
|
+
*/
|
|
135
|
+
export declare function runCrudStages<T extends PlanInput>(stages: Array<CrudStage<T>>, handler: CrudStageHandler<T>, options?: {
|
|
136
|
+
continueAfterBlocked?: boolean;
|
|
137
|
+
}): Promise<CrudStageResult>;
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Case-insensitive component key shared by every phase.
|
|
3
|
+
* @param {string} kind Component family (dlo, dmo, identity-resolution, ...).
|
|
4
|
+
* @param {string} apiName Component API name.
|
|
5
|
+
* @returns {string} Key such as `dmo:person__dlm`.
|
|
6
|
+
*/
|
|
7
|
+
export function componentKey(kind, apiName) {
|
|
8
|
+
return `${kind}:${apiName}`.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Phase of one admitted deploy input.
|
|
12
|
+
* @param {PlanInput} input Admitted input.
|
|
13
|
+
* @returns {CrudPhase | undefined} The phase; undefined for an unknown kind.
|
|
14
|
+
*/
|
|
15
|
+
export function crudPhase(input) {
|
|
16
|
+
const kind = input.document.kind;
|
|
17
|
+
if (kind === 'data-stream')
|
|
18
|
+
return 'P0';
|
|
19
|
+
if (kind === 'data-transform')
|
|
20
|
+
return 'P2';
|
|
21
|
+
if (kind === 'native-data-graph')
|
|
22
|
+
return 'P4';
|
|
23
|
+
if (kind === 'dlo' || kind === 'dmo' || kind === 'mapping' || kind === 'relationship')
|
|
24
|
+
return 'P1';
|
|
25
|
+
if (kind === 'identity-resolution' || kind === 'calculated-insight' || kind === 'segment')
|
|
26
|
+
return 'P3';
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Unified and link DMO names an identity resolution ruleset creates, derived from its document.
|
|
31
|
+
* Salesforce names a ruleset `<type>` or `<type>_<rulesetId>` and its outputs
|
|
32
|
+
* `Unified<entity><rulesetId>__dlm` / `UnifiedLink<entity><rulesetId>__dlm`, where `<entity>` is
|
|
33
|
+
* the reconciliation DMO name without `__dlm` and underscores (`ssot__Individual__dlm` with
|
|
34
|
+
* ruleset `Individual_5810` gives `UnifiedssotIndividual5810__dlm`). Outside the default data
|
|
35
|
+
* space the ruleset is `<prefix>_<type>_<rulesetId>` and the prefix replaces the `ssot` infix
|
|
36
|
+
* (`ds2_Individual__dlm` with ruleset `ds2_Individual_cx2a` gives `ds2_UnifiedIndividualCx2a__dlm`,
|
|
37
|
+
* live API 68; names are compared ignoring case). A name that does not follow the type pattern
|
|
38
|
+
* derives nothing. The names only order the deploy; nothing is sent under them.
|
|
39
|
+
* @param {IdentityResolutionDocument} document Authored ruleset.
|
|
40
|
+
* @returns {string[]} Derived output DMO names.
|
|
41
|
+
*/
|
|
42
|
+
export function unifiedDmoNames(document) {
|
|
43
|
+
// Edges are derived before the family validates the file; a malformed file derives nothing.
|
|
44
|
+
const stored = document.identity?.apiName;
|
|
45
|
+
const type = document.spec?.configurationType;
|
|
46
|
+
const rules = document.spec?.reconciliationRules;
|
|
47
|
+
if (typeof stored !== 'string' || typeof type !== 'string' || !Array.isArray(rules))
|
|
48
|
+
return [];
|
|
49
|
+
const spaced = typeof document.c__dataSpace === 'string' && document.c__dataSpace !== 'default'
|
|
50
|
+
? /^([A-Za-z][A-Za-z0-9]*)_(.+)$/u.exec(stored)
|
|
51
|
+
: undefined;
|
|
52
|
+
if (spaced === null)
|
|
53
|
+
return [];
|
|
54
|
+
const prefix = spaced ? `${spaced[1]}_` : '';
|
|
55
|
+
const name = spaced ? spaced[2] : stored;
|
|
56
|
+
const rulesetId = name.toLowerCase() === type.toLowerCase()
|
|
57
|
+
? ''
|
|
58
|
+
: name.toLowerCase().startsWith(`${type.toLowerCase()}_`) && name.length > type.length + 1
|
|
59
|
+
? name.slice(type.length + 1)
|
|
60
|
+
: undefined;
|
|
61
|
+
if (rulesetId === undefined)
|
|
62
|
+
return [];
|
|
63
|
+
return rules.flatMap((rule) => {
|
|
64
|
+
const apiName = rule?.entity?.apiName;
|
|
65
|
+
if (typeof apiName !== 'string')
|
|
66
|
+
return [];
|
|
67
|
+
const entity = (prefix && apiName.startsWith(prefix) ? apiName.slice(prefix.length) : apiName)
|
|
68
|
+
.replace(/__dlm$/u, '')
|
|
69
|
+
.replaceAll('_', '');
|
|
70
|
+
return [
|
|
71
|
+
`${prefix}Unified${entity}${rulesetId}__dlm`,
|
|
72
|
+
`${prefix}UnifiedLink${entity}${rulesetId}__dlm`,
|
|
73
|
+
];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Collect the object names of a graph node tree (root and related objects).
|
|
78
|
+
* @param {unknown} node Graph definition or node.
|
|
79
|
+
* @param {string[]} names Accumulator.
|
|
80
|
+
* @returns {string[]} The accumulator.
|
|
81
|
+
*/
|
|
82
|
+
function graphObjectNames(node, names = []) {
|
|
83
|
+
if (!node || typeof node !== 'object')
|
|
84
|
+
return names;
|
|
85
|
+
const record = node;
|
|
86
|
+
if (typeof record.primaryObjectName === 'string')
|
|
87
|
+
names.push(record.primaryObjectName);
|
|
88
|
+
if (Array.isArray(record.relatedObjects) && typeof record.name === 'string')
|
|
89
|
+
names.push(record.name);
|
|
90
|
+
for (const value of Object.values(record))
|
|
91
|
+
if (value && typeof value === 'object')
|
|
92
|
+
graphObjectNames(value, names);
|
|
93
|
+
return names;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Component references of one input as `[kind, apiName]` pairs: CI dependencies,
|
|
97
|
+
* the Segment's `segmentOn` and Waterfall child segments, IR reconciliation DMOs and graph
|
|
98
|
+
* root/related objects (as DMOs).
|
|
99
|
+
* @param {PlanInput} input Admitted input.
|
|
100
|
+
* @returns {Array<[string, string]>} Referenced components.
|
|
101
|
+
*/
|
|
102
|
+
function references(input) {
|
|
103
|
+
const document = input.document;
|
|
104
|
+
const spec = document.spec ?? {};
|
|
105
|
+
const listed = (value) => Array.isArray(value)
|
|
106
|
+
? value
|
|
107
|
+
.filter((item) => !!item &&
|
|
108
|
+
typeof item.kind === 'string' &&
|
|
109
|
+
typeof item.apiName === 'string')
|
|
110
|
+
.map((item) => [item.kind, item.apiName])
|
|
111
|
+
: [];
|
|
112
|
+
if (document.kind === 'segment')
|
|
113
|
+
return [
|
|
114
|
+
...listed([spec.segmentOn]),
|
|
115
|
+
...(Array.isArray(spec.childSegments) ? spec.childSegments : [])
|
|
116
|
+
.filter((name) => typeof name === 'string')
|
|
117
|
+
.map((name) => ['segment', name]),
|
|
118
|
+
];
|
|
119
|
+
if (document.kind === 'calculated-insight')
|
|
120
|
+
return listed(spec.dependencies);
|
|
121
|
+
if (document.kind === 'identity-resolution')
|
|
122
|
+
return listed(spec.reconciliationRules?.map((rule) => rule.entity));
|
|
123
|
+
if (document.kind === 'native-data-graph')
|
|
124
|
+
return graphObjectNames(input.document.definition).map((name) => [
|
|
125
|
+
'dmo',
|
|
126
|
+
name,
|
|
127
|
+
]);
|
|
128
|
+
if (document.kind === 'data-transform')
|
|
129
|
+
return transformDloNames(input).map((name) => ['dlo', name]);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* DLOs a data transform reads and writes: the `load` dataset and the `outputD360` target.
|
|
134
|
+
* @param {PlanInput} input Data transform input.
|
|
135
|
+
* @returns {string[]} DLO names found in the definition; a malformed file yields fewer or none.
|
|
136
|
+
*/
|
|
137
|
+
export function transformDloNames(input) {
|
|
138
|
+
const definition = input.document
|
|
139
|
+
.definition?.definition;
|
|
140
|
+
const nodes = definition?.nodes;
|
|
141
|
+
if (!nodes || typeof nodes !== 'object')
|
|
142
|
+
return [];
|
|
143
|
+
const names = [];
|
|
144
|
+
for (const node of Object.values(nodes)) {
|
|
145
|
+
const record = (node ?? {});
|
|
146
|
+
const name = record.action === 'load'
|
|
147
|
+
? record.parameters?.dataset?.name
|
|
148
|
+
: record.action === 'outputD360'
|
|
149
|
+
? record.parameters?.name
|
|
150
|
+
: undefined;
|
|
151
|
+
if (typeof name === 'string')
|
|
152
|
+
names.push(name);
|
|
153
|
+
}
|
|
154
|
+
return names;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Name of the DLO a data stream creates and owns (`spec.newDlo.name`).
|
|
158
|
+
* @param {PlanInput} input Data stream input.
|
|
159
|
+
* @returns {string | undefined} The landing DLO name.
|
|
160
|
+
*/
|
|
161
|
+
export function streamLandingDlo(input) {
|
|
162
|
+
// An Ingestion API stream names it in spec.newDlo, a CRM stream in spec.dataLakeObjectInfo.
|
|
163
|
+
const spec = input.document.spec;
|
|
164
|
+
const name = spec?.newDlo?.name ?? spec?.dataLakeObjectInfo?.name;
|
|
165
|
+
return typeof name === 'string' ? name : undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Selected DLO files that name the landing DLO of a selected data stream. The stream creates and
|
|
169
|
+
* owns that DLO, so deploying both would write one object from two files.
|
|
170
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
171
|
+
* @returns {string[]} Colliding DLO API names, as written in the DLO files.
|
|
172
|
+
*/
|
|
173
|
+
export function streamDloCollisions(inputs) {
|
|
174
|
+
const landing = new Set(inputs
|
|
175
|
+
.filter((input) => input.document.kind === 'data-stream')
|
|
176
|
+
.map((input) => streamLandingDlo(input)?.toLowerCase())
|
|
177
|
+
.filter((name) => name !== undefined));
|
|
178
|
+
return inputs
|
|
179
|
+
.filter((input) => input.document.kind === 'dlo')
|
|
180
|
+
.map((input) => String(input.document.identity?.apiName))
|
|
181
|
+
.filter((name) => landing.has(name.toLowerCase()));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Edges from graph, CI and Segment inputs onto the selected identity resolution rulesets whose
|
|
185
|
+
* derived unified/link DMO they reference (root, `segmentOn`, dependencies or graph objects).
|
|
186
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
187
|
+
* @returns {Map<string, string[]>} Dependent input path to the API names of the rulesets it needs.
|
|
188
|
+
*/
|
|
189
|
+
export function identityResolutionEdges(inputs) {
|
|
190
|
+
const owners = new Map();
|
|
191
|
+
for (const input of inputs)
|
|
192
|
+
if (input.document.kind === 'identity-resolution')
|
|
193
|
+
for (const name of unifiedDmoNames(input.document))
|
|
194
|
+
owners.set(name.toLowerCase(), input.document.identity.apiName);
|
|
195
|
+
const edges = new Map();
|
|
196
|
+
if (owners.size === 0)
|
|
197
|
+
return edges;
|
|
198
|
+
for (const input of inputs) {
|
|
199
|
+
if (input.document.kind !== 'segment' &&
|
|
200
|
+
input.document.kind !== 'calculated-insight' &&
|
|
201
|
+
input.document.kind !== 'native-data-graph')
|
|
202
|
+
continue;
|
|
203
|
+
const needed = new Set();
|
|
204
|
+
for (const [kind, apiName] of references(input)) {
|
|
205
|
+
const owner = kind === 'dmo' ? owners.get(apiName.toLowerCase()) : undefined;
|
|
206
|
+
if (owner)
|
|
207
|
+
needed.add(owner);
|
|
208
|
+
}
|
|
209
|
+
if (needed.size > 0)
|
|
210
|
+
edges.set(input.path, [...needed]);
|
|
211
|
+
}
|
|
212
|
+
return edges;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Every component key one input depends on: its authored references plus derived IR edges.
|
|
216
|
+
* @param {PlanInput} input Admitted input.
|
|
217
|
+
* @param {Map<string, string[]>} edges Result of {@link identityResolutionEdges}.
|
|
218
|
+
* @returns {string[]} Component keys.
|
|
219
|
+
*/
|
|
220
|
+
export function inputDependencies(input, edges) {
|
|
221
|
+
const spec = input.document.spec ?? {};
|
|
222
|
+
const keys = references(input).map(([kind, apiName]) => componentKey(kind, apiName));
|
|
223
|
+
if (input.document.kind === 'mapping')
|
|
224
|
+
keys.push(componentKey('dlo', String(spec.sourceEntityDeveloperName)), componentKey('dmo', String(spec.targetEntityDeveloperName)));
|
|
225
|
+
if (input.document.kind === 'relationship')
|
|
226
|
+
keys.push(componentKey('dmo', String(spec.sourceObjectName)), componentKey('dmo', String(spec.targetObjectName)));
|
|
227
|
+
for (const owner of edges.get(input.path) ?? [])
|
|
228
|
+
keys.push(componentKey('identity-resolution', owner));
|
|
229
|
+
return keys;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Key of one input as other inputs reference it.
|
|
233
|
+
* @param {PlanInput} input Admitted input.
|
|
234
|
+
* @returns {string} Component key.
|
|
235
|
+
*/
|
|
236
|
+
export function inputKey(input) {
|
|
237
|
+
const document = input.document;
|
|
238
|
+
// Graphs and transforms carry their name in the definition, not in an identity block.
|
|
239
|
+
return componentKey(input.document.kind, String(document.identity?.apiName ?? document.definition?.name));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Selected dependents of each input: the inputs whose references (or derived IR edges) name it.
|
|
243
|
+
* @param {PlanInput[]} inputs Whole selection.
|
|
244
|
+
* @returns {Map<PlanInput, string[]>} Input to the component keys of the selected inputs that need it.
|
|
245
|
+
*/
|
|
246
|
+
export function selectedDependents(inputs) {
|
|
247
|
+
const edges = identityResolutionEdges(inputs);
|
|
248
|
+
const byKey = new Map(inputs.map((input) => [inputKey(input), input]));
|
|
249
|
+
const dependents = new Map();
|
|
250
|
+
for (const input of inputs)
|
|
251
|
+
for (const key of inputDependencies(input, edges)) {
|
|
252
|
+
const parent = byKey.get(key);
|
|
253
|
+
if (!parent || parent === input)
|
|
254
|
+
continue;
|
|
255
|
+
const known = dependents.get(parent) ?? [];
|
|
256
|
+
if (!known.includes(inputKey(input)))
|
|
257
|
+
dependents.set(parent, [...known, inputKey(input)]);
|
|
258
|
+
}
|
|
259
|
+
return dependents;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Split a delete selection into ordered stages, the reverse of the deploy order: P4 graphs, then
|
|
263
|
+
* the P3 batch with every dependent in an earlier stage than the identity resolution, calculated
|
|
264
|
+
* insight or Segment it needs (unified-DMO edges included), then P2 transforms, P1 native inputs
|
|
265
|
+
* and P0 streams.
|
|
266
|
+
* @param {PlanInput[]} inputs Whole delete selection.
|
|
267
|
+
* @returns {CrudStage[]} Non-empty stages in run order.
|
|
268
|
+
*/
|
|
269
|
+
export function planDeleteStages(inputs) {
|
|
270
|
+
const stages = [];
|
|
271
|
+
const of = (phase) => inputs.filter((input) => crudPhase(input) === phase);
|
|
272
|
+
const graphs = of('P4');
|
|
273
|
+
if (graphs.length > 0)
|
|
274
|
+
stages.push({ phase: 'P4', inputs: graphs });
|
|
275
|
+
const batch = of('P3');
|
|
276
|
+
const dependents = selectedDependents(batch);
|
|
277
|
+
const byKey = new Map(batch.map((input) => [inputKey(input), input]));
|
|
278
|
+
// Height: the longest chain of selected dependents above an input. An input with no selected
|
|
279
|
+
// dependent goes first; every input runs in a later stage than all of its dependents.
|
|
280
|
+
const heights = new Map();
|
|
281
|
+
const visiting = new Set();
|
|
282
|
+
const height = (input) => {
|
|
283
|
+
const known = heights.get(input);
|
|
284
|
+
if (known !== undefined)
|
|
285
|
+
return known;
|
|
286
|
+
// A cycle is refused by the family checks; never recurse forever here.
|
|
287
|
+
if (visiting.has(input))
|
|
288
|
+
return 0;
|
|
289
|
+
visiting.add(input);
|
|
290
|
+
let result = 0;
|
|
291
|
+
for (const key of dependents.get(input) ?? []) {
|
|
292
|
+
const dependent = byKey.get(key);
|
|
293
|
+
if (dependent)
|
|
294
|
+
result = Math.max(result, height(dependent) + 1);
|
|
295
|
+
}
|
|
296
|
+
visiting.delete(input);
|
|
297
|
+
heights.set(input, result);
|
|
298
|
+
return result;
|
|
299
|
+
};
|
|
300
|
+
const grouped = new Map();
|
|
301
|
+
for (const input of batch) {
|
|
302
|
+
const value = height(input);
|
|
303
|
+
grouped.set(value, [...(grouped.get(value) ?? []), input]);
|
|
304
|
+
}
|
|
305
|
+
const tallest = batch.length === 0 ? -1 : Math.max(...grouped.keys());
|
|
306
|
+
for (let value = 0; value <= tallest; value++) {
|
|
307
|
+
const group = grouped.get(value);
|
|
308
|
+
if (group)
|
|
309
|
+
stages.push({ phase: 'P3', inputs: group });
|
|
310
|
+
}
|
|
311
|
+
for (const phase of ['P2', 'P1', 'P0']) {
|
|
312
|
+
const group = of(phase);
|
|
313
|
+
if (group.length > 0)
|
|
314
|
+
stages.push({ phase, inputs: group });
|
|
315
|
+
}
|
|
316
|
+
return stages;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Split an admitted selection into ordered stages: P0 streams, P1 native inputs, P2 transforms,
|
|
320
|
+
* the P3 dependency batch and P4 graphs. With `nativeRoute`, P1 inputs form one stage on the
|
|
321
|
+
* native route; otherwise they stay in the P3 dependency batch. The batch is split further so
|
|
322
|
+
* that an input needing a selected IR's unified DMO (directly or through another selected input)
|
|
323
|
+
* runs in a later stage than that IR, and a Waterfall segment in a later stage than the selected
|
|
324
|
+
* child segments it names (a child must exist before the Waterfall can name it). Graphs come last, so a graph on a selected IR's unified DMO
|
|
325
|
+
* starts only after that IR settled.
|
|
326
|
+
* @param {PlanInput[]} inputs Whole admitted selection.
|
|
327
|
+
* @param {object} options Routing choice.
|
|
328
|
+
* @param {boolean} options.nativeRoute Run P1 inputs on the native route as their own stage.
|
|
329
|
+
* @returns {CrudStage[]} Non-empty stages in run order.
|
|
330
|
+
*/
|
|
331
|
+
export function planDeployStages(inputs, options) {
|
|
332
|
+
const stages = [];
|
|
333
|
+
const of = (phase) => inputs.filter((input) => crudPhase(input) === phase);
|
|
334
|
+
const streams = of('P0');
|
|
335
|
+
if (streams.length > 0)
|
|
336
|
+
stages.push({ phase: 'P0', inputs: streams });
|
|
337
|
+
const native = options.nativeRoute ? of('P1') : [];
|
|
338
|
+
if (native.length > 0)
|
|
339
|
+
stages.push({ phase: 'P1', inputs: native });
|
|
340
|
+
const transforms = of('P2');
|
|
341
|
+
if (transforms.length > 0)
|
|
342
|
+
stages.push({ phase: 'P2', inputs: transforms });
|
|
343
|
+
const batch = inputs.filter((input) => (crudPhase(input) === 'P1' || crudPhase(input) === 'P3') && !native.includes(input));
|
|
344
|
+
const edges = identityResolutionEdges(batch);
|
|
345
|
+
const byKey = new Map(batch.map((input) => [inputKey(input), input]));
|
|
346
|
+
const levels = new Map();
|
|
347
|
+
const visiting = new Set();
|
|
348
|
+
const level = (input) => {
|
|
349
|
+
const known = levels.get(input);
|
|
350
|
+
if (known !== undefined)
|
|
351
|
+
return known;
|
|
352
|
+
// A cycle is refused later by the dependency order; never recurse forever here.
|
|
353
|
+
if (visiting.has(input))
|
|
354
|
+
return 0;
|
|
355
|
+
visiting.add(input);
|
|
356
|
+
const owners = new Set((edges.get(input.path) ?? []).map((name) => componentKey('identity-resolution', name)));
|
|
357
|
+
let result = 0;
|
|
358
|
+
for (const key of inputDependencies(input, edges)) {
|
|
359
|
+
const parent = byKey.get(key);
|
|
360
|
+
if (parent && parent !== input)
|
|
361
|
+
result = Math.max(result, level(parent) + (owners.has(key) || parent.document.kind === 'segment' ? 1 : 0));
|
|
362
|
+
}
|
|
363
|
+
visiting.delete(input);
|
|
364
|
+
levels.set(input, result);
|
|
365
|
+
return result;
|
|
366
|
+
};
|
|
367
|
+
const grouped = new Map();
|
|
368
|
+
for (const input of batch) {
|
|
369
|
+
const value = level(input);
|
|
370
|
+
grouped.set(value, [...(grouped.get(value) ?? []), input]);
|
|
371
|
+
}
|
|
372
|
+
const deepest = batch.length === 0 ? -1 : Math.max(...grouped.keys());
|
|
373
|
+
for (let value = 0; value <= deepest; value++) {
|
|
374
|
+
const group = grouped.get(value);
|
|
375
|
+
if (group)
|
|
376
|
+
stages.push({ phase: 'P3', inputs: group });
|
|
377
|
+
}
|
|
378
|
+
const graphs = of('P4');
|
|
379
|
+
if (graphs.length > 0)
|
|
380
|
+
stages.push({ phase: 'P4', inputs: graphs });
|
|
381
|
+
return stages;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Run stages in order. A stage starts only after the previous one returned success (every
|
|
385
|
+
* item settled); a blocked or failed stage stops the run. With `continueAfterBlocked`
|
|
386
|
+
* (read-only preview) every stage runs and the first non-success result is returned. Preview keys a stage plans to create
|
|
387
|
+
* are handed to later stages, which report their dependents as planned instead of comparing.
|
|
388
|
+
* @param {CrudStage[]} stages Result of {@link planDeployStages}.
|
|
389
|
+
* @param {CrudStageHandler} handler Runs one stage with the family preflight/executors.
|
|
390
|
+
* @param {object} [options] Run options.
|
|
391
|
+
* @param {boolean} [options.continueAfterBlocked] Preview: run later stages anyway.
|
|
392
|
+
* @returns {Promise<CrudStageResult>} First non-success result, or success.
|
|
393
|
+
*/
|
|
394
|
+
export async function runCrudStages(stages, handler, options = {}) {
|
|
395
|
+
const planned = new Set();
|
|
396
|
+
let first;
|
|
397
|
+
for (const stage of stages) {
|
|
398
|
+
const result = await handler(stage, planned);
|
|
399
|
+
for (const key of result.planned ?? [])
|
|
400
|
+
planned.add(key);
|
|
401
|
+
if (result.status === 'success')
|
|
402
|
+
continue;
|
|
403
|
+
first ??= result;
|
|
404
|
+
if (!options.continueAfterBlocked)
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
return first ?? { status: 'success' };
|
|
408
|
+
}
|