| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package indexeddb |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import ( |
| 10 |
"context" |
| 11 |
|
| 12 |
"github.com/chromedp/cdproto/cdp" |
| 13 |
"github.com/chromedp/cdproto/storage" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
type ClearObjectStoreParams struct { |
| 18 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 19 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 20 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 21 |
DatabaseName string `json:"databaseName"` |
| 22 |
ObjectStoreName string `json:"objectStoreName"` |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
func ClearObjectStore(databaseName string, objectStoreName string) *ClearObjectStoreParams { |
| 34 |
return &ClearObjectStoreParams{ |
| 35 |
DatabaseName: databaseName, |
| 36 |
ObjectStoreName: objectStoreName, |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
func (p ClearObjectStoreParams) WithSecurityOrigin(securityOrigin string) *ClearObjectStoreParams { |
| 43 |
p.SecurityOrigin = securityOrigin |
| 44 |
return &p |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
func (p ClearObjectStoreParams) WithStorageKey(storageKey string) *ClearObjectStoreParams { |
| 49 |
p.StorageKey = storageKey |
| 50 |
return &p |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
func (p ClearObjectStoreParams) WithStorageBucket(storageBucket *storage.Bucket) *ClearObjectStoreParams { |
| 56 |
p.StorageBucket = storageBucket |
| 57 |
return &p |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
func (p *ClearObjectStoreParams) Do(ctx context.Context) (err error) { |
| 62 |
return cdp.Execute(ctx, CommandClearObjectStore, p, nil) |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
type DeleteDatabaseParams struct { |
| 67 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 68 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 69 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 70 |
DatabaseName string `json:"databaseName"` |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
func DeleteDatabase(databaseName string) *DeleteDatabaseParams { |
| 81 |
return &DeleteDatabaseParams{ |
| 82 |
DatabaseName: databaseName, |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
func (p DeleteDatabaseParams) WithSecurityOrigin(securityOrigin string) *DeleteDatabaseParams { |
| 89 |
p.SecurityOrigin = securityOrigin |
| 90 |
return &p |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
func (p DeleteDatabaseParams) WithStorageKey(storageKey string) *DeleteDatabaseParams { |
| 95 |
p.StorageKey = storageKey |
| 96 |
return &p |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
func (p DeleteDatabaseParams) WithStorageBucket(storageBucket *storage.Bucket) *DeleteDatabaseParams { |
| 102 |
p.StorageBucket = storageBucket |
| 103 |
return &p |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
func (p *DeleteDatabaseParams) Do(ctx context.Context) (err error) { |
| 108 |
return cdp.Execute(ctx, CommandDeleteDatabase, p, nil) |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
type DeleteObjectStoreEntriesParams struct { |
| 114 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 115 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 116 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 117 |
DatabaseName string `json:"databaseName"` |
| 118 |
ObjectStoreName string `json:"objectStoreName"` |
| 119 |
KeyRange *KeyRange `json:"keyRange"` |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
func DeleteObjectStoreEntries(databaseName string, objectStoreName string, keyRange *KeyRange) *DeleteObjectStoreEntriesParams { |
| 132 |
return &DeleteObjectStoreEntriesParams{ |
| 133 |
DatabaseName: databaseName, |
| 134 |
ObjectStoreName: objectStoreName, |
| 135 |
KeyRange: keyRange, |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
func (p DeleteObjectStoreEntriesParams) WithSecurityOrigin(securityOrigin string) *DeleteObjectStoreEntriesParams { |
| 142 |
p.SecurityOrigin = securityOrigin |
| 143 |
return &p |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
func (p DeleteObjectStoreEntriesParams) WithStorageKey(storageKey string) *DeleteObjectStoreEntriesParams { |
| 148 |
p.StorageKey = storageKey |
| 149 |
return &p |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
func (p DeleteObjectStoreEntriesParams) WithStorageBucket(storageBucket *storage.Bucket) *DeleteObjectStoreEntriesParams { |
| 155 |
p.StorageBucket = storageBucket |
| 156 |
return &p |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
func (p *DeleteObjectStoreEntriesParams) Do(ctx context.Context) (err error) { |
| 161 |
return cdp.Execute(ctx, CommandDeleteObjectStoreEntries, p, nil) |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
type DisableParams struct{} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
func Disable() *DisableParams { |
| 171 |
return &DisableParams{} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
func (p *DisableParams) Do(ctx context.Context) (err error) { |
| 176 |
return cdp.Execute(ctx, CommandDisable, nil, nil) |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
type EnableParams struct{} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
func Enable() *EnableParams { |
| 186 |
return &EnableParams{} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
func (p *EnableParams) Do(ctx context.Context) (err error) { |
| 191 |
return cdp.Execute(ctx, CommandEnable, nil, nil) |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
type RequestDataParams struct { |
| 196 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 197 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 198 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 199 |
DatabaseName string `json:"databaseName"` |
| 200 |
ObjectStoreName string `json:"objectStoreName"` |
| 201 |
IndexName string `json:"indexName"` |
| 202 |
SkipCount int64 `json:"skipCount"` |
| 203 |
PageSize int64 `json:"pageSize"` |
| 204 |
KeyRange *KeyRange `json:"keyRange,omitempty,omitzero"` |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
func RequestData(databaseName string, objectStoreName string, indexName string, skipCount int64, pageSize int64) *RequestDataParams { |
| 219 |
return &RequestDataParams{ |
| 220 |
DatabaseName: databaseName, |
| 221 |
ObjectStoreName: objectStoreName, |
| 222 |
IndexName: indexName, |
| 223 |
SkipCount: skipCount, |
| 224 |
PageSize: pageSize, |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
func (p RequestDataParams) WithSecurityOrigin(securityOrigin string) *RequestDataParams { |
| 231 |
p.SecurityOrigin = securityOrigin |
| 232 |
return &p |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
func (p RequestDataParams) WithStorageKey(storageKey string) *RequestDataParams { |
| 237 |
p.StorageKey = storageKey |
| 238 |
return &p |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
func (p RequestDataParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDataParams { |
| 244 |
p.StorageBucket = storageBucket |
| 245 |
return &p |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
func (p RequestDataParams) WithKeyRange(keyRange *KeyRange) *RequestDataParams { |
| 250 |
p.KeyRange = keyRange |
| 251 |
return &p |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
type RequestDataReturns struct { |
| 256 |
ObjectStoreDataEntries []*DataEntry `json:"objectStoreDataEntries,omitempty,omitzero"` |
| 257 |
HasMore bool `json:"hasMore"` |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
func (p *RequestDataParams) Do(ctx context.Context) (objectStoreDataEntries []*DataEntry, hasMore bool, err error) { |
| 267 |
|
| 268 |
var res RequestDataReturns |
| 269 |
err = cdp.Execute(ctx, CommandRequestData, p, &res) |
| 270 |
if err != nil { |
| 271 |
return nil, false, err |
| 272 |
} |
| 273 |
|
| 274 |
return res.ObjectStoreDataEntries, res.HasMore, nil |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
type GetMetadataParams struct { |
| 279 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 280 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 281 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 282 |
DatabaseName string `json:"databaseName"` |
| 283 |
ObjectStoreName string `json:"objectStoreName"` |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
func GetMetadata(databaseName string, objectStoreName string) *GetMetadataParams { |
| 295 |
return &GetMetadataParams{ |
| 296 |
DatabaseName: databaseName, |
| 297 |
ObjectStoreName: objectStoreName, |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
func (p GetMetadataParams) WithSecurityOrigin(securityOrigin string) *GetMetadataParams { |
| 304 |
p.SecurityOrigin = securityOrigin |
| 305 |
return &p |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
func (p GetMetadataParams) WithStorageKey(storageKey string) *GetMetadataParams { |
| 310 |
p.StorageKey = storageKey |
| 311 |
return &p |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
func (p GetMetadataParams) WithStorageBucket(storageBucket *storage.Bucket) *GetMetadataParams { |
| 317 |
p.StorageBucket = storageBucket |
| 318 |
return &p |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
type GetMetadataReturns struct { |
| 323 |
EntriesCount float64 `json:"entriesCount,omitempty,omitzero"` |
| 324 |
KeyGeneratorValue float64 `json:"keyGeneratorValue,omitempty,omitzero"` |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
func (p *GetMetadataParams) Do(ctx context.Context) (entriesCount float64, keyGeneratorValue float64, err error) { |
| 334 |
|
| 335 |
var res GetMetadataReturns |
| 336 |
err = cdp.Execute(ctx, CommandGetMetadata, p, &res) |
| 337 |
if err != nil { |
| 338 |
return 0, 0, err |
| 339 |
} |
| 340 |
|
| 341 |
return res.EntriesCount, res.KeyGeneratorValue, nil |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
type RequestDatabaseParams struct { |
| 346 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 347 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 348 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 349 |
DatabaseName string `json:"databaseName"` |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
func RequestDatabase(databaseName string) *RequestDatabaseParams { |
| 360 |
return &RequestDatabaseParams{ |
| 361 |
DatabaseName: databaseName, |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
func (p RequestDatabaseParams) WithSecurityOrigin(securityOrigin string) *RequestDatabaseParams { |
| 368 |
p.SecurityOrigin = securityOrigin |
| 369 |
return &p |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
func (p RequestDatabaseParams) WithStorageKey(storageKey string) *RequestDatabaseParams { |
| 374 |
p.StorageKey = storageKey |
| 375 |
return &p |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
func (p RequestDatabaseParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDatabaseParams { |
| 381 |
p.StorageBucket = storageBucket |
| 382 |
return &p |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
type RequestDatabaseReturns struct { |
| 387 |
DatabaseWithObjectStores *DatabaseWithObjectStores `json:"databaseWithObjectStores,omitempty,omitzero"` |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
func (p *RequestDatabaseParams) Do(ctx context.Context) (databaseWithObjectStores *DatabaseWithObjectStores, err error) { |
| 396 |
|
| 397 |
var res RequestDatabaseReturns |
| 398 |
err = cdp.Execute(ctx, CommandRequestDatabase, p, &res) |
| 399 |
if err != nil { |
| 400 |
return nil, err |
| 401 |
} |
| 402 |
|
| 403 |
return res.DatabaseWithObjectStores, nil |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
type RequestDatabaseNamesParams struct { |
| 409 |
SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` |
| 410 |
StorageKey string `json:"storageKey,omitempty,omitzero"` |
| 411 |
StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
func RequestDatabaseNames() *RequestDatabaseNamesParams { |
| 420 |
return &RequestDatabaseNamesParams{} |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
func (p RequestDatabaseNamesParams) WithSecurityOrigin(securityOrigin string) *RequestDatabaseNamesParams { |
| 426 |
p.SecurityOrigin = securityOrigin |
| 427 |
return &p |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
func (p RequestDatabaseNamesParams) WithStorageKey(storageKey string) *RequestDatabaseNamesParams { |
| 432 |
p.StorageKey = storageKey |
| 433 |
return &p |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
func (p RequestDatabaseNamesParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestDatabaseNamesParams { |
| 439 |
p.StorageBucket = storageBucket |
| 440 |
return &p |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
type RequestDatabaseNamesReturns struct { |
| 445 |
DatabaseNames []string `json:"databaseNames,omitempty,omitzero"` |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
func (p *RequestDatabaseNamesParams) Do(ctx context.Context) (databaseNames []string, err error) { |
| 454 |
|
| 455 |
var res RequestDatabaseNamesReturns |
| 456 |
err = cdp.Execute(ctx, CommandRequestDatabaseNames, p, &res) |
| 457 |
if err != nil { |
| 458 |
return nil, err |
| 459 |
} |
| 460 |
|
| 461 |
return res.DatabaseNames, nil |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
const ( |
| 466 |
CommandClearObjectStore = "IndexedDB.clearObjectStore" |
| 467 |
CommandDeleteDatabase = "IndexedDB.deleteDatabase" |
| 468 |
CommandDeleteObjectStoreEntries = "IndexedDB.deleteObjectStoreEntries" |
| 469 |
CommandDisable = "IndexedDB.disable" |
| 470 |
CommandEnable = "IndexedDB.enable" |
| 471 |
CommandRequestData = "IndexedDB.requestData" |
| 472 |
CommandGetMetadata = "IndexedDB.getMetadata" |
| 473 |
CommandRequestDatabase = "IndexedDB.requestDatabase" |
| 474 |
CommandRequestDatabaseNames = "IndexedDB.requestDatabaseNames" |
| 475 |
) |