Skip to content

Commit 161b05f

Browse files
lucas-tortoraclaude
andcommitted
fix(types): improve index.d.ts accuracy
Regenerated from the corrected emitter: - Undocumented async returns are now Promise<any> instead of a fabricated Promise<void>, which wrongly asserted the method returns no value. - Internal helper classes are emitted as non-exported `declare class`, since the package only exports its main class. - README-documented members that belong to a returned sub-object (the apply host, a server/socket, a message, an extension, a codec) are no longer misattributed as methods of the main class. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b8a44a4 commit 161b05f

1 file changed

Lines changed: 31 additions & 46 deletions

File tree

index.d.ts

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class Hypercore {
321321

322322
static destroyRequests(session: any, err: any): any
323323

324-
static treeHashFromStorage(session: any, length?: any): Promise<void>
324+
static treeHashFromStorage(session: any, length?: any): Promise<any>
325325

326326
/**
327327
* Same as [`core.session(options)`](#const-session--coresessionoptions), but backed by a storage snapshot so will not truncate nor append.
@@ -340,18 +340,18 @@ export class Hypercore {
340340
* Set the encryption key.
341341
* @param opts - `opts`
342342
*/
343-
setEncryptionKey(key: any, opts?: HypercoreSetEncryptionKeyOptions): Promise<void>
343+
setEncryptionKey(key: any, opts?: HypercoreSetEncryptionKeyOptions): Promise<any>
344344

345345
/**
346346
* Set the encryption, which should satisfy the [HypercoreEncryption](https://github.com/holepunchto/hypercore-encryption) interface.
347347
*/
348-
setEncryption(encryption: any): Promise<void>
348+
setEncryption(encryption: any): Promise<any>
349349

350350
/**
351351
* Set the group `topic` that the hypercore belongs to. Useful for grouping hypercores together that need to update a larger data structure (eg. `autobee`) that is comprised of them. See `corestore`'s `store.notifyGroup(topic)` for more details.
352352
* @param topic - `topic` is a 32 byte buffer.
353353
*/
354-
setGroup(topic: any): Promise<void>
354+
setGroup(topic: any): Promise<any>
355355

356356
/**
357357
* Update the core's `keyPair`. Advanced as the `keyPair` is used throughout Hypercore, e.g. verifying blocks, identifying the core, etc.
@@ -377,7 +377,7 @@ export class Hypercore {
377377
* @param opts - `opts`
378378
* @returns Returns `null` if committing failed.
379379
*/
380-
commit(session: any, opts?: HypercoreCommitOptions): Promise<void>
380+
commit(session: any, opts?: HypercoreCommitOptions): Promise<any>
381381

382382
/**
383383
* Create a replication stream. You should pipe this to another Hypercore instance.
@@ -453,20 +453,20 @@ export class Hypercore {
453453
*/
454454
ready(): any
455455

456-
recover(): Promise<void>
456+
recover(): Promise<any>
457457

458458
/**
459459
* Set a key in the User Data key-value store.
460460
* @param key - `key` is a string and
461461
*/
462-
setUserData(key: any, value: any): Promise<void>
462+
setUserData(key: any, value: any): Promise<any>
463463

464464
/**
465465
* `key` is a string.
466466
* @param key - `key` is a string.
467467
* @returns Return the value for a key in the User Data key-value store.
468468
*/
469-
getUserData(key: any): Promise<void>
469+
getUserData(key: any): Promise<any>
470470

471471
transferSession(core: any): any
472472

@@ -479,60 +479,60 @@ export class Hypercore {
479479
* Get information about this core, such as its total size in bytes.
480480
* @param opts - `options`
481481
*/
482-
info(opts?: HypercoreInfoOptions): Promise<void>
482+
info(opts?: HypercoreInfoOptions): Promise<any>
483483

484484
/**
485485
* Waits for initial proof of the new core length until all `findingPeers` calls have finished.
486486
* @param opts - `options`
487487
*/
488-
update(opts?: HypercoreUpdateOptions): Promise<void>
488+
update(opts?: HypercoreUpdateOptions): Promise<any>
489489

490490
/**
491491
* Seek to a byte offset.
492492
* @returns Returns `[index, relativeOffset]`, where `index` is the data block the `byteOffset` is contained in and `relativeOffset` is the relative byte offset in the data block.
493493
*/
494-
seek(bytes: any, opts?: HypercoreSeekOptions): Promise<void>
494+
seek(bytes: any, opts?: HypercoreSeekOptions): Promise<any>
495495

496496
/**
497497
* Check if the core has all blocks between `start` and `end`.
498498
*/
499-
has(start: any, end?: any): Promise<void>
499+
has(start: any, end?: any): Promise<any>
500500

501501
/**
502502
* Get a block of data. If the data is not available locally this method will prioritize and wait for the data to be downloaded.
503503
* @param opts - `options`
504504
*/
505-
get(index: any, opts?: HypercoreGetOptions): Promise<void>
505+
get(index: any, opts?: HypercoreGetOptions): Promise<any>
506506

507507
/**
508508
* Clear stored blocks between `start` and `end`, reclaiming storage when possible.
509509
* @param opts - `options`
510510
*/
511-
clear(start: any, end?: any, opts?: HypercoreClearOptions): Promise<void>
511+
clear(start: any, end?: any, opts?: HypercoreClearOptions): Promise<any>
512512

513-
purge(): Promise<void>
513+
purge(): Promise<any>
514514

515515
/**
516516
* Manually mark a block or range of blocks to be retained when sweeping. Useful to mark blocks without loading them into memory. `end` is non-inclusive and defaults to `start + 1` so `core.markBlock(index)` only marks the block at `index`.
517517
* @param end - `end` is non-inclusive and defaults to
518518
*/
519-
markBlock(start: any, end?: any): Promise<void>
519+
markBlock(start: any, end?: any): Promise<any>
520520

521521
/**
522522
* Manually remove all markings. Automatically called when calling `core.startMarking()`.
523523
*/
524-
clearMarkings(): Promise<void>
524+
clearMarkings(): Promise<any>
525525

526526
/**
527527
* This enables marking mode for the "mark & sweep" approach to clear hypercore storage. When called the current markings are cleared.
528528
*/
529-
startMarking(): Promise<void>
529+
startMarking(): Promise<any>
530530

531531
/**
532532
* Clear all unmarked blocks from storage.
533533
* @param options - `opts`
534534
*/
535-
sweep(options?: HypercoreSweepOptions): Promise<void>
535+
sweep(options?: HypercoreSweepOptions): Promise<any>
536536

537537
/**
538538
* Make a read stream to read a range of data out at once.
@@ -564,43 +564,43 @@ export class Hypercore {
564564
* Truncate the core to a smaller length.
565565
* @param opts - `options`
566566
*/
567-
truncate(newLength?: any, opts?: HypercoreTruncateOptions): Promise<void>
567+
truncate(newLength?: any, opts?: HypercoreTruncateOptions): Promise<any>
568568

569569
/**
570570
* Append a block of data (or an array of blocks) to the core. Returns the new length and byte length of the core.
571571
* @param opts - `options`
572572
*/
573-
append(blocks: any, opts?: HypercoreAppendOptions): Promise<void>
573+
append(blocks: any, opts?: HypercoreAppendOptions): Promise<any>
574574

575575
/**
576576
* @returns Return a buffer which encodes the core's `key`, tree hash (`core.treeHash()`), `length`, & `fork`.
577577
*/
578-
signable(length?: any, fork?: any): Promise<void>
578+
signable(length?: any, fork?: any): Promise<any>
579579

580580
/**
581581
* Get the Merkle Tree hash of the core at a given length, defaulting to the current length of the core.
582582
*/
583-
treeHash(length?: any): Promise<void>
583+
treeHash(length?: any): Promise<any>
584584

585-
missingNodes(index: any): Promise<void>
585+
missingNodes(index: any): Promise<any>
586586

587587
/**
588588
* Generate a proof (a `TreeProof` instance) for the request `opts`.
589589
* @param opts - `opts`
590590
*/
591-
proof(opts: HypercoreProofOptions): Promise<void>
591+
proof(opts: HypercoreProofOptions): Promise<any>
592592

593-
applyProof(proof: any, from: any): Promise<void>
593+
applyProof(proof: any, from: any): Promise<any>
594594

595595
/**
596596
* Note that you cannot seek & provide a block / hash request when upgrading.
597597
* @returns Return the merkle tree batch from the proof.
598598
*/
599-
verifyFullyRemote(proof: any): Promise<void>
599+
verifyFullyRemote(proof: any): Promise<any>
600600

601601
generateRemoteProofForTreeNode(treeNodeIndex: any): any
602602

603-
recoverFromRemoteProof(remoteProof: any): Promise<void>
603+
recoverFromRemoteProof(remoteProof: any): Promise<any>
604604

605605
recoverTreeNodeFromPeers(): any
606606

@@ -671,21 +671,6 @@ export class Hypercore {
671671

672672
waits: any
673673

674-
/**
675-
* Sends the `message` to a specific `peer`.
676-
*/
677-
send(message: any, peer: any): any
678-
679-
/**
680-
* Sends the `message` to all peers.
681-
*/
682-
broadcast(message: any): any
683-
684-
/**
685-
* Unregister and remove extension from the hypercore.
686-
*/
687-
destroy(): any
688-
689674
/**
690675
* Emitted when the core has been fully closed.
691676
*/
@@ -725,7 +710,7 @@ export class Hypercore {
725710
on(event: 'remote-contiguous-length', listener: (...args: any[]) => void): this
726711
}
727712

728-
export class ReadStream {
713+
declare class ReadStream {
729714
constructor(core: any, opts?: any)
730715

731716
push(data: any): any
@@ -757,7 +742,7 @@ export class ReadStream {
757742
on(event: 'error', listener: () => void): this
758743
}
759744

760-
export class WriteStream {
745+
declare class WriteStream {
761746
constructor(core: any)
762747

763748
write(data: any): any
@@ -778,7 +763,7 @@ export class WriteStream {
778763
on(event: 'error', listener: () => void): this
779764
}
780765

781-
export class ByteStream {
766+
declare class ByteStream {
782767
constructor(core: any, opts?: any)
783768

784769
push(data: any): any

0 commit comments

Comments
 (0)