json-as 0.9.9-a → 0.9.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.
@@ -16,7 +16,7 @@ jobs:
16
16
 
17
17
  - name: Setup Bun
18
18
  uses: oven-sh/setup-bun@v1
19
-
19
+
20
20
  - name: Install Dependencies
21
21
  run: bun install
22
22
 
package/CHANGELOG CHANGED
@@ -17,6 +17,7 @@ v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory
17
17
  v0.9.8b - Fix #81 - Revert transform
18
18
  v0.9.9 - Fix #82 - Initialize maps
19
19
  v0.9.9a - Remove extraneous logs from transform
20
+ v0.9.10 - Fix transform type checks. switch to nodekind checks
20
21
 
21
22
  [UNRELEASED] v1.0.0
22
23
  - Allow nullable primitives
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  __| || __|| || | | ___ | _ || __|
4
4
  | | ||__ || | || | | ||___|| ||__ |
5
5
  |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.9a
6
+ v0.9.10
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -559,6 +559,5 @@ describe("Should deserialize Objects", () => {
559
559
  });
560
560
 
561
561
  run({
562
- log: true,
563
- coverage: true
562
+ log: true
564
563
  });
package/assembly/test.ts CHANGED
@@ -1,78 +1,38 @@
1
- import { JSON } from "json-as/assembly";
2
-
1
+ import { JSON } from ".";
3
2
  @json
4
- class TokenMetaData {
5
- id: u64;
6
- name: string;
7
- uri: string;
8
-
9
- constructor(id: u64, name: string, uri: string) {
10
- this.id = id;
11
- this.name = name;
12
- this.uri = uri;
13
- }
3
+ class Vec3 {
4
+ x: f32 = 0.0;
5
+ y: f32 = 0.0;
6
+ z: f32 = 0.0;
14
7
  }
15
8
 
16
9
  @json
17
- class NonFungibleToken {
18
- owner: string = "";
19
- counter: u64 = 0;
20
- tokens: Map<u64, TokenMetaData> = new Map<u64, TokenMetaData>();
21
- owners: Map<u64, string> = new Map<u64, string>();
22
- balances: Map<string, u64[]> = new Map<string, u64[]>();
23
-
24
- constructor() { }
25
-
26
- mint(name: string, uri: string, toAddress: string): u64 {
27
- this.counter += 1;
28
- const id = this.counter;
29
-
30
- const tokenMetaData = new TokenMetaData(id, name, uri);
31
-
32
- this.tokens.set(id, tokenMetaData);
33
- this.owners.set(id, toAddress);
34
-
35
- if (!this.balances.has(toAddress)) {
36
- this.balances.set(toAddress, []);
37
- }
38
-
39
- this.balances.get(toAddress).push(id);
40
-
41
- return id;
42
- }
10
+ class Player {
11
+ @alias("first name")
12
+ firstName!: string;
13
+ lastName!: string;
14
+ lastActive!: i32[];
15
+ // Drop in a code block, function, or expression that evaluates to a boolean
16
+ @omitif("this.age < 18")
17
+ age!: i32;
18
+ @omitnull()
19
+ pos!: Vec3 | null;
20
+ isVerified!: boolean;
43
21
  }
44
- function readStringFromMemory(ptr: usize): string {
45
- let len: i32 = load<u32>(ptr)
46
- let buffer = new Uint8Array(len);
47
-
48
- for (let i = 0; i < len; ++i) {
49
- buffer[i] = load<u8>(ptr + 4 + i);
50
- }
51
-
52
- let s = String.UTF8.decode(buffer.buffer);
53
- return s
54
- }
55
-
56
- function getLengthPrefixedString(s: string): ArrayBuffer {
57
- let stringBuf = Uint8Array.wrap(String.UTF8.encode(s))
58
- let newLen = stringBuf.byteLength
59
- let buffer = new ArrayBuffer(4 + newLen);
60
- let dataView = new DataView(buffer);
61
-
62
- dataView.setUint32(0, newLen, true);
63
-
64
- for (let i = 0; i < newLen; ++i) {
65
- dataView.setInt8(4 + i, stringBuf[i])
66
- }
67
-
68
- return buffer
69
- }
70
-
71
- const s1 = getLengthPrefixedString("hello world");
72
- console.log(Uint8Array.wrap(s1).join(" "));
73
- const s2 = readStringFromMemory(changetype<usize>(s1));
74
- console.log(s2);
75
22
 
76
- let state = JSON.parse<NonFungibleToken>('{"owner":"","counter":1,"tokens":{"1":{"id":1,"name":"foo","uri":"bar"}},"owners":{"1":"baz"},"balances":{"baz":[1]}}');
77
- state.mint("foo", "bar", "baz")
78
- console.log(JSON.stringify(state))
23
+ const player: Player = {
24
+ firstName: "Emmet",
25
+ lastName: "West",
26
+ lastActive: [8, 27, 2022],
27
+ age: 23,
28
+ pos: {
29
+ x: 3.4,
30
+ y: 1.2,
31
+ z: 8.3
32
+ },
33
+ isVerified: true
34
+ };
35
+
36
+ const stringified = JSON.stringify<Player>(player);
37
+
38
+ const parsed = JSON.parse<Player>(stringified);
Binary file