UNPKG

@jupyterlab/services

Version:

Client APIs for the Jupyter services REST APIs

66 lines 2.5 kB
"use strict"; // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. Object.defineProperty(exports, "__esModule", { value: true }); exports.KernelSpecAPIClient = void 0; exports.getSpecs = getSpecs; const serverconnection_1 = require("../serverconnection"); const validate_1 = require("./validate"); const coreutils_1 = require("@jupyterlab/coreutils"); /** * The url for the kernelspec service. */ const KERNELSPEC_SERVICE_URL = 'api/kernelspecs'; /** * Fetch all of the kernel specs. * * @param settings - The optional server settings. * @param useCache - Whether to use the cache. If false, always request. * * @returns A promise that resolves with the kernel specs. * * #### Notes * Uses the [Jupyter Server API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#!/kernelspecs). */ async function getSpecs(settings = serverconnection_1.ServerConnection.makeSettings()) { const url = coreutils_1.URLExt.join(settings.baseUrl, KERNELSPEC_SERVICE_URL); const response = await serverconnection_1.ServerConnection.makeRequest(url, {}, settings); if (response.status !== 200) { const err = await serverconnection_1.ServerConnection.ResponseError.create(response); throw err; } const data = await response.json(); return (0, validate_1.validateSpecModels)(data); } /** * The Kernel Spec API client. * * #### Notes * Use this class to interact with the Jupyter Server Kernel Spec API. * This class adheres to the Jupyter Server API endpoints. */ class KernelSpecAPIClient { /** * Create a new Kernel Spec API client. * * @param options - The options used to create the client. */ constructor(options = {}) { var _a; this.serverSettings = (_a = options.serverSettings) !== null && _a !== void 0 ? _a : serverconnection_1.ServerConnection.makeSettings(); } /** * Fetch all of the kernel specs. * * @returns A promise that resolves with the kernel specs. * * #### Notes * Uses the [Jupyter Server API](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter-server/jupyter_server/main/jupyter_server/services/api/api.yaml#!/kernelspecs). */ async get() { return getSpecs(this.serverSettings); } } exports.KernelSpecAPIClient = KernelSpecAPIClient; //# sourceMappingURL=restapi.js.map