Skip to content

Commit 5725224

Browse files
committed
docs: fix API documentation inconsistencies and improve accuracy
1 parent d0dda42 commit 5725224

7 files changed

Lines changed: 353 additions & 219 deletions

File tree

ts/docs/api/overview.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ The parser module contains streaming-aware data types and the core parser for pr
1414
- **[`Atom`](parser.md#Atom)** - Represents atomic values (numbers, booleans, null)
1515
- **[`Parser`](parser.md#Parser)** - Processes token streams and triggers callbacks
1616

17-
### Helper Classes
17+
### Schema Builder Functions
1818

19-
- **[`Field`](parser.md#Field)** - Field descriptor with validation and metadata (pydantic equivalent)
20-
- **[`ZodType`](parser.md#ZodType)** - Type hint for Zod schema specification
19+
- **[`string()`](parser.md#string)** - Create a streaming string schema
20+
- **[`array(itemSchema)`](parser.md#array)** - Create a streaming array schema
21+
- **[`object(fields)`](parser.md#object)** - Create a streaming object schema
22+
- **[`number()`](parser.md#number)** - Create a number atom schema
23+
- **[`boolean()`](parser.md#boolean)** - Create a boolean atom schema
24+
- **[`atom(zodSchema)`](parser.md#atom)** - Create a custom atom schema
25+
- **[`fromZod(zodSchema)`](parser.md#fromZod)** - Create streaming schema from Zod schema
2126

2227
### Type Aliases
2328

2429
- **`String`** - Alias for `StreamingString`
25-
- **`List<T>`** - Alias for `StreamingList<T>`
26-
- **`Atom<T>`** - Alias for `Atom<T>`
2730
- **`Object`** - Alias for `StreamingObject`
2831

2932
### Key Features
3033

3134
- **Event Callbacks**: All streaming types support `onStart`, `onAppend`, and `onComplete` callbacks
3235
- **Type Safety**: Full TypeScript generics and interfaces for compile-time checking
33-
- **Zod Integration**: Convert streaming models to Zod schemas via `toZod()` and `fromZod()`
36+
- **Zod Integration**: Convert streaming schemas to Zod schemas via `toZod()` and create from Zod schemas via `fromZod()`
3437

3538
## Tracker Module
3639

@@ -52,40 +55,33 @@ The tracker module provides change tracking capabilities for generating JSON Pat
5255
### Basic Streaming
5356

5457
```typescript
55-
import { StreamingObject, StreamingString, StreamingList, Parser } from 'langdiff';
58+
import * as ld from '@langdiff/langdiff';
5659

57-
// Define schema
58-
class Response extends StreamingObject {
59-
title!: StreamingString;
60-
items!: StreamingList<StreamingString>;
61-
62-
protected _initializeFields(): void {
63-
this.addField('title', new StreamingString());
64-
this.addField('items', new StreamingList(StreamingString));
65-
}
66-
}
60+
// Define schema using the modern functional API
61+
const Response = ld.object({
62+
title: ld.string(),
63+
items: ld.array(ld.string())
64+
});
6765

6866
// Set up callbacks
69-
const response = new Response();
67+
const response = Response.create();
7068

7169
response.title.onAppend((chunk: string) => {
7270
console.log(`Title: ${chunk}`);
7371
});
7472

7573
// Parse stream
76-
const parser = new Parser(response);
77-
parser.use((p) => {
78-
for (const token of stream) {
79-
p.push(token);
80-
}
81-
// complete() is called automatically
82-
});
74+
const parser = new ld.Parser(response);
75+
for (const chunk of streamChunks) {
76+
parser.push(chunk);
77+
}
78+
parser.complete();
8379
```
8480

8581
### Change Tracking
8682

8783
```typescript
88-
import { trackChange } from 'langdiff';
84+
import { trackChange } from '@langdiff/langdiff';
8985

9086
interface UI {
9187
items: string[];

0 commit comments

Comments
 (0)