Replace hand-written .d.ts with JSDoc + tsc auto-generation

- Delete hand-written index.d.ts that drifted from source
- Add JSDoc type annotations to all source files
- Create src/types.js with shared typedefs (SelfInfo, Contact,
  ContactMessage, ChannelInfo, RepeaterStats, etc.)
- Add tsconfig.json for declaration generation
- Add build:types script and prepublishOnly hook
- Add GitHub Actions CI workflow for type checking
- Use Uint8Array everywhere (no Buffer references)
- Add semantic type aliases (EpochSeconds, Milliseconds, MilliVolts)
- Add typed event overloads on Connection (on/once/off)
- All 11 PR #15 review comments addressed
This commit is contained in:
Manuel Bahamóndez-Honores 2026-02-18 05:49:46 -03:00
parent de31939a28
commit 2d4cb35e51
23 changed files with 988 additions and 212 deletions

View file

@ -1,6 +1,8 @@
import BufferReader from "./buffer_reader.js";
import BufferWriter from "./buffer_writer.js";
/** @typedef {import("./types.js").AdvertParsedData} AdvertParsedData */
class Advert {
static ADV_TYPE_NONE = 0;
@ -13,14 +15,25 @@ class Advert {
static ADV_FEAT2_MASK = 0x40;
static ADV_NAME_MASK = 0x80;
/**
* @param {Uint8Array} publicKey
* @param {number} timestamp
* @param {Uint8Array} signature
* @param {Uint8Array} appData
*/
constructor(publicKey, timestamp, signature, appData) {
this.publicKey = publicKey;
this.timestamp = timestamp;
this.signature = signature;
this.appData = appData;
/** @type {AdvertParsedData} */
this.parsed = this.parseAppData();
}
/**
* @param {Uint8Array} bytes
* @returns {Advert}
*/
static fromBytes(bytes) {
// read bytes
@ -34,15 +47,18 @@ class Advert {
}
/** @returns {number} */
getFlags() {
return this.appData[0];
}
/** @returns {number} */
getType() {
const flags = this.getFlags();
return flags & 0x0F;
}
/** @returns {string | null} */
getTypeString() {
const type = this.getType();
if(type === Advert.ADV_TYPE_NONE) return "NONE";
@ -52,6 +68,7 @@ class Advert {
return null;
}
/** @returns {Promise<boolean>} */
async isVerified() {
const { ed25519 } = await import("@noble/curves/ed25519");
@ -67,6 +84,7 @@ class Advert {
}
/** @returns {AdvertParsedData} */
parseAppData() {
// read app data