@tricoteuses/assemblee
Version:
Retrieve, clean up & handle French Assemblée nationale's open data
113 lines (112 loc) • 4.81 kB
TypeScript
import { z } from 'zod';
/**
* Metadata for UIDs (unique identifiers)
*/
export interface UidMetadata {
/** Type of entity (acteur, organe, etc.) */
targetType: "acteur" | "organe" | "document" | "scrutin" | "auto";
}
/**
* Metadata for acteur/organe references
*/
export interface RefMetadata {
/** Type of reference */
refType: "acteur" | "organe";
}
/**
* Registry for UIDs (PA*, PO*, etc.)
*/
export declare const uidRegistry: z.core.$ZodRegistry<UidMetadata, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
/**
* Registry for acteur references
*/
export declare const acteurRefRegistry: z.core.$ZodRegistry<RefMetadata, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
/**
* Registry for organe references
*/
export declare const organeRefRegistry: z.core.$ZodRegistry<RefMetadata, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
/**
* Registry for ISO 8601 dates
* Uses empty object as marker (presence in registry = true)
*/
export declare const dateRegistry: z.core.$ZodRegistry<{}, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
/**
* Registry for custom summarizers (future UI integration)
*/
export declare const summarizerRegistry: z.core.$ZodRegistry<Record<string, never>, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
/**
* Helper for creating a UID schema
*
* Validates Assemblée Nationale UID format (e.g., PA123456, PO123456)
*
* Use `.meta({ description: "..." })` on the returned schema to add documentation.
*
* @example
* ```typescript
* const acteurId = uid() // Validates PA* or PO* format
* const withDesc = uid().meta({ description: "Identifiant acteur" })
* ```
*/
export declare function uid(): z.ZodString;
/**
* Helper for creating an acteur reference schema
*
* Use `.meta({ description: "..." })` on the returned schema to add documentation.
*/
export declare function acteurRef(): z.ZodString;
/**
* Helper for creating an organe reference schema
*
* Use `.meta({ description: "..." })` on the returned schema to add documentation.
*/
export declare function organeRef(): z.ZodString;
/**
* Date parsing for Assemblée Nationale's format quirks
* Handles: "2023-01-15", "2023-01-15+01:00", null, undefined
*
* Integrates with existing date-fns utilities:
* - parseISO() for "YYYY-MM-DD"
* - dateFromYearMonthDayTimezoneString() for "YYYY-MM-DD+TZ"
*/
export declare const dateIso8601Base: z.ZodPipe<z.ZodTransform<string | Date | undefined, unknown>, z.ZodOptional<z.ZodDate>>;
/**
* Optional date in ISO 8601 format
*
* Use `.meta({ description: "..." })` on the returned schema to add documentation.
*/
export declare const dateIso8601Optional: () => z.ZodPipe<z.ZodTransform<string | Date | undefined, unknown>, z.ZodOptional<z.ZodDate>>;
/**
* Required date in ISO 8601 format
*
* Use `.meta({ description: "..." })` on the returned schema to add documentation.
*/
export declare const dateIso8601Required: () => z.ZodPipe<z.ZodPipe<z.ZodTransform<string | Date | undefined, unknown>, z.ZodOptional<z.ZodDate>> & z.ZodType<Date, unknown, z.core.$ZodTypeInternals<Date, unknown>>, z.ZodTransform<Date, Date>>;
/**
* Trimmed string helper
*/
export declare const trimmedStringBase: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodString>>;
export declare const trimmedStringOptional: (description?: string) => z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodString>>;
export declare const trimmedStringRequired: (description?: string) => z.ZodPipe<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodOptional<z.ZodString>> & z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>, z.ZodTransform<string, string>>;
/**
* Ensure array helper
* Wraps single objects in arrays (handles XML→JSON single element quirk)
*
* XML: <item>foo</item> -> JSON: {item: "foo"} should become ["foo"]
* XML: <item>foo</item><item>bar</item> -> JSON: {item: ["foo", "bar"]}
*/
export declare function ensureArray<T extends z.ZodTypeAny>(itemSchema: T): z.ZodPipe<z.ZodTransform<unknown[], unknown>, z.ZodArray<T>>;
/**
* Nullable helper
* Handles XML nil attributes and optional fields
*
* Handles:
* - {@xsi:nil: "true"} -> undefined
* - null -> undefined
* - undefined -> undefined
* - value -> value
*/
export declare function nullable<T extends z.ZodTypeAny>(schema: T): z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodTransform<unknown, unknown>, T>>>;
/**
* Helper for creating enums from const arrays
*/
export declare function enumFromConst<T extends readonly [string, ...string[]]>(values: T): z.ZodEnum<{ [k_1 in T[number]]: k_1; } extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never>;