@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.
- package/node_modules/@layer0/core/README.md +50 -0
- package/node_modules/@layer0/core/build.d.ts +5 -0
- package/node_modules/@layer0/core/build.js +17 -0
- package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
- package/node_modules/@layer0/core/cache/Cache.js +138 -0
- package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
- package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
- package/node_modules/@layer0/core/config.d.ts +53 -0
- package/node_modules/@layer0/core/config.js +113 -0
- package/node_modules/@layer0/core/constants.d.ts +214 -0
- package/node_modules/@layer0/core/constants.js +216 -0
- package/node_modules/@layer0/core/context.d.ts +38 -0
- package/node_modules/@layer0/core/context.js +98 -0
- package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
- package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
- package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
- package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
- package/node_modules/@layer0/core/deploy/index.js +6 -0
- package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/listSources.js +18 -0
- package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
- package/node_modules/@layer0/core/deploy/paths.js +33 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
- package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
- package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
- package/node_modules/@layer0/core/dev/index.d.ts +3 -0
- package/node_modules/@layer0/core/dev/index.js +6 -0
- package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
- package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
- package/node_modules/@layer0/core/environment.d.ts +24 -0
- package/node_modules/@layer0/core/environment.js +42 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
- package/node_modules/@layer0/core/index.d.ts +3 -0
- package/node_modules/@layer0/core/index.js +9 -0
- package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
- package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
- package/node_modules/@layer0/core/init/index.d.ts +2 -0
- package/node_modules/@layer0/core/init/index.js +6 -0
- package/node_modules/@layer0/core/init/init.d.ts +5 -0
- package/node_modules/@layer0/core/init/init.js +17 -0
- package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
- package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
- package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
- package/node_modules/@layer0/core/lambda/handler.js +91 -0
- package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
- package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
- package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
- package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
- package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
- package/node_modules/@layer0/core/package.json +132 -0
- package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
- package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
- package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
- package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
- package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
- package/node_modules/@layer0/core/router/Backend.js +176 -0
- package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
- package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
- package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
- package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
- package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
- package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
- package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
- package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
- package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
- package/node_modules/@layer0/core/router/Groups.js +21 -0
- package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
- package/node_modules/@layer0/core/router/Headers.js +2 -0
- package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
- package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
- package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
- package/node_modules/@layer0/core/router/Preload.js +2 -0
- package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
- package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
- package/node_modules/@layer0/core/router/Request.d.ts +74 -0
- package/node_modules/@layer0/core/router/Request.js +2 -0
- package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
- package/node_modules/@layer0/core/router/RequestContext.js +11 -0
- package/node_modules/@layer0/core/router/Response.d.ts +55 -0
- package/node_modules/@layer0/core/router/Response.js +2 -0
- package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
- package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
- package/node_modules/@layer0/core/router/Route.d.ts +124 -0
- package/node_modules/@layer0/core/router/Route.js +280 -0
- package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
- package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
- package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
- package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
- package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
- package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
- package/node_modules/@layer0/core/router/Router.d.ts +439 -0
- package/node_modules/@layer0/core/router/Router.js +907 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
- package/node_modules/@layer0/core/router/index.d.ts +11 -0
- package/node_modules/@layer0/core/router/index.js +17 -0
- package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
- package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
- package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
- package/node_modules/@layer0/core/router/loadRouter.js +29 -0
- package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
- package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
- package/node_modules/@layer0/core/router/stream.d.ts +12 -0
- package/node_modules/@layer0/core/router/stream.js +30 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
- package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
- package/node_modules/@layer0/core/router/validateWriter.js +120 -0
- package/node_modules/@layer0/core/serverless.yml +30 -0
- package/node_modules/@layer0/core/source.d.ts +9 -0
- package/node_modules/@layer0/core/source.js +17 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
- package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
- package/node_modules/@layer0/core/test-utils/index.js +11 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
- package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
- package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
- package/node_modules/@layer0/core/timing.d.ts +115 -0
- package/node_modules/@layer0/core/timing.js +200 -0
- package/node_modules/@layer0/core/transform/index.d.ts +1 -0
- package/node_modules/@layer0/core/transform/index.js +4 -0
- package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
- package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
- package/node_modules/@layer0/core/types.d.ts +102 -0
- package/node_modules/@layer0/core/types.js +30 -0
- package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
- package/node_modules/@layer0/core/utils/Tasks.js +80 -0
- package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
- package/node_modules/@layer0/core/utils/Validator.js +178 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
- package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
- package/node_modules/@layer0/core/utils/decode.js +44 -0
- package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
- package/node_modules/@layer0/core/utils/esImport.js +9 -0
- package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
- package/node_modules/@layer0/core/utils/fs.js +7 -0
- package/node_modules/@layer0/core/utils/get.d.ts +6 -0
- package/node_modules/@layer0/core/utils/get.js +19 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
- package/node_modules/@layer0/core/utils/has.d.ts +6 -0
- package/node_modules/@layer0/core/utils/has.js +15 -0
- package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
- package/node_modules/@layer0/core/utils/identity.js +12 -0
- package/node_modules/@layer0/core/utils/index.d.ts +1 -0
- package/node_modules/@layer0/core/utils/index.js +4 -0
- package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
- package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
- package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
- package/node_modules/@layer0/core/utils/isString.js +6 -0
- package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
- package/node_modules/@layer0/core/utils/logo.js +27 -0
- package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
- package/node_modules/@layer0/core/utils/mapValues.js +16 -0
- package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
- package/node_modules/@layer0/core/utils/minBy.js +41 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
- package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
- package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
- package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
- package/node_modules/@layer0/core/utils/ports.js +7 -0
- package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
- package/node_modules/@layer0/core/utils/readBody.js +15 -0
- package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
- package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
- package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
- package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
- package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
- package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
- package/node_modules/@layer0/core/utils/set.d.ts +10 -0
- package/node_modules/@layer0/core/utils/set.js +21 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
- package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
- package/node_modules/@layer0/core/utils/toLower.js +9 -0
- package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
- package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
- package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
- package/node_modules/@layer0/core/utils/watch.js +17 -0
- 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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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;
|