-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
query-types.ts
74 lines (58 loc) · 2.2 KB
/
query-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
AuthorAddress,
FormatName,
Path,
Timestamp,
} from "../util/doc-types.ts";
//================================================================================
/** Filters a query by document attributes. */
export interface QueryFilter {
/** Match an exact path. */
path?: Path;
pathStartsWith?: string;
pathEndsWith?: string;
/** Match documents with a given author. */
author?: AuthorAddress;
timestamp?: Timestamp;
/** Match documents newer than the given timestamp. */
timestampGt?: Timestamp;
/** Match documents older than the given timestamp. */
timestampLt?: Timestamp;
}
/** Represents fetching all historical versions of a document by authors, or just the latest versions. */
export type HistoryMode = "latest" | "all";
/** Describes a query for fetching documents from a replica. */
export interface Query<FormatsType extends FormatName[]> {
// for each property, the first option is the default if it's omitted
// this is in the order that processing happens:
// first, limit to latest docs or all doc.
/** Whether to fetch all historical versions of a document or just the latest versions. */
historyMode?: HistoryMode;
// then iterate in this order
// "path ASC" is actually "path ASC then break ties with timestamp DESC"
// "path DESC" is the reverse of that
/** The order to return docs in. Defaults to `path ASC`. */
orderBy?: "path ASC" | "path DESC" | "localIndex ASC" | "localIndex DESC";
// start iterating immediately after this item (e.g. get items which are > startAfter)
/** Only fetch documents which come after a certain point. */
startAfter?: {
/** Only documents after this localIndex. Only works when ordering by localIndex. */
localIndex?: number;
/** Only documents after this path. Only works when ordering by path. */
path?: string;
};
// then apply filters, if any
filter?: QueryFilter;
// stop iterating after this number of docs
/** The maximum number of documents to return. */
limit?: number;
formats?: FormatsType;
}
export const DEFAULT_QUERY: Query<["es.5"]> = {
historyMode: "latest",
orderBy: "path ASC",
startAfter: undefined,
limit: undefined,
filter: undefined,
formats: ["es.5"],
};