From 08e6cc275f773e0b2235a3b70c3d07f352ea8f2f Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Mon, 2 Jan 2023 02:14:20 -0800 Subject: [PATCH 1/6] Added pulsar-edit Downloads & Stargazers --- .../pulsar-edit-downloads.service.js | 46 +++++++++++++++++++ .../pulsar-edit-downloads.tester.js | 18 ++++++++ .../pulsar-edit-stargazers.service.js | 46 +++++++++++++++++++ .../pulsar-edit-stargazers.tester.js | 18 ++++++++ 4 files changed, 128 insertions(+) create mode 100644 services/pulsar-edit/pulsar-edit-downloads.service.js create mode 100644 services/pulsar-edit/pulsar-edit-downloads.tester.js create mode 100644 services/pulsar-edit/pulsar-edit-stargazers.service.js create mode 100644 services/pulsar-edit/pulsar-edit-stargazers.tester.js diff --git a/services/pulsar-edit/pulsar-edit-downloads.service.js b/services/pulsar-edit/pulsar-edit-downloads.service.js new file mode 100644 index 0000000000000..aa86c79702af1 --- /dev/null +++ b/services/pulsar-edit/pulsar-edit-downloads.service.js @@ -0,0 +1,46 @@ +import Joi from 'joi' +import { BaseJsonService } from '../index.js' +import { metric } from '../text-formatters.js' +import { nonNegativeInteger } from '../validators.js' + +const schema = Joi.object({ + downloads: nonNegativeInteger, +}) + +export default class PulsarEditDownloads extends BaseJsonService { + static category = 'downloads' + + static route = { base: 'pulsar-edit/downloads', pattern: ':packageName' } + + static examples = [ + { + title: 'Pulsar-Edit Downloads', + namedParams: { packageName: 'hey-pane' }, + staticPreview: this.render({ downloadCount: 1000 }), + }, + ] + + static defaultBadgeData = { label: 'downloads' } + + static render({ downloadCount }) { + return { + label: 'downloads', + message: metric(downloadCount), + color: '#662d91', + } + } + + async fetch({ packageName }) { + return this._requestJson({ + schema, + url: `https://api.pulsar-edit.dev/api/packages/${packageName}`, + errorMessages: { 404: 'package not found' }, + }) + } + + async handle({ packageName }) { + const packageData = await this.fetch({ packageName }) + const downloadCount = packageData.downloads + return this.constructor.render({ downloadCount }) + } +} diff --git a/services/pulsar-edit/pulsar-edit-downloads.tester.js b/services/pulsar-edit/pulsar-edit-downloads.tester.js new file mode 100644 index 0000000000000..d921c825a074e --- /dev/null +++ b/services/pulsar-edit/pulsar-edit-downloads.tester.js @@ -0,0 +1,18 @@ +import { isMetric } from '../test-validators.js' +import { createServiceTester } from '../tester.js' + +export const t = await createServiceTester() + +t.create('pulsar-edit downloads (valid)').get('/hey-pane.json').expectBadge({ + label: 'downloads', + message: isMetric, + color: '#662d91', +}) + +t.create('pulsar-edit downloads (not found)') + .get('/test-package.json') + .expectBadge({ + label: 'downloads', + message: 'package not found', + color: '#662d91', + }) diff --git a/services/pulsar-edit/pulsar-edit-stargazers.service.js b/services/pulsar-edit/pulsar-edit-stargazers.service.js new file mode 100644 index 0000000000000..c87cd5b7fba65 --- /dev/null +++ b/services/pulsar-edit/pulsar-edit-stargazers.service.js @@ -0,0 +1,46 @@ +import Joi from 'joi' +import { BaseJsonService } from '../index.js' +import { metric } from '../text-formatters.js' +import { nonNegativeInteger } from '../validators.js' + +const schema = Joi.object({ + stargazers_count: nonNegativeInteger, +}) + +export default class PulsarEditStargazers extends BaseJsonService { + static category = 'rating' + + static route = { base: 'pulsar-edit/stargazers', pattern: ':packageName' } + + static examples = [ + { + title: 'Pulsar-Edit Stargazers', + namedParams: { packageName: 'hey-pane' }, + staticPreview: this.render({ stargazerCount: 1000 }), + }, + ] + + static defaultBadgeData = { label: 'stargazers' } + + static render({ stargazerCount }) { + return { + label: 'stargazers', + message: metric(stargazerCount), + color: '#662d91', + } + } + + async fetch({ packageName }) { + return this._requestJson({ + schema, + url: `https://api.pulsar-edit.dev/api/packages/${packageName}`, + errorMessages: { 404: 'package not found' }, + }) + } + + async handle({ packageName }) { + const packageData = await this.fetch({ packageName }) + const stargazerCount = packageData.stargazers_count + return this.constructor.render({ stargazerCount }) + } +} diff --git a/services/pulsar-edit/pulsar-edit-stargazers.tester.js b/services/pulsar-edit/pulsar-edit-stargazers.tester.js new file mode 100644 index 0000000000000..81ee06cbb887e --- /dev/null +++ b/services/pulsar-edit/pulsar-edit-stargazers.tester.js @@ -0,0 +1,18 @@ +import { isMetric } from '../test-validators.js' +import { createServiceTester } from '../tester.js' + +export const t = await createServiceTester() + +t.create('pulsar-edit stargazers (valid)').get('/hey-pane.json').expectBadge({ + label: 'stargazers', + message: isMetric, + color: '#662d91', +}) + +t.create('pulsar-edit stargazers (not found)') + .get('/test-package.json') + .expectBadge({ + label: 'stargazers', + message: 'package not found', + color: '#662d91', + }) From d260f72213aae67a5e8ae56b2f435eab52d63020 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Sat, 14 Jan 2023 16:52:10 -0800 Subject: [PATCH 2/6] Manage colour similar to how Docker Badges do --- .../pulsar-edit/pulsar-edit-downloads.service.js | 3 ++- .../pulsar-edit/pulsar-edit-downloads.tester.js | 15 +++++++++------ .../pulsar-edit/pulsar-edit-stargazers.service.js | 3 ++- .../pulsar-edit/pulsar-edit-stargazers.tester.js | 15 +++++++++------ services/pulsar-edit/pulsar-helper.js | 7 +++++++ 5 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 services/pulsar-edit/pulsar-helper.js diff --git a/services/pulsar-edit/pulsar-edit-downloads.service.js b/services/pulsar-edit/pulsar-edit-downloads.service.js index aa86c79702af1..05367a036f67c 100644 --- a/services/pulsar-edit/pulsar-edit-downloads.service.js +++ b/services/pulsar-edit/pulsar-edit-downloads.service.js @@ -2,6 +2,7 @@ import Joi from 'joi' import { BaseJsonService } from '../index.js' import { metric } from '../text-formatters.js' import { nonNegativeInteger } from '../validators.js' +import { pulsarPurple } from './pulsar-helper.js' const schema = Joi.object({ downloads: nonNegativeInteger, @@ -26,7 +27,7 @@ export default class PulsarEditDownloads extends BaseJsonService { return { label: 'downloads', message: metric(downloadCount), - color: '#662d91', + color: pulsarPurple, } } diff --git a/services/pulsar-edit/pulsar-edit-downloads.tester.js b/services/pulsar-edit/pulsar-edit-downloads.tester.js index d921c825a074e..f6ddd9856281a 100644 --- a/services/pulsar-edit/pulsar-edit-downloads.tester.js +++ b/services/pulsar-edit/pulsar-edit-downloads.tester.js @@ -1,18 +1,21 @@ import { isMetric } from '../test-validators.js' import { createServiceTester } from '../tester.js' +import { pulsarPurple } from './pulsar-helper.js' export const t = await createServiceTester() -t.create('pulsar-edit downloads (valid)').get('/hey-pane.json').expectBadge({ - label: 'downloads', - message: isMetric, - color: '#662d91', -}) +t.create('pulsar-edit downloads (valid)') + .get('/hey-pane.json') + .expectBadge({ + label: 'downloads', + message: isMetric, + color: `#${pulsarPurple}`, + }) t.create('pulsar-edit downloads (not found)') .get('/test-package.json') .expectBadge({ label: 'downloads', message: 'package not found', - color: '#662d91', + color: `#${pulsarPurple}`, }) diff --git a/services/pulsar-edit/pulsar-edit-stargazers.service.js b/services/pulsar-edit/pulsar-edit-stargazers.service.js index c87cd5b7fba65..293d052ef8c29 100644 --- a/services/pulsar-edit/pulsar-edit-stargazers.service.js +++ b/services/pulsar-edit/pulsar-edit-stargazers.service.js @@ -2,6 +2,7 @@ import Joi from 'joi' import { BaseJsonService } from '../index.js' import { metric } from '../text-formatters.js' import { nonNegativeInteger } from '../validators.js' +import { pulsarPurple } from './pulsar-helper.js' const schema = Joi.object({ stargazers_count: nonNegativeInteger, @@ -26,7 +27,7 @@ export default class PulsarEditStargazers extends BaseJsonService { return { label: 'stargazers', message: metric(stargazerCount), - color: '#662d91', + color: pulsarPurple, } } diff --git a/services/pulsar-edit/pulsar-edit-stargazers.tester.js b/services/pulsar-edit/pulsar-edit-stargazers.tester.js index 81ee06cbb887e..3f53d327e18ee 100644 --- a/services/pulsar-edit/pulsar-edit-stargazers.tester.js +++ b/services/pulsar-edit/pulsar-edit-stargazers.tester.js @@ -1,18 +1,21 @@ import { isMetric } from '../test-validators.js' import { createServiceTester } from '../tester.js' +import { pulsarPurple } from './pulsar-helper.js' export const t = await createServiceTester() -t.create('pulsar-edit stargazers (valid)').get('/hey-pane.json').expectBadge({ - label: 'stargazers', - message: isMetric, - color: '#662d91', -}) +t.create('pulsar-edit stargazers (valid)') + .get('/hey-pane.json') + .expectBadge({ + label: 'stargazers', + message: isMetric, + color: `#${pulsarPurple}`, + }) t.create('pulsar-edit stargazers (not found)') .get('/test-package.json') .expectBadge({ label: 'stargazers', message: 'package not found', - color: '#662d91', + color: `#${pulsarPurple}`, }) diff --git a/services/pulsar-edit/pulsar-helper.js b/services/pulsar-edit/pulsar-helper.js new file mode 100644 index 0000000000000..0ea539ff46333 --- /dev/null +++ b/services/pulsar-edit/pulsar-helper.js @@ -0,0 +1,7 @@ +// This is based on the format the Docker badges have taken. +// Seems Tests require `#` before colors, whereas the badges do not. +// So a color variable can be exported for all modules to use as needed. + +const pulsarPurple = '6662d91' + +export { pulsarPurple } From cc8ff6fc8ab3343597772f081732b583300c27b2 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Sat, 14 Jan 2023 16:55:03 -0800 Subject: [PATCH 3/6] Fixed typo in colour --- services/pulsar-edit/pulsar-helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/pulsar-edit/pulsar-helper.js b/services/pulsar-edit/pulsar-helper.js index 0ea539ff46333..42e437622cd21 100644 --- a/services/pulsar-edit/pulsar-helper.js +++ b/services/pulsar-edit/pulsar-helper.js @@ -2,6 +2,6 @@ // Seems Tests require `#` before colors, whereas the badges do not. // So a color variable can be exported for all modules to use as needed. -const pulsarPurple = '6662d91' +const pulsarPurple = '662d91' export { pulsarPurple } From 2687e15374a28231178b2120797de39bf5b31cb2 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Sat, 14 Jan 2023 17:06:30 -0800 Subject: [PATCH 4/6] Or it seems no other (not found) tests check colour, likely overrided elsewhere --- services/pulsar-edit/pulsar-edit-downloads.tester.js | 1 - services/pulsar-edit/pulsar-edit-stargazers.tester.js | 1 - 2 files changed, 2 deletions(-) diff --git a/services/pulsar-edit/pulsar-edit-downloads.tester.js b/services/pulsar-edit/pulsar-edit-downloads.tester.js index f6ddd9856281a..f432520690fad 100644 --- a/services/pulsar-edit/pulsar-edit-downloads.tester.js +++ b/services/pulsar-edit/pulsar-edit-downloads.tester.js @@ -17,5 +17,4 @@ t.create('pulsar-edit downloads (not found)') .expectBadge({ label: 'downloads', message: 'package not found', - color: `#${pulsarPurple}`, }) diff --git a/services/pulsar-edit/pulsar-edit-stargazers.tester.js b/services/pulsar-edit/pulsar-edit-stargazers.tester.js index 3f53d327e18ee..ac53c67fb8164 100644 --- a/services/pulsar-edit/pulsar-edit-stargazers.tester.js +++ b/services/pulsar-edit/pulsar-edit-stargazers.tester.js @@ -17,5 +17,4 @@ t.create('pulsar-edit stargazers (not found)') .expectBadge({ label: 'stargazers', message: 'package not found', - color: `#${pulsarPurple}`, }) From ff77c825fddd7797fe29be2968de94c15a02ab61 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Sun, 22 Jan 2023 22:09:00 -0800 Subject: [PATCH 5/6] Remove usage of 'Edit' --- .../pulsar-downloads.service.js} | 6 +++--- .../pulsar-downloads.tester.js} | 12 +++++------- services/{pulsar-edit => pulsar}/pulsar-helper.js | 0 .../pulsar-stargazers.service.js} | 6 +++--- .../pulsar-stargazers.tester.js} | 4 ++-- 5 files changed, 13 insertions(+), 15 deletions(-) rename services/{pulsar-edit/pulsar-edit-downloads.service.js => pulsar/pulsar-downloads.service.js} (85%) rename services/{pulsar-edit/pulsar-edit-downloads.tester.js => pulsar/pulsar-downloads.tester.js} (62%) rename services/{pulsar-edit => pulsar}/pulsar-helper.js (100%) rename services/{pulsar-edit/pulsar-edit-stargazers.service.js => pulsar/pulsar-stargazers.service.js} (85%) rename services/{pulsar-edit/pulsar-edit-stargazers.tester.js => pulsar/pulsar-stargazers.tester.js} (82%) diff --git a/services/pulsar-edit/pulsar-edit-downloads.service.js b/services/pulsar/pulsar-downloads.service.js similarity index 85% rename from services/pulsar-edit/pulsar-edit-downloads.service.js rename to services/pulsar/pulsar-downloads.service.js index 05367a036f67c..1fd07f58fca54 100644 --- a/services/pulsar-edit/pulsar-edit-downloads.service.js +++ b/services/pulsar/pulsar-downloads.service.js @@ -8,14 +8,14 @@ const schema = Joi.object({ downloads: nonNegativeInteger, }) -export default class PulsarEditDownloads extends BaseJsonService { +export default class PulsarDownloads extends BaseJsonService { static category = 'downloads' - static route = { base: 'pulsar-edit/downloads', pattern: ':packageName' } + static route = { base: 'pulsar/downloads', pattern: ':packageName' } static examples = [ { - title: 'Pulsar-Edit Downloads', + title: 'Pulsar Downloads', namedParams: { packageName: 'hey-pane' }, staticPreview: this.render({ downloadCount: 1000 }), }, diff --git a/services/pulsar-edit/pulsar-edit-downloads.tester.js b/services/pulsar/pulsar-downloads.tester.js similarity index 62% rename from services/pulsar-edit/pulsar-edit-downloads.tester.js rename to services/pulsar/pulsar-downloads.tester.js index f432520690fad..1758516a12fae 100644 --- a/services/pulsar-edit/pulsar-edit-downloads.tester.js +++ b/services/pulsar/pulsar-downloads.tester.js @@ -4,7 +4,7 @@ import { pulsarPurple } from './pulsar-helper.js' export const t = await createServiceTester() -t.create('pulsar-edit downloads (valid)') +t.create('pulsar downloads (valid)') .get('/hey-pane.json') .expectBadge({ label: 'downloads', @@ -12,9 +12,7 @@ t.create('pulsar-edit downloads (valid)') color: `#${pulsarPurple}`, }) -t.create('pulsar-edit downloads (not found)') - .get('/test-package.json') - .expectBadge({ - label: 'downloads', - message: 'package not found', - }) +t.create('pulsar downloads (not found)').get('/test-package.json').expectBadge({ + label: 'downloads', + message: 'package not found', +}) diff --git a/services/pulsar-edit/pulsar-helper.js b/services/pulsar/pulsar-helper.js similarity index 100% rename from services/pulsar-edit/pulsar-helper.js rename to services/pulsar/pulsar-helper.js diff --git a/services/pulsar-edit/pulsar-edit-stargazers.service.js b/services/pulsar/pulsar-stargazers.service.js similarity index 85% rename from services/pulsar-edit/pulsar-edit-stargazers.service.js rename to services/pulsar/pulsar-stargazers.service.js index 293d052ef8c29..4800671fc1fb9 100644 --- a/services/pulsar-edit/pulsar-edit-stargazers.service.js +++ b/services/pulsar/pulsar-stargazers.service.js @@ -8,14 +8,14 @@ const schema = Joi.object({ stargazers_count: nonNegativeInteger, }) -export default class PulsarEditStargazers extends BaseJsonService { +export default class PulsarStargazers extends BaseJsonService { static category = 'rating' - static route = { base: 'pulsar-edit/stargazers', pattern: ':packageName' } + static route = { base: 'pulsar/stargazers', pattern: ':packageName' } static examples = [ { - title: 'Pulsar-Edit Stargazers', + title: 'Pulsar Stargazers', namedParams: { packageName: 'hey-pane' }, staticPreview: this.render({ stargazerCount: 1000 }), }, diff --git a/services/pulsar-edit/pulsar-edit-stargazers.tester.js b/services/pulsar/pulsar-stargazers.tester.js similarity index 82% rename from services/pulsar-edit/pulsar-edit-stargazers.tester.js rename to services/pulsar/pulsar-stargazers.tester.js index ac53c67fb8164..3207c4ebd2184 100644 --- a/services/pulsar-edit/pulsar-edit-stargazers.tester.js +++ b/services/pulsar/pulsar-stargazers.tester.js @@ -4,7 +4,7 @@ import { pulsarPurple } from './pulsar-helper.js' export const t = await createServiceTester() -t.create('pulsar-edit stargazers (valid)') +t.create('pulsar stargazers (valid)') .get('/hey-pane.json') .expectBadge({ label: 'stargazers', @@ -12,7 +12,7 @@ t.create('pulsar-edit stargazers (valid)') color: `#${pulsarPurple}`, }) -t.create('pulsar-edit stargazers (not found)') +t.create('pulsar stargazers (not found)') .get('/test-package.json') .expectBadge({ label: 'stargazers', From 1dd2a88c9eaa19790c9d6ea42f46af601b2a6e36 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Mon, 14 Aug 2023 19:14:19 -0700 Subject: [PATCH 6/6] errorMessages => httpErrors && downloads => dt --- services/pulsar/pulsar-downloads.service.js | 4 ++-- services/pulsar/pulsar-stargazers.service.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/pulsar/pulsar-downloads.service.js b/services/pulsar/pulsar-downloads.service.js index 1fd07f58fca54..50d23cc6a1ea6 100644 --- a/services/pulsar/pulsar-downloads.service.js +++ b/services/pulsar/pulsar-downloads.service.js @@ -11,7 +11,7 @@ const schema = Joi.object({ export default class PulsarDownloads extends BaseJsonService { static category = 'downloads' - static route = { base: 'pulsar/downloads', pattern: ':packageName' } + static route = { base: 'pulsar/dt', pattern: ':packageName' } static examples = [ { @@ -35,7 +35,7 @@ export default class PulsarDownloads extends BaseJsonService { return this._requestJson({ schema, url: `https://api.pulsar-edit.dev/api/packages/${packageName}`, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) } diff --git a/services/pulsar/pulsar-stargazers.service.js b/services/pulsar/pulsar-stargazers.service.js index 4800671fc1fb9..33156f274e1de 100644 --- a/services/pulsar/pulsar-stargazers.service.js +++ b/services/pulsar/pulsar-stargazers.service.js @@ -35,7 +35,7 @@ export default class PulsarStargazers extends BaseJsonService { return this._requestJson({ schema, url: `https://api.pulsar-edit.dev/api/packages/${packageName}`, - errorMessages: { 404: 'package not found' }, + httpErrors: { 404: 'package not found' }, }) }