|
| 1 | +// Type definitions for dynamoose 0.7 |
| 2 | +// Project: https://github.com/automategreen/dynamoose |
| 3 | +// Definitions by: Rahul Vaidya <https://github.com/rvaidya> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +declare module "dynamoose" { |
| 7 | + import AWS from 'aws-sdk'; |
| 8 | + |
| 9 | + export class Dynamoose { |
| 10 | + constructor(); |
| 11 | + Dynamoose(): void; |
| 12 | + Schema(obj: any, options: any): Schema; |
| 13 | + Table(name: string, schema: any, options: any, base: any): Table; |
| 14 | + VirtualType(options: any, name: string): VirtualType; |
| 15 | + ddb(): AWS.DynamoDB; |
| 16 | + local(url: string): void; |
| 17 | + model(name: string, schema: Schema, options?: ModelOptions): Model; |
| 18 | + setDefaults(options: Options): void; |
| 19 | + } |
| 20 | + export class Schema { |
| 21 | + constructor(obj: SchemaObject, options?: SchemaOptions); |
| 22 | + method(name: string, fn: any): any; |
| 23 | + parseDynamo(model: any, dynamoObj: any): any; |
| 24 | + static(name: string, fn: any): any; |
| 25 | + toDynamo(model: any): any; |
| 26 | + virtual(name: string, options: any): any; |
| 27 | + virtualpath(name: string): any; |
| 28 | + } |
| 29 | + export class Table { |
| 30 | + constructor(name: string, schema: any, options: any, base: any); |
| 31 | + create(next: any): any; |
| 32 | + createIndex(attributes: any, indexSpec: any): any; |
| 33 | + delete(next: any): any; |
| 34 | + deleteIndex(indexname: string): any; |
| 35 | + describe(next: any): any; |
| 36 | + init(next: any): any; |
| 37 | + update(next: any): any; |
| 38 | + waitForActive(timeout: any, next: any): any; |
| 39 | + } |
| 40 | + export class Model { |
| 41 | + constructor(obj: ModelObject); |
| 42 | + put(options, callback: (err, obj) => void); |
| 43 | + save(options, callback: (err, obj) => void); |
| 44 | + delete(callback: (err) => void); |
| 45 | + delete(key, options, callback: (err) => void); |
| 46 | + get<T>(key, options?, callback?: (err, obj) => void): Promise<T>; |
| 47 | + batchPut(items: ModelObject[], options, callback: (err, obj) => void); |
| 48 | + create<T>(obj: T, callback: (err, obj: T) => void); |
| 49 | + create<T>(obj: T, options, callback: (err, obj: T) => void); |
| 50 | + batchGet<T>(keys, options?, callback?: (err, obj) => void): Promise<T[]>; |
| 51 | + batchDelete(keys, options, callback: (err) => void); |
| 52 | + query<T>(query, options, callback: (err, results: T[]) => void): void; |
| 53 | + query<T>(query, callback: (err, results: T[]) => void): void; |
| 54 | + query<T>(key: string): Query<T>; |
| 55 | + queryOne<T>(query, options, callback: (err, results: T[]) => void): void; |
| 56 | + queryOne<T>(query, callback: (err, results: T[]) => void): void; |
| 57 | + queryOne<T>(key: string): Query<T>; |
| 58 | + scan<T>(filter, options, callback: (err, results: T[]) => void): void; |
| 59 | + scan<T>(filter, callback: (err, results: T[]) => void): void; |
| 60 | + scan<T>(filter: string): Scan<T>; |
| 61 | + update(key, update, options, callback: (err) => void); |
| 62 | + } |
| 63 | + export class VirtualType { |
| 64 | + constructor(options: any, name: string); |
| 65 | + applyVirtuals(model: any): void; |
| 66 | + get(fn: any): any; |
| 67 | + set(fn: any): any; |
| 68 | + } |
| 69 | + |
| 70 | + export function ddb(): AWS.DynamoDB; |
| 71 | + export function local(url: string): void; |
| 72 | + export function model(name: string, schema: Schema, options?: ModelOptions): Model; |
| 73 | + export function setDefaults(options: Options): void; |
| 74 | + export import AWS = AWS; |
| 75 | + |
| 76 | + export default { |
| 77 | + ddb: ddb, |
| 78 | + local: local, |
| 79 | + model: model, |
| 80 | + setDefaults: setDefaults, |
| 81 | + AWS: AWS, |
| 82 | + Schema: Schema |
| 83 | + }; |
| 84 | + |
| 85 | + // Global options |
| 86 | + export interface Options { |
| 87 | + create?: boolean; |
| 88 | + prefix?: string; |
| 89 | + waitForActive?: boolean; |
| 90 | + waitForActiveTimeout?: number; |
| 91 | + } |
| 92 | + |
| 93 | + // tslint:disable-next-line:forbidden-types THIS IS INTENTIONAL, THESE ARE ARGUMENTS FOR THE LIBRARY |
| 94 | + type ST = String | Number | Boolean | Date | Object; |
| 95 | + type TT = ST | ST[] | Buffer; |
| 96 | + export interface ModelObject { |
| 97 | + [key: string]: TT; |
| 98 | + } |
| 99 | + export interface SchemaObject { |
| 100 | + [key: string]: { |
| 101 | + type: TT; |
| 102 | + hashKey?: boolean; |
| 103 | + rangeKey?: boolean; |
| 104 | + required?: boolean; |
| 105 | + index?: boolean | { |
| 106 | + name: string, |
| 107 | + global?: boolean |
| 108 | + rangeKey?: string |
| 109 | + project?: boolean | string[], |
| 110 | + throughput?: number | { read?: number, write?: number }; |
| 111 | + }; |
| 112 | + default?: () => TT | TT; |
| 113 | + validate?: (value: TT) => boolean | RegExp | TT; |
| 114 | + set?: (value: TT) => void; |
| 115 | + get?: () => TT; |
| 116 | + trim?: boolean; |
| 117 | + lowercase?: boolean; |
| 118 | + uppercase?: boolean; |
| 119 | + }; |
| 120 | + } |
| 121 | + |
| 122 | + // Schema options |
| 123 | + export interface SchemaOptions { |
| 124 | + throughput?: number | { read?: number, write?: number }; |
| 125 | + timestamps?: boolean | { createdAt?: string, updatedAt?: string }; |
| 126 | + } |
| 127 | + |
| 128 | + // Model options |
| 129 | + export interface ModelOptions { |
| 130 | + overwrite?: boolean; |
| 131 | + condition?: string; |
| 132 | + conditionNames: any; |
| 133 | + conditionValues: any; |
| 134 | + } |
| 135 | + |
| 136 | + export class Query<T> { |
| 137 | + exec(callback: (err, objs: T[]) => void): void; |
| 138 | + exec(): Promise<T[]>; |
| 139 | + where(rangeKey: string): Query<T>; |
| 140 | + filter(filter: string): Query<T>; |
| 141 | + and(): Query<T>; |
| 142 | + or(): Query<T>; |
| 143 | + not(): Query<T>; |
| 144 | + null(): Query<T>; |
| 145 | + eq(value: string): Query<T>; |
| 146 | + lt(value): Query<T>; |
| 147 | + le(value): Query<T>; |
| 148 | + ge(value): Query<T>; |
| 149 | + gt(value): Query<T>; |
| 150 | + beginsWith(value): Query<T>; |
| 151 | + between(valueA, valueB): Query<T>; |
| 152 | + contains(value): Query<T>; |
| 153 | + beginsWith(value): Query<T>; |
| 154 | + in(values): Query<T>; |
| 155 | + limit(limit: number): Query<T>; |
| 156 | + consistent(): Query<T>; |
| 157 | + descending(): Query<T>; |
| 158 | + ascending(): Query<T>; |
| 159 | + startAt(key): Query<T>; |
| 160 | + attributes(attributes): Query<T>; |
| 161 | + } |
| 162 | + |
| 163 | + export class Scan<T> { |
| 164 | + exec(callback: (err, objs: T[]) => void): void; |
| 165 | + exec(): Promise<T[]>; |
| 166 | + where(rangeKey: string): Scan<T>; |
| 167 | + filter(filter: string): Scan<T>; |
| 168 | + and(): Scan<T>; |
| 169 | + not(): Scan<T>; |
| 170 | + null(): Scan<T>; |
| 171 | + eq(value: string): Scan<T>; |
| 172 | + lt(value): Scan<T>; |
| 173 | + le(value): Scan<T>; |
| 174 | + ge(value): Scan<T>; |
| 175 | + gt(value): Scan<T>; |
| 176 | + beginsWith(value): Scan<T>; |
| 177 | + between(valueA, valueB): Scan<T>; |
| 178 | + contains(value): Scan<T>; |
| 179 | + beginsWith(value): Scan<T>; |
| 180 | + in(values): Scan<T>; |
| 181 | + limit(limit: number): Scan<T>; |
| 182 | + startAt(key): Scan<T>; |
| 183 | + attributes(attributes): Scan<T>; |
| 184 | + } |
| 185 | +} |
0 commit comments