(value: unknown)
| 480 | } |
| 481 | |
| 482 | function decodeQueryResult(value: unknown): SkillCatalogQueryResult { |
| 483 | const record = requireRecord(value, 'skill catalog query result'); |
| 484 | if (record.kind === 'revision_changed') { |
| 485 | const changed = requireExactRecord(record, 'skill catalog revision changed result', [ |
| 486 | 'kind', |
| 487 | 'expectedRevision', |
| 488 | 'actualRevision', |
| 489 | 'resolvedWorkspace', |
| 490 | ]); |
| 491 | return { |
| 492 | ...revisionChanged({ |
| 493 | kind: changed.kind, |
| 494 | expectedRevision: changed.expectedRevision, |
| 495 | actualRevision: changed.actualRevision, |
| 496 | }), |
| 497 | resolvedWorkspace: decodeWorkspaceProjection(changed.resolvedWorkspace), |
| 498 | }; |
| 499 | } |
| 500 | const page = requireExactRecord(record, 'skill catalog page result', [ |
| 501 | 'kind', |
| 502 | 'view', |
| 503 | 'revision', |
| 504 | 'items', |
| 505 | 'nextCursor', |
| 506 | 'resolvedWorkspace', |
| 507 | ]); |
| 508 | if (page.kind !== 'page' || !Array.isArray(page.items)) { |
| 509 | throw invalidProtocolFrame('Invalid skill catalog page result'); |
| 510 | } |
| 511 | if (page.items.length > SKILL_CATALOG_PAGE_MAX_ITEMS) { |
| 512 | throw invalidProtocolFrame('Skill catalog page exceeds item limit'); |
| 513 | } |
| 514 | const view = catalogView(page.view); |
| 515 | const decoded: SkillCatalogQueryResult = { |
| 516 | kind: 'page', |
| 517 | view, |
| 518 | revision: sha256(page.revision, 'skill catalog revision'), |
| 519 | items: page.items.map((item) => pageItem(item, view)), |
| 520 | nextCursor: |
| 521 | page.nextCursor === null |
| 522 | ? null |
| 523 | : utf8String(page.nextCursor, 'skill catalog next cursor', CURSOR_MAX_BYTES), |
| 524 | resolvedWorkspace: decodeWorkspaceProjection(page.resolvedWorkspace), |
| 525 | }; |
| 526 | assertJsonByteLimit( |
| 527 | decoded, |
| 528 | SKILL_CATALOG_PAGE_MAX_BYTES + resolvedWorkspaceByteOverhead(decoded.resolvedWorkspace), |
| 529 | 'Skill catalog page', |
| 530 | ); |
| 531 | return decoded; |
| 532 | } |
| 533 | |
| 534 | function pageItem(value: unknown, view: SkillCatalogView): SkillCatalogPageItem { |
| 535 | if (view === 'governance') return governanceItem(value); |
nothing calls this directly
no test coverage detected