That looks like an API definition. It's pretty common for APIs to support multiple versions of an operation at the same time to keep backwards compatibility with existing clients.
V2 at the beginning could be major API version (eg the API was entirely rewritten to some new paradigm). The v2 at the end could be a specific function that had breaking updates.
I think if you want to add a v2 implementation to a service, you just re-implement the service without changing the interface naming. It's the whole point of dependency injection. Unless the v2 is a significant departure from the format of V1 with totally new DTOs
If you control both sides of the equation then sure, you can refactor to your heart's content. But as soon as you have external clients, be it in a library or web service, you can't just go changing things willy-nilly. You have to provide some sort of backwards compatibility guarantee or external clients will break every time you push a new update.
The usual way to do this is to keep the old version around, mark it as deprecated, and provide a new version. Then, once enough time has passed and external clients have had time to move to the new version, you remove the old version.
Assuming "namespacing" here means putting different versions in different folders/packages:
Sure that works, but then you end up having to use aliased imports in code that needs to reference both (such as the global route configuration), and you add cognitive overhead for developers because they now have to check the import list or current folder every time they read some piece of code. It might even lead to accidental uses of the wrong version due to auto-import features in modern IDEs.
I'm not saying it's a bad solution, just that it's not objectively better than just slapping a "V2" on the class/function name. As usual, there are pros and cons.
API versioning and version control are two completely different things, this is a very common pattern in NestJS, in v9 you can do @Controller({ version: '1' }); please investigate before posting
Am I correct in that the decorators for parameter definitions exist so that argument values are passed through them before entering the function?
Haven't used TypeScript before, so they are a new sight to me... But if I'm right about their usage, they seem like a convenient way to validate/transform/extend argument values, or possibly provide dynamically computed defaults for missing/null arguments.
77
u/Davipb Jun 08 '23
That looks like an API definition. It's pretty common for APIs to support multiple versions of an operation at the same time to keep backwards compatibility with existing clients.
I don't think this is an issue.
31
u/dandesigns7150 Jun 08 '23
This is just API versioning. Not something you can manage with version control
17
u/yn4v4s Jun 08 '23
API versioning and version control are two completely different things, this is a very common pattern in NestJS, in v9 you can do @Controller({ version: '1' }); please investigate before posting
5
u/ComfortablyBalanced Jun 08 '23
What language is that? It's very similar to Retrofit APIs.
2
u/SpaceshipOperations Jun 08 '23
Am I correct in that the decorators for parameter definitions exist so that argument values are passed through them before entering the function?
Haven't used TypeScript before, so they are a new sight to me... But if I'm right about their usage, they seem like a convenient way to validate/transform/extend argument values, or possibly provide dynamically computed defaults for missing/null arguments.
1
u/windswept_mystical Jun 09 '23
LGTM
1
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jun 08 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
-6
u/Fyren-1131 Jun 08 '23
oh no...