forked from couchbaselabs/node-ottoman
/
index.d.ts
108 lines (85 loc) · 2.71 KB
/
index.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
/// <reference types="couchbase" />
import { Bucket, CouchbaseError } from "couchbase";
declare namespace OttomanJS {
class StoreAdapter {
constructor (bucket: Bucket)
store (key: string, data: object, cas: object, callback: any): any
}
class CbStoreAdapter {
constructor (bucket: Bucket)
store (key: string, data: object, cas: object, callback: any): any
}
interface TypeDef {
}
interface OttomanOptions {
bucket?: Bucket
store?: StoreAdapter
namespace?: string
}
interface ModelReference {
ref: string
}
type ValidatorFunction = (value: any) => void
interface SchemaField {
type: 'string' | 'number' | 'integer' | 'boolean' | 'Date' | 'Mixed' | ModelReference,
auto: 'uuid',
readonly: boolean,
validator: ValidatorFunction,
default: boolean | Date | string | number | null
}
interface SchemaDefinition {
[key: string]: Partial<SchemaField>
}
interface Schema {
validate<T> (modelInstance: ModelInstance<T>, callback: ValidationCallback<T>): void
}
interface ModelOptions {
index?: IndexDefinition
query?: QueryDefinition
}
interface Query {
of: string
by: string
}
interface QueryDefinition {
[key: string]: Query
}
interface Index {
type: 'refdoc' | 'view' | 'n1ql',
by: string
}
interface IndexDefinition {
[key: string]: Partial<Index>
}
interface GetByIdOptions {
}
interface CreateOptions {
}
type CreateCallback<T> = (error: CouchbaseError | null, document: ModelInstance<T> | undefined) => void
type GetByIdCallback<T> = (error: CouchbaseError | null, model: ModelInstance<T> | undefined) => void
type SaveCallback<T> = (error: CouchbaseError | null, response: ModelInstance<T> | undefined) => void
type ValidationCallback<T> = (error: CouchbaseError | null) => void
type EnsureIndicesCallback = (error: CouchbaseError | null) => void
class ModelInstance<T> {
fromData<T> (data: any): T
getById<T> (id: string, callback: GetByIdCallback<T>): void
create<T> (data: any, callback: CreateCallback<T>): void
save (callback: SaveCallback<T>): void
}
interface ModelInstanceCtor {
schema: Schema
}
class Ottoman {
bucket: Bucket
readonly namespace: string
readonly store: StoreAdapter
readonly models: { [key: string]: ModelInstance<any> }
readonly types: { [key: string]: TypeDef | undefined }
readonly delayedBind: { [key: string]: Function | undefined }
readonly plugins: Array<[Function, object]>
constructor (options: OttomanOptions)
model (key: string, schema: SchemaDefinition, options: ModelOptions): ModelInstanceCtor
ensureIndices (DeferBuild: boolean, callback: Function): void
}
}
export = OttomanJS