-
Notifications
You must be signed in to change notification settings - Fork 15
Add type configuration support to the typescript cli plugin #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce487dc
13040bd
322e23e
a302fd9
de44f36
5f33a63
76aa7be
b503e7a
9938c3e
4564d3a
7098a11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,3 +139,5 @@ tests/**/*.d.ts | |
# Node.js | ||
node_modules/ | ||
coverage/ | ||
|
||
*.iml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,13 +161,24 @@ def generate(self, project): | |
|
||
models = resolve_models(project.schema) | ||
|
||
if project.configuration_schema: | ||
configuration_models = resolve_models( | ||
project.configuration_schema, "TypeConfigurationModel" | ||
) | ||
Comment on lines
+165
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be great to achieve parity with other plugins: configuration_schema_path =project.root / project.configuration_schema_filename
project.write_configuration_schema(configuration_schema_path) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ammokhov Not sure what this does. As far as I know, we want all the models, |
||
else: | ||
configuration_models = {"TypeConfigurationModel": {}} | ||
|
||
models.update(configuration_models) | ||
|
||
path = self.package_root / "models.ts" | ||
LOG.debug("Writing file: %s", path) | ||
template = self.env.get_template("models.ts") | ||
|
||
contents = template.render( | ||
lib_name=SUPPORT_LIB_NAME, | ||
type_name=project.type_name, | ||
models=models, | ||
contains_type_configuration=project.configuration_schema, | ||
primaryIdentifier=project.schema.get("primaryIdentifier", []), | ||
additionalIdentifiers=project.schema.get("additionalIdentifiers", []), | ||
) | ||
|
@@ -176,6 +187,8 @@ def generate(self, project): | |
LOG.debug("Generate complete") | ||
|
||
def _pre_package(self, build_path): | ||
# Caller should own/delete this, not us. | ||
# pylint: disable=consider-using-with | ||
f = TemporaryFile("w+b") | ||
|
||
# pylint: disable=unexpected-keyword-arg | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { | |
ResourceHandlerRequest, | ||
SessionProxy, | ||
} from '{{lib_name}}'; | ||
import { ResourceModel } from './models'; | ||
import { ResourceModel, TypeConfigurationModel } from './models'; | ||
ammokhov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
interface CallbackContext extends Record<string, any> {} | ||
|
||
|
@@ -25,14 +25,17 @@ class Resource extends BaseResource<ResourceModel> { | |
* @param request The request object for the provisioning request passed to the implementor | ||
* @param callbackContext Custom context object to allow the passing through of additional | ||
* state or metadata between subsequent retries | ||
* @param typeConfiguration Configuration data for this resource type, in the given account | ||
* and region | ||
* @param logger Logger to proxy requests to default publishers | ||
*/ | ||
@handlerEvent(Action.Create) | ||
public async create( | ||
session: Optional<SessionProxy>, | ||
request: ResourceHandlerRequest<ResourceModel>, | ||
callbackContext: CallbackContext, | ||
logger: LoggerProxy | ||
logger: LoggerProxy, | ||
typeConfiguration: TypeConfigurationModel, | ||
): Promise<ProgressEvent<ResourceModel, CallbackContext>> { | ||
const model = new ResourceModel(request.desiredResourceState); | ||
const progress = ProgressEvent.progress<ProgressEvent<ResourceModel, CallbackContext>>(model); | ||
|
@@ -63,14 +66,17 @@ class Resource extends BaseResource<ResourceModel> { | |
* @param request The request object for the provisioning request passed to the implementor | ||
* @param callbackContext Custom context object to allow the passing through of additional | ||
* state or metadata between subsequent retries | ||
* @param typeConfiguration Configuration data for this resource type, in the given account | ||
* and region | ||
* @param logger Logger to proxy requests to default publishers | ||
*/ | ||
@handlerEvent(Action.Update) | ||
public async update( | ||
session: Optional<SessionProxy>, | ||
request: ResourceHandlerRequest<ResourceModel>, | ||
callbackContext: CallbackContext, | ||
logger: LoggerProxy | ||
logger: LoggerProxy, | ||
typeConfiguration: TypeConfigurationModel, | ||
): Promise<ProgressEvent<ResourceModel, CallbackContext>> { | ||
const model = new ResourceModel(request.desiredResourceState); | ||
const progress = ProgressEvent.progress<ProgressEvent<ResourceModel, CallbackContext>>(model); | ||
|
@@ -88,14 +94,17 @@ class Resource extends BaseResource<ResourceModel> { | |
* @param request The request object for the provisioning request passed to the implementor | ||
* @param callbackContext Custom context object to allow the passing through of additional | ||
* state or metadata between subsequent retries | ||
* @param typeConfiguration Configuration data for this resource type, in the given account | ||
* and region | ||
* @param logger Logger to proxy requests to default publishers | ||
*/ | ||
@handlerEvent(Action.Delete) | ||
public async delete( | ||
session: Optional<SessionProxy>, | ||
request: ResourceHandlerRequest<ResourceModel>, | ||
callbackContext: CallbackContext, | ||
logger: LoggerProxy | ||
logger: LoggerProxy, | ||
typeConfiguration: TypeConfigurationModel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean about changing the order. You guys are the experts on TypeScript here, but curious as to why we cannot use syntax like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i also wondered why what we had wanted to do and did previously was to include the previous versions of the framework code of course call the old signature, ie in the test failure we were seeing, that old framework code is running, making that exact call, but against a handler ^ based on the new template, expecting the new signature, so with the changes we had made earlier it thinks the 4th parameter is a in the new code because we haven't changed any existing fields, just appended a new 5th, it quite happily accepts calls from the old framework to new code or even new framework to old code -- in the former case it calls the signature with 4 arguments, and those args match, and it passes |
||
): Promise<ProgressEvent<ResourceModel, CallbackContext>> { | ||
const model = new ResourceModel(request.desiredResourceState); | ||
const progress = ProgressEvent.progress<ProgressEvent<ResourceModel, CallbackContext>>(); | ||
|
@@ -112,14 +121,17 @@ class Resource extends BaseResource<ResourceModel> { | |
* @param request The request object for the provisioning request passed to the implementor | ||
* @param callbackContext Custom context object to allow the passing through of additional | ||
* state or metadata between subsequent retries | ||
* @param typeConfiguration Configuration data for this resource type, in the given account | ||
* and region | ||
* @param logger Logger to proxy requests to default publishers | ||
*/ | ||
@handlerEvent(Action.Read) | ||
public async read( | ||
session: Optional<SessionProxy>, | ||
request: ResourceHandlerRequest<ResourceModel>, | ||
callbackContext: CallbackContext, | ||
logger: LoggerProxy | ||
logger: LoggerProxy, | ||
typeConfiguration: TypeConfigurationModel, | ||
): Promise<ProgressEvent<ResourceModel, CallbackContext>> { | ||
const model = new ResourceModel(request.desiredResourceState); | ||
// TODO: put code here | ||
|
@@ -135,14 +147,17 @@ class Resource extends BaseResource<ResourceModel> { | |
* @param request The request object for the provisioning request passed to the implementor | ||
* @param callbackContext Custom context object to allow the passing through of additional | ||
* state or metadata between subsequent retries | ||
* @param typeConfiguration Configuration data for this resource type, in the given account | ||
* and region | ||
* @param logger Logger to proxy requests to default publishers | ||
*/ | ||
@handlerEvent(Action.List) | ||
public async list( | ||
session: Optional<SessionProxy>, | ||
request: ResourceHandlerRequest<ResourceModel>, | ||
callbackContext: CallbackContext, | ||
logger: LoggerProxy | ||
logger: LoggerProxy, | ||
typeConfiguration: TypeConfigurationModel, | ||
): Promise<ProgressEvent<ResourceModel, CallbackContext>> { | ||
const model = new ResourceModel(request.desiredResourceState); | ||
// TODO: put code here | ||
|
@@ -154,7 +169,8 @@ class Resource extends BaseResource<ResourceModel> { | |
} | ||
} | ||
|
||
export const resource = new Resource(ResourceModel.TYPE_NAME, ResourceModel); | ||
// @ts-ignore // if running against v1.0.1 or earlier of plugin the 5th argument is not known but best to ignored (runtime code may warn) | ||
export const resource = new Resource(ResourceModel.TYPE_NAME, ResourceModel, null, null, TypeConfigurationModel)!; | ||
|
||
// Entrypoint for production usage after registered in CloudFormation | ||
export const entrypoint = resource.entrypoint; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this indent accidental? if so, is it possible to remove this file from the commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably an IDE did that automatically or a linter wanted it. yaml doesn't care and conventions vary whether list items should be indented two spaces or not. i note all the other blocks in this file do indent list items so this change makes it consistent. i'd recommend keeping but happy to remove if you prefer.