Skip to content

Commit

Permalink
chore: updated all handlers to be consistent with container deconstru…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
aryanjassal committed Oct 10, 2024
1 parent f96e4c2 commit a82d1fa
Show file tree
Hide file tree
Showing 76 changed files with 259 additions and 157 deletions.
3 changes: 2 additions & 1 deletion src/client/handlers/AgentLockAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AgentLockAll extends UnaryHandler<
ClientRPCResponseResult
> {
public handle = async (): Promise<ClientRPCResponseResult> => {
const { db, sessionManager } = this.container;
const { db, sessionManager }: { db: DB; sessionManager: SessionManager } =
this.container;
await db.withTransactionF((tran) => sessionManager.resetKey(tran));
return {};
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/AgentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AgentStatus extends UnaryHandler<
public handle = async (): Promise<
ClientRPCResponseResult<StatusResultMessage>
> => {
const { polykeyAgent } = this.container;
const { polykeyAgent }: { polykeyAgent: PolykeyAgent } = this.container;
return {
pid: process.pid,
nodeIdEncoded: nodesUtils.encodeNodeId(polykeyAgent.keyRing.getNodeId()),
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/AgentStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AgentStop extends UnaryHandler<
ClientRPCResponseResult
> {
public handle = async (): Promise<ClientRPCResponseResult> => {
const { polykeyAgent } = this.container;
const { polykeyAgent }: { polykeyAgent: PolykeyAgent } = this.container;
// If not running or in stopping status, then respond successfully
if (!polykeyAgent[running] || polykeyAgent[status] === 'stopping') {
return {};
Expand Down
6 changes: 3 additions & 3 deletions src/client/handlers/AuditEventsGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AuditEventsGet extends ServerHandler<
}>,
ClientRPCResponseResult<AuditEventSerialized>
> {
public async *handle(
public handle = async function* (
{
paths,
seek,
Expand All @@ -46,7 +46,7 @@ class AuditEventsGet extends ServerHandler<
_meta,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<AuditEventSerialized>> {
const { audit } = this.container;
const { audit }: { audit: Audit } = this.container;
const iterators: Array<AsyncGenerator<AuditEvent>> = [];
let seek_: AuditEventId | number | undefined;
if (seek != null) {
Expand Down Expand Up @@ -109,7 +109,7 @@ class AuditEventsGet extends ServerHandler<
data: auditEvent.data,
};
}
}
};
}

export default AuditEventsGet;
2 changes: 1 addition & 1 deletion src/client/handlers/AuditMetricGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AuditMetricGet extends UnaryHandler<
_meta,
_ctx,
): Promise<ClientRPCResponseResult<MetricPathToAuditMetric<T>>> => {
const { audit } = this.container;
const { audit }: { audit: Audit } = this.container;
let seek_: AuditEventId | number | undefined;
if (seek != null) {
seek_ =
Expand Down
3 changes: 2 additions & 1 deletion src/client/handlers/GestaltsActionsGetByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class GestaltsActionsGetByIdentity extends UnaryHandler<
actionsList: Array<GestaltAction>;
}>
> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const {
providerId,
identityId,
Expand Down
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsActionsGetByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsActionsGetByNode extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<NodeIdMessage>,
ClientRPCResponseResult<ActionsListMessage>
> {
public handle = async (
input: ClientRPCRequestParams<NodeIdMessage>,
): Promise<ClientRPCResponseResult<ActionsListMessage>> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
Expand Down
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsActionsSetByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsActionsSetByIdentityHandler extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<SetIdentityActionMessage>,
ClientRPCResponseResult
> {
public handle = async (
input: ClientRPCRequestParams<SetIdentityActionMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const {
action,
providerId,
Expand Down
3 changes: 2 additions & 1 deletion src/client/handlers/GestaltsActionsSetByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class GestaltsActionsSetByNode extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SetNodeActionMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const { nodeId, action }: { nodeId: NodeId; action: GestaltAction } =
validateSync(
(keyPath, value) => {
Expand Down
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsActionsUnsetByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsActionsUnsetByIdentity extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<SetIdentityActionMessage>,
ClientRPCResponseResult
> {
public handle = async (
input: ClientRPCRequestParams<SetIdentityActionMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const {
action,
providerId,
Expand Down
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsActionsUnsetByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsActionsUnsetByNode extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<SetNodeActionMessage>,
ClientRPCResponseResult
> {
public handle = async (
input: ClientRPCRequestParams<SetNodeActionMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const { nodeId, action }: { nodeId: NodeId; action: GestaltAction } =
validateSync(
(keyPath, value) => {
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/GestaltsDiscoveryByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GestaltsDiscoveryByIdentity extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<IdentityMessage>,
): Promise<ClientRPCResponseResult> => {
const { discovery } = this.container;
const { discovery }: { discovery: Discovery } = this.container;
const {
providerId,
identityId,
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/GestaltsDiscoveryByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GestaltsDiscoveryByNode extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<NodeIdMessage>,
): Promise<ClientRPCResponseResult> => {
const { discovery } = this.container;
const { discovery }: { discovery: Discovery } = this.container;
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
Expand Down
6 changes: 3 additions & 3 deletions src/client/handlers/GestaltsDiscoveryQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class GestaltsDiscoveryQueue extends ServerHandler<
ClientRPCRequestParams,
ClientRPCResponseResult<DiscoveryQueueInfo>
> {
public async *handle(
public handle = async function* (
_input: ClientRPCRequestParams,
_cancel,
_meta,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<DiscoveryQueueInfo>> {
const { discovery } = this.container;
const { discovery }: { discovery: Discovery } = this.container;
for await (const discoveryQueueInfo of discovery.getDiscoveryQueue()) {
ctx.signal.throwIfAborted();
yield discoveryQueueInfo;
}
}
};
}

export default GestaltsDiscoveryQueue;
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsGestaltGetByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsGestaltGetByIdentity extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<IdentityMessage>,
ClientRPCResponseResult<GestaltMessage>
> {
public handle = async (
input: ClientRPCRequestParams<IdentityMessage>,
): Promise<ClientRPCResponseResult<GestaltMessage>> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const {
providerId,
identityId,
Expand Down
5 changes: 3 additions & 2 deletions src/client/handlers/GestaltsGestaltGetByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import { matchSync } from '../../utils';

class GestaltsGestaltGetByNode extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams<NodeIdMessage>,
ClientRPCResponseResult<GestaltMessage>
> {
public handle = async (
input: ClientRPCRequestParams<NodeIdMessage>,
): Promise<ClientRPCResponseResult<GestaltMessage>> => {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
Expand Down
9 changes: 5 additions & 4 deletions src/client/handlers/GestaltsGestaltList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import * as nodesUtils from '../../nodes/utils';

class GestaltsGestaltList extends ServerHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
},
ClientRPCRequestParams,
ClientRPCResponseResult<GestaltMessage>
> {
public async *handle(
public handle = async function* (
_input,
_cancel,
_meta,
ctx,
): AsyncGenerator<ClientRPCResponseResult<GestaltMessage>> {
const { db, gestaltGraph } = this.container;
const { db, gestaltGraph }: { db: DB; gestaltGraph: GestaltGraph } =
this.container;
yield* db.withTransactionG(async function* (tran): AsyncGenerator<
ClientRPCResponseResult<GestaltMessage>
> {
Expand Down Expand Up @@ -57,7 +58,7 @@ class GestaltsGestaltList extends ServerHandler<
yield gestaltMessage;
}
});
}
};
}

export default GestaltsGestaltList;
9 changes: 7 additions & 2 deletions src/client/handlers/GestaltsGestaltTrustByIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { matchSync } from '../../utils';

class GestaltsGestaltTrustByIdentity extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
discovery: Discovery;
},
ClientRPCRequestParams<IdentityMessage>,
Expand All @@ -24,7 +24,12 @@ class GestaltsGestaltTrustByIdentity extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<IdentityMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph, discovery } = this.container;
const {
db,
gestaltGraph,
discovery,
}: { db: DB; gestaltGraph: GestaltGraph; discovery: Discovery } =
this.container;
const {
providerId,
identityId,
Expand Down
9 changes: 7 additions & 2 deletions src/client/handlers/GestaltsGestaltTrustByNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { matchSync } from '../../utils';

class GestaltsGestaltTrustByNode extends UnaryHandler<
{
gestaltGraph: GestaltGraph;
db: DB;
gestaltGraph: GestaltGraph;
discovery: Discovery;
},
ClientRPCRequestParams<NodeIdMessage>,
Expand All @@ -24,7 +24,12 @@ class GestaltsGestaltTrustByNode extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<NodeIdMessage>,
): Promise<ClientRPCResponseResult> => {
const { db, gestaltGraph, discovery } = this.container;
const {
db,
gestaltGraph,
discovery,
}: { db: DB; gestaltGraph: GestaltGraph; discovery: Discovery } =
this.container;
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
Expand Down
15 changes: 6 additions & 9 deletions src/client/handlers/IdentitiesAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ class IdentitiesAuthenticate extends ServerHandler<
{
identitiesManager: IdentitiesManager;
},
ClientRPCRequestParams<{
providerId: string;
}>,
ClientRPCRequestParams<{ providerId: string }>,
ClientRPCResponseResult<AuthProcessMessage>
> {
public timeout = 120000; // 2 Minutes
public async *handle(
input: ClientRPCRequestParams<{
providerId: string;
}>,
public handle = async function* (
input: ClientRPCRequestParams<{ providerId: string }>,
_cancel,
_meta,
ctx,
): AsyncGenerator<ClientRPCResponseResult<AuthProcessMessage>> {
if (ctx.signal.aborted) throw ctx.signal.reason;
const { identitiesManager } = this.container;
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
this.container;
const {
providerId,
}: {
Expand Down Expand Up @@ -72,7 +69,7 @@ class IdentitiesAuthenticate extends ServerHandler<
identityId: authFlowResult.value,
},
};
}
};
}

export default IdentitiesAuthenticate;
15 changes: 6 additions & 9 deletions src/client/handlers/IdentitiesAuthenticatedGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ class IdentitiesAuthenticatedGet extends ServerHandler<
{
identitiesManager: IdentitiesManager;
},
ClientRPCRequestParams<{
providerId?: string;
}>,
ClientRPCRequestParams<{ providerId?: string }>,
ClientRPCResponseResult<IdentityMessage>
> {
public async *handle(
input: ClientRPCRequestParams<{
providerId?: string;
}>,
public handle = async function* (
input: ClientRPCRequestParams<{ providerId?: string }>,
_cancel,
_meta,
ctx,
): AsyncGenerator<ClientRPCResponseResult<IdentityMessage>> {
if (ctx.signal.aborted) throw ctx.signal.reason;
const { identitiesManager } = this.container;
const { identitiesManager }: { identitiesManager: IdentitiesManager } =
this.container;
let providerId: ProviderId | undefined;
if (input.providerId != null) {
providerId = validateSync(
Expand Down Expand Up @@ -61,7 +58,7 @@ class IdentitiesAuthenticatedGet extends ServerHandler<
};
}
}
}
};
}

export default IdentitiesAuthenticatedGet;
Loading

0 comments on commit a82d1fa

Please sign in to comment.