Skip to content

Commit 99f881a

Browse files
authored
docs: add migration guide for v1 to v2 (#104)
1 parent 2657d71 commit 99f881a

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ const dataGraph = new SimilarityGraph<DataItem>(dataList, (dataItem) => dataItem
5252
## Documentation
5353

5454
- [SimilarityGraph](./docs/similarity-graph.doc.md)
55+
- [Migration Guide: v1 to v2](./docs/migration-guide-v1-to-v2.md)

docs/migration-guide-v1-to-v2.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Migration Guide: v1 to v2
2+
3+
This guide will help you migrate your code from `@kasnix/structured-objects` v1 to v2.
4+
5+
## Requirements
6+
7+
### Node.js Version
8+
9+
The minimum Node.js version has been updated from 20.8.1 to 22.12.0. To ensure the library continues to work correctly, make sure you are using Node.js version 22.12.0 or higher.
10+
11+
To check your version, use the following command:
12+
13+
```bash
14+
node --version
15+
```
16+
17+
## Replacements
18+
19+
### ObjectGraph → SimilarityGraph
20+
21+
The `ObjectGraph` class has been renamed to `SimilarityGraph` to better reflect its purpose and functionality.
22+
23+
```typescript
24+
// v1
25+
const graph = new ObjectGraph(nodeValues, keyExtractor);
26+
27+
// v2
28+
const graph = new SimilarityGraph(nodeValues, keyExtractor);
29+
```
30+
31+
As a consequence of the class name change, the import subpath has also changed. Additionally, duplicate import paths (original and simplified) have been removed in favor of a single subpath.
32+
33+
```typescript
34+
// v1
35+
import { ObjectGraph } from "@kasnix/structured-objects/object-graph"; // Original
36+
import { ObjectGraph } from "@kasnix/structured-objects/graph"; // Simplified
37+
38+
// v2
39+
import { SimilarityGraph } from "@kasnix/structured-objects/similarity-graph";
40+
```
41+
42+
## Removals
43+
44+
### `length` Property
45+
46+
The deprecated `length` property has been removed. Use the `size` property instead.
47+
48+
```typescript
49+
// v1
50+
const nodeCount = graph.length; // Deprecated but still worked
51+
52+
// v2
53+
const nodeCount = graph.size; // Use this instead
54+
```
55+
56+
This change affects test matchers that rely on the `length` property, such as `.toHaveLength()` in Jest and Vitest.
57+
58+
```typescript
59+
// v1
60+
expect(graph).toHaveLength(5);
61+
62+
// v2
63+
expect(graph.size).toBe(5);
64+
```
65+
66+
## Migration Checklist
67+
68+
- [ ] Update Node.js to version 22.12.0 or higher
69+
- [ ] Replace all references to `ObjectGraph` class with `SimilarityGraph`
70+
- [ ] Update import subpaths from `/graph` or `/object-graph` to `/similarity-graph`
71+
- [ ] Replace all uses of `.length` with `.size`
72+
- [ ] Update test assertions from `expect(graph).toHaveLength(n)` to `expect(graph.size).toBe(n)`

0 commit comments

Comments
 (0)