
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@prisma-next/contract
Advanced tools
Core contract types, framework component descriptors, and JSON schemas for Prisma Next.
This package provides the foundational type definitions for Prisma Next, including:
ContractBase, Source, FamilyInstance) that are shared across all target familiesFamilyDescriptor, TargetDescriptor, AdapterDescriptor, DriverDescriptor, ExtensionDescriptor) and identity instance bases (FamilyInstance, TargetInstance, AdapterInstance, DriverInstance, ExtensionInstance) that plane-specific types extendDocumentContract)ColumnDefault for db-agnostic defaults (literal and function) reused across family contracts and authoring buildersisDocumentContract)TargetFamilyHook, ValidationContext, TypesImportSpec) that are shared between emitter and control planeThe contract supports document target families:
DocumentContract, ContractMarkerRecord, and related typesTargetFamilyHook, ValidationContext, TypesImportSpec)contract.json files in IDEs and tooling
data-contract-document-v1.json (Document family)Import contract types in your TypeScript code:
import type {
ContractMarkerRecord,
DocumentContract,
TargetFamilyHook,
TypesImportSpec,
ValidationContext,
} from '@prisma-next/contract/types';
import { isDocumentContract } from '@prisma-next/contract/types';
// Use type guards to narrow the contract type
function processContract(contract: DocumentContract) {
if (isDocumentContract(contract)) {
// contract is DocumentContract
console.log(contract.storage.document.collections);
}
}
// Use ContractMarkerRecord for database marker operations
function processMarker(marker: ContractMarkerRecord) {
console.log(marker.storageHash, marker.profileHash);
}
// Use emitter types for implementing family hooks
const myFamilyHook: TargetFamilyHook = {
id: 'my-family',
validateTypes: (ir, ctx: ValidationContext) => {
// Validation logic
},
validateStructure: (ir) => {
// Structure validation
},
generateContractTypes: (ir, codecTypeImports: TypesImportSpec[], operationTypeImports: TypesImportSpec[]) => {
// Type generation
return '// Generated types...';
},
};
Import base descriptor and instance interfaces to define or type-check framework components:
import type {
// Descriptors
ComponentDescriptor,
FamilyDescriptor,
TargetDescriptor,
AdapterDescriptor,
DriverDescriptor,
ExtensionDescriptor,
// Instances
FamilyInstance,
TargetInstance,
AdapterInstance,
DriverInstance,
ExtensionInstance,
} from '@prisma-next/contract/framework-components';
// Component descriptors share common properties
interface MyDescriptor extends ComponentDescriptor<'custom'> {
readonly customField: string;
}
// Use FamilyDescriptor for family components
const sqlFamily: FamilyDescriptor<'sql'> = {
kind: 'family',
id: 'sql',
familyId: 'sql',
version: '0.0.1',
};
// Use TargetDescriptor for target components
const postgresTarget: TargetDescriptor<'sql', 'postgres'> = {
kind: 'target',
id: 'postgres',
familyId: 'sql',
targetId: 'postgres',
version: '0.0.1',
capabilities: { postgres: { returning: true } },
};
// Identity instance bases are extended by plane-specific instances
interface MySqlInstance extends FamilyInstance<'sql'> {
// Plane-specific methods...
}
The component hierarchy is:
Family (e.g., 'sql', 'document')
└── Target (e.g., 'postgres', 'mysql', 'mongodb')
├── Adapter (protocol/dialect implementation)
├── Driver (connection/execution layer)
└── Extension (optional capabilities like pgvector)
Plane-specific descriptors (ControlFamilyDescriptor, RuntimeTargetDescriptor, etc.) extend these bases with plane-specific factory methods and capabilities.
Reference the appropriate JSON schema in your contract.json files to enable IDE validation and autocomplete.
For document targets (MongoDB, Firestore, etc.):
{
"$schema": "node_modules/@prisma-next/contract/schemas/data-contract-document-v1.json",
"schemaVersion": "1",
"target": "mongodb",
"targetFamily": "document",
"storageHash": "sha256:...",
"storage": {
"document": {
"collections": {
"users": {
"name": "users",
"fields": {
"id": { "type": "objectId", "nullable": false },
"email": { "type": "string", "nullable": false }
}
}
}
}
}
}
Note: For SQL contracts, use @prisma-next/sql-query/schema-sql instead:
{
"$schema": "node_modules/@prisma-next/sql-query/schemas/data-contract-sql-v1.json",
"schemaVersion": "1",
"target": "postgres",
"targetFamily": "sql",
"storageHash": "sha256:...",
"storage": {
"tables": {
"user": {
"columns": {
"id": { "type": "int4", "nullable": false },
"email": { "type": "text", "nullable": false }
},
"primaryKey": {
"columns": ["id"],
"name": "user_pkey"
}
}
}
}
}
After installing this package, IDEs like VS Code will automatically:
All contracts share these common fields:
schemaVersion (required): Contract schema version (currently "1")target (required): Database target identifier (e.g., "postgres", "mongo", "firestore")targetFamily (required): Target family classification ("document" for document contracts)storageHash (required): SHA-256 hash of the storage schema structureexecutionHash (optional): SHA-256 hash of execution-time mutation defaultsprofileHash (optional): SHA-256 hash of the capability profilecapabilities (optional): Capability flags declared by the contractextensionPacks (optional): Extension packs and their configurationmeta (optional): Non-semantic metadata (excluded from hashing)sources (optional): Read-only sources (views, etc.) available for queryingstorage.document.collections: Object mapping collection names to collection definitions
name: Logical collection nameid (optional): ID generation strategy (auto, client, uuid, objectId)fields: Field definitions using FieldType (supports nested objects and arrays)indexes (optional): Array of index definitions with keys and optional predicatesreadOnly (optional): Whether mutations are disallowednullable: false explicit for columns with defaults in emitted contracts.value in the emitted contract; avoid falsey literals unless the emitter preserves them.defaults.* capability when using function defaults like autoincrement() or now().Column defaults are handled differently depending on output format:
db introspect): Labels show only type and nullability, e.g. id: int4 (not nullable). Defaults are omitted from labels to keep tree output concise.db introspect --json): Full default information is preserved in the schema IR.SchemaTreeNode.meta.default for tooling that needs them.This separation keeps human-readable tree output clean while preserving full data for automation.
ParamDescriptor describes a single parameter in an execution plan. Used in PlanMeta.paramDescriptors for param encoding and plugin inspection.
source: Origin of the parameter:
'dsl': From the Prisma Next DSL/ORM query builder'raw': From raw SQL (e.g. sql\...`` with placeholders)'lane': From a lane integration (e.g. Kysely) that transforms an external AST into PN plan form; the lane id is in meta.laneindex (optional): 1-based position into plan.paramsname (optional): Parameter name for codec resolutioncodecId, nativeType, nullable (optional): Type metadata from contractrefs (optional): { table, column } when the param is used against a known columnUse type guards to narrow the contract type:
import { isDocumentContract } from '@prisma-next/contract/types';
if (isDocumentContract(contract)) {
// TypeScript knows contract is DocumentContract
const collections = contract.storage.document.collections;
}
./types: Core contract type definitions, type guards, and emitter SPI types./framework-components: Framework component model (descriptors + identity instance bases)./pack-manifest-types: Extension pack manifest types./ir: Contract IR types./schema-document: Document family JSON Schema (schemas/data-contract-document-v1.json)flowchart TD
subgraph "Contract Package"
TYPES[Type Definitions]
SCHEMA[JSON Schemas]
GUARDS[Type Guards]
end
subgraph "Consumers"
EMITTER[Emitter]
RUNTIME[Runtime]
QUERY[Query Builder]
end
TYPES --> EMITTER
TYPES --> RUNTIME
TYPES --> QUERY
SCHEMA --> EMITTER
GUARDS --> RUNTIME
GUARDS --> QUERY
@prisma-next/operations: For OperationRegistry type used in ValidationContext and TargetFamilyHook@prisma-next/operations, but @prisma-next/operations does not depend on this package (no cycle). The OperationRegistry type is used in emitter SPI types that are shared between migration-plane and shared-plane packages.Dependents:
@prisma-next/contract-authoring: Uses core contract types for authoring@prisma-next/sql-contract: Extends core contract types for SQL family@prisma-next/emitter: Uses contract types for emission@prisma-next/runtime: Uses contract types for runtime execution@prisma-next/sql-query: Uses contract types for query building@prisma-next/sql-query: SQL query builder and plan types@prisma-next/runtime: Runtime execution engine that consumes contractsFAQs
Data contract type definitions and JSON schema for Prisma Next
The npm package @prisma-next/contract receives a total of 21,635 weekly downloads. As such, @prisma-next/contract popularity was classified as popular.
We found that @prisma-next/contract 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.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.