@kensio/yulin 1.20.17 → 1.21.0
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/dist/service/athena/engine/sim-athena-comparison-shims.d.ts +13 -0
- package/dist/service/athena/engine/sim-athena-comparison-shims.js +68 -0
- package/dist/service/athena/engine/sim-athena-shims.js +2 -0
- package/dist/service/cloudformation/resource/cfn/cloudfront/sim-cloudfront-cfn-value-adapter.js +8 -0
- package/dist/service/cloudformation/resource/cfn/cloudfront/sim-cloudfront-orp-cfn.d.ts +24 -0
- package/dist/service/cloudformation/resource/cfn/cloudfront/sim-cloudfront-orp-cfn.js +31 -0
- package/dist/service/cloudfront/behaviour/sim-cloud-front-behavior.d.ts +12 -1
- package/dist/service/cloudfront/cache/sim-cf-accept-encoding.d.ts +11 -0
- package/dist/service/cloudfront/cache/sim-cf-accept-encoding.js +27 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-control.d.ts +28 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-control.js +49 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-entry-key-path.d.ts +11 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-entry-key-path.js +22 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-entry-key.d.ts +32 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-entry-key.js +112 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-status.d.ts +27 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-status.js +53 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-ttl.d.ts +28 -0
- package/dist/service/cloudfront/cache/sim-cf-cache-ttl.js +50 -0
- package/dist/service/cloudfront/cache/sim-cf-cacheable-request.d.ts +35 -0
- package/dist/service/cloudfront/cache/sim-cf-cacheable-request.js +32 -0
- package/dist/service/cloudfront/cache/sim-cf-distribution-cache.d.ts +57 -0
- package/dist/service/cloudfront/cache/sim-cf-distribution-cache.js +115 -0
- package/dist/service/cloudfront/cache/sim-cf-edge.d.ts +37 -0
- package/dist/service/cloudfront/cache/sim-cf-edge.js +34 -0
- package/dist/service/cloudfront/cache/sim-cf-error-cache-ttl.d.ts +36 -0
- package/dist/service/cloudfront/cache/sim-cf-error-cache-ttl.js +28 -0
- package/dist/service/cloudfront/cache/sim-cf-http-date.d.ts +15 -0
- package/dist/service/cloudfront/cache/sim-cf-http-date.js +40 -0
- package/dist/service/cloudfront/cache-policy/sim-cf-cache-key.d.ts +63 -0
- package/dist/service/cloudfront/cache-policy/sim-cf-cache-key.js +70 -0
- package/dist/service/cloudfront/cache-policy/sim-cf-cache-policy.d.ts +13 -3
- package/dist/service/cloudfront/cache-policy/sim-cf-cache-policy.js +31 -3
- package/dist/service/cloudfront/cache-policy/sim-cf-managed-cache-policies.d.ts +8 -3
- package/dist/service/cloudfront/cache-policy/sim-cf-managed-cache-policies.js +96 -12
- package/dist/service/cloudfront/cff/sim-cff-search-distribution.fixture.js +4 -0
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-config.d.ts +9 -8
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-config.js +40 -11
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-key.d.ts +10 -0
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-key.js +50 -0
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-section.d.ts +28 -0
- package/dist/service/cloudfront/cfn/cache-policy/sim-cfn-cf-cache-policy-section.js +29 -0
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-behavior-policy-kinds.d.ts +16 -0
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-behavior-policy-kinds.js +23 -0
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-distro-behavior-policies.d.ts +3 -2
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-distro-behavior-policies.js +3 -2
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-distro-creator.d.ts +6 -6
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-distro-creator.js +6 -6
- package/dist/service/cloudfront/cfn/distro/sim-cfn-cf-distro-policy-drops.js +8 -23
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-config.d.ts +28 -0
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-config.js +46 -0
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-creator.d.ts +24 -0
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-creator.js +32 -0
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-forwarding.d.ts +10 -0
- package/dist/service/cloudfront/cfn/origin-request-policy/sim-cfn-cf-orp-forwarding.js +51 -0
- package/dist/service/cloudfront/cfn/policy/sim-cfn-cf-policy-section.d.ts +22 -0
- package/dist/service/cloudfront/cfn/policy/sim-cfn-cf-policy-section.js +54 -0
- package/dist/service/cloudfront/cfn/sim-cfn-cloudfront-resource-factory.d.ts +1 -0
- package/dist/service/cloudfront/cfn/sim-cfn-cloudfront-resource-factory.js +12 -0
- package/dist/service/cloudfront/command/create-distribution/create-distribution.command.d.ts +1 -0
- package/dist/service/cloudfront/command/create-distribution/create-distribution.handler.d.ts +2 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-create-invalidation.d.ts +28 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-create-invalidation.js +59 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-get-invalidation.d.ts +19 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-get-invalidation.js +32 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-access.d.ts +36 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-access.js +45 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-command.types.d.ts +80 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-command.types.js +1 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-commands.d.ts +39 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-invalidation-commands.js +35 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-list-invalidations.d.ts +23 -0
- package/dist/service/cloudfront/command/invalidation/sim-cf-list-invalidations.js +39 -0
- package/dist/service/cloudfront/command/update-distribution/update-distribution.handler.d.ts +2 -0
- package/dist/service/cloudfront/controller/content/sim-cf-content-stage.d.ts +51 -0
- package/dist/service/cloudfront/controller/content/sim-cf-content-stage.js +65 -0
- package/dist/service/cloudfront/controller/dependency/sim-cf-controller-dependency.d.ts +2 -3
- package/dist/service/cloudfront/controller/dependency/sim-cf-controller-dependency.js +4 -4
- package/dist/service/cloudfront/controller/error/sim-cf-custom-error-responder.d.ts +4 -0
- package/dist/service/cloudfront/controller/error/sim-cf-custom-error-responder.js +12 -8
- package/dist/service/cloudfront/controller/origin/sim-cf-origin-stage.d.ts +2 -2
- package/dist/service/cloudfront/controller/origin/sim-cf-origin-stage.js +2 -2
- package/dist/service/cloudfront/controller/sim-cloudfront-request-pipeline.d.ts +6 -6
- package/dist/service/cloudfront/controller/sim-cloudfront-request-pipeline.js +35 -20
- package/dist/service/cloudfront/custom-error/sim-cloudfront-custom-error-response.d.ts +23 -5
- package/dist/service/cloudfront/custom-error/sim-cloudfront-custom-error-response.js +8 -0
- package/dist/service/cloudfront/distribution/configurator/sim-cf-behavior-origin-request-policy.d.ts +18 -0
- package/dist/service/cloudfront/distribution/configurator/sim-cf-behavior-origin-request-policy.js +30 -0
- package/dist/service/cloudfront/distribution/configurator/sim-cf-behavior-policies.d.ts +7 -5
- package/dist/service/cloudfront/distribution/configurator/sim-cf-behavior-policies.js +8 -5
- package/dist/service/cloudfront/distribution/configurator/sim-cf-behavior-properties.js +4 -1
- package/dist/service/cloudfront/distribution/configurator/sim-cf-distribution-configurator.factory.d.ts +2 -0
- package/dist/service/cloudfront/distribution/configurator/sim-cf-distribution-configurator.factory.js +6 -2
- package/dist/service/cloudfront/distribution/configurator/sim-cloud-front-custom-error-configurator.d.ts +13 -3
- package/dist/service/cloudfront/distribution/configurator/sim-cloud-front-custom-error-configurator.js +27 -6
- package/dist/service/cloudfront/distribution/configurator/sim-cloud-front-origin-configurator.d.ts +3 -1
- package/dist/service/cloudfront/distribution/configurator/sim-cloud-front-origin-configurator.js +4 -1
- package/dist/service/cloudfront/distribution/sim-cf-distribution-configuration-state.d.ts +5 -3
- package/dist/service/cloudfront/distribution/sim-cf-distribution-reconfigurer.d.ts +2 -0
- package/dist/service/cloudfront/distribution/sim-cf-distribution-view.js +1 -1
- package/dist/service/cloudfront/distribution/sim-cloudfront-distribution.d.ts +25 -2
- package/dist/service/cloudfront/distribution/sim-cloudfront-distribution.js +24 -0
- package/dist/service/cloudfront/error/sim-cf-invalidation.error.d.ts +22 -0
- package/dist/service/cloudfront/error/sim-cf-invalidation.error.js +26 -0
- package/dist/service/cloudfront/error/sim-cf-origin-request-policy.error.d.ts +22 -0
- package/dist/service/cloudfront/error/sim-cf-origin-request-policy.error.js +26 -0
- package/dist/service/cloudfront/index.d.ts +2 -0
- package/dist/service/cloudfront/index.js +1 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation-path.d.ts +22 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation-path.js +32 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation-view.d.ts +43 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation-view.js +33 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation.d.ts +55 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidation.js +56 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidations.d.ts +41 -0
- package/dist/service/cloudfront/invalidation/sim-cf-invalidations.js +58 -0
- package/dist/service/cloudfront/invalidation/sim-cf-repeated-invalidation.d.ts +15 -0
- package/dist/service/cloudfront/invalidation/sim-cf-repeated-invalidation.js +23 -0
- package/dist/service/cloudfront/origin/custom/sim-cf-custom-origin-forwarding.d.ts +19 -0
- package/dist/service/cloudfront/origin/custom/sim-cf-custom-origin-forwarding.js +116 -0
- package/dist/service/cloudfront/origin/custom/sim-cf-custom-origin-request.d.ts +15 -5
- package/dist/service/cloudfront/origin/custom/sim-cf-custom-origin-request.js +13 -8
- package/dist/service/cloudfront/origin/custom/sim-cf-custom-origin-signer.js +8 -5
- package/dist/service/cloudfront/origin/custom/sim-cloudfront-custom-origin.d.ts +13 -0
- package/dist/service/cloudfront/origin/custom/sim-cloudfront-custom-origin.js +8 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-behavior-forwarded.d.ts +24 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-behavior-forwarded.js +21 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-forwarded-to-origin.d.ts +57 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-forwarded-to-origin.js +129 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-managed-origin-request-policies.d.ts +30 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-managed-origin-request-policies.js +121 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-forwarding.d.ts +56 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-forwarding.js +67 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-policy-registry.d.ts +38 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-policy-registry.js +51 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-policy.d.ts +32 -0
- package/dist/service/cloudfront/origin-request-policy/sim-cf-origin-request-policy.js +30 -0
- package/dist/service/cloudfront/registry/sim-cloud-front-registry.d.ts +25 -0
- package/dist/service/cloudfront/registry/sim-cloud-front-registry.js +23 -0
- package/dist/service/cloudfront/sdk/sim-cloudfront-sdk-command-router.js +12 -0
- package/dist/service/cloudfront/sim-cloudfront-caching.d.ts +31 -0
- package/dist/service/cloudfront/sim-cloudfront-caching.js +38 -0
- package/dist/service/cloudfront/sim-cloudfront-commands.d.ts +12 -0
- package/dist/service/cloudfront/sim-cloudfront-commands.js +12 -0
- package/dist/service/cloudfront/sim-cloudfront-distributions.d.ts +21 -0
- package/dist/service/cloudfront/sim-cloudfront-distributions.js +23 -0
- package/dist/service/cloudfront/sim-cloudfront-origin-access-controls.d.ts +30 -0
- package/dist/service/cloudfront/sim-cloudfront-origin-access-controls.js +35 -0
- package/dist/service/cloudfront/sim-cloudfront-policies.d.ts +22 -5
- package/dist/service/cloudfront/sim-cloudfront-policies.js +27 -5
- package/dist/service/cloudfront/sim-cloudfront.d.ts +15 -31
- package/dist/service/cloudfront/sim-cloudfront.js +23 -41
- package/dist/service/iam/authorize/allow/sim-iam-allow-requirement.d.ts +6 -5
- package/dist/service/iam/authorize/allow/sim-iam-allow-requirement.js +6 -5
- package/dist/service/iam/authorize/context/sim-iam-auth-z-input.d.ts +6 -4
- package/dist/service/kms/command/sim-kms-request-options.d.ts +9 -5
- package/dist/service/logs/command/delivery/sim-logs-delivery-source-commands.d.ts +6 -4
- package/dist/service/logs/command/delivery/sim-logs-delivery-source-commands.js +13 -4
- package/dist/service/logs/delivery/cloudfront/sim-logs-vended-log-delivery.d.ts +23 -0
- package/dist/service/logs/delivery/cloudfront/sim-logs-vended-log-delivery.js +28 -0
- package/dist/service/ssm/parameter/sim-ssm-kms-crypto.d.ts +7 -10
- package/dist/service/ssm/parameter/sim-ssm-parameter-kms.d.ts +10 -11
- package/dist/service/ssm/parameter/sim-ssm-parameter-kms.js +11 -16
- package/docs/services/athena/README.md +7 -1
- package/docs/services/cloudformation/README.md +2 -1
- package/docs/services/cloudfront/README.md +903 -25
- package/docs/services/ecs/README.md +5 -2
- package/docs/services/kms/README.md +9 -5
- package/docs/services/logs/README.md +6 -0
- package/docs/services/ssm/README.md +26 -33
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SimCloudFrontBehavior } from "../behaviour/sim-cloud-front-behavior.js";
|
|
2
|
+
import type { SimCloudFrontCachePolicy } from "../cache-policy/sim-cf-cache-policy.js";
|
|
3
|
+
import type { SimCloudFront } from "../sim-cloudfront.js";
|
|
4
|
+
interface SimCfCacheableRequestProperties {
|
|
5
|
+
readonly cloudFront: SimCloudFront;
|
|
6
|
+
readonly behaviour: SimCloudFrontBehavior;
|
|
7
|
+
readonly request: Request;
|
|
8
|
+
readonly edgeId: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A request the Behavior caches, and what decides for how long.
|
|
12
|
+
*/
|
|
13
|
+
export interface SimCfCacheableRequest {
|
|
14
|
+
/** The key the request is cached under. */
|
|
15
|
+
readonly key: string;
|
|
16
|
+
/**
|
|
17
|
+
* The policy the key came from, whose TTLs settle how long the Origin's
|
|
18
|
+
* answer is held.
|
|
19
|
+
*/
|
|
20
|
+
readonly policy: SimCloudFrontCachePolicy;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The key this request is cached under and the policy that decided it, or none
|
|
24
|
+
* where the Behavior caches nothing.
|
|
25
|
+
*
|
|
26
|
+
* Three things stop a Behavior caching. Its cache policy may be one this
|
|
27
|
+
* simulation does not hold, including the Behavior that names no policy at
|
|
28
|
+
* all, and there is nothing to key on and no TTL that is not a guess. Its
|
|
29
|
+
* policy may cache nothing, which is what a `MaxTTL` of zero says and is how
|
|
30
|
+
* `CachingDisabled` reaches the Origin every time. Or the request's method may
|
|
31
|
+
* be outside the Behavior's `CachedMethods`, which is CloudFront's own rule
|
|
32
|
+
* that a POST is never served from a cache.
|
|
33
|
+
*/
|
|
34
|
+
export declare function simCfCacheableRequest(properties: SimCfCacheableRequestProperties): SimCfCacheableRequest | undefined;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { simCfCacheEntryKey } from "./sim-cf-cache-entry-key.js";
|
|
2
|
+
/**
|
|
3
|
+
* The key this request is cached under and the policy that decided it, or none
|
|
4
|
+
* where the Behavior caches nothing.
|
|
5
|
+
*
|
|
6
|
+
* Three things stop a Behavior caching. Its cache policy may be one this
|
|
7
|
+
* simulation does not hold, including the Behavior that names no policy at
|
|
8
|
+
* all, and there is nothing to key on and no TTL that is not a guess. Its
|
|
9
|
+
* policy may cache nothing, which is what a `MaxTTL` of zero says and is how
|
|
10
|
+
* `CachingDisabled` reaches the Origin every time. Or the request's method may
|
|
11
|
+
* be outside the Behavior's `CachedMethods`, which is CloudFront's own rule
|
|
12
|
+
* that a POST is never served from a cache.
|
|
13
|
+
*/
|
|
14
|
+
export function simCfCacheableRequest(properties) {
|
|
15
|
+
const { cloudFront, behaviour, request, edgeId } = properties;
|
|
16
|
+
if (!cloudFront.cachingEnabled) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const policy = behaviour.cachePolicyId === undefined
|
|
20
|
+
? undefined
|
|
21
|
+
: cloudFront.getCachePolicyById(behaviour.cachePolicyId);
|
|
22
|
+
if (policy === undefined || policy.maxTtlSec <= 0) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
if (!behaviour.cachedMethods.has(request.method.toUpperCase())) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
key: simCfCacheEntryKey({ request, cacheKey: policy.cacheKey, edgeId }),
|
|
30
|
+
policy,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type SimClock } from "../../../util/clock/sim-clock.js";
|
|
2
|
+
/**
|
|
3
|
+
* What one simulated Distribution has cached.
|
|
4
|
+
*
|
|
5
|
+
* Real CloudFront caches at each of its points of presence rather than once
|
|
6
|
+
* per Distribution, which the edge in the key stands for. One cache holds an
|
|
7
|
+
* entry per edge, and a request arriving at another edge misses.
|
|
8
|
+
*
|
|
9
|
+
* An entry leaves the cache two ways. It expires on the simulation's clock
|
|
10
|
+
* rather than the host's. A test reaches the instant an object goes stale by
|
|
11
|
+
* advancing simulated time, with no waiting. Or an invalidation clears it ahead
|
|
12
|
+
* of that instant.
|
|
13
|
+
*
|
|
14
|
+
* Storing takes its seconds from the caller. An Origin's answer is held for
|
|
15
|
+
* what its cache policy allows, and an error's own `ErrorCachingMinTTL` fits
|
|
16
|
+
* the same call.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SimCfDistributionCache {
|
|
19
|
+
private readonly entries;
|
|
20
|
+
private readonly clock;
|
|
21
|
+
/**
|
|
22
|
+
* A cache built standalone, outside a Distribution, falls back to the real
|
|
23
|
+
* clock.
|
|
24
|
+
*/
|
|
25
|
+
constructor(clock?: SimClock);
|
|
26
|
+
/**
|
|
27
|
+
* The response cached under a key, or none where the cache does not hold it.
|
|
28
|
+
*
|
|
29
|
+
* An entry that has reached its expiry is dropped here. The request then goes
|
|
30
|
+
* to the Origin, and what the Origin answers replaces the expired entry.
|
|
31
|
+
*
|
|
32
|
+
* What comes back carries `Age`, counted on the simulation's clock from the
|
|
33
|
+
* instant the Origin's answer was stored. An `Age` the Origin sent is
|
|
34
|
+
* replaced by the Distribution's own, as CloudFront replaces one.
|
|
35
|
+
*/
|
|
36
|
+
read(key: string): Response | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Cache a response under a key for a number of seconds, and hand back one to
|
|
39
|
+
* carry on with.
|
|
40
|
+
*
|
|
41
|
+
* Storing reads the response's body, which can only happen once, so the
|
|
42
|
+
* response the caller continues with is built from the bytes that were
|
|
43
|
+
* stored rather than being the one passed in. A TTL of no seconds stores
|
|
44
|
+
* nothing, and the response passed in is handed straight back unread.
|
|
45
|
+
*/
|
|
46
|
+
store(key: string, response: Response, ttlSec: number): Promise<Response>;
|
|
47
|
+
/**
|
|
48
|
+
* Forget every entry an invalidation's paths name, at every edge.
|
|
49
|
+
*
|
|
50
|
+
* The path an entry was cached under is read back out of its key, so
|
|
51
|
+
* matching a batch costs a pass over the keys rather than a second map from
|
|
52
|
+
* path to entry. Nothing here is keyed on the edge, because an invalidation
|
|
53
|
+
* reaches every point of presence rather than the one a viewer happened to
|
|
54
|
+
* arrive at.
|
|
55
|
+
*/
|
|
56
|
+
clearPaths(paths: readonly string[]): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { SimRealClock } from "../../../util/clock/sim-clock.js";
|
|
2
|
+
import { simCfInvalidationBatchCovers } from "../invalidation/sim-cf-invalidation-path.js";
|
|
3
|
+
import { simCfAgeHeaderName, simCfCacheAgeSec } from "./sim-cf-cache-status.js";
|
|
4
|
+
import { simCfCacheEntryKeyPath } from "./sim-cf-cache-entry-key-path.js";
|
|
5
|
+
/**
|
|
6
|
+
* The statuses HTTP gives no body, which a Response refuses to be built with
|
|
7
|
+
* one for.
|
|
8
|
+
*/
|
|
9
|
+
const bodylessStatuses = new Set([101, 103, 204, 205, 304]);
|
|
10
|
+
/**
|
|
11
|
+
* What one simulated Distribution has cached.
|
|
12
|
+
*
|
|
13
|
+
* Real CloudFront caches at each of its points of presence rather than once
|
|
14
|
+
* per Distribution, which the edge in the key stands for. One cache holds an
|
|
15
|
+
* entry per edge, and a request arriving at another edge misses.
|
|
16
|
+
*
|
|
17
|
+
* An entry leaves the cache two ways. It expires on the simulation's clock
|
|
18
|
+
* rather than the host's. A test reaches the instant an object goes stale by
|
|
19
|
+
* advancing simulated time, with no waiting. Or an invalidation clears it ahead
|
|
20
|
+
* of that instant.
|
|
21
|
+
*
|
|
22
|
+
* Storing takes its seconds from the caller. An Origin's answer is held for
|
|
23
|
+
* what its cache policy allows, and an error's own `ErrorCachingMinTTL` fits
|
|
24
|
+
* the same call.
|
|
25
|
+
*/
|
|
26
|
+
export class SimCfDistributionCache {
|
|
27
|
+
entries = new Map();
|
|
28
|
+
clock;
|
|
29
|
+
/**
|
|
30
|
+
* A cache built standalone, outside a Distribution, falls back to the real
|
|
31
|
+
* clock.
|
|
32
|
+
*/
|
|
33
|
+
constructor(clock = new SimRealClock()) {
|
|
34
|
+
this.clock = clock;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The response cached under a key, or none where the cache does not hold it.
|
|
38
|
+
*
|
|
39
|
+
* An entry that has reached its expiry is dropped here. The request then goes
|
|
40
|
+
* to the Origin, and what the Origin answers replaces the expired entry.
|
|
41
|
+
*
|
|
42
|
+
* What comes back carries `Age`, counted on the simulation's clock from the
|
|
43
|
+
* instant the Origin's answer was stored. An `Age` the Origin sent is
|
|
44
|
+
* replaced by the Distribution's own, as CloudFront replaces one.
|
|
45
|
+
*/
|
|
46
|
+
read(key) {
|
|
47
|
+
const entry = this.entries.get(key);
|
|
48
|
+
if (entry === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const now = this.clock.now();
|
|
52
|
+
if (now.getTime() >= entry.expiresAt.getTime()) {
|
|
53
|
+
this.entries.delete(key);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const response = cachedResponse(entry);
|
|
57
|
+
response.headers.set(simCfAgeHeaderName, String(simCfCacheAgeSec(entry.storedAt, now)));
|
|
58
|
+
return response;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Cache a response under a key for a number of seconds, and hand back one to
|
|
62
|
+
* carry on with.
|
|
63
|
+
*
|
|
64
|
+
* Storing reads the response's body, which can only happen once, so the
|
|
65
|
+
* response the caller continues with is built from the bytes that were
|
|
66
|
+
* stored rather than being the one passed in. A TTL of no seconds stores
|
|
67
|
+
* nothing, and the response passed in is handed straight back unread.
|
|
68
|
+
*/
|
|
69
|
+
async store(key, response, ttlSec) {
|
|
70
|
+
if (!Number.isFinite(ttlSec) || ttlSec <= 0) {
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
const storedAt = this.clock.now();
|
|
74
|
+
const entry = {
|
|
75
|
+
status: response.status,
|
|
76
|
+
statusText: response.statusText,
|
|
77
|
+
headers: [...response.headers],
|
|
78
|
+
body: new Uint8Array(await response.arrayBuffer()),
|
|
79
|
+
storedAt,
|
|
80
|
+
expiresAt: new Date(storedAt.getTime() + ttlSec * 1000),
|
|
81
|
+
};
|
|
82
|
+
this.entries.set(key, entry);
|
|
83
|
+
return cachedResponse(entry);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Forget every entry an invalidation's paths name, at every edge.
|
|
87
|
+
*
|
|
88
|
+
* The path an entry was cached under is read back out of its key, so
|
|
89
|
+
* matching a batch costs a pass over the keys rather than a second map from
|
|
90
|
+
* path to entry. Nothing here is keyed on the edge, because an invalidation
|
|
91
|
+
* reaches every point of presence rather than the one a viewer happened to
|
|
92
|
+
* arrive at.
|
|
93
|
+
*/
|
|
94
|
+
clearPaths(paths) {
|
|
95
|
+
for (const key of this.entries.keys()) {
|
|
96
|
+
const path = simCfCacheEntryKeyPath(key);
|
|
97
|
+
if (path !== undefined && simCfInvalidationBatchCovers(paths, path)) {
|
|
98
|
+
this.entries.delete(key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Build a response from a cached one, which every read needs its own of.
|
|
105
|
+
*
|
|
106
|
+
* No `Age` goes on here. A response on its way into the cache has been held
|
|
107
|
+
* for no time at all, and only one leaving it has an age to report.
|
|
108
|
+
*/
|
|
109
|
+
function cachedResponse(entry) {
|
|
110
|
+
return new Response(bodylessStatuses.has(entry.status) ? null : entry.body, {
|
|
111
|
+
status: entry.status,
|
|
112
|
+
statusText: entry.statusText,
|
|
113
|
+
headers: new Headers(entry.headers.map(([name, value]) => [name, value])),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The header naming the CloudFront edge a request arrives at.
|
|
3
|
+
*
|
|
4
|
+
* CloudFront caches at each of its several hundred points of presence, so a
|
|
5
|
+
* viewer is never guaranteed the entry another viewer's request stored. A
|
|
6
|
+
* request naming an edge of its own is answered from that edge's cache, which
|
|
7
|
+
* is how a test proves its app survives arriving somewhere cold.
|
|
8
|
+
*
|
|
9
|
+
* The name follows the `x-sim-aws-*` convention of `simAwsControlHeaderNames`,
|
|
10
|
+
* and like those headers it states something to the simulator rather than to
|
|
11
|
+
* the application. Sim CloudFront reads it, drops it from the request, and
|
|
12
|
+
* nothing downstream of the edge sees it.
|
|
13
|
+
*/
|
|
14
|
+
export declare const simCfEdgeHeaderName = "x-sim-aws-cloudfront-edge";
|
|
15
|
+
/**
|
|
16
|
+
* The edge a request arrives at when it names none.
|
|
17
|
+
*
|
|
18
|
+
* Every request in a test lands here unless the test says otherwise, and a
|
|
19
|
+
* second request for a key the first one stored is a hit. A header carrying no
|
|
20
|
+
* value names no edge, and lands here too.
|
|
21
|
+
*/
|
|
22
|
+
export declare const simCfDefaultEdgeId = "default";
|
|
23
|
+
/**
|
|
24
|
+
* A request and the edge it arrived at.
|
|
25
|
+
*/
|
|
26
|
+
export interface SimCfRequestEdge {
|
|
27
|
+
readonly edgeId: string;
|
|
28
|
+
/**
|
|
29
|
+
* The request with the edge header removed, which is the one the rest of the
|
|
30
|
+
* pipeline works on.
|
|
31
|
+
*/
|
|
32
|
+
readonly request: Request;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Read the edge a request arrived at, and take the header back off it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function simCfRequestEdge(request: Request): SimCfRequestEdge;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The header naming the CloudFront edge a request arrives at.
|
|
3
|
+
*
|
|
4
|
+
* CloudFront caches at each of its several hundred points of presence, so a
|
|
5
|
+
* viewer is never guaranteed the entry another viewer's request stored. A
|
|
6
|
+
* request naming an edge of its own is answered from that edge's cache, which
|
|
7
|
+
* is how a test proves its app survives arriving somewhere cold.
|
|
8
|
+
*
|
|
9
|
+
* The name follows the `x-sim-aws-*` convention of `simAwsControlHeaderNames`,
|
|
10
|
+
* and like those headers it states something to the simulator rather than to
|
|
11
|
+
* the application. Sim CloudFront reads it, drops it from the request, and
|
|
12
|
+
* nothing downstream of the edge sees it.
|
|
13
|
+
*/
|
|
14
|
+
export const simCfEdgeHeaderName = "x-sim-aws-cloudfront-edge";
|
|
15
|
+
/**
|
|
16
|
+
* The edge a request arrives at when it names none.
|
|
17
|
+
*
|
|
18
|
+
* Every request in a test lands here unless the test says otherwise, and a
|
|
19
|
+
* second request for a key the first one stored is a hit. A header carrying no
|
|
20
|
+
* value names no edge, and lands here too.
|
|
21
|
+
*/
|
|
22
|
+
export const simCfDefaultEdgeId = "default";
|
|
23
|
+
/**
|
|
24
|
+
* Read the edge a request arrived at, and take the header back off it.
|
|
25
|
+
*/
|
|
26
|
+
export function simCfRequestEdge(request) {
|
|
27
|
+
const named = request.headers.get(simCfEdgeHeaderName)?.trim();
|
|
28
|
+
if (named === undefined || named.length === 0) {
|
|
29
|
+
return { edgeId: simCfDefaultEdgeId, request };
|
|
30
|
+
}
|
|
31
|
+
const headers = new Headers(request.headers);
|
|
32
|
+
headers.delete(simCfEdgeHeaderName);
|
|
33
|
+
return { edgeId: named, request: new Request(request, { headers }) };
|
|
34
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type SimCloudFrontCustomErrorResponse } from "../custom-error/sim-cloudfront-custom-error-response.js";
|
|
2
|
+
interface SimCfErrorCacheTtlProperties {
|
|
3
|
+
/**
|
|
4
|
+
* The status the Origin answered with, before an origin-response function
|
|
5
|
+
* or a custom error page could replace it.
|
|
6
|
+
*/
|
|
7
|
+
readonly originStatus: number;
|
|
8
|
+
/** The response carrying on towards the viewer. */
|
|
9
|
+
readonly response: Response;
|
|
10
|
+
/**
|
|
11
|
+
* The Distribution's custom error responses, whose `ErrorCachingMinTTL`
|
|
12
|
+
* decides.
|
|
13
|
+
*/
|
|
14
|
+
readonly customErrorResponses: readonly SimCloudFrontCustomErrorResponse[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* How many seconds a Distribution holds an error for, or none where this
|
|
18
|
+
* answer is no error at all.
|
|
19
|
+
*
|
|
20
|
+
* An error has a TTL of its own, and the Origin's cache headers and the
|
|
21
|
+
* Behavior's cache policy have no say in it. It comes from the custom error
|
|
22
|
+
* response matching the status, and from CloudFront's ten seconds where the
|
|
23
|
+
* Distribution configures no rule for that status. An `ErrorCachingMinTTL` of
|
|
24
|
+
* zero holds the error for no time at all, which is how a Distribution turns
|
|
25
|
+
* error caching off.
|
|
26
|
+
*
|
|
27
|
+
* The Origin's status is what a rule is matched against. A 404 the
|
|
28
|
+
* Distribution answers with a 200 error page is still held as the error it
|
|
29
|
+
* was, for the seconds the 404's own rule allows. An error that only an
|
|
30
|
+
* origin-response function made has no Origin error behind it, and its own
|
|
31
|
+
* status stands in.
|
|
32
|
+
*
|
|
33
|
+
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/HTTPStatusCodes.html
|
|
34
|
+
*/
|
|
35
|
+
export declare function simCfErrorCacheTtlSec(properties: SimCfErrorCacheTtlProperties): number | undefined;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { simCloudFrontDefaultErrorCachingMinTtlSec, } from "../custom-error/sim-cloudfront-custom-error-response.js";
|
|
2
|
+
/**
|
|
3
|
+
* How many seconds a Distribution holds an error for, or none where this
|
|
4
|
+
* answer is no error at all.
|
|
5
|
+
*
|
|
6
|
+
* An error has a TTL of its own, and the Origin's cache headers and the
|
|
7
|
+
* Behavior's cache policy have no say in it. It comes from the custom error
|
|
8
|
+
* response matching the status, and from CloudFront's ten seconds where the
|
|
9
|
+
* Distribution configures no rule for that status. An `ErrorCachingMinTTL` of
|
|
10
|
+
* zero holds the error for no time at all, which is how a Distribution turns
|
|
11
|
+
* error caching off.
|
|
12
|
+
*
|
|
13
|
+
* The Origin's status is what a rule is matched against. A 404 the
|
|
14
|
+
* Distribution answers with a 200 error page is still held as the error it
|
|
15
|
+
* was, for the seconds the 404's own rule allows. An error that only an
|
|
16
|
+
* origin-response function made has no Origin error behind it, and its own
|
|
17
|
+
* status stands in.
|
|
18
|
+
*
|
|
19
|
+
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/HTTPStatusCodes.html
|
|
20
|
+
*/
|
|
21
|
+
export function simCfErrorCacheTtlSec(properties) {
|
|
22
|
+
const { originStatus, response, customErrorResponses } = properties;
|
|
23
|
+
const errorStatus = originStatus >= 400 ? originStatus : response.status;
|
|
24
|
+
if (errorStatus < 400) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return (customErrorResponses.find((customErrorResponse) => customErrorResponse.errorCode === errorStatus)?.errorCachingMinTtlSec ?? simCloudFrontDefaultErrorCachingMinTtlSec);
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The instant an HTTP date names, in milliseconds, or none where the value is
|
|
3
|
+
* not one of the three formats HTTP allows.
|
|
4
|
+
*
|
|
5
|
+
* The check matters because `Date.parse` reads far more than HTTP does. It
|
|
6
|
+
* takes `12/31/2099` as a date in 2099 and `0` as the start of the year 2000,
|
|
7
|
+
* and an HTTP cache is required to treat both as an object that has already
|
|
8
|
+
* expired.
|
|
9
|
+
*
|
|
10
|
+
* asctime states no zone and HTTP reads it as GMT, while `Date.parse` would
|
|
11
|
+
* read it in the host's own. It is rewritten with the zone spelled out.
|
|
12
|
+
*
|
|
13
|
+
* https://www.rfc-editor.org/rfc/rfc9110#name-date-time-formats
|
|
14
|
+
*/
|
|
15
|
+
export declare function simCfHttpDateInstant(value: string): number | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMF-fixdate, which every sender is required to use. `Sun, 06 Nov 1994
|
|
3
|
+
* 08:49:37 GMT`.
|
|
4
|
+
*/
|
|
5
|
+
const imfFixdate = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
6
|
+
/**
|
|
7
|
+
* The obsolete RFC 850 format, which a recipient still has to read.
|
|
8
|
+
* `Sunday, 06-Nov-94 08:49:37 GMT`.
|
|
9
|
+
*/
|
|
10
|
+
const rfc850Date = /^[A-Za-z]{6,9}, \d{2}-[A-Za-z]{3}-\d{2} \d{2}:\d{2}:\d{2} GMT$/;
|
|
11
|
+
/**
|
|
12
|
+
* The obsolete asctime format, which carries no zone. `Sun Nov 6 08:49:37
|
|
13
|
+
* 1994`.
|
|
14
|
+
*/
|
|
15
|
+
const asctimeDate = /^[A-Za-z]{3} ([A-Za-z]{3}) {1,2}(\d{1,2}) (\d{2}:\d{2}:\d{2}) (\d{4})$/;
|
|
16
|
+
/**
|
|
17
|
+
* The instant an HTTP date names, in milliseconds, or none where the value is
|
|
18
|
+
* not one of the three formats HTTP allows.
|
|
19
|
+
*
|
|
20
|
+
* The check matters because `Date.parse` reads far more than HTTP does. It
|
|
21
|
+
* takes `12/31/2099` as a date in 2099 and `0` as the start of the year 2000,
|
|
22
|
+
* and an HTTP cache is required to treat both as an object that has already
|
|
23
|
+
* expired.
|
|
24
|
+
*
|
|
25
|
+
* asctime states no zone and HTTP reads it as GMT, while `Date.parse` would
|
|
26
|
+
* read it in the host's own. It is rewritten with the zone spelled out.
|
|
27
|
+
*
|
|
28
|
+
* https://www.rfc-editor.org/rfc/rfc9110#name-date-time-formats
|
|
29
|
+
*/
|
|
30
|
+
export function simCfHttpDateInstant(value) {
|
|
31
|
+
const asctime = asctimeDate.exec(value);
|
|
32
|
+
const parsable = asctime === null
|
|
33
|
+
? value
|
|
34
|
+
: `${asctime[2]} ${asctime[1]} ${asctime[4]} ${asctime[3]} GMT`;
|
|
35
|
+
if (asctime === null && !imfFixdate.test(value) && !rfc850Date.test(value)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const instant = Date.parse(parsable);
|
|
39
|
+
return Number.isNaN(instant) ? undefined : instant;
|
|
40
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cookie behaviours a cache policy may name.
|
|
3
|
+
*
|
|
4
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-cookiesconfig.html
|
|
5
|
+
*/
|
|
6
|
+
export declare const simCfCacheKeyCookieBehaviors: readonly ["none", "whitelist", "allExcept", "all"];
|
|
7
|
+
export type SimCfCacheKeyCookieBehavior = (typeof simCfCacheKeyCookieBehaviors)[number];
|
|
8
|
+
/**
|
|
9
|
+
* The header behaviours a cache policy may name.
|
|
10
|
+
*
|
|
11
|
+
* These are two of the four an origin request policy offers. A cache key can
|
|
12
|
+
* name headers or leave them all out; there is no `allViewer` to key a cache
|
|
13
|
+
* on, since keying on every header a viewer sent would cache almost nothing
|
|
14
|
+
* twice.
|
|
15
|
+
*
|
|
16
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-headersconfig.html
|
|
17
|
+
*/
|
|
18
|
+
export declare const simCfCacheKeyHeaderBehaviors: readonly ["none", "whitelist"];
|
|
19
|
+
export type SimCfCacheKeyHeaderBehavior = (typeof simCfCacheKeyHeaderBehaviors)[number];
|
|
20
|
+
/**
|
|
21
|
+
* The query string behaviours a cache policy may name.
|
|
22
|
+
*
|
|
23
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-querystringsconfig.html
|
|
24
|
+
*/
|
|
25
|
+
export declare const simCfCacheKeyQueryStringBehaviors: readonly ["none", "whitelist", "allExcept", "all"];
|
|
26
|
+
export type SimCfCacheKeyQueryStringBehavior = (typeof simCfCacheKeyQueryStringBehaviors)[number];
|
|
27
|
+
interface SimCloudFrontCacheKeyProperties {
|
|
28
|
+
readonly cookieBehavior?: SimCfCacheKeyCookieBehavior;
|
|
29
|
+
readonly cookies?: readonly string[];
|
|
30
|
+
readonly headerBehavior?: SimCfCacheKeyHeaderBehavior;
|
|
31
|
+
readonly headers?: readonly string[];
|
|
32
|
+
readonly queryStringBehavior?: SimCfCacheKeyQueryStringBehavior;
|
|
33
|
+
readonly queryStrings?: readonly string[];
|
|
34
|
+
readonly enableAcceptEncodingGzip?: boolean;
|
|
35
|
+
readonly enableAcceptEncodingBrotli?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a cache policy keys its cache on.
|
|
39
|
+
*
|
|
40
|
+
* This is CloudFront's `ParametersInCacheKeyAndForwardedToOrigin`. Each of the
|
|
41
|
+
* three sections carries a behaviour and the names it applies to: a
|
|
42
|
+
* `whitelist` keys on the names listed, an `allExcept` keys on everything but
|
|
43
|
+
* them, and `all` and `none` ignore the list. The names listed are also the
|
|
44
|
+
* ones CloudFront forwards to the Origin.
|
|
45
|
+
*
|
|
46
|
+
* The two `EnableAcceptEncoding` flags decide whether the normalized
|
|
47
|
+
* `Accept-Encoding` header joins the key, which is what lets one object be
|
|
48
|
+
* cached once compressed and once not.
|
|
49
|
+
*
|
|
50
|
+
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html
|
|
51
|
+
*/
|
|
52
|
+
export declare class SimCloudFrontCacheKey {
|
|
53
|
+
readonly cookieBehavior: SimCfCacheKeyCookieBehavior;
|
|
54
|
+
readonly cookies: readonly string[];
|
|
55
|
+
readonly headerBehavior: SimCfCacheKeyHeaderBehavior;
|
|
56
|
+
readonly headers: readonly string[];
|
|
57
|
+
readonly queryStringBehavior: SimCfCacheKeyQueryStringBehavior;
|
|
58
|
+
readonly queryStrings: readonly string[];
|
|
59
|
+
readonly enableAcceptEncodingGzip: boolean;
|
|
60
|
+
readonly enableAcceptEncodingBrotli: boolean;
|
|
61
|
+
constructor(properties?: SimCloudFrontCacheKeyProperties);
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cookie behaviours a cache policy may name.
|
|
3
|
+
*
|
|
4
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-cookiesconfig.html
|
|
5
|
+
*/
|
|
6
|
+
export const simCfCacheKeyCookieBehaviors = [
|
|
7
|
+
"none",
|
|
8
|
+
"whitelist",
|
|
9
|
+
"allExcept",
|
|
10
|
+
"all",
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* The header behaviours a cache policy may name.
|
|
14
|
+
*
|
|
15
|
+
* These are two of the four an origin request policy offers. A cache key can
|
|
16
|
+
* name headers or leave them all out; there is no `allViewer` to key a cache
|
|
17
|
+
* on, since keying on every header a viewer sent would cache almost nothing
|
|
18
|
+
* twice.
|
|
19
|
+
*
|
|
20
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-headersconfig.html
|
|
21
|
+
*/
|
|
22
|
+
export const simCfCacheKeyHeaderBehaviors = ["none", "whitelist"];
|
|
23
|
+
/**
|
|
24
|
+
* The query string behaviours a cache policy may name.
|
|
25
|
+
*
|
|
26
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-querystringsconfig.html
|
|
27
|
+
*/
|
|
28
|
+
export const simCfCacheKeyQueryStringBehaviors = [
|
|
29
|
+
"none",
|
|
30
|
+
"whitelist",
|
|
31
|
+
"allExcept",
|
|
32
|
+
"all",
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* What a cache policy keys its cache on.
|
|
36
|
+
*
|
|
37
|
+
* This is CloudFront's `ParametersInCacheKeyAndForwardedToOrigin`. Each of the
|
|
38
|
+
* three sections carries a behaviour and the names it applies to: a
|
|
39
|
+
* `whitelist` keys on the names listed, an `allExcept` keys on everything but
|
|
40
|
+
* them, and `all` and `none` ignore the list. The names listed are also the
|
|
41
|
+
* ones CloudFront forwards to the Origin.
|
|
42
|
+
*
|
|
43
|
+
* The two `EnableAcceptEncoding` flags decide whether the normalized
|
|
44
|
+
* `Accept-Encoding` header joins the key, which is what lets one object be
|
|
45
|
+
* cached once compressed and once not.
|
|
46
|
+
*
|
|
47
|
+
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html
|
|
48
|
+
*/
|
|
49
|
+
export class SimCloudFrontCacheKey {
|
|
50
|
+
cookieBehavior;
|
|
51
|
+
cookies;
|
|
52
|
+
headerBehavior;
|
|
53
|
+
headers;
|
|
54
|
+
queryStringBehavior;
|
|
55
|
+
queryStrings;
|
|
56
|
+
enableAcceptEncodingGzip;
|
|
57
|
+
enableAcceptEncodingBrotli;
|
|
58
|
+
constructor(properties = {}) {
|
|
59
|
+
this.cookieBehavior = properties.cookieBehavior ?? "none";
|
|
60
|
+
this.cookies = properties.cookies ?? [];
|
|
61
|
+
this.headerBehavior = properties.headerBehavior ?? "none";
|
|
62
|
+
this.headers = properties.headers ?? [];
|
|
63
|
+
this.queryStringBehavior = properties.queryStringBehavior ?? "none";
|
|
64
|
+
this.queryStrings = properties.queryStrings ?? [];
|
|
65
|
+
this.enableAcceptEncodingGzip =
|
|
66
|
+
properties.enableAcceptEncodingGzip ?? false;
|
|
67
|
+
this.enableAcceptEncodingBrotli =
|
|
68
|
+
properties.enableAcceptEncodingBrotli ?? false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import type { Brand } from "../../../util/brand.type.js";
|
|
2
|
+
import { SimCloudFrontCacheKey } from "./sim-cf-cache-key.js";
|
|
2
3
|
export type SimCloudFrontCachePolicyId = Brand<string, "SimCloudFrontCachePolicyId">;
|
|
3
4
|
interface SimCloudFrontCachePolicyProperties {
|
|
4
5
|
readonly id?: SimCloudFrontCachePolicyId;
|
|
5
6
|
readonly name: string;
|
|
6
7
|
readonly comment?: string | undefined;
|
|
8
|
+
readonly minTtlSec?: number;
|
|
9
|
+
readonly defaultTtlSec?: number;
|
|
10
|
+
readonly maxTtlSec?: number;
|
|
11
|
+
readonly cacheKey?: SimCloudFrontCacheKey;
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
14
|
* Simulated CloudFront cache policy.
|
|
10
15
|
*
|
|
11
16
|
* A cache policy decides what a cache Behavior keys its cache on and how long
|
|
12
|
-
* an object stays there. This simulation holds the policy under its ID
|
|
13
|
-
*
|
|
14
|
-
*
|
|
17
|
+
* an object stays there. This simulation holds the policy under its ID, along
|
|
18
|
+
* with its three TTLs and its cache key, and keys the Distribution's cache on
|
|
19
|
+
* it. A `MaxTTL` of zero is read as a Behavior that caches nothing, and the
|
|
20
|
+
* other two settle how long an entry lives against what the Origin asked for.
|
|
15
21
|
*
|
|
16
22
|
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html
|
|
17
23
|
*/
|
|
@@ -19,6 +25,10 @@ export declare class SimCloudFrontCachePolicy {
|
|
|
19
25
|
readonly id: SimCloudFrontCachePolicyId;
|
|
20
26
|
readonly name: string;
|
|
21
27
|
readonly comment: string | undefined;
|
|
28
|
+
readonly minTtlSec: number;
|
|
29
|
+
readonly defaultTtlSec: number;
|
|
30
|
+
readonly maxTtlSec: number;
|
|
31
|
+
readonly cacheKey: SimCloudFrontCacheKey;
|
|
22
32
|
constructor(properties: SimCloudFrontCachePolicyProperties);
|
|
23
33
|
}
|
|
24
34
|
export type SimCloudFrontCachePolicyMap = Map<SimCloudFrontCachePolicyId, SimCloudFrontCachePolicy>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { SimCloudFrontCacheKey } from "./sim-cf-cache-key.js";
|
|
3
|
+
const daySeconds = 86_400;
|
|
4
|
+
const yearSeconds = 31_536_000;
|
|
2
5
|
/**
|
|
3
6
|
* Simulated CloudFront cache policy.
|
|
4
7
|
*
|
|
5
8
|
* A cache policy decides what a cache Behavior keys its cache on and how long
|
|
6
|
-
* an object stays there. This simulation holds the policy under its ID
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* an object stays there. This simulation holds the policy under its ID, along
|
|
10
|
+
* with its three TTLs and its cache key, and keys the Distribution's cache on
|
|
11
|
+
* it. A `MaxTTL` of zero is read as a Behavior that caches nothing, and the
|
|
12
|
+
* other two settle how long an entry lives against what the Origin asked for.
|
|
9
13
|
*
|
|
10
14
|
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html
|
|
11
15
|
*/
|
|
@@ -13,9 +17,33 @@ export class SimCloudFrontCachePolicy {
|
|
|
13
17
|
id;
|
|
14
18
|
name;
|
|
15
19
|
comment;
|
|
20
|
+
minTtlSec;
|
|
21
|
+
defaultTtlSec;
|
|
22
|
+
maxTtlSec;
|
|
23
|
+
cacheKey;
|
|
16
24
|
constructor(properties) {
|
|
17
25
|
this.id = properties.id ?? randomUUID();
|
|
18
26
|
this.name = properties.name;
|
|
19
27
|
this.comment = properties.comment;
|
|
28
|
+
this.minTtlSec = properties.minTtlSec ?? 0;
|
|
29
|
+
this.defaultTtlSec =
|
|
30
|
+
properties.defaultTtlSec ?? Math.max(daySeconds, this.minTtlSec);
|
|
31
|
+
this.maxTtlSec =
|
|
32
|
+
properties.maxTtlSec ?? maxTtlDefault(this.minTtlSec, this.defaultTtlSec);
|
|
33
|
+
this.cacheKey = properties.cacheKey ?? new SimCloudFrontCacheKey();
|
|
20
34
|
}
|
|
21
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The `MaxTTL` CloudFront settles on where a policy left it out.
|
|
38
|
+
*
|
|
39
|
+
* It is a year, except where a longer `MinTTL` or `DefaultTTL` would sit above
|
|
40
|
+
* it, in which case CloudFront takes the `DefaultTTL` rather than capping the
|
|
41
|
+
* policy below its own floor.
|
|
42
|
+
*
|
|
43
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-cachepolicy-cachepolicyconfig.html
|
|
44
|
+
*/
|
|
45
|
+
function maxTtlDefault(minTtlSec, defaultTtlSec) {
|
|
46
|
+
return minTtlSec > yearSeconds || defaultTtlSec > yearSeconds
|
|
47
|
+
? defaultTtlSec
|
|
48
|
+
: yearSeconds;
|
|
49
|
+
}
|