json-as 0.9.16 → 0.9.17

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 CHANGED
@@ -24,6 +24,7 @@ v0.9.13 - Fix empty strings not indexing correctly
24
24
  v0.9.14 - Ignore properties of type Function
25
25
  v0.9.15 - Support JSON.Raw blocks
26
26
  v0.9.16 - JSON.Raw should be completely untouched
27
+ v0.9.17 - A schema's parent's fields should be included properly
27
28
 
28
29
  [UNRELEASED] v1.0.0
29
30
  - Allow nullable primitives
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  __| || __|| || | | ___ | _ || __|
4
4
  | | ||__ || | || | | ||___|| ||__ |
5
5
  |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.16
6
+ v0.9.17
7
7
  </pre>
8
8
  </h5>
9
9
 
package/assembly/test.ts CHANGED
@@ -1,33 +1,28 @@
1
1
  // import { JSON } from ".";
2
2
  import { JSON } from ".";
3
3
  @json
4
- class Vec3 {
5
- x: f32 = 0.0;
6
- y: f32 = 0.0;
7
- z: f32 = 0.0;
4
+ class Message {
5
+ constructor(role: string, content: string) {
6
+ this._role = role;
7
+ this.content = content;
8
+ }
9
+
10
+
11
+ @alias("role")
12
+ protected _role: string;
13
+
14
+ get role(): string {
15
+ return this._role;
16
+ }
17
+
18
+ content: string;
8
19
  }
9
20
 
10
21
  @json
11
- class Player {
12
- firstName!: string;
13
- lastName!: string;
14
- lastActive!: i32[];
15
- age!: i32;
16
- pos!: JSON.Raw;
17
- isVerified!: boolean;
22
+ class UserMessage extends Message {
23
+ constructor(content: string) {
24
+ super("user", content);
25
+ }
18
26
  }
19
-
20
- const player: Player = {
21
- firstName: "Emmet",
22
- lastName: "West",
23
- lastActive: [8, 27, 2022],
24
- age: 23,
25
- pos: "{\"x\":3.4,\"y\":1.2,\"z\":8.3}",
26
- isVerified: true
27
- };
28
-
29
- const stringified = JSON.stringify<Player>(player);
30
- console.log(stringified);
31
- console.log(idof<JSON.Raw>().toString());
32
- console.log(idof<string>().toString())
33
- // const parsed = JSON.parse<Player>(stringified);
27
+ console.log(JSON.stringify(new Message("user", "foo")))
28
+ console.log(JSON.stringify(new UserMessage("foo")));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.9.16",
3
+ "version": "0.9.17",
4
4
  "description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -31,10 +31,11 @@ class JSONTransform extends BaseVisitor {
31
31
  if (node.extendsType) {
32
32
  schema.parent = this.schemasList.find((v) => v.name == node.extendsType?.name.identifier.text);
33
33
  if (schema.parent?.members) {
34
- for (let i = 0; i < schema.parent.members.length; i++) {
34
+ for (let i = schema.parent.members.length - 1; i >= 0; i--) {
35
35
  const replace = schema.members.find((v) => v.name == schema.parent?.members[i]?.name);
36
36
  if (!replace) {
37
- schema.members.unshift(schema.parent.members[i]);
37
+ //schema.members.unshift(schema.parent?.members[i]!);
38
+ members.unshift(schema.parent?.members[i].node);
38
39
  }
39
40
  }
40
41
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.9.16",
3
+ "version": "0.9.17",
4
4
  "description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -48,12 +48,13 @@ class JSONTransform extends BaseVisitor {
48
48
  ) as SchemaData | null;
49
49
 
50
50
  if (schema.parent?.members) {
51
- for (let i = 0; i < schema.parent.members.length; i++) {
51
+ for (let i = schema.parent.members.length - 1; i >= 0; i--) {
52
52
  const replace = schema.members.find(
53
53
  (v) => v.name == schema.parent?.members[i]?.name
54
54
  );
55
55
  if (!replace) {
56
- schema.members.unshift(schema.parent.members[i]!);
56
+ //schema.members.unshift(schema.parent?.members[i]!);
57
+ members.unshift(schema.parent?.members[i]!.node);
57
58
  }
58
59
  }
59
60
  }