sf-plugin-data 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +589 -2
- package/bin/run.js +4 -0
- package/docs/artifact-format.md +527 -0
- package/docs/capabilities.md +1208 -0
- package/docs/git-workflow.md +160 -0
- package/docs/handover.md +10446 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +7 -0
- package/lib/artifacts/code-fields.d.ts +49 -0
- package/lib/artifacts/code-fields.js +142 -0
- package/lib/artifacts/data-graph-document.d.ts +29 -0
- package/lib/artifacts/data-graph-document.js +52 -0
- package/lib/artifacts/data-space-field.d.ts +65 -0
- package/lib/artifacts/data-space-field.js +98 -0
- package/lib/artifacts/data-stream-document.d.ts +264 -0
- package/lib/artifacts/data-stream-document.js +680 -0
- package/lib/artifacts/data-transform-document.d.ts +152 -0
- package/lib/artifacts/data-transform-document.js +560 -0
- package/lib/artifacts/dependency-selection.d.ts +51 -0
- package/lib/artifacts/dependency-selection.js +154 -0
- package/lib/artifacts/dlo-document.d.ts +93 -0
- package/lib/artifacts/dlo-document.js +253 -0
- package/lib/artifacts/enum-case.d.ts +39 -0
- package/lib/artifacts/enum-case.js +67 -0
- package/lib/artifacts/git-deploy-selection.d.ts +68 -0
- package/lib/artifacts/git-deploy-selection.js +474 -0
- package/lib/artifacts/identity-resolution-document.d.ts +133 -0
- package/lib/artifacts/identity-resolution-document.js +625 -0
- package/lib/artifacts/mapping-document.d.ts +1 -0
- package/lib/artifacts/mapping-document.js +1 -0
- package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
- package/lib/artifacts/native-calculated-insight-document.js +321 -0
- package/lib/artifacts/native-data-graph-document.d.ts +124 -0
- package/lib/artifacts/native-data-graph-document.js +780 -0
- package/lib/artifacts/native-dmo-document.d.ts +151 -0
- package/lib/artifacts/native-dmo-document.js +313 -0
- package/lib/artifacts/native-mapping-document.d.ts +67 -0
- package/lib/artifacts/native-mapping-document.js +187 -0
- package/lib/artifacts/native-relationship-document.d.ts +76 -0
- package/lib/artifacts/native-relationship-document.js +232 -0
- package/lib/artifacts/path-selector.d.ts +55 -0
- package/lib/artifacts/path-selector.js +167 -0
- package/lib/artifacts/read-deploy-input.d.ts +239 -0
- package/lib/artifacts/read-deploy-input.js +1359 -0
- package/lib/artifacts/segment-document.d.ts +183 -0
- package/lib/artifacts/segment-document.js +570 -0
- package/lib/artifacts/verbatim-document.d.ts +203 -0
- package/lib/artifacts/verbatim-document.js +339 -0
- package/lib/artifacts/write-data-graph.d.ts +17 -0
- package/lib/artifacts/write-data-graph.js +162 -0
- package/lib/artifacts/write-data-stream.d.ts +11 -0
- package/lib/artifacts/write-data-stream.js +175 -0
- package/lib/artifacts/write-data-transform.d.ts +11 -0
- package/lib/artifacts/write-data-transform.js +180 -0
- package/lib/artifacts/write-dlo.d.ts +11 -0
- package/lib/artifacts/write-dlo.js +158 -0
- package/lib/artifacts/write-identity-resolution.d.ts +18 -0
- package/lib/artifacts/write-identity-resolution.js +165 -0
- package/lib/artifacts/write-mapping-definition.d.ts +17 -0
- package/lib/artifacts/write-mapping-definition.js +127 -0
- package/lib/artifacts/write-member-export.d.ts +88 -0
- package/lib/artifacts/write-member-export.js +199 -0
- package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
- package/lib/artifacts/write-native-calculated-insight.js +176 -0
- package/lib/artifacts/write-native-dmo.d.ts +11 -0
- package/lib/artifacts/write-native-dmo.js +158 -0
- package/lib/artifacts/write-native-mapping.d.ts +11 -0
- package/lib/artifacts/write-native-mapping.js +157 -0
- package/lib/artifacts/write-native-relationship.d.ts +11 -0
- package/lib/artifacts/write-native-relationship.js +157 -0
- package/lib/artifacts/write-segment.d.ts +26 -0
- package/lib/artifacts/write-segment.js +212 -0
- package/lib/commands/data360/delete.d.ts +280 -0
- package/lib/commands/data360/delete.js +2297 -0
- package/lib/commands/data360/deploy.d.ts +303 -0
- package/lib/commands/data360/deploy.js +2400 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +322 -0
- package/lib/commands/data360/retrieve.js +1963 -0
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +318 -0
- package/lib/errors/codes/calculated-insight.d.ts +2 -0
- package/lib/errors/codes/calculated-insight.js +25 -0
- package/lib/errors/codes/data-graph.d.ts +2 -0
- package/lib/errors/codes/data-graph.js +22 -0
- package/lib/errors/codes/data-stream.d.ts +2 -0
- package/lib/errors/codes/data-stream.js +70 -0
- package/lib/errors/codes/data-transform.d.ts +2 -0
- package/lib/errors/codes/data-transform.js +35 -0
- package/lib/errors/codes/dependency.d.ts +2 -0
- package/lib/errors/codes/dependency.js +11 -0
- package/lib/errors/codes/dlo.d.ts +2 -0
- package/lib/errors/codes/dlo.js +31 -0
- package/lib/errors/codes/dmo.d.ts +2 -0
- package/lib/errors/codes/dmo.js +28 -0
- package/lib/errors/codes/general.d.ts +2 -0
- package/lib/errors/codes/general.js +57 -0
- package/lib/errors/codes/identity-resolution.d.ts +2 -0
- package/lib/errors/codes/identity-resolution.js +24 -0
- package/lib/errors/codes/mapping.d.ts +2 -0
- package/lib/errors/codes/mapping.js +42 -0
- package/lib/errors/codes/relationship.d.ts +2 -0
- package/lib/errors/codes/relationship.js +21 -0
- package/lib/errors/codes/segment.d.ts +2 -0
- package/lib/errors/codes/segment.js +49 -0
- package/lib/errors/registry.d.ts +60 -0
- package/lib/errors/registry.js +123 -0
- package/lib/plugin.d.ts +5 -0
- package/lib/plugin.js +5 -0
- package/lib/services/acquire-retrieve-selection.d.ts +43 -0
- package/lib/services/acquire-retrieve-selection.js +145 -0
- package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
- package/lib/services/bind-identity-resolution-dependencies.js +238 -0
- package/lib/services/bind-segment-dependencies.d.ts +49 -0
- package/lib/services/bind-segment-dependencies.js +115 -0
- package/lib/services/bounded-reads.d.ts +17 -0
- package/lib/services/bounded-reads.js +42 -0
- package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
- package/lib/services/calculated-insight-sql-checks.js +193 -0
- package/lib/services/command-dlo.d.ts +48 -0
- package/lib/services/command-dlo.js +103 -0
- package/lib/services/command-native-data-graph.d.ts +54 -0
- package/lib/services/command-native-data-graph.js +485 -0
- package/lib/services/command-native-data-stream.d.ts +104 -0
- package/lib/services/command-native-data-stream.js +257 -0
- package/lib/services/command-native-dmo.d.ts +124 -0
- package/lib/services/command-native-dmo.js +338 -0
- package/lib/services/command-native-mapping.d.ts +65 -0
- package/lib/services/command-native-mapping.js +129 -0
- package/lib/services/command-native-relationship.d.ts +46 -0
- package/lib/services/command-native-relationship.js +103 -0
- package/lib/services/cross-dataspace-deploy.d.ts +111 -0
- package/lib/services/cross-dataspace-deploy.js +493 -0
- package/lib/services/cross-dataspace-rename.d.ts +74 -0
- package/lib/services/cross-dataspace-rename.js +1314 -0
- package/lib/services/cross-dataspace-sql.d.ts +109 -0
- package/lib/services/cross-dataspace-sql.js +1301 -0
- package/lib/services/cross-space-context.d.ts +23 -0
- package/lib/services/cross-space-context.js +36 -0
- package/lib/services/crud-plan.d.ts +137 -0
- package/lib/services/crud-plan.js +408 -0
- package/lib/services/data-space-check.d.ts +89 -0
- package/lib/services/data-space-check.js +162 -0
- package/lib/services/data-space-prefix.d.ts +77 -0
- package/lib/services/data-space-prefix.js +127 -0
- package/lib/services/data-transform-space.d.ts +31 -0
- package/lib/services/data-transform-space.js +79 -0
- package/lib/services/delete-calculated-insight.d.ts +44 -0
- package/lib/services/delete-calculated-insight.js +101 -0
- package/lib/services/delete-data-transform.d.ts +52 -0
- package/lib/services/delete-data-transform.js +222 -0
- package/lib/services/delete-dmo-field.d.ts +211 -0
- package/lib/services/delete-dmo-field.js +472 -0
- package/lib/services/delete-identity-resolution.d.ts +43 -0
- package/lib/services/delete-identity-resolution.js +295 -0
- package/lib/services/delete-segment.d.ts +42 -0
- package/lib/services/delete-segment.js +248 -0
- package/lib/services/deploy-result.d.ts +54 -0
- package/lib/services/deploy-result.js +60 -0
- package/lib/services/escaped-copy.d.ts +23 -0
- package/lib/services/escaped-copy.js +88 -0
- package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
- package/lib/services/execute-calculated-insight-deploy.js +96 -0
- package/lib/services/execute-data-transform-deploy.d.ts +56 -0
- package/lib/services/execute-data-transform-deploy.js +168 -0
- package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
- package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
- package/lib/services/execute-segment-deploy.d.ts +45 -0
- package/lib/services/execute-segment-deploy.js +393 -0
- package/lib/services/local-file-removal.d.ts +36 -0
- package/lib/services/local-file-removal.js +103 -0
- package/lib/services/native-calculated-insight.d.ts +87 -0
- package/lib/services/native-calculated-insight.js +164 -0
- package/lib/services/native-crm-data-stream.d.ts +91 -0
- package/lib/services/native-crm-data-stream.js +272 -0
- package/lib/services/native-data-graph-context.d.ts +12 -0
- package/lib/services/native-data-graph-context.js +139 -0
- package/lib/services/native-data-graph-crd.d.ts +261 -0
- package/lib/services/native-data-graph-crd.js +866 -0
- package/lib/services/native-data-stream.d.ts +329 -0
- package/lib/services/native-data-stream.js +1830 -0
- package/lib/services/native-dlo.d.ts +163 -0
- package/lib/services/native-dlo.js +402 -0
- package/lib/services/native-dmo.d.ts +191 -0
- package/lib/services/native-dmo.js +614 -0
- package/lib/services/native-mapping.d.ts +255 -0
- package/lib/services/native-mapping.js +1226 -0
- package/lib/services/native-relationship.d.ts +132 -0
- package/lib/services/native-relationship.js +512 -0
- package/lib/services/operation-diagnostic.d.ts +83 -0
- package/lib/services/operation-diagnostic.js +272 -0
- package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
- package/lib/services/preflight-calculated-insight-deploy.js +95 -0
- package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
- package/lib/services/preflight-data-transform-deploy.js +104 -0
- package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
- package/lib/services/preflight-identity-resolution-deploy.js +281 -0
- package/lib/services/preflight-segment-deploy.d.ts +31 -0
- package/lib/services/preflight-segment-deploy.js +109 -0
- package/lib/services/publish-calculated-insight.d.ts +40 -0
- package/lib/services/publish-calculated-insight.js +95 -0
- package/lib/services/publish-segment.d.ts +65 -0
- package/lib/services/publish-segment.js +194 -0
- package/lib/services/readback-pace.d.ts +16 -0
- package/lib/services/readback-pace.js +23 -0
- package/lib/services/retrieve-data-transform.d.ts +26 -0
- package/lib/services/retrieve-data-transform.js +65 -0
- package/lib/services/retrieve-identity-resolution.d.ts +40 -0
- package/lib/services/retrieve-identity-resolution.js +87 -0
- package/lib/services/retrieve-inventory.d.ts +32 -0
- package/lib/services/retrieve-inventory.js +151 -0
- package/lib/services/retrieve-segment.d.ts +120 -0
- package/lib/services/retrieve-segment.js +502 -0
- package/lib/services/segment-lookup.d.ts +46 -0
- package/lib/services/segment-lookup.js +108 -0
- package/lib/services/segment-members.d.ts +144 -0
- package/lib/services/segment-members.js +402 -0
- package/lib/services/select-native-retrieve.d.ts +60 -0
- package/lib/services/select-native-retrieve.js +226 -0
- package/lib/services/settle-calculated-insight.d.ts +22 -0
- package/lib/services/settle-calculated-insight.js +53 -0
- package/lib/services/sql-tokens.d.ts +58 -0
- package/lib/services/sql-tokens.js +147 -0
- package/lib/transport/api-version.d.ts +36 -0
- package/lib/transport/api-version.js +89 -0
- package/lib/transport/bound-ssot.d.ts +27 -0
- package/lib/transport/bound-ssot.js +116 -0
- package/lib/transport/calculated-insight-rest.d.ts +28 -0
- package/lib/transport/calculated-insight-rest.js +62 -0
- package/lib/transport/connect-client.d.ts +129 -0
- package/lib/transport/connect-client.js +446 -0
- package/lib/transport/connect-diagnostic.d.ts +89 -0
- package/lib/transport/connect-diagnostic.js +331 -0
- package/lib/transport/data-graph-rest.d.ts +27 -0
- package/lib/transport/data-graph-rest.js +76 -0
- package/lib/transport/data-stream-rest.d.ts +62 -0
- package/lib/transport/data-stream-rest.js +348 -0
- package/lib/transport/data-transform-rest.d.ts +25 -0
- package/lib/transport/data-transform-rest.js +100 -0
- package/lib/transport/dlo-native-rest.d.ts +22 -0
- package/lib/transport/dlo-native-rest.js +89 -0
- package/lib/transport/dlo-rest.d.ts +23 -0
- package/lib/transport/dlo-rest.js +135 -0
- package/lib/transport/dmo-native-rest.d.ts +18 -0
- package/lib/transport/dmo-native-rest.js +55 -0
- package/lib/transport/dmo-rest.d.ts +30 -0
- package/lib/transport/dmo-rest.js +163 -0
- package/lib/transport/mapping-rest.d.ts +63 -0
- package/lib/transport/mapping-rest.js +341 -0
- package/lib/transport/project-metadata.d.ts +36 -0
- package/lib/transport/project-metadata.js +118 -0
- package/lib/transport/relationship-rest.d.ts +43 -0
- package/lib/transport/relationship-rest.js +201 -0
- package/package.json +96 -4
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ConnectClient } from '../transport/connect-client.js';
|
|
2
|
+
import { readInOrder } from './bounded-reads.js';
|
|
3
|
+
import { explainInput } from './operation-diagnostic.js';
|
|
4
|
+
import { NativeMappingError, mappingDloName, mappingDmoName, nativeMappingName, } from '../artifacts/native-mapping-document.js';
|
|
5
|
+
// Listing pages in flight at once (the one being read and those fetched ahead of it).
|
|
6
|
+
const pageReads = 4;
|
|
7
|
+
/**
|
|
8
|
+
* The data spaces an inventory entry belongs to; an unusable space is left out.
|
|
9
|
+
* @param {Record<string, unknown>} item Inventory entry.
|
|
10
|
+
* @param {'dlo' | 'dmo'} family Inventory family.
|
|
11
|
+
* @returns {string[]} Its data space names.
|
|
12
|
+
*/
|
|
13
|
+
function entrySpaces(item, family) {
|
|
14
|
+
if (family === 'dmo')
|
|
15
|
+
return typeof item.dataSpaceName === 'string' && item.dataSpaceName ? [item.dataSpaceName] : [];
|
|
16
|
+
if (!Array.isArray(item.dataSpaceInfo))
|
|
17
|
+
return [];
|
|
18
|
+
return item.dataSpaceInfo.flatMap((space) => space &&
|
|
19
|
+
typeof space === 'object' &&
|
|
20
|
+
'name' in space &&
|
|
21
|
+
typeof space.name === 'string' &&
|
|
22
|
+
space.name
|
|
23
|
+
? [space.name]
|
|
24
|
+
: []);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The listing entry as an object; anything else has no usable field.
|
|
28
|
+
* @param {unknown} value Listing entry.
|
|
29
|
+
* @returns {Record<string, unknown>} The entry, or an empty object.
|
|
30
|
+
*/
|
|
31
|
+
function entryObject(value) {
|
|
32
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
33
|
+
? value
|
|
34
|
+
: {};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a listing entry can stand in for its item GET. Live on API68 every DLO list entry, and
|
|
38
|
+
* every DMO list entry, equalled its item GET byte for byte (the DLO item GET wraps it in a
|
|
39
|
+
* one-element `dataLakeObjects` array), except that a few standard DMOs list their fields in
|
|
40
|
+
* varying order in both reads; see DB entry data360:a2.retrieve-speed.api68. An entry without the
|
|
41
|
+
* field list the item GET carries is not that shape, so its object is read on its own.
|
|
42
|
+
* @param {'dlo' | 'dmo'} family Inventory family.
|
|
43
|
+
* @param {Record<string, unknown>} item Listing entry.
|
|
44
|
+
* @returns {boolean} The entry is the item GET's object.
|
|
45
|
+
*/
|
|
46
|
+
export function listedEntryReplacesGet(family, item) {
|
|
47
|
+
return family === 'dlo'
|
|
48
|
+
? Array.isArray(item.dataLakeFieldInfoRepresentation) && Array.isArray(item.fields)
|
|
49
|
+
: Array.isArray(item.fields);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Name a skipped listing entry in a warning.
|
|
53
|
+
* @param {string | undefined} name Its name, when it has one.
|
|
54
|
+
* @param {number} position Its position in the listing.
|
|
55
|
+
* @returns {string} `"Name"` or `the entry at position N`.
|
|
56
|
+
*/
|
|
57
|
+
function entryLabel(name, position) {
|
|
58
|
+
return name === undefined ? `the entry at position ${position}` : `"${name}"`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read a native DLO or DMO inventory through its documented offset paging, until the API has no
|
|
62
|
+
* more pages: `totalSize` when the answer has it, otherwise a non-empty `nextPageUrl` or a full
|
|
63
|
+
* page. Extra envelope keys and the format of the page URLs are ignored. A page whose entries are
|
|
64
|
+
* all listed already ends the listing (a server ignoring the offset). An entry without a usable
|
|
65
|
+
* API name is skipped with a warning; a repeated entry is listed once. Both lists hold every data
|
|
66
|
+
* space whatever `?dataspace=` says, so each entry is kept by its own data space. A DLO entry
|
|
67
|
+
* without a usable data space is skipped with a warning. A DMO entry without one stops the
|
|
68
|
+
* listing (NATIVE_INVENTORY_UNCONFIRMED): every DMO entry read live names its `dataSpaceName`
|
|
69
|
+
* (default ones too), so one without it is not a shape the plugin knows, and skipping it could
|
|
70
|
+
* leave out a DMO of the run's space.
|
|
71
|
+
* @param {Connection} connection Authenticated command-owned connection.
|
|
72
|
+
* @param {string} version Admitted numeric native version.
|
|
73
|
+
* @param {'dlo' | 'dmo'} family Inventory family.
|
|
74
|
+
* @param {string} requestScope The run's data space; entries of other spaces are left out.
|
|
75
|
+
* @param {string[]} [warnings] Receives one warning per skipped entry.
|
|
76
|
+
* @param {Map<string, unknown>} [listed] Receives each listed name's entry, when the entry is
|
|
77
|
+
* proven to equal its item GET (see listedEntryReplacesGet).
|
|
78
|
+
* @returns {Promise<string[]>} Sorted names in the selected space.
|
|
79
|
+
*/
|
|
80
|
+
export async function listNativeNames(connection, version, family, requestScope, warnings, listed) {
|
|
81
|
+
const client = new ConnectClient(connection, version);
|
|
82
|
+
const key = family === 'dmo' ? 'dataModelObject' : 'dataLakeObjects';
|
|
83
|
+
const resource = family === 'dmo' ? 'data-model-objects' : 'data-lake-objects';
|
|
84
|
+
const limit = family === 'dmo' ? 50 : 20;
|
|
85
|
+
const pattern = family === 'dmo' ? mappingDmoName : mappingDloName;
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
const names = [];
|
|
88
|
+
// Pages fetched ahead of the one being read, by offset (below totalSize when it is known).
|
|
89
|
+
// A page fetched past the end is never read; the pages are used in order as before.
|
|
90
|
+
const ahead = new Map();
|
|
91
|
+
const fetchPage = async (offset) => client.get(`/services/data/v${version}/ssot/${resource}?limit=${limit}&offset=${offset}&orderBy=ASC`);
|
|
92
|
+
const prefetch = (from, total = Number.POSITIVE_INFINITY) => {
|
|
93
|
+
for (let offset = from; offset < total && offset < from + pageReads * limit; offset += limit)
|
|
94
|
+
if (!ahead.has(offset))
|
|
95
|
+
ahead.set(offset, fetchPage(offset).then((value) => ({ value }), (error) => ({ error })));
|
|
96
|
+
};
|
|
97
|
+
for (let offset = 0;; offset += limit) {
|
|
98
|
+
const early = ahead.get(offset);
|
|
99
|
+
ahead.delete(offset);
|
|
100
|
+
let page;
|
|
101
|
+
if (early) {
|
|
102
|
+
const settled = await early;
|
|
103
|
+
if ('error' in settled)
|
|
104
|
+
throw settled.error;
|
|
105
|
+
page = settled.value;
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
page = await fetchPage(offset);
|
|
109
|
+
if (!page || typeof page !== 'object' || Array.isArray(page))
|
|
110
|
+
throw new NativeMappingError('NATIVE_INVENTORY_UNCONFIRMED');
|
|
111
|
+
const wrapper = page;
|
|
112
|
+
const entries = wrapper[key];
|
|
113
|
+
if (!Array.isArray(entries))
|
|
114
|
+
throw new NativeMappingError('NATIVE_INVENTORY_UNCONFIRMED');
|
|
115
|
+
let added = 0;
|
|
116
|
+
for (const [index, value] of entries.entries()) {
|
|
117
|
+
const item = entryObject(value);
|
|
118
|
+
const name = typeof item.name === 'string' ? item.name : undefined;
|
|
119
|
+
const named = name !== undefined && pattern.test(name);
|
|
120
|
+
const spaces = entrySpaces(item, family);
|
|
121
|
+
if (named && spaces.length === 0 && family === 'dmo')
|
|
122
|
+
throw explainInput(new NativeMappingError('NATIVE_INVENTORY_UNCONFIRMED'), `The DMO list entry "${name}" names no data space (dataSpaceName), so the plugin cannot tell whether it belongs to the data space ${requestScope}; nothing was retrieved from the DMO list.`);
|
|
123
|
+
if (!named || spaces.length === 0) {
|
|
124
|
+
warnings?.push(`${family} inventory: skipped ${entryLabel(name, offset + index)} because it has no usable ${named ? 'data space' : 'API name'}.`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const identity = name.toLowerCase();
|
|
128
|
+
if (seen.has(identity))
|
|
129
|
+
continue;
|
|
130
|
+
seen.add(identity);
|
|
131
|
+
added++;
|
|
132
|
+
if (!spaces.includes(requestScope))
|
|
133
|
+
continue;
|
|
134
|
+
names.push(name);
|
|
135
|
+
if (listed && listedEntryReplacesGet(family, item))
|
|
136
|
+
listed.set(name, value);
|
|
137
|
+
}
|
|
138
|
+
const total = typeof wrapper.totalSize === 'number' &&
|
|
139
|
+
Number.isSafeInteger(wrapper.totalSize) &&
|
|
140
|
+
wrapper.totalSize >= 0
|
|
141
|
+
? wrapper.totalSize
|
|
142
|
+
: undefined;
|
|
143
|
+
// Salesforce may return fewer entries than a page's offset range; totalSize decides.
|
|
144
|
+
const more = total === undefined
|
|
145
|
+
? added > 0 &&
|
|
146
|
+
((typeof wrapper.nextPageUrl === 'string' && wrapper.nextPageUrl !== '') ||
|
|
147
|
+
entries.length >= limit)
|
|
148
|
+
: offset + limit < total;
|
|
149
|
+
if (!more)
|
|
150
|
+
break;
|
|
151
|
+
// The next pages are read in parallel; they are still used in order.
|
|
152
|
+
prefetch(offset + limit, total);
|
|
153
|
+
}
|
|
154
|
+
names.sort();
|
|
155
|
+
return names;
|
|
156
|
+
}
|
|
157
|
+
/** Mapping lists (one per DMO) read at once; results are still used in DMO order. */
|
|
158
|
+
export const mappingListReads = 6;
|
|
159
|
+
/**
|
|
160
|
+
* Collect the names of the mappings of every selected-space DMO; each mapping is read and checked
|
|
161
|
+
* on its own later. A filtered no-map 404 means the DMO has none. Extra envelope keys are
|
|
162
|
+
* ignored. An entry without a usable name, or of another data space, is skipped with a warning;
|
|
163
|
+
* a name listed under several DMOs is kept once.
|
|
164
|
+
* @param {string[]} dmos Selected-space DMO inventory.
|
|
165
|
+
* @param {Pick<MappingClient, 'list'>} client Filtered mapping reader.
|
|
166
|
+
* @param {string} requestScope The run's data space.
|
|
167
|
+
* @param {MappingListingReport} [report] Warnings and per-DMO failures.
|
|
168
|
+
* @returns {Promise<string[]>} Unique sorted mapping names.
|
|
169
|
+
*/
|
|
170
|
+
export async function listNativeMappingNames(dmos, client, requestScope, report = {}) {
|
|
171
|
+
const mappings = new Map();
|
|
172
|
+
const space = requestScope;
|
|
173
|
+
let stopped = false;
|
|
174
|
+
const fail = (dmo, error) => {
|
|
175
|
+
if (!report.failure) {
|
|
176
|
+
stopped = true;
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
report.failure(dmo, error);
|
|
180
|
+
};
|
|
181
|
+
// Up to mappingListReads DMOs are listed at once; names, warnings and failures follow the DMO
|
|
182
|
+
// order. Retries (429, 503, network) stay per request in the transport.
|
|
183
|
+
const reads = readInOrder(dmos, mappingListReads, async (dmo) => {
|
|
184
|
+
if (stopped)
|
|
185
|
+
throw new NativeMappingError('MAPPING_INVENTORY_UNCONFIRMED');
|
|
186
|
+
return client.list(dmo);
|
|
187
|
+
});
|
|
188
|
+
for (const [index, dmo] of dmos.entries()) {
|
|
189
|
+
const read = await reads[index];
|
|
190
|
+
if ('error' in read) {
|
|
191
|
+
const { error } = read;
|
|
192
|
+
if (!(error instanceof NativeMappingError &&
|
|
193
|
+
error.code === 'MAPPING_HTTP_ERROR' &&
|
|
194
|
+
error.status === 404))
|
|
195
|
+
fail(dmo, error);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const response = read.value;
|
|
199
|
+
const entries = entryObject(response).objectSourceTargetMaps;
|
|
200
|
+
if (!Array.isArray(entries)) {
|
|
201
|
+
fail(dmo, new NativeMappingError('MAPPING_INVENTORY_UNCONFIRMED'));
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
for (const [index, value] of entries.entries()) {
|
|
205
|
+
const item = entryObject(value);
|
|
206
|
+
const name = typeof item.developerName === 'string' ? item.developerName : undefined;
|
|
207
|
+
if (name === undefined || !nativeMappingName.test(name)) {
|
|
208
|
+
report.warnings?.push(`mapping inventory of ${dmo}: skipped ${entryLabel(name, index)} because it has no usable API name.`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (item.dataSpaceName !== undefined && item.dataSpaceName !== space) {
|
|
212
|
+
report.warnings?.push(`mapping inventory of ${dmo}: skipped "${name}" because it belongs to another data space.`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const identity = name.toLowerCase();
|
|
216
|
+
if (mappings.has(identity))
|
|
217
|
+
continue;
|
|
218
|
+
mappings.set(identity, name);
|
|
219
|
+
if (Array.isArray(item.fieldMappings))
|
|
220
|
+
report.listed?.set(name, value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const names = [...mappings.values()];
|
|
224
|
+
names.sort();
|
|
225
|
+
return names;
|
|
226
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NativeCalculatedInsight } from '../artifacts/native-calculated-insight-document.js';
|
|
2
|
+
import type { CalculatedInsightReadContext } from './native-calculated-insight.js';
|
|
3
|
+
export declare const calculatedInsightPollBudget: Readonly<{
|
|
4
|
+
reads: 12;
|
|
5
|
+
intervalMs: 1000;
|
|
6
|
+
timeoutMs: 120000;
|
|
7
|
+
}>;
|
|
8
|
+
export type CalculatedInsightTiming = {
|
|
9
|
+
now?: () => number;
|
|
10
|
+
delay?: (milliseconds: number) => Promise<unknown>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Read the insight again after a write, at most twelve GETs one second apart within 120
|
|
14
|
+
* seconds, never writing. `present`: it reads with every key of the document and is not
|
|
15
|
+
* PROCESSING; `ACTIVE`: the same and ACTIVE; `absent`: it reads 404.
|
|
16
|
+
* @param {CalculatedInsightReadContext} context Read context of the write.
|
|
17
|
+
* @param {NativeCalculatedInsight} desired Document that was sent (or deleted).
|
|
18
|
+
* @param {'present' | 'ACTIVE' | 'absent'} target Expected end state.
|
|
19
|
+
* @param {CalculatedInsightTiming} timing Injectable clock and delay for tests.
|
|
20
|
+
* @returns {Promise<string>} Final status (`absent` after a delete).
|
|
21
|
+
*/
|
|
22
|
+
export declare function settleCalculatedInsight(context: CalculatedInsightReadContext, desired: Pick<NativeCalculatedInsight, 'apiName'> & Partial<NativeCalculatedInsight>, target: 'present' | 'ACTIVE' | 'absent', timing?: CalculatedInsightTiming): Promise<string>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { CalculatedInsightError, calculatedInsightMatches, } from '../artifacts/native-calculated-insight-document.js';
|
|
3
|
+
import { acquireCalculatedInsight, calculatedInsightPresence, } from './native-calculated-insight.js';
|
|
4
|
+
export const calculatedInsightPollBudget = Object.freeze({
|
|
5
|
+
reads: 12,
|
|
6
|
+
intervalMs: 1000,
|
|
7
|
+
timeoutMs: 120_000,
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Read the insight again after a write, at most twelve GETs one second apart within 120
|
|
11
|
+
* seconds, never writing. `present`: it reads with every key of the document and is not
|
|
12
|
+
* PROCESSING; `ACTIVE`: the same and ACTIVE; `absent`: it reads 404.
|
|
13
|
+
* @param {CalculatedInsightReadContext} context Read context of the write.
|
|
14
|
+
* @param {NativeCalculatedInsight} desired Document that was sent (or deleted).
|
|
15
|
+
* @param {'present' | 'ACTIVE' | 'absent'} target Expected end state.
|
|
16
|
+
* @param {CalculatedInsightTiming} timing Injectable clock and delay for tests.
|
|
17
|
+
* @returns {Promise<string>} Final status (`absent` after a delete).
|
|
18
|
+
*/
|
|
19
|
+
export async function settleCalculatedInsight(context, desired, target, timing = {}) {
|
|
20
|
+
const now = timing.now ?? Date.now;
|
|
21
|
+
const pause = timing.delay ?? delay;
|
|
22
|
+
const deadline = now() + calculatedInsightPollBudget.timeoutMs;
|
|
23
|
+
let last = 'CI_SETTLEMENT_TIMEOUT';
|
|
24
|
+
for (let read = 0; read < calculatedInsightPollBudget.reads; read++) {
|
|
25
|
+
if (read > 0)
|
|
26
|
+
await pause(calculatedInsightPollBudget.intervalMs);
|
|
27
|
+
if (now() >= deadline)
|
|
28
|
+
break;
|
|
29
|
+
context.check();
|
|
30
|
+
// After a delete only presence counts; the content of a lingering insight is not projected.
|
|
31
|
+
if (target === 'absent') {
|
|
32
|
+
const presence = await calculatedInsightPresence(context, desired.apiName);
|
|
33
|
+
if (presence.state === 'absent')
|
|
34
|
+
return 'absent';
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const acquired = await acquireCalculatedInsight(context, desired.apiName);
|
|
38
|
+
if (acquired.state === 'absent')
|
|
39
|
+
throw new CalculatedInsightError('CI_UNEXPECTED_ABSENCE');
|
|
40
|
+
if (acquired.status === 'PROCESSING')
|
|
41
|
+
continue;
|
|
42
|
+
if (!calculatedInsightMatches(desired, acquired.document)) {
|
|
43
|
+
last = 'CI_SETTLEMENT_MISMATCH';
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (target === 'ACTIVE' && acquired.status !== 'ACTIVE') {
|
|
47
|
+
last = 'CI_UNEXPECTED_STATE';
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
return acquired.status;
|
|
51
|
+
}
|
|
52
|
+
throw new CalculatedInsightError(last);
|
|
53
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One token of a SQL text. Every character of the text belongs to exactly one token, so joining
|
|
3
|
+
* the `text` of all tokens gives the text back.
|
|
4
|
+
* - `word`: an unquoted identifier or keyword (`[A-Za-z_][A-Za-z0-9_]*`).
|
|
5
|
+
* - `quoted`: an identifier in double quotes or backticks; `value` is its name without quotes.
|
|
6
|
+
* - `string`: a text literal in single quotes; never a name.
|
|
7
|
+
* - `number`, `space`, `comment` (`--` to the end of the line, or `/* … *\/`).
|
|
8
|
+
* - `punct`: any other single character (`.`, `,`, `(`, `)`, operators).
|
|
9
|
+
*/
|
|
10
|
+
export type SqlToken = {
|
|
11
|
+
kind: 'word' | 'quoted' | 'string' | 'number' | 'space' | 'comment' | 'punct';
|
|
12
|
+
text: string;
|
|
13
|
+
/** Offset of the first character. */
|
|
14
|
+
start: number;
|
|
15
|
+
/** 1-based line and column of the first character. */
|
|
16
|
+
line: number;
|
|
17
|
+
column: number;
|
|
18
|
+
/** For `quoted`: the name without quotes (a doubled quote stands for one). */
|
|
19
|
+
value?: string;
|
|
20
|
+
/** For `quoted`: the quote character. */
|
|
21
|
+
quote?: '"' | '`';
|
|
22
|
+
};
|
|
23
|
+
/** A text the tokenizer cannot read exactly: where and why. */
|
|
24
|
+
export type SqlTokenProblem = {
|
|
25
|
+
line: number;
|
|
26
|
+
column: number;
|
|
27
|
+
reason: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Split a SQL text into tokens. Single quotes are text, double quotes and backticks are
|
|
31
|
+
* identifiers (`""` and ``` `` ``` stand for one quote), and comments are `--` lines and
|
|
32
|
+
* `/* … *\/` blocks. What the dialects read differently is refused, never guessed: a backslash
|
|
33
|
+
* before a quote in a text (an escape in Spark SQL, a plain character in ANSI SQL), a block
|
|
34
|
+
* comment that opens another one inside (nested in some dialects only), and anything left open
|
|
35
|
+
* at the end.
|
|
36
|
+
* @param {string} sql SQL text.
|
|
37
|
+
* @returns {SqlToken[] | SqlTokenProblem} Tokens, or where the text cannot be read exactly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function tokenizeSql(sql: string): SqlToken[] | SqlTokenProblem;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a tokenizer answer is a problem.
|
|
42
|
+
* @param {SqlToken[] | SqlTokenProblem} result Tokenizer answer.
|
|
43
|
+
* @returns {boolean} Whether the text could not be read.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSqlTokenProblem(result: SqlToken[] | SqlTokenProblem): result is SqlTokenProblem;
|
|
46
|
+
/**
|
|
47
|
+
* The name a word or quoted token stands for.
|
|
48
|
+
* @param {SqlToken} token Token.
|
|
49
|
+
* @returns {string | undefined} Name; undefined for other kinds.
|
|
50
|
+
*/
|
|
51
|
+
export declare function tokenName(token: SqlToken): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The text of a name token spelled with a new name, in the token's own quotes.
|
|
54
|
+
* @param {SqlToken} token Word or quoted token.
|
|
55
|
+
* @param {string} name New name.
|
|
56
|
+
* @returns {string} Token text.
|
|
57
|
+
*/
|
|
58
|
+
export declare function spellToken(token: SqlToken, name: string): string;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const wordStart = /[A-Za-z_]/u;
|
|
2
|
+
const wordPart = /[A-Za-z0-9_]/u;
|
|
3
|
+
const digit = /[0-9]/u;
|
|
4
|
+
/**
|
|
5
|
+
* Split a SQL text into tokens. Single quotes are text, double quotes and backticks are
|
|
6
|
+
* identifiers (`""` and ``` `` ``` stand for one quote), and comments are `--` lines and
|
|
7
|
+
* `/* … *\/` blocks. What the dialects read differently is refused, never guessed: a backslash
|
|
8
|
+
* before a quote in a text (an escape in Spark SQL, a plain character in ANSI SQL), a block
|
|
9
|
+
* comment that opens another one inside (nested in some dialects only), and anything left open
|
|
10
|
+
* at the end.
|
|
11
|
+
* @param {string} sql SQL text.
|
|
12
|
+
* @returns {SqlToken[] | SqlTokenProblem} Tokens, or where the text cannot be read exactly.
|
|
13
|
+
*/
|
|
14
|
+
export function tokenizeSql(sql) {
|
|
15
|
+
const tokens = [];
|
|
16
|
+
let index = 0;
|
|
17
|
+
let line = 1;
|
|
18
|
+
let column = 1;
|
|
19
|
+
const advance = (to) => {
|
|
20
|
+
for (let at = index; at < to; at++)
|
|
21
|
+
if (sql[at] === '\n') {
|
|
22
|
+
line++;
|
|
23
|
+
column = 1;
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
column++;
|
|
27
|
+
index = to;
|
|
28
|
+
};
|
|
29
|
+
const push = (kind, end, extra = {}) => {
|
|
30
|
+
tokens.push({ kind, text: sql.slice(index, end), start: index, line, column, ...extra });
|
|
31
|
+
advance(end);
|
|
32
|
+
};
|
|
33
|
+
const problem = (reason) => ({ line, column, reason });
|
|
34
|
+
while (index < sql.length) {
|
|
35
|
+
const char = sql[index];
|
|
36
|
+
const next = sql[index + 1];
|
|
37
|
+
if (/\s/u.test(char)) {
|
|
38
|
+
let end = index + 1;
|
|
39
|
+
while (end < sql.length && /\s/u.test(sql[end]))
|
|
40
|
+
end++;
|
|
41
|
+
push('space', end);
|
|
42
|
+
}
|
|
43
|
+
else if (char === '-' && next === '-') {
|
|
44
|
+
const end = sql.indexOf('\n', index);
|
|
45
|
+
push('comment', end === -1 ? sql.length : end);
|
|
46
|
+
}
|
|
47
|
+
else if (char === '/' && next === '*') {
|
|
48
|
+
const end = sql.indexOf('*/', index + 2);
|
|
49
|
+
if (end === -1)
|
|
50
|
+
return problem('a block comment is not closed');
|
|
51
|
+
if (sql.slice(index + 2, end).includes('/*'))
|
|
52
|
+
return problem('a block comment opens another one inside; SQL dialects disagree on where it ends');
|
|
53
|
+
push('comment', end + 2);
|
|
54
|
+
}
|
|
55
|
+
else if (char === "'") {
|
|
56
|
+
let end = index + 1;
|
|
57
|
+
for (;;) {
|
|
58
|
+
if (end >= sql.length)
|
|
59
|
+
return problem('a text in single quotes is not closed');
|
|
60
|
+
if (sql[end] === '\\' && sql[end + 1] === "'")
|
|
61
|
+
return problem('a text in single quotes holds a backslash before a quote; SQL dialects disagree on where it ends');
|
|
62
|
+
if (sql[end] === "'") {
|
|
63
|
+
if (sql[end + 1] === "'") {
|
|
64
|
+
end += 2;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
end++;
|
|
70
|
+
}
|
|
71
|
+
push('string', end + 1);
|
|
72
|
+
}
|
|
73
|
+
else if (char === '"' || char === '`') {
|
|
74
|
+
let end = index + 1;
|
|
75
|
+
let value = '';
|
|
76
|
+
for (;;) {
|
|
77
|
+
if (end >= sql.length)
|
|
78
|
+
return problem(`a name in ${char} quotes is not closed`);
|
|
79
|
+
if (sql[end] === char) {
|
|
80
|
+
if (sql[end + 1] === char) {
|
|
81
|
+
value += char;
|
|
82
|
+
end += 2;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
value += sql[end];
|
|
88
|
+
end++;
|
|
89
|
+
}
|
|
90
|
+
push('quoted', end + 1, { value, quote: char });
|
|
91
|
+
}
|
|
92
|
+
else if (wordStart.test(char)) {
|
|
93
|
+
let end = index + 1;
|
|
94
|
+
while (end < sql.length && wordPart.test(sql[end]))
|
|
95
|
+
end++;
|
|
96
|
+
push('word', end);
|
|
97
|
+
}
|
|
98
|
+
else if (digit.test(char)) {
|
|
99
|
+
let end = index + 1;
|
|
100
|
+
while (end < sql.length && /[0-9.]/u.test(sql[end]))
|
|
101
|
+
end++;
|
|
102
|
+
if (/[eE]/u.test(sql[end] ?? '') && /[0-9+-]/u.test(sql[end + 1] ?? '')) {
|
|
103
|
+
end += 2;
|
|
104
|
+
while (end < sql.length && digit.test(sql[end]))
|
|
105
|
+
end++;
|
|
106
|
+
}
|
|
107
|
+
// A number directly followed by letters (`1d`, `2L`) is one number token.
|
|
108
|
+
while (end < sql.length && wordPart.test(sql[end]))
|
|
109
|
+
end++;
|
|
110
|
+
push('number', end);
|
|
111
|
+
}
|
|
112
|
+
else
|
|
113
|
+
push('punct', index + 1);
|
|
114
|
+
}
|
|
115
|
+
return tokens;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether a tokenizer answer is a problem.
|
|
119
|
+
* @param {SqlToken[] | SqlTokenProblem} result Tokenizer answer.
|
|
120
|
+
* @returns {boolean} Whether the text could not be read.
|
|
121
|
+
*/
|
|
122
|
+
export function isSqlTokenProblem(result) {
|
|
123
|
+
return !Array.isArray(result);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The name a word or quoted token stands for.
|
|
127
|
+
* @param {SqlToken} token Token.
|
|
128
|
+
* @returns {string | undefined} Name; undefined for other kinds.
|
|
129
|
+
*/
|
|
130
|
+
export function tokenName(token) {
|
|
131
|
+
if (token.kind === 'word')
|
|
132
|
+
return token.text;
|
|
133
|
+
if (token.kind === 'quoted')
|
|
134
|
+
return token.value;
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The text of a name token spelled with a new name, in the token's own quotes.
|
|
139
|
+
* @param {SqlToken} token Word or quoted token.
|
|
140
|
+
* @param {string} name New name.
|
|
141
|
+
* @returns {string} Token text.
|
|
142
|
+
*/
|
|
143
|
+
export function spellToken(token, name) {
|
|
144
|
+
if (token.kind !== 'quoted' || token.quote === undefined)
|
|
145
|
+
return name;
|
|
146
|
+
return `${token.quote}${name.replaceAll(token.quote, token.quote + token.quote)}${token.quote}`;
|
|
147
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Separate the requested REST route selector from numeric SOAP version evidence. */
|
|
2
|
+
export type ApiVersionSelection = Readonly<{
|
|
3
|
+
requested: string;
|
|
4
|
+
restSelector: string;
|
|
5
|
+
soapNumeric: string;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Admit the qualified initial native stream pin without widening other families.
|
|
9
|
+
* @param {string} requested Explicit pin or default/auto.
|
|
10
|
+
* @returns {string} Fixed native stream version.
|
|
11
|
+
*/
|
|
12
|
+
export declare function dataStreamApiVersion(requested?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Admit native DLO, DMO and mapping routes without discovery or upgrading numeric pins.
|
|
15
|
+
* Admission is not a claim of live qualification at every admitted version.
|
|
16
|
+
* @param {string} requested Explicit numeric version or default/auto.
|
|
17
|
+
* @returns {string} Numeric route version.
|
|
18
|
+
*/
|
|
19
|
+
export declare function nativeApiVersion(requested?: string): string;
|
|
20
|
+
export type OperationalFamily = 'segment' | 'identity-resolution' | 'calculated-insight' | 'data-graph' | 'data-transform' | 'dlo';
|
|
21
|
+
/**
|
|
22
|
+
* Select only fixed qualified family routes, never probe, upgrade a pin or fall back.
|
|
23
|
+
* The caller retains the original requested mode separately from this effective selection.
|
|
24
|
+
* @param {string} requested User-requested mode or numeric version.
|
|
25
|
+
* @param {OperationalFamily} family Exact selected family.
|
|
26
|
+
* @returns {string} Effective numeric version.
|
|
27
|
+
*/
|
|
28
|
+
export declare function operationApiVersion(requested: string, family: OperationalFamily): string;
|
|
29
|
+
/**
|
|
30
|
+
* Preserve numeric pinning or resolve numeric SOAP evidence for literal REST latest.
|
|
31
|
+
* Discovery freshness belongs to the caller; this helper never caches or retries.
|
|
32
|
+
* @param {string} requested Exact latest selector or supported numeric syntax.
|
|
33
|
+
* @param {Function} discover Fresh advertised-version discovery supplied by the caller.
|
|
34
|
+
* @returns {Promise<ApiVersionSelection>} Immutable REST selector and numeric SOAP version.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveApiVersion(requested: string, discover: () => Promise<unknown>): Promise<ApiVersionSelection>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const numericVersion = /^\d{2,3}\.0$/u;
|
|
2
|
+
/**
|
|
3
|
+
* Admit the qualified initial native stream pin without widening other families.
|
|
4
|
+
* @param {string} requested Explicit pin or default/auto.
|
|
5
|
+
* @returns {string} Fixed native stream version.
|
|
6
|
+
*/
|
|
7
|
+
export function dataStreamApiVersion(requested = 'auto') {
|
|
8
|
+
if (requested === 'auto' || requested === '68.0')
|
|
9
|
+
return '68.0';
|
|
10
|
+
throw new Error('INVALID_SCOPE');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Admit native DLO, DMO and mapping routes without discovery or upgrading numeric pins.
|
|
14
|
+
* Admission is not a claim of live qualification at every admitted version.
|
|
15
|
+
* @param {string} requested Explicit numeric version or default/auto.
|
|
16
|
+
* @returns {string} Numeric route version.
|
|
17
|
+
*/
|
|
18
|
+
export function nativeApiVersion(requested = 'auto') {
|
|
19
|
+
if (requested === 'auto')
|
|
20
|
+
return '68.0';
|
|
21
|
+
if (numericVersion.test(requested) && Number(requested) >= 61)
|
|
22
|
+
return requested;
|
|
23
|
+
throw new Error('INVALID_SCOPE');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Select only fixed qualified family routes, never probe, upgrade a pin or fall back.
|
|
27
|
+
* The caller retains the original requested mode separately from this effective selection.
|
|
28
|
+
* @param {string} requested User-requested mode or numeric version.
|
|
29
|
+
* @param {OperationalFamily} family Exact selected family.
|
|
30
|
+
* @returns {string} Effective numeric version.
|
|
31
|
+
*/
|
|
32
|
+
export function operationApiVersion(requested, family) {
|
|
33
|
+
switch (family) {
|
|
34
|
+
case 'data-transform':
|
|
35
|
+
case 'dlo': {
|
|
36
|
+
if (requested === 'auto' || requested === '68.0')
|
|
37
|
+
return '68.0';
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'segment':
|
|
41
|
+
case 'calculated-insight':
|
|
42
|
+
case 'identity-resolution':
|
|
43
|
+
case 'data-graph': {
|
|
44
|
+
if (requested === 'auto' || requested === '68.0')
|
|
45
|
+
return '68.0';
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
// No default
|
|
49
|
+
}
|
|
50
|
+
throw new Error('INVALID_SCOPE');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Preserve numeric pinning or resolve numeric SOAP evidence for literal REST latest.
|
|
54
|
+
* Discovery freshness belongs to the caller; this helper never caches or retries.
|
|
55
|
+
* @param {string} requested Exact latest selector or supported numeric syntax.
|
|
56
|
+
* @param {Function} discover Fresh advertised-version discovery supplied by the caller.
|
|
57
|
+
* @returns {Promise<ApiVersionSelection>} Immutable REST selector and numeric SOAP version.
|
|
58
|
+
*/
|
|
59
|
+
export async function resolveApiVersion(requested, discover) {
|
|
60
|
+
if (numericVersion.test(requested)) {
|
|
61
|
+
return Object.freeze({ requested, restSelector: `v${requested}`, soapNumeric: requested });
|
|
62
|
+
}
|
|
63
|
+
if (requested !== 'latest') {
|
|
64
|
+
throw new Error('Use latest or an explicit numeric API version such as 68.0.');
|
|
65
|
+
}
|
|
66
|
+
let advertised;
|
|
67
|
+
try {
|
|
68
|
+
advertised = await discover();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new Error('API version discovery failed. Check org access or use an explicit numeric version.');
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(advertised) || advertised.length === 0) {
|
|
74
|
+
throw new Error('API version discovery returned invalid data. Use an explicit numeric version.');
|
|
75
|
+
}
|
|
76
|
+
let soapNumeric = '';
|
|
77
|
+
for (const entry of advertised) {
|
|
78
|
+
if (!entry ||
|
|
79
|
+
typeof entry !== 'object' ||
|
|
80
|
+
Array.isArray(entry) ||
|
|
81
|
+
typeof entry.version !== 'string' ||
|
|
82
|
+
!numericVersion.test(entry.version)) {
|
|
83
|
+
throw new Error('API version discovery returned invalid data. Use an explicit numeric version.');
|
|
84
|
+
}
|
|
85
|
+
if (!soapNumeric || Number(entry.version) > Number(soapNumeric))
|
|
86
|
+
soapNumeric = entry.version;
|
|
87
|
+
}
|
|
88
|
+
return Object.freeze({ requested, restSelector: 'latest', soapNumeric });
|
|
89
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ConnectClient } from './connect-client.js';
|
|
2
|
+
/** Supplies the authenticated Connection; tests inject a synthetic JSforce one. */
|
|
3
|
+
export type BoundConnection = () => Promise<ConstructorParameters<typeof ConnectClient>[0]>;
|
|
4
|
+
/** The Metadata API CRUD calls of the bound Connection (jsforce `connection.metadata`). */
|
|
5
|
+
export type BoundMetadata = {
|
|
6
|
+
read: (type: string, fullNames: string[]) => Promise<unknown>;
|
|
7
|
+
update: (type: string, metadata: Record<string, unknown>) => Promise<unknown>;
|
|
8
|
+
};
|
|
9
|
+
/** HTTP methods of the bound sender; every method other than GET is a write. */
|
|
10
|
+
export type BoundMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
11
|
+
/** One bound SSOT route sender; see BoundTransport for its resend rules. */
|
|
12
|
+
export type BoundSsot = {
|
|
13
|
+
request: (method: BoundMethod, route: string, noContent?: unknown, body?: unknown) => Promise<unknown>;
|
|
14
|
+
/** Metadata API calls on the same Connection; never a child CLI process. */
|
|
15
|
+
metadata?: () => Promise<BoundMetadata>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Bind SSOT reads and writes, and the Metadata API calls, to one lazily opened authenticated
|
|
19
|
+
* Connection.
|
|
20
|
+
* Failures surface as ConnectError with the retained API diagnostic; callers map them.
|
|
21
|
+
* @param {string} targetOrg Resolved username of the target org.
|
|
22
|
+
* @param {string} version Numeric API version such as 68.0, already normalized by the caller.
|
|
23
|
+
* @param {BoundConnection} [connect] Supplies the Connection; defaults to the CLI auth for targetOrg.
|
|
24
|
+
* @returns {BoundSsot} Sender; a GET is resent once after an expired-session refresh, a write never.
|
|
25
|
+
* Its Metadata API calls use the same Connection.
|
|
26
|
+
*/
|
|
27
|
+
export declare function openBoundSsot(targetOrg: string, version: string, connect?: BoundConnection): BoundSsot;
|