Skip to content

Commit

Permalink
fix(dynamoose.ts.d): Add/fix TypeScript types
Browse files Browse the repository at this point in the history
Model.update is missing some options in the options type. model.put and its pseudonym model.save
have the wrong type altogether for the options parameter. I've simply fixed the types in
dynamoose.ts.d to match what the functions are expecting.
  • Loading branch information
Dave Balmain committed May 20, 2019
1 parent 19e633f commit e7472a7
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions dynamoose.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,14 @@ declare module "dynamoose" {
*/
export class Model<ModelData> {
constructor(obj: ModelData);
put(options: PutOptions, callback: (err: Error) => void): Promise<Model<ModelData>>;
save(options: SaveOptions, callback: (err: Error) => void): Promise<Model<ModelData>>;

delete(callback?: (err: Error) => void): Promise<undefined>;

put(options: PutOptions, callback?: (err: Error) => void): Promise<Model<ModelData>>;
put(callback: (err: Error) => void): Promise<Model<ModelData>>;
put(options: ModelData, callback?: (err: Error) => void): Promise<Model<ModelData>>;

save(options: SaveOptions, callback?: (err: Error) => void): Promise<Model<ModelData>>;
save(callback?: (err: Error) => void): Promise<Model<ModelData>>;
save(options: ModelData, callback?: (err: Error) => void): Promise<Model<ModelData>>;

originalItem(): object;

Expand Down Expand Up @@ -211,9 +209,9 @@ declare module "dynamoose" {
queryOne(query: QueryFilter, callback?: (err: Error, results: ModelSchema<DataSchema>) => void): QueryInterface<ModelSchema<DataSchema>, ModelSchema<DataSchema>>;
scan(filter?: ScanFilter, callback?: (err: Error, results: ModelSchema<DataSchema>[]) => void): ScanInterface<ModelSchema<DataSchema>>;

update(key: KeySchema, update: UpdateUpdate<DataSchema>, options: UpdateOption, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options: UpdateOptions, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options?: UpdateOption): Promise<ModelSchema<DataSchema>>;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options?: UpdateOptions): Promise<ModelSchema<DataSchema>>;

transaction: ModelTransactionConstructor<DataSchema, KeySchema>
}
Expand All @@ -234,19 +232,40 @@ declare module "dynamoose" {
| { $DELETE: Partial<DataSchema> }
);

export interface UpdateOption {
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;
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;
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;
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;
}


Expand Down Expand Up @@ -348,9 +367,9 @@ declare module "dynamoose" {

delete(key: KeySchema, callback?: (err: Error) => void): Promise<undefined>;

update(key: KeySchema, update: UpdateUpdate<DataSchema>, options: UpdateOption, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options: UpdateOptions, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, callback: (err: Error, items: ModelSchema<DataSchema>[]) => void): void;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options?: UpdateOption): Promise<ModelSchema<DataSchema>>;
update(key: KeySchema, update: UpdateUpdate<DataSchema>, options?: UpdateOptions): Promise<ModelSchema<DataSchema>>;

conditionCheck(key: KeySchema, options?: ConditionOptions): void
}
Expand Down

0 comments on commit e7472a7

Please sign in to comment.