From b76bdb4bea6cb9bd9d0a417ba89e83d4e8793b2e Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 22 Dec 2024 15:24:39 +0000 Subject: [PATCH 1/4] chore: String is part of Borsh spec and is UTF-8 and capitalized, so make it just be exact as borsh spec --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aaf002fc..a1b34e8e 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ class SomeClass @field({type: 'u64'}) y: bigint - @field({type: 'string'}) + @field({type: 'String'}) z: string @field({type: option(vec('u32'))}) @@ -117,7 +117,7 @@ class TestStruct { } ``` -Variants can be 'number', 'number[]' (represents nested Rust Enums) or 'string' (not part of the Borsh specification). i.e. +Variants can be 'number', 'number[]' (represents nested Rust Enums) or 'String' (not part of the Borsh specification). i.e. ```typescript @variant(0) @@ -154,7 +154,7 @@ class TestStruct { *With Borsh specification, string sizes will be encoded with 'u32'* ```typescript class TestStruct { - @field({ type: 'string' }) + @field({ type: 'String' }) public string: string; } ``` @@ -365,7 +365,7 @@ validate([TestStruct]) | `f32` float | `number` | | `f64` float | `number` | | byte arrays | `Uint8Array` | -| UTF-8 string | `string` | +| String | `string` | | option | `undefined` or type | | map | N/A | | set | N/A | From 478bc625f72f5288dfc8427e33e4a9c253fb12c7 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 22 Dec 2024 15:25:51 +0000 Subject: [PATCH 2/4] fixed codegen --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index caefaf3f..8a993d38 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,7 +49,7 @@ export type IntegerType = export type FloatType = 'f32' | 'f64'; export type PrimitiveType = "bool" - | "string" + | "String" | IntegerType | FloatType From fde1317544dce0f402cea0525d6c695b16f01351 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 22 Dec 2024 15:28:04 +0000 Subject: [PATCH 3/4] more fixes --- src/binary.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/binary.ts b/src/binary.ts index e5e7aae0..3e6854c2 100644 --- a/src/binary.ts +++ b/src/binary.ts @@ -275,7 +275,7 @@ export class BinaryWriter { else if (encoding === 'f64') { return BinaryWriter.f64 } - else if (encoding === 'string') { + else if (encoding === 'String') { return BinaryWriter.string } else { @@ -508,7 +508,7 @@ export class BinaryReader { else if (encoding === 'u512') { return BinaryReader.u512 } - else if (encoding === 'string') { + else if (encoding === 'String') { return fromBuffer ? BinaryReader.bufferString : BinaryReader.string } else if (encoding === 'bool') { @@ -550,4 +550,4 @@ export class BinaryReader { } return result; } -} \ No newline at end of file +} From a7b224ffc327aaf3328a73f68734d97dfe15b9a9 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sun, 22 Dec 2024 15:29:46 +0000 Subject: [PATCH 4/4] more strings --- src/__tests__/index.test.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 8b0a58bf..73e902fd 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -440,7 +440,7 @@ describe("arrays", () => { test("can deserialize large arrays", () => { class TestStruct { - @field({ type: vec("string") }) + @field({ type: vec("String") }) public a: string[]; } const size = 1024 * 1024 + 100; @@ -1279,7 +1279,7 @@ describe("enum", () => { test("enum string variant", () => { class Ape { - @field({ type: "string" }) + @field({ type: "String" }) name: string; constructor(name?: string) { @@ -1387,7 +1387,7 @@ describe("option", () => { test("empty string option", () => { class TestStruct { - @field({ type: option("string") }) + @field({ type: option("String") }) string: string; constructor(string: string) { @@ -1429,15 +1429,15 @@ describe("option", () => { }); }); -describe("string", () => { +describe("String", () => { class TestStruct { - @field({ type: "string" }) + @field({ type: "String" }) public a: string; @field({ type: "u8" }) public b: number; - @field({ type: "string" }) + @field({ type: "String" }) public c: string; constructor(a: string, b: number, c: string) { @@ -1934,8 +1934,8 @@ describe("discriminator", () => { @variant("abc") class D extends C { - @field({ type: "string" }) - string: string = "string"; + @field({ type: "String" }) + string: string = "String"; } const discriminator = getDiscriminator(D); @@ -1947,8 +1947,8 @@ describe("discriminator", () => { test("will reject for undefined behahiour, with super variant", () => { @variant([1, 2]) class A { - @field({ type: "string" }) - string: string = "string"; + @field({ type: "String" }) + string: string = "String"; } @variant(3) class B extends A {} @@ -1957,8 +1957,8 @@ describe("discriminator", () => { test("will reject for undefined behahiour, without super variant", () => { class A { - @field({ type: "string" }) - string: string = "string"; + @field({ type: "String" }) + string: string = "String"; } @variant(3) class B extends A {} @@ -2019,12 +2019,12 @@ describe("Validation", () => { } class A extends Super { - @field({ type: "string" }) + @field({ type: "String" }) string: string; } class B extends Super { - @field({ type: "string" }) + @field({ type: "String" }) string: string; } expect(() => validate(Super)).toThrowError(BorshError); @@ -2118,12 +2118,12 @@ describe("Validation", () => { } class A extends TestStruct { - @field({ type: "string" }) + @field({ type: "String" }) string: string = "A"; } class B extends TestStruct { - @field({ type: "string" }) + @field({ type: "String" }) string: string = "B"; } expect(() => @@ -2252,7 +2252,7 @@ describe("Validation", () => { describe("deserialize input type", () => { test("buffer compat", () => { class Clazz { - @field({ type: "string" }) + @field({ type: "String" }) string: string; constructor(string?: string) { @@ -2311,7 +2311,7 @@ describe("deserialize input type", () => { test("can alternate between", () => { class Clazz { - @field({ type: option("string") }) + @field({ type: option("String") }) string?: string; constructor(string?: string) {