Skip to content

Commit

Permalink
Merge pull request #1376 from balena-io/bump-balena-lint
Browse files Browse the repository at this point in the history
Update @balena/lint from 6.1.1 to 7.0.0
  • Loading branch information
flowzone-app[bot] authored Aug 23, 2023
2 parents 65b390c + ff13fd8 commit 3ee3f54
Show file tree
Hide file tree
Showing 55 changed files with 472 additions and 442 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: ['./node_modules/@balena/lint/config/.eslintrc.js'],
parserOptions: {
project: 'tsconfig.dev.json',
sourceType: 'module',
},
root: true,
rules: {
'no-restricted-imports': ['error', 'date-fns', 'lodash'],
},
};
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const gulp = require('gulp');
const gulpMocha = require('gulp-mocha');
const replace = require('gulp-replace');
Expand All @@ -13,7 +14,7 @@ const minify = uglifyComposer(uglifyJs, console);
const packageJSON = require('./package.json');

const cliOptions = minimist(process.argv.slice(2), {
string: 'buildDir',
string: 'buildDir', // eslint-disable-line id-denylist
default: { buildDir: 'es2015' },
});

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"build": "npm run lint && npm run build-es2015 && npm run build-es2018 && npm run docs",
"docs": "jsdoc2md --template doc/DOCUMENTATION.hbs --files \"es2015/**/!(balena-browser*.js)\" > DOCUMENTATION.md",
"ci": "npm test && catch-uncommitted",
"lint": "balena-lint -e js -e ts --tests typings src tests mjs_tests gulpfile.js",
"lint:fix": "balena-lint -e js -e ts --fix typings src tests mjs_tests gulpfile.js",
"lint": "balena-lint -e js -e ts --tests typing_tests typings src tests mjs_tests gulpfile.js",
"lint:fix": "balena-lint -e js -e ts --fix typing_tests typings src tests mjs_tests gulpfile.js",
"prepack": "npm run build",
"watch": "npm run build && watch \"npm run lint\" \"src\" \"tests\"",
"prepare": "husky install"
Expand All @@ -64,7 +64,7 @@
"node": ">=16.0"
},
"devDependencies": {
"@balena/lint": "^6.1.1",
"@balena/lint": "^7.0.1",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.4",
"@types/lodash": "^4.14.195",
Expand Down
13 changes: 7 additions & 6 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const getAuth = function (
* @namespace balena.auth.twoFactor
* @memberof balena.auth
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
const twoFactor = (require('./2fa') as typeof import('./2fa')).default(
{
...deps,
Expand All @@ -82,7 +83,7 @@ const getAuth = function (

const getActorDetails = async (noCache = false) => {
if (noCache) {
memoizedActorWhoami.clear();
await memoizedActorWhoami.clear();
}
try {
return await memoizedActorWhoami();
Expand Down Expand Up @@ -197,7 +198,7 @@ const getAuth = function (
email: string;
password: string;
}): Promise<void> {
memoizedActorWhoami.clear();
await memoizedActorWhoami.clear();
const token = await authenticate(credentials);
await auth.setKey(token);
}
Expand All @@ -217,8 +218,8 @@ const getAuth = function (
* @example
* balena.auth.loginWithToken(authToken);
*/
function loginWithToken(authToken: string): Promise<void> {
memoizedActorWhoami.clear();
async function loginWithToken(authToken: string): Promise<void> {
await memoizedActorWhoami.clear();
return auth.setKey(authToken);
}

Expand Down Expand Up @@ -345,8 +346,8 @@ const getAuth = function (
* @example
* balena.auth.logout();
*/
function logout(): Promise<void> {
memoizedActorWhoami.clear();
async function logout(): Promise<void> {
await memoizedActorWhoami.clear();
return auth.removeKey();
}

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const BALENA_SDK_HAS_USED_SHARED_OPTIONS = 'BALENA_SDK_HAS_USED_SHARED_OPTIONS';
const BALENA_SDK_HAS_SET_SHARED_OPTIONS = 'BALENA_SDK_HAS_SET_SHARED_OPTIONS';

const sdkTemplate = {
/* eslint-disable @typescript-eslint/no-var-requires */
auth() {
return (require('./auth') as typeof import('./auth')).default;
},
Expand All @@ -157,6 +158,7 @@ const sdkTemplate = {
settings() {
return (require('./settings') as typeof import('./settings')).default;
},
/* eslint-enable @typescript-eslint/no-var-requires */
};

export type BalenaSDK = {
Expand Down Expand Up @@ -208,6 +210,7 @@ export const getSdk = function ($opts?: SdkOptions) {
...$opts,
};

/* eslint-disable @typescript-eslint/no-var-requires */
const version = (
require('./util/sdk-version') as typeof import('./util/sdk-version')
).default;
Expand Down Expand Up @@ -270,6 +273,7 @@ export const getSdk = function ($opts?: SdkOptions) {
strict: true,
})(request.send);
}
/* eslint-enable @typescript-eslint/no-var-requires */
const pine = createPinejsClient({}, { ...opts, auth, request });
const pubsub = new PubSub();

Expand Down Expand Up @@ -377,6 +381,7 @@ export const getSdk = function ($opts?: SdkOptions) {
enumerable: true,
configurable: true,
get() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { mergePineOptions } = require('./util') as typeof import('./util');
return { mergePineOptions };
},
Expand Down
2 changes: 1 addition & 1 deletion src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { InjectedDependenciesParam, InjectedOptionsParam } from '.';
const AbortController: typeof window.AbortController =
'AbortController' in globalEnv
? globalEnv.AbortController
: // tslint:disable-next-line:no-var-requires
: // eslint-disable-next-line @typescript-eslint/no-var-requires
require('abortcontroller-polyfill/dist/cjs-ponyfill').AbortController;

export interface BaseLog {
Expand Down
2 changes: 1 addition & 1 deletion src/models/application-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const getApplicationInviteModel = function (
message,
};
if (roles) {
const [{ id: roleId }] = roles;
const roleId = roles[0]?.id;
// Throw if the user provided a roleName, but we didn't find that role
if (!roleId && roleName) {
throw new errors.BalenaApplicationMembershipRoleNotFound(roleName);
Expand Down
23 changes: 13 additions & 10 deletions src/models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const getApplicationModel = function (
} = deps;
const { apiUrl } = opts;

/* eslint-disable @typescript-eslint/no-var-requires */
const membershipModel = (
require('./application-membership') as typeof import('./application-membership')
).default(deps, (...args: Parameters<typeof exports.get>) =>
Expand All @@ -78,6 +79,17 @@ const getApplicationModel = function (
const { buildDependentResource } =
require('../util/dependent-resource') as typeof import('../util/dependent-resource');

const batchApplicationOperation = once(() =>
(
require('../util/request-batching') as typeof import('../util/request-batching')
).batchResourceOperationFactory<Application>({
getAll: exports.getAll,
NotFoundError: errors.BalenaApplicationNotFound,
AmbiguousResourceError: errors.BalenaAmbiguousApplication,
}),
);
/* eslint-enable @typescript-eslint/no-var-requires */

const tagsModel = buildDependentResource<ApplicationTag>(
{ pine },
{
Expand Down Expand Up @@ -139,6 +151,7 @@ const getApplicationModel = function (
},
},
);

const buildVarModel = buildDependentResource<BuildVariable>(
{ pine },
{
Expand All @@ -160,16 +173,6 @@ const getApplicationModel = function (
},
);

const batchApplicationOperation = once(() =>
(
require('../util/request-batching') as typeof import('../util/request-batching')
).batchResourceOperationFactory<Application>({
getAll: exports.getAll,
NotFoundError: errors.BalenaApplicationNotFound,
AmbiguousResourceError: errors.BalenaAmbiguousApplication,
}),
);

// Infer dashboardUrl from apiUrl if former is undefined
const dashboardUrl = opts.dashboardUrl ?? apiUrl!.replace(/api/, 'dashboard');

Expand Down
39 changes: 21 additions & 18 deletions src/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const getDeviceModel = function (
sdkInstance,
} = deps;
const { apiUrl, deviceUrlsBase } = opts;
/* eslint-disable @typescript-eslint/no-var-requires */
const registerDevice = once(() =>
(
require('balena-register-device') as typeof import('balena-register-device')
Expand All @@ -137,6 +138,24 @@ const getDeviceModel = function (
() => require('../util/date') as typeof import('../util/date'),
);

const batchDeviceOperation = once(() =>
(
require('../util/request-batching') as typeof import('../util/request-batching')
).batchResourceOperationFactory<Device>({
getAll,
NotFoundError: errors.BalenaDeviceNotFound,
AmbiguousResourceError: errors.BalenaAmbiguousDevice,
}),
);

const getOsUpdateHelper = once(async () => {
const $deviceUrlsBase = await getDeviceUrlsBase();
const { getOsUpdateHelper: _getOsUpdateHelper } =
require('../util/device-actions/os-update') as typeof import('../util/device-actions/os-update');
return _getOsUpdateHelper($deviceUrlsBase, request);
});
/* eslint-enable @typescript-eslint/no-var-requires */

const tagsModel = buildDependentResource<DeviceTag>(
{ pine },
{
Expand Down Expand Up @@ -191,16 +210,6 @@ const getDeviceModel = function (
},
);

const batchDeviceOperation = once(() =>
(
require('../util/request-batching') as typeof import('../util/request-batching')
).batchResourceOperationFactory<Device>({
getAll,
NotFoundError: errors.BalenaDeviceNotFound,
AmbiguousResourceError: errors.BalenaAmbiguousDevice,
}),
);

// Infer dashboardUrl from apiUrl if former is undefined
const dashboardUrl = opts.dashboardUrl ?? apiUrl!.replace(/api/, 'dashboard');

Expand All @@ -211,13 +220,6 @@ const getDeviceModel = function (
return (await sdkInstance.models.config.getAll()).deviceUrlsBase;
});

const getOsUpdateHelper = once(async () => {
const $deviceUrlsBase = await getDeviceUrlsBase();
const { getOsUpdateHelper: _getOsUpdateHelper } =
require('../util/device-actions/os-update') as typeof import('../util/device-actions/os-update');
return _getOsUpdateHelper($deviceUrlsBase, request);
});

// Internal method for uuid/id disambiguation
// Note that this throws an exception for missing uuids, but not missing ids
const getId = async (uuidOrId: string | number) => {
Expand Down Expand Up @@ -944,7 +946,8 @@ const getDeviceModel = function (
'is_undervolted',
],
});
// @ts-expect-error
// TODO: Drop the manual __metadata removal once we bump to the v7 model.
// @ts-expect-error __metadata isn't in the pine client typings
delete device.__metadata;
return device;
},
Expand Down
12 changes: 2 additions & 10 deletions src/models/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ limitations under the License.
*/

import * as errors from 'balena-errors';
import type {
Image,
PineOptions,
InjectedDependenciesParam,
InjectedOptionsParam,
} from '..';
import type { Image, PineOptions, InjectedDependenciesParam } from '..';
import { mergePineOptions } from '../util';
import { toWritable } from '../util/types';

const getImageModel = function (
deps: InjectedDependenciesParam,
_opts: InjectedOptionsParam,
) {
const getImageModel = function (deps: InjectedDependenciesParam) {
const { pine } = deps;
const exports = {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

/* eslint-disable @typescript-eslint/no-var-requires */
const modelsTemplate = {
/**
* @namespace application
Expand Down Expand Up @@ -100,6 +101,7 @@ const modelsTemplate = {
*/
billing: () => (require('./billing') as typeof import('./billing')).default,
};
/* eslint-enable @typescript-eslint/no-var-requires */

export = (deps: InjectedDependenciesParam, opts: InjectedOptionsParam) => {
const models = {} as {
Expand Down
2 changes: 1 addition & 1 deletion src/models/organization-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const getOrganizationInviteModel = function (
message,
};
if (roles) {
const [{ id: roleId }] = roles;
const roleId = roles[0]?.id;
// Throw if the user provided a roleName, but we didn't find that role
if (!roleId && roleName) {
throw new errors.BalenaOrganizationMembershipRoleNotFound(roleName);
Expand Down
7 changes: 6 additions & 1 deletion src/models/organization-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const getOrganizationMembershipModel = function (
const { pine } = deps;

const { buildDependentResource } =
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../util/dependent-resource') as typeof import('../util/dependent-resource');

const tagsModel = buildDependentResource<OrganizationMembershipTag>(
Expand All @@ -60,7 +61,11 @@ const getOrganizationMembershipModel = function (
resourceKeyField: 'tag_key',
parentResourceName: 'organization_membership',
async getResourceId(membershipId): Promise<number> {
// @ts-expect-error
if (typeof membershipId !== 'number') {
throw new Error(
`Unexpected type for membershipId provided in organization-membership tagsModel getResourceId: ${typeof membershipId}`,
);
}
const membership = await exports.get(membershipId);
return membership.id;
},
Expand Down
2 changes: 2 additions & 0 deletions src/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ const getOrganizationModel = function (
) {
const { pine } = deps;

/* eslint-disable @typescript-eslint/no-var-requires */
const membershipModel = (
require('./organization-membership') as typeof import('./organization-membership')
).default(deps, (...args: Parameters<typeof get>) => get(...args));

const inviteModel = (
require('./organization-invite') as typeof import('./organization-invite')
).default(deps, opts, (...args: Parameters<typeof get>) => get(...args));
/* eslint-enable @typescript-eslint/no-var-requires */

const getId = async (handleOrId: string | number) => {
const { id } = await get(handleOrId, { $select: 'id' });
Expand Down
17 changes: 8 additions & 9 deletions src/models/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ const getOsModel = function (
} = deps;
const { apiUrl, isBrowser } = opts;

const hupActionHelper = once(
() =>
(
require('../util/device-actions/os-update/utils') as typeof import('../util/device-actions/os-update/utils')
).hupActionHelper,
);
const hupActionHelper = once(() => {
const osUpdateUtils =
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../util/device-actions/os-update/utils') as typeof import('../util/device-actions/os-update/utils');
return osUpdateUtils.hupActionHelper;
});

const authDependentMemoizer = getAuthDependentMemoize(pubsub);

Expand Down Expand Up @@ -808,9 +808,8 @@ const getOsModel = function (
options.network = options.network ?? 'ethernet';

try {
const applicationId = await sdkInstance.models.application._getId(
slugOrUuidOrId,
);
const applicationId =
await sdkInstance.models.application._getId(slugOrUuidOrId);

const { body } = await request.send({
method: 'POST',
Expand Down
Loading

0 comments on commit 3ee3f54

Please sign in to comment.