Skip to content

API between frontend and backend#499

Merged
hummingly merged 22 commits into
masterfrom
api
Aug 14, 2022
Merged

API between frontend and backend#499
hummingly merged 22 commits into
masterfrom
api

Conversation

@hummingly

@hummingly hummingly commented Aug 7, 2022

Copy link
Copy Markdown
Collaborator

Don't panic the majority of the changes just move and/or rename types. That said there are now a lot more types and interfaces.

Notable Changes

  • Shared types between frontend and backend in api module: DTO suffix stands for data transfer object (thread safe and plain objects; no proxy or function object).
  • Remove ISerializable interface: It was never used in any function signature and we have data transfer objects, which are much looser coupled.
  • Use interfaces instead of concrete backend types: This way nothing from the frontend modules depends on the backend modules. Furthermore, having interfaces enables us to write test framework agnostic tests in the future. I consider this a good thing and we should consider moving away from mocking to DI instead (https://dpc.pw/my-case-against-mocking-frameworks).
  • Differentiate between query condition and serialized search criteria: Searializing a tag search criteria is lossy. That means if the criteria operation is contains recursively and the tag has no sub tags it will be stored and loaded as contains. This is problematic if later a user adds a sub tag as the saved search will return wrong results, making the UX worse. I plan to tackle this in the next PR by changing the data layout of serialized search criterias.
  • Remove generic type parameter on ClientBaseSearchCriteria: The ConditionDTO type is generic over the entity but our search criteria objects do not need to be. We only use it for files and it is very unlikely to happen for any other entity. Without generics the code becomes simpler.
  • Cleanup and fix bug in backend implementation: The order direction was not correctly applied. Otherwise, it was just some refactoring.
  • Split the Messaging file: Honestly, those build errors always make me paranoid if we import something into the wrong process. So, I split the file in the hopes of less weird build errors.

Ignorable Changes

  • Anything in the widgets folder. I was just trying to fix build errors.

@hummingly hummingly marked this pull request as ready for review August 9, 2022 22:11
@hummingly hummingly requested a review from RvanderLaan August 9, 2022 22:11

@RvanderLaan RvanderLaan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 noice. Didn't really notice any functional changes, and I agree with your restructuring choices!

What might be handy: To preserve the file/import structure and enforce the right use of it, you could look into eslint rules like this one https://github.com/javierbrea/eslint-plugin-boundaries

What do you reckon is best for the order of merging PRs? Probably this one first, eh?

Comment thread src/api/data-storage.ts
clear: () => Promise<void>;
backupToFile: (path: string) => Promise<void>;
restoreFromFile: (path: string) => Promise<void>;
peekFile: (path: string) => Promise<[numTags: number, numFiles: number]>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cool to have an API like this for all filesystem calls too, so we can implement another back-end for it when running in a web browser. Some day...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some day soonTM? It seems like a simple change that can improve the code base quality quite a lot. At least make the goal of testable code come closer.

We could define a file IO interface and then pass an object implementing it around. In tests we could have some mock implementation that stores a map from absolute path to bytes and then a tree of paths for matching file paths.

Comment thread src/backend/backend.ts
}

async peekDatabaseFile(path: string): Promise<{ numTags: number; numFiles: number }> {
async peekFile(path: string): Promise<[numTags: number, numFiles: number]> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat, I've seen them around, but didn't realise you could do named array values like this.

@hummingly

Copy link
Copy Markdown
Collaborator Author

👏 noice. Didn't really notice any functional changes, and I agree with your restructuring choices!

What might be handy: To preserve the file/import structure and enforce the right use of it, you could look into eslint rules like this one https://github.com/javierbrea/eslint-plugin-boundaries

What do you reckon is best for the order of merging PRs? Probably this one first, eh?

I took a look and I will merge this first because the other PRs are mostly unaffected.

@hummingly hummingly merged commit 0acabc5 into master Aug 14, 2022
@hummingly hummingly deleted the api branch August 14, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants