@expo/entity 0.25.3 → 0.27.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.
Files changed (178) hide show
  1. package/LICENSE +21 -0
  2. package/build/ComposedEntityCacheAdapter.d.ts +4 -2
  3. package/build/ComposedEntityCacheAdapter.js +39 -3
  4. package/build/ComposedEntityCacheAdapter.js.map +1 -1
  5. package/build/ComposedSecondaryEntityCache.d.ts +3 -2
  6. package/build/ComposedSecondaryEntityCache.js +3 -2
  7. package/build/ComposedSecondaryEntityCache.js.map +1 -1
  8. package/build/EnforcingEntityLoader.d.ts +10 -10
  9. package/build/EnforcingEntityLoader.js +8 -8
  10. package/build/EnforcingEntityLoader.js.map +1 -1
  11. package/build/Entity.d.ts +5 -5
  12. package/build/Entity.js +9 -9
  13. package/build/Entity.js.map +1 -1
  14. package/build/EntityAssociationLoader.d.ts +9 -4
  15. package/build/EntityAssociationLoader.js +5 -0
  16. package/build/EntityAssociationLoader.js.map +1 -1
  17. package/build/EntityCacheAdapter.d.ts +1 -1
  18. package/build/EntityCompanion.d.ts +1 -1
  19. package/build/EntityCompanion.js +1 -1
  20. package/build/EntityCompanionProvider.d.ts +9 -9
  21. package/build/EntityCompanionProvider.js +3 -3
  22. package/build/EntityConfiguration.d.ts +2 -2
  23. package/build/EntityDatabaseAdapter.d.ts +15 -6
  24. package/build/EntityDatabaseAdapter.js +8 -2
  25. package/build/EntityDatabaseAdapter.js.map +1 -1
  26. package/build/EntityFieldDefinition.d.ts +16 -8
  27. package/build/EntityFieldDefinition.js +12 -5
  28. package/build/EntityFieldDefinition.js.map +1 -1
  29. package/build/EntityFields.d.ts +11 -11
  30. package/build/EntityFields.js +11 -11
  31. package/build/EntityLoader.d.ts +7 -7
  32. package/build/EntityLoader.js +7 -7
  33. package/build/EntityLoader.js.map +1 -1
  34. package/build/EntityMutationInfo.d.ts +2 -0
  35. package/build/EntityMutationTriggerConfiguration.d.ts +1 -1
  36. package/build/EntityMutationTriggerConfiguration.js +1 -1
  37. package/build/EntityMutator.d.ts +7 -9
  38. package/build/EntityMutator.js +59 -47
  39. package/build/EntityMutator.js.map +1 -1
  40. package/build/EntityMutatorFactory.d.ts +4 -4
  41. package/build/EntityMutatorFactory.js +6 -6
  42. package/build/EntityMutatorFactory.js.map +1 -1
  43. package/build/EntityPrivacyPolicy.d.ts +18 -5
  44. package/build/EntityPrivacyPolicy.js +18 -5
  45. package/build/EntityPrivacyPolicy.js.map +1 -1
  46. package/build/EntityQueryContext.d.ts +12 -1
  47. package/build/EntityQueryContext.js +12 -1
  48. package/build/EntityQueryContext.js.map +1 -1
  49. package/build/EntityQueryContextProvider.d.ts +1 -1
  50. package/build/EntitySecondaryCacheLoader.d.ts +1 -1
  51. package/build/EntitySecondaryCacheLoader.js +1 -1
  52. package/build/GenericSecondaryEntityCache.d.ts +1 -1
  53. package/build/GenericSecondaryEntityCache.js +1 -1
  54. package/build/ReadonlyEntity.d.ts +1 -1
  55. package/build/ReadonlyEntity.js +1 -1
  56. package/build/ViewerContext.d.ts +2 -2
  57. package/build/ViewerContext.js +2 -2
  58. package/build/ViewerScopedEntityCompanion.d.ts +2 -2
  59. package/build/ViewerScopedEntityCompanion.js +2 -2
  60. package/build/ViewerScopedEntityLoaderFactory.d.ts +1 -1
  61. package/build/ViewerScopedEntityLoaderFactory.js +1 -1
  62. package/build/ViewerScopedEntityMutatorFactory.d.ts +5 -5
  63. package/build/ViewerScopedEntityMutatorFactory.js +7 -7
  64. package/build/ViewerScopedEntityMutatorFactory.js.map +1 -1
  65. package/build/__tests__/ComposedCacheAdapter-test.js +37 -4
  66. package/build/__tests__/ComposedCacheAdapter-test.js.map +1 -1
  67. package/build/__tests__/EntityCommonUseCases-test.js +5 -1
  68. package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
  69. package/build/__tests__/EntityCompanion-test.js +5 -1
  70. package/build/__tests__/EntityCompanion-test.js.map +1 -1
  71. package/build/__tests__/EntityCompanionProvider-test.js +5 -1
  72. package/build/__tests__/EntityCompanionProvider-test.js.map +1 -1
  73. package/build/__tests__/EntityEdges-test.js +199 -33
  74. package/build/__tests__/EntityEdges-test.js.map +1 -1
  75. package/build/__tests__/EntityLoader-test.js +5 -1
  76. package/build/__tests__/EntityLoader-test.js.map +1 -1
  77. package/build/__tests__/EntityMutator-test.js +38 -53
  78. package/build/__tests__/EntityMutator-test.js.map +1 -1
  79. package/build/__tests__/EntityPrivacyPolicy-test.js +5 -1
  80. package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
  81. package/build/__tests__/EntitySelfReferentialEdges-test.js +2 -2
  82. package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
  83. package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js +5 -1
  84. package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js.map +1 -1
  85. package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js +2 -3
  86. package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js.map +1 -1
  87. package/build/errors/EntityCacheAdapterError.js +5 -1
  88. package/build/errors/EntityCacheAdapterError.js.map +1 -1
  89. package/build/errors/EntityDatabaseAdapterError.js +5 -1
  90. package/build/errors/EntityDatabaseAdapterError.js.map +1 -1
  91. package/build/errors/EntityInvalidFieldValueError.js +6 -2
  92. package/build/errors/EntityInvalidFieldValueError.js.map +1 -1
  93. package/build/errors/EntityNotAuthorizedError.js +5 -1
  94. package/build/errors/EntityNotAuthorizedError.js.map +1 -1
  95. package/build/errors/EntityNotFoundError.js +6 -2
  96. package/build/errors/EntityNotFoundError.js.map +1 -1
  97. package/build/index.js +5 -1
  98. package/build/index.js.map +1 -1
  99. package/build/internal/EntityDataManager.d.ts +5 -5
  100. package/build/internal/EntityDataManager.js +10 -7
  101. package/build/internal/EntityDataManager.js.map +1 -1
  102. package/build/internal/EntityFieldTransformationUtils.js +1 -1
  103. package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
  104. package/build/internal/ReadThroughEntityCache.d.ts +2 -2
  105. package/build/internal/ReadThroughEntityCache.js +3 -3
  106. package/build/internal/ReadThroughEntityCache.js.map +1 -1
  107. package/build/internal/__tests__/EntityDataManager-test.js +12 -7
  108. package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
  109. package/build/internal/__tests__/ReadThroughEntityCache-test.js +5 -1
  110. package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
  111. package/build/metrics/IEntityMetricsAdapter.d.ts +63 -18
  112. package/build/metrics/IEntityMetricsAdapter.js +17 -1
  113. package/build/metrics/IEntityMetricsAdapter.js.map +1 -1
  114. package/build/metrics/NoOpEntityMetricsAdapter.d.ts +1 -3
  115. package/build/metrics/NoOpEntityMetricsAdapter.js +1 -3
  116. package/build/metrics/NoOpEntityMetricsAdapter.js.map +1 -1
  117. package/build/rules/AlwaysAllowPrivacyPolicyRule.js +5 -1
  118. package/build/rules/AlwaysAllowPrivacyPolicyRule.js.map +1 -1
  119. package/build/rules/AlwaysDenyPrivacyPolicyRule.js +5 -1
  120. package/build/rules/AlwaysDenyPrivacyPolicyRule.js.map +1 -1
  121. package/build/rules/AlwaysSkipPrivacyPolicyRule.js +5 -1
  122. package/build/rules/AlwaysSkipPrivacyPolicyRule.js.map +1 -1
  123. package/build/rules/PrivacyPolicyRule.d.ts +1 -1
  124. package/build/rules/PrivacyPolicyRule.js +1 -1
  125. package/build/utils/collections/maps.d.ts +1 -1
  126. package/build/utils/collections/maps.js +1 -1
  127. package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +1 -2
  128. package/build/utils/testing/StubDatabaseAdapter.js +6 -2
  129. package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
  130. package/build/utils/testing/StubQueryContextProvider.d.ts +1 -1
  131. package/build/utils/testing/StubQueryContextProvider.js +2 -0
  132. package/build/utils/testing/StubQueryContextProvider.js.map +1 -1
  133. package/package.json +3 -2
  134. package/src/ComposedEntityCacheAdapter.ts +44 -3
  135. package/src/ComposedSecondaryEntityCache.ts +3 -2
  136. package/src/EnforcingEntityLoader.ts +14 -10
  137. package/src/Entity.ts +9 -9
  138. package/src/EntityAssociationLoader.ts +9 -4
  139. package/src/EntityCacheAdapter.ts +1 -1
  140. package/src/EntityCompanion.ts +1 -1
  141. package/src/EntityCompanionProvider.ts +9 -9
  142. package/src/EntityConfiguration.ts +2 -2
  143. package/src/EntityDatabaseAdapter.ts +33 -6
  144. package/src/EntityFieldDefinition.ts +15 -6
  145. package/src/EntityFields.ts +11 -11
  146. package/src/EntityLoader.ts +11 -8
  147. package/src/EntityMutationInfo.ts +2 -0
  148. package/src/EntityMutationTriggerConfiguration.ts +1 -1
  149. package/src/EntityMutator.ts +99 -68
  150. package/src/EntityMutatorFactory.ts +4 -10
  151. package/src/EntityPrivacyPolicy.ts +20 -5
  152. package/src/EntityQueryContext.ts +12 -1
  153. package/src/EntityQueryContextProvider.ts +1 -1
  154. package/src/EntitySecondaryCacheLoader.ts +1 -1
  155. package/src/GenericSecondaryEntityCache.ts +1 -1
  156. package/src/ReadonlyEntity.ts +1 -1
  157. package/src/ViewerContext.ts +2 -2
  158. package/src/ViewerScopedEntityCompanion.ts +2 -2
  159. package/src/ViewerScopedEntityLoaderFactory.ts +1 -1
  160. package/src/ViewerScopedEntityMutatorFactory.ts +8 -23
  161. package/src/__tests__/ComposedCacheAdapter-test.ts +43 -4
  162. package/src/__tests__/EntityEdges-test.ts +287 -32
  163. package/src/__tests__/EntityMutator-test.ts +33 -54
  164. package/src/__tests__/EntitySelfReferentialEdges-test.ts +2 -2
  165. package/src/__tests__/ViewerScopedEntityMutatorFactory-test.ts +2 -6
  166. package/src/errors/EntityInvalidFieldValueError.ts +1 -1
  167. package/src/errors/EntityNotFoundError.ts +1 -1
  168. package/src/internal/EntityDataManager.ts +18 -9
  169. package/src/internal/EntityFieldTransformationUtils.ts +1 -1
  170. package/src/internal/ReadThroughEntityCache.ts +5 -3
  171. package/src/internal/__tests__/EntityDataManager-test.ts +11 -8
  172. package/src/metrics/IEntityMetricsAdapter.ts +73 -20
  173. package/src/metrics/NoOpEntityMetricsAdapter.ts +1 -5
  174. package/src/rules/PrivacyPolicyRule.ts +1 -1
  175. package/src/utils/collections/maps.ts +1 -1
  176. package/src/utils/testing/PrivacyPolicyRuleTestUtils.ts +1 -1
  177. package/src/utils/testing/StubDatabaseAdapter.ts +4 -1
  178. package/src/utils/testing/StubQueryContextProvider.ts +1 -1
@@ -9,10 +9,28 @@ export enum EntityMetricsLoadType {
9
9
  LOAD_MANY_RAW,
10
10
  }
11
11
 
12
+ /**
13
+ * Event about a single call to an EntityLoader method.
14
+ */
12
15
  export interface EntityMetricsLoadEvent {
16
+ /**
17
+ * EntityMetricsLoadType for this load.
18
+ */
13
19
  type: EntityMetricsLoadType;
20
+
21
+ /**
22
+ * Class name of the Entity being loaded.
23
+ */
14
24
  entityClassName: string;
25
+
26
+ /**
27
+ * Total duration of this load, including fetch and construction of entities.
28
+ */
15
29
  duration: number;
30
+
31
+ /**
32
+ * Number of entities returned for this load.
33
+ */
16
34
  count: number;
17
35
  }
18
36
 
@@ -23,13 +41,57 @@ export enum EntityMetricsMutationType {
23
41
  }
24
42
 
25
43
  export interface EntityMetricsMutationEvent {
44
+ /**
45
+ * EntityMetricsMutationType for this mutation.
46
+ */
26
47
  type: EntityMetricsMutationType;
48
+
49
+ /**
50
+ * Class name of the Entity being mutated.
51
+ */
27
52
  entityClassName: string;
53
+
54
+ /**
55
+ * Total duration of this mutation.
56
+ */
28
57
  duration: number;
29
58
  }
30
59
 
60
+ export enum IncrementLoadCountEventType {
61
+ /**
62
+ * Type for when a dataloader load is initiated via the standard load methods
63
+ * since all loads go through a dataloader.
64
+ */
65
+ DATALOADER,
66
+
67
+ /**
68
+ * Type for when a cache load is initiated due to a dataloader miss.
69
+ */
70
+ CACHE,
71
+
72
+ /**
73
+ * Type for when a database load is initiated due to a dataloader and cache miss, when an entity query doesn't support caching, or during a transaction.
74
+ */
75
+ DATABASE,
76
+ }
77
+
78
+ /**
79
+ * Event used to record dataloader, cache, and database load counts in EntityDataManager.
80
+ */
31
81
  export interface IncrementLoadCountEvent {
82
+ /**
83
+ * Type of this event.
84
+ */
85
+ type: IncrementLoadCountEventType;
86
+
87
+ /**
88
+ * Number of field values being loaded for this call.
89
+ */
32
90
  fieldValueCount: number;
91
+
92
+ /**
93
+ * Class name of the Entity being loaded.
94
+ */
33
95
  entityClassName: string;
34
96
  }
35
97
 
@@ -38,7 +100,13 @@ export enum EntityMetricsAuthorizationResult {
38
100
  ALLOW,
39
101
  }
40
102
 
103
+ /**
104
+ * Event used to record a singe EntityPrivacyPolicy authorization.
105
+ */
41
106
  export interface EntityMetricsAuthorizationEvent {
107
+ /**
108
+ * Class name of the Entity being authorized.
109
+ */
42
110
  entityClassName: string;
43
111
  action: EntityAuthorizationAction;
44
112
  evaluationResult: EntityMetricsAuthorizationResult;
@@ -51,7 +119,7 @@ export interface EntityMetricsAuthorizationEvent {
51
119
  */
52
120
  export default interface IEntityMetricsAdapter {
53
121
  /**
54
- * Called when a {@link EntityPrivacyPolicy} authorization succeeds or fails.
122
+ * Called when a EntityPrivacyPolicy authorization succeeds or fails.
55
123
  * @param authorizationEvent - info about the authorization event
56
124
  */
57
125
  logAuthorizationEvent(authorizationEvent: EntityMetricsAuthorizationEvent): void;
@@ -69,25 +137,10 @@ export default interface IEntityMetricsAdapter {
69
137
  logMutatorMutationEvent(mutationEvent: EntityMetricsMutationEvent): void;
70
138
 
71
139
  /**
72
- * Called when a dataloader load is initiated via the standard
73
- * load methods (not equality conjunction or raw).
74
- * @param fieldValueCount - count of field values being loaded for a field
75
- */
76
- incrementDataManagerDataloaderLoadCount(incrementLoadCountEvent: IncrementLoadCountEvent): void;
77
-
78
- /**
79
- * Called when a cache load is initiated via the standard
80
- * load methods (not equality conjunction or raw). Occurs upon a dataloader
81
- * miss.
82
- * @param fieldValueCount - count of field values being loaded for a field
83
- */
84
- incrementDataManagerCacheLoadCount(incrementLoadCountEvent: IncrementLoadCountEvent): void;
85
-
86
- /**
87
- * Called when a database load is initiated via the standard
88
- * load methods (not equality conjunction or raw). Occurs upon a cache
89
- * miss or when fetching an uncacheable field.
140
+ * Called when a dataloader, cache, or database load is initiated via the standard
141
+ * load methods (not equality conjunction or raw). Most commonly used for logging
142
+ * a waterfall to determine dataloader and cache hit rates and ratios.
90
143
  * @param fieldValueCount - count of field values being loaded for a field
91
144
  */
92
- incrementDataManagerDatabaseLoadCount(incrementLoadCountEvent: IncrementLoadCountEvent): void;
145
+ incrementDataManagerLoadCount(incrementLoadCountEvent: IncrementLoadCountEvent): void;
93
146
  }
@@ -9,9 +9,5 @@ export default class NoOpEntityMetricsAdapter implements IEntityMetricsAdapter {
9
9
  logAuthorizationEvent(_authorizationEvent: EntityMetricsAuthorizationEvent): void {}
10
10
  logDataManagerLoadEvent(_loadEvent: EntityMetricsLoadEvent): void {}
11
11
  logMutatorMutationEvent(_mutationEvent: EntityMetricsMutationEvent): void {}
12
- incrementDataManagerDataloaderLoadCount(
13
- _incrementLoadCountEvent: IncrementLoadCountEvent
14
- ): void {}
15
- incrementDataManagerCacheLoadCount(_incrementLoadCountEvent: IncrementLoadCountEvent): void {}
16
- incrementDataManagerDatabaseLoadCount(_incrementLoadCountEvent: IncrementLoadCountEvent): void {}
12
+ incrementDataManagerLoadCount(_incrementLoadCountEvent: IncrementLoadCountEvent): void {}
17
13
  }
@@ -32,7 +32,7 @@ export enum RuleEvaluationResult {
32
32
  * rule in the privacy policy. If all rules in the policy SKIP, the policy is denied.
33
33
  *
34
34
  * Returning DENY from a rule is useful in a few notable cases:
35
- * - Preventing a CRUD action on an entity ({@link AlwaysDenyPrivacyPolicyRule})
35
+ * - Preventing a CRUD action on an entity (AlwaysDenyPrivacyPolicyRule)
36
36
  * - Blocking. For example, a user blocks another user from seeing their posts, and the rule
37
37
  * would be named something like `DenyIfViewerHasBeenBlockedPrivacyPolicyRule`.
38
38
  */
@@ -60,7 +60,7 @@ export const mapMapAsync = async function <K, V, M>(
60
60
 
61
61
  /**
62
62
  * Create a new Map by associating the value of each key with mapper executed for each key in the source map.
63
- * The opposite of {@link mapMap}. In the event two source keys map to the same result key, the second source key's
63
+ * The opposite of mapMap. In the event two source keys map to the same result key, the second source key's
64
64
  * value will overwrite the first, in which case the cardinality of the returned map may be smaller than the
65
65
  * source map's.
66
66
  *
@@ -17,7 +17,7 @@ export interface Case<
17
17
  entity: TEntity;
18
18
  }
19
19
 
20
- type CaseMap<
20
+ export type CaseMap<
21
21
  TFields,
22
22
  TID extends NonNullable<TFields[TSelectedFields]>,
23
23
  TViewerContext extends ViewerContext,
@@ -158,7 +158,10 @@ export default class StubDatabaseAdapter<T> extends EntityDatabaseAdapter<T> {
158
158
 
159
159
  private generateRandomID(): any {
160
160
  const idSchemaField = this.entityConfiguration2.schema.get(this.entityConfiguration2.idField);
161
- invariant(idSchemaField, `No schema field found for ${this.entityConfiguration2.idField}`);
161
+ invariant(
162
+ idSchemaField,
163
+ `No schema field found for ${String(this.entityConfiguration2.idField)}`
164
+ );
162
165
  if (idSchemaField instanceof StringField) {
163
166
  return uuidv4();
164
167
  } else if (idSchemaField instanceof IntField) {
@@ -1,6 +1,6 @@
1
1
  import EntityQueryContextProvider from '../../EntityQueryContextProvider';
2
2
 
3
- class StubQueryContextProvider extends EntityQueryContextProvider {
3
+ export class StubQueryContextProvider extends EntityQueryContextProvider {
4
4
  protected getQueryInterface(): any {
5
5
  return {};
6
6
  }