json-as 1.1.8 → 1.1.10
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 +16 -0
- package/README.md +9 -2
- package/assembly/__benches__/large.bench.ts +214 -104
- package/assembly/__tests__/array.spec.ts +8 -5
- package/assembly/__tests__/lib/index.ts +20 -6
- package/assembly/__tests__/struct.spec.ts +2 -0
- package/assembly/__tests__/test.spec.ts +0 -119
- package/assembly/index.ts +4 -2
- package/assembly/test.ts +141 -251
- package/assembly/types.ts +70 -0
- package/index.ts +1 -1
- package/package.json +6 -6
- package/run-bench.as.sh +1 -1
- package/transform/lib/builder.js +3 -0
- package/transform/lib/builder.js.map +1 -1
- package/transform/lib/index.js +463 -224
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linker.js +38 -6
- package/transform/lib/linker.js.map +1 -1
- package/transform/lib/util.js +5 -0
- package/transform/lib/util.js.map +1 -1
- package/transform/src/builder.ts +4 -0
- package/transform/src/index.ts +531 -275
- package/transform/src/linker.ts +48 -7
- package/transform/src/types.ts +1 -1
- package/transform/src/util.ts +11 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2025-05-27 - 1.1.10
|
|
4
|
+
|
|
5
|
+
- feat: add more debug levels (1 = print transform code, 2 = print keys/values at runtime)
|
|
6
|
+
- feat: add write out feature (`JSON_WRITE=path-to-file.ts`) which writes out generated code
|
|
7
|
+
- fix: complete full parity between port and original version for correct deserialization of all types
|
|
8
|
+
- feat: add proper schema resolution and dependency resolution
|
|
9
|
+
- feat: add proper type resolution to schema fields
|
|
10
|
+
- fix: properly calculate the relative path between imports to modules
|
|
11
|
+
|
|
12
|
+
## 2025-05-27 - 1.1.9
|
|
13
|
+
|
|
14
|
+
- change: strict mode is disabled by default. Enable it with JSON_STRICT=true
|
|
15
|
+
- fix: should ignore properties of same length and type if no matching key exists
|
|
16
|
+
- fix: should ignore properties of different type if no matching key exists
|
|
17
|
+
- fix: should ignore complex properties if no matching key exists
|
|
18
|
+
|
|
3
19
|
## 2025-05-27 - 1.1.8
|
|
4
20
|
|
|
5
21
|
- feat: add support for calling `JSON.stringify/JSON.parse` methods inside of custom serializers, but not yet deserializers
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
7
7
|
█████ ███████ ██████ ██ ████ ██ ██ ███████
|
|
8
8
|
</span>
|
|
9
|
-
AssemblyScript - v1.1.
|
|
9
|
+
AssemblyScript - v1.1.10
|
|
10
10
|
</pre>
|
|
11
11
|
</h6>
|
|
12
12
|
|
|
@@ -25,6 +25,7 @@ JSON is the de-facto serialization format of modern web applications, but its se
|
|
|
25
25
|
- [Using Raw JSON Strings](#️-using-raw-json-strings)
|
|
26
26
|
- [Custom Serializers](#️-using-custom-serializers-or-deserializers)
|
|
27
27
|
- [Performance](#-performance)
|
|
28
|
+
- [Debugging](#-debugging)
|
|
28
29
|
- [License](#-license)
|
|
29
30
|
- [Contact](#-contact)
|
|
30
31
|
|
|
@@ -384,7 +385,7 @@ These benchmarks compare this library to JavaScript's native `JSON.stringify` an
|
|
|
384
385
|
| Alphabet String | 104 bytes | 13,617,021 ops/s | 18,390,804 ops/s | 1,416 MB/s | 1,986 MB/s |
|
|
385
386
|
| Small Object | 88 bytes | 24,242,424 ops/s | 12,307,692 ops/s | 2,133 MB/s | 1,083 MB/s |
|
|
386
387
|
| Medium Object | 494 bytes | 4,060,913 ops/s | 1,396,160 ops/s | 2,006 MB/s | 689.7 MB/s |
|
|
387
|
-
| Large Object | 3374 bytes |
|
|
388
|
+
| Large Object | 3374 bytes | 479,616 ops/s | 132,802 ops/s | 2,074 MB/s | 448.0 MB/s |
|
|
388
389
|
|
|
389
390
|
**Table 2** - _JavaScript (V8)_
|
|
390
391
|
|
|
@@ -445,6 +446,12 @@ These benchmarks compare this library to JavaScript's native `JSON.stringify` an
|
|
|
445
446
|
- Inline specific hot code paths
|
|
446
447
|
- Implement error handling implementation
|
|
447
448
|
|
|
449
|
+
## 🐛 Debugging
|
|
450
|
+
|
|
451
|
+
`JSON_DEBUG=1` - Prints out generated code at compile-time
|
|
452
|
+
`JSON_DEBUG=2` - The above and prints keys/values as they are deserialized
|
|
453
|
+
`JSON_WRITE=path-to-file.ts` - Writes out generated code to `path-to-file.json.ts` for easy inspection
|
|
454
|
+
|
|
448
455
|
## 📃 License
|
|
449
456
|
|
|
450
457
|
This project is distributed under an open source license. You can view the full license using the following link: [License](./LICENSE)
|
|
@@ -4,131 +4,241 @@ import { bench } from "./lib/bench";
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
@json
|
|
7
|
-
class
|
|
8
|
-
public
|
|
9
|
-
public
|
|
10
|
-
public
|
|
7
|
+
class RepoOwner {
|
|
8
|
+
public login!: string;
|
|
9
|
+
public id!: i32;
|
|
10
|
+
public node_id!: string;
|
|
11
|
+
public avatar_url!: string;
|
|
12
|
+
public gravatar_id!: string;
|
|
13
|
+
public url!: string;
|
|
14
|
+
public html_url!: string;
|
|
15
|
+
public followers_url!: string;
|
|
16
|
+
public following_url!: string;
|
|
17
|
+
public gists_url!: string;
|
|
18
|
+
public starred_url!: string;
|
|
19
|
+
public subscriptions_url!: string;
|
|
20
|
+
public organizations_url!: string;
|
|
21
|
+
public repos_url!: string;
|
|
22
|
+
public events_url!: string;
|
|
23
|
+
public received_events_url!: string;
|
|
24
|
+
public type!: string;
|
|
25
|
+
public user_view_type!: string;
|
|
26
|
+
public site_admin!: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@json
|
|
31
|
+
class RepoLicense {
|
|
32
|
+
public key!: string;
|
|
33
|
+
public name!: string;
|
|
34
|
+
public spdx_id!: string;
|
|
35
|
+
public url!: string | null;
|
|
36
|
+
public node_id!: string;
|
|
11
37
|
}
|
|
12
38
|
|
|
13
39
|
|
|
14
40
|
@json
|
|
15
|
-
class
|
|
41
|
+
class Repo {
|
|
16
42
|
public id!: i32;
|
|
43
|
+
public node_id!: string;
|
|
17
44
|
public name!: string;
|
|
18
|
-
public
|
|
19
|
-
public
|
|
20
|
-
public
|
|
21
|
-
public
|
|
22
|
-
public
|
|
23
|
-
public
|
|
24
|
-
public
|
|
25
|
-
public
|
|
26
|
-
public
|
|
27
|
-
public
|
|
28
|
-
public
|
|
45
|
+
public full_name!: string;
|
|
46
|
+
public private!: boolean;
|
|
47
|
+
public owner: RepoOwner = new RepoOwner();
|
|
48
|
+
public html_url!: string;
|
|
49
|
+
public description!: string | null;
|
|
50
|
+
public fork!: boolean;
|
|
51
|
+
public url!: string;
|
|
52
|
+
public forks_url!: string;
|
|
53
|
+
public keys_url!: string;
|
|
54
|
+
public collaborators_url!: string;
|
|
55
|
+
public teams_url!: string;
|
|
56
|
+
public hooks_url!: string;
|
|
57
|
+
public issue_events_url!: string;
|
|
58
|
+
public events_url!: string;
|
|
59
|
+
public assignees_url!: string;
|
|
60
|
+
public branches_url!: string;
|
|
61
|
+
public tags_url!: string;
|
|
62
|
+
public blobs_url!: string;
|
|
63
|
+
public git_tags_url!: string;
|
|
64
|
+
public git_refs_url!: string;
|
|
65
|
+
public trees_url!: string;
|
|
66
|
+
public statuses_url!: string;
|
|
67
|
+
public languages_url!: string;
|
|
68
|
+
public stargazers_url!: string;
|
|
69
|
+
public contributors_url!: string;
|
|
70
|
+
public subscribers_url!: string;
|
|
71
|
+
public subscription_url!: string;
|
|
72
|
+
public commits_url!: string;
|
|
73
|
+
public git_commits_url!: string;
|
|
74
|
+
public comments_url!: string;
|
|
75
|
+
public issue_comment_url!: string;
|
|
76
|
+
public contents_url!: string;
|
|
77
|
+
public compare_url!: string;
|
|
78
|
+
public merges_url!: string;
|
|
79
|
+
public archive_url!: string;
|
|
80
|
+
public downloads_url!: string;
|
|
81
|
+
public issues_url!: string;
|
|
82
|
+
public pulls_url!: string;
|
|
83
|
+
public milestones_url!: string;
|
|
84
|
+
public notifications_url!: string;
|
|
85
|
+
public labels_url!: string;
|
|
86
|
+
public releases_url!: string;
|
|
87
|
+
public deployments_url!: string;
|
|
88
|
+
public created_at!: string;
|
|
89
|
+
public updated_at!: string;
|
|
90
|
+
public pushed_at!: string;
|
|
91
|
+
public git_url!: string;
|
|
92
|
+
public ssh_url!: string;
|
|
93
|
+
public clone_url!: string;
|
|
94
|
+
public svn_url!: string;
|
|
95
|
+
public homepage!: string | null;
|
|
96
|
+
public size!: i32;
|
|
97
|
+
public stargazers_count!: i32;
|
|
98
|
+
public watchers_count!: i32;
|
|
99
|
+
public language!: string | null;
|
|
100
|
+
public has_issues!: boolean;
|
|
101
|
+
public has_projects!: boolean;
|
|
102
|
+
public has_downloads!: boolean;
|
|
103
|
+
public has_wiki!: boolean;
|
|
104
|
+
public has_pages!: boolean;
|
|
105
|
+
public has_discussions!: boolean;
|
|
106
|
+
public forks_count!: i32;
|
|
107
|
+
public mirror_url!: string | null;
|
|
108
|
+
public archived!: boolean;
|
|
109
|
+
public disabled!: boolean;
|
|
110
|
+
public open_issues_count!: i32;
|
|
111
|
+
public license!: RepoLicense | null;
|
|
112
|
+
public allow_forking!: boolean;
|
|
113
|
+
public is_template!: boolean;
|
|
114
|
+
public web_commit_signoff_required!: boolean;
|
|
115
|
+
public topics!: string[];
|
|
116
|
+
public visibility!: string;
|
|
117
|
+
public forks!: i32;
|
|
118
|
+
public open_issues!: i32;
|
|
119
|
+
public watchers!: i32;
|
|
120
|
+
public default_branch!: string;
|
|
29
121
|
}
|
|
30
122
|
|
|
31
|
-
const v1:
|
|
32
|
-
id:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
const v1: Repo = {
|
|
124
|
+
id: 132935648,
|
|
125
|
+
node_id: "MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=",
|
|
126
|
+
name: "boysenberry-repo-1",
|
|
127
|
+
full_name: "octocat/boysenberry-repo-1",
|
|
128
|
+
private: true,
|
|
129
|
+
owner: {
|
|
130
|
+
login: "octocat",
|
|
131
|
+
id: 583231,
|
|
132
|
+
node_id: "MDQ6VXNlcjU4MzIzMQ==",
|
|
133
|
+
avatar_url: "https://avatars.githubusercontent.com/u/583231?v=4",
|
|
134
|
+
gravatar_id: "",
|
|
135
|
+
url: "https://api.github.com/users/octocat",
|
|
136
|
+
html_url: "https://github.com/octocat",
|
|
137
|
+
followers_url: "https://api.github.com/users/octocat/followers",
|
|
138
|
+
following_url: "https://api.github.com/users/octocat/following{/other_user}",
|
|
139
|
+
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
|
|
140
|
+
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
|
141
|
+
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
|
|
142
|
+
organizations_url: "https://api.github.com/users/octocat/orgs",
|
|
143
|
+
repos_url: "https://api.github.com/users/octocat/repos",
|
|
144
|
+
events_url: "https://api.github.com/users/octocat/events{/privacy}",
|
|
145
|
+
received_events_url: "https://api.github.com/users/octocat/received_events",
|
|
146
|
+
type: "User",
|
|
147
|
+
user_view_type: "public",
|
|
148
|
+
site_admin: false,
|
|
149
|
+
},
|
|
150
|
+
html_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
151
|
+
description: "Testing",
|
|
152
|
+
fork: true,
|
|
153
|
+
url: "https://api.github.com/repos/octocat/boysenberry-repo-1",
|
|
154
|
+
forks_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/forks",
|
|
155
|
+
keys_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}",
|
|
156
|
+
collaborators_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}",
|
|
157
|
+
teams_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/teams",
|
|
158
|
+
hooks_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/hooks",
|
|
159
|
+
issue_events_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}",
|
|
160
|
+
events_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/events",
|
|
161
|
+
assignees_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}",
|
|
162
|
+
branches_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}",
|
|
163
|
+
tags_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/tags",
|
|
164
|
+
blobs_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}",
|
|
165
|
+
git_tags_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}",
|
|
166
|
+
git_refs_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}",
|
|
167
|
+
trees_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}",
|
|
168
|
+
statuses_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}",
|
|
169
|
+
languages_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/languages",
|
|
170
|
+
stargazers_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers",
|
|
171
|
+
contributors_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/contributors",
|
|
172
|
+
subscribers_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers",
|
|
173
|
+
subscription_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/subscription",
|
|
174
|
+
commits_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}",
|
|
175
|
+
git_commits_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}",
|
|
176
|
+
comments_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}",
|
|
177
|
+
issue_comment_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}",
|
|
178
|
+
contents_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}",
|
|
179
|
+
compare_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}",
|
|
180
|
+
merges_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/merges",
|
|
181
|
+
archive_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}",
|
|
182
|
+
downloads_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/downloads",
|
|
183
|
+
issues_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}",
|
|
184
|
+
pulls_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}",
|
|
185
|
+
milestones_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}",
|
|
186
|
+
notifications_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}",
|
|
187
|
+
labels_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}",
|
|
188
|
+
releases_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}",
|
|
189
|
+
deployments_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/deployments",
|
|
190
|
+
created_at: "2018-05-10T17:51:29Z",
|
|
191
|
+
updated_at: "2025-05-24T02:01:19Z",
|
|
192
|
+
pushed_at: "2024-05-26T07:02:05Z",
|
|
193
|
+
git_url: "git://github.com/octocat/boysenberry-repo-1.git",
|
|
194
|
+
ssh_url: "git@github.com:octocat/boysenberry-repo-1.git",
|
|
195
|
+
clone_url: "https://github.com/octocat/boysenberry-repo-1.git",
|
|
196
|
+
svn_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
197
|
+
homepage: "",
|
|
198
|
+
size: 4,
|
|
199
|
+
stargazers_count: 332,
|
|
200
|
+
watchers_count: 332,
|
|
201
|
+
language: null,
|
|
202
|
+
has_issues: false,
|
|
203
|
+
has_projects: true,
|
|
204
|
+
has_downloads: true,
|
|
205
|
+
has_wiki: true,
|
|
206
|
+
has_pages: false,
|
|
207
|
+
has_discussions: false,
|
|
208
|
+
forks_count: 20,
|
|
209
|
+
mirror_url: null,
|
|
210
|
+
archived: false,
|
|
211
|
+
disabled: false,
|
|
212
|
+
open_issues_count: 1,
|
|
213
|
+
license: null,
|
|
214
|
+
allow_forking: true,
|
|
215
|
+
is_template: false,
|
|
216
|
+
web_commit_signoff_required: false,
|
|
217
|
+
topics: [],
|
|
218
|
+
visibility: "public",
|
|
219
|
+
forks: 20,
|
|
220
|
+
open_issues: 1,
|
|
221
|
+
watchers: 332,
|
|
222
|
+
default_branch: "master",
|
|
114
223
|
};
|
|
115
224
|
|
|
116
|
-
const v2 = `{"id":
|
|
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"}`;
|
|
117
226
|
|
|
118
227
|
expect(JSON.stringify(v1)).toBe(v2);
|
|
119
|
-
expect(JSON.stringify(JSON.parse<
|
|
228
|
+
expect(JSON.stringify(JSON.parse<Repo>(v2))).toBe(v2);
|
|
229
|
+
|
|
120
230
|
bench(
|
|
121
231
|
"Serialize Large Object",
|
|
122
232
|
() => {
|
|
123
233
|
JSON.stringify(v1);
|
|
124
234
|
},
|
|
125
|
-
|
|
235
|
+
100_00,
|
|
126
236
|
);
|
|
127
237
|
|
|
128
238
|
bench(
|
|
129
239
|
"Deserialize Large Object",
|
|
130
240
|
() => {
|
|
131
|
-
JSON.parse<
|
|
241
|
+
JSON.parse<Repo>(v2);
|
|
132
242
|
},
|
|
133
|
-
|
|
243
|
+
100_00,
|
|
134
244
|
);
|
|
@@ -117,13 +117,13 @@ class Vec3 {
|
|
|
117
117
|
|
|
118
118
|
while (srcStart < srcEnd) {
|
|
119
119
|
let code = load<u16>(srcStart);
|
|
120
|
-
while (JSON.Util.isSpace(code)) code = load<u16>(srcStart += 2);
|
|
120
|
+
while (JSON.Util.isSpace(code)) code = load<u16>((srcStart += 2));
|
|
121
121
|
if (keyStart == 0) {
|
|
122
122
|
if (code == 34 && load<u16>(srcStart - 2) !== 92) {
|
|
123
123
|
if (isKey) {
|
|
124
124
|
keyStart = lastIndex;
|
|
125
125
|
keyEnd = srcStart;
|
|
126
|
-
while (JSON.Util.isSpace((code = load<u16>((srcStart += 2))))) {
|
|
126
|
+
while (JSON.Util.isSpace((code = load<u16>((srcStart += 2))))) {}
|
|
127
127
|
if (code !== 58) throw new Error("Expected ':' after key at position " + (srcEnd - srcStart).toString());
|
|
128
128
|
isKey = false;
|
|
129
129
|
} else {
|
|
@@ -142,15 +142,18 @@ class Vec3 {
|
|
|
142
142
|
switch (<u32>keyEnd - <u32>keyStart) {
|
|
143
143
|
case 2: {
|
|
144
144
|
const code16 = load<u16>(keyStart);
|
|
145
|
-
if (code16 == 120) {
|
|
145
|
+
if (code16 == 120) {
|
|
146
|
+
// x
|
|
146
147
|
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("x"));
|
|
147
148
|
keyStart = 0;
|
|
148
149
|
break;
|
|
149
|
-
} else if (code16 == 121) {
|
|
150
|
+
} else if (code16 == 121) {
|
|
151
|
+
// y
|
|
150
152
|
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("y"));
|
|
151
153
|
keyStart = 0;
|
|
152
154
|
break;
|
|
153
|
-
} else if (code16 == 122) {
|
|
155
|
+
} else if (code16 == 122) {
|
|
156
|
+
// z
|
|
154
157
|
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("z"));
|
|
155
158
|
keyStart = 0;
|
|
156
159
|
break;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
let currentDescription: string = "";
|
|
1
2
|
export function describe(description: string, routine: () => void): void {
|
|
3
|
+
currentDescription = description;
|
|
2
4
|
routine();
|
|
3
|
-
// console.log(" " + description + " OK");
|
|
4
5
|
}
|
|
5
6
|
|
|
6
|
-
export function
|
|
7
|
-
|
|
7
|
+
export function it(description: string, routine: () => void): void {
|
|
8
|
+
currentDescription = description;
|
|
9
|
+
routine();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function expect<T>(left: T): Expectation {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!isDefined(left.toString)) throw new Error("Expected left to have a toString method, but it does not.");
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return new Expectation(left == null ? "null" : left.toString());
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
class Expectation {
|
|
@@ -13,9 +22,14 @@ class Expectation {
|
|
|
13
22
|
constructor(left: string) {
|
|
14
23
|
this.left = left;
|
|
15
24
|
}
|
|
16
|
-
toBe(right:
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
toBe<T>(right: T): void {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
if (!isDefined(right.toString)) throw new Error("Expected right to have a toString method, but it does not.");
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
if (this.left != (right == null ? "null" : right.toString())) {
|
|
30
|
+
console.log(" " + currentDescription + "\n");
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
console.log(" (expected) -> " + (right == null ? "null" : right.toString()));
|
|
19
33
|
console.log(" (received) -> " + this.left);
|
|
20
34
|
unreachable();
|
|
21
35
|
}
|
|
@@ -54,6 +54,8 @@ describe("Should ignore properties decorated with @omit", () => {
|
|
|
54
54
|
|
|
55
55
|
describe("Should deserialize structs", () => {
|
|
56
56
|
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
57
|
+
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"a":1.3,"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
58
|
+
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"a":1.3,"y":123,"asdf":3453204,"boink":[],"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
describe("Should deserialize structs with whitespace", () => {
|