Versioning is implemented as a plugin that users can opt into so that there is a simple on-ramp without a bunch of boilerplate.
A user would start with the simplest possible code for a service.
Studio(function serviceA() {
return Math.random();
});
Sometime in the future, a user decides that they want to change a version of the service but leaves the old instance in tact until they can modify all the rest of their services.
// Now you introduce ServiceVersions as plugin
Studio.use(ServiceVersions);
// Legacy service
Studio(function serviceA() {
return Math.random();
}).version('0.0.0');
// New and improved service
Studio(function serviceA() {
return Math.random() + 1;
}).version('2.0.0');
// Reference a service by version in newer services
var serviceA = Studio('serviceA').version("~2.0.0");
Required Modification to core:
- The Studiojs router automatically prepends each route with a version number (defaulted to 0.0.0 in case the ServiceVersion plugin is not used).
- Studiojs router uses SemVer to match the proper version of a service request to the right route (based on ^, ~, =, >=, etc) just like npm does
When no versions exist in the environment all routes work exactly the same way but assume all versions are 0.0.0 When the versions plugin is used, the user would opt individual call sites with an upgraded version based on a SemVer expression like npm.
This could work in a mixed environment (e.g. in a Studio-cluster) as well.