forked from nabil-mansouri/nativescript-couchbaselite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.ts
156 lines (153 loc) · 3.63 KB
/
commons.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
import { ImageSource } from "image-source"
export enum Log {
VERBOSE,
DEBUG,
INFO,
WARN,
ERROR
}
export enum Storage {
SQLLite,
ForestDB
}
export interface DatabaseOptions {
name: string;
create: boolean;
encryptionKey?: string;
}
export interface DatabaseListenerParam {
documentId: string;
revisionId: string;
isConflict: boolean;
isCurrentRevision: boolean;
isDeletion: boolean;
source: string;
}
export interface DatabaseListener {
onChange(p: DatabaseListenerParam[]);
}
export interface QueryListener {
onRows(rows: QueryResult);
}
export interface DocumentOpts {
ttl?: Date;
}
export interface Revision<T> {
revid: string;
object: T;
id: string;
}
export enum AttachmentImage {
PNG, JPG
}
export interface Attachment {
getName();
getType(): string;
getStream(): any;
}
export interface Document {
docId?: string;
docRev?: string;
docType?: string;
docDeleted?: boolean;
}
export interface Emitter {
emit(key: any | Array<any>, value: any);
}
export interface ViewOpts {
name: string;
revision: string;
map: (doc: Document, emitter: Emitter) => void;
reduce?: (keys: any[], values: any[], rereduce: boolean) => any;
}
export interface FilterOpts {
name: string;
filter: (doc: Revision<Document>, params: Map<string, any>) => boolean;
}
export enum IndexUpdateMode {
BEFORE, AFTER, NEVER
}
export enum ReplicationError {
Authentication = 401
}
export enum ReplicationStatus {
Stopped,
Offline,
Idle,
Active
}
export interface LiveQuery {
waitForRows(): void;
updateIndex(): void;
start(): void;
stop(): void;
run(): QueryResult;
}
export interface QueryResult {
getDocumentsId(): string[];
getDocuments(): Document[];
getValues(): any[];
firstDocument(): Document;
firstValue(): any;
firstId(): string;
hasDocuments(): boolean;
hasValues(): boolean;
hasIds(): boolean;
rerun(): void;
}
export interface ReplicationListenerParams {
status: ReplicationStatus;
lastError: string;
lastErrorCode: number | ReplicationError;
completedChangesCount: number;
changesCount: number;
}
export interface ReplicationListener {
onChange(p: ReplicationListenerParams);
}
export interface Query {
startKey?: any;
endKey?: any;
descending?: boolean;
inclusiveStart?: boolean;
inclusiveEnd?: boolean;
limit?: number;
skip?: number;
keys?: string[];
startKeyDocID?: string;
endKeyDocID?: string;
indexUpdateMode?: IndexUpdateMode;
prefixMatchLevel?: number;
mapOnly: boolean;
groupLevel?: number;
onlyConflict?: boolean
}
export class JSTypeChecker {
static isUndefined(jsO: any): boolean {
return typeof jsO === "undefined" || jsO == null || (JSTypeChecker.isNumber(jsO) && isNaN(jsO));
}
static isDate(jsO: any): boolean {
return jsO instanceof Date;
}
static isString(jsO: any): boolean {
return typeof jsO == "string" || jsO instanceof String;
}
static isBoolean(jsO: any): boolean {
return typeof jsO == "boolean" || jsO instanceof Boolean;
}
static isNumber(jsO: any): boolean {
return typeof jsO == "number" || jsO instanceof Number;
}
static isInt(jsO: any): boolean {
return JSTypeChecker.isNumber(jsO) && jsO % 1 === 0;
}
static isFloat(jsO: any): boolean {
return JSTypeChecker.isNumber(jsO) && !JSTypeChecker.isInt(jsO);
}
static isMap(jsO: any): boolean {
return jsO instanceof Map;
}
static isArray(jsO: any): boolean {
return jsO instanceof Array;
}
}