@@ -48,12 +48,20 @@ interface IMetadata {
4848 PolicyOutputEventType . ErrorEvent
4949 ] ,
5050 defaultEvent : true ,
51- properties : [ {
52- name : 'unsigned' ,
53- label : 'Unsigned VC' ,
54- title : 'Unsigned document' ,
55- type : PropertyType . Checkbox
56- } ]
51+ properties : [
52+ {
53+ name : 'unsigned' ,
54+ label : 'Unsigned VC' ,
55+ title : 'Unsigned document' ,
56+ type : PropertyType . Checkbox
57+ } ,
58+ {
59+ name : 'passOriginal' ,
60+ label : 'Pass original' ,
61+ title : 'Pass original document' ,
62+ type : PropertyType . Checkbox
63+ }
64+ ]
5765 } ,
5866 variables : [
5967 { path : 'options.outputSchema' , alias : 'schema' , type : 'Schema' }
@@ -84,17 +92,19 @@ export class CustomLogicBlock {
8492 const ref = PolicyComponentsUtils . GetBlockRef < IPolicyCalculateBlock > ( this ) ;
8593
8694 try {
87- const documents = await this . execute ( event . data , event . user ) ;
88- if ( ! documents ) {
89- return ;
95+ const triggerEvents = ( documents : IPolicyDocument | IPolicyDocument [ ] ) => {
96+ if ( ! documents ) {
97+ return ;
98+ }
99+ event . data . data = documents ;
100+ ref . triggerEvents ( PolicyOutputEventType . RunEvent , event . user , event . data ) ;
101+ ref . triggerEvents ( PolicyOutputEventType . ReleaseEvent , event . user , null ) ;
102+ ref . triggerEvents ( PolicyOutputEventType . RefreshEvent , event . user , event . data ) ;
103+ PolicyComponentsUtils . ExternalEventFn ( new ExternalEvent ( ExternalEventType . Run , ref , event ?. user , {
104+ documents : ExternalDocuments ( event ?. data ?. data )
105+ } ) ) ;
90106 }
91- event . data . data = documents ;
92- ref . triggerEvents ( PolicyOutputEventType . RunEvent , event . user , event . data ) ;
93- ref . triggerEvents ( PolicyOutputEventType . ReleaseEvent , event . user , null ) ;
94- ref . triggerEvents ( PolicyOutputEventType . RefreshEvent , event . user , event . data ) ;
95- PolicyComponentsUtils . ExternalEventFn ( new ExternalEvent ( ExternalEventType . Run , ref , event ?. user , {
96- documents : ExternalDocuments ( event ?. data ?. data )
97- } ) ) ;
107+ await this . execute ( event . data , event . user , triggerEvents ) ;
98108 } catch ( error ) {
99109 ref . error ( PolicyUtils . getErrorMessage ( error ) ) ;
100110 }
@@ -125,7 +135,7 @@ export class CustomLogicBlock {
125135 * @param state
126136 * @param user
127137 */
128- execute ( state : IPolicyEventState , user : PolicyUser ) : Promise < IPolicyDocument | IPolicyDocument [ ] > {
138+ execute ( state : IPolicyEventState , user : PolicyUser , triggerEvents : ( documents : IPolicyDocument | IPolicyDocument [ ] ) => void ) : Promise < IPolicyDocument | IPolicyDocument [ ] > {
129139 return new Promise < IPolicyDocument | IPolicyDocument [ ] > ( async ( resolve , reject ) => {
130140 try {
131141 const ref = PolicyComponentsUtils . GetBlockRef < IPolicyCalculateBlock > ( this ) ;
@@ -143,12 +153,18 @@ export class CustomLogicBlock {
143153 metadata = await this . aggregateMetadata ( documents , user , ref ) ;
144154 }
145155
146- const done = async ( result : any | any [ ] ) => {
156+ const done = async ( result : any | any [ ] , final : boolean ) => {
147157 if ( ! result ) {
148- resolve ( null ) ;
158+ triggerEvents ( null ) ;
159+ if ( final ) {
160+ resolve ( null ) ;
161+ }
149162 return ;
150163 }
151164 const processing = async ( json : any ) : Promise < IPolicyDocument > => {
165+ if ( ref . options . passOriginal ) {
166+ return json ;
167+ }
152168 if ( ref . options . unsigned ) {
153169 return await this . createUnsignedDocument ( json , ref ) ;
154170 } else {
@@ -160,10 +176,16 @@ export class CustomLogicBlock {
160176 for ( const r of result ) {
161177 items . push ( await processing ( r ) )
162178 }
163- resolve ( items ) ;
179+ triggerEvents ( items ) ;
180+ if ( final ) {
181+ resolve ( items ) ;
182+ }
164183 return ;
165184 } else {
166- resolve ( await processing ( result ) ) ;
185+ triggerEvents ( await processing ( result ) ) ;
186+ if ( final ) {
187+ resolve ( await processing ( result ) ) ;
188+ }
167189 return ;
168190 }
169191 }
@@ -200,9 +222,9 @@ export class CustomLogicBlock {
200222 worker . on ( 'error' , ( error ) => {
201223 reject ( error ) ;
202224 } ) ;
203- worker . on ( 'message' , async ( result ) => {
225+ worker . on ( 'message' , async ( data ) => {
204226 try {
205- await done ( result ) ;
227+ await done ( data . result , data . final ) ;
206228 } catch ( error ) {
207229 reject ( error ) ;
208230 }
0 commit comments