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-' * 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 { z } from 'zod/v4';
import { PublicKey } from 'src/crypto/index.js'; import { PublicKey } from 'src/crypto/index.js';

View File

@@ -17,17 +17,17 @@ export class EphemeralTransport {
return response; return response;
} }
async receive<T extends ZodType>(url: string, schema: T): Promise<output<T>>; async receive<T extends ZodType | undefined>(url: string, schema?: T): Promise<T extends undefined ? unknown : output<T>> {
async receive(url: string): Promise<unknown>;
async receive(url: string, schema?: ZodType): Promise<unknown> {
const transport = await this.transports(url); const transport = await this.transports(url);
const message = await transport.waitFor('message', () => true); const message = await transport.waitFor('message', () => true);
transport.disconnect(); transport.disconnect();
if (schema) { 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', () => { it('should handle range on empty tree', () => {
expect(tree.range()).toEqual([]); expect(tree.range()).toEqual([]);
expect(tree.range(1, 2)).toEqual([]);
}); });
it('should handle delete on empty tree', () => { it('should handle delete on empty tree', () => {