json-as 0.9.7 → 0.9.8-a

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 +52 -7
  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 -33
  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 +79 -45
  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 +114980 -0
  42. package/build/test.wasm +0 -0
  43. package/build/test.wasm.map +1 -0
  44. package/build/test.wat +10948 -0
  45. package/package.json +12 -14
  46. package/transform/lib/index.js +256 -21
  47. package/transform/lib/visitor.js +516 -0
  48. package/transform/package.json +1 -1
  49. package/transform/src/index.ts +360 -25
  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
@@ -12,5 +12,13 @@ v0.9.4 - Fix #77
12
12
  v0.9.5 - Fix #46
13
13
  v0.9.6 - Fix bugs
14
14
  v0.9.7 - Update testing framework and readme logo
15
-
16
- [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.
15
+ v0.9.8 - Update dependencies
16
+ v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory out of bounds
17
+ [UNRELEASED] v0.9.9
18
+ - Allow nullable primitives
19
+ - Port over JSON.Value
20
+ - Performance improvements
21
+ - Introduce options
22
+ - Custom serializers
23
+ - Support arbitrary-length integers (@hypercubed/as-mpz)
24
+ - Remove as-container (Box<T>)
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  <h5 align="center">
2
- <pre>
3
- _____ _____ __ _____ _____ _____
4
- | _ | __|___ __| | __| | | |
5
- | |__ |___| | |__ | | | | | |
6
- |__|__|_____| |_____|_____|_____|_|___|
7
-
8
- v0.9.7
2
+ <pre> __ _____ _____ _____ _____ _____
3
+ __| || __|| || | | ___ | _ || __|
4
+ | | ||__ || | || | | ||___|| ||__ |
5
+ |_____||_____||_____||_|___| |__|__||_____|
6
+ v0.9.8a
9
7
  </pre>
10
8
  </h5>
11
9
 
@@ -120,6 +118,53 @@ const serialized = JSON.stringify(arr);
120
118
  const parsed = JSON.parse<Base[]>(serialized);
121
119
  ```
122
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
+
123
168
  If you use this project in your codebase, consider dropping a [star](https://github.com/JairusSW/as-json). I would really appreciate it!
124
169
 
125
170
  ## Notes
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
  }