fix: __name non existent field

This commit is contained in:
Rohit Rajan
2025-11-18 15:11:09 +05:30
parent 801ae5a365
commit 1b8e5046a8

View File

@@ -486,7 +486,7 @@ export default class Interpreter extends EventEmitter {
await this.options.serializableCallback(scrapeResults);
},
scrapeSchema: async (schema: Record<string, { selector: string; tag: string, attribute: string; shadow: string}>) => {
scrapeSchema: async (schema: Record<string, { selector: string; tag: string, attribute: string; shadow: string}>, actionName: string = "") => {
if (this.isAborted) {
this.log('Workflow aborted, stopping scrapeSchema', Level.WARN);
return;
@@ -542,17 +542,17 @@ export default class Interpreter extends EventEmitter {
}
const actionType = "scrapeSchema";
const actionName = (schema as any).__name || "Texts";
const name = actionName || "Texts";
if (!this.namedResults[actionType]) this.namedResults[actionType] = {};
this.namedResults[actionType][actionName] = this.cumulativeResults;
this.namedResults[actionType][name] = this.cumulativeResults;
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
if (!this.serializableDataByType[actionType][actionName]) {
this.serializableDataByType[actionType][actionName] = [];
if (!this.serializableDataByType[actionType][name]) {
this.serializableDataByType[actionType][name] = [];
}
this.serializableDataByType[actionType][actionName] = [...this.cumulativeResults];
this.serializableDataByType[actionType][name] = [...this.cumulativeResults];
await this.options.serializableCallback({
scrapeList: this.serializableDataByType.scrapeList,
@@ -560,7 +560,7 @@ export default class Interpreter extends EventEmitter {
});
},
scrapeList: async (config: { listSelector: string, fields: any, limit?: number, pagination: any }) => {
scrapeList: async (config: { listSelector: string, fields: any, limit?: number, pagination: any }, actionName: string = "") => {
if (this.isAborted) {
this.log('Workflow aborted, stopping scrapeList', Level.WARN);
return;
@@ -596,7 +596,7 @@ export default class Interpreter extends EventEmitter {
}, config);
} else {
paginationUsed = true;
scrapeResults = await this.handlePagination(page, config);
scrapeResults = await this.handlePagination(page, config, actionName);
}
if (!Array.isArray(scrapeResults)) {
@@ -607,19 +607,19 @@ export default class Interpreter extends EventEmitter {
if (!paginationUsed) {
const actionType = "scrapeList";
let actionName = (config as any).__name || "";
let name = actionName || "";
if (!actionName || actionName.trim() === "") {
if (!name || name.trim() === "") {
this.scrapeListCounter++;
actionName = `List ${this.scrapeListCounter}`;
name = `List ${this.scrapeListCounter}`;
}
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
if (!this.serializableDataByType[actionType][actionName]) {
this.serializableDataByType[actionType][actionName] = [];
if (!this.serializableDataByType[actionType][name]) {
this.serializableDataByType[actionType][name] = [];
}
this.serializableDataByType[actionType][actionName].push(...scrapeResults);
this.serializableDataByType[actionType][name].push(...scrapeResults);
await this.options.serializableCallback({
scrapeList: this.serializableDataByType.scrapeList,
@@ -630,18 +630,18 @@ export default class Interpreter extends EventEmitter {
console.error('ScrapeList action failed completely:', error.message);
const actionType = "scrapeList";
let actionName = (config as any).__name || "";
let name = actionName || "";
if (!actionName || actionName.trim() === "") {
if (!name || name.trim() === "") {
this.scrapeListCounter++;
actionName = `List ${this.scrapeListCounter}`;
name = `List ${this.scrapeListCounter}`;
}
if (!this.namedResults[actionType]) this.namedResults[actionType] = {};
this.namedResults[actionType][actionName] = [];
this.namedResults[actionType][name] = [];
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
this.serializableDataByType[actionType][actionName] = [];
this.serializableDataByType[actionType][name] = [];
await this.options.serializableCallback({
scrapeList: this.serializableDataByType.scrapeList,
@@ -736,26 +736,7 @@ export default class Interpreter extends EventEmitter {
debug.setActionType(String(step.action));
}
if ((step as any)?.name) {
stepName = (step as any).name;
} else if (
Array.isArray((step as any)?.args) &&
(step as any).args.length > 0 &&
typeof (step as any).args[0] === "object" &&
"__name" in (step as any).args[0]
) {
stepName = (step as any).args[0].__name;
} else if (
typeof (step as any)?.args === "object" &&
step?.args !== null &&
"__name" in (step as any).args
) {
stepName = (step as any).args.__name;
}
if (!stepName) {
stepName = String(step.action);
}
stepName = (step as any)?.name || String(step.action);
if (debug && typeof (debug as any).setActionName === "function") {
(debug as any).setActionName(stepName);
@@ -769,6 +750,9 @@ export default class Interpreter extends EventEmitter {
const params = !step.args || Array.isArray(step.args) ? step.args : [step.args];
if (step.action === 'screenshot') {
await (wawActions.screenshot as any)(...(params ?? []), stepName ?? undefined);
} else if (step.action === 'scrapeList' || step.action === 'scrapeSchema') {
const actionName = (step as any).name || "";
await wawActions[step.action as CustomFunctions](...(params ?? []), actionName);
} else {
await wawActions[step.action as CustomFunctions](...(params ?? []));
}
@@ -830,14 +814,14 @@ export default class Interpreter extends EventEmitter {
fields: any,
limit?: number,
pagination: any
}) {
}, providedActionName: string = "") {
if (this.isAborted) {
this.log('Workflow aborted, stopping pagination', Level.WARN);
return [];
}
const actionType = "scrapeList";
let actionName = (config as any).__name || "";
let actionName = providedActionName || "";
if (!actionName || actionName.trim() === "") {
this.scrapeListCounter++;
actionName = `List ${this.scrapeListCounter}`;