From 64a7fc0fc7ec4a43225975b989c83fde032ac01e Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:08:59 -0500 Subject: [PATCH] chore(core): typing, naming, and docs of parameters (#4971) --- .changeset/curvy-rockets-camp.md | 5 ++ packages/core/core/src/plugin-utils.ts | 81 ++++++++++++++++++-------- 2 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 .changeset/curvy-rockets-camp.md diff --git a/.changeset/curvy-rockets-camp.md b/.changeset/curvy-rockets-camp.md new file mode 100644 index 000000000..b118744d1 --- /dev/null +++ b/.changeset/curvy-rockets-camp.md @@ -0,0 +1,5 @@ +--- +'@verdaccio/core': patch +--- + +chore(core): typing, naming, and docs of parameters diff --git a/packages/core/core/src/plugin-utils.ts b/packages/core/core/src/plugin-utils.ts index 9b7874026..adf7c3060 100644 --- a/packages/core/core/src/plugin-utils.ts +++ b/packages/core/core/src/plugin-utils.ts @@ -15,21 +15,16 @@ import { import { VerdaccioError, searchUtils } from '.'; -export interface AuthPluginPackage { - packageName: string; - packageVersion?: string; - tag?: string; -} export interface PluginOptions { config: Config; logger: Logger; } /** - * The base plugin class, set of utilities for developing - * plugins. - * @alpha - * */ + * Base Plugin Class + * + * Set of utilities for developing plugins. + */ export class Plugin { static version = 1; public readonly version: number; @@ -45,6 +40,14 @@ export class Plugin { return this.version; } } + +// --- STORAGE PLUGIN --- + +/** + * Storage Handler + * + * Used in storage plugin for managing packages and tarballs. + */ export interface StorageHandler { logger: Logger; deletePackage(fileName: string): Promise; @@ -54,33 +57,44 @@ export interface StorageHandler { packageName: string, handleUpdate: (manifest: Manifest) => Promise ): Promise; - readPackage(name: string): Promise; - savePackage(pkgName: string, value: Manifest): Promise; - readTarball(pkgName: string, { signal }: { signal: AbortSignal }): Promise; - createPackage(name: string, manifest: Manifest): Promise; - writeTarball(tarballName: string, { signal }: { signal: AbortSignal }): Promise; + readPackage(packageName: string): Promise; + savePackage(packageName: string, manifest: Manifest): Promise; + readTarball(fileName: string, { signal }: { signal: AbortSignal }): Promise; + createPackage(packageName: string, manifest: Manifest): Promise; + writeTarball(fileName: string, { signal }: { signal: AbortSignal }): Promise; // verify if tarball exist in the storage hasTarball(fileName: string): Promise; // verify if package exist in the storage hasPackage(): Promise; } +/** + * Storage Plugin interface + * + * https://verdaccio.org/docs/next/plugin-storage + */ export interface Storage extends Plugin { - add(name: string): Promise; - remove(name: string): Promise; - get(): Promise; + add(packageName: string): Promise; + remove(packageName: string): Promise; + get(): Promise; init(): Promise; getSecret(): Promise; setSecret(secret: string): Promise; - getPackageStorage(packageInfo: string): StorageHandler; + getPackageStorage(packageName: string): StorageHandler; search(query: searchUtils.SearchQuery): Promise; saveToken(token: Token): Promise; deleteToken(user: string, tokenKey: string): Promise; readTokens(filter: TokenFilter): Promise; } +// --- MIDDLEWARE PLUGIN --- + /** - * This function allow add additional middleware to the application. + * Middleware Plugin Interface + * + * https://verdaccio.org/docs/next/plugin-middleware + * + * This function allow add middleware to the application. * * ```ts * import express, { Request, Response } from 'express'; @@ -94,8 +108,7 @@ export interface Storage extends Plugin { }); * } * } - * - * + * * const [plugin] = await asyncLoadPlugin(...); * plugin.register_middlewares(app, auth, storage); * ``` @@ -104,15 +117,26 @@ export interface ExpressMiddleware extends Plugin

void; export type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void; export type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void; export type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void; export type AccessCallback = (error: VerdaccioError | null, ok?: boolean) => void; + +export interface AuthPluginPackage { + packageName: string; + packageVersion?: string; + tag?: string; +} + +/** + * Authentication Plugin Interface + * + * https://verdaccio.org/docs/next/plugin-auth + */ export interface Auth extends Plugin { /** * Handles the authenticated method. @@ -169,6 +193,13 @@ export interface IBasicAuth { add_user(user: string, password: string, cb: Callback): any; } +// --- FILTER PLUGIN --- + +/** + * Filter Plugin Interface + * + * https://verdaccio.org/docs/next/plugin-filter + */ export interface ManifestFilter extends Plugin { - filter_metadata(packageInfo: Manifest): Promise; + filter_metadata(manifest: Manifest): Promise; }