Skip to content

Commit 5cece23

Browse files
Copilotstreamich
andcommitted
Fix main index.ts export, revert package-lock.json, convert enums to const enums, move interfaces to respective files
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
1 parent 2f73996 commit 5cece23

File tree

9 files changed

+1287
-303
lines changed

9 files changed

+1287
-303
lines changed

package-lock.json

Lines changed: 715 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export type * from './types';
2-
export * from './smile';

src/smile/SmileDecoder.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ import {
99
decodeFloat64,
1010
shouldAvoidReference,
1111
} from './util';
12-
import type {SmileDecoderOptions, SmileReader, SmileHeader} from './types';
12+
import type {IReader, IReaderResettable} from '@jsonjoy.com/util/lib/buffers';
13+
14+
export interface SmileDecoderOptions {
15+
/**
16+
* Maximum size for shared string tables.
17+
* Default: 1024
18+
*/
19+
maxSharedReferences?: number;
20+
}
21+
22+
export interface SmileHeader {
23+
version: number;
24+
sharedStringValues: boolean;
25+
sharedPropertyNames: boolean;
26+
rawBinaryEnabled: boolean;
27+
}
28+
29+
export type SmileReader = IReader & IReaderResettable;
1330

1431
export class SmileDecoder<R extends SmileReader = SmileReader> {
1532
protected reader: R;

src/smile/SmileEncoder.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ import {
1111
shouldAvoidReference,
1212
isStringShareable,
1313
} from './util';
14-
import type {SmileEncoderOptions, SmileWriter} from './types';
14+
import type {IWriter, IWriterGrowable} from '@jsonjoy.com/util/lib/buffers';
15+
16+
export interface SmileEncoderOptions {
17+
/**
18+
* Whether to enable shared string value checking during encoding.
19+
* When enabled, the encoder will track string values and create back-references
20+
* to previously seen strings to reduce output size.
21+
* Default: false
22+
*/
23+
sharedStringValues?: boolean;
24+
25+
/**
26+
* Whether to enable shared property name checking during encoding.
27+
* When enabled, the encoder will track object property names and create
28+
* back-references to previously seen names to reduce output size.
29+
* Default: true
30+
*/
31+
sharedPropertyNames?: boolean;
32+
33+
/**
34+
* Whether to allow raw binary data in the output.
35+
* When enabled, binary data can contain any byte values including reserved ones.
36+
* Default: false
37+
*/
38+
rawBinaryEnabled?: boolean;
39+
}
40+
41+
export type SmileWriter = IWriter & IWriterGrowable;
1542

1643
export class SmileEncoder<W extends SmileWriter = SmileWriter> {
1744
protected writer: W;

src/smile/constants.ts

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,132 @@
11
// Smile format constants based on specification v1.0.6
22

33
// Header constants
4-
export const HEADER = {
5-
BYTE_0: 0x3a, // ASCII ':'
6-
BYTE_1: 0x29, // ASCII ')'
7-
BYTE_2: 0x0a, // ASCII '\n'
8-
VERSION_MASK: 0xf0, // Bits 4-7 for version
9-
VERSION_CURRENT: 0x00, // Current version
10-
RESERVED_BIT: 0x08, // Bit 3 reserved
11-
RAW_BINARY_ENABLED: 0x04, // Bit 2
12-
SHARED_STRING_VALUES: 0x02, // Bit 1
13-
SHARED_PROPERTY_NAMES: 0x01, // Bit 0
14-
} as const;
4+
export const enum HEADER {
5+
BYTE_0 = 0x3a, // ASCII ':'
6+
BYTE_1 = 0x29, // ASCII ')'
7+
BYTE_2 = 0x0a, // ASCII '\n'
8+
VERSION_MASK = 0xf0, // Bits 4-7 for version
9+
VERSION_CURRENT = 0x00, // Current version
10+
RESERVED_BIT = 0x08, // Bit 3 reserved
11+
RAW_BINARY_ENABLED = 0x04, // Bit 2
12+
SHARED_STRING_VALUES = 0x02, // Bit 1
13+
SHARED_PROPERTY_NAMES = 0x01, // Bit 0
14+
}
1515

1616
// Token value ranges for value mode
17-
export const VALUE_MODE = {
17+
export const enum VALUE_MODE {
1818
// Short Shared Value String reference (0x01 - 0x1F)
19-
SHORT_SHARED_VALUE_MIN: 0x01,
20-
SHORT_SHARED_VALUE_MAX: 0x1f,
19+
SHORT_SHARED_VALUE_MIN = 0x01,
20+
SHORT_SHARED_VALUE_MAX = 0x1f,
2121

2222
// Simple literals, numbers (0x20 - 0x3F)
23-
EMPTY_STRING: 0x20,
24-
NULL: 0x21,
25-
FALSE: 0x22,
26-
TRUE: 0x23,
27-
INT_32: 0x24,
28-
INT_64: 0x25,
29-
BIG_INTEGER: 0x26,
30-
RESERVED_INT: 0x27,
31-
FLOAT_32: 0x28,
32-
FLOAT_64: 0x29,
33-
BIG_DECIMAL: 0x2a,
34-
RESERVED_FLOAT: 0x2b,
23+
EMPTY_STRING = 0x20,
24+
NULL = 0x21,
25+
FALSE = 0x22,
26+
TRUE = 0x23,
27+
INT_32 = 0x24,
28+
INT_64 = 0x25,
29+
BIG_INTEGER = 0x26,
30+
RESERVED_INT = 0x27,
31+
FLOAT_32 = 0x28,
32+
FLOAT_64 = 0x29,
33+
BIG_DECIMAL = 0x2a,
34+
RESERVED_FLOAT = 0x2b,
3535

3636
// Tiny ASCII (0x40 - 0x5F)
37-
TINY_ASCII_MIN: 0x40,
38-
TINY_ASCII_MAX: 0x5f,
37+
TINY_ASCII_MIN = 0x40,
38+
TINY_ASCII_MAX = 0x5f,
3939

4040
// Short ASCII (0x60 - 0x7F)
41-
SHORT_ASCII_MIN: 0x60,
42-
SHORT_ASCII_MAX: 0x7f,
41+
SHORT_ASCII_MIN = 0x60,
42+
SHORT_ASCII_MAX = 0x7f,
4343

4444
// Tiny Unicode (0x80 - 0x9F)
45-
TINY_UNICODE_MIN: 0x80,
46-
TINY_UNICODE_MAX: 0x9f,
45+
TINY_UNICODE_MIN = 0x80,
46+
TINY_UNICODE_MAX = 0x9f,
4747

4848
// Short Unicode (0xA0 - 0xBF)
49-
SHORT_UNICODE_MIN: 0xa0,
50-
SHORT_UNICODE_MAX: 0xbf,
49+
SHORT_UNICODE_MIN = 0xa0,
50+
SHORT_UNICODE_MAX = 0xbf,
5151

5252
// Small integers (0xC0 - 0xDF)
53-
SMALL_INT_MIN: 0xc0,
54-
SMALL_INT_MAX: 0xdf,
53+
SMALL_INT_MIN = 0xc0,
54+
SMALL_INT_MAX = 0xdf,
5555

5656
// Misc / binary / text / structure markers
57-
LONG_ASCII_TEXT: 0xe0,
58-
LONG_UNICODE_TEXT: 0xe4,
59-
BINARY_7BIT: 0xe8,
60-
SHARED_STRING_LONG: 0xec,
57+
LONG_ASCII_TEXT = 0xe0,
58+
LONG_UNICODE_TEXT = 0xe4,
59+
BINARY_7BIT = 0xe8,
60+
SHARED_STRING_LONG = 0xec,
6161

6262
// Structural markers
63-
START_ARRAY: 0xf8,
64-
END_ARRAY: 0xf9,
65-
START_OBJECT: 0xfa,
66-
END_OBJECT: 0xfb, // Only in key mode
63+
START_ARRAY = 0xf8,
64+
END_ARRAY = 0xf9,
65+
START_OBJECT = 0xfa,
66+
END_OBJECT = 0xfb, // Only in key mode
6767

6868
// Special markers
69-
END_STRING_MARKER: 0xfc,
70-
BINARY_RAW: 0xfd,
71-
RESERVED_FE: 0xfe,
72-
END_CONTENT: 0xff,
73-
} as const;
69+
END_STRING_MARKER = 0xfc,
70+
BINARY_RAW = 0xfd,
71+
RESERVED_FE = 0xfe,
72+
END_CONTENT = 0xff,
73+
}
7474

7575
// Token value ranges for key mode
76-
export const KEY_MODE = {
76+
export const enum KEY_MODE {
7777
// Empty string name
78-
EMPTY_STRING: 0x20,
78+
EMPTY_STRING = 0x20,
7979

8080
// Long shared key name reference (0x30 - 0x33)
81-
LONG_SHARED_MIN: 0x30,
82-
LONG_SHARED_MAX: 0x33,
81+
LONG_SHARED_MIN = 0x30,
82+
LONG_SHARED_MAX = 0x33,
8383

8484
// Long Unicode name
85-
LONG_UNICODE_NAME: 0x34,
85+
LONG_UNICODE_NAME = 0x34,
8686

8787
// Short shared key name reference (0x40 - 0x7F)
88-
SHORT_SHARED_MIN: 0x40,
89-
SHORT_SHARED_MAX: 0x7f,
88+
SHORT_SHARED_MIN = 0x40,
89+
SHORT_SHARED_MAX = 0x7f,
9090

9191
// Short ASCII names (0x80 - 0xBF)
92-
SHORT_ASCII_MIN: 0x80,
93-
SHORT_ASCII_MAX: 0xbf,
92+
SHORT_ASCII_MIN = 0x80,
93+
SHORT_ASCII_MAX = 0xbf,
9494

9595
// Short Unicode names (0xC0 - 0xF7)
96-
SHORT_UNICODE_MIN: 0xc0,
97-
SHORT_UNICODE_MAX: 0xf7,
96+
SHORT_UNICODE_MIN = 0xc0,
97+
SHORT_UNICODE_MAX = 0xf7,
9898

9999
// End object marker
100-
END_OBJECT: 0xfb,
101-
} as const;
100+
END_OBJECT = 0xfb,
101+
}
102102

103103
// Constants for shared string tables
104-
export const SHARED = {
105-
MAX_REFERENCES: 1024,
106-
MAX_SHORT_REFERENCE: 31, // Indices 0-30 use short references (tokens 0x01-0x1F)
107-
MIN_LONG_REFERENCE: 31, // Indices 31+ use long references
108-
MAX_STRING_LENGTH: 64, // Only strings <= 64 bytes can be shared
109-
AVOIDED_REFERENCES: [0xfe, 0xff], // These must be avoided in long references
110-
} as const;
104+
export const enum SHARED {
105+
MAX_REFERENCES = 1024,
106+
MAX_SHORT_REFERENCE = 31, // Indices 0-30 use short references (tokens 0x01-0x1F)
107+
MIN_LONG_REFERENCE = 31, // Indices 31+ use long references
108+
MAX_STRING_LENGTH = 64, // Only strings <= 64 bytes can be shared
109+
}
110+
111+
export const SHARED_AVOIDED_REFERENCES = [0xfe, 0xff]; // These must be avoided in long references
111112

112113
// Encoding constants
113-
export const ENCODING = {
114-
SMALL_INT_BIAS: 16, // Small integers are biased by 16 (-16 to +15)
115-
VINT_CONTINUATION_BIT: 0x80, // MSB set for all but last byte
116-
VINT_END_BIT: 0x80, // MSB set for last byte
117-
VINT_DATA_MASK: 0x7f, // 7 bits of data per byte
118-
SAFE_BINARY_MASK: 0x7f, // 7 bits used in safe binary encoding
119-
} as const;
114+
export const enum ENCODING {
115+
SMALL_INT_BIAS = 16, // Small integers are biased by 16 (-16 to +15)
116+
VINT_CONTINUATION_BIT = 0x80, // MSB set for all but last byte
117+
VINT_END_BIT = 0x80, // MSB set for last byte
118+
VINT_DATA_MASK = 0x7f, // 7 bits of data per byte
119+
SAFE_BINARY_MASK = 0x7f, // 7 bits used in safe binary encoding
120+
}
120121

121122
// Error messages
122-
export const ERROR = {
123-
INVALID_HEADER: 'Invalid Smile header',
124-
UNEXPECTED_END: 'Unexpected end of input',
125-
INVALID_TOKEN: 'Invalid token',
126-
INVALID_REFERENCE: 'Invalid shared string reference',
127-
UNSUPPORTED_VERSION: 'Unsupported Smile format version',
128-
MALFORMED_VINT: 'Malformed variable-length integer',
129-
STRING_TOO_LONG: 'String too long for shared reference',
130-
INVALID_FLOAT: 'Invalid floating point encoding',
131-
} as const;
123+
export const enum ERROR {
124+
INVALID_HEADER = 'Invalid Smile header',
125+
UNEXPECTED_END = 'Unexpected end of input',
126+
INVALID_TOKEN = 'Invalid token',
127+
INVALID_REFERENCE = 'Invalid shared string reference',
128+
UNSUPPORTED_VERSION = 'Unsupported Smile format version',
129+
MALFORMED_VINT = 'Malformed variable-length integer',
130+
STRING_TOO_LONG = 'String too long for shared reference',
131+
INVALID_FLOAT = 'Invalid floating point encoding',
132+
}

src/smile/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './SmileEncoder';
22
export * from './SmileDecoder';
33
export * from './constants';
4-
export * from './types';
54
export * from './util';

src/smile/types.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)