MCPcopy
hub / github.com/omkarcloud/botasaurus / _applyViewForUiLargeTask

Function _applyViewForUiLargeTask

js/botasaurus-server-js/src/views.ts:479–522  ·  view source on GitHub ↗
(taskId: number, view: string, views: View[], inputData: any, _per_page: number, start: number, end: number, containsListField: boolean)

Source from the content-addressed store, hash-verified

477 return [results, [], 0];
478}
479async function _applyViewForUiLargeTask(taskId: number, view: string, views: View[], inputData: any, _per_page: number, start: number, end: number, containsListField: boolean): Promise<[number, any[], string[]]> {
480 const viewObj = view && views.find(v => v.id === view);
481 let result: any[] = [];
482 const hidden_fields: string[] = [];
483
484 if (viewObj) {
485 const targetFields: (Field | CustomField | ExpandDictField | ExpandListField)[] = isNotNullish(inputData) ? getFields(viewObj.fields, inputData, hidden_fields) : viewObj.fields;
486 if (containsListField) {
487 let items_count = 0
488 // @ts-ignore
489 await TaskResults.streamTask(taskId, (record, _index) => {
490 if (items_count >= end) return false;
491 for (const expandedRecord of transformRecordStream(targetFields, record)) {
492 if (items_count >= start && items_count < end) {
493 result.push(expandedRecord);
494 }
495 items_count++;
496 }
497 });
498
499 return [items_count, result, hidden_fields];
500 } else {
501 // @ts-ignore
502 await TaskResults.streamTask(taskId, (record, index) => {
503 if (index >= end) return false;
504 if (index >= start) {
505 const expandedRecords: any[] = transformRecord(targetFields, record);
506 result.push(...expandedRecords);
507 }
508 }, end);
509 return [0, result, hidden_fields];
510 }
511 }
512
513 // @ts-ignore
514 await TaskResults.streamTask(taskId, (record, index) => {
515 if (index >= end) return false;
516 if (index >= start) {
517 result.push(record);
518 }
519 }, end);
520
521 return [0, result, hidden_fields];
522}
523function applyView(results: any[], view: string, views: View[]): any[] {
524 if (isEmpty(view)) {
525 return results;

Callers 1

cleanResultsForLargeTaskFunction · 0.90

Calls 6

isNotNullishFunction · 0.90
transformRecordStreamFunction · 0.85
transformRecordFunction · 0.85
streamTaskMethod · 0.80
getFieldsFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected