json-as 1.1.14-preview.2 → 1.1.15-preview.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/CHANGELOG.md +3 -0
- package/README.md +1 -1
- package/assembly/__tests__/staticarray.spec.ts +12 -0
- package/assembly/deserialize/simple/array.ts +1 -1
- package/assembly/index.ts +12 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
+
- feat: add `.as<T>()` method to `JSON.Value`
|
|
6
|
+
- chore: remove all references to `__SERIALIZE_CUSTOM`
|
|
7
|
+
- feat: add support for `StaticArray` serialization
|
|
5
8
|
- feat: support `JSON.Raw` in array types
|
|
6
9
|
- tests: add tests for `JSON.Raw[]`
|
|
7
10
|
- tests: properly support nulls (in testing lib)
|
package/README.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
});
|
|
@@ -24,7 +24,7 @@ export function deserializeArray<T extends unknown[]>(srcStart: usize, srcEnd: u
|
|
|
24
24
|
} else if (isFloat<valueof<T>>()) {
|
|
25
25
|
// @ts-ignore
|
|
26
26
|
return deserializeFloatArray<T>(srcStart, srcEnd, dst);
|
|
27
|
-
} else if (
|
|
27
|
+
} else if (isArray<valueof<T>>()) {
|
|
28
28
|
// @ts-ignore: type
|
|
29
29
|
return deserializeArrayArray<T>(srcStart, srcEnd, dst);
|
|
30
30
|
} else if (isManaged<valueof<T>>() || isReference<valueof<T>>()) {
|
package/assembly/index.ts
CHANGED
|
@@ -131,7 +131,7 @@ export namespace JSON {
|
|
|
131
131
|
memory.copy(changetype<usize>(out) + 2, changetype<usize>(data.toISOString()), 48);
|
|
132
132
|
store<u16>(changetype<usize>(out), QUOTE, 50);
|
|
133
133
|
return changetype<string>(out);
|
|
134
|
-
} else if (data instanceof Array) {
|
|
134
|
+
} else if (data instanceof Array || data instanceof StaticArray) {
|
|
135
135
|
// @ts-ignore
|
|
136
136
|
inline.always(serializeArray(changetype<nonnull<T>>(data)));
|
|
137
137
|
return bs.out<string>();
|
|
@@ -332,13 +332,6 @@ export namespace JSON {
|
|
|
332
332
|
this.type = JSON.Types.Struct;
|
|
333
333
|
store<T>(changetype<usize>(this), value, STORAGE);
|
|
334
334
|
// @ts-ignore: supplied by transform
|
|
335
|
-
} else if (isDefined(value.__SERIALIZE_CUSTOM)) {
|
|
336
|
-
this.type = idof<T>() + JSON.Types.Struct;
|
|
337
|
-
// @ts-ignore
|
|
338
|
-
if (!JSON.Value.METHODS.has(idof<T>())) JSON.Value.METHODS.set(idof<T>(), value.__SERIALIZE_CUSTOM.index);
|
|
339
|
-
// @ts-ignore
|
|
340
|
-
store<usize>(changetype<usize>(this), changetype<usize>(value), STORAGE);
|
|
341
|
-
// @ts-ignore: supplied by transform
|
|
342
335
|
} else if (isDefined(value.__SERIALIZE)) {
|
|
343
336
|
this.type = idof<T>() + JSON.Types.Struct;
|
|
344
337
|
// @ts-ignore
|
|
@@ -364,6 +357,15 @@ export namespace JSON {
|
|
|
364
357
|
return load<T>(changetype<usize>(this), STORAGE);
|
|
365
358
|
}
|
|
366
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Gets the value of the JSON.Value instance.
|
|
362
|
+
* Alias for .get<T>()
|
|
363
|
+
* @returns The encapsulated value.
|
|
364
|
+
*/
|
|
365
|
+
@inline as<T>(): T {
|
|
366
|
+
return load<T>(changetype<usize>(this), STORAGE);
|
|
367
|
+
}
|
|
368
|
+
|
|
367
369
|
/**
|
|
368
370
|
* Converts the JSON.Value to a string representation.
|
|
369
371
|
* @returns The string representation of the JSON.Value.
|
|
@@ -552,7 +554,7 @@ export namespace JSON {
|
|
|
552
554
|
} else if (src instanceof Date) {
|
|
553
555
|
// @ts-ignore
|
|
554
556
|
inline.always(serializeDate(changetype<nonnull<T>>(src)));
|
|
555
|
-
} else if (src instanceof Array) {
|
|
557
|
+
} else if (src instanceof Array || src instanceof StaticArray) {
|
|
556
558
|
// @ts-ignore
|
|
557
559
|
serializeArray(changetype<nonnull<T>>(src));
|
|
558
560
|
} else if (src instanceof Map) {
|
|
@@ -733,7 +735,7 @@ export namespace JSON {
|
|
|
733
735
|
memory.copy(changetype<usize>(out) + 2, changetype<usize>(data.toISOString()), 48);
|
|
734
736
|
store<u16>(changetype<usize>(out), QUOTE, 50);
|
|
735
737
|
return changetype<string>(out);
|
|
736
|
-
} else if (data instanceof Array) {
|
|
738
|
+
} else if (data instanceof Array || data instanceof StaticArray) {
|
|
737
739
|
bs.saveState();
|
|
738
740
|
// @ts-ignore
|
|
739
741
|
inline.always(serializeArray(changetype<nonnull<T>>(data)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15-preview.1",
|
|
4
4
|
"author": "Jairus Tanaka",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@assemblyscript/wasi-shim": "^0.1.0",
|
|
12
12
|
"@types/node": "^22.15.24",
|
|
13
|
-
"assemblyscript": "^0.
|
|
13
|
+
"assemblyscript": "^0.28.1",
|
|
14
14
|
"assemblyscript-prettier": "^3.0.1",
|
|
15
15
|
"prettier": "^3.5.3",
|
|
16
16
|
"tsx": "^4.19.4",
|