Skip to content

Commit e20a14b

Browse files
committed
feat: improve diff values typing
1 parent 5f7d6c4 commit e20a14b

10 files changed

Lines changed: 4205 additions & 3012 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export default [
77
{ settings: { react: { version: "detect" } } },
88
pluginJs.configs.recommended,
99
...tseslint.configs.recommended,
10+
{ rules: { "preserve-caught-error": "off" } },
1011
];

jest.setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { TextEncoder, TextDecoder } from "util";
22

3-
//@ts-expect-error - the TextEncoder is valid
43
global.TextEncoder = TextEncoder;
5-
//@ts-expect-error - the TextDecoder is valid
64
global.TextDecoder = TextDecoder;

package-lock.json

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

package.json

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@donedeal0/superdiff",
3-
"version": "4.2.2",
3+
"version": "4.2.3",
44
"type": "module",
55
"description": "Superdiff provides a rich and readable diff for arrays, objects, texts and coordinates. It supports stream and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a top-tier performance.",
66
"main": "dist/index.js",
@@ -45,42 +45,42 @@
4545
]
4646
]
4747
},
48-
"keywords": [
49-
"array-comparison",
50-
"array-diff",
51-
"chunks",
52-
"code-diff",
53-
"compare",
54-
"comparison-tool",
55-
"coordinates",
56-
"data-diff",
57-
"deep-comparison",
58-
"deep-diff",
59-
"deep-object-diff",
60-
"diff",
61-
"file-diff",
62-
"geo-diff",
63-
"geo-distance",
64-
"haversine",
65-
"isequal",
66-
"json-diff",
67-
"json",
68-
"lat-long",
69-
"lcs",
70-
"list-diff",
71-
"object-comparison",
72-
"object-diff",
73-
"object-difference",
74-
"object",
75-
"stream-diff",
76-
"streaming-diff",
77-
"streaming",
78-
"string-diff",
79-
"text-diff",
80-
"textdiff",
81-
"vincenty",
82-
"word-diff"
83-
],
48+
"keywords": [
49+
"array-comparison",
50+
"array-diff",
51+
"chunks",
52+
"code-diff",
53+
"compare",
54+
"comparison-tool",
55+
"coordinates",
56+
"data-diff",
57+
"deep-comparison",
58+
"deep-diff",
59+
"deep-object-diff",
60+
"diff",
61+
"file-diff",
62+
"geo-diff",
63+
"geo-distance",
64+
"haversine",
65+
"isequal",
66+
"json-diff",
67+
"json",
68+
"lat-long",
69+
"lcs",
70+
"list-diff",
71+
"object-comparison",
72+
"object-diff",
73+
"object-difference",
74+
"object",
75+
"stream-diff",
76+
"streaming-diff",
77+
"streaming",
78+
"string-diff",
79+
"text-diff",
80+
"textdiff",
81+
"vincenty",
82+
"word-diff"
83+
],
8484
"scripts": {
8585
"benchmark": "tsx benchmark/index.ts",
8686
"build": "tsup",
@@ -93,32 +93,33 @@
9393
"tsc": "tsc --noEmit --incremental"
9494
},
9595
"devDependencies": {
96-
"@eslint/js": "^9.39.2",
96+
"@eslint/js": "^10.0.1",
9797
"@semantic-release/exec": "^7.1.0",
9898
"@semantic-release/git": "^10.0.1",
99-
"@swc/core": "^1.15.8",
99+
"@swc/core": "^1.15.40",
100100
"@swc/jest": "^0.2.39",
101101
"@types/arr-diff": "^4.0.3",
102102
"@types/deep-diff": "^1.0.5",
103-
"@types/jest": "^29.5.14",
103+
"@types/jest": "^30.0.0",
104+
"@types/node": "^25.9.1",
104105
"arr-diff": "^4.0.0",
105106
"blob-polyfill": "^9.0.20240710",
106107
"deep-diff": "^1.0.2",
107108
"deep-object-diff": "^1.1.9",
108109
"diff": "^8.0.2",
109-
"eslint": "^9.21.0",
110+
"eslint": "^10.4.0",
110111
"husky": "^9.1.7",
111-
"jest": "^29.7.0",
112-
"jest-environment-jsdom": "^29.7.0",
113-
"jsdom": "^26.0.0",
112+
"jest": "^30.4.2",
113+
"jest-environment-jsdom": "^30.4.1",
114+
"jsdom": "^29.1.1",
114115
"microdiff": "^1.5.0",
115-
"prettier": "^3.5.2",
116-
"swc-loader": "^0.2.6",
116+
"prettier": "^3.8.3",
117+
"swc-loader": "^0.2.7",
117118
"ts-node": "^10.9.2",
118119
"tsup": "^8.5.1",
119-
"tsx": "^4.21.0",
120-
"typescript": "^5.9.3",
121-
"typescript-eslint": "^8.52.0",
122-
"web-streams-polyfill": "^4.2.0"
120+
"tsx": "^4.22.3",
121+
"typescript": "^6.0.3",
122+
"typescript-eslint": "^8.60.0",
123+
"web-streams-polyfill": "^4.3.0"
123124
}
124125
}

src/lib/list-diff/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function getDiffStatus(statusMap: Set<ListStatus>): ListStatus {
1919
return ListStatus.UPDATED;
2020
}
2121

22-
function getLeanDiff(
23-
diff: ListDiff["diff"],
22+
function getLeanDiff<T>(
23+
diff: ListDiff<T>["diff"],
2424
showOnly: ListDiffOptions["showOnly"] = [],
25-
): ListDiff["diff"] {
25+
): ListDiff<T>["diff"] {
2626
const set = new Set(showOnly);
27-
const leanDiff: ListDiff["diff"] = [];
27+
const leanDiff: ListDiff<T>["diff"] = [];
2828
for (let i = 0; i < diff.length; i++) {
2929
if (set.has(diff[i].status)) {
3030
leanDiff.push(diff[i]);
@@ -37,8 +37,8 @@ function formatSingleListDiff<T>(
3737
listData: T[],
3838
status: ListStatus,
3939
options: ListDiffOptions,
40-
): ListDiff {
41-
const diff: ListDiff["diff"] = new Array(listData.length);
40+
): ListDiff<T> {
41+
const diff: ListDiff<T>["diff"] = new Array(listData.length);
4242
const isAdded = status === ListStatus.ADDED;
4343
for (let i = 0; i < listData.length; i++) {
4444
diff[i] = {
@@ -89,7 +89,7 @@ export const getListDiff = <T>(
8989
prevList: T[] | undefined | null,
9090
nextList: T[] | undefined | null,
9191
options: ListDiffOptions = DEFAULT_LIST_DIFF_OPTIONS,
92-
): ListDiff => {
92+
): ListDiff<T> => {
9393
if (!prevList && !nextList) {
9494
return { type: "list", status: ListStatus.EQUAL, diff: [] };
9595
}
@@ -100,7 +100,7 @@ export const getListDiff = <T>(
100100
return formatSingleListDiff(prevList as T[], ListStatus.DELETED, options);
101101
}
102102

103-
const diff: ListDiff["diff"] = [];
103+
const diff: ListDiff<T>["diff"] = [];
104104
const previousMap = new Map<string, ListData<T>>();
105105
const statusMap = new Set<ListStatus>();
106106
const { referenceKey, ignoreArrayOrder } = options;

src/lib/stream-list-diff/client/stream-list-diff-client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* @jest-environment jsdom
33
*/
44
import "blob-polyfill";
5-
import { ReadableStream } from "web-streams-polyfill";
5+
import { ReadableStream as ReadableStreamPolyfill } from "web-streams-polyfill";
66
import prevListFile from "@mocks/prevList.json";
77
import nextListFile from "@mocks/nextList.json";
88
import { ListStatus } from "@models/list";
99
import { StreamListDiff } from "@models/stream";
1010
import { streamListDiff } from ".";
1111

1212
// @ts-expect-error - the ReadableStream polyfill is necessary to test ReadableStream in a Node environment.
13-
global.ReadableStream = ReadableStream;
13+
global.ReadableStream = ReadableStreamPolyfill;
1414

1515
describe("data emission", () => {
1616
it("emits 'data' event and consider the all the nextList added if no prevList is provided", (done) => {

src/lib/stream-list-diff/client/stream-list-diff-client.worker.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* @jest-environment jsdom
33
*/
44
import "blob-polyfill";
5-
import "jsdom";
6-
import { ReadableStream } from "web-streams-polyfill";
5+
import { ReadableStream as ReadableStreamPolyfill } from "web-streams-polyfill";
76
import prevListFile from "@mocks/prevList.json";
87
import nextListFile from "@mocks/nextList.json";
98
import { ListStatus } from "@models/list";
@@ -55,7 +54,7 @@ class Worker {
5554
// @ts-expect-error - a Worker polyfill is necessary to test a Web Worker in a Node environment.
5655
global.Worker = Worker;
5756
// @ts-expect-error - the ReadableStream polyfill is necessary to test ReadableStream in a Node environment.
58-
global.ReadableStream = ReadableStream;
57+
global.ReadableStream = ReadableStreamPolyfill;
5958

6059
describe("data emission", () => {
6160
it("emits 'data' event and consider the all the nextList added if no prevList is provided", (done) => {

src/lib/stream-list-diff/server/worker/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function generateWorker<T extends Record<string, unknown>>(
5454
worker.terminate();
5555
}
5656
});
57-
worker.on(WorkerEvent.Error, (err) =>
57+
worker.on(WorkerEvent.Error, (err: Error) =>
5858
emitter.emit(StreamEvent.Error, new Error(err.message)),
5959
);
6060
} catch (err) {

src/models/list/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export type ListData<T> = {
3030
value: T;
3131
};
3232

33-
export type ListDiff = {
33+
export type ListDiff<T = unknown> = {
3434
type: "list";
3535
status: `${ListStatus}`;
3636
diff: {
37-
value: unknown;
37+
value: T;
3838
previousIndex: number | null;
3939
index: number | null;
4040
status: `${ListStatus}`;

tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"exclude": ["node_modules", "dist"],
3-
"include": ["src"],
3+
"include": ["src", "jest.setup.ts"],
44
"compilerOptions": {
5+
"rootDir": ".",
56
"declaration": true,
67
"declarationDir": "./dist",
78
"lib": ["esnext", "dom"],
9+
"types": ["jest", "node"],
810
"module": "esnext",
911
"target": "esnext",
10-
"moduleResolution": "node",
12+
"moduleResolution": "bundler",
1113
"noUnusedParameters": true,
1214
"esModuleInterop": true,
1315
"noImplicitAny": true,
@@ -16,7 +18,6 @@
1618
"resolveJsonModule": true,
1719
"allowSyntheticDefaultImports": true,
1820
"skipLibCheck": true ,
19-
"baseUrl": ".",
2021
"paths": {
2122
"@lib/*": ["./src/lib/*"],
2223
"@mocks/*": ["./src/mocks/*"],

0 commit comments

Comments
 (0)