Templates SDK JS - Use classes instead of interface#891
Templates SDK JS - Use classes instead of interface#891mishushakov wants to merge 93 commits intomainfrom
Conversation
… template index.ts
…httpx_args; update timestamp logging in AsyncTemplate and Template classes to use datetime.now() instead of datetime.utcnow().
…move unused imports and update test cases to reflect changes.
|
it doesn't have to because base image will always be specified |
| def get_template_base(self) -> "TemplateBase": | ||
| return self.__template |
There was a problem hiding this comment.
because I made template private property, I think it's better this way because you're explicitly have to call the function so you see where the template builder is coming from
There was a problem hiding this comment.
Bug: Template Class Undefined, Serialization Validation Missing
The TemplateClass type is undefined, causing compilation errors for static methods. The Template() factory function also returns TemplateBase, which doesn't implement getTemplateBase() as expected by these methods. Additionally, the serialize method no longer validates that a template specifies either fromImage or fromTemplate, which could lead to invalid template data for the build API.
packages/js-sdk/src/template/index.ts#L551-L579
E2B/packages/js-sdk/src/template/index.ts
Lines 551 to 579 in acccb35
packages/js-sdk/src/template/index.ts#L311-L347
E2B/packages/js-sdk/src/template/index.ts
Lines 311 to 347 in acccb35
Change
In JavaScript specifically this is implemented using interfaces unlike classes in Python. I've found some issues with the interfaces-based approach - you're able to pass empty TemplateBase to Template.build when you are not supposed to and also there was also much duplication in types.ts.
It's also probably not safe at all when using pure JS without TypeScript as you won't see compiler errors.
it was working until this point, because we had other methods on the TemplateFinal interface, but it's now empty so it doesn't match anything anymore.