@expo/entity 0.55.0 → 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.d.ts +1 -1
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityLoader.d.ts +18 -24
- package/build/src/AuthorizationResultBasedEntityLoader.js +37 -56
- package/build/src/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityMutator.js +26 -19
- package/build/src/AuthorizationResultBasedEntityMutator.js.map +1 -1
- package/build/src/EnforcingEntityCreator.d.ts +1 -1
- package/build/src/EnforcingEntityCreator.js +1 -1
- package/build/src/EnforcingEntityLoader.d.ts +1 -58
- package/build/src/EnforcingEntityLoader.js +0 -65
- package/build/src/EnforcingEntityLoader.js.map +1 -1
- package/build/src/Entity.d.ts +6 -0
- package/build/src/Entity.js +6 -0
- package/build/src/Entity.js.map +1 -1
- package/build/src/EntityCompanion.d.ts +2 -2
- package/build/src/EntityCompanion.js.map +1 -1
- package/build/src/EntityCompanionProvider.d.ts +1 -1
- package/build/src/EntityCompanionProvider.js +4 -4
- package/build/src/EntityConfiguration.d.ts +1 -1
- package/build/src/EntityConfiguration.js +1 -2
- package/build/src/EntityConfiguration.js.map +1 -1
- package/build/src/{EntityLoaderUtils.d.ts → EntityConstructionUtils.d.ts} +15 -29
- package/build/src/EntityConstructionUtils.js +118 -0
- package/build/src/EntityConstructionUtils.js.map +1 -0
- package/build/src/EntityDatabaseAdapter.d.ts +10 -108
- package/build/src/EntityDatabaseAdapter.js +14 -76
- package/build/src/EntityDatabaseAdapter.js.map +1 -1
- package/build/src/EntityFieldDefinition.d.ts +1 -1
- package/build/src/EntityInvalidationUtils.d.ts +41 -0
- package/build/src/EntityInvalidationUtils.js +71 -0
- package/build/src/EntityInvalidationUtils.js.map +1 -0
- package/build/src/EntityLoader.d.ts +0 -6
- package/build/src/EntityLoader.js +0 -7
- package/build/src/EntityLoader.js.map +1 -1
- package/build/src/EntityLoaderFactory.d.ts +4 -0
- package/build/src/EntityLoaderFactory.js +10 -3
- package/build/src/EntityLoaderFactory.js.map +1 -1
- package/build/src/EntityPrivacyPolicy.d.ts +27 -0
- package/build/src/EntityPrivacyPolicy.js +22 -1
- package/build/src/EntityPrivacyPolicy.js.map +1 -1
- package/build/src/EntitySecondaryCacheLoader.d.ts +14 -3
- package/build/src/EntitySecondaryCacheLoader.js +21 -4
- package/build/src/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/src/ReadonlyEntity.d.ts +4 -5
- package/build/src/ReadonlyEntity.js +7 -8
- package/build/src/ReadonlyEntity.js.map +1 -1
- package/build/src/ViewerContext.d.ts +6 -6
- package/build/src/ViewerContext.js +8 -8
- package/build/src/ViewerScopedEntityCompanion.d.ts +1 -1
- package/build/src/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/src/ViewerScopedEntityLoaderFactory.d.ts +4 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js +6 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/src/errors/EntityDatabaseAdapterError.d.ts +4 -0
- package/build/src/errors/EntityDatabaseAdapterError.js +13 -1
- package/build/src/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/src/errors/EntityError.d.ts +2 -1
- package/build/src/errors/EntityError.js +1 -0
- package/build/src/errors/EntityError.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/internal/EntityDataManager.d.ts +8 -16
- package/build/src/internal/EntityDataManager.js +8 -18
- package/build/src/internal/EntityDataManager.js.map +1 -1
- package/build/src/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/src/internal/EntityLoadInterfaces.d.ts +2 -0
- package/build/src/internal/EntityLoadInterfaces.js +2 -0
- package/build/src/internal/EntityLoadInterfaces.js.map +1 -1
- package/build/src/internal/EntityTableDataCoordinator.d.ts +2 -0
- package/build/src/internal/EntityTableDataCoordinator.js +4 -0
- package/build/src/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/src/metrics/EntityMetricsUtils.d.ts +1 -0
- package/build/src/metrics/EntityMetricsUtils.js +15 -1
- package/build/src/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/src/metrics/IEntityMetricsAdapter.d.ts +4 -1
- package/build/src/metrics/IEntityMetricsAdapter.js +3 -0
- package/build/src/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/PrivacyPolicyRule.d.ts +2 -2
- package/build/src/utils/EntityPrivacyUtils.js +11 -20
- package/build/src/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/src/utils/collections/maps.d.ts +2 -2
- package/build/src/utils/collections/maps.js +2 -2
- package/package.json +4 -4
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +4 -7
- package/src/AuthorizationResultBasedEntityLoader.ts +58 -88
- package/src/AuthorizationResultBasedEntityMutator.ts +35 -20
- package/src/EnforcingEntityCreator.ts +1 -1
- package/src/EnforcingEntityLoader.ts +1 -95
- package/src/Entity.ts +6 -0
- package/src/EntityCompanion.ts +2 -2
- package/src/EntityCompanionProvider.ts +4 -4
- package/src/EntityConfiguration.ts +8 -5
- package/src/EntityConstructionUtils.ts +168 -0
- package/src/EntityDatabaseAdapter.ts +32 -222
- package/src/EntityFieldDefinition.ts +1 -1
- package/src/{EntityLoaderUtils.ts → EntityInvalidationUtils.ts} +5 -96
- package/src/EntityLoader.ts +0 -16
- package/src/EntityLoaderFactory.ts +50 -10
- package/src/EntityPrivacyPolicy.ts +44 -1
- package/src/EntitySecondaryCacheLoader.ts +54 -3
- package/src/ReadonlyEntity.ts +9 -11
- package/src/ViewerContext.ts +10 -10
- package/src/ViewerScopedEntityCompanion.ts +1 -1
- package/src/ViewerScopedEntityLoaderFactory.ts +37 -0
- package/src/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.ts +3 -5
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +34 -419
- package/src/__tests__/ComposedCacheAdapter-test.ts +3 -3
- package/src/__tests__/EnforcingEntityLoader-test.ts +2 -134
- package/src/__tests__/EntityCompanion-test.ts +18 -0
- package/src/__tests__/EntityConfiguration-test.ts +4 -4
- package/src/__tests__/EntityDatabaseAdapter-test.ts +33 -68
- package/src/__tests__/EntityEdges-test.ts +10 -10
- package/src/__tests__/EntityLoader-test.ts +6 -4
- package/src/__tests__/EntityMutator-test.ts +27 -15
- package/src/__tests__/EntityPrivacyPolicy-test.ts +102 -0
- package/src/__tests__/EntityQueryContext-test.ts +11 -11
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +10 -5
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +6 -6
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +18 -15
- package/src/__tests__/GenericSecondaryEntityCache-test.ts +27 -5
- package/src/__tests__/ReadonlyEntity-test.ts +6 -4
- package/src/__tests__/ViewerContext-test.ts +4 -4
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +1 -0
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +0 -17
- package/src/errors/EntityDatabaseAdapterError.ts +14 -0
- package/src/errors/EntityError.ts +1 -0
- package/src/errors/__tests__/EntityDatabaseAdapterError-test.ts +9 -0
- package/src/errors/__tests__/EntityError-test.ts +13 -5
- package/src/index.ts +2 -1
- package/src/internal/EntityDataManager.ts +19 -54
- package/src/internal/EntityFieldTransformationUtils.ts +5 -5
- package/src/internal/EntityLoadInterfaces.ts +2 -0
- package/src/internal/EntityTableDataCoordinator.ts +2 -2
- package/src/internal/__tests__/CompositeFieldHolder-test.ts +8 -2
- package/src/internal/__tests__/EntityDataManager-test.ts +71 -202
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +39 -24
- package/src/metrics/EntityMetricsUtils.ts +23 -0
- package/src/metrics/IEntityMetricsAdapter.ts +3 -0
- package/src/metrics/__tests__/EntityMetricsUtils-test.ts +120 -0
- package/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.ts +2 -2
- package/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.ts +2 -2
- package/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.ts +2 -2
- package/src/rules/PrivacyPolicyRule.ts +2 -2
- package/src/rules/__tests__/AllowIfAllSubRulesAllowPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfAnySubRuleAllowsPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfInParentCascadeDeletionPrivacyPolicyRule-test.ts +11 -1
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/EvaluateIfEntityFieldPredicatePrivacyPolicyRule-test.ts +3 -3
- package/src/utils/EntityPrivacyUtils.ts +18 -29
- package/src/utils/__testfixtures__/PrivacyPolicyRuleTestUtils.ts +2 -2
- package/src/utils/__testfixtures__/StubDatabaseAdapter.ts +13 -101
- package/src/utils/__tests__/EntityCreationUtils-test.ts +6 -6
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +2 -2
- package/src/utils/collections/maps.ts +2 -2
- package/build/src/EntityLoaderUtils.js +0 -147
- package/build/src/EntityLoaderUtils.js.map +0 -1
|
@@ -130,71 +130,6 @@ class EnforcingEntityLoader {
|
|
|
130
130
|
const entityResults = await this.entityLoader.loadManyByIDsNullableAsync(ids);
|
|
131
131
|
return (0, maps_1.mapMap)(entityResults, (result) => result?.enforceValue() ?? null);
|
|
132
132
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Loads the first entity matching the selection constructed from the conjunction of specified
|
|
135
|
-
* operands, or null if no matching entity exists. Entities loaded using this method are not
|
|
136
|
-
* batched or cached.
|
|
137
|
-
*
|
|
138
|
-
* This is a convenience method for {@link loadManyByFieldEqualityConjunctionAsync}. However, the
|
|
139
|
-
* `orderBy` option must be specified to define what "first" means. If ordering doesn't matter,
|
|
140
|
-
* explicitly pass in an empty array.
|
|
141
|
-
*
|
|
142
|
-
* @param fieldEqualityOperands - list of field equality selection operand specifications
|
|
143
|
-
* @param querySelectionModifiers - orderBy and optional offset for the query
|
|
144
|
-
* @returns the first entity that matches the query or null if no entity matches the query
|
|
145
|
-
* @throws EntityNotAuthorizedError when viewer is not authorized to view the returned entity
|
|
146
|
-
*/
|
|
147
|
-
async loadFirstByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers) {
|
|
148
|
-
const entityResult = await this.entityLoader.loadFirstByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers);
|
|
149
|
-
return entityResult ? entityResult.enforceValue() : null;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Loads many entities matching the selection constructed from the conjunction of specified operands.
|
|
153
|
-
* Entities loaded using this method are not batched or cached.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* fieldEqualityOperands:
|
|
157
|
-
* `[{fieldName: 'hello', fieldValue: 1}, {fieldName: 'world', fieldValues: [2, 3]}]`
|
|
158
|
-
* Entities returned with a SQL EntityDatabaseAdapter:
|
|
159
|
-
* `WHERE hello = 1 AND world = ANY({2, 3})`
|
|
160
|
-
*
|
|
161
|
-
* @param fieldEqualityOperands - list of field equality selection operand specifications
|
|
162
|
-
* @param querySelectionModifiers - limit, offset, and orderBy for the query
|
|
163
|
-
* @returns array of entities that match the query
|
|
164
|
-
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
165
|
-
*/
|
|
166
|
-
async loadManyByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers = {}) {
|
|
167
|
-
const entityResults = await this.entityLoader.loadManyByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers);
|
|
168
|
-
return entityResults.map((result) => result.enforceValue());
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Loads many entities matching the raw WHERE clause. Corresponds to the knex `whereRaw` argument format.
|
|
172
|
-
*
|
|
173
|
-
* @remarks
|
|
174
|
-
* Important notes:
|
|
175
|
-
* - Fields in clause are database column names instead of transformed entity field names.
|
|
176
|
-
* - Entities loaded using this method are not batched or cached.
|
|
177
|
-
* - Not all database adapters implement the ability to execute this method of fetching entities.
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* rawWhereClause: `id = ?`
|
|
181
|
-
* bindings: `[1]`
|
|
182
|
-
* Entites returned `WHERE id = 1`
|
|
183
|
-
*
|
|
184
|
-
* http://knexjs.org/#Builder-whereRaw
|
|
185
|
-
* http://knexjs.org/#Raw-Bindings
|
|
186
|
-
*
|
|
187
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
188
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
189
|
-
* @param querySelectionModifiers - limit, offset, orderBy, and orderByRaw for the query
|
|
190
|
-
* @returns array of entities that match the query
|
|
191
|
-
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
192
|
-
* @throws Error when rawWhereClause or bindings are invalid
|
|
193
|
-
*/
|
|
194
|
-
async loadManyByRawWhereClauseAsync(rawWhereClause, bindings, querySelectionModifiers = {}) {
|
|
195
|
-
const entityResults = await this.entityLoader.loadManyByRawWhereClauseAsync(rawWhereClause, bindings, querySelectionModifiers);
|
|
196
|
-
return entityResults.map((result) => result.enforceValue());
|
|
197
|
-
}
|
|
198
133
|
}
|
|
199
134
|
exports.EnforcingEntityLoader = EnforcingEntityLoader;
|
|
200
135
|
//# sourceMappingURL=EnforcingEntityLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnforcingEntityLoader.js","sourceRoot":"","sources":["../../src/EnforcingEntityLoader.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EnforcingEntityLoader.js","sourceRoot":"","sources":["../../src/EnforcingEntityLoader.ts"],"names":[],"mappings":";;;AAKA,0EAA4E;AAC5E,8EAA2E;AAC3E,mDAAkD;AAElD;;;;GAIG;AACH,MAAa,qBAAqB;IAeb;IADnB,YACmB,YAOhB;QAPgB,iBAAY,GAAZ,YAAY,CAO5B;IACA,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,gCAAgC,CACpC,SAAY,EACZ,WAA+C;QAE/C,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,gCAAgC,CACnF,SAAS,EACT,WAAW,CACZ,CAAC;QACF,OAAO,IAAA,aAAM,EAAC,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE,CAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAC/C,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,yCAAyC,CAG7C,cAAiB,EACjB,oBAA6F;QAE7F,MAAM,6BAA6B,GACjC,MAAM,IAAI,CAAC,YAAY,CAAC,yCAAyC,CAC/D,cAAc,EACd,oBAAoB,CACrB,CAAC;QAEJ,OAAO,IAAI,+CAAsB,CAC/B,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,mBAAmB,EAAE,OAAO,CAAC,EAAE,EAAE;YACzF,OAAO;gBACL,IAAI,gDAAyB,CAAC,mBAAmB,CAAC;gBAClD,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;aA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AY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAC/D,OAAO,YAAY,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,qBAAqB,CAAC,EAAqB;QAC/C,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC;QACvE,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,kBAAkB,CACtB,GAAiC;QAEjC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACtE,OAAO,IAAA,aAAM,EAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,0BAA0B,CAC9B,GAAiC;QAEjC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC;QAC9E,OAAO,IAAA,aAAM,EAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF;AA1MD,sDA0MC"}
|
package/build/src/Entity.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ import { ViewerContext } from './ViewerContext';
|
|
|
24
24
|
*
|
|
25
25
|
* All concrete entity implementations should extend this class and provide their
|
|
26
26
|
* own EntityCompanionDefinition.
|
|
27
|
+
*
|
|
28
|
+
* Generic type parameters:
|
|
29
|
+
* TFields - the shape of the underlying data for this entity, typically corresponding to a database table schema. The mapping from TFields to the actual database schema is defined in the EntityCompanionDefinition for this entity.
|
|
30
|
+
* TIDField - the key of the ID field in TFields, which must be non-nullable and is used to uniquely identify individual entities
|
|
31
|
+
* TViewerContext - the type of ViewerContext that can be used with this entity
|
|
32
|
+
* TSelectedFields - the keys of fields in TFields that belong to this entity; used when there are multiple entities backed by the same underlying table with different field subsets
|
|
27
33
|
*/
|
|
28
34
|
export declare abstract class Entity<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TSelectedFields extends keyof TFields = keyof TFields> extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields> {
|
|
29
35
|
/**
|
package/build/src/Entity.js
CHANGED
|
@@ -22,6 +22,12 @@ const ReadonlyEntity_1 = require("./ReadonlyEntity");
|
|
|
22
22
|
*
|
|
23
23
|
* All concrete entity implementations should extend this class and provide their
|
|
24
24
|
* own EntityCompanionDefinition.
|
|
25
|
+
*
|
|
26
|
+
* Generic type parameters:
|
|
27
|
+
* TFields - the shape of the underlying data for this entity, typically corresponding to a database table schema. The mapping from TFields to the actual database schema is defined in the EntityCompanionDefinition for this entity.
|
|
28
|
+
* TIDField - the key of the ID field in TFields, which must be non-nullable and is used to uniquely identify individual entities
|
|
29
|
+
* TViewerContext - the type of ViewerContext that can be used with this entity
|
|
30
|
+
* TSelectedFields - the keys of fields in TFields that belong to this entity; used when there are multiple entities backed by the same underlying table with different field subsets
|
|
25
31
|
*/
|
|
26
32
|
class Entity extends ReadonlyEntity_1.ReadonlyEntity {
|
|
27
33
|
/**
|
package/build/src/Entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../../src/Entity.ts"],"names":[],"mappings":";;;AASA,mDAAgD;AAChD,mDAAgD;AAGhD,mDAAgD;AAChD,qDAAkD;AAGlD
|
|
1
|
+
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../../src/Entity.ts"],"names":[],"mappings":";;;AASA,mDAAgD;AAChD,mDAAgD;AAGhD,mDA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9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,6BAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,+BAA+B,CAsBpC,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,6BAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC1F,CAAC;CACF;AAnRD,wBAmRC"}
|
|
@@ -16,8 +16,8 @@ export interface IPrivacyPolicyClass<TPrivacyPolicy> {
|
|
|
16
16
|
export declare class EntityCompanion<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
17
17
|
readonly entityCompanionProvider: EntityCompanionProvider;
|
|
18
18
|
readonly entityCompanionDefinition: EntityCompanionDefinition<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
readonly tableDataCoordinator: EntityTableDataCoordinator<TFields, TIDField>;
|
|
20
|
+
readonly metricsAdapter: IEntityMetricsAdapter;
|
|
21
21
|
readonly privacyPolicy: TPrivacyPolicy;
|
|
22
22
|
private readonly entityLoaderFactory;
|
|
23
23
|
private readonly entityMutatorFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../../src/EntityCompanion.ts"],"names":[],"mappings":";;;AACA,+DAA4D;AAC5D,iEAA8D;AAO9D,+GAA4G;AAM5G;;GAEG;AACH,MAAa,eAAe;IAkCR;IACA;
|
|
1
|
+
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../../src/EntityCompanion.ts"],"names":[],"mappings":";;;AACA,+DAA4D;AAC5D,iEAA8D;AAO9D,+GAA4G;AAM5G;;GAEG;AACH,MAAa,eAAe;IAkCR;IACA;IAQA;IACA;IA9BF,aAAa,CAAiB;IAE7B,mBAAmB,CAOlC;IACe,oBAAoB,CAOnC;IAEF,YACkB,uBAAgD,EAChD,yBAOf,EACe,oBAAmE,EACnE,cAAqC;QAVrC,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,8BAAyB,GAAzB,yBAAyB,CAOxC;QACe,yBAAoB,GAApB,oBAAoB,CAA+C;QACnE,mBAAc,GAAd,cAAc,CAAuB;QAErD,IAAI,CAAC,aAAa,GAAG,IAAI,yBAAyB,CAAC,kBAAkB,EAAE,CAAC;QACxE,IAAI,CAAC,mBAAmB,GAAG,IAAI,yCAAmB,CAOhD,IAAI,EAAE,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAC1D,IAAI,CAAC,oBAAoB,GAAG,IAAI,2CAAoB,CAClD,uBAAuB,EACvB,oBAAoB,CAAC,mBAAmB,EACxC,yBAAyB,CAAC,WAAW,EACrC,IAAI,CAAC,aAAa,EAClB,yBAAyB,CAAC,kBAAkB,IAAI,EAAE,EAClD,IAAA,mFAAwC,EACtC,yBAAyB,CAAC,gBAAgB,IAAI,EAAE,EAChD,uBAAuB,CAAC,sBAAsB,IAAI,EAAE,CACrD,EACD,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;AA1GD,0CA0GC"}
|
|
@@ -100,6 +100,6 @@ export declare class EntityCompanionProvider {
|
|
|
100
100
|
* @param entityClass - entity class to load
|
|
101
101
|
*/
|
|
102
102
|
getCompanionForEntity<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields>(entityClass: IEntityClass<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>): EntityCompanion<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
103
|
-
|
|
103
|
+
getQueryContextProviderForDatabaseAdapterFlavor(databaseAdapterFlavor: DatabaseAdapterFlavor): EntityQueryContextProvider;
|
|
104
104
|
private getTableDataCoordinatorForEntity;
|
|
105
105
|
}
|
|
@@ -51,17 +51,17 @@ class EntityCompanionProvider {
|
|
|
51
51
|
return new EntityCompanion_1.EntityCompanion(this, entityCompanionDefinition, tableDataCoordinator, this.metricsAdapter);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
getQueryContextProviderForDatabaseAdapterFlavor(databaseAdapterFlavor) {
|
|
55
55
|
const entityDatabaseAdapterFlavor = this.databaseAdapterFlavors.get(databaseAdapterFlavor);
|
|
56
|
-
(0, invariant_1.default)(entityDatabaseAdapterFlavor, `No database
|
|
56
|
+
(0, invariant_1.default)(entityDatabaseAdapterFlavor, `No database adapter configuration found for flavor: ${databaseAdapterFlavor}`);
|
|
57
57
|
return entityDatabaseAdapterFlavor.queryContextProvider;
|
|
58
58
|
}
|
|
59
59
|
getTableDataCoordinatorForEntity(entityConfiguration, entityClassName) {
|
|
60
60
|
return (0, maps_1.computeIfAbsent)(this.tableDataCoordinatorMap, entityConfiguration.tableName, () => {
|
|
61
61
|
const entityDatabaseAdapterFlavor = this.databaseAdapterFlavors.get(entityConfiguration.databaseAdapterFlavor);
|
|
62
|
-
(0, invariant_1.default)(entityDatabaseAdapterFlavor, `No database
|
|
62
|
+
(0, invariant_1.default)(entityDatabaseAdapterFlavor, `No database adapter configuration found for flavor: ${entityConfiguration.databaseAdapterFlavor}`);
|
|
63
63
|
const entityCacheAdapterFlavor = this.cacheAdapterFlavors.get(entityConfiguration.cacheAdapterFlavor);
|
|
64
|
-
(0, invariant_1.default)(entityCacheAdapterFlavor, `No cache
|
|
64
|
+
(0, invariant_1.default)(entityCacheAdapterFlavor, `No cache adapter configuration found for flavor: ${entityConfiguration.cacheAdapterFlavor}`);
|
|
65
65
|
return new EntityTableDataCoordinator_1.EntityTableDataCoordinator(entityConfiguration, entityDatabaseAdapterFlavor.adapterProvider, entityCacheAdapterFlavor.cacheAdapterProvider, entityDatabaseAdapterFlavor.queryContextProvider, this.metricsAdapter, entityClassName);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
@@ -42,7 +42,7 @@ export declare class CompositeFieldInfo<TFields extends Record<string, any>, TID
|
|
|
42
42
|
* cachable fields, field mappings, and types of cache and database adapter.
|
|
43
43
|
*/
|
|
44
44
|
export declare class EntityConfiguration<TFields extends Record<string, any>, TIDField extends keyof TFields> {
|
|
45
|
-
readonly idField:
|
|
45
|
+
readonly idField: TIDField;
|
|
46
46
|
readonly tableName: string;
|
|
47
47
|
readonly cacheableKeys: ReadonlySet<keyof TFields>;
|
|
48
48
|
readonly compositeFieldInfo: CompositeFieldInfo<TFields, TIDField>;
|
|
@@ -24,8 +24,7 @@ class CompositeFieldInfo {
|
|
|
24
24
|
}));
|
|
25
25
|
}
|
|
26
26
|
getCompositeFieldHolderForCompositeField(compositeField) {
|
|
27
|
-
return this.compositeFieldInfoMap.get(new CompositeFieldHolder_1.CompositeFieldHolder(compositeField).serialize())
|
|
28
|
-
?.compositeFieldHolder;
|
|
27
|
+
return this.compositeFieldInfoMap.get(new CompositeFieldHolder_1.CompositeFieldHolder(compositeField).serialize())?.compositeFieldHolder;
|
|
29
28
|
}
|
|
30
29
|
getAllCompositeFieldHolders() {
|
|
31
30
|
return Array.from(this.compositeFieldInfoMap.values()).map((v) => v.compositeFieldHolder);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityConfiguration.js","sourceRoot":"","sources":["../../src/EntityConfiguration.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAKlC,0EAGyC;AACzC,mDAAwE;AAkCxE;;GAEG;AACH,MAAa,kBAAkB;IAIZ,qBAAqB,CAMpC;IAEF,YAAY,0BAAqE;QAC/E,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,CAClC,0BAA0B,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE;YAC/C,IAAA,mBAAS,EACP,aAAa,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,EACxC,mDAAmD,CACpD,CAAC;YACF,IAAA,mBAAS,EACP,aAAa,CAAC,cAAc,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,IAAI,EAClF,6CAA6C,CAC9C,CAAC;YACF,MAAM,oBAAoB,GAAG,IAAI,2CAAoB,
|
|
1
|
+
{"version":3,"file":"EntityConfiguration.js","sourceRoot":"","sources":["../../src/EntityConfiguration.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAKlC,0EAGyC;AACzC,mDAAwE;AAkCxE;;GAEG;AACH,MAAa,kBAAkB;IAIZ,qBAAqB,CAMpC;IAEF,YAAY,0BAAqE;QAC/E,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,CAClC,0BA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,MACoD;QAEpD,MAAM,oBAAoB,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC1E,KAAK,MAAM,mBAAmB,IAAI,oBAAoB,EAAE,CAAC;YACvD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EAAE,CAAC;gBAC/C,MAAM,IAAI,KAAK,CACb,6FAA6F,mBAAmB,EAAE,CACnH,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,oBAAoB,CACjC,MAAmE;QAEnE,OAAO,IAAA,gBAAS,EACd,MAAM,EACN,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;YACZ,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;gBACZ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACb,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EACD,IAAI,GAAG,EAAiB,CACzB,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,iCAAiC,CAC9C,MAAmE;QAEnE,OAAO,IAAA,aAAM,EAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;CACF;AA/HD,kDA+HC"}
|
|
@@ -2,16 +2,15 @@ import { Result } from '@expo/results';
|
|
|
2
2
|
import { IEntityClass } from './Entity';
|
|
3
3
|
import { EntityConfiguration } from './EntityConfiguration';
|
|
4
4
|
import { EntityPrivacyPolicy, EntityPrivacyPolicyEvaluationContext } from './EntityPrivacyPolicy';
|
|
5
|
-
import { EntityQueryContext
|
|
5
|
+
import { EntityQueryContext } from './EntityQueryContext';
|
|
6
6
|
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
7
7
|
import { ViewerContext } from './ViewerContext';
|
|
8
|
-
import { EntityDataManager } from './internal/EntityDataManager';
|
|
9
8
|
import { IEntityMetricsAdapter } from './metrics/IEntityMetricsAdapter';
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* Common entity loader utilities for entity construction and authorization.
|
|
12
11
|
* Methods are exposed publicly since in rare cases they may need to be called manually.
|
|
13
12
|
*/
|
|
14
|
-
export declare class
|
|
13
|
+
export declare class EntityConstructionUtils<TFields extends Record<string, any>, TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
15
14
|
private readonly viewerContext;
|
|
16
15
|
private readonly queryContext;
|
|
17
16
|
private readonly privacyPolicyEvaluationContext;
|
|
@@ -19,32 +18,8 @@ export declare class EntityLoaderUtils<TFields extends Record<string, any>, TIDF
|
|
|
19
18
|
private readonly entityClass;
|
|
20
19
|
private readonly entitySelectedFields;
|
|
21
20
|
private readonly privacyPolicy;
|
|
22
|
-
private readonly dataManager;
|
|
23
21
|
protected readonly metricsAdapter: IEntityMetricsAdapter;
|
|
24
|
-
constructor(viewerContext: TViewerContext, queryContext: EntityQueryContext, privacyPolicyEvaluationContext: EntityPrivacyPolicyEvaluationContext<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, entityConfiguration: EntityConfiguration<TFields, TIDField>, entityClass: IEntityClass<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, entitySelectedFields: TSelectedFields[] | undefined, privacyPolicy: TPrivacyPolicy,
|
|
25
|
-
private getKeyValuePairsFromObjectFields;
|
|
26
|
-
/**
|
|
27
|
-
* Invalidate all caches and local dataloaders for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
28
|
-
* @param objectFields - entity data object to be invalidated
|
|
29
|
-
*/
|
|
30
|
-
invalidateFieldsAsync(objectFields: Readonly<TFields>): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Invalidate all local dataloaders specific to a transaction for an entity's fields. Exposed primarily for internal use by EntityMutator.
|
|
33
|
-
* @param objectFields - entity data object to be invalidated
|
|
34
|
-
*/
|
|
35
|
-
invalidateFieldsForTransaction(queryContext: EntityTransactionalQueryContext, objectFields: Readonly<TFields>): void;
|
|
36
|
-
/**
|
|
37
|
-
* Invalidate all caches and local dataloaders for an entity. One potential use case would be to keep the entity
|
|
38
|
-
* framework in sync with changes made to data outside of the framework.
|
|
39
|
-
* @param entity - entity to be invalidated
|
|
40
|
-
*/
|
|
41
|
-
invalidateEntityAsync(entity: TEntity): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Invalidate all local dataloaders specific to a transaction for an entity. One potential use case would be to keep the entity
|
|
44
|
-
* framework in sync with changes made to data outside of the framework.
|
|
45
|
-
* @param entity - entity to be invalidated
|
|
46
|
-
*/
|
|
47
|
-
invalidateEntityForTransaction(queryContext: EntityTransactionalQueryContext, entity: TEntity): void;
|
|
22
|
+
constructor(viewerContext: TViewerContext, queryContext: EntityQueryContext, privacyPolicyEvaluationContext: EntityPrivacyPolicyEvaluationContext<TFields, TIDField, TViewerContext, TEntity, TSelectedFields>, entityConfiguration: EntityConfiguration<TFields, TIDField>, entityClass: IEntityClass<TFields, TIDField, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, entitySelectedFields: TSelectedFields[] | undefined, privacyPolicy: TPrivacyPolicy, metricsAdapter: IEntityMetricsAdapter);
|
|
48
23
|
/**
|
|
49
24
|
* Construct an entity from a fields object (applying field selection if applicable),
|
|
50
25
|
* checking that the ID field is specified.
|
|
@@ -66,5 +41,16 @@ export declare class EntityLoaderUtils<TFields extends Record<string, any>, TIDF
|
|
|
66
41
|
* @param fieldObjects - array of field objects
|
|
67
42
|
*/
|
|
68
43
|
constructAndAuthorizeEntitiesArrayAsync(fieldObjects: readonly Readonly<TFields>[]): Promise<readonly Result<TEntity>[]>;
|
|
44
|
+
private authorizeEntityResultAsync;
|
|
45
|
+
constructAndAuthorizeEntityAsync(fieldsObject: Readonly<TFields>): Promise<Result<TEntity>>;
|
|
46
|
+
/**
|
|
47
|
+
* Validate that field values are valid according to the field's validation function.
|
|
48
|
+
*
|
|
49
|
+
* @param fieldName - field name to validate
|
|
50
|
+
* @param fieldValues - field values to validate
|
|
51
|
+
* @throws EntityInvalidFieldValueError when a field value is invalid
|
|
52
|
+
*/
|
|
53
|
+
validateFieldAndValues<N extends keyof Pick<TFields, TSelectedFields>>(fieldName: N, fieldValues: readonly TFields[N][]): void;
|
|
69
54
|
private tryConstructEntities;
|
|
55
|
+
private tryConstructEntity;
|
|
70
56
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EntityConstructionUtils = void 0;
|
|
7
|
+
const results_1 = require("@expo/results");
|
|
8
|
+
const invariant_1 = __importDefault(require("invariant"));
|
|
9
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
10
|
+
const entityUtils_1 = require("./entityUtils");
|
|
11
|
+
const EntityInvalidFieldValueError_1 = require("./errors/EntityInvalidFieldValueError");
|
|
12
|
+
const maps_1 = require("./utils/collections/maps");
|
|
13
|
+
/**
|
|
14
|
+
* Common entity loader utilities for entity construction and authorization.
|
|
15
|
+
* Methods are exposed publicly since in rare cases they may need to be called manually.
|
|
16
|
+
*/
|
|
17
|
+
class EntityConstructionUtils {
|
|
18
|
+
viewerContext;
|
|
19
|
+
queryContext;
|
|
20
|
+
privacyPolicyEvaluationContext;
|
|
21
|
+
entityConfiguration;
|
|
22
|
+
entityClass;
|
|
23
|
+
entitySelectedFields;
|
|
24
|
+
privacyPolicy;
|
|
25
|
+
metricsAdapter;
|
|
26
|
+
constructor(viewerContext, queryContext, privacyPolicyEvaluationContext, entityConfiguration, entityClass, entitySelectedFields, privacyPolicy, metricsAdapter) {
|
|
27
|
+
this.viewerContext = viewerContext;
|
|
28
|
+
this.queryContext = queryContext;
|
|
29
|
+
this.privacyPolicyEvaluationContext = privacyPolicyEvaluationContext;
|
|
30
|
+
this.entityConfiguration = entityConfiguration;
|
|
31
|
+
this.entityClass = entityClass;
|
|
32
|
+
this.entitySelectedFields = entitySelectedFields;
|
|
33
|
+
this.privacyPolicy = privacyPolicy;
|
|
34
|
+
this.metricsAdapter = metricsAdapter;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Construct an entity from a fields object (applying field selection if applicable),
|
|
38
|
+
* checking that the ID field is specified.
|
|
39
|
+
*
|
|
40
|
+
* @param fieldsObject - fields object
|
|
41
|
+
*/
|
|
42
|
+
constructEntity(fieldsObject) {
|
|
43
|
+
const idField = this.entityConfiguration.idField;
|
|
44
|
+
const id = (0, nullthrows_1.default)(fieldsObject[idField], 'must provide ID to create an entity');
|
|
45
|
+
const entitySelectedFields = this.entitySelectedFields ?? Array.from(this.entityConfiguration.schema.keys());
|
|
46
|
+
const selectedFields = (0, entityUtils_1.pick)(fieldsObject, entitySelectedFields);
|
|
47
|
+
return new this.entityClass({
|
|
48
|
+
viewerContext: this.viewerContext,
|
|
49
|
+
id: id,
|
|
50
|
+
databaseFields: fieldsObject,
|
|
51
|
+
selectedFields,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Construct and authorize entities from fields map, returning error results for entities that fail
|
|
56
|
+
* to construct or fail to authorize.
|
|
57
|
+
*
|
|
58
|
+
* @param map - map from an arbitrary key type to an array of entity field objects
|
|
59
|
+
*/
|
|
60
|
+
async constructAndAuthorizeEntitiesAsync(map) {
|
|
61
|
+
return await (0, maps_1.mapMapAsync)(map, async (fieldObjects) => {
|
|
62
|
+
return await this.constructAndAuthorizeEntitiesArrayAsync(fieldObjects);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Construct and authorize entities from field objects array, returning error results for entities that fail
|
|
67
|
+
* to construct or fail to authorize.
|
|
68
|
+
*
|
|
69
|
+
* @param fieldObjects - array of field objects
|
|
70
|
+
*/
|
|
71
|
+
async constructAndAuthorizeEntitiesArrayAsync(fieldObjects) {
|
|
72
|
+
const uncheckedEntityResults = this.tryConstructEntities(fieldObjects);
|
|
73
|
+
return await Promise.all(uncheckedEntityResults.map((uncheckedEntityResult) => this.authorizeEntityResultAsync(uncheckedEntityResult)));
|
|
74
|
+
}
|
|
75
|
+
async authorizeEntityResultAsync(uncheckedEntityResult) {
|
|
76
|
+
if (!uncheckedEntityResult.ok) {
|
|
77
|
+
return uncheckedEntityResult;
|
|
78
|
+
}
|
|
79
|
+
return await (0, results_1.asyncResult)(this.privacyPolicy.authorizeReadAsync(this.viewerContext, this.queryContext, this.privacyPolicyEvaluationContext, uncheckedEntityResult.value, this.metricsAdapter));
|
|
80
|
+
}
|
|
81
|
+
async constructAndAuthorizeEntityAsync(fieldsObject) {
|
|
82
|
+
const uncheckedEntityResult = this.tryConstructEntity(fieldsObject);
|
|
83
|
+
return await this.authorizeEntityResultAsync(uncheckedEntityResult);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validate that field values are valid according to the field's validation function.
|
|
87
|
+
*
|
|
88
|
+
* @param fieldName - field name to validate
|
|
89
|
+
* @param fieldValues - field values to validate
|
|
90
|
+
* @throws EntityInvalidFieldValueError when a field value is invalid
|
|
91
|
+
*/
|
|
92
|
+
validateFieldAndValues(fieldName, fieldValues) {
|
|
93
|
+
const fieldDefinition = this.entityConfiguration.schema.get(fieldName);
|
|
94
|
+
(0, invariant_1.default)(fieldDefinition, `must have field definition for field = ${String(fieldName)}`);
|
|
95
|
+
for (const fieldValue of fieldValues) {
|
|
96
|
+
const isInputValid = fieldDefinition.validateInputValue(fieldValue);
|
|
97
|
+
if (!isInputValid) {
|
|
98
|
+
throw new EntityInvalidFieldValueError_1.EntityInvalidFieldValueError(this.entityClass, fieldName, fieldValue);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
tryConstructEntities(fieldsObjects) {
|
|
103
|
+
return fieldsObjects.map((fieldsObject) => this.tryConstructEntity(fieldsObject));
|
|
104
|
+
}
|
|
105
|
+
tryConstructEntity(fieldsObject) {
|
|
106
|
+
try {
|
|
107
|
+
return (0, results_1.result)(this.constructEntity(fieldsObject));
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
if (!(e instanceof Error)) {
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
return (0, results_1.result)(e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.EntityConstructionUtils = EntityConstructionUtils;
|
|
118
|
+
//# sourceMappingURL=EntityConstructionUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityConstructionUtils.js","sourceRoot":"","sources":["../../src/EntityConstructionUtils.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA4D;AAC5D,0DAAkC;AAClC,4DAAoC;AAQpC,+CAAqC;AACrC,wFAAqF;AAErF,mDAAuD;AAEvD;;;GAGG;AACH,MAAa,uBAAuB;IAef;IACA;IACA;IAOA;IACA;IAQA;IACA;IACE;IArBrB,YACmB,aAA6B,EAC7B,YAAgC,EAChC,8BAMhB,EACgB,mBAA2D,EAC3D,WAOhB,EACgB,oBAAmD,EACnD,aAA6B,EAC3B,cAAqC;QApBvC,kBAAa,GAAb,aAAa,CAAgB;QAC7B,iBAAY,GAAZ,YAAY,CAAoB;QAChC,mCAA8B,GAA9B,8BAA8B,CAM9C;QACgB,wBAAmB,GAAnB,mBAAmB,CAAwC;QAC3D,gBAAW,GAAX,WAAW,CAO3B;QACgB,yBAAoB,GAApB,oBAAoB,CAA+B;QACnD,kBAAa,GAAb,aAAa,CAAgB;QAC3B,mBAAc,GAAd,cAAc,CAAuB;IACvD,CAAC;IAEJ;;;;;OAKG;IACI,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AC,EAAE,CAAC;YACX,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,CAAC,CAAC;YACV,CAAC;YACD,OAAO,IAAA,gBAAM,EAAC,CAAC,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AApJD,0DAoJC"}
|
|
@@ -2,92 +2,6 @@ import { EntityConfiguration } from './EntityConfiguration';
|
|
|
2
2
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
3
3
|
import { FieldTransformerMap } from './internal/EntityFieldTransformationUtils';
|
|
4
4
|
import { IEntityLoadKey, IEntityLoadValue } from './internal/EntityLoadInterfaces';
|
|
5
|
-
/**
|
|
6
|
-
* Equality operand that is used for selecting entities with a field with a single value.
|
|
7
|
-
*/
|
|
8
|
-
export interface SingleValueFieldEqualityCondition<TFields extends Record<string, any>, N extends keyof TFields = keyof TFields> {
|
|
9
|
-
fieldName: N;
|
|
10
|
-
fieldValue: TFields[N];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Equality operand that is used for selecting entities with a field matching one of multiple values.
|
|
14
|
-
*/
|
|
15
|
-
export interface MultiValueFieldEqualityCondition<TFields extends Record<string, any>, N extends keyof TFields = keyof TFields> {
|
|
16
|
-
fieldName: N;
|
|
17
|
-
fieldValues: readonly TFields[N][];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A single equality operand for use in a selection clause.
|
|
21
|
-
* See EntityLoader.loadManyByFieldEqualityConjunctionAsync documentation for examples.
|
|
22
|
-
*/
|
|
23
|
-
export type FieldEqualityCondition<TFields extends Record<string, any>, N extends keyof TFields = keyof TFields> = SingleValueFieldEqualityCondition<TFields, N> | MultiValueFieldEqualityCondition<TFields, N>;
|
|
24
|
-
export declare function isSingleValueFieldEqualityCondition<TFields extends Record<string, any>, N extends keyof TFields = keyof TFields>(condition: FieldEqualityCondition<TFields, N>): condition is SingleValueFieldEqualityCondition<TFields, N>;
|
|
25
|
-
export interface TableFieldSingleValueEqualityCondition {
|
|
26
|
-
tableField: string;
|
|
27
|
-
tableValue: any;
|
|
28
|
-
}
|
|
29
|
-
export interface TableFieldMultiValueEqualityCondition {
|
|
30
|
-
tableField: string;
|
|
31
|
-
tableValues: readonly any[];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Ordering options for `orderBy` clauses.
|
|
35
|
-
*/
|
|
36
|
-
export declare enum OrderByOrdering {
|
|
37
|
-
/**
|
|
38
|
-
* Ascending order (lowest to highest).
|
|
39
|
-
* Ascending order puts smaller values first, where "smaller" is defined in terms of the %3C operator.
|
|
40
|
-
*/
|
|
41
|
-
ASCENDING = "asc",
|
|
42
|
-
/**
|
|
43
|
-
* Descending order (highest to lowest).
|
|
44
|
-
* Descending order puts larger values first, where "larger" is defined in terms of the %3E operator.
|
|
45
|
-
*/
|
|
46
|
-
DESCENDING = "desc"
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* SQL modifiers that only affect the selection but not the projection.
|
|
50
|
-
*/
|
|
51
|
-
export interface QuerySelectionModifiers<TFields extends Record<string, any>> {
|
|
52
|
-
/**
|
|
53
|
-
* Order the entities by specified columns and orders.
|
|
54
|
-
*/
|
|
55
|
-
orderBy?: {
|
|
56
|
-
/**
|
|
57
|
-
* The field name to order by.
|
|
58
|
-
*/
|
|
59
|
-
fieldName: keyof TFields;
|
|
60
|
-
/**
|
|
61
|
-
* The OrderByOrdering to order by.
|
|
62
|
-
*/
|
|
63
|
-
order: OrderByOrdering;
|
|
64
|
-
}[];
|
|
65
|
-
/**
|
|
66
|
-
* Skip the specified number of entities queried before returning.
|
|
67
|
-
*/
|
|
68
|
-
offset?: number;
|
|
69
|
-
/**
|
|
70
|
-
* Limit the number of entities returned.
|
|
71
|
-
*/
|
|
72
|
-
limit?: number;
|
|
73
|
-
}
|
|
74
|
-
export interface QuerySelectionModifiersWithOrderByRaw<TFields extends Record<string, any>> extends QuerySelectionModifiers<TFields> {
|
|
75
|
-
/**
|
|
76
|
-
* Order the entities by a raw SQL `ORDER BY` clause.
|
|
77
|
-
*/
|
|
78
|
-
orderByRaw?: string;
|
|
79
|
-
}
|
|
80
|
-
export interface TableQuerySelectionModifiers {
|
|
81
|
-
orderBy: {
|
|
82
|
-
columnName: string;
|
|
83
|
-
order: OrderByOrdering;
|
|
84
|
-
}[] | undefined;
|
|
85
|
-
offset: number | undefined;
|
|
86
|
-
limit: number | undefined;
|
|
87
|
-
}
|
|
88
|
-
export interface TableQuerySelectionModifiersWithOrderByRaw extends TableQuerySelectionModifiers {
|
|
89
|
-
orderByRaw: string | undefined;
|
|
90
|
-
}
|
|
91
5
|
/**
|
|
92
6
|
* A database adapter is an interface by which entity objects can be
|
|
93
7
|
* fetched, inserted, updated, and deleted from a database. This base class
|
|
@@ -95,8 +9,8 @@ export interface TableQuerySelectionModifiersWithOrderByRaw extends TableQuerySe
|
|
|
95
9
|
* implementing database-specific logic for a type of database.
|
|
96
10
|
*/
|
|
97
11
|
export declare abstract class EntityDatabaseAdapter<TFields extends Record<string, any>, TIDField extends keyof TFields> {
|
|
98
|
-
|
|
99
|
-
|
|
12
|
+
protected readonly entityConfiguration: EntityConfiguration<TFields, TIDField>;
|
|
13
|
+
protected readonly fieldTransformerMap: FieldTransformerMap;
|
|
100
14
|
constructor(entityConfiguration: EntityConfiguration<TFields, TIDField>);
|
|
101
15
|
/**
|
|
102
16
|
* Transformer definitions for field types. Used to modify values as they are read from or written to
|
|
@@ -115,27 +29,17 @@ export declare abstract class EntityDatabaseAdapter<TFields extends Record<strin
|
|
|
115
29
|
fetchManyWhereAsync<TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>, TSerializedLoadValue, TLoadValue extends IEntityLoadValue<TSerializedLoadValue>>(queryContext: EntityQueryContext, key: TLoadKey, values: readonly TLoadValue[]): Promise<ReadonlyMap<TLoadValue, readonly Readonly<TFields>[]>>;
|
|
116
30
|
protected abstract fetchManyWhereInternalAsync(queryInterface: any, tableName: string, tableColumns: readonly string[], tableTuples: (readonly any[])[]): Promise<object[]>;
|
|
117
31
|
/**
|
|
118
|
-
* Fetch
|
|
119
|
-
*
|
|
32
|
+
* Fetch one objects where key is equal to value, null if no matching object exists.
|
|
33
|
+
* Returned object is not guaranteed to be deterministic. Most concrete implementations will implement this
|
|
34
|
+
* with a "first" or "limit 1" query.
|
|
120
35
|
*
|
|
121
36
|
* @param queryContext - query context with which to perform the fetch
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
124
|
-
* @returns
|
|
125
|
-
*/
|
|
126
|
-
fetchManyByFieldEqualityConjunctionAsync<N extends keyof TFields>(queryContext: EntityQueryContext, fieldEqualityOperands: FieldEqualityCondition<TFields, N>[], querySelectionModifiers: QuerySelectionModifiers<TFields>): Promise<readonly Readonly<TFields>[]>;
|
|
127
|
-
protected abstract fetchManyByFieldEqualityConjunctionInternalAsync(queryInterface: any, tableName: string, tableFieldSingleValueEqualityOperands: TableFieldSingleValueEqualityCondition[], tableFieldMultiValueEqualityOperands: TableFieldMultiValueEqualityCondition[], querySelectionModifiers: TableQuerySelectionModifiers): Promise<object[]>;
|
|
128
|
-
/**
|
|
129
|
-
* Fetch many objects matching the raw WHERE clause.
|
|
130
|
-
*
|
|
131
|
-
* @param queryContext - query context with which to perform the fetch
|
|
132
|
-
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
|
133
|
-
* @param bindings - array of positional bindings or object of named bindings
|
|
134
|
-
* @param querySelectionModifiers - limit, offset, and orderBy for the query
|
|
135
|
-
* @returns array of objects matching the query
|
|
37
|
+
* @param key - load key being queried
|
|
38
|
+
* @param values - load value being queried
|
|
39
|
+
* @returns object that matches the query for the value
|
|
136
40
|
*/
|
|
137
|
-
|
|
138
|
-
protected abstract
|
|
41
|
+
fetchOneWhereAsync<TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>, TSerializedLoadValue, TLoadValue extends IEntityLoadValue<TSerializedLoadValue>>(queryContext: EntityQueryContext, key: TLoadKey, value: TLoadValue): Promise<Readonly<TFields> | null>;
|
|
42
|
+
protected abstract fetchOneWhereInternalAsync(queryInterface: any, tableName: string, tableColumns: readonly string[], tableTuple: readonly any[]): Promise<object | null>;
|
|
139
43
|
/**
|
|
140
44
|
* Insert an object.
|
|
141
45
|
*
|
|
@@ -165,6 +69,4 @@ export declare abstract class EntityDatabaseAdapter<TFields extends Record<strin
|
|
|
165
69
|
*/
|
|
166
70
|
deleteAsync<K extends keyof TFields>(queryContext: EntityQueryContext, idField: K, id: any): Promise<void>;
|
|
167
71
|
protected abstract deleteInternalAsync(queryInterface: any, tableName: string, tableIdField: string, id: any): Promise<number>;
|
|
168
|
-
private convertToTableQueryModifiersWithOrderByRaw;
|
|
169
|
-
private convertToTableQueryModifiers;
|
|
170
72
|
}
|