feat: serialize data by action type
This commit is contained in:
@@ -87,9 +87,22 @@ export class WorkflowInterpreter {
|
|||||||
public debugMessages: string[] = [];
|
public debugMessages: string[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of all the serializable data extracted from the run.
|
* Storage for different types of serializable data
|
||||||
*/
|
*/
|
||||||
public serializableData: string[] = [];
|
public serializableDataByType: {
|
||||||
|
scrapeSchema: any[],
|
||||||
|
scrapeList: any[],
|
||||||
|
other: any[]
|
||||||
|
} = {
|
||||||
|
scrapeSchema: [],
|
||||||
|
scrapeList: [],
|
||||||
|
other: []
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Track the current action type being processed
|
||||||
|
*/
|
||||||
|
private currentActionType: string | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of all the binary data extracted from the run.
|
* An array of all the binary data extracted from the run.
|
||||||
@@ -181,6 +194,9 @@ export class WorkflowInterpreter {
|
|||||||
this.debugMessages.push(`[${new Date().toLocaleString()}] ` + msg);
|
this.debugMessages.push(`[${new Date().toLocaleString()}] ` + msg);
|
||||||
this.socket.emit('log', msg)
|
this.socket.emit('log', msg)
|
||||||
},
|
},
|
||||||
|
setActionType: (type: string) => {
|
||||||
|
this.currentActionType = type;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
serializableCallback: (data: any) => {
|
serializableCallback: (data: any) => {
|
||||||
this.socket.emit('serializableCallback', data);
|
this.socket.emit('serializableCallback', data);
|
||||||
@@ -246,7 +262,12 @@ export class WorkflowInterpreter {
|
|||||||
this.interpreter = null;
|
this.interpreter = null;
|
||||||
this.breakpoints = [];
|
this.breakpoints = [];
|
||||||
this.interpretationResume = null;
|
this.interpretationResume = null;
|
||||||
this.serializableData = [];
|
this.currentActionType = null;
|
||||||
|
this.serializableDataByType = {
|
||||||
|
scrapeSchema: [],
|
||||||
|
scrapeList: [],
|
||||||
|
other: []
|
||||||
|
};
|
||||||
this.binaryData = [];
|
this.binaryData = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,9 +299,19 @@ export class WorkflowInterpreter {
|
|||||||
this.debugMessages.push(`[${new Date().toLocaleString()}] ` + msg);
|
this.debugMessages.push(`[${new Date().toLocaleString()}] ` + msg);
|
||||||
this.socket.emit('debugMessage', msg)
|
this.socket.emit('debugMessage', msg)
|
||||||
},
|
},
|
||||||
|
setActionType: (type: string) => {
|
||||||
|
this.currentActionType = type;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
serializableCallback: (data: any) => {
|
serializableCallback: (data: any) => {
|
||||||
this.serializableData.push(data);
|
if (this.currentActionType === 'scrapeSchema') {
|
||||||
|
this.serializableDataByType.scrapeSchema.push(data);
|
||||||
|
} else if (this.currentActionType === 'scrapeList') {
|
||||||
|
this.serializableDataByType.scrapeList.push(data);
|
||||||
|
} else {
|
||||||
|
this.serializableDataByType.other.push(data);
|
||||||
|
}
|
||||||
|
|
||||||
this.socket.emit('serializableCallback', data);
|
this.socket.emit('serializableCallback', data);
|
||||||
},
|
},
|
||||||
binaryCallback: async (data: string, mimetype: string) => {
|
binaryCallback: async (data: string, mimetype: string) => {
|
||||||
@@ -311,14 +342,23 @@ export class WorkflowInterpreter {
|
|||||||
|
|
||||||
const status = await interpreter.run(page, params);
|
const status = await interpreter.run(page, params);
|
||||||
|
|
||||||
const lastArray = this.serializableData.length > 1
|
// Structure the output to maintain separate data for each action type
|
||||||
? [this.serializableData[this.serializableData.length - 1]]
|
|
||||||
: this.serializableData;
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
log: this.debugMessages,
|
log: this.debugMessages,
|
||||||
result: status,
|
result: status,
|
||||||
serializableOutput: lastArray.reduce((reducedObject, item, index) => {
|
scrapeSchemaOutput: this.serializableDataByType.scrapeSchema.reduce((reducedObject, item, index) => {
|
||||||
|
return {
|
||||||
|
[`schema-${index}`]: item,
|
||||||
|
...reducedObject,
|
||||||
|
}
|
||||||
|
}, {}),
|
||||||
|
scrapeListOutput: this.serializableDataByType.scrapeList.reduce((reducedObject, item, index) => {
|
||||||
|
return {
|
||||||
|
[`list-${index}`]: item,
|
||||||
|
...reducedObject,
|
||||||
|
}
|
||||||
|
}, {}),
|
||||||
|
otherOutput: this.serializableDataByType.other.reduce((reducedObject, item, index) => {
|
||||||
return {
|
return {
|
||||||
[`item-${index}`]: item,
|
[`item-${index}`]: item,
|
||||||
...reducedObject,
|
...reducedObject,
|
||||||
|
|||||||
Reference in New Issue
Block a user