# All files / src/schemas/ep feed.ts

100% Statements 19/19
100% Branches 5/5
100% Functions 1/1
100% Lines 19/19

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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149

    58x

    58x

    102x
    2x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

    58x

     /**
     * Feed-endpoint Zod validation schemas.
     *
     * EP API v2 `/…/feed` endpoints fall into two groups:
     *
     * **Group A — Fixed-window feeds** (no timeframe parameter per OpenAPI spec):
     *   `documents/feed`, `plenary-documents/feed`, `committee-documents/feed`,
     *   `plenary-session-documents/feed`, `parliamentary-questions/feed`,
     *   `corporate-bodies/feed`, `controlled-vocabularies/feed`
     *   These return updates from a server-defined default window (typically one month).
     *
     * **Group B — Configurable-window feeds** (accept `timeframe` + `start-date`):
     *   `meps/feed`, `events/feed`, `procedures/feed`, `adopted-texts/feed`,
     *   `meps-declarations/feed`, `external-documents/feed`
     *   Some also accept a domain-specific type filter (`workType`, `activityType`,
     *   `processType`).
     *
     * @see https://data.europarl.europa.eu/api/v2/ (OpenAPI spec)
     * @module schemas/ep/feed
     */

    import { z } from 'zod';
    import { DateStringSchema } from './common.js';

    /**
     * Feed timeframe values accepted by configurable-window feed endpoints.
     */
    export const FeedTimeframeSchema = z
      .enum(['today', 'one-day', 'one-week', 'one-month', 'custom'])
      .default('one-week')
      .describe('Timeframe for the feed (default: one-week)');

    /**
     * Base feed parameters for configurable-window feed endpoints (Group B).
     */
    const BaseFeedParamsSchema = z
      .object({
        timeframe: FeedTimeframeSchema,
        startDate: DateStringSchema.optional()
          .describe('Start date (YYYY-MM-DD) — required when timeframe is "custom"'),
      })
      .superRefine((data, ctx) => {
        if (data.timeframe === 'custom' && (data.startDate === undefined || data.startDate === '')) {
          ctx.addIssue({
            code: 'custom',
            path: ['startDate'],
            message: 'startDate is required when timeframe is "custom"',
          });
        }
      });

    /**
     * Schema for fixed-window feed endpoints (Group A).
     *
     * These EP API endpoints do NOT accept a `timeframe` or `start-date`
     * parameter.  They always return updates from a server-defined default
     * window (typically one month).
     *
     * For API-contract uniformity across all feed tools, this schema still
     * accepts the common feed parameters (`timeframe`, `startDate`, `limit`,
     * `offset`) as **informational-only** — they are silently ignored at the
     * upstream call site.  This allows consumers that model all feeds with a
     * single shape (e.g. `FeedBaseOptions extends { timeframe, startDate,
     * limit, offset }`) to call these tools without hard-failing at runtime.
     *
     * Unknown extra keys are also tolerated (no `.strict()`) so additional
     * future feed primitives are forward-compatible.
     *
     * @see Option 1 in issue #379 (uniform feed input schema).
     */
    const FixedWindowFeedSchema = z
      .object({
        timeframe: FeedTimeframeSchema.optional().describe(
          'Informational-only — this feed uses a server-defined default window (typically one month) and ignores this parameter. Accepted for contract uniformity with sliding-window feed tools.'
        ),
        startDate: DateStringSchema.optional().describe(
          'Informational-only — ignored by this fixed-window feed. Accepted for contract uniformity with sliding-window feed tools.'
        ),
        limit: z.number().int().min(1).max(100).optional().describe(
          'Informational-only — the upstream EP API does not paginate this fixed-window feed. Accepted for contract uniformity.'
        ),
        offset: z.number().int().min(0).optional().describe(
          'Informational-only — the upstream EP API does not paginate this fixed-window feed. Accepted for contract uniformity.'
        ),
      })
      .describe(
        'Fixed-window feed — the EP API always returns updates from a server-defined default window (typically one month). All parameters are informational-only and silently ignored.'
      );

    /** GET /documents/feed — server-default window */
    export const GetDocumentsFeedSchema = FixedWindowFeedSchema;

    /** GET /plenary-documents/feed — server-default window */
    export const GetPlenaryDocumentsFeedSchema = FixedWindowFeedSchema;

    /** GET /committee-documents/feed — server-default window */
    export const GetCommitteeDocumentsFeedSchema = FixedWindowFeedSchema;

    /** GET /plenary-session-documents/feed — server-default window */
    export const GetPlenarySessionDocumentsFeedSchema = FixedWindowFeedSchema;

    /** GET /parliamentary-questions/feed — server-default window */
    export const GetParliamentaryQuestionsFeedSchema = FixedWindowFeedSchema;

    /** GET /corporate-bodies/feed — server-default window */
    export const GetCorporateBodiesFeedSchema = FixedWindowFeedSchema;

    /** GET /controlled-vocabularies/feed — server-default window */
    export const GetControlledVocabulariesFeedSchema = FixedWindowFeedSchema;

    /** GET /meps/feed */
    export const GetMEPsFeedSchema = BaseFeedParamsSchema;

    /** GET /events/feed */
    export const GetEventsFeedSchema = BaseFeedParamsSchema.extend({
      activityType: z.string().max(200).optional()
        .describe('Activity type filter'),
    });

    /** GET /procedures/feed */
    export const GetProceduresFeedSchema = BaseFeedParamsSchema.extend({
      processType: z.string().max(200).optional()
        .describe('Process type filter'),
    });

    /** GET /adopted-texts/feed */
    export const GetAdoptedTextsFeedSchema = BaseFeedParamsSchema.extend({
      workType: z.string().max(200).optional()
        .describe('Work type filter'),
    });

    /** GET /meps-declarations/feed */
    export const GetMEPDeclarationsFeedSchema = BaseFeedParamsSchema.extend({
      workType: z.string().max(200).optional()
        .describe('Work type filter'),
    });

    /** GET /external-documents/feed */
    export const GetExternalDocumentsFeedSchema = BaseFeedParamsSchema.extend({
      workType: z.string().max(200).optional()
        .describe('Work type filter'),
    });

    /** GET /procedures/{process-id}/events/{event-id} */
    export const GetProcedureEventByIdSchema = z.object({
      processId: z.string().min(1).max(200).describe('Procedure process ID'),
      eventId: z.string().min(1).max(200).describe('Event identifier'),
    });