mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
* fix wrong pr #20404 * fix wrong pr #20404 * Update pouchdb-upsert-tests.ts * Use interface instead of a type literal * Missing semicolon * Use Core.DocumentId, Core.RevisionId instead of string
This commit is contained in:
Vendored
+10
-4
@@ -20,7 +20,7 @@ declare namespace PouchDB {
|
||||
* If the document does not already exist, then {} will be the input to diffFunc.
|
||||
*
|
||||
*/
|
||||
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<Core.Document<Model>>;
|
||||
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<UpsertResponse>;
|
||||
|
||||
/**
|
||||
* Perform an upsert (update or insert) operation. If a callback is not provided, the Promise based version
|
||||
@@ -33,7 +33,7 @@ declare namespace PouchDB {
|
||||
* @param callback - called with the results after operation is completed.
|
||||
*/
|
||||
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>,
|
||||
callback: Core.Callback<Core.Document<Model>>): void;
|
||||
callback: Core.Callback<UpsertResponse>): void;
|
||||
|
||||
/**
|
||||
* Put a new document with the given docId, if it doesn't already exist. Returns a Promise.
|
||||
@@ -41,7 +41,7 @@ declare namespace PouchDB {
|
||||
* @param doc - the document to insert. Should contain an _id if docId is not specified
|
||||
* If the document already exists, then the Promise will just resolve immediately.
|
||||
*/
|
||||
putIfNotExists<Model>(doc: Core.Document<Content & Model>): Promise<Core.Document<Model>>;
|
||||
putIfNotExists<Model>(doc: Core.Document<Content & Model>): Promise<UpsertResponse>;
|
||||
|
||||
//
|
||||
/**
|
||||
@@ -55,10 +55,16 @@ declare namespace PouchDB {
|
||||
* will return a Promise.
|
||||
*/
|
||||
putIfNotExists<Model>(doc: Core.Document<Content & Model>,
|
||||
callback: Core.Callback<Core.Document<Model>>): void;
|
||||
callback: Core.Callback<UpsertResponse>): void;
|
||||
}
|
||||
|
||||
type UpsertDiffCallback<Content extends {}> = (doc: Core.Document<Content>) => Core.Document<Content> | boolean;
|
||||
|
||||
interface UpsertResponse {
|
||||
id: Core.DocumentId;
|
||||
rev: Core.RevisionId;
|
||||
updated: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-upsert' {
|
||||
|
||||
@@ -12,7 +12,7 @@ function testUpsert_WithPromise_AndReturnDoc() {
|
||||
db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return doc;
|
||||
}).then((res: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
}).then((res: PouchDB.UpsertResponse) => {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function testUpsert_WithPromise_AndReturnBoolean() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return false;
|
||||
}).then((res: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
}).then((res: PouchDB.UpsertResponse) => {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function testUpsert_WithCallback_AndReturnDoc() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return doc;
|
||||
}, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}, (res: PouchDB.UpsertResponse) => {});
|
||||
}
|
||||
|
||||
function testUpsert_WithCallback_AndReturnBoolean() {
|
||||
@@ -36,13 +36,13 @@ function testUpsert_WithCallback_AndReturnBoolean() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return false;
|
||||
}, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}, (res: PouchDB.UpsertResponse) => {});
|
||||
}
|
||||
|
||||
function testPutIfNotExists_WithPromise() {
|
||||
db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
db.putIfNotExists(docToUpsert).then((res: PouchDB.UpsertResponse) => {});
|
||||
}
|
||||
|
||||
function testPutIfNotExists_WithCallback() {
|
||||
db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
db.putIfNotExists(docToUpsert, (res: PouchDB.UpsertResponse) => {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user