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.
Files changed (61) hide show
  1. package/.github/workflows/nodejs.yml +9 -10
  2. package/CHANGELOG +11 -2
  3. package/README.md +52 -7
  4. package/asconfig.json +24 -3
  5. package/assembly/__tests__/test.spec.ts +564 -0
  6. package/assembly/__tests__/types.ts +82 -0
  7. package/assembly/{src/chars.ts → chars.ts} +36 -36
  8. package/assembly/deserialize/array/array.ts +4 -4
  9. package/assembly/deserialize/array/bool.ts +4 -4
  10. package/assembly/deserialize/array/float.ts +4 -4
  11. package/assembly/deserialize/array/integer.ts +4 -4
  12. package/assembly/deserialize/array/map.ts +4 -4
  13. package/assembly/deserialize/array/object.ts +4 -4
  14. package/assembly/deserialize/array/string.ts +4 -4
  15. package/assembly/deserialize/array.ts +5 -4
  16. package/assembly/deserialize/bool.ts +4 -4
  17. package/assembly/deserialize/date.ts +2 -2
  18. package/assembly/deserialize/float.ts +2 -2
  19. package/assembly/deserialize/integer.ts +3 -3
  20. package/assembly/deserialize/map.ts +4 -4
  21. package/assembly/deserialize/mpz.ts +12 -0
  22. package/assembly/deserialize/object.ts +4 -4
  23. package/assembly/deserialize/string.ts +5 -5
  24. package/assembly/index.ts +25 -23
  25. package/assembly/serialize/array.ts +6 -5
  26. package/assembly/serialize/bool.ts +2 -2
  27. package/assembly/serialize/date.ts +2 -2
  28. package/assembly/serialize/float.ts +2 -2
  29. package/assembly/serialize/integer.ts +2 -2
  30. package/assembly/serialize/map.ts +8 -7
  31. package/assembly/serialize/mpz.ts +6 -0
  32. package/assembly/serialize/object.ts +2 -2
  33. package/assembly/serialize/string.ts +5 -5
  34. package/assembly/serialize/unknown.ts +5 -5
  35. package/assembly/test.ts +10 -47
  36. package/assembly/types.ts +4 -0
  37. package/assembly/{src/util.ts → util.ts} +3 -3
  38. package/bench/benchmark.ts +1 -1
  39. package/build/test.spec.wasm +0 -0
  40. package/build/test.spec.wasm.map +1 -0
  41. package/build/test.spec.wat +112616 -0
  42. package/build/test.wasm +0 -0
  43. package/build/test.wasm.map +1 -0
  44. package/build/test.wat +12267 -0
  45. package/package.json +13 -14
  46. package/transform/lib/visitor.js +516 -0
  47. package/transform/package.json +1 -1
  48. package/transform/src/visitor.ts +543 -0
  49. package/transform/tsconfig.json +23 -63
  50. package/tsconfig.json +13 -13
  51. package/as-pect.asconfig.json +0 -24
  52. package/as-pect.config.js +0 -30
  53. package/assembly/__tests__/deserialize.spec.ts +0 -301
  54. package/assembly/__tests__/serialize.spec.ts +0 -398
  55. package/assembly/deserialize/box.ts +0 -17
  56. package/assembly/serialize/box.ts +0 -11
  57. package/develop/assembly/serialize/unknown.ts +0 -46
  58. package/transform/lib/index.old.js +0 -257
  59. package/transform/lib/types.js +0 -17
  60. package/transform/src/index.old.ts +0 -312
  61. /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 Vec3 {
6
- x: f32 = 0.0;
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
- @json
16
- class Player {
17
- @alias("first name")
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
- const player: Player = {
33
- firstName: null,
34
- lastName: "West",
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));
@@ -0,0 +1,4 @@
1
+ @json
2
+ export class Vec3 {
3
+ x: f64 = 1.0;
4
+ }
@@ -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 StringSink();
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
- @global export function __atoi_fast<T extends number>(str: string, start: u32 = 0, end: u32 = 0): T {
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);
@@ -1,5 +1,5 @@
1
1
  import { bench, blackbox } from "as-bench/assembly/bench";
2
- import { __atoi_fast } from "../assembly/src/util";
2
+ import { __atoi_fast } from "../assembly/util";
3
3
  import { JSON } from "../assembly";
4
4
 
5
5
  @json
Binary file