json-as 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +1 -1
- package/assembly/__benches__/large.bench.ts +22 -19
- package/assembly/__tests__/generics.spec.ts +40 -0
- package/assembly/__tests__/lib/index.ts +3 -7
- package/assembly/__tests__/types.spec.ts +26 -0
- package/bench/large.bench.ts +104 -215
- package/package.json +2 -3
- package/run-bench.js.sh +1 -1
- package/transform/lib/index.js +70 -80
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/alias.js +49 -0
- package/transform/lib/linkers/alias.js.map +1 -0
- package/transform/lib/{linker.js → linkers/classes.js} +3 -17
- package/transform/lib/linkers/classes.js.map +1 -0
- package/transform/lib/linkers/custom.js +32 -0
- package/transform/lib/linkers/custom.js.map +1 -0
- package/transform/lib/linkers/imports.js +17 -0
- package/transform/lib/linkers/imports.js.map +1 -0
- package/transform/lib/types.js +13 -0
- package/transform/lib/types.js.map +1 -1
- package/transform/src/index.ts +67 -82
- package/transform/src/linkers/alias.ts +59 -0
- package/transform/src/{linker.ts → linkers/classes.ts} +3 -23
- package/transform/src/linkers/custom.ts +32 -0
- package/transform/src/linkers/imports.ts +22 -0
- package/transform/src/types.ts +15 -1
- package/transform/tsconfig.json +1 -1
- package/bench/lib/test.ts +0 -37
- package/transform/lib/linker.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2025-05-29 - 1.1.2
|
|
4
|
+
|
|
5
|
+
- fix: add helpful warning on unknown or unaccessible types in fields
|
|
6
|
+
- feat: support deserialization of class generics
|
|
7
|
+
- fix: add support for numerical generics
|
|
8
|
+
- tests: add proper testing for generics
|
|
9
|
+
- feat: support type aliases with a custom type resolver/linker
|
|
10
|
+
- chore: add other linkers to tsconfig and clean up
|
|
11
|
+
- feat: add type alias resolving
|
|
12
|
+
|
|
3
13
|
## 2025-05-28 - 1.1.11
|
|
4
14
|
|
|
5
15
|
- fix: class resolving should only search top level statements for class declarations
|
package/README.md
CHANGED
|
@@ -2,10 +2,11 @@ import { JSON } from "..";
|
|
|
2
2
|
import { expect } from "../__tests__/lib";
|
|
3
3
|
import { bench } from "./lib/bench";
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
@json
|
|
6
7
|
class RepoOwner {
|
|
7
8
|
public login!: string;
|
|
8
|
-
public id!:
|
|
9
|
+
public id!: i32;
|
|
9
10
|
public node_id!: string;
|
|
10
11
|
public avatar_url!: string;
|
|
11
12
|
public gravatar_id!: string;
|
|
@@ -25,6 +26,7 @@ class RepoOwner {
|
|
|
25
26
|
public site_admin!: boolean;
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
|
|
28
30
|
@json
|
|
29
31
|
class RepoLicense {
|
|
30
32
|
public key!: string;
|
|
@@ -34,9 +36,10 @@ class RepoLicense {
|
|
|
34
36
|
public node_id!: string;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
|
|
37
40
|
@json
|
|
38
41
|
class Repo {
|
|
39
|
-
public id!:
|
|
42
|
+
public id!: i32;
|
|
40
43
|
public node_id!: string;
|
|
41
44
|
public name!: string;
|
|
42
45
|
public full_name!: string;
|
|
@@ -90,9 +93,9 @@ class Repo {
|
|
|
90
93
|
public clone_url!: string;
|
|
91
94
|
public svn_url!: string;
|
|
92
95
|
public homepage!: string | null;
|
|
93
|
-
public size!:
|
|
94
|
-
public stargazers_count!:
|
|
95
|
-
public watchers_count!:
|
|
96
|
+
public size!: i32;
|
|
97
|
+
public stargazers_count!: i32;
|
|
98
|
+
public watchers_count!: i32;
|
|
96
99
|
public language!: string | null;
|
|
97
100
|
public has_issues!: boolean;
|
|
98
101
|
public has_projects!: boolean;
|
|
@@ -100,24 +103,24 @@ class Repo {
|
|
|
100
103
|
public has_wiki!: boolean;
|
|
101
104
|
public has_pages!: boolean;
|
|
102
105
|
public has_discussions!: boolean;
|
|
103
|
-
public forks_count!:
|
|
106
|
+
public forks_count!: i32;
|
|
104
107
|
public mirror_url!: string | null;
|
|
105
108
|
public archived!: boolean;
|
|
106
109
|
public disabled!: boolean;
|
|
107
|
-
public open_issues_count!:
|
|
110
|
+
public open_issues_count!: i32;
|
|
108
111
|
public license!: RepoLicense | null;
|
|
109
112
|
public allow_forking!: boolean;
|
|
110
113
|
public is_template!: boolean;
|
|
111
114
|
public web_commit_signoff_required!: boolean;
|
|
112
115
|
public topics!: string[];
|
|
113
116
|
public visibility!: string;
|
|
114
|
-
public forks!:
|
|
115
|
-
public open_issues!:
|
|
116
|
-
public watchers!:
|
|
117
|
+
public forks!: i32;
|
|
118
|
+
public open_issues!: i32;
|
|
119
|
+
public watchers!: i32;
|
|
117
120
|
public default_branch!: string;
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
|
|
123
|
+
const v1: Repo = {
|
|
121
124
|
id: 132935648,
|
|
122
125
|
node_id: "MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=",
|
|
123
126
|
name: "boysenberry-repo-1",
|
|
@@ -142,7 +145,7 @@ let v1: Repo = {
|
|
|
142
145
|
received_events_url: "https://api.github.com/users/octocat/received_events",
|
|
143
146
|
type: "User",
|
|
144
147
|
user_view_type: "public",
|
|
145
|
-
site_admin: false
|
|
148
|
+
site_admin: false,
|
|
146
149
|
},
|
|
147
150
|
html_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
148
151
|
description: "Testing",
|
|
@@ -216,26 +219,26 @@ let v1: Repo = {
|
|
|
216
219
|
forks: 20,
|
|
217
220
|
open_issues: 1,
|
|
218
221
|
watchers: 332,
|
|
219
|
-
default_branch: "master"
|
|
220
|
-
}
|
|
222
|
+
default_branch: "master",
|
|
223
|
+
};
|
|
221
224
|
|
|
222
225
|
const v2 = `{"id":132935648,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=","name":"boysenberry-repo-1","full_name":"octocat/boysenberry-repo-1","private":true,"owner":{"login":"octocat","id":583231,"node_id":"MDQ6VXNlcjU4MzIzMQ==","avatar_url":"https://avatars.githubusercontent.com/u/583231?v=4","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","user_view_type":"public","site_admin":false},"html_url":"https://github.com/octocat/boysenberry-repo-1","description":"Testing","fork":true,"url":"https://api.github.com/repos/octocat/boysenberry-repo-1","forks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/forks","keys_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/teams","hooks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/hooks","issue_events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/events","assignees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/tags","blobs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/languages","stargazers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers","contributors_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contributors","subscribers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers","subscription_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscription","commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/merges","archive_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/downloads","issues_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}","releases_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}","deployments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/deployments","created_at":"2018-05-10T17:51:29Z","updated_at":"2025-05-24T02:01:19Z","pushed_at":"2024-05-26T07:02:05Z","git_url":"git://github.com/octocat/boysenberry-repo-1.git","ssh_url":"git@github.com:octocat/boysenberry-repo-1.git","clone_url":"https://github.com/octocat/boysenberry-repo-1.git","svn_url":"https://github.com/octocat/boysenberry-repo-1","homepage":"","size":4,"stargazers_count":332,"watchers_count":332,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"has_discussions":false,"forks_count":20,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"allow_forking":true,"is_template":false,"web_commit_signoff_required":false,"topics":[],"visibility":"public","forks":20,"open_issues":1,"watchers":332,"default_branch":"master"}`;
|
|
223
226
|
|
|
224
227
|
expect(JSON.stringify(v1)).toBe(v2);
|
|
225
|
-
expect(JSON.stringify(JSON.parse(v2))).toBe(v2);
|
|
228
|
+
expect(JSON.stringify(JSON.parse<Repo>(v2))).toBe(v2);
|
|
226
229
|
|
|
227
230
|
bench(
|
|
228
231
|
"Serialize Large Object",
|
|
229
232
|
() => {
|
|
230
233
|
JSON.stringify(v1);
|
|
231
234
|
},
|
|
232
|
-
|
|
235
|
+
100_00,
|
|
233
236
|
);
|
|
234
237
|
|
|
235
238
|
bench(
|
|
236
239
|
"Deserialize Large Object",
|
|
237
240
|
() => {
|
|
238
|
-
JSON.parse(v2);
|
|
241
|
+
JSON.parse<Repo>(v2);
|
|
239
242
|
},
|
|
240
|
-
|
|
241
|
-
);
|
|
243
|
+
100_00,
|
|
244
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { JSON } from "..";
|
|
2
|
+
import { describe, expect } from "./lib";
|
|
3
|
+
|
|
4
|
+
@json
|
|
5
|
+
class GenericTest<T> {
|
|
6
|
+
public foo: T;
|
|
7
|
+
|
|
8
|
+
constructor(foo: T) {
|
|
9
|
+
this.foo = foo;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@json
|
|
14
|
+
class Vec3 {
|
|
15
|
+
public x!: i32;
|
|
16
|
+
public y!: i32;
|
|
17
|
+
public z!: i32;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Should serialize generics", () => {
|
|
21
|
+
expect(JSON.stringify(new GenericTest<string>("bar"))).toBe('{"foo":"bar"}');
|
|
22
|
+
expect(JSON.stringify(new GenericTest<i32>(42))).toBe('{"foo":42}');
|
|
23
|
+
expect(JSON.stringify(new GenericTest<boolean>(true))).toBe('{"foo":true}');
|
|
24
|
+
expect(JSON.stringify(new GenericTest<Vec3>({ x: 1, y: 2, z: 3 }))).toBe('{"foo":{"x":1,"y":2,"z":3}}');
|
|
25
|
+
expect(JSON.stringify(new GenericTest<string[]>(["item1", "item2"]))).toBe('{"foo":["item1","item2"]}');
|
|
26
|
+
expect(JSON.stringify(new GenericTest<Vec3[]>([{ x: 1, y: 2, z: 3 }, { x: 4, y: 5, z: 6 }]))).toBe('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}');
|
|
27
|
+
expect(JSON.stringify(new GenericTest<i32[]>([1, 2, 3]))).toBe('{"foo":[1,2,3]}');
|
|
28
|
+
expect(JSON.stringify(new GenericTest<boolean[]>([true, false, true]))).toBe('{"foo":[true,false,true]}');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("Should deserialize generics", () => {
|
|
32
|
+
expect(JSON.parse<GenericTest<string>>('{"foo":"bar"}').foo).toBe("bar");
|
|
33
|
+
expect(JSON.parse<GenericTest<i32>>('{"foo":42}').foo.toString()).toBe("42");
|
|
34
|
+
expect(JSON.parse<GenericTest<boolean>>('{"foo":true}').foo).toBe(true);
|
|
35
|
+
expect(JSON.stringify(JSON.parse<GenericTest<Vec3>>('{"foo":{"x":1,"y":2,"z":3}}'))).toBe('{"foo":{"x":1,"y":2,"z":3}}');
|
|
36
|
+
expect(JSON.stringify(JSON.parse<GenericTest<string[]>>('{"foo":["item1","item2"]}'))).toBe('{"foo":["item1","item2"]}');
|
|
37
|
+
expect(JSON.stringify(JSON.parse<GenericTest<Vec3[]>>('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}'))).toBe('{"foo":[{"x":1,"y":2,"z":3},{"x":4,"y":5,"z":6}]}');
|
|
38
|
+
expect(JSON.stringify(JSON.parse<GenericTest<i32[]>>('{"foo":[1,2,3]}'))).toBe('{"foo":[1,2,3]}');
|
|
39
|
+
expect(JSON.stringify(JSON.parse<GenericTest<boolean[]>>('{"foo":[true,false,true]}'))).toBe('{"foo":[true,false,true]}');
|
|
40
|
+
});
|
|
@@ -13,7 +13,7 @@ export function expect<T>(left: T): Expectation {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
if (!isDefined(left.toString)) throw new Error("Expected left to have a toString method, but it does not.");
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
return new Expectation(
|
|
16
|
+
return new Expectation(left == null ? "null" : left.toString());
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
class Expectation {
|
|
@@ -26,16 +26,12 @@ class Expectation {
|
|
|
26
26
|
// @ts-ignore
|
|
27
27
|
if (!isDefined(right.toString)) throw new Error("Expected right to have a toString method, but it does not.");
|
|
28
28
|
// @ts-ignore
|
|
29
|
-
if (this.left != (
|
|
29
|
+
if (this.left != (right == null ? "null" : right.toString())) {
|
|
30
30
|
console.log(" " + currentDescription + "\n");
|
|
31
31
|
// @ts-ignore
|
|
32
|
-
console.log(" (expected) -> " + (
|
|
32
|
+
console.log(" (expected) -> " + (right == null ? "null" : right.toString()));
|
|
33
33
|
console.log(" (received) -> " + this.left);
|
|
34
34
|
unreachable();
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
function isNull<T>(value: T): boolean {
|
|
40
|
-
return isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && value == 0;
|
|
41
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JSON } from "..";
|
|
2
|
+
import { describe, expect } from "./lib";
|
|
3
|
+
|
|
4
|
+
type StringAlias = string;
|
|
5
|
+
type StringAlias1 = StringAlias;
|
|
6
|
+
type StringAlias2 = StringAlias1;
|
|
7
|
+
type StringAlias3 = StringAlias2;
|
|
8
|
+
type StringAlias4 = StringAlias3;
|
|
9
|
+
|
|
10
|
+
@json
|
|
11
|
+
class Alias {
|
|
12
|
+
public foo: StringAlias4 = "";
|
|
13
|
+
constructor(foo: StringAlias2) {
|
|
14
|
+
this.foo = foo;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const alias = new Alias("bar");
|
|
19
|
+
|
|
20
|
+
describe("Should serialize with type aliases", () => {
|
|
21
|
+
expect(JSON.stringify(alias)).toBe('{"foo":"bar"}');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("Should deserialize with type aliases", () => {
|
|
25
|
+
expect(JSON.stringify(JSON.parse<Alias>('{"foo":"bar"}'))).toBe('{"foo":"bar"}');
|
|
26
|
+
});
|
package/bench/large.bench.ts
CHANGED
|
@@ -1,231 +1,120 @@
|
|
|
1
1
|
import { bench } from "./lib/bench.js";
|
|
2
|
-
import { expect } from "./lib/test.js";
|
|
3
2
|
|
|
4
|
-
class
|
|
5
|
-
public
|
|
6
|
-
public
|
|
7
|
-
public
|
|
8
|
-
public avatar_url!: string;
|
|
9
|
-
public gravatar_id!: string;
|
|
10
|
-
public url!: string;
|
|
11
|
-
public html_url!: string;
|
|
12
|
-
public followers_url!: string;
|
|
13
|
-
public following_url!: string;
|
|
14
|
-
public gists_url!: string;
|
|
15
|
-
public starred_url!: string;
|
|
16
|
-
public subscriptions_url!: string;
|
|
17
|
-
public organizations_url!: string;
|
|
18
|
-
public repos_url!: string;
|
|
19
|
-
public events_url!: string;
|
|
20
|
-
public received_events_url!: string;
|
|
21
|
-
public type!: string;
|
|
22
|
-
public user_view_type!: string;
|
|
23
|
-
public site_admin!: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class RepoLicense {
|
|
27
|
-
public key!: string;
|
|
28
|
-
public name!: string;
|
|
29
|
-
public spdx_id!: string;
|
|
30
|
-
public url!: string | null;
|
|
31
|
-
public node_id!: string;
|
|
3
|
+
class Vec3 {
|
|
4
|
+
public x!: number;
|
|
5
|
+
public y!: number;
|
|
6
|
+
public z!: number;
|
|
32
7
|
}
|
|
33
8
|
|
|
34
|
-
class
|
|
9
|
+
class LargeJSON {
|
|
35
10
|
public id!: number;
|
|
36
|
-
public node_id!: string;
|
|
37
11
|
public name!: string;
|
|
38
|
-
public
|
|
39
|
-
public
|
|
40
|
-
public
|
|
41
|
-
public
|
|
42
|
-
public
|
|
43
|
-
public
|
|
44
|
-
public
|
|
45
|
-
public
|
|
46
|
-
public
|
|
47
|
-
public
|
|
48
|
-
public
|
|
49
|
-
public hooks_url!: string;
|
|
50
|
-
public issue_events_url!: string;
|
|
51
|
-
public events_url!: string;
|
|
52
|
-
public assignees_url!: string;
|
|
53
|
-
public branches_url!: string;
|
|
54
|
-
public tags_url!: string;
|
|
55
|
-
public blobs_url!: string;
|
|
56
|
-
public git_tags_url!: string;
|
|
57
|
-
public git_refs_url!: string;
|
|
58
|
-
public trees_url!: string;
|
|
59
|
-
public statuses_url!: string;
|
|
60
|
-
public languages_url!: string;
|
|
61
|
-
public stargazers_url!: string;
|
|
62
|
-
public contributors_url!: string;
|
|
63
|
-
public subscribers_url!: string;
|
|
64
|
-
public subscription_url!: string;
|
|
65
|
-
public commits_url!: string;
|
|
66
|
-
public git_commits_url!: string;
|
|
67
|
-
public comments_url!: string;
|
|
68
|
-
public issue_comment_url!: string;
|
|
69
|
-
public contents_url!: string;
|
|
70
|
-
public compare_url!: string;
|
|
71
|
-
public merges_url!: string;
|
|
72
|
-
public archive_url!: string;
|
|
73
|
-
public downloads_url!: string;
|
|
74
|
-
public issues_url!: string;
|
|
75
|
-
public pulls_url!: string;
|
|
76
|
-
public milestones_url!: string;
|
|
77
|
-
public notifications_url!: string;
|
|
78
|
-
public labels_url!: string;
|
|
79
|
-
public releases_url!: string;
|
|
80
|
-
public deployments_url!: string;
|
|
81
|
-
public created_at!: string;
|
|
82
|
-
public updated_at!: string;
|
|
83
|
-
public pushed_at!: string;
|
|
84
|
-
public git_url!: string;
|
|
85
|
-
public ssh_url!: string;
|
|
86
|
-
public clone_url!: string;
|
|
87
|
-
public svn_url!: string;
|
|
88
|
-
public homepage!: string | null;
|
|
89
|
-
public size!: number;
|
|
90
|
-
public stargazers_count!: number;
|
|
91
|
-
public watchers_count!: number;
|
|
92
|
-
public language!: string | null;
|
|
93
|
-
public has_issues!: boolean;
|
|
94
|
-
public has_projects!: boolean;
|
|
95
|
-
public has_downloads!: boolean;
|
|
96
|
-
public has_wiki!: boolean;
|
|
97
|
-
public has_pages!: boolean;
|
|
98
|
-
public has_discussions!: boolean;
|
|
99
|
-
public forks_count!: number;
|
|
100
|
-
public mirror_url!: string | null;
|
|
101
|
-
public archived!: boolean;
|
|
102
|
-
public disabled!: boolean;
|
|
103
|
-
public open_issues_count!: number;
|
|
104
|
-
public license!: RepoLicense | null;
|
|
105
|
-
public allow_forking!: boolean;
|
|
106
|
-
public is_template!: boolean;
|
|
107
|
-
public web_commit_signoff_required!: boolean;
|
|
108
|
-
public topics!: string[];
|
|
109
|
-
public visibility!: string;
|
|
110
|
-
public forks!: number;
|
|
111
|
-
public open_issues!: number;
|
|
112
|
-
public watchers!: number;
|
|
113
|
-
public default_branch!: string;
|
|
12
|
+
public age!: number;
|
|
13
|
+
public email!: string;
|
|
14
|
+
public street!: string;
|
|
15
|
+
public city!: string;
|
|
16
|
+
public state!: string;
|
|
17
|
+
public zip!: string;
|
|
18
|
+
public tags!: string[];
|
|
19
|
+
public theme!: string;
|
|
20
|
+
public notifications!: boolean;
|
|
21
|
+
public language!: string;
|
|
22
|
+
public movement!: Vec3[];
|
|
114
23
|
}
|
|
115
24
|
|
|
116
|
-
|
|
117
|
-
id:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
has_discussions: false,
|
|
201
|
-
forks_count: 20,
|
|
202
|
-
mirror_url: null,
|
|
203
|
-
archived: false,
|
|
204
|
-
disabled: false,
|
|
205
|
-
open_issues_count: 1,
|
|
206
|
-
license: null,
|
|
207
|
-
allow_forking: true,
|
|
208
|
-
is_template: false,
|
|
209
|
-
web_commit_signoff_required: false,
|
|
210
|
-
topics: [],
|
|
211
|
-
visibility: "public",
|
|
212
|
-
forks: 20,
|
|
213
|
-
open_issues: 1,
|
|
214
|
-
watchers: 332,
|
|
215
|
-
default_branch: "master"
|
|
216
|
-
}
|
|
25
|
+
const v1: LargeJSON = {
|
|
26
|
+
id: 2,
|
|
27
|
+
name: "Medium Object",
|
|
28
|
+
age: 18,
|
|
29
|
+
email: "me@jairus.dev",
|
|
30
|
+
street: "I don't want to say my street",
|
|
31
|
+
city: "I don't want to say this either",
|
|
32
|
+
state: "It really depends",
|
|
33
|
+
zip: "I forget what it is",
|
|
34
|
+
tags: ["me", "dogs", "mountains", "bar", "foo"],
|
|
35
|
+
theme: "Hyper Term Black",
|
|
36
|
+
notifications: true,
|
|
37
|
+
language: "en-US",
|
|
38
|
+
movement: [
|
|
39
|
+
{ x: 1, y: 2, z: 3 },
|
|
40
|
+
{ x: 1, y: 2, z: 3 },
|
|
41
|
+
{ x: 1, y: 2, z: 3 },
|
|
42
|
+
{ x: 1, y: 2, z: 3 },
|
|
43
|
+
{ x: 1, y: 2, z: 3 },
|
|
44
|
+
{ x: 1, y: 2, z: 3 },
|
|
45
|
+
{ x: 1, y: 2, z: 3 },
|
|
46
|
+
{ x: 1, y: 2, z: 3 },
|
|
47
|
+
{ x: 1, y: 2, z: 3 },
|
|
48
|
+
{ x: 1, y: 2, z: 3 },
|
|
49
|
+
{ x: 1, y: 2, z: 3 },
|
|
50
|
+
{ x: 1, y: 2, z: 3 },
|
|
51
|
+
{ x: 1, y: 2, z: 3 },
|
|
52
|
+
{ x: 1, y: 2, z: 3 },
|
|
53
|
+
{ x: 1, y: 2, z: 3 },
|
|
54
|
+
{ x: 1, y: 2, z: 3 },
|
|
55
|
+
{ x: 1, y: 2, z: 3 },
|
|
56
|
+
{ x: 1, y: 2, z: 3 },
|
|
57
|
+
{ x: 1, y: 2, z: 3 },
|
|
58
|
+
{ x: 1, y: 2, z: 3 },
|
|
59
|
+
{ x: 1, y: 2, z: 3 },
|
|
60
|
+
{ x: 1, y: 2, z: 3 },
|
|
61
|
+
{ x: 1, y: 2, z: 3 },
|
|
62
|
+
{ x: 1, y: 2, z: 3 },
|
|
63
|
+
{ x: 1, y: 2, z: 3 },
|
|
64
|
+
{ x: 1, y: 2, z: 3 },
|
|
65
|
+
{ x: 1, y: 2, z: 3 },
|
|
66
|
+
{ x: 1, y: 2, z: 3 },
|
|
67
|
+
{ x: 1, y: 2, z: 3 },
|
|
68
|
+
{ x: 1, y: 2, z: 3 },
|
|
69
|
+
{ x: 1, y: 2, z: 3 },
|
|
70
|
+
{ x: 1, y: 2, z: 3 },
|
|
71
|
+
{ x: 1, y: 2, z: 3 },
|
|
72
|
+
{ x: 1, y: 2, z: 3 },
|
|
73
|
+
{ x: 1, y: 2, z: 3 },
|
|
74
|
+
{ x: 1, y: 2, z: 3 },
|
|
75
|
+
{ x: 1, y: 2, z: 3 },
|
|
76
|
+
{ x: 1, y: 2, z: 3 },
|
|
77
|
+
{ x: 1, y: 2, z: 3 },
|
|
78
|
+
{ x: 1, y: 2, z: 3 },
|
|
79
|
+
{ x: 1, y: 2, z: 3 },
|
|
80
|
+
{ x: 1, y: 2, z: 3 },
|
|
81
|
+
{ x: 1, y: 2, z: 3 },
|
|
82
|
+
{ x: 1, y: 2, z: 3 },
|
|
83
|
+
{ x: 1, y: 2, z: 3 },
|
|
84
|
+
{ x: 1, y: 2, z: 3 },
|
|
85
|
+
{ x: 1, y: 2, z: 3 },
|
|
86
|
+
{ x: 1, y: 2, z: 3 },
|
|
87
|
+
{ x: 1, y: 2, z: 3 },
|
|
88
|
+
{ x: 1, y: 2, z: 3 },
|
|
89
|
+
{ x: 1, y: 2, z: 3 },
|
|
90
|
+
{ x: 1, y: 2, z: 3 },
|
|
91
|
+
{ x: 1, y: 2, z: 3 },
|
|
92
|
+
{ x: 1, y: 2, z: 3 },
|
|
93
|
+
{ x: 1, y: 2, z: 3 },
|
|
94
|
+
{ x: 1, y: 2, z: 3 },
|
|
95
|
+
{ x: 1, y: 2, z: 3 },
|
|
96
|
+
{ x: 1, y: 2, z: 3 },
|
|
97
|
+
{ x: 1, y: 2, z: 3 },
|
|
98
|
+
{ x: 1, y: 2, z: 3 },
|
|
99
|
+
{ x: 1, y: 2, z: 3 },
|
|
100
|
+
{ x: 1, y: 2, z: 3 },
|
|
101
|
+
{ x: 1, y: 2, z: 3 },
|
|
102
|
+
{ x: 1, y: 2, z: 3 },
|
|
103
|
+
{ x: 1, y: 2, z: 3 },
|
|
104
|
+
{ x: 1, y: 2, z: 3 },
|
|
105
|
+
{ x: 1, y: 2, z: 3 },
|
|
106
|
+
{ x: 1, y: 2, z: 3 },
|
|
107
|
+
],
|
|
108
|
+
};
|
|
217
109
|
|
|
218
|
-
const v2 = `{"id":
|
|
219
|
-
|
|
220
|
-
expect(JSON.stringify(v1)).toBe(v2);
|
|
221
|
-
expect(JSON.stringify(JSON.parse(v2))).toBe(v2);
|
|
110
|
+
const v2 = `{"id":2,"name":"Medium Object","age":18,"email":"me@jairus.dev","street":"I don't want to say my street","city":"I don't want to say this either","state":"It really depends","zip":"I forget what it is","tags":["me","dogs","mountains","bar","foo"],"theme":"Hyper Term Black","notifications":true,"language":"en-US","movement":[{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3}]}`;
|
|
222
111
|
|
|
223
112
|
bench(
|
|
224
113
|
"Serialize Large Object",
|
|
225
114
|
() => {
|
|
226
115
|
JSON.stringify(v1);
|
|
227
116
|
},
|
|
228
|
-
|
|
117
|
+
3_000_00,
|
|
229
118
|
);
|
|
230
119
|
|
|
231
120
|
bench(
|
|
@@ -233,5 +122,5 @@ bench(
|
|
|
233
122
|
() => {
|
|
234
123
|
JSON.parse(v2);
|
|
235
124
|
},
|
|
236
|
-
|
|
237
|
-
);
|
|
125
|
+
3_000_00,
|
|
126
|
+
);
|