Skip to content

Commit

Permalink
Add TypeScript typings (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassernasc authored Feb 3, 2025
1 parent 5a22c34 commit 43625f2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Duplex, DuplexEvents } from 'bare-stream'
import constants from './lib/constants'
import TLSError from './lib/errors'

export { constants, TLSError as errors }

export interface TLSSocketEvents extends DuplexEvents {
connect: []
}

export interface TLSSocketOptions {
allowHalfOpen?: boolean
cert?: ArrayBufferView
eagerOpen?: boolean
host?: string
isServer?: boolean
key?: ArrayBufferView
}

export interface TLSSocket<M extends TLSSocketEvents> extends Duplex<M> {
readonly socket: Duplex
readonly encrypted: true
}

export class TLSSocket<M extends TLSSocketEvents> extends Duplex<M> {
constructor(socket: Duplex, opts?: TLSSocketOptions)
}

export { TLSSocket as Socket }
3 changes: 3 additions & 0 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const constants: { state: { HANDSHAKE: number } }

export = constants
5 changes: 5 additions & 0 deletions lib/errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare class TLSError extends Error {
static from(err: Error): TLSError
}

export = TLSError
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
"version": "2.0.0",
"description": "Transport Layer Security (TLS) streams for JavaScript",
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package": "./package.json",
"./constants": "./lib/constants.js",
"./errors": "./lib/errors.js"
"./constants": {
"types": "./lib/constants.d.ts",
"default": "./lib/constants.js"
},
"./errors": {
"types": "./lib/errors.d.ts",
"default": "./lib/errors.js"
}
},
"files": [
"index.js",
"index.d.ts",
"binding.c",
"binding.js",
"CMakeLists.txt",
Expand All @@ -34,7 +44,7 @@
"bare": ">=1.7.0"
},
"dependencies": {
"bare-stream": "^2.0.0"
"bare-stream": "^2.6.4"
},
"devDependencies": {
"bare-fs": "^3.0.0",
Expand Down

0 comments on commit 43625f2

Please sign in to comment.