Skip to content

Commit 530c350

Browse files
lucas-tortoraclaude
andcommitted
fix(types): restore return types and model returned sub-objects
Regenerated from the improved emitter: - Methods that return a known object are typed as that object instead of `any` (verified against source) — sessions/checkouts/batches return their own class, stream factories return their stream class, etc. - Objects the README documents under their own receiver (a server, socket, message, extension, or the autobase apply `host`) are now modeled as helper classes and wired to the method/callback that produces them, instead of being dropped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 161b05f commit 530c350

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

index.d.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ export class Hypercore {
326326
/**
327327
* Same as [`core.session(options)`](#const-session--coresessionoptions), but backed by a storage snapshot so will not truncate nor append.
328328
*/
329-
snapshot(opts?: any): any
329+
snapshot(opts?: any): Hypercore
330330

331331
compact(): any
332332

333333
/**
334334
* Creates a new Hypercore instance that shares the same underlying core.
335335
* @param opts - Options are inherited from the parent instance, unless they are re-set.
336336
*/
337-
session(opts?: HypercoreSessionOptions): any
337+
session(opts?: HypercoreSessionOptions): Hypercore
338338

339339
/**
340340
* Set the encryption key.
@@ -538,18 +538,18 @@ export class Hypercore {
538538
* Make a read stream to read a range of data out at once.
539539
* @param opts - `options`
540540
*/
541-
createReadStream(opts?: HypercoreCreateReadStreamOptions): any
541+
createReadStream(opts?: HypercoreCreateReadStreamOptions): ReadStream
542542

543543
/**
544544
* Make a write stream to append chunks as blocks.
545545
*/
546-
createWriteStream(): any
546+
createWriteStream(): WriteStream
547547

548548
/**
549549
* Make a byte stream to read a range of bytes.
550550
* @param opts - `options`
551551
*/
552-
createByteStream(opts?: HypercoreCreateByteStreamOptions): any
552+
createByteStream(opts?: HypercoreCreateByteStreamOptions): ByteStream
553553

554554
/**
555555
* Download a range of data.
@@ -608,7 +608,7 @@ export class Hypercore {
608608
* Register a custom protocol extension. This is a legacy implementation and is no longer recommended. Creating a [`Protomux`](https://github.com/holepunchto/protomux) protocol is recommended instead.
609609
* @param handlers - `handlers`
610610
*/
611-
registerExtension(name: any, handlers?: HypercoreRegisterExtensionOptions): any
611+
registerExtension(name: any, handlers?: HypercoreRegisterExtensionOptions): Extension
612612

613613
emit(event: any, arg1?: any): any
614614

@@ -781,4 +781,21 @@ declare class ByteStream {
781781
on(event: 'error', listener: () => void): this
782782
}
783783

784+
declare class Extension {
785+
/**
786+
* Sends the `message` to a specific `peer`.
787+
*/
788+
send(message: any, peer: any): any
789+
790+
/**
791+
* Sends the `message` to all peers.
792+
*/
793+
broadcast(message: any): any
794+
795+
/**
796+
* Unregister and remove extension from the hypercore.
797+
*/
798+
destroy(): any
799+
}
800+
784801
export default Hypercore

0 commit comments

Comments
 (0)