rest-vir - v1.0.0
    Preparing search index...

    Type Alias WebSocketInit<MessageFromClientShape, MessageFromServerShape>

    Initialization for a WebSocket within a service definition..

    type WebSocketInit<
        MessageFromClientShape = unknown,
        MessageFromServerShape = unknown,
    > = {
        customProps?: Record<PropertyKey, unknown>;
        messageFromClientShape: MessageFromClientShape;
        messageFromHostShape: MessageFromServerShape;
        protocolsShape?: unknown;
        requiredClientOrigin?: OriginRequirement;
        searchParamsShape?: unknown;
    }

    Type Parameters

    • MessageFromClientShape = unknown
    • MessageFromServerShape = unknown
    Index

    Properties

    customProps?: Record<PropertyKey, unknown>

    Attach any other properties that you want inside of here.

    messageFromClientShape: MessageFromClientShape
    messageFromHostShape: MessageFromServerShape
    protocolsShape?: unknown

    A shape (that is parsed by the object-shape-tester package) that all protocols for this WebSocket are collectively tested against. Omit this or set it to undefined to allow a string array of any length.

    This shape will be tested against all protocols together in a single array, so this should be an array shape. Only string-compatible values inside the array will work. It is recommended to use tupleShape from the object-shape-tester package.

    import {tupleShape, exact} from 'object-shape-tester';

    const partialWebSocketInit = {
    protocolsShape: tupleShape('', exact('hi')),
    };
    requiredClientOrigin?: OriginRequirement

    Set a required client origin for this endpoint.

    • If this is omitted, the service's origin requirement is used instead.
    • If this is explicitly set to undefined, this endpoint allows any origins (regardless of the service's origin requirement).
    • Any other set value overrides the service's origin requirement (if it has any).
    searchParamsShape?: unknown

    A shape used to verify search params. This should match the entire search params object.

    Note the following:

    • Search param values will always be in an array
    • Elements in search param value arrays will always be strings
    import {exact, enumShape, tupleShape} from 'object-shape-tester';

    const partialWebSocketInit = {
    searchParamsShape: {
    // use `tupleShape` to ensure there's exactly one entry for this search param
    userId: tupleShape(enumShape(MyEnum)),
    date: tupleShape(exact('2')),
    // don't use `tupleShape` here so that there can be any number of entries
    colors: [''],
    },
    };