All files / src/transform transform.ts

100% Statements 13/13
100% Branches 6/6
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  1x 1x   6x 6x 6x   5x 3x 2x 1x   1x     1x  
import { Output, CrudContract, Contract } from './types.js'
import { transform as crudTransform } from './crud.js'
import { transform as singleTransform } from './single.js'
 
export const transform = async (contract: CrudContract | Contract | object): Promise<Output> => {
  const data: any = contract
  if (!data.$schema) { return { type: 'error', errors: "Schema files must contain $schema that point to it's type" } }
 
  if (data.$schema.endsWith('singleContractSchema.json')) {
    return singleTransform(data)
  } else if (data.$schema.endsWith('crudContractSchema.json')) {
    return crudTransform(data)
  }
  return { type: 'error', errors: `Unsupported schema for declaration: ${data.$schema}` }
}
 
export default transform