///
import { Document, DocumentObjectFromSchemaSettings } from "./Document";
import { Model } from "./Model";
import { DynamoDB } from "aws-sdk";
export interface DynamoDBSetTypeResult {
name: string;
dynamodbType: string;
isOfType: (value: ValueType, type?: "toDynamo" | "fromDynamo", settings?: Partial) => boolean;
isSet: true;
customType?: any;
toDynamo: (val: GeneralValueType[]) => SetValueType;
fromDynamo: (val: SetValueType) => Set;
}
export interface DynamoDBTypeResult {
name: string;
dynamodbType: string;
isOfType: (value: ValueType) => {
value: ValueType;
type: string;
};
isSet: false;
customType?: any;
nestedType: boolean;
set?: DynamoDBSetTypeResult;
}
declare type SetValueType = {
wrapperName: "Set";
values: ValueType[];
type: string;
};
declare type GeneralValueType = string | boolean | number | Buffer | Date;
export declare type ValueType = GeneralValueType | {
[key: string]: ValueType;
} | ValueType[] | SetValueType;
declare type AttributeType = string | StringConstructor | BooleanConstructor | NumberConstructor | typeof Buffer | DateConstructor | ObjectConstructor | ArrayConstructor;
interface SchemaSettings {
timestamps?: boolean | {
createdAt?: string;
updatedAt?: string;
};
saveUnknown?: boolean | string[];
}
interface IndexDefinition {
name?: string;
global?: boolean;
rangeKey?: string;
project?: boolean | string[];
throughput?: "ON_DEMAND" | number | {
read: number;
write: number;
};
}
interface AttributeDefinitionTypeSettings {
storage?: "miliseconds" | "seconds";
}
interface AttributeDefinition {
type: AttributeType | {
value: DateConstructor;
settings?: AttributeDefinitionTypeSettings;
} | {
value: AttributeType;
};
schema?: SchemaDefinition | SchemaDefinition[];
default?: ValueType | (() => ValueType);
forceDefault?: boolean;
validate?: ValueType | RegExp | ((value: ValueType) => boolean);
required?: boolean;
enum?: ValueType[];
get?: ((value: ValueType) => ValueType);
set?: ((value: ValueType) => ValueType);
index?: boolean | IndexDefinition | IndexDefinition[];
hashKey?: boolean;
rangeKey?: boolean;
}
export interface SchemaDefinition {
[attribute: string]: AttributeType | AttributeDefinition;
}
interface SchemaGetAttributeTypeSettings {
unknownAttributeAllowed: boolean;
}
interface SchemaGetAttributeSettingValue {
returnFunction: boolean;
}
export declare class Schema {
settings: SchemaSettings;
schemaObject: SchemaDefinition;
attributes: () => string[];
getCreateTableAttributeParams(model: Model): Promise>;
getAttributeType(key: string, value?: ValueType, settings?: SchemaGetAttributeTypeSettings): string;
static attributeTypes: {
findDynamoDBType: (type: any) => DynamoDBSetTypeResult | DynamoDBTypeResult;
findTypeForValue: (...args: any[]) => DynamoDBSetTypeResult | DynamoDBTypeResult;
};
getHashKey: () => string;
getRangeKey: () => string | void;
defaultCheck(key: string, value: ValueType, settings: any): Promise;
requiredCheck: (key: string, value: ValueType) => Promise;
getAttributeSettingValue(setting: string, key: string, settings?: SchemaGetAttributeSettingValue): any;
getIndexAttributes: () => Promise<{
index: IndexDefinition;
attribute: string;
}[]>;
getSettingValue: (setting: string) => any;
getAttributeTypeDetails: (key: string, settings?: {
standardKey?: boolean;
}) => DynamoDBTypeResult | DynamoDBSetTypeResult;
getAttributeValue: (key: string, settings?: {
standardKey?: boolean;
}) => AttributeDefinition;
getIndexes: (model: Model) => Promise<{
GlobalSecondaryIndexes?: IndexItem[];
LocalSecondaryIndexes?: IndexItem[];
}>;
getIndexRangeKeyAttributes: () => Promise<{
attribute: string;
}[]>;
constructor(object: SchemaDefinition, settings?: SchemaSettings);
}
export interface IndexItem {
IndexName: string;
KeySchema: ({
AttributeName: string;
KeyType: "HASH" | "RANGE";
})[];
Projection: {
ProjectionType: "KEYS_ONLY" | "INCLUDE" | "ALL";
NonKeyAttributes?: string[];
};
ProvisionedThroughput?: {
"ReadCapacityUnits": number;
"WriteCapacityUnits": number;
};
}
export {};