Make resource names the first constructor parameter

This reverts back to the old style of having the resource name as its
first parameter in the generated package.  Stylistically, this reads a
little nicer, and also ensures we don't need to rewrite all our existing
samples/test cases, etc.
This commit is contained in:
joeduffy 2017-04-29 15:58:34 -07:00
parent fa24d436e3
commit 0e16aa5d93
40 changed files with 175 additions and 194 deletions

View file

@ -9,18 +9,17 @@ export class Account extends coconut.Resource implements AccountArgs {
public readonly name: string;
public cloudWatchRole?: Role;
constructor(args: AccountArgs) {
constructor(name: string, args: AccountArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.cloudWatchRole = args.cloudWatchRole;
}
}
export interface AccountArgs {
readonly name: string;
cloudWatchRole?: Role;
}

View file

@ -13,12 +13,12 @@ export class APIKey extends coconut.Resource implements APIKeyArgs {
public enabled?: boolean;
public stageKeys?: StageKey;
constructor(args: APIKeyArgs) {
constructor(name: string, args: APIKeyArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.keyName = args.keyName;
this.description = args.description;
this.enabled = args.enabled;
@ -27,7 +27,6 @@ export class APIKey extends coconut.Resource implements APIKeyArgs {
}
export interface APIKeyArgs {
readonly name: string;
readonly keyName?: string;
description?: string;
enabled?: boolean;

View file

@ -20,12 +20,12 @@ export class Authorizer extends coconut.Resource implements AuthorizerArgs {
public providers?: coconut.Resource[];
public restAPI?: RestAPI;
constructor(args: AuthorizerArgs) {
constructor(name: string, args: AuthorizerArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.type === undefined) {
throw new Error("Missing required argument 'type'");
}
@ -41,7 +41,6 @@ export class Authorizer extends coconut.Resource implements AuthorizerArgs {
}
export interface AuthorizerArgs {
readonly name: string;
type: AuthorizerType;
authorizerCredentials?: Role;
authorizerResultTTLInSeconds?: number;

View file

@ -13,12 +13,12 @@ export class BasePathMapping extends coconut.Resource implements BasePathMapping
public basePath?: string;
public stage?: Stage;
constructor(args: BasePathMappingArgs) {
constructor(name: string, args: BasePathMappingArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.domainName === undefined) {
throw new Error("Missing required argument 'domainName'");
}
@ -33,7 +33,6 @@ export class BasePathMapping extends coconut.Resource implements BasePathMapping
}
export interface BasePathMappingArgs {
readonly name: string;
domainName: string;
restAPI: RestAPI;
basePath?: string;

View file

@ -7,18 +7,17 @@ export class ClientCertificate extends coconut.Resource implements ClientCertifi
public readonly name: string;
public description?: string;
constructor(args: ClientCertificateArgs) {
constructor(name: string, args: ClientCertificateArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.description = args.description;
}
}
export interface ClientCertificateArgs {
readonly name: string;
description?: string;
}

View file

@ -14,12 +14,12 @@ export class Deployment extends coconut.Resource implements DeploymentArgs {
public stageDescription?: StageDescription;
public stageName?: string;
constructor(args: DeploymentArgs) {
constructor(name: string, args: DeploymentArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.restAPI === undefined) {
throw new Error("Missing required argument 'restAPI'");
}
@ -31,7 +31,6 @@ export class Deployment extends coconut.Resource implements DeploymentArgs {
}
export interface DeploymentArgs {
readonly name: string;
restAPI: RestAPI;
description?: string;
stageDescription?: StageDescription;

View file

@ -75,12 +75,12 @@ export class Method extends coconut.Resource implements MethodArgs {
public requestModels?: {[key: string]: Model};
public requestParameters?: {[key: string]: boolean};
constructor(args: MethodArgs) {
constructor(name: string, args: MethodArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.httpMethod === undefined) {
throw new Error("Missing required argument 'httpMethod'");
}
@ -104,7 +104,6 @@ export class Method extends coconut.Resource implements MethodArgs {
}
export interface MethodArgs {
readonly name: string;
httpMethod: string;
apiResource: Resource;
restAPI: RestAPI;

View file

@ -13,12 +13,12 @@ export class Model extends coconut.Resource implements ModelArgs {
public readonly modelName?: string;
public description?: string;
constructor(args: ModelArgs) {
constructor(name: string, args: ModelArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.contentType === undefined) {
throw new Error("Missing required argument 'contentType'");
}
@ -37,7 +37,6 @@ export class Model extends coconut.Resource implements ModelArgs {
}
export interface ModelArgs {
readonly name: string;
readonly contentType: string;
readonly restAPI: RestAPI;
schema: any;

View file

@ -11,12 +11,12 @@ export class Resource extends coconut.Resource implements ResourceArgs {
public readonly pathPart: string;
public readonly restAPI: RestAPI;
constructor(args: ResourceArgs) {
constructor(name: string, args: ResourceArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.parent === undefined) {
throw new Error("Missing required argument 'parent'");
}
@ -33,7 +33,6 @@ export class Resource extends coconut.Resource implements ResourceArgs {
}
export interface ResourceArgs {
readonly name: string;
readonly parent: Resource;
readonly pathPart: string;
readonly restAPI: RestAPI;

View file

@ -15,12 +15,12 @@ export class RestAPI extends coconut.Resource implements RestAPIArgs {
public apiName?: string;
public parameters?: string[];
constructor(args: RestAPIArgs) {
constructor(name: string, args: RestAPIArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.body = args.body;
this.bodyS3Location = args.bodyS3Location;
this.cloneFrom = args.cloneFrom;
@ -32,7 +32,6 @@ export class RestAPI extends coconut.Resource implements RestAPIArgs {
}
export interface RestAPIArgs {
readonly name: string;
body?: any;
bodyS3Location?: S3Location;
cloneFrom?: RestAPI;

View file

@ -20,12 +20,12 @@ export class Stage extends coconut.Resource implements StageArgs {
public methodSettings?: MethodSetting[];
public variables?: {[key: string]: string};
constructor(args: StageArgs) {
constructor(name: string, args: StageArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.restAPI === undefined) {
throw new Error("Missing required argument 'restAPI'");
}
@ -48,7 +48,6 @@ export class Stage extends coconut.Resource implements StageArgs {
}
export interface StageArgs {
readonly name: string;
readonly restAPI: RestAPI;
readonly stageName: string;
deployment: Deployment;

View file

@ -39,12 +39,12 @@ export class UsagePlan extends coconut.Resource implements UsagePlanArgs {
public throttle?: ThrottleSettings;
public usagePlanName?: string;
constructor(args: UsagePlanArgs) {
constructor(name: string, args: UsagePlanArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.apiStages = args.apiStages;
this.description = args.description;
this.quota = args.quota;
@ -54,7 +54,6 @@ export class UsagePlan extends coconut.Resource implements UsagePlanArgs {
}
export interface UsagePlanArgs {
readonly name: string;
apiStages?: APIStage[];
description?: string;
quota?: QuotaSettings;

View file

@ -11,12 +11,12 @@ export class UsagePlanKey extends coconut.Resource implements UsagePlanKeyArgs {
public readonly key: APIKey;
public readonly usagePlan: UsagePlan;
constructor(args: UsagePlanKeyArgs) {
constructor(name: string, args: UsagePlanKeyArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.key === undefined) {
throw new Error("Missing required argument 'key'");
}
@ -29,7 +29,6 @@ export class UsagePlanKey extends coconut.Resource implements UsagePlanKeyArgs {
}
export interface UsagePlanKeyArgs {
readonly name: string;
readonly key: APIKey;
readonly usagePlan: UsagePlan;
}

View file

@ -48,12 +48,12 @@ export class ActionTarget extends coconut.Resource implements ActionTargetArgs {
public displayName?: string;
public subscription?: TopicSubscription[];
constructor(args: ActionTargetArgs) {
constructor(name: string, args: ActionTargetArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.topicName = args.topicName;
this.displayName = args.displayName;
this.subscription = args.subscription;
@ -61,7 +61,6 @@ export class ActionTarget extends coconut.Resource implements ActionTargetArgs {
}
export interface ActionTargetArgs {
readonly name: string;
readonly topicName?: string;
displayName?: string;
subscription?: TopicSubscription[];
@ -85,12 +84,12 @@ export class Alarm extends coconut.Resource implements AlarmArgs {
public okActions?: ActionTarget[];
public unit?: AlarmMetric;
constructor(args: AlarmArgs) {
constructor(name: string, args: AlarmArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.comparisonOperator === undefined) {
throw new Error("Missing required argument 'comparisonOperator'");
}
@ -131,7 +130,6 @@ export class Alarm extends coconut.Resource implements AlarmArgs {
}
export interface AlarmArgs {
readonly name: string;
comparisonOperator: AlarmComparisonOperator;
evaluationPerids: number;
metricName: string;

View file

@ -75,12 +75,12 @@ export class Instance extends coconut.Resource implements InstanceArgs {
public privateIP?: string;
public publicIP?: string;
constructor(args: InstanceArgs) {
constructor(name: string, args: InstanceArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.imageId === undefined) {
throw new Error("Missing required argument 'imageId'");
}
@ -92,7 +92,6 @@ export class Instance extends coconut.Resource implements InstanceArgs {
}
export interface InstanceArgs {
readonly name: string;
imageId: string;
instanceType?: InstanceType;
securityGroups?: SecurityGroup[];

View file

@ -6,17 +6,16 @@ import * as coconut from "@coconut/coconut";
export class InternetGateway extends coconut.Resource implements InternetGatewayArgs {
public readonly name: string;
constructor(args: InternetGatewayArgs) {
constructor(name: string, args: InternetGatewayArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
}
}
export interface InternetGatewayArgs {
readonly name: string;
}

View file

@ -14,12 +14,12 @@ export class Route extends coconut.Resource implements RouteArgs {
public readonly internetGateway: InternetGateway;
public readonly vpcGatewayAttachment: VPCGatewayAttachment;
constructor(args: RouteArgs) {
constructor(name: string, args: RouteArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.destinationCidrBlock === undefined) {
throw new Error("Missing required argument 'destinationCidrBlock'");
}
@ -40,7 +40,6 @@ export class Route extends coconut.Resource implements RouteArgs {
}
export interface RouteArgs {
readonly name: string;
readonly destinationCidrBlock: string;
readonly routeTable: RouteTable;
readonly internetGateway: InternetGateway;

View file

@ -9,12 +9,12 @@ export class RouteTable extends coconut.Resource implements RouteTableArgs {
public readonly name: string;
public readonly vpc: VPC;
constructor(args: RouteTableArgs) {
constructor(name: string, args: RouteTableArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.vpc === undefined) {
throw new Error("Missing required argument 'vpc'");
}
@ -23,7 +23,6 @@ export class RouteTable extends coconut.Resource implements RouteTableArgs {
}
export interface RouteTableArgs {
readonly name: string;
readonly vpc: VPC;
}

View file

@ -13,12 +13,12 @@ export class SecurityGroup extends coconut.Resource implements SecurityGroupArgs
public securityGroupIngress?: SecurityGroupRule[];
public groupID: string;
constructor(args: SecurityGroupArgs) {
constructor(name: string, args: SecurityGroupArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.groupDescription === undefined) {
throw new Error("Missing required argument 'groupDescription'");
}
@ -30,7 +30,6 @@ export class SecurityGroup extends coconut.Resource implements SecurityGroupArgs
}
export interface SecurityGroupArgs {
readonly name: string;
readonly groupDescription: string;
readonly vpc?: VPC;
securityGroupEgress?: SecurityGroupRule[];

View file

@ -16,12 +16,12 @@ export class SecurityGroupEgress extends coconut.Resource implements SecurityGro
public readonly destinationPrefixListId?: string;
public readonly destinationSecurityGroup?: SecurityGroup;
constructor(args: SecurityGroupEgressArgs) {
constructor(name: string, args: SecurityGroupEgressArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.fromPort === undefined) {
throw new Error("Missing required argument 'fromPort'");
}
@ -46,7 +46,6 @@ export class SecurityGroupEgress extends coconut.Resource implements SecurityGro
}
export interface SecurityGroupEgressArgs {
readonly name: string;
readonly fromPort: number;
readonly group: SecurityGroup;
readonly ipProtocol: string;

View file

@ -18,12 +18,12 @@ export class SecurityGroupIngress extends coconut.Resource implements SecurityGr
public readonly sourceSecurityGroupOwnerId?: string;
public readonly toPort?: number;
constructor(args: SecurityGroupIngressArgs) {
constructor(name: string, args: SecurityGroupIngressArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.ipProtocol === undefined) {
throw new Error("Missing required argument 'ipProtocol'");
}
@ -41,7 +41,6 @@ export class SecurityGroupIngress extends coconut.Resource implements SecurityGr
}
export interface SecurityGroupIngressArgs {
readonly name: string;
readonly ipProtocol: string;
readonly cidrIp?: string;
readonly cidrIpv6?: string;

View file

@ -12,12 +12,12 @@ export class Subnet extends coconut.Resource implements SubnetArgs {
public readonly availabilityZone?: string;
public mapPublicIpOnLaunch?: boolean;
constructor(args: SubnetArgs) {
constructor(name: string, args: SubnetArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.cidrBlock === undefined) {
throw new Error("Missing required argument 'cidrBlock'");
}
@ -32,7 +32,6 @@ export class Subnet extends coconut.Resource implements SubnetArgs {
}
export interface SubnetArgs {
readonly name: string;
readonly cidrBlock: string;
readonly vpc: VPC;
readonly availabilityZone?: string;

View file

@ -19,12 +19,12 @@ export class VPC extends coconut.Resource implements VPCArgs {
public enableDnsSupport?: boolean;
public enableDnsHostnames?: boolean;
constructor(args: VPCArgs) {
constructor(name: string, args: VPCArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.cidrBlock === undefined) {
throw new Error("Missing required argument 'cidrBlock'");
}
@ -36,7 +36,6 @@ export class VPC extends coconut.Resource implements VPCArgs {
}
export interface VPCArgs {
readonly name: string;
readonly cidrBlock: string;
readonly instanceTenancy?: InstanceTenancy;
enableDnsSupport?: boolean;

View file

@ -11,12 +11,12 @@ export class VPCGatewayAttachment extends coconut.Resource implements VPCGateway
public readonly vpc: VPC;
public readonly internetGateway: InternetGateway;
constructor(args: VPCGatewayAttachmentArgs) {
constructor(name: string, args: VPCGatewayAttachmentArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.vpc === undefined) {
throw new Error("Missing required argument 'vpc'");
}
@ -29,7 +29,6 @@ export class VPCGatewayAttachment extends coconut.Resource implements VPCGateway
}
export interface VPCGatewayAttachmentArgs {
readonly name: string;
readonly vpc: VPC;
readonly internetGateway: InternetGateway;
}

View file

@ -10,12 +10,12 @@ export class VPCPeeringConnection extends coconut.Resource implements VPCPeering
public readonly peerVpc: VPC;
public readonly vpc: VPC;
constructor(args: VPCPeeringConnectionArgs) {
constructor(name: string, args: VPCPeeringConnectionArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.peerVpc === undefined) {
throw new Error("Missing required argument 'peerVpc'");
}
@ -28,7 +28,6 @@ export class VPCPeeringConnection extends coconut.Resource implements VPCPeering
}
export interface VPCPeeringConnectionArgs {
readonly name: string;
readonly peerVpc: VPC;
readonly vpc: VPC;
}

View file

@ -12,12 +12,12 @@ export class Group extends coconut.Resource implements GroupArgs {
public path?: string;
public policies?: InlinePolicy;
constructor(args: GroupArgs) {
constructor(name: string, args: GroupArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.groupName = args.groupName;
this.managedPolicies = args.managedPolicies;
this.path = args.path;
@ -26,7 +26,6 @@ export class Group extends coconut.Resource implements GroupArgs {
}
export interface GroupArgs {
readonly name: string;
readonly groupName?: string;
managedPolicies?: Policy[];
path?: string;

View file

@ -20,12 +20,12 @@ export class Policy extends coconut.Resource implements PolicyArgs {
public roles?: Role[];
public users?: User[];
constructor(args: PolicyArgs) {
constructor(name: string, args: PolicyArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.policyDocument === undefined) {
throw new Error("Missing required argument 'policyDocument'");
}
@ -41,7 +41,6 @@ export class Policy extends coconut.Resource implements PolicyArgs {
}
export interface PolicyArgs {
readonly name: string;
policyDocument: any;
policyName: string;
groups?: Group[];

View file

@ -15,12 +15,12 @@ export class Role extends coconut.Resource implements RoleArgs {
public policies?: InlinePolicy[];
public arn: ARN;
constructor(args: RoleArgs) {
constructor(name: string, args: RoleArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.assumeRolePolicyDocument === undefined) {
throw new Error("Missing required argument 'assumeRolePolicyDocument'");
}
@ -33,7 +33,6 @@ export class Role extends coconut.Resource implements RoleArgs {
}
export interface RoleArgs {
readonly name: string;
assumeRolePolicyDocument: any;
readonly path?: string;
readonly roleName?: string;

View file

@ -20,12 +20,12 @@ export class User extends coconut.Resource implements UserArgs {
public path?: string;
public policies?: InlinePolicy[];
constructor(args: UserArgs) {
constructor(name: string, args: UserArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.userName = args.userName;
this.groups = args.groups;
this.loginProfile = args.loginProfile;
@ -36,7 +36,6 @@ export class User extends coconut.Resource implements UserArgs {
}
export interface UserArgs {
readonly name: string;
readonly userName?: string;
groups?: Group[];
loginProfile?: LoginProfile;

View file

@ -10,12 +10,12 @@ export class Key extends coconut.Resource implements KeyArgs {
public enabled?: boolean;
public enableKeyRotation?: boolean;
constructor(args: KeyArgs) {
constructor(name: string, args: KeyArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.keyPolicy === undefined) {
throw new Error("Missing required argument 'keyPolicy'");
}
@ -27,7 +27,6 @@ export class Key extends coconut.Resource implements KeyArgs {
}
export interface KeyArgs {
readonly name: string;
keyPolicy: any;
description?: string;
enabled?: boolean;

View file

@ -39,12 +39,12 @@ export class Function extends coconut.Resource implements FunctionArgs {
public vpcConfig?: VPCConfig;
public arn: ARN;
constructor(args: FunctionArgs) {
constructor(name: string, args: FunctionArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.code === undefined) {
throw new Error("Missing required argument 'code'");
}
@ -73,7 +73,6 @@ export class Function extends coconut.Resource implements FunctionArgs {
}
export interface FunctionArgs {
readonly name: string;
code: coconut.asset.Asset;
handler: string;
role: Role;

View file

@ -14,12 +14,12 @@ export class Permission extends coconut.Resource implements PermissionArgs {
public readonly sourceAccount?: string;
public readonly sourceARN?: ARN;
constructor(args: PermissionArgs) {
constructor(name: string, args: PermissionArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
if (args.action === undefined) {
throw new Error("Missing required argument 'action'");
}
@ -38,7 +38,6 @@ export class Permission extends coconut.Resource implements PermissionArgs {
}
export interface PermissionArgs {
readonly name: string;
readonly action: string;
readonly function: Function;
readonly principal: string;

View file

@ -10,19 +10,18 @@ export class Bucket extends coconut.Resource implements BucketArgs {
public readonly bucketName?: string;
public accessControl?: CannedACL;
constructor(args: BucketArgs) {
constructor(name: string, args: BucketArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.bucketName = args.bucketName;
this.accessControl = args.accessControl;
}
}
export interface BucketArgs {
readonly name: string;
readonly bucketName?: string;
accessControl?: CannedACL;
}

View file

@ -18,12 +18,12 @@ export class Topic extends coconut.Resource implements TopicArgs {
public displayName?: string;
public subscription?: TopicSubscription[];
constructor(args: TopicArgs) {
constructor(name: string, args: TopicArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.topicName = args.topicName;
this.displayName = args.displayName;
this.subscription = args.subscription;
@ -31,7 +31,6 @@ export class Topic extends coconut.Resource implements TopicArgs {
}
export interface TopicArgs {
readonly name: string;
readonly topicName?: string;
displayName?: string;
subscription?: TopicSubscription[];

View file

@ -15,12 +15,12 @@ export class Queue extends coconut.Resource implements QueueArgs {
public redrivePolicy?: RedrivePolicy;
public visibilityTimeout?: number;
constructor(args: QueueArgs) {
constructor(name: string, args: QueueArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
if (name === undefined) {
throw new Error("Missing required resource name");
}
this.name = args.name;
this.name = name;
this.fifoQueue = args.fifoQueue;
this.queueName = args.queueName;
this.contentBasedDeduplication = args.contentBasedDeduplication;
@ -34,7 +34,6 @@ export class Queue extends coconut.Resource implements QueueArgs {
}
export interface QueueArgs {
readonly name: string;
readonly fifoQueue?: boolean;
readonly queueName?: string;
contentBasedDeduplication?: boolean;

View file

@ -7,12 +7,12 @@ export class Environment extends coconut.Resource implements EnvironmentArgs {
public readonly name: string;
public runContainerImageURL: string;
constructor(args: EnvironmentArgs) {
constructor(name: string, args: EnvironmentArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
}
this.name = args.name;
this.name = name;
if (args.runContainerImageURL === undefined) {
throw new Error("Missing required argument 'runContainerImageURL'");
}

View file

@ -10,12 +10,12 @@ export class Function extends coconut.Resource implements FunctionArgs {
public environment: Environment;
public code: coconut.asset.Asset;
constructor(args: FunctionArgs) {
constructor(name: string, args: FunctionArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
}
this.name = args.name;
this.name = name;
if (args.environment === undefined) {
throw new Error("Missing required argument 'environment'");
}

View file

@ -11,12 +11,12 @@ export class HTTPTrigger extends coconut.Resource implements HTTPTriggerArgs {
public method: string;
public function: Function;
constructor(args: HTTPTriggerArgs) {
constructor(name: string, args: HTTPTriggerArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
}
this.name = args.name;
this.name = name;
if (args.urlPattern === undefined) {
throw new Error("Missing required argument 'urlPattern'");
}

View file

@ -14,12 +14,12 @@ export class Watch extends coconut.Resource implements WatchArgs {
public function: Function;
public target: string;
constructor(args: WatchArgs) {
constructor(name: string, args: WatchArgs) {
super();
if (args.name === undefined) {
throw new Error("Missing required argument 'name'");
}
this.name = args.name;
this.name = name;
if (args.namespace === undefined) {
throw new Error("Missing required argument 'namespace'");
}

View file

@ -267,11 +267,22 @@ func (g *PackGenerator) emitResourceClass(w *bufio.Writer, res *Resource) {
}
// Next, a constructor that validates arguments and self-assigns them.
writefmtln(w, " constructor(args: %vArgs) {", name)
writefmt(w, " constructor(")
if res.Named {
writefmt(w, "name: string, ")
}
writefmtln(w, "args: %vArgs) {", name)
writefmtln(w, " super();")
forEachField(res, func(fld *types.Var, opt PropertyOptions) {
// Skip output properties because they won't exist on the arguments.
if !opt.Out {
if opt.Out {
return // skip output properties because they won't exist on the arguments.
} else if isResourceNameProperty(res, opt) {
// Named properties are passed as the constructor's first argument.
writefmtln(w, " if (name === undefined) {")
writefmtln(w, " throw new Error(\"Missing required resource name\");")
writefmtln(w, " }")
writefmtln(w, " this.name = name;")
} else {
if !opt.Optional {
// Validate that required parameters exist.
writefmtln(w, " if (args.%v === undefined) {", opt.Name)
@ -286,6 +297,10 @@ func (g *PackGenerator) emitResourceClass(w *bufio.Writer, res *Resource) {
writefmtln(w, "}")
}
func isResourceNameProperty(res *Resource, prop PropertyOptions) bool {
return res.Named && prop.Name == "name"
}
func (g *PackGenerator) EmitStruct(w *bufio.Writer, s *Struct) {
g.emitStructType(w, s, s.Name())
}
@ -293,10 +308,12 @@ func (g *PackGenerator) EmitStruct(w *bufio.Writer, s *Struct) {
func (g *PackGenerator) emitStructType(w *bufio.Writer, t TypeMember, name tokens.Name) {
writefmtln(w, fmt.Sprintf("export interface %v {", name))
forEachField(t, func(fld *types.Var, opt PropertyOptions) {
// Skip output properties, since those exist solely on the resource class.
if !opt.Out {
g.emitField(w, fld, opt, " ")
if opt.Out {
return // skip output properties, since those exist solely on the resource class.
} else if res, isres := t.(*Resource); isres && isResourceNameProperty(res, opt) {
return // skip resource names, since those are part of the resource but not its property object.
}
g.emitField(w, fld, opt, " ")
})
writefmtln(w, "}")
}