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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tsdiapi/prisma-rest

v0.4.3

Published

A TSDIAPI plugin that provides full REST API access to your Prisma models with built-in security controls.

Readme

@tsdiapi/prisma-rest

A TSDIAPI plugin that provides dynamic REST API access to your Prisma models with built-in security controls.

📌 About

This is a TSDIAPI plugin that provides a single dynamic endpoint to access your Prisma models through REST API. It includes built-in security features and access control.

🔗 TSDIAPI CLI: @tsdiapi/cli


📦 Installation

You can install this plugin using npm:

tsdiapi add prisma-rest

Then, register the plugin in your TSDIAPI project:

import { createApp } from "@tsdiapi/server";
import createPlugin from "@tsdiapi/prisma-rest";

createApp({
  plugins: [createPlugin({ enabled: true })],
});

🚀 Features

  • 🔄 Dynamic Endpoint - Single endpoint for all Prisma operations
  • 🔒 JWT Authentication - Built-in JWT guard support
  • 🌐 IP Restrictions - Control access based on IP addresses
  • 🎯 Method Control - Enable/disable specific Prisma methods
  • 🏷️ Model Selection - Choose which models to expose through the API
  • 🔍 Request Filtering - Modify or validate request data before processing
  • 🎛️ Model-Specific Configuration - Fine-grained control over methods and IPs per model

📱 Prisma REST Client

A TypeScript client for working with Prisma REST API generated by this plugin.

🔗 NPM Package: @tsdiapi/prisma-rest-client
🔗 Demo: https://tsdiapi.com/prisma-rest-client

Client Features

  • Full type safety using Prisma types
  • Automatic model and method validation
  • Support for all Prisma methods (findMany, findUnique, create, update, delete, etc.)
  • JWT authentication
  • Error handling
  • Minified bundle for browser usage

Installation

npm install prisma @prisma/client @tsdiapi/prisma-rest-client

Usage Example

// Get the Prisma client (types only)
import { PrismaClient } from '@prisma/client';
import { PrismaRestClient } from '@tsdiapi/prisma-rest-client';

// Create client instance with the Prisma client
const instance = new PrismaRestClient<PrismaClient>({
    apiUrl: "http://localhost:3100/api/prisma/v1",
    token: "your-jwt-token"
});

// Get typed client
const client = instance.useClient();

// Use like a regular Prisma client
async function main() {
    // Get list of users
    const users = await client.user.findMany({
        where: {
            email: {
                contains: '@example.com'
            }
        },
        select: {
            id: true,
            email: true,
            name: true
        }
    });

    // Create new user
    const newUser = await client.user.create({
        data: {
            email: '[email protected]',
            name: 'John Doe'
        }
    });

    // Update user
    const updatedUser = await client.user.update({
        where: { id: 'user-id' },
        data: { name: 'Jane Doe' }
    });

    // Delete user
    await client.user.delete({
        where: { id: 'user-id' }
    });
}

main().catch(console.error);

Security

The client works with the following security mechanisms provided by the plugin:

  • Model access restrictions
  • Method access restrictions
  • IP address restrictions
  • JWT authentication

It is recommended to configure these restrictions according to your security requirements.

Development

For development and testing:

  1. Clone the repository
  2. Install dependencies: npm install
  3. Run the build: npm run build
  4. For development with auto-rebuild: npm run dev

The repository includes an example HTML page for testing the client. Open https://tsdiapi.com/prisma-rest-client in your browser after building.


🔧 Configuration

This plugin can be configured through environment variables or during initialization:

createPlugin({
  enabled: true,
  // Global filter function
  filter: async (model, method, request, req) => {
    // Modify or validate request data
    return request;
  },
  // Model-specific configurations
  access: {
    User: {
      allowedMethods: ['findMany', 'findUnique'],
      allowedIps: ['127.0.0.1'],
      filter: async (model, method, request, req) => {
        // Model-specific request filtering
        return request;
      }
    }
  }
});

Configuration Options

| Variable | Type | Default | Description | |----------|------|---------|-------------| | PRISMA_REST_ENABLED | boolean | true | Enable/disable the REST API | | PRISMA_REST_METHODS | string | "" | Comma-separated list of allowed Prisma methods | | PRISMA_REST_MODELS | string | "" | Comma-separated list of models to expose | | PRISMA_REST_ALLOWED_IPS | string | "127.0.0.1,::1" | Comma-separated list of allowed IP addresses | | PRISMA_REST_GUARD | string | "admin" | Guard name for JWT authentication |

Advanced Configuration

Request Filtering

You can add a global filter function or model-specific filters to modify or validate request data:

createPlugin({
  // Global filter for all models
  filter: async (model, method, request, req) => {
    // Add timestamp to all requests
    return {
      ...request,
      timestamp: new Date().toISOString()
    };
  },
  access: {
    User: {
      // Model-specific filter
      filter: async (model, method, request, req) => {
        // Validate user creation
        if (method === 'create' && !request.email) {
          throw new Error('Email is required for user creation');
        }
        return request;
      }
    }
  }
});

Model-Specific Configuration

You can configure allowed methods and IP addresses for specific models:

createPlugin({
  access: {
    User: {
      allowedMethods: ['findMany', 'findUnique'], // Only allow read operations
      allowedIps: ['127.0.0.1', '192.168.1.1']   // Restrict access to specific IPs
    },
    Post: {
      allowedMethods: ['create', 'update'],       // Only allow write operations
      allowedIps: ['*']                           // Allow all IPs
    }
  }
});

Filter Function Parameters

The filter function receives the following parameters:

  • model: The Prisma model name
  • method: The Prisma method being called
  • request: The request body data
  • req: The full request object with state

The filter function can:

  • Modify the request data
  • Validate the request data
  • Throw errors to prevent invalid operations
  • Access request state and headers

📌 How to Use

The plugin provides a single dynamic endpoint:

POST /api/v1/prisma/:method/:model

Example Usage:

// Create a new user
POST /api/v1/prisma/create/user
{
  "name": "John Doe",
  "email": "[email protected]"
}

// Find users
POST /api/v1/prisma/findMany/user
{
  "where": {
    "email": "[email protected]"
  }
}

// Update user
POST /api/v1/prisma/update/user
{
  "where": {
    "id": 1
  },
  "data": {
    "name": "John Smith"
  }
}

Authentication

All requests require JWT authentication with the specified guard.

Error Responses

  • 400: Invalid method, model, or request data
  • 403: IP not allowed or authentication failed
  • 500: Server error

🔗 Related Plugins

You can find more TSDIAPI plugins here:
🔗 Available Plugins


👨‍💻 Contributing

Contributions are always welcome! If you have ideas for improving this plugin, feel free to open a pull request.

Author: unbywyd
GitHub Repository: https://github.com/unbywyd/tsdiapi-prisma-rest

📧 Contact: [email protected]

🚀 Happy coding with TSDIAPI! 🎉