From 6709191b6d05621e5a8572e7a300d0646f787a49 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Fri, 16 May 2025 09:40:22 -0500 Subject: [PATCH 1/3] 3.35.1-development: * add .include to stopsContext * add { include: string } option to stop .fetch() * add tests in get_stops.test.js * update readme to use development tag --- README.md | 2 +- package.json | 2 +- src/examples/get_stops.test.js | 23 +++++++++++++++++++++++ src/mocks/stops.js | 18 ++++++++++++++++++ src/resources/Stop.js | 13 +++++++++++-- src/resources/StopsContext.js | 12 ++++++++++++ 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 726a5a2..9e53e23 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ usages in the [src/examples directory][src-examples]. ## Development Versioning: `npm version [0.0.xx-development]` -Publishing: `npm publish` +Publishing: `npm publish --tag development` ## Contributing diff --git a/package.json b/package.json index a817cf5..6f79a1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.35.0", + "version": "3.35.1-development", "description": "Library to interact with the Syncromatics Track API", "main": "dist/index.js", "scripts": { diff --git a/src/examples/get_stops.test.js b/src/examples/get_stops.test.js index 02dfad9..7d33b94 100644 --- a/src/examples/get_stops.test.js +++ b/src/examples/get_stops.test.js @@ -26,6 +26,19 @@ describe('When searching for stops by name', () => { return stopsPromise; }); + + it('should get a list of stops with patternHrefs', () => { + api.logIn({ username: 'charlie@example.com', password: 'securepassword' }); + + const stopsPromise = api.customer('SYNC').stops() + .withQuery('1st') + .include('patternHrefs') // Include patternHrefs associated with each stop + .getPage() + .then(page => page.list) + .then(stops => stops); // Do things with list of stops + + return stopsPromise; + }); }); describe('When retrieving a stop by ID', () => { @@ -45,6 +58,16 @@ describe('When retrieving a stop by ID', () => { return stopsPromise; }); + + it('should get a stop with patternHrefs', () => { + api.logIn({ username: 'charlie@example.com', password: 'securepassword' }); + + const stopPromise = api.customer('SYNC').stop(1) + .fetch({ include: 'patternHrefs' }) // Include patternHrefs associated with the stop + .then(stop => stop); // Do things with stop + + return stopPromise; + }); }); describe('When creating a stop', () => { diff --git a/src/mocks/stops.js b/src/mocks/stops.js index 90300cf..223e2de 100644 --- a/src/mocks/stops.js +++ b/src/mocks/stops.js @@ -10,7 +10,14 @@ const stops = { Link: '; rel="next", ; rel="last"', }, }); + const listResponseWithIncludePatternHrefs = () => new Response( + Client.toBlob(stops.listWithIncludePatternHrefs), { + headers: { + Link: '; rel="next", ; rel="last"', + }, + }); const singleResponse = () => new Response(Client.toBlob(stops.getById(1))); + const singleResponseWithIncludePatternHrefs = () => new Response(Client.toBlob(stops.getByIdWithIncludePatternHrefs(1))); const postResponse = () => new Response(undefined, { headers: { Location: '/1/SYNC/stops/1', @@ -25,12 +32,15 @@ const stops = { fetchMock .get(client.resolve('/1/SYNC/stops?page=1&per_page=10&q=1st&sort='), listResponse) + .get(client.resolve('/1/SYNC/stops?page=1&per_page=10&q=1st&include=patternHrefs&sort='), listResponseWithIncludePatternHrefs) .get(client.resolve('/1/SYNC/stops/1'), singleResponse) + .get(client.resolve('/1/SYNC/stops/1?include=patternHrefs'), singleResponseWithIncludePatternHrefs) .post(client.resolve('/1/SYNC/stops'), postResponse) .get(client.resolve('/1/SYNC/stops?latitude=40.7128&longitude=-74.006&distanceMeters=200'), nearbyResponse) .put(client.resolve('/1/SYNC/stops/1'), putResponse); }, getById: id => stops.list.find(v => v.id === id), + getByIdWithIncludePatternHrefs: id => stops.listWithIncludePatternHrefs.find(v => v.id === id), list: [{ href: '/1/SYNC/stops/1', id: 1, @@ -38,6 +48,14 @@ const stops = { latitude: 34.081728, longitude: -118.351585, }], + listWithIncludePatternHrefs: [{ + href: '/1/SYNC/stops/1', + id: 1, + name: '1st/Main', + latitude: 34.081728, + longitude: -118.351585, + patternHrefs: ['/1/SYNC/patterns/1', '/1/SYNC/patterns/2'], + }], }; export default stops; diff --git a/src/resources/Stop.js b/src/resources/Stop.js index 5af4bc5..8c998d7 100644 --- a/src/resources/Stop.js +++ b/src/resources/Stop.js @@ -46,10 +46,19 @@ class Stop extends Resource { /** * Fetches the data for this stop via the client + * @param {Object} [options] Options for including additional data + * @param {string} [options.include] Comma-separated list of fields to include in the response * @returns {Promise} If successful, a hydrated instance of this stop */ - fetch() { - return this.client.get(this.href) + fetch(options = {}) { + const { include } = options; + let url = this.href; + + if (include) { + url += `?include=${include}`; + } + + return this.client.get(url) .then(response => response.json()) .then(stop => new Stop(this.client, this, stop)); } diff --git a/src/resources/StopsContext.js b/src/resources/StopsContext.js index 20d058b..d5ef8a6 100644 --- a/src/resources/StopsContext.js +++ b/src/resources/StopsContext.js @@ -35,6 +35,18 @@ class StopsContext extends PagedContext { return this; } + /** + * Include additional information in the response + * @param {string} term - The term to include + * @returns {StopsContext} Returns itself + */ + include(term) { + const include = this.params.include ? this.params.include.split(',') : []; + include.push(term); + this.params.include = include.join(','); + return this; + } + /** * Gets the first page of results for this context * @returns {Promise} If successful, a page of Stop objects From 3357129ae05e5a71cd48f0e498283547817bca88 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Fri, 16 May 2025 10:15:28 -0500 Subject: [PATCH 2/3] 3.35.1-development-1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3041b69..cfffe73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.35.0", + "version": "3.35.1-development-1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6f79a1c..3f33c76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.35.1-development", + "version": "3.35.1-development-1", "description": "Library to interact with the Syncromatics Track API", "main": "dist/index.js", "scripts": { From a81d06e40fba9944db1947e7f9e1ee2f67789b27 Mon Sep 17 00:00:00 2001 From: Cooper Scott Date: Thu, 22 May 2025 11:12:44 -0500 Subject: [PATCH 3/3] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f33c76..cd71d88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "syncromatics-track-api", - "version": "3.35.1-development-1", + "version": "3.36.0", "description": "Library to interact with the Syncromatics Track API", "main": "dist/index.js", "scripts": {