Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
]
}
},
"files": [
"dist"
],
"scripts": {
"test": "npm run eslint && npm run tscheck && npm run test:cov",
"mocha": "node node_modules/mocha/bin/mocha",
Expand Down Expand Up @@ -69,7 +72,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^5.7.0",
"@prisma/generator-helper": "^5.11.0",
"await-event-emitter": "^2.0.2",
"filenamify": "4.X",
"flat": "5.X",
Expand All @@ -80,7 +83,8 @@
"outmatch": "^0.7.0",
"pluralize": "^8.0.0",
"pupa": "2.X",
"ts-morph": ">=11 <=16"
"ts-morph": ">=11 <=16",
"type-fest": "4.13.0"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
Expand All @@ -91,7 +95,7 @@
"@nestjs/graphql": "^12.0.11",
"@nestjs/platform-express": "^10.2.10",
"@paljs/plugins": "^6.0.7",
"@prisma/client": "^5.7.0",
"@prisma/client": "^5.11.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.5",
Expand Down
3 changes: 2 additions & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
const AwaitEventEmitter = require('await-event-emitter').default;

import AEE from 'await-event-emitter';
import { WritableDeep } from 'type-fest';

export async function generate(
args: GeneratorOptions & {
Expand Down Expand Up @@ -107,7 +108,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 WritableDeep<DMMF.Document>;
const removeTypes = new Set<string>();
const eventArguments: EventArguments = {
schema,
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/combine-scalar-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { cloneDeep, keyBy, remove } from 'lodash';

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

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

function beforeGenerateField(field: DMMF.SchemaArg): void {
function beforeGenerateField(field: WritableDeep<DMMF.SchemaArg>): void {
for (const fieldInput of field.inputTypes) {
if (fieldInput.location !== 'inputObjectTypes') {
continue;
Expand Down
15 changes: 14 additions & 1 deletion src/handlers/emit-single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ function classProperty(
propertyType,
t => t === 'null' || t.startsWith('Prisma.'),
);
const mappedInstanceofTypes = instanceofTypes.map(t => `InstanceType<typeof ${t}>`);
const mappedInstanceofTypes = instanceofTypes.map((t) => {
if (t.endsWith(`RelationFilter`)) {
let whereInput;
if (isList) {
whereInput = whereInput.replace(`RelationFilter`, `WhereInput`);
} else {
whereInput = t.replace(`ListRelationFilter`, `WhereInput`);
}

return `XOR<InstanceType<typeof ${t}>, ${whereInput}>`;
}

return `InstanceType<typeof ${t}>`;
Comment on lines +26 to +37
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this?
You can control type by using setting useInputType_

});

property.type = [...mappedInstanceofTypes, ...safeTypes].join(' | ');
}
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/model-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { WritableDeep } from 'type-fest';
import { createObjectSettings, ObjectSettings } from '../helpers/object-settings';
import { DMMF, EventArguments, Field } from '../types';

export function modelData(model: DMMF.Model, args: EventArguments) {
export function modelData(model: WritableDeep<DMMF.Model>, args: EventArguments) {
const {
config,
modelNames,
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/get-where-unique-at-least-keys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DMMF } from '../types';
import { Model } from '../types';

export function getWhereUniqueAtLeastKeys(model: DMMF.Model) {
export function getWhereUniqueAtLeastKeys(model: Model) {
const names = model.fields
.filter(field => field.isUnique || field.isId)
.map(field => field.name);
Expand Down
12 changes: 11 additions & 1 deletion src/helpers/property-structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ export function propertyStructure(args: {
hasQuestionToken,
hasExclamationToken,
} = args;
const type = propertyType.map(type => (isList ? `Array<${type}>` : type)).join(' | ');
const type = propertyType.map(type2 => {
if (isList) {
if (name === `AND` || name === `NOT`) {
return `Array<${type2}> | ${type2}`;
}

return `Array<${type2}>`;
}

return type2;
}).join(' | ');

return {
kind: StructureKind.Property,
Expand Down
11 changes: 6 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Project, SourceFile } from 'ts-morph';

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

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 FieldOutputType = SchemaField['outputType'];

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

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