Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@prisma/generator-helper
Advanced tools
@prisma/generator-helper is a utility package designed to assist in the creation of custom generators for Prisma. It provides a set of tools and types to facilitate the development of generators that can extend or customize the behavior of Prisma's schema and client generation.
Generator Definition
This feature allows you to define a custom generator by specifying the manifest and generation logic. The `onManifest` function provides metadata about the generator, while the `onGenerate` function contains the logic to execute when the generator is run.
const { generatorHandler } = require('@prisma/generator-helper');
generatorHandler({
onManifest() {
return {
defaultOutput: 'default-output-path',
prettyName: 'My Custom Generator',
};
},
onGenerate(options) {
console.log('Generating with options:', options);
},
});
Helper Types
The package provides TypeScript types for Prisma's Data Model Meta Format (DMMF), which can be used to type-check and process the Prisma schema programmatically.
const { DMMF } = require('@prisma/generator-helper');
/**
* @param {DMMF.Document} dmmf
*/
function processDMMF(dmmf) {
console.log('Processing DMMF:', dmmf);
}
File Writing Utilities
This feature includes utilities for safely writing files, ensuring that directories are created as needed and that existing files are not overwritten unintentionally.
const { writeFileSafely } = require('@prisma/generator-helper');
const path = require('path');
const outputPath = path.join(__dirname, 'output.txt');
writeFileSafely(outputPath, 'Generated content').then(() => {
console.log('File written successfully');
});
Yeoman Generator is a robust scaffolding tool for building out new projects. It provides a higher-level abstraction for creating generators, including prompts, file system utilities, and more. Compared to @prisma/generator-helper, Yeoman is more general-purpose and not specifically tailored to Prisma.
Plop is a micro-generator framework that makes it easy to create code generators with a simple API. It focuses on simplicity and ease of use, making it a good alternative for smaller, less complex generator tasks. Unlike @prisma/generator-helper, Plop is not specifically designed for Prisma and lacks Prisma-specific utilities and types.
Hygen is a fast and lightweight code generator that uses plain text templates. It is designed for quick and easy setup and usage. While it is versatile and can be used for various generation tasks, it does not offer the Prisma-specific features and types provided by @prisma/generator-helper.
FAQs
This package is intended for Prisma's internal use
The npm package @prisma/generator-helper receives a total of 707,079 weekly downloads. As such, @prisma/generator-helper popularity was classified as popular.
We found that @prisma/generator-helper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.