( value: unknown, issues: TaskNotesRuntimeQueryIssue[], warnings: TaskNotesRuntimeQueryWarning[] )
| 1362 | } |
| 1363 | |
| 1364 | private normalizeRuntimeSorts( |
| 1365 | value: unknown, |
| 1366 | issues: TaskNotesRuntimeQueryIssue[], |
| 1367 | warnings: TaskNotesRuntimeQueryWarning[] |
| 1368 | ): TaskNotesRuntimeNormalizedTaskQuery["sort"] { |
| 1369 | if (typeof value === "undefined") return []; |
| 1370 | if (!Array.isArray(value)) { |
| 1371 | issues.push({ |
| 1372 | path: "$.sort", |
| 1373 | code: "sort_not_array", |
| 1374 | message: "Runtime query sort must be an array.", |
| 1375 | }); |
| 1376 | return []; |
| 1377 | } |
| 1378 | |
| 1379 | const sorts = value |
| 1380 | .map((entry, index): TaskNotesRuntimeNormalizedTaskQuery["sort"][number] | null => { |
| 1381 | if (!isRecord(entry) || typeof entry["field"] !== "string") { |
| 1382 | issues.push({ |
| 1383 | path: `$.sort.${index}`, |
| 1384 | code: "sort_invalid", |
| 1385 | message: "Runtime query sort entries require a field.", |
| 1386 | }); |
| 1387 | return null; |
| 1388 | } |
| 1389 | const field = this.resolveRuntimeQueryField(entry["field"]); |
| 1390 | if (!field || !field.definition.sortable) { |
| 1391 | issues.push({ |
| 1392 | path: `$.sort.${index}.field`, |
| 1393 | code: "sort_field_unsupported", |
| 1394 | message: `Runtime query field is not sortable: ${entry["field"]}`, |
| 1395 | }); |
| 1396 | return null; |
| 1397 | } |
| 1398 | const direction = entry["direction"] === "desc" ? "desc" : "asc"; |
| 1399 | return { field: field.definition.id, direction }; |
| 1400 | }) |
| 1401 | .filter(isDefined); |
| 1402 | |
| 1403 | if (sorts.length > 1) { |
| 1404 | warnings.push({ |
| 1405 | path: "$.sort", |
| 1406 | code: "multiple_sorts", |
| 1407 | message: "Only the first sort is currently applied by TaskNotes.", |
| 1408 | }); |
| 1409 | } |
| 1410 | return sorts; |
| 1411 | } |
| 1412 | |
| 1413 | private normalizeRuntimeGroups( |
| 1414 | value: unknown, |
no test coverage detected