mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
* Add type definitions for async-stream-emitter, consumable-stream, writable-consumable-stream, stream-demux, ag-channel, ag-simple-broker, ncom, async-iterable-stream * Upgrade sc-broker to 8.0 * Upgrade socketcluster-client to 15.1 * Rename definition files to match module file names The files in the module were renamed. * Move socketcluster-server to v14 folder In preparation for socketcluster-server v15, since the old version is still used by other type packages. * Update scc-broker-client to 7.0 * Add current socketcluster-server type definitions Current version is v15.0 * Move sc-broker-cluster to v6 folder In preparation for sc-broker-cluster v9, since the old version is still used by other type packages. * Add current sc-broker-cluster type definitions Current version is v9.0 * Move sc-channel to v1 folder In preparation for sc-channel v2, since the old version is still used by other type packages. * Add current sc-channel type definitions Current version is v2.0 * Include the relevant sc-broker-cluster type-definitions directly in sc-channel It can be run using older and newer version of sc-broker-cluster, which have differently versioned dependencies. * Move sc-channel tests to sc-broker-cluster In the tests we use sc-broker-cluster. If the tests are in sc-channel, they drag in all dependencies for sc-broker-cluster, including esnext.asynciterable, which we don't want. * Simplify sc-errors tests In the tests we used socketcluster-server. That dragged in all of its dependencies, including esnext.asynciterable, which we don't want. * Move sc-channel to v1 folder In preparation for sc-channel v2, since the old version is still used by other type packages.
90 lines
3.2 KiB
TypeScript
90 lines
3.2 KiB
TypeScript
import { EventEmitter } from 'events';
|
|
import { FlexiMap, KeyChain } from 'fleximap';
|
|
import { ExpiryManager } from 'expirymanager';
|
|
import { ComSocket } from 'ncom';
|
|
|
|
interface Subscriptions {
|
|
[socketId: number]: {
|
|
[channel: string]: ComSocket;
|
|
};
|
|
}
|
|
|
|
declare class SCBroker extends EventEmitter {
|
|
readonly type: 'broker';
|
|
|
|
readonly MIDDLEWARE_SUBSCRIBE: 'subscribe';
|
|
readonly MIDDLEWARE_PUBLISH_IN: 'publishIn';
|
|
|
|
id: number;
|
|
debugPort: number;
|
|
options: SCBroker.SCBrokerOptions;
|
|
instanceId: number;
|
|
dataMap: FlexiMap;
|
|
dataExpirer: ExpiryManager;
|
|
subscriptions: Subscriptions;
|
|
|
|
constructor(options?: { run?: () => void });
|
|
static create(options?: { run?: () => void }): SCBroker;
|
|
|
|
on(event: "subscribe" | "unsubscribe", listener: (channel: string) => void): this;
|
|
on(event: "publish", listener: (channel: string, data: any) => void): this;
|
|
on(event: "masterMessage", listener: (data: any, respond: (err: Error | null, responseData: any) => void) => void): this;
|
|
on(event: "message", listener: (message: any, respond: (err: Error | null, responseData: any) => void) => void): this;
|
|
on(event: "warning", listener: (err: Error) => void): this;
|
|
|
|
publish(channel: string, message: any): void;
|
|
run(): void;
|
|
exec(query: SCBroker.QueryFunction, baseKey?: KeyChain): any;
|
|
|
|
addMiddleware(type: 'subscribe', middleware: SCBroker.SubscribeMiddleware): void;
|
|
addMiddleware(type: 'publish', middleware: SCBroker.PublishMiddleware): void;
|
|
|
|
removeMiddleware(type: 'subscribe', middleware: SCBroker.SubscribeMiddleware): void;
|
|
removeMiddleware(type: 'publish', middleware: SCBroker.PublishMiddleware): void;
|
|
|
|
sendToMaster(data: any, callback?: (err: Error | null, responseData: any) => void): void;
|
|
}
|
|
|
|
export = SCBroker;
|
|
|
|
declare namespace SCBroker {
|
|
interface SCBrokerOptions {
|
|
// An ID to associate with this specific instance of SC
|
|
// this may be useful if you are running an SC app on multiple
|
|
// hosts - You can access the instanceId from the Broker object
|
|
// (inside brokerController) - If you don't provide an instanceId,
|
|
// SC will generate a random one (UUID v4)
|
|
instanceId?: string;
|
|
|
|
// A key which various SC processes will use to interact with
|
|
// scBroker broker processes securely, defaults to a 256 bits
|
|
// cryptographically random hex string
|
|
secretKey?: string;
|
|
|
|
// In milliseconds, the timeout for calling res(err, data) when
|
|
// your sendToWorker, sendToBroker or sendToMaster (IPC) call
|
|
// expects an ACK response from the other process
|
|
// (when callback is provided)
|
|
ipcAckTimeout?: number;
|
|
|
|
[additionalOptions: string]: any;
|
|
}
|
|
|
|
type SubscribeMiddleware = (req: SubscribeMiddlewareData) => void;
|
|
|
|
interface SubscribeMiddlewareData {
|
|
socket: ComSocket;
|
|
channel: string;
|
|
}
|
|
|
|
type PublishMiddleware = (req: PublishMiddlewareData) => void;
|
|
|
|
interface PublishMiddlewareData {
|
|
socket: ComSocket;
|
|
channel: string;
|
|
command: object;
|
|
}
|
|
|
|
type QueryFunction = (dataMap: FlexiMap, dataExpirer: ExpiryManager, subscriptions: Subscriptions) => any;
|
|
}
|