<commit_before>import { EventEmitter } from "events";
import { Secret } from "jsonwebtoken";
import { ServerOptions } from "https";
import { IncomingMessage, Server } from "http";
import { SCAuthEngine } from "sc-auth";
import { SCExchange } from "sc-broker-cluster";
import WebSocket = require("ws");

import SCServerSocket = require("./scserversocket");

declare class SCServer extends EventEmitter {
    readonly MIDDLEWARE_HANDSHAKE_WS: "handshakeWS";
    readonly MIDDLEWARE_HANDSHAKE_SC: "handshakeSC";
    readonly MIDDLEWARE_AUTHENTICATE: "authenticate";
    readonly MIDDLEWARE_SUBSCRIBE: "subscribe";
    readonly MIDDLEWARE_PUBLISH_IN: "publishIn";
    readonly MIDDLEWARE_PUBLISH_OUT: "publishOut";
    readonly MIDDLEWARE_EMIT: "emit";

    options: SCServer.SCServerOptions;
    exchange: SCExchange;

    clients: {
        [id: string]: SCServerSocket;
    };
    clientsCount: number;

    pendingClients: {
        [id: string]: SCServerSocket;
    };
    pendingClientsCount: number;

    constructor(options?: SCServer.SCServerOptions);

    on(event: "connection", listener: SCServer.connectionListenerFunction): this;

    addMiddleware(type: "handshakeWS", middlewareFn: (req: IncomingMessage, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "handshakeSC", middlewareFn: (req: SCServer.HandshakeSCRequest, next: SCServer.nextHandshakeSCMiddlewareFunction) => void): void;
    addMiddleware(type: "authenticate", middlewareFn: (req: SCServer.AuthenticateRequest, next: SCServer.nextAuthenticateMiddlewareFunction) => void): void;
    addMiddleware(type: "subscribe", middlewareFn: (req: SCServer.SubscribeRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "publishIn", middlewareFn: (req: SCServer.PublishInRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "publishOut", middlewareFn: (req: SCServer.PublishOutRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "emit", middlewareFn: (req: SCServer.EmitRequest, next: SCServer.nextMiddlewareFunction) => void): void;

    setAuthEngine(authEngine: SCAuthEngine): void;
    setCodecEngine(codecEngine: SCServer.SCCodecEngine): void;
}

export = SCServer;

declare namespace SCServer {
    interface AuthToken {
        [x: string]: any;
    }

    interface SCServerOptions {
        // The port on which to listen for outside connections/requests
        port?: number;

        // Number of worker processes
        workers?: number;

        // Number of broker processes
        brokers?: number;

        // Should be either 'dev' or 'prod' - This affects the shutdown procedure
        // when a 'SIGUSR2' signal is received by master. In 'dev', a SIGUSR2 will
        // trigger an immediate shutdown of workers. In 'prod' workers will
        // be terminated progressively in accordance with processTermTimeout.
        environment?: string;

        // Setting this to true will cause the master process to shut down when
        // it receives a SIGUSR2 signal (instead of just the workers).
        // If you're using nodemon, set this to true.
        killMasterOnSignal?: boolean;

        // A unique name for your app (this is used internally for
        // various things such as the directory name in which to store socket
        // file descriptors) - If you don't provide an appName, SC will
        // generate a random one (UUID v4)
        appName?: string;

        // This can be the name of an npm module or a path to a Node.js module
        // to use as the WebSocket server engine.
        // You can now set this to 'sc-uws' for a massive speedup of at least 2x!
        wsEngine?: string;

        // 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;

        // The key which SC will use to encrypt/decrypt authTokens, defaults
        // to a 256 bits cryptographically random hex string
        // The default JWT algorithm used is 'HS256'.<commit_msg>fix(SCServer): any wsEngine to handle modules<commit_after>import { EventEmitter } from "events";
import { Secret } from "jsonwebtoken";
import { ServerOptions } from "https";
import { IncomingMessage, Server } from "http";
import { SCAuthEngine } from "sc-auth";
import { SCExchange } from "sc-broker-cluster";
import WebSocket = require("ws");

import SCServerSocket = require("./scserversocket");

declare class SCServer extends EventEmitter {
    readonly MIDDLEWARE_HANDSHAKE_WS: "handshakeWS";
    readonly MIDDLEWARE_HANDSHAKE_SC: "handshakeSC";
    readonly MIDDLEWARE_AUTHENTICATE: "authenticate";
    readonly MIDDLEWARE_SUBSCRIBE: "subscribe";
    readonly MIDDLEWARE_PUBLISH_IN: "publishIn";
    readonly MIDDLEWARE_PUBLISH_OUT: "publishOut";
    readonly MIDDLEWARE_EMIT: "emit";

    options: SCServer.SCServerOptions;
    exchange: SCExchange;

    clients: {
        [id: string]: SCServerSocket;
    };
    clientsCount: number;

    pendingClients: {
        [id: string]: SCServerSocket;
    };
    pendingClientsCount: number;

    constructor(options?: SCServer.SCServerOptions);

    on(event: "connection", listener: SCServer.connectionListenerFunction): this;

    addMiddleware(type: "handshakeWS", middlewareFn: (req: IncomingMessage, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "handshakeSC", middlewareFn: (req: SCServer.HandshakeSCRequest, next: SCServer.nextHandshakeSCMiddlewareFunction) => void): void;
    addMiddleware(type: "authenticate", middlewareFn: (req: SCServer.AuthenticateRequest, next: SCServer.nextAuthenticateMiddlewareFunction) => void): void;
    addMiddleware(type: "subscribe", middlewareFn: (req: SCServer.SubscribeRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "publishIn", middlewareFn: (req: SCServer.PublishInRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "publishOut", middlewareFn: (req: SCServer.PublishOutRequest, next: SCServer.nextMiddlewareFunction) => void): void;
    addMiddleware(type: "emit", middlewareFn: (req: SCServer.EmitRequest, next: SCServer.nextMiddlewareFunction) => void): void;

    setAuthEngine(authEngine: SCAuthEngine): void;
    setCodecEngine(codecEngine: SCServer.SCCodecEngine): void;
}

export = SCServer;

declare namespace SCServer {
    interface AuthToken {
        [x: string]: any;
    }

    interface SCServerOptions {
        // The port on which to listen for outside connections/requests
        port?: number;

        // Number of worker processes
        workers?: number;

        // Number of broker processes
        brokers?: number;

        // Should be either 'dev' or 'prod' - This affects the shutdown procedure
        // when a 'SIGUSR2' signal is received by master. In 'dev', a SIGUSR2 will
        // trigger an immediate shutdown of workers. In 'prod' workers will
        // be terminated progressively in accordance with processTermTimeout.
        environment?: string;

        // Setting this to true will cause the master process to shut down when
        // it receives a SIGUSR2 signal (instead of just the workers).
        // If you're using nodemon, set this to true.
        killMasterOnSignal?: boolean;

        // A unique name for your app (this is used internally for
        // various things such as the directory name in which to store socket
        // file descriptors) - If you don't provide an appName, SC will
        // generate a random one (UUID v4)
        appName?: string;

        // This can be the name of an npm module or a path to a Node.js module
        // to use as the WebSocket server engine.
        // You can now set this to 'sc-uws' for a massive speedup of at least 2x!
        wsEngine?: any;

        // 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;

        // The key which SC will use to encrypt/decrypt authTokens, defaults
        // to a 256 bits cryptographically random hex string
        // The default JWT algorithm used is 'HS256'.
{'fraction_non_alphanumeric': 0.0892640406046563, 'fraction_numerical': 0.0033101621979476996, 'mean_word_length': 3.2795089707271012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1070796', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2484, 'n_words': 890}