UNPKG

hacker-news-reel

Version:

A lightweight, typed client for the Hacker News API with validation using Zod

121 lines (120 loc) 4.7 kB
import { z } from 'zod'; /** * @file Defines schemas for Hacker News API responses using Zod. * * This file contains TypeScript definitions and Zod schemas for validating * Hacker News API responses. The schemas include definitions for Hacker News * item IDs, item types, items, users, and updates. * * Schemas: * - `HackerNewsIdSchema`: Schema for a Hacker News item ID. * - `HackerNewsIdListSchema`: Schema for a list of Hacker News item IDs. * - `HackerNewsItemTypeSchema`: Schema for the type of a Hacker News item. * - `HackerNewsItemSchema`: Schema for a Hacker News item. * - `HackerNewsUserSchema`: Schema for a Hacker News user. * - `HackerNewsUpdatesSchema`: Schema for Hacker News updates. */ export declare const HackerNewsIdSchema: z.ZodNumber; export declare const HackerNewsUsernameSchema: z.ZodString; export declare const HackerNewsIdListSchema: z.ZodArray<z.ZodNumber, "many">; export declare const HackerNewsItemTypeSchema: z.ZodEnum<["job", "story", "comment", "poll", "pollopt"]>; export declare const HackerNewsItemSchema: z.ZodObject<{ /** The item's unique id. */ id: z.ZodNumber; /** True if the item is deleted. */ deleted: z.ZodOptional<z.ZodBoolean>; /** The type of item. */ type: z.ZodOptional<z.ZodEnum<["job", "story", "comment", "poll", "pollopt"]>>; /** The username of the item's author. */ by: z.ZodOptional<z.ZodString>; /** Creation date of the item, in Unix time. */ time: z.ZodOptional<z.ZodNumber>; /** The comment, story or poll text (HTML). */ text: z.ZodOptional<z.ZodString>; /** True if the item is dead. */ dead: z.ZodOptional<z.ZodBoolean>; /** The comment's parent id: either another comment or the related story. */ parent: z.ZodOptional<z.ZodNumber>; /** For pollopts, the associated poll id. */ poll: z.ZodOptional<z.ZodNumber>; /** The ids of the item's comments, in ranked display order. */ kids: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>; /** The URL of the story. */ url: z.ZodOptional<z.ZodString>; /** The story's score, or the votes for a pollopt. */ score: z.ZodOptional<z.ZodNumber>; /** The title of the story, poll or job (HTML). */ title: z.ZodOptional<z.ZodString>; /** A list of related pollopts, in display order. */ parts: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>; /** In the case of stories or polls, the total comment count. */ descendants: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { id: number; poll?: number | undefined; type?: "job" | "story" | "comment" | "poll" | "pollopt" | undefined; deleted?: boolean | undefined; by?: string | undefined; time?: number | undefined; text?: string | undefined; dead?: boolean | undefined; parent?: number | undefined; kids?: number[] | undefined; url?: string | undefined; score?: number | undefined; title?: string | undefined; parts?: number[] | undefined; descendants?: number | undefined; }, { id: number; poll?: number | undefined; type?: "job" | "story" | "comment" | "poll" | "pollopt" | undefined; deleted?: boolean | undefined; by?: string | undefined; time?: number | undefined; text?: string | undefined; dead?: boolean | undefined; parent?: number | undefined; kids?: number[] | undefined; url?: string | undefined; score?: number | undefined; title?: string | undefined; parts?: number[] | undefined; descendants?: number | undefined; }>; export declare const HackerNewsUserSchema: z.ZodObject<{ /** The user's unique username. Case-sensitive. */ id: z.ZodString; /** Creation date of the user, in Unix Time. */ created: z.ZodNumber; /** The user's karma. */ karma: z.ZodNumber; /** The user's optional self-description (HTML). */ about: z.ZodOptional<z.ZodString>; /** List of the user's stories, polls, and comments. */ submitted: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>; }, "strip", z.ZodTypeAny, { id: string; created: number; karma: number; about?: string | undefined; submitted?: number[] | undefined; }, { id: string; created: number; karma: number; about?: string | undefined; submitted?: number[] | undefined; }>; export declare const HackerNewsUpdatesSchema: z.ZodObject<{ /** List of recent changes to the item. */ items: z.ZodArray<z.ZodNumber, "many">; /** A list of user names that have changed recently. */ profiles: z.ZodArray<z.ZodString, "many">; }, "strip", z.ZodTypeAny, { items: number[]; profiles: string[]; }, { items: number[]; profiles: string[]; }>;