@memberjunction/core-entities 6.3.0-edge.0 → 6.3.0-edge.2
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/dist/.tsbuildinfo +1 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts +10 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts.map +1 -1
- package/dist/custom/AnchoredConversationSecurity.js +15 -0
- package/dist/custom/AnchoredConversationSecurity.js.map +1 -1
- package/dist/custom/ArtifactLockValidation.d.ts +28 -0
- package/dist/custom/ArtifactLockValidation.d.ts.map +1 -0
- package/dist/custom/ArtifactLockValidation.js +867 -0
- package/dist/custom/ArtifactLockValidation.js.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts +288 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.js +1779 -0
- package/dist/custom/ArtifactPermissionDelegate.js.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts +199 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.js +772 -0
- package/dist/custom/ArtifactPreviewSnapshot.js.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts +151 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.js +1124 -0
- package/dist/custom/ArtifactSynthesisEngine.js.map +1 -0
- package/dist/custom/ConversationWriteAccess.d.ts +36 -0
- package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
- package/dist/custom/ConversationWriteAccess.js +109 -1
- package/dist/custom/ConversationWriteAccess.js.map +1 -1
- package/dist/custom/DocumentLiveBlockEngine.d.ts +612 -0
- package/dist/custom/DocumentLiveBlockEngine.d.ts.map +1 -0
- package/dist/custom/DocumentLiveBlockEngine.js +2352 -0
- package/dist/custom/DocumentLiveBlockEngine.js.map +1 -0
- package/dist/custom/MJQueryEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityExtended.js +27 -11
- package/dist/custom/MJQueryEntityExtended.js.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js +31 -7
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts +3 -4
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js +334 -47
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts +28 -3
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.js +150 -13
- package/dist/custom/Permissions/BaseShareEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts +8 -6
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +107 -43
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts +13 -5
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +284 -49
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts +3 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js +83 -19
- package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/shareNotification.d.ts +14 -1
- package/dist/custom/Permissions/shareNotification.d.ts.map +1 -1
- package/dist/custom/Permissions/shareNotification.js +62 -8
- package/dist/custom/Permissions/shareNotification.js.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js +120 -38
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js.map +1 -1
- package/dist/custom/SlideDeckEngine.d.ts +469 -0
- package/dist/custom/SlideDeckEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckEngine.js +2168 -0
- package/dist/custom/SlideDeckEngine.js.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts +25 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.js +1311 -0
- package/dist/custom/SlideDeckPptxEngine.js.map +1 -0
- package/dist/custom/SpreadsheetEngine.d.ts +1377 -0
- package/dist/custom/SpreadsheetEngine.d.ts.map +1 -0
- package/dist/custom/SpreadsheetEngine.js +17652 -0
- package/dist/custom/SpreadsheetEngine.js.map +1 -0
- package/dist/custom/approvals.d.ts +31 -1
- package/dist/custom/approvals.d.ts.map +1 -1
- package/dist/custom/approvals.js +42 -2
- package/dist/custom/approvals.js.map +1 -1
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts +60 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js +6 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js.map +1 -0
- package/dist/custom/typedQuery.d.ts +162 -0
- package/dist/custom/typedQuery.d.ts.map +1 -0
- package/dist/custom/typedQuery.js +296 -0
- package/dist/custom/typedQuery.js.map +1 -0
- package/dist/engines/CanonGraphEngine.d.ts +115 -2
- package/dist/engines/CanonGraphEngine.d.ts.map +1 -1
- package/dist/engines/CanonGraphEngine.js +259 -34
- package/dist/engines/CanonGraphEngine.js.map +1 -1
- package/dist/engines/EncryptionEngineBase.js +2 -2
- package/dist/engines/EncryptionEngineBase.js.map +1 -1
- package/dist/engines/QueryEngine.js +2 -2
- package/dist/engines/QueryEngine.js.map +1 -1
- package/dist/engines/SearchEngineBase.d.ts +17 -3
- package/dist/engines/SearchEngineBase.d.ts.map +1 -1
- package/dist/engines/SearchEngineBase.js +100 -28
- package/dist/engines/SearchEngineBase.js.map +1 -1
- package/dist/engines/UserInfoEngine.d.ts +8 -0
- package/dist/engines/UserInfoEngine.d.ts.map +1 -1
- package/dist/engines/UserInfoEngine.js +50 -3
- package/dist/engines/UserInfoEngine.js.map +1 -1
- package/dist/engines/conversations.d.ts +74 -6
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +205 -24
- package/dist/engines/conversations.js.map +1 -1
- package/dist/generated/entities/__mj.d.ts +25652 -43408
- package/dist/generated/entities/__mj.d.ts.map +1 -1
- package/dist/generated/entities/__mj.js +50800 -83602
- package/dist/generated/entities/__mj.js.map +1 -1
- package/dist/generated/queries/__mj.d.ts +12 -12
- package/dist/generated/queries/__mj.d.ts.map +1 -1
- package/dist/generated/queries/__mj.js +1 -1
- package/dist/generated/queries/__mj.js.map +1 -1
- package/dist/generated/remote_operations.d.ts +970 -65
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +343 -8
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/generated/schemas/__mj.d.ts +27415 -0
- package/dist/generated/schemas/__mj.d.ts.map +1 -0
- package/dist/generated/schemas/__mj.js +45127 -0
- package/dist/generated/schemas/__mj.js.map +1 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +2 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/graph/BaseGraphEdgeProvider.d.ts +33 -1
- package/dist/graph/BaseGraphEdgeProvider.d.ts.map +1 -1
- package/dist/graph/BaseGraphEdgeProvider.js +18 -3
- package/dist/graph/BaseGraphEdgeProvider.js.map +1 -1
- package/dist/graph/CanonDocumentRenderer.d.ts +43 -0
- package/dist/graph/CanonDocumentRenderer.d.ts.map +1 -0
- package/dist/graph/CanonDocumentRenderer.js +627 -0
- package/dist/graph/CanonDocumentRenderer.js.map +1 -0
- package/dist/graph/DomainClustering.d.ts +88 -0
- package/dist/graph/DomainClustering.d.ts.map +1 -0
- package/dist/graph/DomainClustering.js +327 -0
- package/dist/graph/DomainClustering.js.map +1 -0
- package/dist/graph/DomainProposalWriter.d.ts +25 -0
- package/dist/graph/DomainProposalWriter.d.ts.map +1 -0
- package/dist/graph/DomainProposalWriter.js +107 -0
- package/dist/graph/DomainProposalWriter.js.map +1 -0
- package/dist/graph/GraphAccessPolicy.d.ts +111 -0
- package/dist/graph/GraphAccessPolicy.d.ts.map +1 -0
- package/dist/graph/GraphAccessPolicy.js +123 -0
- package/dist/graph/GraphAccessPolicy.js.map +1 -0
- package/dist/graph/GraphEngine.d.ts +115 -7
- package/dist/graph/GraphEngine.d.ts.map +1 -1
- package/dist/graph/GraphEngine.js +432 -36
- package/dist/graph/GraphEngine.js.map +1 -1
- package/dist/graph/RecordRelations.d.ts +52 -0
- package/dist/graph/RecordRelations.d.ts.map +1 -0
- package/dist/graph/RecordRelations.js +90 -0
- package/dist/graph/RecordRelations.js.map +1 -0
- package/dist/graph/index.d.ts +9 -1
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +13 -1
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts +56 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.d.ts.map +1 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js +228 -0
- package/dist/graph/policies/ProvenanceAccessPolicies.js.map +1 -0
- package/dist/graph/providers/QueryEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/QueryEdgeProvider.js +2 -2
- package/dist/graph/providers/QueryEdgeProvider.js.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.d.ts.map +1 -1
- package/dist/graph/providers/RecordLinkEdgeProvider.js +2 -2
- package/dist/graph/providers/RecordLinkEdgeProvider.js.map +1 -1
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts +54 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js +282 -0
- package/dist/graph/providers/SharedConceptEdgeProvider.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +6 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +6 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +17 -6
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BaseEngine, EntityPermissionType, LogError, LogStatus, RunView, } from '@memberjunction/core';
|
|
2
2
|
import { EscapeSQLString, IndexByUUID, MJGlobal, UUIDMap, UUIDSet, UUIDsEqual } from '@memberjunction/global';
|
|
3
|
+
import { EvaluateAuthorizationChecks } from '../custom/operations/EvaluateAuthorizationChecks.js';
|
|
3
4
|
import { MJGraphEdgeEntity, MJGraphEntity, } from '../generated/entity_subclasses.js';
|
|
4
5
|
import { QueryEngine } from '../engines/QueryEngine.js';
|
|
5
|
-
import {
|
|
6
|
+
import { GraphAccessPolicyRegistry, } from './GraphAccessPolicy.js';
|
|
7
|
+
import { BaseGraphEdgeProvider, FormatGraphNodeKey, IsGraphDataProvider, MatchesEdgeTypeFilter, GRAPH_DEFAULT_EDGE_TYPE, } from './BaseGraphEdgeProvider.js';
|
|
6
8
|
/** Depth used when the caller gives none. */
|
|
7
9
|
export const GRAPH_DEFAULT_DEPTH = 2;
|
|
8
10
|
/** Hard upper bound on traversal depth. */
|
|
@@ -13,20 +15,64 @@ export const GRAPH_DEFAULT_MAX_NODES = 50;
|
|
|
13
15
|
export const GRAPH_MAX_NODES = 200;
|
|
14
16
|
/** Row cap on the stored edges one expansion step reads on demand. */
|
|
15
17
|
export const GRAPH_MAX_STORED_EDGES_PER_STEP = 1000;
|
|
18
|
+
/**
|
|
19
|
+
* Named `MJ: Authorizations` grant required for every approval, rejection/deprecation, edit-of-approved,
|
|
20
|
+
* or delete-of-approved decision on `MJ: Graph Edges` and `MJ: Graph Concepts`.
|
|
21
|
+
*/
|
|
22
|
+
export const GRAPH_APPROVE_EDGES_AUTHORIZATION = 'Graph: Approve Edges';
|
|
16
23
|
/**
|
|
17
24
|
* Server operation key (`ServerOperationScopeManager`) under which the Content Pipeline `Graph` stage
|
|
18
|
-
* saves the `
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
25
|
+
* saves the newly synthesized `Approved` `MJ: Graph Concepts` and `Inferred` + `Approved`
|
|
26
|
+
* `MJ: Graph Edges` that its content source's `GraphOverlay` policy approves (every
|
|
27
|
+
* `ConceptTaxonomyMode` except `propose-only`). `MJGraphEdgeEntityServer` and
|
|
28
|
+
* `MJGraphConceptEntityServer` let a newly created policy-approved row start `Approved` without
|
|
29
|
+
* `Graph: Approve Edges` only inside this scope (never edits, deprecations, or status transitions on
|
|
30
|
+
* existing concepts). Client CRUD entry points (GraphQL, REST, transaction groups) run inside a client
|
|
31
|
+
* CRUD boundary that masks every outer scope, so an API caller cannot enter it; only server code
|
|
32
|
+
* that names this key can.
|
|
23
33
|
*/
|
|
24
34
|
export const GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION = 'ContentPipeline.GraphStage.ApproveInferredEdges';
|
|
35
|
+
/**
|
|
36
|
+
* Server operation key under which the Content Pipeline retracts the evidence of a chunk it is
|
|
37
|
+
* deleting: the `Inferred` edges that have that chunk as an endpoint. Deleting an `Approved` edge is
|
|
38
|
+
* otherwise a review decision that needs `Graph: Approve Edges`, but an edge whose evidence is gone
|
|
39
|
+
* is not one a person decided to keep, so `MJGraphEdgeEntityServer` allows deleting an `Inferred`
|
|
40
|
+
* edge inside this scope. A `Declared` edge is never covered. Like the approval scope, no API caller
|
|
41
|
+
* can enter it.
|
|
42
|
+
*/
|
|
43
|
+
export const GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION = 'ContentPipeline.Delete.RetractInferredEdges';
|
|
44
|
+
/**
|
|
45
|
+
* How deeply access policies may nest (a concept's visibility following its chunks', a chunk's
|
|
46
|
+
* following its document's). Past this depth every node is hidden, so a cycle cannot recurse forever.
|
|
47
|
+
*/
|
|
48
|
+
const MAX_POLICY_DEPTH = 6;
|
|
25
49
|
/** Per-hop decay applied to best-first path scores, so near nodes outrank far ones. */
|
|
26
50
|
const HOP_DECAY = 0.85;
|
|
27
51
|
const GRAPH_EDGES_ENTITY = 'MJ: Graph Edges';
|
|
28
52
|
const GRAPHS_ENTITY = 'MJ: Graphs';
|
|
53
|
+
const GRAPH_TYPES_ENTITY = 'MJ: Graph Types';
|
|
29
54
|
const GRAPH_CONCEPTS_ENTITY = 'MJ: Graph Concepts';
|
|
55
|
+
/**
|
|
56
|
+
* True when a graph belongs to a graph type with `IsCanon = 1`. Whether a graph is Canon is metadata:
|
|
57
|
+
* neither the graph's name nor its type's name decides it.
|
|
58
|
+
*/
|
|
59
|
+
export function IsCanonGraph(graph, canonTypeIds) {
|
|
60
|
+
return canonTypeIds.Has(graph.GraphTypeID);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Whether `entityId` may sit on `side` of an edge of type `edgeTypeId`, according to `endpoints`
|
|
64
|
+
* (`MJ: Graph Edge Type Endpoints` rows). With no row for that type and side, any entity may.
|
|
65
|
+
*
|
|
66
|
+
* The one rule behind {@link GraphEngine.ValidateEdgeEndpoint} (read path and the edge server
|
|
67
|
+
* subclass) and every proposer that checks an edge before writing it, so they cannot disagree.
|
|
68
|
+
*/
|
|
69
|
+
export function GraphEdgeEndpointAllows(endpoints, edgeTypeId, side, entityId) {
|
|
70
|
+
const constraints = endpoints.filter((ep) => UUIDsEqual(ep.EdgeTypeID, edgeTypeId) && ep.Side === side);
|
|
71
|
+
if (constraints.length === 0) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return constraints.some((ep) => UUIDsEqual(ep.EntityID, entityId));
|
|
75
|
+
}
|
|
30
76
|
const STORED_EDGE_FIELDS = [
|
|
31
77
|
'ID',
|
|
32
78
|
'GraphID',
|
|
@@ -86,6 +132,12 @@ export class GraphEngine extends BaseEngine {
|
|
|
86
132
|
this.preloadGeneration = 0;
|
|
87
133
|
/** Field and alternate-view lookups for metadata nodes; rebuilt when the provider's entity list changes. */
|
|
88
134
|
this.metadataNodeIndex = null;
|
|
135
|
+
/** Cached result of the lightweight unloaded Canon-graph existence probe, keyed by provider. */
|
|
136
|
+
this.activeCanonGraphCache = new WeakMap();
|
|
137
|
+
/** In-flight lightweight Canon-graph probes so concurrent callers share one query per provider. */
|
|
138
|
+
this.activeCanonGraphInFlight = new WeakMap();
|
|
139
|
+
/** Monotonic counter incremented when graph/type metadata changes so stale probes do not cache. */
|
|
140
|
+
this.activeCanonProbeGeneration = 0;
|
|
89
141
|
}
|
|
90
142
|
static get Instance() {
|
|
91
143
|
return super.getInstance();
|
|
@@ -103,10 +155,79 @@ export class GraphEngine extends BaseEngine {
|
|
|
103
155
|
];
|
|
104
156
|
await this.Load(configs, provider, forceRefresh, contextUser);
|
|
105
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns `true` when at least one active Canon graph exists. When `GraphEngine` is already
|
|
160
|
+
* loaded for the resolved provider, evaluates strictly in memory; otherwise runs a single
|
|
161
|
+
* lightweight `RunView` probe cached per provider so callers can skip loading all 8 graph entities
|
|
162
|
+
* on deployments with no active Canon graphs.
|
|
163
|
+
*/
|
|
164
|
+
async HasActiveCanonGraphs(contextUser, provider) {
|
|
165
|
+
const resolvedProvider = provider ?? this.ProviderToUse;
|
|
166
|
+
if (this.Loaded && resolvedProvider === this.ProviderToUse) {
|
|
167
|
+
const canonTypeIds = new UUIDSet(this.GraphTypes.filter((gt) => gt.IsCanon).map((gt) => gt.ID));
|
|
168
|
+
return this.Graphs.some((g) => g.Status === 'Active' && IsCanonGraph(g, canonTypeIds));
|
|
169
|
+
}
|
|
170
|
+
const cached = this.activeCanonGraphCache.get(resolvedProvider);
|
|
171
|
+
if (cached !== undefined) {
|
|
172
|
+
return cached;
|
|
173
|
+
}
|
|
174
|
+
const pending = this.activeCanonGraphInFlight.get(resolvedProvider);
|
|
175
|
+
if (pending) {
|
|
176
|
+
return pending;
|
|
177
|
+
}
|
|
178
|
+
const probe = this.probeActiveCanonGraphs(resolvedProvider, contextUser).finally(() => {
|
|
179
|
+
this.activeCanonGraphInFlight.delete(resolvedProvider);
|
|
180
|
+
});
|
|
181
|
+
this.activeCanonGraphInFlight.set(resolvedProvider, probe);
|
|
182
|
+
return probe;
|
|
183
|
+
}
|
|
184
|
+
async probeActiveCanonGraphs(resolvedProvider, contextUser) {
|
|
185
|
+
const graphsMeta = resolvedProvider.EntityByName(GRAPHS_ENTITY);
|
|
186
|
+
if (!graphsMeta) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
await this.SetupGlobalEventListener();
|
|
190
|
+
const generation = this.activeCanonProbeGeneration;
|
|
191
|
+
const rv = RunView.FromMetadataProvider(resolvedProvider);
|
|
192
|
+
const graphsRes = await rv.RunView({
|
|
193
|
+
EntityName: GRAPHS_ENTITY,
|
|
194
|
+
ExtraFilter: "[Status] = 'Active'",
|
|
195
|
+
Fields: ['ID', 'Name', 'GraphTypeID', 'Status'],
|
|
196
|
+
ResultType: 'simple',
|
|
197
|
+
}, contextUser);
|
|
198
|
+
if (!graphsRes.Success) {
|
|
199
|
+
// Fail open without caching so callers fall back to Config().
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
const activeGraphs = (graphsRes.Results ?? []).filter((g) => g.Status === 'Active');
|
|
203
|
+
let hasActive = false;
|
|
204
|
+
if (activeGraphs.length > 0) {
|
|
205
|
+
const typesRes = await rv.RunView({
|
|
206
|
+
EntityName: GRAPH_TYPES_ENTITY,
|
|
207
|
+
Fields: ['ID', 'IsCanon'],
|
|
208
|
+
ResultType: 'simple',
|
|
209
|
+
}, contextUser);
|
|
210
|
+
if (!typesRes.Success) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
const canonTypeIds = new UUIDSet((typesRes.Results ?? []).filter((gt) => Boolean(gt.IsCanon)).map((gt) => gt.ID));
|
|
214
|
+
hasActive = activeGraphs.some((g) => IsCanonGraph(g, canonTypeIds));
|
|
215
|
+
}
|
|
216
|
+
const rlsExempt = !contextUser || graphsMeta.UserExemptFromRowLevelSecurity(contextUser, EntityPermissionType.Read);
|
|
217
|
+
if (rlsExempt && generation === this.activeCanonProbeGeneration) {
|
|
218
|
+
this.activeCanonGraphCache.set(resolvedProvider, hasActive);
|
|
219
|
+
}
|
|
220
|
+
return hasActive;
|
|
221
|
+
}
|
|
222
|
+
invalidateActiveCanonGraphCache() {
|
|
223
|
+
this.activeCanonProbeGeneration++;
|
|
224
|
+
this.activeCanonGraphCache = new WeakMap();
|
|
225
|
+
}
|
|
106
226
|
/** A first or forced (re)load also drops every preloaded graph; each reloads on its next traversal. */
|
|
107
227
|
async Load(configs, provider, forceRefresh = false, contextUser) {
|
|
108
228
|
if (forceRefresh || !this.Loaded) {
|
|
109
229
|
this.invalidatePreloadedEdges(null);
|
|
230
|
+
this.invalidateActiveCanonGraphCache();
|
|
110
231
|
}
|
|
111
232
|
return super.Load(configs, provider, forceRefresh, contextUser);
|
|
112
233
|
}
|
|
@@ -132,6 +253,10 @@ export class GraphEngine extends BaseEngine {
|
|
|
132
253
|
else if (changed && entityName === GRAPHS_ENTITY.toLowerCase()) {
|
|
133
254
|
const graphRow = event.baseEntity instanceof MJGraphEntity ? event.baseEntity : null;
|
|
134
255
|
this.invalidatePreloadedEdges(graphRow ? (graph) => UUIDsEqual(graph, graphRow.ID) : null);
|
|
256
|
+
this.invalidateActiveCanonGraphCache();
|
|
257
|
+
}
|
|
258
|
+
else if (changed && entityName === GRAPH_TYPES_ENTITY.toLowerCase()) {
|
|
259
|
+
this.invalidateActiveCanonGraphCache();
|
|
135
260
|
}
|
|
136
261
|
return super.HandleIndividualBaseEntityEvent(event);
|
|
137
262
|
}
|
|
@@ -195,11 +320,7 @@ export class GraphEngine extends BaseEngine {
|
|
|
195
320
|
* any entity is permitted.
|
|
196
321
|
*/
|
|
197
322
|
ValidateEdgeEndpoint(edgeTypeId, side, entityId) {
|
|
198
|
-
|
|
199
|
-
if (constraints.length === 0) {
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
return constraints.some((ep) => UUIDsEqual(ep.EntityID, entityId));
|
|
323
|
+
return GraphEdgeEndpointAllows(this.EdgeTypeEndpoints, edgeTypeId, side, entityId);
|
|
203
324
|
}
|
|
204
325
|
/**
|
|
205
326
|
* The canonical key of a node (`<entityID>|<recordID>`), resolving the entity through metadata.
|
|
@@ -221,6 +342,18 @@ export class GraphEngine extends BaseEngine {
|
|
|
221
342
|
const provider = this.graphProvider(options.Provider);
|
|
222
343
|
return this.resolveVisibleNodes(nodes, this.principals(user, audienceReaders), provider, options.IncludeProposed === true);
|
|
223
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Runs registered {@link BaseGraphEdgeAccessPolicy} checks over `edges` for `user` and every
|
|
347
|
+
* `audienceReaders` principal. An edge survives only when every principal's policy allows it;
|
|
348
|
+
* edge types with no registered policy pass through unchanged.
|
|
349
|
+
*/
|
|
350
|
+
async FilterEdgesForUser(edges, user, audienceReaders, options = {}) {
|
|
351
|
+
if (!user || !edges || edges.length === 0) {
|
|
352
|
+
return [];
|
|
353
|
+
}
|
|
354
|
+
const provider = this.graphProvider(options.Provider);
|
|
355
|
+
return this.applyEdgePolicies(edges, this.principals(user, audienceReaders), provider, options.IncludeProposed === true);
|
|
356
|
+
}
|
|
224
357
|
/**
|
|
225
358
|
* Stored and derived edges incident to `node` in `graphName` whose endpoints the caller (and any
|
|
226
359
|
* `options.AudienceReaders`) may see. An unknown or inactive graph yields no edges. Every read made
|
|
@@ -269,24 +402,7 @@ export class GraphEngine extends BaseEngine {
|
|
|
269
402
|
if (!graph) {
|
|
270
403
|
return { Nodes: [], Edges: [], Message: `Graph "${graphName}" was not found or is not active.` };
|
|
271
404
|
}
|
|
272
|
-
const dataProvider = this.
|
|
273
|
-
const principals = this.principals(user, options.AudienceReaders);
|
|
274
|
-
const maxDepth = ClampGraphDepth(options.Depth ?? options.MaxDepth);
|
|
275
|
-
const maxNodes = ClampGraphMaxNodes(options.MaxNodes);
|
|
276
|
-
const minWeight = options.MinWeight ?? 0;
|
|
277
|
-
const includeProposed = options.IncludeProposed === true;
|
|
278
|
-
const discovered = new Map();
|
|
279
|
-
const visibleByKey = new Map();
|
|
280
|
-
let frontier = await this.admitSeeds(seeds, principals, maxNodes, dataProvider, includeProposed, discovered, visibleByKey);
|
|
281
|
-
let capped = false;
|
|
282
|
-
for (let hop = 1; hop <= maxDepth && frontier.length > 0; hop++) {
|
|
283
|
-
const stepEdges = await this.getEdgesForFrontier(graph, frontier.map((f) => f.Node), options, principals, dataProvider);
|
|
284
|
-
const candidates = this.rankCandidates(stepEdges, frontier, discovered, minWeight, hop, dataProvider);
|
|
285
|
-
const visible = await this.resolveVisibleNodes(this.uniqueNeighborRefs(candidates), principals, dataProvider, includeProposed);
|
|
286
|
-
const admitted = this.admitCandidates(candidates, visible, maxNodes, hop, discovered, visibleByKey);
|
|
287
|
-
capped = capped || admitted.Capped;
|
|
288
|
-
frontier = admitted.Next;
|
|
289
|
-
}
|
|
405
|
+
const { discovered, visibleByKey, capped, maxNodes, principals, dataProvider } = await this.traverse(graph, seeds, options, { MaxDepth: ClampGraphDepth(options.Depth ?? options.MaxDepth), MaxNodes: ClampGraphMaxNodes(options.MaxNodes) }, user, provider);
|
|
290
406
|
const edges = new Map((await this.collectEdgesBetween(graph, discovered, options, principals, dataProvider)).map((e) => [e.ID, e]));
|
|
291
407
|
const nodes = [];
|
|
292
408
|
for (const d of discovered.values()) {
|
|
@@ -310,6 +426,101 @@ export class GraphEngine extends BaseEngine {
|
|
|
310
426
|
async Expand(graphName, seeds, options, user, provider) {
|
|
311
427
|
return this.Subgraph(graphName, seeds, options, user, provider);
|
|
312
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* The fewest-hop path from `from` to `to` in `graphName` that the caller (and every
|
|
431
|
+
* `options.AudienceReaders`) may see, with the best path weight among paths of that length.
|
|
432
|
+
*
|
|
433
|
+
* The search is the same best-first, permission-checked expansion as {@link Subgraph}, started at
|
|
434
|
+
* `from` and stopped the moment `to` is admitted, so a path never runs through a node some
|
|
435
|
+
* principal cannot see. `Depth` defaults to the maximum (4) and `MaxNodes` to the cap (200),
|
|
436
|
+
* because a path search usually needs the reach that a neighborhood read does not.
|
|
437
|
+
*
|
|
438
|
+
* A node the caller cannot see (either endpoint included) and a node that is not connected give
|
|
439
|
+
* the same answer, `Found: false` with a `Message`, so the result never reveals that a record exists.
|
|
440
|
+
*/
|
|
441
|
+
async FindPath(graphName, from, to, options, user, provider) {
|
|
442
|
+
const graph = this.GetGraph(graphName);
|
|
443
|
+
if (!graph) {
|
|
444
|
+
return notFoundPath(`Graph "${graphName}" was not found or is not active.`);
|
|
445
|
+
}
|
|
446
|
+
if (!user || !from || !to) {
|
|
447
|
+
return notFoundPath('Both a start node and an end node are required.');
|
|
448
|
+
}
|
|
449
|
+
const maxDepth = ClampGraphDepth(options.Depth ?? options.MaxDepth ?? GRAPH_MAX_DEPTH);
|
|
450
|
+
const maxNodes = ClampGraphMaxNodes(options.MaxNodes, GRAPH_MAX_NODES);
|
|
451
|
+
const stopAtKey = this.nodeKey(this.normalizeNodeRef(to, this.graphProvider(provider)), this.graphProvider(provider));
|
|
452
|
+
const run = await this.traverse(graph, [from], options, { MaxDepth: maxDepth, MaxNodes: maxNodes, StopAtKey: stopAtKey }, user, provider);
|
|
453
|
+
if (!run.discovered.has(stopAtKey)) {
|
|
454
|
+
const limit = run.capped ? ` (the search stopped at the ${maxNodes}-node limit)` : '';
|
|
455
|
+
return notFoundPath(`No path found within ${maxDepth} hop${maxDepth === 1 ? '' : 's'}${limit}.`);
|
|
456
|
+
}
|
|
457
|
+
return this.buildPath(stopAtKey, run);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Render a {@link GraphPath} as one Markdown line per hop for LLM prompt injection. Each edge is
|
|
461
|
+
* shown in its own direction, so a hop taken against an edge reads `<--`.
|
|
462
|
+
*/
|
|
463
|
+
DescribePathForPrompt(path, provider) {
|
|
464
|
+
if (!path.Found || path.Nodes.length === 0) {
|
|
465
|
+
return path.Message ? `No graph path found. ${path.Message}` : 'No graph path found.';
|
|
466
|
+
}
|
|
467
|
+
const resolvedProvider = this.graphProvider(provider);
|
|
468
|
+
const lines = [`### Graph Path (${path.Edges.length} hop${path.Edges.length === 1 ? '' : 's'}, weight ${path.PathWeight.toFixed(2)})`];
|
|
469
|
+
lines.push(`- **[${path.Nodes[0].EntityName}] ${path.Nodes[0].Label}**`);
|
|
470
|
+
for (let i = 0; i < path.Edges.length; i++) {
|
|
471
|
+
const edge = path.Edges[i];
|
|
472
|
+
const next = path.Nodes[i + 1];
|
|
473
|
+
const forward = this.nodeKey(edge.Source, resolvedProvider) === path.Nodes[i].Key;
|
|
474
|
+
const arrow = !edge.IsDirected ? '<-->' : forward ? '-->' : '<--';
|
|
475
|
+
const desc = edge.Description ? ` (${edge.Description})` : '';
|
|
476
|
+
lines.push(` ${arrow} [${edge.TypeName} (${edge.Weight.toFixed(2)})]${desc} **[${next.EntityName}] ${next.Label}**`);
|
|
477
|
+
}
|
|
478
|
+
return lines.join('\n');
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Best-first bounded expansion shared by {@link Subgraph} and {@link FindPath}: admit the visible
|
|
482
|
+
* seeds, then expand hop by hop, checking every candidate's visibility for every principal before
|
|
483
|
+
* admitting it, until the depth or node limit is reached or `limits.StopAtKey` is admitted.
|
|
484
|
+
*/
|
|
485
|
+
async traverse(graph, seeds, options, limits, user, provider) {
|
|
486
|
+
const dataProvider = this.graphProvider(provider);
|
|
487
|
+
const principals = this.principals(user, options.AudienceReaders);
|
|
488
|
+
const minWeight = options.MinWeight ?? 0;
|
|
489
|
+
const includeProposed = options.IncludeProposed === true;
|
|
490
|
+
const discovered = new Map();
|
|
491
|
+
const visibleByKey = new Map();
|
|
492
|
+
const maxNodes = limits.MaxNodes;
|
|
493
|
+
let frontier = await this.admitSeeds(seeds, principals, maxNodes, dataProvider, includeProposed, discovered, visibleByKey);
|
|
494
|
+
let capped = false;
|
|
495
|
+
const reachedStop = () => limits.StopAtKey != null && discovered.has(limits.StopAtKey);
|
|
496
|
+
for (let hop = 1; hop <= limits.MaxDepth && frontier.length > 0 && !reachedStop(); hop++) {
|
|
497
|
+
const stepEdges = await this.getEdgesForFrontier(graph, frontier.map((f) => f.Node), options, principals, dataProvider);
|
|
498
|
+
const candidates = this.rankCandidates(stepEdges, frontier, discovered, minWeight, hop, dataProvider);
|
|
499
|
+
const visible = await this.resolveVisibleNodes(this.uniqueNeighborRefs(candidates), principals, dataProvider, includeProposed);
|
|
500
|
+
const admitted = this.admitCandidates(candidates, visible, maxNodes, hop, discovered, visibleByKey);
|
|
501
|
+
capped = capped || admitted.Capped;
|
|
502
|
+
frontier = admitted.Next;
|
|
503
|
+
}
|
|
504
|
+
return { discovered, visibleByKey, capped, maxNodes, principals, dataProvider };
|
|
505
|
+
}
|
|
506
|
+
/** Walk back from `targetKey` through each node's parent to the seed, and return the path in order. */
|
|
507
|
+
buildPath(targetKey, run) {
|
|
508
|
+
const nodes = [];
|
|
509
|
+
const edges = [];
|
|
510
|
+
let current = run.discovered.get(targetKey);
|
|
511
|
+
const pathWeight = current?.PathWeight ?? 0;
|
|
512
|
+
while (current) {
|
|
513
|
+
const view = run.visibleByKey.get(current.Key);
|
|
514
|
+
if (view) {
|
|
515
|
+
nodes.push({ ...view, Hop: current.Hop, PathWeight: current.PathWeight, ParentKey: current.ParentKey, ViaEdgeID: current.ViaEdge?.ID ?? null });
|
|
516
|
+
}
|
|
517
|
+
if (current.ViaEdge) {
|
|
518
|
+
edges.push(current.ViaEdge);
|
|
519
|
+
}
|
|
520
|
+
current = current.ParentKey ? run.discovered.get(current.ParentKey) : undefined;
|
|
521
|
+
}
|
|
522
|
+
return { Found: true, Nodes: nodes.reverse(), Edges: edges.reverse(), PathWeight: pathWeight };
|
|
523
|
+
}
|
|
313
524
|
/**
|
|
314
525
|
* Render a {@link GraphSubgraph} as a compact, deterministic Markdown block for LLM prompt injection.
|
|
315
526
|
*/
|
|
@@ -489,7 +700,47 @@ export class GraphEngine extends BaseEngine {
|
|
|
489
700
|
results.set(edge.ID, edge);
|
|
490
701
|
}
|
|
491
702
|
}
|
|
492
|
-
|
|
703
|
+
const allowed = await this.applyEdgePolicies(Array.from(results.values()), principals, provider, options.IncludeProposed === true);
|
|
704
|
+
return allowed.sort((a, b) => compareStrings(a.ID, b.ID));
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Runs each edge type's access policy, for every principal: an edge survives only if every
|
|
708
|
+
* principal's policy allows it. Edge types with no policy pass through. A policy that throws hides
|
|
709
|
+
* every edge it governs.
|
|
710
|
+
*/
|
|
711
|
+
async applyEdgePolicies(edges, principals, provider, includeProposed) {
|
|
712
|
+
const byType = new Map();
|
|
713
|
+
for (const edge of edges) {
|
|
714
|
+
const list = byType.get(edge.TypeName) ?? [];
|
|
715
|
+
list.push(edge);
|
|
716
|
+
byType.set(edge.TypeName, list);
|
|
717
|
+
}
|
|
718
|
+
const hidden = new Set();
|
|
719
|
+
for (const [typeName, typeEdges] of byType) {
|
|
720
|
+
const policy = GraphAccessPolicyRegistry.GetEdgePolicy(typeName);
|
|
721
|
+
if (!policy) {
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
for (const principal of principals) {
|
|
725
|
+
const allowed = await this.allowedEdges(typeName, policy, typeEdges, principal, provider, includeProposed);
|
|
726
|
+
for (const e of typeEdges) {
|
|
727
|
+
if (!allowed.has(e.ID)) {
|
|
728
|
+
hidden.add(e.ID);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return edges.filter((e) => !hidden.has(e.ID));
|
|
734
|
+
}
|
|
735
|
+
async allowedEdges(typeName, policy, edges, principal, provider, includeProposed) {
|
|
736
|
+
try {
|
|
737
|
+
return await policy.FilterEdges(edges, this.policyContext(principal, provider, includeProposed, 0));
|
|
738
|
+
}
|
|
739
|
+
catch (err) {
|
|
740
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
741
|
+
LogError(`GraphEngine: the access policy for edge type '${typeName}' failed; hiding its edges: ${msg}`);
|
|
742
|
+
return new Set();
|
|
743
|
+
}
|
|
493
744
|
}
|
|
494
745
|
touchesFrontier(edge, frontierKeys, direction, provider) {
|
|
495
746
|
const sKey = this.nodeKey(edge.Source, provider);
|
|
@@ -508,7 +759,7 @@ export class GraphEngine extends BaseEngine {
|
|
|
508
759
|
return null;
|
|
509
760
|
}
|
|
510
761
|
const edgeType = edgeTypesById.Get(row.EdgeTypeID);
|
|
511
|
-
const typeName = edgeType?.Name ?? row.EdgeType ??
|
|
762
|
+
const typeName = edgeType?.Name ?? row.EdgeType ?? GRAPH_DEFAULT_EDGE_TYPE;
|
|
512
763
|
const weight = typeof row.Weight === 'number' ? row.Weight : (edgeType?.DefaultWeight ?? 1.0);
|
|
513
764
|
if (!MatchesEdgeTypeFilter(typeName, options.EdgeTypes) || weight < (options.MinWeight ?? 0)) {
|
|
514
765
|
return null;
|
|
@@ -728,7 +979,12 @@ export class GraphEngine extends BaseEngine {
|
|
|
728
979
|
/** Derived edges from the graph's active providers, read as `caller`. */
|
|
729
980
|
async runDerivedProviders(graph, frontier, options, caller, provider) {
|
|
730
981
|
const active = this.EdgeProviders.filter((ep) => ep.IsActive && UUIDsEqual(ep.GraphID, graph.ID)).sort((a, b) => a.Sequence - b.Sequence || compareStrings(a.ID, b.ID));
|
|
731
|
-
const request = {
|
|
982
|
+
const request = {
|
|
983
|
+
Nodes: frontier,
|
|
984
|
+
Direction: options.Direction ?? 'Both',
|
|
985
|
+
EdgeTypes: options.EdgeTypes,
|
|
986
|
+
IncludeProposed: options.IncludeProposed === true,
|
|
987
|
+
};
|
|
732
988
|
const edges = [];
|
|
733
989
|
for (const row of active) {
|
|
734
990
|
const instance = MJGlobal.Instance.ClassFactory.CreateInstance(BaseGraphEdgeProvider, row.DriverClass);
|
|
@@ -757,10 +1013,14 @@ export class GraphEngine extends BaseEngine {
|
|
|
757
1013
|
const perPrincipal = await Promise.all(principals.map((p) => this.resolveNodesForPrincipal(normalized, p, provider, includeProposed)));
|
|
758
1014
|
const visible = perPrincipal[0];
|
|
759
1015
|
for (const other of perPrincipal.slice(1)) {
|
|
760
|
-
for (const key of Array.from(visible
|
|
761
|
-
|
|
1016
|
+
for (const [key, view] of Array.from(visible)) {
|
|
1017
|
+
const otherView = other.get(key);
|
|
1018
|
+
if (!otherView) {
|
|
762
1019
|
visible.delete(key);
|
|
763
1020
|
}
|
|
1021
|
+
else {
|
|
1022
|
+
visible.set(key, sharedNodeText(view, otherView));
|
|
1023
|
+
}
|
|
764
1024
|
}
|
|
765
1025
|
}
|
|
766
1026
|
if (principals.length > 1) {
|
|
@@ -809,9 +1069,14 @@ export class GraphEngine extends BaseEngine {
|
|
|
809
1069
|
* entity), and a record that does not come back is invisible. A concept whose `Status` (as this
|
|
810
1070
|
* principal read it) is not {@link IsGraphConceptStatusVisible} is invisible too.
|
|
811
1071
|
*/
|
|
812
|
-
async resolveNodesForPrincipal(nodes, principal, provider, includeProposed) {
|
|
1072
|
+
async resolveNodesForPrincipal(nodes, principal, provider, includeProposed, policyDepth = 0) {
|
|
813
1073
|
const visible = new Map();
|
|
1074
|
+
if (policyDepth > MAX_POLICY_DEPTH) {
|
|
1075
|
+
LogError(`GraphEngine: access policies nested more than ${MAX_POLICY_DEPTH} deep; hiding ${nodes.length} node(s).`);
|
|
1076
|
+
return visible;
|
|
1077
|
+
}
|
|
814
1078
|
const buckets = new Map();
|
|
1079
|
+
const replaced = new Map();
|
|
815
1080
|
const seen = new Set();
|
|
816
1081
|
for (const node of nodes) {
|
|
817
1082
|
const key = this.nodeKey(node, provider);
|
|
@@ -828,7 +1093,17 @@ export class GraphEngine extends BaseEngine {
|
|
|
828
1093
|
continue;
|
|
829
1094
|
}
|
|
830
1095
|
const entity = provider.EntityByName(node.EntityName);
|
|
831
|
-
if (!entity
|
|
1096
|
+
if (!entity) {
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
const policy = GraphAccessPolicyRegistry.GetNodePolicy(entity.Name);
|
|
1100
|
+
if (policy?.Mode === 'Replace') {
|
|
1101
|
+
const group = replaced.get(entity.Name) ?? { Policy: policy, Nodes: [] };
|
|
1102
|
+
group.Nodes.push({ Key: key, Ref: node });
|
|
1103
|
+
replaced.set(entity.Name, group);
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
if (!CanUserReadEntity(entity, principal)) {
|
|
832
1107
|
continue;
|
|
833
1108
|
}
|
|
834
1109
|
const bucket = buckets.get(entity.Name) ?? { Entity: entity, Nodes: [] };
|
|
@@ -836,8 +1111,103 @@ export class GraphEngine extends BaseEngine {
|
|
|
836
1111
|
buckets.set(entity.Name, bucket);
|
|
837
1112
|
}
|
|
838
1113
|
await this.resolveDataNodes(Array.from(buckets.values()), principal, provider, includeProposed, visible);
|
|
1114
|
+
const ctx = this.policyContext(principal, provider, includeProposed, policyDepth);
|
|
1115
|
+
await this.readReplacedNodes(replaced, ctx, visible);
|
|
1116
|
+
await this.applyNodePolicies(nodes, ctx, visible);
|
|
839
1117
|
return visible;
|
|
840
1118
|
}
|
|
1119
|
+
/** What a policy may use while deciding for `principal`; nested checks run one level deeper. */
|
|
1120
|
+
policyContext(principal, provider, includeProposed, policyDepth) {
|
|
1121
|
+
return {
|
|
1122
|
+
Principal: principal,
|
|
1123
|
+
Provider: provider,
|
|
1124
|
+
IncludeProposed: includeProposed,
|
|
1125
|
+
NodeKey: (node) => this.nodeKey(node, provider),
|
|
1126
|
+
IsCanonGraph: (graphID) => this.isCanonGraphID(graphID),
|
|
1127
|
+
ResolveVisibleKeys: async (refs) => {
|
|
1128
|
+
const normalized = refs.map((r) => this.normalizeNodeRef(r, provider));
|
|
1129
|
+
const found = await this.resolveNodesForPrincipal(normalized, principal, provider, includeProposed, policyDepth + 1);
|
|
1130
|
+
return new Set(found.keys());
|
|
1131
|
+
},
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
/** `Replace` policies read their own nodes; a policy that throws hides its nodes. */
|
|
1135
|
+
async readReplacedNodes(replaced, ctx, visible) {
|
|
1136
|
+
for (const [entityName, group] of replaced) {
|
|
1137
|
+
try {
|
|
1138
|
+
const views = await group.Policy.ReadNodes(group.Nodes, ctx);
|
|
1139
|
+
for (const n of group.Nodes) {
|
|
1140
|
+
const view = views.get(n.Key);
|
|
1141
|
+
if (view) {
|
|
1142
|
+
visible.set(n.Key, view);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
catch (err) {
|
|
1147
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1148
|
+
LogError(`GraphEngine: the Replace access policy for '${entityName}' failed; hiding its nodes: ${msg}`);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Runs each visible node's entity policy over it. `Hidden` (or a missing decision) removes the
|
|
1154
|
+
* node; `Redacted` keeps it with the neutral label and no description. A policy that throws hides
|
|
1155
|
+
* every node it governs.
|
|
1156
|
+
*/
|
|
1157
|
+
async applyNodePolicies(nodes, ctx, visible) {
|
|
1158
|
+
const groups = new Map();
|
|
1159
|
+
for (const node of nodes) {
|
|
1160
|
+
const key = ctx.NodeKey(node);
|
|
1161
|
+
const view = visible.get(key);
|
|
1162
|
+
if (!view || metadataNodeKind(view.EntityName)) {
|
|
1163
|
+
continue;
|
|
1164
|
+
}
|
|
1165
|
+
const policy = GraphAccessPolicyRegistry.GetNodePolicy(view.EntityName);
|
|
1166
|
+
if (!policy) {
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
const group = groups.get(view.EntityName) ?? { Policy: policy, Nodes: [] };
|
|
1170
|
+
if (!group.Nodes.some((n) => n.Key === key)) {
|
|
1171
|
+
group.Nodes.push({ Key: key, Ref: node, View: view });
|
|
1172
|
+
}
|
|
1173
|
+
groups.set(view.EntityName, group);
|
|
1174
|
+
}
|
|
1175
|
+
for (const [entityName, group] of groups) {
|
|
1176
|
+
const decisions = await this.decideNodes(entityName, group.Policy, group.Nodes, ctx);
|
|
1177
|
+
for (const n of group.Nodes) {
|
|
1178
|
+
this.applyNodeDecision(n, decisions.get(n.Key) ?? 'Hidden', visible);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
async decideNodes(entityName, policy, nodes, ctx) {
|
|
1183
|
+
try {
|
|
1184
|
+
return await policy.FilterNodes(nodes, ctx);
|
|
1185
|
+
}
|
|
1186
|
+
catch (err) {
|
|
1187
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1188
|
+
LogError(`GraphEngine: the access policy for '${entityName}' failed; hiding its nodes: ${msg}`);
|
|
1189
|
+
return new Map();
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
applyNodeDecision(node, decision, visible) {
|
|
1193
|
+
if (decision === 'Hidden') {
|
|
1194
|
+
visible.delete(node.Key);
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
const view = visible.get(node.Key);
|
|
1198
|
+
if (decision === 'Redacted' && view) {
|
|
1199
|
+
visible.set(node.Key, { ...view, Label: NeutralGraphNodeLabel(view.EntityName, view.RecordID), Description: null });
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
/** `true` when `graphID` is an active graph whose graph type has `IsCanon = 1`. */
|
|
1203
|
+
isCanonGraphID(graphID) {
|
|
1204
|
+
const graph = this.Graphs.find((g) => UUIDsEqual(g.ID, graphID));
|
|
1205
|
+
if (!graph || graph.Status !== 'Active') {
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
const graphType = this.GraphTypes.find((t) => UUIDsEqual(t.ID, graph.GraphTypeID));
|
|
1209
|
+
return graphType?.IsCanon === true;
|
|
1210
|
+
}
|
|
841
1211
|
resolveMetadataNode(kind, node, key, principal, provider) {
|
|
842
1212
|
const base = { Key: key, EntityName: kind, EntityID: provider.EntityByName(kind)?.ID ?? node.EntityID };
|
|
843
1213
|
if (kind === 'MJ: Entities') {
|
|
@@ -1000,6 +1370,16 @@ function sharedEdgeText(edge, others) {
|
|
|
1000
1370
|
}
|
|
1001
1371
|
return { ...edge, Description: description, Attributes: attributes };
|
|
1002
1372
|
}
|
|
1373
|
+
/**
|
|
1374
|
+
* The text two principals may both see on one node. A node an access policy redacted for one of them
|
|
1375
|
+
* comes back with the neutral label and no description, so any difference means one reader may not
|
|
1376
|
+
* see the other's text: the label falls back to the neutral label and the description to none.
|
|
1377
|
+
*/
|
|
1378
|
+
function sharedNodeText(view, other) {
|
|
1379
|
+
const label = view.Label === other.Label ? view.Label : NeutralGraphNodeLabel(view.EntityName, view.RecordID);
|
|
1380
|
+
const description = view.Description === other.Description ? view.Description : null;
|
|
1381
|
+
return label === view.Label && description === view.Description ? view : { ...view, Label: label, Description: description };
|
|
1382
|
+
}
|
|
1003
1383
|
function isConceptEntity(entity) {
|
|
1004
1384
|
return entity.Name.trim().toLowerCase() === GRAPH_CONCEPTS_ENTITY.toLowerCase();
|
|
1005
1385
|
}
|
|
@@ -1038,6 +1418,18 @@ export function CanUserReadEntity(entity, user) {
|
|
|
1038
1418
|
}
|
|
1039
1419
|
return entity.GetUserPermisions(user)?.CanRead === true;
|
|
1040
1420
|
}
|
|
1421
|
+
/**
|
|
1422
|
+
* True only when `user` holds the `Graph: Approve Edges` authorization (directly or via an
|
|
1423
|
+
* ancestor authorization) in `authorizations`. Fails closed when `user`, `authorizations`, or the
|
|
1424
|
+
* seeded `Graph: Approve Edges` authorization is missing.
|
|
1425
|
+
*/
|
|
1426
|
+
export function CanUserApproveGraph(user, authorizations) {
|
|
1427
|
+
if (!user || !Array.isArray(authorizations) || authorizations.length === 0) {
|
|
1428
|
+
return false;
|
|
1429
|
+
}
|
|
1430
|
+
const [check] = EvaluateAuthorizationChecks([GRAPH_APPROVE_EDGES_AUTHORIZATION], user, authorizations);
|
|
1431
|
+
return check != null && !check.Unknown && check.Allowed === true;
|
|
1432
|
+
}
|
|
1041
1433
|
/** Clamp a requested traversal depth to `1..4` (default `2`). */
|
|
1042
1434
|
export function ClampGraphDepth(requested) {
|
|
1043
1435
|
const value = requested != null && Number.isFinite(requested) ? Math.floor(requested) : GRAPH_DEFAULT_DEPTH;
|
|
@@ -1048,6 +1440,10 @@ export function ClampGraphMaxNodes(requested, fallback = GRAPH_DEFAULT_MAX_NODES
|
|
|
1048
1440
|
const value = requested != null && Number.isFinite(requested) ? Math.floor(requested) : fallback;
|
|
1049
1441
|
return Math.max(1, Math.min(GRAPH_MAX_NODES, value));
|
|
1050
1442
|
}
|
|
1443
|
+
/** A {@link GraphPath} that found nothing, with the reason. */
|
|
1444
|
+
function notFoundPath(message) {
|
|
1445
|
+
return { Found: false, Nodes: [], Edges: [], PathWeight: 0, Message: message };
|
|
1446
|
+
}
|
|
1051
1447
|
function compareStrings(a, b) {
|
|
1052
1448
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
1053
1449
|
}
|