Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@types/jest": "^27.4.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "^17.0.17",
"@types/node": "^20.0.0",
"@types/pluralize": "0.0.29",
"babel-jest": "^27.5.1",
"jest": "^29.0.0",
"ts-jest": "^29.0.0",
"ts-node": "^10.5.0",
"ts-toolbelt": "9.6.0",
"typescript": "^5.0.0"
},
"dependencies": {
"@prisma/internals": "^4.12.0",
"@antfu/ni": "0.21.12",
"@opentelemetry/api": "1.9.0",
"@prisma/internals": "^5.0.0",
"chalk": "^4.0.0",
"change-case": "4.1.2",
"commander": "7.2.0",
"dotenv": "16.0.3",
"fp-ts": "2.16.9",
"fs-jetpack": "5.1.0",
"http-proxy-agent": "7.0.2",
"https-proxy-agent": "7.0.5",
"js-yaml": "4.1.0",
"pluralize": "8.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { readFileSync, writeFileSync } from 'fs';
import { Command, OptionValues } from 'commander';
import chalk from 'chalk';
import { formatSchema } from '@prisma/internals';
import { formatSchema } from './schema';
import { ConventionTransformer } from './convention-transformer';
import { ConventionStore, DEFAULT_PRISMA_CASE_FORMAT_FILE_LOCATION, SUPPORTED_CASE_CONVENTIONS_MESSAGE, tryGetTableCaseConvention } from './convention-store';
import { resolve } from 'path';
Expand Down Expand Up @@ -132,13 +132,13 @@ async function run() {
process.exit(1);
}

const new_schema = await formatSchema({ schema: schema! });
const new_schema = await formatSchema(schema!);

if (options.dryRun) {
console.log(new_schema);
process.exit(0);
}
writeFileSync(options.file, Buffer.from(new_schema), { encoding: 'utf8' });
writeFileSync(options.file, new_schema, { encoding: 'utf8' });
console.log(chalk.blue('✨ Done.'));
}

Expand Down
6 changes: 6 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { formatSchema as formatSchemaInternal } from '@prisma/internals';

export const formatSchema = async (contents: string) => {
const formated = await formatSchemaInternal({ schemas: [["dummy.prisma", contents]] });
return formated[0][1];
}
3 changes: 2 additions & 1 deletion test/__snapshots__/convention-transformer.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ exports[`disable2 1`] = `
id String @id @default(cuid())
passwordsSingular String[] @map("passwords_singular")
requestsSingulars String[] @map("requests_singular")
columnsSingular String[]
columnsSingular String[] @map("columns_singular")
pluralsPlurals String[] @map("pluralsPlural")
plurals String[] @map("plural")
}
"
`;
Expand Down
30 changes: 15 additions & 15 deletions test/convention-transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'path';

import { camelCase, pascalCase, snakeCase } from 'change-case';
import { CaseChange, ConventionTransformer } from '../src/convention-transformer';
import { formatSchema } from '@prisma/internals';
import { formatSchema } from '../src/schema';

import { asPluralized, asSingularized } from '../src/caseConventions';
import { ConventionStore, defaultConventions } from '../src/convention-store';
Expand Down Expand Up @@ -69,7 +69,7 @@ test('it can map enum column to enum definition', async () => {
const file_contents = getFixture('enum');
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
expect(err).toBeFalsy();
const new_schema = await formatSchema({ schema: schema! });
const new_schema = await formatSchema(schema!);
expect(new_schema).toMatchSnapshot();
});

Expand Down Expand Up @@ -128,19 +128,19 @@ test.each(supported_case_conventions)('it can enforce a specified case conventio

let file_contents = getFixture('idempotency');
let [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
let new_schema = await formatSchema({ schema: schema! });
let new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);

file_contents = getFixture('cascading-deletion-and-fk');
[schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
new_schema = await formatSchema({ schema: schema! });
new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);

file_contents = getFixture('pluralize-fields');
[schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
new_schema = await formatSchema({ schema: schema! });
new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);
});
Expand All @@ -163,19 +163,19 @@ test.each(supported_case_conventions)('it can enforce a specified case conventio

let file_contents = getFixture('idempotency');
let [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
let new_schema = await formatSchema({ schema: schema! });
let new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);

file_contents = getFixture('cascading-deletion-and-fk');
[schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
new_schema = await formatSchema({ schema: schema! });
new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);

file_contents = getFixture('pluralize-fields');
[schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
new_schema = await formatSchema({ schema: schema! });
new_schema = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(new_schema).toMatchSnapshot(caseConvention.name);
});
Expand All @@ -190,7 +190,7 @@ test('it can enforce a specified case convention on views', async () => {
const file_contents = getFixture('views');
let [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
expect(err).toBeFalsy();
let new_schema = await formatSchema({ schema: schema! });
let new_schema = await formatSchema(schema!);
expect(new_schema).toMatchSnapshot();
});

Expand Down Expand Up @@ -269,7 +269,7 @@ test('it can rename enum in the database', async () => {
});
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store);
expect(err).toBeFalsy();
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(result).toMatchSnapshot();
});

Expand Down Expand Up @@ -439,7 +439,7 @@ test('if the entity is marked disabled, or is marked with !, formatting is appli
expect(store_err).toBeFalsy();
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store!);
expect(err).toBeFalsy();
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(result).toMatchSnapshot();
});

Expand All @@ -448,7 +448,7 @@ test('if next-auth is marked as in use, those models should be managed separatel
const [store, store_err] = ConventionStore.fromConf({ uses_next_auth: true });
expect(store_err).toBeFalsy();
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store!);
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(err).toBeFalsy();
expect(result).toMatchSnapshot();
});
Expand All @@ -461,7 +461,7 @@ test('issue', async () => {
expect(store_err).toBeFalsy();
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store!);
expect(err).toBeFalsy();
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(result).toMatchSnapshot();
});

Expand All @@ -473,7 +473,7 @@ test('issue2', async () => {
expect(store_err).toBeFalsy();
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store!);
expect(err).toBeFalsy();
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(result).toMatchSnapshot();
});

Expand All @@ -484,6 +484,6 @@ test('disable2', async () => {
expect(store_err).toBeFalsy();
const [schema, err] = ConventionTransformer.migrateCaseConventions(file_contents, store!);
expect(err).toBeFalsy();
const result = await formatSchema({ schema: schema! });
const result = await formatSchema(schema!);
expect(result).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"esnext"
Expand Down
Loading