@memberjunction/core 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.
- package/dist/generic/JSONType-interfaces/IEntityConfiguration.d.ts +94 -0
- package/dist/generic/JSONType-interfaces/IEntityConfiguration.d.ts.map +1 -1
- package/dist/generic/JSONType-interfaces/IEntitySubtypeSelectorConfig.d.ts +77 -4
- package/dist/generic/JSONType-interfaces/IEntitySubtypeSelectorConfig.d.ts.map +1 -1
- package/dist/generic/appCapabilityRegistry.d.ts +106 -0
- package/dist/generic/appCapabilityRegistry.d.ts.map +1 -0
- package/dist/generic/appCapabilityRegistry.js +212 -0
- package/dist/generic/appCapabilityRegistry.js.map +1 -0
- package/dist/generic/baseEngine.d.ts +108 -3
- package/dist/generic/baseEngine.d.ts.map +1 -1
- package/dist/generic/baseEngine.js +891 -122
- package/dist/generic/baseEngine.js.map +1 -1
- package/dist/generic/baseEngineRegistry.d.ts +8 -0
- package/dist/generic/baseEngineRegistry.d.ts.map +1 -1
- package/dist/generic/baseEngineRegistry.js +36 -11
- package/dist/generic/baseEngineRegistry.js.map +1 -1
- package/dist/generic/baseEntity.d.ts +155 -3
- package/dist/generic/baseEntity.d.ts.map +1 -1
- package/dist/generic/baseEntity.js +1146 -74
- package/dist/generic/baseEntity.js.map +1 -1
- package/dist/generic/baseRemotableOperation.d.ts +32 -0
- package/dist/generic/baseRemotableOperation.d.ts.map +1 -1
- package/dist/generic/baseRemotableOperation.js +29 -0
- package/dist/generic/baseRemotableOperation.js.map +1 -1
- package/dist/generic/compositeKey.d.ts.map +1 -1
- package/dist/generic/compositeKey.js +3 -1
- package/dist/generic/compositeKey.js.map +1 -1
- package/dist/generic/constraintErrorRedaction.d.ts +26 -0
- package/dist/generic/constraintErrorRedaction.d.ts.map +1 -0
- package/dist/generic/constraintErrorRedaction.js +166 -0
- package/dist/generic/constraintErrorRedaction.js.map +1 -0
- package/dist/generic/crossEntityPolicyEngine.d.ts +172 -0
- package/dist/generic/crossEntityPolicyEngine.d.ts.map +1 -0
- package/dist/generic/crossEntityPolicyEngine.js +667 -0
- package/dist/generic/crossEntityPolicyEngine.js.map +1 -0
- package/dist/generic/dataHooks.d.ts +41 -4
- package/dist/generic/dataHooks.d.ts.map +1 -1
- package/dist/generic/dataHooks.js +82 -0
- package/dist/generic/dataHooks.js.map +1 -1
- package/dist/generic/databaseProviderBase.d.ts +96 -1
- package/dist/generic/databaseProviderBase.d.ts.map +1 -1
- package/dist/generic/databaseProviderBase.js +414 -44
- package/dist/generic/databaseProviderBase.js.map +1 -1
- package/dist/generic/documentNumberingEngine.d.ts +190 -0
- package/dist/generic/documentNumberingEngine.d.ts.map +1 -0
- package/dist/generic/documentNumberingEngine.js +739 -0
- package/dist/generic/documentNumberingEngine.js.map +1 -0
- package/dist/generic/entityInfo.d.ts +152 -8
- package/dist/generic/entityInfo.d.ts.map +1 -1
- package/dist/generic/entityInfo.js +507 -71
- package/dist/generic/entityInfo.js.map +1 -1
- package/dist/generic/entityLifecyclePolicy.d.ts +214 -0
- package/dist/generic/entityLifecyclePolicy.d.ts.map +1 -0
- package/dist/generic/entityLifecyclePolicy.js +708 -0
- package/dist/generic/entityLifecyclePolicy.js.map +1 -0
- package/dist/generic/entitySavePlan.d.ts +6 -0
- package/dist/generic/entitySavePlan.d.ts.map +1 -1
- package/dist/generic/entitySavePlan.js +145 -1
- package/dist/generic/entitySavePlan.js.map +1 -1
- package/dist/generic/entitySubtypeDriver.d.ts +49 -0
- package/dist/generic/entitySubtypeDriver.d.ts.map +1 -0
- package/dist/generic/entitySubtypeDriver.js +26 -0
- package/dist/generic/entitySubtypeDriver.js.map +1 -0
- package/dist/generic/fieldSecuritySQLGate.d.ts +17 -0
- package/dist/generic/fieldSecuritySQLGate.d.ts.map +1 -1
- package/dist/generic/fieldSecuritySQLGate.js +41 -1
- package/dist/generic/fieldSecuritySQLGate.js.map +1 -1
- package/dist/generic/filters/compositeFilter.d.ts +5 -1
- package/dist/generic/filters/compositeFilter.d.ts.map +1 -1
- package/dist/generic/filters/compositeFilter.js +127 -12
- package/dist/generic/filters/compositeFilter.js.map +1 -1
- package/dist/generic/filters/compositeFilterSQL.d.ts +121 -0
- package/dist/generic/filters/compositeFilterSQL.d.ts.map +1 -0
- package/dist/generic/filters/compositeFilterSQL.js +489 -0
- package/dist/generic/filters/compositeFilterSQL.js.map +1 -0
- package/dist/generic/filters/filter.types.d.ts +5 -2
- package/dist/generic/filters/filter.types.d.ts.map +1 -1
- package/dist/generic/filters/filter.types.js +4 -1
- package/dist/generic/filters/filter.types.js.map +1 -1
- package/dist/generic/filters/filterBuilder.d.ts +75 -0
- package/dist/generic/filters/filterBuilder.d.ts.map +1 -0
- package/dist/generic/filters/filterBuilder.js +104 -0
- package/dist/generic/filters/filterBuilder.js.map +1 -0
- package/dist/generic/filters/index.d.ts +2 -0
- package/dist/generic/filters/index.d.ts.map +1 -1
- package/dist/generic/filters/index.js +2 -0
- package/dist/generic/filters/index.js.map +1 -1
- package/dist/generic/interfaces.d.ts +125 -19
- package/dist/generic/interfaces.d.ts.map +1 -1
- package/dist/generic/interfaces.js +9 -10
- package/dist/generic/interfaces.js.map +1 -1
- package/dist/generic/localCacheManager.d.ts +54 -14
- package/dist/generic/localCacheManager.d.ts.map +1 -1
- package/dist/generic/localCacheManager.js +450 -106
- package/dist/generic/localCacheManager.js.map +1 -1
- package/dist/generic/metadata.d.ts +7 -5
- package/dist/generic/metadata.d.ts.map +1 -1
- package/dist/generic/metadata.js +29 -10
- package/dist/generic/metadata.js.map +1 -1
- package/dist/generic/providerBase.d.ts +405 -45
- package/dist/generic/providerBase.d.ts.map +1 -1
- package/dist/generic/providerBase.js +1107 -200
- package/dist/generic/providerBase.js.map +1 -1
- package/dist/generic/queryInfo.d.ts +5 -0
- package/dist/generic/queryInfo.d.ts.map +1 -1
- package/dist/generic/queryInfo.js +5 -0
- package/dist/generic/queryInfo.js.map +1 -1
- package/dist/generic/queryInfoInterfaces.d.ts +5 -0
- package/dist/generic/queryInfoInterfaces.d.ts.map +1 -1
- package/dist/generic/queryResultEnricher.d.ts +4 -1
- package/dist/generic/queryResultEnricher.d.ts.map +1 -1
- package/dist/generic/queryResultEnricher.js.map +1 -1
- package/dist/generic/queryTemplateContext.d.ts.map +1 -1
- package/dist/generic/queryTemplateContext.js +38 -3
- package/dist/generic/queryTemplateContext.js.map +1 -1
- package/dist/generic/relatedRecordCollection.d.ts +20 -0
- package/dist/generic/relatedRecordCollection.d.ts.map +1 -1
- package/dist/generic/relatedRecordCollection.js +257 -22
- package/dist/generic/relatedRecordCollection.js.map +1 -1
- package/dist/generic/remoteOperationDispatch.d.ts.map +1 -1
- package/dist/generic/remoteOperationDispatch.js +13 -1
- package/dist/generic/remoteOperationDispatch.js.map +1 -1
- package/dist/generic/saveEntityGraphOperation.d.ts +6 -0
- package/dist/generic/saveEntityGraphOperation.d.ts.map +1 -1
- package/dist/generic/saveEntityGraphOperation.js +8 -0
- package/dist/generic/saveEntityGraphOperation.js.map +1 -1
- package/dist/generic/securityInfo.d.ts +49 -2
- package/dist/generic/securityInfo.d.ts.map +1 -1
- package/dist/generic/securityInfo.js +139 -12
- package/dist/generic/securityInfo.js.map +1 -1
- package/dist/generic/telemetryManager.d.ts +40 -4
- package/dist/generic/telemetryManager.d.ts.map +1 -1
- package/dist/generic/telemetryManager.js +68 -15
- package/dist/generic/telemetryManager.js.map +1 -1
- package/dist/generic/transactionGroup.d.ts +66 -23
- package/dist/generic/transactionGroup.d.ts.map +1 -1
- package/dist/generic/transactionGroup.js +225 -57
- package/dist/generic/transactionGroup.js.map +1 -1
- package/dist/generic/util.d.ts.map +1 -1
- package/dist/generic/util.js +9 -3
- package/dist/generic/util.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/views/runView.d.ts +61 -0
- package/dist/views/runView.d.ts.map +1 -1
- package/dist/views/runView.js +154 -3
- package/dist/views/runView.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +6 -5
|
@@ -6,6 +6,9 @@ import { IsFixedWidthStringSQLType } from "@memberjunction/sql-dialect";
|
|
|
6
6
|
import { LogError } from "./logging.js";
|
|
7
7
|
import { WarningManager, SafeJSONParse, UUIDsEqual, NormalizeUUID, ordinalCompare, GeneratePluralName } from "@memberjunction/global";
|
|
8
8
|
import { ReadRelationshipJoinFields, } from "./entityConfiguration.js";
|
|
9
|
+
import { EntityLifecyclePolicyEngine } from "./entityLifecyclePolicy.js";
|
|
10
|
+
import { DocumentNumberingEngine } from "./documentNumberingEngine.js";
|
|
11
|
+
import { CrossEntityPolicyEngine } from "./crossEntityPolicyEngine.js";
|
|
9
12
|
/**
|
|
10
13
|
* Runtime domain for {@link EntityFieldInfo.ExtendedType}. This array is the single source of
|
|
11
14
|
* truth; {@link EntityFieldExtendedType} is derived from it. CodeGen validates LLM suggestions
|
|
@@ -306,6 +309,46 @@ export class EntityOrganicKeyRelatedEntityInfo extends BaseInfo {
|
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* A unique index or unique constraint on an entity's base table, as a set of columns. CodeGen
|
|
314
|
+
* keeps these in step with the database catalog; primary keys are not included (see
|
|
315
|
+
* {@link EntityFieldInfo.IsPrimaryKey}).
|
|
316
|
+
*
|
|
317
|
+
* {@link EntityFieldInfo.IsUnique} is true only for a column that is a key on its own. A composite
|
|
318
|
+
* key — for example Action Params' (ActionID, Name) — appears here and not on its columns.
|
|
319
|
+
* Maps to the MJ: Entity Unique Keys metadata entity.
|
|
320
|
+
*/
|
|
321
|
+
export class EntityUniqueKeyInfo extends BaseInfo {
|
|
322
|
+
/** The key's field names, in key order. */
|
|
323
|
+
get FieldNamesArray() {
|
|
324
|
+
return this.FieldNames ? this.FieldNames.split(',').map(f => f.trim()).filter(f => f.length > 0) : [];
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* True when the key only applies to rows matching {@link FilterDefinition}. Such a key does not
|
|
328
|
+
* make its columns unique across the whole table.
|
|
329
|
+
*/
|
|
330
|
+
get IsFiltered() {
|
|
331
|
+
return this.FilterDefinition != null && this.FilterDefinition.trim().length > 0;
|
|
332
|
+
}
|
|
333
|
+
constructor(initData = null) {
|
|
334
|
+
super();
|
|
335
|
+
this.ID = null;
|
|
336
|
+
this.EntityID = null;
|
|
337
|
+
/** Name of the unique index or constraint in the database. */
|
|
338
|
+
this.Name = null;
|
|
339
|
+
/** Comma-separated key column names, in key order. Use {@link FieldNamesArray}. */
|
|
340
|
+
this.FieldNames = null;
|
|
341
|
+
/** Predicate of a filtered (SQL Server) or partial (PostgreSQL) index; null when the key covers every row. */
|
|
342
|
+
this.FilterDefinition = null;
|
|
343
|
+
this.__mj_CreatedAt = null;
|
|
344
|
+
this.__mj_UpdatedAt = null;
|
|
345
|
+
// virtual fields from the database view
|
|
346
|
+
this.Entity = null;
|
|
347
|
+
if (initData) {
|
|
348
|
+
this.copyInitData(initData);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
309
352
|
/**
|
|
310
353
|
* Metadata describing a governed alternate SQL view on an entity that maintains 100% column
|
|
311
354
|
* parity with the entity's canonical `BaseView` while applying a curated canonical filter
|
|
@@ -519,7 +562,22 @@ export class EntityPermissionInfo extends BaseInfo {
|
|
|
519
562
|
* look at a Deny row: `GetUserPermisions` subtracts these, and the RLS readers skip them.
|
|
520
563
|
*/
|
|
521
564
|
get IsDeny() {
|
|
522
|
-
|
|
565
|
+
if (this._isDenySource !== this.Type) {
|
|
566
|
+
this._isDenySource = this.Type;
|
|
567
|
+
this._isDenyCache = (this.Type || 'Allow').trim().toLowerCase() === 'deny';
|
|
568
|
+
}
|
|
569
|
+
return this._isDenyCache;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Trimmed, lowercased `RoleID` cached against the current `RoleID` value so hot permission
|
|
573
|
+
* and RLS checks avoid per-call string allocations.
|
|
574
|
+
*/
|
|
575
|
+
get NormalizedRoleID() {
|
|
576
|
+
if (this._normalizedRoleIdSource !== this.RoleID) {
|
|
577
|
+
this._normalizedRoleIdSource = this.RoleID;
|
|
578
|
+
this._normalizedRoleIdCache = this.RoleID ? this.RoleID.trim().toLowerCase() : null;
|
|
579
|
+
}
|
|
580
|
+
return this._normalizedRoleIdCache;
|
|
523
581
|
}
|
|
524
582
|
get CreateRLSFilterObject() {
|
|
525
583
|
return this.RLSFilter(EntityPermissionType.Create);
|
|
@@ -568,6 +626,10 @@ export class EntityPermissionInfo extends BaseInfo {
|
|
|
568
626
|
* materialized before the column existed.
|
|
569
627
|
*/
|
|
570
628
|
this.Type = 'Allow';
|
|
629
|
+
this._isDenyCache = false;
|
|
630
|
+
this._isDenySource = undefined;
|
|
631
|
+
this._normalizedRoleIdCache = null;
|
|
632
|
+
this._normalizedRoleIdSource = undefined;
|
|
571
633
|
this.CanCreate = null;
|
|
572
634
|
this.CanRead = null;
|
|
573
635
|
this.CanUpdate = null;
|
|
@@ -1896,7 +1958,10 @@ export class EntityFieldInfo extends BaseInfo {
|
|
|
1896
1958
|
*/
|
|
1897
1959
|
this.IsSoftForeignKey = null;
|
|
1898
1960
|
/**
|
|
1899
|
-
*
|
|
1961
|
+
* True only when this column alone is a key: the sole key column of an unfiltered unique index or
|
|
1962
|
+
* unique constraint, or the sole column of the primary key. Columns of a composite unique key, of a
|
|
1963
|
+
* composite primary key, or of a filtered (partial) unique index are false; unique keys are
|
|
1964
|
+
* recorded as column sets in {@link EntityInfo.UniqueKeySets}.
|
|
1900
1965
|
*/
|
|
1901
1966
|
this.IsUnique = null;
|
|
1902
1967
|
this.Category = null;
|
|
@@ -2203,6 +2268,9 @@ export class EntityFieldInfo extends BaseInfo {
|
|
|
2203
2268
|
this.RelatedEntityBaseView = null;
|
|
2204
2269
|
this.RelatedEntityCodeName = null;
|
|
2205
2270
|
this.RelatedEntityClassName = null;
|
|
2271
|
+
// These are not in the database view and are added in code
|
|
2272
|
+
this.IsFloat = false;
|
|
2273
|
+
this.RelatedEntityTableAlias = null;
|
|
2206
2274
|
this._rawEntityFieldValues = null;
|
|
2207
2275
|
this._entityFieldValuesConstructed = false;
|
|
2208
2276
|
/**
|
|
@@ -2407,21 +2475,29 @@ function getUserRoleIdSet(user) {
|
|
|
2407
2475
|
const roles = user.UserRoles;
|
|
2408
2476
|
const len = roles.length;
|
|
2409
2477
|
const firstId = roles[0]?.RoleID;
|
|
2478
|
+
const lastId = roles[len - 1]?.RoleID;
|
|
2410
2479
|
const cached = _userRoleIdSetCache.get(user);
|
|
2411
|
-
if (cached &&
|
|
2480
|
+
if (cached &&
|
|
2481
|
+
cached.rolesRef === roles &&
|
|
2482
|
+
cached.rolesLen === len &&
|
|
2483
|
+
cached.firstRoleId === firstId &&
|
|
2484
|
+
cached.lastRoleId === lastId) {
|
|
2412
2485
|
return cached.roleIds;
|
|
2413
2486
|
}
|
|
2414
2487
|
const roleIds = new Set();
|
|
2488
|
+
let rolesKey = '';
|
|
2415
2489
|
for (let i = 0; i < len; i++) {
|
|
2416
2490
|
const rid = roles[i]?.RoleID;
|
|
2491
|
+
rolesKey += `${rid ?? ''}|`;
|
|
2417
2492
|
if (rid) {
|
|
2418
2493
|
roleIds.add(rid.trim().toLowerCase());
|
|
2419
2494
|
}
|
|
2420
2495
|
}
|
|
2421
|
-
_userRoleIdSetCache.set(user, { rolesRef: roles, rolesLen: len, firstRoleId: firstId, roleIds });
|
|
2496
|
+
_userRoleIdSetCache.set(user, { rolesRef: roles, rolesLen: len, firstRoleId: firstId, lastRoleId: lastId, rolesKey, roleIds });
|
|
2422
2497
|
return roleIds;
|
|
2423
2498
|
}
|
|
2424
2499
|
const _entityFieldIndexCache = new WeakMap();
|
|
2500
|
+
const _entityUserPermissionsCache = new WeakMap();
|
|
2425
2501
|
const _entityDeniedFieldsCache = new WeakMap();
|
|
2426
2502
|
/**
|
|
2427
2503
|
* The field-security generation: one process-wide number that moves whenever an answer derived
|
|
@@ -2475,11 +2551,19 @@ function userRolesKey(user) {
|
|
|
2475
2551
|
if (!roles || roles.length === 0) {
|
|
2476
2552
|
return '';
|
|
2477
2553
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2554
|
+
const len = roles.length;
|
|
2555
|
+
const firstId = roles[0]?.RoleID;
|
|
2556
|
+
const lastId = roles[len - 1]?.RoleID;
|
|
2557
|
+
const cached = _userRoleIdSetCache.get(user);
|
|
2558
|
+
if (cached &&
|
|
2559
|
+
cached.rolesRef === roles &&
|
|
2560
|
+
cached.rolesLen === len &&
|
|
2561
|
+
cached.firstRoleId === firstId &&
|
|
2562
|
+
cached.lastRoleId === lastId) {
|
|
2563
|
+
return cached.rolesKey;
|
|
2564
|
+
}
|
|
2565
|
+
getUserRoleIdSet(user);
|
|
2566
|
+
return _userRoleIdSetCache.get(user)?.rolesKey ?? '';
|
|
2483
2567
|
}
|
|
2484
2568
|
const _entityChildEntitiesCache = new WeakMap();
|
|
2485
2569
|
/**
|
|
@@ -2568,15 +2652,38 @@ export class EntityInfo extends BaseInfo {
|
|
|
2568
2652
|
* Parsed SubtypeSelector configuration, if configured.
|
|
2569
2653
|
*/
|
|
2570
2654
|
get SubtypeSelectorConfig() {
|
|
2571
|
-
if (this._subtypeSelectorConfig === undefined) {
|
|
2655
|
+
if (this._subtypeSelectorConfig === undefined || this._subtypeSelectorRaw !== this.SubtypeSelector) {
|
|
2656
|
+
this._subtypeSelectorRaw = this.SubtypeSelector;
|
|
2572
2657
|
if (this.SubtypeSelector && typeof this.SubtypeSelector === 'string') {
|
|
2573
2658
|
try {
|
|
2574
2659
|
const parsed = JSON.parse(this.SubtypeSelector);
|
|
2575
2660
|
if (parsed && typeof parsed['Path'] === 'string' && parsed['Path'].trim().length > 0) {
|
|
2576
|
-
|
|
2661
|
+
const config = {
|
|
2577
2662
|
Path: parsed['Path'].trim(),
|
|
2578
2663
|
UseForLoadedRecords: this.parseSubtypeSelectorUseForLoadedRecords(parsed),
|
|
2579
2664
|
};
|
|
2665
|
+
if (parsed['AutoEnsureOnSave'] !== undefined && parsed['AutoEnsureOnSave'] !== null) {
|
|
2666
|
+
config.AutoEnsureOnSave = this.parseSubtypeSelectorBooleanFlag(parsed, 'AutoEnsureOnSave');
|
|
2667
|
+
}
|
|
2668
|
+
if (parsed['OnSubtypeChange'] !== undefined && parsed['OnSubtypeChange'] !== null) {
|
|
2669
|
+
config.OnSubtypeChange = this.parseSubtypeSelectorChangeBehavior(parsed);
|
|
2670
|
+
}
|
|
2671
|
+
if (parsed['Driver'] !== undefined && parsed['Driver'] !== null) {
|
|
2672
|
+
const driver = this.parseSubtypeSelectorDriver(parsed);
|
|
2673
|
+
if (driver) {
|
|
2674
|
+
config.Driver = driver;
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
if (parsed['FoldIntoForm'] !== undefined && parsed['FoldIntoForm'] !== null) {
|
|
2678
|
+
config.FoldIntoForm = this.parseSubtypeSelectorBooleanFlag(parsed, 'FoldIntoForm');
|
|
2679
|
+
}
|
|
2680
|
+
if (parsed['UIDriver'] !== undefined && parsed['UIDriver'] !== null) {
|
|
2681
|
+
const uiDriver = this.parseSubtypeSelectorUIDriver(parsed);
|
|
2682
|
+
if (uiDriver) {
|
|
2683
|
+
config.UIDriver = uiDriver;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
this._subtypeSelectorConfig = config;
|
|
2580
2687
|
}
|
|
2581
2688
|
else {
|
|
2582
2689
|
LogError(`EntityInfo '${this.Name}': SubtypeSelector JSON must contain a non-empty 'Path' string property. Found: ${this.SubtypeSelector}`);
|
|
@@ -2607,6 +2714,56 @@ export class EntityInfo extends BaseInfo {
|
|
|
2607
2714
|
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'UseForLoadedRecords' must be true or false, but is ${JSON.stringify(value)}. Loads of this entity won't use the selector.`);
|
|
2608
2715
|
return false;
|
|
2609
2716
|
}
|
|
2717
|
+
parseSubtypeSelectorBooleanFlag(parsed, key) {
|
|
2718
|
+
const value = parsed[key];
|
|
2719
|
+
if (typeof value === 'boolean') {
|
|
2720
|
+
return value;
|
|
2721
|
+
}
|
|
2722
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector '${key}' must be true or false, but is ${JSON.stringify(value)}. Defaulting to false.`);
|
|
2723
|
+
return false;
|
|
2724
|
+
}
|
|
2725
|
+
parseSubtypeSelectorChangeBehavior(parsed) {
|
|
2726
|
+
const value = parsed['OnSubtypeChange'];
|
|
2727
|
+
if (value === 'Refuse' || value === 'Replace') {
|
|
2728
|
+
return value;
|
|
2729
|
+
}
|
|
2730
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'OnSubtypeChange' must be 'Refuse' or 'Replace', but is ${JSON.stringify(value)}. Defaulting to 'Refuse'.`);
|
|
2731
|
+
return 'Refuse';
|
|
2732
|
+
}
|
|
2733
|
+
parseSubtypeSelectorDriver(parsed) {
|
|
2734
|
+
const raw = parsed['Driver'];
|
|
2735
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
2736
|
+
const driverObj = raw;
|
|
2737
|
+
const path = driverObj['Path'];
|
|
2738
|
+
if (typeof path === 'string' && path.trim().length > 0) {
|
|
2739
|
+
const driver = { Path: path.trim() };
|
|
2740
|
+
const baseClass = driverObj['BaseClass'];
|
|
2741
|
+
if (baseClass !== undefined && baseClass !== null) {
|
|
2742
|
+
if (typeof baseClass === 'string' && baseClass.trim().length > 0) {
|
|
2743
|
+
driver.BaseClass = baseClass.trim();
|
|
2744
|
+
}
|
|
2745
|
+
else {
|
|
2746
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'Driver.BaseClass' must be a non-empty string when provided, but is ${JSON.stringify(baseClass)}.`);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
return driver;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'Driver' must be an object with a non-empty 'Path' string, but is ${JSON.stringify(raw)}.`);
|
|
2753
|
+
return null;
|
|
2754
|
+
}
|
|
2755
|
+
parseSubtypeSelectorUIDriver(parsed) {
|
|
2756
|
+
const raw = parsed['UIDriver'];
|
|
2757
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
2758
|
+
const uiDriverObj = raw;
|
|
2759
|
+
const path = uiDriverObj['Path'];
|
|
2760
|
+
if (typeof path === 'string' && path.trim().length > 0) {
|
|
2761
|
+
return { Path: path.trim() };
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'UIDriver' must be an object with a non-empty 'Path' string, but is ${JSON.stringify(raw)}.`);
|
|
2765
|
+
return null;
|
|
2766
|
+
}
|
|
2610
2767
|
/**
|
|
2611
2768
|
* Whether field-level (column-level) security is enforced for this entity.
|
|
2612
2769
|
*
|
|
@@ -2734,6 +2891,25 @@ export class EntityInfo extends BaseInfo {
|
|
|
2734
2891
|
get CloneConfig() {
|
|
2735
2892
|
return this.ConfigurationObject?.Clone ?? null;
|
|
2736
2893
|
}
|
|
2894
|
+
/**
|
|
2895
|
+
* Effective declarative + programmatic lifecycle policy (state machine, field-freeze, and
|
|
2896
|
+
* `WriteAuthority`) resolved for this entity, or `null` when none is configured.
|
|
2897
|
+
*/
|
|
2898
|
+
get LifecyclePolicy() {
|
|
2899
|
+
return EntityLifecyclePolicyEngine.Instance.ResolvePolicy(this);
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Effective declarative + programmatic document auto-numbering policies resolved for this entity.
|
|
2903
|
+
*/
|
|
2904
|
+
get AutoNumberPolicies() {
|
|
2905
|
+
return DocumentNumberingEngine.Instance.ResolvePolicies(this);
|
|
2906
|
+
}
|
|
2907
|
+
/**
|
|
2908
|
+
* Effective declarative cross-entity parent-state lock policies resolved for this entity.
|
|
2909
|
+
*/
|
|
2910
|
+
get CrossEntityPolicies() {
|
|
2911
|
+
return CrossEntityPolicyEngine.Instance.ResolveDeclarativePolicies(this);
|
|
2912
|
+
}
|
|
2737
2913
|
/**
|
|
2738
2914
|
* Controls which columns a save operation (`spCreate` / `spUpdate`) returns from the database
|
|
2739
2915
|
* for this entity. Defaults to `'full'` when `Configuration.SaveReturnMode` is omitted or not
|
|
@@ -2822,6 +2998,122 @@ export class EntityInfo extends BaseInfo {
|
|
|
2822
2998
|
}
|
|
2823
2999
|
return true;
|
|
2824
3000
|
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Returns true when a comment of the specified `MJ: Comment Types` code or name is permitted
|
|
3003
|
+
* on records of this entity according to `Configuration.Comments.AllowedCommentTypes`.
|
|
3004
|
+
*
|
|
3005
|
+
* - Returns `false` whenever {@link AllowRecordComments} is `false`.
|
|
3006
|
+
* - When `AllowedCommentTypes` is omitted, plain comments (`'COMMENT'` / `'Comment'`) are
|
|
3007
|
+
* allowed by default while specialized comment types (such as `'FIELD_SUGGESTION'`) must be
|
|
3008
|
+
* explicitly enabled by the entity.
|
|
3009
|
+
* - When `AllowedCommentTypes` includes `'*'`, every comment type is permitted.
|
|
3010
|
+
*/
|
|
3011
|
+
IsCommentTypeAllowed(codeOrName, alternateName) {
|
|
3012
|
+
if (!this.AllowRecordComments) {
|
|
3013
|
+
return false;
|
|
3014
|
+
}
|
|
3015
|
+
const primary = (codeOrName ?? '').trim().toLowerCase();
|
|
3016
|
+
const secondary = (alternateName ?? '').trim().toLowerCase();
|
|
3017
|
+
if (!primary && !secondary) {
|
|
3018
|
+
return true;
|
|
3019
|
+
}
|
|
3020
|
+
const configured = this.CommentsConfig?.AllowedCommentTypes;
|
|
3021
|
+
if (!Array.isArray(configured)) {
|
|
3022
|
+
return primary === 'comment' || secondary === 'comment';
|
|
3023
|
+
}
|
|
3024
|
+
const allowed = new Set(configured.map((entry) => (entry ?? '').trim().toLowerCase()).filter(Boolean));
|
|
3025
|
+
if (allowed.has('*')) {
|
|
3026
|
+
return true;
|
|
3027
|
+
}
|
|
3028
|
+
return ((primary.length > 0 && allowed.has(primary)) ||
|
|
3029
|
+
(secondary.length > 0 && allowed.has(secondary)));
|
|
3030
|
+
}
|
|
3031
|
+
/**
|
|
3032
|
+
* Whether EntityFieldInfo instances have been materialized for this entity.
|
|
3033
|
+
* True if .Fields or any field-derived getter has been accessed; false if still deferred.
|
|
3034
|
+
*/
|
|
3035
|
+
get IsFieldsLoaded() {
|
|
3036
|
+
return this._fieldsLoaded;
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* Serializes EntityInfo to a plain object without forcing lazy EntityFieldInfo
|
|
3040
|
+
* materialization when fields are still deferred.
|
|
3041
|
+
*/
|
|
3042
|
+
toJSON() {
|
|
3043
|
+
if (this._fieldsLoaded) {
|
|
3044
|
+
return super.toJSON();
|
|
3045
|
+
}
|
|
3046
|
+
const savedRaw = this._rawFields;
|
|
3047
|
+
this._fieldsLoaded = true;
|
|
3048
|
+
this._fields = [];
|
|
3049
|
+
let result;
|
|
3050
|
+
try {
|
|
3051
|
+
result = super.toJSON();
|
|
3052
|
+
}
|
|
3053
|
+
finally {
|
|
3054
|
+
this._fieldsLoaded = false;
|
|
3055
|
+
this._rawFields = savedRaw;
|
|
3056
|
+
}
|
|
3057
|
+
result['Fields'] = savedRaw
|
|
3058
|
+
? savedRaw.map((item) => (item instanceof EntityFieldInfo ? item.toJSON() : item))
|
|
3059
|
+
: [];
|
|
3060
|
+
return result;
|
|
3061
|
+
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Ensures EntityFieldInfo instances are created for this entity.
|
|
3064
|
+
* Deferring creation until .Fields or a field-derived getter is accessed
|
|
3065
|
+
* saves allocating thousands of EntityFieldInfo objects at startup.
|
|
3066
|
+
*/
|
|
3067
|
+
EnsureFieldsLoaded() {
|
|
3068
|
+
if (this._fieldsLoaded) {
|
|
3069
|
+
return;
|
|
3070
|
+
}
|
|
3071
|
+
this._fieldsLoaded = true;
|
|
3072
|
+
if (this._rawFields && this._rawFields.length > 0) {
|
|
3073
|
+
const md = this.OwningProvider;
|
|
3074
|
+
const fields = [];
|
|
3075
|
+
for (let j = 0; j < this._rawFields.length; j++) {
|
|
3076
|
+
const item = this._rawFields[j];
|
|
3077
|
+
const field = item instanceof EntityFieldInfo ? item : new EntityFieldInfo(item);
|
|
3078
|
+
if (md) {
|
|
3079
|
+
field.SetOwningProvider(md);
|
|
3080
|
+
}
|
|
3081
|
+
fields.push(field);
|
|
3082
|
+
}
|
|
3083
|
+
this._fields = fields;
|
|
3084
|
+
this._rawFields = null;
|
|
3085
|
+
}
|
|
3086
|
+
else if (!this._fields) {
|
|
3087
|
+
this._fields = [];
|
|
3088
|
+
}
|
|
3089
|
+
let virtualCount = 0;
|
|
3090
|
+
let floatCount = 0;
|
|
3091
|
+
let hasIdField = false;
|
|
3092
|
+
for (let j = 0; j < this._fields.length; ++j) {
|
|
3093
|
+
const f = this._fields[j];
|
|
3094
|
+
if (f.Name && f.Name.trim().toUpperCase() === 'ID') {
|
|
3095
|
+
hasIdField = true;
|
|
3096
|
+
}
|
|
3097
|
+
virtualCount += f.IsVirtual ? 1 : 0;
|
|
3098
|
+
floatCount += f.IsFloat ? 1 : 0;
|
|
3099
|
+
}
|
|
3100
|
+
if (this._lazyHasIdField === undefined) {
|
|
3101
|
+
this._lazyHasIdField = hasIdField;
|
|
3102
|
+
}
|
|
3103
|
+
if (this._lazyVirtualCount === undefined) {
|
|
3104
|
+
this._lazyVirtualCount = virtualCount;
|
|
3105
|
+
}
|
|
3106
|
+
if (this._lazyFloatCount === undefined) {
|
|
3107
|
+
this._lazyFloatCount = floatCount;
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
get HasIdField() {
|
|
3111
|
+
this.EnsureFieldsLoaded();
|
|
3112
|
+
return this._lazyHasIdField ?? false;
|
|
3113
|
+
}
|
|
3114
|
+
set HasIdField(value) {
|
|
3115
|
+
this._lazyHasIdField = value;
|
|
3116
|
+
}
|
|
2825
3117
|
/** @deprecated Use {@link HasIdField}. */
|
|
2826
3118
|
get _hasIdField() {
|
|
2827
3119
|
return this.HasIdField;
|
|
@@ -2830,6 +3122,13 @@ export class EntityInfo extends BaseInfo {
|
|
|
2830
3122
|
set _hasIdField(value) {
|
|
2831
3123
|
this.HasIdField = value;
|
|
2832
3124
|
}
|
|
3125
|
+
get VirtualCount() {
|
|
3126
|
+
this.EnsureFieldsLoaded();
|
|
3127
|
+
return this._lazyVirtualCount ?? 0;
|
|
3128
|
+
}
|
|
3129
|
+
set VirtualCount(value) {
|
|
3130
|
+
this._lazyVirtualCount = value;
|
|
3131
|
+
}
|
|
2833
3132
|
/** @deprecated Use {@link VirtualCount}. */
|
|
2834
3133
|
get _virtualCount() {
|
|
2835
3134
|
return this.VirtualCount;
|
|
@@ -2854,6 +3153,13 @@ export class EntityInfo extends BaseInfo {
|
|
|
2854
3153
|
set _oneToManyCount(value) {
|
|
2855
3154
|
this.OneToManyCount = value;
|
|
2856
3155
|
}
|
|
3156
|
+
get FloatCount() {
|
|
3157
|
+
this.EnsureFieldsLoaded();
|
|
3158
|
+
return this._lazyFloatCount ?? 0;
|
|
3159
|
+
}
|
|
3160
|
+
set FloatCount(value) {
|
|
3161
|
+
this._lazyFloatCount = value;
|
|
3162
|
+
}
|
|
2857
3163
|
/** @deprecated Use {@link FloatCount}. */
|
|
2858
3164
|
get _floatCount() {
|
|
2859
3165
|
return this.FloatCount;
|
|
@@ -3089,9 +3395,10 @@ export class EntityInfo extends BaseInfo {
|
|
|
3089
3395
|
_entityDeniedFieldsCache.set(this, byUser);
|
|
3090
3396
|
}
|
|
3091
3397
|
let entry = byUser.get(user);
|
|
3092
|
-
|
|
3398
|
+
const fields = this.Fields;
|
|
3399
|
+
if (!entry || entry.fieldsRef !== fields || entry.generation !== generation
|
|
3093
3400
|
|| !sameAncestors(entry.ancestors, ancestors) || entry.rolesKey !== rolesKey) {
|
|
3094
|
-
entry = { fieldsRef:
|
|
3401
|
+
entry = { fieldsRef: fields, generation, ancestors, rolesKey };
|
|
3095
3402
|
byUser.set(user, entry);
|
|
3096
3403
|
}
|
|
3097
3404
|
return entry;
|
|
@@ -3126,7 +3433,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3126
3433
|
getDeniedFields(user, verb, isDenied) {
|
|
3127
3434
|
const denied = new Set();
|
|
3128
3435
|
if (this.EnableFieldLevelSecurity) {
|
|
3129
|
-
for (const field of this.
|
|
3436
|
+
for (const field of this.Fields) {
|
|
3130
3437
|
if (isDenied(field.GetUserFieldPermissions(user, true))) {
|
|
3131
3438
|
this.addDeniedField(denied, field);
|
|
3132
3439
|
}
|
|
@@ -3160,7 +3467,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3160
3467
|
if (parentDenied.size === 0) {
|
|
3161
3468
|
return;
|
|
3162
3469
|
}
|
|
3163
|
-
for (const field of this.
|
|
3470
|
+
for (const field of this.Fields) {
|
|
3164
3471
|
const parentField = parent.FieldByName(field.Name);
|
|
3165
3472
|
if (parentField && parentDenied.has(parentField.Name.trim().toLowerCase())) {
|
|
3166
3473
|
this.addDeniedField(denied, field);
|
|
@@ -3187,7 +3494,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3187
3494
|
if (name == null)
|
|
3188
3495
|
return undefined;
|
|
3189
3496
|
if (this._fieldByNameMap === null) {
|
|
3190
|
-
const fields = this.
|
|
3497
|
+
const fields = this.Fields ?? [];
|
|
3191
3498
|
const map = new Map();
|
|
3192
3499
|
for (const f of fields) {
|
|
3193
3500
|
if (f.Name != null)
|
|
@@ -3198,7 +3505,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3198
3505
|
return this._fieldByNameMap.get(name.trim().toLowerCase());
|
|
3199
3506
|
}
|
|
3200
3507
|
ensureFieldIndexEntry() {
|
|
3201
|
-
const fields = this.
|
|
3508
|
+
const fields = this.Fields ?? [];
|
|
3202
3509
|
let entry = _entityFieldIndexCache.get(this);
|
|
3203
3510
|
if (!entry || entry.fieldsRef !== fields || entry.fieldsLen !== fields.length) {
|
|
3204
3511
|
const byName = new Map();
|
|
@@ -3250,7 +3557,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3250
3557
|
*/
|
|
3251
3558
|
FieldByCodeName(codeName) {
|
|
3252
3559
|
const idx = this.FieldIndexByCodeName(codeName);
|
|
3253
|
-
const fields = this.
|
|
3560
|
+
const fields = this.Fields;
|
|
3254
3561
|
return idx >= 0 && fields ? fields[idx] : undefined;
|
|
3255
3562
|
}
|
|
3256
3563
|
/**
|
|
@@ -3279,8 +3586,11 @@ export class EntityInfo extends BaseInfo {
|
|
|
3279
3586
|
return this._primaryKeysCache;
|
|
3280
3587
|
}
|
|
3281
3588
|
/**
|
|
3282
|
-
* Returns
|
|
3283
|
-
*
|
|
3589
|
+
* Returns the fields that are unique on their own ({@link EntityFieldInfo.IsUnique}): a
|
|
3590
|
+
* single-column primary key, or the only key column of an unfiltered unique index or
|
|
3591
|
+
* constraint. Columns of a composite unique key are not included; use {@link UniqueKeySets}
|
|
3592
|
+
* or {@link IsUniqueFieldSet} for those.
|
|
3593
|
+
* @returns {EntityFieldInfo[]} Array of fields that are unique on their own
|
|
3284
3594
|
*/
|
|
3285
3595
|
get UniqueKeys() {
|
|
3286
3596
|
if (this._uniqueKeysCache === null) {
|
|
@@ -3348,6 +3658,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3348
3658
|
* @returns {EntityFieldInfo[]} Array of all entity fields
|
|
3349
3659
|
*/
|
|
3350
3660
|
get Fields() {
|
|
3661
|
+
this.EnsureFieldsLoaded();
|
|
3351
3662
|
return this._fields;
|
|
3352
3663
|
}
|
|
3353
3664
|
/**
|
|
@@ -3363,7 +3674,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3363
3674
|
*/
|
|
3364
3675
|
get HasInactiveFields() {
|
|
3365
3676
|
if (this._hasInactiveFields === undefined) {
|
|
3366
|
-
this._hasInactiveFields = this.
|
|
3677
|
+
this._hasInactiveFields = this.Fields.some(f => f.Status === 'Deprecated' || f.Status === 'Disabled');
|
|
3367
3678
|
}
|
|
3368
3679
|
return this._hasInactiveFields;
|
|
3369
3680
|
}
|
|
@@ -3389,7 +3700,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
3389
3700
|
*/
|
|
3390
3701
|
get HasSearchFields() {
|
|
3391
3702
|
if (this._hasSearchFields === undefined) {
|
|
3392
|
-
this._hasSearchFields = this.
|
|
3703
|
+
this._hasSearchFields = this.Fields.some(f => f.IncludeInUserSearchAPI);
|
|
3393
3704
|
}
|
|
3394
3705
|
return this._hasSearchFields;
|
|
3395
3706
|
}
|
|
@@ -3431,6 +3742,44 @@ export class EntityInfo extends BaseInfo {
|
|
|
3431
3742
|
get OrganicKeys() {
|
|
3432
3743
|
return this._organicKeys;
|
|
3433
3744
|
}
|
|
3745
|
+
/**
|
|
3746
|
+
* The unique indexes and unique constraints on this entity's base table, each as a set of
|
|
3747
|
+
* columns, sorted by name. Primary keys are not included. Maintained by CodeGen from the
|
|
3748
|
+
* database catalog.
|
|
3749
|
+
* @returns {EntityUniqueKeyInfo[]} Array of unique key definitions
|
|
3750
|
+
*/
|
|
3751
|
+
get UniqueKeySets() {
|
|
3752
|
+
return this._uniqueKeySets;
|
|
3753
|
+
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Whether a row is identified by its values in `fieldNames`: true when the names include every
|
|
3756
|
+
* primary key field, a field that is unique on its own ({@link EntityFieldInfo.IsUnique}, which
|
|
3757
|
+
* also covers uniqueness declared by configuration on a view), or every field of an unfiltered
|
|
3758
|
+
* unique key ({@link UniqueKeySets}). Matching is case-insensitive. A filtered key does not
|
|
3759
|
+
* count, since rows outside its filter can repeat its values.
|
|
3760
|
+
*
|
|
3761
|
+
* `IsUniqueFieldSet(['ActionID'])` asks whether that column alone is unique — for a foreign key,
|
|
3762
|
+
* whether the relationship is one-to-one.
|
|
3763
|
+
*/
|
|
3764
|
+
IsUniqueFieldSet(fieldNames) {
|
|
3765
|
+
return EntityInfo.IsUniqueFieldSetOf(this, fieldNames);
|
|
3766
|
+
}
|
|
3767
|
+
/**
|
|
3768
|
+
* {@link IsUniqueFieldSet} over any object carrying an entity's `Fields` and `UniqueKeySets`,
|
|
3769
|
+
* for callers that hold entity metadata in a plain shape. Missing collections count as empty.
|
|
3770
|
+
*/
|
|
3771
|
+
static IsUniqueFieldSetOf(entity, fieldNames) {
|
|
3772
|
+
const names = new Set(fieldNames.map(n => n.trim().toLowerCase()));
|
|
3773
|
+
if (names.size === 0) {
|
|
3774
|
+
return false;
|
|
3775
|
+
}
|
|
3776
|
+
const covers = (keyFields) => keyFields.length > 0 && keyFields.every(f => names.has(f.toLowerCase()));
|
|
3777
|
+
const fields = entity.Fields ?? [];
|
|
3778
|
+
if (covers(fields.filter(f => f.IsPrimaryKey).map(f => f.Name)) || fields.some(f => f.IsUnique && names.has(f.Name.toLowerCase()))) {
|
|
3779
|
+
return true;
|
|
3780
|
+
}
|
|
3781
|
+
return (entity.UniqueKeySets ?? []).some(k => !k.IsFiltered && covers(k.FieldNamesArray));
|
|
3782
|
+
}
|
|
3434
3783
|
/**
|
|
3435
3784
|
* Gets all registered alternate base views for this entity, sorted by `Sequence`, `Name`, and `ID`.
|
|
3436
3785
|
* Alternate base views maintain 100% column parity with {@link BaseView} while applying a
|
|
@@ -3840,12 +4189,43 @@ export class EntityInfo extends BaseInfo {
|
|
|
3840
4189
|
try {
|
|
3841
4190
|
const _ = user.UserRoles; // preserve throw-on-null behavior
|
|
3842
4191
|
const userRoleIds = getUserRoleIdSet(user);
|
|
4192
|
+
const perms = this.Permissions;
|
|
4193
|
+
const permsLen = perms.length;
|
|
4194
|
+
const apiFlags = (this.AllowCreateAPI ? 1 : 0) |
|
|
4195
|
+
(this.AllowUpdateAPI ? 2 : 0) |
|
|
4196
|
+
(this.AllowDeleteAPI ? 4 : 0);
|
|
4197
|
+
let permsStamp = permsLen;
|
|
4198
|
+
for (let k = 0; k < permsLen; k++) {
|
|
4199
|
+
const p = perms[k];
|
|
4200
|
+
const mask = (p.CanCreate ? 1 : 0) |
|
|
4201
|
+
(p.CanRead ? 2 : 0) |
|
|
4202
|
+
(p.CanUpdate ? 4 : 0) |
|
|
4203
|
+
(p.CanDelete ? 8 : 0) |
|
|
4204
|
+
(p.IsDeny ? 16 : 0);
|
|
4205
|
+
permsStamp = ((permsStamp * 31) + mask) | 0;
|
|
4206
|
+
}
|
|
4207
|
+
const firstPermRoleId = permsLen > 0 ? perms[0].RoleID : undefined;
|
|
4208
|
+
const lastPermRoleId = permsLen > 0 ? perms[permsLen - 1].RoleID : undefined;
|
|
4209
|
+
let byUser = _entityUserPermissionsCache.get(this);
|
|
4210
|
+
const cached = byUser?.get(user);
|
|
4211
|
+
if (cached &&
|
|
4212
|
+
cached.generation === _fieldSecurityGeneration &&
|
|
4213
|
+
cached.permissionsRef === perms &&
|
|
4214
|
+
cached.permissionsLen === permsLen &&
|
|
4215
|
+
cached.permissionsStamp === permsStamp &&
|
|
4216
|
+
cached.firstPermRoleId === firstPermRoleId &&
|
|
4217
|
+
cached.lastPermRoleId === lastPermRoleId &&
|
|
4218
|
+
cached.roleIdsRef === userRoleIds &&
|
|
4219
|
+
cached.apiFlags === apiFlags) {
|
|
4220
|
+
return cached.result;
|
|
4221
|
+
}
|
|
3843
4222
|
const allow = { CanCreate: false, CanRead: false, CanUpdate: false, CanDelete: false };
|
|
3844
4223
|
const deny = { CanCreate: false, CanRead: false, CanUpdate: false, CanDelete: false };
|
|
3845
4224
|
if (userRoleIds.size > 0) {
|
|
3846
|
-
for (let j = 0; j <
|
|
3847
|
-
const ep =
|
|
3848
|
-
|
|
4225
|
+
for (let j = 0; j < permsLen; j++) {
|
|
4226
|
+
const ep = perms[j];
|
|
4227
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4228
|
+
if (normRoleId && userRoleIds.has(normRoleId)) {
|
|
3849
4229
|
const bucket = ep.IsDeny ? deny : allow;
|
|
3850
4230
|
bucket.CanCreate = bucket.CanCreate || !!ep.CanCreate;
|
|
3851
4231
|
bucket.CanRead = bucket.CanRead || !!ep.CanRead;
|
|
@@ -3859,12 +4239,27 @@ export class EntityInfo extends BaseInfo {
|
|
|
3859
4239
|
// corresponding API is disabled — so fold the entity-level flag into the result.
|
|
3860
4240
|
// (Read has no `Allow*API` flag; it's governed by the entity view, so it's unchanged.)
|
|
3861
4241
|
const userPermission = new EntityUserPermissionInfo();
|
|
3862
|
-
userPermission.CanCreate = this.AllowCreateAPI && allow.CanCreate && !deny.CanCreate;
|
|
3863
|
-
userPermission.CanRead = allow.CanRead && !deny.CanRead;
|
|
3864
|
-
userPermission.CanUpdate = this.AllowUpdateAPI && allow.CanUpdate && !deny.CanUpdate;
|
|
3865
|
-
userPermission.CanDelete = this.AllowDeleteAPI && allow.CanDelete && !deny.CanDelete;
|
|
4242
|
+
userPermission.CanCreate = Boolean(this.AllowCreateAPI && allow.CanCreate && !deny.CanCreate);
|
|
4243
|
+
userPermission.CanRead = Boolean(allow.CanRead && !deny.CanRead);
|
|
4244
|
+
userPermission.CanUpdate = Boolean(this.AllowUpdateAPI && allow.CanUpdate && !deny.CanUpdate);
|
|
4245
|
+
userPermission.CanDelete = Boolean(this.AllowDeleteAPI && allow.CanDelete && !deny.CanDelete);
|
|
3866
4246
|
userPermission.Entity = this;
|
|
3867
4247
|
userPermission.User = user;
|
|
4248
|
+
if (!byUser) {
|
|
4249
|
+
byUser = new WeakMap();
|
|
4250
|
+
_entityUserPermissionsCache.set(this, byUser);
|
|
4251
|
+
}
|
|
4252
|
+
byUser.set(user, {
|
|
4253
|
+
generation: _fieldSecurityGeneration,
|
|
4254
|
+
permissionsRef: perms,
|
|
4255
|
+
permissionsLen: permsLen,
|
|
4256
|
+
permissionsStamp: permsStamp,
|
|
4257
|
+
firstPermRoleId,
|
|
4258
|
+
lastPermRoleId,
|
|
4259
|
+
roleIdsRef: userRoleIds,
|
|
4260
|
+
apiFlags,
|
|
4261
|
+
result: userPermission,
|
|
4262
|
+
});
|
|
3868
4263
|
return userPermission;
|
|
3869
4264
|
}
|
|
3870
4265
|
catch (err) {
|
|
@@ -3936,7 +4331,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
3936
4331
|
if (ep.IsDeny) {
|
|
3937
4332
|
continue; // a Deny row's Can* flags are denials, never grants — it cannot exempt anyone
|
|
3938
4333
|
}
|
|
3939
|
-
|
|
4334
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4335
|
+
if (normRoleId && userRoleIds.has(normRoleId)) { // user has this role
|
|
3940
4336
|
switch (type) {
|
|
3941
4337
|
case EntityPermissionType.Create:
|
|
3942
4338
|
if (ep.CanCreate && !ep.CreateRLSFilterID)
|
|
@@ -3988,7 +4384,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
3988
4384
|
if (ep.IsDeny) {
|
|
3989
4385
|
continue; // never a grant — see the doc comment
|
|
3990
4386
|
}
|
|
3991
|
-
|
|
4387
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4388
|
+
if (normRoleId && userRoleIds.has(normRoleId)) { // user has this role
|
|
3992
4389
|
let matchObject = null;
|
|
3993
4390
|
switch (type) {
|
|
3994
4391
|
case EntityPermissionType.Create:
|
|
@@ -4037,6 +4434,18 @@ export class EntityInfo extends BaseInfo {
|
|
|
4037
4434
|
if (this.UserExemptFromRowLevelSecurity(user, type)) {
|
|
4038
4435
|
return '';
|
|
4039
4436
|
}
|
|
4437
|
+
const sRLSSQL = this.roleRowFilterClause(user, type, null);
|
|
4438
|
+
if (sRLSSQL.length === 0) {
|
|
4439
|
+
return '';
|
|
4440
|
+
}
|
|
4441
|
+
return `${returnPrefix && returnPrefix.length > 0 ? returnPrefix + ' ' : ''}${sRLSSQL}`;
|
|
4442
|
+
}
|
|
4443
|
+
/**
|
|
4444
|
+
* The role layer of the row filter, '' when no role filter applies. Callers check the
|
|
4445
|
+
* role-RLS exemption first. With a `binder`, user values bind as parameters
|
|
4446
|
+
* ({@link RowLevelSecurityFilterInfo.MarkupFilterParameterized}).
|
|
4447
|
+
*/
|
|
4448
|
+
roleRowFilterClause(user, type, binder) {
|
|
4040
4449
|
const userRLS = this.GetUserRowLevelSecurityInfo(user, type);
|
|
4041
4450
|
if (!userRLS || userRLS.length === 0) {
|
|
4042
4451
|
return '';
|
|
@@ -4045,9 +4454,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
4045
4454
|
// parenthesized, and a group of two or more is parenthesized as a whole, so a predicate the
|
|
4046
4455
|
// caller ANDs beside the clause (`WHERE ID = @p0 AND <clause>`) applies to every filter rather
|
|
4047
4456
|
// than binding to the first one only. A single filter keeps its one pair of parentheses.
|
|
4048
|
-
const terms = userRLS.map((rls) => `(${rls.MarkupFilterText(user)})`);
|
|
4049
|
-
|
|
4050
|
-
return `${returnPrefix && returnPrefix.length > 0 ? returnPrefix + ' ' : ''}${sRLSSQL}`;
|
|
4457
|
+
const terms = userRLS.map((rls) => `(${binder ? rls.MarkupFilterParameterized(user, binder) : rls.MarkupFilterText(user)})`);
|
|
4458
|
+
return terms.length > 1 ? `(${terms.join(' OR ')})` : terms[0];
|
|
4051
4459
|
}
|
|
4052
4460
|
/**
|
|
4053
4461
|
* The EFFECTIVE row-filter clause for a user + permission type: role RLS (subject to the
|
|
@@ -4065,22 +4473,39 @@ export class EntityInfo extends BaseInfo {
|
|
|
4065
4473
|
*
|
|
4066
4474
|
* The application-ceiling layer (APIApplicationScope.RowFilterID) is deferred to v2 by
|
|
4067
4475
|
* design decision; the column ships unused and the term composes here when it lands.
|
|
4068
|
-
|
|
4069
|
-
|
|
4476
|
+
*
|
|
4477
|
+
* With a `binder`, the user's values bind as query parameters (#5713): same layers, same
|
|
4478
|
+
* order, same composition, but each token that is a whole quoted literal is replaced by the
|
|
4479
|
+
* placeholder `binder` returns, so the clause text is the same for every user and the
|
|
4480
|
+
* database reuses one plan per query shape. The binder collects the parameters in
|
|
4481
|
+
* placeholder order, and binds nothing when no layer contributes. The binder is an optional
|
|
4482
|
+
* argument of this method rather than a separate one so that every implementation of the
|
|
4483
|
+
* method, test doubles included, keeps answering the call. The RunView cache fingerprint
|
|
4484
|
+
* must call this without a binder: the literal clause is what keeps two users from sharing
|
|
4485
|
+
* a cached result.
|
|
4486
|
+
*/
|
|
4487
|
+
GetEffectiveRowFilterWhereClause(user, type, returnPrefix, binder) {
|
|
4488
|
+
const sql = this.effectiveRowFilterClause(user, type, binder ?? null);
|
|
4489
|
+
if (sql.length === 0) {
|
|
4490
|
+
return '';
|
|
4491
|
+
}
|
|
4492
|
+
return `${returnPrefix && returnPrefix.length > 0 ? returnPrefix + ' ' : ''}${sql}`;
|
|
4493
|
+
}
|
|
4494
|
+
/** The composed row-filter clause without a prefix; literal when `binder` is null. */
|
|
4495
|
+
effectiveRowFilterClause(user, type, binder) {
|
|
4070
4496
|
const layers = [];
|
|
4071
|
-
|
|
4497
|
+
// The literal form goes through GetUserRowLevelSecurityWhereClause, which applies the exemption itself.
|
|
4498
|
+
const roleClause = binder === null
|
|
4499
|
+
? this.GetUserRowLevelSecurityWhereClause(user, type, '')
|
|
4500
|
+
: (this.UserExemptFromRowLevelSecurity(user, type) ? '' : this.roleRowFilterClause(user, type, binder));
|
|
4072
4501
|
if (roleClause && roleClause.length > 0) {
|
|
4073
4502
|
layers.push(`(${roleClause})`);
|
|
4074
4503
|
}
|
|
4075
|
-
const keyClause = this.getAPIKeyRowFilterClause(user, type);
|
|
4504
|
+
const keyClause = this.getAPIKeyRowFilterClause(user, type, binder);
|
|
4076
4505
|
if (keyClause && keyClause.length > 0) {
|
|
4077
4506
|
layers.push(`(${keyClause})`);
|
|
4078
4507
|
}
|
|
4079
|
-
|
|
4080
|
-
return '';
|
|
4081
|
-
}
|
|
4082
|
-
const sql = layers.join(' AND ');
|
|
4083
|
-
return `${returnPrefix && returnPrefix.length > 0 ? returnPrefix + ' ' : ''}${sql}`;
|
|
4508
|
+
return layers.join(' AND ');
|
|
4084
4509
|
}
|
|
4085
4510
|
/**
|
|
4086
4511
|
* Resolves the API-key row-filter clause for this entity + permission type from the
|
|
@@ -4090,7 +4515,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4090
4515
|
* or unloaded) contributes `(1=0)`, and unresolved tokens inside a filter collapse it
|
|
4091
4516
|
* to `(1=0)` via the match-nothing markup mode.
|
|
4092
4517
|
*/
|
|
4093
|
-
getAPIKeyRowFilterClause(user, type) {
|
|
4518
|
+
getAPIKeyRowFilterClause(user, type, binder) {
|
|
4094
4519
|
const bindings = user?.APIKeyRowFilters;
|
|
4095
4520
|
if (!bindings || bindings.length === 0) {
|
|
4096
4521
|
return '';
|
|
@@ -4107,7 +4532,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
4107
4532
|
LogError(`API-key row filter ${b.FilterID} for entity ${this.Name} not found in metadata — resolving to (1=0)`);
|
|
4108
4533
|
return '(1=0)';
|
|
4109
4534
|
}
|
|
4110
|
-
|
|
4535
|
+
const options = { unresolvedBehavior: 'match-nothing' };
|
|
4536
|
+
return `(${binder ? filter.MarkupFilterParameterized(user, binder, options) : filter.MarkupFilterText(user, options)})`;
|
|
4111
4537
|
});
|
|
4112
4538
|
return clauses.join(' AND ');
|
|
4113
4539
|
}
|
|
@@ -4404,6 +4830,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4404
4830
|
'EntitySettings', '_Settings', 'Settings',
|
|
4405
4831
|
'EntityRelationships', '_RelatedEntities', 'RelatedEntities',
|
|
4406
4832
|
'EntityOrganicKeys', '_OrganicKeys', 'OrganicKeys',
|
|
4833
|
+
'EntityUniqueKeys', '_UniqueKeySets', 'UniqueKeySets',
|
|
4407
4834
|
'EntityAlternateBaseViews', '_AlternateBaseViews', 'AlternateBaseViews',
|
|
4408
4835
|
]); }
|
|
4409
4836
|
/**
|
|
@@ -4528,6 +4955,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4528
4955
|
*/
|
|
4529
4956
|
this.SubtypeSelector = null;
|
|
4530
4957
|
this._subtypeSelectorConfig = undefined;
|
|
4958
|
+
this._subtypeSelectorRaw = undefined;
|
|
4531
4959
|
/**
|
|
4532
4960
|
* Whether to audit when users access records from this entity
|
|
4533
4961
|
*/
|
|
@@ -4852,14 +5280,19 @@ export class EntityInfo extends BaseInfo {
|
|
|
4852
5280
|
this.ParentEntity = null;
|
|
4853
5281
|
this.ParentBaseTable = null;
|
|
4854
5282
|
this.ParentBaseView = null;
|
|
5283
|
+
// These are not in the database view and are added in code
|
|
5284
|
+
this._fields = [];
|
|
5285
|
+
this._fieldsLoaded = false;
|
|
5286
|
+
this._rawFields = null;
|
|
4855
5287
|
this._fieldCategories = null;
|
|
4856
5288
|
this._organicKeys = [];
|
|
5289
|
+
this._uniqueKeySets = [];
|
|
4857
5290
|
this._alternateBaseViews = [];
|
|
4858
|
-
this.
|
|
4859
|
-
this.
|
|
5291
|
+
this._lazyHasIdField = undefined;
|
|
5292
|
+
this._lazyVirtualCount = undefined;
|
|
4860
5293
|
this.ManyToManyCount = 0;
|
|
4861
5294
|
this.OneToManyCount = 0;
|
|
4862
|
-
this.
|
|
5295
|
+
this._lazyFloatCount = undefined;
|
|
4863
5296
|
// --- Lazy caches for immutable field-derived collections ---------------------------------
|
|
4864
5297
|
// `_Fields` is populated once in the constructor and never reassigned, so these caches never
|
|
4865
5298
|
// need invalidation. They replace per-access `.filter()`/`.find()` scans on hot paths
|
|
@@ -4892,6 +5325,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4892
5325
|
// do some special handling to create class instances instead of just data objects
|
|
4893
5326
|
// copy the Entity Fields (accept EntityFields, _Fields, or Fields as input names)
|
|
4894
5327
|
this._fields = [];
|
|
5328
|
+
this._fieldsLoaded = false;
|
|
4895
5329
|
// Reset every lazy field-derived memo cache whenever _Fields is (re)assigned.
|
|
4896
5330
|
// `entityInfo.cacheReset.test.ts` mirrors this list in `runProductionCacheReset`;
|
|
4897
5331
|
// a cache added here needs adding there too, or its reset goes unexercised.
|
|
@@ -4916,13 +5350,16 @@ export class EntityInfo extends BaseInfo {
|
|
|
4916
5350
|
// Added late: HasInactiveFields (Jun 18) post-dates this block (Jun 15) and was never
|
|
4917
5351
|
// listed here, so it carried exactly the staleness the block exists to prevent.
|
|
4918
5352
|
this._hasInactiveFields = undefined;
|
|
5353
|
+
this._lazyHasIdField = undefined;
|
|
5354
|
+
this._lazyVirtualCount = undefined;
|
|
5355
|
+
this._lazyFloatCount = undefined;
|
|
4919
5356
|
const ef = initData.EntityFields || initData._Fields || initData.Fields;
|
|
4920
|
-
if (ef) {
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5357
|
+
if (ef && ef.length > 0) {
|
|
5358
|
+
this._rawFields = ef;
|
|
5359
|
+
}
|
|
5360
|
+
else {
|
|
5361
|
+
this._rawFields = null;
|
|
5362
|
+
this._fieldsLoaded = true;
|
|
4926
5363
|
}
|
|
4927
5364
|
// copy the Entity Permissions
|
|
4928
5365
|
this._permissions = [];
|
|
@@ -4975,6 +5412,15 @@ export class EntityInfo extends BaseInfo {
|
|
|
4975
5412
|
this._organicKeys.push(new EntityOrganicKeyInfo(item));
|
|
4976
5413
|
}
|
|
4977
5414
|
}
|
|
5415
|
+
// copy the Unique Key Sets, sorted by name so consumers see a stable order
|
|
5416
|
+
this._uniqueKeySets = [];
|
|
5417
|
+
const uk = initData.EntityUniqueKeys || initData._UniqueKeySets || initData.UniqueKeySets;
|
|
5418
|
+
if (uk && Array.isArray(uk)) {
|
|
5419
|
+
for (const item of uk) {
|
|
5420
|
+
this._uniqueKeySets.push(new EntityUniqueKeyInfo(item));
|
|
5421
|
+
}
|
|
5422
|
+
this._uniqueKeySets.sort((a, b) => ordinalCompare(a.Name, b.Name) || ordinalCompare(a.ID, b.ID));
|
|
5423
|
+
}
|
|
4978
5424
|
// copy the Alternate Base Views (sorted by Sequence, Name, ID, then linked via ParentID)
|
|
4979
5425
|
this._alternateBaseViews = [];
|
|
4980
5426
|
const abv = initData.EntityAlternateBaseViews || initData._AlternateBaseViews || initData.AlternateBaseViews;
|
|
@@ -4991,30 +5437,16 @@ export class EntityInfo extends BaseInfo {
|
|
|
4991
5437
|
});
|
|
4992
5438
|
EntityAlternateBaseViewInfo.LinkHierarchy(this._alternateBaseViews, this.SchemaName);
|
|
4993
5439
|
}
|
|
4994
|
-
this.
|
|
5440
|
+
this.prepareRelationshipCounts();
|
|
4995
5441
|
}
|
|
4996
5442
|
}
|
|
4997
|
-
|
|
5443
|
+
prepareRelationshipCounts() {
|
|
4998
5444
|
try {
|
|
4999
|
-
let virtualCount = 0;
|
|
5000
5445
|
let manyToManyCount = 0;
|
|
5001
5446
|
let oneToManyCount = 0;
|
|
5002
|
-
let floatCount = 0;
|
|
5003
|
-
let hasIdField = false;
|
|
5004
|
-
for (let j = 0; j < this.Fields.length; ++j) {
|
|
5005
|
-
const f = this.Fields[j];
|
|
5006
|
-
if (f.Name.trim().toUpperCase() === 'ID')
|
|
5007
|
-
hasIdField = true;
|
|
5008
|
-
virtualCount += f.IsVirtual ? 1 : 0;
|
|
5009
|
-
floatCount += f.IsFloat ? 1 : 0;
|
|
5010
|
-
}
|
|
5011
|
-
this.HasIdField = hasIdField;
|
|
5012
|
-
this.FloatCount = floatCount;
|
|
5013
|
-
this.VirtualCount = virtualCount;
|
|
5014
|
-
// now see if there are any relationships and count the one to many and many to many
|
|
5015
5447
|
for (let j = 0; j < this.RelatedEntities.length; ++j) {
|
|
5016
5448
|
const r = this.RelatedEntities[j];
|
|
5017
|
-
if (r.Type.trim().toUpperCase() === 'ONE TO MANY')
|
|
5449
|
+
if (r.Type && r.Type.trim().toUpperCase() === 'ONE TO MANY')
|
|
5018
5450
|
oneToManyCount++;
|
|
5019
5451
|
else
|
|
5020
5452
|
manyToManyCount++;
|
|
@@ -5026,6 +5458,10 @@ export class EntityInfo extends BaseInfo {
|
|
|
5026
5458
|
LogError(e);
|
|
5027
5459
|
}
|
|
5028
5460
|
}
|
|
5461
|
+
prepareSpecialFields() {
|
|
5462
|
+
this.prepareRelationshipCounts();
|
|
5463
|
+
this.EnsureFieldsLoaded();
|
|
5464
|
+
}
|
|
5029
5465
|
/**
|
|
5030
5466
|
* Parses FieldCategoryInfo from EntitySettings, with legacy FieldCategoryIcons fallback.
|
|
5031
5467
|
* Called once during construction so the result is cached on _FieldCategories.
|