UNPKG

verdaccio

Version:

A lightweight private npm proxy registry

207 lines (206 loc) 9.69 kB
import { ReadTarball } from '@verdaccio/streams'; import { Callback, Config, Logger, Manifest, MergeTags, Version, Versions } from '@verdaccio/types'; import { Token, TokenFilter } from '@verdaccio/types'; import { IPluginFilters, ISyncUplinks, StringValue } from '../types'; import LocalStorage from './local-storage'; import ProxyStorage from './up-storage'; declare class Storage { localStorage: LocalStorage; config: Config; logger: Logger; uplinks: Record<string, ProxyStorage>; filters: IPluginFilters | undefined; constructor(config: Config); /** * Initialize the storage: load the storage plugin (or the default * local storage) and the filter plugins. Safe to call once; subsequent * calls only reload missing filters. * @param {Config} config verdaccio configuration * @param {IPluginFilters} filters preloaded filter plugins; when omitted they are loaded from the configuration */ init(config: Config, filters?: IPluginFilters): Promise<void>; /** * Resolve the storage backend: a configured storage plugin when available, * otherwise the default `@verdaccio/local-storage` on the configured path. * @return {Promise<StoragePlugin>} the storage plugin instance */ private loadStorage; /** * Load the storage plugins declared under `store` in the configuration. * Only one storage is supported: with several plugins configured the * first loaded one wins and a warning is logged. * @return {Promise<StoragePluginLegacy<Config> | undefined>} the selected plugin, or undefined when none is configured */ private loadStorePlugin; /** * Add a package to the system (publish flow). * Verifies the package does not exist locally nor on any uplink before * creating it locally; uplinks being offline rejects the publish unless * `publish.allow_offline` is enabled. * Used storages: local (write) && uplinks * @param {String} name package name * @param {Object} metadata package manifest to publish * @param {Function} callback invoked with an error when the publish is rejected */ addPackage(name: string, metadata: any, callback: any): Promise<void>; /** * Whether `publish.allow_offline` is enabled in the configuration. * @return {Boolean} true when publishing with unreachable uplinks is allowed */ private _isAllowPublishOffline; /** * Read the npm tokens matching the filter from the token storage. * Used storages: local (read) */ readTokens(filter: TokenFilter): Promise<Token[]>; /** * Save an npm token to the token storage. * Used storages: local (write) */ saveToken(token: Token): Promise<void>; /** * Delete an npm token from the token storage. * Used storages: local (write) */ deleteToken(user: string, tokenKey: string): Promise<any>; /** * Add a new version of a package to the system. * Used storages: local (write) * @param {String} name package name * @param {String} version version id, eg. 1.0.0 * @param {Version} metadata version metadata * @param {String} tag dist-tag pointing to the version * @param {Function} callback */ addVersion(name: string, version: string, metadata: Version, tag: StringValue, callback: Callback): void; /** * Tag package versions with the provided dist-tags. * Used storages: local (write) * @param {String} name package name * @param {MergeTags} tagHash dist-tag to version mapping to merge * @param {Function} callback */ mergeTags(name: string, tagHash: MergeTags, callback: Callback): void; /** * Change an existing package (eg. unpublish one version). * Used storages: local (write) * @param {String} name package name * @param {Manifest} metadata updated package manifest * @param {String} revision expected revision of the stored manifest * @param {Function} callback */ changePackage(name: string, metadata: Manifest, revision: string, callback: Callback): void; /** * Remove a package from the local storage and the search indexer. * Used storages: local (write) * @param {String} name package name * @param {Function} callback */ removePackage(name: string, callback: Callback): void; /** * Remove a tarball from the local storage. The tarball must not be * linked by any existing version, ie. the version should be * unpublished first. * Used storages: local (write) * @param {String} name package name * @param {String} filename tarball file name * @param {String} revision expected revision of the stored manifest * @param {Function} callback */ removeTarball(name: string, filename: string, revision: string, callback: Callback): void; /** * Upload a tarball (publish flow). Synchronous, returns a writable * stream the tarball body is piped into. * Used storages: local (write) * @param {String} name package name * @param {String} filename tarball file name * @return {Stream} writable upload stream */ addTarball(name: string, filename: string): import("@verdaccio/streams").UploadTarball; /** * Whether a tarball exists in the local storage, without reading it * (the stream is aborted as soon as it opens). * Used storages: local (read) * @param {String} name package name * @param {String} filename tarball file name * @return {Promise<Boolean>} true when the tarball is stored locally */ hasLocalTarball(name: string, filename: string): Promise<boolean>; /** * Get a tarball. Synchronous, returns a readable stream. * The tarball is read locally first; on a local miss the distfile record * is resolved from the package metadata (see lookupDistFile), syncing the * uplinks when the local metadata does not know the file, and the tarball * is then fetched from the uplink that serves the distfile url. * Used storages: local || uplink (just one) * @param {String} name package name * @param {String} filename tarball file name * @return {Stream} readable tarball stream */ getTarball(name: string, filename: string): ReadTarball; /** * Retrieve the package metadata: the local manifest merged with the * manifest of every uplink with proxy access to the package. * Used storages: local && uplink (proxy_access) * @param {Object} options * @property {String} options.name package name * @property {Object} options.req Express `req` object * @property {Boolean} options.keepUpLinkData keep the uplink info (last update, etc.) in the package metadata * @property {Boolean} options.abbreviated serve the abbreviated manifest (npm install) * @property {Function} options.callback invoked with the merged manifest and any uplink errors */ getPackage(options: any): void; /** * Retrieve remote and local packages more recent than the start key. * All uplinks are streamed first, then the local packages; local * packages can override registry ones just because they appear in the * JSON last — a trade-off made to avoid memory issues. * Used storages: local && uplink (proxy_access) * @param {String} startkey timestamp to search from * @param {Object} options request options; `local=1` in the query skips the uplinks * @return {Stream} object stream of search results */ search(startkey: string, options: any): any; /** * Retrieve only private local packages, as the latest version of each. * Used storages: local (read) * @param {Function} callback invoked with the list of latest versions */ getLocalDatabase(callback: Callback): void; /** * Read each local package name, apply filters, and collect the latest version. */ private _collectLocalPackages; /** * Fetch the package metadata from every uplink with proxy access and * synchronize it with the local data; filter plugins are applied to the * merged result. * @param {String} name package name * @param {Manifest} packageInfo local manifest; MUST be provided when the package exists locally * @param {ISyncUplinks} options uplink request options * @param {Function} callback invoked with (err, mergedManifest, uplinkErrors) */ _syncUplinksMetadata(name: string, packageInfo: Manifest, options: ISyncUplinks, callback: Callback): void; /** * Apply all configured filter plugins to a package manifest sequentially. * Each filter's output is passed as input to the next filter. * Returns the filtered manifest and any errors that occurred. */ private _applyFilters; /** * Check if a tarball should be served based on filter plugins, using only * local metadata. Returns true (defer) when the version isn't cached locally * — the uplink-sync path in getTarball re-checks filters after sync, which * avoids a redundant uplink round-trip and double filter application. */ private _isTarballAllowedByFilters; /** * Tag each version with the uplink it was fetched from, under a hidden * (symbol) key. The local storage uses the tag to record the registry * on the distfile records it creates. * @param {Versions} versions versions fetched from the uplink * @param {ProxyStorage} upLink uplink the versions were fetched from */ _updateVersionsHiddenUpLink(versions: Versions, upLink: ProxyStorage): void; } export default Storage;