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
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { SegmentError } from './artifacts/segment-document.js';
|
|
2
|
+
export { listSegments, resolveSegment } from './services/segment-lookup.js';
|
|
3
|
+
export type { LookupConnection, SegmentLookup, SegmentRow } from './services/segment-lookup.js';
|
|
4
|
+
export { crossSpaceContext } from './services/cross-space-context.js';
|
|
5
|
+
export { DataSpaceError } from './services/data-space-check.js';
|
|
6
|
+
export { listDataSpaces } from './services/list-data-spaces.js';
|
|
7
|
+
export type { DataSpaceListing } from './services/list-data-spaces.js';
|
|
8
|
+
export { CrossSpaceError } from './services/cross-dataspace-deploy.js';
|
|
9
|
+
export type { CrossSpaceContext } from 'salesforce-data360-rules';
|
|
10
|
+
export { exitCodeOf } from './exit-code.js';
|
|
11
|
+
export { runRetrieve } from './services/run-retrieve.js';
|
|
12
|
+
export type { RetrieveOptions } from './services/run-retrieve.js';
|
|
13
|
+
export type { RetrieveEnvelope } from './commands/data360/retrieve.js';
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Library entry `sf-plugin-data/api`: functions other plugins call over a Connection they hold.
|
|
2
|
+
// Nothing here prints or exits; refusals are thrown as typed errors with a `code`.
|
|
3
|
+
export { SegmentError } from './artifacts/segment-document.js';
|
|
4
|
+
export { listSegments, resolveSegment } from './services/segment-lookup.js';
|
|
5
|
+
export { crossSpaceContext } from './services/cross-space-context.js';
|
|
6
|
+
export { DataSpaceError } from './services/data-space-check.js';
|
|
7
|
+
export { listDataSpaces } from './services/list-data-spaces.js';
|
|
8
|
+
export { CrossSpaceError } from './services/cross-dataspace-deploy.js';
|
|
9
|
+
export { exitCodeOf } from './exit-code.js';
|
|
10
|
+
export { runRetrieve } from './services/run-retrieve.js';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A string field of a document that lives in its own code file next to the JSON (mcdev query
|
|
3
|
+
* style: `<Name>.<type>-meta.json` plus `<Name>.<type>-meta.sql`).
|
|
4
|
+
* - `{ path, extension }`: the string at `path` is one code file.
|
|
5
|
+
* - `{ path, each, key, extension }`: `path` names an array; the `each` string of every element
|
|
6
|
+
* is one code file, named by that element's `key` string.
|
|
7
|
+
*/
|
|
8
|
+
export type CodeField = {
|
|
9
|
+
path: readonly string[];
|
|
10
|
+
extension: string;
|
|
11
|
+
each?: string;
|
|
12
|
+
key?: string;
|
|
13
|
+
};
|
|
14
|
+
/** One code file: `name` is set for array elements (their `key`), absent for a single field. */
|
|
15
|
+
export type CodeFile = {
|
|
16
|
+
extension: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Take the declared code fields out of a document (the document itself is not changed).
|
|
22
|
+
* @param {unknown} value Complete document.
|
|
23
|
+
* @param {readonly CodeField[]} fields Declared code fields.
|
|
24
|
+
* @param {() => Error} invalid Error for a missing, non-string or ambiguous code field.
|
|
25
|
+
* @returns {{document: Record<string, unknown>; files: CodeFile[]}} Document without the code fields and the code files, in declaration and array order.
|
|
26
|
+
*/
|
|
27
|
+
export declare function splitCodeFields(value: unknown, fields: readonly CodeField[], invalid: () => Error): {
|
|
28
|
+
document: Record<string, unknown>;
|
|
29
|
+
files: CodeFile[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Put code files back into a document split by `splitCodeFields`; every declared field needs
|
|
33
|
+
* exactly its file and no file may be left over.
|
|
34
|
+
* @param {unknown} value Document without the code fields.
|
|
35
|
+
* @param {readonly CodeField[]} fields Declared code fields.
|
|
36
|
+
* @param {readonly CodeFile[]} files Code file contents.
|
|
37
|
+
* @param {() => Error} invalid Error for a missing, extra or already present code field.
|
|
38
|
+
* @returns {Record<string, unknown>} Complete document.
|
|
39
|
+
*/
|
|
40
|
+
export declare function joinCodeFields(value: unknown, fields: readonly CodeField[], files: readonly CodeFile[], invalid: () => Error): Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Path of a code file next to its JSON file: `X.type-meta.json` → `X.type-meta.sql`, or
|
|
43
|
+
* `X.type-meta.<name>.sql` for an array element; likewise `X.segment.json` gives
|
|
44
|
+
* `X.segment.<name>.sql`.
|
|
45
|
+
* @param {string} jsonPath Path of the JSON file, ending in `.json`.
|
|
46
|
+
* @param {Pick<CodeFile, 'extension' | 'name'>} file Code file.
|
|
47
|
+
* @returns {string} Code file path.
|
|
48
|
+
*/
|
|
49
|
+
export declare function codeFilePath(jsonPath: string, file: Pick<CodeFile, 'extension' | 'name'>): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const safeName = /^[A-Za-z0-9][A-Za-z0-9_]*$/u;
|
|
2
|
+
const safeExtension = /^[a-z]+$/u;
|
|
3
|
+
/**
|
|
4
|
+
* Whether a value is a plain JSON object.
|
|
5
|
+
* @param {unknown} value Candidate.
|
|
6
|
+
* @returns {boolean} Object and not an array.
|
|
7
|
+
*/
|
|
8
|
+
function isBag(value) {
|
|
9
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The object holding a field's last path segment.
|
|
13
|
+
* @param {Bag} document Document.
|
|
14
|
+
* @param {readonly string[]} path Field path.
|
|
15
|
+
* @param {() => Error} invalid Error for a missing or non-object step.
|
|
16
|
+
* @returns {Bag} Parent object.
|
|
17
|
+
*/
|
|
18
|
+
function parent(document, path, invalid) {
|
|
19
|
+
let current = document;
|
|
20
|
+
for (const step of path.slice(0, -1)) {
|
|
21
|
+
if (!isBag(current))
|
|
22
|
+
throw invalid();
|
|
23
|
+
current = current[step];
|
|
24
|
+
}
|
|
25
|
+
if (!isBag(current) || path.length === 0)
|
|
26
|
+
throw invalid();
|
|
27
|
+
return current;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The array elements of an `each` field, every one a plain object.
|
|
31
|
+
* @param {Bag} holder Parent object.
|
|
32
|
+
* @param {string} last Array property.
|
|
33
|
+
* @param {() => Error} invalid Error for a malformed array.
|
|
34
|
+
* @returns {Bag[]} Elements.
|
|
35
|
+
*/
|
|
36
|
+
function elements(holder, last, invalid) {
|
|
37
|
+
const list = holder[last];
|
|
38
|
+
if (!Array.isArray(list) || !list.every((element) => isBag(element)))
|
|
39
|
+
throw invalid();
|
|
40
|
+
return list;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Take the declared code fields out of a document (the document itself is not changed).
|
|
44
|
+
* @param {unknown} value Complete document.
|
|
45
|
+
* @param {readonly CodeField[]} fields Declared code fields.
|
|
46
|
+
* @param {() => Error} invalid Error for a missing, non-string or ambiguous code field.
|
|
47
|
+
* @returns {{document: Record<string, unknown>; files: CodeFile[]}} Document without the code fields and the code files, in declaration and array order.
|
|
48
|
+
*/
|
|
49
|
+
export function splitCodeFields(value, fields, invalid) {
|
|
50
|
+
if (!isBag(value))
|
|
51
|
+
throw invalid();
|
|
52
|
+
const document = structuredClone(value);
|
|
53
|
+
const files = [];
|
|
54
|
+
for (const field of fields) {
|
|
55
|
+
if (!safeExtension.test(field.extension))
|
|
56
|
+
throw invalid();
|
|
57
|
+
const holder = parent(document, field.path, invalid);
|
|
58
|
+
const last = field.path.at(-1);
|
|
59
|
+
if (field.each === undefined) {
|
|
60
|
+
const text = holder[last];
|
|
61
|
+
if (typeof text !== 'string')
|
|
62
|
+
throw invalid();
|
|
63
|
+
delete holder[last];
|
|
64
|
+
files.push({ extension: field.extension, text });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const names = new Set();
|
|
68
|
+
for (const element of elements(holder, last, invalid)) {
|
|
69
|
+
const name = element[field.key ?? ''];
|
|
70
|
+
const text = element[field.each];
|
|
71
|
+
if (typeof name !== 'string' || !safeName.test(name) || typeof text !== 'string')
|
|
72
|
+
throw invalid();
|
|
73
|
+
if (names.has(name.toLowerCase()))
|
|
74
|
+
throw invalid();
|
|
75
|
+
names.add(name.toLowerCase());
|
|
76
|
+
delete element[field.each];
|
|
77
|
+
files.push({ extension: field.extension, name, text });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { document, files };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Put code files back into a document split by `splitCodeFields`; every declared field needs
|
|
84
|
+
* exactly its file and no file may be left over.
|
|
85
|
+
* @param {unknown} value Document without the code fields.
|
|
86
|
+
* @param {readonly CodeField[]} fields Declared code fields.
|
|
87
|
+
* @param {readonly CodeFile[]} files Code file contents.
|
|
88
|
+
* @param {() => Error} invalid Error for a missing, extra or already present code field.
|
|
89
|
+
* @returns {Record<string, unknown>} Complete document.
|
|
90
|
+
*/
|
|
91
|
+
export function joinCodeFields(value, fields, files, invalid) {
|
|
92
|
+
if (!isBag(value))
|
|
93
|
+
throw invalid();
|
|
94
|
+
const document = structuredClone(value);
|
|
95
|
+
const pending = new Map();
|
|
96
|
+
for (const file of files) {
|
|
97
|
+
const id = `${file.extension}:${file.name ?? ''}`.toLowerCase();
|
|
98
|
+
if (pending.has(id) || typeof file.text !== 'string')
|
|
99
|
+
throw invalid();
|
|
100
|
+
pending.set(id, file.text);
|
|
101
|
+
}
|
|
102
|
+
const take = (extension, name) => {
|
|
103
|
+
const id = `${extension}:${name ?? ''}`.toLowerCase();
|
|
104
|
+
const text = pending.get(id);
|
|
105
|
+
if (text === undefined)
|
|
106
|
+
throw invalid();
|
|
107
|
+
pending.delete(id);
|
|
108
|
+
return text;
|
|
109
|
+
};
|
|
110
|
+
for (const field of fields) {
|
|
111
|
+
const holder = parent(document, field.path, invalid);
|
|
112
|
+
const last = field.path.at(-1);
|
|
113
|
+
if (field.each === undefined) {
|
|
114
|
+
if (Object.hasOwn(holder, last))
|
|
115
|
+
throw invalid();
|
|
116
|
+
holder[last] = take(field.extension);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
for (const element of elements(holder, last, invalid)) {
|
|
120
|
+
const name = element[field.key ?? ''];
|
|
121
|
+
if (typeof name !== 'string' || !safeName.test(name) || Object.hasOwn(element, field.each))
|
|
122
|
+
throw invalid();
|
|
123
|
+
element[field.each] = take(field.extension, name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (pending.size > 0)
|
|
127
|
+
throw invalid();
|
|
128
|
+
return document;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Path of a code file next to its JSON file: `X.type-meta.json` → `X.type-meta.sql`, or
|
|
132
|
+
* `X.type-meta.<name>.sql` for an array element; likewise `X.segment.json` gives
|
|
133
|
+
* `X.segment.<name>.sql`.
|
|
134
|
+
* @param {string} jsonPath Path of the JSON file, ending in `.json`.
|
|
135
|
+
* @param {Pick<CodeFile, 'extension' | 'name'>} file Code file.
|
|
136
|
+
* @returns {string} Code file path.
|
|
137
|
+
*/
|
|
138
|
+
export function codeFilePath(jsonPath, file) {
|
|
139
|
+
if (!jsonPath.endsWith('.json'))
|
|
140
|
+
throw new Error('Code files sit next to .json files.');
|
|
141
|
+
return `${jsonPath.slice(0, -'json'.length)}${file.name === undefined ? '' : `${file.name}.`}${file.extension}`;
|
|
142
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Payload-free failure for unqualified Graph configuration. */
|
|
2
|
+
export declare class DataGraphError extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code?: string);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Require a qualified invariant without retaining raw data.
|
|
8
|
+
* @param {unknown} value Required invariant.
|
|
9
|
+
*/
|
|
10
|
+
export declare function graphRequire(value: unknown): asserts value;
|
|
11
|
+
/**
|
|
12
|
+
* Validate an exact record.
|
|
13
|
+
* @param {unknown} value Candidate.
|
|
14
|
+
* @param {string[]} keys Inventory.
|
|
15
|
+
* @returns {Record<string, unknown>} Checked record.
|
|
16
|
+
*/
|
|
17
|
+
export declare function graphRecord(value: unknown, keys?: string[]): Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Validate nonblank private identity/display text.
|
|
20
|
+
* @param {unknown} value Candidate.
|
|
21
|
+
*/
|
|
22
|
+
export declare function graphText(value: unknown): asserts value is string;
|
|
23
|
+
/**
|
|
24
|
+
* Stabilize JSON object keys without changing any array order.
|
|
25
|
+
* @param {unknown} value Detached JSON.
|
|
26
|
+
* @returns {unknown} Stable JSON.
|
|
27
|
+
*/
|
|
28
|
+
export declare function graphCanonicalObject(value: unknown): unknown;
|
|
29
|
+
export { dataGraphName } from './path-selector.js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Payload-free failure for unqualified Graph configuration. */
|
|
2
|
+
export class DataGraphError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code = 'UNSUPPORTED_DATA_GRAPH_CONFIGURATION') {
|
|
5
|
+
super('Data graph configuration could not be admitted.');
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = 'DataGraphError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Require a qualified invariant without retaining raw data.
|
|
12
|
+
* @param {unknown} value Required invariant.
|
|
13
|
+
*/
|
|
14
|
+
export function graphRequire(value) {
|
|
15
|
+
if (!value)
|
|
16
|
+
throw new DataGraphError();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validate an exact record.
|
|
20
|
+
* @param {unknown} value Candidate.
|
|
21
|
+
* @param {string[]} keys Inventory.
|
|
22
|
+
* @returns {Record<string, unknown>} Checked record.
|
|
23
|
+
*/
|
|
24
|
+
export function graphRecord(value, keys) {
|
|
25
|
+
graphRequire(value && typeof value === 'object' && !Array.isArray(value));
|
|
26
|
+
if (keys)
|
|
27
|
+
graphRequire(Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key)));
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validate nonblank private identity/display text.
|
|
32
|
+
* @param {unknown} value Candidate.
|
|
33
|
+
*/
|
|
34
|
+
export function graphText(value) {
|
|
35
|
+
graphRequire(typeof value === 'string' && value.trim().length > 0);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stabilize JSON object keys without changing any array order.
|
|
39
|
+
* @param {unknown} value Detached JSON.
|
|
40
|
+
* @returns {unknown} Stable JSON.
|
|
41
|
+
*/
|
|
42
|
+
export function graphCanonicalObject(value) {
|
|
43
|
+
if (Array.isArray(value))
|
|
44
|
+
return value.map((item) => graphCanonicalObject(item));
|
|
45
|
+
if (value && typeof value === 'object') {
|
|
46
|
+
// eslint-disable-next-line unicorn/no-array-sort -- ES2022 library target; keys is a new array.
|
|
47
|
+
const keys = Object.keys(value).sort();
|
|
48
|
+
return Object.fromEntries(keys.map((key) => [key, graphCanonicalObject(graphRecord(value)[key])]));
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
export { dataGraphName } from './path-selector.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `c__dataSpace` key of a plugin file: the data space (or, for a DLO, the data spaces) the
|
|
3
|
+
* component belongs to. It replaces `identity.dataSpace`; pre-alpha, so a file that still has the
|
|
4
|
+
* old key is refused instead of migrated.
|
|
5
|
+
*/
|
|
6
|
+
export declare const dataSpaceKey = "c__dataSpace";
|
|
7
|
+
/** Builds the family's refusal for a key path of the file. */
|
|
8
|
+
export type DataSpaceRefusal = (code: string, keyPath: string, problem: string) => Error;
|
|
9
|
+
/**
|
|
10
|
+
* Whether a value is a usable data space name: non-empty, without surrounding blanks or control
|
|
11
|
+
* characters. Whether the org knows it is checked live, once per command.
|
|
12
|
+
* @param {unknown} value Untrusted value.
|
|
13
|
+
* @returns {boolean} Usable name.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDataSpaceName(value: unknown): value is string;
|
|
16
|
+
/**
|
|
17
|
+
* Refuse the old `identity.dataSpace` key (files are not migrated).
|
|
18
|
+
* @param {Record<string, unknown>} identity The `identity` object of the file.
|
|
19
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
20
|
+
*/
|
|
21
|
+
export declare function refuseLegacyDataSpace(identity: Record<string, unknown>, refuse: DataSpaceRefusal): void;
|
|
22
|
+
/**
|
|
23
|
+
* Read the single data space of a file (every type except DLOs and streams).
|
|
24
|
+
* @param {Record<string, unknown>} document The file.
|
|
25
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
26
|
+
* @returns {string} The data space name.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readSingleDataSpace(document: Record<string, unknown>, refuse: DataSpaceRefusal): string;
|
|
29
|
+
/**
|
|
30
|
+
* Read the data space list of a DLO (or stream) file: at least one entry, each a data space
|
|
31
|
+
* name, none repeated. An entry `{ "name": …, "filter": … }` (a filtered membership) is
|
|
32
|
+
* recognised but refused until a live round-trip of a filter is proven.
|
|
33
|
+
* @param {Record<string, unknown>} document The file.
|
|
34
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
35
|
+
* @returns {string[]} The data space names, in file order.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readDataSpaceList(document: Record<string, unknown>, refuse: DataSpaceRefusal): string[];
|
|
38
|
+
/**
|
|
39
|
+
* The deterministic file order of a data space list: sorted by code point.
|
|
40
|
+
* @param {Iterable<string>} names Data space names.
|
|
41
|
+
* @returns {string[]} Sorted copy without repeats.
|
|
42
|
+
*/
|
|
43
|
+
export declare function sortedDataSpaces(names: Iterable<string>): string[];
|
|
44
|
+
/**
|
|
45
|
+
* The identity a result item reports for a document: its API name and its data space, from
|
|
46
|
+
* `c__dataSpace` when the file names one, otherwise from `identity.dataSpace` (the kinds not
|
|
47
|
+
* converted yet), otherwise (a DLO: no single data space in its file) the run's data space.
|
|
48
|
+
* @param {object} document Document or verbatim document.
|
|
49
|
+
* @param {object} document.identity Its identity.
|
|
50
|
+
* @param {string} document.identity.apiName API name.
|
|
51
|
+
* @param {string} [document.identity.dataSpace] Data space, when the file keeps it there.
|
|
52
|
+
* @param {unknown} [document.c__dataSpace] The file's c__dataSpace (a text for a single space).
|
|
53
|
+
* @param {string} dataSpace The run's data space.
|
|
54
|
+
* @returns {{dataSpace: string; apiName: string}} Reported identity.
|
|
55
|
+
*/
|
|
56
|
+
export declare function reportedIdentity(document: {
|
|
57
|
+
identity: {
|
|
58
|
+
apiName: string;
|
|
59
|
+
dataSpace?: string;
|
|
60
|
+
};
|
|
61
|
+
c__dataSpace?: unknown;
|
|
62
|
+
}, dataSpace: string): {
|
|
63
|
+
dataSpace: string;
|
|
64
|
+
apiName: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `c__dataSpace` key of a plugin file: the data space (or, for a DLO, the data spaces) the
|
|
3
|
+
* component belongs to. It replaces `identity.dataSpace`; pre-alpha, so a file that still has the
|
|
4
|
+
* old key is refused instead of migrated.
|
|
5
|
+
*/
|
|
6
|
+
export const dataSpaceKey = 'c__dataSpace';
|
|
7
|
+
/**
|
|
8
|
+
* Whether a value is a usable data space name: non-empty, without surrounding blanks or control
|
|
9
|
+
* characters. Whether the org knows it is checked live, once per command.
|
|
10
|
+
* @param {unknown} value Untrusted value.
|
|
11
|
+
* @returns {boolean} Usable name.
|
|
12
|
+
*/
|
|
13
|
+
export function isDataSpaceName(value) {
|
|
14
|
+
return (typeof value === 'string' &&
|
|
15
|
+
value.trim() !== '' &&
|
|
16
|
+
value === value.trim() &&
|
|
17
|
+
![...value].some((character) => character.codePointAt(0) < 32 || character.codePointAt(0) === 127));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Refuse the old `identity.dataSpace` key (files are not migrated).
|
|
21
|
+
* @param {Record<string, unknown>} identity The `identity` object of the file.
|
|
22
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
23
|
+
*/
|
|
24
|
+
export function refuseLegacyDataSpace(identity, refuse) {
|
|
25
|
+
if (Object.hasOwn(identity, 'dataSpace'))
|
|
26
|
+
throw refuse('LEGACY_DATASPACE_KEY', 'identity.dataSpace', `is the old place of the data space; move it to the top-level key ${dataSpaceKey}, or retrieve the component again`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read the single data space of a file (every type except DLOs and streams).
|
|
30
|
+
* @param {Record<string, unknown>} document The file.
|
|
31
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
32
|
+
* @returns {string} The data space name.
|
|
33
|
+
*/
|
|
34
|
+
export function readSingleDataSpace(document, refuse) {
|
|
35
|
+
const value = document[dataSpaceKey];
|
|
36
|
+
if (!isDataSpaceName(value))
|
|
37
|
+
throw refuse('INVALID_DATASPACE_FIELD', dataSpaceKey, 'must be a data space name');
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the data space list of a DLO (or stream) file: at least one entry, each a data space
|
|
42
|
+
* name, none repeated. An entry `{ "name": …, "filter": … }` (a filtered membership) is
|
|
43
|
+
* recognised but refused until a live round-trip of a filter is proven.
|
|
44
|
+
* @param {Record<string, unknown>} document The file.
|
|
45
|
+
* @param {DataSpaceRefusal} refuse Family refusal.
|
|
46
|
+
* @returns {string[]} The data space names, in file order.
|
|
47
|
+
*/
|
|
48
|
+
export function readDataSpaceList(document, refuse) {
|
|
49
|
+
const value = document[dataSpaceKey];
|
|
50
|
+
if (!Array.isArray(value))
|
|
51
|
+
throw refuse('INVALID_DATASPACE_FIELD', dataSpaceKey, 'must be a list of data space names');
|
|
52
|
+
if (value.length === 0)
|
|
53
|
+
throw refuse('INVALID_DATASPACE_FIELD', dataSpaceKey, 'must list at least one data space');
|
|
54
|
+
const names = [];
|
|
55
|
+
for (const [index, entry] of value.entries()) {
|
|
56
|
+
const at = `${dataSpaceKey}[${index}]`;
|
|
57
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
|
|
58
|
+
const keys = Object.keys(entry);
|
|
59
|
+
if (keys.includes('name') && keys.includes('filter') && keys.length === 2)
|
|
60
|
+
throw refuse('UNSUPPORTED_DATASPACE_FILTER', at, 'is a filtered membership, which the plugin does not deploy yet');
|
|
61
|
+
}
|
|
62
|
+
if (!isDataSpaceName(entry))
|
|
63
|
+
throw refuse('INVALID_DATASPACE_FIELD', at, 'must be a data space name');
|
|
64
|
+
if (names.includes(entry))
|
|
65
|
+
throw refuse('INVALID_DATASPACE_FIELD', at, 'repeats another data space of the list');
|
|
66
|
+
names.push(entry);
|
|
67
|
+
}
|
|
68
|
+
return names;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The deterministic file order of a data space list: sorted by code point.
|
|
72
|
+
* @param {Iterable<string>} names Data space names.
|
|
73
|
+
* @returns {string[]} Sorted copy without repeats.
|
|
74
|
+
*/
|
|
75
|
+
export function sortedDataSpaces(names) {
|
|
76
|
+
// eslint-disable-next-line unicorn/no-array-sort -- Sort a fresh copy within the ES2022 library target.
|
|
77
|
+
return [...new Set(names)].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The identity a result item reports for a document: its API name and its data space, from
|
|
81
|
+
* `c__dataSpace` when the file names one, otherwise from `identity.dataSpace` (the kinds not
|
|
82
|
+
* converted yet), otherwise (a DLO: no single data space in its file) the run's data space.
|
|
83
|
+
* @param {object} document Document or verbatim document.
|
|
84
|
+
* @param {object} document.identity Its identity.
|
|
85
|
+
* @param {string} document.identity.apiName API name.
|
|
86
|
+
* @param {string} [document.identity.dataSpace] Data space, when the file keeps it there.
|
|
87
|
+
* @param {unknown} [document.c__dataSpace] The file's c__dataSpace (a text for a single space).
|
|
88
|
+
* @param {string} dataSpace The run's data space.
|
|
89
|
+
* @returns {{dataSpace: string; apiName: string}} Reported identity.
|
|
90
|
+
*/
|
|
91
|
+
export function reportedIdentity(document, dataSpace) {
|
|
92
|
+
return {
|
|
93
|
+
dataSpace: typeof document.c__dataSpace === 'string'
|
|
94
|
+
? document.c__dataSpace
|
|
95
|
+
: (document.identity.dataSpace ?? dataSpace),
|
|
96
|
+
apiName: document.identity.apiName,
|
|
97
|
+
};
|
|
98
|
+
}
|