Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
tellet-q committed Jan 7, 2025
1 parent badf61e commit 1d497a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 58 deletions.
40 changes: 11 additions & 29 deletions packages/js-client-grpc/src/client-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ export const ClientVersion = {

let major = undefined;
let minor = undefined;
try {
[major, minor] = version.split('.', 2);
major = major.trim();
minor = minor.trim();
major = parseInt(major, 10);
minor = parseInt(minor, 10);
} catch (error) {
throw new Error(`Unable to parse version, expected format: x.y[.z], found: ${version}`);
}

[major, minor] = version.split('.', 2);
major = parseInt(major, 10);
minor = parseInt(minor, 10);
if (isNaN(major) || isNaN(minor)) {
throw new Error(`Unable to parse version, expected format: x.y[.z], found: ${version}`);
}
Expand All @@ -45,30 +38,19 @@ export const ClientVersion = {
* @returns True if compatible, otherwise false.
*/
isCompatible(clientVersion: string, serverVersion: string): boolean {
if (!clientVersion) {
console.debug(`Unable to compare with client version: null`);
if (!clientVersion || !serverVersion) {
console.debug(
`Unable to compare versions with null values. Client: ${clientVersion}, Server: ${serverVersion}`,
);
return false;
}

if (!serverVersion) {
console.debug(`Unable to compare with server version: null`);
return false;
}

if (clientVersion === serverVersion) {
return true;
}
if (clientVersion === serverVersion) return true;

try {
const parsedClientVersion = ClientVersion.parseVersion(clientVersion);
const parsedServerVersion = ClientVersion.parseVersion(serverVersion);

const majorDiff = Math.abs(parsedClientVersion.major - parsedServerVersion.major);
if (majorDiff >= 1) {
return false;
}

return Math.abs(parsedClientVersion.minor - parsedServerVersion.minor) <= 1;
const client = ClientVersion.parseVersion(clientVersion);
const server = ClientVersion.parseVersion(serverVersion);
return client.major === server.major && Math.abs(client.minor - server.minor) <= 1;
} catch (error) {
console.debug(`Unable to compare versions: ${error as string}`);
return false;
Expand Down
40 changes: 11 additions & 29 deletions packages/js-client-rest/src/client-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ export const ClientVersion = {

let major = undefined;
let minor = undefined;
try {
[major, minor] = version.split('.', 2);
major = major.trim();
minor = minor.trim();
major = parseInt(major, 10);
minor = parseInt(minor, 10);
} catch (error) {
throw new Error(`Unable to parse version, expected format: x.y[.z], found: ${version}`);
}

[major, minor] = version.split('.', 2);
major = parseInt(major, 10);
minor = parseInt(minor, 10);
if (isNaN(major) || isNaN(minor)) {
throw new Error(`Unable to parse version, expected format: x.y[.z], found: ${version}`);
}
Expand All @@ -45,30 +38,19 @@ export const ClientVersion = {
* @returns True if compatible, otherwise false.
*/
isCompatible(clientVersion: string, serverVersion: string): boolean {
if (!clientVersion) {
console.debug(`Unable to compare with client version: null`);
if (!clientVersion || !serverVersion) {
console.debug(
`Unable to compare versions with null values. Client: ${clientVersion}, Server: ${serverVersion}`,
);
return false;
}

if (!serverVersion) {
console.debug(`Unable to compare with server version: null`);
return false;
}

if (clientVersion === serverVersion) {
return true;
}
if (clientVersion === serverVersion) return true;

try {
const parsedClientVersion = ClientVersion.parseVersion(clientVersion);
const parsedServerVersion = ClientVersion.parseVersion(serverVersion);

const majorDiff = Math.abs(parsedClientVersion.major - parsedServerVersion.major);
if (majorDiff >= 1) {
return false;
}

return Math.abs(parsedClientVersion.minor - parsedServerVersion.minor) <= 1;
const client = ClientVersion.parseVersion(clientVersion);
const server = ClientVersion.parseVersion(serverVersion);
return client.major === server.major && Math.abs(client.minor - server.minor) <= 1;
} catch (error) {
console.debug(`Unable to compare versions: ${error as string}`);
return false;
Expand Down

0 comments on commit 1d497a8

Please sign in to comment.