@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,272 @@
|
|
|
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 Groups_1 = __importDefault(require("./Groups"));
|
|
7
|
+
const cookie_1 = require("cookie");
|
|
8
|
+
exports.CUSTOM_CACHE_KEY_ACTIONS = {
|
|
9
|
+
blacklistAll: 'blacklist-all-query-parameters',
|
|
10
|
+
blacklistSome: 'blacklist-some-query-parameters',
|
|
11
|
+
whitelistSome: 'whitelist-some-query-parameters',
|
|
12
|
+
addValue: 'add-value',
|
|
13
|
+
removeMethod: 'remove-method',
|
|
14
|
+
removeBody: 'remove-body',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Allows you to split or normalize the cache space for a given route. Common use cases include:
|
|
18
|
+
*
|
|
19
|
+
* - serving multiple variants of the same URL based on a currency and/or language cookie.
|
|
20
|
+
* - caching different responses based on device type
|
|
21
|
+
* - ignoring all but a specific set of query parameters when looking up a response from the cache.
|
|
22
|
+
*
|
|
23
|
+
* **Example**
|
|
24
|
+
*
|
|
25
|
+
* ```js
|
|
26
|
+
* import { Router, CustomCacheKey } from '@layer0/core/router'
|
|
27
|
+
*
|
|
28
|
+
* new Router()
|
|
29
|
+
* .match('/some-path', ({ cache }) => {
|
|
30
|
+
* cache({
|
|
31
|
+
* key: new CustomCacheKey()
|
|
32
|
+
* .excludeAllQueryParametersExcept('color', 'size')
|
|
33
|
+
* .addCookie('currency')
|
|
34
|
+
* .addCookie('location', cookie => {
|
|
35
|
+
* cookie.group('na').byPattern('us|ca')
|
|
36
|
+
* cookie.group('eur').byPattern('de|fr|ee')
|
|
37
|
+
* }),
|
|
38
|
+
* edge: {
|
|
39
|
+
* maxAgeSeconds: 60 * 60
|
|
40
|
+
* }
|
|
41
|
+
* })
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
class CustomCacheKey {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.config = [];
|
|
48
|
+
this.actions = [];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a copy of the cache key.
|
|
52
|
+
*/
|
|
53
|
+
clone() {
|
|
54
|
+
const newKey = new CustomCacheKey();
|
|
55
|
+
newKey.actions = this.actions;
|
|
56
|
+
newKey.config = this.config;
|
|
57
|
+
return newKey;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Excludes the entire query string from the cache key.
|
|
61
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
62
|
+
*/
|
|
63
|
+
excludeAllQueryParameters() {
|
|
64
|
+
this.config.push({ action: exports.CUSTOM_CACHE_KEY_ACTIONS.blacklistAll });
|
|
65
|
+
this.actions.push((key, srcRequest) => {
|
|
66
|
+
key.query = {};
|
|
67
|
+
});
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Excludes the provided query parameters from the cache key. All other parameters
|
|
72
|
+
* will still be part of the cache key. We also refer to this as "blacklisting" query parameters.
|
|
73
|
+
* @param names The names of the query parameters to blacklist
|
|
74
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
75
|
+
*/
|
|
76
|
+
excludeQueryParameters(...names) {
|
|
77
|
+
this.config.push({
|
|
78
|
+
action: exports.CUSTOM_CACHE_KEY_ACTIONS.blacklistSome,
|
|
79
|
+
names,
|
|
80
|
+
});
|
|
81
|
+
this.actions.push((key, srcRequest) => {
|
|
82
|
+
for (let name of names) {
|
|
83
|
+
delete key.query[name];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Excludes all query parameters except those provided from the cache key. We also refer to
|
|
90
|
+
* this as "whitelisting" query parameters. We recommend using this method over `excludeQueryParameters`
|
|
91
|
+
* as it's difficult to know all of the query parameters your application might receive and unexpected
|
|
92
|
+
* query parameters can lead to significantly lower cache hit rates.
|
|
93
|
+
* @param names The names of the query parameters to whitelist
|
|
94
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
95
|
+
*/
|
|
96
|
+
excludeAllQueryParametersExcept(...names) {
|
|
97
|
+
this.config.push({
|
|
98
|
+
action: exports.CUSTOM_CACHE_KEY_ACTIONS.whitelistSome,
|
|
99
|
+
names,
|
|
100
|
+
});
|
|
101
|
+
this.actions.push((key, srcRequest) => {
|
|
102
|
+
const toKeep = new Set(names);
|
|
103
|
+
for (let name in key.query) {
|
|
104
|
+
if (!toKeep.has(name)) {
|
|
105
|
+
delete key.query[name];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Adds a request header to the cache key.
|
|
113
|
+
* This will have no effect on service worker cache.
|
|
114
|
+
* @param name The name of the request header
|
|
115
|
+
* @param createGroups A function that accepts a `Groups` instance and calls `groups.group(name)` to group multiple values into a single cache key component
|
|
116
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
117
|
+
*/
|
|
118
|
+
addHeader(name, createGroups) {
|
|
119
|
+
this.actions.push((key, srcRequest) => {
|
|
120
|
+
let values = srcRequest.headers[name];
|
|
121
|
+
if (!Array.isArray(values)) {
|
|
122
|
+
values = [values];
|
|
123
|
+
}
|
|
124
|
+
if (createGroups) {
|
|
125
|
+
key.headers[name] = this.createGroupedValue(createGroups, values);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
key.headers[name] = values;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return this.addValue(`\${req:${name}}`, createGroups);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Removes the HTTP method from the cache key.
|
|
135
|
+
* @return A self-reference, suitable for chaining.
|
|
136
|
+
*/
|
|
137
|
+
removeMethod() {
|
|
138
|
+
this.actions.push((key, srcRequest) => {
|
|
139
|
+
key.method = undefined;
|
|
140
|
+
});
|
|
141
|
+
this.config.push({
|
|
142
|
+
action: exports.CUSTOM_CACHE_KEY_ACTIONS.removeMethod,
|
|
143
|
+
});
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Removes the HTTP body from the cache key.
|
|
148
|
+
* @return A self-reference, suitable for chaining.
|
|
149
|
+
*/
|
|
150
|
+
removeBody() {
|
|
151
|
+
this.actions.push((key, srcRequest) => {
|
|
152
|
+
key.body = undefined;
|
|
153
|
+
});
|
|
154
|
+
this.config.push({
|
|
155
|
+
action: exports.CUSTOM_CACHE_KEY_ACTIONS.removeBody,
|
|
156
|
+
});
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Creates a key value for a header or cookie based on the specified group creator
|
|
161
|
+
* @param createGroups the GroupCreator
|
|
162
|
+
* @param srcValues The values of the header or cookie in the request
|
|
163
|
+
*/
|
|
164
|
+
createGroupedValue(createGroups, srcValues) {
|
|
165
|
+
const groups = new Groups_1.default();
|
|
166
|
+
const result = [];
|
|
167
|
+
createGroups(groups);
|
|
168
|
+
const matchingGroup = this.findMatchingGroup(groups, srcValues);
|
|
169
|
+
if (matchingGroup) {
|
|
170
|
+
result.push(matchingGroup);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// if the value doesn't match any group, use the value itself
|
|
174
|
+
result.push(...srcValues);
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
findMatchingGroup(groups, srcValues) {
|
|
179
|
+
var _a;
|
|
180
|
+
for (let group of groups.groups) {
|
|
181
|
+
for (let value of srcValues) {
|
|
182
|
+
/* istanbul ignore next */
|
|
183
|
+
if ((_a = group.pattern) === null || _a === void 0 ? void 0 : _a.test(value)) {
|
|
184
|
+
return group.name;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Specifies that requests should be cached on a per-device basis.
|
|
191
|
+
* This will have no effect on service worker cache.
|
|
192
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
193
|
+
*/
|
|
194
|
+
addDevice() {
|
|
195
|
+
return this.addHeader('x-0-device');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Specifies that requests should be cached on a per-vendor basis.
|
|
199
|
+
* This will have no effect on service worker cache.
|
|
200
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
201
|
+
*/
|
|
202
|
+
addVendor() {
|
|
203
|
+
return this.addHeader('x-0-vendor');
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Specifies that requests should be cached differently for bots.
|
|
207
|
+
* This will have no effect on service worker cache.
|
|
208
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
209
|
+
*/
|
|
210
|
+
addIsBot() {
|
|
211
|
+
return this.addHeader('x-0-device-is-bot');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Specifies that requests should be cached on a per-browser basis.
|
|
215
|
+
* This will have no effect on service worker cache.
|
|
216
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
217
|
+
*/
|
|
218
|
+
addBrowser() {
|
|
219
|
+
return this.addHeader('x-0-browser');
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Adds a cookie to the cache key.
|
|
223
|
+
* This will have no effect on service worker cache.
|
|
224
|
+
* @param name The name of the cookie
|
|
225
|
+
* @param createGroups An function that accepts a `Groups` instance and calls `groups.group(name)` to group multiple values into a single cache key component
|
|
226
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
227
|
+
*/
|
|
228
|
+
addCookie(name, createGroups) {
|
|
229
|
+
this.actions.push((key, srcRequest) => {
|
|
230
|
+
let cookieHeader = srcRequest.headers.cookie || '';
|
|
231
|
+
if (Array.isArray(cookieHeader)) {
|
|
232
|
+
// Based on https://tools.ietf.org/html/rfc6265#section-5.4 we should only get a single cookie header
|
|
233
|
+
// If we get more than one, we, just join them into a single parseable cookie value in case
|
|
234
|
+
// the origin decides to read them all
|
|
235
|
+
cookieHeader = cookieHeader.join(';');
|
|
236
|
+
}
|
|
237
|
+
const cookie = cookie_1.parse(cookieHeader);
|
|
238
|
+
const value = cookie[name];
|
|
239
|
+
if (createGroups) {
|
|
240
|
+
key.cookies[name] = this.createGroupedValue(createGroups, [value]);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
key.cookies[name] = value;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return this.addValue(`\${req:cookie:${name}}`, createGroups);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @private
|
|
250
|
+
* @return {CustomCacheKey} A self-reference, suitable for chaining.
|
|
251
|
+
*/
|
|
252
|
+
addValue(value, createGroups) {
|
|
253
|
+
const action = {
|
|
254
|
+
action: exports.CUSTOM_CACHE_KEY_ACTIONS.addValue,
|
|
255
|
+
value,
|
|
256
|
+
};
|
|
257
|
+
if (createGroups != null) {
|
|
258
|
+
const groups = new Groups_1.default();
|
|
259
|
+
createGroups(groups);
|
|
260
|
+
action.groups = groups.toJSON();
|
|
261
|
+
}
|
|
262
|
+
this.config.push(action);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
getActions() {
|
|
266
|
+
return this.actions;
|
|
267
|
+
}
|
|
268
|
+
toJSON() {
|
|
269
|
+
return this.config;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.default = CustomCacheKey;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class GroupConfig {
|
|
4
|
+
constructor(name) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
byPattern(pattern) {
|
|
8
|
+
this.pattern = pattern;
|
|
9
|
+
}
|
|
10
|
+
toJSON() {
|
|
11
|
+
if (!this.pattern) {
|
|
12
|
+
throw new Error('byPattern is required for group ' + this.name);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
groupedValue: this.name,
|
|
16
|
+
matchRegex: this.pattern.source,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = GroupConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 GroupConfig_1 = __importDefault(require("./GroupConfig"));
|
|
7
|
+
class Groups {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.groups = [];
|
|
10
|
+
this.name = null;
|
|
11
|
+
}
|
|
12
|
+
group(name) {
|
|
13
|
+
const group = new GroupConfig_1.default(name);
|
|
14
|
+
this.groups.push(group);
|
|
15
|
+
return group;
|
|
16
|
+
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
return this.groups.map(p => p.toJSON());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = Groups;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error class thrown by PathMatcher class.
|
|
3
|
+
*/
|
|
4
|
+
export declare class PathMatcherError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Indicates that the error is user error and that it should be handled as so.
|
|
7
|
+
*/
|
|
8
|
+
readonly isUserError: boolean;
|
|
9
|
+
constructor(pattern: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
* A simple abstraction of path-to-regexp that makes the process of
|
|
14
|
+
* extracting variables from requests paths repeatable across multiple use cases
|
|
15
|
+
* such as matching a route and rewriting params.
|
|
16
|
+
*/
|
|
17
|
+
export default class PathMatcher {
|
|
18
|
+
private readonly pattern;
|
|
19
|
+
private matcher?;
|
|
20
|
+
/**
|
|
21
|
+
* A path param in path-to-regexp syntax
|
|
22
|
+
* @param pattern
|
|
23
|
+
*/
|
|
24
|
+
constructor(pattern: string);
|
|
25
|
+
/**
|
|
26
|
+
* Returns key/value pairs if the path matches the pattern, otherwise undefined
|
|
27
|
+
* @param path
|
|
28
|
+
*/
|
|
29
|
+
match(path: string): {
|
|
30
|
+
[key: string]: string | string[];
|
|
31
|
+
} | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Matches partial splat (e.g. `/partial-:splat*`) routes.
|
|
34
|
+
*/
|
|
35
|
+
private static PARTIAL_SPLAT_ROUTE;
|
|
36
|
+
/**
|
|
37
|
+
* Validate the given pattern as acceptable. If it's not acceptable an exception is raised
|
|
38
|
+
* with sufficient information to fix the problem.
|
|
39
|
+
*
|
|
40
|
+
* Notes:
|
|
41
|
+
* - Partial splat patterns (e.g. `/partial-:splat*`) have both semantic and execution issues.
|
|
42
|
+
* Semantic issues lie in the fact that path-to-regexp will generate a surprisingly different
|
|
43
|
+
* regexp for partial splat vs full splat pattern (e.g. `/full/:splat*`) that will actually not
|
|
44
|
+
* match all the sub-paths that follow the partial prefix but rather only the rest of the path
|
|
45
|
+
* until the end of the string. Execution issues lie in the fact that such regexes have been
|
|
46
|
+
* observed to block Chrome, Node and other regular expression engines. To prevent issues with
|
|
47
|
+
* these patterns we do not support them but propose a reasonable alternative of splitting the
|
|
48
|
+
* splat into fixed and splat parameters.
|
|
49
|
+
*/
|
|
50
|
+
private static validatePattern;
|
|
51
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_to_regexp_1 = require("path-to-regexp");
|
|
4
|
+
/**
|
|
5
|
+
* Error class thrown by PathMatcher class.
|
|
6
|
+
*/
|
|
7
|
+
class PathMatcherError extends Error {
|
|
8
|
+
constructor(pattern) {
|
|
9
|
+
super(`Route pattern "${pattern}" contains invalid syntax. See https://docs.layer0.co/guides/routing#section_route_pattern_syntax`); // istanbul ignore next - this is a known issue with TypeScript
|
|
10
|
+
this.isUserError = true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.PathMatcherError = PathMatcherError;
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
* A simple abstraction of path-to-regexp that makes the process of
|
|
17
|
+
* extracting variables from requests paths repeatable across multiple use cases
|
|
18
|
+
* such as matching a route and rewriting params.
|
|
19
|
+
*/
|
|
20
|
+
class PathMatcher {
|
|
21
|
+
/**
|
|
22
|
+
* A path param in path-to-regexp syntax
|
|
23
|
+
* @param pattern
|
|
24
|
+
*/
|
|
25
|
+
constructor(pattern) {
|
|
26
|
+
this.pattern = pattern;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns key/value pairs if the path matches the pattern, otherwise undefined
|
|
30
|
+
* @param path
|
|
31
|
+
*/
|
|
32
|
+
match(path) {
|
|
33
|
+
if (!this.matcher) {
|
|
34
|
+
try {
|
|
35
|
+
this.matcher = path_to_regexp_1.match(this.pattern, { decode: decodeURIComponent });
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw new PathMatcherError(this.pattern);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
PathMatcher.validatePattern(this.pattern);
|
|
42
|
+
const result = this.matcher(path);
|
|
43
|
+
return result ? result.params : undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validate the given pattern as acceptable. If it's not acceptable an exception is raised
|
|
47
|
+
* with sufficient information to fix the problem.
|
|
48
|
+
*
|
|
49
|
+
* Notes:
|
|
50
|
+
* - Partial splat patterns (e.g. `/partial-:splat*`) have both semantic and execution issues.
|
|
51
|
+
* Semantic issues lie in the fact that path-to-regexp will generate a surprisingly different
|
|
52
|
+
* regexp for partial splat vs full splat pattern (e.g. `/full/:splat*`) that will actually not
|
|
53
|
+
* match all the sub-paths that follow the partial prefix but rather only the rest of the path
|
|
54
|
+
* until the end of the string. Execution issues lie in the fact that such regexes have been
|
|
55
|
+
* observed to block Chrome, Node and other regular expression engines. To prevent issues with
|
|
56
|
+
* these patterns we do not support them but propose a reasonable alternative of splitting the
|
|
57
|
+
* splat into fixed and splat parameters.
|
|
58
|
+
*/
|
|
59
|
+
static validatePattern(pattern) {
|
|
60
|
+
const partialSplatRouteMatch = pattern.match(this.PARTIAL_SPLAT_ROUTE);
|
|
61
|
+
if (partialSplatRouteMatch) {
|
|
62
|
+
const [_, prefix, splat] = partialSplatRouteMatch;
|
|
63
|
+
const alternativePattern = pattern.replace(`${prefix}${splat}`, `${prefix}:suffix/${splat}`);
|
|
64
|
+
throw new PathMatcherError(`Partial splat routes are not supported. Use "${alternativePattern}" instead of "${pattern}"`);
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.default = PathMatcher;
|
|
70
|
+
/**
|
|
71
|
+
* Matches partial splat (e.g. `/partial-:splat*`) routes.
|
|
72
|
+
*/
|
|
73
|
+
PathMatcher.PARTIAL_SPLAT_ROUTE = /(\/[^:/]+)(:[^*/#?]+\*)/;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Headers from './Headers';
|
|
2
|
+
export interface PreloadRequestConfig {
|
|
3
|
+
path?: string;
|
|
4
|
+
headers?: Headers;
|
|
5
|
+
top?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CompletePreloadRequestConfig extends PreloadRequestConfig {
|
|
8
|
+
destination: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DestinationPreloadConfig {
|
|
11
|
+
requests: CompletePreloadRequestConfig[];
|
|
12
|
+
}
|
|
13
|
+
export interface CompiledPreloadOptions {
|
|
14
|
+
requests: CompletePreloadRequestConfig[];
|
|
15
|
+
concurrency?: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CompiledPreloadOptions, DestinationPreloadConfig, PreloadRequestConfig } from './Preload';
|
|
2
|
+
import Router from './Router';
|
|
3
|
+
export default class PreloadRequests {
|
|
4
|
+
options: Array<PreloadRequestConfig[] | (() => Promise<PreloadRequestConfig[]>) | (() => PreloadRequestConfig[])>;
|
|
5
|
+
/**
|
|
6
|
+
* Adds prerender config to list
|
|
7
|
+
*
|
|
8
|
+
* @param preloadConfig
|
|
9
|
+
*/
|
|
10
|
+
push(...preloadConfig: Array<PreloadRequestConfig[] | (() => Promise<PreloadRequestConfig[]>) | (() => PreloadRequestConfig[])>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves Preload config per destination
|
|
13
|
+
* @param router
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
static resolveDestinationPreloadConfig(router: Router, destination: string): Promise<DestinationPreloadConfig>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolves compiled Preload config across all destinatons
|
|
19
|
+
* @param router
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
static resolvePreloadConfig(router: Router): Promise<CompiledPreloadOptions>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 config_1 = __importDefault(require("../config"));
|
|
7
|
+
const Tasks_1 = __importDefault(require("../utils/Tasks"));
|
|
8
|
+
class PreloadRequests {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.options = [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Adds prerender config to list
|
|
14
|
+
*
|
|
15
|
+
* @param preloadConfig
|
|
16
|
+
*/
|
|
17
|
+
push(...preloadConfig) {
|
|
18
|
+
this.options.push(...preloadConfig);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolves Preload config per destination
|
|
22
|
+
* @param router
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
static async resolveDestinationPreloadConfig(router, destination) {
|
|
26
|
+
const requests = [];
|
|
27
|
+
await new Tasks_1.default()
|
|
28
|
+
.add(...router.preloadRequests.options)
|
|
29
|
+
.onTaskDone((result) => {
|
|
30
|
+
requests.push(...result.map(r => ({ ...r, destination })));
|
|
31
|
+
})
|
|
32
|
+
.resolve();
|
|
33
|
+
return {
|
|
34
|
+
requests,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolves compiled Preload config across all destinatons
|
|
39
|
+
* @param router
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
static async resolvePreloadConfig(router) {
|
|
43
|
+
const preloadRequests = [];
|
|
44
|
+
const tasks = new Tasks_1.default();
|
|
45
|
+
const destinations = router.getDestinations();
|
|
46
|
+
// Compile all the requests and options across all destinations
|
|
47
|
+
if (!Object.keys(destinations).length) {
|
|
48
|
+
tasks.add(PreloadRequests.resolveDestinationPreloadConfig(router, 'default'));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
for (let d in destinations) {
|
|
52
|
+
tasks.add(PreloadRequests.resolveDestinationPreloadConfig(destinations[d], d));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await tasks
|
|
56
|
+
.onTaskDone(({ requests }) => {
|
|
57
|
+
preloadRequests.push(...requests);
|
|
58
|
+
})
|
|
59
|
+
.resolve();
|
|
60
|
+
return {
|
|
61
|
+
requests: preloadRequests,
|
|
62
|
+
concurrency: config_1.default.get('prerenderConcurrency', null),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.default = PreloadRequests;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Represents an incoming request.
|
|
4
|
+
*/
|
|
5
|
+
export default interface Request {
|
|
6
|
+
/**
|
|
7
|
+
* The path and query string
|
|
8
|
+
*/
|
|
9
|
+
url: string;
|
|
10
|
+
/**
|
|
11
|
+
* Just the path part of the URL
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
14
|
+
/**
|
|
15
|
+
* The request body as a string
|
|
16
|
+
*/
|
|
17
|
+
body?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The raw request body as a buffer
|
|
20
|
+
*/
|
|
21
|
+
rawBody?: Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* The HTTP method
|
|
24
|
+
*/
|
|
25
|
+
method: string;
|
|
26
|
+
/**
|
|
27
|
+
* The request headers. Keys are header names, values are either a string, or when multiple values for
|
|
28
|
+
* the same header name are present, an array of strings.
|
|
29
|
+
*/
|
|
30
|
+
headers: {
|
|
31
|
+
[key: string]: string | string[];
|
|
32
|
+
};
|
|
33
|
+
/** @private */
|
|
34
|
+
on: (event: string, callback: Function) => void;
|
|
35
|
+
/**
|
|
36
|
+
* The path params returned by the matching route.
|
|
37
|
+
*/
|
|
38
|
+
params?: {
|
|
39
|
+
[key: string]: string | string[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The params extracted from the request URL's query string
|
|
43
|
+
*/
|
|
44
|
+
query?: {
|
|
45
|
+
[key: string]: string | string[] | undefined;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Flag indicating if the connection to Layer0 is secure (HTTPS) or not (HTTP).
|
|
49
|
+
*/
|
|
50
|
+
secure: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Sets a header
|
|
53
|
+
* @param name The name of the header to set
|
|
54
|
+
* @param value The value to set
|
|
55
|
+
*/
|
|
56
|
+
setHeader: (name: string, value: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the value of a header
|
|
59
|
+
* @param name The name of the header to return
|
|
60
|
+
* @returns The value of the header
|
|
61
|
+
*/
|
|
62
|
+
getHeader: (name: string) => string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets all headers as key/value pairs.
|
|
65
|
+
*/
|
|
66
|
+
getHeaders: () => {
|
|
67
|
+
[name: string]: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Removes a header
|
|
71
|
+
* @param name The header to remove
|
|
72
|
+
*/
|
|
73
|
+
removeHeader: (name: string) => void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import CacheKey from '../cache/CacheKey';
|
|
2
|
+
export default class RequestContext {
|
|
3
|
+
/**
|
|
4
|
+
* Set to true if ResponseWriter#cache is called with edge: { forcePrivateCaching: true }
|
|
5
|
+
*/
|
|
6
|
+
forcePrivateCaching: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The method criteria from the route that set caching
|
|
9
|
+
*/
|
|
10
|
+
cacheRouteMethod?: string;
|
|
11
|
+
cacheKey?: CacheKey;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class RequestContext {
|
|
4
|
+
constructor() {
|
|
5
|
+
/**
|
|
6
|
+
* Set to true if ResponseWriter#cache is called with edge: { forcePrivateCaching: true }
|
|
7
|
+
*/
|
|
8
|
+
this.forcePrivateCaching = false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = RequestContext;
|