Commit Graph

123 Commits

Author SHA1 Message Date
Daniel Lockyer
d5cbb33e54 Pinned dependencies 2023-07-24 16:21:47 +02:00
Daniel Lockyer
bb4c3de992 Deduplicated ts-node and typescript dependencies
refs https://github.com/TryGhost/DevOps/issues/50

- this commit deduplicates where we define the versions of these
  packages to make them easier to maintain
2023-07-24 16:21:47 +02:00
Naz
9a38c65ee6 Cleaned up CollectionsService from unused code
refs https://github.com/TryGhost/Arch/issues/16

- Some of the methods became unused due to moving the posts handling out of the collections service and cleaning up the event handling system.
2023-07-21 19:46:22 +08:00
Naz
6361423ff7 Fixed ability to remove post from an automatic collection
refs https://github.com/TryGhost/Arch/issues/16

- Post can be removed from a manual collection, but never from an automatic collection.
2023-07-21 19:46:22 +08:00
Naz
d7bbb0b935 Reworked PostsRepository to use model layer
refs https://github.com/TryGhost/Arch/issues/16

- Using the API directly on the repository level prevented us from ensuring collection consistency through transactions.
- This change migrates the PostsRepository to use Bookshelf model layer directly, which also allows to put queries into transactions.
- Additional optimization here was removing the `getAllPosts` method from CollectionService. This is an attempt to reduce the API surface of the  of the service before calling it a GA.
2023-07-21 19:46:22 +08:00
Naz
3dc27f505c Wrapped collection's creation in transaction
refs https://github.com/TryGhost/Arch/issues/16

- This is needed to avoid stale data/race conditions when processing collection post updates
2023-07-21 19:46:22 +08:00
Naz
0880770d50 Wrapped collection's post adding logic in transaction
refs https://github.com/TryGhost/Arch/issues/16

- Having transactional collection post updates makes sure there are no race conditions when updating collection_posts relations. Without the transactions collection was prone to update relations based on a stale state causing problems like described in the linked issue
2023-07-21 19:46:22 +08:00
Naz
04c92d2ca5 Removed CollectionResourceChangeEvent handling
refs https://github.com/TryGhost/Arch/issues/16

- The generic "UpdateAllCollections" logic should not be used as the mapped Post's delete/add/edit events should be sufficient in maintaining collection's state
2023-07-21 19:46:22 +08:00
Naz
53f9f954c1 Added tag filter support to collections
refs https://github.com/TryGhost/Arch/issues/41

- When an new collection is created the relational "tags" filter is now picked up properly and appropriate posts matching the tag filter are assigned and stored in the collection. Example collection filter that is now supported: `tags:['bacon']`
- Additionally cleaned up returned collection post DTOs, so we return as little data as possible and add only the fields that are needed
2023-07-18 20:18:54 +08:00
Naz
939a8fef33 Moved CollectionPost type to it's own file
refs https://github.com/TryGhost/Arch/issues/41

- This type has to be reused in other class, so best way to do it is having it separated into it's own file
2023-07-18 20:18:54 +08:00
Naz
eec610dc53 Added collection handling for post's tag attach events
refs https://github.com/TryGhost/Arch/issues/41

- When a tag is attached or detached to the post automatic collections matching  the tag filter should be updated.
2023-07-18 18:36:49 +08:00
Naz
c733424cc5 Fixed collections ordering
refs https://github.com/TryGhost/Arch/issues/25

- When run against different DB Engines the returned order of collections belonging to a post is not consistent (SQLite vs MySQL). Having a primitive ordering by slug allows to keep the order compatible
2023-07-17 18:43:21 +08:00
Naz
ed91412cd5 Changed "index" collection name to "latest"
https://github.com/TryGhost/Arch/issues/25

- This naming matches how the collection will be visible in the cards and how it's marketed. Naming it "index" even for internal purposes will get confusing.
2023-07-17 18:43:21 +08:00
Naz
0be06f0237 Added extra logging to collections event processing
no issue

- These logs are useful when tracking event processing by the collections repo.
2023-07-14 14:20:37 +08:00
Daniel Lockyer
2aa7da3a0b Improved monorepo tooling setup
refs https://github.com/TryGhost/DevOps/issues/45

- this switches the monorepo over to using Nx instead of Lerna, because
  we don't currently need the versioning+publishing capabilities
- this also adds an `nx.json`, which allows us to enable task caching
- also adds `build:ts` to the TS projects, which is cached for fast execution
- how these interact with the dev.js script will hopefully soon be
  reworked to be a better experience
2023-07-12 16:27:39 +02:00
Daniel Lockyer
e893c92074 Deduplicated tsconfig.json files
refs https://github.com/TryGhost/DevOps/issues/45

- this moves the bulk of the tsconfig file to the `ghost/` folder and
  simply extends this file in each of the TS lib packages we currently
  have
- this makes it a lot easier to make single changes to our TS config
2023-07-12 09:34:00 +02:00
renovate[bot]
7dce046786 Update Test & linting packages 2023-07-11 15:26:07 +02:00
Naz
cdae2a978d Added ability to fetch collection posts by slug
closes https://github.com/TryGhost/Arch/issues/27

- We need a more convenient method of fetching posts belonging to a collection than by collection's "id". This change adds an alias to the existing endpoint `GET /collections/:id/posts/`. A non-valid ObjectID in the parameter is treated as a slug.
2023-07-11 09:30:01 +08:00
Naz
cb8e009c14 Allowed for index collection to have empty filter
refs https://github.com/TryGhost/Arch/issues/25

- The built in index (soon -> "latest") collection does not require any filtering so that it could contain an index of all posts in the system. All other automatic collections should have a filter defined.
2023-07-10 12:43:52 +08:00
renovate[bot]
aa8cbb9fa3 Update dependency typescript to v5.1.6 2023-06-29 08:24:30 +02:00
Fabien "egg" O'Carroll
16db3bbf17 Removed deletable property in favour of protected slugs
We couldn't decide on the best way to encode this in the database.
e.g. deletable: true? or type: internal? but type conflicts with the
storage of manual/automatic.

For now we can use this, and add something in future if we're finding problems
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
cf83d169db Added use of a slug generator to offload calculation of slugs
When we end up wiring this to the database, this generator will also ensure
uniqueness by appending/incrementing a number on the end of the slug. Long term
it would be good to offload this to a shared slug service, this could also
ensure that slugs are unique globally or between multiple tables, if desired
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
0a3e36cd62 Ensured uniqueness of slug in collections
We require that slugs are unique as slugs can/are used for routing purposes and
act as an identifier for a resource. As this is a core business rule, we want
to encode it in the entity so that it can be unit tested, and be enforced
regardless of underlying persistence layer
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
d29f512823 Required titles for collections
We don't want to allow collections to be created without a title, and we need
to encoe that business rule in the entity.
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
0cfa236570 Fixed visibility of internal _posts member
The _posts member is supposed to be an iternal property to store the data used
by the `posts` getter/setter
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
633cecdf75 Fixed createCollection not waiting for save
This can cause race conditions when writing e2e tests in the case of to the API
responding before persisting the data
2023-06-29 01:40:05 +01:00
renovate[bot]
58b54333a5 Update dependency typescript to v5.1.5 2023-06-28 16:21:27 +02:00
Naz
5dd6159ac6 Added handling for 'post.edited' Ghost model event
refs https://github.com/TryGhost/Team/issues/3169

- Adds optomized collection update handling for when post.edited model event is emitted.
2023-06-27 12:52:10 +07:00
Naz
a8e5cbcc3d Extracted post matching to filter to separate method
refs https://github.com/TryGhost/Team/issues/3169

- This method is also useful for external services when checking if collection needs any updates or not.
2023-06-27 12:52:10 +07:00
Naz
bb13845773 Added future perf oprimization note
refs 1bc2a604c3 (r1239780571)
2023-06-27 12:52:10 +07:00
Naz
cf48d4ef5c Removed ability to change collection type after creation
refs https://github.com/TryGhost/Team/issues/3169

- Being able to change the collection type comes with extra complications we don't wan to support just yet. This came up as a part of the PR review here - 1bc2a604c3 (r1239783573).
2023-06-27 12:52:10 +07:00
Naz
623599af1e Moved DomainEvents to be injected to Collections
refs https://github.com/TryGhost/Team/issues/3169

- With the new architecture all possible dependencies should be  injected rather than required directly - this applies to the DomainEvents module as well.
2023-06-27 12:52:10 +07:00
Naz
36783e456b Added 'post.added' event handling in Collections
refs https://github.com/TryGhost/Team/issues/3169

- This piece of logic handles the 'post.added' model event mapping to Collection's PostAddedEvent domain event and logic related to updating collections when the new post is added.
2023-06-27 12:52:10 +07:00
Naz
42539b954f Added collection editing method
refs https://github.com/TryGhost/Team/issues/3169

- The collection entity properties used to be modified, which is not a good practice for logic encapsulation. Extracted editing logic to it's own method which can also contain validation logic when wrong data is passed when editing a collection.
2023-06-27 12:52:10 +07:00
Naz
58a18d37ea Introduced PostEvent classes to make event handling less generic
refs https://github.com/TryGhost/Team/issues/3169

- When handling a single generic event the code becomes riddled with if statements to detect correct "data" that is being passed with the event. Switching to have a domain event per model event helps solving this problem and makes code more readable.
2023-06-27 12:52:10 +07:00
Naz
ebd58515bd Refactored post removal from all collections
refs https://github.com/TryGhost/Team/issues/3169

- It's easier to read this way and possibly reusable in the future
2023-06-27 12:52:10 +07:00
Naz
e7a0462877 Added model event to domain event bridge
refs https://github.com/TryGhost/Team/issues/3169

- To make the coupling to Ghost's model events as loose as possible added a bridge that maps model events to domain events. These domain events it what the collections module can subscribe to to make necessary updates.
2023-06-27 12:52:10 +07:00
Naz
49d831d971 Optimized handling for post.deleted event in collections
refs https://github.com/TryGhost/Team/issues/3428

- I'm taking an approach of adding specialized support for each event one-by-one.
- The post resource deletion event is the most straight forward and works same for both types of collections.
2023-06-27 12:52:10 +07:00
Naz
25e0cb12c0
Added "getBySlug" method to Collections Service
refs https://github.com/TryGhost/Team/issues/3423

- This is a convenience method that should allow fetching collections by their slug. It is a great developer experience for in case when fetching built-in collections like "featured" and "index", so can avoid an extra call to find the collection and it's ide one wants to use.
2023-06-16 16:31:50 +07:00
Naz
6335033466
Added full post data when returning collection's posts
refs https://github.com/TryGhost/Team/issues/3423

- When querying for posts that belong to a collection we should be returning full post information just like we do for Posts API.
2023-06-15 18:35:58 +07:00
Naz
ddc23b3467 Added collection's posts fetching to collections lib
refs https://github.com/TryGhost/Team/issues/3423

- This is a building block to allow paging, querying etc. of the posts belonging to a collection
2023-06-13 17:23:09 +07:00
Fabien 'egg' O'Carroll
92172aca8e
Wired up collections to posts endpoint (#16945)
- Added support for `include=collections` to the Posts Admin API behind a flag
- Refactored some of the collections work to support it
2023-06-07 15:06:15 +02:00
Naz
fab5b1845c
Made builtin collections un-deletable
closes https://github.com/TryGhost/Team/issues/3376

- It should not be possible to delete a built-in collection.
2023-06-06 22:04:16 +07:00
Naz
5a8eec402f
Restricted built-in collection init to run once
refs https://github.com/TryGhost/Team/issues/3376
fixes b4a97d084f

- The in-memory stores are not cleaned up when the Ghost instance is "shallow restarted" between test suite runs, causing the initialization of built-in collections to run multiple times. The initialization should ever add the collections once.
2023-06-06 13:35:06 +07:00
Naz
2390afc6f1
Added automatic collection recalculation
closes https://github.com/TryGhost/Team/issues/3170

- When resources that are related to automatic collection filter are updated the posts in collections should be updated as well.
- This change adds a super-basic way to track changes in post/tag/author resources and updated all automatic collections when any of those resources change. In the future we can optimize the update process to be more performant, but it's good enough for current needs
2023-06-05 18:33:39 +07:00
Naz
3599cfdd7a
Added test coverage for collection updates
refs https://github.com/TryGhost/Team/issues/3170

- When the collection filter is updated the collection's posts should be updated automatically.
2023-06-05 16:23:02 +07:00
Naz
bfefcfd4df
Added automatic collection creation based on filter
refs https://github.com/TryGhost/Team/issues/3170

- This implementation allows to create an automatic collection with a filter defining automatically populated posts that belong to a collection
- To populate collection using a filter the API client can send a `filter` property along with a collection request
- Filter values are compatible with the filters used in Content API (https://ghost.org/docs/content-api/#filter)
2023-06-05 13:39:52 +07:00
Naz
6e224f3702
Added automatic collection validation
refs https://github.com/TryGhost/Team/issues/3170

- When an automatic collection is created it should always have a valid filter assigned
2023-06-05 13:39:52 +07:00
renovate[bot]
17acd2437b Update dependency typescript to v5.1.3 2023-06-02 09:06:20 +02:00
Naz
e8220b1387
Added DEL /collections/:id/posts/:post_id to Admin API
refs https://github.com/TryGhost/Team/issues/3260

- We need a way to remove posts form collections without fetching the whole collection's content. This API method allows to remove posts from manual collections by collection id and post id.
- As a response it returns up to date collection state without the removed post.
2023-06-01 14:59:05 +07:00
Naz
253f144501 Fixed fromDTO collection mapping
refs https://github.com/TryGhost/Team/issues/3260

- Whenever properties of the DTO are undefined they should be removed to avoid unintentional empty assignments to the stored collection
2023-06-01 14:25:49 +07:00
Naz
a0a7c3a61b Added coverage to all editable collection properties
refs https://github.com/TryGhost/Team/issues/3260

- Made sure we have sufficient coverage for all editable properties of the collection to avoid sneaky bugs
2023-06-01 14:25:49 +07:00
Naz
5d16425428 Fixed description editing in collections service
refs https://github.com/TryGhost/Team/issues/3260

- Fixed broken functionality after a refactor
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
b48a1d0a57 Implemented adding posts to collections; 2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
bd4fac451c Update CollectionsService to remove CollectionPost usage 2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
27f60b4ab5 Added logic for adding posts to collection
Also removes concept of CollectionPost in an effort to simplify the structure
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
917ab0a79e Added CollectionRepository
This defines the interface required by the CollectionsService
2023-06-01 14:25:49 +07:00
Fabien "egg" O'Carroll
5282c4a72b Update eslint and c8 to support using TS interfaces
This will allow us to define the repository interface
2023-06-01 14:25:49 +07:00
Naz
a0c36e16d0 Added "addPost" method do collections module
refs https://github.com/TryGhost/Team/issues/3260

- The method allows to append individual posts to the collection
2023-06-01 14:25:49 +07:00
Naz
87df8754ee Moved bookshelf posts repository to core
refs https://github.com/TryGhost/Team/issues/3260

- Moved the posts bookshelf repository into core codebase where it should belong.
2023-05-31 22:55:35 +07:00
Naz
66d489b8b3 Added Posts relation support to collections package
refs https://github.com/TryGhost/Team/issues/3260

- Adds "posts" relation to Collection entity to manage posts belonging to the collection
2023-05-31 22:55:35 +07:00
Fabien "egg" O'Carroll
b58dac262e Updated collections package to use .d.ts for external lib types
Rather than using `require` we can add a type definition file, this allows us
to add custom types in the future if we want. We need to add some config for
ts-node to pick up the types correctly.
2023-05-24 12:47:20 -04:00
Naz
258a562031
Fixed linting error
refs fdd73d01b7
2023-05-24 17:31:14 +07:00
Naz
4cb5cc9087
Added default collection values
refs https://github.com/TryGhost/Team/issues/3259

- For collection entity creation consistency have set defaults
2023-05-24 17:01:28 +07:00
Naz
b52ec948b0
Added property mapper to collections responses
closes https://github.com/TryGhost/Team/issues/3259

- API output mappers (soon to be serializers) are meant to work based on allowlist set of output properties. Having the allowlist early on will allow to track the API evolution consistently.
2023-05-24 17:01:28 +07:00
Naz
fdd73d01b7
Refactored collections entity logic
refs https://github.com/TryGhost/Team/issues/3294

- The factory method for the Collection and validations should live close together based on our latest architectural direction
2023-05-24 17:01:28 +07:00
Naz
735edf5f87 Fixed editing unexistent collection behavior
refs https://github.com/TryGhost/Team/issues/3167

- When editing collection that does not exist the API should be returning a 404 instead of creating a new collection
2023-05-19 20:42:46 +07:00
Naz
7d926dd30b Refactored collections unit test suite
refs https://github.com/TryGhost/Team/issues/3167

- Duplicate service initialization was getting annoying
2023-05-19 20:42:46 +07:00
Naz
606bd383f1 Extended getAll method with paging metadata
refs https://github.com/TryGhost/Team/issues/3167

- Having paging metadata is part of every API response and was missing from initial implementation
- The getAll method has all of the values as "static" as there's nothing to page on.
2023-05-19 20:42:46 +07:00
Naz
2d1eb881fc Extended save method to return saved collection data
refs https://github.com/TryGhost/Team/issues/3167

- The core client (API) needs a way to pass in information without an ID when creating a new entity, handling it on service/repository layer makes the most sense.
- Used "require" syntax to import tpl/errors modules, otherwise TS compiler was complaining about type compatibility issues, this works as a temporary workaround and is tracked and an issue to improve in the future.
2023-05-19 20:42:46 +07:00
Naz
d4a5dac758 Exposed in-memory collections repository
refs https://github.com/TryGhost/Team/issues/3167

- The repository is needed when initializing the collections service from the core
2023-05-19 20:42:46 +07:00
Naz
2a16b1427d
Removed stray tsconfig.tsbuildinfo file
refs 69ce97268e

- This file should not have gotten into the source code from the get co
2023-05-16 13:08:57 +07:00
Naz
4e2a00b6e6 Added a collections package with CRUD logic
closes https://github.com/TryGhost/Team/issues/3166

- The collections service contains CRUD logic to manage collection entities through: save, getById, getAll, and destroy methods.
2023-05-16 12:21:31 +07:00