@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,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("./constants");
4
+ const context_1 = require("./context");
5
+ exports.NOT_ENDED_VALUE = 'na';
6
+ class InternalTiming {
7
+ /**
8
+ * @param name The name of the timing component that will be reported in the `x-0-user-t` header
9
+ */
10
+ constructor(name, internal = true) {
11
+ /**
12
+ * The number of milliseconds elapsed
13
+ */
14
+ this.duration = 0;
15
+ /**
16
+ * Set to true if the timing has been ended
17
+ */
18
+ this.ended = false;
19
+ this.name = name;
20
+ const timings = internal ? internalTimings() : userTimings();
21
+ timings.push(this);
22
+ }
23
+ /**
24
+ * Starts the timing.
25
+ * @returns A self-reference, suitable for chaining
26
+ */
27
+ start() {
28
+ this.startTime = new Date();
29
+ this.ended = false;
30
+ return this;
31
+ }
32
+ /**
33
+ * Sets the discrete value for this timing
34
+ * @param discreteValue
35
+ * @returns A self-reference, suitable for chaining
36
+ */
37
+ set(discreteValue) {
38
+ this.discreteValue = discreteValue;
39
+ return this;
40
+ }
41
+ /**
42
+ * Ends the timing.
43
+ * @returns A self-reference, suitable for chaining
44
+ */
45
+ end() {
46
+ if (!this.startTime) {
47
+ console.warn(`Timing ${this.name} not started.`);
48
+ return this;
49
+ }
50
+ this.ended = true;
51
+ this.duration += new Date().getTime() - this.startTime.getTime();
52
+ return this;
53
+ }
54
+ /**
55
+ * Convenience method that is the same as `end`, but meant to indicate
56
+ * that the timing may be resumed later
57
+ */
58
+ pause() {
59
+ return this.end();
60
+ }
61
+ /**
62
+ * Convenience method that is the same as `start`, but meant to indicate
63
+ * that the timing has been paused.
64
+ */
65
+ resume() {
66
+ return this.start();
67
+ }
68
+ /**
69
+ * Gets the value of the timing for response headers. Will be 'na' if not started, otherwise
70
+ * the numeric duration in milliseconds.
71
+ */
72
+ get value() {
73
+ if (this.discreteValue != null) {
74
+ return this.discreteValue;
75
+ }
76
+ else {
77
+ return this.ended ? this.duration : exports.NOT_ENDED_VALUE;
78
+ }
79
+ }
80
+ }
81
+ exports.InternalTiming = InternalTiming;
82
+ /**
83
+ * A higher order function that wraps the provided function in a request context with user
84
+ * and internal timings reset
85
+ * @private
86
+ * @param handler
87
+ */
88
+ function withTimings(handler) {
89
+ return (...args) => {
90
+ return context_1.withContext(() => {
91
+ return handler(...args);
92
+ });
93
+ };
94
+ }
95
+ exports.withTimings = withTimings;
96
+ /**
97
+ * Returns the value of the internal timing with the specified name
98
+ * @private
99
+ * @param name The name of an internal timing, for example "ecc"
100
+ */
101
+ function getInternalTiming(name) {
102
+ var _a;
103
+ return (_a = internalTimings().find(t => t.name === name)) === null || _a === void 0 ? void 0 : _a.value;
104
+ }
105
+ exports.getInternalTiming = getInternalTiming;
106
+ /**
107
+ * Returns the internal timings from the current request context
108
+ * @private
109
+ */
110
+ function internalTimings() {
111
+ return context_1.get('internalTimings', []);
112
+ }
113
+ /**
114
+ * Returns the user timings from the current request context
115
+ * @private
116
+ */
117
+ function userTimings() {
118
+ return context_1.get('userTimings', []);
119
+ }
120
+ /**
121
+ * Adds x-0-t, x-0-user-t, and server-timing headers to the response
122
+ * @private
123
+ * @param response
124
+ */
125
+ function addTimings(response) {
126
+ const userT = userTimings();
127
+ const internalT = internalTimings();
128
+ if (userT.length) {
129
+ response.setHeader(constants_1.HTTP_HEADERS.x0UserT, getTimingsResponseHeader(userT));
130
+ response.setHeader(constants_1.HTTP_HEADERS.serverTiming, appendServerTimings(response));
131
+ }
132
+ if (internalT.length) {
133
+ response.setHeader(constants_1.HTTP_HEADERS.x0T, getTimingsResponseHeader(internalT));
134
+ }
135
+ }
136
+ exports.addTimings = addTimings;
137
+ /**
138
+ * Gets the value of the x-0-user-t header.
139
+ * @private
140
+ */
141
+ function getTimingsResponseHeader(timings) {
142
+ return timings.map(t => `${t.name}=${t.value}`).join(',');
143
+ }
144
+ /**
145
+ * Returns the user timings in server-timing response header format
146
+ * @private
147
+ */
148
+ function appendServerTimings(response) {
149
+ const existingHeader = response.getHeader(constants_1.HTTP_HEADERS.serverTiming);
150
+ const timings = userTimings().map(t => `${t.name};dur=${t.value}`);
151
+ if (Array.isArray(existingHeader)) {
152
+ timings.push(...existingHeader);
153
+ }
154
+ else if (existingHeader) {
155
+ timings.push(existingHeader);
156
+ }
157
+ return timings.join(', ');
158
+ }
159
+ /**
160
+ * Allows you to track the performance of your code and asynchronous operations such as fetches.
161
+ * Timings will be returned as a comma delimited list in the `x-0-user-t` header.
162
+ *
163
+ * ** Example **
164
+ *
165
+ * ```js
166
+ * import Timing from '@layer0/core/timing'
167
+ *
168
+ * const timing = new Timing('fetch').start()
169
+ * const result = await fetch('http://my-api.com/products/1')
170
+ * timing.end() // will result in `x-0-user-t: fetch=(millis)` response header
171
+ * ```
172
+ *
173
+ * If a timing is started but not finished by the time the response is sent, the value will be `na`.
174
+ */
175
+ class Timing extends InternalTiming {
176
+ constructor(name) {
177
+ super(name, false);
178
+ }
179
+ }
180
+ exports.default = Timing;
181
+ /**
182
+ * Names for x-0-t components
183
+ */
184
+ var InternalNames;
185
+ (function (InternalNames) {
186
+ InternalNames["edgeCache"] = "ecc";
187
+ InternalNames["transformRequest"] = "wa";
188
+ InternalNames["transformResponse"] = "wz";
189
+ InternalNames["routeMatching"] = "wr";
190
+ InternalNames["proxying"] = "wp";
191
+ })(InternalNames = exports.InternalNames || (exports.InternalNames = {}));
192
+ /**
193
+ * Values for edgeCache component of x-0-t
194
+ */
195
+ var CacheValue;
196
+ (function (CacheValue) {
197
+ CacheValue["hit"] = "hit";
198
+ CacheValue["pass"] = "pass";
199
+ CacheValue["cached"] = "cached";
200
+ })(CacheValue = exports.CacheValue || (exports.CacheValue = {}));
@@ -0,0 +1 @@
1
+ export { default as transformMethod } from './transformMethod';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var transformMethod_1 = require("./transformMethod");
4
+ exports.transformMethod = transformMethod_1.default;
@@ -0,0 +1,40 @@
1
+ import Request from '../router/Request';
2
+ /**
3
+ * A function for `transformRequest` that alters the request method to `toMethod`.
4
+ * The request body is set to the value of the `pref_layer0_body` query parameter.
5
+ *
6
+ * **Example**
7
+ *
8
+ * ```js
9
+ * import { Router } from '@layer0/core/router'
10
+ * import { transformMethod } from '@layer0/core/transform'
11
+ *
12
+ * const cacheConfig = {
13
+ * edge: {
14
+ * maxAgeSeconds: 60 * 60 * 24,
15
+ * staleWhileRevalidateSeconds: 60 * 60
16
+ * },
17
+ * browser: {
18
+ * serviceWorkerSeconds: 60 * 60 * 24,
19
+ * convertToGet: true // convert POSTs to GETs so we can prefetch and cache them
20
+ * }
21
+ * }
22
+ *
23
+ * export default new Router()
24
+ * // When the request is a GET, convert it to post using serverless compute and cache the result
25
+ * .get('/some-post-path', ({ cache, proxy }) => {
26
+ * cache(cacheConfig)
27
+ * proxy('origin', {
28
+ * transformRequest: transformMethod('post')
29
+ * })
30
+ * })
31
+ * // When the request is a POST, forward it to origin from the edge without using serverless compute
32
+ * .post('/some-post-path', ({ cache, proxy }) => {
33
+ * cache(cacheConfig)
34
+ * proxy('origin')
35
+ * })
36
+ * ```
37
+ *
38
+ * @param toMethod The method to to set
39
+ */
40
+ export default function transformMethod(toMethod: string): (request: Request) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ /**
5
+ * A function for `transformRequest` that alters the request method to `toMethod`.
6
+ * The request body is set to the value of the `pref_layer0_body` query parameter.
7
+ *
8
+ * **Example**
9
+ *
10
+ * ```js
11
+ * import { Router } from '@layer0/core/router'
12
+ * import { transformMethod } from '@layer0/core/transform'
13
+ *
14
+ * const cacheConfig = {
15
+ * edge: {
16
+ * maxAgeSeconds: 60 * 60 * 24,
17
+ * staleWhileRevalidateSeconds: 60 * 60
18
+ * },
19
+ * browser: {
20
+ * serviceWorkerSeconds: 60 * 60 * 24,
21
+ * convertToGet: true // convert POSTs to GETs so we can prefetch and cache them
22
+ * }
23
+ * }
24
+ *
25
+ * export default new Router()
26
+ * // When the request is a GET, convert it to post using serverless compute and cache the result
27
+ * .get('/some-post-path', ({ cache, proxy }) => {
28
+ * cache(cacheConfig)
29
+ * proxy('origin', {
30
+ * transformRequest: transformMethod('post')
31
+ * })
32
+ * })
33
+ * // When the request is a POST, forward it to origin from the edge without using serverless compute
34
+ * .post('/some-post-path', ({ cache, proxy }) => {
35
+ * cache(cacheConfig)
36
+ * proxy('origin')
37
+ * })
38
+ * ```
39
+ *
40
+ * @param toMethod The method to to set
41
+ */
42
+ function transformMethod(toMethod) {
43
+ return (request) => {
44
+ if (request.method !== toMethod) {
45
+ const url = new URL(`http://dummy.com${request.url}`);
46
+ // convert the request to a post
47
+ request.method = toMethod;
48
+ // get the post body from body query param
49
+ request.body = url.searchParams.get(constants_1.POST_BODY_QUERY_PARAM) || '';
50
+ // the backend proxy is now using rawBody property, so we need to create new Buffer with content of body
51
+ request.rawBody = Buffer.from(request.body, 'utf8');
52
+ // remove body from the URL
53
+ url.searchParams.delete(constants_1.POST_BODY_QUERY_PARAM);
54
+ request.url = url.pathname + url.search;
55
+ }
56
+ };
57
+ }
58
+ exports.default = transformMethod;
@@ -0,0 +1,102 @@
1
+ import BackendOptions from './router/BackendOptions';
2
+ export interface EdgeConfig {
3
+ version: string;
4
+ backends: BackendOptions[];
5
+ destinations: EdgeDestination[];
6
+ }
7
+ export interface EdgeDestination {
8
+ index: number;
9
+ routes: EdgeRule[];
10
+ errorRoutes: EdgeRule[];
11
+ }
12
+ export interface EdgeRule {
13
+ path?: string;
14
+ matchProtocolJavaScriptRegExpSource?: string;
15
+ match?: (EdgeRegexMatcher | EdgeBodyMatcher)[];
16
+ route?: EdgeRoute;
17
+ cache?: EdgeCacheConfig;
18
+ transform: {
19
+ request: EdgeTransform[];
20
+ upstreamResponse: EdgeTransform[];
21
+ response: EdgeTransform[];
22
+ };
23
+ jwtVerification?: JwtVerification;
24
+ }
25
+ export interface EdgeRegexMatcher {
26
+ value: string;
27
+ matchRegex: string | null;
28
+ }
29
+ export interface EdgeBodyMatcher {
30
+ matchBody: string;
31
+ }
32
+ export interface EdgeRoute {
33
+ action: string;
34
+ statusCode?: number;
35
+ statusMessage?: string;
36
+ backend?: string;
37
+ content?: string;
38
+ fallbackToCompute?: boolean;
39
+ loadingPage?: PathTransform;
40
+ expiresSeconds?: number;
41
+ fsPath?: string[];
42
+ fsExclude?: string[];
43
+ jwtVerification?: JwtVerification;
44
+ disableAutoPublish?: boolean;
45
+ }
46
+ export interface EdgeCacheConfig {
47
+ disabled?: boolean;
48
+ maxAgeSeconds?: number;
49
+ staleWhileRevalidateSeconds?: number;
50
+ customKey?: any;
51
+ forcePrivateCaching?: boolean;
52
+ }
53
+ export interface PathTransform {
54
+ valueRegex?: string;
55
+ replaceValue?: string;
56
+ }
57
+ /**
58
+ * @typedef {number} JwtAlgo
59
+ *
60
+ * JwtAlgos are specified in the "JSON Web Algorithms" RFC #7518
61
+ *
62
+ * @enum
63
+ */
64
+ export declare enum JwtAlgo {
65
+ /** HMAC using SHA-256, symmetric */
66
+ HS256 = "HS256",
67
+ /** HMAC using SHA-384, symmetric */
68
+ HS384 = "HS384",
69
+ /** HMAC using SHA-512, symmetric */
70
+ HS512 = "HS512",
71
+ /** RSASSA-PKCS1-v1_5 using SHA-256, asymmetric, RSA */
72
+ RS256 = "RS256",
73
+ /** RSASSA-PKCS1-v1_5 using SHA-384, asymmetric, RSA */
74
+ RS384 = "RS384",
75
+ /** RSASSA-PKCS1-v1_5 using SHA-512, asymmetric, RSA */
76
+ RS512 = "RS512",
77
+ /** ECDSA using P-256 and SHA-256, asymmetric, ECDSA */
78
+ ES256 = "ES256",
79
+ /** ECDSA using P-384 and SHA-384, asymmetric, ECDSA */
80
+ ES384 = "ES384",
81
+ /** ECDSA using P-512 and SHA-512, asymmetric, ECDSA */
82
+ ES512 = "ES512"
83
+ }
84
+ /**
85
+ * @ignore
86
+ *
87
+ * (See ResponseWriter.VerifyJwtOptions)
88
+ */
89
+ export interface JwtVerification {
90
+ algo: JwtAlgo;
91
+ secret: String;
92
+ header?: String;
93
+ cookie?: String;
94
+ redirectExpiredAbsent?: String;
95
+ redirectInvalid?: String;
96
+ returnUrlParamName?: String;
97
+ }
98
+ export interface EdgeTransform extends PathTransform {
99
+ action: string;
100
+ name?: string;
101
+ value?: string;
102
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * @typedef {number} JwtAlgo
5
+ *
6
+ * JwtAlgos are specified in the "JSON Web Algorithms" RFC #7518
7
+ *
8
+ * @enum
9
+ */
10
+ var JwtAlgo;
11
+ (function (JwtAlgo) {
12
+ /** HMAC using SHA-256, symmetric */
13
+ JwtAlgo["HS256"] = "HS256";
14
+ /** HMAC using SHA-384, symmetric */
15
+ JwtAlgo["HS384"] = "HS384";
16
+ /** HMAC using SHA-512, symmetric */
17
+ JwtAlgo["HS512"] = "HS512";
18
+ /** RSASSA-PKCS1-v1_5 using SHA-256, asymmetric, RSA */
19
+ JwtAlgo["RS256"] = "RS256";
20
+ /** RSASSA-PKCS1-v1_5 using SHA-384, asymmetric, RSA */
21
+ JwtAlgo["RS384"] = "RS384";
22
+ /** RSASSA-PKCS1-v1_5 using SHA-512, asymmetric, RSA */
23
+ JwtAlgo["RS512"] = "RS512";
24
+ /** ECDSA using P-256 and SHA-256, asymmetric, ECDSA */
25
+ JwtAlgo["ES256"] = "ES256";
26
+ /** ECDSA using P-384 and SHA-384, asymmetric, ECDSA */
27
+ JwtAlgo["ES384"] = "ES384";
28
+ /** ECDSA using P-512 and SHA-512, asymmetric, ECDSA */
29
+ JwtAlgo["ES512"] = "ES512";
30
+ })(JwtAlgo = exports.JwtAlgo || (exports.JwtAlgo = {}));
@@ -0,0 +1,32 @@
1
+ export default class Tasks {
2
+ private readonly _tasks;
3
+ private _resolveHandler;
4
+ private _errorHandler;
5
+ /**
6
+ * Adds a task to taks array that can be resolved with tasks.resolve()
7
+ *
8
+ * @param tasks List of tasks to finish
9
+ */
10
+ add(...tasks: (Promise<any> | any)[]): Tasks;
11
+ /**
12
+ * Resolve Handler that will be called per each task with resolved value
13
+ *
14
+ * @param handler
15
+ */
16
+ onTaskDone(handler: Function): this;
17
+ /**
18
+ * Error Handler that will be called per each task and can be useful
19
+ * for ignoring the specific errors
20
+ *
21
+ * @param errorHandler
22
+ */
23
+ onTaskError(errorHandler: Function): this;
24
+ /**
25
+ * Finishes all tasks
26
+ */
27
+ resolve(): Promise<any[]>;
28
+ /**
29
+ * Returns list of tasks that are converted into promises | functions
30
+ */
31
+ private _convertTasksToPromises;
32
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Tasks {
4
+ constructor() {
5
+ this._tasks = [];
6
+ this._resolveHandler = Function.prototype;
7
+ this._errorHandler = (err) => {
8
+ throw err;
9
+ };
10
+ }
11
+ /**
12
+ * Adds a task to taks array that can be resolved with tasks.resolve()
13
+ *
14
+ * @param tasks List of tasks to finish
15
+ */
16
+ add(...tasks) {
17
+ this._tasks.push(...tasks);
18
+ return this;
19
+ }
20
+ /**
21
+ * Resolve Handler that will be called per each task with resolved value
22
+ *
23
+ * @param handler
24
+ */
25
+ onTaskDone(handler) {
26
+ this._resolveHandler = handler;
27
+ return this;
28
+ }
29
+ /**
30
+ * Error Handler that will be called per each task and can be useful
31
+ * for ignoring the specific errors
32
+ *
33
+ * @param errorHandler
34
+ */
35
+ onTaskError(errorHandler) {
36
+ this._errorHandler = errorHandler;
37
+ return this;
38
+ }
39
+ /**
40
+ * Finishes all tasks
41
+ */
42
+ resolve() {
43
+ const promises = this._convertTasksToPromises().map((task, i) => {
44
+ return task
45
+ .then((res) => {
46
+ this._resolveHandler(res);
47
+ return res;
48
+ })
49
+ .catch((err) => {
50
+ return this._errorHandler(err);
51
+ });
52
+ });
53
+ return Promise.all(promises);
54
+ }
55
+ /**
56
+ * Returns list of tasks that are converted into promises | functions
57
+ */
58
+ _convertTasksToPromises() {
59
+ return this._tasks.map(task => {
60
+ if (typeof task !== 'function') {
61
+ return Promise.resolve(task);
62
+ }
63
+ // Run the task and check if it returns a promise
64
+ try {
65
+ const taskResult = task();
66
+ if (taskResult instanceof Promise) {
67
+ return taskResult;
68
+ }
69
+ // sync function results
70
+ return Promise.resolve(taskResult);
71
+ }
72
+ catch (e) {
73
+ // Return a error promise if sync task fails
74
+ // This allows to ignore some errors with error handler
75
+ return Promise.reject(e);
76
+ }
77
+ });
78
+ }
79
+ }
80
+ exports.default = Tasks;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * An object used to validate an layer0 config.
3
+ *
4
+ * Example:
5
+ * ```js
6
+ * Validator.validateLayer0FileConfiguration(config)
7
+ * ```
8
+ */
9
+ declare class Validator {
10
+ /**
11
+ * Validates `layer0.config.js`. If the config is validated, it is returned; otherwise,
12
+ * an error is thrown.
13
+ * @param config Loaded layer0 configuration
14
+ * @returns The validated config
15
+ */
16
+ static validateLayer0FileConfiguration(config: any): any;
17
+ }
18
+ export default Validator;