mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
Add typings for xmlrpc (#12021)
This commit is contained in:
28
xmlrpc/xmlrpc-tests.ts
Normal file
28
xmlrpc/xmlrpc-tests.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/// <reference path="xmlrpc.d.ts" />
|
||||
|
||||
import * as xmlrpc from 'xmlrpc';
|
||||
|
||||
const serverOpts = {
|
||||
host: 'localhost',
|
||||
port: 9000
|
||||
};
|
||||
|
||||
const server = xmlrpc.createServer(serverOpts, () => {
|
||||
server.on('NotFound', method => {
|
||||
console.log(`Method ${method} not found`);
|
||||
})
|
||||
|
||||
server.on('hello', (err, params, cb) => {
|
||||
cb(null, `Hello, ${params[0]}!`);
|
||||
});
|
||||
|
||||
var client = xmlrpc.createClient({
|
||||
host: 'localhost',
|
||||
port: 9000,
|
||||
path: '/'
|
||||
});
|
||||
|
||||
client.methodCall('hello', ['world'], (err, val) => {
|
||||
console.log(val);
|
||||
});
|
||||
});
|
||||
90
xmlrpc/xmlrpc.d.ts
vendored
Normal file
90
xmlrpc/xmlrpc.d.ts
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
// Type definitions for xmlrpc 1.3.2
|
||||
// Project: https://github.com/baalexander/node-xmlrpc
|
||||
// Definitions by: Andrew Short <http://ajshort.me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module 'xmlrpc' {
|
||||
import { EventEmitter } from 'events';
|
||||
import { Server as HttpServer } from 'http';
|
||||
import { Server as HttpsServer } from 'https';
|
||||
import { TlsOptions } from 'tls';
|
||||
|
||||
interface ClientOptions {
|
||||
host?: string;
|
||||
path?: string;
|
||||
port?: number;
|
||||
url?: string;
|
||||
cookies?: boolean;
|
||||
headers?: { [header: string]: string };
|
||||
basic_auth?: { user: string, pass: string };
|
||||
method?: string;
|
||||
}
|
||||
|
||||
interface ServerOptions {
|
||||
host?: string;
|
||||
path?: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
interface DateFormatterOptions {
|
||||
colons?: boolean;
|
||||
hyphens?: boolean;
|
||||
local?: boolean;
|
||||
ms?: boolean;
|
||||
offset?: boolean;
|
||||
}
|
||||
|
||||
class Cookies {
|
||||
get(name: string): string;
|
||||
set(name: string, value: string, options?: { secure: boolean, expires: Date }): void;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
namespace xmlrpc {
|
||||
function createClient(options: string | ClientOptions): Client;
|
||||
function createSecureClient(options: string | ClientOptions): Client;
|
||||
|
||||
function createServer(options: string | ServerOptions, callback: () => void): Server;
|
||||
function createSecureServer(options: string | TlsOptions, callback: () => void): Server;
|
||||
|
||||
interface Client {
|
||||
options: ClientOptions;
|
||||
isSecure: boolean;
|
||||
headersProcessors: { processors: HeadersProcessor[] };
|
||||
cookies?: Cookies;
|
||||
|
||||
methodCall(method: string, params: any[], callback: (error: Object, value: any) => void): void;
|
||||
|
||||
getCookie(name: string): string;
|
||||
setCookie(name: string, value: string): this;
|
||||
}
|
||||
|
||||
type ServerFunction = (error: any, params: any, callback: (error: any, value: any) => void) => void;
|
||||
type ServerNotFoundFunction = (methodName: string, params: any[]) => void;
|
||||
|
||||
interface Server extends EventEmitter {
|
||||
httpServer: HttpServer | HttpsServer;
|
||||
|
||||
on(eventName: 'NotFound', callback: ServerNotFoundFunction): this;
|
||||
on(eventName: string, callback: ServerFunction): this;
|
||||
}
|
||||
|
||||
type Headers = { [header: string]: string };
|
||||
|
||||
interface HeadersProcessor {
|
||||
composeRequest(headers: Headers): void;
|
||||
parseResponse(headers: Headers): void;
|
||||
}
|
||||
|
||||
export var dateFormatter: {
|
||||
setOpts(opts: DateFormatterOptions): void;
|
||||
|
||||
decodeIso8601(time: string): Date;
|
||||
encodeIso8601(date: Date): string;
|
||||
}
|
||||
}
|
||||
|
||||
export = xmlrpc;
|
||||
}
|
||||
Reference in New Issue
Block a user