Rebasely Beta: data may be purged

justintsus-experiment Public

Text · 62 lines · 3.1 KiB · at 8e57616

// The search query language of the Issues and Pull requests lists: the parsed query (an AST) and its// errors. parse.tsus reads a query into this shape, serialize.tsus writes its canonical form and// sql.tsus turns it into a WHERE clause and an ORDER BY list. api.ts is the plain .ts face of it.//// A query is a list of terms, all ANDed, in input order with duplicates removed. Every value in a term// is already normalized (lowercased, trimmed, dates checked), so the serializer and the evaluator// never fail for a query the parser accepted.import type { Option } from "@tsus/runtime";export type Target = "issues" | "pulls";export type QueryErrorCode =  | "too_long" | "too_many_terms" | "unterminated_quote" | "unexpected_quote"  | "unknown_qualifier" | "unsupported_qualifier" | "empty_value" | "negation_not_allowed"  | "bad_value" | "bad_date" | "conflict";// start/end: UTF-16 offsets into the input, end exclusive.export type QueryError = { readonly code: QueryErrorCode; readonly message: string; readonly start: number; readonly end: number };// What parseQuery returns for a query with errors: every error, in input order.export type ParseFailure = { readonly tag: "Invalid"; readonly errors: readonly QueryError[] };// A person a term names: the viewer (@me), a user id, or an agent of the repository's organization.export type UserRef =  | { readonly tag: "Me" }  | { readonly tag: "User"; readonly id: string }  | { readonly tag: "Agent"; readonly slug: string };export type StateValue = "open" | "closed" | "merged" | "draft";export type ListState = "open" | "closed" | "merged";export type SortValue = "created-desc" | "created-asc" | "updated-desc" | "updated-asc" | "comments-desc" | "comments-asc";export type DateOp = "<" | "<=" | ">" | ">=";export type Unit = "h" | "d" | "w";// A UTC calendar day: its text as written (YYYY-MM-DD) and its first millisecond.export type Day = { readonly text: string; readonly start: number };export type DateFilter =  | { readonly tag: "On"; readonly day: Day }  | { readonly tag: "Compare"; readonly op: DateOp; readonly day: Day }  | { readonly tag: "Between"; readonly from: Option<Day>; readonly to: Option<Day> }  | { readonly tag: "Age"; readonly op: DateOp; readonly count: number; readonly unit: Unit };export type DateField = "created" | "updated";export type Term =  | { readonly tag: "Is"; readonly negated: boolean; readonly state: StateValue }  | { readonly tag: "Label"; readonly negated: boolean; readonly label: string }  | { readonly tag: "NoLabel" }  | { readonly tag: "Author"; readonly negated: boolean; readonly user: UserRef }  | { readonly tag: "ReviewRequested"; readonly negated: boolean; readonly user: UserRef }  | { readonly tag: "Sort"; readonly sort: SortValue }  | { readonly tag: "Date"; readonly field: DateField; readonly filter: DateFilter }  | { readonly tag: "Number"; readonly number: number }  | { readonly tag: "Text"; readonly negated: boolean; readonly text: string };export type SearchQuery = { readonly target: Target; readonly terms: readonly Term[] };export const LIMITS = { length: 1024, terms: 32 } as const;