This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
207 lines (180 loc) · 9.06 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
export type SimpleIDBKey = string | number | Date | ArrayBuffer | SimpleIDBKeyArray;
export type SimpleIDBInputKey = string | number | Date | ArrayBuffer | ArrayBufferView | SimpleIDBInputKeyArray;
export type SimpleIDBQuery = IDBKeyRange | null;
export type SimpleIDBCursorDirection = "next" | "nextunique" | "prev" | "prevunique";
export type SimpleIDBResult = SimpleIDBResultKey & SimpleIDBResultValue;
export interface SimpleIDBKeyArray extends Array<SimpleIDBKey> {}
export interface SimpleIDBInputKeyArray extends Array<SimpleIDBInputKey> {}
export interface SimpleIDBResultKey {
key: SimpleIDBKey,
primaryKey: SimpleIDBKey,
}
export interface SimpleIDBResultValue {
value: any,
}
export interface SimpleIDBQueryOptions {
indexName?: string,
query?: SimpleIDBQuery,
count?: number,
direction?: SimpleIDBCursorDirection,
}
export declare class SimpleIDB {
/**
* @param name データベースの名前
*/
static deleteDatabase(name: string): Promise<void>;
/**
* データベースの名前
*/
readonly name: string;
/**
* データベースのバージョン
*/
readonly version: number;
/**
* @param name データベースの名前
* @param version データベースのバージョン. ObjectStore や Index の変更時に増やしていく
* @param onupgradeneeded ObjectStore や Index の初期化, 変更を行う函数
*/
constructor(name: string, version: number, onupgradeneeded: (this: SimpleIDB, db: IDBDatabase, transaction: IDBTransaction, oldVersion: number, newVersion: number) => any);
/**
* IndexedDB を開き, 成功したら自身を返す
*/
ready(): Promise<this>;
/**
* ObjectStore に値を追加する. 追加されたプライマリキーを返す
* @param storeName ObjectStore の名前
* @param value 追加する値
* @param primaryKey 追加する値のプライマリキー. ObjectStore に keyPath を付けている場合は省略しなければならず, autoIncrement の場合は省略可能
*/
add(storeName: string, value: any, primaryKey?: SimpleIDBInputKey | null): Promise<SimpleIDBKey>;
/**
* ObjectStore の値を追加もしくは更新する. 追加もしくは更新されたプライマリキーを返す
* @param storeName ObjectStore の名前
* @param value 追加もしくは更新する値
* @param primaryKey 追加もしくは更新する値のプライマリキー. ObjectStore に keyPath を付けている場合は省略しなければならない
*/
put(storeName: string, value: any, primaryKey: SimpleIDBInputKey | null): Promise<SimpleIDBKey>;
/**
* ObjectStore の値を取得する
* @param storeName ObjectStore の名前
* @param primaryKey 取得する値のプライマリキー
*/
get(storeName: string, primaryKey: SimpleIDBInputKey): Promise<any>;
/**
* ObjectStore の値を更新する. 存在しない場合更新を行う函数は呼ばれない
* @param storeName ObjectStore の名前
* @param primaryKey 更新する値のプライマリキー
* @param mapFn 更新を行う函数
*/
update(storeName: string, primaryKey: SimpleIDBInputKey, mapFn: (this: this, value: any) => any): Promise<void>;
/**
* ObjectStore の値を削除する
* @param storeName ObjectStore の名前
* @param primaryKey 削除する値のプライマリキー
*/
delete(storeName: string, primaryKey: SimpleIDBInputKey): Promise<void>;
/**
* ObjectStore の値を取得し, 同時に削除する
* @param storeName ObjectStore の名前
* @param primaryKey 取得, 削除する値のプライマリキー
*/
take(storeName: string, primaryKey: SimpleIDBInputKey): Promise<any>;
/**
* ObjectStore に値を複数追加する. 追加されたプライマリキーを返す
* @param storeName ObjectStore の名前
* @param keyAndValues 追加するプライマリキーと値のペア. プライマリキーは ObjectStore に keyPath を付けている場合は省略しなければならず, ObjectStore が autoIncrement の場合は省略可能
*/
addAll(storeName: string, values: {value: any, primaryKey?: SimpleIDBInputKey | null}[]): Promise<SimpleIDBKey[]>;
/**
* ObjectStore に値を複数追加もしくは更新する. 追加もしくは更新されたキーを返す
* @param storeName ObjectStore の名前
* @param keyAndValues 追加するプライマリキーと値のペア. プライマリキーは ObjectStore に keyPath を付けている場合は省略しなければならない
*/
putAll(storeName: string, keyAndValues: {value: any, primaryKey: SimpleIDBInputKey | null}[]): Promise<SimpleIDBKey[]>;
/**
* ObjectStore の値を複数取得する
* @param storeName ObjectStore の名前
* @param options 取得する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 取得する際のクエリ
* @param options.count 取得する値の個数の上限値
* @param options.direction 昇順, 降順
*/
getAll(storeName: string, options?: SimpleIDBQueryOptions): Promise<SimpleIDBResult[]>;
/**
* ObjectStore のキーのみを複数取得する. 値を取らない分効率的
* @param storeName ObjectStore の名前
* @param options 取得する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 取得する際のクエリ
* @param options.count 取得する値の個数の上限値
* @param options.direction 昇順, 降順
*/
getAllKeys(storeName: string, options?: SimpleIDBQueryOptions): Promise<SimpleIDBResultKey[]>;
/**
* ObjectStore の値のみを複数取得する. キーを取らない分効率的
* @param storeName ObjectStore の名前
* @param options 取得する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 取得する際のクエリ
* @param options.count 取得する値の個数の上限値
* @param options.direction 昇順, 降順
*/
getAllValues(storeName: string, options?: SimpleIDBQueryOptions): Promise<SimpleIDBResultValue[]>;
/**
* ObjectStore の値を複数更新する
* @param storeName ObjectStore の名前
* @param mapFn 更新を行う函数
* @param options 削除する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 更新する際のクエリ
* @param options.count 更新する値の個数の上限値
* @param options.direction 昇順, 降順
*/
updateAll(storeName: string, mapFn: (this: this, value: any, key: SimpleIDBKey, primaryKey: SimpleIDBKey) => any, options: SimpleIDBQueryOptions): Promise<void>;
/**
* ObjectStore の値を複数削除する
* @param storeName ObjectStore の名前
* @param options 削除する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 削除する際のクエリ
* @param options.count 削除する値の個数の上限値
* @param options.direction 昇順, 降順
*/
deleteAll(storeName: string, options: SimpleIDBQueryOptions): Promise<void>;
/**
* ObjectStore の値を複数取得し, 同時に削除する
* @param storeName ObjectStore の名前
* @param options 取得, 削除する際のオプション
* @param options.indexName ObjectStore の Index の名前
* @param options.query 取得, 削除する際のクエリ
* @param options.count 取得, 削除する値の個数の上限値
* @param options.direction 昇順, 降順
*/
takeAll(storeName: string, options?: SimpleIDBQueryOptions): Promise<SimpleIDBResult[]>;
/**
* ObjectStore の値の個数を数える
* @param storeName ObjectStore の名前
* @param indexName ObjectStore の Index の名前. null の場合は直接 ObjectStore から取得する
* @param query 取得する際のクエリ
*/
count(storeName: string, options?: {indexName?: string, query?: SimpleIDBQuery}): number;
/**
* ObjectStore の値を全件削除する
* @param storeName ObjectStore の名前
*/
clear(storeName: string): Promise<void>;
/**
* ObjectStore を直接入手する. 複雑なクエリを使う必要がある時に用いる
* @param storeNames ObjectStore の名前の配列
* @param mode IDBTransaction のモード
* @param oncomplete IDBTransaction が完了したときに呼ばれる callback
* @param onerror IDBTransaction が失敗したときに呼ばれる callback
*/
getObjectStores(storeName: string[], mode?: "readonly" | "readwrite", oncomplete?: ((this: SimpleIDB) => any) | null, onerror?: ((this: SimpleIDB, error: DOMException) => any) | null): IDBObjectStore[];
/**
* データベースとのコネクションを閉じる
*/
close(): void;
}