@ohos-ports/layer0-prefetch 4.20.0-beta.0 → 4.20.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/node_modules/@layer0/core/README.md +50 -0
  2. package/node_modules/@layer0/core/build.d.ts +5 -0
  3. package/node_modules/@layer0/core/build.js +17 -0
  4. package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
  5. package/node_modules/@layer0/core/cache/Cache.js +138 -0
  6. package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
  7. package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
  8. package/node_modules/@layer0/core/config.d.ts +53 -0
  9. package/node_modules/@layer0/core/config.js +113 -0
  10. package/node_modules/@layer0/core/constants.d.ts +214 -0
  11. package/node_modules/@layer0/core/constants.js +216 -0
  12. package/node_modules/@layer0/core/context.d.ts +38 -0
  13. package/node_modules/@layer0/core/context.js +98 -0
  14. package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
  15. package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
  16. package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
  17. package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
  18. package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
  19. package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
  20. package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
  21. package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
  22. package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
  23. package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
  24. package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
  25. package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
  26. package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
  27. package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
  28. package/node_modules/@layer0/core/deploy/index.js +6 -0
  29. package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
  30. package/node_modules/@layer0/core/deploy/listSources.js +18 -0
  31. package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
  32. package/node_modules/@layer0/core/deploy/paths.js +33 -0
  33. package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
  34. package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
  35. package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
  36. package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
  37. package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
  38. package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
  39. package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
  40. package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
  41. package/node_modules/@layer0/core/dev/index.d.ts +3 -0
  42. package/node_modules/@layer0/core/dev/index.js +6 -0
  43. package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
  44. package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
  45. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
  46. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
  47. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
  48. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
  49. package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
  50. package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
  51. package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
  52. package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
  53. package/node_modules/@layer0/core/environment.d.ts +24 -0
  54. package/node_modules/@layer0/core/environment.js +42 -0
  55. package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
  56. package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
  57. package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
  58. package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
  59. package/node_modules/@layer0/core/index.d.ts +3 -0
  60. package/node_modules/@layer0/core/index.js +9 -0
  61. package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
  62. package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
  63. package/node_modules/@layer0/core/init/index.d.ts +2 -0
  64. package/node_modules/@layer0/core/init/index.js +6 -0
  65. package/node_modules/@layer0/core/init/init.d.ts +5 -0
  66. package/node_modules/@layer0/core/init/init.js +17 -0
  67. package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
  68. package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
  69. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
  70. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
  71. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
  72. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
  73. package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
  74. package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
  75. package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
  76. package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
  77. package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
  78. package/node_modules/@layer0/core/lambda/handler.js +91 -0
  79. package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
  80. package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
  81. package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
  82. package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
  83. package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
  84. package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
  85. package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
  86. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
  87. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
  88. package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
  89. package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
  90. package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
  91. package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
  92. package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
  93. package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
  94. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
  95. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
  96. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
  97. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
  98. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
  99. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
  100. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
  101. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
  102. package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
  103. package/node_modules/@layer0/core/package.json +132 -0
  104. package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
  105. package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
  106. package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
  107. package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
  108. package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
  109. package/node_modules/@layer0/core/router/Backend.js +176 -0
  110. package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
  111. package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
  112. package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
  113. package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
  114. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
  115. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
  116. package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
  117. package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
  118. package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
  119. package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
  120. package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
  121. package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
  122. package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
  123. package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
  124. package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
  125. package/node_modules/@layer0/core/router/Groups.js +21 -0
  126. package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
  127. package/node_modules/@layer0/core/router/Headers.js +2 -0
  128. package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
  129. package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
  130. package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
  131. package/node_modules/@layer0/core/router/Preload.js +2 -0
  132. package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
  133. package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
  134. package/node_modules/@layer0/core/router/Request.d.ts +74 -0
  135. package/node_modules/@layer0/core/router/Request.js +2 -0
  136. package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
  137. package/node_modules/@layer0/core/router/RequestContext.js +11 -0
  138. package/node_modules/@layer0/core/router/Response.d.ts +55 -0
  139. package/node_modules/@layer0/core/router/Response.js +2 -0
  140. package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
  141. package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
  142. package/node_modules/@layer0/core/router/Route.d.ts +124 -0
  143. package/node_modules/@layer0/core/router/Route.js +280 -0
  144. package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
  145. package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
  146. package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
  147. package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
  148. package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
  149. package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
  150. package/node_modules/@layer0/core/router/Router.d.ts +439 -0
  151. package/node_modules/@layer0/core/router/Router.js +907 -0
  152. package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
  153. package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
  154. package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
  155. package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
  156. package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
  157. package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
  158. package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
  159. package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
  160. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
  161. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
  162. package/node_modules/@layer0/core/router/index.d.ts +11 -0
  163. package/node_modules/@layer0/core/router/index.js +17 -0
  164. package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
  165. package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
  166. package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
  167. package/node_modules/@layer0/core/router/loadRouter.js +29 -0
  168. package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
  169. package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
  170. package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
  171. package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
  172. package/node_modules/@layer0/core/router/stream.d.ts +12 -0
  173. package/node_modules/@layer0/core/router/stream.js +30 -0
  174. package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
  175. package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
  176. package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
  177. package/node_modules/@layer0/core/router/validateWriter.js +120 -0
  178. package/node_modules/@layer0/core/serverless.yml +30 -0
  179. package/node_modules/@layer0/core/source.d.ts +9 -0
  180. package/node_modules/@layer0/core/source.js +17 -0
  181. package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
  182. package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
  183. package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
  184. package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
  185. package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
  186. package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
  187. package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
  188. package/node_modules/@layer0/core/test-utils/index.js +11 -0
  189. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
  190. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
  191. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
  192. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
  193. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
  194. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
  195. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
  196. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
  197. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
  198. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
  199. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
  200. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
  201. package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
  202. package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
  203. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
  204. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
  205. package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
  206. package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
  207. package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
  208. package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
  209. package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
  210. package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
  211. package/node_modules/@layer0/core/timing.d.ts +115 -0
  212. package/node_modules/@layer0/core/timing.js +200 -0
  213. package/node_modules/@layer0/core/transform/index.d.ts +1 -0
  214. package/node_modules/@layer0/core/transform/index.js +4 -0
  215. package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
  216. package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
  217. package/node_modules/@layer0/core/types.d.ts +102 -0
  218. package/node_modules/@layer0/core/types.js +30 -0
  219. package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
  220. package/node_modules/@layer0/core/utils/Tasks.js +80 -0
  221. package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
  222. package/node_modules/@layer0/core/utils/Validator.js +178 -0
  223. package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
  224. package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
  225. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
  226. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
  227. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
  228. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
  229. package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
  230. package/node_modules/@layer0/core/utils/decode.js +44 -0
  231. package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
  232. package/node_modules/@layer0/core/utils/esImport.js +9 -0
  233. package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
  234. package/node_modules/@layer0/core/utils/fs.js +7 -0
  235. package/node_modules/@layer0/core/utils/get.d.ts +6 -0
  236. package/node_modules/@layer0/core/utils/get.js +19 -0
  237. package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
  238. package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
  239. package/node_modules/@layer0/core/utils/has.d.ts +6 -0
  240. package/node_modules/@layer0/core/utils/has.js +15 -0
  241. package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
  242. package/node_modules/@layer0/core/utils/identity.js +12 -0
  243. package/node_modules/@layer0/core/utils/index.d.ts +1 -0
  244. package/node_modules/@layer0/core/utils/index.js +4 -0
  245. package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
  246. package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
  247. package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
  248. package/node_modules/@layer0/core/utils/isString.js +6 -0
  249. package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
  250. package/node_modules/@layer0/core/utils/logo.js +27 -0
  251. package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
  252. package/node_modules/@layer0/core/utils/mapValues.js +16 -0
  253. package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
  254. package/node_modules/@layer0/core/utils/minBy.js +41 -0
  255. package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
  256. package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
  257. package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
  258. package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
  259. package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
  260. package/node_modules/@layer0/core/utils/ports.js +7 -0
  261. package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
  262. package/node_modules/@layer0/core/utils/readBody.js +15 -0
  263. package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
  264. package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
  265. package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
  266. package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
  267. package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
  268. package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
  269. package/node_modules/@layer0/core/utils/set.d.ts +10 -0
  270. package/node_modules/@layer0/core/utils/set.js +21 -0
  271. package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
  272. package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
  273. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
  274. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
  275. package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
  276. package/node_modules/@layer0/core/utils/toLower.js +9 -0
  277. package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
  278. package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
  279. package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
  280. package/node_modules/@layer0/core/utils/watch.js +17 -0
  281. package/package.json +47 -3
@@ -0,0 +1,6 @@
1
+ import RouteCriteria from './RouteCriteria';
2
+ /**
3
+ * Converts null to an empty RouteCriteria and a string to a RouteCriteria with path.
4
+ * @param criteria null, a route pattern, or an object that implements the RouteCriteria interface
5
+ */
6
+ export default function normalizeCriteria(criteria: string | RouteCriteria | null | undefined): RouteCriteria;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Converts null to an empty RouteCriteria and a string to a RouteCriteria with path.
5
+ * @param criteria null, a route pattern, or an object that implements the RouteCriteria interface
6
+ */
7
+ function normalizeCriteria(criteria) {
8
+ if (criteria == null) {
9
+ return {};
10
+ }
11
+ else if (typeof criteria === 'string') {
12
+ return {
13
+ path: criteria,
14
+ };
15
+ }
16
+ else {
17
+ return criteria;
18
+ }
19
+ }
20
+ exports.default = normalizeCriteria;
@@ -0,0 +1,12 @@
1
+ import Request from './Request';
2
+ import Response from './Response';
3
+ import BackendConfig from './BackendOptions';
4
+ /**
5
+ * Proxies the request to the specified backend as a stream. This can be used for event streams
6
+ * for hot module reloading.
7
+ * @param req The downstream request
8
+ * @param res The downstream response
9
+ * @param backendConfig The backend config from `layer0.config.js`
10
+ * @param errorHandler A function to call when an error occurs
11
+ */
12
+ export default function stream(req: Request, res: Response, backendConfig: BackendConfig, errorHandler: any): void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const http_proxy_1 = __importDefault(require("http-proxy"));
7
+ const proxy = http_proxy_1.default.createProxyServer({
8
+ changeOrigin: true,
9
+ });
10
+ /**
11
+ * Proxies the request to the specified backend as a stream. This can be used for event streams
12
+ * for hot module reloading.
13
+ * @param req The downstream request
14
+ * @param res The downstream response
15
+ * @param backendConfig The backend config from `layer0.config.js`
16
+ * @param errorHandler A function to call when an error occurs
17
+ */
18
+ function stream(req, res, backendConfig, errorHandler) {
19
+ const protocol = backendConfig.domainOrIp === '127.0.0.1' ? 'http' : 'https';
20
+ const config = {
21
+ target: {
22
+ protocol,
23
+ host: backendConfig.domainOrIp,
24
+ port: backendConfig.port,
25
+ },
26
+ };
27
+ // @ts-ignore
28
+ proxy.web(req, res, config, errorHandler || Function.prototype);
29
+ }
30
+ exports.default = stream;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Compares criteria object with request object and returns Boolean.
3
+ *
4
+ * The comparison of keys is case-sensitive by default but an optional `criteriaObjKeyNameFn`
5
+ * parameter can be passed to force case-insensitive comparison.
6
+ *
7
+ * @param criteriaObj Object that contains the criteria ([key]: regex | null)
8
+ * @param requestObj Request object that contains ([key]: string | [key]: string[] | undefined)
9
+ * @param criteriaObjKeyNameFn Optional function to process criteria key names; by default set to `identity`
10
+ *
11
+ * @returns Boolean
12
+ * true when all conditions are matching
13
+ * false if one of the conditions failed
14
+ */
15
+ export declare function matchCriteriaRegexObjectWithRequestObject(criteriaObj: {
16
+ [name: string]: string | RegExp | null;
17
+ }, requestObj: {
18
+ [key: string]: string | string[] | undefined;
19
+ }, criteriaObjKeyNameFn?: (key: string) => string): false | {
20
+ [key: string]: string;
21
+ };
22
+ /**
23
+ * Tests to see if source object deeply matches the criteria object
24
+ *
25
+ * @param source Object
26
+ * @param criteria Object
27
+ *
28
+ * @returns boolean
29
+ */
30
+ export declare function deepMatchObject(source: any, criteria: any): boolean;
31
+ /**
32
+ * Returns true if the value is a matcher that is used to extract
33
+ * request params, like ':id' or ':path'
34
+ * @param value
35
+ */
36
+ export declare function isParamMatcher(value: any): boolean;
37
+ /**
38
+ * Transform a route param matcher to the param name
39
+ * ex: ':id' -> 'id'
40
+ * @param value
41
+ */
42
+ export declare function paramMatcherToParam(value: any): any;
43
+ /**
44
+ * Ensures that the regular expression will be tested anew, without changing its internal state.
45
+ *
46
+ * Notes:
47
+ * - Sometimes users use global for RegExp definitions. In those cases `.test` changes the internal
48
+ * state and leads to different requests on subsequent calls (usually flip-flopping between
49
+ * subsequent requests)
50
+ *
51
+ * @private
52
+ * @param regexp Regular expression
53
+ * @param value Value to test or array of values to test
54
+ */
55
+ export declare function testRegExp(regexp: RegExp, value: undefined | string | string[]): boolean;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ Note: this file contains functions that are needed in both the browser and the server. These were originally
5
+ in Route.ts, but extracted in order to keep Route.ts and it's depedencies from being pulled into the browser bundle.
6
+ */
7
+ const identity = (x) => x;
8
+ /**
9
+ * Compares criteria object with request object and returns Boolean.
10
+ *
11
+ * The comparison of keys is case-sensitive by default but an optional `criteriaObjKeyNameFn`
12
+ * parameter can be passed to force case-insensitive comparison.
13
+ *
14
+ * @param criteriaObj Object that contains the criteria ([key]: regex | null)
15
+ * @param requestObj Request object that contains ([key]: string | [key]: string[] | undefined)
16
+ * @param criteriaObjKeyNameFn Optional function to process criteria key names; by default set to `identity`
17
+ *
18
+ * @returns Boolean
19
+ * true when all conditions are matching
20
+ * false if one of the conditions failed
21
+ */
22
+ function matchCriteriaRegexObjectWithRequestObject(criteriaObj, requestObj, criteriaObjKeyNameFn = identity) {
23
+ let params = {};
24
+ return (Object.entries(criteriaObj).every(([name, regex]) => {
25
+ const value = requestObj[criteriaObjKeyNameFn(name)];
26
+ // When regex is null we match that the value *does not* exist (the undefined case).
27
+ // When regex is string, we convert it to regex matching the whole string.
28
+ // When regex is a matching key (ex: ':id') and the value is a string, we extract that into
29
+ // matcher params
30
+ if (regex === null) {
31
+ return value === undefined;
32
+ }
33
+ else if (typeof regex === 'string') {
34
+ if (typeof value === 'string' && isParamMatcher(regex)) {
35
+ const paramName = paramMatcherToParam(regex);
36
+ params[paramName] = value;
37
+ return true;
38
+ }
39
+ regex = new RegExp(`^${regex}$`, 'i');
40
+ }
41
+ return testRegExp(regex, value);
42
+ }) && params);
43
+ }
44
+ exports.matchCriteriaRegexObjectWithRequestObject = matchCriteriaRegexObjectWithRequestObject;
45
+ /**
46
+ * Tests to see if source object deeply matches the criteria object
47
+ *
48
+ * @param source Object
49
+ * @param criteria Object
50
+ *
51
+ * @returns boolean
52
+ */
53
+ function deepMatchObject(source, criteria) {
54
+ return Object.entries(criteria).every(([key, criteriaValue]) => {
55
+ const sourceValue = source[key];
56
+ if (!sourceValue)
57
+ return false;
58
+ if (criteriaValue instanceof RegExp) {
59
+ return testRegExp(criteriaValue, sourceValue);
60
+ }
61
+ else if (typeof criteriaValue === 'object' && criteriaValue !== null) {
62
+ return deepMatchObject(sourceValue, criteriaValue);
63
+ }
64
+ else {
65
+ return sourceValue == criteriaValue;
66
+ }
67
+ });
68
+ }
69
+ exports.deepMatchObject = deepMatchObject;
70
+ /**
71
+ * Returns true if the value is a matcher that is used to extract
72
+ * request params, like ':id' or ':path'
73
+ * @param value
74
+ */
75
+ function isParamMatcher(value) {
76
+ return typeof value === 'string' && /^:\w+$/.test(value);
77
+ }
78
+ exports.isParamMatcher = isParamMatcher;
79
+ /**
80
+ * Transform a route param matcher to the param name
81
+ * ex: ':id' -> 'id'
82
+ * @param value
83
+ */
84
+ function paramMatcherToParam(value) {
85
+ return value.slice(1);
86
+ }
87
+ exports.paramMatcherToParam = paramMatcherToParam;
88
+ /**
89
+ * Ensures that the regular expression will be tested anew, without changing its internal state.
90
+ *
91
+ * Notes:
92
+ * - Sometimes users use global for RegExp definitions. In those cases `.test` changes the internal
93
+ * state and leads to different requests on subsequent calls (usually flip-flopping between
94
+ * subsequent requests)
95
+ *
96
+ * @private
97
+ * @param regexp Regular expression
98
+ * @param value Value to test or array of values to test
99
+ */
100
+ function testRegExp(regexp, value) {
101
+ if (value == null) {
102
+ return false;
103
+ }
104
+ if (regexp.global) {
105
+ regexp = new RegExp(regexp);
106
+ }
107
+ if (Array.isArray(value)) {
108
+ return value.some(v => regexp.test(v));
109
+ }
110
+ else {
111
+ return regexp.test(value);
112
+ }
113
+ }
114
+ exports.testRegExp = testRegExp;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Validate Set response header
3
+ * @param name header name
4
+ * @param value header value
5
+ */
6
+ export declare const validateSetResponseHeader: (name: string) => void;
7
+ /**
8
+ * Validate Update response header
9
+ * @param name header name
10
+ * @param match match pattern
11
+ * @param replace replace value
12
+ */
13
+ export declare const validateUpdateResponseHeader: (name: string) => void;
14
+ /**
15
+ * Validate Remove response header
16
+ * @param name
17
+ */
18
+ export declare const validateRemoveResponseHeader: (name: string) => void;
19
+ /**
20
+ * Validate set request header
21
+ * @param name header name
22
+ * @param value header value
23
+ */
24
+ export declare const validateSetRequestHeader: (name: string) => void;
25
+ /**
26
+ * Validate Update request header
27
+ * @param name header name
28
+ * @param match match pattern
29
+ * @param replace replace value
30
+ */
31
+ export declare const validateUpdateRequestHeader: (name: string) => void;
32
+ /**
33
+ * Validate Remove request header
34
+ * @param name
35
+ */
36
+ export declare const validateRemoveRequestHeader: (name: string) => void;
37
+ /**
38
+ * Validate cookie name.
39
+ * @param name
40
+ */
41
+ export declare const validateCookieName: (name: string) => void;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * List of header regexes that will be matched against user provided header name.
5
+ * The following headers are not allowed for user to modify in any way.
6
+ *
7
+ * * `x-0-platform` headers are generated and maintained by Layer0 platform to store intermediate state during request processing
8
+ * * `x-0-version` header should only be manipulated by Layer0 platform
9
+ * * `x-0-t` header should only be manipulated by Layer0 platform
10
+ * * `x-0-components` header should only be manipulated by Layer0 platform
11
+ * * `x-0-status` header should only be manipulated by Layer0 platform
12
+ * * `x-0-lambda-name` header should only be manipulated by Layer0 platform as otherwise it messes with reverse proxying. Removed by XBP
13
+ * * `x-0-lambda-schedule-timeout` header should only be manipulated by Layer0 platform as otherwise it messes with reverse proxying. Removed by XBP
14
+ * * `x-0-received-at` header should only be manipulated by Layer0 platform as otherwise it messes with reverse proxying.
15
+ * * `host` header should only be manipulated by Layer0 platform as otherwise it messes with reverse proxying
16
+ * * `x-request-id` header is generated by Layer0 platform and used as unique identifier of requests
17
+ * * `content-length` header cannot be manipulated apart from manipulating the body and we don't support that in the edge
18
+ * * `via` header is used to prevent request loops in the platform
19
+ */
20
+ const LAYER0_PROHIBITED_HEADER_NAMES = [
21
+ // Only allowed for platform to manipulate
22
+ /^\s*x-0-platform\s*/i,
23
+ // Deny list for x-0-* headers
24
+ /^\s*x-0-version\s*$/i,
25
+ /^\s*x-0-t\s*$/i,
26
+ /^\s*x-0-components\s*$/i,
27
+ /^\s*x-0-status\s*$/i,
28
+ /^\s*x-0-lambda-name\s*$/i,
29
+ /^\s*x-0-lambda-schedule-timeout\s*$/i,
30
+ /^\s*x-0-received-at\s*$/i,
31
+ // Deny list for non x-0-* headers
32
+ /^\s*host\s*$/i,
33
+ /^\s*x-request-id\s*$/i,
34
+ /^\s*content-length\s*$/i,
35
+ /^\s*via\s*$/i,
36
+ ];
37
+ /**
38
+ * List of cookie regexes that will be matched against user provided cookie name.
39
+ * The following cookies are not allowed for user to modify in any way.
40
+ *
41
+ * * `layer0_*` cookies are created and maintained by Layer0 platform (e.g. `layer0_buckets` and `layer0_destination`)
42
+ * * `layer0_devtools_*` cookies allow enabling/disabling the devtools on a per-user or per-environment bases
43
+ * (cf. packages/devtools/src/addBuiltInRoutes.js)
44
+ */
45
+ const LAYER0_PROHIBITED_COOKIE_NAMES = [/^layer0_/i];
46
+ const LAYER0_WHITELISTED_COOKIE_NAMES = [/^layer0_devtools/i];
47
+ /**
48
+ * Validate that prohibited header names are not overrideable by the user
49
+ * @param name
50
+ */
51
+ const validateProhibitedHeaderNames = (name) => {
52
+ if (LAYER0_PROHIBITED_HEADER_NAMES.find(prohibitedRegex => name.match(prohibitedRegex))) {
53
+ throw new Error(`Header "${name}" is reserved and cannot be modified`);
54
+ }
55
+ };
56
+ /**
57
+ * Validate that prohibited cookie names are not overrideable by the user
58
+ * @param name
59
+ */
60
+ const validateProhibitedCookieNames = (name) => {
61
+ if (LAYER0_PROHIBITED_COOKIE_NAMES.find(prohibitedRegex => name.match(prohibitedRegex)) &&
62
+ !LAYER0_WHITELISTED_COOKIE_NAMES.find(whitelistRegexp => name.match(whitelistRegexp))) {
63
+ throw new Error(`Cookie "${name}" is reserved and cannot be modified`);
64
+ }
65
+ };
66
+ /**
67
+ * Validate Set response header
68
+ * @param name header name
69
+ * @param value header value
70
+ */
71
+ exports.validateSetResponseHeader = (name /* value */) => {
72
+ validateProhibitedHeaderNames(name);
73
+ };
74
+ /**
75
+ * Validate Update response header
76
+ * @param name header name
77
+ * @param match match pattern
78
+ * @param replace replace value
79
+ */
80
+ exports.validateUpdateResponseHeader = (name /* match, replace */) => {
81
+ validateProhibitedHeaderNames(name);
82
+ };
83
+ /**
84
+ * Validate Remove response header
85
+ * @param name
86
+ */
87
+ exports.validateRemoveResponseHeader = (name) => {
88
+ validateProhibitedHeaderNames(name);
89
+ };
90
+ /**
91
+ * Validate set request header
92
+ * @param name header name
93
+ * @param value header value
94
+ */
95
+ exports.validateSetRequestHeader = (name) => {
96
+ validateProhibitedHeaderNames(name);
97
+ };
98
+ /**
99
+ * Validate Update request header
100
+ * @param name header name
101
+ * @param match match pattern
102
+ * @param replace replace value
103
+ */
104
+ exports.validateUpdateRequestHeader = (name) => {
105
+ validateProhibitedHeaderNames(name);
106
+ };
107
+ /**
108
+ * Validate Remove request header
109
+ * @param name
110
+ */
111
+ exports.validateRemoveRequestHeader = (name) => {
112
+ validateProhibitedHeaderNames(name);
113
+ };
114
+ /**
115
+ * Validate cookie name.
116
+ * @param name
117
+ */
118
+ exports.validateCookieName = (name) => {
119
+ validateProhibitedCookieNames(name);
120
+ };
@@ -0,0 +1,30 @@
1
+ service:
2
+ name: myApp
3
+
4
+ provider:
5
+ name: aws
6
+ runtime: nodejs16.x # NODE_VERSION
7
+
8
+ plugins:
9
+ - serverless-offline
10
+ - serverless-dotenv-plugin
11
+ custom:
12
+ dotenv:
13
+ path: '../../.env'
14
+
15
+ functions:
16
+ all:
17
+ handler: handler.handler
18
+ environment:
19
+ LAYER0_DEPLOYMENT_TYPE: AWS
20
+ LAYER0_CONFIG: '{ "backends": { "__static__": { "domainOrIp": "127.0.0.1:3002" } } }'
21
+ # The `events` block defines how to trigger the handler
22
+ events:
23
+ - http:
24
+ path: /
25
+ method: ANY
26
+ cors: true
27
+ - http:
28
+ path: /{proxy+}
29
+ method: ANY
30
+ cors: true
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets the directory corresponding to the root of the project source code.
3
+ */
4
+ export declare function getSourceDir(): string;
5
+ /**
6
+ * Sets the directory corresponding to the root of the project source code.
7
+ * @param dir The directory to set
8
+ */
9
+ export declare function setSourceDir(dir: string): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Gets the directory corresponding to the root of the project source code.
5
+ */
6
+ function getSourceDir() {
7
+ return process.env.LAYER0_ROOT_SOURCE_DIR || process.cwd();
8
+ }
9
+ exports.getSourceDir = getSourceDir;
10
+ /**
11
+ * Sets the directory corresponding to the root of the project source code.
12
+ * @param dir The directory to set
13
+ */
14
+ function setSourceDir(dir) {
15
+ process.env.LAYER0_ROOT_SOURCE_DIR = dir;
16
+ }
17
+ exports.setSourceDir = setSourceDir;
@@ -0,0 +1,15 @@
1
+ /// <reference types="jest" />
2
+ export default class MockRequest {
3
+ method: string;
4
+ headers: {
5
+ host: string;
6
+ };
7
+ connection: {
8
+ remoteAddress: string;
9
+ };
10
+ constructor(config: any);
11
+ setHeader: jest.Mock<any, any>;
12
+ updateHeader: jest.Mock<any, any>;
13
+ removeHeader: jest.Mock<any, any>;
14
+ on: jest.Mock<void, [any, any]>;
15
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // @ts-nocheck
7
+ const querystring_1 = __importDefault(require("querystring"));
8
+ class MockRequest {
9
+ constructor(config) {
10
+ this.method = 'GET';
11
+ this.headers = {
12
+ host: 'jest.layer0.co',
13
+ };
14
+ this.connection = {
15
+ remoteAddress: '127.0.0.1',
16
+ };
17
+ this.setHeader = jest.fn();
18
+ this.updateHeader = jest.fn();
19
+ this.removeHeader = jest.fn();
20
+ this.on = jest.fn((event, cb) => {
21
+ if (event === 'end') {
22
+ cb();
23
+ }
24
+ });
25
+ Object.assign(this, config);
26
+ if (config.url) {
27
+ const [path, qs] = config.url.split(/\?/);
28
+ this.path = path;
29
+ this.query = {
30
+ ...this.query,
31
+ ...(qs && querystring_1.default.parse(qs)),
32
+ };
33
+ }
34
+ }
35
+ }
36
+ exports.default = MockRequest;
@@ -0,0 +1,7 @@
1
+ export default class MockResponse {
2
+ headers: {
3
+ 'x-test': string;
4
+ };
5
+ constructor(config?: {});
6
+ clone: () => this;
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ class MockResponse {
5
+ constructor(config = {}) {
6
+ this.headers = {
7
+ 'x-test': 'jest',
8
+ };
9
+ this.clone = () => this;
10
+ Object.assign(this, {
11
+ writeHead: jest.fn(),
12
+ end: jest.fn(body => (this.body = (body || '').toString())),
13
+ getHeader: jest.fn(name => this.headers[name.toLowerCase()] || this.headers[name]),
14
+ setHeader: jest.fn((name, value) => (this.headers[name] = value)),
15
+ removeHeader: jest.fn(name => delete this.headers[name]),
16
+ getHeaders: () => this.headers,
17
+ on: jest.fn(),
18
+ once: jest.fn(),
19
+ write: jest.fn(),
20
+ emit: jest.fn(),
21
+ }, config);
22
+ }
23
+ }
24
+ exports.default = MockResponse;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importStar = (this && this.__importStar) || function (mod) {
3
+ if (mod && mod.__esModule) return mod;
4
+ var result = {};
5
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6
+ result["default"] = mod;
7
+ return result;
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const extensions = __importStar(require("./matchers"));
11
+ expect.extend(extensions);
@@ -0,0 +1,4 @@
1
+ import './expect-extend';
2
+ export { default as runRoute } from './utils/runRoute';
3
+ export { default as createRouteMock } from './utils/createRouteMock';
4
+ export { appHost, staticHost, backendHost } from './utils/getBackend';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./expect-extend");
4
+ var runRoute_1 = require("./utils/runRoute");
5
+ exports.runRoute = runRoute_1.default;
6
+ var createRouteMock_1 = require("./utils/createRouteMock");
7
+ exports.createRouteMock = createRouteMock_1.default;
8
+ var getBackend_1 = require("./utils/getBackend");
9
+ exports.appHost = getBackend_1.appHost;
10
+ exports.staticHost = getBackend_1.staticHost;
11
+ exports.backendHost = getBackend_1.backendHost;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Matches the browser cache-control header in the response with an optional duration
3
+ *
4
+ * **Example**
5
+ * ```js
6
+ * expect(response).toBeCachedByTheBrowser()
7
+ * ...
8
+ * expect(response).toBeCachedByTheBrowser(60*60*24)
9
+ * ```
10
+ *
11
+ * @param {MockResponse} received The mocked response
12
+ * @param {Number} duration Optional - the duration (in seconds) the response is expected to be cached for
13
+ * @returns
14
+ */
15
+ export declare function toBeCachedByTheBrowser(received: any, duration?: number): {
16
+ message: () => string;
17
+ pass: boolean;
18
+ };
19
+ export declare const toBeCachedByTheBrowserFor: typeof toBeCachedByTheBrowser;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const constants_1 = require("../../constants");
7
+ const getMessage_1 = __importDefault(require("../utils/getMessage"));
8
+ /**
9
+ * Matches the browser cache-control header in the response with an optional duration
10
+ *
11
+ * **Example**
12
+ * ```js
13
+ * expect(response).toBeCachedByTheBrowser()
14
+ * ...
15
+ * expect(response).toBeCachedByTheBrowser(60*60*24)
16
+ * ```
17
+ *
18
+ * @param {MockResponse} received The mocked response
19
+ * @param {Number} duration Optional - the duration (in seconds) the response is expected to be cached for
20
+ * @returns
21
+ */
22
+ function toBeCachedByTheBrowser(received, duration) {
23
+ const response = received;
24
+ const request = response.request;
25
+ const header = response.getHeader(constants_1.HTTP_HEADERS.cacheControl);
26
+ let pass = !!header;
27
+ if (header) {
28
+ // @ts-ignore
29
+ if (this.isNot) {
30
+ pass = !/no-cache/.test(header);
31
+ duration = 0;
32
+ }
33
+ else if (pass && duration) {
34
+ pass = new RegExp(`max-age=${duration}`).test(header);
35
+ }
36
+ }
37
+ return {
38
+ message: () => getMessage_1.default(
39
+ // @ts-ignore
40
+ this, `toBeCachedByTheBrowser${duration ? 'For' : ''}`, `'${request.path}' [[to]] be cached by the browser${duration ? ` for ${duration}ms` : ''}`, header),
41
+ pass,
42
+ };
43
+ }
44
+ exports.toBeCachedByTheBrowser = toBeCachedByTheBrowser;
45
+ exports.toBeCachedByTheBrowserFor = toBeCachedByTheBrowser;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Matches the edge cache-control header in the response with an optional duration
3
+ *
4
+ * **Example**
5
+ * ```js
6
+ * expect(response).toBeCachedByTheEdge()
7
+ * ...
8
+ * expect(response).toBeCachedByTheEdge(60*60*24)
9
+ * ```
10
+ *
11
+ * @param {MockResponse} received The mocked response
12
+ * @param {Number} duration Optional - the duration (in seconds) the response is expected to be cached for
13
+ * @returns
14
+ */
15
+ export declare function toBeCachedByTheEdge(received: any, duration?: number): {
16
+ message: () => string;
17
+ pass: boolean;
18
+ };
19
+ export declare const toBeCachedByTheEdgeFor: typeof toBeCachedByTheEdge;