UNPKG

@openactive/models-ts

Version:

JavaScript/TypeScript implementation of OpenActive's data model

146 lines (145 loc) 10.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAuthenticatedPerson = exports.AuthenticatedPersonOrSubClassJoiSchema = exports.AuthenticatedPersonJoiSchema = void 0; // This file was generated const Joi = require("joi"); const oaValidationError_1 = require("../oaValidationError"); const oa = require("../oa"); const schema = require("../schema"); /** * beta:AuthenticatedPerson - Validation schema (w/ JOI) * * [NOTICE: This is a beta class, and is highly likely to change in future versions of this library.] * * This type is derived from https://schema.org/Person, which means that any of this type's properties within schema.org may also be used. */ exports.AuthenticatedPersonJoiSchema = Joi.object({ '@type': Joi.string().valid('AuthenticatedPerson').required(), '@context': Joi.alternatives().try([Joi.string(), Joi.array().items(Joi.string())]), identifier: Joi.alternatives().try(Joi.number().integer(), Joi.string(), Joi.lazy(() => oa.PropertyValueOrSubClassJoiSchema), Joi.array().items(Joi.lazy(() => oa.PropertyValueOrSubClassJoiSchema))), name: Joi.string(), description: Joi.string(), '@id': Joi.string().uri(), address: Joi.lazy(() => oa.PostalAddressOrSubClassJoiSchema), email: Joi.string(), familyName: Joi.string(), gender: Joi.lazy(() => schema.GenderTypeJoiSchema), givenName: Joi.string(), isOpenBookingAllowed: Joi.boolean(), jobTitle: Joi.string(), legalName: Joi.string(), logo: Joi.lazy(() => oa.ImageObjectOrSubClassJoiSchema), sameAs: Joi.array().items(Joi.string().uri()), taxMode: Joi.lazy(() => oa.TaxModeJoiSchema), telephone: Joi.string(), termsOfService: Joi.array().items(Joi.lazy(() => oa.TermsOrSubClassJoiSchema)), url: Joi.string().uri(), vatID: Joi.string(), 'beta:accessToken': Joi.string(), 'beta:formattedDescription': Joi.string(), 'beta:formalCriteriaMet': Joi.array().items(Joi.string().uri()), follows: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), workLocation: Joi.alternatives().try(Joi.lazy(() => schema.ContactPointOrSubClassJoiSchema), Joi.lazy(() => schema.PlaceOrSubClassJoiSchema), Joi.string().uri()), affiliation: Joi.alternatives().try(Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), height: Joi.alternatives().try(Joi.lazy(() => schema.QuantitativeValueOrSubClassJoiSchema), Joi.lazy(() => schema.DistanceOrSubClassJoiSchema), Joi.string().uri()), worksFor: Joi.alternatives().try(Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), honorificPrefix: Joi.string(), globalLocationNumber: Joi.string(), knowsAbout: Joi.alternatives().try(Joi.string(), Joi.string().uri(), Joi.lazy(() => schema.ThingOrSubClassJoiSchema)), contactPoint: Joi.alternatives().try(Joi.lazy(() => schema.ContactPointOrSubClassJoiSchema), Joi.string().uri()), knowsLanguage: Joi.alternatives().try(Joi.string(), Joi.lazy(() => schema.LanguageOrSubClassJoiSchema), Joi.string().uri()), hasOccupation: Joi.alternatives().try(Joi.lazy(() => schema.OccupationOrSubClassJoiSchema), Joi.string().uri()), performerIn: Joi.alternatives().try(Joi.lazy(() => schema.Event_OrSubClassJoiSchema), Joi.string().uri()), weight: Joi.alternatives().try(Joi.lazy(() => schema.QuantitativeValueOrSubClassJoiSchema), Joi.string().uri()), homeLocation: Joi.alternatives().try(Joi.lazy(() => schema.PlaceOrSubClassJoiSchema), Joi.lazy(() => schema.ContactPointOrSubClassJoiSchema), Joi.string().uri()), spouse: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), siblings: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), duns: Joi.string(), colleague: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), contactPoints: Joi.alternatives().try(Joi.lazy(() => schema.ContactPointOrSubClassJoiSchema), Joi.string().uri()), makesOffer: Joi.alternatives().try(Joi.lazy(() => schema.OfferOrSubClassJoiSchema), Joi.string().uri()), isicV4: Joi.string(), award: Joi.string(), netWorth: Joi.alternatives().try(Joi.lazy(() => schema.PriceSpecificationOrSubClassJoiSchema), Joi.lazy(() => schema.MonetaryAmountOrSubClassJoiSchema), Joi.string().uri()), seeks: Joi.alternatives().try(Joi.lazy(() => schema.DemandOrSubClassJoiSchema), Joi.string().uri()), hasOfferCatalog: Joi.alternatives().try(Joi.lazy(() => schema.OfferCatalogOrSubClassJoiSchema), Joi.string().uri()), birthDate: Joi.string().isoDate(), children: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), sponsor: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), birthPlace: Joi.alternatives().try(Joi.lazy(() => schema.PlaceOrSubClassJoiSchema), Joi.string().uri()), honorificSuffix: Joi.string(), colleagues: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), alumniOf: Joi.alternatives().try(Joi.lazy(() => schema.EducationalOrganizationOrSubClassJoiSchema), Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), owns: Joi.alternatives().try(Joi.lazy(() => schema.OwnershipInfoOrSubClassJoiSchema), Joi.lazy(() => schema.ProductOrSubClassJoiSchema), Joi.string().uri()), interactionStatistic: Joi.alternatives().try(Joi.lazy(() => schema.InteractionCounterOrSubClassJoiSchema), Joi.string().uri()), deathDate: Joi.string().isoDate(), additionalName: Joi.string(), faxNumber: Joi.string(), knows: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), memberOf: Joi.alternatives().try(Joi.lazy(() => schema.ProgramMembershipOrSubClassJoiSchema), Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), sibling: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), deathPlace: Joi.alternatives().try(Joi.lazy(() => schema.PlaceOrSubClassJoiSchema), Joi.string().uri()), hasCredential: Joi.alternatives().try(Joi.lazy(() => schema.EducationalOccupationalCredentialOrSubClassJoiSchema), Joi.string().uri()), parents: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), relatedTo: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), brand: Joi.alternatives().try(Joi.lazy(() => schema.BrandOrSubClassJoiSchema), Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.string().uri()), taxID: Joi.string(), nationality: Joi.alternatives().try(Joi.lazy(() => schema.CountryOrSubClassJoiSchema), Joi.string().uri()), naics: Joi.string(), funder: Joi.alternatives().try(Joi.lazy(() => schema.OrganizationOrSubClassJoiSchema), Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), publishingPrinciples: Joi.alternatives().try(Joi.string().uri(), Joi.lazy(() => schema.CreativeWorkOrSubClassJoiSchema)), awards: Joi.string(), callSign: Joi.string(), parent: Joi.alternatives().try(Joi.lazy(() => schema.PersonOrSubClassJoiSchema), Joi.string().uri()), hasPOS: Joi.alternatives().try(Joi.lazy(() => schema.PlaceOrSubClassJoiSchema), Joi.string().uri()), subjectOf: Joi.alternatives().try(Joi.lazy(() => schema.Event_OrSubClassJoiSchema), Joi.lazy(() => schema.CreativeWorkOrSubClassJoiSchema), Joi.string().uri()), potentialAction: Joi.alternatives().try(Joi.lazy(() => schema.ActionOrSubClassJoiSchema), Joi.string().uri()), mainEntityOfPage: Joi.alternatives().try(Joi.lazy(() => schema.CreativeWorkOrSubClassJoiSchema), Joi.string().uri()), additionalType: Joi.string().uri(), alternateName: Joi.string(), image: Joi.alternatives().try(Joi.lazy(() => schema.ImageObjectOrSubClassJoiSchema), Joi.string().uri()), disambiguatingDescription: Joi.string(), }); /** * beta:AuthenticatedPerson - Validation schema (w/ JOI) * * [NOTICE: This is a beta class, and is highly likely to change in future versions of this library.] * * This type is derived from https://schema.org/Person, which means that any of this type's properties within schema.org may also be used. * * This differs from AuthenticatedPersonJoiSchema because it also allows for objects that have the type of a model that * sub-classes this model. e.g. `Event.OrSubClassJoiSchema` allows `Event`s as well as `ScheduledSession`s, * `SessionSeries`, etc. */ exports.AuthenticatedPersonOrSubClassJoiSchema = Joi.alternatives().try([ exports.AuthenticatedPersonJoiSchema, ]); /** * Runtime validator for beta:AuthenticatedPerson. * * If some data has a structure which matches a beta:AuthenticatedPerson, 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 maybeAuthenticatedPerson = validateAuthenticatedPerson(req.body); // `req.body` will have type `any` or `unknown` * if (maybeAuthenticatedPerson instanceof OaValidationError) { * // From this point on, `maybeAuthenticatedPerson` will have type `OaValidationError` * const error = maybeAuthenticatedPerson; * // Do something with the error. Maybe ignore it? Or log it? Or throw? Up to you. * } * // From this point on, `maybeAuthenticatedPerson` will have type `AuthenticatedPerson` * const authenticatedPerson = maybeAuthenticatedPerson; * ``` */ function validateAuthenticatedPerson(maybeAuthenticatedPerson) { const { value, error } = exports.AuthenticatedPersonJoiSchema.validate(maybeAuthenticatedPerson); if (error) { return new oaValidationError_1.OaValidationError('AuthenticatedPerson', maybeAuthenticatedPerson, 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.validateAuthenticatedPerson = validateAuthenticatedPerson;