UNPKG

kodi-api

Version:

A complete implementation of Kodi JSON-RPC calls in an easy-to-use Javascript/TypeScript client.

56 lines (55 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KodiIntrospect = void 0; const jsonschema_1 = require("jsonschema"); /** Wrapper class for Kodi's `JSONRPC.Introspect` metadata response. */ class KodiIntrospect { constructor(introspect) { this.id = introspect.id; this.jsonrpc = introspect.jsonrpc; this.result = introspect.result; this.validator = new jsonschema_1.Validator(); for (const refSchema of Object.values(this.result.types)) { this.validator.addSchema(refSchema); } } /** Method to return a method descripton. */ describeMethod(method) { return this.result.methods[method]; } /** Method to return a notification description. */ describeNotification(notification) { return this.result.notifications[notification]; } /** Method to return a type description. */ describeType(typeName) { return this.result.types[typeName]; } /** Method to validate an input by it's accompanying schema. */ validateSchema(input, schema, throwError) { const result = this.validator.validate(input, schema); if (throwError && !result.valid) { throw result.errors[0]; } return result.valid; } listMethods(group = false) { const methodNames = Object.keys(this.result.methods); if (group) { const methodNameGroups = {}; for (const methodName of methodNames) { const [nameSpace, method] = methodName.split('.'); if (!Array.isArray(methodNameGroups[nameSpace])) methodNameGroups[nameSpace] = []; methodNameGroups[nameSpace].push(method); } return methodNameGroups; } return methodNames; } /** Get the version of the Kodi API. */ version() { return this.result.version; } } exports.KodiIntrospect = KodiIntrospect;