Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SomeClass
@field({type: 'u64'})
y: bigint

@field({type: 'string'})
@field({type: 'String'})
z: string

@field({type: option(vec('u32'))})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
```
Expand Down Expand Up @@ -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 |
Expand Down
36 changes: 18 additions & 18 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1279,7 +1279,7 @@ describe("enum", () => {

test("enum string variant", () => {
class Ape {
@field({ type: "string" })
@field({ type: "String" })
name: string;

constructor(name?: string) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 {}
Expand All @@ -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 {}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(() =>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -550,4 +550,4 @@ export class BinaryReader {
}
return result;
}
}
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type IntegerType =
export type FloatType = 'f32' | 'f64';

export type PrimitiveType = "bool"
| "string"
| "String"
| IntegerType
| FloatType

Expand Down