entitySchemas.ts 600 B

123456789101112131415
  1. import fs from 'fs'
  2. import { getInputsLocation } from './inputs'
  3. const schemaInputFilenames = fs.readdirSync(getInputsLocation('schemas'))
  4. type EntitySchemaType = 'Ref' | 'Entity' | 'Batch'
  5. export const schemaFilenameToEntitySchemaName = (inputFilename: string, schemaType?: EntitySchemaType) =>
  6. inputFilename.split('_')[1].replace('Schema.json', schemaType || '')
  7. export const classIdToEntitySchemaName = (classId: number, schemaType: EntitySchemaType) =>
  8. schemaFilenameToEntitySchemaName(
  9. schemaInputFilenames.find((fileName) => fileName.startsWith(`${classId}_`))!,
  10. schemaType
  11. )