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

100% Statements 9/9
100% Branches 2/2
100% Functions 1/1
100% Lines 9/9

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
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202

    58x

    58x

    35x

    58x

    58x

    58x

    58x

    58x

    58x

     /**
     * Legislative document Zod validation schemas.
     *
     * @module schemas/ep/document
     */

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

    /**
     * Document type enum
     * @internal - Used internally within SearchDocumentsSchema and other schemas
     */
    const DocumentTypeSchema = z.enum([
      'REPORT',
      'RESOLUTION',
      'DECISION',
      'DIRECTIVE',
      'REGULATION',
      'OPINION',
      'AMENDMENT'
    ]);

    /**
     * Search documents input schema
     */
    export const SearchDocumentsSchema = z.object({
      docId: z.string()
        .trim()
        .min(1)
        .max(200)
        .optional()
        .describe('Document ID for single document lookup (bypasses keyword search)'),
      keyword: z.string()
        .trim()
        .min(2, 'Keyword must be at least 2 characters')
        .max(200)
        .regex(/^[a-zA-Z0-9\s\-_]+$/, 'Invalid characters in keyword')
        .optional()
        .describe('Search keyword or phrase'),
      documentType: DocumentTypeSchema
        .optional()
        .describe('Filter by document type'),
      dateFrom: DateStringSchema.optional(),
      dateTo: DateStringSchema.optional(),
      committee: z.string()
        .min(1)
        .max(100)
        .optional()
        .describe('Committee identifier'),
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(20)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    }).refine(
      data => data.docId !== undefined || data.keyword !== undefined,
      { message: 'Either docId or keyword must be provided' }
    ).refine(
      refineDateRange,
      { message: DATE_RANGE_ERROR }
    );

    /**
     * Legislative document output schema
     */
    export const LegislativeDocumentSchema = z.object({
      id: z.string(),
      type: DocumentTypeSchema,
      title: z.string(),
      date: z.string(),
      authors: z.array(z.string()),
      committee: z.string().optional(),
      status: z.enum(['DRAFT', 'SUBMITTED', 'IN_COMMITTEE', 'PLENARY', 'ADOPTED', 'REJECTED']),
      pdfUrl: z.url({ message: 'Invalid PDF URL format' }).optional(),
      xmlUrl: z.url({ message: 'Invalid XML URL format' }).optional(),
      summary: z.string().optional()
    });

    /**
     * Get plenary documents input schema
     */
    export const GetPlenaryDocumentsSchema = z.object({
      docId: z.string()
        .min(1)
        .max(200)
        .optional()
        .describe('Document ID for single document lookup'),
      year: z.number()
        .int()
        .min(1990)
        .max(2040)
        .optional()
        .describe('Filter by year'),
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(50)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    });

    /**
     * Get committee documents input schema.
     *
     * **EP API /committee-documents filtering:** The EP API does not support
     * a `year` parameter for this endpoint.  Only pagination is available.
     */
    export const GetCommitteeDocumentsSchema = z.object({
      docId: z.string()
        .min(1)
        .max(200)
        .optional()
        .describe('Document ID for single document lookup'),
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(50)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    });

    /**
     * Get plenary session documents input schema
     */
    export const GetPlenarySessionDocumentsSchema = z.object({
      docId: z.string()
        .min(1)
        .max(200)
        .optional()
        .describe('Document ID for single document lookup'),
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(50)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    });

    /**
     * Get plenary session document items input schema
     */
    export const GetPlenarySessionDocumentItemsSchema = z.object({
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(50)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    });

    /**
     * Get external documents input schema.
     *
     * **EP API /external-documents filtering:** The EP API does not support
     * a `year` parameter for this endpoint.  Only pagination is available.
     */
    export const GetExternalDocumentsSchema = z.object({
      docId: z.string()
        .min(1)
        .max(200)
        .optional()
        .describe('Document ID for single document lookup'),
      limit: z.number()
        .int()
        .min(1)
        .max(100)
        .default(50)
        .describe('Maximum results to return'),
      offset: z.number()
        .int()
        .min(0)
        .default(0)
        .describe('Pagination offset')
    });