@memberjunction/core 6.2.1 → 6.3.0-edge.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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.map +1 -1
- package/dist/generic/baseEngineRegistry.js +8 -1
- package/dist/generic/baseEngineRegistry.js.map +1 -1
- package/dist/generic/baseEntity.d.ts +147 -3
- package/dist/generic/baseEntity.d.ts.map +1 -1
- package/dist/generic/baseEntity.js +1063 -25
- package/dist/generic/baseEntity.js.map +1 -1
- package/dist/generic/baseRemotableOperation.d.ts +15 -0
- package/dist/generic/baseRemotableOperation.d.ts.map +1 -1
- package/dist/generic/baseRemotableOperation.js +11 -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/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 +14 -1
- package/dist/generic/dataHooks.d.ts.map +1 -1
- package/dist/generic/dataHooks.js.map +1 -1
- package/dist/generic/databaseProviderBase.d.ts +37 -0
- package/dist/generic/databaseProviderBase.d.ts.map +1 -1
- package/dist/generic/databaseProviderBase.js +220 -24
- 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 +104 -3
- package/dist/generic/entityInfo.d.ts.map +1 -1
- package/dist/generic/entityInfo.js +326 -22
- 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/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 +56 -1
- package/dist/generic/interfaces.d.ts.map +1 -1
- package/dist/generic/interfaces.js +0 -1
- package/dist/generic/interfaces.js.map +1 -1
- package/dist/generic/localCacheManager.d.ts +46 -3
- package/dist/generic/localCacheManager.d.ts.map +1 -1
- package/dist/generic/localCacheManager.js +267 -45
- package/dist/generic/localCacheManager.js.map +1 -1
- package/dist/generic/metadata.d.ts +3 -1
- package/dist/generic/metadata.d.ts.map +1 -1
- package/dist/generic/metadata.js +25 -6
- package/dist/generic/metadata.js.map +1 -1
- package/dist/generic/providerBase.d.ts +212 -33
- package/dist/generic/providerBase.d.ts.map +1 -1
- package/dist/generic/providerBase.js +543 -117
- 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/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/transactionGroup.d.ts +25 -0
- package/dist/generic/transactionGroup.d.ts.map +1 -1
- package/dist/generic/transactionGroup.js +105 -0
- package/dist/generic/transactionGroup.js.map +1 -1
- package/dist/generic/typedQuery.d.ts +151 -0
- package/dist/generic/typedQuery.d.ts.map +1 -0
- package/dist/generic/typedQuery.js +286 -0
- package/dist/generic/typedQuery.js.map +1 -0
- 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/views/runView.d.ts +53 -0
- package/dist/views/runView.d.ts.map +1 -1
- package/dist/views/runView.js +134 -0
- package/dist/views/runView.js.map +1 -1
- package/package.json +3 -3
|
@@ -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;
|
|
@@ -2407,21 +2472,29 @@ function getUserRoleIdSet(user) {
|
|
|
2407
2472
|
const roles = user.UserRoles;
|
|
2408
2473
|
const len = roles.length;
|
|
2409
2474
|
const firstId = roles[0]?.RoleID;
|
|
2475
|
+
const lastId = roles[len - 1]?.RoleID;
|
|
2410
2476
|
const cached = _userRoleIdSetCache.get(user);
|
|
2411
|
-
if (cached &&
|
|
2477
|
+
if (cached &&
|
|
2478
|
+
cached.rolesRef === roles &&
|
|
2479
|
+
cached.rolesLen === len &&
|
|
2480
|
+
cached.firstRoleId === firstId &&
|
|
2481
|
+
cached.lastRoleId === lastId) {
|
|
2412
2482
|
return cached.roleIds;
|
|
2413
2483
|
}
|
|
2414
2484
|
const roleIds = new Set();
|
|
2485
|
+
let rolesKey = '';
|
|
2415
2486
|
for (let i = 0; i < len; i++) {
|
|
2416
2487
|
const rid = roles[i]?.RoleID;
|
|
2488
|
+
rolesKey += `${rid ?? ''}|`;
|
|
2417
2489
|
if (rid) {
|
|
2418
2490
|
roleIds.add(rid.trim().toLowerCase());
|
|
2419
2491
|
}
|
|
2420
2492
|
}
|
|
2421
|
-
_userRoleIdSetCache.set(user, { rolesRef: roles, rolesLen: len, firstRoleId: firstId, roleIds });
|
|
2493
|
+
_userRoleIdSetCache.set(user, { rolesRef: roles, rolesLen: len, firstRoleId: firstId, lastRoleId: lastId, rolesKey, roleIds });
|
|
2422
2494
|
return roleIds;
|
|
2423
2495
|
}
|
|
2424
2496
|
const _entityFieldIndexCache = new WeakMap();
|
|
2497
|
+
const _entityUserPermissionsCache = new WeakMap();
|
|
2425
2498
|
const _entityDeniedFieldsCache = new WeakMap();
|
|
2426
2499
|
/**
|
|
2427
2500
|
* The field-security generation: one process-wide number that moves whenever an answer derived
|
|
@@ -2475,11 +2548,19 @@ function userRolesKey(user) {
|
|
|
2475
2548
|
if (!roles || roles.length === 0) {
|
|
2476
2549
|
return '';
|
|
2477
2550
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2551
|
+
const len = roles.length;
|
|
2552
|
+
const firstId = roles[0]?.RoleID;
|
|
2553
|
+
const lastId = roles[len - 1]?.RoleID;
|
|
2554
|
+
const cached = _userRoleIdSetCache.get(user);
|
|
2555
|
+
if (cached &&
|
|
2556
|
+
cached.rolesRef === roles &&
|
|
2557
|
+
cached.rolesLen === len &&
|
|
2558
|
+
cached.firstRoleId === firstId &&
|
|
2559
|
+
cached.lastRoleId === lastId) {
|
|
2560
|
+
return cached.rolesKey;
|
|
2561
|
+
}
|
|
2562
|
+
getUserRoleIdSet(user);
|
|
2563
|
+
return _userRoleIdSetCache.get(user)?.rolesKey ?? '';
|
|
2483
2564
|
}
|
|
2484
2565
|
const _entityChildEntitiesCache = new WeakMap();
|
|
2485
2566
|
/**
|
|
@@ -2568,15 +2649,38 @@ export class EntityInfo extends BaseInfo {
|
|
|
2568
2649
|
* Parsed SubtypeSelector configuration, if configured.
|
|
2569
2650
|
*/
|
|
2570
2651
|
get SubtypeSelectorConfig() {
|
|
2571
|
-
if (this._subtypeSelectorConfig === undefined) {
|
|
2652
|
+
if (this._subtypeSelectorConfig === undefined || this._subtypeSelectorRaw !== this.SubtypeSelector) {
|
|
2653
|
+
this._subtypeSelectorRaw = this.SubtypeSelector;
|
|
2572
2654
|
if (this.SubtypeSelector && typeof this.SubtypeSelector === 'string') {
|
|
2573
2655
|
try {
|
|
2574
2656
|
const parsed = JSON.parse(this.SubtypeSelector);
|
|
2575
2657
|
if (parsed && typeof parsed['Path'] === 'string' && parsed['Path'].trim().length > 0) {
|
|
2576
|
-
|
|
2658
|
+
const config = {
|
|
2577
2659
|
Path: parsed['Path'].trim(),
|
|
2578
2660
|
UseForLoadedRecords: this.parseSubtypeSelectorUseForLoadedRecords(parsed),
|
|
2579
2661
|
};
|
|
2662
|
+
if (parsed['AutoEnsureOnSave'] !== undefined && parsed['AutoEnsureOnSave'] !== null) {
|
|
2663
|
+
config.AutoEnsureOnSave = this.parseSubtypeSelectorBooleanFlag(parsed, 'AutoEnsureOnSave');
|
|
2664
|
+
}
|
|
2665
|
+
if (parsed['OnSubtypeChange'] !== undefined && parsed['OnSubtypeChange'] !== null) {
|
|
2666
|
+
config.OnSubtypeChange = this.parseSubtypeSelectorChangeBehavior(parsed);
|
|
2667
|
+
}
|
|
2668
|
+
if (parsed['Driver'] !== undefined && parsed['Driver'] !== null) {
|
|
2669
|
+
const driver = this.parseSubtypeSelectorDriver(parsed);
|
|
2670
|
+
if (driver) {
|
|
2671
|
+
config.Driver = driver;
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
if (parsed['FoldIntoForm'] !== undefined && parsed['FoldIntoForm'] !== null) {
|
|
2675
|
+
config.FoldIntoForm = this.parseSubtypeSelectorBooleanFlag(parsed, 'FoldIntoForm');
|
|
2676
|
+
}
|
|
2677
|
+
if (parsed['UIDriver'] !== undefined && parsed['UIDriver'] !== null) {
|
|
2678
|
+
const uiDriver = this.parseSubtypeSelectorUIDriver(parsed);
|
|
2679
|
+
if (uiDriver) {
|
|
2680
|
+
config.UIDriver = uiDriver;
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
this._subtypeSelectorConfig = config;
|
|
2580
2684
|
}
|
|
2581
2685
|
else {
|
|
2582
2686
|
LogError(`EntityInfo '${this.Name}': SubtypeSelector JSON must contain a non-empty 'Path' string property. Found: ${this.SubtypeSelector}`);
|
|
@@ -2607,6 +2711,56 @@ export class EntityInfo extends BaseInfo {
|
|
|
2607
2711
|
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
2712
|
return false;
|
|
2609
2713
|
}
|
|
2714
|
+
parseSubtypeSelectorBooleanFlag(parsed, key) {
|
|
2715
|
+
const value = parsed[key];
|
|
2716
|
+
if (typeof value === 'boolean') {
|
|
2717
|
+
return value;
|
|
2718
|
+
}
|
|
2719
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector '${key}' must be true or false, but is ${JSON.stringify(value)}. Defaulting to false.`);
|
|
2720
|
+
return false;
|
|
2721
|
+
}
|
|
2722
|
+
parseSubtypeSelectorChangeBehavior(parsed) {
|
|
2723
|
+
const value = parsed['OnSubtypeChange'];
|
|
2724
|
+
if (value === 'Refuse' || value === 'Replace') {
|
|
2725
|
+
return value;
|
|
2726
|
+
}
|
|
2727
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'OnSubtypeChange' must be 'Refuse' or 'Replace', but is ${JSON.stringify(value)}. Defaulting to 'Refuse'.`);
|
|
2728
|
+
return 'Refuse';
|
|
2729
|
+
}
|
|
2730
|
+
parseSubtypeSelectorDriver(parsed) {
|
|
2731
|
+
const raw = parsed['Driver'];
|
|
2732
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
2733
|
+
const driverObj = raw;
|
|
2734
|
+
const path = driverObj['Path'];
|
|
2735
|
+
if (typeof path === 'string' && path.trim().length > 0) {
|
|
2736
|
+
const driver = { Path: path.trim() };
|
|
2737
|
+
const baseClass = driverObj['BaseClass'];
|
|
2738
|
+
if (baseClass !== undefined && baseClass !== null) {
|
|
2739
|
+
if (typeof baseClass === 'string' && baseClass.trim().length > 0) {
|
|
2740
|
+
driver.BaseClass = baseClass.trim();
|
|
2741
|
+
}
|
|
2742
|
+
else {
|
|
2743
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'Driver.BaseClass' must be a non-empty string when provided, but is ${JSON.stringify(baseClass)}.`);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
return driver;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'Driver' must be an object with a non-empty 'Path' string, but is ${JSON.stringify(raw)}.`);
|
|
2750
|
+
return null;
|
|
2751
|
+
}
|
|
2752
|
+
parseSubtypeSelectorUIDriver(parsed) {
|
|
2753
|
+
const raw = parsed['UIDriver'];
|
|
2754
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
|
2755
|
+
const uiDriverObj = raw;
|
|
2756
|
+
const path = uiDriverObj['Path'];
|
|
2757
|
+
if (typeof path === 'string' && path.trim().length > 0) {
|
|
2758
|
+
return { Path: path.trim() };
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
LogError(`EntityInfo '${this.Name}': SubtypeSelector 'UIDriver' must be an object with a non-empty 'Path' string, but is ${JSON.stringify(raw)}.`);
|
|
2762
|
+
return null;
|
|
2763
|
+
}
|
|
2610
2764
|
/**
|
|
2611
2765
|
* Whether field-level (column-level) security is enforced for this entity.
|
|
2612
2766
|
*
|
|
@@ -2734,6 +2888,25 @@ export class EntityInfo extends BaseInfo {
|
|
|
2734
2888
|
get CloneConfig() {
|
|
2735
2889
|
return this.ConfigurationObject?.Clone ?? null;
|
|
2736
2890
|
}
|
|
2891
|
+
/**
|
|
2892
|
+
* Effective declarative + programmatic lifecycle policy (state machine, field-freeze, and
|
|
2893
|
+
* `WriteAuthority`) resolved for this entity, or `null` when none is configured.
|
|
2894
|
+
*/
|
|
2895
|
+
get LifecyclePolicy() {
|
|
2896
|
+
return EntityLifecyclePolicyEngine.Instance.ResolvePolicy(this);
|
|
2897
|
+
}
|
|
2898
|
+
/**
|
|
2899
|
+
* Effective declarative + programmatic document auto-numbering policies resolved for this entity.
|
|
2900
|
+
*/
|
|
2901
|
+
get AutoNumberPolicies() {
|
|
2902
|
+
return DocumentNumberingEngine.Instance.ResolvePolicies(this);
|
|
2903
|
+
}
|
|
2904
|
+
/**
|
|
2905
|
+
* Effective declarative cross-entity parent-state lock policies resolved for this entity.
|
|
2906
|
+
*/
|
|
2907
|
+
get CrossEntityPolicies() {
|
|
2908
|
+
return CrossEntityPolicyEngine.Instance.ResolveDeclarativePolicies(this);
|
|
2909
|
+
}
|
|
2737
2910
|
/**
|
|
2738
2911
|
* Controls which columns a save operation (`spCreate` / `spUpdate`) returns from the database
|
|
2739
2912
|
* for this entity. Defaults to `'full'` when `Configuration.SaveReturnMode` is omitted or not
|
|
@@ -2822,6 +2995,36 @@ export class EntityInfo extends BaseInfo {
|
|
|
2822
2995
|
}
|
|
2823
2996
|
return true;
|
|
2824
2997
|
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Returns true when a comment of the specified `MJ: Comment Types` code or name is permitted
|
|
3000
|
+
* on records of this entity according to `Configuration.Comments.AllowedCommentTypes`.
|
|
3001
|
+
*
|
|
3002
|
+
* - Returns `false` whenever {@link AllowRecordComments} is `false`.
|
|
3003
|
+
* - When `AllowedCommentTypes` is omitted, plain comments (`'COMMENT'` / `'Comment'`) are
|
|
3004
|
+
* allowed by default while specialized comment types (such as `'FIELD_SUGGESTION'`) must be
|
|
3005
|
+
* explicitly enabled by the entity.
|
|
3006
|
+
* - When `AllowedCommentTypes` includes `'*'`, every comment type is permitted.
|
|
3007
|
+
*/
|
|
3008
|
+
IsCommentTypeAllowed(codeOrName, alternateName) {
|
|
3009
|
+
if (!this.AllowRecordComments) {
|
|
3010
|
+
return false;
|
|
3011
|
+
}
|
|
3012
|
+
const primary = (codeOrName ?? '').trim().toLowerCase();
|
|
3013
|
+
const secondary = (alternateName ?? '').trim().toLowerCase();
|
|
3014
|
+
if (!primary && !secondary) {
|
|
3015
|
+
return true;
|
|
3016
|
+
}
|
|
3017
|
+
const configured = this.CommentsConfig?.AllowedCommentTypes;
|
|
3018
|
+
if (!Array.isArray(configured)) {
|
|
3019
|
+
return primary === 'comment' || secondary === 'comment';
|
|
3020
|
+
}
|
|
3021
|
+
const allowed = new Set(configured.map((entry) => (entry ?? '').trim().toLowerCase()).filter(Boolean));
|
|
3022
|
+
if (allowed.has('*')) {
|
|
3023
|
+
return true;
|
|
3024
|
+
}
|
|
3025
|
+
return ((primary.length > 0 && allowed.has(primary)) ||
|
|
3026
|
+
(secondary.length > 0 && allowed.has(secondary)));
|
|
3027
|
+
}
|
|
2825
3028
|
/** @deprecated Use {@link HasIdField}. */
|
|
2826
3029
|
get _hasIdField() {
|
|
2827
3030
|
return this.HasIdField;
|
|
@@ -3279,8 +3482,11 @@ export class EntityInfo extends BaseInfo {
|
|
|
3279
3482
|
return this._primaryKeysCache;
|
|
3280
3483
|
}
|
|
3281
3484
|
/**
|
|
3282
|
-
* Returns
|
|
3283
|
-
*
|
|
3485
|
+
* Returns the fields that are unique on their own ({@link EntityFieldInfo.IsUnique}): a
|
|
3486
|
+
* single-column primary key, or the only key column of an unfiltered unique index or
|
|
3487
|
+
* constraint. Columns of a composite unique key are not included; use {@link UniqueKeySets}
|
|
3488
|
+
* or {@link IsUniqueFieldSet} for those.
|
|
3489
|
+
* @returns {EntityFieldInfo[]} Array of fields that are unique on their own
|
|
3284
3490
|
*/
|
|
3285
3491
|
get UniqueKeys() {
|
|
3286
3492
|
if (this._uniqueKeysCache === null) {
|
|
@@ -3431,6 +3637,44 @@ export class EntityInfo extends BaseInfo {
|
|
|
3431
3637
|
get OrganicKeys() {
|
|
3432
3638
|
return this._organicKeys;
|
|
3433
3639
|
}
|
|
3640
|
+
/**
|
|
3641
|
+
* The unique indexes and unique constraints on this entity's base table, each as a set of
|
|
3642
|
+
* columns, sorted by name. Primary keys are not included. Maintained by CodeGen from the
|
|
3643
|
+
* database catalog.
|
|
3644
|
+
* @returns {EntityUniqueKeyInfo[]} Array of unique key definitions
|
|
3645
|
+
*/
|
|
3646
|
+
get UniqueKeySets() {
|
|
3647
|
+
return this._uniqueKeySets;
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* Whether a row is identified by its values in `fieldNames`: true when the names include every
|
|
3651
|
+
* primary key field, a field that is unique on its own ({@link EntityFieldInfo.IsUnique}, which
|
|
3652
|
+
* also covers uniqueness declared by configuration on a view), or every field of an unfiltered
|
|
3653
|
+
* unique key ({@link UniqueKeySets}). Matching is case-insensitive. A filtered key does not
|
|
3654
|
+
* count, since rows outside its filter can repeat its values.
|
|
3655
|
+
*
|
|
3656
|
+
* `IsUniqueFieldSet(['ActionID'])` asks whether that column alone is unique — for a foreign key,
|
|
3657
|
+
* whether the relationship is one-to-one.
|
|
3658
|
+
*/
|
|
3659
|
+
IsUniqueFieldSet(fieldNames) {
|
|
3660
|
+
return EntityInfo.IsUniqueFieldSetOf(this, fieldNames);
|
|
3661
|
+
}
|
|
3662
|
+
/**
|
|
3663
|
+
* {@link IsUniqueFieldSet} over any object carrying an entity's `Fields` and `UniqueKeySets`,
|
|
3664
|
+
* for callers that hold entity metadata in a plain shape. Missing collections count as empty.
|
|
3665
|
+
*/
|
|
3666
|
+
static IsUniqueFieldSetOf(entity, fieldNames) {
|
|
3667
|
+
const names = new Set(fieldNames.map(n => n.trim().toLowerCase()));
|
|
3668
|
+
if (names.size === 0) {
|
|
3669
|
+
return false;
|
|
3670
|
+
}
|
|
3671
|
+
const covers = (keyFields) => keyFields.length > 0 && keyFields.every(f => names.has(f.toLowerCase()));
|
|
3672
|
+
const fields = entity.Fields ?? [];
|
|
3673
|
+
if (covers(fields.filter(f => f.IsPrimaryKey).map(f => f.Name)) || fields.some(f => f.IsUnique && names.has(f.Name.toLowerCase()))) {
|
|
3674
|
+
return true;
|
|
3675
|
+
}
|
|
3676
|
+
return (entity.UniqueKeySets ?? []).some(k => !k.IsFiltered && covers(k.FieldNamesArray));
|
|
3677
|
+
}
|
|
3434
3678
|
/**
|
|
3435
3679
|
* Gets all registered alternate base views for this entity, sorted by `Sequence`, `Name`, and `ID`.
|
|
3436
3680
|
* Alternate base views maintain 100% column parity with {@link BaseView} while applying a
|
|
@@ -3840,12 +4084,43 @@ export class EntityInfo extends BaseInfo {
|
|
|
3840
4084
|
try {
|
|
3841
4085
|
const _ = user.UserRoles; // preserve throw-on-null behavior
|
|
3842
4086
|
const userRoleIds = getUserRoleIdSet(user);
|
|
4087
|
+
const perms = this.Permissions;
|
|
4088
|
+
const permsLen = perms.length;
|
|
4089
|
+
const apiFlags = (this.AllowCreateAPI ? 1 : 0) |
|
|
4090
|
+
(this.AllowUpdateAPI ? 2 : 0) |
|
|
4091
|
+
(this.AllowDeleteAPI ? 4 : 0);
|
|
4092
|
+
let permsStamp = permsLen;
|
|
4093
|
+
for (let k = 0; k < permsLen; k++) {
|
|
4094
|
+
const p = perms[k];
|
|
4095
|
+
const mask = (p.CanCreate ? 1 : 0) |
|
|
4096
|
+
(p.CanRead ? 2 : 0) |
|
|
4097
|
+
(p.CanUpdate ? 4 : 0) |
|
|
4098
|
+
(p.CanDelete ? 8 : 0) |
|
|
4099
|
+
(p.IsDeny ? 16 : 0);
|
|
4100
|
+
permsStamp = ((permsStamp * 31) + mask) | 0;
|
|
4101
|
+
}
|
|
4102
|
+
const firstPermRoleId = permsLen > 0 ? perms[0].RoleID : undefined;
|
|
4103
|
+
const lastPermRoleId = permsLen > 0 ? perms[permsLen - 1].RoleID : undefined;
|
|
4104
|
+
let byUser = _entityUserPermissionsCache.get(this);
|
|
4105
|
+
const cached = byUser?.get(user);
|
|
4106
|
+
if (cached &&
|
|
4107
|
+
cached.generation === _fieldSecurityGeneration &&
|
|
4108
|
+
cached.permissionsRef === perms &&
|
|
4109
|
+
cached.permissionsLen === permsLen &&
|
|
4110
|
+
cached.permissionsStamp === permsStamp &&
|
|
4111
|
+
cached.firstPermRoleId === firstPermRoleId &&
|
|
4112
|
+
cached.lastPermRoleId === lastPermRoleId &&
|
|
4113
|
+
cached.roleIdsRef === userRoleIds &&
|
|
4114
|
+
cached.apiFlags === apiFlags) {
|
|
4115
|
+
return cached.result;
|
|
4116
|
+
}
|
|
3843
4117
|
const allow = { CanCreate: false, CanRead: false, CanUpdate: false, CanDelete: false };
|
|
3844
4118
|
const deny = { CanCreate: false, CanRead: false, CanUpdate: false, CanDelete: false };
|
|
3845
4119
|
if (userRoleIds.size > 0) {
|
|
3846
|
-
for (let j = 0; j <
|
|
3847
|
-
const ep =
|
|
3848
|
-
|
|
4120
|
+
for (let j = 0; j < permsLen; j++) {
|
|
4121
|
+
const ep = perms[j];
|
|
4122
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4123
|
+
if (normRoleId && userRoleIds.has(normRoleId)) {
|
|
3849
4124
|
const bucket = ep.IsDeny ? deny : allow;
|
|
3850
4125
|
bucket.CanCreate = bucket.CanCreate || !!ep.CanCreate;
|
|
3851
4126
|
bucket.CanRead = bucket.CanRead || !!ep.CanRead;
|
|
@@ -3859,12 +4134,27 @@ export class EntityInfo extends BaseInfo {
|
|
|
3859
4134
|
// corresponding API is disabled — so fold the entity-level flag into the result.
|
|
3860
4135
|
// (Read has no `Allow*API` flag; it's governed by the entity view, so it's unchanged.)
|
|
3861
4136
|
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;
|
|
4137
|
+
userPermission.CanCreate = Boolean(this.AllowCreateAPI && allow.CanCreate && !deny.CanCreate);
|
|
4138
|
+
userPermission.CanRead = Boolean(allow.CanRead && !deny.CanRead);
|
|
4139
|
+
userPermission.CanUpdate = Boolean(this.AllowUpdateAPI && allow.CanUpdate && !deny.CanUpdate);
|
|
4140
|
+
userPermission.CanDelete = Boolean(this.AllowDeleteAPI && allow.CanDelete && !deny.CanDelete);
|
|
3866
4141
|
userPermission.Entity = this;
|
|
3867
4142
|
userPermission.User = user;
|
|
4143
|
+
if (!byUser) {
|
|
4144
|
+
byUser = new WeakMap();
|
|
4145
|
+
_entityUserPermissionsCache.set(this, byUser);
|
|
4146
|
+
}
|
|
4147
|
+
byUser.set(user, {
|
|
4148
|
+
generation: _fieldSecurityGeneration,
|
|
4149
|
+
permissionsRef: perms,
|
|
4150
|
+
permissionsLen: permsLen,
|
|
4151
|
+
permissionsStamp: permsStamp,
|
|
4152
|
+
firstPermRoleId,
|
|
4153
|
+
lastPermRoleId,
|
|
4154
|
+
roleIdsRef: userRoleIds,
|
|
4155
|
+
apiFlags,
|
|
4156
|
+
result: userPermission,
|
|
4157
|
+
});
|
|
3868
4158
|
return userPermission;
|
|
3869
4159
|
}
|
|
3870
4160
|
catch (err) {
|
|
@@ -3936,7 +4226,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
3936
4226
|
if (ep.IsDeny) {
|
|
3937
4227
|
continue; // a Deny row's Can* flags are denials, never grants — it cannot exempt anyone
|
|
3938
4228
|
}
|
|
3939
|
-
|
|
4229
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4230
|
+
if (normRoleId && userRoleIds.has(normRoleId)) { // user has this role
|
|
3940
4231
|
switch (type) {
|
|
3941
4232
|
case EntityPermissionType.Create:
|
|
3942
4233
|
if (ep.CanCreate && !ep.CreateRLSFilterID)
|
|
@@ -3988,7 +4279,8 @@ export class EntityInfo extends BaseInfo {
|
|
|
3988
4279
|
if (ep.IsDeny) {
|
|
3989
4280
|
continue; // never a grant — see the doc comment
|
|
3990
4281
|
}
|
|
3991
|
-
|
|
4282
|
+
const normRoleId = ep.NormalizedRoleID;
|
|
4283
|
+
if (normRoleId && userRoleIds.has(normRoleId)) { // user has this role
|
|
3992
4284
|
let matchObject = null;
|
|
3993
4285
|
switch (type) {
|
|
3994
4286
|
case EntityPermissionType.Create:
|
|
@@ -4404,6 +4696,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4404
4696
|
'EntitySettings', '_Settings', 'Settings',
|
|
4405
4697
|
'EntityRelationships', '_RelatedEntities', 'RelatedEntities',
|
|
4406
4698
|
'EntityOrganicKeys', '_OrganicKeys', 'OrganicKeys',
|
|
4699
|
+
'EntityUniqueKeys', '_UniqueKeySets', 'UniqueKeySets',
|
|
4407
4700
|
'EntityAlternateBaseViews', '_AlternateBaseViews', 'AlternateBaseViews',
|
|
4408
4701
|
]); }
|
|
4409
4702
|
/**
|
|
@@ -4528,6 +4821,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4528
4821
|
*/
|
|
4529
4822
|
this.SubtypeSelector = null;
|
|
4530
4823
|
this._subtypeSelectorConfig = undefined;
|
|
4824
|
+
this._subtypeSelectorRaw = undefined;
|
|
4531
4825
|
/**
|
|
4532
4826
|
* Whether to audit when users access records from this entity
|
|
4533
4827
|
*/
|
|
@@ -4854,6 +5148,7 @@ export class EntityInfo extends BaseInfo {
|
|
|
4854
5148
|
this.ParentBaseView = null;
|
|
4855
5149
|
this._fieldCategories = null;
|
|
4856
5150
|
this._organicKeys = [];
|
|
5151
|
+
this._uniqueKeySets = [];
|
|
4857
5152
|
this._alternateBaseViews = [];
|
|
4858
5153
|
this.HasIdField = false;
|
|
4859
5154
|
this.VirtualCount = 0;
|
|
@@ -4975,6 +5270,15 @@ export class EntityInfo extends BaseInfo {
|
|
|
4975
5270
|
this._organicKeys.push(new EntityOrganicKeyInfo(item));
|
|
4976
5271
|
}
|
|
4977
5272
|
}
|
|
5273
|
+
// copy the Unique Key Sets, sorted by name so consumers see a stable order
|
|
5274
|
+
this._uniqueKeySets = [];
|
|
5275
|
+
const uk = initData.EntityUniqueKeys || initData._UniqueKeySets || initData.UniqueKeySets;
|
|
5276
|
+
if (uk && Array.isArray(uk)) {
|
|
5277
|
+
for (const item of uk) {
|
|
5278
|
+
this._uniqueKeySets.push(new EntityUniqueKeyInfo(item));
|
|
5279
|
+
}
|
|
5280
|
+
this._uniqueKeySets.sort((a, b) => ordinalCompare(a.Name, b.Name) || ordinalCompare(a.ID, b.ID));
|
|
5281
|
+
}
|
|
4978
5282
|
// copy the Alternate Base Views (sorted by Sequence, Name, ID, then linked via ParentID)
|
|
4979
5283
|
this._alternateBaseViews = [];
|
|
4980
5284
|
const abv = initData.EntityAlternateBaseViews || initData._AlternateBaseViews || initData.AlternateBaseViews;
|