From b7ae426bebd511ae04cf9d294b19eb5d3ec25bee Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Fri, 6 Sep 2024 09:36:20 +0300 Subject: [PATCH] _Export is not connected to Top --- TODO.md | 3 +-- src/abstract-export/index.js | 47 ++++++++++++++++++------------------ src/dbsolve-export/index.js | 2 +- test/export/export-check.js | 1 - 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/TODO.md b/TODO.md index 224357dd..7567bb15 100644 --- a/TODO.md +++ b/TODO.md @@ -37,11 +37,11 @@ ## features - atStart to exports: Matlab, DBSolve -- write reusable `Build` class - alternative solution to substitute "pkg": Node.js 21 https://nodejs.org/api/single-executable-applications.html wait until Node.js 22 will be released - use `Component` as a subclass of `Top` - `include` statement is deprecated, use `#include` action (v0.8.0) +- automatic creation of modifiers in SBML ## ideas @@ -53,7 +53,6 @@ - generation of 'platform.yml' by `heta init` - check file format for modules - add "ignoreCompartment" property in Species -- automatic creation of modifiers in SBML - `@Dose` class to use with simbiology/mrgsolve/nonmem doses - stoichiometry as `@Const` and `@Record` - highlight for Vim https://ezpzdev.medium.com/create-a-vim-plugin-for-your-next-programming-language-structure-and-syntax-highlight-1dc0823a6b92 diff --git a/src/abstract-export/index.js b/src/abstract-export/index.js index 8a185c74..dd07fca2 100644 --- a/src/abstract-export/index.js +++ b/src/abstract-export/index.js @@ -1,4 +1,3 @@ -const { Top } = require('../core/top'); const { ajv } = require('../utils'); const schema = { @@ -6,15 +5,6 @@ const schema = { properties: { filepath: {type: 'string', pattern: '^[\\w\\d\\\\/._!-:]+$'}, spaceFilter: { type: 'string' } - }, - definitions: { - ID: { - description: 'First character is letter, others are letter, digit or underscore.', - type: 'string', - minLength: 1, - pattern: '^[_a-zA-Z][_a-zA-Z0-9]*$', - example: 'x_12_' - }, } }; @@ -26,12 +16,11 @@ const schema = { powTransform: keep // possible values are: keep/operator/function }; */ -class AbstractExport extends Top { - constructor(q = {}, isCore = false){ - super(q, isCore); +class AbstractExport { + constructor(q = {}){ // check arguments here - let logger = this._builder.logger; + let { logger } = this._builder; let valid = AbstractExport.isValid(q, logger); if (!valid) { this.errored = true; return; } @@ -58,23 +47,24 @@ class AbstractExport extends Top { return false; } selectedNamespaces() { - let logger = this._builder.logger; + let { container, logger } = this._builder; // filter namespaces if set - let namespaces0 = [...this._builder.container.namespaceStorage] + let filteredNS = [...container.namespaceStorage] .filter(([spaceName, ns]) => new RegExp(this.spaceFilter).test(spaceName)); - - let namespaces1 = this.requireConcrete - ? namespaces0.filter(([spaceName, ns]) => !ns.isAbstract) - : namespaces0; + + // select only concrete namespaces + let concreteNS = this.requireConcrete + ? filteredNS.filter(([spaceName, ns]) => !ns.isAbstract) + : filteredNS; - if (namespaces1.length === 0) { + if (concreteNS.length === 0) { let msg = `Nothing was exported because there is no concrete namespaces matching spaceFilter in "${this.format}".`; logger.warn(msg, {}); } - return namespaces1; + return concreteNS; } - make() { // Buffer + make() { let text = this.makeText(); let buffer = text.map((x) => { return { @@ -89,6 +79,17 @@ class AbstractExport extends Top { static get validate() { return ajv.compile(schema); } + static isValid(q, logger) { + let valid = this.validate(q); + if (!valid) { + let msg = `Some of properties do not satisfy requirements for "${this.name}"\n` + + this.validate.errors.map((x, i) => ` ${i+1}. ${x.dataPath} ${x.message}`) + .join('\n'); + logger?.error(msg, {type: 'ValidationError'}); + } + + return valid; + } } module.exports = { AbstractExport }; diff --git a/src/dbsolve-export/index.js b/src/dbsolve-export/index.js index 4f658887..96c1382c 100644 --- a/src/dbsolve-export/index.js +++ b/src/dbsolve-export/index.js @@ -13,7 +13,7 @@ const schema = { } }; -class DBSolveExport extends AbstractExport{ +class DBSolveExport extends AbstractExport { constructor(q = {}, isCore = false) { super(q, isCore); diff --git a/test/export/export-check.js b/test/export/export-check.js index c78c7ff9..06646ba6 100644 --- a/test/export/export-check.js +++ b/test/export/export-check.js @@ -16,7 +16,6 @@ describe('General argument checking', () => { powTransform: 'function' }); expect(p.logger).to.have.property('hasErrors').false; - expect(json_export).to.have.property('id', 'json_export'); expect(json_export).to.have.property('filepath', './1.json'); expect(json_export).to.have.property('format', 'JSON'); expect(json_export).to.have.deep.property('omit', ['num']);