Skip to content

Commit 2435d10

Browse files
authored
fix: export option types (#137)
To enable reuse of the types, export them from the index file. Also removes some unused types that were not exposed publicly.
1 parent 4af409e commit 2435d10

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

src/decode.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,10 @@ import { Uint8ArrayList } from 'uint8arraylist'
55
import { MAX_DATA_LENGTH, MAX_LENGTH_LENGTH } from './constants.js'
66
import { InvalidDataLengthError, InvalidDataLengthLengthError, InvalidMessageLengthError, UnexpectedEOFError } from './errors.js'
77
import { isAsyncIterable } from './utils.js'
8-
import type { LengthDecoderFunction } from './index.js'
8+
import type { DecoderOptions, LengthDecoderFunction } from './index.js'
99
import type { Reader } from 'it-reader'
1010
import type { Source } from 'it-stream-types'
1111

12-
export interface ReadState {
13-
dataLength: number
14-
}
15-
16-
export interface DecoderOptions {
17-
lengthDecoder?: LengthDecoderFunction
18-
onData?(data: Uint8ArrayList): void
19-
onLength?(length: number): void
20-
maxLengthLength?: number
21-
maxDataLength?: number
22-
}
23-
24-
export interface ReadResult {
25-
mode: string
26-
chunk?: Uint8ArrayList
27-
buffer: Uint8ArrayList
28-
state?: ReadState
29-
data?: Uint8ArrayList
30-
}
31-
3212
enum ReadMode {
3313
LENGTH,
3414
DATA

src/encode.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ import { allocUnsafe } from 'uint8arrays/alloc'
44
import { MAX_DATA_LENGTH } from './constants.js'
55
import { InvalidDataLengthError } from './errors.js'
66
import { isAsyncIterable } from './utils.js'
7-
import type { LengthEncoderFunction } from './index.js'
7+
import type { EncoderOptions, LengthEncoderFunction } from './index.js'
88
import type { Source } from 'it-stream-types'
99

10-
interface EncoderOptions {
11-
lengthEncoder?: LengthEncoderFunction
12-
maxDataLength?: number
13-
}
14-
1510
// Helper function to validate the chunk size against maxDataLength
1611
function validateMaxDataLength (chunk: Uint8Array | Uint8ArrayList, maxDataLength: number): void {
1712
if (chunk.byteLength > maxDataLength) {

src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,24 @@ import type { Uint8ArrayList } from 'uint8arraylist'
4848
export { encode } from './encode.js'
4949
export { decode } from './decode.js'
5050

51+
export interface DecoderOptions {
52+
lengthDecoder?: LengthDecoderFunction
53+
onData?(data: Uint8ArrayList): void
54+
onLength?(length: number): void
55+
maxLengthLength?: number
56+
maxDataLength?: number
57+
}
58+
5159
export interface LengthDecoderFunction {
5260
(data: Uint8ArrayList): number
5361
bytes: number
5462
}
5563

64+
export interface EncoderOptions {
65+
lengthEncoder?: LengthEncoderFunction
66+
maxDataLength?: number
67+
}
68+
5669
export interface LengthEncoderFunction {
5770
(value: number): Uint8ArrayList | Uint8Array
5871
bytes: number

0 commit comments

Comments
 (0)