@@ -40,12 +40,14 @@ class TemplateInstance {
4040 }
4141 this . template = template ;
4242 this . data = null ;
43+ this . composerData = null ;
4344 }
4445
4546 /**
4647 * Set the data for the clause
4748 * @param {object } data - the data for the clause, must be an instance of the
48- * template model for the clause's template
49+ * template model for the clause's template. This should be a plain JS object
50+ * and will be deserialized and validated into the Composer object before assignment.
4951 */
5052 setData ( data ) {
5153 // verify that data is an instance of the template model
@@ -57,21 +59,34 @@ class TemplateInstance {
5759
5860 // downloadExternalDependencies the data using the template model
5961 logger . debug ( 'Setting clause data: ' + JSON . stringify ( data ) ) ;
60- const resource = this . template . getSerializer ( ) . fromJSON ( data ) ;
62+ const resource = this . getTemplate ( ) . getSerializer ( ) . fromJSON ( data ) ;
6163 resource . validate ( ) ;
6264
63- // passed validation!
65+ // save the data
6466 this . data = data ;
67+
68+ // save the composer data
69+ this . composerData = resource ;
6570 }
6671
6772 /**
68- * Get the data for the clause
73+ * Get the data for the clause. This is a plain JS object. To retrieve the Composer
74+ * object call getComposerData().
6975 * @return {object } - the data for the clause, or null if it has not been set
7076 */
7177 getData ( ) {
7278 return this . data ;
7379 }
7480
81+ /**
82+ * Get the data for the clause. This is a Composer object. To retrieve the
83+ * plain JS object suitable for serialization call toJSON() and retrieve the `data` property.
84+ * @return {object } - the data for the clause, or null if it has not been set
85+ */
86+ getDataAsComposerObject ( ) {
87+ return this . composerData ;
88+ }
89+
7590 /**
7691 * Set the data for the clause by parsing natural language text.
7792 * @param {string } text - the data for the clause
@@ -107,7 +122,7 @@ class TemplateInstance {
107122 let hash = '' ;
108123
109124 if ( this . data ) {
110- const textToHash = JSON . stringify ( this . data ) ;
125+ const textToHash = JSON . stringify ( this . getData ( ) ) ;
111126 const hasher = crypto . createHash ( 'sha256' ) ;
112127 hasher . update ( textToHash ) ;
113128 hash = '-' + hasher . digest ( 'hex' ) ;
0 commit comments