( query?: TaskNotesRuntimeTaskQuery )
| 1104 | } |
| 1105 | |
| 1106 | private async queryTasks( |
| 1107 | query?: TaskNotesRuntimeTaskQuery |
| 1108 | ): Promise<TaskNotesRuntimeTaskQueryResult> { |
| 1109 | const execution = this.normalizeRuntimeQueryForExecution(query); |
| 1110 | if (!execution.validation.valid) { |
| 1111 | throw new TaskNotesApiError("invalid_input", "TaskNotes runtime query is invalid", { |
| 1112 | status: 400, |
| 1113 | details: { issues: execution.validation.issues }, |
| 1114 | }); |
| 1115 | } |
| 1116 | |
| 1117 | const allTasks = await this.plugin.cacheManager.getAllTasks(); |
| 1118 | const scopedTasks = applyRuntimeQueryScope(allTasks, execution.normalized.scope); |
| 1119 | const scopedPaths = new Set(scopedTasks.map((task) => task.path)); |
| 1120 | const groupedTasks = await this.plugin.filterService.getGroupedTasks(execution.filterQuery); |
| 1121 | const matchedTasksByPath = new Map<string, TaskInfo>(); |
| 1122 | |
| 1123 | for (const groupTasks of groupedTasks.values()) { |
| 1124 | for (const task of groupTasks) { |
| 1125 | if (scopedPaths.has(task.path) && !matchedTasksByPath.has(task.path)) { |
| 1126 | matchedTasksByPath.set(task.path, task); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | const matchedTasks = Array.from(matchedTasksByPath.values()); |
| 1132 | const offset = execution.normalized.offset; |
| 1133 | const limit = execution.normalized.limit; |
| 1134 | const returnedTasks = |
| 1135 | typeof limit === "number" |
| 1136 | ? matchedTasks.slice(offset, offset + limit) |
| 1137 | : matchedTasks.slice(offset); |
| 1138 | const returnedPaths = new Set(returnedTasks.map((task) => task.path)); |
| 1139 | |
| 1140 | return { |
| 1141 | tasks: returnedTasks.map(copyTaskInfo), |
| 1142 | total: scopedTasks.length, |
| 1143 | matched: matchedTasks.length, |
| 1144 | returned: returnedTasks.length, |
| 1145 | groups: |
| 1146 | execution.normalized.group.length > 0 |
| 1147 | ? runtimeQueryGroups(groupedTasks, returnedPaths) |
| 1148 | : undefined, |
| 1149 | query: execution.normalized, |
| 1150 | warnings: execution.validation.warnings, |
| 1151 | }; |
| 1152 | } |
| 1153 | |
| 1154 | private validateRuntimeQuery(query: unknown): TaskNotesRuntimeQueryValidationResult { |
| 1155 | return this.normalizeRuntimeQueryForExecution(query).validation; |
no test coverage detected