UNPKG

1.63 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.validateModels = exports.updateLegacySessionModel = exports.validateModel = void 0;
6const validate_1 = require("../kernel/validate");
7const validate_2 = require("../validate");
8/**
9 * Validate an `Session.IModel` object.
10 */
11// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
12function validateModel(data) {
13 (0, validate_2.validateProperty)(data, 'id', 'string');
14 (0, validate_2.validateProperty)(data, 'type', 'string');
15 (0, validate_2.validateProperty)(data, 'name', 'string');
16 (0, validate_2.validateProperty)(data, 'path', 'string');
17 (0, validate_2.validateProperty)(data, 'kernel', 'object');
18 (0, validate_1.validateModel)(data.kernel);
19}
20exports.validateModel = validateModel;
21/**
22 * Update model from legacy session data.
23 */
24// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
25function updateLegacySessionModel(data) {
26 if (data.path === undefined && data.notebook !== undefined) {
27 data.path = data.notebook.path;
28 data.type = 'notebook';
29 data.name = '';
30 }
31}
32exports.updateLegacySessionModel = updateLegacySessionModel;
33/**
34 * Validate an array of `Session.IModel` objects.
35 */
36function validateModels(models) {
37 if (!Array.isArray(models)) {
38 throw new Error('Invalid session list');
39 }
40 models.forEach(d => validateModel(d));
41}
42exports.validateModels = validateModels;
43//# sourceMappingURL=validate.js.map
\No newline at end of file