index.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Options, CacheControl, MethodNotAllowedError, NotFoundError, InternalError } from './types';
  2. declare global {
  3. var __STATIC_CONTENT: any, __STATIC_CONTENT_MANIFEST: string;
  4. }
  5. /**
  6. * maps the path of incoming request to the request pathKey to look up
  7. * in bucket and in cache
  8. * e.g. for a path '/' returns '/index.html' which serves
  9. * the content of bucket/index.html
  10. * @param {Request} request incoming request
  11. */
  12. declare const mapRequestToAsset: (request: Request, options?: Partial<Options>) => Request;
  13. /**
  14. * maps the path of incoming request to /index.html if it evaluates to
  15. * any HTML file.
  16. * @param {Request} request incoming request
  17. */
  18. declare function serveSinglePageApp(request: Request, options?: Partial<Options>): Request;
  19. /**
  20. * takes the path of the incoming request, gathers the appropriate content from KV, and returns
  21. * the response
  22. *
  23. * @param {FetchEvent} event the fetch event of the triggered request
  24. * @param {{mapRequestToAsset: (string: Request) => Request, cacheControl: {bypassCache:boolean, edgeTTL: number, browserTTL:number}, ASSET_NAMESPACE: any, ASSET_MANIFEST:any}} [options] configurable options
  25. * @param {CacheControl} [options.cacheControl] determine how to cache on Cloudflare and the browser
  26. * @param {typeof(options.mapRequestToAsset)} [options.mapRequestToAsset] maps the path of incoming request to the request pathKey to look up
  27. * @param {Object | string} [options.ASSET_NAMESPACE] the binding to the namespace that script references
  28. * @param {any} [options.ASSET_MANIFEST] the map of the key to cache and store in KV
  29. * */
  30. declare type Evt = {
  31. request: Request;
  32. waitUntil: (promise: Promise<any>) => void;
  33. };
  34. declare const getAssetFromKV: (event: Evt, options?: Partial<Options>) => Promise<Response>;
  35. export { getAssetFromKV, mapRequestToAsset, serveSinglePageApp };
  36. export { Options, CacheControl, MethodNotAllowedError, NotFoundError, InternalError };