Initializes a new Procedure.
The underlying callback function powering the procedure itself. The callback may be asynchronous.
Optional
options: Partial<ProcedureDefinitionOptions> = {}Options for a Procedure. Defaults to {}
.
Private
Optional
#endpointPrivate
Optional
#uuidProtected
callbackThe underlying callback function powering the procedure itself. The callback may be asynchronous.
Protected
optionsThe options in use by the Procedure, including defaults.
Protected
socketsThe underlying nanomsg sockets used for data transmission.
An optional msgpack ExtensionCodec to use for encoding and decoding messages.
An optional msgpack ExtensionCodec to use for encoding and decoding messages.
Whether or not to ignore undefined
properties of objects passed to or from a Procedure. Defaults to true
.
When true
on a Procedure, only affects properties of input parameters.
When true
on a call, only affects properties of the return value.
The procedure.js library uses the msgpack
serialization format for encoding JavaScript objects and values for transmission to and from remote procedures.
The JavaScript implementation of msgpack maps undefined
to null
.
This means that when passing objects in or out of a Procedure (i.e. as a parameter or return value), any properties defined as
undefined
will evaluate to null
on receipt.
ignoreUndefinedProperties aims to alleviate this by signalling msgpack to ignore undefined properties from objects before they are encoded,
allowing undefined
to be evaluated as undefined
and null
to be evaluated as null
.
This operation incurs some overhead, and means that code relying on the presence of a property to infer meaning
may not operate as expected.
Whether or not to ignore undefined
properties of objects passed to or from a Procedure. Defaults to true
.
When true
on a Procedure, only affects properties of input parameters.
When true
on a call, only affects properties of the return value.
The procedure.js library uses the msgpack
serialization format for encoding JavaScript objects and values for transmission to and from remote procedures.
The JavaScript implementation of msgpack maps undefined
to null
.
This means that when passing objects in or out of a Procedure (i.e. as a parameter or return value), any properties defined as
undefined
will evaluate to null
on receipt.
ignoreUndefinedProperties aims to alleviate this by signalling msgpack to ignore undefined properties from objects before they are encoded,
allowing undefined
to be evaluated as undefined
and null
to be evaluated as null
.
This operation incurs some overhead, and means that code relying on the presence of a property to infer meaning
may not operate as expected.
Whether or not to enable optional parameter support. Defaults to true
.
When true
on a Procedure, a null
input parameter will be coerced to undefined
.
When true
for a call, a null
return value will be coerced to undefined
.
The procedure.js library uses the msgpack
serialization format for encoding JavaScript objects and values for transmission to and from remote procedures.
The JavaScript implementation of msgpack maps undefined
to null
.
For procedures which accept optional parameters, this is problematic.
It could also be an issue if you depend on the return value of a procedure to conditionally be undefined
,
for the convenience of passing the return value into an optional parameter of another function call.
optionalParameterSupport aims to alleviate these issues by mapping null
to undefined
for the input and output of your Procedure calls.
Whether or not to enable optional parameter support. Defaults to true
.
When true
on a Procedure, a null
input parameter will be coerced to undefined
.
When true
for a call, a null
return value will be coerced to undefined
.
The procedure.js library uses the msgpack
serialization format for encoding JavaScript objects and values for transmission to and from remote procedures.
The JavaScript implementation of msgpack maps undefined
to null
.
For procedures which accept optional parameters, this is problematic.
It could also be an issue if you depend on the return value of a procedure to conditionally be undefined
,
for the convenience of passing the return value into an optional parameter of another function call.
optionalParameterSupport aims to alleviate these issues by mapping null
to undefined
for the input and output of your Procedure calls.
Protected
uuidA v5 uuid generated from endpoint, used to identify ping requests.
Whether or not to output errors and events to the console. Defaults to false
.
Whether or not to output errors and events to the console. Defaults to false
.
The number of workers to spin up for the Procedure. Useful for procedures which may take a long time to complete.
Will be clamped between 1
and Number.MAX_SAFE_INTEGER
inclusive.
Defaults to 1
.
The number of workers to spin up for the Procedure. Useful for procedures which may take a long time to complete.
Will be clamped between 1
and Number.MAX_SAFE_INTEGER
inclusive.
Defaults to 1
.
Private
#emitPrivate
#emitEmits and optionally logs a given error.
A custom error message describing the cause of the error. The message will be concatenated with the Procedure's endpoint.
Optional
error: ProcedureErrorThe error.
Private
#emitPrivate
#logOptionally logs the close event of the Procedure's underlying sockets.
Private
#onPrivate
#onPrivate
#tryAttempts to decode the given Buffer.
If successful, an object of shape { input: Input | Ping }
,
otherwise { error: unknown }
.
The Buffer to decode.
Private
#tryAttempts to encode the given response for transmission back to the Procedure's caller.
A Buffer containing the encoded response.
The response to encode.
Private
#tryAttempts to asynchronously call the Procedure's callback and return a response containing its output value.
A Promise which when resolved passes the response to the then handler(s).
An input parameter to pass to the callback.
Private
#tryHandles ping requests for a given socket.
true
when the decoded data object was a valid Ping and handled, otherwise false
.
The decoded incoming data object.
The socket the data was received on.
Private
#tryAttempts to send the encoded buffer back to the Procedure's caller.
true
when the encoded Buffer was successfully sent, otherwise false
.
A Buffer containing the encoded response.
The socket through which to send the response.
Binds the Procedure to an endpoint, making it available to be called.
The bound Procedure for method chaining.
The endpoint at which the procedure will be callable.
Optional
ipv6: boolean = falseWhether the endpoint requires ipv6 support. Defaults to false
.
Rest
...args: Parameters<ProcedureEvents<Input>[E]>Optional
event: EGenerated using TypeDoc
A simple abstraction of a procedure (the P in RPC). Allows you to turn a function or callback into a procedure, which can be called via the transport specified.
See
TypedEmitter