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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rubicon2/object-transformer-prisma

v1.0.0

Published

Common rules for use with object-transformer to create query objects for Prisma ORM

Readme

object-transformer-prisma

A ruleset for object-transformer. Basically a re-implementation of url-query-for-prisma, which was too inflexible and was really only designed with get requests in mind.

Common rules for use with object-transformer to create query objects for Prisma ORM.

Install

npm install @rubicon2/object-transformer-prisma

Examples

An Express Application

import transformer, { copy } from '@rubicon2/object-transformer';
import { rulesets, options } from '@rubicon2/object-transformer-prisma';
import { PrismaClient } from '../generated/prisma/client';
import express from 'express';

const app = express();
const prisma = new PrismaClient();

app.get('/user', async (req, res) => {
  try {
    // Set up a transformer with the rules and options we want.
    const queryTransformer = transformer(rulesets.get, options);
    // Use it to transform req.query into an object for prisma to use.
    const query = queryTransformer(req.query);
    const users = await prisma.user.findMany(query);
    res.send({
      status: 'success',
      data: {
        users
      }
    })
  } catch (error) {
    console.error(error.message);
    res.sendStatus(500);
  }
});

app.listen(8080, () => console.log('Listening on post 8080'));

Extending The Ruleset

You can easily add your own rules as below. There are some useful rule functions that can be imported and used to generate the correct structures for common prisma queries.

import transformer { copy } from '@rubicon2/object-transformer';
import { rulesets, options } from '@rubicon2/object-transformer-prisma';

const getUsersRuleset = {
  ...rulesets.get,
  // We can run a prisma query based on params from req.query, or req.body.
  email: copyIncludesInsensitive('where.email'),
  fromDate: copyDate('where.createdAt.gte'),
  toDate: copyDate('where.createdAt.lte'),
  _onFinish: (params) => {
    // get._onFinish completes the work started by get.orderBy and get.sortOrder rules, so for those 
    // values on the input object to be processed properly, we need to make sure get._onFinish runs.
    rulesets.get._onFinish(params);
    // Whatever extra stuff you need to do after all other rules have finished.
  }
}

const getUsersTransformer = transformer(getUsersRuleset, options);

rulesets.get

|Rule|Notes| |----|-----| |take|How many results to get. Automatically parsed into an integer.| |skip|How many results to skip. Automatically parsed into an integer.| |cursor|To facilitate cursor-based pagination. Not parsed, as ids are likely to be uuid strings. Can easily be overridden with your own cursor function if you need a number instead of a string.| |orderBy|Takes a string or an array of strings. Can use nested object paths.| |sortOrder|Takes a string or an array of strings. Should be 'asc' or 'desc'.| |_onFinish|Takes data collected by orderBy and sortOrder and formats correctly for prisma query.|

The rulesets import only has one ruleset so far (get), but it has been structured to allow more rulesets to be added in future if need be.

Options

The options import contains what are probably the best practice settings for using prisma with this.

Firstly, it sets omitRulelessKeys to true, so object-transformer will ignore any input keys that don't have a corresponding rule. Without this, if a user submits a query with a key with a random name, it will automatically get copied over to the output object and when it gets given to prisma, if there is no corresponding column with that name on the database table, prisma will throw an error and crash.

The options import also has omitEmptyStrings set to true, so that any inputs with empty values will be ignored. If a user has submitted a search form with some empty fields, it seems natural to ignore the empty fields rather than include them on the query.

Rules

|Rule|Description| |----|-----------| |copyIncludes|Creates a structure to partially match a string.| |copyIncludesInsensitive|Creates a structure to case-insensitively partially match a string.|