Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit a4fe356

Browse files
committed
Further flow fixes and limited testing
1 parent fcac116 commit a4fe356

File tree

5 files changed

+133
-86
lines changed

5 files changed

+133
-86
lines changed

flow/measured.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
declare module 'measured' {
3+
declare class MeasuredCollection {
4+
_metrics: any;
5+
6+
timer(name: string): MeasuredTimer;
7+
8+
counter(name: string): MeasuredCounter;
9+
10+
toJSON(): any;
11+
}
12+
13+
declare class MeasuredTimer {
14+
start(): Stopwatch;
15+
}
16+
17+
declare class MeasuredCounter {
18+
inc(value: number): void;
19+
}
20+
21+
declare class Stopwatch {
22+
end(): void;
23+
}
24+
25+
declare function createCollection(): MeasuredCollection;
26+
}

make-webpack-config.js

Lines changed: 74 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,92 @@
1-
var path = require("path");
2-
var webpack = require("webpack");
3-
var StatsPlugin = require("stats-webpack-plugin");
4-
var ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin");
1+
var path = require('path');
2+
var webpack = require('webpack');
3+
var StatsPlugin = require('stats-webpack-plugin');
4+
var ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
55

6-
module.exports = function(options) {
7-
var entry = { 'index': './src/Index.js' };
6+
module.exports = function (options) {
87

8+
var entry = { index: './src/Index.js' };
99
var loaders = [
10-
{ test: /\.jsx$/, loader: options.hotComponents ? ["react-hot-loader", "babel-loader?stage=0"] : "babel-loader?stage=0"},
11-
{ test: /\.js$/, loader: "babel-loader", include: path.join(__dirname, "src")},
10+
{ test: /\.jsx$/, loader: options.hotComponents ?
11+
[ 'react-hot-loader', 'babel-loader?stage=0' ] : 'babel-loader?stage=0'},
12+
{ test: /\.js$/, loader: 'babel-loader', include: path.join(__dirname, 'src')},
1213
{ test: /\.json$/, loader: 'json-loader' },
1314
{ test: /\.md|markdown$/, loader: 'markdown-loader'}
1415
];
1516

16-
var alias = {};
17-
var aliasLoader = {};
18-
var externals = [
17+
var alias = {};
18+
var aliasLoader = {};
19+
var externals = [
1920
{ 'aws-sdk': 'commonjs aws-sdk' } // This is already available on the lambda server
2021
];
21-
var modulesDirectories = ['node_modules', 'web_modules'];
22-
var extensions = ["", ".web.js", ".js", ".jsx", ".json"];
23-
var root = __dirname;
22+
var modulesDirectories = [ 'node_modules', 'web_modules' ];
23+
var extensions = [ '', '.web.js', '.js', '.jsx', '.json' ];
24+
var root = __dirname;
2425

25-
var publicPath = options.devServer ?
26-
"http://localhost:2992/assets/" :
27-
"/assets/";
26+
var publicPath = options.devServer ? 'http://localhost:2992/assets/' : '/assets/';
2827

29-
var output = {
30-
path: path.join(__dirname, "dist"),
31-
publicPath,
32-
filename: "[name].js",
33-
chunkFilename: options.devServer ? "[id].js" : "[name].js",
34-
sourceMapFilename: "debugging/[file].map",
35-
pathinfo: options.debug,
36-
libraryTarget: 'umd'
37-
};
28+
var output = {
29+
path: path.join(__dirname, 'dist'),
30+
publicPath,
31+
filename: '[name].js',
32+
chunkFilename: options.devServer ? '[id].js' : '[name].js',
33+
sourceMapFilename: 'debugging/[file].map',
34+
pathinfo: options.debug,
35+
libraryTarget: 'umd'
36+
};
3837

39-
var excludeFromStats = [
40-
/node_modules[\\\/]react(-router)?[\\\/]/,
41-
/node_modules[\\\/]items-store[\\\/]/
42-
];
38+
var excludeFromStats = [
39+
/node_modules[\\\/]react(-router)?[\\\/]/,
40+
/node_modules[\\\/]items-store[\\\/]/
41+
];
4342

44-
var plugins = [
45-
new StatsPlugin(path.join(__dirname, "build", "stats.json"), {
46-
chunkModules: true,
47-
exclude: excludeFromStats
48-
}),
49-
new ContextReplacementPlugin(/moment\.js[\/\\]lang$/, /^\.\/(de|pl)$/)
50-
];
43+
var plugins = [
44+
new StatsPlugin(path.join(__dirname, 'build', 'stats.json'), {
45+
chunkModules: true,
46+
exclude: excludeFromStats
47+
}),
48+
new ContextReplacementPlugin(/moment\.js[\/\\]lang$/, /^\.\/(de|pl)$/)
49+
];
5150

52-
if(options.minimize) {
53-
plugins.push(
54-
new webpack.optimize.UglifyJsPlugin({
55-
compressor: {
56-
warnings: false
57-
}
58-
}),
59-
new webpack.optimize.DedupePlugin()
60-
);
61-
plugins.push(
62-
new webpack.DefinePlugin({
63-
"process.env": {
64-
NODE_ENV: JSON.stringify("production")
65-
}
66-
}),
51+
if(options.minimize) {
52+
plugins.push(
53+
new webpack.optimize.UglifyJsPlugin({
54+
compressor: {
55+
warnings: false
56+
}
57+
}),
58+
new webpack.optimize.DedupePlugin()
59+
);
60+
plugins.push(
61+
new webpack.DefinePlugin({'process.env': { NODE_ENV: JSON.stringify('production')}}),
6762
new webpack.NoErrorsPlugin()
6863
);
69-
}
64+
}
7065

71-
return {
72-
entry: entry,
73-
output: output,
74-
target: 'node',
75-
module: { loaders: loaders },
76-
devtool: options.devtool,
77-
debug: options.debug,
78-
resolveLoader: {
79-
root: path.join(__dirname, "node_modules"),
80-
alias: aliasLoader
81-
},
82-
externals: externals,
83-
resolve: {
84-
root: root,
85-
modulesDirectories: modulesDirectories,
86-
extensions: extensions,
87-
alias: alias
88-
},
89-
plugins: plugins,
90-
devServer: {
91-
stats: {
92-
cached: false,
93-
exclude: excludeFromStats
94-
}
95-
}
96-
};
66+
return {
67+
entry,
68+
output,
69+
target: 'node',
70+
module: { loaders },
71+
devtool: options.devtool,
72+
debug: options.debug,
73+
resolveLoader: {
74+
root: path.join(__dirname, 'node_modules'),
75+
alias: aliasLoader
76+
},
77+
externals,
78+
resolve: {
79+
root,
80+
modulesDirectories,
81+
extensions,
82+
alias
83+
},
84+
plugins,
85+
devServer: {
86+
stats: {
87+
cached: false,
88+
exclude: excludeFromStats
89+
}
90+
}
91+
};
9792
};

src/Provisioner.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export default class Provisioner extends ProvisionerConfigurableBase {
4747
invariant(data != null, 'Parameter \'data\' is not set');
4848

4949
let config = this.getTableConfig(data);
50+
if (config.ReadCapacity.Increment == null) {
51+
return false;
52+
}
53+
5054
let adjustmentContext = this.getReadCapacityIncrementAdjustmentContext(data, config);
5155
return this.isCapacityAdjustmentRequired(data, adjustmentContext);
5256
}
@@ -63,8 +67,12 @@ export default class Provisioner extends ProvisionerConfigurableBase {
6367
invariant(data != null, 'Parameter \'data\' is not set');
6468

6569
let config = this.getTableConfig(data);
70+
if (config.ReadCapacity.Decrement == null) {
71+
return false;
72+
}
73+
6674
let adjustmentContext = this.getReadCapacityDecrementAdjustmentContext(data, config);
67-
return this.isCapacityAdjustmentRequired(data, adjustmentContext, this.calculateDecrementedReadCapacityValue);
75+
return this.isCapacityAdjustmentRequired(data, adjustmentContext, d => this.calculateDecrementedReadCapacityValue(d));
6876
}
6977

7078
calculateDecrementedReadCapacityValue(data: TableProvisionedAndConsumedThroughput) {
@@ -79,6 +87,10 @@ export default class Provisioner extends ProvisionerConfigurableBase {
7987
invariant(data != null, 'Parameter \'data\' is not set');
8088

8189
let config = this.getTableConfig(data);
90+
if (config.WriteCapacity.Increment == null) {
91+
return false;
92+
}
93+
8294
let adjustmentContext = this.getWriteCapacityIncrementAdjustmentContext(data, config);
8395
return this.isCapacityAdjustmentRequired(data, adjustmentContext);
8496
}
@@ -95,6 +107,10 @@ export default class Provisioner extends ProvisionerConfigurableBase {
95107
invariant(data != null, 'Parameter \'data\' is not set');
96108

97109
let config = this.getTableConfig(data);
110+
if (config.WriteCapacity.Decrement == null) {
111+
return false;
112+
}
113+
98114
let adjustmentContext = this.getWriteCapacityDecrementAdjustmentContext(data, config);
99115
return this.isCapacityAdjustmentRequired(data, adjustmentContext, this.calculateDecrementedWriteCapacityValue);
100116
}
@@ -110,6 +126,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
110126
getReadCapacityIncrementAdjustmentContext(
111127
data: TableProvisionedAndConsumedThroughput,
112128
config: ProvisionerConfig): AdjustmentContext {
129+
130+
invariant(config.ReadCapacity.Increment != null, 'Increment cannot be null');
113131
return {
114132
TableName: data.TableName,
115133
IndexName: data.IndexName,
@@ -126,6 +144,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
126144
getReadCapacityDecrementAdjustmentContext(
127145
data: TableProvisionedAndConsumedThroughput,
128146
config: ProvisionerConfig): AdjustmentContext {
147+
148+
invariant(config.ReadCapacity.Decrement != null, 'Decrement cannot be null');
129149
return {
130150
TableName: data.TableName,
131151
IndexName: data.IndexName,
@@ -142,6 +162,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
142162
getWriteCapacityIncrementAdjustmentContext(
143163
data: TableProvisionedAndConsumedThroughput,
144164
config: ProvisionerConfig): AdjustmentContext {
165+
166+
invariant(config.WriteCapacity.Increment != null, 'Increment cannot be null');
145167
return {
146168
TableName: data.TableName,
147169
IndexName: data.IndexName,
@@ -158,6 +180,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
158180
getWriteCapacityDecrementAdjustmentContext(
159181
data: TableProvisionedAndConsumedThroughput,
160182
config: ProvisionerConfig): AdjustmentContext {
183+
184+
invariant(config.WriteCapacity.Decrement != null, 'Decrement cannot be null');
161185
return {
162186
TableName: data.TableName,
163187
IndexName: data.IndexName,
@@ -191,7 +215,7 @@ export default class Provisioner extends ProvisionerConfigurableBase {
191215
adjustmentContext.CapacityAdjustmentConfig.When.AfterLastIncrementMinutes);
192216

193217
let isReadDecrementAllowed = adjustmentContext.AdjustmentType === 'decrement' ?
194-
RateLimitedDecrement.isDecrementAllowed(data, adjustmentContext, this.calculateDecrementedReadCapacityValue) :
218+
RateLimitedDecrement.isDecrementAllowed(data, adjustmentContext, d => this.calculateDecrementedReadCapacityValue(d)) :
195219
true;
196220

197221
let isAdjustmentAllowed = isAfterLastDecreaseGracePeriod && isAfterLastIncreaseGracePeriod && isReadDecrementAllowed;

src/flow/FlowTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export type ProvisionerConfig = {
3333
export type CapacityConfig = {
3434
Min?: number,
3535
Max?: number,
36-
Increment: CapacityAdjustmentConfig,
37-
Decrement: CapacityAdjustmentConfig,
36+
Increment?: CapacityAdjustmentConfig,
37+
Decrement?: CapacityAdjustmentConfig,
3838
};
3939

4040
export type CapacityAdjustmentConfig = {

src/utils/Stats.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* @flow */
2+
import measured from 'measured';
3+
24
export default class Stats {
3-
_stats: any;
5+
_stats: measured.MeasuredCollection;
46

5-
constructor(stats: any) {
7+
constructor(stats: measured.MeasuredCollection) {
68
this._stats = stats;
79
}
810

@@ -19,7 +21,7 @@ export default class Stats {
1921
this._stats._metrics = {};
2022
}
2123

22-
toJSON() {
24+
toJSON(): any {
2325
return this._stats.toJSON();
2426
}
2527

0 commit comments

Comments
 (0)