import {z} from 'zod' export type CorpusType = 'USC' | 'CFR' | 'STATE' | 'CONSTITUTION' | 'FEDERAL_RULES' | 'FEDERAL_LOCAL_RULES' | 'STATE_CONSTITUTION' | 'STATE_RULES' | 'EXECUTIVE_ACTION' | 'REGULATION' | 'FEDERAL_REGISTER' | 'FEDERAL_REGISTER_NOTICE' | 'AGENCY_GUIDANCE' | 'SENTENCING_GUIDELINES' | 'US_TAX_TREATY' | 'US_TREATY' | 'STATE_AGENCY_GUIDANCE' | 'STATE_AG_OPINION' | 'STATE_REGISTER' | 'SESSION_LAW' | 'STATUTE_COMPILATION' | 'AGENCY_ADJUDICATION' | 'CFR_ANNUAL' | 'USC_ANNUAL' | 'FEDERAL_BILL' | 'FEDERAL_RULES_ANNUAL' | 'FEDERAL_RULES_PROPOSED'; export type StatuteCountRequest = {query?: (string | null) | undefined, matchType?: ('boolean' | null) | undefined, corpusType?: (CorpusType | Array | null) | undefined, state?: ('federal' | 'al' | 'ak' | 'as' | 'az' | 'ar' | 'ca' | 'co' | 'ct' | 'de' | 'dc' | 'fl' | 'ga' | 'gu' | 'hi' | 'id' | 'il' | 'in' | 'ia' | 'ks' | 'ky' | 'la' | 'me' | 'md' | 'ma' | 'mi' | 'mn' | 'ms' | 'mo' | 'mt' | 'ne' | 'nv' | 'nh' | 'nj' | 'nm' | 'ny' | 'nc' | 'nd' | 'mp' | 'oh' | 'ok' | 'or' | 'pa' | 'pr' | 'ri' | 'sc' | 'sd' | 'tn' | 'tx' | 'ut' | 'vt' | 'vi' | 'va' | 'wa' | 'wv' | 'wi' | 'wy' | Array<'federal' | 'al' | 'ak' | 'as' | 'az' | 'ar' | 'ca' | 'co' | 'ct' | 'de' | 'dc' | 'fl' | 'ga' | 'gu' | 'hi' | 'id' | 'il' | 'in' | 'ia' | 'ks' | 'ky' | 'la' | 'me' | 'md' | 'ma' | 'mi' | 'mn' | 'ms' | 'mo' | 'mt' | 'ne' | 'nv' | 'nh' | 'nj' | 'nm' | 'ny' | 'nc' | 'nd' | 'mp' | 'oh' | 'ok' | 'or' | 'pa' | 'pr' | 'ri' | 'sc' | 'sd' | 'tn' | 'tx' | 'ut' | 'vt' | 'vi' | 'va' | 'wa' | 'wv' | 'wi' | 'wy'> | null) | undefined, code?: (string | Array | null) | undefined, article?: (string | Array | null) | undefined, titleNumber?: (number | null) | undefined, chapter?: (string | Array | null) | undefined, part?: (string | Array | null) | undefined, actStatus?: ('abolished' | 'deleted' | 'expired' | 'in_force' | 'inactive' | 'non_precedential' | 'not_funded' | 'not_yet_effective' | 'omitted' | 'proposed' | 'recodified' | 'recompiled' | 'rejected' | 'relocated' | 'removed' | 'renumbered' | 'repealed' | 'rescinded' | 'reserved' | 'revoked' | 'superseded' | 'terminated' | 'transferred' | 'unconstitutional' | 'vacant' | 'vacated' | 'vetoed' | 'withdrawn' | Array<'abolished' | 'deleted' | 'expired' | 'in_force' | 'inactive' | 'non_precedential' | 'not_funded' | 'not_yet_effective' | 'omitted' | 'proposed' | 'recodified' | 'recompiled' | 'rejected' | 'relocated' | 'removed' | 'renumbered' | 'repealed' | 'rescinded' | 'reserved' | 'revoked' | 'superseded' | 'terminated' | 'transferred' | 'unconstitutional' | 'vacant' | 'vacated' | 'vetoed' | 'withdrawn'> | null) | undefined, excludeRepealed?: boolean | undefined}; export type CreateApiApiV1UsStatutesCountArgs = {'Idempotency-Key'?: (string | null) | undefined, body: StatuteCountRequest}; export type CreateApiApiV1UsStatutesCountOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const statuteCountResponse = z.object({count: z.number().int().optional(), isExact: z.boolean().optional(), parsedQuery: z.string().nullable().optional(), scope: z.record(z.string(), z.unknown()).optional(), processingTimeMs: z.number().optional(), creditsConsumed: z.number().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Count the sections in a scope * * POST /api/v1/us/statutes/count * * Also accepts auth: ApiKeyHeader */ export const createApiApiV1UsStatutesCount = async (args: CreateApiApiV1UsStatutesCountArgs, options?: CreateApiApiV1UsStatutesCountOptions) => { const {baseUrl = "https://api.vaquill.ai", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/us/statutes/count${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(statuteCountResponse, await res.json()) };