@expo/entity 0.42.0 → 0.44.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 (66) hide show
  1. package/build/AuthorizationResultBasedEntityMutator.d.ts +87 -2
  2. package/build/AuthorizationResultBasedEntityMutator.js +122 -8
  3. package/build/AuthorizationResultBasedEntityMutator.js.map +1 -1
  4. package/build/EntityFieldDefinition.d.ts +1 -1
  5. package/build/EntityFieldDefinition.js +1 -1
  6. package/build/EntityFieldDefinition.js.map +1 -1
  7. package/build/EntityLoaderUtils.d.ts +15 -3
  8. package/build/EntityLoaderUtils.js +25 -10
  9. package/build/EntityLoaderUtils.js.map +1 -1
  10. package/build/EntityQueryContext.d.ts +53 -7
  11. package/build/EntityQueryContext.js +65 -10
  12. package/build/EntityQueryContext.js.map +1 -1
  13. package/build/EntityQueryContextProvider.d.ts +5 -1
  14. package/build/EntityQueryContextProvider.js +11 -4
  15. package/build/EntityQueryContextProvider.js.map +1 -1
  16. package/build/IEntityGenericCacher.d.ts +2 -2
  17. package/build/internal/CompositeFieldHolder.d.ts +13 -0
  18. package/build/internal/CompositeFieldHolder.js +7 -0
  19. package/build/internal/CompositeFieldHolder.js.map +1 -1
  20. package/build/internal/CompositeFieldValueMap.d.ts +3 -0
  21. package/build/internal/CompositeFieldValueMap.js +3 -0
  22. package/build/internal/CompositeFieldValueMap.js.map +1 -1
  23. package/build/internal/EntityDataManager.d.ts +22 -3
  24. package/build/internal/EntityDataManager.js +99 -11
  25. package/build/internal/EntityDataManager.js.map +1 -1
  26. package/build/internal/EntityFieldTransformationUtils.d.ts +20 -0
  27. package/build/internal/EntityFieldTransformationUtils.js +15 -0
  28. package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
  29. package/build/internal/EntityLoadInterfaces.d.ts +8 -0
  30. package/build/internal/EntityLoadInterfaces.js +2 -0
  31. package/build/internal/EntityLoadInterfaces.js.map +1 -1
  32. package/build/internal/EntityTableDataCoordinator.d.ts +2 -0
  33. package/build/internal/EntityTableDataCoordinator.js +2 -0
  34. package/build/internal/EntityTableDataCoordinator.js.map +1 -1
  35. package/build/internal/ReadThroughEntityCache.d.ts +8 -0
  36. package/build/internal/ReadThroughEntityCache.js +5 -0
  37. package/build/internal/ReadThroughEntityCache.js.map +1 -1
  38. package/build/internal/SingleFieldHolder.d.ts +7 -0
  39. package/build/internal/SingleFieldHolder.js +7 -0
  40. package/build/internal/SingleFieldHolder.js.map +1 -1
  41. package/build/metrics/EntityMetricsUtils.d.ts +4 -3
  42. package/build/metrics/EntityMetricsUtils.js +6 -3
  43. package/build/metrics/EntityMetricsUtils.js.map +1 -1
  44. package/build/metrics/IEntityMetricsAdapter.d.ts +21 -0
  45. package/build/metrics/IEntityMetricsAdapter.js.map +1 -1
  46. package/package.json +13 -13
  47. package/src/AuthorizationResultBasedEntityMutator.ts +133 -15
  48. package/src/EntityFieldDefinition.ts +1 -1
  49. package/src/EntityLoaderUtils.ts +43 -12
  50. package/src/EntityQueryContext.ts +68 -13
  51. package/src/EntityQueryContextProvider.ts +20 -3
  52. package/src/IEntityGenericCacher.ts +2 -2
  53. package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +98 -0
  54. package/src/__tests__/EntityQueryContext-test.ts +141 -26
  55. package/src/internal/CompositeFieldHolder.ts +15 -0
  56. package/src/internal/CompositeFieldValueMap.ts +3 -0
  57. package/src/internal/EntityDataManager.ts +170 -10
  58. package/src/internal/EntityFieldTransformationUtils.ts +20 -0
  59. package/src/internal/EntityLoadInterfaces.ts +8 -0
  60. package/src/internal/EntityTableDataCoordinator.ts +2 -0
  61. package/src/internal/ReadThroughEntityCache.ts +8 -0
  62. package/src/internal/SingleFieldHolder.ts +7 -0
  63. package/src/internal/__tests__/EntityDataManager-test.ts +708 -186
  64. package/src/metrics/EntityMetricsUtils.ts +7 -0
  65. package/src/metrics/IEntityMetricsAdapter.ts +27 -0
  66. package/src/utils/__testfixtures__/StubDatabaseAdapter.ts +13 -1
@@ -2,6 +2,7 @@ import IEntityMetricsAdapter, {
2
2
  EntityMetricsLoadType,
3
3
  EntityMetricsMutationType,
4
4
  } from './IEntityMetricsAdapter';
5
+ import { EntityQueryContext } from '../EntityQueryContext';
5
6
  import { IEntityLoadValue } from '../internal/EntityLoadInterfaces';
6
7
  import { reduceMap } from '../utils/collections/maps';
7
8
 
@@ -10,6 +11,7 @@ export const timeAndLogLoadEventAsync =
10
11
  metricsAdapter: IEntityMetricsAdapter,
11
12
  loadType: EntityMetricsLoadType,
12
13
  entityClassName: string,
14
+ queryContext: EntityQueryContext,
13
15
  ) =>
14
16
  async <TFields>(promise: Promise<readonly Readonly<TFields>[]>) => {
15
17
  const startTime = Date.now();
@@ -18,6 +20,7 @@ export const timeAndLogLoadEventAsync =
18
20
 
19
21
  metricsAdapter.logDataManagerLoadEvent({
20
22
  type: loadType,
23
+ isInTransaction: queryContext.isInTransaction(),
21
24
  entityClassName,
22
25
  duration: endTime - startTime,
23
26
  count: result.length,
@@ -31,6 +34,7 @@ export const timeAndLogLoadMapEventAsync =
31
34
  metricsAdapter: IEntityMetricsAdapter,
32
35
  loadType: EntityMetricsLoadType,
33
36
  entityClassName: string,
37
+ queryContext: EntityQueryContext,
34
38
  ) =>
35
39
  async <
36
40
  TFields extends Record<string, any>,
@@ -47,6 +51,7 @@ export const timeAndLogLoadMapEventAsync =
47
51
 
48
52
  metricsAdapter.logDataManagerLoadEvent({
49
53
  type: loadType,
54
+ isInTransaction: queryContext.isInTransaction(),
50
55
  entityClassName,
51
56
  duration: endTime - startTime,
52
57
  count,
@@ -60,6 +65,7 @@ export const timeAndLogMutationEventAsync =
60
65
  metricsAdapter: IEntityMetricsAdapter,
61
66
  mutationType: EntityMetricsMutationType,
62
67
  entityClassName: string,
68
+ queryContext: EntityQueryContext,
63
69
  ) =>
64
70
  async <T>(promise: Promise<T>) => {
65
71
  const startTime = Date.now();
@@ -68,6 +74,7 @@ export const timeAndLogMutationEventAsync =
68
74
 
69
75
  metricsAdapter.logMutatorMutationEvent({
70
76
  type: mutationType,
77
+ isInTransaction: queryContext.isInTransaction(),
71
78
  entityClassName,
72
79
  duration: endTime - startTime,
73
80
  });
@@ -19,6 +19,11 @@ export interface EntityMetricsLoadEvent {
19
19
  */
20
20
  type: EntityMetricsLoadType;
21
21
 
22
+ /**
23
+ * Whether this load is within a transaction.
24
+ */
25
+ isInTransaction: boolean;
26
+
22
27
  /**
23
28
  * Class name of the Entity being loaded.
24
29
  */
@@ -47,6 +52,11 @@ export interface EntityMetricsMutationEvent {
47
52
  */
48
53
  type: EntityMetricsMutationType;
49
54
 
55
+ /**
56
+ * Whether this mutation is within a transaction.
57
+ */
58
+ isInTransaction: boolean;
59
+
50
60
  /**
51
61
  * Class name of the Entity being mutated.
52
62
  */
@@ -85,6 +95,11 @@ export interface IncrementLoadCountEvent {
85
95
  */
86
96
  type: IncrementLoadCountEventType;
87
97
 
98
+ /**
99
+ * Whether this load is within a transaction.
100
+ */
101
+ isInTransaction: boolean;
102
+
88
103
  /**
89
104
  * Load method type for this event.
90
105
  */
@@ -114,8 +129,20 @@ export interface EntityMetricsAuthorizationEvent {
114
129
  * Class name of the Entity being authorized.
115
130
  */
116
131
  entityClassName: string;
132
+
133
+ /**
134
+ * The action being authorized.
135
+ */
117
136
  action: EntityAuthorizationAction;
137
+
138
+ /**
139
+ * The result of the authorization.
140
+ */
118
141
  evaluationResult: EntityMetricsAuthorizationResult;
142
+
143
+ /**
144
+ * The evaluation mode of the privacy policy.
145
+ */
119
146
  privacyPolicyEvaluationMode: EntityPrivacyPolicyEvaluationMode;
120
147
  }
121
148
 
@@ -49,6 +49,18 @@ export default class StubDatabaseAdapter<
49
49
  return new Map();
50
50
  }
51
51
 
52
+ private static uniqBy<T>(a: T[], keyExtractor: (k: T) => string): T[] {
53
+ const seen = new Set();
54
+ return a.filter((item) => {
55
+ const k = keyExtractor(item);
56
+ if (seen.has(k)) {
57
+ return false;
58
+ }
59
+ seen.add(k);
60
+ return true;
61
+ });
62
+ }
63
+
52
64
  protected async fetchManyWhereInternalAsync(
53
65
  _queryInterface: any,
54
66
  tableName: string,
@@ -56,7 +68,7 @@ export default class StubDatabaseAdapter<
56
68
  tableTuples: (readonly any[])[],
57
69
  ): Promise<object[]> {
58
70
  const objectCollection = this.getObjectCollectionForTable(tableName);
59
- const results = tableTuples.reduce(
71
+ const results = StubDatabaseAdapter.uniqBy(tableTuples, (tuple) => tuple.join(':')).reduce(
60
72
  (acc, tableTuple) => {
61
73
  return acc.concat(
62
74
  objectCollection.filter((obj) => {