You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the Proof of Concept (PoC) phase, specific Client implementation classes were created through the resource type's buildClient method, while specific Infra implementation classes were registered in the Registry and then retrieved by querying the Registry based on platform and engine type. Both of these methods introduced additional cognitive load for SDK developers, requiring an understanding of the specific creation methods and adding extra logic to Pluto's implementation. Simplification in this area could be explored.
// Resource Client exportclassQueueimplementsResource{constructor(name: string,opts?: QueueOptions){name;opts;thrownewError("Cannot instantiate this class, instead of its subclass depending on the target runtime.");}publicstaticbuildClient(name: string,opts?: QueueClientOptions): QueueClient{constrtType=process.env["RUNTIME_TYPE"];switch(rtType){caseruntime.Type.AWS:
returnnewaws.SNSQueue(name,opts);caseruntime.Type.K8s:
returnnewk8s.RedisQueue(name,opts);caseruntime.Type.Simulator:
if(!process.env.PLUTO_SIMULATOR_URL)thrownewError("PLUTO_SIMULATOR_URL doesn't exist");returnsimulator.makeSimulatorClient(process.env.PLUTO_SIMULATOR_URL!,name);default:
thrownewError(`not support this runtime '${rtType}'`);}}}// Resource Infraexportfunctionregister(reg: Registry){reg.register(runtime.Type.AWS,engine.Type.pulumi,Router,aws.ApiGatewayRouter);reg.register(runtime.Type.AWS,engine.Type.pulumi,KVStore,aws.DynamoKVStore);reg.register(runtime.Type.AWS,engine.Type.pulumi,Queue,aws.SNSQueue);reg.register(runtime.Type.AWS,engine.Type.pulumi,Schedule,aws.CloudWatchSchedule);reg.register(runtime.Type.AWS,engine.Type.pulumi,"FnResource",aws.Lambda);reg.register(runtime.Type.AWS,engine.Type.pulumi,Tester,aws.Tester);}
We can place the logic for selecting the specific implementation class within the constructor, allowing SDK developers to manage this process. By eliminating Registry and buildClient, Pluto would no longer have to add extra logic for handling type conversion and could instead focus solely on maintaining user code.
We'd like to instantiate the implementation classes asynchronously, which can help cut down on package loading costs. This process will be encapsulated within an asynchronous function, often referred to as a 'lazy importing' function. However, in JavaScript, it's not feasible to call an async function within a constructor.
So we've come up with a solution where each resource has an abstract base class at the root of the infra SDK and includes a static async method named createInstance. This method serves to create instances of resource infrastructure implementation classes based on the target platform and engine.
Not only does this strategy streamline operations, but it also allows SDK developers to concentrate more effectively on their tasks.
The stipulation is that the parameters for both the client implementation class and infrastructure implementation class of a resource, along with those of the createInstance method from its base class, must all be consistent.
abstractclassQueue{publicstaticasynccreateInstance(name,opts){if(currentPlatform=="AWS"){returnnewSNSQueue(name,opts);}elseif(...){// ...}}}classSNSQueue{publicsubscribe(handler: any){// do something...}}
The text was updated successfully, but these errors were encountered:
jianzs
changed the title
Move the selection of specific implementation classes to the constructor of base class
Move the selection of specific implementation classes to the static method within the base classes
Jan 11, 2024
After #122, the instance of the resource infrastructure implementation class will be instantiated asynchronously. The creation process is completed within the createInstance method.
However, instances of the resource client are still created synchronously. This is because users may instantiate a resource object in global scope. We can't simply change constructor invocation to asynchronous method buildClient. In CommonJS, it's not practical to call an asynchronous function in global scope.
During the Proof of Concept (PoC) phase, specific Client implementation classes were created through the resource type's
buildClient
method, while specific Infra implementation classes were registered in the Registry and then retrieved by querying the Registry based on platform and engine type. Both of these methods introduced additional cognitive load for SDK developers, requiring an understanding of the specific creation methods and adding extra logic to Pluto's implementation. Simplification in this area could be explored.We can place the logic for selecting the specific implementation class within the constructor, allowing SDK developers to manage this process. By eliminating Registry and buildClient, Pluto would no longer have to add extra logic for handling type conversion and could instead focus solely on maintaining user code.We'd like to instantiate the implementation classes asynchronously, which can help cut down on package loading costs. This process will be encapsulated within an asynchronous function, often referred to as a 'lazy importing' function. However, in JavaScript, it's not feasible to call an async function within a constructor.
So we've come up with a solution where each resource has an abstract base class at the root of the infra SDK and includes a static async method named
createInstance
. This method serves to create instances of resource infrastructure implementation classes based on the target platform and engine.Not only does this strategy streamline operations, but it also allows SDK developers to concentrate more effectively on their tasks.
The stipulation is that the parameters for both the client implementation class and infrastructure implementation class of a resource, along with those of the
createInstance
method from its base class, must all be consistent.The text was updated successfully, but these errors were encountered: