json-as 1.2.1 → 1.2.2-beta.1
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/package.json +1 -1
- package/.github/FUNDING.yml +0 -1
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/benchmark.yml +0 -72
- package/.github/workflows/release-package.yml +0 -47
- package/.github/workflows/tests.yml +0 -25
- package/.prettierignore +0 -9
- package/.prettierrc.json +0 -7
- package/.trunk/configs/.markdownlint.yaml +0 -2
- package/.trunk/configs/.shellcheckrc +0 -7
- package/.trunk/configs/.yamllint.yaml +0 -7
- package/.trunk/trunk.yaml +0 -37
- package/CHANGELOG.md +0 -334
- package/SECURITY.md +0 -32
- package/asconfig.json +0 -7
- package/assembly/__benches__/abc.bench.ts +0 -28
- package/assembly/__benches__/large.bench.ts +0 -238
- package/assembly/__benches__/lib/bench.ts +0 -85
- package/assembly/__benches__/medium.bench.ts +0 -128
- package/assembly/__benches__/small.bench.ts +0 -46
- package/assembly/__benches__/throughput.ts +0 -172
- package/assembly/__benches__/vec3.bench.ts +0 -37
- package/assembly/__tests__/arbitrary.spec.ts +0 -35
- package/assembly/__tests__/array.spec.ts +0 -145
- package/assembly/__tests__/bool.spec.ts +0 -12
- package/assembly/__tests__/box.spec.ts +0 -27
- package/assembly/__tests__/custom.spec.ts +0 -56
- package/assembly/__tests__/date.spec.ts +0 -36
- package/assembly/__tests__/enum.spec.ts +0 -35
- package/assembly/__tests__/float.spec.ts +0 -42
- package/assembly/__tests__/generics.spec.ts +0 -49
- package/assembly/__tests__/hierarchy.spec.ts +0 -61
- package/assembly/__tests__/integer.spec.ts +0 -26
- package/assembly/__tests__/lib/index.ts +0 -41
- package/assembly/__tests__/map.spec.ts +0 -7
- package/assembly/__tests__/namespace.spec.ts +0 -63
- package/assembly/__tests__/null.spec.ts +0 -12
- package/assembly/__tests__/raw.spec.ts +0 -23
- package/assembly/__tests__/resolving.spec.ts +0 -55
- package/assembly/__tests__/staticarray.spec.ts +0 -12
- package/assembly/__tests__/string.spec.ts +0 -30
- package/assembly/__tests__/struct.spec.ts +0 -163
- package/assembly/__tests__/test.spec.ts +0 -3
- package/assembly/__tests__/types.spec.ts +0 -27
- package/assembly/__tests__/types.ts +0 -98
- package/assembly/test.tmp.ts +0 -133
- package/bench/abc.bench.ts +0 -25
- package/bench/large.bench.ts +0 -127
- package/bench/lib/bench.d.ts +0 -27
- package/bench/lib/bench.js +0 -53
- package/bench/lib/chart.ts +0 -217
- package/bench/medium.bench.ts +0 -68
- package/bench/runners/assemblyscript.js +0 -34
- package/bench/small.bench.ts +0 -34
- package/bench/throughput.ts +0 -87
- package/bench/tsconfig.json +0 -13
- package/bench/vec3.bench.ts +0 -30
- package/bench.ts +0 -18
- package/ci/bench/lib/bench.ts +0 -42
- package/ci/bench/runners/assemblyscript.js +0 -29
- package/ci/run-bench.as.sh +0 -63
- package/publish.sh +0 -78
- package/run-bench.as.sh +0 -60
- package/run-bench.js.sh +0 -36
- package/run-tests.sh +0 -51
- package/scripts/build-chart01.ts +0 -38
- package/scripts/build-chart02.ts +0 -38
- package/scripts/build-chart03.ts +0 -139
- package/scripts/build-chart05.ts +0 -47
- package/scripts/generate-as-class.ts +0 -50
- package/scripts/lib/bench-utils.ts +0 -308
- package/transform/src/builder.ts +0 -1375
- package/transform/src/index.ts +0 -1486
- package/transform/src/linkers/alias.ts +0 -58
- package/transform/src/linkers/custom.ts +0 -32
- package/transform/src/linkers/imports.ts +0 -22
- package/transform/src/types.ts +0 -300
- package/transform/src/util.ts +0 -128
- package/transform/src/visitor.ts +0 -530
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
|
|
2
|
-
import { JSON } from "..";
|
|
3
|
-
import { describe, expect } from "./lib";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@json
|
|
7
|
-
class Foo {
|
|
8
|
-
a: i32 = 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@json
|
|
13
|
-
class Bar extends Foo {
|
|
14
|
-
b: i32 = 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@serializer
|
|
18
|
-
serialize(self: Bar): string {
|
|
19
|
-
return `"bar"`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@deserializer
|
|
24
|
-
deserialize(data: string): Bar {
|
|
25
|
-
return data == '"bar"'
|
|
26
|
-
? {
|
|
27
|
-
a: 1,
|
|
28
|
-
b: 2,
|
|
29
|
-
}
|
|
30
|
-
: new Bar();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
describe("should use custom serializer for subclasses", () => {
|
|
35
|
-
const bar = new Bar();
|
|
36
|
-
bar.a = 1;
|
|
37
|
-
bar.b = 2;
|
|
38
|
-
const data = JSON.stringify(bar);
|
|
39
|
-
expect(data).toBe('"bar"');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("should use custom serializer for subclasses when type is the parent", () => {
|
|
43
|
-
const bar = new Bar();
|
|
44
|
-
bar.a = 1;
|
|
45
|
-
bar.b = 2;
|
|
46
|
-
const data = JSON.stringify<Foo>(bar);
|
|
47
|
-
expect(data).toBe('"bar"');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe("should use custom deserializer for subclass", () => {
|
|
51
|
-
const json = '"bar"';
|
|
52
|
-
const bar = JSON.parse<Bar>(json);
|
|
53
|
-
expect(bar.a.toString()).toBe("1");
|
|
54
|
-
expect(bar.b.toString()).toBe("2");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("should use custom deserializer even when type is the parent", () => {
|
|
58
|
-
const json = '"bar"';
|
|
59
|
-
const foo = JSON.parse<Bar>(json);
|
|
60
|
-
expect(foo.a.toString()).toBe("1");
|
|
61
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize integers", () => {
|
|
5
|
-
expect(JSON.stringify(0)).toBe("0");
|
|
6
|
-
|
|
7
|
-
expect(JSON.stringify<u32>(100)).toBe("100");
|
|
8
|
-
|
|
9
|
-
expect(JSON.stringify<u64>(101)).toBe("101");
|
|
10
|
-
|
|
11
|
-
expect(JSON.stringify<i32>(-100)).toBe("-100");
|
|
12
|
-
|
|
13
|
-
expect(JSON.stringify<i64>(-101)).toBe("-101");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe("Should deserialize integers", () => {
|
|
17
|
-
expect(JSON.parse<i32>("0").toString()).toBe("0");
|
|
18
|
-
|
|
19
|
-
expect(JSON.parse<u32>("100").toString()).toBe("100");
|
|
20
|
-
|
|
21
|
-
expect(JSON.parse<u64>("101").toString()).toBe("101");
|
|
22
|
-
|
|
23
|
-
expect(JSON.parse<i32>("-100").toString()).toBe("-100");
|
|
24
|
-
|
|
25
|
-
expect(JSON.parse<i64>("-101").toString()).toBe("-101");
|
|
26
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
let currentDescription: string = "";
|
|
2
|
-
export function describe(description: string, routine: () => void): void {
|
|
3
|
-
currentDescription = description;
|
|
4
|
-
routine();
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function it(description: string, routine: () => void): void {
|
|
8
|
-
currentDescription = description;
|
|
9
|
-
routine();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function expect<T>(left: T): Expectation {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
if (!isDefined(left.toString)) throw new Error("Expected left to have a toString method, but it does not.");
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
return new Expectation(isNull(left) ? "null" : left.toString());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class Expectation {
|
|
20
|
-
public left: string;
|
|
21
|
-
|
|
22
|
-
constructor(left: string) {
|
|
23
|
-
this.left = left;
|
|
24
|
-
}
|
|
25
|
-
toBe<T>(right: T): void {
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
if (!isDefined(right.toString)) throw new Error("Expected right to have a toString method, but it does not.");
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
if (this.left != (isNull(right) ? "null" : right.toString())) {
|
|
30
|
-
console.log(" " + currentDescription + "\n");
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
console.log(" (expected) -> " + (isNull(right) ? "null" : right.toString()));
|
|
33
|
-
console.log(" (received) -> " + this.left);
|
|
34
|
-
unreachable();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isNull<T>(value: T): bool {
|
|
40
|
-
return (isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && value == 0) || (isNullable<T>() && changetype<usize>(value) == <usize>0);
|
|
41
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should deserialize complex objects", () => {
|
|
5
|
-
const input = '{"a":{"b":{"c":[{"d":"random value 1"},{"e":["value 2","value 3"]}],"f":{"g":{"h":[1,2,3],"i":{"j":"nested value"}}}},"k":"simple value"},"l":[{"m":"another value","n":{"o":"deep nested","p":[{"q":"even deeper"},"final value"]}}],"r":null}';
|
|
6
|
-
expect(JSON.stringify(JSON.parse<Map<string, JSON.Raw>>(input))).toBe(input);
|
|
7
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize namespaced derived structs", () => {
|
|
5
|
-
const obj: Namespace.DerivedObject = { a: "foo", b: "bar" };
|
|
6
|
-
expect(JSON.stringify(obj)).toBe(`{"a":"foo","b":"bar"}`);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
describe("Should serialize namespaced derived structs with nested object", () => {
|
|
10
|
-
const bar: Namespace.Bar = { value: "baz" };
|
|
11
|
-
const obj: Namespace.DerivedObjectWithNestedObject = { a: "foo", b: "bar", c: bar };
|
|
12
|
-
expect(JSON.stringify(obj)).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("Should deserialize namespaced object with alias property", () => {
|
|
16
|
-
expect(JSON.stringify(JSON.parse<Namespace.ObjectWithAliasProperty>(`{"a":"foo","value":42}`))).toBe(`{"a":"foo","value":42}`);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("Should deserialize namespaced derived structs", () => {
|
|
20
|
-
expect(JSON.stringify(JSON.parse<Namespace.DerivedObject>(`{"a":"foo","b":"bar"}`))).toBe(`{"a":"foo","b":"bar"}`);
|
|
21
|
-
expect(JSON.stringify(JSON.parse<Namespace.DerivedObject>(`{"b":"bar","a":"foo"}`))).toBe(`{"a":"foo","b":"bar"}`);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("Should deserialize namespaced derived structs with nested object", () => {
|
|
25
|
-
expect(JSON.stringify(JSON.parse<Namespace.DerivedObjectWithNestedObject>(`{"a":"foo","b":"bar","c":{"value":"baz"}}`))).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
|
|
26
|
-
expect(JSON.stringify(JSON.parse<Namespace.DerivedObjectWithNestedObject>(`{"c":{"value":"baz"},"a":"foo","b":"bar"}`))).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
type NumberAlias = i64;
|
|
30
|
-
|
|
31
|
-
namespace Namespace {
|
|
32
|
-
|
|
33
|
-
@json
|
|
34
|
-
export class Base {
|
|
35
|
-
a: string = "";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@json
|
|
40
|
-
export class Bar {
|
|
41
|
-
value: string = "";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@json
|
|
46
|
-
export class ObjectWithAliasProperty {
|
|
47
|
-
a: string = "";
|
|
48
|
-
value: NumberAlias = 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@json
|
|
53
|
-
export class DerivedObject extends Base {
|
|
54
|
-
b: string = "";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@json
|
|
59
|
-
export class DerivedObjectWithNestedObject extends Base {
|
|
60
|
-
b: string = "";
|
|
61
|
-
c: Bar = new Bar();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize null", () => {
|
|
5
|
-
expect(JSON.stringify(null)).toBe("null");
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
describe("Should serialize nullable classes", () => {
|
|
9
|
-
expect(JSON.stringify<Nullable | null>(null)).toBe("null");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
class Nullable {}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize JSON.Raw", () => {
|
|
5
|
-
expect(JSON.stringify<JSON.Raw>(JSON.Raw.from('{"x":1.0,"y":2.0,"z":3.0}'))).toBe('{"x":1.0,"y":2.0,"z":3.0}');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
describe("Should deserialize JSON.Raw", () => {
|
|
9
|
-
expect(JSON.parse<JSON.Raw>('{"x":1.0,"y":2.0,"z":3.0}').toString()).toBe('{"x":1.0,"y":2.0,"z":3.0}');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe("Should serialize Map<string, JSON.Raw>", () => {
|
|
13
|
-
const m1 = new Map<string, JSON.Raw>();
|
|
14
|
-
m1.set("hello", new JSON.Raw('"world"'));
|
|
15
|
-
m1.set("pos", new JSON.Raw('{"x":1.0,"y":2.0,"z":3.0}'));
|
|
16
|
-
|
|
17
|
-
expect(JSON.stringify(m1)).toBe('{"hello":"world","pos":{"x":1.0,"y":2.0,"z":3.0}}');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("Should deserialize Map<string, JSON.Raw>", () => {
|
|
21
|
-
const m1 = JSON.parse<Map<string, JSON.Raw>>('{"hello":"world","pos":{"x":1.0,"y":2.0,"z":3.0}}');
|
|
22
|
-
expect(JSON.stringify(m1)).toBe('{"hello":"world","pos":{"x":1.0,"y":2.0,"z":3.0}}');
|
|
23
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
import { Vec3 } from "./types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@json
|
|
7
|
-
class Player {
|
|
8
|
-
|
|
9
|
-
@alias("first name")
|
|
10
|
-
firstName!: string;
|
|
11
|
-
lastName!: string;
|
|
12
|
-
lastActive!: i32[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@omitif((self: Player) => self.age < 18)
|
|
16
|
-
age!: i32;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@omitnull()
|
|
20
|
-
pos!: Vec3 | null;
|
|
21
|
-
isVerified!: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const player: Player = {
|
|
25
|
-
firstName: "Jairus",
|
|
26
|
-
lastName: "Tanaka",
|
|
27
|
-
lastActive: [3, 9, 2025],
|
|
28
|
-
age: 18,
|
|
29
|
-
pos: {
|
|
30
|
-
x: 3.4,
|
|
31
|
-
y: 1.2,
|
|
32
|
-
z: 8.3,
|
|
33
|
-
},
|
|
34
|
-
isVerified: true,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@json
|
|
39
|
-
class Foo {
|
|
40
|
-
bar: Bar = new Bar();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@json
|
|
45
|
-
class Bar {
|
|
46
|
-
baz: string = "buz";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
describe("Should resolve imported schemas", () => {
|
|
50
|
-
expect(JSON.stringify(player)).toBe('{"age":18,"pos":{"x":3.4,"y":1.2,"z":8.3},"first name":"Jairus","lastName":"Tanaka","lastActive":[3,9,2025],"isVerified":true}');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("Should resolve local schemas", () => {
|
|
54
|
-
expect(JSON.stringify(new Foo())).toBe('{"bar":{"baz":"buz"}}');
|
|
55
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize integer static arrays", () => {
|
|
5
|
-
expect(JSON.stringify<StaticArray<u32>>([0, 100, 101])).toBe("[0,100,101]");
|
|
6
|
-
|
|
7
|
-
expect(JSON.stringify<StaticArray<u64>>([0, 100, 101])).toBe("[0,100,101]");
|
|
8
|
-
|
|
9
|
-
expect(JSON.stringify<StaticArray<i32>>([0, 100, 101, -100, -101])).toBe("[0,100,101,-100,-101]");
|
|
10
|
-
|
|
11
|
-
expect(JSON.stringify<StaticArray<i64>>([0, 100, 101, -100, -101])).toBe("[0,100,101,-100,-101]");
|
|
12
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize strings", () => {
|
|
5
|
-
expect(JSON.stringify("abcdefg")).toBe('"abcdefg"');
|
|
6
|
-
|
|
7
|
-
expect(JSON.stringify('st"ring" w""ith quotes"')).toBe('"st\\"ring\\" w\\"\\"ith quotes\\""');
|
|
8
|
-
|
|
9
|
-
expect(JSON.stringify('string "with random spa\nces and \nnewlines\n\n\n')).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
|
|
10
|
-
|
|
11
|
-
expect(JSON.stringify('string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"')).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\\\""');
|
|
12
|
-
|
|
13
|
-
expect(JSON.stringify("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f")).toBe('"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u000f\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f"');
|
|
14
|
-
|
|
15
|
-
expect(JSON.stringify("abcdYZ12345890sdfw\"vie91kfESDFOK12i9i12dsf./?")).toBe('"abcdYZ12345890sdfw\\"vie91kfESDFOK12i9i12dsf./?"');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("Should deserialize strings", () => {
|
|
19
|
-
expect(JSON.parse<string>('"abcdefg"')).toBe("abcdefg");
|
|
20
|
-
|
|
21
|
-
expect(JSON.parse<string>('"\\"st\\\\\\"ring\\\\\\" w\\\\\\"\\\\\\"ith quotes\\\\\\"\\""')).toBe('"st\\"ring\\" w\\"\\"ith quotes\\""');
|
|
22
|
-
|
|
23
|
-
expect(JSON.parse<string>('"\\"string \\\\\\"with random spa\\\\nces and \\\\nnewlines\\\\n\\\\n\\\\n\\""')).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
|
|
24
|
-
|
|
25
|
-
expect(JSON.parse<string>('"\\"string with colon : comma , brace [ ] bracket { } and quote \\\\\\" and other quote \\\\\\\\\\"\\""')).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\""');
|
|
26
|
-
|
|
27
|
-
expect(JSON.parse<string>('"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u000f\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f"')).toBe("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f");
|
|
28
|
-
|
|
29
|
-
expect(JSON.parse<string>('"abcdYZ12345890sdfw\\"vie91kfESDFOK12i9i12dsf./?"')).toBe("abcdYZ12345890sdfw\"vie91kfESDFOK12i9i12dsf./?");
|
|
30
|
-
});
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize structs", () => {
|
|
5
|
-
expect(
|
|
6
|
-
JSON.stringify<Vec3>({
|
|
7
|
-
x: 3.4,
|
|
8
|
-
y: 1.2,
|
|
9
|
-
z: 8.3,
|
|
10
|
-
}),
|
|
11
|
-
).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
12
|
-
|
|
13
|
-
expect(
|
|
14
|
-
JSON.stringify<Player>({
|
|
15
|
-
firstName: "Emmet",
|
|
16
|
-
lastName: "West",
|
|
17
|
-
lastActive: [8, 27, 2022],
|
|
18
|
-
age: 23,
|
|
19
|
-
pos: {
|
|
20
|
-
x: 3.4,
|
|
21
|
-
y: 1.2,
|
|
22
|
-
z: 8.3,
|
|
23
|
-
},
|
|
24
|
-
isVerified: true,
|
|
25
|
-
}),
|
|
26
|
-
).toBe('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}');
|
|
27
|
-
|
|
28
|
-
expect(JSON.stringify<ObjectWithFloat>({ f: 7.23 })).toBe('{"f":7.23}');
|
|
29
|
-
|
|
30
|
-
expect(JSON.stringify<ObjectWithFloat>({ f: 0.000001 })).toBe('{"f":0.000001}');
|
|
31
|
-
|
|
32
|
-
expect(JSON.stringify<ObjectWithFloat>({ f: 1e-7 })).toBe('{"f":1e-7}');
|
|
33
|
-
|
|
34
|
-
expect(JSON.stringify<ObjectWithFloat>({ f: 1e20 })).toBe('{"f":100000000000000000000.0}');
|
|
35
|
-
|
|
36
|
-
expect(JSON.stringify<ObjectWithFloat>({ f: 1e21 })).toBe('{"f":1e+21}');
|
|
37
|
-
|
|
38
|
-
expect(JSON.stringify<ObjWithStrangeKey<string>>({ data: "foo" })).toBe('{"a\\\\\\t\\"\\u0002b`c":"foo"}');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("Should serialize structs with inheritance", () => {
|
|
42
|
-
const obj = new DerivedObject("1", "2");
|
|
43
|
-
|
|
44
|
-
expect(JSON.stringify(obj)).toBe('{"a":"1","b":"2"}');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("Should ignore properties decorated with @omit", () => {
|
|
48
|
-
expect(
|
|
49
|
-
JSON.stringify(<OmitIf>{
|
|
50
|
-
y: 1,
|
|
51
|
-
}),
|
|
52
|
-
).toBe('{"y":1,"x":1,"z":1}');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("Should deserialize structs", () => {
|
|
56
|
-
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
57
|
-
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"a":1.3,"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
58
|
-
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"a":1.3,"y":123,"asdf":3453204,"boink":[],"y":1.2,"z":8.3}'))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe("Should deserialize structs with whitespace", () => {
|
|
62
|
-
expect(JSON.stringify(JSON.parse<Vec3>(' { "x" : 3.4 , "y" : 1.2 , "z" : 8.3 } '))).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("Should deserialize structs with nullable properties", () => {
|
|
66
|
-
expect(JSON.stringify(JSON.parse<NullableObj>('{"bar":{"value":"test"}}'))).toBe('{"bar":{"value":"test"}}');
|
|
67
|
-
|
|
68
|
-
expect(JSON.stringify(JSON.parse<NullableObj>('{"bar":null}'))).toBe('{"bar":null}');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("Should deserialize structs with nullable arrays in properties", () => {
|
|
72
|
-
expect(JSON.stringify(JSON.parse<NullableArrayObj>('{"bars":[{"value":"test"}]}'))).toBe('{"bars":[{"value":"test"}]}');
|
|
73
|
-
|
|
74
|
-
expect(JSON.stringify(JSON.parse<NullableArrayObj>('{"bars":null}'))).toBe('{"bars":null}');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// describe("Should serialize Suite struct", () => {
|
|
78
|
-
|
|
79
|
-
// });
|
|
80
|
-
|
|
81
|
-
@json
|
|
82
|
-
class BaseObject {
|
|
83
|
-
a: string;
|
|
84
|
-
constructor(a: string) {
|
|
85
|
-
this.a = a;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@json
|
|
91
|
-
class DerivedObject extends BaseObject {
|
|
92
|
-
b: string;
|
|
93
|
-
constructor(a: string, b: string) {
|
|
94
|
-
super(a);
|
|
95
|
-
this.b = b;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
@json
|
|
101
|
-
class Vec3 {
|
|
102
|
-
x: f64 = 0.0;
|
|
103
|
-
y: f64 = 0.0;
|
|
104
|
-
z: f64 = 0.0;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
@json
|
|
109
|
-
class Player {
|
|
110
|
-
firstName!: string;
|
|
111
|
-
lastName!: string;
|
|
112
|
-
lastActive!: i32[];
|
|
113
|
-
age!: i32;
|
|
114
|
-
pos!: Vec3 | null;
|
|
115
|
-
isVerified!: boolean;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@json
|
|
120
|
-
class ObjWithStrangeKey<T> {
|
|
121
|
-
|
|
122
|
-
@alias('a\\\t"\x02b`c')
|
|
123
|
-
data!: T;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@json
|
|
128
|
-
class ObjectWithFloat {
|
|
129
|
-
f!: f64;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
@json
|
|
134
|
-
class OmitIf {
|
|
135
|
-
x: i32 = 1;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@omitif("this.y == -1")
|
|
139
|
-
y: i32 = -1;
|
|
140
|
-
z: i32 = 1;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
@omitnull()
|
|
144
|
-
foo: string | null = null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
@json
|
|
149
|
-
class NullableObj {
|
|
150
|
-
bar: Bar | null = null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
@json
|
|
155
|
-
class NullableArrayObj {
|
|
156
|
-
bars: Bar[] | null = null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
@json
|
|
161
|
-
class Bar {
|
|
162
|
-
value: string = "";
|
|
163
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { JSON } from "..";
|
|
2
|
-
import { describe, expect } from "./lib";
|
|
3
|
-
|
|
4
|
-
type StringAlias = string;
|
|
5
|
-
type StringAlias1 = StringAlias;
|
|
6
|
-
type StringAlias2 = StringAlias1;
|
|
7
|
-
type StringAlias3 = StringAlias2;
|
|
8
|
-
type StringAlias4 = StringAlias3;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@json
|
|
12
|
-
class Alias {
|
|
13
|
-
public foo: StringAlias4 = "";
|
|
14
|
-
constructor(foo: StringAlias2) {
|
|
15
|
-
this.foo = foo;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const alias = new Alias("bar");
|
|
20
|
-
|
|
21
|
-
describe("Should serialize with type aliases", () => {
|
|
22
|
-
expect(JSON.stringify(alias)).toBe('{"foo":"bar"}');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("Should deserialize with type aliases", () => {
|
|
26
|
-
expect(JSON.stringify(JSON.parse<Alias>('{"foo":"bar"}'))).toBe('{"foo":"bar"}');
|
|
27
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
@json
|
|
3
|
-
export class ObjWithString {
|
|
4
|
-
s!: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@json
|
|
9
|
-
export class ObjWithStrangeKey<T> {
|
|
10
|
-
|
|
11
|
-
@alias('a\\\t"\x02b`c')
|
|
12
|
-
data!: T;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@json
|
|
17
|
-
export class ObjectWithStringArray {
|
|
18
|
-
sa!: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@json
|
|
23
|
-
export class ObjectWithFloat {
|
|
24
|
-
f!: f64;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@json
|
|
29
|
-
export class ObjectWithFloatArray {
|
|
30
|
-
fa!: f64[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@json
|
|
35
|
-
export class BaseObject {
|
|
36
|
-
a: string;
|
|
37
|
-
constructor(a: string) {
|
|
38
|
-
this.a = a;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
@json
|
|
44
|
-
export class DerivedObject extends BaseObject {
|
|
45
|
-
b: string;
|
|
46
|
-
constructor(a: string, b: string) {
|
|
47
|
-
super(a);
|
|
48
|
-
this.b = b;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@json
|
|
54
|
-
export class Map4 {
|
|
55
|
-
a: string;
|
|
56
|
-
b: string;
|
|
57
|
-
c: string;
|
|
58
|
-
d: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@json
|
|
63
|
-
export class Vec3 {
|
|
64
|
-
x: f64 = 1.0;
|
|
65
|
-
y: f64 = 2.0;
|
|
66
|
-
z: f64 = 3.0;
|
|
67
|
-
|
|
68
|
-
static shouldIgnore: string = "should not be serialized";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@json
|
|
73
|
-
export class Player {
|
|
74
|
-
firstName: string;
|
|
75
|
-
lastName: string;
|
|
76
|
-
lastActive: i32[];
|
|
77
|
-
age: i32;
|
|
78
|
-
pos: Vec3 | null;
|
|
79
|
-
isVerified: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export class Nullable {}
|
|
83
|
-
export type Null = Nullable | null;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@json
|
|
87
|
-
export class OmitIf {
|
|
88
|
-
x: i32 = 1;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@omitif("this.y == -1")
|
|
92
|
-
y: i32 = -1;
|
|
93
|
-
z: i32 = 1;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
@omitnull()
|
|
97
|
-
foo: string | null = null;
|
|
98
|
-
}
|