mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 13:27:15 +08:00
Added types/wampy v6.x.x (#25265)
This commit is contained in:
committed by
Wesley Wigham
parent
e9b73ce6db
commit
9c7cdc97e5
298
types/wampy/index.d.ts
vendored
298
types/wampy/index.d.ts
vendored
@@ -1,115 +1,195 @@
|
||||
// Type definitions for wampy.js v3.0.x
|
||||
// Type definitions for wampy.js v6.x.x
|
||||
// Project: https://github.com/KSDaemon/wampy.js
|
||||
// Definitions by: Konstantin Burkalev <https://github.com/KSDaemon>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface WampyOptions
|
||||
{
|
||||
autoReconnect?: boolean;
|
||||
reconnectInterval?: number;
|
||||
maxRetries?: number;
|
||||
realm?: string;
|
||||
helloCustomDetails?: any;
|
||||
onChallenge?: (auth_method: string, challenge_details: string) => string;
|
||||
authid?: string;
|
||||
onConnect?: () => void;
|
||||
onClose?: () => void;
|
||||
onError?: () => void;
|
||||
onReconnect?: () => void;
|
||||
onReconnectSuccess?: () => void;
|
||||
ws?: any;
|
||||
serializer?: any;
|
||||
declare namespace wampy {
|
||||
|
||||
type Dict = {[key: string]: any};
|
||||
|
||||
type Callback = () => void;
|
||||
|
||||
type ErrorCallback = (args: ErrorArgs) => void;
|
||||
|
||||
type EventCallback = (args: DataArgs) => void;
|
||||
|
||||
type SuccessCallback = (args: DataArgs) => void;
|
||||
|
||||
type RPCCallback = (args: DataArgs) => RPCResult | void;
|
||||
|
||||
type ChallengeCallback = (auth_method: string, extra: Dict) => string;
|
||||
|
||||
type Payload = Args | Dict | string | number | boolean | any[] | null;
|
||||
|
||||
interface Args
|
||||
{
|
||||
argsList: any[];
|
||||
argsDict: Dict;
|
||||
}
|
||||
|
||||
interface ErrorArgs
|
||||
{
|
||||
error: string;
|
||||
details: Dict;
|
||||
}
|
||||
|
||||
interface DataArgs extends Args
|
||||
{
|
||||
details: Dict;
|
||||
}
|
||||
|
||||
interface RPCOptions
|
||||
{
|
||||
process?: boolean;
|
||||
}
|
||||
|
||||
interface RPCResult extends Args
|
||||
{
|
||||
options: RPCOptions;
|
||||
}
|
||||
|
||||
interface SubscribeCallbacksHash
|
||||
{
|
||||
onSuccess?: Callback;
|
||||
onError?: ErrorCallback;
|
||||
onEvent?: EventCallback;
|
||||
}
|
||||
|
||||
interface UnsubscibeCallbacksHash extends SubscribeCallbacksHash
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
interface PublishCallbacksHash
|
||||
{
|
||||
onSuccess?: Callback;
|
||||
onError?: ErrorCallback;
|
||||
}
|
||||
|
||||
interface CallCallbacksHash
|
||||
{
|
||||
onSuccess?: SuccessCallback;
|
||||
onError?: ErrorCallback;
|
||||
}
|
||||
|
||||
interface CancelCallbacksHash
|
||||
{
|
||||
onSuccess?: Callback;
|
||||
onError?: Callback;
|
||||
}
|
||||
|
||||
interface RegisterCallbacksHash
|
||||
{
|
||||
rpc: RPCCallback;
|
||||
onSuccess?: Callback;
|
||||
onError?: ErrorCallback;
|
||||
}
|
||||
|
||||
interface UnregisterCallbacksHash
|
||||
{
|
||||
onSuccess?: Callback;
|
||||
onError?: ErrorCallback;
|
||||
}
|
||||
|
||||
interface AdvancedOptions
|
||||
{
|
||||
exclude?: number | number[];
|
||||
eligible?: number | number[];
|
||||
exclude_me?: boolean;
|
||||
disclose_me?: boolean;
|
||||
}
|
||||
|
||||
interface PublishAdvancedOptions extends AdvancedOptions
|
||||
{
|
||||
exclude_authid?: string | string[];
|
||||
exclude_authrole?: string | string[];
|
||||
eligible_authid?: string | string[];
|
||||
eligible_authrole?: string | string[];
|
||||
}
|
||||
|
||||
interface CallAdvancedOptions
|
||||
{
|
||||
disclose_me?: boolean;
|
||||
receive_progress?: boolean;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface CancelAdvancedOptions
|
||||
{
|
||||
mode?: "skip" | "kill" | "killnowait";
|
||||
}
|
||||
|
||||
interface RegisterAdvancedOptions
|
||||
{
|
||||
match?: "prefix" | "wildcard"
|
||||
invoke?: "single" | "roundrobin" | "random" | "first" | "last"
|
||||
}
|
||||
|
||||
interface WampyOptions
|
||||
{
|
||||
autoReconnect?: boolean;
|
||||
reconnectInterval?: number;
|
||||
maxRetries?: number;
|
||||
realm?: string;
|
||||
helloCustomDetails?: any;
|
||||
authid?: string;
|
||||
authmethods?: string[];
|
||||
onChallenge?: ChallengeCallback;
|
||||
onConnect?: Callback;
|
||||
onClose?: Callback;
|
||||
onError?: Callback;
|
||||
onReconnect?: Callback;
|
||||
onReconnectSuccess?: Callback;
|
||||
ws?: any;
|
||||
serializer?: any;
|
||||
}
|
||||
|
||||
interface WampyOpStatus
|
||||
{
|
||||
code: number;
|
||||
description: string;
|
||||
reqId?: number;
|
||||
}
|
||||
|
||||
interface WampyStatic
|
||||
{
|
||||
new (options?: WampyOptions): Wampy;
|
||||
new (url: string, options?: WampyOptions): Wampy;
|
||||
}
|
||||
|
||||
interface Wampy
|
||||
{
|
||||
constructor: WampyStatic;
|
||||
options(opts?: WampyOptions): WampyOptions | Wampy;
|
||||
getOpStatus(): WampyOpStatus;
|
||||
getSessionId(): number;
|
||||
connect(url?: string): Wampy;
|
||||
disconnect(): Wampy;
|
||||
abort(): Wampy;
|
||||
subscribe(topicURI: string,
|
||||
callbacks: EventCallback | SubscribeCallbacksHash): Wampy;
|
||||
unsubscribe(topicURI: string,
|
||||
callbacks?: EventCallback | UnsubscibeCallbacksHash): Wampy;
|
||||
publish(topicURI: string,
|
||||
payload?: Payload,
|
||||
callbacks?: PublishCallbacksHash,
|
||||
advancedOptions?: PublishAdvancedOptions): Wampy;
|
||||
call(topicURI: string,
|
||||
payload?: Payload,
|
||||
callbacks?: SuccessCallback | CallCallbacksHash,
|
||||
advancedOptions?: CallAdvancedOptions): Wampy;
|
||||
cancel(reqId: number,
|
||||
callbacks?: Callback | CancelCallbacksHash,
|
||||
advancedOptions?: CancelAdvancedOptions): Wampy;
|
||||
register(topicURI: string,
|
||||
callbacks: RPCCallback | RegisterCallbacksHash,
|
||||
avdancedOptions?: RegisterAdvancedOptions): Wampy;
|
||||
unregister(topicURI: string,
|
||||
callbacks?: Callback | UnregisterCallbacksHash): Wampy;
|
||||
}
|
||||
}
|
||||
|
||||
interface WampyOpStatus
|
||||
{
|
||||
code: number;
|
||||
description: string;
|
||||
reqId?: number;
|
||||
}
|
||||
|
||||
interface SuccessErrorCallbacksHash
|
||||
{
|
||||
onSuccess?: (args: any[], kwargs: any) => void;
|
||||
onError?: (err: string, details: any) => void;
|
||||
}
|
||||
|
||||
interface SubscribeCallbacksHash extends SuccessErrorCallbacksHash
|
||||
{
|
||||
onEvent: (args: any[], kwargs: any) => void;
|
||||
}
|
||||
|
||||
interface RegisterCallbacksHash extends SuccessErrorCallbacksHash
|
||||
{
|
||||
rpc: (args: any[], kwargs: any, options: any) => any[];
|
||||
}
|
||||
|
||||
interface CallSuccessErrorCallbacksHash
|
||||
{
|
||||
onSuccess: (args: any[], kwargs: any) => any;
|
||||
onError?: (err: string, details: any, args: any[], kwargs: any) => void;
|
||||
}
|
||||
|
||||
interface AdvancedOptions
|
||||
{
|
||||
exclude?: number | number[];
|
||||
eligible?: number | number[];
|
||||
exclude_me?: boolean;
|
||||
disclose_me?: boolean;
|
||||
}
|
||||
|
||||
interface PublishAdvancedOptions extends AdvancedOptions
|
||||
{
|
||||
exclude_authid?: string | string[];
|
||||
exclude_authrole?: string | string[];
|
||||
eligible_authid?: string | string[];
|
||||
eligible_authrole?: string | string[];
|
||||
}
|
||||
|
||||
interface CallAdvancedOptions
|
||||
{
|
||||
disclose_me?: boolean;
|
||||
receive_progress?: boolean;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface CancelAdvancedOptions
|
||||
{
|
||||
mode?: "skip" | "kill" | "killnowait";
|
||||
}
|
||||
|
||||
interface Wampy
|
||||
{
|
||||
new (url?: string, options?: WampyOptions): Wampy;
|
||||
options(opts?: WampyOptions): WampyOptions | Wampy;
|
||||
getOpStatus(): WampyOpStatus;
|
||||
getSessionId(): number;
|
||||
connect(url?: string): Wampy;
|
||||
disconnect(): Wampy;
|
||||
abort(): Wampy;
|
||||
subscribe(topicURI: string, callbacks: (((args: any[], kwargs: any) => void) | SubscribeCallbacksHash)): Wampy;
|
||||
unsubscribe(topicURI: string, callbacks?: (((args: any[], kwargs: any) => void) | SubscribeCallbacksHash)): Wampy;
|
||||
publish(topicURI: string,
|
||||
payload?: any,
|
||||
callbacks?: SuccessErrorCallbacksHash,
|
||||
advancedOptions?: PublishAdvancedOptions): Wampy;
|
||||
call(topicURI: string,
|
||||
payload?: any,
|
||||
callbacks?: (((args: any[], kwargs: any) => void) | CallSuccessErrorCallbacksHash),
|
||||
advancedOptions?: CallAdvancedOptions): Wampy;
|
||||
cancel(reqId: number,
|
||||
callbacks?: ((() => void) | SuccessErrorCallbacksHash),
|
||||
advancedOptions?: CancelAdvancedOptions): Wampy;
|
||||
register(topicURI: string, callbacks: (((args: any[], kwargs: any, options: any) => any[]) | RegisterCallbacksHash)): Wampy;
|
||||
unregister(topicURI: string, callbacks?: ((() => void) | SuccessErrorCallbacksHash)): Wampy;
|
||||
}
|
||||
|
||||
declare var wampy: Wampy;
|
||||
|
||||
declare module 'wampy'
|
||||
{
|
||||
export = wampy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
declare const wampy: wampy.WampyStatic;
|
||||
export as namespace wampy;
|
||||
export = wampy;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import Wampy = require('wampy');
|
||||
import {
|
||||
DataArgs,
|
||||
ErrorArgs,
|
||||
RPCResult,
|
||||
RPCOptions,
|
||||
RPCCallback,
|
||||
WampyOpStatus
|
||||
} from 'wampy';
|
||||
declare var console: { log(...args: any[]): void };
|
||||
|
||||
let ws = new Wampy('http://wamp.router.url', {realm: 'WAMPRealm'});
|
||||
@@ -24,11 +32,11 @@ let id: number = ws.getSessionId();
|
||||
ws.disconnect();
|
||||
ws.abort();
|
||||
|
||||
ws.subscribe('system.monitor.update', (args: any[], kwargs: any) =>
|
||||
ws.subscribe('system.monitor.update', (args: DataArgs) =>
|
||||
{
|
||||
console.log('Received system.monitor.update event!');
|
||||
})
|
||||
.subscribe('client.message', function (args: any[], kwargs: any)
|
||||
.subscribe('client.message', function (args: DataArgs)
|
||||
{
|
||||
console.log('Received client.message event!');
|
||||
});
|
||||
@@ -40,14 +48,14 @@ ws.unsubscribe('subscribed.topic', f1);
|
||||
ws.unsubscribe('chat.message.received');
|
||||
|
||||
ws.call('get.server.time', null, {
|
||||
onSuccess: (args: any[], kwargs: any) =>
|
||||
onSuccess: (args: DataArgs) =>
|
||||
{
|
||||
console.log('RPC successfully called');
|
||||
console.log('Server time is ' + kwargs);
|
||||
console.log('Server time is ' + args.argsDict);
|
||||
},
|
||||
onError: (err: string, details: any, args: any[], kwargs: any) =>
|
||||
onError: (args: ErrorArgs) =>
|
||||
{
|
||||
console.log('RPC call failed with error ' + err);
|
||||
console.log('RPC call failed with error ' + args.error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -63,44 +71,59 @@ ws.publish('user.modified', {field1: 'field1', field2: true, field3: 123}, {
|
||||
});
|
||||
ws.publish('user.modified', {field1: 'field1', field2: true, field3: 123}, {
|
||||
onSuccess: () => console.log('User successfully modified'),
|
||||
onError: (err: string, details: any) => console.log('User modification failed', err)
|
||||
onError: (args: ErrorArgs) => console.log('User modification failed', args.error)
|
||||
});
|
||||
ws.publish('chat.message.received', ['Private message'], null, {eligible: 123456789});
|
||||
ws.publish('user.logged.in', { argsList: [1,2,3], argsDict: {first: 1, second:2, third: 3}});
|
||||
|
||||
ws.call('server.time', null, (args: any[], kwargs: any) => console.log('Server time is ' + args[0]));
|
||||
ws.call('server.time', null, (args: DataArgs) => console.log('Server time is ' + args.argsList[0]));
|
||||
ws.call('server.time', null, (args: DataArgs) => console.log('Server time is ' + args.argsDict.serverTime));
|
||||
|
||||
ws.call('start.migration', null, {
|
||||
onSuccess: (args: any[], kwargs: any) => console.log('RPC successfully called'),
|
||||
onError: (err: string, details: any, args: any[], kwargs: any) => console.log('RPC call failed!', err)
|
||||
onSuccess: (args: DataArgs) => console.log('RPC successfully called'),
|
||||
onError: (args: ErrorArgs) => console.log('RPC call failed!', args.error)
|
||||
});
|
||||
|
||||
ws.call('restore.backup', {backupFile: 'backup.zip'}, {
|
||||
onSuccess: (args: any[], kwargs: any) => console.log('Backup successfully restored'),
|
||||
onError: (err: string, details: any, args: any[], kwargs: any) => console.log('Restore failed!', err)
|
||||
onSuccess: (args: DataArgs) => console.log('Backup successfully restored'),
|
||||
onError: (args: ErrorArgs) => console.log('Restore failed!', args.error)
|
||||
});
|
||||
|
||||
ws.call('start.migration', null, {
|
||||
onSuccess: (args: any[], kwargs: any) => console.log('RPC successfully called'),
|
||||
onError: (err: string, details: any, args: any[], kwargs: any) => console.log('RPC call failed!', err)
|
||||
onSuccess: (args: DataArgs) => console.log('RPC successfully called'),
|
||||
onError: (args: ErrorArgs) => console.log('RPC call failed!', args.error)
|
||||
});
|
||||
|
||||
let status = ws.getOpStatus();
|
||||
let status: WampyOpStatus = ws.getOpStatus();
|
||||
|
||||
ws.cancel(status.reqId);
|
||||
|
||||
let sqrt_f = (args: any[], kwargs: any, options: any) => [{}, kwargs * kwargs];
|
||||
let options: RPCOptions = { process: true };
|
||||
|
||||
let sqrt_f: RPCCallback = (args: DataArgs): RPCResult => {
|
||||
let result = args.argsList[0] * args.argsList[0];
|
||||
if (result === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
options,
|
||||
argsList: [result],
|
||||
argsDict: { result }
|
||||
}
|
||||
};
|
||||
|
||||
ws.register('sqrt.value', sqrt_f);
|
||||
|
||||
ws.register('sqrt.value', {
|
||||
rpc: sqrt_f,
|
||||
onSuccess: (args: any[], kwargs: any) => console.log('RPC successfully registered'),
|
||||
onError: (err: string, details: any) => console.log('RPC registration failed!', err)
|
||||
onSuccess: () => console.log('RPC successfully registered'),
|
||||
onError: (args: ErrorArgs) => console.log('RPC registration failed!', args.error)
|
||||
});
|
||||
|
||||
ws.unregister('sqrt.value');
|
||||
|
||||
ws.unregister('sqrt.value', {
|
||||
onSuccess: (data: any) => console.log('RPC successfully unregistered'),
|
||||
onError: (err: string, details: any) => console.log('RPC unregistration failed!', err)
|
||||
onSuccess: () => console.log('RPC successfully unregistered'),
|
||||
onError: (args: ErrorArgs) => console.log('RPC unregistration failed!', args.error)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user