From 27c429f00a04d5944365f840a0cfcbcc7fb54564 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:16:59 -0700 Subject: [PATCH 1/8] chore: add pyproject file --- pyproject.toml | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4b5f515 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,77 @@ +[project] +name = "mat3ra-code" +dynamic = ["version"] +description = "COre DEfinitions." +readme = "README.md" +requires-python = ">=3.8" +license = {file = "LICENSE.md"} +authors = [ + {name = "Exabyte Inc.", email = "info@mat3ra.com"} +] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Development Status :: 3 - Alpha", + "Topic :: Software Development", +] +dependencies = [ + # add requirements here + "numpy" +] + +[project.optional-dependencies] +tests = [ + "coverage[toml]>=5.3", + "pre-commit", + "black", + "ruff", + "isort", + "mypy", + "pip-tools" +] +all = ["mat3ra-code[tests]"] + +# Entrypoint scripts can be defined here, see examples below. +[project.scripts] +# my-script = "my_package.my_module:my_function" + + +[build-system] +requires = [ + "setuptools>=42", + "setuptools-scm[toml]>=3.4" +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +git_describe_command = "git describe --tags --long" + +[tool.setuptools.packages.find] +where = ["src/py"] + +[tool.black] +line-length = 120 +target-version = ['py38'] +# 'extend-exclude' excludes files or directories in addition to the defaults +extend-exclude = ''' +( + examples\/.*\/.*\.py + | other\/.*\/.*\.(py|ipynb) +) +''' + +[tool.ruff] +# Exclude a variety of commonly ignored directories. +extend-exclude = [ + "src/js" +] +line-length = 120 +target-version = "py38" + +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] + +[tool.isort] +profile = "black" +multi_line_output = 3 +include_trailing_comma = true From 4218fa6b0123812353f6b84d62294f38c4220831 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:17:57 -0700 Subject: [PATCH 2/8] chore: add tests/src --- src/{ => js}/constants.js | 0 src/{ => js}/context/index.ts | 0 src/{ => js}/context/json_schema_provider.ts | 0 src/{ => js}/context/mixins.ts | 0 src/{ => js}/context/pickers.js | 0 src/{ => js}/context/provider.ts | 0 src/{ => js}/context/registry.js | 0 src/{ => js}/entity/in_memory.ts | 0 src/{ => js}/entity/index.ts | 0 src/{ => js}/entity/mixins/context.ts | 1 + src/{ => js}/entity/mixins/context_runtime.ts | 0 src/{ => js}/entity/mixins/flowchart.ts | 0 src/{ => js}/entity/mixins/hash.ts | 0 src/{ => js}/entity/mixins/props.ts | 0 src/{ => js}/entity/mixins/repetition.ts | 0 src/{ => js}/entity/mixins/runtime_items.ts | 1 + src/{ => js}/entity/other.ts | 0 src/{ => js}/entity/set.ts | 0 src/{ => js}/entity/set/enums.ts | 0 src/{ => js}/entity/set/factory.ts | 0 src/{ => js}/entity/set/mixins.ts | 0 src/{ => js}/entity/set/ordered.ts | 0 src/{ => js}/entity/set/ordered/mixins.ts | 0 src/{ => js}/entity/set/ordered/utils.ts | 0 src/{ => js}/entity/set/selectors.ts | 0 src/{ => js}/index.ts | 0 src/{ => js}/math.ts | 6 +- src/{ => js}/utils/array.js | 0 src/{ => js}/utils/class.js | 0 src/{ => js}/utils/clone.js | 0 src/{ => js}/utils/codemirror.ts | 0 src/{ => js}/utils/file.js | 0 src/{ => js}/utils/filter.ts | 0 src/{ => js}/utils/github.js | 0 src/{ => js}/utils/graph.ts | 0 src/{ => js}/utils/hash.ts | 0 src/{ => js}/utils/index.ts | 0 src/{ => js}/utils/object.ts | 2 +- src/{ => js}/utils/schemas.ts | 0 src/{ => js}/utils/selector.js | 0 src/{ => js}/utils/str.js | 0 src/{ => js}/utils/tree.js | 0 src/{ => js}/utils/url.js | 0 src/{ => js}/utils/uuid.js | 0 src/{ => js}/utils/yaml.ts | 0 src/py/__init__.py | 0 src/py/mat3ra/__init__.py | 0 src/py/mat3ra/code/__init__.py | 5 + tests/js/context.tests.d.ts | 1 + tests/js/context.tests.js | 81 ++++++ tests/{ => js}/context.tests.ts | 4 +- tests/js/enums.d.ts | 9 + tests/js/enums.js | 63 +++++ tests/{ => js}/enums.ts | 0 tests/{ => js}/fixtures/json/example/1.json | 0 tests/{ => js}/fixtures/json/example/2.json | 0 tests/{ => js}/fixtures/json/example/3.json | 0 tests/{ => js}/fixtures/json/example/4.json | 0 tests/{ => js}/fixtures/json/example/5.json | 0 tests/js/fixtures/rjsf_schemas.d.ts | 230 ++++++++++++++++++ tests/{ => js}/fixtures/rjsf_schemas.js | 0 tests/{ => js}/fixtures/test_content.txt | 0 tests/{ => js}/fixtures/yaml_combine_tag.yml | 0 .../fixtures/yaml_concatString_tag.yml | 0 tests/{ => js}/fixtures/yaml_esse_tag.yml | 0 tests/{ => js}/fixtures/yaml_flatten_tag.yml | 0 tests/{ => js}/fixtures/yaml_include_tag.yml | 0 .../fixtures/yaml_listToString_tag.yml | 0 .../{ => js}/fixtures/yaml_parameter_ref.yml | 0 .../{ => js}/fixtures/yaml_parameter_tag.yml | 0 tests/{ => js}/fixtures/yaml_readFile_tag.yml | 0 tests/js/in_memory.tests.d.ts | 1 + tests/js/in_memory.tests.js | 88 +++++++ tests/{ => js}/in_memory.tests.ts | 2 +- tests/js/mixin.flowchart.tests.d.ts | 1 + tests/js/mixin.flowchart.tests.js | 87 +++++++ tests/{ => js}/mixin.flowchart.tests.ts | 2 +- tests/js/provider.tests.d.ts | 1 + tests/js/provider.tests.js | 22 ++ tests/{ => js}/provider.tests.ts | 2 +- tests/js/utils.d.ts | 4 + tests/js/utils.js | 14 ++ tests/{ => js}/utils.ts | 2 +- tests/js/utils/class.tests.d.ts | 1 + tests/js/utils/class.tests.js | 98 ++++++++ tests/{ => js}/utils/class.tests.ts | 4 +- tests/js/utils/file.tests.d.ts | 1 + tests/js/utils/file.tests.js | 11 + tests/{ => js}/utils/file.tests.ts | 2 +- tests/js/utils/filter.tests.d.ts | 1 + tests/js/utils/filter.tests.js | 94 +++++++ tests/{ => js}/utils/filter.tests.ts | 2 +- tests/js/utils/object.tests.d.ts | 1 + tests/js/utils/object.tests.js | 91 +++++++ tests/{ => js}/utils/object.tests.ts | 2 +- tests/js/utils/schemas.tests.d.ts | 1 + tests/js/utils/schemas.tests.js | 121 +++++++++ tests/{ => js}/utils/schemas.tests.ts | 2 +- tests/js/utils/str.tests.d.ts | 1 + tests/js/utils/str.tests.js | 70 ++++++ tests/{ => js}/utils/str.tests.ts | 2 +- tests/js/utils/tree.tests.d.ts | 1 + tests/js/utils/tree.tests.js | 34 +++ tests/{ => js}/utils/tree.tests.ts | 2 +- tests/js/utils/utils.tests.d.ts | 1 + tests/js/utils/utils.tests.js | 34 +++ tests/{ => js}/utils/utils.tests.ts | 4 +- tests/js/utils/yaml.combine.tests.d.ts | 1 + tests/js/utils/yaml.combine.tests.js | 122 ++++++++++ tests/{ => js}/utils/yaml.combine.tests.ts | 2 +- tests/js/utils/yaml.concatString.tests.d.ts | 1 + tests/js/utils/yaml.concatString.tests.js | 31 +++ .../{ => js}/utils/yaml.concatString.tests.ts | 2 +- tests/js/utils/yaml.esse.tests.d.ts | 1 + tests/js/utils/yaml.esse.tests.js | 58 +++++ tests/{ => js}/utils/yaml.esse.tests.ts | 2 +- tests/js/utils/yaml.flatten.tests.d.ts | 1 + tests/js/utils/yaml.flatten.tests.js | 21 ++ tests/{ => js}/utils/yaml.flatten.tests.ts | 2 +- tests/js/utils/yaml.include.tests.d.ts | 1 + tests/js/utils/yaml.include.tests.js | 33 +++ tests/{ => js}/utils/yaml.include.tests.ts | 3 +- tests/js/utils/yaml.listToString.tests.d.ts | 1 + tests/js/utils/yaml.listToString.tests.js | 33 +++ .../{ => js}/utils/yaml.listToString.tests.ts | 2 +- tests/js/utils/yaml.parameter.tests.d.ts | 1 + tests/js/utils/yaml.parameter.tests.js | 61 +++++ tests/{ => js}/utils/yaml.parameter.tests.ts | 3 +- tests/js/utils/yaml.readFile.tests.d.ts | 1 + tests/js/utils/yaml.readFile.tests.js | 22 ++ tests/{ => js}/utils/yaml.readFile.tests.ts | 3 +- tests/py/__init__.py | 0 tests/py/unit/__init__.py | 0 tests/py/unit/test_sample.py | 10 + 134 files changed, 1600 insertions(+), 28 deletions(-) rename src/{ => js}/constants.js (100%) rename src/{ => js}/context/index.ts (100%) rename src/{ => js}/context/json_schema_provider.ts (100%) rename src/{ => js}/context/mixins.ts (100%) rename src/{ => js}/context/pickers.js (100%) rename src/{ => js}/context/provider.ts (100%) rename src/{ => js}/context/registry.js (100%) rename src/{ => js}/entity/in_memory.ts (100%) rename src/{ => js}/entity/index.ts (100%) rename src/{ => js}/entity/mixins/context.ts (99%) rename src/{ => js}/entity/mixins/context_runtime.ts (100%) rename src/{ => js}/entity/mixins/flowchart.ts (100%) rename src/{ => js}/entity/mixins/hash.ts (100%) rename src/{ => js}/entity/mixins/props.ts (100%) rename src/{ => js}/entity/mixins/repetition.ts (100%) rename src/{ => js}/entity/mixins/runtime_items.ts (99%) rename src/{ => js}/entity/other.ts (100%) rename src/{ => js}/entity/set.ts (100%) rename src/{ => js}/entity/set/enums.ts (100%) rename src/{ => js}/entity/set/factory.ts (100%) rename src/{ => js}/entity/set/mixins.ts (100%) rename src/{ => js}/entity/set/ordered.ts (100%) rename src/{ => js}/entity/set/ordered/mixins.ts (100%) rename src/{ => js}/entity/set/ordered/utils.ts (100%) rename src/{ => js}/entity/set/selectors.ts (100%) rename src/{ => js}/index.ts (100%) rename src/{ => js}/math.ts (98%) rename src/{ => js}/utils/array.js (100%) rename src/{ => js}/utils/class.js (100%) rename src/{ => js}/utils/clone.js (100%) rename src/{ => js}/utils/codemirror.ts (100%) rename src/{ => js}/utils/file.js (100%) rename src/{ => js}/utils/filter.ts (100%) rename src/{ => js}/utils/github.js (100%) rename src/{ => js}/utils/graph.ts (100%) rename src/{ => js}/utils/hash.ts (100%) rename src/{ => js}/utils/index.ts (100%) rename src/{ => js}/utils/object.ts (99%) rename src/{ => js}/utils/schemas.ts (100%) rename src/{ => js}/utils/selector.js (100%) rename src/{ => js}/utils/str.js (100%) rename src/{ => js}/utils/tree.js (100%) rename src/{ => js}/utils/url.js (100%) rename src/{ => js}/utils/uuid.js (100%) rename src/{ => js}/utils/yaml.ts (100%) create mode 100644 src/py/__init__.py create mode 100644 src/py/mat3ra/__init__.py create mode 100644 src/py/mat3ra/code/__init__.py create mode 100644 tests/js/context.tests.d.ts create mode 100644 tests/js/context.tests.js rename tests/{ => js}/context.tests.ts (96%) create mode 100644 tests/js/enums.d.ts create mode 100644 tests/js/enums.js rename tests/{ => js}/enums.ts (100%) rename tests/{ => js}/fixtures/json/example/1.json (100%) rename tests/{ => js}/fixtures/json/example/2.json (100%) rename tests/{ => js}/fixtures/json/example/3.json (100%) rename tests/{ => js}/fixtures/json/example/4.json (100%) rename tests/{ => js}/fixtures/json/example/5.json (100%) create mode 100644 tests/js/fixtures/rjsf_schemas.d.ts rename tests/{ => js}/fixtures/rjsf_schemas.js (100%) rename tests/{ => js}/fixtures/test_content.txt (100%) rename tests/{ => js}/fixtures/yaml_combine_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_concatString_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_esse_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_flatten_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_include_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_listToString_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_parameter_ref.yml (100%) rename tests/{ => js}/fixtures/yaml_parameter_tag.yml (100%) rename tests/{ => js}/fixtures/yaml_readFile_tag.yml (100%) create mode 100644 tests/js/in_memory.tests.d.ts create mode 100644 tests/js/in_memory.tests.js rename tests/{ => js}/in_memory.tests.ts (97%) create mode 100644 tests/js/mixin.flowchart.tests.d.ts create mode 100644 tests/js/mixin.flowchart.tests.js rename tests/{ => js}/mixin.flowchart.tests.ts (99%) create mode 100644 tests/js/provider.tests.d.ts create mode 100644 tests/js/provider.tests.js rename tests/{ => js}/provider.tests.ts (92%) create mode 100644 tests/js/utils.d.ts create mode 100644 tests/js/utils.js rename tests/{ => js}/utils.ts (85%) create mode 100644 tests/js/utils/class.tests.d.ts create mode 100644 tests/js/utils/class.tests.js rename tests/{ => js}/utils/class.tests.ts (96%) create mode 100644 tests/js/utils/file.tests.d.ts create mode 100644 tests/js/utils/file.tests.js rename tests/{ => js}/utils/file.tests.ts (82%) create mode 100644 tests/js/utils/filter.tests.d.ts create mode 100644 tests/js/utils/filter.tests.js rename tests/{ => js}/utils/filter.tests.ts (97%) create mode 100644 tests/js/utils/object.tests.d.ts create mode 100644 tests/js/utils/object.tests.js rename tests/{ => js}/utils/object.tests.ts (96%) create mode 100644 tests/js/utils/schemas.tests.d.ts create mode 100644 tests/js/utils/schemas.tests.js rename tests/{ => js}/utils/schemas.tests.ts (99%) create mode 100644 tests/js/utils/str.tests.d.ts create mode 100644 tests/js/utils/str.tests.js rename tests/{ => js}/utils/str.tests.ts (99%) create mode 100644 tests/js/utils/tree.tests.d.ts create mode 100644 tests/js/utils/tree.tests.js rename tests/{ => js}/utils/tree.tests.ts (94%) create mode 100644 tests/js/utils/utils.tests.d.ts create mode 100644 tests/js/utils/utils.tests.js rename tests/{ => js}/utils/utils.tests.ts (90%) create mode 100644 tests/js/utils/yaml.combine.tests.d.ts create mode 100644 tests/js/utils/yaml.combine.tests.js rename tests/{ => js}/utils/yaml.combine.tests.ts (98%) create mode 100644 tests/js/utils/yaml.concatString.tests.d.ts create mode 100644 tests/js/utils/yaml.concatString.tests.js rename tests/{ => js}/utils/yaml.concatString.tests.ts (94%) create mode 100644 tests/js/utils/yaml.esse.tests.d.ts create mode 100644 tests/js/utils/yaml.esse.tests.js rename tests/{ => js}/utils/yaml.esse.tests.ts (97%) create mode 100644 tests/js/utils/yaml.flatten.tests.d.ts create mode 100644 tests/js/utils/yaml.flatten.tests.js rename tests/{ => js}/utils/yaml.flatten.tests.ts (91%) create mode 100644 tests/js/utils/yaml.include.tests.d.ts create mode 100644 tests/js/utils/yaml.include.tests.js rename tests/{ => js}/utils/yaml.include.tests.ts (93%) create mode 100644 tests/js/utils/yaml.listToString.tests.d.ts create mode 100644 tests/js/utils/yaml.listToString.tests.js rename tests/{ => js}/utils/yaml.listToString.tests.ts (93%) create mode 100644 tests/js/utils/yaml.parameter.tests.d.ts create mode 100644 tests/js/utils/yaml.parameter.tests.js rename tests/{ => js}/utils/yaml.parameter.tests.ts (97%) create mode 100644 tests/js/utils/yaml.readFile.tests.d.ts create mode 100644 tests/js/utils/yaml.readFile.tests.js rename tests/{ => js}/utils/yaml.readFile.tests.ts (89%) create mode 100644 tests/py/__init__.py create mode 100644 tests/py/unit/__init__.py create mode 100644 tests/py/unit/test_sample.py diff --git a/src/constants.js b/src/js/constants.js similarity index 100% rename from src/constants.js rename to src/js/constants.js diff --git a/src/context/index.ts b/src/js/context/index.ts similarity index 100% rename from src/context/index.ts rename to src/js/context/index.ts diff --git a/src/context/json_schema_provider.ts b/src/js/context/json_schema_provider.ts similarity index 100% rename from src/context/json_schema_provider.ts rename to src/js/context/json_schema_provider.ts diff --git a/src/context/mixins.ts b/src/js/context/mixins.ts similarity index 100% rename from src/context/mixins.ts rename to src/js/context/mixins.ts diff --git a/src/context/pickers.js b/src/js/context/pickers.js similarity index 100% rename from src/context/pickers.js rename to src/js/context/pickers.js diff --git a/src/context/provider.ts b/src/js/context/provider.ts similarity index 100% rename from src/context/provider.ts rename to src/js/context/provider.ts diff --git a/src/context/registry.js b/src/js/context/registry.js similarity index 100% rename from src/context/registry.js rename to src/js/context/registry.js diff --git a/src/entity/in_memory.ts b/src/js/entity/in_memory.ts similarity index 100% rename from src/entity/in_memory.ts rename to src/js/entity/in_memory.ts diff --git a/src/entity/index.ts b/src/js/entity/index.ts similarity index 100% rename from src/entity/index.ts rename to src/js/entity/index.ts diff --git a/src/entity/mixins/context.ts b/src/js/entity/mixins/context.ts similarity index 99% rename from src/entity/mixins/context.ts rename to src/js/entity/mixins/context.ts index 024e0d8..ec51c04 100644 --- a/src/entity/mixins/context.ts +++ b/src/js/entity/mixins/context.ts @@ -50,6 +50,7 @@ export function ContextAndRenderFieldsMixin // override in subclasses // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars + // @ts-ignore render(context = this.context) { throw new Error("RenderInitMixin: render not implemented in derived class"); } diff --git a/src/entity/mixins/context_runtime.ts b/src/js/entity/mixins/context_runtime.ts similarity index 100% rename from src/entity/mixins/context_runtime.ts rename to src/js/entity/mixins/context_runtime.ts diff --git a/src/entity/mixins/flowchart.ts b/src/js/entity/mixins/flowchart.ts similarity index 100% rename from src/entity/mixins/flowchart.ts rename to src/js/entity/mixins/flowchart.ts diff --git a/src/entity/mixins/hash.ts b/src/js/entity/mixins/hash.ts similarity index 100% rename from src/entity/mixins/hash.ts rename to src/js/entity/mixins/hash.ts diff --git a/src/entity/mixins/props.ts b/src/js/entity/mixins/props.ts similarity index 100% rename from src/entity/mixins/props.ts rename to src/js/entity/mixins/props.ts diff --git a/src/entity/mixins/repetition.ts b/src/js/entity/mixins/repetition.ts similarity index 100% rename from src/entity/mixins/repetition.ts rename to src/js/entity/mixins/repetition.ts diff --git a/src/entity/mixins/runtime_items.ts b/src/js/entity/mixins/runtime_items.ts similarity index 99% rename from src/entity/mixins/runtime_items.ts rename to src/js/entity/mixins/runtime_items.ts index 2e301ed..5af340b 100644 --- a/src/entity/mixins/runtime_items.ts +++ b/src/js/entity/mixins/runtime_items.ts @@ -112,6 +112,7 @@ export function RuntimeItemsUILogicMixin(su * @private */ // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars + // @ts-ignore _initRuntimeItems(keys: ItemKey[], config: object) { // keeping this separate from constructor so that it can be overridden in mixing (eg. in `ExecutionUnit`) // eslint-disable-next-line @typescript-eslint/no-this-alias diff --git a/src/entity/other.ts b/src/js/entity/other.ts similarity index 100% rename from src/entity/other.ts rename to src/js/entity/other.ts diff --git a/src/entity/set.ts b/src/js/entity/set.ts similarity index 100% rename from src/entity/set.ts rename to src/js/entity/set.ts diff --git a/src/entity/set/enums.ts b/src/js/entity/set/enums.ts similarity index 100% rename from src/entity/set/enums.ts rename to src/js/entity/set/enums.ts diff --git a/src/entity/set/factory.ts b/src/js/entity/set/factory.ts similarity index 100% rename from src/entity/set/factory.ts rename to src/js/entity/set/factory.ts diff --git a/src/entity/set/mixins.ts b/src/js/entity/set/mixins.ts similarity index 100% rename from src/entity/set/mixins.ts rename to src/js/entity/set/mixins.ts diff --git a/src/entity/set/ordered.ts b/src/js/entity/set/ordered.ts similarity index 100% rename from src/entity/set/ordered.ts rename to src/js/entity/set/ordered.ts diff --git a/src/entity/set/ordered/mixins.ts b/src/js/entity/set/ordered/mixins.ts similarity index 100% rename from src/entity/set/ordered/mixins.ts rename to src/js/entity/set/ordered/mixins.ts diff --git a/src/entity/set/ordered/utils.ts b/src/js/entity/set/ordered/utils.ts similarity index 100% rename from src/entity/set/ordered/utils.ts rename to src/js/entity/set/ordered/utils.ts diff --git a/src/entity/set/selectors.ts b/src/js/entity/set/selectors.ts similarity index 100% rename from src/entity/set/selectors.ts rename to src/js/entity/set/selectors.ts diff --git a/src/index.ts b/src/js/index.ts similarity index 100% rename from src/index.ts rename to src/js/index.ts diff --git a/src/math.ts b/src/js/math.ts similarity index 98% rename from src/math.ts rename to src/js/math.ts index db370a3..3634b69 100644 --- a/src/math.ts +++ b/src/js/math.ts @@ -158,7 +158,7 @@ const isBetweenZeroInclusiveAndOne = (number: number, tolerance = TOLERANCE.leng * @param c */ const combinations = (a: number, b: number, c: number) => { - const combs = []; + const combs: number[][] = []; for (let i = 0; i <= a; i++) { for (let j = 0; j <= b; j++) { for (let k = 0; k <= c; k++) { @@ -173,7 +173,7 @@ const combinations = (a: number, b: number, c: number) => { * @summary Same as `combinations` but accepting intervals (tuples) of integers: eg. [-3, 4] */ const combinationsFromIntervals = (arrA: number[], arrB: number[], arrC: number[]) => { - const combs = []; + const combs: number[][] = []; for (let i = arrA[0]; i <= arrA[1]; i++) { for (let j = arrB[0]; j <= arrB[1]; j++) { for (let k = arrC[0]; k <= arrC[1]; k++) { @@ -201,7 +201,7 @@ const calculateSegmentsBetweenPoints3D = ( const point2_ = point2.map((x) => (typeof x === "string" ? parseFloat(x) : x)); const n_ = typeof n === "string" ? parseInt(n) : n; - const result = []; + const result: number[][] = []; for (let i = 1; i < n_; i++) { const lambda = i / (n_ - i); result.push([ diff --git a/src/utils/array.js b/src/js/utils/array.js similarity index 100% rename from src/utils/array.js rename to src/js/utils/array.js diff --git a/src/utils/class.js b/src/js/utils/class.js similarity index 100% rename from src/utils/class.js rename to src/js/utils/class.js diff --git a/src/utils/clone.js b/src/js/utils/clone.js similarity index 100% rename from src/utils/clone.js rename to src/js/utils/clone.js diff --git a/src/utils/codemirror.ts b/src/js/utils/codemirror.ts similarity index 100% rename from src/utils/codemirror.ts rename to src/js/utils/codemirror.ts diff --git a/src/utils/file.js b/src/js/utils/file.js similarity index 100% rename from src/utils/file.js rename to src/js/utils/file.js diff --git a/src/utils/filter.ts b/src/js/utils/filter.ts similarity index 100% rename from src/utils/filter.ts rename to src/js/utils/filter.ts diff --git a/src/utils/github.js b/src/js/utils/github.js similarity index 100% rename from src/utils/github.js rename to src/js/utils/github.js diff --git a/src/utils/graph.ts b/src/js/utils/graph.ts similarity index 100% rename from src/utils/graph.ts rename to src/js/utils/graph.ts diff --git a/src/utils/hash.ts b/src/js/utils/hash.ts similarity index 100% rename from src/utils/hash.ts rename to src/js/utils/hash.ts diff --git a/src/utils/index.ts b/src/js/utils/index.ts similarity index 100% rename from src/utils/index.ts rename to src/js/utils/index.ts diff --git a/src/utils/object.ts b/src/js/utils/object.ts similarity index 99% rename from src/utils/object.ts rename to src/js/utils/object.ts index a848eec..0833158 100644 --- a/src/utils/object.ts +++ b/src/js/utils/object.ts @@ -51,7 +51,7 @@ export function getOneMatchFromObject(obj: object, attribute: string, value: unk */ export function convertKeysToCamelCaseForObject(obj: object) { const newObj = deepClone(obj); - return mapKeys(newObj, (v, k) => camelCase(k)); + return mapKeys(newObj, (_v, k) => camelCase(k)); } /* diff --git a/src/utils/schemas.ts b/src/js/utils/schemas.ts similarity index 100% rename from src/utils/schemas.ts rename to src/js/utils/schemas.ts diff --git a/src/utils/selector.js b/src/js/utils/selector.js similarity index 100% rename from src/utils/selector.js rename to src/js/utils/selector.js diff --git a/src/utils/str.js b/src/js/utils/str.js similarity index 100% rename from src/utils/str.js rename to src/js/utils/str.js diff --git a/src/utils/tree.js b/src/js/utils/tree.js similarity index 100% rename from src/utils/tree.js rename to src/js/utils/tree.js diff --git a/src/utils/url.js b/src/js/utils/url.js similarity index 100% rename from src/utils/url.js rename to src/js/utils/url.js diff --git a/src/utils/uuid.js b/src/js/utils/uuid.js similarity index 100% rename from src/utils/uuid.js rename to src/js/utils/uuid.js diff --git a/src/utils/yaml.ts b/src/js/utils/yaml.ts similarity index 100% rename from src/utils/yaml.ts rename to src/js/utils/yaml.ts diff --git a/src/py/__init__.py b/src/py/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/py/mat3ra/__init__.py b/src/py/mat3ra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/py/mat3ra/code/__init__.py b/src/py/mat3ra/code/__init__.py new file mode 100644 index 0000000..b94a6ae --- /dev/null +++ b/src/py/mat3ra/code/__init__.py @@ -0,0 +1,5 @@ +import numpy as np + + +def get_length(vec: np.ndarray) -> np.float_: + return np.linalg.norm(vec) diff --git a/tests/js/context.tests.d.ts b/tests/js/context.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/context.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/context.tests.js b/tests/js/context.tests.js new file mode 100644 index 0000000..0405ab4 --- /dev/null +++ b/tests/js/context.tests.js @@ -0,0 +1,81 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const context_1 = require("../../src/js/context"); + +class MockMaterial { + static createDefault() { + return "defaultMockMaterial"; + } +} +class SpecificMockMaterial { + static createDefault() { + return "defaultSpecificMockMaterial"; + } +} +class MockApplication { + static createDefault() { + return "defaultMockApplication"; + } +} +class SpecificMockApplication { + static createDefault() { + return "defaultSpecificMockApplication"; + } +} +class ProviderEntity extends (0, context_1.MaterialContextMixin)( + (0, context_1.ApplicationContextMixin)(context_1.ContextProvider), +) {} +ProviderEntity.Material = MockMaterial; +ProviderEntity.Application = MockApplication; +ProviderEntity.setting = 10; +class DerivedProviderEntity extends ProviderEntity {} +DerivedProviderEntity.Material = SpecificMockMaterial; +DerivedProviderEntity.Application = SpecificMockApplication; +class ApplicationContextProvider extends (0, context_1.ApplicationContextMixin)( + context_1.ContextProvider, +) {} +ApplicationContextProvider.Application = SpecificMockApplication; +describe("Material & Application ContextMixin", () => { + const config = { name: "test" }; + it("uses static entity class", () => { + const provider = new ProviderEntity(config); + (0, chai_1.expect)(provider.material).to.be.equal("defaultMockMaterial"); + (0, chai_1.expect)(provider.application).to.be.equal("defaultMockApplication"); + }); + it("uses static entity class from derived class", () => { + const provider = new DerivedProviderEntity(config); + (0, chai_1.expect)(provider.material).to.be.equal("defaultSpecificMockMaterial"); + (0, chai_1.expect)(provider.application).to.be.equal("defaultSpecificMockApplication"); + }); +}); +describe("ContextProviderRegistryContainer", () => { + const classConfigObj = { + DataManager: { + providerCls: ProviderEntity, + config: { name: "example1", domain: "important" }, + }, + ApplicationDataManager: { + providerCls: ApplicationContextProvider, + config: { name: "example2", domain: "important" }, + }, + }; + const defaultSettings = { + ProviderEntity: { + setting: 100, + }, + }; + it("can be created and patched", () => { + const registry = (0, context_1.createAndPatchRegistry)( + classConfigObj, + { Material: SpecificMockMaterial }, + defaultSettings, + ); + const _dataProvider = registry.findProviderInstanceByName("DataManager"); + const dataProvider = new _dataProvider.constructor(_dataProvider.config); + const _appProvider = registry.findProviderInstanceByName("ApplicationDataManager"); + const appProvider = new _appProvider.constructor(_appProvider.config); + (0, chai_1.expect)(_dataProvider.constructor.setting).to.be.equal(100); + (0, chai_1.expect)(dataProvider.material).to.be.equal("defaultSpecificMockMaterial"); + (0, chai_1.expect)(appProvider.application).to.be.equal("defaultSpecificMockApplication"); + }); +}); diff --git a/tests/context.tests.ts b/tests/js/context.tests.ts similarity index 96% rename from tests/context.tests.ts rename to tests/js/context.tests.ts index 35d623f..4791582 100644 --- a/tests/context.tests.ts +++ b/tests/js/context.tests.ts @@ -5,8 +5,8 @@ import { ContextProvider, createAndPatchRegistry, MaterialContextMixin, -} from "../src/context"; -import { ContextProviderConfig } from "../src/context/provider"; +} from "../../src/js/context"; +import { ContextProviderConfig } from "../../src/js/context/provider"; class MockMaterial { static createDefault() { diff --git a/tests/js/enums.d.ts b/tests/js/enums.d.ts new file mode 100644 index 0000000..1bb368a --- /dev/null +++ b/tests/js/enums.d.ts @@ -0,0 +1,9 @@ +export declare const FIXTURES_DIR: string; +export declare const YAML_COMBINE_FILE: string; +export declare const YAML_LIST_TO_STRING_FILE: string; +export declare const YAML_PARAMETER_FILE: string; +export declare const YAML_ESSE_FILE: string; +export declare const YAML_INCLUDE_FILE: string; +export declare const YAML_FLATTEN_FILE: string; +export declare const YAML_READFILE_FILE: string; +export declare const YAML_CONCAT_STRING_FILE: string; diff --git a/tests/js/enums.js b/tests/js/enums.js new file mode 100644 index 0000000..74cd742 --- /dev/null +++ b/tests/js/enums.js @@ -0,0 +1,63 @@ +const __createBinding = + (this && this.__createBinding) || + (Object.create + ? function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + let desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { + enumerable: true, + get() { + return m[k]; + }, + }; + } + Object.defineProperty(o, k2, desc); + } + : function (o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; + }); +const __setModuleDefault = + (this && this.__setModuleDefault) || + (Object.create + ? function (o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); + } + : function (o, v) { + o.default = v; + }); +const __importStar = + (this && this.__importStar) || + function (mod) { + if (mod && mod.__esModule) return mod; + const result = {}; + if (mod != null) + for (const k in mod) + if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.YAML_CONCAT_STRING_FILE = + exports.YAML_READFILE_FILE = + exports.YAML_FLATTEN_FILE = + exports.YAML_INCLUDE_FILE = + exports.YAML_ESSE_FILE = + exports.YAML_PARAMETER_FILE = + exports.YAML_LIST_TO_STRING_FILE = + exports.YAML_COMBINE_FILE = + exports.FIXTURES_DIR = + void 0; +const path = __importStar(require("path")); + +exports.FIXTURES_DIR = path.resolve(__dirname, "./fixtures"); +exports.YAML_COMBINE_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_combine_tag.yml"); +exports.YAML_LIST_TO_STRING_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_listToString_tag.yml"); +exports.YAML_PARAMETER_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_parameter_tag.yml"); +exports.YAML_ESSE_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_esse_tag.yml"); +exports.YAML_INCLUDE_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_include_tag.yml"); +exports.YAML_FLATTEN_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_flatten_tag.yml"); +exports.YAML_READFILE_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_readFile_tag.yml"); +exports.YAML_CONCAT_STRING_FILE = path.resolve(exports.FIXTURES_DIR, "yaml_concatString_tag.yml"); diff --git a/tests/enums.ts b/tests/js/enums.ts similarity index 100% rename from tests/enums.ts rename to tests/js/enums.ts diff --git a/tests/fixtures/json/example/1.json b/tests/js/fixtures/json/example/1.json similarity index 100% rename from tests/fixtures/json/example/1.json rename to tests/js/fixtures/json/example/1.json diff --git a/tests/fixtures/json/example/2.json b/tests/js/fixtures/json/example/2.json similarity index 100% rename from tests/fixtures/json/example/2.json rename to tests/js/fixtures/json/example/2.json diff --git a/tests/fixtures/json/example/3.json b/tests/js/fixtures/json/example/3.json similarity index 100% rename from tests/fixtures/json/example/3.json rename to tests/js/fixtures/json/example/3.json diff --git a/tests/fixtures/json/example/4.json b/tests/js/fixtures/json/example/4.json similarity index 100% rename from tests/fixtures/json/example/4.json rename to tests/js/fixtures/json/example/4.json diff --git a/tests/fixtures/json/example/5.json b/tests/js/fixtures/json/example/5.json similarity index 100% rename from tests/fixtures/json/example/5.json rename to tests/js/fixtures/json/example/5.json diff --git a/tests/js/fixtures/rjsf_schemas.d.ts b/tests/js/fixtures/rjsf_schemas.d.ts new file mode 100644 index 0000000..3c2c99a --- /dev/null +++ b/tests/js/fixtures/rjsf_schemas.d.ts @@ -0,0 +1,230 @@ +export namespace EXAMPLE_SCHEMA { + const type: string; + namespace properties { + export namespace type_1 { + const type_2: string; + export { type_2 as type }; + } + export { type_1 as type }; + export namespace subtype { + const type_3: string; + export { type_3 as type }; + } + export namespace subsubtype { + const type_4: string; + export { type_4 as type }; + } + } +} +export namespace TREE_SIMPLE { + const path: string; + namespace data { + const key: string; + const value: string; + const name: string; + } + const children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + }[]; + }[]; +} +export namespace TREE_ADVANCED { + const path_1: string; + export { path_1 as path }; + export namespace data_1 { + const key_1: string; + export { key_1 as key }; + const value_1: string; + export { value_1 as value }; + const name_1: string; + export { name_1 as name }; + } + export { data_1 as data }; + const children_1: ( + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + }[]; + staticOptions?: undefined; + } + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + }[]; + staticOptions: { + key: string; + values: string[]; + }[]; + } + )[]; + export { children_1 as children }; + export const staticOptions: ( + | { + key: string; + values: string[]; + namesMap: { + static_a1: string; + }; + } + | { + key: string; + values: boolean[]; + namesMap?: undefined; + } + )[]; +} +export namespace UNEVEN_TREE { + const path_2: string; + export { path_2 as path }; + export namespace data_2 { + const key_2: string; + export { key_2 as key }; + const value_2: string; + export { value_2 as value }; + const name_2: string; + export { name_2 as name }; + } + export { data_2 as data }; + const children_2: ( + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children?: undefined; + } + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + }[]; + } + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: { + path: string; + data: { + key: string; + value: string; + name: string; + }; + }[]; + }[]; + } + )[]; + export { children_2 as children }; +} +export namespace TREE_STATIC_TERMINAL { + const path_3: string; + export { path_3 as path }; + export namespace data_3 { + const key_3: string; + export { key_3 as key }; + const value_3: string; + export { value_3 as value }; + const name_3: string; + export { name_3 as name }; + } + export { data_3 as data }; + const children_3: ( + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children?: undefined; + } + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + children: ( + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + staticOptions: { + key: string; + values: string[]; + }[]; + } + | { + path: string; + data: { + key: string; + value: string; + name: string; + }; + staticOptions?: undefined; + } + )[]; + } + )[]; + export { children_3 as children }; +} diff --git a/tests/fixtures/rjsf_schemas.js b/tests/js/fixtures/rjsf_schemas.js similarity index 100% rename from tests/fixtures/rjsf_schemas.js rename to tests/js/fixtures/rjsf_schemas.js diff --git a/tests/fixtures/test_content.txt b/tests/js/fixtures/test_content.txt similarity index 100% rename from tests/fixtures/test_content.txt rename to tests/js/fixtures/test_content.txt diff --git a/tests/fixtures/yaml_combine_tag.yml b/tests/js/fixtures/yaml_combine_tag.yml similarity index 100% rename from tests/fixtures/yaml_combine_tag.yml rename to tests/js/fixtures/yaml_combine_tag.yml diff --git a/tests/fixtures/yaml_concatString_tag.yml b/tests/js/fixtures/yaml_concatString_tag.yml similarity index 100% rename from tests/fixtures/yaml_concatString_tag.yml rename to tests/js/fixtures/yaml_concatString_tag.yml diff --git a/tests/fixtures/yaml_esse_tag.yml b/tests/js/fixtures/yaml_esse_tag.yml similarity index 100% rename from tests/fixtures/yaml_esse_tag.yml rename to tests/js/fixtures/yaml_esse_tag.yml diff --git a/tests/fixtures/yaml_flatten_tag.yml b/tests/js/fixtures/yaml_flatten_tag.yml similarity index 100% rename from tests/fixtures/yaml_flatten_tag.yml rename to tests/js/fixtures/yaml_flatten_tag.yml diff --git a/tests/fixtures/yaml_include_tag.yml b/tests/js/fixtures/yaml_include_tag.yml similarity index 100% rename from tests/fixtures/yaml_include_tag.yml rename to tests/js/fixtures/yaml_include_tag.yml diff --git a/tests/fixtures/yaml_listToString_tag.yml b/tests/js/fixtures/yaml_listToString_tag.yml similarity index 100% rename from tests/fixtures/yaml_listToString_tag.yml rename to tests/js/fixtures/yaml_listToString_tag.yml diff --git a/tests/fixtures/yaml_parameter_ref.yml b/tests/js/fixtures/yaml_parameter_ref.yml similarity index 100% rename from tests/fixtures/yaml_parameter_ref.yml rename to tests/js/fixtures/yaml_parameter_ref.yml diff --git a/tests/fixtures/yaml_parameter_tag.yml b/tests/js/fixtures/yaml_parameter_tag.yml similarity index 100% rename from tests/fixtures/yaml_parameter_tag.yml rename to tests/js/fixtures/yaml_parameter_tag.yml diff --git a/tests/fixtures/yaml_readFile_tag.yml b/tests/js/fixtures/yaml_readFile_tag.yml similarity index 100% rename from tests/fixtures/yaml_readFile_tag.yml rename to tests/js/fixtures/yaml_readFile_tag.yml diff --git a/tests/js/in_memory.tests.d.ts b/tests/js/in_memory.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/in_memory.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/in_memory.tests.js b/tests/js/in_memory.tests.js new file mode 100644 index 0000000..0d2ef28 --- /dev/null +++ b/tests/js/in_memory.tests.js @@ -0,0 +1,88 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +const base_json_1 = __importDefault( + require("@mat3ra/esse/lib/js/schema/in_memory_entity/base.json"), +); +const chai_1 = require("chai"); +const in_memory_1 = require("../../src/js/entity/in_memory"); + +class DerivedInMemoryEntity extends in_memory_1.InMemoryEntity {} +DerivedInMemoryEntity.jsonSchema = base_json_1.default; +function validateEntity(entity) { + try { + entity.validate(); + } catch (err) { + return false; + } + return true; +} +describe("InMemoryEntity", () => { + const obj = { + a: "b", + name: "test", + }; + it("can be created", () => { + const empty = new in_memory_1.InMemoryEntity(); + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(empty).to.exist; + const entity = new in_memory_1.InMemoryEntity(obj); + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(entity).to.exist; + }); + it("prop gets props", () => { + const entity = new in_memory_1.InMemoryEntity(obj); + (0, chai_1.expect)(entity.prop("a")).to.equal("b"); + (0, chai_1.expect)(entity.prop("b")).to.equal(undefined); + (0, chai_1.expect)(entity.prop("b", "a")).to.equal("a"); + }); + it("setProp sets props", () => { + const entity = new in_memory_1.InMemoryEntity(obj); + (0, chai_1.expect)(entity.prop("a")).to.equal("b"); + entity.setProp("b", "c"); + (0, chai_1.expect)(entity.prop("b")).to.equal("c"); + entity.setProp("a", "d"); + (0, chai_1.expect)(entity.prop("a")).to.equal("d"); + }); + it("unsetProp unsets props", () => { + const entity = new in_memory_1.InMemoryEntity(obj); + (0, chai_1.expect)(entity.prop("a")).to.equal("b"); + entity.unsetProp("a"); + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(entity.prop("a")).not.to.exist; + }); + it("toJSON converts to JSON", () => { + const entity = new DerivedInMemoryEntity({ _id: "123", type: "type" }); + (0, chai_1.expect)(JSON.stringify(entity.toJSON())).to.be.equal( + JSON.stringify({ _id: "123", schemaVersion: "2022.8.16" }), + ); + }); + it("jsonSchema returns correct registered schema", async () => { + (0, chai_1.expect)(DerivedInMemoryEntity.jsonSchema).to.be.an("object"); + (0, chai_1.expect)(DerivedInMemoryEntity.jsonSchema).to.have.nested.property( + "properties._id", + ); // check mix schemas + }); + it("jsonSchema validate", async () => { + const validEntity = new DerivedInMemoryEntity({ _id: "123", slug: "slug" }); + const invalidEntity = new DerivedInMemoryEntity({ _id: "123", slug: ["slug"] }); + (0, chai_1.expect)(validateEntity(validEntity)).to.be.true; + (0, chai_1.expect)(validateEntity(invalidEntity)).to.be.false; + }); + it("jsonSchema clean", async () => { + const config = { + _id: "123", + slug: "slug", + additional: "additional", + }; + const cleanConfig = new DerivedInMemoryEntity().clean({ ...config }); + (0, chai_1.expect)(cleanConfig).to.be.deep.equal({ + _id: "123", + slug: "slug", + schemaVersion: "2022.8.16", // schema's default value + }); + }); +}); diff --git a/tests/in_memory.tests.ts b/tests/js/in_memory.tests.ts similarity index 97% rename from tests/in_memory.tests.ts rename to tests/js/in_memory.tests.ts index e1759c1..7483df9 100644 --- a/tests/in_memory.tests.ts +++ b/tests/js/in_memory.tests.ts @@ -3,7 +3,7 @@ import { JSONSchema } from "@mat3ra/esse/lib/js/esse/utils"; import inMemoryEntitySchema from "@mat3ra/esse/lib/js/schema/in_memory_entity/base.json"; import { expect } from "chai"; -import { InMemoryEntity } from "../src/entity/in_memory"; +import { InMemoryEntity } from "../../src/js/entity/in_memory"; class DerivedInMemoryEntity extends InMemoryEntity { static readonly jsonSchema = inMemoryEntitySchema as JSONSchema; diff --git a/tests/js/mixin.flowchart.tests.d.ts b/tests/js/mixin.flowchart.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/mixin.flowchart.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/mixin.flowchart.tests.js b/tests/js/mixin.flowchart.tests.js new file mode 100644 index 0000000..77f8bf9 --- /dev/null +++ b/tests/js/mixin.flowchart.tests.js @@ -0,0 +1,87 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const entity_1 = require("../../src/js/entity"); + +const FlowchartEntity = (0, entity_1.FlowchartEntityMixin)(entity_1.InMemoryEntity); +const FlowchartItem = (0, entity_1.FlowchartItemMixin)(entity_1.InMemoryEntity); +function assertString(prop) { + (0, chai_1.expect)(prop).to.be.a("string"); + return typeof prop === "string"; +} +describe("Flowchart Mixins", () => { + it("flowchart item can be added", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + (0, chai_1.expect)(entity.units.length).to.be.equal(1); + }); + it("flowchart item can be added between two other units", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + (0, chai_1.expect)(entity.units[0].next).to.be.equal(entity.units[1].flowchartId); + const item = new FlowchartItem(); + entity.addUnit(item, 1); + (0, chai_1.expect)(entity.units[1].flowchartId).to.be.equal(item.flowchartId); + (0, chai_1.expect)(entity.units[1].next).to.be.equal(entity.units[2].flowchartId); + }); + it("flowchart item points to correct target after removal of the in-between unit", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + if (assertString(entity.units[1].flowchartId)) { + entity.removeUnit(entity.units[1].flowchartId); + } + (0, chai_1.expect)(entity.units[0].next).to.be.equal(entity.units[1].flowchartId); + }); + it("flowchart item points to correct target after removal of last unit", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + if (assertString(entity.units[2].flowchartId)) { + entity.removeUnit(entity.units[2].flowchartId); + } + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(entity.units[1].next).to.be.undefined; + }); + it("flowchart item can be removed", () => { + const entity = new FlowchartEntity(); + const item = new FlowchartItem(); + entity.addUnit(item); + entity.removeUnit(item.flowchartId); + (0, chai_1.expect)(entity.units.length).to.be.equal(0); + }); + it("flowchart item can be replaced between two other units", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + const unitsBeforeReplace = entity.units.length; + const item = new FlowchartItem(); + entity.replaceUnit(item, 1); + (0, chai_1.expect)(entity.units[1].flowchartId).to.be.equal(item.flowchartId); + (0, chai_1.expect)(entity.units.length).to.be.equal(unitsBeforeReplace); + }); + it("flowchart item can be accessed by flowchart Id", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + const item = new FlowchartItem(); + entity.addUnit(item); + const fetchedUnit = entity.getUnit(item.flowchartId); + (0, chai_1.expect)(fetchedUnit).to.be.instanceof(FlowchartItem); + (0, chai_1.expect)( + fetchedUnit === null || fetchedUnit === void 0 ? void 0 : fetchedUnit.flowchartId, + ).to.be.equal(item.flowchartId); + }); + it("flowchart item index can be found by flowchart Id", () => { + const entity = new FlowchartEntity(); + entity.addUnit(new FlowchartItem()); + entity.addUnit(new FlowchartItem()); + const item = new FlowchartItem(); + entity.addUnit(item); + const index = entity.getUnitIndexByFlowchartId(item.flowchartId); + (0, chai_1.expect)(index).to.be.equal(entity.units.length - 1); // last unit + }); +}); diff --git a/tests/mixin.flowchart.tests.ts b/tests/js/mixin.flowchart.tests.ts similarity index 99% rename from tests/mixin.flowchart.tests.ts rename to tests/js/mixin.flowchart.tests.ts index 775a12c..6a29fa8 100644 --- a/tests/mixin.flowchart.tests.ts +++ b/tests/js/mixin.flowchart.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { FlowchartEntityMixin, FlowchartItemMixin, InMemoryEntity } from "../src/entity"; +import { FlowchartEntityMixin, FlowchartItemMixin, InMemoryEntity } from "../../src/js/entity"; const FlowchartEntity = FlowchartEntityMixin(InMemoryEntity); diff --git a/tests/js/provider.tests.d.ts b/tests/js/provider.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/provider.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/provider.tests.js b/tests/js/provider.tests.js new file mode 100644 index 0000000..cd2ef4d --- /dev/null +++ b/tests/js/provider.tests.js @@ -0,0 +1,22 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const provider_1 = require("../../src/js/context/provider"); + +describe("ContextProvider", () => { + const minimal = { name: "name" }; + const data = { a: "test" }; + it("can be created", () => { + const provider = new provider_1.ContextProvider(minimal); + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(provider).to.exist; + }); + it("sets and gets data", () => { + const provider = new provider_1.ContextProvider(minimal); + provider.setData(data); + (0, chai_1.expect)(() => provider.getData()).to.throw("Not implemented."); + provider.setIsEdited(true); + (0, chai_1.expect)(JSON.stringify(provider.getData())).to.equal(JSON.stringify(data)); + (0, chai_1.expect)(() => provider.defaultData).to.throw("Not implemented."); + }); + // transform, yieldData, yieldDataForRendering +}); diff --git a/tests/provider.tests.ts b/tests/js/provider.tests.ts similarity index 92% rename from tests/provider.tests.ts rename to tests/js/provider.tests.ts index 3a38fee..d72b3ad 100644 --- a/tests/provider.tests.ts +++ b/tests/js/provider.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { ContextProvider } from "../src/context/provider"; +import { ContextProvider } from "../../src/js/context/provider"; describe("ContextProvider", () => { const minimal = { name: "name" }; diff --git a/tests/js/utils.d.ts b/tests/js/utils.d.ts new file mode 100644 index 0000000..2d5799c --- /dev/null +++ b/tests/js/utils.d.ts @@ -0,0 +1,4 @@ +import { AnyObject } from "../../src/js/entity/in_memory"; + +export declare function assertObject(prop: unknown): prop is AnyObject; +export declare function assertArray(prop: unknown): prop is unknown[]; diff --git a/tests/js/utils.js b/tests/js/utils.js new file mode 100644 index 0000000..39d91e4 --- /dev/null +++ b/tests/js/utils.js @@ -0,0 +1,14 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.assertArray = exports.assertObject = void 0; +const chai_1 = require("chai"); + +function assertObject(prop) { + (0, chai_1.expect)(prop).to.be.an("object"); + return Boolean(prop) && typeof prop === "object" && !Array.isArray(prop); +} +exports.assertObject = assertObject; +function assertArray(prop) { + (0, chai_1.expect)(prop).to.be.an("array"); + return Array.isArray(prop); +} +exports.assertArray = assertArray; diff --git a/tests/utils.ts b/tests/js/utils.ts similarity index 85% rename from tests/utils.ts rename to tests/js/utils.ts index 9533584..690bd24 100644 --- a/tests/utils.ts +++ b/tests/js/utils.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { AnyObject } from "../src/entity/in_memory"; +import { AnyObject } from "../../src/js/entity/in_memory"; export function assertObject(prop: unknown): prop is AnyObject { expect(prop).to.be.an("object"); diff --git a/tests/js/utils/class.tests.d.ts b/tests/js/utils/class.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/class.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/class.tests.js b/tests/js/utils/class.tests.js new file mode 100644 index 0000000..0939de2 --- /dev/null +++ b/tests/js/utils/class.tests.js @@ -0,0 +1,98 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable max-classes-per-file, class-methods-use-this */ +const chai_1 = require("chai"); +const index_1 = require("../../../src/js/entity/index"); +const class_1 = require("../../../src/js/utils/class"); + +class BaseEntity extends (0, index_1.RuntimeItemsMixin)(index_1.InMemoryEntity) { + baseMethod() { + return "base"; + } +} +class ExtendClassEntity extends (0, index_1.DefaultableMixin)(index_1.NamedInMemoryEntity) { + constructor(config, excluded = []) { + super(config); + (0, class_1.extendClass)(ExtendClassEntity, BaseEntity, excluded, [config]); + } + + baseMethod() { + return "derived"; + } +} +class BaseBetweenEntity extends index_1.NamedInMemoryEntity { + constructor(config) { + super(config); + this.instanceAttr = "base"; + this.instanceAttr = "base"; + } + + betweenMethod() { + return "base"; + } +} +BaseBetweenEntity.staticAttr = "base"; +class BetweenEntity extends BaseBetweenEntity { + constructor(config) { + super(config); + this.instanceAttr = "between"; + } + + betweenMethod() { + return "between"; + } +} +BetweenEntity.staticAttr = "between"; +class ExtendThisEntity extends (0, index_1.DefaultableMixin)(BetweenEntity) { + constructor(config) { + super(config); + (0, class_1.extendThis)(ExtendThisEntity, BaseEntity, config); + } + + baseMethod() { + return "derived"; + } +} +describe("extendClass", () => { + it("extends classes no excluded props", () => { + const obj = new ExtendClassEntity({}); + (0, chai_1.expect)(obj.baseMethod()).to.be.equal("base"); + }); + it("should support excluded props but doesnt", () => { + const obj = new ExtendClassEntity({}); + (0, chai_1.expect)(obj.baseMethod()).not.to.be.equal("derived"); + }); + it("should have results but doesnt", () => { + const obj = new ExtendClassEntity({ results: ["test"] }); + (0, chai_1.expect)(JSON.stringify(obj.results)).not.to.be.equal( + JSON.stringify([{ name: "test" }]), + ); + }); +}); +describe("extendThis", () => { + it("extends this prefer child method", () => { + const obj = new ExtendThisEntity({}); + (0, chai_1.expect)(obj.baseMethod()).to.be.equal("derived"); + }); + it("extends this support base mixins", () => { + const obj = new ExtendThisEntity({ results: ["test"] }); + (0, chai_1.expect)(JSON.stringify(obj.results)).to.be.equal( + JSON.stringify([{ name: "test" }]), + ); + }); + it("remembers intermediate methods", () => { + const base = new BaseBetweenEntity({}); + (0, chai_1.expect)(base.betweenMethod()).to.be.equal("base"); + const obj = new ExtendThisEntity({}); + (0, chai_1.expect)(obj.betweenMethod()).to.be.equal("between"); + }); + it("propagates instance attributes", () => { + const base = new BaseBetweenEntity({}); + (0, chai_1.expect)(base.instanceAttr).to.be.equal("base"); + const obj = new ExtendThisEntity({}); + (0, chai_1.expect)(obj.instanceAttr).to.be.equal("between"); + }); + it("propagates static attributes", () => { + (0, chai_1.expect)(BaseBetweenEntity.staticAttr).to.be.equal("base"); + (0, chai_1.expect)(ExtendThisEntity.staticAttr).to.be.equal("between"); + }); +}); diff --git a/tests/utils/class.tests.ts b/tests/js/utils/class.tests.ts similarity index 96% rename from tests/utils/class.tests.ts rename to tests/js/utils/class.tests.ts index ae4bcbb..27f41fa 100644 --- a/tests/utils/class.tests.ts +++ b/tests/js/utils/class.tests.ts @@ -6,8 +6,8 @@ import { InMemoryEntity, NamedInMemoryEntity, RuntimeItemsMixin, -} from "../../src/entity/index"; -import { extendClass, extendThis } from "../../src/utils/class"; +} from "../../../src/js/entity/index"; +import { extendClass, extendThis } from "../../../src/js/utils/class"; class BaseEntity extends RuntimeItemsMixin(InMemoryEntity) { baseMethod() { diff --git a/tests/js/utils/file.tests.d.ts b/tests/js/utils/file.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/file.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/file.tests.js b/tests/js/utils/file.tests.js new file mode 100644 index 0000000..e4fb1f5 --- /dev/null +++ b/tests/js/utils/file.tests.js @@ -0,0 +1,11 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const file_1 = require("../../../src/js/utils/file"); + +describe("file utilities", () => { + it("should create an object path from a file path", () => { + const thisFile = "/code.js/tests/utils/file.tests.js"; + const objectPath = (0, file_1.createObjectPathFromFilePath)(thisFile, "/code.js"); + (0, chai_1.expect)(objectPath).to.be.equal("['tests']['utils']['file.tests']"); + }); +}); diff --git a/tests/utils/file.tests.ts b/tests/js/utils/file.tests.ts similarity index 82% rename from tests/utils/file.tests.ts rename to tests/js/utils/file.tests.ts index e75180f..9f84bf3 100644 --- a/tests/utils/file.tests.ts +++ b/tests/js/utils/file.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { createObjectPathFromFilePath } from "../../src/utils/file"; +import { createObjectPathFromFilePath } from "../../../src/js/utils/file"; describe("file utilities", () => { it("should create an object path from a file path", () => { diff --git a/tests/js/utils/filter.tests.d.ts b/tests/js/utils/filter.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/filter.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/filter.tests.js b/tests/js/utils/filter.tests.js new file mode 100644 index 0000000..d8bc647 --- /dev/null +++ b/tests/js/utils/filter.tests.js @@ -0,0 +1,94 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const filter_1 = require("../../../src/js/utils/filter"); + +describe("entity filter", () => { + const entities = [ + { name: "A", path: "/root/entity/a" }, + { name: "B", path: "/root/entity/b" }, + { name: "C", path: "/root/entity/c" }, + { name: "D", path: "/root/entity/d" }, + ]; + it("should filter an entity list with paths", () => { + const filterObjects = [{ path: "/root/entity/b" }, { path: "/root/entity/c" }]; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: entities, + }); + const expected = [ + { name: "B", path: "/root/entity/b" }, + { name: "C", path: "/root/entity/c" }, + ]; + (0, chai_1.expect)(filtered).to.have.deep.members(expected); + }); + it("should filter an entity list with regular expressions", () => { + const filterObjects = [{ regex: /\/root\/entity\/[bc]/ }]; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: entities, + }); + const expected = [ + { name: "B", path: "/root/entity/b" }, + { name: "C", path: "/root/entity/c" }, + ]; + (0, chai_1.expect)(filtered).to.have.deep.members(expected); + }); + it("should filter an entity list with both paths and regular expressions", () => { + const filterObjects = [{ path: "/root/entity/b" }, { regex: /\/root\/entity\/[c]/ }]; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: entities, + }); + const expected = [ + { name: "B", path: "/root/entity/b" }, + { name: "C", path: "/root/entity/c" }, + ]; + (0, chai_1.expect)(filtered).to.have.deep.members(expected); + }); + it("should filter an entity list containing concatenated paths", () => { + const filterObjects = [{ path: "/root/entity/b" }, { path: "/root/entity/c" }]; + const multiPathEntities = [ + { name: "AB", path: "/root/entity/a::/root/entity/b" }, + { name: "BC", path: "/root/entity/b::/root/entity/c" }, + ]; + const multiPathSeparator = "::"; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: multiPathEntities, + multiPathSeparator, + }); + const expected = [{ name: "BC", path: "/root/entity/b::/root/entity/c" }]; + (0, chai_1.expect)(filtered).to.have.deep.members(expected); + }); + it("should filter an entity list containing concatenated paths using regex", () => { + const filterObjects = [{ path: "/root/entity/b" }, { regex: /\/root\/entity\/[c]/ }]; + const multiPathEntities = [ + { name: "AB", path: "/root/entity/a::/root/entity/b" }, + { name: "BC", path: "/root/entity/b::/root/entity/c" }, + ]; + const multiPathSeparator = "::"; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: multiPathEntities, + multiPathSeparator, + }); + const expected = [{ name: "BC", path: "/root/entity/b::/root/entity/c" }]; + (0, chai_1.expect)(filtered).to.have.deep.members(expected); + }); + it("should return empty list if empty filter object array is given", () => { + const filterObjects = []; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: entities, + }); + (0, chai_1.expect)(filtered).to.have.length(0); + }); + it("should return empty list if no filter object array is given", () => { + const filterObjects = undefined; + const filtered = (0, filter_1.filterEntityList)({ + filterObjects, + entitiesOrPaths: entities, + }); + (0, chai_1.expect)(filtered).to.have.length(0); + }); +}); diff --git a/tests/utils/filter.tests.ts b/tests/js/utils/filter.tests.ts similarity index 97% rename from tests/utils/filter.tests.ts rename to tests/js/utils/filter.tests.ts index d4b5d22..343f0e8 100644 --- a/tests/utils/filter.tests.ts +++ b/tests/js/utils/filter.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { filterEntityList, FilterObject } from "../../src/utils/filter"; +import { filterEntityList, FilterObject } from "../../../src/js/utils/filter"; describe("entity filter", () => { const entities = [ diff --git a/tests/js/utils/object.tests.d.ts b/tests/js/utils/object.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/object.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/object.tests.js b/tests/js/utils/object.tests.js new file mode 100644 index 0000000..e4573e9 --- /dev/null +++ b/tests/js/utils/object.tests.js @@ -0,0 +1,91 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const object_1 = require("../../../src/js/utils/object"); + +describe("flattenObject", () => { + it("serializes simple object", () => { + const obj = { + value: 1.0, + name: "p-norm", + degree: 2, + }; + const expectedObj = { "p-norm:degree=2": 1 }; + (0, chai_1.expect)(expectedObj).to.deep.equal((0, object_1.flattenObject)(obj)); + }); + it("serialize complex object", () => { + const obj = { + value: 1.0, + name: "p-norm", + extraProp: { + name: "zeta", + value: 6, + extraProp: { + name: "alpha", + value: 3, + veracity: 7, + }, + }, + }; + const expectedObj = { "p-norm:zeta=6:alpha=3:veracity=7": 1 }; + (0, chai_1.expect)(expectedObj).to.deep.equal((0, object_1.flattenObject)(obj)); + }); + it("throws error for wrong object", () => { + const obj = { + value: 1.0, + name: "p-norm", + degree: 2, + extraProperty: 1, + }; + (0, chai_1.expect)(() => { + (0, object_1.flattenObject)(obj); + }).to.throw(); + }); +}); +describe("mergeTerminalNodes", () => { + it("merges terminal nodes containing an array of strings", () => { + const treeStrings = { + level1: { + level2a: { + level3a: { + key1: ["a", "b", "c"], + }, + level3b: { + key2: ["d", "e", "f"], + }, + }, + }, + }; + const merged = (0, object_1.mergeTerminalNodes)(treeStrings); + (0, chai_1.expect)(merged).to.have.members(["a", "b", "c", "d", "e", "f"]); + }); + it("merges terminal nodes containing an array of objects", () => { + const treeObjects = { + level1: { + level2a: { + level3a: { + key1: [{ path: "a" }, { path: "b" }, { path: "c" }], + }, + level3b: { + key2: [{ path: "d" }, { path: "e" }, { path: "f" }], + }, + }, + }, + }; + const merged = (0, object_1.mergeTerminalNodes)(treeObjects); + (0, chai_1.expect)(merged).to.have.length(6); + (0, chai_1.expect)(merged.map((o) => o.path)).to.have.members([ + "a", + "b", + "c", + "d", + "e", + "f", + ]); + }); + it("should only merge objects", () => { + const array = [{ path: "a" }, { path: "b" }, { path: "c" }]; + // @ts-ignore + const merged = (0, object_1.mergeTerminalNodes)(array); + (0, chai_1.expect)(merged).to.have.deep.members(array); + }); +}); diff --git a/tests/utils/object.tests.ts b/tests/js/utils/object.tests.ts similarity index 96% rename from tests/utils/object.tests.ts rename to tests/js/utils/object.tests.ts index af0fd0e..6577d9f 100644 --- a/tests/utils/object.tests.ts +++ b/tests/js/utils/object.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { flattenObject, mergeTerminalNodes } from "../../src/utils/object"; +import { flattenObject, mergeTerminalNodes } from "../../../src/js/utils/object"; describe("flattenObject", () => { it("serializes simple object", () => { diff --git a/tests/js/utils/schemas.tests.d.ts b/tests/js/utils/schemas.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/schemas.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/schemas.tests.js b/tests/js/utils/schemas.tests.js new file mode 100644 index 0000000..7b1b31f --- /dev/null +++ b/tests/js/utils/schemas.tests.js @@ -0,0 +1,121 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-unused-expressions */ +// @ts-nocheck +/* eslint-disable no-unsafe-optional-chaining */ +const chai_1 = require("chai"); +const schemas_1 = require("../../../src/js/utils/schemas"); +const rjsf_schemas_1 = require("../fixtures/rjsf_schemas"); + +describe("RJSF schema", () => { + it("dependencies block can be created from tree", () => { + const dependencies = (0, schemas_1.buildDependencies)([rjsf_schemas_1.TREE_SIMPLE]); + const [aCase] = dependencies.dependencies.type.oneOf; + (0, chai_1.expect)(aCase.properties.subtype.enum).to.have.ordered.members(["b", "c"]); + (0, chai_1.expect)(aCase.properties.subtype.enumNames).to.have.ordered.members(["B", "C"]); + const [bCase, cCase] = aCase.dependencies.subtype.oneOf; + (0, chai_1.expect)(bCase.properties.subtype.enum).to.have.length(1); + (0, chai_1.expect)(bCase.properties.subsubtype.enum).to.have.ordered.members(["d", "e"]); + (0, chai_1.expect)(bCase.properties.subsubtype.enumNames).to.have.ordered.members([ + "D", + "E", + ]); + (0, chai_1.expect)(bCase).to.not.have.property("dependencies"); + (0, chai_1.expect)(cCase.properties.subtype.enum).to.have.length(1); + (0, chai_1.expect)(cCase.properties.subsubtype.enum).to.have.ordered.members(["f", "g"]); + (0, chai_1.expect)(cCase.properties.subsubtype.enumNames).to.have.ordered.members([ + "F", + "G", + ]); + (0, chai_1.expect)(cCase).to.not.have.property("dependencies"); + }); + it("should create static options in dependency block if present in node", () => { + const dependencies = (0, schemas_1.buildDependencies)([rjsf_schemas_1.TREE_ADVANCED]); + const [aCase] = dependencies.dependencies.type.oneOf; + (0, chai_1.expect)(aCase.properties.staticA2.enum).to.have.members([true]); + (0, chai_1.expect)(aCase.properties.staticA2.enumNames).to.have.members(["true"]); + const [bCase, cCase] = aCase.dependencies.subtype.oneOf; + (0, chai_1.expect)(bCase.properties).not.to.haveOwnProperty("staticC"); + (0, chai_1.expect)(cCase.properties.staticC.enum).to.have.members(["static_c"]); + (0, chai_1.expect)(cCase.properties.staticC.enumNames).to.have.members(["static_c"]); + }); + it("should create static options from terminal nodes of dependency tree", () => { + const dependencies = (0, schemas_1.buildDependencies)([ + rjsf_schemas_1.TREE_STATIC_TERMINAL, + ]); + const [typeCase] = dependencies.dependencies.type.oneOf; + (0, chai_1.expect)(typeCase.properties.type.enum).to.have.members(["a"]); + (0, chai_1.expect)(typeCase.properties.subtype.enum).to.have.members(["b", "c"]); + const [bCase, cCase] = typeCase.dependencies.subtype.oneOf; + (0, chai_1.expect)(bCase.properties.subtype.enum).to.have.members(["b"]); + (0, chai_1.expect)(cCase.properties.subtype.enum).to.have.members(["c"]); + (0, chai_1.expect)(cCase.properties.subsubtype.enum).to.have.members(["c1", "c2"]); + const [c1Case, c2Case] = cCase.dependencies.subsubtype.oneOf; + (0, chai_1.expect)(c1Case).to.not.be.undefined; + (0, chai_1.expect)(c1Case.properties.subsubtype.enum).to.have.members(["c1"]); + (0, chai_1.expect)(c1Case.properties.static.enum).to.have.members([ + "static1", + "static2", + "static3", + ]); + (0, chai_1.expect)(c2Case).to.not.be.undefined; + (0, chai_1.expect)(c2Case.properties.subsubtype.enum).to.have.members(["c2"]); + }); + it("can be created with dependencies from schema", () => { + const rjsfSchema = (0, schemas_1.getSchemaWithDependencies)({ + schema: rjsf_schemas_1.EXAMPLE_SCHEMA, + nodes: [rjsf_schemas_1.TREE_SIMPLE], + }); + (0, chai_1.expect)(rjsfSchema.type).to.be.eql(rjsf_schemas_1.EXAMPLE_SCHEMA.type); + (0, chai_1.expect)(rjsfSchema.properties).to.be.eql( + rjsf_schemas_1.EXAMPLE_SCHEMA.properties, + ); + (0, chai_1.expect)(rjsfSchema).to.have.property("dependencies"); + }); + it("enum and enumNames can be added to schema properties", () => { + const rjsfSchema = (0, schemas_1.getSchemaWithDependencies)({ + schema: rjsf_schemas_1.EXAMPLE_SCHEMA, + nodes: [rjsf_schemas_1.TREE_SIMPLE], + modifyProperties: true, + }); + (0, chai_1.expect)(rjsfSchema.type).to.be.eql(rjsf_schemas_1.EXAMPLE_SCHEMA.type); + (0, chai_1.expect)(rjsfSchema.properties.type).to.have.property("enum"); + (0, chai_1.expect)(rjsfSchema.properties.type.enum).to.be.eql(["a"]); + (0, chai_1.expect)(rjsfSchema.properties.type).to.have.property("enumNames"); + (0, chai_1.expect)(rjsfSchema.properties.type.enumNames).to.be.eql(["A"]); + (0, chai_1.expect)(rjsfSchema).to.have.property("dependencies"); + }); + it("should correctly create dependencies from an uneven tree", () => { + const dependencies = (0, schemas_1.buildDependencies)([rjsf_schemas_1.UNEVEN_TREE]); + const [typeCase] = dependencies.dependencies.type.oneOf; + (0, chai_1.expect)(typeCase.properties.type.enum).to.have.members(["a"]); + (0, chai_1.expect)(typeCase.properties.subtype.enum).to.have.members(["b", "c", "d"]); + const [bCase, cCase, dCase] = typeCase.dependencies.subtype.oneOf; + (0, chai_1.expect)(bCase.properties.subtype.enum).to.have.members(["b"]); + (0, chai_1.expect)(cCase.properties.subtype.enum).to.have.members(["c"]); + (0, chai_1.expect)(cCase.properties.subsubtype.enum).to.have.members(["c1", "c2"]); + (0, chai_1.expect)(dCase.properties.subtype.enum).to.have.members(["d"]); + (0, chai_1.expect)(dCase.properties.subsubtype.enum).to.have.members(["d1"]); + const [xCase] = dCase.dependencies.subsubtype.oneOf; + (0, chai_1.expect)(xCase.properties.subsubtype.enum).to.have.members(["d1"]); + (0, chai_1.expect)(xCase.properties.propX.enum).to.have.members(["x"]); + }); +}); +describe("Schema utility", () => { + const schemas = [ + ["string", { type: "string" }], + ["integer", { type: "integer" }], + ["number", { type: "number" }], + ["object", { type: "object" }], + ["array", { type: "array" }], + ]; + const objSchemaNoType = { properties: { name: { type: "string" } } }; + const arraySchemaNoType = { items: { type: "number" } }; + it("type can be determined correctly", () => { + schemas.forEach(([type, schema]) => { + const currentType = (0, schemas_1.typeofSchema)(schema); + (0, chai_1.expect)(currentType).to.be.equal(type); + }); + (0, chai_1.expect)((0, schemas_1.typeofSchema)(objSchemaNoType)).to.be.equal("object"); + (0, chai_1.expect)((0, schemas_1.typeofSchema)(arraySchemaNoType)).to.be.equal("array"); + }); +}); diff --git a/tests/utils/schemas.tests.ts b/tests/js/utils/schemas.tests.ts similarity index 99% rename from tests/utils/schemas.tests.ts rename to tests/js/utils/schemas.tests.ts index 0904868..e260367 100644 --- a/tests/utils/schemas.tests.ts +++ b/tests/js/utils/schemas.tests.ts @@ -7,7 +7,7 @@ import { buildDependencies, getSchemaWithDependencies, typeofSchema, -} from "../../src/utils/schemas"; +} from "../../../src/js/utils/schemas"; import { EXAMPLE_SCHEMA, TREE_ADVANCED, diff --git a/tests/js/utils/str.tests.d.ts b/tests/js/utils/str.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/str.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/str.tests.js b/tests/js/utils/str.tests.js new file mode 100644 index 0000000..cbe30cb --- /dev/null +++ b/tests/js/utils/str.tests.js @@ -0,0 +1,70 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const utils_1 = require("../../../src/js/utils"); + +describe("str: renderTextWithSubstitutes", () => { + it("should substitute flat properties", () => { + const template = "Hello {{ user }}!"; + const data = { user: "user001" }; + const substitutionMap = { user001: "John Doe" }; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello John Doe!"); + }); + it("should substitute nested properties", () => { + const template = "Hello {{ parameters.user }}!"; + const data = { parameters: { user: "user001" } }; + const substitutionMap = { user001: "John Doe" }; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello John Doe!"); + }); + it("should leave properties without substitution unchanged", () => { + const template = "Hello {{ user }}!"; + const data = { user: "user001" }; + const substitutionMap = {}; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello user001!"); + }); + it("should return the original string if the template does not contain any variable", () => { + const template = "Hello world!"; + const data = { user: "user001" }; + const substitutionMap = {}; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello world!"); + }); + it("should return the an empty string if the template is undefined", () => { + const template = undefined; + const data = { user: "user001" }; + const substitutionMap = {}; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal(""); + }); + it("should replace the template variable with an empty string if the value is falsy", () => { + const template = "Hello {{ user }}!"; + const data = { user: null }; + const substitutionMap = {}; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello !"); + }); + it("should be able to access nested elements in template notation", () => { + const template = "Hello {{ user }} of {{ array[1]['planet'] }}!"; + const data = { user: "user001", array: [{ planet: "A" }, { planet: "B" }] }; + const substitutionMap = { + A: "Earth", + B: "Mars", + }; + const result = (0, utils_1.renderTextWithSubstitutes)(template, data, substitutionMap); + (0, chai_1.expect)(result).to.be.equal("Hello user001 of Mars!"); + }); +}); +describe("str: findPreviousVersion", () => { + const versions = ["5.4.2", "3.2", "6.2", "4", "7.2.1"]; + it("should find a previous semantic version", () => { + const previous = (0, utils_1.findPreviousVersion)(versions, "5.2"); + (0, chai_1.expect)(previous).to.be.equal("4"); + }); + it("should return undefined if no previous version is found", () => { + const previous = (0, utils_1.findPreviousVersion)(versions, "2"); + // eslint-disable-next-line no-unused-expressions + (0, chai_1.expect)(previous).to.be.undefined; + }); +}); diff --git a/tests/utils/str.tests.ts b/tests/js/utils/str.tests.ts similarity index 99% rename from tests/utils/str.tests.ts rename to tests/js/utils/str.tests.ts index 84aeae7..14b0ab9 100644 --- a/tests/utils/str.tests.ts +++ b/tests/js/utils/str.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { findPreviousVersion, renderTextWithSubstitutes } from "../../src/utils"; +import { findPreviousVersion, renderTextWithSubstitutes } from "../../../src/js/utils"; describe("str: renderTextWithSubstitutes", () => { it("should substitute flat properties", () => { diff --git a/tests/js/utils/tree.tests.d.ts b/tests/js/utils/tree.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/tree.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/tree.tests.js b/tests/js/utils/tree.tests.js new file mode 100644 index 0000000..5ade22f --- /dev/null +++ b/tests/js/utils/tree.tests.js @@ -0,0 +1,34 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const utils_1 = require("../../../src/js/utils"); + +describe("Tree data structure", () => { + const TREE = { + path: "/A", + children: [ + { + path: "/A/B", + children: [ + { + path: "/A/B/C", + }, + ], + }, + { + path: "/A/D", + }, + ], + }; + it("map", () => { + const [mappedTree] = (0, utils_1.mapTree)([TREE], (node) => { + return { ...node, foo: "bar" }; + }); + (0, chai_1.expect)(mappedTree).to.have.property("foo", "bar"); + // @ts-ignore + (0, chai_1.expect)(mappedTree.children[0]).to.have.property("foo", "bar"); + // @ts-ignore + (0, chai_1.expect)(mappedTree.children[0].children[0]).to.have.property("foo", "bar"); + // @ts-ignore + (0, chai_1.expect)(mappedTree.children[1]).to.have.property("foo", "bar"); + }); +}); diff --git a/tests/utils/tree.tests.ts b/tests/js/utils/tree.tests.ts similarity index 94% rename from tests/utils/tree.tests.ts rename to tests/js/utils/tree.tests.ts index 90d124a..dc3a793 100644 --- a/tests/utils/tree.tests.ts +++ b/tests/js/utils/tree.tests.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { mapTree } from "../../src/utils"; +import { mapTree } from "../../../src/js/utils"; describe("Tree data structure", () => { const TREE = { diff --git a/tests/js/utils/utils.tests.d.ts b/tests/js/utils/utils.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/utils.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/utils.tests.js b/tests/js/utils/utils.tests.js new file mode 100644 index 0000000..4368375 --- /dev/null +++ b/tests/js/utils/utils.tests.js @@ -0,0 +1,34 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-unused-expressions */ +const chai_1 = require("chai"); +const clone_1 = require("../../../src/js/utils/clone"); +const url_1 = require("../../../src/js/utils/url"); + +describe("deepClone", () => { + const obj = { + number: 1.0, + string: "test", + array: [1.0], + object: { a: "b" }, + }; + it("clones an object", () => { + const clone = (0, clone_1.deepClone)(obj); + (0, chai_1.expect)(clone).to.deep.equal(obj); + (0, chai_1.expect)(clone); + }); + it("deep clones", () => { + const clone = (0, clone_1.deepClone)(obj); + (0, chai_1.expect)(clone).to.haveOwnProperty("object"); + delete obj.object; + const other = (0, clone_1.deepClone)(obj); + (0, chai_1.expect)(other).not.to.haveOwnProperty("object"); + }); +}); +describe("containsEncodedComponents", () => { + const decodedComponent = "a test with // special = characters?"; + const encodedComponent = encodeURIComponent(decodedComponent); + it("identifies whether a string is URL encoded", () => { + (0, chai_1.expect)((0, url_1.containsEncodedComponents)(encodedComponent)).to.be.true; + (0, chai_1.expect)((0, url_1.containsEncodedComponents)(decodedComponent)).to.be.false; + }); +}); diff --git a/tests/utils/utils.tests.ts b/tests/js/utils/utils.tests.ts similarity index 90% rename from tests/utils/utils.tests.ts rename to tests/js/utils/utils.tests.ts index e157c6b..4d6a156 100644 --- a/tests/utils/utils.tests.ts +++ b/tests/js/utils/utils.tests.ts @@ -1,8 +1,8 @@ /* eslint-disable no-unused-expressions */ import { expect } from "chai"; -import { deepClone } from "../../src/utils/clone"; -import { containsEncodedComponents } from "../../src/utils/url"; +import { deepClone } from "../../../src/js/utils/clone"; +import { containsEncodedComponents } from "../../../src/js/utils/url"; interface TestObject { number: number; diff --git a/tests/js/utils/yaml.combine.tests.d.ts b/tests/js/utils/yaml.combine.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.combine.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.combine.tests.js b/tests/js/utils/yaml.combine.tests.js new file mode 100644 index 0000000..8b00717 --- /dev/null +++ b/tests/js/utils/yaml.combine.tests.js @@ -0,0 +1,122 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable no-unused-expressions */ +// @ts-nocheck +const JSONSchemasInterfaceServer_1 = __importDefault( + require("@mat3ra/esse/lib/js/esse/JSONSchemasInterfaceServer"), +); +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const lodash_1 = __importDefault(require("lodash")); +const path_1 = __importDefault(require("path")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const combineSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([ + yaml_1.combineType, + yaml_1.esseType, +]); +describe("YAML tag: !combine", () => { + let yamlFixture, parsed; + before(() => { + JSONSchemasInterfaceServer_1.default.setSchemaFolder( + path_1.default.join(__dirname, "./../fixtures/json/example"), + ); + yamlFixture = fs_1.default.readFileSync(enums_1.YAML_COMBINE_FILE, "utf8"); + parsed = js_yaml_1.default.load(yamlFixture, { schema: combineSchema }); + }); + it("should correctly parse a custom !combine tag with forEach and config keys", () => { + const expectedResult = [ + { name: "mytest", a: 1, b: 3, c: 5 }, + { name: "mytest", a: 1, b: 4, c: 5 }, + { name: "mytest", a: 2, b: 3, c: 5 }, + { name: "mytest", a: 2, b: 4, c: 5 }, + ]; + (0, chai_1.expect)(parsed.case1).to.have.deep.members(expectedResult); + }); + it("should correctly parse a custom !combine tag with only a name key", () => { + const expectedResult = [{ name: "mytest" }]; + (0, chai_1.expect)(parsed.case2).to.have.deep.members(expectedResult); + }); + it("should correctly parse a custom !combine tag with forEach key and no values", () => { + const expectedResult = [{ name: "mytest" }]; + (0, chai_1.expect)(parsed.case3).to.have.deep.members(expectedResult); + }); + it("should correctly parse a custom !combine tag with an empty forEach key and a config key", () => { + const expectedResult = [{ name: "mytest", c: 5 }]; + (0, chai_1.expect)(parsed.case4).to.have.deep.members(expectedResult); + }); + it("should correctly generate name based on template", () => { + const expectedResult = [ + { name: "A1 with B2 and C5", a: 1, b: "two", c: 5 }, + { name: "A1 with B4 and C5", a: 1, b: "four", c: 5 }, + ]; + (0, chai_1.expect)(parsed.case5).to.have.deep.members(expectedResult); + }); + it("should correctly parse a custom !combine tag with additional property", () => { + const expectedResult = [ + { name: "mytest", a: 1, b: 3 }, + { name: "mytest", a: 1, b: 4 }, + { name: "additional property", x: 7 }, + ]; + (0, chai_1.expect)(parsed.case6).to.have.deep.members(expectedResult); + }); + it("should correctly parse a custom !combine tag with additional property from !combine tag", () => { + const expectedResult = [ + { name: "mytest", a: 1, b: 3 }, + { name: "mytest", a: 1, b: 4 }, + { name: "additional property", x: 7, y: 9 }, + { name: "additional property", x: 8, y: 9 }, + ]; + (0, chai_1.expect)(parsed.case7).to.have.deep.members(expectedResult); + }); + it("should create an additional config when falsy parameter is provided", () => { + const expectedResult = [ + { name: "A1 with B2", a: 1, b: "two" }, + { name: "A1 with B4", a: 1, b: "four" }, + { name: "A1", a: 1 }, + ]; + (0, chai_1.expect)(parsed.case8).to.have.deep.members(expectedResult); + }); + it("should create all combinations of n optional parameters", () => { + const expectedResult = [ + { name: "optional params", a: 1 }, + { name: "optional params", a: 1, b: 2 }, + { name: "optional params", a: 1, b: 3 }, + { name: "optional params", a: 1, c: 4 }, + { name: "optional params", a: 1, b: 2, c: 4 }, + { name: "optional params", a: 1, b: 3, c: 4 }, + ]; + (0, chai_1.expect)(parsed.case9).to.have.deep.members(expectedResult); + }); + it("should allow to exclude certain parameter-specified combinations", () => { + const expectedResult = [{ name: "ignore test", a: { c: 3 }, d: 4 }]; + (0, chai_1.expect)(parsed.case10).to.have.deep.members(expectedResult); + }); + it("should use the push action to add value to an array parameter", () => { + const expectedResult = [ + { name: "push test", units: [{ a: 1 }, { b: 4 }] }, + { name: "push test", units: [{ a: 2 }, { b: 4 }] }, + { name: "push test", units: [{ a: 3 }, { b: 4 }] }, + { name: "push test", units: [{ a: 1 }, { b: 5 }] }, + { name: "push test", units: [{ a: 2 }, { b: 5 }] }, + { name: "push test", units: [{ a: 3 }, { b: 5 }] }, + ]; + // sort units before comparing + parsed.case11.forEach((c) => (c.units = lodash_1.default.sortBy(c.units, ["a", "b"]))); + expectedResult.forEach((c) => (c.units = lodash_1.default.sortBy(c.units, ["a", "b"]))); + (0, chai_1.expect)(parsed.case11).to.have.deep.members(expectedResult); + }); + it("should use cloned objects when pushing to array", () => { + const [config1, config2] = parsed.case12; + // deleting property in one should not affect the other + delete config1.units[1].schema; + (0, chai_1.expect)(config1.units[1].schema).to.be.undefined; + (0, chai_1.expect)(config2.units[1].schema).not.to.be.undefined; + }); +}); diff --git a/tests/utils/yaml.combine.tests.ts b/tests/js/utils/yaml.combine.tests.ts similarity index 98% rename from tests/utils/yaml.combine.tests.ts rename to tests/js/utils/yaml.combine.tests.ts index 536cb87..f8cf836 100644 --- a/tests/utils/yaml.combine.tests.ts +++ b/tests/js/utils/yaml.combine.tests.ts @@ -7,7 +7,7 @@ import yaml from "js-yaml"; import lodash from "lodash"; import path from "path"; -import { combineType, esseType } from "../../src/utils/yaml"; +import { combineType, esseType } from "../../../src/js/utils/yaml"; import { YAML_COMBINE_FILE } from "../enums"; const combineSchema = yaml.DEFAULT_SCHEMA.extend([combineType, esseType]); diff --git a/tests/js/utils/yaml.concatString.tests.d.ts b/tests/js/utils/yaml.concatString.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.concatString.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.concatString.tests.js b/tests/js/utils/yaml.concatString.tests.js new file mode 100644 index 0000000..9c35266 --- /dev/null +++ b/tests/js/utils/yaml.concatString.tests.js @@ -0,0 +1,31 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const concatStringSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.concatStringType]); +describe("YAML tag: !concatString", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_CONCAT_STRING_FILE, "utf8"); + it("should concatenate two strings", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: concatStringSchema }); + const expected = "Hello world!"; + (0, chai_1.expect)(parsed.case1).to.be.eql(expected); + }); + it("should return a string if there is only a single item", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: concatStringSchema }); + const expected = "Hello"; + (0, chai_1.expect)(parsed.case2).to.be.eql(expected); + }); + it("should return an empty string if the array is empty", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: concatStringSchema }); + const expected = ""; + (0, chai_1.expect)(parsed.case3).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.concatString.tests.ts b/tests/js/utils/yaml.concatString.tests.ts similarity index 94% rename from tests/utils/yaml.concatString.tests.ts rename to tests/js/utils/yaml.concatString.tests.ts index 7f83e30..25b794a 100644 --- a/tests/utils/yaml.concatString.tests.ts +++ b/tests/js/utils/yaml.concatString.tests.ts @@ -2,7 +2,7 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { concatStringType } from "../../src/utils/yaml"; +import { concatStringType } from "../../../src/js/utils/yaml"; import { YAML_CONCAT_STRING_FILE } from "../enums"; const concatStringSchema = yaml.DEFAULT_SCHEMA.extend([concatStringType]); diff --git a/tests/js/utils/yaml.esse.tests.d.ts b/tests/js/utils/yaml.esse.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.esse.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.esse.tests.js b/tests/js/utils/yaml.esse.tests.js new file mode 100644 index 0000000..f54de41 --- /dev/null +++ b/tests/js/utils/yaml.esse.tests.js @@ -0,0 +1,58 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +// @ts-nocheck +const JSONSchemasInterfaceServer_1 = __importDefault( + require("@mat3ra/esse/lib/js/esse/JSONSchemasInterfaceServer"), +); +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const path_1 = __importDefault(require("path")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const yamlSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.esseType]); +describe("YAML tag: !esse", () => { + let yamlFixture, parsed; + before(() => { + JSONSchemasInterfaceServer_1.default.setSchemaFolder( + path_1.default.join(__dirname, "./../fixtures/json/example"), + ); + yamlFixture = fs_1.default.readFileSync(enums_1.YAML_ESSE_FILE, "utf8"); + parsed = js_yaml_1.default.load(yamlFixture, { schema: yamlSchema }); + }); + it("should correctly parse a custom !esse tag and return ESSE schema", () => { + const expected = { + $id: "core/primitive/scalar", + $schema: "http://json-schema.org/draft-07/schema#", + title: "scalar schema", + type: "object", + required: ["value"], + properties: { + value: { + type: "number", + }, + }, + }; + (0, chai_1.expect)(parsed.case1).to.eql(expected); + }); + it("should return the original data when an error occurs", () => { + (0, chai_1.expect)(parsed.case2).to.be.equal("non-existent-schema-id"); + }); + it("should parse a custom !esse tag and return a value from the ESSE schema", () => { + const expected = ["kbar", "pa"]; + (0, chai_1.expect)(parsed.case3).to.have.deep.members(expected); + }); + it("should correctly return nested value from esse schema", () => { + const expected = "array containing values of x Axis"; + (0, chai_1.expect)(parsed.case4).to.be.eql(expected); + }); + it("should correctly return array item from esse schema", () => { + const expected = "yDataSeries"; + (0, chai_1.expect)(parsed.case5).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.esse.tests.ts b/tests/js/utils/yaml.esse.tests.ts similarity index 97% rename from tests/utils/yaml.esse.tests.ts rename to tests/js/utils/yaml.esse.tests.ts index 2accca4..1a72bb5 100644 --- a/tests/utils/yaml.esse.tests.ts +++ b/tests/js/utils/yaml.esse.tests.ts @@ -5,7 +5,7 @@ import fs from "fs"; import yaml from "js-yaml"; import path from "path"; -import { esseType } from "../../src/utils/yaml"; +import { esseType } from "../../../src/js/utils/yaml"; import { YAML_ESSE_FILE } from "../enums"; const yamlSchema = yaml.DEFAULT_SCHEMA.extend([esseType]); diff --git a/tests/js/utils/yaml.flatten.tests.d.ts b/tests/js/utils/yaml.flatten.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.flatten.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.flatten.tests.js b/tests/js/utils/yaml.flatten.tests.js new file mode 100644 index 0000000..d540b96 --- /dev/null +++ b/tests/js/utils/yaml.flatten.tests.js @@ -0,0 +1,21 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const flattenSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.flattenType]); +describe("YAML tag: !flatten", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_FLATTEN_FILE, "utf8"); + it("should convert an array of arrays into a flattened array", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: flattenSchema }); + const expected = ["a", "b", "c", "d", "e", "f"]; + (0, chai_1.expect)(parsed.case1).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.flatten.tests.ts b/tests/js/utils/yaml.flatten.tests.ts similarity index 91% rename from tests/utils/yaml.flatten.tests.ts rename to tests/js/utils/yaml.flatten.tests.ts index 3ef17bf..5431ff1 100644 --- a/tests/utils/yaml.flatten.tests.ts +++ b/tests/js/utils/yaml.flatten.tests.ts @@ -2,7 +2,7 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { flattenType } from "../../src/utils/yaml"; +import { flattenType } from "../../../src/js/utils/yaml"; import { YAML_FLATTEN_FILE } from "../enums"; const flattenSchema = yaml.DEFAULT_SCHEMA.extend([flattenType]); diff --git a/tests/js/utils/yaml.include.tests.d.ts b/tests/js/utils/yaml.include.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.include.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.include.tests.js b/tests/js/utils/yaml.include.tests.js new file mode 100644 index 0000000..b47b28d --- /dev/null +++ b/tests/js/utils/yaml.include.tests.js @@ -0,0 +1,33 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +// @ts-nocheck +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const includeSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.includeType]); +describe("YAML tag: !include", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_INCLUDE_FILE, "utf8"); + it("should correctly include content from another Yaml file", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: includeSchema }); + const expected = { + here: "original content", + there: ["run", "stop", "pause"], + }; + (0, chai_1.expect)(parsed.case1).to.be.eql(expected); + }); + it("should return the original data when an error occurs", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: includeSchema }); + const expected = { + here: "original content", + there: "nonexistent_file.txt", + }; + (0, chai_1.expect)(parsed.case2).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.include.tests.ts b/tests/js/utils/yaml.include.tests.ts similarity index 93% rename from tests/utils/yaml.include.tests.ts rename to tests/js/utils/yaml.include.tests.ts index b79e2d8..31b9870 100644 --- a/tests/utils/yaml.include.tests.ts +++ b/tests/js/utils/yaml.include.tests.ts @@ -3,7 +3,8 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { includeType } from "../../src/utils/yaml"; +import { includeType } from "../../../src/js/utils/yaml"; +// @ts-ignore import { YAML_INCLUDE_FILE } from "../enums"; const includeSchema = yaml.DEFAULT_SCHEMA.extend([includeType]); diff --git a/tests/js/utils/yaml.listToString.tests.d.ts b/tests/js/utils/yaml.listToString.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.listToString.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.listToString.tests.js b/tests/js/utils/yaml.listToString.tests.js new file mode 100644 index 0000000..29adce0 --- /dev/null +++ b/tests/js/utils/yaml.listToString.tests.js @@ -0,0 +1,33 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +// @ts-nocheck +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const includeSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.listToStringType]); +describe("YAML tag: !listToString", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_LIST_TO_STRING_FILE, "utf8"); + it("should correctly concatenate content from list to string", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: includeSchema }); + const expected = { + here: "original content", + there: "onetwo", + }; + (0, chai_1.expect)(parsed.case1).to.be.eql(expected); + }); + it("should correctly filter out and concatenate only strings from list", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: includeSchema }); + const expected = { + here: "original content", + there: "onetwo", + }; + (0, chai_1.expect)(parsed.case2).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.listToString.tests.ts b/tests/js/utils/yaml.listToString.tests.ts similarity index 93% rename from tests/utils/yaml.listToString.tests.ts rename to tests/js/utils/yaml.listToString.tests.ts index 94e328c..4a79ee6 100644 --- a/tests/utils/yaml.listToString.tests.ts +++ b/tests/js/utils/yaml.listToString.tests.ts @@ -3,7 +3,7 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { listToStringType } from "../../src/utils/yaml"; +import { listToStringType } from "../../../src/js/utils/yaml"; import { YAML_LIST_TO_STRING_FILE } from "../enums"; const includeSchema = yaml.DEFAULT_SCHEMA.extend([listToStringType]); diff --git a/tests/js/utils/yaml.parameter.tests.d.ts b/tests/js/utils/yaml.parameter.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.parameter.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.parameter.tests.js b/tests/js/utils/yaml.parameter.tests.js new file mode 100644 index 0000000..5baa7b7 --- /dev/null +++ b/tests/js/utils/yaml.parameter.tests.js @@ -0,0 +1,61 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +// @ts-nocheck +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const parameterSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.parameterType]); +describe("YAML tag: !parameter", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_PARAMETER_FILE, "utf8"); + it("should correctly parse a custom !parameter tag with a key and values", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case1).to.be.eql({ key: "some.key", values: ["a", "b", "c"] }); + }); + it("should correctly parse a custom !parameter tag with a ref", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case2).to.be.eql({ + key: "job.workflow", + values: ["run", "stop", "pause"], + }); + }); + it("should correctly parse a custom !parameter tag with a ref and exclude", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case3).to.be.eql({ key: "workflow", values: ["stop", "pause"] }); + }); + it("should correctly parse a custom !parameter tag with a ref and exclude using a regular expression", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case4).to.be.eql({ key: "job.workflow", values: ["stop"] }); + }); + it("should return the original data when an error occurs", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case5).to.be.eql({ + key: "error.key", + ref: "non_existent_file.yaml", + }); + }); + it("should add null to values array when isOptional is true", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case6).to.be.eql({ + key: "some.key", + values: ["a", "b", "c", null], + }); + }); + it("should exclude values using regex and add null for optional parameters", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case7).to.be.eql({ key: "some.key", values: ["a", "c", null] }); + }); + it("should merge values with locally defined items and arrays", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: parameterSchema }); + (0, chai_1.expect)(parsed.case8).to.be.eql({ + key: "merged", + values: ["a", "b", "c", "d", "e"], + }); + }); +}); diff --git a/tests/utils/yaml.parameter.tests.ts b/tests/js/utils/yaml.parameter.tests.ts similarity index 97% rename from tests/utils/yaml.parameter.tests.ts rename to tests/js/utils/yaml.parameter.tests.ts index 6c822aa..25891d3 100644 --- a/tests/utils/yaml.parameter.tests.ts +++ b/tests/js/utils/yaml.parameter.tests.ts @@ -3,7 +3,8 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { parameterType } from "../../src/utils/yaml"; +import { parameterType } from "../../../src/js/utils/yaml"; +// @ts-ignore import { YAML_PARAMETER_FILE } from "../enums"; const parameterSchema = yaml.DEFAULT_SCHEMA.extend([parameterType]); diff --git a/tests/js/utils/yaml.readFile.tests.d.ts b/tests/js/utils/yaml.readFile.tests.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/tests/js/utils/yaml.readFile.tests.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/tests/js/utils/yaml.readFile.tests.js b/tests/js/utils/yaml.readFile.tests.js new file mode 100644 index 0000000..ef07338 --- /dev/null +++ b/tests/js/utils/yaml.readFile.tests.js @@ -0,0 +1,22 @@ +const __importDefault = + (this && this.__importDefault) || + function (mod) { + return mod && mod.__esModule ? mod : { default: mod }; + }; +Object.defineProperty(exports, "__esModule", { value: true }); +const chai_1 = require("chai"); +const fs_1 = __importDefault(require("fs")); +const js_yaml_1 = __importDefault(require("js-yaml")); +const yaml_1 = require("../../../src/js/utils/yaml"); +const enums_1 = require("../enums"); + +const readFileSchema = js_yaml_1.default.DEFAULT_SCHEMA.extend([yaml_1.readFileType]); +describe("YAML tag: !readFile", () => { + const yamlFixture = fs_1.default.readFileSync(enums_1.YAML_READFILE_FILE, "utf8"); + it("should read contents of a file into a string", () => { + const parsed = js_yaml_1.default.load(yamlFixture, { schema: readFileSchema }); + const expected = "Example text\nwith linebreaks.\n"; + (0, chai_1.expect)(parsed.case1).to.be.a("string"); + (0, chai_1.expect)(parsed.case1).to.be.eql(expected); + }); +}); diff --git a/tests/utils/yaml.readFile.tests.ts b/tests/js/utils/yaml.readFile.tests.ts similarity index 89% rename from tests/utils/yaml.readFile.tests.ts rename to tests/js/utils/yaml.readFile.tests.ts index c04c4ac..8b83e97 100644 --- a/tests/utils/yaml.readFile.tests.ts +++ b/tests/js/utils/yaml.readFile.tests.ts @@ -2,7 +2,8 @@ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; -import { readFileType } from "../../src/utils/yaml"; +import { readFileType } from "../../../src/js/utils/yaml"; +// @ts-ignore import { YAML_READFILE_FILE } from "../enums"; const readFileSchema = yaml.DEFAULT_SCHEMA.extend([readFileType]); diff --git a/tests/py/__init__.py b/tests/py/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/py/unit/__init__.py b/tests/py/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/py/unit/test_sample.py b/tests/py/unit/test_sample.py new file mode 100644 index 0000000..7384932 --- /dev/null +++ b/tests/py/unit/test_sample.py @@ -0,0 +1,10 @@ +import unittest + +import numpy as np +from mat3ra.code import get_length + + +class TestSample(unittest.TestCase): + def test_type(self): + a = get_length(np.array([1, 2])) + self.assertTrue(type(a) == np.float_) From a339361e0140b9afbe6612569fea4e0320b95af0 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:18:35 -0700 Subject: [PATCH 3/8] chore: update gitignore --- .gitignore | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 170 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7427e3c..15490f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,175 @@ +src/types.ts +.vscode/ + + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +# Ruff +.ruff_cache/ + +########### JAVASCRIPT ############# node_modules/ .eslintcache .nyc_output/ -.idea/ + +########### GENERAL ############# *.DS_Store -src/types.ts -.vscode/ From b3f715a25bfe77192202344b7704fca37a97a368 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:18:45 -0700 Subject: [PATCH 4/8] chore: update eslintignore --- .eslintignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintignore b/.eslintignore index 849ddff..fefbbd5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,3 @@ dist/ +src/py +test/py From 11361174720c4bba42208a20f058d80612aa4f1d Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:19:21 -0700 Subject: [PATCH 5/8] chore: add pre-commit yaml --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..23bd89d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: https://github.com/Exabyte-io/pre-commit-hooks + rev: 2023.6.28 + hooks: + - id: ruff + - id: black + - id: isort + - id: mypy + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: local + hooks: + - id: lint-staged + name: lint-staged + language: node + entry: npx lint-staged + verbose: true # to see familiar lint-staged output + pass_filenames: false # lint-staged has its own glob expression From de0b17fa0230ef11651717b561444331603f990a Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:19:42 -0700 Subject: [PATCH 6/8] chore: add tsconfig --- tsconfig.json | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 8476cc6..89becc3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,33 +1,48 @@ { "compilerOptions": { - "target": "ES2018", - "jsx": "react", - "lib": ["ES2019", "dom"], + /* Basic Options */ + "target": "es2019", + "module": "esNext", "allowJs": true, - "module": "commonjs", - "moduleResolution": "Node", - "declaration": true, + "jsx": "react", + "incremental": true, + "noEmit": true, "outDir": "./dist", - "noEmitOnError": false, - "isolatedModules": true, + + /* Strict Type-Checking Options */ + "strict": true, + "noImplicitAny": false, + "strictNullChecks": true, + "experimentalDecorators": true, + + /* Additional Checks */ + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": false, + "noFallthroughCasesInSwitch": false, + + /* Module Resolution Options */ + "baseUrl": "./src/js", + "rootDir": "./src/js", + "moduleResolution": "node", + "resolveJsonModule": true, "esModuleInterop": true, + "declaration": true, + "isolatedModules": true, "forceConsistentCasingInFileNames": true, - "strict": true, "skipLibCheck": true, - "types": ["mocha", "node"], - "rootDir": "./src", - "baseUrl": "./", - "resolveJsonModule": true + "types": ["mocha", "node"] }, "include": [ - "./src" + "./src/js" ], "exclude": [ - "node_modules", - "dist" + "node_modules", + "dist", + "lib" ], "ts-node": { "files": true, "compilerOptions": {} - }, + } } From a2eacd98bb39bc3a52fbb7fb630b953715218791 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:26:42 -0700 Subject: [PATCH 7/8] chore: update package.json --- package.json | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 5b0b6ca..28f9026 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,16 @@ { - "name": "@exabyte-io/code.js", + "name": "@mat3ra/code", "version": "0.0.0", - "description": "COre DEfinitions in JS for Mat3ra.com (Exabyte.io)", + "description": "COre DEfinitions", "scripts": { - "test": "mocha", - "lint": "eslint src tests && prettier --write src tests", - "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", - "transpile": "tsc", - "prettier": "prettier --check src tests", - "prepare": "husky install" + "lint": "eslint --cache src/js tests/js && prettier --write src/js tests/js", + "lint:fix": "eslint --fix --cache src/js tests/js && prettier --write src/js tests/js", + "lint:staged": "lint-staged", + "postinstall": "npm run transpile", + "prepare": "husky install", + "prettier": "prettier --check src/js tests/js", + "test": "nyc --reporter=text mocha --recursive --bail tests/js", + "transpile": "tsc" }, "repository": { "type": "git", @@ -31,7 +33,7 @@ }, "files": [ "/dist", - "/src", + "/src/js", ".babelrc", "modules.d.ts", "tsconfig.json" From 364ebca88718b70817a8dde2775635fd5e1bbcd3 Mon Sep 17 00:00:00 2001 From: Timur Bazhirov Date: Wed, 20 Mar 2024 21:27:04 -0700 Subject: [PATCH 8/8] chore: update package-lock --- package-lock.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3b510f5..055036a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@exabyte-io/code.js", + "name": "@mat3ra/code", "version": "0.0.0", "lockfileVersion": 1, "requires": true, @@ -5621,7 +5621,7 @@ "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { "wrappy": "1" @@ -5707,13 +5707,13 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "dev": true }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, "path-key": { @@ -5972,7 +5972,7 @@ "release-zalgo": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", - "integrity": "sha512-gUAyHVHPPC5wdqX/LG4LWtRYtgjxyX78oanFNTMMyFEfOqdC54s3eE82imuWKbOeqYht2CrNf64Qb8vgmmtZGA==", + "integrity": "sha1-CXALflB0Mpc5Mw5TXFqQ+2eFFzA=", "dev": true, "requires": { "es6-error": "^4.0.1" @@ -5981,7 +5981,7 @@ "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, "require-from-string": { @@ -6136,7 +6136,7 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, "set-function-length": { @@ -6261,7 +6261,7 @@ "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true }, "source-map-support": { @@ -6419,7 +6419,7 @@ "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, "strip-final-newline": { @@ -6496,7 +6496,7 @@ "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, "thenify": { @@ -6520,7 +6520,7 @@ "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, "timers-ext": { @@ -6541,7 +6541,7 @@ "to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true }, "to-regex-range": { @@ -6956,7 +6956,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "write-file-atomic": {