Skip to content

Commit

Permalink
chore: updated meta type to match signature
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Jan 10, 2025
1 parent 5c8633f commit cf4426f
Show file tree
Hide file tree
Showing 32 changed files with 178 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VaultsClone extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<CloneMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VaultsCreate extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<VaultNameMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<VaultIdMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VaultsDelete extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<VaultIdentifierMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class VaultsList extends ServerHandler<
public handle = async function* (
_input: ClientRPCRequestParams,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<VaultListMessage>> {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VaultsLog extends ServerHandler<
public handle = async function* (
input: ClientRPCRequestParams<VaultsLogMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<LogEntryMessage>> {
ctx.signal.throwIfAborted();
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsPermissionGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class VaultsPermissionGet extends ServerHandler<
public handle = async function* (
input: ClientRPCRequestParams<VaultIdentifierMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<VaultPermissionMessage>> {
ctx.signal.throwIfAborted();
Expand Down
4 changes: 3 additions & 1 deletion src/client/handlers/VaultsPermissionUnset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class VaultsPermissionUnset extends UnaryHandler<
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined();
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
const {
nodeId,
Expand Down
22 changes: 18 additions & 4 deletions src/client/handlers/VaultsPull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import type {
SuccessMessage,
VaultsPullMessage,
} from '../types';
import type { NodeId } from '../../ids';
import type VaultManager from '../../vaults/VaultManager';
import { UnaryHandler } from '@matrixai/rpc';
import { validateSync } from '../../validation';
import { matchSync } from '../../utils';
import * as ids from '../../ids';
import * as vaultsUtils from '../../vaults/utils';
import * as vaultsErrors from '../../vaults/errors';
Expand All @@ -24,7 +27,7 @@ class VaultsPull extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<VaultsPullMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand All @@ -43,9 +46,20 @@ class VaultsPull extends UnaryHandler<
`Vault "${input.nameOrId}" does not exist`,
);
}
const nodeId = input.nodeIdEncoded
? ids.parseNodeId(input.nodeIdEncoded)
: undefined;
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
[
['nodeId'],
() => (value != null ? ids.parseNodeId(value) : undefined),
],
() => value,
);
},
{
nodeId: input.nodeIdEncoded,
},
);
await vaultManager.pullVault(
{
vaultId: vaultId,
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsRename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VaultsRename extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<VaultsRenameMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<VaultIdMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
17 changes: 15 additions & 2 deletions src/client/handlers/VaultsScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import type {
NodeIdMessage,
VaultsScanMessage,
} from '../types';
import type { NodeId } from '../../ids';
import type VaultManager from '../../vaults/VaultManager';
import { ServerHandler } from '@matrixai/rpc';
import { validateSync } from '../../validation';
import { matchSync } from '../../utils';
import * as ids from '../../ids';

class VaultsScan extends ServerHandler<
Expand All @@ -20,12 +23,22 @@ class VaultsScan extends ServerHandler<
public handle = async function* (
input: ClientRPCRequestParams<NodeIdMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<VaultsScanMessage>> {
ctx.signal.throwIfAborted();
const { vaultManager }: { vaultManager: VaultManager } = this.container;
const nodeId = ids.parseNodeId(input.nodeIdEncoded);
const { nodeId }: { nodeId: NodeId } = validateSync(
(keyPath, value) => {
return matchSync(keyPath)(
[['nodeId'], () => ids.parseNodeId(value)],
() => value,
);
},
{
nodeId: input.nodeIdEncoded,
},
);
for await (const {
vaultIdEncoded,
vaultName,
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsSecretsCat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class VaultsSecretsCat extends DuplexHandler<
ClientRPCRequestParams<SecretIdentifierMessage>
>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<ContentOrErrorMessage>> {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
4 changes: 2 additions & 2 deletions src/client/handlers/VaultsSecretsEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VaultsSecretsEnv extends DuplexHandler<
ClientRPCRequestParams<SecretIdentifierMessage>
>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<SecretContentMessage>> {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down Expand Up @@ -59,7 +59,7 @@ class VaultsSecretsEnv extends DuplexHandler<
ctx.signal.throwIfAborted();
const fileContents = await fs.readFile(filePath);
results.push({
filePath,
filePath: filePath,
value: fileContents.toString(),
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/client/handlers/VaultsSecretsGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class VaultsSecretsGet extends ServerHandler<
);
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) throw new vaultsErrors.ErrorVaultsVaultUndefined();
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
// Get the contents of the file
return await vaultManager.withVaults([vaultId], async (vault) => {
const content = await vaultOps.getSecret(vault, input.secretName);
Expand Down
8 changes: 6 additions & 2 deletions src/client/handlers/VaultsSecretsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VaultsSecretsList extends ServerHandler<
public handle = async function* (
input: ClientRPCRequestParams<SecretIdentifierMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<SecretFilesMessage>, void, void> {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand All @@ -36,7 +36,11 @@ class VaultsSecretsList extends ServerHandler<
);
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) throw new vaultsErrors.ErrorVaultsVaultUndefined();
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
return vaultId;
});

Expand Down
3 changes: 2 additions & 1 deletion src/client/handlers/VaultsSecretsMkdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VaultsSecretsMkdir extends DuplexHandler<
public handle = async function* (
input: AsyncIterableIterator<ClientRPCRequestParams<SecretDirMessage>>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<ClientRPCResponseResult<SuccessOrErrorMessageTagged>> {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand All @@ -48,6 +48,7 @@ class VaultsSecretsMkdir extends DuplexHandler<
`Vault "${nameOrId}" does not exist`,
);
}

// Write directories. This doesn't need to be grouped by vault names,
// as no commit is created for empty directories anyway.
yield await vaultManager.withVaults(
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsSecretsNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VaultsSecretsNew extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SecretContentMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
6 changes: 4 additions & 2 deletions src/client/handlers/VaultsSecretsNewDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VaultsSecretsNewDir extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SecretDirMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const {
Expand All @@ -42,7 +42,9 @@ class VaultsSecretsNewDir extends UnaryHandler<
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined();
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
await vaultManager.withVaults(
[vaultId],
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsSecretsRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class VaultsSecretsRemove extends DuplexHandler<
const vaultId = vaultIdFromName ?? vaultsUtils.decodeVaultId(vaultName);
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault ${vaultName} does not exist`,
`Vault "${vaultName}" does not exist`,
);
}
// The resource acquisition will automatically create a transaction and
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsSecretsRename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VaultsSecretsRename extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SecretRenameMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/VaultsSecretsStat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VaultsSecretsStat extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SecretIdentifierMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SecretStatMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand Down
6 changes: 4 additions & 2 deletions src/client/handlers/VaultsSecretsWriteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VaultsSecretsWriteFile extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<SecretContentMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<SuccessMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand All @@ -37,7 +37,9 @@ class VaultsSecretsWriteFile extends UnaryHandler<
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined();
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
const secretContent = Buffer.from(input.secretContent, 'binary');
await vaultManager.withVaults(
Expand Down
6 changes: 4 additions & 2 deletions src/client/handlers/VaultsVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class VaultsVersion extends UnaryHandler<
public handle = async (
input: ClientRPCRequestParams<VaultsVersionMessage>,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue>,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): Promise<ClientRPCResponseResult<VaultsLatestVersionMessage>> => {
const { db, vaultManager }: { db: DB; vaultManager: VaultManager } =
Expand All @@ -36,7 +36,9 @@ class VaultsVersion extends UnaryHandler<
const vaultId =
vaultIdFromName ?? vaultsUtils.decodeVaultId(input.nameOrId);
if (vaultId == null) {
throw new vaultsErrors.ErrorVaultsVaultUndefined();
throw new vaultsErrors.ErrorVaultsVaultUndefined(
`Vault "${input.nameOrId}" does not exist`,
);
}
const versionId = input.versionId;
const [latestOid, currentVersionId] = await vaultManager.withVaults(
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/agent/handlers/NodesClaimNetworkSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class NodesClaimNetworkSign extends UnaryHandler<
> {
public handle = async (
input: AgentRPCRequestParams<AgentClaimMessage>,
_cancel,
_cancel: (reason?: any) => void,
meta: Record<string, JSONValue> | undefined,
): Promise<AgentRPCResponseResult<AgentClaimMessage>> => {
const { nodeManager } = this.container;
const { nodeManager }: { nodeManager: NodeManager } = this.container;
// Connections should always be validated
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
if (requestingNodeId == null) {
Expand Down
8 changes: 3 additions & 5 deletions src/nodes/agent/handlers/NodesClaimNetworkVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ class NodesClaimNetworkVerify extends UnaryHandler<
> {
public handle = async (
input: AgentRPCRequestParams<AgentClaimMessage>,
_cancel,
_cancel: (reason?: any) => void,
meta: Record<string, JSONValue> | undefined,
): Promise<AgentRPCResponseResult<{ success: true }>> => {
const { nodeManager }: { nodeManager: NodeManager } = this.container;
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);
if (requestingNodeId == null) {
throw new agentErrors.ErrorAgentNodeIdMissing();
}
return this.container.nodeManager.handleVerifyClaimNetwork(
requestingNodeId,
input,
);
return nodeManager.handleVerifyClaimNetwork(requestingNodeId, input);
};
}

Expand Down
10 changes: 8 additions & 2 deletions src/nodes/agent/handlers/NodesClaimsGet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ContextTimed } from '@matrixai/contexts';
import type { DB } from '@matrixai/db';
import type { JSONValue } from '@matrixai/rpc';
import type Sigchain from '../../../sigchain/Sigchain';
import type {
AgentRPCRequestParams,
Expand All @@ -22,15 +24,19 @@ class NodesClaimsGet extends ServerHandler<
> {
public handle = async function* (
_input: ClaimIdMessage,
_cancel: (reason?: any) => void,
_meta: Record<string, JSONValue> | undefined,
ctx: ContextTimed,
): AsyncGenerator<AgentRPCResponseResult<AgentClaimMessage>> {
const { sigchain, db } = this.container;
const { sigchain, db }: { sigchain: Sigchain; db: DB } = this.container;
yield* db.withTransactionG(async function* (tran): AsyncGenerator<
AgentRPCResponseResult<AgentClaimMessage>
> {
for await (const [claimId, signedClaim] of sigchain.getSignedClaims(
{ /* seek: seekClaimId,*/ order: 'asc' },
{ order: 'asc' },
tran,
)) {
ctx.signal.throwIfAborted();
const encodedClaim = claimsUtils.generateSignedClaim(signedClaim);
const response: AgentClaimMessage = {
claimIdEncoded: claimsUtils.encodeClaimId(claimId),
Expand Down
Loading

0 comments on commit cf4426f

Please sign in to comment.