Skip to content

Commit f797fbe

Browse files
committed
Client version compatibility with API version as enum
1 parent baa134b commit f797fbe

File tree

9 files changed

+131
-26
lines changed

9 files changed

+131
-26
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ console.log(newsletter._response.status); // 200
112112
- [Namespace: `Cloudnode`](#namespace-cloudnode)
113113
- [Class: `Cloudnode.ApiResponse<T>`](#class-cloudnodeapiresponset)
114114
- [Class: `Cloudnode.RawResponse`](#class-cloudnoderawresponse)
115+
- [Enum: `Cloudnode.CompatibilityStatus`](#enum-cloudnodecompatibilitystatus)
115116
- [Interface: `Cloudnode.AccountDetails`](#interface-cloudnodeaccountdetails)
116117
- [Interface: `Cloudnode.AccountEmail`](#interface-cloudnodeaccountemail)
117118
- [Interface: `Cloudnode.AccountIdentity`](#interface-cloudnodeaccountidentity)
@@ -200,7 +201,7 @@ Get all other pages of paginated results and return the complete data
200201
Check compatibility with the API
201202

202203

203-
- 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)
204+
- Returns: <code>[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Cloudnode.CompatibilityStatus](#enum-cloudnodecompatibilitystatus)></code>
204205

205206

206207
<a name="cloudnodeaccountchangepasswordcurrentpassword-newpassword"></a>
@@ -685,6 +686,16 @@ Raw API response
685686
- `statusText` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The status message corresponding to the status code. (e.g., `OK` for `200`). (read-only)
686687
- `url` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> The URL of the response. (read-only)
687688

689+
<a name="enum-cloudnodecompatibilitystatus"></a>
690+
691+
### Enum: `Cloudnode.CompatibilityStatus`
692+
693+
API client compatibility status
694+
695+
- `COMPATIBLE` <code>"compatible"</code> Fully compatible (API patch version may differ)
696+
- `OUTDATED` <code>"outdated"</code> Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
697+
- `INCOMPATIBLE` <code>"incompatible"</code> API has implemented breaking changes which are not compatible with this client.
698+
688699
<a name="interface-cloudnodeaccountdetails"></a>
689700

690701
### Interface: `Cloudnode.AccountDetails`

browser/Cloudnode.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,13 @@ class Cloudnode {
150150
const verA = [partsA[0] || "0", partsA[1] || "0"];
151151
const verB = [partsB[0] || "0", partsB[1] || "0"];
152152
if (verA[0] !== verB[0])
153-
return "incompatible";
153+
return Cloudnode.CompatibilityStatus.INCOMPATIBLE;
154154
if (verA[1] !== verB[1])
155-
return "outdated";
156-
return "compatible";
155+
return Cloudnode.CompatibilityStatus.OUTDATED;
156+
return Cloudnode.CompatibilityStatus.COMPATIBLE;
157157
}
158158
/**
159159
* Check compatibility with the API
160-
* @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)
161160
*/
162161
async checkCompatibility() {
163162
const data = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
@@ -727,5 +726,23 @@ class Cloudnode {
727726
return Object.assign(new R.ApiResponse(response), data);
728727
}
729728
Cloudnode.makeApiResponse = makeApiResponse;
729+
/**
730+
* API client compatibility status
731+
*/
732+
let CompatibilityStatus;
733+
(function (CompatibilityStatus) {
734+
/**
735+
* Fully compatible (API patch version may differ)
736+
*/
737+
CompatibilityStatus["COMPATIBLE"] = "compatible";
738+
/**
739+
* Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
740+
*/
741+
CompatibilityStatus["OUTDATED"] = "outdated";
742+
/**
743+
* API has implemented breaking changes which are not compatible with this client.
744+
*/
745+
CompatibilityStatus["INCOMPATIBLE"] = "incompatible";
746+
})(CompatibilityStatus = Cloudnode.CompatibilityStatus || (Cloudnode.CompatibilityStatus = {}));
730747
})(Cloudnode || (Cloudnode = {}));
731748

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/DocSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace DocSchema {
100100
public readonly description: string;
101101
public readonly properties: (Property | Group)[];
102102

103-
constructor(name: string, type: "Class" | "Interface" | "Namespace", description: string, properties: Property[]) {
103+
constructor(name: string, type: "Class" | "Interface" | "Namespace" | "Enum", description: string, properties: Property[]) {
104104
super(name, type, undefined, true);
105105
this.description = description;
106106
this.properties = properties;
@@ -111,7 +111,7 @@ namespace DocSchema {
111111
}
112112

113113
public override content(config: Config, schema: Schema): string {
114-
return `${this.description}${["Interface", "Class"].includes(this.type) ? `\n\n${this.properties.map(p => " - " + p.inlineContent(config, schema)).join("\n")}` : ""}`;
114+
return `${this.description}${["Interface", "Class", "Enum"].includes(this.type) ? `\n\n${this.properties.map(p => " - " + p.inlineContent(config, schema)).join("\n")}` : ""}`;
115115
}
116116

117117
public inlineContent(): string {

gen/docs.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const globalTypes = {
3434
new DocSchema.Property("maxRetryDelay", "number", "The maximum number of seconds that is acceptable to wait before retrying a failed request.\nThis requires `autoRetry` to be enabled."),
3535
new DocSchema.Property("maxRetries", "number", "The maximum number of times to retry a failed request.\nThis requires `autoRetry` to be enabled.")
3636
]),
37+
compatibilityStatus: (config: Config) => new DocSchema.Group(config.name + ".CompatibilityStatus", "Enum", "API client compatibility status", [
38+
new DocSchema.Property("COMPATIBLE", '"compatible"', "Fully compatible (API patch version may differ)"),
39+
new DocSchema.Property("OUTDATED", '"outdated"', "Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features)."),
40+
new DocSchema.Property("INCOMPATIBLE", '"incompatible"', "API has implemented breaking changes which are not compatible with this client."),
41+
]),
42+
3743
} as const;
3844

3945
/**
@@ -53,6 +59,7 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
5359
mainNamespace.properties.push(globalTypes.apiResponse(config));
5460
mainNamespace.properties.push(globalTypes.rawResponse(config));
5561
mainNamespace.properties.push(globalTypes.options(config));
62+
mainNamespace.properties.push(globalTypes.compatibilityStatus(config));
5663
const operations: (Schema.Operation & {name: string})[] = [];
5764
for (const [name, operation] of Object.entries(schema.operations)) {
5865
if (operation.type === "operation") operations.push({name, ...operation});
@@ -104,8 +111,7 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
104111
description: "All of the data in 1 page"
105112
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
106113
always.push(new DocSchema.Method(`${config.instanceName}.checkCompatibility`, "Check compatibility with the API", [], {
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)"
114+
type: `Promise<Cloudnode.CompatibilityStatus>`
109115
}, []));
110116
mainClass.properties.unshift(...always);
111117
mainNamespace.properties.sort((a, b) => a.displayName.localeCompare(b.displayName));

gen/templates/main.mustache

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,20 @@ class {{config.name}} {
153153
* @param a First version
154154
* @param b Second version
155155
*/
156-
#compareVersions(a: string, b: string): "compatible" | "outdated" | "incompatible" {
156+
#compareVersions(a: string, b: string): Cloudnode.CompatibilityStatus {
157157
const partsA = a.split(".");
158158
const partsB = b.split(".");
159159
160160
const verA = [partsA[0] || "0", partsA[1] || "0"];
161161
const verB = [partsB[0] || "0", partsB[1] || "0"];
162162
163-
if (verA[0] !== verB[0]) return "incompatible";
164-
if (verA[1] !== verB[1]) return "outdated";
165-
return "compatible";
163+
if (verA[0] !== verB[0]) return Cloudnode.CompatibilityStatus.INCOMPATIBLE;
164+
if (verA[1] !== verB[1]) return Cloudnode.CompatibilityStatus.OUTDATED;
165+
return Cloudnode.CompatibilityStatus.COMPATIBLE;
166166
}
167167

168168
/**
169169
* Check compatibility with the API
170-
* @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)
171170
*/
172171
public async checkCompatibility() {
173172
const data: any = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
@@ -431,6 +430,26 @@ namespace {{config.name}} {
431430
*/
432431
maxRetries: number;
433432
}
433+
434+
/**
435+
* API client compatibility status
436+
*/
437+
export enum CompatibilityStatus {
438+
/**
439+
* Fully compatible (API patch version may differ)
440+
*/
441+
COMPATIBLE = "compatible",
442+
443+
/**
444+
* Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
445+
*/
446+
OUTDATED = "outdated",
447+
448+
/**
449+
* API has implemented breaking changes which are not compatible with this client.
450+
*/
451+
INCOMPATIBLE = "incompatible",
452+
}
434453
}
435454

436455
export default {{config.name}};

src/Cloudnode.d.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ declare class Cloudnode {
1313
constructor(token?: string, options?: Partial<Cloudnode.Options>);
1414
/**
1515
* Check compatibility with the API
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)
1716
*/
18-
checkCompatibility(): Promise<"compatible" | "outdated" | "incompatible">;
17+
checkCompatibility(): Promise<Cloudnode.CompatibilityStatus>;
1918
/**
2019
* Get another page of paginated results
2120
* @param response Response to get a different page of
@@ -939,5 +938,22 @@ declare namespace Cloudnode {
939938
*/
940939
maxRetries: number;
941940
}
941+
/**
942+
* API client compatibility status
943+
*/
944+
enum CompatibilityStatus {
945+
/**
946+
* Fully compatible (API patch version may differ)
947+
*/
948+
COMPATIBLE = "compatible",
949+
/**
950+
* Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
951+
*/
952+
OUTDATED = "outdated",
953+
/**
954+
* API has implemented breaking changes which are not compatible with this client.
955+
*/
956+
INCOMPATIBLE = "incompatible"
957+
}
942958
}
943959
export default Cloudnode;

src/Cloudnode.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,13 @@ class Cloudnode {
150150
const verA = [partsA[0] || "0", partsA[1] || "0"];
151151
const verB = [partsB[0] || "0", partsB[1] || "0"];
152152
if (verA[0] !== verB[0])
153-
return "incompatible";
153+
return Cloudnode.CompatibilityStatus.INCOMPATIBLE;
154154
if (verA[1] !== verB[1])
155-
return "outdated";
156-
return "compatible";
155+
return Cloudnode.CompatibilityStatus.OUTDATED;
156+
return Cloudnode.CompatibilityStatus.COMPATIBLE;
157157
}
158158
/**
159159
* Check compatibility with the API
160-
* @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)
161160
*/
162161
async checkCompatibility() {
163162
const data = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
@@ -727,5 +726,23 @@ class Cloudnode {
727726
return Object.assign(new R.ApiResponse(response), data);
728727
}
729728
Cloudnode.makeApiResponse = makeApiResponse;
729+
/**
730+
* API client compatibility status
731+
*/
732+
let CompatibilityStatus;
733+
(function (CompatibilityStatus) {
734+
/**
735+
* Fully compatible (API patch version may differ)
736+
*/
737+
CompatibilityStatus["COMPATIBLE"] = "compatible";
738+
/**
739+
* Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
740+
*/
741+
CompatibilityStatus["OUTDATED"] = "outdated";
742+
/**
743+
* API has implemented breaking changes which are not compatible with this client.
744+
*/
745+
CompatibilityStatus["INCOMPATIBLE"] = "incompatible";
746+
})(CompatibilityStatus = Cloudnode.CompatibilityStatus || (Cloudnode.CompatibilityStatus = {}));
730747
})(Cloudnode || (Cloudnode = {}));
731748
export default Cloudnode;

src/Cloudnode.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,20 @@ class Cloudnode {
153153
* @param a First version
154154
* @param b Second version
155155
*/
156-
#compareVersions(a: string, b: string): "compatible" | "outdated" | "incompatible" {
156+
#compareVersions(a: string, b: string): Cloudnode.CompatibilityStatus {
157157
const partsA = a.split(".");
158158
const partsB = b.split(".");
159159

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

163-
if (verA[0] !== verB[0]) return "incompatible";
164-
if (verA[1] !== verB[1]) return "outdated";
165-
return "compatible";
163+
if (verA[0] !== verB[0]) return Cloudnode.CompatibilityStatus.INCOMPATIBLE;
164+
if (verA[1] !== verB[1]) return Cloudnode.CompatibilityStatus.OUTDATED;
165+
return Cloudnode.CompatibilityStatus.COMPATIBLE;
166166
}
167167

168168
/**
169169
* Check compatibility with the API
170-
* @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)
171170
*/
172171
public async checkCompatibility() {
173172
const data: any = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
@@ -1213,6 +1212,26 @@ namespace Cloudnode {
12131212
*/
12141213
maxRetries: number;
12151214
}
1215+
1216+
/**
1217+
* API client compatibility status
1218+
*/
1219+
export enum CompatibilityStatus {
1220+
/**
1221+
* Fully compatible (API patch version may differ)
1222+
*/
1223+
COMPATIBLE = "compatible",
1224+
1225+
/**
1226+
* Compatible, but outdated (i.e. existing APIs will work, but you are missing out on new features).
1227+
*/
1228+
OUTDATED = "outdated",
1229+
1230+
/**
1231+
* API has implemented breaking changes which are not compatible with this client.
1232+
*/
1233+
INCOMPATIBLE = "incompatible",
1234+
}
12161235
}
12171236

12181237
export default Cloudnode;

0 commit comments

Comments
 (0)