Skip to content

Commit d4afe7d

Browse files
author
William Duncan
committed
more statuses in compatibility check
1 parent 53e45cc commit d4afe7d

File tree

8 files changed

+30
-18
lines changed

8 files changed

+30
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Get all other pages of paginated results and return the complete data
192192
Check compatibility with the API
193193

194194

195-
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)></code> True if this client is compatible with the API server
195+
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;"compatible" | "outdated" | "incompatible"></code> `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
196196

197197

198198
<a name="cloudnodeaccountchangepasswordcurrentpassword-newpassword"></a>

browser/Cloudnode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ class Cloudnode {
150150
const partsB = b.split(".");
151151
const verA = [partsA[0] || "0", partsA[1] || "0"];
152152
const verB = [partsB[0] || "0", partsB[1] || "0"];
153-
return verA[0] === verB[0] && verA[1] === verB[1];
153+
if (verA[0] !== verB[0])
154+
return "incompatible";
155+
if (verA[1] !== verB[1])
156+
return "outdated";
157+
return "compatible";
154158
}
155159
/**
156160
* Check compatibility with the API
157-
* @returns True if this client is compatible with the API server
161+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
158162
*/
159163
async checkCompatibility() {
160164
const data = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {

browser/Cloudnode.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/docs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
104104
description: "All of the data in 1 page"
105105
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
106106
always.push(new DocSchema.Method(`${config.instanceName}.checkCompatibility`, "Check compatibility with the API", [], {
107-
type: `Promise<boolean>`,
108-
description: "True if this client is compatible with the API server"
107+
type: `Promise<"compatible" | "outdated" | "incompatible">`,
108+
description: "`compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)"
109109
}, []));
110110
mainClass.properties.unshift(...always);
111111
mainNamespace.properties.sort((a, b) => a.displayName.localeCompare(b.displayName));

gen/templates/main.mustache

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,23 @@ class {{config.name}} {
154154
* @param a First version
155155
* @param b Second version
156156
*/
157-
#compareVersions(a: string, b: string): boolean {
157+
#compareVersions(a: string, b: string): "compatible" | "outdated" | "incompatible" {
158158
const partsA = a.split(".");
159159
const partsB = b.split(".");
160160
161161
const verA = [partsA[0] || "0", partsA[1] || "0"];
162162
const verB = [partsB[0] || "0", partsB[1] || "0"];
163163
164-
return verA[0] === verB[0] && verA[1] === verB[1];
164+
if (verA[0] !== verB[0]) return "incompatible";
165+
if (verA[1] !== verB[1]) return "outdated";
166+
return "compatible";
165167
}
166168

167169
/**
168170
* Check compatibility with the API
169-
* @returns True if this client is compatible with the API server
171+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
170172
*/
171-
public async checkCompatibility(): Promise<boolean> {
173+
public async checkCompatibility() {
172174
const data: any = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
173175
method: "GET",
174176
headers: {

src/Cloudnode.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ declare class Cloudnode {
1313
constructor(token?: string, options?: Partial<Cloudnode.Options>);
1414
/**
1515
* Check compatibility with the API
16-
* @returns True if this client is compatible with the API server
16+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
1717
*/
18-
checkCompatibility(): Promise<boolean>;
18+
checkCompatibility(): Promise<"compatible" | "outdated" | "incompatible">;
1919
/**
2020
* Get another page of paginated results
2121
* @param response Response to get a different page of

src/Cloudnode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ class Cloudnode {
150150
const partsB = b.split(".");
151151
const verA = [partsA[0] || "0", partsA[1] || "0"];
152152
const verB = [partsB[0] || "0", partsB[1] || "0"];
153-
return verA[0] === verB[0] && verA[1] === verB[1];
153+
if (verA[0] !== verB[0])
154+
return "incompatible";
155+
if (verA[1] !== verB[1])
156+
return "outdated";
157+
return "compatible";
154158
}
155159
/**
156160
* Check compatibility with the API
157-
* @returns True if this client is compatible with the API server
161+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
158162
*/
159163
async checkCompatibility() {
160164
const data = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {

src/Cloudnode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,23 @@ class Cloudnode {
154154
* @param a First version
155155
* @param b Second version
156156
*/
157-
#compareVersions(a: string, b: string): boolean {
157+
#compareVersions(a: string, b: string): "compatible" | "outdated" | "incompatible" {
158158
const partsA = a.split(".");
159159
const partsB = b.split(".");
160160

161161
const verA = [partsA[0] || "0", partsA[1] || "0"];
162162
const verB = [partsB[0] || "0", partsB[1] || "0"];
163163

164-
return verA[0] === verB[0] && verA[1] === verB[1];
164+
if (verA[0] !== verB[0]) return "incompatible";
165+
if (verA[1] !== verB[1]) return "outdated";
166+
return "compatible";
165167
}
166168

167169
/**
168170
* Check compatibility with the API
169-
* @returns True if this client is compatible with the API server
171+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
170172
*/
171-
public async checkCompatibility(): Promise<boolean> {
173+
public async checkCompatibility() {
172174
const data: any = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
173175
method: "GET",
174176
headers: {

0 commit comments

Comments
 (0)