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

@acrontum/boats-utils

v2.0.4

Published

Collection of useful boats template helpers.

Downloads

13

Readme

Boats utils

Collection of useful boats template helpers to be used with j-d-carmichael/boats.

Table of Contents generated with DocToc

Usage

npm install @acrontum/boats-utils

In your openapi boats project, simply include this module as a helper in your build command:

{
  "name": "service-openapi-spec",
  "version": "1.0.0",
  "description": "Some boats openapi builder",
  "scripts": {
    "prebuild": "rm -rf build",
    "build": "NODE_ENV=test boats --yes -f node_modules/@acrontum/boats-utils/dist -i ./src/index.yml -o ./build/api.yml",
    "postbuild": "cp build/api*.yml ./release/$npm_package_name.yml"
  },
  "keywords": [],
  "author": "p-mcgowan",
  "devDependencies": {
    "boats": "^2.25.0",
    "@acrontum/boats-utils": "^1.0.0"
  }
}

Modules

extend

Extend a base model with additional, omitted, required, and / or optional fields.

# model.yml

type: object
properties:
  id:
    type: string
    format: uuid
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
  # ...
# postModel.yml

{{
  extend('./model.yml', {
    omit: [
      'properties.id'
    ],
    require: [
      'properties.name',
      'properties.email'
    ],
    include: [
      ['properties.username', { type: 'string', 'x-unique': true }]
    ],
    optional: [
      'properties.dateOfBirth'
    ]
  })
}}

Examples


Removing fields from the model:

# model.yml

type: object
required:
  - id
properties:
  id:
    type: string
    format: uuid
  createdAt:
    type: string
    format: date-time
  updatedAt:
    type: string
    format: date-time
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
# postModel.yml

{{
  extend('./model.yml', {
    omit: [
      'properties.id',
      'properties.createdAt',
      'properties.updatedAt'
    ]
  })
}}

Would output:

type: object
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri

Adding fields to the model:

# model.yml

type: object
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
# postModel.yml
{{
  extend('./model.yml', {
    include: [
      ['properties.password', { type: 'string', minLength: 32 }]
    ]
  })
}}

Would output:

type: object
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
  password:
    type: string
    minLength: 32

Marking fields as required:

# model.yml

type: object
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
# postModel.yml

{{
  extend('./model.yml', {
    require: [
      'properties.email',
      'properties.name'
    ]
  })
}}

Would output:

type: object
required:
  - name
  - email
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri

Marking fields as optional:

# model.yml

type: object
require:
  - name
  - email
  - profilePicture
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri
# postModel.yml

{{
  extend('./model.yml', {
    optional: [
      'properties.profilePicture'
    ]
  })
}}

Would output:

type: object
required:
  - name
  - email
properties:
  name:
    type: string
  email:
    type: string
    format: email
  profilePicture:
    type: string
    format: uri

database-entry

Adds common DB fields to a model.

type: object
properties:
  {{ databaseentry(<options>) }}
  otherProps:
    type: string
  # ...

Examples


With no params:

# model.yml

type: object
properties:
  {{ databaseentry() }}
  name:
    type: string
  profilePicture:
    type: string
    format: uri

Would output:

type: object
properties:
  id:
    type: string
    format: uuid
  createdAt:
    type: string
    format: date-time
  updatedAt:
    type: string
    format: date-time
  name:
    type: string
  profilePicture:
    type: string

To specifiy the id type:

# model.yml

type: object
properties:
  {{ databaseentry({ id: 'string' }) }}
# {{ databaseentry({ id: 'number' }) }}
  name:
    type: string
  profilePicture:
    type: string
    format: uri

Would output:

type: object
properties:
  id:
    type: string
#   type: number
  createdAt:
    type: string
    format: date-time
  updatedAt:
    type: string
    format: date-time
  name:
    type: string
  profilePicture:
    type: string

With softDeletion:

# model.yml

type: object
properties:
  {{ databaseentry({ softDeletion: true }) }}
  name:
    type: string
  profilePicture:
    type: string
    format: uri

Would output:

type: object
properties:
  id:
    type: string
    format: uuid
  createdAt:
    type: string
    format: date-time
  updatedAt:
    type: string
    format: date-time
  deletedAt:
    type: string
    format: date-time
  name:
    type: string
  profilePicture:
    type: string

pagination

Adds a collection-type pagination model.

{{ pagination(<path_or_options>) }}

Examples


With no params:

# components/schemas/user/model.yml

type: object
properties:
  name:
    type: string
  numberOfDogs:
    type: number
# components/schemas/user/models.yml

{{ pagination() }}

Would output:

type: object
required:
  - meta
  - data
properties:
  meta:
    $ref: "#/components/schemas/Meta"
  data:
    type: array
    items: 
      $ref: "./model.yml"

To specify another model name:

# components/schemas/user/singleUserResponse.yml

type: object
properties:
  name:
    type: string
  numberOfDogs:
    type: number
# components/schemas/user/models.yml

{{ pagination({ path: "./singleUserResponse.yml" }) }}

or simply

{{ pagination("./singleUserResponse.yml") }}

Would output:

type: object
required:
  - meta
  - data
properties:
  meta:
    $ref: "#/components/schemas/Meta"
  data:
    type: array
    items: 
      $ref: "./singleUserResponse.yml"

To specify another pagination model:

# components/schemas/user/singleUserResponse.yml

type: object
properties:
  name:
    type: string
  numberOfDogs:
    type: number
# components/schemas/user/models.yml

{{ pagination({ paginationModel: "#/components/schemas/Pagination" }) }}

Would output:

type: object
required:
  - meta
  - data
properties:
  meta:
    $ref: "#/components/schemas/Pagination"
  data:
    type: array
    items: 
      $ref: "./model.yml"

To alter or remove required fields:

# components/schemas/user/singleUserResponse.yml

type: object
properties:
  name:
    type: string
  numberOfDogs:
    type: number
# components/schemas/user/models.yml

{{ pagination({ required: ['meta'] }) }}

Would output:

type: object
required:
  - meta
properties:
  meta:
    $ref: "#/components/schemas/Pagination"
  data:
    type: array
    items: 
      $ref: "./model.yml"
# components/schemas/user/models.yml

{{ pagination({ required: [] }) }}

Would output:

type: object
properties:
  meta:
    $ref: "#/components/schemas/Pagination"
  data:
    type: array
    items: 
      $ref: "./model.yml"