mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
add more tests and update as needed
This commit is contained in:
@@ -1,12 +1,120 @@
|
||||
import * as nano from "couchdb-nano";
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const instance: nano.Client = nano('http://localhost:5984/emails');
|
||||
|
||||
const config: nano.Config = {
|
||||
/*
|
||||
* Instantiate with configuration object
|
||||
*/
|
||||
const config: nano.Configuration = {
|
||||
url: "http://localhost:5984/foo",
|
||||
requestDefaults: { "proxy": "http://someproxy" }
|
||||
};
|
||||
|
||||
const cfgInstance: nano.Client = nano(config);
|
||||
const cfgInstance = nano(config);
|
||||
|
||||
const db: nano.Database = instance.use("mydb");
|
||||
/*
|
||||
* Server Scope
|
||||
*/
|
||||
const instance: nano.ServerScope = <nano.ServerScope>nano('http://localhost:5984/emails');
|
||||
|
||||
instance.dinosaur('', function (err, response) { });
|
||||
const url = instance.config.url;
|
||||
|
||||
instance.relax({
|
||||
method: 'POST',
|
||||
path: '_users',
|
||||
body: {
|
||||
_id: 'org.couchdb.user:',
|
||||
type: 'user',
|
||||
name: 'ss',
|
||||
roles: ['admin'],
|
||||
password: 'rf'
|
||||
}
|
||||
}, function (err: any) { });
|
||||
|
||||
instance.session(function (error, session) { });
|
||||
|
||||
instance.request({
|
||||
db: 'shared_headers',
|
||||
doc: 'new',
|
||||
headers: {'If-None-Match': JSON.stringify({})}
|
||||
}, function(error, helloWorld, rh) {});
|
||||
|
||||
instance.relax({
|
||||
db: 'document_list',
|
||||
doc: '_all_docs',
|
||||
method: 'GET',
|
||||
qs: {limit: 1}
|
||||
}, function(error, docs) {});
|
||||
|
||||
instance.auth("", "", function(err: any, _: any, headers: any) {});
|
||||
|
||||
instance.uuids(3, function (error, data) { });
|
||||
|
||||
/*
|
||||
* Database Scope
|
||||
*/
|
||||
const db: nano.DatabaseScope = instance.db;
|
||||
|
||||
db.create('az09_$()+-/', function (err) { });
|
||||
db.get('database_get', function(error, response) {});
|
||||
db.destroy('_users', function() {});
|
||||
db.list(function(error, list) {});
|
||||
db.replicate(instance.use("a"), instance.use("b"), function(error: any) {});
|
||||
db.replicate("a", "b", function(error: any) {});
|
||||
|
||||
|
||||
/*
|
||||
* Document Scope
|
||||
*/
|
||||
const mydb: nano.DocumentScope = instance.use("mydb");
|
||||
|
||||
mydb.insert({ 'foo': 'baz' }, null, function (error, response) { });
|
||||
mydb.insert({ 'foo': 'baz' }, 'foobar', function (error, foo) { });
|
||||
mydb.get('foobaz', { 'revs_info': true }, function (error, foobaz) { });
|
||||
mydb.head('foobaz', function (error, body, headers) { });
|
||||
mydb.copy('foo_src', 'foo_dest', { overwrite: true }, function (error, response, headers) { });
|
||||
mydb.destroy(undefined, undefined, function (error, response) { });
|
||||
mydb.bulk(
|
||||
{
|
||||
'docs': [
|
||||
{ 'key': 'baz', 'name': 'bazzel' },
|
||||
{ 'key': 'bar', 'name': 'barry' }
|
||||
]
|
||||
},
|
||||
function (error: any, response: any) { }
|
||||
);
|
||||
mydb.list(function (error: any, docs: any) { });
|
||||
mydb.fetch({ keys: ['foobar'] }, function (error: any, docs: any) { });
|
||||
mydb.fetchRevs({ keys: ['foobar'] }, function (error: any, docs: any) { });
|
||||
mydb.changes({ since: 0 }, function (error, response) { });
|
||||
mydb.compact(function (error) { });
|
||||
const feed = mydb.follow({ since: '0' });
|
||||
feed.on('change', function (change: any) { });
|
||||
mydb.atomic('update', 'addbaz', 'baz', function (error: any, response: any) { });
|
||||
mydb.viewWithList('people', 'by_name_and_city', 'my_list', {
|
||||
key: [
|
||||
'Derek',
|
||||
'San Francisco'
|
||||
]
|
||||
}, function (error, list) { }
|
||||
);
|
||||
mydb.view('alice', 'by_id', {
|
||||
keys: ['foobar', 'barfoo'],
|
||||
'include_docs': true
|
||||
}, function (err, view) { }
|
||||
);
|
||||
mydb.show('people', 'singleDoc', 'p_clemens', function(error: any, doc: any, rh: any) {});
|
||||
mydb.replicate('database_replica', function(error: any) {});
|
||||
|
||||
mydb.attachment.insert('new', 'att', 'Hello World!', 'text/plain', function (error: any, att: any) { });
|
||||
mydb.attachment.destroy('new', 'att', { rev: '123' }, function (error, response) { });
|
||||
mydb.attachment.get('new_string', 'att', function (error: any, helloWorld: any) { });
|
||||
|
||||
mydb.multipart.insert({'foo': 'baz'}, [{}], 'foobaz', function(error, foo) {});
|
||||
mydb.multipart.get('foobaz', function(error: any, foobaz: any, headers: any) {});
|
||||
|
||||
const rs = fs.createReadStream("");
|
||||
const is = mydb.attachment.insert('nodejs', 'logo.png', null, 'image/png');
|
||||
is.on('end', function () { });
|
||||
rs.pipe(is);
|
||||
Vendored
+34
-31
@@ -16,6 +16,10 @@ declare namespace nano {
|
||||
parseUrl?: boolean
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: any, result: any, headers?: any): void
|
||||
}
|
||||
|
||||
interface ServerScope {
|
||||
readonly config: ServerConfig
|
||||
db: DatabaseScope
|
||||
@@ -28,7 +32,7 @@ declare namespace nano {
|
||||
session(callback?: Callback): Request
|
||||
updates(params?: UpdatesParams, callback?: Callback): Request
|
||||
followUpdates(params?: object, callback?: Callback): EventEmitter
|
||||
uuids(num: number, callback: Function): Request
|
||||
uuids(num: number, callback: Callback): Request
|
||||
}
|
||||
|
||||
interface DatabaseScope {
|
||||
@@ -38,7 +42,7 @@ declare namespace nano {
|
||||
list(callback?: Callback): Request
|
||||
use(db: string): DocumentScope
|
||||
compact(name: string, designname?: string, callback?: Callback): Request
|
||||
replicate(source: string, target: string, options?: object, callback?: Callback): Request
|
||||
replicate(source: string | DocumentScope, target: string | DocumentScope, options?: object, callback?: Callback): Request
|
||||
changes(name: string, params?: object, callback?: Callback): Request
|
||||
follow(source: string, params?: FollowUpdatesParams, callback?: Callback): any
|
||||
followUpdates(params?: object, callback?: Callback): EventEmitter
|
||||
@@ -51,13 +55,13 @@ declare namespace nano {
|
||||
replicate(target: string, options?: object, callback?: Callback): Request
|
||||
compact(callback?: Callback): Request
|
||||
changes(params?: object, callback?: Callback): Request
|
||||
follow(params?: FollowUpdatesParams, callback?: Callback): any
|
||||
follow(params?: ScopedFollowUpdatesParams, callback?: Callback): any
|
||||
auth(username: string, userpass: string, callback?: Function): Request
|
||||
session(callback?: Callback): Request
|
||||
insert(document: object, params?: string | object, callback?: Callback): Request
|
||||
get(docname: string, params?: object, callback?: Callback): Request
|
||||
head(docname: string, callback: Callback): Request
|
||||
copy(src_document: object, dst_document: object, options: object, callback?: Callback): Request
|
||||
copy(src_document: string, dst_document: string, options: object, callback?: Callback): Request
|
||||
destroy(docname: string, rev: string, callback?: Callback): Request
|
||||
bulk(docs: BulkModifyDocsWrapper, params?: object, callback?: Callback): Request
|
||||
list(params?: object, callback?: Callback): Request
|
||||
@@ -92,21 +96,21 @@ declare namespace nano {
|
||||
}
|
||||
|
||||
interface RequestFunction {
|
||||
(options: RequestOptions, callback?: Callback): void
|
||||
(options?: RequestOptions | string, callback?: Callback): void
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
db: string
|
||||
method: string
|
||||
path: string
|
||||
doc: string
|
||||
att: string
|
||||
qs: any
|
||||
content_type: string
|
||||
headers: any
|
||||
body: any
|
||||
encoding: string
|
||||
multipart: any[]
|
||||
db?: string
|
||||
method?: string
|
||||
path?: string
|
||||
doc?: string
|
||||
att?: string
|
||||
qs?: any
|
||||
content_type?: string
|
||||
headers?: any
|
||||
body?: any
|
||||
encoding?: string
|
||||
multipart?: any[]
|
||||
}
|
||||
|
||||
interface UpdatesParams {
|
||||
@@ -115,22 +119,9 @@ declare namespace nano {
|
||||
heartbeat: boolean
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: any, result: any): void
|
||||
}
|
||||
|
||||
interface BulkModifyDocsWrapper {
|
||||
docs: object[]
|
||||
}
|
||||
|
||||
interface BulkFetchDocsWrapper {
|
||||
keys: string[]
|
||||
}
|
||||
|
||||
interface FollowUpdatesParams {
|
||||
db: string
|
||||
interface ScopedFollowUpdatesParams {
|
||||
inlucde_docs?: boolean
|
||||
since?: number | "now"
|
||||
since?: string
|
||||
heartbeat?: number
|
||||
feed?: "continuous"
|
||||
filter?: string | FollowUpdatesParamsFilterFunction
|
||||
@@ -142,9 +133,21 @@ declare namespace nano {
|
||||
response_grace_time?: number
|
||||
}
|
||||
|
||||
interface FollowUpdatesParams extends ScopedFollowUpdatesParams {
|
||||
db: string
|
||||
}
|
||||
|
||||
interface FollowUpdatesParamsFilterFunction {
|
||||
(doc: any, req: any): boolean
|
||||
}
|
||||
|
||||
interface BulkModifyDocsWrapper {
|
||||
docs: object[]
|
||||
}
|
||||
|
||||
interface BulkFetchDocsWrapper {
|
||||
keys: string[]
|
||||
}
|
||||
}
|
||||
|
||||
export = nano
|
||||
|
||||
Reference in New Issue
Block a user