forked from chromedp/chromedp
/
indexeddb.go
228 lines (197 loc) · 7.67 KB
/
indexeddb.go
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Package indexeddb provides the Chrome Debugging Protocol
// commands, types, and events for the IndexedDB domain.
//
// Generated by the chromedp-gen command.
package indexeddb
// Code generated by chromedp-gen. DO NOT EDIT.
import (
"context"
cdp "github.com/rjeczalik/chromedp/cdp"
)
// EnableParams enables events from backend.
type EnableParams struct{}
// Enable enables events from backend.
func Enable() *EnableParams {
return &EnableParams{}
}
// Do executes IndexedDB.enable against the provided context and
// target handler.
func (p *EnableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandIndexedDBEnable, nil, nil)
}
// DisableParams disables events from backend.
type DisableParams struct{}
// Disable disables events from backend.
func Disable() *DisableParams {
return &DisableParams{}
}
// Do executes IndexedDB.disable against the provided context and
// target handler.
func (p *DisableParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandIndexedDBDisable, nil, nil)
}
// RequestDatabaseNamesParams requests database names for given security
// origin.
type RequestDatabaseNamesParams struct {
SecurityOrigin string `json:"securityOrigin"` // Security origin.
}
// RequestDatabaseNames requests database names for given security origin.
//
// parameters:
// securityOrigin - Security origin.
func RequestDatabaseNames(securityOrigin string) *RequestDatabaseNamesParams {
return &RequestDatabaseNamesParams{
SecurityOrigin: securityOrigin,
}
}
// RequestDatabaseNamesReturns return values.
type RequestDatabaseNamesReturns struct {
DatabaseNames []string `json:"databaseNames,omitempty"` // Database names for origin.
}
// Do executes IndexedDB.requestDatabaseNames against the provided context and
// target handler.
//
// returns:
// databaseNames - Database names for origin.
func (p *RequestDatabaseNamesParams) Do(ctxt context.Context, h cdp.Handler) (databaseNames []string, err error) {
// execute
var res RequestDatabaseNamesReturns
err = h.Execute(ctxt, cdp.CommandIndexedDBRequestDatabaseNames, p, &res)
if err != nil {
return nil, err
}
return res.DatabaseNames, nil
}
// RequestDatabaseParams requests database with given name in given frame.
type RequestDatabaseParams struct {
SecurityOrigin string `json:"securityOrigin"` // Security origin.
DatabaseName string `json:"databaseName"` // Database name.
}
// RequestDatabase requests database with given name in given frame.
//
// parameters:
// securityOrigin - Security origin.
// databaseName - Database name.
func RequestDatabase(securityOrigin string, databaseName string) *RequestDatabaseParams {
return &RequestDatabaseParams{
SecurityOrigin: securityOrigin,
DatabaseName: databaseName,
}
}
// RequestDatabaseReturns return values.
type RequestDatabaseReturns struct {
DatabaseWithObjectStores *DatabaseWithObjectStores `json:"databaseWithObjectStores,omitempty"` // Database with an array of object stores.
}
// Do executes IndexedDB.requestDatabase against the provided context and
// target handler.
//
// returns:
// databaseWithObjectStores - Database with an array of object stores.
func (p *RequestDatabaseParams) Do(ctxt context.Context, h cdp.Handler) (databaseWithObjectStores *DatabaseWithObjectStores, err error) {
// execute
var res RequestDatabaseReturns
err = h.Execute(ctxt, cdp.CommandIndexedDBRequestDatabase, p, &res)
if err != nil {
return nil, err
}
return res.DatabaseWithObjectStores, nil
}
// RequestDataParams requests data from object store or index.
type RequestDataParams struct {
SecurityOrigin string `json:"securityOrigin"` // Security origin.
DatabaseName string `json:"databaseName"` // Database name.
ObjectStoreName string `json:"objectStoreName"` // Object store name.
IndexName string `json:"indexName"` // Index name, empty string for object store data requests.
SkipCount int64 `json:"skipCount"` // Number of records to skip.
PageSize int64 `json:"pageSize"` // Number of records to fetch.
KeyRange *KeyRange `json:"keyRange,omitempty"` // Key range.
}
// RequestData requests data from object store or index.
//
// parameters:
// securityOrigin - Security origin.
// databaseName - Database name.
// objectStoreName - Object store name.
// indexName - Index name, empty string for object store data requests.
// skipCount - Number of records to skip.
// pageSize - Number of records to fetch.
func RequestData(securityOrigin string, databaseName string, objectStoreName string, indexName string, skipCount int64, pageSize int64) *RequestDataParams {
return &RequestDataParams{
SecurityOrigin: securityOrigin,
DatabaseName: databaseName,
ObjectStoreName: objectStoreName,
IndexName: indexName,
SkipCount: skipCount,
PageSize: pageSize,
}
}
// WithKeyRange key range.
func (p RequestDataParams) WithKeyRange(keyRange *KeyRange) *RequestDataParams {
p.KeyRange = keyRange
return &p
}
// RequestDataReturns return values.
type RequestDataReturns struct {
ObjectStoreDataEntries []*DataEntry `json:"objectStoreDataEntries,omitempty"` // Array of object store data entries.
HasMore bool `json:"hasMore,omitempty"` // If true, there are more entries to fetch in the given range.
}
// Do executes IndexedDB.requestData against the provided context and
// target handler.
//
// returns:
// objectStoreDataEntries - Array of object store data entries.
// hasMore - If true, there are more entries to fetch in the given range.
func (p *RequestDataParams) Do(ctxt context.Context, h cdp.Handler) (objectStoreDataEntries []*DataEntry, hasMore bool, err error) {
// execute
var res RequestDataReturns
err = h.Execute(ctxt, cdp.CommandIndexedDBRequestData, p, &res)
if err != nil {
return nil, false, err
}
return res.ObjectStoreDataEntries, res.HasMore, nil
}
// ClearObjectStoreParams clears all entries from an object store.
type ClearObjectStoreParams struct {
SecurityOrigin string `json:"securityOrigin"` // Security origin.
DatabaseName string `json:"databaseName"` // Database name.
ObjectStoreName string `json:"objectStoreName"` // Object store name.
}
// ClearObjectStore clears all entries from an object store.
//
// parameters:
// securityOrigin - Security origin.
// databaseName - Database name.
// objectStoreName - Object store name.
func ClearObjectStore(securityOrigin string, databaseName string, objectStoreName string) *ClearObjectStoreParams {
return &ClearObjectStoreParams{
SecurityOrigin: securityOrigin,
DatabaseName: databaseName,
ObjectStoreName: objectStoreName,
}
}
// Do executes IndexedDB.clearObjectStore against the provided context and
// target handler.
func (p *ClearObjectStoreParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandIndexedDBClearObjectStore, p, nil)
}
// DeleteDatabaseParams deletes a database.
type DeleteDatabaseParams struct {
SecurityOrigin string `json:"securityOrigin"` // Security origin.
DatabaseName string `json:"databaseName"` // Database name.
}
// DeleteDatabase deletes a database.
//
// parameters:
// securityOrigin - Security origin.
// databaseName - Database name.
func DeleteDatabase(securityOrigin string, databaseName string) *DeleteDatabaseParams {
return &DeleteDatabaseParams{
SecurityOrigin: securityOrigin,
DatabaseName: databaseName,
}
}
// Do executes IndexedDB.deleteDatabase against the provided context and
// target handler.
func (p *DeleteDatabaseParams) Do(ctxt context.Context, h cdp.Handler) (err error) {
return h.Execute(ctxt, cdp.CommandIndexedDBDeleteDatabase, p, nil)
}