Skip to content

Commit

Permalink
perf: Removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed Nov 27, 2020
1 parent c7127a4 commit da6dbc0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
9 changes: 2 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,11 @@ module.exports = {
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unused-vars': 0,
'import/max-dependencies': 0,
'sonarjs/no-duplicate-string': 0,
},
},
{
files: ['src/testing/type-tests.ts'],
rules: {
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
},
},
],
};
16 changes: 12 additions & 4 deletions src/generate-model/generate-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ describe('generate models', () => {
count Int @id @default(1)
}`,
});
const args = getFieldArguments({ sourceFile, className: 'User', property: 'count' });
const args = getFieldArguments({
sourceFile,
className: 'User',
property: 'count',
});
expect(args?.[1]).toContain('nullable: false');
expect(args?.[1]).toContain('defaultValue: 1');
expect(args?.[1]).not.toContain('description: undefined');
Expand Down Expand Up @@ -151,7 +155,7 @@ describe('generate models', () => {
const args = struct?.decorators?.[0].arguments;
stringContains('nullable: false', args?.[1]);
stringContains('description: "user id"', args?.[1]);
assert.strictEqual(args?.[0], '() => ID');
expect(args?.[0]).toEqual('() => ID');
});

it('remove description', async () => {
Expand Down Expand Up @@ -236,7 +240,7 @@ describe('generate models', () => {
sourceText = sourceFile.getText();
const property = sourceFile.getClass('User')?.getProperty('posts');
assert(property, 'Property posts should exists');
assert.strictEqual(property.getStructure().type, 'Array<Post>');
expect(property.getStructure().type).toEqual('Array<Post>');
});

it('custom language type', async () => {
Expand All @@ -252,7 +256,11 @@ describe('generate models', () => {
`types_Decimal_fieldModule = "decimal.js"`,
],
});
const property = sourceFile.getClasses()[0]?.getProperty('d')?.getStructure();
const property = getStructure({
sourceFile,
className: 'User',
property: 'd',
});
expect(property?.type).toEqual('MyDec');
const imports = getImportDeclarations(sourceFile);
expect(imports).toContainEqual({
Expand Down
6 changes: 0 additions & 6 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ export async function generate(args: GenerateArgs) {
const enums = [
...(prismaClientDmmf.schema.enumTypes.model || []),
...prismaClientDmmf.schema.enumTypes.prisma,
// todo: test
...prismaClientDmmf.datamodel.enums.map((x) => ({
name: x.name,
values: x.values.map((v) => v.name),
documentation: x.documentation,
})),
];
for (const enumerable of enums) {
const sourceFile = await createSourceFile({ type: 'enum', name: enumerable.name });
Expand Down
13 changes: 6 additions & 7 deletions src/testing/type-tests.ts → src/testing/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PrismaClient } from '@prisma/client';
import * as prisma from '@prisma/client';
import { Prisma,PrismaClient } from '@prisma/client';

import { ArticleListRelationFilter } from '../@generated/article/article-list-relation-filter.input';
import { DateTimeFilter } from '../@generated/prisma/date-time-filter.input';
Expand All @@ -10,13 +9,13 @@ import { UserWhereInput } from '../@generated/user/user-where.input';
const $prisma = new PrismaClient();

{
const n: IntFilter = {};
const p = n as prisma.IntFilter;
// let x: IntFilter = {};
// let p: Prisma.IntFilter = {};
// p = x;
}

{
const n: DateTimeFilter = {};
const p = n as prisma.UserWhereInput;
// const n: DateTimeFilter = {};
// const p = n as Prisma.UserWhereInput;
}
{
// const n: ArticleListRelationFilter = {};
Expand Down
2 changes: 1 addition & 1 deletion src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getImportDeclarations(sourceFile: SourceFile) {
}

export function getFieldArguments(args: GetStructuredArguments & { index?: number }) {
let result: any = getStructure(args)?.decorators?.[0]?.arguments;
let result = getStructure(args)?.decorators?.[0]?.arguments;
if (args.index !== undefined) {
result = result?.[args.index];
}
Expand Down
4 changes: 1 addition & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ export function updateObjectProperty(args: UpdateObjectPropertyArgs) {
}) as PropertyAssignment;
}

propertyAssignment.setInitializer(
JSON.stringify(value) || (value !== undefined ? String(value) : 'undefined'),
);
propertyAssignment.setInitializer(JSON.stringify(value));
}

export function fieldLocationToKind(fieldLocation: PrismaDMMF.FieldLocation) {
Expand Down

0 comments on commit da6dbc0

Please sign in to comment.