From 0f7806d98ba9182a141f22b98e1cfb1ca7648d42 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Mon, 3 Aug 2020 00:04:21 +1000 Subject: [PATCH] add cachebuster param to Datasets.listDatasets and Datasets.listFeatures --- docs/services.md | 2 ++ services/datasets.js | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/services.md b/docs/services.md index 58f18b06..109b65b9 100644 --- a/docs/services.md +++ b/docs/services.md @@ -738,6 +738,7 @@ See the [corresponding HTTP service documentation][222]. - `config` **[Object][200]?** - `config.sortby` **[string][201]** Sort by either `modified` or `created` (default) dates. (optional, default `created`) + - `config.cachebuster` **[boolean][202]** If `true`, set a timestamp based cache-buster. (optional, default `false`) #### Examples @@ -879,6 +880,7 @@ See the [corresponding HTTP service documentation][227]. - `config.limit` **[number][205]?** Only list this number of features. - `config.start` **[string][201]?** The ID of the feature from which the listing should start. + - `config.cachebuster` **[boolean][202]** If `true`, set a timestamp based cache-buster. (optional, default `false`) #### Examples diff --git a/services/datasets.js b/services/datasets.js index 567ca585..c8e65839 100644 --- a/services/datasets.js +++ b/services/datasets.js @@ -19,6 +19,7 @@ var Datasets = {}; * * @param {Object} [config] * @param {string} [config.sortby=created] - Sort by either `modified` or `created` (default) dates. + * @param {boolean} [config.cachebuster=false] - If `true`, set a timestamp based cache-buster. * @return {MapiRequest} * * @example @@ -36,13 +37,19 @@ var Datasets = {}; */ Datasets.listDatasets = function(config) { v.assertShape({ - sortby: v.oneOf('created', 'modified') + sortby: v.oneOf('created', 'modified'), + cachebuster: v.boolean })(config); + if (config.cachebuster) { + delete config.cachebuster; + config._ = Date.now(); + } + return this.client.createRequest({ method: 'GET', path: '/datasets/v1/:ownerId', - query: config ? pick(config, ['sortby']) : {} + query: config ? pick(config, ['sortby', '_']) : {} }); }; @@ -189,6 +196,7 @@ Datasets.deleteDataset = function(config) { * @param {number} [config.limit] - Only list this number of features. * @param {string} [config.start] - The ID of the feature from which the listing should * start. + * @param {boolean} [config.cachebuster=false] - If `true`, set a timestamp based cache-buster. * @return {MapiRequest} * * @example @@ -204,14 +212,20 @@ Datasets.listFeatures = function(config) { v.assertShape({ datasetId: v.required(v.string), limit: v.number, - start: v.string + start: v.string, + cachebuster: v.boolean })(config); + if (config.cachebuster) { + delete config.cachebuster; + config._ = Date.now(); + } + return this.client.createRequest({ method: 'GET', path: '/datasets/v1/:ownerId/:datasetId/features', params: pick(config, ['datasetId']), - query: pick(config, ['limit', 'start']) + query: pick(config, ['limit', 'start', '_']) }); };