# All files / src/clients/ep vocabularyClient.ts

91.66% Statements 11/12
91.66% Branches 11/12
75% Functions 3/4
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87

    344x

    7x
    7x

    7x

    6x
    7x
    7x

    4x
    2x

    2x

    2x

     /**
     * @fileoverview Vocabulary sub-client for European Parliament API
     *
     * Handles EP controlled-vocabularies endpoints (list and single-item lookup).
     *
     * @module clients/ep/vocabularyClient
     */

    import type { PaginatedResponse } from '../../types/europeanParliament.js';
    import {
      BaseEPClient,
      APIError,
      type EPClientConfig,
      type EPSharedResources,
      type JSONLDResponse,
    } from './baseClient.js';

    /**
     * Sub-client for EP controlled-vocabularies endpoints.
     *
     * @extends BaseEPClient
     * @public
     */
    export class VocabularyClient extends BaseEPClient {
      constructor(config: EPClientConfig = {}, shared?: EPSharedResources) {
        super(config, shared);
      }

      /**
       * Returns EP controlled vocabularies.
       * **EP API Endpoint:** `GET /controlled-vocabularies`
       *
       * @param params - limit, offset
       * @returns Raw API response with vocabulary items
       */
      async getControlledVocabularies(params: {
        limit?: number;
        offset?: number;
      } = {}): Promise<PaginatedResponse<Record<string, unknown>>> {
        const limit = params.limit ?? 50;
        const offset = params.offset ?? 0;

        const response = await this.get<JSONLDResponse>('controlled-vocabularies', {
          format: 'application/ld+json',
          offset,
          limit,
        });

        const items = Array.isArray(response.data) ? response.data : [];
        const hasMore = items.length === limit;
        return { data: items, total: items.length + offset + (hasMore ? 1 : 0), limit, offset, hasMore };
      }

      /**
       * Retrieves recently updated controlled vocabularies via the feed endpoint.
       * **EP API Endpoint:** `GET /controlled-vocabularies/feed`
       *
       * Fixed-window feed — no `timeframe` parameter per OpenAPI spec.
       * Returns HTTP 204 No Content when no updates exist (handled by baseClient).
       */
      async getControlledVocabulariesFeed(): Promise<JSONLDResponse> {
        return this.get<JSONLDResponse>('controlled-vocabularies/feed', {
          format: 'application/ld+json',
        });
      }

      /**
       * Returns a single EP Controlled Vocabulary by ID.
       * **EP API Endpoint:** `GET /controlled-vocabularies/{voc-id}`
       *
       * @param vocId - Vocabulary identifier
       * @returns Single vocabulary entry
       */
      async getControlledVocabularyById(
        vocId: string
      ): Promise<Record<string, unknown>> {
        if (vocId.trim() === '') {
          throw new APIError('Vocabulary ID is required', 400);
        }
        const response = await this.get<Record<string, unknown>>(
          `controlled-vocabularies/${vocId}`,
          { format: 'application/ld+json' }
        );
        return response;
      }
    }