prisma-json-types-generator
Advanced tools
Comparing version
export type Declaration = { | ||
/** path to the original file */ | ||
/** Path to the original file */ | ||
sourcePath: string; | ||
/** the modified or not content of the file */ | ||
/** The modified or not content of the file */ | ||
content: string; | ||
/** replaces the coordinates with the provided text, adjusting the coords to previous changes. */ | ||
/** | ||
* Replaces the coordinates with the provided text, adjusting the coords to previous | ||
* changes. | ||
*/ | ||
replacer: (start: number, end: number, text: string) => void; | ||
/** a list of changes made in the original file to adjust any future coordinates of texts */ | ||
/** A list of changes made in the original file to adjust any future coordinates of texts */ | ||
changeset: Array<{ | ||
@@ -13,3 +16,3 @@ start: number; | ||
}>; | ||
/** updates the original file of sourcePath with the content's contents */ | ||
/** Updates the original file of sourcePath with the content's contents */ | ||
update: () => Promise<void>; | ||
@@ -16,0 +19,0 @@ }; |
import type ts from 'typescript'; | ||
import type { Declaration } from '../file/reader'; | ||
/** | ||
* Handles and replaces the signature of a typed field. | ||
*/ | ||
/** Handles and replaces the signature of a typed field. */ | ||
export declare function replaceSignature(signatureType: ts.TypeNode, typename: string, nsName: string, replacer: Declaration['replacer'], fieldName: string, modelName: string, typeAliasName: string): void; | ||
//# sourceMappingURL=handle-signature.d.ts.map |
@@ -5,5 +5,3 @@ "use strict"; | ||
const regex_1 = require("./regex"); | ||
/** | ||
* Handles and replaces the signature of a typed field. | ||
*/ | ||
/** Handles and replaces the signature of a typed field. */ | ||
function replaceSignature(signatureType, typename, nsName, replacer, fieldName, modelName, typeAliasName) { | ||
@@ -32,2 +30,41 @@ // Updates should leave optional fields | ||
// | ||
// String | ||
// | ||
case 'string': | ||
replacer(signatureType.pos, signatureType.end, name); | ||
break; | ||
case 'string[]': | ||
replacer(signatureType.pos, signatureType.end, `(${name})[]`); | ||
break; | ||
case 'string | null': | ||
replacer(signatureType.pos, signatureType.end, name); | ||
break; | ||
case `StringFilter | string`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringFilter<${name}> | ${name}`); | ||
break; | ||
case `StringNullableFilter | string | null`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringNullableFilter<${name}> | ${name} | null`); | ||
break; | ||
case `StringNullableListFilter`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringNullableListFilter<${name}>`); | ||
break; | ||
case `StringWithAggregatesFilter | string`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringWithAggregatesFilter<${name}> | ${name}`); | ||
break; | ||
case `StringNullableWithAggregatesFilter | string | null`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringNullableWithAggregatesFilter<${name}> | ${name}`); | ||
break; | ||
case `StringFieldUpdateOperationsInput | string`: | ||
replacer(signatureType.pos, signatureType.end, `TypedStringFieldUpdateOperationsInput<${name}> | ${name}`); | ||
break; | ||
case `NullableStringFieldUpdateOperationsInput | string | null`: | ||
replacer(signatureType.pos, signatureType.end, `TypedNullableStringFieldUpdateOperationsInput<${name}> | ${name} | null`); | ||
break; | ||
case `${modelName}Create${fieldName}Input | Enumerable<string>`: | ||
replacer(signatureType.pos, signatureType.end, `CreateStringArrayInput<${name}> | Enumerable<${name}>`); | ||
break; | ||
case `${modelName}Update${fieldName}Input | Enumerable<string>`: | ||
replacer(signatureType.pos, signatureType.end, `CreateStringArrayInput<${name}> | Enumerable<${name}>`); | ||
break; | ||
// | ||
// Nullable | ||
@@ -34,0 +71,0 @@ // |
@@ -52,2 +52,121 @@ "use strict"; | ||
/** | ||
* A typed version of NestedStringFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringFilter<S extends string> = Prisma.StringFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringFilter<S> | S | ||
} | ||
/** | ||
* A typed version of StringFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringFilter<S extends string> = Prisma.StringFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringFilter<S> | S | ||
} | ||
/** | ||
* A typed version of NestedStringNullableFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringNullableFilter<S extends string> = Prisma.StringNullableFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of StringNullableFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableFilter<S extends string> = Prisma.StringNullableFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of NestedStringWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringWithAggregatesFilter<S extends string> = Prisma.NestedStringWithAggregatesFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringWithAggregatesFilter<S> | S | ||
} | ||
/** | ||
* A typed version of StringWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringWithAggregatesFilter<S extends string> = Prisma.StringWithAggregatesFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not?: TypedNestedStringWithAggregatesFilter<S> | S | ||
} | ||
/** | ||
* A typed version of NestedStringNullableWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringNullableWithAggregatesFilter<S extends string> = Prisma.NestedStringNullableWithAggregatesFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableWithAggregatesFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of tringNullableWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableWithAggregatesFilter<S extends string> = Prisma.StringNullableWithAggregatesFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not?: TypedNestedStringNullableWithAggregatesFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of StringFieldUpdateOperationsInput, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringFieldUpdateOperationsInput<S extends string> = Prisma.StringFieldUpdateOperationsInput & { | ||
set?: S | ||
} | ||
/** | ||
* A typed version of NullableStringFieldUpdateOperationsInput, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNullableStringFieldUpdateOperationsInput<S extends string> = Prisma.NullableStringFieldUpdateOperationsInput & { | ||
set?: S | null | ||
} | ||
/** | ||
* A typed version of StringNullableListFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableListFilter<S extends string> = Prisma.StringNullableListFilter & { | ||
equals?: Enumerable<S> | null | ||
has?: S | null | ||
hasEvery?: Enumerable<S> | ||
hasSome?: Enumerable<S> | ||
} | ||
/** | ||
* A typed version of the input type to update a string[] field, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type UpdateStringArrayInput<S extends string> = { | ||
set?: Enumerable<S> | ||
push?: S | Enumerable<S> | ||
} | ||
/** | ||
* A typed version of the input type to create a string[] field, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type CreateStringArrayInput<S extends string> = { | ||
set?: Enumerable<S> | ||
} | ||
`.trim(); | ||
@@ -54,0 +173,0 @@ } |
export declare const JSON_REGEX: RegExp; | ||
/** | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific model | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific | ||
* model | ||
*/ | ||
export declare function regexForPrismaType(name: string): RegExp[]; | ||
/** | ||
* If the provided type is a update one variant | ||
*/ | ||
/** If the provided type is a update one variant */ | ||
export declare function isUpdateOne(type: string): RegExpMatchArray | null; | ||
//# sourceMappingURL=regex.d.ts.map |
@@ -6,3 +6,4 @@ "use strict"; | ||
/** | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific model | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific | ||
* model | ||
*/ | ||
@@ -33,5 +34,3 @@ function regexForPrismaType(name) { | ||
exports.regexForPrismaType = regexForPrismaType; | ||
/** | ||
* If the provided type is a update one variant | ||
*/ | ||
/** If the provided type is a update one variant */ | ||
function isUpdateOne(type) { | ||
@@ -38,0 +37,0 @@ return type.match(/UpdateInput$/m) || type.match(/UpdateWithout(?:\\w+?)Input$/m); |
import type ts from 'typescript'; | ||
import type { Declaration } from '../file/reader'; | ||
import type { ModelWithRegex } from './dmmf'; | ||
import type { Declaration } from '../file/reader'; | ||
export declare function replaceObject(model: ModelWithRegex, object: ts.TypeLiteralNode, nsName: string, replacer: Declaration['replacer'], typeAliasName: string): void; | ||
//# sourceMappingURL=replace-object.d.ts.map |
{ | ||
"name": "prisma-json-types-generator", | ||
"version": "2.3.0", | ||
"description": "Changes JsonValues to your custom typescript type", | ||
"version": "2.2.3", | ||
"main": "dist/generator.js", | ||
"bin": "./dist/bin.js", | ||
"license": "MIT", | ||
"funding": "https://github.com/ArthurFiorette/prisma-json-types-generator?sponsor=1", | ||
"repository": "https://github.com/arthurfiorette/prisma-json-types-generator.git", | ||
"bugs": "https://github.com/arthurfiorette/prisma-json-types-generator/issues", | ||
"author": "Arthur Fiorette <npm@arthur.place>", | ||
"keywords": [ | ||
@@ -18,2 +11,17 @@ "prisma", | ||
], | ||
"bugs": "https://github.com/arthurfiorette/prisma-json-types-generator/issues", | ||
"repository": "https://github.com/arthurfiorette/prisma-json-types-generator.git", | ||
"funding": "https://github.com/ArthurFiorette/prisma-json-types-generator?sponsor=1", | ||
"license": "MIT", | ||
"author": "Arthur Fiorette <npm@arthur.place>", | ||
"main": "dist/generator.js", | ||
"bin": "./dist/bin.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc -w", | ||
"format": "prettier --write .", | ||
"prepack": "rm -rf dist && pnpm build", | ||
"start": "node dist/bin.js", | ||
"test": "prisma generate && tsc --noEmit -p tsconfig.test.json" | ||
}, | ||
"dependencies": { | ||
@@ -26,3 +34,3 @@ "@prisma/generator-helper": "^4.10.1", | ||
"@prisma/client": "^4.10.1", | ||
"@types/node": "18.13.0", | ||
"@types/node": "18.15.3", | ||
"@types/prettier": "2.7.2", | ||
@@ -35,10 +43,3 @@ "prettier": "2.8.4", | ||
"node": ">=14.0" | ||
}, | ||
"scripts": { | ||
"start": "node dist/bin.js", | ||
"dev": "tsc -w", | ||
"build": "tsc", | ||
"format": "prettier --write .", | ||
"test": "prisma generate && tsc --noEmit -p tsconfig.test.json" | ||
} | ||
} | ||
} |
@@ -6,11 +6,14 @@ import fs from 'fs/promises'; | ||
export type Declaration = { | ||
/** path to the original file */ | ||
/** Path to the original file */ | ||
sourcePath: string; | ||
/** the modified or not content of the file */ | ||
/** The modified or not content of the file */ | ||
content: string; | ||
/** replaces the coordinates with the provided text, adjusting the coords to previous changes. */ | ||
/** | ||
* Replaces the coordinates with the provided text, adjusting the coords to previous | ||
* changes. | ||
*/ | ||
replacer: (start: number, end: number, text: string) => void; | ||
/** a list of changes made in the original file to adjust any future coordinates of texts */ | ||
/** A list of changes made in the original file to adjust any future coordinates of texts */ | ||
changeset: Array<{ start: number; diff: number }>; | ||
/** updates the original file of sourcePath with the content's contents */ | ||
/** Updates the original file of sourcePath with the content's contents */ | ||
update: () => Promise<void>; | ||
@@ -17,0 +20,0 @@ }; |
@@ -5,5 +5,3 @@ import type ts from 'typescript'; | ||
/** | ||
* Handles and replaces the signature of a typed field. | ||
*/ | ||
/** Handles and replaces the signature of a typed field. */ | ||
export function replaceSignature( | ||
@@ -45,2 +43,89 @@ signatureType: ts.TypeNode, | ||
// | ||
// String | ||
// | ||
case 'string': | ||
replacer(signatureType.pos, signatureType.end, name); | ||
break; | ||
case 'string[]': | ||
replacer(signatureType.pos, signatureType.end, `(${name})[]`); | ||
break; | ||
case 'string | null': | ||
replacer(signatureType.pos, signatureType.end, name); | ||
break; | ||
case `StringFilter | string`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringFilter<${name}> | ${name}` | ||
); | ||
break; | ||
case `StringNullableFilter | string | null`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringNullableFilter<${name}> | ${name} | null` | ||
); | ||
break; | ||
case `StringNullableListFilter`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringNullableListFilter<${name}>` | ||
); | ||
break; | ||
case `StringWithAggregatesFilter | string`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringWithAggregatesFilter<${name}> | ${name}` | ||
); | ||
break; | ||
case `StringNullableWithAggregatesFilter | string | null`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringNullableWithAggregatesFilter<${name}> | ${name}` | ||
); | ||
break; | ||
case `StringFieldUpdateOperationsInput | string`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedStringFieldUpdateOperationsInput<${name}> | ${name}` | ||
); | ||
break; | ||
case `NullableStringFieldUpdateOperationsInput | string | null`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`TypedNullableStringFieldUpdateOperationsInput<${name}> | ${name} | null` | ||
); | ||
break; | ||
case `${modelName}Create${fieldName}Input | Enumerable<string>`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`CreateStringArrayInput<${name}> | Enumerable<${name}>` | ||
); | ||
break; | ||
case `${modelName}Update${fieldName}Input | Enumerable<string>`: | ||
replacer( | ||
signatureType.pos, | ||
signatureType.end, | ||
`CreateStringArrayInput<${name}> | Enumerable<${name}>` | ||
); | ||
break; | ||
// | ||
// Nullable | ||
@@ -47,0 +132,0 @@ // |
@@ -49,3 +49,122 @@ export function createNamespace(nsName: string) { | ||
/** | ||
* A typed version of NestedStringFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringFilter<S extends string> = Prisma.StringFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringFilter<S> | S | ||
} | ||
/** | ||
* A typed version of StringFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringFilter<S extends string> = Prisma.StringFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringFilter<S> | S | ||
} | ||
/** | ||
* A typed version of NestedStringNullableFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringNullableFilter<S extends string> = Prisma.StringNullableFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of StringNullableFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableFilter<S extends string> = Prisma.StringNullableFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of NestedStringWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringWithAggregatesFilter<S extends string> = Prisma.NestedStringWithAggregatesFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not: TypedNestedStringWithAggregatesFilter<S> | S | ||
} | ||
/** | ||
* A typed version of StringWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringWithAggregatesFilter<S extends string> = Prisma.StringWithAggregatesFilter & { | ||
equals?: S; | ||
in?: Prisma.Enumerable<S>; | ||
notIn?: Prisma.Enumerable<S>; | ||
not?: TypedNestedStringWithAggregatesFilter<S> | S | ||
} | ||
/** | ||
* A typed version of NestedStringNullableWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNestedStringNullableWithAggregatesFilter<S extends string> = Prisma.NestedStringNullableWithAggregatesFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not: TypedNestedStringNullableWithAggregatesFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of tringNullableWithAggregatesFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableWithAggregatesFilter<S extends string> = Prisma.StringNullableWithAggregatesFilter & { | ||
equals?: S | null; | ||
in?: Prisma.Enumerable<S> | null; | ||
notIn?: Prisma.Enumerable<S> | null; | ||
not?: TypedNestedStringNullableWithAggregatesFilter<S> | S | null | ||
} | ||
/** | ||
* A typed version of StringFieldUpdateOperationsInput, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringFieldUpdateOperationsInput<S extends string> = Prisma.StringFieldUpdateOperationsInput & { | ||
set?: S | ||
} | ||
/** | ||
* A typed version of NullableStringFieldUpdateOperationsInput, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedNullableStringFieldUpdateOperationsInput<S extends string> = Prisma.NullableStringFieldUpdateOperationsInput & { | ||
set?: S | null | ||
} | ||
/** | ||
* A typed version of StringNullableListFilter, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type TypedStringNullableListFilter<S extends string> = Prisma.StringNullableListFilter & { | ||
equals?: Enumerable<S> | null | ||
has?: S | null | ||
hasEvery?: Enumerable<S> | ||
hasSome?: Enumerable<S> | ||
} | ||
/** | ||
* A typed version of the input type to update a string[] field, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type UpdateStringArrayInput<S extends string> = { | ||
set?: Enumerable<S> | ||
push?: S | Enumerable<S> | ||
} | ||
/** | ||
* A typed version of the input type to create a string[] field, allowing narrowing of string types to discriminated unions. | ||
*/ | ||
export type CreateStringArrayInput<S extends string> = { | ||
set?: Enumerable<S> | ||
} | ||
`.trim(); | ||
} |
export const JSON_REGEX = /^\s*\[(.*?)\]/m; | ||
/** | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific model | ||
* A list of regexes to match all types and subtypes generated by prisma for a specific | ||
* model | ||
*/ | ||
@@ -34,7 +35,5 @@ export function regexForPrismaType(name: string) { | ||
/** | ||
* If the provided type is a update one variant | ||
*/ | ||
/** If the provided type is a update one variant */ | ||
export function isUpdateOne(type: string) { | ||
return type.match(/UpdateInput$/m) || type.match(/UpdateWithout(?:\\w+?)Input$/m); | ||
} |
import type ts from 'typescript'; | ||
import type { Declaration } from '../file/reader'; | ||
import type { ModelWithRegex } from './dmmf'; | ||
import { replaceSignature } from './handle-signature'; | ||
import { JSON_REGEX } from './regex'; | ||
import type { Declaration } from '../file/reader'; | ||
@@ -7,0 +7,0 @@ export function replaceObject( |
@@ -10,2 +10,9 @@ import { Prisma, PrismaClient, User } from '@prisma/client'; | ||
type List = { a: number }; | ||
type StringType = 'a' | 'b'; | ||
enum EnumType { | ||
Case1 = 'Case1', | ||
Case2 = 'Case2' | ||
} | ||
} | ||
@@ -86,3 +93,6 @@ } | ||
} | ||
] | ||
], | ||
//@ts-expect-error - should be a or b | ||
stringArrayField: ['c'] | ||
} | ||
@@ -243,3 +253,6 @@ }); | ||
} | ||
] | ||
], | ||
//@ts-expect-error - should be a or b | ||
stringArrayField: ['c'] | ||
} | ||
@@ -388,1 +401,196 @@ }); | ||
}); | ||
user({ | ||
simple: { | ||
//@ts-expect-error - should be a | ||
b: 1 | ||
}, | ||
optional: { | ||
//@ts-expect-error - should be a | ||
b: 'not a number' | ||
}, | ||
list: [ | ||
{ | ||
//@ts-expect-error - should be a | ||
b: true | ||
} | ||
], | ||
//@ts-expect-error - should only be a | b | ||
stringField: 'c' | ||
}); | ||
// | ||
// Strings | ||
// | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: 'c' } }); | ||
client.findMany({ | ||
//@ts-expect-error - should not be able to construct since {one: "a"} is not a string | ||
where: { incorrectlyTypedStringField: { equals: { one: 'a' } } } | ||
}); | ||
//@ts-expect-error - should not be able to construct since {one: "a"} is not a string | ||
client.findMany({ where: { incorrectlyTypedStringField: { one: 'a' } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { equals: 'c' } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { in: ['c'] } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { notIn: ['c'] } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { not: { equals: 'c' } } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { not: { in: ['c'] } } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringField: { not: { notIn: ['c'] } } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.aggregate({ _count: { list: true }, where: { stringField: 'c' } }); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: 'c' } | ||
}); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: { equals: 'c' } } | ||
}); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: { not: 'c' } } | ||
}); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: { not: { equals: 'c' } } } | ||
}); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: { in: ['a', 'b', 'c'] } } | ||
}); | ||
client.groupBy({ | ||
by: ['stringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { stringField: { notIn: ['a', 'b', 'c'] } } | ||
}); | ||
//@ts-expect-error - should only be a | b | ||
client.update({ where: { id: 1 }, data: { stringField: 'c' } }); | ||
//@ts-expect-error - should only be a | b | ||
client.update({ where: { id: 1 }, data: { stringField: { set: 'c' } } }); | ||
// | ||
// Nullable Strings | ||
// | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: 'c' } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { equals: 'c' } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { in: ['c'] } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { notIn: ['c'] } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { not: { equals: 'c' } } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { not: { in: ['c'] } } } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { optionalStringField: { not: { notIn: ['c'] } } } }); | ||
client.aggregate({ | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
where: { optionalStringField: 'c' } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: 'c' } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: { equals: 'c' } } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: { not: 'c' } } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: { not: { equals: 'c' } } } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: { in: ['a', 'b', 'c'] } } | ||
}); | ||
client.groupBy({ | ||
by: ['optionalStringField'], | ||
_count: { list: true }, | ||
//@ts-expect-error - should only be a | b | ||
having: { optionalStringField: { notIn: ['a', 'b', 'c'] } } | ||
}); | ||
//@ts-expect-error - should only be a | b | ||
client.update({ where: { id: 1 }, data: { optionalStringField: 'c' } }); | ||
client.update({ | ||
where: { id: 1 }, | ||
//@ts-expect-error - should only be a | b | ||
data: { optionalStringField: { set: 'c' } } | ||
}); | ||
//@ts-expect-error - should only be able to pass enum values | ||
client.findMany({ where: { enumField: 'incorrectCase' } }); | ||
client.findMany({ where: { enumField: PrismaJson.EnumType.Case1 } }); | ||
//@ts-expect-error - should only be able to pass enum values | ||
client.findMany({ where: { optionalEnumField: 'incorrectCase' } }); | ||
client.findMany({ where: { optionalEnumField: PrismaJson.EnumType.Case1 } }); | ||
// | ||
// String Arrays | ||
// | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringArrayField: ['c', 'd'] } }); | ||
//@ts-expect-error - should only be a | b | ||
client.findMany({ where: { stringArrayField: { has: 'c' } } }); |
@@ -106,2 +106,2 @@ /* prettier-ignore */ | ||
"include": ["src"] | ||
} | ||
} |
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["test"] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123632
19.3%82
1.23%1938
34.3%