Get all of the events defined by this contract.
array with events
Get all of the methods defined by this contract.
array with methods
Describe an event.
new instance with event added
Describe a method.
new instance with method added
Get the contract for an event via its name.
contract for event or null
if event does not exist
Get the contract for a method via its name.
contract for method or null
if method does not exist
Implement this contract using the given handler.
instance with added marker for the contract
Get the service contract a certain object implements. This works for
objects returned for implement and for objects/classes that
either define their contract in the serviceContract
property or using
the serviceContract decorator.
contract as defined by the instance or null
if no contract is
available
Merge several contract instances together. Methods and events will be treated in left to right order, methods/events that are redefined by contracts later in the array will be checked for compatibility.
merged contract
Generated using TypeDoc
Contract for a service, defines methods that can be invoked and events that can be listened to.
For TypeScript contracts are typed and can be used with interfaces to help guide in their definition:
Defining methods
Methods are defined with {@link defineMethod} and need to provide the name of the method, its return type and parameters.
For methods that return nothing voidType should be used:
Defining events
Events are defined with {@link defineEvent} and should provide information about the parameters the event emits. For implementations
AsyncEvent
is assumed to be used.Using contracts
When using classes the recommended way to mark what contract a class implements is to use the serviceContract decorator:
If the decorator is not used you can define a static property called
serviceContract
instead:Contracts will traverse the prototype chain, so defining contract on extended classes work well:
For plain objects the easiest way to use a contract is to use implement:
As with classes a property may be used instead: