@memberjunction/core-entities-server 6.2.2 → 6.3.0-edge.1

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.
Files changed (200) hide show
  1. package/README.md +19 -0
  2. package/dist/custom/AnchoredConversationReadSecurityHook.d.ts +1 -14
  3. package/dist/custom/AnchoredConversationReadSecurityHook.d.ts.map +1 -1
  4. package/dist/custom/AnchoredConversationReadSecurityHook.js +43 -5
  5. package/dist/custom/AnchoredConversationReadSecurityHook.js.map +1 -1
  6. package/dist/custom/ArtifactSecurityHookHelpers.d.ts +223 -0
  7. package/dist/custom/ArtifactSecurityHookHelpers.d.ts.map +1 -0
  8. package/dist/custom/ArtifactSecurityHookHelpers.js +1402 -0
  9. package/dist/custom/ArtifactSecurityHookHelpers.js.map +1 -0
  10. package/dist/custom/ConversationAndCommentDrivers.d.ts +82 -0
  11. package/dist/custom/ConversationAndCommentDrivers.d.ts.map +1 -0
  12. package/dist/custom/ConversationAndCommentDrivers.js +543 -0
  13. package/dist/custom/ConversationAndCommentDrivers.js.map +1 -0
  14. package/dist/custom/FieldSuggestionRecordChangeHook.d.ts +17 -0
  15. package/dist/custom/FieldSuggestionRecordChangeHook.d.ts.map +1 -0
  16. package/dist/custom/FieldSuggestionRecordChangeHook.js +142 -0
  17. package/dist/custom/FieldSuggestionRecordChangeHook.js.map +1 -0
  18. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts +11 -0
  19. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.d.ts.map +1 -1
  20. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js +41 -0
  21. package/dist/custom/MJAIAgentUserPolicyEntityServer.server.js.map +1 -1
  22. package/dist/custom/MJAIBridgeAgentIdentityEntityServer.server.js +2 -2
  23. package/dist/custom/MJAIBridgeAgentIdentityEntityServer.server.js.map +1 -1
  24. package/dist/custom/MJAIPromptRunEntityServer.server.d.ts +21 -0
  25. package/dist/custom/MJAIPromptRunEntityServer.server.d.ts.map +1 -1
  26. package/dist/custom/MJAIPromptRunEntityServer.server.js +76 -5
  27. package/dist/custom/MJAIPromptRunEntityServer.server.js.map +1 -1
  28. package/dist/custom/MJArtifactEntityServer.server.d.ts +38 -0
  29. package/dist/custom/MJArtifactEntityServer.server.d.ts.map +1 -0
  30. package/dist/custom/MJArtifactEntityServer.server.js +436 -0
  31. package/dist/custom/MJArtifactEntityServer.server.js.map +1 -0
  32. package/dist/custom/MJArtifactGuestShareLinkEntityServer.server.d.ts +32 -0
  33. package/dist/custom/MJArtifactGuestShareLinkEntityServer.server.d.ts.map +1 -0
  34. package/dist/custom/MJArtifactGuestShareLinkEntityServer.server.js +434 -0
  35. package/dist/custom/MJArtifactGuestShareLinkEntityServer.server.js.map +1 -0
  36. package/dist/custom/MJArtifactPermissionEntityServer.server.d.ts +18 -0
  37. package/dist/custom/MJArtifactPermissionEntityServer.server.d.ts.map +1 -0
  38. package/dist/custom/MJArtifactPermissionEntityServer.server.js +194 -0
  39. package/dist/custom/MJArtifactPermissionEntityServer.server.js.map +1 -0
  40. package/dist/custom/MJArtifactVersionAttributeEntityServer.server.d.ts +22 -0
  41. package/dist/custom/MJArtifactVersionAttributeEntityServer.server.d.ts.map +1 -0
  42. package/dist/custom/MJArtifactVersionAttributeEntityServer.server.js +312 -0
  43. package/dist/custom/MJArtifactVersionAttributeEntityServer.server.js.map +1 -0
  44. package/dist/custom/MJArtifactVersionEntityServer.server.d.ts +76 -12
  45. package/dist/custom/MJArtifactVersionEntityServer.server.d.ts.map +1 -1
  46. package/dist/custom/MJArtifactVersionEntityServer.server.js +934 -55
  47. package/dist/custom/MJArtifactVersionEntityServer.server.js.map +1 -1
  48. package/dist/custom/MJArtifactWorkingStateEntityServer.server.d.ts +42 -0
  49. package/dist/custom/MJArtifactWorkingStateEntityServer.server.d.ts.map +1 -0
  50. package/dist/custom/MJArtifactWorkingStateEntityServer.server.js +547 -0
  51. package/dist/custom/MJArtifactWorkingStateEntityServer.server.js.map +1 -0
  52. package/dist/custom/MJCollectionArtifactEntityServer.server.d.ts +36 -0
  53. package/dist/custom/MJCollectionArtifactEntityServer.server.d.ts.map +1 -0
  54. package/dist/custom/MJCollectionArtifactEntityServer.server.js +533 -0
  55. package/dist/custom/MJCollectionArtifactEntityServer.server.js.map +1 -0
  56. package/dist/custom/MJCollectionEntityServer.server.d.ts +23 -0
  57. package/dist/custom/MJCollectionEntityServer.server.d.ts.map +1 -0
  58. package/dist/custom/MJCollectionEntityServer.server.js +555 -0
  59. package/dist/custom/MJCollectionEntityServer.server.js.map +1 -0
  60. package/dist/custom/MJCollectionPermissionEntityServer.server.d.ts +18 -0
  61. package/dist/custom/MJCollectionPermissionEntityServer.server.d.ts.map +1 -0
  62. package/dist/custom/MJCollectionPermissionEntityServer.server.js +196 -0
  63. package/dist/custom/MJCollectionPermissionEntityServer.server.js.map +1 -0
  64. package/dist/custom/MJCommentEntityServer.server.d.ts +19 -0
  65. package/dist/custom/MJCommentEntityServer.server.d.ts.map +1 -0
  66. package/dist/custom/MJCommentEntityServer.server.js +137 -0
  67. package/dist/custom/MJCommentEntityServer.server.js.map +1 -0
  68. package/dist/custom/MJConversationEntityServer.server.d.ts +11 -4
  69. package/dist/custom/MJConversationEntityServer.server.d.ts.map +1 -1
  70. package/dist/custom/MJConversationEntityServer.server.js +75 -11
  71. package/dist/custom/MJConversationEntityServer.server.js.map +1 -1
  72. package/dist/custom/MJEntityEntityServer.server.d.ts +9 -0
  73. package/dist/custom/MJEntityEntityServer.server.d.ts.map +1 -1
  74. package/dist/custom/MJEntityEntityServer.server.js +31 -2
  75. package/dist/custom/MJEntityEntityServer.server.js.map +1 -1
  76. package/dist/custom/MJFieldSuggestionEntityServer.server.d.ts +29 -0
  77. package/dist/custom/MJFieldSuggestionEntityServer.server.d.ts.map +1 -0
  78. package/dist/custom/MJFieldSuggestionEntityServer.server.js +249 -0
  79. package/dist/custom/MJFieldSuggestionEntityServer.server.js.map +1 -0
  80. package/dist/custom/MJGraphEdgeEntityServer.server.d.ts +197 -0
  81. package/dist/custom/MJGraphEdgeEntityServer.server.d.ts.map +1 -0
  82. package/dist/custom/MJGraphEdgeEntityServer.server.js +459 -0
  83. package/dist/custom/MJGraphEdgeEntityServer.server.js.map +1 -0
  84. package/dist/custom/MJGraphEdgeProviderEntityServer.server.d.ts +22 -0
  85. package/dist/custom/MJGraphEdgeProviderEntityServer.server.d.ts.map +1 -0
  86. package/dist/custom/MJGraphEdgeProviderEntityServer.server.js +85 -0
  87. package/dist/custom/MJGraphEdgeProviderEntityServer.server.js.map +1 -0
  88. package/dist/custom/MJGraphEdgeTypeEntityServer.server.d.ts +21 -0
  89. package/dist/custom/MJGraphEdgeTypeEntityServer.server.d.ts.map +1 -0
  90. package/dist/custom/MJGraphEdgeTypeEntityServer.server.js +88 -0
  91. package/dist/custom/MJGraphEdgeTypeEntityServer.server.js.map +1 -0
  92. package/dist/custom/MJListEntityServer.server.d.ts +26 -10
  93. package/dist/custom/MJListEntityServer.server.d.ts.map +1 -1
  94. package/dist/custom/MJListEntityServer.server.js +118 -20
  95. package/dist/custom/MJListEntityServer.server.js.map +1 -1
  96. package/dist/custom/MJMLEvaluationProtocolEntityServer.server.d.ts +39 -0
  97. package/dist/custom/MJMLEvaluationProtocolEntityServer.server.d.ts.map +1 -0
  98. package/dist/custom/MJMLEvaluationProtocolEntityServer.server.js +124 -0
  99. package/dist/custom/MJMLEvaluationProtocolEntityServer.server.js.map +1 -0
  100. package/dist/custom/MJMLPredictionUnitEntityServer.server.d.ts +124 -0
  101. package/dist/custom/MJMLPredictionUnitEntityServer.server.d.ts.map +1 -0
  102. package/dist/custom/MJMLPredictionUnitEntityServer.server.js +214 -0
  103. package/dist/custom/MJMLPredictionUnitEntityServer.server.js.map +1 -0
  104. package/dist/custom/MJMLTrainingPipelineEntityServer.server.d.ts +101 -1
  105. package/dist/custom/MJMLTrainingPipelineEntityServer.server.d.ts.map +1 -1
  106. package/dist/custom/MJMLTrainingPipelineEntityServer.server.js +266 -12
  107. package/dist/custom/MJMLTrainingPipelineEntityServer.server.js.map +1 -1
  108. package/dist/custom/MJMLTrainingSnapshotEntityServer.server.d.ts +14 -0
  109. package/dist/custom/MJMLTrainingSnapshotEntityServer.server.d.ts.map +1 -0
  110. package/dist/custom/MJMLTrainingSnapshotEntityServer.server.js +42 -0
  111. package/dist/custom/MJMLTrainingSnapshotEntityServer.server.js.map +1 -0
  112. package/dist/custom/MJProjectEntityServer.server.d.ts +28 -2
  113. package/dist/custom/MJProjectEntityServer.server.d.ts.map +1 -1
  114. package/dist/custom/MJProjectEntityServer.server.js +115 -2
  115. package/dist/custom/MJProjectEntityServer.server.js.map +1 -1
  116. package/dist/custom/MJQueryEntityServer.server.d.ts +10 -6
  117. package/dist/custom/MJQueryEntityServer.server.d.ts.map +1 -1
  118. package/dist/custom/MJQueryEntityServer.server.js +27 -16
  119. package/dist/custom/MJQueryEntityServer.server.js.map +1 -1
  120. package/dist/custom/MJScheduledJobEntityServer.server.d.ts +27 -0
  121. package/dist/custom/MJScheduledJobEntityServer.server.d.ts.map +1 -0
  122. package/dist/custom/MJScheduledJobEntityServer.server.js +56 -0
  123. package/dist/custom/MJScheduledJobEntityServer.server.js.map +1 -0
  124. package/dist/custom/MJScopedNotificationConfigEntityServer.server.d.ts +15 -0
  125. package/dist/custom/MJScopedNotificationConfigEntityServer.server.d.ts.map +1 -0
  126. package/dist/custom/MJScopedNotificationConfigEntityServer.server.js +48 -0
  127. package/dist/custom/MJScopedNotificationConfigEntityServer.server.js.map +1 -0
  128. package/dist/custom/MJTagEntityServer.server.d.ts +11 -1
  129. package/dist/custom/MJTagEntityServer.server.d.ts.map +1 -1
  130. package/dist/custom/MJTagEntityServer.server.js +28 -3
  131. package/dist/custom/MJTagEntityServer.server.js.map +1 -1
  132. package/dist/custom/MJTaskDependencyEntityServer.server.d.ts +24 -0
  133. package/dist/custom/MJTaskDependencyEntityServer.server.d.ts.map +1 -0
  134. package/dist/custom/MJTaskDependencyEntityServer.server.js +75 -0
  135. package/dist/custom/MJTaskDependencyEntityServer.server.js.map +1 -0
  136. package/dist/custom/MJTaskEntityServer.server.d.ts +148 -0
  137. package/dist/custom/MJTaskEntityServer.server.d.ts.map +1 -0
  138. package/dist/custom/MJTaskEntityServer.server.js +413 -0
  139. package/dist/custom/MJTaskEntityServer.server.js.map +1 -0
  140. package/dist/custom/MJUserEntityServer.server.d.ts +2 -1
  141. package/dist/custom/MJUserEntityServer.server.d.ts.map +1 -1
  142. package/dist/custom/MJUserEntityServer.server.js +2 -1
  143. package/dist/custom/MJUserEntityServer.server.js.map +1 -1
  144. package/dist/custom/MJUserViewEntityServer.server.d.ts +8 -2
  145. package/dist/custom/MJUserViewEntityServer.server.d.ts.map +1 -1
  146. package/dist/custom/MJUserViewEntityServer.server.js +25 -12
  147. package/dist/custom/MJUserViewEntityServer.server.js.map +1 -1
  148. package/dist/custom/RestrictedFieldCommentClassifier.d.ts +9 -3
  149. package/dist/custom/RestrictedFieldCommentClassifier.d.ts.map +1 -1
  150. package/dist/custom/RestrictedFieldCommentClassifier.js +91 -15
  151. package/dist/custom/RestrictedFieldCommentClassifier.js.map +1 -1
  152. package/dist/custom/RestrictedFieldDecision.d.ts +121 -0
  153. package/dist/custom/RestrictedFieldDecision.d.ts.map +1 -0
  154. package/dist/custom/RestrictedFieldDecision.js +168 -0
  155. package/dist/custom/RestrictedFieldDecision.js.map +1 -0
  156. package/dist/custom/SpreadsheetWorkerEntry.d.ts +25 -0
  157. package/dist/custom/SpreadsheetWorkerEntry.d.ts.map +1 -0
  158. package/dist/custom/SpreadsheetWorkerEntry.js +37 -0
  159. package/dist/custom/SpreadsheetWorkerEntry.js.map +1 -0
  160. package/dist/custom/SpreadsheetWorkerRunner.d.ts +45 -0
  161. package/dist/custom/SpreadsheetWorkerRunner.d.ts.map +1 -0
  162. package/dist/custom/SpreadsheetWorkerRunner.js +243 -0
  163. package/dist/custom/SpreadsheetWorkerRunner.js.map +1 -0
  164. package/dist/custom/fieldPermissionDelta.d.ts +15 -1
  165. package/dist/custom/fieldPermissionDelta.d.ts.map +1 -1
  166. package/dist/custom/fieldPermissionDelta.js +28 -7
  167. package/dist/custom/fieldPermissionDelta.js.map +1 -1
  168. package/dist/custom/fieldPermissionReconciler.d.ts +4 -1
  169. package/dist/custom/fieldPermissionReconciler.d.ts.map +1 -1
  170. package/dist/custom/fieldPermissionReconciler.js +4 -2
  171. package/dist/custom/fieldPermissionReconciler.js.map +1 -1
  172. package/dist/custom/list-refresh/ListRefreshRoutine.d.ts +40 -0
  173. package/dist/custom/list-refresh/ListRefreshRoutine.d.ts.map +1 -0
  174. package/dist/custom/list-refresh/ListRefreshRoutine.js +114 -0
  175. package/dist/custom/list-refresh/ListRefreshRoutine.js.map +1 -0
  176. package/dist/custom/query-extraction/childRowWriter.d.ts +2 -2
  177. package/dist/custom/query-extraction/childRowWriter.d.ts.map +1 -1
  178. package/dist/custom/query-extraction/childRowWriter.js +7 -2
  179. package/dist/custom/query-extraction/childRowWriter.js.map +1 -1
  180. package/dist/custom/query-extraction/describeFacts.d.ts +2 -0
  181. package/dist/custom/query-extraction/describeFacts.d.ts.map +1 -1
  182. package/dist/custom/query-extraction/describeFacts.js +17 -10
  183. package/dist/custom/query-extraction/describeFacts.js.map +1 -1
  184. package/dist/custom/query-extraction/descriptionPass.d.ts.map +1 -1
  185. package/dist/custom/query-extraction/descriptionPass.js +4 -1
  186. package/dist/custom/query-extraction/descriptionPass.js.map +1 -1
  187. package/dist/custom/query-extraction/extractQuery.js +5 -3
  188. package/dist/custom/query-extraction/extractQuery.js.map +1 -1
  189. package/dist/custom/query-extraction/extractionTypes.d.ts +5 -0
  190. package/dist/custom/query-extraction/extractionTypes.d.ts.map +1 -1
  191. package/dist/custom/sessionConfigGuard.d.ts +7 -0
  192. package/dist/custom/sessionConfigGuard.d.ts.map +1 -1
  193. package/dist/custom/sessionConfigGuard.js +13 -1
  194. package/dist/custom/sessionConfigGuard.js.map +1 -1
  195. package/dist/index.d.ts +25 -0
  196. package/dist/index.d.ts.map +1 -1
  197. package/dist/index.js +34 -0
  198. package/dist/index.js.map +1 -1
  199. package/dist/tsconfig.tsbuildinfo +1 -0
  200. package/package.json +31 -30
@@ -0,0 +1,88 @@
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 { BaseEntity, ValidationErrorInfo, ValidationErrorType, } from '@memberjunction/core';
8
+ import { NormalizeUUID, RegisterClass } from '@memberjunction/global';
9
+ import { GraphEngine, IsGraphDataProvider, MJGraphEdgeTypeEntity } from '@memberjunction/core-entities';
10
+ /**
11
+ * Pure invariant check for `MJ: Graph Edge Types` `(GraphID, Name)` uniqueness,
12
+ * including global (`GraphID === null`) edge types.
13
+ */
14
+ export function ValidateGraphEdgeTypeUniqueness(candidate, existingEdgeTypes) {
15
+ const trimmedName = candidate.Name?.trim();
16
+ if (!trimmedName) {
17
+ return null;
18
+ }
19
+ const candidateIdNorm = candidate.ID ? NormalizeUUID(candidate.ID) : '';
20
+ const candidateGraphNorm = candidate.GraphID ? NormalizeUUID(candidate.GraphID) : null;
21
+ const candidateNameLower = trimmedName.toLowerCase();
22
+ for (const existing of existingEdgeTypes) {
23
+ if (candidateIdNorm && existing.ID && NormalizeUUID(existing.ID) === candidateIdNorm) {
24
+ continue;
25
+ }
26
+ const existingGraphNorm = existing.GraphID ? NormalizeUUID(existing.GraphID) : null;
27
+ if (existingGraphNorm !== candidateGraphNorm) {
28
+ continue;
29
+ }
30
+ if ((existing.Name ?? '').trim().toLowerCase() === candidateNameLower) {
31
+ const scopeDesc = candidateGraphNorm ? `graph "${candidate.GraphID}"` : 'global edge types (GraphID = NULL)';
32
+ return new ValidationErrorInfo('Name', `An edge type named "${trimmedName}" already exists in ${scopeDesc}.`, candidate.Name, ValidationErrorType.Failure);
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * Server-side `MJ: Graph Edge Types` entity enforcing `(GraphID, Name)` uniqueness
39
+ * across both graph-scoped and global (`GraphID === null`) edge types.
40
+ */
41
+ let MJGraphEdgeTypeEntityServer = class MJGraphEdgeTypeEntityServer extends MJGraphEdgeTypeEntity {
42
+ get DefaultSkipAsyncValidation() {
43
+ return false;
44
+ }
45
+ async ValidateAsync() {
46
+ const result = await super.ValidateAsync();
47
+ if (!result.Success) {
48
+ return result;
49
+ }
50
+ // Uniqueness is judged against GraphEngine's cached edge types, so they must be loaded. Config is a
51
+ // no-op once loaded, and on a server BaseEngine loads it as the system user (never this caller's
52
+ // scope). A load failure is an error: an empty cache would pass every duplicate.
53
+ const provider = this.ProviderToUse;
54
+ if (!IsGraphDataProvider(provider)) {
55
+ return this.fail(result, 'Graph edge types can only be validated against a metadata provider.');
56
+ }
57
+ try {
58
+ await GraphEngine.Instance.Config(false, this.ContextCurrentUser, provider);
59
+ }
60
+ catch (err) {
61
+ const msg = err instanceof Error ? err.message : String(err);
62
+ return this.fail(result, `Graph metadata could not be loaded to validate this edge type: ${msg}`);
63
+ }
64
+ if (!GraphEngine.Instance.Loaded) {
65
+ return this.fail(result, 'Graph metadata could not be loaded to validate this edge type.');
66
+ }
67
+ const dupError = ValidateGraphEdgeTypeUniqueness({
68
+ ID: this.ID,
69
+ GraphID: this.GraphID,
70
+ Name: this.Name,
71
+ }, GraphEngine.Instance.EdgeTypes);
72
+ if (dupError) {
73
+ result.Errors.push(dupError);
74
+ result.Success = false;
75
+ }
76
+ return result;
77
+ }
78
+ fail(result, message) {
79
+ result.Errors.push(new ValidationErrorInfo('Name', message, this.Name, ValidationErrorType.Failure));
80
+ result.Success = false;
81
+ return result;
82
+ }
83
+ };
84
+ MJGraphEdgeTypeEntityServer = __decorate([
85
+ RegisterClass(BaseEntity, 'MJ: Graph Edge Types')
86
+ ], MJGraphEdgeTypeEntityServer);
87
+ export { MJGraphEdgeTypeEntityServer };
88
+ //# sourceMappingURL=MJGraphEdgeTypeEntityServer.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MJGraphEdgeTypeEntityServer.server.js","sourceRoot":"","sources":["../../src/custom/MJGraphEdgeTypeEntityServer.server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,UAAU,EACV,mBAAmB,EACnB,mBAAmB,GAEtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAExG;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAC3C,SAIC,EACD,iBAAoF;IAEpF,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,eAAe,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,MAAM,kBAAkB,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvF,MAAM,kBAAkB,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC;IAErD,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;QACvC,IAAI,eAAe,IAAI,QAAQ,CAAC,EAAE,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,eAAe,EAA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
@@ -1,18 +1,34 @@
1
- import { EntityDeleteOptions } from '@memberjunction/core';
1
+ import { EntityDeleteOptions, EntitySaveOptions, ValidationResult } from '@memberjunction/core';
2
2
  import { MJListEntityExtended } from '@memberjunction/core-entities';
3
3
  /**
4
- * Server-side Lists entity. Enforces row-level DELETE authorization: a user may delete a List only
5
- * if they own it, UNLESS they hold the Developer or Integration role (who may delete any List). The
6
- * rule itself lives once in {@link MJListEntityExtended.UserCanDelete} and is shared with the UI.
4
+ * Server-side Lists entity.
7
5
  *
8
- * This is the security-critical enforcement point. The `EntityPermission` migration grants the UI
9
- * role entity-wide Delete permission on Lists (so standard users can delete their own); this override
10
- * narrows that back down to owner-or-privileged at the application layer, since coarse entity
11
- * permissions can't express row-level ownership. On denial it returns `false` and records a
12
- * `BaseEntityResult` so callers get `LatestResult.CompleteMessage` (Delete does not throw on a
13
- * logical rejection — see the CLAUDE.md Save/Delete error-handling contract).
6
+ * **Delete.** A user may delete a List only if they own it, unless they hold the Developer or
7
+ * Integration role. The rule lives once in {@link MJListEntityExtended.UserCanDelete} and is shared
8
+ * with the UI. The `EntityPermission` migration grants the UI role entity-wide Delete on Lists, and
9
+ * this override narrows it to owner-or-privileged, since entity permissions can't express row-level
10
+ * ownership. The list's refresh routine is deleted after the list.
11
+ *
12
+ * **Source and refresh.** Only the list's owner may link it to a source query or view, or turn on
13
+ * Refresh automatically. Linking an existing list to a new source fills it from that source right
14
+ * away, adding records only. Turning Refresh automatically on creates (or re-enables) a User Routine
15
+ * that runs "Refresh List From Source" on the Lists app's default schedule; turning it off disables
16
+ * the routine. Both happen after the save and never fail it: the list is valid and already saved,
17
+ * so an error is logged instead.
14
18
  */
15
19
  export declare class MJListEntityServer extends MJListEntityExtended {
20
+ Validate(): ValidationResult;
21
+ Save(options?: EntitySaveOptions): Promise<boolean>;
16
22
  Delete(options?: EntityDeleteOptions): Promise<boolean>;
23
+ private get hasSource();
24
+ /** Refuses a save that links a source or turns on Refresh automatically, unless the saving user owns the list. */
25
+ private ownerOnlyRefusal;
26
+ private reconcileRoutineSafely;
27
+ /** Fills the list from its newly linked source, adding records only. */
28
+ private fillFromSourceSafely;
29
+ private runSafely;
30
+ private routine;
31
+ private anyFieldDirty;
32
+ private refusalResult;
17
33
  }
18
34
  //# sourceMappingURL=MJListEntityServer.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MJListEntityServer.server.d.ts","sourceRoot":"","sources":["../../src/custom/MJListEntityServer.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,qBACa,kBAAmB,SAAQ,oBAAoB;IAClC,MAAM,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;CAchF"}
1
+ {"version":3,"file":"MJListEntityServer.server.d.ts","sourceRoot":"","sources":["../../src/custom/MJListEntityServer.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,mBAAmB,EACnB,iBAAiB,EAKjB,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAWrE;;;;;;;;;;;;;;;GAeG;AACH,qBACa,kBAAmB,SAAQ,oBAAoB;IACxC,QAAQ,IAAI,gBAAgB;IActB,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBnD,MAAM,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB7E,OAAO,KAAK,SAAS,GAEpB;IAED,kHAAkH;IAClH,OAAO,CAAC,gBAAgB;YAQV,sBAAsB;IAYpC,wEAAwE;YAC1D,oBAAoB;YAQpB,SAAS;IAQvB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,aAAa;CASxB"}
@@ -4,35 +4,133 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { BaseEntity, BaseEntityResult } from '@memberjunction/core';
8
- import { RegisterClass } from '@memberjunction/global';
7
+ import { BaseEntity, BaseEntityResult, LogError, ValidationErrorInfo, ValidationErrorType, } from '@memberjunction/core';
8
+ import { RegisterClass, UUIDsEqual } from '@memberjunction/global';
9
9
  import { MJListEntityExtended } from '@memberjunction/core-entities';
10
+ import { ListOperations } from '@memberjunction/lists';
11
+ import { ListRefreshRoutine } from './list-refresh/ListRefreshRoutine.js';
12
+ /** The fields that say which source a list refreshes from. Changing any of them re-links the list. */
13
+ const SOURCE_IDENTITY_FIELDS = ['SourceViewID', 'SourceQueryID', 'SourceQueryKeyField'];
14
+ /** The fields the list's refresh routine follows. */
15
+ const ROUTINE_FIELDS = ['AutoRefresh', 'Name', 'UserID', 'SourceViewID', 'SourceQueryID'];
10
16
  /**
11
- * Server-side Lists entity. Enforces row-level DELETE authorization: a user may delete a List only
12
- * if they own it, UNLESS they hold the Developer or Integration role (who may delete any List). The
13
- * rule itself lives once in {@link MJListEntityExtended.UserCanDelete} and is shared with the UI.
17
+ * Server-side Lists entity.
14
18
  *
15
- * This is the security-critical enforcement point. The `EntityPermission` migration grants the UI
16
- * role entity-wide Delete permission on Lists (so standard users can delete their own); this override
17
- * narrows that back down to owner-or-privileged at the application layer, since coarse entity
18
- * permissions can't express row-level ownership. On denial it returns `false` and records a
19
- * `BaseEntityResult` so callers get `LatestResult.CompleteMessage` (Delete does not throw on a
20
- * logical rejection — see the CLAUDE.md Save/Delete error-handling contract).
19
+ * **Delete.** A user may delete a List only if they own it, unless they hold the Developer or
20
+ * Integration role. The rule lives once in {@link MJListEntityExtended.UserCanDelete} and is shared
21
+ * with the UI. The `EntityPermission` migration grants the UI role entity-wide Delete on Lists, and
22
+ * this override narrows it to owner-or-privileged, since entity permissions can't express row-level
23
+ * ownership. The list's refresh routine is deleted after the list.
24
+ *
25
+ * **Source and refresh.** Only the list's owner may link it to a source query or view, or turn on
26
+ * Refresh automatically. Linking an existing list to a new source fills it from that source right
27
+ * away, adding records only. Turning Refresh automatically on creates (or re-enables) a User Routine
28
+ * that runs "Refresh List From Source" on the Lists app's default schedule; turning it off disables
29
+ * the routine. Both happen after the save and never fail it: the list is valid and already saved,
30
+ * so an error is logged instead.
21
31
  */
22
32
  let MJListEntityServer = class MJListEntityServer extends MJListEntityExtended {
33
+ Validate() {
34
+ const result = super.Validate();
35
+ if (this.SourceQueryID && !this.SourceQueryKeyField?.trim()) {
36
+ result.Errors.push(new ValidationErrorInfo('SourceQueryKeyField', 'A list refreshed from a query needs SourceQueryKeyField: the query column that holds the record key.', this.SourceQueryKeyField, ValidationErrorType.Failure));
37
+ }
38
+ result.Success = result.Success && result.Errors.length === 0;
39
+ return result;
40
+ }
41
+ async Save(options) {
42
+ if (options?.ReplayOnly)
43
+ return super.Save(options);
44
+ // Read before the save, which resets every dirty flag.
45
+ const isNew = !this.IsSaved;
46
+ const sourceRelinked = this.anyFieldDirty(SOURCE_IDENTITY_FIELDS) && this.hasSource;
47
+ const reconcileRoutine = (isNew && this.AutoRefresh) || (!isNew && this.anyFieldDirty(ROUTINE_FIELDS));
48
+ const refusal = this.ownerOnlyRefusal(sourceRelinked || (this.AutoRefresh && this.anyFieldDirty(['AutoRefresh'])));
49
+ if (refusal) {
50
+ this.RegisterResultHistoryEntry(refusal);
51
+ return false;
52
+ }
53
+ // A new source has not been approved by anyone yet: its first refresh takes its fingerprint.
54
+ if (sourceRelinked)
55
+ this.SourceFingerprint = null;
56
+ if (!(await super.Save(options)))
57
+ return false;
58
+ if (reconcileRoutine)
59
+ await this.reconcileRoutineSafely(options);
60
+ // A list created with a source was filled by whatever created it (MaterializeFromView does).
61
+ if (sourceRelinked && !isNew)
62
+ await this.fillFromSourceSafely();
63
+ return true;
64
+ }
23
65
  async Delete(options) {
24
66
  if (!MJListEntityExtended.UserCanDelete(this.UserID, this.ContextCurrentUser)) {
25
- const result = new BaseEntityResult();
26
- result.StartedAt = new Date();
27
- result.Success = false;
28
- result.Type = 'delete';
29
- result.Message = 'You do not have permission to delete this List. Only the List owner, ' +
30
- 'or a user in the Developer or Integration role, may delete it.';
31
- result.EndedAt = new Date();
32
- this.RegisterResultHistoryEntry(result);
67
+ this.RegisterResultHistoryEntry(this.refusalResult('delete', 'You do not have permission to delete this List. Only the List owner, ' +
68
+ 'or a user in the Developer or Integration role, may delete it.'));
33
69
  return false;
34
70
  }
35
- return super.Delete(options);
71
+ const routineID = this.RefreshRoutineID;
72
+ if (!(await super.Delete(options)))
73
+ return false;
74
+ // The list's foreign key points at the routine, so the routine goes after the list.
75
+ if (routineID) {
76
+ await this.runSafely('routine delete', () => this.routine().DeleteAsync(routineID));
77
+ }
78
+ return true;
79
+ }
80
+ get hasSource() {
81
+ return !!this.SourceViewID || !!this.SourceQueryID;
82
+ }
83
+ /** Refuses a save that links a source or turns on Refresh automatically, unless the saving user owns the list. */
84
+ ownerOnlyRefusal(ownerOnlyChange) {
85
+ if (!ownerOnlyChange)
86
+ return null;
87
+ const user = this.ContextCurrentUser;
88
+ if (user && UUIDsEqual(user.ID, this.UserID))
89
+ return null;
90
+ return this.refusalResult('update', 'Only the owner of this List can link it to a source or turn on Refresh automatically.');
91
+ }
92
+ async reconcileRoutineSafely(options) {
93
+ await this.runSafely('refresh routine', async () => {
94
+ const routineID = await this.routine().ReconcileAsync(this);
95
+ if (routineID && !UUIDsEqual(routineID, this.RefreshRoutineID)) {
96
+ this.RefreshRoutineID = routineID;
97
+ if (!(await super.Save(options))) {
98
+ throw new Error(`could not store the routine ID: ${this.LatestResult?.CompleteMessage ?? 'unknown error'}`);
99
+ }
100
+ }
101
+ });
102
+ }
103
+ /** Fills the list from its newly linked source, adding records only. */
104
+ async fillFromSourceSafely() {
105
+ await this.runSafely('fill from new source', async () => {
106
+ const result = await new ListOperations(this.ContextCurrentUser, this.ProviderToUse)
107
+ .RefreshFromSource(this.ID, 'Additive', { ConfirmDrops: false });
108
+ if (!result.Success)
109
+ throw new Error(`${result.ResultCode}: ${result.Message}`);
110
+ });
111
+ }
112
+ async runSafely(label, work) {
113
+ try {
114
+ await work();
115
+ }
116
+ catch (e) {
117
+ LogError(`MJListEntityServer: ${label} failed for list '${this.Name}' (${this.ID}): ${e instanceof Error ? e.message : String(e)}`);
118
+ }
119
+ }
120
+ routine() {
121
+ return new ListRefreshRoutine(this.ProviderToUse, this.ContextCurrentUser);
122
+ }
123
+ anyFieldDirty(fields) {
124
+ return fields.some((f) => this.GetFieldByName(f)?.Dirty ?? false);
125
+ }
126
+ refusalResult(type, message) {
127
+ const result = new BaseEntityResult();
128
+ result.StartedAt = new Date();
129
+ result.Success = false;
130
+ result.Type = type;
131
+ result.Message = message;
132
+ result.EndedAt = new Date();
133
+ return result;
36
134
  }
37
135
  };
38
136
  MJListEntityServer = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"MJListEntityServer.server.js","sourceRoot":"","sources":["../../src/custom/MJListEntityServer.server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAuB,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE;;;;;;;;;;;GAWG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,oBAAoB;IACxC,KAAK,CAAC,MAAM,CAAC,OAA6B;QACtD,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC5E,MAAM,MAAM,GAAG,IAAI,gBAAgB,E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+ import { MJMLEvaluationProtocolEntity } from '@memberjunction/core-entities';
3
+ import { type Actor, type EvaluationProtocolColumns } from '@memberjunction/predictive-studio-core';
4
+ import { type RowRead } from './MJMLPredictionUnitEntityServer.server.js';
5
+ /**
6
+ * `MJ: ML Evaluation Protocols`: immutable versions plus the protocol's own shape checks. On insert, the protocol rules
7
+ * that do not need a Prediction Unit are checked against the previous version of the lineage: a dummy baseline is
8
+ * declared, and the guard fields change only when the author may change them under the previous version's
9
+ * `GuardFieldsEditableBy` (never an agent tool call; under `human-only`, only a user). A version authored by a user
10
+ * names the user who saves it: the guard-field rule trusts `AuthoredBy`, so a version may not claim another user (or
11
+ * a user when no user saves it). "The user who saves it" is the user the save is attributed to, `ActiveUser` (see
12
+ * {@link VersionedRowGuard}), which also reads the previous version. The rules that need a unit run where a pipeline
13
+ * binds a unit and a protocol.
14
+ */
15
+ export declare class MJMLEvaluationProtocolEntityServer extends MJMLEvaluationProtocolEntity {
16
+ /** A version-1 row is its own lineage root; the server assigns it on create. A `ReplayOnly` save of a saved row is refused. */
17
+ Save(options?: EntitySaveOptions): Promise<boolean>;
18
+ Validate(): ValidationResult;
19
+ /** False: the rules that read the previous version run in {@link ValidateAsync} on every save. */
20
+ get DefaultSkipAsyncValidation(): boolean;
21
+ /**
22
+ * The protocol rules that need the previous version, on insert only (a saved version is never updated, so there is
23
+ * nothing to re-check on an update; the synchronous guard refuses it).
24
+ */
25
+ ValidateAsync(): Promise<ValidationResult>;
26
+ /**
27
+ * Why a version's author cannot be accepted: it names a user other than the one saving it (or names a user when no
28
+ * user saves it). Null for any other author, and for the saving user. Pure.
29
+ *
30
+ * @param author the version's `AuthoredBy`
31
+ * @param savingUserId the ID of the user saving the version, or null when none is known
32
+ */
33
+ static GetHumanAuthorProblem(author: Actor, savingUserId: string | null): string | null;
34
+ /** The column a protocol refusal is reported on. */
35
+ private static refusalField;
36
+ /** One version of this row's lineage as a plain row (nothing is mutated), read as the saving user, or the read error. */
37
+ protected LoadVersion(provider: IMetadataProvider, version: number): Promise<RowRead<EvaluationProtocolColumns>>;
38
+ }
39
+ //# sourceMappingURL=MJMLEvaluationProtocolEntityServer.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MJMLEvaluationProtocolEntityServer.server.d.ts","sourceRoot":"","sources":["../../src/custom/MJMLEvaluationProtocolEntityServer.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEpI,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAA+C,KAAK,KAAK,EAAE,KAAK,yBAAyB,EAAqD,MAAM,wCAAwC,CAAC;AACpM,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,yCAAyC,CAAC;AAE1F;;;;;;;;;GASG;AACH,qBACa,kCAAmC,SAAQ,4BAA4B;IAClF,+HAA+H;IACzG,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzD,QAAQ,IAAI,gBAAgB;IAI5C,kGAAkG;IAClG,IAAoB,0BAA0B,IAAI,OAAO,CAExD;IAED;;;OAGG;IACmB,aAAa,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA8BhE;;;;;;OAMG;WACW,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI;IAK9F,oDAAoD;IACpD,OAAO,CAAC,MAAM,CAAC,YAAY;IAgC3B,yHAAyH;cACzG,WAAW,CAAC,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAGvH"}
@@ -0,0 +1,124 @@
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
+ var MJMLEvaluationProtocolEntityServer_1;
8
+ import { BaseEntity, LogStatus } from '@memberjunction/core';
9
+ import { RegisterClass, UUIDsEqual } from '@memberjunction/global';
10
+ import { MJMLEvaluationProtocolEntity } from '@memberjunction/core-entities';
11
+ import { EvaluationProtocol, EvaluationProtocolRules } from '@memberjunction/predictive-studio-core';
12
+ import { VersionedRowGuard } from './MJMLPredictionUnitEntityServer.server.js';
13
+ /**
14
+ * `MJ: ML Evaluation Protocols`: immutable versions plus the protocol's own shape checks. On insert, the protocol rules
15
+ * that do not need a Prediction Unit are checked against the previous version of the lineage: a dummy baseline is
16
+ * declared, and the guard fields change only when the author may change them under the previous version's
17
+ * `GuardFieldsEditableBy` (never an agent tool call; under `human-only`, only a user). A version authored by a user
18
+ * names the user who saves it: the guard-field rule trusts `AuthoredBy`, so a version may not claim another user (or
19
+ * a user when no user saves it). "The user who saves it" is the user the save is attributed to, `ActiveUser` (see
20
+ * {@link VersionedRowGuard}), which also reads the previous version. The rules that need a unit run where a pipeline
21
+ * binds a unit and a protocol.
22
+ */
23
+ let MJMLEvaluationProtocolEntityServer = MJMLEvaluationProtocolEntityServer_1 = class MJMLEvaluationProtocolEntityServer extends MJMLEvaluationProtocolEntity {
24
+ /** A version-1 row is its own lineage root; the server assigns it on create. A `ReplayOnly` save of a saved row is refused. */
25
+ async Save(options) {
26
+ VersionedRowGuard.AdoptOwnLineageRoot(this);
27
+ return VersionedRowGuard.SaveRefusingSavedRowReplay(this, options, () => super.Save(options));
28
+ }
29
+ Validate() {
30
+ return VersionedRowGuard.AddProblems(this, super.Validate(), 'Version', 'Version', () => EvaluationProtocol.GetEvaluationProtocolShapeProblems(this));
31
+ }
32
+ /** False: the rules that read the previous version run in {@link ValidateAsync} on every save. */
33
+ get DefaultSkipAsyncValidation() {
34
+ return false;
35
+ }
36
+ /**
37
+ * The protocol rules that need the previous version, on insert only (a saved version is never updated, so there is
38
+ * nothing to re-check on an update; the synchronous guard refuses it).
39
+ */
40
+ async ValidateAsync() {
41
+ const result = await super.ValidateAsync();
42
+ if (!result.Success || this.IsSaved)
43
+ return result;
44
+ const provider = this.ProviderToUse;
45
+ if (!VersionedRowGuard.IsMetadataProvider(provider)) {
46
+ LogStatus(`MJMLEvaluationProtocolEntityServer: the provider is not a metadata provider, so the protocol rules were skipped for "${this.Name}" v${this.Version}`);
47
+ return result;
48
+ }
49
+ const parsed = EvaluationProtocol.ParseEvaluationProtocolRow(this);
50
+ if (parsed.Ok === false) {
51
+ VersionedRowGuard.Fail(result, 'Version', `Evaluation Protocol does not parse: ${parsed.Errors.join('; ')}`);
52
+ return result;
53
+ }
54
+ const impersonation = MJMLEvaluationProtocolEntityServer_1.GetHumanAuthorProblem(parsed.Value.authoredBy, this.ActiveUser?.ID || null);
55
+ if (impersonation !== null) {
56
+ VersionedRowGuard.Fail(result, 'AuthoredBy', impersonation);
57
+ return result;
58
+ }
59
+ const previous = await VersionedRowGuard.PreviousVersion(result, {
60
+ Label: 'Evaluation Protocol', LineageRootID: this.LineageRootID, Version: this.Version,
61
+ Load: (version) => this.LoadVersion(provider, version),
62
+ Parse: (row) => EvaluationProtocol.ParseEvaluationProtocolRow(row),
63
+ });
64
+ if (previous === undefined)
65
+ return result;
66
+ for (const r of EvaluationProtocolRules.ValidateEvaluationProtocol({ Protocol: parsed.Value, Previous: previous === null ? null : previous.Spec, AuthoredBy: parsed.Value.authoredBy })) {
67
+ VersionedRowGuard.Fail(result, MJMLEvaluationProtocolEntityServer_1.refusalField(r), EvaluationProtocolRules.DescribeProtocolRefusal(r));
68
+ }
69
+ return result;
70
+ }
71
+ /**
72
+ * Why a version's author cannot be accepted: it names a user other than the one saving it (or names a user when no
73
+ * user saves it). Null for any other author, and for the saving user. Pure.
74
+ *
75
+ * @param author the version's `AuthoredBy`
76
+ * @param savingUserId the ID of the user saving the version, or null when none is known
77
+ */
78
+ static GetHumanAuthorProblem(author, savingUserId) {
79
+ if (author.kind !== 'human' || (savingUserId !== null && UUIDsEqual(author.userId, savingUserId)))
80
+ return null;
81
+ return `AuthoredBy names the user ${author.userId}, but the version is saved by ${savingUserId === null ? 'no user' : 'another user'}; a version is authored by a user only when that user saves it.`;
82
+ }
83
+ /** The column a protocol refusal is reported on. */
84
+ static refusalField(r) {
85
+ switch (r.Kind) {
86
+ case 'holdout-kind-mismatch':
87
+ case 'horizon-mismatch':
88
+ case 'lag-inside-horizon':
89
+ case 'rolling-window-inside-horizon':
90
+ case 'new-entity-group-key-mismatch':
91
+ case 'forecast-multiple-series':
92
+ return 'Holdout';
93
+ case 'inner-gap-below-horizon':
94
+ case 'group-key-mismatch':
95
+ case 'inner-validation-ungrouped':
96
+ return 'InnerValidation';
97
+ case 'primary-score-family-mismatch':
98
+ return 'PrimaryScore';
99
+ case 'calibration-not-applicable-for-probability-task':
100
+ return 'Calibration';
101
+ case 'no-dummy-baseline':
102
+ case 'forecast-no-seasonal-naive':
103
+ return 'Baselines';
104
+ case 'forecast-prediction-intervals':
105
+ return 'PredictionIntervals';
106
+ case 'forecast-slices':
107
+ return 'Slices';
108
+ case 'forecast-interval-method':
109
+ case 'intervals-not-clustered':
110
+ return 'Intervals';
111
+ case 'guard-field-edited-by-disallowed-author':
112
+ return 'AuthoredBy';
113
+ }
114
+ }
115
+ /** One version of this row's lineage as a plain row (nothing is mutated), read as the saving user, or the read error. */
116
+ async LoadVersion(provider, version) {
117
+ return VersionedRowGuard.LoadVersion(provider, 'MJ: ML Evaluation Protocols', this.LineageRootID, version, this.ActiveUser);
118
+ }
119
+ };
120
+ MJMLEvaluationProtocolEntityServer = MJMLEvaluationProtocolEntityServer_1 = __decorate([
121
+ RegisterClass(BaseEntity, 'MJ: ML Evaluation Protocols')
122
+ ], MJMLEvaluationProtocolEntityServer);
123
+ export { MJMLEvaluationProtocolEntityServer };
124
+ //# sourceMappingURL=MJMLEvaluationProtocolEntityServer.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MJMLEvaluationProtocolEntityServer.server.js","sourceRoot":"","sources":["../../src/custom/MJMLEvaluationProtocolEntityServer.server.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAyE,MAAM,sBAAsB,CAAC;AACpI,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAiG,MAAM,wCAAwC,CAAC;AACpM,OAAO,EAAE,iBAAiB,EAAgB,MAAM,yCAAyC,CAAC;AAE1F;;;;;;;;;GASG;AAEI,IAAM,kCAAkC,0CAAxC,MAAM,kCAAmC,SAAQ,4BAA4B;IAClF,+HAA+H;IAC/G,KAAK,CAAC,IAAI,CAAC,OAA2B;QACpD,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,iBAAiB,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAChG,CAAC;IAEe,QAAQ;QACtB,OAAO,iBAAiB,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,kCAAkC,CAAC,IAAI,CAAC,CAAC,CAAC;IACxJ,CAAC;IAED,kGAAkG;IAClG,IAAoB,0BAA0B;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACa,KAAK,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B,CAAC;YACrC,KAAK,0BAA0B;gBAC7B,OAAO,SAAS,CAAC;YACnB,KAAK,yBAAyB,CAAC;YAC/B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,4BAA4B;gBAC/B,OAAO,iBAAiB,CAAC;YAC3B,KAAK,+BAA+B;gBAClC,OAAO,cAAc,CAAC;YACxB,KAAK,iDAAiD;gBACpD,OAAO,aAAa,CAAC;YACvB,KAAK,mBAAmB,CAAC;YACzB,KAAK,4BAA4B;gBAC/B,OAAO,WAAW,CAAC;YACrB,KAAK,+BAA+B;gBAClC,OAAO,qBAAqB,CAAC;YAC/B,KAAK,iBAAiB;gBACpB,OAAO,QAAQ,CAAC;YAClB,KAAK,0BAA0B,CAAC;YAChC,KAAK,yBAAyB;gBAC5B,OAAO,WAAW,CAAC;YACrB,KAAK,yCAAyC;gBAC5C,OAAO,YAAY,CAAC;QACxB,CAAC;IACH,CAAC;IAED,yHAAyH;IAC/G,KAAK,CAAC,WAAW,CAAC,QAA2B,EAAE,OAAe;QACtE,OAAO,iBAAiB,CAAC,WAAW,CAA4B,QAAQ,EAAE,6BAA6B,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACzJ,CAAC;CACF,CAAA;AAnGY,kCAAkC;IAD9C,aAAa,CAAC,UAAU,EAAE,6BAA6B,CAAC;GAC5C,kCAAkC,CAmG9C"}
@@ -0,0 +1,124 @@
1
+ import { BaseEntity, type EntitySaveOptions, type IEntityDataProvider, type IMetadataProvider, type UserInfo, type ValidationResult } from '@memberjunction/core';
2
+ import { MJMLPredictionUnitEntity } from '@memberjunction/core-entities';
3
+ import { type ParseResult } from '@memberjunction/predictive-studio-core';
4
+ /** One row read as a plain object: the row (null when absent), or why the read failed. */
5
+ export interface RowRead<TRow> {
6
+ /** The row's columns; null when it is absent or the read failed. */
7
+ readonly Row: TRow | null;
8
+ /** Why the read failed; null when it succeeded. */
9
+ readonly Error: string | null;
10
+ }
11
+ /** What {@link VersionedRowGuard.PreviousVersion} reads: the lineage, the version being saved, and how to load and parse a version. */
12
+ export interface PreviousVersionArgs<TRow extends {
13
+ readonly ID: string;
14
+ }, TSpec> {
15
+ /** The entity's display name in messages (`Prediction Unit`, `Evaluation Protocol`). */
16
+ readonly Label: string;
17
+ /** The lineage whose version n−1 is read. */
18
+ readonly LineageRootID: string;
19
+ /** The version being saved; its predecessor is read. */
20
+ readonly Version: number;
21
+ /** Reads one version of the lineage as a plain row. */
22
+ readonly Load: (version: number) => Promise<RowRead<TRow>>;
23
+ /** Parses a row into its spec. */
24
+ readonly Parse: (row: TRow) => ParseResult<TSpec>;
25
+ }
26
+ /**
27
+ * The immutable-version guard shared by the unit, protocol and snapshot subclasses: one implementation of
28
+ * "a saved version is never updated", so the three entities cannot drift apart. It holds on both write paths: an
29
+ * ordinary save is refused in `Validate()` ({@link AddProblems}), and a `ReplayOnly` save, which skips `Validate()`,
30
+ * in `Save()` ({@link SaveRefusingSavedRowReplay}). A delete is not refused: the integration rigs and the plan's probes
31
+ * delete the rows they create, and the foreign keys keep a version that anything references.
32
+ *
33
+ * **Which user.** The unit, protocol and pipeline subclasses judge authorship and read other rows as `ActiveUser`: the
34
+ * user the save is attributed to (`ContextCurrentUser`, else the provider's `CurrentUser`), which `BaseEntity.Save()`
35
+ * checks permissions for and hands the provider's write. The coding standard's "use `BaseEntity.ContextCurrentUser`
36
+ * rather than tracking the current user" is about not keeping a user of one's own; `ActiveUser` is that same
37
+ * BaseEntity resolution, finished. `ContextCurrentUser` alone is only an explicitly set user: an entity created without
38
+ * one is written as the provider's user, and reading `ContextCurrentUser` would judge, and read as, no user instead.
39
+ */
40
+ export declare class VersionedRowGuard {
41
+ /**
42
+ * The refusal for a write to a saved row; null for a new row or a saved row with no change. A row of a versioned
43
+ * lineage (it has a `LineageRootID`) is told to save the next version; a row with no lineage (a Training Snapshot) to
44
+ * write a new row. Pure.
45
+ */
46
+ static GetVersionedRowUpdateProblem(entityName: string, isSaved: boolean, dirtyFields: readonly string[], hasLineage: boolean): string | null;
47
+ /** The refusal for a `ReplayOnly` save of a saved row of `entityName`. Pure. */
48
+ static GetReplayOnlyUpdateProblem(entityName: string): string;
49
+ /**
50
+ * Runs `save` (the subclass's base save) unless this is a `ReplayOnly` save of a saved row, which is refused with
51
+ * {@link GetReplayOnlyUpdateProblem} recorded on the result history (so `LatestResult.CompleteMessage` carries it).
52
+ * `ReplayOnly` skips `Validate()` but still writes, and it writes even when no field is dirty (values loaded with
53
+ * `LoadFromData` are not dirty), so the option itself is refused on a saved row rather than its dirty fields judged.
54
+ * A `ReplayOnly` insert goes through, as it does for every entity.
55
+ */
56
+ static SaveRefusingSavedRowReplay(entity: BaseEntity, options: EntitySaveOptions | undefined, save: () => Promise<boolean>): Promise<boolean>;
57
+ /**
58
+ * A version-1 row is its own lineage root: on create the server assigns `LineageRootID = ID`, because a client
59
+ * cannot choose the ID it will be given. Any other row is left as it is.
60
+ */
61
+ static AdoptOwnLineageRoot(row: {
62
+ readonly IsSaved: boolean;
63
+ readonly Version: number;
64
+ readonly ID: string;
65
+ LineageRootID: string;
66
+ }): void;
67
+ /**
68
+ * Every MJ data provider is also a metadata provider; a test double may not be. Narrows without a cast so the
69
+ * Predictive Studio server subclasses can use metadata lookups only when the provider supports them.
70
+ */
71
+ static IsMetadataProvider(p: IEntityDataProvider | null | undefined): p is IEntityDataProvider & IMetadataProvider;
72
+ /** Records a failure on `field` and marks the result failed. */
73
+ static Fail(result: ValidationResult, field: string, message: string): void;
74
+ /**
75
+ * The first row of `entityName` matching `filter`, as a plain row (nothing is mutated). A failed read is returned as
76
+ * its error, so it is never reported as an absent row.
77
+ */
78
+ static ReadOneRow<TRow>(provider: IMetadataProvider, entityName: string, filter: string, user: UserInfo | undefined): Promise<RowRead<TRow>>;
79
+ /** Version `version` of a lineage, read with {@link ReadOneRow}. */
80
+ static LoadVersion<TRow>(provider: IMetadataProvider, entityName: string, lineageRootID: string, version: number, user: UserInfo | undefined): Promise<RowRead<TRow>>;
81
+ /**
82
+ * Version `n - 1` of a lineage with its parsed form: null for version 1; undefined when it could not be read, is
83
+ * absent (versions are consecutive) or does not parse, each recorded on `result` against `Version`.
84
+ */
85
+ static PreviousVersion<TRow extends {
86
+ readonly ID: string;
87
+ }, TSpec>(result: ValidationResult, a: PreviousVersionArgs<TRow, TSpec>): Promise<{
88
+ readonly Row: TRow;
89
+ readonly Spec: TSpec;
90
+ } | null | undefined>;
91
+ /**
92
+ * Adds the update refusal (on `updateField`) or, for a new row, the row's own problems (on `rowField`) to `result`.
93
+ * `rowProblems` runs only when the write is not an update of a saved version.
94
+ */
95
+ static AddProblems(entity: BaseEntity, result: ValidationResult, updateField: string, rowField: string, rowProblems: () => readonly string[]): ValidationResult;
96
+ }
97
+ /**
98
+ * `MJ: ML Prediction Units`: a version row is written once and never updated, and must parse. On insert, every entity
99
+ * and field the unit names must exist, versions of a lineage must be consecutive, and LabelVersion must move exactly
100
+ * when the outcome definition changed from the previous version.
101
+ */
102
+ export declare class MJMLPredictionUnitEntityServer extends MJMLPredictionUnitEntity {
103
+ /** Shape problems of a unit row (all JSON columns parse; cross-field rules hold). Pure. */
104
+ static GetPredictionUnitRowProblems(row: MJMLPredictionUnitEntity): readonly string[];
105
+ /** The LabelVersion a new version must carry: the previous one, plus one when the outcome definition changed. Pure. */
106
+ static ExpectedLabelVersion(previous: number, changed: boolean): number;
107
+ /** A version-1 row is its own lineage root; the server assigns it on create. A `ReplayOnly` save of a saved row is refused. */
108
+ Save(options?: EntitySaveOptions): Promise<boolean>;
109
+ Validate(): ValidationResult;
110
+ get DefaultSkipAsyncValidation(): boolean;
111
+ /**
112
+ * The checks that need metadata or other rows, on insert only (a saved version is never updated, so there is
113
+ * nothing to re-check on an update; the synchronous guard refuses it).
114
+ */
115
+ ValidateAsync(): Promise<ValidationResult>;
116
+ /** Every entity the unit names must be registered, and every field it names must exist on that entity. */
117
+ private checkReferencedFields;
118
+ /**
119
+ * Version `n` follows version `n - 1` of the same lineage, and its LabelVersion is the previous one plus one exactly
120
+ * when the outcome definition (rule, window, gap, task) changed. Nothing to check for version 1.
121
+ */
122
+ private checkLabelVersion;
123
+ }
124
+ //# sourceMappingURL=MJMLPredictionUnitEntityServer.server.d.ts.map