// Custom made dynamoose declaration file. import * as _AWS from 'aws-sdk'; declare module "dynamoose" { export var AWS: typeof _AWS; export function local(url?: string): void; export function ddb(): _AWS.DynamoDB; export function setDocumentClient(documentClient: _AWS.DynamoDB.DocumentClient): void; export function model( modelName: string, schema: Schema | SchemaAttributes, options?: ModelOption ): ModelConstructor; export function setDefaults(options: ModelOption): void; export function setDDB(ddb: _AWS.DynamoDB): void; export function revertDDB(): void; export function transaction( items: Array< Promise> | _AWS.DynamoDB.TransactWriteItem | _AWS.DynamoDB.TransactGetItem >, options?: TransactionOptions, next?: (err: Error, data: TransactionReturnData) => void ): Promise> export interface TransactionReturnData { TransactItems: Array> } export interface TransactionOptions { type: 'get' | 'write' } export interface ModelOption { create?: boolean, // Create table in DB, if it does not exist, update?: boolean, // Update remote indexes if they do not match local index structure waitForActive?: boolean, // Wait for table to be created before trying to us it waitForActiveTimeout?: number, // wait 3 minutes for table to activate prefix?: string, // Set table name prefix suffix?: string, // Set table name suffix streamOptions?: { // Set table stream options enabled: boolean, // Enable/disable stream type: 'NEW_IMAGE'|'OLD_IMAGE'|'NEW_AND_OLD_IMAGES'|'KEYS_ONLY', // https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_StreamSpecification.html#DDB-Type-StreamSpecification-StreamViewType }, serverSideEncryption?: boolean, // Set SSESpecification.Enabled (server-side encryption) to true or false (default: true) } /** * Schema */ export class Schema { constructor(schema: SchemaAttributes, options?: SchemaOptions); method(name: string, fn: any): any; parseDynamo(model: any, dynamoObj: any): any; static(name: string, fn: any): any; toDynamo(model: any): any; virtual(name: string, options: any): any; virtualpath(name: string): any; } export interface RawSchemaAttributeDefinition { [key: string]: SchemaAttributeDefinition | RawSchemaAttributeDefinition; } export interface SchemaAttributeDefinition { type: Constructor; validate?: (v: Type) => boolean | Promise; hashKey?: boolean; rangeKey?: boolean; required?: boolean; get?: () => Type; set?: (v: Type) => void; trim?: boolean; lowercase?: boolean; uppercase?: boolean; /** * Indicating Secondary Index. * 'true' is means local, project all */ index?: boolean | IndexDefinition | IndexDefinition[]; default?: (() => Type) | Type } export interface SchemaOptions { throughput?: boolean | { read: number, write: number } | "ON_DEMAND"; useNativeBooleans?: boolean; useDocumentTypes?: boolean; timestamps?: boolean | { createdAt: string, updatedAt: string }; expires?: number | { ttl: number, attribute: string, returnExpiredItems: boolean }; saveUnknown?: boolean; // @todo more strong type definition attributeToDynamo?: (name: string, json: any, model: any, defaultFormatter: any) => any; attributeFromDynamo?: (name: string, json: any, fallback: any) => any; } export interface SchemaAttributes { [key: string]: ( SchemaAttributeDefinition | SchemaAttributeDefinition<[NumberConstructor], number[]> | SchemaAttributeDefinition | SchemaAttributeDefinition | SchemaAttributeDefinition<[StringConstructor], string[]> | SchemaAttributeDefinition | SchemaAttributeDefinition> | SchemaAttributeDefinition | RawSchemaAttributeDefinition | NumberConstructor | [NumberConstructor] | DateConstructor | StringConstructor | [StringConstructor] | ObjectConstructor | ArrayConstructor ) } /** * Index */ interface IndexDefinition { name?: string; global?: boolean; rangeKey?: string; project?: boolean | string[]; throughput?: number | { read: number, write: number }; } /** * Table */ export class Table { constructor(name: string, schema: any, options: any, base: any); create(next: any): any; createIndex(attributes: any, indexSpec: any): any; delete(next: any): any; deleteIndex(indexname: string): any; describe(next: any): any; init(next: any): any; update(next: any): any; waitForActive(timeout: any, next: any): any; getTableReq(): any; } /** * Model */ export class Model { constructor(obj: ModelData); delete(callback?: (err: Error) => void): Promise; put(options: PutOptions, callback?: (err: Error) => void): Promise>; put(callback: (err: Error) => void): Promise>; save(options: SaveOptions, callback?: (err: Error) => void): Promise>; save(callback?: (err: Error) => void): Promise>; originalItem(): object; populate(path: string | PopulateOptions): Promise & T> } type PopulateOptions = { path: string, model: string, populate?: PopulateOptions } export interface PutOptions { /** * Overwrite existing item. Defaults to true for `model.put` and false for `Model.create`. */ overwrite?: boolean; /** * Whether to update the documents timestamps or not. Defaults to true. */ updateTimestamps?: boolean; /** * Whether to update the documents expires or not. Defaults to false. */ updateExpires?: boolean; /** * An expression for a conditional update. See the AWS documentation for more information about condition expressions. */ condition?: string; /** * A map of name substitutions for the condition expression. */ conditionNames?: any; /** * A map of values for the condition expression. Note that in order for automatic object conversion to work, the keys in this object must match schema attribute names. */ conditionValues?: any; } type SaveOptions = PutOptions; export interface ModelConstructor { new(value?: DataSchema): ModelSchema; (value?: DataSchema): ModelSchema; readonly prototype: ModelSchema; batchPut(items: DataSchema[], options?: PutOptions, callback?: (err: Error, items: ModelSchema[]) => void): Promise[]>; batchPut(items: DataSchema[], callback?: (err: Error, items: ModelSchema[]) => void): Promise[]>; create(item: DataSchema, options?: PutOptions, callback?: (err: Error, model: ModelSchema) => void): Promise>; create(item: DataSchema, callback?: (err: Error, model: ModelSchema) => void): Promise>; create(item: DataSchema, options?: PutOptions): Promise>; get(key: KeySchema, callback?: (err: Error, data: DataSchema) => void): Promise | undefined>; batchGet(key: KeySchema[], callback?: (err: Error, data: DataSchema) => void): Promise[]>; delete(key: KeySchema, callback?: (err: Error) => void): Promise; batchDelete(keys: KeySchema[], callback?: (err: Error) => void): Promise; query(query: QueryFilter, callback?: (err: Error, results: ModelSchema[]) => void): QueryInterface, QueryResult>>; queryOne(query: QueryFilter, callback?: (err: Error, results: ModelSchema) => void): QueryInterface, ModelSchema>; scan(filter?: ScanFilter, callback?: (err: Error, results: ModelSchema[]) => void): ScanInterface>; update(key: KeySchema, update: UpdateUpdate, options: UpdateOptions, callback: (err: Error, items: ModelSchema[]) => void): void; update(key: KeySchema, update: UpdateUpdate, callback: (err: Error, items: ModelSchema[]) => void): void; update(key: KeySchema, update: UpdateUpdate, options?: UpdateOptions): Promise>; transaction: ModelTransactionConstructor } type ModelSchema = Model & T; /** * Update */ /** * Updates and existing item in the table. Three types of updates: $PUT, $ADD, and $DELETE. * Put is the default behavior. */ type UpdateUpdate = ( Partial | { $PUT: Partial } | { $ADD: Partial } | { $DELETE: Partial } ); export interface UpdateOptions { /** * If true, the attribute can be updated to an empty array. If false, empty arrays will remove the attribute. Defaults to false. */ allowEmptyArray?: boolean; /** * If true, required attributes will be filled with their default values on update (regardless of you specifying them for the update). Defaults to false. */ createRequired?: boolean; /** * If true, the timestamps attributes will be updated. Will not do anything if timestamps attribute were not specified. Defaults to true. */ updateTimestamps?: boolean; /** * Specifies what should be returned after update successfully completes. */ returnValues?: | "NONE" | "ALL_OLD" | "UPDATED_OLD" | "ALL_NEW" | "UPDATED_NEW"; /** * An expression for a conditional update. See the AWS documentation for more information about condition expressions. */ condition?: string; /** * A map of name substitutions for the condition expression. */ conditionNames?: any; /** * A map of values for the condition expression. Note that in order for automatic object conversion to work, the keys in this object must match schema attribute names. */ conditionValues?: any; } /** * Query */ type QueryFilter = any; export interface QueryInterface { exec(callback?: (err: Error, result: R) => void): Promise; where(rangeKey: string): QueryInterface; filter(filter: string): QueryInterface; and(): QueryInterface; or(): QueryInterface; not(): QueryInterface; null(): QueryInterface; eq(value: any): QueryInterface; lt(value: any): QueryInterface; le(value: any): QueryInterface; ge(value: any): QueryInterface; gt(value: any): QueryInterface; beginsWith(value: string): QueryInterface; between(valueA: any, valueB: any): QueryInterface; contains(value: string): QueryInterface; in(values: any[]): QueryInterface; limit(limit: number): QueryInterface; consistent(): QueryInterface; descending(): QueryInterface; ascending(): QueryInterface; startAt(key: QueryKey): QueryInterface; attributes(attributes: string[]): QueryInterface; count(): QueryInterface; counts(): QueryInterface; using(indexName: string): QueryInterface; } export interface QueryResult extends Array { lastKey?: QueryKey; } type QueryKey = any; /** * Scan */ type ScanFilter = string | any; export interface ScanInterface { exec(callback?: (err: Error, result: ScanResult) => void): Promise>; all(delay?: number, max?: number): ScanInterface; parallel(totalSegments: number): ScanInterface; using(indexName: string): ScanInterface; consistent(filter?: any): ScanInterface; where(filter: any): ScanInterface; filter(filter: any): ScanInterface; and(): ScanInterface; not(): ScanInterface; null(): ScanInterface; eq(value: any): ScanInterface; lt(value: any): ScanInterface; le(value: any): ScanInterface; ge(value: any): ScanInterface; gt(value: any): ScanInterface; beginsWith(value: any): ScanInterface; between(valueA: any, valueB: any): ScanInterface; contains(value: any): ScanInterface; beginsWith(value: any): ScanInterface; in(value: any): ScanInterface; limit(limit: number): ScanInterface; startAt(key: ScanKey): ScanInterface; attributes(value: any): ScanInterface; count(): ScanInterface; counts(): ScanInterface; } export interface ScanResult extends Array { lastKey?: ScanKey; } type ScanKey = any; export class VirtualType { constructor(options: any, name: string); applyVirtuals(model: any): void; get(fn: any): any; set(fn: any): any; } /** * Transaction */ export interface ModelTransactionConstructor { new(value?: DataSchema): ModelSchema; (value?: DataSchema): ModelSchema; readonly prototype: ModelSchema; create(item: DataSchema, options?: PutOptions, callback?: (err: Error, model: ModelSchema) => void): Promise>; create(item: DataSchema, callback?: (err: Error, model: ModelSchema) => void): Promise>; create(item: DataSchema, options?: PutOptions): Promise>; get(key: KeySchema, callback?: (err: Error, data: DataSchema) => void): Promise | undefined>; delete(key: KeySchema, callback?: (err: Error) => void): Promise; update(key: KeySchema, update: UpdateUpdate, options: UpdateOptions, callback: (err: Error, items: ModelSchema[]) => void): void; update(key: KeySchema, update: UpdateUpdate, callback: (err: Error, items: ModelSchema[]) => void): void; update(key: KeySchema, update: UpdateUpdate, options?: UpdateOptions): Promise>; conditionCheck(key: KeySchema, options?: ConditionOptions): void } export interface ConditionOptions { condition: string, conditionNames: object, conditionValues: object, } }