0.1.1 • Published 4 months ago

@tsdiapi/dboptions v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@tsdiapi/dboptions: Database Options Plugin for TSDIAPI-Server

@tsdiapi/dboptions extends TSDIAPI-Server with dynamic database options, integrating seamlessly with Prisma. It enables storing and managing configuration settings in a database with optional DTO transformation and authentication control.


Features

  • Prisma Integration: Automatically adds a DbOption model for storing key-value configurations.
  • Dynamic API Routes: Provides endpoints for managing database options.
  • DTO Support: Optionally transform database-stored values using a DTO.
  • JWT Authentication: Secure access using a custom adminGuard function.
  • Auto-Registration: Automatically integrates controllers when enabled.
  • Feature Generator: Allows custom entity names for full control over the setup.

Installation

npm install @tsdiapi/dboptions

Or use the CLI to add the plugin:

tsdiapi plugins add dboptions

Usage

Register the Plugin

Add the plugin to your TSDIAPI-Server setup:

import { createApp } from "@tsdiapi/server";
import DboptionsPlugin from "@tsdiapi/dboptions";
import TsdiapiPrismaPlugin from "@tsdiapi/prisma";
import { isJWTValid } from "@tsdiapi/jwt-auth";
import { Dboptions } from "./dboptions.config";

createApp({
  plugins: [
    DboptionsPlugin({
      configDTO: Dboptions, // DTO for structuring option values
      adminGuard: async (req) => {
        const session = await isJWTValid<any>(req);
        if (!session) {
          return false;
        }
        return session.isAdmin; // Allow only admins
      }
    }),
    TsdiapiPrismaPlugin()
  ]
});

Configuration Options

OptionTypeDefaultDescription
configDTOClassnullDTO for transforming option values before storing or retrieving them.
adminGuardFunctionnullCustom function to validate Bearer authentication.

Auto-Registration

If DBOPTIONS_AUTO_REGISTER_CONTROLLERS is enabled, the plugin:

  • Adds the DbOption model to Prisma schema.
  • Automatically registers API controllers for managing options.

To disable auto-registration, use:

{
  "DBOPTIONS_AUTO_REGISTER_CONTROLLERS": false
}

For manual setup, use the feature generator to create a custom entity:

tsdiapi generate dboptions feature

This allows defining a custom database model and gaining full control over API behavior.


Summary

The @tsdiapi/dboptions plugin extends TSDIAPI with a database-driven configuration system. It supports Prisma, DTO-based transformations, and flexible authentication control. Use auto-registration for quick setup or manual generation for advanced customization. 🚀

0.0.1-alpha.25

4 months ago

0.0.1-alpha.24

4 months ago

0.2.0-alpha.2

4 months ago

0.2.0-alpha.1

4 months ago

0.2.0-alpha.3

4 months ago

0.1.0

4 months ago

0.1.1

4 months ago

0.1.1-alpha.26

4 months ago

0.0.1-alpha.23

5 months ago

0.0.1-alpha.22

5 months ago

0.0.1-alpha.16

5 months ago

0.0.1-alpha.18

5 months ago

0.0.1-alpha.17

5 months ago

0.0.1-alpha.21

5 months ago

0.0.1-alpha.19

5 months ago

0.0.1-alpha.15

5 months ago

0.0.1-alpha.14

5 months ago

0.0.1-alpha.13

5 months ago

0.0.1-alpha.12

5 months ago

0.0.1-alpha.11

5 months ago

0.0.1-alpha.10

5 months ago

0.0.1-alpha.9

5 months ago

0.0.1-alpha.8

5 months ago

0.0.1-alpha.7

5 months ago

0.0.1-alpha.6

5 months ago

0.0.1-alpha.5

5 months ago

0.0.1-alpha.4

5 months ago

0.0.1-alpha.2

5 months ago

0.0.1-alpha.1

5 months ago