json-as 1.1.1 → 1.1.3
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/tests.yml +3 -1
- package/.prettierignore +4 -1
- package/CHANGELOG.md +11 -1
- package/README.md +1 -1
- package/assembly/__tests__/array.spec.ts +156 -90
- package/assembly/__tests__/hierarchy.spec.ts +10 -4
- package/assembly/deserialize/simple/arbitrary.ts +1 -1
- package/assembly/index.ts +2 -3
- package/assembly/test.ts +49 -3
- package/index.ts +26 -1
- package/package.json +3 -2
- package/transform/lib/index.js +154 -113
- package/transform/lib/index.js.map +1 -1
- package/transform/src/index.ts +167 -115
|
@@ -11,7 +11,9 @@ jobs:
|
|
|
11
11
|
uses: actions/checkout@v4
|
|
12
12
|
|
|
13
13
|
- name: Install Wasmtime
|
|
14
|
-
|
|
14
|
+
run: |
|
|
15
|
+
curl https://wasmtime.dev/install.sh -sSf | bash
|
|
16
|
+
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
|
|
15
17
|
|
|
16
18
|
- name: Setup Bun
|
|
17
19
|
uses: oven-sh/setup-bun@v1
|
package/.prettierignore
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2025-05-23 - 1.1.3
|
|
4
|
+
|
|
5
|
+
- feat: group properties of structs before code generation
|
|
6
|
+
- fix: break out of switch case after completion
|
|
7
|
+
- ci: make compatible with act for local testing
|
|
8
|
+
|
|
9
|
+
## 2025-05-22 - 1.1.2
|
|
10
|
+
|
|
11
|
+
- fix: correct small typos in string value deserialization port
|
|
12
|
+
|
|
3
13
|
## 2025-05-22 - 1.1.1
|
|
4
14
|
|
|
5
15
|
- fix: remove random logs
|
|
6
16
|
|
|
7
17
|
## 2025-05-22 - 1.1.0
|
|
8
18
|
|
|
9
|
-
- fix: change
|
|
19
|
+
- fix: change _DESERIALIZE<T> to _JSON_T to avoid populating local scope
|
|
10
20
|
|
|
11
21
|
## 2025-05-22 - 1.0.9
|
|
12
22
|
|
package/README.md
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
1
|
import { JSON } from "..";
|
|
2
2
|
import { describe, expect } from "./lib";
|
|
3
3
|
|
|
4
|
-
describe("Should serialize integer arrays", () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("Should serialize float arrays", () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("Should serialize boolean arrays", () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("Should serialize string arrays", () => {
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("Should serialize nested integer arrays", () => {
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("Should serialize nested float arrays", () => {
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("Should serialize nested boolean arrays", () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("Should serialize object arrays", () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe("Should deserialize integer arrays", () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe("Should deserialize float arrays", () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("Should deserialize boolean arrays", () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("Should deserialize string arrays", () => {
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("Should deserialize nested integer arrays", () => {
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe("Should deserialize nested float arrays", () => {
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe("Should deserialize nested boolean arrays", () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
4
|
+
// describe("Should serialize integer arrays", () => {
|
|
5
|
+
// expect(JSON.stringify<u32[]>([0, 100, 101])).toBe("[0,100,101]");
|
|
6
|
+
|
|
7
|
+
// expect(JSON.stringify<u64[]>([0, 100, 101])).toBe("[0,100,101]");
|
|
8
|
+
|
|
9
|
+
// expect(JSON.stringify<i32[]>([0, 100, 101, -100, -101])).toBe("[0,100,101,-100,-101]");
|
|
10
|
+
|
|
11
|
+
// expect(JSON.stringify<i64[]>([0, 100, 101, -100, -101])).toBe("[0,100,101,-100,-101]");
|
|
12
|
+
// });
|
|
13
|
+
|
|
14
|
+
// describe("Should serialize float arrays", () => {
|
|
15
|
+
// expect(JSON.stringify<f64[]>([7.23, 10e2, 10e2, 123456e-5, 123456e-5, 0.0, 7.23])).toBe("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]");
|
|
16
|
+
|
|
17
|
+
// expect(JSON.stringify<f64[]>([1e21, 1e22, 1e-7, 1e-8, 1e-9])).toBe("[1e+21,1e+22,1e-7,1e-8,1e-9]");
|
|
18
|
+
// });
|
|
19
|
+
|
|
20
|
+
// describe("Should serialize boolean arrays", () => {
|
|
21
|
+
// expect(JSON.stringify<bool[]>([true, false])).toBe("[true,false]");
|
|
22
|
+
|
|
23
|
+
// expect(JSON.stringify<boolean[]>([true, false])).toBe("[true,false]");
|
|
24
|
+
// });
|
|
25
|
+
|
|
26
|
+
// describe("Should serialize string arrays", () => {
|
|
27
|
+
// expect(JSON.stringify<string[]>(['string "with random spa\nces and \nnewlines\n\n\n'])).toBe('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]');
|
|
28
|
+
// });
|
|
29
|
+
|
|
30
|
+
// describe("Should serialize nested integer arrays", () => {
|
|
31
|
+
// expect(JSON.stringify<i64[][]>([[100, 101], [-100, -101], [0]])).toBe("[[100,101],[-100,-101],[0]]");
|
|
32
|
+
// });
|
|
33
|
+
|
|
34
|
+
// describe("Should serialize nested float arrays", () => {
|
|
35
|
+
// expect(JSON.stringify<f64[][]>([[7.23], [10e2], [10e2], [123456e-5], [123456e-5], [0.0], [7.23]])).toBe("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]");
|
|
36
|
+
// });
|
|
37
|
+
|
|
38
|
+
// describe("Should serialize nested boolean arrays", () => {
|
|
39
|
+
// expect(JSON.stringify<bool[][]>([[true], [false]])).toBe("[[true],[false]]");
|
|
40
|
+
|
|
41
|
+
// expect(JSON.stringify<boolean[][]>([[true], [false]])).toBe("[[true],[false]]");
|
|
42
|
+
// });
|
|
43
|
+
|
|
44
|
+
// describe("Should serialize object arrays", () => {
|
|
45
|
+
// expect(
|
|
46
|
+
// JSON.stringify<Vec3[]>([
|
|
47
|
+
// {
|
|
48
|
+
// x: 3.4,
|
|
49
|
+
// y: 1.2,
|
|
50
|
+
// z: 8.3,
|
|
51
|
+
// },
|
|
52
|
+
// {
|
|
53
|
+
// x: 3.4,
|
|
54
|
+
// y: -2.1,
|
|
55
|
+
// z: 9.3,
|
|
56
|
+
// },
|
|
57
|
+
// ]),
|
|
58
|
+
// ).toBe('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]');
|
|
59
|
+
// });
|
|
60
|
+
|
|
61
|
+
// describe("Should deserialize integer arrays", () => {
|
|
62
|
+
// expect(JSON.stringify(JSON.parse<u32[]>("[0,100,101]"))).toBe("[0,100,101]");
|
|
63
|
+
// expect(JSON.stringify(JSON.parse<u64[]>("[0,100,101]"))).toBe("[0,100,101]");
|
|
64
|
+
// expect(JSON.stringify(JSON.parse<i32[]>("[0,100,101,-100,-101]"))).toBe("[0,100,101,-100,-101]");
|
|
65
|
+
// expect(JSON.stringify(JSON.parse<i64[]>("[0,100,101,-100,-101]"))).toBe("[0,100,101,-100,-101]");
|
|
66
|
+
// });
|
|
67
|
+
|
|
68
|
+
// describe("Should deserialize float arrays", () => {
|
|
69
|
+
// expect(JSON.stringify(JSON.parse<f64[]>("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]"))).toBe("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]");
|
|
70
|
+
// expect(JSON.stringify(JSON.parse<f64[]>("[1e+21,1e+22,1e-7,1e-8,1e-9]"))).toBe("[1e+21,1e+22,1e-7,1e-8,1e-9]");
|
|
71
|
+
// });
|
|
72
|
+
|
|
73
|
+
// describe("Should deserialize boolean arrays", () => {
|
|
74
|
+
// expect(JSON.stringify(JSON.parse<bool[]>("[true,false]"))).toBe("[true,false]");
|
|
75
|
+
// expect(JSON.stringify(JSON.parse<boolean[]>("[true,false]"))).toBe("[true,false]");
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
// describe("Should deserialize string arrays", () => {
|
|
79
|
+
// expect(JSON.stringify(JSON.parse<string[]>('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]'))).toBe('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]');
|
|
80
|
+
// });
|
|
81
|
+
|
|
82
|
+
// describe("Should deserialize nested integer arrays", () => {
|
|
83
|
+
// expect(JSON.stringify(JSON.parse<i64[][]>("[[100,101],[-100,-101],[0]]"))).toBe("[[100,101],[-100,-101],[0]]");
|
|
84
|
+
// });
|
|
85
|
+
|
|
86
|
+
// describe("Should deserialize nested float arrays", () => {
|
|
87
|
+
// expect(JSON.stringify(JSON.parse<f64[][]>("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]"))).toBe("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]");
|
|
88
|
+
// });
|
|
89
|
+
|
|
90
|
+
// describe("Should deserialize nested boolean arrays", () => {
|
|
91
|
+
// expect(JSON.stringify(JSON.parse<bool[][]>("[[true],[false]]"))).toBe("[[true],[false]]");
|
|
92
|
+
// expect(JSON.stringify(JSON.parse<boolean[][]>("[[true],[false]]"))).toBe("[[true],[false]]");
|
|
93
|
+
// });
|
|
94
94
|
|
|
95
95
|
describe("Should deserialize object arrays", () => {
|
|
96
96
|
expect(JSON.stringify(JSON.parse<Vec3[]>('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]'))).toBe('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]');
|
|
@@ -102,4 +102,70 @@ class Vec3 {
|
|
|
102
102
|
x: f64 = 0.0;
|
|
103
103
|
y: f64 = 0.0;
|
|
104
104
|
z: f64 = 0.0;
|
|
105
|
+
__DESERIALIZE<__JSON_T>(srcStart: usize, srcEnd: usize, out: __JSON_T): __JSON_T {
|
|
106
|
+
let keyStart: usize = 0;
|
|
107
|
+
let keyEnd: usize = 0;
|
|
108
|
+
let isKey = false;
|
|
109
|
+
let lastIndex: usize = 0;
|
|
110
|
+
|
|
111
|
+
while (srcStart < srcEnd && JSON.Util.isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
112
|
+
while (srcEnd > srcStart && JSON.Util.isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
|
|
113
|
+
if (srcStart - srcEnd == 0) throw new Error("Input string had zero length or was all whitespace");
|
|
114
|
+
if (load<u16>(srcStart) != 123) throw new Error("Expected '{' at start of object at position " + (srcEnd - srcStart).toString());
|
|
115
|
+
if (load<u16>(srcEnd - 2) != 125) throw new Error("Expected '}' at end of object at position " + (srcEnd - srcStart).toString());
|
|
116
|
+
srcStart += 2;
|
|
117
|
+
|
|
118
|
+
while (srcStart < srcEnd) {
|
|
119
|
+
let code = load<u16>(srcStart);
|
|
120
|
+
while (JSON.Util.isSpace(code)) code = load<u16>(srcStart += 2);
|
|
121
|
+
if (keyStart == 0) {
|
|
122
|
+
if (code == 34 && load<u16>(srcStart - 2) !== 92) {
|
|
123
|
+
if (isKey) {
|
|
124
|
+
keyStart = lastIndex;
|
|
125
|
+
keyEnd = srcStart;
|
|
126
|
+
while (JSON.Util.isSpace((code = load<u16>((srcStart += 2))))) { }
|
|
127
|
+
if (code !== 58) throw new Error("Expected ':' after key at position " + (srcEnd - srcStart).toString());
|
|
128
|
+
isKey = false;
|
|
129
|
+
} else {
|
|
130
|
+
isKey = true;
|
|
131
|
+
lastIndex = srcStart + 2;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
srcStart += 2;
|
|
135
|
+
} else {
|
|
136
|
+
if (code - 48 <= 9 || code == 45) {
|
|
137
|
+
lastIndex = srcStart;
|
|
138
|
+
srcStart += 2;
|
|
139
|
+
while (srcStart < srcEnd) {
|
|
140
|
+
const code = load<u16>(srcStart);
|
|
141
|
+
if (code == 44 || code == 125 || JSON.Util.isSpace(code)) {
|
|
142
|
+
switch (<u32>keyEnd - <u32>keyStart) {
|
|
143
|
+
case 2: {
|
|
144
|
+
const code16 = load<u16>(keyStart);
|
|
145
|
+
if (code16 == 120) { // x
|
|
146
|
+
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("x"));
|
|
147
|
+
keyStart = 0;
|
|
148
|
+
break;
|
|
149
|
+
} else if (code16 == 121) { // y
|
|
150
|
+
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("y"));
|
|
151
|
+
keyStart = 0;
|
|
152
|
+
break;
|
|
153
|
+
} else if (code16 == 122) { // z
|
|
154
|
+
store<f64>(changetype<usize>(out), JSON.__deserialize<f64>(lastIndex, srcStart), offsetof<this>("z"));
|
|
155
|
+
keyStart = 0;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
srcStart += 2;
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
srcStart += 2;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
105
171
|
}
|
|
@@ -2,26 +2,32 @@ import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
|
|
|
2
2
|
import { JSON } from "..";
|
|
3
3
|
import { describe, expect } from "./lib";
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
@json
|
|
6
7
|
class Foo {
|
|
7
8
|
a: i32 = 0;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
@json
|
|
11
13
|
class Bar extends Foo {
|
|
12
14
|
b: i32 = 0;
|
|
13
15
|
|
|
16
|
+
|
|
14
17
|
@serializer
|
|
15
18
|
serialize(self: Bar): string {
|
|
16
19
|
return `"bar"`;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
|
|
19
23
|
@deserializer
|
|
20
24
|
deserialize(data: string): Bar {
|
|
21
|
-
return data == "
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
return data == '"bar"'
|
|
26
|
+
? {
|
|
27
|
+
a: 1,
|
|
28
|
+
b: 2,
|
|
29
|
+
}
|
|
30
|
+
: new Bar();
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -15,7 +15,7 @@ export function deserializeArbitrary(srcStart: usize, srcEnd: usize, dst: usize)
|
|
|
15
15
|
return JSON.Value.from(deserializeArray<JSON.Value[]>(srcStart, srcEnd, 0));
|
|
16
16
|
} else if (firstChar == 116 || firstChar == 102) return JSON.Value.from(deserializeBoolean(srcStart, srcEnd));
|
|
17
17
|
else if (firstChar == CHAR_N) {
|
|
18
|
-
return JSON.Value.from(
|
|
18
|
+
return JSON.Value.from<usize>(0);
|
|
19
19
|
}
|
|
20
20
|
return unreachable();
|
|
21
21
|
}
|
package/assembly/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { serializeDate } from "./serialize/simple/date";
|
|
|
8
8
|
import { deserializeBoolean } from "./deserialize/simple/bool";
|
|
9
9
|
import { deserializeArray } from "./deserialize/simple/array";
|
|
10
10
|
import { deserializeFloat } from "./deserialize/simple/float";
|
|
11
|
-
import { deserializeStruct } from "./deserialize/simple/struct";
|
|
12
11
|
import { deserializeMap } from "./deserialize/simple/map";
|
|
13
12
|
import { deserializeDate } from "./deserialize/simple/date";
|
|
14
13
|
import { deserializeInteger } from "./deserialize/simple/integer";
|
|
@@ -588,7 +587,7 @@ export namespace JSON {
|
|
|
588
587
|
let type: nonnull<T> = changetype<nonnull<T>>(0);
|
|
589
588
|
// @ts-ignore: Defined by transform
|
|
590
589
|
if (isDefined(type.__DESERIALIZE)) {
|
|
591
|
-
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()))
|
|
590
|
+
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
592
591
|
// @ts-ignore: Defined by transform
|
|
593
592
|
return out.__DESERIALIZE(srcStart, srcEnd, out);
|
|
594
593
|
} else if (type instanceof Map) {
|
|
@@ -613,7 +612,7 @@ export namespace JSON {
|
|
|
613
612
|
}
|
|
614
613
|
throw new Error(`Could not deserialize data '${ptrToStr(srcStart, srcEnd).slice(0, 100)}' to type. Make sure to add the correct decorators to classes.`);
|
|
615
614
|
}
|
|
616
|
-
namespace Util {
|
|
615
|
+
export namespace Util {
|
|
617
616
|
// @ts-ignore: decorator
|
|
618
617
|
@inline export function isSpace(code: u16): boolean {
|
|
619
618
|
return code == 0x20 || code - 9 <= 4;
|
package/assembly/test.ts
CHANGED
|
@@ -25,7 +25,6 @@ class Player {
|
|
|
25
25
|
@omitif((self: Player) => self.age < 18)
|
|
26
26
|
age!: i32;
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
@omitnull()
|
|
30
29
|
pos!: Vec3 | null;
|
|
31
30
|
isVerified!: boolean;
|
|
@@ -65,7 +64,6 @@ class InnerObj<T> {
|
|
|
65
64
|
obj: T = instantiate<T>();
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
|
|
69
67
|
@json
|
|
70
68
|
class ObjWithBracketString {
|
|
71
69
|
data: string = "";
|
|
@@ -169,4 +167,52 @@ const a20 = JSON.parse<JSON.Box<f64>[]>("[1.3,4.7,9.5]");
|
|
|
169
167
|
console.log("a20: " + JSON.stringify(a20));
|
|
170
168
|
|
|
171
169
|
const a21 = JSON.stringify<JSON.Box<f64>[]>(a20);
|
|
172
|
-
console.log("a21: " + a21);
|
|
170
|
+
console.log("a21: " + a21);
|
|
171
|
+
|
|
172
|
+
const a22 = JSON.parse<Foo>('{"id":"0xb8","firstName":"Jairus","lastName":"Tanaka"}');
|
|
173
|
+
console.log("a22: " + JSON.stringify(a22));
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@json
|
|
177
|
+
class Foo {
|
|
178
|
+
id: string = "";
|
|
179
|
+
firstName: string = "";
|
|
180
|
+
lastName: string = "";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@json
|
|
184
|
+
class SrvInfo {
|
|
185
|
+
accessUrl: string = "https://example.com";
|
|
186
|
+
cardTypes: i32[] = [1, 2, 3];
|
|
187
|
+
customService: string = "Contact us at support@example.com";
|
|
188
|
+
invoiceApplicationStatus: i32 = 1;
|
|
189
|
+
isCertification: bool = true;
|
|
190
|
+
isOnlineRecharge: bool = false;
|
|
191
|
+
loginTypes: i32[] = [0, 1]; // e.g. 0 = password, 1 = OTP
|
|
192
|
+
record: string = "ICP 12345678";
|
|
193
|
+
regCompanyAudit: i32 = 2;
|
|
194
|
+
regCompanyPipeline: i32[] = [101, 102, 103];
|
|
195
|
+
regPwdLimit: i32 = 8; // min password length
|
|
196
|
+
serverTime: i64 = 1650000000000; // dummy timestamp
|
|
197
|
+
srvDescription: string = "A demo service for handling customer operations.";
|
|
198
|
+
srvHiddenMenu: string[] = ["admin", "beta"];
|
|
199
|
+
srvHost: string = "srv.example.com";
|
|
200
|
+
srvId: i32 = 999;
|
|
201
|
+
srvKeywords: string[] = ["finance", "payments", "online"];
|
|
202
|
+
srvLogoImgUrl: string = "https://example.com/logo.png";
|
|
203
|
+
srvName: string = "ExampleService";
|
|
204
|
+
srvPageId: i32 = 5;
|
|
205
|
+
thirdAuthUrl: string = "https://auth.example.com";
|
|
206
|
+
userCenterStyle: i32 = 1; // e.g. 1 = modern, 0 = legacy
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const a23 = JSON.stringify(new SrvInfo());
|
|
210
|
+
console.log("a23: " + a23);
|
|
211
|
+
|
|
212
|
+
const a24 = '{"accessUrl":"https://example.com","cardTypes":[1,2,3],"customService":"Contact us at support@example.com","invoiceApplicationStatus":1,"isCertification":true,"isOnlineRecharge":false,"loginTypes":[0,1],"record":"ICP 12345678","regCompanyAudit":2,"regCompanyPipeline":[101,102,103],"regPwdLimit":8,"serverTime":1650000000000,"srvDescription":"A demo service for handling customer operations.","srvHiddenMenu":["admin","beta"],"srvHost":"srv.example.com","srvId":999,"srvKeywords":["finance","payments","online"],"srvLogoImgUrl":"https://example.com/logo.png","srvName":"ExampleService","srvPageId":5,"thirdAuthUrl":"https://auth.example.com","userCenterStyle":1}';
|
|
213
|
+
console.log("a25: " + (a24 == a23).toString());
|
|
214
|
+
|
|
215
|
+
const a26 = JSON.parse<SrvInfo>(a23);
|
|
216
|
+
console.log("a26: " + JSON.stringify(a26));
|
|
217
|
+
|
|
218
|
+
console.log("a27: " + (JSON.stringify(a26) == a23).toString())
|
package/index.ts
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
class SrvInfo {
|
|
2
|
+
accessUrl: string = "https://example.com";
|
|
3
|
+
cardTypes: number[] = [1, 2, 3];
|
|
4
|
+
customService: string = "Contact us at support@example.com";
|
|
5
|
+
invoiceApplicationStatus: number = 1;
|
|
6
|
+
isCertification: bool = true;
|
|
7
|
+
isOnlineRecharge: bool = false;
|
|
8
|
+
loginTypes: number[] = [0, 1]; // e.g. 0 = password, 1 = OTP
|
|
9
|
+
record: string = "ICP 12345678";
|
|
10
|
+
regCompanyAudit: number = 2;
|
|
11
|
+
regCompanyPipeline: number[] = [101, 102, 103];
|
|
12
|
+
regPwdLimit: number = 8; // min password length
|
|
13
|
+
serverTime: i64 = 1650000000000; // dummy timestamp
|
|
14
|
+
srvDescription: string = "A demo service for handling customer operations.";
|
|
15
|
+
srvHiddenMenu: string[] = ["admin", "beta"];
|
|
16
|
+
srvHost: string = "srv.example.com";
|
|
17
|
+
srvId: number = 999;
|
|
18
|
+
srvKeywords: string[] = ["finance", "payments", "online"];
|
|
19
|
+
srvLogoImgUrl: string = "https://example.com/logo.png";
|
|
20
|
+
srvName: string = "ExampleService";
|
|
21
|
+
srvPageId: number = 5;
|
|
22
|
+
thirdAuthUrl: string = "https://auth.example.com";
|
|
23
|
+
userCenterStyle: number = 1; // e.g. 1 = modern, 0 = legacy
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log(JSON.stringify(new SrvInfo()))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"author": "Jairus Tanaka",
|
|
5
5
|
"description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
|
|
6
6
|
"types": "assembly/index.ts",
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
"url": "https://github.com/JairusSW/json-as/issues"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
+
"ci": "act",
|
|
18
19
|
"test": "bash ./run-tests.sh",
|
|
19
20
|
"bench:as": "bash ./run-bench.as.sh",
|
|
20
21
|
"bench:js": "bash ./run-bench.js.sh",
|
|
21
|
-
"build:test": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --debug --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
22
|
+
"build:test": "rm -rf ./build/ && JSON_STRICT=true JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --debug --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
22
23
|
"build:test:simd": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm --textFile ./build/test.wat --optimizeLevel 3 --shrinkLevel 0 --enable simd --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json",
|
|
23
24
|
"test:wasmtime": "wasmtime ./build/test.wasm",
|
|
24
25
|
"test:wasmer": "wasmer ./build/test.wasm",
|