forked from IBM/prisma-schema-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoke.ts
36 lines (29 loc) · 1.29 KB
/
invoke.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* For debugging
*/
import * as fs from 'fs';
import {getDMMF, formatSchema} from '@prisma/sdk';
import {dmmfModelsdeserializer, Model, dmmfModelTransformer} from './src';
const schemaName = 'private';
const outputSchemaName = `${schemaName}.actual`;
const schemaPath = `./fixtures/${schemaName}.prisma`;
const outputSchemaPath = `./fixtures/${outputSchemaName}.prisma`;
(async function () {
// Format input schema file
const formatedSchemaString = await formatSchema({schemaPath});
fs.writeFileSync(schemaPath, formatedSchemaString);
const schema = fs.readFileSync(schemaPath, 'utf-8');
const dmmf = await getDMMF({datamodel: schema});
fs.writeFileSync(`./${schemaName}-dmmf.json`, JSON.stringify(dmmf, null, 2));
// Transform to camelcase
const models = dmmf.datamodel.models as Model[];
const transformedModels = dmmfModelTransformer(models);
// Deserialize models
const outputSchema = await dmmfModelsdeserializer(transformedModels);
fs.writeFileSync(outputSchemaPath, outputSchema);
const formatedOutputSchema = await formatSchema({schemaPath: outputSchemaPath});
fs.writeFileSync(outputSchemaPath, formatedOutputSchema);
// Validate
const outputDmmf = await getDMMF({datamodel: outputSchema});
fs.writeFileSync(`./${schemaName}-dmmf.actual.json`, JSON.stringify(outputDmmf, null, 2));
})();