Comparing version 0.3.1 to 0.3.2
@@ -56,2 +56,13 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
Collection.objectAtIndex = function(array, index) { | ||
if (index < 0) { | ||
if (index === -1) { | ||
return array.slice(-1)[0]; | ||
} else { | ||
return array.slice(index, index+1)[0]; | ||
} | ||
} | ||
return array[index]; | ||
}; | ||
Collection.prototype._filterArrayOrThrow = function(array) { | ||
@@ -82,10 +93,3 @@ return _.map(array, function(element) { | ||
Collection.prototype.objectAtIndex = function(index) { | ||
if (index < 0) { | ||
if (index === -1) { | ||
return this.array.slice(-1)[0]; | ||
} else { | ||
return this.array.slice(index, index+1)[0]; | ||
} | ||
} | ||
return this.array[index]; | ||
return Collection.objectAtIndex(this.array, index); | ||
}; | ||
@@ -92,0 +96,0 @@ |
@@ -24,3 +24,5 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var Collection = require('../collection'); | ||
var Expression = require('./expression'); | ||
var KeyPathNotation = require('./key_path_notation'); | ||
var SyncFragment = require('../sync_fragment'); | ||
@@ -36,3 +38,4 @@ | ||
return callback(new Error( | ||
'Incoming expression must be of the form "$incoming.ModelObjectType.changeType.value"')); | ||
'Incoming expression must be of the form "$incoming.ModelObjectType.changeType.value"' + | ||
'; expr: \'' + value + '\'')); | ||
} | ||
@@ -43,3 +46,4 @@ | ||
return callback(new Error( | ||
'Incoming expression must be of the form "$incoming.ModelObjectType.changeType.value"')); | ||
'Incoming expression must be of the form "$incoming.ModelObjectType.changeType.value"' + | ||
'; expr: \'' + value + '\'')); | ||
} | ||
@@ -54,3 +58,3 @@ | ||
'Incoming expression used bad change type, should be one of: ' + | ||
SyncFragment.CONST.TYPES.join(', '))); | ||
SyncFragment.CONST.TYPES.join(', ') + '; expr: \'' + value + '\'')); | ||
} | ||
@@ -61,3 +65,5 @@ | ||
if (!syncFragment) { | ||
return callback(new Error('Incoming did not contain the change \'' + incomingKey + '\'')); | ||
return callback(new Error( | ||
'Incoming did not contain the change \'' + incomingKey + | ||
'\'; expr: \'' + value + '\'')); | ||
} | ||
@@ -69,7 +75,34 @@ | ||
// Potentially parse an array index for this path | ||
var index = null; | ||
if (split.length === 6) { | ||
index = parseInt(split[5]); | ||
if (isNaN(index)) { | ||
return callback(new Error( | ||
'Incoming expression used bad index \'' + split[5] + | ||
'\'; expr: \'' + value + '\'')); | ||
} | ||
} else { | ||
var matches = KeyPathNotation.CONST.INDEX_REGEX.exec(field); | ||
if (matches) { | ||
field = matches[1]; | ||
index = parseInt(matches[2]); | ||
} | ||
} | ||
if (!syncFragment.properties.hasOwnProperty(field)) { | ||
return callback(new Error('Incoming change did not contain the field \'' + field + '\'')); | ||
return callback(new Error('Incoming change did not contain the field \'' + field + | ||
'\'; expr: \'' + value + '\'')); | ||
} | ||
callback(null, syncFragment.properties[field]); | ||
var fieldValue = syncFragment.properties[field]; | ||
if (index !== null) { | ||
if (!Array.isArray(fieldValue)) { | ||
return callback(new Error('Incoming change was not an array value for field \'' + field + | ||
'\'; expr: \'' + value + '\'')); | ||
} | ||
return callback(null, Collection.objectAtIndex(fieldValue, index)); | ||
} | ||
callback(null, fieldValue); | ||
}; |
@@ -49,2 +49,4 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
KeyPathNotation.CONST = CONST; | ||
/** | ||
@@ -51,0 +53,0 @@ * Get a ModelObject at a key path relative from a ModelObject |
{ | ||
"name": "jetstream", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Jetstream Sync server framework to sync local and remote models", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -98,3 +98,4 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
'Authorization': scope.params.accessToken, | ||
'X-Locale': 'en_US' | ||
'X-ChatRoom-Locale': 'en_US', | ||
'X-ChatRoom-LastMessageId': newMessageUUID | ||
}); | ||
@@ -107,3 +108,3 @@ | ||
text: newMessageText, | ||
tags: ['san_francisco', 'nodejs'] | ||
tags: ['staticValue0', 'staticValue1'] | ||
}); | ||
@@ -110,0 +111,0 @@ |
@@ -104,3 +104,4 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
'Authorization': expr('$scope.params.accessToken'), | ||
'X-Locale': expr('$rootModel.attributes.locale') | ||
'X-ChatRoom-Locale': expr('$rootModel.attributes.locale'), | ||
'X-ChatRoom-LastMessageId': expr('$incoming.ChatRoom.change.messages[-1]') | ||
}, | ||
@@ -112,5 +113,5 @@ body: { | ||
text: expr('$incoming.Message.add.text'), | ||
tags: ['san_francisco', 'nodejs'] | ||
tags: ['staticValue0', 'staticValue1'] | ||
} | ||
} | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
458884
10244