From df0db0da3f234ad5645bc7e097fe0aec25b107dd Mon Sep 17 00:00:00 2001 From: Xavier Sosnovsky Date: Thu, 19 Dec 2019 19:55:29 +0100 Subject: [PATCH 1/4] Exclude vs code settings --- .npmignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmignore b/.npmignore index d422cfc..faadf7a 100644 --- a/.npmignore +++ b/.npmignore @@ -6,3 +6,4 @@ coverage/ coffeelint.json .travis.yml _config.yml +*.code-workspace From f9a6b8810609c4b4e83f0a4cf22ecfee068f7cd5 Mon Sep 17 00:00:00 2001 From: Xavier Sosnovsky Date: Thu, 19 Dec 2019 19:55:54 +0100 Subject: [PATCH 2/4] Upgrade version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81b7661..24af1b5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "node": ">=6" }, "description": "SDMX REST API client for JavaScript", - "version": "2.15.0", + "version": "2.15.1", "main": "./lib/index.js", "scripts": { "prebuild": "rm -rf lib && mkdir lib", From 8f33db3c457b504d69ab8becac066968449c723e Mon Sep 17 00:00:00 2001 From: Xavier Sosnovsky Date: Thu, 19 Dec 2019 20:24:58 +0100 Subject: [PATCH 3/4] fix(index): getUrl supports schema and availability queries fix #127 --- src/index.coffee | 24 +++++++++++++++++------- test/index.test.coffee | 25 +++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/index.coffee b/src/index.coffee index a8f0eb0..bc3a740 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -269,15 +269,25 @@ getSchemaQuery = (input) -> # @see #getService # getUrl = (query, service) -> - # URL generation requires all fields to be set. The 3 next lines are just - # in case partial objects are passed to the function. throw ReferenceError 'Service is a mandatory parameter' unless service s = getService service - throw Error 'Not a valid query' unless query?.flow or query?.resource - q = if query.flow then getDataQuery query else getMetadataQuery query - - return new UrlGenerator().getUrl q, s - + if (query?.mode? \ + or (query?.flow? and query?.references?) \ + or (query?.flow? and query?.component?)) + q = getAvailabilityQuery query + return new UrlGenerator().getUrl q, s + else if query?.flow? + q = getDataQuery query + return new UrlGenerator().getUrl q, s + else if query?.resource? + q = getMetadataQuery query + return new UrlGenerator().getUrl q, s + else if query?.context? + q = getSchemaQuery query + return new UrlGenerator().getUrl q, s + else + throw Error 'Not a valid query' + # # Executes the supplied query against the supplied service and returns a # Promise. diff --git a/test/index.test.coffee b/test/index.test.coffee index c919a36..e8d9abc 100644 --- a/test/index.test.coffee +++ b/test/index.test.coffee @@ -195,7 +195,7 @@ describe 'API', -> describe 'when using getUrl()', -> - it 'offers to create a URL from a data query and a service objects', -> + it 'creates a URL from a data query and a service objects', -> query = sdmxrest.getDataQuery {flow: 'EXR', key: 'A.CHF.NOK.SP00.A'} service = sdmxrest.getService 'ECB' url = sdmxrest.getUrl query, service @@ -204,13 +204,34 @@ describe 'API', -> url.should.contain query.flow url.should.contain query.key - it 'offers to create a URL from a metadata query and a service objects', -> + it 'creates a URL from a metadata query and a service objects', -> url = sdmxrest.getUrl {resource: 'codelist', id: 'CL_FREQ'}, 'ECB' url.should.be.a 'string' url.should.contain 'sdw-wsrest.ecb.europa.eu' url.should.contain 'codelist' url.should.contain 'CL_FREQ' + it 'creates a URL from a schema query and a service objects', -> + q = {'context': 'dataflow', 'agency': 'BIS', 'id': 'CBS'} + url = sdmxrest.getUrl q, 'ECB' + url.should.be.a 'string' + url.should.contain 'sdw-wsrest.ecb.europa.eu' + url.should.contain 'schema' + url.should.contain 'dataflow/BIS/CBS' + + it 'creates a URL from an availability query and a service objects', -> + input = { + flow: 'EXR' + key: 'A..EUR.SP00.A' + } + q = sdmxrest.getAvailabilityQuery input + s = sdmxrest.getService({url: 'http://ws-entry-point'}); + url = sdmxrest.getUrl q, s + url.should.be.a 'string' + url.should.contain 'http://ws-entry-point' + url.should.contain 'availableconstraint' + url.should.contain 'EXR/A..EUR.SP00.A' + it 'fails if the input is not of the expected type', -> test = -> sdmxrest.getUrl undefined, sdmxrest.getService 'ECB' should.Throw(test, Error, 'Not a valid query') From f7b44a7610cc12a0833088f1f9de3724b233852f Mon Sep 17 00:00:00 2001 From: Xavier Sosnovsky Date: Thu, 19 Dec 2019 20:37:35 +0100 Subject: [PATCH 4/4] Updated minimum node version required --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 24af1b5..dfbbfa0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sdmx-rest", "engines": { - "node": ">=6" + "node": ">=10" }, "description": "SDMX REST API client for JavaScript", "version": "2.15.1",