@dmc--98/dfe-prisma
v0.1.3
Published
Prisma database adapter for Dynamic Form Engine
Downloads
512
Readme
@dmc--98/dfe-prisma
Prisma ORM adapter for the Dynamic Form Engine.
Install
npm install @dmc--98/dfe-prisma @dmc--98/dfe-server @prisma/client
npm install -D prismaRecommended Migration Flow
Use the adapter-aware CLI first, then hand off to Prisma's normal migration command:
npx dfe migrate plan --adapter prisma
npx dfe migrate generate --adapter prisma
npx prisma migrate dev --schema prisma/schema.prisma --name add_dfe_tables
npx dfe migrate doctor --adapter prisma --database-url "$DATABASE_URL"What each step does:
planinspects the project and tells you whether DFE models are already wired intoprisma/schema.prisma.generatescaffoldsprisma/dfe-schema.prismawhen the DFE models are not merged yet.prisma migrate devremains the source of truth for creating or applying the actual migration.doctorverifies local project wiring and, whenDATABASE_URLis provided, checks the live PostgreSQL tables and columns too.
If generate creates prisma/dfe-schema.prisma, merge that fragment into your main prisma/schema.prisma before running Prisma migrations.
Lower-Level Schema Options
Option A: scaffold the fragment directly:
npx dfe add prisma-schemaOption B: copy from the package:
cat node_modules/@dmc--98/dfe-prisma/schema/schema.prisma >> prisma/schema.prismaTables Created
| Table | Purpose |
|-------|---------|
| dfe_forms | Form definitions (slug, title, description) |
| dfe_form_versions | Versioned form configs (draft/published/archived) |
| dfe_steps | Step definitions with config (API contracts, review) |
| dfe_fields | Field definitions (type, config, conditions) |
| dfe_field_options | Dynamic SELECT options |
| dfe_submissions | Form submission state (progress, context) |
Usage
import { PrismaClient } from '@prisma/client'
import { PrismaDatabaseAdapter } from '@dmc--98/dfe-prisma'
const prisma = new PrismaClient()
const db = new PrismaDatabaseAdapter(prisma)Custom API Contract Execution
By default, API contracts use an in-memory store. For production, provide your own:
const db = new PrismaDatabaseAdapter(prisma, {
executeApiContract: async (contract, body) => {
switch (contract.resourceName) {
case 'Employee':
return prisma.employee.create({ data: body as any })
case 'Assignment':
return prisma.assignment.create({ data: body as any })
default:
throw new Error(`Unknown resource: ${contract.resourceName}`)
}
},
})This maps the logical resourceName in the API contract to your actual Prisma models.
Links
- Source: packages/prisma
- Docs source: docs/packages/prisma.md
- Issues: https://github.com/dmc-98/dynamic-form-engine/issues
