-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rewrite name handling * Move texts to constants * Use createDeploymentArtifacts hook * Add build:watch task * Update index/table dimensions * Update homepage in package.json * Update serverless declarations * Closes #20 * Use external project for serverless declarations * Update README.md Add information about breaking changes in CF resource names * Update README.md * Update README.md * AWS resources extend Resource class * Add readonly properties * Add name handling to Resource * Remove unused imports * Add Options export to Resource * Add Options interface to main.d.ts
- Loading branch information
Showing
19 changed files
with
446 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as md5 from 'md5' | ||
import * as util from 'util' | ||
|
||
const TEXT = { | ||
DIMENSION: 'dynamodb:%s:%sCapacityUnits', | ||
METRIC: 'DynamoDB%sCapacityUtilization', | ||
POLICYROLE: 'DynamoDBAutoscalePolicy', | ||
POLICYSCALE: 'TableScalingPolicy-%s', | ||
ROLE: 'DynamoDBAutoscaleRole', | ||
TARGET: 'AutoScalingTarget-%s' | ||
} | ||
|
||
function clean(input: string): string { | ||
return truncate(input.replace(/[^a-z0-9+]+/gi, '')) | ||
} | ||
|
||
function truncate(input: string): string { | ||
return input.length <= 64 ? input : input.substr(0, 32) + md5(input) | ||
} | ||
|
||
function ucfirst(data: string): string { | ||
return data.charAt(0).toUpperCase() + data.slice(1) | ||
} | ||
|
||
export default class Name { | ||
constructor(private options: Options) { } | ||
|
||
public metricRead(): string { | ||
return this.metric(true) | ||
} | ||
|
||
public metricWrite(): string { | ||
return this.metric(false) | ||
} | ||
|
||
public targetRead(): string { | ||
return this.target(true) | ||
} | ||
|
||
public targetWrite(): string { | ||
return this.target(false) | ||
} | ||
|
||
public policyScaleRead(): string { | ||
return this.policyScale(true) | ||
} | ||
|
||
public policyScaleWrite(): string { | ||
return this.policyScale(false) | ||
} | ||
|
||
public policyRole(): string { | ||
return clean( | ||
this.build(TEXT.POLICYROLE) | ||
) | ||
} | ||
|
||
public dimension(read: boolean): string { | ||
const type = this.options.index === '' ? 'table' : 'index' | ||
|
||
return util.format(TEXT.DIMENSION, type, read ? 'Read' : 'Write') | ||
} | ||
|
||
public role(): string { | ||
return clean(this.build(TEXT.ROLE)) | ||
} | ||
|
||
public target(read: boolean): string { | ||
return clean( | ||
this.build(TEXT.TARGET, read ? 'Read' : 'Write') | ||
) | ||
} | ||
|
||
public policyScale(read: boolean): string { | ||
return clean( | ||
this.build(TEXT.POLICYSCALE, read ? 'Read' : 'Write') | ||
) | ||
} | ||
|
||
public metric(read: boolean): string { | ||
return clean( | ||
util.format(TEXT.METRIC, read ? 'Read' : 'Write') | ||
) | ||
} | ||
|
||
private build(data: string, ...args: string[]): string { | ||
return [ | ||
this.prefix(), | ||
args ? util.format(data, ...args) : data, | ||
this.suffix() | ||
].join('') | ||
} | ||
|
||
private prefix(): string { | ||
return this.options.service | ||
} | ||
|
||
private suffix(): string { | ||
return [ | ||
this.options.table, | ||
this.options.index, | ||
this.options.stage, | ||
this.options.region | ||
].map( | ||
ucfirst | ||
).join('') | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Name from './name' | ||
|
||
export default class Resource { | ||
protected dependencies: string[] = [] | ||
protected name: Name | ||
|
||
constructor(protected options: Options) { | ||
this.name = new Name(options) | ||
} | ||
|
||
public setDependencies(list: string[]): Resource { | ||
this.dependencies = list | ||
|
||
return this | ||
} | ||
} |
Oops, something went wrong.