Skip to content

Commit

Permalink
Always allow empty process graphs if option is set, v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Aug 2, 2021
1 parent 352381a commit 49ab43c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.1] - 2021-08-02

### Fixed

- Always allow empty process graphs if option is set

## [1.2.0] - 2021-07-05

### Added
Expand All @@ -31,7 +37,8 @@ First stable release supporting openEO API 1.0.0.

All prior releases have been documented in the [GitHub Releases](https://github.com/Open-EO/openeo-js-processgraphs/releases).

[Unreleased]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.2.0...HEAD>
[Unreleased]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.2.1...HEAD>
[1.2.1]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.2.0...v1.2.1>
[1.2.0]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.1.0...v1.2.0>
[1.1.0]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.0.0...v1.1.0>
[1.0.0]: <https://github.com/Open-EO/openeo-js-processgraphs/compare/v1.0.0>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Build Status](https://travis-ci.org/Open-EO/openeo-js-processgraphs.svg?branch=master)](https://travis-ci.org/Open-EO/openeo-js-processgraphs)

This library's version is **1.2.0** and supports **openEO API version 1.x**.
This library's version is **1.2.1** and supports **openEO API version 1.x**.

This repository was split apart from [openeo-js-commons](https://github.com/Open-EO/openeo-js-commons). Old releases can be found there.

Expand All @@ -27,4 +27,4 @@ In a web environment you can include the library as follows:
<script src="https://cdn.jsdelivr.net/npm/@openeo/js-processgraphs@1/dist/main.min.js"></script>
```

More information can be found in the [**documentation**](https://open-eo.github.io/openeo-js-processgraphs/1.2.0/).
More information can be found in the [**documentation**](https://open-eo.github.io/openeo-js-processgraphs/1.2.1/).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openeo/js-processgraphs",
"version": "1.2.0",
"version": "1.2.1",
"author": "openEO Consortium",
"contributors": [
{
Expand Down
28 changes: 22 additions & 6 deletions src/processgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ const ProcessGraphNode = require('./node');
const Utils = require('./utils');
const ProcessUtils = require('@openeo/js-commons/src/processUtils.js');

const processKeys = [
'id',
'summary',
'description',
'categories',
'parameters',
'returns',
'deprecated',
'experimental',
'exceptions',
'examples',
'links',
'process_graph'
];

/**
* Process parser, validator and executor.
*
Expand Down Expand Up @@ -150,13 +165,14 @@ class ProcessGraph {
}

if (Utils.size(this.process.process_graph) === 0) {
if (this.allowEmptyGraph && Utils.size(this.process) === 0) {
this.parsed = true;
return;
}
else {
throw makeError('ProcessGraphMissing');
if (this.allowEmptyGraph) {
let hasProcessKey = Object.keys(this.process).find(key => processKeys.includes(key));
if (Utils.size(this.process) === 0 || hasProcessKey) {
this.parsed = true;
return;
}
}
throw makeError('ProcessGraphMissing');
}

this.nodes = Utils.mapObjectValues(this.process.process_graph, (pg, id) => this.createNodeInstance(pg, id, this));
Expand Down
10 changes: 8 additions & 2 deletions tests/processgraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ describe('Process Graph Tests', () => {
expect(() => pg.parse()).toThrow();
});

test('Parser > Empty process allowed', async () => {
test('Parser > allowEmpty > Empty process allowed', async () => {
var pg = new ProcessGraph({}, registry);
pg.allowEmpty();
expect(() => pg.parse()).not.toThrow();
});

test('Parser > Fail on non-empty invalid processes', async () => {
test('Parser > allowEmpty > Fail on non-empty invalid processes', async () => {
var pg = new ProcessGraph({"1": {process_id: "foo", arguments: {}}}, registry);
pg.allowEmpty();
expect(() => pg.parse()).toThrow();
Expand All @@ -94,6 +94,12 @@ describe('Process Graph Tests', () => {
expect(() => pg.parse()).toThrow();
});

test('Parser > allowEmpty > Empty process graph does not throw', async () => {
var pg = new ProcessGraph({process_graph: {}}, registry);
pg.allowEmpty();
expect(() => pg.parse()).not.toThrow();
});

test('Parser > Multiple result nodes throw', async () => {
let absNode = {
process_id: "absolute",
Expand Down

0 comments on commit 49ab43c

Please sign in to comment.