@@ -8,18 +8,11 @@ import {
88 EntityCompositeFieldValue ,
99 EntityConfiguration ,
1010} from './EntityConfiguration' ;
11- import {
12- FieldEqualityCondition ,
13- isSingleValueFieldEqualityCondition ,
14- QuerySelectionModifiers ,
15- QuerySelectionModifiersWithOrderByRaw ,
16- } from './EntityDatabaseAdapter' ;
1711import { EntityLoaderUtils } from './EntityLoaderUtils' ;
1812import { EntityPrivacyPolicy } from './EntityPrivacyPolicy' ;
1913import { EntityQueryContext } from './EntityQueryContext' ;
2014import { ReadonlyEntity } from './ReadonlyEntity' ;
2115import { ViewerContext } from './ViewerContext' ;
22- import { EntityInvalidFieldValueError } from './errors/EntityInvalidFieldValueError' ;
2316import { EntityNotFoundError } from './errors/EntityNotFoundError' ;
2417import { CompositeFieldHolder , CompositeFieldValueHolder } from './internal/CompositeFieldHolder' ;
2518import { CompositeFieldValueMap } from './internal/CompositeFieldValueMap' ;
@@ -265,87 +258,14 @@ export class AuthorizationResultBasedEntityLoader<
265258 } ) ;
266259 }
267260
268- /**
269- * Authorization-result-based version of the EnforcingEntityLoader method by the same name.
270- * @returns the first entity results that matches the query, where result error can be
271- * UnauthorizedError
272- */
273- async loadFirstByFieldEqualityConjunctionAsync < N extends keyof Pick < TFields , TSelectedFields > > (
274- fieldEqualityOperands : FieldEqualityCondition < TFields , N > [ ] ,
275- querySelectionModifiers : Omit < QuerySelectionModifiers < TFields > , 'limit' > &
276- Required < Pick < QuerySelectionModifiers < TFields > , 'orderBy' > > ,
277- ) : Promise < Result < TEntity > | null > {
278- const results = await this . loadManyByFieldEqualityConjunctionAsync ( fieldEqualityOperands , {
279- ...querySelectionModifiers ,
280- limit : 1 ,
281- } ) ;
282- return results [ 0 ] ?? null ;
283- }
284-
285- /**
286- * Authorization-result-based version of the EnforcingEntityLoader method by the same name.
287- * @returns array of entity results that match the query, where result error can be UnauthorizedError
288- */
289- async loadManyByFieldEqualityConjunctionAsync < N extends keyof Pick < TFields , TSelectedFields > > (
290- fieldEqualityOperands : FieldEqualityCondition < TFields , N > [ ] ,
291- querySelectionModifiers : QuerySelectionModifiers < TFields > = { } ,
292- ) : Promise < readonly Result < TEntity > [ ] > {
293- for ( const fieldEqualityOperand of fieldEqualityOperands ) {
294- const fieldValues = isSingleValueFieldEqualityCondition ( fieldEqualityOperand )
295- ? [ fieldEqualityOperand . fieldValue ]
296- : fieldEqualityOperand . fieldValues ;
297- this . validateFieldAndValues ( fieldEqualityOperand . fieldName , fieldValues ) ;
298- }
299-
300- const fieldObjects = await this . dataManager . loadManyByFieldEqualityConjunctionAsync (
301- this . queryContext ,
302- fieldEqualityOperands ,
303- querySelectionModifiers ,
304- ) ;
305- return await this . utils . constructAndAuthorizeEntitiesArrayAsync ( fieldObjects ) ;
306- }
307-
308- /**
309- * Authorization-result-based version of the EnforcingEntityLoader method by the same name.
310- * @returns array of entity results that match the query, where result error can be UnauthorizedError
311- * @throws Error when rawWhereClause or bindings are invalid
312- */
313- async loadManyByRawWhereClauseAsync (
314- rawWhereClause : string ,
315- bindings : any [ ] | object ,
316- querySelectionModifiers : QuerySelectionModifiersWithOrderByRaw < TFields > = { } ,
317- ) : Promise < readonly Result < TEntity > [ ] > {
318- const fieldObjects = await this . dataManager . loadManyByRawWhereClauseAsync (
319- this . queryContext ,
320- rawWhereClause ,
321- bindings ,
322- querySelectionModifiers ,
323- ) ;
324- return await this . utils . constructAndAuthorizeEntitiesArrayAsync ( fieldObjects ) ;
325- }
326-
327- private validateFieldAndValues < N extends keyof Pick < TFields , TSelectedFields > > (
328- fieldName : N ,
329- fieldValues : readonly TFields [ N ] [ ] ,
330- ) : void {
331- const fieldDefinition = this . entityConfiguration . schema . get ( fieldName ) ;
332- invariant ( fieldDefinition , `must have field definition for field = ${ String ( fieldName ) } ` ) ;
333- for ( const fieldValue of fieldValues ) {
334- const isInputValid = fieldDefinition . validateInputValue ( fieldValue ) ;
335- if ( ! isInputValid ) {
336- throw new EntityInvalidFieldValueError ( this . entityClass , fieldName , fieldValue ) ;
337- }
338- }
339- }
340-
341261 private validateFieldAndValuesAndConvertToHolders < N extends keyof Pick < TFields , TSelectedFields > > (
342262 fieldName : N ,
343263 fieldValues : readonly NonNullable < TFields [ N ] > [ ] ,
344264 ) : {
345265 loadKey : SingleFieldHolder < TFields , TIDField , N > ;
346266 loadValues : readonly SingleFieldValueHolder < TFields , N > [ ] ;
347267 } {
348- this . validateFieldAndValues ( fieldName , fieldValues ) ;
268+ this . utils . validateFieldAndValues ( fieldName , fieldValues ) ;
349269
350270 return {
351271 loadKey : new SingleFieldHolder < TFields , TIDField , N > ( fieldName ) ,
@@ -388,7 +308,7 @@ export class AuthorizationResultBasedEntityLoader<
388308 ) ;
389309 for ( const field of compositeField ) {
390310 const fieldValue = compositeFieldValueHolder . compositeFieldValue [ field ] ;
391- this . validateFieldAndValues ( field , [ fieldValue ] ) ;
311+ this . utils . validateFieldAndValues ( field , [ fieldValue ] ) ;
392312 }
393313 }
394314
0 commit comments