Skip to content

Commit

Permalink
Merge pull request noflo#8 from djdeath/new-port-api
Browse files Browse the repository at this point in the history
New port api
  • Loading branch information
bergie committed May 9, 2014
2 parents 3c254fb + ccd80de commit 52c786b
Show file tree
Hide file tree
Showing 30 changed files with 322 additions and 163 deletions.
25 changes: 17 additions & 8 deletions components/CallMethod.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ class CallMethod extends noflo.Component
@method = null
@args = []

@inPorts =
in: new noflo.Port 'object'
method: new noflo.Port 'string'
arguments: new noflo.Port 'all'
@outPorts =
out: new noflo.Port 'all'
error: new noflo.Port 'string'
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object on which a method will be called'
method:
datatype: 'string'
description: 'Name of the method to call'
arguments:
datatype: 'all'
description: 'Arguments given to the method (one argument per IP)'
@outPorts = new noflo.OutPorts
out:
datatype: 'all'
description: 'Value returned by the method call'
error:
datatype: 'object'

@inPorts.in.on 'begingroup', (group) =>
@outPorts.out.beginGroup group
Expand All @@ -42,7 +51,7 @@ class CallMethod extends noflo.Component

@inPorts.arguments.on 'connect', =>
@args = []

@inPorts.arguments.on 'data', (data) =>
@args.push data

Expand Down
12 changes: 8 additions & 4 deletions components/CreateDate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ class CreateDate extends noflo.Component
description: 'Create a new Date object from string'
icon: 'clock-o'
constructor: ->
@inPorts =
in: new noflo.Port 'string'
@outPorts =
out: new noflo.Port 'object'
@inPorts = new noflo.InPorts
in:
datatype: 'string'
description: 'A string representation of a date in RFC2822/IETF/ISO8601 format'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'
description: 'A new Date object'

@inPorts.in.on 'begingroup', (group) =>
@outPorts.out.beginGroup group
Expand Down
12 changes: 8 additions & 4 deletions components/CreateObject.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ noflo = require 'noflo'

class CreateObject extends noflo.Component
constructor: ->
@inPorts =
start: new noflo.Port 'bang'
@outPorts =
out: new noflo.Port 'object'
@inPorts = new noflo.InPorts
start:
datatype: 'bang'
description: 'Signal to create a new object'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'
description: 'A new empty object'

@inPorts.start.on 'begingroup', (group) =>
@outPorts.out.beginGroup group
Expand Down
18 changes: 11 additions & 7 deletions components/DuplicateProperty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ class DuplicateProperty extends noflo.Component
@properties = {}
@separator = '/'

@inPorts =
property: new noflo.ArrayPort()
separator: new noflo.Port()
in: new noflo.Port()
@outPorts =
out: new noflo.Port()
@inPorts = new noflo.InPorts
property:
datatype: 'all'
separator:
datatype: 'string'
in:
datatype: 'object'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'

@inPorts.property.on 'data', (data) =>
@setProperty data
Expand All @@ -35,7 +39,7 @@ class DuplicateProperty extends noflo.Component
if propParts.length > 2
@properties[propParts.pop()] = propParts
return

@properties[propParts[1]] = propParts[0]

addProperties: (object) ->
Expand Down
24 changes: 17 additions & 7 deletions components/Extend.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ class Extend extends noflo.Component
@key = null
@reverse = false

@inPorts =
in: new noflo.Port
base: new noflo.Port
key: new noflo.Port
reverse: new noflo.Port
@outPorts =
out: new noflo.Port
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to extend'
base:
datatype: 'object'
description: 'Objects to extend with (one object per IP)'
key:
datatype: 'string'
description: 'Property name to extend with'
reverse:
datatype: 'string'
description: 'A string equal "true" if you want to reverse the order of extension algorithm'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'
description: 'The object received on port "in" extended'

@inPorts.base.on "connect", =>
@bases = []
Expand Down
16 changes: 11 additions & 5 deletions components/ExtractProperty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ class ExtractProperty extends noflo.Component
in the incoming object"

constructor: ->
@inPorts =
in: new noflo.Port
key: new noflo.Port
@outPorts =
out: new noflo.Port
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'An object to extract property from'
key:
datatype: 'string'
description: 'Property names to extract (one property per IP)'
@outPorts = new noflo.OutPorts
out:
datatype: 'all'
description: 'Values of the property extracted (each value sent as a separate IP)'

@inPorts.key.on "connect", =>
@keys = []
Expand Down
29 changes: 20 additions & 9 deletions components/FilterProperty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ class FilterProperty extends noflo.Component
@accepts = []
@regexps = []

@inPorts =
in: new noflo.Port
key: new noflo.Port
recurse: new noflo.Port
keep: new noflo.Port
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to filter properties from'
key:
datatype: 'string'
description: 'Keys to filter (one key per IP)'
recurse:
datatype: 'string'
description: '"true" to recurse on the object\'s values'
keep:
datatype: 'string'
description: '"true" if matching properties must be kept, otherwise removed'
# Legacy mode
accept: new noflo.ArrayPort
regexp: new noflo.ArrayPort
@outPorts =
out: new noflo.Port
accept:
datatype: 'all'
regexp:
datatype: 'all'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'

@inPorts.keep.on "data", (keep) =>
@keep = true if keep is "true"
Expand Down
24 changes: 17 additions & 7 deletions components/FilterPropertyValue.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ class FilterPropertyValue extends noflo.Component
@accepts = {}
@regexps = {}

@inPorts =
accept: new noflo.ArrayPort 'all'
regexp: new noflo.ArrayPort 'string'
in: new noflo.Port 'object'
@outPorts =
out: new noflo.Port 'object'
missed: new noflo.Port 'object'
@inPorts = new noflo.InPorts
accept:
datatype: 'all'
description: ''
regexp:
datatype: 'string'
description: ''
in:
datatype: 'object'
description: 'Object to filter properties from'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'
description: 'Object including the filtered properties'
missed:
datatype: 'object'
description: 'Object received as input if no key have been matched'

@inPorts.accept.on 'data', (data) =>
@prepareAccept data
Expand Down
14 changes: 9 additions & 5 deletions components/FlattenObject.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ noflo = require 'noflo'
class FlattenObject extends noflo.Component
constructor: ->
@map = {}
@inPorts =
map: new noflo.ArrayPort()
in: new noflo.Port()
@outPorts =
out: new noflo.Port()
@inPorts = new noflo.InPorts
map:
datatype: 'all'
in:
datatype: 'object'
description: 'Object to flatten'
@outPorts = new noflo.OutPorts
out:
datatype: 'array'

@inPorts.map.on 'data', (data) =>
@prepareMap data
Expand Down
30 changes: 21 additions & 9 deletions components/GetObjectKey.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ class GetObjectKey extends noflo.Component
@data = []
@key = []

@inPorts =
in: new noflo.Port 'object'
key: new noflo.ArrayPort 'string'
sendgroup: new noflo.Port 'boolean'
@outPorts =
out: new noflo.Port 'all'
object: new noflo.Port 'object'
missed: new noflo.Port 'object'
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to get keys from'
key:
datatype: 'string'
description: 'Keys to extract from the object (one key per IP)'
sendgroup:
datatype: 'boolean'
description: 'true to send keys as groups around value IPs, false otherwise'
@outPorts = new noflo.OutPorts
out:
datatype: 'all'
description: 'Values extracts from the input object given the input keys (one value per IP, potentially grouped using the key names)'
object:
datatype: 'object'
description: 'Object forwarded from input if at least one property matches the input keys'
missed:
datatype: 'object'
description: 'Object forwarded from input if no property matches the input keys'

@inPorts.in.on 'connect', =>
@data = []
Expand All @@ -30,7 +42,7 @@ class GetObjectKey extends noflo.Component
# Data already sent
@outPorts.out.disconnect()
return

# No key, data will be sent when we get it
return unless @key.length

Expand Down
16 changes: 11 additions & 5 deletions components/InsertProperty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class InsertProperty extends noflo.Component
constructor: ->
@properties = {}

@inPorts =
in: new noflo.Port
property: new noflo.Port
@outPorts =
out: new noflo.Port
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to insert property into'
property:
datatype: 'all'
description: 'Property to insert (property sent as group, value sent as IP)'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'
description: 'Object received as input with added properties'

@inPorts.property.on "connect", =>
@properties = {}
Expand Down
16 changes: 11 additions & 5 deletions components/Join.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ class Join extends noflo.Component
constructor: ->
@delimiter = ","

@inPorts =
in: new noflo.Port
delimiter: new noflo.Port
@outPorts =
out: new noflo.Port
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to join values from'
delimiter:
datatype: 'string'
description: 'Delimiter to join values'
@outPorts = new noflo.OutPorts
out:
datatype: 'string'
description: 'String conversion of all values joined with delimiter into one string'

@inPorts.delimiter.on "data", (@delimiter) =>

Expand Down
12 changes: 8 additions & 4 deletions components/Keys.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ class Keys extends noflo.Component
description: "gets only the keys of an object and forward them as an array"

constructor: ->
@inPorts =
in: new noflo.Port 'object'
@outPorts =
out: new noflo.Port 'all'
@inPorts = new noflo.InPorts
in:
datatype: 'object'
description: 'Object to get keys from'
@outPorts = new noflo.OutPorts
out:
datatype: 'string'
description: 'Keys from the incoming object (one per IP)'

@inPorts.in.on "begingroup", (group) =>
@outPorts.out.beginGroup(group)
Expand Down
16 changes: 10 additions & 6 deletions components/MapProperty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ class MapProperty extends noflo.Component
@map = {}
@regexps = {}

@inPorts =
map: new noflo.ArrayPort()
regexp: new noflo.ArrayPort()
in: new noflo.Port()
@outPorts =
out: new noflo.Port()
@inPorts = new noflo.InPorts
map:
datatype: 'all'
regexp:
datatype: 'string'
in:
datatype: 'object'
@outPorts = new noflo.OutPorts
out:
datatype: 'object'

@inPorts.map.on 'data', (data) =>
@prepareMap data
Expand Down
Loading

0 comments on commit 52c786b

Please sign in to comment.