fix: __name non existent field
This commit is contained in:
@@ -486,7 +486,7 @@ export default class Interpreter extends EventEmitter {
|
|||||||
await this.options.serializableCallback(scrapeResults);
|
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) {
|
if (this.isAborted) {
|
||||||
this.log('Workflow aborted, stopping scrapeSchema', Level.WARN);
|
this.log('Workflow aborted, stopping scrapeSchema', Level.WARN);
|
||||||
return;
|
return;
|
||||||
@@ -542,17 +542,17 @@ export default class Interpreter extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const actionType = "scrapeSchema";
|
const actionType = "scrapeSchema";
|
||||||
const actionName = (schema as any).__name || "Texts";
|
const name = actionName || "Texts";
|
||||||
|
|
||||||
if (!this.namedResults[actionType]) this.namedResults[actionType] = {};
|
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]) this.serializableDataByType[actionType] = {};
|
||||||
if (!this.serializableDataByType[actionType][actionName]) {
|
if (!this.serializableDataByType[actionType][name]) {
|
||||||
this.serializableDataByType[actionType][actionName] = [];
|
this.serializableDataByType[actionType][name] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serializableDataByType[actionType][actionName] = [...this.cumulativeResults];
|
this.serializableDataByType[actionType][name] = [...this.cumulativeResults];
|
||||||
|
|
||||||
await this.options.serializableCallback({
|
await this.options.serializableCallback({
|
||||||
scrapeList: this.serializableDataByType.scrapeList,
|
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) {
|
if (this.isAborted) {
|
||||||
this.log('Workflow aborted, stopping scrapeList', Level.WARN);
|
this.log('Workflow aborted, stopping scrapeList', Level.WARN);
|
||||||
return;
|
return;
|
||||||
@@ -596,7 +596,7 @@ export default class Interpreter extends EventEmitter {
|
|||||||
}, config);
|
}, config);
|
||||||
} else {
|
} else {
|
||||||
paginationUsed = true;
|
paginationUsed = true;
|
||||||
scrapeResults = await this.handlePagination(page, config);
|
scrapeResults = await this.handlePagination(page, config, actionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(scrapeResults)) {
|
if (!Array.isArray(scrapeResults)) {
|
||||||
@@ -607,19 +607,19 @@ export default class Interpreter extends EventEmitter {
|
|||||||
|
|
||||||
if (!paginationUsed) {
|
if (!paginationUsed) {
|
||||||
const actionType = "scrapeList";
|
const actionType = "scrapeList";
|
||||||
let actionName = (config as any).__name || "";
|
let name = actionName || "";
|
||||||
|
|
||||||
if (!actionName || actionName.trim() === "") {
|
if (!name || name.trim() === "") {
|
||||||
this.scrapeListCounter++;
|
this.scrapeListCounter++;
|
||||||
actionName = `List ${this.scrapeListCounter}`;
|
name = `List ${this.scrapeListCounter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
|
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
|
||||||
if (!this.serializableDataByType[actionType][actionName]) {
|
if (!this.serializableDataByType[actionType][name]) {
|
||||||
this.serializableDataByType[actionType][actionName] = [];
|
this.serializableDataByType[actionType][name] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serializableDataByType[actionType][actionName].push(...scrapeResults);
|
this.serializableDataByType[actionType][name].push(...scrapeResults);
|
||||||
|
|
||||||
await this.options.serializableCallback({
|
await this.options.serializableCallback({
|
||||||
scrapeList: this.serializableDataByType.scrapeList,
|
scrapeList: this.serializableDataByType.scrapeList,
|
||||||
@@ -630,18 +630,18 @@ export default class Interpreter extends EventEmitter {
|
|||||||
console.error('ScrapeList action failed completely:', error.message);
|
console.error('ScrapeList action failed completely:', error.message);
|
||||||
|
|
||||||
const actionType = "scrapeList";
|
const actionType = "scrapeList";
|
||||||
let actionName = (config as any).__name || "";
|
let name = actionName || "";
|
||||||
|
|
||||||
if (!actionName || actionName.trim() === "") {
|
if (!name || name.trim() === "") {
|
||||||
this.scrapeListCounter++;
|
this.scrapeListCounter++;
|
||||||
actionName = `List ${this.scrapeListCounter}`;
|
name = `List ${this.scrapeListCounter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.namedResults[actionType]) this.namedResults[actionType] = {};
|
if (!this.namedResults[actionType]) this.namedResults[actionType] = {};
|
||||||
this.namedResults[actionType][actionName] = [];
|
this.namedResults[actionType][name] = [];
|
||||||
|
|
||||||
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
|
if (!this.serializableDataByType[actionType]) this.serializableDataByType[actionType] = {};
|
||||||
this.serializableDataByType[actionType][actionName] = [];
|
this.serializableDataByType[actionType][name] = [];
|
||||||
|
|
||||||
await this.options.serializableCallback({
|
await this.options.serializableCallback({
|
||||||
scrapeList: this.serializableDataByType.scrapeList,
|
scrapeList: this.serializableDataByType.scrapeList,
|
||||||
@@ -736,26 +736,7 @@ export default class Interpreter extends EventEmitter {
|
|||||||
debug.setActionType(String(step.action));
|
debug.setActionType(String(step.action));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((step as any)?.name) {
|
stepName = (step as any)?.name || String(step.action);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debug && typeof (debug as any).setActionName === "function") {
|
if (debug && typeof (debug as any).setActionName === "function") {
|
||||||
(debug as any).setActionName(stepName);
|
(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];
|
const params = !step.args || Array.isArray(step.args) ? step.args : [step.args];
|
||||||
if (step.action === 'screenshot') {
|
if (step.action === 'screenshot') {
|
||||||
await (wawActions.screenshot as any)(...(params ?? []), stepName ?? undefined);
|
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 {
|
} else {
|
||||||
await wawActions[step.action as CustomFunctions](...(params ?? []));
|
await wawActions[step.action as CustomFunctions](...(params ?? []));
|
||||||
}
|
}
|
||||||
@@ -830,14 +814,14 @@ export default class Interpreter extends EventEmitter {
|
|||||||
fields: any,
|
fields: any,
|
||||||
limit?: number,
|
limit?: number,
|
||||||
pagination: any
|
pagination: any
|
||||||
}) {
|
}, providedActionName: string = "") {
|
||||||
if (this.isAborted) {
|
if (this.isAborted) {
|
||||||
this.log('Workflow aborted, stopping pagination', Level.WARN);
|
this.log('Workflow aborted, stopping pagination', Level.WARN);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionType = "scrapeList";
|
const actionType = "scrapeList";
|
||||||
let actionName = (config as any).__name || "";
|
let actionName = providedActionName || "";
|
||||||
if (!actionName || actionName.trim() === "") {
|
if (!actionName || actionName.trim() === "") {
|
||||||
this.scrapeListCounter++;
|
this.scrapeListCounter++;
|
||||||
actionName = `List ${this.scrapeListCounter}`;
|
actionName = `List ${this.scrapeListCounter}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user