-
Notifications
You must be signed in to change notification settings - Fork 0
/
grapher.d.ts
158 lines (134 loc) · 4.23 KB
/
grapher.d.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
declare module 'meteor/cultofcoders:grapher' {
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
module Grapher {
type TypesEnum = 'one' | 'many';
type onReadyCallback = () => void;
type onStopCallback = (err: Meteor.Error | undefined) => void;
interface subscriptionCallbacks {
onReady: onReadyCallback
onStop: onStopCallback
}
interface Query<T> {
clone: (params?: object) => Query<T>
subscribe: (cb: onReadyCallback | subscriptionCallbacks) => Meteor.SubscriptionHandle
subscribeCount: () => Meteor.SubscriptionHandle
unsubscribeCount: () => void
setParams: () => any
resolve: () => any
expose: (exposure: Exposure) => void
fetch: (callback?: (error: Meteor.Error, data: T[]) => void) => T[]
fetchOne: (callback?: (error: Meteor.Error, data: T) => void) => T
fetchSync: () => Promise<T[]>
fetchOneSync: () => Promise<T>
getCount: (callback?: (error: Meteor.Error, count: number) => void) => number
getCountSync: () => Promise<number>
} // WIP
interface ILink<TSchema> {
collection: Mongo.Collection<TSchema>
inversedBy?: string
denormalize?: iDenormalize
}
interface ILink<TSchema> {
collection: Mongo.Collection<TSchema>
type?: TypesEnum
metadata?: true
field?: string
foreignIdentityField?: string
index?: boolean
denormalize?: iDenormalize
}
interface Link<TSchema = {}> {
[field: string]: ILink<TSchema>
}
interface QueryOptions<T = any> {
$filter?: Mongo.FieldExpression<T>
}
type RecursiveBody<T> = { [K in keyof T]: T[K] extends object ? RecursiveBody<T[K]> : BodyEnum };
type Body<T> = {
[field: string]: DependencyGraph | QueryOptions<T>
} & Partial<RecursiveBody<T>>;
type createQuery<T = {}> = (
name: string,
body: Body<T> | {},
options?: {}
) => any;
type QueryBody<T = {}> = Body<T>;
type BodyEnum = 0 | 1;
type GrapherBody<TSchema = {}> = TSchema extends object
? SelectionSet<GraphQLQuery<TSchema>>
: SelectionSet<BodyEnum>;
interface TEmbodyArgs<TArgs, TSchema = {}> {
body: GrapherBody<TSchema>
getArgs: () => TArgs
}
interface DependencyGraph {
[field: string]: GrapherBody | DependencyGraph
}
type TFirewall<TFilters, TOptions> = (
filters: TFilters,
options: TOptions,
userId: string
) => void;
interface SelectionSet<BodyType> {
[field: string]: BodyType
}
interface iDenormalize {
field: string
body: {
[field: string]: number
}
}
interface GraphQLQuery<TSchema extends object = {}, TQueryArguments = {}> {
embody?: (transform: TEmbodyArgs<TQueryArguments>) => void
$filter?: Mongo.Selector<TSchema>
$options?: Mongo.Options<TSchema>
// Integer
maxDepth?: number
// Integer
maxLimit?: number
deny?: string[]
intersect?: GrapherBody<TSchema>
}
interface Exposure<TBody = {}, TFilters = {}, TOptions = {}> {
firewall?: TFirewall<TFilters, TOptions> | Array<TFirewall<TFilters, TOptions>>
publication?: boolean // Boolean
method?: boolean // Boolean
blocking?: boolean // Boolean
maxLimit?: number // Number
maxDepth?: number // Number
restrictedFields?: string[] // [String]
restrictLinks?: string[] | ((...args: any[]) => any) // [String] or Function,
}
interface ASTToQueryOptions {
maxLimit: number
maxDepth: number
}
}
export function createQuery <T> (
body: Grapher.Body<T> | {},
options?: {}
): Grapher.Query<T>;
export function createQuery <T> (
name: string,
body: Grapher.Body<T> | {},
options?: {}
): Grapher.Query<T>;
export function setAstToQueryDefaults (
options: Grapher.ASTToQueryOptions
): void;
export const db: Readonly<{
[key: string]: Mongo.CollectionStatic
}>;
export class MemoryResultCacher {
constructor ({ ttl }: { ttl: number })
public fetch<TResult = {}>(
cacheId: string,
options: {
query: any
countCursor: any
}
): TResult
public storeData<T = {}>(cacheId: string, data: T): void
}
}