001package Torello.Browser.BrowserAPI; 002 003// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 004// Java-HTML Imports 005// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 006 007import Torello.Browser.*; 008import Torello.Browser.helper.*; 009import Torello.Browser.JavaScriptAPI.*; 010import Torello.JSON.*; 011 012import Torello.Java.ReadOnly.ReadOnlyList; 013import Torello.Java.ReadOnly.ReadOnlyArrayList; 014 015import Torello.JavaDoc.Annotations.StaticFunctional; 016import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg; 017 018import Torello.Browser.BrowserAPI.NestedHelpers.Commands.CacheStorage$$Commands; 019 020 021// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 022// JDK Imports 023// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 024 025import javax.json.JsonObject; 026import javax.json.JsonValue; 027 028/** 029 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN> 030 * <EMBED CLASS='external-html' DATA-FILE-ID=CDP.CODE_GEN_NOTE> 031 */ 032@StaticFunctional@JDHeaderBackgroundImg(EmbedTagFileID="CDP.WOOD_PLANK_NOTE") 033public class CacheStorage 034{ 035 // No Pubic Constructors 036 private CacheStorage() { } 037 038 039 // ******************************************************************************************** 040 // ******************************************************************************************** 041 // Eliminated Types 042 // ******************************************************************************************** 043 // ******************************************************************************************** 044 045 046 /** 047 * Unique identifier of the Cache object. 048 049 * <EMBED CLASS='external-html' DATA-CTAS='String' DATA-FILE-ID=CDP.EliminatedType 050 * DATA-NAME=CacheId> 051 */ 052 public static final String CacheId = 053 "CacheId has been eliminated.\n" + 054 "It was replaced with the standard Java-Type: String"; 055 056 057 // ******************************************************************************************** 058 // ******************************************************************************************** 059 // Enumerated String Constants Lists 060 // ******************************************************************************************** 061 // ******************************************************************************************** 062 063 064 /** 065 * type of HTTP response cached 066 * <BR /><BR /><B CLASS=StrEnumType>String-Enumeration Type</B> 067 */ 068 public static final ReadOnlyList<String> CachedResponseType = new ReadOnlyArrayList<> 069 (String.class, "basic", "cors", "default", "error", "opaqueRedirect", "opaqueResponse"); 070 071 072 073 // ******************************************************************************************** 074 // ******************************************************************************************** 075 // Basic Types 076 // ******************************************************************************************** 077 // ******************************************************************************************** 078 079 080 /** 081 * Cache identifier. 082 * 083 * <EMBED CLASS=globalDefs DATA-DOMAIN=CacheStorage DATA-API=BrowserAPI> 084 */ 085 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 086 public static class Cache 087 extends BaseType<Cache> 088 implements java.io.Serializable 089 { 090 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 091 protected static final long serialVersionUID = 1; 092 093 private static final NestedHelper<CacheStorage.Cache> singleton = 094 Torello.Browser.BrowserAPI.NestedHelpers.Types. 095 CacheStorage$$Cache$$.singleton; 096 097 /** An opaque unique id of the cache. */ 098 public final String cacheId; 099 100 /** Security origin of the cache. */ 101 public final String securityOrigin; 102 103 /** Storage key of the cache. */ 104 public final String storageKey; 105 106 /** 107 * Storage bucket of the cache. 108 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 109 */ 110 public final Storage.StorageBucket storageBucket; 111 112 /** The name of the cache. */ 113 public final String cacheName; 114 115 /** Constructor. Please review this class' fields for documentation. */ 116 public Cache( 117 ReadOnlyList<Boolean> isPresent, String cacheId, String securityOrigin, 118 String storageKey, Storage.StorageBucket storageBucket, String cacheName 119 ) 120 { 121 super(singleton, Domains.CacheStorage, "Cache", 5); 122 123 this.cacheId = cacheId; 124 this.securityOrigin = securityOrigin; 125 this.storageKey = storageKey; 126 this.storageBucket = storageBucket; 127 this.cacheName = cacheName; 128 129 this.isPresent = (isPresent == null) 130 ? singleton.generateIsPresentList(this) 131 : THROWS.check(isPresent, 5, "CacheStorage.Cache"); 132 } 133 134 /** Creates an instance of this class from a {@link JsonObject}.*/ 135 public static Cache fromJSON(JsonObject jo) 136 { return singleton.fromJSON(jo); } 137 138 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 139 public static NestedDescriptor<Cache> descriptor() 140 { return singleton.descriptor(); } 141 } 142 143 /** 144 * Cached response 145 * 146 * <EMBED CLASS=globalDefs DATA-DOMAIN=CacheStorage DATA-API=BrowserAPI> 147 */ 148 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 149 public static class CachedResponse 150 extends BaseType<CachedResponse> 151 implements java.io.Serializable 152 { 153 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 154 protected static final long serialVersionUID = 1; 155 156 private static final NestedHelper<CacheStorage.CachedResponse> singleton = 157 Torello.Browser.BrowserAPI.NestedHelpers.Types. 158 CacheStorage$$CachedResponse$$.singleton; 159 160 /** Entry content, base64-encoded. (Encoded as a base64 string when passed over JSON) */ 161 public final String body; 162 163 /** Constructor. Please review this class' fields for documentation. */ 164 public CachedResponse(ReadOnlyList<Boolean> isPresent, String body) 165 { 166 super(singleton, Domains.CacheStorage, "CachedResponse", 1); 167 168 this.body = body; 169 170 this.isPresent = (isPresent == null) 171 ? singleton.generateIsPresentList(this) 172 : THROWS.check(isPresent, 1, "CacheStorage.CachedResponse"); 173 } 174 175 /** Creates an instance of this class from a {@link JsonObject}.*/ 176 public static CachedResponse fromJSON(JsonObject jo) 177 { return singleton.fromJSON(jo); } 178 179 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 180 public static NestedDescriptor<CachedResponse> descriptor() 181 { return singleton.descriptor(); } 182 } 183 184 /** 185 * Data entry. 186 * 187 * <EMBED CLASS=globalDefs DATA-DOMAIN=CacheStorage DATA-API=BrowserAPI> 188 */ 189 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 190 public static class DataEntry 191 extends BaseType<DataEntry> 192 implements java.io.Serializable 193 { 194 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 195 protected static final long serialVersionUID = 1; 196 197 private static final NestedHelper<CacheStorage.DataEntry> singleton = 198 Torello.Browser.BrowserAPI.NestedHelpers.Types. 199 CacheStorage$$DataEntry$$.singleton; 200 201 /** Request URL. */ 202 public final String requestURL; 203 204 /** Request method. */ 205 public final String requestMethod; 206 207 /** Request headers */ 208 public final CacheStorage.Header[] requestHeaders; 209 210 /** Number of seconds since epoch. */ 211 public final Number responseTime; 212 213 /** HTTP response status code. */ 214 public final int responseStatus; 215 216 /** HTTP response status text. */ 217 public final String responseStatusText; 218 219 /** 220 * HTTP response type 221 * <EMBED CLASS='external-html' DATA-D=CacheStorage DATA-C=CachedResponseType DATA-F=responseType DATA-FILE-ID=CDP.EL2> 222 * @see BaseType#enumStrList(String) 223 */ 224 public final String responseType; 225 226 /** Response headers */ 227 public final CacheStorage.Header[] responseHeaders; 228 229 /** Constructor. Please review this class' fields for documentation. */ 230 public DataEntry( 231 ReadOnlyList<Boolean> isPresent, String requestURL, String requestMethod, 232 Header[] requestHeaders, Number responseTime, int responseStatus, 233 String responseStatusText, String responseType, Header[] responseHeaders 234 ) 235 { 236 super(singleton, Domains.CacheStorage, "DataEntry", 8); 237 238 this.requestURL = requestURL; 239 this.requestMethod = requestMethod; 240 this.requestHeaders = requestHeaders; 241 this.responseTime = responseTime; 242 this.responseStatus = responseStatus; 243 this.responseStatusText = responseStatusText; 244 this.responseType = responseType; 245 this.responseHeaders = responseHeaders; 246 247 this.isPresent = (isPresent == null) 248 ? singleton.generateIsPresentList(this) 249 : THROWS.check(isPresent, 8, "CacheStorage.DataEntry"); 250 } 251 252 /** Creates an instance of this class from a {@link JsonObject}.*/ 253 public static DataEntry fromJSON(JsonObject jo) 254 { return singleton.fromJSON(jo); } 255 256 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 257 public static NestedDescriptor<DataEntry> descriptor() 258 { return singleton.descriptor(); } 259 } 260 261 /** 262 * <CODE>[No Description Provided by Google]</CODE> 263 * 264 * <EMBED CLASS=globalDefs DATA-DOMAIN=CacheStorage DATA-API=BrowserAPI> 265 */ 266 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_TYPE_JDHBI") 267 public static class Header 268 extends BaseType<Header> 269 implements java.io.Serializable 270 { 271 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 272 protected static final long serialVersionUID = 1; 273 274 private static final NestedHelper<CacheStorage.Header> singleton = 275 Torello.Browser.BrowserAPI.NestedHelpers.Types. 276 CacheStorage$$Header$$.singleton; 277 278 /** <CODE>[No Description Provided by Google]</CODE> */ 279 public final String name; 280 281 /** <CODE>[No Description Provided by Google]</CODE> */ 282 public final String value; 283 284 /** Constructor. Please review this class' fields for documentation. */ 285 public Header(ReadOnlyList<Boolean> isPresent, String name, String value) 286 { 287 super(singleton, Domains.CacheStorage, "Header", 2); 288 289 this.name = name; 290 this.value = value; 291 292 this.isPresent = (isPresent == null) 293 ? singleton.generateIsPresentList(this) 294 : THROWS.check(isPresent, 2, "CacheStorage.Header"); 295 } 296 297 /** Creates an instance of this class from a {@link JsonObject}.*/ 298 public static Header fromJSON(JsonObject jo) 299 { return singleton.fromJSON(jo); } 300 301 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 302 public static NestedDescriptor<Header> descriptor() 303 { return singleton.descriptor(); } 304 } 305 306 307 // ******************************************************************************************** 308 // ******************************************************************************************** 309 // Command-Return Types 310 // ******************************************************************************************** 311 // ******************************************************************************************** 312 313 314 /** 315 * Requests data from cache. 316 * 317 * <EMBED CLASS=globalDefs DATA-DOMAIN=CacheStorage DATA-API=BrowserAPI DATA-CMD=requestEntries> 318 * @see CacheStorage#requestEntries 319 */ 320 @JDHeaderBackgroundImg(EmbedTagFileID="CDP.NESTED_CMD_JDHBI") 321 public static class requestEntries$$RET 322 extends BaseType<requestEntries$$RET> 323 implements java.io.Serializable 324 { 325 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ 326 protected static final long serialVersionUID = 1; 327 328 private static final NestedHelper<CacheStorage.requestEntries$$RET> singleton = 329 Torello.Browser.BrowserAPI.NestedHelpers.CmdReturns. 330 CacheStorage$$requestEntries$$RET.singleton; 331 332 /** Array of object store data entries. */ 333 public final CacheStorage.DataEntry[] cacheDataEntries; 334 335 /** 336 * Count of returned entries from this storage. If pathFilter is empty, it 337 * is the count of all entries from this storage. 338 */ 339 public final Number returnCount; 340 341 /** Constructor. Please review this class' fields for documentation. */ 342 public requestEntries$$RET 343 (ReadOnlyList<Boolean> isPresent, DataEntry[] cacheDataEntries, Number returnCount) 344 { 345 super(singleton, Domains.CacheStorage, "requestEntries", 2); 346 347 this.cacheDataEntries = cacheDataEntries; 348 this.returnCount = returnCount; 349 350 this.isPresent = (isPresent == null) 351 ? singleton.generateIsPresentList(this) 352 : THROWS.check(isPresent, 2, "CacheStorage.requestEntries$$RET"); 353 } 354 355 /** Creates an instance of this class from a {@link JsonObject}.*/ 356 public static requestEntries$$RET fromJSON(JsonObject jo) 357 { return singleton.fromJSON(jo); } 358 359 /** Returns this class's {@link NestedDescriptor} singleton-instance. class / type.*/ 360 public static NestedDescriptor<requestEntries$$RET> descriptor() 361 { return singleton.descriptor(); } 362 } 363 364 365 366 367 // ******************************************************************************************** 368 // ******************************************************************************************** 369 // Commands 370 // ******************************************************************************************** 371 // ******************************************************************************************** 372 373 374 /** 375 * Deletes a cache. 376 * 377 * @param cacheId Id of cache for deletion. 378 * 379 * @return An instance of <CODE>{@link Script}<Void></CODE> 380 * 381 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 382 * browser receives the invocation-request. 383 * 384 * <BR /><BR /><DIV CLASS=JDHint> 385 * This Browser-Function <I>does not have</I> a return-value. You may choose to 386 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 387 * the Browser Function has run to completion. 388 * </DIV> 389 */ 390 public static Script<Void> deleteCache(String cacheId) 391 { 392 // Build the JSON Request-Object (as a String); only 1 Parameter is passed 393 final String requestJSON = WriteJSON.get 394 (CDPTypes.STRING, "cacheId", false, "CacheStorage.deleteCache", cacheId); 395 396 return Script.NO_RET(Domains.CacheStorage, "deleteCache", requestJSON); 397 } 398 399 /** 400 * Deletes a cache entry. 401 * 402 * @param cacheId Id of cache where the entry will be deleted. 403 * 404 * @param request URL spec of the request. 405 * 406 * @return An instance of <CODE>{@link Script}<Void></CODE> 407 * 408 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 409 * browser receives the invocation-request. 410 * 411 * <BR /><BR /><DIV CLASS=JDHint> 412 * This Browser-Function <I>does not have</I> a return-value. You may choose to 413 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <Void>} to ensure that 414 * the Browser Function has run to completion. 415 * </DIV> 416 */ 417 public static Script<Void> deleteEntry(String cacheId, String request) 418 { 419 // Convert all Method Parameters into a JSON Request-Object (as a String) 420 final String requestJSON = WriteJSON.get( 421 CacheStorage$$Commands.deleteEntry$$, "CacheStorage.deleteEntry", 422 cacheId, request 423 ); 424 425 return Script.NO_RET(Domains.CacheStorage, "deleteEntry", requestJSON); 426 } 427 428 /** 429 * Requests cache names. 430 * 431 * @param securityOrigin 432 * At least and at most one of securityOrigin, storageKey, storageBucket must be specified. 433 * Security origin. 434 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 435 * 436 * @param storageKey Storage key. 437 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 438 * 439 * @param storageBucket Storage bucket. If not specified, it uses the default bucket. 440 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 441 * 442 * @return An instance of <CODE>{@link Script}<{@link CacheStorage.Cache}[]></CODE> 443 * 444 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 445 * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise} 446 * <CODE><{@link CacheStorage.Cache}[]></CODE> will be returned 447 * 448 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 449 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 450 * be retrieved.</I> 451 * 452 * <BR /><BR /><DIV CLASS=JDHint> 453 * This Browser Function's {@code Promise} returns: 454 * <CODE>{@link CacheStorage.Cache}[] (<B>caches</B>)</CODE> 455 * <BR /> 456 * Caches for the security origin. 457 * </DIV> 458 */ 459 public static Script<CacheStorage.Cache[]> requestCacheNames 460 (String securityOrigin, String storageKey, Storage.StorageBucket storageBucket) 461 { 462 // Convert all Method Parameters into a JSON Request-Object (as a String) 463 final String requestJSON = WriteJSON.get( 464 CacheStorage$$Commands.requestCacheNames$$, "CacheStorage.requestCacheNames", 465 securityOrigin, storageKey, storageBucket 466 ); 467 468 return new Script<>( 469 Domains.CacheStorage, "requestCacheNames", requestJSON, 470 CacheStorage$$Commands::requestCacheNames, 471 CacheStorage.Cache[].class 472 ); 473 } 474 475 /** 476 * Fetches cache entry. 477 * 478 * @param cacheId Id of cache that contains the entry. 479 * 480 * @param requestURL URL spec of the request. 481 * 482 * @param requestHeaders headers of the request. 483 * 484 * @return An instance of <CODE>{@link Script}<{@link CacheStorage.CachedResponse}></CODE> 485 * 486 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 487 * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise} 488 * <CODE><{@link CacheStorage.CachedResponse}></CODE> will be returned 489 * 490 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 491 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 492 * be retrieved.</I> 493 * 494 * <BR /><BR /><DIV CLASS=JDHint> 495 * This Browser Function's {@code Promise} returns: 496 * <CODE>{@link CacheStorage.CachedResponse} (<B>response</B>)</CODE> 497 * <BR /> 498 * Response read from the cache. 499 * </DIV> 500 */ 501 public static Script<CacheStorage.CachedResponse> requestCachedResponse 502 (String cacheId, String requestURL, Header[] requestHeaders) 503 { 504 // Convert all Method Parameters into a JSON Request-Object (as a String) 505 final String requestJSON = WriteJSON.get( 506 CacheStorage$$Commands.requestCachedResponse$$, "CacheStorage.requestCachedResponse", 507 cacheId, requestURL, requestHeaders 508 ); 509 510 return new Script<>( 511 Domains.CacheStorage, "requestCachedResponse", requestJSON, 512 CacheStorage$$Commands::requestCachedResponse, 513 CacheStorage.CachedResponse.class 514 ); 515 } 516 517 /** 518 * Requests data from cache. 519 * 520 * @param cacheId ID of cache to get entries from. 521 * 522 * @param skipCount Number of records to skip. 523 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 524 * 525 * @param pageSize Number of records to fetch. 526 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 527 * 528 * @param pathFilter If present, only return the entries containing this substring in the path 529 * <BR /><B CLASS=Opt-Top>OPTIONAL</B> 530 * 531 * @return An instance of <CODE>{@link Script}<{@link requestEntries$$RET}></CODE> 532 * 533 * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using 534 * {@link Script#exec(WebSocketSender) Script.exec}, and afterwards, a {@link Promise} 535 * <CODE><{@link requestEntries$$RET}></CODE> will be returned 536 * 537 * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>, 538 * using {@link Promise#await()}, <I>and the returned result of this Browser Function may 539 * be retrieved.</I> 540 * 541 * <BR /><BR /><DIV CLASS=JDHint> 542 * This Browser Function's {@code Promise} returns:{@link requestEntries$$RET} 543 * A dedicated return type implies that the browser may return more than 1 datum 544 * </DIV> 545 */ 546 public static Script<requestEntries$$RET> requestEntries 547 (String cacheId, Integer skipCount, Integer pageSize, String pathFilter) 548 { 549 // Convert all Method Parameters into a JSON Request-Object (as a String) 550 final String requestJSON = WriteJSON.get( 551 CacheStorage$$Commands.requestEntries$$, "CacheStorage.requestEntries", 552 cacheId, skipCount, pageSize, pathFilter 553 ); 554 555 return new Script<>( 556 Domains.CacheStorage, "requestEntries", requestJSON, 557 requestEntries$$RET::fromJSON, 558 requestEntries$$RET.class 559 ); 560 } 561 562 563}