@expo/entity 0.55.0 → 0.57.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/build/src/AuthorizationResultBasedEntityAssociationLoader.d.ts +1 -1
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityLoader.d.ts +18 -24
- package/build/src/AuthorizationResultBasedEntityLoader.js +37 -56
- package/build/src/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityMutator.js +26 -19
- package/build/src/AuthorizationResultBasedEntityMutator.js.map +1 -1
- package/build/src/EnforcingEntityCreator.d.ts +1 -1
- package/build/src/EnforcingEntityCreator.js +1 -1
- package/build/src/EnforcingEntityLoader.d.ts +1 -58
- package/build/src/EnforcingEntityLoader.js +0 -65
- package/build/src/EnforcingEntityLoader.js.map +1 -1
- package/build/src/Entity.d.ts +6 -0
- package/build/src/Entity.js +6 -0
- package/build/src/Entity.js.map +1 -1
- package/build/src/EntityCompanion.d.ts +2 -2
- package/build/src/EntityCompanion.js.map +1 -1
- package/build/src/EntityCompanionProvider.d.ts +1 -1
- package/build/src/EntityCompanionProvider.js +4 -4
- package/build/src/EntityConfiguration.d.ts +1 -1
- package/build/src/EntityConfiguration.js +1 -2
- package/build/src/EntityConfiguration.js.map +1 -1
- package/build/src/{EntityLoaderUtils.d.ts → EntityConstructionUtils.d.ts} +15 -29
- package/build/src/EntityConstructionUtils.js +118 -0
- package/build/src/EntityConstructionUtils.js.map +1 -0
- package/build/src/EntityDatabaseAdapter.d.ts +10 -108
- package/build/src/EntityDatabaseAdapter.js +14 -76
- package/build/src/EntityDatabaseAdapter.js.map +1 -1
- package/build/src/EntityFieldDefinition.d.ts +1 -1
- package/build/src/EntityInvalidationUtils.d.ts +41 -0
- package/build/src/EntityInvalidationUtils.js +71 -0
- package/build/src/EntityInvalidationUtils.js.map +1 -0
- package/build/src/EntityLoader.d.ts +0 -6
- package/build/src/EntityLoader.js +0 -7
- package/build/src/EntityLoader.js.map +1 -1
- package/build/src/EntityLoaderFactory.d.ts +4 -0
- package/build/src/EntityLoaderFactory.js +10 -3
- package/build/src/EntityLoaderFactory.js.map +1 -1
- package/build/src/EntityPrivacyPolicy.d.ts +27 -0
- package/build/src/EntityPrivacyPolicy.js +22 -1
- package/build/src/EntityPrivacyPolicy.js.map +1 -1
- package/build/src/EntitySecondaryCacheLoader.d.ts +14 -3
- package/build/src/EntitySecondaryCacheLoader.js +21 -4
- package/build/src/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/src/ReadonlyEntity.d.ts +4 -5
- package/build/src/ReadonlyEntity.js +7 -8
- package/build/src/ReadonlyEntity.js.map +1 -1
- package/build/src/ViewerContext.d.ts +6 -6
- package/build/src/ViewerContext.js +8 -8
- package/build/src/ViewerScopedEntityCompanion.d.ts +1 -1
- package/build/src/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/src/ViewerScopedEntityLoaderFactory.d.ts +4 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js +6 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/src/errors/EntityDatabaseAdapterError.d.ts +4 -0
- package/build/src/errors/EntityDatabaseAdapterError.js +13 -1
- package/build/src/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/src/errors/EntityError.d.ts +2 -1
- package/build/src/errors/EntityError.js +1 -0
- package/build/src/errors/EntityError.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/internal/EntityDataManager.d.ts +8 -16
- package/build/src/internal/EntityDataManager.js +8 -18
- package/build/src/internal/EntityDataManager.js.map +1 -1
- package/build/src/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/src/internal/EntityLoadInterfaces.d.ts +2 -0
- package/build/src/internal/EntityLoadInterfaces.js +2 -0
- package/build/src/internal/EntityLoadInterfaces.js.map +1 -1
- package/build/src/internal/EntityTableDataCoordinator.d.ts +2 -0
- package/build/src/internal/EntityTableDataCoordinator.js +4 -0
- package/build/src/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/src/metrics/EntityMetricsUtils.d.ts +1 -0
- package/build/src/metrics/EntityMetricsUtils.js +15 -1
- package/build/src/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/src/metrics/IEntityMetricsAdapter.d.ts +4 -1
- package/build/src/metrics/IEntityMetricsAdapter.js +3 -0
- package/build/src/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/PrivacyPolicyRule.d.ts +2 -2
- package/build/src/utils/EntityPrivacyUtils.js +11 -20
- package/build/src/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/src/utils/collections/maps.d.ts +2 -2
- package/build/src/utils/collections/maps.js +2 -2
- package/package.json +4 -4
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +4 -7
- package/src/AuthorizationResultBasedEntityLoader.ts +58 -88
- package/src/AuthorizationResultBasedEntityMutator.ts +35 -20
- package/src/EnforcingEntityCreator.ts +1 -1
- package/src/EnforcingEntityLoader.ts +1 -95
- package/src/Entity.ts +6 -0
- package/src/EntityCompanion.ts +2 -2
- package/src/EntityCompanionProvider.ts +4 -4
- package/src/EntityConfiguration.ts +8 -5
- package/src/EntityConstructionUtils.ts +168 -0
- package/src/EntityDatabaseAdapter.ts +32 -222
- package/src/EntityFieldDefinition.ts +1 -1
- package/src/{EntityLoaderUtils.ts → EntityInvalidationUtils.ts} +5 -96
- package/src/EntityLoader.ts +0 -16
- package/src/EntityLoaderFactory.ts +50 -10
- package/src/EntityPrivacyPolicy.ts +44 -1
- package/src/EntitySecondaryCacheLoader.ts +54 -3
- package/src/ReadonlyEntity.ts +9 -11
- package/src/ViewerContext.ts +10 -10
- package/src/ViewerScopedEntityCompanion.ts +1 -1
- package/src/ViewerScopedEntityLoaderFactory.ts +37 -0
- package/src/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.ts +3 -5
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +34 -419
- package/src/__tests__/ComposedCacheAdapter-test.ts +3 -3
- package/src/__tests__/EnforcingEntityLoader-test.ts +2 -134
- package/src/__tests__/EntityCompanion-test.ts +18 -0
- package/src/__tests__/EntityConfiguration-test.ts +4 -4
- package/src/__tests__/EntityDatabaseAdapter-test.ts +33 -68
- package/src/__tests__/EntityEdges-test.ts +10 -10
- package/src/__tests__/EntityLoader-test.ts +6 -4
- package/src/__tests__/EntityMutator-test.ts +27 -15
- package/src/__tests__/EntityPrivacyPolicy-test.ts +102 -0
- package/src/__tests__/EntityQueryContext-test.ts +11 -11
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +10 -5
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +6 -6
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +18 -15
- package/src/__tests__/GenericSecondaryEntityCache-test.ts +27 -5
- package/src/__tests__/ReadonlyEntity-test.ts +6 -4
- package/src/__tests__/ViewerContext-test.ts +4 -4
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +1 -0
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +0 -17
- package/src/errors/EntityDatabaseAdapterError.ts +14 -0
- package/src/errors/EntityError.ts +1 -0
- package/src/errors/__tests__/EntityDatabaseAdapterError-test.ts +9 -0
- package/src/errors/__tests__/EntityError-test.ts +13 -5
- package/src/index.ts +2 -1
- package/src/internal/EntityDataManager.ts +19 -54
- package/src/internal/EntityFieldTransformationUtils.ts +5 -5
- package/src/internal/EntityLoadInterfaces.ts +2 -0
- package/src/internal/EntityTableDataCoordinator.ts +2 -2
- package/src/internal/__tests__/CompositeFieldHolder-test.ts +8 -2
- package/src/internal/__tests__/EntityDataManager-test.ts +71 -202
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +39 -24
- package/src/metrics/EntityMetricsUtils.ts +23 -0
- package/src/metrics/IEntityMetricsAdapter.ts +3 -0
- package/src/metrics/__tests__/EntityMetricsUtils-test.ts +120 -0
- package/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.ts +2 -2
- package/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.ts +2 -2
- package/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.ts +2 -2
- package/src/rules/PrivacyPolicyRule.ts +2 -2
- package/src/rules/__tests__/AllowIfAllSubRulesAllowPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfAnySubRuleAllowsPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfInParentCascadeDeletionPrivacyPolicyRule-test.ts +11 -1
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/EvaluateIfEntityFieldPredicatePrivacyPolicyRule-test.ts +3 -3
- package/src/utils/EntityPrivacyUtils.ts +18 -29
- package/src/utils/__testfixtures__/PrivacyPolicyRuleTestUtils.ts +2 -2
- package/src/utils/__testfixtures__/StubDatabaseAdapter.ts +13 -101
- package/src/utils/__tests__/EntityCreationUtils-test.ts +6 -6
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +2 -2
- package/src/utils/collections/maps.ts +2 -2
- package/build/src/EntityLoaderUtils.js +0 -147
- package/build/src/EntityLoaderUtils.js.map +0 -1
|
@@ -3,30 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EntityDatabaseAdapter =
|
|
7
|
-
exports.isSingleValueFieldEqualityCondition = isSingleValueFieldEqualityCondition;
|
|
6
|
+
exports.EntityDatabaseAdapter = void 0;
|
|
8
7
|
const invariant_1 = __importDefault(require("invariant"));
|
|
9
8
|
const EntityDatabaseAdapterError_1 = require("./errors/EntityDatabaseAdapterError");
|
|
10
9
|
const EntityFieldTransformationUtils_1 = require("./internal/EntityFieldTransformationUtils");
|
|
11
|
-
function isSingleValueFieldEqualityCondition(condition) {
|
|
12
|
-
return condition.fieldValue !== undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Ordering options for `orderBy` clauses.
|
|
16
|
-
*/
|
|
17
|
-
var OrderByOrdering;
|
|
18
|
-
(function (OrderByOrdering) {
|
|
19
|
-
/**
|
|
20
|
-
* Ascending order (lowest to highest).
|
|
21
|
-
* Ascending order puts smaller values first, where "smaller" is defined in terms of the %3C operator.
|
|
22
|
-
*/
|
|
23
|
-
OrderByOrdering["ASCENDING"] = "asc";
|
|
24
|
-
/**
|
|
25
|
-
* Descending order (highest to lowest).
|
|
26
|
-
* Descending order puts larger values first, where "larger" is defined in terms of the %3E operator.
|
|
27
|
-
*/
|
|
28
|
-
OrderByOrdering["DESCENDING"] = "desc";
|
|
29
|
-
})(OrderByOrdering || (exports.OrderByOrdering = OrderByOrdering = {}));
|
|
30
10
|
/**
|
|
31
11
|
* A database adapter is an interface by which entity objects can be
|
|
32
12
|
* fetched, inserted, updated, and deleted from a database. This base class
|
|
@@ -67,46 +47,23 @@ class EntityDatabaseAdapter {
|
|
|
67
47
|
return objectMap;
|
|
68
48
|
}
|
|
69
49
|
/**
|
|
70
|
-
* Fetch
|
|
71
|
-
*
|
|
50
|
+
* Fetch one objects where key is equal to value, null if no matching object exists.
|
|
51
|
+
* Returned object is not guaranteed to be deterministic. Most concrete implementations will implement this
|
|
52
|
+
* with a "first" or "limit 1" query.
|
|
72
53
|
*
|
|
73
54
|
* @param queryContext - query context with which to perform the fetch
|
|
74
|
-
* @param
|
|
75
|
-
* @param
|
|
76
|
-
* @returns
|
|
55
|
+
* @param key - load key being queried
|
|
56
|
+
* @param values - load value being queried
|
|
57
|
+
* @returns object that matches the query for the value
|
|
77
58
|
*/
|
|
78
|
-
async
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
tableField: (0, EntityFieldTransformationUtils_1.getDatabaseFieldForEntityField)(this.entityConfiguration, operand.fieldName),
|
|
85
|
-
tableValue: operand.fieldValue,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
tableFieldMultipleValueOperands.push({
|
|
90
|
-
tableField: (0, EntityFieldTransformationUtils_1.getDatabaseFieldForEntityField)(this.entityConfiguration, operand.fieldName),
|
|
91
|
-
tableValues: operand.fieldValues,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
59
|
+
async fetchOneWhereAsync(queryContext, key, value) {
|
|
60
|
+
const keyDatabaseColumns = key.getDatabaseColumns(this.entityConfiguration);
|
|
61
|
+
const valueDatabaseValue = key.getDatabaseValues(value);
|
|
62
|
+
const result = await this.fetchOneWhereInternalAsync(queryContext.getQueryInterface(), this.entityConfiguration.tableName, keyDatabaseColumns, valueDatabaseValue);
|
|
63
|
+
if (!result) {
|
|
64
|
+
return null;
|
|
94
65
|
}
|
|
95
|
-
|
|
96
|
-
return results.map((result) => (0, EntityFieldTransformationUtils_1.transformDatabaseObjectToFields)(this.entityConfiguration, this.fieldTransformerMap, result));
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Fetch many objects matching the raw WHERE clause.
|
|
100
|
-
*
|
|
101
|
-
* @param queryContext - query context with which to perform the fetch
|
|
102
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
103
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
104
|
-
* @param querySelectionModifiers - limit, offset, and orderBy for the query
|
|
105
|
-
* @returns array of objects matching the query
|
|
106
|
-
*/
|
|
107
|
-
async fetchManyByRawWhereClauseAsync(queryContext, rawWhereClause, bindings, querySelectionModifiers) {
|
|
108
|
-
const results = await this.fetchManyByRawWhereClauseInternalAsync(queryContext.getQueryInterface(), this.entityConfiguration.tableName, rawWhereClause, bindings, this.convertToTableQueryModifiersWithOrderByRaw(querySelectionModifiers));
|
|
109
|
-
return results.map((result) => (0, EntityFieldTransformationUtils_1.transformDatabaseObjectToFields)(this.entityConfiguration, this.fieldTransformerMap, result));
|
|
66
|
+
return (0, EntityFieldTransformationUtils_1.transformDatabaseObjectToFields)(this.entityConfiguration, this.fieldTransformerMap, result);
|
|
110
67
|
}
|
|
111
68
|
/**
|
|
112
69
|
* Insert an object.
|
|
@@ -167,25 +124,6 @@ class EntityDatabaseAdapter {
|
|
|
167
124
|
throw new EntityDatabaseAdapterError_1.EntityDatabaseAdapterExcessiveDeleteResultError(`Excessive deletions from database adapter delete: ${this.entityConfiguration.tableName}(id = ${id})`);
|
|
168
125
|
}
|
|
169
126
|
}
|
|
170
|
-
convertToTableQueryModifiersWithOrderByRaw(querySelectionModifiers) {
|
|
171
|
-
return {
|
|
172
|
-
...this.convertToTableQueryModifiers(querySelectionModifiers),
|
|
173
|
-
orderByRaw: querySelectionModifiers.orderByRaw,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
convertToTableQueryModifiers(querySelectionModifiers) {
|
|
177
|
-
const orderBy = querySelectionModifiers.orderBy;
|
|
178
|
-
return {
|
|
179
|
-
orderBy: orderBy !== undefined
|
|
180
|
-
? orderBy.map((orderBySpecification) => ({
|
|
181
|
-
columnName: (0, EntityFieldTransformationUtils_1.getDatabaseFieldForEntityField)(this.entityConfiguration, orderBySpecification.fieldName),
|
|
182
|
-
order: orderBySpecification.order,
|
|
183
|
-
}))
|
|
184
|
-
: undefined,
|
|
185
|
-
offset: querySelectionModifiers.offset,
|
|
186
|
-
limit: querySelectionModifiers.limit,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
127
|
}
|
|
190
128
|
exports.EntityDatabaseAdapter = EntityDatabaseAdapter;
|
|
191
129
|
//# sourceMappingURL=EntityDatabaseAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDatabaseAdapter.js","sourceRoot":"","sources":["../../src/EntityDatabaseAdapter.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"EntityDatabaseAdapter.js","sourceRoot":"","sources":["../../src/EntityDatabaseAdapter.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAIlC,oFAM6C;AAC7C,8FAKmD;AAGnD;;;;;GAKG;AACH,MAAsB,qBAAqB;IAMV;IAFZ,mBAAmB,CAAsB;IAE5D,YAA+B,mBAA2D;QAA3D,wBAAmB,GAAnB,mBAAmB,CAAwC;QACxF,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAC3D,CAAC;IASD;;;;;;;OAOG;IACH,KAAK,CAAC,mBAAmB,CAKvB,YAAgC,EAChC,GAAa,EACb,MAA6B;QAE7B,MAAM,kBAAkB,GAAG,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC5E,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;QAEhF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,2BAA2B,CACpD,YAAY,CAAC,iBAAiB,EAAE,EAChC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAClC,kBAAkB,EAClB,mBAAmB,CACpB,CAAC;QAEF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACrC,IAAA,gEAA+B,EAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAA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by which to load the instance of associatedEntityClass. If not provided, the
|
|
71
71
|
* associatedEntityClass instance is fetched by its ID.
|
|
72
72
|
*/
|
|
73
|
-
associatedEntityLookupByField?:
|
|
73
|
+
associatedEntityLookupByField?: TAssociatedSelectedFields;
|
|
74
74
|
/**
|
|
75
75
|
* What action to perform on the entity at the other end of this edge when the entity on the source end of
|
|
76
76
|
* this edge is deleted.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IEntityClass } from './Entity';
|
|
2
|
+
import { EntityConfiguration } from './EntityConfiguration';
|
|
3
|
+
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
4
|
+
import { EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
5
|
+
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
6
|
+
import { ViewerContext } from './ViewerContext';
|
|
7
|
+
import { EntityDataManager } from './internal/EntityDataManager';
|
|
8
|
+
import { IEntityMetricsAdapter } from './metrics/IEntityMetricsAdapter';
|
|
9
|
+
/**
|
|
10
|
+
* Entity invalidation utilities.
|
|
11
|
+
* Methods are exposed publicly since in rare cases they may need to be called manually.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EntityInvalidationUtils<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
14
|
+
private readonly entityConfiguration;
|
|
15
|
+
private readonly dataManager;
|
|
16
|
+
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
17
|
+
constructor(entityConfiguration: EntityConfiguration<TFields, TIDField>, _entityClass: IEntityClass<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, dataManager: EntityDataManager<TFields, TIDField>, metricsAdapter: IEntityMetricsAdapter);
|
|
18
|
+
private getKeyValuePairsFromObjectFields;
|
|
19
|
+
/**
|
|
20
|
+
* Invalidate all caches and local dataloaders for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
21
|
+
* @param objectFields - entity data object to be invalidated
|
|
22
|
+
*/
|
|
23
|
+
invalidateFieldsAsync(objectFields: Readonly<TFields>): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Invalidate all local dataloaders specific to a transaction for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
26
|
+
* @param objectFields - entity data object to be invalidated
|
|
27
|
+
*/
|
|
28
|
+
invalidateFieldsForTransaction(queryContext: EntityTransactionalQueryContext, objectFields: Readonly<TFields>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Invalidate all caches and local dataloaders for an entity. One potential use case would be to keep the entity
|
|
31
|
+
* framework in sync with changes made to data outside of the framework.
|
|
32
|
+
* @param entity - entity to be invalidated
|
|
33
|
+
*/
|
|
34
|
+
invalidateEntityAsync(entity: TEntity): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Invalidate all local dataloaders specific to a transaction for an entity. One potential use case would be to keep the entity
|
|
37
|
+
* framework in sync with changes made to data outside of the framework.
|
|
38
|
+
* @param entity - entity to be invalidated
|
|
39
|
+
*/
|
|
40
|
+
invalidateEntityForTransaction(queryContext: EntityTransactionalQueryContext, entity: TEntity): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityInvalidationUtils = void 0;
|
|
4
|
+
const SingleFieldHolder_1 = require("./internal/SingleFieldHolder");
|
|
5
|
+
/**
|
|
6
|
+
* Entity invalidation utilities.
|
|
7
|
+
* Methods are exposed publicly since in rare cases they may need to be called manually.
|
|
8
|
+
*/
|
|
9
|
+
class EntityInvalidationUtils {
|
|
10
|
+
entityConfiguration;
|
|
11
|
+
dataManager;
|
|
12
|
+
metricsAdapter;
|
|
13
|
+
constructor(entityConfiguration, _entityClass, dataManager, metricsAdapter) {
|
|
14
|
+
this.entityConfiguration = entityConfiguration;
|
|
15
|
+
this.dataManager = dataManager;
|
|
16
|
+
this.metricsAdapter = metricsAdapter;
|
|
17
|
+
}
|
|
18
|
+
getKeyValuePairsFromObjectFields(objectFields) {
|
|
19
|
+
const keys = Object.keys(objectFields);
|
|
20
|
+
const singleFieldKeyValues = [];
|
|
21
|
+
for (const fieldName of keys) {
|
|
22
|
+
const value = objectFields[fieldName];
|
|
23
|
+
if (value !== undefined && value !== null) {
|
|
24
|
+
singleFieldKeyValues.push([
|
|
25
|
+
new SingleFieldHolder_1.SingleFieldHolder(fieldName),
|
|
26
|
+
new SingleFieldHolder_1.SingleFieldValueHolder(value),
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const compositeFieldKeyValues = [];
|
|
31
|
+
for (const compositeFieldHolder of this.entityConfiguration.compositeFieldInfo.getAllCompositeFieldHolders()) {
|
|
32
|
+
const compositeFieldValueHolder = compositeFieldHolder.extractCompositeFieldValueHolderFromObjectFields(objectFields);
|
|
33
|
+
if (compositeFieldValueHolder) {
|
|
34
|
+
compositeFieldKeyValues.push([compositeFieldHolder, compositeFieldValueHolder]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [...singleFieldKeyValues, ...compositeFieldKeyValues];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Invalidate all caches and local dataloaders for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
41
|
+
* @param objectFields - entity data object to be invalidated
|
|
42
|
+
*/
|
|
43
|
+
async invalidateFieldsAsync(objectFields) {
|
|
44
|
+
await this.dataManager.invalidateKeyValuePairsAsync(this.getKeyValuePairsFromObjectFields(objectFields));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Invalidate all local dataloaders specific to a transaction for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
48
|
+
* @param objectFields - entity data object to be invalidated
|
|
49
|
+
*/
|
|
50
|
+
invalidateFieldsForTransaction(queryContext, objectFields) {
|
|
51
|
+
this.dataManager.invalidateKeyValuePairsForTransaction(queryContext, this.getKeyValuePairsFromObjectFields(objectFields));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Invalidate all caches and local dataloaders for an entity. One potential use case would be to keep the entity
|
|
55
|
+
* framework in sync with changes made to data outside of the framework.
|
|
56
|
+
* @param entity - entity to be invalidated
|
|
57
|
+
*/
|
|
58
|
+
async invalidateEntityAsync(entity) {
|
|
59
|
+
await this.invalidateFieldsAsync(entity.getAllDatabaseFields());
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Invalidate all local dataloaders specific to a transaction for an entity. One potential use case would be to keep the entity
|
|
63
|
+
* framework in sync with changes made to data outside of the framework.
|
|
64
|
+
* @param entity - entity to be invalidated
|
|
65
|
+
*/
|
|
66
|
+
invalidateEntityForTransaction(queryContext, entity) {
|
|
67
|
+
this.invalidateFieldsForTransaction(queryContext, entity.getAllDatabaseFields());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.EntityInvalidationUtils = EntityInvalidationUtils;
|
|
71
|
+
//# sourceMappingURL=EntityInvalidationUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityInvalidationUtils.js","sourceRoot":"","sources":["../../src/EntityInvalidationUtils.ts"],"names":[],"mappings":";;;AAQA,oEAAyF;AAGzF;;;GAGG;AACH,MAAa,uBAAuB;IAef;IASA;IACE;IAXrB,YACmB,mBAA2D,EAC5E,YAOC,EACgB,WAAiD,EAC/C,cAAqC;QAVvC,wBAAmB,GAAnB,mBAAmB,CAAwC;QAS3D,gBAAW,GAAX,WAAW,CAAsC;QAC/C,mBAAc,GAAd,cAAc,CAAuB;IACvD,CAAC;IAEI,gCAAgC,CACtC,YAA+B;QAE/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAsB,CAAC;QAC5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,oBAAoB,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACI,8BAA8B,CACnC,YAA6C,EAC7C,MAAe;QAEf,IAAI,CAAC,8BAA8B,CAAC,YAAY,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACnF,CAAC;CACF;AAnGD,0DAmGC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AuthorizationResultBasedEntityLoader } from './AuthorizationResultBasedEntityLoader';
|
|
2
2
|
import { EnforcingEntityLoader } from './EnforcingEntityLoader';
|
|
3
3
|
import { IEntityClass } from './Entity';
|
|
4
|
-
import { EntityLoaderUtils } from './EntityLoaderUtils';
|
|
5
4
|
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
6
5
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
7
6
|
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
@@ -27,9 +26,4 @@ export declare class EntityLoader<TFields extends Record<string, any>, TIDField
|
|
|
27
26
|
* means an authorization error or entity construction error occurred. Other errors are thrown.
|
|
28
27
|
*/
|
|
29
28
|
withAuthorizationResults(): AuthorizationResultBasedEntityLoader<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
30
|
-
/**
|
|
31
|
-
* Entity loader utilities for things like cache invalidation, entity construction, and authorization.
|
|
32
|
-
* Calling into these should only be necessary in rare cases.
|
|
33
|
-
*/
|
|
34
|
-
utils(): EntityLoaderUtils<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
35
29
|
}
|
|
@@ -34,13 +34,6 @@ class EntityLoader {
|
|
|
34
34
|
.getLoaderFactory()
|
|
35
35
|
.forLoad(this.queryContext, { previousValue: null, cascadingDeleteCause: null });
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Entity loader utilities for things like cache invalidation, entity construction, and authorization.
|
|
39
|
-
* Calling into these should only be necessary in rare cases.
|
|
40
|
-
*/
|
|
41
|
-
utils() {
|
|
42
|
-
return this.withAuthorizationResults().utils;
|
|
43
|
-
}
|
|
44
37
|
}
|
|
45
38
|
exports.EntityLoader = EntityLoader;
|
|
46
39
|
//# sourceMappingURL=EntityLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityLoader.js","sourceRoot":"","sources":["../../src/EntityLoader.ts"],"names":[],"mappings":";;;AACA,mEAAgE;
|
|
1
|
+
{"version":3,"file":"EntityLoader.js","sourceRoot":"","sources":["../../src/EntityLoader.ts"],"names":[],"mappings":";;;AACA,mEAAgE;AAOhE;;;GAGG;AACH,MAAa,YAAY;IAgBJ;IACA;IACA;IAHnB,YACmB,aAA8B,EAC9B,YAAgC,EAChC,WAOhB;QATgB,kBAAa,GAAb,aAAa,CAAiB;QAC9B,iBAAY,GAAZ,YAAY,CAAoB;QAChC,gBAAW,GAAX,WAAW,CAO3B;IACA,CAAC;IAEJ;;;;OAIG;IACH,SAAS;QAQP,OAAO,IAAI,6CAAqB,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC,CAAC;IACpE,CAAC;IAED;;;;OAIG;IACH,wBAAwB;QAQtB,OAAO,IAAI,CAAC,aAAa;aACtB,sCAAsC,CAAC,IAAI,CAAC,WAAW,CAAC;aACxD,gBAAgB,EAAE;aAClB,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;IACrF,CAAC;CACF;AA9DD,oCA8DC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AuthorizationResultBasedEntityLoader } from './AuthorizationResultBasedEntityLoader';
|
|
2
2
|
import { EntityCompanion } from './EntityCompanion';
|
|
3
|
+
import { EntityConstructionUtils } from './EntityConstructionUtils';
|
|
4
|
+
import { EntityInvalidationUtils } from './EntityInvalidationUtils';
|
|
3
5
|
import { EntityPrivacyPolicy, EntityPrivacyPolicyEvaluationContext } from './EntityPrivacyPolicy';
|
|
4
6
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
5
7
|
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
@@ -14,6 +16,8 @@ export declare class EntityLoaderFactory<TFields extends Record<string, any>, TI
|
|
|
14
16
|
private readonly dataManager;
|
|
15
17
|
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
16
18
|
constructor(entityCompanion: EntityCompanion<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, dataManager: EntityDataManager<TFields, TIDField>, metricsAdapter: IEntityMetricsAdapter);
|
|
19
|
+
invalidationUtils(): EntityInvalidationUtils<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
20
|
+
constructionUtils(viewerContext: TViewerContext, queryContext: EntityQueryContext, privacyPolicyEvaluationContext: EntityPrivacyPolicyEvaluationContext<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>): EntityConstructionUtils<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
17
21
|
/**
|
|
18
22
|
* Vend loader for loading an entity in a given query context.
|
|
19
23
|
* @param viewerContext - viewer context of loading user
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityLoaderFactory = void 0;
|
|
4
4
|
const AuthorizationResultBasedEntityLoader_1 = require("./AuthorizationResultBasedEntityLoader");
|
|
5
|
-
const
|
|
5
|
+
const EntityConstructionUtils_1 = require("./EntityConstructionUtils");
|
|
6
|
+
const EntityInvalidationUtils_1 = require("./EntityInvalidationUtils");
|
|
6
7
|
/**
|
|
7
8
|
* The primary entry point for loading entities.
|
|
8
9
|
*/
|
|
@@ -15,14 +16,20 @@ class EntityLoaderFactory {
|
|
|
15
16
|
this.dataManager = dataManager;
|
|
16
17
|
this.metricsAdapter = metricsAdapter;
|
|
17
18
|
}
|
|
19
|
+
invalidationUtils() {
|
|
20
|
+
return new EntityInvalidationUtils_1.EntityInvalidationUtils(this.entityCompanion.entityCompanionDefinition.entityConfiguration, this.entityCompanion.entityCompanionDefinition.entityClass, this.dataManager, this.metricsAdapter);
|
|
21
|
+
}
|
|
22
|
+
constructionUtils(viewerContext, queryContext, privacyPolicyEvaluationContext) {
|
|
23
|
+
return new EntityConstructionUtils_1.EntityConstructionUtils(viewerContext, queryContext, privacyPolicyEvaluationContext, this.entityCompanion.entityCompanionDefinition.entityConfiguration, this.entityCompanion.entityCompanionDefinition.entityClass, this.entityCompanion.entityCompanionDefinition.entitySelectedFields, this.entityCompanion.privacyPolicy, this.metricsAdapter);
|
|
24
|
+
}
|
|
18
25
|
/**
|
|
19
26
|
* Vend loader for loading an entity in a given query context.
|
|
20
27
|
* @param viewerContext - viewer context of loading user
|
|
21
28
|
* @param queryContext - query context in which to perform the load
|
|
22
29
|
*/
|
|
23
30
|
forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext) {
|
|
24
|
-
const
|
|
25
|
-
return new AuthorizationResultBasedEntityLoader_1.AuthorizationResultBasedEntityLoader(queryContext, this.entityCompanion.entityCompanionDefinition.entityConfiguration, this.entityCompanion.entityCompanionDefinition.entityClass, this.dataManager,
|
|
31
|
+
const constructionUtils = this.constructionUtils(viewerContext, queryContext, privacyPolicyEvaluationContext);
|
|
32
|
+
return new AuthorizationResultBasedEntityLoader_1.AuthorizationResultBasedEntityLoader(queryContext, this.entityCompanion.entityCompanionDefinition.entityConfiguration, this.entityCompanion.entityCompanionDefinition.entityClass, this.dataManager, constructionUtils);
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
35
|
exports.EntityLoaderFactory = EntityLoaderFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityLoaderFactory.js","sourceRoot":"","sources":["../../src/EntityLoaderFactory.ts"],"names":[],"mappings":";;;AAAA,iGAA8F;AAE9F,
|
|
1
|
+
{"version":3,"file":"EntityLoaderFactory.js","sourceRoot":"","sources":["../../src/EntityL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F;AA9GD,kDA8GC"}
|
|
@@ -21,6 +21,12 @@ export type EntityPrivacyPolicyEvaluationContext<TFields extends Record<string,
|
|
|
21
21
|
*/
|
|
22
22
|
cascadingDeleteCause: EntityCascadingDeletionInfo | null;
|
|
23
23
|
};
|
|
24
|
+
export type EntityPrivacyPolicyRuleEvaluationContext<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> = EntityPrivacyPolicyEvaluationContext<TFields, TIDField, TViewerContext, TEntity, TSelectedFields> & {
|
|
25
|
+
/**
|
|
26
|
+
* The CRUD action for which the privacy policy rule is being evaluated.
|
|
27
|
+
*/
|
|
28
|
+
action: EntityAuthorizationAction;
|
|
29
|
+
};
|
|
24
30
|
/**
|
|
25
31
|
* Evaluation mode for a EntityPrivacyPolicy. Useful when transitioning to
|
|
26
32
|
* using Entity for privacy.
|
|
@@ -76,14 +82,29 @@ export declare enum EntityAuthorizationAction {
|
|
|
76
82
|
* ```
|
|
77
83
|
*/
|
|
78
84
|
export declare abstract class EntityPrivacyPolicy<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
85
|
+
/**
|
|
86
|
+
* List of rules to evaluate for create authorization.
|
|
87
|
+
*/
|
|
79
88
|
protected readonly createRules: readonly PrivacyPolicyRule<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>[];
|
|
89
|
+
/**
|
|
90
|
+
* List of rules to evaluate for read authorization.
|
|
91
|
+
*/
|
|
80
92
|
protected readonly readRules: readonly PrivacyPolicyRule<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>[];
|
|
93
|
+
/**
|
|
94
|
+
* List of rules to evaluate for update authorization.
|
|
95
|
+
*/
|
|
81
96
|
protected readonly updateRules: readonly PrivacyPolicyRule<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>[];
|
|
97
|
+
/**
|
|
98
|
+
* List of rules to evaluate for delete authorization.
|
|
99
|
+
*/
|
|
82
100
|
protected readonly deleteRules: readonly PrivacyPolicyRule<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>[];
|
|
83
101
|
/**
|
|
84
102
|
* Get the privacy policy evaluation mode and deny handler for this policy.
|
|
85
103
|
* Defaults to normal enforcing policy.
|
|
86
104
|
*
|
|
105
|
+
* DRY_RUN mode is useful for testing and logging the effects of a policy without actually enforcing it, such as when
|
|
106
|
+
* first rolling out a new policy. Entities that fail the policy will be allowed so caution should be take when using.
|
|
107
|
+
*
|
|
87
108
|
* @remarks
|
|
88
109
|
*
|
|
89
110
|
* Override to enable dry run evaluation of the policy.
|
|
@@ -102,7 +123,9 @@ export declare abstract class EntityPrivacyPolicy<TFields extends Record<string,
|
|
|
102
123
|
* Authorize an entity against read policy.
|
|
103
124
|
* @param viewerContext - viewer context of user reading the entity
|
|
104
125
|
* @param queryContext - query context in which to perform the read authorization
|
|
126
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
105
127
|
* @param entity - entity to authorize
|
|
128
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
106
129
|
* @returns entity if authorized
|
|
107
130
|
* @throws EntityNotAuthorizedError when not authorized
|
|
108
131
|
*/
|
|
@@ -111,7 +134,9 @@ export declare abstract class EntityPrivacyPolicy<TFields extends Record<string,
|
|
|
111
134
|
* Authorize an entity against update policy.
|
|
112
135
|
* @param viewerContext - viewer context of user updating the entity
|
|
113
136
|
* @param queryContext - query context in which to perform the update authorization
|
|
137
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
114
138
|
* @param entity - entity to authorize
|
|
139
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
115
140
|
* @returns entity if authorized
|
|
116
141
|
* @throws EntityNotAuthorizedError when not authorized
|
|
117
142
|
*/
|
|
@@ -120,7 +145,9 @@ export declare abstract class EntityPrivacyPolicy<TFields extends Record<string,
|
|
|
120
145
|
* Authorize an entity against deletion policy.
|
|
121
146
|
* @param viewerContext - viewer context of user deleting the entity
|
|
122
147
|
* @param queryContext - query context in which to perform the delete authorization
|
|
148
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
123
149
|
* @param entity - entity to authorize
|
|
150
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
124
151
|
* @returns entity if authorized
|
|
125
152
|
* @throws EntityNotAuthorizedError when not authorized
|
|
126
153
|
*/
|
|
@@ -52,14 +52,29 @@ var EntityAuthorizationAction;
|
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
class EntityPrivacyPolicy {
|
|
55
|
+
/**
|
|
56
|
+
* List of rules to evaluate for create authorization.
|
|
57
|
+
*/
|
|
55
58
|
createRules = [];
|
|
59
|
+
/**
|
|
60
|
+
* List of rules to evaluate for read authorization.
|
|
61
|
+
*/
|
|
56
62
|
readRules = [];
|
|
63
|
+
/**
|
|
64
|
+
* List of rules to evaluate for update authorization.
|
|
65
|
+
*/
|
|
57
66
|
updateRules = [];
|
|
67
|
+
/**
|
|
68
|
+
* List of rules to evaluate for delete authorization.
|
|
69
|
+
*/
|
|
58
70
|
deleteRules = [];
|
|
59
71
|
/**
|
|
60
72
|
* Get the privacy policy evaluation mode and deny handler for this policy.
|
|
61
73
|
* Defaults to normal enforcing policy.
|
|
62
74
|
*
|
|
75
|
+
* DRY_RUN mode is useful for testing and logging the effects of a policy without actually enforcing it, such as when
|
|
76
|
+
* first rolling out a new policy. Entities that fail the policy will be allowed so caution should be take when using.
|
|
77
|
+
*
|
|
63
78
|
* @remarks
|
|
64
79
|
*
|
|
65
80
|
* Override to enable dry run evaluation of the policy.
|
|
@@ -84,7 +99,9 @@ class EntityPrivacyPolicy {
|
|
|
84
99
|
* Authorize an entity against read policy.
|
|
85
100
|
* @param viewerContext - viewer context of user reading the entity
|
|
86
101
|
* @param queryContext - query context in which to perform the read authorization
|
|
102
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
87
103
|
* @param entity - entity to authorize
|
|
104
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
88
105
|
* @returns entity if authorized
|
|
89
106
|
* @throws EntityNotAuthorizedError when not authorized
|
|
90
107
|
*/
|
|
@@ -95,7 +112,9 @@ class EntityPrivacyPolicy {
|
|
|
95
112
|
* Authorize an entity against update policy.
|
|
96
113
|
* @param viewerContext - viewer context of user updating the entity
|
|
97
114
|
* @param queryContext - query context in which to perform the update authorization
|
|
115
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
98
116
|
* @param entity - entity to authorize
|
|
117
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
99
118
|
* @returns entity if authorized
|
|
100
119
|
* @throws EntityNotAuthorizedError when not authorized
|
|
101
120
|
*/
|
|
@@ -106,7 +125,9 @@ class EntityPrivacyPolicy {
|
|
|
106
125
|
* Authorize an entity against deletion policy.
|
|
107
126
|
* @param viewerContext - viewer context of user deleting the entity
|
|
108
127
|
* @param queryContext - query context in which to perform the delete authorization
|
|
128
|
+
* @param evaluationContext - context about the reason for this privacy policy evaluation
|
|
109
129
|
* @param entity - entity to authorize
|
|
130
|
+
* @param metricsAdapter - adapter for logging metrics about this authorization
|
|
110
131
|
* @returns entity if authorized
|
|
111
132
|
* @throws EntityNotAuthorizedError when not authorized
|
|
112
133
|
*/
|
|
@@ -192,7 +213,7 @@ class EntityPrivacyPolicy {
|
|
|
192
213
|
async authorizeForRulesetInnerAsync(ruleset, viewerContext, queryContext, evaluationContext, entity, action) {
|
|
193
214
|
for (let i = 0; i < ruleset.length; i++) {
|
|
194
215
|
const rule = ruleset[i];
|
|
195
|
-
const ruleEvaluationResult = await rule.evaluateAsync(viewerContext, queryContext, evaluationContext, entity);
|
|
216
|
+
const ruleEvaluationResult = await rule.evaluateAsync(viewerContext, queryContext, { ...evaluationContext, action }, entity);
|
|
196
217
|
switch (ruleEvaluationResult) {
|
|
197
218
|
case PrivacyPolicyRule_1.RuleEvaluationResult.DENY:
|
|
198
219
|
throw new EntityNotAuthorizedError_1.EntityNotAuthorizedError(entity, viewerContext, action, i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityPrivacyPolicy.js","sourceRoot":"","sources":["../../src/EntityPrivacyPolicy.ts"],"names":[],"mappings":";;;AAIA,gFAA6E;AAC7E,2EAGyC;AACzC,iEAAoF;
|
|
1
|
+
{"version":3,"file":"EntityPrivacyPolicy.js","sourceRoot":"","sources":["../../src/EntityPrivacyPolicy.ts"],"names":[],"mappings":";;;AAIA,gFAA6E;AAC7E,2EAGyC;AACzC,iEAAoF;AA4CpF;;;GAGG;AACH,IAAY,iCAeX;AAfD,WAAY,iCAAiC;IAC3C;;OAEG;IACH,+FAAO,CAAA;IAEP;;OAEG;IACH,+FAAO,CAAA;IAEP;;OAEG;IACH,+GAAe,CAAA;AACjB,CAAC,EAfW,iCAAiC,iDAAjC,iCAAiC,QAe5C;AAqCD,IAAY,yBAKX;AALD,WAAY,yBAAyB;IACnC,6EAAM,CAAA;IACN,yEAAI,CAAA;IACJ,6EAAM,CAAA;IACN,6EAAM,CAAA;AACR,CAAC,EALW,yBAAyB,yCAAzB,yBAAyB,QAKpC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAsB,mBAAmB;IAOvC;;OAEG;IACgB,WAAW,GAMxB,EAAE,CAAC;IAET;;OAEG;IACgB,SAAS,GAMtB,EAAE,CAAC;IAET;;OAEG;IACgB,WAAW,GAMxB,EAAE,CAAC;IAET;;OAEG;IACgB,WAAW,GAMxB,EAAE,CAAC;IAET;;;;;;;;;;OAUG;IACO,yBAAyB,CACjC,cAA8B;QAE9B,OAAO;YACL,IAAI,EAAE,iCAAiC,CAAC,OAAO;SAChD,CAAC;IACJ,CAAC;IAED;;;;;;;OAO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wBACvD,2BAA2B,EAAE,sBAAsB,CAAC,IAAI;qBACzD,CAAC,CAAC;oBACH,OAAO,MAAM,CAAC;gBAChB,CAAC;QACL,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,6BAA6B,CACzC,OAMG,EACH,aAA6B,EAC7B,YAAgC,EAChC,iBAMC,EACD,MAAe,EACf,MAAiC;QAEjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;YACzB,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,aAAa,CACnD,aAAa,EACb,YAAY,EACZ,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,EAChC,MAAM,CACP,CAAC;YACF,QAAQ,oBAAoB,EAAE,CAAC;gBAC7B,KAAK,wCAAoB,CAAC,IAAI;oBAC5B,MAAM,IAAI,mDAAwB,CAMhC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;gBACtC,KAAK,wCAAoB,CAAC,IAAI;oBAC5B,SAAS;gBACX,KAAK,wCAAoB,CAAC,KAAK;oBAC7B,OAAO,MAAM,CAAC;gBAChB;oBACE,MAAM,IAAI,KAAK,CACb,oDAAoD,MAAM,cAAc,aAAa,cAAc,yBAAyB,CAAC,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAC1J,CAAC;YACN,CAAC;QACH,CAAC;QAED,MAAM,IAAI,mDAAwB,CAChC,MAAM,EACN,aAAa,EACb,MAAM,EACN,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAtXD,kDAsXC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Result } from '@expo/results';
|
|
2
|
-
import {
|
|
2
|
+
import { IEntityClass } from './Entity';
|
|
3
|
+
import { EntityConstructionUtils } from './EntityConstructionUtils';
|
|
3
4
|
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
5
|
+
import { EntityQueryContext } from './EntityQueryContext';
|
|
4
6
|
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
5
7
|
import { ViewerContext } from './ViewerContext';
|
|
6
8
|
/**
|
|
@@ -35,8 +37,8 @@ export interface ISecondaryEntityCache<TFields extends Record<string, any>, TLoa
|
|
|
35
37
|
*/
|
|
36
38
|
export declare abstract class EntitySecondaryCacheLoader<TLoadParams, TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
37
39
|
private readonly secondaryEntityCache;
|
|
38
|
-
|
|
39
|
-
constructor(secondaryEntityCache: ISecondaryEntityCache<TFields, TLoadParams>,
|
|
40
|
+
private readonly constructionUtils;
|
|
41
|
+
constructor(secondaryEntityCache: ISecondaryEntityCache<TFields, TLoadParams>, constructionUtils: EntityConstructionUtils<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>);
|
|
40
42
|
/**
|
|
41
43
|
* Load many by load params objects
|
|
42
44
|
*
|
|
@@ -55,4 +57,13 @@ export declare abstract class EntitySecondaryCacheLoader<TLoadParams, TFields ex
|
|
|
55
57
|
* @param loadParamsArray - array of load params objects to load
|
|
56
58
|
*/
|
|
57
59
|
protected abstract fetchObjectsFromDatabaseAsync(loadParamsArray: readonly Readonly<TLoadParams>[]): Promise<ReadonlyMap<Readonly<Readonly<TLoadParams>>, Readonly<TFields> | null>>;
|
|
60
|
+
/**
|
|
61
|
+
* Helper to get construction utils for instantiating a EntitySecondaryCacheLoader.
|
|
62
|
+
*
|
|
63
|
+
* @param entityClass - the entity class for which to get construction utils for
|
|
64
|
+
* @param viewerContext - the viewer context to use for construction utils
|
|
65
|
+
* @param queryContext - query context to use for construction utils
|
|
66
|
+
* @returns construction utils for the given entity class and viewer context
|
|
67
|
+
*/
|
|
68
|
+
static getConstructionUtilsForEntityClass<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields>(entityClass: IEntityClass<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, viewerContext: TViewerContext, queryContext?: EntityQueryContext): EntityConstructionUtils<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
58
69
|
}
|
|
@@ -15,10 +15,10 @@ const maps_1 = require("./utils/collections/maps");
|
|
|
15
15
|
*/
|
|
16
16
|
class EntitySecondaryCacheLoader {
|
|
17
17
|
secondaryEntityCache;
|
|
18
|
-
|
|
19
|
-
constructor(secondaryEntityCache,
|
|
18
|
+
constructionUtils;
|
|
19
|
+
constructor(secondaryEntityCache, constructionUtils) {
|
|
20
20
|
this.secondaryEntityCache = secondaryEntityCache;
|
|
21
|
-
this.
|
|
21
|
+
this.constructionUtils = constructionUtils;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Load many by load params objects
|
|
@@ -28,7 +28,7 @@ class EntitySecondaryCacheLoader {
|
|
|
28
28
|
async loadManyAsync(loadParamsArray) {
|
|
29
29
|
const loadParamsToFieldObjects = await this.secondaryEntityCache.loadManyThroughAsync(loadParamsArray, this.fetchObjectsFromDatabaseAsync.bind(this));
|
|
30
30
|
// convert value to and from array to reuse complex code
|
|
31
|
-
const entitiesMap = await this.
|
|
31
|
+
const entitiesMap = await this.constructionUtils.constructAndAuthorizeEntitiesAsync((0, maps_1.mapMap)(loadParamsToFieldObjects, (fieldObject) => (fieldObject ? [fieldObject] : [])));
|
|
32
32
|
return (0, maps_1.mapMap)(entitiesMap, (fieldObjects) => fieldObjects[0] ?? null);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -39,6 +39,23 @@ class EntitySecondaryCacheLoader {
|
|
|
39
39
|
async invalidateManyAsync(loadParamsArray) {
|
|
40
40
|
await this.secondaryEntityCache.invalidateManyAsync(loadParamsArray);
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper to get construction utils for instantiating a EntitySecondaryCacheLoader.
|
|
44
|
+
*
|
|
45
|
+
* @param entityClass - the entity class for which to get construction utils for
|
|
46
|
+
* @param viewerContext - the viewer context to use for construction utils
|
|
47
|
+
* @param queryContext - query context to use for construction utils
|
|
48
|
+
* @returns construction utils for the given entity class and viewer context
|
|
49
|
+
*/
|
|
50
|
+
static getConstructionUtilsForEntityClass(entityClass, viewerContext, queryContext = viewerContext
|
|
51
|
+
.getViewerScopedEntityCompanionForClass(entityClass)
|
|
52
|
+
.getQueryContextProvider()
|
|
53
|
+
.getQueryContext()) {
|
|
54
|
+
return viewerContext
|
|
55
|
+
.getViewerScopedEntityCompanionForClass(entityClass)
|
|
56
|
+
.getLoaderFactory()
|
|
57
|
+
.constructionUtils(queryContext, { previousValue: null, cascadingDeleteCause: null });
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
exports.EntitySecondaryCacheLoader = EntitySecondaryCacheLoader;
|
|
44
61
|
//# sourceMappingURL=EntitySecondaryCacheLoader.js.map
|