Skip to content

Commit

Permalink
_Export is not connected to Top
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Sep 6, 2024
1 parent 9ced0da commit b7ae426
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
47 changes: 24 additions & 23 deletions src/abstract-export/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
const { Top } = require('../core/top');
const { ajv } = require('../utils');

const schema = {
type: 'object',
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_'
},
}
};

Expand All @@ -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; }

Expand All @@ -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 {
Expand All @@ -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 };
2 changes: 1 addition & 1 deletion src/dbsolve-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const schema = {
}
};

class DBSolveExport extends AbstractExport{
class DBSolveExport extends AbstractExport {
constructor(q = {}, isCore = false) {
super(q, isCore);

Expand Down
1 change: 0 additions & 1 deletion test/export/export-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit b7ae426

Please sign in to comment.