@openeo/js-commons
Advanced tools
Comparing version 0.4.3 to 0.4.4
108
dist/main.js
@@ -479,25 +479,25 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
constructor() { | ||
this.typeHints = { | ||
'band-name': {type: 'string', validate: 'validateBandName'}, | ||
'bounding-box': {type: 'object', validate: 'validateBoundingBox'}, | ||
'callback': {type: 'object', validate: 'validateCallback'}, | ||
'collection-id': {type: 'string', validate: 'validateCollectionId'}, | ||
'epsg-code': {type: 'integer', validate: 'validateEpsgCode'}, | ||
'geojson': {type: 'object', validate: 'validateGeoJson'}, | ||
'job-id': {type: 'string', validate: 'validateJobId'}, | ||
'kernel': {type: 'array', validate: 'validateKernel'}, | ||
'output-format': {type: 'string', validate: 'validateOutputFormat'}, | ||
'output-format-options': {type: 'array', validate: 'validateOutputFormatOptions'}, | ||
'process-graph-id': {type: 'string', validate: 'validateProcessGraphId'}, | ||
'process-graph-variables': {type: 'array', validate: 'validateProcessGraphVariables'}, | ||
'proj-definition': {type: 'string', validate: 'validateProjDefinition'}, | ||
'raster-cube': {type: 'object', validate: 'validateRasterCube'}, | ||
'temporal-interval': {type: 'array', validate: 'validateTemporalInterval'}, | ||
'temporal-intervals': {type: 'array', validate: 'validateTemporalIntervals'}, | ||
'vector-cube': {type: 'object', validate: 'validateVectorCube'} | ||
}; | ||
var ajvOptions = { | ||
schemaId: 'auto', | ||
format: 'full', | ||
formats: { | ||
// See issue https://github.com/Open-EO/openeo-js-commons/issues/4 for information on why ajv doesn't support non-string validation | ||
'band-name': {type: 'string', async: true, validate: this.validateBandName.bind(this)}, | ||
'bounding-box': {type: 'object', async: true, validate: this.validateBoundingBox.bind(this)}, // Currently not supported by ajv 6.10 | ||
'callback': {type: 'object', async: true, validate: this.validateCallback.bind(this)}, // Currently not supported by ajv 6.10 | ||
'collection-id': {type: 'string', async: true, validate: this.validateCollectionId.bind(this)}, | ||
'epsg-code': {type: 'integer', async: true, validate: this.validateEpsgCode.bind(this)}, // Currently not supported by ajv 6.10 | ||
'geojson': {type: 'object', async: true, validate: this.validateGeoJson.bind(this)}, // Currently not supported by ajv 6.10 | ||
'job-id': {type: 'string', async: true, validate: this.validateJobId.bind(this)}, | ||
'kernel': {type: 'array', async: true, validate: this.validateKernel.bind(this)}, // Currently not supported by ajv 6.10 | ||
'output-format': {type: 'string', async: true, validate: this.validateOutputFormat.bind(this)}, | ||
'output-format-options': {type: 'array', async: true, validate: this.validateOutputFormatOptions.bind(this)}, // Currently not supported by ajv 6.10 | ||
'process-graph-id': {type: 'string', async: true, validate: this.validateProcessGraphId.bind(this)}, | ||
'process-graph-variables': {type: 'array', async: true, validate: this.validateProcessGraphVariables.bind(this)}, // Currently not supported by ajv 6.10 | ||
'proj-definition': {type: 'string', async: true, validate: this.validateProjDefinition.bind(this)}, | ||
'raster-cube': {type: 'object', async: true, validate: this.validateRasterCube.bind(this)}, // Currently not supported by ajv 6.10 | ||
'temporal-interval': {type: 'array', async: true, validate: this.validateTemporalInterval.bind(this)}, // Currently not supported by ajv 6.10 | ||
'temporal-intervals': {type: 'array', async: true, validate: this.validateTemporalIntervals.bind(this)}, // Currently not supported by ajv 6.10 | ||
'vector-cube': {type: 'object', async: true, validate: this.validateVectorCube.bind(this)} // Currently not supported by ajv 6.10 | ||
} | ||
unknownFormats: Object.keys(this.typeHints) | ||
}; | ||
@@ -519,2 +519,18 @@ this.ajv = new ajv(ajvOptions); | ||
}); | ||
this.ajv.addKeyword('typehint', { | ||
dependencies: [ | ||
"type" | ||
], | ||
validate: async (typehint, data, schema) => { | ||
if (typeof this.typeHints[typehint] === 'object') { | ||
var th = this.typeHints[typehint]; | ||
if (th.type === schema.type || (Array.isArray(schema.type) && schema.type.includes(th.type))) { | ||
return await this[th.validate](data); | ||
} | ||
} | ||
return false; | ||
}, | ||
async: true, | ||
errors: true | ||
}); | ||
@@ -525,13 +541,39 @@ this.outputFormats = null; | ||
async validateJson(json, schema) { | ||
// Make sure we don't alter the process registry | ||
var clonedSchema = Object.assign({}, schema); | ||
clonedSchema.$async = true; | ||
if (typeof clonedSchema.$schema === 'undefined') { | ||
// Set applicable JSON Schema draft version if not already set | ||
clonedSchema.$schema = "http://json-schema.org/draft-07/schema#"; | ||
/* This is a temporary workaround for the following issues: | ||
- https://github.com/epoberezkin/ajv/issues/1039 | ||
- https://github.com/Open-EO/openeo-processes/issues/67 | ||
Once one of the issues is solved, fixSchema can be removed. | ||
*/ | ||
fixSchemaFormat(s) { | ||
for(var i in s) { | ||
if (i === 'format' && typeof s[i] === 'string' && Object.keys(this.typeHints).includes(s[i])) { | ||
s.typehint = s[i]; | ||
} | ||
if (s[i] && typeof s[i] === 'object') { | ||
s[i] = this.fixSchemaFormat(s[i]); | ||
} | ||
} | ||
return s; | ||
} | ||
fixSchema(s) { | ||
s = JSON.parse(JSON.stringify(s)); | ||
// Set applicable JSON Schema draft version if not already set | ||
if (typeof s.$schema === 'undefined') { | ||
s.$schema = "http://json-schema.org/draft-07/schema#"; | ||
} | ||
// format => typehint (see above) | ||
s = this.fixSchemaFormat(s); | ||
return s; | ||
} | ||
async validateJson(json, schema) { | ||
schema = this.fixSchema(schema); | ||
schema.$async = true; | ||
try { | ||
await this.ajv.validate(clonedSchema, json); | ||
await this.ajv.validate(schema, json); | ||
return []; | ||
@@ -549,8 +591,4 @@ } catch (e) { | ||
validateJsonSchema(schema) { | ||
// Set applicable JSON SChema draft version if not already set | ||
if (typeof schema.$schema === 'undefined') { | ||
schema = Object.assign({}, schema); // Make sure we don't alter the process registry | ||
schema.$schema = "http://json-schema.org/draft-07/schema#"; | ||
} | ||
schema = JSON.parse(JSON.stringify(schema)); | ||
schema = this.fixSchema(schema); | ||
let result = this.ajv.compile(schema); | ||
@@ -615,3 +653,3 @@ return result.errors || []; | ||
if (!this.geoJsonValidator(data)) { | ||
throw new ajv.ValidationError(ajv.errors); | ||
throw new ajv.ValidationError(this.geoJsonValidator.errors); | ||
} | ||
@@ -618,0 +656,0 @@ return true; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("ajv"));else if("function"==typeof define&&define.amd)define(["ajv"],t);else{var r="object"==typeof exports?t(require("ajv")):t(e.ajv);for(var s in r)("object"==typeof exports?exports:e)[s]=r[s]}}(window,function(e){return function(e){var t={};function r(s){if(t[s])return t[s].exports;var a=t[s]={i:s,l:!1,exports:{}};return e[s].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(s,a,function(t){return e[t]}.bind(null,a));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=7)}([function(e,t,r){const s=r(9);var a={compareVersion(e,t){try{return s(e,t)}catch(e){return null}},isObject:e=>"object"==typeof e&&e===Object(e)&&!Array.isArray(e),size:e=>"object"==typeof e&&null!==e?Array.isArray(e)?e.length:Object.keys(e).length:0,replacePlaceholders(e,t={}){if("string"==typeof e&&this.isObject(t))for(var r in t)e=e.replace("{"+r+"}",t[r]);return e}};e.exports=a},function(e,t,r){const s=r(0),a={MultipleResultNodes:"Multiple result nodes specified for process graph.",StartNodeMissing:"No start nodes found for process graph.",ResultNodeMissing:"No result node found for process graph.",MultipleResultNodesCallback:"Multiple result nodes specified for the callback in the process '{process_id}' (node: '{node_id}').",StartNodeMissingCallback:"No start nodes found for the callback in the process '{process_id}' (node: '{node_id}')'.",ResultNodeMissingCallback:"No result node found for the callback in the process '{process_id}' (node: '{node_id}').",ReferencedNodeMissing:"Referenced node '{node_id}' doesn't exist.",NodeIdInvalid:"Invalid node id specified in process graph.",NodeInvalid:"Process graph node '{node_id}' is not a valid object.",ProcessIdMissing:"Process graph node '{node_id}' doesn't contain a process id.",CallbackArgumentInvalid:"Invalid callback argument '{argument}' requested in the process '{process_id}' (node: '{node_id}').",ProcessUnsupported:"Process '{process}' is not supported.",ProcessArgumentUnsupported:"Process '{process}' does not support argument '{argument}'.",ProcessArgumentRequired:"Process '{process}' requires argument '{argument}'.",ProcessArgumentInvalid:"The argument '{argument}' in process '{process}' is invalid: {reason}",VariableValueMissing:"No value specified for process graph variable '{variable_id}'.",VariableDefaultValueTypeInvalid:"The default value specified for the process graph variable '{variable_id}' is not of type '{type}'.",VariableValueTypeInvalid:"The value specified for the process graph variable '{variable_id}' is not of type '{type}'.",VariableIdInvalid:"A specified variable ID is not valid.",VariableTypeInvalid:"The data type specified for the process graph variable '{variable_id}' is invalid. Must be one of: string, boolean, number, array or object."};e.exports=class extends Error{constructor(e,t={}){super(),this.variables=t,"string"==typeof a[e]?(this.code=e,this.message=s.replacePlaceholders(a[e],t)):(this.code=e.replace(/[^\w\d]+/g,""),this.message=e)}toJSON(){return{code:this.code,message:this.message}}}},function(e,t,r){const s=r(1),a=r(0);e.exports=class e{constructor(e,t,r){if("string"!=typeof t||0===t.length)throw new s("NodeIdInvalid");if(!a.isObject(e))throw new s("NodeInvalid",{node_id:t});if("string"!=typeof e.process_id)throw new s("ProcessIdMissing",{node_id:t});this.id=t,this.processGraph=r,this.process_id=e.process_id,this.arguments=a.isObject(e.arguments)?JSON.parse(JSON.stringify(e.arguments)):{},this.isResultNode=e.result||!1,this.expectsFrom=[],this.passesTo=[],this.result=null,this.resultsAvailableFrom=[]}getProcessGraph(){return this.processGraph}getArgumentNames(){return Object.keys(this.arguments)}hasArgument(e){return e in this.arguments}getArgumentType(t){return e.getType(this.arguments[t])}getRawArgument(e){return this.arguments[e]}getRawArgumentValue(t){var r=this.arguments[t];switch(e.getType(r)){case"result":return r.from_node;case"callback":return r.callback;case"callback-argument":return r.from_argument;default:return r}}getArgument(e,t){return void 0===this.arguments[e]?t:this.processArgument(this.arguments[e])}processArgument(t){switch(e.getType(t)){case"result":return this.processGraph.getNode(t.from_node).getResult();case"callback":return t.callback;case"callback-argument":return this.processGraph.getParameter(t.from_argument);case"variable":return this.processGraph.getVariableValue(t.variable_id);case"array":case"object":for(var r in t)t[r]=this.processArgument(t[r]);return t;default:return t}}static getType(e,t="null"){return"object"==typeof e?null===e?t:Array.isArray(e)?"array":e.hasOwnProperty("callback")?"callback":e.hasOwnProperty("variable_id")?"variable":e.hasOwnProperty("from_node")?"result":e.hasOwnProperty("from_argument")?"callback-argument":"object":typeof e}isStartNode(){return 0===this.expectsFrom.length}addPreviousNode(e){this.expectsFrom.push(e)}getPreviousNodes(){return this.expectsFrom}addNextNode(e){this.passesTo.push(e)}getNextNodes(){return this.passesTo}reset(){this.result=null,this.resultsAvailableFrom=[]}setResult(e){this.result=e}getResult(){return this.result}solveDependency(e){return null!==e&&this.expectsFrom.includes(e)&&this.resultsAvailableFrom.push(e),this.expectsFrom.length===this.resultsAvailableFrom.length}}},function(e,t,r){const s=r(4),a=r(1),i=r(2),n=r(5);e.exports=class{constructor(e,t=null){this.schema=e,this.jsonSchema=null===t?new s:t}async validate(e){var t=e.getArgumentNames().filter(e=>void 0===this.schema.parameters[e]);if(t.length>0)throw new a("ProcessArgumentUnsupported",{process:this.schema.id,argument:t[0]});for(let t in this.schema.parameters){let r=this.schema.parameters[t],s=e.getRawArgument(t);if(await this.validateArgument(s,e,t,r))continue;let i=await this.jsonSchema.validateJson(s,r.schema);if(i.length>0)throw new a("ProcessArgumentInvalid",{process:this.schema.id,argument:t,reason:i.join("; ")})}}async validateArgument(e,t,r,o){let c=i.getType(e);if(e instanceof n)return await e.validate(!0),!0;switch(c){case"undefined":if(o.required)throw new a("ProcessArgumentRequired",{process:this.schema.id,argument:r});return!0;case"callback-argument":var l=t.getProcessGraph().getCallbackParameters();return s.isSchemaCompatible(o.schema,l[e.from_argument]);case"variable":var d={type:e.type||"string"};return s.isSchemaCompatible(o.schema,d);case"result":try{var p=t.getProcessGraph(),u=p.getNode(e.from_node).process_id,h=p.getProcess(u);return s.isSchemaCompatible(o.schema,h.schema.returns.schema)}catch(e){}break;case"array":case"object":return!0}return!1}async execute(){throw"execute not implemented yet"}test(){throw"test not implemented yet"}}},function(e,t,r){const s=r(12),a=r(0);e.exports=class e{constructor(){var e={schemaId:"auto",format:"full",formats:{"band-name":{type:"string",async:!0,validate:this.validateBandName.bind(this)},"bounding-box":{type:"object",async:!0,validate:this.validateBoundingBox.bind(this)},callback:{type:"object",async:!0,validate:this.validateCallback.bind(this)},"collection-id":{type:"string",async:!0,validate:this.validateCollectionId.bind(this)},"epsg-code":{type:"integer",async:!0,validate:this.validateEpsgCode.bind(this)},geojson:{type:"object",async:!0,validate:this.validateGeoJson.bind(this)},"job-id":{type:"string",async:!0,validate:this.validateJobId.bind(this)},kernel:{type:"array",async:!0,validate:this.validateKernel.bind(this)},"output-format":{type:"string",async:!0,validate:this.validateOutputFormat.bind(this)},"output-format-options":{type:"array",async:!0,validate:this.validateOutputFormatOptions.bind(this)},"process-graph-id":{type:"string",async:!0,validate:this.validateProcessGraphId.bind(this)},"process-graph-variables":{type:"array",async:!0,validate:this.validateProcessGraphVariables.bind(this)},"proj-definition":{type:"string",async:!0,validate:this.validateProjDefinition.bind(this)},"raster-cube":{type:"object",async:!0,validate:this.validateRasterCube.bind(this)},"temporal-interval":{type:"array",async:!0,validate:this.validateTemporalInterval.bind(this)},"temporal-intervals":{type:"array",async:!0,validate:this.validateTemporalIntervals.bind(this)},"vector-cube":{type:"object",async:!0,validate:this.validateVectorCube.bind(this)}}};this.ajv=new s(e),this.ajv.addKeyword("parameters",{dependencies:["type","format"],metaSchema:{type:"object",additionalProperties:{type:"object"}},valid:!0,errors:!0}),this.outputFormats=null,this.geoJsonValidator=null}async validateJson(e,t){var r=Object.assign({},t);r.$async=!0,void 0===r.$schema&&(r.$schema="http://json-schema.org/draft-07/schema#");try{return await this.ajv.validate(r,e),[]}catch(e){if(Array.isArray(e.errors))return e.errors.map(e=>e.message);throw e}}validateJsonSchema(e){return void 0===e.$schema&&((e=Object.assign({},e)).$schema="http://json-schema.org/draft-07/schema#"),this.ajv.compile(e).errors||[]}setGeoJsonSchema(e){var t=new s;this.geoJsonValidator=t.compile(e)}setOutputFormats(e){for(var t in this.outputFormats={},e)this.outputFormats[t.toUpperCase()]=e[t]}async validateBandName(){return!0}async validateBoundingBox(){return!0}async validateCallback(){return!0}async validateCollectionId(){return!0}async validateEpsgCode(e){if(e>=2e3)return!0;throw new s.ValidationError([{message:"Invalid EPSG code specified."}])}async validateGeoJson(e){if(null!==this.geoJsonValidator){if(!this.geoJsonValidator(e))throw new s.ValidationError(s.errors);return!0}if("string"!=typeof e.type)throw new s.ValidationError([{message:"Invalid GeoJSON specified (no type property)."}]);switch(e.type){case"Point":case"MultiPoint":case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":if(!Array.isArray(e.coordinates))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Geometry has no valid coordinates member)."}]);return!0;case"GeometryCollection":if(!Array.isArray(e.geometries))throw new s.ValidationError([{message:"Invalid GeoJSON specified (GeometryCollection has no valid geometries member)."}]);return!0;case"Feature":if(null!==e.geometry&&!a.isObject(e.geometry))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Feature has no valid geometry member)."}]);if(null!==e.properties&&!a.isObject(e.properties))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Feature has no valid properties member)."}]);return!0;case"FeatureCollection":if(!Array.isArray(e.features))throw new s.ValidationError([{message:"Invalid GeoJSON specified (FeatureCollection has no valid features member)."}]);return!0;default:throw new s.ValidationError([{message:"Invalid GeoJSON type specified."}])}}async validateJobId(){return!0}async validateKernel(){return!0}async validateOutputFormat(e){if(a.isObject(this.outputFormats)&&!(e.toUpperCase()in this.outputFormats))throw new s.ValidationError([{message:"Output format not supported."}]);return!0}async validateOutputFormatOptions(){return!0}async validateProcessGraphId(){return!0}async validateProcessGraphVariables(){return!0}async validateProjDefinition(e){if(!e.toLowerCase().includes("+proj"))throw new s.ValidationError([{message:"Invalid PROJ string specified (doesn't contain '+proj')."}]);return!0}async validateRasterCube(){return!0}async validateTemporalInterval(){return!0}async validateTemporalIntervals(e){return 0===e.filter(e=>!this.validateTemporalInterval(e)).length}async validateVectorCube(){return!0}static isSchemaCompatible(t,r,s=!1,i=!1){var n=this._convertSchemaToArray(t),o=this._convertSchemaToArray(r);return n.filter(t=>{for(var r in o){var n=o[r];if("string"!=typeof t.type||!s&&"string"!=typeof n.type)return!0;if(t.type===n.type||i&&("array"===t.type||"object"===t.type)||"number"===t.type&&"integer"===n.type||!s&&"integer"===t.type&&"number"===n.type)if("array"===t.type&&a.isObject(t.items)&&a.isObject(n.items)){if(i&&e.isSchemaCompatible(t.items,n,s))return!0;if(e.isSchemaCompatible(t.items,n.items,s))return!0}else{if("object"===t.type&&a.isObject(t.properties)&&a.isObject(n.properties))return!0;if(!(s||"string"==typeof t.format&&"string"==typeof n.format))return!0;if("string"!=typeof t.format)return!0;if(t.format===n.format)return!0}}return!1}).length>0}static _convertSchemaToArray(e){return e.oneOf||e.anyOf?e.oneOf||e.anyOf:Array.isArray(e.type)?e.type.map(t=>Object.assign({},e,{type:t})):[e]}static async getTypeForValue(t,r){var s=new e,a=[];for(var i in t){0===(await s.validateJson(r,t[i])).length&&a.push(String(i))}return a.length>1?a:a[0]}}},function(e,t,r){const s=r(6),a=r(1),i=r(2),n=r(0),o=["string","number","boolean","array","object"];e.exports=class e{constructor(e,t){this.json=e,this.processRegistry=t,this.nodes=[],this.startNodes={},this.resultNode=null,this.childrenProcessGraphs=[],this.parentNode=null,this.parentProcessId=null,this.parentParameterName=null,this.variables={},this.parsed=!1,this.validated=!1,this.errors=new s,this.parameters={}}toJSON(){return this.json}createNodeInstance(e,t,r){return new i(e,t,r)}createProcessGraphInstance(t){return new e(t,this.processRegistry)}setParent(e,t){e instanceof i?(this.parentNode=e,this.parentProcessId=e.process_id):(this.parentNode=null,this.parentProcessId=e),this.parentParameterName=t}isValid(){return this.validated&&0===this.errors.count()}addError(e){this.errors.add(e)}parse(){if(!this.parsed){for(let e in this.json)this.nodes[e]=this.createNodeInstance(this.json[e],e,this);var e=e=>this.parentProcessId?new a(e+"Callback",{process_id:this.parentProcessId,node_id:this.parentNode?this.parentNode.id:"N/A"}):new a(e);for(let r in this.nodes){var t=this.nodes[r];if(t.isResultNode){if(null!==this.resultNode)throw e("MultipleResultNodes");this.resultNode=t}this.parseArguments(r,t)}if(!this.findStartNodes())throw e("StartNodeMissing");if(null===this.resultNode)throw e("ResultNodeMissing");this.parsed=!0}}async validate(e=!0){if(this.validated)return null;this.validated=!0;try{this.parse()}catch(t){if(this.addError(t),e)throw t}return await this.validateNodes(this.getStartNodes(),e),this.errors}async execute(e=null){return await this.validate(),this.reset(),this.setParameters(e),await this.executeNodes(this.getStartNodes()),this.getResultNode()}async validateNodes(e,t,r=null){if(0!==e.length){var a=e.map(async e=>{if(e.solveDependency(r)){try{await this.validateNode(e)}catch(e){if(e instanceof s){if(this.errors.merge(e),t)throw e.first()}else if(this.addError(e),t)throw e}await this.validateNodes(e.getNextNodes(),t,e)}});await Promise.all(a)}}async validateNode(e){var t=this.getProcess(e);return await t.validate(e)}async executeNodes(e,t=null){if(0!==e.length){var r=e.map(async e=>{if(e.solveDependency(t)){var r=await this.executeNode(e);e.setResult(r),await this.executeNodes(e.getNextNodes(),e)}});return Promise.all(r)}}async executeNode(e){var t=this.getProcess(e);return await t.execute(e)}parseArguments(e,t,r){for(var s in void 0===r&&(r=t.arguments),r){var a=r[s];switch(i.getType(a)){case"result":this.connectNodes(t,a.from_node);break;case"variable":this.parseVariable(a);break;case"callback":a.callback=this.createProcessGraph(a.callback,t,s);break;case"callback-argument":this.parseCallbackArgument(t,a.from_argument);break;case"array":case"object":this.parseArguments(e,t,a)}}}parseCallbackArgument(e,t){var r=this.getCallbackParameters();if(!n.isObject(r)||!r.hasOwnProperty(t))throw new a("CallbackArgumentInvalid",{argument:t,node_id:e.id,process_id:e.process_id})}createProcessGraph(e,t,r){var s=this.createProcessGraphInstance(e);return s.setParent(t,r),s.parse(),this.childrenProcessGraphs.push(s),s}parseVariable(e){if("string"!=typeof e.variable_id)throw new a("VariableIdInvalid");var t={};if(void 0!==e.type&&!o.includes(e.type))throw new a("VariableTypeInvalid",e);t.type=void 0!==e.type?e.type:"string";var r=i.getType(e.default);if("undefined"!==r){if(r!==t.type)throw new a("VariableDefaultValueTypeInvalid",e);t.value=e.default}}setParameters(e){"object"==typeof e&&null!==e&&(this.parameters=e)}getParameter(e){return this.parameters[e]}setVariableValues(e){for(var t in e)this.setVariable(t,e[t])}setVariableValue(e,t){"object"!=typeof this.variables[e]&&(this.variables[e]={}),this.variables[e].value=t}getVariableValue(e){var t=this.variables[e];if("object"!=typeof t||void 0===t.value)throw new a("VariableValueMissing",{variable_id:e});if(i.getType(t.value)!==t.type)throw new a("VariableValueTypeInvalid",{variable_id:e,type:t.type});return this.variables[e].value}connectNodes(e,t){var r=this.nodes[t];if(void 0===r)throw new a("ReferencedNodeMissing",{node_id:t});e.addPreviousNode(r),r.addNextNode(e)}findStartNodes(){var e=!1;for(var t in this.nodes){var r=this.nodes[t];r.isStartNode()&&(this.startNodes[t]=r,e=!0)}return e}reset(){for(var e in this.nodes)this.nodes[e].reset();this.childrenProcessGraphs.forEach(e=>e.reset())}getResultNode(){return this.resultNode}getStartNodes(){return Object.values(this.startNodes)}getStartNodeIds(){return Object.keys(this.startNodes)}getNode(e){return this.nodes[e]}getNodes(){return this.nodes}getErrors(){return this.errors}getProcess(e){var t=this.processRegistry.get(e.process_id);if(null===t)throw new a("ProcessUnsupported",{process:e.process_id});return t}getParentProcess(){return this.processRegistry.get(this.parentProcessId)}getCallbackParameters(){var e=this.getParentProcess();if(!this.parentParameterName||!e)return{};var t=e.schema.parameters[this.parentParameterName].schema;if(n.isObject(t.parameters))return t.parameters;var r={},s=t.anyOf||t.oneOf||t.allOf;if(Array.isArray(s))for(let e in s){var a=s[e];n.isObject(a.parameters)&&Object.assign(r,a.parameters)}return r}}},function(e,t){e.exports=class{constructor(){this.errors=[]}first(){return this.errors[0]||null}last(){return this.errors[this.errors.length-1]||null}merge(e){this.errors=this.errors.concat(e.getAll())}add(e){this.errors.push(e)}count(){return this.errors.length}toJSON(){return this.errors.map(e=>"function"==typeof e.toJSON?e.toJSON():{code:"InternalError",message:e.message})}getMessage(){var e="";for(var t in this.errors)e+=parseInt(t,10)+1+". "+this.errors[t].message+"\r\n";return e.trim()}getAll(){return this.errors}}},function(e,t,r){const s=r(8),a=r(10),i=r(11),n=r(3),o=r(4),c=r(5),l=r(1),d=r(2),p=r(13),u=r(6),h=r(14),g=r(0);e.exports={MigrateCapabilities:s,MigrateCollections:a,MigrateProcesses:i,BaseProcess:n,JsonSchemaValidator:o,ProcessGraph:c,ProcessGraphError:l,ProcessGraphNode:d,ProcessRegistry:p,ErrorList:u,FeatureList:h,Utils:g}},function(e,t,r){const s=r(0);var a={guessApiVersion:e=>"string"==typeof e.version?e.version:"string"==typeof e.api_version?e.api_version:e.backend_version||e.title||e.description||e.links?"0.4":"0.3",convertCapabilitiesToLatestSpec(e,t=null,r="Unknown"){var a=Object.assign({},e);return null===t&&(t=this.guessApiVersion(a)),0===s.compareVersion(t,"0.3.x")&&void 0!==a.version&&delete a.version,void 0!==a.billing&&(a.billing=this.convertBillingToLatestSpec(a.billing,t)),a.endpoints=this.convertEndpointsToLatestSpec(a.endpoints,t),"string"!=typeof a.api_version&&(a.api_version="0.4.2"),"string"!=typeof a.backend_version&&(a.backend_version="Unknown"),"string"!=typeof a.title&&(a.title=r),"string"!=typeof a.description&&(a.description="No description provided."),a},convertBillingToLatestSpec(e,t){var r=Object.assign({},e);return 0===s.compareVersion(t,"0.3.x")&&Array.isArray(r.plans)&&(r.plans=r.plans.map(e=>("boolean"!=typeof e.paid&&(e.paid=!0,"string"==typeof e.name&&e.name.toLowerCase().includes("free")&&(e.paid=!1)),e))),r},convertEndpointsToLatestSpec(e,t){var r=[];return Array.isArray(e)&&(r=e.slice(0)),s.compareVersion(t,"0.3.x"),r},convertOutputFormatsToLatestSpec(e,t){var r=Object.assign({},e);return 0===s.compareVersion(t,"0.3.x")&&"object"==typeof r.formats&&null!==r.formats?r.formats:r},convertServiceTypesToLatestSpec(e,t){var r=Object.assign({},e);return s.compareVersion(t,"0.3.x"),r}};e.exports=a},function(e,t,r){var s,a,i;a=[],void 0===(i="function"==typeof(s=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r,s=e.replace(/^v/,"").replace(/\+.*$/,""),a=(r="-",-1===(t=s).indexOf(r)?t.length:t.indexOf(r)),i=s.substring(0,a).split(".");return i.push(s.substring(a+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function s(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function a(e,a){[e,a].forEach(s);for(var i=t(e),n=t(a),o=0;o<Math.max(i.length-1,n.length-1);o++){var c=parseInt(i[o]||0,10),l=parseInt(n[o]||0,10);if(c>l)return 1;if(l>c)return-1}var d=i[i.length-1],p=n[n.length-1];if(d&&p){var u=d.split(".").map(r),h=p.split(".").map(r);for(o=0;o<Math.max(u.length,h.length);o++){if(void 0===u[o]||"string"==typeof h[o]&&"number"==typeof u[o])return-1;if(void 0===h[o]||"string"==typeof u[o]&&"number"==typeof h[o])return 1;if(u[o]>h[o])return 1;if(h[o]>u[o])return-1}}else if(d||p)return d?-1:1;return 0}var i=[">",">=","=","<","<="];return a.compare=function(e,t,r){switch(function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===i.indexOf(e))throw new TypeError("Invalid operator, expected one of "+i.join("|"))}(r),r){case">":return a(e,t)>0;case">=":return a(e,t)>=0;case"<":return a(e,t)<0;case"<=":return a(e,t)<=0;default:return 0===a(e,t)}},a})?s.apply(t,a):s)||(e.exports=i)},function(e,t,r){const s=r(0);var a={guessCollectionSpecVersion(e){var t="0.4";return void 0===e.id&&void 0!==e.name&&(t="0.3"),t},convertCollectionToLatestSpec(e,t=null){var r=Object.assign({},e);if(!Object.keys(r).length)return r;if(null===t&&(t=this.guessCollectionSpecVersion(r)),0===s.compareVersion(t,"0.3.x")){if(r.id=r.name,delete r.name,r.stac_version="0.6.1",Array.isArray(r.provider)&&(r.providers=r.provider,delete r.provider),"object"!=typeof r.properties&&(r.properties={}),null!==r["eo:bands"]&&"object"==typeof r["eo:bands"]&&!Array.isArray(r["eo:bands"])){var a=[];for(let e in r["eo:bands"]){var i=Object.assign({},r["eo:bands"][e]);i.name=e,void 0!==i.resolution&&void 0===i.gsd&&(i.gsd=i.resolution,delete i.resolution),void 0!==i.wavelength&&void 0===i.center_wavelength&&(i.center_wavelength=i.wavelength,delete i.wavelength),a.push(i)}r["eo:bands"]=a}for(let e in r)e.includes(":")&&(r.properties[e]=r[e],delete r[e])}return r}};e.exports=a},function(e,t,r){const s=r(0);var a={guessProcessSpecVersion(e){var t="0.4";return void 0===e.id&&void 0!==e.name&&(t="0.3"),t},convertProcessToLatestSpec(e,t=null){var r=Object.assign({},e);if(null===t&&(t=this.guessProcessSpecVersion(r)),0===s.compareVersion(t,"0.3.x")){if(r.id=r.name,delete r.name,"object"==typeof r.parameters)for(var a in r.parameters)if(void 0!==r.parameters[a].mime_type){var i=Object.assign({},r.parameters[a]);i.media_type=i.mime_type,delete i.mime_type,r.parameters[a]=i}if("object"==typeof r.returns&&void 0!==r.returns.mime_type&&(r.returns.media_type=r.returns.mime_type,delete r.returns.mime_type),"object"==typeof r.exceptions)for(let e in r.exceptions){var n=r.exceptions[e];void 0===n.message&&(r.exceptions[e]=Object.assign({},n,{message:n.description}))}if("object"==typeof r.examples){var o=[];for(let e in r.examples){var c=r.examples[e],l={title:c.summary||e,description:c.description};c.process_graph&&(l.process_graph=c.process_graph),o.push(l)}r.examples=o}if("object"==typeof r.parameters&&!Array.isArray(r.parameter_order)){var d=Object.keys(r.parameters);d.length>1&&(r.parameter_order=d)}}return r}};e.exports=a},function(t,r){t.exports=e},function(e,t,r){const s=r(3),a=r(0);e.exports=class{constructor(){this.processes={}}addFromResponse(e){for(var t in e.processes)this.add(e.processes[t])}add(e){this.processes[e.id]=new s(e)}count(){return a.size(this.processes)}get(e){var t=e.toLowerCase();return void 0!==this.processes[t]?this.processes[t]:null}getSchema(e){var t=this.get(e);return null!==t?t.schema:null}getProcessSchemas(){return Object.values(this.processes).map(e=>e.schema)}}},function(e,t,r){const s=r(0);var a={features:{"Basic functionality":["get /collections","get /collections/{}","get /processes","get /output_formats"],"Authenticate with HTTP Basic":["get /credentials/basic"],"Authenticate with OpenID Connect":["get /credentials/oidc"],"Batch processing":["get /jobs","post /jobs","get /jobs/{}","delete /jobs/{}","get /jobs/{}/results","post /jobs/{}/results"],"Estimate processing costs":["get /jobs/{}/estimate"],"Preview processing results":["post /result"],"Secondary web services":["get /service_types","get /services","post /services","get /services/{}","delete /services/{}"],"File storage":["get /files/{}","get /files/{}/{}","put /files/{}/{}","delete /files/{}/{}"],"Stored process graphs":["get /process_graphs","post /process_graphs","get /process_graphs/{}","delete /process_graphs/{}"],"Validate process graphs":["post /validation"],"Notifications and monitoring":["get /subscription"],"User defined functions (UDF)":["get /udf_runtimes"]},legacyFeatures:{"post /result":{"post /preview":["0.3.*"]}},getListForVersion(e){var t={};for(var r in this.features)for(var s in t[r]=[],this.features[r]){var a=this.findLegacyEndpoint(e,this.features[r][s]);t[r].push(a)}return t},findLegacyEndpoint(e,t,r=null){if(null!==r&&(t=this.endpointToString(r,t)),"object"==typeof this.legacyFeatures[t]){var a=this.legacyFeatures[t];for(var i in a)for(var n in a[i]){var o=a[i][n];if(0===s.compareVersion(e,o))return i}}return t},getFeatures(){return Object.keys(this.features)},getFeatureCount(){return Object.keys(this.features).length},endpointsToStringList(e){var t=[];for(let r in e)for(let s in e[r].methods)t.push(this.endpointToString(e[r].methods[s],e[r].path));return t},endpointToString:(e,t)=>(e+" "+t.replace(/{[^}]+}/g,"{}")).toLowerCase(),getReport(e,t,r=!0){var s=0,a=r?this.endpointsToStringList(e):e,i=this.getListForVersion(t);return Object.keys(i).forEach(e=>{let t=i[e];switch(t.filter(e=>!a.includes(e)).length){case 0:i[e]=2,s++;break;case t.length:i[e]=0;break;default:i[e]=1}}),{count:s,list:i}}};e.exports=a}])}); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("ajv"));else if("function"==typeof define&&define.amd)define(["ajv"],t);else{var r="object"==typeof exports?t(require("ajv")):t(e.ajv);for(var s in r)("object"==typeof exports?exports:e)[s]=r[s]}}(window,function(e){return function(e){var t={};function r(s){if(t[s])return t[s].exports;var a=t[s]={i:s,l:!1,exports:{}};return e[s].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(s,a,function(t){return e[t]}.bind(null,a));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=7)}([function(e,t,r){const s=r(9);var a={compareVersion(e,t){try{return s(e,t)}catch(e){return null}},isObject:e=>"object"==typeof e&&e===Object(e)&&!Array.isArray(e),size:e=>"object"==typeof e&&null!==e?Array.isArray(e)?e.length:Object.keys(e).length:0,replacePlaceholders(e,t={}){if("string"==typeof e&&this.isObject(t))for(var r in t)e=e.replace("{"+r+"}",t[r]);return e}};e.exports=a},function(e,t,r){const s=r(0),a={MultipleResultNodes:"Multiple result nodes specified for process graph.",StartNodeMissing:"No start nodes found for process graph.",ResultNodeMissing:"No result node found for process graph.",MultipleResultNodesCallback:"Multiple result nodes specified for the callback in the process '{process_id}' (node: '{node_id}').",StartNodeMissingCallback:"No start nodes found for the callback in the process '{process_id}' (node: '{node_id}')'.",ResultNodeMissingCallback:"No result node found for the callback in the process '{process_id}' (node: '{node_id}').",ReferencedNodeMissing:"Referenced node '{node_id}' doesn't exist.",NodeIdInvalid:"Invalid node id specified in process graph.",NodeInvalid:"Process graph node '{node_id}' is not a valid object.",ProcessIdMissing:"Process graph node '{node_id}' doesn't contain a process id.",CallbackArgumentInvalid:"Invalid callback argument '{argument}' requested in the process '{process_id}' (node: '{node_id}').",ProcessUnsupported:"Process '{process}' is not supported.",ProcessArgumentUnsupported:"Process '{process}' does not support argument '{argument}'.",ProcessArgumentRequired:"Process '{process}' requires argument '{argument}'.",ProcessArgumentInvalid:"The argument '{argument}' in process '{process}' is invalid: {reason}",VariableValueMissing:"No value specified for process graph variable '{variable_id}'.",VariableDefaultValueTypeInvalid:"The default value specified for the process graph variable '{variable_id}' is not of type '{type}'.",VariableValueTypeInvalid:"The value specified for the process graph variable '{variable_id}' is not of type '{type}'.",VariableIdInvalid:"A specified variable ID is not valid.",VariableTypeInvalid:"The data type specified for the process graph variable '{variable_id}' is invalid. Must be one of: string, boolean, number, array or object."};e.exports=class extends Error{constructor(e,t={}){super(),this.variables=t,"string"==typeof a[e]?(this.code=e,this.message=s.replacePlaceholders(a[e],t)):(this.code=e.replace(/[^\w\d]+/g,""),this.message=e)}toJSON(){return{code:this.code,message:this.message}}}},function(e,t,r){const s=r(1),a=r(0);e.exports=class e{constructor(e,t,r){if("string"!=typeof t||0===t.length)throw new s("NodeIdInvalid");if(!a.isObject(e))throw new s("NodeInvalid",{node_id:t});if("string"!=typeof e.process_id)throw new s("ProcessIdMissing",{node_id:t});this.id=t,this.processGraph=r,this.process_id=e.process_id,this.arguments=a.isObject(e.arguments)?JSON.parse(JSON.stringify(e.arguments)):{},this.isResultNode=e.result||!1,this.expectsFrom=[],this.passesTo=[],this.result=null,this.resultsAvailableFrom=[]}getProcessGraph(){return this.processGraph}getArgumentNames(){return Object.keys(this.arguments)}hasArgument(e){return e in this.arguments}getArgumentType(t){return e.getType(this.arguments[t])}getRawArgument(e){return this.arguments[e]}getRawArgumentValue(t){var r=this.arguments[t];switch(e.getType(r)){case"result":return r.from_node;case"callback":return r.callback;case"callback-argument":return r.from_argument;default:return r}}getArgument(e,t){return void 0===this.arguments[e]?t:this.processArgument(this.arguments[e])}processArgument(t){switch(e.getType(t)){case"result":return this.processGraph.getNode(t.from_node).getResult();case"callback":return t.callback;case"callback-argument":return this.processGraph.getParameter(t.from_argument);case"variable":return this.processGraph.getVariableValue(t.variable_id);case"array":case"object":for(var r in t)t[r]=this.processArgument(t[r]);return t;default:return t}}static getType(e,t="null"){return"object"==typeof e?null===e?t:Array.isArray(e)?"array":e.hasOwnProperty("callback")?"callback":e.hasOwnProperty("variable_id")?"variable":e.hasOwnProperty("from_node")?"result":e.hasOwnProperty("from_argument")?"callback-argument":"object":typeof e}isStartNode(){return 0===this.expectsFrom.length}addPreviousNode(e){this.expectsFrom.push(e)}getPreviousNodes(){return this.expectsFrom}addNextNode(e){this.passesTo.push(e)}getNextNodes(){return this.passesTo}reset(){this.result=null,this.resultsAvailableFrom=[]}setResult(e){this.result=e}getResult(){return this.result}solveDependency(e){return null!==e&&this.expectsFrom.includes(e)&&this.resultsAvailableFrom.push(e),this.expectsFrom.length===this.resultsAvailableFrom.length}}},function(e,t,r){const s=r(4),a=r(1),i=r(2),o=r(5);e.exports=class{constructor(e,t=null){this.schema=e,this.jsonSchema=null===t?new s:t}async validate(e){var t=e.getArgumentNames().filter(e=>void 0===this.schema.parameters[e]);if(t.length>0)throw new a("ProcessArgumentUnsupported",{process:this.schema.id,argument:t[0]});for(let t in this.schema.parameters){let r=this.schema.parameters[t],s=e.getRawArgument(t);if(await this.validateArgument(s,e,t,r))continue;let i=await this.jsonSchema.validateJson(s,r.schema);if(i.length>0)throw new a("ProcessArgumentInvalid",{process:this.schema.id,argument:t,reason:i.join("; ")})}}async validateArgument(e,t,r,n){let c=i.getType(e);if(e instanceof o)return await e.validate(!0),!0;switch(c){case"undefined":if(n.required)throw new a("ProcessArgumentRequired",{process:this.schema.id,argument:r});return!0;case"callback-argument":var l=t.getProcessGraph().getCallbackParameters();return s.isSchemaCompatible(n.schema,l[e.from_argument]);case"variable":var p={type:e.type||"string"};return s.isSchemaCompatible(n.schema,p);case"result":try{var d=t.getProcessGraph(),u=d.getNode(e.from_node).process_id,h=d.getProcess(u);return s.isSchemaCompatible(n.schema,h.schema.returns.schema)}catch(e){}break;case"array":case"object":return!0}return!1}async execute(){throw"execute not implemented yet"}test(){throw"test not implemented yet"}}},function(e,t,r){const s=r(12),a=r(0);e.exports=class e{constructor(){this.typeHints={"band-name":{type:"string",validate:"validateBandName"},"bounding-box":{type:"object",validate:"validateBoundingBox"},callback:{type:"object",validate:"validateCallback"},"collection-id":{type:"string",validate:"validateCollectionId"},"epsg-code":{type:"integer",validate:"validateEpsgCode"},geojson:{type:"object",validate:"validateGeoJson"},"job-id":{type:"string",validate:"validateJobId"},kernel:{type:"array",validate:"validateKernel"},"output-format":{type:"string",validate:"validateOutputFormat"},"output-format-options":{type:"array",validate:"validateOutputFormatOptions"},"process-graph-id":{type:"string",validate:"validateProcessGraphId"},"process-graph-variables":{type:"array",validate:"validateProcessGraphVariables"},"proj-definition":{type:"string",validate:"validateProjDefinition"},"raster-cube":{type:"object",validate:"validateRasterCube"},"temporal-interval":{type:"array",validate:"validateTemporalInterval"},"temporal-intervals":{type:"array",validate:"validateTemporalIntervals"},"vector-cube":{type:"object",validate:"validateVectorCube"}};var e={schemaId:"auto",format:"full",unknownFormats:Object.keys(this.typeHints)};this.ajv=new s(e),this.ajv.addKeyword("parameters",{dependencies:["type","format"],metaSchema:{type:"object",additionalProperties:{type:"object"}},valid:!0,errors:!0}),this.ajv.addKeyword("typehint",{dependencies:["type"],validate:async(e,t,r)=>{if("object"==typeof this.typeHints[e]){var s=this.typeHints[e];if(s.type===r.type||Array.isArray(r.type)&&r.type.includes(s.type))return await this[s.validate](t)}return!1},async:!0,errors:!0}),this.outputFormats=null,this.geoJsonValidator=null}fixSchemaFormat(e){for(var t in e)"format"===t&&"string"==typeof e[t]&&Object.keys(this.typeHints).includes(e[t])&&(e.typehint=e[t]),e[t]&&"object"==typeof e[t]&&(e[t]=this.fixSchemaFormat(e[t]));return e}fixSchema(e){return void 0===(e=JSON.parse(JSON.stringify(e))).$schema&&(e.$schema="http://json-schema.org/draft-07/schema#"),e=this.fixSchemaFormat(e)}async validateJson(e,t){(t=this.fixSchema(t)).$async=!0;try{return await this.ajv.validate(t,e),[]}catch(e){if(Array.isArray(e.errors))return e.errors.map(e=>e.message);throw e}}validateJsonSchema(e){return e=JSON.parse(JSON.stringify(e)),e=this.fixSchema(e),this.ajv.compile(e).errors||[]}setGeoJsonSchema(e){var t=new s;this.geoJsonValidator=t.compile(e)}setOutputFormats(e){for(var t in this.outputFormats={},e)this.outputFormats[t.toUpperCase()]=e[t]}async validateBandName(){return!0}async validateBoundingBox(){return!0}async validateCallback(){return!0}async validateCollectionId(){return!0}async validateEpsgCode(e){if(e>=2e3)return!0;throw new s.ValidationError([{message:"Invalid EPSG code specified."}])}async validateGeoJson(e){if(null!==this.geoJsonValidator){if(!this.geoJsonValidator(e))throw new s.ValidationError(this.geoJsonValidator.errors);return!0}if("string"!=typeof e.type)throw new s.ValidationError([{message:"Invalid GeoJSON specified (no type property)."}]);switch(e.type){case"Point":case"MultiPoint":case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":if(!Array.isArray(e.coordinates))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Geometry has no valid coordinates member)."}]);return!0;case"GeometryCollection":if(!Array.isArray(e.geometries))throw new s.ValidationError([{message:"Invalid GeoJSON specified (GeometryCollection has no valid geometries member)."}]);return!0;case"Feature":if(null!==e.geometry&&!a.isObject(e.geometry))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Feature has no valid geometry member)."}]);if(null!==e.properties&&!a.isObject(e.properties))throw new s.ValidationError([{message:"Invalid GeoJSON specified (Feature has no valid properties member)."}]);return!0;case"FeatureCollection":if(!Array.isArray(e.features))throw new s.ValidationError([{message:"Invalid GeoJSON specified (FeatureCollection has no valid features member)."}]);return!0;default:throw new s.ValidationError([{message:"Invalid GeoJSON type specified."}])}}async validateJobId(){return!0}async validateKernel(){return!0}async validateOutputFormat(e){if(a.isObject(this.outputFormats)&&!(e.toUpperCase()in this.outputFormats))throw new s.ValidationError([{message:"Output format not supported."}]);return!0}async validateOutputFormatOptions(){return!0}async validateProcessGraphId(){return!0}async validateProcessGraphVariables(){return!0}async validateProjDefinition(e){if(!e.toLowerCase().includes("+proj"))throw new s.ValidationError([{message:"Invalid PROJ string specified (doesn't contain '+proj')."}]);return!0}async validateRasterCube(){return!0}async validateTemporalInterval(){return!0}async validateTemporalIntervals(e){return 0===e.filter(e=>!this.validateTemporalInterval(e)).length}async validateVectorCube(){return!0}static isSchemaCompatible(t,r,s=!1,i=!1){var o=this._convertSchemaToArray(t),n=this._convertSchemaToArray(r);return o.filter(t=>{for(var r in n){var o=n[r];if("string"!=typeof t.type||!s&&"string"!=typeof o.type)return!0;if(t.type===o.type||i&&("array"===t.type||"object"===t.type)||"number"===t.type&&"integer"===o.type||!s&&"integer"===t.type&&"number"===o.type)if("array"===t.type&&a.isObject(t.items)&&a.isObject(o.items)){if(i&&e.isSchemaCompatible(t.items,o,s))return!0;if(e.isSchemaCompatible(t.items,o.items,s))return!0}else{if("object"===t.type&&a.isObject(t.properties)&&a.isObject(o.properties))return!0;if(!(s||"string"==typeof t.format&&"string"==typeof o.format))return!0;if("string"!=typeof t.format)return!0;if(t.format===o.format)return!0}}return!1}).length>0}static _convertSchemaToArray(e){return e.oneOf||e.anyOf?e.oneOf||e.anyOf:Array.isArray(e.type)?e.type.map(t=>Object.assign({},e,{type:t})):[e]}static async getTypeForValue(t,r){var s=new e,a=[];for(var i in t){0===(await s.validateJson(r,t[i])).length&&a.push(String(i))}return a.length>1?a:a[0]}}},function(e,t,r){const s=r(6),a=r(1),i=r(2),o=r(0),n=["string","number","boolean","array","object"];e.exports=class e{constructor(e,t){this.json=e,this.processRegistry=t,this.nodes=[],this.startNodes={},this.resultNode=null,this.childrenProcessGraphs=[],this.parentNode=null,this.parentProcessId=null,this.parentParameterName=null,this.variables={},this.parsed=!1,this.validated=!1,this.errors=new s,this.parameters={}}toJSON(){return this.json}createNodeInstance(e,t,r){return new i(e,t,r)}createProcessGraphInstance(t){return new e(t,this.processRegistry)}setParent(e,t){e instanceof i?(this.parentNode=e,this.parentProcessId=e.process_id):(this.parentNode=null,this.parentProcessId=e),this.parentParameterName=t}isValid(){return this.validated&&0===this.errors.count()}addError(e){this.errors.add(e)}parse(){if(!this.parsed){for(let e in this.json)this.nodes[e]=this.createNodeInstance(this.json[e],e,this);var e=e=>this.parentProcessId?new a(e+"Callback",{process_id:this.parentProcessId,node_id:this.parentNode?this.parentNode.id:"N/A"}):new a(e);for(let r in this.nodes){var t=this.nodes[r];if(t.isResultNode){if(null!==this.resultNode)throw e("MultipleResultNodes");this.resultNode=t}this.parseArguments(r,t)}if(!this.findStartNodes())throw e("StartNodeMissing");if(null===this.resultNode)throw e("ResultNodeMissing");this.parsed=!0}}async validate(e=!0){if(this.validated)return null;this.validated=!0;try{this.parse()}catch(t){if(this.addError(t),e)throw t}return await this.validateNodes(this.getStartNodes(),e),this.errors}async execute(e=null){return await this.validate(),this.reset(),this.setParameters(e),await this.executeNodes(this.getStartNodes()),this.getResultNode()}async validateNodes(e,t,r=null){if(0!==e.length){var a=e.map(async e=>{if(e.solveDependency(r)){try{await this.validateNode(e)}catch(e){if(e instanceof s){if(this.errors.merge(e),t)throw e.first()}else if(this.addError(e),t)throw e}await this.validateNodes(e.getNextNodes(),t,e)}});await Promise.all(a)}}async validateNode(e){var t=this.getProcess(e);return await t.validate(e)}async executeNodes(e,t=null){if(0!==e.length){var r=e.map(async e=>{if(e.solveDependency(t)){var r=await this.executeNode(e);e.setResult(r),await this.executeNodes(e.getNextNodes(),e)}});return Promise.all(r)}}async executeNode(e){var t=this.getProcess(e);return await t.execute(e)}parseArguments(e,t,r){for(var s in void 0===r&&(r=t.arguments),r){var a=r[s];switch(i.getType(a)){case"result":this.connectNodes(t,a.from_node);break;case"variable":this.parseVariable(a);break;case"callback":a.callback=this.createProcessGraph(a.callback,t,s);break;case"callback-argument":this.parseCallbackArgument(t,a.from_argument);break;case"array":case"object":this.parseArguments(e,t,a)}}}parseCallbackArgument(e,t){var r=this.getCallbackParameters();if(!o.isObject(r)||!r.hasOwnProperty(t))throw new a("CallbackArgumentInvalid",{argument:t,node_id:e.id,process_id:e.process_id})}createProcessGraph(e,t,r){var s=this.createProcessGraphInstance(e);return s.setParent(t,r),s.parse(),this.childrenProcessGraphs.push(s),s}parseVariable(e){if("string"!=typeof e.variable_id)throw new a("VariableIdInvalid");var t={};if(void 0!==e.type&&!n.includes(e.type))throw new a("VariableTypeInvalid",e);t.type=void 0!==e.type?e.type:"string";var r=i.getType(e.default);if("undefined"!==r){if(r!==t.type)throw new a("VariableDefaultValueTypeInvalid",e);t.value=e.default}}setParameters(e){"object"==typeof e&&null!==e&&(this.parameters=e)}getParameter(e){return this.parameters[e]}setVariableValues(e){for(var t in e)this.setVariable(t,e[t])}setVariableValue(e,t){"object"!=typeof this.variables[e]&&(this.variables[e]={}),this.variables[e].value=t}getVariableValue(e){var t=this.variables[e];if("object"!=typeof t||void 0===t.value)throw new a("VariableValueMissing",{variable_id:e});if(i.getType(t.value)!==t.type)throw new a("VariableValueTypeInvalid",{variable_id:e,type:t.type});return this.variables[e].value}connectNodes(e,t){var r=this.nodes[t];if(void 0===r)throw new a("ReferencedNodeMissing",{node_id:t});e.addPreviousNode(r),r.addNextNode(e)}findStartNodes(){var e=!1;for(var t in this.nodes){var r=this.nodes[t];r.isStartNode()&&(this.startNodes[t]=r,e=!0)}return e}reset(){for(var e in this.nodes)this.nodes[e].reset();this.childrenProcessGraphs.forEach(e=>e.reset())}getResultNode(){return this.resultNode}getStartNodes(){return Object.values(this.startNodes)}getStartNodeIds(){return Object.keys(this.startNodes)}getNode(e){return this.nodes[e]}getNodes(){return this.nodes}getErrors(){return this.errors}getProcess(e){var t=this.processRegistry.get(e.process_id);if(null===t)throw new a("ProcessUnsupported",{process:e.process_id});return t}getParentProcess(){return this.processRegistry.get(this.parentProcessId)}getCallbackParameters(){var e=this.getParentProcess();if(!this.parentParameterName||!e)return{};var t=e.schema.parameters[this.parentParameterName].schema;if(o.isObject(t.parameters))return t.parameters;var r={},s=t.anyOf||t.oneOf||t.allOf;if(Array.isArray(s))for(let e in s){var a=s[e];o.isObject(a.parameters)&&Object.assign(r,a.parameters)}return r}}},function(e,t){e.exports=class{constructor(){this.errors=[]}first(){return this.errors[0]||null}last(){return this.errors[this.errors.length-1]||null}merge(e){this.errors=this.errors.concat(e.getAll())}add(e){this.errors.push(e)}count(){return this.errors.length}toJSON(){return this.errors.map(e=>"function"==typeof e.toJSON?e.toJSON():{code:"InternalError",message:e.message})}getMessage(){var e="";for(var t in this.errors)e+=parseInt(t,10)+1+". "+this.errors[t].message+"\r\n";return e.trim()}getAll(){return this.errors}}},function(e,t,r){const s=r(8),a=r(10),i=r(11),o=r(3),n=r(4),c=r(5),l=r(1),p=r(2),d=r(13),u=r(6),h=r(14),g=r(0);e.exports={MigrateCapabilities:s,MigrateCollections:a,MigrateProcesses:i,BaseProcess:o,JsonSchemaValidator:n,ProcessGraph:c,ProcessGraphError:l,ProcessGraphNode:p,ProcessRegistry:d,ErrorList:u,FeatureList:h,Utils:g}},function(e,t,r){const s=r(0);var a={guessApiVersion:e=>"string"==typeof e.version?e.version:"string"==typeof e.api_version?e.api_version:e.backend_version||e.title||e.description||e.links?"0.4":"0.3",convertCapabilitiesToLatestSpec(e,t=null,r="Unknown"){var a=Object.assign({},e);return null===t&&(t=this.guessApiVersion(a)),0===s.compareVersion(t,"0.3.x")&&void 0!==a.version&&delete a.version,void 0!==a.billing&&(a.billing=this.convertBillingToLatestSpec(a.billing,t)),a.endpoints=this.convertEndpointsToLatestSpec(a.endpoints,t),"string"!=typeof a.api_version&&(a.api_version="0.4.2"),"string"!=typeof a.backend_version&&(a.backend_version="Unknown"),"string"!=typeof a.title&&(a.title=r),"string"!=typeof a.description&&(a.description="No description provided."),a},convertBillingToLatestSpec(e,t){var r=Object.assign({},e);return 0===s.compareVersion(t,"0.3.x")&&Array.isArray(r.plans)&&(r.plans=r.plans.map(e=>("boolean"!=typeof e.paid&&(e.paid=!0,"string"==typeof e.name&&e.name.toLowerCase().includes("free")&&(e.paid=!1)),e))),r},convertEndpointsToLatestSpec(e,t){var r=[];return Array.isArray(e)&&(r=e.slice(0)),s.compareVersion(t,"0.3.x"),r},convertOutputFormatsToLatestSpec(e,t){var r=Object.assign({},e);return 0===s.compareVersion(t,"0.3.x")&&"object"==typeof r.formats&&null!==r.formats?r.formats:r},convertServiceTypesToLatestSpec(e,t){var r=Object.assign({},e);return s.compareVersion(t,"0.3.x"),r}};e.exports=a},function(e,t,r){var s,a,i;a=[],void 0===(i="function"==typeof(s=function(){var e=/^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;function t(e){var t,r,s=e.replace(/^v/,"").replace(/\+.*$/,""),a=(r="-",-1===(t=s).indexOf(r)?t.length:t.indexOf(r)),i=s.substring(0,a).split(".");return i.push(s.substring(a+1)),i}function r(e){return isNaN(Number(e))?e:Number(e)}function s(t){if("string"!=typeof t)throw new TypeError("Invalid argument expected string");if(!e.test(t))throw new Error("Invalid argument not valid semver ('"+t+"' received)")}function a(e,a){[e,a].forEach(s);for(var i=t(e),o=t(a),n=0;n<Math.max(i.length-1,o.length-1);n++){var c=parseInt(i[n]||0,10),l=parseInt(o[n]||0,10);if(c>l)return 1;if(l>c)return-1}var p=i[i.length-1],d=o[o.length-1];if(p&&d){var u=p.split(".").map(r),h=d.split(".").map(r);for(n=0;n<Math.max(u.length,h.length);n++){if(void 0===u[n]||"string"==typeof h[n]&&"number"==typeof u[n])return-1;if(void 0===h[n]||"string"==typeof u[n]&&"number"==typeof h[n])return 1;if(u[n]>h[n])return 1;if(h[n]>u[n])return-1}}else if(p||d)return p?-1:1;return 0}var i=[">",">=","=","<","<="];return a.compare=function(e,t,r){switch(function(e){if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===i.indexOf(e))throw new TypeError("Invalid operator, expected one of "+i.join("|"))}(r),r){case">":return a(e,t)>0;case">=":return a(e,t)>=0;case"<":return a(e,t)<0;case"<=":return a(e,t)<=0;default:return 0===a(e,t)}},a})?s.apply(t,a):s)||(e.exports=i)},function(e,t,r){const s=r(0);var a={guessCollectionSpecVersion(e){var t="0.4";return void 0===e.id&&void 0!==e.name&&(t="0.3"),t},convertCollectionToLatestSpec(e,t=null){var r=Object.assign({},e);if(!Object.keys(r).length)return r;if(null===t&&(t=this.guessCollectionSpecVersion(r)),0===s.compareVersion(t,"0.3.x")){if(r.id=r.name,delete r.name,r.stac_version="0.6.1",Array.isArray(r.provider)&&(r.providers=r.provider,delete r.provider),"object"!=typeof r.properties&&(r.properties={}),null!==r["eo:bands"]&&"object"==typeof r["eo:bands"]&&!Array.isArray(r["eo:bands"])){var a=[];for(let e in r["eo:bands"]){var i=Object.assign({},r["eo:bands"][e]);i.name=e,void 0!==i.resolution&&void 0===i.gsd&&(i.gsd=i.resolution,delete i.resolution),void 0!==i.wavelength&&void 0===i.center_wavelength&&(i.center_wavelength=i.wavelength,delete i.wavelength),a.push(i)}r["eo:bands"]=a}for(let e in r)e.includes(":")&&(r.properties[e]=r[e],delete r[e])}return r}};e.exports=a},function(e,t,r){const s=r(0);var a={guessProcessSpecVersion(e){var t="0.4";return void 0===e.id&&void 0!==e.name&&(t="0.3"),t},convertProcessToLatestSpec(e,t=null){var r=Object.assign({},e);if(null===t&&(t=this.guessProcessSpecVersion(r)),0===s.compareVersion(t,"0.3.x")){if(r.id=r.name,delete r.name,"object"==typeof r.parameters)for(var a in r.parameters)if(void 0!==r.parameters[a].mime_type){var i=Object.assign({},r.parameters[a]);i.media_type=i.mime_type,delete i.mime_type,r.parameters[a]=i}if("object"==typeof r.returns&&void 0!==r.returns.mime_type&&(r.returns.media_type=r.returns.mime_type,delete r.returns.mime_type),"object"==typeof r.exceptions)for(let e in r.exceptions){var o=r.exceptions[e];void 0===o.message&&(r.exceptions[e]=Object.assign({},o,{message:o.description}))}if("object"==typeof r.examples){var n=[];for(let e in r.examples){var c=r.examples[e],l={title:c.summary||e,description:c.description};c.process_graph&&(l.process_graph=c.process_graph),n.push(l)}r.examples=n}if("object"==typeof r.parameters&&!Array.isArray(r.parameter_order)){var p=Object.keys(r.parameters);p.length>1&&(r.parameter_order=p)}}return r}};e.exports=a},function(t,r){t.exports=e},function(e,t,r){const s=r(3),a=r(0);e.exports=class{constructor(){this.processes={}}addFromResponse(e){for(var t in e.processes)this.add(e.processes[t])}add(e){this.processes[e.id]=new s(e)}count(){return a.size(this.processes)}get(e){var t=e.toLowerCase();return void 0!==this.processes[t]?this.processes[t]:null}getSchema(e){var t=this.get(e);return null!==t?t.schema:null}getProcessSchemas(){return Object.values(this.processes).map(e=>e.schema)}}},function(e,t,r){const s=r(0);var a={features:{"Basic functionality":["get /collections","get /collections/{}","get /processes","get /output_formats"],"Authenticate with HTTP Basic":["get /credentials/basic"],"Authenticate with OpenID Connect":["get /credentials/oidc"],"Batch processing":["get /jobs","post /jobs","get /jobs/{}","delete /jobs/{}","get /jobs/{}/results","post /jobs/{}/results"],"Estimate processing costs":["get /jobs/{}/estimate"],"Preview processing results":["post /result"],"Secondary web services":["get /service_types","get /services","post /services","get /services/{}","delete /services/{}"],"File storage":["get /files/{}","get /files/{}/{}","put /files/{}/{}","delete /files/{}/{}"],"Stored process graphs":["get /process_graphs","post /process_graphs","get /process_graphs/{}","delete /process_graphs/{}"],"Validate process graphs":["post /validation"],"Notifications and monitoring":["get /subscription"],"User defined functions (UDF)":["get /udf_runtimes"]},legacyFeatures:{"post /result":{"post /preview":["0.3.*"]}},getListForVersion(e){var t={};for(var r in this.features)for(var s in t[r]=[],this.features[r]){var a=this.findLegacyEndpoint(e,this.features[r][s]);t[r].push(a)}return t},findLegacyEndpoint(e,t,r=null){if(null!==r&&(t=this.endpointToString(r,t)),"object"==typeof this.legacyFeatures[t]){var a=this.legacyFeatures[t];for(var i in a)for(var o in a[i]){var n=a[i][o];if(0===s.compareVersion(e,n))return i}}return t},getFeatures(){return Object.keys(this.features)},getFeatureCount(){return Object.keys(this.features).length},endpointsToStringList(e){var t=[];for(let r in e)for(let s in e[r].methods)t.push(this.endpointToString(e[r].methods[s],e[r].path));return t},endpointToString:(e,t)=>(e+" "+t.replace(/{[^}]+}/g,"{}")).toLowerCase(),getReport(e,t,r=!0){var s=0,a=r?this.endpointsToStringList(e):e,i=this.getListForVersion(t);return Object.keys(i).forEach(e=>{let t=i[e];switch(t.filter(e=>!a.includes(e)).length){case 0:i[e]=2,s++;break;case t.length:i[e]=0;break;default:i[e]=1}}),{count:s,list:i}}};e.exports=a}])}); |
{ | ||
"name": "@openeo/js-commons", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"author": "openEO Consortium", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -7,25 +7,25 @@ const ajv = require('ajv'); | ||
constructor() { | ||
this.typeHints = { | ||
'band-name': {type: 'string', validate: 'validateBandName'}, | ||
'bounding-box': {type: 'object', validate: 'validateBoundingBox'}, | ||
'callback': {type: 'object', validate: 'validateCallback'}, | ||
'collection-id': {type: 'string', validate: 'validateCollectionId'}, | ||
'epsg-code': {type: 'integer', validate: 'validateEpsgCode'}, | ||
'geojson': {type: 'object', validate: 'validateGeoJson'}, | ||
'job-id': {type: 'string', validate: 'validateJobId'}, | ||
'kernel': {type: 'array', validate: 'validateKernel'}, | ||
'output-format': {type: 'string', validate: 'validateOutputFormat'}, | ||
'output-format-options': {type: 'array', validate: 'validateOutputFormatOptions'}, | ||
'process-graph-id': {type: 'string', validate: 'validateProcessGraphId'}, | ||
'process-graph-variables': {type: 'array', validate: 'validateProcessGraphVariables'}, | ||
'proj-definition': {type: 'string', validate: 'validateProjDefinition'}, | ||
'raster-cube': {type: 'object', validate: 'validateRasterCube'}, | ||
'temporal-interval': {type: 'array', validate: 'validateTemporalInterval'}, | ||
'temporal-intervals': {type: 'array', validate: 'validateTemporalIntervals'}, | ||
'vector-cube': {type: 'object', validate: 'validateVectorCube'} | ||
}; | ||
var ajvOptions = { | ||
schemaId: 'auto', | ||
format: 'full', | ||
formats: { | ||
// See issue https://github.com/Open-EO/openeo-js-commons/issues/4 for information on why ajv doesn't support non-string validation | ||
'band-name': {type: 'string', async: true, validate: this.validateBandName.bind(this)}, | ||
'bounding-box': {type: 'object', async: true, validate: this.validateBoundingBox.bind(this)}, // Currently not supported by ajv 6.10 | ||
'callback': {type: 'object', async: true, validate: this.validateCallback.bind(this)}, // Currently not supported by ajv 6.10 | ||
'collection-id': {type: 'string', async: true, validate: this.validateCollectionId.bind(this)}, | ||
'epsg-code': {type: 'integer', async: true, validate: this.validateEpsgCode.bind(this)}, // Currently not supported by ajv 6.10 | ||
'geojson': {type: 'object', async: true, validate: this.validateGeoJson.bind(this)}, // Currently not supported by ajv 6.10 | ||
'job-id': {type: 'string', async: true, validate: this.validateJobId.bind(this)}, | ||
'kernel': {type: 'array', async: true, validate: this.validateKernel.bind(this)}, // Currently not supported by ajv 6.10 | ||
'output-format': {type: 'string', async: true, validate: this.validateOutputFormat.bind(this)}, | ||
'output-format-options': {type: 'array', async: true, validate: this.validateOutputFormatOptions.bind(this)}, // Currently not supported by ajv 6.10 | ||
'process-graph-id': {type: 'string', async: true, validate: this.validateProcessGraphId.bind(this)}, | ||
'process-graph-variables': {type: 'array', async: true, validate: this.validateProcessGraphVariables.bind(this)}, // Currently not supported by ajv 6.10 | ||
'proj-definition': {type: 'string', async: true, validate: this.validateProjDefinition.bind(this)}, | ||
'raster-cube': {type: 'object', async: true, validate: this.validateRasterCube.bind(this)}, // Currently not supported by ajv 6.10 | ||
'temporal-interval': {type: 'array', async: true, validate: this.validateTemporalInterval.bind(this)}, // Currently not supported by ajv 6.10 | ||
'temporal-intervals': {type: 'array', async: true, validate: this.validateTemporalIntervals.bind(this)}, // Currently not supported by ajv 6.10 | ||
'vector-cube': {type: 'object', async: true, validate: this.validateVectorCube.bind(this)} // Currently not supported by ajv 6.10 | ||
} | ||
unknownFormats: Object.keys(this.typeHints) | ||
}; | ||
@@ -47,2 +47,18 @@ this.ajv = new ajv(ajvOptions); | ||
}); | ||
this.ajv.addKeyword('typehint', { | ||
dependencies: [ | ||
"type" | ||
], | ||
validate: async (typehint, data, schema) => { | ||
if (typeof this.typeHints[typehint] === 'object') { | ||
var th = this.typeHints[typehint]; | ||
if (th.type === schema.type || (Array.isArray(schema.type) && schema.type.includes(th.type))) { | ||
return await this[th.validate](data); | ||
} | ||
} | ||
return false; | ||
}, | ||
async: true, | ||
errors: true | ||
}); | ||
@@ -53,13 +69,39 @@ this.outputFormats = null; | ||
async validateJson(json, schema) { | ||
// Make sure we don't alter the process registry | ||
var clonedSchema = Object.assign({}, schema); | ||
clonedSchema.$async = true; | ||
if (typeof clonedSchema.$schema === 'undefined') { | ||
// Set applicable JSON Schema draft version if not already set | ||
clonedSchema.$schema = "http://json-schema.org/draft-07/schema#"; | ||
/* This is a temporary workaround for the following issues: | ||
- https://github.com/epoberezkin/ajv/issues/1039 | ||
- https://github.com/Open-EO/openeo-processes/issues/67 | ||
Once one of the issues is solved, fixSchema can be removed. | ||
*/ | ||
fixSchemaFormat(s) { | ||
for(var i in s) { | ||
if (i === 'format' && typeof s[i] === 'string' && Object.keys(this.typeHints).includes(s[i])) { | ||
s.typehint = s[i]; | ||
} | ||
if (s[i] && typeof s[i] === 'object') { | ||
s[i] = this.fixSchemaFormat(s[i]); | ||
} | ||
} | ||
return s; | ||
} | ||
fixSchema(s) { | ||
s = JSON.parse(JSON.stringify(s)); | ||
// Set applicable JSON Schema draft version if not already set | ||
if (typeof s.$schema === 'undefined') { | ||
s.$schema = "http://json-schema.org/draft-07/schema#"; | ||
} | ||
// format => typehint (see above) | ||
s = this.fixSchemaFormat(s); | ||
return s; | ||
} | ||
async validateJson(json, schema) { | ||
schema = this.fixSchema(schema); | ||
schema.$async = true; | ||
try { | ||
await this.ajv.validate(clonedSchema, json); | ||
await this.ajv.validate(schema, json); | ||
return []; | ||
@@ -77,8 +119,4 @@ } catch (e) { | ||
validateJsonSchema(schema) { | ||
// Set applicable JSON SChema draft version if not already set | ||
if (typeof schema.$schema === 'undefined') { | ||
schema = Object.assign({}, schema); // Make sure we don't alter the process registry | ||
schema.$schema = "http://json-schema.org/draft-07/schema#"; | ||
} | ||
schema = JSON.parse(JSON.stringify(schema)); | ||
schema = this.fixSchema(schema); | ||
let result = this.ajv.compile(schema); | ||
@@ -143,3 +181,3 @@ return result.errors || []; | ||
if (!this.geoJsonValidator(data)) { | ||
throw new ajv.ValidationError(ajv.errors); | ||
throw new ajv.ValidationError(this.geoJsonValidator.errors); | ||
} | ||
@@ -146,0 +184,0 @@ return true; |
3222
150722