chore: simplify withDeps signature and fix non-null assertion

This commit is contained in:
Nicolas Meienberger 2026-03-11 21:42:38 +01:00
parent 9be16a2172
commit ea2b197d1e
3 changed files with 10 additions and 14 deletions

View file

@ -53,12 +53,12 @@ export const ls = async (
config: RepositoryConfig,
snapshotId: string,
organizationId: string,
path?: string,
options?: { offset?: number; limit?: number },
deps?: ResticDeps,
path: string | undefined,
options: { offset?: number; limit?: number } | undefined,
deps: ResticDeps,
): Promise<ResticLsResult> => {
const repoUrl = buildRepoUrl(config);
const env = await buildEnv(config, organizationId, deps!);
const env = await buildEnv(config, organizationId, deps);
const args: string[] = ["--repo", repoUrl, "ls", snapshotId, "--long"];
@ -119,7 +119,7 @@ export const ls = async (
},
});
await cleanupTemporaryKeys(env, deps!);
await cleanupTemporaryKeys(env, deps);
if (res.exitCode !== 0) {
logger.error(`Restic ls failed: ${res.error}`);

View file

@ -25,13 +25,8 @@ export { ResticError } from "./error";
function withDeps<Args extends unknown[], Result>(
command: (...args: [...Args, ResticDeps]) => Result,
deps: ResticDeps,
): (...args: Args) => Result;
function withDeps<Args extends unknown[], Result>(
command: (...args: [...Args, ResticDeps?]) => Result,
deps: ResticDeps,
): (...args: Args) => Result;
function withDeps(command: (...args: any[]) => any, deps: ResticDeps) {
return (...args: any[]) => command(...args, deps);
): (...args: Args) => Result {
return (...args: Args) => command(...args, deps);
}
export const createRestic = (deps: ResticDeps) => ({

View file

@ -14,8 +14,9 @@ export const findCommonAncestor = (paths: string[]): string => {
const commonParts: string[] = [];
for (let i = 0; i < minLength; i++) {
const partSet = new Set(splitPaths.map((parts) => parts[i]));
if (partSet.size === 1) {
commonParts.push(splitPaths[0]![i]!);
const toPush = splitPaths[0]?.[i];
if (partSet.size === 1 && toPush) {
commonParts.push(toPush);
} else {
break;
}