validate-projection-schema-definition.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {InvalidArgumentError} from '@e22m4u/js-format';
  2. import {validateProjectionSchema} from './validate-projection-schema.js';
  3. /**
  4. * Validate projection schema definition.
  5. *
  6. * @param {object} schemaDef
  7. */
  8. export function validateProjectionSchemaDefinition(schemaDef) {
  9. if (!schemaDef || typeof schemaDef !== 'object' || Array.isArray(schemaDef)) {
  10. throw new InvalidArgumentError(
  11. 'Schema definition must be an Object, but %v was given.',
  12. schemaDef,
  13. );
  14. }
  15. if (!schemaDef.name || typeof schemaDef.name !== 'string') {
  16. throw new InvalidArgumentError(
  17. 'Definition option "name" must be a non-empty String, but %v was given.',
  18. schemaDef.name,
  19. );
  20. }
  21. if (
  22. !schemaDef.schema ||
  23. (typeof schemaDef.schema !== 'object' &&
  24. typeof schemaDef.schema !== 'function' &&
  25. typeof schemaDef.schema !== 'string') ||
  26. Array.isArray(schemaDef.schema)
  27. ) {
  28. throw new InvalidArgumentError(
  29. 'Definition option "schema" must be an Object, a Function ' +
  30. 'or a non-empty String, but %v was given.',
  31. schemaDef.schema,
  32. );
  33. }
  34. validateProjectionSchema(schemaDef.schema);
  35. }