@cloudflare/pages-shared 0.11.13 → 0.11.15

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.
@@ -70,12 +70,20 @@ type ServeAsset<AssetEntry> = (
70
70
  options?: { preserve: boolean }
71
71
  ) => Promise<Response>;
72
72
 
73
+ type CacheStatus = "hit" | "miss";
74
+ type CacheResult<A extends string> = `${A}-${CacheStatus}`;
75
+ export type HandlerMetrics = {
76
+ preservationCacheResult?: CacheResult<"checked"> | "disabled";
77
+ earlyHintsResult?: CacheResult<"used" | "notused"> | "disabled";
78
+ };
79
+
73
80
  type FullHandlerContext<AssetEntry, ContentNegotiation, Asset> = {
74
81
  request: Request;
75
82
  metadata: Metadata;
76
83
  xServerEnvHeader?: string;
77
84
  xDeploymentIdHeader?: boolean;
78
85
  logError: (err: Error) => void;
86
+ setMetrics?: (metrics: HandlerMetrics) => void;
79
87
  findAssetEntryForPath: FindAssetEntryForPath<AssetEntry>;
80
88
  getAssetKey(assetEntry: AssetEntry, content: ContentNegotiation): string;
81
89
  negotiateContent(
@@ -123,6 +131,7 @@ export async function generateHandler<
123
131
  xServerEnvHeader,
124
132
  xDeploymentIdHeader,
125
133
  logError,
134
+ setMetrics,
126
135
  findAssetEntryForPath,
127
136
  getAssetKey,
128
137
  negotiateContent,
@@ -332,7 +341,12 @@ export async function generateHandler<
332
341
  const earlyHintsLinkHeader = earlyHintsResponse.headers.get("Link");
333
342
  if (earlyHintsLinkHeader) {
334
343
  headers.set("Link", earlyHintsLinkHeader);
344
+ if (setMetrics) setMetrics({ earlyHintsResult: "used-hit" });
345
+ } else {
346
+ if (setMetrics) setMetrics({ earlyHintsResult: "notused-hit" });
335
347
  }
348
+ } else {
349
+ if (setMetrics) setMetrics({ earlyHintsResult: "notused-miss" });
336
350
  }
337
351
 
338
352
  const clonedResponse = response.clone();
@@ -393,6 +407,8 @@ export async function generateHandler<
393
407
  })()
394
408
  );
395
409
  }
410
+ } else {
411
+ if (setMetrics) setMetrics({ earlyHintsResult: "disabled" });
396
412
  }
397
413
 
398
414
  // Iterate through rules and find rules that match the path
@@ -566,8 +582,13 @@ export async function generateHandler<
566
582
  );
567
583
  const preservedResponse = await assetPreservationCache.match(request.url);
568
584
  if (preservedResponse) {
585
+ if (setMetrics) setMetrics({ preservationCacheResult: "checked-hit" });
569
586
  return preservedResponse;
587
+ } else {
588
+ if (setMetrics) setMetrics({ preservationCacheResult: "checked-miss" });
570
589
  }
590
+ } else {
591
+ if (setMetrics) setMetrics({ preservationCacheResult: "disabled" });
571
592
  }
572
593
 
573
594
  // Traverse upwards from the current path looking for a custom 404 page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/pages-shared",
3
- "version": "0.11.13",
3
+ "version": "0.11.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/workers-sdk.git",
@@ -13,7 +13,7 @@
13
13
  "metadata-generator/**/*"
14
14
  ],
15
15
  "dependencies": {
16
- "miniflare": "3.20240129.3"
16
+ "miniflare": "3.20240223.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@cloudflare/workers-types": "^4.20230511.0",