Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deviceTypes: Rename and deprecate some helpers for clarity #1749

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function onInitHooks() {
_.flatMap(auth.KEYS, 'permissions'),
);
const { setSyncSettings } = await import('./src/features/contracts/index.js');
const { getAccessibleDeviceTypes } = await import(
const { getAccessibleDeviceTypeJsons } = await import(
'./src/features/device-types/device-types.js'
);

Expand Down Expand Up @@ -131,7 +131,7 @@ async function onInitHooks() {
});

// Pre-fetch the device types and populate the cache w/o blocking the API startup
void getAccessibleDeviceTypes(sbvrUtils.api.resin);
void getAccessibleDeviceTypeJsons(sbvrUtils.api.resin);

await sbvrUtils.db.transaction((tx) =>
createAll(tx, permissionNames, auth.ROLES, auth.KEYS, {}),
Expand Down
4 changes: 2 additions & 2 deletions src/features/device-config/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../infra/error-handling/index.js';

import { generateConfig } from './device-config.js';
import { findBySlug } from '../device-types/device-types.js';
import { getDeviceTypeJsonBySlug } from '../device-types/device-types.js';
import { checkInt, getBodyOrQueryParam } from '../../lib/utils.js';

const { UnauthorizedError, NotFoundError } = errors;
Expand Down Expand Up @@ -58,7 +58,7 @@ export const downloadImageConfig: RequestHandler = async (req, res) => {
const resinApi = api.resin.clone({ passthrough: { req } });

const app = await getApp(appId, req);
const deviceTypeJson = await findBySlug(
const deviceTypeJson = await getDeviceTypeJsonBySlug(
resinApi,
deviceTypeSlug || app.is_for__device_type[0].slug,
);
Expand Down
6 changes: 3 additions & 3 deletions src/features/device-types/device-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export const validateSlug = (slug?: string) => {
return slug;
};

/** @deprecated */
export const getAccessibleDeviceTypes = async (
/** @deprecated Prefer querying the device_type resource directly unless you need the device-type.json contents. */
export const getAccessibleDeviceTypeJsons = async (
resinApi: typeof sbvrUtils.api.resin,
): Promise<DeviceTypeJson[]> => {
const [deviceTypeInfosBySlug, accessibleDeviceTypes] = await Promise.all([
Expand All @@ -101,7 +101,7 @@ export const getAccessibleDeviceTypes = async (
};

/** @deprecated Use the getDeviceTypeBySlug unless you need the device-type.json contents. */
export const findBySlug = async (
export const getDeviceTypeJsonBySlug = async (
resinApi: typeof sbvrUtils.api.resin,
slug: string,
): Promise<DeviceTypeJson> =>
Expand Down
5 changes: 3 additions & 2 deletions src/features/device-types/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const { api } = sbvrUtils;
export const getDeviceTypes: RequestHandler = async (req, res) => {
const resinApi = api.resin.clone({ passthrough: { req } });
try {
const deviceTypes = await deviceTypesLib.getAccessibleDeviceTypes(resinApi);
const deviceTypes =
await deviceTypesLib.getAccessibleDeviceTypeJsons(resinApi);
res.json(deviceTypes);
} catch (err) {
captureException(err, 'Error getting device types', { req });
Expand All @@ -31,7 +32,7 @@ export const getDeviceType: RequestHandler = async (req, res) => {
try {
const resinApi = api.resin.clone({ passthrough: { req } });
const slug = deviceTypesLib.validateSlug(req.params.deviceType);
const data = await deviceTypesLib.findBySlug(resinApi, slug);
const data = await deviceTypesLib.getDeviceTypeJsonBySlug(resinApi, slug);
res.json(data);
} catch (err) {
captureException(err, 'Error getting device type', {
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ import {
getUserIDFromCreds,
} from './infra/rate-limiting/index.js';
import {
getAccessibleDeviceTypes,
findBySlug,
getAccessibleDeviceTypeJsons,
getDeviceTypeJsonBySlug,
getDeviceTypeBySlug,
} from './features/device-types/device-types.js';
import { proxy as supervisorProxy } from './features/device-proxy/device-proxy.js';
Expand Down Expand Up @@ -247,8 +247,14 @@ export const release = {
addVirtualFieldsToModel: addReleaseAdditionsToModel,
};
export const deviceTypes = {
getAccessibleDeviceTypes,
findBySlug,
// TODO: Drop me in the next major
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next major might be for example
See: #1607

/** @deprecated Use getAccessibleDeviceTypeJsons */
getAccessibleDeviceTypes: getAccessibleDeviceTypeJsons,
getAccessibleDeviceTypeJsons,
// TODO: Drop me in the next major
/** @deprecated Use getDeviceTypeJsonBySlug */
findBySlug: getDeviceTypeJsonBySlug,
getDeviceTypeJsonBySlug,
getDeviceTypeBySlug,
};
export * as contracts from './exports/contracts.js';
Expand Down
Loading