json-as 0.9.17 → 0.9.19
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/.github/FUNDING.yml +1 -1
- package/.github/workflows/nodejs.yml +4 -5
- package/.github/workflows/release-package.yml +2 -2
- package/CHANGELOG +2 -0
- package/README.md +27 -67
- package/as-test.config.json +3 -5
- package/assembly/__tests__/test.spec.ts +201 -311
- package/assembly/__tests__/types.ts +9 -10
- package/assembly/custom/sink.ts +264 -263
- package/assembly/custom/types.ts +1 -1
- package/assembly/deserialize/array.ts +30 -26
- package/assembly/index.d.ts +1 -2
- package/assembly/serialize/object.ts +2 -1
- package/assembly/test.ts +4 -3
- package/assembly/tsconfig.json +8 -10
- package/bench/bench-node.js +6 -6
- package/bench/benchmark.ts +18 -18
- package/bench/tsconfig.json +96 -98
- package/bench.js +9 -9
- package/index.ts +1 -1
- package/package.json +8 -5
- package/transform/lib/index.js +472 -420
- package/transform/package.json +1 -1
- package/transform/src/index.ts +244 -142
- package/transform/tsconfig.json +2 -2
package/.github/FUNDING.yml
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
github: [JairusSW]
|
|
1
|
+
github: [JairusSW]
|
|
@@ -4,24 +4,23 @@ on: [push, pull_request]
|
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
6
|
build:
|
|
7
|
-
|
|
8
7
|
runs-on: ubuntu-latest
|
|
9
8
|
|
|
10
9
|
steps:
|
|
11
10
|
- name: Checkout the repository
|
|
12
11
|
uses: actions/checkout@v4
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
- name: Install Wasmtime
|
|
15
14
|
uses: jcbhmr/setup-wasmtime@v2
|
|
16
15
|
|
|
17
16
|
- name: Setup Bun
|
|
18
17
|
uses: oven-sh/setup-bun@v1
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
- name: Install Dependencies
|
|
21
20
|
run: bun install
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
- name: Build Tests
|
|
24
23
|
run: bun run pretest
|
|
25
24
|
|
|
26
25
|
- name: Run Tests
|
|
27
|
-
run: bun run test
|
|
26
|
+
run: bun run test
|
|
@@ -11,7 +11,7 @@ jobs:
|
|
|
11
11
|
- uses: actions/checkout@v4
|
|
12
12
|
- uses: actions/setup-node@v3
|
|
13
13
|
with:
|
|
14
|
-
node-version: 16
|
|
14
|
+
node-version: 16
|
|
15
15
|
|
|
16
16
|
- name: Install Wasmtime
|
|
17
17
|
uses: jcbhmr/setup-wasmtime@v2
|
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
- name: Install dependencies
|
|
23
23
|
if: steps.node-cache.outputs.cache-hit != 'true'
|
|
24
24
|
run: yarn
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
- name: Build tests
|
|
27
27
|
run: yarn run tests:build
|
|
28
28
|
|
package/CHANGELOG
CHANGED
|
@@ -25,6 +25,8 @@ v0.9.14 - Ignore properties of type Function
|
|
|
25
25
|
v0.9.15 - Support JSON.Raw blocks
|
|
26
26
|
v0.9.16 - JSON.Raw should be completely untouched
|
|
27
27
|
v0.9.17 - A schema's parent's fields should be included properly
|
|
28
|
+
v0.9.18 - Should be able to use @alias and @omit*** or JSON.Raw
|
|
29
|
+
v0.9.19 - Fix arguments in @omitif declarations not working properly
|
|
28
30
|
|
|
29
31
|
[UNRELEASED] v1.0.0
|
|
30
32
|
- Allow nullable primitives
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
__| || __|| || | | ___ | _ || __|
|
|
4
4
|
| | ||__ || | || | | ||___|| ||__ |
|
|
5
5
|
|_____||_____||_____||_|___| |__|__||_____|
|
|
6
|
-
v0.9.
|
|
6
|
+
v0.9.19
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -118,51 +118,13 @@ const serialized = JSON.stringify(arr);
|
|
|
118
118
|
const parsed = JSON.parse<Base[]>(serialized);
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
It also supports arbitrary-length integers with [@hypercubed/as-mpz](https://github.com/Hypercubed/as-mpz)
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
import { MpZ } from "@hypercubed/as-mpz";
|
|
125
|
-
|
|
126
|
-
const a = MpZ.from(18448972);
|
|
127
|
-
const b = MpZ.from('7881297289452930');
|
|
128
|
-
const c = a.add(b);
|
|
129
|
-
|
|
130
|
-
const serialized = JSON.stringify(c);
|
|
131
|
-
// 7881297307901902
|
|
132
|
-
const parsed = JSON.parse<MpZ>(serialized);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
It also supports nullable primitive types, something that AssemblyScript usually can't do
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
@json
|
|
139
|
-
class Vec2 {
|
|
140
|
-
x: f64 | null = 1.0;
|
|
141
|
-
y: f32 | null = 2.0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const vec: Vec2 = {
|
|
145
|
-
x: 1.0,
|
|
146
|
-
y: null
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
vec.y = 2.0;
|
|
150
|
-
|
|
151
|
-
if (vec.y) {
|
|
152
|
-
// do something
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
NOTE: There are a few quirks to using nullable primitives. First, you'll get a warning about usize (ignore it, its fine) and secondly, you'll get a wasm validation error if you do not have a `!` operator after accessing an element. Eg. `console.log(vec.y.toString())` fails, but `console.log(vec.y!.toString())` works.
|
|
157
|
-
|
|
158
121
|
You can also add it to your `asconfig.json`
|
|
159
122
|
|
|
160
123
|
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
124
|
+
// ...
|
|
125
|
+
"options": {
|
|
126
|
+
"transform": ["json-as/transform"]
|
|
127
|
+
}
|
|
166
128
|
}
|
|
167
129
|
|
|
168
130
|
If you use this project in your codebase, consider dropping a [star](https://github.com/JairusSW/as-json). I would really appreciate it!
|
|
@@ -185,41 +147,39 @@ Run or view the benchmarks [here](https://github.com/JairusSW/as-json/tree/maste
|
|
|
185
147
|
|
|
186
148
|
Below are benchmark results comparing JavaScript's built-in JSON implementation and `JSON-AS`
|
|
187
149
|
|
|
188
|
-
My library beats JSON (written in C++) on all counts
|
|
150
|
+
My library beats JSON (written in C++) on all counts _and_, I see many places where I can pull at least a 60% uplift in performance if I implement it.
|
|
189
151
|
|
|
190
152
|
Note: SIMD is in-development and only available on the `v1` branch on GitHub
|
|
191
153
|
|
|
192
154
|
Serialization Benchmarks:
|
|
193
155
|
|
|
194
|
-
| Value | JavaScript (ops/s) | JSON-AS (ops/s) | JSON-AS (Pages) | JSON-AS (SIMD+Pages)| Max Throughput |
|
|
195
|
-
|
|
196
|
-
| "hello world" | 7,124,361 | 44,290,480 (6.2x) | 73,601,235 (10.3x) | NOT IMPLEMENTED
|
|
197
|
-
| 12345 | 9,611,677 | 66,900,642 (6.9x) | 145,924,333 (15.2x) | NOT IMPLEMENTED
|
|
198
|
-
| 1.2345 | 7,227,259 | 20,322,939 (2.8x) | NOT IMPLEMENTED | NOT IMPLEMENTED
|
|
199
|
-
| [[],[[]],[[],[[]]]] | 5,655,429 | 34,453,102 (6.0x) | NOT IMPLEMENTED | NOT IMPLEMENTED
|
|
200
|
-
| { x: f64, y: f64, z: f64 } | 3,878,604 | 44,557,996 (11.5x) | 113,203,242 (29.2x) | 172,023,231 (44.4x)
|
|
201
|
-
|
|
202
|
-
|
|
156
|
+
| Value | JavaScript (ops/s) | JSON-AS (ops/s) | JSON-AS (Pages) | JSON-AS (SIMD+Pages) | Max Throughput |
|
|
157
|
+
| -------------------------- | ------------------ | ------------------ | ------------------- | -------------------- | -------------- |
|
|
158
|
+
| "hello world" | 7,124,361 | 44,290,480 (6.2x) | 73,601,235 (10.3x) | NOT IMPLEMENTED | 1.91 GB/s |
|
|
159
|
+
| 12345 | 9,611,677 | 66,900,642 (6.9x) | 145,924,333 (15.2x) | NOT IMPLEMENTED | 0.58 GB/s |
|
|
160
|
+
| 1.2345 | 7,227,259 | 20,322,939 (2.8x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 0.16 GB/s |
|
|
161
|
+
| [[],[[]],[[],[[]]]] | 5,655,429 | 34,453,102 (6.0x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 1.32 GB/s |
|
|
162
|
+
| { x: f64, y: f64, z: f64 } | 3,878,604 | 44,557,996 (11.5x) | 113,203,242 (29.2x) | 172,023,231 (44.4x) | 8.61 GB/s |
|
|
203
163
|
|
|
204
164
|
Deserialization Benchmarks:
|
|
205
165
|
|
|
206
|
-
| Value | JavaScript (ops/s) | JSON-AS (ops/s) | Difference|
|
|
207
|
-
|
|
208
|
-
| "hello world" | 12,210,131 | 24,274,496 | + 98%
|
|
209
|
-
| "12345" | 21,376,873 | 254,640,930 | + 1,191%
|
|
210
|
-
| 1.2345 | 23,193,902 | 221,869,840 | + 987%
|
|
211
|
-
| [[],[[]],[[],[[]]]] | 4,777,227 | 74,921,123 | + 1,568%
|
|
212
|
-
| { x: f64, y: f64, z: f64 } | 10,973,723 | 25,214,019 | + 230%
|
|
166
|
+
| Value | JavaScript (ops/s) | JSON-AS (ops/s) | Difference |
|
|
167
|
+
| -------------------------- | ------------------ | --------------- | ---------- |
|
|
168
|
+
| "hello world" | 12,210,131 | 24,274,496 | + 98% |
|
|
169
|
+
| "12345" | 21,376,873 | 254,640,930 | + 1,191% |
|
|
170
|
+
| 1.2345 | 23,193,902 | 221,869,840 | + 987% |
|
|
171
|
+
| [[],[[]],[[],[[]]]] | 4,777,227 | 74,921,123 | + 1,568% |
|
|
172
|
+
| { x: f64, y: f64, z: f64 } | 10,973,723 | 25,214,019 | + 230% |
|
|
213
173
|
|
|
214
174
|
And my PC specs:
|
|
215
175
|
|
|
216
|
-
| Component
|
|
217
|
-
|
|
218
|
-
| Wasmer Version
|
|
219
|
-
| CPU
|
|
220
|
-
| Memory
|
|
221
|
-
| OS
|
|
176
|
+
| Component | Specification |
|
|
177
|
+
| -------------- | ------------------------------ |
|
|
178
|
+
| Wasmer Version | v4.3.0 |
|
|
179
|
+
| CPU | AMD Ryzen 7 7800x3D @ 6.00 GHz |
|
|
180
|
+
| Memory | T-Force DDR5 6000 MHz |
|
|
181
|
+
| OS | Ubuntu WSL2 |
|
|
222
182
|
|
|
223
183
|
## Issues
|
|
224
184
|
|
|
225
|
-
Please submit an issue to https://github.com/JairusSW/as-json/issues if you find anything wrong with this library
|
|
185
|
+
Please submit an issue to https://github.com/JairusSW/as-json/issues if you find anything wrong with this library
|
package/as-test.config.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"input": [
|
|
3
|
-
"./assembly/__tests__/*.spec.ts"
|
|
4
|
-
],
|
|
2
|
+
"input": ["./assembly/__tests__/*.spec.ts"],
|
|
5
3
|
"outDir": "./build",
|
|
6
4
|
"config": "none",
|
|
7
5
|
"plugins": {
|
|
8
6
|
"coverage": false
|
|
9
7
|
},
|
|
10
8
|
"buildOptions": {
|
|
11
|
-
"args": [],
|
|
9
|
+
"args": ["--transform ./transform"],
|
|
12
10
|
"target": "wasi"
|
|
13
11
|
},
|
|
14
12
|
"runOptions": {
|
|
@@ -17,4 +15,4 @@
|
|
|
17
15
|
"run": "wasmtime <file>"
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
}
|
|
18
|
+
}
|