json-as 0.9.7 → 0.9.8-b
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 +9 -10
- package/CHANGELOG +11 -2
- package/README.md +52 -7
- package/asconfig.json +24 -3
- package/assembly/__tests__/test.spec.ts +564 -0
- package/assembly/__tests__/types.ts +82 -0
- package/assembly/{src/chars.ts → chars.ts} +36 -36
- package/assembly/deserialize/array/array.ts +4 -4
- package/assembly/deserialize/array/bool.ts +4 -4
- package/assembly/deserialize/array/float.ts +4 -4
- package/assembly/deserialize/array/integer.ts +4 -4
- package/assembly/deserialize/array/map.ts +4 -4
- package/assembly/deserialize/array/object.ts +4 -4
- package/assembly/deserialize/array/string.ts +4 -4
- package/assembly/deserialize/array.ts +5 -4
- package/assembly/deserialize/bool.ts +4 -4
- package/assembly/deserialize/date.ts +2 -2
- package/assembly/deserialize/float.ts +2 -2
- package/assembly/deserialize/integer.ts +3 -3
- package/assembly/deserialize/map.ts +4 -4
- package/assembly/deserialize/mpz.ts +12 -0
- package/assembly/deserialize/object.ts +4 -4
- package/assembly/deserialize/string.ts +5 -5
- package/assembly/index.ts +25 -23
- package/assembly/serialize/array.ts +6 -5
- package/assembly/serialize/bool.ts +2 -2
- package/assembly/serialize/date.ts +2 -2
- package/assembly/serialize/float.ts +2 -2
- package/assembly/serialize/integer.ts +2 -2
- package/assembly/serialize/map.ts +8 -7
- package/assembly/serialize/mpz.ts +6 -0
- package/assembly/serialize/object.ts +2 -2
- package/assembly/serialize/string.ts +5 -5
- package/assembly/serialize/unknown.ts +5 -5
- package/assembly/test.ts +10 -47
- package/assembly/types.ts +4 -0
- package/assembly/{src/util.ts → util.ts} +3 -3
- package/bench/benchmark.ts +1 -1
- package/build/test.spec.wasm +0 -0
- package/build/test.spec.wasm.map +1 -0
- package/build/test.spec.wat +112616 -0
- package/build/test.wasm +0 -0
- package/build/test.wasm.map +1 -0
- package/build/test.wat +12267 -0
- package/package.json +13 -14
- package/transform/lib/visitor.js +516 -0
- package/transform/package.json +1 -1
- package/transform/src/visitor.ts +543 -0
- package/transform/tsconfig.json +23 -63
- package/tsconfig.json +13 -13
- package/as-pect.asconfig.json +0 -24
- package/as-pect.config.js +0 -30
- package/assembly/__tests__/deserialize.spec.ts +0 -301
- package/assembly/__tests__/serialize.spec.ts +0 -398
- package/assembly/deserialize/box.ts +0 -17
- package/assembly/serialize/box.ts +0 -11
- package/develop/assembly/serialize/unknown.ts +0 -46
- package/transform/lib/index.old.js +0 -257
- package/transform/lib/types.js +0 -17
- package/transform/src/index.old.ts +0 -312
- /package/assembly/{src/sink.ts → sink.ts} +0 -0
package/assembly/test.ts
CHANGED
|
@@ -1,51 +1,14 @@
|
|
|
1
|
-
import { JSON } from "
|
|
2
|
-
|
|
3
|
-
// @json or @serializable work here
|
|
1
|
+
import { JSON } from "json-as/assembly";
|
|
2
|
+
import * as console from "as-console";
|
|
4
3
|
@json
|
|
5
|
-
class
|
|
6
|
-
|
|
7
|
-
y: f32 = 0.0;
|
|
8
|
-
z: f32 = 0.0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class Box<T> {
|
|
12
|
-
value: T;
|
|
13
|
-
}
|
|
4
|
+
class Yo {
|
|
5
|
+
map: Map<string, u64>;
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@omitnull()
|
|
19
|
-
firstName: string | null;
|
|
20
|
-
lastName!: string;
|
|
21
|
-
lastActive!: i32[];
|
|
22
|
-
// Drop in a code block, function, or expression that evaluates to a boolean
|
|
23
|
-
@omitif("this.age < 18")
|
|
24
|
-
age!: i32;
|
|
25
|
-
@omitnull()
|
|
26
|
-
pos!: Vec3 | null;
|
|
27
|
-
isVerified!: boolean;
|
|
28
|
-
@flatten("value")
|
|
29
|
-
box: Box<i32> | null;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.map = new Map();
|
|
9
|
+
}
|
|
30
10
|
}
|
|
31
11
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
lastActive: [8, 27, 2022],
|
|
36
|
-
age: 23,
|
|
37
|
-
pos: {
|
|
38
|
-
x: 3.4,
|
|
39
|
-
y: 1.2,
|
|
40
|
-
z: 8.3
|
|
41
|
-
},
|
|
42
|
-
isVerified: true,
|
|
43
|
-
box: null
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const stringified = JSON.stringify<Player>(player);
|
|
47
|
-
|
|
48
|
-
const parsed = JSON.parse<Player>(stringified);
|
|
49
|
-
|
|
50
|
-
console.log("Stringified: " + stringified);
|
|
51
|
-
console.log("Parsed: " + JSON.stringify(parsed));
|
|
12
|
+
let y = new Yo();
|
|
13
|
+
y.map.set("bhavya", 3000);
|
|
14
|
+
console.log(JSON.stringify(y));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { StringSink } from "as-string-sink/assembly";
|
|
2
1
|
import { isSpace } from "util/string";
|
|
3
2
|
import { BACK_SLASH, QUOTE } from "./chars";
|
|
3
|
+
import { Sink } from "./sink";
|
|
4
4
|
|
|
5
5
|
// @ts-ignore: Decorator
|
|
6
6
|
export function isMap<T>(): bool {
|
|
@@ -15,7 +15,7 @@ export function unsafeCharCodeAt(data: string, pos: i32): i32 {
|
|
|
15
15
|
|
|
16
16
|
// @ts-ignore: Decorator
|
|
17
17
|
export function removeWhitespace(data: string): string {
|
|
18
|
-
const result = new
|
|
18
|
+
const result = new Sink();
|
|
19
19
|
let instr = false;
|
|
20
20
|
for (let i = 0; i < data.length; i++) {
|
|
21
21
|
const char = unsafeCharCodeAt(data, i);
|
|
@@ -258,7 +258,7 @@ export function snip_fast<T extends number>(str: string, len: u32 = 0, offset: u
|
|
|
258
258
|
*/
|
|
259
259
|
|
|
260
260
|
// @ts-ignore
|
|
261
|
-
|
|
261
|
+
export function __atoi_fast<T extends number>(str: string, start: u32 = 0, end: u32 = 0): T {
|
|
262
262
|
// @ts-ignore
|
|
263
263
|
let val: T = 0;
|
|
264
264
|
if (!end) end = start + u32(str.length << 1);
|
package/bench/benchmark.ts
CHANGED
|
Binary file
|