Skip to content

Commit

Permalink
chore: updated handler name
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 9, 2024
1 parent 527556d commit 1a1dc55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
20 changes: 4 additions & 16 deletions src/client/handlers/VaultsSecretsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as vaultsErrors from '../../vaults/errors';
import * as utils from '../../utils';
import { fileTree } from '../../vaults';

class VaultsSecretsGet extends RawHandler<{
class VaultsSecretsGetFileTree extends RawHandler<{
vaultManager: VaultManager;
db: DB;
}> {
Expand Down Expand Up @@ -67,31 +67,19 @@ class VaultsSecretsGet extends RawHandler<{
});
});

async function* filterTransform(
source: AsyncGenerator<TreeNode | ContentNode | Uint8Array>,
): AsyncGenerator<Uint8Array> {
for await (const chunk of source) {
if (chunk instanceof Uint8Array) {
// @ts-ignore while the types don't fully match, they match enough
yield Buffer.from(chunk).toString();
}
}
}
const filteredFilesData = filterTransform(filesData);

const filesDataStream = new ReadableStream<Uint8Array>({
pull: async (controller) => {
const next = await filteredFilesData.next();
const next = await filesData.next();
if (next.done === true) return controller.close();
controller.enqueue(next.value);
},
cancel: async() => {
filteredFilesData.return('Closed');
filesData.return('Closed');
}
});

return [{}, filesDataStream];
};
}

export default VaultsSecretsGet;
export default VaultsSecretsGetFileTree;
6 changes: 4 additions & 2 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,15 +1602,17 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => {
});

console.log(secrets);
console.log(secrets.readable);

const secretDataStream = secrets.readable;
const parserTransform = fileTree.parserTransformStreamFactory();
const parsedFilesStream = secretDataStream.pipeThrough(parserTransform);
const parsedFiles: Array<Uint8Array | TreeNode | ContentNode> = []
console.log('after parsing files');

const parsedFiles: Array<Uint8Array | TreeNode | ContentNode> = []
for await (const file of parsedFilesStream) {
console.log('adding file');
parsedFiles.push(file);
console.log('file added');
}

console.log(parsedFiles);
Expand Down

0 comments on commit 1a1dc55

Please sign in to comment.