Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SDKAlias to use nested objects for physical id and return values #34

Merged
merged 2 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,16 @@ var MyAliasActionName = CfnLambda.SDKAlias({ // Like Create, Update, Delete
'TheSDKMethod',
'**UsedBeforeMapKeys**'
],
returnKeys: [
returnAttrs: [
'KeysFrom',
'SDKReturnValue',
'ToUseWithCfn',
'Fn::GetAttr'
'Fn::GetAttr',
'You.Can.Access.Nested.Properties.As.Well'
],
ignoreErrorCodes: [IntegerCodeToIgnore, ExWouldBe404ForDeleteOps],
physicalIdAs: 'UsePhysicalIdAsThisKeyInSDKCall',
// physicalIdAs: 'OrUseNested.Property.Using.Dot.Notation'
});

// Then...
Expand Down
26 changes: 21 additions & 5 deletions src/SDKAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,27 @@ function isIgnorable(ignorableErrorCodes, errObject) {


function accessFunction(key) {
return function(data) {
return data == null
? undefined
: data[key];
var actualKey = key;
var getDataSimple = function(data) {
return data == null ?
undefined :
data[actualKey];
};

function getDataRecursive(data) {
if (actualKey.includes('.')) {
var pathTokens = actualKey.split('.'),
firstElem = pathTokens[0],
childData = data[firstElem],
childPath = pathTokens.slice(1).join('.');

actualKey = childPath;
return getDataRecursive(childData);
}
return getDataSimple(data);
};

return getDataRecursive;
}

function forcePaths(params, pathSet, translator) {
Expand Down Expand Up @@ -187,7 +203,7 @@ function noop() {

function keyFilter(includedKeySet, hash) {
return includedKeySet.reduce(function(fHash, key) {
fHash[key] = hash[key];
fHash[key] = accessFunction(key)(hash);
return fHash;
}, {});
}