0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

chore(core): typing, naming, and docs of parameters (#4971)

This commit is contained in:
Marc Bernard 2024-11-29 12:08:59 -05:00 committed by GitHub
parent 538bb8f3a6
commit 64a7fc0fc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 25 deletions

View file

@ -0,0 +1,5 @@
---
'@verdaccio/core': patch
---
chore(core): typing, naming, and docs of parameters

View file

@ -15,21 +15,16 @@ import {
import { VerdaccioError, searchUtils } from '.'; import { VerdaccioError, searchUtils } from '.';
export interface AuthPluginPackage {
packageName: string;
packageVersion?: string;
tag?: string;
}
export interface PluginOptions { export interface PluginOptions {
config: Config; config: Config;
logger: Logger; logger: Logger;
} }
/** /**
* The base plugin class, set of utilities for developing * Base Plugin Class
* plugins. *
* @alpha * Set of utilities for developing plugins.
* */ */
export class Plugin<PluginConfig> { export class Plugin<PluginConfig> {
static version = 1; static version = 1;
public readonly version: number; public readonly version: number;
@ -45,6 +40,14 @@ export class Plugin<PluginConfig> {
return this.version; return this.version;
} }
} }
// --- STORAGE PLUGIN ---
/**
* Storage Handler
*
* Used in storage plugin for managing packages and tarballs.
*/
export interface StorageHandler { export interface StorageHandler {
logger: Logger; logger: Logger;
deletePackage(fileName: string): Promise<void>; deletePackage(fileName: string): Promise<void>;
@ -54,33 +57,44 @@ export interface StorageHandler {
packageName: string, packageName: string,
handleUpdate: (manifest: Manifest) => Promise<Manifest> handleUpdate: (manifest: Manifest) => Promise<Manifest>
): Promise<Manifest>; ): Promise<Manifest>;
readPackage(name: string): Promise<Manifest>; readPackage(packageName: string): Promise<Manifest>;
savePackage(pkgName: string, value: Manifest): Promise<void>; savePackage(packageName: string, manifest: Manifest): Promise<void>;
readTarball(pkgName: string, { signal }: { signal: AbortSignal }): Promise<Readable>; readTarball(fileName: string, { signal }: { signal: AbortSignal }): Promise<Readable>;
createPackage(name: string, manifest: Manifest): Promise<void>; createPackage(packageName: string, manifest: Manifest): Promise<void>;
writeTarball(tarballName: string, { signal }: { signal: AbortSignal }): Promise<Writable>; writeTarball(fileName: string, { signal }: { signal: AbortSignal }): Promise<Writable>;
// verify if tarball exist in the storage // verify if tarball exist in the storage
hasTarball(fileName: string): Promise<boolean>; hasTarball(fileName: string): Promise<boolean>;
// verify if package exist in the storage // verify if package exist in the storage
hasPackage(): Promise<boolean>; hasPackage(): Promise<boolean>;
} }
/**
* Storage Plugin interface
*
* https://verdaccio.org/docs/next/plugin-storage
*/
export interface Storage<PluginConfig> extends Plugin<PluginConfig> { export interface Storage<PluginConfig> extends Plugin<PluginConfig> {
add(name: string): Promise<void>; add(packageName: string): Promise<void>;
remove(name: string): Promise<void>; remove(packageName: string): Promise<void>;
get(): Promise<any>; get(): Promise<string[]>;
init(): Promise<void>; init(): Promise<void>;
getSecret(): Promise<string>; getSecret(): Promise<string>;
setSecret(secret: string): Promise<any>; setSecret(secret: string): Promise<any>;
getPackageStorage(packageInfo: string): StorageHandler; getPackageStorage(packageName: string): StorageHandler;
search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>; search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
saveToken(token: Token): Promise<any>; saveToken(token: Token): Promise<any>;
deleteToken(user: string, tokenKey: string): Promise<any>; deleteToken(user: string, tokenKey: string): Promise<any>;
readTokens(filter: TokenFilter): Promise<Token[]>; readTokens(filter: TokenFilter): Promise<Token[]>;
} }
// --- 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 * ```ts
* import express, { Request, Response } from 'express'; * import express, { Request, Response } from 'express';
@ -95,7 +109,6 @@ export interface Storage<PluginConfig> extends Plugin<PluginConfig> {
* } * }
* } * }
* *
*
* const [plugin] = await asyncLoadPlugin(...); * const [plugin] = await asyncLoadPlugin(...);
* plugin.register_middlewares(app, auth, storage); * plugin.register_middlewares(app, auth, storage);
* ``` * ```
@ -104,15 +117,26 @@ export interface ExpressMiddleware<PluginConfig, Storage, Auth> extends Plugin<P
register_middlewares(app: Express, auth: Auth, storage: Storage): void; register_middlewares(app: Express, auth: Auth, storage: Storage): void;
} }
/** // --- AUTH PLUGIN ---
* dasdsa
*/
export type AuthCallback = (error: VerdaccioError | null, groups?: string[] | false) => void; export type AuthCallback = (error: VerdaccioError | null, groups?: string[] | false) => void;
export type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void; export type AuthAccessCallback = (error: VerdaccioError | null, access?: boolean) => void;
export type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void; export type AuthUserCallback = (error: VerdaccioError | null, access?: boolean | string) => void;
export type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void; export type AuthChangePasswordCallback = (error: VerdaccioError | null, access?: boolean) => void;
export type AccessCallback = (error: VerdaccioError | null, ok?: 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<T> extends Plugin<T> { export interface Auth<T> extends Plugin<T> {
/** /**
* Handles the authenticated method. * Handles the authenticated method.
@ -169,6 +193,13 @@ export interface IBasicAuth {
add_user(user: string, password: string, cb: Callback): any; add_user(user: string, password: string, cb: Callback): any;
} }
// --- FILTER PLUGIN ---
/**
* Filter Plugin Interface
*
* https://verdaccio.org/docs/next/plugin-filter
*/
export interface ManifestFilter<T> extends Plugin<T> { export interface ManifestFilter<T> extends Plugin<T> {
filter_metadata(packageInfo: Manifest): Promise<Manifest>; filter_metadata(manifest: Manifest): Promise<Manifest>;
} }