Skip to content

Commit c733337

Browse files
committed
feat: implemented basic functionality of nodesAuditGet test
1 parent 09065aa commit c733337

File tree

4 files changed

+244
-178
lines changed

4 files changed

+244
-178
lines changed

src/network/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ async function resolveHostnames(
440440
// TODO: review and fix the `toError` and `fromError` code here.
441441
// Right now it's very basic and need fleshing out.
442442
function fromError(error: any) {
443+
console.error(error);
443444
switch (typeof error) {
444445
case 'symbol':
445446
case 'bigint':

src/nodes/agent/handlers/NodesAuditEventsGet.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ContextTimed } from '@matrixai/contexts';
22
import type { DB } from '@matrixai/db';
33
import type { JSONValue } from '@matrixai/rpc';
4-
import type Sigchain from '../../../sigchain/Sigchain';
54
import type {
65
AgentRPCRequestParams,
76
AgentRPCResponseResult,
@@ -11,29 +10,30 @@ import type {
1110
import type Audit from '../../../audit/Audit';
1211
import { ServerHandler } from '@matrixai/rpc';
1312
import * as auditUtils from '../../../audit/utils'
13+
import { AuditEvent } from '@/audit/types';
1414

1515
/**
1616
* Gets audit events from a node
1717
*/
1818
class NodesAuditEventsGet extends ServerHandler<
1919
{
20-
sigchain: Sigchain;
20+
audit: Audit;
2121
db: DB;
2222
},
2323
AgentRPCRequestParams<AuditIdMessage>,
24-
AgentRPCResponseResult<AgentAuditMessage>
24+
AgentRPCResponseResult<AgentAuditMessage<AuditEvent>>
2525
> {
2626
public handle = async function* (
2727
input: AgentRPCRequestParams<AuditIdMessage>,
2828
_cancel: (reason?: any) => void,
2929
_meta: Record<string, JSONValue> | undefined,
3030
ctx: ContextTimed,
31-
): AsyncGenerator<AgentRPCResponseResult<AgentAuditMessage>> {
31+
): AsyncGenerator<AgentRPCResponseResult<AgentAuditMessage<AuditEvent>>> {
3232
const { seek, seekEnd, limit } = input;
3333
const { audit, db }: { audit: Audit; db: DB } = this.container;
3434

3535
yield* db.withTransactionG(async function* (tran): AsyncGenerator<
36-
AgentRPCResponseResult<AgentAuditMessage>
36+
AgentRPCResponseResult<AgentAuditMessage<AuditEvent>>
3737
> {
3838
for await (const auditEvent of audit.getAuditEvents(
3939
[],
@@ -46,7 +46,9 @@ class NodesAuditEventsGet extends ServerHandler<
4646
)) {
4747
ctx.signal.throwIfAborted();
4848
yield {
49-
auditIdEncoded: auditUtils.encodeAuditEventId(auditEvent.id)
49+
id: auditUtils.encodeAuditEventId(auditEvent.id),
50+
path: auditEvent.path,
51+
data: auditEvent.data
5052
};
5153
}
5254
});

src/nodes/agent/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { VaultAction, VaultName } from '../../vaults/types';
1515
import type { SignedNotification } from '../../notifications/types';
1616
import type { Host, Hostname, Port } from '../../network/types';
1717
import type { NodeContact } from '../../nodes/types';
18+
import { AuditEvent } from '@/audit/types';
1819

1920
type AgentRPCRequestParams<T extends JSONObject = JSONObject> =
2021
JSONRPCRequestParams<T>;
@@ -23,14 +24,15 @@ type AgentRPCResponseResult<T extends JSONObject = JSONObject> =
2324
JSONRPCResponseResult<T>;
2425

2526
type AuditIdMessage = {
26-
auditIdEncoded: AuditEventIdEncoded;
2727
seek?: AuditEventId | number;
2828
seekEnd?: AuditEventId | number;
2929
order?: 'asc' | 'desc';
3030
limit?: number;
3131
};
3232

33-
type AgentAuditMessage = Partial<AuditIdMessage> & {};
33+
type AgentAuditMessage<T extends AuditEvent> = Omit<T, 'id'> & {
34+
id: AuditEventIdEncoded
35+
};
3436

3537
type NodesClaimsGetMessage = {
3638
seek?: ClaimIdEncoded | number;

0 commit comments

Comments
 (0)