Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
joshbwlng committed Jun 4, 2024
1 parent 61d5878 commit 952f52b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/types/big-integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const types = {
},
};

export type Types = TypeUtils.TsTypes<bigint, bigint>;
export type Types = TypeUtils.TsTypes<bigint, number | bigint>;
type DbWriteType = bigint;

export const fetchProcessing: TypeUtils.FetchProcessing<Types['Read']> = (
Expand All @@ -18,14 +18,15 @@ export const fetchProcessing: TypeUtils.FetchProcessing<Types['Read']> = (
if (data == null) {
return data;
}

let value: bigint;
if (typeof data === 'bigint') {
return data;
value = data;
} else if (typeof data === 'string' || typeof data === 'number') {
return BigInt(data);
value = BigInt(data);
} else {
throw new Error('Fetched bigint is not valid: ' + typeof data);
}

throw new Error('Fetched bigint is not valid: ' + typeof data);
return value;
};

export const nativeFactTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/types/big-serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const types = {
},
};

export type Types = TypeUtils.TsTypes<bigint, bigint>;
export type Types = TypeUtils.TsTypes<bigint, number | bigint>;
type DbWriteType = bigint;

export const validate: TypeUtils.Validate<Types['Write'], DbWriteType> =
Expand Down
1 change: 1 addition & 0 deletions test/Big Integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ helpers.describe('Big Integer', (test) => {
test.fetch('1', BigInt(1));
test.fetch(BigInt(testBigIntString), BigInt(testBigIntString));
test.fetch(testBigIntString, BigInt(testBigIntString));
test.fetch({}, new Error('Fetched bigint is not valid: object'));
});

describe('validate', function () {
Expand Down

0 comments on commit 952f52b

Please sign in to comment.