Skip to content

Commit

Permalink
Drop os.getLastModified as it has not worked for a while and is unused
Browse files Browse the repository at this point in the history
Change-type: major
  • Loading branch information
myarmolinsky committed Dec 10, 2024
1 parent 7b3f502 commit 5c2d34a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 119 deletions.
26 changes: 0 additions & 26 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ const sdk = fromSharedOptions();
* [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ <code>Promise</code>
* [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ <code>Promise</code>
* [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ <code>Promise</code>
* [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ <code>Promise</code>
* [.download(options)](#balena.models.os.download) ⇒ <code>Promise</code>
* [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ <code>Promise</code>
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -761,7 +760,6 @@ balena.models.device.get(123).catch(function (error) {
* [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ <code>Promise</code>
* [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ <code>Promise</code>
* [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ <code>Promise</code>
* [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ <code>Promise</code>
* [.download(options)](#balena.models.os.download) ⇒ <code>Promise</code>
* [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ <code>Promise</code>
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -5117,7 +5115,6 @@ balena.models.organization.remove(123);
* [.getAllOsVersions(deviceTypes, [options])](#balena.models.os.getAllOsVersions) ⇒ <code>Promise</code>
* [.getDownloadSize(deviceType, [version])](#balena.models.os.getDownloadSize) ⇒ <code>Promise</code>
* [.getMaxSatisfyingVersion(deviceType, versionOrRange, [osType])](#balena.models.os.getMaxSatisfyingVersion) ⇒ <code>Promise</code>
* [.getLastModified(deviceType, [version])](#balena.models.os.getLastModified) ⇒ <code>Promise</code>
* [.download(options)](#balena.models.os.download) ⇒ <code>Promise</code>
* [.getConfig(slugOrUuidOrId, options)](#balena.models.os.getConfig) ⇒ <code>Promise</code>
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -5215,29 +5212,6 @@ balena.models.os.getMaxSatisfyingVersion('raspberry-pi', '^2.11.0').then(functio
console.log(version);
});
```
<a name="balena.models.os.getLastModified"></a>

##### os.getLastModified(deviceType, [version]) ⇒ <code>Promise</code>
**Kind**: static method of [<code>os</code>](#balena.models.os)
**Summary**: Get the OS image last modified date
**Access**: public
**Fulfil**: <code>Date</code> - last modified date

| Param | Type | Description |
| --- | --- | --- |
| deviceType | <code>String</code> | device type slug |
| [version] | <code>String</code> | semver-compatible version or 'latest', defaults to 'latest'. Unsupported (unpublished) version will result in rejection. The version **must** be the exact version number. To resolve the semver-compatible range use `balena.model.os.getMaxSatisfyingVersion`. |

**Example**
```js
balena.models.os.getLastModified('raspberry-pi').then(function(date) {
console.log('The raspberry-pi image was last modified in ' + date);
});

balena.models.os.getLastModified('raspberrypi3', '2.0.0').then(function(date) {
console.log('The raspberry-pi image was last modified in ' + date);
});
```
<a name="balena.models.os.download"></a>

##### os.download(options) ⇒ <code>Promise</code>
Expand Down
52 changes: 0 additions & 52 deletions src/models/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,57 +619,6 @@ const getOsModel = function (
return _getMaxSatisfyingVersion(versionOrRange, osVersions) ?? null;
};

/**
* @summary Get the OS image last modified date
* @name getLastModified
* @public
* @function
* @memberof balena.models.os
*
* @param {String} deviceType - device type slug
* @param {String} [version] - semver-compatible version or 'latest', defaults to 'latest'.
* Unsupported (unpublished) version will result in rejection.
* The version **must** be the exact version number.
* To resolve the semver-compatible range use `balena.model.os.getMaxSatisfyingVersion`.
* @fulfil {Date} - last modified date
* @returns {Promise}
*
* @example
* balena.models.os.getLastModified('raspberry-pi').then(function(date) {
* console.log('The raspberry-pi image was last modified in ' + date);
* });
*
* balena.models.os.getLastModified('raspberrypi3', '2.0.0').then(function(date) {
* console.log('The raspberry-pi image was last modified in ' + date);
* });
*/
const getLastModified = async function (
deviceType: string,
version = 'latest',
): Promise<Date | null> {
try {
deviceType = await _getNormalizedDeviceTypeSlug(deviceType);
version = normalizeVersion(version);
const response = await request.send({
method: 'HEAD',
url: '/download',
qs: {
deviceType,
version,
},
baseUrl: apiUrl,
});

const lastModified = response.headers.get('last-modified');
return lastModified != null ? new Date(lastModified) : lastModified;
} catch (err) {
if (isNotFoundResponse(err)) {
throw new Error('No such version for the device type');
}
throw err;
}
};

/**
* @summary Download an OS image
* @name download
Expand Down Expand Up @@ -1054,7 +1003,6 @@ const getOsModel = function (
getAvailableOsVersions,
getMaxSatisfyingVersion,
getDownloadSize,
getLastModified,
download,
getConfig,
isSupportedOsUpdate,
Expand Down
41 changes: 0 additions & 41 deletions tests/integration/models/os.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,47 +705,6 @@ describe('OS model', function () {
});
});

describe('balena.models.os.getLastModified()', function () {
parallel('given a valid device slug', function () {
it('should eventually be a valid Date instance', async function () {
const lastModified =
await balena.models.os.getLastModified('raspberry-pi');
expect(lastModified).to.be.an.instanceof(Date);
});

it('should eventually be a valid Date instance if passing a device type alias', async function () {
const lastModified =
await balena.models.os.getLastModified('raspberrypi');
expect(lastModified).to.be.an.instanceof(Date);
});

it('should be able to query for a specific version', async function () {
const lastModified = await balena.models.os.getLastModified(
'raspberrypi',
'1.26.1',
);
expect(lastModified).to.be.an.instanceof(Date);
});

it('should be able to query for a version containing a plus', async function () {
const lastModified = await balena.models.os.getLastModified(
'raspberrypi',
'2.0.6+rev3.prod',
);
expect(lastModified).to.be.an.instanceof(Date);
});
});

describe('given an invalid device slug', () => {
it('should be rejected with an error message', async function () {
const promise = balena.models.os.getLastModified('foo-bar-baz');
await expect(promise).to.be.rejectedWith(
'Invalid device type: foo-bar-baz',
);
});
});
});

describe('balena.models.os.download()', function () {
if (IS_BROWSER) {
return;
Expand Down

0 comments on commit 5c2d34a

Please sign in to comment.