Skip to content

Commit

Permalink
chore: added custom type and pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 6, 2024
1 parent 65537d7 commit 1813a10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/client/handlers/VaultsSecretsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import type {
ClientRPCRequestParams,
ClientRPCResponseResult,
SecretFilesList,
VaultIdentifierMessage,
SecretPatternMessage,
} from '../types';
import type VaultManager from '../../vaults/VaultManager';
import { UnaryHandler } from '@matrixai/rpc';
import * as vaultsUtils from '../../vaults/utils';
import * as vaultsErrors from '../../vaults/errors';
import { fileTree } from '@/vaults';
import { ContentNode, TreeNode } from '@/vaults/types';
import type { ContentNode, TreeNode } from '../../vaults/types';
import { fileTree } from '../../vaults';

class VaultsSecretsList extends UnaryHandler<
{
vaultManager: VaultManager;
db: DB;
},
ClientRPCRequestParams<VaultIdentifierMessage>,
ClientRPCRequestParams<SecretPatternMessage>,
ClientRPCResponseResult<SecretFilesList>
> {
public handle = async (
input: ClientRPCRequestParams<VaultIdentifierMessage>,
input: ClientRPCRequestParams<SecretPatternMessage>,
): Promise<ClientRPCResponseResult<SecretFilesList>> => {
const { vaultManager, db } = this.container;
return await db.withTransactionF(async (tran) => {
Expand All @@ -41,24 +41,25 @@ class VaultsSecretsList extends UnaryHandler<
const fileTreeGen = fileTree.globWalk({
fs,
basePath: vault.vaultDataDir, // NOTE: check if this is correct
pattern: input.pattern,
yieldStats: true,
yieldRoot: false,
yieldFiles: true,
yieldParents: true,
yieldDirectories: true,
});
const data: Array<TreeNode | ContentNode | Uint8Array> = []
const data: Array<TreeNode | ContentNode | Uint8Array> = [];
const parserTransform = fileTree.parserTransformStreamFactory();
const serializedStream = fileTree.serializerStreamFactory(
fs,
fileTreeGen,
false,
)
);
const outputStream = serializedStream.pipeThrough(parserTransform);
for await (const output of outputStream) {
data.push(output)
}
return data
data.push(output);
};
return data;
});

const files = data
Expand Down
5 changes: 5 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ type SecretFilesList = {
secretFilesList: Array<string>;
}

type SecretPatternMessage = VaultIdentifierMessage & {
pattern: string;
}

// NOTE: we used to use SecretNameMessage before. do we need to keep it? look into this.

type SecretNameMessage = {
Expand Down Expand Up @@ -419,6 +423,7 @@ export type {
SecretFilesList,
SecretNameMessage,
SecretIdentifierMessage,
SecretPatternMessage,
ContentMessage,
SecretContentMessage,
SecretMkdirMessage,
Expand Down

0 comments on commit 1813a10

Please sign in to comment.