chore: simplify withDeps signature and fix non-null assertion
This commit is contained in:
parent
9be16a2172
commit
ea2b197d1e
3 changed files with 10 additions and 14 deletions
|
|
@ -53,12 +53,12 @@ export const ls = async (
|
||||||
config: RepositoryConfig,
|
config: RepositoryConfig,
|
||||||
snapshotId: string,
|
snapshotId: string,
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
path?: string,
|
path: string | undefined,
|
||||||
options?: { offset?: number; limit?: number },
|
options: { offset?: number; limit?: number } | undefined,
|
||||||
deps?: ResticDeps,
|
deps: ResticDeps,
|
||||||
): Promise<ResticLsResult> => {
|
): Promise<ResticLsResult> => {
|
||||||
const repoUrl = buildRepoUrl(config);
|
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"];
|
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) {
|
if (res.exitCode !== 0) {
|
||||||
logger.error(`Restic ls failed: ${res.error}`);
|
logger.error(`Restic ls failed: ${res.error}`);
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,8 @@ export { ResticError } from "./error";
|
||||||
function withDeps<Args extends unknown[], Result>(
|
function withDeps<Args extends unknown[], Result>(
|
||||||
command: (...args: [...Args, ResticDeps]) => Result,
|
command: (...args: [...Args, ResticDeps]) => Result,
|
||||||
deps: ResticDeps,
|
deps: ResticDeps,
|
||||||
): (...args: Args) => Result;
|
): (...args: Args) => Result {
|
||||||
function withDeps<Args extends unknown[], Result>(
|
return (...args: Args) => command(...args, deps);
|
||||||
command: (...args: [...Args, ResticDeps?]) => Result,
|
|
||||||
deps: ResticDeps,
|
|
||||||
): (...args: Args) => Result;
|
|
||||||
function withDeps(command: (...args: any[]) => any, deps: ResticDeps) {
|
|
||||||
return (...args: any[]) => command(...args, deps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createRestic = (deps: ResticDeps) => ({
|
export const createRestic = (deps: ResticDeps) => ({
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ export const findCommonAncestor = (paths: string[]): string => {
|
||||||
const commonParts: string[] = [];
|
const commonParts: string[] = [];
|
||||||
for (let i = 0; i < minLength; i++) {
|
for (let i = 0; i < minLength; i++) {
|
||||||
const partSet = new Set(splitPaths.map((parts) => parts[i]));
|
const partSet = new Set(splitPaths.map((parts) => parts[i]));
|
||||||
if (partSet.size === 1) {
|
const toPush = splitPaths[0]?.[i];
|
||||||
commonParts.push(splitPaths[0]![i]!);
|
if (partSet.size === 1 && toPush) {
|
||||||
|
commonParts.push(toPush);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue