@@ -12,9 +12,13 @@ const {
12
12
isEmpty,
13
13
isUndefined,
14
14
map,
15
- mapValues,
15
+ toPairs,
16
+ negate,
17
+ overEvery,
18
+ overSome,
16
19
matchesProperty,
17
20
omitBy,
21
+ isString,
18
22
pipe,
19
23
startsWith
20
24
} = require ( 'lodash/fp' ) ;
@@ -55,13 +59,15 @@ class ServerlessOfflineKinesis {
55
59
}
56
60
57
61
getConfig ( ) {
58
- return assignAll ( [
59
- omitBy ( isUndefined , this . options ) ,
60
- omitBy ( isUndefined , this . service ) ,
61
- omitBy ( isUndefined , this . service . provider ) ,
62
- omitBy ( isUndefined , get ( [ 'custom' , 'serverless-offline' ] , this . service ) ) ,
63
- omitBy ( isUndefined , get ( [ 'custom' , 'serverless-offline-kinesis' ] , this . service ) )
64
- ] ) ;
62
+ return assignAll (
63
+ [
64
+ this . options ,
65
+ this . service ,
66
+ this . service . provider ,
67
+ get ( [ 'custom' , 'serverless-offline' ] , this . service ) ,
68
+ get ( [ 'custom' , 'serverless-offline-kinesis' ] , this . service )
69
+ ] . map ( omitBy ( isUndefined ) )
70
+ ) ;
65
71
}
66
72
67
73
getClient ( ) {
@@ -128,23 +134,16 @@ class ServerlessOfflineKinesis {
128
134
}
129
135
130
136
getStreamName ( streamEvent ) {
131
- if ( typeof streamEvent === 'string' && startsWith ( 'arn:aws:kinesis' , streamEvent ) )
137
+ if ( isString ( streamEvent ) && startsWith ( 'arn:aws:kinesis' , streamEvent ) )
132
138
return extractStreamNameFromARN ( streamEvent ) ;
133
- if ( typeof streamEvent . arn === 'string' ) return extractStreamNameFromARN ( streamEvent . arn ) ;
134
- if ( typeof streamEvent . streamName === 'string' ) return streamEvent . streamName ;
139
+ if ( isString ( streamEvent . arn ) ) return extractStreamNameFromARN ( streamEvent . arn ) ;
140
+ if ( isString ( streamEvent . streamName ) ) return streamEvent . streamName ;
135
141
136
142
if ( streamEvent . arn [ 'Fn::GetAtt' ] ) {
137
143
const [ ResourceName ] = streamEvent . arn [ 'Fn::GetAtt' ] ;
138
144
139
- if (
140
- this . service &&
141
- this . service . resources &&
142
- this . service . resources . Resources &&
143
- this . service . resources . Resources [ ResourceName ] &&
144
- this . service . resources . Resources [ ResourceName ] . Properties &&
145
- typeof this . service . resources . Resources [ ResourceName ] . Properties . Name === 'string'
146
- )
147
- return this . service . resources . Resources [ ResourceName ] . Properties . Name ;
145
+ const name = get ( `resources.Resources.${ ResourceName } .Properties.Name` , this . service ) ;
146
+ if ( isString ( name ) ) return name ;
148
147
}
149
148
150
149
throw new Error (
@@ -200,31 +199,35 @@ class ServerlessOfflineKinesis {
200
199
offlineStartInit ( ) {
201
200
this . serverless . cli . log ( `Starting Offline Kinesis.` ) ;
202
201
203
- mapValues . convert ( { cap : false } ) ( ( _function , functionName ) => {
202
+ forEach ( ( [ functionName , functionConfiguration ] ) => {
204
203
const streams = pipe (
205
204
get ( 'events' ) ,
206
205
filter (
207
- event =>
208
- ! matchesProperty ( 'stream.enabled' , false ) ( event ) &&
209
- ( matchesProperty ( 'stream.type' , 'kinesis' ) ( event ) ||
210
- startsWith ( 'arn:aws:kinesis' , event . stream ) )
206
+ overEvery ( [
207
+ negate ( matchesProperty ( 'stream.enabled' , false ) ) ,
208
+ overSome ( [
209
+ matchesProperty ( 'stream.type' , 'kinesis' ) ,
210
+ pipe (
211
+ get ( 'stream' ) ,
212
+ startsWith ( 'arn:aws:kinesis' )
213
+ )
214
+ ] )
215
+ ] )
211
216
) ,
212
- map ( get ( 'stream' ) )
213
- ) ( _function ) ;
217
+ map ( 'stream' )
218
+ ) ( functionConfiguration ) ;
214
219
215
220
if ( ! isEmpty ( streams ) ) {
216
221
printBlankLine ( ) ;
217
222
this . serverless . cli . log ( `Kinesis for ${ functionName } :` ) ;
218
- }
219
223
220
- forEach ( streamEvent => {
221
- this . createKinesisReadable ( functionName , streamEvent ) ;
222
- } , streams ) ;
224
+ forEach ( streamEvent => {
225
+ this . createKinesisReadable ( functionName , streamEvent ) ;
226
+ } , streams ) ;
223
227
224
- if ( ! isEmpty ( streams ) ) {
225
228
printBlankLine ( ) ;
226
229
}
227
- } , this . service . functions ) ;
230
+ } ) ( toPairs ( this . service . functions ) ) ;
228
231
}
229
232
230
233
offlineStartEnd ( ) {
0 commit comments