Options
All
  • Public
  • Public/Protected
  • All
Menu

Module ataraxia-service-contracts

Service contracts to define what methods and events services support.

Contracts are used to define how a service acts when used over the network. They help define what methods and events are available and what types and parameters those support.

import { ServiceContract, AsyncSubscribable } from 'ataraxia-service-contracts';

interface EchoService {
onEcho: AsyncSubscribable<this, [ message: string ]>;

echo(message: string): Promise<string>;
}

const EchoService = new ServiceContract<EchoService>()
.defineMethod('echo', {
returnType: stringType,
parameters: [
{
name: 'message',
type: stringType
}
]
})
.defineEvent('onEcho', {
parameters: [
{
name: 'message',
type: stringType
}
]
});

For easy of use this module re-exports AsyncEvent, AsyncSubscribable and Listener from Atvik as those are used for events.

Index

Type aliases

BasicValue

BasicValue: void | string | number | boolean | null | ArrayBuffer | BasicValue[] | {}

Type used to identify the basic types used with DataType.

Listener

Listener<This, Args>: (this: This, ...args: Args) => void | Promise<void>

Type parameters

  • This

  • Args: any[]

Type declaration

    • (this: This, ...args: Args): void | Promise<void>
    • Listener type. Defines the function signature that a listener is expected to have.

      Parameters

      • this: This
      • Rest ...args: Args

      Returns void | Promise<void>

Variables

booleanType

booleanType: DataType<boolean> = ...

Type that represents a boolean.

numberType

numberType: DataType<number> = ...

Type that represents a number.

stringType

stringType: DataType<string> = ...

Type that represents a string value.

voidType

voidType: DataType<void> = ...

Type that represents no value.

Functions

arrayType

serviceContract

  • Decorator for defining what contract a certain class implements.

    @serviceContract(contractHere)
    class ServiceImpl {
    ...
    }

    With Typescript the decorator can't validate the type, but it is recommended to implement the same type as the contract was defined with:

    interface EchoService {
    echo(message: string): Promise<string>;
    }

    const EchoService = new ServiceContract<EchoService>()
    .defineMethod('echo', {
    returnType: stringType,
    parameters: [
    {
    name: 'message',
    type: stringType
    }
    ]
    });

    @serviceContract(EchoService)
    class EchoServiceImpl implements EchoService {
    async echo(message: string) {
    return message;
    }
    }

    Parameters

    Returns ClassDecorator

    decorator

Generated using TypeDoc