Compare commits

...

2 Commits

3 changed files with 24 additions and 5 deletions

View File

@@ -19,6 +19,24 @@
* Only allow specific parameters, unless prefixed with 'x-'
*/
/**
* What I *think* this is:
* Deps: List of transports
*
* Recieving:
* 1. Create from a list of tranpsports and a lsit of items.
* 2. Starts listening on all of the transports and returns a URL (maybe a promise too? Not sure whether it should be a promise or event emitter. Maybe both?)
* 3. Once it recieves a message, decrypt it and resolve the promise with the message.
*
* Sending:
* 1. Create from a list of transports and the URL.
* 2. Encrypt the message
* 3. Send the encrypted message to all of the transports that are in both the requestURL and the list of transports.
*
* Possibilities:
* - Non-ephemeral. Keep listeners alive to allow for multiple requests
*/
import { z } from 'zod/v4';
import { PublicKey } from 'src/crypto/index.js';

View File

@@ -17,17 +17,17 @@ export class EphemeralTransport {
return response;
}
async receive<T extends ZodType>(url: string, schema: T): Promise<output<T>>;
async receive(url: string): Promise<unknown>;
async receive(url: string, schema?: ZodType): Promise<unknown> {
async receive<T extends ZodType | undefined>(url: string, schema?: T): Promise<T extends undefined ? unknown : output<T>> {
const transport = await this.transports(url);
const message = await transport.waitFor('message', () => true);
transport.disconnect();
if (schema) {
return schema.parse(message);
// TODO: Figure out how the hell to fix this assertion. It shouldnt be needed, but TS is being a bitch.
return schema.parse(message) as T extends undefined ? unknown : output<T>;
}
return message;
// TODO: Figure out how the hell to fix this assertion. It shouldnt be needed, but TS is being a bitch.
return message as T extends undefined ? unknown : output<T>;
}
}

View File

@@ -181,6 +181,7 @@ describe('BPlusTree', () => {
it('should handle range on empty tree', () => {
expect(tree.range()).toEqual([]);
expect(tree.range(1, 2)).toEqual([]);
});
it('should handle delete on empty tree', () => {