Prisma Dmmf TransformerAPI ReferenceAPI Reference

API Reference

Last updated:

API Reference

Complete API documentation for Prisma DMMF transformer.

transformDMMF()

Transform Prisma DMMF to JSON Schema v7.

function transformDMMF(
  dmmf: DMMF.Document,
  options?: TransformOptions
): JSONSchema7

Parameters:

  • dmmf - Prisma DMMF document from prisma._getDmmf()
  • options - Transformation options (optional)

Returns: JSON Schema v7 document

Example:

import { transformDMMF } from "@visulima/prisma-dmmf-transformer";

const schema = transformDMMF(dmmf, {
  includeRequiredFields: "true",
});

getJSONSchemaProperty()

Get JSON Schema property for a specific DMMF field.

function getJSONSchemaProperty(
  field: DMMF.Field,
  options?: TransformOptions
): JSONSchema7Definition

Parameters:

  • field - DMMF field definition
  • options - Transformation options (optional)

Returns: JSON Schema property definition

Example:

import { getJSONSchemaProperty } from "@visulima/prisma-dmmf-transformer";

const property = getJSONSchemaProperty(field, {
  persistOriginalType: "true",
});

TransformOptions

Configuration options for transformation.

interface TransformOptions {
  keepRelationScalarFields?: "true" | "false";
  includeRequiredFields?: "true" | "false";
  persistOriginalType?: "true" | "false";
  schemaId?: string;
}

keepRelationScalarFields

Include foreign key fields in the schema.

  • Type: "true" | "false"
  • Default: "false"

includeRequiredFields

Add required array to schemas.

  • Type: "true" | "false"
  • Default: "false"

persistOriginalType

Preserve Prisma type information.

  • Type: "true" | "false"
  • Default: "false"

schemaId

Set schema $id property.

  • Type: string
  • Default: undefined

Type Definitions

DefinitionMap

Tuple of model name and JSON Schema definition.

type DefinitionMap = [name: string, definition: JSONSchema7Definition];

PropertyMap

Tuple with property metadata.

type PropertyMap = [...DefinitionMap, PropertyMetaData];

PropertyMetaData

Metadata about a property.

interface PropertyMetaData {
  hasDefaultValue: boolean;
  isScalar: boolean;
  required: boolean;
}

ModelMetaData

Metadata about a model.

interface ModelMetaData {
  enums: ReadonlyDeep<DMMF.DatamodelEnum[]>;
}

PrismaPrimitive

Prisma scalar types.

type PrismaPrimitive =
  | "String"
  | "Boolean"
  | "Int"
  | "BigInt"
  | "Float"
  | "Decimal"
  | "DateTime"
  | "Json"
  | "Bytes";

JSONSchema7

The output schema follows JSON Schema Draft 7:

interface JSONSchema7 {
  $schema: string;
  $id?: string;
  type: string;
  definitions: Record<string, JSONSchema7Definition>;
  properties: Record<string, JSONSchema7Definition>;
}

DMMF Types

From @prisma/generator-helper:

DMMF.Document

interface Document {
  datamodel: Datamodel;
  schema: Schema;
  mappings: Mappings;
}

DMMF.Model

interface Model {
  name: string;
  fields: Field[];
  primaryKey: PrimaryKey | null;
  uniqueFields: string[][];
  uniqueIndexes: UniqueIndex[];
}

DMMF.Field

interface Field {
  name: string;
  kind: FieldKind;
  type: string;
  isRequired: boolean;
  isList: boolean;
  isUnique: boolean;
  isId: boolean;
  isReadOnly: boolean;
  hasDefaultValue: boolean;
  default?: FieldDefault;
  relationName?: string;
  relationFromFields?: string[];
  relationToFields?: string[];
}
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues