Skip to content

Commit adb1b5e

Browse files
authored
feat: add node method to fetch node info
feat: add node method to fetch node info
1 parent 00bedd2 commit adb1b5e

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

packages/homestar/src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as T from './types.js'
2121
* @typedef {T.HomestarEvents} HomestarEvents
2222
* @typedef {T.HomestarOptions} HomestarOptions
2323
* @typedef {T.Metrics} Metrics
24+
* @typedef {T.Node} Node
2425
* @typedef {T.Health} Health
2526
* @typedef {T.WorkflowNotification} WorkflowNotification
2627
* @typedef {T.EventNotification} EventNotification
@@ -91,6 +92,15 @@ export class Homestar extends Emittery {
9192
})
9293
}
9394

95+
/**
96+
* Homestar Node info
97+
*/
98+
async node() {
99+
return this.#channel.request({
100+
method: 'node',
101+
})
102+
}
103+
94104
/**
95105
* Homestar Health info
96106
*/

packages/homestar/src/schemas.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CID as _CID } from 'multiformats/cid'
44
/**
55
* @typedef {import('zod').z.infer<typeof Receipt>} Receipt
66
* @typedef {import('zod').z.infer<typeof Metrics>} Metrics
7+
* @typedef {import('zod').z.infer<typeof Node>} Node
78
* @typedef {import('zod').z.infer<typeof Health>} Health
89
* @typedef {import('zod').z.infer<typeof Invocation>} Invocation
910
* @typedef {import('zod').z.infer<typeof Task>} Task
@@ -30,10 +31,11 @@ export const Metrics = z.object({
3031

3132
export const Health = z.object({
3233
healthy: z.boolean(),
33-
// nodeInfo: z.object({
34-
// static: z.object({ peer_id: z.string() }),
35-
// dynamic: z.object({ listeners: z.array(z.string()) }),
36-
// }),
34+
})
35+
36+
export const Node = z.object({
37+
static: z.object({ peer_id: z.string() }),
38+
dynamic: z.object({ listeners: z.array(z.string()) }),
3739
})
3840

3941
export const CID = /** @type {typeof z.custom<import('multiformats').CID>} */ (

packages/homestar/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface Receipt<Out> extends Schemas.Receipt {
3131
export type HomestarService = Service<
3232
[
3333
IO<{ method: 'metrics' }, Schemas.Metrics>,
34+
IO<{ method: 'node' }, Schemas.Node>,
3435
IO<{ method: 'health' }, Schemas.Health>,
3536
IO<{ method: 'subscribe_run_workflow'; params: Workflow[] }, string>,
3637
IO<{ method: 'subscribe_network_events' }, string>,

packages/homestar/test/homestar.test.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ test(
5353
}
5454
)
5555

56+
test(
57+
'should fetch node info from homestar',
58+
async function () {
59+
const hs = new Homestar({
60+
transport: new WebsocketTransport(HS1_URL, {
61+
ws: WebSocket,
62+
}),
63+
})
64+
65+
const { error, result } = await hs.node()
66+
67+
if (error) {
68+
return assert.fail(error)
69+
}
70+
71+
assert.ok(typeof result.static.peer_id === 'string')
72+
assert.ok(Array.isArray(result.dynamic.listeners))
73+
hs.close()
74+
},
75+
{
76+
timeout: 30_000,
77+
}
78+
)
79+
5680
test(
5781
'should fetch health from homestar',
5882
async function () {
@@ -69,9 +93,7 @@ test(
6993
}
7094

7195
assert.equal(result.healthy, true)
72-
// assert.ok(result.nodeInfo)
73-
// assert.ok(typeof result.nodeInfo.static.peer_id === 'string')
74-
// assert.ok(Array.isArray(result.nodeInfo.dynamic.listeners))
96+
7597
hs.close()
7698
},
7799
{

0 commit comments

Comments
 (0)