UNPKG

@altostra/core

Version:

Core library for shared types and logic

51 lines (50 loc) 2.68 kB
export declare const MAX_BATCH_ITEMS_READ_COUNT = 100; export declare const MAX_BATCH_ITEMS_WRITE_COUNT = 25; /** * Checks if a given value is an error that was thrown because DynamoDB conditional * write failed to meet its condition. * @param err The error to check * @returns `true` if the error is DynamoDB conditional check error. \ * Otherwise, `false`. */ export declare function isDynamoDBConditionalCheckFailureError(err: unknown): boolean; /** * Checks if a given value is an error that was thrown because a transaction was cancelled. \ * Usually because DynamoDB conditional check failure. * @param err The error to check * @returns `true` if the error is DynamoDB transaction cancelled error. \ * Otherwise, `false`. */ export declare function isDynamoDBTransactionCanceledError(err: unknown): boolean; export interface ConditionalExpression { ConditionExpression: string; ExpressionAttributeNames: Record<string, string>; } /** * Creates a conditional that prevent a record to be put into a DynamoDB table * if a record with its partition-key already exist * @param pkKey The key that is used as partition key (default = `'pk'`) * @param attributeName The name of the attribute as it is being used in the expression, * without the `'#'` prefix (default = `'pk'`) * @returns An object containing the expression and expression-attribute-names * that can be used in DynamoDB put query */ export declare function recordDoesNotExistConditionalExpression(pkKey?: string, attributeName?: string): ConditionalExpression; /** * Creates a conditional that prevent a record being updated in a DynamoDB table * unless it exists * @param pkKey The key that is used as partition key (default = `'pk'`) * @param attributeName The name of the attribute as it is being used in the expression, * without the `'#'` prefix (default = `'pk'`) * @returns An object containing the expression and expression-attribute-names * that can be used in DynamoDB put query */ export declare function recordExistsConditionalExpression(pkKey?: string, attributeName?: string): ConditionalExpression; export declare type DynamoDBScalar = boolean | number | string | null; export interface DynamoDBMap { [k: string]: DynamoDBType; } export declare type DynamoDBType = DynamoDBMap | DynamoDBScalar | DynamoDBType[]; export declare const isDynamoDBScalar: import("@altostra/type-validations").TypeValidation<DynamoDBScalar>; export declare const isDynamoDBType: import("@altostra/type-validations").WithRecursionValidation<DynamoDBType>; export declare const isDynamoDBMap: import("@altostra/type-validations").TypeValidation<Record<string | number, DynamoDBType>>;