generate.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. "use strict";
  2. /*
  3. Copyright 2019 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. const joi = require('@hapi/joi');
  9. const defaults = require('../defaults');
  10. const regExpObject = require('../objects/reg-exp');
  11. module.exports = {
  12. babelPresetEnvTargets: joi.array().items(joi.string()).default(defaults.babelPresetEnvTargets),
  13. cacheId: joi.string(),
  14. cleanupOutdatedCaches: joi.boolean().default(defaults.cleanupOutdatedCaches),
  15. clientsClaim: joi.boolean().default(defaults.clientsClaim),
  16. directoryIndex: joi.string(),
  17. disableDevLogs: joi.boolean().default(defaults.disableDevLogs),
  18. ignoreURLParametersMatching: joi.array().items(regExpObject),
  19. importScripts: joi.array().items(joi.string()),
  20. inlineWorkboxRuntime: joi.boolean().default(defaults.inlineWorkboxRuntime),
  21. navigateFallback: joi.string().default(defaults.navigateFallback),
  22. navigateFallbackAllowlist: joi.array().items(regExpObject),
  23. navigateFallbackBlacklist: joi.forbidden().error(new Error('navigateFallbackBlacklist has been renamed navigateFallbackDenylist.')),
  24. navigateFallbackDenylist: joi.array().items(regExpObject),
  25. navigateFallbackWhitelist: joi.forbidden().error(new Error('navigateFallbackWhitelist has been renamed navigateFallbackAllowlist.')),
  26. navigationPreload: joi.boolean().default(defaults.navigationPreload),
  27. offlineGoogleAnalytics: joi.alternatives().try(joi.boolean(), joi.object()).default(defaults.offlineGoogleAnalytics),
  28. runtimeCaching: joi.array().items(joi.object().keys({
  29. method: joi.string().valid('DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'),
  30. urlPattern: [regExpObject, joi.string(), joi.func()],
  31. handler: [joi.func(), joi.string().valid('CacheFirst', 'CacheOnly', 'NetworkFirst', 'NetworkOnly', 'StaleWhileRevalidate')],
  32. options: joi.object().keys({
  33. backgroundSync: joi.object().keys({
  34. name: joi.string().required(),
  35. options: joi.object()
  36. }),
  37. broadcastUpdate: joi.object().keys({
  38. channelName: joi.string().required(),
  39. options: joi.object()
  40. }),
  41. cacheableResponse: joi.object().keys({
  42. statuses: joi.array().items(joi.number().min(0).max(599)),
  43. headers: joi.object()
  44. }).or('statuses', 'headers'),
  45. cacheName: joi.string(),
  46. expiration: joi.object().keys({
  47. maxEntries: joi.number().min(1),
  48. maxAgeSeconds: joi.number().min(1),
  49. purgeOnQuotaError: joi.boolean().default(defaults.purgeOnQuotaError)
  50. }).or('maxEntries', 'maxAgeSeconds'),
  51. networkTimeoutSeconds: joi.number().min(1),
  52. plugins: joi.array().items(joi.object()),
  53. fetchOptions: joi.object(),
  54. matchOptions: joi.object()
  55. }).with('expiration', 'cacheName')
  56. }).requiredKeys('urlPattern', 'handler')).when('navigationPreload', {
  57. is: true,
  58. then: joi.required()
  59. }),
  60. skipWaiting: joi.boolean().default(defaults.skipWaiting),
  61. sourcemap: joi.boolean().default(defaults.sourcemap)
  62. };