diff --git a/types/nano/index.d.ts b/types/nano/index.d.ts index 4b7cc6f367..ab80e563d4 100644 --- a/types/nano/index.d.ts +++ b/types/nano/index.d.ts @@ -1,157 +1,248 @@ -// Type definitions for nano 6.2.0 +// Type definitions for nano 6.2 // Project: https://github.com/apache/couchdb-nano // Definitions by: Tim Jacobi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.0 -declare module "nano" { - import { EventEmitter } from "events"; - import { Request, CoreOptions } from "request"; +import { EventEmitter } from "events"; +import { Request, CoreOptions } from "request"; - function nano(config: nano.Configuration | string): nano.ServerScope | nano.DocumentScope; +declare function nano( + config: nano.Configuration | string +): nano.ServerScope | nano.DocumentScope; - namespace nano { - interface Configuration { - url: string - requestDefaults?: CoreOptions - log?(id: string, args: any): void - parseUrl?: boolean - request?: Function - } +declare namespace nano { + interface Configuration { + url: string; + requestDefaults?: CoreOptions; + log?(id: string, args: any): void; + parseUrl?: boolean; + request?(params: any): void; + } - interface Callback { - (error: any, result: any, headers?: any): void - } + type Callback = (error: any, result: any, headers?: any) => void; - interface ServerScope { - readonly config: ServerConfig - db: DatabaseScope - use(db: string): DocumentScope - scope(db: string): DocumentScope - request: RequestFunction - relax: RequestFunction - dinosaur: RequestFunction - auth(username: string, userpass: string, callback?: Callback): Request - session(callback?: Callback): Request - updates(params?: UpdatesParams, callback?: Callback): Request - followUpdates(params?: any, callback?: Callback): EventEmitter - uuids(num: number, callback: Callback): Request - } + interface ServerScope { + readonly config: ServerConfig; + db: DatabaseScope; + use(db: string): DocumentScope; + scope(db: string): DocumentScope; + request: RequestFunction; + relax: RequestFunction; + dinosaur: RequestFunction; + auth(username: string, userpass: string, callback?: Callback): Request; + session(callback?: Callback): Request; + updates(params?: UpdatesParams, callback?: Callback): Request; + followUpdates(params?: any, callback?: Callback): EventEmitter; + uuids(num: number, callback: Callback): Request; + } - interface DatabaseScope { - create(name: string, callback?: Callback): Request - get(name: string, callback?: Callback): Request - destroy(name: string, callback?: Callback): Request - list(callback?: Callback): Request - use(db: string): DocumentScope - compact(name: string, designname?: string, callback?: Callback): Request - replicate(source: string | DocumentScope, target: string | DocumentScope, options?: any, callback?: Callback): Request - changes(name: string, params?: any, callback?: Callback): Request - follow(source: string, params?: DatabaseScopeFollowUpdatesParams, callback?: Callback): void - followUpdates(params?: any, callback?: Callback): EventEmitter - updates(params?: UpdatesParams, callback?: Callback): Request - } + interface DatabaseScope { + create(name: string, callback?: Callback): Request; + get(name: string, callback?: Callback): Request; + destroy(name: string, callback?: Callback): Request; + list(callback?: Callback): Request; + use(db: string): DocumentScope; + compact(name: string, designname?: string, callback?: Callback): Request; + replicate( + source: string | DocumentScope, + target: string | DocumentScope, + options?: any, + callback?: Callback + ): Request; + changes(name: string, params?: any, callback?: Callback): Request; + follow( + source: string, + params?: DatabaseScopeFollowUpdatesParams, + callback?: Callback + ): EventEmitter; + followUpdates(params?: any, callback?: Callback): EventEmitter; + updates(params?: UpdatesParams, callback?: Callback): Request; + } - interface DocumentScope { - readonly config: ServerConfig - info(callback?: Callback): Request - replicate(target: string | DocumentScope, options?: any, callback?: Callback): Request - compact(callback?: Callback): Request - changes(params?: any, callback?: Callback): Request - follow(params?: DocumentScopeFollowUpdatesParams, callback?: Callback): void - auth(username: string, userpass: string, callback?: Callback): Request - session(callback?: Callback): Request - insert(document: any, params?: any, callback?: Callback): Request - get(docname: string, params?: any, callback?: Callback): Request - head(docname: string, callback: Callback): Request - copy(src_document: string, dst_document: string, options: any, callback?: Callback): Request - destroy(docname: string, rev: string, callback?: Callback): Request - bulk(docs: BulkModifyDocsWrapper, params?: any, callback?: Callback): Request - list(params?: any, callback?: Callback): Request - fetch(docnames: BulkFetchDocsWrapper, params?: any, callback?: Callback): Request - fetchRevs(docnames: BulkFetchDocsWrapper, params?: any, callback?: Callback): Request - multipart: Multipart - attachment: Attachment - show(designname: string, showname: string, doc_id: string, params?: any, callback?: Callback): Request - atomic(designname: string, updatename: string, docname: string, body?: any, callback?: Callback): Request - updateWithHandler(designname: string, updatename: string, docname: string, body?: any, callback?: Callback): Request - search(designname: string, searchname: string, params?: any, callback?: Callback): Request - spatial(ddoc: string, viewname: string, params?: any, callback?: Callback): Request - view(designname: string, viewname: string, params?: any, callback?: Callback): Request - viewWithList(designname: string, viewname: string, listname: string, params?: any, callback?: Callback): Request - server: ServerScope - } + interface DocumentScope { + readonly config: ServerConfig; + info(callback?: Callback): Request; + replicate( + target: string | DocumentScope, + options?: any, + callback?: Callback + ): Request; + compact(callback?: Callback): Request; + changes(params?: any, callback?: Callback): Request; + follow( + params?: DocumentScopeFollowUpdatesParams, + callback?: Callback + ): EventEmitter; + auth(username: string, userpass: string, callback?: Callback): Request; + session(callback?: Callback): Request; + insert(document: any, params?: any, callback?: Callback): Request; + get(docname: string, params?: any, callback?: Callback): Request; + head(docname: string, callback: Callback): Request; + copy( + src_document: string, + dst_document: string, + options: any, + callback?: Callback + ): Request; + destroy(docname: string, rev: string, callback?: Callback): Request; + bulk( + docs: BulkModifyDocsWrapper, + params?: any, + callback?: Callback + ): Request; + list(params?: any, callback?: Callback): Request; + fetch( + docnames: BulkFetchDocsWrapper, + params?: any, + callback?: Callback + ): Request; + fetchRevs( + docnames: BulkFetchDocsWrapper, + params?: any, + callback?: Callback + ): Request; + multipart: Multipart; + attachment: Attachment; + show( + designname: string, + showname: string, + doc_id: string, + params?: any, + callback?: Callback + ): Request; + atomic( + designname: string, + updatename: string, + docname: string, + body?: any, + callback?: Callback + ): Request; + updateWithHandler( + designname: string, + updatename: string, + docname: string, + body?: any, + callback?: Callback + ): Request; + search( + designname: string, + searchname: string, + params?: any, + callback?: Callback + ): Request; + spatial( + ddoc: string, + viewname: string, + params?: any, + callback?: Callback + ): Request; + view( + designname: string, + viewname: string, + params?: any, + callback?: Callback + ): Request; + viewWithList( + designname: string, + viewname: string, + listname: string, + params?: any, + callback?: Callback + ): Request; + server: ServerScope; + } - interface Multipart { - insert(doc: any, attachments: any[], params: string | any, callback?: Callback): Request - get(docname: string, params?: string | any, callback?: Callback): Request - } + interface Multipart { + insert( + doc: any, + attachments: any[], + params: string | any, + callback?: Callback + ): Request; + get(docname: string, params?: string | any, callback?: Callback): Request; + } - interface Attachment { - insert(docname: string, attname: string, att: any, contenttype: string, params?: any, callback?: Callback): Request - get(docname: string, attname: string, params?: any, callback?: Callback): Request - destroy(docname: string, attname: string, params?: any, callback?: Callback): Request - } + interface Attachment { + insert( + docname: string, + attname: string, + att: any, + contenttype: string, + params?: any, + callback?: Callback + ): Request; + get( + docname: string, + attname: string, + params?: any, + callback?: Callback + ): Request; + destroy( + docname: string, + attname: string, + params?: any, + callback?: Callback + ): Request; + } - interface ServerConfig { - url: string - db: string - } + interface ServerConfig { + url: string; + db: string; + } - interface RequestFunction { - (options?: RequestOptions | string, callback?: Callback): void - } + type RequestFunction = ( + 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[] - } + 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[]; + } - interface UpdatesParams { - feed: "longpoll" | "continuous" | "eventsource" - timeout: number - heartbeat: boolean - } + interface UpdatesParams { + feed: "longpoll" | "continuous" | "eventsource"; + timeout: number; + heartbeat: boolean; + } - interface DocumentScopeFollowUpdatesParams { - inlucde_docs?: boolean - since?: string - heartbeat?: number - feed?: "continuous" - filter?: string | FollowUpdatesParamsFilterFunction - query_params?: any - headers?: any - inactivity_ms?: number - max_retry_seconds?: number - initial_retry_delay?: number - response_grace_time?: number - } + interface DocumentScopeFollowUpdatesParams { + inlucde_docs?: boolean; + since?: string; + heartbeat?: number; + feed?: "continuous"; + filter?: string | FollowUpdatesParamsFilterFunction; + query_params?: any; + headers?: any; + inactivity_ms?: number; + max_retry_seconds?: number; + initial_retry_delay?: number; + response_grace_time?: number; + } - interface DatabaseScopeFollowUpdatesParams extends DocumentScopeFollowUpdatesParams { - db: string - } + interface DatabaseScopeFollowUpdatesParams + extends DocumentScopeFollowUpdatesParams { + db: string; + } - interface FollowUpdatesParamsFilterFunction { - (doc: any, req: any): boolean - } + type FollowUpdatesParamsFilterFunction = (doc: any, req: any) => boolean; - interface BulkModifyDocsWrapper { - docs: any[] - } + interface BulkModifyDocsWrapper { + docs: any[]; + } - interface BulkFetchDocsWrapper { - keys: string[] - } - } - - export = nano + interface BulkFetchDocsWrapper { + keys: string[]; + } } + +export = nano; diff --git a/types/nano/nano-tests.ts b/types/nano/nano-tests.ts index 79b2fded4c..1e57052329 100644 --- a/types/nano/nano-tests.ts +++ b/types/nano/nano-tests.ts @@ -7,7 +7,7 @@ import * as path from "path"; */ const config: nano.Configuration = { url: "http://localhost:5984/foo", - requestDefaults: { "proxy": "http://someproxy" } + requestDefaults: { proxy: "http://someproxy" } }; const cfgInstance = nano(config); @@ -15,73 +15,72 @@ const cfgInstance = nano(config); /* * Server Scope */ -const instance: nano.ServerScope = nano("http://localhost:5984/emails"); +const instance: nano.ServerScope = nano("http://localhost:5984/emails"); -instance.dinosaur("", function (err, response) { }); +instance.dinosaur("", (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) { }); +instance.relax({ method: "POST", path: "_users", body: { _id: "org.couchdb.user:", type: "user", name: "ss", roles: ["admin"], password: "rf" } }, (err: any) => {}); +instance.session((error, session) => {}); +instance.request({ db: "shared_headers", doc: "new", headers: { "If-None-Match": JSON.stringify({}) } }, (error, helloWorld, rh) => {}); +instance.relax({ db: "document_list", doc: "_all_docs", method: "GET", qs: { limit: 1 } }, (error, docs) => {}); +instance.auth("", "", (err: any, _: any, headers: any) => {}); +instance.uuids(3, (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) { }); - +db.create("az09_$()+-/", (err) => {}); +db.get("database_get", (err, response) => {}); +db.destroy("_users", () => {}); +db.list((error, list) => {}); +db.replicate(instance.use("a"), instance.use("b"), (error: any) => {}); +db.replicate("a", "b", (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) { }); +mydb.insert({ foo: "baz" }, null, (err, response) => {}); +mydb.insert({ foo: "baz" }, "foobar", (error, foo) => {}); +mydb.get("foobaz", { revs_info: true }, (error, foobaz) => {}); +mydb.head("foobaz", (error, body, headers) => {}); +mydb.copy("foo_src", "foo_dest", { overwrite: true }, (error, response, headers) => {}); +mydb.destroy("x", "x", (err, response) => {}); +mydb.bulk({ docs: [{ key: "baz", name: "bazzel" }, { key: "bar", name: "barry" }] }, (error: any, response: any) => {}); +mydb.list((error: any, docs: any) => {}); +mydb.fetch({ keys: ["foobar"] }, (error: any, docs: any) => {}); +mydb.fetchRevs({ keys: ["foobar"] }, (error: any, docs: any) => {}); +mydb.changes({ since: 0 }, (err, response) => {}); +mydb.compact((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) { }); +feed.on("change", (change: any) => {}); +mydb.atomic("update", "addbaz", "baz", (error: any, response: any) => {}); +mydb.viewWithList("people", "by_name_and_city", "my_list", { key: ["Derek", "San Francisco"] }, (error, list) => {}); +mydb.view("alice", "by_id", { keys: ["foobar", "barfoo"], include_docs: true }, (err, view) => {}); +mydb.show("people", "singleDoc", "p_clemens", (error: any, doc: any, rh: any) => {}); +mydb.replicate("database_replica", (error: any) => {}); /* * Attachments */ -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.attachment.insert("new", "att", "Hello World!", "text/plain", (error: any, att: any) => {}); +mydb.attachment.destroy("new", "att", { rev: "123" }, (err, response) => {}); +mydb.attachment.get("new_string", "att", (error: any, helloWorld: any) => {}); /* * Multipart */ -mydb.multipart.insert({ "foo": "baz" }, [{}], "foobaz", function (error, foo) { }); -mydb.multipart.get("foobaz", function (error: any, foobaz: any, headers: any) { }); +mydb.multipart.insert({ foo: "baz" }, [{}], "foobaz", (error, foo) => {}); +mydb.multipart.get("foobaz", (error: any, foobaz: any, headers: any) => {}); /* * Piping */ const rs = fs.createReadStream(""); const is = mydb.attachment.insert("nodejs", "logo.png", null, "image/png"); -is.on("end", function () { }); -rs.pipe(is); \ No newline at end of file +is.on("end", () => {}); +rs.pipe(is);