refactor: services: add compile-time checks for existence of CRUD methods #3199
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#3199
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right now every service has all the methods (
getAll
,create
,post
), but not all of them are actually implemented by all of the services. There is a runtime check:6aa02e29b1/src/services/abstractService.ts (L345-L347)
getAll
would throw if you were to call it onUserSettingsService
:2b82df5dbd/src/services/userSettings.ts (L4-L8)
would be nice if the property actually didn't exist instead. Or, IMO, better yet, if each CRUD method was exported separately somehow, for better modularity and ease to see what's used (and unused) where (yes I'm an OOP hater). Also the fact that
loading
is shared for all the CRUD methods is weird to me.Explicitly listing supported query parameters would also be cool.
Do you have an idea on how to do this without much boilerplate?
I didn't think too much about it, but I'm sure it shouldn't be exceptionally hard.
I was thinking about initially inferring the available methods from the
Paths
object provided to the constructor (e.g. if there's nogetAll
property then thegetAll
method should returnnever
), but I haven't come up with a way to fit it in the class paradigm properly.That sounds like it could work (can't say this 100% sure due to my lack of ts knowledge). What's preventing you to fit this in the class paradigm?
@dpschen Do you have any idea about this?
I kinda tried a bit, but then gave up. Should be possible.
@konrad Yes. We talked about this a while ago.
I would love to have something like this:
This takes heavy inspiration from: https://stackblitz.com/edit/axios-actions-ts?devToolsHeight=100&file=src%2Flib.ts%2Csrc%2Fmain.ts
Zodiac does a good job. Sadly it's still axios based and I really would like to replace axios / make that fetcher independent. I would prefer using native fetch or something like ky. In v11 they want to allow this though.