Line data Source code
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 : packages: Record<string, string>
80 : }
81 :
82 : export interface PackageManager {
83 : name: string
84 : check_missing_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<MissingPackages>;
85 : install_missing_packages(data: MissingPackages, progress_cb?: InstallProgressCB): Promise<void>;
86 : refresh(force: boolean, progress_cb?: ProgressCB): Promise<void>;
87 : is_installed(pkgnames: string[]): Promise<boolean>;
88 : install_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<void>;
89 : remove_packages(pkgnames: string[], progress_cb?: ProgressCB): Promise<void>;
90 : find_file_packages(files: string[], progress_cb?: ProgressCB): Promise<string[]>;
91 : get_updates<T extends boolean>(detail: T, progress_cb?: ProgressCB): Promise<T extends true ? UpdateDetail[] : Update[]>;
92 : update_packages(updates: Update[] | UpdateDetail[], progress_cb?: ProgressCB, transaction_path?: string): Promise<void>;
93 : get_backend(): Promise<string>;
94 : get_last_refresh_time(): Promise<number>;
95 : get_history(): Promise<History[]>;
96 : is_available(pkgnames: string[]): Promise<boolean>;
97 : }
98 :
99 283 : export class UnsupportedError extends Error {
100 0 : constructor(message: string) {
101 0 : super(message);
102 0 : this.name = "UnsupportedError";
103 0 : }
104 283 : }
105 :
106 283 : export class NotFoundError extends Error {
107 0 : constructor(message: string) {
108 0 : super(message);
109 0 : this.name = "NotFoundError";
110 0 : }
111 283 : }
112 :
113 283 : export class ResolveError extends Error {
114 1 : constructor(message: string) {
115 1 : super(message);
116 1 : this.name = "ResolveError";
117 1 : }
118 283 : }
|