@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
86 lines (85 loc) • 3.36 kB
TypeScript
import { type BasePrismaClient, type BaseTypeMap, type FirstLetterLowercase, type PartialWithUndefined, type PrismaAllModelsCreate, type PrismaBasicModel, type PrismaModelName } from '@augment-vir/common';
import { type IsAny } from 'type-fest';
/**
* Params for `prisma.client.addData()`. This is similar to {@link PrismaAllModelsCreate} but allows
* an array of {@link PrismaAllModelsCreate} for sequential data creation.
*
* @category Prisma : Node
* @category Package : @augment-vir/node
* @example
*
* ```ts
* import {PrismaAddModelData} from '@augment-vir/common';
* import {type PrismaClient} from '@prisma/client';
*
* const mockData: PrismaAddModelData<PrismaClient> = [
* {
* user: {
* mockUser1: {
* first_name: 'one',
* id: 123,
* // etc.
* },
* mockUser2: {
* first_name: 'two',
* id: 124,
* authRole: 'user',
* // etc.
* },
* },
* },
* {
* region: [
* {
* id: 1,
* name: 'North America',
* // etc.
* },
* {
* id: 2,
* name: 'Europe',
* // etc.
* },
* ],
* },
* ];
* ```
*
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export type PrismaAddDataData<PrismaClient extends BasePrismaClient, TypeMap extends BaseTypeMap> = Readonly<PrismaAllModelsCreate<PrismaClient, TypeMap>> | ReadonlyArray<Readonly<PrismaAllModelsCreate<PrismaClient, TypeMap>>>;
export declare function addData<const PrismaClient extends BasePrismaClient, const TypeMap extends BaseTypeMap>(prismaClient: Readonly<PrismaClient>, data: IsAny<PrismaClient> extends true ? any : PrismaAddDataData<PrismaClient, TypeMap>): Promise<void>;
/** These are not the real model names, they are the names on the PrismaClient (which are lowercase). */
export declare function getAllPrismaModelKeys(prismaClient: BasePrismaClient): string[];
/**
* Options for `prisma.client.dumpData`.
*
* @category Prisma : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export type PrismaDataDumpOptions = {
/**
* The max number of entries to load per model. Set to `0` to remove this limit altogether
* (which could be _very_ expensive for your database).
*
* @default 100
*/
limit: number;
/**
* Strings to omit from the dumped data. For testability, omitting date or UUID id fields is a
* common practice.
*/
omitFields: string[];
};
/**
* Output for `prisma.client.dumpData`.
*
* @category Prisma : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export type PrismaDumpOutput<TypeMap extends BaseTypeMap> = Partial<{
[Model in PrismaModelName<TypeMap> as FirstLetterLowercase<Model>]: PrismaBasicModel<TypeMap, Model>[];
}>;
export declare function dumpData<const TypeMap extends BaseTypeMap>(prismaClient: BasePrismaClient, options?: Readonly<PartialWithUndefined<PrismaDataDumpOptions>>): Promise<PrismaDumpOutput<TypeMap>>;