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 | 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) { 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 +} 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