You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const node = require("../../ast-node");
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
const either = require("@validatem/either");
|
|
const required = require("@validatem/required");
|
|
const arrayOf = require("@validatem/array-of");
|
|
|
|
const isCollectionName = require("../../validators/is-collection-name");
|
|
|
|
module.exports = function (operations) {
|
|
const isObjectType = require("../../validators/operations/is-object-type")(operations);
|
|
const isFieldsObject = require("../../validators/operations/schema/is-fields-object")(operations);
|
|
|
|
return function createCollection(_name, _operations) {
|
|
let [ name, collectionOperations ] = validateArguments(arguments, {
|
|
name: [ required, isCollectionName ],
|
|
operations: [ required, either([
|
|
[ isFieldsObject, (fieldsObject) => {
|
|
return [ operations.fields(fieldsObject) ];
|
|
}],
|
|
arrayOf(either([
|
|
isObjectType("schemaFields"),
|
|
isObjectType("schemaIndexes")
|
|
])) // FIXME: At least one of schemaFields
|
|
]) ]
|
|
});
|
|
|
|
return node({
|
|
type: "createCollectionCommand",
|
|
name: name,
|
|
operations: collectionOperations
|
|
});
|
|
};
|
|
};
|