Skip to content

Commit 5dc2276

Browse files
authored
Add typescript interface for the added new functions (#1112)
This patch adds typescript interface for the newly added functions, see #1106 #1108 Fix: #1113
1 parent 131ebf8 commit 5dc2276

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

test/types/index.test-d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const NODE_NAME = 'test_node';
77
const LIFECYCLE_NODE_NAME = 'lifecycle_test_node';
88
const TYPE_CLASS = 'std_msgs/msg/String';
99
const TOPIC = 'topic';
10+
const SERVICE_NAME = 'service';
1011
const MSG = rclnodejs.createMessageObject(TYPE_CLASS);
1112
MSG.data = '';
1213

@@ -27,6 +28,7 @@ expectType<string | undefined>(rclnodejs.DistroUtils.getDistroName(2105));
2728

2829
// ---- Context -----
2930
expectType<rclnodejs.Context>(rclnodejs.Context.defaultContext());
31+
expectType<number>(rclnodejs.Context.defaultContext().domainId());
3032

3133
// ---- NodeOptions ----
3234
const nodeOptions = new rclnodejs.NodeOptions();
@@ -69,6 +71,8 @@ expectType<Array<object>>(node.getPublishersInfoByTopic('topic', false));
6971
expectType<Array<object>>(node.getSubscriptionsInfoByTopic('topic', false));
7072
expectType<number>(node.countPublishers(TOPIC));
7173
expectType<number>(node.countSubscribers(TOPIC));
74+
expectType<number>(node.countClients(SERVICE_NAME));
75+
expectType<number>(node.countServices(SERVICE_NAME));
7276
expectType<rclnodejs.Options<string | rclnodejs.QoS>>(
7377
rclnodejs.Node.getDefaultOptions()
7478
);
@@ -229,6 +233,9 @@ expectType<bigint>(timer.timeSinceLastCall());
229233
expectType<bigint>(timer.timeUntilNextCall());
230234
expectType<boolean>(timer.isCanceled());
231235
expectType<void>(timer.cancel());
236+
expectType<void>(timer.changeTimerPeriod(BigInt(100000)));
237+
expectType<bigint>(timer.timerPeriod());
238+
expectType<object>(timer.callTimerWithInfo());
232239

233240
// ---- Rate ----
234241
const rate = await node.createRate(1);

types/context.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,11 @@ declare module 'rclnodejs' {
8787
* @returns The default Context
8888
*/
8989
static defaultContext(): Context;
90+
91+
/**
92+
* Get the domain ID of this context.
93+
* @returns domain ID of this context
94+
*/
95+
domainId(): number;
9096
}
9197
}

types/node.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,5 +782,19 @@ declare module 'rclnodejs' {
782782
* @returns Number of subscribers on the given topic.
783783
*/
784784
countSubscribers(topic: string): number;
785+
786+
/**
787+
* Get the number of clients on a given service name.
788+
* @param serviceName - The service name.
789+
* @returns Number of clients.
790+
*/
791+
countClients(serviceName: string): number;
792+
793+
/**
794+
* Get the number of services on a given service name.
795+
* @param serviceName - The service name.
796+
* @returns Number of services.
797+
*/
798+
countServices(serviceName: string): number;
785799
}
786800
}

types/publisher.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ declare module 'rclnodejs' {
1414
* @param message - The message to be sent.
1515
*/
1616
publish(message: MessageType<T> | Buffer): void;
17+
18+
/**
19+
* Get the number of subscriptions to this publisher.
20+
* @returns The number of subscriptions
21+
*/
22+
subscriptionCount(): number;
1723
}
1824
}

types/subscription.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ declare module 'rclnodejs' {
6666
* @returns True if successful; false otherwise
6767
*/
6868
clearContentFilter(): boolean;
69+
70+
/**
71+
* Get the number of publishers to this subscription.
72+
* @returns The number of publishers
73+
*/
74+
publisherCount(): number;
6975
}
7076
}

types/timer.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,23 @@ declare module 'rclnodejs' {
4545
* @returns The interval value in nanoseconds
4646
*/
4747
timeUntilNextCall(): bigint;
48+
49+
/**
50+
* Change the timer period.
51+
* @param period - The new period in nanoseconds.
52+
*/
53+
changeTimerPeriod(period: bigint): void;
54+
55+
/**
56+
* Get the timer period.
57+
* @return The period in nanoseconds.
58+
*/
59+
timerPeriod(): bigint;
60+
61+
/**
62+
* Call a timer and starts counting again, retrieves actual and expected call time.
63+
* @return - The timer information.
64+
*/
65+
callTimerWithInfo(): object;
4866
}
4967
}

0 commit comments

Comments
 (0)