UNPKG

tmdbrjs

Version:

A TypeScript wrapper for The Movie Database (TMDB) API

137 lines 4.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PopularPeopleSchema = exports.PopularMoviesSchema = exports.CastSchema = exports.PersonSchema = exports.PopularPersonSchema = exports.MovieSchema = exports.PopularMovieSchema = exports.SpokenLanguageSchema = exports.ProductionCountrySchema = exports.ProductionCompanySchema = exports.GenreSchema = void 0; exports.validateResponse = validateResponse; const zod_1 = require("zod"); // Base schemas exports.GenreSchema = zod_1.z.object({ id: zod_1.z.number(), name: zod_1.z.string(), }); exports.ProductionCompanySchema = zod_1.z.object({ id: zod_1.z.number(), logoPath: zod_1.z.string().nullable(), name: zod_1.z.string(), originCountry: zod_1.z.string(), }); exports.ProductionCountrySchema = zod_1.z.object({ iso_3166_1: zod_1.z.string(), name: zod_1.z.string(), }); exports.SpokenLanguageSchema = zod_1.z.object({ englishName: zod_1.z.string(), iso_639_1: zod_1.z.string(), name: zod_1.z.string(), }); // Movie schemas exports.PopularMovieSchema = zod_1.z.object({ adult: zod_1.z.boolean(), backdropPath: zod_1.z.string().nullable(), genreIds: zod_1.z.array(zod_1.z.number()), id: zod_1.z.number(), originalLanguage: zod_1.z.string(), originalTitle: zod_1.z.string(), overview: zod_1.z.string(), popularity: zod_1.z.number(), posterPath: zod_1.z.string().nullable(), releaseDate: zod_1.z.string(), title: zod_1.z.string(), video: zod_1.z.boolean(), voteAverage: zod_1.z.number(), voteCount: zod_1.z.number(), }); exports.MovieSchema = zod_1.z.object({ adult: zod_1.z.boolean(), backdropPath: zod_1.z.string().nullable(), belongsToCollection: zod_1.z.any().nullable(), budget: zod_1.z.number(), genres: zod_1.z.array(exports.GenreSchema), homepage: zod_1.z.string().nullable(), id: zod_1.z.number(), imdbId: zod_1.z.string().nullable(), originalLanguage: zod_1.z.string(), originalTitle: zod_1.z.string(), overview: zod_1.z.string(), popularity: zod_1.z.number(), posterPath: zod_1.z.string().nullable(), productionCompanies: zod_1.z.array(exports.ProductionCompanySchema), productionCountries: zod_1.z.array(exports.ProductionCountrySchema), releaseDate: zod_1.z.string(), revenue: zod_1.z.number(), runtime: zod_1.z.number().nullable(), spokenLanguages: zod_1.z.array(exports.SpokenLanguageSchema), status: zod_1.z.string(), tagline: zod_1.z.string().nullable(), title: zod_1.z.string(), video: zod_1.z.boolean(), voteAverage: zod_1.z.number(), voteCount: zod_1.z.number(), }); // Person schemas exports.PopularPersonSchema = zod_1.z.object({ adult: zod_1.z.boolean(), gender: zod_1.z.number(), id: zod_1.z.number(), knownFor: zod_1.z.array(exports.PopularMovieSchema), knownForDepartment: zod_1.z.string(), name: zod_1.z.string(), popularity: zod_1.z.number(), profilePath: zod_1.z.string().nullable(), }); exports.PersonSchema = zod_1.z.object({ adult: zod_1.z.boolean(), alsoKnownAs: zod_1.z.array(zod_1.z.string()), biography: zod_1.z.string(), birthday: zod_1.z.string().nullable(), deathday: zod_1.z.string().nullable(), gender: zod_1.z.number(), homepage: zod_1.z.string().nullable(), id: zod_1.z.number(), imdbId: zod_1.z.string().nullable(), knownForDepartment: zod_1.z.string(), name: zod_1.z.string(), placeOfBirth: zod_1.z.string().nullable(), popularity: zod_1.z.number(), profilePath: zod_1.z.string().nullable(), }); // Cast schemas exports.CastSchema = zod_1.z.object({ adult: zod_1.z.boolean(), gender: zod_1.z.number().nullable(), id: zod_1.z.number(), knownForDepartment: zod_1.z.string(), name: zod_1.z.string(), originalName: zod_1.z.string(), popularity: zod_1.z.number(), profilePath: zod_1.z.string().nullable(), castId: zod_1.z.number(), character: zod_1.z.string(), creditId: zod_1.z.string(), order: zod_1.z.number(), }); // Response schemas exports.PopularMoviesSchema = zod_1.z.object({ page: zod_1.z.number(), results: zod_1.z.array(exports.PopularMovieSchema), totalPages: zod_1.z.number(), totalResults: zod_1.z.number(), }); exports.PopularPeopleSchema = zod_1.z.object({ page: zod_1.z.number(), results: zod_1.z.array(exports.PopularPersonSchema), totalPages: zod_1.z.number(), totalResults: zod_1.z.number(), }); // Validation function function validateResponse(schema, data) { try { return schema.parse(data); } catch (error) { if (error instanceof zod_1.z.ZodError) { console.error('API Response Validation Error:', error.issues); } throw error; } } //# sourceMappingURL=validation.js.map