From 89645ba55760766ca33c116b2d8fea83f890d32d Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Mon, 22 Mar 2021 11:37:10 -0500 Subject: [PATCH 1/5] version bump --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index 559ed9a..4af5d08 100644 --- a/box.json +++ b/box.json @@ -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@/mementifier-@build.version@.zip", "author":"Ortus Solutions, Corp", "homepage":"https://github.com/coldbox-modules/mementifier", From bc1ac837127f3440a257f4b147be18536975fe3e Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Mon, 26 Apr 2021 09:39:45 -0500 Subject: [PATCH 2/5] * When using orm with composite keys and no default includes it should look at the metdata for the identifier type not the includes --- changelog.md | 9 +++++++++ interceptors/Mementifier.cfc | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index e5be050..6f11b8f 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,15 @@ 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- + +### 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 diff --git a/interceptors/Mementifier.cfc b/interceptors/Mementifier.cfc index 52e707a..18f335f 100644 --- a/interceptors/Mementifier.cfc +++ b/interceptors/Mementifier.cfc @@ -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 ); From 6d61a5b2f4b4fff03448bc6ff4dee4cdcbe148fb Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Fri, 30 Apr 2021 18:06:20 -0500 Subject: [PATCH 3/5] * Ability to do output aliases using `:` notation: `property:alias` --- changelog.md | 6 ++++- interceptors/Mementifier.cfc | 31 ++++++++++++++++---------- test-harness/box.json | 2 +- test-harness/config/Coldbox.cfc | 10 +++------ test-harness/handlers/Main.cfc | 5 ++++- test-harness/models/User.cfc | 4 ++-- test-harness/tests/specs/MainTests.cfc | 13 +++++++++-- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/changelog.md b/changelog.md index 6f11b8f..9dad642 100644 --- a/changelog.md +++ b/changelog.md @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ---- -## [2.5.0] => 2021- +## [2.5.0] => 2021-APR-30 + +### Added + +* Ability to do output aliases using `:` notation: `property:alias` ### Fixed diff --git a/interceptors/Mementifier.cfc b/interceptors/Mementifier.cfc index 18f335f..b568edb 100644 --- a/interceptors/Mementifier.cfc +++ b/interceptors/Mementifier.cfc @@ -290,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 { @@ -314,7 +321,7 @@ component { ) : thisValue; if ( isNull( thisValue ) ) { - result[ item ] = javacast( "null", "" ); + result[ thisAlias ] = javacast( "null", "" ); } // Match timestamps + date/time objects else if ( @@ -332,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 @@ -365,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 ), @@ -374,7 +381,7 @@ component { ignoreDefaults = nestedIncludes.len() ? arguments.ignoreDefaults : false ); } else { - result[ item ][ thisIndex ] = thisValue[ thisIndex ]; + result[ thisAlias ][ thisIndex ] = thisValue[ thisIndex ]; } } } @@ -400,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; } } diff --git a/test-harness/box.json b/test-harness/box.json index 40587e0..5ae622b 100644 --- a/test-harness/box.json +++ b/test-harness/box.json @@ -15,7 +15,7 @@ "installPaths":{ "coldbox":"coldbox/", "testbox":"testbox/", - "cborm":"modules/cborm/", + "cborm":"lazymodules/cborm/", "mockdatacfc":"modules/mockdatacfc/" }, "testbox":{ diff --git a/test-harness/config/Coldbox.cfc b/test-harness/config/Coldbox.cfc index 80c97b8..c24102e 100644 --- a/test-harness/config/Coldbox.cfc +++ b/test-harness/config/Coldbox.cfc @@ -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, @@ -50,7 +50,6 @@ //Register interceptors as an array, we need order interceptors = [ - //SES ]; //LogBox DSL @@ -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" ); diff --git a/test-harness/handlers/Main.cfc b/test-harness/handlers/Main.cfc index 0fa323d..b05bbba 100644 --- a/test-harness/handlers/Main.cfc +++ b/test-harness/handlers/Main.cfc @@ -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 = ""; @@ -21,6 +22,8 @@ otherURL = "www.luismajano.com" }; + + var oUser = populateModel( model = userService.new(), memento = mockData, @@ -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" ) ? diff --git a/test-harness/models/User.cfc b/test-harness/models/User.cfc index e076a83..4da7308 100755 --- a/test-harness/models/User.cfc +++ b/test-harness/models/User.cfc @@ -165,8 +165,8 @@ component persistent="true" //"*" "userId", "blogUrl", - "fname", - "lname" + "fname:firstName", + "lname:lastName" ], // Default Exclusions defaultExcludes = [ diff --git a/test-harness/tests/specs/MainTests.cfc b/test-harness/tests/specs/MainTests.cfc index a263e40..8d9f062 100644 --- a/test-harness/tests/specs/MainTests.cfc +++ b/test-harness/tests/specs/MainTests.cfc @@ -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() { @@ -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() { @@ -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" ); + }); } ); } From 8757ad60351854a6461c6c0eb0e15234056e52ae Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Fri, 30 Apr 2021 18:16:19 -0500 Subject: [PATCH 4/5] oops on module location --- test-harness/box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-harness/box.json b/test-harness/box.json index 5ae622b..40587e0 100644 --- a/test-harness/box.json +++ b/test-harness/box.json @@ -15,7 +15,7 @@ "installPaths":{ "coldbox":"coldbox/", "testbox":"testbox/", - "cborm":"lazymodules/cborm/", + "cborm":"modules/cborm/", "mockdatacfc":"modules/mockdatacfc/" }, "testbox":{ From 4bd7324050a06fe848cba8a2ee5eaad23872efde Mon Sep 17 00:00:00 2001 From: Luis Majano Date: Fri, 30 Apr 2021 18:21:47 -0500 Subject: [PATCH 5/5] missing semi colon --- interceptors/Mementifier.cfc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interceptors/Mementifier.cfc b/interceptors/Mementifier.cfc index b568edb..2734965 100644 --- a/interceptors/Mementifier.cfc +++ b/interceptors/Mementifier.cfc @@ -292,7 +292,7 @@ component { var thisValue = javacast( "null", "" ); // Do we have a property output alias? if ( item.find( ":" ) ) { - var thisAlias = item.getToken( 2, ":" ) + var thisAlias = item.getToken( 2, ":" ); item = item.getToken( 1, ":" ); } else { var thisAlias = item;