diff --git a/ghost/dynamic-routing-events/.eslintrc.js b/ghost/dynamic-routing-events/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/dynamic-routing-events/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/dynamic-routing-events/README.md b/ghost/dynamic-routing-events/README.md new file mode 100644 index 0000000000..b4baa20fc9 --- /dev/null +++ b/ghost/dynamic-routing-events/README.md @@ -0,0 +1,23 @@ +# Dynamic Routing Events + +Contains Dynamic Routing (URL Service) events + + +## Usage + + +## Develop + +This is a monorepo package. + +Follow the instructions for the top-level repo. +1. `git clone` this repo & `cd` into it as usual +2. Run `yarn` to install top-level dependencies. + + + +## Test + +- `yarn lint` run just eslint +- `yarn test` run lint and tests + diff --git a/ghost/dynamic-routing-events/index.js b/ghost/dynamic-routing-events/index.js new file mode 100644 index 0000000000..517d3b4fba --- /dev/null +++ b/ghost/dynamic-routing-events/index.js @@ -0,0 +1,3 @@ +module.exports = { + URLResourceUpdatedEvent: require('./lib/URLResourceUpdatedEvent') +}; diff --git a/ghost/dynamic-routing-events/lib/URLResourceUpdatedEvent.js b/ghost/dynamic-routing-events/lib/URLResourceUpdatedEvent.js new file mode 100644 index 0000000000..3b7ba8b544 --- /dev/null +++ b/ghost/dynamic-routing-events/lib/URLResourceUpdatedEvent.js @@ -0,0 +1,33 @@ +module.exports = class URLResourceUpdatedEvent { + /** + * @readonly + * @type {Object} + */ + data; + + /** + * @readonly + * @type {Date} + */ + timestamp; + + /** + * @private + */ + constructor({timestamp, ...data}) { + this.data = data; + this.timestamp = timestamp; + } + + /** + * + * @param {Object} data URL Resource + * @returns + */ + static create(data) { + return new URLResourceUpdatedEvent({ + ...data, + timestamp: data.timestamp || new Date + }); + } +}; diff --git a/ghost/dynamic-routing-events/package.json b/ghost/dynamic-routing-events/package.json new file mode 100644 index 0000000000..2bc495dabc --- /dev/null +++ b/ghost/dynamic-routing-events/package.json @@ -0,0 +1,26 @@ +{ + "name": "@tryghost/dynamic-routing-events", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/dynamic-routing-events", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "test": "yarn test:unit", + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" + }, + "files": [ + "index.js", + "lib" + ], + "devDependencies": { + "c8": "7.12.0", + "mocha": "10.2.0", + "sinon": "15.0.1" + }, + "dependencies": {} +} diff --git a/ghost/dynamic-routing-events/test/.eslintrc.js b/ghost/dynamic-routing-events/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/dynamic-routing-events/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/dynamic-routing-events/test/dynamic-routing-events.test.js b/ghost/dynamic-routing-events/test/dynamic-routing-events.test.js new file mode 100644 index 0000000000..6e9a773f85 --- /dev/null +++ b/ghost/dynamic-routing-events/test/dynamic-routing-events.test.js @@ -0,0 +1,8 @@ +const assert = require('assert'); +const events = require('../index'); + +describe('Dynamic Routing Events', function () { + it('exports events', function () { + assert(events.URLResourceUpdatedEvent); + }); +}); diff --git a/ghost/dynamic-routing-events/test/lib/URLResourceUpdatedEvent.test.js b/ghost/dynamic-routing-events/test/lib/URLResourceUpdatedEvent.test.js new file mode 100644 index 0000000000..3cab0329ca --- /dev/null +++ b/ghost/dynamic-routing-events/test/lib/URLResourceUpdatedEvent.test.js @@ -0,0 +1,12 @@ +const assert = require('assert'); +const {URLResourceUpdatedEvent} = require('../../index'); + +describe('URLResourceUpdatedEvent', function () { + it('exports a static create method to create instances', function () { + const event = URLResourceUpdatedEvent.create({ + id: 'resource-id' + }); + + assert(event instanceof URLResourceUpdatedEvent); + }); +});