@expo/entity 0.18.0 → 0.22.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/Entity.js +8 -2
- package/build/Entity.js.map +1 -1
- package/build/EntityCompanion.d.ts +5 -0
- package/build/EntityCompanion.js +8 -1
- package/build/EntityCompanion.js.map +1 -1
- package/build/EntityCompanionProvider.d.ts +1 -1
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityLoader.d.ts +3 -1
- package/build/EntityLoader.js +5 -4
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +3 -1
- package/build/EntityLoaderFactory.js +3 -2
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityMutationInfo.d.ts +26 -0
- package/build/EntityMutationInfo.js +10 -0
- package/build/EntityMutationInfo.js.map +1 -0
- package/build/EntityMutationTriggerConfiguration.d.ts +3 -3
- package/build/EntityMutationValidator.d.ts +2 -2
- package/build/EntityMutationValidator.js.map +1 -1
- package/build/EntityMutator.d.ts +4 -15
- package/build/EntityMutator.js +48 -44
- package/build/EntityMutator.js.map +1 -1
- package/build/EntityPrivacyPolicy.d.ts +5 -4
- package/build/EntityPrivacyPolicy.js +60 -12
- package/build/EntityPrivacyPolicy.js.map +1 -1
- package/build/EntityQueryContext.d.ts +24 -0
- package/build/EntityQueryContext.js +43 -0
- package/build/EntityQueryContext.js.map +1 -1
- package/build/EntityQueryContextProvider.js +1 -0
- package/build/EntityQueryContextProvider.js.map +1 -1
- package/build/ViewerScopedEntityCompanion.d.ts +5 -0
- package/build/ViewerScopedEntityCompanion.js +6 -0
- package/build/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +99 -3
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js +3 -2
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +19 -11
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.d.ts +1 -0
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +81 -0
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -0
- package/build/__tests__/EntityMutator-test.js +16 -14
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +119 -43
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntityQueryContext-test.d.ts +1 -0
- package/build/__tests__/EntityQueryContext-test.js +56 -0
- package/build/__tests__/EntityQueryContext-test.js.map +1 -0
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/metrics/IEntityMetricsAdapter.d.ts +16 -0
- package/build/metrics/IEntityMetricsAdapter.js +6 -1
- package/build/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/metrics/NoOpEntityMetricsAdapter.d.ts +2 -1
- package/build/metrics/NoOpEntityMetricsAdapter.js +1 -0
- package/build/metrics/NoOpEntityMetricsAdapter.js.map +1 -1
- package/package.json +1 -1
- package/src/Entity.ts +10 -2
- package/src/EntityCompanion.ts +10 -2
- package/src/EntityCompanionProvider.ts +1 -1
- package/src/EntityLoader.ts +9 -4
- package/src/EntityLoaderFactory.ts +5 -2
- package/src/EntityMutationInfo.ts +47 -0
- package/src/EntityMutationTriggerConfiguration.ts +3 -3
- package/src/EntityMutationValidator.ts +8 -2
- package/src/EntityMutator.ts +91 -71
- package/src/EntityPrivacyPolicy.ts +76 -18
- package/src/EntityQueryContext.ts +54 -0
- package/src/EntityQueryContextProvider.ts +1 -0
- package/src/ViewerScopedEntityCompanion.ts +8 -0
- package/src/__tests__/EntityEdges-test.ts +163 -9
- package/src/__tests__/EntityLoader-constructor-test.ts +4 -2
- package/src/__tests__/EntityLoader-test.ts +39 -11
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +105 -0
- package/src/__tests__/EntityMutator-test.ts +38 -13
- package/src/__tests__/EntityPrivacyPolicy-test.ts +189 -52
- package/src/__tests__/EntityQueryContext-test.ts +82 -0
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +1 -0
- package/src/index.ts +1 -0
- package/src/metrics/IEntityMetricsAdapter.ts +23 -0
- package/src/metrics/NoOpEntityMetricsAdapter.ts +2 -0
package/build/Entity.js
CHANGED
|
@@ -111,8 +111,11 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
111
111
|
.getViewerScopedEntityCompanionForClass(this)
|
|
112
112
|
.getQueryContextProvider()
|
|
113
113
|
.getQueryContext()) {
|
|
114
|
+
const companion = existingEntity
|
|
115
|
+
.getViewerContext()
|
|
116
|
+
.getViewerScopedEntityCompanionForClass(this);
|
|
114
117
|
const privacyPolicy = new (this.getCompanionDefinition().privacyPolicyClass)();
|
|
115
|
-
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeUpdateAsync(existingEntity.getViewerContext(), queryContext, existingEntity));
|
|
118
|
+
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeUpdateAsync(existingEntity.getViewerContext(), queryContext, existingEntity, companion.getMetricsAdapter()));
|
|
116
119
|
return evaluationResult.ok;
|
|
117
120
|
}
|
|
118
121
|
/**
|
|
@@ -129,8 +132,11 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
129
132
|
.getViewerScopedEntityCompanionForClass(this)
|
|
130
133
|
.getQueryContextProvider()
|
|
131
134
|
.getQueryContext()) {
|
|
135
|
+
const companion = existingEntity
|
|
136
|
+
.getViewerContext()
|
|
137
|
+
.getViewerScopedEntityCompanionForClass(this);
|
|
132
138
|
const privacyPolicy = new (this.getCompanionDefinition().privacyPolicyClass)();
|
|
133
|
-
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeDeleteAsync(existingEntity.getViewerContext(), queryContext, existingEntity));
|
|
139
|
+
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeDeleteAsync(existingEntity.getViewerContext(), queryContext, existingEntity, companion.getMetricsAdapter()));
|
|
134
140
|
return evaluationResult.ok;
|
|
135
141
|
}
|
|
136
142
|
}
|
package/build/Entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":";;;;;AAAA,2CAAoD;AAMpD,sEAA8C;AAG9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAA8B,MAK5B,SAAQ,wBAA6D;IACrE;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAuBZ,aAA+B,EAC/B,eAAmC,aAAa;SAC7C,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,OAAO,aAAa;aACjB,sCAAsC,CAAC,IAAI,CAAC;aAC5C,iBAAiB,EAAE;aACnB,SAAS,CAAC,YAAY,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAsBZ,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,OAAO,cAAc;aAClB,gBAAgB,EAAE;aAClB,sCAAsC,CAAC,IAAI,CAAC;aAC5C,iBAAiB,EAAE;aACnB,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAsBhB,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,OAAO,cAAc;aAClB,gBAAgB,EAAE;aAClB,sCAAsC,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sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,MAAM,SAAS,GAAG,cAAc;aAC7B,gBAAgB,EAAE;aAClB,sCAAsC,CAAC,IAAI,CAAC,CAAC;QAChD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC/E,MAAM,gBAAgB,GAAG,MAAM,IAAA,qBAAW,EACxC,aAAa,CAAC,oBAAoB,CAChC,cAAc,CAAC,gBAAgB,EAAE,EACjC,YAAY,EACZ,cAAc,EACd,SAAS,CAAC,iBAAiB,EAAE,CAC9B,CACF,CAAC;QACF,OAAO,gBAAgB,CAAC,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAsB/B,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,MAAM,SAAS,GAAG,cAAc;aAC7B,gBAAgB,EAAE;aAClB,sCAAsC,CAAC,IAAI,CAAC,CAAC;QAChD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC/E,MAAM,gBAAgB,GAAG,MAAM,IAAA,qBAAW,EACxC,aAAa,CAAC,oBAAoB,CAChC,cAAc,CAAC,gBAAgB,EAAE,EACjC,YAAY,EACZ,cAAc,EACd,SAAS,CAAC,iBAAiB,EAAE,CAC9B,CACF,CAAC;QACF,OAAO,gBAAgB,CAAC,EAAE,CAAC;IAC7B,CAAC;CACF;AA7RD,yBA6RC"}
|
|
@@ -17,6 +17,7 @@ export interface IPrivacyPolicyClass<TPrivacyPolicy> {
|
|
|
17
17
|
*/
|
|
18
18
|
export default class EntityCompanion<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
19
19
|
private readonly tableDataCoordinator;
|
|
20
|
+
private readonly metricsAdapter;
|
|
20
21
|
private readonly entityLoaderFactory;
|
|
21
22
|
private readonly entityMutatorFactory;
|
|
22
23
|
constructor(entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, tableDataCoordinator: EntityTableDataCoordinator<TFields>, PrivacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>, mutationValidators: EntityMutationValidator<TFields, TID, TViewerContext, TEntity, TSelectedFields>[], mutationTriggers: EntityMutationTriggerConfiguration<TFields, TID, TViewerContext, TEntity, TSelectedFields>, metricsAdapter: IEntityMetricsAdapter);
|
|
@@ -26,4 +27,8 @@ export default class EntityCompanion<TFields, TID extends NonNullable<TFields[TS
|
|
|
26
27
|
* Get the query context provider for this entity.
|
|
27
28
|
*/
|
|
28
29
|
getQueryContextProvider(): EntityQueryContextProvider;
|
|
30
|
+
/**
|
|
31
|
+
* Get the {@link IEntityMetricsAdapter} for this companion.
|
|
32
|
+
*/
|
|
33
|
+
getMetricsAdapter(): IEntityMetricsAdapter;
|
|
29
34
|
}
|
package/build/EntityCompanion.js
CHANGED
|
@@ -11,8 +11,9 @@ const EntityMutatorFactory_1 = __importDefault(require("./EntityMutatorFactory")
|
|
|
11
11
|
class EntityCompanion {
|
|
12
12
|
constructor(entityClass, tableDataCoordinator, PrivacyPolicyClass, mutationValidators, mutationTriggers, metricsAdapter) {
|
|
13
13
|
this.tableDataCoordinator = tableDataCoordinator;
|
|
14
|
+
this.metricsAdapter = metricsAdapter;
|
|
14
15
|
const privacyPolicy = new PrivacyPolicyClass();
|
|
15
|
-
this.entityLoaderFactory = new EntityLoaderFactory_1.default(tableDataCoordinator.entityConfiguration, entityClass, privacyPolicy, tableDataCoordinator.dataManager);
|
|
16
|
+
this.entityLoaderFactory = new EntityLoaderFactory_1.default(tableDataCoordinator.entityConfiguration, entityClass, privacyPolicy, tableDataCoordinator.dataManager, metricsAdapter);
|
|
16
17
|
this.entityMutatorFactory = new EntityMutatorFactory_1.default(tableDataCoordinator.entityConfiguration, entityClass, privacyPolicy, mutationValidators, mutationTriggers, this.entityLoaderFactory, tableDataCoordinator.databaseAdapter, metricsAdapter);
|
|
17
18
|
}
|
|
18
19
|
getLoaderFactory() {
|
|
@@ -27,6 +28,12 @@ class EntityCompanion {
|
|
|
27
28
|
getQueryContextProvider() {
|
|
28
29
|
return this.tableDataCoordinator.getQueryContextProvider();
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the {@link IEntityMetricsAdapter} for this companion.
|
|
33
|
+
*/
|
|
34
|
+
getMetricsAdapter() {
|
|
35
|
+
return this.metricsAdapter;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
exports.default = EntityCompanion;
|
|
32
39
|
//# sourceMappingURL=EntityCompanion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../src/EntityCompanion.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AAGxD,kFAA0D;AAY1D;;GAEG;AACH,MAAqB,eAAe;IA+BlC,YACE,WAOC,EACgB,oBAAyD,EAC1E,kBAAuD,EACvD,kBAMG,EACH,gBAMC,
|
|
1
|
+
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../src/EntityCompanion.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AAGxD,kFAA0D;AAY1D;;GAEG;AACH,MAAqB,eAAe;IA+BlC,YACE,WAOC,EACgB,oBAAyD,EAC1E,kBAAuD,EACvD,kBAMG,EACH,gBAMC,EACgB,cAAqC;QAhBrC,yBAAoB,GAApB,oBAAoB,CAAqC;QAgBzD,mBAAc,GAAd,cAAc,CAAuB;QAEtD,MAAM,aAAa,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC/C,IAAI,CAAC,mBAAmB,GAAG,IAAI,6BAAmB,CAQhD,oBAAoB,CAAC,mBAAmB,EACxC,WAAW,EACX,aAAa,EACb,oBAAoB,CAAC,WAAW,EAChC,cAAc,CACf,CAAC;QACF,IAAI,CAAC,oBAAoB,GAAG,IAAI,8BAAoB,CAClD,oBAAoB,CAAC,mBAAmB,EACxC,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,IAAI,CAAC,mBAAmB,EACxB,oBAAoB,CAAC,eAAe,EACpC,cAAc,CACf,CAAC;IACJ,CAAC;IAED,gBAAgB;QAQd,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,iBAAiB;QAQf,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC,uBAAuB,EAAE,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAxHD,kCAwHC"}
|
|
@@ -86,7 +86,7 @@ export declare class EntityCompanionDefinition<TFields, TID extends NonNullable<
|
|
|
86
86
|
* {@link EntityCompanion} for each type of {@link Entity}.
|
|
87
87
|
*/
|
|
88
88
|
export default class EntityCompanionProvider {
|
|
89
|
-
|
|
89
|
+
readonly metricsAdapter: IEntityMetricsAdapter;
|
|
90
90
|
private databaseAdapterFlavors;
|
|
91
91
|
private cacheAdapterFlavors;
|
|
92
92
|
private readonly companionMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCompanionProvider.js","sourceRoot":"","sources":["../src/EntityCompanionProvider.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAGlC,wEAAyE;AAUzE,uGAA+E;AAE/E,mDAA2D;AAgC3D;;;GAGG;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,CAAC;IAEO,gCAAgC,CACtC,mBAAiD,EACjD,eAAuB;QAEvB,OAAO,IAAA,sBAAe,EAAC,IAAI,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,SAAS,EAAE,GAAG,EAAE;YACvF,MAAM,2BAA2B,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CACjE,mBAAmB,CAAC,qBAAqB,CAC1C,CAAC;YACF,IAAA,mBAAS,EACP,2BAA2B,EAC3B,uDAAuD,mBAAmB,CAAC,qBAAqB,EAAE,CACnG,CAAC;YAEF,MAAM,wBAAwB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAC3D,mBAAmB,CAAC,kBAAkB,CACvC,CAAC;YACF,IAAA,mBAAS,EACP,wBAAwB,EACxB,oDAAoD,mBAAmB,CAAC,kBAAkB,EAAE,CAC7F,CAAC;YAEF,OAAO,IAAI,oCAA0B,CACnC,mBAAmB,EACnB,2BAA2B,CAAC,eAAe,EAC3C,wBAAwB,CAAC,oBAAoB,EAC7C,2BAA2B,CAAC,oBAAoB,EAChD,IAAI,CAAC,cAAc,EACnB,eAAe,CAChB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtHD,0CAsHC"}
|
package/build/EntityLoader.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { EntityQueryContext } from './EntityQueryContext';
|
|
|
8
8
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
9
9
|
import ViewerContext from './ViewerContext';
|
|
10
10
|
import EntityDataManager from './internal/EntityDataManager';
|
|
11
|
+
import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
11
12
|
/**
|
|
12
13
|
* The primary interface for loading entities. All normal loads are batched,
|
|
13
14
|
* cached, and authorized against the entity's {@link EntityPrivacyPolicy}.
|
|
@@ -19,7 +20,8 @@ export default class EntityLoader<TFields, TID extends NonNullable<TFields[TSele
|
|
|
19
20
|
private readonly entityClass;
|
|
20
21
|
private readonly privacyPolicy;
|
|
21
22
|
private readonly dataManager;
|
|
22
|
-
|
|
23
|
+
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
24
|
+
constructor(viewerContext: TViewerContext, queryContext: EntityQueryContext, entityConfiguration: EntityConfiguration<TFields>, entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, privacyPolicy: TPrivacyPolicy, dataManager: EntityDataManager<TFields>, metricsAdapter: IEntityMetricsAdapter);
|
|
23
25
|
/**
|
|
24
26
|
* Enforcing view on this entity loader. All loads through this view are
|
|
25
27
|
* guaranteed to be the values of successful results (or null for some loader methods),
|
package/build/EntityLoader.js
CHANGED
|
@@ -15,13 +15,14 @@ const maps_1 = require("./utils/collections/maps");
|
|
|
15
15
|
* cached, and authorized against the entity's {@link EntityPrivacyPolicy}.
|
|
16
16
|
*/
|
|
17
17
|
class EntityLoader {
|
|
18
|
-
constructor(viewerContext, queryContext, entityConfiguration, entityClass, privacyPolicy, dataManager) {
|
|
18
|
+
constructor(viewerContext, queryContext, entityConfiguration, entityClass, privacyPolicy, dataManager, metricsAdapter) {
|
|
19
19
|
this.viewerContext = viewerContext;
|
|
20
20
|
this.queryContext = queryContext;
|
|
21
21
|
this.entityConfiguration = entityConfiguration;
|
|
22
22
|
this.entityClass = entityClass;
|
|
23
23
|
this.privacyPolicy = privacyPolicy;
|
|
24
24
|
this.dataManager = dataManager;
|
|
25
|
+
this.metricsAdapter = metricsAdapter;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Enforcing view on this entity loader. All loads through this view are
|
|
@@ -129,7 +130,7 @@ class EntityLoader {
|
|
|
129
130
|
if (!uncheckedEntityResult.ok) {
|
|
130
131
|
return uncheckedEntityResult;
|
|
131
132
|
}
|
|
132
|
-
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value));
|
|
133
|
+
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value, this.metricsAdapter));
|
|
133
134
|
}));
|
|
134
135
|
}
|
|
135
136
|
/**
|
|
@@ -164,7 +165,7 @@ class EntityLoader {
|
|
|
164
165
|
if (!uncheckedEntityResult.ok) {
|
|
165
166
|
return uncheckedEntityResult;
|
|
166
167
|
}
|
|
167
|
-
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value));
|
|
168
|
+
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value, this.metricsAdapter));
|
|
168
169
|
}));
|
|
169
170
|
}
|
|
170
171
|
/**
|
|
@@ -208,7 +209,7 @@ class EntityLoader {
|
|
|
208
209
|
if (!uncheckedEntityResult.ok) {
|
|
209
210
|
return uncheckedEntityResult;
|
|
210
211
|
}
|
|
211
|
-
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value));
|
|
212
|
+
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, uncheckedEntityResult.value, this.metricsAdapter));
|
|
212
213
|
}));
|
|
213
214
|
});
|
|
214
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityLoader.js","sourceRoot":"","sources":["../src/EntityLoader.ts"],"names":[],"mappings":";;;;;AAAA,2CAA4D;AAC5D,0DAAkC;AAElC,oFAA4D;AAG5D,mEAIiC;AAKjC,yGAAiF;AACjF,uFAA+D;
|
|
1
|
+
{"version":3,"file":"EntityLoader.js","sourceRoot":"","sources":["../src/EntityLoader.ts"],"names":[],"mappings":";;;;;AAAA,2CAA4D;AAC5D,0DAAkC;AAElC,oFAA4D;AAG5D,mEAIiC;AAKjC,yGAAiF;AACjF,uFAA+D;AAG/D,mDAA+D;AAE/D;;;GAGG;AACH,MAAqB,YAAY;IAc/B,YACmB,aAA6B,EAC7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H,CAAC;CACF;AA3UD,+BA2UC"}
|
|
@@ -6,6 +6,7 @@ import { EntityQueryContext } from './EntityQueryContext';
|
|
|
6
6
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
7
7
|
import ViewerContext from './ViewerContext';
|
|
8
8
|
import EntityDataManager from './internal/EntityDataManager';
|
|
9
|
+
import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
9
10
|
/**
|
|
10
11
|
* The primary entry point for loading entities.
|
|
11
12
|
*/
|
|
@@ -14,7 +15,8 @@ export default class EntityLoaderFactory<TFields, TID extends NonNullable<TField
|
|
|
14
15
|
private readonly entityClass;
|
|
15
16
|
private readonly privacyPolicyClass;
|
|
16
17
|
private readonly dataManager;
|
|
17
|
-
|
|
18
|
+
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
19
|
+
constructor(entityConfiguration: EntityConfiguration<TFields>, entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, privacyPolicyClass: TPrivacyPolicy, dataManager: EntityDataManager<TFields>, metricsAdapter: IEntityMetricsAdapter);
|
|
18
20
|
/**
|
|
19
21
|
* Vend loader for loading an entity in a given query context.
|
|
20
22
|
* @param viewerContext - viewer context of loading user
|
|
@@ -8,11 +8,12 @@ const EntityLoader_1 = __importDefault(require("./EntityLoader"));
|
|
|
8
8
|
* The primary entry point for loading entities.
|
|
9
9
|
*/
|
|
10
10
|
class EntityLoaderFactory {
|
|
11
|
-
constructor(entityConfiguration, entityClass, privacyPolicyClass, dataManager) {
|
|
11
|
+
constructor(entityConfiguration, entityClass, privacyPolicyClass, dataManager, metricsAdapter) {
|
|
12
12
|
this.entityConfiguration = entityConfiguration;
|
|
13
13
|
this.entityClass = entityClass;
|
|
14
14
|
this.privacyPolicyClass = privacyPolicyClass;
|
|
15
15
|
this.dataManager = dataManager;
|
|
16
|
+
this.metricsAdapter = metricsAdapter;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Vend loader for loading an entity in a given query context.
|
|
@@ -20,7 +21,7 @@ class EntityLoaderFactory {
|
|
|
20
21
|
* @param queryContext - query context in which to perform the load
|
|
21
22
|
*/
|
|
22
23
|
forLoad(viewerContext, queryContext) {
|
|
23
|
-
return new EntityLoader_1.default(viewerContext, queryContext, this.entityConfiguration, this.entityClass, this.privacyPolicyClass, this.dataManager);
|
|
24
|
+
return new EntityLoader_1.default(viewerContext, queryContext, this.entityConfiguration, this.entityClass, this.privacyPolicyClass, this.dataManager, this.metricsAdapter);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
exports.default = EntityLoaderFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityLoaderFactory.js","sourceRoot":"","sources":["../src/EntityLoaderFactory.ts"],"names":[],"mappings":";;;;;AAEA,kEAA0C;
|
|
1
|
+
{"version":3,"file":"EntityLoaderFactory.js","sourceRoot":"","sources":["../src/EntityLoaderFactory.ts"],"names":[],"mappings":";;;;;AAEA,kEAA0C;AAQ1C;;GAEG;AACH,MAAqB,mBAAmB;IActC,YACmB,mBAAiD,EACjD,WAOhB,EACgB,kBAAkC,EAClC,WAAuC,EACrC,cAAqC;QAXvC,wBAAmB,GAAnB,mBAAmB,CAA8B;QACjD,gBAAW,GAAX,WAAW,CAO3B;QACgB,uBAAkB,GAAlB,kBAAkB,CAAgB;QAClC,gBAAW,GAAX,WAAW,CAA4B;QACrC,mBAAc,GAAd,cAAc,CAAuB;IACvD,CAAC;IAEJ;;;;OAIG;IACH,OAAO,CACL,aAA6B,EAC7B,YAAgC;QAEhC,OAAO,IAAI,sBAAY,CACrB,aAAa,EACb,YAAY,EACZ,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF;AAhDD,sCAgDC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Entity from './Entity';
|
|
2
|
+
import ViewerContext from './ViewerContext';
|
|
3
|
+
export declare enum EntityMutationType {
|
|
4
|
+
CREATE = 0,
|
|
5
|
+
UPDATE = 1,
|
|
6
|
+
DELETE = 2
|
|
7
|
+
}
|
|
8
|
+
export declare type EntityValidatorMutationInfo<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> = {
|
|
9
|
+
type: EntityMutationType.CREATE;
|
|
10
|
+
} | {
|
|
11
|
+
type: EntityMutationType.UPDATE;
|
|
12
|
+
previousValue: TEntity;
|
|
13
|
+
};
|
|
14
|
+
export declare type EntityMutationTriggerDeleteCascadeInfo = {
|
|
15
|
+
entity: Entity<any, any, any, any>;
|
|
16
|
+
cascadingDeleteCause: EntityMutationTriggerDeleteCascadeInfo | null;
|
|
17
|
+
};
|
|
18
|
+
export declare type EntityTriggerMutationInfo<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> = {
|
|
19
|
+
type: EntityMutationType.CREATE;
|
|
20
|
+
} | {
|
|
21
|
+
type: EntityMutationType.UPDATE;
|
|
22
|
+
previousValue: TEntity;
|
|
23
|
+
} | {
|
|
24
|
+
type: EntityMutationType.DELETE;
|
|
25
|
+
cascadingDeleteCause: EntityMutationTriggerDeleteCascadeInfo | null;
|
|
26
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityMutationType = void 0;
|
|
4
|
+
var EntityMutationType;
|
|
5
|
+
(function (EntityMutationType) {
|
|
6
|
+
EntityMutationType[EntityMutationType["CREATE"] = 0] = "CREATE";
|
|
7
|
+
EntityMutationType[EntityMutationType["UPDATE"] = 1] = "UPDATE";
|
|
8
|
+
EntityMutationType[EntityMutationType["DELETE"] = 2] = "DELETE";
|
|
9
|
+
})(EntityMutationType = exports.EntityMutationType || (exports.EntityMutationType = {}));
|
|
10
|
+
//# sourceMappingURL=EntityMutationInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityMutationInfo.js","sourceRoot":"","sources":["../src/EntityMutationInfo.ts"],"names":[],"mappings":";;;AAGA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,+DAAM,CAAA;IACN,+DAAM,CAAA;IACN,+DAAM,CAAA;AACR,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityTriggerMutationInfo } from './EntityMutationInfo';
|
|
2
2
|
import { EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
3
3
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
4
|
import ViewerContext from './ViewerContext';
|
|
@@ -52,12 +52,12 @@ export default interface EntityMutationTriggerConfiguration<TFields, TID extends
|
|
|
52
52
|
* the transaction if a transaction is supplied.
|
|
53
53
|
*/
|
|
54
54
|
export declare abstract class EntityMutationTrigger<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
55
|
-
abstract executeAsync(viewerContext: TViewerContext, queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo:
|
|
55
|
+
abstract executeAsync(viewerContext: TViewerContext, queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* A non-transactional trigger is like a {@link EntityMutationTrigger} but used for afterCommit triggers
|
|
59
59
|
* since they explicitly occur outside of the transaction.
|
|
60
60
|
*/
|
|
61
61
|
export declare abstract class EntityNonTransactionalMutationTrigger<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
62
|
-
abstract executeAsync(viewerContext: TViewerContext, entity: TEntity, mutationInfo:
|
|
62
|
+
abstract executeAsync(viewerContext: TViewerContext, entity: TEntity, mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
63
63
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityValidatorMutationInfo } from './EntityMutationInfo';
|
|
2
2
|
import { EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
3
3
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
4
|
import ViewerContext from './ViewerContext';
|
|
@@ -7,5 +7,5 @@ import ViewerContext from './ViewerContext';
|
|
|
7
7
|
* same transaction as the mutation itself before creating or updating an entity.
|
|
8
8
|
*/
|
|
9
9
|
export default abstract class EntityMutationValidator<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
10
|
-
abstract executeAsync(viewerContext: TViewerContext, queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo:
|
|
10
|
+
abstract executeAsync(viewerContext: TViewerContext, queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo: EntityValidatorMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityMutationValidator.js","sourceRoot":"","sources":["../src/EntityMutationValidator.ts"],"names":[],"mappings":";;AAKA;;;GAGG;AACH,MAA8B,uBAAuB;
|
|
1
|
+
{"version":3,"file":"EntityMutationValidator.js","sourceRoot":"","sources":["../src/EntityMutationValidator.ts"],"names":[],"mappings":";;AAKA;;;GAGG;AACH,MAA8B,uBAAuB;CAmBpD;AAnBD,0CAmBC"}
|
package/build/EntityMutator.d.ts
CHANGED
|
@@ -3,25 +3,13 @@ import Entity, { IEntityClass } from './Entity';
|
|
|
3
3
|
import EntityConfiguration from './EntityConfiguration';
|
|
4
4
|
import EntityDatabaseAdapter from './EntityDatabaseAdapter';
|
|
5
5
|
import EntityLoaderFactory from './EntityLoaderFactory';
|
|
6
|
+
import { EntityValidatorMutationInfo, EntityTriggerMutationInfo } from './EntityMutationInfo';
|
|
6
7
|
import EntityMutationTriggerConfiguration, { EntityMutationTrigger, EntityNonTransactionalMutationTrigger } from './EntityMutationTriggerConfiguration';
|
|
7
8
|
import EntityMutationValidator from './EntityMutationValidator';
|
|
8
9
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
9
10
|
import { EntityQueryContext, EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
10
11
|
import ViewerContext from './ViewerContext';
|
|
11
12
|
import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
12
|
-
export declare enum EntityMutationType {
|
|
13
|
-
CREATE = 0,
|
|
14
|
-
UPDATE = 1,
|
|
15
|
-
DELETE = 2
|
|
16
|
-
}
|
|
17
|
-
export declare type EntityMutationInfo<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> = {
|
|
18
|
-
type: EntityMutationType.CREATE;
|
|
19
|
-
} | {
|
|
20
|
-
type: EntityMutationType.UPDATE;
|
|
21
|
-
previousValue: TEntity;
|
|
22
|
-
} | {
|
|
23
|
-
type: EntityMutationType.DELETE;
|
|
24
|
-
};
|
|
25
13
|
declare abstract class BaseMutator<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
26
14
|
protected readonly viewerContext: TViewerContext;
|
|
27
15
|
protected readonly queryContext: EntityQueryContext;
|
|
@@ -35,8 +23,9 @@ declare abstract class BaseMutator<TFields, TID extends NonNullable<TFields[TSel
|
|
|
35
23
|
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
36
24
|
constructor(viewerContext: TViewerContext, queryContext: EntityQueryContext, entityConfiguration: EntityConfiguration<TFields>, entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, privacyPolicy: TPrivacyPolicy, mutationValidators: EntityMutationValidator<TFields, TID, TViewerContext, TEntity, TSelectedFields>[], mutationTriggers: EntityMutationTriggerConfiguration<TFields, TID, TViewerContext, TEntity, TSelectedFields>, entityLoaderFactory: EntityLoaderFactory<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, databaseAdapter: EntityDatabaseAdapter<TFields>, metricsAdapter: IEntityMetricsAdapter);
|
|
37
25
|
protected validateFields(fields: Partial<TFields>): void;
|
|
38
|
-
protected
|
|
39
|
-
protected
|
|
26
|
+
protected executeMutationValidatorsAsync(validators: EntityMutationValidator<TFields, TID, TViewerContext, TEntity, TSelectedFields>[], queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo: EntityValidatorMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
27
|
+
protected executeMutationTriggersAsync(triggers: EntityMutationTrigger<TFields, TID, TViewerContext, TEntity, TSelectedFields>[] | undefined, queryContext: EntityTransactionalQueryContext, entity: TEntity, mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
28
|
+
protected executeNonTransactionalMutationTriggersAsync(triggers: EntityNonTransactionalMutationTrigger<TFields, TID, TViewerContext, TEntity, TSelectedFields>[] | undefined, entity: TEntity, mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>): Promise<void>;
|
|
40
29
|
}
|
|
41
30
|
/**
|
|
42
31
|
* Mutator for creating a new entity.
|
package/build/EntityMutator.js
CHANGED
|
@@ -3,20 +3,15 @@ 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.DeleteMutator = exports.UpdateMutator = exports.CreateMutator =
|
|
6
|
+
exports.DeleteMutator = exports.UpdateMutator = exports.CreateMutator = void 0;
|
|
7
7
|
const results_1 = require("@expo/results");
|
|
8
8
|
const invariant_1 = __importDefault(require("invariant"));
|
|
9
9
|
const EntityFieldDefinition_1 = require("./EntityFieldDefinition");
|
|
10
|
+
const EntityMutationInfo_1 = require("./EntityMutationInfo");
|
|
10
11
|
const EntityInvalidFieldValueError_1 = __importDefault(require("./errors/EntityInvalidFieldValueError"));
|
|
11
12
|
const EntityMetricsUtils_1 = require("./metrics/EntityMetricsUtils");
|
|
12
13
|
const IEntityMetricsAdapter_1 = require("./metrics/IEntityMetricsAdapter");
|
|
13
14
|
const maps_1 = require("./utils/collections/maps");
|
|
14
|
-
var EntityMutationType;
|
|
15
|
-
(function (EntityMutationType) {
|
|
16
|
-
EntityMutationType[EntityMutationType["CREATE"] = 0] = "CREATE";
|
|
17
|
-
EntityMutationType[EntityMutationType["UPDATE"] = 1] = "UPDATE";
|
|
18
|
-
EntityMutationType[EntityMutationType["DELETE"] = 2] = "DELETE";
|
|
19
|
-
})(EntityMutationType = exports.EntityMutationType || (exports.EntityMutationType = {}));
|
|
20
15
|
class BaseMutator {
|
|
21
16
|
constructor(viewerContext, queryContext, entityConfiguration, entityClass, privacyPolicy, mutationValidators, mutationTriggers, entityLoaderFactory, databaseAdapter, metricsAdapter) {
|
|
22
17
|
this.viewerContext = viewerContext;
|
|
@@ -41,13 +36,16 @@ class BaseMutator {
|
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
|
-
async
|
|
45
|
-
|
|
39
|
+
async executeMutationValidatorsAsync(validators, queryContext, entity, mutationInfo) {
|
|
40
|
+
await Promise.all(validators.map((validator) => validator.executeAsync(this.viewerContext, queryContext, entity, mutationInfo)));
|
|
41
|
+
}
|
|
42
|
+
async executeMutationTriggersAsync(triggers, queryContext, entity, mutationInfo) {
|
|
43
|
+
if (!triggers) {
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
48
|
-
await Promise.all(
|
|
46
|
+
await Promise.all(triggers.map((trigger) => trigger.executeAsync(this.viewerContext, queryContext, entity, mutationInfo)));
|
|
49
47
|
}
|
|
50
|
-
async
|
|
48
|
+
async executeNonTransactionalMutationTriggersAsync(triggers, entity, mutationInfo) {
|
|
51
49
|
if (!triggers) {
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
@@ -94,23 +92,23 @@ class CreateMutator extends BaseMutator {
|
|
|
94
92
|
[this.entityConfiguration.idField]: '00000000-0000-0000-0000-000000000000',
|
|
95
93
|
...this.fieldsForEntity,
|
|
96
94
|
});
|
|
97
|
-
const authorizeCreateResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeCreateAsync(this.viewerContext, queryContext, temporaryEntityForPrivacyCheck));
|
|
95
|
+
const authorizeCreateResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeCreateAsync(this.viewerContext, queryContext, temporaryEntityForPrivacyCheck, this.metricsAdapter));
|
|
98
96
|
if (!authorizeCreateResult.ok) {
|
|
99
97
|
return authorizeCreateResult;
|
|
100
98
|
}
|
|
101
|
-
await this.
|
|
102
|
-
await this.
|
|
103
|
-
await this.
|
|
99
|
+
await this.executeMutationValidatorsAsync(this.mutationValidators, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
100
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
101
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeCreate, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
104
102
|
const insertResult = await this.databaseAdapter.insertAsync(queryContext, this.fieldsForEntity);
|
|
105
103
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext);
|
|
106
|
-
queryContext.
|
|
104
|
+
queryContext.appendPostCommitInvalidationCallback(entityLoader.invalidateFieldsAsync.bind(entityLoader, insertResult));
|
|
107
105
|
const unauthorizedEntityAfterInsert = new this.entityClass(this.viewerContext, insertResult);
|
|
108
106
|
const newEntity = await entityLoader
|
|
109
107
|
.enforcing()
|
|
110
108
|
.loadByIDAsync(unauthorizedEntityAfterInsert.getID());
|
|
111
|
-
await this.
|
|
112
|
-
await this.
|
|
113
|
-
queryContext.appendPostCommitCallback(this.
|
|
109
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterCreate, queryContext, newEntity, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
110
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, newEntity, { type: EntityMutationInfo_1.EntityMutationType.CREATE });
|
|
111
|
+
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, newEntity, { type: EntityMutationInfo_1.EntityMutationType.CREATE }));
|
|
114
112
|
return (0, results_1.result)(newEntity);
|
|
115
113
|
}
|
|
116
114
|
}
|
|
@@ -156,24 +154,24 @@ class UpdateMutator extends BaseMutator {
|
|
|
156
154
|
async updateInternalAsync(queryContext) {
|
|
157
155
|
this.validateFields(this.updatedFields);
|
|
158
156
|
const entityAboutToBeUpdated = new this.entityClass(this.viewerContext, this.fieldsForEntity);
|
|
159
|
-
const authorizeUpdateResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeUpdateAsync(this.viewerContext, queryContext, entityAboutToBeUpdated));
|
|
157
|
+
const authorizeUpdateResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeUpdateAsync(this.viewerContext, queryContext, entityAboutToBeUpdated, this.metricsAdapter));
|
|
160
158
|
if (!authorizeUpdateResult.ok) {
|
|
161
159
|
return authorizeUpdateResult;
|
|
162
160
|
}
|
|
163
|
-
await this.
|
|
164
|
-
await this.
|
|
165
|
-
await this.
|
|
161
|
+
await this.executeMutationValidatorsAsync(this.mutationValidators, queryContext, entityAboutToBeUpdated, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity });
|
|
162
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, entityAboutToBeUpdated, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity });
|
|
163
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeUpdate, queryContext, entityAboutToBeUpdated, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity });
|
|
166
164
|
const updateResult = await this.databaseAdapter.updateAsync(queryContext, this.entityConfiguration.idField, entityAboutToBeUpdated.getID(), this.updatedFields);
|
|
167
165
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext);
|
|
168
|
-
queryContext.
|
|
169
|
-
queryContext.
|
|
166
|
+
queryContext.appendPostCommitInvalidationCallback(entityLoader.invalidateFieldsAsync.bind(entityLoader, this.originalEntity.getAllDatabaseFields()));
|
|
167
|
+
queryContext.appendPostCommitInvalidationCallback(entityLoader.invalidateFieldsAsync.bind(entityLoader, this.fieldsForEntity));
|
|
170
168
|
const unauthorizedEntityAfterUpdate = new this.entityClass(this.viewerContext, updateResult);
|
|
171
169
|
const updatedEntity = await entityLoader
|
|
172
170
|
.enforcing()
|
|
173
171
|
.loadByIDAsync(unauthorizedEntityAfterUpdate.getID());
|
|
174
|
-
await this.
|
|
175
|
-
await this.
|
|
176
|
-
queryContext.appendPostCommitCallback(this.
|
|
172
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterUpdate, queryContext, updatedEntity, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity });
|
|
173
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, updatedEntity, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity });
|
|
174
|
+
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, updatedEntity, { type: EntityMutationInfo_1.EntityMutationType.UPDATE, previousValue: this.originalEntity }));
|
|
177
175
|
return (0, results_1.result)(updatedEntity);
|
|
178
176
|
}
|
|
179
177
|
}
|
|
@@ -191,7 +189,7 @@ class DeleteMutator extends BaseMutator {
|
|
|
191
189
|
* @returns void result, where result error can be UnauthorizedError
|
|
192
190
|
*/
|
|
193
191
|
async deleteAsync() {
|
|
194
|
-
return await (0, EntityMetricsUtils_1.timeAndLogMutationEventAsync)(this.metricsAdapter, IEntityMetricsAdapter_1.EntityMetricsMutationType.DELETE, this.entityClass.name)(this.deleteInTransactionAsync());
|
|
192
|
+
return await (0, EntityMetricsUtils_1.timeAndLogMutationEventAsync)(this.metricsAdapter, IEntityMetricsAdapter_1.EntityMetricsMutationType.DELETE, this.entityClass.name)(this.deleteInTransactionAsync(new Set(), false, null));
|
|
195
193
|
}
|
|
196
194
|
/**
|
|
197
195
|
* Convenience method that throws upon delete failure.
|
|
@@ -199,25 +197,25 @@ class DeleteMutator extends BaseMutator {
|
|
|
199
197
|
async enforceDeleteAsync() {
|
|
200
198
|
return await (0, results_1.enforceAsyncResult)(this.deleteAsync());
|
|
201
199
|
}
|
|
202
|
-
async deleteInTransactionAsync(processedEntityIdentifiersFromTransitiveDeletions
|
|
203
|
-
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) => this.deleteInternalAsync(innerQueryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion));
|
|
200
|
+
async deleteInTransactionAsync(processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion, cascadingDeleteCause) {
|
|
201
|
+
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) => this.deleteInternalAsync(innerQueryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion, cascadingDeleteCause));
|
|
204
202
|
}
|
|
205
|
-
async deleteInternalAsync(queryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion) {
|
|
206
|
-
const authorizeDeleteResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeDeleteAsync(this.viewerContext, queryContext, this.entity));
|
|
203
|
+
async deleteInternalAsync(queryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion, cascadingDeleteCause) {
|
|
204
|
+
const authorizeDeleteResult = await (0, results_1.asyncResult)(this.privacyPolicy.authorizeDeleteAsync(this.viewerContext, queryContext, this.entity, this.metricsAdapter));
|
|
207
205
|
if (!authorizeDeleteResult.ok) {
|
|
208
206
|
return authorizeDeleteResult;
|
|
209
207
|
}
|
|
210
|
-
await this.processEntityDeletionForInboundEdgesAsync(this.entity, queryContext, processedEntityIdentifiersFromTransitiveDeletions);
|
|
211
|
-
await this.
|
|
212
|
-
await this.
|
|
208
|
+
await this.processEntityDeletionForInboundEdgesAsync(this.entity, queryContext, processedEntityIdentifiersFromTransitiveDeletions, cascadingDeleteCause);
|
|
209
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, this.entity, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause });
|
|
210
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeDelete, queryContext, this.entity, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause });
|
|
213
211
|
if (!skipDatabaseDeletion) {
|
|
214
212
|
await this.databaseAdapter.deleteAsync(queryContext, this.entityConfiguration.idField, this.entity.getID());
|
|
215
213
|
}
|
|
216
214
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext);
|
|
217
|
-
queryContext.
|
|
218
|
-
await this.
|
|
219
|
-
await this.
|
|
220
|
-
queryContext.appendPostCommitCallback(this.
|
|
215
|
+
queryContext.appendPostCommitInvalidationCallback(entityLoader.invalidateFieldsAsync.bind(entityLoader, this.entity.getAllDatabaseFields()));
|
|
216
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterDelete, queryContext, this.entity, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause });
|
|
217
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, this.entity, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause });
|
|
218
|
+
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, this.entity, { type: EntityMutationInfo_1.EntityMutationType.DELETE, cascadingDeleteCause }));
|
|
221
219
|
return (0, results_1.result)();
|
|
222
220
|
}
|
|
223
221
|
/**
|
|
@@ -234,7 +232,7 @@ class DeleteMutator extends BaseMutator {
|
|
|
234
232
|
*
|
|
235
233
|
* @param entity - entity to find all references to
|
|
236
234
|
*/
|
|
237
|
-
async processEntityDeletionForInboundEdgesAsync(entity, queryContext, processedEntityIdentifiers) {
|
|
235
|
+
async processEntityDeletionForInboundEdgesAsync(entity, queryContext, processedEntityIdentifiers, cascadingDeleteCause) {
|
|
238
236
|
// prevent infinite reference cycles by keeping track of entities already processed
|
|
239
237
|
if (processedEntityIdentifiers.has(entity.getUniqueIdentifier())) {
|
|
240
238
|
return;
|
|
@@ -283,8 +281,11 @@ class DeleteMutator extends BaseMutator {
|
|
|
283
281
|
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => mutatorFactory
|
|
284
282
|
.forDelete(inboundReferenceEntity, queryContext)
|
|
285
283
|
.deleteInTransactionAsync(processedEntityIdentifiers,
|
|
286
|
-
/* skipDatabaseDeletion */ true // deletion is handled by DB
|
|
287
|
-
|
|
284
|
+
/* skipDatabaseDeletion */ true, // deletion is handled by DB
|
|
285
|
+
{
|
|
286
|
+
entity,
|
|
287
|
+
cascadingDeleteCause,
|
|
288
|
+
})));
|
|
288
289
|
break;
|
|
289
290
|
}
|
|
290
291
|
case EntityFieldDefinition_1.EntityEdgeDeletionBehavior.SET_NULL: {
|
|
@@ -298,7 +299,10 @@ class DeleteMutator extends BaseMutator {
|
|
|
298
299
|
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => mutatorFactory
|
|
299
300
|
.forDelete(inboundReferenceEntity, queryContext)
|
|
300
301
|
.deleteInTransactionAsync(processedEntityIdentifiers,
|
|
301
|
-
/* skipDatabaseDeletion */ false
|
|
302
|
+
/* skipDatabaseDeletion */ false, {
|
|
303
|
+
entity,
|
|
304
|
+
cascadingDeleteCause,
|
|
305
|
+
})));
|
|
302
306
|
}
|
|
303
307
|
}
|
|
304
308
|
});
|