Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Apr 30, 2021
2 parents d30fe63 + 4bd7324 commit 790407a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"Mementifier : The State Maker!",
"version":"2.4.0",
"version":"2.5.0",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/mementifier/@build.version@/[email protected]@.zip",
"author":"Ortus Solutions, Corp",
"homepage":"https://github.com/coldbox-modules/mementifier",
Expand Down
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

----

## [2.5.0] => 2021-APR-30

### Added

* Ability to do output aliases using `:` notation: `property:alias`

### Fixed

* When using orm with composite keys and no default includes it should look at the metdata for the identifier type not the includes


----

## [2.4.0] => 2021-MAR-22
Expand Down
34 changes: 21 additions & 13 deletions interceptors/Mementifier.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ component {
thisMemento.defaultIncludes,
entityMd.getIdentifierPropertyName()
);
} else if ( thisMemento.defaultIncludes.getIdentifierType().isComponentType() ) {
} else if ( entityMd.getIdentifierType().isComponentType() ) {
arrayAppend(
thisMemento.defaultIncludes,
// Convert Java array to CF Array
listToArray( arrayToList( entityMd.getIdentifierType().getPropertyNames() ) ),
true
);
Expand Down Expand Up @@ -289,6 +290,13 @@ component {

// Retrieve Value for transformation: ACF Incompats Suck on elvis operator
var thisValue = javacast( "null", "" );
// Do we have a property output alias?
if ( item.find( ":" ) ) {
var thisAlias = item.getToken( 2, ":" );
item = item.getToken( 1, ":" );
} else {
var thisAlias = item;
}

if ( arguments.trustedGetters || structKeyExists( this, "get#item#" ) ) {
try {
Expand All @@ -313,7 +321,7 @@ component {
) : thisValue;

if ( isNull( thisValue ) ) {
result[ item ] = javacast( "null", "" );
result[ thisAlias ] = javacast( "null", "" );
}
// Match timestamps + date/time objects
else if (
Expand All @@ -331,26 +339,26 @@ component {
// Iso Date?
if ( arguments.iso8601Format ) {
// we need to convert trailing Zulu time designations offset or JS libs like Moment will not know how to parse it
result[ item ] = this.$FORMATTER_ISO8601.format( thisValue ).replace( "Z", "+00:00" );
result[ thisAlias ] = this.$FORMATTER_ISO8601.format( thisValue ).replace( "Z", "+00:00" );
} else {
result[ item ] = customDateFormatter.format( thisValue );
result[ thisAlias ] = customDateFormatter.format( thisValue );
}
} catch ( any e ) {
result[ item ] = thisValue;
result[ thisAlias ] = thisValue;
}
}
// Strict Type Boolean Values
else if ( !isNumeric( thisValue ) && isBoolean( thisValue ) ) {
result[ item ] = javacast( "Boolean", thisValue );
result[ thisAlias ] = javacast( "Boolean", thisValue );
}
// Simple Values
else if ( isSimpleValue( thisValue ) ) {
result[ item ] = thisValue;
result[ thisAlias ] = thisValue;
}
// Array Collections
else if ( isArray( thisValue ) ) {
// Map Items into result object
result[ item ] = [];
result[ thisAlias ] = [];
// Again we use traditional loops to avoid closure references and slowness on some engines
for ( var thisIndex = 1; thisIndex <= arrayLen( thisValue ); thisIndex++ ) {
// only get mementos from relationships that have mementos, in the event that we have an already-serialized array of structs
Expand All @@ -364,7 +372,7 @@ component {
var nestedIncludes = $buildNestedMementoList( includes, item );

// Process the item memento
result[ item ][ thisIndex ] = thisValue[ thisIndex ].getMemento(
result[ thisAlias ][ thisIndex ] = thisValue[ thisIndex ].getMemento(
includes = nestedIncludes,
excludes = $buildNestedMementoList( excludes, item ),
mappers = $buildNestedMementoStruct( mappers, item ),
Expand All @@ -373,7 +381,7 @@ component {
ignoreDefaults = nestedIncludes.len() ? arguments.ignoreDefaults : false
);
} else {
result[ item ][ thisIndex ] = thisValue[ thisIndex ];
result[ thisAlias ][ thisIndex ] = thisValue[ thisIndex ];
}
}
}
Expand All @@ -399,16 +407,16 @@ component {
// Do we have a root already for this guy?
if ( result.keyExists( item ) ) {
structAppend(
result[ item ],
result[ thisAlias ],
thisItemMemento,
false
);
} else {
result[ item ] = thisItemMemento;
result[ thisAlias ] = thisItemMemento;
}
} else {
// we don't know what to do with this item so we return as-is
result[ item ] = thisValue;
result[ thisAlias ] = thisValue;
}
}

Expand Down
10 changes: 3 additions & 7 deletions test-harness/config/Coldbox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//Error/Exception Handling
exceptionHandler = "",
onInvalidEvent = "",
customErrorTemplate = "/coldbox/system/includes/BugReport.cfm",
customErrorTemplate = "/coldbox/system/exceptions/Whoops.cfm",

//Application Aspects
handlerCaching = false,
Expand All @@ -50,7 +50,6 @@

//Register interceptors as an array, we need order
interceptors = [
//SES
];

//LogBox DSL
Expand All @@ -71,12 +70,9 @@

}

/**
* Load the Module you are testing
*/
function afterAspectsLoad( event, interceptData, rc, prc ){
function afterModuleRegistrations( event, interceptData ){
controller.getModuleService()
.registerAndActivateModule(
.registerModule(
moduleName = request.MODULE_NAME,
invocationPath = "moduleroot"
);
Expand Down
5 changes: 4 additions & 1 deletion test-harness/handlers/Main.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
property name="permissionService" inject="entityService:Permission";

function index( event, rc, prc ){

param rc.ignoreDefaults = false;
param rc.ignoredRoots = "";
param rc.includes = "";
Expand All @@ -21,6 +22,8 @@
otherURL = "www.luismajano.com"
};



var oUser = populateModel(
model = userService.new(),
memento = mockData,
Expand Down Expand Up @@ -56,7 +59,7 @@
mappers = {
lname = function( item ){ return item.ucase(); },
"foo" = function( _, memento ) {
return memento.fname & " " & memento.lname;
return memento.firstName & " " & memento.lastName;
}
},
iso8601Format = event.valueExists( "iso8601Format" ) ?
Expand Down
4 changes: 2 additions & 2 deletions test-harness/models/User.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ component persistent="true"
//"*"
"userId",
"blogUrl",
"fname",
"lname"
"fname:firstName",
"lname:lastName"
],
// Default Exclusions
defaultExcludes = [
Expand Down
13 changes: 11 additions & 2 deletions test-harness/tests/specs/MainTests.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.notToHaveKey( "role" )
.notToHaveKey( "permission" );
// mapper
expect( memento.lname ).toBe( "TESTUSER" );
expect( memento.lastName ).toBe( "TESTUSER" );
} );

it( "can render mementos even if the object has already-serialized data", function() {
Expand Down Expand Up @@ -82,7 +82,7 @@
// Expect inherited properties from the base class
expect( memento ).toBeStruct();
expect( memento ).toHaveKey( "foo" );
expect( memento.foo ).toBe( memento.fname & " " & memento.lname );
expect( memento.foo ).toBe( memento.firstName & " " & memento.lastName );
} );

it( "skips properties that do not exist and do not have a mapper", function() {
Expand Down Expand Up @@ -173,6 +173,15 @@
expect( memento.role.permissions[ 2 ].description ).toBeWithCase( "WRITE" );
} ).notToThrow();
} );

it( "can use property aliases for includes", function(){
var event = this.request(
route = "/main/index",
params = { includes = "APIToken:token"}
);
var memento = deserializeJSON( event.getRenderedContent() );
expect( memento ).toHaveKey( "token,firstName,lastName" );
});
} );
}

Expand Down

0 comments on commit 790407a

Please sign in to comment.