@memberjunction/core-entities-server 6.3.0-edge.1 → 6.3.0-edge.3
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/README.md +13 -0
- package/dist/custom/AgentChannelConversationDriver.server.d.ts +87 -0
- package/dist/custom/AgentChannelConversationDriver.server.d.ts.map +1 -0
- package/dist/custom/AgentChannelConversationDriver.server.js +216 -0
- package/dist/custom/AgentChannelConversationDriver.server.js.map +1 -0
- package/dist/custom/ArtifactSecurityHookHelpers.d.ts.map +1 -1
- package/dist/custom/ArtifactSecurityHookHelpers.js +50 -0
- package/dist/custom/ArtifactSecurityHookHelpers.js.map +1 -1
- package/dist/custom/AudienceNamedPersonAgentRequestService.d.ts +25 -0
- package/dist/custom/AudienceNamedPersonAgentRequestService.d.ts.map +1 -0
- package/dist/custom/AudienceNamedPersonAgentRequestService.js +304 -0
- package/dist/custom/AudienceNamedPersonAgentRequestService.js.map +1 -0
- package/dist/custom/ConversationDetailWritePermissionProvider.d.ts +113 -0
- package/dist/custom/ConversationDetailWritePermissionProvider.d.ts.map +1 -0
- package/dist/custom/ConversationDetailWritePermissionProvider.js +200 -0
- package/dist/custom/ConversationDetailWritePermissionProvider.js.map +1 -0
- package/dist/custom/ConversationReadSecurityHook.d.ts +61 -0
- package/dist/custom/ConversationReadSecurityHook.d.ts.map +1 -0
- package/dist/custom/ConversationReadSecurityHook.js +587 -0
- package/dist/custom/ConversationReadSecurityHook.js.map +1 -0
- package/dist/custom/GraphConceptReadSecurityHook.d.ts +75 -0
- package/dist/custom/GraphConceptReadSecurityHook.d.ts.map +1 -0
- package/dist/custom/GraphConceptReadSecurityHook.js +574 -0
- package/dist/custom/GraphConceptReadSecurityHook.js.map +1 -0
- package/dist/custom/GraphRecordChangesReadSecurityHook.d.ts +45 -0
- package/dist/custom/GraphRecordChangesReadSecurityHook.d.ts.map +1 -0
- package/dist/custom/GraphRecordChangesReadSecurityHook.js +744 -0
- package/dist/custom/GraphRecordChangesReadSecurityHook.js.map +1 -0
- package/dist/custom/MJAIAgentActionEntityServer.server.d.ts +13 -0
- package/dist/custom/MJAIAgentActionEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentActionEntityServer.server.js +52 -0
- package/dist/custom/MJAIAgentActionEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentCategoryEntityServer.server.d.ts +30 -0
- package/dist/custom/MJAIAgentCategoryEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentCategoryEntityServer.server.js +127 -0
- package/dist/custom/MJAIAgentCategoryEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentClientToolEntityServer.server.d.ts +12 -0
- package/dist/custom/MJAIAgentClientToolEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentClientToolEntityServer.server.js +46 -0
- package/dist/custom/MJAIAgentClientToolEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentEntityServer.server.d.ts +185 -33
- package/dist/custom/MJAIAgentEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJAIAgentEntityServer.server.js +2232 -42
- package/dist/custom/MJAIAgentEntityServer.server.js.map +1 -1
- package/dist/custom/MJAIAgentModalityEntityServer.server.d.ts +13 -0
- package/dist/custom/MJAIAgentModalityEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentModalityEntityServer.server.js +52 -0
- package/dist/custom/MJAIAgentModalityEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts +64 -8
- package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJAIAgentNoteEntityServer.server.js +263 -9
- package/dist/custom/MJAIAgentNoteEntityServer.server.js.map +1 -1
- package/dist/custom/MJAIAgentPersonaEntityServer.server.d.ts +23 -0
- package/dist/custom/MJAIAgentPersonaEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentPersonaEntityServer.server.js +95 -0
- package/dist/custom/MJAIAgentPersonaEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts +5 -2
- package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJAIAgentRelationshipEntityServer.server.js +25 -2
- package/dist/custom/MJAIAgentRelationshipEntityServer.server.js.map +1 -1
- package/dist/custom/MJAIAgentSkillEntityServer.server.d.ts +12 -0
- package/dist/custom/MJAIAgentSkillEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentSkillEntityServer.server.js +46 -0
- package/dist/custom/MJAIAgentSkillEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentStepTypeEntityServer.server.d.ts +28 -0
- package/dist/custom/MJAIAgentStepTypeEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentStepTypeEntityServer.server.js +117 -0
- package/dist/custom/MJAIAgentStepTypeEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentTypeEntityServer.server.d.ts +34 -0
- package/dist/custom/MJAIAgentTypeEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJAIAgentTypeEntityServer.server.js +231 -0
- package/dist/custom/MJAIAgentTypeEntityServer.server.js.map +1 -0
- package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts +24 -13
- package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js +167 -24
- package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js.map +1 -1
- package/dist/custom/MJActionEntityServer.server.d.ts +37 -0
- package/dist/custom/MJActionEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJActionEntityServer.server.js +208 -3
- package/dist/custom/MJActionEntityServer.server.js.map +1 -1
- package/dist/custom/MJComponentEntityServer.server.d.ts +6 -0
- package/dist/custom/MJComponentEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJComponentEntityServer.server.js +20 -2
- package/dist/custom/MJComponentEntityServer.server.js.map +1 -1
- package/dist/custom/MJContentSourceEntityServer.server.d.ts +28 -0
- package/dist/custom/MJContentSourceEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJContentSourceEntityServer.server.js +73 -0
- package/dist/custom/MJContentSourceEntityServer.server.js.map +1 -0
- package/dist/custom/MJContentSourceTypeEntityServer.server.d.ts +25 -0
- package/dist/custom/MJContentSourceTypeEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJContentSourceTypeEntityServer.server.js +73 -0
- package/dist/custom/MJContentSourceTypeEntityServer.server.js.map +1 -0
- package/dist/custom/MJConversationDetailEntityServer.server.d.ts +27 -2
- package/dist/custom/MJConversationDetailEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJConversationDetailEntityServer.server.js +300 -4
- package/dist/custom/MJConversationDetailEntityServer.server.js.map +1 -1
- package/dist/custom/MJConversationEntityServer.server.d.ts +5 -26
- package/dist/custom/MJConversationEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJConversationEntityServer.server.js +236 -8
- package/dist/custom/MJConversationEntityServer.server.js.map +1 -1
- package/dist/custom/MJDashboardEntityServer.server.d.ts +6 -0
- package/dist/custom/MJDashboardEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJDashboardEntityServer.server.js +24 -2
- package/dist/custom/MJDashboardEntityServer.server.js.map +1 -1
- package/dist/custom/MJGraphConceptEntityServer.server.d.ts +244 -0
- package/dist/custom/MJGraphConceptEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJGraphConceptEntityServer.server.js +746 -0
- package/dist/custom/MJGraphConceptEntityServer.server.js.map +1 -0
- package/dist/custom/MJGraphEdgeEntityServer.server.d.ts +52 -11
- package/dist/custom/MJGraphEdgeEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJGraphEdgeEntityServer.server.js +269 -37
- package/dist/custom/MJGraphEdgeEntityServer.server.js.map +1 -1
- package/dist/custom/MJGraphEntityServer.server.d.ts +58 -0
- package/dist/custom/MJGraphEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJGraphEntityServer.server.js +357 -0
- package/dist/custom/MJGraphEntityServer.server.js.map +1 -0
- package/dist/custom/MJGraphLinkEntityServer.server.d.ts +98 -0
- package/dist/custom/MJGraphLinkEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJGraphLinkEntityServer.server.js +375 -0
- package/dist/custom/MJGraphLinkEntityServer.server.js.map +1 -0
- package/dist/custom/MJGraphPermissionEntityServer.server.d.ts +29 -0
- package/dist/custom/MJGraphPermissionEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJGraphPermissionEntityServer.server.js +141 -0
- package/dist/custom/MJGraphPermissionEntityServer.server.js.map +1 -0
- package/dist/custom/MJListDetailEntityServer.server.d.ts +4 -4
- package/dist/custom/MJListDetailEntityServer.server.js +4 -4
- package/dist/custom/MJListEntityServer.server.d.ts +2 -1
- package/dist/custom/MJListEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJListEntityServer.server.js +5 -2
- package/dist/custom/MJListEntityServer.server.js.map +1 -1
- package/dist/custom/MJMLModelPublishRecordEntityServer.server.d.ts +31 -0
- package/dist/custom/MJMLModelPublishRecordEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJMLModelPublishRecordEntityServer.server.js +68 -0
- package/dist/custom/MJMLModelPublishRecordEntityServer.server.js.map +1 -0
- package/dist/custom/MJMLModelScoringBindingEntityServer.server.d.ts +78 -0
- package/dist/custom/MJMLModelScoringBindingEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJMLModelScoringBindingEntityServer.server.js +273 -0
- package/dist/custom/MJMLModelScoringBindingEntityServer.server.js.map +1 -0
- package/dist/custom/MJMLOutputBindingEntityServer.server.d.ts +18 -0
- package/dist/custom/MJMLOutputBindingEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJMLOutputBindingEntityServer.server.js +61 -0
- package/dist/custom/MJMLOutputBindingEntityServer.server.js.map +1 -0
- package/dist/custom/MJMLPredictionUnitEntityServer.server.d.ts +3 -3
- package/dist/custom/MJMLPredictionUnitEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJMLPredictionUnitEntityServer.server.js +4 -4
- package/dist/custom/MJMLPredictionUnitEntityServer.server.js.map +1 -1
- package/dist/custom/MJQueryEntityServer.server.d.ts +81 -0
- package/dist/custom/MJQueryEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityServer.server.js +194 -4
- package/dist/custom/MJQueryEntityServer.server.js.map +1 -1
- package/dist/custom/MJQueryParameterEntityServer.server.d.ts +37 -0
- package/dist/custom/MJQueryParameterEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJQueryParameterEntityServer.server.js +160 -0
- package/dist/custom/MJQueryParameterEntityServer.server.js.map +1 -0
- package/dist/custom/MJQuerySQLEntityServer.server.d.ts +36 -1
- package/dist/custom/MJQuerySQLEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJQuerySQLEntityServer.server.js +138 -7
- package/dist/custom/MJQuerySQLEntityServer.server.js.map +1 -1
- package/dist/custom/MJResourcePermissionEntityServer.server.d.ts +28 -0
- package/dist/custom/MJResourcePermissionEntityServer.server.d.ts.map +1 -0
- package/dist/custom/MJResourcePermissionEntityServer.server.js +206 -0
- package/dist/custom/MJResourcePermissionEntityServer.server.js.map +1 -0
- package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.d.ts +1 -1
- package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.js +8 -5
- package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.js.map +1 -1
- package/dist/custom/MJUserRoleEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJUserRoleEntityServer.server.js +9 -0
- package/dist/custom/MJUserRoleEntityServer.server.js.map +1 -1
- package/dist/custom/MJUserRoutineEntityServer.server.d.ts +23 -0
- package/dist/custom/MJUserRoutineEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJUserRoutineEntityServer.server.js +320 -3
- package/dist/custom/MJUserRoutineEntityServer.server.js.map +1 -1
- package/dist/custom/MJUserViewEntityServer.server.d.ts +9 -0
- package/dist/custom/MJUserViewEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJUserViewEntityServer.server.js +59 -3
- package/dist/custom/MJUserViewEntityServer.server.js.map +1 -1
- package/dist/custom/agentRelationalGrantGuard.d.ts +73 -0
- package/dist/custom/agentRelationalGrantGuard.d.ts.map +1 -0
- package/dist/custom/agentRelationalGrantGuard.js +375 -0
- package/dist/custom/agentRelationalGrantGuard.js.map +1 -0
- package/dist/custom/approvalStamp.d.ts +86 -6
- package/dist/custom/approvalStamp.d.ts.map +1 -1
- package/dist/custom/approvalStamp.js +119 -15
- package/dist/custom/approvalStamp.js.map +1 -1
- package/dist/custom/canon/CanonFingerprintRecorderServer.d.ts +20 -0
- package/dist/custom/canon/CanonFingerprintRecorderServer.d.ts.map +1 -0
- package/dist/custom/canon/CanonFingerprintRecorderServer.js +148 -0
- package/dist/custom/canon/CanonFingerprintRecorderServer.js.map +1 -0
- package/dist/custom/canon/index.d.ts +2 -0
- package/dist/custom/canon/index.d.ts.map +1 -0
- package/dist/custom/canon/index.js +2 -0
- package/dist/custom/canon/index.js.map +1 -0
- package/dist/custom/graph/GraphFindPathServerOperation.d.ts +26 -0
- package/dist/custom/graph/GraphFindPathServerOperation.d.ts.map +1 -0
- package/dist/custom/graph/GraphFindPathServerOperation.js +117 -0
- package/dist/custom/graph/GraphFindPathServerOperation.js.map +1 -0
- package/dist/custom/graph/index.d.ts +2 -0
- package/dist/custom/graph/index.d.ts.map +1 -0
- package/dist/custom/graph/index.js +2 -0
- package/dist/custom/graph/index.js.map +1 -0
- package/dist/custom/graphPermissionGuard.d.ts +69 -0
- package/dist/custom/graphPermissionGuard.d.ts.map +1 -0
- package/dist/custom/graphPermissionGuard.js +229 -0
- package/dist/custom/graphPermissionGuard.js.map +1 -0
- package/dist/custom/graphRlsCacheInvalidation.d.ts +38 -0
- package/dist/custom/graphRlsCacheInvalidation.d.ts.map +1 -0
- package/dist/custom/graphRlsCacheInvalidation.js +111 -0
- package/dist/custom/graphRlsCacheInvalidation.js.map +1 -0
- package/dist/custom/queryParentFingerprint.d.ts +36 -0
- package/dist/custom/queryParentFingerprint.d.ts.map +1 -0
- package/dist/custom/queryParentFingerprint.js +159 -0
- package/dist/custom/queryParentFingerprint.js.map +1 -0
- package/dist/custom/queryParentSaveChain.d.ts +5 -0
- package/dist/custom/queryParentSaveChain.d.ts.map +1 -0
- package/dist/custom/queryParentSaveChain.js +25 -0
- package/dist/custom/queryParentSaveChain.js.map +1 -0
- package/dist/custom/seededMetadataPush.d.ts +7 -0
- package/dist/custom/seededMetadataPush.d.ts.map +1 -0
- package/dist/custom/seededMetadataPush.js +23 -0
- package/dist/custom/seededMetadataPush.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -31
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
|
+
import { BaseEntity, BaseEntityResult, CompositeKey, LogError, RunView, ServerOperationScopeManager, ValidationErrorInfo, ValidationErrorType, ValidationResult, } from '@memberjunction/core';
|
|
9
|
+
import { EscapeSQLString, GetGlobalObjectStore, NormalizeUUID, RegisterClass, UUIDsEqual, } from '@memberjunction/global';
|
|
10
|
+
import { GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION, GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION, IsGraphBuildingEnabled, IsGraphDataProvider, MJGraphConceptEntity, ResolveGraphOverlayTargetGraphIDs, } from '@memberjunction/core-entities';
|
|
11
|
+
import { IsSetByTransactionVariable } from './anonymousOwnershipKeyGuard.js';
|
|
12
|
+
import { EnforceGraphConceptDirectLoadVisibility, EnsureGraphConceptReadHookRegistered, IsRedactedConceptEntity, MarkConceptEntityRedacted, REDACTED_CONCEPT_WRITE_DENIED_MESSAGE } from './GraphConceptReadSecurityHook.js';
|
|
13
|
+
import { CheckGraphApproveAuthorization, CheckGraphUseAuthorization } from './graphPermissionGuard.js';
|
|
14
|
+
import { ApproveEdgesDenialReason } from './MJGraphEdgeEntityServer.server.js';
|
|
15
|
+
EnsureGraphConceptReadHookRegistered();
|
|
16
|
+
const GRAPH_CONCEPTS_ENTITY_NAME = 'MJ: Graph Concepts';
|
|
17
|
+
/**
|
|
18
|
+
* Process-wide global store key for the post-save concept vector sync hook registered by
|
|
19
|
+
* `@memberjunction/content-pipeline` (finding 121). Stored in `GetGlobalObjectStore()` so
|
|
20
|
+
* `@memberjunction/core-entities-server` and `@memberjunction/content-pipeline` stay decoupled.
|
|
21
|
+
*/
|
|
22
|
+
export const GRAPH_CONCEPT_VECTOR_SYNC_HOOK_KEY = '___MJ_GRAPH_CONCEPT_VECTOR_SYNC_HOOK__';
|
|
23
|
+
/**
|
|
24
|
+
* Process-wide global store key for the post-delete / deprecation concept vector cleanup hook
|
|
25
|
+
* registered by `@memberjunction/content-pipeline` (finding 121).
|
|
26
|
+
*/
|
|
27
|
+
export const GRAPH_CONCEPT_VECTOR_DELETE_HOOK_KEY = '___MJ_GRAPH_CONCEPT_VECTOR_DELETE_HOOK__';
|
|
28
|
+
/**
|
|
29
|
+
* Process-wide global store key backing the `AsyncLocalStorage` token used to suppress the
|
|
30
|
+
* post-save vector sync hook during pipeline-managed writes (`EntityGraphOverlayStore.UpsertConcept`),
|
|
31
|
+
* preventing double-embedding (finding 142).
|
|
32
|
+
*/
|
|
33
|
+
export const GRAPH_CONCEPT_VECTOR_SYNC_SUPPRESS_STORE_KEY = '___MJ_GRAPH_CONCEPT_VECTOR_SYNC_SUPPRESS_ALS__';
|
|
34
|
+
/** Global store key backing the short-TTL D58 graph-building-enabled lookup cache. */
|
|
35
|
+
const GRAPH_BUILDING_ENABLED_CACHE_KEY = '___MJ_GRAPH_BUILDING_ENABLED_CACHE__';
|
|
36
|
+
/** Short in-process TTL for `MJ: Content Sources` graph-building checks (D58, finding 142). */
|
|
37
|
+
const GRAPH_BUILDING_ENABLED_CACHE_TTL_MS = 30_000; // 30s bounds DB queries on batch edits while picking up config changes promptly
|
|
38
|
+
/** Page size for paginated `MJ: Content Sources` graph-building probes (Finding 142). */
|
|
39
|
+
const GRAPH_BUILDING_SOURCES_PAGE_SIZE = 200; // Paginates until exhausted so graphs with >200 sources are never silently truncated
|
|
40
|
+
/**
|
|
41
|
+
* Fields on `MJ: Graph Concepts` whose modification alters the rendered embedding text and
|
|
42
|
+
* therefore triggers post-save vector synchronization (finding 142). Status-only transitions
|
|
43
|
+
* (e.g., `Proposed` -> `Approved`) are deliberately excluded so approval does ZERO embedding.
|
|
44
|
+
*/
|
|
45
|
+
export const CONCEPT_VECTOR_SYNC_FIELDS = [
|
|
46
|
+
'Name',
|
|
47
|
+
'ConceptTypeID',
|
|
48
|
+
'Synonyms',
|
|
49
|
+
'Description',
|
|
50
|
+
'Specification',
|
|
51
|
+
];
|
|
52
|
+
/** Registers (or clears with `null`) the post-save concept vector sync handler. */
|
|
53
|
+
export function RegisterGraphConceptVectorSyncHandler(handler) {
|
|
54
|
+
const g = GetGlobalObjectStore();
|
|
55
|
+
if (handler === null) {
|
|
56
|
+
delete g[GRAPH_CONCEPT_VECTOR_SYNC_HOOK_KEY];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
g[GRAPH_CONCEPT_VECTOR_SYNC_HOOK_KEY] = handler;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Returns the currently registered post-save concept vector sync handler, if any. */
|
|
63
|
+
export function GetGraphConceptVectorSyncHandler() {
|
|
64
|
+
const g = GetGlobalObjectStore();
|
|
65
|
+
const candidate = g[GRAPH_CONCEPT_VECTOR_SYNC_HOOK_KEY];
|
|
66
|
+
return typeof candidate === 'function' ? candidate : null;
|
|
67
|
+
}
|
|
68
|
+
/** Registers (or clears with `null`) the post-delete / deprecation concept vector cleanup handler. */
|
|
69
|
+
export function RegisterGraphConceptVectorDeleteHandler(handler) {
|
|
70
|
+
const g = GetGlobalObjectStore();
|
|
71
|
+
if (handler === null) {
|
|
72
|
+
delete g[GRAPH_CONCEPT_VECTOR_DELETE_HOOK_KEY];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
g[GRAPH_CONCEPT_VECTOR_DELETE_HOOK_KEY] = handler;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Returns the currently registered post-delete / deprecation concept vector cleanup handler, if any. */
|
|
79
|
+
export function GetGraphConceptVectorDeleteHandler() {
|
|
80
|
+
const g = GetGlobalObjectStore();
|
|
81
|
+
const candidate = g[GRAPH_CONCEPT_VECTOR_DELETE_HOOK_KEY];
|
|
82
|
+
return typeof candidate === 'function' ? candidate : null;
|
|
83
|
+
}
|
|
84
|
+
function getConceptVectorSyncSuppressALS() {
|
|
85
|
+
const g = GetGlobalObjectStore();
|
|
86
|
+
if (!(g[GRAPH_CONCEPT_VECTOR_SYNC_SUPPRESS_STORE_KEY] instanceof AsyncLocalStorage)) {
|
|
87
|
+
g[GRAPH_CONCEPT_VECTOR_SYNC_SUPPRESS_STORE_KEY] = new AsyncLocalStorage();
|
|
88
|
+
}
|
|
89
|
+
return g[GRAPH_CONCEPT_VECTOR_SYNC_SUPPRESS_STORE_KEY];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Executes `work` with the `MJGraphConceptEntityServer.Save()` post-save vector sync hook
|
|
93
|
+
* suppressed on this async execution context (finding 142 — eliminates double-embedding when
|
|
94
|
+
* `GraphStage` persists concepts and syncs their precomputed vectors directly).
|
|
95
|
+
*/
|
|
96
|
+
export function RunWithSuppressedGraphConceptVectorSync(work) {
|
|
97
|
+
return getConceptVectorSyncSuppressALS().run(true, work);
|
|
98
|
+
}
|
|
99
|
+
/** Returns `true` when the current async execution context is suppressing post-save concept vector sync. */
|
|
100
|
+
export function IsGraphConceptVectorSyncSuppressed() {
|
|
101
|
+
return getConceptVectorSyncSuppressALS().getStore() === true;
|
|
102
|
+
}
|
|
103
|
+
function getGraphBuildingCache() {
|
|
104
|
+
const g = GetGlobalObjectStore();
|
|
105
|
+
if (!(g[GRAPH_BUILDING_ENABLED_CACHE_KEY] instanceof Map)) {
|
|
106
|
+
g[GRAPH_BUILDING_ENABLED_CACHE_KEY] = new Map();
|
|
107
|
+
}
|
|
108
|
+
return g[GRAPH_BUILDING_ENABLED_CACHE_KEY];
|
|
109
|
+
}
|
|
110
|
+
/** Clears cached D58 graph-building-enabled answers (for one `graphID` or all graphs, e.g. in tests). */
|
|
111
|
+
export function InvalidateGraphBuildingEnabledCache(graphID) {
|
|
112
|
+
const cache = getGraphBuildingCache();
|
|
113
|
+
if (!graphID) {
|
|
114
|
+
cache.clear();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
cache.delete(NormalizeUUID(graphID));
|
|
118
|
+
}
|
|
119
|
+
function contentSourceEnablesGraphBuildingForGraph(source, graphID) {
|
|
120
|
+
if (!IsGraphBuildingEnabled(source.Configuration)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const targets = ResolveGraphOverlayTargetGraphIDs(source.GraphID, source.Configuration);
|
|
124
|
+
return targets.some((targetID) => UUIDsEqual(targetID, graphID));
|
|
125
|
+
}
|
|
126
|
+
async function hasGraphBuildingEnabledContentSource(graphID, contextUser, provider) {
|
|
127
|
+
if (!graphID || graphID.trim().length === 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const key = NormalizeUUID(graphID);
|
|
131
|
+
const cache = getGraphBuildingCache();
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
const cached = cache.get(key);
|
|
134
|
+
if (cached && cached.ExpiresAt > now) {
|
|
135
|
+
return cached.Enabled;
|
|
136
|
+
}
|
|
137
|
+
const safeID = EscapeSQLString(graphID);
|
|
138
|
+
const rv = RunView.FromMetadataProvider(provider);
|
|
139
|
+
let enabled = false;
|
|
140
|
+
let startRow = 0;
|
|
141
|
+
for (;;) {
|
|
142
|
+
const res = await rv.RunView({
|
|
143
|
+
EntityName: 'MJ: Content Sources',
|
|
144
|
+
Fields: ['ID', 'GraphID', 'Configuration'],
|
|
145
|
+
ExtraFilter: `GraphID = '${safeID}' OR Configuration LIKE '%${safeID}%'`,
|
|
146
|
+
OrderBy: 'ID ASC',
|
|
147
|
+
StartRow: startRow,
|
|
148
|
+
MaxRows: GRAPH_BUILDING_SOURCES_PAGE_SIZE,
|
|
149
|
+
ResultType: 'simple',
|
|
150
|
+
}, contextUser);
|
|
151
|
+
if (!res.Success) {
|
|
152
|
+
const msg = `MJGraphConceptEntityServer: failed checking MJ: Content Sources graph building status for GraphID '${graphID}' at StartRow=${startRow}: ${res.ErrorMessage}`;
|
|
153
|
+
LogError(msg);
|
|
154
|
+
throw new Error(msg);
|
|
155
|
+
}
|
|
156
|
+
const rows = res.Results ?? [];
|
|
157
|
+
if (rows.some((row) => contentSourceEnablesGraphBuildingForGraph(row, graphID))) {
|
|
158
|
+
enabled = true;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (rows.length < GRAPH_BUILDING_SOURCES_PAGE_SIZE) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
startRow += rows.length;
|
|
165
|
+
}
|
|
166
|
+
cache.set(key, { Enabled: enabled, ExpiresAt: now + GRAPH_BUILDING_ENABLED_CACHE_TTL_MS });
|
|
167
|
+
return enabled;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Server-owned D42 approval stamp columns on `MJ: Graph Concepts`.
|
|
171
|
+
* These are governed fields maintained exclusively by the server and refused when supplied or modified by a client.
|
|
172
|
+
*/
|
|
173
|
+
export const CONCEPT_APPROVAL_STAMP_FIELDS = ['ApprovalMode', 'ApprovedByUserID', 'ApprovedAt'];
|
|
174
|
+
function isApprovedOrProvisionalConceptStatus(status) {
|
|
175
|
+
return status === 'Approved' || status === 'Provisional';
|
|
176
|
+
}
|
|
177
|
+
function dateToMillis(value) {
|
|
178
|
+
if (value instanceof Date) {
|
|
179
|
+
return Number.isNaN(value.getTime()) ? null : value.getTime();
|
|
180
|
+
}
|
|
181
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
182
|
+
const parsed = Date.parse(value);
|
|
183
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Columns exempt from field-edit governance on an existing `Approved`, `Deprecated`, or
|
|
189
|
+
* `Provisional` `MJ: Graph Concepts` row: only `Status` (governed by status transition rules)
|
|
190
|
+
* and `__mj*` system audit columns (plus read-only/virtual/primary-key metadata fields).
|
|
191
|
+
*
|
|
192
|
+
* Every other business column — including D42 approval stamp columns and any newly added schema column —
|
|
193
|
+
* is governed by default.
|
|
194
|
+
*/
|
|
195
|
+
export const CONCEPT_UNGOVERNED_EXCLUSIONS = ['Status'];
|
|
196
|
+
const CONCEPT_UNGOVERNED_EXCLUSIONS_LOWER = new Set(CONCEPT_UNGOVERNED_EXCLUSIONS.map((name) => name.toLowerCase()));
|
|
197
|
+
/**
|
|
198
|
+
* Returns `true` when `fieldName` is a governed business column on `MJ: Graph Concepts`.
|
|
199
|
+
* Only columns in {@link CONCEPT_UNGOVERNED_EXCLUSIONS} and `__mj*` system audit columns are exempt;
|
|
200
|
+
* every other column is governed.
|
|
201
|
+
*/
|
|
202
|
+
export function IsGovernedConceptFieldName(fieldName) {
|
|
203
|
+
const trimmed = fieldName.trim();
|
|
204
|
+
if (trimmed.length === 0) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const lower = trimmed.toLowerCase();
|
|
208
|
+
return !CONCEPT_UNGOVERNED_EXCLUSIONS_LOWER.has(lower) && !lower.startsWith('__mj');
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* True when an update to an existing concept dirties any updatable non-`Status`, non-`__mj*`
|
|
212
|
+
* column, or targets one via a `'Use'` transaction variable.
|
|
213
|
+
*/
|
|
214
|
+
export function HasGovernedConceptFieldChanges(target) {
|
|
215
|
+
if (!target.IsSaved) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
const dirtyFieldChanged = target.Fields.some((field) => field.Dirty === true &&
|
|
219
|
+
!field.IsPrimaryKey &&
|
|
220
|
+
!field.ReadOnly &&
|
|
221
|
+
!field.EntityFieldInfo?.IsVirtual &&
|
|
222
|
+
IsGovernedConceptFieldName(field.Name));
|
|
223
|
+
if (dirtyFieldChanged) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
return Boolean(target.TransactionGroup?.Variables.some((v) => v.EntityObject === target && v.Type === 'Use' && IsGovernedConceptFieldName(v.FieldName)));
|
|
227
|
+
}
|
|
228
|
+
function isEditableUnapprovedStatus(status) {
|
|
229
|
+
return status === 'Draft' || status === 'Proposed';
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* True when saving these concept values is a governance decision that `Graph: Approve Edges` must
|
|
233
|
+
* authorize:
|
|
234
|
+
* - binding `'Status'` or `'ID'` via a `'Use'` transaction variable (applied after `ValidateAsync` runs);
|
|
235
|
+
* - creating a concept whose `Status` does not start `Draft` or `Proposed` (null/undefined uses the
|
|
236
|
+
* database column default `'Draft'`, so those stay ungated; `'Provisional'`, `'Approved'`, and
|
|
237
|
+
* `'Deprecated'` require it);
|
|
238
|
+
* - changing `Status` into or out of `'Provisional'`, `'Approved'`, or `'Deprecated'` (only
|
|
239
|
+
* `Draft <-> Proposed` stays ungated);
|
|
240
|
+
* - editing any governed field on a concept whose status is `'Provisional'`, `'Approved'`, or
|
|
241
|
+
* `'Deprecated'`.
|
|
242
|
+
*
|
|
243
|
+
* Fails closed when `IsSaved` is `true` and `PreviousStatus` is unknown.
|
|
244
|
+
*/
|
|
245
|
+
export function GraphConceptSaveNeedsApproval(input) {
|
|
246
|
+
if (input.StatusOrIdSetByVariable) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if (!input.IsSaved) {
|
|
250
|
+
const effectiveNext = input.NextStatus === null || input.NextStatus === undefined ? 'Draft' : input.NextStatus;
|
|
251
|
+
return !isEditableUnapprovedStatus(effectiveNext);
|
|
252
|
+
}
|
|
253
|
+
if (!input.PreviousStatus) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
if (input.PreviousStatus !== input.NextStatus) {
|
|
257
|
+
return !(isEditableUnapprovedStatus(input.PreviousStatus) && isEditableUnapprovedStatus(input.NextStatus));
|
|
258
|
+
}
|
|
259
|
+
return !isEditableUnapprovedStatus(input.PreviousStatus) && input.GovernedFieldsChanged;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* True when the Content Pipeline `Graph` stage is creating a brand-new `Approved` concept inside its
|
|
263
|
+
* {@link GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION} server scope. Edits to existing concepts, status
|
|
264
|
+
* transitions, deprecations, and variable-driven `Status`/`ID` mutations are never covered by this scope.
|
|
265
|
+
*/
|
|
266
|
+
export function IsPipelinePolicyApprovedConceptCreate(input) {
|
|
267
|
+
return input.InPipelineApprovalScope && !input.IsSaved && input.NextStatus === 'Approved' && !input.StatusOrIdSetByVariable;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Pure fail-closed gate for `MJ: Graph Concepts` approval, deprecation/rejection, and edits to
|
|
271
|
+
* governed concepts (see {@link GraphConceptSaveNeedsApproval}).
|
|
272
|
+
*/
|
|
273
|
+
export function EvaluateGraphConceptApproval(input) {
|
|
274
|
+
if (!GraphConceptSaveNeedsApproval(input) || IsPipelinePolicyApprovedConceptCreate(input)) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
const denial = ApproveEdgesDenialReason(input.User, input.Authorizations);
|
|
278
|
+
if (!denial) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return new ValidationErrorInfo('Status', `Saving this graph concept as "${input.NextStatus ?? ''}" or modifying a governed concept ${denial}. ` +
|
|
282
|
+
'Save new or unratified concepts as "Draft" or "Proposed" for a steward instead.', input.NextStatus, ValidationErrorType.Failure);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Refusal message for deleting an `MJ: Graph Concepts` row whose stored `Status` is `storedStatus`,
|
|
286
|
+
* or `null` when allowed.
|
|
287
|
+
*
|
|
288
|
+
* - `'Draft'` and `'Proposed'` concepts may be deleted without `Graph: Approve Edges`.
|
|
289
|
+
* - Pipeline-originated (`Origin === 'Inferred'`) concepts whose stored status is not `'Deprecated'`,
|
|
290
|
+
* not `'Rejected'`, and not unknown (`null`/`undefined`) may be deleted without `Graph: Approve Edges`
|
|
291
|
+
* only inside {@link GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION} (`pipelineRetraction.InScope === true`).
|
|
292
|
+
* - `'Deprecated'` and `'Rejected'` tombstones (D68) and all curated (`'Declared'`) or unknown-status /
|
|
293
|
+
* unknown-origin concepts require `Graph: Approve Edges` (keeping `'Deprecated'` and `'Rejected'`
|
|
294
|
+
* tombstones intact so rejected concepts remain suppressed across re-runs).
|
|
295
|
+
*/
|
|
296
|
+
export function GraphConceptDeleteRefusal(storedStatus, user, authorizations, pipelineRetraction) {
|
|
297
|
+
if (isEditableUnapprovedStatus(storedStatus)) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
if (storedStatus != null &&
|
|
301
|
+
storedStatus !== 'Deprecated' &&
|
|
302
|
+
storedStatus !== 'Rejected' &&
|
|
303
|
+
pipelineRetraction?.InScope &&
|
|
304
|
+
pipelineRetraction.Origin === 'Inferred') {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
const denial = ApproveEdgesDenialReason(user, authorizations);
|
|
308
|
+
if (!denial) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
const label = storedStatus ? `"${storedStatus}"` : 'unknown-status';
|
|
312
|
+
return `Deleting a ${label} graph concept is a governance decision and ${denial}.`;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* True while the current async call chain is inside {@link GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION}
|
|
316
|
+
* scoped to `'MJ: Graph Concepts'` for `user`. Client CRUD boundaries mask every outer scope.
|
|
317
|
+
*/
|
|
318
|
+
export function IsInGraphConceptPipelineApprovalScope(user) {
|
|
319
|
+
if (!user) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
return ServerOperationScopeManager.Instance.IsOperationActive([GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION], GRAPH_CONCEPTS_ENTITY_NAME, user);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* True while the current async call chain is inside {@link GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION}
|
|
326
|
+
* scoped to `'MJ: Graph Concepts'` for `user`. Client CRUD boundaries mask every outer scope.
|
|
327
|
+
*/
|
|
328
|
+
export function IsInGraphConceptPipelineRetractionScope(user) {
|
|
329
|
+
if (!user) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
return ServerOperationScopeManager.Instance.IsOperationActive([GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION], GRAPH_CONCEPTS_ENTITY_NAME, user);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Server-side `MJ: Graph Concepts` entity enforcing Workstream 5a & D18/D19 governance:
|
|
336
|
+
* - Creating an `Approved`, `Deprecated`, or `Provisional` concept, transitioning into/out of
|
|
337
|
+
* those statuses, editing any non-`Status`, non-`__mj*` business column on an `Approved`,
|
|
338
|
+
* `Deprecated`, or `Provisional` concept, or deleting a governed concept requires
|
|
339
|
+
* `Graph: Approve Edges` ({@link EvaluateGraphConceptApproval}, {@link GraphConceptDeleteRefusal});
|
|
340
|
+
* - The Content Pipeline `Graph` stage (`EntityGraphOverlayStore.UpsertConcept`) is permitted to
|
|
341
|
+
* create new policy-approved concepts inside {@link GRAPH_PIPELINE_EDGE_APPROVAL_OPERATION}
|
|
342
|
+
* ({@link IsPipelinePolicyApprovedConceptCreate}), while never editing or deprecating existing
|
|
343
|
+
* governed concepts;
|
|
344
|
+
* - The Content Pipeline evidence retractor (`GraphEvidenceRetractor`) is permitted to delete an
|
|
345
|
+
* `Inferred` (non-`Deprecated`) concept inside {@link GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION},
|
|
346
|
+
* while curated (`Declared`) `Approved`/`Provisional`/`Deprecated` concepts remain protected.
|
|
347
|
+
*/
|
|
348
|
+
let MJGraphConceptEntityServer = class MJGraphConceptEntityServer extends MJGraphConceptEntity {
|
|
349
|
+
constructor() {
|
|
350
|
+
super(...arguments);
|
|
351
|
+
this._serverStampedApproval = null;
|
|
352
|
+
}
|
|
353
|
+
get DefaultSkipAsyncValidation() {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
async Load(ID, EntityRelationshipsToLoad) {
|
|
357
|
+
const key = CompositeKey.FromID(ID); // first-pk-ok: 'MJ: Graph Concepts' has single GUID PK 'ID'
|
|
358
|
+
return this.InnerLoad(key, EntityRelationshipsToLoad);
|
|
359
|
+
}
|
|
360
|
+
async InnerLoad(compositeKey, EntityRelationshipsToLoad) {
|
|
361
|
+
const loaded = await super.InnerLoad(compositeKey, EntityRelationshipsToLoad);
|
|
362
|
+
if (!loaded) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
const provider = IsGraphDataProvider(this.ProviderToUse) ? this.ProviderToUse : null;
|
|
366
|
+
return EnforceGraphConceptDirectLoadVisibility(this, this.ContextCurrentUser, provider);
|
|
367
|
+
}
|
|
368
|
+
NewRecord(newValues) {
|
|
369
|
+
MarkConceptEntityRedacted(this, false);
|
|
370
|
+
return super.NewRecord(newValues);
|
|
371
|
+
}
|
|
372
|
+
async ValidateAsync() {
|
|
373
|
+
if (IsRedactedConceptEntity(this)) {
|
|
374
|
+
const res = new ValidationResult();
|
|
375
|
+
res.Success = false;
|
|
376
|
+
res.Errors.push(new ValidationErrorInfo('Name', REDACTED_CONCEPT_WRITE_DENIED_MESSAGE, null, ValidationErrorType.Failure));
|
|
377
|
+
return res;
|
|
378
|
+
}
|
|
379
|
+
const result = await super.ValidateAsync();
|
|
380
|
+
if (!result.Success) {
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
const stampError = this.evaluateClientApprovalStampError();
|
|
384
|
+
if (stampError) {
|
|
385
|
+
result.Errors.push(stampError);
|
|
386
|
+
result.Success = false;
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
const error = await this.evaluateApprovalErrorAsync();
|
|
390
|
+
if (error) {
|
|
391
|
+
result.Errors.push(error);
|
|
392
|
+
result.Success = false;
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
const useError = await this.evaluateUseAccessErrorAsync();
|
|
396
|
+
if (useError) {
|
|
397
|
+
result.Errors.push(useError);
|
|
398
|
+
result.Success = false;
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
this.applyServerApprovalStamp();
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
/** Enforces the same governance gate and D42 stamp lifecycle when `ReplayOnly` or `SkipAsyncValidation` would skip `ValidateAsync`. */
|
|
405
|
+
async Save(options) {
|
|
406
|
+
if (IsRedactedConceptEntity(this)) {
|
|
407
|
+
return this.refuseOperation(this.IsSaved ? 'update' : 'create', REDACTED_CONCEPT_WRITE_DENIED_MESSAGE);
|
|
408
|
+
}
|
|
409
|
+
if (options?.ReplayOnly || options?.SkipAsyncValidation) {
|
|
410
|
+
const stampError = this.evaluateClientApprovalStampError();
|
|
411
|
+
if (stampError) {
|
|
412
|
+
return this.refuseOperation(this.IsSaved ? 'update' : 'create', stampError.Message);
|
|
413
|
+
}
|
|
414
|
+
const error = await this.evaluateApprovalErrorAsync();
|
|
415
|
+
if (error) {
|
|
416
|
+
return this.refuseOperation(this.IsSaved ? 'update' : 'create', error.Message);
|
|
417
|
+
}
|
|
418
|
+
const useError = await this.evaluateUseAccessErrorAsync();
|
|
419
|
+
if (useError) {
|
|
420
|
+
return this.refuseOperation(this.IsSaved ? 'update' : 'create', useError.Message);
|
|
421
|
+
}
|
|
422
|
+
this.applyServerApprovalStamp();
|
|
423
|
+
}
|
|
424
|
+
const isDeprecating = !options?.ReplayOnly &&
|
|
425
|
+
this.IsSaved &&
|
|
426
|
+
this.previousStatus() !== 'Deprecated' &&
|
|
427
|
+
this.Status === 'Deprecated';
|
|
428
|
+
const shouldSyncVector = !options?.ReplayOnly &&
|
|
429
|
+
!IsGraphConceptVectorSyncSuppressed() &&
|
|
430
|
+
!isDeprecating &&
|
|
431
|
+
this.Status !== 'Deprecated' &&
|
|
432
|
+
this.hasVectorSyncRelevantChanges();
|
|
433
|
+
const saved = await super.Save(options);
|
|
434
|
+
if (saved) {
|
|
435
|
+
this._serverStampedApproval = null;
|
|
436
|
+
if (isDeprecating) {
|
|
437
|
+
await this.invokeVectorDeleteHook(this.ID, this.GraphID);
|
|
438
|
+
}
|
|
439
|
+
else if (shouldSyncVector) {
|
|
440
|
+
await this.invokeVectorSyncHook();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return saved;
|
|
444
|
+
}
|
|
445
|
+
hasVectorSyncRelevantChanges() {
|
|
446
|
+
if (!this.IsSaved) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
return CONCEPT_VECTOR_SYNC_FIELDS.some((fieldName) => this.GetFieldByName(fieldName)?.Dirty === true);
|
|
450
|
+
}
|
|
451
|
+
async invokeVectorSyncHook() {
|
|
452
|
+
if (IsGraphConceptVectorSyncSuppressed()) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const handler = GetGraphConceptVectorSyncHandler();
|
|
456
|
+
if (!handler || !this.ContextCurrentUser || !IsGraphDataProvider(this.ProviderToUse)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const enabled = await hasGraphBuildingEnabledContentSource(this.GraphID, this.ContextCurrentUser, this.ProviderToUse);
|
|
461
|
+
if (!enabled) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
await handler(this, this.ContextCurrentUser, this.ProviderToUse);
|
|
465
|
+
}
|
|
466
|
+
catch (err) {
|
|
467
|
+
// Do not break the concept save on a transient vector DB failure; GraphConcept.__mj_UpdatedAt
|
|
468
|
+
// stays newer than ERD.EntityRecordUpdatedAt so EnsureCanonConceptsIndexedForGraph catches it up.
|
|
469
|
+
LogError(`MJGraphConceptEntityServer: post-save vector sync failed for concept '${this.ID}': ` +
|
|
470
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async invokeVectorDeleteHook(conceptID, graphID) {
|
|
474
|
+
const handler = GetGraphConceptVectorDeleteHandler();
|
|
475
|
+
if (!handler || !conceptID || !this.ContextCurrentUser || !IsGraphDataProvider(this.ProviderToUse)) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
await handler(conceptID, graphID, this.ContextCurrentUser, this.ProviderToUse);
|
|
480
|
+
}
|
|
481
|
+
catch (err) {
|
|
482
|
+
LogError(`MJGraphConceptEntityServer: post-delete vector cleanup failed for concept '${conceptID}': ` +
|
|
483
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Evaluates whether this concept record may be deleted in the current caller and operation
|
|
488
|
+
* scope without mutating or deleting anything. Saved records read persisted `Status` and
|
|
489
|
+
* `Origin` (`OldValue`) and never trust in-memory mutations.
|
|
490
|
+
*/
|
|
491
|
+
CheckDeleteRefusal() {
|
|
492
|
+
const provider = this.ProviderToUse;
|
|
493
|
+
const authorizations = IsGraphDataProvider(provider) ? provider.Authorizations : undefined;
|
|
494
|
+
const storedStatus = this.IsSaved ? this.previousStatus() : this.Status;
|
|
495
|
+
const storedOrigin = this.IsSaved ? this.previousOrigin() : this.Origin;
|
|
496
|
+
return GraphConceptDeleteRefusal(storedStatus, this.ContextCurrentUser, authorizations, {
|
|
497
|
+
InScope: IsInGraphConceptPipelineRetractionScope(this.ContextCurrentUser),
|
|
498
|
+
Origin: storedOrigin,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Async variant of {@link CheckDeleteRefusal} that also evaluates per-graph `Approve` and `Use`
|
|
503
|
+
* permissions via `MJ: Graph Permissions` (D3 / 5b).
|
|
504
|
+
*/
|
|
505
|
+
async CheckDeleteRefusalAsync() {
|
|
506
|
+
const provider = this.ProviderToUse;
|
|
507
|
+
const graphProvider = IsGraphDataProvider(provider) ? provider : undefined;
|
|
508
|
+
const authorizations = graphProvider?.Authorizations;
|
|
509
|
+
const storedStatus = this.IsSaved ? this.previousStatus() : this.Status;
|
|
510
|
+
const storedOrigin = this.IsSaved ? this.previousOrigin() : this.Origin;
|
|
511
|
+
const inRetractionScope = IsInGraphConceptPipelineRetractionScope(this.ContextCurrentUser);
|
|
512
|
+
const storedGraphId = this.storedGraphId();
|
|
513
|
+
if (isEditableUnapprovedStatus(storedStatus)) {
|
|
514
|
+
if (inRetractionScope) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
const useErr = await CheckGraphUseAuthorization(this.ContextCurrentUser, [storedGraphId], graphProvider);
|
|
518
|
+
return useErr ? useErr.Message : null;
|
|
519
|
+
}
|
|
520
|
+
if (storedStatus != null &&
|
|
521
|
+
storedStatus !== 'Deprecated' &&
|
|
522
|
+
storedStatus !== 'Rejected' &&
|
|
523
|
+
inRetractionScope &&
|
|
524
|
+
storedOrigin === 'Inferred') {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
const globalDenial = ApproveEdgesDenialReason(this.ContextCurrentUser, authorizations);
|
|
528
|
+
const approvalDenial = await CheckGraphApproveAuthorization(this.ContextCurrentUser, [storedGraphId], graphProvider, globalDenial);
|
|
529
|
+
if (!approvalDenial) {
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
const label = storedStatus ? `"${storedStatus}"` : 'unknown-status';
|
|
533
|
+
return `Deleting a ${label} graph concept is a governance decision and ${approvalDenial}.`;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Refuses deleting an `Approved`, `Deprecated`, `Provisional`, or unknown/unloaded stored-status
|
|
537
|
+
* concept without `Graph: Approve Edges` or per-graph `Approve` permission, except an `Inferred`
|
|
538
|
+
* non-`Deprecated` concept deleted inside {@link GRAPH_PIPELINE_EVIDENCE_RETRACTION_OPERATION}.
|
|
539
|
+
* Saved records read stored `Status`, `Origin`, and `GraphID` (`OldValue`) and never fall back
|
|
540
|
+
* to in-memory property values.
|
|
541
|
+
*/
|
|
542
|
+
async Delete(options) {
|
|
543
|
+
if (IsRedactedConceptEntity(this)) {
|
|
544
|
+
return this.refuseOperation('delete', REDACTED_CONCEPT_WRITE_DENIED_MESSAGE);
|
|
545
|
+
}
|
|
546
|
+
const refusal = await this.CheckDeleteRefusalAsync();
|
|
547
|
+
if (refusal) {
|
|
548
|
+
return this.refuseOperation('delete', refusal);
|
|
549
|
+
}
|
|
550
|
+
const conceptID = this.ID;
|
|
551
|
+
const graphID = this.GraphID;
|
|
552
|
+
const deleted = await super.Delete(options);
|
|
553
|
+
if (deleted && !options?.ReplayOnly) {
|
|
554
|
+
await this.invokeVectorDeleteHook(conceptID, graphID);
|
|
555
|
+
}
|
|
556
|
+
return deleted;
|
|
557
|
+
}
|
|
558
|
+
affectedGraphIds() {
|
|
559
|
+
const ids = [this.GraphID];
|
|
560
|
+
const graphIdField = this.GetFieldByName('GraphID');
|
|
561
|
+
if (this.IsSaved && graphIdField?.Dirty && typeof graphIdField.OldValue === 'string') {
|
|
562
|
+
ids.push(graphIdField.OldValue);
|
|
563
|
+
}
|
|
564
|
+
return ids;
|
|
565
|
+
}
|
|
566
|
+
storedGraphId() {
|
|
567
|
+
const graphIdField = this.GetFieldByName('GraphID');
|
|
568
|
+
if (this.IsSaved && typeof graphIdField?.OldValue === 'string' && graphIdField.OldValue.trim().length > 0) {
|
|
569
|
+
return graphIdField.OldValue;
|
|
570
|
+
}
|
|
571
|
+
return this.GraphID;
|
|
572
|
+
}
|
|
573
|
+
async evaluateApprovalErrorAsync() {
|
|
574
|
+
const provider = this.ProviderToUse;
|
|
575
|
+
if (!IsGraphDataProvider(provider)) {
|
|
576
|
+
return new ValidationErrorInfo('Status', 'Graph concepts can only be validated against a metadata provider.', this.Status, ValidationErrorType.Failure);
|
|
577
|
+
}
|
|
578
|
+
const approvalInput = {
|
|
579
|
+
IsSaved: this.IsSaved,
|
|
580
|
+
PreviousStatus: this.previousStatus(),
|
|
581
|
+
NextStatus: this.Status,
|
|
582
|
+
GovernedFieldsChanged: HasGovernedConceptFieldChanges(this),
|
|
583
|
+
StatusOrIdSetByVariable: IsSetByTransactionVariable(this, ['Status', 'ID']),
|
|
584
|
+
User: this.ContextCurrentUser,
|
|
585
|
+
Authorizations: provider.Authorizations,
|
|
586
|
+
InPipelineApprovalScope: IsInGraphConceptPipelineApprovalScope(this.ContextCurrentUser),
|
|
587
|
+
};
|
|
588
|
+
if (!GraphConceptSaveNeedsApproval(approvalInput) || IsPipelinePolicyApprovedConceptCreate(approvalInput)) {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
const globalDenial = ApproveEdgesDenialReason(approvalInput.User, approvalInput.Authorizations);
|
|
592
|
+
const denial = await CheckGraphApproveAuthorization(approvalInput.User, this.affectedGraphIds(), provider, globalDenial);
|
|
593
|
+
if (!denial) {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
return new ValidationErrorInfo('Status', `Saving this graph concept as "${approvalInput.NextStatus ?? ''}" or modifying a governed concept ${denial}. ` +
|
|
597
|
+
'Save new or unratified concepts as "Draft" or "Proposed" for a steward instead.', approvalInput.NextStatus, ValidationErrorType.Failure);
|
|
598
|
+
}
|
|
599
|
+
async evaluateUseAccessErrorAsync() {
|
|
600
|
+
if (IsSetByTransactionVariable(this, ['GraphID'])) {
|
|
601
|
+
return new ValidationErrorInfo('GraphID', 'GraphID on MJ: Graph Concepts cannot be bound via transaction variables.', this.GraphID, ValidationErrorType.Failure);
|
|
602
|
+
}
|
|
603
|
+
if (IsInGraphConceptPipelineApprovalScope(this.ContextCurrentUser)) {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
const provider = this.ProviderToUse;
|
|
607
|
+
if (!IsGraphDataProvider(provider)) {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
return CheckGraphUseAuthorization(this.ContextCurrentUser, this.affectedGraphIds(), provider);
|
|
611
|
+
}
|
|
612
|
+
refuseOperation(type, message) {
|
|
613
|
+
const result = new BaseEntityResult();
|
|
614
|
+
result.Success = false;
|
|
615
|
+
result.Type = type;
|
|
616
|
+
result.Message = message;
|
|
617
|
+
result.StartedAt = new Date();
|
|
618
|
+
result.EndedAt = new Date();
|
|
619
|
+
this.RegisterResultHistoryEntry(result);
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
previousStatus() {
|
|
623
|
+
const field = this.GetFieldByName('Status');
|
|
624
|
+
if (field?.NotLoaded) {
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
const oldValue = field?.OldValue;
|
|
628
|
+
return oldValue === 'Approved' ||
|
|
629
|
+
oldValue === 'Deprecated' ||
|
|
630
|
+
oldValue === 'Draft' ||
|
|
631
|
+
oldValue === 'Proposed' ||
|
|
632
|
+
oldValue === 'Provisional' ||
|
|
633
|
+
oldValue === 'Rejected'
|
|
634
|
+
? oldValue
|
|
635
|
+
: null;
|
|
636
|
+
}
|
|
637
|
+
evaluateClientApprovalStampError() {
|
|
638
|
+
if (IsSetByTransactionVariable(this, [...CONCEPT_APPROVAL_STAMP_FIELDS])) {
|
|
639
|
+
return new ValidationErrorInfo('ApprovalMode', 'ApprovalMode, ApprovedByUserID, and ApprovedAt are maintained by the server and cannot be bound via transaction variables.', this.ApprovalMode, ValidationErrorType.Failure);
|
|
640
|
+
}
|
|
641
|
+
if (this.matchesLastServerStamp()) {
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
if (!this.IsSaved) {
|
|
645
|
+
if (this.ApprovalMode != null || this.GetFieldByName('ApprovalMode')?.Dirty) {
|
|
646
|
+
return this.clientStampError('ApprovalMode', this.ApprovalMode);
|
|
647
|
+
}
|
|
648
|
+
if (this.ApprovedByUserID != null || this.GetFieldByName('ApprovedByUserID')?.Dirty) {
|
|
649
|
+
return this.clientStampError('ApprovedByUserID', this.ApprovedByUserID);
|
|
650
|
+
}
|
|
651
|
+
if (this.ApprovedAt != null || this.GetFieldByName('ApprovedAt')?.Dirty) {
|
|
652
|
+
return this.clientStampError('ApprovedAt', this.ApprovedAt);
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
for (const fieldName of CONCEPT_APPROVAL_STAMP_FIELDS) {
|
|
657
|
+
const field = this.GetFieldByName(fieldName);
|
|
658
|
+
if (field?.Dirty) {
|
|
659
|
+
const value = fieldName === 'ApprovalMode'
|
|
660
|
+
? this.ApprovalMode
|
|
661
|
+
: fieldName === 'ApprovedByUserID'
|
|
662
|
+
? this.ApprovedByUserID
|
|
663
|
+
: this.ApprovedAt;
|
|
664
|
+
return this.clientStampError(fieldName, value);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
matchesLastServerStamp() {
|
|
670
|
+
if (!this._serverStampedApproval) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
return ((this.ApprovalMode ?? null) === (this._serverStampedApproval.ApprovalMode ?? null) &&
|
|
674
|
+
(this.ApprovedByUserID ?? null) === (this._serverStampedApproval.ApprovedByUserID ?? null) &&
|
|
675
|
+
dateToMillis(this.ApprovedAt) === this._serverStampedApproval.ApprovedAtMs);
|
|
676
|
+
}
|
|
677
|
+
clientStampError(field, value) {
|
|
678
|
+
return new ValidationErrorInfo(field, `"${field}" is a server-maintained approval stamp (D42) and cannot be set or modified by a client.`, value, ValidationErrorType.Failure);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Applies D42 approval stamp lifecycle rules after validation passes:
|
|
682
|
+
* - Entering `Approved` or `Provisional` (or editing governed fields on one as a person):
|
|
683
|
+
* stamps `ApprovalMode = 'Policy'` (pipeline policy create) or `'Person'` (authorized human)
|
|
684
|
+
* along with `ApprovedByUserID` (null when non-human) and `ApprovedAt`.
|
|
685
|
+
* - Leaving `Approved` or `Provisional` (e.g. `Draft`, `Proposed`, `Deprecated`):
|
|
686
|
+
* clears all three columns to `null`.
|
|
687
|
+
*/
|
|
688
|
+
applyServerApprovalStamp() {
|
|
689
|
+
const previousStatus = this.IsSaved ? this.previousStatus() : null;
|
|
690
|
+
const effectiveNextStatus = !this.IsSaved && this.Status == null ? 'Draft' : this.Status;
|
|
691
|
+
const enteringOrStayingApproved = isApprovedOrProvisionalConceptStatus(effectiveNextStatus);
|
|
692
|
+
const leavingApproved = this.IsSaved && isApprovedOrProvisionalConceptStatus(previousStatus) && !enteringOrStayingApproved;
|
|
693
|
+
if (enteringOrStayingApproved) {
|
|
694
|
+
const inPipelineScope = IsInGraphConceptPipelineApprovalScope(this.ContextCurrentUser);
|
|
695
|
+
const isPipelineCreate = !this.IsSaved && effectiveNextStatus === 'Approved' && inPipelineScope;
|
|
696
|
+
const statusChanged = !this.IsSaved || previousStatus !== effectiveNextStatus;
|
|
697
|
+
const governedChanged = this.IsSaved && HasGovernedConceptFieldChanges(this);
|
|
698
|
+
if (isPipelineCreate) {
|
|
699
|
+
const now = new Date();
|
|
700
|
+
this.ApprovalMode = 'Policy';
|
|
701
|
+
this.ApprovedByUserID = null;
|
|
702
|
+
this.ApprovedAt = now;
|
|
703
|
+
this._serverStampedApproval = {
|
|
704
|
+
ApprovalMode: 'Policy',
|
|
705
|
+
ApprovedByUserID: null,
|
|
706
|
+
ApprovedAtMs: now.getTime(),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
else if ((statusChanged || governedChanged) && this.ContextCurrentUser?.ID) {
|
|
710
|
+
const now = new Date();
|
|
711
|
+
this.ApprovalMode = 'Person';
|
|
712
|
+
this.ApprovedByUserID = this.ContextCurrentUser.ID;
|
|
713
|
+
this.ApprovedAt = now;
|
|
714
|
+
this._serverStampedApproval = {
|
|
715
|
+
ApprovalMode: 'Person',
|
|
716
|
+
ApprovedByUserID: this.ContextCurrentUser.ID,
|
|
717
|
+
ApprovedAtMs: now.getTime(),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
if (leavingApproved) {
|
|
723
|
+
this.ApprovalMode = null;
|
|
724
|
+
this.ApprovedByUserID = null;
|
|
725
|
+
this.ApprovedAt = null;
|
|
726
|
+
this._serverStampedApproval = {
|
|
727
|
+
ApprovalMode: null,
|
|
728
|
+
ApprovedByUserID: null,
|
|
729
|
+
ApprovedAtMs: null,
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
previousOrigin() {
|
|
734
|
+
const field = this.GetFieldByName('Origin');
|
|
735
|
+
if (field?.NotLoaded) {
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
const oldValue = field?.OldValue;
|
|
739
|
+
return oldValue === 'Declared' || oldValue === 'Inferred' ? oldValue : null;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
MJGraphConceptEntityServer = __decorate([
|
|
743
|
+
RegisterClass(BaseEntity, 'MJ: Graph Concepts')
|
|
744
|
+
], MJGraphConceptEntityServer);
|
|
745
|
+
export { MJGraphConceptEntityServer };
|
|
746
|
+
//# sourceMappingURL=MJGraphConceptEntityServer.server.js.map
|