export interface ITypedRequest { /** * Transport-generated identity for one exact request attempt. Transports use * it with the method and correlation ID to reject stale responses and route * cancellation without confusing retries. */ requestInstanceId?: string; /** * the method that the request response data is meant for */ method: string; /** * any needed auth data */ authInfo?: { jwt: string; }; /** * localData tracks things within typedrequest. * needed for VirtualStreams */ localData?: { firstTypedrouter?: any; }; /** * server data that is added for dealing with the request server side. Will be omitted when sending the response */ serverData?: { jwtData: any; jwtValid: boolean; }; /** * the request data */ request: object; /** * the response data */ response: object; /** * any error information that might be encountered while dealing with a request */ error?: { text: string; data: any; }; /** * retry information for smartly advising the client to retry at a later point in time */ retry?: { waitForMs: number; reason: string; }; /** * a correlation id that * used for matching request and response * !important. Don't remove. */ correlation?: { id: string; phase: 'request' | 'response'; }; } export type implementsTR = {}; export interface ITypedEvent { name: string; uniqueEventId: string; payload: T; } export interface ITag { name: string; payload: any; } export type implementsTag = {}; /** JSON-compatible data interpreted exclusively by the stream transport. */ export type TVirtualStreamTransportDescriptorPayload = null | boolean | number | string | readonly TVirtualStreamTransportDescriptorPayload[] | { readonly [key: string]: TVirtualStreamTransportDescriptorPayload; }; export type TVirtualStreamDirection = 'send' | 'receive'; export type TOppositeVirtualStreamDirection = TDirection extends 'send' ? 'receive' : 'send'; /** Optional whole-stream integrity contract for a finite stream. */ export interface IVirtualStreamIntegrity { readonly algorithm: 'sha256'; /** Non-negative safe integer. */ readonly byteLength: number; /** `sha256:` followed by exactly 64 lowercase hexadecimal characters. */ readonly digest: string; } /** Resolves identically on both peers only after receiver acceptance. */ export interface IVirtualStreamReceipt { readonly streamId: string; /** Non-negative safe integer. */ readonly chunkCount: number; /** Non-negative safe integer. */ readonly byteLength: number; readonly accepted: true; /** Exact declared integrity when verified, otherwise `null`. */ readonly verifiedIntegrity: IVirtualStreamIntegrity | null; } /** * Serializable stream descriptor. `creatorDirection` is local to the peer that * created the descriptor; its consumer always receives the opposite direction. */ export interface IVirtualStreamDescriptor { readonly _isVirtualStream: true; readonly protocol: 'virtual-stream-v1'; readonly streamId: string; readonly creatorDirection: TCreatorDirection; readonly contentType?: string; readonly integrity?: IVirtualStreamIntegrity; readonly transport: TVirtualStreamTransportDescriptorPayload; } interface IVirtualStreamBase { readonly protocol: 'virtual-stream-v1'; /** Direction local to the facade owner. */ readonly direction: TDirection; readonly streamId: string; readonly contentType?: string; readonly integrity?: IVirtualStreamIntegrity; /** Rejects if the exact endpoint cannot be established. */ readonly opened: Promise; /** Resolves only after receiver acceptance; every other outcome rejects. */ readonly completion: Promise; /** * Always resolves after transport-owned resources have been released within * the transport's bounded terminal-cleanup deadline. */ readonly closed: Promise; /** Immediate abnormal cancellation. Repeated aborts are idempotent. */ abort(reasonArg?: unknown): Promise; } export interface IVirtualStreamSender extends IVirtualStreamBase<'send'> { /** * Sends one logical chunk. The implementation snapshots bytes at admission, * uses bounded admission queues, preserves order and boundaries, and resolves * after receiver dequeue. */ send(chunkArg: Uint8Array): Promise; /** Writes share the same ordered admission queue as `send()`. */ readonly writable: WritableStream; /** Flushes admitted chunks and resolves with the accepted receipt. */ close(): Promise; } export interface IVirtualStreamReceiver extends IVirtualStreamBase<'receive'> { /** Returns one complete logical chunk, or `undefined` after graceful EOF. */ receive(): Promise; /** * Readable pulls preserve logical chunk boundaries. Direct `receive()` and * readable consumption are mutually exclusive for one endpoint. */ readonly readable: ReadableStream; /** Accepts a fully drained EOF and resolves with the shared receipt. */ accept(): Promise; /** Peer-visible application refusal. Repeated rejects are idempotent. */ reject(reasonArg?: unknown): Promise; } /** Direction is explicit and is requester-local when used in a shared DTO. */ export type TVirtualStream = TDirection extends 'send' ? IVirtualStreamSender : IVirtualStreamReceiver; export type TVirtualStreamTransportEndpoint = TVirtualStream; /** * Silent local registration owned by the facade after binding. `dispose()` is * synchronous, idempotent, performs no transport I/O, and is called after * `closed` or any activation/serialization rollback. */ export interface IVirtualStreamTransportRegistration { readonly descriptor: IVirtualStreamDescriptor; readonly endpoint: TVirtualStreamTransportEndpoint; readonly dispose: () => void; } export interface IVirtualStreamOpenOptions { /** Aborts staging and requires the transport promise to settle promptly. */ readonly abortSignal: AbortSignal; /** Remaining positive safe-integer staging budget in milliseconds. */ readonly timeoutMs: number; } /** Exact stream boundary supplied by a transport such as TypedSocket. */ export interface IVirtualStreamTransport { /** * Returns a staged opposite-direction endpoint after the complete parent * payload is validated. The descriptor consumer alone initiates physical * opening after TypedRequest authorizes application use. The transport must * observe `abortSignal` and settle this promise promptly when it aborts. */ openVirtualStream(descriptorArg: IVirtualStreamDescriptor, optionsArg: IVirtualStreamOpenOptions): Promise>>; } export {};