UNPKG

@shockpkg/core

Version:
187 lines (186 loc) 4.76 kB
import { Package } from './package'; import { IPackagesList, IPackagesListPackage, IPackageUpdated } from './types'; /** * Packages constructor. * * @param path The path to the packages file. */ export declare class Packages extends Object { /** * Packages data. */ protected _packagesList: IPackagesList | null; /** * Packages array. */ protected _packages: Set<Package>; /** * Packages mapped by name. */ protected _packagesByName: Map<string, Package>; /** * Packages mapped by sha256. */ protected _packagesBySha256: Map<string, Package>; /** * Packages mapped by unique. */ protected _packagesByUnique: Map<string, Package>; /** * The path to the packages file. */ protected readonly _path: string; /** * Format version. */ static readonly FORMAT: string; constructor(path: string); /** * Get path of the packages file. */ readonly path: string; /** * Get if packages loaded. */ readonly loaded: boolean; /** * Update packages. * * @param data Encoded data. * @return Update report. */ update(data: string): { updated: IPackageUpdated[]; added: IPackageUpdated[]; removed: IPackageUpdated[]; }; /** * Assert loaded. */ assertLoaded(): void; /** * Check if the file path exists. */ exists(): Promise<boolean>; /** * Read the file path. */ read(): Promise<void>; /** * Write packages to the file path. */ write(): Promise<void>; /** * Read the file path if the file exists. */ readIfExists(): Promise<boolean>; /** * Itterate over the packages. */ itter(): IterableIterator<Package>; /** * Check if package is in this collection. * * @param pkg Package instance. * @return If the package instance is present. */ has(pkg: Package): boolean; /** * Assert the package is in this collection. * * @param pkg Package instance. */ assertHas(pkg: Package): void; /** * Get package by the unique name. * * @param name Package name. * @return The package or null. */ byName(name: string): Package | null; /** * Get package by the sha256 hash. * * @param name Package sha256. * @return The package or null. */ bySha256(sha256: string): Package | null; /** * Get package by the unique value. * * @param name Package unique. * @return The package or null. */ byUnique(unique: string): Package | null; /** * Create a package instance. * * @param info Package info. * @return Package instance. */ protected _createPackage(info: IPackagesListPackage): Package; /** * Set the packages list. * * @param packages Parsed list. */ protected _setPackagesList(packagesList: IPackagesList): void; /** * Validate format version string. * * @param format The format version string. */ protected _validateFormat(format: string): void; /** * Parse the packages list. * * @param packages Packages list. * @return Parsed list. */ protected _parsePackages(packages: IPackagesListPackage[]): Package[]; /** * List all packages deep. * * @param packages A list of packages * @return A set of all packages and their children. */ protected _listPackages(packages: Package[]): Set<Package>; /** * Map out package list by name. * Throws on any duplicates. * * @param packages Packages list. * @return Map from package name to package. */ protected _packagesMapName(packages: Set<Package>): Map<string, Package>; /** * Map out package list by sha256. * Throws on any duplicates. * * @param packages Packages list. * @return Map from package sha256 to package. */ protected _packagesMapSha256(packages: Set<Package>): Map<string, Package>; /** * Map out package list by unique. * Throws on any duplicates. * * @param packages Packages list. * @return Map from package unique to package. */ protected _packagesMapUnique(packages: Set<Package>): Map<string, Package>; /** * Parse and cast the encoded data. * * @param data Encoded data. * @return Parsed and cast data. */ protected _parseData(data: string): IPackagesList; /** * Cast the parsed data. * * @param packages Parsed data. * @return Cast data. */ protected _castData(packages: any): IPackagesList; }