(value: unknown)
| 373 | } |
| 374 | |
| 375 | export function readListProjects(value: unknown): ListProjectsResult { |
| 376 | const raw = record(value); |
| 377 | const projects: ProjectEntry[] = []; |
| 378 | for (const entry of tableRows(raw['projects'])) { |
| 379 | const name = toText(entry['name']); |
| 380 | if (name === undefined) { |
| 381 | continue; |
| 382 | } |
| 383 | projects.push({ |
| 384 | name, |
| 385 | root_path: toText(entry['root_path']), |
| 386 | nodes: toOptionalNumber(entry['nodes']), |
| 387 | edges: toOptionalNumber(entry['edges']), |
| 388 | }); |
| 389 | } |
| 390 | const result: ListProjectsResult = { projects }; |
| 391 | for (const key of ['total', 'returned', 'offset', 'limit'] as const) { |
| 392 | const value = raw[key]; |
| 393 | if (value !== undefined) { |
| 394 | if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) throw new Error(`Invalid project pagination: ${key}.`); |
| 395 | result[key] = value; |
| 396 | } |
| 397 | } |
| 398 | if (raw['has_more'] !== undefined) { |
| 399 | if (typeof raw['has_more'] !== 'boolean') throw new Error('Invalid project pagination: has_more.'); |
| 400 | result.hasMore = raw['has_more']; |
| 401 | } |
| 402 | if (raw['next_offset'] !== undefined && raw['next_offset'] !== null) { |
| 403 | if (typeof raw['next_offset'] !== 'number' || !Number.isSafeInteger(raw['next_offset']) || raw['next_offset'] < 0) throw new Error('Invalid project pagination: next_offset.'); |
| 404 | result.nextOffset = raw['next_offset']; |
| 405 | } |
| 406 | return result; |
| 407 | } |
| 408 | |
| 409 | export function readIndexStatus(value: unknown): IndexStatusResult { |
| 410 | const raw = record(value); |
no test coverage detected