@expo/entity 0.17.0 → 0.21.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/EnforcingEntityLoader.js +2 -2
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.js +8 -2
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.js +3 -3
- package/build/EntityAssociationLoader.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 +5 -5
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityConfiguration.d.ts +1 -1
- package/build/EntityConfiguration.js +3 -3
- package/build/EntityConfiguration.js.map +1 -1
- package/build/EntityDatabaseAdapter.d.ts +4 -4
- package/build/EntityDatabaseAdapter.js +13 -13
- package/build/EntityDatabaseAdapter.js.map +1 -1
- package/build/EntityFieldDefinition.d.ts +77 -0
- package/build/EntityFieldDefinition.js +53 -0
- package/build/EntityFieldDefinition.js.map +1 -0
- package/build/EntityFields.d.ts +1 -77
- package/build/EntityFields.js +13 -61
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +3 -1
- package/build/EntityLoader.js +19 -15
- 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 +4 -4
- package/build/EntityMutationValidator.d.ts +3 -3
- package/build/EntityMutationValidator.js.map +1 -1
- package/build/EntityMutator.d.ts +5 -16
- package/build/EntityMutator.js +62 -58
- 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/EntitySecondaryCacheLoader.js +2 -2
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/ReadonlyEntity.js +3 -4
- package/build/ReadonlyEntity.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__/EnforcingEntityLoader-test.js +82 -82
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +6 -6
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +40 -40
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +11 -11
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +3 -3
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityCompanionProvider-test.js +1 -1
- package/build/__tests__/EntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/EntityDatabaseAdapter-test.js +12 -12
- package/build/__tests__/EntityDatabaseAdapter-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +103 -6
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +18 -27
- package/build/__tests__/EntityFields-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.d.ts +22 -0
- package/build/__tests__/EntityLoader-constructor-test.js +111 -0
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -0
- package/build/__tests__/EntityLoader-test.js +72 -64
- 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 +116 -114
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +143 -67
- 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 +15 -15
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +13 -12
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +11 -11
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/ViewerContext-test.js +2 -2
- package/build/__tests__/ViewerContext-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityCompanion-test.js +2 -2
- package/build/__tests__/ViewerScopedEntityCompanion-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js +2 -2
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js +5 -5
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js +5 -5
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +5 -5
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +2 -2
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/__tests__/entityUtils-test.js +21 -21
- package/build/__tests__/entityUtils-test.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/build/internal/EntityDataManager.js +8 -7
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/EntityFieldTransformationUtils.js +2 -2
- package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/internal/ReadThroughEntityCache.js +4 -4
- package/build/internal/ReadThroughEntityCache.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +17 -17
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js +8 -8
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +48 -48
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/metrics/EntityMetricsUtils.js +1 -1
- package/build/metrics/EntityMetricsUtils.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/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js +4 -4
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js.map +1 -1
- package/build/testfixtures/DateIDTestEntity.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.d.ts +5 -5
- package/build/testfixtures/TestEntity.js +2 -2
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.d.ts +5 -5
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestEntityNumberKey.js.map +1 -1
- package/build/utils/collections/__tests__/maps-test.js +13 -13
- package/build/utils/collections/__tests__/maps-test.js.map +1 -1
- package/build/utils/collections/maps.js +1 -1
- package/build/utils/collections/maps.js.map +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +6 -6
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js.map +1 -1
- package/build/utils/testing/StubCacheAdapter.js +1 -1
- package/build/utils/testing/StubCacheAdapter.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapter.js +6 -6
- package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js +9 -9
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js.map +1 -1
- package/build/utils/testing/describeFieldTestCase.d.ts +2 -0
- package/build/utils/testing/describeFieldTestCase.js +18 -0
- package/build/utils/testing/describeFieldTestCase.js.map +1 -0
- package/package.json +2 -1
- package/src/Entity.ts +10 -2
- package/src/EntityAssociationLoader.ts +1 -1
- package/src/EntityCompanion.ts +10 -2
- package/src/EntityCompanionProvider.ts +5 -9
- package/src/EntityConfiguration.ts +1 -1
- package/src/EntityDatabaseAdapter.ts +10 -8
- package/src/EntityFieldDefinition.ts +124 -0
- package/src/EntityFields.ts +2 -125
- package/src/EntityLoader.ts +12 -4
- package/src/EntityLoaderFactory.ts +5 -2
- package/src/EntityMutationInfo.ts +47 -0
- package/src/EntityMutationTriggerConfiguration.ts +5 -5
- package/src/EntityMutationValidator.ts +10 -4
- package/src/EntityMutator.ts +98 -76
- package/src/EntityPrivacyPolicy.ts +77 -19
- package/src/EntityQueryContext.ts +54 -0
- package/src/EntityQueryContextProvider.ts +1 -0
- package/src/ReadonlyEntity.ts +3 -2
- package/src/ViewerScopedEntityCompanion.ts +8 -0
- package/src/__tests__/Entity-test.ts +8 -8
- package/src/__tests__/EntityCommonUseCases-test.ts +4 -4
- package/src/__tests__/EntityEdges-test.ts +169 -14
- package/src/__tests__/EntityFields-test.ts +2 -21
- package/src/__tests__/EntityLoader-constructor-test.ts +177 -0
- package/src/__tests__/EntityLoader-test.ts +39 -11
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +105 -0
- package/src/__tests__/EntityMutator-test.ts +140 -133
- package/src/__tests__/EntityPrivacyPolicy-test.ts +215 -78
- package/src/__tests__/EntityQueryContext-test.ts +82 -0
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -9
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +6 -5
- package/src/__tests__/ViewerContext-test.ts +7 -6
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +11 -10
- package/src/__tests__/ViewerScopedEntityMutatorFactory-test.ts +4 -3
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +6 -6
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +4 -4
- package/src/index.ts +3 -0
- package/src/internal/EntityDataManager.ts +2 -1
- package/src/internal/__tests__/EntityDataManager-test.ts +2 -2
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +15 -13
- package/src/metrics/EntityMetricsUtils.ts +56 -50
- package/src/metrics/IEntityMetricsAdapter.ts +23 -0
- package/src/metrics/NoOpEntityMetricsAdapter.ts +2 -0
- package/src/testfixtures/DateIDTestEntity.ts +4 -4
- package/src/testfixtures/SimpleTestEntity.ts +4 -4
- package/src/testfixtures/TestEntity.ts +4 -4
- package/src/testfixtures/TestEntity2.ts +4 -4
- package/src/testfixtures/TestEntityNumberKey.ts +4 -4
- package/src/utils/testing/StubDatabaseAdapter.ts +2 -2
- package/src/utils/testing/__tests__/StubDatabaseAdapter-test.ts +1 -1
- package/src/utils/testing/describeFieldTestCase.ts +21 -0
- package/CHANGELOG.md +0 -252
package/build/EntityFields.js
CHANGED
|
@@ -1,57 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MaybeJSONArrayField = exports.JSONArrayField = exports.EnumField = exports.JSONObjectField = exports.StringArrayField = exports.FloatField = exports.IntField = exports.BooleanField = exports.DateField = exports.UUIDField = exports.StringField =
|
|
3
|
+
exports.MaybeJSONArrayField = exports.JSONArrayField = exports.EnumField = exports.JSONObjectField = exports.StringArrayField = exports.FloatField = exports.IntField = exports.BooleanField = exports.DateField = exports.UUIDField = exports.StringField = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Default. Invalidate the cache for all entities that reference the entity
|
|
9
|
-
* being deleted through this field, and transitively run deletions on those entities.
|
|
10
|
-
* This is most useful when the database itself expresses foreign
|
|
11
|
-
* keys and cascading deletes or set nulls and the entity framework just needs to
|
|
12
|
-
* be kept consistent with the state of the database.
|
|
13
|
-
*/
|
|
14
|
-
EntityEdgeDeletionBehavior[EntityEdgeDeletionBehavior["CASCADE_DELETE_INVALIDATE_CACHE"] = 0] = "CASCADE_DELETE_INVALIDATE_CACHE";
|
|
15
|
-
/**
|
|
16
|
-
* Delete all entities that reference the entity being deleted through this field. This is very similar
|
|
17
|
-
* to SQL `ON DELETE CASCADE` but is done in the Entity framework instead of at the underlying level.
|
|
18
|
-
* This will also invalidate the cached referencing entities.
|
|
19
|
-
*/
|
|
20
|
-
EntityEdgeDeletionBehavior[EntityEdgeDeletionBehavior["CASCADE_DELETE"] = 1] = "CASCADE_DELETE";
|
|
21
|
-
/**
|
|
22
|
-
* Set this field to null when the referenced entity is deleted. This is very similar
|
|
23
|
-
* to SQL `ON DELETE SET NULL` but is done in the Entity framework instead of at the underlying level.
|
|
24
|
-
* This will also invalidate the cached referencing entities.
|
|
25
|
-
*/
|
|
26
|
-
EntityEdgeDeletionBehavior[EntityEdgeDeletionBehavior["SET_NULL"] = 2] = "SET_NULL";
|
|
27
|
-
})(EntityEdgeDeletionBehavior = exports.EntityEdgeDeletionBehavior || (exports.EntityEdgeDeletionBehavior = {}));
|
|
28
|
-
class EntityFieldDefinition {
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param columnName - Column name in the database.
|
|
32
|
-
* @param cache - Whether or not to cache loaded instances of the entity by this field. The column name is
|
|
33
|
-
* used to derive a cache key for the cache entry. If true, this column must be able uniquely
|
|
34
|
-
* identify the entity.
|
|
35
|
-
*/
|
|
36
|
-
constructor({ columnName, cache = false, association, }) {
|
|
37
|
-
this.columnName = columnName;
|
|
38
|
-
this.cache = cache;
|
|
39
|
-
this.association = association;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Validates input value for a field of this type. Null and undefined are considered valid by default. This is used for things like:
|
|
43
|
-
* - EntityLoader.loadByFieldValue - to ensure the value being loaded by is a valid value
|
|
44
|
-
* - EntityMutator.setField - to ensure the value being set is a valid value
|
|
45
|
-
*/
|
|
46
|
-
validateInputValue(value) {
|
|
47
|
-
if (value === null || value === undefined) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return this.validateInputValueInternal(value);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.EntityFieldDefinition = EntityFieldDefinition;
|
|
54
|
-
class StringField extends EntityFieldDefinition {
|
|
5
|
+
const EntityFieldDefinition_1 = require("./EntityFieldDefinition");
|
|
6
|
+
class StringField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
55
7
|
validateInputValueInternal(value) {
|
|
56
8
|
return typeof value === 'string';
|
|
57
9
|
}
|
|
@@ -59,59 +11,59 @@ class StringField extends EntityFieldDefinition {
|
|
|
59
11
|
exports.StringField = StringField;
|
|
60
12
|
class UUIDField extends StringField {
|
|
61
13
|
validateInputValueInternal(value) {
|
|
62
|
-
return uuid_1.validate(value);
|
|
14
|
+
return (0, uuid_1.validate)(value);
|
|
63
15
|
}
|
|
64
16
|
}
|
|
65
17
|
exports.UUIDField = UUIDField;
|
|
66
|
-
class DateField extends EntityFieldDefinition {
|
|
18
|
+
class DateField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
67
19
|
validateInputValueInternal(value) {
|
|
68
20
|
return value instanceof Date;
|
|
69
21
|
}
|
|
70
22
|
}
|
|
71
23
|
exports.DateField = DateField;
|
|
72
|
-
class BooleanField extends EntityFieldDefinition {
|
|
24
|
+
class BooleanField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
73
25
|
validateInputValueInternal(value) {
|
|
74
26
|
return typeof value === 'boolean';
|
|
75
27
|
}
|
|
76
28
|
}
|
|
77
29
|
exports.BooleanField = BooleanField;
|
|
78
|
-
class IntField extends EntityFieldDefinition {
|
|
30
|
+
class IntField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
79
31
|
validateInputValueInternal(value) {
|
|
80
32
|
return typeof value === 'number' && Number.isInteger(value);
|
|
81
33
|
}
|
|
82
34
|
}
|
|
83
35
|
exports.IntField = IntField;
|
|
84
|
-
class FloatField extends EntityFieldDefinition {
|
|
36
|
+
class FloatField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
85
37
|
validateInputValueInternal(value) {
|
|
86
38
|
return typeof value === 'number';
|
|
87
39
|
}
|
|
88
40
|
}
|
|
89
41
|
exports.FloatField = FloatField;
|
|
90
|
-
class StringArrayField extends EntityFieldDefinition {
|
|
42
|
+
class StringArrayField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
91
43
|
validateInputValueInternal(value) {
|
|
92
44
|
return Array.isArray(value) && value.every((subValue) => typeof subValue === 'string');
|
|
93
45
|
}
|
|
94
46
|
}
|
|
95
47
|
exports.StringArrayField = StringArrayField;
|
|
96
|
-
class JSONObjectField extends EntityFieldDefinition {
|
|
48
|
+
class JSONObjectField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
97
49
|
validateInputValueInternal(value) {
|
|
98
50
|
return typeof value === 'object' && !Array.isArray(value);
|
|
99
51
|
}
|
|
100
52
|
}
|
|
101
53
|
exports.JSONObjectField = JSONObjectField;
|
|
102
|
-
class EnumField extends EntityFieldDefinition {
|
|
54
|
+
class EnumField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
103
55
|
validateInputValueInternal(value) {
|
|
104
56
|
return typeof value === 'number' || typeof value === 'string';
|
|
105
57
|
}
|
|
106
58
|
}
|
|
107
59
|
exports.EnumField = EnumField;
|
|
108
|
-
class JSONArrayField extends EntityFieldDefinition {
|
|
60
|
+
class JSONArrayField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
109
61
|
validateInputValueInternal(value) {
|
|
110
62
|
return Array.isArray(value);
|
|
111
63
|
}
|
|
112
64
|
}
|
|
113
65
|
exports.JSONArrayField = JSONArrayField;
|
|
114
|
-
class MaybeJSONArrayField extends EntityFieldDefinition {
|
|
66
|
+
class MaybeJSONArrayField extends EntityFieldDefinition_1.EntityFieldDefinition {
|
|
115
67
|
validateInputValueInternal(_value) {
|
|
116
68
|
return true;
|
|
117
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFields.js","sourceRoot":"","sources":["../src/EntityFields.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;
|
|
1
|
+
{"version":3,"file":"EntityFields.js","sourceRoot":"","sources":["../src/EntityFields.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;AAEhD,mEAAgE;AAEhE,MAAa,WAAY,SAAQ,6CAA6B;IAClD,0BAA0B,CAAC,KAAa;QAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;CACF;AAJD,kCAIC;AACD,MAAa,SAAU,SAAQ,WAAW;IACrB,0BAA0B,CAAC,KAAa;QACzD,OAAO,IAAA,eAAY,EAAC,KAAK,CA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pD,0BAA0B,CAAC,KAAY;QAC/C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF;AAJD,wCAIC;AACD,MAAa,mBAAoB,SAAQ,6CAAkC;IAC/D,0BAA0B,CAAC,MAAW;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAJD,kDAIC"}
|
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
|
|
@@ -52,7 +53,7 @@ class EntityLoader {
|
|
|
52
53
|
async loadManyByFieldEqualingAsync(fieldName, fieldValue) {
|
|
53
54
|
const entityResults = await this.loadManyByFieldEqualingManyAsync(fieldName, [fieldValue]);
|
|
54
55
|
const entityResultsForFieldValue = entityResults.get(fieldValue);
|
|
55
|
-
invariant_1.default(entityResultsForFieldValue !== undefined, `${fieldValue} should be guaranteed to be present in returned map of entities`);
|
|
56
|
+
(0, invariant_1.default)(entityResultsForFieldValue !== undefined, `${fieldValue} should be guaranteed to be present in returned map of entities`);
|
|
56
57
|
return entityResultsForFieldValue;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
@@ -65,7 +66,7 @@ class EntityLoader {
|
|
|
65
66
|
async loadByFieldEqualingAsync(uniqueFieldName, fieldValue) {
|
|
66
67
|
var _a;
|
|
67
68
|
const entityResults = await this.loadManyByFieldEqualingAsync(uniqueFieldName, fieldValue);
|
|
68
|
-
invariant_1.default(entityResults.length <= 1, `loadByFieldEqualing: Multiple entities of type ${this.entityClass.name} found for ${uniqueFieldName}=${fieldValue}`);
|
|
69
|
+
(0, invariant_1.default)(entityResults.length <= 1, `loadByFieldEqualing: Multiple entities of type ${this.entityClass.name} found for ${uniqueFieldName}=${fieldValue}`);
|
|
69
70
|
return (_a = entityResults[0]) !== null && _a !== void 0 ? _a : null;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
@@ -77,7 +78,7 @@ class EntityLoader {
|
|
|
77
78
|
const entityResults = await this.loadManyByIDsAsync([id]);
|
|
78
79
|
const entityResult = entityResults.get(id);
|
|
79
80
|
if (entityResult === undefined) {
|
|
80
|
-
return results_1.result(new EntityNotFoundError_1.default(this.entityClass, this.entityConfiguration.idField, id));
|
|
81
|
+
return (0, results_1.result)(new EntityNotFoundError_1.default(this.entityClass, this.entityConfiguration.idField, id));
|
|
81
82
|
}
|
|
82
83
|
return entityResult;
|
|
83
84
|
}
|
|
@@ -97,9 +98,9 @@ class EntityLoader {
|
|
|
97
98
|
*/
|
|
98
99
|
async loadManyByIDsAsync(ids) {
|
|
99
100
|
const entityResults = (await this.loadManyByFieldEqualingManyAsync(this.entityConfiguration.idField, ids));
|
|
100
|
-
return maps_1.mapMap(entityResults, (entityResultsForId, id) => {
|
|
101
|
+
return (0, maps_1.mapMap)(entityResults, (entityResultsForId, id) => {
|
|
101
102
|
const entityResult = entityResultsForId[0];
|
|
102
|
-
return (entityResult !== null && entityResult !== void 0 ? entityResult : results_1.result(new EntityNotFoundError_1.default(this.entityClass, this.entityConfiguration.idField, id)));
|
|
103
|
+
return (entityResult !== null && entityResult !== void 0 ? entityResult : (0, results_1.result)(new EntityNotFoundError_1.default(this.entityClass, this.entityConfiguration.idField, id)));
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
@@ -118,7 +119,7 @@ class EntityLoader {
|
|
|
118
119
|
*/
|
|
119
120
|
async loadManyByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers = {}) {
|
|
120
121
|
for (const fieldEqualityOperand of fieldEqualityOperands) {
|
|
121
|
-
const fieldValues = EntityDatabaseAdapter_1.isSingleValueFieldEqualityCondition(fieldEqualityOperand)
|
|
122
|
+
const fieldValues = (0, EntityDatabaseAdapter_1.isSingleValueFieldEqualityCondition)(fieldEqualityOperand)
|
|
122
123
|
? [fieldEqualityOperand.fieldValue]
|
|
123
124
|
: fieldEqualityOperand.fieldValues;
|
|
124
125
|
this.validateFieldValues(fieldEqualityOperand.fieldName, fieldValues);
|
|
@@ -129,7 +130,7 @@ class EntityLoader {
|
|
|
129
130
|
if (!uncheckedEntityResult.ok) {
|
|
130
131
|
return uncheckedEntityResult;
|
|
131
132
|
}
|
|
132
|
-
return await 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 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
|
/**
|
|
@@ -185,10 +186,13 @@ class EntityLoader {
|
|
|
185
186
|
tryConstructEntities(fieldsObjects) {
|
|
186
187
|
return fieldsObjects.map((fieldsObject) => {
|
|
187
188
|
try {
|
|
188
|
-
return results_1.result(new this.entityClass(this.viewerContext, fieldsObject));
|
|
189
|
+
return (0, results_1.result)(new this.entityClass(this.viewerContext, fieldsObject));
|
|
189
190
|
}
|
|
190
191
|
catch (e) {
|
|
191
|
-
|
|
192
|
+
if (!(e instanceof Error)) {
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
return (0, results_1.result)(e);
|
|
192
196
|
}
|
|
193
197
|
});
|
|
194
198
|
}
|
|
@@ -199,19 +203,19 @@ class EntityLoader {
|
|
|
199
203
|
* @param map - map from an arbitrary key type to an array of entity field objects
|
|
200
204
|
*/
|
|
201
205
|
async constructAndAuthorizeEntitiesAsync(map) {
|
|
202
|
-
const uncheckedEntityResultsMap = maps_1.mapMap(map, (fieldObjects) => this.tryConstructEntities(fieldObjects));
|
|
203
|
-
return await maps_1.mapMapAsync(uncheckedEntityResultsMap, async (uncheckedEntityResults) => {
|
|
206
|
+
const uncheckedEntityResultsMap = (0, maps_1.mapMap)(map, (fieldObjects) => this.tryConstructEntities(fieldObjects));
|
|
207
|
+
return await (0, maps_1.mapMapAsync)(uncheckedEntityResultsMap, async (uncheckedEntityResults) => {
|
|
204
208
|
return await Promise.all(uncheckedEntityResults.map(async (uncheckedEntityResult) => {
|
|
205
209
|
if (!uncheckedEntityResult.ok) {
|
|
206
210
|
return uncheckedEntityResult;
|
|
207
211
|
}
|
|
208
|
-
return await 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));
|
|
209
213
|
}));
|
|
210
214
|
});
|
|
211
215
|
}
|
|
212
216
|
validateFieldValues(fieldName, fieldValues) {
|
|
213
217
|
const fieldDefinition = this.entityConfiguration.schema.get(fieldName);
|
|
214
|
-
invariant_1.default(fieldDefinition, `must have field definition for field = ${fieldName}`);
|
|
218
|
+
(0, invariant_1.default)(fieldDefinition, `must have field definition for field = ${fieldName}`);
|
|
215
219
|
for (const fieldValue of fieldValues) {
|
|
216
220
|
const isInputValid = fieldDefinition.validateInputValue(fieldValue);
|
|
217
221
|
if (!isInputValid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityLoader.js","sourceRoot":"","sources":["../src/EntityLoader.ts"],"names":[],"mappings":";;;;;AAAA,2CAA4D;AAC5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AAC,CAAC;QACvE,IAAA,mBAAS,EAAC,eAAe,EAAE,0CAA0C,SAAS,EAAE,CAAC,CAAC;QAClF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YACpC,MAAM,YAAY,GAAG,eAAe,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;YACpE,IAAI,CAAC,YAAY,EAAE;gBACjB,MAAM,IAAI,sCAA4B,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;aACjF;SACF;IACH,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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EntityTriggerMutationInfo } from './EntityMutationInfo';
|
|
2
|
+
import { EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
3
3
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
4
|
import ViewerContext from './ViewerContext';
|
|
5
5
|
/**
|
|
@@ -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:
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { EntityValidatorMutationInfo } from './EntityMutationInfo';
|
|
2
|
+
import { EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
3
3
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
4
|
import ViewerContext from './ViewerContext';
|
|
5
5
|
/**
|
|
@@ -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:
|
|
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
|
-
import { EntityQueryContext } from './EntityQueryContext';
|
|
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.
|