@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,439 @@
1
+ import { PreloadRequestConfig } from './Preload';
2
+ import BackendOptions from './BackendOptions';
3
+ import PluginBase from '../plugins/PluginBase';
4
+ import PreloadRequests from './PreloadRequests';
5
+ import Request from './Request';
6
+ import Response from './Response';
7
+ import ResponseWriter from './ResponseWriter';
8
+ import RouteCriteria from './RouteCriteria';
9
+ import RouteGroup, { StaticOptions, BasicAuthOptions } from './RouteGroup';
10
+ import RouteGroupList from './RouteGroupList';
11
+ export interface RouterOptions {
12
+ /**
13
+ * If `true`, built in routes under /__layer0__/ will be not be added to the router.
14
+ */
15
+ excludeBuiltInRoutes?: boolean;
16
+ /**
17
+ * If `true`, duplicate queries in request will not be transformed to array
18
+ */
19
+ allowReqQueryDuplicates?: boolean;
20
+ }
21
+ /**
22
+ * A router.
23
+ */
24
+ export default class Router {
25
+ readonly routeGroups: RouteGroupList;
26
+ readonly preloadRequests: PreloadRequests;
27
+ readonly allowReqQueryDuplicates: boolean;
28
+ private readonly plugins;
29
+ private readonly destinations;
30
+ private nextRouterIndex;
31
+ private newRequestId?;
32
+ /**
33
+ * Index is used to determine the precedence of a router when routing rules
34
+ * have not resolved to a specific destination. The router with the lowest
35
+ * number wins.
36
+ * @private
37
+ *
38
+ */
39
+ private _index;
40
+ constructor(options?: RouterOptions);
41
+ /**
42
+ * Returns a manifest of all static assets to be served via router.static
43
+ * @private
44
+ */
45
+ getStaticAssetManifest(): {
46
+ [key: string]: string[];
47
+ };
48
+ /**
49
+ * Allows the lambda handler to add the __js__ backend in the cloud
50
+ * @private
51
+ * @param name
52
+ * @param value
53
+ */
54
+ setBackend(name: string, value: BackendOptions): this;
55
+ /**
56
+ * Constructs plugin and pushes it to registered plugins
57
+ * @param pluginInstance A plugin to use.
58
+ * @returns {Router} A self-reference, suitable for chaining.
59
+ */
60
+ use(pluginInstance: PluginBase): this;
61
+ /**
62
+ * Adds a named destination to which you can map traffic using the traffic shaping settings in your environment
63
+ * in Layer0 developer console
64
+ * @param name The name of the destination
65
+ * @param router A router to use when handling requests
66
+ * @returns {Router} A self-reference, suitable for chaining.
67
+ */
68
+ destination(name: string, router: Router): this;
69
+ /**
70
+ * Returns all plugins, including those registered on destination routers.
71
+ */
72
+ getPlugins(): PluginBase[];
73
+ /**
74
+ * Sets the index at which the router has been added to its parent router
75
+ * @private
76
+ * @param index
77
+ */
78
+ setIndex(index: number): void;
79
+ /**
80
+ * Returns the index at which the router has been added to its parent router
81
+ * @private
82
+ * @returns router's index
83
+ */
84
+ get index(): number;
85
+ /**
86
+ * Adds a RouteGroup to router and calls route register function for group.
87
+ * @private
88
+ * @param name Group name
89
+ * @param registerRoutesFn Group route register function
90
+ * @returns {Router} A self-reference, suitable for chaining.
91
+ */
92
+ group(name: string, registerRoutesFn: (group: RouteGroup) => void): this;
93
+ /**
94
+ * Adds a route matching all methods.
95
+ *
96
+ * Example:
97
+ *
98
+ * ```js
99
+ * new Router().match('/p/:productId', ({ cache, proxy }) => {
100
+ * cache({
101
+ * edge: {
102
+ * maxAgeSeconds: 60 * 60 * 24
103
+ * }
104
+ * })
105
+ *
106
+ * proxy('origin')
107
+ * })
108
+ * ```
109
+ *
110
+ * @param criteria Either the path as a string or an object with `path`, `method`, and `headers`.
111
+ * @param handler A handler function that will be called when the route is matched
112
+ * @returns {Router} A self-reference, suitable for chaining.
113
+ */
114
+ match(criteria: RouteCriteria | string, handler: RouteHandler): this;
115
+ /**
116
+ * Adds preload config for router
117
+ *
118
+ * ```js
119
+ * new Router().preload(
120
+ * async () => [{ path: '/foo', headers: { foo: 'bar' } }],
121
+ * [{ path: '/bar' }]
122
+ * )
123
+ * ```
124
+ *
125
+ * @param preloadOptions
126
+ */
127
+ prerender(...preloadOptions: Array<PreloadRequestConfig[] | (() => Promise<PreloadRequestConfig[]>) | (() => PreloadRequestConfig[])>): this;
128
+ /**
129
+ * Adds a route matching the given HTTP method.
130
+ *
131
+ * @param method HTTP method
132
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
133
+ * @param handler A handler function that will be called when the route is matched
134
+ * @private
135
+ */
136
+ private matchMethod;
137
+ /**
138
+ * Adds a route matching `HEAD` HTTP method.
139
+ *
140
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
141
+ * @param handler A handler function that will be called when the route is matched
142
+ * @returns {Router} A self-reference, suitable for chaining.
143
+ */
144
+ head(criteria: RouteCriteria | string, handler: RouteHandler): this;
145
+ /**
146
+ * Adds a route matching `GET` HTTP method.
147
+ *
148
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
149
+ * @param handler A handler function that will be called when the route is matched
150
+ * @returns {Router} A self-reference, suitable for chaining.
151
+ */
152
+ get(criteria: RouteCriteria | string, handler: RouteHandler): this;
153
+ /**
154
+ * Adds a route matching `POST` HTTP method.
155
+ *
156
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
157
+ * @param handler A handler function that will be called when the route is matched
158
+ * @returns {Router} A self-reference, suitable for chaining.
159
+ */
160
+ post(criteria: RouteCriteria | string, handler: RouteHandler): this;
161
+ /**
162
+ * Adds a route matching `DELETE` HTTP method.
163
+ *
164
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
165
+ * @param handler A handler function that will be called when the route is matched
166
+ * @returns {Router} A self-reference, suitable for chaining.
167
+ */
168
+ delete(criteria: RouteCriteria | string, handler: RouteHandler): this;
169
+ /**
170
+ * Adds a route matching `PUT` HTTP method.
171
+ *
172
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
173
+ * @param handler A handler function that will be called when the route is matched
174
+ * @returns {Router} A self-reference, suitable for chaining.
175
+ */
176
+ put(criteria: RouteCriteria | string, handler: RouteHandler): this;
177
+ /**
178
+ * Adds a route matching `PATCH` HTTP method.
179
+ *
180
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
181
+ * @param handler A handler function that will be called when the route is matched
182
+ * @returns {Router} A self-reference, suitable for chaining.
183
+ */
184
+ patch(criteria: RouteCriteria | string, handler: RouteHandler): this;
185
+ /**
186
+ * Adds a route matching `OPTIONS` HTTP method.
187
+ *
188
+ * @param criteria Either the path as a string or an object with `path`, `headers` and `cookies`.
189
+ * @param handler A handler function that will be called when the route is matched
190
+ * @returns {Router} A self-reference, suitable for chaining.
191
+ */
192
+ options(criteria: RouteCriteria | string, handler: RouteHandler): this;
193
+ /**
194
+ * Adds a route that will run if no other routes are matched
195
+ * @param handler A handler function that will be called when no other route is matched
196
+ * @returns A self-reference, suitable for chaining.
197
+ */
198
+ fallback(handler: RouteHandler): this;
199
+ /**
200
+ * Adds a route that matches all requests with internal error header.
201
+ * @param handler A handler function that will be called when the route is matched
202
+ * @returns {Router} A self-reference, suitable for chaining.
203
+ */
204
+ catch(error: RegExp | string | number, handler: RouteHandler): this;
205
+ /**
206
+ * Disables crawling of permalinks by setting the `x-robots-tag: noindex` response header
207
+ * for hosts matching layer0.link or layer0-perma.link.
208
+ *
209
+ * ```js
210
+ * new Router().noIndexPermalink()
211
+ * ```
212
+ *
213
+ * * @returns {Router} A self-reference, suitable for chaining.
214
+ */
215
+ noIndexPermalink(): this;
216
+ /**
217
+ * Checks headers for validity and updates them as needed.
218
+ *
219
+ * Notes:
220
+ * - If x-request-id is not present we generate it and later inject it into
221
+ * the response.
222
+ * - If accept-encoding includes gzip then we use it but eliminating everything else
223
+ * as we don't support other encodings. If there is no gzip in accept-encoding
224
+ * then we delete it entirely forcing upstream to return uncoded response.
225
+ * - We emulate the edge router by injecting the same headers it injects:
226
+ * - x-0-client-ip
227
+ * - x-forwarded-for
228
+ */
229
+ private processRequestHeaders;
230
+ /**
231
+ * Emulates edge by injecting device headers into the request prior to routing.
232
+ *
233
+ * Notes:
234
+ * - This code must be the same as the the generated edge router.
235
+ * - This code has been directly translated from ECL compiler
236
+ * - We emulate the edge router by injecting the same headers it injects:
237
+ * - x-0-device
238
+ * - x-0-vendor
239
+ * - x-0-browser
240
+ * - x-0-device-is-bot
241
+ */
242
+ private processRequestDeviceHeaders;
243
+ /**
244
+ * Emulates edge by injecting Geolocation headers into the request prior to routing.
245
+ * - x-0-geo-city
246
+ * - x-0-geo-country-code
247
+ * - x-0-geo-latitude
248
+ * - x-0-geo-longitude
249
+ * - x-0-geo-postal-code
250
+ */
251
+ private processRequestGeoHeaders;
252
+ /**
253
+ * Adds the `rawBody` (Buffer) and `body` (String) to the request
254
+ * @param req
255
+ */
256
+ private processRequestBody;
257
+ /**
258
+ * Checks if the number of user headers is within the limits.
259
+ *
260
+ * Notes:
261
+ * - User headers are all those that do not have `x-0-` prefix.
262
+ * - We check user headers counts in the router because in local
263
+ * development the router is running on "the edge" and we want to
264
+ * simulate the edge behavior (which actually has hard limits on
265
+ * header count - see `LAYER0_MAX_USER_HEADERS_ALLOWED` for more info)
266
+ */
267
+ private isUserHeaderCountWithinLimits;
268
+ /**
269
+ * Patches writeHead method of the response so that we can do any post-response work.
270
+ *
271
+ * Notes:
272
+ * - Injects response ID header when this same component has generated the request ID.
273
+ * All components that actually generate the request ID before processing the request
274
+ * or going upstream are then also responsible for sending back the request ID downstream.
275
+ * - Return status 542 when there are too many response headers.
276
+ *
277
+ * @param req The request
278
+ * @param res The response
279
+ */
280
+ private patchResWriteHead;
281
+ /**
282
+ * Handles a request, sending the response by running the handler for each matched route.
283
+ * @param req The request
284
+ * @param res The response
285
+ */
286
+ run: (req: Request, res: Response) => Promise<void>;
287
+ /**
288
+ * Both edge and @core/router have a built-in fallback that has the following rules:
289
+ *
290
+ * 1. On HTTP protocol return a 301 with the same request path in `location` header but on HTTPS
291
+ * protocol.
292
+ * 2. On HTTPS protocol return a 404.
293
+ *
294
+ * One complication is that in local development HTTPS does not exist - it is only emulated.
295
+ * Therefore in local development we could go into a redirect loop if the HTTP is emulated
296
+ * through the `local_layer0_emulate_http_protocol` cookie. There are a few options:
297
+ *
298
+ * 1. Always return 404 in local development.
299
+ * 2. If the cookie is present, issue 301 but unset the cookie in the response.
300
+ * 3. If the cookie is not present, return 301.
301
+ *
302
+ * We feel that the least surprising is simply always issuing 404 as that is also the original behavior.
303
+ *
304
+ * @param res
305
+ */
306
+ private builtInFallback;
307
+ /**
308
+ * Adds routes for all static assets in a directory tree.
309
+ *
310
+ * **Example**
311
+ *
312
+ * ```js
313
+ * router.static('public')
314
+ * ```
315
+ *
316
+ * To only serve files matching a particular pattern, use the `glob` options:
317
+ *
318
+ * ```js
319
+ * router.static('public', {
320
+ * glob: '*.css'
321
+ * })
322
+ * ```
323
+ *
324
+ * By default the path on which files are served corresponds to the path within the directory,
325
+ * so for example, `public/css/main.css` would be served at `'/css/main.css'`,
326
+ * you can override this using the `path` option:
327
+ *
328
+ * ```js
329
+ * router.static('public', {
330
+ * paths: file => ['/assets/ + file] // will serve public/css/main.css at /assets/css/main.css
331
+ * })
332
+ * ```
333
+ *
334
+ * You can add caching or other additional handler logic using the `handler` option:
335
+ *
336
+ * ```js
337
+ * router.static('public', {
338
+ * handler: (file) => ({ cache }) => {
339
+ * cache({
340
+ * browser: {
341
+ * maxAgeSeconds: 60 * 60
342
+ * },
343
+ * edge: {
344
+ * maxAgeSeconds: 60 * 60 * 24,
345
+ * staleWhileRevalidateSeconds: 60 * 60
346
+ * }
347
+ * })
348
+ * }
349
+ * })
350
+ * ```
351
+ *
352
+ * @param sourcePath The path to a directory containing static assets relative to the root of your project.
353
+ * @param options
354
+ * @returns A self-reference, suitable for chaining.
355
+ */
356
+ static(sourcePath: string, options?: StaticOptions): this;
357
+ /**
358
+ * Shorthand for adding GraphQL body matching
359
+ *
360
+ * Examples:
361
+ *
362
+ * // by default the path is graphql
363
+ * new Router().graphqlOperation("GetRates")
364
+ *
365
+ * or
366
+ *
367
+ * // with optional non-default path
368
+ * new Router().graphqlOperation({ path: "/gql-api", name: "GetRates" })
369
+ *
370
+ * @param criteria Either the operation name as a string or an object with `path`, `name`.
371
+ * @param handler A handler function that will be called when the route is matched
372
+ *
373
+ * @returns A self-reference, suitable for chaining.
374
+ */
375
+ graphqlOperation(criteria: string | RegExp | {
376
+ path: string;
377
+ name: string | RegExp;
378
+ }, handler: RouteHandler): this;
379
+ /**
380
+ * Adds Basic Authentication.
381
+ *
382
+ * **example**
383
+ *
384
+ * ```js
385
+ * router
386
+ * .requireBasicAuth({ username: 'user', password: 's3cr3t!' })
387
+ * // ...include additional routes below...
388
+ * ```
389
+ *
390
+ * You can also require basic auth for a subset of URLs using the `criteria` option:
391
+ *
392
+ * ```js
393
+ * router
394
+ * .requireBasicAuth({ criteria: '/secret/:path*', username: 'user', password: 's3cr3t!' })
395
+ * // ...include additional routes below...
396
+ * ```
397
+ *
398
+ * The criteria option accepts a path pattern as a string, or a RouteCriteria object.
399
+ *
400
+ * @param options
401
+ * @returns A self-reference, suitable for chaining.
402
+ */
403
+ requireBasicAuth(options: BasicAuthOptions): this;
404
+ /**
405
+ * Returns edge config from current router
406
+ * @private
407
+ */
408
+ createEdgeConfig(): Promise<import("../types").EdgeConfig>;
409
+ /**
410
+ * Returns preload config from current router
411
+ * @private
412
+ */
413
+ createPreloadConfig(): Promise<import("./Preload").CompiledPreloadOptions>;
414
+ /**
415
+ * @private
416
+ */
417
+ getDestinations(): {
418
+ [name: string]: Router;
419
+ };
420
+ /**
421
+ * @private
422
+ */
423
+ getRouteGroups(): RouteGroupList;
424
+ /**
425
+ * Returns a string summarizing all routes for debugging purposes. Don't rely on the format
426
+ * of this string as we may improve it over time.
427
+ */
428
+ toString(): string;
429
+ /**
430
+ * Returns true if the request came through Layer0 edge.
431
+ *
432
+ * Notes:
433
+ * - If the request came through Layer0 edge then `x-0-version` has been injected.
434
+ *
435
+ * @param req The request
436
+ */
437
+ static isRequestFromEdge(req: Request): boolean;
438
+ }
439
+ export declare type RouteHandler = (respond: ResponseWriter) => void;