scalecube-js
scalecube-js copied to clipboard
🎁 simpler API
General description
Scalecube requires a lot of setups to start
- when bootstrapping a microservice container the service definition can be optional. when it's not passed then all the reference<->definition validation should be skipped,
instead of createProxy we should use getService which get
type getService = (qualifier : string) => ServiceInvokation
interface ServiceInvokation {
subscribe: ()=> Observable<any>
then: () => Promise<any>
}
API
Design description
A clear and concise description of the design proposition.
- Is it a breaking change (not backward compatible)? no
- Is it adds new API? yes
- Is it changes existing API? yes
- Is it removes existing API? yes
Changes
old
interface Service {
/**
* @property
* The metadata for a service, that includes the name of a service and the map of methods that are
* included in it
*/
definition: ServiceDefinition;
/**
* @property
* The implementation of a service, that can be an object with methods or a module with a function being exported
*/
reference: ServiceReference;
}
interface Microservice {
/**
* @method destroy
* The method is used to delete a microservice and close all the subscriptions related with it
*/
destroy: () => Promise<any>;
/**
* @method createProxy
* Creates a proxy to a method and provides extra logic when is invoked
*/
createProxy: CreateProxy;
/**
* @method createServiceCall
* Exposes serviceCall to a user (not via Proxy)
*/
createServiceCall: CreateServiceCall;
}
new
interface Service {
/**
* @property
* The metadata for a service, that includes the name of a service and the map of methods that are
* included in it
*/
definition ?: ServiceDefinition;
/**
* @property
* The implementation of a service, that can be an object with methods or a module with a function being exported
*/
reference: ServiceReference;
}
interface Microservice {
/**
* @method destroy
* The method is used to delete a microservice and close all the subscriptions related with it
*/
destroy: () => Promise<any>;
/**
* @method getService
* Creates a proxy to a method and provides extra logic when is invoked
*/
getService: GetService;
/**
* @method createServiceCall
* Exposes serviceCall to a user (not via Proxy)
*/
createServiceCall: CreateServiceCall;
}
Behavior
Consideration
List of everything to consider before writing test cases.
Test cases
Add test case that are written in Gherkin Syntax and cover all the possible scenarios.
DoR
- [ ] API has been approved
- [ ] Test cases have been prepared
- [ ] Discussed with Technical lead
@katzIdo I don't think it should be instead, it should be in addition Actually, the current API of SC has two methods createProxy and createServiceCall createServiceCall is similar to what you are suggesting:
ms.createServiceCall().requestStream(Message).subscribe(...);
ms.createServiceCall().requestResponse(Message).then(...);
I suggest leaving the old API as is and add:
interface ServiceInvokation {
then: ServiceCall.requestResponse.then,
subscribe: ServiceCall.requestStream.subscribe,
}
interface Microservice {
// ...
invoke(qualifier: Message.qualifier, ...args: Message.data): ServiceInvokation;
}
But let's leave for now until we have any request