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.
- package/.github/workflows/nodejs.yml +1 -1
- package/CHANGELOG +1 -0
- package/README.md +1 -1
- package/assembly/__tests__/test.spec.ts +1 -2
- package/assembly/test.ts +32 -72
- package/build/test.spec.wasm +0 -0
- package/build/test.spec.wasm.map +1 -1
- package/build/test.spec.wat +3488 -8664
- package/build/test.wasm +0 -0
- package/build/test.wasm.map +1 -1
- package/build/test.wat +7452 -23148
- package/package.json +3 -5
- package/transform/lib/index.js +1 -4
- package/transform/package.json +1 -1
- package/transform/src/index.ts +3 -4
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
package/assembly/test.ts
CHANGED
|
@@ -1,78 +1,38 @@
|
|
|
1
|
-
import { JSON } from "
|
|
2
|
-
|
|
1
|
+
import { JSON } from ".";
|
|
3
2
|
@json
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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);
|
package/build/test.spec.wasm
CHANGED
|
Binary file
|