json-as 0.9.8 → 0.9.9

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.
Files changed (63) hide show
  1. package/.github/workflows/nodejs.yml +9 -10
  2. package/CHANGELOG +10 -2
  3. package/README.md +55 -8
  4. package/asconfig.json +24 -3
  5. package/assembly/__tests__/test.spec.ts +564 -0
  6. package/assembly/__tests__/types.ts +82 -0
  7. package/assembly/{src/chars.ts → chars.ts} +36 -36
  8. package/assembly/deserialize/array/array.ts +4 -4
  9. package/assembly/deserialize/array/bool.ts +4 -4
  10. package/assembly/deserialize/array/float.ts +4 -4
  11. package/assembly/deserialize/array/integer.ts +4 -4
  12. package/assembly/deserialize/array/map.ts +4 -4
  13. package/assembly/deserialize/array/object.ts +4 -4
  14. package/assembly/deserialize/array/string.ts +4 -4
  15. package/assembly/deserialize/array.ts +5 -4
  16. package/assembly/deserialize/bool.ts +4 -4
  17. package/assembly/deserialize/date.ts +2 -2
  18. package/assembly/deserialize/float.ts +2 -2
  19. package/assembly/deserialize/integer.ts +3 -3
  20. package/assembly/deserialize/map.ts +4 -4
  21. package/assembly/deserialize/mpz.ts +12 -0
  22. package/assembly/deserialize/object.ts +4 -4
  23. package/assembly/deserialize/string.ts +5 -5
  24. package/assembly/index.ts +25 -23
  25. package/assembly/serialize/array.ts +6 -5
  26. package/assembly/serialize/bool.ts +2 -2
  27. package/assembly/serialize/date.ts +2 -2
  28. package/assembly/serialize/float.ts +2 -2
  29. package/assembly/serialize/integer.ts +2 -2
  30. package/assembly/serialize/map.ts +8 -7
  31. package/assembly/serialize/mpz.ts +6 -0
  32. package/assembly/serialize/object.ts +2 -2
  33. package/assembly/serialize/string.ts +5 -5
  34. package/assembly/serialize/unknown.ts +5 -5
  35. package/assembly/test.ts +30 -40
  36. package/assembly/types.ts +4 -0
  37. package/assembly/{src/util.ts → util.ts} +3 -3
  38. package/bench/benchmark.ts +1 -1
  39. package/build/test.spec.wasm +0 -0
  40. package/build/test.spec.wasm.map +1 -0
  41. package/build/test.spec.wat +112683 -0
  42. package/build/test.wasm +0 -0
  43. package/build/test.wasm.map +1 -0
  44. package/build/test.wat +24968 -0
  45. package/package.json +11 -12
  46. package/transform/lib/index.js +12 -0
  47. package/transform/lib/visitor.js +516 -0
  48. package/transform/package.json +1 -1
  49. package/transform/src/index.ts +8 -0
  50. package/transform/src/visitor.ts +543 -0
  51. package/transform/tsconfig.json +23 -63
  52. package/tsconfig.json +13 -13
  53. package/as-pect.asconfig.json +0 -24
  54. package/as-pect.config.js +0 -30
  55. package/assembly/__tests__/deserialize.spec.ts +0 -301
  56. package/assembly/__tests__/serialize.spec.ts +0 -398
  57. package/assembly/deserialize/box.ts +0 -17
  58. package/assembly/serialize/box.ts +0 -11
  59. package/develop/assembly/serialize/unknown.ts +0 -46
  60. package/transform/lib/index.old.js +0 -257
  61. package/transform/lib/types.js +0 -17
  62. package/transform/src/index.old.ts +0 -312
  63. /package/assembly/{src/sink.ts → sink.ts} +0 -0
@@ -1,4 +1,4 @@
1
- name: Node.js CI
1
+ name: Bun/Wasmtime CI
2
2
 
3
3
  on: [push, pull_request]
4
4
 
@@ -14,15 +14,14 @@ jobs:
14
14
  - name: Install Wasmtime
15
15
  uses: jcbhmr/setup-wasmtime@v2
16
16
 
17
- - name: Setup Node.js
18
- uses: actions/setup-node@v2
17
+ - name: Setup Bun
18
+ uses: oven-sh/setup-bun@v1
19
19
 
20
- - name: Install dependencies
21
- if: steps.node-cache.outputs.cache-hit != 'true'
22
- run: yarn
20
+ - name: Install Dependencies
21
+ run: bun install
23
22
 
24
- - name: Build tests
25
- run: yarn run tests:build
23
+ - name: Build Tests
24
+ run: bun run pretest
26
25
 
27
- - name: Perform tests
28
- run: yarn run test
26
+ - name: Run Tests
27
+ run: bun run test
package/CHANGELOG CHANGED
@@ -13,5 +13,13 @@ v0.9.5 - Fix #46
13
13
  v0.9.6 - Fix bugs
14
14
  v0.9.7 - Update testing framework and readme logo
15
15
  v0.9.8 - Update dependencies
16
-
17
- [UNRELEASED] v0.9.x - Port JSON.Value from the `develop` branch to allow for union types, parsing of arbitrary data, and whatever the hell you want.
16
+ v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory out of bounds
17
+ v0.9.8b - Fix #81 - Revert transform
18
+ [UNRELEASED] v0.9.9
19
+ - Allow nullable primitives
20
+ - Port over JSON.Value
21
+ - Performance improvements
22
+ - Introduce options
23
+ - Custom serializers
24
+ - Support arbitrary-length integers (@hypercubed/as-mpz)
25
+ - Remove as-container (Box<T>)
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  __| || __|| || | | ___ | _ || __|
4
4
  | | ||__ || | || | | ||___|| ||__ |
5
5
  |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.8
6
+ v0.9.9
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -118,6 +118,53 @@ 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
+ You can also add it to your `asconfig.json`
159
+
160
+ {
161
+ // ...
162
+ "options": {
163
+ "transform": ["json-as/transform"],
164
+ "disableWarning": [226]
165
+ }
166
+ }
167
+
121
168
  If you use this project in your codebase, consider dropping a [star](https://github.com/JairusSW/as-json). I would really appreciate it!
122
169
 
123
170
  ## Notes
@@ -143,13 +190,13 @@ My library beats JSON (written in C++) on all counts *and*, I see many places wh
143
190
 
144
191
  Serialization Benchmarks:
145
192
 
146
- | Value | JavaScript (ops/s) | JSON-as (ops/s) | Difference |
147
- |----------------------------|--------------------|-----------------|------------|
148
- | "hello world" | 28,629,598 | 64,210,666 | + 124% |
149
- | 12345 | 31,562,431 | 56,329,066 | + 78% |
150
- | 1.2345 | 15,977,278 | 20,322,939 | + 27% |
151
- | [[],[[]],[[],[[]]]] | 8,998,624 | 34,453,102 | + 283% |
152
- | { x: f64, y: f64, z: f64 } | 15,583,686 | 17,604,821 | + 12% |
193
+ | Value | JavaScript (ops/s) | JSON-AS (ops/s) | JSON-AS (Pages) | JSON-AS (SIMD+Pages)| Max Throughput |
194
+ |----------------------------|--------------------|--------------------|---------------------|---------------------|----------------|
195
+ | "hello world" | 7,124,361 | 44,290,480 (6.2x) | 73,601,235 (10.3x) | NOT IMPLEMENTED | 1.91 GB/s |
196
+ | 12345 | 9,611,677 | 66,900,642 (6.9x) | 145,924,333 (15.2x) | NOT IMPLEMENTED | 0.58 GB/s |
197
+ | 1.2345 | 7,227,259 | 20,322,939 (2.8x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 0.16 GB/s |
198
+ | [[],[[]],[[],[[]]]] | 5,655,429 | 34,453,102 (6.0x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 1.32 GB/s |
199
+ | { 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 |
153
200
 
154
201
 
155
202
 
package/asconfig.json CHANGED
@@ -1,15 +1,36 @@
1
1
  {
2
2
  "targets": {
3
3
  "test": {
4
+ "outFile": "build/test.spec.wasm",
5
+ "textFile": "build/test.spec.wat",
6
+ "sourceMap": true,
7
+ "optimizeLevel": 0,
8
+ "shrinkLevel": 0,
9
+ "converge": false,
10
+ "noAssert": false
11
+ },
12
+ "debug": {
4
13
  "outFile": "build/test.wasm",
5
- "sourceMap": false,
14
+ "textFile": "build/test.wat",
15
+ "sourceMap": true,
6
16
  "optimizeLevel": 0,
7
17
  "shrinkLevel": 0,
8
18
  "converge": false,
9
19
  "noAssert": false
20
+ },
21
+ "bench": {
22
+ "outFile": "build/bench.wasm",
23
+ "textFile": "build/bench.wat",
24
+ "sourceMap": true,
25
+ "optimizeLevel": 3,
26
+ "shrinkLevel": 0,
27
+ "converge": true,
28
+ "noAssert": true
10
29
  }
11
30
  },
12
31
  "options": {
13
- "transform": ["./transform"]
14
- }
32
+ "transform": ["./transform", "as-test/transform"],
33
+ "disableWarning": [226]
34
+ },
35
+ "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
15
36
  }