npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@herbsjs/herbarium

v1.5.0

Published

Herbs Object Repository and Discovery.

Downloads

2,468

Readme

CD Build codecov

Herbarium

Herbarium is a centralized and standardized repository and discovery service for Herbs objects (entities, use cases, repositories) allowing glues (ex: Herbs Shelf, herbs2rest, herbs2gql, herbs2knex, etc) to access, explore and find these objects.

Installing

$ npm install @herbsjs/herbarium

Initializing

const { herbarium } = require('@herbs/herbarium')
herbarium.requireAll(options)

This will require all entities, use cases and repositories files.

You can check which files were found within the herbarium.requireAll(options) method using:

const { herbarium } = require('@herbs/herbarium')
const retqAll = herbarium.requireAll(options)

/* Will return an object of array of files founded
 {
   entities:[],
   usecases":[],
   repositories:[]
  }
*/

Advanced Options

options:

  • initialPath: (optional) default process.cwd()
  • avoidFiles: (optional) default (fileName) => (fileName.includes('.spec.js') || fileName.includes('.test.js') ? false : fileName)
  • onlySpecs: (optional) default (fileName) => (fileName.includes('.spec.js') ? fileName : false)
  • entitiesPath: (optional) default /src/domain/entities
  • usecasesPath: (optional) default /src/domain/usecases
  • specPath: (optional) default /src/domain/
  • repositoriesPath: (optional) default /src/infra/repositories

Adding Objects and Metadata

Entities

// src/domain/entities/item.js
const { entity, field } = require('@herbsjs/herbs')
const { herbarium } = require('@herbsjs/herbarium')

const Item =
    entity('Item', {
        ...
    })

module.exports =
    herbarium.entities
        .add(Item, 'Item')
        .entity

The second parameter of the herbarium.entities.add function is the entity id for herbarium. It is optional and if none is provided, it uses the entity name (Item).

Use Cases

// src/domain/usecases/item/createItem.js
const { usecase } = require('@herbsjs/herbs')
const { herbarium } = require('@herbsjs/herbarium')
const { Item } = require('../entities/item')

const createItem = (injection) =>
    usecase('Create Item', {
        ...
    })

module.exports =
    herbarium.usecases
        .add(createItem, 'CreateItem')
        .metadata({ group: 'Items', operation: herbarium.crud.create, entity: Item })
        .usecase

The second parameter of the herbarium.usecases.add function is the usecase id for herbarium. It is optional and if none is provided, it uses the usecase description (Create Item).

Specs

// src/domain/usecases/createItem.spec.js
const { spec, scenario, given, check } = require('@herbsjs/aloe')

const createItemSpec = spec({ 
    ...
    })

module.exports =
    herbarium.specs
        .add(createItemSpec, 'CreateItemSpec')
        .spec

The second parameter of the herbarium.specs.add function is the entity id for herbarium.

Repository

const { herbarium } = require('@herbsjs/herbarium')
const { Repository } = require("@herbsjs/herbs2knex")
const { Item } = require('../../../domain/entities/item')

class ItemRepository extends Repository {
    constructor(injection) {
        ...
    }
}

module.exports =
    herbarium.repositories
        .add(ItemRepository, 'ItemRepository')
        .metadata({ entity: Item })
        .repository

The second parameter of the herbarium.repositories.add function is the repository id for herbarium. It is optional and if none is provided, it uses the repository class name (ItemRepository).

Consuming Objects

all

const entities = herbarium.entities.all
const usecases = herbarium.usecases.all
const repositories = herbarium.repositories.all

findBy

const usecases = herbarium.usecases.findBy({
  operation: [
    herbarium.crud.create,
    herbarium.crud.update,
    herbarium.crud.delete,
  ],
})

get by id

const entity = herbarium.entities.get(1)
const usecase = herbarium.usecases.get("a")
const repository = herbarium.repositories.get(item)

Reset

This method will clear all objects and metadata. Usefull for testing.

herbarium.reset()

TODO

  • [x] Improve Test Coverage (metadata, specialized objects, etc)
  • [x] Default IDs - No need to inform IDs when adding a item. Use entity name or use case description.

Contribute

Come with us to make an awesome Herbarium.

Now, if you do not have technical knowledge and also have intend to help us, do not feel shy, click here to open an issue and collaborate their ideas, the contribution may be a criticism or a compliment (why not?)

If you would like to help contribute to this repository, please see CONTRIBUTING

The Herb

A herbarium is a collection of preserved plant specimens and associated data used for scientific study.

https://en.wikipedia.org/wiki/Herbarium

License

Herbarium is released under the MIT license.