Skip to content

Commit b65ea23

Browse files
authored
Merge pull request #40 from Procedure-RPC/simplify-generics
Simplify generics
2 parents 972df7a + d2677a3 commit b65ea23

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@procedure-rpc/procedure.js",
3-
"version": "0.8.4",
3+
"version": "0.9.0",
44
"title": "procedure.js",
55
"description": "The simple RPC framework for Node.js.",
66
"main": "./dist/index.js",
@@ -58,7 +58,7 @@
5858
"typed-emitter": "^2.1.0",
5959
"typedoc": "^0.23.10",
6060
"typedoc-plugin-versions": "^0.1.1",
61-
"typescript": "^4.7.4"
61+
"typescript": "^4.8.0"
6262
},
6363
"files": [
6464
"dist/**/*.*js",

src/index.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ const uuidNamespace = uuidv5(homepage, uuidv5.URL);
3333
* @template Output Type of output value the procedure returns. Defaults to `undefined`.
3434
* @see [TypedEmitter](https://github.com/andywer/typed-emitter#readme)
3535
*/
36-
export class Procedure<
37-
Input extends Nullable = undefined,
38-
Output extends Nullable = undefined
39-
>
36+
export class Procedure<Input = undefined, Output = undefined>
4037
extends (EventEmitter as {
4138
new <Input>(): TypedEmitter<ProcedureEvents<Input>>;
4239
})<Input>
@@ -473,27 +470,21 @@ export class Procedure<
473470
}
474471
export default Procedure;
475472

476-
/**
477-
* Represents a nullable value.
478-
*/
479-
export type Nullable = unknown | null | undefined;
480-
481473
/**
482474
* Represents a simple callback function which can take a single input parameter.
483475
* @template Input The type of input parameter the callback accepts. Defaults to `undefined`.
484476
* @template Output The type of output value the callback returns. Defaults to `undefined`.
485477
* @see {@link Procedure}
486478
*/
487-
export type Callback<
488-
Input extends Nullable = undefined,
489-
Output extends Nullable = undefined
490-
> = (input: Input) => Output;
479+
export type Callback<Input = undefined, Output = undefined> = (
480+
input: Input
481+
) => Output;
491482

492483
/**
493484
* A response from a {@link call Procedure call}.
494485
* If the call returned successfully, the response will be of shape `{ output: Output }`, otherwise `{ error: ProcedureError }`.
495486
*/
496-
export type Response<Output extends Nullable = undefined> =
487+
export type Response<Output = undefined> =
497488
| { output: Output | null | undefined; error?: never; pong?: never }
498489
| { output?: never; error: ProcedureError | null | undefined; pong?: never }
499490
| { output?: never; error?: never; pong: string };
@@ -599,7 +590,7 @@ export interface ProcedureCallOptions extends ProcedureOptions {
599590
* @template Input The type of input parameter passed to the data event.
600591
* @see [TypedEmitter](https://github.com/andywer/typed-emitter#readme)
601592
*/
602-
export type ProcedureEvents<Input extends Nullable = undefined> = {
593+
export type ProcedureEvents<Input = undefined> = {
603594
/**
604595
* Signature for the data event.
605596
* @param {Input} data The input parameter which was passed to the {@link Procedure}.
@@ -651,9 +642,9 @@ export function isPing(object: unknown): object is Ping {
651642
* @see {@link Procedure.endpoint}
652643
* @see {@link ping}
653644
*/
654-
export async function call<Output extends Nullable = unknown>(
645+
export async function call<Output = unknown>(
655646
endpoint: string,
656-
input?: Nullable,
647+
input?: unknown,
657648
options: Partial<ProcedureCallOptions> = {}
658649
): Promise<Output> {
659650
try {
@@ -848,9 +839,9 @@ export async function tryPing(
848839
* [then](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) handler(s).
849840
* @template Output The type of output value expected to be returned from the {@link Procedure}. Defaults to `unknown`.
850841
*/
851-
async function getResponse<Output extends Nullable = unknown>(
842+
async function getResponse<Output = unknown>(
852843
endpoint: string,
853-
input: Nullable,
844+
input: unknown,
854845
options: ProcedureCallOptions
855846
): Promise<Response<Output>> {
856847
let socket: Socket | undefined;

0 commit comments

Comments
 (0)