Skip to content

Commit

Permalink
chore: Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed May 19, 2024
1 parent 35da088 commit 0f84728
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"temp-dir": "2.X",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"type-fest": "^4.18.2",
"typescript": "^5.4.5",
"watchexec-bin": "^1.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createConfig } from './helpers/create-config';
import { factoryGetSourceFile } from './helpers/factory-get-source-file';
import { createGetModelName } from './helpers/get-model-name';
import {
DMMF,
Document,
EventArguments,
Field,
Model,
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function generate(
outputFilePattern: config.outputFilePattern,
eventEmitter,
});
const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf)) as DMMF.Document;
const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf)) as Document;
const removeTypes = new Set<string>();
const eventArguments: EventArguments = {
schema,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/combine-scalar-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AwaitEventEmitter from 'await-event-emitter';
import { cloneDeep, keyBy, remove } from 'lodash';

import { BeforeGenerateField } from '../event-names';
import { DMMF, EventArguments, InputType } from '../types';
import { EventArguments, InputType, SchemaArg } from '../types';

/**
* Subscribes on 'BeforeInputType'
Expand All @@ -28,7 +28,7 @@ function beforeInputType(
}
}

function beforeGenerateField(field: DMMF.SchemaArg): void {
function beforeGenerateField(field: SchemaArg): void {
for (const fieldInput of field.inputTypes) {
if (fieldInput.location !== 'inputObjectTypes') {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/model-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createObjectSettings, ObjectSettings } from '../helpers/object-settings';
import { DMMF, EventArguments, Field } from '../types';
import { EventArguments, Field, Model } from '../types';

export function modelData(model: DMMF.Model, args: EventArguments) {
export function modelData(model: Model, args: EventArguments) {
const {
config,
modelNames,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/get-where-unique-at-least-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getWhereUniqueAtLeastKeys(model: DMMF.Model) {
return names;
}

function createFieldName(args: { name?: string | null; fields: string[] }) {
function createFieldName(args: { name?: string | null; fields: Readonly<string[]> }) {
const { name, fields } = args;

return name || fields.join('_');
Expand Down
14 changes: 9 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { DMMF } from '@prisma/client/runtime/library';
import AwaitEventEmitter from 'await-event-emitter';
import { Project, SourceFile } from 'ts-morph';
import type { WritableDeep } from 'type-fest';

import { createConfig } from './helpers/create-config';
import { ObjectSettings } from './helpers/object-settings';

export type InputType = DMMF.InputType;
export type InputType = WritableDeep<DMMF.InputType>;
export type FieldLocation = DMMF.FieldLocation;
export type OutputType = DMMF.OutputType;
export type SchemaField = DMMF.SchemaField;
export type OutputType = WritableDeep<DMMF.OutputType>;
export type SchemaField = WritableDeep<DMMF.SchemaField>;
export type SchemaEnum = DMMF.SchemaEnum;
export type Model = DMMF.Model;
export type Model = WritableDeep<DMMF.Model>;
export type SchemaArg = WritableDeep<DMMF.SchemaArg>;
export type Schema = WritableDeep<DMMF.Schema>;
export type Document = WritableDeep<DMMF.Document>;

export type FieldOutputType = SchemaField['outputType'];

Expand All @@ -28,7 +32,7 @@ export type TypeRecord = Partial<{
export type GeneratorConfiguration = ReturnType<typeof createConfig>;

export type EventArguments = {
schema: DMMF.Schema;
schema: Schema;
models: Map<string, Model>;
modelNames: string[];
modelFields: Map<string, Map<string, Field>>;
Expand Down

0 comments on commit 0f84728

Please sign in to comment.