pouchdb.d.ts
pouchdb.d.ts copied to clipboard
Replicate 'Delete doc with rev in opts'
Summary
The api docs imply two (and only two) overloads for remove
,
-
remove(docId: string, docRev: string, options?: { ...
-
remove(doc: { _rev: string; _id: string; }, options?: { ...
(where the doc in the overload (2) is currently typed to ExistingDoc
)
The test 'Delete doc with rev in opts'
(see below) implies a third overload:
-
remove(doc: NewDoc, options: { rev: string }, ...
Question
Is this (overload 3 above) an official overload and do we want therefore want it in the d.ts?
Samples
- non-compiling MCVE: gist and playground (note red squiggle on line 34)
- compiling MCVE: gist diff showing changes and playground
If playground url doesn't work, paste the gists into http://www.typescriptlang.org/Playground
Details
.js test from test.basics.js
(L386):
it('Delete doc with rev in opts', function () {
var db = new PouchDB(dbs.name);
var doc = {_id: 'foo'};
return db.put(doc).then(function (info) {
return db.remove(doc, {rev: info.rev});
});
});
.ts equivalent:
it('Delete doc with rev in opts', () => {
var db = new PouchDB(dbs.name);
// type specified purely to illustrate this question
var doc: pouchdb.api.methods.NewDoc = { _id: 'foo' };
return db.put(doc).then((info) => {
return db.remove(doc, { rev: info.rev });
});
});
As of 2c043b96 (current feat branch at the time of writing this) the above .ts snippet would not compile as
-
doc
, being aNewDoc
({_id: string;}
) does not have a_rev: string;
property - that is only present inExistingDoc
- this is due to developing the
remove
overloads according to the api doc for remove() which shows only two valid function definitions and states (highlighting added):
doc is required to be a document with at least an
_id
and a_rev
property.
Based on this documentation these are the only two overloads defined to date for remove()
in pouchdb v3.4.0.
The documentation often doesn't contain all the allowed forms, just to keep the whole thing understandable. Supplying a rev in the options might have been added for backwards compatibility or some syntactic sugar or some other reason, but since it's not explicitly deprecated I think in this case you can consider it supported. (Mostly because it is tested.)
On the other hand, it's not a widely used function signature as far as I can tell (I'm pretty sure I don't have logic handling it in pouchdb-wrappers, for example. But that's more a bug from my side than PouchDB's.)
IRC chat log:
[20:45:47]
[20:45:56]
[20:47:03]
[20:47:28]
[20:47:40]
[20:49:08]
[20:50:46]
[20:54:37] <AndyBrown> So I'm probably just looking for you guys to say that either you want an overload which lets the user specify the rev in the options, or if you want to stick to just the two overloads explicitly detailed in the docs. Keep in mind this d.ts will reflect your intentions in v3.4.0 and we can change it in future.
[21:00:02]
[21:00:09] <AndyBrown> and in fact I think that's probably the actual question: do you (who are more qualified than I to decide) want the 3rd overload for the v3.4.0 d.ts, or not.
[21:00:22] <AndyBrown> commandoline: decision made then [I'll include it if possible]
[21:00:30]
Decision: we will add this, but it is low priority for the moment as it is not publicly documented, it is just in one of the tests, and the current overload definitions do fulfil the api docs as explicitly stated. Assigning it as up-for-grabs for anyone to fork and PR.