import { dynamoTable } from "./dynamo";
import * as fs from 'fs';
function fakeDefinition(definition, name) {
    return new Promise(resolve => {
        dynamoTable({ dynamodbTable: resolve }, definition, name, {});
    });
}
function obj(it) {
    if (Array.isArray(it)) {
        return it.map(obj);
    }
    if (typeof it === 'object') {
        return Object.keys(it ?? {}).reduce((acc, key) => ({ ...acc, [key.slice(0, 1).toUpperCase() + key.slice(1)]: obj(it?.[key]) }), { ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 } });
    }
    return it;
}
export async function tableDefinition(defintions) {
    const tables = await Promise.all(Object.keys(defintions).map(async (table) => await fakeDefinition(defintions[table], table)));
    return { tables: tables.map(obj) };
}
export async function writeFile(defintions, name = 'jest-dynamodb-config.js') {
    const definition = await tableDefinition(defintions);
    fs.writeFileSync(name, `module.exports = ${JSON.stringify(definition, null, 2)};`);
}
