Skip to content

Commit a2688d1

Browse files
authored
Merge pull request #41 from Procedure-RPC/remove-callback-export
Remove `Callback<Input, Output>` export
2 parents 997eac0 + 9009b31 commit a2688d1

File tree

4 files changed

+37
-48
lines changed

4 files changed

+37
-48
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@procedure-rpc/procedure.js",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"title": "procedure.js",
55
"description": "The simple RPC framework for Node.js.",
66
"main": "./dist/index.js",

src/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ export class Procedure<Input = undefined, Output = undefined>
126126

127127
/**
128128
* Initializes a new {@link Procedure}.
129-
* @param {Callback<Input, Output>} callback The underlying callback function powering the procedure itself. The callback may be asynchronous.
129+
* @param {(input: Input) => Output} callback The underlying callback function powering the procedure itself. The callback may be asynchronous.
130130
* @param {Partial<ProcedureDefinitionOptions>} [options] Options for a {@link Procedure}. Defaults to `{}`.
131131
* @template Input Type of input parameter the procedure accepts. Defaults to `undefined`.
132132
* @template Output Type of output value the procedure returns. Defaults to `undefined`.
133133
*/
134134
constructor(
135-
protected callback: Callback<Input, Output>,
135+
protected callback: (input: Input) => Output,
136136
options: Partial<ProcedureDefinitionOptions> = {}
137137
) {
138138
super();
@@ -470,16 +470,6 @@ export class Procedure<Input = undefined, Output = undefined>
470470
}
471471
export default Procedure;
472472

473-
/**
474-
* Represents a simple callback function which can take a single input parameter.
475-
* @template Input The type of input parameter the callback accepts. Defaults to `undefined`.
476-
* @template Output The type of output value the callback returns. Defaults to `undefined`.
477-
* @see {@link Procedure}
478-
*/
479-
export type Callback<Input = undefined, Output = undefined> = (
480-
input: Input
481-
) => Output;
482-
483473
/**
484474
* A response from a {@link call Procedure call}.
485475
* If the call returned successfully, the response will be of shape `{ output: Output }`, otherwise `{ error: ProcedureError }`.

test/index.spec.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ExtensionCodec } from '@msgpack/msgpack';
2-
import Procedure, { call, ping, tryPing, isPing, Callback } from '../src';
2+
import Procedure, { call, ping, tryPing, isPing } from '../src';
33
import {
44
ProcedureErrorCodes,
55
ProcedureInternalServerError,
@@ -329,7 +329,7 @@ describe('Procedure', () => {
329329
});
330330

331331
describe('call(endpoint: string, input: Input | null, options: Partial<ProcedureCallOptions>): Promise<Output>', () => {
332-
let fn: Callback<unknown, unknown>;
332+
let fn: ReturnType<typeof jest.fn>;
333333
let procedure: Procedure<unknown, unknown>;
334334
let procedureEndpoint: string;
335335
let input: unknown;
@@ -339,13 +339,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
339339
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
340340
beforeEach(() => {
341341
let i = 0;
342-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
342+
fn = jest.fn((n: number) => {
343343
if (typeof n !== 'number') {
344344
throw new TypeError('Expected a number');
345345
}
346346

347347
return (i += n);
348-
}));
348+
});
349349
procedureEndpoint = 'inproc://Procedure/Add';
350350
procedure = new Procedure(fn, { workers: 3 });
351351
procedure.bind(procedureEndpoint);
@@ -528,13 +528,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
528528

529529
describe('when procedure callback: Callback<number, null> (testing nullish returns)', () => {
530530
beforeEach(() => {
531-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
531+
fn = jest.fn((n: number) => {
532532
if (typeof n !== 'number') {
533533
throw new TypeError('Expected a number');
534534
}
535535

536536
return null;
537-
}));
537+
});
538538
procedureEndpoint = 'inproc://Procedure/ReturnsNull';
539539
procedure = new Procedure(fn, { workers: 3 });
540540
procedure.bind(procedureEndpoint);
@@ -717,13 +717,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
717717

718718
describe('when procedure callback: Callback<number, void> (testing nullish returns)', () => {
719719
beforeEach(() => {
720-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
720+
fn = jest.fn((n: number) => {
721721
if (typeof n !== 'number') {
722722
throw new TypeError('Expected a number');
723723
}
724724

725725
return;
726-
}));
726+
});
727727
procedureEndpoint = 'inproc://Procedure/ReturnsVoid';
728728
procedure = new Procedure(fn, { workers: 3 });
729729
procedure.bind(procedureEndpoint);
@@ -916,13 +916,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
916916
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
917917
beforeEach(() => {
918918
let i = 0;
919-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
919+
fn = jest.fn((n: number) => {
920920
if (typeof n !== 'number') {
921921
throw new TypeError('Expected a number');
922922
}
923923

924924
return (i += n);
925-
}));
925+
});
926926
procedureEndpoint = 'ipc://procedure/add';
927927
procedure = new Procedure(fn, { workers: 3 });
928928
procedure.bind(procedureEndpoint);
@@ -1105,13 +1105,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
11051105

11061106
describe('when procedure callback: Callback<number, null> (testing nullish returns)', () => {
11071107
beforeEach(() => {
1108-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
1108+
fn = jest.fn((n: number) => {
11091109
if (typeof n !== 'number') {
11101110
throw new TypeError('Expected a number');
11111111
}
11121112

11131113
return null;
1114-
}));
1114+
});
11151115
procedureEndpoint = 'ipc://procedure/returnsnull';
11161116
procedure = new Procedure(fn, { workers: 3 });
11171117
procedure.bind(procedureEndpoint);
@@ -1294,13 +1294,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
12941294

12951295
describe('when procedure callback: Callback<number, void> (testing nullish returns)', () => {
12961296
beforeEach(() => {
1297-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
1297+
fn = jest.fn((n: number) => {
12981298
if (typeof n !== 'number') {
12991299
throw new TypeError('Expected a number');
13001300
}
13011301

13021302
return;
1303-
}));
1303+
});
13041304
procedureEndpoint = 'ipc://procedure/returnsvoid';
13051305
procedure = new Procedure(fn, { workers: 3 });
13061306
procedure.bind(procedureEndpoint);
@@ -1486,13 +1486,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
14861486
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
14871487
beforeEach(() => {
14881488
let i = 0;
1489-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
1489+
fn = jest.fn((n: number) => {
14901490
if (typeof n !== 'number') {
14911491
throw new TypeError('Expected a number');
14921492
}
14931493

14941494
return (i += n);
1495-
}));
1495+
});
14961496
procedureEndpoint = 'tcp://127.0.0.1:33333';
14971497
procedure = new Procedure(fn, { workers: 3 });
14981498
procedure.bind(procedureEndpoint);
@@ -1675,13 +1675,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
16751675

16761676
describe('when procedure callback: Callback<number, null> (testing nullish returns)', () => {
16771677
beforeEach(() => {
1678-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
1678+
fn = jest.fn((n: number) => {
16791679
if (typeof n !== 'number') {
16801680
throw new TypeError('Expected a number');
16811681
}
16821682

16831683
return null;
1684-
}));
1684+
});
16851685
procedureEndpoint = 'tcp://127.0.0.1:33334';
16861686
procedure = new Procedure(fn, { workers: 3 });
16871687
procedure.bind(procedureEndpoint);
@@ -1864,13 +1864,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
18641864

18651865
describe('when procedure callback: Callback<number, void> (testing nullish returns)', () => {
18661866
beforeEach(() => {
1867-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
1867+
fn = jest.fn((n: number) => {
18681868
if (typeof n !== 'number') {
18691869
throw new TypeError('Expected a number');
18701870
}
18711871

18721872
return;
1873-
}));
1873+
});
18741874
procedureEndpoint = 'tcp://127.0.0.1:33335';
18751875
procedure = new Procedure(fn, { workers: 3 });
18761876
procedure.bind(procedureEndpoint);
@@ -2056,13 +2056,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
20562056
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
20572057
beforeEach(() => {
20582058
let i = 0;
2059-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
2059+
fn = jest.fn((n: number) => {
20602060
if (typeof n !== 'number') {
20612061
throw new TypeError('Expected a number');
20622062
}
20632063

20642064
return (i += n);
2065-
}));
2065+
});
20662066
procedureEndpoint = 'ws://127.0.0.1:33333';
20672067
procedure = new Procedure(fn, { workers: 3 });
20682068
procedure.bind(procedureEndpoint);
@@ -2245,13 +2245,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
22452245

22462246
describe('when procedure callback: Callback<number, null> (testing nullish returns)', () => {
22472247
beforeEach(() => {
2248-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
2248+
fn = jest.fn((n: number) => {
22492249
if (typeof n !== 'number') {
22502250
throw new TypeError('Expected a number');
22512251
}
22522252

22532253
return null;
2254-
}));
2254+
});
22552255

22562256
procedureEndpoint = 'ws://127.0.0.1:33334';
22572257
procedure = new Procedure(fn, { workers: 3 });
@@ -2435,13 +2435,13 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
24352435

24362436
describe('when procedure callback: Callback<number, void> (testing nullish returns)', () => {
24372437
beforeEach(() => {
2438-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
2438+
fn = jest.fn((n: number) => {
24392439
if (typeof n !== 'number') {
24402440
throw new TypeError('Expected a number');
24412441
}
24422442

24432443
return;
2444-
}));
2444+
});
24452445

24462446
procedureEndpoint = 'ws://127.0.0.1:33335';
24472447
procedure = new Procedure(fn, { workers: 3 });
@@ -2626,21 +2626,21 @@ describe('call(endpoint: string, input: Input | null, options: Partial<Procedure
26262626
});
26272627

26282628
describe('ping(endpoint: string, timeout: number | undefined = 100, signal?: AbortSignal): Promise<boolean>', () => {
2629-
let fn: Callback<unknown, unknown>;
2629+
let fn: ReturnType<typeof jest.fn>;
26302630
let procedure: Procedure<unknown, unknown>;
26312631
let procedureEndpoint: string;
26322632
let pingEndpoint: string | undefined;
26332633

26342634
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
26352635
beforeEach(() => {
26362636
let i = 0;
2637-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
2637+
fn = jest.fn((n: number) => {
26382638
if (typeof n !== 'number') {
26392639
throw new TypeError('Expected a number');
26402640
}
26412641

26422642
return (i += n);
2643-
}));
2643+
});
26442644

26452645
procedureEndpoint = 'inproc://Procedure/Add';
26462646
procedure = new Procedure(fn, { workers: 3 });
@@ -2690,22 +2690,21 @@ describe('ping(endpoint: string, timeout: number | undefined = 100, signal?: Abo
26902690
});
26912691

26922692
describe('tryPing(endpoint: string, timeout: number | undefined = 100, signal?: AbortSignal): Promise<boolean>', () => {
2693-
let fn: Callback<unknown, unknown>;
2694-
2693+
let fn: ReturnType<typeof jest.fn>;
26952694
let procedure: Procedure<unknown, unknown>;
26962695
let procedureEndpoint: string;
26972696
let pingEndpoint: string | undefined;
26982697

26992698
describe('when procedure callback: Callback<number, number> (simple accumulator function)', () => {
27002699
beforeEach(() => {
27012700
let i = 0;
2702-
fn = jest.fn(<Callback<unknown, unknown>>((n: number) => {
2701+
fn = jest.fn((n: number) => {
27032702
if (typeof n !== 'number') {
27042703
throw new TypeError('Expected a number');
27052704
}
27062705

27072706
return (i += n);
2708-
}));
2707+
});
27092708

27102709
procedureEndpoint = 'inproc://Procedure/Add';
27112710
procedure = new Procedure(fn, { workers: 3 });

0 commit comments

Comments
 (0)