| 1 |
/* |
| 2 |
* Copyright (C) 2025 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
export interface ProgressData { |
| 7 |
// PackageManager waits on a lock or another operation to finish |
| 8 |
waiting: boolean |
| 9 |
// If not null, the operation can be cancelled |
| 10 |
cancel: (() => void) | null |
| 11 |
// Transaction percentage |
| 12 |
percentage: number |
| 13 |
} |
| 14 |
|
| 15 |
export type ProgressCB = (data: ProgressData) => void; |
| 16 |
export interface InstallProgressData extends ProgressData { |
| 17 |
// One of the Enum states |
| 18 |
info: number |
| 19 |
// Package being downloaded or installed |
| 20 |
package: string |
| 21 |
} |
| 22 |
|
| 23 |
export type InstallProgressCB = (data: InstallProgressData) => void; |
| 24 |
|
| 25 |
export interface MissingPackages { |
| 26 |
// Packages that were requested, are currently not installed, and can be installed |
| 27 |
missing_names: string[] |
| 28 |
// The full package IDs corresponding to missing_names (the ID format is backend specific) |
| 29 |
missing_ids: string[] |
| 30 |
// Packages that were requested, are currently not installed, but can't be found in any repository |
| 31 |
unavailable_names: string[] |
| 32 |
|
| 33 |
// If unavailable_names is empty, a simulated installation of the missing packages |
| 34 |
// is done and the result also contains these fields: |
| 35 |
|
| 36 |
// Packages that need to be installed as dependencies of missing_names |
| 37 |
extra_names: string[] |
| 38 |
// Packages that need to be removed |
| 39 |
remove_names: string[] |
| 40 |
// Bytes that need to be downloaded |
| 41 |
download_size: number |
| 42 |
} |
| 43 |
|
| 44 |
export enum InstallProgressType { |
| 45 |
DOWNLOADING, |
| 46 |
UPDATING, |
| 47 |
INSTALLING, |
| 48 |
REMOVING, |
| 49 |
REINSTALLING, |
| 50 |
DOWNGRADING, |
| 51 |
} |
| 52 |
|
| 53 |
export enum Severity { |
| 54 |
NONE, |
| 55 |
LOW, |
| 56 |
MODERATE, |
| 57 |
IMPORTANT, |
| 58 |
CRITICAL, |
| 59 |
} |
| 60 |
|
| 61 |
export interface Update { |
| 62 |
id: string |
| 63 |
name: string |
| 64 |
version: string |
| 65 |
arch: string |
| 66 |
} |
| 67 |
|
| 68 |
export interface UpdateDetail extends Update { |
| 69 |
severity: Severity |
| 70 |
description: string |
| 71 |
markdown: boolean |
| 72 |
bug_urls: string[] |
| 73 |
cve_urls: string[] |
| 74 |
vendor_urls: string[] |
| 75 |
} |
| 76 |
|
| 77 |
export interface History { |
| 78 |
timestamp: number |
| 79 |
// packagename, evr |
| 80 |
packages: Record<string, string> |
| 81 |
} |
| 82 |
|
| 83 |
export interface PackageManager { |
| 84 |
name: string |
| 85 |
check_missing_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<MissingPackages>; |
| 86 |
install_missing_packages(data: MissingPackages, progress_cb?: InstallProgressCB): Promise<void>; |
| 87 |
refresh(force: boolean, progress_cb?: ProgressCB): Promise<void>; |
| 88 |
is_installed(pkgnames: string[]): Promise<boolean>; |
| 89 |
install_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<void>; |
| 90 |
remove_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<void>; |
| 91 |
find_file_packages(files: string[], progress_cb?: ProgressCB): Promise<string[]>; |
| 92 |
get_updates<T extends boolean>(detail: T, progress_cb?: ProgressCB): Promise<T extends true ? UpdateDetail[] : Update[]>; |
| 93 |
update_packages(updates: Update[] | UpdateDetail[], progress_cb?: ProgressCB, transaction_path?: string): Promise<void>; |
| 94 |
get_backend(): Promise<string>; |
| 95 |
get_last_refresh_time(): Promise<number>; |
| 96 |
get_history(): Promise<History[]>; |
| 97 |
is_available(pkgnames: string[]): Promise<boolean>; |
| 98 |
} |
| 99 |
|
| 100 |
export class UnsupportedError extends Error { |
| 101 |
constructor(message: string) { |
| 102 |
super(message); |
| 103 |
this.name = "UnsupportedError"; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
export class NotFoundError extends Error { |
| 108 |
constructor(message: string) { |
| 109 |
super(message); |
| 110 |
this.name = "NotFoundError"; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
export class ResolveError extends Error { |
| 115 |
constructor(message: string) { |
| 116 |
super(message); |
| 117 |
this.name = "ResolveError"; |
| 118 |
} |
| 119 |
} |