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

strapi-plugin-tunning

v1.0.14

Published

A strapi plugin that makes it easier to handle the input and output of http request data.

Downloads

69

Readme

strapi-plugin-tunning

🚀   Overview

This plugin implements a simple way to input / output data from the strapi through http requests, correcting some annoying and repetitive problems to deal with each project.


⏳   Installation

With npm:

npm install strapi-plugin-tunning

With yarn:

yarn add strapi-plugin-tunning

✨   INPUT - Feature

In many cases, you will need to test if input is comming up on request body or via multipart/form-data. To make this verification simple as one line of code, was implemented an util extension to get/set data field or file from request context. So you don't have to worry about how this is happening.

Retrieving all input data

const data = strapi.tunning.input(ctx).data()

Retrieving a field input data

const dataName = strapi.tunning.input(ctx).data("name")

Retrieving a field input data with default value

const dataName = strapi.tunning.input(ctx).data("name", "unknown name")

Listing all input files

const files = strapi.tunning.input(ctx).files()

Retrieving one input file by field name

const fileThumb = strapi.tunning.input(ctx).files("thumb")

Setting a field value to body or multipart/form-data programatically

strapi.tunning.input(ctx).set({ foo: "bar" })

✨   KEEP - Feature

A utils function to keep only necessary data from context request body:

You can use it direcly in your controllers or routes:

strapi.tunning.keep(ctx, ["field_a", "field_b"])

Or you can pass it configured in your routes as a keep config option:

{
  "routes": [
    {
      "method": "POST",
      "path": "/articles",
      "handler": "Article.create",
      "config": {
        "policies": [],
        "keep": ["slug", "title", "content"]
      }
    }
  ]
}

It will remove any field from ctx.request.body that is not present on array, preventing user to pass unwanted data to fill unwanted fields.


✨   VIRTUAL INPUT Feature

Imagine, you have an implicit route that needs to update a specific value of your record, in some cases you could create a new controller just to implement this little specific business rule. But now you can pass this business rule to your route definition.

Example: You have an implicit route that frontends can call to accept a profile, so you need to filter only the specific field that needs to be updated (preventing to update an unwanted field), also need to force that this field value must to be true, once this implicit routes must to accept the profile. For this case you will need to create a custom controller to override the default controller allowing you to implement this business rule.

With the virtual_input feature you dont need be worried about that and you can implement this business rule direcly on route definition, avoiding you to override the default function or create another one to solve the problem.

{
  "routes": [
    {
      "method": "PUT",
      "path": "/profiles/:id/accept",
      "handler": "profile.update",
      "config": {
        "policies": [],
        "keep": [],
        "virtual_input": {
          "accepted": true
        }
      }
    }
  ]
}

It will force only the input field accepted as true to be updated on default controller function


✨   PICK Feature - Query Param

You can pass another type of filter in your query parameters, _pick, allowing you to select which field you want to return from the API, avoiding data overfetch.

GET http://localhost:1337/articles?_pick=id,slug,title

Also you can pass it configured in your routes as a pick config option returning the selected fields mandatorily:

{
  "routes": [
    {
      "method": "GET",
      "path": "/articles",
      "handler": "Article.find",
      "config": {
        "policies": [],
        "pick": ["id", "slug", "title"]
      }
    }
  ]
}

It will returns only fields id, slug and title on response body


🎉   Congradulations, You're done.

I hope this plugin helps you in your strapi projects and save a lot of time and code.


📜   License

This project is under the MIT license. See the LICENSE for details.


💻   Developed by André Ciornavei - Get in touch!