Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release to master #26

Merged
merged 4 commits into from
Jul 5, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
.idea
10 changes: 5 additions & 5 deletions src/helpers/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function parseBoolean(val: string | undefined | null): boolean {
case 'no':
return false;
default:
throw new Error(`Cannot parse boolean from "${val}"`);
throw new Error(`Cannot parse boolean`);
}
}

Expand All @@ -64,10 +64,10 @@ export function hexToBuffer(hex: string): Buffer {
return Buffer.alloc(0);
}
if (!hex.startsWith('0x')) {
throw new Error(`Hex string is missing the "0x" prefix: "${hex}"`);
throw new Error(`Hex string is missing the "0x" prefix`);
}
if (hex.length % 2 !== 0) {
throw new Error(`Hex string is an odd number of digits: ${hex}`);
throw new Error(`Hex string is an odd number of digits`);
}
return Buffer.from(hex.substring(2), 'hex');
}
Expand All @@ -82,10 +82,10 @@ export function coerceToBuffer(hex: string | Buffer | ArrayBufferView): Buffer {
hex = hex.substring(2);
}
if (hex.length % 2 !== 0) {
throw new Error(`Hex string is an odd number of characters: ${hex}`);
throw new Error(`Hex string is an odd number of characters`);
}
if (!/^[0-9a-fA-F]*$/.test(hex)) {
throw new Error(`Hex string contains non-hexadecimal characters: ${hex}`);
throw new Error(`Hex string contains non-hexadecimal characters`);
}
return Buffer.from(hex, 'hex');
} else if (Buffer.isBuffer(hex)) {
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ export const PG_TYPE_MAPPINGS = {
if (/^(0x|0X)[a-fA-F0-9]*$/.test(x)) {
// hex string with "0x" prefix
if (x.length % 2 !== 0) {
throw new Error(`Hex string is an odd number of digits: "${x}"`);
throw new Error(`Hex string is an odd number of digits`);
}
return '\\x' + x.slice(2);
} else if (x.length === 0) {
return '\\x';
} else if (/^\\x[a-fA-F0-9]*$/.test(x)) {
// hex string with "\x" prefix (already encoded for postgres)
if (x.length % 2 !== 0) {
throw new Error(`Hex string is an odd number of digits: "${x}"`);
throw new Error(`Hex string is an odd number of digits`);
}
return x;
} else {
throw new Error(`String value for bytea column does not have 0x prefix: "${x}"`);
throw new Error(`String value for bytea column does not have 0x prefix`);
}
} else if (Buffer.isBuffer(x)) {
return '\\x' + x.toString('hex');
Expand Down
Loading