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

Fix callback key types #77

Merged
merged 1 commit into from
Jan 12, 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
2 changes: 1 addition & 1 deletion http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function deleteRequest<T>(
return data;
}

const getRequestStreamCallbackKeys = ['onWrite'];
const getRequestStreamCallbackKeys = ['onWrite'] as const;

function createGetRequestStream(contentType: string) {
return async (
Expand Down
2 changes: 1 addition & 1 deletion lib/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ZipData = {
tmpDir: string;
};

const archiveCallbackKeys = ['init', 'copy'];
const archiveCallbackKeys = ['init', 'copy'] as const;

async function extractZip(
name: string,
Expand Down
16 changes: 8 additions & 8 deletions lib/cms/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import { LogCallbacksArg } from '../../types/LogCallbacks';

const i18nKey = 'lib.cms.functions';

const createFunctionCallbackKeys = [
'destPathAlreadyExists',
'createdDest',
'createdFunctionFile',
'createdConfigFile',
'success',
] as const;

type Config = {
runtime: string;
version: string;
Expand Down Expand Up @@ -146,14 +154,6 @@ type FunctionOptions = {
allowExistingFile?: boolean;
};

const createFunctionCallbackKeys = [
'destPathAlreadyExists',
'createdDest',
'createdFunctionFile',
'createdConfigFile',
'success',
];

export async function createFunction(
functionInfo: FunctionInfo,
dest: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/cms/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { PathInput } from '../../types/Modules';

const i18nKey = 'lib.cms.modules';

const createModuleCallbackKeys = ['creatingPath', 'creatingModule'] as const;

// Ids for testing
export const ValidationIds = {
SRC_REQUIRED: 'SRC_REQUIRED',
Expand Down Expand Up @@ -108,8 +110,6 @@ type ModuleDefinition = {
global: boolean;
};

const createModuleCallbackKeys = ['creatingPath', 'creatingModule'] as const;

export async function createModule(
moduleDefinition: ModuleDefinition,
name: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/cms/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { LogCallbacksArg } from '../../types/LogCallbacks';

const i18nKey = 'lib.cms.templates';

const templatesCallbackKeys = ['creatingFile'] as const;

// Matches the .html file extension, excluding module.html
const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);

Expand Down Expand Up @@ -50,8 +52,6 @@ const ASSET_PATHS = {
section: 'templates/section.html',
} as const;

const templatesCallbackKeys = ['creatingFile'];

export async function createTemplate(
name: string,
dest: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/cms/uploadFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { Mode } from '../../types/Files';

const i18nKey = 'lib.cms.uploadFolder';

const uploadFolderCallbackKeys = ['success'] as const;

const queue = new PQueue({
concurrency: 10,
});
Expand Down Expand Up @@ -117,8 +119,6 @@ export async function getFilesByType(
return [filePathsByType, fieldsJsObjects];
}

const uploadFolderCallbackKeys = ['success'];

export async function uploadFolder(
accountId: number,
src: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/fileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ type SimplifiedFolder = Partial<Folder> & Pick<Folder, 'id' | 'name'>;

const i18nKey = 'lib.fileManager';

const uploadCallbackKeys = ['uploadSuccess'];
const uploadCallbackKeys = ['uploadSuccess'] as const;
const downloadCallbackKeys = [
'skippedExisting',
'fetchFolderStarted',
'fetchFolderSuccess',
'fetchFileStarted',
'fetchFileSuccess',
];
] as const;

export async function uploadFolder(
accountId: number,
Expand Down
10 changes: 8 additions & 2 deletions lib/fileMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import { makeTypedLogger } from '../utils/logger';

const i18nKey = 'lib.fileMapper';

const filemapperCallbackKeys = [
'skippedExisting',
'wroteFolder',
'completedFetch',
'folderFetch',
'completedFolderFetch',
] as const;

const queue = new PQueue({
concurrency: 10,
});
Expand Down Expand Up @@ -187,8 +195,6 @@ async function skipExisting(
return false;
}

const filemapperCallbackKeys = ['skippedExisting', 'wroteFolder'];

async function fetchAndWriteFileStream(
accountId: number,
srcPath: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {

const i18nKey = 'lib.github';

const cloneGithubRepoCallbackKeys = ['success'] as const;

type RepoPath = `${string}/${string}`;

export async function fetchFileFromRepository(
Expand Down Expand Up @@ -114,8 +116,6 @@ type CloneGithubRepoOptions = {
sourceDir?: string; // The directory within the downloaded repo to write after extraction
};

const cloneGithubRepoCallbackKeys = ['success'];

export async function cloneGithubRepo(
repoPath: RepoPath,
dest: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { updateAccountConfig, writeConfig } from '../config';

const i18nKey = 'lib.oauth';

const addOauthToAccountConfigCallbackKeys = ['init', 'success'] as const;

const oauthManagers = new Map<number, OAuth2Manager>();

function writeOauthTokenInfo(accountConfig: FlatAccountFields): void {
Expand All @@ -37,8 +39,6 @@ export function getOauthManager(
return oauthManagers.get(accountId);
}

const addOauthToAccountConfigCallbackKeys = ['init', 'success'];

export function addOauthToAccountConfig(
oauth: OAuth2Manager,
logCallbacks: LogCallbacksArg<typeof addOauthToAccountConfigCallbackKeys>
Expand Down
Loading