From faf21104813609b6596fdf491e3468fed508002a Mon Sep 17 00:00:00 2001 From: Jairus Date: Mon, 22 Jul 2024 11:42:11 -0700 Subject: [PATCH] fix: schema parents should be added properly --- assembly/test.ts | 47 +++++++++++++++++++----------------------- transform/lib/index.js | 5 +++-- transform/src/index.ts | 5 +++-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/assembly/test.ts b/assembly/test.ts index d6c2b43..d89567f 100644 --- a/assembly/test.ts +++ b/assembly/test.ts @@ -1,33 +1,28 @@ // import { JSON } from "."; import { JSON } from "."; @json -class Vec3 { - x: f32 = 0.0; - y: f32 = 0.0; - z: f32 = 0.0; +class Message { + constructor(role: string, content: string) { + this._role = role; + this.content = content; + } + + + @alias("role") + protected _role: string; + + get role(): string { + return this._role; + } + + content: string; } @json -class Player { - firstName!: string; - lastName!: string; - lastActive!: i32[]; - age!: i32; - pos!: JSON.Raw; - isVerified!: boolean; +class UserMessage extends Message { + constructor(content: string) { + super("user", content); + } } - -const player: Player = { - firstName: "Emmet", - lastName: "West", - lastActive: [8, 27, 2022], - age: 23, - pos: "{\"x\":3.4,\"y\":1.2,\"z\":8.3}", - isVerified: true -}; - -const stringified = JSON.stringify(player); -console.log(stringified); -console.log(idof().toString()); -console.log(idof().toString()) -// const parsed = JSON.parse(stringified); \ No newline at end of file +console.log(JSON.stringify(new Message("user", "foo"))) +console.log(JSON.stringify(new UserMessage("foo"))); \ No newline at end of file diff --git a/transform/lib/index.js b/transform/lib/index.js index 2428303..a39308f 100644 --- a/transform/lib/index.js +++ b/transform/lib/index.js @@ -31,10 +31,11 @@ class JSONTransform extends BaseVisitor { if (node.extendsType) { schema.parent = this.schemasList.find((v) => v.name == node.extendsType?.name.identifier.text); if (schema.parent?.members) { - for (let i = 0; i < schema.parent.members.length; i++) { + for (let i = schema.parent.members.length - 1; i >= 0; i--) { const replace = schema.members.find((v) => v.name == schema.parent?.members[i]?.name); if (!replace) { - schema.members.unshift(schema.parent.members[i]); + //schema.members.unshift(schema.parent?.members[i]!); + members.unshift(schema.parent?.members[i].node); } } } diff --git a/transform/src/index.ts b/transform/src/index.ts index 875b84d..6b17b70 100644 --- a/transform/src/index.ts +++ b/transform/src/index.ts @@ -48,12 +48,13 @@ class JSONTransform extends BaseVisitor { ) as SchemaData | null; if (schema.parent?.members) { - for (let i = 0; i < schema.parent.members.length; i++) { + for (let i = schema.parent.members.length - 1; i >= 0; i--) { const replace = schema.members.find( (v) => v.name == schema.parent?.members[i]?.name ); if (!replace) { - schema.members.unshift(schema.parent.members[i]!); + //schema.members.unshift(schema.parent?.members[i]!); + members.unshift(schema.parent?.members[i]!.node); } } }