"use strict";

const syncpipe = require("syncpipe");

const astToQuery = require("../ast-to-query");

const optimizeAST = require("../ast/optimize");
const optimizers = require("../optimizers/schema");

module.exports = function processSchemaUpdate(update) {
	return {
		... update,
		operations: update.operations.map((operation) => {
			// FIXME: This is too simplified. A single operation may result in multiple queries.
			return syncpipe(operation, [
				(_) => optimizeAST(_, optimizers),
				// (_) => astToQuery(_.ast)
				(_) => _.ast
			]);
		})
	};
};

