@stencila/jesta
Version:
Stencila plugin for executable documents using JavaScript
41 lines (40 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.import_ = exports.schema = void 0;
const read_1 = require("./read");
const { input, cache } = read_1.schema.properties;
exports.schema = {
title: 'import',
description: 'Import a document from a URL.',
required: ['input'],
properties: {
input,
format: {
description: 'Format to import the document from. Defaults to the file extension (or media type, for remote URLs).',
type: 'string',
enum: ['json'],
},
cache,
upcast: {
description: 'Upcast the document after it is imported?',
type: 'boolean',
// Constant `false` because Jesta does not implement the upcast method
const: false,
},
validate: {
description: 'Validate the document after it is imported?',
type: 'boolean',
const: true,
},
},
};
async function import_(input, format, cache = true,
// These default to false because Jesta has neither capability
upcast = false, validate = false) {
const [content, formatRead] = await this.read(input, cache);
const decoded = await this.decode(content, format !== null && format !== void 0 ? format : formatRead);
const validated = validate ? await this.validate(decoded) : decoded;
return upcast ? this.upcast(validated) : validated;
}
exports.import_ = import_;
import_.schema = exports.schema;