Skip to content

Commit 8310269

Browse files
committed
chore: add jsdocs to semver functions
1 parent efcf981 commit 8310269

File tree

1 file changed

+31
-10
lines changed
  • packages/opentelemetry-api/src/internal

1 file changed

+31
-10
lines changed

packages/opentelemetry-api/src/internal/semver.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,29 @@ import { VERSION } from '../version';
1818

1919
const re = /^(\d+)\.(\d+)\.(\d+)(?:-(.*))?$/;
2020

21+
/**
22+
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
23+
*
24+
* The returned function has the following semantics:
25+
* - Exact match is always compatible
26+
* - Major versions must always match
27+
* - The minor version of the API module requesting access to the global API must be greater or equal to the minor version of this API
28+
* - Patch and build tag differences are not considered at this time
29+
*
30+
* @param ownVersion version which should be checked against
31+
*/
2132
export function _makeCompatibilityCheck(
22-
myVersion: string
33+
ownVersion: string
2334
): (version: string) => boolean {
24-
const acceptedVersions = new Set<string>([myVersion]);
35+
const acceptedVersions = new Set<string>([ownVersion]);
2536
const rejectedVersions = new Set<string>();
2637

27-
const myVersionMatch = myVersion.match(re);
38+
const myVersionMatch = ownVersion.match(re);
2839
if (!myVersionMatch) {
2940
throw new Error('Cannot parse own version');
3041
}
3142

32-
const ownVersion = {
43+
const ownVersionParsed = {
3344
major: +myVersionMatch[1],
3445
minor: +myVersionMatch[2],
3546
patch: +myVersionMatch[3],
@@ -51,26 +62,26 @@ export function _makeCompatibilityCheck(
5162
return false;
5263
}
5364

54-
const other = {
65+
const otherVersionParsed = {
5566
major: +m[1],
5667
minor: +m[2],
5768
patch: +m[3],
5869
};
5970

6071
// major versions must match
61-
if (ownVersion.major != other.major) {
72+
if (ownVersionParsed.major != otherVersionParsed.major) {
6273
rejectedVersions.add(version);
6374
return false;
6475
}
6576

6677
// if major version is 0, minor is treated like major and patch is treated like minor
67-
if (ownVersion.major === 0) {
68-
if (ownVersion.minor != other.minor) {
78+
if (ownVersionParsed.major === 0) {
79+
if (ownVersionParsed.minor != otherVersionParsed.minor) {
6980
rejectedVersions.add(version);
7081
return false;
7182
}
7283

73-
if (ownVersion.patch < other.patch) {
84+
if (ownVersionParsed.patch < otherVersionParsed.patch) {
7485
rejectedVersions.add(version);
7586
return false;
7687
}
@@ -79,7 +90,7 @@ export function _makeCompatibilityCheck(
7990
return true;
8091
}
8192

82-
if (ownVersion.minor < other.minor) {
93+
if (ownVersionParsed.minor < otherVersionParsed.minor) {
8394
rejectedVersions.add(version);
8495
return false;
8596
}
@@ -89,4 +100,14 @@ export function _makeCompatibilityCheck(
89100
};
90101
}
91102

103+
/**
104+
* Test an API version to see if it is compatible with this API.
105+
*
106+
* - Exact match is always compatible
107+
* - Major versions must always match
108+
* - The minor version of the API module requesting access to the global API must be greater or equal to the minor version of this API
109+
* - Patch and build tag differences are not considered at this time
110+
*
111+
* @param version version of the API requesting an instance of the global API
112+
*/
92113
export const isCompatible = _makeCompatibilityCheck(VERSION);

0 commit comments

Comments
 (0)