UNPKG

@openactive/models-ts

Version:

JavaScript/TypeScript implementation of OpenActive's data model

42 lines (41 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateMediaManipulationRatingEnumeration = exports.MediaManipulationRatingEnumerationJoiSchema = void 0; // This file was generated const Joi = require("joi"); const oaValidationError_1 = require("../oaValidationError"); /** * schema:MediaManipulationRatingEnumeration - Validation schema (w/ JOI) * * Codes for use with the [[mediaAuthenticityCategory]] property, indicating the authenticity of a media object (in the context of how it was published or shared). In general these codes are not mutually exclusive, although some combinations (such as 'original' versus 'transformed', 'edited' and 'staged') would be contradictory if applied in the same [[MediaReview]]. Note that the application of these codes is with regard to a piece of media shared or published in a particular context. */ exports.MediaManipulationRatingEnumerationJoiSchema = Joi.string().valid('https://schema.org/OriginalMediaContent', 'https://schema.org/TransformedContent', 'https://schema.org/StagedContent', 'https://schema.org/EditedOrCroppedContent', 'https://schema.org/DecontextualizedContent', 'https://schema.org/SatireOrParodyContent'); /** * Runtime validator for schema:MediaManipulationRatingEnumeration. * * If some data has one of the values of the schema:MediaManipulationRatingEnumeration enum, it will be returned with the correct type. * Otherwise, this function returns an `OAValidationError` with details about why the data does not match. * * Use this to e.g. check a JSON object received in an HTTP request. Example usage (for an express request handler): * * ```ts * const maybeMediaManipulationRatingEnumeration = validateMediaManipulationRatingEnumeration(req.body); // `req.body` will have type `any` or `unknown` * if (maybeMediaManipulationRatingEnumeration instanceof OaValidationError) { * // From this point on, `maybeMediaManipulationRatingEnumeration` will have type `OaValidationError` * const error = maybeMediaManipulationRatingEnumeration; * // Do something with the error. Maybe ignore it? Or log it? Or throw? Up to you. * } * // From this point on, `maybeMediaManipulationRatingEnumeration` will have type `MediaManipulationRatingEnumeration` * const mediaManipulationRatingEnumeration = maybeMediaManipulationRatingEnumeration; * ``` */ function validateMediaManipulationRatingEnumeration(maybeMediaManipulationRatingEnumeration) { const { value, error } = exports.MediaManipulationRatingEnumerationJoiSchema.validate(maybeMediaManipulationRatingEnumeration); if (error) { return new oaValidationError_1.OaValidationError('MediaManipulationRatingEnumeration', maybeMediaManipulationRatingEnumeration, error); } /* Joi does not implement TS Type Guards, so TS does not implicitly know that this has now been validated to have the right type. Therefore, we just cast it to the right type. */ return value; } exports.validateMediaManipulationRatingEnumeration = validateMediaManipulationRatingEnumeration;