-
-
Save mrgcohen/a5a420a3ce0fbed575c27bd572437f13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @flow */ | |
declare module 'dynamoose' { | |
declare type Throughput = number | ({ | |
read: number; | |
} | { | |
write: number; | |
}); | |
declare type ThroughputConfig = { | |
throuput: Throughput; | |
} | { | |
timestamps: boolean | {createdAt: string;} | {updatedAt: string;}; | |
} | |
declare type LastKey = {lastKey: ?string;}; | |
declare type Query$Comp<Self> = { | |
not(): Query$Comp<Self>; | |
null(): Self; | |
eq(v: any): Self; | |
lt(v: number): Self; | |
le(v: number): Self; | |
gt(v: number): Self; | |
ge(v: number): Self; | |
contains(v: any): Self; | |
befinsWith(v: any): Self; | |
between(v1: any, v2: any): Self; | |
in(xs: any[]): Self; | |
startAt(xs: any[]): Self; | |
} | |
declare type Query$Op<Self> = { | |
and(): Self; | |
or(): Self; | |
} | |
declare type Queryable<Self, HandleType> = Query$Op<Self> & Query$Comp<Self> & { | |
where(rangeKey: string): Self; | |
filter(v: $Keys<HandleType>): Self; | |
limit(v: number): Self; | |
consistent(): Self; | |
decending(): Self; | |
ascending(): Self; | |
} | |
declare type Query<T, U> = Queryable<Query<T, U>, T> & { | |
exec(): Promise<U & LastKey>; | |
attributes(xs: Array<$Keys<T>>): Query<any, any>; | |
count(): Query<number>; | |
} | |
declare type Scan<T> = Queryable<Scan<T>, T> & { | |
exec(): Promise<T[] & LastKey>; | |
attributes(xs: Array<$Keys<T>>): Scan<any>; | |
count(): Scan<number>; | |
counts(): Scan<{count: number; scannedCount: number;}>; | |
} | |
declare type Comparator = { | |
eq: any | |
} | { | |
gt: any | |
} | { | |
ge: any | |
} | { | |
lt: any | |
} | { | |
le: any | |
} | { | |
contains: any | |
} | { | |
between: [number, number] | |
} | { | |
befinsWith: string | |
} | { | |
in: any[] | |
} | { | |
startAt: any | |
}; | |
declare type QueryObject<T> = { | |
[key: $Keys<T>]: Comparator; | |
}; | |
declare type PutOption = ({} | { | |
overwrite: boolean; | |
} | { | |
condition: string; | |
} | { | |
conditionNames: Object; | |
} | { | |
conditionValues: Object; | |
}); | |
declare type UpdateQuery<T> = $Subtype<T> | |
| { $PUT: $Subtype<T>;} | |
| { $ADD: $Subtype<T>;} | |
| { $DELETE: $Subtype<T>;}; | |
declare type ModelInstance<T> = { | |
save(v: ?$Subtype<T>, opt: ?PutOption): Promise<void>; | |
put(v: ?$Subtype<T>, opt: ?PutOption): Promise<void>; | |
} | |
declare type Model<T> = { | |
constructor(obj: T | $Diff<T, {id: any;}>): ModelInstance<T>; | |
get(i: $Subtype<T> | any): Promise<T>; | |
batchGet(xs: ($Subtype<T> | any)[], opts: ?any): Promise<T[]>; | |
batchPut(xs: ($Diff<T, {id: any}>)[], opts: ?PutOption): Promise<T[]>; | |
delete(i: string | $Subtype<T>, opts: ?any): Promise<T[]>; | |
batchDelete(xs: (string | $Subtype<T>)[], opts: ?any): Promise<T[]>; | |
query(obj: $Keys<T> | QueryObject<T>): Query<T, T[]>; | |
queryOne(obj: $Keys<T> | QueryObject<T>): Query<T, T>; | |
scan(obj: ?($Keys<T> | QueryObject<T>)): Scan<T>; | |
update(i: $Subtype<T> | any, q: UpdateQuery<T>, opt: ?( | |
{} | |
| { allowEmpty: boolean;} | |
| { createRequired: boolean;} | |
| { updateTimestamp: boolean;} | |
)): Promise<void> ; | |
} | |
declare type Primitive = | |
typeof Number | |
| typeof String | |
| typeof Boolean | |
| typeof Date | |
| typeof Object | |
| typeof Array | |
| typeof Buffer | |
| [Primitive] | |
; | |
declare type SchemaDefinition$Value = | |
Primitive | |
| {|[key: string]: SchemaDefinition$Value|} | |
| {type: Primitive;} & ({ | |
trim: boolean; | |
} | { | |
set: Function; | |
} | { | |
get: Function; | |
} | { | |
lowercase: boolean; | |
} | { | |
uppercase: boolean; | |
} | { | |
validate(v: any): boolean; | |
} | { | |
hashKey: boolean; | |
} | { | |
required: boolean; | |
} | { | |
default: ?any; | |
} | { | |
index: boolean | { name: string; } & ({} | { | |
global: boolean; | |
} | { | |
rangeKey: string; | |
} | { | |
project: boolean; | |
} | { | |
throughput: number; | |
}) | |
}); | |
declare type SchemaDefinition = { [name: string] : SchemaDefinition$Value }; | |
declare type AWSConfig = { | |
region: string; | |
accessKeyId: string; | |
secretAccessKey: string; | |
}; | |
declare class Schema { | |
constructor(def: SchemaDefinition, throuput: ?ThroughputConfig): Schema; | |
} | |
// Private API | |
declare class Table { | |
constructor(name: string, schema: Schema, opt: ?Object, base: any): Table; | |
createIndex(attributes: any[], indexSpec: any): Promise<void>; | |
deleteIndex(attributes: any[], indexSpec: any): Promise<void>; | |
init(): Promise<void>; | |
waitForActive(timeout: ?number): Promise<void>; | |
describe(): Promise<any>; | |
create(): Promise<void>; | |
update(): Promise<void>; | |
delete(): Promise<void>; | |
} | |
declare var AWS: { | |
config: { | |
update(config: AWSConfig): void; | |
} | |
}; | |
declare function local(url: ?string): void; | |
declare function ddb(): any; | |
declare function setDefaults(opts: {create: boolean}): void; | |
declare function model(name: string, def: Schema | SchemaDefinition): any; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment