Rebasely Beta: data may be purged

justintsus-experiment Public

TypeScript · 57 lines · 2.5 KiB · at 8e57616

// The search query language's types (search/api.ts is the module's door): what a query parses to,// what an invalid one reports, and what toSql binds. Plain data, so a parsed query can be passed back// to serializeQuery and toSql, compared, and edited by the pages (search/edit.ts).export type Target = "issues" | "pulls";export type SqlValue = string | number | null;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 code unit offsets into the input, end exclusive.export type QueryError = { code: QueryErrorCode; message: string; start: number; end: number };export type StateValue = "open" | "closed" | "merged" | "draft";export type SortValue = "created-desc" | "created-asc" | "updated-desc" | "updated-asc" | "comments-desc" | "comments-asc";// A person named in a query: the viewer, a user id, or an agent of the repository's organization.export type UserRef = { kind: "me" } | { kind: "id"; id: string } | { kind: "slug"; slug: string };// A calendar day: as written (YYYY-MM-DD) and its start in epoch ms (00:00:00.000Z).export type Day = { text: string; start: number };export type DateOp = "<" | "<=" | ">" | ">=";export type RelUnit = "h" | "d" | "w";export type DateFilter =  | { kind: "day"; day: Day }  | { kind: "cmp"; op: DateOp; day: Day }  | { kind: "range"; from: Day | null; to: Day | null }  | { kind: "age"; op: DateOp; n: number; unit: RelUnit };export type Term =  | { kind: "is"; neg: boolean; value: StateValue }  | { kind: "label"; neg: boolean; value: string }  | { kind: "no"; value: "label" }  | { kind: "author"; neg: boolean; user: UserRef }  | { kind: "review-requested"; neg: boolean; user: UserRef }  | { kind: "sort"; value: SortValue }  | { kind: "date"; field: "created" | "updated"; filter: DateFilter }  | { kind: "number"; value: number }  | { kind: "text"; neg: boolean; value: string };// A parsed, valid query: its target and its terms in input order, duplicates (same canonical text)// removed. At most one sort term.export type SearchQuery = { readonly target: Target; readonly terms: readonly Term[] };export type ParseResult = { ok: true; query: SearchQuery } | { ok: false; errors: QueryError[] };export type SqlCtx = {  repoId: string;  orgId: string;  viewerId: string | null;  now: number;};export type SqlResult = { where: string; params: SqlValue[]; orderBy: string };