Options
All
  • Public
  • Public/Protected
  • All
Menu

prisma-slug

Index

Type aliases

Middleware<T>: (params: MiddlewareParams, next: (params: MiddlewareParams) => Promise<T>) => Promise<T>

Type parameters

  • T = any

Type declaration

MiddlewareParams<ModelName>: { action: PrismaAction; args: any; dataPath: string[]; model?: ModelName; runInTransaction: boolean }

These options are being passed in to the middleware as "params".

Type parameters

  • ModelName = string

Type declaration

  • action: PrismaAction

    Method used to trigger this request.

  • args: any

    The arguments passed into Prisma.

  • dataPath: string[]

    Where Prisma will be updating.

  • Optional model?: ModelName

    The name of the Prisma model the operation is running on.

  • runInTransaction: boolean

    Whether this is running in a transaction.

PrismaAction: "findUnique" | "findMany" | "findFirst" | "create" | "createMany" | "update" | "updateMany" | "upsert" | "delete" | "deleteMany" | "executeRaw" | "queryRaw" | "aggregate" | "count" | "runCommandRaw"
PrismaSlugOptions: { onDone?: any; onError: any; slugify: any; source: any; willGenerate: any }

Options that can be passed into the PrismaSlug() function.

Type declaration

  • onDone?:function
    • Additional logic to perform after the slug has been generated.

      Parameters

      Returns void

  • onError:function
    • onError(error: unknown): void
    • Configure what happens when an error occurs generating a slug or finding the source.

      By default, the error is printed to STDERR.

      Parameters

      • error: unknown

      Returns void

  • slugify:function
    • slugify(source: string): string | Promise<string>
    • The function that is used to generate the slug for a given source string.

      By default, this uses slugify().

      Parameters

      • source: string

      Returns string | Promise<string>

  • source:function
    • source(data: Record<string, any>): string | Promise<string>
    • The function to use for generating the source text to slugify. The string returned from this function will be used to generate the slug that is saved to the database.

      By default, this will return the .name key of the passed-in object.

      Parameters

      • data: Record<string, any>

      Returns string | Promise<string>

  • willGenerate:function
    • Determine whether to generate a slug for this particular record. By default, this ensures that the params.action is either "create" or "delete".

      Parameters

      Returns boolean

Functions

  • Create a Prisma middleware that generates slugs in a field called slug for models that have a field called name.

    Parameters

    • Optional options: Partial<PrismaSlugOptions>

      Optional configuration for the middleware

    Returns Middleware

Generated using TypeDoc