Added dynamic-routing-events package
refs https://github.com/TryGhost/Toolbox/issues/503 - Reusing existing events inside of dynamic routing would only contribute to general confusion that is already there. Having separate "DomainEvents" is the best practice used throughout the code which is substituting generic events. - The URLResourceUpdatedEvent is supposed to be emmited whenever there's an updated to the resource already associated with the URL circumventing full url regeneration process inside of DynamicRouting
This commit is contained in:
parent
95b6a9d569
commit
ec4045cb57
6
ghost/dynamic-routing-events/.eslintrc.js
Normal file
6
ghost/dynamic-routing-events/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node'
|
||||
]
|
||||
};
|
23
ghost/dynamic-routing-events/README.md
Normal file
23
ghost/dynamic-routing-events/README.md
Normal file
@ -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
|
||||
|
3
ghost/dynamic-routing-events/index.js
Normal file
3
ghost/dynamic-routing-events/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
URLResourceUpdatedEvent: require('./lib/URLResourceUpdatedEvent')
|
||||
};
|
33
ghost/dynamic-routing-events/lib/URLResourceUpdatedEvent.js
Normal file
33
ghost/dynamic-routing-events/lib/URLResourceUpdatedEvent.js
Normal file
@ -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
|
||||
});
|
||||
}
|
||||
};
|
26
ghost/dynamic-routing-events/package.json
Normal file
26
ghost/dynamic-routing-events/package.json
Normal file
@ -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": {}
|
||||
}
|
6
ghost/dynamic-routing-events/test/.eslintrc.js
Normal file
6
ghost/dynamic-routing-events/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test'
|
||||
]
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
const assert = require('assert');
|
||||
const events = require('../index');
|
||||
|
||||
describe('Dynamic Routing Events', function () {
|
||||
it('exports events', function () {
|
||||
assert(events.URLResourceUpdatedEvent);
|
||||
});
|
||||
});
|
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user