Skip to content

Commit 4309054

Browse files
committed
Update build config and dependencies for custom typings
Disable tsup auto dts generation and copy custom .d.ts files to dist. Add @ason-format/ason as dependency and update package versions.
1 parent 6f933fc commit 4309054

File tree

5 files changed

+270
-4
lines changed

5 files changed

+270
-4
lines changed

nodejs-compressor/CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.1.2] - 2024-11-11
9+
10+
### Fixed
11+
- **TypeScript Declarations**: Fixed TypeScript declaration files to only expose public API
12+
- Reduced `.d.ts` file size from ~1434 lines to 191 lines (87% reduction)
13+
- Removed internal/private methods from public type definitions
14+
- Private methods (prefixed with `_`) are no longer visible in TypeScript autocomplete
15+
- Added proper TypeScript interfaces: `SmartCompressorOptions` and `TokenComparisonStats`
16+
- Improved IDE experience for TypeScript users
17+
18+
### Changed
19+
- Modified `tsup.config.js` to use custom TypeScript declarations instead of auto-generation
20+
- Added custom `src/index.d.ts` with clean, public-only API definitions
21+
22+
## [1.1.1] - 2024-11-10
23+
24+
### Changed
25+
- Documentation improvements
26+
- Updated badges and preview images in README
27+
- Enhanced package metadata
28+
29+
## [1.1.0] - 2024-11-10
30+
31+
### Added
32+
- Initial public release
33+
- Smart compression with automatic pattern detection
34+
- Uniform array compression with schema extraction
35+
- Object aliasing for repeated structures
36+
- Inline-first value dictionary
37+
- Path flattening for nested objects
38+
- Token counter utilities
39+
- CLI tool for compression/decompression
40+
- Comprehensive documentation and examples
41+
42+
[1.1.2]: https://github.com/ason-format/ason/compare/v1.1.1...v1.1.2
43+
[1.1.1]: https://github.com/ason-format/ason/compare/v1.1.0...v1.1.1
44+
[1.1.0]: https://github.com/ason-format/ason/releases/tag/v1.1.0

nodejs-compressor/package-lock.json

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

nodejs-compressor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ason-format/ason",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "ASON (Aliased Serialization Object Notation) - Token-optimized JSON compression for LLMs. Reduces tokens by 20-60% while maintaining perfect round-trip fidelity.",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.js",
@@ -58,6 +58,7 @@
5858
"author": "ASON Project Contributors",
5959
"license": "MIT",
6060
"dependencies": {
61+
"@ason-format/ason": "^1.1.1",
6162
"@toon-format/toon": "^0.9.0"
6263
},
6364
"devDependencies": {

nodejs-compressor/src/index.d.ts

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/**
2+
* ASON - Aliased Serialization Object Notation
3+
*
4+
* A token-optimized serialization format designed specifically for LLMs,
5+
* reducing token usage by 20-60% compared to JSON while maintaining full round-trip fidelity.
6+
*
7+
* @module @ason-format/ason
8+
* @license MIT
9+
*/
10+
11+
/**
12+
* Configuration options for SmartCompressor
13+
*/
14+
export interface SmartCompressorOptions {
15+
/**
16+
* Indentation spaces (minimum 1 for parser compatibility)
17+
* @default 1
18+
*/
19+
indent?: number;
20+
21+
/**
22+
* Delimiter for CSV arrays
23+
* @default ','
24+
*/
25+
delimiter?: string;
26+
27+
/**
28+
* Enable automatic pattern detection and references
29+
* @default true
30+
*/
31+
useReferences?: boolean;
32+
33+
/**
34+
* Enable inline-first value dictionary
35+
* @default true
36+
*/
37+
useDictionary?: boolean;
38+
}
39+
40+
/**
41+
* Token comparison statistics
42+
*/
43+
export interface TokenComparisonStats {
44+
/** Original token count */
45+
original_tokens: number;
46+
47+
/** Compressed token count */
48+
compressed_tokens: number;
49+
50+
/** Reduction percentage */
51+
reduction_percent: number;
52+
53+
/** Original size in characters */
54+
original_size: number;
55+
56+
/** Compressed size in characters */
57+
compressed_size: number;
58+
}
59+
60+
/**
61+
* SmartCompressor class handles compression and decompression of JSON data to/from ASON format.
62+
*
63+
* @example
64+
* ```typescript
65+
* import { SmartCompressor } from '@ason-format/ason';
66+
*
67+
* const compressor = new SmartCompressor({ indent: 1, useReferences: true });
68+
* const data = { users: [{id: 1, name: "Alice"}] };
69+
*
70+
* // Compress
71+
* const compressed = compressor.compress(data);
72+
*
73+
* // Decompress
74+
* const original = compressor.decompress(compressed);
75+
* ```
76+
*/
77+
export class SmartCompressor {
78+
/**
79+
* Creates a new SmartCompressor instance with optional configuration.
80+
*
81+
* @param options - Configuration options
82+
*
83+
* @example
84+
* ```typescript
85+
* // Maximum compression
86+
* const compressor = new SmartCompressor({ indent: 1, useReferences: true });
87+
*
88+
* // Maximum readability
89+
* const readable = new SmartCompressor({ indent: 2, useReferences: false });
90+
* ```
91+
*/
92+
constructor(options?: SmartCompressorOptions);
93+
94+
/**
95+
* Compresses JSON data into ASON format.
96+
*
97+
* Performs a three-pass compression:
98+
* 1. Detect repeated array structures (3+ occurrences)
99+
* 2. Detect repeated objects (2+ occurrences)
100+
* 3. Detect frequent string values (2+ occurrences)
101+
*
102+
* @param data - Any JSON-serializable data
103+
* @returns ASON-formatted string
104+
*
105+
* @example
106+
* ```typescript
107+
* const data = {
108+
* users: [
109+
* {id: 1, name: "Alice", email: "alice@example.com"},
110+
* {id: 2, name: "Bob", email: "bob@example.com"}
111+
* ]
112+
* };
113+
* const compressed = compressor.compress(data);
114+
* // Output: users:[2]@id,name,email\n1,Alice,alice@example.com\n2,Bob,bob@example.com
115+
* ```
116+
*/
117+
compress(data: any): string;
118+
119+
/**
120+
* Decompresses ASON format back to original JSON structure.
121+
*
122+
* Parses the ASON format including:
123+
* - $def: section for structure/object/value definitions
124+
* - $data: section for actual data
125+
* - Uniform array notation ([N]@keys)
126+
* - Object aliases (&obj0)
127+
* - Value dictionary references (#0)
128+
* - Path flattening (a.b.c)
129+
*
130+
* @param text - ASON formatted string
131+
* @returns Original JSON data structure
132+
* @throws {Error} If parsing fails due to malformed input
133+
*
134+
* @example
135+
* ```typescript
136+
* const ason = "users:[2]@id,name\n1,Alice\n2,Bob";
137+
* const original = compressor.decompress(ason);
138+
* // Returns: {users: [{id: 1, name: "Alice"}, {id: 2, name: "Bob"}]}
139+
* ```
140+
*/
141+
decompress(text: string): any;
142+
}
143+
144+
/**
145+
* TokenCounter provides utilities for estimating and comparing token usage.
146+
*
147+
* Uses approximation (text.length / 4) for token counts.
148+
*
149+
* @example
150+
* ```typescript
151+
* import { TokenCounter } from '@ason-format/ason';
152+
*
153+
* const tokens = TokenCounter.estimateTokens("Hello world");
154+
* console.log(tokens); // 3
155+
*
156+
* const stats = TokenCounter.compareFormats(original, compressed);
157+
* console.log(`Saved ${stats.reduction_percent}% tokens`);
158+
* ```
159+
*/
160+
export class TokenCounter {
161+
/**
162+
* Estimates token count for text using approximation (text.length / 4).
163+
*
164+
* @param text - Text to count tokens for (auto-stringifies non-strings)
165+
* @returns Estimated token count
166+
*
167+
* @example
168+
* ```typescript
169+
* TokenCounter.estimateTokens("Hello world") // 3
170+
* TokenCounter.estimateTokens({key: "value"}) // 4
171+
* ```
172+
*/
173+
static estimateTokens(text: string | any): number;
174+
175+
/**
176+
* Compares token usage between original JSON and compressed ASON.
177+
*
178+
* @param original - Original data structure
179+
* @param compressed - Compressed data (ASON string or data structure)
180+
* @returns Token comparison statistics
181+
*
182+
* @example
183+
* ```typescript
184+
* const original = {users: [{id: 1}, {id: 2}]};
185+
* const compressed = compressor.compress(original);
186+
* const stats = TokenCounter.compareFormats(original, compressed);
187+
* // Returns: {original_tokens: 15, compressed_tokens: 8, reduction_percent: 46.67, ...}
188+
* ```
189+
*/
190+
static compareFormats(original: any, compressed: string | any): TokenComparisonStats;
191+
}

nodejs-compressor/tsup.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import { defineConfig } from "tsup";
2+
import { copyFileSync } from "fs";
3+
import { join } from "path";
24

35
export default defineConfig({
46
entry: ["src/index.js"],
57
format: ["esm", "cjs"],
6-
dts: true,
8+
dts: false, // Disable auto-generation, we use custom .d.ts
79
splitting: false,
810
sourcemap: false,
911
clean: true,
1012
minify: true,
1113
treeshake: true,
1214
outDir: "dist",
1315
external: ["gpt-tokenizer", "@toon-format/toon"],
16+
async onSuccess() {
17+
// Copy custom TypeScript declarations to dist
18+
copyFileSync(
19+
join(process.cwd(), "src/index.d.ts"),
20+
join(process.cwd(), "dist/index.d.ts")
21+
);
22+
copyFileSync(
23+
join(process.cwd(), "src/index.d.ts"),
24+
join(process.cwd(), "dist/index.d.cts")
25+
);
26+
console.log("✓ TypeScript declarations copied");
27+
},
1428
});

0 commit comments

Comments
 (0)