Newer
Older
declare module 'cozy-client'
type QueryDefinition = {
doctype: string
id: string
ids: Array
selector: object
fields: Array
indexedFields: Array
sort: Array
includes: string
referenced: string
limit: null | number
skip: null | number
cursor: unknown
}
type AppMetaData = {
slug: string
version: string
}
type Offline = {
getDatabase: unknown
}
export type Client = {
find(doctype: string): typeof QueryDefinition
query(doctype: string): typeof QueryDefinition
destroy(document: Document): typeof QueryDefinition
save(document: Document): typeof QueryDefinition
collection(doctype: string): function
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
}
export type QueryId = string
export type QueryDefinitionBuilder = (client: Client) => QueryDefinition
export type QueryOptions = {
doc?: unknown
query?: QueryDefinition | QueryDefinitionBuilder
as?: QueryId
}
export type QueryOptionsBuilder<P> = (props: P) => QueryOptions
export type QuerySpecs<P> = {
[k in string]: QueryOptions | QueryOptionsBuilder<P>
}
export function queryConnect<C extends React.ElementType>(
querySpecs: QuerySpecs<React.ComponentPropsWithoutRef<C>>
): (wrappedElement: C) => void
export function withClient<C extends React.ElementType>(
component: React.ComponentPropsWithoutRef<C>
): (wrappedElement: C) => void
export type QueryState<D> = {
id: unknown
definition: unknown
fetchStatus: 'pending' | 'loading' | 'loaded' | 'failed'
lastFetch: null | number
lastUpdate: null | number
lastError: null | number
hasMore: boolean
count: number
data: D[]
}
export function fromEnv(env: NodeJS.ProcessEnv, schema: object): () => Client