@cclabsnz/sf-core 0.3.0 → 0.5.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/CHANGELOG.md +149 -0
- package/README.md +32 -8
- package/lib/events/rteCatalog.d.ts +17 -1
- package/lib/events/rteCatalog.js +28 -4
- package/lib/graph/coverage.d.ts +3 -0
- package/lib/graph/coverage.js +10 -0
- package/lib/graph/index.d.ts +9 -0
- package/lib/graph/index.js +10 -0
- package/lib/graph/kinds.d.ts +109 -0
- package/lib/graph/kinds.js +39 -0
- package/lib/graph/merge.d.ts +24 -0
- package/lib/graph/merge.js +175 -0
- package/lib/graph/roleOf.d.ts +17 -0
- package/lib/graph/roleOf.js +56 -0
- package/lib/graph/rules.d.ts +34 -0
- package/lib/graph/rules.js +30 -0
- package/lib/graph/schema.d.ts +170 -0
- package/lib/graph/schema.js +91 -0
- package/lib/graph/types.d.ts +84 -0
- package/lib/graph/types.js +10 -0
- package/lib/graph/validate.d.ts +8 -0
- package/lib/graph/validate.js +200 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/lib/order.d.ts +2 -0
- package/lib/lib/order.js +10 -0
- package/lib/report/branding.js +1 -1
- package/package.json +12 -7
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { SUPPORTED_GRAPH_SCHEMA_VERSION } from './types.js';
|
|
2
|
+
import { GRAPH_RULES } from './rules.js';
|
|
3
|
+
import { isKnownGraphKind, ownerOfKind } from './kinds.js';
|
|
4
|
+
import { codepointCompare } from '../lib/order.js';
|
|
5
|
+
function mergeCoverage(fragments) {
|
|
6
|
+
return {
|
|
7
|
+
notes: fragments.flatMap((f) => f.coverage.notes),
|
|
8
|
+
unavailable: fragments.flatMap((f) => f.coverage.unavailable),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Sorted the same way regardless of the order the caller passed fragments in. Spec section 12. */
|
|
12
|
+
function sortFindings(findings) {
|
|
13
|
+
return findings.sort((a, b) => codepointCompare(a.code, b.code) || codepointCompare(a.id, b.id));
|
|
14
|
+
}
|
|
15
|
+
export function mergeGraphs(fragments) {
|
|
16
|
+
if (fragments.length === 0) {
|
|
17
|
+
return {
|
|
18
|
+
graph: null,
|
|
19
|
+
findings: [
|
|
20
|
+
{
|
|
21
|
+
code: GRAPH_RULES.MERGE_NO_FRAGMENTS,
|
|
22
|
+
id: 'document',
|
|
23
|
+
message: 'No fragments were supplied to merge.',
|
|
24
|
+
fix: 'Pass at least one canonical graph fragment to merge.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
report: { fragments: [], contributionsApplied: 0 },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const report = {
|
|
31
|
+
fragments: fragments.map((f) => ({ producer: f.producer ?? null, capturedAt: f.capturedAt })),
|
|
32
|
+
contributionsApplied: 0,
|
|
33
|
+
};
|
|
34
|
+
const findings = [];
|
|
35
|
+
const orgIds = [...new Set(fragments.map((f) => f.orgId))];
|
|
36
|
+
if (orgIds.length > 1) {
|
|
37
|
+
findings.push({
|
|
38
|
+
code: GRAPH_RULES.MERGE_ORG_MISMATCH,
|
|
39
|
+
id: 'document',
|
|
40
|
+
message: `Fragments describe different orgs: ${orgIds.join(', ')}.`,
|
|
41
|
+
fix: 'Merge fragments captured from one org. Re-run whichever producer targeted the other.',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const versions = [...new Set(fragments.map((f) => f.schemaVersion))];
|
|
45
|
+
if (versions.length > 1) {
|
|
46
|
+
findings.push({
|
|
47
|
+
code: GRAPH_RULES.MERGE_SCHEMA_VERSION_MISMATCH,
|
|
48
|
+
id: 'document',
|
|
49
|
+
message: `Fragments are at different schema versions: ${versions.join(', ')}.`,
|
|
50
|
+
fix: `Re-produce every fragment with a build that writes ${SUPPORTED_GRAPH_SCHEMA_VERSION}.`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else if (versions[0] !== SUPPORTED_GRAPH_SCHEMA_VERSION) {
|
|
54
|
+
// Every fragment agrees with every other, so the mismatch rule above never fires -- but they
|
|
55
|
+
// can all agree on a version this build no longer supports. Two fragments from a pre-bump
|
|
56
|
+
// build are the day-one case: they merge clean and the operator would otherwise only learn
|
|
57
|
+
// about it from a finding naming the merged OUTPUT, not the stale input that caused it.
|
|
58
|
+
findings.push({
|
|
59
|
+
code: GRAPH_RULES.MERGE_SCHEMA_VERSION_MISMATCH,
|
|
60
|
+
id: 'document',
|
|
61
|
+
message: `Fragments agree on schema version ${versions[0]}, which this build does not support.`,
|
|
62
|
+
fix: `Re-produce every fragment with a build that writes ${SUPPORTED_GRAPH_SCHEMA_VERSION}.`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const seen = new Map();
|
|
66
|
+
for (const [index, f] of fragments.entries()) {
|
|
67
|
+
for (const node of f.nodes) {
|
|
68
|
+
const first = seen.get(node.id);
|
|
69
|
+
if (first !== undefined) {
|
|
70
|
+
const message = first === index
|
|
71
|
+
? `Node ${node.id} is claimed twice within fragment ${index + 1}. ` +
|
|
72
|
+
'One node is one fact; two fragments asserting it is two facts wearing one id.'
|
|
73
|
+
: `Node ${node.id} is claimed by fragment ${first + 1} and fragment ${index + 1}. ` +
|
|
74
|
+
'One node is one fact; two fragments asserting it is two facts wearing one id.';
|
|
75
|
+
findings.push({
|
|
76
|
+
code: GRAPH_RULES.MERGE_ID_COLLISION,
|
|
77
|
+
id: node.id,
|
|
78
|
+
message,
|
|
79
|
+
fix: 'Give one producer the kind, per GRAPH_KIND_TABLE, and stop the other emitting it.',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
seen.set(node.id, index);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const f of fragments) {
|
|
88
|
+
// An unnamed producer cannot violate an ownership rule -- a hand-written or older fragment
|
|
89
|
+
// is still merged, and the id-collision rule above covers the harm ownership prevents.
|
|
90
|
+
if (!f.producer)
|
|
91
|
+
continue;
|
|
92
|
+
for (const node of f.nodes) {
|
|
93
|
+
if (!isKnownGraphKind(node.kind))
|
|
94
|
+
continue;
|
|
95
|
+
const owner = ownerOfKind(node.kind);
|
|
96
|
+
if (owner === f.producer)
|
|
97
|
+
continue;
|
|
98
|
+
findings.push({
|
|
99
|
+
code: GRAPH_RULES.MERGE_KIND_NOT_OWNED,
|
|
100
|
+
id: node.id,
|
|
101
|
+
message: `Fragment from ${f.producer} emits kind ${node.kind}, which ${owner} owns.`,
|
|
102
|
+
fix: `Emit ${node.kind} from ${owner}, or move its ownership in GRAPH_KIND_TABLE if the design changed.`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (findings.length > 0)
|
|
107
|
+
return { graph: null, findings: sortFindings(findings), report };
|
|
108
|
+
// Copied, never mutated: the caller may still be holding the fragments it passed in.
|
|
109
|
+
const nodes = fragments.flatMap((f) => f.nodes).map((n) => ({ ...n, attrs: { ...n.attrs } }));
|
|
110
|
+
const edges = fragments.flatMap((f) => f.edges).map((e) => ({ ...e, attrs: { ...e.attrs } }));
|
|
111
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
112
|
+
for (const f of fragments) {
|
|
113
|
+
for (const c of f.contributions ?? []) {
|
|
114
|
+
if (!f.producer) {
|
|
115
|
+
// Namespaced by contributor: an unnamespaced patch makes "who asserted this"
|
|
116
|
+
// unanswerable, and two anonymous fragments contributing the same key would be a silent
|
|
117
|
+
// last-writer-wins -- exactly what namespacing exists to prevent. Skipped, not merged
|
|
118
|
+
// under a shared 'unknown' bucket.
|
|
119
|
+
findings.push({
|
|
120
|
+
code: GRAPH_RULES.MERGE_CONTRIBUTION_UNATTRIBUTED,
|
|
121
|
+
id: c.nodeId,
|
|
122
|
+
message: `A fragment with no producer contributes attributes to ${c.nodeId}. An unattributed ` +
|
|
123
|
+
'contribution cannot be namespaced, so it was not applied.',
|
|
124
|
+
fix: 'Set `producer` on the fragment that contributes attributes, or drop the contribution.',
|
|
125
|
+
});
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const target = byId.get(c.nodeId);
|
|
129
|
+
if (!target) {
|
|
130
|
+
findings.push({
|
|
131
|
+
code: GRAPH_RULES.MERGE_CONTRIBUTION_UNRESOLVED,
|
|
132
|
+
id: c.nodeId,
|
|
133
|
+
message: `${f.producer} contributes attributes to ${c.nodeId}, which no fragment provides.`,
|
|
134
|
+
fix: 'Include the fragment that owns that node, or stop contributing to it.',
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const ns = f.producer;
|
|
139
|
+
target.attrs[ns] = { ...target.attrs[ns], ...c.attrs };
|
|
140
|
+
report.contributionsApplied += 1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// The oldest, not the newest. A merged picture is only as fresh as its stalest part, and
|
|
144
|
+
// taking the newest would let a fresh fragment make a month-old one look current. Compare
|
|
145
|
+
// chronologically, not lexically: two independently-written tools are not guaranteed to agree
|
|
146
|
+
// on timezone offset or fractional-second precision, and a lexical `<` gets those wrong (e.g.
|
|
147
|
+
// '...+05:00' can sort after a numerically earlier '...Z' instant). The ORIGINAL string is
|
|
148
|
+
// kept as the value -- never round-tripped through a Date and re-serialised, which would
|
|
149
|
+
// silently rewrite the caller's format. `Date.parse` returns NaN on an unparseable string, and
|
|
150
|
+
// NaN comparisons are always false, so an unguarded reduce lets a bad value at index 0 always
|
|
151
|
+
// win and a bad value elsewhere always lose, silently. A parseable timestamp is preferred over
|
|
152
|
+
// an unparseable one; only when every fragment is unparseable does the first one's string win.
|
|
153
|
+
const capturedAt = fragments.map((f) => f.capturedAt).reduce((oldest, t) => {
|
|
154
|
+
const oldestParsed = Date.parse(oldest);
|
|
155
|
+
const tParsed = Date.parse(t);
|
|
156
|
+
if (Number.isNaN(oldestParsed))
|
|
157
|
+
return Number.isNaN(tParsed) ? oldest : t;
|
|
158
|
+
if (Number.isNaN(tParsed))
|
|
159
|
+
return oldest;
|
|
160
|
+
return tParsed < oldestParsed ? t : oldest;
|
|
161
|
+
});
|
|
162
|
+
const graph = {
|
|
163
|
+
schemaVersion: fragments[0].schemaVersion,
|
|
164
|
+
capturedAt,
|
|
165
|
+
orgId: fragments[0].orgId,
|
|
166
|
+
nodes: nodes.sort((a, b) => codepointCompare(a.id, b.id)),
|
|
167
|
+
edges: edges.sort((a, b) => codepointCompare(a.from, b.from) ||
|
|
168
|
+
codepointCompare(a.to, b.to) ||
|
|
169
|
+
codepointCompare(a.kind, b.kind) ||
|
|
170
|
+
codepointCompare(a.provenance.source, b.provenance.source)),
|
|
171
|
+
coverage: mergeCoverage(fragments),
|
|
172
|
+
};
|
|
173
|
+
return { graph, findings: sortFindings(findings), report };
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Architectural layers of a Salesforce org's coupling graph.
|
|
3
|
+
*
|
|
4
|
+
* A real org's graph is dominated by objects that carry no business process — User, Profile,
|
|
5
|
+
* PermissionSet, logger tables, custom metadata — because Apex references them constantly.
|
|
6
|
+
* Filtering them out is tempting and wrong: on a production org, business↔security was the
|
|
7
|
+
* second-heaviest relationship in the entire graph, behind only business-internal coupling.
|
|
8
|
+
* That is a genuine architectural finding (the business model is deeply wired into the
|
|
9
|
+
* permission model) and deleting the objects deletes the finding.
|
|
10
|
+
*
|
|
11
|
+
* Classifying instead of filtering keeps every object, and turns the noise into structure.
|
|
12
|
+
*/
|
|
13
|
+
import type { ObjectLayer } from '../schemas/index.js';
|
|
14
|
+
export declare const OBJECT_LAYER_DESCRIPTIONS: Readonly<Record<ObjectLayer, string>>;
|
|
15
|
+
/** Which layer an object belongs to. Unrecognised objects are business, never hidden. */
|
|
16
|
+
export declare function roleOf(object: string): ObjectLayer;
|
|
17
|
+
//# sourceMappingURL=roleOf.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Architectural layers of a Salesforce org's coupling graph.
|
|
3
|
+
*
|
|
4
|
+
* A real org's graph is dominated by objects that carry no business process — User, Profile,
|
|
5
|
+
* PermissionSet, logger tables, custom metadata — because Apex references them constantly.
|
|
6
|
+
* Filtering them out is tempting and wrong: on a production org, business↔security was the
|
|
7
|
+
* second-heaviest relationship in the entire graph, behind only business-internal coupling.
|
|
8
|
+
* That is a genuine architectural finding (the business model is deeply wired into the
|
|
9
|
+
* permission model) and deleting the objects deletes the finding.
|
|
10
|
+
*
|
|
11
|
+
* Classifying instead of filtering keeps every object, and turns the noise into structure.
|
|
12
|
+
*/
|
|
13
|
+
export const OBJECT_LAYER_DESCRIPTIONS = {
|
|
14
|
+
integration: 'platform events and external data',
|
|
15
|
+
configuration: 'custom metadata driving behaviour',
|
|
16
|
+
business: 'business process',
|
|
17
|
+
content: 'files, documents and email',
|
|
18
|
+
sharing: 'sharing, history and change tracking',
|
|
19
|
+
security: 'identity and permissions',
|
|
20
|
+
observability: 'logging and instrumentation',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Setup and platform objects. Matched exactly rather than by prefix: `Contract` must not be
|
|
24
|
+
* mistaken for `ContentDocument`, nor `UserStory__c` for `User`.
|
|
25
|
+
*/
|
|
26
|
+
const SECURITY_OBJECTS = new Set([
|
|
27
|
+
'User', 'Profile', 'PermissionSet', 'PermissionSetAssignment', 'PermissionSetGroup',
|
|
28
|
+
'PermissionSetGroupComponent', 'PermissionSetLicense', 'PermissionSetLicenseAssign',
|
|
29
|
+
'UserRole', 'UserLicense', 'UserRecordAccess', 'UserPermissionAccess', 'SetupEntityAccess',
|
|
30
|
+
'CustomPermission', 'Organization', 'LoginHistory', 'AuthSession', 'AuthProvider',
|
|
31
|
+
'ThirdPartyAccountLink', 'CronTrigger', 'AsyncApexJob', 'ApexClass', 'ApexTrigger',
|
|
32
|
+
'ApexEmailNotification', 'AuraDefinitionBundle', 'FlowDefinitionView', 'FlowVersionView',
|
|
33
|
+
'Group', 'GroupMember', 'QueueSobject', 'ObjectPermissions', 'FieldPermissions',
|
|
34
|
+
'EntityDefinition', 'FieldDefinition', 'Identifier', 'StaticResource', 'Topic',
|
|
35
|
+
'TopicAssignment', 'SetupAuditTrail', 'NetworkMemberGroup',
|
|
36
|
+
]);
|
|
37
|
+
const CONTENT_OBJECTS = new Set([
|
|
38
|
+
'Attachment', 'Document', 'EmailMessage', 'EmailTemplate', 'Note',
|
|
39
|
+
]);
|
|
40
|
+
/** Which layer an object belongs to. Unrecognised objects are business, never hidden. */
|
|
41
|
+
export function roleOf(object) {
|
|
42
|
+
if (SECURITY_OBJECTS.has(object))
|
|
43
|
+
return 'security';
|
|
44
|
+
if (/^Logger?[A-Z_]/.test(object) || /^Log(Entry|Status|Retention)/.test(object))
|
|
45
|
+
return 'observability';
|
|
46
|
+
if (object.endsWith('__mdt'))
|
|
47
|
+
return 'configuration';
|
|
48
|
+
if (object.endsWith('__e') || object.endsWith('__x'))
|
|
49
|
+
return 'integration';
|
|
50
|
+
if (/(?:Share|History|Feed|ChangeEvent)$/.test(object))
|
|
51
|
+
return 'sharing';
|
|
52
|
+
if (CONTENT_OBJECTS.has(object) || /^Content[A-Z]/.test(object))
|
|
53
|
+
return 'content';
|
|
54
|
+
return 'business';
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=roleOf.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const GRAPH_RULES: {
|
|
2
|
+
readonly NOT_AN_OBJECT: "GRAPH_NOT_AN_OBJECT";
|
|
3
|
+
readonly SCHEMA_VERSION_UNSUPPORTED: "GRAPH_SCHEMA_VERSION_UNSUPPORTED";
|
|
4
|
+
readonly SCHEMA_SHAPE: "GRAPH_SCHEMA_SHAPE";
|
|
5
|
+
readonly EDGE_MISSING_PROVENANCE: "GRAPH_EDGE_MISSING_PROVENANCE";
|
|
6
|
+
readonly DERIVED_MISSING_RULE: "GRAPH_DERIVED_MISSING_RULE";
|
|
7
|
+
readonly ID_NOT_NAMESPACED: "GRAPH_ID_NOT_NAMESPACED";
|
|
8
|
+
readonly ID_DUPLICATE: "GRAPH_ID_DUPLICATE";
|
|
9
|
+
readonly UNKNOWN_KIND: "GRAPH_UNKNOWN_KIND";
|
|
10
|
+
readonly LEVEL_KIND_MISMATCH: "GRAPH_LEVEL_KIND_MISMATCH";
|
|
11
|
+
readonly LAYER_KIND_MISMATCH: "GRAPH_LAYER_KIND_MISMATCH";
|
|
12
|
+
readonly ROOT_HAS_PARENT: "GRAPH_ROOT_HAS_PARENT";
|
|
13
|
+
readonly PARENT_UNRESOLVED: "GRAPH_PARENT_UNRESOLVED";
|
|
14
|
+
readonly LEVEL_PARENT_ORDER: "GRAPH_LEVEL_PARENT_ORDER";
|
|
15
|
+
readonly PARENT_CYCLE: "GRAPH_PARENT_CYCLE";
|
|
16
|
+
readonly EDGE_ENDPOINT_UNRESOLVED: "GRAPH_EDGE_ENDPOINT_UNRESOLVED";
|
|
17
|
+
readonly MERGE_ORG_MISMATCH: "GRAPH_MERGE_ORG_MISMATCH";
|
|
18
|
+
readonly MERGE_SCHEMA_VERSION_MISMATCH: "GRAPH_MERGE_SCHEMA_VERSION_MISMATCH";
|
|
19
|
+
readonly MERGE_ID_COLLISION: "GRAPH_MERGE_ID_COLLISION";
|
|
20
|
+
readonly MERGE_KIND_NOT_OWNED: "GRAPH_MERGE_KIND_NOT_OWNED";
|
|
21
|
+
readonly MERGE_CONTRIBUTION_UNRESOLVED: "GRAPH_MERGE_CONTRIBUTION_UNRESOLVED";
|
|
22
|
+
readonly MERGE_NO_FRAGMENTS: "GRAPH_MERGE_NO_FRAGMENTS";
|
|
23
|
+
readonly MERGE_CONTRIBUTION_UNATTRIBUTED: "GRAPH_MERGE_CONTRIBUTION_UNATTRIBUTED";
|
|
24
|
+
};
|
|
25
|
+
export type GraphRuleCode = (typeof GRAPH_RULES)[keyof typeof GRAPH_RULES];
|
|
26
|
+
export interface GraphDiagnostic {
|
|
27
|
+
code: GraphRuleCode;
|
|
28
|
+
/** The offending node id, or `from->to` for an edge. `document` for whole-file findings. */
|
|
29
|
+
id: string;
|
|
30
|
+
message: string;
|
|
31
|
+
/** A supported fix. Never empty — a finding a reader cannot act on is a bug report. */
|
|
32
|
+
fix: string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/graph/rules.ts
|
|
2
|
+
// Stable rule codes. A code is an API: renaming one is a breaking change for anything that
|
|
3
|
+
// keys off validator output, so treat this table the way you would treat an error enum.
|
|
4
|
+
export const GRAPH_RULES = {
|
|
5
|
+
NOT_AN_OBJECT: 'GRAPH_NOT_AN_OBJECT',
|
|
6
|
+
SCHEMA_VERSION_UNSUPPORTED: 'GRAPH_SCHEMA_VERSION_UNSUPPORTED',
|
|
7
|
+
SCHEMA_SHAPE: 'GRAPH_SCHEMA_SHAPE',
|
|
8
|
+
EDGE_MISSING_PROVENANCE: 'GRAPH_EDGE_MISSING_PROVENANCE',
|
|
9
|
+
DERIVED_MISSING_RULE: 'GRAPH_DERIVED_MISSING_RULE',
|
|
10
|
+
ID_NOT_NAMESPACED: 'GRAPH_ID_NOT_NAMESPACED',
|
|
11
|
+
ID_DUPLICATE: 'GRAPH_ID_DUPLICATE',
|
|
12
|
+
UNKNOWN_KIND: 'GRAPH_UNKNOWN_KIND',
|
|
13
|
+
LEVEL_KIND_MISMATCH: 'GRAPH_LEVEL_KIND_MISMATCH',
|
|
14
|
+
LAYER_KIND_MISMATCH: 'GRAPH_LAYER_KIND_MISMATCH',
|
|
15
|
+
ROOT_HAS_PARENT: 'GRAPH_ROOT_HAS_PARENT',
|
|
16
|
+
PARENT_UNRESOLVED: 'GRAPH_PARENT_UNRESOLVED',
|
|
17
|
+
LEVEL_PARENT_ORDER: 'GRAPH_LEVEL_PARENT_ORDER',
|
|
18
|
+
PARENT_CYCLE: 'GRAPH_PARENT_CYCLE',
|
|
19
|
+
EDGE_ENDPOINT_UNRESOLVED: 'GRAPH_EDGE_ENDPOINT_UNRESOLVED',
|
|
20
|
+
// Merge. Separate codes from the validator's, because a reader acts differently on them: a
|
|
21
|
+
// validation finding is about one document, a merge finding is about two disagreeing.
|
|
22
|
+
MERGE_ORG_MISMATCH: 'GRAPH_MERGE_ORG_MISMATCH',
|
|
23
|
+
MERGE_SCHEMA_VERSION_MISMATCH: 'GRAPH_MERGE_SCHEMA_VERSION_MISMATCH',
|
|
24
|
+
MERGE_ID_COLLISION: 'GRAPH_MERGE_ID_COLLISION',
|
|
25
|
+
MERGE_KIND_NOT_OWNED: 'GRAPH_MERGE_KIND_NOT_OWNED',
|
|
26
|
+
MERGE_CONTRIBUTION_UNRESOLVED: 'GRAPH_MERGE_CONTRIBUTION_UNRESOLVED',
|
|
27
|
+
MERGE_NO_FRAGMENTS: 'GRAPH_MERGE_NO_FRAGMENTS',
|
|
28
|
+
MERGE_CONTRIBUTION_UNATTRIBUTED: 'GRAPH_MERGE_CONTRIBUTION_UNATTRIBUTED',
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
export declare const GRAPH_SCHEMA: {
|
|
2
|
+
type: string;
|
|
3
|
+
required: string[];
|
|
4
|
+
additionalProperties: boolean;
|
|
5
|
+
properties: {
|
|
6
|
+
schemaVersion: {
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
capturedAt: {
|
|
10
|
+
type: string;
|
|
11
|
+
};
|
|
12
|
+
orgId: {
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
nodes: {
|
|
16
|
+
type: string;
|
|
17
|
+
items: {
|
|
18
|
+
$ref: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
edges: {
|
|
22
|
+
type: string;
|
|
23
|
+
items: {
|
|
24
|
+
$ref: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
coverage: {
|
|
28
|
+
$ref: string;
|
|
29
|
+
};
|
|
30
|
+
producer: {
|
|
31
|
+
enum: string[];
|
|
32
|
+
};
|
|
33
|
+
contributions: {
|
|
34
|
+
type: string;
|
|
35
|
+
items: {
|
|
36
|
+
$ref: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
$defs: {
|
|
41
|
+
provenance: {
|
|
42
|
+
type: string;
|
|
43
|
+
required: string[];
|
|
44
|
+
additionalProperties: boolean;
|
|
45
|
+
properties: {
|
|
46
|
+
source: {
|
|
47
|
+
enum: string[];
|
|
48
|
+
};
|
|
49
|
+
capturedAt: {
|
|
50
|
+
type: string;
|
|
51
|
+
};
|
|
52
|
+
rule: {
|
|
53
|
+
type: string;
|
|
54
|
+
};
|
|
55
|
+
evidence: {
|
|
56
|
+
type: string;
|
|
57
|
+
};
|
|
58
|
+
observations: {
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
node: {
|
|
64
|
+
type: string;
|
|
65
|
+
required: string[];
|
|
66
|
+
additionalProperties: boolean;
|
|
67
|
+
properties: {
|
|
68
|
+
id: {
|
|
69
|
+
type: string;
|
|
70
|
+
minLength: number;
|
|
71
|
+
};
|
|
72
|
+
kind: {
|
|
73
|
+
type: string;
|
|
74
|
+
minLength: number;
|
|
75
|
+
};
|
|
76
|
+
layer: {
|
|
77
|
+
enum: string[];
|
|
78
|
+
};
|
|
79
|
+
level: {
|
|
80
|
+
enum: number[];
|
|
81
|
+
};
|
|
82
|
+
parent: {
|
|
83
|
+
type: string[];
|
|
84
|
+
};
|
|
85
|
+
label: {
|
|
86
|
+
type: string;
|
|
87
|
+
};
|
|
88
|
+
attrs: {
|
|
89
|
+
type: string;
|
|
90
|
+
};
|
|
91
|
+
provenance: {
|
|
92
|
+
$ref: string;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
edge: {
|
|
97
|
+
type: string;
|
|
98
|
+
required: string[];
|
|
99
|
+
additionalProperties: boolean;
|
|
100
|
+
properties: {
|
|
101
|
+
from: {
|
|
102
|
+
type: string;
|
|
103
|
+
minLength: number;
|
|
104
|
+
};
|
|
105
|
+
to: {
|
|
106
|
+
type: string;
|
|
107
|
+
minLength: number;
|
|
108
|
+
};
|
|
109
|
+
kind: {
|
|
110
|
+
type: string;
|
|
111
|
+
minLength: number;
|
|
112
|
+
};
|
|
113
|
+
attrs: {
|
|
114
|
+
type: string;
|
|
115
|
+
};
|
|
116
|
+
provenance: {
|
|
117
|
+
$ref: string;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
contribution: {
|
|
122
|
+
type: string;
|
|
123
|
+
required: string[];
|
|
124
|
+
additionalProperties: boolean;
|
|
125
|
+
properties: {
|
|
126
|
+
nodeId: {
|
|
127
|
+
type: string;
|
|
128
|
+
minLength: number;
|
|
129
|
+
};
|
|
130
|
+
attrs: {
|
|
131
|
+
type: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
coverage: {
|
|
136
|
+
type: string;
|
|
137
|
+
required: string[];
|
|
138
|
+
additionalProperties: boolean;
|
|
139
|
+
properties: {
|
|
140
|
+
notes: {
|
|
141
|
+
type: string;
|
|
142
|
+
items: {
|
|
143
|
+
type: string;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
unavailable: {
|
|
147
|
+
type: string;
|
|
148
|
+
items: {
|
|
149
|
+
type: string;
|
|
150
|
+
required: string[];
|
|
151
|
+
additionalProperties: boolean;
|
|
152
|
+
properties: {
|
|
153
|
+
scope: {
|
|
154
|
+
type: string;
|
|
155
|
+
minLength: number;
|
|
156
|
+
};
|
|
157
|
+
reason: {
|
|
158
|
+
enum: string[];
|
|
159
|
+
};
|
|
160
|
+
detail: {
|
|
161
|
+
type: string;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/graph/schema.ts
|
|
2
|
+
// JSON Schema for the document envelope and the shape of nodes and edges. Semantic rules that
|
|
3
|
+
// need cross-referencing between nodes (parents, cycles, endpoints) live in validate.ts, since
|
|
4
|
+
// JSON Schema cannot express them.
|
|
5
|
+
export const GRAPH_SCHEMA = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
required: ['schemaVersion', 'capturedAt', 'orgId', 'nodes', 'edges', 'coverage'],
|
|
8
|
+
additionalProperties: false,
|
|
9
|
+
properties: {
|
|
10
|
+
schemaVersion: { type: 'string' },
|
|
11
|
+
capturedAt: { type: 'string' },
|
|
12
|
+
orgId: { type: 'string' },
|
|
13
|
+
nodes: { type: 'array', items: { $ref: '#/$defs/node' } },
|
|
14
|
+
edges: { type: 'array', items: { $ref: '#/$defs/edge' } },
|
|
15
|
+
coverage: { $ref: '#/$defs/coverage' },
|
|
16
|
+
producer: { enum: ['orgviz', 'orgintel'] },
|
|
17
|
+
contributions: { type: 'array', items: { $ref: '#/$defs/contribution' } },
|
|
18
|
+
},
|
|
19
|
+
$defs: {
|
|
20
|
+
provenance: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
required: ['source', 'capturedAt'],
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
properties: {
|
|
25
|
+
source: { enum: ['metadata', 'runtime', 'derived'] },
|
|
26
|
+
capturedAt: { type: 'string' },
|
|
27
|
+
rule: { type: 'string' },
|
|
28
|
+
evidence: { type: 'string' },
|
|
29
|
+
observations: { type: 'number' },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
node: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
required: ['id', 'kind', 'layer', 'level', 'parent', 'label', 'attrs', 'provenance'],
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
properties: {
|
|
37
|
+
id: { type: 'string', minLength: 1 },
|
|
38
|
+
kind: { type: 'string', minLength: 1 },
|
|
39
|
+
layer: { enum: ['landscape', 'domain', 'data', 'process', 'access', 'runtime'] },
|
|
40
|
+
level: { enum: [0, 1, 2, 3] },
|
|
41
|
+
parent: { type: ['string', 'null'] },
|
|
42
|
+
label: { type: 'string' },
|
|
43
|
+
attrs: { type: 'object' },
|
|
44
|
+
provenance: { $ref: '#/$defs/provenance' },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
edge: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
required: ['from', 'to', 'kind', 'attrs', 'provenance'],
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
properties: {
|
|
52
|
+
from: { type: 'string', minLength: 1 },
|
|
53
|
+
to: { type: 'string', minLength: 1 },
|
|
54
|
+
kind: { type: 'string', minLength: 1 },
|
|
55
|
+
attrs: { type: 'object' },
|
|
56
|
+
provenance: { $ref: '#/$defs/provenance' },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
contribution: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
required: ['nodeId', 'attrs'],
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
properties: {
|
|
64
|
+
nodeId: { type: 'string', minLength: 1 },
|
|
65
|
+
attrs: { type: 'object' },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
coverage: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
required: ['notes', 'unavailable'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
properties: {
|
|
73
|
+
notes: { type: 'array', items: { type: 'string' } },
|
|
74
|
+
unavailable: {
|
|
75
|
+
type: 'array',
|
|
76
|
+
items: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
required: ['scope', 'reason', 'detail'],
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
properties: {
|
|
81
|
+
scope: { type: 'string', minLength: 1 },
|
|
82
|
+
reason: { enum: ['deferred', 'failed'] },
|
|
83
|
+
detail: { type: 'string' },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** What kind of thing a node is. Independent of `GraphLevel`. Spec section 2. */
|
|
2
|
+
export type GraphLayer = 'landscape' | 'domain' | 'data' | 'process' | 'access' | 'runtime';
|
|
3
|
+
/** How zoomed out a node is. Independent of `GraphLayer`. Spec section 2.2. */
|
|
4
|
+
export type GraphLevel = 0 | 1 | 2 | 3;
|
|
5
|
+
/**
|
|
6
|
+
* Which tool emits this kind. Ownership is per kind rather than per layer because
|
|
7
|
+
* sf-orgintel's anatomy collectors gather landscape-layer facts -- sites, products, personas --
|
|
8
|
+
* that sf-orgviz has no reason to extract. Node ids are `prefix.name`, so disjoint kinds give
|
|
9
|
+
* the disjoint ids the merge needs. See sf-orgviz/docs/CONVERGENCE_SPEC.md section 1.1.
|
|
10
|
+
*/
|
|
11
|
+
export type GraphProducer = 'orgviz' | 'orgintel';
|
|
12
|
+
export type GraphProvenanceSource = 'metadata' | 'runtime' | 'derived';
|
|
13
|
+
export interface GraphProvenance {
|
|
14
|
+
source: GraphProvenanceSource;
|
|
15
|
+
capturedAt: string;
|
|
16
|
+
/** Required when `source` is 'derived': names the rule that produced this. Spec section 4. */
|
|
17
|
+
rule?: string;
|
|
18
|
+
/** Evidence handle for runtime facts, e.g. an Event Monitoring finding id. */
|
|
19
|
+
evidence?: string;
|
|
20
|
+
observations?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface GraphNode {
|
|
23
|
+
/** Deterministic and content-derived, namespaced by kind: `obj.Account`. Never an index. */
|
|
24
|
+
id: string;
|
|
25
|
+
kind: string;
|
|
26
|
+
layer: GraphLayer;
|
|
27
|
+
level: GraphLevel;
|
|
28
|
+
/** Null at level 0. Above it, null means extracted but not yet grouped. Spec section 2.3. */
|
|
29
|
+
parent: string | null;
|
|
30
|
+
label: string;
|
|
31
|
+
attrs: Record<string, unknown>;
|
|
32
|
+
provenance: GraphProvenance;
|
|
33
|
+
}
|
|
34
|
+
export interface GraphEdge {
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
kind: string;
|
|
38
|
+
attrs: Record<string, unknown>;
|
|
39
|
+
provenance: GraphProvenance;
|
|
40
|
+
}
|
|
41
|
+
/** Why part of the org is absent from the document. `deferred` was never attempted. */
|
|
42
|
+
export interface GraphUnavailable {
|
|
43
|
+
/** Stable dotted key naming what is missing, e.g. `landscape.connectedApps`. */
|
|
44
|
+
scope: string;
|
|
45
|
+
reason: 'deferred' | 'failed';
|
|
46
|
+
detail: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What could not be gathered. Absence is data: a diagram that silently omits a layer nobody was
|
|
50
|
+
* allowed to read is a lie, and `notes` alone is prose a consumer cannot key off.
|
|
51
|
+
*/
|
|
52
|
+
export interface GraphCoverage {
|
|
53
|
+
notes: string[];
|
|
54
|
+
unavailable: GraphUnavailable[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A measurement about a node another producer owns. `recordCount90d` on an `obj.*` node is the
|
|
58
|
+
* case that forced this: it is a fact about a node sf-orgviz owns, measured by sf-orgintel,
|
|
59
|
+
* which has no other reason to emit that node. Applied under the contributor's namespace, never
|
|
60
|
+
* merged into `attrs` directly. See sf-orgviz/docs/CONVERGENCE_SPEC.md section 3.3.
|
|
61
|
+
*/
|
|
62
|
+
export interface AttributeContribution {
|
|
63
|
+
nodeId: string;
|
|
64
|
+
attrs: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
export interface CanonicalGraph {
|
|
67
|
+
schemaVersion: string;
|
|
68
|
+
capturedAt: string;
|
|
69
|
+
orgId: string;
|
|
70
|
+
nodes: GraphNode[];
|
|
71
|
+
edges: GraphEdge[];
|
|
72
|
+
coverage: GraphCoverage;
|
|
73
|
+
/** Which tool wrote this fragment. Absent on a merged graph, which has no single producer. */
|
|
74
|
+
producer?: GraphProducer;
|
|
75
|
+
contributions?: AttributeContribution[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 1.2.0 since `producer` and `contributions` were added, both optional. The 1.0.0 schema set
|
|
79
|
+
* additionalProperties:false, so a 1.1.0 reader rejects a 1.2.0 document — breaking under
|
|
80
|
+
* GRAPH_EXPORT_SPEC section 3, hence the exact-equality check and the bump. No documents exist
|
|
81
|
+
* outside this repo's fixtures (sf-orgviz is unpublished), so the migration is the fixture edit.
|
|
82
|
+
*/
|
|
83
|
+
export declare const SUPPORTED_GRAPH_SCHEMA_VERSION = "1.2.0";
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/graph/types.ts
|
|
2
|
+
// The canonical graph. Layers are projections over this document; there is no second model.
|
|
3
|
+
/**
|
|
4
|
+
* 1.2.0 since `producer` and `contributions` were added, both optional. The 1.0.0 schema set
|
|
5
|
+
* additionalProperties:false, so a 1.1.0 reader rejects a 1.2.0 document — breaking under
|
|
6
|
+
* GRAPH_EXPORT_SPEC section 3, hence the exact-equality check and the bump. No documents exist
|
|
7
|
+
* outside this repo's fixtures (sf-orgviz is unpublished), so the migration is the fixture edit.
|
|
8
|
+
*/
|
|
9
|
+
export const SUPPORTED_GRAPH_SCHEMA_VERSION = '1.2.0';
|
|
10
|
+
//# sourceMappingURL=types.js.map
|