module import { Metadata } from '../../decorator/metadata/metadata' ; import { curry } from '../../helper/curry.function' ; import { ConditionalParamsHost , UpdateParamsHost } from '../operation-params.type' ; import { StandardRequest } from '../request/standard.request' ; import { buildFilterExpression } from './condition-expression-builder' ; import { addExpression } from './param-util' ; import { prepareAndAddUpdateExpressions } from './prepare-and-add-update-expressions.function' ; import { ConditionExpressionDefinitionChain , ConditionExpressionDefinitionChainTyped , RequestConditionFunctionTyped , } from './type/condition-expression-definition-chain' ; import { ConditionExpressionDefinitionFunction } from './type/condition-expression-definition-function' ; import { OperatorAlias } from './type/condition-operator-alias.type' ; import { OPERATOR_TO_ALIAS_MAP } from './type/condition-operator-to-alias-map.const' ; import { ConditionOperator } from './type/condition-operator.type' ; import { ExpressionType } from './type/expression-type.type' ; import { Expression } from './type/expression.type' ; import { SortKeyConditionFunction } from './type/sort-key-condition-function' ; import { UpdateActionDef } from './type/update-action-def' ; import { UPDATE_ACTION_DEFS } from './type/update-action-defs.const' ; import { RequestUpdateFunction , UpdateExpressionDefinitionChain , UpdateExpressionDefinitionChainTyped , } from './type/update-expression-definition-chain' ; import { UpdateExpressionDefinitionFunction } from './type/update-expression-definition-function' ; import { UpdateExpression } from './type/update-expression.type' ; import { buildUpdateExpression } from './update-expression-builder' ; param attributePath param request param metadata hidden export function addUpdate < R extends UpdateParamsHost , T , K extends keyof T > ( attributePath , request , metadata ) { const f = ( operator ) => { return ( ... values ) : R => { const copy = [ ... values ] ; const curried = curry < string , UpdateActionDef , any [ ] , string [ ] | undefined , Metadata < any > | undefined , UpdateExpression > ( buildUpdateExpression ) ; const updateDefFn = curried ( < string > attributePath , operator , copy ) ; prepareAndAddUpdateExpressions ( metadata , request . params , [ updateDefFn ] ) ; return request ; } ; } ; return createUpdateFunctions < RequestUpdateFunction < R , T , K > > ( f ) ; } hidden export function addCondition < R extends ConditionalParamsHost , T , K extends keyof T > ( expressionType , attributePath , request , metadata ? ) { const f = ( operator ) => { return ( ... values ) : R => { return doAddCondition ( expressionType , < string > attributePath , request , metadata , operator , ... values ) ; } ; } ; return createConditionFunctions < RequestConditionFunctionTyped < R , T , K > > ( f ) ; } hidden export function addSortKeyCondition < R extends ConditionalParamsHost > ( keyName , request ) ; hidden export function addSortKeyCondition < T , R extends ConditionalParamsHost > ( keyName , request , metadata ) ; hidden export function addSortKeyCondition < T , R extends ConditionalParamsHost > ( keyName , request , metadata ? ) { const f = ( operator ) => { return ( ... values ) : R => { return doAddCondition ( 'KeyConditionExpression' , < string > keyName , request , metadata , operator , ... values ) ; } ; } ; return createConditionFunctions ( f , '=' , '<=' , '<' , '>' , '>=' , 'begins_with' , 'BETWEEN' ) ; } hidden export function doAddCondition < T , R extends ConditionalParamsHost > ( expressionType , attributePath , request , metadata , operator , ... values ) { const copy = [ ... values ] ; const existingValueKeys = request . params . ExpressionAttributeValues ? Object . keys ( request . params . ExpressionAttributeValues ) : [ ] ; const condition = buildFilterExpression ( attributePath , operator , copy , existingValueKeys , metadata ) ; addExpression ( expressionType , condition , request . params ) ; return request ; } hidden export function addPartitionKeyCondition < R extends StandardRequest < any , any , any , any > > ( keyName , keyValue , request ) ; export function addPartitionKeyCondition < T , R extends StandardRequest < T , any , any , any > > ( keyName , keyValue , request , metadata ) ; export function addPartitionKeyCondition < T , R extends StandardRequest < T , any , any , any > > ( keyName , keyValue , request , metadata ? ) { if ( metadata ) { return addSortKeyCondition ( keyName , request , metadata ) . equals ( keyValue ) ; } else { return addSortKeyCondition ( keyName , request ) . equals ( keyValue ) ; } } hidden export function updateDefinitionFunction ( attributePath ) ; export function updateDefinitionFunction < T > ( attributePath ) ; export function updateDefinitionFunction < T , K extends keyof T > ( attributePath ) ; export function updateDefinitionFunction < T > ( attributePath ) { const f = ( operation ) => { return ( ... values ) : UpdateExpressionDefinitionFunction => { const copy = [ ... values ] ; const curried = curry < string , UpdateActionDef , any [ ] , string [ ] | undefined , Metadata < any > | undefined , UpdateExpression > ( buildUpdateExpression ) ; return curried ( < string > attributePath , operation , copy ) ; } ; } ; return createUpdateFunctions < UpdateExpressionDefinitionChain > ( f ) ; } hidden export function propertyDefinitionFunction < T > ( attributePath ) ; export function propertyDefinitionFunction < T , K extends keyof T > ( attributePath ) ; export function propertyDefinitionFunction < T > ( attributePath ) { const f = ( operator ) => { return ( ... values ) : ConditionExpressionDefinitionFunction => { const copy = [ ... values ] ; const curried = curry < string , ConditionOperator , any [ ] , string [ ] , Metadata < any > , Expression > ( buildFilterExpression ) ; return < ConditionExpressionDefinitionFunction > curried ( < string > attributePath , operator , copy ) ; } ; } ; return createConditionFunctions < ConditionExpressionDefinitionChain > ( f ) ; } param { ( operator : ConditionOperator ) => any } impl hidden function createUpdateFunctions < T > ( impl ) { return UPDATE_ACTION_DEFS . reduce ( ( result , updateActionDef ) => { Reflect . set ( < any > result , updateActionDef . action , impl ( updateActionDef ) ) ; return result ; } , < T > { } ) ; } param { ( operator : ConditionOperator ) => any } impl hidden function createConditionFunctions < T > ( impl , ... operators ) { const includedAlias = operators && operators . length ? operators : < ConditionOperator [ ] > Object . keys ( OPERATOR_TO_ALIAS_MAP ) ; return includedAlias . reduce ( ( result , operator ) => { const alias = OPERATOR_TO_ALIAS_MAP [ operator ] ; if ( Array . isArray ( alias ) ) { alias . forEach ( ( a ) => Reflect . set ( < any > result , a , impl ( operator ) ) ) ; } else { Reflect . set ( < any > result , alias , impl ( operator ) ) ; } return result ; } , < T > { } ) ; }