0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/website/versioned_docs/version-6.x/plugin-storage.md
2024-09-26 21:05:10 +02:00

5.2 KiB
Raw Permalink Blame History

id title
plugin-storage Storage Plugin

What's a storage plugin?

Verdaccio by default uses a file system storage plugin local-storage. The default storage can be easily replaced, either using a community plugin or creating one by your own.

API

Storage plugins are composed of two objects, the IPluginStorage<T> and the IPackageStorage.

  • The IPluginStorage object handle the local database for private packages.
interface IPluginStorage<T> extends IPlugin<T>, ITokenActions {
  logger: Logger;
  config: T & Config;
  add(name: string, callback: Callback): void;
  remove(name: string, callback: Callback): void;
  get(callback: Callback): void;
  getSecret(): Promise<string>;
  setSecret(secret: string): Promise<any>;
  getPackageStorage(packageInfo: string): IPackageStorage;
  search(
    onPackage: onSearchPackage,
    onEnd: onEndSearchPackage,
    validateName: onValidatePackage
  ): void;
}
  • The IPackageStorage is an object that is created by each request that handles the I/O actions for the metadata and tarballs.
interface IPackageStorage {
  logger: Logger;
  writeTarball(pkgName: string): IUploadTarball;
  readTarball(pkgName: string): IReadTarball;
  readPackage(fileName: string, callback: ReadPackageCallback): void;
  createPackage(pkgName: string, value: Package, cb: CallbackAction): void;
  deletePackage(fileName: string, callback: CallbackAction): void;
  removePackage(callback: CallbackAction): void;
  updatePackage(
    pkgFileName: string,
    updateHandler: StorageUpdateCallback,
    onWrite: StorageWriteCallback,
    transformPackage: PackageTransformer,
    onEnd: CallbackAction
  ): void;
  savePackage(fileName: string, json: Package, callback: CallbackAction): void;
}

Generate an middleware plugin

For detailed info check our plugin generator page. Run the yo command in your terminal and follow the steps.

➜ yo verdaccio-plugin

Just found a `.yo-rc.json` in a parent directory.
Setting the project root at: /Users/user/verdaccio_yo_generator

     _-----_     ╭──────────────────────────╮
    |       |    │        Welcome to        │
    |--(o)--|    │ generator-verdaccio-plug │
   `---------´   │   in plugin generator!   │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? What is the name of your plugin? custom-endpoint
? Select Language typescript
? What kind of plugin you want to create? storage
? Please, describe your plugin awesome storage plugin
? GitHub username or organization myusername
? Author's Name Juan Picado
? Author's Email jotadeveloper@gmail.com
? Key your keywords (comma to split) verdaccio,plugin,storage,awesome,verdaccio-plugin
   create verdaccio-plugin-storage-package-database/package.json
   create verdaccio-plugin-storage-package-database/.gitignore
   create verdaccio-plugin-storage-package-database/.npmignore
   create verdaccio-plugin-storage-package-database/jest.config.js
   create verdaccio-plugin-storage-package-database/.babelrc
   create verdaccio-plugin-storage-package-database/.travis.yml
   create verdaccio-plugin-storage-package-database/README.md
   create verdaccio-plugin-storage-package-database/.eslintrc
   create verdaccio-plugin-storage-package-database/.eslintignore
   create verdaccio-plugin-storage-package-database/src/PackageStorage.ts
   create verdaccio-plugin-storage-package-database/src/index.ts
   create verdaccio-plugin-storage-package-database/src/plugin.ts
   create verdaccio-plugin-storage-package-database/index.ts
   create verdaccio-plugin-storage-package-database/tsconfig.json
   create verdaccio-plugin-storage-package-database/types/index.ts
   create verdaccio-plugin-storage-package-database/.editorconfig

I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.


⸨ ░░░░░░░░░░░░░░░░░⸩ ⠋ fetchMetadata: sill pacote range manifest for @babel/plugin-syntax-jsx@^7.7.4 fetc

List Community Storage Plugins

The following list of plugins are implementing the Storage API and might be used them as example.