refactor(tools,client): remove head and tail logic (#66524)

This commit is contained in:
Sem Bauke
2026-03-17 17:59:16 +01:00
committed by GitHub
parent 1990ba6794
commit e66bf09dce
34 changed files with 24 additions and 998 deletions
+2 -47
View File
@@ -6,8 +6,6 @@ export interface IncompleteChallengeFile {
ext: Ext;
name: string;
contents: string;
head?: string;
tail?: string;
}
export interface ChallengeFile extends IncompleteChallengeFile {
@@ -15,8 +13,6 @@ export interface ChallengeFile extends IncompleteChallengeFile {
editableContents?: string;
usesMultifileEditor?: boolean;
error?: unknown;
head: string;
tail: string;
seed?: string;
source?: string;
path: string;
@@ -71,8 +67,6 @@ export function isPoly(poly: unknown): poly is ChallengeFile {
'name' in poly &&
'ext' in poly &&
'fileKey' in poly &&
'head' in poly &&
'tail' in poly &&
'history' in poly
);
}
@@ -82,8 +76,6 @@ export function isPoly(poly: unknown): poly is ChallengeFile {
typeof poly.name === 'string' &&
exts.includes(poly.ext as Ext) &&
typeof poly.fileKey === 'string' &&
typeof poly.head === 'string' &&
typeof poly.tail === 'string' &&
Array.isArray(poly.history);
return hasProperties(poly) && hasCorrectTypes(poly);
@@ -111,33 +103,11 @@ export function setContent(
// database.
export function regenerateMissingProperties(file: IncompleteChallengeFile) {
const newPath = file.name + '.' + file.ext;
const newFile = {
return {
...file,
path: newPath,
history: [newPath],
head: file.head ?? '',
tail: file.tail ?? ''
history: [newPath]
};
return newFile;
}
async function clearHeadTail(polyP: Promise<ChallengeFile>) {
const poly = await polyP;
checkPoly(poly);
return {
...poly,
head: '',
tail: ''
};
}
export async function compileHeadTail(padding = '', poly: ChallengeFile) {
return clearHeadTail(
transformContents(
() => [poly.head, poly.contents, poly.tail].join(padding),
poly
)
);
}
type Wrapper = (x: string) => Promise<string> | string;
@@ -154,21 +124,6 @@ export async function transformContents(
return newPoly;
}
export async function transformHeadTailAndContents(
wrap: Wrapper,
polyP: ChallengeFile | Promise<ChallengeFile>
) {
const poly = await polyP;
const contents = await transformContents(wrap, poly);
const head = await wrap(poly.head);
const tail = await wrap(poly.tail);
return {
...contents,
head,
tail
};
}
// createSource(poly: PolyVinyl) => PolyVinyl
export function createSource<Rest>(
poly: Pick<ChallengeFile, 'contents' | 'source'> & Rest