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:
Naz 2023-01-20 19:57:05 +08:00
parent 95b6a9d569
commit ec4045cb57
No known key found for this signature in database
8 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,6 @@
module.exports = {
plugins: ['ghost'],
extends: [
'plugin:ghost/node'
]
};

View 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

View File

@ -0,0 +1,3 @@
module.exports = {
URLResourceUpdatedEvent: require('./lib/URLResourceUpdatedEvent')
};

View 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
});
}
};

View 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": {}
}

View File

@ -0,0 +1,6 @@
module.exports = {
plugins: ['ghost'],
extends: [
'plugin:ghost/test'
]
};

View File

@ -0,0 +1,8 @@
const assert = require('assert');
const events = require('../index');
describe('Dynamic Routing Events', function () {
it('exports events', function () {
assert(events.URLResourceUpdatedEvent);
});
});

View File

@ -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);
});
});